@beam-network/sdk 0.2.23 → 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/README.md +6 -1
- package/dist/client.d.ts +6 -6
- package/dist/client.js +765 -286
- package/dist/models.d.ts +62 -11
- package/dist/multipart-limits.d.ts +3 -4
- package/dist/multipart-limits.js +8 -9
- package/dist/nats-control.d.ts +32 -44
- package/dist/nats-control.js +287 -133
- package/dist/provider-signing.d.ts +10 -15
- package/dist/provider-signing.js +50 -59
- package/package.json +1 -1
package/dist/models.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type SignedUrlFlow = "
|
|
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
|
|
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,39 @@ export interface TransferStatusInfo {
|
|
|
120
121
|
error_message: string | null;
|
|
121
122
|
started_at: string | null;
|
|
122
123
|
completed_at: string | null;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
runtime?: boolean;
|
|
125
|
+
source_bytes_total: number;
|
|
126
|
+
delivery_bytes_total: number;
|
|
127
|
+
delivery_bytes_completed: number;
|
|
128
|
+
delivery_tasks_total: number;
|
|
129
|
+
delivery_tasks_completed: number;
|
|
130
|
+
destinations_total: number;
|
|
131
|
+
destinations_completed: number;
|
|
132
|
+
destination_progress: Array<{
|
|
133
|
+
destination_id: string;
|
|
134
|
+
delivery_bytes_total: number;
|
|
135
|
+
delivery_bytes_completed: number;
|
|
136
|
+
completion_verified: boolean;
|
|
137
|
+
}>;
|
|
138
|
+
destination_groups?: {
|
|
139
|
+
totalGroups: number;
|
|
140
|
+
completedGroups: number;
|
|
141
|
+
pendingGroups: number;
|
|
142
|
+
totalDestinations: number;
|
|
143
|
+
completedDestinations: number;
|
|
144
|
+
completedDestinationIds: string[];
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export interface TransferTerminalEvent {
|
|
148
|
+
schema_version: "transfer-client-control/v4";
|
|
149
|
+
producer: "transfer-runtime";
|
|
150
|
+
transfer_id: string;
|
|
151
|
+
status: "completed" | "failed" | "cancelled";
|
|
152
|
+
occurred_at: string;
|
|
153
|
+
}
|
|
154
|
+
export interface TransferTerminalSignalWaiter {
|
|
155
|
+
wait(timeoutMs: number): Promise<TransferTerminalEvent | null>;
|
|
156
|
+
close(): Promise<void>;
|
|
127
157
|
}
|
|
128
158
|
export interface S3ProviderConfig {
|
|
129
159
|
provider: "s3";
|
|
@@ -204,6 +234,8 @@ export interface ProviderTransferCreateInput {
|
|
|
204
234
|
onPrepared?: (prepared: TransferPrepareResponse) => void | Promise<void>;
|
|
205
235
|
throwIfCancelled?: (transferId?: string) => void | Promise<void>;
|
|
206
236
|
signedUrlFlow?: SignedUrlFlow;
|
|
237
|
+
/** Stable caller identity used to derive the transfer and lifecycle request ids. */
|
|
238
|
+
idempotencyKey?: string;
|
|
207
239
|
}
|
|
208
240
|
export interface PlanningHttpSource {
|
|
209
241
|
source_id: string;
|
|
@@ -257,13 +289,12 @@ export interface CompactTransferPlanDescriptor {
|
|
|
257
289
|
destinations: CompactTransferPlanDestination[];
|
|
258
290
|
logical_chunk_count: number;
|
|
259
291
|
delivery_route_count: number;
|
|
260
|
-
multipart_attempt_slots: number;
|
|
261
292
|
formulas: {
|
|
262
293
|
source_offset: "source_chunk_index * chunk_size";
|
|
263
294
|
delivery_index: "chunk_index * destination_count + destination_index";
|
|
264
|
-
part_number: "
|
|
295
|
+
part_number: "source_chunk_index + 1";
|
|
265
296
|
route_generation_id: "initial-{chunk_index}-{destination_id}";
|
|
266
|
-
staging_object_key: "{final_object_key}/{
|
|
297
|
+
staging_object_key: "{final_object_key}.beam-staging/{transfer_id}/{source_id}/{destination_id}/part-{part_number}-chunk-{chunk_index}";
|
|
267
298
|
};
|
|
268
299
|
}
|
|
269
300
|
export interface SignedChunkRoute {
|
|
@@ -280,6 +311,26 @@ export interface SignedChunkRoute {
|
|
|
280
311
|
dest_headers?: Record<string, string>;
|
|
281
312
|
metadata?: Record<string, unknown>;
|
|
282
313
|
}
|
|
314
|
+
export interface MultipartGroupManifest {
|
|
315
|
+
multipart_group_id: string;
|
|
316
|
+
source_id: string;
|
|
317
|
+
destination_id: string;
|
|
318
|
+
final_object_key: string;
|
|
319
|
+
upload_id: string;
|
|
320
|
+
expected_object_size: number;
|
|
321
|
+
expected_part_count: number;
|
|
322
|
+
max_part_number: number;
|
|
323
|
+
complete_url: string;
|
|
324
|
+
abort_url: string;
|
|
325
|
+
list_page_urls: string[];
|
|
326
|
+
staging_list_urls: string[];
|
|
327
|
+
final_head_url: string;
|
|
328
|
+
final_object_metadata: {
|
|
329
|
+
"beam-transfer-id": string;
|
|
330
|
+
"beam-multipart-group-id": string;
|
|
331
|
+
};
|
|
332
|
+
urls_expires_at: string;
|
|
333
|
+
}
|
|
283
334
|
export interface TransferPlanResponse {
|
|
284
335
|
success: boolean;
|
|
285
336
|
chunk_size?: number;
|
|
@@ -289,7 +340,7 @@ export interface TransferPlanResponse {
|
|
|
289
340
|
logical_chunks?: number;
|
|
290
341
|
total_chunks?: number;
|
|
291
342
|
plan_descriptor: CompactTransferPlanDescriptor;
|
|
292
|
-
signed_url_flow
|
|
343
|
+
signed_url_flow: SignedUrlFlow;
|
|
293
344
|
error?: string;
|
|
294
345
|
message?: string;
|
|
295
346
|
}
|
|
@@ -305,7 +356,7 @@ export interface TransferPrepareResponse {
|
|
|
305
356
|
logical_chunks?: number;
|
|
306
357
|
total_chunks?: number;
|
|
307
358
|
plan_descriptor: CompactTransferPlanDescriptor;
|
|
308
|
-
signed_url_flow
|
|
359
|
+
signed_url_flow: SignedUrlFlow;
|
|
309
360
|
error?: string;
|
|
310
361
|
message?: string;
|
|
311
362
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
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;
|
package/dist/multipart-limits.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export const
|
|
2
|
-
export const
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
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 (
|
|
9
|
-
throw new Error(`
|
|
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
|
|
10
|
+
return sourceChunkIndex + 1;
|
|
12
11
|
}
|
package/dist/nats-control.d.ts
CHANGED
|
@@ -1,41 +1,9 @@
|
|
|
1
|
-
import type { SignedChunkRoute } from "./models.js";
|
|
2
|
-
export declare const TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION = "transfer-client-control/
|
|
1
|
+
import type { MultipartGroupManifest, SignedChunkRoute, TransferTerminalSignalWaiter } from "./models.js";
|
|
2
|
+
export declare const TRANSFER_CLIENT_CONTROL_SCHEMA_VERSION = "transfer-client-control/v4";
|
|
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
|
|
7
|
-
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
|
-
}
|
|
6
|
+
export type TransferClientMessageType = "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";
|
|
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,26 @@ export interface CompactSignedRouteBatch {
|
|
|
58
22
|
dest_url: string;
|
|
59
23
|
expires_at?: string;
|
|
60
24
|
dest_headers?: Record<string, string>;
|
|
61
|
-
|
|
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
|
+
urls_expires_at?: string;
|
|
36
|
+
signed_url_flow: "signed_url_v2";
|
|
37
|
+
auto_distribute: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface RouteStreamManifestPayload {
|
|
40
|
+
transfer_id: string;
|
|
41
|
+
stream_id: string;
|
|
42
|
+
manifest_batch_id: string;
|
|
43
|
+
groups: MultipartGroupManifest[];
|
|
44
|
+
}
|
|
65
45
|
export interface TransferControlOptions {
|
|
66
46
|
apiKey: string;
|
|
67
47
|
natsUrl?: string;
|
|
@@ -72,6 +52,10 @@ export interface TransferControlOptions {
|
|
|
72
52
|
requestTimeoutMs?: number;
|
|
73
53
|
maxPayloadBytes?: number;
|
|
74
54
|
}
|
|
55
|
+
export interface LifecycleRequestOptions {
|
|
56
|
+
transferId?: string;
|
|
57
|
+
idempotencyKey?: string;
|
|
58
|
+
}
|
|
75
59
|
export declare class BeamTransferControl {
|
|
76
60
|
readonly environment: string;
|
|
77
61
|
readonly keyPrefix: string;
|
|
@@ -82,19 +66,23 @@ export declare class BeamTransferControl {
|
|
|
82
66
|
private readonly natsUrl;
|
|
83
67
|
private readonly apiKey;
|
|
84
68
|
private nc;
|
|
69
|
+
private connectionPromise;
|
|
70
|
+
private closed;
|
|
85
71
|
private authToken;
|
|
86
72
|
private authTokenExpiresAt;
|
|
73
|
+
private authResolvePromise;
|
|
74
|
+
private readonly terminalWaitCancellations;
|
|
87
75
|
constructor(options: TransferControlOptions);
|
|
88
|
-
serveRouteRecoverySigner(transferId: string, handler: (payload: RouteRecoverySignRequestPayload) => Promise<RouteRecoverySignReplyPayload>): Promise<() => void>;
|
|
89
76
|
close(): Promise<void>;
|
|
90
|
-
request<T>(messageType: TransferClientMessageType, payload: Record<string, unknown>,
|
|
77
|
+
request<T>(messageType: TransferClientMessageType, payload: Record<string, unknown>, options?: LifecycleRequestOptions): Promise<T>;
|
|
78
|
+
openTerminalSignalWaiter(transferId: string): Promise<TransferTerminalSignalWaiter>;
|
|
91
79
|
splitRoutesForPayload(messageType: TransferClientMessageType, basePayload: Record<string, unknown>, routes: SignedChunkRoute[]): SignedChunkRoute[][];
|
|
92
80
|
private connection;
|
|
93
81
|
private resolveAuthToken;
|
|
82
|
+
private resolveAuthTokenFresh;
|
|
94
83
|
private authSubject;
|
|
95
|
-
private routeRecoverySignSubject;
|
|
96
|
-
private buildRouteRecoveryReply;
|
|
97
84
|
private requestSubject;
|
|
85
|
+
private terminalSubject;
|
|
98
86
|
}
|
|
99
87
|
export declare function compactSignedRoutes(routes: SignedChunkRoute[]): CompactSignedRouteBatch;
|
|
100
88
|
export declare function transferShardId(transferId: string, shardCount: number): number;
|