@backblaze-labs/b2-sdk 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -1
- package/README.md +38 -7
- package/dist/_virtual/_b2-sdk-version-json.cjs +1 -1
- package/dist/_virtual/_b2-sdk-version-json.js +1 -1
- package/dist/auth/file.cjs.map +1 -1
- package/dist/auth/reauth-coalescer.cjs +65 -0
- package/dist/auth/reauth-coalescer.cjs.map +1 -0
- package/dist/auth/reauth-coalescer.d.cts +34 -0
- package/dist/auth/reauth-coalescer.d.cts.map +1 -0
- package/dist/auth/reauth-coalescer.d.ts +34 -0
- package/dist/auth/reauth-coalescer.d.ts.map +1 -0
- package/dist/auth/reauth-coalescer.js +65 -0
- package/dist/auth/reauth-coalescer.js.map +1 -0
- package/dist/backup/client.cjs +206 -0
- package/dist/backup/client.cjs.map +1 -0
- package/dist/backup/client.d.cts +238 -0
- package/dist/backup/client.d.cts.map +1 -0
- package/dist/backup/client.d.ts +238 -0
- package/dist/backup/client.d.ts.map +1 -0
- package/dist/backup/client.js +206 -0
- package/dist/backup/client.js.map +1 -0
- package/dist/backup/index.cjs +15 -0
- package/dist/backup/index.d.cts +22 -0
- package/dist/backup/index.d.cts.map +1 -0
- package/dist/backup/index.d.ts +22 -0
- package/dist/backup/index.d.ts.map +1 -0
- package/dist/backup/index.js +7 -0
- package/dist/backup/raw.cjs +168 -0
- package/dist/backup/raw.cjs.map +1 -0
- package/dist/backup/raw.d.cts +122 -0
- package/dist/backup/raw.d.cts.map +1 -0
- package/dist/backup/raw.d.ts +122 -0
- package/dist/backup/raw.d.ts.map +1 -0
- package/dist/backup/raw.js +168 -0
- package/dist/backup/raw.js.map +1 -0
- package/dist/bucket-validation.cjs +111 -0
- package/dist/bucket-validation.cjs.map +1 -0
- package/dist/bucket-validation.d.cts +27 -0
- package/dist/bucket-validation.d.cts.map +1 -0
- package/dist/bucket-validation.d.ts +27 -0
- package/dist/bucket-validation.d.ts.map +1 -0
- package/dist/bucket-validation.js +109 -0
- package/dist/bucket-validation.js.map +1 -0
- package/dist/bucket.cjs +125 -74
- package/dist/bucket.cjs.map +1 -1
- package/dist/bucket.d.cts +156 -61
- package/dist/bucket.d.cts.map +1 -1
- package/dist/bucket.d.ts +156 -61
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +125 -74
- package/dist/bucket.js.map +1 -1
- package/dist/client.cjs +29 -8
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +30 -9
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts +30 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -8
- package/dist/client.js.map +1 -1
- package/dist/copy/large.cjs +5 -3
- package/dist/copy/large.cjs.map +1 -1
- package/dist/copy/large.d.cts.map +1 -1
- package/dist/copy/large.d.ts.map +1 -1
- package/dist/copy/large.js +5 -3
- package/dist/copy/large.js.map +1 -1
- package/dist/download/checksum.cjs +6 -2
- package/dist/download/checksum.cjs.map +1 -1
- package/dist/download/checksum.js +6 -2
- package/dist/download/checksum.js.map +1 -1
- package/dist/download/parallel.cjs +52 -15
- package/dist/download/parallel.cjs.map +1 -1
- package/dist/download/parallel.d.cts +8 -1
- package/dist/download/parallel.d.cts.map +1 -1
- package/dist/download/parallel.d.ts +8 -1
- package/dist/download/parallel.d.ts.map +1 -1
- package/dist/download/parallel.js +52 -15
- package/dist/download/parallel.js.map +1 -1
- package/dist/download/single.cjs +179 -19
- package/dist/download/single.cjs.map +1 -1
- package/dist/download/single.d.cts +10 -4
- package/dist/download/single.d.cts.map +1 -1
- package/dist/download/single.d.ts +10 -4
- package/dist/download/single.d.ts.map +1 -1
- package/dist/download/single.js +179 -19
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +196 -3
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +134 -0
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +134 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +183 -4
- package/dist/errors/index.js.map +1 -1
- package/dist/http/non-idempotent-mutations.cjs +38 -0
- package/dist/http/non-idempotent-mutations.cjs.map +1 -0
- package/dist/http/non-idempotent-mutations.d.cts +25 -0
- package/dist/http/non-idempotent-mutations.d.cts.map +1 -0
- package/dist/http/non-idempotent-mutations.d.ts +25 -0
- package/dist/http/non-idempotent-mutations.d.ts.map +1 -0
- package/dist/http/non-idempotent-mutations.js +35 -0
- package/dist/http/non-idempotent-mutations.js.map +1 -0
- package/dist/http/retry.cjs +1 -1
- package/dist/http/retry.cjs.map +1 -1
- package/dist/http/retry.js +1 -1
- package/dist/http/retry.js.map +1 -1
- package/dist/http/transport.cjs +62 -23
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +30 -3
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +30 -3
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +60 -22
- package/dist/http/transport.js.map +1 -1
- package/dist/http/user-agent.cjs +12 -1
- package/dist/http/user-agent.cjs.map +1 -1
- package/dist/http/user-agent.d.cts +8 -0
- package/dist/http/user-agent.d.cts.map +1 -1
- package/dist/http/user-agent.d.ts +8 -0
- package/dist/http/user-agent.d.ts.map +1 -1
- package/dist/http/user-agent.js +13 -3
- package/dist/http/user-agent.js.map +1 -1
- package/dist/index.cjs +50 -2
- package/dist/index.d.cts +15 -12
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -10
- package/dist/notifications/index.cjs +3 -0
- package/dist/notifications/index.d.cts +2 -0
- package/dist/notifications/index.d.cts.map +1 -1
- package/dist/notifications/index.d.ts +2 -0
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +2 -1
- package/dist/object.cjs +13 -2
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.cts +11 -3
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +11 -3
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +13 -2
- package/dist/object.js.map +1 -1
- package/dist/partner/account-info.d.cts +43 -0
- package/dist/partner/account-info.d.cts.map +1 -0
- package/dist/partner/account-info.d.ts +43 -0
- package/dist/partner/account-info.d.ts.map +1 -0
- package/dist/partner/auth-clone.cjs +64 -0
- package/dist/partner/auth-clone.cjs.map +1 -0
- package/dist/partner/auth-clone.d.cts +27 -0
- package/dist/partner/auth-clone.d.cts.map +1 -0
- package/dist/partner/auth-clone.d.ts +27 -0
- package/dist/partner/auth-clone.d.ts.map +1 -0
- package/dist/partner/auth-clone.js +63 -0
- package/dist/partner/auth-clone.js.map +1 -0
- package/dist/partner/auth-core.cjs +156 -0
- package/dist/partner/auth-core.cjs.map +1 -0
- package/dist/partner/auth-core.d.cts +111 -0
- package/dist/partner/auth-core.d.cts.map +1 -0
- package/dist/partner/auth-core.d.ts +111 -0
- package/dist/partner/auth-core.d.ts.map +1 -0
- package/dist/partner/auth-core.js +156 -0
- package/dist/partner/auth-core.js.map +1 -0
- package/dist/partner/auth-shape.cjs +36 -0
- package/dist/partner/auth-shape.cjs.map +1 -0
- package/dist/partner/auth-shape.d.cts +12 -0
- package/dist/partner/auth-shape.d.cts.map +1 -0
- package/dist/partner/auth-shape.d.ts +12 -0
- package/dist/partner/auth-shape.d.ts.map +1 -0
- package/dist/partner/auth-shape.js +36 -0
- package/dist/partner/auth-shape.js.map +1 -0
- package/dist/partner/client.cjs +270 -0
- package/dist/partner/client.cjs.map +1 -0
- package/dist/partner/client.d.cts +357 -0
- package/dist/partner/client.d.cts.map +1 -0
- package/dist/partner/client.d.ts +357 -0
- package/dist/partner/client.d.ts.map +1 -0
- package/dist/partner/client.js +270 -0
- package/dist/partner/client.js.map +1 -0
- package/dist/partner/endpoint-url.cjs +109 -0
- package/dist/partner/endpoint-url.cjs.map +1 -0
- package/dist/partner/endpoint-url.d.cts +74 -0
- package/dist/partner/endpoint-url.d.cts.map +1 -0
- package/dist/partner/endpoint-url.d.ts +74 -0
- package/dist/partner/endpoint-url.d.ts.map +1 -0
- package/dist/partner/endpoint-url.js +106 -0
- package/dist/partner/endpoint-url.js.map +1 -0
- package/dist/partner/in-memory.cjs +135 -0
- package/dist/partner/in-memory.cjs.map +1 -0
- package/dist/partner/in-memory.d.cts +99 -0
- package/dist/partner/in-memory.d.cts.map +1 -0
- package/dist/partner/in-memory.d.ts +99 -0
- package/dist/partner/in-memory.d.ts.map +1 -0
- package/dist/partner/in-memory.js +135 -0
- package/dist/partner/in-memory.js.map +1 -0
- package/dist/partner/index.cjs +27 -0
- package/dist/partner/index.d.cts +32 -0
- package/dist/partner/index.d.cts.map +1 -0
- package/dist/partner/index.d.ts +32 -0
- package/dist/partner/index.d.ts.map +1 -0
- package/dist/partner/index.js +9 -0
- package/dist/partner/raw.cjs +400 -0
- package/dist/partner/raw.cjs.map +1 -0
- package/dist/partner/raw.d.cts +220 -0
- package/dist/partner/raw.d.cts.map +1 -0
- package/dist/partner/raw.d.ts +220 -0
- package/dist/partner/raw.d.ts.map +1 -0
- package/dist/partner/raw.js +398 -0
- package/dist/partner/raw.js.map +1 -0
- package/dist/partner/redaction-placeholders.cjs +10 -0
- package/dist/partner/redaction-placeholders.cjs.map +1 -0
- package/dist/partner/redaction-placeholders.d.cts +5 -0
- package/dist/partner/redaction-placeholders.d.cts.map +1 -0
- package/dist/partner/redaction-placeholders.d.ts +5 -0
- package/dist/partner/redaction-placeholders.d.ts.map +1 -0
- package/dist/partner/redaction-placeholders.js +9 -0
- package/dist/partner/redaction-placeholders.js.map +1 -0
- package/dist/partner/redaction.cjs +292 -0
- package/dist/partner/redaction.cjs.map +1 -0
- package/dist/partner/redaction.d.cts +158 -0
- package/dist/partner/redaction.d.cts.map +1 -0
- package/dist/partner/redaction.d.ts +158 -0
- package/dist/partner/redaction.d.ts.map +1 -0
- package/dist/partner/redaction.js +281 -0
- package/dist/partner/redaction.js.map +1 -0
- package/dist/raw/encoding.cjs +29 -10
- package/dist/raw/encoding.cjs.map +1 -1
- package/dist/raw/encoding.d.cts +3 -2
- package/dist/raw/encoding.d.cts.map +1 -1
- package/dist/raw/encoding.d.ts +3 -2
- package/dist/raw/encoding.d.ts.map +1 -1
- package/dist/raw/encoding.js +29 -10
- package/dist/raw/encoding.js.map +1 -1
- package/dist/raw/index.cjs +131 -44
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +21 -15
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +21 -15
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +114 -45
- package/dist/raw/index.js.map +1 -1
- package/dist/raw/url.cjs +111 -0
- package/dist/raw/url.cjs.map +1 -0
- package/dist/raw/url.d.cts +41 -0
- package/dist/raw/url.d.cts.map +1 -0
- package/dist/raw/url.d.ts +41 -0
- package/dist/raw/url.d.ts.map +1 -0
- package/dist/raw/url.js +110 -0
- package/dist/raw/url.js.map +1 -0
- package/dist/s3/sigv4.cjs +15 -10
- package/dist/s3/sigv4.cjs.map +1 -1
- package/dist/s3/sigv4.js +15 -10
- package/dist/s3/sigv4.js.map +1 -1
- package/dist/simulator/index.cjs +1579 -257
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +124 -11
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +124 -11
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +1568 -262
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/partner-capabilities.cjs +77 -0
- package/dist/simulator/partner-capabilities.cjs.map +1 -0
- package/dist/simulator/partner-capabilities.d.cts +53 -0
- package/dist/simulator/partner-capabilities.d.cts.map +1 -0
- package/dist/simulator/partner-capabilities.d.ts +53 -0
- package/dist/simulator/partner-capabilities.d.ts.map +1 -0
- package/dist/simulator/partner-capabilities.js +73 -0
- package/dist/simulator/partner-capabilities.js.map +1 -0
- package/dist/simulator/partner.cjs +713 -0
- package/dist/simulator/partner.cjs.map +1 -0
- package/dist/simulator/partner.d.cts +186 -0
- package/dist/simulator/partner.d.cts.map +1 -0
- package/dist/simulator/partner.d.ts +186 -0
- package/dist/simulator/partner.d.ts.map +1 -0
- package/dist/simulator/partner.js +713 -0
- package/dist/simulator/partner.js.map +1 -0
- package/dist/simulator/validation.cjs +732 -25
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +145 -6
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +145 -6
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +705 -26
- package/dist/simulator/validation.js.map +1 -1
- package/dist/streams/file-source.cjs +2 -2
- package/dist/streams/file-source.cjs.map +1 -1
- package/dist/streams/file-source.js +2 -2
- package/dist/streams/file-source.js.map +1 -1
- package/dist/streams/hash.cjs +246 -13
- package/dist/streams/hash.cjs.map +1 -1
- package/dist/streams/hash.d.cts +37 -12
- package/dist/streams/hash.d.cts.map +1 -1
- package/dist/streams/hash.d.ts +37 -12
- package/dist/streams/hash.d.ts.map +1 -1
- package/dist/streams/hash.js +246 -15
- package/dist/streams/hash.js.map +1 -1
- package/dist/streams/index.cjs +3 -1
- package/dist/streams/index.d.cts +1 -1
- package/dist/streams/index.d.cts.map +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.d.ts.map +1 -1
- package/dist/streams/index.js +3 -3
- package/dist/streams/progress.cjs +63 -4
- package/dist/streams/progress.cjs.map +1 -1
- package/dist/streams/progress.d.cts +28 -2
- package/dist/streams/progress.d.cts.map +1 -1
- package/dist/streams/progress.d.ts +28 -2
- package/dist/streams/progress.d.ts.map +1 -1
- package/dist/streams/progress.js +63 -4
- package/dist/streams/progress.js.map +1 -1
- package/dist/streams/source.cjs +2 -1
- package/dist/streams/source.cjs.map +1 -1
- package/dist/streams/source.js +2 -1
- package/dist/streams/source.js.map +1 -1
- package/dist/sync/b2-sha1-reader.cjs +6 -2
- package/dist/sync/b2-sha1-reader.cjs.map +1 -1
- package/dist/sync/b2-sha1-reader.d.cts.map +1 -1
- package/dist/sync/b2-sha1-reader.d.ts.map +1 -1
- package/dist/sync/b2-sha1-reader.js +6 -2
- package/dist/sync/b2-sha1-reader.js.map +1 -1
- package/dist/sync/download-staging.cjs +156 -43
- package/dist/sync/download-staging.cjs.map +1 -1
- package/dist/sync/download-staging.d.cts +26 -2
- package/dist/sync/download-staging.d.cts.map +1 -1
- package/dist/sync/download-staging.d.ts +26 -2
- package/dist/sync/download-staging.d.ts.map +1 -1
- package/dist/sync/download-staging.js +155 -44
- package/dist/sync/download-staging.js.map +1 -1
- package/dist/sync/filters.cjs.map +1 -1
- package/dist/sync/filters.js.map +1 -1
- package/dist/sync/index.d.cts +1 -1
- package/dist/sync/index.d.cts.map +1 -1
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/local-file-io.cjs +15 -6
- package/dist/sync/local-file-io.cjs.map +1 -1
- package/dist/sync/local-file-io.d.cts +3 -0
- package/dist/sync/local-file-io.d.cts.map +1 -1
- package/dist/sync/local-file-io.d.ts +3 -0
- package/dist/sync/local-file-io.d.ts.map +1 -1
- package/dist/sync/local-file-io.js +15 -6
- package/dist/sync/local-file-io.js.map +1 -1
- package/dist/sync/local-sha1.cjs +6 -15
- package/dist/sync/local-sha1.cjs.map +1 -1
- package/dist/sync/local-sha1.d.cts +0 -8
- package/dist/sync/local-sha1.d.cts.map +1 -1
- package/dist/sync/local-sha1.d.ts +0 -8
- package/dist/sync/local-sha1.d.ts.map +1 -1
- package/dist/sync/local-sha1.js +7 -15
- package/dist/sync/local-sha1.js.map +1 -1
- package/dist/sync/pairing.cjs +1 -0
- package/dist/sync/pairing.cjs.map +1 -1
- package/dist/sync/pairing.js +1 -0
- package/dist/sync/pairing.js.map +1 -1
- package/dist/sync/policies/compare.cjs +5 -3
- package/dist/sync/policies/compare.cjs.map +1 -1
- package/dist/sync/policies/compare.d.cts.map +1 -1
- package/dist/sync/policies/compare.d.ts.map +1 -1
- package/dist/sync/policies/compare.js +6 -4
- package/dist/sync/policies/compare.js.map +1 -1
- package/dist/sync/policies/index.cjs +4 -10
- package/dist/sync/policies/index.cjs.map +1 -1
- package/dist/sync/policies/index.js +4 -10
- package/dist/sync/policies/index.js.map +1 -1
- package/dist/sync/scanners/b2.cjs +4 -2
- package/dist/sync/scanners/b2.cjs.map +1 -1
- package/dist/sync/scanners/b2.d.cts.map +1 -1
- package/dist/sync/scanners/b2.d.ts.map +1 -1
- package/dist/sync/scanners/b2.js +4 -2
- package/dist/sync/scanners/b2.js.map +1 -1
- package/dist/sync/scanners/local.cjs +150 -33
- package/dist/sync/scanners/local.cjs.map +1 -1
- package/dist/sync/scanners/local.d.cts +6 -0
- package/dist/sync/scanners/local.d.cts.map +1 -1
- package/dist/sync/scanners/local.d.ts +6 -0
- package/dist/sync/scanners/local.d.ts.map +1 -1
- package/dist/sync/scanners/local.js +150 -33
- package/dist/sync/scanners/local.js.map +1 -1
- package/dist/sync/synchronizer.cjs +79 -31
- package/dist/sync/synchronizer.cjs.map +1 -1
- package/dist/sync/synchronizer.d.cts +1 -0
- package/dist/sync/synchronizer.d.cts.map +1 -1
- package/dist/sync/synchronizer.d.ts +1 -0
- package/dist/sync/synchronizer.d.ts.map +1 -1
- package/dist/sync/synchronizer.js +79 -31
- package/dist/sync/synchronizer.js.map +1 -1
- package/dist/sync/types.d.cts +19 -3
- package/dist/sync/types.d.cts.map +1 -1
- package/dist/sync/types.d.ts +19 -3
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/types/auth.cjs +4 -0
- package/dist/types/auth.cjs.map +1 -1
- package/dist/types/auth.d.cts +4 -0
- package/dist/types/auth.d.cts.map +1 -1
- package/dist/types/auth.d.ts +4 -0
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +4 -0
- package/dist/types/auth.js.map +1 -1
- package/dist/types/backup.d.cts +85 -0
- package/dist/types/backup.d.cts.map +1 -0
- package/dist/types/backup.d.ts +85 -0
- package/dist/types/backup.d.ts.map +1 -0
- package/dist/types/bucket.cjs +81 -11
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.d.cts +194 -41
- package/dist/types/bucket.d.cts.map +1 -1
- package/dist/types/bucket.d.ts +194 -41
- package/dist/types/bucket.d.ts.map +1 -1
- package/dist/types/bucket.js +67 -12
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/download.cjs +62 -0
- package/dist/types/download.cjs.map +1 -0
- package/dist/types/download.d.cts +100 -16
- package/dist/types/download.d.cts.map +1 -1
- package/dist/types/download.d.ts +100 -16
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/download.js +61 -0
- package/dist/types/download.js.map +1 -0
- package/dist/types/encryption.cjs +76 -229
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +48 -6
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +48 -6
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +74 -229
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/errors.cjs +9 -0
- package/dist/types/errors.cjs.map +1 -1
- package/dist/types/errors.d.cts +1 -1
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +9 -0
- package/dist/types/errors.js.map +1 -1
- package/dist/types/file.cjs +3 -0
- package/dist/types/file.cjs.map +1 -1
- package/dist/types/file.d.cts +140 -18
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +140 -18
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/file.js +3 -1
- package/dist/types/file.js.map +1 -1
- package/dist/types/ids.cjs +30 -0
- package/dist/types/ids.cjs.map +1 -1
- package/dist/types/ids.d.cts +32 -0
- package/dist/types/ids.d.cts.map +1 -1
- package/dist/types/ids.d.ts +32 -0
- package/dist/types/ids.d.ts.map +1 -1
- package/dist/types/ids.js +28 -1
- package/dist/types/ids.js.map +1 -1
- package/dist/types/index.d.cts +16 -12
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +16 -12
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key.d.cts +4 -3
- package/dist/types/key.d.cts.map +1 -1
- package/dist/types/key.d.ts +4 -3
- package/dist/types/key.d.ts.map +1 -1
- package/dist/types/lock.cjs.map +1 -1
- package/dist/types/lock.d.cts +14 -0
- package/dist/types/lock.d.cts.map +1 -1
- package/dist/types/lock.d.ts +14 -0
- package/dist/types/lock.d.ts.map +1 -1
- package/dist/types/lock.js.map +1 -1
- package/dist/types/notifications.cjs +31 -1
- package/dist/types/notifications.cjs.map +1 -1
- package/dist/types/notifications.d.cts +31 -4
- package/dist/types/notifications.d.cts.map +1 -1
- package/dist/types/notifications.d.ts +31 -4
- package/dist/types/notifications.d.ts.map +1 -1
- package/dist/types/notifications.js +30 -2
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/partner.cjs +32 -0
- package/dist/types/partner.cjs.map +1 -0
- package/dist/types/partner.d.cts +386 -0
- package/dist/types/partner.d.cts.map +1 -0
- package/dist/types/partner.d.ts +386 -0
- package/dist/types/partner.d.ts.map +1 -0
- package/dist/types/partner.js +29 -0
- package/dist/types/partner.js.map +1 -0
- package/dist/types/upload.d.cts +35 -18
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +35 -18
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort-scope.cjs +0 -45
- package/dist/upload/abort-scope.cjs.map +1 -1
- package/dist/upload/abort-scope.d.cts +0 -22
- package/dist/upload/abort-scope.d.cts.map +1 -1
- package/dist/upload/abort-scope.d.ts +0 -22
- package/dist/upload/abort-scope.d.ts.map +1 -1
- package/dist/upload/abort-scope.js +1 -44
- package/dist/upload/abort-scope.js.map +1 -1
- package/dist/upload/finish.cjs +3 -8
- package/dist/upload/finish.cjs.map +1 -1
- package/dist/upload/finish.d.cts.map +1 -1
- package/dist/upload/finish.d.ts.map +1 -1
- package/dist/upload/finish.js +1 -6
- package/dist/upload/finish.js.map +1 -1
- package/dist/upload/large.cjs +15 -8
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +31 -8
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +31 -8
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +15 -8
- package/dist/upload/large.js.map +1 -1
- package/dist/upload/options.cjs.map +1 -1
- package/dist/upload/options.d.cts +24 -0
- package/dist/upload/options.d.cts.map +1 -1
- package/dist/upload/options.d.ts +24 -0
- package/dist/upload/options.d.ts.map +1 -1
- package/dist/upload/options.js.map +1 -1
- package/dist/upload/resume.cjs +6 -4
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +9 -5
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +9 -5
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +6 -4
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +25 -13
- package/dist/upload/retry.cjs.map +1 -1
- package/dist/upload/retry.d.cts.map +1 -1
- package/dist/upload/retry.d.ts.map +1 -1
- package/dist/upload/retry.js +25 -13
- package/dist/upload/retry.js.map +1 -1
- package/dist/upload/single.cjs +35 -30
- package/dist/upload/single.cjs.map +1 -1
- package/dist/upload/single.d.cts +12 -0
- package/dist/upload/single.d.cts.map +1 -1
- package/dist/upload/single.d.ts +12 -0
- package/dist/upload/single.d.ts.map +1 -1
- package/dist/upload/single.js +35 -30
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +18 -5
- package/dist/upload/stream.cjs.map +1 -1
- package/dist/upload/stream.d.cts +12 -0
- package/dist/upload/stream.d.cts.map +1 -1
- package/dist/upload/stream.d.ts +12 -0
- package/dist/upload/stream.d.ts.map +1 -1
- package/dist/upload/stream.js +15 -2
- package/dist/upload/stream.js.map +1 -1
- package/dist/util/abort.cjs +114 -0
- package/dist/util/abort.cjs.map +1 -0
- package/dist/util/abort.d.cts +65 -0
- package/dist/util/abort.d.cts.map +1 -0
- package/dist/util/abort.d.ts +65 -0
- package/dist/util/abort.d.ts.map +1 -0
- package/dist/util/abort.js +109 -0
- package/dist/util/abort.js.map +1 -0
- package/dist/util/defaults.cjs +3 -0
- package/dist/util/defaults.cjs.map +1 -1
- package/dist/util/defaults.d.cts +2 -0
- package/dist/util/defaults.d.cts.map +1 -1
- package/dist/util/defaults.d.ts +2 -0
- package/dist/util/defaults.d.ts.map +1 -1
- package/dist/util/defaults.js +3 -1
- package/dist/util/defaults.js.map +1 -1
- package/dist/util/md5.cjs +211 -0
- package/dist/util/md5.cjs.map +1 -0
- package/dist/util/md5.d.cts +43 -0
- package/dist/util/md5.d.cts.map +1 -0
- package/dist/util/md5.d.ts +43 -0
- package/dist/util/md5.d.ts.map +1 -0
- package/dist/util/md5.js +209 -0
- package/dist/util/md5.js.map +1 -0
- package/dist/util/normalize.cjs +5 -5
- package/dist/util/normalize.cjs.map +1 -1
- package/dist/util/normalize.d.cts +7 -7
- package/dist/util/normalize.d.cts.map +1 -1
- package/dist/util/normalize.d.ts +7 -7
- package/dist/util/normalize.d.ts.map +1 -1
- package/dist/util/normalize.js +5 -5
- package/dist/util/normalize.js.map +1 -1
- package/dist/util/paginator.cjs +7 -1
- package/dist/util/paginator.cjs.map +1 -1
- package/dist/util/paginator.d.cts +3 -1
- package/dist/util/paginator.d.cts.map +1 -1
- package/dist/util/paginator.d.ts +3 -1
- package/dist/util/paginator.d.ts.map +1 -1
- package/dist/util/paginator.js +7 -1
- package/dist/util/paginator.js.map +1 -1
- package/dist/version.cjs +56 -4
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +53 -4
- package/dist/version.d.cts.map +1 -1
- package/dist/version.d.ts +53 -4
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +52 -5
- package/dist/version.js.map +1 -1
- package/package.json +47 -18
package/dist/client.d.cts
CHANGED
|
@@ -5,8 +5,7 @@ import { HttpTransport } from './http/transport.js';
|
|
|
5
5
|
import { UrlGuard } from './http/url-guard.js';
|
|
6
6
|
import { RawClient } from './raw/index.js';
|
|
7
7
|
import { AuthorizeAccountResponse, Capability } from './types/auth.js';
|
|
8
|
-
import { BucketInfo, BucketRetentionPolicy, BucketType, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
9
|
-
import { EncryptionSetting } from './types/encryption.js';
|
|
8
|
+
import { BucketDefaultServerSideEncryptionSetting, BucketInfo, BucketRetentionPolicy, BucketType, BucketTypesFilter, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
10
9
|
import { ApplicationKeyId, BucketId } from './types/ids.js';
|
|
11
10
|
import { ApplicationKey, CreateKeyOptions, FullApplicationKey, ListKeysResponse } from './types/key.js';
|
|
12
11
|
import { ReplicationConfiguration } from './types/replication.js';
|
|
@@ -64,6 +63,11 @@ export interface B2ClientOptions {
|
|
|
64
63
|
*/
|
|
65
64
|
readonly followSameOriginRedirects?: boolean;
|
|
66
65
|
}
|
|
66
|
+
/** Options for {@link B2Client.authorize}. */
|
|
67
|
+
export interface B2ClientAuthorizeOptions {
|
|
68
|
+
/** Abort signal for cancelling the authorize request. */
|
|
69
|
+
readonly signal?: AbortSignal;
|
|
70
|
+
}
|
|
67
71
|
/**
|
|
68
72
|
* High-level B2 client providing ergonomic access to buckets, files, and keys.
|
|
69
73
|
*
|
|
@@ -93,6 +97,7 @@ export declare class B2Client {
|
|
|
93
97
|
private readonly realmUrl;
|
|
94
98
|
private readonly userAllowedSuffixes;
|
|
95
99
|
private readonly resolvedUploadRetryOptions;
|
|
100
|
+
private readonly reauthCoalescer;
|
|
96
101
|
/**
|
|
97
102
|
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
98
103
|
* @param options - Configuration including credentials, realm, and transport settings.
|
|
@@ -101,18 +106,23 @@ export declare class B2Client {
|
|
|
101
106
|
/**
|
|
102
107
|
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
103
108
|
*
|
|
109
|
+
* @param options - Optional request controls.
|
|
110
|
+
*
|
|
104
111
|
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
105
112
|
*/
|
|
106
|
-
authorize(): Promise<AuthorizeAccountResponse>;
|
|
113
|
+
authorize(options?: B2ClientAuthorizeOptions): Promise<AuthorizeAccountResponse>;
|
|
107
114
|
private lockUrlGuard;
|
|
108
115
|
/**
|
|
109
116
|
* Refresh credentials after a 401. Returns the fresh auth token so
|
|
110
117
|
* {@link RetryTransport} can rewrite the in-flight request's
|
|
111
118
|
* Authorization header before retrying.
|
|
112
119
|
*
|
|
120
|
+
* @param signal - Optional abort signal for the request that triggered reauthorization.
|
|
121
|
+
*
|
|
113
122
|
* @returns The fresh authorization token.
|
|
114
123
|
*/
|
|
115
124
|
private reauthorize;
|
|
125
|
+
private doReauthorize;
|
|
116
126
|
/**
|
|
117
127
|
* Creates a new B2 bucket.
|
|
118
128
|
* @param options - Bucket configuration including name, type, and optional settings.
|
|
@@ -124,12 +134,23 @@ export declare class B2Client {
|
|
|
124
134
|
bucketName: string;
|
|
125
135
|
/** Access level: `"allPrivate"` or `"allPublic"`. */
|
|
126
136
|
bucketType: BucketType;
|
|
127
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Custom key-value metadata stored with the bucket. Keys must be 1-50
|
|
139
|
+
* UTF-8 bytes, must not start with `b2-`, and all values together must be
|
|
140
|
+
* at most 10,000 UTF-8 bytes. Keys must match
|
|
141
|
+
* {@link BUCKET_INFO_KEY_PATTERN}. There is no bucketInfo pair-count cap.
|
|
142
|
+
*/
|
|
128
143
|
bucketInfo?: Record<string, string>;
|
|
129
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* CORS rules for browser-based access. A bucket may have at most 100
|
|
146
|
+
* rules; rule names must be unique, 6-63 characters, match
|
|
147
|
+
* `[A-Za-z0-9-]`, and not start with `b2-`. Each rule must be less than
|
|
148
|
+
* 1,000 UTF-8 bytes across its name, origins, operations, allowed headers,
|
|
149
|
+
* and exposed headers. `maxAgeSeconds` must be at most 86,400.
|
|
150
|
+
*/
|
|
130
151
|
corsRules?: CorsRule[];
|
|
131
152
|
/** Default server-side encryption for new files. */
|
|
132
|
-
defaultServerSideEncryption?:
|
|
153
|
+
defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting;
|
|
133
154
|
/** Default retention policy for new files (requires file lock). */
|
|
134
155
|
defaultRetention?: BucketRetentionPolicy;
|
|
135
156
|
/** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */
|
|
@@ -150,8 +171,8 @@ export declare class B2Client {
|
|
|
150
171
|
bucketId?: BucketId;
|
|
151
172
|
/** Filter to a specific bucket by name. */
|
|
152
173
|
bucketName?: string;
|
|
153
|
-
/** Filter by bucket types (e.g., `["allPrivate"]`). */
|
|
154
|
-
bucketTypes?:
|
|
174
|
+
/** Filter by bucket types (e.g., `["allPrivate"]`, `["shared"]`, or `["all"]`). */
|
|
175
|
+
bucketTypes?: BucketTypesFilter;
|
|
155
176
|
}): Promise<Bucket[]>;
|
|
156
177
|
/**
|
|
157
178
|
* Looks up a single bucket by name.
|
|
@@ -186,7 +207,7 @@ export declare class B2Client {
|
|
|
186
207
|
* raw API's `maxKeyCount` parameter.
|
|
187
208
|
*/
|
|
188
209
|
pageSize?: number;
|
|
189
|
-
/** Start listing
|
|
210
|
+
/** Start listing at this key ID, usually from `nextApplicationKeyId`. */
|
|
190
211
|
startApplicationKeyId?: ApplicationKeyId;
|
|
191
212
|
}): Promise<ListKeysResponse>;
|
|
192
213
|
/**
|
package/dist/client.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names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AQ,CAAC,EAAE,MAAM,CAAA;QACjB,yEAAyE;QACzE,qBAAqB,CAAC,EAAE,gBAAgB,CAAA;KACzC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAU7B;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,qBAAqB,CAAC,cAAc,CAAC;IAc/E;;;;;OAKG;IACG,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAM5E;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,qBAAqB;CAOtE"}
|
package/dist/client.d.ts
CHANGED
|
@@ -5,8 +5,7 @@ import { HttpTransport } from './http/transport.js';
|
|
|
5
5
|
import { UrlGuard } from './http/url-guard.js';
|
|
6
6
|
import { RawClient } from './raw/index.js';
|
|
7
7
|
import { AuthorizeAccountResponse, Capability } from './types/auth.js';
|
|
8
|
-
import { BucketInfo, BucketRetentionPolicy, BucketType, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
9
|
-
import { EncryptionSetting } from './types/encryption.js';
|
|
8
|
+
import { BucketDefaultServerSideEncryptionSetting, BucketInfo, BucketRetentionPolicy, BucketType, BucketTypesFilter, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
10
9
|
import { ApplicationKeyId, BucketId } from './types/ids.js';
|
|
11
10
|
import { ApplicationKey, CreateKeyOptions, FullApplicationKey, ListKeysResponse } from './types/key.js';
|
|
12
11
|
import { ReplicationConfiguration } from './types/replication.js';
|
|
@@ -64,6 +63,11 @@ export interface B2ClientOptions {
|
|
|
64
63
|
*/
|
|
65
64
|
readonly followSameOriginRedirects?: boolean;
|
|
66
65
|
}
|
|
66
|
+
/** Options for {@link B2Client.authorize}. */
|
|
67
|
+
export interface B2ClientAuthorizeOptions {
|
|
68
|
+
/** Abort signal for cancelling the authorize request. */
|
|
69
|
+
readonly signal?: AbortSignal;
|
|
70
|
+
}
|
|
67
71
|
/**
|
|
68
72
|
* High-level B2 client providing ergonomic access to buckets, files, and keys.
|
|
69
73
|
*
|
|
@@ -93,6 +97,7 @@ export declare class B2Client {
|
|
|
93
97
|
private readonly realmUrl;
|
|
94
98
|
private readonly userAllowedSuffixes;
|
|
95
99
|
private readonly resolvedUploadRetryOptions;
|
|
100
|
+
private readonly reauthCoalescer;
|
|
96
101
|
/**
|
|
97
102
|
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
98
103
|
* @param options - Configuration including credentials, realm, and transport settings.
|
|
@@ -101,18 +106,23 @@ export declare class B2Client {
|
|
|
101
106
|
/**
|
|
102
107
|
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
103
108
|
*
|
|
109
|
+
* @param options - Optional request controls.
|
|
110
|
+
*
|
|
104
111
|
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
105
112
|
*/
|
|
106
|
-
authorize(): Promise<AuthorizeAccountResponse>;
|
|
113
|
+
authorize(options?: B2ClientAuthorizeOptions): Promise<AuthorizeAccountResponse>;
|
|
107
114
|
private lockUrlGuard;
|
|
108
115
|
/**
|
|
109
116
|
* Refresh credentials after a 401. Returns the fresh auth token so
|
|
110
117
|
* {@link RetryTransport} can rewrite the in-flight request's
|
|
111
118
|
* Authorization header before retrying.
|
|
112
119
|
*
|
|
120
|
+
* @param signal - Optional abort signal for the request that triggered reauthorization.
|
|
121
|
+
*
|
|
113
122
|
* @returns The fresh authorization token.
|
|
114
123
|
*/
|
|
115
124
|
private reauthorize;
|
|
125
|
+
private doReauthorize;
|
|
116
126
|
/**
|
|
117
127
|
* Creates a new B2 bucket.
|
|
118
128
|
* @param options - Bucket configuration including name, type, and optional settings.
|
|
@@ -124,12 +134,23 @@ export declare class B2Client {
|
|
|
124
134
|
bucketName: string;
|
|
125
135
|
/** Access level: `"allPrivate"` or `"allPublic"`. */
|
|
126
136
|
bucketType: BucketType;
|
|
127
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Custom key-value metadata stored with the bucket. Keys must be 1-50
|
|
139
|
+
* UTF-8 bytes, must not start with `b2-`, and all values together must be
|
|
140
|
+
* at most 10,000 UTF-8 bytes. Keys must match
|
|
141
|
+
* {@link BUCKET_INFO_KEY_PATTERN}. There is no bucketInfo pair-count cap.
|
|
142
|
+
*/
|
|
128
143
|
bucketInfo?: Record<string, string>;
|
|
129
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* CORS rules for browser-based access. A bucket may have at most 100
|
|
146
|
+
* rules; rule names must be unique, 6-63 characters, match
|
|
147
|
+
* `[A-Za-z0-9-]`, and not start with `b2-`. Each rule must be less than
|
|
148
|
+
* 1,000 UTF-8 bytes across its name, origins, operations, allowed headers,
|
|
149
|
+
* and exposed headers. `maxAgeSeconds` must be at most 86,400.
|
|
150
|
+
*/
|
|
130
151
|
corsRules?: CorsRule[];
|
|
131
152
|
/** Default server-side encryption for new files. */
|
|
132
|
-
defaultServerSideEncryption?:
|
|
153
|
+
defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting;
|
|
133
154
|
/** Default retention policy for new files (requires file lock). */
|
|
134
155
|
defaultRetention?: BucketRetentionPolicy;
|
|
135
156
|
/** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */
|
|
@@ -150,8 +171,8 @@ export declare class B2Client {
|
|
|
150
171
|
bucketId?: BucketId;
|
|
151
172
|
/** Filter to a specific bucket by name. */
|
|
152
173
|
bucketName?: string;
|
|
153
|
-
/** Filter by bucket types (e.g., `["allPrivate"]`). */
|
|
154
|
-
bucketTypes?:
|
|
174
|
+
/** Filter by bucket types (e.g., `["allPrivate"]`, `["shared"]`, or `["all"]`). */
|
|
175
|
+
bucketTypes?: BucketTypesFilter;
|
|
155
176
|
}): Promise<Bucket[]>;
|
|
156
177
|
/**
|
|
157
178
|
* Looks up a single bucket by name.
|
|
@@ -186,7 +207,7 @@ export declare class B2Client {
|
|
|
186
207
|
* raw API's `maxKeyCount` parameter.
|
|
187
208
|
*/
|
|
188
209
|
pageSize?: number;
|
|
189
|
-
/** Start listing
|
|
210
|
+
/** Start listing at this key ID, usually from `nextApplicationKeyId`. */
|
|
190
211
|
startApplicationKeyId?: ApplicationKeyId;
|
|
191
212
|
}): Promise<ListKeysResponse>;
|
|
192
213
|
/**
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAIzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,OAAO,EAAyB,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC3E,OAAO,KAAK,EACV,wCAAwC,EACxC,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,iBAAiB,EACjB,QAAQ,EAER,aAAa,EACd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEhE,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AAGtE,OAAO,EAAE,KAAK,gBAAgB,EAAiB,MAAM,qBAAqB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,EAAE,iBAAiB,CAAA;KAChC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAYrB;;;;;OAKG;IACG,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAS3D;;;;;OAKG;IACG,YAAY,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IAOrD;;;;;OAKG;IACG,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAOvE;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,CAAC,EAAE;QACvB;;;WAGG;QACH,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,yEAAyE;QACzE,qBAAqB,CAAC,EAAE,gBAAgB,CAAA;KACzC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAU7B;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,qBAAqB,CAAC,cAAc,CAAC;IAc/E;;;;;OAKG;IACG,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAM5E;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,qBAAqB;CAOtE"}
|
package/dist/client.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { InMemoryAccountInfo } from "./auth/in-memory.js";
|
|
2
2
|
import { accountId } from "./types/ids.js";
|
|
3
|
+
import { throwIfSignalAborted } from "./util/abort.js";
|
|
3
4
|
import "./util/defaults.js";
|
|
4
5
|
import { DEFAULT_RETRY_OPTIONS } from "./http/retry.js";
|
|
5
6
|
import { paginateItems } from "./util/paginator.js";
|
|
6
7
|
import { Bucket } from "./bucket.js";
|
|
7
8
|
import { getRealmUrl } from "./auth/realms.js";
|
|
9
|
+
import { ReauthCoalescer } from "./auth/reauth-coalescer.js";
|
|
8
10
|
import { UrlGuard, deriveAllowedSuffixes } from "./http/url-guard.js";
|
|
9
11
|
import { FetchTransport, RetryTransport } from "./http/transport.js";
|
|
10
12
|
import { RawClient } from "./raw/index.js";
|
|
@@ -38,6 +40,7 @@ var B2Client = class {
|
|
|
38
40
|
realmUrl;
|
|
39
41
|
userAllowedSuffixes;
|
|
40
42
|
resolvedUploadRetryOptions;
|
|
43
|
+
reauthCoalescer;
|
|
41
44
|
/**
|
|
42
45
|
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
43
46
|
* @param options - Configuration including credentials, realm, and transport settings.
|
|
@@ -53,6 +56,7 @@ var B2Client = class {
|
|
|
53
56
|
...DEFAULT_RETRY_OPTIONS,
|
|
54
57
|
...options.retry
|
|
55
58
|
};
|
|
59
|
+
this.reauthCoalescer = new ReauthCoalescer((signal) => this.doReauthorize(signal));
|
|
56
60
|
let baseTransport;
|
|
57
61
|
if (options.transport !== void 0) {
|
|
58
62
|
baseTransport = options.transport;
|
|
@@ -69,7 +73,7 @@ var B2Client = class {
|
|
|
69
73
|
const retryTransport = new RetryTransport({
|
|
70
74
|
transport: baseTransport,
|
|
71
75
|
retry: this.resolvedUploadRetryOptions,
|
|
72
|
-
onReauth: () => this.reauthorize()
|
|
76
|
+
onReauth: (signal) => this.reauthorize(signal)
|
|
73
77
|
});
|
|
74
78
|
const cachedAuth = this.accountInfo.getAuth();
|
|
75
79
|
if (cachedAuth !== null) this.lockUrlGuard(cachedAuth);
|
|
@@ -78,10 +82,14 @@ var B2Client = class {
|
|
|
78
82
|
/**
|
|
79
83
|
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
80
84
|
*
|
|
85
|
+
* @param options - Optional request controls.
|
|
86
|
+
*
|
|
81
87
|
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
82
88
|
*/
|
|
83
|
-
async authorize() {
|
|
84
|
-
|
|
89
|
+
async authorize(options) {
|
|
90
|
+
throwIfSignalAborted(options?.signal);
|
|
91
|
+
const auth = await this.raw.authorizeAccount(this.applicationKeyId, this.applicationKey, this.realmUrl, options?.signal !== void 0 ? { signal: options.signal } : void 0);
|
|
92
|
+
throwIfSignalAborted(options?.signal);
|
|
85
93
|
this.accountInfo.setAuth(auth);
|
|
86
94
|
this.lockUrlGuard(auth);
|
|
87
95
|
return auth;
|
|
@@ -98,11 +106,15 @@ var B2Client = class {
|
|
|
98
106
|
* {@link RetryTransport} can rewrite the in-flight request's
|
|
99
107
|
* Authorization header before retrying.
|
|
100
108
|
*
|
|
109
|
+
* @param signal - Optional abort signal for the request that triggered reauthorization.
|
|
110
|
+
*
|
|
101
111
|
* @returns The fresh authorization token.
|
|
102
112
|
*/
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
113
|
+
reauthorize(signal) {
|
|
114
|
+
return this.reauthCoalescer.run(signal);
|
|
115
|
+
}
|
|
116
|
+
async doReauthorize(signal) {
|
|
117
|
+
return (await this.authorize({ signal })).authorizationToken;
|
|
106
118
|
}
|
|
107
119
|
/**
|
|
108
120
|
* Creates a new B2 bucket.
|
|
@@ -111,9 +123,18 @@ var B2Client = class {
|
|
|
111
123
|
* @returns A {@link Bucket} handle for the newly created bucket.
|
|
112
124
|
*/
|
|
113
125
|
async createBucket(options) {
|
|
126
|
+
const { bucketInfo, bucketName, bucketType, corsRules, defaultRetention, defaultServerSideEncryption, fileLockEnabled, lifecycleRules, replicationConfiguration } = options;
|
|
114
127
|
const request = {
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
...bucketInfo !== void 0 ? { bucketInfo } : {},
|
|
129
|
+
bucketName,
|
|
130
|
+
bucketType,
|
|
131
|
+
...corsRules !== void 0 ? { corsRules } : {},
|
|
132
|
+
...defaultServerSideEncryption !== void 0 ? { defaultServerSideEncryption } : {},
|
|
133
|
+
...defaultRetention !== void 0 ? { defaultRetention } : {},
|
|
134
|
+
...fileLockEnabled !== void 0 ? { fileLockEnabled } : {},
|
|
135
|
+
...lifecycleRules !== void 0 ? { lifecycleRules } : {},
|
|
136
|
+
...replicationConfiguration !== void 0 ? { replicationConfiguration } : {},
|
|
137
|
+
accountId: accountId(this.accountInfo.getAccountId())
|
|
117
138
|
};
|
|
118
139
|
const info = await this.raw.createBucket(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), request);
|
|
119
140
|
return new Bucket(this, info, this.resolvedUploadRetryOptions);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"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 { DEFAULT_RETRY_OPTIONS, type RetryOptions } from './http/retry.ts'\nimport type { HttpTransport } from './http/transport.ts'\nimport { FetchTransport, RetryTransport } from './http/transport.ts'\nimport { deriveAllowedSuffixes, UrlGuard } from './http/url-guard.ts'\nimport { RawClient } from './raw/index.ts'\nimport type { AuthorizeAccountResponse, Capability } from './types/auth.ts'\nimport type {\n BucketInfo,\n BucketRetentionPolicy,\n BucketType,\n CorsRule,\n CreateBucketRequest,\n LifecycleRule,\n} 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 {\n ApplicationKey,\n CreateKeyOptions,\n FullApplicationKey,\n ListKeysResponse,\n} 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 /**\n * B2 realm to authenticate against. Accepts a known realm-map key\n * (`\"production\"` or `\"staging\"`) or a direct base URL. Custom HTTPS hosts\n * are trusted with the application key during authorize, so never derive\n * `realm` from untrusted input. URL values must use HTTPS, or loopback IP\n * literal HTTP for local testing only; application-key credentials are sent\n * unencrypted over loopback HTTP. Unsupported schemes, malformed URLs,\n * non-URL strings, plaintext HTTP hostnames such as `localhost`, and\n * non-loopback plaintext HTTP are rejected before credentials are sent. URL\n * values must not include userinfo, query strings, or fragments. Defaults to\n * `\"production\"`.\n */\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, and per-attempt timeout). */\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 * Follow same-origin GET/HEAD redirects in the default fetch transport after\n * checking each target with the SSRF guard. POST redirects remain blocked.\n * Defaults to true.\n */\n readonly followSameOriginRedirects?: boolean\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 private readonly resolvedUploadRetryOptions: RetryOptions\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 bindAccountInfoAuthContext(this.accountInfo, this.realmUrl, this.applicationKeyId)\n this.userAllowedSuffixes = options.allowedHostSuffixes\n this.resolvedUploadRetryOptions = { ...DEFAULT_RETRY_OPTIONS, ...options.retry }\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 ...(options.followSameOriginRedirects !== undefined\n ? { followSameOriginRedirects: options.followSameOriginRedirects }\n : {}),\n })\n this.urlGuard = urlGuard\n }\n\n const retryTransport = new RetryTransport({\n transport: baseTransport,\n retry: this.resolvedUploadRetryOptions,\n onReauth: () => this.reauthorize(),\n })\n\n const cachedAuth = this.accountInfo.getAuth()\n if (cachedAuth !== null) this.lockUrlGuard(cachedAuth)\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 this.lockUrlGuard(auth)\n return auth\n }\n\n private lockUrlGuard(auth: AuthorizeAccountResponse): void {\n if (this.urlGuard !== null) {\n const derived = deriveAllowedSuffixes(auth.apiInfo.storageApi)\n const merged =\n this.userAllowedSuffixes !== undefined\n ? this.userAllowedSuffixes.length === 0\n ? []\n : Array.from(new Set([...derived, ...this.userAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\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-63 chars; letters, digits, hyphens, periods). */\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, this.resolvedUploadRetryOptions)\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, this.resolvedUploadRetryOptions))\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 const filteredMatch = buckets[0]\n if (filteredMatch !== undefined) return filteredMatch\n\n const unfilteredBuckets = await this.listBuckets()\n return unfilteredBuckets.find((bucket) => bucket.name === bucketName) ?? 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: CreateKeyOptions): 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\nfunction bindAccountInfoAuthContext(\n accountInfo: AccountInfo,\n realmUrl: string,\n applicationKeyId: string,\n): void {\n accountInfo.setApplicationKeyId?.(applicationKeyId)\n accountInfo.setRealmUrl?.(realmUrl)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmGA,IAAa,WAAb,MAAsB;;CAEpB;;CAEA;;;;;;CAMA;CACA;CACA;CACA;CACA;CACA;;;;;CAMA,YAAY,SAA0B;EACpC,KAAK,mBAAmB,QAAQ;EAChC,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,WAAW,YAAY,QAAQ,SAAS,YAAY;EACzD,KAAK,cAAc,QAAQ,eAAe,IAAI,oBAAoB;EAClE,2BAA2B,KAAK,aAAa,KAAK,UAAU,KAAK,gBAAgB;EACjF,KAAK,sBAAsB,QAAQ;EACnC,KAAK,6BAA6B;GAAE,GAAG;GAAuB,GAAG,QAAQ;EAAM;EAE/E,IAAI;EACJ,IAAI,QAAQ,cAAc,KAAA,GAAW;GACnC,gBAAgB,QAAQ;GACxB,KAAK,WAAW;EAClB,OAAO;GACL,MAAM,WAAW,IAAI,SAAS;GAC9B,gBAAgB,IAAI,eAAe;IACjC;IACA,GAAI,QAAQ,cAAc,KAAA,IAAY,EAAE,WAAW,QAAQ,UAAU,IAAI,CAAC;IAC1E,GAAI,QAAQ,8BAA8B,KAAA,IACtC,EAAE,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A;IACnB,GAAI,WAAW,KAAA,IAAY,EAAE,uBAAuB,OAAO,IAAI,CAAC;GAClE,CAAC;GACD,OAAO;IAAE,MAAM;IAAM,YAAY,KAAK,wBAAwB,KAAA;GAAU;EAC1E,IACC,SAAS,KAAK,MACf,SAAS,MACX;CACF;;;;;;;CAQA,MAAM,UAAU,kBAA6D;EAC3E,OAAO,KAAK,IAAI,UAAU,KAAK,YAAY,UAAU,GAAG,KAAK,YAAY,aAAa,GAAG,EACvF,iBACF,CAAC;CACH;;;;;;;;;;;;;CAcA,gBAAgB,QAAsD;EACpE,MAAM,OAAO,KAAK,YAAY,QAAQ;EACtC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,yCAAyC;EACpE,MAAM,YAAY,IAAI,IAAY,KAAK,QAAQ,WAAW,QAAQ,YAAY;EAC9E,MAAM,UAAU,OAAO,QAAQ,QAAQ,CAAC,UAAU,IAAI,GAAa,CAAC;EACpE,OAAO;GAAE,IAAI,QAAQ,WAAW;GAAG;EAAQ;CAC7C;AACF;AAEA,SAAS,2BACP,aACA,UACA,kBACM;CACN,YAAY,sBAAsB,gBAAgB;CAClD,YAAY,cAAc,QAAQ;AACpC"}
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"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 { ReauthCoalescer } from './auth/reauth-coalescer.ts'\nimport { Bucket } from './bucket.ts'\nimport { DEFAULT_RETRY_OPTIONS, type RetryOptions } from './http/retry.ts'\nimport type { HttpTransport } from './http/transport.ts'\nimport { FetchTransport, RetryTransport } from './http/transport.ts'\nimport { deriveAllowedSuffixes, UrlGuard } from './http/url-guard.ts'\nimport { RawClient } from './raw/index.ts'\nimport type { AuthorizeAccountResponse, Capability } from './types/auth.ts'\nimport type {\n BucketDefaultServerSideEncryptionSetting,\n BucketInfo,\n BucketRetentionPolicy,\n BucketType,\n BucketTypesFilter,\n CorsRule,\n CreateBucketRequest,\n LifecycleRule,\n} from './types/bucket.ts'\nimport type { ApplicationKeyId, BucketId } from './types/ids.ts'\nimport { accountId } from './types/ids.ts'\nimport type {\n ApplicationKey,\n CreateKeyOptions,\n FullApplicationKey,\n ListKeysResponse,\n} from './types/key.ts'\nimport type { ReplicationConfiguration } from './types/replication.ts'\nimport { throwIfSignalAborted } from './util/abort.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 /**\n * B2 realm to authenticate against. Accepts a known realm-map key\n * (`\"production\"` or `\"staging\"`) or a direct base URL. Custom HTTPS hosts\n * are trusted with the application key during authorize, so never derive\n * `realm` from untrusted input. URL values must use HTTPS, or loopback IP\n * literal HTTP for local testing only; application-key credentials are sent\n * unencrypted over loopback HTTP. Unsupported schemes, malformed URLs,\n * non-URL strings, plaintext HTTP hostnames such as `localhost`, and\n * non-loopback plaintext HTTP are rejected before credentials are sent. URL\n * values must not include userinfo, query strings, or fragments. Defaults to\n * `\"production\"`.\n */\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, and per-attempt timeout). */\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 * Follow same-origin GET/HEAD redirects in the default fetch transport after\n * checking each target with the SSRF guard. POST redirects remain blocked.\n * Defaults to true.\n */\n readonly followSameOriginRedirects?: boolean\n}\n\n/** Options for {@link B2Client.authorize}. */\nexport interface B2ClientAuthorizeOptions {\n /** Abort signal for cancelling the authorize request. */\n readonly signal?: AbortSignal\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 private readonly resolvedUploadRetryOptions: RetryOptions\n private readonly reauthCoalescer: ReauthCoalescer<string>\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 bindAccountInfoAuthContext(this.accountInfo, this.realmUrl, this.applicationKeyId)\n this.userAllowedSuffixes = options.allowedHostSuffixes\n this.resolvedUploadRetryOptions = { ...DEFAULT_RETRY_OPTIONS, ...options.retry }\n this.reauthCoalescer = new ReauthCoalescer((signal) => this.doReauthorize(signal))\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 ...(options.followSameOriginRedirects !== undefined\n ? { followSameOriginRedirects: options.followSameOriginRedirects }\n : {}),\n })\n this.urlGuard = urlGuard\n }\n\n const retryTransport = new RetryTransport({\n transport: baseTransport,\n retry: this.resolvedUploadRetryOptions,\n onReauth: (signal) => this.reauthorize(signal),\n })\n\n const cachedAuth = this.accountInfo.getAuth()\n if (cachedAuth !== null) this.lockUrlGuard(cachedAuth)\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 * @param options - Optional request controls.\n *\n * @returns The authorization response containing tokens, URLs, and capabilities.\n */\n async authorize(options?: B2ClientAuthorizeOptions): Promise<AuthorizeAccountResponse> {\n throwIfSignalAborted(options?.signal)\n const auth = await this.raw.authorizeAccount(\n this.applicationKeyId,\n this.applicationKey,\n this.realmUrl,\n options?.signal !== undefined ? { signal: options.signal } : undefined,\n )\n throwIfSignalAborted(options?.signal)\n this.accountInfo.setAuth(auth)\n this.lockUrlGuard(auth)\n return auth\n }\n\n private lockUrlGuard(auth: AuthorizeAccountResponse): void {\n if (this.urlGuard !== null) {\n const derived = deriveAllowedSuffixes(auth.apiInfo.storageApi)\n const merged =\n this.userAllowedSuffixes !== undefined\n ? this.userAllowedSuffixes.length === 0\n ? []\n : Array.from(new Set([...derived, ...this.userAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\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 * @param signal - Optional abort signal for the request that triggered reauthorization.\n *\n * @returns The fresh authorization token.\n */\n private reauthorize(signal: AbortSignal | undefined): Promise<string> {\n return this.reauthCoalescer.run(signal)\n }\n\n private async doReauthorize(signal: AbortSignal): Promise<string> {\n const auth = await this.authorize({ signal })\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-63 chars; letters, digits, hyphens, periods). */\n bucketName: string\n /** Access level: `\"allPrivate\"` or `\"allPublic\"`. */\n bucketType: BucketType\n /**\n * Custom key-value metadata stored with the bucket. Keys must be 1-50\n * UTF-8 bytes, must not start with `b2-`, and all values together must be\n * at most 10,000 UTF-8 bytes. Keys must match\n * {@link BUCKET_INFO_KEY_PATTERN}. There is no bucketInfo pair-count cap.\n */\n bucketInfo?: Record<string, string>\n /**\n * CORS rules for browser-based access. A bucket may have at most 100\n * rules; rule names must be unique, 6-63 characters, match\n * `[A-Za-z0-9-]`, and not start with `b2-`. Each rule must be less than\n * 1,000 UTF-8 bytes across its name, origins, operations, allowed headers,\n * and exposed headers. `maxAgeSeconds` must be at most 86,400.\n */\n corsRules?: CorsRule[]\n /** Default server-side encryption for new files. */\n defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting\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 {\n bucketInfo,\n bucketName,\n bucketType,\n corsRules,\n defaultRetention,\n defaultServerSideEncryption,\n fileLockEnabled,\n lifecycleRules,\n replicationConfiguration,\n } = options\n const request: CreateBucketRequest = {\n ...(bucketInfo !== undefined ? { bucketInfo } : {}),\n bucketName,\n bucketType,\n ...(corsRules !== undefined ? { corsRules } : {}),\n ...(defaultServerSideEncryption !== undefined ? { defaultServerSideEncryption } : {}),\n ...(defaultRetention !== undefined ? { defaultRetention } : {}),\n ...(fileLockEnabled !== undefined ? { fileLockEnabled } : {}),\n ...(lifecycleRules !== undefined ? { lifecycleRules } : {}),\n ...(replicationConfiguration !== undefined ? { replicationConfiguration } : {}),\n accountId: accountId(this.accountInfo.getAccountId()),\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, this.resolvedUploadRetryOptions)\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\"]`, `[\"shared\"]`, or `[\"all\"]`). */\n bucketTypes?: BucketTypesFilter\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, this.resolvedUploadRetryOptions))\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 const filteredMatch = buckets[0]\n if (filteredMatch !== undefined) return filteredMatch\n\n const unfilteredBuckets = await this.listBuckets()\n return unfilteredBuckets.find((bucket) => bucket.name === bucketName) ?? 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: CreateKeyOptions): 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 at this key ID, usually from `nextApplicationKeyId`. */\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\nfunction bindAccountInfoAuthContext(\n accountInfo: AccountInfo,\n realmUrl: string,\n applicationKeyId: string,\n): void {\n accountInfo.setApplicationKeyId?.(applicationKeyId)\n accountInfo.setRealmUrl?.(realmUrl)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,IAAa,WAAb,MAAsB;;CAEpB;;CAEA;;;;;;CAMA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;CAMA,YAAY,SAA0B;EACpC,KAAK,mBAAmB,QAAQ;EAChC,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,WAAW,YAAY,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YAAA;IACnB,GAAI,WAAW,KAAA,IAAY,EAAE,uBAAuB,OAAO,IAAI,CAAC;GAClE,CAAC;GACD,OAAO;IAAE,MAAM;IAAM,YAAY,KAAK,wBAAwB,KAAA;GAAU;EAC1E,IACC,SAAS,KAAK,MACf,SAAS,MACX;CACF;;;;;;;CAQA,MAAM,UAAU,kBAA6D;EAC3E,OAAO,KAAK,IAAI,UAAU,KAAK,YAAY,UAAU,GAAG,KAAK,YAAY,aAAa,GAAG,EACvF,iBACF,CAAC;CACH;;;;;;;;;;;;;CAcA,gBAAgB,QAAsD;EACpE,MAAM,OAAO,KAAK,YAAY,QAAQ;EACtC,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,yCAAyC;EACpE,MAAM,YAAY,IAAI,IAAY,KAAK,QAAQ,WAAW,QAAQ,YAAY;EAC9E,MAAM,UAAU,OAAO,QAAQ,QAAQ,CAAC,UAAU,IAAI,GAAa,CAAC;EACpE,OAAO;GAAE,IAAI,QAAQ,WAAW;GAAG;EAAQ;CAC7C;AACF;AAEA,SAAS,2BACP,aACA,UACA,kBACM;CACN,YAAY,sBAAsB,gBAAgB;CAClD,YAAY,cAAc,QAAQ;AACpC"}
|
package/dist/copy/large.cjs
CHANGED
|
@@ -3,6 +3,7 @@ const require_ids = require("../types/ids.cjs");
|
|
|
3
3
|
const require_abort_scope = require("../upload/abort-scope.cjs");
|
|
4
4
|
const require_cancel = require("../upload/cancel.cjs");
|
|
5
5
|
const require_concurrency = require("../upload/concurrency.cjs");
|
|
6
|
+
const require_abort = require("../util/abort.cjs");
|
|
6
7
|
const require_finish = require("../upload/finish.cjs");
|
|
7
8
|
require("../util/defaults.cjs");
|
|
8
9
|
const require_plan_ranges = require("../util/plan-ranges.cjs");
|
|
@@ -59,7 +60,7 @@ async function copyLargeFile(raw, accountInfo, options) {
|
|
|
59
60
|
...options.destinationServerSideEncryption !== void 0 ? { serverSideEncryption: options.destinationServerSideEncryption } : {}
|
|
60
61
|
}, { signal: abortScope.signal });
|
|
61
62
|
try {
|
|
62
|
-
largeFileId = (await
|
|
63
|
+
largeFileId = (await require_abort.raceWithAbort(startPromise, abortScope.signal)).fileId;
|
|
63
64
|
} catch (err) {
|
|
64
65
|
if (abortScope.signal.aborted) cancelLargeFileAfterStart(startPromise, raw, accountInfo, options.onCleanupFailure);
|
|
65
66
|
throw err;
|
|
@@ -70,14 +71,15 @@ async function copyLargeFile(raw, accountInfo, options) {
|
|
|
70
71
|
await sem.acquire();
|
|
71
72
|
try {
|
|
72
73
|
abortScope.signal.throwIfAborted();
|
|
73
|
-
const
|
|
74
|
+
const copyPromise = raw.copyPart(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
74
75
|
sourceFileId: options.sourceFileId,
|
|
75
76
|
largeFileId: require_ids.fileId(startedLargeFileId),
|
|
76
77
|
partNumber: range.partNumber,
|
|
77
78
|
range: require_plan_ranges.byteRangeHeader(range.start, range.end),
|
|
78
79
|
...options.sourceServerSideEncryption !== void 0 ? { sourceServerSideEncryption: options.sourceServerSideEncryption } : {},
|
|
79
80
|
...options.destinationServerSideEncryption !== void 0 ? { destinationServerSideEncryption: options.destinationServerSideEncryption } : {}
|
|
80
|
-
}, { signal: abortScope.signal })
|
|
81
|
+
}, { signal: abortScope.signal });
|
|
82
|
+
const resp = await require_abort.raceWithAbort(copyPromise, abortScope.signal);
|
|
81
83
|
partSha1s[range.partNumber - 1] = resp.contentSha1;
|
|
82
84
|
} catch (err) {
|
|
83
85
|
abortScope.abort(err);
|
package/dist/copy/large.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"large.cjs","names":[],"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, MetadataDirective } from '../types/file.ts'\nimport { type BucketId, type FileId, fileId as fileIdOf, type LargeFileId } from '../types/ids.ts'\nimport {\n createAbortScope,\n raceWithAbort,\n throwRejectedOrAbortReason,\n} from '../upload/abort-scope.ts'\nimport {\n type CleanupFailureListener,\n cancelLargeFileBestEffort,\n cleanupAfterLargeFileError,\n} from '../upload/cancel.ts'\nimport { Semaphore } from '../upload/concurrency.ts'\nimport { finishLargeFileWithAbortReconciliation } from '../upload/finish.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 * Callback invoked if best-effort cancellation fails, or if cancellation is\n * skipped because `b2_finish_large_file` may already have committed.\n */\n readonly onCleanupFailure?: CleanupFailureListener\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 options.signal?.throwIfAborted()\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 options.signal?.throwIfAborted()\n // `b2_copy_file` only accepts replacement contentType/fileInfo under\n // `metadataDirective: REPLACE`; supplying them in the default COPY mode is\n // rejected by B2. When the caller sets either, switch to REPLACE with a\n // required contentType (the override, else the source's, else b2/x-auto),\n // matching the multipart path's metadata semantics below.\n const replaceMetadata = options.contentType !== undefined || options.fileInfo !== undefined\n return raw.copyFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\n sourceFileId: options.sourceFileId,\n fileName: options.fileName,\n ...(options.destinationBucketId !== undefined\n ? { destinationBucketId: options.destinationBucketId }\n : {}),\n ...(replaceMetadata\n ? {\n metadataDirective: MetadataDirective.Replace,\n contentType: options.contentType ?? sourceInfo.contentType ?? DEFAULT_CONTENT_TYPE,\n fileInfo: options.fileInfo ?? {},\n }\n : {}),\n ...(options.destinationServerSideEncryption !== undefined\n ? { destinationServerSideEncryption: options.destinationServerSideEncryption }\n : {}),\n ...(options.sourceServerSideEncryption !== undefined\n ? { sourceServerSideEncryption: options.sourceServerSideEncryption }\n : {}),\n },\n options.signal !== undefined ? { signal: options.signal } : undefined,\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 const ranges = planRanges(totalSize, partSize)\n const partSha1s: string[] = new Array(ranges.length)\n const sem = new Semaphore(concurrency)\n const abortScope = createAbortScope(options.signal)\n let largeFileId: LargeFileId | undefined\n\n try {\n abortScope.signal.throwIfAborted()\n const startPromise = raw.startLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\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 { signal: abortScope.signal },\n )\n try {\n const startResp = await raceWithAbort(startPromise, abortScope.signal)\n largeFileId = startResp.fileId\n } catch (err) {\n if (abortScope.signal.aborted) {\n cancelLargeFileAfterStart(startPromise, raw, accountInfo, options.onCleanupFailure)\n }\n throw err\n }\n const startedLargeFileId = largeFileId\n if (startedLargeFileId === undefined) {\n throw new Error('copyLargeFile: start did not return a large file ID.')\n }\n\n const tasks = ranges.map(async (range) => {\n await sem.acquire()\n try {\n abortScope.signal.throwIfAborted()\n const copyPromise = raw.copyPart(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\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(startedLargeFileId),\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 { signal: abortScope.signal },\n )\n const resp = await raceWithAbort(copyPromise, abortScope.signal)\n partSha1s[range.partNumber - 1] = resp.contentSha1\n } catch (err) {\n abortScope.abort(err)\n throw err\n } finally {\n sem.release()\n }\n })\n\n throwRejectedOrAbortReason(await Promise.allSettled(tasks), abortScope)\n\n return await finishLargeFileWithAbortReconciliation(raw, accountInfo, {\n fileId: startedLargeFileId,\n bucketId: destBucketId,\n fileName: options.fileName,\n partSha1s,\n signal: abortScope.signal,\n })\n } catch (err) {\n abortScope.abort(err)\n if (largeFileId === undefined) throw err\n return await cleanupAfterLargeFileError(err, raw, accountInfo, {\n fileId: largeFileId,\n bucketId: destBucketId,\n fileName: options.fileName,\n signal: options.signal,\n onCleanupFailure: options.onCleanupFailure,\n })\n } finally {\n abortScope.dispose()\n }\n}\n\nfunction cancelLargeFileAfterStart(\n started: Promise<{ readonly fileId: LargeFileId }>,\n raw: RawClient,\n accountInfo: AccountInfo,\n onCleanupFailure: CleanupFailureListener | undefined,\n): void {\n void started\n .then((resp) =>\n cancelLargeFileBestEffort(\n raw,\n accountInfo,\n resp.fileId,\n onCleanupFailure === undefined ? undefined : { onCleanupFailure },\n ),\n )\n .catch(() => {\n // If start failed, no file ID is available to cancel.\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwEA,eAAsB,cACpB,KACA,aACA,SACsB;CACtB,QAAQ,QAAQ,eAAe;CAC/B,MAAM,sBAAsB,YAAY,uBAAuB;CAC/D,MAAM,cAAc,YAAY,2BAA2B;CAC3D,MAAM,WAAW,KAAK,IAAI,QAAQ,YAAY,qBAAqB,WAAW;CAC9E,MAAM,cAAc,QAAQ,eAAA;CAG5B,MAAM,aAAa,MAAM,IAAI,YAAY,YAAY,UAAU,GAAG,YAAY,aAAa,GAAG,EAC5F,QAAQ,QAAQ,aAClB,CAAC;CACD,MAAM,YAAY,WAAW;CAG7B,IAAI,aAAa,UAAU;EACzB,QAAQ,QAAQ,eAAe;EAM/B,MAAM,kBAAkB,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AAQ,QAAQ;GAChB,kBAAkB,QAAQ;EAC5B,CAAC;CACH,UAAU;EACR,WAAW,QAAQ;CACrB;AACF;AAEA,SAAS,0BACP,SACA,KACA,aACA,kBACM;CACN,QACG,MAAM,SACL,eAAA,0BACE,KACA,aACA,KAAK,QACL,qBAAqB,KAAA,IAAY,KAAA,IAAY,EAAE,iBAAiB,CAClE,CACF,CAAC,CACA,YAAY,CAEb,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"large.cjs","names":[],"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, MetadataDirective } from '../types/file.ts'\nimport { type BucketId, type FileId, fileId as fileIdOf, type LargeFileId } from '../types/ids.ts'\nimport { createAbortScope, throwRejectedOrAbortReason } from '../upload/abort-scope.ts'\nimport {\n type CleanupFailureListener,\n cancelLargeFileBestEffort,\n cleanupAfterLargeFileError,\n} from '../upload/cancel.ts'\nimport { Semaphore } from '../upload/concurrency.ts'\nimport { finishLargeFileWithAbortReconciliation } from '../upload/finish.ts'\nimport { raceWithAbort } from '../util/abort.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 * Callback invoked if best-effort cancellation fails, or if cancellation is\n * skipped because `b2_finish_large_file` may already have committed.\n */\n readonly onCleanupFailure?: CleanupFailureListener\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 options.signal?.throwIfAborted()\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 options.signal?.throwIfAborted()\n // `b2_copy_file` only accepts replacement contentType/fileInfo under\n // `metadataDirective: REPLACE`; supplying them in the default COPY mode is\n // rejected by B2. When the caller sets either, switch to REPLACE with a\n // required contentType (the override, else the source's, else b2/x-auto),\n // matching the multipart path's metadata semantics below.\n const replaceMetadata = options.contentType !== undefined || options.fileInfo !== undefined\n return raw.copyFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\n sourceFileId: options.sourceFileId,\n fileName: options.fileName,\n ...(options.destinationBucketId !== undefined\n ? { destinationBucketId: options.destinationBucketId }\n : {}),\n ...(replaceMetadata\n ? {\n metadataDirective: MetadataDirective.Replace,\n contentType: options.contentType ?? sourceInfo.contentType ?? DEFAULT_CONTENT_TYPE,\n fileInfo: options.fileInfo ?? {},\n }\n : {}),\n ...(options.destinationServerSideEncryption !== undefined\n ? { destinationServerSideEncryption: options.destinationServerSideEncryption }\n : {}),\n ...(options.sourceServerSideEncryption !== undefined\n ? { sourceServerSideEncryption: options.sourceServerSideEncryption }\n : {}),\n },\n options.signal !== undefined ? { signal: options.signal } : undefined,\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 const ranges = planRanges(totalSize, partSize)\n const partSha1s: string[] = new Array(ranges.length)\n const sem = new Semaphore(concurrency)\n const abortScope = createAbortScope(options.signal)\n let largeFileId: LargeFileId | undefined\n\n try {\n abortScope.signal.throwIfAborted()\n const startPromise = raw.startLargeFile(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\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 { signal: abortScope.signal },\n )\n try {\n const startResp = await raceWithAbort(startPromise, abortScope.signal)\n largeFileId = startResp.fileId\n } catch (err) {\n if (abortScope.signal.aborted) {\n cancelLargeFileAfterStart(startPromise, raw, accountInfo, options.onCleanupFailure)\n }\n throw err\n }\n const startedLargeFileId = largeFileId\n if (startedLargeFileId === undefined) {\n throw new Error('copyLargeFile: start did not return a large file ID.')\n }\n\n const tasks = ranges.map(async (range) => {\n await sem.acquire()\n try {\n abortScope.signal.throwIfAborted()\n const copyPromise = raw.copyPart(\n accountInfo.getApiUrl(),\n accountInfo.getAuthToken(),\n {\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(startedLargeFileId),\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 { signal: abortScope.signal },\n )\n const resp = await raceWithAbort(copyPromise, abortScope.signal)\n partSha1s[range.partNumber - 1] = resp.contentSha1\n } catch (err) {\n abortScope.abort(err)\n throw err\n } finally {\n sem.release()\n }\n })\n\n throwRejectedOrAbortReason(await Promise.allSettled(tasks), abortScope)\n\n return await finishLargeFileWithAbortReconciliation(raw, accountInfo, {\n fileId: startedLargeFileId,\n bucketId: destBucketId,\n fileName: options.fileName,\n partSha1s,\n signal: abortScope.signal,\n })\n } catch (err) {\n abortScope.abort(err)\n if (largeFileId === undefined) throw err\n return await cleanupAfterLargeFileError(err, raw, accountInfo, {\n fileId: largeFileId,\n bucketId: destBucketId,\n fileName: options.fileName,\n signal: options.signal,\n onCleanupFailure: options.onCleanupFailure,\n })\n } finally {\n abortScope.dispose()\n }\n}\n\nfunction cancelLargeFileAfterStart(\n started: Promise<{ readonly fileId: LargeFileId }>,\n raw: RawClient,\n accountInfo: AccountInfo,\n onCleanupFailure: CleanupFailureListener | undefined,\n): void {\n void started\n .then((resp) =>\n cancelLargeFileBestEffort(\n raw,\n accountInfo,\n resp.fileId,\n onCleanupF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W,CAAA;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,SAAS,EACd,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAgJtB"}
|
package/dist/copy/large.d.ts.map
CHANGED
|
@@ -1 +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,EAAE,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAwC,MAAM,iBAAiB,CAAA;
|
|
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,EAAE,KAAK,WAAW,EAAqB,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAwC,MAAM,iBAAiB,CAAA;AAElG,OAAO,EACL,KAAK,sBAAsB,EAG5B,MAAM,qBAAqB,CAAA;AAO5B,gDAAgD;AAChD,MAAM,WAAW,oBAAoB;IACnC,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,kDAAkD;IAClD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,sDAAsD;IACtD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,QAAQ,CAAA;IACvC,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,yDAAyD;IACzD,QAAQ,CAAC,+BAA+B,CAAC,EAAE,iBAAiB,CAAA;IAC5D,4EAA4E;IAC5E,QAAQ,CAAC,0BAA0B,CAAC,EAAE,iBAAiB,CAAA;IACvD;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,sBAAsB,CAAA;IAClD;;;;;;;;OAQG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,SAAS,EACd,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAgJtB"}
|
package/dist/copy/large.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MetadataDirective } from "../types/file.js";
|
|
2
2
|
import { fileId } from "../types/ids.js";
|
|
3
|
-
import { createAbortScope,
|
|
3
|
+
import { createAbortScope, throwRejectedOrAbortReason } from "../upload/abort-scope.js";
|
|
4
4
|
import { cancelLargeFileBestEffort, cleanupAfterLargeFileError } from "../upload/cancel.js";
|
|
5
5
|
import { Semaphore } from "../upload/concurrency.js";
|
|
6
|
+
import { raceWithAbort } from "../util/abort.js";
|
|
6
7
|
import { finishLargeFileWithAbortReconciliation } from "../upload/finish.js";
|
|
7
8
|
import "../util/defaults.js";
|
|
8
9
|
import { byteRangeHeader, planRanges } from "../util/plan-ranges.js";
|
|
@@ -70,14 +71,15 @@ async function copyLargeFile(raw, accountInfo, options) {
|
|
|
70
71
|
await sem.acquire();
|
|
71
72
|
try {
|
|
72
73
|
abortScope.signal.throwIfAborted();
|
|
73
|
-
const
|
|
74
|
+
const copyPromise = raw.copyPart(accountInfo.getApiUrl(), accountInfo.getAuthToken(), {
|
|
74
75
|
sourceFileId: options.sourceFileId,
|
|
75
76
|
largeFileId: fileId(startedLargeFileId),
|
|
76
77
|
partNumber: range.partNumber,
|
|
77
78
|
range: byteRangeHeader(range.start, range.end),
|
|
78
79
|
...options.sourceServerSideEncryption !== void 0 ? { sourceServerSideEncryption: options.sourceServerSideEncryption } : {},
|
|
79
80
|
...options.destinationServerSideEncryption !== void 0 ? { destinationServerSideEncryption: options.destinationServerSideEncryption } : {}
|
|
80
|
-
}, { signal: abortScope.signal })
|
|
81
|
+
}, { signal: abortScope.signal });
|
|
82
|
+
const resp = await raceWithAbort(copyPromise, abortScope.signal);
|
|
81
83
|
partSha1s[range.partNumber - 1] = resp.contentSha1;
|
|
82
84
|
} catch (err) {
|
|
83
85
|
abortScope.abort(err);
|