@edgestore/server 1.0.0-next.5 → 1.0.0-rc.7
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 +2 -2
- package/agent-docs/README.md +1 -1
- package/agent-docs/astro.md +3 -3
- package/agent-docs/backend-client.md +5 -8
- package/agent-docs/express.md +3 -3
- package/agent-docs/fastify.md +3 -3
- package/agent-docs/hono.md +3 -3
- package/agent-docs/next.md +3 -3
- package/agent-docs/provider-azure-blob.md +150 -57
- package/agent-docs/provider-custom.md +29 -3
- package/agent-docs/provider-edgestore.md +2 -2
- package/agent-docs/provider-s3.md +124 -24
- package/agent-docs/remix.md +3 -3
- package/agent-docs/tanstack-start.md +3 -3
- package/dist/adapters/dispatcher.d.ts.map +1 -1
- package/dist/adapters/dispatcher.js +10 -1
- package/dist/adapters/shared.d.ts +25 -103
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +157 -110
- package/dist/core/client/index.d.ts +0 -4
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/provider.d.ts +0 -1
- package/dist/core/provider.d.ts.map +1 -1
- package/dist/core/provider.js +1 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/libs/env.d.ts.map +1 -1
- package/dist/libs/env.js +3 -0
- package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -1
- package/dist/providers/azure-blob/blocks.d.ts +48 -0
- package/dist/providers/azure-blob/blocks.d.ts.map +1 -0
- package/dist/providers/azure-blob/blocks.js +126 -0
- package/dist/providers/azure-blob/index.d.ts +76 -51
- package/dist/providers/azure-blob/index.d.ts.map +1 -1
- package/dist/providers/azure-blob/index.js +189 -107
- package/dist/providers/edgestore/index.d.ts +41 -24
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +33 -20
- package/dist/providers/s3/backendUpload.d.ts +2 -5
- package/dist/providers/s3/backendUpload.d.ts.map +1 -1
- package/dist/providers/s3/backendUpload.js +19 -57
- package/dist/providers/s3/index.d.ts +3 -12
- package/dist/providers/s3/index.d.ts.map +1 -1
- package/dist/providers/s3/index.js +24 -45
- package/dist/providers/s3/multipart.d.ts +3 -5
- package/dist/providers/s3/multipart.d.ts.map +1 -1
- package/dist/providers/s3/multipart.js +26 -62
- package/dist/providers/s3/options.d.ts +13 -35
- package/dist/providers/s3/options.d.ts.map +1 -1
- package/dist/providers/storage/multipartSession.d.ts +51 -0
- package/dist/providers/storage/multipartSession.d.ts.map +1 -0
- package/dist/providers/storage/multipartSession.js +83 -0
- package/dist/providers/storage/objectKeys.d.ts +41 -0
- package/dist/providers/storage/objectKeys.d.ts.map +1 -0
- package/dist/providers/{s3/keys.js → storage/objectKeys.js} +31 -4
- package/dist/providers/storage/transfer.d.ts +18 -0
- package/dist/providers/storage/transfer.d.ts.map +1 -0
- package/dist/providers/storage/transfer.js +69 -0
- 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 +4 -11
- package/src/adapters/dispatcher.ts +14 -0
- package/src/adapters/shared.ts +179 -127
- package/src/core/client/index.ts +0 -4
- package/src/core/provider.ts +0 -8
- package/src/index.ts +3 -8
- package/src/libs/env.ts +9 -0
- package/src/libs/errors/EdgeStoreCredentialsError.ts +1 -1
- package/src/providers/azure-blob/blocks.ts +201 -0
- package/src/providers/azure-blob/index.ts +289 -171
- package/src/providers/edgestore/index.ts +30 -26
- package/src/providers/s3/backendUpload.ts +20 -55
- package/src/providers/s3/index.ts +32 -59
- package/src/providers/s3/multipart.ts +36 -94
- package/src/providers/s3/options.ts +13 -36
- package/src/providers/storage/multipartSession.ts +145 -0
- package/src/providers/storage/objectKeys.ts +106 -0
- package/src/providers/storage/transfer.ts +105 -0
- package/src/test-utils/edgestoreSmoke.ts +3 -5
- package/src/version.ts +1 -1
- package/core/index.d.ts +0 -1
- package/core/index.js +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -3
- package/dist/providers/s3/keys.d.ts +0 -10
- package/dist/providers/s3/keys.d.ts.map +0 -1
- package/src/core/index.ts +0 -9
- package/src/providers/s3/keys.ts +0 -59
|
@@ -1,90 +1,130 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateBlobSASQueryParameters, SASProtocol, BlobSASPermissions, StorageSharedKeyCredential, BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
+
import { planMultipartUpload } from '@edgestore/sdk';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { defineProvider } from '../../core/provider.js';
|
|
4
5
|
import { getEnv } from '../../libs/env.js';
|
|
6
|
+
import { createMultipartSessions } from '../storage/multipartSession.js';
|
|
7
|
+
import { createObjectKeys } from '../storage/objectKeys.js';
|
|
8
|
+
import { runConcurrently, assertSignedUrlAccessControl, signedUrlLifetime } from '../storage/transfer.js';
|
|
9
|
+
import { createBlockUploads, uploadBlob } from './blocks.js';
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
const MiB = 1024 ** 2;
|
|
12
|
+
/** Largest single Put Blob request. */ const MAX_SINGLE_UPLOAD_BYTES = 5000 * MiB;
|
|
13
|
+
/** Largest Put Block request. */ const MAX_BLOCK_BYTES = 4000 * MiB;
|
|
14
|
+
const expiration = (value)=>signedUrlLifetime('Azure Blob', value);
|
|
15
|
+
function azureBlob(options = {}) {
|
|
16
|
+
const { storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'), storageAccountKey = getEnv('ES_AZURE_ACCOUNT_KEY'), containerName = getEnv('ES_AZURE_CONTAINER_NAME') } = options;
|
|
17
|
+
const endpoint = (options.endpoint ?? getEnv('ES_AZURE_ENDPOINT') ?? `https://${storageAccountName}.blob.core.windows.net`).replace(/\/+$/, '');
|
|
18
|
+
const baseUrl = options.baseUrl ?? getEnv('EDGESTORE_BASE_URL') ?? `${endpoint}/${containerName}`;
|
|
19
|
+
const keys = createObjectKeys('Azure Blob', baseUrl);
|
|
20
|
+
const uploadExpiresIn = expiration(options.uploadUrlExpiresIn ?? 3600);
|
|
21
|
+
const readExpiresIn = expiration(options.signedUrlExpiresIn ?? 3600);
|
|
22
|
+
function plan(sizeBytes) {
|
|
23
|
+
if (!Number.isSafeInteger(sizeBytes) || sizeBytes < 0) throw new RangeError('Azure Blob upload size must be a nonnegative safe integer.');
|
|
24
|
+
const result = planMultipartUpload({
|
|
25
|
+
sizeBytes,
|
|
26
|
+
thresholdBytes: options.multipart?.thresholdBytes,
|
|
27
|
+
preferredPartSizeBytes: options.multipart?.partSizeBytes,
|
|
28
|
+
forceMultipart: sizeBytes > MAX_SINGLE_UPLOAD_BYTES
|
|
29
|
+
});
|
|
30
|
+
if (result && result.partSizeBytes > MAX_BLOCK_BYTES) throw new RangeError('Azure blocks cannot exceed 4000 MiB.');
|
|
31
|
+
return result;
|
|
10
32
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
// Validate multipart settings even before the first large upload.
|
|
34
|
+
plan(0);
|
|
35
|
+
// Credentials are resolved on first use, so defining a router needs none.
|
|
36
|
+
let resolved;
|
|
37
|
+
function storage() {
|
|
38
|
+
if (!storageAccountName || !storageAccountKey || !containerName) {
|
|
39
|
+
throw new Error('Azure Blob requires storageAccountName, storageAccountKey, and containerName (or ES_AZURE_ACCOUNT_NAME, ES_AZURE_ACCOUNT_KEY, and ES_AZURE_CONTAINER_NAME).');
|
|
40
|
+
}
|
|
41
|
+
if (!resolved) {
|
|
42
|
+
const credential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);
|
|
43
|
+
resolved = {
|
|
44
|
+
containerName,
|
|
45
|
+
credential,
|
|
46
|
+
container: new BlobServiceClient(endpoint, credential).getContainerClient(containerName)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return resolved;
|
|
16
50
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
permissions: BlobSASPermissions.parse(params.permissions),
|
|
28
|
-
protocol: baseUrl.startsWith('https:') ? SASProtocol.Https : SASProtocol.HttpsAndHttp,
|
|
51
|
+
const blob = (key)=>storage().container.getBlockBlobClient(key);
|
|
52
|
+
function sas(key, permissions, expiresIn) {
|
|
53
|
+
const expiresAt = new Date(Date.now() + expiresIn * 1000);
|
|
54
|
+
const { containerName: container, credential } = storage();
|
|
55
|
+
const query = generateBlobSASQueryParameters({
|
|
56
|
+
containerName: container,
|
|
57
|
+
blobName: key,
|
|
58
|
+
permissions: BlobSASPermissions.parse(permissions),
|
|
59
|
+
protocol: endpoint.startsWith('https:') ? SASProtocol.Https : SASProtocol.HttpsAndHttp,
|
|
60
|
+
// Tolerate clock skew between this server and Azure.
|
|
29
61
|
startsOn: new Date(Date.now() - 5 * 60 * 1000),
|
|
30
62
|
expiresOn: expiresAt
|
|
31
|
-
},
|
|
32
|
-
const blobClient = containerClient.getBlobClient(params.blobName);
|
|
63
|
+
}, credential).toString();
|
|
33
64
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
expiresAt,
|
|
37
|
-
expiresIn: params.expiresIn
|
|
65
|
+
query,
|
|
66
|
+
expiresAt
|
|
38
67
|
};
|
|
39
68
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
throw new Error();
|
|
50
|
-
}
|
|
51
|
-
return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
|
|
52
|
-
} catch {
|
|
53
|
-
throw new Error('File URL does not belong to this Azure Blob provider.');
|
|
54
|
-
}
|
|
69
|
+
function signedRead(key, expiresIn = readExpiresIn) {
|
|
70
|
+
const ttl = expiration(expiresIn);
|
|
71
|
+
const { query, expiresAt } = sas(key, 'r', ttl);
|
|
72
|
+
return {
|
|
73
|
+
url: keys.toUrl(key),
|
|
74
|
+
signedUrl: `${blob(key).url}?${query}`,
|
|
75
|
+
expiresAt,
|
|
76
|
+
expiresIn: ttl
|
|
77
|
+
};
|
|
55
78
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new Error(`File does not belong to EdgeStore bucket "${edgestoreBucketName}".`);
|
|
60
|
-
}
|
|
61
|
-
return blobName;
|
|
79
|
+
function readForUpload(key, params) {
|
|
80
|
+
if (params.fileInfo.isPublic || !params.autoSignedUrls) return undefined;
|
|
81
|
+
return signedRead(key, params.autoSignedUrls.expiresIn);
|
|
62
82
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
const blocks = createBlockUploads({
|
|
84
|
+
blob,
|
|
85
|
+
sessions: createMultipartSessions({
|
|
86
|
+
providerName: 'Azure Blob',
|
|
87
|
+
audience: `edgestore:azure-blob:${endpoint}:${containerName}`,
|
|
88
|
+
secret: options.jwtSecret,
|
|
89
|
+
expiresIn: options.multipart?.sessionExpiresIn ?? 86400
|
|
90
|
+
}),
|
|
91
|
+
signPartUrl: (key, id)=>`${blob(key).url}?comp=block&blockid=${encodeURIComponent(id)}&${sas(key, 'w', uploadExpiresIn).query}`
|
|
92
|
+
});
|
|
93
|
+
async function prepare({ bucketName, fileInfo }) {
|
|
94
|
+
const { key, pathArgs } = await keys.forUpload(bucketName, fileInfo, options.path);
|
|
95
|
+
const objectOptions = typeof options.objectOptions === 'function' ? await options.objectOptions(pathArgs) : options.objectOptions;
|
|
96
|
+
const commit = {
|
|
97
|
+
blobHTTPHeaders: {
|
|
98
|
+
blobContentType: fileInfo.type || 'application/octet-stream',
|
|
99
|
+
blobCacheControl: objectOptions?.cacheControl,
|
|
100
|
+
blobContentDisposition: objectOptions?.contentDisposition
|
|
101
|
+
},
|
|
102
|
+
metadata: objectOptions?.metadata
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
key,
|
|
106
|
+
commit,
|
|
107
|
+
plan: plan(fileInfo.size)
|
|
108
|
+
};
|
|
75
109
|
}
|
|
76
110
|
return defineProvider({
|
|
77
111
|
name: 'azure-blob',
|
|
78
|
-
baseUrl,
|
|
79
112
|
reference: {
|
|
80
|
-
schema: z.
|
|
81
|
-
|
|
82
|
-
|
|
113
|
+
schema: z.union([
|
|
114
|
+
z.object({
|
|
115
|
+
key: z.string().min(1)
|
|
116
|
+
}),
|
|
117
|
+
z.object({
|
|
118
|
+
url: z.string().url()
|
|
119
|
+
})
|
|
120
|
+
]),
|
|
83
121
|
fromUrl: (url)=>({
|
|
84
122
|
url
|
|
85
123
|
})
|
|
86
124
|
},
|
|
87
|
-
async init () {
|
|
125
|
+
async init ({ router }) {
|
|
126
|
+
storage();
|
|
127
|
+
assertSignedUrlAccessControl('Azure Blob', router);
|
|
88
128
|
return {};
|
|
89
129
|
},
|
|
90
130
|
uploads: {
|
|
@@ -93,62 +133,86 @@ function azureBlob(options) {
|
|
|
93
133
|
replaceTargetUrl: false
|
|
94
134
|
},
|
|
95
135
|
async request (params) {
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
136
|
+
const { key, commit, plan } = await prepare(params);
|
|
137
|
+
const signedReadUrl = readForUpload(key, params);
|
|
138
|
+
const access = {
|
|
139
|
+
key,
|
|
140
|
+
url: keys.toUrl(key),
|
|
141
|
+
...signedReadUrl ? {
|
|
142
|
+
signedReadUrl
|
|
143
|
+
} : {}
|
|
144
|
+
};
|
|
145
|
+
if (plan) {
|
|
146
|
+
return {
|
|
147
|
+
...access,
|
|
148
|
+
multipart: await blocks.request({
|
|
149
|
+
key,
|
|
150
|
+
size: params.fileInfo.size,
|
|
151
|
+
plan,
|
|
152
|
+
commit
|
|
153
|
+
})
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
...access,
|
|
158
|
+
uploadUrl: `${blob(key).url}?${sas(key, 'cw', uploadExpiresIn).query}`,
|
|
159
|
+
uploadHeaders: blobUploadHeaders(commit)
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
multipart: blocks.operations,
|
|
163
|
+
async upload (params) {
|
|
164
|
+
const { key, commit, plan } = await prepare({
|
|
165
|
+
...params,
|
|
166
|
+
fileInfo: {
|
|
167
|
+
...params.fileInfo,
|
|
168
|
+
size: params.source.size,
|
|
169
|
+
type: params.source.type || params.fileInfo.type
|
|
170
|
+
}
|
|
101
171
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
172
|
+
// Sign before sending bytes: nothing fallible runs after the commit.
|
|
173
|
+
const signedReadUrl = readForUpload(key, params);
|
|
174
|
+
await uploadBlob({
|
|
175
|
+
client: blob(key),
|
|
176
|
+
commit,
|
|
177
|
+
plan,
|
|
178
|
+
source: params.source,
|
|
179
|
+
signal: params.signal,
|
|
180
|
+
onProgress: params.onProgress
|
|
106
181
|
});
|
|
182
|
+
const uploadedAt = new Date();
|
|
107
183
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
184
|
+
file: {
|
|
185
|
+
key,
|
|
186
|
+
url: keys.toUrl(key),
|
|
187
|
+
sizeBytes: params.source.size,
|
|
188
|
+
uploadedAt,
|
|
189
|
+
updatedAt: uploadedAt
|
|
111
190
|
},
|
|
112
|
-
|
|
113
|
-
accessSignedUrl: readAccess?.signedUrl,
|
|
114
|
-
accessSignedUrlExpiresAt: readAccess?.expiresAt,
|
|
115
|
-
accessSignedUrlExpiresIn: readAccess?.expiresIn
|
|
191
|
+
signedReadUrl
|
|
116
192
|
};
|
|
117
193
|
}
|
|
118
194
|
},
|
|
119
195
|
files: {
|
|
120
196
|
async get ({ bucketName, file }) {
|
|
121
|
-
const
|
|
122
|
-
const { contentLength, lastModified } = await
|
|
123
|
-
|
|
197
|
+
const key = keys.fromReference(bucketName, file);
|
|
198
|
+
const { contentLength, lastModified } = await blob(key).getProperties();
|
|
199
|
+
if (contentLength === undefined || !lastModified) throw new Error('File not found');
|
|
124
200
|
return {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
201
|
+
key,
|
|
202
|
+
url: keys.toUrl(key),
|
|
203
|
+
sizeBytes: contentLength,
|
|
204
|
+
uploadedAt: lastModified,
|
|
205
|
+
updatedAt: lastModified
|
|
129
206
|
};
|
|
130
207
|
},
|
|
131
208
|
async getSignedUrls ({ bucketName, files, expiresIn }) {
|
|
132
|
-
return files.map((file)=>
|
|
133
|
-
const access = createSignedBlobUrl({
|
|
134
|
-
blobName: getBucketBlobName(bucketName, file.url),
|
|
135
|
-
permissions: 'r',
|
|
136
|
-
expiresIn: expiresIn ?? signedUrlExpiresIn
|
|
137
|
-
});
|
|
138
|
-
return {
|
|
139
|
-
url: access.url,
|
|
140
|
-
signedUrl: access.signedUrl,
|
|
141
|
-
expiresAt: access.expiresAt,
|
|
142
|
-
expiresIn: access.expiresIn
|
|
143
|
-
};
|
|
144
|
-
});
|
|
209
|
+
return files.map((file)=>signedRead(keys.fromReference(bucketName, file), expiresIn));
|
|
145
210
|
},
|
|
146
211
|
async delete ({ bucketName, files }) {
|
|
147
|
-
const
|
|
148
|
-
const results = await
|
|
212
|
+
const blobKeys = files.map((file)=>keys.fromReference(bucketName, file));
|
|
213
|
+
const results = await runConcurrently(blobKeys, undefined, async (key)=>{
|
|
149
214
|
try {
|
|
150
|
-
|
|
151
|
-
await blobClient.delete();
|
|
215
|
+
await blob(key).deleteIfExists();
|
|
152
216
|
return {
|
|
153
217
|
success: true
|
|
154
218
|
};
|
|
@@ -161,7 +225,7 @@ function azureBlob(options) {
|
|
|
161
225
|
}
|
|
162
226
|
};
|
|
163
227
|
}
|
|
164
|
-
})
|
|
228
|
+
});
|
|
165
229
|
return {
|
|
166
230
|
results
|
|
167
231
|
};
|
|
@@ -169,5 +233,23 @@ function azureBlob(options) {
|
|
|
169
233
|
}
|
|
170
234
|
});
|
|
171
235
|
}
|
|
236
|
+
/** Headers a browser Put Blob request must send to apply the blob settings. */ function blobUploadHeaders({ blobHTTPHeaders, metadata }) {
|
|
237
|
+
const headers = {
|
|
238
|
+
'x-ms-blob-type': 'BlockBlob'
|
|
239
|
+
};
|
|
240
|
+
const fields = {
|
|
241
|
+
blobContentType: 'x-ms-blob-content-type',
|
|
242
|
+
blobCacheControl: 'x-ms-blob-cache-control',
|
|
243
|
+
blobContentDisposition: 'x-ms-blob-content-disposition'
|
|
244
|
+
};
|
|
245
|
+
for (const [field, header] of Object.entries(fields)){
|
|
246
|
+
const value = blobHTTPHeaders[field];
|
|
247
|
+
if (value !== undefined) headers[header] = value;
|
|
248
|
+
}
|
|
249
|
+
for (const [name, value] of Object.entries(metadata ?? {})){
|
|
250
|
+
headers[`x-ms-meta-${name}`] = value;
|
|
251
|
+
}
|
|
252
|
+
return headers;
|
|
253
|
+
}
|
|
172
254
|
|
|
173
255
|
export { azureBlob };
|
|
@@ -9,14 +9,14 @@ type EdgeStoreProjectProviderOptions = {
|
|
|
9
9
|
* Access key for your EdgeStore project.
|
|
10
10
|
* Can be found in the EdgeStore dashboard.
|
|
11
11
|
*
|
|
12
|
-
* This can be omitted if the `
|
|
12
|
+
* This can be omitted if the `EDGESTORE_ACCESS_KEY` environment variable is set.
|
|
13
13
|
*/
|
|
14
14
|
accessKey?: string;
|
|
15
15
|
/**
|
|
16
16
|
* Secret key for your EdgeStore project.
|
|
17
17
|
* Can be found in the EdgeStore dashboard.
|
|
18
18
|
*
|
|
19
|
-
* This can be omitted if the `
|
|
19
|
+
* This can be omitted if the `EDGESTORE_SECRET_KEY` environment variable is set.
|
|
20
20
|
*/
|
|
21
21
|
secretKey?: string;
|
|
22
22
|
token?: never;
|
|
@@ -33,27 +33,14 @@ type EdgeStoreBearerProviderOptions = {
|
|
|
33
33
|
export type EdgeStoreProviderOptions = EdgeStoreProviderCommonOptions & (EdgeStoreProjectProviderOptions | EdgeStoreBearerProviderOptions);
|
|
34
34
|
export declare function edgestore(options?: EdgeStoreProviderOptions): {
|
|
35
35
|
readonly name: "edgestore";
|
|
36
|
-
readonly baseUrl: string;
|
|
37
36
|
readonly reference: {
|
|
38
|
-
readonly schema: z.
|
|
37
|
+
readonly schema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
39
38
|
id: z.ZodString;
|
|
40
|
-
},
|
|
41
|
-
id: string;
|
|
42
|
-
}, {
|
|
43
|
-
id: string;
|
|
44
|
-
}>, z.ZodObject<{
|
|
39
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
45
40
|
key: z.ZodString;
|
|
46
|
-
},
|
|
47
|
-
key: string;
|
|
48
|
-
}, {
|
|
49
|
-
key: string;
|
|
50
|
-
}>, z.ZodObject<{
|
|
41
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
51
42
|
url: z.ZodString;
|
|
52
|
-
},
|
|
53
|
-
url: string;
|
|
54
|
-
}, {
|
|
55
|
-
url: string;
|
|
56
|
-
}>]>, {
|
|
43
|
+
}, z.core.$strip>]>, z.ZodTransform<{
|
|
57
44
|
id: string;
|
|
58
45
|
} | {
|
|
59
46
|
key: string;
|
|
@@ -65,22 +52,19 @@ export declare function edgestore(options?: EdgeStoreProviderOptions): {
|
|
|
65
52
|
key: string;
|
|
66
53
|
} | {
|
|
67
54
|
url: string;
|
|
68
|
-
}
|
|
55
|
+
}>>;
|
|
69
56
|
readonly fromUrl: (url: string) => {
|
|
70
57
|
url: string;
|
|
71
58
|
};
|
|
72
59
|
};
|
|
73
60
|
readonly init: <TCtx extends import("@edgestore/shared").AnyContext>({ ctx, router }: import("@edgestore/shared").InitParams<TCtx>) => Promise<{
|
|
74
|
-
baseUrl?: undefined;
|
|
75
61
|
clientInit?: undefined;
|
|
76
62
|
} | {
|
|
77
|
-
baseUrl: string;
|
|
78
63
|
clientInit: {
|
|
79
|
-
|
|
64
|
+
urls: string[];
|
|
80
65
|
headers: {
|
|
81
66
|
'x-edgestore-token': string;
|
|
82
67
|
};
|
|
83
|
-
urls?: string[] | undefined;
|
|
84
68
|
};
|
|
85
69
|
}>;
|
|
86
70
|
readonly uploads: {
|
|
@@ -95,6 +79,39 @@ export declare function edgestore(options?: EdgeStoreProviderOptions): {
|
|
|
95
79
|
readonly complete: ({ uploadId, parts }: import("@edgestore/shared").CompleteMultipartUploadParams) => Promise<void>;
|
|
96
80
|
readonly abort: ({ uploadId }: import("@edgestore/shared").MultipartUploadSession) => Promise<void>;
|
|
97
81
|
};
|
|
82
|
+
readonly getStatus: ({ id }: {
|
|
83
|
+
bucketName: string;
|
|
84
|
+
id: string;
|
|
85
|
+
}) => Promise<{
|
|
86
|
+
status: "completed";
|
|
87
|
+
file: {
|
|
88
|
+
id: string;
|
|
89
|
+
url: string;
|
|
90
|
+
key: string;
|
|
91
|
+
thumbnailUrl: string | null;
|
|
92
|
+
thumbnailKey: string | null;
|
|
93
|
+
bucketId: string;
|
|
94
|
+
bucketName: string;
|
|
95
|
+
projectId: string;
|
|
96
|
+
accountId: string;
|
|
97
|
+
name: string;
|
|
98
|
+
path: {
|
|
99
|
+
[key: string]: string;
|
|
100
|
+
};
|
|
101
|
+
metadata: {
|
|
102
|
+
[key: string]: string;
|
|
103
|
+
};
|
|
104
|
+
sizeBytes: number;
|
|
105
|
+
mimeType: string | null;
|
|
106
|
+
state: "requested" | "uploaded" | "deleted" | "replace_requested";
|
|
107
|
+
temporary: boolean;
|
|
108
|
+
uploadedAt: string;
|
|
109
|
+
updatedAt: string;
|
|
110
|
+
};
|
|
111
|
+
} | {
|
|
112
|
+
status: "processing" | "canceled";
|
|
113
|
+
file?: undefined;
|
|
114
|
+
}>;
|
|
98
115
|
readonly upload: ({ bucketName, bucketType, fileInfo, autoSignedUrls, source, signal, onProgress, }: import("@edgestore/shared").BackendUploadParams) => Promise<{
|
|
99
116
|
file: ProviderFile;
|
|
100
117
|
signedReadUrl: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,KAAK,8BAA8B,GAAG;IACpC,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,+BAA+B,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,GACnE,CAAC,+BAA+B,GAAG,8BAA8B,CAAC,CAAC;AAErE,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,wBAAwB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAqBxB,KAAK,8BAA8B,GAAG;IACpC,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,+BAA+B,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,GACnE,CAAC,+BAA+B,GAAG,8BAA8B,CAAC,CAAC;AAErE,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0GAgElD,OAAO,CAAC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6JlC;AAED,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -21,11 +21,9 @@ const fileReferenceSchema = z.union([
|
|
|
21
21
|
url: reference
|
|
22
22
|
} : reference);
|
|
23
23
|
function edgestore(options) {
|
|
24
|
-
const baseUrl = getEnv('EDGE_STORE_BASE_URL') ?? DEFAULT_BASE_URL;
|
|
25
24
|
const runtime = createProviderRuntime(options);
|
|
26
25
|
const provider = defineProvider({
|
|
27
26
|
name: 'edgestore',
|
|
28
|
-
baseUrl,
|
|
29
27
|
reference: {
|
|
30
28
|
schema: fileReferenceSchema,
|
|
31
29
|
fromUrl: (url)=>({
|
|
@@ -58,14 +56,12 @@ function edgestore(options) {
|
|
|
58
56
|
}
|
|
59
57
|
]))
|
|
60
58
|
});
|
|
61
|
-
const overrideBaseUrl = getEnv('
|
|
59
|
+
const overrideBaseUrl = getEnv('EDGESTORE_BASE_URL');
|
|
62
60
|
return {
|
|
63
|
-
baseUrl: overrideBaseUrl ?? delivery?.baseUrl ?? baseUrl,
|
|
64
61
|
clientInit: {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
path: '/_init',
|
|
62
|
+
urls: delivery && !overrideBaseUrl ? delivery.initUrls : [
|
|
63
|
+
`${(overrideBaseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, '')}/_init`
|
|
64
|
+
],
|
|
69
65
|
headers: {
|
|
70
66
|
'x-edgestore-token': token
|
|
71
67
|
}
|
|
@@ -110,7 +106,18 @@ function edgestore(options) {
|
|
|
110
106
|
complete: async ({ uploadId, parts })=>{
|
|
111
107
|
await runtime.uploads.completeMultipart({
|
|
112
108
|
uploadId,
|
|
113
|
-
parts
|
|
109
|
+
parts: parts.map(({ partNumber, eTag })=>{
|
|
110
|
+
if (!eTag) {
|
|
111
|
+
throw new EdgeStoreError({
|
|
112
|
+
message: `Multipart part ${partNumber} is missing its ETag.`,
|
|
113
|
+
code: 'BAD_REQUEST'
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
partNumber,
|
|
118
|
+
eTag
|
|
119
|
+
};
|
|
120
|
+
})
|
|
114
121
|
});
|
|
115
122
|
},
|
|
116
123
|
abort: async ({ uploadId })=>{
|
|
@@ -119,6 +126,17 @@ function edgestore(options) {
|
|
|
119
126
|
});
|
|
120
127
|
}
|
|
121
128
|
},
|
|
129
|
+
getStatus: async ({ id })=>{
|
|
130
|
+
const result = await runtime.uploads.get({
|
|
131
|
+
uploadId: id
|
|
132
|
+
});
|
|
133
|
+
return 'file' in result ? {
|
|
134
|
+
status: 'completed',
|
|
135
|
+
file: result.file
|
|
136
|
+
} : {
|
|
137
|
+
status: result.upload.status
|
|
138
|
+
};
|
|
139
|
+
},
|
|
122
140
|
upload: async ({ bucketName, bucketType, fileInfo, autoSignedUrls, source, signal, onProgress })=>{
|
|
123
141
|
const result = await runtime.uploads.upload({
|
|
124
142
|
bucket: bucketName,
|
|
@@ -237,10 +255,8 @@ function resolveProviderAuthentication(options) {
|
|
|
237
255
|
if (project !== undefined) {
|
|
238
256
|
throw new TypeError('EdgeStore provider option `project` requires a Bearer token.');
|
|
239
257
|
}
|
|
240
|
-
const accessKey = configuredAccessKey ?? getEnv('
|
|
241
|
-
|
|
242
|
-
const secretKey = configuredSecretKey ?? getEnv('EDGE_STORE_SECRET_KEY') ?? // @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
243
|
-
import.meta.env?.EDGE_STORE_SECRET_KEY;
|
|
258
|
+
const accessKey = configuredAccessKey ?? getEnv('EDGESTORE_ACCESS_KEY');
|
|
259
|
+
const secretKey = configuredSecretKey ?? getEnv('EDGESTORE_SECRET_KEY');
|
|
244
260
|
if (typeof accessKey !== 'string' || !accessKey.trim() || typeof secretKey !== 'string' || !secretKey.trim()) {
|
|
245
261
|
throw new EdgeStoreCredentialsError();
|
|
246
262
|
}
|
|
@@ -266,7 +282,7 @@ function mapMutationResult(result) {
|
|
|
266
282
|
};
|
|
267
283
|
}
|
|
268
284
|
function getApiUrl() {
|
|
269
|
-
const configured = getEnv('
|
|
285
|
+
const configured = getEnv('EDGESTORE_API_ENDPOINT');
|
|
270
286
|
if (!configured) return undefined;
|
|
271
287
|
const base = configured.replace(/\/+$/, '');
|
|
272
288
|
return base.endsWith('/v2') ? base : `${base}/v2`;
|
|
@@ -297,15 +313,12 @@ function mapRawUploadRequest(bucketType, fileInfo, signedReadUrl) {
|
|
|
297
313
|
};
|
|
298
314
|
}
|
|
299
315
|
function mapUploadResponse(res, multipartConfig) {
|
|
300
|
-
const signed = res.signedReadUrl;
|
|
301
316
|
const access = {
|
|
317
|
+
id: res.file.id,
|
|
302
318
|
key: res.file.key,
|
|
303
|
-
|
|
319
|
+
url: res.file.url,
|
|
304
320
|
thumbnailUrl: res.file.thumbnailUrl,
|
|
305
|
-
|
|
306
|
-
accessSignedThumbnailUrl: signed?.signedThumbnailUrl,
|
|
307
|
-
accessSignedUrlExpiresAt: signed?.expiresAt,
|
|
308
|
-
accessSignedUrlExpiresIn: signed?.expiresIn
|
|
321
|
+
signedReadUrl: res.signedReadUrl
|
|
309
322
|
};
|
|
310
323
|
if (res.upload.kind === 'single') {
|
|
311
324
|
return {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { type PutObjectCommandInput, type S3Client } from '@aws-sdk/client-s3';
|
|
2
|
-
import {
|
|
2
|
+
import type { MultipartUploadPlan } from '@edgestore/sdk';
|
|
3
3
|
import type { BackendUploadParams } from '@edgestore/shared';
|
|
4
|
-
/**
|
|
5
|
-
* Uploads with the configured S3 client, which owns request retries. Multipart
|
|
6
|
-
* parts are read and sent a few at a time to bound memory use.
|
|
7
|
-
*/
|
|
4
|
+
/** Uploads with the configured S3 client, which owns request retries. */
|
|
8
5
|
export declare function uploadObject({ client, input, source, plan, signal, onProgress, }: {
|
|
9
6
|
client: S3Client;
|
|
10
7
|
input: PutObjectCommandInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backendUpload.d.ts","sourceRoot":"","sources":["../../../src/providers/s3/backendUpload.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"backendUpload.d.ts","sourceRoot":"","sources":["../../../src/providers/s3/backendUpload.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,yEAAyE;AACzE,wBAAsB,YAAY,CAAC,EACjC,MAAM,EACN,KAAK,EACL,MAAM,EACN,IAAI,EACJ,MAAM,EACN,UAAU,GACX,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC;IACjB,KAAK,EAAE,qBAAqB,CAAC;IAC7B,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAClC,GAAG,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAC,iBAwDhE"}
|