@edgestore/server 1.0.0-next.0 → 1.0.0-next.2
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/README.md +11 -5
- package/dist/adapters/astro/index.d.ts +7 -12
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +14 -161
- package/dist/adapters/dispatcher.d.ts +30 -0
- package/dist/adapters/dispatcher.d.ts.map +1 -0
- package/dist/adapters/dispatcher.js +172 -0
- package/dist/adapters/express/index.d.ts +7 -12
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +24 -94
- package/dist/adapters/fastify/index.d.ts +7 -12
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +23 -121
- package/dist/adapters/hono/index.d.ts +7 -12
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +14 -121
- package/dist/adapters/next/app/index.d.ts +7 -12
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +21 -148
- package/dist/adapters/next/pages/index.d.ts +7 -12
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +34 -95
- package/dist/adapters/remix/index.d.ts +7 -12
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +14 -136
- package/dist/adapters/shared.d.ts +140 -55
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +188 -179
- package/dist/adapters/start/index.d.ts +7 -12
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +14 -169
- package/dist/core/client/bucketClient.d.ts +7 -0
- package/dist/core/client/bucketClient.d.ts.map +1 -0
- package/dist/core/client/bucketClient.js +312 -0
- package/dist/core/client/index.d.ts +120 -142
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +13 -218
- package/dist/core/index.d.ts +20 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -2
- package/dist/core/provider.d.ts +15 -0
- package/dist/core/provider.d.ts.map +1 -0
- package/dist/core/provider.js +25 -0
- package/dist/core/routerRules.d.ts +20 -0
- package/dist/core/routerRules.d.ts.map +1 -0
- package/dist/core/routerRules.js +42 -0
- package/dist/core/validateFile.d.ts +9 -0
- package/dist/core/validateFile.d.ts.map +1 -0
- package/dist/core/validateFile.js +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/libs/env.d.ts +3 -0
- package/dist/libs/env.d.ts.map +1 -0
- package/dist/libs/env.js +14 -0
- package/dist/libs/logger.d.ts +2 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/libs/logger.js +1 -1
- package/dist/providers/azure-blob/index.d.ts +119 -0
- package/dist/providers/azure-blob/index.d.ts.map +1 -0
- package/dist/providers/azure-blob/index.js +166 -0
- package/dist/providers/edgestore/index.d.ts +171 -3
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +304 -136
- package/dist/providers/{aws → s3}/index.d.ts +68 -11
- package/dist/providers/s3/index.d.ts.map +1 -0
- package/dist/providers/s3/index.js +146 -0
- package/dist/test-utils/edgestoreSmoke.d.ts +0 -2
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +17 -20
- package/providers/azure-blob/index.d.ts +1 -0
- package/providers/azure-blob/index.js +1 -0
- package/providers/s3/index.d.ts +1 -0
- package/providers/s3/index.js +1 -0
- package/src/adapters/astro/index.ts +27 -211
- package/src/adapters/dispatcher.ts +261 -0
- package/src/adapters/express/index.ts +43 -149
- package/src/adapters/fastify/index.ts +43 -191
- package/src/adapters/hono/index.ts +28 -183
- package/src/adapters/next/app/index.ts +37 -201
- package/src/adapters/next/pages/index.ts +55 -156
- package/src/adapters/remix/index.ts +27 -190
- package/src/adapters/shared.ts +237 -261
- package/src/adapters/start/index.ts +28 -200
- package/src/core/client/bucketClient.ts +476 -0
- package/src/core/client/index.ts +301 -428
- package/src/core/index.ts +42 -1
- package/src/core/provider.ts +80 -0
- package/src/core/routerRules.ts +63 -0
- package/src/core/validateFile.ts +50 -0
- package/src/index.ts +10 -0
- package/src/libs/env.ts +16 -0
- package/src/libs/logger.ts +4 -2
- package/src/providers/azure-blob/index.ts +265 -0
- package/src/providers/edgestore/index.ts +426 -154
- package/src/providers/s3/index.ts +289 -0
- package/src/test-utils/edgestoreSmoke.ts +0 -11
- package/src/version.ts +1 -1
- package/dist/core/sdk/index.d.ts +0 -282
- package/dist/core/sdk/index.d.ts.map +0 -1
- package/dist/core/sdk/index.js +0 -253
- package/dist/providers/aws/index.d.ts.map +0 -1
- package/dist/providers/aws/index.js +0 -102
- package/dist/providers/azure/index.d.ts +0 -39
- package/dist/providers/azure/index.d.ts.map +0 -1
- package/dist/providers/azure/index.js +0 -84
- package/dist/version.js +0 -4
- package/providers/aws/index.d.ts +0 -1
- package/providers/aws/index.js +0 -1
- package/providers/azure/index.d.ts +0 -1
- package/providers/azure/index.js +0 -1
- package/src/core/sdk/index.ts +0 -542
- package/src/providers/aws/index.ts +0 -239
- package/src/providers/azure/index.ts +0 -141
package/src/core/sdk/index.ts
DELETED
|
@@ -1,542 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EdgeStoreError,
|
|
3
|
-
type AnyContext,
|
|
4
|
-
type AnyMetadata,
|
|
5
|
-
type AnyRouter,
|
|
6
|
-
} from '@edgestore/shared';
|
|
7
|
-
import { getEnv } from '../../adapters/shared';
|
|
8
|
-
import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError';
|
|
9
|
-
import {
|
|
10
|
-
EDGE_STORE_PACKAGE_NAME,
|
|
11
|
-
EDGE_STORE_PACKAGE_VERSION,
|
|
12
|
-
} from '../../version';
|
|
13
|
-
|
|
14
|
-
const API_ENDPOINT =
|
|
15
|
-
getEnv('EDGE_STORE_API_ENDPOINT') ?? 'https://api.edgestore.dev';
|
|
16
|
-
|
|
17
|
-
type FileInfoForUpload = {
|
|
18
|
-
size: number;
|
|
19
|
-
extension: string;
|
|
20
|
-
type?: string;
|
|
21
|
-
isPublic: boolean;
|
|
22
|
-
path: {
|
|
23
|
-
key: string;
|
|
24
|
-
value: string;
|
|
25
|
-
}[];
|
|
26
|
-
metadata: AnyMetadata;
|
|
27
|
-
fileName?: string;
|
|
28
|
-
replaceTargetUrl?: string;
|
|
29
|
-
temporary: boolean;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type AutoSignedUrlsForUpload = {
|
|
33
|
-
expiresIn?: number;
|
|
34
|
-
includeThumbnails?: boolean;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type SimpleOperator =
|
|
38
|
-
'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'startsWith' | 'endsWith';
|
|
39
|
-
|
|
40
|
-
export type Comparison<TType = string> =
|
|
41
|
-
| TType
|
|
42
|
-
| Partial<
|
|
43
|
-
{
|
|
44
|
-
[K in SimpleOperator]: TType;
|
|
45
|
-
} & {
|
|
46
|
-
between: [TType, TType];
|
|
47
|
-
}
|
|
48
|
-
>;
|
|
49
|
-
|
|
50
|
-
type ListFilesFilter = {
|
|
51
|
-
AND?: ListFilesFilter[];
|
|
52
|
-
OR?: ListFilesFilter[];
|
|
53
|
-
uploadedAt?: Comparison<Date>;
|
|
54
|
-
path?: Partial<{
|
|
55
|
-
[key: string]: Comparison;
|
|
56
|
-
}>;
|
|
57
|
-
metadata?: Partial<{
|
|
58
|
-
[key: string]: Comparison;
|
|
59
|
-
}>;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
type Pagination = {
|
|
63
|
-
currentPage: number;
|
|
64
|
-
pageSize: number;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
async function makeRequest<TOutput>(params: {
|
|
68
|
-
body: object;
|
|
69
|
-
accessKey: string;
|
|
70
|
-
secretKey: string;
|
|
71
|
-
path: string;
|
|
72
|
-
}) {
|
|
73
|
-
const { body, accessKey, secretKey, path } = params;
|
|
74
|
-
const res = await fetch(`${API_ENDPOINT}${path}`, {
|
|
75
|
-
method: 'POST',
|
|
76
|
-
body: JSON.stringify(body),
|
|
77
|
-
headers: {
|
|
78
|
-
'Content-Type': 'application/json',
|
|
79
|
-
Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString(
|
|
80
|
-
'base64',
|
|
81
|
-
)}`,
|
|
82
|
-
'x-edgestore-package-name': EDGE_STORE_PACKAGE_NAME,
|
|
83
|
-
'x-edgestore-package-version': EDGE_STORE_PACKAGE_VERSION,
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
if (!res.ok) {
|
|
87
|
-
throw new Error(`Failed to make request to ${path}: ${await res.text()}`);
|
|
88
|
-
}
|
|
89
|
-
return (await res.json()) as TOutput;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const edgeStoreRawSdk = {
|
|
93
|
-
async getToken(params: {
|
|
94
|
-
accessKey: string;
|
|
95
|
-
secretKey: string;
|
|
96
|
-
ctx: AnyContext;
|
|
97
|
-
router: AnyRouter;
|
|
98
|
-
}) {
|
|
99
|
-
const reqBuckets = Object.entries(params.router.buckets).reduce(
|
|
100
|
-
(acc, [bucketName, bucket]) => {
|
|
101
|
-
acc[bucketName] = {
|
|
102
|
-
path: bucket._def.path.map((p: { [key: string]: () => string }) => {
|
|
103
|
-
const paramEntries = Object.entries(p);
|
|
104
|
-
if (paramEntries[0] === undefined) {
|
|
105
|
-
throw new EdgeStoreError({
|
|
106
|
-
message: `Empty path param found in: ${JSON.stringify(
|
|
107
|
-
bucket._def.path,
|
|
108
|
-
)}`,
|
|
109
|
-
code: 'SERVER_ERROR',
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const [key, value] = paramEntries[0];
|
|
113
|
-
return {
|
|
114
|
-
key,
|
|
115
|
-
value: value(),
|
|
116
|
-
};
|
|
117
|
-
}),
|
|
118
|
-
accessControl: bucket._def.accessControl,
|
|
119
|
-
};
|
|
120
|
-
return acc;
|
|
121
|
-
},
|
|
122
|
-
{} as any,
|
|
123
|
-
);
|
|
124
|
-
const { token } = await makeRequest<{ token: string }>({
|
|
125
|
-
body: {
|
|
126
|
-
ctx: params.ctx,
|
|
127
|
-
buckets: reqBuckets,
|
|
128
|
-
},
|
|
129
|
-
accessKey: params.accessKey,
|
|
130
|
-
secretKey: params.secretKey,
|
|
131
|
-
path: '/get-token',
|
|
132
|
-
});
|
|
133
|
-
return token;
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
async getFile({
|
|
137
|
-
accessKey,
|
|
138
|
-
secretKey,
|
|
139
|
-
url,
|
|
140
|
-
}: {
|
|
141
|
-
accessKey: string;
|
|
142
|
-
secretKey: string;
|
|
143
|
-
url: string;
|
|
144
|
-
}) {
|
|
145
|
-
return await makeRequest<{
|
|
146
|
-
url: string;
|
|
147
|
-
size: number;
|
|
148
|
-
uploadedAt: string;
|
|
149
|
-
path: Record<string, string>;
|
|
150
|
-
metadata: Record<string, string>;
|
|
151
|
-
}>({
|
|
152
|
-
path: '/get-file',
|
|
153
|
-
accessKey,
|
|
154
|
-
secretKey,
|
|
155
|
-
body: {
|
|
156
|
-
url,
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
async requestUpload({
|
|
162
|
-
accessKey,
|
|
163
|
-
secretKey,
|
|
164
|
-
bucketName,
|
|
165
|
-
bucketType,
|
|
166
|
-
fileInfo,
|
|
167
|
-
multipart,
|
|
168
|
-
autoSignedUrls,
|
|
169
|
-
}: {
|
|
170
|
-
accessKey: string;
|
|
171
|
-
secretKey: string;
|
|
172
|
-
bucketName: string;
|
|
173
|
-
bucketType: string;
|
|
174
|
-
fileInfo: FileInfoForUpload;
|
|
175
|
-
autoSignedUrls?: AutoSignedUrlsForUpload;
|
|
176
|
-
multipart?: {
|
|
177
|
-
parts: number[];
|
|
178
|
-
};
|
|
179
|
-
}) {
|
|
180
|
-
const res = await makeRequest<{
|
|
181
|
-
multipart?: {
|
|
182
|
-
key: string;
|
|
183
|
-
uploadId: string;
|
|
184
|
-
parts: {
|
|
185
|
-
partNumber: number;
|
|
186
|
-
signedUrl: string;
|
|
187
|
-
}[];
|
|
188
|
-
};
|
|
189
|
-
signedUrl?: string;
|
|
190
|
-
url: string;
|
|
191
|
-
path: string;
|
|
192
|
-
thumbnailUrl: string | null;
|
|
193
|
-
accessSignedUrl?: string;
|
|
194
|
-
accessSignedThumbnailUrl?: string | null;
|
|
195
|
-
accessSignedUrlExpiresAt?: string;
|
|
196
|
-
accessSignedUrlExpiresIn?: number;
|
|
197
|
-
}>({
|
|
198
|
-
path: '/request-upload',
|
|
199
|
-
accessKey,
|
|
200
|
-
secretKey,
|
|
201
|
-
body: {
|
|
202
|
-
multipart,
|
|
203
|
-
bucketName,
|
|
204
|
-
bucketType,
|
|
205
|
-
isPublic: fileInfo.isPublic,
|
|
206
|
-
path: fileInfo.path,
|
|
207
|
-
extension: fileInfo.extension,
|
|
208
|
-
size: fileInfo.size,
|
|
209
|
-
mimeType: fileInfo.type,
|
|
210
|
-
metadata: fileInfo.metadata,
|
|
211
|
-
fileName: fileInfo.fileName,
|
|
212
|
-
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
213
|
-
isTemporary: fileInfo.temporary,
|
|
214
|
-
autoSignedUrls,
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
return {
|
|
218
|
-
multipart: res.multipart,
|
|
219
|
-
signedUrl: res.signedUrl,
|
|
220
|
-
accessUrl: res.url,
|
|
221
|
-
path: res.path,
|
|
222
|
-
thumbnailUrl: res.thumbnailUrl,
|
|
223
|
-
accessSignedUrl: res.accessSignedUrl,
|
|
224
|
-
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
225
|
-
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt,
|
|
226
|
-
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn,
|
|
227
|
-
};
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
async getSignedUrls({
|
|
231
|
-
accessKey,
|
|
232
|
-
secretKey,
|
|
233
|
-
bucketName,
|
|
234
|
-
urls,
|
|
235
|
-
expiresIn,
|
|
236
|
-
includeThumbnails,
|
|
237
|
-
}: {
|
|
238
|
-
accessKey: string;
|
|
239
|
-
secretKey: string;
|
|
240
|
-
bucketName: string;
|
|
241
|
-
urls: string[];
|
|
242
|
-
expiresIn?: number;
|
|
243
|
-
includeThumbnails?: boolean;
|
|
244
|
-
}) {
|
|
245
|
-
const res = await makeRequest<{
|
|
246
|
-
signedUrls: {
|
|
247
|
-
url: string;
|
|
248
|
-
signedUrl: string;
|
|
249
|
-
expiresAt: string;
|
|
250
|
-
expiresIn: number;
|
|
251
|
-
thumbnailUrl?: string | null;
|
|
252
|
-
signedThumbnailUrl?: string | null;
|
|
253
|
-
}[];
|
|
254
|
-
}>({
|
|
255
|
-
path: '/get-signed-urls',
|
|
256
|
-
accessKey,
|
|
257
|
-
secretKey,
|
|
258
|
-
body: {
|
|
259
|
-
bucketName,
|
|
260
|
-
urls,
|
|
261
|
-
expiresIn,
|
|
262
|
-
includeThumbnails,
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
return res.signedUrls;
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
async requestUploadParts({
|
|
269
|
-
accessKey,
|
|
270
|
-
secretKey,
|
|
271
|
-
key,
|
|
272
|
-
multipart,
|
|
273
|
-
}: {
|
|
274
|
-
accessKey: string;
|
|
275
|
-
secretKey: string;
|
|
276
|
-
key: string;
|
|
277
|
-
multipart: {
|
|
278
|
-
uploadId?: string;
|
|
279
|
-
parts: number[];
|
|
280
|
-
};
|
|
281
|
-
}) {
|
|
282
|
-
const res = await makeRequest<{
|
|
283
|
-
multipart: {
|
|
284
|
-
uploadId: string;
|
|
285
|
-
parts: {
|
|
286
|
-
partNumber: number;
|
|
287
|
-
signedUrl: string;
|
|
288
|
-
}[];
|
|
289
|
-
};
|
|
290
|
-
}>({
|
|
291
|
-
path: '/request-upload-parts',
|
|
292
|
-
accessKey,
|
|
293
|
-
secretKey,
|
|
294
|
-
body: {
|
|
295
|
-
multipart,
|
|
296
|
-
key,
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
return {
|
|
300
|
-
multipart: res.multipart,
|
|
301
|
-
};
|
|
302
|
-
},
|
|
303
|
-
|
|
304
|
-
async completeMultipartUpload({
|
|
305
|
-
accessKey,
|
|
306
|
-
secretKey,
|
|
307
|
-
uploadId,
|
|
308
|
-
key,
|
|
309
|
-
parts,
|
|
310
|
-
}: {
|
|
311
|
-
accessKey: string;
|
|
312
|
-
secretKey: string;
|
|
313
|
-
uploadId: string;
|
|
314
|
-
key: string;
|
|
315
|
-
parts: {
|
|
316
|
-
partNumber: number;
|
|
317
|
-
eTag: string;
|
|
318
|
-
}[];
|
|
319
|
-
}) {
|
|
320
|
-
return await makeRequest<{ success: boolean }>({
|
|
321
|
-
path: '/complete-multipart-upload',
|
|
322
|
-
accessKey,
|
|
323
|
-
secretKey,
|
|
324
|
-
body: {
|
|
325
|
-
uploadId,
|
|
326
|
-
key,
|
|
327
|
-
parts,
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
async confirmUpload({
|
|
333
|
-
accessKey,
|
|
334
|
-
secretKey,
|
|
335
|
-
url,
|
|
336
|
-
}: {
|
|
337
|
-
accessKey: string;
|
|
338
|
-
secretKey: string;
|
|
339
|
-
url: string;
|
|
340
|
-
}) {
|
|
341
|
-
return await makeRequest<{ success: boolean }>({
|
|
342
|
-
path: '/confirm-upload',
|
|
343
|
-
accessKey,
|
|
344
|
-
secretKey,
|
|
345
|
-
body: {
|
|
346
|
-
url,
|
|
347
|
-
},
|
|
348
|
-
});
|
|
349
|
-
},
|
|
350
|
-
|
|
351
|
-
async deleteFile({
|
|
352
|
-
accessKey,
|
|
353
|
-
secretKey,
|
|
354
|
-
url,
|
|
355
|
-
}: {
|
|
356
|
-
accessKey: string;
|
|
357
|
-
secretKey: string;
|
|
358
|
-
url: string;
|
|
359
|
-
}) {
|
|
360
|
-
return await makeRequest<{ success: boolean }>({
|
|
361
|
-
path: '/delete-file',
|
|
362
|
-
accessKey,
|
|
363
|
-
secretKey,
|
|
364
|
-
body: {
|
|
365
|
-
url,
|
|
366
|
-
},
|
|
367
|
-
});
|
|
368
|
-
},
|
|
369
|
-
|
|
370
|
-
async listFiles({
|
|
371
|
-
accessKey,
|
|
372
|
-
secretKey,
|
|
373
|
-
bucketName,
|
|
374
|
-
filter,
|
|
375
|
-
pagination,
|
|
376
|
-
}: {
|
|
377
|
-
accessKey: string;
|
|
378
|
-
secretKey: string;
|
|
379
|
-
bucketName: string;
|
|
380
|
-
filter?: ListFilesFilter;
|
|
381
|
-
pagination?: Pagination;
|
|
382
|
-
}) {
|
|
383
|
-
return await makeRequest<{
|
|
384
|
-
data: {
|
|
385
|
-
url: string;
|
|
386
|
-
thumbnailUrl: string | null;
|
|
387
|
-
size: number;
|
|
388
|
-
uploadedAt: string;
|
|
389
|
-
path: Record<string, string>;
|
|
390
|
-
metadata: Record<string, string>;
|
|
391
|
-
}[];
|
|
392
|
-
pagination: {
|
|
393
|
-
currentPage: number;
|
|
394
|
-
pageSize: number;
|
|
395
|
-
totalPages: number;
|
|
396
|
-
totalCount: number;
|
|
397
|
-
};
|
|
398
|
-
}>({
|
|
399
|
-
path: '/list-files',
|
|
400
|
-
accessKey,
|
|
401
|
-
secretKey,
|
|
402
|
-
body: {
|
|
403
|
-
bucketName,
|
|
404
|
-
filter,
|
|
405
|
-
pagination,
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
},
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
export function initEdgeStoreSdk(params: {
|
|
412
|
-
accessKey?: string;
|
|
413
|
-
secretKey?: string;
|
|
414
|
-
}) {
|
|
415
|
-
const {
|
|
416
|
-
accessKey = getEnv('EDGE_STORE_ACCESS_KEY'),
|
|
417
|
-
secretKey = getEnv('EDGE_STORE_SECRET_KEY'),
|
|
418
|
-
} = params ?? {};
|
|
419
|
-
|
|
420
|
-
if (!accessKey || !secretKey) {
|
|
421
|
-
throw new EdgeStoreCredentialsError();
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return {
|
|
425
|
-
async getToken(params: { ctx: AnyContext; router: AnyRouter }) {
|
|
426
|
-
return await edgeStoreRawSdk.getToken({
|
|
427
|
-
accessKey,
|
|
428
|
-
secretKey,
|
|
429
|
-
ctx: params.ctx,
|
|
430
|
-
router: params.router,
|
|
431
|
-
});
|
|
432
|
-
},
|
|
433
|
-
async getFile({ url }: { url: string }) {
|
|
434
|
-
return await edgeStoreRawSdk.getFile({
|
|
435
|
-
accessKey,
|
|
436
|
-
secretKey,
|
|
437
|
-
url,
|
|
438
|
-
});
|
|
439
|
-
},
|
|
440
|
-
async requestUpload({
|
|
441
|
-
bucketName,
|
|
442
|
-
bucketType,
|
|
443
|
-
fileInfo,
|
|
444
|
-
multipart,
|
|
445
|
-
autoSignedUrls,
|
|
446
|
-
}: {
|
|
447
|
-
bucketName: string;
|
|
448
|
-
bucketType: string;
|
|
449
|
-
fileInfo: FileInfoForUpload;
|
|
450
|
-
autoSignedUrls?: AutoSignedUrlsForUpload;
|
|
451
|
-
multipart?: {
|
|
452
|
-
parts: number[];
|
|
453
|
-
};
|
|
454
|
-
}) {
|
|
455
|
-
return await edgeStoreRawSdk.requestUpload({
|
|
456
|
-
accessKey,
|
|
457
|
-
secretKey,
|
|
458
|
-
bucketName,
|
|
459
|
-
bucketType,
|
|
460
|
-
fileInfo,
|
|
461
|
-
multipart,
|
|
462
|
-
autoSignedUrls,
|
|
463
|
-
});
|
|
464
|
-
},
|
|
465
|
-
async getSignedUrls(params: {
|
|
466
|
-
bucketName: string;
|
|
467
|
-
urls: string[];
|
|
468
|
-
expiresIn?: number;
|
|
469
|
-
includeThumbnails?: boolean;
|
|
470
|
-
}) {
|
|
471
|
-
return await edgeStoreRawSdk.getSignedUrls({
|
|
472
|
-
accessKey,
|
|
473
|
-
secretKey,
|
|
474
|
-
...params,
|
|
475
|
-
});
|
|
476
|
-
},
|
|
477
|
-
async requestUploadParts({
|
|
478
|
-
key,
|
|
479
|
-
multipart,
|
|
480
|
-
}: {
|
|
481
|
-
key: string;
|
|
482
|
-
multipart: {
|
|
483
|
-
uploadId?: string;
|
|
484
|
-
parts: number[];
|
|
485
|
-
};
|
|
486
|
-
}) {
|
|
487
|
-
return await edgeStoreRawSdk.requestUploadParts({
|
|
488
|
-
accessKey,
|
|
489
|
-
secretKey,
|
|
490
|
-
key,
|
|
491
|
-
multipart,
|
|
492
|
-
});
|
|
493
|
-
},
|
|
494
|
-
async completeMultipartUpload({
|
|
495
|
-
uploadId,
|
|
496
|
-
key,
|
|
497
|
-
parts,
|
|
498
|
-
}: {
|
|
499
|
-
uploadId: string;
|
|
500
|
-
key: string;
|
|
501
|
-
parts: {
|
|
502
|
-
partNumber: number;
|
|
503
|
-
eTag: string;
|
|
504
|
-
}[];
|
|
505
|
-
}) {
|
|
506
|
-
return await edgeStoreRawSdk.completeMultipartUpload({
|
|
507
|
-
accessKey,
|
|
508
|
-
secretKey,
|
|
509
|
-
uploadId,
|
|
510
|
-
key,
|
|
511
|
-
parts,
|
|
512
|
-
});
|
|
513
|
-
},
|
|
514
|
-
async confirmUpload({ url }: { url: string }) {
|
|
515
|
-
return await edgeStoreRawSdk.confirmUpload({
|
|
516
|
-
accessKey,
|
|
517
|
-
secretKey,
|
|
518
|
-
url,
|
|
519
|
-
});
|
|
520
|
-
},
|
|
521
|
-
async deleteFile({ url }: { url: string }) {
|
|
522
|
-
return await edgeStoreRawSdk.deleteFile({
|
|
523
|
-
accessKey,
|
|
524
|
-
secretKey,
|
|
525
|
-
url,
|
|
526
|
-
});
|
|
527
|
-
},
|
|
528
|
-
async listFiles(params: {
|
|
529
|
-
bucketName: string;
|
|
530
|
-
filter?: ListFilesFilter;
|
|
531
|
-
pagination?: Pagination;
|
|
532
|
-
}) {
|
|
533
|
-
return await edgeStoreRawSdk.listFiles({
|
|
534
|
-
accessKey,
|
|
535
|
-
secretKey,
|
|
536
|
-
...params,
|
|
537
|
-
});
|
|
538
|
-
},
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
export type EdgeStoreSdk = ReturnType<typeof initEdgeStoreSdk>;
|