@backblaze-labs/b2-sdk - v0.6.0
    Preparing search index...

    Class B2Client

    High-level B2 client providing ergonomic access to buckets, files, and keys.

    const client = new B2Client({
    applicationKeyId: process.env.B2_APPLICATION_KEY_ID,
    applicationKey: process.env.B2_APPLICATION_KEY,
    })
    await client.authorize()
    const buckets = await client.listBuckets()
    Index

    Low-level client for direct B2 API calls.

    urlGuard: UrlGuard | null

    SSRF allow-list applied by the default FetchTransport. null when a custom transport was supplied — in that case the SDK does not own the guard. Locked down by B2Client.authorize.

    • get accountInfo(): AccountInfo

      Authorization state storage (tokens, URLs, capabilities). Custom stores should keep secrets out of enumerable properties so direct diagnostics and object spread do not expose them.

      Returns AccountInfo

      The configured authorization state store.

    • Creates a new B2 bucket. This mutation is not automatically replayed after connection failures or HTTP 408/5xx. Check its outcome before retrying manually; expired-token reauth and HTTP 429 retries remain enabled.

      Parameters

      • options: {
            bucketInfo?: Record<string, string>;
            bucketName: string;
            bucketType: BucketType;
            corsRules?: CorsRule[];
            defaultRetention?: BucketRetentionPolicy;
            defaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting;
            fileLockEnabled?: boolean;
            lifecycleRules?: LifecycleRule[];
            replicationConfiguration?: ReplicationConfiguration;
        }

        Bucket configuration including name, type, and optional settings.

        • OptionalbucketInfo?: Record<string, string>

          Custom key-value metadata stored with the bucket. Keys must be 1-50 UTF-8 bytes, must not start with b2-, and all values together must be at most 10,000 UTF-8 bytes. Keys must match BUCKET_INFO_KEY_PATTERN. There is no bucketInfo pair-count cap.

        • bucketName: string

          Globally unique bucket name (6-63 chars; letters, digits, hyphens, periods).

        • bucketType: BucketType

          Access level: "allPrivate" or "allPublic".

        • OptionalcorsRules?: CorsRule[]

          CORS rules for browser-based access. A bucket may have at most 100 rules; rule names must be unique, 6-63 characters, match [A-Za-z0-9-], and not start with b2-. Each rule must be less than 1,000 UTF-8 bytes across its name, origins, operations, allowed headers, and exposed headers. maxAgeSeconds must be at most 86,400.

        • OptionaldefaultRetention?: BucketRetentionPolicy

          Default retention policy for new files (requires file lock).

        • OptionaldefaultServerSideEncryption?: BucketDefaultServerSideEncryptionSetting

          Default server-side encryption for new files.

        • OptionalfileLockEnabled?: boolean

          Enable file lock (Object Lock) on the bucket. Cannot be disabled once set.

        • OptionallifecycleRules?: LifecycleRule[]

          Lifecycle rules for automatic file deletion or hiding.

        • OptionalreplicationConfiguration?: ReplicationConfiguration

          Cross-region replication configuration.

      Returns Promise<Bucket>

      A Bucket handle for the newly created bucket.

    • Creates a new application key with the specified capabilities. This mutation is not automatically replayed after connection failures or HTTP 408/5xx. Check its outcome before retrying manually; expired-token reauth and HTTP 429 retries remain enabled.

      Parameters

      • options: CreateKeyOptions

        Key configuration including capabilities, name, and optional restrictions.

      Returns Promise<FullApplicationKey>

      The full key including the secret (only returned at creation time).

    • Permanently deletes a bucket. The bucket must be empty.

      Parameters

      • id: BucketId

        The unique identifier of the bucket to delete.

      Returns Promise<BucketInfo>

      The deleted bucket metadata.

    • Looks up a single bucket by name.

      Parameters

      • bucketName: string

        The name of the bucket to find.

      Returns Promise<Bucket | null>

      The Bucket handle, or null if not found.

    • Checks whether the authorized application key carries every capability in needed. Returns the missing capabilities so callers can fail fast with a clear error instead of a generic 401/403 from the server.

      Parameters

      • needed: readonly Capability[]

        The capabilities required by the planned operation.

      Returns CapabilityCheckResult

      An object with ok: true when every needed capability is present, otherwise { ok: false, missing: [...] }.

      If authorize has not been called yet.

    • Lists buckets in the account, optionally filtered by ID, name, or type.

      Parameters

      • Optionaloptions: { bucketId?: BucketId; bucketName?: string; bucketTypes?: BucketTypesFilter }

        Optional filters for bucket ID, name, or type.

        • OptionalbucketId?: BucketId

          Filter to a specific bucket by ID.

        • OptionalbucketName?: string

          Filter to a specific bucket by name.

        • OptionalbucketTypes?: BucketTypesFilter

          Filter by bucket types (e.g., ["allPrivate"], ["shared"], or ["all"]).

      Returns Promise<Bucket[]>

      An array of Bucket handles.

    • Lists application keys in the account.

      Parameters

      • Optionaloptions: { pageSize?: number; startApplicationKeyId?: ApplicationKeyId }

        Optional pagination settings.

        • OptionalpageSize?: number

          Maximum number of keys to return per request. Forwarded to the raw API's maxKeyCount parameter.

        • OptionalstartApplicationKeyId?: ApplicationKeyId

          Start listing at this key ID, usually from nextApplicationKeyId.

      Returns Promise<ListKeysResponse>

      A page of application keys with an optional continuation token.

    • Async iterator that yields every application key on the account, automatically handling pagination via listKeys.

      Parameters

      • Optionaloptions: PaginatorOptions

        Pagination + abort options. pageSize is forwarded to maxKeyCount; the default is 1000.

      Returns AsyncIterableIterator<ApplicationKey>

      An async iterable of ApplicationKey entries.

      for await (const key of client.paginateKeys()) {
      console.log(key.keyName, key.capabilities)
      }
    • Hides credentials and stored tokens from JSON diagnostics.

      Returns B2ClientJson

      A safe summary without walking the account store or transport.