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

box / box-typescript-sdk-gen / 11854841369

15 Nov 2024 10:45AM UTC coverage: 41.72%. First build
11854841369

Pull #415

github

web-flow
Merge c30dc5fb7 into e48500756
Pull Request #415: fix: Support status codes with no content (box/box-codegen#604)

4062 of 16843 branches covered (24.12%)

Branch coverage included in aggregate %.

9 of 13 new or added lines in 5 files covered. (69.23%)

13377 of 24957 relevant lines covered (53.6%)

77.71 hits per line

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

61.77
/src/managers/chunkedUploads.generated.ts
1
import { serializeFileFull } from '../schemas/fileFull.generated.js';
2
import { deserializeFileFull } from '../schemas/fileFull.generated.js';
3
import { serializeUploadSession } from '../schemas/uploadSession.generated.js';
4
import { deserializeUploadSession } from '../schemas/uploadSession.generated.js';
140✔
5
import { serializeClientError } from '../schemas/clientError.generated.js';
6
import { deserializeClientError } from '../schemas/clientError.generated.js';
7
import { serializeUploadedPart } from '../schemas/uploadedPart.generated.js';
8
import { deserializeUploadedPart } from '../schemas/uploadedPart.generated.js';
140✔
9
import { serializeUploadParts } from '../schemas/uploadParts.generated.js';
10
import { deserializeUploadParts } from '../schemas/uploadParts.generated.js';
140✔
11
import { serializeFiles } from '../schemas/files.generated.js';
12
import { deserializeFiles } from '../schemas/files.generated.js';
140✔
13
import { serializeUploadPart } from '../schemas/uploadPart.generated.js';
140✔
14
import { deserializeUploadPart } from '../schemas/uploadPart.generated.js';
140✔
15
import { Buffer } from '../internal/utils.js';
16
import { HashName } from '../internal/utils.js';
17
import { FileFull } from '../schemas/fileFull.generated.js';
18
import { Iterator } from '../internal/utils.js';
19
import { UploadSession } from '../schemas/uploadSession.generated.js';
20
import { ClientError } from '../schemas/clientError.generated.js';
21
import { UploadedPart } from '../schemas/uploadedPart.generated.js';
22
import { UploadParts } from '../schemas/uploadParts.generated.js';
23
import { Files } from '../schemas/files.generated.js';
24
import { UploadPart } from '../schemas/uploadPart.generated.js';
25
import { Authentication } from '../networking/auth.generated.js';
26
import { NetworkSession } from '../networking/network.generated.js';
140✔
27
import { prepareParams } from '../internal/utils.js';
140✔
28
import { toString } from '../internal/utils.js';
140✔
29
import { ByteStream } from '../internal/utils.js';
30
import { CancellationToken } from '../internal/utils.js';
31
import { FetchOptions } from '../networking/fetch.js';
32
import { FetchResponse } from '../networking/fetch.js';
33
import { fetch } from '../networking/fetch.js';
140✔
34
import { SerializedData } from '../serialization/json.js';
35
import { sdToJson } from '../serialization/json.js';
36
import { generateByteStreamFromBuffer } from '../internal/utils.js';
140✔
37
import { hexToBase64 } from '../internal/utils.js';
140✔
38
import { iterateChunks } from '../internal/utils.js';
140✔
39
import { readByteStream } from '../internal/utils.js';
140✔
40
import { reduceIterator } from '../internal/utils.js';
140✔
41
import { Hash } from '../internal/utils.js';
140✔
42
import { bufferLength } from '../internal/utils.js';
140✔
43
import { BoxSdkError } from '../box/errors.js';
140✔
44
import { sdIsEmpty } from '../serialization/json.js';
45
import { sdIsBoolean } from '../serialization/json.js';
46
import { sdIsNumber } from '../serialization/json.js';
140✔
47
import { sdIsString } from '../serialization/json.js';
140✔
48
import { sdIsList } from '../serialization/json.js';
140✔
49
import { sdIsMap } from '../serialization/json.js';
140✔
50
export class CreateFileUploadSessionOptionals {
140✔
51
  readonly headers: CreateFileUploadSessionHeaders =
6✔
52
    new CreateFileUploadSessionHeaders({});
53
  readonly cancellationToken?: CancellationToken = void 0;
6✔
54
  constructor(
55
    fields: Omit<
56
      CreateFileUploadSessionOptionals,
57
      'headers' | 'cancellationToken'
58
    > &
59
      Partial<
60
        Pick<CreateFileUploadSessionOptionals, 'headers' | 'cancellationToken'>
61
      >,
62
  ) {
63
    if (fields.headers) {
6✔
64
      this.headers = fields.headers;
2✔
65
    }
66
    if (fields.cancellationToken) {
6!
67
      this.cancellationToken = fields.cancellationToken;
×
68
    }
69
  }
70
}
71
export interface CreateFileUploadSessionOptionalsInput {
72
  readonly headers?: CreateFileUploadSessionHeaders;
73
  readonly cancellationToken?: undefined | CancellationToken;
74
}
75
export class CreateFileUploadSessionForExistingFileOptionals {
140✔
76
  readonly headers: CreateFileUploadSessionForExistingFileHeaders =
×
77
    new CreateFileUploadSessionForExistingFileHeaders({});
78
  readonly cancellationToken?: CancellationToken = void 0;
×
79
  constructor(
80
    fields: Omit<
81
      CreateFileUploadSessionForExistingFileOptionals,
82
      'headers' | 'cancellationToken'
83
    > &
84
      Partial<
85
        Pick<
86
          CreateFileUploadSessionForExistingFileOptionals,
87
          'headers' | 'cancellationToken'
88
        >
89
      >,
90
  ) {
91
    if (fields.headers) {
×
92
      this.headers = fields.headers;
×
93
    }
94
    if (fields.cancellationToken) {
×
95
      this.cancellationToken = fields.cancellationToken;
×
96
    }
97
  }
98
}
99
export interface CreateFileUploadSessionForExistingFileOptionalsInput {
100
  readonly headers?: CreateFileUploadSessionForExistingFileHeaders;
101
  readonly cancellationToken?: undefined | CancellationToken;
102
}
103
export class GetFileUploadSessionByUrlOptionals {
140✔
104
  readonly headers: GetFileUploadSessionByUrlHeaders =
2✔
105
    new GetFileUploadSessionByUrlHeaders({});
106
  readonly cancellationToken?: CancellationToken = void 0;
2✔
107
  constructor(
108
    fields: Omit<
109
      GetFileUploadSessionByUrlOptionals,
110
      'headers' | 'cancellationToken'
111
    > &
112
      Partial<
113
        Pick<
114
          GetFileUploadSessionByUrlOptionals,
115
          'headers' | 'cancellationToken'
116
        >
117
      >,
118
  ) {
119
    if (fields.headers) {
2!
120
      this.headers = fields.headers;
×
121
    }
122
    if (fields.cancellationToken) {
2!
123
      this.cancellationToken = fields.cancellationToken;
×
124
    }
125
  }
126
}
127
export interface GetFileUploadSessionByUrlOptionalsInput {
128
  readonly headers?: GetFileUploadSessionByUrlHeaders;
129
  readonly cancellationToken?: undefined | CancellationToken;
130
}
131
export class GetFileUploadSessionByIdOptionals {
140✔
132
  readonly headers: GetFileUploadSessionByIdHeaders =
2✔
133
    new GetFileUploadSessionByIdHeaders({});
134
  readonly cancellationToken?: CancellationToken = void 0;
2✔
135
  constructor(
136
    fields: Omit<
137
      GetFileUploadSessionByIdOptionals,
138
      'headers' | 'cancellationToken'
139
    > &
140
      Partial<
141
        Pick<GetFileUploadSessionByIdOptionals, 'headers' | 'cancellationToken'>
142
      >,
143
  ) {
144
    if (fields.headers) {
2!
145
      this.headers = fields.headers;
×
146
    }
147
    if (fields.cancellationToken) {
2!
148
      this.cancellationToken = fields.cancellationToken;
×
149
    }
150
  }
151
}
152
export interface GetFileUploadSessionByIdOptionalsInput {
153
  readonly headers?: GetFileUploadSessionByIdHeaders;
154
  readonly cancellationToken?: undefined | CancellationToken;
155
}
156
export class UploadFilePartByUrlOptionals {
140✔
157
  readonly cancellationToken?: CancellationToken = void 0;
10✔
158
  constructor(
159
    fields: Omit<UploadFilePartByUrlOptionals, 'cancellationToken'> &
160
      Partial<Pick<UploadFilePartByUrlOptionals, 'cancellationToken'>>,
161
  ) {
162
    if (fields.cancellationToken) {
10!
163
      this.cancellationToken = fields.cancellationToken;
×
164
    }
165
  }
166
}
167
export interface UploadFilePartByUrlOptionalsInput {
168
  readonly cancellationToken?: undefined | CancellationToken;
169
}
170
export class UploadFilePartOptionals {
140✔
171
  readonly cancellationToken?: CancellationToken = void 0;
5✔
172
  constructor(
173
    fields: Omit<UploadFilePartOptionals, 'cancellationToken'> &
174
      Partial<Pick<UploadFilePartOptionals, 'cancellationToken'>>,
175
  ) {
176
    if (fields.cancellationToken) {
5!
177
      this.cancellationToken = fields.cancellationToken;
×
178
    }
179
  }
180
}
181
export interface UploadFilePartOptionalsInput {
182
  readonly cancellationToken?: undefined | CancellationToken;
183
}
184
export class DeleteFileUploadSessionByUrlOptionals {
140✔
185
  readonly headers: DeleteFileUploadSessionByUrlHeaders =
2✔
186
    new DeleteFileUploadSessionByUrlHeaders({});
187
  readonly cancellationToken?: CancellationToken = void 0;
2✔
188
  constructor(
189
    fields: Omit<
190
      DeleteFileUploadSessionByUrlOptionals,
191
      'headers' | 'cancellationToken'
192
    > &
193
      Partial<
194
        Pick<
195
          DeleteFileUploadSessionByUrlOptionals,
196
          'headers' | 'cancellationToken'
197
        >
198
      >,
199
  ) {
200
    if (fields.headers) {
2!
201
      this.headers = fields.headers;
×
202
    }
203
    if (fields.cancellationToken) {
2!
204
      this.cancellationToken = fields.cancellationToken;
×
205
    }
206
  }
207
}
208
export interface DeleteFileUploadSessionByUrlOptionalsInput {
209
  readonly headers?: DeleteFileUploadSessionByUrlHeaders;
210
  readonly cancellationToken?: undefined | CancellationToken;
211
}
212
export class DeleteFileUploadSessionByIdOptionals {
140✔
213
  readonly headers: DeleteFileUploadSessionByIdHeaders =
2✔
214
    new DeleteFileUploadSessionByIdHeaders({});
215
  readonly cancellationToken?: CancellationToken = void 0;
2✔
216
  constructor(
217
    fields: Omit<
218
      DeleteFileUploadSessionByIdOptionals,
219
      'headers' | 'cancellationToken'
220
    > &
221
      Partial<
222
        Pick<
223
          DeleteFileUploadSessionByIdOptionals,
224
          'headers' | 'cancellationToken'
225
        >
226
      >,
227
  ) {
228
    if (fields.headers) {
2!
229
      this.headers = fields.headers;
×
230
    }
231
    if (fields.cancellationToken) {
2!
232
      this.cancellationToken = fields.cancellationToken;
×
233
    }
234
  }
235
}
236
export interface DeleteFileUploadSessionByIdOptionalsInput {
237
  readonly headers?: DeleteFileUploadSessionByIdHeaders;
238
  readonly cancellationToken?: undefined | CancellationToken;
239
}
240
export class GetFileUploadSessionPartsByUrlOptionals {
140✔
241
  readonly queryParams: GetFileUploadSessionPartsByUrlQueryParams =
4✔
242
    {} satisfies GetFileUploadSessionPartsByUrlQueryParams;
243
  readonly headers: GetFileUploadSessionPartsByUrlHeaders =
4✔
244
    new GetFileUploadSessionPartsByUrlHeaders({});
245
  readonly cancellationToken?: CancellationToken = void 0;
4✔
246
  constructor(
247
    fields: Omit<
248
      GetFileUploadSessionPartsByUrlOptionals,
249
      'queryParams' | 'headers' | 'cancellationToken'
250
    > &
251
      Partial<
252
        Pick<
253
          GetFileUploadSessionPartsByUrlOptionals,
254
          'queryParams' | 'headers' | 'cancellationToken'
255
        >
256
      >,
257
  ) {
258
    if (fields.queryParams) {
4✔
259
      this.queryParams = fields.queryParams;
2✔
260
    }
261
    if (fields.headers) {
4✔
262
      this.headers = fields.headers;
2✔
263
    }
264
    if (fields.cancellationToken) {
4!
265
      this.cancellationToken = fields.cancellationToken;
×
266
    }
267
  }
268
}
269
export interface GetFileUploadSessionPartsByUrlOptionalsInput {
270
  readonly queryParams?: GetFileUploadSessionPartsByUrlQueryParams;
271
  readonly headers?: GetFileUploadSessionPartsByUrlHeaders;
272
  readonly cancellationToken?: undefined | CancellationToken;
273
}
274
export class GetFileUploadSessionPartsOptionals {
140✔
275
  readonly queryParams: GetFileUploadSessionPartsQueryParams =
2✔
276
    {} satisfies GetFileUploadSessionPartsQueryParams;
277
  readonly headers: GetFileUploadSessionPartsHeaders =
2✔
278
    new GetFileUploadSessionPartsHeaders({});
279
  readonly cancellationToken?: CancellationToken = void 0;
2✔
280
  constructor(
281
    fields: Omit<
282
      GetFileUploadSessionPartsOptionals,
283
      'queryParams' | 'headers' | 'cancellationToken'
284
    > &
285
      Partial<
286
        Pick<
287
          GetFileUploadSessionPartsOptionals,
288
          'queryParams' | 'headers' | 'cancellationToken'
289
        >
290
      >,
291
  ) {
292
    if (fields.queryParams) {
2!
293
      this.queryParams = fields.queryParams;
×
294
    }
295
    if (fields.headers) {
2!
296
      this.headers = fields.headers;
×
297
    }
298
    if (fields.cancellationToken) {
2!
299
      this.cancellationToken = fields.cancellationToken;
×
300
    }
301
  }
302
}
303
export interface GetFileUploadSessionPartsOptionalsInput {
304
  readonly queryParams?: GetFileUploadSessionPartsQueryParams;
305
  readonly headers?: GetFileUploadSessionPartsHeaders;
306
  readonly cancellationToken?: undefined | CancellationToken;
307
}
308
export class CreateFileUploadSessionCommitByUrlOptionals {
140✔
309
  readonly cancellationToken?: CancellationToken = void 0;
4✔
310
  constructor(
311
    fields: Omit<
312
      CreateFileUploadSessionCommitByUrlOptionals,
313
      'cancellationToken'
314
    > &
315
      Partial<
316
        Pick<CreateFileUploadSessionCommitByUrlOptionals, 'cancellationToken'>
317
      >,
318
  ) {
319
    if (fields.cancellationToken) {
4!
320
      this.cancellationToken = fields.cancellationToken;
×
321
    }
322
  }
323
}
324
export interface CreateFileUploadSessionCommitByUrlOptionalsInput {
325
  readonly cancellationToken?: undefined | CancellationToken;
326
}
327
export class CreateFileUploadSessionCommitOptionals {
140✔
328
  readonly cancellationToken?: CancellationToken = void 0;
2✔
329
  constructor(
330
    fields: Omit<CreateFileUploadSessionCommitOptionals, 'cancellationToken'> &
331
      Partial<
332
        Pick<CreateFileUploadSessionCommitOptionals, 'cancellationToken'>
333
      >,
334
  ) {
335
    if (fields.cancellationToken) {
2!
336
      this.cancellationToken = fields.cancellationToken;
×
337
    }
338
  }
339
}
340
export interface CreateFileUploadSessionCommitOptionalsInput {
341
  readonly cancellationToken?: undefined | CancellationToken;
342
}
343
interface PartAccumulator {
344
  readonly lastIndex: number;
345
  readonly parts: readonly UploadPart[];
346
  readonly fileSize: number;
347
  readonly uploadPartUrl: string;
348
  readonly fileHash: Hash;
349
}
350
export interface CreateFileUploadSessionRequestBody {
351
  /**
352
   * The ID of the folder to upload the new file to. */
353
  readonly folderId: string;
354
  /**
355
   * The total number of bytes of the file to be uploaded */
356
  readonly fileSize: number;
357
  /**
358
   * The name of new file */
359
  readonly fileName: string;
360
  readonly rawData?: SerializedData;
361
}
362
export class CreateFileUploadSessionHeaders {
140✔
363
  /**
364
   * Extra headers that will be included in the HTTP request. */
365
  readonly extraHeaders?: {
8✔
366
    readonly [key: string]: undefined | string;
367
  } = {};
368
  constructor(
369
    fields: Omit<CreateFileUploadSessionHeaders, 'extraHeaders'> &
370
      Partial<Pick<CreateFileUploadSessionHeaders, 'extraHeaders'>>,
371
  ) {
372
    if (fields.extraHeaders) {
8!
373
      this.extraHeaders = fields.extraHeaders;
×
374
    }
375
  }
376
}
377
export interface CreateFileUploadSessionHeadersInput {
378
  /**
379
   * Extra headers that will be included in the HTTP request. */
380
  readonly extraHeaders?:
381
    | undefined
382
    | {
383
        readonly [key: string]: undefined | string;
384
      };
385
}
386
export interface CreateFileUploadSessionForExistingFileRequestBody {
387
  /**
388
   * The total number of bytes of the file to be uploaded */
389
  readonly fileSize: number;
390
  /**
391
   * The optional new name of new file */
392
  readonly fileName?: string;
393
  readonly rawData?: SerializedData;
394
}
395
export class CreateFileUploadSessionForExistingFileHeaders {
140✔
396
  /**
397
   * Extra headers that will be included in the HTTP request. */
398
  readonly extraHeaders?: {
×
399
    readonly [key: string]: undefined | string;
400
  } = {};
401
  constructor(
402
    fields: Omit<
403
      CreateFileUploadSessionForExistingFileHeaders,
404
      'extraHeaders'
405
    > &
406
      Partial<
407
        Pick<CreateFileUploadSessionForExistingFileHeaders, 'extraHeaders'>
408
      >,
409
  ) {
410
    if (fields.extraHeaders) {
×
411
      this.extraHeaders = fields.extraHeaders;
×
412
    }
413
  }
414
}
415
export interface CreateFileUploadSessionForExistingFileHeadersInput {
416
  /**
417
   * Extra headers that will be included in the HTTP request. */
418
  readonly extraHeaders?:
419
    | undefined
420
    | {
421
        readonly [key: string]: undefined | string;
422
      };
423
}
424
export class GetFileUploadSessionByUrlHeaders {
140✔
425
  /**
426
   * Extra headers that will be included in the HTTP request. */
427
  readonly extraHeaders?: {
2✔
428
    readonly [key: string]: undefined | string;
429
  } = {};
430
  constructor(
431
    fields: Omit<GetFileUploadSessionByUrlHeaders, 'extraHeaders'> &
432
      Partial<Pick<GetFileUploadSessionByUrlHeaders, 'extraHeaders'>>,
433
  ) {
434
    if (fields.extraHeaders) {
2!
435
      this.extraHeaders = fields.extraHeaders;
×
436
    }
437
  }
438
}
439
export interface GetFileUploadSessionByUrlHeadersInput {
440
  /**
441
   * Extra headers that will be included in the HTTP request. */
442
  readonly extraHeaders?:
443
    | undefined
444
    | {
445
        readonly [key: string]: undefined | string;
446
      };
447
}
448
export class GetFileUploadSessionByIdHeaders {
140✔
449
  /**
450
   * Extra headers that will be included in the HTTP request. */
451
  readonly extraHeaders?: {
2✔
452
    readonly [key: string]: undefined | string;
453
  } = {};
454
  constructor(
455
    fields: Omit<GetFileUploadSessionByIdHeaders, 'extraHeaders'> &
456
      Partial<Pick<GetFileUploadSessionByIdHeaders, 'extraHeaders'>>,
457
  ) {
458
    if (fields.extraHeaders) {
2!
459
      this.extraHeaders = fields.extraHeaders;
×
460
    }
461
  }
462
}
463
export interface GetFileUploadSessionByIdHeadersInput {
464
  /**
465
   * Extra headers that will be included in the HTTP request. */
466
  readonly extraHeaders?:
467
    | undefined
468
    | {
469
        readonly [key: string]: undefined | string;
470
      };
471
}
472
export class UploadFilePartByUrlHeaders {
140✔
473
  /**
474
   * The [RFC3230][1] message digest of the chunk uploaded.
475
   *
476
   * Only SHA1 is supported. The SHA1 digest must be base64
477
   * encoded. The format of this header is as
478
   * `sha=BASE64_ENCODED_DIGEST`.
479
   *
480
   * To get the value for the `SHA` digest, use the
481
   * openSSL command to encode the file part:
482
   * `openssl sha1 -binary <FILE_PART_NAME> | base64`
483
   *
484
   * [1]: https://tools.ietf.org/html/rfc3230 */
485
  readonly digest!: string;
486
  /**
487
   * The byte range of the chunk.
488
   *
489
   * Must not overlap with the range of a part already
490
   * uploaded this session. Each part’s size must be
491
   * exactly equal in size to the part size specified
492
   * in the upload session that you created.
493
   * One exception is the last part of the file, as this can be smaller.
494
   *
495
   * When providing the value for `content-range`, remember that:
496
   *
497
   * * The lower bound of each part's byte range
498
   *   must be a multiple of the part size.
499
   * * The higher bound must be a multiple of the part size - 1. */
500
  readonly contentRange!: string;
501
  /**
502
   * Extra headers that will be included in the HTTP request. */
503
  readonly extraHeaders?: {
10✔
504
    readonly [key: string]: undefined | string;
505
  } = {};
506
  constructor(
507
    fields: Omit<UploadFilePartByUrlHeaders, 'extraHeaders'> &
508
      Partial<Pick<UploadFilePartByUrlHeaders, 'extraHeaders'>>,
509
  ) {
510
    if (fields.digest) {
10✔
511
      this.digest = fields.digest;
10✔
512
    }
513
    if (fields.contentRange) {
10✔
514
      this.contentRange = fields.contentRange;
10✔
515
    }
516
    if (fields.extraHeaders) {
10!
517
      this.extraHeaders = fields.extraHeaders;
×
518
    }
519
  }
520
}
521
export interface UploadFilePartByUrlHeadersInput {
522
  /**
523
   * The [RFC3230][1] message digest of the chunk uploaded.
524
   *
525
   * Only SHA1 is supported. The SHA1 digest must be base64
526
   * encoded. The format of this header is as
527
   * `sha=BASE64_ENCODED_DIGEST`.
528
   *
529
   * To get the value for the `SHA` digest, use the
530
   * openSSL command to encode the file part:
531
   * `openssl sha1 -binary <FILE_PART_NAME> | base64`
532
   *
533
   * [1]: https://tools.ietf.org/html/rfc3230 */
534
  readonly digest: string;
535
  /**
536
   * The byte range of the chunk.
537
   *
538
   * Must not overlap with the range of a part already
539
   * uploaded this session. Each part’s size must be
540
   * exactly equal in size to the part size specified
541
   * in the upload session that you created.
542
   * One exception is the last part of the file, as this can be smaller.
543
   *
544
   * When providing the value for `content-range`, remember that:
545
   *
546
   * * The lower bound of each part's byte range
547
   *   must be a multiple of the part size.
548
   * * The higher bound must be a multiple of the part size - 1. */
549
  readonly contentRange: string;
550
  /**
551
   * Extra headers that will be included in the HTTP request. */
552
  readonly extraHeaders?:
553
    | undefined
554
    | {
555
        readonly [key: string]: undefined | string;
556
      };
557
}
558
export class UploadFilePartHeaders {
140✔
559
  /**
560
   * The [RFC3230][1] message digest of the chunk uploaded.
561
   *
562
   * Only SHA1 is supported. The SHA1 digest must be base64
563
   * encoded. The format of this header is as
564
   * `sha=BASE64_ENCODED_DIGEST`.
565
   *
566
   * To get the value for the `SHA` digest, use the
567
   * openSSL command to encode the file part:
568
   * `openssl sha1 -binary <FILE_PART_NAME> | base64`
569
   *
570
   * [1]: https://tools.ietf.org/html/rfc3230 */
571
  readonly digest!: string;
572
  /**
573
   * The byte range of the chunk.
574
   *
575
   * Must not overlap with the range of a part already
576
   * uploaded this session. Each part’s size must be
577
   * exactly equal in size to the part size specified
578
   * in the upload session that you created.
579
   * One exception is the last part of the file, as this can be smaller.
580
   *
581
   * When providing the value for `content-range`, remember that:
582
   *
583
   * * The lower bound of each part's byte range
584
   *   must be a multiple of the part size.
585
   * * The higher bound must be a multiple of the part size - 1. */
586
  readonly contentRange!: string;
587
  /**
588
   * Extra headers that will be included in the HTTP request. */
589
  readonly extraHeaders?: {
5✔
590
    readonly [key: string]: undefined | string;
591
  } = {};
592
  constructor(
593
    fields: Omit<UploadFilePartHeaders, 'extraHeaders'> &
594
      Partial<Pick<UploadFilePartHeaders, 'extraHeaders'>>,
595
  ) {
596
    if (fields.digest) {
5✔
597
      this.digest = fields.digest;
5✔
598
    }
599
    if (fields.contentRange) {
5✔
600
      this.contentRange = fields.contentRange;
5✔
601
    }
602
    if (fields.extraHeaders) {
5!
603
      this.extraHeaders = fields.extraHeaders;
×
604
    }
605
  }
606
}
607
export interface UploadFilePartHeadersInput {
608
  /**
609
   * The [RFC3230][1] message digest of the chunk uploaded.
610
   *
611
   * Only SHA1 is supported. The SHA1 digest must be base64
612
   * encoded. The format of this header is as
613
   * `sha=BASE64_ENCODED_DIGEST`.
614
   *
615
   * To get the value for the `SHA` digest, use the
616
   * openSSL command to encode the file part:
617
   * `openssl sha1 -binary <FILE_PART_NAME> | base64`
618
   *
619
   * [1]: https://tools.ietf.org/html/rfc3230 */
620
  readonly digest: string;
621
  /**
622
   * The byte range of the chunk.
623
   *
624
   * Must not overlap with the range of a part already
625
   * uploaded this session. Each part’s size must be
626
   * exactly equal in size to the part size specified
627
   * in the upload session that you created.
628
   * One exception is the last part of the file, as this can be smaller.
629
   *
630
   * When providing the value for `content-range`, remember that:
631
   *
632
   * * The lower bound of each part's byte range
633
   *   must be a multiple of the part size.
634
   * * The higher bound must be a multiple of the part size - 1. */
635
  readonly contentRange: string;
636
  /**
637
   * Extra headers that will be included in the HTTP request. */
638
  readonly extraHeaders?:
639
    | undefined
640
    | {
641
        readonly [key: string]: undefined | string;
642
      };
643
}
644
export class DeleteFileUploadSessionByUrlHeaders {
140✔
645
  /**
646
   * Extra headers that will be included in the HTTP request. */
647
  readonly extraHeaders?: {
2✔
648
    readonly [key: string]: undefined | string;
649
  } = {};
650
  constructor(
651
    fields: Omit<DeleteFileUploadSessionByUrlHeaders, 'extraHeaders'> &
652
      Partial<Pick<DeleteFileUploadSessionByUrlHeaders, 'extraHeaders'>>,
653
  ) {
654
    if (fields.extraHeaders) {
2!
655
      this.extraHeaders = fields.extraHeaders;
×
656
    }
657
  }
658
}
659
export interface DeleteFileUploadSessionByUrlHeadersInput {
660
  /**
661
   * Extra headers that will be included in the HTTP request. */
662
  readonly extraHeaders?:
663
    | undefined
664
    | {
665
        readonly [key: string]: undefined | string;
666
      };
667
}
668
export class DeleteFileUploadSessionByIdHeaders {
140✔
669
  /**
670
   * Extra headers that will be included in the HTTP request. */
671
  readonly extraHeaders?: {
2✔
672
    readonly [key: string]: undefined | string;
673
  } = {};
674
  constructor(
675
    fields: Omit<DeleteFileUploadSessionByIdHeaders, 'extraHeaders'> &
676
      Partial<Pick<DeleteFileUploadSessionByIdHeaders, 'extraHeaders'>>,
677
  ) {
678
    if (fields.extraHeaders) {
2!
679
      this.extraHeaders = fields.extraHeaders;
×
680
    }
681
  }
682
}
683
export interface DeleteFileUploadSessionByIdHeadersInput {
684
  /**
685
   * Extra headers that will be included in the HTTP request. */
686
  readonly extraHeaders?:
687
    | undefined
688
    | {
689
        readonly [key: string]: undefined | string;
690
      };
691
}
692
export interface GetFileUploadSessionPartsByUrlQueryParams {
693
  /**
694
   * The offset of the item at which to begin the response.
695
   *
696
   * Queries with offset parameter value
697
   * exceeding 10000 will be rejected
698
   * with a 400 response. */
699
  readonly offset?: number;
700
  /**
701
   * The maximum number of items to return per page. */
702
  readonly limit?: number;
703
}
704
export class GetFileUploadSessionPartsByUrlHeaders {
140✔
705
  /**
706
   * Extra headers that will be included in the HTTP request. */
707
  readonly extraHeaders?: {
6✔
708
    readonly [key: string]: undefined | string;
709
  } = {};
710
  constructor(
711
    fields: Omit<GetFileUploadSessionPartsByUrlHeaders, 'extraHeaders'> &
712
      Partial<Pick<GetFileUploadSessionPartsByUrlHeaders, 'extraHeaders'>>,
713
  ) {
714
    if (fields.extraHeaders) {
6!
715
      this.extraHeaders = fields.extraHeaders;
×
716
    }
717
  }
718
}
719
export interface GetFileUploadSessionPartsByUrlHeadersInput {
720
  /**
721
   * Extra headers that will be included in the HTTP request. */
722
  readonly extraHeaders?:
723
    | undefined
724
    | {
725
        readonly [key: string]: undefined | string;
726
      };
727
}
728
export interface GetFileUploadSessionPartsQueryParams {
729
  /**
730
   * The offset of the item at which to begin the response.
731
   *
732
   * Queries with offset parameter value
733
   * exceeding 10000 will be rejected
734
   * with a 400 response. */
735
  readonly offset?: number;
736
  /**
737
   * The maximum number of items to return per page. */
738
  readonly limit?: number;
739
}
740
export class GetFileUploadSessionPartsHeaders {
140✔
741
  /**
742
   * Extra headers that will be included in the HTTP request. */
743
  readonly extraHeaders?: {
2✔
744
    readonly [key: string]: undefined | string;
745
  } = {};
746
  constructor(
747
    fields: Omit<GetFileUploadSessionPartsHeaders, 'extraHeaders'> &
748
      Partial<Pick<GetFileUploadSessionPartsHeaders, 'extraHeaders'>>,
749
  ) {
750
    if (fields.extraHeaders) {
2!
751
      this.extraHeaders = fields.extraHeaders;
×
752
    }
753
  }
754
}
755
export interface GetFileUploadSessionPartsHeadersInput {
756
  /**
757
   * Extra headers that will be included in the HTTP request. */
758
  readonly extraHeaders?:
759
    | undefined
760
    | {
761
        readonly [key: string]: undefined | string;
762
      };
763
}
764
export interface CreateFileUploadSessionCommitByUrlRequestBody {
765
  /**
766
   * The list details for the uploaded parts */
767
  readonly parts: readonly UploadPart[];
768
  readonly rawData?: SerializedData;
769
}
770
export class CreateFileUploadSessionCommitByUrlHeaders {
140✔
771
  /**
772
   * The [RFC3230][1] message digest of the whole file.
773
   *
774
   * Only SHA1 is supported. The SHA1 digest must be Base64
775
   * encoded. The format of this header is as
776
   * `sha=BASE64_ENCODED_DIGEST`.
777
   *
778
   * [1]: https://tools.ietf.org/html/rfc3230 */
779
  readonly digest!: string;
780
  /**
781
   * Ensures this item hasn't recently changed before
782
   * making changes.
783
   *
784
   * Pass in the item's last observed `etag` value
785
   * into this header and the endpoint will fail
786
   * with a `412 Precondition Failed` if it
787
   * has changed since. */
788
  readonly ifMatch?: string;
789
  /**
790
   * Ensures an item is only returned if it has changed.
791
   *
792
   * Pass in the item's last observed `etag` value
793
   * into this header and the endpoint will fail
794
   * with a `304 Not Modified` if the item has not
795
   * changed since. */
796
  readonly ifNoneMatch?: string;
797
  /**
798
   * Extra headers that will be included in the HTTP request. */
799
  readonly extraHeaders?: {
4✔
800
    readonly [key: string]: undefined | string;
801
  } = {};
802
  constructor(
803
    fields: Omit<CreateFileUploadSessionCommitByUrlHeaders, 'extraHeaders'> &
804
      Partial<Pick<CreateFileUploadSessionCommitByUrlHeaders, 'extraHeaders'>>,
805
  ) {
806
    if (fields.digest) {
4✔
807
      this.digest = fields.digest;
4✔
808
    }
809
    if (fields.ifMatch) {
4!
810
      this.ifMatch = fields.ifMatch;
×
811
    }
812
    if (fields.ifNoneMatch) {
4!
813
      this.ifNoneMatch = fields.ifNoneMatch;
×
814
    }
815
    if (fields.extraHeaders) {
4!
816
      this.extraHeaders = fields.extraHeaders;
×
817
    }
818
  }
819
}
820
export interface CreateFileUploadSessionCommitByUrlHeadersInput {
821
  /**
822
   * The [RFC3230][1] message digest of the whole file.
823
   *
824
   * Only SHA1 is supported. The SHA1 digest must be Base64
825
   * encoded. The format of this header is as
826
   * `sha=BASE64_ENCODED_DIGEST`.
827
   *
828
   * [1]: https://tools.ietf.org/html/rfc3230 */
829
  readonly digest: string;
830
  /**
831
   * Ensures this item hasn't recently changed before
832
   * making changes.
833
   *
834
   * Pass in the item's last observed `etag` value
835
   * into this header and the endpoint will fail
836
   * with a `412 Precondition Failed` if it
837
   * has changed since. */
838
  readonly ifMatch?: string;
839
  /**
840
   * Ensures an item is only returned if it has changed.
841
   *
842
   * Pass in the item's last observed `etag` value
843
   * into this header and the endpoint will fail
844
   * with a `304 Not Modified` if the item has not
845
   * changed since. */
846
  readonly ifNoneMatch?: string;
847
  /**
848
   * Extra headers that will be included in the HTTP request. */
849
  readonly extraHeaders?:
850
    | undefined
851
    | {
852
        readonly [key: string]: undefined | string;
853
      };
854
}
855
export interface CreateFileUploadSessionCommitRequestBody {
856
  /**
857
   * The list details for the uploaded parts */
858
  readonly parts: readonly UploadPart[];
859
  readonly rawData?: SerializedData;
860
}
861
export class CreateFileUploadSessionCommitHeaders {
140✔
862
  /**
863
   * The [RFC3230][1] message digest of the whole file.
864
   *
865
   * Only SHA1 is supported. The SHA1 digest must be Base64
866
   * encoded. The format of this header is as
867
   * `sha=BASE64_ENCODED_DIGEST`.
868
   *
869
   * [1]: https://tools.ietf.org/html/rfc3230 */
870
  readonly digest!: string;
871
  /**
872
   * Ensures this item hasn't recently changed before
873
   * making changes.
874
   *
875
   * Pass in the item's last observed `etag` value
876
   * into this header and the endpoint will fail
877
   * with a `412 Precondition Failed` if it
878
   * has changed since. */
879
  readonly ifMatch?: string;
880
  /**
881
   * Ensures an item is only returned if it has changed.
882
   *
883
   * Pass in the item's last observed `etag` value
884
   * into this header and the endpoint will fail
885
   * with a `304 Not Modified` if the item has not
886
   * changed since. */
887
  readonly ifNoneMatch?: string;
888
  /**
889
   * Extra headers that will be included in the HTTP request. */
890
  readonly extraHeaders?: {
2✔
891
    readonly [key: string]: undefined | string;
892
  } = {};
893
  constructor(
894
    fields: Omit<CreateFileUploadSessionCommitHeaders, 'extraHeaders'> &
895
      Partial<Pick<CreateFileUploadSessionCommitHeaders, 'extraHeaders'>>,
896
  ) {
897
    if (fields.digest) {
2✔
898
      this.digest = fields.digest;
2✔
899
    }
900
    if (fields.ifMatch) {
2!
901
      this.ifMatch = fields.ifMatch;
×
902
    }
903
    if (fields.ifNoneMatch) {
2!
904
      this.ifNoneMatch = fields.ifNoneMatch;
×
905
    }
906
    if (fields.extraHeaders) {
2!
907
      this.extraHeaders = fields.extraHeaders;
×
908
    }
909
  }
910
}
911
export interface CreateFileUploadSessionCommitHeadersInput {
912
  /**
913
   * The [RFC3230][1] message digest of the whole file.
914
   *
915
   * Only SHA1 is supported. The SHA1 digest must be Base64
916
   * encoded. The format of this header is as
917
   * `sha=BASE64_ENCODED_DIGEST`.
918
   *
919
   * [1]: https://tools.ietf.org/html/rfc3230 */
920
  readonly digest: string;
921
  /**
922
   * Ensures this item hasn't recently changed before
923
   * making changes.
924
   *
925
   * Pass in the item's last observed `etag` value
926
   * into this header and the endpoint will fail
927
   * with a `412 Precondition Failed` if it
928
   * has changed since. */
929
  readonly ifMatch?: string;
930
  /**
931
   * Ensures an item is only returned if it has changed.
932
   *
933
   * Pass in the item's last observed `etag` value
934
   * into this header and the endpoint will fail
935
   * with a `304 Not Modified` if the item has not
936
   * changed since. */
937
  readonly ifNoneMatch?: string;
938
  /**
939
   * Extra headers that will be included in the HTTP request. */
940
  readonly extraHeaders?:
941
    | undefined
942
    | {
943
        readonly [key: string]: undefined | string;
944
      };
945
}
946
export class ChunkedUploadsManager {
140✔
947
  readonly auth?: Authentication;
948
  readonly networkSession: NetworkSession = new NetworkSession({});
298✔
949
  constructor(
950
    fields: Omit<
951
      ChunkedUploadsManager,
952
      | 'networkSession'
953
      | 'createFileUploadSession'
954
      | 'createFileUploadSessionForExistingFile'
955
      | 'getFileUploadSessionByUrl'
956
      | 'getFileUploadSessionById'
957
      | 'uploadFilePartByUrl'
958
      | 'uploadFilePart'
959
      | 'deleteFileUploadSessionByUrl'
960
      | 'deleteFileUploadSessionById'
961
      | 'getFileUploadSessionPartsByUrl'
962
      | 'getFileUploadSessionParts'
963
      | 'createFileUploadSessionCommitByUrl'
964
      | 'createFileUploadSessionCommit'
965
      | 'reducer'
966
      | 'uploadBigFile'
967
    > &
968
      Partial<Pick<ChunkedUploadsManager, 'networkSession'>>,
969
  ) {
970
    if (fields.auth) {
298✔
971
      this.auth = fields.auth;
298✔
972
    }
973
    if (fields.networkSession) {
298✔
974
      this.networkSession = fields.networkSession;
298✔
975
    }
976
  }
977
  /**
978
   * Creates an upload session for a new file.
979
   * @param {CreateFileUploadSessionRequestBody} requestBody Request body of createFileUploadSession method
980
   * @param {CreateFileUploadSessionOptionalsInput} optionalsInput
981
   * @returns {Promise<UploadSession>}
982
   */
983
  async createFileUploadSession(
984
    requestBody: CreateFileUploadSessionRequestBody,
6✔
985
    optionalsInput: CreateFileUploadSessionOptionalsInput = {},
4✔
986
  ): Promise<UploadSession> {
987
    const optionals: CreateFileUploadSessionOptionals =
988
      new CreateFileUploadSessionOptionals({
6✔
989
        headers: optionalsInput.headers,
990
        cancellationToken: optionalsInput.cancellationToken,
991
      });
992
    const headers: any = optionals.headers;
6✔
993
    const cancellationToken: any = optionals.cancellationToken;
6✔
994
    const headersMap: {
995
      readonly [key: string]: string;
996
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
997
    const response: FetchResponse = (await fetch({
6✔
998
      url: ''.concat(
999
        this.networkSession.baseUrls.uploadUrl,
1000
        '/2.0/files/upload_sessions',
1001
      ) as string,
1002
      method: 'POST',
1003
      headers: headersMap,
1004
      data: serializeCreateFileUploadSessionRequestBody(requestBody),
1005
      contentType: 'application/json',
1006
      responseFormat: 'json',
1007
      auth: this.auth,
1008
      networkSession: this.networkSession,
1009
      cancellationToken: cancellationToken,
1010
    } satisfies FetchOptions)) as FetchResponse;
1011
    return {
6✔
1012
      ...deserializeUploadSession(response.data),
1013
      rawData: response.data,
1014
    };
1015
  }
1016
  /**
1017
     * Creates an upload session for an existing file.
1018
     * @param {string} fileId The unique identifier that represents a file.
1019
    
1020
    The ID for any file can be determined
1021
    by visiting a file in the web application
1022
    and copying the ID from the URL. For example,
1023
    for the URL `https://*.app.box.com/files/123`
1024
    the `file_id` is `123`.
1025
    Example: "12345"
1026
     * @param {CreateFileUploadSessionForExistingFileRequestBody} requestBody Request body of createFileUploadSessionForExistingFile method
1027
     * @param {CreateFileUploadSessionForExistingFileOptionalsInput} optionalsInput
1028
     * @returns {Promise<UploadSession>}
1029
     */
1030
  async createFileUploadSessionForExistingFile(
1031
    fileId: string,
×
1032
    requestBody: CreateFileUploadSessionForExistingFileRequestBody,
1033
    optionalsInput: CreateFileUploadSessionForExistingFileOptionalsInput = {},
×
1034
  ): Promise<UploadSession> {
1035
    const optionals: CreateFileUploadSessionForExistingFileOptionals =
1036
      new CreateFileUploadSessionForExistingFileOptionals({
×
1037
        headers: optionalsInput.headers,
1038
        cancellationToken: optionalsInput.cancellationToken,
1039
      });
1040
    const headers: any = optionals.headers;
×
1041
    const cancellationToken: any = optionals.cancellationToken;
×
1042
    const headersMap: {
1043
      readonly [key: string]: string;
1044
    } = prepareParams({ ...{}, ...headers.extraHeaders });
×
1045
    const response: FetchResponse = (await fetch({
×
1046
      url: ''.concat(
1047
        this.networkSession.baseUrls.uploadUrl,
1048
        '/2.0/files/',
1049
        toString(fileId) as string,
1050
        '/upload_sessions',
1051
      ) as string,
1052
      method: 'POST',
1053
      headers: headersMap,
1054
      data: serializeCreateFileUploadSessionForExistingFileRequestBody(
1055
        requestBody,
1056
      ),
1057
      contentType: 'application/json',
1058
      responseFormat: 'json',
1059
      auth: this.auth,
1060
      networkSession: this.networkSession,
1061
      cancellationToken: cancellationToken,
1062
    } satisfies FetchOptions)) as FetchResponse;
1063
    return {
×
1064
      ...deserializeUploadSession(response.data),
1065
      rawData: response.data,
1066
    };
1067
  }
1068
  /**
1069
   * Using this method with urls provided in response when creating a new upload session is preferred to use over GetFileUploadSessionById method.
1070
   * This allows to always upload your content to the closest Box data center and can significantly improve upload speed.
1071
   *  Return information about an upload session.
1072
   *
1073
   * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions) endpoint.
1074
   * @param {string} url URL of getFileUploadSessionById method
1075
   * @param {GetFileUploadSessionByUrlOptionalsInput} optionalsInput
1076
   * @returns {Promise<UploadSession>}
1077
   */
1078
  async getFileUploadSessionByUrl(
1079
    url: string,
2✔
1080
    optionalsInput: GetFileUploadSessionByUrlOptionalsInput = {},
2✔
1081
  ): Promise<UploadSession> {
1082
    const optionals: GetFileUploadSessionByUrlOptionals =
1083
      new GetFileUploadSessionByUrlOptionals({
2✔
1084
        headers: optionalsInput.headers,
1085
        cancellationToken: optionalsInput.cancellationToken,
1086
      });
1087
    const headers: any = optionals.headers;
2✔
1088
    const cancellationToken: any = optionals.cancellationToken;
2✔
1089
    const headersMap: {
1090
      readonly [key: string]: string;
1091
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
1092
    const response: FetchResponse = (await fetch({
2✔
1093
      url: url,
1094
      method: 'GET',
1095
      headers: headersMap,
1096
      responseFormat: 'json',
1097
      auth: this.auth,
1098
      networkSession: this.networkSession,
1099
      cancellationToken: cancellationToken,
1100
    } satisfies FetchOptions)) as FetchResponse;
1101
    return {
2✔
1102
      ...deserializeUploadSession(response.data),
1103
      rawData: response.data,
1104
    };
1105
  }
1106
  /**
1107
     * Return information about an upload session.
1108
     *
1109
     * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions) endpoint.
1110
     * @param {string} uploadSessionId The ID of the upload session.
1111
    Example: "D5E3F7A"
1112
     * @param {GetFileUploadSessionByIdOptionalsInput} optionalsInput
1113
     * @returns {Promise<UploadSession>}
1114
     */
1115
  async getFileUploadSessionById(
1116
    uploadSessionId: string,
2✔
1117
    optionalsInput: GetFileUploadSessionByIdOptionalsInput = {},
2✔
1118
  ): Promise<UploadSession> {
1119
    const optionals: GetFileUploadSessionByIdOptionals =
1120
      new GetFileUploadSessionByIdOptionals({
2✔
1121
        headers: optionalsInput.headers,
1122
        cancellationToken: optionalsInput.cancellationToken,
1123
      });
1124
    const headers: any = optionals.headers;
2✔
1125
    const cancellationToken: any = optionals.cancellationToken;
2✔
1126
    const headersMap: {
1127
      readonly [key: string]: string;
1128
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
1129
    const response: FetchResponse = (await fetch({
2✔
1130
      url: ''.concat(
1131
        this.networkSession.baseUrls.uploadUrl,
1132
        '/2.0/files/upload_sessions/',
1133
        toString(uploadSessionId) as string,
1134
      ) as string,
1135
      method: 'GET',
1136
      headers: headersMap,
1137
      responseFormat: 'json',
1138
      auth: this.auth,
1139
      networkSession: this.networkSession,
1140
      cancellationToken: cancellationToken,
1141
    } satisfies FetchOptions)) as FetchResponse;
1142
    return {
2✔
1143
      ...deserializeUploadSession(response.data),
1144
      rawData: response.data,
1145
    };
1146
  }
1147
  /**
1148
   * Using this method with urls provided in response when creating a new upload session is preferred to use over UploadFilePart method.
1149
   * This allows to always upload your content to the closest Box data center and can significantly improve upload speed.
1150
   *  Uploads a chunk of a file for an upload session.
1151
   *
1152
   * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1153
   * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1154
   * @param {string} url URL of uploadFilePart method
1155
   * @param {ByteStream} requestBody Request body of uploadFilePart method
1156
   * @param {UploadFilePartByUrlHeadersInput} headersInput Headers of uploadFilePart method
1157
   * @param {UploadFilePartByUrlOptionalsInput} optionalsInput
1158
   * @returns {Promise<UploadedPart>}
1159
   */
1160
  async uploadFilePartByUrl(
1161
    url: string,
10✔
1162
    requestBody: ByteStream,
1163
    headersInput: UploadFilePartByUrlHeadersInput,
1164
    optionalsInput: UploadFilePartByUrlOptionalsInput = {},
10✔
1165
  ): Promise<UploadedPart> {
1166
    const headers: UploadFilePartByUrlHeaders = new UploadFilePartByUrlHeaders({
10✔
1167
      digest: headersInput.digest,
1168
      contentRange: headersInput.contentRange,
1169
      extraHeaders: headersInput.extraHeaders,
1170
    });
1171
    const optionals: UploadFilePartByUrlOptionals =
1172
      new UploadFilePartByUrlOptionals({
10✔
1173
        cancellationToken: optionalsInput.cancellationToken,
1174
      });
1175
    const cancellationToken: any = optionals.cancellationToken;
10✔
1176
    const headersMap: {
1177
      readonly [key: string]: string;
1178
    } = prepareParams({
10✔
1179
      ...{
1180
        ['digest']: toString(headers.digest) as string,
1181
        ['content-range']: toString(headers.contentRange) as string,
1182
      },
1183
      ...headers.extraHeaders,
1184
    });
1185
    const response: FetchResponse = (await fetch({
10✔
1186
      url: url,
1187
      method: 'PUT',
1188
      headers: headersMap,
1189
      fileStream: requestBody,
1190
      contentType: 'application/octet-stream',
1191
      responseFormat: 'json',
1192
      auth: this.auth,
1193
      networkSession: this.networkSession,
1194
      cancellationToken: cancellationToken,
1195
    } satisfies FetchOptions)) as FetchResponse;
1196
    return {
10✔
1197
      ...deserializeUploadedPart(response.data),
1198
      rawData: response.data,
1199
    };
1200
  }
1201
  /**
1202
     * Uploads a chunk of a file for an upload session.
1203
     *
1204
     * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1205
     * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1206
     * @param {string} uploadSessionId The ID of the upload session.
1207
    Example: "D5E3F7A"
1208
     * @param {ByteStream} requestBody Request body of uploadFilePart method
1209
     * @param {UploadFilePartHeadersInput} headersInput Headers of uploadFilePart method
1210
     * @param {UploadFilePartOptionalsInput} optionalsInput
1211
     * @returns {Promise<UploadedPart>}
1212
     */
1213
  async uploadFilePart(
1214
    uploadSessionId: string,
5✔
1215
    requestBody: ByteStream,
1216
    headersInput: UploadFilePartHeadersInput,
1217
    optionalsInput: UploadFilePartOptionalsInput = {},
5✔
1218
  ): Promise<UploadedPart> {
1219
    const headers: UploadFilePartHeaders = new UploadFilePartHeaders({
5✔
1220
      digest: headersInput.digest,
1221
      contentRange: headersInput.contentRange,
1222
      extraHeaders: headersInput.extraHeaders,
1223
    });
1224
    const optionals: UploadFilePartOptionals = new UploadFilePartOptionals({
5✔
1225
      cancellationToken: optionalsInput.cancellationToken,
1226
    });
1227
    const cancellationToken: any = optionals.cancellationToken;
5✔
1228
    const headersMap: {
1229
      readonly [key: string]: string;
1230
    } = prepareParams({
5✔
1231
      ...{
1232
        ['digest']: toString(headers.digest) as string,
1233
        ['content-range']: toString(headers.contentRange) as string,
1234
      },
1235
      ...headers.extraHeaders,
1236
    });
1237
    const response: FetchResponse = (await fetch({
5✔
1238
      url: ''.concat(
1239
        this.networkSession.baseUrls.uploadUrl,
1240
        '/2.0/files/upload_sessions/',
1241
        toString(uploadSessionId) as string,
1242
      ) as string,
1243
      method: 'PUT',
1244
      headers: headersMap,
1245
      fileStream: requestBody,
1246
      contentType: 'application/octet-stream',
1247
      responseFormat: 'json',
1248
      auth: this.auth,
1249
      networkSession: this.networkSession,
1250
      cancellationToken: cancellationToken,
1251
    } satisfies FetchOptions)) as FetchResponse;
1252
    return {
5✔
1253
      ...deserializeUploadedPart(response.data),
1254
      rawData: response.data,
1255
    };
1256
  }
1257
  /**
1258
   * Using this method with urls provided in response when creating a new upload session is preferred to use over DeleteFileUploadSessionById method.
1259
   * This allows to always upload your content to the closest Box data center and can significantly improve upload speed.
1260
   *  Abort an upload session and discard all data uploaded.
1261
   *
1262
   * This cannot be reversed.
1263
   *
1264
   * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1265
   * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1266
   * @param {string} url URL of deleteFileUploadSessionById method
1267
   * @param {DeleteFileUploadSessionByUrlOptionalsInput} optionalsInput
1268
   * @returns {Promise<undefined>}
1269
   */
1270
  async deleteFileUploadSessionByUrl(
1271
    url: string,
2✔
1272
    optionalsInput: DeleteFileUploadSessionByUrlOptionalsInput = {},
2✔
1273
  ): Promise<undefined> {
1274
    const optionals: DeleteFileUploadSessionByUrlOptionals =
1275
      new DeleteFileUploadSessionByUrlOptionals({
2✔
1276
        headers: optionalsInput.headers,
1277
        cancellationToken: optionalsInput.cancellationToken,
1278
      });
1279
    const headers: any = optionals.headers;
2✔
1280
    const cancellationToken: any = optionals.cancellationToken;
2✔
1281
    const headersMap: {
1282
      readonly [key: string]: string;
1283
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
1284
    const response: FetchResponse = (await fetch({
2✔
1285
      url: url,
1286
      method: 'DELETE',
1287
      headers: headersMap,
1288
      responseFormat: void 0,
1289
      auth: this.auth,
1290
      networkSession: this.networkSession,
1291
      cancellationToken: cancellationToken,
1292
    } satisfies FetchOptions)) as FetchResponse;
1293
    return void 0;
2✔
1294
  }
1295
  /**
1296
     * Abort an upload session and discard all data uploaded.
1297
     *
1298
     * This cannot be reversed.
1299
     *
1300
     * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1301
     * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1302
     * @param {string} uploadSessionId The ID of the upload session.
1303
    Example: "D5E3F7A"
1304
     * @param {DeleteFileUploadSessionByIdOptionalsInput} optionalsInput
1305
     * @returns {Promise<undefined>}
1306
     */
1307
  async deleteFileUploadSessionById(
1308
    uploadSessionId: string,
2✔
1309
    optionalsInput: DeleteFileUploadSessionByIdOptionalsInput = {},
2✔
1310
  ): Promise<undefined> {
1311
    const optionals: DeleteFileUploadSessionByIdOptionals =
1312
      new DeleteFileUploadSessionByIdOptionals({
2✔
1313
        headers: optionalsInput.headers,
1314
        cancellationToken: optionalsInput.cancellationToken,
1315
      });
1316
    const headers: any = optionals.headers;
2✔
1317
    const cancellationToken: any = optionals.cancellationToken;
2✔
1318
    const headersMap: {
1319
      readonly [key: string]: string;
1320
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
1321
    const response: FetchResponse = (await fetch({
2✔
1322
      url: ''.concat(
1323
        this.networkSession.baseUrls.uploadUrl,
1324
        '/2.0/files/upload_sessions/',
1325
        toString(uploadSessionId) as string,
1326
      ) as string,
1327
      method: 'DELETE',
1328
      headers: headersMap,
1329
      responseFormat: void 0,
1330
      auth: this.auth,
1331
      networkSession: this.networkSession,
1332
      cancellationToken: cancellationToken,
1333
    } satisfies FetchOptions)) as FetchResponse;
1334
    return void 0;
2✔
1335
  }
1336
  /**
1337
   * Using this method with urls provided in response when creating a new upload session is preferred to use over GetFileUploadSessionParts method.
1338
   * This allows to always upload your content to the closest Box data center and can significantly improve upload speed.
1339
   *  Return a list of the chunks uploaded to the upload session so far.
1340
   *
1341
   * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1342
   * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1343
   * @param {string} url URL of getFileUploadSessionParts method
1344
   * @param {GetFileUploadSessionPartsByUrlOptionalsInput} optionalsInput
1345
   * @returns {Promise<UploadParts>}
1346
   */
1347
  async getFileUploadSessionPartsByUrl(
1348
    url: string,
4✔
1349
    optionalsInput: GetFileUploadSessionPartsByUrlOptionalsInput = {},
2✔
1350
  ): Promise<UploadParts> {
1351
    const optionals: GetFileUploadSessionPartsByUrlOptionals =
1352
      new GetFileUploadSessionPartsByUrlOptionals({
4✔
1353
        queryParams: optionalsInput.queryParams,
1354
        headers: optionalsInput.headers,
1355
        cancellationToken: optionalsInput.cancellationToken,
1356
      });
1357
    const queryParams: any = optionals.queryParams;
4✔
1358
    const headers: any = optionals.headers;
4✔
1359
    const cancellationToken: any = optionals.cancellationToken;
4✔
1360
    const queryParamsMap: {
1361
      readonly [key: string]: string;
1362
    } = prepareParams({
4✔
1363
      ['offset']: toString(queryParams.offset) as string,
1364
      ['limit']: toString(queryParams.limit) as string,
1365
    });
1366
    const headersMap: {
1367
      readonly [key: string]: string;
1368
    } = prepareParams({ ...{}, ...headers.extraHeaders });
4✔
1369
    const response: FetchResponse = (await fetch({
4✔
1370
      url: url,
1371
      method: 'GET',
1372
      params: queryParamsMap,
1373
      headers: headersMap,
1374
      responseFormat: 'json',
1375
      auth: this.auth,
1376
      networkSession: this.networkSession,
1377
      cancellationToken: cancellationToken,
1378
    } satisfies FetchOptions)) as FetchResponse;
1379
    return {
4✔
1380
      ...deserializeUploadParts(response.data),
1381
      rawData: response.data,
1382
    };
1383
  }
1384
  /**
1385
     * Return a list of the chunks uploaded to the upload session so far.
1386
     *
1387
     * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1388
     * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1389
     * @param {string} uploadSessionId The ID of the upload session.
1390
    Example: "D5E3F7A"
1391
     * @param {GetFileUploadSessionPartsOptionalsInput} optionalsInput
1392
     * @returns {Promise<UploadParts>}
1393
     */
1394
  async getFileUploadSessionParts(
1395
    uploadSessionId: string,
2✔
1396
    optionalsInput: GetFileUploadSessionPartsOptionalsInput = {},
2✔
1397
  ): Promise<UploadParts> {
1398
    const optionals: GetFileUploadSessionPartsOptionals =
1399
      new GetFileUploadSessionPartsOptionals({
2✔
1400
        queryParams: optionalsInput.queryParams,
1401
        headers: optionalsInput.headers,
1402
        cancellationToken: optionalsInput.cancellationToken,
1403
      });
1404
    const queryParams: any = optionals.queryParams;
2✔
1405
    const headers: any = optionals.headers;
2✔
1406
    const cancellationToken: any = optionals.cancellationToken;
2✔
1407
    const queryParamsMap: {
1408
      readonly [key: string]: string;
1409
    } = prepareParams({
2✔
1410
      ['offset']: toString(queryParams.offset) as string,
1411
      ['limit']: toString(queryParams.limit) as string,
1412
    });
1413
    const headersMap: {
1414
      readonly [key: string]: string;
1415
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
1416
    const response: FetchResponse = (await fetch({
2✔
1417
      url: ''.concat(
1418
        this.networkSession.baseUrls.uploadUrl,
1419
        '/2.0/files/upload_sessions/',
1420
        toString(uploadSessionId) as string,
1421
        '/parts',
1422
      ) as string,
1423
      method: 'GET',
1424
      params: queryParamsMap,
1425
      headers: headersMap,
1426
      responseFormat: 'json',
1427
      auth: this.auth,
1428
      networkSession: this.networkSession,
1429
      cancellationToken: cancellationToken,
1430
    } satisfies FetchOptions)) as FetchResponse;
1431
    return {
2✔
1432
      ...deserializeUploadParts(response.data),
1433
      rawData: response.data,
1434
    };
1435
  }
1436
  /**
1437
   * Using this method with urls provided in response when creating a new upload session is preferred to use over CreateFileUploadSessionCommit method.
1438
   * This allows to always upload your content to the closest Box data center and can significantly improve upload speed.
1439
   *  Close an upload session and create a file from the uploaded chunks.
1440
   *
1441
   * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1442
   * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1443
   * @param {string} url URL of createFileUploadSessionCommit method
1444
   * @param {CreateFileUploadSessionCommitByUrlRequestBody} requestBody Request body of createFileUploadSessionCommit method
1445
   * @param {CreateFileUploadSessionCommitByUrlHeadersInput} headersInput Headers of createFileUploadSessionCommit method
1446
   * @param {CreateFileUploadSessionCommitByUrlOptionalsInput} optionalsInput
1447
   * @returns {Promise<undefined | Files>}
1448
   */
1449
  async createFileUploadSessionCommitByUrl(
1450
    url: string,
4✔
1451
    requestBody: CreateFileUploadSessionCommitByUrlRequestBody,
1452
    headersInput: CreateFileUploadSessionCommitByUrlHeadersInput,
1453
    optionalsInput: CreateFileUploadSessionCommitByUrlOptionalsInput = {},
2✔
1454
  ): Promise<undefined | Files> {
1455
    const headers: CreateFileUploadSessionCommitByUrlHeaders =
1456
      new CreateFileUploadSessionCommitByUrlHeaders({
4✔
1457
        digest: headersInput.digest,
1458
        ifMatch: headersInput.ifMatch,
1459
        ifNoneMatch: headersInput.ifNoneMatch,
1460
        extraHeaders: headersInput.extraHeaders,
1461
      });
1462
    const optionals: CreateFileUploadSessionCommitByUrlOptionals =
1463
      new CreateFileUploadSessionCommitByUrlOptionals({
4✔
1464
        cancellationToken: optionalsInput.cancellationToken,
1465
      });
1466
    const cancellationToken: any = optionals.cancellationToken;
4✔
1467
    const headersMap: {
1468
      readonly [key: string]: string;
1469
    } = prepareParams({
4✔
1470
      ...{
1471
        ['digest']: toString(headers.digest) as string,
1472
        ['if-match']: toString(headers.ifMatch) as string,
1473
        ['if-none-match']: toString(headers.ifNoneMatch) as string,
1474
      },
1475
      ...headers.extraHeaders,
1476
    });
1477
    const response: FetchResponse = (await fetch({
4✔
1478
      url: url,
1479
      method: 'POST',
1480
      headers: headersMap,
1481
      data: serializeCreateFileUploadSessionCommitRequestBody(requestBody),
1482
      contentType: 'application/json',
1483
      responseFormat: 'json',
1484
      auth: this.auth,
1485
      networkSession: this.networkSession,
1486
      cancellationToken: cancellationToken,
1487
    } satisfies FetchOptions)) as FetchResponse;
1488
    if ((toString(response.status) as string) == '202') {
4!
NEW
1489
      return void 0;
×
1490
    }
1491
    return {
4✔
1492
      ...deserializeFiles(response.data),
1493
      rawData: response.data,
1494
    };
1495
  }
1496
  /**
1497
     * Close an upload session and create a file from the uploaded chunks.
1498
     *
1499
     * The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
1500
     * and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
1501
     * @param {string} uploadSessionId The ID of the upload session.
1502
    Example: "D5E3F7A"
1503
     * @param {CreateFileUploadSessionCommitRequestBody} requestBody Request body of createFileUploadSessionCommit method
1504
     * @param {CreateFileUploadSessionCommitHeadersInput} headersInput Headers of createFileUploadSessionCommit method
1505
     * @param {CreateFileUploadSessionCommitOptionalsInput} optionalsInput
1506
     * @returns {Promise<undefined | Files>}
1507
     */
1508
  async createFileUploadSessionCommit(
1509
    uploadSessionId: string,
2✔
1510
    requestBody: CreateFileUploadSessionCommitRequestBody,
1511
    headersInput: CreateFileUploadSessionCommitHeadersInput,
1512
    optionalsInput: CreateFileUploadSessionCommitOptionalsInput = {},
2✔
1513
  ): Promise<undefined | Files> {
1514
    const headers: CreateFileUploadSessionCommitHeaders =
1515
      new CreateFileUploadSessionCommitHeaders({
2✔
1516
        digest: headersInput.digest,
1517
        ifMatch: headersInput.ifMatch,
1518
        ifNoneMatch: headersInput.ifNoneMatch,
1519
        extraHeaders: headersInput.extraHeaders,
1520
      });
1521
    const optionals: CreateFileUploadSessionCommitOptionals =
1522
      new CreateFileUploadSessionCommitOptionals({
2✔
1523
        cancellationToken: optionalsInput.cancellationToken,
1524
      });
1525
    const cancellationToken: any = optionals.cancellationToken;
2✔
1526
    const headersMap: {
1527
      readonly [key: string]: string;
1528
    } = prepareParams({
2✔
1529
      ...{
1530
        ['digest']: toString(headers.digest) as string,
1531
        ['if-match']: toString(headers.ifMatch) as string,
1532
        ['if-none-match']: toString(headers.ifNoneMatch) as string,
1533
      },
1534
      ...headers.extraHeaders,
1535
    });
1536
    const response: FetchResponse = (await fetch({
2✔
1537
      url: ''.concat(
1538
        this.networkSession.baseUrls.uploadUrl,
1539
        '/2.0/files/upload_sessions/',
1540
        toString(uploadSessionId) as string,
1541
        '/commit',
1542
      ) as string,
1543
      method: 'POST',
1544
      headers: headersMap,
1545
      data: serializeCreateFileUploadSessionCommitRequestBody(requestBody),
1546
      contentType: 'application/json',
1547
      responseFormat: 'json',
1548
      auth: this.auth,
1549
      networkSession: this.networkSession,
1550
      cancellationToken: cancellationToken,
1551
    } satisfies FetchOptions)) as FetchResponse;
1552
    if ((toString(response.status) as string) == '202') {
2!
NEW
1553
      return void 0;
×
1554
    }
1555
    return {
2✔
1556
      ...deserializeFiles(response.data),
1557
      rawData: response.data,
1558
    };
1559
  }
1560
  /**
1561
   * @param {PartAccumulator} acc
1562
   * @param {ByteStream} chunk
1563
   * @returns {Promise<PartAccumulator>}
1564
   */
1565
  private async reducer(
1566
    acc: PartAccumulator,
1567
    chunk: ByteStream,
1568
  ): Promise<PartAccumulator> {
1569
    const lastIndex: number = acc.lastIndex;
5✔
1570
    const parts: readonly UploadPart[] = acc.parts;
5✔
1571
    const chunkBuffer: Buffer = await readByteStream(chunk);
5✔
1572
    const hash: Hash = new Hash({ algorithm: 'sha1' as HashName });
5✔
1573
    hash.updateHash(chunkBuffer);
5✔
1574
    const sha1: string = await hash.digestHash('base64');
5✔
1575
    const digest: string = ''.concat('sha=', sha1) as string;
5✔
1576
    const chunkSize: number = bufferLength(chunkBuffer);
5✔
1577
    const bytesStart: number = lastIndex + 1;
5✔
1578
    const bytesEnd: number = lastIndex + chunkSize;
5✔
1579
    const contentRange: string = ''.concat(
5✔
1580
      'bytes ',
1581
      (toString(bytesStart) as string)!,
1582
      '-',
1583
      (toString(bytesEnd) as string)!,
1584
      '/',
1585
      (toString(acc.fileSize) as string)!,
1586
    ) as string;
1587
    const uploadedPart: UploadedPart = await this.uploadFilePartByUrl(
5✔
1588
      acc.uploadPartUrl,
1589
      generateByteStreamFromBuffer(chunkBuffer),
1590
      {
1591
        digest: digest,
1592
        contentRange: contentRange,
1593
      } satisfies UploadFilePartByUrlHeadersInput,
1594
    );
1595
    const part: UploadPart = uploadedPart.part!;
5✔
1596
    const partSha1: string = hexToBase64(part.sha1!);
5✔
1597
    if (!(partSha1 == sha1)) {
5!
1598
      throw new Error('Assertion failed');
×
1599
    }
1600
    if (!(part.size! == chunkSize)) {
5!
1601
      throw new Error('Assertion failed');
×
1602
    }
1603
    if (!(part.offset! == bytesStart)) {
5!
1604
      throw new Error('Assertion failed');
×
1605
    }
1606
    acc.fileHash.updateHash(chunkBuffer);
5✔
1607
    return {
5✔
1608
      lastIndex: bytesEnd,
1609
      parts: parts.concat([part]),
1610
      fileSize: acc.fileSize,
1611
      uploadPartUrl: acc.uploadPartUrl,
1612
      fileHash: acc.fileHash,
1613
    } satisfies PartAccumulator;
1614
  }
1615
  /**
1616
   * Starts the process of chunk uploading a big file. Should return a File object representing uploaded file.
1617
   * @param {ByteStream} file The stream of the file to upload.
1618
   * @param {string} fileName The name of the file, which will be used for storage in Box.
1619
   * @param {number} fileSize The total size of the file for the chunked upload in bytes.
1620
   * @param {string} parentFolderId The ID of the folder where the file should be uploaded.
1621
   * @param {CancellationToken} cancellationToken Token used for request cancellation.
1622
   * @returns {Promise<FileFull>}
1623
   */
1624
  async uploadBigFile(
1625
    file: ByteStream,
1626
    fileName: string,
1627
    fileSize: number,
1628
    parentFolderId: string,
1629
    cancellationToken?: CancellationToken,
1630
  ): Promise<FileFull> {
1631
    const uploadSession: UploadSession = await this.createFileUploadSession(
2✔
1632
      {
1633
        fileName: fileName,
1634
        fileSize: fileSize,
1635
        folderId: parentFolderId,
1636
      } satisfies CreateFileUploadSessionRequestBody,
1637
      {
1638
        headers: new CreateFileUploadSessionHeaders({}),
1639
        cancellationToken: cancellationToken,
1640
      } satisfies CreateFileUploadSessionOptionalsInput,
1641
    );
1642
    const uploadPartUrl: string = uploadSession.sessionEndpoints!.uploadPart!;
2✔
1643
    const commitUrl: string = uploadSession.sessionEndpoints!.commit!;
2✔
1644
    const listPartsUrl: string = uploadSession.sessionEndpoints!.listParts!;
2✔
1645
    const partSize: number = uploadSession.partSize!;
2✔
1646
    const totalParts: number = uploadSession.totalParts!;
2✔
1647
    if (!(partSize * totalParts >= fileSize)) {
2!
1648
      throw new Error('Assertion failed');
×
1649
    }
1650
    if (!(uploadSession.numPartsProcessed == 0)) {
2!
1651
      throw new Error('Assertion failed');
×
1652
    }
1653
    const fileHash: Hash = new Hash({ algorithm: 'sha1' as HashName });
2✔
1654
    const chunksIterator: Iterator = iterateChunks(file, partSize, fileSize);
2✔
1655
    const results: PartAccumulator = await reduceIterator(
2✔
1656
      chunksIterator,
1657
      this.reducer.bind(this),
1658
      {
1659
        lastIndex: -1,
1660
        parts: [],
1661
        fileSize: fileSize,
1662
        uploadPartUrl: uploadPartUrl,
1663
        fileHash: fileHash,
1664
      } satisfies PartAccumulator,
1665
    );
1666
    const parts: readonly UploadPart[] = results.parts;
2✔
1667
    const processedSessionParts: UploadParts =
1668
      await this.getFileUploadSessionPartsByUrl(listPartsUrl, {
2✔
1669
        queryParams: {} satisfies GetFileUploadSessionPartsByUrlQueryParams,
1670
        headers: new GetFileUploadSessionPartsByUrlHeaders({}),
1671
        cancellationToken: cancellationToken,
1672
      } satisfies GetFileUploadSessionPartsByUrlOptionalsInput);
1673
    if (!(processedSessionParts.totalCount! == totalParts)) {
2!
1674
      throw new Error('Assertion failed');
×
1675
    }
1676
    const sha1: string = await fileHash.digestHash('base64');
2✔
1677
    const digest: string = ''.concat('sha=', sha1) as string;
2✔
1678
    const committedSession: undefined | Files =
1679
      await this.createFileUploadSessionCommitByUrl(
2✔
1680
        commitUrl,
1681
        {
1682
          parts: parts,
1683
        } satisfies CreateFileUploadSessionCommitByUrlRequestBody,
1684
        {
1685
          digest: digest,
1686
        } satisfies CreateFileUploadSessionCommitByUrlHeadersInput,
1687
        {
1688
          cancellationToken: cancellationToken,
1689
        } satisfies CreateFileUploadSessionCommitByUrlOptionalsInput,
1690
      );
1691
    return committedSession!.entries![0];
2✔
1692
  }
1693
}
1694
export interface ChunkedUploadsManagerInput {
1695
  readonly auth?: Authentication;
1696
  readonly networkSession?: NetworkSession;
1697
}
1698
export function serializeCreateFileUploadSessionRequestBody(
140✔
1699
  val: CreateFileUploadSessionRequestBody,
1700
): SerializedData {
1701
  return {
6✔
1702
    ['folder_id']: val.folderId,
1703
    ['file_size']: val.fileSize,
1704
    ['file_name']: val.fileName,
1705
  };
1706
}
1707
export function deserializeCreateFileUploadSessionRequestBody(
140✔
1708
  val: SerializedData,
1709
): CreateFileUploadSessionRequestBody {
1710
  if (!sdIsMap(val)) {
×
1711
    throw new BoxSdkError({
×
1712
      message: 'Expecting a map for "CreateFileUploadSessionRequestBody"',
1713
    });
1714
  }
1715
  if (val.folder_id == void 0) {
×
1716
    throw new BoxSdkError({
×
1717
      message:
1718
        'Expecting "folder_id" of type "CreateFileUploadSessionRequestBody" to be defined',
1719
    });
1720
  }
1721
  if (!sdIsString(val.folder_id)) {
×
1722
    throw new BoxSdkError({
×
1723
      message:
1724
        'Expecting string for "folder_id" of type "CreateFileUploadSessionRequestBody"',
1725
    });
1726
  }
1727
  const folderId: string = val.folder_id;
×
1728
  if (val.file_size == void 0) {
×
1729
    throw new BoxSdkError({
×
1730
      message:
1731
        'Expecting "file_size" of type "CreateFileUploadSessionRequestBody" to be defined',
1732
    });
1733
  }
1734
  if (!sdIsNumber(val.file_size)) {
×
1735
    throw new BoxSdkError({
×
1736
      message:
1737
        'Expecting number for "file_size" of type "CreateFileUploadSessionRequestBody"',
1738
    });
1739
  }
1740
  const fileSize: number = val.file_size;
×
1741
  if (val.file_name == void 0) {
×
1742
    throw new BoxSdkError({
×
1743
      message:
1744
        'Expecting "file_name" of type "CreateFileUploadSessionRequestBody" to be defined',
1745
    });
1746
  }
1747
  if (!sdIsString(val.file_name)) {
×
1748
    throw new BoxSdkError({
×
1749
      message:
1750
        'Expecting string for "file_name" of type "CreateFileUploadSessionRequestBody"',
1751
    });
1752
  }
1753
  const fileName: string = val.file_name;
×
1754
  return {
×
1755
    folderId: folderId,
1756
    fileSize: fileSize,
1757
    fileName: fileName,
1758
  } satisfies CreateFileUploadSessionRequestBody;
1759
}
1760
export function serializeCreateFileUploadSessionForExistingFileRequestBody(
140✔
1761
  val: CreateFileUploadSessionForExistingFileRequestBody,
1762
): SerializedData {
1763
  return {
×
1764
    ['file_size']: val.fileSize,
1765
    ['file_name']: val.fileName == void 0 ? void 0 : val.fileName,
×
1766
  };
1767
}
1768
export function deserializeCreateFileUploadSessionForExistingFileRequestBody(
140✔
1769
  val: SerializedData,
1770
): CreateFileUploadSessionForExistingFileRequestBody {
1771
  if (!sdIsMap(val)) {
×
1772
    throw new BoxSdkError({
×
1773
      message:
1774
        'Expecting a map for "CreateFileUploadSessionForExistingFileRequestBody"',
1775
    });
1776
  }
1777
  if (val.file_size == void 0) {
×
1778
    throw new BoxSdkError({
×
1779
      message:
1780
        'Expecting "file_size" of type "CreateFileUploadSessionForExistingFileRequestBody" to be defined',
1781
    });
1782
  }
1783
  if (!sdIsNumber(val.file_size)) {
×
1784
    throw new BoxSdkError({
×
1785
      message:
1786
        'Expecting number for "file_size" of type "CreateFileUploadSessionForExistingFileRequestBody"',
1787
    });
1788
  }
1789
  const fileSize: number = val.file_size;
×
1790
  if (!(val.file_name == void 0) && !sdIsString(val.file_name)) {
×
1791
    throw new BoxSdkError({
×
1792
      message:
1793
        'Expecting string for "file_name" of type "CreateFileUploadSessionForExistingFileRequestBody"',
1794
    });
1795
  }
1796
  const fileName: undefined | string =
1797
    val.file_name == void 0 ? void 0 : val.file_name;
×
1798
  return {
×
1799
    fileSize: fileSize,
1800
    fileName: fileName,
1801
  } satisfies CreateFileUploadSessionForExistingFileRequestBody;
1802
}
1803
export function serializeCreateFileUploadSessionCommitByUrlRequestBody(
140✔
1804
  val: CreateFileUploadSessionCommitByUrlRequestBody,
1805
): SerializedData {
1806
  return {
×
1807
    ['parts']: val.parts.map(function (item: UploadPart): SerializedData {
1808
      return serializeUploadPart(item);
×
1809
    }) as readonly any[],
1810
  };
1811
}
1812
export function deserializeCreateFileUploadSessionCommitByUrlRequestBody(
140✔
1813
  val: SerializedData,
1814
): CreateFileUploadSessionCommitByUrlRequestBody {
1815
  if (!sdIsMap(val)) {
×
1816
    throw new BoxSdkError({
×
1817
      message:
1818
        'Expecting a map for "CreateFileUploadSessionCommitByUrlRequestBody"',
1819
    });
1820
  }
1821
  if (val.parts == void 0) {
×
1822
    throw new BoxSdkError({
×
1823
      message:
1824
        'Expecting "parts" of type "CreateFileUploadSessionCommitByUrlRequestBody" to be defined',
1825
    });
1826
  }
1827
  if (!sdIsList(val.parts)) {
×
1828
    throw new BoxSdkError({
×
1829
      message:
1830
        'Expecting array for "parts" of type "CreateFileUploadSessionCommitByUrlRequestBody"',
1831
    });
1832
  }
1833
  const parts: readonly UploadPart[] = sdIsList(val.parts)
×
1834
    ? (val.parts.map(function (itm: SerializedData): UploadPart {
1835
        return deserializeUploadPart(itm);
×
1836
      }) as readonly any[])
1837
    : [];
1838
  return {
×
1839
    parts: parts,
1840
  } satisfies CreateFileUploadSessionCommitByUrlRequestBody;
1841
}
1842
export function serializeCreateFileUploadSessionCommitRequestBody(
140✔
1843
  val: CreateFileUploadSessionCommitRequestBody,
1844
): SerializedData {
1845
  return {
6✔
1846
    ['parts']: val.parts.map(function (item: UploadPart): SerializedData {
1847
      return serializeUploadPart(item);
15✔
1848
    }) as readonly any[],
1849
  };
1850
}
1851
export function deserializeCreateFileUploadSessionCommitRequestBody(
140✔
1852
  val: SerializedData,
1853
): CreateFileUploadSessionCommitRequestBody {
1854
  if (!sdIsMap(val)) {
×
1855
    throw new BoxSdkError({
×
1856
      message: 'Expecting a map for "CreateFileUploadSessionCommitRequestBody"',
1857
    });
1858
  }
1859
  if (val.parts == void 0) {
×
1860
    throw new BoxSdkError({
×
1861
      message:
1862
        'Expecting "parts" of type "CreateFileUploadSessionCommitRequestBody" to be defined',
1863
    });
1864
  }
1865
  if (!sdIsList(val.parts)) {
×
1866
    throw new BoxSdkError({
×
1867
      message:
1868
        'Expecting array for "parts" of type "CreateFileUploadSessionCommitRequestBody"',
1869
    });
1870
  }
1871
  const parts: readonly UploadPart[] = sdIsList(val.parts)
×
1872
    ? (val.parts.map(function (itm: SerializedData): UploadPart {
1873
        return deserializeUploadPart(itm);
×
1874
      }) as readonly any[])
1875
    : [];
1876
  return { parts: parts } satisfies CreateFileUploadSessionCommitRequestBody;
×
1877
}
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

© 2025 Coveralls, Inc