@beam-network/sdk 0.2.23 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/models.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type SignedUrlFlow = "signed_url_v1" | "signed_url_v2";
1
+ export type SignedUrlFlow = "signed_url_v2";
2
2
  export interface BeamClientOptions {
3
3
  apiKey?: string;
4
4
  natsUrl?: string;
@@ -52,7 +52,7 @@ export interface TransferCreateRequest {
52
52
  callbacks?: CallbackConfig[];
53
53
  test_mode?: boolean;
54
54
  progressive_mode?: boolean;
55
- signed_url_flow?: SignedUrlFlow;
55
+ signed_url_flow: SignedUrlFlow;
56
56
  }
57
57
  export interface RawTransferCreateInput {
58
58
  sources: SourceConfig[];
@@ -69,6 +69,7 @@ export interface RawTransferCreateInput {
69
69
  testMode?: boolean;
70
70
  progressiveMode?: boolean;
71
71
  signedUrlFlow?: SignedUrlFlow;
72
+ idempotencyKey?: string;
72
73
  }
73
74
  export interface TransferCreateResponse {
74
75
  success: boolean;
@@ -120,10 +121,31 @@ export interface TransferStatusInfo {
120
121
  error_message: string | null;
121
122
  started_at: string | null;
122
123
  completed_at: string | null;
124
+ runtime?: boolean;
123
125
  total_bytes?: number;
124
126
  total_size?: number;
125
127
  total_chunks?: number;
126
128
  chunks_completed?: number;
129
+ total_destinations?: number;
130
+ destinations_completed?: number;
131
+ destination_groups?: {
132
+ totalGroups: number;
133
+ completedGroups: number;
134
+ pendingGroups: number;
135
+ totalDestinations: number;
136
+ completedDestinations: number;
137
+ };
138
+ }
139
+ export interface TransferTerminalEvent {
140
+ schema_version: "transfer-client-control/v3";
141
+ producer: "transfer-runtime";
142
+ transfer_id: string;
143
+ status: "completed" | "failed" | "cancelled";
144
+ occurred_at: string;
145
+ }
146
+ export interface TransferTerminalSignalWaiter {
147
+ wait(timeoutMs: number): Promise<TransferTerminalEvent | null>;
148
+ close(): Promise<void>;
127
149
  }
128
150
  export interface S3ProviderConfig {
129
151
  provider: "s3";
@@ -204,6 +226,8 @@ export interface ProviderTransferCreateInput {
204
226
  onPrepared?: (prepared: TransferPrepareResponse) => void | Promise<void>;
205
227
  throwIfCancelled?: (transferId?: string) => void | Promise<void>;
206
228
  signedUrlFlow?: SignedUrlFlow;
229
+ /** Stable caller identity used to derive the transfer and lifecycle request ids. */
230
+ idempotencyKey?: string;
207
231
  }
208
232
  export interface PlanningHttpSource {
209
233
  source_id: string;
@@ -257,13 +281,12 @@ export interface CompactTransferPlanDescriptor {
257
281
  destinations: CompactTransferPlanDestination[];
258
282
  logical_chunk_count: number;
259
283
  delivery_route_count: number;
260
- multipart_attempt_slots: number;
261
284
  formulas: {
262
285
  source_offset: "source_chunk_index * chunk_size";
263
286
  delivery_index: "chunk_index * destination_count + destination_index";
264
- part_number: "chunk_index * multipart_attempt_slots + attempt_slot + 1";
287
+ part_number: "source_chunk_index + 1";
265
288
  route_generation_id: "initial-{chunk_index}-{destination_id}";
266
- staging_object_key: "{final_object_key}/{plan_nonce}/chunk-{source_chunk_index:6}";
289
+ staging_object_key: "{final_object_key}.beam-staging/{transfer_id}/{source_id}/{destination_id}/part-{part_number}-chunk-{chunk_index}";
267
290
  };
268
291
  }
269
292
  export interface SignedChunkRoute {
@@ -280,6 +303,26 @@ export interface SignedChunkRoute {
280
303
  dest_headers?: Record<string, string>;
281
304
  metadata?: Record<string, unknown>;
282
305
  }
306
+ export interface MultipartGroupManifest {
307
+ multipart_group_id: string;
308
+ source_id: string;
309
+ destination_id: string;
310
+ final_object_key: string;
311
+ upload_id: string;
312
+ expected_object_size: number;
313
+ expected_part_count: number;
314
+ max_part_number: number;
315
+ complete_url: string;
316
+ abort_url: string;
317
+ list_page_urls: string[];
318
+ staging_list_urls: string[];
319
+ final_head_url: string;
320
+ final_object_metadata: {
321
+ "beam-transfer-id": string;
322
+ "beam-multipart-group-id": string;
323
+ };
324
+ urls_expires_at: string;
325
+ }
283
326
  export interface TransferPlanResponse {
284
327
  success: boolean;
285
328
  chunk_size?: number;
@@ -289,7 +332,7 @@ export interface TransferPlanResponse {
289
332
  logical_chunks?: number;
290
333
  total_chunks?: number;
291
334
  plan_descriptor: CompactTransferPlanDescriptor;
292
- signed_url_flow?: SignedUrlFlow;
335
+ signed_url_flow: SignedUrlFlow;
293
336
  error?: string;
294
337
  message?: string;
295
338
  }
@@ -305,7 +348,7 @@ export interface TransferPrepareResponse {
305
348
  logical_chunks?: number;
306
349
  total_chunks?: number;
307
350
  plan_descriptor: CompactTransferPlanDescriptor;
308
- signed_url_flow?: SignedUrlFlow;
351
+ signed_url_flow: SignedUrlFlow;
309
352
  error?: string;
310
353
  message?: string;
311
354
  }
@@ -1,4 +1,3 @@
1
- export declare const DIRECT_MULTIPART_ATTEMPT_SLOT_COUNT = 2;
2
- export declare const DIRECT_MULTIPART_MAX_PART_NUMBER = 10000;
3
- export declare const DIRECT_MULTIPART_MAX_LOGICAL_CHUNKS: number;
4
- export declare function directMultipartInitialPartNumber(chunkIndex: number): number;
1
+ export declare const MULTIPART_MAX_PART_NUMBER = 10000;
2
+ export declare const MULTIPART_MAX_SOURCE_CHUNKS = 10000;
3
+ export declare function multipartPartNumber(sourceChunkIndex: number): number;
@@ -1,12 +1,11 @@
1
- export const DIRECT_MULTIPART_ATTEMPT_SLOT_COUNT = 2;
2
- export const DIRECT_MULTIPART_MAX_PART_NUMBER = 10_000;
3
- export const DIRECT_MULTIPART_MAX_LOGICAL_CHUNKS = Math.floor(DIRECT_MULTIPART_MAX_PART_NUMBER / DIRECT_MULTIPART_ATTEMPT_SLOT_COUNT);
4
- export function directMultipartInitialPartNumber(chunkIndex) {
5
- if (!Number.isInteger(chunkIndex) || chunkIndex < 0) {
6
- throw new Error("chunk_index must be a non-negative integer");
1
+ export const MULTIPART_MAX_PART_NUMBER = 10_000;
2
+ export const MULTIPART_MAX_SOURCE_CHUNKS = MULTIPART_MAX_PART_NUMBER;
3
+ export function multipartPartNumber(sourceChunkIndex) {
4
+ if (!Number.isInteger(sourceChunkIndex) || sourceChunkIndex < 0) {
5
+ throw new Error("source_chunk_index must be a non-negative integer");
7
6
  }
8
- if (chunkIndex >= DIRECT_MULTIPART_MAX_LOGICAL_CHUNKS) {
9
- throw new Error(`chunk_index must be less than ${DIRECT_MULTIPART_MAX_LOGICAL_CHUNKS}`);
7
+ if (sourceChunkIndex >= MULTIPART_MAX_SOURCE_CHUNKS) {
8
+ throw new Error(`source_chunk_index must be less than ${MULTIPART_MAX_SOURCE_CHUNKS}`);
10
9
  }
11
- return chunkIndex * DIRECT_MULTIPART_ATTEMPT_SLOT_COUNT + 1;
10
+ return sourceChunkIndex + 1;
12
11
  }
@@ -1,41 +1,9 @@
1
- import type { SignedChunkRoute } from "./models.js";
2
- export declare const TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION = "transfer-client-control/v2";
1
+ import type { MultipartGroupManifest, SignedChunkRoute, TransferTerminalSignalWaiter } from "./models.js";
2
+ export declare const TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION = "transfer-client-control/v3";
3
3
  export declare const BEAM_DEFAULT_NATS_URL = "tls://nats.b1m.ai:4222";
4
4
  export declare const BEAM_DEFAULT_NATS_WS_URL = "wss://nats.b1m.ai:443";
5
5
  export declare const BEAM_DEFAULT_MAX_PAYLOAD_BYTES: number;
6
- export declare const ROUTE_RECOVERY_SIGN_MESSAGE_TYPE = "transfer.route_recovery.sign";
7
6
  export type TransferClientMessageType = "transfer.plan" | "transfer.create" | "transfer.prepare" | "transfer.route_stream.begin" | "transfer.route_stream.batch" | "transfer.route_stream.complete" | "transfer.distribute" | "transfer.status" | "transfer.cancel";
8
- export interface RouteRecoverySignChunk {
9
- source_id: string;
10
- destination_id: string;
11
- chunk_index: number;
12
- delivery_index: number;
13
- source_offset: number;
14
- chunk_size: number;
15
- logical_attempt_index: number;
16
- attempt_slot: 0 | 1 | 2;
17
- part_number: number;
18
- route_generation_id: string;
19
- multipart_group_id: string;
20
- final_object_key: string;
21
- upload_id?: string;
22
- urls_expires_at?: string;
23
- multipart_created_at?: string;
24
- source_metadata?: Record<string, unknown>;
25
- destination_metadata?: Record<string, unknown>;
26
- }
27
- export interface RouteRecoverySignRequestPayload {
28
- transfer_id: string;
29
- route_generation_id: string;
30
- requested_at?: string;
31
- chunks: RouteRecoverySignChunk[];
32
- }
33
- export interface RouteRecoverySignReplyPayload {
34
- transfer_id: string;
35
- route_generation_id: string;
36
- signed_at?: string;
37
- route_batch: CompactSignedRouteBatch;
38
- }
39
7
  export interface CompactSignedRouteBatch {
40
8
  source_chunks: Array<{
41
9
  source_ref: number;
@@ -47,10 +15,6 @@ export interface CompactSignedRouteBatch {
47
15
  expires_at?: string;
48
16
  headers?: Record<string, string>;
49
17
  }>;
50
- multipart_groups: Array<{
51
- group_ref: number;
52
- metadata: Record<string, unknown>;
53
- }>;
54
18
  routes: Array<{
55
19
  source_ref: number;
56
20
  destination_id: string;
@@ -58,10 +22,21 @@ export interface CompactSignedRouteBatch {
58
22
  dest_url: string;
59
23
  expires_at?: string;
60
24
  dest_headers?: Record<string, string>;
61
- multipart_group_ref?: number;
25
+ multipart_group_id?: string;
62
26
  metadata?: Record<string, unknown>;
63
27
  }>;
64
28
  }
29
+ export interface RouteStreamBeginPayload {
30
+ transfer_id: string;
31
+ stream_id: string;
32
+ total_routes: number;
33
+ total_chunks: number;
34
+ route_contract_version: "signed_url_v2";
35
+ multipart_group_manifest: MultipartGroupManifest[];
36
+ urls_expires_at?: string;
37
+ signed_url_flow: "signed_url_v2";
38
+ auto_distribute: boolean;
39
+ }
65
40
  export interface TransferControlOptions {
66
41
  apiKey: string;
67
42
  natsUrl?: string;
@@ -72,6 +47,10 @@ export interface TransferControlOptions {
72
47
  requestTimeoutMs?: number;
73
48
  maxPayloadBytes?: number;
74
49
  }
50
+ export interface LifecycleRequestOptions {
51
+ transferId?: string;
52
+ idempotencyKey?: string;
53
+ }
75
54
  export declare class BeamTransferControl {
76
55
  readonly environment: string;
77
56
  readonly keyPrefix: string;
@@ -82,19 +61,23 @@ export declare class BeamTransferControl {
82
61
  private readonly natsUrl;
83
62
  private readonly apiKey;
84
63
  private nc;
64
+ private connectionPromise;
65
+ private closed;
85
66
  private authToken;
86
67
  private authTokenExpiresAt;
68
+ private authResolvePromise;
69
+ private readonly terminalWaitCancellations;
87
70
  constructor(options: TransferControlOptions);
88
- serveRouteRecoverySigner(transferId: string, handler: (payload: RouteRecoverySignRequestPayload) => Promise<RouteRecoverySignReplyPayload>): Promise<() => void>;
89
71
  close(): Promise<void>;
90
- request<T>(messageType: TransferClientMessageType, payload: Record<string, unknown>, transferId?: string): Promise<T>;
72
+ request<T>(messageType: TransferClientMessageType, payload: Record<string, unknown>, options?: LifecycleRequestOptions): Promise<T>;
73
+ openTerminalSignalWaiter(transferId: string): Promise<TransferTerminalSignalWaiter>;
91
74
  splitRoutesForPayload(messageType: TransferClientMessageType, basePayload: Record<string, unknown>, routes: SignedChunkRoute[]): SignedChunkRoute[][];
92
75
  private connection;
93
76
  private resolveAuthToken;
77
+ private resolveAuthTokenFresh;
94
78
  private authSubject;
95
- private routeRecoverySignSubject;
96
- private buildRouteRecoveryReply;
97
79
  private requestSubject;
80
+ private terminalSubject;
98
81
  }
99
82
  export declare function compactSignedRoutes(routes: SignedChunkRoute[]): CompactSignedRouteBatch;
100
83
  export declare function transferShardId(transferId: string, shardCount: number): number;