@edgestore/server 1.0.0-rc.6 → 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 +2 -2
- package/agent-docs/express.md +2 -2
- package/agent-docs/fastify.md +2 -2
- package/agent-docs/hono.md +2 -2
- package/agent-docs/next.md +2 -2
- package/agent-docs/provider-azure-blob.md +14 -14
- package/agent-docs/provider-custom.md +12 -0
- package/agent-docs/provider-edgestore.md +2 -2
- package/agent-docs/provider-s3.md +119 -20
- package/agent-docs/remix.md +2 -2
- package/agent-docs/tanstack-start.md +2 -2
- package/dist/adapters/dispatcher.d.ts.map +1 -1
- package/dist/adapters/dispatcher.js +10 -1
- package/dist/adapters/shared.d.ts +13 -1
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +96 -4
- 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/index.d.ts +2 -2
- package/dist/providers/azure-blob/index.js +1 -1
- package/dist/providers/edgestore/index.d.ts +35 -2
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +16 -4
- package/dist/providers/s3/index.js +1 -1
- package/dist/providers/s3/options.d.ts +3 -3
- package/dist/providers/storage/multipartSession.js +2 -2
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/adapters/dispatcher.ts +14 -0
- package/src/adapters/shared.ts +100 -2
- package/src/libs/env.ts +9 -0
- package/src/libs/errors/EdgeStoreCredentialsError.ts +1 -1
- package/src/providers/azure-blob/index.ts +3 -3
- package/src/providers/edgestore/index.ts +13 -6
- package/src/providers/s3/index.ts +1 -1
- package/src/providers/s3/options.ts +3 -3
- package/src/providers/storage/multipartSession.ts +3 -3
- package/src/test-utils/edgestoreSmoke.ts +3 -5
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ npm install @edgestore/server @edgestore/react
|
|
|
19
19
|
Then go to your [Dashboard](https://dashboard.edgestore.dev), create a new project and copy the keys to your environment variables.
|
|
20
20
|
|
|
21
21
|
```shell title=".env"
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
23
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### Backend
|
package/agent-docs/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @edgestore/server 1.0.0-rc.
|
|
1
|
+
# @edgestore/server 1.0.0-rc.7: agent references
|
|
2
2
|
|
|
3
3
|
These references ship with this exact package version. Prefer them over newer online examples.
|
|
4
4
|
Generated from the authored documentation; do not edit these files directly.
|
package/agent-docs/astro.md
CHANGED
|
@@ -22,8 +22,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
22
22
|
Example: title=".env"
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
26
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
> WARNING
|
package/agent-docs/express.md
CHANGED
|
@@ -19,8 +19,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
19
19
|
Example: title=".env"
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
23
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
> WARNING
|
package/agent-docs/fastify.md
CHANGED
|
@@ -19,8 +19,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
19
19
|
Example: title=".env"
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
23
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
> WARNING
|
package/agent-docs/hono.md
CHANGED
|
@@ -21,8 +21,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
21
21
|
Example: title=".env.local (backend only)"
|
|
22
22
|
|
|
23
23
|
```sh
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
25
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
> WARNING
|
package/agent-docs/next.md
CHANGED
|
@@ -17,8 +17,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
17
17
|
Example: title=".env.local"
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
21
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
> WARNING
|
|
@@ -39,24 +39,24 @@ export type EdgeStoreRouter = typeof router;
|
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Pass `router` to your framework adapter as its `router` option. Set
|
|
42
|
-
`ES_AZURE_ACCOUNT_KEY` on the server, and set `
|
|
42
|
+
`ES_AZURE_ACCOUNT_KEY` on the server, and set `EDGESTORE_JWT_SECRET` to a
|
|
43
43
|
stable random secret, for example one generated with `openssl rand -base64 32`.
|
|
44
44
|
All application instances must share it. Credentials are only checked when the
|
|
45
45
|
provider is first used, so defining a router does not require them.
|
|
46
46
|
|
|
47
|
-
| Option | Default / environment variable
|
|
48
|
-
| ---------------------------- |
|
|
49
|
-
| `storageAccountName` | `ES_AZURE_ACCOUNT_NAME`
|
|
50
|
-
| `storageAccountKey` | `ES_AZURE_ACCOUNT_KEY`
|
|
51
|
-
| `containerName` | `ES_AZURE_CONTAINER_NAME`
|
|
52
|
-
| `endpoint` | `ES_AZURE_ENDPOINT`, otherwise `https://<account>.blob.core.windows.net`
|
|
53
|
-
| `baseUrl` | `
|
|
54
|
-
| `uploadUrlExpiresIn` | 3600 seconds
|
|
55
|
-
| `signedUrlExpiresIn` | 3600 seconds
|
|
56
|
-
| `multipart.thresholdBytes` | 100 MiB
|
|
57
|
-
| `multipart.partSizeBytes` | 16 MiB; minimum 5 MiB, maximum 4000 MiB
|
|
58
|
-
| `multipart.sessionExpiresIn` | 86400 seconds
|
|
59
|
-
| `jwtSecret` | Multipart signing override; otherwise `
|
|
47
|
+
| Option | Default / environment variable |
|
|
48
|
+
| ---------------------------- | -------------------------------------------------------------------------------------- |
|
|
49
|
+
| `storageAccountName` | `ES_AZURE_ACCOUNT_NAME` |
|
|
50
|
+
| `storageAccountKey` | `ES_AZURE_ACCOUNT_KEY` |
|
|
51
|
+
| `containerName` | `ES_AZURE_CONTAINER_NAME` |
|
|
52
|
+
| `endpoint` | `ES_AZURE_ENDPOINT`, otherwise `https://<account>.blob.core.windows.net` |
|
|
53
|
+
| `baseUrl` | `EDGESTORE_BASE_URL`, otherwise `<endpoint>/<container>` |
|
|
54
|
+
| `uploadUrlExpiresIn` | 3600 seconds |
|
|
55
|
+
| `signedUrlExpiresIn` | 3600 seconds |
|
|
56
|
+
| `multipart.thresholdBytes` | 100 MiB |
|
|
57
|
+
| `multipart.partSizeBytes` | 16 MiB; minimum 5 MiB, maximum 4000 MiB |
|
|
58
|
+
| `multipart.sessionExpiresIn` | 86400 seconds |
|
|
59
|
+
| `jwtSecret` | Multipart signing override; otherwise `EDGESTORE_JWT_SECRET` or `EDGESTORE_SECRET_KEY` |
|
|
60
60
|
|
|
61
61
|
Signed URL lifetimes must be between 1 and 604800 seconds. Upload URLs grant
|
|
62
62
|
only create/write permission on one blob, and read URLs grant only read
|
|
@@ -265,6 +265,18 @@ A single-part plan can include `uploadHeaders`. The browser sends them with the
|
|
|
265
265
|
upload request, which lets a provider sign headers such as `Content-Type` or
|
|
266
266
|
storage metadata into the URL.
|
|
267
267
|
|
|
268
|
+
Return `id` from `uploads.request` when your storage assigns stable file IDs.
|
|
269
|
+
The browser upload result includes it so apps can save it.
|
|
270
|
+
|
|
271
|
+
If your storage processes files after the transfer, return `id` and implement
|
|
272
|
+
`uploads.getStatus({ bucketName, id })`. It returns
|
|
273
|
+
`{ status: 'processing' }`, `{ status: 'canceled' }`, or
|
|
274
|
+
`{ status: 'completed', file }` with the processed `url`, `key`,
|
|
275
|
+
`thumbnailUrl`, and `sizeBytes`. Browser uploads with `waitForProcessing` poll
|
|
276
|
+
it through an encrypted status token that only the uploading browser receives.
|
|
277
|
+
Providers without `getStatus` treat uploads as ready once the transfer
|
|
278
|
+
completes.
|
|
279
|
+
|
|
268
280
|
Set `uploads.supportedOptions` to reject upload options your storage cannot
|
|
269
281
|
honor. For example, `supportedOptions: { temporary: false }` removes
|
|
270
282
|
`temporary` from the browser and backend upload types, and EdgeStore rejects it
|
|
@@ -35,14 +35,14 @@ export type EdgeStoreProviderOptions = {
|
|
|
35
35
|
* Access key for your EdgeStore project.
|
|
36
36
|
* Can be found in the EdgeStore dashboard.
|
|
37
37
|
*
|
|
38
|
-
* This can be omitted if the `
|
|
38
|
+
* This can be omitted if the `EDGESTORE_ACCESS_KEY` environment variable is set.
|
|
39
39
|
*/
|
|
40
40
|
accessKey?: string;
|
|
41
41
|
/**
|
|
42
42
|
* Secret key for your EdgeStore project.
|
|
43
43
|
* Can be found in the EdgeStore dashboard.
|
|
44
44
|
*
|
|
45
|
-
* This can be omitted if the `
|
|
45
|
+
* This can be omitted if the `EDGESTORE_SECRET_KEY` environment variable is set.
|
|
46
46
|
*/
|
|
47
47
|
secretKey?: string;
|
|
48
48
|
/**
|
|
@@ -36,7 +36,7 @@ export type EdgeStoreRouter = typeof router;
|
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Pass `router` to your framework adapter as its `router` option.
|
|
39
|
-
Set `
|
|
39
|
+
Set `EDGESTORE_JWT_SECRET` to a stable random secret, for example one generated
|
|
40
40
|
with `openssl rand -base64 32`. All application instances must share it.
|
|
41
41
|
|
|
42
42
|
Pass `credentials` with an AWS credentials object or provider function. If it
|
|
@@ -44,19 +44,19 @@ is unset, `ES_AWS_ACCESS_KEY_ID` and `ES_AWS_SECRET_ACCESS_KEY` are used when
|
|
|
44
44
|
both are set; otherwise the AWS SDK's default provider chain applies, including
|
|
45
45
|
environment variables, shared config, and instance/task roles.
|
|
46
46
|
|
|
47
|
-
| Option | Default / environment variable
|
|
48
|
-
| ---------------------------- |
|
|
49
|
-
| `bucketName` | `ES_AWS_BUCKET_NAME`
|
|
50
|
-
| `region` | `ES_AWS_REGION`, then AWS SDK region resolution
|
|
51
|
-
| `endpoint` | `ES_AWS_ENDPOINT`
|
|
52
|
-
| `forcePathStyle` | `ES_AWS_FORCE_PATH_STYLE === 'true'`
|
|
53
|
-
| `baseUrl` | `
|
|
54
|
-
| `uploadUrlExpiresIn` | 3600 seconds
|
|
55
|
-
| `signedUrlExpiresIn` | 3600 seconds
|
|
56
|
-
| `multipart.thresholdBytes` | 100 MiB
|
|
57
|
-
| `multipart.partSizeBytes` | 16 MiB; minimum 5 MiB
|
|
58
|
-
| `multipart.sessionExpiresIn` | 86400 seconds
|
|
59
|
-
| `jwtSecret` | Multipart signing override; otherwise `
|
|
47
|
+
| Option | Default / environment variable |
|
|
48
|
+
| ---------------------------- | -------------------------------------------------------------------------------------- |
|
|
49
|
+
| `bucketName` | `ES_AWS_BUCKET_NAME` |
|
|
50
|
+
| `region` | `ES_AWS_REGION`, then AWS SDK region resolution |
|
|
51
|
+
| `endpoint` | `ES_AWS_ENDPOINT` |
|
|
52
|
+
| `forcePathStyle` | `ES_AWS_FORCE_PATH_STYLE === 'true'` |
|
|
53
|
+
| `baseUrl` | `EDGESTORE_BASE_URL`, otherwise the storage URL |
|
|
54
|
+
| `uploadUrlExpiresIn` | 3600 seconds |
|
|
55
|
+
| `signedUrlExpiresIn` | 3600 seconds |
|
|
56
|
+
| `multipart.thresholdBytes` | 100 MiB |
|
|
57
|
+
| `multipart.partSizeBytes` | 16 MiB; minimum 5 MiB |
|
|
58
|
+
| `multipart.sessionExpiresIn` | 86400 seconds |
|
|
59
|
+
| `jwtSecret` | Multipart signing override; otherwise `EDGESTORE_JWT_SECRET` or `EDGESTORE_SECRET_KEY` |
|
|
60
60
|
|
|
61
61
|
Setting `jwtSecret` does not replace the required environment secret.
|
|
62
62
|
Signed URL lifetimes must be between 1 and 604800 seconds; temporary AWS
|
|
@@ -241,7 +241,111 @@ required for browser multipart completion:
|
|
|
241
241
|
|
|
242
242
|
## S3-compatible services
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
`s3()` works with services that implement the S3 API, including Cloudflare R2,
|
|
245
|
+
Backblaze B2, DigitalOcean Spaces, Google Cloud Storage, Tigris, Supabase
|
|
246
|
+
Storage, and MinIO. Point `endpoint` at the service, pass its access keys as
|
|
247
|
+
`credentials` (or the `ES_AWS_ACCESS_KEY_ID` / `ES_AWS_SECRET_ACCESS_KEY`
|
|
248
|
+
environment variables), and configure bucket CORS as described above, including
|
|
249
|
+
exposing `ETag`.
|
|
250
|
+
|
|
251
|
+
The endpoint must be reachable from both your server and the browser. `baseUrl`
|
|
252
|
+
defaults to `<endpoint>/<bucket>`; set it to the service's public or CDN URL when
|
|
253
|
+
public files are served from a different host. Services differ in support for
|
|
254
|
+
tags, storage classes, and KMS encryption, so only set `objectOptions` your
|
|
255
|
+
service supports. EdgeStore's CI runs against MinIO; the setups below follow each
|
|
256
|
+
service's S3 compatibility documentation.
|
|
257
|
+
|
|
258
|
+
### Cloudflare R2
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
s3({
|
|
262
|
+
bucketName: 'edgestore',
|
|
263
|
+
region: 'auto',
|
|
264
|
+
endpoint: 'https://<ACCOUNT_ID>.r2.cloudflarestorage.com',
|
|
265
|
+
credentials: { accessKeyId: '...', secretAccessKey: '...' },
|
|
266
|
+
// Public files: an r2.dev subdomain or a custom domain on the bucket.
|
|
267
|
+
baseUrl: 'https://files.example.com',
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Create the keys as an R2 API token. R2 does not support object tagging or KMS
|
|
272
|
+
encryption, and supports the `STANDARD` and `STANDARD_IA` storage classes.
|
|
273
|
+
|
|
274
|
+
### Backblaze B2
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
s3({
|
|
278
|
+
bucketName: 'edgestore',
|
|
279
|
+
region: 'us-west-004',
|
|
280
|
+
endpoint: 'https://s3.us-west-004.backblazeb2.com',
|
|
281
|
+
credentials: { accessKeyId: '<keyID>', secretAccessKey: '<applicationKey>' },
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Use the region from your bucket's S3 endpoint and an application key. B2 does
|
|
286
|
+
not support object tagging or KMS encryption.
|
|
287
|
+
|
|
288
|
+
### DigitalOcean Spaces
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
s3({
|
|
292
|
+
bucketName: 'edgestore',
|
|
293
|
+
region: 'nyc3',
|
|
294
|
+
endpoint: 'https://nyc3.digitaloceanspaces.com',
|
|
295
|
+
credentials: { accessKeyId: '...', secretAccessKey: '...' },
|
|
296
|
+
// Optional: serve public files through the Spaces CDN.
|
|
297
|
+
baseUrl: 'https://edgestore.nyc3.cdn.digitaloceanspaces.com',
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Spaces supports customer-provided encryption keys but not KMS encryption.
|
|
302
|
+
|
|
303
|
+
### Google Cloud Storage
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
s3({
|
|
307
|
+
bucketName: 'edgestore',
|
|
308
|
+
region: 'auto',
|
|
309
|
+
endpoint: 'https://storage.googleapis.com',
|
|
310
|
+
credentials: { accessKeyId: '<HMAC access ID>', secretAccessKey: '<HMAC secret>' },
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Cloud Storage's XML API is S3-compatible when you use HMAC keys, including
|
|
315
|
+
signed URLs, multipart uploads, and multi-object delete. Create an HMAC key for a
|
|
316
|
+
service account with access to the bucket. Tagging and KMS headers are not
|
|
317
|
+
supported.
|
|
318
|
+
|
|
319
|
+
### Tigris
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
s3({
|
|
323
|
+
bucketName: 'edgestore',
|
|
324
|
+
region: 'auto',
|
|
325
|
+
endpoint: 'https://t3.storage.dev',
|
|
326
|
+
credentials: { accessKeyId: '...', secretAccessKey: '...' },
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Supabase Storage
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
s3({
|
|
334
|
+
bucketName: 'edgestore',
|
|
335
|
+
region: '<project region>',
|
|
336
|
+
endpoint: 'https://<project_ref>.storage.supabase.co/storage/v1/s3',
|
|
337
|
+
forcePathStyle: true,
|
|
338
|
+
credentials: { accessKeyId: '...', secretAccessKey: '...' },
|
|
339
|
+
// Public buckets are served from the object endpoint.
|
|
340
|
+
baseUrl:
|
|
341
|
+
'https://<project_ref>.supabase.co/storage/v1/object/public/edgestore',
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Create S3 access keys in your project's storage settings. Supabase Storage does
|
|
346
|
+
not support object tagging, storage classes, or server-side encryption options.
|
|
347
|
+
|
|
348
|
+
### MinIO
|
|
245
349
|
|
|
246
350
|
```ts
|
|
247
351
|
s3({
|
|
@@ -252,11 +356,6 @@ s3({
|
|
|
252
356
|
});
|
|
253
357
|
```
|
|
254
358
|
|
|
255
|
-
The endpoint must be reachable from both the application server and browser.
|
|
256
|
-
Set `baseUrl` explicitly for custom domains or virtual-hosted endpoint layouts.
|
|
257
|
-
S3-compatible services may differ in support for KMS, storage classes, tags,
|
|
258
|
-
checksums, and lifecycle policies; only enable settings your service supports.
|
|
259
|
-
|
|
260
359
|
## Limitations
|
|
261
360
|
|
|
262
361
|
* `temporary` and `replaceTargetUrl` are rejected. Track application-owned files
|
package/agent-docs/remix.md
CHANGED
|
@@ -22,8 +22,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
22
22
|
Example: title=".env"
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
26
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
> WARNING
|
|
@@ -19,8 +19,8 @@ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/)
|
|
|
19
19
|
Example: title=".env.local"
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
EDGESTORE_ACCESS_KEY=your-access-key
|
|
23
|
+
EDGESTORE_SECRET_KEY=your-secret-key
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
> WARNING
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/adapters/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EAEf,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/adapters/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,UAAU,EAEf,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA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,7 @@
|
|
|
1
1
|
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
2
|
import { parseCookie } from 'cookie';
|
|
3
3
|
import { matchPath } from '../libs/utils.js';
|
|
4
|
-
import { getCookieConfig, init, requestUpload, requestUploadBodySchema, requestUploadParts, requestUploadPartsBodySchema, completeMultipartUpload, completeMultipartUploadBodySchema, abortMultipartUpload, abortMultipartUploadBodySchema, confirmUploads, confirmUploadsBodySchema, deleteFiles, deleteFilesBodySchema } from './shared.js';
|
|
4
|
+
import { getCookieConfig, init, requestUpload, requestUploadBodySchema, requestUploadParts, requestUploadPartsBodySchema, completeMultipartUpload, completeMultipartUploadBodySchema, abortMultipartUpload, abortMultipartUploadBodySchema, getUploadStatus, uploadStatusBodySchema, confirmUploads, confirmUploadsBodySchema, deleteFiles, deleteFilesBodySchema } from './shared.js';
|
|
5
5
|
|
|
6
6
|
function resolveContext(config, options) {
|
|
7
7
|
return hasCreateContext(config) ? config.createContext(options) : {};
|
|
@@ -87,6 +87,15 @@ async function dispatchEdgeStoreRequest(params) {
|
|
|
87
87
|
status: 200
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
+
if (matchPath(request.pathname, '/upload-status')) {
|
|
91
|
+
return jsonResponse(await getUploadStatus({
|
|
92
|
+
provider,
|
|
93
|
+
router,
|
|
94
|
+
body: await parseRequestBody(request, uploadStatusBodySchema),
|
|
95
|
+
ctxToken,
|
|
96
|
+
logger
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
90
99
|
if (matchPath(request.pathname, '/confirm-uploads')) {
|
|
91
100
|
return jsonResponse(await confirmUploads({
|
|
92
101
|
provider,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyContext, type AnyEdgeStoreProvider, type EdgeStoreRouter, type SharedConfirmUploadsRes, type SharedDeleteFilesRes, type SharedInitRes, type SharedRequestUploadPartsRes, type SharedRequestUploadRes } from '@edgestore/shared';
|
|
1
|
+
import { type AnyContext, type AnyEdgeStoreProvider, type EdgeStoreRouter, type SharedConfirmUploadsRes, type SharedDeleteFilesRes, type SharedInitRes, type SharedRequestUploadPartsRes, type SharedRequestUploadRes, type SharedUploadStatusRes } from '@edgestore/shared';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import type { LoggerLike } from '../libs/logger.js';
|
|
4
4
|
export type HandlerRouter<TCtx extends AnyContext> = EdgeStoreRouter<TCtx> & {
|
|
@@ -87,6 +87,18 @@ export declare function requestUpload<TCtx extends AnyContext>(params: {
|
|
|
87
87
|
body: RequestUploadBody;
|
|
88
88
|
logger: LoggerLike;
|
|
89
89
|
}): Promise<SharedRequestUploadRes>;
|
|
90
|
+
export declare const uploadStatusBodySchema: z.ZodObject<{
|
|
91
|
+
statusToken: z.ZodString;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
export type UploadStatusBody = z.infer<typeof uploadStatusBodySchema>;
|
|
94
|
+
/** Reports processing state for an upload authorized by its status token. */
|
|
95
|
+
export declare function getUploadStatus<TCtx extends AnyContext>(params: {
|
|
96
|
+
provider: AnyEdgeStoreProvider;
|
|
97
|
+
router: EdgeStoreRouter<TCtx>;
|
|
98
|
+
ctxToken: string | undefined;
|
|
99
|
+
body: UploadStatusBody;
|
|
100
|
+
logger: LoggerLike;
|
|
101
|
+
}): Promise<SharedUploadStatusRes>;
|
|
90
102
|
export declare const requestUploadPartsBodySchema: z.ZodObject<{
|
|
91
103
|
bucketName: z.ZodString;
|
|
92
104
|
uploadId: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/adapters/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAEpB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,
|
|
1
|
+
{"version":3,"file":"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AAE,MAAM,EAAE;IACpE,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,EAAE,UAAU,CAAC;CACpB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA8BnC;AAED,eAAO,MAAM,qBAAqB;;;iBAGhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,wBAAsB,WAAW,CAAC,IAAI,SAAS,UAAU,EAAE,MAAM,EAAE;IACjE,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;CACpB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8EhC"}
|
package/dist/adapters/shared.js
CHANGED
|
@@ -139,13 +139,74 @@ async function requestUpload(params) {
|
|
|
139
139
|
autoSignedUrls
|
|
140
140
|
});
|
|
141
141
|
const { parsedPath, pathOrder } = parsePath(path);
|
|
142
|
+
const statusToken = provider.uploads.getStatus && requestUploadRes.id ? await encryptStatusToken({
|
|
143
|
+
id: requestUploadRes.id,
|
|
144
|
+
bucketName
|
|
145
|
+
}) : undefined;
|
|
142
146
|
logger.debug('Finished [requestUpload]');
|
|
143
147
|
return {
|
|
144
148
|
...requestUploadRes,
|
|
145
149
|
size: fileInfo.size,
|
|
146
150
|
path: parsedPath,
|
|
147
151
|
pathOrder,
|
|
148
|
-
metadata
|
|
152
|
+
metadata,
|
|
153
|
+
statusToken
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const uploadStatusBodySchema = z.object({
|
|
157
|
+
statusToken: nonEmptyStringSchema
|
|
158
|
+
});
|
|
159
|
+
/** Reports processing state for an upload authorized by its status token. */ async function getUploadStatus(params) {
|
|
160
|
+
const { provider, router, ctxToken, logger, body } = params;
|
|
161
|
+
await getContext(ctxToken);
|
|
162
|
+
const { id, bucketName } = await decryptStatusToken(body.statusToken);
|
|
163
|
+
logger.debug('Running [getUploadStatus]', {
|
|
164
|
+
bucketName,
|
|
165
|
+
id
|
|
166
|
+
});
|
|
167
|
+
const bucket = getBucket(router, bucketName);
|
|
168
|
+
if (!provider.uploads.getStatus) {
|
|
169
|
+
throw new EdgeStoreError({
|
|
170
|
+
message: `Provider ${provider.name} does not report upload status.`,
|
|
171
|
+
code: 'BAD_REQUEST'
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const result = await provider.uploads.getStatus({
|
|
175
|
+
bucketName,
|
|
176
|
+
id
|
|
177
|
+
});
|
|
178
|
+
logger.debug('Finished [getUploadStatus]', {
|
|
179
|
+
status: result.status
|
|
180
|
+
});
|
|
181
|
+
if (result.status !== 'completed') return {
|
|
182
|
+
status: result.status
|
|
183
|
+
};
|
|
184
|
+
const { url, key, thumbnailUrl, sizeBytes } = result.file;
|
|
185
|
+
// Processing may add a thumbnail that the upload response could not sign.
|
|
186
|
+
const { autoSignedUrls } = bucket._def;
|
|
187
|
+
const [signed] = autoSignedUrls && provider.files.getSignedUrls ? await provider.files.getSignedUrls({
|
|
188
|
+
bucketName,
|
|
189
|
+
files: [
|
|
190
|
+
await referenceFromUrl(provider, url)
|
|
191
|
+
],
|
|
192
|
+
...autoSignedUrls
|
|
193
|
+
}) : [];
|
|
194
|
+
return {
|
|
195
|
+
status: 'completed',
|
|
196
|
+
file: {
|
|
197
|
+
url,
|
|
198
|
+
key,
|
|
199
|
+
thumbnailUrl: thumbnailUrl ?? null,
|
|
200
|
+
size: sizeBytes
|
|
201
|
+
},
|
|
202
|
+
...signed && {
|
|
203
|
+
signedReadUrl: {
|
|
204
|
+
signedUrl: signed.signedUrl,
|
|
205
|
+
signedThumbnailUrl: signed.signedThumbnailUrl ?? null,
|
|
206
|
+
expiresAt: signed.expiresAt,
|
|
207
|
+
expiresIn: signed.expiresIn
|
|
208
|
+
}
|
|
209
|
+
}
|
|
149
210
|
};
|
|
150
211
|
}
|
|
151
212
|
const multipartSessionBodySchema = z.object({
|
|
@@ -351,6 +412,37 @@ async function encryptJWT(ctx) {
|
|
|
351
412
|
enc: 'A256GCM'
|
|
352
413
|
}).setIssuedAt().setExpirationTime(Date.now() / 1000 + DEFAULT_MAX_AGE).setJti(crypto.randomUUID()).encrypt(await getEncryptionKey());
|
|
353
414
|
}
|
|
415
|
+
/**
|
|
416
|
+
* Status tokens bind one upload to the browser that requested it. They never
|
|
417
|
+
* reach application code, so they carry no expiry: uploads can take arbitrarily
|
|
418
|
+
* long, and the client bounds how long it waits for processing.
|
|
419
|
+
*/ async function encryptStatusToken(upload) {
|
|
420
|
+
return await new EncryptJWT({
|
|
421
|
+
upload
|
|
422
|
+
}).setProtectedHeader({
|
|
423
|
+
alg: 'dir',
|
|
424
|
+
enc: 'A256GCM'
|
|
425
|
+
}).encrypt(await getEncryptionKey());
|
|
426
|
+
}
|
|
427
|
+
const statusTokenPayloadSchema = z.object({
|
|
428
|
+
upload: z.object({
|
|
429
|
+
id: nonEmptyStringSchema,
|
|
430
|
+
bucketName: nonEmptyStringSchema
|
|
431
|
+
})
|
|
432
|
+
});
|
|
433
|
+
async function decryptStatusToken(token) {
|
|
434
|
+
const invalid = (cause)=>new EdgeStoreError({
|
|
435
|
+
message: 'Invalid upload status token',
|
|
436
|
+
code: 'BAD_REQUEST',
|
|
437
|
+
cause
|
|
438
|
+
});
|
|
439
|
+
const { payload } = await jwtDecrypt(token, await getEncryptionKey()).catch((error)=>{
|
|
440
|
+
throw invalid(error instanceof Error ? error : undefined);
|
|
441
|
+
});
|
|
442
|
+
const result = statusTokenPayloadSchema.safeParse(payload);
|
|
443
|
+
if (!result.success) throw invalid(result.error);
|
|
444
|
+
return result.data.upload;
|
|
445
|
+
}
|
|
354
446
|
const contextPayloadSchema = z.object({
|
|
355
447
|
ctx: z.record(z.string(), z.string())
|
|
356
448
|
});
|
|
@@ -382,10 +474,10 @@ const contextPayloadSchema = z.object({
|
|
|
382
474
|
return result.data.ctx;
|
|
383
475
|
}
|
|
384
476
|
/** Derives the context-cookie encryption key from the configured secret. */ async function getEncryptionKey() {
|
|
385
|
-
const secret = getEnv('
|
|
477
|
+
const secret = getEnv('EDGESTORE_JWT_SECRET') ?? getEnv('EDGESTORE_SECRET_KEY');
|
|
386
478
|
if (!secret) {
|
|
387
479
|
throw new EdgeStoreError({
|
|
388
|
-
message: '
|
|
480
|
+
message: 'EDGESTORE_JWT_SECRET or EDGESTORE_SECRET_KEY is not defined',
|
|
389
481
|
code: 'SERVER_ERROR'
|
|
390
482
|
});
|
|
391
483
|
}
|
|
@@ -402,4 +494,4 @@ const contextPayloadSchema = z.object({
|
|
|
402
494
|
return new Uint8Array(bits);
|
|
403
495
|
}
|
|
404
496
|
|
|
405
|
-
export { abortMultipartUpload, abortMultipartUploadBodySchema, completeMultipartUpload, completeMultipartUploadBodySchema, confirmUploads, confirmUploadsBodySchema, deleteFiles, deleteFilesBodySchema, getCookieConfig, init, requestUpload, requestUploadBodySchema, requestUploadParts, requestUploadPartsBodySchema };
|
|
497
|
+
export { abortMultipartUpload, abortMultipartUploadBodySchema, completeMultipartUpload, completeMultipartUploadBodySchema, confirmUploads, confirmUploadsBodySchema, deleteFiles, deleteFilesBodySchema, getCookieConfig, getUploadStatus, init, requestUpload, requestUploadBodySchema, requestUploadParts, requestUploadPartsBodySchema, uploadStatusBodySchema };
|
package/dist/libs/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/libs/env.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOtD;
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/libs/env.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOtD;AAWD,wBAAgB,KAAK,IAAI,OAAO,CAM/B"}
|
package/dist/libs/env.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
function getEnv(key) {
|
|
2
|
+
return readEnv(key) ?? (key.startsWith('EDGESTORE_') ? readEnv(key.replace('EDGESTORE_', 'EDGE_STORE_')) : undefined);
|
|
3
|
+
}
|
|
4
|
+
function readEnv(key) {
|
|
2
5
|
if (typeof process !== 'undefined' && process.env) {
|
|
3
6
|
// @ts-expect-error - In Vite/Astro, env variables are available on import.meta.
|
|
4
7
|
return process.env[key] ?? import.meta.env?.[key];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const DEFAULT_MESSAGE = `Missing
|
|
1
|
+
const DEFAULT_MESSAGE = `Missing EDGESTORE_ACCESS_KEY or EDGESTORE_SECRET_KEY.
|
|
2
2
|
This can happen if you are trying to import something related to the backend of EdgeStore in a client component.`;
|
|
3
3
|
class EdgeStoreCredentialsError extends Error {
|
|
4
4
|
constructor(message = DEFAULT_MESSAGE){
|
|
@@ -28,13 +28,13 @@ export type AzureBlobProviderOptions = {
|
|
|
28
28
|
endpoint?: string;
|
|
29
29
|
/**
|
|
30
30
|
* Base URL for file URLs, such as a CDN in front of the container. Defaults
|
|
31
|
-
* to `<endpoint>/<container>`. Can also be set via `
|
|
31
|
+
* to `<endpoint>/<container>`. Can also be set via `EDGESTORE_BASE_URL`.
|
|
32
32
|
* Signed URLs always use the endpoint.
|
|
33
33
|
*/
|
|
34
34
|
baseUrl?: string;
|
|
35
35
|
/**
|
|
36
36
|
* Secret used to sign multipart upload sessions. Defaults to
|
|
37
|
-
* `
|
|
37
|
+
* `EDGESTORE_JWT_SECRET` or `EDGESTORE_SECRET_KEY`.
|
|
38
38
|
*/
|
|
39
39
|
jwtSecret?: string;
|
|
40
40
|
/**
|
|
@@ -15,7 +15,7 @@ const expiration = (value)=>signedUrlLifetime('Azure Blob', value);
|
|
|
15
15
|
function azureBlob(options = {}) {
|
|
16
16
|
const { storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'), storageAccountKey = getEnv('ES_AZURE_ACCOUNT_KEY'), containerName = getEnv('ES_AZURE_CONTAINER_NAME') } = options;
|
|
17
17
|
const endpoint = (options.endpoint ?? getEnv('ES_AZURE_ENDPOINT') ?? `https://${storageAccountName}.blob.core.windows.net`).replace(/\/+$/, '');
|
|
18
|
-
const baseUrl = options.baseUrl ?? getEnv('
|
|
18
|
+
const baseUrl = options.baseUrl ?? getEnv('EDGESTORE_BASE_URL') ?? `${endpoint}/${containerName}`;
|
|
19
19
|
const keys = createObjectKeys('Azure Blob', baseUrl);
|
|
20
20
|
const uploadExpiresIn = expiration(options.uploadUrlExpiresIn ?? 3600);
|
|
21
21
|
const readExpiresIn = expiration(options.signedUrlExpiresIn ?? 3600);
|
|
@@ -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;
|
|
@@ -79,6 +79,39 @@ export declare function edgestore(options?: EdgeStoreProviderOptions): {
|
|
|
79
79
|
readonly complete: ({ uploadId, parts }: import("@edgestore/shared").CompleteMultipartUploadParams) => Promise<void>;
|
|
80
80
|
readonly abort: ({ uploadId }: import("@edgestore/shared").MultipartUploadSession) => Promise<void>;
|
|
81
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
|
+
}>;
|
|
82
115
|
readonly upload: ({ bucketName, bucketType, fileInfo, autoSignedUrls, source, signal, onProgress, }: import("@edgestore/shared").BackendUploadParams) => Promise<{
|
|
83
116
|
file: ProviderFile;
|
|
84
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,CAA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C;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"}
|
|
@@ -56,7 +56,7 @@ function edgestore(options) {
|
|
|
56
56
|
}
|
|
57
57
|
]))
|
|
58
58
|
});
|
|
59
|
-
const overrideBaseUrl = getEnv('
|
|
59
|
+
const overrideBaseUrl = getEnv('EDGESTORE_BASE_URL');
|
|
60
60
|
return {
|
|
61
61
|
clientInit: {
|
|
62
62
|
urls: delivery && !overrideBaseUrl ? delivery.initUrls : [
|
|
@@ -126,6 +126,17 @@ function edgestore(options) {
|
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
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
|
+
},
|
|
129
140
|
upload: async ({ bucketName, bucketType, fileInfo, autoSignedUrls, source, signal, onProgress })=>{
|
|
130
141
|
const result = await runtime.uploads.upload({
|
|
131
142
|
bucket: bucketName,
|
|
@@ -244,8 +255,8 @@ function resolveProviderAuthentication(options) {
|
|
|
244
255
|
if (project !== undefined) {
|
|
245
256
|
throw new TypeError('EdgeStore provider option `project` requires a Bearer token.');
|
|
246
257
|
}
|
|
247
|
-
const accessKey = configuredAccessKey ?? getEnv('
|
|
248
|
-
const secretKey = configuredSecretKey ?? getEnv('
|
|
258
|
+
const accessKey = configuredAccessKey ?? getEnv('EDGESTORE_ACCESS_KEY');
|
|
259
|
+
const secretKey = configuredSecretKey ?? getEnv('EDGESTORE_SECRET_KEY');
|
|
249
260
|
if (typeof accessKey !== 'string' || !accessKey.trim() || typeof secretKey !== 'string' || !secretKey.trim()) {
|
|
250
261
|
throw new EdgeStoreCredentialsError();
|
|
251
262
|
}
|
|
@@ -271,7 +282,7 @@ function mapMutationResult(result) {
|
|
|
271
282
|
};
|
|
272
283
|
}
|
|
273
284
|
function getApiUrl() {
|
|
274
|
-
const configured = getEnv('
|
|
285
|
+
const configured = getEnv('EDGESTORE_API_ENDPOINT');
|
|
275
286
|
if (!configured) return undefined;
|
|
276
287
|
const base = configured.replace(/\/+$/, '');
|
|
277
288
|
return base.endsWith('/v2') ? base : `${base}/v2`;
|
|
@@ -303,6 +314,7 @@ function mapRawUploadRequest(bucketType, fileInfo, signedReadUrl) {
|
|
|
303
314
|
}
|
|
304
315
|
function mapUploadResponse(res, multipartConfig) {
|
|
305
316
|
const access = {
|
|
317
|
+
id: res.file.id,
|
|
306
318
|
key: res.file.key,
|
|
307
319
|
url: res.file.url,
|
|
308
320
|
thumbnailUrl: res.file.thumbnailUrl,
|
|
@@ -27,7 +27,7 @@ function s3(options = {}) {
|
|
|
27
27
|
// Presigning without a body must not sign an empty-body optional checksum.
|
|
28
28
|
requestChecksumCalculation: 'WHEN_REQUIRED'
|
|
29
29
|
});
|
|
30
|
-
const baseUrl = options.baseUrl ?? getEnv('
|
|
30
|
+
const baseUrl = options.baseUrl ?? getEnv('EDGESTORE_BASE_URL') ?? (endpoint ? `${endpoint.replace(/\/+$/, '')}/${bucketName}` : region ? `https://${bucketName}.s3.${region}.amazonaws.com` : async ()=>`https://${bucketName}.s3.${await client.config.region()}.amazonaws.com`);
|
|
31
31
|
const keys = async ()=>createObjectKeys('S3', typeof baseUrl === 'function' ? await baseUrl() : baseUrl);
|
|
32
32
|
const uploadExpiresIn = expiration(options.uploadUrlExpiresIn ?? 3600);
|
|
33
33
|
const readExpiresIn = expiration(options.signedUrlExpiresIn ?? 3600);
|
|
@@ -41,15 +41,15 @@ export type S3ProviderOptions = {
|
|
|
41
41
|
* Base URL to use for accessing files.
|
|
42
42
|
* Only needed if you are using a custom domain or cloudfront.
|
|
43
43
|
*
|
|
44
|
-
* It can also be set via the `
|
|
44
|
+
* It can also be set via the `EDGESTORE_BASE_URL` environment variable.
|
|
45
45
|
*/
|
|
46
46
|
baseUrl?: string;
|
|
47
47
|
/**
|
|
48
48
|
* Secret used to sign multipart upload sessions. The adapter context cookie
|
|
49
|
-
* still requires
|
|
49
|
+
* still requires EDGESTORE_JWT_SECRET (or EDGESTORE_SECRET_KEY).
|
|
50
50
|
* Can be generated with `openssl rand -base64 32`.
|
|
51
51
|
*
|
|
52
|
-
* It can also be set via the `
|
|
52
|
+
* It can also be set via the `EDGESTORE_JWT_SECRET` environment variable.
|
|
53
53
|
*/
|
|
54
54
|
jwtSecret?: string;
|
|
55
55
|
/**
|
|
@@ -20,8 +20,8 @@ const sessionSchema = z.object({
|
|
|
20
20
|
throw new RangeError(`${providerName} multipart session lifetime must be a positive integer number of seconds.`);
|
|
21
21
|
}
|
|
22
22
|
function signingKey() {
|
|
23
|
-
const value = secret ?? getEnv('
|
|
24
|
-
if (!value) throw new Error(`${providerName} multipart uploads require jwtSecret or
|
|
23
|
+
const value = secret ?? getEnv('EDGESTORE_JWT_SECRET') ?? getEnv('EDGESTORE_SECRET_KEY');
|
|
24
|
+
if (!value) throw new Error(`${providerName} multipart uploads require jwtSecret or EDGESTORE_JWT_SECRET.`);
|
|
25
25
|
return new TextEncoder().encode(value);
|
|
26
26
|
}
|
|
27
27
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgestoreSmoke.d.ts","sourceRoot":"","sources":["../../src/test-utils/edgestoreSmoke.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edgestoreSmoke.d.ts","sourceRoot":"","sources":["../../src/test-utils/edgestoreSmoke.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AAEpD,wBAAgB,kBAAkB,WAEjC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,UAEjD;AAED,wBAAgB,uBAAuB,SAMtC;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"}
|
package/dist/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/server",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.7",
|
|
4
4
|
"description": "Upload files with ease from React/Next.js",
|
|
5
5
|
"homepage": "https://edgestore.dev",
|
|
6
6
|
"license": "MIT",
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"!**/__tests__"
|
|
108
108
|
],
|
|
109
109
|
"dependencies": {
|
|
110
|
-
"@edgestore/sdk": "1.0.0-rc.
|
|
111
|
-
"@edgestore/shared": "1.0.0-rc.
|
|
110
|
+
"@edgestore/sdk": "1.0.0-rc.7",
|
|
111
|
+
"@edgestore/shared": "1.0.0-rc.7",
|
|
112
112
|
"@standard-schema/spec": "^1.1.0",
|
|
113
113
|
"cookie": "^2.0.1",
|
|
114
114
|
"jose": "^6.2.3",
|
|
@@ -19,11 +19,13 @@ import {
|
|
|
19
19
|
deleteFiles,
|
|
20
20
|
deleteFilesBodySchema,
|
|
21
21
|
getCookieConfig,
|
|
22
|
+
getUploadStatus,
|
|
22
23
|
init,
|
|
23
24
|
requestUpload,
|
|
24
25
|
requestUploadBodySchema,
|
|
25
26
|
requestUploadParts,
|
|
26
27
|
requestUploadPartsBodySchema,
|
|
28
|
+
uploadStatusBodySchema,
|
|
27
29
|
type CookieConfig,
|
|
28
30
|
type HandlerRouter,
|
|
29
31
|
} from './shared';
|
|
@@ -159,6 +161,18 @@ export async function dispatchEdgeStoreRequest<
|
|
|
159
161
|
return new Response(null, { status: 200 });
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
if (matchPath(request.pathname, '/upload-status')) {
|
|
165
|
+
return jsonResponse(
|
|
166
|
+
await getUploadStatus({
|
|
167
|
+
provider,
|
|
168
|
+
router,
|
|
169
|
+
body: await parseRequestBody(request, uploadStatusBodySchema),
|
|
170
|
+
ctxToken,
|
|
171
|
+
logger,
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
162
176
|
if (matchPath(request.pathname, '/confirm-uploads')) {
|
|
163
177
|
return jsonResponse(
|
|
164
178
|
await confirmUploads({
|
package/src/adapters/shared.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type SharedInitRes,
|
|
10
10
|
type SharedRequestUploadPartsRes,
|
|
11
11
|
type SharedRequestUploadRes,
|
|
12
|
+
type SharedUploadStatusRes,
|
|
12
13
|
} from '@edgestore/shared';
|
|
13
14
|
import { stringifySetCookie } from 'cookie';
|
|
14
15
|
import { EncryptJWT, jwtDecrypt } from 'jose';
|
|
@@ -224,6 +225,10 @@ export async function requestUpload<TCtx extends AnyContext>(params: {
|
|
|
224
225
|
autoSignedUrls,
|
|
225
226
|
});
|
|
226
227
|
const { parsedPath, pathOrder } = parsePath(path);
|
|
228
|
+
const statusToken =
|
|
229
|
+
provider.uploads.getStatus && requestUploadRes.id
|
|
230
|
+
? await encryptStatusToken({ id: requestUploadRes.id, bucketName })
|
|
231
|
+
: undefined;
|
|
227
232
|
|
|
228
233
|
logger.debug('Finished [requestUpload]');
|
|
229
234
|
|
|
@@ -233,6 +238,64 @@ export async function requestUpload<TCtx extends AnyContext>(params: {
|
|
|
233
238
|
path: parsedPath,
|
|
234
239
|
pathOrder,
|
|
235
240
|
metadata,
|
|
241
|
+
statusToken,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const uploadStatusBodySchema = z.object({
|
|
246
|
+
statusToken: nonEmptyStringSchema,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
export type UploadStatusBody = z.infer<typeof uploadStatusBodySchema>;
|
|
250
|
+
|
|
251
|
+
/** Reports processing state for an upload authorized by its status token. */
|
|
252
|
+
export async function getUploadStatus<TCtx extends AnyContext>(params: {
|
|
253
|
+
provider: AnyEdgeStoreProvider;
|
|
254
|
+
router: EdgeStoreRouter<TCtx>;
|
|
255
|
+
ctxToken: string | undefined;
|
|
256
|
+
body: UploadStatusBody;
|
|
257
|
+
logger: LoggerLike;
|
|
258
|
+
}): Promise<SharedUploadStatusRes> {
|
|
259
|
+
const { provider, router, ctxToken, logger, body } = params;
|
|
260
|
+
|
|
261
|
+
await getContext(ctxToken);
|
|
262
|
+
const { id, bucketName } = await decryptStatusToken(body.statusToken);
|
|
263
|
+
logger.debug('Running [getUploadStatus]', { bucketName, id });
|
|
264
|
+
const bucket = getBucket(router, bucketName);
|
|
265
|
+
|
|
266
|
+
if (!provider.uploads.getStatus) {
|
|
267
|
+
throw new EdgeStoreError({
|
|
268
|
+
message: `Provider ${provider.name} does not report upload status.`,
|
|
269
|
+
code: 'BAD_REQUEST',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const result = await provider.uploads.getStatus({ bucketName, id });
|
|
273
|
+
|
|
274
|
+
logger.debug('Finished [getUploadStatus]', { status: result.status });
|
|
275
|
+
|
|
276
|
+
if (result.status !== 'completed') return { status: result.status };
|
|
277
|
+
const { url, key, thumbnailUrl, sizeBytes } = result.file;
|
|
278
|
+
// Processing may add a thumbnail that the upload response could not sign.
|
|
279
|
+
const { autoSignedUrls } = bucket._def;
|
|
280
|
+
const [signed] =
|
|
281
|
+
autoSignedUrls && provider.files.getSignedUrls
|
|
282
|
+
? await provider.files.getSignedUrls({
|
|
283
|
+
bucketName,
|
|
284
|
+
files: [await referenceFromUrl(provider, url)],
|
|
285
|
+
...autoSignedUrls,
|
|
286
|
+
})
|
|
287
|
+
: [];
|
|
288
|
+
return {
|
|
289
|
+
status: 'completed',
|
|
290
|
+
file: { url, key, thumbnailUrl: thumbnailUrl ?? null, size: sizeBytes },
|
|
291
|
+
...(signed && {
|
|
292
|
+
signedReadUrl: {
|
|
293
|
+
signedUrl: signed.signedUrl,
|
|
294
|
+
signedThumbnailUrl: signed.signedThumbnailUrl ?? null,
|
|
295
|
+
expiresAt: signed.expiresAt,
|
|
296
|
+
expiresIn: signed.expiresIn,
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
236
299
|
};
|
|
237
300
|
}
|
|
238
301
|
|
|
@@ -525,6 +588,41 @@ async function encryptJWT(ctx: AnyContext) {
|
|
|
525
588
|
.encrypt(await getEncryptionKey());
|
|
526
589
|
}
|
|
527
590
|
|
|
591
|
+
/**
|
|
592
|
+
* Status tokens bind one upload to the browser that requested it. They never
|
|
593
|
+
* reach application code, so they carry no expiry: uploads can take arbitrarily
|
|
594
|
+
* long, and the client bounds how long it waits for processing.
|
|
595
|
+
*/
|
|
596
|
+
async function encryptStatusToken(upload: { id: string; bucketName: string }) {
|
|
597
|
+
return await new EncryptJWT({ upload })
|
|
598
|
+
.setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
|
|
599
|
+
.encrypt(await getEncryptionKey());
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
const statusTokenPayloadSchema = z.object({
|
|
603
|
+
upload: z.object({
|
|
604
|
+
id: nonEmptyStringSchema,
|
|
605
|
+
bucketName: nonEmptyStringSchema,
|
|
606
|
+
}),
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
async function decryptStatusToken(token: string) {
|
|
610
|
+
const invalid = (cause?: Error) =>
|
|
611
|
+
new EdgeStoreError({
|
|
612
|
+
message: 'Invalid upload status token',
|
|
613
|
+
code: 'BAD_REQUEST',
|
|
614
|
+
cause,
|
|
615
|
+
});
|
|
616
|
+
const { payload } = await jwtDecrypt(token, await getEncryptionKey()).catch(
|
|
617
|
+
(error: unknown) => {
|
|
618
|
+
throw invalid(error instanceof Error ? error : undefined);
|
|
619
|
+
},
|
|
620
|
+
);
|
|
621
|
+
const result = statusTokenPayloadSchema.safeParse(payload);
|
|
622
|
+
if (!result.success) throw invalid(result.error);
|
|
623
|
+
return result.data.upload;
|
|
624
|
+
}
|
|
625
|
+
|
|
528
626
|
const contextPayloadSchema = z.object({
|
|
529
627
|
ctx: z.record(z.string(), z.string()),
|
|
530
628
|
});
|
|
@@ -562,10 +660,10 @@ async function getContext(token: string | undefined) {
|
|
|
562
660
|
/** Derives the context-cookie encryption key from the configured secret. */
|
|
563
661
|
async function getEncryptionKey() {
|
|
564
662
|
const secret =
|
|
565
|
-
getEnv('
|
|
663
|
+
getEnv('EDGESTORE_JWT_SECRET') ?? getEnv('EDGESTORE_SECRET_KEY');
|
|
566
664
|
if (!secret) {
|
|
567
665
|
throw new EdgeStoreError({
|
|
568
|
-
message: '
|
|
666
|
+
message: 'EDGESTORE_JWT_SECRET or EDGESTORE_SECRET_KEY is not defined',
|
|
569
667
|
code: 'SERVER_ERROR',
|
|
570
668
|
});
|
|
571
669
|
}
|
package/src/libs/env.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export function getEnv(key: string): string | undefined {
|
|
2
|
+
return (
|
|
3
|
+
readEnv(key) ??
|
|
4
|
+
(key.startsWith('EDGESTORE_')
|
|
5
|
+
? readEnv(key.replace('EDGESTORE_', 'EDGE_STORE_'))
|
|
6
|
+
: undefined)
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function readEnv(key: string): string | undefined {
|
|
2
11
|
if (typeof process !== 'undefined' && process.env) {
|
|
3
12
|
// @ts-expect-error - In Vite/Astro, env variables are available on import.meta.
|
|
4
13
|
return process.env[key] ?? import.meta.env?.[key];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const DEFAULT_MESSAGE = `Missing
|
|
1
|
+
const DEFAULT_MESSAGE = `Missing EDGESTORE_ACCESS_KEY or EDGESTORE_SECRET_KEY.
|
|
2
2
|
This can happen if you are trying to import something related to the backend of EdgeStore in a client component.`;
|
|
3
3
|
|
|
4
4
|
class EdgeStoreCredentialsError extends Error {
|
|
@@ -60,13 +60,13 @@ export type AzureBlobProviderOptions = {
|
|
|
60
60
|
endpoint?: string;
|
|
61
61
|
/**
|
|
62
62
|
* Base URL for file URLs, such as a CDN in front of the container. Defaults
|
|
63
|
-
* to `<endpoint>/<container>`. Can also be set via `
|
|
63
|
+
* to `<endpoint>/<container>`. Can also be set via `EDGESTORE_BASE_URL`.
|
|
64
64
|
* Signed URLs always use the endpoint.
|
|
65
65
|
*/
|
|
66
66
|
baseUrl?: string;
|
|
67
67
|
/**
|
|
68
68
|
* Secret used to sign multipart upload sessions. Defaults to
|
|
69
|
-
* `
|
|
69
|
+
* `EDGESTORE_JWT_SECRET` or `EDGESTORE_SECRET_KEY`.
|
|
70
70
|
*/
|
|
71
71
|
jwtSecret?: string;
|
|
72
72
|
/**
|
|
@@ -117,7 +117,7 @@ export function azureBlob(options: AzureBlobProviderOptions = {}) {
|
|
|
117
117
|
).replace(/\/+$/, '');
|
|
118
118
|
const baseUrl =
|
|
119
119
|
options.baseUrl ??
|
|
120
|
-
getEnv('
|
|
120
|
+
getEnv('EDGESTORE_BASE_URL') ??
|
|
121
121
|
`${endpoint}/${containerName}`;
|
|
122
122
|
const keys = createObjectKeys('Azure Blob', baseUrl);
|
|
123
123
|
const uploadExpiresIn = expiration(options.uploadUrlExpiresIn ?? 3600);
|
|
@@ -41,14 +41,14 @@ type EdgeStoreProjectProviderOptions = {
|
|
|
41
41
|
* Access key for your EdgeStore project.
|
|
42
42
|
* Can be found in the EdgeStore dashboard.
|
|
43
43
|
*
|
|
44
|
-
* This can be omitted if the `
|
|
44
|
+
* This can be omitted if the `EDGESTORE_ACCESS_KEY` environment variable is set.
|
|
45
45
|
*/
|
|
46
46
|
accessKey?: string;
|
|
47
47
|
/**
|
|
48
48
|
* Secret key for your EdgeStore project.
|
|
49
49
|
* Can be found in the EdgeStore dashboard.
|
|
50
50
|
*
|
|
51
|
-
* This can be omitted if the `
|
|
51
|
+
* This can be omitted if the `EDGESTORE_SECRET_KEY` environment variable is set.
|
|
52
52
|
*/
|
|
53
53
|
secretKey?: string;
|
|
54
54
|
token?: never;
|
|
@@ -110,7 +110,7 @@ export function edgestore(options?: EdgeStoreProviderOptions) {
|
|
|
110
110
|
]),
|
|
111
111
|
),
|
|
112
112
|
});
|
|
113
|
-
const overrideBaseUrl = getEnv('
|
|
113
|
+
const overrideBaseUrl = getEnv('EDGESTORE_BASE_URL');
|
|
114
114
|
return {
|
|
115
115
|
clientInit: {
|
|
116
116
|
urls:
|
|
@@ -191,6 +191,12 @@ export function edgestore(options?: EdgeStoreProviderOptions) {
|
|
|
191
191
|
await runtime.uploads.cancel({ uploadId });
|
|
192
192
|
},
|
|
193
193
|
},
|
|
194
|
+
getStatus: async ({ id }) => {
|
|
195
|
+
const result = await runtime.uploads.get({ uploadId: id });
|
|
196
|
+
return 'file' in result
|
|
197
|
+
? { status: 'completed', file: result.file }
|
|
198
|
+
: { status: result.upload.status };
|
|
199
|
+
},
|
|
194
200
|
upload: async ({
|
|
195
201
|
bucketName,
|
|
196
202
|
bucketType,
|
|
@@ -351,8 +357,8 @@ function resolveProviderAuthentication(
|
|
|
351
357
|
);
|
|
352
358
|
}
|
|
353
359
|
|
|
354
|
-
const accessKey = configuredAccessKey ?? getEnv('
|
|
355
|
-
const secretKey = configuredSecretKey ?? getEnv('
|
|
360
|
+
const accessKey = configuredAccessKey ?? getEnv('EDGESTORE_ACCESS_KEY');
|
|
361
|
+
const secretKey = configuredSecretKey ?? getEnv('EDGESTORE_SECRET_KEY');
|
|
356
362
|
|
|
357
363
|
if (
|
|
358
364
|
typeof accessKey !== 'string' ||
|
|
@@ -399,7 +405,7 @@ function mapMutationResult<TErrorCode extends string>(result: {
|
|
|
399
405
|
}
|
|
400
406
|
|
|
401
407
|
function getApiUrl() {
|
|
402
|
-
const configured = getEnv('
|
|
408
|
+
const configured = getEnv('EDGESTORE_API_ENDPOINT');
|
|
403
409
|
if (!configured) return undefined;
|
|
404
410
|
const base = configured.replace(/\/+$/, '');
|
|
405
411
|
return base.endsWith('/v2') ? base : `${base}/v2`;
|
|
@@ -453,6 +459,7 @@ function mapUploadResponse(
|
|
|
453
459
|
multipartConfig?: { partSize: number; totalParts: number },
|
|
454
460
|
): RequestUploadRes {
|
|
455
461
|
const access = {
|
|
462
|
+
id: res.file.id,
|
|
456
463
|
key: res.file.key,
|
|
457
464
|
url: res.file.url,
|
|
458
465
|
thumbnailUrl: res.file.thumbnailUrl,
|
|
@@ -58,15 +58,15 @@ export type S3ProviderOptions = {
|
|
|
58
58
|
* Base URL to use for accessing files.
|
|
59
59
|
* Only needed if you are using a custom domain or cloudfront.
|
|
60
60
|
*
|
|
61
|
-
* It can also be set via the `
|
|
61
|
+
* It can also be set via the `EDGESTORE_BASE_URL` environment variable.
|
|
62
62
|
*/
|
|
63
63
|
baseUrl?: string;
|
|
64
64
|
/**
|
|
65
65
|
* Secret used to sign multipart upload sessions. The adapter context cookie
|
|
66
|
-
* still requires
|
|
66
|
+
* still requires EDGESTORE_JWT_SECRET (or EDGESTORE_SECRET_KEY).
|
|
67
67
|
* Can be generated with `openssl rand -base64 32`.
|
|
68
68
|
*
|
|
69
|
-
* It can also be set via the `
|
|
69
|
+
* It can also be set via the `EDGESTORE_JWT_SECRET` environment variable.
|
|
70
70
|
*/
|
|
71
71
|
jwtSecret?: string;
|
|
72
72
|
/**
|
|
@@ -42,11 +42,11 @@ export function createMultipartSessions({
|
|
|
42
42
|
function signingKey() {
|
|
43
43
|
const value =
|
|
44
44
|
secret ??
|
|
45
|
-
getEnv('
|
|
46
|
-
getEnv('
|
|
45
|
+
getEnv('EDGESTORE_JWT_SECRET') ??
|
|
46
|
+
getEnv('EDGESTORE_SECRET_KEY');
|
|
47
47
|
if (!value)
|
|
48
48
|
throw new Error(
|
|
49
|
-
`${providerName} multipart uploads require jwtSecret or
|
|
49
|
+
`${providerName} multipart uploads require jwtSecret or EDGESTORE_JWT_SECRET.`,
|
|
50
50
|
);
|
|
51
51
|
return new TextEncoder().encode(value);
|
|
52
52
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { getEnv } from '../libs/env';
|
|
2
3
|
|
|
3
4
|
export const SMOKE_CONTENT = 'edgestore smoke test';
|
|
4
5
|
|
|
@@ -11,12 +12,9 @@ export function createSmokeFileName(prefix: string) {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export function requireSmokeCredentials() {
|
|
14
|
-
if (
|
|
15
|
-
!process.env.EDGE_STORE_ACCESS_KEY ||
|
|
16
|
-
!process.env.EDGE_STORE_SECRET_KEY
|
|
17
|
-
) {
|
|
15
|
+
if (!getEnv('EDGESTORE_ACCESS_KEY') || !getEnv('EDGESTORE_SECRET_KEY')) {
|
|
18
16
|
throw new Error(
|
|
19
|
-
'
|
|
17
|
+
'EDGESTORE_ACCESS_KEY and EDGESTORE_SECRET_KEY are required',
|
|
20
18
|
);
|
|
21
19
|
}
|
|
22
20
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const EDGE_STORE_PACKAGE_NAME = '@edgestore/server';
|
|
2
|
-
export const EDGE_STORE_PACKAGE_VERSION = '1.0.0-rc.
|
|
2
|
+
export const EDGE_STORE_PACKAGE_VERSION = '1.0.0-rc.7';
|