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

box / box-typescript-sdk-gen / 6814673855

09 Nov 2023 04:31PM UTC coverage: 31.432% (+1.3%) from 30.127%
6814673855

Pull #41

github

web-flow
Merge 3aec2106f into 1aa8f5afc
Pull Request #41: codegen output 13ed41f186c7473db272e90659610b17

1501 of 9137 branches covered (0.0%)

Branch coverage included in aggregate %.

492 of 992 new or added lines in 75 files covered. (49.6%)

160 existing lines in 14 files now uncovered.

5124 of 11940 relevant lines covered (42.91%)

27.06 hits per line

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

45.83
/src/managers/uploads.generated.ts
1
import { serializeFiles } from '../schemas.generated.js';
2
import { deserializeFiles } from '../schemas.generated.js';
70✔
3
import { serializeClientError } from '../schemas.generated.js';
4
import { deserializeClientError } from '../schemas.generated.js';
5
import { serializeUploadUrl } from '../schemas.generated.js';
6
import { deserializeUploadUrl } from '../schemas.generated.js';
70✔
7
import { serializeConflictError } from '../schemas.generated.js';
8
import { deserializeConflictError } from '../schemas.generated.js';
9
import { Files } from '../schemas.generated.js';
10
import { ClientError } from '../schemas.generated.js';
11
import { UploadUrl } from '../schemas.generated.js';
12
import { ConflictError } from '../schemas.generated.js';
13
import { Authentication } from '../auth.js';
14
import { NetworkSession } from '../network.js';
15
import { prepareParams } from '../utils.js';
70✔
16
import { toString } from '../utils.js';
70✔
17
import { ByteStream } from '../utils.js';
18
import { CancellationToken } from '../utils.js';
19
import { sdToJson } from '../json.js';
20
import { fetch } from '../fetch.js';
70✔
21
import { FetchOptions } from '../fetch.js';
22
import { FetchResponse } from '../fetch.js';
23
import { MultipartItem } from '../fetch.js';
24
import { SerializedData } from '../json.js';
25
import { sdIsEmpty } from '../json.js';
26
import { sdIsBoolean } from '../json.js';
27
import { sdIsNumber } from '../json.js';
28
import { sdIsString } from '../json.js';
29
import { sdIsList } from '../json.js';
30
import { sdIsMap } from '../json.js';
31
export interface UploadFileVersionRequestBodyArgAttributesField {
32
  readonly name: string;
33
  readonly contentModifiedAt?: string;
34
}
35
export interface UploadFileVersionRequestBodyArg {
36
  readonly attributes: UploadFileVersionRequestBodyArgAttributesField;
37
  readonly file: ByteStream;
38
  readonly fileFileName?: string;
39
  readonly fileContentType?: string;
40
}
41
export interface UploadFileVersionQueryParamsArg {
42
  readonly fields?: readonly string[];
43
}
44
export class UploadFileVersionHeadersArg {
70✔
45
  readonly ifMatch?: string;
46
  readonly contentMd5?: string;
47
  readonly extraHeaders?: {
4✔
48
    readonly [key: string]: undefined | string;
49
  } = {};
50
  constructor(
51
    fields:
52
      | Omit<UploadFileVersionHeadersArg, 'extraHeaders'>
53
      | Partial<Pick<UploadFileVersionHeadersArg, 'extraHeaders'>>
54
  ) {
55
    Object.assign(this, fields);
4✔
56
  }
57
}
58
export interface UploadFileRequestBodyArgAttributesFieldParentField {
59
  readonly id: string;
60
}
61
export interface UploadFileRequestBodyArgAttributesField {
62
  readonly name: string;
63
  readonly parent: UploadFileRequestBodyArgAttributesFieldParentField;
64
  readonly contentCreatedAt?: string;
65
  readonly contentModifiedAt?: string;
66
}
67
export interface UploadFileRequestBodyArg {
68
  readonly attributes: UploadFileRequestBodyArgAttributesField;
69
  readonly file: ByteStream;
70
  readonly fileFileName?: string;
71
  readonly fileContentType?: string;
72
}
73
export interface UploadFileQueryParamsArg {
74
  readonly fields?: readonly string[];
75
}
76
export class UploadFileHeadersArg {
70✔
77
  readonly contentMd5?: string;
78
  readonly extraHeaders?: {
38✔
79
    readonly [key: string]: undefined | string;
80
  } = {};
81
  constructor(
82
    fields:
83
      | Omit<UploadFileHeadersArg, 'extraHeaders'>
84
      | Partial<Pick<UploadFileHeadersArg, 'extraHeaders'>>
85
  ) {
86
    Object.assign(this, fields);
38✔
87
  }
88
}
89
export interface PreflightFileUploadRequestBodyArgParentField {
90
  readonly id?: string;
91
}
92
export interface PreflightFileUploadRequestBodyArg {
93
  readonly name?: string;
94
  readonly size?: number;
95
  readonly parent?: PreflightFileUploadRequestBodyArgParentField;
96
}
97
export class PreflightFileUploadHeadersArg {
70✔
98
  readonly extraHeaders?: {
×
99
    readonly [key: string]: undefined | string;
100
  } = {};
101
  constructor(
102
    fields:
103
      | Omit<PreflightFileUploadHeadersArg, 'extraHeaders'>
104
      | Partial<Pick<PreflightFileUploadHeadersArg, 'extraHeaders'>>
105
  ) {
106
    Object.assign(this, fields);
×
107
  }
108
}
109
export class UploadsManager {
70✔
110
  readonly auth?: Authentication;
111
  readonly networkSession?: NetworkSession;
112
  constructor(
113
    fields: Omit<
114
      UploadsManager,
115
      'uploadFileVersion' | 'uploadFile' | 'preflightFileUpload'
116
    >
117
  ) {
118
    Object.assign(this, fields);
104✔
119
  }
120
  async uploadFileVersion(
121
    fileId: string,
122
    requestBody: UploadFileVersionRequestBodyArg,
123
    queryParams: UploadFileVersionQueryParamsArg = {} satisfies UploadFileVersionQueryParamsArg,
4✔
124
    headers: UploadFileVersionHeadersArg = new UploadFileVersionHeadersArg({}),
4✔
125
    cancellationToken?: CancellationToken
126
  ): Promise<Files> {
127
    const queryParamsMap: {
128
      readonly [key: string]: string;
129
    } = prepareParams({
4✔
130
      ['fields']: queryParams.fields
4!
131
        ? queryParams.fields.map(toString).join(',')
132
        : undefined,
133
    });
134
    const headersMap: {
135
      readonly [key: string]: string;
136
    } = prepareParams({
4✔
137
      ...{
138
        ['if-match']: toString(headers.ifMatch) as string,
139
        ['content-md5']: toString(headers.contentMd5) as string,
140
      },
141
      ...headers.extraHeaders,
142
    });
143
    const response: FetchResponse = (await fetch(
4✔
144
      ''.concat(
145
        'https://upload.box.com/api/2.0/files/',
146
        toString(fileId) as string,
147
        '/content'
148
      ) as string,
149
      {
150
        method: 'POST',
151
        params: queryParamsMap,
152
        headers: headersMap,
153
        multipartData: [
154
          {
155
            partName: 'attributes',
156
            data: serializeUploadFileVersionRequestBodyArgAttributesField(
157
              requestBody.attributes
158
            ),
159
          } satisfies MultipartItem,
160
          {
161
            partName: 'file',
162
            fileStream: requestBody.file,
163
            fileName: requestBody.fileFileName,
164
            contentType: requestBody.fileContentType,
165
          } satisfies MultipartItem,
166
        ],
167
        contentType: 'multipart/form-data',
168
        responseFormat: 'json',
169
        auth: this.auth,
170
        networkSession: this.networkSession,
171
        cancellationToken: cancellationToken,
172
      } satisfies FetchOptions
173
    )) as FetchResponse;
174
    return deserializeFiles(response.data);
4✔
175
  }
176
  async uploadFile(
177
    requestBody: UploadFileRequestBodyArg,
178
    queryParams: UploadFileQueryParamsArg = {} satisfies UploadFileQueryParamsArg,
36✔
179
    headers: UploadFileHeadersArg = new UploadFileHeadersArg({}),
36✔
180
    cancellationToken?: CancellationToken
181
  ): Promise<Files> {
182
    const queryParamsMap: {
183
      readonly [key: string]: string;
184
    } = prepareParams({
38✔
185
      ['fields']: queryParams.fields
38!
186
        ? queryParams.fields.map(toString).join(',')
187
        : undefined,
188
    });
189
    const headersMap: {
190
      readonly [key: string]: string;
191
    } = prepareParams({
38✔
192
      ...{ ['content-md5']: toString(headers.contentMd5) as string },
193
      ...headers.extraHeaders,
194
    });
195
    const response: FetchResponse = (await fetch(
38✔
196
      ''.concat('https://upload.box.com/api/2.0/files/content') as string,
197
      {
198
        method: 'POST',
199
        params: queryParamsMap,
200
        headers: headersMap,
201
        multipartData: [
202
          {
203
            partName: 'attributes',
204
            data: serializeUploadFileRequestBodyArgAttributesField(
205
              requestBody.attributes
206
            ),
207
          } satisfies MultipartItem,
208
          {
209
            partName: 'file',
210
            fileStream: requestBody.file,
211
            fileName: requestBody.fileFileName,
212
            contentType: requestBody.fileContentType,
213
          } satisfies MultipartItem,
214
        ],
215
        contentType: 'multipart/form-data',
216
        responseFormat: 'json',
217
        auth: this.auth,
218
        networkSession: this.networkSession,
219
        cancellationToken: cancellationToken,
220
      } satisfies FetchOptions
221
    )) as FetchResponse;
222
    return deserializeFiles(response.data);
36✔
223
  }
224
  async preflightFileUpload(
225
    requestBody: PreflightFileUploadRequestBodyArg = {} satisfies PreflightFileUploadRequestBodyArg,
×
226
    headers: PreflightFileUploadHeadersArg = new PreflightFileUploadHeadersArg(
×
227
      {}
228
    ),
229
    cancellationToken?: CancellationToken
230
  ): Promise<UploadUrl> {
231
    const headersMap: {
232
      readonly [key: string]: string;
233
    } = prepareParams({ ...{}, ...headers.extraHeaders });
×
234
    const response: FetchResponse = (await fetch(
×
235
      ''.concat('https://api.box.com/2.0/files/content') as string,
236
      {
237
        method: 'OPTIONS',
238
        headers: headersMap,
239
        data: serializePreflightFileUploadRequestBodyArg(requestBody),
240
        contentType: 'application/json',
241
        responseFormat: 'json',
242
        auth: this.auth,
243
        networkSession: this.networkSession,
244
        cancellationToken: cancellationToken,
245
      } satisfies FetchOptions
246
    )) as FetchResponse;
NEW
247
    return deserializeUploadUrl(response.data);
×
248
  }
249
}
250
export function serializeUploadFileVersionRequestBodyArgAttributesField(
70✔
251
  val: UploadFileVersionRequestBodyArgAttributesField
252
): SerializedData {
253
  return {
4✔
254
    ['name']: val.name,
255
    ['content_modified_at']:
256
      val.contentModifiedAt == void 0 ? void 0 : val.contentModifiedAt,
4!
257
  };
258
}
259
export function deserializeUploadFileVersionRequestBodyArgAttributesField(
70✔
260
  val: any
261
): UploadFileVersionRequestBodyArgAttributesField {
262
  const name: string = val.name;
×
263
  const contentModifiedAt: undefined | string =
264
    val.content_modified_at == void 0 ? void 0 : val.content_modified_at;
×
265
  return {
×
266
    name: name,
267
    contentModifiedAt: contentModifiedAt,
268
  } satisfies UploadFileVersionRequestBodyArgAttributesField;
269
}
270
export function serializeUploadFileRequestBodyArgAttributesFieldParentField(
70✔
271
  val: UploadFileRequestBodyArgAttributesFieldParentField
272
): SerializedData {
273
  return { ['id']: val.id };
38✔
274
}
275
export function deserializeUploadFileRequestBodyArgAttributesFieldParentField(
70✔
276
  val: any
277
): UploadFileRequestBodyArgAttributesFieldParentField {
278
  const id: string = val.id;
×
279
  return {
×
280
    id: id,
281
  } satisfies UploadFileRequestBodyArgAttributesFieldParentField;
282
}
283
export function serializeUploadFileRequestBodyArgAttributesField(
70✔
284
  val: UploadFileRequestBodyArgAttributesField
285
): SerializedData {
286
  return {
38✔
287
    ['name']: val.name,
288
    ['parent']: serializeUploadFileRequestBodyArgAttributesFieldParentField(
289
      val.parent
290
    ),
291
    ['content_created_at']:
292
      val.contentCreatedAt == void 0 ? void 0 : val.contentCreatedAt,
38!
293
    ['content_modified_at']:
294
      val.contentModifiedAt == void 0 ? void 0 : val.contentModifiedAt,
38!
295
  };
296
}
297
export function deserializeUploadFileRequestBodyArgAttributesField(
70✔
298
  val: any
299
): UploadFileRequestBodyArgAttributesField {
300
  const name: string = val.name;
×
301
  const parent: UploadFileRequestBodyArgAttributesFieldParentField =
302
    deserializeUploadFileRequestBodyArgAttributesFieldParentField(val.parent);
×
303
  const contentCreatedAt: undefined | string =
304
    val.content_created_at == void 0 ? void 0 : val.content_created_at;
×
305
  const contentModifiedAt: undefined | string =
306
    val.content_modified_at == void 0 ? void 0 : val.content_modified_at;
×
307
  return {
×
308
    name: name,
309
    parent: parent,
310
    contentCreatedAt: contentCreatedAt,
311
    contentModifiedAt: contentModifiedAt,
312
  } satisfies UploadFileRequestBodyArgAttributesField;
313
}
314
export function serializePreflightFileUploadRequestBodyArgParentField(
70✔
315
  val: PreflightFileUploadRequestBodyArgParentField
316
): SerializedData {
317
  return { ['id']: val.id == void 0 ? void 0 : val.id };
×
318
}
319
export function deserializePreflightFileUploadRequestBodyArgParentField(
70✔
320
  val: any
321
): PreflightFileUploadRequestBodyArgParentField {
322
  const id: undefined | string = val.id == void 0 ? void 0 : val.id;
×
323
  return { id: id } satisfies PreflightFileUploadRequestBodyArgParentField;
×
324
}
325
export function serializePreflightFileUploadRequestBodyArg(
70✔
326
  val: PreflightFileUploadRequestBodyArg
327
): SerializedData {
328
  return {
×
329
    ['name']: val.name == void 0 ? void 0 : val.name,
×
330
    ['size']: val.size == void 0 ? void 0 : val.size,
×
331
    ['parent']:
332
      val.parent == void 0
×
333
        ? void 0
334
        : serializePreflightFileUploadRequestBodyArgParentField(val.parent),
335
  };
336
}
337
export function deserializePreflightFileUploadRequestBodyArg(
70✔
338
  val: any
339
): PreflightFileUploadRequestBodyArg {
340
  const name: undefined | string = val.name == void 0 ? void 0 : val.name;
×
341
  const size: undefined | number = val.size == void 0 ? void 0 : val.size;
×
342
  const parent: undefined | PreflightFileUploadRequestBodyArgParentField =
343
    val.parent == void 0
×
344
      ? void 0
345
      : deserializePreflightFileUploadRequestBodyArgParentField(val.parent);
346
  return {
×
347
    name: name,
348
    size: size,
349
    parent: parent,
350
  } satisfies PreflightFileUploadRequestBodyArg;
351
}
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