@beam-network/sdk 0.2.2 → 0.2.3

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 CHANGED
@@ -192,8 +192,16 @@ export class BeamClient {
192
192
  if (!input.target.object_key) {
193
193
  throw new Error("destination signing target is missing object_key");
194
194
  }
195
- const { copyUrl, copySource } = await signUploadPartCopy(input.destination, input.finalObjectKey, input.target.object_key, input.upload.uploadId, input.partNumber, input.expiresIn);
196
- const deleteUrl = await signDeleteObject(input.destination, input.target.object_key, input.expiresIn);
195
+ const stagingObjectKey = buildStagingObjectKey({
196
+ finalObjectKey: input.finalObjectKey,
197
+ transferId: input.transferId,
198
+ sourceId: input.chunk.source_id,
199
+ destinationId: input.target.destination_id,
200
+ chunkIndex: input.chunk.chunk_index,
201
+ partNumber: input.partNumber
202
+ });
203
+ const { copyUrl, copySource } = await signUploadPartCopy(input.destination, input.finalObjectKey, stagingObjectKey, input.upload.uploadId, input.partNumber, input.expiresIn);
204
+ const deleteUrl = await signDeleteObject(input.destination, stagingObjectKey, input.expiresIn);
197
205
  return signDestinationRoute({
198
206
  chunk: input.chunk,
199
207
  target: input.target,
@@ -209,7 +217,7 @@ export class BeamClient {
209
217
  multipartGroupId: input.upload.multipartGroupId,
210
218
  multipartCreatedAt: input.upload.multipartCreatedAt,
211
219
  commitMethod: "upload_part_copy",
212
- stagingObjectKey: input.target.object_key,
220
+ stagingObjectKey,
213
221
  copyUrl,
214
222
  copySource,
215
223
  deleteUrl,
@@ -292,6 +300,19 @@ function normalizeBaseUrl(value) {
292
300
  function compact(input) {
293
301
  return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
294
302
  }
303
+ function buildStagingObjectKey(input) {
304
+ const base = input.finalObjectKey.replace(/\/+$/, "") || "object";
305
+ return [
306
+ `${base}.beam-staging`,
307
+ safeObjectKeySegment(input.transferId),
308
+ safeObjectKeySegment(input.sourceId),
309
+ safeObjectKeySegment(input.destinationId),
310
+ `part-${input.partNumber}-chunk-${input.chunkIndex}`
311
+ ].join("/");
312
+ }
313
+ function safeObjectKeySegment(value) {
314
+ return encodeURIComponent(value).replace(/%2F/gi, "_");
315
+ }
295
316
  function validateId(value, name) {
296
317
  if (!value || value.includes("/") || value.includes("..")) {
297
318
  throw new Error(`${name} is invalid`);
@@ -135,11 +135,14 @@ export async function abortMultipartUpload(destination, objectKey, uploadId) {
135
135
  throw new Error(`multipart abort is not supported for ${destination.provider}`);
136
136
  }
137
137
  export async function signDestinationRoute(input) {
138
- const objectKey = input.target.object_key;
139
- if (!objectKey) {
138
+ const targetObjectKey = input.target.object_key;
139
+ if (!targetObjectKey) {
140
140
  throw new Error("destination signing target is missing object_key");
141
141
  }
142
- const uploadPartObjectKey = input.multipartObjectKey ?? objectKey;
142
+ const objectKey = input.commitMethod === "upload_part_copy" && input.stagingObjectKey
143
+ ? input.stagingObjectKey
144
+ : targetObjectKey;
145
+ const uploadPartObjectKey = input.multipartObjectKey ?? targetObjectKey;
143
146
  const destUrl = await signDestinationUrl({
144
147
  destination: input.destination,
145
148
  objectKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beam-network/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "TypeScript SDK for BEAM transfer creation and management.",
5
5
  "type": "module",
6
6
  "license": "MIT",