@beam-network/sdk 0.6.0 → 0.7.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/README.md CHANGED
@@ -156,19 +156,19 @@ For low-level raw transfer configs, use `createRawTransfer`; lifecycle transport
156
156
 
157
157
  Provider transfers use `transfer-client-control/v7`. Every reply carries Runtime and transport epochs; prepare and every route-stream message carry a UUID route generation. S3, R2, and S3-compatible destinations retain direct multipart UploadPart/ListParts/HEAD handling. Hippius and Hugging Face destinations take a plain PUT per chunk instead, so they carry no multipart group manifest.
158
158
 
159
- The client signs up to 64 routes concurrently by default and emits 2,048-route logical batches. Encoded MessagePack requests target 4 MiB physical batches under `maxPayloadBytes` (8 MiB by default; explicit positive overrides remain supported). The splitter reserves control-envelope headroom for the live auth token and stable request identity so the final encoded request remains below the configured guard. Lifecycle control refreshes cached SDK auth before the final 30 seconds of token lifetime and retries `auth_token_expired` replies with the same request identity and payload but a fresh token, preserving Core request-conflict protection during large route streams. A single route above the 4 MiB target but within the configured guard publishes alone; a single route larger than the configured limit fails before publication with both sizes in the error. Multipart create and abort requests use a separate `multipartControlConcurrency` limit of 2 by default, with explicit positive overrides supported, and S3-compatible control requests make up to five attempts for transient provider failures. This keeps URL signing throughput independent from provider control-plane pressure.
159
+ The client signs up to 64 routes concurrently by default and emits 1,024-route logical batches. Encoded MessagePack requests target 4 MiB physical batches under `maxPayloadBytes` (8 MiB by default; explicit positive overrides remain supported). The splitter reserves control-envelope headroom for the live auth token and stable request identity so the final encoded request remains below the configured guard. Lifecycle control refreshes cached SDK auth before the final 30 seconds of token lifetime and retries `auth_token_expired` replies with the same request identity and payload but a fresh token, preserving Core request-conflict protection during large route streams. A single route above the 4 MiB target but within the configured guard publishes alone; a single route larger than the configured limit fails before publication with both sizes in the error. Multipart create and abort requests use a separate `multipartControlConcurrency` limit of 2 by default, with explicit positive overrides supported, and S3-compatible control requests make up to five attempts for transient provider failures. This keeps URL signing throughput independent from provider control-plane pressure.
160
160
 
161
161
  Callers that need durable recovery accounting can provide `onMultipartGroupReady`. The SDK invokes it after creating a multipart upload and before streaming that group’s signed routes. Its payload contains transfer, source, destination, object-key, upload, size, part-count, and expiry identities only; it never includes credentials, request headers, or signed URLs. A rejected callback aborts the newly created upload and fails preparation closed.
162
162
 
163
163
  `resumeProviderTransfer` requires the complete saved callback payloads in `multipartGroups`. It validates every transfer/source/destination/object/size/part coordinate, then uses the same route-stream implementation as creation with those upload IDs. Missing, duplicate, or changed identities fail before new provider uploads or route publication. If a process died before recording an upload identity, treat it as uncertain cleanup instead of inventing a replacement. The `onPrepared` callback also runs during resume, before routes are streamed.
164
164
 
165
- Create and resume accept an ownership `signal`. Aborting it stops initial routes, multipart creation, and recovery signing/replay; it does not cancel the transfer or abort a replacement owner's uploads. User cancellation still uses `cancelTransfer` and verified provider cleanup. `prepareProviderSource` accepts the same signal for metadata requests.
165
+ Create and resume accept an ownership `signal`. Aborting it stops initial routes, multipart creation, and recovery signing/replay; it does not cancel the transfer or abort a replacement owner's uploads. Recovery leases, signers, and background resume/replay are keyed by owner identity: a fenced-off owner never replays into, releases, or stops the signers of a replacement owner registered for the same transfer, and a replacement always gets its own recovery. User cancellation still uses `cancelTransfer` and verified provider cleanup. `prepareProviderSource` accepts the same signal for metadata requests.
166
166
 
167
167
  The stream ID derives from the transfer, selected flow, and immutable plan identity, and each ordered batch ID includes its route-coordinate checksum. Manual multi-destination attachment requires `delivery_index` on every route. Lifecycle mutations retry transient failures up to three times with the same request identity. A non-recoverable provider setup or route failure raises `BeamProviderTransferError`, whose `errors`, `transferCancelled`, and `multipartCleanupComplete` fields retain the original provider, cancellation, and cleanup outcomes. `waitForTransfer` subscribes to the API-key-owned, at-most-once terminal signal before its first status read and reconciles every signal through authoritative status; subscription failure degrades to the same jittered 15-to-30-second status fallback. Call `close()` when the client is no longer needed; it also closes outstanding terminal waiters.
168
168
 
169
169
  During the pre-completion `integrity_check` phase, Runtime may include an `integrity_audit_challenge` in status. The TypeScript client signs exact read-only source and final-destination GET ranges and submits `transfer.integrity_audit_grants`. S3-compatible source and destination grants use the prepared source ETag and Runtime-verified final-object ETag as `If-Match` conditions. Submission failures retry on the next status poll and appear as a URL-safe `integrity_audit_submission_error` on that status response; the transfer completes with a warning if the check cannot finish by its deadline.
170
170
 
171
- Hippius uses canonical non-multipart `signed_url` routes, so its manifest is empty and group-level final HEAD verification is not available from that provider flow.
171
+ Hippius uses canonical non-multipart `signed_url` routes (initial and recovered routes both PUT to the planned `<final>/<plan_nonce>/chunk-NNNNNN` key), so its manifest is empty and group-level final HEAD verification is not available from that provider flow.
172
172
 
173
173
  NATS requires this guard because the broker rejects messages above its configured `max_payload`. This limit applies only to lifecycle/control metadata; transfer file bytes do not flow through NATS.
174
174
 
@@ -189,3 +189,30 @@ Only short-lived range/upload routes go to workers. Multipart creation, verifica
189
189
  Manual releases from `dev` require a committed `-dev.N` version and publish only to npm tag `dev`; the stable tag is unchanged.
190
190
 
191
191
  Multipart control helpers (`createMultipartUpload`, `listMultipartParts`, `completeMultipartUpload`, `inspectDestinationObject`, and `abortMultipartUpload`) accept an optional `AbortSignal` and cancel through the existing provider HTTP transport. Pass it as `signal` in object arguments or as the last positional argument. Cancellation stops waiting and network activity; it cannot undo a provider operation already accepted. After an interrupted completion, inspect the durable upload/object identity before retrying or reporting cleanup complete.
192
+
193
+ ### Preparation diagnostics
194
+
195
+ Route streaming flushes at 1,024 routes, with no timer, and sends the final partial batch at stream completion. Signing overlaps acknowledged publication through bounded buffering; existing encoded-payload limits still apply. A source grant is reused across destinations only within the same signing generation and actual expiry.
196
+
197
+ The optional `onDiagnostics` callback receives bounded preparation measurements and source-grant reuse counts. Callbacks are best effort, may be dropped under load, and do not affect transfer outcomes. Durations may overlap; do not sum them into elapsed transfer time. Transfer status also exposes a typed `performance` summary when supported by Core.
198
+
199
+ Optional `storage_location` (`StorageLocation` in Go) describes the physical
200
+ storage location. It is separate from the region used to sign provider requests.
201
+ Leave it unset when unknown; a signing region such as R2's `auto` is not a location.
202
+
203
+ When supported by Core, diagnostics use `sdk-performance/v2`: bounded histograms,
204
+ preparation milestones, concurrency high-water marks, and separate provider,
205
+ callback, manifest, signing, and transport waits. Histogram bins are noncumulative,
206
+ with upper bounds in milliseconds of 0.1, 0.5, 1, 2, 5, 10, 25, 50, 100, 250,
207
+ 500, 1000, 2500, 5000, 10000, 30000, 120000, then overflow. `unmeasured` explicitly
208
+ identifies unavailable measurements. Process CPU includes other concurrent work
209
+ in the SDK process; it is not transfer-exclusive CPU. Detailed reporting can be
210
+ disabled with `BEAM_SDK_PERFORMANCE_DETAILS=false`. Older peers retain v1 reports.
211
+ No credentials or storage grants are included in these diagnostics.
212
+
213
+ `sdk.producer_wait` measures waiting for a signed route separately from publication
214
+ backpressure. Configured-limit gauges preserve starting limits; effective-limit
215
+ gauges report the highest limit reached. Optional `source_renewals` counts source
216
+ grants recreated in later preparation generations. A bounded 16 KiB history tracks
217
+ 131,072 chunk indices; the counter is omitted after takeover or beyond that bound.
218
+ It does not include separate recovery-control signing operations.
package/dist/client.d.ts CHANGED
@@ -44,8 +44,11 @@ export declare class BeamClient {
44
44
  private readonly routeSigningConcurrency;
45
45
  private readonly routeSigningConcurrencyOverridden;
46
46
  private readonly multipartControlConcurrency;
47
+ private readonly onDiagnostics;
48
+ private diagnosticPending;
47
49
  private readonly recoverySigners;
48
50
  private readonly integrityAuditSigners;
51
+ private readonly integrityGrantCache;
49
52
  private readonly integrityAuditSubmissions;
50
53
  private readonly huggingFaceUploads;
51
54
  constructor(options?: BeamClientOptions);
@@ -105,7 +108,9 @@ export declare class BeamClient {
105
108
  private startProviderRouteRecoverySigner;
106
109
  private recoveryMultipartUploadState;
107
110
  private submitIntegrityAuditGrantsIfPresent;
108
- private submitProviderIntegrityAuditGrants;
111
+ private signedIntegrityGrants;
112
+ private buildProviderIntegrityAuditGrants;
113
+ /** Stop a transfer's recovery and integrity signers; with `owner`, only if that owner installed them. */
109
114
  private stopRecoverySigner;
110
115
  private stopAllRecoverySigners;
111
116
  createAndDistribute(input: RawTransferCreateInput): Promise<TransferCreateResponse>;