box-node-sdk 10.4.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/lib/bundle.js +117 -7
  2. package/lib/bundle.js.map +1 -1
  3. package/lib/client.d.ts +8 -1
  4. package/lib/client.d.ts.map +1 -1
  5. package/lib/client.js +11 -0
  6. package/lib/client.js.map +1 -1
  7. package/lib/managers/archives.d.ts +4 -0
  8. package/lib/managers/archives.d.ts.map +1 -1
  9. package/lib/managers/archives.js +4 -0
  10. package/lib/managers/archives.js.map +1 -1
  11. package/lib/networking/boxNetworkClient.d.ts.map +1 -1
  12. package/lib/networking/boxNetworkClient.js +61 -6
  13. package/lib/networking/boxNetworkClient.js.map +1 -1
  14. package/lib/networking/network.d.ts +10 -1
  15. package/lib/networking/network.d.ts.map +1 -1
  16. package/lib/networking/network.js +29 -0
  17. package/lib/networking/network.js.map +1 -1
  18. package/lib/networking/timeoutConfig.d.ts +4 -0
  19. package/lib/networking/timeoutConfig.d.ts.map +1 -0
  20. package/lib/networking/timeoutConfig.js +3 -0
  21. package/lib/networking/timeoutConfig.js.map +1 -0
  22. package/lib/networking/version.d.ts +1 -1
  23. package/lib/networking/version.js +1 -1
  24. package/lib/schemas/index.d.ts +4 -4
  25. package/lib/schemas/index.d.ts.map +1 -1
  26. package/lib/schemas/index.js +4 -4
  27. package/lib/schemas/index.js.map +1 -1
  28. package/lib/schemas/v2025R0/hubUpdateRequestV2025R0.d.ts +3 -0
  29. package/lib/schemas/v2025R0/hubUpdateRequestV2025R0.d.ts.map +1 -1
  30. package/lib/schemas/v2025R0/hubUpdateRequestV2025R0.js +11 -0
  31. package/lib/schemas/v2025R0/hubUpdateRequestV2025R0.js.map +1 -1
  32. package/lib/schemas/v2025R0/hubV2025R0.d.ts +1 -0
  33. package/lib/schemas/v2025R0/hubV2025R0.d.ts.map +1 -1
  34. package/lib/schemas/v2025R0/hubV2025R0.js +14 -0
  35. package/lib/schemas/v2025R0/hubV2025R0.js.map +1 -1
  36. package/lib-esm/client.d.ts +8 -1
  37. package/lib-esm/client.js +11 -0
  38. package/lib-esm/client.js.map +1 -1
  39. package/lib-esm/managers/archives.d.ts +4 -0
  40. package/lib-esm/managers/archives.js +4 -0
  41. package/lib-esm/managers/archives.js.map +1 -1
  42. package/lib-esm/networking/boxNetworkClient.js +67 -6
  43. package/lib-esm/networking/boxNetworkClient.js.map +1 -1
  44. package/lib-esm/networking/network.d.ts +10 -1
  45. package/lib-esm/networking/network.js +30 -0
  46. package/lib-esm/networking/network.js.map +1 -1
  47. package/lib-esm/networking/timeoutConfig.d.ts +3 -0
  48. package/lib-esm/networking/timeoutConfig.js +2 -0
  49. package/lib-esm/networking/timeoutConfig.js.map +1 -0
  50. package/lib-esm/networking/version.d.ts +1 -1
  51. package/lib-esm/networking/version.js +1 -1
  52. package/lib-esm/schemas/index.d.ts +4 -4
  53. package/lib-esm/schemas/index.js +4 -4
  54. package/lib-esm/schemas/index.js.map +1 -1
  55. package/lib-esm/schemas/v2025R0/hubUpdateRequestV2025R0.d.ts +3 -0
  56. package/lib-esm/schemas/v2025R0/hubUpdateRequestV2025R0.js +11 -0
  57. package/lib-esm/schemas/v2025R0/hubUpdateRequestV2025R0.js.map +1 -1
  58. package/lib-esm/schemas/v2025R0/hubV2025R0.d.ts +1 -0
  59. package/lib-esm/schemas/v2025R0/hubV2025R0.js +15 -0
  60. package/lib-esm/schemas/v2025R0/hubV2025R0.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/client.ts +13 -0
  63. package/src/managers/archives.ts +4 -0
  64. package/src/networking/boxNetworkClient.ts +82 -13
  65. package/src/networking/network.ts +33 -0
  66. package/src/networking/timeoutConfig.ts +3 -0
  67. package/src/networking/version.ts +1 -1
  68. package/src/schemas/index.ts +4 -4
  69. package/src/schemas/v2025R0/hubUpdateRequestV2025R0.ts +18 -0
  70. package/src/schemas/v2025R0/hubV2025R0.ts +19 -0
  71. package/src/test/archives.test.ts +0 -1
  72. package/src/test/client.test.ts +17 -0
package/lib/bundle.js CHANGED
@@ -3622,7 +3622,7 @@
3622
3622
  var browserExports = browser.exports;
3623
3623
  var nodeFetch = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
3624
3624
 
3625
- const sdkVersion = '10.4.0';
3625
+ const sdkVersion = '10.5.0';
3626
3626
 
3627
3627
  class BoxRetryStrategy {
3628
3628
  constructor(fields) {
@@ -3707,6 +3707,46 @@
3707
3707
  (options.responseFormat === 'binary' ||
3708
3708
  options.responseFormat === 'no_content'));
3709
3709
  };
3710
+ function createAbortSignalWithTimeout(baseSignal, timeoutMs) {
3711
+ var _a;
3712
+ const controller = new AbortController();
3713
+ const upstream = baseSignal;
3714
+ let timedOut = false;
3715
+ const abortFromUpstream = () => {
3716
+ try {
3717
+ controller.abort(upstream === null || upstream === void 0 ? void 0 : upstream.reason);
3718
+ }
3719
+ catch (_a) {
3720
+ controller.abort();
3721
+ }
3722
+ };
3723
+ if (upstream) {
3724
+ if (upstream.aborted) {
3725
+ abortFromUpstream();
3726
+ }
3727
+ else {
3728
+ upstream.addEventListener('abort', abortFromUpstream, { once: true });
3729
+ }
3730
+ }
3731
+ const timeoutId = setTimeout(() => {
3732
+ timedOut = true;
3733
+ controller.abort();
3734
+ }, timeoutMs);
3735
+ // Node.js timers keep the event loop alive. If the only pending work is this
3736
+ // watchdog timeout, we don't want it to prevent process exit (e.g. short CLI
3737
+ // runs, tests, scripts). `unref()` detaches the timer from the event loop.
3738
+ // It’s a no-op in environments where `unref` isn’t available.
3739
+ (_a = timeoutId === null || timeoutId === void 0 ? void 0 : timeoutId.unref) === null || _a === void 0 ? void 0 : _a.call(timeoutId);
3740
+ return {
3741
+ signal: controller.signal,
3742
+ clearTimeout: () => {
3743
+ clearTimeout(timeoutId);
3744
+ if (upstream)
3745
+ upstream.removeEventListener('abort', abortFromUpstream);
3746
+ },
3747
+ didTimeout: () => timedOut,
3748
+ };
3749
+ }
3710
3750
  function createRequestInit(options) {
3711
3751
  return __awaiter$1(this, void 0, void 0, function* () {
3712
3752
  var _a, _b;
@@ -3809,11 +3849,18 @@
3809
3849
  : void 0, multipartData: multipartBuffer
3810
3850
  ? multipartBufferToStream(multipartBuffer)
3811
3851
  : void 0 }));
3852
+ const timeoutConfig = (_j = fetchOptions.networkSession) === null || _j === void 0 ? void 0 : _j.timeoutConfig;
3853
+ const timeoutMs = timeoutConfig === null || timeoutConfig === void 0 ? void 0 : timeoutConfig.timeoutMs;
3854
+ const requestTimeout = timeoutMs != null && timeoutMs > 0
3855
+ ? createAbortSignalWithTimeout(requestInit.signal, timeoutMs)
3856
+ : undefined;
3857
+ const requestInitWithTimeout = requestTimeout
3858
+ ? Object.assign(Object.assign({}, requestInit), { signal: requestTimeout.signal }) : requestInit;
3812
3859
  try {
3813
- const response = yield nodeFetch(''.concat(fetchOptions.url, Object.keys(params).length === 0 || fetchOptions.url.endsWith('?')
3860
+ const requestUrl = ''.concat(fetchOptions.url, Object.keys(params).length === 0 || fetchOptions.url.endsWith('?')
3814
3861
  ? ''
3815
- : '?', new URLSearchParams(params).toString()), Object.assign(Object.assign({}, requestInit), { redirect: isBrowser() ? 'follow' : 'manual' }));
3816
- const contentType = (_j = response.headers.get('content-type')) !== null && _j !== void 0 ? _j : '';
3862
+ : '?', new URLSearchParams(params).toString());
3863
+ const response = yield nodeFetch(requestUrl, Object.assign(Object.assign({}, requestInitWithTimeout), { redirect: isBrowser() ? 'follow' : 'manual' }));
3817
3864
  const ignoreResponseBody = fetchOptions.followRedirects === false;
3818
3865
  let data;
3819
3866
  let content = generateByteStreamFromBuffer(new Uint8Array().buffer);
@@ -3845,16 +3892,24 @@
3845
3892
  catch (error) {
3846
3893
  isExceptionCase = true;
3847
3894
  numberOfRetriesOnException++;
3848
- caughtError = error instanceof Error ? error : new Error(String(error));
3895
+ if (requestTimeout === null || requestTimeout === void 0 ? void 0 : requestTimeout.didTimeout()) {
3896
+ caughtError = new Error(`Connection timeout after ${timeoutMs}ms`);
3897
+ }
3898
+ else {
3899
+ caughtError = error instanceof Error ? error : new Error(String(error));
3900
+ }
3849
3901
  fetchResponse = fetchResponse !== null && fetchResponse !== void 0 ? fetchResponse : { status: 0, headers: {} };
3850
3902
  }
3903
+ finally {
3904
+ requestTimeout === null || requestTimeout === void 0 ? void 0 : requestTimeout.clearTimeout();
3905
+ }
3851
3906
  const attemptForRetry = isExceptionCase
3852
3907
  ? numberOfRetriesOnException
3853
3908
  : attemptNumber;
3854
3909
  const shouldRetry = yield retryStrategy.shouldRetry(fetchOptions, fetchResponse, attemptForRetry);
3855
3910
  if (shouldRetry) {
3856
3911
  const retryTimeout = retryStrategy.retryAfter(fetchOptions, fetchResponse, attemptForRetry);
3857
- yield new Promise((resolve) => setTimeout(resolve, retryTimeout));
3912
+ yield new Promise((resolve) => setTimeout(resolve, retryTimeout * 1000));
3858
3913
  return this.fetch(Object.assign(Object.assign({}, options), { attemptNumber: attemptNumber + 1, numberOfRetriesOnException: numberOfRetriesOnException, fileStream: fileStreamBuffer
3859
3914
  ? generateByteStreamFromBuffer(fileStreamBuffer)
3860
3915
  : void 0, multipartData: multipartBuffer
@@ -3891,7 +3946,7 @@
3891
3946
  : [];
3892
3947
  if (fetchResponse.status === 0) {
3893
3948
  throw new BoxSdkError({
3894
- message: `Unexpected Error occurred`,
3949
+ message: (caughtError === null || caughtError === void 0 ? void 0 : caughtError.message) || `Unexpected Error occurred`,
3895
3950
  timestamp: `${Date.now()}`,
3896
3951
  error: caughtError,
3897
3952
  });
@@ -3976,6 +4031,9 @@
3976
4031
  if (fields.dataSanitizer !== undefined) {
3977
4032
  this.dataSanitizer = fields.dataSanitizer;
3978
4033
  }
4034
+ if (fields.timeoutConfig !== undefined) {
4035
+ this.timeoutConfig = fields.timeoutConfig;
4036
+ }
3979
4037
  }
3980
4038
  /**
3981
4039
  * Generate a fresh network session by duplicating the existing configuration and network parameters, while also including additional headers to be attached to every API call.
@@ -4013,6 +4071,7 @@
4013
4071
  networkClient: this.networkClient,
4014
4072
  retryStrategy: this.retryStrategy,
4015
4073
  dataSanitizer: this.dataSanitizer,
4074
+ timeoutConfig: this.timeoutConfig,
4016
4075
  });
4017
4076
  }
4018
4077
  /**
@@ -4031,6 +4090,7 @@
4031
4090
  networkClient: this.networkClient,
4032
4091
  retryStrategy: this.retryStrategy,
4033
4092
  dataSanitizer: this.dataSanitizer,
4093
+ timeoutConfig: this.timeoutConfig,
4034
4094
  });
4035
4095
  }
4036
4096
  /**
@@ -4049,6 +4109,7 @@
4049
4109
  networkClient: this.networkClient,
4050
4110
  retryStrategy: this.retryStrategy,
4051
4111
  dataSanitizer: this.dataSanitizer,
4112
+ timeoutConfig: this.timeoutConfig,
4052
4113
  });
4053
4114
  }
4054
4115
  /**
@@ -4067,6 +4128,7 @@
4067
4128
  networkClient: this.networkClient,
4068
4129
  retryStrategy: this.retryStrategy,
4069
4130
  dataSanitizer: this.dataSanitizer,
4131
+ timeoutConfig: this.timeoutConfig,
4070
4132
  });
4071
4133
  }
4072
4134
  /**
@@ -4085,6 +4147,7 @@
4085
4147
  networkClient: networkClient,
4086
4148
  retryStrategy: this.retryStrategy,
4087
4149
  dataSanitizer: this.dataSanitizer,
4150
+ timeoutConfig: this.timeoutConfig,
4088
4151
  });
4089
4152
  }
4090
4153
  /**
@@ -4103,6 +4166,7 @@
4103
4166
  networkClient: this.networkClient,
4104
4167
  retryStrategy: retryStrategy,
4105
4168
  dataSanitizer: this.dataSanitizer,
4169
+ timeoutConfig: this.timeoutConfig,
4106
4170
  });
4107
4171
  }
4108
4172
  /**
@@ -4122,6 +4186,26 @@
4122
4186
  networkClient: this.networkClient,
4123
4187
  retryStrategy: this.retryStrategy,
4124
4188
  dataSanitizer: dataSanitizer,
4189
+ timeoutConfig: this.timeoutConfig,
4190
+ });
4191
+ }
4192
+ /**
4193
+ * Generate a fresh network session by duplicating the existing configuration and network parameters, while also applying timeout config
4194
+ * @param {TimeoutConfig} timeoutConfig
4195
+ * @returns {NetworkSession}
4196
+ */
4197
+ withTimeoutConfig(timeoutConfig) {
4198
+ return new NetworkSession({
4199
+ additionalHeaders: this.additionalHeaders,
4200
+ baseUrls: this.baseUrls,
4201
+ interceptors: this.interceptors,
4202
+ agent: this.agent,
4203
+ agentOptions: this.agentOptions,
4204
+ proxyConfig: this.proxyConfig,
4205
+ networkClient: this.networkClient,
4206
+ retryStrategy: this.retryStrategy,
4207
+ dataSanitizer: this.dataSanitizer,
4208
+ timeoutConfig: timeoutConfig,
4125
4209
  });
4126
4210
  }
4127
4211
  }
@@ -48992,6 +49076,15 @@
48992
49076
  const canSharedLinkBeCreated = val.can_shared_link_be_created == void 0
48993
49077
  ? void 0
48994
49078
  : val.can_shared_link_be_created;
49079
+ if (!(val.can_public_shared_link_be_created == void 0) &&
49080
+ !sdIsBoolean(val.can_public_shared_link_be_created)) {
49081
+ throw new BoxSdkError({
49082
+ message: 'Expecting boolean for "can_public_shared_link_be_created" of type "HubV2025R0"',
49083
+ });
49084
+ }
49085
+ const canPublicSharedLinkBeCreated = val.can_public_shared_link_be_created == void 0
49086
+ ? void 0
49087
+ : val.can_public_shared_link_be_created;
48995
49088
  if (val.id == void 0) {
48996
49089
  throw new BoxSdkError({
48997
49090
  message: 'Expecting "id" of type "HubV2025R0" to be defined',
@@ -49021,6 +49114,7 @@
49021
49114
  isCollaborationRestrictedToEnterprise: isCollaborationRestrictedToEnterprise,
49022
49115
  canNonOwnersInvite: canNonOwnersInvite,
49023
49116
  canSharedLinkBeCreated: canSharedLinkBeCreated,
49117
+ canPublicSharedLinkBeCreated: canPublicSharedLinkBeCreated,
49024
49118
  id: id,
49025
49119
  type: type,
49026
49120
  };
@@ -49073,6 +49167,7 @@
49073
49167
  ['is_collaboration_restricted_to_enterprise']: val.isCollaborationRestrictedToEnterprise,
49074
49168
  ['can_non_owners_invite']: val.canNonOwnersInvite,
49075
49169
  ['can_shared_link_be_created']: val.canSharedLinkBeCreated,
49170
+ ['can_public_shared_link_be_created']: val.canPublicSharedLinkBeCreated,
49076
49171
  };
49077
49172
  }
49078
49173
 
@@ -51751,6 +51846,10 @@
51751
51846
  * Permanently deletes an archive.
51752
51847
  *
51753
51848
  * To learn more about the archive APIs, see the [Archive API Guide](https://developer.box.com/guides/archives).
51849
+ *
51850
+ * <Danger>
51851
+ * This endpoint is currently unavailable. Please contact support for assistance.
51852
+ * </Danger>
51754
51853
  * @param {string} archiveId The ID of the archive.
51755
51854
  Example: "982312"
51756
51855
  * @param {DeleteArchiveByIdV2025R0OptionalsInput} optionalsInput
@@ -52432,6 +52531,17 @@
52432
52531
  networkSession: this.networkSession.withProxy(config),
52433
52532
  });
52434
52533
  }
52534
+ /**
52535
+ * Create a new client with custom timeouts that will be used for every API call
52536
+ * @param {TimeoutConfig} config Timeout configuration.
52537
+ * @returns {BoxClient}
52538
+ */
52539
+ withTimeouts(config) {
52540
+ return new BoxClient({
52541
+ auth: this.auth,
52542
+ networkSession: this.networkSession.withTimeoutConfig(config),
52543
+ });
52544
+ }
52435
52545
  /**
52436
52546
  * Create a new client with a custom set of agent options that will be used for every API call
52437
52547
  * @param {AgentOptions} agentOptions Custom set of agent options that will be used for every API call