• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-node-sdk / 19555963099

20 Nov 2025 03:38PM UTC coverage: 40.654% (-54.5%) from 95.198%
19555963099

push

github

web-flow
docs: Update Readme for migrating `sdk-gen` to main (box/box-codegen#889) (#1212)

4525 of 19644 branches covered (23.04%)

Branch coverage included in aggregate %.

16708 of 32584 relevant lines covered (51.28%)

140.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.08
/src/managers/comments.ts
1
import { serializeComments } from '../schemas/comments';
2
import { deserializeComments } from '../schemas/comments';
237✔
3
import { serializeClientError } from '../schemas/clientError';
4
import { deserializeClientError } from '../schemas/clientError';
5
import { serializeCommentFull } from '../schemas/commentFull';
6
import { deserializeCommentFull } from '../schemas/commentFull';
237✔
7
import { ResponseFormat } from '../networking/fetchOptions';
8
import { Comments } from '../schemas/comments';
9
import { ClientError } from '../schemas/clientError';
10
import { CommentFull } from '../schemas/commentFull';
11
import { BoxSdkError } from '../box/errors';
237✔
12
import { Authentication } from '../networking/auth';
13
import { NetworkSession } from '../networking/network';
237✔
14
import { FetchOptions } from '../networking/fetchOptions';
237✔
15
import { FetchResponse } from '../networking/fetchResponse';
16
import { prepareParams } from '../internal/utils';
237✔
17
import { toString } from '../internal/utils';
237✔
18
import { ByteStream } from '../internal/utils';
19
import { CancellationToken } from '../internal/utils';
20
import { sdToJson } from '../serialization/json';
21
import { SerializedData } from '../serialization/json';
22
import { sdIsEmpty } from '../serialization/json';
23
import { sdIsBoolean } from '../serialization/json';
24
import { sdIsNumber } from '../serialization/json';
25
import { sdIsString } from '../serialization/json';
237✔
26
import { sdIsList } from '../serialization/json';
27
import { sdIsMap } from '../serialization/json';
237✔
28
export class GetFileCommentsOptionals {
237✔
29
  readonly queryParams: GetFileCommentsQueryParams =
6✔
30
    {} satisfies GetFileCommentsQueryParams;
31
  readonly headers: GetFileCommentsHeaders = new GetFileCommentsHeaders({});
6✔
32
  readonly cancellationToken?: CancellationToken = void 0;
6✔
33
  constructor(
34
    fields: Omit<
35
      GetFileCommentsOptionals,
36
      'queryParams' | 'headers' | 'cancellationToken'
37
    > &
38
      Partial<
39
        Pick<
40
          GetFileCommentsOptionals,
41
          'queryParams' | 'headers' | 'cancellationToken'
42
        >
43
      >,
44
  ) {
45
    if (fields.queryParams !== undefined) {
6!
46
      this.queryParams = fields.queryParams;
×
47
    }
48
    if (fields.headers !== undefined) {
6!
49
      this.headers = fields.headers;
×
50
    }
51
    if (fields.cancellationToken !== undefined) {
6!
52
      this.cancellationToken = fields.cancellationToken;
×
53
    }
54
  }
55
}
56
export interface GetFileCommentsOptionalsInput {
57
  readonly queryParams?: GetFileCommentsQueryParams;
58
  readonly headers?: GetFileCommentsHeaders;
59
  readonly cancellationToken?: undefined | CancellationToken;
60
}
61
export class GetCommentByIdOptionals {
237✔
62
  readonly queryParams: GetCommentByIdQueryParams =
6✔
63
    {} satisfies GetCommentByIdQueryParams;
64
  readonly headers: GetCommentByIdHeaders = new GetCommentByIdHeaders({});
6✔
65
  readonly cancellationToken?: CancellationToken = void 0;
6✔
66
  constructor(
67
    fields: Omit<
68
      GetCommentByIdOptionals,
69
      'queryParams' | 'headers' | 'cancellationToken'
70
    > &
71
      Partial<
72
        Pick<
73
          GetCommentByIdOptionals,
74
          'queryParams' | 'headers' | 'cancellationToken'
75
        >
76
      >,
77
  ) {
78
    if (fields.queryParams !== undefined) {
6!
79
      this.queryParams = fields.queryParams;
×
80
    }
81
    if (fields.headers !== undefined) {
6!
82
      this.headers = fields.headers;
×
83
    }
84
    if (fields.cancellationToken !== undefined) {
6!
85
      this.cancellationToken = fields.cancellationToken;
×
86
    }
87
  }
88
}
89
export interface GetCommentByIdOptionalsInput {
90
  readonly queryParams?: GetCommentByIdQueryParams;
91
  readonly headers?: GetCommentByIdHeaders;
92
  readonly cancellationToken?: undefined | CancellationToken;
93
}
94
export class UpdateCommentByIdOptionals {
237✔
95
  readonly requestBody: UpdateCommentByIdRequestBody =
3✔
96
    {} satisfies UpdateCommentByIdRequestBody;
97
  readonly queryParams: UpdateCommentByIdQueryParams =
3✔
98
    {} satisfies UpdateCommentByIdQueryParams;
99
  readonly headers: UpdateCommentByIdHeaders = new UpdateCommentByIdHeaders({});
3✔
100
  readonly cancellationToken?: CancellationToken = void 0;
3✔
101
  constructor(
102
    fields: Omit<
103
      UpdateCommentByIdOptionals,
104
      'requestBody' | 'queryParams' | 'headers' | 'cancellationToken'
105
    > &
106
      Partial<
107
        Pick<
108
          UpdateCommentByIdOptionals,
109
          'requestBody' | 'queryParams' | 'headers' | 'cancellationToken'
110
        >
111
      >,
112
  ) {
113
    if (fields.requestBody !== undefined) {
3✔
114
      this.requestBody = fields.requestBody;
3✔
115
    }
116
    if (fields.queryParams !== undefined) {
3!
117
      this.queryParams = fields.queryParams;
×
118
    }
119
    if (fields.headers !== undefined) {
3!
120
      this.headers = fields.headers;
×
121
    }
122
    if (fields.cancellationToken !== undefined) {
3!
123
      this.cancellationToken = fields.cancellationToken;
×
124
    }
125
  }
126
}
127
export interface UpdateCommentByIdOptionalsInput {
128
  readonly requestBody?: UpdateCommentByIdRequestBody;
129
  readonly queryParams?: UpdateCommentByIdQueryParams;
130
  readonly headers?: UpdateCommentByIdHeaders;
131
  readonly cancellationToken?: undefined | CancellationToken;
132
}
133
export class DeleteCommentByIdOptionals {
237✔
134
  readonly headers: DeleteCommentByIdHeaders = new DeleteCommentByIdHeaders({});
3✔
135
  readonly cancellationToken?: CancellationToken = void 0;
3✔
136
  constructor(
137
    fields: Omit<DeleteCommentByIdOptionals, 'headers' | 'cancellationToken'> &
138
      Partial<
139
        Pick<DeleteCommentByIdOptionals, 'headers' | 'cancellationToken'>
140
      >,
141
  ) {
142
    if (fields.headers !== undefined) {
3!
143
      this.headers = fields.headers;
×
144
    }
145
    if (fields.cancellationToken !== undefined) {
3!
146
      this.cancellationToken = fields.cancellationToken;
×
147
    }
148
  }
149
}
150
export interface DeleteCommentByIdOptionalsInput {
151
  readonly headers?: DeleteCommentByIdHeaders;
152
  readonly cancellationToken?: undefined | CancellationToken;
153
}
154
export class CreateCommentOptionals {
237✔
155
  readonly queryParams: CreateCommentQueryParams =
6✔
156
    {} satisfies CreateCommentQueryParams;
157
  readonly headers: CreateCommentHeaders = new CreateCommentHeaders({});
6✔
158
  readonly cancellationToken?: CancellationToken = void 0;
6✔
159
  constructor(
160
    fields: Omit<
161
      CreateCommentOptionals,
162
      'queryParams' | 'headers' | 'cancellationToken'
163
    > &
164
      Partial<
165
        Pick<
166
          CreateCommentOptionals,
167
          'queryParams' | 'headers' | 'cancellationToken'
168
        >
169
      >,
170
  ) {
171
    if (fields.queryParams !== undefined) {
6!
172
      this.queryParams = fields.queryParams;
×
173
    }
174
    if (fields.headers !== undefined) {
6!
175
      this.headers = fields.headers;
×
176
    }
177
    if (fields.cancellationToken !== undefined) {
6!
178
      this.cancellationToken = fields.cancellationToken;
×
179
    }
180
  }
181
}
182
export interface CreateCommentOptionalsInput {
183
  readonly queryParams?: CreateCommentQueryParams;
184
  readonly headers?: CreateCommentHeaders;
185
  readonly cancellationToken?: undefined | CancellationToken;
186
}
187
export interface GetFileCommentsQueryParams {
188
  /**
189
   * A comma-separated list of attributes to include in the
190
   * response. This can be used to request fields that are
191
   * not normally returned in a standard response.
192
   *
193
   * Be aware that specifying this parameter will have the
194
   * effect that none of the standard fields are returned in
195
   * the response unless explicitly specified, instead only
196
   * fields for the mini representation are returned, additional
197
   * to the fields requested. */
198
  readonly fields?: readonly string[];
199
  /**
200
   * The maximum number of items to return per page. */
201
  readonly limit?: number;
202
  /**
203
   * The offset of the item at which to begin the response.
204
   *
205
   * Queries with offset parameter value
206
   * exceeding 10000 will be rejected
207
   * with a 400 response. */
208
  readonly offset?: number;
209
}
210
export class GetFileCommentsHeaders {
237✔
211
  /**
212
   * Extra headers that will be included in the HTTP request. */
213
  readonly extraHeaders?: {
6✔
214
    readonly [key: string]: undefined | string;
215
  } = {};
216
  constructor(
217
    fields: Omit<GetFileCommentsHeaders, 'extraHeaders'> &
218
      Partial<Pick<GetFileCommentsHeaders, 'extraHeaders'>>,
219
  ) {
220
    if (fields.extraHeaders !== undefined) {
6!
221
      this.extraHeaders = fields.extraHeaders;
×
222
    }
223
  }
224
}
225
export interface GetFileCommentsHeadersInput {
226
  /**
227
   * Extra headers that will be included in the HTTP request. */
228
  readonly extraHeaders?:
229
    | undefined
230
    | {
231
        readonly [key: string]: undefined | string;
232
      };
233
}
234
export interface GetCommentByIdQueryParams {
235
  /**
236
   * A comma-separated list of attributes to include in the
237
   * response. This can be used to request fields that are
238
   * not normally returned in a standard response.
239
   *
240
   * Be aware that specifying this parameter will have the
241
   * effect that none of the standard fields are returned in
242
   * the response unless explicitly specified, instead only
243
   * fields for the mini representation are returned, additional
244
   * to the fields requested. */
245
  readonly fields?: readonly string[];
246
}
247
export class GetCommentByIdHeaders {
237✔
248
  /**
249
   * Extra headers that will be included in the HTTP request. */
250
  readonly extraHeaders?: {
6✔
251
    readonly [key: string]: undefined | string;
252
  } = {};
253
  constructor(
254
    fields: Omit<GetCommentByIdHeaders, 'extraHeaders'> &
255
      Partial<Pick<GetCommentByIdHeaders, 'extraHeaders'>>,
256
  ) {
257
    if (fields.extraHeaders !== undefined) {
6!
258
      this.extraHeaders = fields.extraHeaders;
×
259
    }
260
  }
261
}
262
export interface GetCommentByIdHeadersInput {
263
  /**
264
   * Extra headers that will be included in the HTTP request. */
265
  readonly extraHeaders?:
266
    | undefined
267
    | {
268
        readonly [key: string]: undefined | string;
269
      };
270
}
271
export interface UpdateCommentByIdRequestBody {
272
  /**
273
   * The text of the comment to update. */
274
  readonly message?: string;
275
  readonly rawData?: SerializedData;
276
}
277
export interface UpdateCommentByIdQueryParams {
278
  /**
279
   * A comma-separated list of attributes to include in the
280
   * response. This can be used to request fields that are
281
   * not normally returned in a standard response.
282
   *
283
   * Be aware that specifying this parameter will have the
284
   * effect that none of the standard fields are returned in
285
   * the response unless explicitly specified, instead only
286
   * fields for the mini representation are returned, additional
287
   * to the fields requested. */
288
  readonly fields?: readonly string[];
289
}
290
export class UpdateCommentByIdHeaders {
237✔
291
  /**
292
   * Extra headers that will be included in the HTTP request. */
293
  readonly extraHeaders?: {
3✔
294
    readonly [key: string]: undefined | string;
295
  } = {};
296
  constructor(
297
    fields: Omit<UpdateCommentByIdHeaders, 'extraHeaders'> &
298
      Partial<Pick<UpdateCommentByIdHeaders, 'extraHeaders'>>,
299
  ) {
300
    if (fields.extraHeaders !== undefined) {
3!
301
      this.extraHeaders = fields.extraHeaders;
×
302
    }
303
  }
304
}
305
export interface UpdateCommentByIdHeadersInput {
306
  /**
307
   * Extra headers that will be included in the HTTP request. */
308
  readonly extraHeaders?:
309
    | undefined
310
    | {
311
        readonly [key: string]: undefined | string;
312
      };
313
}
314
export class DeleteCommentByIdHeaders {
237✔
315
  /**
316
   * Extra headers that will be included in the HTTP request. */
317
  readonly extraHeaders?: {
3✔
318
    readonly [key: string]: undefined | string;
319
  } = {};
320
  constructor(
321
    fields: Omit<DeleteCommentByIdHeaders, 'extraHeaders'> &
322
      Partial<Pick<DeleteCommentByIdHeaders, 'extraHeaders'>>,
323
  ) {
324
    if (fields.extraHeaders !== undefined) {
3!
325
      this.extraHeaders = fields.extraHeaders;
×
326
    }
327
  }
328
}
329
export interface DeleteCommentByIdHeadersInput {
330
  /**
331
   * Extra headers that will be included in the HTTP request. */
332
  readonly extraHeaders?:
333
    | undefined
334
    | {
335
        readonly [key: string]: undefined | string;
336
      };
337
}
338
export type CreateCommentRequestBodyItemTypeField = 'file' | 'comment';
339
export interface CreateCommentRequestBodyItemField {
340
  /**
341
   * The ID of the item. */
342
  readonly id: string;
343
  /**
344
   * The type of the item that this comment will be placed on. */
345
  readonly type: CreateCommentRequestBodyItemTypeField;
346
  readonly rawData?: SerializedData;
347
}
348
export interface CreateCommentRequestBody {
349
  /**
350
   * The text of the comment.
351
   *
352
   * To mention a user, use the `tagged_message`
353
   * parameter instead. */
354
  readonly message: string;
355
  /**
356
   * The text of the comment, including `@[user_id:name]`
357
   * somewhere in the message to mention another user, which
358
   * will send them an email notification, letting them know
359
   * they have been mentioned.
360
   *
361
   * The `user_id` is the target user's ID, where the `name`
362
   * can be any custom phrase. In the Box UI this name will
363
   * link to the user's profile.
364
   *
365
   * If you are not mentioning another user, use `message`
366
   * instead. */
367
  readonly taggedMessage?: string;
368
  /**
369
   * The item to attach the comment to. */
370
  readonly item: CreateCommentRequestBodyItemField;
371
  readonly rawData?: SerializedData;
372
}
373
export interface CreateCommentQueryParams {
374
  /**
375
   * A comma-separated list of attributes to include in the
376
   * response. This can be used to request fields that are
377
   * not normally returned in a standard response.
378
   *
379
   * Be aware that specifying this parameter will have the
380
   * effect that none of the standard fields are returned in
381
   * the response unless explicitly specified, instead only
382
   * fields for the mini representation are returned, additional
383
   * to the fields requested. */
384
  readonly fields?: readonly string[];
385
}
386
export class CreateCommentHeaders {
237✔
387
  /**
388
   * Extra headers that will be included in the HTTP request. */
389
  readonly extraHeaders?: {
6✔
390
    readonly [key: string]: undefined | string;
391
  } = {};
392
  constructor(
393
    fields: Omit<CreateCommentHeaders, 'extraHeaders'> &
394
      Partial<Pick<CreateCommentHeaders, 'extraHeaders'>>,
395
  ) {
396
    if (fields.extraHeaders !== undefined) {
6!
397
      this.extraHeaders = fields.extraHeaders;
×
398
    }
399
  }
400
}
401
export interface CreateCommentHeadersInput {
402
  /**
403
   * Extra headers that will be included in the HTTP request. */
404
  readonly extraHeaders?:
405
    | undefined
406
    | {
407
        readonly [key: string]: undefined | string;
408
      };
409
}
410
export class CommentsManager {
237✔
411
  readonly auth?: Authentication;
412
  readonly networkSession: NetworkSession = new NetworkSession({});
510✔
413
  constructor(
414
    fields: Omit<
415
      CommentsManager,
416
      | 'networkSession'
417
      | 'getFileComments'
418
      | 'getCommentById'
419
      | 'updateCommentById'
420
      | 'deleteCommentById'
421
      | 'createComment'
422
    > &
423
      Partial<Pick<CommentsManager, 'networkSession'>>,
424
  ) {
425
    if (fields.auth !== undefined) {
510✔
426
      this.auth = fields.auth;
510✔
427
    }
428
    if (fields.networkSession !== undefined) {
510✔
429
      this.networkSession = fields.networkSession;
510✔
430
    }
431
  }
432
  /**
433
     * Retrieves a list of comments for a file.
434
     * @param {string} fileId The unique identifier that represents a file.
435
    
436
    The ID for any file can be determined
437
    by visiting a file in the web application
438
    and copying the ID from the URL. For example,
439
    for the URL `https://*.app.box.com/files/123`
440
    the `file_id` is `123`.
441
    Example: "12345"
442
     * @param {GetFileCommentsOptionalsInput} optionalsInput
443
     * @returns {Promise<Comments>}
444
     */
445
  async getFileComments(
446
    fileId: string,
6✔
447
    optionalsInput: GetFileCommentsOptionalsInput = {},
6✔
448
  ): Promise<Comments> {
449
    const optionals: GetFileCommentsOptionals = new GetFileCommentsOptionals({
6✔
450
      queryParams: optionalsInput.queryParams,
451
      headers: optionalsInput.headers,
452
      cancellationToken: optionalsInput.cancellationToken,
453
    });
454
    const queryParams: any = optionals.queryParams;
6✔
455
    const headers: any = optionals.headers;
6✔
456
    const cancellationToken: any = optionals.cancellationToken;
6✔
457
    const queryParamsMap: {
458
      readonly [key: string]: string;
459
    } = prepareParams({
6✔
460
      ['fields']: queryParams.fields
6!
461
        ? queryParams.fields.map(toString).join(',')
462
        : undefined,
463
      ['limit']: toString(queryParams.limit) as string,
464
      ['offset']: toString(queryParams.offset) as string,
465
    });
466
    const headersMap: {
467
      readonly [key: string]: string;
468
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
469
    const response: FetchResponse =
470
      await this.networkSession.networkClient.fetch(
6✔
471
        new FetchOptions({
472
          url: ''.concat(
473
            this.networkSession.baseUrls.baseUrl,
474
            '/2.0/files/',
475
            toString(fileId) as string,
476
            '/comments',
477
          ) as string,
478
          method: 'GET',
479
          params: queryParamsMap,
480
          headers: headersMap,
481
          responseFormat: 'json' as ResponseFormat,
482
          auth: this.auth,
483
          networkSession: this.networkSession,
484
          cancellationToken: cancellationToken,
485
        }),
486
      );
487
    return {
6✔
488
      ...deserializeComments(response.data!),
489
      rawData: response.data!,
490
    };
491
  }
492
  /**
493
     * Retrieves the message and metadata for a specific comment, as well
494
     * as information on the user who created the comment.
495
     * @param {string} commentId The ID of the comment.
496
    Example: "12345"
497
     * @param {GetCommentByIdOptionalsInput} optionalsInput
498
     * @returns {Promise<CommentFull>}
499
     */
500
  async getCommentById(
501
    commentId: string,
6✔
502
    optionalsInput: GetCommentByIdOptionalsInput = {},
6✔
503
  ): Promise<CommentFull> {
504
    const optionals: GetCommentByIdOptionals = new GetCommentByIdOptionals({
6✔
505
      queryParams: optionalsInput.queryParams,
506
      headers: optionalsInput.headers,
507
      cancellationToken: optionalsInput.cancellationToken,
508
    });
509
    const queryParams: any = optionals.queryParams;
6✔
510
    const headers: any = optionals.headers;
6✔
511
    const cancellationToken: any = optionals.cancellationToken;
6✔
512
    const queryParamsMap: {
513
      readonly [key: string]: string;
514
    } = prepareParams({
6✔
515
      ['fields']: queryParams.fields
6!
516
        ? queryParams.fields.map(toString).join(',')
517
        : undefined,
518
    });
519
    const headersMap: {
520
      readonly [key: string]: string;
521
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
522
    const response: FetchResponse =
523
      await this.networkSession.networkClient.fetch(
6✔
524
        new FetchOptions({
525
          url: ''.concat(
526
            this.networkSession.baseUrls.baseUrl,
527
            '/2.0/comments/',
528
            toString(commentId) as string,
529
          ) as string,
530
          method: 'GET',
531
          params: queryParamsMap,
532
          headers: headersMap,
533
          responseFormat: 'json' as ResponseFormat,
534
          auth: this.auth,
535
          networkSession: this.networkSession,
536
          cancellationToken: cancellationToken,
537
        }),
538
      );
539
    return {
3✔
540
      ...deserializeCommentFull(response.data!),
541
      rawData: response.data!,
542
    };
543
  }
544
  /**
545
     * Update the message of a comment.
546
     * @param {string} commentId The ID of the comment.
547
    Example: "12345"
548
     * @param {UpdateCommentByIdOptionalsInput} optionalsInput
549
     * @returns {Promise<CommentFull>}
550
     */
551
  async updateCommentById(
552
    commentId: string,
3✔
553
    optionalsInput: UpdateCommentByIdOptionalsInput = {},
×
554
  ): Promise<CommentFull> {
555
    const optionals: UpdateCommentByIdOptionals =
556
      new UpdateCommentByIdOptionals({
3✔
557
        requestBody: optionalsInput.requestBody,
558
        queryParams: optionalsInput.queryParams,
559
        headers: optionalsInput.headers,
560
        cancellationToken: optionalsInput.cancellationToken,
561
      });
562
    const requestBody: any = optionals.requestBody;
3✔
563
    const queryParams: any = optionals.queryParams;
3✔
564
    const headers: any = optionals.headers;
3✔
565
    const cancellationToken: any = optionals.cancellationToken;
3✔
566
    const queryParamsMap: {
567
      readonly [key: string]: string;
568
    } = prepareParams({
3✔
569
      ['fields']: queryParams.fields
3!
570
        ? queryParams.fields.map(toString).join(',')
571
        : undefined,
572
    });
573
    const headersMap: {
574
      readonly [key: string]: string;
575
    } = prepareParams({ ...{}, ...headers.extraHeaders });
3✔
576
    const response: FetchResponse =
577
      await this.networkSession.networkClient.fetch(
3✔
578
        new FetchOptions({
579
          url: ''.concat(
580
            this.networkSession.baseUrls.baseUrl,
581
            '/2.0/comments/',
582
            toString(commentId) as string,
583
          ) as string,
584
          method: 'PUT',
585
          params: queryParamsMap,
586
          headers: headersMap,
587
          data: serializeUpdateCommentByIdRequestBody(requestBody),
588
          contentType: 'application/json',
589
          responseFormat: 'json' as ResponseFormat,
590
          auth: this.auth,
591
          networkSession: this.networkSession,
592
          cancellationToken: cancellationToken,
593
        }),
594
      );
595
    return {
3✔
596
      ...deserializeCommentFull(response.data!),
597
      rawData: response.data!,
598
    };
599
  }
600
  /**
601
     * Permanently deletes a comment.
602
     * @param {string} commentId The ID of the comment.
603
    Example: "12345"
604
     * @param {DeleteCommentByIdOptionalsInput} optionalsInput
605
     * @returns {Promise<undefined>}
606
     */
607
  async deleteCommentById(
608
    commentId: string,
3✔
609
    optionalsInput: DeleteCommentByIdOptionalsInput = {},
3✔
610
  ): Promise<undefined> {
611
    const optionals: DeleteCommentByIdOptionals =
612
      new DeleteCommentByIdOptionals({
3✔
613
        headers: optionalsInput.headers,
614
        cancellationToken: optionalsInput.cancellationToken,
615
      });
616
    const headers: any = optionals.headers;
3✔
617
    const cancellationToken: any = optionals.cancellationToken;
3✔
618
    const headersMap: {
619
      readonly [key: string]: string;
620
    } = prepareParams({ ...{}, ...headers.extraHeaders });
3✔
621
    const response: FetchResponse =
622
      await this.networkSession.networkClient.fetch(
3✔
623
        new FetchOptions({
624
          url: ''.concat(
625
            this.networkSession.baseUrls.baseUrl,
626
            '/2.0/comments/',
627
            toString(commentId) as string,
628
          ) as string,
629
          method: 'DELETE',
630
          headers: headersMap,
631
          responseFormat: 'no_content' as ResponseFormat,
632
          auth: this.auth,
633
          networkSession: this.networkSession,
634
          cancellationToken: cancellationToken,
635
        }),
636
      );
637
    return void 0;
3✔
638
  }
639
  /**
640
   * Adds a comment by the user to a specific file, or
641
   * as a reply to an other comment.
642
   * @param {CreateCommentRequestBody} requestBody Request body of createComment method
643
   * @param {CreateCommentOptionalsInput} optionalsInput
644
   * @returns {Promise<CommentFull>}
645
   */
646
  async createComment(
647
    requestBody: CreateCommentRequestBody,
6✔
648
    optionalsInput: CreateCommentOptionalsInput = {},
6✔
649
  ): Promise<CommentFull> {
650
    const optionals: CreateCommentOptionals = new CreateCommentOptionals({
6✔
651
      queryParams: optionalsInput.queryParams,
652
      headers: optionalsInput.headers,
653
      cancellationToken: optionalsInput.cancellationToken,
654
    });
655
    const queryParams: any = optionals.queryParams;
6✔
656
    const headers: any = optionals.headers;
6✔
657
    const cancellationToken: any = optionals.cancellationToken;
6✔
658
    const queryParamsMap: {
659
      readonly [key: string]: string;
660
    } = prepareParams({
6✔
661
      ['fields']: queryParams.fields
6!
662
        ? queryParams.fields.map(toString).join(',')
663
        : undefined,
664
    });
665
    const headersMap: {
666
      readonly [key: string]: string;
667
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
668
    const response: FetchResponse =
669
      await this.networkSession.networkClient.fetch(
6✔
670
        new FetchOptions({
671
          url: ''.concat(
672
            this.networkSession.baseUrls.baseUrl,
673
            '/2.0/comments',
674
          ) as string,
675
          method: 'POST',
676
          params: queryParamsMap,
677
          headers: headersMap,
678
          data: serializeCreateCommentRequestBody(requestBody),
679
          contentType: 'application/json',
680
          responseFormat: 'json' as ResponseFormat,
681
          auth: this.auth,
682
          networkSession: this.networkSession,
683
          cancellationToken: cancellationToken,
684
        }),
685
      );
686
    return {
6✔
687
      ...deserializeCommentFull(response.data!),
688
      rawData: response.data!,
689
    };
690
  }
691
}
692
export interface CommentsManagerInput {
693
  readonly auth?: Authentication;
694
  readonly networkSession?: NetworkSession;
695
}
696
export function serializeUpdateCommentByIdRequestBody(
237✔
697
  val: UpdateCommentByIdRequestBody,
698
): SerializedData {
699
  return { ['message']: val.message };
3✔
700
}
701
export function deserializeUpdateCommentByIdRequestBody(
237✔
702
  val: SerializedData,
703
): UpdateCommentByIdRequestBody {
704
  if (!sdIsMap(val)) {
×
705
    throw new BoxSdkError({
×
706
      message: 'Expecting a map for "UpdateCommentByIdRequestBody"',
707
    });
708
  }
709
  if (!(val.message == void 0) && !sdIsString(val.message)) {
×
710
    throw new BoxSdkError({
×
711
      message:
712
        'Expecting string for "message" of type "UpdateCommentByIdRequestBody"',
713
    });
714
  }
715
  const message: undefined | string =
716
    val.message == void 0 ? void 0 : val.message;
×
717
  return { message: message } satisfies UpdateCommentByIdRequestBody;
×
718
}
719
export function serializeCreateCommentRequestBodyItemTypeField(
237✔
720
  val: CreateCommentRequestBodyItemTypeField,
721
): SerializedData {
722
  return val;
6✔
723
}
724
export function deserializeCreateCommentRequestBodyItemTypeField(
237✔
725
  val: SerializedData,
726
): CreateCommentRequestBodyItemTypeField {
727
  if (val == 'file') {
×
728
    return val;
×
729
  }
730
  if (val == 'comment') {
×
731
    return val;
×
732
  }
733
  throw new BoxSdkError({
×
734
    message: "Can't deserialize CreateCommentRequestBodyItemTypeField",
735
  });
736
}
737
export function serializeCreateCommentRequestBodyItemField(
237✔
738
  val: CreateCommentRequestBodyItemField,
739
): SerializedData {
740
  return {
6✔
741
    ['id']: val.id,
742
    ['type']: serializeCreateCommentRequestBodyItemTypeField(val.type),
743
  };
744
}
745
export function deserializeCreateCommentRequestBodyItemField(
237✔
746
  val: SerializedData,
747
): CreateCommentRequestBodyItemField {
748
  if (!sdIsMap(val)) {
×
749
    throw new BoxSdkError({
×
750
      message: 'Expecting a map for "CreateCommentRequestBodyItemField"',
751
    });
752
  }
753
  if (val.id == void 0) {
×
754
    throw new BoxSdkError({
×
755
      message:
756
        'Expecting "id" of type "CreateCommentRequestBodyItemField" to be defined',
757
    });
758
  }
759
  if (!sdIsString(val.id)) {
×
760
    throw new BoxSdkError({
×
761
      message:
762
        'Expecting string for "id" of type "CreateCommentRequestBodyItemField"',
763
    });
764
  }
765
  const id: string = val.id;
×
766
  if (val.type == void 0) {
×
767
    throw new BoxSdkError({
×
768
      message:
769
        'Expecting "type" of type "CreateCommentRequestBodyItemField" to be defined',
770
    });
771
  }
772
  const type: CreateCommentRequestBodyItemTypeField =
773
    deserializeCreateCommentRequestBodyItemTypeField(val.type);
×
774
  return { id: id, type: type } satisfies CreateCommentRequestBodyItemField;
×
775
}
776
export function serializeCreateCommentRequestBody(
237✔
777
  val: CreateCommentRequestBody,
778
): SerializedData {
779
  return {
6✔
780
    ['message']: val.message,
781
    ['tagged_message']: val.taggedMessage,
782
    ['item']: serializeCreateCommentRequestBodyItemField(val.item),
783
  };
784
}
785
export function deserializeCreateCommentRequestBody(
237✔
786
  val: SerializedData,
787
): CreateCommentRequestBody {
788
  if (!sdIsMap(val)) {
×
789
    throw new BoxSdkError({
×
790
      message: 'Expecting a map for "CreateCommentRequestBody"',
791
    });
792
  }
793
  if (val.message == void 0) {
×
794
    throw new BoxSdkError({
×
795
      message:
796
        'Expecting "message" of type "CreateCommentRequestBody" to be defined',
797
    });
798
  }
799
  if (!sdIsString(val.message)) {
×
800
    throw new BoxSdkError({
×
801
      message:
802
        'Expecting string for "message" of type "CreateCommentRequestBody"',
803
    });
804
  }
805
  const message: string = val.message;
×
806
  if (!(val.tagged_message == void 0) && !sdIsString(val.tagged_message)) {
×
807
    throw new BoxSdkError({
×
808
      message:
809
        'Expecting string for "tagged_message" of type "CreateCommentRequestBody"',
810
    });
811
  }
812
  const taggedMessage: undefined | string =
813
    val.tagged_message == void 0 ? void 0 : val.tagged_message;
×
814
  if (val.item == void 0) {
×
815
    throw new BoxSdkError({
×
816
      message:
817
        'Expecting "item" of type "CreateCommentRequestBody" to be defined',
818
    });
819
  }
820
  const item: CreateCommentRequestBodyItemField =
821
    deserializeCreateCommentRequestBodyItemField(val.item);
×
822
  return {
×
823
    message: message,
824
    taggedMessage: taggedMessage,
825
    item: item,
826
  } satisfies CreateCommentRequestBody;
827
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc