• 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

71.43
/src/managers/downloads.generated.ts
1
import { serializeClientError } from '../schemas/clientError.generated.js';
2
import { deserializeClientError } from '../schemas/clientError.generated.js';
3
import { ClientError } from '../schemas/clientError.generated.js';
4
import { Authentication } from '../networking/auth.generated.js';
5
import { NetworkSession } from '../networking/network.generated.js';
140✔
6
import { prepareParams } from '../internal/utils.js';
140✔
7
import { toString } from '../internal/utils.js';
140✔
8
import { ByteStream } from '../internal/utils.js';
9
import { CancellationToken } from '../internal/utils.js';
10
import { sdToJson } from '../serialization/json.js';
11
import { FetchOptions } from '../networking/fetch.js';
12
import { FetchResponse } from '../networking/fetch.js';
13
import { fetch } from '../networking/fetch.js';
140✔
14
import { SerializedData } from '../serialization/json.js';
15
import { sdIsEmpty } from '../serialization/json.js';
16
import { sdIsBoolean } from '../serialization/json.js';
17
import { sdIsNumber } from '../serialization/json.js';
18
import { sdIsString } from '../serialization/json.js';
19
import { sdIsList } from '../serialization/json.js';
20
import { sdIsMap } from '../serialization/json.js';
21
export class DownloadFileOptionals {
140✔
22
  readonly queryParams: DownloadFileQueryParams =
6✔
23
    {} satisfies DownloadFileQueryParams;
24
  readonly headers: DownloadFileHeaders = new DownloadFileHeaders({});
6✔
25
  readonly cancellationToken?: CancellationToken = void 0;
6✔
26
  constructor(
27
    fields: Omit<
28
      DownloadFileOptionals,
29
      'queryParams' | 'headers' | 'cancellationToken'
30
    > &
31
      Partial<
32
        Pick<
33
          DownloadFileOptionals,
34
          'queryParams' | 'headers' | 'cancellationToken'
35
        >
36
      >,
37
  ) {
38
    if (fields.queryParams) {
6!
39
      this.queryParams = fields.queryParams;
×
40
    }
41
    if (fields.headers) {
6!
42
      this.headers = fields.headers;
×
43
    }
44
    if (fields.cancellationToken) {
6!
45
      this.cancellationToken = fields.cancellationToken;
×
46
    }
47
  }
48
}
49
export interface DownloadFileOptionalsInput {
50
  readonly queryParams?: DownloadFileQueryParams;
51
  readonly headers?: DownloadFileHeaders;
52
  readonly cancellationToken?: undefined | CancellationToken;
53
}
54
export interface DownloadFileQueryParams {
55
  /**
56
   * The file version to download */
57
  readonly version?: string;
58
  /**
59
   * An optional access token that can be used to pre-authenticate this request, which means that a download link can be shared with a browser or a third party service without them needing to know how to handle the authentication.
60
   * When using this parameter, please make sure that the access token is sufficiently scoped down to only allow read access to that file and no other files or folders. */
61
  readonly accessToken?: string;
62
}
63
export class DownloadFileHeaders {
140✔
64
  /**
65
   * The byte range of the content to download.
66
   *
67
   * The format `bytes={start_byte}-{end_byte}` can be used to specify
68
   * what section of the file to download. */
69
  readonly range?: string;
70
  /**
71
   * The URL, and optional password, for the shared link of this item.
72
   *
73
   * This header can be used to access items that have not been
74
   * explicitly shared with a user.
75
   *
76
   * Use the format `shared_link=[link]` or if a password is required then
77
   * use `shared_link=[link]&shared_link_password=[password]`.
78
   *
79
   * This header can be used on the file or folder shared, as well as on any files
80
   * or folders nested within the item. */
81
  readonly boxapi?: string;
82
  /**
83
   * Extra headers that will be included in the HTTP request. */
84
  readonly extraHeaders?: {
6✔
85
    readonly [key: string]: undefined | string;
86
  } = {};
87
  constructor(
88
    fields: Omit<DownloadFileHeaders, 'extraHeaders'> &
89
      Partial<Pick<DownloadFileHeaders, 'extraHeaders'>>,
90
  ) {
91
    if (fields.range) {
6!
92
      this.range = fields.range;
×
93
    }
94
    if (fields.boxapi) {
6!
95
      this.boxapi = fields.boxapi;
×
96
    }
97
    if (fields.extraHeaders) {
6!
98
      this.extraHeaders = fields.extraHeaders;
×
99
    }
100
  }
101
}
102
export interface DownloadFileHeadersInput {
103
  /**
104
   * The byte range of the content to download.
105
   *
106
   * The format `bytes={start_byte}-{end_byte}` can be used to specify
107
   * what section of the file to download. */
108
  readonly range?: string;
109
  /**
110
   * The URL, and optional password, for the shared link of this item.
111
   *
112
   * This header can be used to access items that have not been
113
   * explicitly shared with a user.
114
   *
115
   * Use the format `shared_link=[link]` or if a password is required then
116
   * use `shared_link=[link]&shared_link_password=[password]`.
117
   *
118
   * This header can be used on the file or folder shared, as well as on any files
119
   * or folders nested within the item. */
120
  readonly boxapi?: string;
121
  /**
122
   * Extra headers that will be included in the HTTP request. */
123
  readonly extraHeaders?:
124
    | undefined
125
    | {
126
        readonly [key: string]: undefined | string;
127
      };
128
}
129
export class DownloadsManager {
140✔
130
  readonly auth?: Authentication;
131
  readonly networkSession: NetworkSession = new NetworkSession({});
298✔
132
  constructor(
133
    fields: Omit<DownloadsManager, 'networkSession' | 'downloadFile'> &
134
      Partial<Pick<DownloadsManager, 'networkSession'>>,
135
  ) {
136
    if (fields.auth) {
298✔
137
      this.auth = fields.auth;
298✔
138
    }
139
    if (fields.networkSession) {
298✔
140
      this.networkSession = fields.networkSession;
298✔
141
    }
142
  }
143
  /**
144
     * Returns the contents of a file in binary format.
145
     * @param {string} fileId The unique identifier that represents a file.
146
    
147
    The ID for any file can be determined
148
    by visiting a file in the web application
149
    and copying the ID from the URL. For example,
150
    for the URL `https://*.app.box.com/files/123`
151
    the `file_id` is `123`.
152
    Example: "12345"
153
     * @param {DownloadFileOptionalsInput} optionalsInput
154
     * @returns {Promise<undefined | ByteStream>}
155
     */
156
  async downloadFile(
157
    fileId: string,
6✔
158
    optionalsInput: DownloadFileOptionalsInput = {},
6✔
159
  ): Promise<undefined | ByteStream> {
160
    const optionals: DownloadFileOptionals = new DownloadFileOptionals({
6✔
161
      queryParams: optionalsInput.queryParams,
162
      headers: optionalsInput.headers,
163
      cancellationToken: optionalsInput.cancellationToken,
164
    });
165
    const queryParams: any = optionals.queryParams;
6✔
166
    const headers: any = optionals.headers;
6✔
167
    const cancellationToken: any = optionals.cancellationToken;
6✔
168
    const queryParamsMap: {
169
      readonly [key: string]: string;
170
    } = prepareParams({
6✔
171
      ['version']: toString(queryParams.version) as string,
172
      ['access_token']: toString(queryParams.accessToken) as string,
173
    });
174
    const headersMap: {
175
      readonly [key: string]: string;
176
    } = prepareParams({
6✔
177
      ...{
178
        ['range']: toString(headers.range) as string,
179
        ['boxapi']: toString(headers.boxapi) as string,
180
      },
181
      ...headers.extraHeaders,
182
    });
183
    const response: FetchResponse = (await fetch({
6✔
184
      url: ''.concat(
185
        this.networkSession.baseUrls.baseUrl,
186
        '/2.0/files/',
187
        toString(fileId) as string,
188
        '/content',
189
      ) as string,
190
      method: 'GET',
191
      params: queryParamsMap,
192
      headers: headersMap,
193
      responseFormat: 'binary',
194
      auth: this.auth,
195
      networkSession: this.networkSession,
196
      cancellationToken: cancellationToken,
197
    } satisfies FetchOptions)) as FetchResponse;
198
    if ((toString(response.status) as string) == '202') {
4!
NEW
199
      return void 0;
×
200
    }
201
    return response.content;
4✔
202
  }
203
}
204
export interface DownloadsManagerInput {
205
  readonly auth?: Authentication;
206
  readonly networkSession?: NetworkSession;
207
}
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