@edgestore/server 0.8.0 → 1.0.0-next.0
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/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 +2 -2
- package/dist/adapters/astro/index.js +28 -30
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.js +28 -30
- package/dist/adapters/fastify/index.d.ts +2 -2
- package/dist/adapters/fastify/index.js +28 -30
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.js +28 -30
- package/dist/adapters/imageTypes.js +1 -3
- package/dist/adapters/next/app/index.d.ts +2 -2
- package/dist/adapters/next/app/index.js +29 -31
- package/dist/adapters/next/pages/index.d.ts +2 -2
- package/dist/adapters/next/pages/index.js +29 -31
- package/dist/adapters/remix/index.d.ts +2 -2
- package/dist/adapters/remix/index.js +28 -30
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +44 -50
- package/dist/adapters/start/index.d.ts +2 -2
- package/dist/adapters/start/index.js +28 -30
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +7 -9
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -10
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/core/sdk/index.js +10 -13
- package/dist/index.js +1 -10
- package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -3
- package/dist/libs/logger.js +5 -9
- package/dist/libs/utils.js +1 -3
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +12 -15
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +6 -9
- package/dist/providers/edgestore/index.js +12 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -5
- package/package.json +51 -50
- package/providers/aws/index.d.ts +1 -1
- package/providers/aws/index.js +1 -1
- package/providers/azure/index.d.ts +1 -1
- package/providers/azure/index.js +1 -1
- package/providers/edgestore/index.d.ts +1 -1
- package/providers/edgestore/index.js +1 -1
- package/src/adapters/shared.ts +12 -13
- package/src/core/client/index.ts +0 -1
- package/src/core/sdk/index.ts +1 -8
- package/src/providers/aws/index.ts +1 -2
- package/src/providers/azure/index.ts +1 -2
- 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.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.mjs +0 -103
- package/dist/providers/azure/index.mjs +0 -85
- package/dist/providers/edgestore/index.mjs +0 -164
- package/dist/version.mjs +0 -4
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { buildPath, parsePath, isDev } from '../../adapters/shared.mjs';
|
|
2
|
-
import { initEdgeStoreSdk } from '../sdk/index.mjs';
|
|
3
|
-
|
|
4
|
-
// type guard for `content`
|
|
5
|
-
function isTextContent(content) {
|
|
6
|
-
return typeof content === 'string';
|
|
7
|
-
}
|
|
8
|
-
function isBlobContent(content) {
|
|
9
|
-
return typeof content !== 'string' && 'blob' in content;
|
|
10
|
-
}
|
|
11
|
-
function initEdgeStoreClient(config) {
|
|
12
|
-
const sdk = initEdgeStoreSdk({
|
|
13
|
-
accessKey: config.accessKey,
|
|
14
|
-
secretKey: config.secretKey
|
|
15
|
-
});
|
|
16
|
-
return new Proxy({}, {
|
|
17
|
-
get (_target, key) {
|
|
18
|
-
const bucketName = key;
|
|
19
|
-
const bucket = config.router.buckets[bucketName];
|
|
20
|
-
if (!bucket) {
|
|
21
|
-
throw new Error(`Bucket ${bucketName} not found`);
|
|
22
|
-
}
|
|
23
|
-
const client = {
|
|
24
|
-
async upload (params) {
|
|
25
|
-
const { content, ctx = {}, input = {} } = params;
|
|
26
|
-
let { blob, extension } = await (async ()=>{
|
|
27
|
-
if (isTextContent(content)) {
|
|
28
|
-
return {
|
|
29
|
-
blob: new Blob([
|
|
30
|
-
content
|
|
31
|
-
], {
|
|
32
|
-
type: 'text/plain'
|
|
33
|
-
}),
|
|
34
|
-
extension: 'txt'
|
|
35
|
-
};
|
|
36
|
-
} else if (isBlobContent(content)) {
|
|
37
|
-
return {
|
|
38
|
-
blob: content.blob,
|
|
39
|
-
extension: content.extension
|
|
40
|
-
};
|
|
41
|
-
} else {
|
|
42
|
-
return {
|
|
43
|
-
blob: await getBlobFromUrl(content.url),
|
|
44
|
-
extension: content.extension
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
})();
|
|
48
|
-
if (params.options?.transform) {
|
|
49
|
-
const transformed = await params.options.transform({
|
|
50
|
-
blob,
|
|
51
|
-
extension,
|
|
52
|
-
type: blob.type
|
|
53
|
-
});
|
|
54
|
-
blob = transformed.blob;
|
|
55
|
-
extension = transformed.extension;
|
|
56
|
-
}
|
|
57
|
-
const path = buildPath({
|
|
58
|
-
bucket,
|
|
59
|
-
pathAttrs: {
|
|
60
|
-
ctx,
|
|
61
|
-
input
|
|
62
|
-
},
|
|
63
|
-
fileInfo: {
|
|
64
|
-
type: blob.type,
|
|
65
|
-
size: blob.size,
|
|
66
|
-
fileName: params.options?.manualFileName,
|
|
67
|
-
replaceTargetUrl: params.options?.replaceTargetUrl
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const metadata = await bucket._def.metadata({
|
|
71
|
-
ctx,
|
|
72
|
-
input
|
|
73
|
-
});
|
|
74
|
-
const requestUploadRes = await sdk.requestUpload({
|
|
75
|
-
bucketName,
|
|
76
|
-
bucketType: bucket._def.type,
|
|
77
|
-
autoSignedUrls: bucket._def.autoSignedUrls,
|
|
78
|
-
fileInfo: {
|
|
79
|
-
fileName: params.options?.manualFileName,
|
|
80
|
-
replaceTargetUrl: params.options?.replaceTargetUrl,
|
|
81
|
-
type: blob.type,
|
|
82
|
-
size: blob.size,
|
|
83
|
-
extension,
|
|
84
|
-
isPublic: bucket._def.accessControl === undefined,
|
|
85
|
-
temporary: params.options?.temporary ?? false,
|
|
86
|
-
path,
|
|
87
|
-
metadata
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
const { signedUrl, multipart } = requestUploadRes;
|
|
91
|
-
if (multipart) {
|
|
92
|
-
// TODO
|
|
93
|
-
throw new Error('Multipart upload not implemented');
|
|
94
|
-
} else if (signedUrl) {
|
|
95
|
-
const uploadResponse = await fetch(signedUrl, {
|
|
96
|
-
method: 'PUT',
|
|
97
|
-
body: blob
|
|
98
|
-
});
|
|
99
|
-
if (!uploadResponse.ok) {
|
|
100
|
-
throw new Error(`Upload failed with status ${uploadResponse.status}: ${uploadResponse.statusText}`);
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error('Missing signedUrl');
|
|
104
|
-
}
|
|
105
|
-
const { parsedPath, pathOrder } = parsePath(path);
|
|
106
|
-
return {
|
|
107
|
-
url: requestUploadRes.accessUrl,
|
|
108
|
-
...{
|
|
109
|
-
thumbnailUrl: requestUploadRes.thumbnailUrl
|
|
110
|
-
},
|
|
111
|
-
...mapSignedUploadAccess(requestUploadRes),
|
|
112
|
-
size: blob.size,
|
|
113
|
-
metadata,
|
|
114
|
-
path: parsedPath,
|
|
115
|
-
pathOrder
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
async getFile (params) {
|
|
119
|
-
const res = await sdk.getFile(params);
|
|
120
|
-
return {
|
|
121
|
-
url: getUrl(res.url, config.baseUrl),
|
|
122
|
-
size: res.size,
|
|
123
|
-
uploadedAt: new Date(res.uploadedAt),
|
|
124
|
-
metadata: res.metadata,
|
|
125
|
-
path: res.path
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
async confirmUpload (params) {
|
|
129
|
-
return await sdk.confirmUpload(params);
|
|
130
|
-
},
|
|
131
|
-
async deleteFile (params) {
|
|
132
|
-
return await sdk.deleteFile(params);
|
|
133
|
-
},
|
|
134
|
-
async listFiles (params) {
|
|
135
|
-
const res = await sdk.listFiles({
|
|
136
|
-
bucketName,
|
|
137
|
-
...params
|
|
138
|
-
});
|
|
139
|
-
const files = res.data.map((file)=>{
|
|
140
|
-
return {
|
|
141
|
-
url: getUrl(file.url, config.baseUrl),
|
|
142
|
-
thumbnailUrl: file.thumbnailUrl,
|
|
143
|
-
size: file.size,
|
|
144
|
-
uploadedAt: new Date(file.uploadedAt),
|
|
145
|
-
metadata: file.metadata,
|
|
146
|
-
path: file.path
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
return {
|
|
150
|
-
data: files,
|
|
151
|
-
pagination: res.pagination
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
async getSignedUrl (params) {
|
|
155
|
-
const [signedUrl] = await sdk.getSignedUrls({
|
|
156
|
-
bucketName,
|
|
157
|
-
urls: [
|
|
158
|
-
params.url
|
|
159
|
-
],
|
|
160
|
-
expiresIn: params.expiresIn
|
|
161
|
-
});
|
|
162
|
-
if (!signedUrl) {
|
|
163
|
-
throw new Error('Missing signed URL response');
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
...signedUrl,
|
|
167
|
-
expiresAt: new Date(signedUrl.expiresAt)
|
|
168
|
-
};
|
|
169
|
-
},
|
|
170
|
-
async getSignedUrls (params) {
|
|
171
|
-
const signedUrls = await sdk.getSignedUrls({
|
|
172
|
-
bucketName,
|
|
173
|
-
urls: params.urls,
|
|
174
|
-
expiresIn: params.expiresIn,
|
|
175
|
-
includeThumbnails: params.includeThumbnails
|
|
176
|
-
});
|
|
177
|
-
return signedUrls.map((signedUrl)=>({
|
|
178
|
-
...signedUrl,
|
|
179
|
-
expiresAt: new Date(signedUrl.expiresAt)
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
return client;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Protected files need third-party cookies to work.
|
|
189
|
-
* Since third party cookies don't work on localhost,
|
|
190
|
-
* we need to proxy the file through the server.
|
|
191
|
-
*/ function getUrl(url, baseUrl) {
|
|
192
|
-
if (isDev() && !url.includes('/_public/')) {
|
|
193
|
-
if (!baseUrl) {
|
|
194
|
-
throw new Error('Missing baseUrl. You need to pass the baseUrl to `initEdgeStoreClient` to get protected files in development.');
|
|
195
|
-
}
|
|
196
|
-
const proxyUrl = new URL(baseUrl);
|
|
197
|
-
proxyUrl.pathname = `${proxyUrl.pathname}/proxy-file`;
|
|
198
|
-
proxyUrl.search = new URLSearchParams({
|
|
199
|
-
url
|
|
200
|
-
}).toString();
|
|
201
|
-
return proxyUrl.toString();
|
|
202
|
-
}
|
|
203
|
-
return url;
|
|
204
|
-
}
|
|
205
|
-
async function getBlobFromUrl(url) {
|
|
206
|
-
const res = await fetch(url);
|
|
207
|
-
return await res.blob();
|
|
208
|
-
}
|
|
209
|
-
function mapSignedUploadAccess(res) {
|
|
210
|
-
if (!res.accessSignedUrl) {
|
|
211
|
-
return {};
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
signedUrl: res.accessSignedUrl,
|
|
215
|
-
expiresAt: res.accessSignedUrlExpiresAt ? new Date(res.accessSignedUrlExpiresAt) : new Date(),
|
|
216
|
-
expiresIn: res.accessSignedUrlExpiresIn ?? 0,
|
|
217
|
-
signedThumbnailUrl: res.accessSignedThumbnailUrl ?? null
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export { initEdgeStoreClient };
|
package/dist/core/index.mjs
DELETED
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,103 +0,0 @@
|
|
|
1
|
-
import { S3Client, DeleteObjectCommand, PutObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
|
|
2
|
-
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
3
|
-
import { v4 } from 'uuid';
|
|
4
|
-
import { getEnv } from '../../adapters/shared.mjs';
|
|
5
|
-
|
|
6
|
-
function AWSProvider(options) {
|
|
7
|
-
const { credentials: credentialsFromOptions, accessKeyId = getEnv('ES_AWS_ACCESS_KEY_ID'), secretAccessKey = getEnv('ES_AWS_SECRET_ACCESS_KEY'), region = getEnv('ES_AWS_REGION'), bucketName = getEnv('ES_AWS_BUCKET_NAME'), endpoint = getEnv('ES_AWS_ENDPOINT'), forcePathStyle = getEnv('ES_AWS_FORCE_PATH_STYLE') === 'true', overwritePath } = options ?? {};
|
|
8
|
-
const baseUrl = options?.baseUrl ?? getEnv('EDGE_STORE_BASE_URL') ?? (endpoint ? `${endpoint}/${bucketName}` : `https://${bucketName}.s3.${region}.amazonaws.com`);
|
|
9
|
-
const credentials = credentialsFromOptions ?? (accessKeyId && secretAccessKey ? {
|
|
10
|
-
accessKeyId,
|
|
11
|
-
secretAccessKey
|
|
12
|
-
} : undefined);
|
|
13
|
-
const s3Client = new S3Client({
|
|
14
|
-
region,
|
|
15
|
-
credentials,
|
|
16
|
-
endpoint,
|
|
17
|
-
forcePathStyle
|
|
18
|
-
});
|
|
19
|
-
return {
|
|
20
|
-
name: 'aws',
|
|
21
|
-
async init () {
|
|
22
|
-
return {};
|
|
23
|
-
},
|
|
24
|
-
getBaseUrl () {
|
|
25
|
-
return baseUrl;
|
|
26
|
-
},
|
|
27
|
-
async getFile ({ url }) {
|
|
28
|
-
const path = url.replace(`${baseUrl}/`, '');
|
|
29
|
-
const { ContentLength, LastModified } = await s3Client.send(new HeadObjectCommand({
|
|
30
|
-
Bucket: bucketName,
|
|
31
|
-
Key: path
|
|
32
|
-
}));
|
|
33
|
-
if (!ContentLength || !LastModified) {
|
|
34
|
-
throw new Error('File not found');
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
url,
|
|
38
|
-
metadata: {},
|
|
39
|
-
path: {},
|
|
40
|
-
size: ContentLength,
|
|
41
|
-
uploadedAt: LastModified
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
async requestUpload (params) {
|
|
45
|
-
const { bucketName: esBucketName, fileInfo } = params;
|
|
46
|
-
if (!bucketName) {
|
|
47
|
-
throw new Error('S3 bucketName is not configured in AWSProviderOptions.');
|
|
48
|
-
}
|
|
49
|
-
// Default S3 key (accessPath) construction logic
|
|
50
|
-
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
51
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
52
|
-
const defaultResolvedFileName = fileInfo.fileName ?? `${v4()}${extension}`;
|
|
53
|
-
const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item)=>{
|
|
54
|
-
return `${acc}/${item.value}`;
|
|
55
|
-
}, '');
|
|
56
|
-
let accessPath = `${pathPrefix}${defaultFilePathFromMetadata}/${defaultResolvedFileName}`;
|
|
57
|
-
if (overwritePath) {
|
|
58
|
-
accessPath = await overwritePath({
|
|
59
|
-
esBucketName,
|
|
60
|
-
fileInfo,
|
|
61
|
-
defaultAccessPath: accessPath
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
accessPath = accessPath.replace(/^\/+/, '');
|
|
65
|
-
const command = new PutObjectCommand({
|
|
66
|
-
Bucket: bucketName,
|
|
67
|
-
Key: accessPath
|
|
68
|
-
});
|
|
69
|
-
const signedUrl = await getSignedUrl(s3Client, command, {
|
|
70
|
-
expiresIn: 60 * 60
|
|
71
|
-
});
|
|
72
|
-
const finalAccessUrl = `${baseUrl}/${accessPath}`;
|
|
73
|
-
return {
|
|
74
|
-
uploadUrl: signedUrl,
|
|
75
|
-
accessUrl: finalAccessUrl
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
async requestUploadParts () {
|
|
79
|
-
throw new Error('Not implemented');
|
|
80
|
-
},
|
|
81
|
-
async completeMultipartUpload () {
|
|
82
|
-
throw new Error('Not implemented');
|
|
83
|
-
},
|
|
84
|
-
async confirmUpload () {
|
|
85
|
-
throw new Error('Not implemented');
|
|
86
|
-
},
|
|
87
|
-
async deleteFile ({ url }) {
|
|
88
|
-
if (!bucketName) {
|
|
89
|
-
throw new Error('S3 bucketName is not configured in AWSProviderOptions for deleteFile.');
|
|
90
|
-
}
|
|
91
|
-
const path = url.replace(`${baseUrl}/`, '');
|
|
92
|
-
await s3Client.send(new DeleteObjectCommand({
|
|
93
|
-
Bucket: bucketName,
|
|
94
|
-
Key: path
|
|
95
|
-
}));
|
|
96
|
-
return {
|
|
97
|
-
success: true
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export { AWSProvider };
|