@backblaze-labs/b2-sdk 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -1
- package/README.md +18 -5
- package/dist/_virtual/_b2-sdk-version-json.cjs +1 -1
- package/dist/_virtual/_b2-sdk-version-json.js +1 -1
- package/dist/auth/reauth-coalescer.cjs +65 -0
- package/dist/auth/reauth-coalescer.cjs.map +1 -0
- package/dist/auth/reauth-coalescer.d.cts +34 -0
- package/dist/auth/reauth-coalescer.d.cts.map +1 -0
- package/dist/auth/reauth-coalescer.d.ts +34 -0
- package/dist/auth/reauth-coalescer.d.ts.map +1 -0
- package/dist/auth/reauth-coalescer.js +65 -0
- package/dist/auth/reauth-coalescer.js.map +1 -0
- package/dist/backup/raw.cjs +37 -15
- package/dist/backup/raw.cjs.map +1 -1
- package/dist/backup/raw.d.cts +2 -2
- package/dist/backup/raw.d.cts.map +1 -1
- package/dist/backup/raw.d.ts +2 -2
- package/dist/backup/raw.d.ts.map +1 -1
- package/dist/backup/raw.js +37 -15
- package/dist/backup/raw.js.map +1 -1
- package/dist/bucket-validation.cjs +111 -0
- package/dist/bucket-validation.cjs.map +1 -0
- package/dist/bucket-validation.d.cts +27 -0
- package/dist/bucket-validation.d.cts.map +1 -0
- package/dist/bucket-validation.d.ts +27 -0
- package/dist/bucket-validation.d.ts.map +1 -0
- package/dist/bucket-validation.js +109 -0
- package/dist/bucket-validation.js.map +1 -0
- package/dist/bucket.cjs +123 -73
- package/dist/bucket.cjs.map +1 -1
- package/dist/bucket.d.cts +156 -61
- package/dist/bucket.d.cts.map +1 -1
- package/dist/bucket.d.ts +156 -61
- package/dist/bucket.d.ts.map +1 -1
- package/dist/bucket.js +123 -73
- package/dist/bucket.js.map +1 -1
- package/dist/client.cjs +29 -8
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +30 -9
- package/dist/client.d.cts.map +1 -1
- package/dist/client.d.ts +30 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -8
- package/dist/client.js.map +1 -1
- package/dist/download/single.cjs +38 -13
- package/dist/download/single.cjs.map +1 -1
- package/dist/download/single.d.cts +10 -4
- package/dist/download/single.d.cts.map +1 -1
- package/dist/download/single.d.ts +10 -4
- package/dist/download/single.d.ts.map +1 -1
- package/dist/download/single.js +38 -13
- package/dist/download/single.js.map +1 -1
- package/dist/errors/index.cjs +27 -4
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +15 -0
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +15 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +27 -5
- package/dist/errors/index.js.map +1 -1
- package/dist/http/non-idempotent-mutations.cjs +38 -0
- package/dist/http/non-idempotent-mutations.cjs.map +1 -0
- package/dist/http/non-idempotent-mutations.d.cts +25 -0
- package/dist/http/non-idempotent-mutations.d.cts.map +1 -0
- package/dist/http/non-idempotent-mutations.d.ts +25 -0
- package/dist/http/non-idempotent-mutations.d.ts.map +1 -0
- package/dist/http/non-idempotent-mutations.js +35 -0
- package/dist/http/non-idempotent-mutations.js.map +1 -0
- package/dist/http/transport.cjs +9 -8
- package/dist/http/transport.cjs.map +1 -1
- package/dist/http/transport.d.cts +5 -0
- package/dist/http/transport.d.cts.map +1 -1
- package/dist/http/transport.d.ts +5 -0
- package/dist/http/transport.d.ts.map +1 -1
- package/dist/http/transport.js +9 -8
- package/dist/http/transport.js.map +1 -1
- package/dist/http/user-agent.cjs +12 -1
- package/dist/http/user-agent.cjs.map +1 -1
- package/dist/http/user-agent.d.cts +8 -0
- package/dist/http/user-agent.d.cts.map +1 -1
- package/dist/http/user-agent.d.ts +8 -0
- package/dist/http/user-agent.d.ts.map +1 -1
- package/dist/http/user-agent.js +13 -3
- package/dist/http/user-agent.js.map +1 -1
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +10 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/notifications/index.cjs +3 -0
- package/dist/notifications/index.d.cts +2 -0
- package/dist/notifications/index.d.cts.map +1 -1
- package/dist/notifications/index.d.ts +2 -0
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +2 -1
- package/dist/object.cjs +12 -1
- package/dist/object.cjs.map +1 -1
- package/dist/object.d.cts +7 -1
- package/dist/object.d.cts.map +1 -1
- package/dist/object.d.ts +7 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +12 -1
- package/dist/object.js.map +1 -1
- package/dist/partner/auth-core.cjs +4 -23
- package/dist/partner/auth-core.cjs.map +1 -1
- package/dist/partner/auth-core.d.cts +1 -1
- package/dist/partner/auth-core.d.cts.map +1 -1
- package/dist/partner/auth-core.d.ts +1 -1
- package/dist/partner/auth-core.d.ts.map +1 -1
- package/dist/partner/auth-core.js +5 -24
- package/dist/partner/auth-core.js.map +1 -1
- package/dist/partner/client.cjs +25 -10
- package/dist/partner/client.cjs.map +1 -1
- package/dist/partner/client.d.cts +32 -10
- package/dist/partner/client.d.cts.map +1 -1
- package/dist/partner/client.d.ts +32 -10
- package/dist/partner/client.d.ts.map +1 -1
- package/dist/partner/client.js +25 -10
- package/dist/partner/client.js.map +1 -1
- package/dist/partner/endpoint-url.cjs +1 -0
- package/dist/partner/endpoint-url.cjs.map +1 -1
- package/dist/partner/endpoint-url.d.cts +2 -0
- package/dist/partner/endpoint-url.d.cts.map +1 -1
- package/dist/partner/endpoint-url.d.ts +2 -0
- package/dist/partner/endpoint-url.d.ts.map +1 -1
- package/dist/partner/endpoint-url.js +1 -0
- package/dist/partner/endpoint-url.js.map +1 -1
- package/dist/partner/in-memory.cjs.map +1 -1
- package/dist/partner/in-memory.js.map +1 -1
- package/dist/partner/index.cjs +9 -0
- package/dist/partner/index.d.cts +11 -2
- package/dist/partner/index.d.cts.map +1 -1
- package/dist/partner/index.d.ts +11 -2
- package/dist/partner/index.d.ts.map +1 -1
- package/dist/partner/index.js +3 -1
- package/dist/partner/raw.cjs +52 -44
- package/dist/partner/raw.cjs.map +1 -1
- package/dist/partner/raw.d.cts +16 -19
- package/dist/partner/raw.d.cts.map +1 -1
- package/dist/partner/raw.d.ts +16 -19
- package/dist/partner/raw.d.ts.map +1 -1
- package/dist/partner/raw.js +52 -44
- package/dist/partner/raw.js.map +1 -1
- package/dist/partner/redaction.cjs +133 -108
- package/dist/partner/redaction.cjs.map +1 -1
- package/dist/partner/redaction.d.cts +47 -13
- package/dist/partner/redaction.d.cts.map +1 -1
- package/dist/partner/redaction.d.ts +47 -13
- package/dist/partner/redaction.d.ts.map +1 -1
- package/dist/partner/redaction.js +133 -109
- package/dist/partner/redaction.js.map +1 -1
- package/dist/raw/encoding.cjs +29 -10
- package/dist/raw/encoding.cjs.map +1 -1
- package/dist/raw/encoding.d.cts +3 -2
- package/dist/raw/encoding.d.cts.map +1 -1
- package/dist/raw/encoding.d.ts +3 -2
- package/dist/raw/encoding.d.ts.map +1 -1
- package/dist/raw/encoding.js +29 -10
- package/dist/raw/encoding.js.map +1 -1
- package/dist/raw/index.cjs +64 -39
- package/dist/raw/index.cjs.map +1 -1
- package/dist/raw/index.d.cts +21 -19
- package/dist/raw/index.d.cts.map +1 -1
- package/dist/raw/index.d.ts +21 -19
- package/dist/raw/index.d.ts.map +1 -1
- package/dist/raw/index.js +47 -40
- package/dist/raw/index.js.map +1 -1
- package/dist/raw/url.cjs.map +1 -1
- package/dist/raw/url.d.cts +3 -3
- package/dist/raw/url.d.ts +3 -3
- package/dist/raw/url.js.map +1 -1
- package/dist/simulator/index.cjs +456 -125
- package/dist/simulator/index.cjs.map +1 -1
- package/dist/simulator/index.d.cts +16 -1
- package/dist/simulator/index.d.cts.map +1 -1
- package/dist/simulator/index.d.ts +16 -1
- package/dist/simulator/index.d.ts.map +1 -1
- package/dist/simulator/index.js +449 -130
- package/dist/simulator/index.js.map +1 -1
- package/dist/simulator/partner-capabilities.cjs +77 -0
- package/dist/simulator/partner-capabilities.cjs.map +1 -0
- package/dist/simulator/partner-capabilities.d.cts +53 -0
- package/dist/simulator/partner-capabilities.d.cts.map +1 -0
- package/dist/simulator/partner-capabilities.d.ts +53 -0
- package/dist/simulator/partner-capabilities.d.ts.map +1 -0
- package/dist/simulator/partner-capabilities.js +73 -0
- package/dist/simulator/partner-capabilities.js.map +1 -0
- package/dist/simulator/partner.cjs +55 -61
- package/dist/simulator/partner.cjs.map +1 -1
- package/dist/simulator/partner.d.cts +5 -2
- package/dist/simulator/partner.d.cts.map +1 -1
- package/dist/simulator/partner.d.ts +5 -2
- package/dist/simulator/partner.d.ts.map +1 -1
- package/dist/simulator/partner.js +56 -61
- package/dist/simulator/partner.js.map +1 -1
- package/dist/simulator/validation.cjs +160 -30
- package/dist/simulator/validation.cjs.map +1 -1
- package/dist/simulator/validation.d.cts +28 -6
- package/dist/simulator/validation.d.cts.map +1 -1
- package/dist/simulator/validation.d.ts +28 -6
- package/dist/simulator/validation.d.ts.map +1 -1
- package/dist/simulator/validation.js +148 -31
- 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/hash.cjs +246 -13
- package/dist/streams/hash.cjs.map +1 -1
- package/dist/streams/hash.d.cts +37 -12
- package/dist/streams/hash.d.cts.map +1 -1
- package/dist/streams/hash.d.ts +37 -12
- package/dist/streams/hash.d.ts.map +1 -1
- package/dist/streams/hash.js +246 -15
- package/dist/streams/hash.js.map +1 -1
- package/dist/streams/index.cjs +2 -0
- package/dist/streams/index.d.cts +1 -1
- package/dist/streams/index.d.cts.map +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/streams/index.d.ts.map +1 -1
- package/dist/streams/index.js +2 -2
- package/dist/streams/progress.cjs +63 -4
- package/dist/streams/progress.cjs.map +1 -1
- package/dist/streams/progress.d.cts +28 -2
- package/dist/streams/progress.d.cts.map +1 -1
- package/dist/streams/progress.d.ts +28 -2
- package/dist/streams/progress.d.ts.map +1 -1
- package/dist/streams/progress.js +63 -4
- package/dist/streams/progress.js.map +1 -1
- package/dist/sync/download-staging.cjs +147 -35
- package/dist/sync/download-staging.cjs.map +1 -1
- package/dist/sync/download-staging.d.cts +25 -2
- package/dist/sync/download-staging.d.cts.map +1 -1
- package/dist/sync/download-staging.d.ts +25 -2
- package/dist/sync/download-staging.d.ts.map +1 -1
- package/dist/sync/download-staging.js +146 -36
- package/dist/sync/download-staging.js.map +1 -1
- package/dist/sync/index.d.cts +1 -1
- package/dist/sync/index.d.cts.map +1 -1
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/local-file-io.cjs +5 -1
- package/dist/sync/local-file-io.cjs.map +1 -1
- package/dist/sync/local-file-io.d.cts +2 -0
- package/dist/sync/local-file-io.d.cts.map +1 -1
- package/dist/sync/local-file-io.d.ts +2 -0
- package/dist/sync/local-file-io.d.ts.map +1 -1
- package/dist/sync/local-file-io.js +5 -1
- package/dist/sync/local-file-io.js.map +1 -1
- package/dist/sync/pairing.cjs +1 -0
- package/dist/sync/pairing.cjs.map +1 -1
- package/dist/sync/pairing.js +1 -0
- package/dist/sync/pairing.js.map +1 -1
- package/dist/sync/scanners/b2.cjs +2 -0
- package/dist/sync/scanners/b2.cjs.map +1 -1
- package/dist/sync/scanners/b2.d.cts.map +1 -1
- package/dist/sync/scanners/b2.d.ts.map +1 -1
- package/dist/sync/scanners/b2.js +2 -0
- package/dist/sync/scanners/b2.js.map +1 -1
- package/dist/sync/scanners/local.cjs +150 -33
- package/dist/sync/scanners/local.cjs.map +1 -1
- package/dist/sync/scanners/local.d.cts +6 -0
- package/dist/sync/scanners/local.d.cts.map +1 -1
- package/dist/sync/scanners/local.d.ts +6 -0
- package/dist/sync/scanners/local.d.ts.map +1 -1
- package/dist/sync/scanners/local.js +150 -33
- package/dist/sync/scanners/local.js.map +1 -1
- package/dist/sync/synchronizer.cjs +76 -29
- package/dist/sync/synchronizer.cjs.map +1 -1
- package/dist/sync/synchronizer.d.cts +1 -0
- package/dist/sync/synchronizer.d.cts.map +1 -1
- package/dist/sync/synchronizer.d.ts +1 -0
- package/dist/sync/synchronizer.d.ts.map +1 -1
- package/dist/sync/synchronizer.js +76 -29
- package/dist/sync/synchronizer.js.map +1 -1
- package/dist/sync/types.d.cts +19 -3
- package/dist/sync/types.d.cts.map +1 -1
- package/dist/sync/types.d.ts +19 -3
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/types/backup.d.cts +6 -1
- package/dist/types/backup.d.cts.map +1 -1
- package/dist/types/backup.d.ts +6 -1
- package/dist/types/backup.d.ts.map +1 -1
- package/dist/types/bucket.cjs +81 -11
- package/dist/types/bucket.cjs.map +1 -1
- package/dist/types/bucket.d.cts +190 -39
- package/dist/types/bucket.d.cts.map +1 -1
- package/dist/types/bucket.d.ts +190 -39
- package/dist/types/bucket.d.ts.map +1 -1
- package/dist/types/bucket.js +67 -12
- package/dist/types/bucket.js.map +1 -1
- package/dist/types/download.cjs.map +1 -1
- package/dist/types/download.d.cts +3 -17
- package/dist/types/download.d.cts.map +1 -1
- package/dist/types/download.d.ts +3 -17
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/download.js.map +1 -1
- package/dist/types/encryption.cjs +18 -0
- package/dist/types/encryption.cjs.map +1 -1
- package/dist/types/encryption.d.cts +21 -11
- package/dist/types/encryption.d.cts.map +1 -1
- package/dist/types/encryption.d.ts +21 -11
- package/dist/types/encryption.d.ts.map +1 -1
- package/dist/types/encryption.js +18 -0
- package/dist/types/encryption.js.map +1 -1
- package/dist/types/file.cjs +3 -0
- package/dist/types/file.cjs.map +1 -1
- package/dist/types/file.d.cts +125 -16
- package/dist/types/file.d.cts.map +1 -1
- package/dist/types/file.d.ts +125 -16
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/file.js +3 -1
- package/dist/types/file.js.map +1 -1
- package/dist/types/index.d.cts +7 -7
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key.d.cts +4 -3
- package/dist/types/key.d.cts.map +1 -1
- package/dist/types/key.d.ts +4 -3
- package/dist/types/key.d.ts.map +1 -1
- package/dist/types/notifications.cjs +30 -0
- package/dist/types/notifications.cjs.map +1 -1
- package/dist/types/notifications.d.cts +26 -1
- package/dist/types/notifications.d.cts.map +1 -1
- package/dist/types/notifications.d.ts +26 -1
- package/dist/types/notifications.d.ts.map +1 -1
- package/dist/types/notifications.js +29 -1
- package/dist/types/notifications.js.map +1 -1
- package/dist/types/partner.cjs.map +1 -1
- package/dist/types/partner.d.cts +28 -36
- package/dist/types/partner.d.cts.map +1 -1
- package/dist/types/partner.d.ts +28 -36
- package/dist/types/partner.d.ts.map +1 -1
- package/dist/types/partner.js.map +1 -1
- package/dist/types/upload.d.cts +4 -0
- package/dist/types/upload.d.cts.map +1 -1
- package/dist/types/upload.d.ts +4 -0
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/large.cjs +10 -7
- package/dist/upload/large.cjs.map +1 -1
- package/dist/upload/large.d.cts +15 -6
- package/dist/upload/large.d.cts.map +1 -1
- package/dist/upload/large.d.ts +15 -6
- package/dist/upload/large.d.ts.map +1 -1
- package/dist/upload/large.js +10 -7
- 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 +4 -3
- package/dist/upload/resume.cjs.map +1 -1
- package/dist/upload/resume.d.cts +6 -4
- package/dist/upload/resume.d.cts.map +1 -1
- package/dist/upload/resume.d.ts +6 -4
- package/dist/upload/resume.d.ts.map +1 -1
- package/dist/upload/resume.js +4 -3
- package/dist/upload/resume.js.map +1 -1
- package/dist/upload/retry.cjs +17 -10
- package/dist/upload/retry.cjs.map +1 -1
- package/dist/upload/retry.d.cts.map +1 -1
- package/dist/upload/retry.d.ts.map +1 -1
- package/dist/upload/retry.js +17 -10
- package/dist/upload/retry.js.map +1 -1
- package/dist/upload/single.cjs +35 -31
- 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 +35 -31
- package/dist/upload/single.js.map +1 -1
- package/dist/upload/stream.cjs +12 -1
- 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 +12 -1
- package/dist/upload/stream.js.map +1 -1
- package/dist/version.cjs +56 -4
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +53 -4
- package/dist/version.d.cts.map +1 -1
- package/dist/version.d.ts +53 -4
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +52 -5
- package/dist/version.js.map +1 -1
- package/package.json +11 -4
package/dist/client.d.cts
CHANGED
|
@@ -5,8 +5,7 @@ import { HttpTransport } from './http/transport.js';
|
|
|
5
5
|
import { UrlGuard } from './http/url-guard.js';
|
|
6
6
|
import { RawClient } from './raw/index.js';
|
|
7
7
|
import { AuthorizeAccountResponse, Capability } from './types/auth.js';
|
|
8
|
-
import { BucketInfo, BucketRetentionPolicy, BucketType, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
9
|
-
import { EncryptionSetting } from './types/encryption.js';
|
|
8
|
+
import { BucketDefaultServerSideEncryptionSetting, BucketInfo, BucketRetentionPolicy, BucketType, BucketTypesFilter, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
10
9
|
import { ApplicationKeyId, BucketId } from './types/ids.js';
|
|
11
10
|
import { ApplicationKey, CreateKeyOptions, FullApplicationKey, ListKeysResponse } from './types/key.js';
|
|
12
11
|
import { ReplicationConfiguration } from './types/replication.js';
|
|
@@ -64,6 +63,11 @@ export interface B2ClientOptions {
|
|
|
64
63
|
*/
|
|
65
64
|
readonly followSameOriginRedirects?: boolean;
|
|
66
65
|
}
|
|
66
|
+
/** Options for {@link B2Client.authorize}. */
|
|
67
|
+
export interface B2ClientAuthorizeOptions {
|
|
68
|
+
/** Abort signal for cancelling the authorize request. */
|
|
69
|
+
readonly signal?: AbortSignal;
|
|
70
|
+
}
|
|
67
71
|
/**
|
|
68
72
|
* High-level B2 client providing ergonomic access to buckets, files, and keys.
|
|
69
73
|
*
|
|
@@ -93,6 +97,7 @@ export declare class B2Client {
|
|
|
93
97
|
private readonly realmUrl;
|
|
94
98
|
private readonly userAllowedSuffixes;
|
|
95
99
|
private readonly resolvedUploadRetryOptions;
|
|
100
|
+
private readonly reauthCoalescer;
|
|
96
101
|
/**
|
|
97
102
|
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
98
103
|
* @param options - Configuration including credentials, realm, and transport settings.
|
|
@@ -101,18 +106,23 @@ export declare class B2Client {
|
|
|
101
106
|
/**
|
|
102
107
|
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
103
108
|
*
|
|
109
|
+
* @param options - Optional request controls.
|
|
110
|
+
*
|
|
104
111
|
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
105
112
|
*/
|
|
106
|
-
authorize(): Promise<AuthorizeAccountResponse>;
|
|
113
|
+
authorize(options?: B2ClientAuthorizeOptions): Promise<AuthorizeAccountResponse>;
|
|
107
114
|
private lockUrlGuard;
|
|
108
115
|
/**
|
|
109
116
|
* Refresh credentials after a 401. Returns the fresh auth token so
|
|
110
117
|
* {@link RetryTransport} can rewrite the in-flight request's
|
|
111
118
|
* Authorization header before retrying.
|
|
112
119
|
*
|
|
120
|
+
* @param signal - Optional abort signal for the request that triggered reauthorization.
|
|
121
|
+
*
|
|
113
122
|
* @returns The fresh authorization token.
|
|
114
123
|
*/
|
|
115
124
|
private reauthorize;
|
|
125
|
+
private doReauthorize;
|
|
116
126
|
/**
|
|
117
127
|
* Creates a new B2 bucket.
|
|
118
128
|
* @param options - Bucket configuration including name, type, and optional settings.
|
|
@@ -124,12 +134,23 @@ export declare class B2Client {
|
|
|
124
134
|
bucketName: string;
|
|
125
135
|
/** Access level: `"allPrivate"` or `"allPublic"`. */
|
|
126
136
|
bucketType: BucketType;
|
|
127
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Custom key-value metadata stored with the bucket. Keys must be 1-50
|
|
139
|
+
* UTF-8 bytes, must not start with `b2-`, and all values together must be
|
|
140
|
+
* at most 10,000 UTF-8 bytes. Keys must match
|
|
141
|
+
* {@link BUCKET_INFO_KEY_PATTERN}. There is no bucketInfo pair-count cap.
|
|
142
|
+
*/
|
|
128
143
|
bucketInfo?: Record<string, string>;
|
|
129
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* CORS rules for browser-based access. A bucket may have at most 100
|
|
146
|
+
* rules; rule names must be unique, 6-63 characters, match
|
|
147
|
+
* `[A-Za-z0-9-]`, and not start with `b2-`. Each rule must be less than
|
|
148
|
+
* 1,000 UTF-8 bytes across its name, origins, operations, allowed headers,
|
|
149
|
+
* and exposed headers. `maxAgeSeconds` must be at most 86,400.
|
|
150
|
+
*/
|
|
130
151
|
corsRules?: CorsRule[];
|
|
131
152
|
/** Default server-side encryption for new files. */
|
|
132
|
-
defaultServerSideEncryption?:
|
|
153
|
+
defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting;
|
|
133
154
|
/** Default retention policy for new files (requires file lock). */
|
|
134
155
|
defaultRetention?: BucketRetentionPolicy;
|
|
135
156
|
/** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */
|
|
@@ -150,8 +171,8 @@ export declare class B2Client {
|
|
|
150
171
|
bucketId?: BucketId;
|
|
151
172
|
/** Filter to a specific bucket by name. */
|
|
152
173
|
bucketName?: string;
|
|
153
|
-
/** Filter by bucket types (e.g., `["allPrivate"]`). */
|
|
154
|
-
bucketTypes?:
|
|
174
|
+
/** Filter by bucket types (e.g., `["allPrivate"]`, `["shared"]`, or `["all"]`). */
|
|
175
|
+
bucketTypes?: BucketTypesFilter;
|
|
155
176
|
}): Promise<Bucket[]>;
|
|
156
177
|
/**
|
|
157
178
|
* Looks up a single bucket by name.
|
|
@@ -186,7 +207,7 @@ export declare class B2Client {
|
|
|
186
207
|
* raw API's `maxKeyCount` parameter.
|
|
187
208
|
*/
|
|
188
209
|
pageSize?: number;
|
|
189
|
-
/** Start listing
|
|
210
|
+
/** Start listing at this key ID, usually from `nextApplicationKeyId`. */
|
|
190
211
|
startApplicationKeyId?: ApplicationKeyId;
|
|
191
212
|
}): Promise<ListKeysResponse>;
|
|
192
213
|
/**
|
package/dist/client.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAIzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD,OAAO,EAAyB,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC3E,OAAO,KAAK,EACV,wCAAwC,EACxC,U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 +5,7 @@ import { HttpTransport } from './http/transport.js';
|
|
|
5
5
|
import { UrlGuard } from './http/url-guard.js';
|
|
6
6
|
import { RawClient } from './raw/index.js';
|
|
7
7
|
import { AuthorizeAccountResponse, Capability } from './types/auth.js';
|
|
8
|
-
import { BucketInfo, BucketRetentionPolicy, BucketType, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
9
|
-
import { EncryptionSetting } from './types/encryption.js';
|
|
8
|
+
import { BucketDefaultServerSideEncryptionSetting, BucketInfo, BucketRetentionPolicy, BucketType, BucketTypesFilter, CorsRule, LifecycleRule } from './types/bucket.js';
|
|
10
9
|
import { ApplicationKeyId, BucketId } from './types/ids.js';
|
|
11
10
|
import { ApplicationKey, CreateKeyOptions, FullApplicationKey, ListKeysResponse } from './types/key.js';
|
|
12
11
|
import { ReplicationConfiguration } from './types/replication.js';
|
|
@@ -64,6 +63,11 @@ export interface B2ClientOptions {
|
|
|
64
63
|
*/
|
|
65
64
|
readonly followSameOriginRedirects?: boolean;
|
|
66
65
|
}
|
|
66
|
+
/** Options for {@link B2Client.authorize}. */
|
|
67
|
+
export interface B2ClientAuthorizeOptions {
|
|
68
|
+
/** Abort signal for cancelling the authorize request. */
|
|
69
|
+
readonly signal?: AbortSignal;
|
|
70
|
+
}
|
|
67
71
|
/**
|
|
68
72
|
* High-level B2 client providing ergonomic access to buckets, files, and keys.
|
|
69
73
|
*
|
|
@@ -93,6 +97,7 @@ export declare class B2Client {
|
|
|
93
97
|
private readonly realmUrl;
|
|
94
98
|
private readonly userAllowedSuffixes;
|
|
95
99
|
private readonly resolvedUploadRetryOptions;
|
|
100
|
+
private readonly reauthCoalescer;
|
|
96
101
|
/**
|
|
97
102
|
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
98
103
|
* @param options - Configuration including credentials, realm, and transport settings.
|
|
@@ -101,18 +106,23 @@ export declare class B2Client {
|
|
|
101
106
|
/**
|
|
102
107
|
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
103
108
|
*
|
|
109
|
+
* @param options - Optional request controls.
|
|
110
|
+
*
|
|
104
111
|
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
105
112
|
*/
|
|
106
|
-
authorize(): Promise<AuthorizeAccountResponse>;
|
|
113
|
+
authorize(options?: B2ClientAuthorizeOptions): Promise<AuthorizeAccountResponse>;
|
|
107
114
|
private lockUrlGuard;
|
|
108
115
|
/**
|
|
109
116
|
* Refresh credentials after a 401. Returns the fresh auth token so
|
|
110
117
|
* {@link RetryTransport} can rewrite the in-flight request's
|
|
111
118
|
* Authorization header before retrying.
|
|
112
119
|
*
|
|
120
|
+
* @param signal - Optional abort signal for the request that triggered reauthorization.
|
|
121
|
+
*
|
|
113
122
|
* @returns The fresh authorization token.
|
|
114
123
|
*/
|
|
115
124
|
private reauthorize;
|
|
125
|
+
private doReauthorize;
|
|
116
126
|
/**
|
|
117
127
|
* Creates a new B2 bucket.
|
|
118
128
|
* @param options - Bucket configuration including name, type, and optional settings.
|
|
@@ -124,12 +134,23 @@ export declare class B2Client {
|
|
|
124
134
|
bucketName: string;
|
|
125
135
|
/** Access level: `"allPrivate"` or `"allPublic"`. */
|
|
126
136
|
bucketType: BucketType;
|
|
127
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Custom key-value metadata stored with the bucket. Keys must be 1-50
|
|
139
|
+
* UTF-8 bytes, must not start with `b2-`, and all values together must be
|
|
140
|
+
* at most 10,000 UTF-8 bytes. Keys must match
|
|
141
|
+
* {@link BUCKET_INFO_KEY_PATTERN}. There is no bucketInfo pair-count cap.
|
|
142
|
+
*/
|
|
128
143
|
bucketInfo?: Record<string, string>;
|
|
129
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* CORS rules for browser-based access. A bucket may have at most 100
|
|
146
|
+
* rules; rule names must be unique, 6-63 characters, match
|
|
147
|
+
* `[A-Za-z0-9-]`, and not start with `b2-`. Each rule must be less than
|
|
148
|
+
* 1,000 UTF-8 bytes across its name, origins, operations, allowed headers,
|
|
149
|
+
* and exposed headers. `maxAgeSeconds` must be at most 86,400.
|
|
150
|
+
*/
|
|
130
151
|
corsRules?: CorsRule[];
|
|
131
152
|
/** Default server-side encryption for new files. */
|
|
132
|
-
defaultServerSideEncryption?:
|
|
153
|
+
defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting;
|
|
133
154
|
/** Default retention policy for new files (requires file lock). */
|
|
134
155
|
defaultRetention?: BucketRetentionPolicy;
|
|
135
156
|
/** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */
|
|
@@ -150,8 +171,8 @@ export declare class B2Client {
|
|
|
150
171
|
bucketId?: BucketId;
|
|
151
172
|
/** Filter to a specific bucket by name. */
|
|
152
173
|
bucketName?: string;
|
|
153
|
-
/** Filter by bucket types (e.g., `["allPrivate"]`). */
|
|
154
|
-
bucketTypes?:
|
|
174
|
+
/** Filter by bucket types (e.g., `["allPrivate"]`, `["shared"]`, or `["all"]`). */
|
|
175
|
+
bucketTypes?: BucketTypesFilter;
|
|
155
176
|
}): Promise<Bucket[]>;
|
|
156
177
|
/**
|
|
157
178
|
* Looks up a single bucket by name.
|
|
@@ -186,7 +207,7 @@ export declare class B2Client {
|
|
|
186
207
|
* raw API's `maxKeyCount` parameter.
|
|
187
208
|
*/
|
|
188
209
|
pageSize?: number;
|
|
189
|
-
/** Start listing
|
|
210
|
+
/** Start listing at this key ID, usually from `nextApplicationKeyId`. */
|
|
190
211
|
startApplicationKeyId?: ApplicationKeyId;
|
|
191
212
|
}): Promise<ListKeysResponse>;
|
|
192
213
|
/**
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,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E;QACzE,qBAAqB,CAAC,EAAE,gBAAgB,CAAA;KACzC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAU7B;;;;;;;;;;;;;;;OAeG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,qBAAqB,CAAC,cAAc,CAAC;IAc/E;;;;;OAKG;IACG,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAM5E;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,qBAAqB;CAOtE"}
|
package/dist/client.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { InMemoryAccountInfo } from "./auth/in-memory.js";
|
|
2
2
|
import { accountId } from "./types/ids.js";
|
|
3
|
+
import { throwIfSignalAborted } from "./util/abort.js";
|
|
3
4
|
import "./util/defaults.js";
|
|
4
5
|
import { DEFAULT_RETRY_OPTIONS } from "./http/retry.js";
|
|
5
6
|
import { paginateItems } from "./util/paginator.js";
|
|
6
7
|
import { Bucket } from "./bucket.js";
|
|
7
8
|
import { getRealmUrl } from "./auth/realms.js";
|
|
9
|
+
import { ReauthCoalescer } from "./auth/reauth-coalescer.js";
|
|
8
10
|
import { UrlGuard, deriveAllowedSuffixes } from "./http/url-guard.js";
|
|
9
11
|
import { FetchTransport, RetryTransport } from "./http/transport.js";
|
|
10
12
|
import { RawClient } from "./raw/index.js";
|
|
@@ -38,6 +40,7 @@ var B2Client = class {
|
|
|
38
40
|
realmUrl;
|
|
39
41
|
userAllowedSuffixes;
|
|
40
42
|
resolvedUploadRetryOptions;
|
|
43
|
+
reauthCoalescer;
|
|
41
44
|
/**
|
|
42
45
|
* Creates a new B2Client. Call {@link authorize} before making API requests.
|
|
43
46
|
* @param options - Configuration including credentials, realm, and transport settings.
|
|
@@ -53,6 +56,7 @@ var B2Client = class {
|
|
|
53
56
|
...DEFAULT_RETRY_OPTIONS,
|
|
54
57
|
...options.retry
|
|
55
58
|
};
|
|
59
|
+
this.reauthCoalescer = new ReauthCoalescer((signal) => this.doReauthorize(signal));
|
|
56
60
|
let baseTransport;
|
|
57
61
|
if (options.transport !== void 0) {
|
|
58
62
|
baseTransport = options.transport;
|
|
@@ -69,7 +73,7 @@ var B2Client = class {
|
|
|
69
73
|
const retryTransport = new RetryTransport({
|
|
70
74
|
transport: baseTransport,
|
|
71
75
|
retry: this.resolvedUploadRetryOptions,
|
|
72
|
-
onReauth: () => this.reauthorize()
|
|
76
|
+
onReauth: (signal) => this.reauthorize(signal)
|
|
73
77
|
});
|
|
74
78
|
const cachedAuth = this.accountInfo.getAuth();
|
|
75
79
|
if (cachedAuth !== null) this.lockUrlGuard(cachedAuth);
|
|
@@ -78,10 +82,14 @@ var B2Client = class {
|
|
|
78
82
|
/**
|
|
79
83
|
* Authenticates with B2 and stores the authorization state. Must be called before other methods.
|
|
80
84
|
*
|
|
85
|
+
* @param options - Optional request controls.
|
|
86
|
+
*
|
|
81
87
|
* @returns The authorization response containing tokens, URLs, and capabilities.
|
|
82
88
|
*/
|
|
83
|
-
async authorize() {
|
|
84
|
-
|
|
89
|
+
async authorize(options) {
|
|
90
|
+
throwIfSignalAborted(options?.signal);
|
|
91
|
+
const auth = await this.raw.authorizeAccount(this.applicationKeyId, this.applicationKey, this.realmUrl, options?.signal !== void 0 ? { signal: options.signal } : void 0);
|
|
92
|
+
throwIfSignalAborted(options?.signal);
|
|
85
93
|
this.accountInfo.setAuth(auth);
|
|
86
94
|
this.lockUrlGuard(auth);
|
|
87
95
|
return auth;
|
|
@@ -98,11 +106,15 @@ var B2Client = class {
|
|
|
98
106
|
* {@link RetryTransport} can rewrite the in-flight request's
|
|
99
107
|
* Authorization header before retrying.
|
|
100
108
|
*
|
|
109
|
+
* @param signal - Optional abort signal for the request that triggered reauthorization.
|
|
110
|
+
*
|
|
101
111
|
* @returns The fresh authorization token.
|
|
102
112
|
*/
|
|
103
|
-
|
|
104
|
-
this.
|
|
105
|
-
|
|
113
|
+
reauthorize(signal) {
|
|
114
|
+
return this.reauthCoalescer.run(signal);
|
|
115
|
+
}
|
|
116
|
+
async doReauthorize(signal) {
|
|
117
|
+
return (await this.authorize({ signal })).authorizationToken;
|
|
106
118
|
}
|
|
107
119
|
/**
|
|
108
120
|
* Creates a new B2 bucket.
|
|
@@ -111,9 +123,18 @@ var B2Client = class {
|
|
|
111
123
|
* @returns A {@link Bucket} handle for the newly created bucket.
|
|
112
124
|
*/
|
|
113
125
|
async createBucket(options) {
|
|
126
|
+
const { bucketInfo, bucketName, bucketType, corsRules, defaultRetention, defaultServerSideEncryption, fileLockEnabled, lifecycleRules, replicationConfiguration } = options;
|
|
114
127
|
const request = {
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
...bucketInfo !== void 0 ? { bucketInfo } : {},
|
|
129
|
+
bucketName,
|
|
130
|
+
bucketType,
|
|
131
|
+
...corsRules !== void 0 ? { corsRules } : {},
|
|
132
|
+
...defaultServerSideEncryption !== void 0 ? { defaultServerSideEncryption } : {},
|
|
133
|
+
...defaultRetention !== void 0 ? { defaultRetention } : {},
|
|
134
|
+
...fileLockEnabled !== void 0 ? { fileLockEnabled } : {},
|
|
135
|
+
...lifecycleRules !== void 0 ? { lifecycleRules } : {},
|
|
136
|
+
...replicationConfiguration !== void 0 ? { replicationConfiguration } : {},
|
|
137
|
+
accountId: accountId(this.accountInfo.getAccountId())
|
|
117
138
|
};
|
|
118
139
|
const info = await this.raw.createBucket(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), request);
|
|
119
140
|
return new Bucket(this, info, this.resolvedUploadRetryOptions);
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { AccountInfo } from './auth/account-info.ts'\nimport { InMemoryAccountInfo } from './auth/in-memory.ts'\nimport { getRealmUrl } from './auth/realms.ts'\nimport { Bucket } from './bucket.ts'\nimport { DEFAULT_RETRY_OPTIONS, type RetryOptions } from './http/retry.ts'\nimport type { HttpTransport } from './http/transport.ts'\nimport { FetchTransport, RetryTransport } from './http/transport.ts'\nimport { deriveAllowedSuffixes, UrlGuard } from './http/url-guard.ts'\nimport { RawClient } from './raw/index.ts'\nimport type { AuthorizeAccountResponse, Capability } from './types/auth.ts'\nimport type {\n BucketInfo,\n BucketRetentionPolicy,\n BucketType,\n CorsRule,\n CreateBucketRequest,\n LifecycleRule,\n} from './types/bucket.ts'\nimport type { EncryptionSetting } from './types/encryption.ts'\nimport type { ApplicationKeyId, BucketId } from './types/ids.ts'\nimport { accountId } from './types/ids.ts'\nimport type {\n ApplicationKey,\n CreateKeyOptions,\n FullApplicationKey,\n ListKeysResponse,\n} from './types/key.ts'\nimport type { ReplicationConfiguration } from './types/replication.ts'\nimport { DEFAULT_PAGE_SIZE } from './util/defaults.ts'\nimport { type PaginatorOptions, paginateItems } from './util/paginator.ts'\n\n/** Result of {@link B2Client.hasCapabilities}. */\nexport interface CapabilityCheckResult {\n /** `true` when the key carries every requested capability. */\n readonly ok: boolean\n /** Capabilities the call requested that the current key does not hold. Empty when `ok` is `true`. */\n readonly missing: readonly Capability[]\n}\n\n/** Configuration options for creating a {@link B2Client}. */\nexport interface B2ClientOptions {\n /** The application key ID from the B2 dashboard or `b2_create_key`. */\n readonly applicationKeyId: string\n /** The application key secret. */\n readonly applicationKey: string\n /**\n * B2 realm to authenticate against. Accepts a known realm-map key\n * (`\"production\"` or `\"staging\"`) or a direct base URL. Custom HTTPS hosts\n * are trusted with the application key during authorize, so never derive\n * `realm` from untrusted input. URL values must use HTTPS, or loopback IP\n * literal HTTP for local testing only; application-key credentials are sent\n * unencrypted over loopback HTTP. Unsupported schemes, malformed URLs,\n * non-URL strings, plaintext HTTP hostnames such as `localhost`, and\n * non-loopback plaintext HTTP are rejected before credentials are sent. URL\n * values must not include userinfo, query strings, or fragments. Defaults to\n * `\"production\"`.\n */\n readonly realm?: string\n /** Storage backend for authorization state. Defaults to {@link InMemoryAccountInfo}. */\n readonly accountInfo?: AccountInfo\n /** Custom HTTP transport. Defaults to {@link FetchTransport}. Wrapped by {@link RetryTransport}. */\n readonly transport?: HttpTransport\n /** Override retry behavior (max retries, backoff, and per-attempt timeout). */\n readonly retry?: Partial<RetryOptions>\n /** Custom user-agent string prepended to the SDK default. */\n readonly userAgent?: string\n /**\n * Override the SSRF allow-list. By default the SDK locks the\n * {@link FetchTransport} to host suffixes derived from the realm's authorize\n * response (e.g. `backblazeb2.com`, `backblaze.com`) so a compromised B2\n * endpoint cannot redirect the SDK to internal services. Pass an explicit\n * list to add hosts (e.g. when testing against a self-hosted proxy) or set\n * to an empty array to disable the guard entirely (not recommended).\n *\n * Only consulted when {@link B2ClientOptions.transport} is unset; a custom\n * transport is the user's responsibility to harden.\n */\n readonly allowedHostSuffixes?: readonly string[]\n /**\n * Follow same-origin GET/HEAD redirects in the default fetch transport after\n * checking each target with the SSRF guard. POST redirects remain blocked.\n * Defaults to true.\n */\n readonly followSameOriginRedirects?: boolean\n}\n\n/**\n * High-level B2 client providing ergonomic access to buckets, files, and keys.\n *\n * @example\n * ```ts\n * const client = new B2Client({\n * applicationKeyId: process.env.B2_APPLICATION_KEY_ID,\n * applicationKey: process.env.B2_APPLICATION_KEY,\n * })\n * await client.authorize()\n * const buckets = await client.listBuckets()\n * ```\n */\nexport class B2Client {\n /** Low-level client for direct B2 API calls. */\n readonly raw: RawClient\n /** Authorization state storage (tokens, URLs, capabilities). */\n readonly accountInfo: AccountInfo\n /**\n * SSRF allow-list applied by the default {@link FetchTransport}. `null` when\n * a custom transport was supplied — in that case the SDK does not own the\n * guard. Locked down by {@link B2Client.authorize}.\n */\n readonly urlGuard: UrlGuard | null\n private readonly applicationKeyId: string\n private readonly applicationKey: string\n private readonly realmUrl: string\n private readonly userAllowedSuffixes: readonly string[] | undefined\n private readonly resolvedUploadRetryOptions: RetryOptions\n\n /**\n * Creates a new B2Client. Call {@link authorize} before making API requests.\n * @param options - Configuration including credentials, realm, and transport settings.\n */\n constructor(options: B2ClientOptions) {\n this.applicationKeyId = options.applicationKeyId\n this.applicationKey = options.applicationKey\n this.realmUrl = getRealmUrl(options.realm ?? 'production')\n this.accountInfo = options.accountInfo ?? new InMemoryAccountInfo()\n bindAccountInfoAuthContext(this.accountInfo, this.realmUrl, this.applicationKeyId)\n this.userAllowedSuffixes = options.allowedHostSuffixes\n this.resolvedUploadRetryOptions = { ...DEFAULT_RETRY_OPTIONS, ...options.retry }\n\n let baseTransport: HttpTransport\n if (options.transport !== undefined) {\n baseTransport = options.transport\n this.urlGuard = null\n } else {\n const urlGuard = new UrlGuard()\n baseTransport = new FetchTransport({\n urlGuard,\n ...(options.userAgent !== undefined ? { userAgent: options.userAgent } : {}),\n ...(options.followSameOriginRedirects !== undefined\n ? { followSameOriginRedirects: options.followSameOriginRedirects }\n : {}),\n })\n this.urlGuard = urlGuard\n }\n\n const retryTransport = new RetryTransport({\n transport: baseTransport,\n retry: this.resolvedUploadRetryOptions,\n onReauth: () => this.reauthorize(),\n })\n\n const cachedAuth = this.accountInfo.getAuth()\n if (cachedAuth !== null) this.lockUrlGuard(cachedAuth)\n\n this.raw = new RawClient({ transport: retryTransport })\n }\n\n /**\n * Authenticates with B2 and stores the authorization state. Must be called before other methods.\n *\n * @returns The authorization response containing tokens, URLs, and capabilities.\n */\n async authorize(): Promise<AuthorizeAccountResponse> {\n const auth = await this.raw.authorizeAccount(\n this.applicationKeyId,\n this.applicationKey,\n this.realmUrl,\n )\n this.accountInfo.setAuth(auth)\n this.lockUrlGuard(auth)\n return auth\n }\n\n private lockUrlGuard(auth: AuthorizeAccountResponse): void {\n if (this.urlGuard !== null) {\n const derived = deriveAllowedSuffixes(auth.apiInfo.storageApi)\n const merged =\n this.userAllowedSuffixes !== undefined\n ? this.userAllowedSuffixes.length === 0\n ? []\n : Array.from(new Set([...derived, ...this.userAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\n }\n\n /**\n * Refresh credentials after a 401. Returns the fresh auth token so\n * {@link RetryTransport} can rewrite the in-flight request's\n * Authorization header before retrying.\n *\n * @returns The fresh authorization token.\n */\n private async reauthorize(): Promise<string> {\n this.accountInfo.clear()\n const auth = await this.authorize()\n return auth.authorizationToken\n }\n\n /**\n * Creates a new B2 bucket.\n * @param options - Bucket configuration including name, type, and optional settings.\n *\n * @returns A {@link Bucket} handle for the newly created bucket.\n */\n async createBucket(options: {\n /** Globally unique bucket name (6-63 chars; letters, digits, hyphens, periods). */\n bucketName: string\n /** Access level: `\"allPrivate\"` or `\"allPublic\"`. */\n bucketType: BucketType\n /** Custom key-value metadata stored with the bucket. */\n bucketInfo?: Record<string, string>\n /** CORS rules for browser-based access. */\n corsRules?: CorsRule[]\n /** Default server-side encryption for new files. */\n defaultServerSideEncryption?: EncryptionSetting\n /** Default retention policy for new files (requires file lock). */\n defaultRetention?: BucketRetentionPolicy\n /** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */\n fileLockEnabled?: boolean\n /** Lifecycle rules for automatic file deletion or hiding. */\n lifecycleRules?: LifecycleRule[]\n /** Cross-region replication configuration. */\n replicationConfiguration?: ReplicationConfiguration\n }): Promise<Bucket> {\n const request: CreateBucketRequest = {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n }\n const info = await this.raw.createBucket(\n this.accountInfo.getApiUrl(),\n this.accountInfo.getAuthToken(),\n request,\n )\n return new Bucket(this, info, this.resolvedUploadRetryOptions)\n }\n\n /**\n * Lists buckets in the account, optionally filtered by ID, name, or type.\n * @param options - Optional filters for bucket ID, name, or type.\n *\n * @returns An array of {@link Bucket} handles.\n */\n async listBuckets(options?: {\n /** Filter to a specific bucket by ID. */\n bucketId?: BucketId\n /** Filter to a specific bucket by name. */\n bucketName?: string\n /** Filter by bucket types (e.g., `[\"allPrivate\"]`). */\n bucketTypes?: BucketType[]\n }): Promise<Bucket[]> {\n const resp = await this.raw.listBuckets(\n this.accountInfo.getApiUrl(),\n this.accountInfo.getAuthToken(),\n {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n },\n )\n return resp.buckets.map((info) => new Bucket(this, info, this.resolvedUploadRetryOptions))\n }\n\n /**\n * Looks up a single bucket by name.\n * @param bucketName - The name of the bucket to find.\n *\n * @returns The {@link Bucket} handle, or `null` if not found.\n */\n async getBucket(bucketName: string): Promise<Bucket | null> {\n const buckets = await this.listBuckets({ bucketName })\n const filteredMatch = buckets[0]\n if (filteredMatch !== undefined) return filteredMatch\n\n const unfilteredBuckets = await this.listBuckets()\n return unfilteredBuckets.find((bucket) => bucket.name === bucketName) ?? null\n }\n\n /**\n * Permanently deletes a bucket. The bucket must be empty.\n * @param id - The unique identifier of the bucket to delete.\n *\n * @returns The deleted bucket metadata.\n */\n async deleteBucket(id: BucketId): Promise<BucketInfo> {\n return this.raw.deleteBucket(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n bucketId: id,\n })\n }\n\n /**\n * Creates a new application key with the specified capabilities.\n * @param options - Key configuration including capabilities, name, and optional restrictions.\n *\n * @returns The full key including the secret (only returned at creation time).\n */\n async createKey(options: CreateKeyOptions): Promise<FullApplicationKey> {\n return this.raw.createKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n })\n }\n\n /**\n * Lists application keys in the account.\n * @param options - Optional pagination settings.\n *\n * @returns A page of application keys with an optional continuation token.\n */\n async listKeys(options?: {\n /**\n * Maximum number of keys to return per request. Forwarded to the\n * raw API's `maxKeyCount` parameter.\n */\n pageSize?: number\n /** Start listing after this key ID (for pagination). */\n startApplicationKeyId?: ApplicationKeyId\n }): Promise<ListKeysResponse> {\n return this.raw.listKeys(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...(options?.pageSize !== undefined ? { maxKeyCount: options.pageSize } : {}),\n ...(options?.startApplicationKeyId !== undefined\n ? { startApplicationKeyId: options.startApplicationKeyId }\n : {}),\n })\n }\n\n /**\n * Async iterator that yields every application key on the account,\n * automatically handling pagination via `listKeys`.\n *\n * @param options - Pagination + abort options. `pageSize` is forwarded\n * to `maxKeyCount`; the default is 1000.\n *\n * @returns An async iterable of {@link ApplicationKey} entries.\n *\n * @example\n * ```ts\n * for await (const key of client.paginateKeys()) {\n * console.log(key.keyName, key.capabilities)\n * }\n * ```\n */\n paginateKeys(options?: PaginatorOptions): AsyncIterableIterator<ApplicationKey> {\n return paginateItems(\n async (cursor: ApplicationKeyId | undefined) => {\n const resp = await this.listKeys({\n pageSize: options?.pageSize ?? DEFAULT_PAGE_SIZE,\n ...(cursor !== undefined ? { startApplicationKeyId: cursor } : {}),\n })\n return { page: resp, nextCursor: resp.nextApplicationKeyId ?? undefined }\n },\n (page) => page.keys,\n options?.signal,\n )\n }\n\n /**\n * Permanently deletes an application key.\n * @param applicationKeyId - The unique identifier of the key to delete.\n *\n * @returns The deleted application key metadata.\n */\n async deleteKey(applicationKeyId: ApplicationKeyId): Promise<ApplicationKey> {\n return this.raw.deleteKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n applicationKeyId,\n })\n }\n\n /**\n * Checks whether the authorized application key carries every capability in\n * `needed`. Returns the missing capabilities so callers can fail fast with a\n * clear error instead of a generic 401/403 from the server.\n *\n * @param needed - The capabilities required by the planned operation.\n *\n * @returns An object with `ok: true` when every needed capability is\n * present, otherwise `{ ok: false, missing: [...] }`.\n *\n * @throws If {@link authorize} has not been called yet.\n */\n hasCapabilities(needed: readonly Capability[]): CapabilityCheckResult {\n const auth = this.accountInfo.getAuth()\n if (!auth) throw new Error('Not authorized. Call authorize() first.')\n const available = new Set<string>(auth.apiInfo.storageApi.allowed.capabilities)\n const missing = needed.filter((cap) => !available.has(cap as string))\n return { ok: missing.length === 0, missing }\n }\n}\n\nfunction bindAccountInfoAuthContext(\n accountInfo: AccountInfo,\n realmUrl: string,\n applicationKeyId: string,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,MAAM,YAAY,IAAI,IAAY,KAAK,QAAQ,WAAW,QAAQ,YAAY;EAC9E,MAAM,UAAU,OAAO,QAAQ,QAAQ,CAAC,UAAU,IAAI,GAAa,CAAC;EACpE,OAAO;GAAE,IAAI,QAAQ,WAAW;GAAG;EAAQ;CAC7C;AACF;AAEA,SAAS,2BACP,aACA,UACA,kBACM;CACN,YAAY,sBAAsB,gBAAgB;CAClD,YAAY,cAAc,QAAQ;AACpC"}
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { AccountInfo } from './auth/account-info.ts'\nimport { InMemoryAccountInfo } from './auth/in-memory.ts'\nimport { getRealmUrl } from './auth/realms.ts'\nimport { ReauthCoalescer } from './auth/reauth-coalescer.ts'\nimport { Bucket } from './bucket.ts'\nimport { DEFAULT_RETRY_OPTIONS, type RetryOptions } from './http/retry.ts'\nimport type { HttpTransport } from './http/transport.ts'\nimport { FetchTransport, RetryTransport } from './http/transport.ts'\nimport { deriveAllowedSuffixes, UrlGuard } from './http/url-guard.ts'\nimport { RawClient } from './raw/index.ts'\nimport type { AuthorizeAccountResponse, Capability } from './types/auth.ts'\nimport type {\n BucketDefaultServerSideEncryptionSetting,\n BucketInfo,\n BucketRetentionPolicy,\n BucketType,\n BucketTypesFilter,\n CorsRule,\n CreateBucketRequest,\n LifecycleRule,\n} from './types/bucket.ts'\nimport type { ApplicationKeyId, BucketId } from './types/ids.ts'\nimport { accountId } from './types/ids.ts'\nimport type {\n ApplicationKey,\n CreateKeyOptions,\n FullApplicationKey,\n ListKeysResponse,\n} from './types/key.ts'\nimport type { ReplicationConfiguration } from './types/replication.ts'\nimport { throwIfSignalAborted } from './util/abort.ts'\nimport { DEFAULT_PAGE_SIZE } from './util/defaults.ts'\nimport { type PaginatorOptions, paginateItems } from './util/paginator.ts'\n\n/** Result of {@link B2Client.hasCapabilities}. */\nexport interface CapabilityCheckResult {\n /** `true` when the key carries every requested capability. */\n readonly ok: boolean\n /** Capabilities the call requested that the current key does not hold. Empty when `ok` is `true`. */\n readonly missing: readonly Capability[]\n}\n\n/** Configuration options for creating a {@link B2Client}. */\nexport interface B2ClientOptions {\n /** The application key ID from the B2 dashboard or `b2_create_key`. */\n readonly applicationKeyId: string\n /** The application key secret. */\n readonly applicationKey: string\n /**\n * B2 realm to authenticate against. Accepts a known realm-map key\n * (`\"production\"` or `\"staging\"`) or a direct base URL. Custom HTTPS hosts\n * are trusted with the application key during authorize, so never derive\n * `realm` from untrusted input. URL values must use HTTPS, or loopback IP\n * literal HTTP for local testing only; application-key credentials are sent\n * unencrypted over loopback HTTP. Unsupported schemes, malformed URLs,\n * non-URL strings, plaintext HTTP hostnames such as `localhost`, and\n * non-loopback plaintext HTTP are rejected before credentials are sent. URL\n * values must not include userinfo, query strings, or fragments. Defaults to\n * `\"production\"`.\n */\n readonly realm?: string\n /** Storage backend for authorization state. Defaults to {@link InMemoryAccountInfo}. */\n readonly accountInfo?: AccountInfo\n /** Custom HTTP transport. Defaults to {@link FetchTransport}. Wrapped by {@link RetryTransport}. */\n readonly transport?: HttpTransport\n /** Override retry behavior (max retries, backoff, and per-attempt timeout). */\n readonly retry?: Partial<RetryOptions>\n /** Custom user-agent string prepended to the SDK default. */\n readonly userAgent?: string\n /**\n * Override the SSRF allow-list. By default the SDK locks the\n * {@link FetchTransport} to host suffixes derived from the realm's authorize\n * response (e.g. `backblazeb2.com`, `backblaze.com`) so a compromised B2\n * endpoint cannot redirect the SDK to internal services. Pass an explicit\n * list to add hosts (e.g. when testing against a self-hosted proxy) or set\n * to an empty array to disable the guard entirely (not recommended).\n *\n * Only consulted when {@link B2ClientOptions.transport} is unset; a custom\n * transport is the user's responsibility to harden.\n */\n readonly allowedHostSuffixes?: readonly string[]\n /**\n * Follow same-origin GET/HEAD redirects in the default fetch transport after\n * checking each target with the SSRF guard. POST redirects remain blocked.\n * Defaults to true.\n */\n readonly followSameOriginRedirects?: boolean\n}\n\n/** Options for {@link B2Client.authorize}. */\nexport interface B2ClientAuthorizeOptions {\n /** Abort signal for cancelling the authorize request. */\n readonly signal?: AbortSignal\n}\n\n/**\n * High-level B2 client providing ergonomic access to buckets, files, and keys.\n *\n * @example\n * ```ts\n * const client = new B2Client({\n * applicationKeyId: process.env.B2_APPLICATION_KEY_ID,\n * applicationKey: process.env.B2_APPLICATION_KEY,\n * })\n * await client.authorize()\n * const buckets = await client.listBuckets()\n * ```\n */\nexport class B2Client {\n /** Low-level client for direct B2 API calls. */\n readonly raw: RawClient\n /** Authorization state storage (tokens, URLs, capabilities). */\n readonly accountInfo: AccountInfo\n /**\n * SSRF allow-list applied by the default {@link FetchTransport}. `null` when\n * a custom transport was supplied — in that case the SDK does not own the\n * guard. Locked down by {@link B2Client.authorize}.\n */\n readonly urlGuard: UrlGuard | null\n private readonly applicationKeyId: string\n private readonly applicationKey: string\n private readonly realmUrl: string\n private readonly userAllowedSuffixes: readonly string[] | undefined\n private readonly resolvedUploadRetryOptions: RetryOptions\n private readonly reauthCoalescer: ReauthCoalescer<string>\n\n /**\n * Creates a new B2Client. Call {@link authorize} before making API requests.\n * @param options - Configuration including credentials, realm, and transport settings.\n */\n constructor(options: B2ClientOptions) {\n this.applicationKeyId = options.applicationKeyId\n this.applicationKey = options.applicationKey\n this.realmUrl = getRealmUrl(options.realm ?? 'production')\n this.accountInfo = options.accountInfo ?? new InMemoryAccountInfo()\n bindAccountInfoAuthContext(this.accountInfo, this.realmUrl, this.applicationKeyId)\n this.userAllowedSuffixes = options.allowedHostSuffixes\n this.resolvedUploadRetryOptions = { ...DEFAULT_RETRY_OPTIONS, ...options.retry }\n this.reauthCoalescer = new ReauthCoalescer((signal) => this.doReauthorize(signal))\n\n let baseTransport: HttpTransport\n if (options.transport !== undefined) {\n baseTransport = options.transport\n this.urlGuard = null\n } else {\n const urlGuard = new UrlGuard()\n baseTransport = new FetchTransport({\n urlGuard,\n ...(options.userAgent !== undefined ? { userAgent: options.userAgent } : {}),\n ...(options.followSameOriginRedirects !== undefined\n ? { followSameOriginRedirects: options.followSameOriginRedirects }\n : {}),\n })\n this.urlGuard = urlGuard\n }\n\n const retryTransport = new RetryTransport({\n transport: baseTransport,\n retry: this.resolvedUploadRetryOptions,\n onReauth: (signal) => this.reauthorize(signal),\n })\n\n const cachedAuth = this.accountInfo.getAuth()\n if (cachedAuth !== null) this.lockUrlGuard(cachedAuth)\n\n this.raw = new RawClient({ transport: retryTransport })\n }\n\n /**\n * Authenticates with B2 and stores the authorization state. Must be called before other methods.\n *\n * @param options - Optional request controls.\n *\n * @returns The authorization response containing tokens, URLs, and capabilities.\n */\n async authorize(options?: B2ClientAuthorizeOptions): Promise<AuthorizeAccountResponse> {\n throwIfSignalAborted(options?.signal)\n const auth = await this.raw.authorizeAccount(\n this.applicationKeyId,\n this.applicationKey,\n this.realmUrl,\n options?.signal !== undefined ? { signal: options.signal } : undefined,\n )\n throwIfSignalAborted(options?.signal)\n this.accountInfo.setAuth(auth)\n this.lockUrlGuard(auth)\n return auth\n }\n\n private lockUrlGuard(auth: AuthorizeAccountResponse): void {\n if (this.urlGuard !== null) {\n const derived = deriveAllowedSuffixes(auth.apiInfo.storageApi)\n const merged =\n this.userAllowedSuffixes !== undefined\n ? this.userAllowedSuffixes.length === 0\n ? []\n : Array.from(new Set([...derived, ...this.userAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\n }\n\n /**\n * Refresh credentials after a 401. Returns the fresh auth token so\n * {@link RetryTransport} can rewrite the in-flight request's\n * Authorization header before retrying.\n *\n * @param signal - Optional abort signal for the request that triggered reauthorization.\n *\n * @returns The fresh authorization token.\n */\n private reauthorize(signal: AbortSignal | undefined): Promise<string> {\n return this.reauthCoalescer.run(signal)\n }\n\n private async doReauthorize(signal: AbortSignal): Promise<string> {\n const auth = await this.authorize({ signal })\n return auth.authorizationToken\n }\n\n /**\n * Creates a new B2 bucket.\n * @param options - Bucket configuration including name, type, and optional settings.\n *\n * @returns A {@link Bucket} handle for the newly created bucket.\n */\n async createBucket(options: {\n /** Globally unique bucket name (6-63 chars; letters, digits, hyphens, periods). */\n bucketName: string\n /** Access level: `\"allPrivate\"` or `\"allPublic\"`. */\n bucketType: BucketType\n /**\n * Custom key-value metadata stored with the bucket. Keys must be 1-50\n * UTF-8 bytes, must not start with `b2-`, and all values together must be\n * at most 10,000 UTF-8 bytes. Keys must match\n * {@link BUCKET_INFO_KEY_PATTERN}. There is no bucketInfo pair-count cap.\n */\n bucketInfo?: Record<string, string>\n /**\n * CORS rules for browser-based access. A bucket may have at most 100\n * rules; rule names must be unique, 6-63 characters, match\n * `[A-Za-z0-9-]`, and not start with `b2-`. Each rule must be less than\n * 1,000 UTF-8 bytes across its name, origins, operations, allowed headers,\n * and exposed headers. `maxAgeSeconds` must be at most 86,400.\n */\n corsRules?: CorsRule[]\n /** Default server-side encryption for new files. */\n defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting\n /** Default retention policy for new files (requires file lock). */\n defaultRetention?: BucketRetentionPolicy\n /** Enable file lock (Object Lock) on the bucket. Cannot be disabled once set. */\n fileLockEnabled?: boolean\n /** Lifecycle rules for automatic file deletion or hiding. */\n lifecycleRules?: LifecycleRule[]\n /** Cross-region replication configuration. */\n replicationConfiguration?: ReplicationConfiguration\n }): Promise<Bucket> {\n const {\n bucketInfo,\n bucketName,\n bucketType,\n corsRules,\n defaultRetention,\n defaultServerSideEncryption,\n fileLockEnabled,\n lifecycleRules,\n replicationConfiguration,\n } = options\n const request: CreateBucketRequest = {\n ...(bucketInfo !== undefined ? { bucketInfo } : {}),\n bucketName,\n bucketType,\n ...(corsRules !== undefined ? { corsRules } : {}),\n ...(defaultServerSideEncryption !== undefined ? { defaultServerSideEncryption } : {}),\n ...(defaultRetention !== undefined ? { defaultRetention } : {}),\n ...(fileLockEnabled !== undefined ? { fileLockEnabled } : {}),\n ...(lifecycleRules !== undefined ? { lifecycleRules } : {}),\n ...(replicationConfiguration !== undefined ? { replicationConfiguration } : {}),\n accountId: accountId(this.accountInfo.getAccountId()),\n }\n const info = await this.raw.createBucket(\n this.accountInfo.getApiUrl(),\n this.accountInfo.getAuthToken(),\n request,\n )\n return new Bucket(this, info, this.resolvedUploadRetryOptions)\n }\n\n /**\n * Lists buckets in the account, optionally filtered by ID, name, or type.\n * @param options - Optional filters for bucket ID, name, or type.\n *\n * @returns An array of {@link Bucket} handles.\n */\n async listBuckets(options?: {\n /** Filter to a specific bucket by ID. */\n bucketId?: BucketId\n /** Filter to a specific bucket by name. */\n bucketName?: string\n /** Filter by bucket types (e.g., `[\"allPrivate\"]`, `[\"shared\"]`, or `[\"all\"]`). */\n bucketTypes?: BucketTypesFilter\n }): Promise<Bucket[]> {\n const resp = await this.raw.listBuckets(\n this.accountInfo.getApiUrl(),\n this.accountInfo.getAuthToken(),\n {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n },\n )\n return resp.buckets.map((info) => new Bucket(this, info, this.resolvedUploadRetryOptions))\n }\n\n /**\n * Looks up a single bucket by name.\n * @param bucketName - The name of the bucket to find.\n *\n * @returns The {@link Bucket} handle, or `null` if not found.\n */\n async getBucket(bucketName: string): Promise<Bucket | null> {\n const buckets = await this.listBuckets({ bucketName })\n const filteredMatch = buckets[0]\n if (filteredMatch !== undefined) return filteredMatch\n\n const unfilteredBuckets = await this.listBuckets()\n return unfilteredBuckets.find((bucket) => bucket.name === bucketName) ?? null\n }\n\n /**\n * Permanently deletes a bucket. The bucket must be empty.\n * @param id - The unique identifier of the bucket to delete.\n *\n * @returns The deleted bucket metadata.\n */\n async deleteBucket(id: BucketId): Promise<BucketInfo> {\n return this.raw.deleteBucket(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n bucketId: id,\n })\n }\n\n /**\n * Creates a new application key with the specified capabilities.\n * @param options - Key configuration including capabilities, name, and optional restrictions.\n *\n * @returns The full key including the secret (only returned at creation time).\n */\n async createKey(options: CreateKeyOptions): Promise<FullApplicationKey> {\n return this.raw.createKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...options,\n })\n }\n\n /**\n * Lists application keys in the account.\n * @param options - Optional pagination settings.\n *\n * @returns A page of application keys with an optional continuation token.\n */\n async listKeys(options?: {\n /**\n * Maximum number of keys to return per request. Forwarded to the\n * raw API's `maxKeyCount` parameter.\n */\n pageSize?: number\n /** Start listing at this key ID, usually from `nextApplicationKeyId`. */\n startApplicationKeyId?: ApplicationKeyId\n }): Promise<ListKeysResponse> {\n return this.raw.listKeys(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n accountId: accountId(this.accountInfo.getAccountId()),\n ...(options?.pageSize !== undefined ? { maxKeyCount: options.pageSize } : {}),\n ...(options?.startApplicationKeyId !== undefined\n ? { startApplicationKeyId: options.startApplicationKeyId }\n : {}),\n })\n }\n\n /**\n * Async iterator that yields every application key on the account,\n * automatically handling pagination via `listKeys`.\n *\n * @param options - Pagination + abort options. `pageSize` is forwarded\n * to `maxKeyCount`; the default is 1000.\n *\n * @returns An async iterable of {@link ApplicationKey} entries.\n *\n * @example\n * ```ts\n * for await (const key of client.paginateKeys()) {\n * console.log(key.keyName, key.capabilities)\n * }\n * ```\n */\n paginateKeys(options?: PaginatorOptions): AsyncIterableIterator<ApplicationKey> {\n return paginateItems(\n async (cursor: ApplicationKeyId | undefined) => {\n const resp = await this.listKeys({\n pageSize: options?.pageSize ?? DEFAULT_PAGE_SIZE,\n ...(cursor !== undefined ? { startApplicationKeyId: cursor } : {}),\n })\n return { page: resp, nextCursor: resp.nextApplicationKeyId ?? undefined }\n },\n (page) => page.keys,\n options?.signal,\n )\n }\n\n /**\n * Permanently deletes an application key.\n * @param applicationKeyId - The unique identifier of the key to delete.\n *\n * @returns The deleted application key metadata.\n */\n async deleteKey(applicationKeyId: ApplicationKeyId): Promise<ApplicationKey> {\n return this.raw.deleteKey(this.accountInfo.getApiUrl(), this.accountInfo.getAuthToken(), {\n applicationKeyId,\n })\n }\n\n /**\n * Checks whether the authorized application key carries every capability in\n * `needed`. Returns the missing capabilities so callers can fail fast with a\n * clear error instead of a generic 401/403 from the server.\n *\n * @param needed - The capabilities required by the planned operation.\n *\n * @returns An object with `ok: true` when every needed capability is\n * present, otherwise `{ ok: false, missing: [...] }`.\n *\n * @throws If {@link authorize} has not been called yet.\n */\n hasCapabilities(needed: readonly Capability[]): CapabilityCheckResult {\n const auth = this.accountInfo.getAuth()\n if (!auth) throw new Error('Not authorized. Call authorize() first.')\n const available = new Set<string>(auth.apiInfo.storageApi.allowed.capabilities)\n const missing = needed.filter((cap) => !available.has(cap as string))\n return { ok: missing.length === 0, missing }\n }\n}\n\nfunction bindAccountInfoAuthContext(\n accountInfo: AccountInfo,\n realmUrl: string,\n applicationKeyId: string,\n): void {\n accountInfo.setApplicationKeyId?.(applicationKeyId)\n accountInfo.setRealmUrl?.(realmUrl)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,IAAa,WAAb,MAAsB;;CAEpB;;CAEA;;;;;;CAMA;CACA;CACA;CACA;CACA;CACA;CACA;;;;;CAMA,YAAY,SAA0B;EACpC,KAAK,mBAAmB,QAAQ;EAChC,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,WAAW,YAAY,QAAQ,SAAS,YAAY;EACzD,KAAK,cAAc,QAAQ,eAAe,IAAI,oBAAoB;EAClE,2BAA2B,KAAK,aAAa,KAAK,UAAU,KAAK,gBAAgB;EACjF,KAAK,sBAAsB,QAAQ;EACnC,KAAK,6BAA6B;GAAE,GAAG;GAAuB,GAAG,QAAQ;EAAM;EAC/E,KAAK,kBAAkB,IAAI,iBAAiB,WAAW,KAAK,cAAc,MAAM,CAAC;EAEjF,IAAI;EACJ,IAAI,QAAQ,cAAc,KAAA,GAAW;GACnC,gBAAgB,QAAQ;GACxB,KAAK,WAAW;EAClB,OAAO;GACL,MAAM,WAAW,IAAI,SAAS;GAC9B,gBAAgB,IAAI,eAAe;IACjC;IACA,GAAI,Q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ACpE,MAAM,YAAY,IAAI,IAAY,KAAK,QAAQ,WAAW,QAAQ,YAAY;EAC9E,MAAM,UAAU,OAAO,QAAQ,QAAQ,CAAC,UAAU,IAAI,GAAa,CAAC;EACpE,OAAO;GAAE,IAAI,QAAQ,WAAW;GAAG;EAAQ;CAC7C;AACF;AAEA,SAAS,2BACP,aACA,UACA,kBACM;CACN,YAAY,sBAAsB,gBAAgB;CAClD,YAAY,cAAc,QAAQ;AACpC"}
|
package/dist/download/single.cjs
CHANGED
|
@@ -154,12 +154,11 @@ function emptyStream() {
|
|
|
154
154
|
* @returns A stream wrapped for checksum verification and progress reporting.
|
|
155
155
|
*/
|
|
156
156
|
function prepareDownloadBody(body, headers, options) {
|
|
157
|
-
return instrumentProgress(options.method !== "HEAD" && options.range === void 0 ? require_checksum.verifyDownloadStream(body, headers.contentSha1) : body, headers.contentLength, options.onProgress);
|
|
157
|
+
return instrumentProgress(options.method !== "HEAD" && options.range === void 0 ? require_checksum.verifyDownloadStream(body, headers.contentSha1) : body, headers.contentLength, options.onProgress, options.progressIntervalMillis);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
* Wraps a body stream
|
|
161
|
-
*
|
|
162
|
-
* when the stream finishes.
|
|
160
|
+
* Wraps a body stream so the SDK increments a {@link ProgressTracker} for
|
|
161
|
+
* each chunk and reports `partsCompleted: 1` when the stream finishes.
|
|
163
162
|
*
|
|
164
163
|
* When `listener` is undefined the function short-circuits and returns
|
|
165
164
|
* the original stream, so unobserved downloads pay no overhead.
|
|
@@ -167,22 +166,48 @@ function prepareDownloadBody(body, headers, options) {
|
|
|
167
166
|
* @param body - The download response body to wrap.
|
|
168
167
|
* @param totalBytes - Expected total bytes (response `Content-Length`).
|
|
169
168
|
* @param listener - Caller-supplied progress callback, or undefined.
|
|
169
|
+
* @param progressIntervalMillis - Optional byte-progress throttle interval.
|
|
170
170
|
*
|
|
171
171
|
* @returns A stream that emits the same bytes and reports progress.
|
|
172
172
|
*/
|
|
173
|
-
function instrumentProgress(body, totalBytes, listener) {
|
|
173
|
+
function instrumentProgress(body, totalBytes, listener, progressIntervalMillis) {
|
|
174
174
|
if (listener === void 0) return body;
|
|
175
|
-
const tracker = new require_progress.ProgressTracker(listener, totalBytes, 1);
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
const tracker = new require_progress.ProgressTracker(listener, totalBytes, 1, { ...progressIntervalMillis !== void 0 ? { minIntervalMs: progressIntervalMillis } : {} });
|
|
176
|
+
const reader = body.getReader();
|
|
177
|
+
let released = false;
|
|
178
|
+
function releaseReader() {
|
|
179
|
+
if (released) return;
|
|
180
|
+
released = true;
|
|
181
|
+
reader.releaseLock();
|
|
182
|
+
}
|
|
183
|
+
return new ReadableStream({
|
|
184
|
+
async pull(controller) {
|
|
185
|
+
try {
|
|
186
|
+
const { done, value } = await reader.read();
|
|
187
|
+
if (done) {
|
|
188
|
+
tracker.completePart();
|
|
189
|
+
tracker.dispose();
|
|
190
|
+
releaseReader();
|
|
191
|
+
controller.close();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
tracker.addBytes(value.byteLength);
|
|
195
|
+
controller.enqueue(value);
|
|
196
|
+
} catch (err) {
|
|
197
|
+
tracker.dispose();
|
|
198
|
+
releaseReader();
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
180
201
|
},
|
|
181
|
-
|
|
182
|
-
tracker.
|
|
202
|
+
async cancel(reason) {
|
|
203
|
+
tracker.dispose();
|
|
204
|
+
try {
|
|
205
|
+
await reader.cancel(reason);
|
|
206
|
+
} finally {
|
|
207
|
+
releaseReader();
|
|
208
|
+
}
|
|
183
209
|
}
|
|
184
210
|
});
|
|
185
|
-
return body.pipeThrough(transform);
|
|
186
211
|
}
|
|
187
212
|
/**
|
|
188
213
|
* Extracts B2-specific download headers into a structured object.
|