@beam-network/sdk 0.2.13 → 0.2.14

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.d.ts CHANGED
@@ -48,6 +48,12 @@ export declare class BeamClient {
48
48
  private request;
49
49
  }
50
50
  export declare function calculateOptimalChunkSize(totalSize: number): number;
51
+ export declare function buildStagingObjectPrefix(input: {
52
+ finalObjectKey: string;
53
+ transferId: string;
54
+ sourceId: string;
55
+ destinationId: string;
56
+ }): string;
51
57
  export declare function buildStagingObjectKey(input: {
52
58
  finalObjectKey: string;
53
59
  transferId: string;
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { abortMultipartUpload, computeChunksContentMd5, createMultipartUpload, nowIso, prepareProviderDestination, prepareProviderSource, prepareProviderSourceForPlan, isS3CompatibleProvider, listPartsPageMarker, listPartsVerifyMarker, signAbortMultipartUpload, signCompleteMultipartUpload, signDeleteObject, signDestinationRoute, signListMultipartUpload, signUploadPartCopy } from "./provider-signing.js";
1
+ import { abortMultipartUpload, computeChunksContentMd5, createMultipartUpload, nowIso, prepareProviderDestination, prepareProviderSource, prepareProviderSourceForPlan, isS3CompatibleProvider, listPartsPageMarker, listPartsVerifyMarker, signAbortMultipartUpload, signCompleteMultipartUpload, signDeleteObject, signDestinationRoute, signListMultipartUpload, signListObjects, signUploadPartCopy } from "./provider-signing.js";
2
2
  export const BEAM_DEFAULT_URL = "https://beamcore.b1m.ai";
3
3
  export class BeamApiError extends Error {
4
4
  status;
@@ -341,16 +341,19 @@ export class BeamClient {
341
341
  fetchImpl: this.fetchImpl
342
342
  });
343
343
  }
344
- const stagingObjectKey = buildStagingObjectKey({
344
+ const stagingObjectPrefix = buildStagingObjectPrefix({
345
345
  finalObjectKey: input.finalObjectKey,
346
346
  transferId: input.transferId,
347
347
  sourceId: input.chunk.source_id,
348
- destinationId: input.target.destination_id,
349
- chunkIndex: input.chunk.chunk_index,
350
- partNumber: input.partNumber
348
+ destinationId: input.target.destination_id
351
349
  });
350
+ const stagingObjectKey = [
351
+ stagingObjectPrefix,
352
+ `part-${input.partNumber}-chunk-${input.chunk.chunk_index}`
353
+ ].join("/");
352
354
  const copySourceRange = `bytes=0-${Math.max(0, input.chunk.chunk_size - 1)}`;
353
355
  const { copyUrl, copySource } = await signUploadPartCopy(input.destination, input.finalObjectKey, stagingObjectKey, input.upload.uploadId, input.partNumber, input.expiresIn, copySourceRange);
356
+ const stagingListUrl = await signListObjects(input.destination, stagingObjectPrefix, input.expiresIn);
354
357
  const deleteUrl = await signDeleteObject(input.destination, stagingObjectKey, input.expiresIn);
355
358
  return signDestinationRoute({
356
359
  chunk: input.chunk,
@@ -369,6 +372,7 @@ export class BeamClient {
369
372
  multipartCreatedAt: input.upload.multipartCreatedAt,
370
373
  commitMethod: "upload_part_copy",
371
374
  stagingObjectKey,
375
+ stagingListUrl,
372
376
  copyUrl,
373
377
  copySource,
374
378
  copySourceRange,
@@ -716,13 +720,18 @@ function normalizeBaseUrl(value) {
716
720
  function compact(input) {
717
721
  return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
718
722
  }
719
- export function buildStagingObjectKey(input) {
723
+ export function buildStagingObjectPrefix(input) {
720
724
  const base = input.finalObjectKey.replace(/\/+$/, "") || "object";
721
725
  return [
722
726
  `${base}.beam-staging`,
723
727
  safeObjectKeySegment(input.transferId),
724
728
  safeObjectKeySegment(input.sourceId),
725
- safeObjectKeySegment(input.destinationId),
729
+ safeObjectKeySegment(input.destinationId)
730
+ ].join("/");
731
+ }
732
+ export function buildStagingObjectKey(input) {
733
+ return [
734
+ buildStagingObjectPrefix(input),
726
735
  `part-${input.partNumber}-chunk-${input.chunkIndex}`
727
736
  ].join("/");
728
737
  }
@@ -17,6 +17,7 @@ export declare function prepareProviderDestination(destination: ProviderDestinat
17
17
  export declare function createMultipartUpload(destination: ProviderDestinationConfig, objectKey: string): Promise<string>;
18
18
  export declare function signCompleteMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string, expiresIn: number): Promise<string>;
19
19
  export declare function signAbortMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string, expiresIn: number): Promise<string>;
20
+ export declare function signListObjects(destination: ProviderDestinationConfig, prefix: string, expiresIn: number): Promise<string>;
20
21
  export declare function signListMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string, expiresIn: number, options?: {
21
22
  maxParts?: number;
22
23
  partNumberMarker?: number;
@@ -49,6 +50,7 @@ export declare function signDestinationRoute(input: {
49
50
  partVerifyUrl?: string;
50
51
  listPageUrl?: string;
51
52
  stagingObjectKey?: string;
53
+ stagingListUrl?: string;
52
54
  copyUrl?: string;
53
55
  copySource?: string;
54
56
  copySourceRange?: string;
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { AbortMultipartUploadCommand, CompleteMultipartUploadCommand, CreateMultipartUploadCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListPartsCommand, PutObjectCommand, S3Client, UploadPartCopyCommand, UploadPartCommand } from "@aws-sdk/client-s3";
2
+ import { AbortMultipartUploadCommand, CompleteMultipartUploadCommand, CreateMultipartUploadCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, ListPartsCommand, PutObjectCommand, S3Client, UploadPartCopyCommand, UploadPartCommand } from "@aws-sdk/client-s3";
3
3
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
4
4
  export function nowIso() {
5
5
  return new Date().toISOString();
@@ -139,6 +139,13 @@ export async function signAbortMultipartUpload(destination, objectKey, uploadId,
139
139
  }
140
140
  throw new Error(`multipart abort is not supported for ${destination.provider}`);
141
141
  }
142
+ export async function signListObjects(destination, prefix, expiresIn) {
143
+ if (isS3CompatibleProvider(destination)) {
144
+ const client = createS3CompatibleClient(destination);
145
+ return getSignedUrl(client, new ListObjectsV2Command({ Bucket: destination.bucket, Prefix: prefix }), { expiresIn });
146
+ }
147
+ throw new Error(`multipart staging list is not supported for ${destination.provider}`);
148
+ }
142
149
  export async function signListMultipartUpload(destination, objectKey, uploadId, expiresIn, options = {}) {
143
150
  if (isS3CompatibleProvider(destination)) {
144
151
  const client = createS3CompatibleClient(destination);
@@ -247,6 +254,7 @@ export async function signDestinationRoute(input) {
247
254
  ...(input.multipartCreatedAt ? { multipart_created_at: input.multipartCreatedAt } : {}),
248
255
  ...(input.commitMethod ? { commit_method: input.commitMethod } : {}),
249
256
  ...(input.stagingObjectKey ? { staging_object_key: input.stagingObjectKey } : {}),
257
+ ...(input.stagingListUrl ? { staging_list_url: input.stagingListUrl } : {}),
250
258
  ...(input.copyUrl ? { copy_url: input.copyUrl } : {}),
251
259
  ...(input.copySource ? { copy_source: input.copySource } : {}),
252
260
  ...(input.copySourceRange ? { copy_source_range: input.copySourceRange } : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beam-network/sdk",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "TypeScript SDK for BEAM transfer creation and management.",
5
5
  "type": "module",
6
6
  "license": "MIT",