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

box / box-typescript-sdk-gen / 12049597708

27 Nov 2024 11:43AM UTC coverage: 43.349%. First build
12049597708

Pull #431

github

web-flow
Merge 63b3d5cc8 into 991dc29bc
Pull Request #431: feat: Expose fetch method (box/box-codegen#610)

3883 of 15146 branches covered (25.64%)

Branch coverage included in aggregate %.

369 of 392 new or added lines in 74 files covered. (94.13%)

13570 of 25116 relevant lines covered (54.03%)

80.8 hits per line

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

49.14
/src/managers/authorization.generated.ts
1
import { serializeAccessToken } from '../schemas/accessToken.generated.js';
2
import { deserializeAccessToken } from '../schemas/accessToken.generated.js';
140✔
3
import { serializeOAuth2Error } from '../schemas/oAuth2Error.generated.js';
4
import { deserializeOAuth2Error } from '../schemas/oAuth2Error.generated.js';
5
import { serializePostOAuth2Token } from '../schemas/postOAuth2Token.generated.js';
140✔
6
import { deserializePostOAuth2Token } from '../schemas/postOAuth2Token.generated.js';
7
import { serializePostOAuth2TokenRefreshAccessToken } from '../schemas/postOAuth2TokenRefreshAccessToken.generated.js';
140✔
8
import { deserializePostOAuth2TokenRefreshAccessToken } from '../schemas/postOAuth2TokenRefreshAccessToken.generated.js';
9
import { serializePostOAuth2Revoke } from '../schemas/postOAuth2Revoke.generated.js';
140✔
10
import { deserializePostOAuth2Revoke } from '../schemas/postOAuth2Revoke.generated.js';
11
import { PostOAuth2TokenRefreshAccessTokenInput } from '../schemas/postOAuth2TokenRefreshAccessToken.generated.js';
12
import { ResponseFormat } from '../networking/fetchOptions.generated.js';
13
import { AccessToken } from '../schemas/accessToken.generated.js';
14
import { OAuth2Error } from '../schemas/oAuth2Error.generated.js';
15
import { PostOAuth2Token } from '../schemas/postOAuth2Token.generated.js';
16
import { PostOAuth2TokenRefreshAccessToken } from '../schemas/postOAuth2TokenRefreshAccessToken.generated.js';
140✔
17
import { PostOAuth2Revoke } from '../schemas/postOAuth2Revoke.generated.js';
18
import { Authentication } from '../networking/auth.generated.js';
19
import { NetworkSession } from '../networking/network.generated.js';
140✔
20
import { prepareParams } from '../internal/utils.js';
140✔
21
import { toString } from '../internal/utils.js';
140✔
22
import { ByteStream } from '../internal/utils.js';
23
import { CancellationToken } from '../internal/utils.js';
24
import { sdToJson } from '../serialization/json.js';
25
import { FetchOptions } from '../networking/fetchOptions.generated.js';
140✔
26
import { FetchResponse } from '../networking/fetchResponse.generated.js';
27
import { fetch } from '../networking/fetch.js';
140✔
28
import { SerializedData } from '../serialization/json.js';
29
import { BoxSdkError } from '../box/errors.js';
140✔
30
import { sdIsEmpty } from '../serialization/json.js';
31
import { sdIsBoolean } from '../serialization/json.js';
32
import { sdIsNumber } from '../serialization/json.js';
33
import { sdIsString } from '../serialization/json.js';
34
import { sdIsList } from '../serialization/json.js';
35
import { sdIsMap } from '../serialization/json.js';
36
export class AuthorizeUserOptionals {
140✔
37
  readonly headers: AuthorizeUserHeaders = new AuthorizeUserHeaders({});
×
38
  readonly cancellationToken?: CancellationToken = void 0;
×
39
  constructor(
40
    fields: Omit<AuthorizeUserOptionals, 'headers' | 'cancellationToken'> &
41
      Partial<Pick<AuthorizeUserOptionals, 'headers' | 'cancellationToken'>>,
42
  ) {
43
    if (fields.headers) {
×
44
      this.headers = fields.headers;
×
45
    }
46
    if (fields.cancellationToken) {
×
47
      this.cancellationToken = fields.cancellationToken;
×
48
    }
49
  }
50
}
51
export interface AuthorizeUserOptionalsInput {
52
  readonly headers?: AuthorizeUserHeaders;
53
  readonly cancellationToken?: undefined | CancellationToken;
54
}
55
export class RequestAccessTokenOptionals {
140✔
56
  readonly headers: RequestAccessTokenHeaders = new RequestAccessTokenHeaders(
274✔
57
    {},
58
  );
59
  readonly cancellationToken?: CancellationToken = void 0;
274✔
60
  constructor(
61
    fields: Omit<RequestAccessTokenOptionals, 'headers' | 'cancellationToken'> &
62
      Partial<
63
        Pick<RequestAccessTokenOptionals, 'headers' | 'cancellationToken'>
64
      >,
65
  ) {
66
    if (fields.headers) {
274!
67
      this.headers = fields.headers;
×
68
    }
69
    if (fields.cancellationToken) {
274!
70
      this.cancellationToken = fields.cancellationToken;
×
71
    }
72
  }
73
}
74
export interface RequestAccessTokenOptionalsInput {
75
  readonly headers?: RequestAccessTokenHeaders;
76
  readonly cancellationToken?: undefined | CancellationToken;
77
}
78
export class RefreshAccessTokenOptionals {
140✔
79
  readonly headers: RefreshAccessTokenHeaders = new RefreshAccessTokenHeaders(
×
80
    {},
81
  );
82
  readonly cancellationToken?: CancellationToken = void 0;
×
83
  constructor(
84
    fields: Omit<RefreshAccessTokenOptionals, 'headers' | 'cancellationToken'> &
85
      Partial<
86
        Pick<RefreshAccessTokenOptionals, 'headers' | 'cancellationToken'>
87
      >,
88
  ) {
89
    if (fields.headers) {
×
90
      this.headers = fields.headers;
×
91
    }
92
    if (fields.cancellationToken) {
×
93
      this.cancellationToken = fields.cancellationToken;
×
94
    }
95
  }
96
}
97
export interface RefreshAccessTokenOptionalsInput {
98
  readonly headers?: RefreshAccessTokenHeaders;
99
  readonly cancellationToken?: undefined | CancellationToken;
100
}
101
export class RevokeAccessTokenOptionals {
140✔
102
  readonly headers: RevokeAccessTokenHeaders = new RevokeAccessTokenHeaders({});
8✔
103
  readonly cancellationToken?: CancellationToken = void 0;
8✔
104
  constructor(
105
    fields: Omit<RevokeAccessTokenOptionals, 'headers' | 'cancellationToken'> &
106
      Partial<
107
        Pick<RevokeAccessTokenOptionals, 'headers' | 'cancellationToken'>
108
      >,
109
  ) {
110
    if (fields.headers) {
8!
111
      this.headers = fields.headers;
×
112
    }
113
    if (fields.cancellationToken) {
8!
114
      this.cancellationToken = fields.cancellationToken;
×
115
    }
116
  }
117
}
118
export interface RevokeAccessTokenOptionalsInput {
119
  readonly headers?: RevokeAccessTokenHeaders;
120
  readonly cancellationToken?: undefined | CancellationToken;
121
}
122
export type AuthorizeUserQueryParamsResponseTypeField = 'code';
123
export interface AuthorizeUserQueryParams {
124
  /**
125
   * The type of response we'd like to receive. */
126
  readonly responseType: AuthorizeUserQueryParamsResponseTypeField;
127
  /**
128
   * The Client ID of the application that is requesting to authenticate
129
   * the user. To get the Client ID for your application, log in to your
130
   * Box developer console and click the **Edit Application** link for
131
   * the application you're working with. In the OAuth 2.0 Parameters section
132
   * of the configuration page, find the item labelled `client_id`. The
133
   * text of that item is your application's Client ID. */
134
  readonly clientId: string;
135
  /**
136
   * The URI to which Box redirects the browser after the user has granted
137
   * or denied the application permission. This URI match one of the redirect
138
   * URIs in the configuration of your application. It must be a
139
   * valid HTTPS URI and it needs to be able to handle the redirection to
140
   * complete the next step in the OAuth 2.0 flow.
141
   * Although this parameter is optional, it must be a part of the
142
   * authorization URL if you configured multiple redirect URIs
143
   * for the application in the developer console. A missing parameter causes
144
   * a `redirect_uri_missing` error after the user grants application access. */
145
  readonly redirectUri?: string;
146
  /**
147
   * A custom string of your choice. Box will pass the same string to
148
   * the redirect URL when authentication is complete. This parameter
149
   * can be used to identify a user on redirect, as well as protect
150
   * against hijacked sessions and other exploits. */
151
  readonly state?: string;
152
  /**
153
   * A space-separated list of application scopes you'd like to
154
   * authenticate the user for. This defaults to all the scopes configured
155
   * for the application in its configuration page. */
156
  readonly scope?: string;
157
}
158
export class AuthorizeUserHeaders {
140✔
159
  /**
160
   * Extra headers that will be included in the HTTP request. */
161
  readonly extraHeaders?: {
×
162
    readonly [key: string]: undefined | string;
163
  } = {};
164
  constructor(
165
    fields: Omit<AuthorizeUserHeaders, 'extraHeaders'> &
166
      Partial<Pick<AuthorizeUserHeaders, 'extraHeaders'>>,
167
  ) {
168
    if (fields.extraHeaders) {
×
169
      this.extraHeaders = fields.extraHeaders;
×
170
    }
171
  }
172
}
173
export interface AuthorizeUserHeadersInput {
174
  /**
175
   * Extra headers that will be included in the HTTP request. */
176
  readonly extraHeaders?:
177
    | undefined
178
    | {
179
        readonly [key: string]: undefined | string;
180
      };
181
}
182
export class RequestAccessTokenHeaders {
140✔
183
  /**
184
   * Extra headers that will be included in the HTTP request. */
185
  readonly extraHeaders?: {
274✔
186
    readonly [key: string]: undefined | string;
187
  } = {};
188
  constructor(
189
    fields: Omit<RequestAccessTokenHeaders, 'extraHeaders'> &
190
      Partial<Pick<RequestAccessTokenHeaders, 'extraHeaders'>>,
191
  ) {
192
    if (fields.extraHeaders) {
274!
193
      this.extraHeaders = fields.extraHeaders;
×
194
    }
195
  }
196
}
197
export interface RequestAccessTokenHeadersInput {
198
  /**
199
   * Extra headers that will be included in the HTTP request. */
200
  readonly extraHeaders?:
201
    | undefined
202
    | {
203
        readonly [key: string]: undefined | string;
204
      };
205
}
206
export class RefreshAccessTokenHeaders {
140✔
207
  /**
208
   * Extra headers that will be included in the HTTP request. */
209
  readonly extraHeaders?: {
×
210
    readonly [key: string]: undefined | string;
211
  } = {};
212
  constructor(
213
    fields: Omit<RefreshAccessTokenHeaders, 'extraHeaders'> &
214
      Partial<Pick<RefreshAccessTokenHeaders, 'extraHeaders'>>,
215
  ) {
216
    if (fields.extraHeaders) {
×
217
      this.extraHeaders = fields.extraHeaders;
×
218
    }
219
  }
220
}
221
export interface RefreshAccessTokenHeadersInput {
222
  /**
223
   * Extra headers that will be included in the HTTP request. */
224
  readonly extraHeaders?:
225
    | undefined
226
    | {
227
        readonly [key: string]: undefined | string;
228
      };
229
}
230
export class RevokeAccessTokenHeaders {
140✔
231
  /**
232
   * Extra headers that will be included in the HTTP request. */
233
  readonly extraHeaders?: {
8✔
234
    readonly [key: string]: undefined | string;
235
  } = {};
236
  constructor(
237
    fields: Omit<RevokeAccessTokenHeaders, 'extraHeaders'> &
238
      Partial<Pick<RevokeAccessTokenHeaders, 'extraHeaders'>>,
239
  ) {
240
    if (fields.extraHeaders) {
8!
241
      this.extraHeaders = fields.extraHeaders;
×
242
    }
243
  }
244
}
245
export interface RevokeAccessTokenHeadersInput {
246
  /**
247
   * Extra headers that will be included in the HTTP request. */
248
  readonly extraHeaders?:
249
    | undefined
250
    | {
251
        readonly [key: string]: undefined | string;
252
      };
253
}
254
export class AuthorizationManager {
140✔
255
  readonly auth?: Authentication;
256
  readonly networkSession: NetworkSession = new NetworkSession({});
582✔
257
  constructor(
258
    fields: Omit<
259
      AuthorizationManager,
260
      | 'networkSession'
261
      | 'authorizeUser'
262
      | 'requestAccessToken'
263
      | 'refreshAccessToken'
264
      | 'revokeAccessToken'
265
    > &
266
      Partial<Pick<AuthorizationManager, 'networkSession'>>,
267
  ) {
268
    if (fields.auth) {
582✔
269
      this.auth = fields.auth;
300✔
270
    }
271
    if (fields.networkSession) {
582✔
272
      this.networkSession = fields.networkSession;
582✔
273
    }
274
  }
275
  /**
276
   * Authorize a user by sending them through the [Box](https://box.com)
277
   * website and request their permission to act on their behalf.
278
   *
279
   * This is the first step when authenticating a user using
280
   * OAuth 2.0. To request a user's authorization to use the Box APIs
281
   * on their behalf you will need to send a user to the URL with this
282
   * format.
283
   * @param {AuthorizeUserQueryParams} queryParams Query parameters of authorizeUser method
284
   * @param {AuthorizeUserOptionalsInput} optionalsInput
285
   * @returns {Promise<undefined>}
286
   */
287
  async authorizeUser(
288
    queryParams: AuthorizeUserQueryParams,
×
289
    optionalsInput: AuthorizeUserOptionalsInput = {},
×
290
  ): Promise<undefined> {
291
    const optionals: AuthorizeUserOptionals = new AuthorizeUserOptionals({
×
292
      headers: optionalsInput.headers,
293
      cancellationToken: optionalsInput.cancellationToken,
294
    });
295
    const headers: any = optionals.headers;
×
296
    const cancellationToken: any = optionals.cancellationToken;
×
297
    const queryParamsMap: {
298
      readonly [key: string]: string;
299
    } = prepareParams({
×
300
      ['response_type']: toString(queryParams.responseType) as string,
301
      ['client_id']: toString(queryParams.clientId) as string,
302
      ['redirect_uri']: toString(queryParams.redirectUri) as string,
303
      ['state']: toString(queryParams.state) as string,
304
      ['scope']: toString(queryParams.scope) as string,
305
    });
306
    const headersMap: {
307
      readonly [key: string]: string;
308
    } = prepareParams({ ...{}, ...headers.extraHeaders });
×
NEW
309
    const response: FetchResponse = (await fetch(
×
310
      new FetchOptions({
311
        url: ''.concat(
312
          this.networkSession.baseUrls.oauth2Url,
313
          '/authorize',
314
        ) as string,
315
        method: 'GET',
316
        params: queryParamsMap,
317
        headers: headersMap,
318
        responseFormat: 'no_content' as ResponseFormat,
319
        auth: this.auth,
320
        networkSession: this.networkSession,
321
        cancellationToken: cancellationToken,
322
      }),
323
    )) as FetchResponse;
324
    return void 0;
×
325
  }
326
  /**
327
   * Request an Access Token using either a client-side obtained OAuth 2.0
328
   * authorization code or a server-side JWT assertion.
329
   *
330
   * An Access Token is a string that enables Box to verify that a
331
   * request belongs to an authorized session. In the normal order of
332
   * operations you will begin by requesting authentication from the
333
   * [authorize](#get-authorize) endpoint and Box will send you an
334
   * authorization code.
335
   *
336
   * You will then send this code to this endpoint to exchange it for
337
   * an Access Token. The returned Access Token can then be used to to make
338
   * Box API calls.
339
   * @param {PostOAuth2Token} requestBody Request body of requestAccessToken method
340
   * @param {RequestAccessTokenOptionalsInput} optionalsInput
341
   * @returns {Promise<AccessToken>}
342
   */
343
  async requestAccessToken(
344
    requestBody: PostOAuth2Token,
274✔
345
    optionalsInput: RequestAccessTokenOptionalsInput = {},
274✔
346
  ): Promise<AccessToken> {
347
    const optionals: RequestAccessTokenOptionals =
348
      new RequestAccessTokenOptionals({
274✔
349
        headers: optionalsInput.headers,
350
        cancellationToken: optionalsInput.cancellationToken,
351
      });
352
    const headers: any = optionals.headers;
274✔
353
    const cancellationToken: any = optionals.cancellationToken;
274✔
354
    const headersMap: {
355
      readonly [key: string]: string;
356
    } = prepareParams({ ...{}, ...headers.extraHeaders });
274✔
357
    const response: FetchResponse = (await fetch(
274✔
358
      new FetchOptions({
359
        url: ''.concat(
360
          this.networkSession.baseUrls.baseUrl,
361
          '/oauth2/token',
362
        ) as string,
363
        method: 'POST',
364
        headers: headersMap,
365
        data: serializePostOAuth2Token(requestBody),
366
        contentType: 'application/x-www-form-urlencoded',
367
        responseFormat: 'json' as ResponseFormat,
368
        auth: this.auth,
369
        networkSession: this.networkSession,
370
        cancellationToken: cancellationToken,
371
      }),
372
    )) as FetchResponse;
373
    return {
272✔
374
      ...deserializeAccessToken(response.data!),
375
      rawData: response.data!,
376
    };
377
  }
378
  /**
379
   * Refresh an Access Token using its client ID, secret, and refresh token.
380
   * @param {PostOAuth2TokenRefreshAccessTokenInput} requestBodyInput Request body of refreshAccessToken method
381
   * @param {RefreshAccessTokenOptionalsInput} optionalsInput
382
   * @returns {Promise<AccessToken>}
383
   */
384
  async refreshAccessToken(
385
    requestBodyInput: PostOAuth2TokenRefreshAccessTokenInput,
×
386
    optionalsInput: RefreshAccessTokenOptionalsInput = {},
×
387
  ): Promise<AccessToken> {
388
    const requestBody: PostOAuth2TokenRefreshAccessToken =
389
      new PostOAuth2TokenRefreshAccessToken({
×
390
        grantType: requestBodyInput.grantType,
391
        clientId: requestBodyInput.clientId,
392
        clientSecret: requestBodyInput.clientSecret,
393
        refreshToken: requestBodyInput.refreshToken,
394
      });
395
    const optionals: RefreshAccessTokenOptionals =
396
      new RefreshAccessTokenOptionals({
×
397
        headers: optionalsInput.headers,
398
        cancellationToken: optionalsInput.cancellationToken,
399
      });
400
    const headers: any = optionals.headers;
×
401
    const cancellationToken: any = optionals.cancellationToken;
×
402
    const headersMap: {
403
      readonly [key: string]: string;
404
    } = prepareParams({ ...{}, ...headers.extraHeaders });
×
NEW
405
    const response: FetchResponse = (await fetch(
×
406
      new FetchOptions({
407
        url: ''.concat(
408
          this.networkSession.baseUrls.baseUrl,
409
          '/oauth2/token#refresh',
410
        ) as string,
411
        method: 'POST',
412
        headers: headersMap,
413
        data: serializePostOAuth2TokenRefreshAccessToken(requestBody),
414
        contentType: 'application/x-www-form-urlencoded',
415
        responseFormat: 'json' as ResponseFormat,
416
        auth: this.auth,
417
        networkSession: this.networkSession,
418
        cancellationToken: cancellationToken,
419
      }),
420
    )) as FetchResponse;
421
    return {
×
422
      ...deserializeAccessToken(response.data!),
423
      rawData: response.data!,
424
    };
425
  }
426
  /**
427
   * Revoke an active Access Token, effectively logging a user out
428
   * that has been previously authenticated.
429
   * @param {PostOAuth2Revoke} requestBody Request body of revokeAccessToken method
430
   * @param {RevokeAccessTokenOptionalsInput} optionalsInput
431
   * @returns {Promise<undefined>}
432
   */
433
  async revokeAccessToken(
434
    requestBody: PostOAuth2Revoke,
8✔
435
    optionalsInput: RevokeAccessTokenOptionalsInput = {},
8✔
436
  ): Promise<undefined> {
437
    const optionals: RevokeAccessTokenOptionals =
438
      new RevokeAccessTokenOptionals({
8✔
439
        headers: optionalsInput.headers,
440
        cancellationToken: optionalsInput.cancellationToken,
441
      });
442
    const headers: any = optionals.headers;
8✔
443
    const cancellationToken: any = optionals.cancellationToken;
8✔
444
    const headersMap: {
445
      readonly [key: string]: string;
446
    } = prepareParams({ ...{}, ...headers.extraHeaders });
8✔
447
    const response: FetchResponse = (await fetch(
8✔
448
      new FetchOptions({
449
        url: ''.concat(
450
          this.networkSession.baseUrls.baseUrl,
451
          '/oauth2/revoke',
452
        ) as string,
453
        method: 'POST',
454
        headers: headersMap,
455
        data: serializePostOAuth2Revoke(requestBody),
456
        contentType: 'application/x-www-form-urlencoded',
457
        responseFormat: 'no_content' as ResponseFormat,
458
        auth: this.auth,
459
        networkSession: this.networkSession,
460
        cancellationToken: cancellationToken,
461
      }),
462
    )) as FetchResponse;
463
    return void 0;
8✔
464
  }
465
}
466
export interface AuthorizationManagerInput {
467
  readonly auth?: Authentication;
468
  readonly networkSession?: NetworkSession;
469
}
470
export function serializeAuthorizeUserQueryParamsResponseTypeField(
140✔
471
  val: AuthorizeUserQueryParamsResponseTypeField,
472
): SerializedData {
473
  return val;
×
474
}
475
export function deserializeAuthorizeUserQueryParamsResponseTypeField(
140✔
476
  val: SerializedData,
477
): AuthorizeUserQueryParamsResponseTypeField {
478
  if (val == 'code') {
×
479
    return val;
×
480
  }
481
  throw new BoxSdkError({
×
482
    message: "Can't deserialize AuthorizeUserQueryParamsResponseTypeField",
483
  });
484
}
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