@unofficialbox/box-open-sdk 0.2.0 → 0.4.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 (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -1
  3. package/dist/cjs/auth.js +3 -3
  4. package/dist/cjs/buildinfo.js +2 -2
  5. package/dist/cjs/chunked_upload.js +108 -0
  6. package/dist/cjs/client.js +3 -0
  7. package/dist/cjs/index.js +3 -1
  8. package/dist/cjs/jwt.js +1 -1
  9. package/dist/cjs/managers/chunked_uploads.js +4 -4
  10. package/dist/cjs/managers/collaboration_allowlist_entries.js +6 -6
  11. package/dist/cjs/managers/collaboration_allowlist_exempt_targets.js +6 -6
  12. package/dist/cjs/managers/index.js +1 -0
  13. package/dist/cjs/managers/memberships.js +4 -4
  14. package/dist/cjs/managers/query.js +68 -0
  15. package/dist/cjs/models/schemas.js +1 -1
  16. package/dist/cjs/runtime.js +8 -3
  17. package/dist/cjs/tokens.js +5 -3
  18. package/dist/esm/auth.js +3 -3
  19. package/dist/esm/buildinfo.js +2 -2
  20. package/dist/esm/chunked_upload.js +104 -0
  21. package/dist/esm/client.js +3 -0
  22. package/dist/esm/index.js +1 -0
  23. package/dist/esm/jwt.js +1 -1
  24. package/dist/esm/managers/chunked_uploads.js +4 -4
  25. package/dist/esm/managers/collaboration_allowlist_entries.js +6 -6
  26. package/dist/esm/managers/collaboration_allowlist_exempt_targets.js +6 -6
  27. package/dist/esm/managers/index.js +1 -0
  28. package/dist/esm/managers/memberships.js +4 -4
  29. package/dist/esm/managers/query.js +31 -0
  30. package/dist/esm/models/schemas.js +1 -1
  31. package/dist/esm/runtime.js +8 -3
  32. package/dist/esm/tokens.js +5 -3
  33. package/dist/types/auth.d.ts +8 -0
  34. package/dist/types/buildinfo.d.ts +1 -1
  35. package/dist/types/chunked_upload.d.ts +21 -0
  36. package/dist/types/client.d.ts +2 -0
  37. package/dist/types/index.d.ts +1 -0
  38. package/dist/types/jwt.d.ts +4 -0
  39. package/dist/types/managers/archives.d.ts +2 -2
  40. package/dist/types/managers/avatars.d.ts +1 -1
  41. package/dist/types/managers/chunked_uploads.d.ts +3 -3
  42. package/dist/types/managers/classifications.d.ts +3 -3
  43. package/dist/types/managers/collaboration_allowlist_entries.d.ts +7 -7
  44. package/dist/types/managers/collaboration_allowlist_exempt_targets.d.ts +7 -7
  45. package/dist/types/managers/comments.d.ts +2 -2
  46. package/dist/types/managers/email_aliases.d.ts +1 -1
  47. package/dist/types/managers/file_classifications.d.ts +2 -2
  48. package/dist/types/managers/file_metadata.d.ts +4 -4
  49. package/dist/types/managers/file_versions.d.ts +2 -2
  50. package/dist/types/managers/file_watermarks.d.ts +1 -1
  51. package/dist/types/managers/files.d.ts +2 -2
  52. package/dist/types/managers/folder_classifications.d.ts +2 -2
  53. package/dist/types/managers/folder_locks.d.ts +1 -1
  54. package/dist/types/managers/folder_metadata.d.ts +4 -4
  55. package/dist/types/managers/folder_watermarks.d.ts +1 -1
  56. package/dist/types/managers/folders.d.ts +3 -3
  57. package/dist/types/managers/groups.d.ts +2 -2
  58. package/dist/types/managers/index.d.ts +1 -0
  59. package/dist/types/managers/integration_mappings.d.ts +2 -2
  60. package/dist/types/managers/invites.d.ts +1 -1
  61. package/dist/types/managers/legal_hold_policies.d.ts +2 -2
  62. package/dist/types/managers/legal_hold_policy_assignments.d.ts +1 -1
  63. package/dist/types/managers/memberships.d.ts +10 -10
  64. package/dist/types/managers/metadata_cascade_policies.d.ts +2 -2
  65. package/dist/types/managers/metadata_taxonomies.d.ts +6 -6
  66. package/dist/types/managers/metadata_templates.d.ts +4 -4
  67. package/dist/types/managers/query.d.ts +9 -0
  68. package/dist/types/managers/retention_policies.d.ts +2 -2
  69. package/dist/types/managers/retention_policy_assignments.d.ts +1 -1
  70. package/dist/types/managers/session_termination.d.ts +2 -2
  71. package/dist/types/managers/shared_links_files.d.ts +3 -3
  72. package/dist/types/managers/shared_links_folders.d.ts +3 -3
  73. package/dist/types/managers/shared_links_web_links.d.ts +3 -3
  74. package/dist/types/managers/shield_information_barrier_segment_members.d.ts +1 -1
  75. package/dist/types/managers/shield_information_barrier_segment_restrictions.d.ts +1 -1
  76. package/dist/types/managers/shield_information_barrier_segments.d.ts +2 -2
  77. package/dist/types/managers/shield_information_barriers.d.ts +2 -2
  78. package/dist/types/managers/skills.d.ts +3 -3
  79. package/dist/types/managers/storage_policy_assignments.d.ts +2 -2
  80. package/dist/types/managers/task_assignments.d.ts +2 -2
  81. package/dist/types/managers/tasks.d.ts +2 -2
  82. package/dist/types/managers/terms_of_service_user_statuses.d.ts +2 -2
  83. package/dist/types/managers/terms_of_services.d.ts +2 -2
  84. package/dist/types/managers/transfer.d.ts +1 -1
  85. package/dist/types/managers/trashed_files.d.ts +1 -1
  86. package/dist/types/managers/trashed_folders.d.ts +1 -1
  87. package/dist/types/managers/trashed_web_links.d.ts +1 -1
  88. package/dist/types/managers/uploads.d.ts +2 -2
  89. package/dist/types/managers/user_collaborations.d.ts +2 -2
  90. package/dist/types/managers/users.d.ts +2 -2
  91. package/dist/types/managers/web_links.d.ts +2 -2
  92. package/dist/types/managers/webhooks.d.ts +2 -2
  93. package/dist/types/managers/workflows.d.ts +1 -1
  94. package/dist/types/models/schemas.d.ts +204 -141
  95. package/dist/types/runtime.d.ts +10 -0
  96. package/dist/types/tokens.d.ts +4 -2
  97. package/docs/README.md +1 -0
  98. package/docs/managers/archives.md +2 -2
  99. package/docs/managers/avatars.md +1 -1
  100. package/docs/managers/chunked_uploads.md +7 -7
  101. package/docs/managers/classifications.md +3 -3
  102. package/docs/managers/collaboration_allowlist_entries.md +10 -10
  103. package/docs/managers/collaboration_allowlist_exempt_targets.md +10 -10
  104. package/docs/managers/comments.md +2 -2
  105. package/docs/managers/email_aliases.md +1 -1
  106. package/docs/managers/file_classifications.md +2 -2
  107. package/docs/managers/file_metadata.md +5 -5
  108. package/docs/managers/file_versions.md +2 -2
  109. package/docs/managers/file_watermarks.md +1 -1
  110. package/docs/managers/files.md +2 -2
  111. package/docs/managers/folder_classifications.md +2 -2
  112. package/docs/managers/folder_locks.md +1 -1
  113. package/docs/managers/folder_metadata.md +5 -5
  114. package/docs/managers/folder_watermarks.md +1 -1
  115. package/docs/managers/folders.md +3 -3
  116. package/docs/managers/groups.md +2 -2
  117. package/docs/managers/integration_mappings.md +2 -2
  118. package/docs/managers/invites.md +1 -1
  119. package/docs/managers/legal_hold_policies.md +2 -2
  120. package/docs/managers/legal_hold_policy_assignments.md +1 -1
  121. package/docs/managers/memberships.md +10 -10
  122. package/docs/managers/metadata_cascade_policies.md +2 -2
  123. package/docs/managers/metadata_taxonomies.md +6 -6
  124. package/docs/managers/metadata_templates.md +5 -5
  125. package/docs/managers/query.md +33 -0
  126. package/docs/managers/retention_policies.md +2 -2
  127. package/docs/managers/retention_policy_assignments.md +1 -1
  128. package/docs/managers/session_termination.md +2 -2
  129. package/docs/managers/shared_links_files.md +3 -3
  130. package/docs/managers/shared_links_folders.md +3 -3
  131. package/docs/managers/shared_links_web_links.md +3 -3
  132. package/docs/managers/shield_information_barrier_segment_members.md +1 -1
  133. package/docs/managers/shield_information_barrier_segment_restrictions.md +1 -1
  134. package/docs/managers/shield_information_barrier_segments.md +2 -2
  135. package/docs/managers/shield_information_barriers.md +2 -2
  136. package/docs/managers/skills.md +3 -3
  137. package/docs/managers/storage_policy_assignments.md +2 -2
  138. package/docs/managers/task_assignments.md +2 -2
  139. package/docs/managers/tasks.md +2 -2
  140. package/docs/managers/terms_of_service_user_statuses.md +2 -2
  141. package/docs/managers/terms_of_services.md +2 -2
  142. package/docs/managers/transfer.md +1 -1
  143. package/docs/managers/trashed_files.md +1 -1
  144. package/docs/managers/trashed_folders.md +1 -1
  145. package/docs/managers/trashed_web_links.md +1 -1
  146. package/docs/managers/uploads.md +2 -2
  147. package/docs/managers/user_collaborations.md +2 -2
  148. package/docs/managers/users.md +2 -2
  149. package/docs/managers/web_links.md +2 -2
  150. package/docs/managers/webhooks.md +2 -2
  151. package/docs/managers/workflows.md +1 -1
  152. package/package.json +3 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kyle @ Unofficial Box
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -3,9 +3,11 @@
3
3
 
4
4
  # @unofficialbox/box-open-sdk
5
5
 
6
+ [![release](https://img.shields.io/github/v/release/unofficialbox/box-open-ts-sdk?sort=semver)](https://github.com/unofficialbox/box-open-ts-sdk/releases/latest)
6
7
  [![npm](https://img.shields.io/npm/v/@unofficialbox/box-open-sdk.svg)](https://www.npmjs.com/package/@unofficialbox/box-open-sdk)
8
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
9
 
8
- A **community, unofficial** Box API client for TypeScript — fully typed models
10
+ An **open source, community-built** Box API client for TypeScript — fully typed models
9
11
  for the whole Box surface, one manager per API area behind a single `Client`,
10
12
  and a `fetch`-based runtime with retry, backoff, and token refresh. Ships as a
11
13
  **dual ESM/CJS** package with bundled `.d.ts` declarations; no runtime
package/dist/cjs/auth.js CHANGED
@@ -43,7 +43,7 @@ function clientCredentials(config) {
43
43
  client_secret: config.clientSecret,
44
44
  box_subject_type: subject.type,
45
45
  box_subject_id: subject.id,
46
- }));
46
+ }, undefined, config.fetch));
47
47
  }
48
48
  /**
49
49
  * Build the URL to redirect a user to so they can grant access. `state` is
@@ -72,7 +72,7 @@ function refreshTokenExchange(config, tokenUrl, initialRefresh) {
72
72
  refresh_token: refreshToken,
73
73
  client_id: config.clientId,
74
74
  client_secret: config.clientSecret,
75
- });
75
+ }, undefined, config.fetch);
76
76
  if (token.refreshToken) {
77
77
  refreshToken = token.refreshToken;
78
78
  config.onRefresh?.(token.refreshToken);
@@ -101,7 +101,7 @@ async function exchangeCode(config, code, redirectUri, signal) {
101
101
  client_id: config.clientId,
102
102
  client_secret: config.clientSecret,
103
103
  redirect_uri: redirectUri,
104
- }, signal);
104
+ }, signal, config.fetch);
105
105
  if (!token.refreshToken) {
106
106
  throw new errors_js_1.BoxApiError('authorization-code exchange returned no refresh_token');
107
107
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
- // Code generated by box-gantry 0.1.0 (spec ee7d55aedefe2fa0). DO NOT EDIT.
2
+ // Code generated by box-gantry 0.1.0 (spec 3fb3510fe12f2f80). DO NOT EDIT.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.TARGET = exports.SPEC_FINGERPRINT = exports.ENGINE = void 0;
5
5
  /** The box-gantry engine version that generated this SDK. */
6
6
  exports.ENGINE = "0.1.0";
7
7
  /** Fingerprint of the input spec set. */
8
- exports.SPEC_FINGERPRINT = "ee7d55aedefe2fa0";
8
+ exports.SPEC_FINGERPRINT = "3fb3510fe12f2f80";
9
9
  /** The target language key (FR-4). */
10
10
  exports.TARGET = "typescript";
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // Code generated by box-gantry. DO NOT EDIT.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ChunkedUpload = void 0;
5
+ /**
6
+ * ChunkedUpload orchestrates a Box chunked (multipart) upload over a Client: it
7
+ * creates an upload session, uploads the content's parts with bounded
8
+ * concurrency, and commits — for a new file (upload) or a new version of an
9
+ * existing file (uploadVersion). Box requires chunked upload for files at or
10
+ * above its minimum session size; smaller files use the single-shot endpoints.
11
+ */
12
+ class ChunkedUpload {
13
+ client;
14
+ /** Bounds parts in flight, capping peak memory. */
15
+ maxConcurrent = 4;
16
+ constructor(client) {
17
+ this.client = client;
18
+ }
19
+ /** Upload content as a new file named fileName into folderId. */
20
+ async upload(content, fileName, folderId) {
21
+ const session = await this.client.chunkedUploads.createFileUploadSession({
22
+ folder_id: folderId,
23
+ file_size: content.length,
24
+ file_name: fileName,
25
+ });
26
+ return this.finish(session, content);
27
+ }
28
+ /** Upload content as a new version of the existing file fileId. */
29
+ async uploadVersion(content, fileName, fileId) {
30
+ const session = await this.client.chunkedUploads.createFileVersionUploadSession(fileId, {
31
+ file_size: content.length,
32
+ file_name: fileName,
33
+ });
34
+ return this.finish(session, content);
35
+ }
36
+ async finish(session, content) {
37
+ if (session.id === undefined) {
38
+ throw new Error('gantry: upload session returned no id');
39
+ }
40
+ if (session.part_size === undefined || session.part_size <= 0) {
41
+ throw new Error('gantry: upload session returned a non-positive part_size');
42
+ }
43
+ const id = session.id;
44
+ const partSize = session.part_size;
45
+ const total = content.length;
46
+ const offsets = [];
47
+ for (let off = 0; off < total; off += partSize) {
48
+ offsets.push(off);
49
+ }
50
+ const parts = new Array(offsets.length);
51
+ // A bounded worker pool: each of maxConcurrent workers claims the next
52
+ // offset (the `next++` read is atomic between awaits on a single thread).
53
+ // Once any part fails, `failed` stops the others from starting new parts,
54
+ // so a failure early in a large upload doesn't push every remaining part.
55
+ let next = 0;
56
+ let failed = false;
57
+ const worker = async () => {
58
+ for (;;) {
59
+ if (failed) {
60
+ return;
61
+ }
62
+ const i = next++;
63
+ if (i >= offsets.length) {
64
+ return;
65
+ }
66
+ const start = offsets[i];
67
+ const end = Math.min(start + partSize, total);
68
+ try {
69
+ parts[i] = await this.uploadPart(id, content, start, end, total);
70
+ }
71
+ catch (err) {
72
+ failed = true;
73
+ throw err;
74
+ }
75
+ }
76
+ };
77
+ const workerCount = Math.min(this.maxConcurrent, offsets.length);
78
+ await Promise.all(Array.from({ length: workerCount }, () => worker()));
79
+ const digest = 'sha=' + (await sha1Base64(content));
80
+ return this.client.chunkedUploads.commitFileUploadSession(id, digest, { parts });
81
+ }
82
+ async uploadPart(id, content, start, end, total) {
83
+ const slice = content.subarray(start, end);
84
+ const digest = 'sha=' + (await sha1Base64(slice));
85
+ const contentRange = `bytes ${start}-${end - 1}/${total}`;
86
+ // The `as BlobPart` cast bridges the `Uint8Array<ArrayBufferLike>` vs
87
+ // `BufferSource` (ArrayBuffer-only) generic gap in the DOM lib, exactly as
88
+ // the runtime casts its `fetch` body; a plain `Uint8Array` is a valid part.
89
+ const uploaded = await this.client.chunkedUploads.updateFileUploadSession(id, digest, contentRange, new Blob([slice]));
90
+ if (uploaded.part === undefined) {
91
+ throw new Error('gantry: upload part returned no part');
92
+ }
93
+ return uploaded.part;
94
+ }
95
+ }
96
+ exports.ChunkedUpload = ChunkedUpload;
97
+ /** Base64 of the SHA-1 of data — the Box `Digest: sha=…` header value. Uses Web
98
+ * Crypto (browser and Node 18+), so it adds no dependency. */
99
+ async function sha1Base64(data) {
100
+ // `as BufferSource` bridges the `Uint8Array<ArrayBufferLike>` vs ArrayBuffer-only
101
+ // generic gap in the DOM lib (as the runtime does for its `fetch` body).
102
+ const digest = new Uint8Array(await crypto.subtle.digest('SHA-1', data));
103
+ let binary = '';
104
+ for (const byte of digest) {
105
+ binary += String.fromCharCode(byte);
106
+ }
107
+ return btoa(binary);
108
+ }
@@ -52,6 +52,7 @@ const metadata_cascade_policies_js_1 = require("./managers/metadata_cascade_poli
52
52
  const metadata_taxonomies_js_1 = require("./managers/metadata_taxonomies.js");
53
53
  const metadata_templates_js_1 = require("./managers/metadata_templates.js");
54
54
  const notes_js_1 = require("./managers/notes.js");
55
+ const query_js_1 = require("./managers/query.js");
55
56
  const recent_items_js_1 = require("./managers/recent_items.js");
56
57
  const retention_policies_js_1 = require("./managers/retention_policies.js");
57
58
  const retention_policy_assignments_js_1 = require("./managers/retention_policy_assignments.js");
@@ -139,6 +140,7 @@ class Client {
139
140
  metadataTaxonomies;
140
141
  metadataTemplates;
141
142
  notes;
143
+ query;
142
144
  recentItems;
143
145
  retentionPolicies;
144
146
  retentionPolicyAssignments;
@@ -227,6 +229,7 @@ class Client {
227
229
  this.metadataTaxonomies = new metadata_taxonomies_js_1.MetadataTaxonomiesManager(session);
228
230
  this.metadataTemplates = new metadata_templates_js_1.MetadataTemplatesManager(session);
229
231
  this.notes = new notes_js_1.NotesManager(session);
232
+ this.query = new query_js_1.QueryManager(session);
230
233
  this.recentItems = new recent_items_js_1.RecentItemsManager(session);
231
234
  this.retentionPolicies = new retention_policies_js_1.RetentionPoliciesManager(session);
232
235
  this.retentionPolicyAssignments = new retention_policy_assignments_js_1.RetentionPolicyAssignmentsManager(session);
package/dist/cjs/index.js CHANGED
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.buildinfo = exports.auth = exports.runtime = exports.managers = exports.models = exports.Client = void 0;
37
+ exports.ChunkedUpload = exports.buildinfo = exports.auth = exports.runtime = exports.managers = exports.models = exports.Client = void 0;
38
38
  var client_js_1 = require("./client.js");
39
39
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
40
40
  exports.models = __importStar(require("./models/index.js"));
@@ -42,3 +42,5 @@ exports.managers = __importStar(require("./managers/index.js"));
42
42
  exports.runtime = __importStar(require("./runtime.js"));
43
43
  exports.auth = __importStar(require("./auth.js"));
44
44
  exports.buildinfo = __importStar(require("./buildinfo.js"));
45
+ var chunked_upload_js_1 = require("./chunked_upload.js");
46
+ Object.defineProperty(exports, "ChunkedUpload", { enumerable: true, get: function () { return chunked_upload_js_1.ChunkedUpload; } });
package/dist/cjs/jwt.js CHANGED
@@ -79,7 +79,7 @@ async function jwtAuth(config) {
79
79
  assertion,
80
80
  client_id: config.clientId,
81
81
  client_secret: config.clientSecret,
82
- });
82
+ }, undefined, config.fetch);
83
83
  });
84
84
  }
85
85
  /**
@@ -43,7 +43,7 @@ class ChunkedUploadsManager {
43
43
  constructor(session) {
44
44
  this.session = session;
45
45
  }
46
- async createFileUploadSessions(body) {
46
+ async createFileUploadSession(body) {
47
47
  let url = this.session.baseUrl("upload");
48
48
  url += "/files";
49
49
  url += "/upload_sessions";
@@ -54,7 +54,7 @@ class ChunkedUploadsManager {
54
54
  const data = runtime.responseBytes(resp);
55
55
  return JSON.parse(new TextDecoder().decode(data));
56
56
  }
57
- async createFileByIdUploadSessions(fileId, body) {
57
+ async createFileVersionUploadSession(fileId, body) {
58
58
  let url = this.session.baseUrl("upload");
59
59
  url += "/files";
60
60
  url += '/' + (0, internal_js_1.pathEscape)(fileId);
@@ -84,8 +84,8 @@ class ChunkedUploadsManager {
84
84
  let req = this.session.newRequest("PUT", url);
85
85
  req = runtime.withHeader(req, "digest", digest);
86
86
  req = runtime.withHeader(req, "content-range", contentRange);
87
- void body;
88
- req = runtime.withStreamBody(req, runtime.Stream.empty(), 'application/octet-stream');
87
+ const fileBytes = new Uint8Array(await body.arrayBuffer());
88
+ req = runtime.withStreamBody(req, new runtime.Stream(fileBytes), 'application/octet-stream');
89
89
  const resp = await this.session.fetch(req);
90
90
  const data = runtime.responseBytes(resp);
91
91
  return JSON.parse(new TextDecoder().decode(data));
@@ -44,10 +44,10 @@ class CollaborationAllowlistEntriesManager {
44
44
  this.session = session;
45
45
  }
46
46
  /** Iterate every `models.schemas.CollaborationAllowlistEntry` across pages, threading the marker cursor. */
47
- async *listCollaborationWhitelistEntries(opts) {
47
+ async *list(opts) {
48
48
  const options = { ...opts };
49
49
  for (;;) {
50
- const page = await this.listCollaborationWhitelistEntriesPage(options);
50
+ const page = await this.listPage(options);
51
51
  const items = page.entries ?? [];
52
52
  for (const item of items) {
53
53
  yield item;
@@ -59,7 +59,7 @@ class CollaborationAllowlistEntriesManager {
59
59
  options.marker = cursor;
60
60
  }
61
61
  }
62
- async listCollaborationWhitelistEntriesPage(opts) {
62
+ async listPage(opts) {
63
63
  let url = this.session.baseUrl("api");
64
64
  url += "/collaboration_whitelist_entries";
65
65
  let req = this.session.newRequest("GET", url);
@@ -74,7 +74,7 @@ class CollaborationAllowlistEntriesManager {
74
74
  const data = runtime.responseBytes(resp);
75
75
  return JSON.parse(new TextDecoder().decode(data));
76
76
  }
77
- async createCollaborationWhitelistEntries(body) {
77
+ async create(body) {
78
78
  let url = this.session.baseUrl("api");
79
79
  url += "/collaboration_whitelist_entries";
80
80
  let req = this.session.newRequest("POST", url);
@@ -84,7 +84,7 @@ class CollaborationAllowlistEntriesManager {
84
84
  const data = runtime.responseBytes(resp);
85
85
  return JSON.parse(new TextDecoder().decode(data));
86
86
  }
87
- async getCollaborationWhitelistEntry(collaborationWhitelistEntryId) {
87
+ async get(collaborationWhitelistEntryId) {
88
88
  let url = this.session.baseUrl("api");
89
89
  url += "/collaboration_whitelist_entries";
90
90
  url += '/' + (0, internal_js_1.pathEscape)(collaborationWhitelistEntryId);
@@ -93,7 +93,7 @@ class CollaborationAllowlistEntriesManager {
93
93
  const data = runtime.responseBytes(resp);
94
94
  return JSON.parse(new TextDecoder().decode(data));
95
95
  }
96
- async deleteCollaborationWhitelistEntry(collaborationWhitelistEntryId) {
96
+ async delete_(collaborationWhitelistEntryId) {
97
97
  let url = this.session.baseUrl("api");
98
98
  url += "/collaboration_whitelist_entries";
99
99
  url += '/' + (0, internal_js_1.pathEscape)(collaborationWhitelistEntryId);
@@ -44,10 +44,10 @@ class CollaborationAllowlistExemptTargetsManager {
44
44
  this.session = session;
45
45
  }
46
46
  /** Iterate every `models.schemas.CollaborationAllowlistExemptTarget` across pages, threading the marker cursor. */
47
- async *listCollaborationWhitelistExemptTargets(opts) {
47
+ async *list(opts) {
48
48
  const options = { ...opts };
49
49
  for (;;) {
50
- const page = await this.listCollaborationWhitelistExemptTargetsPage(options);
50
+ const page = await this.listPage(options);
51
51
  const items = page.entries ?? [];
52
52
  for (const item of items) {
53
53
  yield item;
@@ -59,7 +59,7 @@ class CollaborationAllowlistExemptTargetsManager {
59
59
  options.marker = cursor;
60
60
  }
61
61
  }
62
- async listCollaborationWhitelistExemptTargetsPage(opts) {
62
+ async listPage(opts) {
63
63
  let url = this.session.baseUrl("api");
64
64
  url += "/collaboration_whitelist_exempt_targets";
65
65
  let req = this.session.newRequest("GET", url);
@@ -74,7 +74,7 @@ class CollaborationAllowlistExemptTargetsManager {
74
74
  const data = runtime.responseBytes(resp);
75
75
  return JSON.parse(new TextDecoder().decode(data));
76
76
  }
77
- async createCollaborationWhitelistExemptTargets(body) {
77
+ async create(body) {
78
78
  let url = this.session.baseUrl("api");
79
79
  url += "/collaboration_whitelist_exempt_targets";
80
80
  let req = this.session.newRequest("POST", url);
@@ -84,7 +84,7 @@ class CollaborationAllowlistExemptTargetsManager {
84
84
  const data = runtime.responseBytes(resp);
85
85
  return JSON.parse(new TextDecoder().decode(data));
86
86
  }
87
- async getCollaborationWhitelistExemptTarget(collaborationWhitelistExemptTargetId) {
87
+ async get(collaborationWhitelistExemptTargetId) {
88
88
  let url = this.session.baseUrl("api");
89
89
  url += "/collaboration_whitelist_exempt_targets";
90
90
  url += '/' + (0, internal_js_1.pathEscape)(collaborationWhitelistExemptTargetId);
@@ -93,7 +93,7 @@ class CollaborationAllowlistExemptTargetsManager {
93
93
  const data = runtime.responseBytes(resp);
94
94
  return JSON.parse(new TextDecoder().decode(data));
95
95
  }
96
- async deleteCollaborationWhitelistExemptTarget(collaborationWhitelistExemptTargetId) {
96
+ async delete_(collaborationWhitelistExemptTargetId) {
97
97
  let url = this.session.baseUrl("api");
98
98
  url += "/collaboration_whitelist_exempt_targets";
99
99
  url += '/' + (0, internal_js_1.pathEscape)(collaborationWhitelistExemptTargetId);
@@ -64,6 +64,7 @@ __exportStar(require("./metadata_cascade_policies.js"), exports);
64
64
  __exportStar(require("./metadata_taxonomies.js"), exports);
65
65
  __exportStar(require("./metadata_templates.js"), exports);
66
66
  __exportStar(require("./notes.js"), exports);
67
+ __exportStar(require("./query.js"), exports);
67
68
  __exportStar(require("./recent_items.js"), exports);
68
69
  __exportStar(require("./retention_policies.js"), exports);
69
70
  __exportStar(require("./retention_policy_assignments.js"), exports);
@@ -107,7 +107,7 @@ class MembershipsManager {
107
107
  const data = runtime.responseBytes(resp);
108
108
  return JSON.parse(new TextDecoder().decode(data));
109
109
  }
110
- async createGroup(body, opts) {
110
+ async createGroupMembership(body, opts) {
111
111
  let url = this.session.baseUrl("api");
112
112
  url += "/group_memberships";
113
113
  let req = this.session.newRequest("POST", url);
@@ -121,7 +121,7 @@ class MembershipsManager {
121
121
  const data = runtime.responseBytes(resp);
122
122
  return JSON.parse(new TextDecoder().decode(data));
123
123
  }
124
- async getGroup(groupMembershipId, opts) {
124
+ async getGroupMembership(groupMembershipId, opts) {
125
125
  let url = this.session.baseUrl("api");
126
126
  url += "/group_memberships";
127
127
  url += '/' + (0, internal_js_1.pathEscape)(groupMembershipId);
@@ -134,7 +134,7 @@ class MembershipsManager {
134
134
  const data = runtime.responseBytes(resp);
135
135
  return JSON.parse(new TextDecoder().decode(data));
136
136
  }
137
- async updateGroup(groupMembershipId, body, opts) {
137
+ async updateGroupMembership(groupMembershipId, body, opts) {
138
138
  let url = this.session.baseUrl("api");
139
139
  url += "/group_memberships";
140
140
  url += '/' + (0, internal_js_1.pathEscape)(groupMembershipId);
@@ -149,7 +149,7 @@ class MembershipsManager {
149
149
  const data = runtime.responseBytes(resp);
150
150
  return JSON.parse(new TextDecoder().decode(data));
151
151
  }
152
- async deleteGroup(groupMembershipId) {
152
+ async deleteGroupMembership(groupMembershipId) {
153
153
  let url = this.session.baseUrl("api");
154
154
  url += "/group_memberships";
155
155
  url += '/' + (0, internal_js_1.pathEscape)(groupMembershipId);
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // Code generated by box-gantry. DO NOT EDIT.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.QueryManager = void 0;
38
+ const runtime = __importStar(require("../runtime.js"));
39
+ /** Operations for the "query" API area. */
40
+ class QueryManager {
41
+ session;
42
+ constructor(session) {
43
+ this.session = session;
44
+ }
45
+ async query(body) {
46
+ let url = this.session.baseUrl("api");
47
+ url += "/query";
48
+ let req = this.session.newRequest("POST", url);
49
+ req = runtime.withHeader(req, "box-version", "2026.0");
50
+ const payload = new TextEncoder().encode(JSON.stringify(body));
51
+ req = runtime.withJsonBody(req, payload);
52
+ const resp = await this.session.fetch(req);
53
+ const data = runtime.responseBytes(resp);
54
+ return JSON.parse(new TextDecoder().decode(data));
55
+ }
56
+ async queryInsights(body) {
57
+ let url = this.session.baseUrl("api");
58
+ url += "/query_insights";
59
+ let req = this.session.newRequest("POST", url);
60
+ req = runtime.withHeader(req, "box-version", "2026.0");
61
+ const payload = new TextEncoder().encode(JSON.stringify(body));
62
+ req = runtime.withJsonBody(req, payload);
63
+ const resp = await this.session.fetch(req);
64
+ const data = runtime.responseBytes(resp);
65
+ return JSON.parse(new TextDecoder().decode(data));
66
+ }
67
+ }
68
+ exports.QueryManager = QueryManager;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- // Code generated by box-gantry 0.1.0 (spec ee7d55aedefe2fa0) for Box API 2024.0. DO NOT EDIT.
2
+ // Code generated by box-gantry 0.1.0 (spec 3fb3510fe12f2f80) for Box API 2024.0. DO NOT EDIT.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -86,6 +86,8 @@ class Client {
86
86
  auth;
87
87
  baseUrls;
88
88
  maxRetries;
89
+ fetchImpl;
90
+ defaultHeaders;
89
91
  constructor(auth, options = {}) {
90
92
  this.auth = auth;
91
93
  const maxRetries = options.maxRetries ?? 5;
@@ -94,6 +96,8 @@ class Client {
94
96
  }
95
97
  this.maxRetries = maxRetries;
96
98
  this.baseUrls = { ...DEFAULT_BASE_URLS, ...(options.baseUrls ?? {}) };
99
+ this.fetchImpl = options.fetch ?? fetch;
100
+ this.defaultHeaders = { ...(options.headers ?? {}) };
97
101
  }
98
102
  /** The configured base URL for a D-106 class, without a trailing slash. */
99
103
  baseUrl(name) {
@@ -124,13 +128,14 @@ class Client {
124
128
  let refreshed = false;
125
129
  let lastError;
126
130
  for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
127
- const headers = new Headers(request.headers);
131
+ const headers = new Headers(this.defaultHeaders);
132
+ request.headers.forEach((value, name) => headers.set(name, value));
128
133
  headers.set('Authorization', `Bearer ${token}`);
129
134
  // `httpResponse` is the platform `Response` (via inference — the name is
130
135
  // shadowed by this module's `Response` class, so it is never annotated).
131
136
  let httpResponse;
132
137
  try {
133
- httpResponse = await fetch(url, {
138
+ httpResponse = await this.fetchImpl(url, {
134
139
  method: request.method,
135
140
  headers,
136
141
  // A `Uint8Array` is a valid `BodyInit` at runtime; the cast bridges
@@ -154,7 +159,7 @@ class Client {
154
159
  const response = new Response(httpResponse.status, httpResponse.headers, bodyBytes);
155
160
  // A single force-refresh on 401: re-acquire past the token cache so the
156
161
  // retry doesn't just resend the same rejected token.
157
- if (response.status === 401 && !refreshed) {
162
+ if (response.status === 401 && !refreshed && attempt < this.maxRetries) {
158
163
  refreshed = true;
159
164
  token = await this.auth.forceRefresh(token);
160
165
  continue;
@@ -72,9 +72,11 @@ exports.CachedToken = CachedToken;
72
72
  * token acquisition never escapes the runtime's error contract. The optional
73
73
  * `signal` cancels an explicit caller-initiated exchange (`exchangeCode`); the
74
74
  * cached flows do not thread one, so a shared refresh is never bound to a single
75
- * request's cancellation.
75
+ * request's cancellation. `fetchImpl` defaults to the global `fetch`; a caller
76
+ * building an `Auth` with a custom transport (matching the runtime `Client`'s
77
+ * own `fetch` override) passes it through so auth traffic is observable too.
76
78
  */
77
- async function postTokenForm(tokenUrl, form, signal) {
79
+ async function postTokenForm(tokenUrl, form, signal, fetchImpl = fetch) {
78
80
  // An internal deadline independent of the caller's signal, combined with it
79
81
  // when present. It also covers the body read, since the signal aborts an
80
82
  // in-progress `fetch` (including body streaming). `AbortSignal.timeout` owns
@@ -84,7 +86,7 @@ async function postTokenForm(tokenUrl, form, signal) {
84
86
  let response;
85
87
  let text;
86
88
  try {
87
- response = await fetch(tokenUrl, {
89
+ response = await fetchImpl(tokenUrl, {
88
90
  method: 'POST',
89
91
  headers: {
90
92
  'Content-Type': 'application/x-www-form-urlencoded',
package/dist/esm/auth.js CHANGED
@@ -36,7 +36,7 @@ export function clientCredentials(config) {
36
36
  client_secret: config.clientSecret,
37
37
  box_subject_type: subject.type,
38
38
  box_subject_id: subject.id,
39
- }));
39
+ }, undefined, config.fetch));
40
40
  }
41
41
  /**
42
42
  * Build the URL to redirect a user to so they can grant access. `state` is
@@ -65,7 +65,7 @@ function refreshTokenExchange(config, tokenUrl, initialRefresh) {
65
65
  refresh_token: refreshToken,
66
66
  client_id: config.clientId,
67
67
  client_secret: config.clientSecret,
68
- });
68
+ }, undefined, config.fetch);
69
69
  if (token.refreshToken) {
70
70
  refreshToken = token.refreshToken;
71
71
  config.onRefresh?.(token.refreshToken);
@@ -94,7 +94,7 @@ export async function exchangeCode(config, code, redirectUri, signal) {
94
94
  client_id: config.clientId,
95
95
  client_secret: config.clientSecret,
96
96
  redirect_uri: redirectUri,
97
- }, signal);
97
+ }, signal, config.fetch);
98
98
  if (!token.refreshToken) {
99
99
  throw new BoxApiError('authorization-code exchange returned no refresh_token');
100
100
  }
@@ -1,7 +1,7 @@
1
- // Code generated by box-gantry 0.1.0 (spec ee7d55aedefe2fa0). DO NOT EDIT.
1
+ // Code generated by box-gantry 0.1.0 (spec 3fb3510fe12f2f80). DO NOT EDIT.
2
2
  /** The box-gantry engine version that generated this SDK. */
3
3
  export const ENGINE = "0.1.0";
4
4
  /** Fingerprint of the input spec set. */
5
- export const SPEC_FINGERPRINT = "ee7d55aedefe2fa0";
5
+ export const SPEC_FINGERPRINT = "3fb3510fe12f2f80";
6
6
  /** The target language key (FR-4). */
7
7
  export const TARGET = "typescript";