@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
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { utf8Encoder } from "../util/text-codec.js";
|
|
2
|
+
import { BucketRetentionMode, BucketType, CorsOperation } from "../types/bucket.js";
|
|
3
|
+
import { Capability } from "../types/auth.js";
|
|
4
|
+
import { EventType } from "../types/notifications.js";
|
|
2
5
|
import { BUCKET_NAME_MAX, BUCKET_NAME_MIN, FILE_NAME_MAX_BYTES, getB2FileNameByteLength, hasB2FileNameControlCharacter, hasValidB2BucketNameShape, isB2BucketNameIpv4Address } from "../internal/b2-naming.js";
|
|
3
6
|
//#region src/simulator/validation.ts
|
|
4
7
|
/**
|
|
@@ -16,6 +19,66 @@ import { BUCKET_NAME_MAX, BUCKET_NAME_MIN, FILE_NAME_MAX_BYTES, getB2FileNameByt
|
|
|
16
19
|
*
|
|
17
20
|
* @packageDocumentation
|
|
18
21
|
*/
|
|
22
|
+
/** Minimum length for application key names. */
|
|
23
|
+
var KEY_NAME_MIN = 1;
|
|
24
|
+
/** Maximum length for application key names. */
|
|
25
|
+
var KEY_NAME_MAX = 100;
|
|
26
|
+
var VALID_CAPABILITIES = new Set(Object.values(Capability));
|
|
27
|
+
/**
|
|
28
|
+
* Validates application-key capabilities against B2's supported capability set.
|
|
29
|
+
*
|
|
30
|
+
* @param capabilities - Caller-supplied capabilities array.
|
|
31
|
+
*
|
|
32
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
33
|
+
*
|
|
34
|
+
* @see https://www.backblaze.com/apidocs/b2-create-key
|
|
35
|
+
*/
|
|
36
|
+
function validateCreateKeyCapabilities(capabilities) {
|
|
37
|
+
if (!Array.isArray(capabilities)) return {
|
|
38
|
+
code: "bad_request",
|
|
39
|
+
message: "capabilities must be an array"
|
|
40
|
+
};
|
|
41
|
+
if (capabilities.length === 0) return {
|
|
42
|
+
code: "bad_request",
|
|
43
|
+
message: "capabilities must not be empty"
|
|
44
|
+
};
|
|
45
|
+
const unknownCapabilities = capabilities.filter((capability) => typeof capability !== "string" || !VALID_CAPABILITIES.has(capability));
|
|
46
|
+
if (unknownCapabilities.length > 0) return {
|
|
47
|
+
code: "bad_request",
|
|
48
|
+
message: `unknown capabilities: ${unknownCapabilities.map(String).join(", ")}`
|
|
49
|
+
};
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns a frozen copy of a previously validated application-key capability list.
|
|
54
|
+
*
|
|
55
|
+
* @param capabilities - Validated caller-supplied capabilities.
|
|
56
|
+
*
|
|
57
|
+
* @returns An immutable capability list safe to store internally.
|
|
58
|
+
*/
|
|
59
|
+
function normalizeCreateKeyCapabilities(capabilities) {
|
|
60
|
+
return Object.freeze([...capabilities]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validates application-key names against B2's documented length limits.
|
|
64
|
+
*
|
|
65
|
+
* @param keyName - Caller-supplied keyName.
|
|
66
|
+
*
|
|
67
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
68
|
+
*
|
|
69
|
+
* @see https://www.backblaze.com/apidocs/b2-create-key
|
|
70
|
+
*/
|
|
71
|
+
function validateCreateKeyName(keyName) {
|
|
72
|
+
if (typeof keyName !== "string") return {
|
|
73
|
+
code: "bad_request",
|
|
74
|
+
message: "keyName must be a string"
|
|
75
|
+
};
|
|
76
|
+
if (keyName.length < 1 || keyName.length > 100) return {
|
|
77
|
+
code: "bad_request",
|
|
78
|
+
message: `keyName must be 1-100 characters`
|
|
79
|
+
};
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
19
82
|
/**
|
|
20
83
|
* Validates a bucket name against B2's documented rules.
|
|
21
84
|
*
|
|
@@ -194,7 +257,506 @@ function validateMaxCount(requested, endpoint) {
|
|
|
194
257
|
};
|
|
195
258
|
return null;
|
|
196
259
|
}
|
|
260
|
+
/** Minimum `b2_get_download_authorization.validDurationInSeconds`. */
|
|
261
|
+
var DOWNLOAD_AUTH_DURATION_MIN_SECONDS = 1;
|
|
262
|
+
/** Maximum `b2_get_download_authorization.validDurationInSeconds`. */
|
|
263
|
+
var DOWNLOAD_AUTH_DURATION_MAX_SECONDS = 604800;
|
|
264
|
+
/**
|
|
265
|
+
* Validates a `b2_get_download_authorization` duration against B2's
|
|
266
|
+
* documented inclusive 1-second to 7-day range.
|
|
267
|
+
*
|
|
268
|
+
* @param requested - Caller-supplied duration in seconds.
|
|
269
|
+
*
|
|
270
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
271
|
+
*/
|
|
272
|
+
function validateDownloadAuthorizationDuration(requested) {
|
|
273
|
+
if (typeof requested !== "number" || !Number.isInteger(requested) || requested < 1 || requested > 604800) return {
|
|
274
|
+
code: "bad_request",
|
|
275
|
+
message: `validDurationInSeconds must be an integer from 1 through ${DOWNLOAD_AUTH_DURATION_MAX_SECONDS}`
|
|
276
|
+
};
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Validates a `b2_get_download_authorization` file name prefix.
|
|
281
|
+
*
|
|
282
|
+
* B2 allows an empty prefix, but the field must still be present as a
|
|
283
|
+
* string so later prefix checks cannot crash on malformed request bodies.
|
|
284
|
+
*
|
|
285
|
+
* @param requested - Caller-supplied file name prefix.
|
|
286
|
+
*
|
|
287
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
288
|
+
*/
|
|
289
|
+
function validateDownloadAuthorizationPrefix(requested) {
|
|
290
|
+
if (typeof requested !== "string") return {
|
|
291
|
+
code: "bad_request",
|
|
292
|
+
message: "fileNamePrefix must be a string"
|
|
293
|
+
};
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
function isRecord(value) {
|
|
297
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
298
|
+
}
|
|
299
|
+
function validateKnownFields(value, allowedFields, path) {
|
|
300
|
+
for (const field of Object.keys(value)) if (!allowedFields.has(field)) return {
|
|
301
|
+
code: "bad_request",
|
|
302
|
+
message: `${path}.${field} is not a supported field`
|
|
303
|
+
};
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
function validateStringArray(value, path, options = {}) {
|
|
307
|
+
if (value === null && options.allowNull === true) return null;
|
|
308
|
+
if (!Array.isArray(value)) return {
|
|
309
|
+
code: "bad_request",
|
|
310
|
+
message: `${path} must be an array of strings`
|
|
311
|
+
};
|
|
312
|
+
if (options.requireNonEmpty === true && value.length === 0) return {
|
|
313
|
+
code: "bad_request",
|
|
314
|
+
message: `${path} must be a non-empty array`
|
|
315
|
+
};
|
|
316
|
+
for (const [index, item] of value.entries()) if (typeof item !== "string") return {
|
|
317
|
+
code: "bad_request",
|
|
318
|
+
message: `${path}[${index}] must be a string`
|
|
319
|
+
};
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function validateNonEmptyString(value, path) {
|
|
323
|
+
if (typeof value !== "string" || value.length === 0) return {
|
|
324
|
+
code: "bad_request",
|
|
325
|
+
message: `${path} must be a non-empty string`
|
|
326
|
+
};
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
function validateNonNegativeInteger(value, path) {
|
|
330
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return {
|
|
331
|
+
code: "bad_request",
|
|
332
|
+
message: `${path} must be a non-negative integer`
|
|
333
|
+
};
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
function validateIntegerAtMost(value, max, path) {
|
|
337
|
+
if (value > max) return {
|
|
338
|
+
code: "bad_request",
|
|
339
|
+
message: `${path} must not exceed ${max}`
|
|
340
|
+
};
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
function validatePositiveInteger(value, path) {
|
|
344
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) return {
|
|
345
|
+
code: "bad_request",
|
|
346
|
+
message: `${path} must be a positive integer`
|
|
347
|
+
};
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
function validateNullablePositiveInteger(value, path) {
|
|
351
|
+
if (value === void 0 || value === null) return null;
|
|
352
|
+
return validatePositiveInteger(value, path);
|
|
353
|
+
}
|
|
354
|
+
function validateUniqueName(names, name, path) {
|
|
355
|
+
if (names.has(name)) return {
|
|
356
|
+
code: "bad_request",
|
|
357
|
+
message: `${path} must be unique`
|
|
358
|
+
};
|
|
359
|
+
names.add(name);
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
var KNOWN_BUCKET_TYPES = new Set(Object.values(BucketType));
|
|
363
|
+
/**
|
|
364
|
+
* Validates a `b2_list_buckets.bucketTypes` filter.
|
|
365
|
+
*
|
|
366
|
+
* @param bucketTypes - Caller-supplied bucket type filter.
|
|
367
|
+
*
|
|
368
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
369
|
+
*
|
|
370
|
+
* @see https://www.backblaze.com/apidocs/b2-list-buckets
|
|
371
|
+
*/
|
|
372
|
+
function validateBucketTypes(bucketTypes) {
|
|
373
|
+
if (bucketTypes === void 0) return null;
|
|
374
|
+
if (!Array.isArray(bucketTypes)) return {
|
|
375
|
+
code: "bad_request",
|
|
376
|
+
message: "bucketTypes must be an array"
|
|
377
|
+
};
|
|
378
|
+
for (const [index, bucketType] of bucketTypes.entries()) if (typeof bucketType !== "string" || !KNOWN_BUCKET_TYPES.has(bucketType)) return {
|
|
379
|
+
code: "bad_request",
|
|
380
|
+
message: `bucketTypes[${index}] must be a known bucket type`
|
|
381
|
+
};
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
var CORS_RULE_FIELDS = /* @__PURE__ */ new Set([
|
|
385
|
+
"allowedHeaders",
|
|
386
|
+
"allowedOperations",
|
|
387
|
+
"allowedOrigins",
|
|
388
|
+
"corsRuleName",
|
|
389
|
+
"exposeHeaders",
|
|
390
|
+
"maxAgeSeconds"
|
|
391
|
+
]);
|
|
392
|
+
var CORS_MAX_AGE_SECONDS_MAX = 86400;
|
|
393
|
+
var KNOWN_CORS_OPERATIONS = new Set(Object.values(CorsOperation));
|
|
394
|
+
/**
|
|
395
|
+
* Validates B2 CORS rule structure for bucket create/update requests.
|
|
396
|
+
*
|
|
397
|
+
* @param rules - Caller-supplied CORS rules.
|
|
398
|
+
*
|
|
399
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
400
|
+
*
|
|
401
|
+
* @see https://www.backblaze.com/docs/cloud-storage-cross-origin-resource-sharing-rules
|
|
402
|
+
*/
|
|
403
|
+
function validateCorsRules(rules) {
|
|
404
|
+
if (!Array.isArray(rules)) return {
|
|
405
|
+
code: "bad_request",
|
|
406
|
+
message: "corsRules must be an array"
|
|
407
|
+
};
|
|
408
|
+
const names = /* @__PURE__ */ new Set();
|
|
409
|
+
for (const [index, rule] of rules.entries()) {
|
|
410
|
+
const rulePath = `corsRules[${index}]`;
|
|
411
|
+
if (!isRecord(rule)) return {
|
|
412
|
+
code: "bad_request",
|
|
413
|
+
message: `${rulePath} must be an object`
|
|
414
|
+
};
|
|
415
|
+
const fieldError = validateKnownFields(rule, CORS_RULE_FIELDS, rulePath);
|
|
416
|
+
if (fieldError) return fieldError;
|
|
417
|
+
const nameError = validateNonEmptyString(rule["corsRuleName"], `${rulePath}.corsRuleName`);
|
|
418
|
+
if (nameError) return nameError;
|
|
419
|
+
const ruleName = rule["corsRuleName"];
|
|
420
|
+
const uniqueNameError = validateUniqueName(names, ruleName, `${rulePath}.corsRuleName`);
|
|
421
|
+
if (uniqueNameError) return uniqueNameError;
|
|
422
|
+
const originsError = validateStringArray(rule["allowedOrigins"], `${rulePath}.allowedOrigins`, { requireNonEmpty: true });
|
|
423
|
+
if (originsError) return originsError;
|
|
424
|
+
const operationsError = validateStringArray(rule["allowedOperations"], `${rulePath}.allowedOperations`, { requireNonEmpty: true });
|
|
425
|
+
if (operationsError) return operationsError;
|
|
426
|
+
for (const operation of rule["allowedOperations"]) if (!KNOWN_CORS_OPERATIONS.has(operation)) return {
|
|
427
|
+
code: "bad_request",
|
|
428
|
+
message: `${rulePath}.allowedOperations contains an unknown operation`
|
|
429
|
+
};
|
|
430
|
+
const headersError = validateStringArray(rule["allowedHeaders"], `${rulePath}.allowedHeaders`, { allowNull: true });
|
|
431
|
+
if (headersError) return headersError;
|
|
432
|
+
const exposeError = validateStringArray(rule["exposeHeaders"], `${rulePath}.exposeHeaders`, { allowNull: true });
|
|
433
|
+
if (exposeError) return exposeError;
|
|
434
|
+
const ageError = validateNonNegativeInteger(rule["maxAgeSeconds"], `${rulePath}.maxAgeSeconds`);
|
|
435
|
+
if (ageError) return ageError;
|
|
436
|
+
const maxAgeError = validateIntegerAtMost(rule["maxAgeSeconds"], CORS_MAX_AGE_SECONDS_MAX, `${rulePath}.maxAgeSeconds`);
|
|
437
|
+
if (maxAgeError) return maxAgeError;
|
|
438
|
+
}
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
var LIFECYCLE_RULE_FIELDS = /* @__PURE__ */ new Set([
|
|
442
|
+
"daysFromHidingToDeleting",
|
|
443
|
+
"daysFromStartingToCancelingUnfinishedLargeFiles",
|
|
444
|
+
"daysFromUploadingToHiding",
|
|
445
|
+
"fileNamePrefix"
|
|
446
|
+
]);
|
|
447
|
+
/**
|
|
448
|
+
* Validates B2 lifecycle rule structure for bucket create/update requests.
|
|
449
|
+
*
|
|
450
|
+
* @param rules - Caller-supplied lifecycle rules.
|
|
451
|
+
*
|
|
452
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
453
|
+
*
|
|
454
|
+
* @see https://www.backblaze.com/docs/cloud-storage-lifecycle-rules
|
|
455
|
+
*/
|
|
456
|
+
function validateLifecycleRules(rules) {
|
|
457
|
+
if (!Array.isArray(rules)) return {
|
|
458
|
+
code: "bad_request",
|
|
459
|
+
message: "lifecycleRules must be an array"
|
|
460
|
+
};
|
|
461
|
+
for (const [index, rule] of rules.entries()) {
|
|
462
|
+
const rulePath = `lifecycleRules[${index}]`;
|
|
463
|
+
if (!isRecord(rule)) return {
|
|
464
|
+
code: "bad_request",
|
|
465
|
+
message: `${rulePath} must be an object`
|
|
466
|
+
};
|
|
467
|
+
const fieldError = validateKnownFields(rule, LIFECYCLE_RULE_FIELDS, rulePath);
|
|
468
|
+
if (fieldError) return fieldError;
|
|
469
|
+
const deletingError = validateNullablePositiveInteger(rule["daysFromHidingToDeleting"], `${rulePath}.daysFromHidingToDeleting`);
|
|
470
|
+
if (deletingError) return deletingError;
|
|
471
|
+
const hidingError = validateNullablePositiveInteger(rule["daysFromUploadingToHiding"], `${rulePath}.daysFromUploadingToHiding`);
|
|
472
|
+
if (hidingError) return hidingError;
|
|
473
|
+
const cancelError = validateNullablePositiveInteger(rule["daysFromStartingToCancelingUnfinishedLargeFiles"], `${rulePath}.daysFromStartingToCancelingUnfinishedLargeFiles`);
|
|
474
|
+
if (cancelError) return cancelError;
|
|
475
|
+
if (rule["daysFromHidingToDeleting"] == null && rule["daysFromUploadingToHiding"] == null && rule["daysFromStartingToCancelingUnfinishedLargeFiles"] == null) return {
|
|
476
|
+
code: "bad_request",
|
|
477
|
+
message: `${rulePath} must set at least one lifecycle action`
|
|
478
|
+
};
|
|
479
|
+
if (typeof rule["fileNamePrefix"] !== "string") return {
|
|
480
|
+
code: "bad_request",
|
|
481
|
+
message: `${rulePath}.fileNamePrefix must be a string`
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
var DEFAULT_RETENTION_FIELDS = /* @__PURE__ */ new Set(["mode", "period"]);
|
|
487
|
+
var RETENTION_PERIOD_FIELDS = /* @__PURE__ */ new Set(["duration", "unit"]);
|
|
488
|
+
var DEFAULT_RETENTION_MODES = new Set(Object.values(BucketRetentionMode));
|
|
489
|
+
var OBJECT_LOCK_RETENTION_MAX_DAYS = 3e3;
|
|
490
|
+
/**
|
|
491
|
+
* Validates default Object Lock retention policy structure for bucket requests.
|
|
492
|
+
*
|
|
493
|
+
* @param policy - Caller-supplied default retention policy.
|
|
494
|
+
*
|
|
495
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
496
|
+
*
|
|
497
|
+
* @see https://www.backblaze.com/docs/cloud-storage-object-lock
|
|
498
|
+
*/
|
|
499
|
+
function validateDefaultRetention(policy) {
|
|
500
|
+
if (!isRecord(policy)) return {
|
|
501
|
+
code: "bad_request",
|
|
502
|
+
message: "defaultRetention must be an object"
|
|
503
|
+
};
|
|
504
|
+
const fieldError = validateKnownFields(policy, DEFAULT_RETENTION_FIELDS, "defaultRetention");
|
|
505
|
+
if (fieldError) return fieldError;
|
|
506
|
+
const mode = policy["mode"];
|
|
507
|
+
if (typeof mode !== "string" || !DEFAULT_RETENTION_MODES.has(mode)) return {
|
|
508
|
+
code: "bad_request",
|
|
509
|
+
message: "defaultRetention.mode must be \"compliance\", \"governance\", or \"none\""
|
|
510
|
+
};
|
|
511
|
+
const period = policy["period"];
|
|
512
|
+
if (mode === BucketRetentionMode.None) {
|
|
513
|
+
if (period !== null) return {
|
|
514
|
+
code: "bad_request",
|
|
515
|
+
message: "defaultRetention.period must be null when mode is \"none\""
|
|
516
|
+
};
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
if (!isRecord(period)) return {
|
|
520
|
+
code: "bad_request",
|
|
521
|
+
message: "defaultRetention.period must be an object for retention modes"
|
|
522
|
+
};
|
|
523
|
+
const periodFieldError = validateKnownFields(period, RETENTION_PERIOD_FIELDS, "defaultRetention.period");
|
|
524
|
+
if (periodFieldError) return periodFieldError;
|
|
525
|
+
const durationError = validatePositiveInteger(period["duration"], "defaultRetention.period.duration");
|
|
526
|
+
if (durationError) return durationError;
|
|
527
|
+
if (!Number.isSafeInteger(period["duration"])) return {
|
|
528
|
+
code: "bad_request",
|
|
529
|
+
message: "defaultRetention.period.duration must be a safe integer"
|
|
530
|
+
};
|
|
531
|
+
if (period["unit"] !== "days" && period["unit"] !== "years") return {
|
|
532
|
+
code: "bad_request",
|
|
533
|
+
message: "defaultRetention.period.unit must be \"days\" or \"years\""
|
|
534
|
+
};
|
|
535
|
+
const durationDays = period["unit"] === "days" ? period["duration"] : period["duration"] * 365;
|
|
536
|
+
if (!Number.isFinite(durationDays) || durationDays > OBJECT_LOCK_RETENTION_MAX_DAYS) return {
|
|
537
|
+
code: "bad_request",
|
|
538
|
+
message: `defaultRetention.period must not exceed ${OBJECT_LOCK_RETENTION_MAX_DAYS} days`
|
|
539
|
+
};
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
var REPLICATION_CONFIG_FIELDS = /* @__PURE__ */ new Set(["asReplicationSource", "asReplicationDestination"]);
|
|
543
|
+
var REPLICATION_SOURCE_FIELDS = /* @__PURE__ */ new Set(["replicationRules", "sourceApplicationKeyId"]);
|
|
544
|
+
var REPLICATION_DESTINATION_FIELDS = /* @__PURE__ */ new Set(["sourceToDestinationKeyMapping"]);
|
|
545
|
+
var REPLICATION_RULE_FIELDS = /* @__PURE__ */ new Set([
|
|
546
|
+
"destinationBucketId",
|
|
547
|
+
"fileNamePrefix",
|
|
548
|
+
"includeExistingFiles",
|
|
549
|
+
"isEnabled",
|
|
550
|
+
"priority",
|
|
551
|
+
"replicationRuleName"
|
|
552
|
+
]);
|
|
553
|
+
function validateReplicationRule(rule, rulePath) {
|
|
554
|
+
if (!isRecord(rule)) return {
|
|
555
|
+
code: "bad_request",
|
|
556
|
+
message: `${rulePath} must be an object`
|
|
557
|
+
};
|
|
558
|
+
const fieldError = validateKnownFields(rule, REPLICATION_RULE_FIELDS, rulePath);
|
|
559
|
+
if (fieldError) return fieldError;
|
|
560
|
+
const destinationError = validateNonEmptyString(rule["destinationBucketId"], `${rulePath}.destinationBucketId`);
|
|
561
|
+
if (destinationError) return destinationError;
|
|
562
|
+
if (typeof rule["fileNamePrefix"] !== "string") return {
|
|
563
|
+
code: "bad_request",
|
|
564
|
+
message: `${rulePath}.fileNamePrefix must be a string`
|
|
565
|
+
};
|
|
566
|
+
if (typeof rule["includeExistingFiles"] !== "boolean") return {
|
|
567
|
+
code: "bad_request",
|
|
568
|
+
message: `${rulePath}.includeExistingFiles must be a boolean`
|
|
569
|
+
};
|
|
570
|
+
if (typeof rule["isEnabled"] !== "boolean") return {
|
|
571
|
+
code: "bad_request",
|
|
572
|
+
message: `${rulePath}.isEnabled must be a boolean`
|
|
573
|
+
};
|
|
574
|
+
const priorityError = validatePositiveInteger(rule["priority"], `${rulePath}.priority`);
|
|
575
|
+
if (priorityError) return priorityError;
|
|
576
|
+
const nameError = validateNonEmptyString(rule["replicationRuleName"], `${rulePath}.replicationRuleName`);
|
|
577
|
+
if (nameError) return nameError;
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
function validateReplicationSource(source) {
|
|
581
|
+
if (!isRecord(source)) return {
|
|
582
|
+
code: "bad_request",
|
|
583
|
+
message: "replicationConfiguration.asReplicationSource must be an object"
|
|
584
|
+
};
|
|
585
|
+
const fieldError = validateKnownFields(source, REPLICATION_SOURCE_FIELDS, "replicationConfiguration.asReplicationSource");
|
|
586
|
+
if (fieldError) return fieldError;
|
|
587
|
+
const sourceKeyError = validateNonEmptyString(source["sourceApplicationKeyId"], "replicationConfiguration.asReplicationSource.sourceApplicationKeyId");
|
|
588
|
+
if (sourceKeyError) return sourceKeyError;
|
|
589
|
+
const rules = source["replicationRules"];
|
|
590
|
+
if (!Array.isArray(rules)) return {
|
|
591
|
+
code: "bad_request",
|
|
592
|
+
message: "replicationConfiguration.asReplicationSource.replicationRules must be an array"
|
|
593
|
+
};
|
|
594
|
+
const names = /* @__PURE__ */ new Set();
|
|
595
|
+
for (const [index, rule] of rules.entries()) {
|
|
596
|
+
const rulePath = `replicationConfiguration.asReplicationSource.replicationRules[${index}]`;
|
|
597
|
+
const ruleError = validateReplicationRule(rule, rulePath);
|
|
598
|
+
if (ruleError) return ruleError;
|
|
599
|
+
const ruleName = rule["replicationRuleName"];
|
|
600
|
+
const uniqueNameError = validateUniqueName(names, ruleName, `${rulePath}.replicationRuleName`);
|
|
601
|
+
if (uniqueNameError) return uniqueNameError;
|
|
602
|
+
}
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
function validateReplicationDestination(destination) {
|
|
606
|
+
if (!isRecord(destination)) return {
|
|
607
|
+
code: "bad_request",
|
|
608
|
+
message: "replicationConfiguration.asReplicationDestination must be an object"
|
|
609
|
+
};
|
|
610
|
+
const fieldError = validateKnownFields(destination, REPLICATION_DESTINATION_FIELDS, "replicationConfiguration.asReplicationDestination");
|
|
611
|
+
if (fieldError) return fieldError;
|
|
612
|
+
const mapping = destination["sourceToDestinationKeyMapping"];
|
|
613
|
+
if (!isRecord(mapping)) return {
|
|
614
|
+
code: "bad_request",
|
|
615
|
+
message: "replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping must be an object"
|
|
616
|
+
};
|
|
617
|
+
for (const [sourceKey, destinationKey] of Object.entries(mapping)) {
|
|
618
|
+
if (sourceKey.length === 0) return {
|
|
619
|
+
code: "bad_request",
|
|
620
|
+
message: "replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping keys must be non-empty"
|
|
621
|
+
};
|
|
622
|
+
if (typeof destinationKey !== "string" || destinationKey.length === 0) return {
|
|
623
|
+
code: "bad_request",
|
|
624
|
+
message: "replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping values must be non-empty strings"
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Validates B2 replication configuration structure for bucket requests.
|
|
631
|
+
*
|
|
632
|
+
* @param config - Caller-supplied replication configuration.
|
|
633
|
+
*
|
|
634
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
635
|
+
*
|
|
636
|
+
* @see https://www.backblaze.com/apidocs/b2-update-bucket
|
|
637
|
+
*/
|
|
638
|
+
function validateReplicationConfiguration(config) {
|
|
639
|
+
if (!isRecord(config)) return {
|
|
640
|
+
code: "bad_request",
|
|
641
|
+
message: "replicationConfiguration must be an object"
|
|
642
|
+
};
|
|
643
|
+
const fieldError = validateKnownFields(config, REPLICATION_CONFIG_FIELDS, "replicationConfiguration");
|
|
644
|
+
if (fieldError) return fieldError;
|
|
645
|
+
if (!("asReplicationSource" in config) && !("asReplicationDestination" in config)) return {
|
|
646
|
+
code: "bad_request",
|
|
647
|
+
message: "replicationConfiguration must include asReplicationSource or asReplicationDestination"
|
|
648
|
+
};
|
|
649
|
+
const source = config["asReplicationSource"];
|
|
650
|
+
if (source !== void 0 && source !== null) {
|
|
651
|
+
const sourceError = validateReplicationSource(source);
|
|
652
|
+
if (sourceError) return sourceError;
|
|
653
|
+
}
|
|
654
|
+
const destination = config["asReplicationDestination"];
|
|
655
|
+
if (destination !== void 0 && destination !== null) {
|
|
656
|
+
const destinationError = validateReplicationDestination(destination);
|
|
657
|
+
if (destinationError) return destinationError;
|
|
658
|
+
}
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
var NOTIFICATION_RULE_FIELDS = /* @__PURE__ */ new Set([
|
|
662
|
+
"eventTypes",
|
|
663
|
+
"isEnabled",
|
|
664
|
+
"isSuspended",
|
|
665
|
+
"maxEventsPerBatch",
|
|
666
|
+
"name",
|
|
667
|
+
"objectNamePrefix",
|
|
668
|
+
"suspensionReason",
|
|
669
|
+
"targetConfiguration"
|
|
670
|
+
]);
|
|
671
|
+
var NOTIFICATION_TARGET_FIELDS = /* @__PURE__ */ new Set([
|
|
672
|
+
"customHeaders",
|
|
673
|
+
"hmacSha256SigningSecret",
|
|
674
|
+
"targetType",
|
|
675
|
+
"url"
|
|
676
|
+
]);
|
|
677
|
+
var KNOWN_NOTIFICATION_EVENT_TYPES = new Set(Object.values(EventType));
|
|
678
|
+
/**
|
|
679
|
+
* Validates event notification rules for `b2_set_bucket_notification_rules`.
|
|
680
|
+
*
|
|
681
|
+
* @param rules - Caller-supplied event notification rules.
|
|
682
|
+
*
|
|
683
|
+
* @returns A `{ code, message }` pair on failure, or `null` when valid.
|
|
684
|
+
*
|
|
685
|
+
* @see https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules
|
|
686
|
+
*/
|
|
687
|
+
function validateNotificationRules(rules) {
|
|
688
|
+
if (!Array.isArray(rules)) return {
|
|
689
|
+
code: "bad_request",
|
|
690
|
+
message: "eventNotificationRules must be an array"
|
|
691
|
+
};
|
|
692
|
+
const names = /* @__PURE__ */ new Set();
|
|
693
|
+
for (const [index, ruleValue] of rules.entries()) {
|
|
694
|
+
const rulePath = `eventNotificationRules[${index}]`;
|
|
695
|
+
if (!isRecord(ruleValue)) return {
|
|
696
|
+
code: "bad_request",
|
|
697
|
+
message: `${rulePath} must be an object`
|
|
698
|
+
};
|
|
699
|
+
const fieldError = validateKnownFields(ruleValue, NOTIFICATION_RULE_FIELDS, rulePath);
|
|
700
|
+
if (fieldError) return fieldError;
|
|
701
|
+
if (typeof ruleValue["isEnabled"] !== "boolean") return {
|
|
702
|
+
code: "bad_request",
|
|
703
|
+
message: `${rulePath}.isEnabled must be a boolean`
|
|
704
|
+
};
|
|
705
|
+
const maxEventsPerBatch = ruleValue["maxEventsPerBatch"];
|
|
706
|
+
if (maxEventsPerBatch !== void 0 && (typeof maxEventsPerBatch !== "number" || !Number.isInteger(maxEventsPerBatch) || maxEventsPerBatch < 1)) return {
|
|
707
|
+
code: "bad_request",
|
|
708
|
+
message: `${rulePath}.maxEventsPerBatch must be a positive integer`
|
|
709
|
+
};
|
|
710
|
+
const name = ruleValue["name"];
|
|
711
|
+
if (typeof name !== "string" || name.length === 0) return {
|
|
712
|
+
code: "bad_request",
|
|
713
|
+
message: `${rulePath}.name must be a non-empty string`
|
|
714
|
+
};
|
|
715
|
+
if (names.has(name)) return {
|
|
716
|
+
code: "bad_request",
|
|
717
|
+
message: `${rulePath}.name must be unique within eventNotificationRules`
|
|
718
|
+
};
|
|
719
|
+
names.add(name);
|
|
720
|
+
const eventTypes = ruleValue["eventTypes"];
|
|
721
|
+
if (!Array.isArray(eventTypes) || eventTypes.length === 0) return {
|
|
722
|
+
code: "bad_request",
|
|
723
|
+
message: `${rulePath}.eventTypes must be a non-empty array`
|
|
724
|
+
};
|
|
725
|
+
for (const eventType of eventTypes) if (typeof eventType !== "string" || !KNOWN_NOTIFICATION_EVENT_TYPES.has(eventType)) return {
|
|
726
|
+
code: "bad_request",
|
|
727
|
+
message: `${rulePath}.eventTypes contains an unknown event type`
|
|
728
|
+
};
|
|
729
|
+
const targetConfiguration = ruleValue["targetConfiguration"];
|
|
730
|
+
if (!isRecord(targetConfiguration)) return {
|
|
731
|
+
code: "bad_request",
|
|
732
|
+
message: `${rulePath}.targetConfiguration must be an object`
|
|
733
|
+
};
|
|
734
|
+
const targetFieldError = validateKnownFields(targetConfiguration, NOTIFICATION_TARGET_FIELDS, `${rulePath}.targetConfiguration`);
|
|
735
|
+
if (targetFieldError) return targetFieldError;
|
|
736
|
+
if (targetConfiguration["targetType"] !== "webhook") return {
|
|
737
|
+
code: "bad_request",
|
|
738
|
+
message: `${rulePath}.targetConfiguration.targetType must be "webhook"`
|
|
739
|
+
};
|
|
740
|
+
const url = targetConfiguration["url"];
|
|
741
|
+
if (typeof url !== "string") return {
|
|
742
|
+
code: "bad_request",
|
|
743
|
+
message: `${rulePath}.targetConfiguration.url must be a valid https URL`
|
|
744
|
+
};
|
|
745
|
+
try {
|
|
746
|
+
if (new URL(url).protocol !== "https:") return {
|
|
747
|
+
code: "bad_request",
|
|
748
|
+
message: `${rulePath}.targetConfiguration.url must be a valid https URL`
|
|
749
|
+
};
|
|
750
|
+
} catch {
|
|
751
|
+
return {
|
|
752
|
+
code: "bad_request",
|
|
753
|
+
message: `${rulePath}.targetConfiguration.url must be a valid https URL`
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
197
759
|
//#endregion
|
|
198
|
-
export { BUCKET_INFO_MAX_KEYS, BUCKET_INFO_VALUE_MAX, BUCKET_NAME_MAX, BUCKET_NAME_MIN, FILE_INFO_TOTAL_MAX, FILE_INFO_VALUE_MAX, FILE_NAME_MAX_BYTES, LIST_ENDPOINT_CAPS, validateBucketInfo, validateBucketName, validateFileInfo, validateFileName, validateMaxCount };
|
|
760
|
+
export { BUCKET_INFO_MAX_KEYS, BUCKET_INFO_VALUE_MAX, BUCKET_NAME_MAX, BUCKET_NAME_MIN, DOWNLOAD_AUTH_DURATION_MAX_SECONDS, DOWNLOAD_AUTH_DURATION_MIN_SECONDS, FILE_INFO_TOTAL_MAX, FILE_INFO_VALUE_MAX, FILE_NAME_MAX_BYTES, KEY_NAME_MAX, KEY_NAME_MIN, LIST_ENDPOINT_CAPS, normalizeCreateKeyCapabilities, validateBucketInfo, validateBucketName, validateBucketTypes, validateCorsRules, validateCreateKeyCapabilities, validateCreateKeyName, validateDefaultRetention, validateDownloadAuthorizationDuration, validateDownloadAuthorizationPrefix, validateFileInfo, validateFileName, validateLifecycleRules, validateMaxCount, validateNotificationRules, validateReplicationConfiguration };
|
|
199
761
|
|
|
200
762
|
//# sourceMappingURL=validation.js.map
|