@backblaze-labs/b2-sdk 0.1.0 → 0.2.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 +110 -5
- package/README.md +144 -33
- package/dist/_virtual/_b2-sdk-version-json.cjs +4 -0
- package/dist/_virtual/_b2-sdk-version-json.js +4 -0
- package/dist/auth/account-info.d.cts +32 -0
- package/dist/auth/account-info.d.cts.map +1 -1
- package/dist/auth/account-info.d.ts +32 -0
- package/dist/auth/account-info.d.ts.map +1 -1
- package/dist/auth/file.cjs +408 -207
- package/dist/auth/file.cjs.map +1 -1
- package/dist/auth/file.d.cts +77 -3
- package/dist/auth/file.d.cts.map +1 -1
- package/dist/auth/file.d.ts +77 -3
- package/dist/auth/file.d.ts.map +1 -1
- package/dist/auth/file.js +407 -207
- package/dist/auth/file.js.map +1 -1
- package/dist/auth/in-memory.cjs +212 -183
- package/dist/auth/in-memory.cjs.map +1 -1
- package/dist/auth/in-memory.d.cts +8 -0
- package/dist/auth/in-memory.d.cts.map +1 -1
- package/dist/auth/in-memory.d.ts +8 -0
- package/dist/auth/in-memory.d.ts.map +1 -1
- package/dist/auth/in-memory.js +211 -182
- package/dist/auth/in-memory.js.map +1 -1
- package/dist/auth/index.cjs +7 -9
- package/dist/auth/index.d.cts +3 -2
- package/dist/auth/index.d.cts.map +1 -1
- package/dist/auth/index.d.ts +3 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -8
- package/dist/auth/realms.cjs +80 -7
- package/dist/auth/realms.cjs.map +1 -1
- package/dist/auth/realms.d.cts +27 -4
- package/dist/auth/realms.d.cts.map +1 -1
- package/dist/auth/realms.d.ts +27 -4
- package/dist/auth/realms.d.ts.map +1 -1
- package/dist/auth/realms.js +80 -9
- package/dist/auth/realms.js.map +1 -1
- package/dist/auth/upload-url-pool.cjs +55 -51
- package/dist/auth/upload-url-pool.cjs.map +1 -1
- package/dist/auth/upload-url-pool.js +55 -51
- package/dist/auth/upload-url-pool.js.map +1 -1
- package/dist/bucket.cjs +785 -787
- package/dist/bucket.cjs.map +1 -1
- package/dist/bucket.d.cts +35 -47
- package/dist/bucket.d.cts.map +1 -1
- package/dist/bucket.d.ts +35 -47
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +780 -782
- package/dist/bucket.js.map +1 -1
- package/dist/client.cjs +246 -228
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +25 -17
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts +25 -17
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +243 -225
- package/dist/client.js.map +1 -1
- package/dist/copy/large.cjs +114 -71
- package/dist/copy/large.cjs.map +1 -1
- package/dist/copy/large.d.cts +6 -0
- package/dist/copy/large.d.cts.map +1 -1
- package/dist/copy/large.d.ts +6 -0
- package/dist/copy/large.d.ts.map +1 -1
- package/dist/copy/large.js +112 -69
- package/dist/copy/large.js.map +1 -1
- package/dist/download/checksum.cjs +89 -0
- package/dist/download/checksum.cjs.map +1 -0
- package/dist/download/checksum.d.cts +40 -0
- package/dist/download/checksum.d.cts.map +1 -0
- package/dist/download/checksum.d.ts +40 -0
- package/dist/download/checksum.d.ts.map +1 -0
- package/dist/download/checksum.js +87 -0
- package/dist/download/checksum.js.map +1 -0
- package/dist/download/parallel.cjs +214 -118
- package/dist/download/parallel.cjs.map +1 -1
- package/dist/download/parallel.d.cts +5 -1
- package/dist/download/parallel.d.cts.map +1 -1
- package/dist/download/parallel.d.ts +5 -1
- package/dist/download/parallel.d.ts.map +1 -1
- package/dist/download/parallel.js +212 -116
- package/dist/download/parallel.js.map +1 -1
- package/dist/download/single.cjs +188 -97
- package/dist/download/single.cjs.map +1 -1
- package/dist/download/single.d.cts +6 -1
- package/dist/download/single.d.cts.map +1 -1
- package/dist/download/single.d.ts +6 -1
- package/dist/download/single.d.ts.map +1 -1
- package/dist/download/single.js +186 -98
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +699 -243
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +285 -82
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +285 -82
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +678 -261
- package/dist/errors/index.js.map +1 -1
- package/dist/http/retry.cjs +45 -28
- package/dist/http/retry.cjs.map +1 -1
- package/dist/http/retry.d.cts +15 -2
- package/dist/http/retry.d.cts.map +1 -1
- package/dist/http/retry.d.ts +15 -2
- package/dist/http/retry.d.ts.map +1 -1
- package/dist/http/retry.js +46 -31
- package/dist/http/retry.js.map +1 -1
- package/dist/http/transport.cjs +438 -140
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +21 -2
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +21 -2
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +437 -140
- package/dist/http/transport.js.map +1 -1
- package/dist/http/url-guard.cjs +154 -89
- package/dist/http/url-guard.cjs.map +1 -1
- package/dist/http/url-guard.d.cts +25 -3
- package/dist/http/url-guard.d.cts.map +1 -1
- package/dist/http/url-guard.d.ts +25 -3
- package/dist/http/url-guard.d.ts.map +1 -1
- package/dist/http/url-guard.js +152 -90
- package/dist/http/url-guard.js.map +1 -1
- package/dist/http/user-agent.cjs +84 -44
- package/dist/http/user-agent.cjs.map +1 -1
- package/dist/http/user-agent.js +84 -46
- package/dist/http/user-agent.js.map +1 -1
- package/dist/index.cjs +101 -77
- package/dist/index.d.cts +27 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +27 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -71
- package/dist/internal/b2-naming.cjs +66 -0
- package/dist/internal/b2-naming.cjs.map +1 -0
- package/dist/internal/b2-naming.d.cts +43 -0
- package/dist/internal/b2-naming.d.cts.map +1 -0
- package/dist/internal/b2-naming.d.ts +43 -0
- package/dist/internal/b2-naming.d.ts.map +1 -0
- package/dist/internal/b2-naming.js +60 -0
- package/dist/internal/b2-naming.js.map +1 -0
- package/dist/internal/upload-retry-options.cjs +21 -0
- package/dist/internal/upload-retry-options.cjs.map +1 -0
- package/dist/internal/upload-retry-options.d.cts +12 -0
- package/dist/internal/upload-retry-options.d.cts.map +1 -0
- package/dist/internal/upload-retry-options.d.ts +12 -0
- package/dist/internal/upload-retry-options.d.ts.map +1 -0
- package/dist/internal/upload-retry-options.js +21 -0
- package/dist/internal/upload-retry-options.js.map +1 -0
- package/dist/internal/url-redaction.cjs +31 -0
- package/dist/internal/url-redaction.cjs.map +1 -0
- package/dist/internal/url-redaction.d.cts +17 -0
- package/dist/internal/url-redaction.d.cts.map +1 -0
- package/dist/internal/url-redaction.d.ts +17 -0
- package/dist/internal/url-redaction.d.ts.map +1 -0
- package/dist/internal/url-redaction.js +31 -0
- package/dist/internal/url-redaction.js.map +1 -0
- package/dist/notifications/index.cjs +4 -6
- package/dist/notifications/index.d.cts +1 -1
- package/dist/notifications/index.d.cts.map +1 -1
- package/dist/notifications/index.d.ts +1 -1
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +1 -6
- package/dist/notifications/webhook.cjs +195 -85
- package/dist/notifications/webhook.cjs.map +1 -1
- package/dist/notifications/webhook.d.cts.map +1 -1
- package/dist/notifications/webhook.d.ts.map +1 -1
- package/dist/notifications/webhook.js +195 -87
- package/dist/notifications/webhook.js.map +1 -1
- package/dist/object.cjs +253 -210
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.cts +9 -55
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +9 -55
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +249 -206
- package/dist/object.js.map +1 -1
- package/dist/raw/encoding.cjs +74 -35
- package/dist/raw/encoding.cjs.map +1 -1
- package/dist/raw/encoding.js +74 -38
- package/dist/raw/encoding.js.map +1 -1
- package/dist/raw/index.cjs +678 -587
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +121 -18
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +121 -18
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +674 -589
- package/dist/raw/index.js.map +1 -1
- package/dist/s3/index.cjs +355 -18
- package/dist/s3/index.cjs.map +1 -1
- package/dist/s3/index.d.cts +233 -5
- package/dist/s3/index.d.cts.map +1 -1
- package/dist/s3/index.d.ts +233 -5
- package/dist/s3/index.d.ts.map +1 -1
- package/dist/s3/index.js +351 -22
- package/dist/s3/index.js.map +1 -1
- package/dist/s3/sigv4.cjs +149 -0
- package/dist/s3/sigv4.cjs.map +1 -0
- package/dist/s3/sigv4.d.cts +43 -0
- package/dist/s3/sigv4.d.cts.map +1 -0
- package/dist/s3/sigv4.d.ts +43 -0
- package/dist/s3/sigv4.d.ts.map +1 -0
- package/dist/s3/sigv4.js +148 -0
- package/dist/s3/sigv4.js.map +1 -0
- package/dist/s3/validation.cjs +69 -0
- package/dist/s3/validation.cjs.map +1 -0
- package/dist/s3/validation.d.cts +43 -0
- package/dist/s3/validation.d.cts.map +1 -0
- package/dist/s3/validation.d.ts +43 -0
- package/dist/s3/validation.d.ts.map +1 -0
- package/dist/s3/validation.js +66 -0
- package/dist/s3/validation.js.map +1 -0
- package/dist/simulator/capabilities.cjs +63 -48
- package/dist/simulator/capabilities.cjs.map +1 -1
- package/dist/simulator/capabilities.js +63 -49
- package/dist/simulator/capabilities.js.map +1 -1
- package/dist/simulator/index.cjs +2124 -1548
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +79 -11
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +79 -11
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +2112 -1546
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/validation.cjs +191 -153
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +3 -21
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +3 -21
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +188 -162
- package/dist/simulator/validation.js.map +1 -1
- package/dist/streams/collect.cjs +74 -24
- package/dist/streams/collect.cjs.map +1 -1
- package/dist/streams/collect.d.cts +14 -1
- package/dist/streams/collect.d.cts.map +1 -1
- package/dist/streams/collect.d.ts +14 -1
- package/dist/streams/collect.d.ts.map +1 -1
- package/dist/streams/collect.js +74 -25
- package/dist/streams/collect.js.map +1 -1
- package/dist/streams/file-source.cjs +287 -0
- package/dist/streams/file-source.cjs.map +1 -0
- package/dist/streams/file-source.d.cts +96 -0
- package/dist/streams/file-source.d.cts.map +1 -0
- package/dist/streams/file-source.d.ts +96 -0
- package/dist/streams/file-source.d.ts.map +1 -0
- package/dist/streams/file-source.js +286 -0
- package/dist/streams/file-source.js.map +1 -0
- package/dist/streams/hash.cjs +207 -115
- package/dist/streams/hash.cjs.map +1 -1
- package/dist/streams/hash.d.cts +5 -4
- package/dist/streams/hash.d.cts.map +1 -1
- package/dist/streams/hash.d.ts +5 -4
- package/dist/streams/hash.d.ts.map +1 -1
- package/dist/streams/hash.js +208 -95
- package/dist/streams/hash.js.map +1 -1
- package/dist/streams/index.cjs +12 -12
- package/dist/streams/index.d.cts +3 -3
- package/dist/streams/index.d.cts.map +1 -1
- package/dist/streams/index.d.ts +3 -3
- package/dist/streams/index.d.ts.map +1 -1
- package/dist/streams/index.js +2 -10
- package/dist/streams/progress.cjs +60 -46
- package/dist/streams/progress.cjs.map +1 -1
- package/dist/streams/progress.js +60 -46
- package/dist/streams/progress.js.map +1 -1
- package/dist/streams/source.cjs +316 -146
- package/dist/streams/source.cjs.map +1 -1
- package/dist/streams/source.d.cts +56 -18
- package/dist/streams/source.d.cts.map +1 -1
- package/dist/streams/source.d.ts +56 -18
- package/dist/streams/source.d.ts.map +1 -1
- package/dist/streams/source.js +312 -149
- package/dist/streams/source.js.map +1 -1
- package/dist/sync/actions/index.cjs +236 -184
- package/dist/sync/actions/index.cjs.map +1 -1
- package/dist/sync/actions/index.d.cts +29 -21
- package/dist/sync/actions/index.d.cts.map +1 -1
- package/dist/sync/actions/index.d.ts +29 -21
- package/dist/sync/actions/index.d.ts.map +1 -1
- package/dist/sync/actions/index.js +236 -190
- package/dist/sync/actions/index.js.map +1 -1
- package/dist/sync/b2-sha1-reader.cjs +148 -0
- package/dist/sync/b2-sha1-reader.cjs.map +1 -0
- package/dist/sync/b2-sha1-reader.d.cts +58 -0
- package/dist/sync/b2-sha1-reader.d.cts.map +1 -0
- package/dist/sync/b2-sha1-reader.d.ts +58 -0
- package/dist/sync/b2-sha1-reader.d.ts.map +1 -0
- package/dist/sync/b2-sha1-reader.js +145 -0
- package/dist/sync/b2-sha1-reader.js.map +1 -0
- package/dist/sync/download-staging.cjs +265 -0
- package/dist/sync/download-staging.cjs.map +1 -0
- package/dist/sync/download-staging.d.cts +54 -0
- package/dist/sync/download-staging.d.cts.map +1 -0
- package/dist/sync/download-staging.d.ts +54 -0
- package/dist/sync/download-staging.d.ts.map +1 -0
- package/dist/sync/download-staging.js +259 -0
- package/dist/sync/download-staging.js.map +1 -0
- package/dist/sync/filesystem-errors.cjs +32 -0
- package/dist/sync/filesystem-errors.cjs.map +1 -0
- package/dist/sync/filesystem-errors.d.cts +8 -0
- package/dist/sync/filesystem-errors.d.cts.map +1 -0
- package/dist/sync/filesystem-errors.d.ts +8 -0
- package/dist/sync/filesystem-errors.d.ts.map +1 -0
- package/dist/sync/filesystem-errors.js +32 -0
- package/dist/sync/filesystem-errors.js.map +1 -0
- package/dist/sync/filters.cjs +217 -0
- package/dist/sync/filters.cjs.map +1 -0
- package/dist/sync/filters.d.cts +51 -0
- package/dist/sync/filters.d.cts.map +1 -0
- package/dist/sync/filters.d.ts +51 -0
- package/dist/sync/filters.d.ts.map +1 -0
- package/dist/sync/filters.js +213 -0
- package/dist/sync/filters.js.map +1 -0
- package/dist/sync/index.cjs +39 -22
- package/dist/sync/index.d.cts +14 -9
- package/dist/sync/index.d.cts.map +1 -1
- package/dist/sync/index.d.ts +14 -9
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +9 -20
- package/dist/sync/local-file-identity.cjs +61 -0
- package/dist/sync/local-file-identity.cjs.map +1 -0
- package/dist/sync/local-file-identity.d.cts +37 -0
- package/dist/sync/local-file-identity.d.cts.map +1 -0
- package/dist/sync/local-file-identity.d.ts +37 -0
- package/dist/sync/local-file-identity.d.ts.map +1 -0
- package/dist/sync/local-file-identity.js +60 -0
- package/dist/sync/local-file-identity.js.map +1 -0
- package/dist/sync/local-file-io.cjs +364 -0
- package/dist/sync/local-file-io.cjs.map +1 -0
- package/dist/sync/local-file-io.d.cts +75 -0
- package/dist/sync/local-file-io.d.cts.map +1 -0
- package/dist/sync/local-file-io.d.ts +75 -0
- package/dist/sync/local-file-io.d.ts.map +1 -0
- package/dist/sync/local-file-io.js +360 -0
- package/dist/sync/local-file-io.js.map +1 -0
- package/dist/sync/local-filesystem-root.cjs +27 -0
- package/dist/sync/local-filesystem-root.cjs.map +1 -0
- package/dist/sync/local-filesystem-root.d.cts +18 -0
- package/dist/sync/local-filesystem-root.d.cts.map +1 -0
- package/dist/sync/local-filesystem-root.d.ts +18 -0
- package/dist/sync/local-filesystem-root.d.ts.map +1 -0
- package/dist/sync/local-filesystem-root.js +26 -0
- package/dist/sync/local-filesystem-root.js.map +1 -0
- package/dist/sync/local-sha1.cjs +119 -0
- package/dist/sync/local-sha1.cjs.map +1 -0
- package/dist/sync/local-sha1.d.cts +39 -0
- package/dist/sync/local-sha1.d.cts.map +1 -0
- package/dist/sync/local-sha1.d.ts +39 -0
- package/dist/sync/local-sha1.d.ts.map +1 -0
- package/dist/sync/local-sha1.js +117 -0
- package/dist/sync/local-sha1.js.map +1 -0
- package/dist/sync/pairing.cjs +118 -29
- package/dist/sync/pairing.cjs.map +1 -1
- package/dist/sync/pairing.d.cts +7 -2
- package/dist/sync/pairing.d.cts.map +1 -1
- package/dist/sync/pairing.d.ts +7 -2
- package/dist/sync/pairing.d.ts.map +1 -1
- package/dist/sync/pairing.js +120 -31
- package/dist/sync/pairing.js.map +1 -1
- package/dist/sync/path-order.cjs +30 -0
- package/dist/sync/path-order.cjs.map +1 -0
- package/dist/sync/path-order.d.cts +28 -0
- package/dist/sync/path-order.d.cts.map +1 -0
- package/dist/sync/path-order.d.ts +28 -0
- package/dist/sync/path-order.d.ts.map +1 -0
- package/dist/sync/path-order.js +29 -0
- package/dist/sync/path-order.js.map +1 -0
- package/dist/sync/path-safety.cjs +111 -0
- package/dist/sync/path-safety.cjs.map +1 -0
- package/dist/sync/path-safety.d.cts +78 -0
- package/dist/sync/path-safety.d.cts.map +1 -0
- package/dist/sync/path-safety.d.ts +78 -0
- package/dist/sync/path-safety.d.ts.map +1 -0
- package/dist/sync/path-safety.js +105 -0
- package/dist/sync/path-safety.js.map +1 -0
- package/dist/sync/paths.d.cts +19 -0
- package/dist/sync/paths.d.cts.map +1 -0
- package/dist/sync/paths.d.ts +19 -0
- package/dist/sync/paths.d.ts.map +1 -0
- package/dist/sync/policies/compare.cjs +389 -11
- package/dist/sync/policies/compare.cjs.map +1 -1
- package/dist/sync/policies/compare.d.cts +100 -2
- package/dist/sync/policies/compare.d.cts.map +1 -1
- package/dist/sync/policies/compare.d.ts +100 -2
- package/dist/sync/policies/compare.d.ts.map +1 -1
- package/dist/sync/policies/compare.js +387 -13
- package/dist/sync/policies/compare.js.map +1 -1
- package/dist/sync/policies/index.cjs +76 -65
- package/dist/sync/policies/index.cjs.map +1 -1
- package/dist/sync/policies/index.d.cts +35 -6
- package/dist/sync/policies/index.d.cts.map +1 -1
- package/dist/sync/policies/index.d.ts +35 -6
- package/dist/sync/policies/index.d.ts.map +1 -1
- package/dist/sync/policies/index.js +76 -65
- package/dist/sync/policies/index.js.map +1 -1
- package/dist/sync/prefix.cjs +96 -0
- package/dist/sync/prefix.cjs.map +1 -0
- package/dist/sync/prefix.d.cts +55 -0
- package/dist/sync/prefix.d.cts.map +1 -0
- package/dist/sync/prefix.d.ts +55 -0
- package/dist/sync/prefix.d.ts.map +1 -0
- package/dist/sync/prefix.js +92 -0
- package/dist/sync/prefix.js.map +1 -0
- package/dist/sync/regexp-safety.cjs +192 -0
- package/dist/sync/regexp-safety.cjs.map +1 -0
- package/dist/sync/regexp-safety.d.cts +29 -0
- package/dist/sync/regexp-safety.d.cts.map +1 -0
- package/dist/sync/regexp-safety.d.ts +29 -0
- package/dist/sync/regexp-safety.d.ts.map +1 -0
- package/dist/sync/regexp-safety.js +190 -0
- package/dist/sync/regexp-safety.js.map +1 -0
- package/dist/sync/scan-events.cjs +33 -0
- package/dist/sync/scan-events.cjs.map +1 -0
- package/dist/sync/scan-events.d.cts +17 -0
- package/dist/sync/scan-events.d.cts.map +1 -0
- package/dist/sync/scan-events.d.ts +17 -0
- package/dist/sync/scan-events.d.ts.map +1 -0
- package/dist/sync/scan-events.js +32 -0
- package/dist/sync/scan-events.js.map +1 -0
- package/dist/sync/scan-limit.cjs +33 -0
- package/dist/sync/scan-limit.cjs.map +1 -0
- package/dist/sync/scan-limit.d.cts +21 -0
- package/dist/sync/scan-limit.d.cts.map +1 -0
- package/dist/sync/scan-limit.d.ts +21 -0
- package/dist/sync/scan-limit.d.ts.map +1 -0
- package/dist/sync/scan-limit.js +31 -0
- package/dist/sync/scan-limit.js.map +1 -0
- package/dist/sync/scanners/b2.cjs +239 -55
- package/dist/sync/scanners/b2.cjs.map +1 -1
- package/dist/sync/scanners/b2.d.cts +26 -7
- package/dist/sync/scanners/b2.d.cts.map +1 -1
- package/dist/sync/scanners/b2.d.ts +26 -7
- package/dist/sync/scanners/b2.d.ts.map +1 -1
- package/dist/sync/scanners/b2.js +239 -55
- package/dist/sync/scanners/b2.js.map +1 -1
- package/dist/sync/scanners/local.cjs +215 -56
- package/dist/sync/scanners/local.cjs.map +1 -1
- package/dist/sync/scanners/local.d.cts +22 -7
- package/dist/sync/scanners/local.d.cts.map +1 -1
- package/dist/sync/scanners/local.d.ts +22 -7
- package/dist/sync/scanners/local.d.ts.map +1 -1
- package/dist/sync/scanners/local.js +216 -57
- package/dist/sync/scanners/local.js.map +1 -1
- package/dist/sync/sha1-metadata.cjs +94 -0
- package/dist/sync/sha1-metadata.cjs.map +1 -0
- package/dist/sync/sha1-metadata.d.cts +82 -0
- package/dist/sync/sha1-metadata.d.cts.map +1 -0
- package/dist/sync/sha1-metadata.d.ts +82 -0
- package/dist/sync/sha1-metadata.d.ts.map +1 -0
- package/dist/sync/sha1-metadata.js +89 -0
- package/dist/sync/sha1-metadata.js.map +1 -0
- package/dist/sync/sha1-options.cjs +23 -0
- package/dist/sync/sha1-options.cjs.map +1 -0
- package/dist/sync/sha1-options.d.cts +14 -0
- package/dist/sync/sha1-options.d.cts.map +1 -0
- package/dist/sync/sha1-options.d.ts +14 -0
- package/dist/sync/sha1-options.d.ts.map +1 -0
- package/dist/sync/sha1-options.js +21 -0
- package/dist/sync/sha1-options.js.map +1 -0
- package/dist/sync/synchronizer.cjs +782 -197
- package/dist/sync/synchronizer.cjs.map +1 -1
- package/dist/sync/synchronizer.d.cts +47 -1
- package/dist/sync/synchronizer.d.cts.map +1 -1
- package/dist/sync/synchronizer.d.ts +47 -1
- package/dist/sync/synchronizer.d.ts.map +1 -1
- package/dist/sync/synchronizer.js +779 -173
- package/dist/sync/synchronizer.js.map +1 -1
- package/dist/sync/types.d.cts +208 -16
- package/dist/sync/types.d.cts.map +1 -1
- package/dist/sync/types.d.ts +208 -16
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/types/auth.cjs +76 -56
- package/dist/types/auth.cjs.map +1 -1
- package/dist/types/auth.d.cts +67 -9
- package/dist/types/auth.d.cts.map +1 -1
- package/dist/types/auth.d.ts +67 -9
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +77 -57
- package/dist/types/auth.js.map +1 -1
- package/dist/types/bucket.cjs +74 -38
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.js +75 -41
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/encryption.cjs +364 -327
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +16 -0
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +16 -0
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +364 -310
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/errors.cjs +47 -0
- package/dist/types/errors.cjs.map +1 -0
- package/dist/types/errors.d.cts +13 -4
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +13 -4
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +47 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/file.cjs +36 -19
- package/dist/types/file.cjs.map +1 -1
- package/dist/types/file.d.cts +2 -2
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +2 -2
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/file.js +37 -21
- package/dist/types/file.js.map +1 -1
- package/dist/types/ids.cjs +53 -9
- package/dist/types/ids.cjs.map +1 -1
- package/dist/types/ids.js +54 -15
- package/dist/types/ids.js.map +1 -1
- package/dist/types/index.d.cts +12 -11
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +12 -11
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key.d.cts +44 -8
- package/dist/types/key.d.cts.map +1 -1
- package/dist/types/key.d.ts +44 -8
- package/dist/types/key.d.ts.map +1 -1
- package/dist/types/lock.cjs +33 -13
- package/dist/types/lock.cjs.map +1 -1
- package/dist/types/lock.js +34 -15
- package/dist/types/lock.js.map +1 -1
- package/dist/types/notifications.cjs +44 -22
- package/dist/types/notifications.cjs.map +1 -1
- package/dist/types/notifications.js +45 -23
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/upload.d.cts +39 -5
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +39 -5
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort-scope.cjs +91 -0
- package/dist/upload/abort-scope.cjs.map +1 -0
- package/dist/upload/abort-scope.d.cts +48 -0
- package/dist/upload/abort-scope.d.cts.map +1 -0
- package/dist/upload/abort-scope.d.ts +48 -0
- package/dist/upload/abort-scope.d.ts.map +1 -0
- package/dist/upload/abort-scope.js +88 -0
- package/dist/upload/abort-scope.js.map +1 -0
- package/dist/upload/cancel.cjs +183 -8
- package/dist/upload/cancel.cjs.map +1 -1
- package/dist/upload/cancel.d.cts +110 -2
- package/dist/upload/cancel.d.cts.map +1 -1
- package/dist/upload/cancel.d.ts +110 -2
- package/dist/upload/cancel.d.ts.map +1 -1
- package/dist/upload/cancel.js +178 -9
- package/dist/upload/cancel.js.map +1 -1
- package/dist/upload/concurrency.cjs +79 -52
- package/dist/upload/concurrency.cjs.map +1 -1
- package/dist/upload/concurrency.js +79 -53
- package/dist/upload/concurrency.js.map +1 -1
- package/dist/upload/finish.cjs +59 -0
- package/dist/upload/finish.cjs.map +1 -0
- package/dist/upload/finish.d.cts +26 -0
- package/dist/upload/finish.d.cts.map +1 -0
- package/dist/upload/finish.d.ts +26 -0
- package/dist/upload/finish.d.ts.map +1 -0
- package/dist/upload/finish.js +59 -0
- package/dist/upload/finish.js.map +1 -0
- package/dist/upload/large.cjs +301 -218
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +76 -9
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +76 -9
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +301 -218
- package/dist/upload/large.js.map +1 -1
- package/dist/upload/options.cjs +28 -0
- package/dist/upload/options.cjs.map +1 -0
- package/dist/upload/options.d.cts +104 -0
- package/dist/upload/options.d.cts.map +1 -0
- package/dist/upload/options.d.ts +104 -0
- package/dist/upload/options.d.ts.map +1 -0
- package/dist/upload/options.js +27 -0
- package/dist/upload/options.js.map +1 -0
- package/dist/upload/resume.cjs +333 -33
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +82 -12
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +82 -12
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +330 -33
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +186 -0
- package/dist/upload/retry.cjs.map +1 -0
- package/dist/upload/retry.d.cts +127 -0
- package/dist/upload/retry.d.cts.map +1 -0
- package/dist/upload/retry.d.ts +127 -0
- package/dist/upload/retry.d.ts.map +1 -0
- package/dist/upload/retry.js +182 -0
- package/dist/upload/retry.js.map +1 -0
- package/dist/upload/single.cjs +68 -44
- package/dist/upload/single.cjs.map +1 -1
- package/dist/upload/single.d.cts +2 -1
- package/dist/upload/single.d.cts.map +1 -1
- package/dist/upload/single.d.ts +2 -1
- package/dist/upload/single.d.ts.map +1 -1
- package/dist/upload/single.js +68 -44
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +317 -193
- package/dist/upload/stream.cjs.map +1 -1
- package/dist/upload/stream.d.cts +3 -1
- package/dist/upload/stream.d.cts.map +1 -1
- package/dist/upload/stream.d.ts +3 -1
- package/dist/upload/stream.d.ts.map +1 -1
- package/dist/upload/stream.js +316 -192
- package/dist/upload/stream.js.map +1 -1
- package/dist/util/best-effort.cjs +42 -8
- package/dist/util/best-effort.cjs.map +1 -1
- package/dist/util/best-effort.d.cts +2 -1
- package/dist/util/best-effort.d.cts.map +1 -1
- package/dist/util/best-effort.d.ts +2 -1
- package/dist/util/best-effort.d.ts.map +1 -1
- package/dist/util/best-effort.js +43 -9
- package/dist/util/best-effort.js.map +1 -1
- package/dist/util/bytes.cjs +23 -0
- package/dist/util/bytes.cjs.map +1 -0
- package/dist/util/bytes.d.cts +15 -0
- package/dist/util/bytes.d.cts.map +1 -0
- package/dist/util/bytes.d.ts +15 -0
- package/dist/util/bytes.d.ts.map +1 -0
- package/dist/util/bytes.js +23 -0
- package/dist/util/bytes.js.map +1 -0
- package/dist/util/crypto.cjs +68 -0
- package/dist/util/crypto.cjs.map +1 -0
- package/dist/util/crypto.d.cts +26 -0
- package/dist/util/crypto.d.cts.map +1 -0
- package/dist/util/crypto.d.ts +26 -0
- package/dist/util/crypto.d.ts.map +1 -0
- package/dist/util/crypto.js +66 -0
- package/dist/util/crypto.js.map +1 -0
- package/dist/util/defaults.cjs +25 -9
- package/dist/util/defaults.cjs.map +1 -1
- package/dist/util/defaults.js +26 -11
- package/dist/util/defaults.js.map +1 -1
- package/dist/util/error-reason.cjs +41 -0
- package/dist/util/error-reason.cjs.map +1 -0
- package/dist/util/error-reason.d.cts +9 -0
- package/dist/util/error-reason.d.cts.map +1 -0
- package/dist/util/error-reason.d.ts +9 -0
- package/dist/util/error-reason.d.ts.map +1 -0
- package/dist/util/error-reason.js +41 -0
- package/dist/util/error-reason.js.map +1 -0
- package/dist/util/http.cjs +23 -0
- package/dist/util/http.cjs.map +1 -0
- package/dist/util/http.d.cts +13 -0
- package/dist/util/http.d.cts.map +1 -0
- package/dist/util/http.d.ts +13 -0
- package/dist/util/http.d.ts.map +1 -0
- package/dist/util/http.js +23 -0
- package/dist/util/http.js.map +1 -0
- package/dist/util/normalize.cjs +66 -7
- package/dist/util/normalize.cjs.map +1 -1
- package/dist/util/normalize.js +67 -10
- package/dist/util/normalize.js.map +1 -1
- package/dist/util/paginator.cjs +63 -14
- package/dist/util/paginator.cjs.map +1 -1
- package/dist/util/paginator.js +64 -16
- package/dist/util/paginator.js.map +1 -1
- package/dist/util/plan-ranges.cjs +47 -22
- package/dist/util/plan-ranges.cjs.map +1 -1
- package/dist/util/plan-ranges.js +48 -24
- package/dist/util/plan-ranges.js.map +1 -1
- package/dist/util/sha1.cjs +27 -0
- package/dist/util/sha1.cjs.map +1 -0
- package/dist/util/sha1.d.cts +17 -0
- package/dist/util/sha1.d.cts.map +1 -0
- package/dist/util/sha1.d.ts +17 -0
- package/dist/util/sha1.d.ts.map +1 -0
- package/dist/util/sha1.js +26 -0
- package/dist/util/sha1.js.map +1 -0
- package/dist/util/text-codec.cjs +29 -5
- package/dist/util/text-codec.cjs.map +1 -1
- package/dist/util/text-codec.js +30 -7
- package/dist/util/text-codec.js.map +1 -1
- package/dist/util/to-error.cjs +18 -4
- package/dist/util/to-error.cjs.map +1 -1
- package/dist/util/to-error.js +19 -5
- package/dist/util/to-error.js.map +1 -1
- package/dist/version.cjs +17 -5
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +3 -3
- package/dist/version.d.ts +3 -3
- package/dist/version.js +19 -6
- package/dist/version.js.map +1 -1
- package/package.json +19 -16
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/notifications/index.cjs.map +0 -1
- package/dist/notifications/index.js.map +0 -1
- package/dist/package.json.cjs +0 -9
- package/dist/package.json.cjs.map +0 -1
- package/dist/package.json.js +0 -9
- package/dist/package.json.js.map +0 -1
- package/dist/streams/index.cjs.map +0 -1
- package/dist/streams/index.js.map +0 -1
- package/dist/sync/index.cjs.map +0 -1
- package/dist/sync/index.js.map +0 -1
package/dist/raw/index.js
CHANGED
|
@@ -1,601 +1,686 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { buildFileInfoHeaders, encodeFileName } from "./encoding.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
method: "GET",
|
|
28
|
-
headers: {
|
|
29
|
-
Authorization: `Basic ${btoa(`${applicationKeyId}:${applicationKey}`)}`
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return response.json();
|
|
33
|
-
}
|
|
34
|
-
// --- Buckets ---
|
|
35
|
-
/**
|
|
36
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-create-bucket | b2_create_bucket}.
|
|
37
|
-
* @param apiUrl - The B2 API base URL.
|
|
38
|
-
* @param authToken - The authorization token.
|
|
39
|
-
* @param request - The API request parameters.
|
|
40
|
-
*
|
|
41
|
-
* @returns The created bucket metadata.
|
|
42
|
-
*/
|
|
43
|
-
async createBucket(apiUrl, authToken, request) {
|
|
44
|
-
return this.postJson(apiUrl, authToken, "b2_create_bucket", request);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-delete-bucket | b2_delete_bucket}.
|
|
48
|
-
* @param apiUrl - The B2 API base URL.
|
|
49
|
-
* @param authToken - The authorization token.
|
|
50
|
-
* @param request - The API request parameters.
|
|
51
|
-
*
|
|
52
|
-
* @returns The deleted bucket metadata.
|
|
53
|
-
*/
|
|
54
|
-
async deleteBucket(apiUrl, authToken, request) {
|
|
55
|
-
return this.postJson(apiUrl, authToken, "b2_delete_bucket", request);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-list-buckets | b2_list_buckets}.
|
|
59
|
-
* @param apiUrl - The B2 API base URL.
|
|
60
|
-
* @param authToken - The authorization token.
|
|
61
|
-
* @param request - The API request parameters.
|
|
62
|
-
*
|
|
63
|
-
* @returns The list of matching buckets.
|
|
64
|
-
*/
|
|
65
|
-
async listBuckets(apiUrl, authToken, request) {
|
|
66
|
-
return this.postJson(apiUrl, authToken, "b2_list_buckets", request);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-update-bucket | b2_update_bucket}.
|
|
70
|
-
* @param apiUrl - The B2 API base URL.
|
|
71
|
-
* @param authToken - The authorization token.
|
|
72
|
-
* @param request - The API request parameters.
|
|
73
|
-
*
|
|
74
|
-
* @returns The updated bucket metadata.
|
|
75
|
-
*/
|
|
76
|
-
async updateBucket(apiUrl, authToken, request) {
|
|
77
|
-
return this.postJson(apiUrl, authToken, "b2_update_bucket", request);
|
|
78
|
-
}
|
|
79
|
-
// --- Files ---
|
|
80
|
-
/**
|
|
81
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-get-upload-url | b2_get_upload_url}.
|
|
82
|
-
* @param apiUrl - The B2 API base URL.
|
|
83
|
-
* @param authToken - The authorization token.
|
|
84
|
-
* @param request - The API request parameters.
|
|
85
|
-
*
|
|
86
|
-
* @returns The upload URL and authorization token.
|
|
87
|
-
*/
|
|
88
|
-
async getUploadUrl(apiUrl, authToken, request) {
|
|
89
|
-
return this.postJson(apiUrl, authToken, "b2_get_upload_url", request);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-upload-file | b2_upload_file}.
|
|
93
|
-
*
|
|
94
|
-
* Unlike most methods, this posts directly to the `uploadUrl` obtained
|
|
95
|
-
* from {@link getUploadUrl} rather than the API URL.
|
|
96
|
-
* @param uploadUrl - The upload endpoint URL.
|
|
97
|
-
* @param headers - The request headers including authorization and content metadata.
|
|
98
|
-
* @param body - The file data to upload.
|
|
99
|
-
* @param signal - An optional abort signal for cancellation.
|
|
100
|
-
*
|
|
101
|
-
* @returns The uploaded file version metadata.
|
|
102
|
-
*/
|
|
103
|
-
async uploadFile(uploadUrl, headers, body, signal) {
|
|
104
|
-
const reqHeaders = {
|
|
105
|
-
Authorization: headers.authorization,
|
|
106
|
-
"X-Bz-File-Name": encodeFileName(headers.fileName),
|
|
107
|
-
"Content-Type": headers.contentType,
|
|
108
|
-
"Content-Length": String(headers.contentLength),
|
|
109
|
-
"X-Bz-Content-Sha1": headers.contentSha1,
|
|
110
|
-
...buildFileInfoHeaders(headers.fileInfo)
|
|
111
|
-
};
|
|
112
|
-
if (headers.lastModifiedMillis !== void 0) {
|
|
113
|
-
reqHeaders["X-Bz-Info-src_last_modified_millis"] = String(headers.lastModifiedMillis);
|
|
114
|
-
}
|
|
115
|
-
if (headers.contentDisposition) {
|
|
116
|
-
reqHeaders["X-Bz-Info-b2-content-disposition"] = headers.contentDisposition;
|
|
117
|
-
}
|
|
118
|
-
if (headers.contentLanguage) {
|
|
119
|
-
reqHeaders["X-Bz-Info-b2-content-language"] = headers.contentLanguage;
|
|
120
|
-
}
|
|
121
|
-
if (headers.expires) {
|
|
122
|
-
reqHeaders["X-Bz-Info-b2-expires"] = headers.expires;
|
|
123
|
-
}
|
|
124
|
-
if (headers.cacheControl) {
|
|
125
|
-
reqHeaders["X-Bz-Info-b2-cache-control"] = headers.cacheControl;
|
|
126
|
-
}
|
|
127
|
-
if (headers.contentEncoding) {
|
|
128
|
-
reqHeaders["X-Bz-Info-b2-content-encoding"] = headers.contentEncoding;
|
|
129
|
-
}
|
|
130
|
-
applyEncryptionHeaders(reqHeaders, headers.serverSideEncryption);
|
|
131
|
-
applyRetentionHeaders(reqHeaders, headers.fileRetention);
|
|
132
|
-
applyLegalHoldHeader(reqHeaders, headers.legalHold);
|
|
133
|
-
const response = await this.transport.send({
|
|
134
|
-
url: uploadUrl,
|
|
135
|
-
method: "POST",
|
|
136
|
-
headers: reqHeaders,
|
|
137
|
-
body,
|
|
138
|
-
...signal !== void 0 ? { signal } : {}
|
|
139
|
-
});
|
|
140
|
-
return normalizeFileVersionSha1(await response.json());
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-list-file-names | b2_list_file_names}.
|
|
144
|
-
* @param apiUrl - The B2 API base URL.
|
|
145
|
-
* @param authToken - The authorization token.
|
|
146
|
-
* @param request - The API request parameters.
|
|
147
|
-
*
|
|
148
|
-
* @returns The list of file names and optional continuation token.
|
|
149
|
-
*/
|
|
150
|
-
async listFileNames(apiUrl, authToken, request) {
|
|
151
|
-
return normalizeFileVersionListSha1(
|
|
152
|
-
await this.postJson(apiUrl, authToken, "b2_list_file_names", request)
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-list-file-versions | b2_list_file_versions}.
|
|
157
|
-
* @param apiUrl - The B2 API base URL.
|
|
158
|
-
* @param authToken - The authorization token.
|
|
159
|
-
* @param request - The API request parameters.
|
|
160
|
-
*
|
|
161
|
-
* @returns The list of file versions and optional continuation token.
|
|
162
|
-
*/
|
|
163
|
-
async listFileVersions(apiUrl, authToken, request) {
|
|
164
|
-
return normalizeFileVersionListSha1(
|
|
165
|
-
await this.postJson(
|
|
166
|
-
apiUrl,
|
|
167
|
-
authToken,
|
|
168
|
-
"b2_list_file_versions",
|
|
169
|
-
request
|
|
170
|
-
)
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-get-file-info | b2_get_file_info}.
|
|
175
|
-
* @param apiUrl - The B2 API base URL.
|
|
176
|
-
* @param authToken - The authorization token.
|
|
177
|
-
* @param request - The API request parameters.
|
|
178
|
-
*
|
|
179
|
-
* @returns The file version metadata.
|
|
180
|
-
*/
|
|
181
|
-
async getFileInfo(apiUrl, authToken, request) {
|
|
182
|
-
return normalizeFileVersionSha1(
|
|
183
|
-
await this.postJson(apiUrl, authToken, "b2_get_file_info", request)
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-hide-file | b2_hide_file}.
|
|
188
|
-
* @param apiUrl - The B2 API base URL.
|
|
189
|
-
* @param authToken - The authorization token.
|
|
190
|
-
* @param request - The API request parameters.
|
|
191
|
-
*
|
|
192
|
-
* @returns The hidden file version metadata.
|
|
193
|
-
*/
|
|
194
|
-
async hideFile(apiUrl, authToken, request) {
|
|
195
|
-
return normalizeFileVersionSha1(
|
|
196
|
-
await this.postJson(apiUrl, authToken, "b2_hide_file", request)
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-delete-file-version | b2_delete_file_version}.
|
|
201
|
-
* @param apiUrl - The B2 API base URL.
|
|
202
|
-
* @param authToken - The authorization token.
|
|
203
|
-
* @param request - The API request parameters.
|
|
204
|
-
*
|
|
205
|
-
* @returns The deleted file version identifier.
|
|
206
|
-
*/
|
|
207
|
-
async deleteFileVersion(apiUrl, authToken, request) {
|
|
208
|
-
return this.postJson(
|
|
209
|
-
apiUrl,
|
|
210
|
-
authToken,
|
|
211
|
-
"b2_delete_file_version",
|
|
212
|
-
request
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-copy-file | b2_copy_file}.
|
|
217
|
-
* @param apiUrl - The B2 API base URL.
|
|
218
|
-
* @param authToken - The authorization token.
|
|
219
|
-
* @param request - The API request parameters.
|
|
220
|
-
*
|
|
221
|
-
* @returns The copied file version metadata.
|
|
222
|
-
*/
|
|
223
|
-
async copyFile(apiUrl, authToken, request) {
|
|
224
|
-
return normalizeFileVersionSha1(
|
|
225
|
-
await this.postJson(apiUrl, authToken, "b2_copy_file", request)
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-copy-part | b2_copy_part}.
|
|
230
|
-
* @param apiUrl - The B2 API base URL.
|
|
231
|
-
* @param authToken - The authorization token.
|
|
232
|
-
* @param request - The API request parameters.
|
|
233
|
-
*
|
|
234
|
-
* @returns The copied part metadata.
|
|
235
|
-
*/
|
|
236
|
-
async copyPart(apiUrl, authToken, request) {
|
|
237
|
-
return this.postJson(apiUrl, authToken, "b2_copy_part", request);
|
|
238
|
-
}
|
|
239
|
-
// --- Large Files ---
|
|
240
|
-
/**
|
|
241
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-start-large-file | b2_start_large_file}.
|
|
242
|
-
* @param apiUrl - The B2 API base URL.
|
|
243
|
-
* @param authToken - The authorization token.
|
|
244
|
-
* @param request - The API request parameters.
|
|
245
|
-
*
|
|
246
|
-
* @returns The started large file metadata with file ID.
|
|
247
|
-
*/
|
|
248
|
-
async startLargeFile(apiUrl, authToken, request) {
|
|
249
|
-
return this.postJson(apiUrl, authToken, "b2_start_large_file", request);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-get-upload-part-url | b2_get_upload_part_url}.
|
|
253
|
-
* @param apiUrl - The B2 API base URL.
|
|
254
|
-
* @param authToken - The authorization token.
|
|
255
|
-
* @param request - The API request parameters.
|
|
256
|
-
*
|
|
257
|
-
* @returns The upload part URL and authorization token.
|
|
258
|
-
*/
|
|
259
|
-
async getUploadPartUrl(apiUrl, authToken, request) {
|
|
260
|
-
return this.postJson(
|
|
261
|
-
apiUrl,
|
|
262
|
-
authToken,
|
|
263
|
-
"b2_get_upload_part_url",
|
|
264
|
-
request
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-upload-part | b2_upload_part}.
|
|
269
|
-
*
|
|
270
|
-
* Posts directly to the `uploadUrl` obtained from {@link getUploadPartUrl}
|
|
271
|
-
* rather than the API URL.
|
|
272
|
-
* @param uploadUrl - The upload endpoint URL.
|
|
273
|
-
* @param headers - The request headers including authorization and content metadata.
|
|
274
|
-
* @param body - The file data to upload.
|
|
275
|
-
* @param signal - An optional abort signal for cancellation.
|
|
276
|
-
*
|
|
277
|
-
* @returns The uploaded part metadata.
|
|
278
|
-
*/
|
|
279
|
-
async uploadPart(uploadUrl, headers, body, signal) {
|
|
280
|
-
const reqHeaders = {
|
|
281
|
-
Authorization: headers.authorization,
|
|
282
|
-
"X-Bz-Part-Number": String(headers.partNumber),
|
|
283
|
-
"Content-Length": String(headers.contentLength),
|
|
284
|
-
"X-Bz-Content-Sha1": headers.contentSha1
|
|
285
|
-
};
|
|
286
|
-
applyEncryptionHeaders(reqHeaders, headers.serverSideEncryption);
|
|
287
|
-
const response = await this.transport.send({
|
|
288
|
-
url: uploadUrl,
|
|
289
|
-
method: "POST",
|
|
290
|
-
headers: reqHeaders,
|
|
291
|
-
body,
|
|
292
|
-
...signal !== void 0 ? { signal } : {}
|
|
293
|
-
});
|
|
294
|
-
return response.json();
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-finish-large-file | b2_finish_large_file}.
|
|
298
|
-
* @param apiUrl - The B2 API base URL.
|
|
299
|
-
* @param authToken - The authorization token.
|
|
300
|
-
* @param request - The API request parameters.
|
|
301
|
-
*
|
|
302
|
-
* @returns The completed file version metadata.
|
|
303
|
-
*/
|
|
304
|
-
async finishLargeFile(apiUrl, authToken, request) {
|
|
305
|
-
return normalizeFileVersionSha1(
|
|
306
|
-
await this.postJson(apiUrl, authToken, "b2_finish_large_file", request)
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-cancel-large-file | b2_cancel_large_file}.
|
|
311
|
-
* @param apiUrl - The B2 API base URL.
|
|
312
|
-
* @param authToken - The authorization token.
|
|
313
|
-
* @param request - The API request parameters.
|
|
314
|
-
*
|
|
315
|
-
* @returns The cancelled large file metadata.
|
|
316
|
-
*/
|
|
317
|
-
async cancelLargeFile(apiUrl, authToken, request) {
|
|
318
|
-
return this.postJson(
|
|
319
|
-
apiUrl,
|
|
320
|
-
authToken,
|
|
321
|
-
"b2_cancel_large_file",
|
|
322
|
-
request
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-list-unfinished-large-files | b2_list_unfinished_large_files}.
|
|
327
|
-
* @param apiUrl - The B2 API base URL.
|
|
328
|
-
* @param authToken - The authorization token.
|
|
329
|
-
* @param request - The API request parameters.
|
|
330
|
-
*
|
|
331
|
-
* @returns The list of unfinished large files and optional continuation token.
|
|
332
|
-
*/
|
|
333
|
-
async listUnfinishedLargeFiles(apiUrl, authToken, request) {
|
|
334
|
-
return this.postJson(
|
|
335
|
-
apiUrl,
|
|
336
|
-
authToken,
|
|
337
|
-
"b2_list_unfinished_large_files",
|
|
338
|
-
request
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-list-parts | b2_list_parts}.
|
|
343
|
-
* @param apiUrl - The B2 API base URL.
|
|
344
|
-
* @param authToken - The authorization token.
|
|
345
|
-
* @param request - The API request parameters.
|
|
346
|
-
*
|
|
347
|
-
* @returns The list of uploaded parts and optional continuation token.
|
|
348
|
-
*/
|
|
349
|
-
async listParts(apiUrl, authToken, request) {
|
|
350
|
-
return this.postJson(apiUrl, authToken, "b2_list_parts", request);
|
|
351
|
-
}
|
|
352
|
-
// --- Downloads ---
|
|
353
|
-
/**
|
|
354
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-download-file-by-id | b2_download_file_by_id}.
|
|
355
|
-
* @param downloadUrl - The B2 download base URL.
|
|
356
|
-
* @param authToken - The authorization token.
|
|
357
|
-
* @param fileId - The unique identifier of the file to download.
|
|
358
|
-
* @param options - Optional download parameters for range requests and cancellation.
|
|
359
|
-
*
|
|
360
|
-
* @returns The response headers, streaming body, and HTTP status code.
|
|
361
|
-
*/
|
|
362
|
-
async downloadFileById(downloadUrl, authToken, fileId, options) {
|
|
363
|
-
const headers = buildDownloadRequestHeaders(authToken, options);
|
|
364
|
-
const url = appendDownloadOverrides(
|
|
365
|
-
`${downloadUrl}/b2api/v3/b2_download_file_by_id?fileId=${encodeURIComponent(fileId)}`,
|
|
366
|
-
options
|
|
367
|
-
);
|
|
368
|
-
const response = await this.transport.send({
|
|
369
|
-
url,
|
|
370
|
-
method: options?.method ?? "GET",
|
|
371
|
-
headers,
|
|
372
|
-
...options?.signal !== void 0 ? { signal: options.signal } : {}
|
|
373
|
-
});
|
|
374
|
-
return { headers: response.headers, body: response.body, status: response.status };
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-download-file-by-name | b2_download_file_by_name}.
|
|
378
|
-
* @param downloadUrl - The B2 download base URL.
|
|
379
|
-
* @param authToken - The authorization token.
|
|
380
|
-
* @param bucketName - The name of the bucket containing the file.
|
|
381
|
-
* @param fileName - The name of the file to download.
|
|
382
|
-
* @param options - Optional download parameters for range requests and cancellation.
|
|
383
|
-
*
|
|
384
|
-
* @returns The response headers, streaming body, and HTTP status code.
|
|
385
|
-
*/
|
|
386
|
-
async downloadFileByName(downloadUrl, authToken, bucketName, fileName, options) {
|
|
387
|
-
const headers = buildDownloadRequestHeaders(authToken, options);
|
|
388
|
-
const url = appendDownloadOverrides(
|
|
389
|
-
`${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeFileName(fileName)}`,
|
|
390
|
-
options
|
|
391
|
-
);
|
|
392
|
-
const response = await this.transport.send({
|
|
393
|
-
url,
|
|
394
|
-
method: options?.method ?? "GET",
|
|
395
|
-
headers,
|
|
396
|
-
...options?.signal !== void 0 ? { signal: options.signal } : {}
|
|
397
|
-
});
|
|
398
|
-
return { headers: response.headers, body: response.body, status: response.status };
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-get-download-authorization | b2_get_download_authorization}.
|
|
402
|
-
* @param apiUrl - The B2 API base URL.
|
|
403
|
-
* @param authToken - The current session authorization token.
|
|
404
|
-
* @param request - The API request parameters.
|
|
405
|
-
*
|
|
406
|
-
* @returns The download authorization token for the specified file prefix.
|
|
407
|
-
*/
|
|
408
|
-
async getDownloadAuthorization(apiUrl, authToken, request) {
|
|
409
|
-
return this.postJson(
|
|
410
|
-
apiUrl,
|
|
411
|
-
authToken,
|
|
412
|
-
"b2_get_download_authorization",
|
|
413
|
-
request
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
// --- Keys ---
|
|
417
|
-
/**
|
|
418
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-create-key | b2_create_key}.
|
|
419
|
-
* @param apiUrl - The B2 API base URL.
|
|
420
|
-
* @param authToken - The authorization token.
|
|
421
|
-
* @param request - The API request parameters.
|
|
422
|
-
*
|
|
423
|
-
* @returns The newly created application key with secret.
|
|
424
|
-
*/
|
|
425
|
-
async createKey(apiUrl, authToken, request) {
|
|
426
|
-
return this.postJson(apiUrl, authToken, "b2_create_key", request);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-list-keys | b2_list_keys}.
|
|
430
|
-
* @param apiUrl - The B2 API base URL.
|
|
431
|
-
* @param authToken - The authorization token.
|
|
432
|
-
* @param request - The API request parameters.
|
|
433
|
-
*
|
|
434
|
-
* @returns The list of application keys and optional continuation token.
|
|
435
|
-
*/
|
|
436
|
-
async listKeys(apiUrl, authToken, request) {
|
|
437
|
-
return this.postJson(apiUrl, authToken, "b2_list_keys", request);
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-delete-key | b2_delete_key}.
|
|
441
|
-
* @param apiUrl - The B2 API base URL.
|
|
442
|
-
* @param authToken - The authorization token.
|
|
443
|
-
* @param request - The API request parameters.
|
|
444
|
-
*
|
|
445
|
-
* @returns The deleted application key metadata.
|
|
446
|
-
*/
|
|
447
|
-
async deleteKey(apiUrl, authToken, request) {
|
|
448
|
-
return this.postJson(apiUrl, authToken, "b2_delete_key", request);
|
|
449
|
-
}
|
|
450
|
-
// --- Retention / Legal Hold ---
|
|
451
|
-
/**
|
|
452
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-update-file-retention | b2_update_file_retention}.
|
|
453
|
-
* @param apiUrl - The B2 API base URL.
|
|
454
|
-
* @param authToken - The authorization token.
|
|
455
|
-
* @param request - The API request parameters.
|
|
456
|
-
*
|
|
457
|
-
* @returns The updated file retention settings.
|
|
458
|
-
*/
|
|
459
|
-
async updateFileRetention(apiUrl, authToken, request) {
|
|
460
|
-
return this.postJson(
|
|
461
|
-
apiUrl,
|
|
462
|
-
authToken,
|
|
463
|
-
"b2_update_file_retention",
|
|
464
|
-
request
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-update-file-legal-hold | b2_update_file_legal_hold}.
|
|
469
|
-
* @param apiUrl - The B2 API base URL.
|
|
470
|
-
* @param authToken - The authorization token.
|
|
471
|
-
* @param request - The API request parameters.
|
|
472
|
-
*
|
|
473
|
-
* @returns The updated file legal hold status.
|
|
474
|
-
*/
|
|
475
|
-
async updateFileLegalHold(apiUrl, authToken, request) {
|
|
476
|
-
return this.postJson(
|
|
477
|
-
apiUrl,
|
|
478
|
-
authToken,
|
|
479
|
-
"b2_update_file_legal_hold",
|
|
480
|
-
request
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
// --- Notifications ---
|
|
484
|
-
/**
|
|
485
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-get-bucket-notification-rules | b2_get_bucket_notification_rules}.
|
|
486
|
-
* @param apiUrl - The B2 API base URL.
|
|
487
|
-
* @param authToken - The authorization token.
|
|
488
|
-
* @param request - The API request parameters.
|
|
489
|
-
*
|
|
490
|
-
* @returns The configured event notification rules for the specified bucket.
|
|
491
|
-
*/
|
|
492
|
-
async getBucketNotificationRules(apiUrl, authToken, request) {
|
|
493
|
-
return this.postJson(
|
|
494
|
-
apiUrl,
|
|
495
|
-
authToken,
|
|
496
|
-
"b2_get_bucket_notification_rules",
|
|
497
|
-
request
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Calls {@link https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules | b2_set_bucket_notification_rules}.
|
|
502
|
-
* @param apiUrl - The B2 API base URL.
|
|
503
|
-
* @param authToken - The authorization token.
|
|
504
|
-
* @param request - The API request parameters.
|
|
505
|
-
*
|
|
506
|
-
* @returns The updated bucket notification rules.
|
|
507
|
-
*/
|
|
508
|
-
async setBucketNotificationRules(apiUrl, authToken, request) {
|
|
509
|
-
return this.postJson(
|
|
510
|
-
apiUrl,
|
|
511
|
-
authToken,
|
|
512
|
-
"b2_set_bucket_notification_rules",
|
|
513
|
-
request
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
// --- Internal ---
|
|
517
|
-
/**
|
|
518
|
-
* Sends a JSON POST request to the specified B2 API endpoint.
|
|
519
|
-
* @param apiUrl - The B2 API base URL.
|
|
520
|
-
* @param authToken - The authorization token.
|
|
521
|
-
* @param endpoint - The B2 API endpoint name.
|
|
522
|
-
* @param body - The JSON request body.
|
|
523
|
-
*
|
|
524
|
-
* @returns The parsed JSON response.
|
|
525
|
-
*/
|
|
526
|
-
async postJson(apiUrl, authToken, endpoint, body) {
|
|
527
|
-
const response = await this.transport.send({
|
|
528
|
-
url: `${apiUrl}/b2api/v3/${endpoint}`,
|
|
529
|
-
method: "POST",
|
|
530
|
-
headers: {
|
|
531
|
-
Authorization: authToken,
|
|
532
|
-
"Content-Type": "application/json"
|
|
533
|
-
},
|
|
534
|
-
body: JSON.stringify(body)
|
|
535
|
-
});
|
|
536
|
-
return response.json();
|
|
537
|
-
}
|
|
1
|
+
import { FinishLargeFileResponseBodyError, UploadResponseBodyError } from "../errors/index.js";
|
|
2
|
+
import { buildFileInfoHeaders, decodeFileName, encodeFileName, parseFileInfoHeaders } from "./encoding.js";
|
|
3
|
+
import { normalizeFileVersionListSha1, normalizeFileVersionSha1 } from "../util/normalize.js";
|
|
4
|
+
import { EncryptionAlgorithm, EncryptionMode } from "../types/encryption.js";
|
|
5
|
+
import { assertSecureRealmUrl } from "../auth/realms.js";
|
|
6
|
+
//#region src/raw/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Low-level 1:1 bindings for every B2 native API endpoint.
|
|
9
|
+
*
|
|
10
|
+
* Each method on {@link RawClient} maps directly to a single `b2_*` HTTP call
|
|
11
|
+
* with fully typed request and response objects. No retry logic, no URL pooling,
|
|
12
|
+
* no automatic reauthorization. Use this when you need precise control over
|
|
13
|
+
* individual API calls; for most use cases prefer the high-level `B2Client`.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
function normalizeRawRequestOptions(optionsOrSignal, retry) {
|
|
18
|
+
if (optionsOrSignal === void 0) return retry === void 0 ? void 0 : { retry };
|
|
19
|
+
if (isAbortSignal(optionsOrSignal)) return {
|
|
20
|
+
signal: optionsOrSignal,
|
|
21
|
+
...retry !== void 0 ? { retry } : {}
|
|
22
|
+
};
|
|
23
|
+
return retry === void 0 ? optionsOrSignal : {
|
|
24
|
+
...optionsOrSignal,
|
|
25
|
+
retry
|
|
26
|
+
};
|
|
538
27
|
}
|
|
28
|
+
function isAbortSignal(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && "aborted" in value && typeof value.addEventListener === "function";
|
|
30
|
+
}
|
|
31
|
+
function normalizeCreateKeyRequest(request) {
|
|
32
|
+
const { bucketId, ...withoutDeprecatedBucketId } = request;
|
|
33
|
+
if (bucketId !== void 0 && withoutDeprecatedBucketId.bucketIds !== void 0) throw new TypeError("createKey accepts either bucketIds or deprecated bucketId, not both");
|
|
34
|
+
if (bucketId === void 0) return withoutDeprecatedBucketId;
|
|
35
|
+
return {
|
|
36
|
+
...withoutDeprecatedBucketId,
|
|
37
|
+
bucketIds: [bucketId]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function singleBucketId(bucketIds) {
|
|
41
|
+
return bucketIds?.length === 1 ? bucketIds[0] ?? null : null;
|
|
42
|
+
}
|
|
43
|
+
function normalizeKeyResponse(key) {
|
|
44
|
+
return {
|
|
45
|
+
...key,
|
|
46
|
+
bucketId: singleBucketId(key.bucketIds)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function normalizeAllowedBuckets(storageApi) {
|
|
50
|
+
const allowed = storageApi.allowed;
|
|
51
|
+
if (allowed?.buckets !== void 0) return allowed.buckets === null ? null : allowed.buckets.map((bucket) => ({ ...bucket }));
|
|
52
|
+
const bucketId = allowed?.bucketId ?? storageApi.bucketId ?? null;
|
|
53
|
+
if (bucketId === null) return null;
|
|
54
|
+
return [{
|
|
55
|
+
id: bucketId,
|
|
56
|
+
name: allowed?.bucketName ?? storageApi.bucketName ?? null
|
|
57
|
+
}];
|
|
58
|
+
}
|
|
59
|
+
function normalizeAuthorizeAccountResponse(response) {
|
|
60
|
+
const storageApi = response.apiInfo.storageApi;
|
|
61
|
+
const allowed = storageApi.allowed;
|
|
62
|
+
const buckets = normalizeAllowedBuckets(storageApi);
|
|
63
|
+
const singleBucket = buckets?.length === 1 ? buckets[0] : void 0;
|
|
64
|
+
const bucketId = singleBucket?.id ?? null;
|
|
65
|
+
const bucketName = singleBucket?.name ?? null;
|
|
66
|
+
const namePrefix = allowed?.namePrefix ?? storageApi.namePrefix ?? null;
|
|
67
|
+
const capabilities = allowed?.capabilities ?? storageApi.capabilities ?? [];
|
|
68
|
+
const { allowed: _wireAllowed, capabilities: _legacyCapabilities, ...storageApiBase } = storageApi;
|
|
69
|
+
return {
|
|
70
|
+
...response,
|
|
71
|
+
apiInfo: {
|
|
72
|
+
...response.apiInfo,
|
|
73
|
+
storageApi: {
|
|
74
|
+
...storageApiBase,
|
|
75
|
+
bucketId,
|
|
76
|
+
bucketName,
|
|
77
|
+
downloadUrl: storageApi.downloadUrl,
|
|
78
|
+
infoType: "storageApi",
|
|
79
|
+
namePrefix,
|
|
80
|
+
allowed: {
|
|
81
|
+
...allowed ?? {},
|
|
82
|
+
capabilities,
|
|
83
|
+
buckets,
|
|
84
|
+
bucketId,
|
|
85
|
+
bucketName,
|
|
86
|
+
namePrefix
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function uploadResponseBodyError(err, signal) {
|
|
93
|
+
if (signal?.aborted === true) throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
94
|
+
return new UploadResponseBodyError(err instanceof Error ? err.message : "Upload response body could not be read", { cause: err });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Low-level client providing 1:1 bindings to all B2 native API endpoints.
|
|
98
|
+
*
|
|
99
|
+
* Each method maps directly to a single B2 API call. Most methods accept
|
|
100
|
+
* `(apiUrl, authToken, request)` and return the JSON response. Upload and
|
|
101
|
+
* download methods accept endpoint-specific parameters instead.
|
|
102
|
+
*/
|
|
103
|
+
var RawClient = class {
|
|
104
|
+
/** @internal */
|
|
105
|
+
transport;
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new RawClient with the given transport.
|
|
108
|
+
* @param options - The constructor configuration.
|
|
109
|
+
*/
|
|
110
|
+
constructor(options) {
|
|
111
|
+
this.transport = options.transport;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-authorize-account | b2_authorize_account}.
|
|
115
|
+
* @param applicationKeyId - The application key ID for authentication.
|
|
116
|
+
* @param applicationKey - The application key secret.
|
|
117
|
+
* @param realmUrl - The B2 realm URL to authenticate against.
|
|
118
|
+
*
|
|
119
|
+
* @returns The authorization response with API URLs and credentials.
|
|
120
|
+
*/
|
|
121
|
+
async authorizeAccount(applicationKeyId, applicationKey, realmUrl = "https://api.backblazeb2.com") {
|
|
122
|
+
assertSecureRealmUrl(realmUrl);
|
|
123
|
+
return normalizeAuthorizeAccountResponse(await (await this.transport.send({
|
|
124
|
+
url: `${realmUrl}/b2api/v4/b2_authorize_account`,
|
|
125
|
+
method: "GET",
|
|
126
|
+
headers: { Authorization: `Basic ${btoa(`${applicationKeyId}:${applicationKey}`)}` }
|
|
127
|
+
})).json());
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-create-bucket | b2_create_bucket}.
|
|
131
|
+
* @param apiUrl - The B2 API base URL.
|
|
132
|
+
* @param authToken - The authorization token.
|
|
133
|
+
* @param request - The API request parameters.
|
|
134
|
+
*
|
|
135
|
+
* @returns The created bucket metadata.
|
|
136
|
+
*/
|
|
137
|
+
async createBucket(apiUrl, authToken, request) {
|
|
138
|
+
return this.postJson(apiUrl, authToken, "b2_create_bucket", request);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-delete-bucket | b2_delete_bucket}.
|
|
142
|
+
* @param apiUrl - The B2 API base URL.
|
|
143
|
+
* @param authToken - The authorization token.
|
|
144
|
+
* @param request - The API request parameters.
|
|
145
|
+
*
|
|
146
|
+
* @returns The deleted bucket metadata.
|
|
147
|
+
*/
|
|
148
|
+
async deleteBucket(apiUrl, authToken, request) {
|
|
149
|
+
return this.postJson(apiUrl, authToken, "b2_delete_bucket", request);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-list-buckets | b2_list_buckets}.
|
|
153
|
+
* @param apiUrl - The B2 API base URL.
|
|
154
|
+
* @param authToken - The authorization token.
|
|
155
|
+
* @param request - The API request parameters.
|
|
156
|
+
*
|
|
157
|
+
* @returns The list of matching buckets.
|
|
158
|
+
*/
|
|
159
|
+
async listBuckets(apiUrl, authToken, request) {
|
|
160
|
+
return this.postJson(apiUrl, authToken, "b2_list_buckets", request);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-update-bucket | b2_update_bucket}.
|
|
164
|
+
* @param apiUrl - The B2 API base URL.
|
|
165
|
+
* @param authToken - The authorization token.
|
|
166
|
+
* @param request - The API request parameters.
|
|
167
|
+
*
|
|
168
|
+
* @returns The updated bucket metadata.
|
|
169
|
+
*/
|
|
170
|
+
async updateBucket(apiUrl, authToken, request) {
|
|
171
|
+
return this.postJson(apiUrl, authToken, "b2_update_bucket", request);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Implementation for both upload URL request-control signatures.
|
|
175
|
+
* @param apiUrl - The B2 API base URL.
|
|
176
|
+
* @param authToken - The authorization token.
|
|
177
|
+
* @param request - The API request parameters.
|
|
178
|
+
* @param optionsOrSignal - Options bag or legacy abort signal.
|
|
179
|
+
* @param retry - Optional legacy per-request retry override.
|
|
180
|
+
*
|
|
181
|
+
* @returns The upload URL and authorization token.
|
|
182
|
+
*/
|
|
183
|
+
async getUploadUrl(apiUrl, authToken, request, optionsOrSignal, retry) {
|
|
184
|
+
return this.postJson(apiUrl, authToken, "b2_get_upload_url", request, normalizeRawRequestOptions(optionsOrSignal, retry));
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Implementation for both upload-file request-control signatures.
|
|
188
|
+
* @param uploadUrl - The upload endpoint URL.
|
|
189
|
+
* @param headers - The request headers including authorization and content metadata.
|
|
190
|
+
* @param body - The file data to upload.
|
|
191
|
+
* @param optionsOrSignal - Options bag or legacy abort signal.
|
|
192
|
+
* @param retry - Optional legacy per-request retry override.
|
|
193
|
+
*
|
|
194
|
+
* @returns The uploaded file version metadata.
|
|
195
|
+
*/
|
|
196
|
+
async uploadFile(uploadUrl, headers, body, optionsOrSignal, retry) {
|
|
197
|
+
const options = normalizeRawRequestOptions(optionsOrSignal, retry);
|
|
198
|
+
const reqHeaders = {
|
|
199
|
+
Authorization: headers.authorization,
|
|
200
|
+
"X-Bz-File-Name": encodeFileName(headers.fileName),
|
|
201
|
+
"Content-Type": headers.contentType,
|
|
202
|
+
"Content-Length": String(headers.contentLength),
|
|
203
|
+
"X-Bz-Content-Sha1": headers.contentSha1,
|
|
204
|
+
...buildFileInfoHeaders(headers.fileInfo)
|
|
205
|
+
};
|
|
206
|
+
if (headers.lastModifiedMillis !== void 0) reqHeaders["X-Bz-Info-src_last_modified_millis"] = String(headers.lastModifiedMillis);
|
|
207
|
+
if (headers.contentDisposition) reqHeaders["X-Bz-Info-b2-content-disposition"] = headers.contentDisposition;
|
|
208
|
+
if (headers.contentLanguage) reqHeaders["X-Bz-Info-b2-content-language"] = headers.contentLanguage;
|
|
209
|
+
if (headers.expires) reqHeaders["X-Bz-Info-b2-expires"] = headers.expires;
|
|
210
|
+
if (headers.cacheControl) reqHeaders["X-Bz-Info-b2-cache-control"] = headers.cacheControl;
|
|
211
|
+
if (headers.contentEncoding) reqHeaders["X-Bz-Info-b2-content-encoding"] = headers.contentEncoding;
|
|
212
|
+
applyEncryptionHeaders(reqHeaders, headers.serverSideEncryption);
|
|
213
|
+
applyRetentionHeaders(reqHeaders, headers.fileRetention);
|
|
214
|
+
applyLegalHoldHeader(reqHeaders, headers.legalHold);
|
|
215
|
+
const response = await this.transport.send({
|
|
216
|
+
url: uploadUrl,
|
|
217
|
+
method: "POST",
|
|
218
|
+
headers: reqHeaders,
|
|
219
|
+
body,
|
|
220
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {},
|
|
221
|
+
...options?.retry !== void 0 ? { retry: options.retry } : {}
|
|
222
|
+
});
|
|
223
|
+
try {
|
|
224
|
+
return normalizeFileVersionSha1(await response.json());
|
|
225
|
+
} catch (err) {
|
|
226
|
+
throw uploadResponseBodyError(err, options?.signal);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-list-file-names | b2_list_file_names}.
|
|
231
|
+
* @param apiUrl - The B2 API base URL.
|
|
232
|
+
* @param authToken - The authorization token.
|
|
233
|
+
* @param request - The API request parameters.
|
|
234
|
+
* @param options - Optional request controls such as an abort signal.
|
|
235
|
+
*
|
|
236
|
+
* @returns The list of file names and optional continuation token.
|
|
237
|
+
*/
|
|
238
|
+
async listFileNames(apiUrl, authToken, request, options) {
|
|
239
|
+
return normalizeFileVersionListSha1(await this.postJson(apiUrl, authToken, "b2_list_file_names", request, options));
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-list-file-versions | b2_list_file_versions}.
|
|
243
|
+
* @param apiUrl - The B2 API base URL.
|
|
244
|
+
* @param authToken - The authorization token.
|
|
245
|
+
* @param request - The API request parameters.
|
|
246
|
+
* @param options - Optional request controls such as an abort signal.
|
|
247
|
+
*
|
|
248
|
+
* @returns The list of file versions and optional continuation token.
|
|
249
|
+
*/
|
|
250
|
+
async listFileVersions(apiUrl, authToken, request, options) {
|
|
251
|
+
return normalizeFileVersionListSha1(await this.postJson(apiUrl, authToken, "b2_list_file_versions", request, options));
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-get-file-info | b2_get_file_info}.
|
|
255
|
+
* @param apiUrl - The B2 API base URL.
|
|
256
|
+
* @param authToken - The authorization token.
|
|
257
|
+
* @param request - The API request parameters.
|
|
258
|
+
*
|
|
259
|
+
* @returns The file version metadata.
|
|
260
|
+
*/
|
|
261
|
+
async getFileInfo(apiUrl, authToken, request) {
|
|
262
|
+
return normalizeFileVersionSha1(await this.postJson(apiUrl, authToken, "b2_get_file_info", request));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-hide-file | b2_hide_file}.
|
|
266
|
+
* @param apiUrl - The B2 API base URL.
|
|
267
|
+
* @param authToken - The authorization token.
|
|
268
|
+
* @param request - The API request parameters.
|
|
269
|
+
* @param options - Optional request controls such as an abort signal.
|
|
270
|
+
*
|
|
271
|
+
* @returns The hidden file version metadata.
|
|
272
|
+
*/
|
|
273
|
+
async hideFile(apiUrl, authToken, request, options) {
|
|
274
|
+
return normalizeFileVersionSha1(await this.postJson(apiUrl, authToken, "b2_hide_file", request, options));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-delete-file-version | b2_delete_file_version}.
|
|
278
|
+
* @param apiUrl - The B2 API base URL.
|
|
279
|
+
* @param authToken - The authorization token.
|
|
280
|
+
* @param request - The API request parameters.
|
|
281
|
+
* @param options - Optional request controls such as an abort signal.
|
|
282
|
+
*
|
|
283
|
+
* @returns The deleted file version identifier.
|
|
284
|
+
*/
|
|
285
|
+
async deleteFileVersion(apiUrl, authToken, request, options) {
|
|
286
|
+
return this.postJson(apiUrl, authToken, "b2_delete_file_version", request, options);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-copy-file | b2_copy_file}.
|
|
290
|
+
* @param apiUrl - The B2 API base URL.
|
|
291
|
+
* @param authToken - The authorization token.
|
|
292
|
+
* @param request - The API request parameters.
|
|
293
|
+
* @param options - Optional request controls such as an abort signal.
|
|
294
|
+
*
|
|
295
|
+
* @returns The copied file version metadata.
|
|
296
|
+
*/
|
|
297
|
+
async copyFile(apiUrl, authToken, request, options) {
|
|
298
|
+
return normalizeFileVersionSha1(await this.postJson(apiUrl, authToken, "b2_copy_file", request, options));
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-copy-part | b2_copy_part}.
|
|
302
|
+
* @param apiUrl - The B2 API base URL.
|
|
303
|
+
* @param authToken - The authorization token.
|
|
304
|
+
* @param request - The API request parameters.
|
|
305
|
+
* @param options - Optional abort and retry controls.
|
|
306
|
+
*
|
|
307
|
+
* @returns The copied part metadata.
|
|
308
|
+
*/
|
|
309
|
+
async copyPart(apiUrl, authToken, request, options) {
|
|
310
|
+
return this.postJson(apiUrl, authToken, "b2_copy_part", request, options);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-start-large-file | b2_start_large_file}.
|
|
314
|
+
* @param apiUrl - The B2 API base URL.
|
|
315
|
+
* @param authToken - The authorization token.
|
|
316
|
+
* @param request - The API request parameters.
|
|
317
|
+
* @param options - Optional abort and retry controls.
|
|
318
|
+
*
|
|
319
|
+
* @returns The started large file metadata with file ID.
|
|
320
|
+
*/
|
|
321
|
+
async startLargeFile(apiUrl, authToken, request, options) {
|
|
322
|
+
return this.postJson(apiUrl, authToken, "b2_start_large_file", request, options);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Implementation for both upload part URL request-control signatures.
|
|
326
|
+
* @param apiUrl - The B2 API base URL.
|
|
327
|
+
* @param authToken - The authorization token.
|
|
328
|
+
* @param request - The API request parameters.
|
|
329
|
+
* @param optionsOrSignal - Options bag or legacy abort signal.
|
|
330
|
+
* @param retry - Optional legacy per-request retry override.
|
|
331
|
+
*
|
|
332
|
+
* @returns The upload part URL and authorization token.
|
|
333
|
+
*/
|
|
334
|
+
async getUploadPartUrl(apiUrl, authToken, request, optionsOrSignal, retry) {
|
|
335
|
+
return this.postJson(apiUrl, authToken, "b2_get_upload_part_url", request, normalizeRawRequestOptions(optionsOrSignal, retry));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Implementation for both upload-part request-control signatures.
|
|
339
|
+
* @param uploadUrl - The upload endpoint URL.
|
|
340
|
+
* @param headers - The request headers including authorization and content metadata.
|
|
341
|
+
* @param body - The file data to upload.
|
|
342
|
+
* @param optionsOrSignal - Options bag or legacy abort signal.
|
|
343
|
+
* @param retry - Optional legacy per-request retry override.
|
|
344
|
+
*
|
|
345
|
+
* @returns The uploaded part metadata.
|
|
346
|
+
*/
|
|
347
|
+
async uploadPart(uploadUrl, headers, body, optionsOrSignal, retry) {
|
|
348
|
+
const options = normalizeRawRequestOptions(optionsOrSignal, retry);
|
|
349
|
+
const reqHeaders = {
|
|
350
|
+
Authorization: headers.authorization,
|
|
351
|
+
"X-Bz-Part-Number": String(headers.partNumber),
|
|
352
|
+
"Content-Length": String(headers.contentLength),
|
|
353
|
+
"X-Bz-Content-Sha1": headers.contentSha1
|
|
354
|
+
};
|
|
355
|
+
applyEncryptionHeaders(reqHeaders, headers.serverSideEncryption);
|
|
356
|
+
const response = await this.transport.send({
|
|
357
|
+
url: uploadUrl,
|
|
358
|
+
method: "POST",
|
|
359
|
+
headers: reqHeaders,
|
|
360
|
+
body,
|
|
361
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {},
|
|
362
|
+
...options?.retry !== void 0 ? { retry: options.retry } : {}
|
|
363
|
+
});
|
|
364
|
+
try {
|
|
365
|
+
return await response.json();
|
|
366
|
+
} catch (err) {
|
|
367
|
+
throw uploadResponseBodyError(err, options?.signal);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-finish-large-file | b2_finish_large_file}.
|
|
372
|
+
* @param apiUrl - The B2 API base URL.
|
|
373
|
+
* @param authToken - The authorization token.
|
|
374
|
+
* @param request - The API request parameters.
|
|
375
|
+
* @param options - Optional abort and retry controls.
|
|
376
|
+
*
|
|
377
|
+
* @returns The completed file version metadata.
|
|
378
|
+
*/
|
|
379
|
+
async finishLargeFile(apiUrl, authToken, request, options) {
|
|
380
|
+
const response = await this.transport.send({
|
|
381
|
+
url: `${apiUrl}/b2api/v3/b2_finish_large_file`,
|
|
382
|
+
method: "POST",
|
|
383
|
+
headers: {
|
|
384
|
+
Authorization: authToken,
|
|
385
|
+
"Content-Type": "application/json"
|
|
386
|
+
},
|
|
387
|
+
body: JSON.stringify(request),
|
|
388
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {},
|
|
389
|
+
...options?.retry !== void 0 ? { retry: options.retry } : {}
|
|
390
|
+
});
|
|
391
|
+
let fileVersion;
|
|
392
|
+
try {
|
|
393
|
+
fileVersion = await response.json();
|
|
394
|
+
} catch (err) {
|
|
395
|
+
throw new FinishLargeFileResponseBodyError(err instanceof Error ? err.message : "Finish large file response body could not be read", {
|
|
396
|
+
cause: err,
|
|
397
|
+
fileId: request.fileId
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
return normalizeFileVersionSha1(fileVersion);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-cancel-large-file | b2_cancel_large_file}.
|
|
404
|
+
* @param apiUrl - The B2 API base URL.
|
|
405
|
+
* @param authToken - The authorization token.
|
|
406
|
+
* @param request - The API request parameters.
|
|
407
|
+
* @param options - Optional request controls such as cancellation and retry overrides.
|
|
408
|
+
*
|
|
409
|
+
* @returns The cancelled large file metadata.
|
|
410
|
+
*/
|
|
411
|
+
async cancelLargeFile(apiUrl, authToken, request, options) {
|
|
412
|
+
return this.postJson(apiUrl, authToken, "b2_cancel_large_file", request, options);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-list-unfinished-large-files | b2_list_unfinished_large_files}.
|
|
416
|
+
* @param apiUrl - The B2 API base URL.
|
|
417
|
+
* @param authToken - The authorization token.
|
|
418
|
+
* @param request - The API request parameters.
|
|
419
|
+
* @param options - Optional request controls such as cancellation and retry.
|
|
420
|
+
*
|
|
421
|
+
* @returns The list of unfinished large files and optional continuation token.
|
|
422
|
+
*/
|
|
423
|
+
async listUnfinishedLargeFiles(apiUrl, authToken, request, options) {
|
|
424
|
+
return this.postJson(apiUrl, authToken, "b2_list_unfinished_large_files", request, options);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-list-parts | b2_list_parts}.
|
|
428
|
+
* @param apiUrl - The B2 API base URL.
|
|
429
|
+
* @param authToken - The authorization token.
|
|
430
|
+
* @param request - The API request parameters.
|
|
431
|
+
* @param options - Optional request controls such as cancellation and retry.
|
|
432
|
+
*
|
|
433
|
+
* @returns The list of uploaded parts and optional continuation token.
|
|
434
|
+
*/
|
|
435
|
+
async listParts(apiUrl, authToken, request, options) {
|
|
436
|
+
return this.postJson(apiUrl, authToken, "b2_list_parts", request, options);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-download-file-by-id | b2_download_file_by_id}.
|
|
440
|
+
* @param downloadUrl - The B2 download base URL.
|
|
441
|
+
* @param authToken - The authorization token.
|
|
442
|
+
* @param fileId - The unique identifier of the file to download.
|
|
443
|
+
* @param options - Optional download parameters for range requests and cancellation.
|
|
444
|
+
*
|
|
445
|
+
* @returns The response headers, streaming body, and HTTP status code.
|
|
446
|
+
*/
|
|
447
|
+
async downloadFileById(downloadUrl, authToken, fileId, options) {
|
|
448
|
+
const headers = buildDownloadRequestHeaders(authToken, options);
|
|
449
|
+
const url = appendDownloadOverrides(`${downloadUrl}/b2api/v3/b2_download_file_by_id?fileId=${encodeURIComponent(fileId)}`, options);
|
|
450
|
+
const response = await this.transport.send({
|
|
451
|
+
url,
|
|
452
|
+
method: options?.method ?? "GET",
|
|
453
|
+
headers,
|
|
454
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {}
|
|
455
|
+
});
|
|
456
|
+
return {
|
|
457
|
+
headers: response.headers,
|
|
458
|
+
body: response.body,
|
|
459
|
+
status: response.status
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-download-file-by-name | b2_download_file_by_name}.
|
|
464
|
+
* @param downloadUrl - The B2 download base URL.
|
|
465
|
+
* @param authToken - The authorization token.
|
|
466
|
+
* @param bucketName - The name of the bucket containing the file.
|
|
467
|
+
* @param fileName - The name of the file to download.
|
|
468
|
+
* @param options - Optional download parameters for range requests and cancellation.
|
|
469
|
+
*
|
|
470
|
+
* @returns The response headers, streaming body, and HTTP status code.
|
|
471
|
+
*/
|
|
472
|
+
async downloadFileByName(downloadUrl, authToken, bucketName, fileName, options) {
|
|
473
|
+
const headers = buildDownloadRequestHeaders(authToken, options);
|
|
474
|
+
const url = appendDownloadOverrides(`${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeFileName(fileName)}`, options);
|
|
475
|
+
const response = await this.transport.send({
|
|
476
|
+
url,
|
|
477
|
+
method: options?.method ?? "GET",
|
|
478
|
+
headers,
|
|
479
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {}
|
|
480
|
+
});
|
|
481
|
+
return {
|
|
482
|
+
headers: response.headers,
|
|
483
|
+
body: response.body,
|
|
484
|
+
status: response.status
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-get-download-authorization | b2_get_download_authorization}.
|
|
489
|
+
* @param apiUrl - The B2 API base URL.
|
|
490
|
+
* @param authToken - The current session authorization token.
|
|
491
|
+
* @param request - The API request parameters.
|
|
492
|
+
*
|
|
493
|
+
* @returns The download authorization token for the specified file prefix.
|
|
494
|
+
*/
|
|
495
|
+
async getDownloadAuthorization(apiUrl, authToken, request) {
|
|
496
|
+
return this.postJson(apiUrl, authToken, "b2_get_download_authorization", request);
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-create-key | b2_create_key}.
|
|
500
|
+
* @param apiUrl - The B2 API base URL.
|
|
501
|
+
* @param authToken - The authorization token.
|
|
502
|
+
* @param request - The API request parameters.
|
|
503
|
+
*
|
|
504
|
+
* @returns The newly created application key with secret.
|
|
505
|
+
*/
|
|
506
|
+
async createKey(apiUrl, authToken, request) {
|
|
507
|
+
return normalizeKeyResponse(await this.postJson(apiUrl, authToken, "b2_create_key", normalizeCreateKeyRequest(request), void 0, "v4"));
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-list-keys | b2_list_keys}.
|
|
511
|
+
* @param apiUrl - The B2 API base URL.
|
|
512
|
+
* @param authToken - The authorization token.
|
|
513
|
+
* @param request - The API request parameters.
|
|
514
|
+
*
|
|
515
|
+
* @returns The list of application keys and optional continuation token.
|
|
516
|
+
*/
|
|
517
|
+
async listKeys(apiUrl, authToken, request) {
|
|
518
|
+
const response = await this.postJson(apiUrl, authToken, "b2_list_keys", request, void 0, "v4");
|
|
519
|
+
return {
|
|
520
|
+
...response,
|
|
521
|
+
keys: response.keys.map((key) => normalizeKeyResponse(key))
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-delete-key | b2_delete_key}.
|
|
526
|
+
* @param apiUrl - The B2 API base URL.
|
|
527
|
+
* @param authToken - The authorization token.
|
|
528
|
+
* @param request - The API request parameters.
|
|
529
|
+
*
|
|
530
|
+
* @returns The deleted application key metadata.
|
|
531
|
+
*/
|
|
532
|
+
async deleteKey(apiUrl, authToken, request) {
|
|
533
|
+
return normalizeKeyResponse(await this.postJson(apiUrl, authToken, "b2_delete_key", request, void 0, "v4"));
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-update-file-retention | b2_update_file_retention}.
|
|
537
|
+
* @param apiUrl - The B2 API base URL.
|
|
538
|
+
* @param authToken - The authorization token.
|
|
539
|
+
* @param request - The API request parameters.
|
|
540
|
+
*
|
|
541
|
+
* @returns The updated file retention settings.
|
|
542
|
+
*/
|
|
543
|
+
async updateFileRetention(apiUrl, authToken, request) {
|
|
544
|
+
return this.postJson(apiUrl, authToken, "b2_update_file_retention", request);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-update-file-legal-hold | b2_update_file_legal_hold}.
|
|
548
|
+
* @param apiUrl - The B2 API base URL.
|
|
549
|
+
* @param authToken - The authorization token.
|
|
550
|
+
* @param request - The API request parameters.
|
|
551
|
+
*
|
|
552
|
+
* @returns The updated file legal hold status.
|
|
553
|
+
*/
|
|
554
|
+
async updateFileLegalHold(apiUrl, authToken, request) {
|
|
555
|
+
return this.postJson(apiUrl, authToken, "b2_update_file_legal_hold", request);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-get-bucket-notification-rules | b2_get_bucket_notification_rules}.
|
|
559
|
+
* @param apiUrl - The B2 API base URL.
|
|
560
|
+
* @param authToken - The authorization token.
|
|
561
|
+
* @param request - The API request parameters.
|
|
562
|
+
*
|
|
563
|
+
* @returns The configured event notification rules for the specified bucket.
|
|
564
|
+
*/
|
|
565
|
+
async getBucketNotificationRules(apiUrl, authToken, request) {
|
|
566
|
+
return this.postJson(apiUrl, authToken, "b2_get_bucket_notification_rules", request);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Calls {@link https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules | b2_set_bucket_notification_rules}.
|
|
570
|
+
* @param apiUrl - The B2 API base URL.
|
|
571
|
+
* @param authToken - The authorization token.
|
|
572
|
+
* @param request - The API request parameters.
|
|
573
|
+
*
|
|
574
|
+
* @returns The updated bucket notification rules.
|
|
575
|
+
*/
|
|
576
|
+
async setBucketNotificationRules(apiUrl, authToken, request) {
|
|
577
|
+
return this.postJson(apiUrl, authToken, "b2_set_bucket_notification_rules", request);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Sends a JSON POST request to the specified B2 API endpoint.
|
|
581
|
+
* @param apiUrl - The B2 API base URL.
|
|
582
|
+
* @param authToken - The authorization token.
|
|
583
|
+
* @param endpoint - The B2 API endpoint name.
|
|
584
|
+
* @param body - The JSON request body.
|
|
585
|
+
* @param options - Optional abort and per-request retry settings.
|
|
586
|
+
* @param apiVersion - B2 Native API version segment for this endpoint.
|
|
587
|
+
*
|
|
588
|
+
* @returns The parsed JSON response.
|
|
589
|
+
*/
|
|
590
|
+
async postJson(apiUrl, authToken, endpoint, body, options, apiVersion = "v3") {
|
|
591
|
+
return (await this.transport.send({
|
|
592
|
+
url: `${apiUrl}/b2api/${apiVersion}/${endpoint}`,
|
|
593
|
+
method: "POST",
|
|
594
|
+
headers: {
|
|
595
|
+
Authorization: authToken,
|
|
596
|
+
"Content-Type": "application/json"
|
|
597
|
+
},
|
|
598
|
+
body: JSON.stringify(body),
|
|
599
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {},
|
|
600
|
+
...options?.retry !== void 0 ? { retry: options.retry } : {}
|
|
601
|
+
})).json();
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* Applies server-side encryption headers to the request.
|
|
606
|
+
* @param headers - The mutable headers object to populate.
|
|
607
|
+
* @param encryption - The encryption settings, or undefined to skip.
|
|
608
|
+
*/
|
|
539
609
|
function applyEncryptionHeaders(headers, encryption) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
610
|
+
if (!encryption || encryption.mode === EncryptionMode.None) return;
|
|
611
|
+
if (encryption.mode === EncryptionMode.SseB2) headers["X-Bz-Server-Side-Encryption"] = EncryptionAlgorithm.Aes256;
|
|
612
|
+
else if (encryption.mode === EncryptionMode.SseC) {
|
|
613
|
+
headers["X-Bz-Server-Side-Encryption-Customer-Algorithm"] = EncryptionAlgorithm.Aes256;
|
|
614
|
+
headers["X-Bz-Server-Side-Encryption-Customer-Key"] = encryption.customerKey;
|
|
615
|
+
headers["X-Bz-Server-Side-Encryption-Customer-Key-Md5"] = encryption.customerKeyMd5;
|
|
616
|
+
}
|
|
548
617
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
618
|
+
var DOWNLOAD_OVERRIDE_PARAMS = [
|
|
619
|
+
"b2ContentDisposition",
|
|
620
|
+
"b2ContentLanguage",
|
|
621
|
+
"b2ContentEncoding",
|
|
622
|
+
"b2ContentType",
|
|
623
|
+
"b2CacheControl",
|
|
624
|
+
"b2Expires"
|
|
556
625
|
];
|
|
626
|
+
/**
|
|
627
|
+
* Builds the HTTP request headers for a download: Authorization, optional
|
|
628
|
+
* Range, and optional SSE-C decryption headers.
|
|
629
|
+
*
|
|
630
|
+
* @param authToken - The B2 session authorization token.
|
|
631
|
+
* @param options - Caller-supplied download options.
|
|
632
|
+
*
|
|
633
|
+
* @returns The header map to send with the request.
|
|
634
|
+
*/
|
|
557
635
|
function buildDownloadRequestHeaders(authToken, options) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
return headers;
|
|
636
|
+
const headers = { Authorization: authToken };
|
|
637
|
+
if (options?.range) headers["Range"] = options.range;
|
|
638
|
+
if (options?.serverSideEncryption) applyEncryptionHeaders(headers, {
|
|
639
|
+
mode: EncryptionMode.SseC,
|
|
640
|
+
...options.serverSideEncryption
|
|
641
|
+
});
|
|
642
|
+
return headers;
|
|
567
643
|
}
|
|
644
|
+
/**
|
|
645
|
+
* Appends the documented `b2Content*` response-header overrides to a download
|
|
646
|
+
* URL as query-string parameters. B2 echoes the values into the response
|
|
647
|
+
* headers so callers can control content type, disposition, and caching.
|
|
648
|
+
*
|
|
649
|
+
* @param url - The base download URL.
|
|
650
|
+
* @param options - Caller-supplied download options.
|
|
651
|
+
*
|
|
652
|
+
* @returns The URL with any override parameters appended.
|
|
653
|
+
*/
|
|
568
654
|
function appendDownloadOverrides(url, options) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
if (params.length === 0) return url;
|
|
578
|
-
const separator = url.includes("?") ? "&" : "?";
|
|
579
|
-
return `${url}${separator}${params.join("&")}`;
|
|
655
|
+
if (!options) return url;
|
|
656
|
+
const params = [];
|
|
657
|
+
for (const key of DOWNLOAD_OVERRIDE_PARAMS) {
|
|
658
|
+
const value = options[key];
|
|
659
|
+
if (value !== void 0) params.push(`${key}=${encodeURIComponent(value)}`);
|
|
660
|
+
}
|
|
661
|
+
if (params.length === 0) return url;
|
|
662
|
+
return `${url}${url.includes("?") ? "&" : "?"}${params.join("&")}`;
|
|
580
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* Applies file retention headers to the request.
|
|
666
|
+
* @param headers - The mutable headers object to populate.
|
|
667
|
+
* @param retention - The retention settings, or undefined to skip.
|
|
668
|
+
*/
|
|
581
669
|
function applyRetentionHeaders(headers, retention) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
if (retention.retainUntilTimestamp) {
|
|
587
|
-
headers["X-Bz-File-Retention-Retain-Until-Timestamp"] = String(retention.retainUntilTimestamp);
|
|
588
|
-
}
|
|
670
|
+
if (!retention) return;
|
|
671
|
+
if (retention.mode) headers["X-Bz-File-Retention-Mode"] = retention.mode;
|
|
672
|
+
if (retention.retainUntilTimestamp) headers["X-Bz-File-Retention-Retain-Until-Timestamp"] = String(retention.retainUntilTimestamp);
|
|
589
673
|
}
|
|
674
|
+
/**
|
|
675
|
+
* Applies the legal hold header to the request.
|
|
676
|
+
* @param headers - The mutable headers object to populate.
|
|
677
|
+
* @param legalHold - The legal hold value, or undefined to skip.
|
|
678
|
+
*/
|
|
590
679
|
function applyLegalHoldHeader(headers, legalHold) {
|
|
591
|
-
|
|
592
|
-
|
|
680
|
+
if (!legalHold) return;
|
|
681
|
+
headers["X-Bz-File-Legal-Hold"] = legalHold;
|
|
593
682
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
encodeFileName,
|
|
599
|
-
parseFileInfoHeaders
|
|
600
|
-
};
|
|
601
|
-
//# sourceMappingURL=index.js.map
|
|
683
|
+
//#endregion
|
|
684
|
+
export { RawClient, buildFileInfoHeaders, decodeFileName, encodeFileName, parseFileInfoHeaders };
|
|
685
|
+
|
|
686
|
+
//# sourceMappingURL=index.js.map
|