@edgestore/server 0.0.0-alpha.12

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.
Files changed (83) hide show
  1. package/README.md +86 -0
  2. package/adapters/next/app/index.d.ts +1 -0
  3. package/adapters/next/app/index.js +1 -0
  4. package/adapters/next/index.d.ts +1 -0
  5. package/adapters/next/index.js +1 -0
  6. package/adapters/next/pages/index.d.ts +1 -0
  7. package/adapters/next/pages/index.js +1 -0
  8. package/core/index.d.ts +1 -0
  9. package/core/index.js +1 -0
  10. package/dist/adapters/imageTypes.d.ts +2 -0
  11. package/dist/adapters/imageTypes.d.ts.map +1 -0
  12. package/dist/adapters/next/app/index.d.ts +14 -0
  13. package/dist/adapters/next/app/index.d.ts.map +1 -0
  14. package/dist/adapters/next/app/index.js +95 -0
  15. package/dist/adapters/next/app/index.mjs +91 -0
  16. package/dist/adapters/next/pages/index.d.ts +15 -0
  17. package/dist/adapters/next/pages/index.d.ts.map +1 -0
  18. package/dist/adapters/next/pages/index.js +69 -0
  19. package/dist/adapters/next/pages/index.mjs +65 -0
  20. package/dist/adapters/shared.d.ts +79 -0
  21. package/dist/adapters/shared.d.ts.map +1 -0
  22. package/dist/core/client/index.d.ts +81 -0
  23. package/dist/core/client/index.d.ts.map +1 -0
  24. package/dist/core/index.d.ts +6 -0
  25. package/dist/core/index.d.ts.map +1 -0
  26. package/dist/core/index.js +96 -0
  27. package/dist/core/index.mjs +91 -0
  28. package/dist/core/internals/bucketBuilder.d.ts +199 -0
  29. package/dist/core/internals/bucketBuilder.d.ts.map +1 -0
  30. package/dist/core/internals/createPathParamProxy.d.ts +21 -0
  31. package/dist/core/internals/createPathParamProxy.d.ts.map +1 -0
  32. package/dist/core/sdk/index.d.ts +200 -0
  33. package/dist/core/sdk/index.d.ts.map +1 -0
  34. package/dist/index-3999aae6.js +187 -0
  35. package/dist/index-3cc4d530.js +183 -0
  36. package/dist/index-ca41982b.mjs +183 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +213 -0
  40. package/dist/index.mjs +209 -0
  41. package/dist/libs/errors/EdgeStoreCredentialsError.d.ts +5 -0
  42. package/dist/libs/errors/EdgeStoreCredentialsError.d.ts.map +1 -0
  43. package/dist/libs/errors/EdgeStoreError.d.ts +16 -0
  44. package/dist/libs/errors/EdgeStoreError.d.ts.map +1 -0
  45. package/dist/providers/aws/index.d.ts +9 -0
  46. package/dist/providers/aws/index.d.ts.map +1 -0
  47. package/dist/providers/aws/index.js +81 -0
  48. package/dist/providers/aws/index.mjs +77 -0
  49. package/dist/providers/edgestore/index.d.ts +8 -0
  50. package/dist/providers/edgestore/index.d.ts.map +1 -0
  51. package/dist/providers/edgestore/index.js +121 -0
  52. package/dist/providers/edgestore/index.mjs +117 -0
  53. package/dist/providers/index.d.ts +3 -0
  54. package/dist/providers/index.d.ts.map +1 -0
  55. package/dist/providers/types.d.ts +91 -0
  56. package/dist/providers/types.d.ts.map +1 -0
  57. package/dist/shared-43667670.mjs +232 -0
  58. package/dist/shared-6bef8919.js +227 -0
  59. package/dist/shared-f7607e44.js +239 -0
  60. package/dist/types.d.ts +88 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/package.json +96 -0
  63. package/providers/aws/index.d.ts +1 -0
  64. package/providers/aws/index.js +1 -0
  65. package/providers/edgestore/index.d.ts +1 -0
  66. package/providers/edgestore/index.js +1 -0
  67. package/src/adapters/imageTypes.ts +10 -0
  68. package/src/adapters/next/app/index.ts +111 -0
  69. package/src/adapters/next/pages/index.ts +84 -0
  70. package/src/adapters/shared.ts +306 -0
  71. package/src/core/client/index.ts +202 -0
  72. package/src/core/index.ts +10 -0
  73. package/src/core/internals/bucketBuilder.ts +462 -0
  74. package/src/core/internals/createPathParamProxy.ts +40 -0
  75. package/src/core/sdk/index.ts +381 -0
  76. package/src/index.ts +1 -0
  77. package/src/libs/errors/EdgeStoreCredentialsError.ts +12 -0
  78. package/src/libs/errors/EdgeStoreError.ts +25 -0
  79. package/src/providers/aws/index.ts +109 -0
  80. package/src/providers/edgestore/index.ts +140 -0
  81. package/src/providers/index.ts +2 -0
  82. package/src/providers/types.ts +107 -0
  83. package/src/types.ts +139 -0
@@ -0,0 +1,381 @@
1
+ import { AnyRouter } from '..';
2
+ import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError';
3
+ import { AnyContext } from '../internals/bucketBuilder';
4
+
5
+ const API_ENDPOINT =
6
+ process.env.EDGE_STORE_API_ENDPOINT ?? 'https://api.edge-store.com';
7
+
8
+ type FileInfoForUpload = {
9
+ size: number;
10
+ extension: string;
11
+ isPublic: boolean;
12
+ path: {
13
+ key: string;
14
+ value: string;
15
+ }[];
16
+ metadata?: {
17
+ [key: string]: string;
18
+ };
19
+ replaceTargetUrl?: string;
20
+ };
21
+
22
+ export type SimpleOperator =
23
+ | 'eq'
24
+ | 'neq'
25
+ | 'gt'
26
+ | 'gte'
27
+ | 'lt'
28
+ | 'lte'
29
+ | 'startsWith'
30
+ | 'endsWith';
31
+
32
+ export type Comparison<TType = string> =
33
+ | TType
34
+ | Partial<
35
+ {
36
+ [K in SimpleOperator]: TType;
37
+ } & {
38
+ between: [TType, TType];
39
+ }
40
+ >;
41
+
42
+ type ListFilesFilter = {
43
+ AND?: ListFilesFilter[];
44
+ OR?: ListFilesFilter[];
45
+ uploadedAt?: Comparison<Date>;
46
+ path?: Partial<{
47
+ [key: string]: Comparison;
48
+ }>;
49
+ metadata?: Partial<{
50
+ [key: string]: Comparison;
51
+ }>;
52
+ };
53
+
54
+ type Pagination = {
55
+ currentPage: number;
56
+ pageSize: number;
57
+ };
58
+
59
+ async function makeRequest<TOutput>(params: {
60
+ body: object;
61
+ accessKey: string;
62
+ secretKey: string;
63
+ path: string;
64
+ }) {
65
+ const { body, accessKey, secretKey, path } = params;
66
+ const res = await fetch(`${API_ENDPOINT}${path}`, {
67
+ method: 'POST',
68
+ body: JSON.stringify(body),
69
+ headers: {
70
+ 'Content-Type': 'application/json',
71
+ Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString(
72
+ 'base64',
73
+ )}`,
74
+ },
75
+ });
76
+ if (!res.ok) {
77
+ throw new Error(`Failed to make request to ${path}`);
78
+ }
79
+ return (await res.json()) as TOutput;
80
+ }
81
+
82
+ export const edgeStoreRawSdk = {
83
+ async getToken(params: {
84
+ accessKey: string;
85
+ secretKey: string;
86
+ ctx: AnyContext;
87
+ router: AnyRouter;
88
+ }) {
89
+ const reqBuckets = Object.entries(params.router.buckets).reduce(
90
+ (acc, [bucketName, bucket]) => {
91
+ acc[bucketName] = {
92
+ path: bucket._def.path.map((p: { [key: string]: () => string }) => {
93
+ const paramEntries = Object.entries(p);
94
+ if (paramEntries[0] === undefined) {
95
+ throw new Error('Missing path param');
96
+ }
97
+ const [key, value] = paramEntries[0];
98
+ return {
99
+ key,
100
+ value: value(),
101
+ };
102
+ }),
103
+ accessControl: bucket._def.accessControl,
104
+ };
105
+ return acc;
106
+ },
107
+ {} as any,
108
+ );
109
+ const { token } = await makeRequest<{ token: string }>({
110
+ body: {
111
+ ctx: params.ctx,
112
+ buckets: reqBuckets,
113
+ },
114
+ accessKey: params.accessKey,
115
+ secretKey: params.secretKey,
116
+ path: '/get-token',
117
+ });
118
+ return token;
119
+ },
120
+
121
+ async getFile({
122
+ accessKey,
123
+ secretKey,
124
+ url,
125
+ }: {
126
+ accessKey: string;
127
+ secretKey: string;
128
+ url: string;
129
+ }) {
130
+ return await makeRequest<{
131
+ url: string;
132
+ size: number;
133
+ uploadedAt: string;
134
+ path: Record<string, string>;
135
+ metadata: Record<string, string>;
136
+ }>({
137
+ path: '/get-file',
138
+ accessKey,
139
+ secretKey,
140
+ body: {
141
+ url,
142
+ },
143
+ });
144
+ },
145
+
146
+ async requestUpload({
147
+ accessKey,
148
+ secretKey,
149
+ bucketName,
150
+ bucketType,
151
+ fileInfo,
152
+ multipart,
153
+ }: {
154
+ accessKey: string;
155
+ secretKey: string;
156
+ bucketName: string;
157
+ bucketType: string;
158
+ fileInfo: FileInfoForUpload;
159
+ multipart?: {
160
+ parts: number[];
161
+ };
162
+ }) {
163
+ const res = await makeRequest<{
164
+ multipart?: {
165
+ uploadId: string;
166
+ parts: {
167
+ partNumber: number;
168
+ signedUrl: string;
169
+ }[];
170
+ };
171
+ signedUrl?: string;
172
+ url: string;
173
+ }>({
174
+ path: '/request-upload',
175
+ accessKey,
176
+ secretKey,
177
+ body: {
178
+ multipart,
179
+ bucketName,
180
+ bucketType,
181
+ isPublic: fileInfo.isPublic,
182
+ path: fileInfo.path,
183
+ extension: fileInfo.extension,
184
+ size: fileInfo.size,
185
+ metadata: fileInfo.metadata,
186
+ replaceTargetUrl: fileInfo.replaceTargetUrl,
187
+ },
188
+ });
189
+ return {
190
+ multipart: res.multipart,
191
+ signedUrl: res.signedUrl,
192
+ accessUrl: res.url,
193
+ };
194
+ },
195
+
196
+ async requestUploadParts({
197
+ accessKey,
198
+ secretKey,
199
+ key,
200
+ multipart,
201
+ }: {
202
+ accessKey: string;
203
+ secretKey: string;
204
+ key: string;
205
+ multipart: {
206
+ uploadId?: string;
207
+ parts: number[];
208
+ };
209
+ }) {
210
+ const res = await makeRequest<{
211
+ multipart: {
212
+ uploadId: string;
213
+ parts: {
214
+ partNumber: number;
215
+ signedUrl: string;
216
+ }[];
217
+ };
218
+ }>({
219
+ path: '/request-upload-parts',
220
+ accessKey,
221
+ secretKey,
222
+ body: {
223
+ multipart,
224
+ key,
225
+ },
226
+ });
227
+ return {
228
+ multipart: res.multipart,
229
+ };
230
+ },
231
+
232
+ async deleteFile({
233
+ accessKey,
234
+ secretKey,
235
+ url,
236
+ }: {
237
+ accessKey: string;
238
+ secretKey: string;
239
+ url: string;
240
+ }) {
241
+ return await makeRequest<{ success: boolean }>({
242
+ path: '/delete-file',
243
+ accessKey,
244
+ secretKey,
245
+ body: {
246
+ url,
247
+ },
248
+ });
249
+ },
250
+
251
+ async listFiles({
252
+ accessKey,
253
+ secretKey,
254
+ bucketName,
255
+ filter,
256
+ pagination,
257
+ }: {
258
+ accessKey: string;
259
+ secretKey: string;
260
+ bucketName: string;
261
+ filter?: ListFilesFilter;
262
+ pagination?: Pagination;
263
+ }) {
264
+ return await makeRequest<{
265
+ data: {
266
+ url: string;
267
+ thumbnailUrl: string | null;
268
+ size: number;
269
+ uploadedAt: string;
270
+ path: Record<string, string>;
271
+ metadata: Record<string, string>;
272
+ }[];
273
+ pagination: {
274
+ currentPage: number;
275
+ pageSize: number;
276
+ totalPages: number;
277
+ totalCount: number;
278
+ };
279
+ }>({
280
+ path: '/list-files',
281
+ accessKey,
282
+ secretKey,
283
+ body: {
284
+ bucketName,
285
+ filter,
286
+ pagination,
287
+ },
288
+ });
289
+ },
290
+ };
291
+
292
+ export function initEdgeStoreSdk(params: {
293
+ accessKey?: string;
294
+ secretKey?: string;
295
+ }) {
296
+ const {
297
+ accessKey = process.env.EDGE_STORE_ACCESS_KEY,
298
+ secretKey = process.env.EDGE_STORE_SECRET_KEY,
299
+ } = params ?? {};
300
+
301
+ if (!accessKey || !secretKey) {
302
+ throw new EdgeStoreCredentialsError();
303
+ }
304
+
305
+ return {
306
+ async getToken(params: { ctx: AnyContext; router: AnyRouter }) {
307
+ return await edgeStoreRawSdk.getToken({
308
+ accessKey,
309
+ secretKey,
310
+ ctx: params.ctx,
311
+ router: params.router,
312
+ });
313
+ },
314
+ async getFile({ url }: { url: string }) {
315
+ return await edgeStoreRawSdk.getFile({
316
+ accessKey,
317
+ secretKey,
318
+ url,
319
+ });
320
+ },
321
+ async requestUpload({
322
+ bucketName,
323
+ bucketType,
324
+ fileInfo,
325
+ multipart,
326
+ }: {
327
+ bucketName: string;
328
+ bucketType: string;
329
+ fileInfo: FileInfoForUpload;
330
+ multipart?: {
331
+ parts: number[];
332
+ };
333
+ }) {
334
+ return await edgeStoreRawSdk.requestUpload({
335
+ accessKey,
336
+ secretKey,
337
+ bucketName,
338
+ bucketType,
339
+ fileInfo,
340
+ multipart,
341
+ });
342
+ },
343
+ async requestUploadParts({
344
+ key,
345
+ multipart,
346
+ }: {
347
+ key: string;
348
+ multipart: {
349
+ uploadId?: string;
350
+ parts: number[];
351
+ };
352
+ }) {
353
+ return await edgeStoreRawSdk.requestUploadParts({
354
+ accessKey,
355
+ secretKey,
356
+ key,
357
+ multipart,
358
+ });
359
+ },
360
+ async deleteFile({ url }: { url: string }) {
361
+ return await edgeStoreRawSdk.deleteFile({
362
+ accessKey,
363
+ secretKey,
364
+ url,
365
+ });
366
+ },
367
+ async listFiles(params: {
368
+ bucketName: string;
369
+ filter?: ListFilesFilter;
370
+ pagination?: Pagination;
371
+ }) {
372
+ return await edgeStoreRawSdk.listFiles({
373
+ accessKey,
374
+ secretKey,
375
+ ...params,
376
+ });
377
+ },
378
+ };
379
+ }
380
+
381
+ export type EdgeStoreSdk = ReturnType<typeof initEdgeStoreSdk>;
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { initEdgeStore } from './core/internals/bucketBuilder';
@@ -0,0 +1,12 @@
1
+ const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
2
+ This can happen if you are trying to use the vanilla client in your frontend.
3
+ The vanilla client should only be used in the backend.`;
4
+
5
+ class EdgeStoreCredentialsError extends Error {
6
+ constructor(message = DEFAULT_MESSAGE) {
7
+ super(message);
8
+ this.name = 'EdgeStoreCredentialsError';
9
+ }
10
+ }
11
+
12
+ export default EdgeStoreCredentialsError;
@@ -0,0 +1,25 @@
1
+ export const EDGE_STORE_ERROR_CODES = {
2
+ BAD_REQUEST: 400,
3
+ UNAUTHORIZED: 401,
4
+ } as const;
5
+
6
+ export type EdgeStoreErrorCodeKey = keyof typeof EDGE_STORE_ERROR_CODES;
7
+
8
+ class EdgeStoreError extends Error {
9
+ public readonly cause?: Error;
10
+ public readonly code: EdgeStoreErrorCodeKey;
11
+
12
+ constructor(opts: {
13
+ message: string;
14
+ code: EdgeStoreErrorCodeKey;
15
+ cause?: Error;
16
+ }) {
17
+ super(opts.message);
18
+ this.name = 'EdgeStoreError';
19
+
20
+ this.code = opts.code;
21
+ this.cause = opts.cause;
22
+ }
23
+ }
24
+
25
+ export default EdgeStoreError;
@@ -0,0 +1,109 @@
1
+ import {
2
+ DeleteObjectCommand,
3
+ HeadObjectCommand,
4
+ PutObjectCommand,
5
+ S3Client,
6
+ } from '@aws-sdk/client-s3';
7
+ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
8
+ import { v4 as uuidv4 } from 'uuid';
9
+ import { Provider } from '../types';
10
+
11
+ export type AWSProviderOptions = {
12
+ accessKeyId?: string;
13
+ secretAccessKey?: string;
14
+ region?: string;
15
+ bucketName?: string;
16
+ };
17
+
18
+ export function AWSProvider(options?: AWSProviderOptions): Provider {
19
+ const {
20
+ accessKeyId = process.env.ES_AWS_ACCESS_KEY_ID,
21
+ secretAccessKey = process.env.ES_AWS_SECRET_ACCESS_KEY,
22
+ region = process.env.ES_AWS_REGION,
23
+ bucketName = process.env.ES_AWS_BUCKET_NAME,
24
+ } = options ?? {};
25
+
26
+ const credentials =
27
+ accessKeyId && secretAccessKey
28
+ ? {
29
+ accessKeyId,
30
+ secretAccessKey,
31
+ }
32
+ : undefined;
33
+ const s3Client = new S3Client({ region, credentials });
34
+
35
+ const baseUrl =
36
+ process.env.EDGE_STORE_BASE_URL ??
37
+ `https://${bucketName}.s3.${region}.amazonaws.com`;
38
+
39
+ return {
40
+ async init() {
41
+ return {};
42
+ },
43
+ getBaseUrl() {
44
+ return baseUrl;
45
+ },
46
+ async getFile({ url }) {
47
+ const path = url.replace(`${baseUrl}/`, '');
48
+ const { ContentLength, LastModified } = await s3Client.send(
49
+ new HeadObjectCommand({
50
+ Bucket: bucketName,
51
+ Key: path,
52
+ }),
53
+ );
54
+
55
+ if (!ContentLength || !LastModified) {
56
+ throw new Error('File not found');
57
+ }
58
+
59
+ return {
60
+ url,
61
+ metadata: {},
62
+ path: {},
63
+ size: ContentLength,
64
+ uploadedAt: LastModified,
65
+ };
66
+ },
67
+ async requestUpload({ bucketName, fileInfo }) {
68
+ const pathPrefix = `${bucketName}${fileInfo.isPublic ? '/_public' : ''}`;
69
+ const nameId = uuidv4();
70
+ const extension = fileInfo.extension
71
+ ? `.${fileInfo.extension.replace('.', '')}`
72
+ : '';
73
+ const fileName = `${nameId}${extension}`;
74
+ const filePath = fileInfo.path.reduce((acc, item) => {
75
+ return `${acc}/${item.value}`;
76
+ }, '');
77
+
78
+ const command = new PutObjectCommand({
79
+ Bucket: bucketName,
80
+ Key: `${pathPrefix}/${filePath}/${fileName}`,
81
+ });
82
+
83
+ const signedUrl = await getSignedUrl(s3Client, command, {
84
+ expiresIn: 60 * 60, // 1 hour
85
+ });
86
+
87
+ const url = `${baseUrl}/${fileInfo.path}`;
88
+ return {
89
+ uploadUrl: signedUrl,
90
+ accessUrl: url,
91
+ };
92
+ },
93
+ async requestUploadParts() {
94
+ throw new Error('Not implemented');
95
+ },
96
+ async deleteFile({ url }) {
97
+ const path = url.replace(`${baseUrl}/`, '');
98
+ await s3Client.send(
99
+ new DeleteObjectCommand({
100
+ Bucket: bucketName,
101
+ Key: path,
102
+ }),
103
+ );
104
+ return {
105
+ success: true,
106
+ };
107
+ },
108
+ };
109
+ }
@@ -0,0 +1,140 @@
1
+ import { initEdgeStoreSdk } from '../../core/sdk';
2
+ import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError';
3
+ import { Provider, RequestUploadRes } from '../types';
4
+
5
+ const DEFAULT_BASE_URL =
6
+ process.env.EDGE_STORE_BASE_URL ?? 'https://files.edge-store.com';
7
+
8
+ export type EdgeStoreProviderOptions = {
9
+ accessKey?: string;
10
+ secretKey?: string;
11
+ baseUrl?: string;
12
+ };
13
+
14
+ export function EdgeStoreProvider(
15
+ options?: EdgeStoreProviderOptions,
16
+ ): Provider {
17
+ const {
18
+ accessKey = process.env.EDGE_STORE_ACCESS_KEY,
19
+ secretKey = process.env.EDGE_STORE_SECRET_KEY,
20
+ baseUrl = process.env.EDGE_STORE_BASE_URL ?? DEFAULT_BASE_URL,
21
+ } = options ?? {};
22
+
23
+ if (!accessKey || !secretKey) {
24
+ throw new EdgeStoreCredentialsError();
25
+ }
26
+
27
+ const edgeStoreSdk = initEdgeStoreSdk({
28
+ accessKey,
29
+ secretKey,
30
+ });
31
+ return {
32
+ init: async ({ ctx, router }) => {
33
+ const token = await edgeStoreSdk.getToken({
34
+ ctx,
35
+ router,
36
+ });
37
+ return {
38
+ token,
39
+ };
40
+ },
41
+ getBaseUrl() {
42
+ return baseUrl;
43
+ },
44
+ getFile: async ({ url }) => {
45
+ const { uploadedAt, ...rest } = await edgeStoreSdk.getFile({
46
+ url,
47
+ });
48
+ return {
49
+ uploadedAt: new Date(uploadedAt),
50
+ ...rest,
51
+ };
52
+ },
53
+ async requestUpload({
54
+ bucketName,
55
+ bucketType,
56
+ fileInfo,
57
+ }): Promise<RequestUploadRes> {
58
+ // multiplart upload if file is bigger than a certain size
59
+ const MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10MB
60
+ const CONCURRENCY = 3;
61
+ let partSize = 5 * 1024 * 1024; // 5MB
62
+ if (fileInfo.size > MULTIPART_THRESHOLD) {
63
+ let totalParts = Math.ceil(fileInfo.size / partSize);
64
+ if (totalParts > 10000) {
65
+ // the maximum number of parts is 10000
66
+ totalParts = 10000;
67
+ partSize = Math.ceil(fileInfo.size / totalParts);
68
+ }
69
+ const requestParts =
70
+ totalParts > CONCURRENCY ? CONCURRENCY : totalParts;
71
+ const res = await edgeStoreSdk.requestUpload({
72
+ bucketName,
73
+ bucketType,
74
+ fileInfo,
75
+ multipart: {
76
+ parts: Array.from({ length: requestParts }).map(
77
+ (_, index) => index + 1,
78
+ ),
79
+ },
80
+ });
81
+ const multipart = res.multipart
82
+ ? {
83
+ uploadId: res.multipart.uploadId,
84
+ parts: res.multipart.parts.map((part) => ({
85
+ partNumber: part.partNumber,
86
+ uploadUrl: part.signedUrl,
87
+ })),
88
+ partSize,
89
+ totalParts,
90
+ }
91
+ : undefined;
92
+ if (multipart) {
93
+ return {
94
+ accessUrl: res.accessUrl,
95
+ multipart,
96
+ };
97
+ } else if (res.signedUrl) {
98
+ return {
99
+ accessUrl: res.accessUrl,
100
+ uploadUrl: res.signedUrl,
101
+ };
102
+ } else {
103
+ throw new Error('Could not get upload url');
104
+ }
105
+ }
106
+ const res = await edgeStoreSdk.requestUpload({
107
+ bucketName,
108
+ bucketType,
109
+ fileInfo,
110
+ });
111
+ if (res.signedUrl) {
112
+ return {
113
+ accessUrl: res.accessUrl,
114
+ uploadUrl: res.signedUrl,
115
+ };
116
+ }
117
+ throw new Error('Could not get upload url');
118
+ },
119
+ requestUploadParts: async ({ multipart, path }) => {
120
+ const res = await edgeStoreSdk.requestUploadParts({
121
+ multipart,
122
+ key: path,
123
+ });
124
+ return {
125
+ multipart: {
126
+ uploadId: res.multipart.uploadId,
127
+ parts: res.multipart.parts.map((part) => ({
128
+ partNumber: part.partNumber,
129
+ uploadUrl: part.signedUrl,
130
+ })),
131
+ },
132
+ };
133
+ },
134
+ deleteFile: async ({ url }) => {
135
+ return await edgeStoreSdk.deleteFile({
136
+ url,
137
+ });
138
+ },
139
+ };
140
+ }
@@ -0,0 +1,2 @@
1
+ export * from './aws';
2
+ export * from './edgestore';