@backblaze-labs/b2-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -0
- package/LICENSE +21 -0
- package/README.md +664 -0
- package/dist/auth/account-info.d.cts +51 -0
- package/dist/auth/account-info.d.cts.map +1 -0
- package/dist/auth/account-info.d.ts +51 -0
- package/dist/auth/account-info.d.ts.map +1 -0
- package/dist/auth/file.cjs +210 -0
- package/dist/auth/file.cjs.map +1 -0
- package/dist/auth/file.d.cts +157 -0
- package/dist/auth/file.d.cts.map +1 -0
- package/dist/auth/file.d.ts +157 -0
- package/dist/auth/file.d.ts.map +1 -0
- package/dist/auth/file.js +210 -0
- package/dist/auth/file.js.map +1 -0
- package/dist/auth/in-memory.cjs +184 -0
- package/dist/auth/in-memory.cjs.map +1 -0
- package/dist/auth/in-memory.d.cts +147 -0
- package/dist/auth/in-memory.d.cts.map +1 -0
- package/dist/auth/in-memory.d.ts +147 -0
- package/dist/auth/in-memory.d.ts.map +1 -0
- package/dist/auth/in-memory.js +184 -0
- package/dist/auth/in-memory.js.map +1 -0
- package/dist/auth/index.cjs +10 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +6 -0
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.ts +6 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +10 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/realms.cjs +12 -0
- package/dist/auth/realms.cjs.map +1 -0
- package/dist/auth/realms.d.cts +12 -0
- package/dist/auth/realms.d.cts.map +1 -0
- package/dist/auth/realms.d.ts +12 -0
- package/dist/auth/realms.d.ts.map +1 -0
- package/dist/auth/realms.js +12 -0
- package/dist/auth/realms.js.map +1 -0
- package/dist/auth/upload-url-pool.cjs +52 -0
- package/dist/auth/upload-url-pool.cjs.map +1 -0
- package/dist/auth/upload-url-pool.d.cts +35 -0
- package/dist/auth/upload-url-pool.d.cts.map +1 -0
- package/dist/auth/upload-url-pool.d.ts +35 -0
- package/dist/auth/upload-url-pool.d.ts.map +1 -0
- package/dist/auth/upload-url-pool.js +52 -0
- package/dist/auth/upload-url-pool.js.map +1 -0
- package/dist/bucket.cjs +789 -0
- package/dist/bucket.cjs.map +1 -0
- package/dist/bucket.d.cts +659 -0
- package/dist/bucket.d.cts.map +1 -0
- package/dist/bucket.d.ts +659 -0
- package/dist/bucket.d.ts.map +1 -0
- package/dist/bucket.js +789 -0
- package/dist/bucket.js.map +1 -0
- package/dist/client.cjs +230 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +222 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +222 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +230 -0
- package/dist/client.js.map +1 -0
- package/dist/copy/large.cjs +74 -0
- package/dist/copy/large.cjs.map +1 -0
- package/dist/copy/large.d.cts +53 -0
- package/dist/copy/large.d.cts.map +1 -0
- package/dist/copy/large.d.ts +53 -0
- package/dist/copy/large.d.ts.map +1 -0
- package/dist/copy/large.js +74 -0
- package/dist/copy/large.js.map +1 -0
- package/dist/download/parallel.cjs +122 -0
- package/dist/download/parallel.cjs.map +1 -0
- package/dist/download/parallel.d.cts +42 -0
- package/dist/download/parallel.d.cts.map +1 -0
- package/dist/download/parallel.d.ts +42 -0
- package/dist/download/parallel.d.ts.map +1 -0
- package/dist/download/parallel.js +122 -0
- package/dist/download/parallel.js.map +1 -0
- package/dist/download/single.cjs +117 -0
- package/dist/download/single.cjs.map +1 -0
- package/dist/download/single.d.cts +152 -0
- package/dist/download/single.d.cts.map +1 -0
- package/dist/download/single.d.ts +152 -0
- package/dist/download/single.d.ts.map +1 -0
- package/dist/download/single.js +117 -0
- package/dist/download/single.js.map +1 -0
- package/dist/errors/index.cjs +268 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +264 -0
- package/dist/errors/index.d.cts.map +1 -0
- package/dist/errors/index.d.ts +264 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +268 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/http/retry.cjs +36 -0
- package/dist/http/retry.cjs.map +1 -0
- package/dist/http/retry.d.cts +34 -0
- package/dist/http/retry.d.cts.map +1 -0
- package/dist/http/retry.d.ts +34 -0
- package/dist/http/retry.d.ts.map +1 -0
- package/dist/http/retry.js +36 -0
- package/dist/http/retry.js.map +1 -0
- package/dist/http/transport.cjs +143 -0
- package/dist/http/transport.cjs.map +1 -0
- package/dist/http/transport.d.cts +122 -0
- package/dist/http/transport.d.cts.map +1 -0
- package/dist/http/transport.d.ts +122 -0
- package/dist/http/transport.d.ts.map +1 -0
- package/dist/http/transport.js +143 -0
- package/dist/http/transport.js.map +1 -0
- package/dist/http/url-guard.cjs +97 -0
- package/dist/http/url-guard.cjs.map +1 -0
- package/dist/http/url-guard.d.cts +88 -0
- package/dist/http/url-guard.d.cts.map +1 -0
- package/dist/http/url-guard.d.ts +88 -0
- package/dist/http/url-guard.d.ts.map +1 -0
- package/dist/http/url-guard.js +97 -0
- package/dist/http/url-guard.js.map +1 -0
- package/dist/http/user-agent.cjs +51 -0
- package/dist/http/user-agent.cjs.map +1 -0
- package/dist/http/user-agent.d.cts +28 -0
- package/dist/http/user-agent.d.cts.map +1 -0
- package/dist/http/user-agent.d.ts +28 -0
- package/dist/http/user-agent.d.ts.map +1 -0
- package/dist/http/user-agent.js +51 -0
- package/dist/http/user-agent.js.map +1 -0
- package/dist/index.cjs +78 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/notifications/index.cjs +7 -0
- package/dist/notifications/index.cjs.map +1 -0
- package/dist/notifications/index.d.cts +3 -0
- package/dist/notifications/index.d.cts.map +1 -0
- package/dist/notifications/index.d.ts +3 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/index.js +7 -0
- package/dist/notifications/index.js.map +1 -0
- package/dist/notifications/webhook.cjs +106 -0
- package/dist/notifications/webhook.cjs.map +1 -0
- package/dist/notifications/webhook.d.cts +146 -0
- package/dist/notifications/webhook.d.cts.map +1 -0
- package/dist/notifications/webhook.d.ts +146 -0
- package/dist/notifications/webhook.d.ts.map +1 -0
- package/dist/notifications/webhook.js +106 -0
- package/dist/notifications/webhook.js.map +1 -0
- package/dist/object.cjs +212 -0
- package/dist/object.cjs.map +1 -0
- package/dist/object.d.cts +263 -0
- package/dist/object.d.cts.map +1 -0
- package/dist/object.d.ts +263 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +212 -0
- package/dist/object.js.map +1 -0
- package/dist/package.json.cjs +9 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/package.json.js +9 -0
- package/dist/package.json.js.map +1 -0
- package/dist/raw/encoding.cjs +47 -0
- package/dist/raw/encoding.cjs.map +1 -0
- package/dist/raw/encoding.d.cts +46 -0
- package/dist/raw/encoding.d.cts.map +1 -0
- package/dist/raw/encoding.d.ts +46 -0
- package/dist/raw/encoding.d.ts.map +1 -0
- package/dist/raw/encoding.js +47 -0
- package/dist/raw/encoding.js.map +1 -0
- package/dist/raw/index.cjs +600 -0
- package/dist/raw/index.cjs.map +1 -0
- package/dist/raw/index.d.cts +381 -0
- package/dist/raw/index.d.cts.map +1 -0
- package/dist/raw/index.d.ts +381 -0
- package/dist/raw/index.d.ts.map +1 -0
- package/dist/raw/index.js +601 -0
- package/dist/raw/index.js.map +1 -0
- package/dist/s3/index.cjs +23 -0
- package/dist/s3/index.cjs.map +1 -0
- package/dist/s3/index.d.cts +74 -0
- package/dist/s3/index.d.cts.map +1 -0
- package/dist/s3/index.d.ts +74 -0
- package/dist/s3/index.d.ts.map +1 -0
- package/dist/s3/index.js +23 -0
- package/dist/s3/index.js.map +1 -0
- package/dist/simulator/capabilities.cjs +53 -0
- package/dist/simulator/capabilities.cjs.map +1 -0
- package/dist/simulator/capabilities.d.cts +15 -0
- package/dist/simulator/capabilities.d.cts.map +1 -0
- package/dist/simulator/capabilities.d.ts +15 -0
- package/dist/simulator/capabilities.d.ts.map +1 -0
- package/dist/simulator/capabilities.js +53 -0
- package/dist/simulator/capabilities.js.map +1 -0
- package/dist/simulator/index.cjs +1559 -0
- package/dist/simulator/index.cjs.map +1 -0
- package/dist/simulator/index.d.cts +495 -0
- package/dist/simulator/index.d.cts.map +1 -0
- package/dist/simulator/index.d.ts +495 -0
- package/dist/simulator/index.d.ts.map +1 -0
- package/dist/simulator/index.js +1560 -0
- package/dist/simulator/index.js.map +1 -0
- package/dist/simulator/validation.cjs +174 -0
- package/dist/simulator/validation.cjs.map +1 -0
- package/dist/simulator/validation.d.cts +104 -0
- package/dist/simulator/validation.d.cts.map +1 -0
- package/dist/simulator/validation.d.ts +104 -0
- package/dist/simulator/validation.d.ts.map +1 -0
- package/dist/simulator/validation.js +174 -0
- package/dist/simulator/validation.js.map +1 -0
- package/dist/streams/collect.cjs +26 -0
- package/dist/streams/collect.cjs.map +1 -0
- package/dist/streams/collect.d.cts +18 -0
- package/dist/streams/collect.d.cts.map +1 -0
- package/dist/streams/collect.d.ts +18 -0
- package/dist/streams/collect.d.ts.map +1 -0
- package/dist/streams/collect.js +26 -0
- package/dist/streams/collect.js.map +1 -0
- package/dist/streams/hash.cjs +123 -0
- package/dist/streams/hash.cjs.map +1 -0
- package/dist/streams/hash.d.cts +42 -0
- package/dist/streams/hash.d.cts.map +1 -0
- package/dist/streams/hash.d.ts +42 -0
- package/dist/streams/hash.d.ts.map +1 -0
- package/dist/streams/hash.js +101 -0
- package/dist/streams/hash.js.map +1 -0
- package/dist/streams/index.cjs +13 -0
- package/dist/streams/index.cjs.map +1 -0
- package/dist/streams/index.d.cts +7 -0
- package/dist/streams/index.d.cts.map +1 -0
- package/dist/streams/index.d.ts +7 -0
- package/dist/streams/index.d.ts.map +1 -0
- package/dist/streams/index.js +13 -0
- package/dist/streams/index.js.map +1 -0
- package/dist/streams/progress.cjs +47 -0
- package/dist/streams/progress.cjs.map +1 -0
- package/dist/streams/progress.d.cts +53 -0
- package/dist/streams/progress.d.cts.map +1 -0
- package/dist/streams/progress.d.ts +53 -0
- package/dist/streams/progress.d.ts.map +1 -0
- package/dist/streams/progress.js +47 -0
- package/dist/streams/progress.js.map +1 -0
- package/dist/streams/source.cjs +155 -0
- package/dist/streams/source.cjs.map +1 -0
- package/dist/streams/source.d.cts +140 -0
- package/dist/streams/source.d.cts.map +1 -0
- package/dist/streams/source.d.ts +140 -0
- package/dist/streams/source.d.ts.map +1 -0
- package/dist/streams/source.js +155 -0
- package/dist/streams/source.js.map +1 -0
- package/dist/sync/actions/index.cjs +191 -0
- package/dist/sync/actions/index.cjs.map +1 -0
- package/dist/sync/actions/index.d.cts +167 -0
- package/dist/sync/actions/index.d.cts.map +1 -0
- package/dist/sync/actions/index.d.ts +167 -0
- package/dist/sync/actions/index.d.ts.map +1 -0
- package/dist/sync/actions/index.js +191 -0
- package/dist/sync/actions/index.js.map +1 -0
- package/dist/sync/index.cjs +23 -0
- package/dist/sync/index.cjs.map +1 -0
- package/dist/sync/index.d.cts +21 -0
- package/dist/sync/index.d.cts.map +1 -0
- package/dist/sync/index.d.ts +21 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +23 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/pairing.cjs +31 -0
- package/dist/sync/pairing.cjs.map +1 -0
- package/dist/sync/pairing.d.cts +13 -0
- package/dist/sync/pairing.d.cts.map +1 -0
- package/dist/sync/pairing.d.ts +13 -0
- package/dist/sync/pairing.d.ts.map +1 -0
- package/dist/sync/pairing.js +31 -0
- package/dist/sync/pairing.js.map +1 -0
- package/dist/sync/policies/compare.cjs +14 -0
- package/dist/sync/policies/compare.cjs.map +1 -0
- package/dist/sync/policies/compare.d.cts +13 -0
- package/dist/sync/policies/compare.d.cts.map +1 -0
- package/dist/sync/policies/compare.d.ts +13 -0
- package/dist/sync/policies/compare.d.ts.map +1 -0
- package/dist/sync/policies/compare.js +14 -0
- package/dist/sync/policies/compare.js.map +1 -0
- package/dist/sync/policies/index.cjs +74 -0
- package/dist/sync/policies/index.cjs.map +1 -0
- package/dist/sync/policies/index.d.cts +42 -0
- package/dist/sync/policies/index.d.cts.map +1 -0
- package/dist/sync/policies/index.d.ts +42 -0
- package/dist/sync/policies/index.d.ts.map +1 -0
- package/dist/sync/policies/index.js +74 -0
- package/dist/sync/policies/index.js.map +1 -0
- package/dist/sync/scanners/b2.cjs +57 -0
- package/dist/sync/scanners/b2.cjs.map +1 -0
- package/dist/sync/scanners/b2.d.cts +20 -0
- package/dist/sync/scanners/b2.d.cts.map +1 -0
- package/dist/sync/scanners/b2.d.ts +20 -0
- package/dist/sync/scanners/b2.d.ts.map +1 -0
- package/dist/sync/scanners/b2.js +57 -0
- package/dist/sync/scanners/b2.js.map +1 -0
- package/dist/sync/scanners/local.cjs +58 -0
- package/dist/sync/scanners/local.cjs.map +1 -0
- package/dist/sync/scanners/local.d.cts +24 -0
- package/dist/sync/scanners/local.d.cts.map +1 -0
- package/dist/sync/scanners/local.d.ts +24 -0
- package/dist/sync/scanners/local.d.ts.map +1 -0
- package/dist/sync/scanners/local.js +58 -0
- package/dist/sync/scanners/local.js.map +1 -0
- package/dist/sync/synchronizer.cjs +203 -0
- package/dist/sync/synchronizer.cjs.map +1 -0
- package/dist/sync/synchronizer.d.cts +52 -0
- package/dist/sync/synchronizer.d.cts.map +1 -0
- package/dist/sync/synchronizer.d.ts +52 -0
- package/dist/sync/synchronizer.d.ts.map +1 -0
- package/dist/sync/synchronizer.js +181 -0
- package/dist/sync/synchronizer.js.map +1 -0
- package/dist/sync/types.d.cts +121 -0
- package/dist/sync/types.d.cts.map +1 -0
- package/dist/sync/types.d.ts +121 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/types/auth.cjs +58 -0
- package/dist/types/auth.cjs.map +1 -0
- package/dist/types/auth.d.cts +150 -0
- package/dist/types/auth.d.cts.map +1 -0
- package/dist/types/auth.d.ts +150 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +58 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/bucket.cjs +44 -0
- package/dist/types/bucket.cjs.map +1 -0
- package/dist/types/bucket.d.cts +245 -0
- package/dist/types/bucket.d.cts.map +1 -0
- package/dist/types/bucket.d.ts +245 -0
- package/dist/types/bucket.d.ts.map +1 -0
- package/dist/types/bucket.js +44 -0
- package/dist/types/bucket.js.map +1 -0
- package/dist/types/download.d.cts +110 -0
- package/dist/types/download.d.cts.map +1 -0
- package/dist/types/download.d.ts +110 -0
- package/dist/types/download.d.ts.map +1 -0
- package/dist/types/encryption.cjs +343 -0
- package/dist/types/encryption.cjs.map +1 -0
- package/dist/types/encryption.d.cts +132 -0
- package/dist/types/encryption.d.cts.map +1 -0
- package/dist/types/encryption.d.ts +132 -0
- package/dist/types/encryption.d.ts.map +1 -0
- package/dist/types/encryption.js +321 -0
- package/dist/types/encryption.js.map +1 -0
- package/dist/types/errors.d.cts +16 -0
- package/dist/types/errors.d.cts.map +1 -0
- package/dist/types/errors.d.ts +16 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/file.cjs +23 -0
- package/dist/types/file.cjs.map +1 -0
- package/dist/types/file.d.cts +220 -0
- package/dist/types/file.d.cts.map +1 -0
- package/dist/types/file.d.ts +220 -0
- package/dist/types/file.d.ts.map +1 -0
- package/dist/types/file.js +23 -0
- package/dist/types/file.js.map +1 -0
- package/dist/types/ids.cjs +27 -0
- package/dist/types/ids.cjs.map +1 -0
- package/dist/types/ids.d.cts +84 -0
- package/dist/types/ids.d.cts.map +1 -0
- package/dist/types/ids.d.ts +84 -0
- package/dist/types/ids.d.ts.map +1 -0
- package/dist/types/ids.js +27 -0
- package/dist/types/ids.js.map +1 -0
- package/dist/types/index.d.cts +25 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.ts +25 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/key.d.cts +84 -0
- package/dist/types/key.d.cts.map +1 -0
- package/dist/types/key.d.ts +84 -0
- package/dist/types/key.d.ts.map +1 -0
- package/dist/types/lock.cjs +17 -0
- package/dist/types/lock.cjs.map +1 -0
- package/dist/types/lock.d.cts +92 -0
- package/dist/types/lock.d.cts.map +1 -0
- package/dist/types/lock.d.ts +92 -0
- package/dist/types/lock.d.ts.map +1 -0
- package/dist/types/lock.js +17 -0
- package/dist/types/lock.js.map +1 -0
- package/dist/types/notifications.cjs +24 -0
- package/dist/types/notifications.cjs.map +1 -0
- package/dist/types/notifications.d.cts +97 -0
- package/dist/types/notifications.d.cts.map +1 -0
- package/dist/types/notifications.d.ts +97 -0
- package/dist/types/notifications.d.ts.map +1 -0
- package/dist/types/notifications.js +24 -0
- package/dist/types/notifications.js.map +1 -0
- package/dist/types/replication.d.cts +42 -0
- package/dist/types/replication.d.cts.map +1 -0
- package/dist/types/replication.d.ts +42 -0
- package/dist/types/replication.d.ts.map +1 -0
- package/dist/types/upload.d.cts +219 -0
- package/dist/types/upload.d.cts.map +1 -0
- package/dist/types/upload.d.ts +219 -0
- package/dist/types/upload.d.ts.map +1 -0
- package/dist/upload/cancel.cjs +10 -0
- package/dist/upload/cancel.cjs.map +1 -0
- package/dist/upload/cancel.d.cts +23 -0
- package/dist/upload/cancel.d.cts.map +1 -0
- package/dist/upload/cancel.d.ts +23 -0
- package/dist/upload/cancel.d.ts.map +1 -0
- package/dist/upload/cancel.js +10 -0
- package/dist/upload/cancel.js.map +1 -0
- package/dist/upload/concurrency.cjs +54 -0
- package/dist/upload/concurrency.cjs.map +1 -0
- package/dist/upload/concurrency.d.cts +46 -0
- package/dist/upload/concurrency.d.cts.map +1 -0
- package/dist/upload/concurrency.d.ts +46 -0
- package/dist/upload/concurrency.d.ts.map +1 -0
- package/dist/upload/concurrency.js +54 -0
- package/dist/upload/concurrency.js.map +1 -0
- package/dist/upload/large.cjs +222 -0
- package/dist/upload/large.cjs.map +1 -0
- package/dist/upload/large.d.cts +71 -0
- package/dist/upload/large.d.cts.map +1 -0
- package/dist/upload/large.d.ts +71 -0
- package/dist/upload/large.d.ts.map +1 -0
- package/dist/upload/large.js +222 -0
- package/dist/upload/large.js.map +1 -0
- package/dist/upload/resume.cjs +34 -0
- package/dist/upload/resume.cjs.map +1 -0
- package/dist/upload/resume.d.cts +33 -0
- package/dist/upload/resume.d.cts.map +1 -0
- package/dist/upload/resume.d.ts +33 -0
- package/dist/upload/resume.d.ts.map +1 -0
- package/dist/upload/resume.js +34 -0
- package/dist/upload/resume.js.map +1 -0
- package/dist/upload/single.cjs +47 -0
- package/dist/upload/single.cjs.map +1 -0
- package/dist/upload/single.d.cts +51 -0
- package/dist/upload/single.d.cts.map +1 -0
- package/dist/upload/single.d.ts +51 -0
- package/dist/upload/single.d.ts.map +1 -0
- package/dist/upload/single.js +47 -0
- package/dist/upload/single.js.map +1 -0
- package/dist/upload/stream.cjs +198 -0
- package/dist/upload/stream.cjs.map +1 -0
- package/dist/upload/stream.d.cts +61 -0
- package/dist/upload/stream.d.cts.map +1 -0
- package/dist/upload/stream.d.ts +61 -0
- package/dist/upload/stream.d.ts.map +1 -0
- package/dist/upload/stream.js +198 -0
- package/dist/upload/stream.js.map +1 -0
- package/dist/util/best-effort.cjs +10 -0
- package/dist/util/best-effort.cjs.map +1 -0
- package/dist/util/best-effort.d.cts +31 -0
- package/dist/util/best-effort.d.cts.map +1 -0
- package/dist/util/best-effort.d.ts +31 -0
- package/dist/util/best-effort.d.ts.map +1 -0
- package/dist/util/best-effort.js +10 -0
- package/dist/util/best-effort.js.map +1 -0
- package/dist/util/defaults.cjs +11 -0
- package/dist/util/defaults.cjs.map +1 -0
- package/dist/util/defaults.d.cts +54 -0
- package/dist/util/defaults.d.cts.map +1 -0
- package/dist/util/defaults.d.ts +54 -0
- package/dist/util/defaults.d.ts.map +1 -0
- package/dist/util/defaults.js +11 -0
- package/dist/util/defaults.js.map +1 -0
- package/dist/util/normalize.cjs +16 -0
- package/dist/util/normalize.cjs.map +1 -0
- package/dist/util/normalize.d.cts +62 -0
- package/dist/util/normalize.d.cts.map +1 -0
- package/dist/util/normalize.d.ts +62 -0
- package/dist/util/normalize.d.ts.map +1 -0
- package/dist/util/normalize.js +16 -0
- package/dist/util/normalize.js.map +1 -0
- package/dist/util/paginator.cjs +20 -0
- package/dist/util/paginator.cjs.map +1 -0
- package/dist/util/paginator.d.cts +120 -0
- package/dist/util/paginator.d.cts.map +1 -0
- package/dist/util/paginator.d.ts +120 -0
- package/dist/util/paginator.d.ts.map +1 -0
- package/dist/util/paginator.js +20 -0
- package/dist/util/paginator.js.map +1 -0
- package/dist/util/plan-ranges.cjs +28 -0
- package/dist/util/plan-ranges.cjs.map +1 -0
- package/dist/util/plan-ranges.d.cts +56 -0
- package/dist/util/plan-ranges.d.cts.map +1 -0
- package/dist/util/plan-ranges.d.ts +56 -0
- package/dist/util/plan-ranges.d.ts.map +1 -0
- package/dist/util/plan-ranges.js +28 -0
- package/dist/util/plan-ranges.js.map +1 -0
- package/dist/util/text-codec.cjs +7 -0
- package/dist/util/text-codec.cjs.map +1 -0
- package/dist/util/text-codec.d.cts +26 -0
- package/dist/util/text-codec.d.cts.map +1 -0
- package/dist/util/text-codec.d.ts +26 -0
- package/dist/util/text-codec.d.ts.map +1 -0
- package/dist/util/text-codec.js +7 -0
- package/dist/util/text-codec.js.map +1 -0
- package/dist/util/to-error.cjs +7 -0
- package/dist/util/to-error.cjs.map +1 -0
- package/dist/util/to-error.d.cts +15 -0
- package/dist/util/to-error.d.cts.map +1 -0
- package/dist/util/to-error.d.ts +15 -0
- package/dist/util/to-error.d.ts.map +1 -0
- package/dist/util/to-error.js +7 -0
- package/dist/util/to-error.js.map +1 -0
- package/dist/version.cjs +6 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.cts +14 -0
- package/dist/version.d.cts.map +1 -0
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/package.json +198 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { AccountInfo } from './auth/account-info.js';
|
|
2
|
+
import { Bucket } from './bucket.js';
|
|
3
|
+
import { RetryOptions } from './http/retry.js';
|
|
4
|
+
import { HttpTransport } from './http/transport.js';
|
|
5
|
+
import { UrlGuard } from './http/url-guard.js';
|
|
6
|
+
import { RawClient } from './raw/index.js';
|
|
7
|
+
import { AuthorizeAccountResponse, Capability } from './types/auth.js';
|
|
8
|
+
import { BucketInfo, BucketType, CorsRule, LifecycleRule, BucketRetentionPolicy } from './types/bucket.js';
|
|
9
|
+
import { EncryptionSetting } from './types/encryption.js';
|
|
10
|
+
import { ApplicationKeyId, BucketId } from './types/ids.js';
|
|
11
|
+
import { ApplicationKey, FullApplicationKey, ListKeysResponse } from './types/key.js';
|
|
12
|
+
import { ReplicationConfiguration } from './types/replication.js';
|
|
13
|
+
import { PaginatorOptions } from './util/paginator.js';
|
|
14
|
+
/** Result of {@link B2Client.hasCapabilities}. */
|
|
15
|
+
export interface CapabilityCheckResult {
|
|
16
|
+
/** `true` when the key carries every requested capability. */
|
|
17
|
+
readonly ok: boolean;
|
|
18
|
+
/** Capabilities the call requested that the current key does not hold. Empty when `ok` is `true`. */
|
|
19
|
+
readonly missing: readonly Capability[];
|
|
20
|
+
}
|
|
21
|
+
/** Configuration options for creating a {@link B2Client}. */
|
|
22
|
+
export interface B2ClientOptions {
|
|
23
|
+
/** The application key ID from the B2 dashboard or `b2_create_key`. */
|
|
24
|
+
readonly applicationKeyId: string;
|
|
25
|
+
/** The application key secret. */
|
|
26
|
+
readonly applicationKey: string;
|
|
27
|
+
/** B2 realm to authenticate against. Defaults to `"production"`. */
|
|
28
|
+
readonly realm?: string;
|
|
29
|
+
/** Storage backend for authorization state. Defaults to {@link InMemoryAccountInfo}. */
|
|
30
|
+
readonly accountInfo?: AccountInfo;
|
|
31
|
+
/** Custom HTTP transport. Defaults to {@link FetchTransport}. Wrapped by {@link RetryTransport}. */
|
|
32
|
+
readonly transport?: HttpTransport;
|
|
33
|
+
/** Override retry behavior (max retries, backoff, jitter). */
|
|
34
|
+
readonly retry?: Partial<RetryOptions>;
|
|
35
|
+
/** Custom user-agent string prepended to the SDK default. */
|
|
36
|
+
readonly userAgent?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Override the SSRF allow-list. By default the SDK locks the
|
|
39
|
+
* {@link FetchTransport} to host suffixes derived from the realm's authorize
|
|
40
|
+
* response (e.g. `backblazeb2.com`, `backblaze.com`) so a compromised B2
|
|
41
|
+
* endpoint cannot redirect the SDK to internal services. Pass an explicit
|
|
42
|
+
* list to add hosts (e.g. when testing against a self-hosted proxy) or set
|
|
43
|
+
* to an empty array to disable the guard entirely (not recommended).
|
|
44
|
+
*
|
|
45
|
+
* Only consulted when {@link B2ClientOptions.transport} is unset; a custom
|
|
46
|
+
* transport is the user's responsibility to harden.
|
|
47
|
+
*/
|
|
48
|
+
readonly allowedHostSuffixes?: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* High-level B2 client providing ergonomic access to buckets, files, and keys.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const client = new B2Client({
|
|
56
|
+
* applicationKeyId: process.env.B2_APPLICATION_KEY_ID,
|
|
57
|
+
* applicationKey: process.env.B2_APPLICATION_KEY,
|
|
58
|
+
* })
|
|
59
|
+
* await client.authorize()
|
|
60
|
+
* const buckets = await client.listBuckets()
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare class B2Client {
|
|
64
|
+
/** Low-level client for direct B2 API calls. */
|
|
65
|
+
readonly raw: RawClient;
|
|
66
|
+
/** Authorization state storage (tokens, URLs, capabilities). */
|
|
67
|
+
readonly accountInfo: AccountInfo;
|
|
68
|
+
/**
|
|
69
|
+
* SSRF allow-list applied by the default {@link FetchTransport}. `null` when
|
|
70
|
+
* a custom transport was supplied — in that case the SDK does not own the
|
|
71
|
+
* guard. Locked down by {@link B2Client.authorize}.
|
|
72
|
+
*/
|
|
73
|
+
readonly urlGuard: UrlGuard | null;
|
|
74
|
+
private readonly applicationKeyId;
|
|
75
|
+
private readonly applicationKey;
|
|
76
|
+
private readonly realmUrl;
|
|
77
|
+
private readonly userAllowedSuffixes;
|
|
78
|
+
/**
|
|
79
|
+
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
80
|
+
* @param options - Configuration including credentials, realm, and transport settings.
|
|
81
|
+
*/
|
|
82
|
+
constructor(options: B2ClientOptions);
|
|
83
|
+
/**
|
|
84
|
+
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
85
|
+
*
|
|
86
|
+
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
87
|
+
*/
|
|
88
|
+
authorize(): Promise<AuthorizeAccountResponse>;
|
|
89
|
+
/**
|
|
90
|
+
* Refresh credentials after a 401. Returns the fresh auth token so
|
|
91
|
+
* {@link RetryTransport} can rewrite the in-flight request's
|
|
92
|
+
* Authorization header before retrying.
|
|
93
|
+
*
|
|
94
|
+
* @returns The fresh authorization token.
|
|
95
|
+
*/
|
|
96
|
+
private reauthorize;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new B2 bucket.
|
|
99
|
+
* @param options - Bucket configuration including name, type, and optional settings.
|
|
100
|
+
*
|
|
101
|
+
* @returns A {@link Bucket} handle for the newly created bucket.
|
|
102
|
+
*/
|
|
103
|
+
createBucket(options: {
|
|
104
|
+
/** Globally unique bucket name (6-50 chars, letters, digits, hyphens). */
|
|
105
|
+
bucketName: string;
|
|
106
|
+
/** Access level: `"allPrivate"` or `"allPublic"`. */
|
|
107
|
+
bucketType: BucketType;
|
|
108
|
+
/** Custom key-value metadata stored with the bucket. */
|
|
109
|
+
bucketInfo?: Record<string, string>;
|
|
110
|
+
/** CORS rules for browser-based access. */
|
|
111
|
+
corsRules?: CorsRule[];
|
|
112
|
+
/** Default server-side encryption for new files. */
|
|
113
|
+
defaultServerSideEncryption?: EncryptionSetting;
|
|
114
|
+
/** Default retention policy for new files (requires file lock). */
|
|
115
|
+
defaultRetention?: BucketRetentionPolicy;
|
|
116
|
+
/** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */
|
|
117
|
+
fileLockEnabled?: boolean;
|
|
118
|
+
/** Lifecycle rules for automatic file deletion or hiding. */
|
|
119
|
+
lifecycleRules?: LifecycleRule[];
|
|
120
|
+
/** Cross-region replication configuration. */
|
|
121
|
+
replicationConfiguration?: ReplicationConfiguration;
|
|
122
|
+
}): Promise<Bucket>;
|
|
123
|
+
/**
|
|
124
|
+
* Lists buckets in the account, optionally filtered by ID, name, or type.
|
|
125
|
+
* @param options - Optional filters for bucket ID, name, or type.
|
|
126
|
+
*
|
|
127
|
+
* @returns An array of {@link Bucket} handles.
|
|
128
|
+
*/
|
|
129
|
+
listBuckets(options?: {
|
|
130
|
+
/** Filter to a specific bucket by ID. */
|
|
131
|
+
bucketId?: BucketId;
|
|
132
|
+
/** Filter to a specific bucket by name. */
|
|
133
|
+
bucketName?: string;
|
|
134
|
+
/** Filter by bucket types (e.g., `["allPrivate"]`). */
|
|
135
|
+
bucketTypes?: BucketType[];
|
|
136
|
+
}): Promise<Bucket[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Looks up a single bucket by name.
|
|
139
|
+
* @param bucketName - The name of the bucket to find.
|
|
140
|
+
*
|
|
141
|
+
* @returns The {@link Bucket} handle, or `null` if not found.
|
|
142
|
+
*/
|
|
143
|
+
getBucket(bucketName: string): Promise<Bucket | null>;
|
|
144
|
+
/**
|
|
145
|
+
* Permanently deletes a bucket. The bucket must be empty.
|
|
146
|
+
* @param id - The unique identifier of the bucket to delete.
|
|
147
|
+
*
|
|
148
|
+
* @returns The deleted bucket metadata.
|
|
149
|
+
*/
|
|
150
|
+
deleteBucket(id: BucketId): Promise<BucketInfo>;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a new application key with the specified capabilities.
|
|
153
|
+
* @param options - Key configuration including capabilities, name, and optional restrictions.
|
|
154
|
+
*
|
|
155
|
+
* @returns The full key including the secret (only returned at creation time).
|
|
156
|
+
*/
|
|
157
|
+
createKey(options: {
|
|
158
|
+
/** Capabilities to grant (e.g., `["readFiles", "writeFiles"]`). */
|
|
159
|
+
capabilities: Capability[];
|
|
160
|
+
/** Human-readable name for the key. */
|
|
161
|
+
keyName: string;
|
|
162
|
+
/** Key expiration in seconds from now. Omit for non-expiring keys. */
|
|
163
|
+
validDurationInSeconds?: number;
|
|
164
|
+
/** Restrict the key to a single bucket. */
|
|
165
|
+
bucketId?: BucketId;
|
|
166
|
+
/** Restrict the key to files with this name prefix. */
|
|
167
|
+
namePrefix?: string;
|
|
168
|
+
}): Promise<FullApplicationKey>;
|
|
169
|
+
/**
|
|
170
|
+
* Lists application keys in the account.
|
|
171
|
+
* @param options - Optional pagination settings.
|
|
172
|
+
*
|
|
173
|
+
* @returns A page of application keys with an optional continuation token.
|
|
174
|
+
*/
|
|
175
|
+
listKeys(options?: {
|
|
176
|
+
/**
|
|
177
|
+
* Maximum number of keys to return per request. Forwarded to the
|
|
178
|
+
* raw API's `maxKeyCount` parameter.
|
|
179
|
+
*/
|
|
180
|
+
pageSize?: number;
|
|
181
|
+
/** Start listing after this key ID (for pagination). */
|
|
182
|
+
startApplicationKeyId?: ApplicationKeyId;
|
|
183
|
+
}): Promise<ListKeysResponse>;
|
|
184
|
+
/**
|
|
185
|
+
* Async iterator that yields every application key on the account,
|
|
186
|
+
* automatically handling pagination via `listKeys`.
|
|
187
|
+
*
|
|
188
|
+
* @param options - Pagination + abort options. `pageSize` is forwarded
|
|
189
|
+
* to `maxKeyCount`; the default is 1000.
|
|
190
|
+
*
|
|
191
|
+
* @returns An async iterable of {@link ApplicationKey} entries.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* for await (const key of client.paginateKeys()) {
|
|
196
|
+
* console.log(key.keyName, key.capabilities)
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
paginateKeys(options?: PaginatorOptions): AsyncIterableIterator<ApplicationKey>;
|
|
201
|
+
/**
|
|
202
|
+
* Permanently deletes an application key.
|
|
203
|
+
* @param applicationKeyId - The unique identifier of the key to delete.
|
|
204
|
+
*
|
|
205
|
+
* @returns The deleted application key metadata.
|
|
206
|
+
*/
|
|
207
|
+
deleteKey(applicationKeyId: ApplicationKeyId): Promise<ApplicationKey>;
|
|
208
|
+
/**
|
|
209
|
+
* Checks whether the authorized application key carries every capability in
|
|
210
|
+
* `needed`. Returns the missing capabilities so callers can fail fast with a
|
|
211
|
+
* clear error instead of a generic 401/403 from the server.
|
|
212
|
+
*
|
|
213
|
+
* @param needed - The capabilities required by the planned operation.
|
|
214
|
+
*
|
|
215
|
+
* @returns An object with `ok: true` when every needed capability is
|
|
216
|
+
* present, otherwise `{ ok: false, missing: [...] }`.
|
|
217
|
+
*
|
|
218
|
+
* @throws If {@link authorize} has not been called yet.
|
|
219
|
+
*/
|
|
220
|
+
hasCapabilities(needed: readonly Capability[]): CapabilityCheckResult;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,OAAO,EAAE,QAAQ,EAAyB,MAAM,qBAAqB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC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AU,EAAE,GAAG,qBAAqB;CAOtE"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { InMemoryAccountInfo } from "./auth/in-memory.js";
|
|
2
|
+
import { getRealmUrl } from "./auth/realms.js";
|
|
3
|
+
import { Bucket } from "./bucket.js";
|
|
4
|
+
import { FetchTransport, RetryTransport } from "./http/transport.js";
|
|
5
|
+
import { UrlGuard, deriveAllowedSuffixes } from "./http/url-guard.js";
|
|
6
|
+
import { RawClient } from "./raw/index.js";
|
|
7
|
+
import { accountId } from "./types/ids.js";
|
|
8
|
+
import { DEFAULT_PAGE_SIZE } from "./util/defaults.js";
|
|
9
|
+
import { paginateItems } from "./util/paginator.js";
|
|
10
|
+
class B2Client {
|
|
11
|
+
/** Low-level client for direct B2 API calls. */
|
|
12
|
+
raw;
|
|
13
|
+
/** Authorization state storage (tokens, URLs, capabilities). */
|
|
14
|
+
accountInfo;
|
|
15
|
+
/**
|
|
16
|
+
* SSRF allow-list applied by the default {@link FetchTransport}. `null` when
|
|
17
|
+
* a custom transport was supplied — in that case the SDK does not own the
|
|
18
|
+
* guard. Locked down by {@link B2Client.authorize}.
|
|
19
|
+
*/
|
|
20
|
+
urlGuard;
|
|
21
|
+
applicationKeyId;
|
|
22
|
+
applicationKey;
|
|
23
|
+
realmUrl;
|
|
24
|
+
userAllowedSuffixes;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
27
|
+
* @param options - Configuration including credentials, realm, and transport settings.
|
|
28
|
+
*/
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.applicationKeyId = options.applicationKeyId;
|
|
31
|
+
this.applicationKey = options.applicationKey;
|
|
32
|
+
this.realmUrl = getRealmUrl(options.realm ?? "production");
|
|
33
|
+
this.accountInfo = options.accountInfo ?? new InMemoryAccountInfo();
|
|
34
|
+
this.userAllowedSuffixes = options.allowedHostSuffixes;
|
|
35
|
+
let baseTransport;
|
|
36
|
+
if (options.transport !== void 0) {
|
|
37
|
+
baseTransport = options.transport;
|
|
38
|
+
this.urlGuard = null;
|
|
39
|
+
} else {
|
|
40
|
+
const urlGuard = new UrlGuard();
|
|
41
|
+
baseTransport = new FetchTransport({
|
|
42
|
+
urlGuard,
|
|
43
|
+
...options.userAgent !== void 0 ? { userAgent: options.userAgent } : {}
|
|
44
|
+
});
|
|
45
|
+
this.urlGuard = urlGuard;
|
|
46
|
+
}
|
|
47
|
+
const retryTransport = new RetryTransport({
|
|
48
|
+
transport: baseTransport,
|
|
49
|
+
...options.retry !== void 0 ? { retry: options.retry } : {},
|
|
50
|
+
onReauth: () => this.reauthorize()
|
|
51
|
+
});
|
|
52
|
+
this.raw = new RawClient({ transport: retryTransport });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
56
|
+
*
|
|
57
|
+
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
58
|
+
*/
|
|
59
|
+
async authorize() {
|
|
60
|
+
const auth = await this.raw.authorizeAccount(
|
|
61
|
+
this.applicationKeyId,
|
|
62
|
+
this.applicationKey,
|
|
63
|
+
this.realmUrl
|
|
64
|
+
);
|
|
65
|
+
this.accountInfo.setAuth(auth);
|
|
66
|
+
if (this.urlGuard !== null) {
|
|
67
|
+
const derived = deriveAllowedSuffixes(auth.apiInfo.storageApi);
|
|
68
|
+
const merged = this.userAllowedSuffixes !== void 0 ? Array.from(/* @__PURE__ */ new Set([...derived, ...this.userAllowedSuffixes])) : derived;
|
|
69
|
+
this.urlGuard.setAllowedSuffixes(merged);
|
|
70
|
+
}
|
|
71
|
+
return auth;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Refresh credentials after a 401. Returns the fresh auth token so
|
|
75
|
+
* {@link RetryTransport} can rewrite the in-flight request's
|
|
76
|
+
* Authorization header before retrying.
|
|
77
|
+
*
|
|
78
|
+
* @returns The fresh authorization token.
|
|
79
|
+
*/
|
|
80
|
+
async reauthorize() {
|
|
81
|
+
this.accountInfo.clear();
|
|
82
|
+
const auth = await this.authorize();
|
|
83
|
+
return auth.authorizationToken;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new B2 bucket.
|
|
87
|
+
* @param options - Bucket configuration including name, type, and optional settings.
|
|
88
|
+
*
|
|
89
|
+
* @returns A {@link Bucket} handle for the newly created bucket.
|
|
90
|
+
*/
|
|
91
|
+
async createBucket(options) {
|
|
92
|
+
const request = {
|
|
93
|
+
accountId: accountId(this.accountInfo.getAccountId()),
|
|
94
|
+
...options
|
|
95
|
+
};
|
|
96
|
+
const info = await this.raw.createBucket(
|
|
97
|
+
this.accountInfo.getApiUrl(),
|
|
98
|
+
this.accountInfo.getAuthToken(),
|
|
99
|
+
request
|
|
100
|
+
);
|
|
101
|
+
return new Bucket(this, info);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Lists buckets in the account, optionally filtered by ID, name, or type.
|
|
105
|
+
* @param options - Optional filters for bucket ID, name, or type.
|
|
106
|
+
*
|
|
107
|
+
* @returns An array of {@link Bucket} handles.
|
|
108
|
+
*/
|
|
109
|
+
async listBuckets(options) {
|
|
110
|
+
const resp = await this.raw.listBuckets(
|
|
111
|
+
this.accountInfo.getApiUrl(),
|
|
112
|
+
this.accountInfo.getAuthToken(),
|
|
113
|
+
{
|
|
114
|
+
accountId: accountId(this.accountInfo.getAccountId()),
|
|
115
|
+
...options
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
return resp.buckets.map((info) => new Bucket(this, info));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Looks up a single bucket by name.
|
|
122
|
+
* @param bucketName - The name of the bucket to find.
|
|
123
|
+
*
|
|
124
|
+
* @returns The {@link Bucket} handle, or `null` if not found.
|
|
125
|
+
*/
|
|
126
|
+
async getBucket(bucketName) {
|
|
127
|
+
const buckets = await this.listBuckets({ bucketName });
|
|
128
|
+
return buckets[0] ?? null;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Permanently deletes a bucket. The bucket must be empty.
|
|
132
|
+
* @param id - The unique identifier of the bucket to delete.
|
|
133
|
+
*
|
|
134
|
+
* @returns The deleted bucket metadata.
|
|
135
|
+
*/
|
|
136
|
+
async deleteBucket(id) {
|
|
137
|
+
return this.raw.deleteBucket(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {
|
|
138
|
+
accountId: accountId(this.accountInfo.getAccountId()),
|
|
139
|
+
bucketId: id
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates a new application key with the specified capabilities.
|
|
144
|
+
* @param options - Key configuration including capabilities, name, and optional restrictions.
|
|
145
|
+
*
|
|
146
|
+
* @returns The full key including the secret (only returned at creation time).
|
|
147
|
+
*/
|
|
148
|
+
async createKey(options) {
|
|
149
|
+
return this.raw.createKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {
|
|
150
|
+
accountId: accountId(this.accountInfo.getAccountId()),
|
|
151
|
+
...options
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Lists application keys in the account.
|
|
156
|
+
* @param options - Optional pagination settings.
|
|
157
|
+
*
|
|
158
|
+
* @returns A page of application keys with an optional continuation token.
|
|
159
|
+
*/
|
|
160
|
+
async listKeys(options) {
|
|
161
|
+
return this.raw.listKeys(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {
|
|
162
|
+
accountId: accountId(this.accountInfo.getAccountId()),
|
|
163
|
+
...options?.pageSize !== void 0 ? { maxKeyCount: options.pageSize } : {},
|
|
164
|
+
...options?.startApplicationKeyId !== void 0 ? { startApplicationKeyId: options.startApplicationKeyId } : {}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Async iterator that yields every application key on the account,
|
|
169
|
+
* automatically handling pagination via `listKeys`.
|
|
170
|
+
*
|
|
171
|
+
* @param options - Pagination + abort options. `pageSize` is forwarded
|
|
172
|
+
* to `maxKeyCount`; the default is 1000.
|
|
173
|
+
*
|
|
174
|
+
* @returns An async iterable of {@link ApplicationKey} entries.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* for await (const key of client.paginateKeys()) {
|
|
179
|
+
* console.log(key.keyName, key.capabilities)
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
paginateKeys(options) {
|
|
184
|
+
return paginateItems(
|
|
185
|
+
async (cursor) => {
|
|
186
|
+
const resp = await this.listKeys({
|
|
187
|
+
pageSize: options?.pageSize ?? DEFAULT_PAGE_SIZE,
|
|
188
|
+
...cursor !== void 0 ? { startApplicationKeyId: cursor } : {}
|
|
189
|
+
});
|
|
190
|
+
return { page: resp, nextCursor: resp.nextApplicationKeyId ?? void 0 };
|
|
191
|
+
},
|
|
192
|
+
(page) => page.keys,
|
|
193
|
+
options?.signal
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Permanently deletes an application key.
|
|
198
|
+
* @param applicationKeyId - The unique identifier of the key to delete.
|
|
199
|
+
*
|
|
200
|
+
* @returns The deleted application key metadata.
|
|
201
|
+
*/
|
|
202
|
+
async deleteKey(applicationKeyId) {
|
|
203
|
+
return this.raw.deleteKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {
|
|
204
|
+
applicationKeyId
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Checks whether the authorized application key carries every capability in
|
|
209
|
+
* `needed`. Returns the missing capabilities so callers can fail fast with a
|
|
210
|
+
* clear error instead of a generic 401/403 from the server.
|
|
211
|
+
*
|
|
212
|
+
* @param needed - The capabilities required by the planned operation.
|
|
213
|
+
*
|
|
214
|
+
* @returns An object with `ok: true` when every needed capability is
|
|
215
|
+
* present, otherwise `{ ok: false, missing: [...] }`.
|
|
216
|
+
*
|
|
217
|
+
* @throws If {@link authorize} has not been called yet.
|
|
218
|
+
*/
|
|
219
|
+
hasCapabilities(needed) {
|
|
220
|
+
const auth = this.accountInfo.getAuth();
|
|
221
|
+
if (!auth) throw new Error("Not authorized. Call authorize() first.");
|
|
222
|
+
const available = new Set(auth.apiInfo.storageApi.allowed.capabilities);
|
|
223
|
+
const missing = needed.filter((cap) => !available.has(cap));
|
|
224
|
+
return { ok: missing.length === 0, missing };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export {
|
|
228
|
+
B2Client
|
|
229
|
+
};
|
|
230
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../src/client.ts"],"sourcesContent":["import type { AccountInfo } from './auth/account-info.ts'\nimport { InMemoryAccountInfo } from './auth/in-memory.ts'\nimport { getRealmUrl } from './auth/realms.ts'\nimport { Bucket } from './bucket.ts'\nimport type { RetryOptions } from './http/retry.ts'\nimport type { HttpTransport } from './http/transport.ts'\nimport { FetchTransport, RetryTransport } from './http/transport.ts'\nimport { UrlGuard, deriveAllowedSuffixes } from './http/url-guard.ts'\nimport { RawClient } from './raw/index.ts'\nimport type { AuthorizeAccountResponse, Capability } from './types/auth.ts'\nimport type {\n BucketInfo,\n BucketType,\n CorsRule,\n CreateBucketRequest,\n LifecycleRule,\n} from './types/bucket.ts'\nimport type { BucketRetentionPolicy } from './types/bucket.ts'\nimport type { EncryptionSetting } from './types/encryption.ts'\nimport type { ApplicationKeyId, BucketId } from './types/ids.ts'\nimport { accountId } from './types/ids.ts'\nimport type { ApplicationKey, FullApplicationKey, ListKeysResponse } from './types/key.ts'\nimport type { ReplicationConfiguration } from './types/replication.ts'\nimport { DEFAULT_PAGE_SIZE } from './util/defaults.ts'\nimport { type PaginatorOptions, paginateItems } from './util/paginator.ts'\n\n/** Result of {@link B2Client.hasCapabilities}. */\nexport interface CapabilityCheckResult {\n /** `true` when the key carries every requested capability. */\n readonly ok: boolean\n /** Capabilities the call requested that the current key does not hold. Empty when `ok` is `true`. */\n readonly missing: readonly Capability[]\n}\n\n/** Configuration options for creating a {@link B2Client}. */\nexport interface B2ClientOptions {\n /** The application key ID from the B2 dashboard or `b2_create_key`. */\n readonly applicationKeyId: string\n /** The application key secret. */\n readonly applicationKey: string\n /** B2 realm to authenticate against. Defaults to `\"production\"`. */\n readonly realm?: string\n /** Storage backend for authorization state. Defaults to {@link InMemoryAccountInfo}. */\n readonly accountInfo?: AccountInfo\n /** Custom HTTP transport. Defaults to {@link FetchTransport}. Wrapped by {@link RetryTransport}. */\n readonly transport?: HttpTransport\n /** Override retry behavior (max retries, backoff, jitter). */\n readonly retry?: Partial<RetryOptions>\n /** Custom user-agent string prepended to the SDK default. */\n readonly userAgent?: string\n /**\n * Override the SSRF allow-list. By default the SDK locks the\n * {@link FetchTransport} to host suffixes derived from the realm's authorize\n * response (e.g. `backblazeb2.com`, `backblaze.com`) so a compromised B2\n * endpoint cannot redirect the SDK to internal services. Pass an explicit\n * list to add hosts (e.g. when testing against a self-hosted proxy) or set\n * to an empty array to disable the guard entirely (not recommended).\n *\n * Only consulted when {@link B2ClientOptions.transport} is unset; a custom\n * transport is the user's responsibility to harden.\n */\n readonly allowedHostSuffixes?: readonly string[]\n}\n\n/**\n * High-level B2 client providing ergonomic access to buckets, files, and keys.\n *\n * @example\n * ```ts\n * const client = new B2Client({\n * applicationKeyId: process.env.B2_APPLICATION_KEY_ID,\n * applicationKey: process.env.B2_APPLICATION_KEY,\n * })\n * await client.authorize()\n * const buckets = await client.listBuckets()\n * ```\n */\nexport class B2Client {\n /** Low-level client for direct B2 API calls. */\n readonly raw: RawClient\n /** Authorization state storage (tokens, URLs, capabilities). */\n readonly accountInfo: AccountInfo\n /**\n * SSRF allow-list applied by the default {@link FetchTransport}. `null` when\n * a custom transport was supplied — in that case the SDK does not own the\n * guard. Locked down by {@link B2Client.authorize}.\n */\n readonly urlGuard: UrlGuard | null\n private readonly applicationKeyId: string\n private readonly applicationKey: string\n private readonly realmUrl: string\n private readonly userAllowedSuffixes: readonly string[] | undefined\n\n /**\n * Creates a new B2Client. Call {@link authorize} before making API requests.\n * @param options - Configuration including credentials, realm, and transport settings.\n */\n constructor(options: B2ClientOptions) {\n this.applicationKeyId = options.applicationKeyId\n this.applicationKey = options.applicationKey\n this.realmUrl = getRealmUrl(options.realm ?? 'production')\n this.accountInfo = options.accountInfo ?? new InMemoryAccountInfo()\n this.userAllowedSuffixes = options.allowedHostSuffixes\n\n let baseTransport: HttpTransport\n if (options.transport !== undefined) {\n baseTransport = options.transport\n this.urlGuard = null\n } else {\n const urlGuard = new UrlGuard()\n baseTransport = new FetchTransport({\n urlGuard,\n ...(options.userAgent !== undefined ? { userAgent: options.userAgent } : {}),\n })\n this.urlGuard = urlGuard\n }\n\n const retryTransport = new RetryTransport({\n transport: baseTransport,\n ...(options.retry !== undefined ? { retry: options.retry } : {}),\n onReauth: () => this.reauthorize(),\n })\n\n this.raw = new RawClient({ transport: retryTransport })\n }\n\n /**\n * Authenticates with B2 and stores the authorization state. Must be called before other methods.\n *\n * @returns The authorization response containing tokens, URLs, and capabilities.\n */\n async authorize(): Promise<AuthorizeAccountResponse> {\n const auth = await this.raw.authorizeAccount(\n this.applicationKeyId,\n this.applicationKey,\n this.realmUrl,\n )\n this.accountInfo.setAuth(auth)\n // Lock the SSRF guard to the realm's hosts (plus any user additions).\n // No-op when the caller supplied a custom transport: their threat model.\n if (this.urlGuard !== null) {\n const derived = deriveAllowedSuffixes(auth.apiInfo.storageApi)\n const merged =\n this.userAllowedSuffixes !== undefined\n ? Array.from(new Set([...derived, ...this.userAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\n return auth\n }\n\n /**\n * Refresh credentials after a 401. Returns the fresh auth token so\n * {@link RetryTransport} can rewrite the in-flight request's\n * Authorization header before retrying.\n *\n * @returns The fresh authorization token.\n */\n private async reauthorize(): Promise<string> {\n this.accountInfo.clear()\n const auth = await this.authorize()\n return auth.authorizationToken\n }\n\n /**\n * Creates a new B2 bucket.\n * @param options - Bucket configuration including name, type, and optional settings.\n *\n * @returns A {@link Bucket} handle for the newly created bucket.\n */\n async createBucket(options: {\n /** Globally unique bucket name (6-50 chars, letters, digits, hyphens). */\n bucketName: string\n /** Access level: `\"allPrivate\"` or `\"allPublic\"`. */\n bucketType: BucketType\n /** Custom key-value metadata stored with the bucket. */\n bucketInfo?: Record<string, string>\n /** CORS rules for browser-based access. */\n corsRules?: CorsRule[]\n /** Default server-side encryption for new files. */\n defaultServerSideEncryption?: EncryptionSetting\n /** Default retention policy for new files (requires file lock). */\n defaultRetention?: BucketRetentionPolicy\n /** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */\n fileLockEnabled?: boolean\n /** Lifecycle rules for automatic file deletion or hiding. */\n lifecycleRules?: LifecycleRule[]\n /** Cross-region replication configuration. */\n replicationConfiguration?: ReplicationConfiguration\n }): Promise<Bucket> {\n const request: CreateBucketRequest = {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n }\n const info = await this.raw.createBucket(\n this.accountInfo.getApiUrl(),\n this.accountInfo.getAuthToken(),\n request,\n )\n return new Bucket(this, info)\n }\n\n /**\n * Lists buckets in the account, optionally filtered by ID, name, or type.\n * @param options - Optional filters for bucket ID, name, or type.\n *\n * @returns An array of {@link Bucket} handles.\n */\n async listBuckets(options?: {\n /** Filter to a specific bucket by ID. */\n bucketId?: BucketId\n /** Filter to a specific bucket by name. */\n bucketName?: string\n /** Filter by bucket types (e.g., `[\"allPrivate\"]`). */\n bucketTypes?: BucketType[]\n }): Promise<Bucket[]> {\n const resp = await this.raw.listBuckets(\n this.accountInfo.getApiUrl(),\n this.accountInfo.getAuthToken(),\n {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n },\n )\n return resp.buckets.map((info) => new Bucket(this, info))\n }\n\n /**\n * Looks up a single bucket by name.\n * @param bucketName - The name of the bucket to find.\n *\n * @returns The {@link Bucket} handle, or `null` if not found.\n */\n async getBucket(bucketName: string): Promise<Bucket | null> {\n const buckets = await this.listBuckets({ bucketName })\n return buckets[0] ?? null\n }\n\n /**\n * Permanently deletes a bucket. The bucket must be empty.\n * @param id - The unique identifier of the bucket to delete.\n *\n * @returns The deleted bucket metadata.\n */\n async deleteBucket(id: BucketId): Promise<BucketInfo> {\n return this.raw.deleteBucket(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n bucketId: id,\n })\n }\n\n /**\n * Creates a new application key with the specified capabilities.\n * @param options - Key configuration including capabilities, name, and optional restrictions.\n *\n * @returns The full key including the secret (only returned at creation time).\n */\n async createKey(options: {\n /** Capabilities to grant (e.g., `[\"readFiles\", \"writeFiles\"]`). */\n capabilities: Capability[]\n /** Human-readable name for the key. */\n keyName: string\n /** Key expiration in seconds from now. Omit for non-expiring keys. */\n validDurationInSeconds?: number\n /** Restrict the key to a single bucket. */\n bucketId?: BucketId\n /** Restrict the key to files with this name prefix. */\n namePrefix?: string\n }): Promise<FullApplicationKey> {\n return this.raw.createKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n })\n }\n\n /**\n * Lists application keys in the account.\n * @param options - Optional pagination settings.\n *\n * @returns A page of application keys with an optional continuation token.\n */\n async listKeys(options?: {\n /**\n * Maximum number of keys to return per request. Forwarded to the\n * raw API's `maxKeyCount` parameter.\n */\n pageSize?: number\n /** Start listing after this key ID (for pagination). */\n startApplicationKeyId?: ApplicationKeyId\n }): Promise<ListKeysResponse> {\n return this.raw.listKeys(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...(options?.pageSize !== undefined ? { maxKeyCount: options.pageSize } : {}),\n ...(options?.startApplicationKeyId !== undefined\n ? { startApplicationKeyId: options.startApplicationKeyId }\n : {}),\n })\n }\n\n /**\n * Async iterator that yields every application key on the account,\n * automatically handling pagination via `listKeys`.\n *\n * @param options - Pagination + abort options. `pageSize` is forwarded\n * to `maxKeyCount`; the default is 1000.\n *\n * @returns An async iterable of {@link ApplicationKey} entries.\n *\n * @example\n * ```ts\n * for await (const key of client.paginateKeys()) {\n * console.log(key.keyName, key.capabilities)\n * }\n * ```\n */\n paginateKeys(options?: PaginatorOptions): AsyncIterableIterator<ApplicationKey> {\n return paginateItems(\n async (cursor: ApplicationKeyId | undefined) => {\n const resp = await this.listKeys({\n pageSize: options?.pageSize ?? DEFAULT_PAGE_SIZE,\n ...(cursor !== undefined ? { startApplicationKeyId: cursor } : {}),\n })\n return { page: resp, nextCursor: resp.nextApplicationKeyId ?? undefined }\n },\n (page) => page.keys,\n options?.signal,\n )\n }\n\n /**\n * Permanently deletes an application key.\n * @param applicationKeyId - The unique identifier of the key to delete.\n *\n * @returns The deleted application key metadata.\n */\n async deleteKey(applicationKeyId: ApplicationKeyId): Promise<ApplicationKey> {\n return this.raw.deleteKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n applicationKeyId,\n })\n }\n\n /**\n * Checks whether the authorized application key carries every capability in\n * `needed`. Returns the missing capabilities so callers can fail fast with a\n * clear error instead of a generic 401/403 from the server.\n *\n * @param needed - The capabilities required by the planned operation.\n *\n * @returns An object with `ok: true` when every needed capability is\n * present, otherwise `{ ok: false, missing: [...] }`.\n *\n * @throws If {@link authorize} has not been called yet.\n */\n hasCapabilities(needed: readonly Capability[]): CapabilityCheckResult {\n const auth = this.accountInfo.getAuth()\n if (!auth) throw new Error('Not authorized. Call authorize() first.')\n const available = new Set<string>(auth.apiInfo.storageApi.allowed.capabilities)\n const missing = needed.filter((cap) => !available.has(cap as string))\n return { ok: missing.length === 0, missing }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AA6EO,MAAM,SAAS;AAAA;AAAA,EAEX;AAAA;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA,EACQ;AAAA,EACA;AAAA,EACA;AAA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;AAAA;AAAA,EAcA,gBAAgB,QAAsD;AACpE,UAAM,OAAO,KAAK,YAAY,QAAA;AAC9B,QAAI,CAAC,KAAM,OAAM,IAAI,MAAM,yCAAyC;AACpE,UAAM,YAAY,IAAI,IAAY,KAAK,QAAQ,WAAW,QAAQ,YAAY;AAC9E,UAAM,UAAU,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,IAAI,GAAa,CAAC;AACpE,WAAO,EAAE,IAAI,QAAQ,WAAW,GAAG,QAAA;AAAA,EACrC;AACF;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const ids = require("../types/ids.cjs");
|
|
4
|
+
const cancel = require("../upload/cancel.cjs");
|
|
5
|
+
const concurrency = require("../upload/concurrency.cjs");
|
|
6
|
+
const defaults = require("../util/defaults.cjs");
|
|
7
|
+
const planRanges = require("../util/plan-ranges.cjs");
|
|
8
|
+
async function copyLargeFile(raw, accountInfo, options) {
|
|
9
|
+
const recommendedPartSize = accountInfo.getRecommendedPartSize();
|
|
10
|
+
const minPartSize = accountInfo.getAbsoluteMinimumPartSize();
|
|
11
|
+
const partSize = Math.max(options.partSize ?? recommendedPartSize, minPartSize);
|
|
12
|
+
const concurrency$1 = options.concurrency ?? defaults.DEFAULT_TRANSFER_CONCURRENCY;
|
|
13
|
+
const sourceInfo = await raw.getFileInfo(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
14
|
+
fileId: options.sourceFileId
|
|
15
|
+
});
|
|
16
|
+
const totalSize = sourceInfo.contentLength;
|
|
17
|
+
if (totalSize <= partSize) {
|
|
18
|
+
return raw.copyFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
19
|
+
sourceFileId: options.sourceFileId,
|
|
20
|
+
fileName: options.fileName,
|
|
21
|
+
...options.destinationBucketId !== void 0 ? { destinationBucketId: options.destinationBucketId } : {},
|
|
22
|
+
...options.contentType !== void 0 ? { contentType: options.contentType } : {},
|
|
23
|
+
...options.fileInfo !== void 0 ? { fileInfo: options.fileInfo } : {},
|
|
24
|
+
...options.destinationServerSideEncryption !== void 0 ? { destinationServerSideEncryption: options.destinationServerSideEncryption } : {},
|
|
25
|
+
...options.sourceServerSideEncryption !== void 0 ? { sourceServerSideEncryption: options.sourceServerSideEncryption } : {}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const destBucketId = options.destinationBucketId ?? sourceInfo.bucketId;
|
|
29
|
+
const startResp = await raw.startLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
30
|
+
bucketId: destBucketId,
|
|
31
|
+
fileName: options.fileName,
|
|
32
|
+
contentType: options.contentType ?? sourceInfo.contentType ?? defaults.DEFAULT_CONTENT_TYPE,
|
|
33
|
+
fileInfo: options.fileInfo ?? {},
|
|
34
|
+
...options.destinationServerSideEncryption !== void 0 ? { serverSideEncryption: options.destinationServerSideEncryption } : {}
|
|
35
|
+
});
|
|
36
|
+
const largeFileId = startResp.fileId;
|
|
37
|
+
const ranges = planRanges.planRanges(totalSize, partSize);
|
|
38
|
+
const partSha1s = new Array(ranges.length);
|
|
39
|
+
const sem = new concurrency.Semaphore(concurrency$1);
|
|
40
|
+
try {
|
|
41
|
+
options.signal?.throwIfAborted();
|
|
42
|
+
await Promise.all(
|
|
43
|
+
ranges.map(async (range) => {
|
|
44
|
+
await sem.acquire();
|
|
45
|
+
try {
|
|
46
|
+
options.signal?.throwIfAborted();
|
|
47
|
+
const resp = await raw.copyPart(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
48
|
+
sourceFileId: options.sourceFileId,
|
|
49
|
+
// `startLargeFile` returns `LargeFileId`; `copyPart` takes the
|
|
50
|
+
// same value typed as `FileId`. Re-brand via the factory.
|
|
51
|
+
largeFileId: ids.fileId(largeFileId),
|
|
52
|
+
partNumber: range.partNumber,
|
|
53
|
+
range: planRanges.byteRangeHeader(range.start, range.end),
|
|
54
|
+
...options.sourceServerSideEncryption !== void 0 ? { sourceServerSideEncryption: options.sourceServerSideEncryption } : {},
|
|
55
|
+
...options.destinationServerSideEncryption !== void 0 ? { destinationServerSideEncryption: options.destinationServerSideEncryption } : {}
|
|
56
|
+
});
|
|
57
|
+
partSha1s[range.partNumber - 1] = resp.contentSha1;
|
|
58
|
+
} finally {
|
|
59
|
+
sem.release();
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
options.signal?.throwIfAborted();
|
|
64
|
+
return await raw.finishLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
65
|
+
fileId: largeFileId,
|
|
66
|
+
partSha1Array: partSha1s
|
|
67
|
+
});
|
|
68
|
+
} catch (err) {
|
|
69
|
+
await cancel.cancelLargeFileBestEffort(raw, accountInfo, largeFileId);
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.copyLargeFile = copyLargeFile;
|
|
74
|
+
//# sourceMappingURL=large.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"large.cjs","sources":["../../src/copy/large.ts"],"sourcesContent":["import type { AccountInfo } from '../auth/account-info.ts'\nimport type { RawClient } from '../raw/index.ts'\nimport type { EncryptionSetting } from '../types/encryption.ts'\nimport type { FileVersion } from '../types/file.ts'\nimport { type BucketId, type FileId, fileId as fileIdOf } from '../types/ids.ts'\nimport { cancelLargeFileBestEffort } from '../upload/cancel.ts'\nimport { Semaphore } from '../upload/concurrency.ts'\nimport { DEFAULT_CONTENT_TYPE, DEFAULT_TRANSFER_CONCURRENCY } from '../util/defaults.ts'\nimport { byteRangeHeader, planRanges } from '../util/plan-ranges.ts'\n\n/** Options for a server-side multipart copy. */\nexport interface CopyLargeFileOptions {\n /** ID of the source file version to copy. */\n readonly sourceFileId: FileId\n /** Destination file name in the target bucket. */\n readonly fileName: string\n /** Target bucket. Defaults to the source's bucket. */\n readonly destinationBucketId?: BucketId\n /** Size of each part in bytes. Defaults to the account's recommended part size. */\n readonly partSize?: number\n /**\n * Maximum number of parts copied in parallel. Defaults to\n * {@link DEFAULT_TRANSFER_CONCURRENCY}.\n */\n readonly concurrency?: number\n /** MIME type for the destination file. Defaults to `b2/x-auto`. */\n readonly contentType?: string\n /** Custom file info merged into the destination. */\n readonly fileInfo?: Record<string, string>\n /** Server-side encryption applied to the destination. */\n readonly destinationServerSideEncryption?: EncryptionSetting\n /** SSE-C settings used to read the source if it was uploaded with SSE-C. */\n readonly sourceServerSideEncryption?: EncryptionSetting\n /**\n * Optional abort signal. Checked before dispatching each part and\n * between parts; an aborted signal cancels remaining parts and rolls\n * back the unfinished large file via best-effort `cancelLargeFile`.\n *\n * Aborting does NOT roll back parts already accepted by B2; those\n * exist on the unfinished large file until the cancel call completes\n * or B2's lifecycle expires the in-progress upload (24 hours).\n */\n readonly signal?: AbortSignal\n}\n\n/**\n * Performs a server-side copy of a file using the multipart `b2_copy_part` protocol.\n * The source bytes never traverse the client; B2 copies each range internally.\n *\n * Falls back to a single `copyFile` call when the source fits in one part.\n *\n * @param raw - Low-level B2 API client.\n * @param accountInfo - Authorized account state (used to resolve API URL, recommended part size).\n * @param options - Copy parameters including source, destination, and concurrency.\n *\n * @returns The resulting destination {@link FileVersion}.\n */\nexport async function copyLargeFile(\n raw: RawClient,\n accountInfo: AccountInfo,\n options: CopyLargeFileOptions,\n): Promise<FileVersion> {\n const recommendedPartSize = accountInfo.getRecommendedPartSize()\n const minPartSize = accountInfo.getAbsoluteMinimumPartSize()\n const partSize = Math.max(options.partSize ?? recommendedPartSize, minPartSize)\n const concurrency = options.concurrency ?? DEFAULT_TRANSFER_CONCURRENCY\n\n // Discover the source size via getFileInfo.\n const sourceInfo = await raw.getFileInfo(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n fileId: options.sourceFileId,\n })\n const totalSize = sourceInfo.contentLength\n\n // Below the part threshold, take the single-call fast path.\n if (totalSize <= partSize) {\n return raw.copyFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n sourceFileId: options.sourceFileId,\n fileName: options.fileName,\n ...(options.destinationBucketId !== undefined\n ? { destinationBucketId: options.destinationBucketId }\n : {}),\n ...(options.contentType !== undefined ? { contentType: options.contentType } : {}),\n ...(options.fileInfo !== undefined ? { fileInfo: options.fileInfo } : {}),\n ...(options.destinationServerSideEncryption !== undefined\n ? { destinationServerSideEncryption: options.destinationServerSideEncryption }\n : {}),\n ...(options.sourceServerSideEncryption !== undefined\n ? { sourceServerSideEncryption: options.sourceServerSideEncryption }\n : {}),\n })\n }\n\n // Resolve destination bucket (defaults to source's bucket). Both operands\n // are already typed `BucketId`, so no cast is needed.\n const destBucketId = options.destinationBucketId ?? sourceInfo.bucketId\n\n // Start the multipart file.\n const startResp = await raw.startLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n bucketId: destBucketId,\n fileName: options.fileName,\n contentType: options.contentType ?? sourceInfo.contentType ?? DEFAULT_CONTENT_TYPE,\n fileInfo: options.fileInfo ?? {},\n ...(options.destinationServerSideEncryption !== undefined\n ? { serverSideEncryption: options.destinationServerSideEncryption }\n : {}),\n })\n const largeFileId = startResp.fileId\n\n const ranges = planRanges(totalSize, partSize)\n const partSha1s: string[] = new Array(ranges.length)\n const sem = new Semaphore(concurrency)\n\n try {\n options.signal?.throwIfAborted()\n await Promise.all(\n ranges.map(async (range) => {\n await sem.acquire()\n try {\n // Re-check the abort flag after every queue handoff so the\n // first cancelled task short-circuits the remaining parts.\n options.signal?.throwIfAborted()\n const resp = await raw.copyPart(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n sourceFileId: options.sourceFileId,\n // `startLargeFile` returns `LargeFileId`; `copyPart` takes the\n // same value typed as `FileId`. Re-brand via the factory.\n largeFileId: fileIdOf(largeFileId),\n partNumber: range.partNumber,\n range: byteRangeHeader(range.start, range.end),\n ...(options.sourceServerSideEncryption !== undefined\n ? { sourceServerSideEncryption: options.sourceServerSideEncryption }\n : {}),\n ...(options.destinationServerSideEncryption !== undefined\n ? { destinationServerSideEncryption: options.destinationServerSideEncryption }\n : {}),\n })\n partSha1s[range.partNumber - 1] = resp.contentSha1\n } finally {\n sem.release()\n }\n }),\n )\n\n options.signal?.throwIfAborted()\n return await raw.finishLargeFile(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {\n fileId: largeFileId,\n partSha1Array: partSha1s,\n })\n } catch (err) {\n await cancelLargeFileBestEffort(raw, accountInfo, largeFileId)\n throw err\n }\n}\n"],"names":["concurrency","DEFAULT_TRANSFER_CONCURRENCY","DEFAULT_CONTENT_TYPE","planRanges","Semaphore","fileIdOf","byteRangeHeader","cancelLargeFileBestEffort"],"mappings":";;;;;;;AAyDA,eAAsB,cACpB,KACA,aACA,SACsB;AACtB,QAAM,sBAAsB,YAAY,uBAAA;AACxC,QAAM,cAAc,YAAY,2BAAA;AAChC,QAAM,WAAW,KAAK,IAAI,QAAQ,YAAY,qBAAqB,WAAW;AAC9E,QAAMA,gBAAc,QAAQ,eAAeC,SAAAA;AAG3C,QAAM,aAAa,MAAM,IAAI,YAAY,YAAY,UAAA,GAAa,YAAY,gBAAgB;AAAA,IAC5F,QAAQ,QAAQ;AAAA,EAAA,CACjB;AACD,QAAM,YAAY,WAAW;AAG7B,MAAI,aAAa,UAAU;AACzB,WAAO,IAAI,SAAS,YAAY,aAAa,YAAY,gBAAgB;AAAA,MACvE,cAAc,QAAQ;AAAA,MACtB,UAAU,QAAQ;AAAA,MAClB,GAAI,QAAQ,wBAAwB,SAChC,EAAE,qBAAqB,QAAQ,oBAAA,IAC/B,CAAA;AAAA,MACJ,GAAI,QAAQ,gBAAgB,SAAY,EAAE,aAAa,QAAQ,YAAA,IAAgB,CAAA;AAAA,MAC/E,GAAI,QAAQ,aAAa,SAAY,EAAE,UAAU,QAAQ,SAAA,IAAa,CAAA;AAAA,MACtE,GAAI,QAAQ,oCAAoC,SAC5C,EAAE,iCAAiC,QAAQ,gCAAA,IAC3C,CAAA;AAAA,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;AAAA,QACN;AAAA,MACF,CAAC;AAAA,IAAA;AAGH,YAAQ,QAAQ,eAAA;AAChB,WAAO,MAAM,IAAI,gBAAgB,YAAY,aAAa,YAAY,gBAAgB;AAAA,MACpF,QAAQ;AAAA,MACR,eAAe;AAAA,IAAA,CAChB;AAAA,EACH,SAAS,KAAK;AACZ,UAAMC,iCAA0B,KAAK,aAAa,WAAW;AAC7D,UAAM;AAAA,EACR;AACF;;"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AccountInfo } from '../auth/account-info.js';
|
|
2
|
+
import { RawClient } from '../raw/index.js';
|
|
3
|
+
import { EncryptionSetting } from '../types/encryption.js';
|
|
4
|
+
import { FileVersion } from '../types/file.js';
|
|
5
|
+
import { BucketId, FileId } from '../types/ids.js';
|
|
6
|
+
/** Options for a server-side multipart copy. */
|
|
7
|
+
export interface CopyLargeFileOptions {
|
|
8
|
+
/** ID of the source file version to copy. */
|
|
9
|
+
readonly sourceFileId: FileId;
|
|
10
|
+
/** Destination file name in the target bucket. */
|
|
11
|
+
readonly fileName: string;
|
|
12
|
+
/** Target bucket. Defaults to the source's bucket. */
|
|
13
|
+
readonly destinationBucketId?: BucketId;
|
|
14
|
+
/** Size of each part in bytes. Defaults to the account's recommended part size. */
|
|
15
|
+
readonly partSize?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum number of parts copied in parallel. Defaults to
|
|
18
|
+
* {@link DEFAULT_TRANSFER_CONCURRENCY}.
|
|
19
|
+
*/
|
|
20
|
+
readonly concurrency?: number;
|
|
21
|
+
/** MIME type for the destination file. Defaults to `b2/x-auto`. */
|
|
22
|
+
readonly contentType?: string;
|
|
23
|
+
/** Custom file info merged into the destination. */
|
|
24
|
+
readonly fileInfo?: Record<string, string>;
|
|
25
|
+
/** Server-side encryption applied to the destination. */
|
|
26
|
+
readonly destinationServerSideEncryption?: EncryptionSetting;
|
|
27
|
+
/** SSE-C settings used to read the source if it was uploaded with SSE-C. */
|
|
28
|
+
readonly sourceServerSideEncryption?: EncryptionSetting;
|
|
29
|
+
/**
|
|
30
|
+
* Optional abort signal. Checked before dispatching each part and
|
|
31
|
+
* between parts; an aborted signal cancels remaining parts and rolls
|
|
32
|
+
* back the unfinished large file via best-effort `cancelLargeFile`.
|
|
33
|
+
*
|
|
34
|
+
* Aborting does NOT roll back parts already accepted by B2; those
|
|
35
|
+
* exist on the unfinished large file until the cancel call completes
|
|
36
|
+
* or B2's lifecycle expires the in-progress upload (24 hours).
|
|
37
|
+
*/
|
|
38
|
+
readonly signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Performs a server-side copy of a file using the multipart `b2_copy_part` protocol.
|
|
42
|
+
* The source bytes never traverse the client; B2 copies each range internally.
|
|
43
|
+
*
|
|
44
|
+
* Falls back to a single `copyFile` call when the source fits in one part.
|
|
45
|
+
*
|
|
46
|
+
* @param raw - Low-level B2 API client.
|
|
47
|
+
* @param accountInfo - Authorized account state (used to resolve API URL, recommended part size).
|
|
48
|
+
* @param options - Copy parameters including source, destination, and concurrency.
|
|
49
|
+
*
|
|
50
|
+
* @returns The resulting destination {@link FileVersion}.
|
|
51
|
+
*/
|
|
52
|
+
export declare function copyLargeFile(raw: RawClient, accountInfo: AccountInfo, options: CopyLargeFileOptions): Promise<FileVersion>;
|
|
53
|
+
//# sourceMappingURL=large.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"large.d.ts","sourceRoot":"","sources":["../../src/copy/large.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAA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