@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/http/transport.js
CHANGED
|
@@ -1,143 +1,440 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DEFAULT_RETRY_OPTIONS,
|
|
1
|
+
import { B2Error, B2RedirectError, B2SsrfError, ExpiredAuthTokenError, NetworkError, classifyError } from "../errors/index.js";
|
|
2
|
+
import { DEFAULT_RETRY_OPTIONS, computeBackoff, sleep } from "./retry.js";
|
|
3
3
|
import { UrlGuard } from "./url-guard.js";
|
|
4
4
|
import { getUserAgent } from "./user-agent.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
let errorBody;
|
|
91
|
-
try {
|
|
92
|
-
errorBody = await response.json();
|
|
93
|
-
} catch {
|
|
94
|
-
errorBody = {
|
|
95
|
-
status: response.status,
|
|
96
|
-
code: "internal_error",
|
|
97
|
-
message: `HTTP ${response.status}`
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
const retryAfterHeader = response.headers.get("Retry-After");
|
|
101
|
-
const retryAfterSec = retryAfterHeader ? Number.parseInt(retryAfterHeader, 10) : void 0;
|
|
102
|
-
const requestId = response.headers.get("X-Bz-Request-Id") ?? void 0;
|
|
103
|
-
const error = classifyError(errorBody, {
|
|
104
|
-
...retryAfterSec !== void 0 ? { retryAfter: retryAfterSec } : {},
|
|
105
|
-
...requestId !== void 0 ? { requestId } : {}
|
|
106
|
-
});
|
|
107
|
-
if (error instanceof ExpiredAuthTokenError && this.onReauth) {
|
|
108
|
-
const freshToken = await this.onReauth();
|
|
109
|
-
request = {
|
|
110
|
-
...request,
|
|
111
|
-
headers: { ...request.headers ?? {}, Authorization: freshToken }
|
|
112
|
-
};
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
if (!error.retryable || attempt === this.options.maxRetries) {
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
lastError = error;
|
|
119
|
-
} catch (err) {
|
|
120
|
-
if (err instanceof B2Error || err instanceof NetworkError) {
|
|
121
|
-
throw err;
|
|
122
|
-
}
|
|
123
|
-
if (err instanceof DOMException && err.name === "AbortError") {
|
|
124
|
-
throw err;
|
|
125
|
-
}
|
|
126
|
-
const networkErr = new NetworkError(
|
|
127
|
-
err instanceof Error ? err.message : "Network error",
|
|
128
|
-
err
|
|
129
|
-
);
|
|
130
|
-
if (attempt === this.options.maxRetries) {
|
|
131
|
-
throw networkErr;
|
|
132
|
-
}
|
|
133
|
-
lastError = networkErr;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
throw lastError ?? new NetworkError("Max retries exceeded");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
export {
|
|
140
|
-
FetchTransport,
|
|
141
|
-
RetryTransport
|
|
5
|
+
//#region src/http/transport.ts
|
|
6
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([
|
|
7
|
+
301,
|
|
8
|
+
302,
|
|
9
|
+
303,
|
|
10
|
+
307,
|
|
11
|
+
308
|
|
12
|
+
]);
|
|
13
|
+
var MAX_SAME_ORIGIN_REDIRECTS = 5;
|
|
14
|
+
/**
|
|
15
|
+
* Default transport implementation using the global `fetch` API.
|
|
16
|
+
* Automatically sets the User-Agent header on each request and applies the
|
|
17
|
+
* SSRF {@link UrlGuard} (if configured) before opening the connection.
|
|
18
|
+
* Redirect following is disabled so redirected URLs cannot bypass the guard or
|
|
19
|
+
* receive credential-bearing headers without an explicit checked request.
|
|
20
|
+
*/
|
|
21
|
+
var FetchTransport = class {
|
|
22
|
+
/** User-Agent string sent with every request. */
|
|
23
|
+
userAgent;
|
|
24
|
+
/** Whether same-origin GET/HEAD redirects should be followed after guard checks. */
|
|
25
|
+
followSameOriginRedirects;
|
|
26
|
+
/** SSRF allow-list applied to every outgoing URL. Mutable so `B2Client.authorize()` can lock it down post-auth. */
|
|
27
|
+
urlGuard;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new FetchTransport.
|
|
30
|
+
* @param options - Optional configuration: custom User-Agent prefix and SSRF guard.
|
|
31
|
+
*/
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.userAgent = getUserAgent(options?.userAgent);
|
|
34
|
+
this.followSameOriginRedirects = options?.followSameOriginRedirects ?? true;
|
|
35
|
+
this.urlGuard = options?.urlGuard ?? new UrlGuard();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sends the request using the global `fetch` function.
|
|
39
|
+
* @param request - The HTTP request to execute.
|
|
40
|
+
*
|
|
41
|
+
* @returns The HTTP response.
|
|
42
|
+
*
|
|
43
|
+
* @throws B2SsrfError when the URL fails the configured SSRF guard.
|
|
44
|
+
* @throws B2RedirectError when a response attempts to redirect.
|
|
45
|
+
*/
|
|
46
|
+
async send(request) {
|
|
47
|
+
let currentRequest = request;
|
|
48
|
+
let redirectCount = 0;
|
|
49
|
+
while (true) {
|
|
50
|
+
this.urlGuard.check(currentRequest.url);
|
|
51
|
+
const headers = new Headers(currentRequest.headers);
|
|
52
|
+
if (!headers.has("User-Agent")) headers.set("User-Agent", this.userAgent);
|
|
53
|
+
const timeoutScope = createRequestTimeoutScope(currentRequest);
|
|
54
|
+
let response;
|
|
55
|
+
try {
|
|
56
|
+
response = await fetch(currentRequest.url, {
|
|
57
|
+
method: currentRequest.method,
|
|
58
|
+
headers,
|
|
59
|
+
body: currentRequest.body ?? null,
|
|
60
|
+
redirect: "manual",
|
|
61
|
+
...timeoutScope.signal !== void 0 ? { signal: timeoutScope.signal } : {}
|
|
62
|
+
});
|
|
63
|
+
} catch (err) {
|
|
64
|
+
timeoutScope.dispose();
|
|
65
|
+
if (timeoutScope.timedOut) throw createRequestTimeoutError(timeoutScope);
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
if (isBlockedRedirect(response)) {
|
|
69
|
+
const location = response.headers.get("Location");
|
|
70
|
+
if (this.followSameOriginRedirects && location !== null && redirectCount < MAX_SAME_ORIGIN_REDIRECTS && canFollowSameOriginRedirect(currentRequest, location)) {
|
|
71
|
+
const nextUrl = new URL(location, currentRequest.url).toString();
|
|
72
|
+
await cancelResponseBody(response);
|
|
73
|
+
timeoutScope.dispose();
|
|
74
|
+
this.urlGuard.check(nextUrl);
|
|
75
|
+
currentRequest = {
|
|
76
|
+
...currentRequest,
|
|
77
|
+
url: nextUrl
|
|
78
|
+
};
|
|
79
|
+
redirectCount += 1;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
await cancelResponseBody(response);
|
|
83
|
+
timeoutScope.dispose();
|
|
84
|
+
throw new B2RedirectError(currentRequest.url, response.status, location);
|
|
85
|
+
}
|
|
86
|
+
return createTimedHttpResponse(response, timeoutScope);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
142
89
|
};
|
|
143
|
-
|
|
90
|
+
function createRequestTimeoutScope(request) {
|
|
91
|
+
const timeoutMs = request.retry?.requestTimeoutMs ?? DEFAULT_RETRY_OPTIONS.requestTimeoutMs;
|
|
92
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
93
|
+
const scope = {
|
|
94
|
+
timeoutMs: 0,
|
|
95
|
+
timedOut: false,
|
|
96
|
+
reset() {},
|
|
97
|
+
dispose() {}
|
|
98
|
+
};
|
|
99
|
+
if (request.signal !== void 0) return {
|
|
100
|
+
...scope,
|
|
101
|
+
signal: request.signal
|
|
102
|
+
};
|
|
103
|
+
return scope;
|
|
104
|
+
}
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
let timedOut = false;
|
|
107
|
+
let timer;
|
|
108
|
+
const abortFromUpstream = () => {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
controller.abort(request.signal?.reason ?? new DOMException("Aborted", "AbortError"));
|
|
111
|
+
};
|
|
112
|
+
const armTimer = () => {
|
|
113
|
+
const nextTimer = setTimeout(() => {
|
|
114
|
+
timedOut = true;
|
|
115
|
+
controller.abort(new DOMException("HTTP request timed out", "TimeoutError"));
|
|
116
|
+
}, timeoutMs);
|
|
117
|
+
unrefTimer(nextTimer);
|
|
118
|
+
return nextTimer;
|
|
119
|
+
};
|
|
120
|
+
timer = armTimer();
|
|
121
|
+
const reset = () => {
|
|
122
|
+
if (timedOut || controller.signal.aborted) return;
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
timer = armTimer();
|
|
125
|
+
};
|
|
126
|
+
if (request.signal?.aborted === true) {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
abortFromUpstream();
|
|
129
|
+
} else request.signal?.addEventListener("abort", abortFromUpstream, { once: true });
|
|
130
|
+
return {
|
|
131
|
+
signal: controller.signal,
|
|
132
|
+
timeoutMs,
|
|
133
|
+
get timedOut() {
|
|
134
|
+
return timedOut;
|
|
135
|
+
},
|
|
136
|
+
reset,
|
|
137
|
+
dispose() {
|
|
138
|
+
clearTimeout(timer);
|
|
139
|
+
request.signal?.removeEventListener("abort", abortFromUpstream);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function unrefTimer(timer) {
|
|
144
|
+
const maybeUnref = timer.unref;
|
|
145
|
+
if (typeof maybeUnref === "function") maybeUnref.call(timer);
|
|
146
|
+
}
|
|
147
|
+
function createRequestTimeoutError(scope) {
|
|
148
|
+
return new DOMException(`HTTP request timed out after ${scope.timeoutMs} ms`, "TimeoutError");
|
|
149
|
+
}
|
|
150
|
+
function createTimedHttpResponse(response, timeoutScope) {
|
|
151
|
+
const body = response.body;
|
|
152
|
+
if (body === null) timeoutScope.dispose();
|
|
153
|
+
let timedBody;
|
|
154
|
+
return {
|
|
155
|
+
status: response.status,
|
|
156
|
+
headers: response.headers,
|
|
157
|
+
get body() {
|
|
158
|
+
if (body === null) return null;
|
|
159
|
+
timedBody ??= createTimedResponseBody(body, timeoutScope);
|
|
160
|
+
return timedBody;
|
|
161
|
+
},
|
|
162
|
+
json: () => readTimedResponseBody(timeoutScope, response, () => response.json()),
|
|
163
|
+
text: () => readTimedResponseBody(timeoutScope, response, () => response.text()),
|
|
164
|
+
arrayBuffer: () => readTimedResponseBody(timeoutScope, response, () => response.arrayBuffer())
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
async function readTimedResponseBody(timeoutScope, response, read) {
|
|
168
|
+
try {
|
|
169
|
+
return await raceBodyReadWithAbort(timeoutScope, read(), (reason) => cancelResponseBody(response, reason));
|
|
170
|
+
} catch (err) {
|
|
171
|
+
if (timeoutScope.timedOut) throw createRequestTimeoutError(timeoutScope);
|
|
172
|
+
throw err;
|
|
173
|
+
} finally {
|
|
174
|
+
timeoutScope.dispose();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function createTimedResponseBody(body, timeoutScope) {
|
|
178
|
+
let reader;
|
|
179
|
+
let disposed = false;
|
|
180
|
+
const dispose = () => {
|
|
181
|
+
if (disposed) return;
|
|
182
|
+
disposed = true;
|
|
183
|
+
timeoutScope.dispose();
|
|
184
|
+
};
|
|
185
|
+
return new ReadableStream({
|
|
186
|
+
async pull(controller) {
|
|
187
|
+
reader ??= body.getReader();
|
|
188
|
+
try {
|
|
189
|
+
const result = await raceBodyReadWithAbort(timeoutScope, reader.read(), (reason) => reader?.cancel(reason));
|
|
190
|
+
if (result.done) {
|
|
191
|
+
dispose();
|
|
192
|
+
controller.close();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
timeoutScope.reset();
|
|
196
|
+
controller.enqueue(result.value);
|
|
197
|
+
} catch (err) {
|
|
198
|
+
dispose();
|
|
199
|
+
if (timeoutScope.timedOut) {
|
|
200
|
+
controller.error(createRequestTimeoutError(timeoutScope));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
controller.error(err);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
async cancel(reason) {
|
|
207
|
+
dispose();
|
|
208
|
+
try {
|
|
209
|
+
if (reader !== void 0) {
|
|
210
|
+
await reader.cancel(reason);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
await body.cancel(reason);
|
|
214
|
+
} catch {}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async function raceBodyReadWithAbort(timeoutScope, read, abortCleanup) {
|
|
219
|
+
const signal = timeoutScope.signal;
|
|
220
|
+
if (signal === void 0) return read;
|
|
221
|
+
const abortReason = () => signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
222
|
+
if (signal.aborted) {
|
|
223
|
+
read.catch(() => {});
|
|
224
|
+
const reason = abortReason();
|
|
225
|
+
await runAbortCleanup(abortCleanup, reason);
|
|
226
|
+
throw reason;
|
|
227
|
+
}
|
|
228
|
+
let removeAbortListener;
|
|
229
|
+
const abort = new Promise((_, reject) => {
|
|
230
|
+
const onAbort = () => {
|
|
231
|
+
const reason = abortReason();
|
|
232
|
+
read.catch(() => {});
|
|
233
|
+
reject(reason);
|
|
234
|
+
runAbortCleanup(abortCleanup, reason);
|
|
235
|
+
};
|
|
236
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
237
|
+
removeAbortListener = () => signal.removeEventListener("abort", onAbort);
|
|
238
|
+
});
|
|
239
|
+
try {
|
|
240
|
+
return await Promise.race([read, abort]);
|
|
241
|
+
} finally {
|
|
242
|
+
removeAbortListener?.();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function runAbortCleanup(abortCleanup, reason) {
|
|
246
|
+
try {
|
|
247
|
+
await abortCleanup?.(reason);
|
|
248
|
+
} catch {}
|
|
249
|
+
}
|
|
250
|
+
function isBlockedRedirect(response) {
|
|
251
|
+
return response.type === "opaqueredirect" || REDIRECT_STATUSES.has(response.status);
|
|
252
|
+
}
|
|
253
|
+
function canFollowSameOriginRedirect(request, location) {
|
|
254
|
+
if (request.method !== "GET" && request.method !== "HEAD") return false;
|
|
255
|
+
try {
|
|
256
|
+
return new URL(request.url).origin === new URL(location, request.url).origin;
|
|
257
|
+
} catch {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async function cancelResponseBody(response, reason) {
|
|
262
|
+
try {
|
|
263
|
+
await response.body?.cancel(reason);
|
|
264
|
+
} catch {}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Decide whether `url` points at a URL-pinned upload POST endpoint.
|
|
268
|
+
*
|
|
269
|
+
* @param url - Request URL to inspect.
|
|
270
|
+
*
|
|
271
|
+
* @returns Whether the request is a direct upload endpoint.
|
|
272
|
+
*/
|
|
273
|
+
function isUploadEndpoint(url) {
|
|
274
|
+
const endpoint = b2ApiEndpointName(url);
|
|
275
|
+
return endpoint === "b2_upload_file" || endpoint === "b2_upload_part";
|
|
276
|
+
}
|
|
277
|
+
function isFinishLargeFileEndpoint(url) {
|
|
278
|
+
return b2ApiEndpointName(url) === "b2_finish_large_file";
|
|
279
|
+
}
|
|
280
|
+
function isStartLargeFileEndpoint(url) {
|
|
281
|
+
return b2ApiEndpointName(url) === "b2_start_large_file";
|
|
282
|
+
}
|
|
283
|
+
function b2ApiEndpointName(url) {
|
|
284
|
+
const [, root, , endpoint] = new URL(url).pathname.split("/");
|
|
285
|
+
if (root !== "b2api") return void 0;
|
|
286
|
+
return endpoint;
|
|
287
|
+
}
|
|
288
|
+
function isReplayUnsafePostEndpoint(url) {
|
|
289
|
+
return isUploadEndpoint(url) || isStartLargeFileEndpoint(url) || isFinishLargeFileEndpoint(url);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Decide whether a classified error should be retried in place for `url`.
|
|
293
|
+
* Transient errors normally retry; upload endpoints bubble to the upload layer
|
|
294
|
+
* for fresh-URL retry except account-level 429 throttling, where fetching a new
|
|
295
|
+
* upload URL only amplifies the rate limit.
|
|
296
|
+
*
|
|
297
|
+
* @param error - The classified, retryability-tagged error.
|
|
298
|
+
* @param url - The request URL (used to detect upload endpoints).
|
|
299
|
+
*
|
|
300
|
+
* @returns Whether to retry the request in place.
|
|
301
|
+
*/
|
|
302
|
+
function shouldRetryInPlace(error, url) {
|
|
303
|
+
if (!error.retryable) return false;
|
|
304
|
+
if (isStartLargeFileEndpoint(url) || isFinishLargeFileEndpoint(url)) return false;
|
|
305
|
+
if (isUploadEndpoint(url) && error.status === 429) return true;
|
|
306
|
+
if (isUploadEndpoint(url)) return false;
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
function isRequestTimeoutError(err) {
|
|
310
|
+
return err instanceof DOMException && err.name === "TimeoutError";
|
|
311
|
+
}
|
|
312
|
+
function isTerminalTransportError(err) {
|
|
313
|
+
return err instanceof B2Error || err instanceof B2RedirectError || err instanceof NetworkError || err instanceof B2SsrfError || err instanceof DOMException && err.name === "AbortError";
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Transport wrapper that adds automatic retry with exponential backoff.
|
|
317
|
+
* Handles transient errors (408, 429, and the transient 5xx set 500/502/503/504),
|
|
318
|
+
* expired auth tokens, and network failures. Delegates to an inner
|
|
319
|
+
* {@link HttpTransport}.
|
|
320
|
+
*
|
|
321
|
+
* Upload endpoints (`b2_upload_file` / `b2_upload_part`) are URL-pinned. Their
|
|
322
|
+
* retryable pod failures bubble to the upload layer, which evicts the failed
|
|
323
|
+
* URL, fetches a fresh one, and retries there. HTTP 429 remains an in-place
|
|
324
|
+
* retry so account-level throttling does not trigger extra upload URL fetches.
|
|
325
|
+
*/
|
|
326
|
+
var RetryTransport = class {
|
|
327
|
+
/** The wrapped transport that performs actual HTTP requests. */
|
|
328
|
+
inner;
|
|
329
|
+
/** Resolved retry options (defaults merged with user overrides). */
|
|
330
|
+
options;
|
|
331
|
+
/** Optional callback to refresh auth credentials on 401 — returns the fresh token. */
|
|
332
|
+
onReauth;
|
|
333
|
+
/** Sleep implementation used between retries; injectable for tests. */
|
|
334
|
+
sleepImpl;
|
|
335
|
+
/**
|
|
336
|
+
* Creates a new RetryTransport.
|
|
337
|
+
* @param opts - Retry transport configuration.
|
|
338
|
+
*/
|
|
339
|
+
constructor(opts) {
|
|
340
|
+
this.inner = opts.transport;
|
|
341
|
+
this.options = {
|
|
342
|
+
...DEFAULT_RETRY_OPTIONS,
|
|
343
|
+
...opts.retry
|
|
344
|
+
};
|
|
345
|
+
if (opts.onReauth !== void 0) this.onReauth = opts.onReauth;
|
|
346
|
+
this.sleepImpl = opts.sleepImpl ?? sleep;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Sends the request with automatic retry on transient failures.
|
|
350
|
+
* On expired auth tokens, calls {@link RetryTransportOptions.onReauth} and retries.
|
|
351
|
+
* @param originalRequest - The HTTP request to execute. The caller's
|
|
352
|
+
* reference is not mutated; on reauth, a copy with a refreshed
|
|
353
|
+
* Authorization header is sent.
|
|
354
|
+
*
|
|
355
|
+
* @returns The HTTP response.
|
|
356
|
+
*/
|
|
357
|
+
async send(originalRequest) {
|
|
358
|
+
let request = originalRequest;
|
|
359
|
+
const retryOptions = {
|
|
360
|
+
...this.options,
|
|
361
|
+
...originalRequest.retry
|
|
362
|
+
};
|
|
363
|
+
let lastError;
|
|
364
|
+
let didReauth = false;
|
|
365
|
+
let attempt = 0;
|
|
366
|
+
while (attempt <= retryOptions.maxRetries) {
|
|
367
|
+
throwIfSignalAborted(request.signal);
|
|
368
|
+
if (attempt > 0 && lastError) {
|
|
369
|
+
const retryAfter = lastError instanceof NetworkError ? void 0 : lastError.retryAfter;
|
|
370
|
+
const delay = computeBackoff(attempt - 1, retryOptions, retryAfter);
|
|
371
|
+
await this.sleepImpl(delay, request.signal);
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const response = await this.inner.send({
|
|
375
|
+
...request,
|
|
376
|
+
retry: retryOptions
|
|
377
|
+
});
|
|
378
|
+
await throwIfSignalAbortedAfterResponse(request.signal, response);
|
|
379
|
+
if (response.status >= 200 && response.status < 300) return response;
|
|
380
|
+
let errorBody;
|
|
381
|
+
try {
|
|
382
|
+
errorBody = await response.json();
|
|
383
|
+
} catch (err) {
|
|
384
|
+
if (isRequestTimeoutError(err)) throw err;
|
|
385
|
+
errorBody = {
|
|
386
|
+
status: response.status,
|
|
387
|
+
code: "internal_error",
|
|
388
|
+
message: `HTTP ${response.status}`
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
const retryAfterHeader = response.headers.get("Retry-After");
|
|
392
|
+
const retryAfterSec = retryAfterHeader ? Number.parseInt(retryAfterHeader, 10) : void 0;
|
|
393
|
+
const requestId = response.headers.get("X-Bz-Request-Id") ?? void 0;
|
|
394
|
+
const error = classifyError(errorBody, {
|
|
395
|
+
...retryAfterSec !== void 0 ? { retryAfter: retryAfterSec } : {},
|
|
396
|
+
...requestId !== void 0 ? { requestId } : {}
|
|
397
|
+
});
|
|
398
|
+
if (error instanceof ExpiredAuthTokenError && this.onReauth && !isUploadEndpoint(request.url) && !didReauth) {
|
|
399
|
+
const freshToken = await this.onReauth();
|
|
400
|
+
request = {
|
|
401
|
+
...request,
|
|
402
|
+
headers: {
|
|
403
|
+
...request.headers ?? {},
|
|
404
|
+
Authorization: freshToken
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
didReauth = true;
|
|
408
|
+
lastError = void 0;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
if (!shouldRetryInPlace(error, request.url) || attempt === retryOptions.maxRetries) throw error;
|
|
412
|
+
lastError = error;
|
|
413
|
+
attempt += 1;
|
|
414
|
+
} catch (err) {
|
|
415
|
+
throwIfSignalAborted(request.signal);
|
|
416
|
+
if (isTerminalTransportError(err)) throw err;
|
|
417
|
+
const networkErr = new NetworkError(err instanceof Error ? err.message : "Network error", err);
|
|
418
|
+
if (isReplayUnsafePostEndpoint(request.url) || attempt === retryOptions.maxRetries) throw networkErr;
|
|
419
|
+
lastError = networkErr;
|
|
420
|
+
attempt += 1;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
throw lastError ?? new NetworkError("Max retries exceeded");
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
function throwIfSignalAborted(signal) {
|
|
427
|
+
if (signal?.aborted === true) throw signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
428
|
+
}
|
|
429
|
+
async function throwIfSignalAbortedAfterResponse(signal, response) {
|
|
430
|
+
if (signal?.aborted !== true) return;
|
|
431
|
+
const reason = signal.reason ?? new DOMException("Aborted", "AbortError");
|
|
432
|
+
try {
|
|
433
|
+
await response.body?.cancel(reason);
|
|
434
|
+
} catch {}
|
|
435
|
+
throw reason;
|
|
436
|
+
}
|
|
437
|
+
//#endregion
|
|
438
|
+
export { FetchTransport, RetryTransport };
|
|
439
|
+
|
|
440
|
+
//# sourceMappingURL=transport.js.map
|