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,1408 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Manager for the Box Files Resource
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
// ------------------------------------------------------------------------------
|
|
9
|
+
// Requirements
|
|
10
|
+
// ------------------------------------------------------------------------------
|
|
11
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
12
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
13
|
+
const http_status_1 = __importDefault(require("http-status"));
|
|
14
|
+
const stream_1 = require("stream");
|
|
15
|
+
const url_template_1 = __importDefault(require("url-template"));
|
|
16
|
+
const errors_1 = __importDefault(require("../util/errors"));
|
|
17
|
+
const url_path_1 = __importDefault(require("../util/url-path"));
|
|
18
|
+
const ChunkedUploader = require('../chunked-uploader');
|
|
19
|
+
// -----------------------------------------------------------------------------
|
|
20
|
+
// Typedefs
|
|
21
|
+
// -----------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Enum of valid x-rep- hint values for generating representation info
|
|
24
|
+
*
|
|
25
|
+
* @readonly
|
|
26
|
+
* @enum {FileRepresentationType}
|
|
27
|
+
*/
|
|
28
|
+
var FileRepresentationType;
|
|
29
|
+
(function (FileRepresentationType) {
|
|
30
|
+
FileRepresentationType["PDF"] = "[pdf]";
|
|
31
|
+
FileRepresentationType["THUMBNAIL"] = "[jpg?dimensions=320x320]";
|
|
32
|
+
FileRepresentationType["IMAGE_MEDIUM"] = "[jpg?dimensions=1024x1024][png?dimensions=1024x1024]";
|
|
33
|
+
FileRepresentationType["IMAGE_LARGE"] = "[jpg?dimensions=2048x2048][png?dimensions=2048x2048]";
|
|
34
|
+
FileRepresentationType["EXTRACTED_TEXT"] = "[extracted_text]";
|
|
35
|
+
})(FileRepresentationType || (FileRepresentationType = {}));
|
|
36
|
+
/**
|
|
37
|
+
* Enum of valid lock types
|
|
38
|
+
*
|
|
39
|
+
* @readonly
|
|
40
|
+
* @enum {LockType}
|
|
41
|
+
*/
|
|
42
|
+
var LockType;
|
|
43
|
+
(function (LockType) {
|
|
44
|
+
LockType["LOCK"] = "lock";
|
|
45
|
+
LockType["UNLOCK"] = "unlock";
|
|
46
|
+
})(LockType || (LockType = {}));
|
|
47
|
+
// -----------------------------------------------------------------------------
|
|
48
|
+
// Private
|
|
49
|
+
// -----------------------------------------------------------------------------
|
|
50
|
+
// Base path for all files endpoints
|
|
51
|
+
const BASE_PATH = '/files', VERSIONS_SUBRESOURCE = '/versions', WATERMARK_SUBRESOURCE = '/watermark', UPLOAD_SESSION_SUBRESOURCE = '/upload_sessions', ZIP_DOWNLOAD_PATH = '/zip_downloads';
|
|
52
|
+
/**
|
|
53
|
+
* Returns the multipart form value for file upload metadata.
|
|
54
|
+
* @param {string} parentFolderID - the ID of the parent folder to upload to
|
|
55
|
+
* @param {string} filename - the file name that the uploaded file should have
|
|
56
|
+
* @param {Object} [options] - Optional metadata
|
|
57
|
+
* @returns {Object} - the form value expected by the API for the 'metadata' key
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
function createFileMetadataFormData(parentFolderID, filename, options) {
|
|
61
|
+
// Although the filename and parent folder ID can be specified without using a
|
|
62
|
+
// metadata form field, Platform has recommended that we use the metadata form
|
|
63
|
+
// field to specify these parameters (one benefit is that UTF-8 characters can
|
|
64
|
+
// be specified in the filename).
|
|
65
|
+
var metadata = {
|
|
66
|
+
name: filename,
|
|
67
|
+
parent: { id: parentFolderID },
|
|
68
|
+
};
|
|
69
|
+
Object.assign(metadata, options);
|
|
70
|
+
return JSON.stringify(metadata);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the multipart form value for file upload content.
|
|
74
|
+
* @param {string|Buffer|Stream} content - the content of the file being uploaded
|
|
75
|
+
* @param {Object} options - options for the content
|
|
76
|
+
* @returns {Object} - the form value expected by the API for the 'content' key
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
function createFileContentFormData(content, options) {
|
|
80
|
+
// The upload API appears to look for a form field that contains a filename
|
|
81
|
+
// property and assume that this form field contains the file content. Thus,
|
|
82
|
+
// the value of name does not actually matter (as long as it does not conflict
|
|
83
|
+
// with other field names). Similarly, the value of options.filename does not
|
|
84
|
+
// matter either (as long as it exists), since the upload API will use the
|
|
85
|
+
// filename specified in the metadata form field instead.
|
|
86
|
+
return {
|
|
87
|
+
value: content,
|
|
88
|
+
options: Object.assign({ filename: 'unused' }, options),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Poll the representation info URL until representation is generated,
|
|
93
|
+
* then return content URL template.
|
|
94
|
+
* @param {BoxClient} client The client to use for making API calls
|
|
95
|
+
* @param {string} infoURL The URL to use for getting representation info
|
|
96
|
+
* @returns {Promise<string>} A promise resolving to the content URL template
|
|
97
|
+
*/
|
|
98
|
+
function pollRepresentationInfo(client, infoURL) {
|
|
99
|
+
return client.get(infoURL).then((response /* FIXME */) => {
|
|
100
|
+
if (response.statusCode !== 200) {
|
|
101
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
102
|
+
}
|
|
103
|
+
var info = response.body;
|
|
104
|
+
switch (info.status.state) {
|
|
105
|
+
case 'success':
|
|
106
|
+
case 'viewable':
|
|
107
|
+
case 'error':
|
|
108
|
+
return info;
|
|
109
|
+
case 'none':
|
|
110
|
+
case 'pending':
|
|
111
|
+
return bluebird_1.default.delay(1000).then(() => pollRepresentationInfo(client, infoURL));
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unknown representation status: ${info.status.state}`);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
// ------------------------------------------------------------------------------
|
|
118
|
+
// Public
|
|
119
|
+
// ------------------------------------------------------------------------------
|
|
120
|
+
/**
|
|
121
|
+
* Simple manager for interacting with all 'File' endpoints and actions.
|
|
122
|
+
*
|
|
123
|
+
* @param {BoxClient} client The Box API Client that is responsible for making calls to the API
|
|
124
|
+
* @constructor
|
|
125
|
+
*/
|
|
126
|
+
class Files {
|
|
127
|
+
constructor(client) {
|
|
128
|
+
// Attach the client, for making API calls
|
|
129
|
+
this.client = client;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Requests a file object with the given ID.
|
|
133
|
+
*
|
|
134
|
+
* API Endpoint: '/files/:fileID'
|
|
135
|
+
* Method: GET
|
|
136
|
+
*
|
|
137
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
138
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
139
|
+
* @param {Function} [callback] - Passed the file information if it was acquired successfully
|
|
140
|
+
* @returns {Promise<Object>} A promise resolving to the file object
|
|
141
|
+
*/
|
|
142
|
+
get(fileID, options, callback) {
|
|
143
|
+
var params = {
|
|
144
|
+
qs: options,
|
|
145
|
+
};
|
|
146
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID);
|
|
147
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Requests a download URL for a given file.
|
|
151
|
+
*
|
|
152
|
+
* API Endpoint: '/files/:fileID/content'
|
|
153
|
+
* Method: GET
|
|
154
|
+
* Special Expected Responses:
|
|
155
|
+
* 202 ACCEPTED - Download isn't available yet. Returns an error.
|
|
156
|
+
* 302 FOUND - Download is available. A Download URL is returned.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
159
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
160
|
+
* @param {Function} [callback] - Passed the download URL if request was successful.
|
|
161
|
+
* @returns {Promise<string>} A promise resolving to the file's download URL
|
|
162
|
+
*/
|
|
163
|
+
getDownloadURL(fileID, options, callback) {
|
|
164
|
+
var params = {
|
|
165
|
+
qs: options,
|
|
166
|
+
};
|
|
167
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/content');
|
|
168
|
+
// Handle Special API Response
|
|
169
|
+
return this.client
|
|
170
|
+
.get(apiPath, params)
|
|
171
|
+
.then((response /* FIXME */) => {
|
|
172
|
+
switch (response.statusCode) {
|
|
173
|
+
// 302 - Found
|
|
174
|
+
// No data returned, but the location header points to a download link for that file.
|
|
175
|
+
case http_status_1.default.FOUND:
|
|
176
|
+
return response.headers.location;
|
|
177
|
+
// 202 - Download isn't ready yet.
|
|
178
|
+
case http_status_1.default.ACCEPTED:
|
|
179
|
+
throw errors_1.default.buildResponseError(response, 'Download not ready at this time');
|
|
180
|
+
// Unexpected Response
|
|
181
|
+
default:
|
|
182
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
.asCallback(callback);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Requests a Readable Stream for the given file ID.
|
|
189
|
+
*
|
|
190
|
+
* API Endpoint: '/files/:fileID/content'
|
|
191
|
+
* Method: GET
|
|
192
|
+
* Special Expected Responses:
|
|
193
|
+
* 202 ACCEPTED - Download isn't available yet. Returns an error.
|
|
194
|
+
* 302 FOUND - Download is available. A Download stream is returned.
|
|
195
|
+
*
|
|
196
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
197
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
198
|
+
* @param {string} [options.version] - ID of the version of this file to download
|
|
199
|
+
* @param {int[]} [options.byteRange] - starting and ending bytes of the file to read, e.g. [0, 99] to read the first 100 bytes
|
|
200
|
+
* @param {Function} [callback] - passed the readable stream if request was successful
|
|
201
|
+
* @returns {Promise<Readable>} A promise resolving for the file stream
|
|
202
|
+
*/
|
|
203
|
+
getReadStream(fileID, options, callback) {
|
|
204
|
+
options = options || {};
|
|
205
|
+
var downloadStreamOptions = {
|
|
206
|
+
streaming: true,
|
|
207
|
+
headers: {},
|
|
208
|
+
};
|
|
209
|
+
if (options.byteRange) {
|
|
210
|
+
var range = options.byteRange;
|
|
211
|
+
delete options.byteRange;
|
|
212
|
+
downloadStreamOptions.headers.Range = `bytes=${range[0]}-${range[1]}`;
|
|
213
|
+
}
|
|
214
|
+
// Get the download URL to download from
|
|
215
|
+
return (this.getDownloadURL(fileID, options)
|
|
216
|
+
// Return a read stream to download the file
|
|
217
|
+
.then((url) => this.client.get(url, downloadStreamOptions))
|
|
218
|
+
.asCallback(callback));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets the comments on a file.
|
|
222
|
+
*
|
|
223
|
+
* API Endpoint: '/files/:fileID/comments'
|
|
224
|
+
* Method: GET
|
|
225
|
+
*
|
|
226
|
+
* @param {string} fileID - Box file id of the file
|
|
227
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
228
|
+
* @param {Function} [callback] - passed the file comments if they were successfully acquired
|
|
229
|
+
* @returns {Promise<Object>} A promise resolving to the collection of comments
|
|
230
|
+
*/
|
|
231
|
+
getComments(fileID, options, callback) {
|
|
232
|
+
var params = {
|
|
233
|
+
qs: options,
|
|
234
|
+
};
|
|
235
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/comments');
|
|
236
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Update some information about a given file.
|
|
240
|
+
*
|
|
241
|
+
* API Endpoint: '/files/:fileID'
|
|
242
|
+
* Method: PUT
|
|
243
|
+
*
|
|
244
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
245
|
+
* @param {Object} updates - File fields to update
|
|
246
|
+
* @param {string} [updates.etag] Only apply the updates if the file etag matches
|
|
247
|
+
* @param {string} [updates.fields] Comma-separated list of fields to return
|
|
248
|
+
* @param {Function} [callback] - Passed the updated file information if it was acquired successfully
|
|
249
|
+
* @returns {Promise<Object>} A promise resolving to the update file object
|
|
250
|
+
*/
|
|
251
|
+
update(fileID, updates, callback) {
|
|
252
|
+
var params = {
|
|
253
|
+
body: updates,
|
|
254
|
+
};
|
|
255
|
+
if (updates && updates.etag) {
|
|
256
|
+
params.headers = {
|
|
257
|
+
'If-Match': updates.etag,
|
|
258
|
+
};
|
|
259
|
+
delete updates.etag;
|
|
260
|
+
}
|
|
261
|
+
if (updates && updates.fields) {
|
|
262
|
+
params.qs = {
|
|
263
|
+
fields: updates.fields,
|
|
264
|
+
};
|
|
265
|
+
delete updates.fields;
|
|
266
|
+
}
|
|
267
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID);
|
|
268
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Add a file to a given collection
|
|
272
|
+
*
|
|
273
|
+
* API Endpoint: '/files/:fileID'
|
|
274
|
+
* Method: PUT
|
|
275
|
+
*
|
|
276
|
+
* @param {string} fileID - The file to add to the collection
|
|
277
|
+
* @param {string} collectionID - The collection to add the file to
|
|
278
|
+
* @param {Function} [callback] - Passed the updated file if successful, error otherwise
|
|
279
|
+
* @returns {Promise<Object>} A promise resolving to the updated file object
|
|
280
|
+
*/
|
|
281
|
+
addToCollection(fileID, collectionID, callback) {
|
|
282
|
+
return this.get(fileID, { fields: 'collections' })
|
|
283
|
+
.then((data) => {
|
|
284
|
+
var collections = data.collections || [];
|
|
285
|
+
// Convert to correct format
|
|
286
|
+
collections = collections.map((c /* FIXME */) => ({
|
|
287
|
+
id: c.id,
|
|
288
|
+
}));
|
|
289
|
+
if (!collections.find((c /* FIXME */) => c.id === collectionID)) {
|
|
290
|
+
collections.push({ id: collectionID });
|
|
291
|
+
}
|
|
292
|
+
return this.update(fileID, { collections });
|
|
293
|
+
})
|
|
294
|
+
.asCallback(callback);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Remove a file from a given collection
|
|
298
|
+
*
|
|
299
|
+
* API Endpoint: '/files/:fileID'
|
|
300
|
+
* Method: PUT
|
|
301
|
+
*
|
|
302
|
+
* @param {string} fileID - The file to remove from the collection
|
|
303
|
+
* @param {string} collectionID - The collection to remove the file from
|
|
304
|
+
* @param {Function} [callback] - Passed the updated file if successful, error otherwise
|
|
305
|
+
* @returns {Promise<Object>} A promise resolving to the updated file object
|
|
306
|
+
*/
|
|
307
|
+
removeFromCollection(fileID, collectionID, callback) {
|
|
308
|
+
return this.get(fileID, { fields: 'collections' })
|
|
309
|
+
.then((data /* FIXME */) => {
|
|
310
|
+
var collections = data.collections || [];
|
|
311
|
+
// Convert to correct object format and remove the specified collection
|
|
312
|
+
collections = collections
|
|
313
|
+
.map((c /* FIXME */) => ({ id: c.id }))
|
|
314
|
+
.filter((c /* FIXME */) => c.id !== collectionID);
|
|
315
|
+
return this.update(fileID, { collections });
|
|
316
|
+
})
|
|
317
|
+
.asCallback(callback);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Move a file into a new parent folder.
|
|
321
|
+
*
|
|
322
|
+
* API Endpoint: '/files/:fileID'
|
|
323
|
+
* Method: PUT
|
|
324
|
+
*
|
|
325
|
+
* @param {string} fileID - The Box ID of the file being requested
|
|
326
|
+
* @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
|
|
327
|
+
* @param {Function} [callback] - Passed the updated file information if it was acquired successfully
|
|
328
|
+
* @returns {Promise<Object>} A promise resolving to the updated file object
|
|
329
|
+
*/
|
|
330
|
+
move(fileID, newParentID, callback) {
|
|
331
|
+
var params = {
|
|
332
|
+
body: {
|
|
333
|
+
parent: {
|
|
334
|
+
id: newParentID,
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID);
|
|
339
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Copy a file into a new folder.
|
|
343
|
+
*
|
|
344
|
+
* API Endpoint: '/files/:fileID/copy
|
|
345
|
+
* Method: POST
|
|
346
|
+
*
|
|
347
|
+
* @param {string} fileID - The Box ID of the file being requested
|
|
348
|
+
* @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
|
|
349
|
+
* @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
|
|
350
|
+
* @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
|
|
351
|
+
* @param {string} [options.version] - An optional ID of the specific file version to copy
|
|
352
|
+
* @param {Function} [callback] - passed the new file info if call was successful
|
|
353
|
+
* @returns {Promise<Object>} A promise resolving to the new file object
|
|
354
|
+
*/
|
|
355
|
+
copy(fileID, newParentID, options, callback) {
|
|
356
|
+
// @NOTE(mwiller) 2016-10-25: Shuffle arguments to maintain backward compatibility
|
|
357
|
+
// This can be removed at the v2.0 update
|
|
358
|
+
if (typeof options === 'function') {
|
|
359
|
+
callback = options;
|
|
360
|
+
options = {};
|
|
361
|
+
}
|
|
362
|
+
options = options || {};
|
|
363
|
+
options.parent = {
|
|
364
|
+
id: newParentID,
|
|
365
|
+
};
|
|
366
|
+
var params = {
|
|
367
|
+
body: options,
|
|
368
|
+
};
|
|
369
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/copy');
|
|
370
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Delete a given file.
|
|
374
|
+
*
|
|
375
|
+
* API Endpoint: '/files/:fileID'
|
|
376
|
+
* Method: DELETE
|
|
377
|
+
*
|
|
378
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
379
|
+
* @param {Object} [options] Optional parameters
|
|
380
|
+
* @param {string} [options.etag] Only delete the file if the etag value matches
|
|
381
|
+
* @param {Function} [callback] - Empty response body passed if successful.
|
|
382
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
383
|
+
*/
|
|
384
|
+
delete(fileID, options, callback) {
|
|
385
|
+
// Switch around arguments if necessary for backwards compatibility
|
|
386
|
+
if (typeof options === 'function') {
|
|
387
|
+
callback = options;
|
|
388
|
+
options = {};
|
|
389
|
+
}
|
|
390
|
+
var params = {};
|
|
391
|
+
if (options && options.etag) {
|
|
392
|
+
params.headers = {
|
|
393
|
+
'If-Match': options.etag,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID);
|
|
397
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Get preflight information for a new file upload. Without any file data,
|
|
401
|
+
* this will return an upload URL and token to be used when uploading the file.
|
|
402
|
+
* Using this upload URL will allow for the fastest upload, and the one-time
|
|
403
|
+
* token can be passed to a worker or other client to actually perform the
|
|
404
|
+
* upload with. If file data (e.g. size, parent, name) is passed, it will be
|
|
405
|
+
* validated as if the actual file were being uploaded. This enables checking
|
|
406
|
+
* of preconditions such as name uniqueness and available storage space before
|
|
407
|
+
* attempting a large file upload.
|
|
408
|
+
*
|
|
409
|
+
* API Endpoint: '/files/content'
|
|
410
|
+
* Method: OPTIONS
|
|
411
|
+
*
|
|
412
|
+
* @param {string} parentFolderID - The id of the parent folder to upload to
|
|
413
|
+
* @param {Object} [fileData] - Optional data about the file to be uploaded
|
|
414
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
415
|
+
* @param {Function} [callback] - Called with upload data if successful, or err if the upload would not succeed
|
|
416
|
+
* @returns {Promise<Object>} A promise resolving to the upload data
|
|
417
|
+
*/
|
|
418
|
+
preflightUploadFile(parentFolderID, fileData, options, callback) {
|
|
419
|
+
var params = {
|
|
420
|
+
body: {
|
|
421
|
+
parent: {
|
|
422
|
+
id: parentFolderID,
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
qs: options,
|
|
426
|
+
};
|
|
427
|
+
if (fileData) {
|
|
428
|
+
Object.assign(params.body, fileData);
|
|
429
|
+
}
|
|
430
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, '/content');
|
|
431
|
+
return this.client.wrapWithDefaultHandler(this.client.options)(apiPath, params, callback);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get preflight information for a file version upload. Without any file data,
|
|
435
|
+
* this will return an upload URL and token to be used when uploading the file.
|
|
436
|
+
* Using this upload URL will allow for the fastest upload, and the one-time
|
|
437
|
+
* token can be passed to a worker or other client to actually perform the
|
|
438
|
+
* upload with. If file data (e.g. size, parent, name) is passed, it will be
|
|
439
|
+
* validated as if the actual file were being uploaded. This enables checking
|
|
440
|
+
* of preconditions such as name uniqueness and available storage space before
|
|
441
|
+
* attempting a large file upload.
|
|
442
|
+
*
|
|
443
|
+
* API Endpoint: '/files/:fileID/content'
|
|
444
|
+
* Method: OPTIONS
|
|
445
|
+
*
|
|
446
|
+
* @param {string} fileID - The file ID to which a new version will be uploaded
|
|
447
|
+
* @param {Object} [fileData] - Optional data about the file to be uploaded
|
|
448
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
449
|
+
* @param {Function} [callback] - Called with upload data if successful, or err if the upload would not succeed
|
|
450
|
+
* @returns {Promise<Object>} A promise resolving to the upload data
|
|
451
|
+
*/
|
|
452
|
+
preflightUploadNewFileVersion(fileID, fileData, options, callback) {
|
|
453
|
+
var params = {
|
|
454
|
+
qs: options,
|
|
455
|
+
};
|
|
456
|
+
if (fileData) {
|
|
457
|
+
params.body = fileData;
|
|
458
|
+
}
|
|
459
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/content');
|
|
460
|
+
return this.client.wrapWithDefaultHandler(this.client.options)(apiPath, params, callback);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* If there are previous versions of this file, this method can be used to promote one of the older
|
|
464
|
+
* versions to the top of the stack. This actually mints a copy of the old version and puts it on
|
|
465
|
+
* the top of the versions stack. The file will have the exact same contents, the same SHA1/etag,
|
|
466
|
+
* and the same name as the original. Other properties such as comments do not get updated to their former values.
|
|
467
|
+
*
|
|
468
|
+
* API Endpoint: '/files/:fileID/versions/current'
|
|
469
|
+
* Method: POST
|
|
470
|
+
*
|
|
471
|
+
* @param {string} fileID - The file ID which version will be promoted
|
|
472
|
+
* @param {string} versionID - The ID of the file_version that you want to make current
|
|
473
|
+
* @param {Function} [callback] - Passed the promoted file version information if successful, error otherwise
|
|
474
|
+
* @returns {Promise<Object>} A promise resolving to the promoted file version
|
|
475
|
+
*/
|
|
476
|
+
promoteVersion(fileID, versionID, callback) {
|
|
477
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, VERSIONS_SUBRESOURCE, '/current'), params = {
|
|
478
|
+
body: {
|
|
479
|
+
type: 'file_version',
|
|
480
|
+
id: versionID,
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Uploads a new file. Unlike non-upload methods, this method will not perform any retries.
|
|
487
|
+
* This method currently does not support any optional parameters such as contentModifiedAt.
|
|
488
|
+
*
|
|
489
|
+
* API Endpoint: '/files/content'
|
|
490
|
+
* Method: POST
|
|
491
|
+
*
|
|
492
|
+
* @param {string} parentFolderID - the id of the parent folder to upload to
|
|
493
|
+
* @param {string} filename - the file name that the uploaded file should have
|
|
494
|
+
* @param {string|Buffer|ReadStream} content - the content of the file. It can be a string, a Buffer, or a read stream
|
|
495
|
+
* (like that returned by fs.createReadStream()).
|
|
496
|
+
* @param {Object} [options] - Optional parameters
|
|
497
|
+
* @param {string} [options.content_created_at] - RFC 3339 timestamp when the file was created
|
|
498
|
+
* @param {string} [options.content_modified_at] - RFC 3339 timestamp when the file was last modified
|
|
499
|
+
* @param {int} [options.content_length] - Optional length of the content. Required if content is a read stream of any type other than fs stream.
|
|
500
|
+
* @param {string} [options.description] - Optional description of the uploaded file.
|
|
501
|
+
* @param {Function} [callback] - called with data about the upload if successful, or an error if the
|
|
502
|
+
* upload failed
|
|
503
|
+
* @returns {Promise<Object>} A promise resolving to the uploaded file
|
|
504
|
+
*/
|
|
505
|
+
uploadFile(parentFolderID, filename, content, options, callback) {
|
|
506
|
+
// Shuffle around optional parameter
|
|
507
|
+
if (typeof options === 'function') {
|
|
508
|
+
callback = options;
|
|
509
|
+
options = {};
|
|
510
|
+
}
|
|
511
|
+
var formOptions = {};
|
|
512
|
+
if (options && options.hasOwnProperty('content_length')) {
|
|
513
|
+
formOptions.knownLength = options.content_length;
|
|
514
|
+
// Delete content_length from options so it's not added to the attributes of the form
|
|
515
|
+
delete options.content_length;
|
|
516
|
+
}
|
|
517
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, '/content'), multipartFormData = {
|
|
518
|
+
attributes: createFileMetadataFormData(parentFolderID, filename, options),
|
|
519
|
+
content: createFileContentFormData(content, formOptions),
|
|
520
|
+
};
|
|
521
|
+
return this.client.wrapWithDefaultHandler(this.client.upload)(apiPath, null, multipartFormData, callback);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Uploads a new version of a file. Unlike non-upload methods, this method will not perform any retries.
|
|
525
|
+
* This method currently does not support any optional parameters such as contentModifiedAt.
|
|
526
|
+
*
|
|
527
|
+
* API Endpoint: '/files/:fileID/content'
|
|
528
|
+
* Method: POST
|
|
529
|
+
*
|
|
530
|
+
* @param {string} fileID - the id of the file to upload a new version of
|
|
531
|
+
* @param {string|Buffer|Stream} content - the content of the file. It can be a string, a Buffer, or a read stream
|
|
532
|
+
* (like that returned by fs.createReadStream()).
|
|
533
|
+
* @param {Object} [options] - Optional parameters
|
|
534
|
+
* @param {string} [options.content_modified_at] - RFC 3339 timestamp when the file was last modified
|
|
535
|
+
* @param {string} [options.name] - A new name for the file
|
|
536
|
+
* @param {int} [options.content_length] - Optional length of the content. Required if content is a read stream of any type other than fs stream.
|
|
537
|
+
* @param {string} [options.description] - Optional description of the uploaded new file version.
|
|
538
|
+
* @param {Function} [callback] - called with data about the upload if successful, or an error if the
|
|
539
|
+
* upload failed
|
|
540
|
+
* @returns {Promise<Object>} A promise resolving to the uploaded file
|
|
541
|
+
*/
|
|
542
|
+
uploadNewFileVersion(fileID, content, options, callback) {
|
|
543
|
+
// Shuffle around optional parameter
|
|
544
|
+
if (typeof options === 'function') {
|
|
545
|
+
callback = options;
|
|
546
|
+
options = {};
|
|
547
|
+
}
|
|
548
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/content'), multipartFormData = {};
|
|
549
|
+
var formOptions = {};
|
|
550
|
+
if (options) {
|
|
551
|
+
if (options.hasOwnProperty('content_length')) {
|
|
552
|
+
formOptions.knownLength = options.content_length;
|
|
553
|
+
// Delete content_length from options so it's not added to the attributes of the form
|
|
554
|
+
delete options.content_length;
|
|
555
|
+
}
|
|
556
|
+
multipartFormData.attributes = JSON.stringify(options);
|
|
557
|
+
}
|
|
558
|
+
multipartFormData.content = createFileContentFormData(content, formOptions);
|
|
559
|
+
return this.client.wrapWithDefaultHandler(this.client.upload)(apiPath, null, multipartFormData, callback);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Retrieves all metadata associated with a file.
|
|
563
|
+
*
|
|
564
|
+
* API Endpoint: '/files/:fileID/metadata'
|
|
565
|
+
* Method: GET
|
|
566
|
+
*
|
|
567
|
+
* @param {string} fileID - the ID of the file to get metadata for
|
|
568
|
+
* @param {Function} [callback] - called with an array of metadata when successful
|
|
569
|
+
* @returns {Promise<Object>} A promise resolving to a collection of metadata on the file
|
|
570
|
+
*/
|
|
571
|
+
getAllMetadata(fileID, callback) {
|
|
572
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, 'metadata');
|
|
573
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Retrieve a single metadata template instance for a file.
|
|
577
|
+
*
|
|
578
|
+
* API Endpoint: '/files/:fileID/metadata/:scope/:template'
|
|
579
|
+
* Method: GET
|
|
580
|
+
*
|
|
581
|
+
* @param {string} fileID - The ID of the file to retrive the metadata of
|
|
582
|
+
* @param {string} scope - The scope of the metadata template, e.g. "global"
|
|
583
|
+
* @param {string} template - The metadata template to retrieve
|
|
584
|
+
* @param {Function} [callback] - Passed the metadata template if successful
|
|
585
|
+
* @returns {Promise<Object>} A promise resolving to the metadata template
|
|
586
|
+
*/
|
|
587
|
+
getMetadata(fileID, scope, template, callback) {
|
|
588
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, 'metadata', scope, template);
|
|
589
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Adds metadata to a file. Metadata must either match a template schema or
|
|
593
|
+
* be placed into the unstructured "properties" template in global scope.
|
|
594
|
+
*
|
|
595
|
+
* API Endpoint: '/files/:fileID/metadata/:scope/:template'
|
|
596
|
+
* Method: POST
|
|
597
|
+
*
|
|
598
|
+
* @param {string} fileID - The ID of the file to add metadata to
|
|
599
|
+
* @param {string} scope - The scope of the metadata template, e.g. "enterprise"
|
|
600
|
+
* @param {string} template - The metadata template schema to add
|
|
601
|
+
* @param {Object} data - Key/value pairs tp add as metadata
|
|
602
|
+
* @param {Function} [callback] - Called with error if unsuccessful
|
|
603
|
+
* @returns {Promise<Object>} A promise resolving to the new metadata
|
|
604
|
+
*/
|
|
605
|
+
addMetadata(fileID, scope, template, data, callback) {
|
|
606
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, 'metadata', scope, template), params = {
|
|
607
|
+
body: data,
|
|
608
|
+
};
|
|
609
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Updates a metadata template instance with JSON Patch-formatted data.
|
|
613
|
+
*
|
|
614
|
+
* API Endpoint: '/files/:fileID/metadata/:scope/:template'
|
|
615
|
+
* Method: PUT
|
|
616
|
+
*
|
|
617
|
+
* @param {string} fileID - The file to update metadata for
|
|
618
|
+
* @param {string} scope - The scope of the template to update
|
|
619
|
+
* @param {string} template - The template to update
|
|
620
|
+
* @param {Object} patch - The patch data
|
|
621
|
+
* @param {Function} [callback] - Called with updated metadata if successful
|
|
622
|
+
* @returns {Promise<Object>} A promise resolving to the updated metadata
|
|
623
|
+
*/
|
|
624
|
+
updateMetadata(fileID, scope, template, patch, callback) {
|
|
625
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, 'metadata', scope, template), params = {
|
|
626
|
+
body: patch,
|
|
627
|
+
headers: {
|
|
628
|
+
'Content-Type': 'application/json-patch+json',
|
|
629
|
+
},
|
|
630
|
+
};
|
|
631
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Sets metadata on a file, overwriting any metadata that exists for the provided keys.
|
|
635
|
+
*
|
|
636
|
+
* @param {string} fileID - The file to set metadata on
|
|
637
|
+
* @param {string} scope - The scope of the metadata template
|
|
638
|
+
* @param {string} template - The key of the metadata template
|
|
639
|
+
* @param {Object} metadata - The metadata to set
|
|
640
|
+
* @param {Function} [callback] - Called with updated metadata if successful
|
|
641
|
+
* @returns {Promise<Object>} A promise resolving to the updated metadata
|
|
642
|
+
*/
|
|
643
|
+
setMetadata(fileID, scope, template, metadata, callback) {
|
|
644
|
+
return this.addMetadata(fileID, scope, template, metadata)
|
|
645
|
+
.catch((err /* FIXME */) => {
|
|
646
|
+
if (err.statusCode !== 409) {
|
|
647
|
+
throw err;
|
|
648
|
+
}
|
|
649
|
+
// Metadata already exists on the file; update instead
|
|
650
|
+
var updates = Object.keys(metadata).map((key) => ({
|
|
651
|
+
op: 'add',
|
|
652
|
+
path: `/${key}`,
|
|
653
|
+
value: metadata[key],
|
|
654
|
+
}));
|
|
655
|
+
return this.updateMetadata(fileID, scope, template, updates);
|
|
656
|
+
})
|
|
657
|
+
.asCallback(callback);
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Deletes a metadata template from a file.
|
|
661
|
+
*
|
|
662
|
+
* API Endpoint: '/files/:fileID/metadata/:scope/:template'
|
|
663
|
+
* Method: DELETE
|
|
664
|
+
*
|
|
665
|
+
* @param {string} fileID - The ID of the file to remove metadata from
|
|
666
|
+
* @param {string} scope - The scope of the metadata template
|
|
667
|
+
* @param {string} template - The template to remove from the file
|
|
668
|
+
* @param {Function} [callback] - Called with nothing if successful, error otherwise
|
|
669
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
670
|
+
*/
|
|
671
|
+
deleteMetadata(fileID, scope, template, callback) {
|
|
672
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, 'metadata', scope, template);
|
|
673
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Permanently deletes an item that is in the trash. The item will no longer exist in Box. This action cannot be undone.
|
|
677
|
+
*
|
|
678
|
+
* API Endpoint: '/files/:fileID/trash'
|
|
679
|
+
* Method: DELETE
|
|
680
|
+
*
|
|
681
|
+
* @param {string} fileID - The ID of the file to remove metadata from
|
|
682
|
+
* @param {Object} [options] Optional parameters
|
|
683
|
+
* @param {string} [options.etag] Only delete the file if the etag matches
|
|
684
|
+
* @param {Function} [callback] - Called with nothing if successful, error otherwise
|
|
685
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
686
|
+
*/
|
|
687
|
+
deletePermanently(fileID, options, callback) {
|
|
688
|
+
if (typeof options === 'function') {
|
|
689
|
+
callback = options;
|
|
690
|
+
options = {};
|
|
691
|
+
}
|
|
692
|
+
var params = {};
|
|
693
|
+
if (options && options.etag) {
|
|
694
|
+
params.headers = {
|
|
695
|
+
'If-Match': options.etag,
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/trash');
|
|
699
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Retrieves a file that has been moved to the trash.
|
|
703
|
+
*
|
|
704
|
+
* API Endpoint: '/files/:fileID/trash'
|
|
705
|
+
* Method: GET
|
|
706
|
+
*
|
|
707
|
+
* @param {string} fileID - The ID of the file being requested
|
|
708
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
709
|
+
* @param {Function} [callback] - Passed the trashed file information if successful, error otherwise
|
|
710
|
+
* @returns {Promise<Object>} A promise resolving to the trashed file
|
|
711
|
+
*/
|
|
712
|
+
getTrashedFile(fileID, options, callback) {
|
|
713
|
+
var params = {
|
|
714
|
+
qs: options,
|
|
715
|
+
};
|
|
716
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, 'trash');
|
|
717
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Retrieves all of the tasks for given file.
|
|
721
|
+
*
|
|
722
|
+
* API Endpoint: '/files/:fileID/tasks'
|
|
723
|
+
* Method: GET
|
|
724
|
+
*
|
|
725
|
+
* @param {string} fileID - The ID of the file to get tasks for
|
|
726
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
727
|
+
* @param {Function} [callback] - Passed the file tasks if successful, error otherwise
|
|
728
|
+
* @returns {Promise<Object>} A promise resolving to a collections of tasks on the file
|
|
729
|
+
*/
|
|
730
|
+
getTasks(fileID, options, callback) {
|
|
731
|
+
var params = {
|
|
732
|
+
qs: options,
|
|
733
|
+
};
|
|
734
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/tasks');
|
|
735
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Used to retrieve an expiring URL for creating an embedded preview session.
|
|
739
|
+
* The URL will expire after 60 seconds and the preview session will expire after 60 minutes.
|
|
740
|
+
*
|
|
741
|
+
* API Endpoint: '/files/:fileID?fields=expiring_embed_link'
|
|
742
|
+
* Method: GET
|
|
743
|
+
*
|
|
744
|
+
* @param {string} fileID - The ID of the file to generate embed link for
|
|
745
|
+
* @param {Function} [callback] - Passed with the embed link if successful, error otherwise
|
|
746
|
+
* @returns {Promise<string>} A promise resolving to the file embed link URL
|
|
747
|
+
*/
|
|
748
|
+
getEmbedLink(fileID, callback) {
|
|
749
|
+
var params = {
|
|
750
|
+
qs: {
|
|
751
|
+
fields: 'expiring_embed_link',
|
|
752
|
+
},
|
|
753
|
+
};
|
|
754
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID);
|
|
755
|
+
return this.client
|
|
756
|
+
.get(apiPath, params)
|
|
757
|
+
.then((response /* FIXME */) => {
|
|
758
|
+
if (response.statusCode !== http_status_1.default.OK) {
|
|
759
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
760
|
+
}
|
|
761
|
+
return response.body.expiring_embed_link.url;
|
|
762
|
+
})
|
|
763
|
+
.asCallback(callback);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Locks a file.
|
|
767
|
+
*
|
|
768
|
+
* API Endpoint: '/files/:fileID'
|
|
769
|
+
* Method: PUT
|
|
770
|
+
*
|
|
771
|
+
* @param {string} fileID - The ID of the file to lock
|
|
772
|
+
* @param {Object} [options] - Optional parameters, can be left null in most cases
|
|
773
|
+
* @param {?string} [options.expires_at] - The time the lock expires
|
|
774
|
+
* @param {boolean} [options.is_download_prevented] - Whether or not the file can be downloaded while locked
|
|
775
|
+
* @param {Function} [callback] - Passed with the locked file information if successful, error otherwise
|
|
776
|
+
* @returns {Promise<Object>} A promise resolving to the locked file object
|
|
777
|
+
*/
|
|
778
|
+
lock(fileID, options, callback) {
|
|
779
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID), params = {
|
|
780
|
+
body: {
|
|
781
|
+
lock: {
|
|
782
|
+
type: LockType.LOCK,
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
};
|
|
786
|
+
Object.assign(params.body.lock, options);
|
|
787
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Unlocks a file.
|
|
791
|
+
*
|
|
792
|
+
* API Endpoint: '/files/:fileID'
|
|
793
|
+
* Method: PUT
|
|
794
|
+
*
|
|
795
|
+
* @param {string} fileID - The ID of the file to unlock
|
|
796
|
+
* @param {Function} [callback] - Passed with the unlocked file information if successful, error otherwise
|
|
797
|
+
* @returns {Promise<Object>} A promise resolving to the unlocked file object
|
|
798
|
+
*/
|
|
799
|
+
unlock(fileID, callback) {
|
|
800
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID), params = {
|
|
801
|
+
body: {
|
|
802
|
+
lock: null,
|
|
803
|
+
},
|
|
804
|
+
};
|
|
805
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Restores an item that has been moved to the trash. Default behavior is to
|
|
809
|
+
* restore the item to the folder it was in before it was moved to the trash.
|
|
810
|
+
* If that parent folder no longer exists or if there is now an item with the
|
|
811
|
+
* same name in that parent folder, the new parent folder and/or new name will
|
|
812
|
+
* need to be included in the request.
|
|
813
|
+
*
|
|
814
|
+
* API Endpoint: '/files/:fileID'
|
|
815
|
+
* Method: POST
|
|
816
|
+
*
|
|
817
|
+
* @param {string} fileID - The ID of the file to restore
|
|
818
|
+
* @param {Object} [options] - Optional parameters, can be left null in most cases
|
|
819
|
+
* @param {string} [options.name] - The new name for this item
|
|
820
|
+
* @param {string} [options.parent_id] - The new parent folder for this item
|
|
821
|
+
* @param {Function} [callback] - Called with item information if successful, error otherwise
|
|
822
|
+
* @returns {Promise<Object>} A promise resolving to the restored file object
|
|
823
|
+
*/
|
|
824
|
+
restoreFromTrash(fileID, options, callback) {
|
|
825
|
+
// Set up the parent_id parameter
|
|
826
|
+
if (options && options.parent_id) {
|
|
827
|
+
options.parent = {
|
|
828
|
+
id: options.parent_id,
|
|
829
|
+
};
|
|
830
|
+
delete options.parent_id;
|
|
831
|
+
}
|
|
832
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID), params = {
|
|
833
|
+
body: options || {},
|
|
834
|
+
};
|
|
835
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* If there are previous versions of this file, this method can be used to retrieve information
|
|
839
|
+
* about the older versions.
|
|
840
|
+
*
|
|
841
|
+
* API Endpoint: '/files/:fileID/versions'
|
|
842
|
+
* Method: GET
|
|
843
|
+
*
|
|
844
|
+
* @param {string} fileID - The ID of the file to view version for
|
|
845
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
846
|
+
* @param {Function} [callback] - Passed a list of previous file versions if successful, error otherwise
|
|
847
|
+
* @returns {Promise<Object>} A promise resolving to the collection of file versions
|
|
848
|
+
*/
|
|
849
|
+
getVersions(fileID, options, callback) {
|
|
850
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, VERSIONS_SUBRESOURCE), params = {
|
|
851
|
+
qs: options,
|
|
852
|
+
};
|
|
853
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Used to retrieve the watermark for a corresponding Box file.
|
|
857
|
+
*
|
|
858
|
+
* API Endpoint: '/files/:fileID/watermark'
|
|
859
|
+
* Method: GET
|
|
860
|
+
*
|
|
861
|
+
* @param {string} fileID - The Box ID of the file to get watermark for
|
|
862
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
863
|
+
* @param {Function} [callback] - Passed the watermark information if successful, error otherwise
|
|
864
|
+
* @returns {Promise<Object>} A promise resolving to the watermark info
|
|
865
|
+
*/
|
|
866
|
+
getWatermark(fileID, options, callback) {
|
|
867
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, WATERMARK_SUBRESOURCE), params = {
|
|
868
|
+
qs: options,
|
|
869
|
+
};
|
|
870
|
+
return this.client
|
|
871
|
+
.get(apiPath, params)
|
|
872
|
+
.then((response /* FIXME */) => {
|
|
873
|
+
if (response.statusCode !== 200) {
|
|
874
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
875
|
+
}
|
|
876
|
+
return response.body.watermark;
|
|
877
|
+
})
|
|
878
|
+
.asCallback(callback);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Used to apply or update the watermark for a corresponding Box file.
|
|
882
|
+
*
|
|
883
|
+
* API Endpoint: '/files/:fileID/watermark'
|
|
884
|
+
* Method: PUT
|
|
885
|
+
*
|
|
886
|
+
* @param {string} fileID - The Box ID of the file to update watermark for
|
|
887
|
+
* @param {Object} [options] - Optional parameters, can be left null
|
|
888
|
+
* @param {Function} [callback] - Passed the watermark information if successful, error otherwise
|
|
889
|
+
* @returns {Promise<Object>} A promise resolving to the watermark info
|
|
890
|
+
*/
|
|
891
|
+
applyWatermark(fileID, options, callback) {
|
|
892
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, WATERMARK_SUBRESOURCE), params = {
|
|
893
|
+
body: {
|
|
894
|
+
watermark: {
|
|
895
|
+
imprint: 'default', // Currently the API only supports default imprint
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
};
|
|
899
|
+
Object.assign(params.body.watermark, options);
|
|
900
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Used to remove the watermark for a corresponding Box file.
|
|
904
|
+
*
|
|
905
|
+
* API Endpoint: '/files/:fileID/watermark'
|
|
906
|
+
* Method: DELETE
|
|
907
|
+
*
|
|
908
|
+
* @param {string} fileID - The Box ID of the file to remove watermark from
|
|
909
|
+
* @param {Function} [callback] - Empty response body passed if successful, error otherwise
|
|
910
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
911
|
+
*/
|
|
912
|
+
removeWatermark(fileID, callback) {
|
|
913
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, WATERMARK_SUBRESOURCE);
|
|
914
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Discards a specific file version to the trash. Depending on the enterprise settings
|
|
918
|
+
* for this user, the item will either be actually deleted from Box or moved to the trash.
|
|
919
|
+
*
|
|
920
|
+
* API Endpoint: '/files/:fileID/version/:versionID'
|
|
921
|
+
* Method: DELETE
|
|
922
|
+
*
|
|
923
|
+
* @param {string} fileID - The file ID which old version will be moved to the trash or delete permanently
|
|
924
|
+
* @param {string} versionID - The ID of the version to move to the trash or delete permanently
|
|
925
|
+
* @param {Object} [options] Optional parameters
|
|
926
|
+
* @param {string} [options.etag] Only delete the version of the file etag matches
|
|
927
|
+
* @param {Function} [callback] - Empty response body, error otherwise
|
|
928
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
929
|
+
*/
|
|
930
|
+
deleteVersion(fileID, versionID, options, callback) {
|
|
931
|
+
// Switch around arguments if necessary for backwwards compatibility
|
|
932
|
+
if (typeof options === 'function') {
|
|
933
|
+
callback = options;
|
|
934
|
+
options = {};
|
|
935
|
+
}
|
|
936
|
+
var params = {};
|
|
937
|
+
if (options && options.etag) {
|
|
938
|
+
params.headers = {
|
|
939
|
+
'If-Match': options.etag,
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, VERSIONS_SUBRESOURCE, versionID);
|
|
943
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, params, callback);
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Creates a session used to upload a new file in chunks.. This will first
|
|
947
|
+
* verify that the file can be created and then open a session for uploading
|
|
948
|
+
* pieces of the file.
|
|
949
|
+
*
|
|
950
|
+
* API Endpoint: '/files/upload_sessions'
|
|
951
|
+
* Method: POST
|
|
952
|
+
*
|
|
953
|
+
* @param {string} folderID - The ID of the folder to upload the file to
|
|
954
|
+
* @param {int} size - The size of the file that will be uploaded
|
|
955
|
+
* @param {string} name - The name of the file to be created
|
|
956
|
+
* @param {Function} [callback] - Passed the upload session info if successful
|
|
957
|
+
* @returns {Promise<Object>} A promise resolving to the new upload session object
|
|
958
|
+
*/
|
|
959
|
+
createUploadSession(folderID, size, name, callback) {
|
|
960
|
+
var apiURL = this.client._uploadBaseURL +
|
|
961
|
+
(0, url_path_1.default)(BASE_PATH, UPLOAD_SESSION_SUBRESOURCE), params = {
|
|
962
|
+
body: {
|
|
963
|
+
folder_id: folderID,
|
|
964
|
+
file_size: size,
|
|
965
|
+
file_name: name,
|
|
966
|
+
},
|
|
967
|
+
};
|
|
968
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiURL, params, callback);
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Creates a session used to upload a new version of a file in chunks. This
|
|
972
|
+
* will first verify that the version can be created and then open a session for
|
|
973
|
+
* uploading pieces of the file.
|
|
974
|
+
*
|
|
975
|
+
* API Endpoint: '/files/:fileID/upload_sessions'
|
|
976
|
+
* Method: POST
|
|
977
|
+
*
|
|
978
|
+
* @param {string} fileID - The ID of the file to upload a new version of
|
|
979
|
+
* @param {int} size - The size of the file that will be uploaded
|
|
980
|
+
* @param {Function} [callback] - Passed the upload session info if successful
|
|
981
|
+
* @returns {Promise<Object>} A promise resolving to the new upload session object
|
|
982
|
+
*/
|
|
983
|
+
createNewVersionUploadSession(fileID, size, callback) {
|
|
984
|
+
var apiURL = this.client._uploadBaseURL +
|
|
985
|
+
(0, url_path_1.default)(BASE_PATH, fileID, UPLOAD_SESSION_SUBRESOURCE), params = {
|
|
986
|
+
body: {
|
|
987
|
+
file_size: size,
|
|
988
|
+
},
|
|
989
|
+
};
|
|
990
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiURL, params, callback);
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Uploads a chunk of a file to an open upload session
|
|
994
|
+
*
|
|
995
|
+
* API Endpoint: '/files/upload_sessions/:sessionID'
|
|
996
|
+
* Method: PUT
|
|
997
|
+
*
|
|
998
|
+
* @param {string} sessionID - The ID of the upload session to upload to
|
|
999
|
+
* @param {Buffer|string} part - The chunk of the file to upload
|
|
1000
|
+
* @param {int} offset - The byte position where the chunk begins in the file
|
|
1001
|
+
* @param {int} totalSize - The total size of the file being uploaded
|
|
1002
|
+
* @param {Function} [callback] - Passed the part definition if successful
|
|
1003
|
+
* @returns {Promise<Object>} A promise resolving to the part object
|
|
1004
|
+
*/
|
|
1005
|
+
uploadPart(sessionID, part, offset, totalSize, callback) {
|
|
1006
|
+
var apiURL = this.client._uploadBaseURL +
|
|
1007
|
+
(0, url_path_1.default)(BASE_PATH, UPLOAD_SESSION_SUBRESOURCE, sessionID);
|
|
1008
|
+
var hash = crypto_1.default.createHash('sha1').update(part).digest('base64');
|
|
1009
|
+
var params = {
|
|
1010
|
+
headers: {
|
|
1011
|
+
'Content-Type': 'application/octet-stream',
|
|
1012
|
+
Digest: `SHA=${hash}`,
|
|
1013
|
+
'Content-Range': `bytes ${offset}-${offset + part.length - 1}/${totalSize}`,
|
|
1014
|
+
},
|
|
1015
|
+
json: false,
|
|
1016
|
+
body: part,
|
|
1017
|
+
};
|
|
1018
|
+
return this.client
|
|
1019
|
+
.put(apiURL, params)
|
|
1020
|
+
.then((response /* FIXME */) => {
|
|
1021
|
+
if (response.statusCode !== 200) {
|
|
1022
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
1023
|
+
}
|
|
1024
|
+
return JSON.parse(response.body);
|
|
1025
|
+
})
|
|
1026
|
+
.asCallback(callback);
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Commit an upload session after all parts have been uploaded, creating the new file
|
|
1030
|
+
*
|
|
1031
|
+
* API Endpoint: '/files/upload_sessions/:sessionID/commit'
|
|
1032
|
+
* Method: POST
|
|
1033
|
+
*
|
|
1034
|
+
* @param {string} sessionID - The ID of the upload session to commit
|
|
1035
|
+
* @param {string} fileHash - The base64-encoded SHA-1 hash of the file being uploaded
|
|
1036
|
+
* @param {Object} [options] - Optional parameters set on the created file, can be left null
|
|
1037
|
+
* @param {UploadPart[]} [options.parts] The list of uploaded parts to be committed, will be fetched from the API otherwise
|
|
1038
|
+
* @param {string} [options.description] - Optional description of the uploaded file.
|
|
1039
|
+
* @param {Function} [callback] - Passed the new file information if successful
|
|
1040
|
+
* @returns {Promise<Object>} A promise resolving to the uploaded file object
|
|
1041
|
+
*/
|
|
1042
|
+
commitUploadSession(sessionID, fileHash, options, callback) {
|
|
1043
|
+
options = options || {};
|
|
1044
|
+
var userParts;
|
|
1045
|
+
if (options.parts) {
|
|
1046
|
+
userParts = options.parts;
|
|
1047
|
+
delete options.parts;
|
|
1048
|
+
}
|
|
1049
|
+
var apiURL = this.client._uploadBaseURL +
|
|
1050
|
+
(0, url_path_1.default)(BASE_PATH, UPLOAD_SESSION_SUBRESOURCE, sessionID, 'commit'), params = {
|
|
1051
|
+
headers: {
|
|
1052
|
+
Digest: `SHA=${fileHash}`,
|
|
1053
|
+
},
|
|
1054
|
+
body: {
|
|
1055
|
+
attributes: options,
|
|
1056
|
+
},
|
|
1057
|
+
};
|
|
1058
|
+
var fetchParts = (offset /* FIXME */, fetchedParts /* FIXME */) => {
|
|
1059
|
+
let pagingOptions = {
|
|
1060
|
+
limit: 1000,
|
|
1061
|
+
offset,
|
|
1062
|
+
};
|
|
1063
|
+
return this.getUploadSessionParts(sessionID, pagingOptions).then((data /* FIXME */) => {
|
|
1064
|
+
fetchedParts = fetchedParts.concat(data.entries);
|
|
1065
|
+
if (data.offset + data.entries.length >= data.total_count) {
|
|
1066
|
+
return bluebird_1.default.resolve(fetchedParts);
|
|
1067
|
+
}
|
|
1068
|
+
return fetchParts(offset + data.limit, fetchedParts);
|
|
1069
|
+
});
|
|
1070
|
+
};
|
|
1071
|
+
return (userParts ? bluebird_1.default.resolve(userParts) : fetchParts(0, []))
|
|
1072
|
+
.then((parts /* FIXME */) => {
|
|
1073
|
+
// Commit the upload with the list of parts
|
|
1074
|
+
params.body.parts = parts;
|
|
1075
|
+
return this.client.post(apiURL, params);
|
|
1076
|
+
})
|
|
1077
|
+
.then((response /* FIXME */) => {
|
|
1078
|
+
if (response.statusCode === 201) {
|
|
1079
|
+
return response.body;
|
|
1080
|
+
}
|
|
1081
|
+
if (response.statusCode === 202) {
|
|
1082
|
+
var retryInterval = response.headers['retry-after'] || 1;
|
|
1083
|
+
return bluebird_1.default.delay(retryInterval * 1000).then(() => {
|
|
1084
|
+
// Ensure we don't have to fetch parts from the API again on retry
|
|
1085
|
+
options = Object.assign({}, options, {
|
|
1086
|
+
parts: params.body.parts,
|
|
1087
|
+
});
|
|
1088
|
+
return this.commitUploadSession(sessionID, fileHash, options);
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
1092
|
+
})
|
|
1093
|
+
.asCallback(callback);
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Abort an upload session, discarding any chunks that were uploaded to it
|
|
1097
|
+
*
|
|
1098
|
+
* API Endpoint: '/files/upload_sessions/:sessionID'
|
|
1099
|
+
* Method: DELETE
|
|
1100
|
+
*
|
|
1101
|
+
* @param {string} sessionID - The ID of the upload session to commit
|
|
1102
|
+
* @param {Function} [callback] - Passed nothing if successful, error otherwise
|
|
1103
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
1104
|
+
*/
|
|
1105
|
+
abortUploadSession(sessionID, callback) {
|
|
1106
|
+
var apiURL = this.client._uploadBaseURL +
|
|
1107
|
+
(0, url_path_1.default)(BASE_PATH, UPLOAD_SESSION_SUBRESOURCE, sessionID);
|
|
1108
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiURL, null, callback);
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Get a list of all parts that have been uploaded to an upload session
|
|
1112
|
+
*
|
|
1113
|
+
* API Endpoint: '/files/upload_sessions/:sessionID/parts'
|
|
1114
|
+
* Method: GET
|
|
1115
|
+
*
|
|
1116
|
+
* @param {string} sessionID - The ID of the session to get a list of parts from
|
|
1117
|
+
* @param {Object} [options] - Optional parameters, can be left null
|
|
1118
|
+
* @param {string} [options.offset] - Paging offset for the list of parts
|
|
1119
|
+
* @param {int} [options.limit] - Maximum number of parts to return
|
|
1120
|
+
* @param {Function} [callback] - Passed the list of parts if successful
|
|
1121
|
+
* @returns {Promise<Object>} A promise resolving to the collection of uploaded parts
|
|
1122
|
+
*/
|
|
1123
|
+
getUploadSessionParts(sessionID, options, callback) {
|
|
1124
|
+
var apiURL = this.client._uploadBaseURL +
|
|
1125
|
+
(0, url_path_1.default)(BASE_PATH, UPLOAD_SESSION_SUBRESOURCE, sessionID, 'parts'), params = {
|
|
1126
|
+
qs: options,
|
|
1127
|
+
};
|
|
1128
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiURL, params, callback);
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Get the status of an upload session, e.g. whether or not is has started or
|
|
1132
|
+
* finished committing
|
|
1133
|
+
*
|
|
1134
|
+
* API Endpoint: '/files/upload_sessions/:sessionID'
|
|
1135
|
+
* Method: GET
|
|
1136
|
+
*
|
|
1137
|
+
* @param {string} sessionID - The ID of the upload session to get the status of
|
|
1138
|
+
* @param {Function} [callback] - Passed the session status if successful
|
|
1139
|
+
* @returns {Promise<Object>} A promise resolving to the upload session object
|
|
1140
|
+
*/
|
|
1141
|
+
getUploadSession(sessionID, callback) {
|
|
1142
|
+
var apiURL = this.client._uploadBaseURL +
|
|
1143
|
+
(0, url_path_1.default)(BASE_PATH, UPLOAD_SESSION_SUBRESOURCE, sessionID);
|
|
1144
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiURL, null, callback);
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Upload a file in chunks, which is generally faster and more reliable for
|
|
1148
|
+
* large files.
|
|
1149
|
+
*
|
|
1150
|
+
* API Endpoint: '/files/upload_sessions'
|
|
1151
|
+
* Method: POST
|
|
1152
|
+
*
|
|
1153
|
+
* @param {string} folderID - The ID of the folder to upload the file to
|
|
1154
|
+
* @param {int} size - The size of the file that will be uploaded
|
|
1155
|
+
* @param {string} name - The name of the file to be created
|
|
1156
|
+
* @param {Buffer|string|Readable} file - The file to upload
|
|
1157
|
+
* @param {Object} [options] - Optional parameters for the upload
|
|
1158
|
+
* @param {int} [options.parallelism] The number of chunks to upload concurrently
|
|
1159
|
+
* @param {int} [options.retryInterval] The amount of time to wait before retrying a failed chunk upload, in ms
|
|
1160
|
+
* @param {Object} [options.fileAttributes] Attributes to set on the newly-uploaded file
|
|
1161
|
+
* @param {Function} [callback] - Passed the uploader if successful
|
|
1162
|
+
* @returns {Promise<ChunkedUploader>} A promise resolving to the chunked uploader
|
|
1163
|
+
*/
|
|
1164
|
+
getChunkedUploader(folderID, size, name, file, options, callback) {
|
|
1165
|
+
if (file instanceof stream_1.Readable) {
|
|
1166
|
+
// Need to pause the stream immediately to prevent certain libraries,
|
|
1167
|
+
// e.g. request from placing the stream into flowing mode and consuming bytes
|
|
1168
|
+
file.pause();
|
|
1169
|
+
}
|
|
1170
|
+
return this.createUploadSession(folderID, size, name)
|
|
1171
|
+
.then((sessionInfo /* FIXME */) => new ChunkedUploader(this.client, sessionInfo, file, size, options))
|
|
1172
|
+
.asCallback(callback);
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Upload a new file version in chunks, which is generally faster and more
|
|
1176
|
+
* reliable for large files.
|
|
1177
|
+
*
|
|
1178
|
+
* API Endpoint: '/files/:fileID/upload_sessions'
|
|
1179
|
+
* Method: POST
|
|
1180
|
+
*
|
|
1181
|
+
* @param {string} fileID - The ID of the file to upload a new version of
|
|
1182
|
+
* @param {int} size - The size of the file that will be uploaded
|
|
1183
|
+
* @param {Buffer|string|Readable} file - The file to upload
|
|
1184
|
+
* @param {Object} [options] - Optional parameters for the upload
|
|
1185
|
+
* @param {int} [options.parallelism] The number of chunks to upload concurrently
|
|
1186
|
+
* @param {int} [options.retryInterval] The amount of time to wait before retrying a failed chunk upload, in ms
|
|
1187
|
+
* @param {Object} [options.fileAttributes] Attributes to set on the updated file object
|
|
1188
|
+
* @param {Function} [callback] - Passed the uploader if successful
|
|
1189
|
+
* @returns {Promise<ChunkedUploader>} A promise resolving to the chunked uploader
|
|
1190
|
+
*/
|
|
1191
|
+
getNewVersionChunkedUploader(fileID, size, file, options, callback) {
|
|
1192
|
+
if (file instanceof stream_1.Readable) {
|
|
1193
|
+
// Need to pause the stream immediately to prevent certain libraries,
|
|
1194
|
+
// e.g. request from placing the stream into flowing mode and consuming bytes
|
|
1195
|
+
file.pause();
|
|
1196
|
+
}
|
|
1197
|
+
return this.createNewVersionUploadSession(fileID, size)
|
|
1198
|
+
.then((sessionInfo /* FIXME */) => new ChunkedUploader(this.client, sessionInfo, file, size, options))
|
|
1199
|
+
.asCallback(callback);
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Requests collaborations on a given file.
|
|
1203
|
+
*
|
|
1204
|
+
* API Endpoint: '/files/:fileID/collaborations'
|
|
1205
|
+
* Method: GET
|
|
1206
|
+
*
|
|
1207
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
1208
|
+
* @param {Object} [options] - Additional options. Can be left null in most cases.
|
|
1209
|
+
* @param {int} [options.limit] - The maximum number of collaborations to return
|
|
1210
|
+
* @param {int} [options.offset] - Paging parameter for the collaborations collection
|
|
1211
|
+
* @param {string} [options.fields] - Comma-separated list of fields to return on the collaboration objects
|
|
1212
|
+
* @param {Function} [callback] - Passed the collaborations if successful, error otherwise
|
|
1213
|
+
* @returns {Promise<schemas.Collaborations>} A promise resolving to the collection of collaborations on the file
|
|
1214
|
+
*/
|
|
1215
|
+
getCollaborations(fileID, options, callback) {
|
|
1216
|
+
var params = {
|
|
1217
|
+
qs: options,
|
|
1218
|
+
};
|
|
1219
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID, '/collaborations');
|
|
1220
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Requests information for all representation objects generated for a specific Box file
|
|
1224
|
+
*
|
|
1225
|
+
* API Endpoint: '/files/:fileID?fields=representations'
|
|
1226
|
+
* Method : GET
|
|
1227
|
+
*
|
|
1228
|
+
* @param {string} fileID - Box ID of the file being requested
|
|
1229
|
+
* @param {client.files.representation} representationType - The x-rep-hints value the application should create a
|
|
1230
|
+
* representation for. This value can either come from FileRepresentationType enum or manually created
|
|
1231
|
+
* @param {Object} [options] - Additional options. Can be left empty
|
|
1232
|
+
* @param {boolean} [options.generateRepresentations = false] - Set to true to return representation info where all states resolve to success.
|
|
1233
|
+
* @param {Function} [callback] - Passed an array of representaton objects if successful
|
|
1234
|
+
* @returns {Promise<Object>} A promise resolving to the representation response objects
|
|
1235
|
+
*/
|
|
1236
|
+
getRepresentationInfo(fileID, representationType, options, callback) {
|
|
1237
|
+
if (typeof options === 'function') {
|
|
1238
|
+
callback = options;
|
|
1239
|
+
options = {};
|
|
1240
|
+
}
|
|
1241
|
+
if (!representationType && options && options.generateRepresentations) {
|
|
1242
|
+
throw new Error('Must provide a valid X-Rep-Hints string to get representations with a success status');
|
|
1243
|
+
}
|
|
1244
|
+
var params = {
|
|
1245
|
+
qs: {
|
|
1246
|
+
fields: 'representations',
|
|
1247
|
+
},
|
|
1248
|
+
headers: {
|
|
1249
|
+
'x-rep-hints': representationType,
|
|
1250
|
+
},
|
|
1251
|
+
};
|
|
1252
|
+
var apiPath = (0, url_path_1.default)(BASE_PATH, fileID);
|
|
1253
|
+
return this.client
|
|
1254
|
+
.get(apiPath, params)
|
|
1255
|
+
.then((response /* FIXME */) => {
|
|
1256
|
+
switch (response.statusCode) {
|
|
1257
|
+
// 202 - A Box file representation will be generated, but is not ready yet
|
|
1258
|
+
case http_status_1.default.ACCEPTED:
|
|
1259
|
+
throw errors_1.default.buildResponseError(response, 'Representation not ready at this time');
|
|
1260
|
+
// 200 - A Boxfile representation generated successfully
|
|
1261
|
+
// return the representation object
|
|
1262
|
+
case http_status_1.default.OK:
|
|
1263
|
+
if (options && options.generateRepresentations) {
|
|
1264
|
+
var data = response.body.representations.entries;
|
|
1265
|
+
var promiseArray = data.map((entry /* FIXME */) => {
|
|
1266
|
+
switch (entry.status.state) {
|
|
1267
|
+
case 'success':
|
|
1268
|
+
case 'viewable':
|
|
1269
|
+
case 'error':
|
|
1270
|
+
return bluebird_1.default.resolve(entry);
|
|
1271
|
+
default:
|
|
1272
|
+
return pollRepresentationInfo(this.client, entry.info.url);
|
|
1273
|
+
}
|
|
1274
|
+
});
|
|
1275
|
+
return bluebird_1.default.all(promiseArray).then((entries) => ({ entries }));
|
|
1276
|
+
}
|
|
1277
|
+
return response.body.representations;
|
|
1278
|
+
// Unexpected Response
|
|
1279
|
+
default:
|
|
1280
|
+
throw errors_1.default.buildUnexpectedResponseError(response);
|
|
1281
|
+
}
|
|
1282
|
+
})
|
|
1283
|
+
.asCallback(callback);
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Get the contents of a representation of a file, e.g, the binary content of an image or pdf.
|
|
1287
|
+
*
|
|
1288
|
+
* API Endpoint: '/files/:fileID?fields=representations'
|
|
1289
|
+
* Method : GET
|
|
1290
|
+
*
|
|
1291
|
+
* @param {string} fileID The file ID to get the representation of
|
|
1292
|
+
* @param {string} representationType The X-Rep-Hints type to request
|
|
1293
|
+
* @param {Object} [options] Optional parameters
|
|
1294
|
+
* @param {string} [options.assetPath] Asset path for representations with multiple files
|
|
1295
|
+
* @param {Function} [callback] Passed a stream over the representation contents if successful
|
|
1296
|
+
* @returns {Promise<Readable>} A promise resolving to a stream over the representation contents
|
|
1297
|
+
*/
|
|
1298
|
+
getRepresentationContent(fileID, representationType, options, callback) {
|
|
1299
|
+
if (!representationType) {
|
|
1300
|
+
throw new Error('Must provide a valid X-Rep-Hints string');
|
|
1301
|
+
}
|
|
1302
|
+
options = Object.assign({ assetPath: '' }, options);
|
|
1303
|
+
return this.getRepresentationInfo(fileID, representationType)
|
|
1304
|
+
.then((reps /* FIXME */) => {
|
|
1305
|
+
var repInfo = reps.entries.pop();
|
|
1306
|
+
if (!repInfo) {
|
|
1307
|
+
throw new Error('Could not get information for requested representation');
|
|
1308
|
+
}
|
|
1309
|
+
// If the representation is paged, we need to specify which page to get the content for
|
|
1310
|
+
// If the assetPath is not specified, we default to the first pages
|
|
1311
|
+
if (!options?.assetPath && repInfo.properties?.paged == 'true') {
|
|
1312
|
+
options.assetPath = `1.${repInfo.representation}`;
|
|
1313
|
+
}
|
|
1314
|
+
switch (repInfo.status.state) {
|
|
1315
|
+
case 'success':
|
|
1316
|
+
case 'viewable':
|
|
1317
|
+
return repInfo.content.url_template;
|
|
1318
|
+
case 'error':
|
|
1319
|
+
throw new Error('Representation had error status');
|
|
1320
|
+
case 'none':
|
|
1321
|
+
case 'pending':
|
|
1322
|
+
return pollRepresentationInfo(this.client, repInfo.info.url).then((info /* FIXME */) => {
|
|
1323
|
+
if (info.status.state === 'error') {
|
|
1324
|
+
throw new Error('Representation had error status');
|
|
1325
|
+
}
|
|
1326
|
+
return info.content.url_template;
|
|
1327
|
+
});
|
|
1328
|
+
default:
|
|
1329
|
+
throw new Error(`Unknown representation status: ${repInfo.status.state}`);
|
|
1330
|
+
}
|
|
1331
|
+
})
|
|
1332
|
+
.then((assetURLTemplate) => {
|
|
1333
|
+
var url = url_template_1.default
|
|
1334
|
+
.parse(assetURLTemplate)
|
|
1335
|
+
.expand({ asset_path: options.assetPath });
|
|
1336
|
+
return this.client.get(url, { streaming: true });
|
|
1337
|
+
})
|
|
1338
|
+
.asCallback(callback);
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Creates a zip of multiple files and folders.
|
|
1342
|
+
*
|
|
1343
|
+
* API Endpoint: '/zip_downloads'
|
|
1344
|
+
* Method: POST
|
|
1345
|
+
*
|
|
1346
|
+
* @param {name} name - The name of the zip file to be created
|
|
1347
|
+
* @param {Array} items - Array of files or folders to be part of the created zip
|
|
1348
|
+
* @param {Function} [callback] Passed a zip information object
|
|
1349
|
+
* @returns {Promise<string>} A promise resolving to a zip information object
|
|
1350
|
+
*/
|
|
1351
|
+
createZip(name, items /* FIXME */, callback) {
|
|
1352
|
+
var params = {
|
|
1353
|
+
body: {
|
|
1354
|
+
download_file_name: name,
|
|
1355
|
+
items,
|
|
1356
|
+
},
|
|
1357
|
+
};
|
|
1358
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(ZIP_DOWNLOAD_PATH, params, callback);
|
|
1359
|
+
}
|
|
1360
|
+
/**
|
|
1361
|
+
* Creates a zip of multiple files and folders and downloads it.
|
|
1362
|
+
*
|
|
1363
|
+
* API Endpoint: '/zip_downloads'
|
|
1364
|
+
* Method: GET
|
|
1365
|
+
*
|
|
1366
|
+
* @param {name} name - The name of the zip file to be created
|
|
1367
|
+
* @param {Array} items - Array of files or folders to be part of the created zip
|
|
1368
|
+
* @param {Stream} stream - Stream to pipe the readable stream of the zip file
|
|
1369
|
+
* @param {Function} [callback] - Passed a zip download status object
|
|
1370
|
+
* @returns {Promise<Readable>} A promise resolving to a zip download status object
|
|
1371
|
+
*/
|
|
1372
|
+
downloadZip(name, items /* FIXME */, stream, callback) {
|
|
1373
|
+
var downloadStreamOptions = {
|
|
1374
|
+
streaming: true,
|
|
1375
|
+
headers: {},
|
|
1376
|
+
};
|
|
1377
|
+
var params = {
|
|
1378
|
+
body: {
|
|
1379
|
+
download_file_name: name,
|
|
1380
|
+
items,
|
|
1381
|
+
},
|
|
1382
|
+
};
|
|
1383
|
+
return this.client
|
|
1384
|
+
.post(ZIP_DOWNLOAD_PATH, params)
|
|
1385
|
+
.then((response /* FIXME */) => this.client
|
|
1386
|
+
.get(response.body.download_url, downloadStreamOptions)
|
|
1387
|
+
.then((responseStream) => {
|
|
1388
|
+
responseStream.pipe(stream);
|
|
1389
|
+
// eslint-disable-next-line promise/avoid-new
|
|
1390
|
+
return new bluebird_1.default((resolve, reject) => {
|
|
1391
|
+
responseStream.on('end', () => resolve('Done downloading'));
|
|
1392
|
+
responseStream.on('error', (error) => reject(error));
|
|
1393
|
+
}).then(() => this.client
|
|
1394
|
+
.get(response.body.status_url)
|
|
1395
|
+
.then((responseStatus /* FIXME */) => responseStatus.body));
|
|
1396
|
+
}))
|
|
1397
|
+
.asCallback(callback);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Enum of valid x-rep- hint values for generating representation info
|
|
1402
|
+
*
|
|
1403
|
+
* @readonly
|
|
1404
|
+
* @enum {FileRepresentationType}
|
|
1405
|
+
*/
|
|
1406
|
+
Files.prototype.representation = FileRepresentationType;
|
|
1407
|
+
module.exports = Files;
|
|
1408
|
+
//# sourceMappingURL=files.js.map
|