@beam-network/sdk 0.2.0 → 0.2.1
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 +4 -1
- package/dist/provider-signing.d.ts +2 -0
- package/dist/provider-signing.js +18 -4
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { abortMultipartUpload, createMultipartUpload, nowIso, prepareProviderDestination, prepareProviderSource, signAbortMultipartUpload, signCompleteMultipartUpload, signDestinationRoute } from "./provider-signing.js";
|
|
1
|
+
import { abortMultipartUpload, createMultipartUpload, nowIso, prepareProviderDestination, prepareProviderSource, signAbortMultipartUpload, signCompleteMultipartUpload, signDestinationRoute, signListMultipartUpload } 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;
|
|
@@ -119,6 +119,7 @@ export class BeamClient {
|
|
|
119
119
|
uploadId: "",
|
|
120
120
|
completeUrl: "",
|
|
121
121
|
abortUrl: "",
|
|
122
|
+
listUrl: "",
|
|
122
123
|
multipartGroupId: multipartKey,
|
|
123
124
|
multipartCreatedAt
|
|
124
125
|
};
|
|
@@ -131,6 +132,7 @@ export class BeamClient {
|
|
|
131
132
|
uploadId,
|
|
132
133
|
completeUrl: await signCompleteMultipartUpload(destination, finalObjectKey, uploadId, expiresIn),
|
|
133
134
|
abortUrl: await signAbortMultipartUpload(destination, finalObjectKey, uploadId, expiresIn),
|
|
135
|
+
listUrl: await signListMultipartUpload(destination, finalObjectKey, uploadId, expiresIn),
|
|
134
136
|
multipartGroupId: multipartKey,
|
|
135
137
|
multipartCreatedAt
|
|
136
138
|
};
|
|
@@ -149,6 +151,7 @@ export class BeamClient {
|
|
|
149
151
|
multipartObjectKey: finalObjectKey,
|
|
150
152
|
completeUrl: upload.completeUrl,
|
|
151
153
|
abortUrl: upload.abortUrl,
|
|
154
|
+
listUrl: upload.listUrl,
|
|
152
155
|
transferId: prepared.transfer_id,
|
|
153
156
|
multipartGroupId: upload.multipartGroupId,
|
|
154
157
|
multipartCreatedAt: upload.multipartCreatedAt,
|
|
@@ -13,6 +13,7 @@ export declare function prepareProviderDestination(destination: ProviderDestinat
|
|
|
13
13
|
export declare function createMultipartUpload(destination: ProviderDestinationConfig, objectKey: string): Promise<string>;
|
|
14
14
|
export declare function signCompleteMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string, expiresIn: number): Promise<string>;
|
|
15
15
|
export declare function signAbortMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string, expiresIn: number): Promise<string>;
|
|
16
|
+
export declare function signListMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string, expiresIn: number): Promise<string>;
|
|
16
17
|
export declare function abortMultipartUpload(destination: ProviderDestinationConfig, objectKey: string, uploadId: string): Promise<void>;
|
|
17
18
|
export declare function signDestinationRoute(input: {
|
|
18
19
|
chunk: ChunkSigningPlanItem;
|
|
@@ -24,6 +25,7 @@ export declare function signDestinationRoute(input: {
|
|
|
24
25
|
multipartObjectKey?: string;
|
|
25
26
|
completeUrl?: string;
|
|
26
27
|
abortUrl?: string;
|
|
28
|
+
listUrl?: string;
|
|
27
29
|
transferId?: string;
|
|
28
30
|
multipartGroupId?: string;
|
|
29
31
|
multipartCreatedAt?: string;
|
package/dist/provider-signing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortMultipartUploadCommand, CompleteMultipartUploadCommand, CreateMultipartUploadCommand, GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client, UploadPartCommand } from "@aws-sdk/client-s3";
|
|
1
|
+
import { AbortMultipartUploadCommand, CompleteMultipartUploadCommand, CreateMultipartUploadCommand, GetObjectCommand, HeadObjectCommand, ListPartsCommand, PutObjectCommand, S3Client, UploadPartCommand } from "@aws-sdk/client-s3";
|
|
2
2
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
3
3
|
export function nowIso() {
|
|
4
4
|
return new Date().toISOString();
|
|
@@ -52,7 +52,9 @@ export function prepareProviderDestination(destination, options = {}) {
|
|
|
52
52
|
destination_id: destinationId,
|
|
53
53
|
provider: destination.provider,
|
|
54
54
|
logical_prefix: destination.key,
|
|
55
|
-
metadata:
|
|
55
|
+
metadata: {
|
|
56
|
+
...s3CompatibleMetadata(destination, endpoint)
|
|
57
|
+
}
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
if (isHippiusProvider(destination)) {
|
|
@@ -60,7 +62,11 @@ export function prepareProviderDestination(destination, options = {}) {
|
|
|
60
62
|
destination_id: destinationId,
|
|
61
63
|
provider: "hippius",
|
|
62
64
|
logical_prefix: destination.key.replace(/\/+$/, ""),
|
|
63
|
-
metadata: {
|
|
65
|
+
metadata: {
|
|
66
|
+
bucket: destination.bucket,
|
|
67
|
+
key: destination.key,
|
|
68
|
+
base_url: destination.base_url ?? "https://api.hippius.com"
|
|
69
|
+
}
|
|
64
70
|
};
|
|
65
71
|
}
|
|
66
72
|
return unsupportedProviderConfig(destination);
|
|
@@ -90,6 +96,13 @@ export async function signAbortMultipartUpload(destination, objectKey, uploadId,
|
|
|
90
96
|
}
|
|
91
97
|
throw new Error(`multipart abort is not supported for ${destination.provider}`);
|
|
92
98
|
}
|
|
99
|
+
export async function signListMultipartUpload(destination, objectKey, uploadId, expiresIn) {
|
|
100
|
+
if (isS3CompatibleProvider(destination)) {
|
|
101
|
+
const client = createS3CompatibleClient(destination);
|
|
102
|
+
return getSignedUrl(client, new ListPartsCommand({ Bucket: destination.bucket, Key: objectKey, UploadId: uploadId }), { expiresIn });
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`multipart list-parts is not supported for ${destination.provider}`);
|
|
105
|
+
}
|
|
93
106
|
export async function abortMultipartUpload(destination, objectKey, uploadId) {
|
|
94
107
|
if (isS3CompatibleProvider(destination)) {
|
|
95
108
|
await createS3CompatibleClient(destination).send(new AbortMultipartUploadCommand({ Bucket: destination.bucket, Key: objectKey, UploadId: uploadId }));
|
|
@@ -129,7 +142,8 @@ export async function signDestinationRoute(input) {
|
|
|
129
142
|
...(input.uploadId ? { upload_id: input.uploadId } : {}),
|
|
130
143
|
...(input.partNumber ? { part_number: input.partNumber } : {}),
|
|
131
144
|
...(input.completeUrl ? { complete_url: input.completeUrl } : {}),
|
|
132
|
-
...(input.abortUrl ? { abort_url: input.abortUrl } : {})
|
|
145
|
+
...(input.abortUrl ? { abort_url: input.abortUrl } : {}),
|
|
146
|
+
...(input.listUrl ? { list_url: input.listUrl } : {})
|
|
133
147
|
}
|
|
134
148
|
};
|
|
135
149
|
}
|