@unofficialbox/box-open-sdk 0.1.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.
- package/README.md +13 -0
- package/dist/cjs/auth.js +112 -0
- package/dist/cjs/buildinfo.js +10 -0
- package/dist/cjs/client.js +268 -0
- package/dist/cjs/errors.js +20 -0
- package/dist/cjs/index.js +43 -0
- package/dist/cjs/internal.js +37 -0
- package/dist/cjs/jwt.js +122 -0
- package/dist/cjs/managers/ai.js +106 -0
- package/dist/cjs/managers/ai_studio.js +131 -0
- package/dist/cjs/managers/app_item_associations.js +119 -0
- package/dist/cjs/managers/archives.js +110 -0
- package/dist/cjs/managers/authorization.js +149 -0
- package/dist/cjs/managers/automate_workflows.js +91 -0
- package/dist/cjs/managers/avatars.js +76 -0
- package/dist/cjs/managers/chunked_uploads.js +156 -0
- package/dist/cjs/managers/classifications.js +94 -0
- package/dist/cjs/managers/collaboration_allowlist_entries.js +104 -0
- package/dist/cjs/managers/collaboration_allowlist_exempt_targets.js +104 -0
- package/dist/cjs/managers/collections.js +124 -0
- package/dist/cjs/managers/comments.js +131 -0
- package/dist/cjs/managers/device_pinners.js +99 -0
- package/dist/cjs/managers/docgen.js +133 -0
- package/dist/cjs/managers/docgen_template.js +178 -0
- package/dist/cjs/managers/downloads.js +69 -0
- package/dist/cjs/managers/email_aliases.js +78 -0
- package/dist/cjs/managers/enterprise_configurations.js +58 -0
- package/dist/cjs/managers/events.js +82 -0
- package/dist/cjs/managers/external_users.js +58 -0
- package/dist/cjs/managers/file_classifications.js +97 -0
- package/dist/cjs/managers/file_metadata.js +115 -0
- package/dist/cjs/managers/file_requests.js +90 -0
- package/dist/cjs/managers/file_version_legal_holds.js +88 -0
- package/dist/cjs/managers/file_version_retentions.js +105 -0
- package/dist/cjs/managers/file_versions.js +140 -0
- package/dist/cjs/managers/file_watermarks.js +77 -0
- package/dist/cjs/managers/files.js +138 -0
- package/dist/cjs/managers/folder_classifications.js +97 -0
- package/dist/cjs/managers/folder_locks.js +73 -0
- package/dist/cjs/managers/folder_metadata.js +111 -0
- package/dist/cjs/managers/folder_watermarks.js +77 -0
- package/dist/cjs/managers/folders.js +191 -0
- package/dist/cjs/managers/groups.js +132 -0
- package/dist/cjs/managers/hub_collaborations.js +121 -0
- package/dist/cjs/managers/hub_document.js +113 -0
- package/dist/cjs/managers/hub_items.js +96 -0
- package/dist/cjs/managers/hubs.js +186 -0
- package/dist/cjs/managers/index.js +102 -0
- package/dist/cjs/managers/integration_mappings.js +178 -0
- package/dist/cjs/managers/invites.js +74 -0
- package/dist/cjs/managers/legal_hold_policies.js +121 -0
- package/dist/cjs/managers/legal_hold_policy_assignments.js +186 -0
- package/dist/cjs/managers/list_collaborations.js +185 -0
- package/dist/cjs/managers/memberships.js +160 -0
- package/dist/cjs/managers/metadata_cascade_policies.js +118 -0
- package/dist/cjs/managers/metadata_taxonomies.js +322 -0
- package/dist/cjs/managers/metadata_templates.js +196 -0
- package/dist/cjs/managers/notes.js +58 -0
- package/dist/cjs/managers/recent_items.js +80 -0
- package/dist/cjs/managers/retention_policies.js +131 -0
- package/dist/cjs/managers/retention_policy_assignments.js +182 -0
- package/dist/cjs/managers/search.js +130 -0
- package/dist/cjs/managers/session_termination.js +68 -0
- package/dist/cjs/managers/shared_links_app_items.js +55 -0
- package/dist/cjs/managers/shared_links_files.js +109 -0
- package/dist/cjs/managers/shared_links_folders.js +109 -0
- package/dist/cjs/managers/shared_links_web_links.js +109 -0
- package/dist/cjs/managers/shield_information_barrier_reports.js +98 -0
- package/dist/cjs/managers/shield_information_barrier_segment_members.js +105 -0
- package/dist/cjs/managers/shield_information_barrier_segment_restrictions.js +105 -0
- package/dist/cjs/managers/shield_information_barrier_segments.js +116 -0
- package/dist/cjs/managers/shield_information_barriers.js +108 -0
- package/dist/cjs/managers/shield_lists.js +97 -0
- package/dist/cjs/managers/sign_requests.js +123 -0
- package/dist/cjs/managers/sign_templates.js +87 -0
- package/dist/cjs/managers/skills.js +106 -0
- package/dist/cjs/managers/storage_policies.js +90 -0
- package/dist/cjs/managers/storage_policy_assignments.js +114 -0
- package/dist/cjs/managers/task_assignments.js +94 -0
- package/dist/cjs/managers/tasks.js +94 -0
- package/dist/cjs/managers/terms_of_service_user_statuses.js +81 -0
- package/dist/cjs/managers/terms_of_services.js +89 -0
- package/dist/cjs/managers/transfer.js +67 -0
- package/dist/cjs/managers/trashed_files.js +84 -0
- package/dist/cjs/managers/trashed_folders.js +84 -0
- package/dist/cjs/managers/trashed_items.js +94 -0
- package/dist/cjs/managers/trashed_web_links.js +84 -0
- package/dist/cjs/managers/uploads.js +98 -0
- package/dist/cjs/managers/user_collaborations.js +95 -0
- package/dist/cjs/managers/users.js +165 -0
- package/dist/cjs/managers/web_links.js +88 -0
- package/dist/cjs/managers/webhooks.js +115 -0
- package/dist/cjs/managers/workflows.js +92 -0
- package/dist/cjs/managers/zip_downloads.js +76 -0
- package/dist/cjs/models/index.js +38 -0
- package/dist/cjs/models/schemas.js +3 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/runtime.js +304 -0
- package/dist/cjs/tokens.js +121 -0
- package/dist/esm/auth.js +105 -0
- package/dist/esm/buildinfo.js +7 -0
- package/dist/esm/client.js +264 -0
- package/dist/esm/errors.js +16 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/internal.js +32 -0
- package/dist/esm/jwt.js +86 -0
- package/dist/esm/managers/ai.js +69 -0
- package/dist/esm/managers/ai_studio.js +94 -0
- package/dist/esm/managers/app_item_associations.js +82 -0
- package/dist/esm/managers/archives.js +73 -0
- package/dist/esm/managers/authorization.js +112 -0
- package/dist/esm/managers/automate_workflows.js +54 -0
- package/dist/esm/managers/avatars.js +39 -0
- package/dist/esm/managers/chunked_uploads.js +119 -0
- package/dist/esm/managers/classifications.js +57 -0
- package/dist/esm/managers/collaboration_allowlist_entries.js +67 -0
- package/dist/esm/managers/collaboration_allowlist_exempt_targets.js +67 -0
- package/dist/esm/managers/collections.js +87 -0
- package/dist/esm/managers/comments.js +94 -0
- package/dist/esm/managers/device_pinners.js +62 -0
- package/dist/esm/managers/docgen.js +96 -0
- package/dist/esm/managers/docgen_template.js +141 -0
- package/dist/esm/managers/downloads.js +32 -0
- package/dist/esm/managers/email_aliases.js +41 -0
- package/dist/esm/managers/enterprise_configurations.js +21 -0
- package/dist/esm/managers/events.js +45 -0
- package/dist/esm/managers/external_users.js +21 -0
- package/dist/esm/managers/file_classifications.js +60 -0
- package/dist/esm/managers/file_metadata.js +78 -0
- package/dist/esm/managers/file_requests.js +53 -0
- package/dist/esm/managers/file_version_legal_holds.js +51 -0
- package/dist/esm/managers/file_version_retentions.js +68 -0
- package/dist/esm/managers/file_versions.js +103 -0
- package/dist/esm/managers/file_watermarks.js +40 -0
- package/dist/esm/managers/files.js +101 -0
- package/dist/esm/managers/folder_classifications.js +60 -0
- package/dist/esm/managers/folder_locks.js +36 -0
- package/dist/esm/managers/folder_metadata.js +74 -0
- package/dist/esm/managers/folder_watermarks.js +40 -0
- package/dist/esm/managers/folders.js +154 -0
- package/dist/esm/managers/groups.js +95 -0
- package/dist/esm/managers/hub_collaborations.js +84 -0
- package/dist/esm/managers/hub_document.js +76 -0
- package/dist/esm/managers/hub_items.js +59 -0
- package/dist/esm/managers/hubs.js +149 -0
- package/dist/esm/managers/index.js +86 -0
- package/dist/esm/managers/integration_mappings.js +141 -0
- package/dist/esm/managers/invites.js +37 -0
- package/dist/esm/managers/legal_hold_policies.js +84 -0
- package/dist/esm/managers/legal_hold_policy_assignments.js +149 -0
- package/dist/esm/managers/list_collaborations.js +148 -0
- package/dist/esm/managers/memberships.js +123 -0
- package/dist/esm/managers/metadata_cascade_policies.js +81 -0
- package/dist/esm/managers/metadata_taxonomies.js +285 -0
- package/dist/esm/managers/metadata_templates.js +159 -0
- package/dist/esm/managers/notes.js +21 -0
- package/dist/esm/managers/recent_items.js +43 -0
- package/dist/esm/managers/retention_policies.js +94 -0
- package/dist/esm/managers/retention_policy_assignments.js +145 -0
- package/dist/esm/managers/search.js +93 -0
- package/dist/esm/managers/session_termination.js +31 -0
- package/dist/esm/managers/shared_links_app_items.js +18 -0
- package/dist/esm/managers/shared_links_files.js +72 -0
- package/dist/esm/managers/shared_links_folders.js +72 -0
- package/dist/esm/managers/shared_links_web_links.js +72 -0
- package/dist/esm/managers/shield_information_barrier_reports.js +61 -0
- package/dist/esm/managers/shield_information_barrier_segment_members.js +68 -0
- package/dist/esm/managers/shield_information_barrier_segment_restrictions.js +68 -0
- package/dist/esm/managers/shield_information_barrier_segments.js +79 -0
- package/dist/esm/managers/shield_information_barriers.js +71 -0
- package/dist/esm/managers/shield_lists.js +60 -0
- package/dist/esm/managers/sign_requests.js +86 -0
- package/dist/esm/managers/sign_templates.js +50 -0
- package/dist/esm/managers/skills.js +69 -0
- package/dist/esm/managers/storage_policies.js +53 -0
- package/dist/esm/managers/storage_policy_assignments.js +77 -0
- package/dist/esm/managers/task_assignments.js +57 -0
- package/dist/esm/managers/tasks.js +57 -0
- package/dist/esm/managers/terms_of_service_user_statuses.js +44 -0
- package/dist/esm/managers/terms_of_services.js +52 -0
- package/dist/esm/managers/transfer.js +30 -0
- package/dist/esm/managers/trashed_files.js +47 -0
- package/dist/esm/managers/trashed_folders.js +47 -0
- package/dist/esm/managers/trashed_items.js +57 -0
- package/dist/esm/managers/trashed_web_links.js +47 -0
- package/dist/esm/managers/uploads.js +61 -0
- package/dist/esm/managers/user_collaborations.js +58 -0
- package/dist/esm/managers/users.js +128 -0
- package/dist/esm/managers/web_links.js +51 -0
- package/dist/esm/managers/webhooks.js +78 -0
- package/dist/esm/managers/workflows.js +55 -0
- package/dist/esm/managers/zip_downloads.js +39 -0
- package/dist/esm/models/index.js +2 -0
- package/dist/esm/models/schemas.js +2 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/runtime.js +272 -0
- package/dist/esm/tokens.js +116 -0
- package/dist/types/auth.d.ts +56 -0
- package/dist/types/buildinfo.d.ts +6 -0
- package/dist/types/client.d.ts +176 -0
- package/dist/types/errors.d.ts +19 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/internal.d.ts +9 -0
- package/dist/types/jwt.d.ts +23 -0
- package/dist/types/managers/ai.d.ts +17 -0
- package/dist/types/managers/ai_studio.d.ts +27 -0
- package/dist/types/managers/app_item_associations.d.ts +25 -0
- package/dist/types/managers/archives.d.ts +18 -0
- package/dist/types/managers/authorization.d.ts +17 -0
- package/dist/types/managers/automate_workflows.d.ts +16 -0
- package/dist/types/managers/avatars.d.ts +10 -0
- package/dist/types/managers/chunked_uploads.d.ts +26 -0
- package/dist/types/managers/classifications.d.ts +11 -0
- package/dist/types/managers/collaboration_allowlist_entries.d.ts +18 -0
- package/dist/types/managers/collaboration_allowlist_exempt_targets.d.ts +18 -0
- package/dist/types/managers/collections.d.ts +26 -0
- package/dist/types/managers/comments.d.ts +32 -0
- package/dist/types/managers/device_pinners.d.ts +18 -0
- package/dist/types/managers/docgen.d.ts +25 -0
- package/dist/types/managers/docgen_template.d.ts +35 -0
- package/dist/types/managers/downloads.d.ts +14 -0
- package/dist/types/managers/email_aliases.d.ts +10 -0
- package/dist/types/managers/enterprise_configurations.d.ts +8 -0
- package/dist/types/managers/events.d.ts +18 -0
- package/dist/types/managers/external_users.d.ts +8 -0
- package/dist/types/managers/file_classifications.d.ts +11 -0
- package/dist/types/managers/file_metadata.d.ts +20 -0
- package/dist/types/managers/file_requests.d.ts +15 -0
- package/dist/types/managers/file_version_legal_holds.d.ts +16 -0
- package/dist/types/managers/file_version_retentions.d.ts +22 -0
- package/dist/types/managers/file_versions.d.ts +32 -0
- package/dist/types/managers/file_watermarks.d.ts +10 -0
- package/dist/types/managers/files.d.ts +39 -0
- package/dist/types/managers/folder_classifications.d.ts +11 -0
- package/dist/types/managers/folder_locks.d.ts +10 -0
- package/dist/types/managers/folder_metadata.d.ts +16 -0
- package/dist/types/managers/folder_watermarks.d.ts +10 -0
- package/dist/types/managers/folders.d.ts +54 -0
- package/dist/types/managers/groups.d.ts +33 -0
- package/dist/types/managers/hub_collaborations.d.ts +19 -0
- package/dist/types/managers/hub_document.d.ts +23 -0
- package/dist/types/managers/hub_items.d.ts +17 -0
- package/dist/types/managers/hubs.d.ts +35 -0
- package/dist/types/managers/index.d.ts +85 -0
- package/dist/types/managers/integration_mappings.d.ts +34 -0
- package/dist/types/managers/invites.d.ts +17 -0
- package/dist/types/managers/legal_hold_policies.d.ts +21 -0
- package/dist/types/managers/legal_hold_policy_assignments.d.ts +39 -0
- package/dist/types/managers/list_collaborations.d.ts +42 -0
- package/dist/types/managers/memberships.d.ts +39 -0
- package/dist/types/managers/metadata_cascade_policies.d.ts +20 -0
- package/dist/types/managers/metadata_taxonomies.d.ts +54 -0
- package/dist/types/managers/metadata_templates.d.ts +36 -0
- package/dist/types/managers/notes.d.ts +8 -0
- package/dist/types/managers/recent_items.d.ts +16 -0
- package/dist/types/managers/retention_policies.d.ts +27 -0
- package/dist/types/managers/retention_policy_assignments.d.ts +40 -0
- package/dist/types/managers/search.d.ts +33 -0
- package/dist/types/managers/session_termination.d.ts +9 -0
- package/dist/types/managers/shared_links_app_items.d.ts +8 -0
- package/dist/types/managers/shared_links_files.d.ts +17 -0
- package/dist/types/managers/shared_links_folders.d.ts +17 -0
- package/dist/types/managers/shared_links_web_links.d.ts +17 -0
- package/dist/types/managers/shield_information_barrier_reports.d.ts +17 -0
- package/dist/types/managers/shield_information_barrier_segment_members.d.ts +18 -0
- package/dist/types/managers/shield_information_barrier_segment_restrictions.d.ts +18 -0
- package/dist/types/managers/shield_information_barrier_segments.d.ts +19 -0
- package/dist/types/managers/shield_information_barriers.d.ts +18 -0
- package/dist/types/managers/shield_lists.d.ts +12 -0
- package/dist/types/managers/sign_requests.d.ts +21 -0
- package/dist/types/managers/sign_templates.d.ts +16 -0
- package/dist/types/managers/skills.d.ts +12 -0
- package/dist/types/managers/storage_policies.d.ts +17 -0
- package/dist/types/managers/storage_policy_assignments.d.ts +18 -0
- package/dist/types/managers/task_assignments.d.ts +12 -0
- package/dist/types/managers/tasks.d.ts +12 -0
- package/dist/types/managers/terms_of_service_user_statuses.d.ts +14 -0
- package/dist/types/managers/terms_of_services.d.ts +15 -0
- package/dist/types/managers/transfer.d.ts +13 -0
- package/dist/types/managers/trashed_files.d.ts +18 -0
- package/dist/types/managers/trashed_folders.d.ts +18 -0
- package/dist/types/managers/trashed_items.d.ts +20 -0
- package/dist/types/managers/trashed_web_links.d.ts +18 -0
- package/dist/types/managers/uploads.d.ts +21 -0
- package/dist/types/managers/user_collaborations.d.ts +20 -0
- package/dist/types/managers/users.d.ts +47 -0
- package/dist/types/managers/web_links.d.ts +15 -0
- package/dist/types/managers/webhooks.d.ts +19 -0
- package/dist/types/managers/workflows.d.ts +17 -0
- package/dist/types/managers/zip_downloads.d.ts +10 -0
- package/dist/types/models/index.d.ts +1 -0
- package/dist/types/models/schemas.d.ts +4424 -0
- package/dist/types/runtime.d.ts +85 -0
- package/dist/types/tokens.d.ts +50 -0
- package/docs/README.md +101 -0
- package/docs/auth.md +60 -0
- package/docs/errors.md +20 -0
- package/docs/managers/ai.md +49 -0
- package/docs/managers/ai_studio.md +63 -0
- package/docs/managers/app_item_associations.md +35 -0
- package/docs/managers/archives.md +48 -0
- package/docs/managers/authorization.md +43 -0
- package/docs/managers/automate_workflows.md +31 -0
- package/docs/managers/avatars.md +37 -0
- package/docs/managers/chunked_uploads.md +88 -0
- package/docs/managers/classifications.md +35 -0
- package/docs/managers/collaboration_allowlist_entries.md +46 -0
- package/docs/managers/collaboration_allowlist_exempt_targets.md +46 -0
- package/docs/managers/collections.md +44 -0
- package/docs/managers/comments.md +66 -0
- package/docs/managers/device_pinners.md +40 -0
- package/docs/managers/docgen.md +50 -0
- package/docs/managers/docgen_template.md +75 -0
- package/docs/managers/downloads.md +19 -0
- package/docs/managers/email_aliases.md +38 -0
- package/docs/managers/enterprise_configurations.md +16 -0
- package/docs/managers/events.md +26 -0
- package/docs/managers/external_users.md +13 -0
- package/docs/managers/file_classifications.md +49 -0
- package/docs/managers/file_metadata.md +69 -0
- package/docs/managers/file_requests.md +50 -0
- package/docs/managers/file_version_legal_holds.md +29 -0
- package/docs/managers/file_version_retentions.md +34 -0
- package/docs/managers/file_versions.md +70 -0
- package/docs/managers/file_watermarks.md +37 -0
- package/docs/managers/files.md +72 -0
- package/docs/managers/folder_classifications.md +49 -0
- package/docs/managers/folder_locks.md +33 -0
- package/docs/managers/folder_metadata.md +68 -0
- package/docs/managers/folder_watermarks.md +37 -0
- package/docs/managers/folders.md +93 -0
- package/docs/managers/groups.md +66 -0
- package/docs/managers/hub_collaborations.md +59 -0
- package/docs/managers/hub_document.md +34 -0
- package/docs/managers/hub_items.md +32 -0
- package/docs/managers/hubs.md +90 -0
- package/docs/managers/integration_mappings.md +96 -0
- package/docs/managers/invites.md +28 -0
- package/docs/managers/legal_hold_policies.md +60 -0
- package/docs/managers/legal_hold_policy_assignments.md +80 -0
- package/docs/managers/list_collaborations.md +64 -0
- package/docs/managers/memberships.md +79 -0
- package/docs/managers/metadata_cascade_policies.md +60 -0
- package/docs/managers/metadata_taxonomies.md +206 -0
- package/docs/managers/metadata_templates.md +98 -0
- package/docs/managers/notes.md +13 -0
- package/docs/managers/recent_items.md +19 -0
- package/docs/managers/retention_policies.md +63 -0
- package/docs/managers/retention_policy_assignments.md +78 -0
- package/docs/managers/search.md +43 -0
- package/docs/managers/session_termination.md +21 -0
- package/docs/managers/shared_links_app_items.md +15 -0
- package/docs/managers/shared_links_files.md +67 -0
- package/docs/managers/shared_links_folders.md +67 -0
- package/docs/managers/shared_links_web_links.md +67 -0
- package/docs/managers/shield_information_barrier_reports.md +37 -0
- package/docs/managers/shield_information_barrier_segment_members.md +47 -0
- package/docs/managers/shield_information_barrier_segment_restrictions.md +47 -0
- package/docs/managers/shield_information_barrier_segments.md +59 -0
- package/docs/managers/shield_information_barriers.md +44 -0
- package/docs/managers/shield_lists.md +51 -0
- package/docs/managers/sign_requests.md +60 -0
- package/docs/managers/sign_templates.md +28 -0
- package/docs/managers/skills.md +61 -0
- package/docs/managers/storage_policies.md +29 -0
- package/docs/managers/storage_policy_assignments.md +59 -0
- package/docs/managers/task_assignments.md +55 -0
- package/docs/managers/tasks.md +55 -0
- package/docs/managers/terms_of_service_user_statuses.md +36 -0
- package/docs/managers/terms_of_services.md +45 -0
- package/docs/managers/transfer.md +19 -0
- package/docs/managers/trashed_files.md +39 -0
- package/docs/managers/trashed_folders.md +39 -0
- package/docs/managers/trashed_items.md +23 -0
- package/docs/managers/trashed_web_links.md +39 -0
- package/docs/managers/uploads.md +41 -0
- package/docs/managers/user_collaborations.md +51 -0
- package/docs/managers/users.md +82 -0
- package/docs/managers/web_links.md +46 -0
- package/docs/managers/webhooks.md +58 -0
- package/docs/managers/workflows.md +32 -0
- package/docs/managers/zip_downloads.md +33 -0
- package/docs/pagination.md +17 -0
- package/package.json +32 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Code generated by box-gantry (vendored from runtimes/typescript/gantryruntime/src/runtime.ts). 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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Client = exports.Stream = exports.Response = exports.Request = exports.BoxApiError = void 0;
|
|
19
|
+
exports.withHeader = withHeader;
|
|
20
|
+
exports.withQuery = withQuery;
|
|
21
|
+
exports.withJsonBody = withJsonBody;
|
|
22
|
+
exports.withFormBody = withFormBody;
|
|
23
|
+
exports.withStreamBody = withStreamBody;
|
|
24
|
+
exports.withMultipartBody = withMultipartBody;
|
|
25
|
+
exports.responseBytes = responseBytes;
|
|
26
|
+
exports.responseStream = responseStream;
|
|
27
|
+
exports.responseHeader = responseHeader;
|
|
28
|
+
exports.statusCode = statusCode;
|
|
29
|
+
const errors_js_1 = require("./errors.js");
|
|
30
|
+
var errors_js_2 = require("./errors.js");
|
|
31
|
+
Object.defineProperty(exports, "BoxApiError", { enumerable: true, get: function () { return errors_js_2.BoxApiError; } });
|
|
32
|
+
__exportStar(require("./auth.js"), exports);
|
|
33
|
+
/** The default base URLs for the D-106 URL classes. */
|
|
34
|
+
const DEFAULT_BASE_URLS = {
|
|
35
|
+
api: 'https://api.box.com/2.0',
|
|
36
|
+
api_root: 'https://api.box.com',
|
|
37
|
+
upload: 'https://upload.box.com/api/2.0',
|
|
38
|
+
upload_session: 'https://upload.box.com/api/2.0',
|
|
39
|
+
oauth_authorize: 'https://account.box.com/api/oauth2',
|
|
40
|
+
download: 'https://api.box.com/2.0',
|
|
41
|
+
};
|
|
42
|
+
/** The runtime-owned HTTP request envelope, assembled by the `with*` builders
|
|
43
|
+
* before `fetch` executes it. */
|
|
44
|
+
class Request {
|
|
45
|
+
method;
|
|
46
|
+
url;
|
|
47
|
+
headers = new Headers();
|
|
48
|
+
query = new URLSearchParams();
|
|
49
|
+
/** The buffered request body, if any (buffered so retries can replay it). */
|
|
50
|
+
body;
|
|
51
|
+
constructor(method, url) {
|
|
52
|
+
this.method = method;
|
|
53
|
+
this.url = url;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.Request = Request;
|
|
57
|
+
/** The runtime-owned HTTP response envelope. The body is read fully so it can be
|
|
58
|
+
* replayed as bytes or a stream, and so retries stay safe. */
|
|
59
|
+
class Response {
|
|
60
|
+
status;
|
|
61
|
+
headers;
|
|
62
|
+
bodyBytes;
|
|
63
|
+
constructor(status, headers, bodyBytes) {
|
|
64
|
+
this.status = status;
|
|
65
|
+
this.headers = headers;
|
|
66
|
+
this.bodyBytes = bodyBytes;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.Response = Response;
|
|
70
|
+
/** A response/request body as bytes. The platform buffers it (the manifest's
|
|
71
|
+
* `Streaming` axis allows buffering) so a retried request can replay it. */
|
|
72
|
+
class Stream {
|
|
73
|
+
data;
|
|
74
|
+
constructor(data) {
|
|
75
|
+
this.data = data;
|
|
76
|
+
}
|
|
77
|
+
/** An empty stream (e.g. an absent multipart file part). */
|
|
78
|
+
static empty() {
|
|
79
|
+
return new Stream(new Uint8Array(0));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.Stream = Stream;
|
|
83
|
+
/** The runtime session: it holds the auth flow, base-URL configuration, and
|
|
84
|
+
* retry policy shared by every manager. */
|
|
85
|
+
class Client {
|
|
86
|
+
auth;
|
|
87
|
+
baseUrls;
|
|
88
|
+
maxRetries;
|
|
89
|
+
constructor(auth, options = {}) {
|
|
90
|
+
this.auth = auth;
|
|
91
|
+
const maxRetries = options.maxRetries ?? 5;
|
|
92
|
+
if (!Number.isInteger(maxRetries) || maxRetries < 0) {
|
|
93
|
+
throw new RangeError('maxRetries must be a non-negative integer');
|
|
94
|
+
}
|
|
95
|
+
this.maxRetries = maxRetries;
|
|
96
|
+
this.baseUrls = { ...DEFAULT_BASE_URLS, ...(options.baseUrls ?? {}) };
|
|
97
|
+
}
|
|
98
|
+
/** The configured base URL for a D-106 class, without a trailing slash. */
|
|
99
|
+
baseUrl(name) {
|
|
100
|
+
return this.baseUrls[name] ?? '';
|
|
101
|
+
}
|
|
102
|
+
/** A valid access token for the configured auth flow. The `signal` is
|
|
103
|
+
* accepted for contract symmetry; token acquisition is a shared refresh not
|
|
104
|
+
* bound to a single request's cancellation (mirroring the Rust runtime). */
|
|
105
|
+
async accessToken(_signal) {
|
|
106
|
+
return this.auth.accessToken();
|
|
107
|
+
}
|
|
108
|
+
/** A request envelope for a method and fully built URL. */
|
|
109
|
+
newRequest(method, url) {
|
|
110
|
+
return new Request(method, url);
|
|
111
|
+
}
|
|
112
|
+
/** Execute the request with retries: exponential backoff + full jitter, a
|
|
113
|
+
* single force-refresh on 401, and Retry-After (as a floor) on 429/5xx.
|
|
114
|
+
*
|
|
115
|
+
* Retry policy follows idempotency: a 429 (rate-limited, never processed)
|
|
116
|
+
* retries for every method; a transport error or a 5xx may have already
|
|
117
|
+
* committed a write, so those retry only for idempotent methods
|
|
118
|
+
* (GET/HEAD/PUT/DELETE/…). The 401 refresh applies to every method. */
|
|
119
|
+
async fetch(request, signal) {
|
|
120
|
+
let token = await this.auth.accessToken();
|
|
121
|
+
const query = request.query.toString();
|
|
122
|
+
const url = query ? `${request.url}?${query}` : request.url;
|
|
123
|
+
const idempotent = isIdempotent(request.method);
|
|
124
|
+
let refreshed = false;
|
|
125
|
+
let lastError;
|
|
126
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
127
|
+
const headers = new Headers(request.headers);
|
|
128
|
+
headers.set('Authorization', `Bearer ${token}`);
|
|
129
|
+
// `httpResponse` is the platform `Response` (via inference — the name is
|
|
130
|
+
// shadowed by this module's `Response` class, so it is never annotated).
|
|
131
|
+
let httpResponse;
|
|
132
|
+
try {
|
|
133
|
+
httpResponse = await fetch(url, {
|
|
134
|
+
method: request.method,
|
|
135
|
+
headers,
|
|
136
|
+
// A `Uint8Array` is a valid `BodyInit` at runtime; the cast bridges
|
|
137
|
+
// the `Uint8Array<ArrayBufferLike>` vs `BufferSource` generic gap in
|
|
138
|
+
// the DOM lib without narrowing the contract's plain-`Uint8Array` body.
|
|
139
|
+
body: request.body,
|
|
140
|
+
signal,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
// A transport error gives no response, so a non-idempotent write may
|
|
145
|
+
// already have committed — only retry idempotent methods.
|
|
146
|
+
lastError = err;
|
|
147
|
+
if (attempt === this.maxRetries || !idempotent) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
await sleep(backoff(attempt), signal);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const bodyBytes = new Uint8Array(await httpResponse.arrayBuffer());
|
|
154
|
+
const response = new Response(httpResponse.status, httpResponse.headers, bodyBytes);
|
|
155
|
+
// A single force-refresh on 401: re-acquire past the token cache so the
|
|
156
|
+
// retry doesn't just resend the same rejected token.
|
|
157
|
+
if (response.status === 401 && !refreshed) {
|
|
158
|
+
refreshed = true;
|
|
159
|
+
token = await this.auth.forceRefresh(token);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (shouldRetry(response.status, idempotent) && attempt < this.maxRetries) {
|
|
163
|
+
await sleep(retryDelay(response, attempt), signal);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
return response;
|
|
167
|
+
}
|
|
168
|
+
throw new errors_js_1.BoxApiError(`request failed after ${this.maxRetries + 1} attempts`, {
|
|
169
|
+
cause: lastError,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.Client = Client;
|
|
174
|
+
/** The safety ceiling on any single retry sleep, so a hostile server-sent
|
|
175
|
+
* Retry-After can't stall the client indefinitely. */
|
|
176
|
+
const MAX_RETRY_DELAY_MS = 30_000;
|
|
177
|
+
/** HTTP's idempotent methods: safe to replay after a transport error or 5xx. */
|
|
178
|
+
const IDEMPOTENT_METHODS = new Set(['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE']);
|
|
179
|
+
function isIdempotent(method) {
|
|
180
|
+
return IDEMPOTENT_METHODS.has(method.toUpperCase());
|
|
181
|
+
}
|
|
182
|
+
/** Whether a response status warrants a retry for a request of this idempotency.
|
|
183
|
+
* A 429 (rate-limited, never processed) retries for any method; a 5xx may have
|
|
184
|
+
* committed a write, so it retries only for idempotent methods. */
|
|
185
|
+
function shouldRetry(status, idempotent) {
|
|
186
|
+
return status === 429 || (status >= 500 && idempotent);
|
|
187
|
+
}
|
|
188
|
+
/** Full-jitter exponential backoff, capped at the max retry delay. */
|
|
189
|
+
function backoff(attempt) {
|
|
190
|
+
const base = Math.min(2 ** attempt * 500, MAX_RETRY_DELAY_MS);
|
|
191
|
+
return Math.random() * base;
|
|
192
|
+
}
|
|
193
|
+
/** The delay before the next retry: exponential backoff, raised to a
|
|
194
|
+
* (delay-seconds) Retry-After as a floor when present, and clamped to
|
|
195
|
+
* `MAX_RETRY_DELAY_MS`. HTTP-date Retry-After values fall back to backoff (the
|
|
196
|
+
* same posture as the Rust runtime). */
|
|
197
|
+
function retryDelay(response, attempt) {
|
|
198
|
+
let delay = backoff(attempt);
|
|
199
|
+
const header = response.headers.get('Retry-After');
|
|
200
|
+
if (header && /^\d+$/.test(header.trim())) {
|
|
201
|
+
delay = Math.max(delay, Number(header.trim()) * 1000);
|
|
202
|
+
}
|
|
203
|
+
return Math.min(delay, MAX_RETRY_DELAY_MS);
|
|
204
|
+
}
|
|
205
|
+
/** Sleep for `ms`, rejecting promptly if the signal aborts. */
|
|
206
|
+
function sleep(ms, signal) {
|
|
207
|
+
return new Promise((resolve, reject) => {
|
|
208
|
+
if (signal?.aborted) {
|
|
209
|
+
reject(abortError(signal));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const onAbort = () => {
|
|
213
|
+
clearTimeout(timer);
|
|
214
|
+
reject(abortError(signal));
|
|
215
|
+
};
|
|
216
|
+
const timer = setTimeout(() => {
|
|
217
|
+
signal?.removeEventListener('abort', onAbort);
|
|
218
|
+
resolve();
|
|
219
|
+
}, ms);
|
|
220
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function abortError(signal) {
|
|
224
|
+
const reason = signal?.reason;
|
|
225
|
+
return reason instanceof Error
|
|
226
|
+
? new errors_js_1.BoxApiError(`request aborted: ${reason.message}`)
|
|
227
|
+
: new errors_js_1.BoxApiError('request aborted');
|
|
228
|
+
}
|
|
229
|
+
/** Return the request with the header set. */
|
|
230
|
+
function withHeader(request, name, value) {
|
|
231
|
+
request.headers.set(name, value);
|
|
232
|
+
return request;
|
|
233
|
+
}
|
|
234
|
+
/** Return the request with the query parameter appended, encoded. */
|
|
235
|
+
function withQuery(request, name, value) {
|
|
236
|
+
request.query.append(name, value);
|
|
237
|
+
return request;
|
|
238
|
+
}
|
|
239
|
+
/** Return the request with the serialized JSON body and content type set. */
|
|
240
|
+
function withJsonBody(request, body) {
|
|
241
|
+
request.headers.set('Content-Type', 'application/json');
|
|
242
|
+
request.body = body;
|
|
243
|
+
return request;
|
|
244
|
+
}
|
|
245
|
+
/** Return the request with an application/x-www-form-urlencoded body (the
|
|
246
|
+
* OAuth2 token endpoints). */
|
|
247
|
+
function withFormBody(request, form) {
|
|
248
|
+
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
|
249
|
+
request.body = form;
|
|
250
|
+
return request;
|
|
251
|
+
}
|
|
252
|
+
/** Return the request with a streaming body (buffered, so retries can replay
|
|
253
|
+
* it — the manifest's `Streaming` axis permits buffering). */
|
|
254
|
+
function withStreamBody(request, body, contentType) {
|
|
255
|
+
request.headers.set('Content-Type', contentType);
|
|
256
|
+
request.body = body.data;
|
|
257
|
+
return request;
|
|
258
|
+
}
|
|
259
|
+
/** Return the request with a Box-style multipart body: an `attributes` JSON
|
|
260
|
+
* part plus a file part (G-7). */
|
|
261
|
+
function withMultipartBody(request, attributes, fileName, file) {
|
|
262
|
+
const boundary = `----gantryFormBoundary${Math.random().toString(36).slice(2)}`;
|
|
263
|
+
const encoder = new TextEncoder();
|
|
264
|
+
const escaped = fileName.replace(/["\r\n]/g, '_');
|
|
265
|
+
const parts = [
|
|
266
|
+
encoder.encode(`--${boundary}\r\nContent-Disposition: form-data; name="attributes"\r\n\r\n`),
|
|
267
|
+
attributes,
|
|
268
|
+
encoder.encode(`\r\n--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${escaped}"\r\n` +
|
|
269
|
+
'Content-Type: application/octet-stream\r\n\r\n'),
|
|
270
|
+
file.data,
|
|
271
|
+
encoder.encode(`\r\n--${boundary}--\r\n`),
|
|
272
|
+
];
|
|
273
|
+
request.headers.set('Content-Type', `multipart/form-data; boundary=${boundary}`);
|
|
274
|
+
request.body = concat(parts);
|
|
275
|
+
return request;
|
|
276
|
+
}
|
|
277
|
+
/** Concatenate byte chunks into one buffer. */
|
|
278
|
+
function concat(chunks) {
|
|
279
|
+
const total = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
280
|
+
const out = new Uint8Array(total);
|
|
281
|
+
let offset = 0;
|
|
282
|
+
for (const chunk of chunks) {
|
|
283
|
+
out.set(chunk, offset);
|
|
284
|
+
offset += chunk.length;
|
|
285
|
+
}
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
/** Read the whole response body. */
|
|
289
|
+
function responseBytes(response) {
|
|
290
|
+
return response.bodyBytes;
|
|
291
|
+
}
|
|
292
|
+
/** The response body as a stream, for binary downloads (FR-7.4). */
|
|
293
|
+
function responseStream(response) {
|
|
294
|
+
return new Stream(response.bodyBytes);
|
|
295
|
+
}
|
|
296
|
+
/** A response header value, empty when absent (redirect Location, Retry-After
|
|
297
|
+
* surfacing). */
|
|
298
|
+
function responseHeader(response, name) {
|
|
299
|
+
return response.headers.get(name) ?? '';
|
|
300
|
+
}
|
|
301
|
+
/** The response status code. */
|
|
302
|
+
function statusCode(response) {
|
|
303
|
+
return response.status;
|
|
304
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Code generated by box-gantry (vendored from runtimes/typescript/gantryruntime/src/tokens.ts). DO NOT EDIT.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CachedToken = exports.DEFAULT_TOKEN_URL = void 0;
|
|
5
|
+
exports.postTokenForm = postTokenForm;
|
|
6
|
+
// The shared token machinery behind every exchange flow: the `Auth` contract,
|
|
7
|
+
// the token-endpoint POST, and the single-flight access-token cache. Split out
|
|
8
|
+
// so both `auth.ts` (developer token, CCG, OAuth) and `jwt.ts` (JWT server auth)
|
|
9
|
+
// reuse it without either importing the other, and without leaking these
|
|
10
|
+
// internals into the package's public surface.
|
|
11
|
+
const errors_js_1 = require("./errors.js");
|
|
12
|
+
/** Box's OAuth 2.0 token endpoint, shared by every exchange flow. */
|
|
13
|
+
exports.DEFAULT_TOKEN_URL = 'https://api.box.com/oauth2/token';
|
|
14
|
+
/** Refresh a cached token this long before expiry, so in-flight requests never
|
|
15
|
+
* race an expiry. */
|
|
16
|
+
const REFRESH_MARGIN_MS = 60_000;
|
|
17
|
+
/** A hard deadline on a token exchange, so a stalled endpoint can't leave a
|
|
18
|
+
* single-flight refresh (and every caller awaiting it) hung forever. Matches
|
|
19
|
+
* the Go runtime's 30s token HTTP client. */
|
|
20
|
+
const TOKEN_TIMEOUT_MS = 30_000;
|
|
21
|
+
/**
|
|
22
|
+
* Caches an access token and refreshes it — via the flow-specific `refresh` —
|
|
23
|
+
* when it is missing or within the refresh margin of expiry. Concurrent callers
|
|
24
|
+
* during a refresh share one in-flight exchange (single-flight), so a token is
|
|
25
|
+
* never fetched twice at once, and the exchange is not tied to any one caller.
|
|
26
|
+
*/
|
|
27
|
+
class CachedToken {
|
|
28
|
+
refresh;
|
|
29
|
+
token;
|
|
30
|
+
expiry;
|
|
31
|
+
inflight;
|
|
32
|
+
constructor(refresh, seed) {
|
|
33
|
+
this.refresh = refresh;
|
|
34
|
+
this.token = seed?.accessToken ?? '';
|
|
35
|
+
this.expiry = seed ? Date.now() + seed.ttlMs : 0;
|
|
36
|
+
}
|
|
37
|
+
async accessToken() {
|
|
38
|
+
if (this.token && this.expiry - Date.now() > REFRESH_MARGIN_MS) {
|
|
39
|
+
return this.token;
|
|
40
|
+
}
|
|
41
|
+
return this.refreshOnce();
|
|
42
|
+
}
|
|
43
|
+
async forceRefresh(stale) {
|
|
44
|
+
// Another caller may already have refreshed past the rejected token.
|
|
45
|
+
if (this.token && this.token !== stale) {
|
|
46
|
+
return this.token;
|
|
47
|
+
}
|
|
48
|
+
return this.refreshOnce();
|
|
49
|
+
}
|
|
50
|
+
/** Run the flow's refresh, sharing one in-flight exchange across callers. */
|
|
51
|
+
refreshOnce() {
|
|
52
|
+
if (!this.inflight) {
|
|
53
|
+
this.inflight = this.refresh()
|
|
54
|
+
.then((token) => {
|
|
55
|
+
this.token = token.accessToken;
|
|
56
|
+
this.expiry = Date.now() + token.ttlMs;
|
|
57
|
+
this.inflight = undefined;
|
|
58
|
+
return token.accessToken;
|
|
59
|
+
})
|
|
60
|
+
.catch((err) => {
|
|
61
|
+
this.inflight = undefined;
|
|
62
|
+
throw err;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return this.inflight;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.CachedToken = CachedToken;
|
|
69
|
+
/**
|
|
70
|
+
* POST a form-encoded grant to the token endpoint and normalize the response.
|
|
71
|
+
* A transport failure and a non-2xx body both surface as a `BoxApiError`, so
|
|
72
|
+
* token acquisition never escapes the runtime's error contract. The optional
|
|
73
|
+
* `signal` cancels an explicit caller-initiated exchange (`exchangeCode`); the
|
|
74
|
+
* cached flows do not thread one, so a shared refresh is never bound to a single
|
|
75
|
+
* request's cancellation.
|
|
76
|
+
*/
|
|
77
|
+
async function postTokenForm(tokenUrl, form, signal) {
|
|
78
|
+
// An internal deadline independent of the caller's signal, combined with it
|
|
79
|
+
// when present. It also covers the body read, since the signal aborts an
|
|
80
|
+
// in-progress `fetch` (including body streaming). `AbortSignal.timeout` owns
|
|
81
|
+
// its own timer, so there is nothing to clear.
|
|
82
|
+
const deadline = AbortSignal.timeout(TOKEN_TIMEOUT_MS);
|
|
83
|
+
const combined = signal ? AbortSignal.any([signal, deadline]) : deadline;
|
|
84
|
+
let response;
|
|
85
|
+
let text;
|
|
86
|
+
try {
|
|
87
|
+
response = await fetch(tokenUrl, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: {
|
|
90
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
91
|
+
Accept: 'application/json',
|
|
92
|
+
},
|
|
93
|
+
body: new URLSearchParams(form).toString(),
|
|
94
|
+
signal: combined,
|
|
95
|
+
});
|
|
96
|
+
text = await response.text();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
throw new errors_js_1.BoxApiError('token endpoint request failed', { cause: err });
|
|
100
|
+
}
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
throw new errors_js_1.BoxApiError(`token endpoint returned ${response.status}: ${text.trim()}`, {
|
|
103
|
+
status: response.status,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
let parsed;
|
|
107
|
+
try {
|
|
108
|
+
parsed = JSON.parse(text);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
throw new errors_js_1.BoxApiError('token endpoint returned invalid JSON');
|
|
112
|
+
}
|
|
113
|
+
if (!parsed.access_token) {
|
|
114
|
+
throw new errors_js_1.BoxApiError('token endpoint returned no access_token');
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
accessToken: parsed.access_token,
|
|
118
|
+
refreshToken: parsed.refresh_token ?? '',
|
|
119
|
+
ttlMs: (parsed.expires_in ?? 0) * 1000,
|
|
120
|
+
};
|
|
121
|
+
}
|
package/dist/esm/auth.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Code generated by box-gantry (vendored from runtimes/typescript/gantryruntime/src/auth.ts). DO NOT EDIT.
|
|
2
|
+
// The `fetch`-only Box auth flows, each an `Auth` passed to the runtime
|
|
3
|
+
// `Client`: `developerToken` (a fixed token), `clientCredentials` (CCG), and the
|
|
4
|
+
// OAuth 2.0 authorization-code flow. They exchange credentials at Box's token
|
|
5
|
+
// endpoint and cache the access token (via the shared machinery in `tokens.ts`).
|
|
6
|
+
// JWT server auth lives in `jwt.ts` — the only flow that reaches beyond `fetch`.
|
|
7
|
+
import { BoxApiError } from './errors.js';
|
|
8
|
+
import { CachedToken, DEFAULT_TOKEN_URL, postTokenForm } from './tokens.js';
|
|
9
|
+
/** Where a user is sent to grant an OAuth 2.0 app access. */
|
|
10
|
+
const AUTHORIZE_URL = 'https://account.box.com/api/oauth2/authorize';
|
|
11
|
+
/**
|
|
12
|
+
* The simplest flow: a fixed access token from the Box developer console. A
|
|
13
|
+
* fixed token cannot be refreshed, so `forceRefresh` returns it unchanged (a
|
|
14
|
+
* subsequent 401 then surfaces to the caller).
|
|
15
|
+
*/
|
|
16
|
+
export function developerToken(token) {
|
|
17
|
+
return {
|
|
18
|
+
accessToken: async () => token,
|
|
19
|
+
forceRefresh: async () => token,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Build a CCG `Auth`. Requires a subject: `enterpriseId` or `userId`. */
|
|
23
|
+
export function clientCredentials(config) {
|
|
24
|
+
if (!config.userId && !config.enterpriseId) {
|
|
25
|
+
throw new BoxApiError('clientCredentials requires a subject: enterpriseId or userId');
|
|
26
|
+
}
|
|
27
|
+
const tokenUrl = config.tokenUrl ?? DEFAULT_TOKEN_URL;
|
|
28
|
+
// A `userId` acts as that managed user; otherwise the enterprise service
|
|
29
|
+
// account. The guard above rules out an empty subject.
|
|
30
|
+
const subject = config.userId
|
|
31
|
+
? { type: 'user', id: config.userId }
|
|
32
|
+
: { type: 'enterprise', id: config.enterpriseId ?? '' };
|
|
33
|
+
return new CachedToken(() => postTokenForm(tokenUrl, {
|
|
34
|
+
grant_type: 'client_credentials',
|
|
35
|
+
client_id: config.clientId,
|
|
36
|
+
client_secret: config.clientSecret,
|
|
37
|
+
box_subject_type: subject.type,
|
|
38
|
+
box_subject_id: subject.id,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the URL to redirect a user to so they can grant access. `state` is
|
|
43
|
+
* echoed back to the redirect URI for CSRF protection.
|
|
44
|
+
*/
|
|
45
|
+
export function authorizeUrl(config, redirectUri, state) {
|
|
46
|
+
const query = new URLSearchParams({
|
|
47
|
+
response_type: 'code',
|
|
48
|
+
client_id: config.clientId,
|
|
49
|
+
redirect_uri: redirectUri,
|
|
50
|
+
state,
|
|
51
|
+
});
|
|
52
|
+
return `${AUTHORIZE_URL}?${query.toString()}`;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The refresh exchange for the authorization-code flow: it swaps the current
|
|
56
|
+
* refresh token for a fresh access token and rotates the refresh token Box
|
|
57
|
+
* returns (Box invalidates the old one on each exchange), reporting each rotated
|
|
58
|
+
* token through `config.onRefresh` so a caller can persist it.
|
|
59
|
+
*/
|
|
60
|
+
function refreshTokenExchange(config, tokenUrl, initialRefresh) {
|
|
61
|
+
let refreshToken = initialRefresh;
|
|
62
|
+
return async () => {
|
|
63
|
+
const token = await postTokenForm(tokenUrl, {
|
|
64
|
+
grant_type: 'refresh_token',
|
|
65
|
+
refresh_token: refreshToken,
|
|
66
|
+
client_id: config.clientId,
|
|
67
|
+
client_secret: config.clientSecret,
|
|
68
|
+
});
|
|
69
|
+
if (token.refreshToken) {
|
|
70
|
+
refreshToken = token.refreshToken;
|
|
71
|
+
config.onRefresh?.(token.refreshToken);
|
|
72
|
+
}
|
|
73
|
+
return token;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resume the authorization-code flow from a previously stored refresh token,
|
|
78
|
+
* exchanging it for access tokens as needed.
|
|
79
|
+
*/
|
|
80
|
+
export function oauth(config, refreshToken) {
|
|
81
|
+
const tokenUrl = config.tokenUrl ?? DEFAULT_TOKEN_URL;
|
|
82
|
+
return new CachedToken(refreshTokenExchange(config, tokenUrl, refreshToken));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Exchange an authorization code for an `Auth` that refreshes itself thereafter.
|
|
86
|
+
* The initial refresh token is reported through `config.onRefresh` so it can be
|
|
87
|
+
* persisted immediately.
|
|
88
|
+
*/
|
|
89
|
+
export async function exchangeCode(config, code, redirectUri, signal) {
|
|
90
|
+
const tokenUrl = config.tokenUrl ?? DEFAULT_TOKEN_URL;
|
|
91
|
+
const token = await postTokenForm(tokenUrl, {
|
|
92
|
+
grant_type: 'authorization_code',
|
|
93
|
+
code,
|
|
94
|
+
client_id: config.clientId,
|
|
95
|
+
client_secret: config.clientSecret,
|
|
96
|
+
redirect_uri: redirectUri,
|
|
97
|
+
}, signal);
|
|
98
|
+
if (!token.refreshToken) {
|
|
99
|
+
throw new BoxApiError('authorization-code exchange returned no refresh_token');
|
|
100
|
+
}
|
|
101
|
+
config.onRefresh?.(token.refreshToken);
|
|
102
|
+
// Seed the cache with the access token we just obtained, and refresh via the
|
|
103
|
+
// rotating refresh token thereafter.
|
|
104
|
+
return new CachedToken(refreshTokenExchange(config, tokenUrl, token.refreshToken), token);
|
|
105
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Code generated by box-gantry 0.1.0 (spec ee7d55aedefe2fa0). DO NOT EDIT.
|
|
2
|
+
/** The box-gantry engine version that generated this SDK. */
|
|
3
|
+
export const ENGINE = "0.1.0";
|
|
4
|
+
/** Fingerprint of the input spec set. */
|
|
5
|
+
export const SPEC_FINGERPRINT = "ee7d55aedefe2fa0";
|
|
6
|
+
/** The target language key (FR-4). */
|
|
7
|
+
export const TARGET = "typescript";
|