@beam-network/sdk 0.5.4 → 0.5.5

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
@@ -98,7 +98,7 @@ For low-level raw transfer configs, use `createRawTransfer`; lifecycle transport
98
98
 
99
99
  Provider transfers use `transfer-client-control/v5`. 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.
100
100
 
101
- The client signs up to 64 routes concurrently by default and emits 2,048-route logical batches, split only when encoded MessagePack requests approach `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. 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.
101
+ 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. 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.
102
102
 
103
103
  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.
104
104
 
@@ -4,6 +4,7 @@ export declare const TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION = "transfer-client-c
4
4
  export declare const BEAM_DEFAULT_NATS_URL = "tls://nats.b1m.ai:4222";
5
5
  export declare const BEAM_DEFAULT_NATS_WS_URL = "wss://nats.b1m.ai:443";
6
6
  export declare const BEAM_DEFAULT_MAX_PAYLOAD_BYTES: number;
7
+ export declare const BEAM_ROUTE_TARGET_PAYLOAD_BYTES: number;
7
8
  export type TransferClientMessageType = "runtime.hello" | "transfer.plan" | "transfer.create" | "transfer.prepare" | "transfer.route_stream.begin" | "transfer.route_stream.manifest" | "transfer.route_stream.batch" | "transfer.route_stream.complete" | "transfer.distribute" | "transfer.status" | "transfer.cancel" | "transfer.resume";
8
9
  export interface CompactSignedRouteBatch {
9
10
  source_chunks: Array<{
@@ -6,6 +6,7 @@ export const BEAM_DEFAULT_NATS_WS_URL = "wss://nats.b1m.ai:443";
6
6
  // NATS enforces max_payload per message. This guard splits signed-route control
7
7
  // messages before the broker rejects them; transfer bytes never flow through NATS.
8
8
  export const BEAM_DEFAULT_MAX_PAYLOAD_BYTES = 8 * 1024 * 1024;
9
+ export const BEAM_ROUTE_TARGET_PAYLOAD_BYTES = 4 * 1024 * 1024;
9
10
  const ROUTE_BATCH_AUTH_TOKEN_ESTIMATE_BYTES = 64 * 1024;
10
11
  export function buildConnectionOptions(options) {
11
12
  const connectionOptions = {
@@ -285,6 +286,7 @@ export class BeamTransferControl {
285
286
  }
286
287
  }
287
288
  splitRoutesForPayload(messageType, basePayload, routes) {
289
+ const targetPayloadBytes = Math.min(this.maxPayloadBytes, BEAM_ROUTE_TARGET_PAYLOAD_BYTES);
288
290
  const authTokenEstimateBytes = Math.min(ROUTE_BATCH_AUTH_TOKEN_ESTIMATE_BYTES, Math.max(512, Math.floor(this.maxPayloadBytes / 128)));
289
291
  const encodedBytes = (candidate) => {
290
292
  const encoded = encode({
@@ -312,7 +314,7 @@ export class BeamTransferControl {
312
314
  let accepted = 0;
313
315
  while (low <= high) {
314
316
  const count = Math.floor((low + high) / 2);
315
- if (encodedBytes(routes.slice(offset, offset + count)) <= this.maxPayloadBytes) {
317
+ if (encodedBytes(routes.slice(offset, offset + count)) <= targetPayloadBytes) {
316
318
  accepted = count;
317
319
  low = count + 1;
318
320
  }
@@ -321,7 +323,10 @@ export class BeamTransferControl {
321
323
  }
322
324
  if (accepted === 0) {
323
325
  const bytes = encodedBytes(routes.slice(offset, offset + 1));
324
- throw new Error(`single signed route is ${bytes} bytes, above maxPayloadBytes=${this.maxPayloadBytes}`);
326
+ if (bytes > this.maxPayloadBytes) {
327
+ throw new Error(`single signed route is ${bytes} bytes, above maxPayloadBytes=${this.maxPayloadBytes}`);
328
+ }
329
+ accepted = 1;
325
330
  }
326
331
  chunks.push(routes.slice(offset, offset + accepted));
327
332
  offset += accepted;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beam-network/sdk",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "TypeScript SDK for BEAM transfer creation and management.",
5
5
  "type": "module",
6
6
  "license": "MIT",