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

box / box-typescript-sdk-gen / 12547398862

30 Dec 2024 01:44PM UTC coverage: 43.462% (+0.06%) from 43.401%
12547398862

push

github

web-flow
feat: Support webhook message validation (box/box-codegen#631) (#455)

Co-authored-by: box-sdk-build <box-sdk-build@box.com>

3928 of 15234 branches covered (25.78%)

Branch coverage included in aggregate %.

43 of 53 new or added lines in 2 files covered. (81.13%)

3697 existing lines in 76 files now uncovered.

13661 of 25236 relevant lines covered (54.13%)

83.7 hits per line

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

60.43
/src/managers/trashedFiles.generated.ts
1
import { serializeTrashFileRestored } from '../schemas/trashFileRestored.generated.js';
2
import { deserializeTrashFileRestored } from '../schemas/trashFileRestored.generated.js';
140✔
3
import { serializeClientError } from '../schemas/clientError.generated.js';
4
import { deserializeClientError } from '../schemas/clientError.generated.js';
5
import { serializeTrashFile } from '../schemas/trashFile.generated.js';
6
import { deserializeTrashFile } from '../schemas/trashFile.generated.js';
140✔
7
import { ResponseFormat } from '../networking/fetchOptions.generated.js';
8
import { TrashFileRestored } from '../schemas/trashFileRestored.generated.js';
9
import { ClientError } from '../schemas/clientError.generated.js';
10
import { TrashFile } from '../schemas/trashFile.generated.js';
11
import { BoxSdkError } from '../box/errors.js';
140✔
12
import { Authentication } from '../networking/auth.generated.js';
13
import { NetworkSession } from '../networking/network.generated.js';
140✔
14
import { FetchOptions } from '../networking/fetchOptions.generated.js';
140✔
15
import { FetchResponse } from '../networking/fetchResponse.generated.js';
16
import { prepareParams } from '../internal/utils.js';
140✔
17
import { toString } from '../internal/utils.js';
140✔
18
import { ByteStream } from '../internal/utils.js';
19
import { CancellationToken } from '../internal/utils.js';
20
import { sdToJson } from '../serialization/json.js';
21
import { SerializedData } from '../serialization/json.js';
22
import { sdIsEmpty } from '../serialization/json.js';
23
import { sdIsBoolean } from '../serialization/json.js';
24
import { sdIsNumber } from '../serialization/json.js';
25
import { sdIsString } from '../serialization/json.js';
140✔
26
import { sdIsList } from '../serialization/json.js';
27
import { sdIsMap } from '../serialization/json.js';
140✔
28
export class RestoreFileFromTrashOptionals {
140✔
29
  readonly requestBody: RestoreFileFromTrashRequestBody =
2✔
30
    {} satisfies RestoreFileFromTrashRequestBody;
31
  readonly queryParams: RestoreFileFromTrashQueryParams =
2✔
32
    {} satisfies RestoreFileFromTrashQueryParams;
33
  readonly headers: RestoreFileFromTrashHeaders =
2✔
34
    new RestoreFileFromTrashHeaders({});
35
  readonly cancellationToken?: CancellationToken = void 0;
2✔
36
  constructor(
37
    fields: Omit<
38
      RestoreFileFromTrashOptionals,
39
      'requestBody' | 'queryParams' | 'headers' | 'cancellationToken'
40
    > &
41
      Partial<
42
        Pick<
43
          RestoreFileFromTrashOptionals,
44
          'requestBody' | 'queryParams' | 'headers' | 'cancellationToken'
45
        >
46
      >,
47
  ) {
48
    if (fields.requestBody !== undefined) {
2!
UNCOV
49
      this.requestBody = fields.requestBody;
×
50
    }
51
    if (fields.queryParams !== undefined) {
2!
UNCOV
52
      this.queryParams = fields.queryParams;
×
53
    }
54
    if (fields.headers !== undefined) {
2!
UNCOV
55
      this.headers = fields.headers;
×
56
    }
57
    if (fields.cancellationToken !== undefined) {
2!
UNCOV
58
      this.cancellationToken = fields.cancellationToken;
×
59
    }
60
  }
61
}
62
export interface RestoreFileFromTrashOptionalsInput {
63
  readonly requestBody?: RestoreFileFromTrashRequestBody;
64
  readonly queryParams?: RestoreFileFromTrashQueryParams;
65
  readonly headers?: RestoreFileFromTrashHeaders;
66
  readonly cancellationToken?: undefined | CancellationToken;
67
}
68
export class GetTrashedFileByIdOptionals {
140✔
69
  readonly queryParams: GetTrashedFileByIdQueryParams =
6✔
70
    {} satisfies GetTrashedFileByIdQueryParams;
71
  readonly headers: GetTrashedFileByIdHeaders = new GetTrashedFileByIdHeaders(
6✔
72
    {},
73
  );
74
  readonly cancellationToken?: CancellationToken = void 0;
6✔
75
  constructor(
76
    fields: Omit<
77
      GetTrashedFileByIdOptionals,
78
      'queryParams' | 'headers' | 'cancellationToken'
79
    > &
80
      Partial<
81
        Pick<
82
          GetTrashedFileByIdOptionals,
83
          'queryParams' | 'headers' | 'cancellationToken'
84
        >
85
      >,
86
  ) {
87
    if (fields.queryParams !== undefined) {
6!
UNCOV
88
      this.queryParams = fields.queryParams;
×
89
    }
90
    if (fields.headers !== undefined) {
6!
UNCOV
91
      this.headers = fields.headers;
×
92
    }
93
    if (fields.cancellationToken !== undefined) {
6!
UNCOV
94
      this.cancellationToken = fields.cancellationToken;
×
95
    }
96
  }
97
}
98
export interface GetTrashedFileByIdOptionalsInput {
99
  readonly queryParams?: GetTrashedFileByIdQueryParams;
100
  readonly headers?: GetTrashedFileByIdHeaders;
101
  readonly cancellationToken?: undefined | CancellationToken;
102
}
103
export class DeleteTrashedFileByIdOptionals {
140✔
104
  readonly headers: DeleteTrashedFileByIdHeaders =
2✔
105
    new DeleteTrashedFileByIdHeaders({});
106
  readonly cancellationToken?: CancellationToken = void 0;
2✔
107
  constructor(
108
    fields: Omit<
109
      DeleteTrashedFileByIdOptionals,
110
      'headers' | 'cancellationToken'
111
    > &
112
      Partial<
113
        Pick<DeleteTrashedFileByIdOptionals, 'headers' | 'cancellationToken'>
114
      >,
115
  ) {
116
    if (fields.headers !== undefined) {
2!
UNCOV
117
      this.headers = fields.headers;
×
118
    }
119
    if (fields.cancellationToken !== undefined) {
2!
UNCOV
120
      this.cancellationToken = fields.cancellationToken;
×
121
    }
122
  }
123
}
124
export interface DeleteTrashedFileByIdOptionalsInput {
125
  readonly headers?: DeleteTrashedFileByIdHeaders;
126
  readonly cancellationToken?: undefined | CancellationToken;
127
}
128
export interface RestoreFileFromTrashRequestBodyParentField {
129
  /**
130
   * The ID of parent item */
131
  readonly id?: string;
132
  readonly rawData?: SerializedData;
133
}
134
export interface RestoreFileFromTrashRequestBody {
135
  /**
136
   * An optional new name for the file. */
137
  readonly name?: string;
138
  readonly parent?: RestoreFileFromTrashRequestBodyParentField;
139
  readonly rawData?: SerializedData;
140
}
141
export interface RestoreFileFromTrashQueryParams {
142
  /**
143
   * A comma-separated list of attributes to include in the
144
   * response. This can be used to request fields that are
145
   * not normally returned in a standard response.
146
   *
147
   * Be aware that specifying this parameter will have the
148
   * effect that none of the standard fields are returned in
149
   * the response unless explicitly specified, instead only
150
   * fields for the mini representation are returned, additional
151
   * to the fields requested. */
152
  readonly fields?: readonly string[];
153
}
154
export class RestoreFileFromTrashHeaders {
140✔
155
  /**
156
   * Extra headers that will be included in the HTTP request. */
157
  readonly extraHeaders?: {
2✔
158
    readonly [key: string]: undefined | string;
159
  } = {};
160
  constructor(
161
    fields: Omit<RestoreFileFromTrashHeaders, 'extraHeaders'> &
162
      Partial<Pick<RestoreFileFromTrashHeaders, 'extraHeaders'>>,
163
  ) {
164
    if (fields.extraHeaders !== undefined) {
2!
UNCOV
165
      this.extraHeaders = fields.extraHeaders;
×
166
    }
167
  }
168
}
169
export interface RestoreFileFromTrashHeadersInput {
170
  /**
171
   * Extra headers that will be included in the HTTP request. */
172
  readonly extraHeaders?:
173
    | undefined
174
    | {
175
        readonly [key: string]: undefined | string;
176
      };
177
}
178
export interface GetTrashedFileByIdQueryParams {
179
  /**
180
   * A comma-separated list of attributes to include in the
181
   * response. This can be used to request fields that are
182
   * not normally returned in a standard response.
183
   *
184
   * Be aware that specifying this parameter will have the
185
   * effect that none of the standard fields are returned in
186
   * the response unless explicitly specified, instead only
187
   * fields for the mini representation are returned, additional
188
   * to the fields requested. */
189
  readonly fields?: readonly string[];
190
}
191
export class GetTrashedFileByIdHeaders {
140✔
192
  /**
193
   * Extra headers that will be included in the HTTP request. */
194
  readonly extraHeaders?: {
6✔
195
    readonly [key: string]: undefined | string;
196
  } = {};
197
  constructor(
198
    fields: Omit<GetTrashedFileByIdHeaders, 'extraHeaders'> &
199
      Partial<Pick<GetTrashedFileByIdHeaders, 'extraHeaders'>>,
200
  ) {
201
    if (fields.extraHeaders !== undefined) {
6!
UNCOV
202
      this.extraHeaders = fields.extraHeaders;
×
203
    }
204
  }
205
}
206
export interface GetTrashedFileByIdHeadersInput {
207
  /**
208
   * Extra headers that will be included in the HTTP request. */
209
  readonly extraHeaders?:
210
    | undefined
211
    | {
212
        readonly [key: string]: undefined | string;
213
      };
214
}
215
export class DeleteTrashedFileByIdHeaders {
140✔
216
  /**
217
   * Extra headers that will be included in the HTTP request. */
218
  readonly extraHeaders?: {
2✔
219
    readonly [key: string]: undefined | string;
220
  } = {};
221
  constructor(
222
    fields: Omit<DeleteTrashedFileByIdHeaders, 'extraHeaders'> &
223
      Partial<Pick<DeleteTrashedFileByIdHeaders, 'extraHeaders'>>,
224
  ) {
225
    if (fields.extraHeaders !== undefined) {
2!
UNCOV
226
      this.extraHeaders = fields.extraHeaders;
×
227
    }
228
  }
229
}
230
export interface DeleteTrashedFileByIdHeadersInput {
231
  /**
232
   * Extra headers that will be included in the HTTP request. */
233
  readonly extraHeaders?:
234
    | undefined
235
    | {
236
        readonly [key: string]: undefined | string;
237
      };
238
}
239
export class TrashedFilesManager {
140✔
240
  readonly auth?: Authentication;
241
  readonly networkSession: NetworkSession = new NetworkSession({});
302✔
242
  constructor(
243
    fields: Omit<
244
      TrashedFilesManager,
245
      | 'networkSession'
246
      | 'restoreFileFromTrash'
247
      | 'getTrashedFileById'
248
      | 'deleteTrashedFileById'
249
    > &
250
      Partial<Pick<TrashedFilesManager, 'networkSession'>>,
251
  ) {
252
    if (fields.auth !== undefined) {
302✔
253
      this.auth = fields.auth;
302✔
254
    }
255
    if (fields.networkSession !== undefined) {
302✔
256
      this.networkSession = fields.networkSession;
302✔
257
    }
258
  }
259
  /**
260
     * Restores a file that has been moved to the trash.
261
     *
262
     * An optional new parent ID can be provided to restore the file to in case the
263
     * original folder has been deleted.
264
     * @param {string} fileId The unique identifier that represents a file.
265
    
266
    The ID for any file can be determined
267
    by visiting a file in the web application
268
    and copying the ID from the URL. For example,
269
    for the URL `https://*.app.box.com/files/123`
270
    the `file_id` is `123`.
271
    Example: "12345"
272
     * @param {RestoreFileFromTrashOptionalsInput} optionalsInput
273
     * @returns {Promise<TrashFileRestored>}
274
     */
275
  async restoreFileFromTrash(
276
    fileId: string,
2✔
277
    optionalsInput: RestoreFileFromTrashOptionalsInput = {},
2✔
278
  ): Promise<TrashFileRestored> {
279
    const optionals: RestoreFileFromTrashOptionals =
280
      new RestoreFileFromTrashOptionals({
2✔
281
        requestBody: optionalsInput.requestBody,
282
        queryParams: optionalsInput.queryParams,
283
        headers: optionalsInput.headers,
284
        cancellationToken: optionalsInput.cancellationToken,
285
      });
286
    const requestBody: any = optionals.requestBody;
2✔
287
    const queryParams: any = optionals.queryParams;
2✔
288
    const headers: any = optionals.headers;
2✔
289
    const cancellationToken: any = optionals.cancellationToken;
2✔
290
    const queryParamsMap: {
291
      readonly [key: string]: string;
292
    } = prepareParams({
2✔
293
      ['fields']: queryParams.fields
2!
294
        ? queryParams.fields.map(toString).join(',')
295
        : undefined,
296
    });
297
    const headersMap: {
298
      readonly [key: string]: string;
299
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
300
    const response: FetchResponse =
301
      await this.networkSession.networkClient.fetch(
2✔
302
        new FetchOptions({
303
          url: ''.concat(
304
            this.networkSession.baseUrls.baseUrl,
305
            '/2.0/files/',
306
            toString(fileId) as string,
307
          ) as string,
308
          method: 'POST',
309
          params: queryParamsMap,
310
          headers: headersMap,
311
          data: serializeRestoreFileFromTrashRequestBody(requestBody),
312
          contentType: 'application/json',
313
          responseFormat: 'json' as ResponseFormat,
314
          auth: this.auth,
315
          networkSession: this.networkSession,
316
          cancellationToken: cancellationToken,
317
        }),
318
      );
319
    return {
2✔
320
      ...deserializeTrashFileRestored(response.data!),
321
      rawData: response.data!,
322
    };
323
  }
324
  /**
325
     * Retrieves a file that has been moved to the trash.
326
     *
327
     * Please note that only if the file itself has been moved to the
328
     * trash can it be retrieved with this API call. If instead one of
329
     * its parent folders was moved to the trash, only that folder
330
     * can be inspected using the
331
     * [`GET /folders/:id/trash`](e://get_folders_id_trash) API.
332
     *
333
     * To list all items that have been moved to the trash, please
334
     * use the [`GET /folders/trash/items`](e://get-folders-trash-items/)
335
     * API.
336
     * @param {string} fileId The unique identifier that represents a file.
337
    
338
    The ID for any file can be determined
339
    by visiting a file in the web application
340
    and copying the ID from the URL. For example,
341
    for the URL `https://*.app.box.com/files/123`
342
    the `file_id` is `123`.
343
    Example: "12345"
344
     * @param {GetTrashedFileByIdOptionalsInput} optionalsInput
345
     * @returns {Promise<TrashFile>}
346
     */
347
  async getTrashedFileById(
348
    fileId: string,
6✔
349
    optionalsInput: GetTrashedFileByIdOptionalsInput = {},
6✔
350
  ): Promise<TrashFile> {
351
    const optionals: GetTrashedFileByIdOptionals =
352
      new GetTrashedFileByIdOptionals({
6✔
353
        queryParams: optionalsInput.queryParams,
354
        headers: optionalsInput.headers,
355
        cancellationToken: optionalsInput.cancellationToken,
356
      });
357
    const queryParams: any = optionals.queryParams;
6✔
358
    const headers: any = optionals.headers;
6✔
359
    const cancellationToken: any = optionals.cancellationToken;
6✔
360
    const queryParamsMap: {
361
      readonly [key: string]: string;
362
    } = prepareParams({
6✔
363
      ['fields']: queryParams.fields
6!
364
        ? queryParams.fields.map(toString).join(',')
365
        : undefined,
366
    });
367
    const headersMap: {
368
      readonly [key: string]: string;
369
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
370
    const response: FetchResponse =
371
      await this.networkSession.networkClient.fetch(
6✔
372
        new FetchOptions({
373
          url: ''.concat(
374
            this.networkSession.baseUrls.baseUrl,
375
            '/2.0/files/',
376
            toString(fileId) as string,
377
            '/trash',
378
          ) as string,
379
          method: 'GET',
380
          params: queryParamsMap,
381
          headers: headersMap,
382
          responseFormat: 'json' as ResponseFormat,
383
          auth: this.auth,
384
          networkSession: this.networkSession,
385
          cancellationToken: cancellationToken,
386
        }),
387
      );
388
    return {
4✔
389
      ...deserializeTrashFile(response.data!),
390
      rawData: response.data!,
391
    };
392
  }
393
  /**
394
     * Permanently deletes a file that is in the trash.
395
     * This action cannot be undone.
396
     * @param {string} fileId The unique identifier that represents a file.
397
    
398
    The ID for any file can be determined
399
    by visiting a file in the web application
400
    and copying the ID from the URL. For example,
401
    for the URL `https://*.app.box.com/files/123`
402
    the `file_id` is `123`.
403
    Example: "12345"
404
     * @param {DeleteTrashedFileByIdOptionalsInput} optionalsInput
405
     * @returns {Promise<undefined>}
406
     */
407
  async deleteTrashedFileById(
408
    fileId: string,
2✔
409
    optionalsInput: DeleteTrashedFileByIdOptionalsInput = {},
2✔
410
  ): Promise<undefined> {
411
    const optionals: DeleteTrashedFileByIdOptionals =
412
      new DeleteTrashedFileByIdOptionals({
2✔
413
        headers: optionalsInput.headers,
414
        cancellationToken: optionalsInput.cancellationToken,
415
      });
416
    const headers: any = optionals.headers;
2✔
417
    const cancellationToken: any = optionals.cancellationToken;
2✔
418
    const headersMap: {
419
      readonly [key: string]: string;
420
    } = prepareParams({ ...{}, ...headers.extraHeaders });
2✔
421
    const response: FetchResponse =
422
      await this.networkSession.networkClient.fetch(
2✔
423
        new FetchOptions({
424
          url: ''.concat(
425
            this.networkSession.baseUrls.baseUrl,
426
            '/2.0/files/',
427
            toString(fileId) as string,
428
            '/trash',
429
          ) as string,
430
          method: 'DELETE',
431
          headers: headersMap,
432
          responseFormat: 'no_content' as ResponseFormat,
433
          auth: this.auth,
434
          networkSession: this.networkSession,
435
          cancellationToken: cancellationToken,
436
        }),
437
      );
438
    return void 0;
2✔
439
  }
440
}
441
export interface TrashedFilesManagerInput {
442
  readonly auth?: Authentication;
443
  readonly networkSession?: NetworkSession;
444
}
445
export function serializeRestoreFileFromTrashRequestBodyParentField(
140✔
446
  val: RestoreFileFromTrashRequestBodyParentField,
447
): SerializedData {
UNCOV
448
  return { ['id']: val.id };
×
449
}
450
export function deserializeRestoreFileFromTrashRequestBodyParentField(
140✔
451
  val: SerializedData,
452
): RestoreFileFromTrashRequestBodyParentField {
UNCOV
453
  if (!sdIsMap(val)) {
×
UNCOV
454
    throw new BoxSdkError({
×
455
      message:
456
        'Expecting a map for "RestoreFileFromTrashRequestBodyParentField"',
457
    });
458
  }
UNCOV
459
  if (!(val.id == void 0) && !sdIsString(val.id)) {
×
UNCOV
460
    throw new BoxSdkError({
×
461
      message:
462
        'Expecting string for "id" of type "RestoreFileFromTrashRequestBodyParentField"',
463
    });
464
  }
UNCOV
465
  const id: undefined | string = val.id == void 0 ? void 0 : val.id;
×
UNCOV
466
  return { id: id } satisfies RestoreFileFromTrashRequestBodyParentField;
×
467
}
468
export function serializeRestoreFileFromTrashRequestBody(
140✔
469
  val: RestoreFileFromTrashRequestBody,
470
): SerializedData {
471
  return {
2✔
472
    ['name']: val.name,
473
    ['parent']:
474
      val.parent == void 0
2!
475
        ? val.parent
476
        : serializeRestoreFileFromTrashRequestBodyParentField(val.parent),
477
  };
478
}
479
export function deserializeRestoreFileFromTrashRequestBody(
140✔
480
  val: SerializedData,
481
): RestoreFileFromTrashRequestBody {
UNCOV
482
  if (!sdIsMap(val)) {
×
UNCOV
483
    throw new BoxSdkError({
×
484
      message: 'Expecting a map for "RestoreFileFromTrashRequestBody"',
485
    });
486
  }
UNCOV
487
  if (!(val.name == void 0) && !sdIsString(val.name)) {
×
UNCOV
488
    throw new BoxSdkError({
×
489
      message:
490
        'Expecting string for "name" of type "RestoreFileFromTrashRequestBody"',
491
    });
492
  }
493
  const name: undefined | string = val.name == void 0 ? void 0 : val.name;
×
494
  const parent: undefined | RestoreFileFromTrashRequestBodyParentField =
UNCOV
495
    val.parent == void 0
×
496
      ? void 0
497
      : deserializeRestoreFileFromTrashRequestBodyParentField(val.parent);
UNCOV
498
  return {
×
499
    name: name,
500
    parent: parent,
501
  } satisfies RestoreFileFromTrashRequestBody;
502
}
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