@backblaze-labs/b2-sdk 0.2.0 → 0.3.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 +42 -1
- package/README.md +20 -2
- package/dist/_virtual/_b2-sdk-version-json.cjs +1 -1
- package/dist/_virtual/_b2-sdk-version-json.js +1 -1
- package/dist/auth/file.cjs.map +1 -1
- package/dist/backup/client.cjs +206 -0
- package/dist/backup/client.cjs.map +1 -0
- package/dist/backup/client.d.cts +238 -0
- package/dist/backup/client.d.cts.map +1 -0
- package/dist/backup/client.d.ts +238 -0
- package/dist/backup/client.d.ts.map +1 -0
- package/dist/backup/client.js +206 -0
- package/dist/backup/client.js.map +1 -0
- package/dist/backup/index.cjs +15 -0
- package/dist/backup/index.d.cts +22 -0
- package/dist/backup/index.d.cts.map +1 -0
- package/dist/backup/index.d.ts +22 -0
- package/dist/backup/index.d.ts.map +1 -0
- package/dist/backup/index.js +7 -0
- package/dist/backup/raw.cjs +146 -0
- package/dist/backup/raw.cjs.map +1 -0
- package/dist/backup/raw.d.cts +122 -0
- package/dist/backup/raw.d.cts.map +1 -0
- package/dist/backup/raw.d.ts +122 -0
- package/dist/backup/raw.d.ts.map +1 -0
- package/dist/backup/raw.js +146 -0
- package/dist/backup/raw.js.map +1 -0
- package/dist/bucket.cjs +2 -1
- package/dist/bucket.cjs.map +1 -1
- package/dist/bucket.js +2 -1
- package/dist/bucket.js.map +1 -1
- package/dist/copy/large.cjs +5 -3
- package/dist/copy/large.cjs.map +1 -1
- package/dist/copy/large.d.cts.map +1 -1
- package/dist/copy/large.d.ts.map +1 -1
- package/dist/copy/large.js +5 -3
- package/dist/copy/large.js.map +1 -1
- package/dist/download/checksum.cjs +6 -2
- package/dist/download/checksum.cjs.map +1 -1
- package/dist/download/checksum.js +6 -2
- package/dist/download/checksum.js.map +1 -1
- package/dist/download/parallel.cjs +52 -15
- package/dist/download/parallel.cjs.map +1 -1
- package/dist/download/parallel.d.cts +8 -1
- package/dist/download/parallel.d.cts.map +1 -1
- package/dist/download/parallel.d.ts +8 -1
- package/dist/download/parallel.d.ts.map +1 -1
- package/dist/download/parallel.js +52 -15
- package/dist/download/parallel.js.map +1 -1
- package/dist/download/single.cjs +141 -6
- package/dist/download/single.cjs.map +1 -1
- package/dist/download/single.d.cts.map +1 -1
- package/dist/download/single.d.ts.map +1 -1
- package/dist/download/single.js +141 -6
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +173 -3
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +119 -0
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +119 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +161 -4
- package/dist/errors/index.js.map +1 -1
- package/dist/http/retry.cjs +1 -1
- package/dist/http/retry.cjs.map +1 -1
- package/dist/http/retry.js +1 -1
- package/dist/http/retry.js.map +1 -1
- package/dist/http/transport.cjs +61 -23
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +25 -3
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +25 -3
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +59 -22
- package/dist/http/transport.js.map +1 -1
- package/dist/index.cjs +25 -2
- package/dist/index.d.cts +6 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/object.cjs +1 -1
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.cts +4 -2
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +4 -2
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +1 -1
- package/dist/object.js.map +1 -1
- package/dist/partner/account-info.d.cts +43 -0
- package/dist/partner/account-info.d.cts.map +1 -0
- package/dist/partner/account-info.d.ts +43 -0
- package/dist/partner/account-info.d.ts.map +1 -0
- package/dist/partner/auth-clone.cjs +64 -0
- package/dist/partner/auth-clone.cjs.map +1 -0
- package/dist/partner/auth-clone.d.cts +27 -0
- package/dist/partner/auth-clone.d.cts.map +1 -0
- package/dist/partner/auth-clone.d.ts +27 -0
- package/dist/partner/auth-clone.d.ts.map +1 -0
- package/dist/partner/auth-clone.js +63 -0
- package/dist/partner/auth-clone.js.map +1 -0
- package/dist/partner/auth-core.cjs +175 -0
- package/dist/partner/auth-core.cjs.map +1 -0
- package/dist/partner/auth-core.d.cts +111 -0
- package/dist/partner/auth-core.d.cts.map +1 -0
- package/dist/partner/auth-core.d.ts +111 -0
- package/dist/partner/auth-core.d.ts.map +1 -0
- package/dist/partner/auth-core.js +175 -0
- package/dist/partner/auth-core.js.map +1 -0
- package/dist/partner/auth-shape.cjs +36 -0
- package/dist/partner/auth-shape.cjs.map +1 -0
- package/dist/partner/auth-shape.d.cts +12 -0
- package/dist/partner/auth-shape.d.cts.map +1 -0
- package/dist/partner/auth-shape.d.ts +12 -0
- package/dist/partner/auth-shape.d.ts.map +1 -0
- package/dist/partner/auth-shape.js +36 -0
- package/dist/partner/auth-shape.js.map +1 -0
- package/dist/partner/client.cjs +255 -0
- package/dist/partner/client.cjs.map +1 -0
- package/dist/partner/client.d.cts +335 -0
- package/dist/partner/client.d.cts.map +1 -0
- package/dist/partner/client.d.ts +335 -0
- package/dist/partner/client.d.ts.map +1 -0
- package/dist/partner/client.js +255 -0
- package/dist/partner/client.js.map +1 -0
- package/dist/partner/endpoint-url.cjs +108 -0
- package/dist/partner/endpoint-url.cjs.map +1 -0
- package/dist/partner/endpoint-url.d.cts +72 -0
- package/dist/partner/endpoint-url.d.cts.map +1 -0
- package/dist/partner/endpoint-url.d.ts +72 -0
- package/dist/partner/endpoint-url.d.ts.map +1 -0
- package/dist/partner/endpoint-url.js +105 -0
- package/dist/partner/endpoint-url.js.map +1 -0
- package/dist/partner/in-memory.cjs +135 -0
- package/dist/partner/in-memory.cjs.map +1 -0
- package/dist/partner/in-memory.d.cts +99 -0
- package/dist/partner/in-memory.d.cts.map +1 -0
- package/dist/partner/in-memory.d.ts +99 -0
- package/dist/partner/in-memory.d.ts.map +1 -0
- package/dist/partner/in-memory.js +135 -0
- package/dist/partner/in-memory.js.map +1 -0
- package/dist/partner/index.cjs +18 -0
- package/dist/partner/index.d.cts +23 -0
- package/dist/partner/index.d.cts.map +1 -0
- package/dist/partner/index.d.ts +23 -0
- package/dist/partner/index.d.ts.map +1 -0
- package/dist/partner/index.js +7 -0
- package/dist/partner/raw.cjs +392 -0
- package/dist/partner/raw.cjs.map +1 -0
- package/dist/partner/raw.d.cts +223 -0
- package/dist/partner/raw.d.cts.map +1 -0
- package/dist/partner/raw.d.ts +223 -0
- package/dist/partner/raw.d.ts.map +1 -0
- package/dist/partner/raw.js +390 -0
- package/dist/partner/raw.js.map +1 -0
- package/dist/partner/redaction-placeholders.cjs +10 -0
- package/dist/partner/redaction-placeholders.cjs.map +1 -0
- package/dist/partner/redaction-placeholders.d.cts +5 -0
- package/dist/partner/redaction-placeholders.d.cts.map +1 -0
- package/dist/partner/redaction-placeholders.d.ts +5 -0
- package/dist/partner/redaction-placeholders.d.ts.map +1 -0
- package/dist/partner/redaction-placeholders.js +9 -0
- package/dist/partner/redaction-placeholders.js.map +1 -0
- package/dist/partner/redaction.cjs +267 -0
- package/dist/partner/redaction.cjs.map +1 -0
- package/dist/partner/redaction.d.cts +124 -0
- package/dist/partner/redaction.d.cts.map +1 -0
- package/dist/partner/redaction.d.ts +124 -0
- package/dist/partner/redaction.d.ts.map +1 -0
- package/dist/partner/redaction.js +257 -0
- package/dist/partner/redaction.js.map +1 -0
- package/dist/raw/index.cjs +81 -19
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +6 -2
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +6 -2
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +81 -19
- package/dist/raw/index.js.map +1 -1
- package/dist/raw/url.cjs +111 -0
- package/dist/raw/url.cjs.map +1 -0
- package/dist/raw/url.d.cts +41 -0
- package/dist/raw/url.d.cts.map +1 -0
- package/dist/raw/url.d.ts +41 -0
- package/dist/raw/url.d.ts.map +1 -0
- package/dist/raw/url.js +110 -0
- package/dist/raw/url.js.map +1 -0
- package/dist/s3/sigv4.cjs +15 -10
- package/dist/s3/sigv4.cjs.map +1 -1
- package/dist/s3/sigv4.js +15 -10
- package/dist/s3/sigv4.js.map +1 -1
- package/dist/simulator/index.cjs +1197 -206
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +109 -11
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +109 -11
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +1196 -209
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/partner.cjs +719 -0
- package/dist/simulator/partner.cjs.map +1 -0
- package/dist/simulator/partner.d.cts +183 -0
- package/dist/simulator/partner.d.cts.map +1 -0
- package/dist/simulator/partner.d.ts +183 -0
- package/dist/simulator/partner.d.ts.map +1 -0
- package/dist/simulator/partner.js +718 -0
- package/dist/simulator/partner.js.map +1 -0
- package/dist/simulator/validation.cjs +577 -0
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +117 -0
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +117 -0
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +563 -1
- package/dist/simulator/validation.js.map +1 -1
- package/dist/streams/file-source.cjs +1 -1
- package/dist/streams/file-source.cjs.map +1 -1
- package/dist/streams/file-source.js +1 -1
- package/dist/streams/file-source.js.map +1 -1
- package/dist/streams/index.cjs +1 -1
- package/dist/streams/index.js +1 -1
- package/dist/streams/source.cjs +2 -1
- package/dist/streams/source.cjs.map +1 -1
- package/dist/streams/source.js +2 -1
- package/dist/streams/source.js.map +1 -1
- package/dist/sync/b2-sha1-reader.cjs +6 -2
- package/dist/sync/b2-sha1-reader.cjs.map +1 -1
- package/dist/sync/b2-sha1-reader.d.cts.map +1 -1
- package/dist/sync/b2-sha1-reader.d.ts.map +1 -1
- package/dist/sync/b2-sha1-reader.js +6 -2
- package/dist/sync/b2-sha1-reader.js.map +1 -1
- package/dist/sync/download-staging.cjs +11 -10
- package/dist/sync/download-staging.cjs.map +1 -1
- package/dist/sync/download-staging.d.cts +2 -1
- package/dist/sync/download-staging.d.cts.map +1 -1
- package/dist/sync/download-staging.d.ts +2 -1
- package/dist/sync/download-staging.d.ts.map +1 -1
- package/dist/sync/download-staging.js +11 -10
- package/dist/sync/download-staging.js.map +1 -1
- package/dist/sync/filters.cjs.map +1 -1
- package/dist/sync/filters.js.map +1 -1
- package/dist/sync/local-file-io.cjs +11 -6
- package/dist/sync/local-file-io.cjs.map +1 -1
- package/dist/sync/local-file-io.d.cts +1 -0
- package/dist/sync/local-file-io.d.cts.map +1 -1
- package/dist/sync/local-file-io.d.ts +1 -0
- package/dist/sync/local-file-io.d.ts.map +1 -1
- package/dist/sync/local-file-io.js +11 -6
- package/dist/sync/local-file-io.js.map +1 -1
- package/dist/sync/local-sha1.cjs +6 -15
- package/dist/sync/local-sha1.cjs.map +1 -1
- package/dist/sync/local-sha1.d.cts +0 -8
- package/dist/sync/local-sha1.d.cts.map +1 -1
- package/dist/sync/local-sha1.d.ts +0 -8
- package/dist/sync/local-sha1.d.ts.map +1 -1
- package/dist/sync/local-sha1.js +7 -15
- package/dist/sync/local-sha1.js.map +1 -1
- package/dist/sync/policies/compare.cjs +5 -3
- package/dist/sync/policies/compare.cjs.map +1 -1
- package/dist/sync/policies/compare.d.cts.map +1 -1
- package/dist/sync/policies/compare.d.ts.map +1 -1
- package/dist/sync/policies/compare.js +6 -4
- package/dist/sync/policies/compare.js.map +1 -1
- package/dist/sync/policies/index.cjs +4 -10
- package/dist/sync/policies/index.cjs.map +1 -1
- package/dist/sync/policies/index.js +4 -10
- package/dist/sync/policies/index.js.map +1 -1
- package/dist/sync/scanners/b2.cjs +2 -2
- package/dist/sync/scanners/b2.cjs.map +1 -1
- package/dist/sync/scanners/b2.js +2 -2
- package/dist/sync/scanners/b2.js.map +1 -1
- package/dist/sync/scanners/local.cjs.map +1 -1
- package/dist/sync/scanners/local.js.map +1 -1
- package/dist/sync/synchronizer.cjs +3 -2
- package/dist/sync/synchronizer.cjs.map +1 -1
- package/dist/sync/synchronizer.js +3 -2
- package/dist/sync/synchronizer.js.map +1 -1
- package/dist/types/auth.cjs +4 -0
- package/dist/types/auth.cjs.map +1 -1
- package/dist/types/auth.d.cts +4 -0
- package/dist/types/auth.d.cts.map +1 -1
- package/dist/types/auth.d.ts +4 -0
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +4 -0
- package/dist/types/auth.js.map +1 -1
- package/dist/types/backup.d.cts +80 -0
- package/dist/types/backup.d.cts.map +1 -0
- package/dist/types/backup.d.ts +80 -0
- package/dist/types/backup.d.ts.map +1 -0
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.d.cts +4 -2
- package/dist/types/bucket.d.cts.map +1 -1
- package/dist/types/bucket.d.ts +4 -2
- package/dist/types/bucket.d.ts.map +1 -1
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/download.cjs +62 -0
- package/dist/types/download.cjs.map +1 -0
- package/dist/types/download.d.cts +98 -0
- package/dist/types/download.d.cts.map +1 -1
- package/dist/types/download.d.ts +98 -0
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/download.js +61 -0
- package/dist/types/download.js.map +1 -0
- package/dist/types/encryption.cjs +58 -229
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +32 -0
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +32 -0
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +56 -229
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/errors.cjs +9 -0
- package/dist/types/errors.cjs.map +1 -1
- package/dist/types/errors.d.cts +1 -1
- package/dist/types/errors.d.cts.map +1 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +9 -0
- package/dist/types/errors.js.map +1 -1
- package/dist/types/file.cjs.map +1 -1
- package/dist/types/file.d.cts +15 -2
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +15 -2
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/file.js.map +1 -1
- package/dist/types/ids.cjs +30 -0
- package/dist/types/ids.cjs.map +1 -1
- package/dist/types/ids.d.cts +32 -0
- package/dist/types/ids.d.cts.map +1 -1
- package/dist/types/ids.d.ts +32 -0
- package/dist/types/ids.d.ts.map +1 -1
- package/dist/types/ids.js +28 -1
- package/dist/types/ids.js.map +1 -1
- package/dist/types/index.d.cts +10 -6
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +10 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lock.cjs.map +1 -1
- package/dist/types/lock.d.cts +14 -0
- package/dist/types/lock.d.cts.map +1 -1
- package/dist/types/lock.d.ts +14 -0
- package/dist/types/lock.d.ts.map +1 -1
- package/dist/types/lock.js.map +1 -1
- package/dist/types/notifications.cjs +1 -1
- package/dist/types/notifications.cjs.map +1 -1
- package/dist/types/notifications.d.cts +5 -3
- package/dist/types/notifications.d.cts.map +1 -1
- package/dist/types/notifications.d.ts +5 -3
- package/dist/types/notifications.d.ts.map +1 -1
- package/dist/types/notifications.js +1 -1
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/partner.cjs +32 -0
- package/dist/types/partner.cjs.map +1 -0
- package/dist/types/partner.d.cts +394 -0
- package/dist/types/partner.d.cts.map +1 -0
- package/dist/types/partner.d.ts +394 -0
- package/dist/types/partner.d.ts.map +1 -0
- package/dist/types/partner.js +29 -0
- package/dist/types/partner.js.map +1 -0
- package/dist/types/upload.d.cts +31 -18
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +31 -18
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort-scope.cjs +0 -45
- package/dist/upload/abort-scope.cjs.map +1 -1
- package/dist/upload/abort-scope.d.cts +0 -22
- package/dist/upload/abort-scope.d.cts.map +1 -1
- package/dist/upload/abort-scope.d.ts +0 -22
- package/dist/upload/abort-scope.d.ts.map +1 -1
- package/dist/upload/abort-scope.js +1 -44
- package/dist/upload/abort-scope.js.map +1 -1
- package/dist/upload/finish.cjs +3 -8
- package/dist/upload/finish.cjs.map +1 -1
- package/dist/upload/finish.d.cts.map +1 -1
- package/dist/upload/finish.d.ts.map +1 -1
- package/dist/upload/finish.js +1 -6
- package/dist/upload/finish.js.map +1 -1
- package/dist/upload/large.cjs +5 -1
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +16 -2
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +16 -2
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +5 -1
- package/dist/upload/large.js.map +1 -1
- package/dist/upload/options.cjs.map +1 -1
- package/dist/upload/options.d.cts +12 -0
- package/dist/upload/options.d.cts.map +1 -1
- package/dist/upload/options.d.ts +12 -0
- package/dist/upload/options.d.ts.map +1 -1
- package/dist/upload/options.js.map +1 -1
- package/dist/upload/resume.cjs +2 -1
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +3 -1
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +3 -1
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +2 -1
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +8 -3
- package/dist/upload/retry.cjs.map +1 -1
- package/dist/upload/retry.js +8 -3
- package/dist/upload/retry.js.map +1 -1
- package/dist/upload/single.cjs +2 -1
- package/dist/upload/single.cjs.map +1 -1
- package/dist/upload/single.d.cts +6 -0
- package/dist/upload/single.d.cts.map +1 -1
- package/dist/upload/single.d.ts +6 -0
- package/dist/upload/single.d.ts.map +1 -1
- package/dist/upload/single.js +2 -1
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +6 -4
- package/dist/upload/stream.cjs.map +1 -1
- package/dist/upload/stream.d.cts +6 -0
- package/dist/upload/stream.d.cts.map +1 -1
- package/dist/upload/stream.d.ts +6 -0
- package/dist/upload/stream.d.ts.map +1 -1
- package/dist/upload/stream.js +3 -1
- package/dist/upload/stream.js.map +1 -1
- package/dist/util/abort.cjs +114 -0
- package/dist/util/abort.cjs.map +1 -0
- package/dist/util/abort.d.cts +65 -0
- package/dist/util/abort.d.cts.map +1 -0
- package/dist/util/abort.d.ts +65 -0
- package/dist/util/abort.d.ts.map +1 -0
- package/dist/util/abort.js +109 -0
- package/dist/util/abort.js.map +1 -0
- package/dist/util/defaults.cjs +3 -0
- package/dist/util/defaults.cjs.map +1 -1
- package/dist/util/defaults.d.cts +2 -0
- package/dist/util/defaults.d.cts.map +1 -1
- package/dist/util/defaults.d.ts +2 -0
- package/dist/util/defaults.d.ts.map +1 -1
- package/dist/util/defaults.js +3 -1
- package/dist/util/defaults.js.map +1 -1
- package/dist/util/md5.cjs +211 -0
- package/dist/util/md5.cjs.map +1 -0
- package/dist/util/md5.d.cts +43 -0
- package/dist/util/md5.d.cts.map +1 -0
- package/dist/util/md5.d.ts +43 -0
- package/dist/util/md5.d.ts.map +1 -0
- package/dist/util/md5.js +209 -0
- package/dist/util/md5.js.map +1 -0
- package/dist/util/normalize.cjs +5 -5
- package/dist/util/normalize.cjs.map +1 -1
- package/dist/util/normalize.d.cts +7 -7
- package/dist/util/normalize.d.cts.map +1 -1
- package/dist/util/normalize.d.ts +7 -7
- package/dist/util/normalize.d.ts.map +1 -1
- package/dist/util/normalize.js +5 -5
- package/dist/util/normalize.js.map +1 -1
- package/dist/util/paginator.cjs +7 -1
- package/dist/util/paginator.cjs.map +1 -1
- package/dist/util/paginator.d.cts +3 -1
- package/dist/util/paginator.d.cts.map +1 -1
- package/dist/util/paginator.d.ts +3 -1
- package/dist/util/paginator.d.ts.map +1 -1
- package/dist/util/paginator.js +7 -1
- package/dist/util/paginator.js.map +1 -1
- package/package.json +38 -16
package/dist/types/download.d.ts
CHANGED
|
@@ -1,4 +1,66 @@
|
|
|
1
|
+
import { SseB2Setting, SseCPublicSetting } from './encryption.js';
|
|
1
2
|
import { BucketId, FileId } from './ids.js';
|
|
3
|
+
import { ReadableFileRetention, ReadableLegalHold } from './lock.js';
|
|
4
|
+
/** HTTP response header names returned by B2 download endpoints. */
|
|
5
|
+
export declare const DownloadHeaderName: {
|
|
6
|
+
/** Header carrying the response content disposition. */
|
|
7
|
+
readonly ContentDisposition: "Content-Disposition";
|
|
8
|
+
/** Header carrying the response content language. */
|
|
9
|
+
readonly ContentLanguage: "Content-Language";
|
|
10
|
+
/** Header carrying the response content encoding. */
|
|
11
|
+
readonly ContentEncoding: "Content-Encoding";
|
|
12
|
+
/** Header carrying the response content type. */
|
|
13
|
+
readonly ContentType: "Content-Type";
|
|
14
|
+
/** Header carrying the response cache policy. */
|
|
15
|
+
readonly CacheControl: "Cache-Control";
|
|
16
|
+
/** Header carrying the response expiration time. */
|
|
17
|
+
readonly Expires: "Expires";
|
|
18
|
+
/** Header carrying the byte range returned for partial downloads. */
|
|
19
|
+
readonly ContentRange: "Content-Range";
|
|
20
|
+
/** Header carrying the response content length. */
|
|
21
|
+
readonly ContentLength: "Content-Length";
|
|
22
|
+
/** Header carrying the B2 SHA-1 metadata value. */
|
|
23
|
+
readonly ContentSha1: "X-Bz-Content-Sha1";
|
|
24
|
+
/** Header carrying the downloaded file version ID. */
|
|
25
|
+
readonly FileId: "X-Bz-File-Id";
|
|
26
|
+
/** Header carrying the URL-encoded downloaded file name. */
|
|
27
|
+
readonly FileName: "X-Bz-File-Name";
|
|
28
|
+
/** Header carrying the file upload timestamp. */
|
|
29
|
+
readonly UploadTimestamp: "X-Bz-Upload-Timestamp";
|
|
30
|
+
/** Header carrying the B2-managed server-side encryption algorithm. */
|
|
31
|
+
readonly ServerSideEncryption: "X-Bz-Server-Side-Encryption";
|
|
32
|
+
/** Header carrying the SSE-C algorithm echo. */
|
|
33
|
+
readonly ServerSideEncryptionCustomerAlgorithm: "X-Bz-Server-Side-Encryption-Customer-Algorithm";
|
|
34
|
+
/** Header carrying the SSE-C customer-key MD5 echo. */
|
|
35
|
+
readonly ServerSideEncryptionCustomerKeyMd5: "X-Bz-Server-Side-Encryption-Customer-Key-Md5";
|
|
36
|
+
/** Header carrying the Object Lock retention mode. */
|
|
37
|
+
readonly FileRetentionMode: "X-Bz-File-Retention-Mode";
|
|
38
|
+
/** Header carrying the Object Lock retain-until timestamp. */
|
|
39
|
+
readonly FileRetentionRetainUntilTimestamp: "X-Bz-File-Retention-Retain-Until-Timestamp";
|
|
40
|
+
/** Header carrying the Object Lock legal-hold value. */
|
|
41
|
+
readonly FileLegalHold: "X-Bz-File-Legal-Hold";
|
|
42
|
+
/** Header carrying names of metadata headers hidden by missing capabilities. */
|
|
43
|
+
readonly ClientUnauthorizedToRead: "X-Bz-Client-Unauthorized-To-Read";
|
|
44
|
+
};
|
|
45
|
+
/** HTTP response header name returned by B2 download endpoints. */
|
|
46
|
+
export type DownloadHeaderName = (typeof DownloadHeaderName)[keyof typeof DownloadHeaderName];
|
|
47
|
+
/** Documented download metadata markers B2 may hide when the caller lacks read capabilities. */
|
|
48
|
+
export declare const DownloadClientUnauthorizedToReadMarker: {
|
|
49
|
+
/** B2-managed encryption metadata is hidden. */
|
|
50
|
+
readonly ServerSideEncryption: "X-Bz-Server-Side-Encryption";
|
|
51
|
+
/** SSE-C algorithm metadata is hidden. */
|
|
52
|
+
readonly ServerSideEncryptionCustomerAlgorithm: "X-Bz-Server-Side-Encryption-Customer-Algorithm";
|
|
53
|
+
/** SSE-C customer-key MD5 metadata is hidden. */
|
|
54
|
+
readonly ServerSideEncryptionCustomerKeyMd5: "X-Bz-Server-Side-Encryption-Customer-Key-Md5";
|
|
55
|
+
/** Object Lock retention mode metadata is hidden. */
|
|
56
|
+
readonly FileRetentionMode: "X-Bz-File-Retention-Mode";
|
|
57
|
+
/** Object Lock retain-until timestamp metadata is hidden. */
|
|
58
|
+
readonly FileRetentionRetainUntilTimestamp: "X-Bz-File-Retention-Retain-Until-Timestamp";
|
|
59
|
+
/** Object Lock legal-hold metadata is hidden. */
|
|
60
|
+
readonly FileLegalHold: "X-Bz-File-Legal-Hold";
|
|
61
|
+
};
|
|
62
|
+
/** Documented download metadata marker B2 may hide when the caller lacks read capabilities. */
|
|
63
|
+
export type DownloadClientUnauthorizedToReadMarker = (typeof DownloadClientUnauthorizedToReadMarker)[keyof typeof DownloadClientUnauthorizedToReadMarker];
|
|
2
64
|
/** Request parameters for downloading a file by its ID via `b2_download_file_by_id`. */
|
|
3
65
|
export interface DownloadByIdRequest {
|
|
4
66
|
/** ID of the file version to download. */
|
|
@@ -90,12 +152,38 @@ export interface DownloadAuthorizationResponse {
|
|
|
90
152
|
/** Authorization token to include in download requests. */
|
|
91
153
|
readonly authorizationToken: string;
|
|
92
154
|
}
|
|
155
|
+
/** Customer-managed server-side encryption metadata echoed in B2 download response headers. */
|
|
156
|
+
export interface SseCDownloadSetting extends SseCPublicSetting {
|
|
157
|
+
/** MD5 digest echoed by `X-Bz-Server-Side-Encryption-Customer-Key-Md5`. */
|
|
158
|
+
readonly customerKeyMd5: string;
|
|
159
|
+
}
|
|
160
|
+
/** Server-side encryption metadata echoed in B2 download response headers. */
|
|
161
|
+
export type DownloadServerSideEncryption = SseB2Setting | SseCDownloadSetting;
|
|
162
|
+
/** Diagnostic for a present download metadata header the SDK could not parse narrowly. */
|
|
163
|
+
export interface DownloadHeaderParseIssue {
|
|
164
|
+
/** Header whose value could not be parsed into the current typed SDK model. */
|
|
165
|
+
readonly headerName: DownloadHeaderName;
|
|
166
|
+
/** Raw header value that could not be parsed. */
|
|
167
|
+
readonly value: string;
|
|
168
|
+
}
|
|
93
169
|
/** Parsed headers from a B2 file download response. */
|
|
94
170
|
export interface DownloadHeaders {
|
|
95
171
|
/** MIME type of the downloaded file content. */
|
|
96
172
|
readonly contentType: string;
|
|
97
173
|
/** Size of the downloaded content in bytes. */
|
|
98
174
|
readonly contentLength: number;
|
|
175
|
+
/** Content-Disposition value computed from upload metadata or the download request. */
|
|
176
|
+
readonly contentDisposition?: string;
|
|
177
|
+
/** Content-Language value computed from upload metadata or the download request. */
|
|
178
|
+
readonly contentLanguage?: string;
|
|
179
|
+
/** Content-Encoding value computed from upload metadata or the download request. */
|
|
180
|
+
readonly contentEncoding?: string;
|
|
181
|
+
/** Cache-Control value computed from upload metadata, bucket defaults, or the download request. */
|
|
182
|
+
readonly cacheControl?: string;
|
|
183
|
+
/** Expires value computed from upload metadata or the download request. */
|
|
184
|
+
readonly expires?: string;
|
|
185
|
+
/** Content-Range value returned for satisfiable range downloads. */
|
|
186
|
+
readonly contentRange?: string;
|
|
99
187
|
/** SHA-1 checksum of the full file content, or null for large files. */
|
|
100
188
|
readonly contentSha1: string | null;
|
|
101
189
|
/** ID of the downloaded file version. */
|
|
@@ -106,5 +194,15 @@ export interface DownloadHeaders {
|
|
|
106
194
|
readonly fileInfo: Record<string, string>;
|
|
107
195
|
/** UTC timestamp (milliseconds) when the file was uploaded. */
|
|
108
196
|
readonly uploadTimestamp: number;
|
|
197
|
+
/** Server-side encryption metadata echoed by B2, when the caller is authorized to read it. */
|
|
198
|
+
readonly serverSideEncryption?: DownloadServerSideEncryption;
|
|
199
|
+
/** Object Lock retention metadata, including whether the caller may read it. */
|
|
200
|
+
readonly fileRetention?: ReadableFileRetention;
|
|
201
|
+
/** Object Lock legal hold metadata, including whether the caller may read it. */
|
|
202
|
+
readonly legalHold?: ReadableLegalHold;
|
|
203
|
+
/** Header names B2 omitted because the caller lacks capability to read them. */
|
|
204
|
+
readonly clientUnauthorizedToRead?: readonly DownloadClientUnauthorizedToReadMarker[];
|
|
205
|
+
/** Present metadata headers the SDK could not parse into its current narrow typed model. */
|
|
206
|
+
readonly headerParseIssues?: readonly DownloadHeaderParseIssue[];
|
|
109
207
|
}
|
|
110
208
|
//# sourceMappingURL=download.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/types/download.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/types/download.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAEzE,oEAAoE;AACpE,eAAO,MAAM,kBAAkB;IAC7B,wDAAwD;;IAExD,qDAAqD;;IAErD,qDAAqD;;IAErD,iDAAiD;;IAEjD,iDAAiD;;IAEjD,oDAAoD;;IAEpD,qEAAqE;;IAErE,mDAAmD;;IAEnD,mDAAmD;;IAEnD,sDAAsD;;IAEtD,4DAA4D;;IAE5D,iDAAiD;;IAEjD,uEAAuE;;IAEvE,gDAAgD;;IAEhD,uDAAuD;;IAEvD,sDAAsD;;IAEtD,8DAA8D;;IAE9D,wDAAwD;;IAExD,gFAAgF;;CAExE,CAAA;AAEV,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAA;AAE7F,gGAAgG;AAChG,eAAO,MAAM,sCAAsC;IACjD,gDAAgD;;IAEhD,0CAA0C;;IAE1C,iDAAiD;;IAEjD,qDAAqD;;IAErD,6DAA6D;;IAE7D,iDAAiD;;CAEzC,CAAA;AAEV,+FAA+F;AAC/F,MAAM,MAAM,sCAAsC,GAChD,CAAC,OAAO,sCAAsC,CAAC,CAAC,MAAM,OAAO,s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MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,oBAAoB,CAAC,EAAE,4BAA4B,CAAA;IAC5D,gFAAgF;IAChF,QAAQ,CAAC,aAAa,CAAC,EAAE,qBAAqB,CAAA;IAC9C,iFAAiF;IACjF,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAA;IACtC,gFAAgF;IAChF,QAAQ,CAAC,wBAAwB,CAAC,EAAE,SAAS,sCAAsC,EAAE,CAAA;IACrF,4FAA4F;IAC5F,QAAQ,CAAC,iBAAiB,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAA;CACjE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//#region src/types/download.ts
|
|
2
|
+
/** HTTP response header names returned by B2 download endpoints. */
|
|
3
|
+
var DownloadHeaderName = {
|
|
4
|
+
/** Header carrying the response content disposition. */
|
|
5
|
+
ContentDisposition: "Content-Disposition",
|
|
6
|
+
/** Header carrying the response content language. */
|
|
7
|
+
ContentLanguage: "Content-Language",
|
|
8
|
+
/** Header carrying the response content encoding. */
|
|
9
|
+
ContentEncoding: "Content-Encoding",
|
|
10
|
+
/** Header carrying the response content type. */
|
|
11
|
+
ContentType: "Content-Type",
|
|
12
|
+
/** Header carrying the response cache policy. */
|
|
13
|
+
CacheControl: "Cache-Control",
|
|
14
|
+
/** Header carrying the response expiration time. */
|
|
15
|
+
Expires: "Expires",
|
|
16
|
+
/** Header carrying the byte range returned for partial downloads. */
|
|
17
|
+
ContentRange: "Content-Range",
|
|
18
|
+
/** Header carrying the response content length. */
|
|
19
|
+
ContentLength: "Content-Length",
|
|
20
|
+
/** Header carrying the B2 SHA-1 metadata value. */
|
|
21
|
+
ContentSha1: "X-Bz-Content-Sha1",
|
|
22
|
+
/** Header carrying the downloaded file version ID. */
|
|
23
|
+
FileId: "X-Bz-File-Id",
|
|
24
|
+
/** Header carrying the URL-encoded downloaded file name. */
|
|
25
|
+
FileName: "X-Bz-File-Name",
|
|
26
|
+
/** Header carrying the file upload timestamp. */
|
|
27
|
+
UploadTimestamp: "X-Bz-Upload-Timestamp",
|
|
28
|
+
/** Header carrying the B2-managed server-side encryption algorithm. */
|
|
29
|
+
ServerSideEncryption: "X-Bz-Server-Side-Encryption",
|
|
30
|
+
/** Header carrying the SSE-C algorithm echo. */
|
|
31
|
+
ServerSideEncryptionCustomerAlgorithm: "X-Bz-Server-Side-Encryption-Customer-Algorithm",
|
|
32
|
+
/** Header carrying the SSE-C customer-key MD5 echo. */
|
|
33
|
+
ServerSideEncryptionCustomerKeyMd5: "X-Bz-Server-Side-Encryption-Customer-Key-Md5",
|
|
34
|
+
/** Header carrying the Object Lock retention mode. */
|
|
35
|
+
FileRetentionMode: "X-Bz-File-Retention-Mode",
|
|
36
|
+
/** Header carrying the Object Lock retain-until timestamp. */
|
|
37
|
+
FileRetentionRetainUntilTimestamp: "X-Bz-File-Retention-Retain-Until-Timestamp",
|
|
38
|
+
/** Header carrying the Object Lock legal-hold value. */
|
|
39
|
+
FileLegalHold: "X-Bz-File-Legal-Hold",
|
|
40
|
+
/** Header carrying names of metadata headers hidden by missing capabilities. */
|
|
41
|
+
ClientUnauthorizedToRead: "X-Bz-Client-Unauthorized-To-Read"
|
|
42
|
+
};
|
|
43
|
+
/** Documented download metadata markers B2 may hide when the caller lacks read capabilities. */
|
|
44
|
+
var DownloadClientUnauthorizedToReadMarker = {
|
|
45
|
+
/** B2-managed encryption metadata is hidden. */
|
|
46
|
+
ServerSideEncryption: DownloadHeaderName.ServerSideEncryption,
|
|
47
|
+
/** SSE-C algorithm metadata is hidden. */
|
|
48
|
+
ServerSideEncryptionCustomerAlgorithm: DownloadHeaderName.ServerSideEncryptionCustomerAlgorithm,
|
|
49
|
+
/** SSE-C customer-key MD5 metadata is hidden. */
|
|
50
|
+
ServerSideEncryptionCustomerKeyMd5: DownloadHeaderName.ServerSideEncryptionCustomerKeyMd5,
|
|
51
|
+
/** Object Lock retention mode metadata is hidden. */
|
|
52
|
+
FileRetentionMode: DownloadHeaderName.FileRetentionMode,
|
|
53
|
+
/** Object Lock retain-until timestamp metadata is hidden. */
|
|
54
|
+
FileRetentionRetainUntilTimestamp: DownloadHeaderName.FileRetentionRetainUntilTimestamp,
|
|
55
|
+
/** Object Lock legal-hold metadata is hidden. */
|
|
56
|
+
FileLegalHold: DownloadHeaderName.FileLegalHold
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { DownloadClientUnauthorizedToReadMarker, DownloadHeaderName };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","names":[],"sources":["../../src/types/download.ts"],"sourcesContent":["import type { SseB2Setting, SseCPublicSetting } from './encryption.ts'\nimport type { BucketId, FileId } from './ids.ts'\nimport type { ReadableFileRetention, ReadableLegalHold } from './lock.ts'\n\n/** HTTP response header names returned by B2 download endpoints. */\nexport const DownloadHeaderName = {\n /** Header carrying the response content disposition. */\n ContentDisposition: 'Content-Disposition',\n /** Header carrying the response content language. */\n ContentLanguage: 'Content-Language',\n /** Header carrying the response content encoding. */\n ContentEncoding: 'Content-Encoding',\n /** Header carrying the response content type. */\n ContentType: 'Content-Type',\n /** Header carrying the response cache policy. */\n CacheControl: 'Cache-Control',\n /** Header carrying the response expiration time. */\n Expires: 'Expires',\n /** Header carrying the byte range returned for partial downloads. */\n ContentRange: 'Content-Range',\n /** Header carrying the response content length. */\n ContentLength: 'Content-Length',\n /** Header carrying the B2 SHA-1 metadata value. */\n ContentSha1: 'X-Bz-Content-Sha1',\n /** Header carrying the downloaded file version ID. */\n FileId: 'X-Bz-File-Id',\n /** Header carrying the URL-encoded downloaded file name. */\n FileName: 'X-Bz-File-Name',\n /** Header carrying the file upload timestamp. */\n UploadTimestamp: 'X-Bz-Upload-Timestamp',\n /** Header carrying the B2-managed server-side encryption algorithm. */\n ServerSideEncryption: 'X-Bz-Server-Side-Encryption',\n /** Header carrying the SSE-C algorithm echo. */\n ServerSideEncryptionCustomerAlgorithm: 'X-Bz-Server-Side-Encryption-Customer-Algorithm',\n /** Header carrying the SSE-C customer-key MD5 echo. */\n ServerSideEncryptionCustomerKeyMd5: 'X-Bz-Server-Side-Encryption-Customer-Key-Md5',\n /** Header carrying the Object Lock retention mode. */\n FileRetentionMode: 'X-Bz-File-Retention-Mode',\n /** Header carrying the Object Lock retain-until timestamp. */\n FileRetentionRetainUntilTimestamp: 'X-Bz-File-Retention-Retain-Until-Timestamp',\n /** Header carrying the Object Lock legal-hold value. */\n FileLegalHold: 'X-Bz-File-Legal-Hold',\n /** Header carrying names of metadata headers hidden by missing capabilities. */\n ClientUnauthorizedToRead: 'X-Bz-Client-Unauthorized-To-Read',\n} as const\n\n/** HTTP response header name returned by B2 download endpoints. */\nexport type DownloadHeaderName = (typeof DownloadHeaderName)[keyof typeof DownloadHeaderName]\n\n/** Documented download metadata markers B2 may hide when the caller lacks read capabilities. */\nexport const DownloadClientUnauthorizedToReadMarker = {\n /** B2-managed encryption metadata is hidden. */\n ServerSideEncryption: DownloadHeaderName.ServerSideEncryption,\n /** SSE-C algorithm metadata is hidden. */\n ServerSideEncryptionCustomerAlgorithm: DownloadHeaderName.ServerSideEncryptionCustomerAlgorithm,\n /** SSE-C customer-key MD5 metadata is hidden. */\n ServerSideEncryptionCustomerKeyMd5: DownloadHeaderName.ServerSideEncryptionCustomerKeyMd5,\n /** Object Lock retention mode metadata is hidden. */\n FileRetentionMode: DownloadHeaderName.FileRetentionMode,\n /** Object Lock retain-until timestamp metadata is hidden. */\n FileRetentionRetainUntilTimestamp: DownloadHeaderName.FileRetentionRetainUntilTimestamp,\n /** Object Lock legal-hold metadata is hidden. */\n FileLegalHold: DownloadHeaderName.FileLegalHold,\n} as const\n\n/** Documented download metadata marker B2 may hide when the caller lacks read capabilities. */\nexport type DownloadClientUnauthorizedToReadMarker =\n (typeof DownloadClientUnauthorizedToReadMarker)[keyof typeof DownloadClientUnauthorizedToReadMarker]\n\n/** Request parameters for downloading a file by its ID via `b2_download_file_by_id`. */\nexport interface DownloadByIdRequest {\n /** ID of the file version to download. */\n readonly fileId: FileId\n /** Optional byte range to download (e.g., `'bytes=0-999'`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: {\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: 'AES256'\n /** Base64-encoded customer-provided decryption key. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the decryption key. */\n readonly customerKeyMd5: string\n }\n /** Override the Content-Disposition header in the download response. */\n readonly b2ContentDisposition?: string\n /** Override the Content-Language header in the download response. */\n readonly b2ContentLanguage?: string\n /** Override the Content-Encoding header in the download response. */\n readonly b2ContentEncoding?: string\n /** Override the Content-Type header in the download response. */\n readonly b2ContentType?: string\n /** Override the Cache-Control header in the download response. */\n readonly b2CacheControl?: string\n /** Override the Expires header in the download response. */\n readonly b2Expires?: string\n}\n\n/** Request parameters for downloading a file by bucket name and file name via `b2_download_file_by_name`. */\nexport interface DownloadByNameRequest {\n /** Name of the bucket containing the file. */\n readonly bucketName: string\n /** Full path and name of the file within the bucket. */\n readonly fileName: string\n /** Optional byte range to download (e.g., `'bytes=0-999'`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: {\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: 'AES256'\n /** Base64-encoded customer-provided decryption key. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the decryption key. */\n readonly customerKeyMd5: string\n }\n /** Override the Content-Disposition header in the download response. */\n readonly b2ContentDisposition?: string\n /** Override the Content-Language header in the download response. */\n readonly b2ContentLanguage?: string\n /** Override the Content-Encoding header in the download response. */\n readonly b2ContentEncoding?: string\n /** Override the Content-Type header in the download response. */\n readonly b2ContentType?: string\n /** Override the Cache-Control header in the download response. */\n readonly b2CacheControl?: string\n /** Override the Expires header in the download response. */\n readonly b2Expires?: string\n}\n\n/**\n * Request parameters for the `b2_get_download_authorization` API call.\n * Creates a time-limited token that authorizes downloads of files matching a prefix.\n */\nexport interface DownloadAuthorizationRequest {\n /** Bucket to authorize downloads from. */\n readonly bucketId: BucketId\n /** Only files with names starting with this prefix are authorized. */\n readonly fileNamePrefix: string\n /** Duration in seconds that the authorization token remains valid. */\n readonly validDurationInSeconds: number\n /** Override the Content-Disposition header in authorized download responses. */\n readonly b2ContentDisposition?: string\n /** Override the Content-Language header in authorized download responses. */\n readonly b2ContentLanguage?: string\n /** Override the Content-Encoding header in authorized download responses. */\n readonly b2ContentEncoding?: string\n /** Override the Content-Type header in authorized download responses. */\n readonly b2ContentType?: string\n /** Override the Cache-Control header in authorized download responses. */\n readonly b2CacheControl?: string\n /** Override the Expires header in authorized download responses. */\n readonly b2Expires?: string\n}\n\n/** Response from the `b2_get_download_authorization` API call. */\nexport interface DownloadAuthorizationResponse {\n /** Bucket the authorization applies to. */\n readonly bucketId: BucketId\n /** File name prefix the authorization is scoped to. */\n readonly fileNamePrefix: string\n /** Authorization token to include in download requests. */\n readonly authorizationToken: string\n}\n\n/** Customer-managed server-side encryption metadata echoed in B2 download response headers. */\nexport interface SseCDownloadSetting extends SseCPublicSetting {\n /** MD5 digest echoed by `X-Bz-Server-Side-Encryption-Customer-Key-Md5`. */\n readonly customerKeyMd5: string\n}\n\n/** Server-side encryption metadata echoed in B2 download response headers. */\nexport type DownloadServerSideEncryption = SseB2Setting | SseCDownloadSetting\n\n/** Diagnostic for a present download metadata header the SDK could not parse narrowly. */\nexport interface DownloadHeaderParseIssue {\n /** Header whose value could not be parsed into the current typed SDK model. */\n readonly headerName: DownloadHeaderName\n /** Raw header value that could not be parsed. */\n readonly value: string\n}\n\n/** Parsed headers from a B2 file download response. */\nexport interface DownloadHeaders {\n /** MIME type of the downloaded file content. */\n readonly contentType: string\n /** Size of the downloaded content in bytes. */\n readonly contentLength: number\n /** Content-Disposition value computed from upload metadata or the download request. */\n readonly contentDisposition?: string\n /** Content-Language value computed from upload metadata or the download request. */\n readonly contentLanguage?: string\n /** Content-Encoding value computed from upload metadata or the download request. */\n readonly contentEncoding?: string\n /** Cache-Control value computed from upload metadata, bucket defaults, or the download request. */\n readonly cacheControl?: string\n /** Expires value computed from upload metadata or the download request. */\n readonly expires?: string\n /** Content-Range value returned for satisfiable range downloads. */\n readonly contentRange?: string\n /** SHA-1 checksum of the full file content, or null for large files. */\n readonly contentSha1: string | null\n /** ID of the downloaded file version. */\n readonly fileId: FileId\n /** Full path and name of the downloaded file. */\n readonly fileName: string\n /** User-defined key-value metadata stored with the file. */\n readonly fileInfo: Record<string, string>\n /** UTC timestamp (milliseconds) when the file was uploaded. */\n readonly uploadTimestamp: number\n /** Server-side encryption metadata echoed by B2, when the caller is authorized to read it. */\n readonly serverSideEncryption?: DownloadServerSideEncryption\n /** Object Lock retention metadata, including whether the caller may read it. */\n readonly fileRetention?: ReadableFileRetention\n /** Object Lock legal hold metadata, including whether the caller may read it. */\n readonly legalHold?: ReadableLegalHold\n /** Header names B2 omitted because the caller lacks capability to read them. */\n readonly clientUnauthorizedToRead?: readonly DownloadClientUnauthorizedToReadMarker[]\n /** Present metadata headers the SDK could not parse into its current narrow typed model. */\n readonly headerParseIssues?: readonly DownloadHeaderParseIssue[]\n}\n"],"mappings":";;AAKA,IAAa,qBAAqB;;CAEhC,oBAAoB;;CAEpB,iBAAiB;;CAEjB,iBAAiB;;CAEjB,aAAa;;CAEb,cAAc;;CAEd,SAAS;;CAET,cAAc;;CAEd,eAAe;;CAEf,aAAa;;CAEb,QAAQ;;CAER,UAAU;;CAEV,iBAAiB;;CAEjB,sBAAsB;;CAEtB,uCAAuC;;CAEvC,oCAAoC;;CAEpC,mBAAmB;;CAEnB,mCAAmC;;CAEnC,eAAe;;CAEf,0BAA0B;AAC5B;;AAMA,IAAa,yCAAyC;;CAEpD,sBAAsB,mBAAmB;;CAEzC,uCAAuC,mBAAmB;;CAE1D,oCAAoC,mBAAmB;;CAEvD,mBAAmB,mBAAmB;;CAEtC,mCAAmC,mBAAmB;;CAEtD,eAAe,mBAAmB;AACpC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_md5 = require("../util/md5.cjs");
|
|
1
2
|
//#region src/types/encryption.ts
|
|
2
3
|
/** Named constants for the supported server-side encryption algorithms. */
|
|
3
4
|
var EncryptionAlgorithm = {
|
|
@@ -56,233 +57,61 @@ function bytesToBase64(bytes) {
|
|
|
56
57
|
for (const b of bytes) binary += String.fromCharCode(b);
|
|
57
58
|
return btoa(binary);
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
* @returns The base64-encoded MD5 digest.
|
|
73
|
-
*/
|
|
74
|
-
async function md5Base64(bytes) {
|
|
75
|
-
try {
|
|
76
|
-
const { createHash } = await import("node:crypto");
|
|
77
|
-
if (typeof createHash !== "function") throw new Error("createHash unavailable");
|
|
78
|
-
return createHash("md5").update(bytes).digest("base64");
|
|
79
|
-
} catch {
|
|
80
|
-
return bytesToBase64(md5Bytes(bytes));
|
|
81
|
-
}
|
|
60
|
+
var SSE_C_KEY_REDACTION = "[redacted SSE-C key]";
|
|
61
|
+
var NODE_INSPECT_CUSTOM = Symbol.for("nodejs.util.inspect.custom");
|
|
62
|
+
function sseCKeyRedactedJson(key, options) {
|
|
63
|
+
return {
|
|
64
|
+
...options.mode !== void 0 ? { mode: options.mode } : {},
|
|
65
|
+
algorithm: key.algorithm,
|
|
66
|
+
customerKey: SSE_C_KEY_REDACTION,
|
|
67
|
+
customerKeyMd5: SSE_C_KEY_REDACTION
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function sseCKeyRedactedString(options) {
|
|
71
|
+
return `[${options.label} ${SSE_C_KEY_REDACTION}]`;
|
|
82
72
|
}
|
|
83
73
|
/**
|
|
84
|
-
*
|
|
85
|
-
* input. Used as a browser fallback for SSE-C key MD5 computation; not
|
|
86
|
-
* intended for security-sensitive purposes (MD5 is broken cryptographically).
|
|
74
|
+
* Wraps SSE-C key material so diagnostic stringification redacts key fields.
|
|
87
75
|
*
|
|
88
|
-
*
|
|
76
|
+
* The returned object keeps `customerKey` and `customerKeyMd5` readable by
|
|
77
|
+
* property access for request header construction, but makes them
|
|
78
|
+
* non-enumerable so object spread and generic serializers do not copy them.
|
|
79
|
+
* Callers that need wire headers must read those fields directly.
|
|
89
80
|
*
|
|
90
|
-
* @
|
|
81
|
+
* @param key - SSE-C key material to wrap.
|
|
82
|
+
* @param options - Redaction label and optional encryption mode discriminator.
|
|
83
|
+
*
|
|
84
|
+
* @returns A redacted view with the same readable key fields.
|
|
91
85
|
*/
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
12,
|
|
114
|
-
17,
|
|
115
|
-
22,
|
|
116
|
-
7,
|
|
117
|
-
12,
|
|
118
|
-
17,
|
|
119
|
-
22,
|
|
120
|
-
5,
|
|
121
|
-
9,
|
|
122
|
-
14,
|
|
123
|
-
20,
|
|
124
|
-
5,
|
|
125
|
-
9,
|
|
126
|
-
14,
|
|
127
|
-
20,
|
|
128
|
-
5,
|
|
129
|
-
9,
|
|
130
|
-
14,
|
|
131
|
-
20,
|
|
132
|
-
5,
|
|
133
|
-
9,
|
|
134
|
-
14,
|
|
135
|
-
20,
|
|
136
|
-
4,
|
|
137
|
-
11,
|
|
138
|
-
16,
|
|
139
|
-
23,
|
|
140
|
-
4,
|
|
141
|
-
11,
|
|
142
|
-
16,
|
|
143
|
-
23,
|
|
144
|
-
4,
|
|
145
|
-
11,
|
|
146
|
-
16,
|
|
147
|
-
23,
|
|
148
|
-
4,
|
|
149
|
-
11,
|
|
150
|
-
16,
|
|
151
|
-
23,
|
|
152
|
-
6,
|
|
153
|
-
10,
|
|
154
|
-
15,
|
|
155
|
-
21,
|
|
156
|
-
6,
|
|
157
|
-
10,
|
|
158
|
-
15,
|
|
159
|
-
21,
|
|
160
|
-
6,
|
|
161
|
-
10,
|
|
162
|
-
15,
|
|
163
|
-
21,
|
|
164
|
-
6,
|
|
165
|
-
10,
|
|
166
|
-
15,
|
|
167
|
-
21
|
|
168
|
-
];
|
|
169
|
-
const k = new Uint32Array([
|
|
170
|
-
3614090360,
|
|
171
|
-
3905402710,
|
|
172
|
-
606105819,
|
|
173
|
-
3250441966,
|
|
174
|
-
4118548399,
|
|
175
|
-
1200080426,
|
|
176
|
-
2821735955,
|
|
177
|
-
4249261313,
|
|
178
|
-
1770035416,
|
|
179
|
-
2336552879,
|
|
180
|
-
4294925233,
|
|
181
|
-
2304563134,
|
|
182
|
-
1804603682,
|
|
183
|
-
4254626195,
|
|
184
|
-
2792965006,
|
|
185
|
-
1236535329,
|
|
186
|
-
4129170786,
|
|
187
|
-
3225465664,
|
|
188
|
-
643717713,
|
|
189
|
-
3921069994,
|
|
190
|
-
3593408605,
|
|
191
|
-
38016083,
|
|
192
|
-
3634488961,
|
|
193
|
-
3889429448,
|
|
194
|
-
568446438,
|
|
195
|
-
3275163606,
|
|
196
|
-
4107603335,
|
|
197
|
-
1163531501,
|
|
198
|
-
2850285829,
|
|
199
|
-
4243563512,
|
|
200
|
-
1735328473,
|
|
201
|
-
2368359562,
|
|
202
|
-
4294588738,
|
|
203
|
-
2272392833,
|
|
204
|
-
1839030562,
|
|
205
|
-
4259657740,
|
|
206
|
-
2763975236,
|
|
207
|
-
1272893353,
|
|
208
|
-
4139469664,
|
|
209
|
-
3200236656,
|
|
210
|
-
681279174,
|
|
211
|
-
3936430074,
|
|
212
|
-
3572445317,
|
|
213
|
-
76029189,
|
|
214
|
-
3654602809,
|
|
215
|
-
3873151461,
|
|
216
|
-
530742520,
|
|
217
|
-
3299628645,
|
|
218
|
-
4096336452,
|
|
219
|
-
1126891415,
|
|
220
|
-
2878612391,
|
|
221
|
-
4237533241,
|
|
222
|
-
1700485571,
|
|
223
|
-
2399980690,
|
|
224
|
-
4293915773,
|
|
225
|
-
2240044497,
|
|
226
|
-
1873313359,
|
|
227
|
-
4264355552,
|
|
228
|
-
2734768916,
|
|
229
|
-
1309151649,
|
|
230
|
-
4149444226,
|
|
231
|
-
3174756917,
|
|
232
|
-
718787259,
|
|
233
|
-
3951481745
|
|
234
|
-
]);
|
|
235
|
-
let a0 = 1732584193;
|
|
236
|
-
let b0 = 4023233417;
|
|
237
|
-
let c0 = 2562383102;
|
|
238
|
-
let d0 = 271733878;
|
|
239
|
-
const m = /* @__PURE__ */ new Uint32Array(16);
|
|
240
|
-
const view = new DataView(padded.buffer);
|
|
241
|
-
for (let block = 0; block < padded.byteLength; block += 64) {
|
|
242
|
-
for (let i = 0; i < 16; i++) m[i] = view.getUint32(block + i * 4, true);
|
|
243
|
-
let A = a0;
|
|
244
|
-
let B = b0;
|
|
245
|
-
let C = c0;
|
|
246
|
-
let D = d0;
|
|
247
|
-
for (let i = 0; i < 64; i++) {
|
|
248
|
-
let f;
|
|
249
|
-
let g;
|
|
250
|
-
if (i < 16) {
|
|
251
|
-
f = B & C | ~B & D;
|
|
252
|
-
g = i;
|
|
253
|
-
} else if (i < 32) {
|
|
254
|
-
f = D & B | ~D & C;
|
|
255
|
-
g = (5 * i + 1) % 16;
|
|
256
|
-
} else if (i < 48) {
|
|
257
|
-
f = B ^ C ^ D;
|
|
258
|
-
g = (3 * i + 5) % 16;
|
|
259
|
-
} else {
|
|
260
|
-
f = C ^ (B | ~D);
|
|
261
|
-
g = 7 * i % 16;
|
|
262
|
-
}
|
|
263
|
-
const temp = D;
|
|
264
|
-
D = C;
|
|
265
|
-
C = B;
|
|
266
|
-
const sum = A + f + (k[i] ?? 0) + (m[g] ?? 0) >>> 0;
|
|
267
|
-
const shift = s[i] ?? 0;
|
|
268
|
-
const rotated = (sum << shift | sum >>> 32 - shift) >>> 0;
|
|
269
|
-
B = B + rotated >>> 0;
|
|
270
|
-
A = temp;
|
|
86
|
+
function redactSseCKeyMaterial(key, options) {
|
|
87
|
+
const redacted = {
|
|
88
|
+
...options.mode !== void 0 ? { mode: options.mode } : {},
|
|
89
|
+
algorithm: key.algorithm
|
|
90
|
+
};
|
|
91
|
+
Object.defineProperties(redacted, {
|
|
92
|
+
customerKey: {
|
|
93
|
+
value: key.customerKey,
|
|
94
|
+
enumerable: false
|
|
95
|
+
},
|
|
96
|
+
customerKeyMd5: {
|
|
97
|
+
value: key.customerKeyMd5,
|
|
98
|
+
enumerable: false
|
|
99
|
+
},
|
|
100
|
+
toJSON: {
|
|
101
|
+
value: () => sseCKeyRedactedJson(key, options),
|
|
102
|
+
enumerable: false
|
|
103
|
+
},
|
|
104
|
+
toString: {
|
|
105
|
+
value: () => sseCKeyRedactedString(options),
|
|
106
|
+
enumerable: false
|
|
271
107
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const outView = new DataView(out.buffer);
|
|
279
|
-
outView.setUint32(0, a0, true);
|
|
280
|
-
outView.setUint32(4, b0, true);
|
|
281
|
-
outView.setUint32(8, c0, true);
|
|
282
|
-
outView.setUint32(12, d0, true);
|
|
283
|
-
return out;
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(redacted, NODE_INSPECT_CUSTOM, {
|
|
110
|
+
value: () => sseCKeyRedactedString(options),
|
|
111
|
+
enumerable: false
|
|
112
|
+
});
|
|
113
|
+
return redacted;
|
|
284
114
|
}
|
|
285
|
-
var KEY_REDACTED = "[redacted SSE-C key]";
|
|
286
115
|
/**
|
|
287
116
|
* Safe wrapper around an SSE-C customer key. Hides the key bytes from
|
|
288
117
|
* `JSON.stringify`, `console.log`, and Node's `util.inspect`. Use {@link EncryptionKey.fromBytes}
|
|
@@ -323,7 +152,7 @@ var EncryptionKey = class EncryptionKey {
|
|
|
323
152
|
static async fromBytes(rawKey) {
|
|
324
153
|
if (rawKey.byteLength !== 32) throw new Error(`SSE-C key must be exactly 32 bytes (256 bits); got ${rawKey.byteLength}.`);
|
|
325
154
|
const customerKey = bytesToBase64(rawKey);
|
|
326
|
-
const customerKeyMd5 = await md5Base64(rawKey);
|
|
155
|
+
const customerKeyMd5 = await require_md5.md5Base64(rawKey);
|
|
327
156
|
return new EncryptionKey(customerKey, customerKeyMd5);
|
|
328
157
|
}
|
|
329
158
|
/**
|
|
@@ -345,12 +174,10 @@ var EncryptionKey = class EncryptionKey {
|
|
|
345
174
|
* replaced with a placeholder string.
|
|
346
175
|
*/
|
|
347
176
|
toJSON() {
|
|
348
|
-
return {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
customerKeyMd5: KEY_REDACTED
|
|
353
|
-
};
|
|
177
|
+
return sseCKeyRedactedJson(this, {
|
|
178
|
+
label: "EncryptionKey SSE-C",
|
|
179
|
+
mode: this.mode
|
|
180
|
+
});
|
|
354
181
|
}
|
|
355
182
|
/**
|
|
356
183
|
* Hides the key bytes from default `toString()`.
|
|
@@ -358,14 +185,14 @@ var EncryptionKey = class EncryptionKey {
|
|
|
358
185
|
* @returns A short opaque label indicating this is an SSE-C key.
|
|
359
186
|
*/
|
|
360
187
|
toString() {
|
|
361
|
-
return
|
|
188
|
+
return sseCKeyRedactedString({ label: "EncryptionKey SSE-C" });
|
|
362
189
|
}
|
|
363
190
|
/**
|
|
364
191
|
* Hides the key bytes from Node's `util.inspect` (and therefore `console.log`).
|
|
365
192
|
*
|
|
366
193
|
* @returns A short opaque label indicating this is an SSE-C key.
|
|
367
194
|
*/
|
|
368
|
-
[
|
|
195
|
+
[NODE_INSPECT_CUSTOM]() {
|
|
369
196
|
return this.toString();
|
|
370
197
|
}
|
|
371
198
|
};
|
|
@@ -374,7 +201,9 @@ exports.EncryptionAlgorithm = EncryptionAlgorithm;
|
|
|
374
201
|
exports.EncryptionKey = EncryptionKey;
|
|
375
202
|
exports.EncryptionMode = EncryptionMode;
|
|
376
203
|
exports.SSE_B2 = SSE_B2;
|
|
204
|
+
exports.SSE_C_KEY_REDACTION = SSE_C_KEY_REDACTION;
|
|
377
205
|
exports.SSE_NONE = SSE_NONE;
|
|
206
|
+
exports.redactSseCKeyMaterial = redactSseCKeyMaterial;
|
|
378
207
|
exports.sseCustomer = sseCustomer;
|
|
379
208
|
|
|
380
209
|
//# sourceMappingURL=encryption.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.cjs","names":[],"sources":["../../src/types/encryption.ts"],"sourcesContent":["/** Named constants for the supported server-side encryption algorithms. */\nexport const EncryptionAlgorithm = {\n /** AES with a 256-bit key. The only algorithm B2 currently supports. */\n Aes256: 'AES256',\n} as const\n\n/** Supported server-side encryption algorithm. Derived from {@link EncryptionAlgorithm}. */\nexport type EncryptionAlgorithm = (typeof EncryptionAlgorithm)[keyof typeof EncryptionAlgorithm]\n\n/**\n * Named constants for the server-side encryption mode used by a file.\n *\n * Most callers should use the {@link SSE_B2}, {@link SSE_NONE}, and\n * {@link sseCustomer} helpers below which return complete\n * {@link EncryptionSetting} objects. These constants are useful when you\n * need the bare mode discriminator (e.g., when introspecting a file's\n * current encryption setting).\n */\nexport const EncryptionMode = {\n /** B2-managed encryption keys. */\n SseB2: 'SSE-B2',\n /** Customer-provided encryption keys. */\n SseC: 'SSE-C',\n /** No encryption. */\n None: 'none',\n} as const\n\n/** Server-side encryption mode for files stored in B2. Derived from {@link EncryptionMode}. */\nexport type EncryptionMode = (typeof EncryptionMode)[keyof typeof EncryptionMode]\n\n/** Server-side encryption using B2-managed keys (SSE-B2). */\nexport interface SseB2Setting {\n /** Encryption mode discriminator. Always `'SSE-B2'`. */\n readonly mode: 'SSE-B2'\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: EncryptionAlgorithm\n}\n\n/** Server-side encryption using customer-provided keys (SSE-C). */\nexport interface SseCCustomerSetting {\n /** Encryption mode discriminator. Always `'SSE-C'`. */\n readonly mode: 'SSE-C'\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: EncryptionAlgorithm\n /** Base64-encoded 256-bit encryption key provided by the customer. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the customer-provided key, used for integrity verification. */\n readonly customerKeyMd5: string\n}\n\n/** Server-side encryption using customer-provided keys as returned by B2 responses. */\nexport interface SseCPublicSetting {\n /** Encryption mode discriminator. Always `'SSE-C'`. */\n readonly mode: 'SSE-C'\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: EncryptionAlgorithm\n}\n\n/** Indicates no server-side encryption is applied. */\nexport interface NoEncryption {\n /** Encryption mode discriminator. Always `'none'`. */\n readonly mode: 'none'\n}\n\n/** No-encryption shape returned by B2 response objects. */\nexport interface NoEncryptionWireSetting {\n /** Encryption mode discriminator. B2 response payloads use null for no encryption. */\n readonly mode: null\n /** Encryption algorithm. B2 response payloads use null when no encryption is applied. */\n readonly algorithm: null\n}\n\n/** Union of all server-side encryption settings: B2-managed, customer-provided, or none. */\nexport type EncryptionSetting = SseB2Setting | SseCCustomerSetting | NoEncryption\n\n/** Server-side encryption setting returned by B2 response objects. */\nexport type PublicEncryptionSetting =\n | SseB2Setting\n | SseCPublicSetting\n | NoEncryption\n | NoEncryptionWireSetting\n\n/** Pre-built SSE-B2 encryption setting using AES-256. */\nexport const SSE_B2: SseB2Setting = { mode: 'SSE-B2', algorithm: 'AES256' }\n\n/** Pre-built setting indicating no server-side encryption. */\nexport const SSE_NONE: NoEncryption = { mode: 'none' }\n\n/**\n * Creates an SSE-C encryption setting with a customer-provided key.\n * @param customerKey - Base64-encoded 256-bit encryption key.\n * @param customerKeyMd5 - Base64-encoded MD5 digest of the key.\n *\n * @returns An SSE-C encryption setting ready to pass to upload or download calls.\n */\nexport function sseCustomer(customerKey: string, customerKeyMd5: string): SseCCustomerSetting {\n return { mode: 'SSE-C', algorithm: 'AES256', customerKey, customerKeyMd5 }\n}\n\n/**\n * Encodes raw bytes as base64 in an isomorphic way (Node Buffer fallback to btoa).\n *\n * @param bytes - The raw bytes to encode.\n *\n * @returns The base64-encoded string.\n */\nfunction bytesToBase64(bytes: Uint8Array): string {\n // Prefer Node's Buffer when available (faster), but degrade to btoa() in\n // browsers / Deno / Workers where Buffer isn't a global. We access via\n // globalThis to avoid a hard reference to a Node-only symbol — that would\n // break the type-check in non-Node runtimes (Deno, browser-mode Vitest).\n const g = globalThis as {\n Buffer?: { from(b: Uint8Array): { toString(encoding: string): string } }\n }\n if (g.Buffer) {\n return g.Buffer.from(bytes).toString('base64')\n }\n let binary = ''\n for (const b of bytes) binary += String.fromCharCode(b)\n return btoa(binary)\n}\n\n/**\n * Computes the MD5 digest of the given bytes as a base64 string. Prefers\n * `node:crypto` for native speed when available; falls back to a pure-JS\n * implementation in browser / edge runtimes because WebCrypto's\n * `crypto.subtle.digest` deliberately does not support MD5.\n *\n * MD5 is used here only for SSE-C key integrity (matching the B2 wire\n * protocol). It is **not** a security boundary; the customer key itself is\n * the secret. Bundling a pure-JS fallback keeps `EncryptionKey.fromBytes`\n * isomorphic.\n *\n * @param bytes - The bytes to digest.\n *\n * @returns The base64-encoded MD5 digest.\n */\nasync function md5Base64(bytes: Uint8Array): Promise<string> {\n try {\n const { createHash } = await import('node:crypto')\n // Vite's browser shim resolves the import but does not implement\n // `createHash`. Probe explicitly so we fall through to the pure-JS path.\n if (typeof createHash !== 'function') throw new Error('createHash unavailable')\n return createHash('md5').update(bytes).digest('base64')\n /* v8 ignore next 3 -- fallback only reachable in non-Node runtimes */\n } catch {\n return bytesToBase64(md5Bytes(bytes))\n }\n}\n\n/**\n * Pure-JS MD5 implementation per RFC 1321. Returns the 16-byte digest of the\n * input. Used as a browser fallback for SSE-C key MD5 computation; not\n * intended for security-sensitive purposes (MD5 is broken cryptographically).\n *\n * @param data - The bytes to hash.\n *\n * @returns The 16-byte MD5 digest.\n */\nfunction md5Bytes(data: Uint8Array): Uint8Array {\n // Padding: append 0x80, then zeros, then the original length in bits as a\n // little-endian 64-bit integer, so the total length is a multiple of 64.\n const originalBitLength = data.byteLength * 8\n const padLength = ((data.byteLength + 8) >>> 6) + 1\n const padded = new Uint8Array(padLength * 64)\n padded.set(data)\n padded[data.byteLength] = 0x80\n // Write the 64-bit length (little-endian). JS bitwise ops are 32-bit, so\n // split into low/high halves.\n const lowBits = originalBitLength >>> 0\n const highBits = Math.floor(originalBitLength / 0x1_0000_0000) >>> 0\n const lengthView = new DataView(padded.buffer, padded.byteLength - 8, 8)\n lengthView.setUint32(0, lowBits, true)\n lengthView.setUint32(4, highBits, true)\n\n // Per-round shift amounts.\n const s = [\n 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9,\n 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21,\n 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,\n ]\n // Per-round sine-derived constants K[i] = floor(2^32 * abs(sin(i + 1))).\n const k = new Uint32Array([\n 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,\n 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,\n 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,\n 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,\n 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,\n 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,\n 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,\n 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,\n ])\n\n let a0 = 0x67452301\n let b0 = 0xefcdab89\n let c0 = 0x98badcfe\n let d0 = 0x10325476\n\n const m = new Uint32Array(16)\n const view = new DataView(padded.buffer)\n for (let block = 0; block < padded.byteLength; block += 64) {\n for (let i = 0; i < 16; i++) m[i] = view.getUint32(block + i * 4, true)\n let A = a0\n let B = b0\n let C = c0\n let D = d0\n for (let i = 0; i < 64; i++) {\n let f: number\n let g: number\n if (i < 16) {\n f = (B & C) | (~B & D)\n g = i\n } else if (i < 32) {\n f = (D & B) | (~D & C)\n g = (5 * i + 1) % 16\n } else if (i < 48) {\n f = B ^ C ^ D\n g = (3 * i + 5) % 16\n } else {\n f = C ^ (B | ~D)\n g = (7 * i) % 16\n }\n const temp = D\n D = C\n C = B\n const sum = (A + f + (k[i] ?? 0) + (m[g] ?? 0)) >>> 0\n const shift = s[i] ?? 0\n const rotated = ((sum << shift) | (sum >>> (32 - shift))) >>> 0\n B = (B + rotated) >>> 0\n A = temp\n }\n a0 = (a0 + A) >>> 0\n b0 = (b0 + B) >>> 0\n c0 = (c0 + C) >>> 0\n d0 = (d0 + D) >>> 0\n }\n\n const out = new Uint8Array(16)\n const outView = new DataView(out.buffer)\n outView.setUint32(0, a0, true)\n outView.setUint32(4, b0, true)\n outView.setUint32(8, c0, true)\n outView.setUint32(12, d0, true)\n return out\n}\n\nconst KEY_REDACTED = '[redacted SSE-C key]'\n\n/**\n * Safe wrapper around an SSE-C customer key. Hides the key bytes from\n * `JSON.stringify`, `console.log`, and Node's `util.inspect`. Use {@link EncryptionKey.fromBytes}\n * to construct one from a raw 32-byte key; the MD5 digest is computed internally.\n */\nexport class EncryptionKey {\n /** Encryption mode discriminant. Always `'SSE-C'` for this class. */\n readonly mode = 'SSE-C' as const\n /** Encryption algorithm. B2's S3-compatible API only supports AES-256. */\n readonly algorithm: EncryptionAlgorithm = 'AES256'\n /** Base64-encoded 256-bit customer key. Logged as `[redacted SSE-C key]` via `toJSON` / `toString`. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the customer key. Required by B2 for integrity verification. */\n readonly customerKeyMd5: string\n\n /**\n * Internal constructor. Use {@link EncryptionKey.fromBytes} or\n * {@link EncryptionKey.fromBase64} instead.\n *\n * @param customerKey - Base64-encoded 256-bit encryption key.\n * @param customerKeyMd5 - Base64-encoded MD5 digest of the key.\n *\n * @internal\n */\n private constructor(customerKey: string, customerKeyMd5: string) {\n this.customerKey = customerKey\n this.customerKeyMd5 = customerKeyMd5\n }\n\n /**\n * Builds an EncryptionKey from a raw 32-byte (256-bit) key. Computes the\n * required base64 MD5 digest internally.\n *\n * @param rawKey - The raw 256-bit key as bytes. Must be exactly 32 bytes.\n *\n * @returns A safely-wrapped EncryptionKey ready for upload/download.\n *\n * @throws If the key is not exactly 32 bytes.\n */\n static async fromBytes(rawKey: Uint8Array): Promise<EncryptionKey> {\n if (rawKey.byteLength !== 32) {\n throw new Error(`SSE-C key must be exactly 32 bytes (256 bits); got ${rawKey.byteLength}.`)\n }\n const customerKey = bytesToBase64(rawKey)\n const customerKeyMd5 = await md5Base64(rawKey)\n return new EncryptionKey(customerKey, customerKeyMd5)\n }\n\n /**\n * Builds an EncryptionKey from precomputed base64 strings. Use this in\n * environments where MD5 must be computed externally (e.g., browsers).\n *\n * @param customerKey - Base64-encoded 256-bit encryption key.\n * @param customerKeyMd5 - Base64-encoded MD5 digest of the key.\n *\n * @returns A safely-wrapped EncryptionKey ready for upload/download.\n */\n static fromBase64(customerKey: string, customerKeyMd5: string): EncryptionKey {\n return new EncryptionKey(customerKey, customerKeyMd5)\n }\n\n /**\n * Hides the key bytes from `JSON.stringify`.\n *\n * @returns A redacted shape: same mode and algorithm, but the key and MD5\n * replaced with a placeholder string.\n */\n toJSON(): {\n /** Encryption mode discriminant. */\n mode: 'SSE-C'\n /** Encryption algorithm. */\n algorithm: EncryptionAlgorithm\n /** Always the literal redaction placeholder; the real key never leaves the instance. */\n customerKey: string\n /** Always the literal redaction placeholder; the real MD5 never leaves the instance. */\n customerKeyMd5: string\n } {\n return {\n mode: this.mode,\n algorithm: this.algorithm,\n customerKey: KEY_REDACTED,\n customerKeyMd5: KEY_REDACTED,\n }\n }\n\n /**\n * Hides the key bytes from default `toString()`.\n *\n * @returns A short opaque label indicating this is an SSE-C key.\n */\n toString(): string {\n return `[EncryptionKey SSE-C ${KEY_REDACTED}]`\n }\n\n /**\n * Hides the key bytes from Node's `util.inspect` (and therefore `console.log`).\n *\n * @returns A short opaque label indicating this is an SSE-C key.\n */\n [Symbol.for('nodejs.util.inspect.custom')](): string {\n return this.toString()\n }\n}\n"],"mappings":";;AACA,IAAa,sBAAsB;;AAEjC,QAAQ,SACV;;;;;;;;;;AAcA,IAAa,iBAAiB;;CAE5B,OAAO;;CAEP,MAAM;;CAEN,MAAM;AACR;;AA0DA,IAAa,SAAuB;CAAE,MAAM;CAAU,WAAW;AAAS;;AAG1E,IAAa,WAAyB,EAAE,MAAM,OAAO;;;;;;;;AASrD,SAAgB,YAAY,aAAqB,gBAA6C;CAC5F,OAAO;EAAE,MAAM;EAAS,WAAW;EAAU;EAAa;CAAe;AAC3E;;;;;;;;AASA,SAAS,cAAc,OAA2B;CAKhD,MAAM,IAAI;CAGV,IAAI,EAAE,QACJ,OAAO,EAAE,OAAO,KAAK,KAAK,CAAC,CAAC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BAA4B,KAAa;EACnD,OAAO,KAAK,SAAS;CACvB;AACF"}
|
|
1
|
+
{"version":3,"file":"encryption.cjs","names":[],"sources":["../../src/types/encryption.ts"],"sourcesContent":["import { md5Base64 } from '../util/md5.ts'\n\n/** Named constants for the supported server-side encryption algorithms. */\nexport const EncryptionAlgorithm = {\n /** AES with a 256-bit key. The only algorithm B2 currently supports. */\n Aes256: 'AES256',\n} as const\n\n/** Supported server-side encryption algorithm. Derived from {@link EncryptionAlgorithm}. */\nexport type EncryptionAlgorithm = (typeof EncryptionAlgorithm)[keyof typeof EncryptionAlgorithm]\n\n/**\n * Named constants for the server-side encryption mode used by a file.\n *\n * Most callers should use the {@link SSE_B2}, {@link SSE_NONE}, and\n * {@link sseCustomer} helpers below which return complete\n * {@link EncryptionSetting} objects. These constants are useful when you\n * need the bare mode discriminator (e.g., when introspecting a file's\n * current encryption setting).\n */\nexport const EncryptionMode = {\n /** B2-managed encryption keys. */\n SseB2: 'SSE-B2',\n /** Customer-provided encryption keys. */\n SseC: 'SSE-C',\n /** No encryption. */\n None: 'none',\n} as const\n\n/** Server-side encryption mode for files stored in B2. Derived from {@link EncryptionMode}. */\nexport type EncryptionMode = (typeof EncryptionMode)[keyof typeof EncryptionMode]\n\n/** Server-side encryption using B2-managed keys (SSE-B2). */\nexport interface SseB2Setting {\n /** Encryption mode discriminator. Always `'SSE-B2'`. */\n readonly mode: 'SSE-B2'\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: EncryptionAlgorithm\n}\n\n/** Server-side encryption using customer-provided keys (SSE-C). */\nexport interface SseCCustomerSetting {\n /** Encryption mode discriminator. Always `'SSE-C'`. */\n readonly mode: 'SSE-C'\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: EncryptionAlgorithm\n /** Base64-encoded 256-bit encryption key provided by the customer. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the customer-provided key, used for integrity verification. */\n readonly customerKeyMd5: string\n}\n\n/** Server-side encryption using customer-provided keys as returned by B2 responses. */\nexport interface SseCPublicSetting {\n /** Encryption mode discriminator. Always `'SSE-C'`. */\n readonly mode: 'SSE-C'\n /** Encryption algorithm. Always `'AES256'`. */\n readonly algorithm: EncryptionAlgorithm\n}\n\n/** Indicates no server-side encryption is applied. */\nexport interface NoEncryption {\n /** Encryption mode discriminator. Always `'none'`. */\n readonly mode: 'none'\n}\n\n/** No-encryption shape returned by B2 response objects. */\nexport interface NoEncryptionWireSetting {\n /** Encryption mode discriminator. B2 response payloads use null for no encryption. */\n readonly mode: null\n /** Encryption algorithm. B2 response payloads use null when no encryption is applied. */\n readonly algorithm: null\n}\n\n/** Union of all server-side encryption settings: B2-managed, customer-provided, or none. */\nexport type EncryptionSetting = SseB2Setting | SseCCustomerSetting | NoEncryption\n\n/** Server-side encryption setting returned by B2 response objects. */\nexport type PublicEncryptionSetting =\n | SseB2Setting\n | SseCPublicSetting\n | NoEncryption\n | NoEncryptionWireSetting\n\n/** Pre-built SSE-B2 encryption setting using AES-256. */\nexport const SSE_B2: SseB2Setting = { mode: 'SSE-B2', algorithm: 'AES256' }\n\n/** Pre-built setting indicating no server-side encryption. */\nexport const SSE_NONE: NoEncryption = { mode: 'none' }\n\n/**\n * Creates an SSE-C encryption setting with a customer-provided key.\n * @param customerKey - Base64-encoded 256-bit encryption key.\n * @param customerKeyMd5 - Base64-encoded MD5 digest of the key.\n *\n * @returns An SSE-C encryption setting ready to pass to upload or download calls.\n */\nexport function sseCustomer(customerKey: string, customerKeyMd5: string): SseCCustomerSetting {\n return { mode: 'SSE-C', algorithm: 'AES256', customerKey, customerKeyMd5 }\n}\n\n/**\n * Encodes raw bytes as base64 in an isomorphic way (Node Buffer fallback to btoa).\n *\n * @param bytes - The raw bytes to encode.\n *\n * @returns The base64-encoded string.\n */\nfunction bytesToBase64(bytes: Uint8Array): string {\n // Prefer Node's Buffer when available (faster), but degrade to btoa() in\n // browsers / Deno / Workers where Buffer isn't a global. We access via\n // globalThis to avoid a hard reference to a Node-only symbol — that would\n // break the type-check in non-Node runtimes (Deno, browser-mode Vitest).\n const g = globalThis as {\n Buffer?: { from(b: Uint8Array): { toString(encoding: string): string } }\n }\n if (g.Buffer) {\n return g.Buffer.from(bytes).toString('base64')\n }\n let binary = ''\n for (const b of bytes) binary += String.fromCharCode(b)\n return btoa(binary)\n}\n\nexport const SSE_C_KEY_REDACTION = '[redacted SSE-C key]'\n\nconst NODE_INSPECT_CUSTOM = Symbol.for('nodejs.util.inspect.custom')\n\ninterface SseCKeyMaterial {\n readonly algorithm: EncryptionAlgorithm\n readonly customerKey: string\n readonly customerKeyMd5: string\n}\n\ninterface SseCKeyRedactionOptions {\n readonly label: string\n readonly mode?: 'SSE-C'\n}\n\ninterface RedactedSseCKeyJson {\n readonly mode?: 'SSE-C'\n readonly algorithm: EncryptionAlgorithm\n readonly customerKey: string\n readonly customerKeyMd5: string\n}\n\nfunction sseCKeyRedactedJson(\n key: SseCKeyMaterial,\n options: SseCKeyRedactionOptions,\n): RedactedSseCKeyJson {\n return {\n ...(options.mode !== undefined ? { mode: options.mode } : {}),\n algorithm: key.algorithm,\n customerKey: SSE_C_KEY_REDACTION,\n // The MD5 is not secret key material, but it is still derived from a\n // customer-provided key. Keep logged key views fully opaque by default.\n customerKeyMd5: SSE_C_KEY_REDACTION,\n }\n}\n\nfunction sseCKeyRedactedString(options: SseCKeyRedactionOptions): string {\n return `[${options.label} ${SSE_C_KEY_REDACTION}]`\n}\n\n/**\n * Wraps SSE-C key material so diagnostic stringification redacts key fields.\n *\n * The returned object keeps `customerKey` and `customerKeyMd5` readable by\n * property access for request header construction, but makes them\n * non-enumerable so object spread and generic serializers do not copy them.\n * Callers that need wire headers must read those fields directly.\n *\n * @param key - SSE-C key material to wrap.\n * @param options - Redaction label and optional encryption mode discriminator.\n *\n * @returns A redacted view with the same readable key fields.\n */\nexport function redactSseCKeyMaterial<T extends SseCKeyMaterial>(\n key: T,\n options: SseCKeyRedactionOptions,\n): T {\n const redacted = {\n ...(options.mode !== undefined ? { mode: options.mode } : {}),\n algorithm: key.algorithm,\n } as T & {\n toJSON(): RedactedSseCKeyJson\n toString(): string\n }\n\n Object.defineProperties(redacted, {\n customerKey: { value: key.customerKey, enumerable: false },\n customerKeyMd5: { value: key.customerKeyMd5, enumerable: false },\n toJSON: { value: () => sseCKeyRedactedJson(key, options), enumerable: false },\n toString: { value: () => sseCKeyRedactedString(options), enumerable: false },\n })\n Object.defineProperty(redacted, NODE_INSPECT_CUSTOM, {\n value: () => sseCKeyRedactedString(options),\n enumerable: false,\n })\n\n return redacted\n}\n\n/**\n * Safe wrapper around an SSE-C customer key. Hides the key bytes from\n * `JSON.stringify`, `console.log`, and Node's `util.inspect`. Use {@link EncryptionKey.fromBytes}\n * to construct one from a raw 32-byte key; the MD5 digest is computed internally.\n */\nexport class EncryptionKey {\n /** Encryption mode discriminant. Always `'SSE-C'` for this class. */\n readonly mode = 'SSE-C' as const\n /** Encryption algorithm. B2's S3-compatible API only supports AES-256. */\n readonly algorithm: EncryptionAlgorithm = 'AES256'\n /** Base64-encoded 256-bit customer key. Logged as `[redacted SSE-C key]` via `toJSON` / `toString`. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the customer key. Required by B2 for integrity verification. */\n readonly customerKeyMd5: string\n\n /**\n * Internal constructor. Use {@link EncryptionKey.fromBytes} or\n * {@link EncryptionKey.fromBase64} instead.\n *\n * @param customerKey - Base64-encoded 256-bit encryption key.\n * @param customerKeyMd5 - Base64-encoded MD5 digest of the key.\n *\n * @internal\n */\n private constructor(customerKey: string, customerKeyMd5: string) {\n this.customerKey = customerKey\n this.customerKeyMd5 = customerKeyMd5\n }\n\n /**\n * Builds an EncryptionKey from a raw 32-byte (256-bit) key. Computes the\n * required base64 MD5 digest internally.\n *\n * @param rawKey - The raw 256-bit key as bytes. Must be exactly 32 bytes.\n *\n * @returns A safely-wrapped EncryptionKey ready for upload/download.\n *\n * @throws If the key is not exactly 32 bytes.\n */\n static async fromBytes(rawKey: Uint8Array): Promise<EncryptionKey> {\n if (rawKey.byteLength !== 32) {\n throw new Error(`SSE-C key must be exactly 32 bytes (256 bits); got ${rawKey.byteLength}.`)\n }\n const customerKey = bytesToBase64(rawKey)\n const customerKeyMd5 = await md5Base64(rawKey)\n return new EncryptionKey(customerKey, customerKeyMd5)\n }\n\n /**\n * Builds an EncryptionKey from precomputed base64 strings. Use this in\n * environments where MD5 must be computed externally (e.g., browsers).\n *\n * @param customerKey - Base64-encoded 256-bit encryption key.\n * @param customerKeyMd5 - Base64-encoded MD5 digest of the key.\n *\n * @returns A safely-wrapped EncryptionKey ready for upload/download.\n */\n static fromBase64(customerKey: string, customerKeyMd5: string): EncryptionKey {\n return new EncryptionKey(customerKey, customerKeyMd5)\n }\n\n /**\n * Hides the key bytes from `JSON.stringify`.\n *\n * @returns A redacted shape: same mode and algorithm, but the key and MD5\n * replaced with a placeholder string.\n */\n toJSON(): {\n /** Encryption mode discriminant. */\n mode: 'SSE-C'\n /** Encryption algorithm. */\n algorithm: EncryptionAlgorithm\n /** Always the literal redaction placeholder; the real key never leaves the instance. */\n customerKey: string\n /** Always the literal redaction placeholder; the real MD5 never leaves the instance. */\n customerKeyMd5: string\n } {\n return sseCKeyRedactedJson(this, { label: 'EncryptionKey SSE-C', mode: this.mode }) as {\n mode: 'SSE-C'\n algorithm: EncryptionAlgorithm\n customerKey: string\n customerKeyMd5: string\n }\n }\n\n /**\n * Hides the key bytes from default `toString()`.\n *\n * @returns A short opaque label indicating this is an SSE-C key.\n */\n toString(): string {\n return sseCKeyRedactedString({ label: 'EncryptionKey SSE-C' })\n }\n\n /**\n * Hides the key bytes from Node's `util.inspect` (and therefore `console.log`).\n *\n * @returns A short opaque label indicating this is an SSE-C key.\n */\n [NODE_INSPECT_CUSTOM](): string {\n return this.toString()\n }\n}\n"],"mappings":";;;AAGA,IAAa,sBAAsB;;AAEjC,QAAQ,SACV;;;;;;;;;;AAcA,IAAa,iBAAiB;;CAE5B,OAAO;;CAEP,MAAM;;CAEN,MAAM;AAC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