@edgestore/server 0.7.0-canary.2 → 0.8.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/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +9 -15
- package/dist/adapters/astro/index.mjs +10 -16
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +8 -13
- package/dist/adapters/express/index.mjs +9 -14
- package/dist/adapters/fastify/index.d.ts +1 -1
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +7 -14
- package/dist/adapters/fastify/index.mjs +8 -15
- package/dist/adapters/hono/index.d.ts +4 -70
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +12 -13
- package/dist/adapters/hono/index.mjs +13 -14
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +7 -13
- package/dist/adapters/next/app/index.mjs +8 -14
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +8 -13
- package/dist/adapters/next/pages/index.mjs +9 -14
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +9 -14
- package/dist/adapters/remix/index.mjs +10 -15
- package/dist/adapters/shared.d.ts +8 -0
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +36 -7
- package/dist/adapters/shared.mjs +36 -8
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +9 -15
- package/dist/adapters/start/index.mjs +10 -16
- package/dist/core/client/index.d.ts +112 -69
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +52 -4
- package/dist/core/client/index.mjs +52 -4
- package/dist/core/sdk/index.d.ts +44 -2
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/core/sdk/index.js +36 -6
- package/dist/core/sdk/index.mjs +36 -6
- package/dist/providers/aws/index.d.ts +1 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +3 -3
- package/dist/providers/aws/index.mjs +3 -3
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +33 -7
- package/dist/providers/azure/index.mjs +33 -7
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +24 -4
- package/dist/providers/edgestore/index.mjs +24 -4
- package/dist/test-utils/edgestoreSmoke.d.ts +32 -0
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.mjs +4 -0
- package/package.json +11 -2
- package/src/adapters/astro/index.ts +11 -21
- package/src/adapters/express/index.ts +10 -16
- package/src/adapters/fastify/index.ts +13 -19
- package/src/adapters/hono/index.ts +19 -23
- package/src/adapters/next/app/index.ts +12 -22
- package/src/adapters/next/pages/index.ts +11 -16
- package/src/adapters/remix/index.ts +11 -12
- package/src/adapters/shared.ts +49 -4
- package/src/adapters/start/index.ts +11 -12
- package/src/core/client/index.ts +199 -74
- package/src/core/sdk/index.ts +75 -0
- package/src/providers/aws/index.ts +4 -4
- package/src/providers/azure/index.ts +40 -10
- package/src/providers/edgestore/index.ts +29 -0
- package/src/test-utils/edgestoreSmoke.ts +141 -0
- package/src/version.ts +2 -0
package/dist/core/sdk/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EdgeStoreError } from '@edgestore/shared';
|
|
2
2
|
import { getEnv } from '../../adapters/shared.mjs';
|
|
3
3
|
import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError.mjs';
|
|
4
|
+
import { EDGE_STORE_PACKAGE_VERSION, EDGE_STORE_PACKAGE_NAME } from '../../version.mjs';
|
|
4
5
|
|
|
5
6
|
const API_ENDPOINT = getEnv('EDGE_STORE_API_ENDPOINT') ?? 'https://api.edgestore.dev';
|
|
6
7
|
async function makeRequest(params) {
|
|
@@ -10,7 +11,9 @@ async function makeRequest(params) {
|
|
|
10
11
|
body: JSON.stringify(body),
|
|
11
12
|
headers: {
|
|
12
13
|
'Content-Type': 'application/json',
|
|
13
|
-
Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}
|
|
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
|
|
14
17
|
}
|
|
15
18
|
});
|
|
16
19
|
if (!res.ok) {
|
|
@@ -61,7 +64,7 @@ const edgeStoreRawSdk = {
|
|
|
61
64
|
}
|
|
62
65
|
});
|
|
63
66
|
},
|
|
64
|
-
async requestUpload ({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart }) {
|
|
67
|
+
async requestUpload ({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
|
|
65
68
|
const res = await makeRequest({
|
|
66
69
|
path: '/request-upload',
|
|
67
70
|
accessKey,
|
|
@@ -78,7 +81,8 @@ const edgeStoreRawSdk = {
|
|
|
78
81
|
metadata: fileInfo.metadata,
|
|
79
82
|
fileName: fileInfo.fileName,
|
|
80
83
|
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
81
|
-
isTemporary: fileInfo.temporary
|
|
84
|
+
isTemporary: fileInfo.temporary,
|
|
85
|
+
autoSignedUrls
|
|
82
86
|
}
|
|
83
87
|
});
|
|
84
88
|
return {
|
|
@@ -86,9 +90,27 @@ const edgeStoreRawSdk = {
|
|
|
86
90
|
signedUrl: res.signedUrl,
|
|
87
91
|
accessUrl: res.url,
|
|
88
92
|
path: res.path,
|
|
89
|
-
thumbnailUrl: res.thumbnailUrl
|
|
93
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
94
|
+
accessSignedUrl: res.accessSignedUrl,
|
|
95
|
+
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
96
|
+
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt,
|
|
97
|
+
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
|
|
90
98
|
};
|
|
91
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
|
+
},
|
|
92
114
|
async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
|
|
93
115
|
const res = await makeRequest({
|
|
94
116
|
path: '/request-upload-parts',
|
|
@@ -169,14 +191,22 @@ function initEdgeStoreSdk(params) {
|
|
|
169
191
|
url
|
|
170
192
|
});
|
|
171
193
|
},
|
|
172
|
-
async requestUpload ({ bucketName, bucketType, fileInfo, multipart }) {
|
|
194
|
+
async requestUpload ({ bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
|
|
173
195
|
return await edgeStoreRawSdk.requestUpload({
|
|
174
196
|
accessKey,
|
|
175
197
|
secretKey,
|
|
176
198
|
bucketName,
|
|
177
199
|
bucketType,
|
|
178
200
|
fileInfo,
|
|
179
|
-
multipart
|
|
201
|
+
multipart,
|
|
202
|
+
autoSignedUrls
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
async getSignedUrls (params) {
|
|
206
|
+
return await edgeStoreRawSdk.getSignedUrls({
|
|
207
|
+
accessKey,
|
|
208
|
+
secretKey,
|
|
209
|
+
...params
|
|
180
210
|
});
|
|
181
211
|
},
|
|
182
212
|
async requestUploadParts ({ key, multipart }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type S3ClientConfig } from '@aws-sdk/client-s3';
|
|
2
|
-
import { type
|
|
2
|
+
import { type Provider as EdgeStoreProvider, type MaybePromise, type RequestUploadParams } from '@edgestore/shared';
|
|
3
3
|
type ProviderUploadedFileInfo = RequestUploadParams['fileInfo'];
|
|
4
4
|
export type AWSOverwritePathFnArgs = {
|
|
5
5
|
esBucketName: string;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
|
@@ -50,9 +50,8 @@ function AWSProvider(options) {
|
|
|
50
50
|
}
|
|
51
51
|
// Default S3 key (accessPath) construction logic
|
|
52
52
|
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
53
|
-
const nameId = uuid.v4();
|
|
54
53
|
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
55
|
-
const defaultResolvedFileName = fileInfo.fileName ?? `${
|
|
54
|
+
const defaultResolvedFileName = fileInfo.fileName ?? `${uuid.v4()}${extension}`;
|
|
56
55
|
const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item)=>{
|
|
57
56
|
return `${acc}/${item.value}`;
|
|
58
57
|
}, '');
|
|
@@ -64,6 +63,7 @@ function AWSProvider(options) {
|
|
|
64
63
|
defaultAccessPath: accessPath
|
|
65
64
|
});
|
|
66
65
|
}
|
|
66
|
+
accessPath = accessPath.replace(/^\/+/, '');
|
|
67
67
|
const command = new clientS3.PutObjectCommand({
|
|
68
68
|
Bucket: bucketName,
|
|
69
69
|
Key: accessPath
|
|
@@ -71,7 +71,7 @@ function AWSProvider(options) {
|
|
|
71
71
|
const signedUrl = await s3RequestPresigner.getSignedUrl(s3Client, command, {
|
|
72
72
|
expiresIn: 60 * 60
|
|
73
73
|
});
|
|
74
|
-
const finalAccessUrl = `${baseUrl}/${accessPath
|
|
74
|
+
const finalAccessUrl = `${baseUrl}/${accessPath}`;
|
|
75
75
|
return {
|
|
76
76
|
uploadUrl: signedUrl,
|
|
77
77
|
accessUrl: finalAccessUrl
|
|
@@ -48,9 +48,8 @@ function AWSProvider(options) {
|
|
|
48
48
|
}
|
|
49
49
|
// Default S3 key (accessPath) construction logic
|
|
50
50
|
const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
|
|
51
|
-
const nameId = v4();
|
|
52
51
|
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
53
|
-
const defaultResolvedFileName = fileInfo.fileName ?? `${
|
|
52
|
+
const defaultResolvedFileName = fileInfo.fileName ?? `${v4()}${extension}`;
|
|
54
53
|
const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item)=>{
|
|
55
54
|
return `${acc}/${item.value}`;
|
|
56
55
|
}, '');
|
|
@@ -62,6 +61,7 @@ function AWSProvider(options) {
|
|
|
62
61
|
defaultAccessPath: accessPath
|
|
63
62
|
});
|
|
64
63
|
}
|
|
64
|
+
accessPath = accessPath.replace(/^\/+/, '');
|
|
65
65
|
const command = new PutObjectCommand({
|
|
66
66
|
Bucket: bucketName,
|
|
67
67
|
Key: accessPath
|
|
@@ -69,7 +69,7 @@ function AWSProvider(options) {
|
|
|
69
69
|
const signedUrl = await getSignedUrl(s3Client, command, {
|
|
70
70
|
expiresIn: 60 * 60
|
|
71
71
|
});
|
|
72
|
-
const finalAccessUrl = `${baseUrl}/${accessPath
|
|
72
|
+
const finalAccessUrl = `${baseUrl}/${accessPath}`;
|
|
73
73
|
return {
|
|
74
74
|
uploadUrl: signedUrl,
|
|
75
75
|
accessUrl: finalAccessUrl
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIlD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIlD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,QAAQ,CAmGtE"}
|
|
@@ -9,6 +9,35 @@ function AzureProvider(options) {
|
|
|
9
9
|
const baseUrl = customBaseUrl ?? `https://${storageAccountName}.blob.core.windows.net`;
|
|
10
10
|
const blobServiceClient = new storageBlob.BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
11
11
|
const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
|
|
12
|
+
function getBlobNameFromUrl(url) {
|
|
13
|
+
try {
|
|
14
|
+
const blobUrl = new URL(url);
|
|
15
|
+
const containerUrl = new URL(containerClient.url);
|
|
16
|
+
const containerPath = containerUrl.pathname.replace(/\/$/, '');
|
|
17
|
+
if (blobUrl.origin !== containerUrl.origin) {
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
if (!blobUrl.pathname.startsWith(`${containerPath}/`)) {
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
|
|
24
|
+
} catch {
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getBlobName(params) {
|
|
29
|
+
const { bucketName: esBucketName, fileInfo } = params;
|
|
30
|
+
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
31
|
+
const fileName = fileInfo.fileName ?? `${uuid.v4()}${extension}`;
|
|
32
|
+
return [
|
|
33
|
+
esBucketName,
|
|
34
|
+
...fileInfo.isPublic ? [
|
|
35
|
+
'_public'
|
|
36
|
+
] : [],
|
|
37
|
+
...fileInfo.path.map((item)=>item.value),
|
|
38
|
+
fileName
|
|
39
|
+
].join('/');
|
|
40
|
+
}
|
|
12
41
|
return {
|
|
13
42
|
name: 'azure',
|
|
14
43
|
async init () {
|
|
@@ -18,7 +47,7 @@ function AzureProvider(options) {
|
|
|
18
47
|
return baseUrl;
|
|
19
48
|
},
|
|
20
49
|
async getFile ({ url }) {
|
|
21
|
-
const blobClient = containerClient.getBlobClient(url);
|
|
50
|
+
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
22
51
|
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
23
52
|
return {
|
|
24
53
|
url: url,
|
|
@@ -28,11 +57,8 @@ function AzureProvider(options) {
|
|
|
28
57
|
uploadedAt: lastModified ?? new Date()
|
|
29
58
|
};
|
|
30
59
|
},
|
|
31
|
-
async requestUpload (
|
|
32
|
-
const
|
|
33
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
34
|
-
const fileName = fileInfo.fileName ?? `${nameId}${extension}`;
|
|
35
|
-
const blobClient = containerClient.getBlobClient(fileName);
|
|
60
|
+
async requestUpload (params) {
|
|
61
|
+
const blobClient = containerClient.getBlobClient(getBlobName(params));
|
|
36
62
|
const url = blobClient.url;
|
|
37
63
|
return {
|
|
38
64
|
uploadUrl: url,
|
|
@@ -49,7 +75,7 @@ function AzureProvider(options) {
|
|
|
49
75
|
throw new Error('Not implemented');
|
|
50
76
|
},
|
|
51
77
|
async deleteFile ({ url }) {
|
|
52
|
-
const blobClient = containerClient.getBlobClient(url);
|
|
78
|
+
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
53
79
|
await blobClient.delete();
|
|
54
80
|
return {
|
|
55
81
|
success: true
|
|
@@ -7,6 +7,35 @@ function AzureProvider(options) {
|
|
|
7
7
|
const baseUrl = customBaseUrl ?? `https://${storageAccountName}.blob.core.windows.net`;
|
|
8
8
|
const blobServiceClient = new BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
9
9
|
const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
|
|
10
|
+
function getBlobNameFromUrl(url) {
|
|
11
|
+
try {
|
|
12
|
+
const blobUrl = new URL(url);
|
|
13
|
+
const containerUrl = new URL(containerClient.url);
|
|
14
|
+
const containerPath = containerUrl.pathname.replace(/\/$/, '');
|
|
15
|
+
if (blobUrl.origin !== containerUrl.origin) {
|
|
16
|
+
return url;
|
|
17
|
+
}
|
|
18
|
+
if (!blobUrl.pathname.startsWith(`${containerPath}/`)) {
|
|
19
|
+
return url;
|
|
20
|
+
}
|
|
21
|
+
return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
|
|
22
|
+
} catch {
|
|
23
|
+
return url;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function getBlobName(params) {
|
|
27
|
+
const { bucketName: esBucketName, fileInfo } = params;
|
|
28
|
+
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
29
|
+
const fileName = fileInfo.fileName ?? `${v4()}${extension}`;
|
|
30
|
+
return [
|
|
31
|
+
esBucketName,
|
|
32
|
+
...fileInfo.isPublic ? [
|
|
33
|
+
'_public'
|
|
34
|
+
] : [],
|
|
35
|
+
...fileInfo.path.map((item)=>item.value),
|
|
36
|
+
fileName
|
|
37
|
+
].join('/');
|
|
38
|
+
}
|
|
10
39
|
return {
|
|
11
40
|
name: 'azure',
|
|
12
41
|
async init () {
|
|
@@ -16,7 +45,7 @@ function AzureProvider(options) {
|
|
|
16
45
|
return baseUrl;
|
|
17
46
|
},
|
|
18
47
|
async getFile ({ url }) {
|
|
19
|
-
const blobClient = containerClient.getBlobClient(url);
|
|
48
|
+
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
20
49
|
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
21
50
|
return {
|
|
22
51
|
url: url,
|
|
@@ -26,11 +55,8 @@ function AzureProvider(options) {
|
|
|
26
55
|
uploadedAt: lastModified ?? new Date()
|
|
27
56
|
};
|
|
28
57
|
},
|
|
29
|
-
async requestUpload (
|
|
30
|
-
const
|
|
31
|
-
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
32
|
-
const fileName = fileInfo.fileName ?? `${nameId}${extension}`;
|
|
33
|
-
const blobClient = containerClient.getBlobClient(fileName);
|
|
58
|
+
async requestUpload (params) {
|
|
59
|
+
const blobClient = containerClient.getBlobClient(getBlobName(params));
|
|
34
60
|
const url = blobClient.url;
|
|
35
61
|
return {
|
|
36
62
|
uploadUrl: url,
|
|
@@ -47,7 +73,7 @@ function AzureProvider(options) {
|
|
|
47
73
|
throw new Error('Not implemented');
|
|
48
74
|
},
|
|
49
75
|
async deleteFile ({ url }) {
|
|
50
|
-
const blobClient = containerClient.getBlobClient(url);
|
|
76
|
+
const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
|
|
51
77
|
await blobClient.delete();
|
|
52
78
|
return {
|
|
53
79
|
success: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EAEd,MAAM,mBAAmB,CAAC;AAO3B,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EAEd,MAAM,mBAAmB,CAAC;AAO3B,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,QAAQ,CAkKV"}
|
|
@@ -41,7 +41,7 @@ function EdgeStoreProvider(options) {
|
|
|
41
41
|
...rest
|
|
42
42
|
};
|
|
43
43
|
},
|
|
44
|
-
async requestUpload ({ bucketName, bucketType, fileInfo }) {
|
|
44
|
+
async requestUpload ({ bucketName, bucketType, fileInfo, autoSignedUrls }) {
|
|
45
45
|
// multipart upload if file is bigger than a certain size
|
|
46
46
|
const MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10MB
|
|
47
47
|
let partSize = 5 * 1024 * 1024; // 5MB
|
|
@@ -56,6 +56,7 @@ function EdgeStoreProvider(options) {
|
|
|
56
56
|
bucketName,
|
|
57
57
|
bucketType,
|
|
58
58
|
fileInfo,
|
|
59
|
+
autoSignedUrls,
|
|
59
60
|
multipart: {
|
|
60
61
|
parts: Array.from({
|
|
61
62
|
length: totalParts
|
|
@@ -76,13 +77,15 @@ function EdgeStoreProvider(options) {
|
|
|
76
77
|
return {
|
|
77
78
|
accessUrl: res.accessUrl,
|
|
78
79
|
thumbnailUrl: res.thumbnailUrl,
|
|
80
|
+
...mapSignedUploadAccess(res),
|
|
79
81
|
multipart
|
|
80
82
|
};
|
|
81
83
|
} else if (res.signedUrl) {
|
|
82
84
|
return {
|
|
83
85
|
accessUrl: res.accessUrl,
|
|
84
86
|
uploadUrl: res.signedUrl,
|
|
85
|
-
thumbnailUrl: res.thumbnailUrl
|
|
87
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
88
|
+
...mapSignedUploadAccess(res)
|
|
86
89
|
};
|
|
87
90
|
} else {
|
|
88
91
|
throw new shared$1.EdgeStoreError({
|
|
@@ -94,13 +97,15 @@ function EdgeStoreProvider(options) {
|
|
|
94
97
|
const res = await edgeStoreSdk.requestUpload({
|
|
95
98
|
bucketName,
|
|
96
99
|
bucketType,
|
|
97
|
-
fileInfo
|
|
100
|
+
fileInfo,
|
|
101
|
+
autoSignedUrls
|
|
98
102
|
});
|
|
99
103
|
if (res.signedUrl) {
|
|
100
104
|
return {
|
|
101
105
|
accessUrl: res.accessUrl,
|
|
102
106
|
uploadUrl: res.signedUrl,
|
|
103
|
-
thumbnailUrl: res.thumbnailUrl
|
|
107
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
108
|
+
...mapSignedUploadAccess(res)
|
|
104
109
|
};
|
|
105
110
|
}
|
|
106
111
|
throw new shared$1.EdgeStoreError({
|
|
@@ -123,6 +128,13 @@ function EdgeStoreProvider(options) {
|
|
|
123
128
|
}
|
|
124
129
|
};
|
|
125
130
|
},
|
|
131
|
+
getSignedUrls: async (params)=>{
|
|
132
|
+
const res = await edgeStoreSdk.getSignedUrls(params);
|
|
133
|
+
return res.map((item)=>({
|
|
134
|
+
...item,
|
|
135
|
+
expiresAt: new Date(item.expiresAt)
|
|
136
|
+
}));
|
|
137
|
+
},
|
|
126
138
|
completeMultipartUpload: async ({ uploadId, key, parts })=>{
|
|
127
139
|
return await edgeStoreSdk.completeMultipartUpload({
|
|
128
140
|
uploadId,
|
|
@@ -142,5 +154,13 @@ function EdgeStoreProvider(options) {
|
|
|
142
154
|
}
|
|
143
155
|
};
|
|
144
156
|
}
|
|
157
|
+
function mapSignedUploadAccess(res) {
|
|
158
|
+
return {
|
|
159
|
+
accessSignedUrl: res.accessSignedUrl,
|
|
160
|
+
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
161
|
+
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt ? new Date(res.accessSignedUrlExpiresAt) : undefined,
|
|
162
|
+
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
|
|
163
|
+
};
|
|
164
|
+
}
|
|
145
165
|
|
|
146
166
|
exports.EdgeStoreProvider = EdgeStoreProvider;
|
|
@@ -39,7 +39,7 @@ function EdgeStoreProvider(options) {
|
|
|
39
39
|
...rest
|
|
40
40
|
};
|
|
41
41
|
},
|
|
42
|
-
async requestUpload ({ bucketName, bucketType, fileInfo }) {
|
|
42
|
+
async requestUpload ({ bucketName, bucketType, fileInfo, autoSignedUrls }) {
|
|
43
43
|
// multipart upload if file is bigger than a certain size
|
|
44
44
|
const MULTIPART_THRESHOLD = 10 * 1024 * 1024; // 10MB
|
|
45
45
|
let partSize = 5 * 1024 * 1024; // 5MB
|
|
@@ -54,6 +54,7 @@ function EdgeStoreProvider(options) {
|
|
|
54
54
|
bucketName,
|
|
55
55
|
bucketType,
|
|
56
56
|
fileInfo,
|
|
57
|
+
autoSignedUrls,
|
|
57
58
|
multipart: {
|
|
58
59
|
parts: Array.from({
|
|
59
60
|
length: totalParts
|
|
@@ -74,13 +75,15 @@ function EdgeStoreProvider(options) {
|
|
|
74
75
|
return {
|
|
75
76
|
accessUrl: res.accessUrl,
|
|
76
77
|
thumbnailUrl: res.thumbnailUrl,
|
|
78
|
+
...mapSignedUploadAccess(res),
|
|
77
79
|
multipart
|
|
78
80
|
};
|
|
79
81
|
} else if (res.signedUrl) {
|
|
80
82
|
return {
|
|
81
83
|
accessUrl: res.accessUrl,
|
|
82
84
|
uploadUrl: res.signedUrl,
|
|
83
|
-
thumbnailUrl: res.thumbnailUrl
|
|
85
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
86
|
+
...mapSignedUploadAccess(res)
|
|
84
87
|
};
|
|
85
88
|
} else {
|
|
86
89
|
throw new EdgeStoreError({
|
|
@@ -92,13 +95,15 @@ function EdgeStoreProvider(options) {
|
|
|
92
95
|
const res = await edgeStoreSdk.requestUpload({
|
|
93
96
|
bucketName,
|
|
94
97
|
bucketType,
|
|
95
|
-
fileInfo
|
|
98
|
+
fileInfo,
|
|
99
|
+
autoSignedUrls
|
|
96
100
|
});
|
|
97
101
|
if (res.signedUrl) {
|
|
98
102
|
return {
|
|
99
103
|
accessUrl: res.accessUrl,
|
|
100
104
|
uploadUrl: res.signedUrl,
|
|
101
|
-
thumbnailUrl: res.thumbnailUrl
|
|
105
|
+
thumbnailUrl: res.thumbnailUrl,
|
|
106
|
+
...mapSignedUploadAccess(res)
|
|
102
107
|
};
|
|
103
108
|
}
|
|
104
109
|
throw new EdgeStoreError({
|
|
@@ -121,6 +126,13 @@ function EdgeStoreProvider(options) {
|
|
|
121
126
|
}
|
|
122
127
|
};
|
|
123
128
|
},
|
|
129
|
+
getSignedUrls: async (params)=>{
|
|
130
|
+
const res = await edgeStoreSdk.getSignedUrls(params);
|
|
131
|
+
return res.map((item)=>({
|
|
132
|
+
...item,
|
|
133
|
+
expiresAt: new Date(item.expiresAt)
|
|
134
|
+
}));
|
|
135
|
+
},
|
|
124
136
|
completeMultipartUpload: async ({ uploadId, key, parts })=>{
|
|
125
137
|
return await edgeStoreSdk.completeMultipartUpload({
|
|
126
138
|
uploadId,
|
|
@@ -140,5 +152,13 @@ function EdgeStoreProvider(options) {
|
|
|
140
152
|
}
|
|
141
153
|
};
|
|
142
154
|
}
|
|
155
|
+
function mapSignedUploadAccess(res) {
|
|
156
|
+
return {
|
|
157
|
+
accessSignedUrl: res.accessSignedUrl,
|
|
158
|
+
accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
|
|
159
|
+
accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt ? new Date(res.accessSignedUrlExpiresAt) : undefined,
|
|
160
|
+
accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
|
|
161
|
+
};
|
|
162
|
+
}
|
|
143
163
|
|
|
144
164
|
export { EdgeStoreProvider };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const SMOKE_CONTENT = "edgestore smoke test";
|
|
2
|
+
export declare function getSmokeApiEndpoint(): string;
|
|
3
|
+
export declare function getSmokeBucketName(): string;
|
|
4
|
+
export declare function getSmokeBasicAuthHeader(): string;
|
|
5
|
+
export declare function createSmokeFileName(prefix: string): string;
|
|
6
|
+
export declare function requireSmokeCredentials(): void;
|
|
7
|
+
export declare function retryUntilSuccess(params: {
|
|
8
|
+
action: () => Promise<{
|
|
9
|
+
success: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
description: string;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
type SmokeFileResult = {
|
|
16
|
+
size: number;
|
|
17
|
+
url: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function runSmokeUploadLifecycle(params: {
|
|
20
|
+
confirmUpload: (url: string) => Promise<{
|
|
21
|
+
success: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
deleteFile: (url: string) => Promise<{
|
|
24
|
+
success: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
deleteDescription: string;
|
|
27
|
+
expectedSize: number;
|
|
28
|
+
getFile?: (url: string) => Promise<SmokeFileResult>;
|
|
29
|
+
upload: () => Promise<SmokeFileResult>;
|
|
30
|
+
}): Promise<SmokeFileResult>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=edgestoreSmoke.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edgestoreSmoke.d.ts","sourceRoot":"","sources":["../../src/test-utils/edgestoreSmoke.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AAEpD,wBAAgB,mBAAmB,WAElC;AAED,wBAAgB,kBAAkB,WAEjC;AAED,wBAAgB,uBAAuB,WAKtC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,UAEjD;AAED,wBAAgB,uBAAuB,SAStC;AAMD,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC9C,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC5C,WAAW,EAAE,MAAM,CAAC;CACrB;aAE4B,OAAO;GAkCnC;AAED,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAuBF,wBAAsB,uBAAuB,CAAC,MAAM,EAAE;IACpD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC9D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC3D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACxC,4BA4BA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,eAAO,MAAM,0BAA0B,UAAU,CAAC"}
|
package/dist/version.js
ADDED
package/dist/version.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Upload files with ease from React/Next.js",
|
|
5
5
|
"homepage": "https://edgestore.dev",
|
|
6
6
|
"license": "MIT",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"!**/__tests__"
|
|
110
110
|
],
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"@edgestore/shared": "0.
|
|
112
|
+
"@edgestore/shared": "0.8.0",
|
|
113
113
|
"@panva/hkdf": "^1.0.4",
|
|
114
114
|
"cookie": "^0.7.0",
|
|
115
115
|
"jose": "^4.13.1",
|
|
@@ -144,6 +144,7 @@
|
|
|
144
144
|
"@types/node": "25.0.3",
|
|
145
145
|
"@types/uuid": "^9.0.1",
|
|
146
146
|
"astro": "^5.7.12",
|
|
147
|
+
"dotenv": "^16.4.7",
|
|
147
148
|
"express": "^4.18.2",
|
|
148
149
|
"fastify": "^5.3.2",
|
|
149
150
|
"hono": "^4.7.9",
|
|
@@ -158,6 +159,14 @@
|
|
|
158
159
|
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
159
160
|
"dev": "pnpm build --watch",
|
|
160
161
|
"codegen:entrypoints": "tsx entrypoints.script.ts",
|
|
162
|
+
"test": "vitest run --config vitest.config.ts",
|
|
163
|
+
"test:smoke": "vitest run --config vitest.smoke.config.ts",
|
|
164
|
+
"test:smoke:dev": "TEST_ENV=dev vitest run --config vitest.smoke.config.ts",
|
|
165
|
+
"test:smoke:prod": "TEST_ENV=prod vitest run --config vitest.smoke.config.ts",
|
|
166
|
+
"test:smoke:adapter": "vitest run --config vitest.smoke.config.ts src/adapters/edgestore.smoke.test.ts",
|
|
167
|
+
"test:smoke:client": "vitest run --config vitest.smoke.config.ts src/core/client/edgestore.smoke.test.ts",
|
|
168
|
+
"test:smoke:errors": "vitest run --config vitest.smoke.config.ts src/core/sdk/edgestore.errors.smoke.test.ts",
|
|
169
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
161
170
|
"lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src"
|
|
162
171
|
}
|
|
163
172
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
completeMultipartUpload,
|
|
15
15
|
confirmUpload,
|
|
16
16
|
deleteFile,
|
|
17
|
+
fetchProxyFile,
|
|
17
18
|
getCookieConfig,
|
|
18
19
|
init,
|
|
19
20
|
requestUpload,
|
|
@@ -89,7 +90,7 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
|
|
|
89
90
|
cause: err instanceof Error ? err : undefined,
|
|
90
91
|
});
|
|
91
92
|
}
|
|
92
|
-
const { newCookies,
|
|
93
|
+
const { newCookies, ...body } = await init({
|
|
93
94
|
ctx,
|
|
94
95
|
provider,
|
|
95
96
|
router: config.router,
|
|
@@ -108,14 +109,7 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
|
|
|
108
109
|
headers.append('Set-Cookie', newCookies);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
return new Response(
|
|
112
|
-
JSON.stringify({
|
|
113
|
-
token,
|
|
114
|
-
baseUrl,
|
|
115
|
-
providerName,
|
|
116
|
-
}),
|
|
117
|
-
{ headers },
|
|
118
|
-
);
|
|
112
|
+
return new Response(JSON.stringify(body), { headers });
|
|
119
113
|
} else if (matchPath(url.pathname, 'request-upload')) {
|
|
120
114
|
const body = (await request.json()) as RequestUploadBody;
|
|
121
115
|
const result = await requestUpload({
|
|
@@ -178,22 +172,18 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
|
|
|
178
172
|
const url = new URL(request.url).searchParams.get('url');
|
|
179
173
|
|
|
180
174
|
if (typeof url === 'string') {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
headers: {
|
|
185
|
-
cookie: cookieHeader,
|
|
186
|
-
},
|
|
175
|
+
const proxyRes = await fetchProxyFile({
|
|
176
|
+
cookieHeader: request.headers.get('cookie') ?? undefined,
|
|
177
|
+
url,
|
|
187
178
|
});
|
|
188
179
|
|
|
189
|
-
const data = await proxyRes.arrayBuffer();
|
|
190
180
|
const headers = new Headers();
|
|
191
|
-
headers.set(
|
|
192
|
-
'Content-Type',
|
|
193
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
194
|
-
);
|
|
181
|
+
headers.set('Content-Type', proxyRes.contentType);
|
|
195
182
|
|
|
196
|
-
return new Response(
|
|
183
|
+
return new Response(proxyRes.body, {
|
|
184
|
+
headers,
|
|
185
|
+
status: proxyRes.status,
|
|
186
|
+
});
|
|
197
187
|
} else {
|
|
198
188
|
return new Response(null, { status: 400 });
|
|
199
189
|
}
|