box-node-sdk 3.8.1 → 3.8.2
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/lib-esm/api-request-manager.d.ts +36 -0
- package/lib-esm/api-request-manager.js +78 -0
- package/lib-esm/api-request-manager.js.map +1 -0
- package/lib-esm/api-request.d.ts +135 -0
- package/lib-esm/api-request.js +282 -0
- package/lib-esm/api-request.js.map +1 -0
- package/lib-esm/box-client.d.ts +274 -0
- package/lib-esm/box-client.js +594 -0
- package/lib-esm/box-client.js.map +1 -0
- package/lib-esm/box-node-sdk.d.ts +227 -0
- package/lib-esm/box-node-sdk.js +373 -0
- package/lib-esm/box-node-sdk.js.map +1 -0
- package/lib-esm/chunked-uploader.d.ts +128 -0
- package/lib-esm/chunked-uploader.js +276 -0
- package/lib-esm/chunked-uploader.js.map +1 -0
- package/lib-esm/enterprise-event-stream.d.ts +82 -0
- package/lib-esm/enterprise-event-stream.js +205 -0
- package/lib-esm/enterprise-event-stream.js.map +1 -0
- package/lib-esm/event-stream.d.ts +91 -0
- package/lib-esm/event-stream.js +277 -0
- package/lib-esm/event-stream.js.map +1 -0
- package/lib-esm/managers/ai.generated.d.ts +58 -0
- package/lib-esm/managers/ai.generated.js +66 -0
- package/lib-esm/managers/ai.generated.js.map +1 -0
- package/lib-esm/managers/collaboration-allowlist.d.ts +133 -0
- package/lib-esm/managers/collaboration-allowlist.js +194 -0
- package/lib-esm/managers/collaboration-allowlist.js.map +1 -0
- package/lib-esm/managers/collaborations.d.ts +173 -0
- package/lib-esm/managers/collaborations.js +252 -0
- package/lib-esm/managers/collaborations.js.map +1 -0
- package/lib-esm/managers/collections.d.ts +42 -0
- package/lib-esm/managers/collections.js +62 -0
- package/lib-esm/managers/collections.js.map +1 -0
- package/lib-esm/managers/comments.d.ts +103 -0
- package/lib-esm/managers/comments.js +175 -0
- package/lib-esm/managers/comments.js.map +1 -0
- package/lib-esm/managers/device-pins.d.ts +52 -0
- package/lib-esm/managers/device-pins.js +91 -0
- package/lib-esm/managers/device-pins.js.map +1 -0
- package/lib-esm/managers/enterprise.d.ts +164 -0
- package/lib-esm/managers/enterprise.js +193 -0
- package/lib-esm/managers/enterprise.js.map +1 -0
- package/lib-esm/managers/events.d.ts +222 -0
- package/lib-esm/managers/events.js +295 -0
- package/lib-esm/managers/events.js.map +1 -0
- package/lib-esm/managers/file-requests-manager.d.ts +56 -0
- package/lib-esm/managers/file-requests-manager.js +81 -0
- package/lib-esm/managers/file-requests-manager.js.map +1 -0
- package/lib-esm/managers/files.d.ts +817 -0
- package/lib-esm/managers/files.js +1408 -0
- package/lib-esm/managers/files.js.map +1 -0
- package/lib-esm/managers/folders.d.ts +396 -0
- package/lib-esm/managers/folders.js +570 -0
- package/lib-esm/managers/folders.js.map +1 -0
- package/lib-esm/managers/groups.d.ts +213 -0
- package/lib-esm/managers/groups.js +289 -0
- package/lib-esm/managers/groups.js.map +1 -0
- package/lib-esm/managers/integration-mappings.d.ts +116 -0
- package/lib-esm/managers/integration-mappings.js +101 -0
- package/lib-esm/managers/integration-mappings.js.map +1 -0
- package/lib-esm/managers/legal-hold-policies.d.ts +190 -0
- package/lib-esm/managers/legal-hold-policies.js +254 -0
- package/lib-esm/managers/legal-hold-policies.js.map +1 -0
- package/lib-esm/managers/metadata.d.ts +232 -0
- package/lib-esm/managers/metadata.js +288 -0
- package/lib-esm/managers/metadata.js.map +1 -0
- package/lib-esm/managers/recent-items.d.ts +38 -0
- package/lib-esm/managers/recent-items.js +49 -0
- package/lib-esm/managers/recent-items.js.map +1 -0
- package/lib-esm/managers/retention-policies.d.ts +308 -0
- package/lib-esm/managers/retention-policies.js +374 -0
- package/lib-esm/managers/retention-policies.js.map +1 -0
- package/lib-esm/managers/search.d.ts +82 -0
- package/lib-esm/managers/search.js +90 -0
- package/lib-esm/managers/search.js.map +1 -0
- package/lib-esm/managers/shared-items.d.ts +33 -0
- package/lib-esm/managers/shared-items.js +74 -0
- package/lib-esm/managers/shared-items.js.map +1 -0
- package/lib-esm/managers/shield-information-barrier-reports.generated.d.ts +65 -0
- package/lib-esm/managers/shield-information-barrier-reports.generated.js +65 -0
- package/lib-esm/managers/shield-information-barrier-reports.generated.js.map +1 -0
- package/lib-esm/managers/shield-information-barrier-segment-members.generated.d.ts +83 -0
- package/lib-esm/managers/shield-information-barrier-segment-members.generated.js +83 -0
- package/lib-esm/managers/shield-information-barrier-segment-members.generated.js.map +1 -0
- package/lib-esm/managers/shield-information-barrier-segment-restrictions.generated.d.ts +84 -0
- package/lib-esm/managers/shield-information-barrier-segment-restrictions.generated.js +84 -0
- package/lib-esm/managers/shield-information-barrier-segment-restrictions.generated.js.map +1 -0
- package/lib-esm/managers/shield-information-barrier-segments.generated.d.ts +98 -0
- package/lib-esm/managers/shield-information-barrier-segments.generated.js +99 -0
- package/lib-esm/managers/shield-information-barrier-segments.generated.js.map +1 -0
- package/lib-esm/managers/shield-information-barriers.generated.d.ts +79 -0
- package/lib-esm/managers/shield-information-barriers.generated.js +83 -0
- package/lib-esm/managers/shield-information-barriers.generated.js.map +1 -0
- package/lib-esm/managers/sign-requests.generated.d.ts +93 -0
- package/lib-esm/managers/sign-requests.generated.js +97 -0
- package/lib-esm/managers/sign-requests.generated.js.map +1 -0
- package/lib-esm/managers/sign-templates.generated.d.ts +51 -0
- package/lib-esm/managers/sign-templates.generated.js +49 -0
- package/lib-esm/managers/sign-templates.generated.js.map +1 -0
- package/lib-esm/managers/storage-policies.d.ts +86 -0
- package/lib-esm/managers/storage-policies.js +174 -0
- package/lib-esm/managers/storage-policies.js.map +1 -0
- package/lib-esm/managers/tasks.d.ts +161 -0
- package/lib-esm/managers/tasks.js +243 -0
- package/lib-esm/managers/tasks.js.map +1 -0
- package/lib-esm/managers/terms-of-service.d.ts +161 -0
- package/lib-esm/managers/terms-of-service.js +283 -0
- package/lib-esm/managers/terms-of-service.js.map +1 -0
- package/lib-esm/managers/trash.d.ts +30 -0
- package/lib-esm/managers/trash.js +47 -0
- package/lib-esm/managers/trash.js.map +1 -0
- package/lib-esm/managers/users.d.ts +171 -0
- package/lib-esm/managers/users.js +230 -0
- package/lib-esm/managers/users.js.map +1 -0
- package/lib-esm/managers/web-links.d.ts +127 -0
- package/lib-esm/managers/web-links.js +200 -0
- package/lib-esm/managers/web-links.js.map +1 -0
- package/lib-esm/managers/webhooks.d.ts +169 -0
- package/lib-esm/managers/webhooks.js +398 -0
- package/lib-esm/managers/webhooks.js.map +1 -0
- package/lib-esm/schemas/ai-agent-ask.generated.d.ts +17 -0
- package/lib-esm/schemas/ai-agent-ask.generated.js +3 -0
- package/lib-esm/schemas/ai-agent-ask.generated.js.map +1 -0
- package/lib-esm/schemas/ai-agent-basic-gen-tool.generated.d.ts +14 -0
- package/lib-esm/schemas/ai-agent-basic-gen-tool.generated.js +3 -0
- package/lib-esm/schemas/ai-agent-basic-gen-tool.generated.js.map +1 -0
- package/lib-esm/schemas/ai-agent-basic-text-tool-ask.generated.d.ts +34 -0
- package/lib-esm/schemas/ai-agent-basic-text-tool-ask.generated.js +3 -0
- package/lib-esm/schemas/ai-agent-basic-text-tool-ask.generated.js.map +1 -0
- package/lib-esm/schemas/ai-agent-basic-text-tool-text-gen.generated.d.ts +36 -0
- package/lib-esm/schemas/ai-agent-basic-text-tool-text-gen.generated.js +3 -0
- package/lib-esm/schemas/ai-agent-basic-text-tool-text-gen.generated.js.map +1 -0
- package/lib-esm/schemas/ai-agent-long-text-tool.generated.d.ts +9 -0
- package/lib-esm/schemas/ai-agent-long-text-tool.generated.js +3 -0
- package/lib-esm/schemas/ai-agent-long-text-tool.generated.js.map +1 -0
- package/lib-esm/schemas/ai-agent-text-gen.generated.d.ts +14 -0
- package/lib-esm/schemas/ai-agent-text-gen.generated.js +3 -0
- package/lib-esm/schemas/ai-agent-text-gen.generated.js.map +1 -0
- package/lib-esm/schemas/ai-ask.generated.d.ts +40 -0
- package/lib-esm/schemas/ai-ask.generated.js +3 -0
- package/lib-esm/schemas/ai-ask.generated.js.map +1 -0
- package/lib-esm/schemas/ai-citation.generated.d.ts +27 -0
- package/lib-esm/schemas/ai-citation.generated.js +3 -0
- package/lib-esm/schemas/ai-citation.generated.js.map +1 -0
- package/lib-esm/schemas/ai-dialogue-history.generated.d.ts +22 -0
- package/lib-esm/schemas/ai-dialogue-history.generated.js +3 -0
- package/lib-esm/schemas/ai-dialogue-history.generated.js.map +1 -0
- package/lib-esm/schemas/ai-llm-endpoint-params-google.generated.d.ts +31 -0
- package/lib-esm/schemas/ai-llm-endpoint-params-google.generated.js +3 -0
- package/lib-esm/schemas/ai-llm-endpoint-params-google.generated.js.map +1 -0
- package/lib-esm/schemas/ai-llm-endpoint-params-open-ai.generated.d.ts +43 -0
- package/lib-esm/schemas/ai-llm-endpoint-params-open-ai.generated.js +3 -0
- package/lib-esm/schemas/ai-llm-endpoint-params-open-ai.generated.js.map +1 -0
- package/lib-esm/schemas/ai-response-full.generated.d.ts +12 -0
- package/lib-esm/schemas/ai-response-full.generated.js +3 -0
- package/lib-esm/schemas/ai-response-full.generated.js.map +1 -0
- package/lib-esm/schemas/ai-response.generated.d.ts +22 -0
- package/lib-esm/schemas/ai-response.generated.js +3 -0
- package/lib-esm/schemas/ai-response.generated.js.map +1 -0
- package/lib-esm/schemas/ai-text-gen.generated.d.ts +30 -0
- package/lib-esm/schemas/ai-text-gen.generated.js +3 -0
- package/lib-esm/schemas/ai-text-gen.generated.js.map +1 -0
- package/lib-esm/schemas/collaboration-create.d.ts +5 -0
- package/lib-esm/schemas/collaboration-create.js +3 -0
- package/lib-esm/schemas/collaboration-create.js.map +1 -0
- package/lib-esm/schemas/collaboration-update.d.ts +7 -0
- package/lib-esm/schemas/collaboration-update.js +3 -0
- package/lib-esm/schemas/collaboration-update.js.map +1 -0
- package/lib-esm/schemas/collaboration.d.ts +108 -0
- package/lib-esm/schemas/collaboration.js +3 -0
- package/lib-esm/schemas/collaboration.js.map +1 -0
- package/lib-esm/schemas/collaborations.d.ts +13 -0
- package/lib-esm/schemas/collaborations.js +3 -0
- package/lib-esm/schemas/collaborations.js.map +1 -0
- package/lib-esm/schemas/enterprise-base.generated.d.ts +18 -0
- package/lib-esm/schemas/enterprise-base.generated.js +3 -0
- package/lib-esm/schemas/enterprise-base.generated.js.map +1 -0
- package/lib-esm/schemas/file-base.generated.d.ts +32 -0
- package/lib-esm/schemas/file-base.generated.js +3 -0
- package/lib-esm/schemas/file-base.generated.js.map +1 -0
- package/lib-esm/schemas/file-mini.generated.d.ts +41 -0
- package/lib-esm/schemas/file-mini.generated.js +3 -0
- package/lib-esm/schemas/file-mini.generated.js.map +1 -0
- package/lib-esm/schemas/file-request.d.ts +41 -0
- package/lib-esm/schemas/file-request.js +3 -0
- package/lib-esm/schemas/file-request.js.map +1 -0
- package/lib-esm/schemas/file-version-base.generated.d.ts +19 -0
- package/lib-esm/schemas/file-version-base.generated.js +3 -0
- package/lib-esm/schemas/file-version-base.generated.js.map +1 -0
- package/lib-esm/schemas/file-version-mini.generated.d.ts +14 -0
- package/lib-esm/schemas/file-version-mini.generated.js +3 -0
- package/lib-esm/schemas/file-version-mini.generated.js.map +1 -0
- package/lib-esm/schemas/folder-base.generated.d.ts +32 -0
- package/lib-esm/schemas/folder-base.generated.js +3 -0
- package/lib-esm/schemas/folder-base.generated.js.map +1 -0
- package/lib-esm/schemas/folder-mini.generated.d.ts +31 -0
- package/lib-esm/schemas/folder-mini.generated.js +3 -0
- package/lib-esm/schemas/folder-mini.generated.js.map +1 -0
- package/lib-esm/schemas/index.d.ts +15 -0
- package/lib-esm/schemas/index.generated.d.ts +52 -0
- package/lib-esm/schemas/index.generated.js +69 -0
- package/lib-esm/schemas/index.generated.js.map +1 -0
- package/lib-esm/schemas/index.js +32 -0
- package/lib-esm/schemas/index.js.map +1 -0
- package/lib-esm/schemas/integration-mapping-base.d.ts +23 -0
- package/lib-esm/schemas/integration-mapping-base.js +3 -0
- package/lib-esm/schemas/integration-mapping-base.js.map +1 -0
- package/lib-esm/schemas/integration-mapping-box-item-slack.d.ts +17 -0
- package/lib-esm/schemas/integration-mapping-box-item-slack.js +3 -0
- package/lib-esm/schemas/integration-mapping-box-item-slack.js.map +1 -0
- package/lib-esm/schemas/integration-mapping-partner-item-slack.d.ts +27 -0
- package/lib-esm/schemas/integration-mapping-partner-item-slack.js +3 -0
- package/lib-esm/schemas/integration-mapping-partner-item-slack.js.map +1 -0
- package/lib-esm/schemas/integration-mapping-slack-create-request.d.ts +12 -0
- package/lib-esm/schemas/integration-mapping-slack-create-request.js +3 -0
- package/lib-esm/schemas/integration-mapping-slack-create-request.js.map +1 -0
- package/lib-esm/schemas/integration-mapping-slack-options.d.ts +16 -0
- package/lib-esm/schemas/integration-mapping-slack-options.js +3 -0
- package/lib-esm/schemas/integration-mapping-slack-options.js.map +1 -0
- package/lib-esm/schemas/integration-mapping.d.ts +55 -0
- package/lib-esm/schemas/integration-mapping.js +3 -0
- package/lib-esm/schemas/integration-mapping.js.map +1 -0
- package/lib-esm/schemas/integration-mappings.d.ts +27 -0
- package/lib-esm/schemas/integration-mappings.js +3 -0
- package/lib-esm/schemas/integration-mappings.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-base.generated.d.ts +18 -0
- package/lib-esm/schemas/shield-information-barrier-base.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-base.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-reference.generated.d.ts +9 -0
- package/lib-esm/schemas/shield-information-barrier-reference.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-reference.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-report-base.generated.d.ts +18 -0
- package/lib-esm/schemas/shield-information-barrier-report-base.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-report-base.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-report-details.generated.d.ts +9 -0
- package/lib-esm/schemas/shield-information-barrier-report-details.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-report-details.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-report.generated.d.ts +32 -0
- package/lib-esm/schemas/shield-information-barrier-report.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-report.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-reports.generated.d.ts +26 -0
- package/lib-esm/schemas/shield-information-barrier-reports.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-reports.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member-base.generated.d.ts +19 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member-base.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member-base.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member-mini.generated.d.ts +13 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member-mini.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member-mini.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member.generated.d.ts +39 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-member.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-members.generated.d.ts +26 -0
- package/lib-esm/schemas/shield-information-barrier-segment-members.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-members.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction-base.generated.d.ts +20 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction-base.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction-base.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction-mini.generated.d.ts +20 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction-mini.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction-mini.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction.generated.d.ts +33 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restriction.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restrictions.generated.d.ts +26 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restrictions.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment-restrictions.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segment.generated.d.ts +50 -0
- package/lib-esm/schemas/shield-information-barrier-segment.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segment.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier-segments.generated.d.ts +26 -0
- package/lib-esm/schemas/shield-information-barrier-segments.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier-segments.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barrier.generated.d.ts +56 -0
- package/lib-esm/schemas/shield-information-barrier.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barrier.generated.js.map +1 -0
- package/lib-esm/schemas/shield-information-barriers.generated.d.ts +25 -0
- package/lib-esm/schemas/shield-information-barriers.generated.js +3 -0
- package/lib-esm/schemas/shield-information-barriers.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request-base.generated.d.ts +78 -0
- package/lib-esm/schemas/sign-request-base.generated.js +3 -0
- package/lib-esm/schemas/sign-request-base.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request-create-request.generated.d.ts +39 -0
- package/lib-esm/schemas/sign-request-create-request.generated.js +3 -0
- package/lib-esm/schemas/sign-request-create-request.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request-create-signer.generated.d.ts +95 -0
- package/lib-esm/schemas/sign-request-create-signer.generated.js +3 -0
- package/lib-esm/schemas/sign-request-create-signer.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request-prefill-tag.generated.d.ts +28 -0
- package/lib-esm/schemas/sign-request-prefill-tag.generated.js +3 -0
- package/lib-esm/schemas/sign-request-prefill-tag.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request-signer-input.generated.d.ts +28 -0
- package/lib-esm/schemas/sign-request-signer-input.generated.js +3 -0
- package/lib-esm/schemas/sign-request-signer-input.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request-signer.generated.d.ts +34 -0
- package/lib-esm/schemas/sign-request-signer.generated.js +3 -0
- package/lib-esm/schemas/sign-request-signer.generated.js.map +1 -0
- package/lib-esm/schemas/sign-request.generated.d.ts +72 -0
- package/lib-esm/schemas/sign-request.generated.js +3 -0
- package/lib-esm/schemas/sign-request.generated.js.map +1 -0
- package/lib-esm/schemas/sign-requests.generated.d.ts +25 -0
- package/lib-esm/schemas/sign-requests.generated.js +3 -0
- package/lib-esm/schemas/sign-requests.generated.js.map +1 -0
- package/lib-esm/schemas/sign-template.generated.d.ts +94 -0
- package/lib-esm/schemas/sign-template.generated.js +3 -0
- package/lib-esm/schemas/sign-template.generated.js.map +1 -0
- package/lib-esm/schemas/sign-templates.generated.d.ts +30 -0
- package/lib-esm/schemas/sign-templates.generated.js +3 -0
- package/lib-esm/schemas/sign-templates.generated.js.map +1 -0
- package/lib-esm/schemas/template-signer-input.generated.d.ts +61 -0
- package/lib-esm/schemas/template-signer-input.generated.js +3 -0
- package/lib-esm/schemas/template-signer-input.generated.js.map +1 -0
- package/lib-esm/schemas/template-signer.generated.d.ts +43 -0
- package/lib-esm/schemas/template-signer.generated.js +3 -0
- package/lib-esm/schemas/template-signer.generated.js.map +1 -0
- package/lib-esm/schemas/user-base.generated.d.ts +18 -0
- package/lib-esm/schemas/user-base.generated.js +3 -0
- package/lib-esm/schemas/user-base.generated.js.map +1 -0
- package/lib-esm/schemas/user-integration-mappings.d.ts +19 -0
- package/lib-esm/schemas/user-integration-mappings.js +3 -0
- package/lib-esm/schemas/user-integration-mappings.js.map +1 -0
- package/lib-esm/schemas/user-mini.d.ts +6 -0
- package/lib-esm/schemas/user-mini.js +3 -0
- package/lib-esm/schemas/user-mini.js.map +1 -0
- package/lib-esm/sessions/app-auth-session.d.ts +92 -0
- package/lib-esm/sessions/app-auth-session.js +176 -0
- package/lib-esm/sessions/app-auth-session.js.map +1 -0
- package/lib-esm/sessions/basic-session.d.ts +55 -0
- package/lib-esm/sessions/basic-session.js +62 -0
- package/lib-esm/sessions/basic-session.js.map +1 -0
- package/lib-esm/sessions/ccg-session.d.ts +72 -0
- package/lib-esm/sessions/ccg-session.js +111 -0
- package/lib-esm/sessions/ccg-session.js.map +1 -0
- package/lib-esm/sessions/persistent-session.d.ts +96 -0
- package/lib-esm/sessions/persistent-session.js +234 -0
- package/lib-esm/sessions/persistent-session.js.map +1 -0
- package/lib-esm/token-manager.d.ts +191 -0
- package/lib-esm/token-manager.js +453 -0
- package/lib-esm/token-manager.js.map +1 -0
- package/lib-esm/util/config.d.ts +85 -0
- package/lib-esm/util/config.js +212 -0
- package/lib-esm/util/config.js.map +1 -0
- package/lib-esm/util/errors.d.ts +50 -0
- package/lib-esm/util/errors.js +176 -0
- package/lib-esm/util/errors.js.map +1 -0
- package/lib-esm/util/exponential-backoff.d.ts +11 -0
- package/lib-esm/util/exponential-backoff.js +17 -0
- package/lib-esm/util/exponential-backoff.js.map +1 -0
- package/lib-esm/util/paging-iterator.d.ts +53 -0
- package/lib-esm/util/paging-iterator.js +247 -0
- package/lib-esm/util/paging-iterator.js.map +1 -0
- package/lib-esm/util/serializable.d.ts +10 -0
- package/lib-esm/util/serializable.js +17 -0
- package/lib-esm/util/serializable.js.map +1 -0
- package/lib-esm/util/url-path.d.ts +16 -0
- package/lib-esm/util/url-path.js +36 -0
- package/lib-esm/util/url-path.js.map +1 -0
- package/package.json +18 -4
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview An Anonymous Box API Session.
|
|
3
|
+
*/
|
|
4
|
+
type Config = any;
|
|
5
|
+
type TokenManager = any;
|
|
6
|
+
type TokenInfo = any;
|
|
7
|
+
type TokenRequestOptions = any;
|
|
8
|
+
/**
|
|
9
|
+
* The Client Credentials Grant Box API Session.
|
|
10
|
+
*
|
|
11
|
+
* The Client Credentials Grant API Session holds a Client Credentials accessToken, which it
|
|
12
|
+
* returns to the client so that it may make calls on behalf of service account or specified users.
|
|
13
|
+
*
|
|
14
|
+
* Tokens will be refreshed in the background if a request is made within the
|
|
15
|
+
* "stale buffer" (defaults to 10 minutes before the token is set to expire).
|
|
16
|
+
* If the token is also expired, all incoming requests will be held until a fresh token
|
|
17
|
+
* is retrieved.
|
|
18
|
+
*
|
|
19
|
+
* @param {Config} config The SDK configuration options
|
|
20
|
+
* @param {TokenManager} tokenManager The TokenManager
|
|
21
|
+
* @constructor
|
|
22
|
+
*/
|
|
23
|
+
declare class CCGSession {
|
|
24
|
+
_config: Config;
|
|
25
|
+
_tokenManager: TokenManager;
|
|
26
|
+
_tokenInfo: TokenInfo;
|
|
27
|
+
_refreshPromise: Promise<any> | null;
|
|
28
|
+
constructor(config: Config, tokenManager: TokenManager);
|
|
29
|
+
/**
|
|
30
|
+
* Initiate a refresh of the access tokens. New tokens should be passed to the
|
|
31
|
+
* caller, and then cached for later use.
|
|
32
|
+
*
|
|
33
|
+
* @param {?TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
34
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
_refreshAccessToken(options?: TokenRequestOptions): Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Produces a valid, anonymous access token.
|
|
40
|
+
* Performs a refresh before returning if the current token is expired. If the current
|
|
41
|
+
* token is considered stale but still valid, return the current token but initiate a
|
|
42
|
+
* new refresh in the background.
|
|
43
|
+
*
|
|
44
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
45
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
46
|
+
*/
|
|
47
|
+
getAccessToken(options?: TokenRequestOptions): Promise<any>;
|
|
48
|
+
/**
|
|
49
|
+
* Revokes the anonymous token used by this anonymous session, and clears the saved tokenInfo.
|
|
50
|
+
*
|
|
51
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
52
|
+
* @returns {Promise} Promise resolving if the revoke succeeds
|
|
53
|
+
*/
|
|
54
|
+
revokeTokens(options?: TokenRequestOptions): any;
|
|
55
|
+
/**
|
|
56
|
+
* Exchange the client access token for one with lower scope
|
|
57
|
+
*
|
|
58
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
59
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
60
|
+
* @param {Object} [options] - Optional parameters
|
|
61
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
exchangeToken(scopes: string | string[], resource?: string, options?: {
|
|
65
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
66
|
+
}): Promise<any>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @module box-node-sdk/lib/sessions/ccg-session
|
|
70
|
+
* @see {@Link CCGSession}
|
|
71
|
+
*/
|
|
72
|
+
export = CCGSession;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview An Anonymous Box API Session.
|
|
4
|
+
*/
|
|
5
|
+
// ------------------------------------------------------------------------------
|
|
6
|
+
// Requirements
|
|
7
|
+
// ------------------------------------------------------------------------------
|
|
8
|
+
const bluebird_1 = require("bluebird");
|
|
9
|
+
// ------------------------------------------------------------------------------
|
|
10
|
+
// Private
|
|
11
|
+
// ------------------------------------------------------------------------------
|
|
12
|
+
// ------------------------------------------------------------------------------
|
|
13
|
+
// Public
|
|
14
|
+
// ------------------------------------------------------------------------------
|
|
15
|
+
/**
|
|
16
|
+
* The Client Credentials Grant Box API Session.
|
|
17
|
+
*
|
|
18
|
+
* The Client Credentials Grant API Session holds a Client Credentials accessToken, which it
|
|
19
|
+
* returns to the client so that it may make calls on behalf of service account or specified users.
|
|
20
|
+
*
|
|
21
|
+
* Tokens will be refreshed in the background if a request is made within the
|
|
22
|
+
* "stale buffer" (defaults to 10 minutes before the token is set to expire).
|
|
23
|
+
* If the token is also expired, all incoming requests will be held until a fresh token
|
|
24
|
+
* is retrieved.
|
|
25
|
+
*
|
|
26
|
+
* @param {Config} config The SDK configuration options
|
|
27
|
+
* @param {TokenManager} tokenManager The TokenManager
|
|
28
|
+
* @constructor
|
|
29
|
+
*/
|
|
30
|
+
class CCGSession {
|
|
31
|
+
constructor(config, tokenManager) {
|
|
32
|
+
this._config = config;
|
|
33
|
+
this._tokenManager = tokenManager;
|
|
34
|
+
// The TokenInfo object for this anonymous session
|
|
35
|
+
this._tokenInfo = null;
|
|
36
|
+
this._refreshPromise = null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Initiate a refresh of the access tokens. New tokens should be passed to the
|
|
40
|
+
* caller, and then cached for later use.
|
|
41
|
+
*
|
|
42
|
+
* @param {?TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
43
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
_refreshAccessToken(options) {
|
|
47
|
+
// If tokens aren't already being refreshed, start the refresh
|
|
48
|
+
if (!this._refreshPromise) {
|
|
49
|
+
// Initiate a refresh
|
|
50
|
+
this._refreshPromise = this._tokenManager
|
|
51
|
+
.getTokensClientCredentialsGrant(options)
|
|
52
|
+
.then((tokenInfo) => {
|
|
53
|
+
// Set new token info and propagate the new access token
|
|
54
|
+
this._tokenInfo = tokenInfo;
|
|
55
|
+
return tokenInfo.accessToken;
|
|
56
|
+
})
|
|
57
|
+
.finally(() => {
|
|
58
|
+
// Refresh complete, clear promise
|
|
59
|
+
this._refreshPromise = null;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return this._refreshPromise;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Produces a valid, anonymous access token.
|
|
66
|
+
* Performs a refresh before returning if the current token is expired. If the current
|
|
67
|
+
* token is considered stale but still valid, return the current token but initiate a
|
|
68
|
+
* new refresh in the background.
|
|
69
|
+
*
|
|
70
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
71
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
72
|
+
*/
|
|
73
|
+
getAccessToken(options) {
|
|
74
|
+
// If the current token is no longer fresh, get a new token. All incoming
|
|
75
|
+
// requests will be held until a fresh token is retrieved.
|
|
76
|
+
var expirationBuffer = this._config.expiredBufferMS;
|
|
77
|
+
if (!this._tokenInfo ||
|
|
78
|
+
!this._tokenManager.isAccessTokenValid(this._tokenInfo, expirationBuffer)) {
|
|
79
|
+
return this._refreshAccessToken(options);
|
|
80
|
+
}
|
|
81
|
+
// Your token is not currently stale! Return the current access token.
|
|
82
|
+
return bluebird_1.Promise.resolve(this._tokenInfo.accessToken);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Revokes the anonymous token used by this anonymous session, and clears the saved tokenInfo.
|
|
86
|
+
*
|
|
87
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
88
|
+
* @returns {Promise} Promise resolving if the revoke succeeds
|
|
89
|
+
*/
|
|
90
|
+
revokeTokens(options) {
|
|
91
|
+
// The current anonymous token is revoked (but a new one will be created automatically as needed).
|
|
92
|
+
var tokenInfo = this._tokenInfo || {}, accessToken = tokenInfo.accessToken;
|
|
93
|
+
this._tokenInfo = null;
|
|
94
|
+
return this._tokenManager.revokeTokens(accessToken, options);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Exchange the client access token for one with lower scope
|
|
98
|
+
*
|
|
99
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
100
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
101
|
+
* @param {Object} [options] - Optional parameters
|
|
102
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
103
|
+
* @returns {void}
|
|
104
|
+
*/
|
|
105
|
+
exchangeToken(scopes, resource, options) {
|
|
106
|
+
// We need to get the access token, in case it hasn't been generated yet
|
|
107
|
+
return this.getAccessToken(options).then((accessToken) => this._tokenManager.exchangeToken(accessToken, scopes, resource, options));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
module.exports = CCGSession;
|
|
111
|
+
//# sourceMappingURL=ccg-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ccg-session.js","sourceRoot":"","sources":["../../src/sessions/ccg-session.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,uCAAmC;AAWnC,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF,iFAAiF;AACjF,SAAS;AACT,iFAAiF;AAEjF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU;IAMd,YAAY,MAAc,EAAE,YAA0B;QACpD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAElC,kDAAkD;QAClD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;;;;;OAOG;IACH,mBAAmB,CAAC,OAA6B;QAC/C,8DAA8D;QAC9D,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1B,qBAAqB;YACrB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,aAAa;iBACtC,+BAA+B,CAAC,OAAO,CAAC;iBACxC,IAAI,CAAC,CAAC,SAAoB,EAAE,EAAE;gBAC7B,wDAAwD;gBACxD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;gBAC5B,OAAO,SAAS,CAAC,WAAW,CAAC;YAC/B,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,kCAAkC;gBAClC,IAAI,CAAC,eAAe,GAAG,IA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
*/
|
|
4
|
+
type TokenInfo = any;
|
|
5
|
+
type TokenStore = any;
|
|
6
|
+
type Config = any;
|
|
7
|
+
type TokenManager = any;
|
|
8
|
+
type TokenRequestOptions = Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* A Persistent API Session has the ability to refresh its access token once it becomes expired.
|
|
11
|
+
* It takes in a full tokenInfo object for authentication. It can detect when its tokens have
|
|
12
|
+
* expired and will request new, valid tokens if needed. It can also interface with a token
|
|
13
|
+
* data-store if one is provided.
|
|
14
|
+
*
|
|
15
|
+
* Persistent API Session a good choice for long-running applications or web servers that
|
|
16
|
+
* must remember users across sessions.
|
|
17
|
+
*
|
|
18
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object. Will throw if improperly formatted.
|
|
19
|
+
* @param {TokenStore} [tokenStore] A valid TokenStore object. Will throw if improperly formatted.
|
|
20
|
+
* @param {Config} config The SDK configuration options
|
|
21
|
+
* @param {TokenManager} tokenManager The token manager
|
|
22
|
+
* @constructor
|
|
23
|
+
*/
|
|
24
|
+
declare class PersistentSession {
|
|
25
|
+
_config: Config;
|
|
26
|
+
_refreshPromise: Promise<any> | null;
|
|
27
|
+
_tokenManager: TokenManager;
|
|
28
|
+
_tokenStore: TokenStore;
|
|
29
|
+
_tokenInfo: TokenInfo;
|
|
30
|
+
constructor(tokenInfo: TokenInfo, tokenStore: TokenStore, config: Config, tokenManager: TokenManager);
|
|
31
|
+
/**
|
|
32
|
+
* Sets all relevant token info for this client.
|
|
33
|
+
*
|
|
34
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object.
|
|
35
|
+
* @returns {void}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
_setTokenInfo(tokenInfo: TokenStore): void;
|
|
39
|
+
/**
|
|
40
|
+
* Attempts to refresh tokens for the client.
|
|
41
|
+
* Will use the Box refresh token grant to complete the refresh. On refresh failure, we'll
|
|
42
|
+
* check the token store for more recently updated tokens and load them if found. Otherwise
|
|
43
|
+
* an error will be propagated.
|
|
44
|
+
*
|
|
45
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
46
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
_refreshTokens(options?: TokenRequestOptions): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the clients access token.
|
|
52
|
+
*
|
|
53
|
+
* If tokens don't yet exist, first attempt to retrieve them.
|
|
54
|
+
* If tokens are expired, first attempt to refresh them.
|
|
55
|
+
*
|
|
56
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
57
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
58
|
+
*/
|
|
59
|
+
getAccessToken(options?: TokenRequestOptions): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Revokes the session's tokens. If the session has a refresh token we'll use that,
|
|
62
|
+
* since it is more likely to be up to date. Otherwise, we'll revoke the accessToken.
|
|
63
|
+
* Revoking either one will disable the other as well.
|
|
64
|
+
*
|
|
65
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
66
|
+
* @returns {Promise} Promise that resolves when the revoke succeeds
|
|
67
|
+
*/
|
|
68
|
+
revokeTokens(options?: TokenRequestOptions): any;
|
|
69
|
+
/**
|
|
70
|
+
* Exchange the client access token for one with lower scope
|
|
71
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
72
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
73
|
+
* @param {Object} [options] - Optional parameters
|
|
74
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
exchangeToken(scopes: string | string[], resource?: string, options?: {
|
|
78
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
79
|
+
}): Promise<any>;
|
|
80
|
+
/**
|
|
81
|
+
* Handle an an "Expired Tokens" Error. If our tokens are expired, we need to clear the token
|
|
82
|
+
* store (if present) before continuing.
|
|
83
|
+
*
|
|
84
|
+
* @param {Errors~ExpiredTokensError} err An "expired tokens" error including information
|
|
85
|
+
* about the request/response.
|
|
86
|
+
* @returns {Promise<Error>} Promise resolving to an error. This will
|
|
87
|
+
* usually be the original response error, but could an error from trying to access the
|
|
88
|
+
* token store as well.
|
|
89
|
+
*/
|
|
90
|
+
handleExpiredTokensError(err: any): any;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @module box-node-sdk/lib/sessions/persistent-session
|
|
94
|
+
* @see {@Link PersistentSession}
|
|
95
|
+
*/
|
|
96
|
+
export = PersistentSession;
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview A Persistent Box API Session.
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
// ------------------------------------------------------------------------------
|
|
9
|
+
// Requirements
|
|
10
|
+
// ------------------------------------------------------------------------------
|
|
11
|
+
const assert_1 = __importDefault(require("assert"));
|
|
12
|
+
const bluebird_1 = require("bluebird");
|
|
13
|
+
const http_status_1 = __importDefault(require("http-status"));
|
|
14
|
+
const errors_1 = __importDefault(require("../util/errors"));
|
|
15
|
+
// ------------------------------------------------------------------------------
|
|
16
|
+
// Private
|
|
17
|
+
// ------------------------------------------------------------------------------
|
|
18
|
+
/**
|
|
19
|
+
* Validate that an object is a valid TokenInfo object
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} obj The object to validate
|
|
22
|
+
* @returns {boolean} True if the passed in object is a valid TokenInfo object that
|
|
23
|
+
* has all the expected properties, false otherwise
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
function isObjectValidTokenInfo(obj) {
|
|
27
|
+
return Boolean(obj &&
|
|
28
|
+
obj.accessToken &&
|
|
29
|
+
obj.refreshToken &&
|
|
30
|
+
obj.accessTokenTTLMS &&
|
|
31
|
+
obj.acquiredAtMS);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validate that an object is a valid TokenStore object
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} obj the object to validate
|
|
37
|
+
* @returns {boolean} returns true if the passed in object is a valid TokenStore object that
|
|
38
|
+
* has all the expected properties. false otherwise.
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
function isObjectValidTokenStore(obj) {
|
|
42
|
+
return Boolean(obj && obj.read && obj.write && obj.clear);
|
|
43
|
+
}
|
|
44
|
+
// ------------------------------------------------------------------------------
|
|
45
|
+
// Public
|
|
46
|
+
// ------------------------------------------------------------------------------
|
|
47
|
+
/**
|
|
48
|
+
* A Persistent API Session has the ability to refresh its access token once it becomes expired.
|
|
49
|
+
* It takes in a full tokenInfo object for authentication. It can detect when its tokens have
|
|
50
|
+
* expired and will request new, valid tokens if needed. It can also interface with a token
|
|
51
|
+
* data-store if one is provided.
|
|
52
|
+
*
|
|
53
|
+
* Persistent API Session a good choice for long-running applications or web servers that
|
|
54
|
+
* must remember users across sessions.
|
|
55
|
+
*
|
|
56
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object. Will throw if improperly formatted.
|
|
57
|
+
* @param {TokenStore} [tokenStore] A valid TokenStore object. Will throw if improperly formatted.
|
|
58
|
+
* @param {Config} config The SDK configuration options
|
|
59
|
+
* @param {TokenManager} tokenManager The token manager
|
|
60
|
+
* @constructor
|
|
61
|
+
*/
|
|
62
|
+
class PersistentSession {
|
|
63
|
+
constructor(tokenInfo, tokenStore, config, tokenManager) {
|
|
64
|
+
this._config = config;
|
|
65
|
+
this._tokenManager = tokenManager;
|
|
66
|
+
// Keeps track of if tokens are currently being refreshed
|
|
67
|
+
this._refreshPromise = null;
|
|
68
|
+
// Set valid PersistentSession credentials. Throw if expected credentials are invalid or not given.
|
|
69
|
+
(0, assert_1.default)(isObjectValidTokenInfo(tokenInfo), 'tokenInfo is improperly formatted. Properties required: accessToken, refreshToken, accessTokenTTLMS and acquiredAtMS.');
|
|
70
|
+
this._setTokenInfo(tokenInfo);
|
|
71
|
+
// If tokenStore was provided, set the persistent data & current store operations
|
|
72
|
+
if (tokenStore) {
|
|
73
|
+
(0, assert_1.default)(isObjectValidTokenStore(tokenStore), 'Token store provided but is improperly formatted. Methods required: read(), write(), clear().');
|
|
74
|
+
this._tokenStore = bluebird_1.Promise.promisifyAll(tokenStore);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sets all relevant token info for this client.
|
|
79
|
+
*
|
|
80
|
+
* @param {TokenInfo} tokenInfo A valid TokenInfo object.
|
|
81
|
+
* @returns {void}
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
_setTokenInfo(tokenInfo) {
|
|
85
|
+
this._tokenInfo = {
|
|
86
|
+
accessToken: tokenInfo.accessToken,
|
|
87
|
+
refreshToken: tokenInfo.refreshToken,
|
|
88
|
+
accessTokenTTLMS: tokenInfo.accessTokenTTLMS,
|
|
89
|
+
acquiredAtMS: tokenInfo.acquiredAtMS,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Attempts to refresh tokens for the client.
|
|
94
|
+
* Will use the Box refresh token grant to complete the refresh. On refresh failure, we'll
|
|
95
|
+
* check the token store for more recently updated tokens and load them if found. Otherwise
|
|
96
|
+
* an error will be propagated.
|
|
97
|
+
*
|
|
98
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
99
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
_refreshTokens(options) {
|
|
103
|
+
// If not already refreshing, kick off a token refresh request and set a lock so that additional
|
|
104
|
+
// client requests don't try as well
|
|
105
|
+
if (!this._refreshPromise) {
|
|
106
|
+
this._refreshPromise = this._tokenManager
|
|
107
|
+
.getTokensRefreshGrant(this._tokenInfo.refreshToken, options)
|
|
108
|
+
.catch((err) => {
|
|
109
|
+
// If we got an error response from Box API, but it was 400 invalid_grant, it indicates we may have just
|
|
110
|
+
// made the request with an invalidated refresh token. Since only a max of 2 refresh tokens can be valid
|
|
111
|
+
// at any point in time, and a horizontally scaled app could have multiple Node instances running in parallel,
|
|
112
|
+
// it is possible to hit cases where too many servers all refresh a user's tokens at once
|
|
113
|
+
// and cause this server's token to become invalidated. However, the user should still be alive, but
|
|
114
|
+
// we'll need to check the central data store for the latest valid tokens that some other server in the app
|
|
115
|
+
// cluster would have received. So, instead pull tokens from the central store and attempt to use them.
|
|
116
|
+
if (err.statusCode === http_status_1.default.BAD_REQUEST &&
|
|
117
|
+
this._tokenStore) {
|
|
118
|
+
var invalidGrantError = err;
|
|
119
|
+
// Check the tokenStore to see if tokens have been updated recently. If they have, then another
|
|
120
|
+
// instance of the session may have already refreshed the user tokens, which would explain why
|
|
121
|
+
// we couldn't refresh.
|
|
122
|
+
return this._tokenStore
|
|
123
|
+
.readAsync()
|
|
124
|
+
.catch((e) => errors_1.default.unwrapAndThrow(e))
|
|
125
|
+
.then((storeTokenInfo) => {
|
|
126
|
+
// if the tokens we got from the central store are the same as the tokens we made the failed request with
|
|
127
|
+
// already, then we can be sure that no other servers have valid tokens for this server either.
|
|
128
|
+
// Thus, this user truly has an expired refresh token. So, propagate an "Expired Tokens" error.
|
|
129
|
+
if (!storeTokenInfo ||
|
|
130
|
+
storeTokenInfo.refreshToken === this._tokenInfo.refreshToken) {
|
|
131
|
+
throw errors_1.default.buildAuthError(invalidGrantError.response);
|
|
132
|
+
}
|
|
133
|
+
// Propagate the fresh tokens that we found in the session
|
|
134
|
+
return storeTokenInfo;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// Box API returned a permanent error that is not retryable and we can't recover.
|
|
138
|
+
// We have no usable tokens for the user and no way to refresh them - propagate a permanent error.
|
|
139
|
+
throw err;
|
|
140
|
+
})
|
|
141
|
+
.then((tokenInfo) => {
|
|
142
|
+
// Success! We got back a TokenInfo object from the API.
|
|
143
|
+
// If we have a token store, we'll write it there now before finishing up the request.
|
|
144
|
+
if (this._tokenStore) {
|
|
145
|
+
return this._tokenStore
|
|
146
|
+
.writeAsync(tokenInfo)
|
|
147
|
+
.catch((e) => errors_1.default.unwrapAndThrow(e))
|
|
148
|
+
.then(() => tokenInfo);
|
|
149
|
+
}
|
|
150
|
+
// If no token store, Set and propagate the access token immediately
|
|
151
|
+
return tokenInfo;
|
|
152
|
+
})
|
|
153
|
+
.then((tokenInfo) => {
|
|
154
|
+
// Set and propagate the new access token
|
|
155
|
+
this._setTokenInfo(tokenInfo);
|
|
156
|
+
return tokenInfo.accessToken;
|
|
157
|
+
})
|
|
158
|
+
.catch((err) => this.handleExpiredTokensError(err))
|
|
159
|
+
.finally(() => {
|
|
160
|
+
// Refresh complete, clear promise
|
|
161
|
+
this._refreshPromise = null;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return this._refreshPromise;
|
|
165
|
+
}
|
|
166
|
+
// ------------------------------------------------------------------------------
|
|
167
|
+
// Public Instance
|
|
168
|
+
// ------------------------------------------------------------------------------
|
|
169
|
+
/**
|
|
170
|
+
* Returns the clients access token.
|
|
171
|
+
*
|
|
172
|
+
* If tokens don't yet exist, first attempt to retrieve them.
|
|
173
|
+
* If tokens are expired, first attempt to refresh them.
|
|
174
|
+
*
|
|
175
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
176
|
+
* @returns {Promise<string>} Promise resolving to the access token
|
|
177
|
+
*/
|
|
178
|
+
getAccessToken(options) {
|
|
179
|
+
// If our tokens are not fresh, we need to refresh them
|
|
180
|
+
const expirationBuffer = this._config.expiredBufferMS;
|
|
181
|
+
if (!this._tokenManager.isAccessTokenValid(this._tokenInfo, expirationBuffer)) {
|
|
182
|
+
return this._refreshTokens(options);
|
|
183
|
+
}
|
|
184
|
+
// Current access token is still valid. Return it.
|
|
185
|
+
return bluebird_1.Promise.resolve(this._tokenInfo.accessToken);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Revokes the session's tokens. If the session has a refresh token we'll use that,
|
|
189
|
+
* since it is more likely to be up to date. Otherwise, we'll revoke the accessToken.
|
|
190
|
+
* Revoking either one will disable the other as well.
|
|
191
|
+
*
|
|
192
|
+
* @param {TokenRequestOptions} [options] - Sets optional behavior for the token grant
|
|
193
|
+
* @returns {Promise} Promise that resolves when the revoke succeeds
|
|
194
|
+
*/
|
|
195
|
+
revokeTokens(options) {
|
|
196
|
+
return this._tokenManager.revokeTokens(this._tokenInfo.refreshToken, options);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Exchange the client access token for one with lower scope
|
|
200
|
+
* @param {string|string[]} scopes The scope(s) requested for the new token
|
|
201
|
+
* @param {string} [resource] The absolute URL of an API resource to scope the new token to
|
|
202
|
+
* @param {Object} [options] - Optional parameters
|
|
203
|
+
* @param {TokenRequestOptions} [options.tokenRequestOptions] - Sets optional behavior for the token grant
|
|
204
|
+
* @returns {void}
|
|
205
|
+
*/
|
|
206
|
+
exchangeToken(scopes, resource, options) {
|
|
207
|
+
return this.getAccessToken(options).then((accessToken) => this._tokenManager.exchangeToken(accessToken, scopes, resource, options));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Handle an an "Expired Tokens" Error. If our tokens are expired, we need to clear the token
|
|
211
|
+
* store (if present) before continuing.
|
|
212
|
+
*
|
|
213
|
+
* @param {Errors~ExpiredTokensError} err An "expired tokens" error including information
|
|
214
|
+
* about the request/response.
|
|
215
|
+
* @returns {Promise<Error>} Promise resolving to an error. This will
|
|
216
|
+
* usually be the original response error, but could an error from trying to access the
|
|
217
|
+
* token store as well.
|
|
218
|
+
*/
|
|
219
|
+
handleExpiredTokensError(err /* FIXME */) {
|
|
220
|
+
if (!this._tokenStore) {
|
|
221
|
+
return bluebird_1.Promise.resolve(err);
|
|
222
|
+
}
|
|
223
|
+
// If a token store is available, clear the store and throw either error
|
|
224
|
+
// eslint-disable-next-line promise/no-promise-in-callback
|
|
225
|
+
return this._tokenStore
|
|
226
|
+
.clearAsync()
|
|
227
|
+
.catch((e) => errors_1.default.unwrapAndThrow(e))
|
|
228
|
+
.then(() => {
|
|
229
|
+
throw err;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
module.exports = PersistentSession;
|
|
234
|
+
//# sourceMappingURL=persistent-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistent-session.js","sourceRoot":"","sources":["../../src/sessions/persistent-session.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,oDAA4B;AAC5B,uCAAmC;AACnC,8DAA0C;AAC1C,4DAAoC;AAYpC,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF;;;;;;;GAOG;AACH,SAAS,sBAAsB,CAAC,GAAwB;IACtD,OAAO,OAAO,CACZ,GAAG;QACD,GAAG,CAAC,WAAW;QACf,GAAG,CAAC,YAAY;QAChB,GAAG,CAAC,gBAAgB;QACpB,GAAG,CAAC,YAAY,CACnB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAAC,GAAwB;IACvD,OAAO,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED,iFAAiF;AACjF,SAAS;AACT,iFAAiF;AAEjF;;;;;;;;;;;;;;GAcG;AACH,MAAM,iBAAiB;IAOrB,YACE,SAAoB,EACpB,UAAsB,EACtB,MAAc,EACd,YAA0B;QAE1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAElC,yDAAyD;QACzD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;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