@beam-network/sdk 0.2.7 → 0.2.9
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/client.js +5 -0
- package/dist/models.d.ts +5 -13
- package/dist/provider-signing.js +12 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -88,6 +88,8 @@ export class BeamClient {
|
|
|
88
88
|
if (!prepared.success) {
|
|
89
89
|
return prepared;
|
|
90
90
|
}
|
|
91
|
+
await input.onPrepared?.(prepared);
|
|
92
|
+
await input.throwIfCancelled?.(prepared.transfer_id);
|
|
91
93
|
const destinationsById = new Map();
|
|
92
94
|
preparedDestinations.forEach((preparedDestination, index) => {
|
|
93
95
|
destinationsById.set(preparedDestination.destination_id, input.destinations[index]);
|
|
@@ -100,6 +102,7 @@ export class BeamClient {
|
|
|
100
102
|
const multipartUploads = new Map();
|
|
101
103
|
try {
|
|
102
104
|
for (const chunk of prepared.chunk_plan) {
|
|
105
|
+
await input.throwIfCancelled?.(prepared.transfer_id);
|
|
103
106
|
for (const target of chunk.destinations) {
|
|
104
107
|
const destination = destinationsById.get(target.destination_id);
|
|
105
108
|
if (!destination) {
|
|
@@ -168,6 +171,7 @@ export class BeamClient {
|
|
|
168
171
|
throw error;
|
|
169
172
|
}
|
|
170
173
|
try {
|
|
174
|
+
await input.throwIfCancelled?.(prepared.transfer_id);
|
|
171
175
|
const attached = await this.attachSignedUrls(prepared.transfer_id, {
|
|
172
176
|
chunkRoutes: routes,
|
|
173
177
|
transferKey: prepared.transfer_key
|
|
@@ -181,6 +185,7 @@ export class BeamClient {
|
|
|
181
185
|
throw error;
|
|
182
186
|
}
|
|
183
187
|
if (input.distribute !== false) {
|
|
188
|
+
await input.throwIfCancelled?.(prepared.transfer_id);
|
|
184
189
|
await this.distributeTransfer(prepared.transfer_id);
|
|
185
190
|
}
|
|
186
191
|
return prepared;
|
package/dist/models.d.ts
CHANGED
|
@@ -104,20 +104,10 @@ export interface DestinationStatusInfo {
|
|
|
104
104
|
}
|
|
105
105
|
export interface TransferStatusInfo {
|
|
106
106
|
transfer_id: string;
|
|
107
|
-
name?: string;
|
|
108
107
|
status: string;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
total_destinations?: number;
|
|
113
|
-
chunks_completed?: number;
|
|
114
|
-
destinations_completed?: number;
|
|
115
|
-
sources?: SourceStatusInfo[];
|
|
116
|
-
destinations?: DestinationStatusInfo[];
|
|
117
|
-
created_at?: string;
|
|
118
|
-
started_at?: string;
|
|
119
|
-
completed_at?: string;
|
|
120
|
-
error_message?: string;
|
|
108
|
+
error_message: string | null;
|
|
109
|
+
started_at: string | null;
|
|
110
|
+
completed_at: string | null;
|
|
121
111
|
}
|
|
122
112
|
export interface S3ProviderConfig {
|
|
123
113
|
provider: "s3";
|
|
@@ -194,6 +184,8 @@ export interface ProviderTransferCreateInput {
|
|
|
194
184
|
* Defaults to true. Set to false to only prepare and attach signed URLs.
|
|
195
185
|
*/
|
|
196
186
|
distribute?: boolean;
|
|
187
|
+
onPrepared?: (prepared: TransferPrepareResponse) => void | Promise<void>;
|
|
188
|
+
throwIfCancelled?: (transferId: string) => void | Promise<void>;
|
|
197
189
|
}
|
|
198
190
|
export interface PreparedHttpSource {
|
|
199
191
|
source_id: string;
|
package/dist/provider-signing.js
CHANGED
|
@@ -107,6 +107,17 @@ export async function signUploadPartCopy(destination, finalObjectKey, stagingObj
|
|
|
107
107
|
if (isS3CompatibleProvider(destination)) {
|
|
108
108
|
const client = createS3CompatibleClient(destination);
|
|
109
109
|
const copySource = copySourceHeader(destination, stagingObjectKey);
|
|
110
|
+
// Keep x-amz-copy-source (and x-amz-copy-source-range when present) in
|
|
111
|
+
// X-Amz-SignedHeaders rather than hoisting them to URL query params.
|
|
112
|
+
// The JS AWS SDK default hoists all x-amz-* headers to query params for
|
|
113
|
+
// presigned URLs; R2 ignores copy-source from query params (zero-byte copy)
|
|
114
|
+
// and returns SignatureDoesNotMatch when they are sent as unsigned headers
|
|
115
|
+
// alongside the signed query value. Keeping them as signed headers matches
|
|
116
|
+
// boto3 behavior and the copySourceHeaders replay contract in core-server.
|
|
117
|
+
const unhoistableHeaders = new Set(["x-amz-copy-source"]);
|
|
118
|
+
if (copySourceRange) {
|
|
119
|
+
unhoistableHeaders.add("x-amz-copy-source-range");
|
|
120
|
+
}
|
|
110
121
|
return {
|
|
111
122
|
copySource,
|
|
112
123
|
copyUrl: await getSignedUrl(client, new UploadPartCopyCommand({
|
|
@@ -116,7 +127,7 @@ export async function signUploadPartCopy(destination, finalObjectKey, stagingObj
|
|
|
116
127
|
PartNumber: partNumber,
|
|
117
128
|
CopySource: copySource,
|
|
118
129
|
CopySourceRange: copySourceRange
|
|
119
|
-
}), { expiresIn })
|
|
130
|
+
}), { expiresIn, unhoistableHeaders })
|
|
120
131
|
};
|
|
121
132
|
}
|
|
122
133
|
throw new Error(`multipart copy is not supported for ${destination.provider}`);
|