@edgestore/server 0.8.0 → 1.0.0-next.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/README.md +10 -4
- package/adapters/astro/index.d.ts +1 -1
- package/adapters/astro/index.js +1 -1
- package/adapters/express/index.d.ts +1 -1
- package/adapters/express/index.js +1 -1
- package/adapters/fastify/index.d.ts +1 -1
- package/adapters/fastify/index.js +1 -1
- package/adapters/hono/index.d.ts +1 -1
- package/adapters/hono/index.js +1 -1
- package/adapters/next/app/index.d.ts +1 -1
- package/adapters/next/app/index.js +1 -1
- package/adapters/next/pages/index.d.ts +1 -1
- package/adapters/next/pages/index.js +1 -1
- package/adapters/remix/index.d.ts +1 -1
- package/adapters/remix/index.js +1 -1
- package/adapters/start/index.d.ts +1 -1
- package/adapters/start/index.js +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +1 -1
- package/dist/adapters/astro/index.d.ts +8 -13
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +17 -166
- 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 +8 -13
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +27 -99
- package/dist/adapters/fastify/index.d.ts +8 -13
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +26 -126
- package/dist/adapters/hono/index.d.ts +8 -13
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +17 -126
- package/dist/adapters/imageTypes.js +1 -3
- package/dist/adapters/next/app/index.d.ts +8 -13
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +24 -153
- package/dist/adapters/next/pages/index.d.ts +8 -13
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +37 -100
- package/dist/adapters/remix/index.d.ts +8 -13
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +17 -141
- package/dist/adapters/shared.d.ts +140 -55
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +218 -215
- package/dist/adapters/start/index.d.ts +8 -13
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +17 -174
- 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 +119 -140
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +13 -220
- package/dist/core/index.d.ts +21 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -10
- 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 +21 -0
- package/dist/core/routerRules.d.ts.map +1 -0
- package/dist/core/routerRules.js +54 -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 +4 -10
- 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/errors/EdgeStoreCredentialsError.js +1 -3
- package/dist/libs/logger.d.ts +2 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/libs/logger.js +5 -9
- package/dist/libs/utils.js +1 -3
- 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 +307 -141
- 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/dist/version.d.ts.map +1 -1
- package/package.json +58 -56
- package/providers/azure-blob/index.d.ts +1 -0
- package/providers/azure-blob/index.js +1 -0
- package/providers/edgestore/index.d.ts +1 -1
- package/providers/edgestore/index.js +1 -1
- 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 +249 -274
- package/src/adapters/start/index.ts +28 -200
- package/src/core/client/bucketClient.ts +480 -0
- package/src/core/client/index.ts +300 -428
- package/src/core/index.ts +42 -1
- package/src/core/provider.ts +80 -0
- package/src/core/routerRules.ts +75 -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/adapters/astro/index.mjs +0 -172
- package/dist/adapters/express/index.mjs +0 -108
- package/dist/adapters/fastify/index.mjs +0 -135
- package/dist/adapters/hono/index.mjs +0 -131
- package/dist/adapters/imageTypes.mjs +0 -12
- package/dist/adapters/next/app/index.mjs +0 -163
- package/dist/adapters/next/pages/index.mjs +0 -112
- package/dist/adapters/remix/index.mjs +0 -148
- package/dist/adapters/shared.mjs +0 -471
- package/dist/adapters/start/index.mjs +0 -181
- package/dist/core/client/index.mjs +0 -221
- package/dist/core/index.mjs +0 -2
- 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 -256
- package/dist/core/sdk/index.mjs +0 -253
- package/dist/index.mjs +0 -1
- package/dist/libs/errors/EdgeStoreCredentialsError.mjs +0 -10
- package/dist/libs/logger.mjs +0 -53
- package/dist/libs/utils.mjs +0 -10
- package/dist/providers/aws/index.d.ts.map +0 -1
- package/dist/providers/aws/index.js +0 -105
- package/dist/providers/aws/index.mjs +0 -103
- 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 -87
- package/dist/providers/azure/index.mjs +0 -85
- package/dist/providers/edgestore/index.mjs +0 -164
- package/dist/version.js +0 -7
- package/dist/version.mjs +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 -549
- package/src/providers/aws/index.ts +0 -240
- package/src/providers/azure/index.ts +0 -142
package/dist/core/sdk/index.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var shared$1 = require('@edgestore/shared');
|
|
4
|
-
var shared = require('../../adapters/shared.js');
|
|
5
|
-
var EdgeStoreCredentialsError = require('../../libs/errors/EdgeStoreCredentialsError.js');
|
|
6
|
-
var version = require('../../version.js');
|
|
7
|
-
|
|
8
|
-
const API_ENDPOINT = shared.getEnv('EDGE_STORE_API_ENDPOINT') ?? 'https://api.edgestore.dev';
|
|
9
|
-
async function makeRequest(params) {
|
|
10
|
-
const { body, accessKey, secretKey, path } = params;
|
|
11
|
-
const res = await fetch(`${API_ENDPOINT}${path}`, {
|
|
12
|
-
method: 'POST',
|
|
13
|
-
body: JSON.stringify(body),
|
|
14
|
-
headers: {
|
|
15
|
-
'Content-Type': 'application/json',
|
|
16
|
-
Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}`,
|
|
17
|
-
'x-edgestore-package-name': version.EDGE_STORE_PACKAGE_NAME,
|
|
18
|
-
'x-edgestore-package-version': version.EDGE_STORE_PACKAGE_VERSION
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
if (!res.ok) {
|
|
22
|
-
throw new Error(`Failed to make request to ${path}: ${await res.text()}`);
|
|
23
|
-
}
|
|
24
|
-
return await res.json();
|
|
25
|
-
}
|
|
26
|
-
const edgeStoreRawSdk = {
|
|
27
|
-
async getToken (params) {
|
|
28
|
-
const reqBuckets = Object.entries(params.router.buckets).reduce((acc, [bucketName, bucket])=>{
|
|
29
|
-
acc[bucketName] = {
|
|
30
|
-
path: bucket._def.path.map((p)=>{
|
|
31
|
-
const paramEntries = Object.entries(p);
|
|
32
|
-
if (paramEntries[0] === undefined) {
|
|
33
|
-
throw new shared$1.EdgeStoreError({
|
|
34
|
-
message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
|
|
35
|
-
code: 'SERVER_ERROR'
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
const [key, value] = paramEntries[0];
|
|
39
|
-
return {
|
|
40
|
-
key,
|
|
41
|
-
value: value()
|
|
42
|
-
};
|
|
43
|
-
}),
|
|
44
|
-
accessControl: bucket._def.accessControl
|
|
45
|
-
};
|
|
46
|
-
return acc;
|
|
47
|
-
}, {});
|
|
48
|
-
const { token } = await makeRequest({
|
|
49
|
-
body: {
|
|
50
|
-
ctx: params.ctx,
|
|
51
|
-
buckets: reqBuckets
|
|
52
|
-
},
|
|
53
|
-
accessKey: params.accessKey,
|
|
54
|
-
secretKey: params.secretKey,
|
|
55
|
-
path: '/get-token'
|
|
56
|
-
});
|
|
57
|
-
return token;
|
|
58
|
-
},
|
|
59
|
-
async getFile ({ accessKey, secretKey, url }) {
|
|
60
|
-
return await makeRequest({
|
|
61
|
-
path: '/get-file',
|
|
62
|
-
accessKey,
|
|
63
|
-
secretKey,
|
|
64
|
-
body: {
|
|
65
|
-
url
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
},
|
|
69
|
-
async requestUpload ({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
|
|
70
|
-
const res = await makeRequest({
|
|
71
|
-
path: '/request-upload',
|
|
72
|
-
accessKey,
|
|
73
|
-
secretKey,
|
|
74
|
-
body: {
|
|
75
|
-
multipart,
|
|
76
|
-
bucketName,
|
|
77
|
-
bucketType,
|
|
78
|
-
isPublic: fileInfo.isPublic,
|
|
79
|
-
path: fileInfo.path,
|
|
80
|
-
extension: fileInfo.extension,
|
|
81
|
-
size: fileInfo.size,
|
|
82
|
-
mimeType: fileInfo.type,
|
|
83
|
-
metadata: fileInfo.metadata,
|
|
84
|
-
fileName: fileInfo.fileName,
|
|
85
|
-
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
86
|
-
isTemporary: fileInfo.temporary,
|
|
87
|
-
autoSignedUrls
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
multipart: res.multipart,
|
|
92
|
-
signedUrl: res.signedUrl,
|
|
93
|
-
accessUrl: res.url,
|
|
94
|
-
path: res.path,
|
|
95
|
-
thumbnailUrl: res.thumbnailUrl,
|
|
96
|
-
accessSignedUrl: res.accessSignedUrl,
|
|
97
|
-
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
98
|
-
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt,
|
|
99
|
-
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
async getSignedUrls ({ accessKey, secretKey, bucketName, urls, expiresIn, includeThumbnails }) {
|
|
103
|
-
const res = await makeRequest({
|
|
104
|
-
path: '/get-signed-urls',
|
|
105
|
-
accessKey,
|
|
106
|
-
secretKey,
|
|
107
|
-
body: {
|
|
108
|
-
bucketName,
|
|
109
|
-
urls,
|
|
110
|
-
expiresIn,
|
|
111
|
-
includeThumbnails
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return res.signedUrls;
|
|
115
|
-
},
|
|
116
|
-
async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
|
|
117
|
-
const res = await makeRequest({
|
|
118
|
-
path: '/request-upload-parts',
|
|
119
|
-
accessKey,
|
|
120
|
-
secretKey,
|
|
121
|
-
body: {
|
|
122
|
-
multipart,
|
|
123
|
-
key
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return {
|
|
127
|
-
multipart: res.multipart
|
|
128
|
-
};
|
|
129
|
-
},
|
|
130
|
-
async completeMultipartUpload ({ accessKey, secretKey, uploadId, key, parts }) {
|
|
131
|
-
return await makeRequest({
|
|
132
|
-
path: '/complete-multipart-upload',
|
|
133
|
-
accessKey,
|
|
134
|
-
secretKey,
|
|
135
|
-
body: {
|
|
136
|
-
uploadId,
|
|
137
|
-
key,
|
|
138
|
-
parts
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
|
-
async confirmUpload ({ accessKey, secretKey, url }) {
|
|
143
|
-
return await makeRequest({
|
|
144
|
-
path: '/confirm-upload',
|
|
145
|
-
accessKey,
|
|
146
|
-
secretKey,
|
|
147
|
-
body: {
|
|
148
|
-
url
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
},
|
|
152
|
-
async deleteFile ({ accessKey, secretKey, url }) {
|
|
153
|
-
return await makeRequest({
|
|
154
|
-
path: '/delete-file',
|
|
155
|
-
accessKey,
|
|
156
|
-
secretKey,
|
|
157
|
-
body: {
|
|
158
|
-
url
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
async listFiles ({ accessKey, secretKey, bucketName, filter, pagination }) {
|
|
163
|
-
return await makeRequest({
|
|
164
|
-
path: '/list-files',
|
|
165
|
-
accessKey,
|
|
166
|
-
secretKey,
|
|
167
|
-
body: {
|
|
168
|
-
bucketName,
|
|
169
|
-
filter,
|
|
170
|
-
pagination
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
function initEdgeStoreSdk(params) {
|
|
176
|
-
const { accessKey = shared.getEnv('EDGE_STORE_ACCESS_KEY'), secretKey = shared.getEnv('EDGE_STORE_SECRET_KEY') } = params ?? {};
|
|
177
|
-
if (!accessKey || !secretKey) {
|
|
178
|
-
throw new EdgeStoreCredentialsError();
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
async getToken (params) {
|
|
182
|
-
return await edgeStoreRawSdk.getToken({
|
|
183
|
-
accessKey,
|
|
184
|
-
secretKey,
|
|
185
|
-
ctx: params.ctx,
|
|
186
|
-
router: params.router
|
|
187
|
-
});
|
|
188
|
-
},
|
|
189
|
-
async getFile ({ url }) {
|
|
190
|
-
return await edgeStoreRawSdk.getFile({
|
|
191
|
-
accessKey,
|
|
192
|
-
secretKey,
|
|
193
|
-
url
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
async requestUpload ({ bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
|
|
197
|
-
return await edgeStoreRawSdk.requestUpload({
|
|
198
|
-
accessKey,
|
|
199
|
-
secretKey,
|
|
200
|
-
bucketName,
|
|
201
|
-
bucketType,
|
|
202
|
-
fileInfo,
|
|
203
|
-
multipart,
|
|
204
|
-
autoSignedUrls
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
async getSignedUrls (params) {
|
|
208
|
-
return await edgeStoreRawSdk.getSignedUrls({
|
|
209
|
-
accessKey,
|
|
210
|
-
secretKey,
|
|
211
|
-
...params
|
|
212
|
-
});
|
|
213
|
-
},
|
|
214
|
-
async requestUploadParts ({ key, multipart }) {
|
|
215
|
-
return await edgeStoreRawSdk.requestUploadParts({
|
|
216
|
-
accessKey,
|
|
217
|
-
secretKey,
|
|
218
|
-
key,
|
|
219
|
-
multipart
|
|
220
|
-
});
|
|
221
|
-
},
|
|
222
|
-
async completeMultipartUpload ({ uploadId, key, parts }) {
|
|
223
|
-
return await edgeStoreRawSdk.completeMultipartUpload({
|
|
224
|
-
accessKey,
|
|
225
|
-
secretKey,
|
|
226
|
-
uploadId,
|
|
227
|
-
key,
|
|
228
|
-
parts
|
|
229
|
-
});
|
|
230
|
-
},
|
|
231
|
-
async confirmUpload ({ url }) {
|
|
232
|
-
return await edgeStoreRawSdk.confirmUpload({
|
|
233
|
-
accessKey,
|
|
234
|
-
secretKey,
|
|
235
|
-
url
|
|
236
|
-
});
|
|
237
|
-
},
|
|
238
|
-
async deleteFile ({ url }) {
|
|
239
|
-
return await edgeStoreRawSdk.deleteFile({
|
|
240
|
-
accessKey,
|
|
241
|
-
secretKey,
|
|
242
|
-
url
|
|
243
|
-
});
|
|
244
|
-
},
|
|
245
|
-
async listFiles (params) {
|
|
246
|
-
return await edgeStoreRawSdk.listFiles({
|
|
247
|
-
accessKey,
|
|
248
|
-
secretKey,
|
|
249
|
-
...params
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
exports.edgeStoreRawSdk = edgeStoreRawSdk;
|
|
256
|
-
exports.initEdgeStoreSdk = initEdgeStoreSdk;
|
package/dist/core/sdk/index.mjs
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { EdgeStoreError } from '@edgestore/shared';
|
|
2
|
-
import { getEnv } from '../../adapters/shared.mjs';
|
|
3
|
-
import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError.mjs';
|
|
4
|
-
import { EDGE_STORE_PACKAGE_VERSION, EDGE_STORE_PACKAGE_NAME } from '../../version.mjs';
|
|
5
|
-
|
|
6
|
-
const API_ENDPOINT = getEnv('EDGE_STORE_API_ENDPOINT') ?? 'https://api.edgestore.dev';
|
|
7
|
-
async function makeRequest(params) {
|
|
8
|
-
const { body, accessKey, secretKey, path } = params;
|
|
9
|
-
const res = await fetch(`${API_ENDPOINT}${path}`, {
|
|
10
|
-
method: 'POST',
|
|
11
|
-
body: JSON.stringify(body),
|
|
12
|
-
headers: {
|
|
13
|
-
'Content-Type': 'application/json',
|
|
14
|
-
Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}`,
|
|
15
|
-
'x-edgestore-package-name': EDGE_STORE_PACKAGE_NAME,
|
|
16
|
-
'x-edgestore-package-version': EDGE_STORE_PACKAGE_VERSION
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
if (!res.ok) {
|
|
20
|
-
throw new Error(`Failed to make request to ${path}: ${await res.text()}`);
|
|
21
|
-
}
|
|
22
|
-
return await res.json();
|
|
23
|
-
}
|
|
24
|
-
const edgeStoreRawSdk = {
|
|
25
|
-
async getToken (params) {
|
|
26
|
-
const reqBuckets = Object.entries(params.router.buckets).reduce((acc, [bucketName, bucket])=>{
|
|
27
|
-
acc[bucketName] = {
|
|
28
|
-
path: bucket._def.path.map((p)=>{
|
|
29
|
-
const paramEntries = Object.entries(p);
|
|
30
|
-
if (paramEntries[0] === undefined) {
|
|
31
|
-
throw new EdgeStoreError({
|
|
32
|
-
message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
|
|
33
|
-
code: 'SERVER_ERROR'
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const [key, value] = paramEntries[0];
|
|
37
|
-
return {
|
|
38
|
-
key,
|
|
39
|
-
value: value()
|
|
40
|
-
};
|
|
41
|
-
}),
|
|
42
|
-
accessControl: bucket._def.accessControl
|
|
43
|
-
};
|
|
44
|
-
return acc;
|
|
45
|
-
}, {});
|
|
46
|
-
const { token } = await makeRequest({
|
|
47
|
-
body: {
|
|
48
|
-
ctx: params.ctx,
|
|
49
|
-
buckets: reqBuckets
|
|
50
|
-
},
|
|
51
|
-
accessKey: params.accessKey,
|
|
52
|
-
secretKey: params.secretKey,
|
|
53
|
-
path: '/get-token'
|
|
54
|
-
});
|
|
55
|
-
return token;
|
|
56
|
-
},
|
|
57
|
-
async getFile ({ accessKey, secretKey, url }) {
|
|
58
|
-
return await makeRequest({
|
|
59
|
-
path: '/get-file',
|
|
60
|
-
accessKey,
|
|
61
|
-
secretKey,
|
|
62
|
-
body: {
|
|
63
|
-
url
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
async requestUpload ({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
|
|
68
|
-
const res = await makeRequest({
|
|
69
|
-
path: '/request-upload',
|
|
70
|
-
accessKey,
|
|
71
|
-
secretKey,
|
|
72
|
-
body: {
|
|
73
|
-
multipart,
|
|
74
|
-
bucketName,
|
|
75
|
-
bucketType,
|
|
76
|
-
isPublic: fileInfo.isPublic,
|
|
77
|
-
path: fileInfo.path,
|
|
78
|
-
extension: fileInfo.extension,
|
|
79
|
-
size: fileInfo.size,
|
|
80
|
-
mimeType: fileInfo.type,
|
|
81
|
-
metadata: fileInfo.metadata,
|
|
82
|
-
fileName: fileInfo.fileName,
|
|
83
|
-
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
84
|
-
isTemporary: fileInfo.temporary,
|
|
85
|
-
autoSignedUrls
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
multipart: res.multipart,
|
|
90
|
-
signedUrl: res.signedUrl,
|
|
91
|
-
accessUrl: res.url,
|
|
92
|
-
path: res.path,
|
|
93
|
-
thumbnailUrl: res.thumbnailUrl,
|
|
94
|
-
accessSignedUrl: res.accessSignedUrl,
|
|
95
|
-
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
96
|
-
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt,
|
|
97
|
-
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
|
|
98
|
-
};
|
|
99
|
-
},
|
|
100
|
-
async getSignedUrls ({ accessKey, secretKey, bucketName, urls, expiresIn, includeThumbnails }) {
|
|
101
|
-
const res = await makeRequest({
|
|
102
|
-
path: '/get-signed-urls',
|
|
103
|
-
accessKey,
|
|
104
|
-
secretKey,
|
|
105
|
-
body: {
|
|
106
|
-
bucketName,
|
|
107
|
-
urls,
|
|
108
|
-
expiresIn,
|
|
109
|
-
includeThumbnails
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return res.signedUrls;
|
|
113
|
-
},
|
|
114
|
-
async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
|
|
115
|
-
const res = await makeRequest({
|
|
116
|
-
path: '/request-upload-parts',
|
|
117
|
-
accessKey,
|
|
118
|
-
secretKey,
|
|
119
|
-
body: {
|
|
120
|
-
multipart,
|
|
121
|
-
key
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
return {
|
|
125
|
-
multipart: res.multipart
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
async completeMultipartUpload ({ accessKey, secretKey, uploadId, key, parts }) {
|
|
129
|
-
return await makeRequest({
|
|
130
|
-
path: '/complete-multipart-upload',
|
|
131
|
-
accessKey,
|
|
132
|
-
secretKey,
|
|
133
|
-
body: {
|
|
134
|
-
uploadId,
|
|
135
|
-
key,
|
|
136
|
-
parts
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
async confirmUpload ({ accessKey, secretKey, url }) {
|
|
141
|
-
return await makeRequest({
|
|
142
|
-
path: '/confirm-upload',
|
|
143
|
-
accessKey,
|
|
144
|
-
secretKey,
|
|
145
|
-
body: {
|
|
146
|
-
url
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
async deleteFile ({ accessKey, secretKey, url }) {
|
|
151
|
-
return await makeRequest({
|
|
152
|
-
path: '/delete-file',
|
|
153
|
-
accessKey,
|
|
154
|
-
secretKey,
|
|
155
|
-
body: {
|
|
156
|
-
url
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
async listFiles ({ accessKey, secretKey, bucketName, filter, pagination }) {
|
|
161
|
-
return await makeRequest({
|
|
162
|
-
path: '/list-files',
|
|
163
|
-
accessKey,
|
|
164
|
-
secretKey,
|
|
165
|
-
body: {
|
|
166
|
-
bucketName,
|
|
167
|
-
filter,
|
|
168
|
-
pagination
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
function initEdgeStoreSdk(params) {
|
|
174
|
-
const { accessKey = getEnv('EDGE_STORE_ACCESS_KEY'), secretKey = getEnv('EDGE_STORE_SECRET_KEY') } = params ?? {};
|
|
175
|
-
if (!accessKey || !secretKey) {
|
|
176
|
-
throw new EdgeStoreCredentialsError();
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
async getToken (params) {
|
|
180
|
-
return await edgeStoreRawSdk.getToken({
|
|
181
|
-
accessKey,
|
|
182
|
-
secretKey,
|
|
183
|
-
ctx: params.ctx,
|
|
184
|
-
router: params.router
|
|
185
|
-
});
|
|
186
|
-
},
|
|
187
|
-
async getFile ({ url }) {
|
|
188
|
-
return await edgeStoreRawSdk.getFile({
|
|
189
|
-
accessKey,
|
|
190
|
-
secretKey,
|
|
191
|
-
url
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
async requestUpload ({ bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
|
|
195
|
-
return await edgeStoreRawSdk.requestUpload({
|
|
196
|
-
accessKey,
|
|
197
|
-
secretKey,
|
|
198
|
-
bucketName,
|
|
199
|
-
bucketType,
|
|
200
|
-
fileInfo,
|
|
201
|
-
multipart,
|
|
202
|
-
autoSignedUrls
|
|
203
|
-
});
|
|
204
|
-
},
|
|
205
|
-
async getSignedUrls (params) {
|
|
206
|
-
return await edgeStoreRawSdk.getSignedUrls({
|
|
207
|
-
accessKey,
|
|
208
|
-
secretKey,
|
|
209
|
-
...params
|
|
210
|
-
});
|
|
211
|
-
},
|
|
212
|
-
async requestUploadParts ({ key, multipart }) {
|
|
213
|
-
return await edgeStoreRawSdk.requestUploadParts({
|
|
214
|
-
accessKey,
|
|
215
|
-
secretKey,
|
|
216
|
-
key,
|
|
217
|
-
multipart
|
|
218
|
-
});
|
|
219
|
-
},
|
|
220
|
-
async completeMultipartUpload ({ uploadId, key, parts }) {
|
|
221
|
-
return await edgeStoreRawSdk.completeMultipartUpload({
|
|
222
|
-
accessKey,
|
|
223
|
-
secretKey,
|
|
224
|
-
uploadId,
|
|
225
|
-
key,
|
|
226
|
-
parts
|
|
227
|
-
});
|
|
228
|
-
},
|
|
229
|
-
async confirmUpload ({ url }) {
|
|
230
|
-
return await edgeStoreRawSdk.confirmUpload({
|
|
231
|
-
accessKey,
|
|
232
|
-
secretKey,
|
|
233
|
-
url
|
|
234
|
-
});
|
|
235
|
-
},
|
|
236
|
-
async deleteFile ({ url }) {
|
|
237
|
-
return await edgeStoreRawSdk.deleteFile({
|
|
238
|
-
accessKey,
|
|
239
|
-
secretKey,
|
|
240
|
-
url
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
async listFiles (params) {
|
|
244
|
-
return await edgeStoreRawSdk.listFiles({
|
|
245
|
-
accessKey,
|
|
246
|
-
secretKey,
|
|
247
|
-
...params
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export { edgeStoreRawSdk, initEdgeStoreSdk };
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { initEdgeStore } from '@edgestore/shared';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
|
|
2
|
-
This can happen if you are trying to import something related to the backend of EdgeStore in a client component.`;
|
|
3
|
-
class EdgeStoreCredentialsError extends Error {
|
|
4
|
-
constructor(message = DEFAULT_MESSAGE){
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = 'EdgeStoreCredentialsError';
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { EdgeStoreCredentialsError as default };
|
package/dist/libs/logger.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { isDev } from '../adapters/shared.mjs';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-console */ function _define_property(obj, key, value) {
|
|
4
|
-
if (key in obj) {
|
|
5
|
-
Object.defineProperty(obj, key, {
|
|
6
|
-
value: value,
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true
|
|
10
|
-
});
|
|
11
|
-
} else {
|
|
12
|
-
obj[key] = value;
|
|
13
|
-
}
|
|
14
|
-
return obj;
|
|
15
|
-
}
|
|
16
|
-
const logLevel = [
|
|
17
|
-
'debug',
|
|
18
|
-
'info',
|
|
19
|
-
'warn',
|
|
20
|
-
'error',
|
|
21
|
-
'none'
|
|
22
|
-
];
|
|
23
|
-
class Logger {
|
|
24
|
-
shouldLog(level) {
|
|
25
|
-
return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
|
|
26
|
-
}
|
|
27
|
-
debug(message, ...optionalParams) {
|
|
28
|
-
if (this.shouldLog('debug')) {
|
|
29
|
-
console.debug('[EdgeStoreDebug]', message, ...optionalParams);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
info(message, ...optionalParams) {
|
|
33
|
-
if (this.shouldLog('info')) {
|
|
34
|
-
console.info('[EdgeStoreInfo]', message, ...optionalParams);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
warn(message, ...optionalParams) {
|
|
38
|
-
if (this.shouldLog('warn')) {
|
|
39
|
-
console.warn('[EdgeStoreWarn]', message, ...optionalParams);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
error(message, ...optionalParams) {
|
|
43
|
-
if (this.shouldLog('error')) {
|
|
44
|
-
console.error('[EdgeStoreError]', message, ...optionalParams);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
constructor(logLevel){
|
|
48
|
-
_define_property(this, "logLevel", void 0);
|
|
49
|
-
this.logLevel = logLevel ?? (isDev() ? 'info' : 'error');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export { Logger as default };
|
package/dist/libs/utils.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,QAAQ,IAAI,iBAAiB,EAClC,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAK3B,KAAK,wBAAwB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAEhE,MAAM,MAAM,sBAAsB,GAAG;IAEnC,YAAY,EAAE,MAAM,CAAC;IAErB,QAAQ,EAAE,wBAAwB,CAAC;IAEnC,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,CAC/B,IAAI,EAAE,sBAAsB,KACzB,YAAY,CAAC,MAAM,CAAC,CAAC;AAE1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;IAC5C;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,iBAAiB,CA0I3E"}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var clientS3 = require('@aws-sdk/client-s3');
|
|
4
|
-
var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
|
|
5
|
-
var uuid = require('uuid');
|
|
6
|
-
var shared = require('../../adapters/shared.js');
|
|
7
|
-
|
|
8
|
-
function AWSProvider(options) {
|
|
9
|
-
const { credentials: credentialsFromOptions, accessKeyId = shared.getEnv('ES_AWS_ACCESS_KEY_ID'), secretAccessKey = shared.getEnv('ES_AWS_SECRET_ACCESS_KEY'), region = shared.getEnv('ES_AWS_REGION'), bucketName = shared.getEnv('ES_AWS_BUCKET_NAME'), endpoint = shared.getEnv('ES_AWS_ENDPOINT'), forcePathStyle = shared.getEnv('ES_AWS_FORCE_PATH_STYLE') === 'true', overwritePath } = options ?? {};
|
|
10
|
-
const baseUrl = options?.baseUrl ?? shared.getEnv('EDGE_STORE_BASE_URL') ?? (endpoint ? `${endpoint}/${bucketName}` : `https://${bucketName}.s3.${region}.amazonaws.com`);
|
|
11
|
-
const credentials = credentialsFromOptions ?? (accessKeyId && secretAccessKey ? {
|
|
12
|
-
accessKeyId,
|
|
13
|
-
secretAccessKey
|
|
14
|
-
} : undefined);
|
|
15
|
-
const s3Client = new clientS3.S3Client({
|
|
16
|
-
region,
|
|
17
|
-
credentials,
|
|
18
|
-
endpoint,
|
|
19
|
-
forcePathStyle
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
name: 'aws',
|
|
23
|
-
async init () {
|
|
24
|
-
return {};
|
|
25
|
-
},
|
|
26
|
-
getBaseUrl () {
|
|
27
|
-
return baseUrl;
|
|
28
|
-
},
|
|
29
|
-
async getFile ({ url }) {
|
|
30
|
-
const path = url.replace(`${baseUrl}/`, '');
|
|
31
|
-
const { ContentLength, LastModified } = await s3Client.send(new clientS3.HeadObjectCommand({
|
|
32
|
-
Bucket: bucketName,
|
|
33
|
-
Key: path
|
|
34
|
-
}));
|
|
35
|
-
if (!ContentLength || !LastModified) {
|
|
36
|
-
throw new Error('File not found');
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
url,
|
|
40
|
-
metadata: {},
|
|
41
|
-
path: {},
|
|
42
|
-
size: ContentLength,
|
|
43
|
-
uploadedAt: LastModified
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
async requestUpload (params) {
|
|
47
|
-
const { bucketName: esBucketName, fileInfo } = params;
|
|
48
|
-
if (!bucketName) {
|
|
49
|
-
throw new Error('S3 bucketName is not configured in AWSProviderOptions.');
|
|
50
|
-
}
|
|
51
|
-
// Default S3 key (accessPath) construction logic
|
|
52
|
-
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
53
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
54
|
-
const defaultResolvedFileName = fileInfo.fileName ?? `${uuid.v4()}${extension}`;
|
|
55
|
-
const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item)=>{
|
|
56
|
-
return `${acc}/${item.value}`;
|
|
57
|
-
}, '');
|
|
58
|
-
let accessPath = `${pathPrefix}${defaultFilePathFromMetadata}/${defaultResolvedFileName}`;
|
|
59
|
-
if (overwritePath) {
|
|
60
|
-
accessPath = await overwritePath({
|
|
61
|
-
esBucketName,
|
|
62
|
-
fileInfo,
|
|
63
|
-
defaultAccessPath: accessPath
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
accessPath = accessPath.replace(/^\/+/, '');
|
|
67
|
-
const command = new clientS3.PutObjectCommand({
|
|
68
|
-
Bucket: bucketName,
|
|
69
|
-
Key: accessPath
|
|
70
|
-
});
|
|
71
|
-
const signedUrl = await s3RequestPresigner.getSignedUrl(s3Client, command, {
|
|
72
|
-
expiresIn: 60 * 60
|
|
73
|
-
});
|
|
74
|
-
const finalAccessUrl = `${baseUrl}/${accessPath}`;
|
|
75
|
-
return {
|
|
76
|
-
uploadUrl: signedUrl,
|
|
77
|
-
accessUrl: finalAccessUrl
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
async requestUploadParts () {
|
|
81
|
-
throw new Error('Not implemented');
|
|
82
|
-
},
|
|
83
|
-
async completeMultipartUpload () {
|
|
84
|
-
throw new Error('Not implemented');
|
|
85
|
-
},
|
|
86
|
-
async confirmUpload () {
|
|
87
|
-
throw new Error('Not implemented');
|
|
88
|
-
},
|
|
89
|
-
async deleteFile ({ url }) {
|
|
90
|
-
if (!bucketName) {
|
|
91
|
-
throw new Error('S3 bucketName is not configured in AWSProviderOptions for deleteFile.');
|
|
92
|
-
}
|
|
93
|
-
const path = url.replace(`${baseUrl}/`, '');
|
|
94
|
-
await s3Client.send(new clientS3.DeleteObjectCommand({
|
|
95
|
-
Bucket: bucketName,
|
|
96
|
-
Key: path
|
|
97
|
-
}));
|
|
98
|
-
return {
|
|
99
|
-
success: true
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
exports.AWSProvider = AWSProvider;
|