@edgestore/server 1.0.0-next.4 → 1.0.0-rc.6
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 -8
- package/agent-docs/README.md +1 -1
- package/agent-docs/astro.md +3 -9
- package/agent-docs/backend-client.md +16 -29
- package/agent-docs/configuration.md +41 -10
- package/agent-docs/express.md +3 -9
- package/agent-docs/fastify.md +3 -9
- package/agent-docs/hono.md +3 -9
- package/agent-docs/next.md +5 -17
- package/agent-docs/provider-azure-blob.md +150 -59
- package/agent-docs/provider-custom.md +42 -13
- package/agent-docs/provider-edgestore.md +9 -9
- package/agent-docs/provider-s3.md +224 -119
- package/agent-docs/remix.md +3 -9
- package/agent-docs/tanstack-start.md +3 -9
- package/dist/adapters/astro/index.d.ts +2 -2
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +1 -2
- package/dist/adapters/dispatcher.d.ts +2 -3
- package/dist/adapters/dispatcher.d.ts.map +1 -1
- package/dist/adapters/dispatcher.js +17 -22
- package/dist/adapters/express/index.d.ts +2 -2
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +1 -5
- package/dist/adapters/fastify/index.d.ts +2 -2
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +1 -5
- package/dist/adapters/hono/index.d.ts +2 -2
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +1 -2
- package/dist/adapters/next/app/index.d.ts +2 -2
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +1 -2
- package/dist/adapters/next/pages/index.d.ts +2 -2
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +1 -5
- package/dist/adapters/remix/index.d.ts +2 -2
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +1 -2
- package/dist/adapters/shared.d.ts +31 -143
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +115 -197
- package/dist/adapters/start/index.d.ts +2 -2
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +1 -2
- package/dist/core/client/bucketClient.d.ts +0 -1
- package/dist/core/client/bucketClient.d.ts.map +1 -1
- package/dist/core/client/bucketClient.js +6 -28
- package/dist/core/client/index.d.ts +25 -26
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +2 -3
- package/dist/core/provider.d.ts +11 -2
- package/dist/core/provider.d.ts.map +1 -1
- package/dist/core/provider.js +20 -3
- package/dist/core/router.d.ts +25 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/router.js +49 -0
- package/dist/core/routerRules.d.ts +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- 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 +81 -49
- package/dist/providers/azure-blob/index.d.ts.map +1 -1
- package/dist/providers/azure-blob/index.js +194 -105
- package/dist/providers/edgestore/index.d.ts +12 -32
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +34 -31
- package/dist/providers/s3/backendUpload.d.ts +10 -0
- package/dist/providers/s3/backendUpload.d.ts.map +1 -0
- package/dist/providers/s3/backendUpload.js +59 -0
- package/dist/providers/s3/index.d.ts +52 -97
- package/dist/providers/s3/index.d.ts.map +1 -1
- package/dist/providers/s3/index.js +221 -91
- package/dist/providers/s3/multipart.d.ts +23 -0
- package/dist/providers/s3/multipart.d.ts.map +1 -0
- package/dist/providers/s3/multipart.js +96 -0
- package/dist/providers/s3/objectHeaders.d.ts +4 -0
- package/dist/providers/s3/objectHeaders.d.ts.map +1 -0
- package/dist/providers/s3/objectHeaders.js +22 -0
- package/dist/providers/s3/options.d.ts +85 -0
- package/dist/providers/s3/options.d.ts.map +1 -0
- 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/storage/objectKeys.js +67 -0
- 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/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +5 -12
- package/src/adapters/astro/index.ts +3 -4
- package/src/adapters/dispatcher.ts +21 -30
- package/src/adapters/express/index.ts +3 -9
- package/src/adapters/fastify/index.ts +3 -9
- package/src/adapters/hono/index.ts +3 -4
- package/src/adapters/next/app/index.ts +3 -4
- package/src/adapters/next/pages/index.ts +3 -9
- package/src/adapters/remix/index.ts +3 -4
- package/src/adapters/shared.ts +166 -285
- package/src/adapters/start/index.ts +3 -4
- package/src/core/client/bucketClient.ts +10 -41
- package/src/core/client/index.ts +29 -49
- package/src/core/provider.ts +25 -10
- package/src/core/router.ts +97 -0
- package/src/index.ts +4 -11
- package/src/providers/azure-blob/blocks.ts +201 -0
- package/src/providers/azure-blob/index.ts +290 -170
- package/src/providers/edgestore/index.ts +38 -35
- package/src/providers/s3/backendUpload.ts +82 -0
- package/src/providers/s3/index.ts +279 -227
- package/src/providers/s3/multipart.ts +138 -0
- package/src/providers/s3/objectHeaders.ts +23 -0
- package/src/providers/s3/options.ts +102 -0
- 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/version.ts +1 -1
- package/core/index.d.ts +0 -1
- package/core/index.js +0 -1
- package/dist/core/index.d.ts +0 -22
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -14
- package/src/core/index.ts +0 -43
package/README.md
CHANGED
|
@@ -33,9 +33,8 @@ The example below is the simplest bucket you can create with EdgeStore. Just a s
|
|
|
33
33
|
You can have multiple buckets in your app, each with its own configuration.
|
|
34
34
|
|
|
35
35
|
```ts title="src/app/api/edgestore/[...edgestore]/route.ts"
|
|
36
|
-
import {
|
|
36
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
37
37
|
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';
|
|
38
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
39
38
|
|
|
40
39
|
const es = initEdgeStore.create();
|
|
41
40
|
|
|
@@ -46,13 +45,8 @@ const router = es.router({
|
|
|
46
45
|
publicFiles: es.fileBucket(),
|
|
47
46
|
});
|
|
48
47
|
|
|
49
|
-
const configuredEdgeStore = createEdgeStore({
|
|
50
|
-
router,
|
|
51
|
-
provider: edgestore(),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
48
|
const handler = createEdgeStoreNextHandler({
|
|
55
|
-
|
|
49
|
+
router,
|
|
56
50
|
});
|
|
57
51
|
|
|
58
52
|
export { handler as GET, handler as POST };
|
package/agent-docs/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @edgestore/server 1.0.0-
|
|
1
|
+
# @edgestore/server 1.0.0-rc.6: 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
|
@@ -12,7 +12,7 @@ React component.
|
|
|
12
12
|
Packages to install (use the application’s package manager):
|
|
13
13
|
|
|
14
14
|
```text
|
|
15
|
-
@edgestore/server @edgestore/react
|
|
15
|
+
@edgestore/server@rc @edgestore/react@rc
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
### Environment variables
|
|
@@ -39,9 +39,8 @@ EdgeStore endpoint must run on demand; a static-only deployment cannot serve it.
|
|
|
39
39
|
Create `src/pages/api/edgestore/[...edgestore].ts`:
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
|
-
import {
|
|
42
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
43
43
|
import { createEdgeStoreAstroHandler } from '@edgestore/server/adapters/astro';
|
|
44
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
45
44
|
|
|
46
45
|
export const prerender = false;
|
|
47
46
|
|
|
@@ -51,13 +50,8 @@ const router = es.router({
|
|
|
51
50
|
publicFiles: es.fileBucket(),
|
|
52
51
|
});
|
|
53
52
|
|
|
54
|
-
const configuredEdgeStore = createEdgeStore({
|
|
55
|
-
router,
|
|
56
|
-
provider: edgestore(),
|
|
57
|
-
});
|
|
58
|
-
|
|
59
53
|
const handler = createEdgeStoreAstroHandler({
|
|
60
|
-
|
|
54
|
+
router,
|
|
61
55
|
});
|
|
62
56
|
|
|
63
57
|
export { handler as GET, handler as POST };
|
|
@@ -6,17 +6,17 @@ Sometimes you might want to use the EdgeStore functionality directly from your b
|
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
The router exposes a type-safe backend client through `router.client`. The HTTP
|
|
10
|
+
handler and backend client share the same provider. EdgeStore is the default;
|
|
11
|
+
chain `.provider(myProvider)` on the router to use a different provider.
|
|
11
12
|
|
|
12
13
|
Since Next.js doesn't allow exports in the api route, you will need to move your router to an external file.
|
|
13
14
|
|
|
14
15
|
Example: title="src/lib/edgestore-server.ts"
|
|
15
16
|
|
|
16
17
|
```ts
|
|
17
|
-
import {
|
|
18
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
18
19
|
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';
|
|
19
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
20
20
|
|
|
21
21
|
const es = initEdgeStore.create();
|
|
22
22
|
|
|
@@ -24,16 +24,11 @@ export const router = es.router({
|
|
|
24
24
|
publicFiles: es.fileBucket(),
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
export const configuredEdgeStore = createEdgeStore({
|
|
28
|
-
router,
|
|
29
|
-
provider: edgestore(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
27
|
export const handler = createEdgeStoreNextHandler({
|
|
33
|
-
|
|
28
|
+
router,
|
|
34
29
|
});
|
|
35
30
|
|
|
36
|
-
export const backendClient =
|
|
31
|
+
export const backendClient = router.client;
|
|
37
32
|
```
|
|
38
33
|
|
|
39
34
|
Then you will need to update your api route to use the exported handler.
|
|
@@ -59,11 +54,11 @@ export { handler as GET, handler as POST };
|
|
|
59
54
|
> `accessControl`, `beforeUpload`, or `beforeDelete`. Perform authorization in
|
|
60
55
|
> the server code that calls it.
|
|
61
56
|
|
|
62
|
-
The hosted `edgestore()` provider supports the complete backend client. S3
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
provider
|
|
57
|
+
The hosted `edgestore()` provider supports the complete backend client. S3 and
|
|
58
|
+
Azure Blob Storage support `upload`, `get`, `delete`, `deleteMany`, and
|
|
59
|
+
private-read `createSignedUrl` / `createSignedUrls`, accepting key or URL
|
|
60
|
+
references. Unsupported operations, such as listing and confirmation, remain
|
|
61
|
+
absent from each provider's client type.
|
|
67
62
|
|
|
68
63
|
## Backend Upload
|
|
69
64
|
|
|
@@ -252,11 +247,11 @@ client:
|
|
|
252
247
|
|
|
253
248
|
```ts
|
|
254
249
|
type UploadInput = Parameters<
|
|
255
|
-
typeof
|
|
250
|
+
typeof router.client.publicFiles.upload
|
|
256
251
|
>[0];
|
|
257
252
|
|
|
258
253
|
type UploadOutput = Awaited<
|
|
259
|
-
ReturnType<typeof
|
|
254
|
+
ReturnType<typeof router.client.publicFiles.upload>
|
|
260
255
|
>;
|
|
261
256
|
```
|
|
262
257
|
|
|
@@ -281,14 +276,6 @@ type UploadInput = BackendInputs['publicFiles']['upload'];
|
|
|
281
276
|
type UploadOutput = BackendOutputs['publicFiles']['upload'];
|
|
282
277
|
```
|
|
283
278
|
|
|
284
|
-
The
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
```ts
|
|
288
|
-
type BackendOutputs = InferClientOutputs<
|
|
289
|
-
typeof router,
|
|
290
|
-
typeof customProvider
|
|
291
|
-
>;
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
`InferClientResponse` remains as a deprecated alias of `InferClientOutputs`.
|
|
279
|
+
The helpers infer capabilities and provider-specific types directly from the
|
|
280
|
+
router, including custom providers. Use `EdgeStoreClient<typeof router>` for
|
|
281
|
+
the complete backend client type.
|
|
@@ -2,6 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
Source: https://next.edgestore.dev/docs/configuration
|
|
4
4
|
|
|
5
|
+
## Router and Provider
|
|
6
|
+
|
|
7
|
+
Import `initEdgeStore` from `@edgestore/server`. The router uses the hosted
|
|
8
|
+
EdgeStore provider by default and exposes its backend client as `router.client`:
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
const es = initEdgeStore.create();
|
|
12
|
+
const router = es.router({
|
|
13
|
+
publicFiles: es.fileBucket(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const handler = createEdgeStoreNextHandler({ router });
|
|
17
|
+
const backendClient = router.client;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Chain `.provider()` to use another provider or custom credentials:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { s3 } from '@edgestore/server/providers/s3';
|
|
24
|
+
|
|
25
|
+
const router = es.router({
|
|
26
|
+
publicFiles: es.fileBucket(),
|
|
27
|
+
}).provider(s3());
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`.provider()` returns a new router. It preserves bucket definitions, while
|
|
31
|
+
leaving existing routers, clients, and handlers bound to their original
|
|
32
|
+
provider. The backend client exposes only methods supported by the
|
|
33
|
+
selected provider.
|
|
34
|
+
|
|
35
|
+
The default hosted provider is initialized when handling requests or when
|
|
36
|
+
`router.client` is first accessed. Defining a router or overriding its provider
|
|
37
|
+
does not require hosted EdgeStore credentials. Each router reuses its provider
|
|
38
|
+
and backend client after initialization.
|
|
39
|
+
|
|
40
|
+
Keep the router object on the server; import only its type into frontend code.
|
|
41
|
+
|
|
5
42
|
## Bucket Types
|
|
6
43
|
|
|
7
44
|
There are two types of file buckets: `IMAGE` and `FILE`. Both types of buckets work basically the same way, but the `IMAGE` bucket only accepts [certain mime types](https://next.edgestore.dev/docs/configuration#image-bucket-accepted-mime-types).
|
|
@@ -33,12 +70,11 @@ const router = es.router({
|
|
|
33
70
|
Many of the functions that you can use to configure your file buckets receive a `context` object as an argument. This object is generated by the `createContext` function that you pass to your router configuration.
|
|
34
71
|
|
|
35
72
|
```ts
|
|
36
|
-
import {
|
|
73
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
37
74
|
import {
|
|
38
75
|
type CreateContextOptions,
|
|
39
76
|
createEdgeStoreNextHandler,
|
|
40
77
|
} from '@edgestore/server/adapters/next/app';
|
|
41
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
42
78
|
import { z } from 'zod';
|
|
43
79
|
|
|
44
80
|
type Context = {
|
|
@@ -59,13 +95,8 @@ const es = initEdgeStore.context<Context>().create();
|
|
|
59
95
|
|
|
60
96
|
// ...
|
|
61
97
|
|
|
62
|
-
const configuredEdgeStore = createEdgeStore({
|
|
63
|
-
router,
|
|
64
|
-
provider: edgestore(),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
98
|
export default createEdgeStoreNextHandler({
|
|
68
|
-
|
|
99
|
+
router,
|
|
69
100
|
/**
|
|
70
101
|
* The context is generated and saved to a cookie
|
|
71
102
|
* in the first load of the page.
|
|
@@ -223,9 +254,9 @@ Other available operators are: `eq`, `not`, `gt`, `gte`, `lt`, `lte`, `in`, `con
|
|
|
223
254
|
|
|
224
255
|
> NOTE
|
|
225
256
|
>
|
|
226
|
-
> The access control functionality uses
|
|
257
|
+
> The access control functionality uses a partitioned cookie that EdgeStore sets on the file origin when the provider initializes. Protected files load directly from that origin, including in local development.
|
|
227
258
|
>
|
|
228
|
-
>
|
|
259
|
+
> The `<Image />` component from `next/image` does not forward the cookies in the request, so protected images won't be displayed. You will need to use the `<img />` tag instead.
|
|
229
260
|
|
|
230
261
|
## Limit parallel uploads
|
|
231
262
|
|
package/agent-docs/express.md
CHANGED
|
@@ -9,7 +9,7 @@ Source: https://next.edgestore.dev/docs/adapters/express
|
|
|
9
9
|
Packages to install (use the application’s package manager):
|
|
10
10
|
|
|
11
11
|
```text
|
|
12
|
-
@edgestore/server @edgestore/react
|
|
12
|
+
@edgestore/server@rc @edgestore/react@rc
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Environment variables
|
|
@@ -35,9 +35,8 @@ env file before constructing the provider; Express does not load it automaticall
|
|
|
35
35
|
This bucket's files are accessible to anyone with the link.
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
-
import {
|
|
38
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
39
39
|
import { createEdgeStoreExpressHandler } from '@edgestore/server/adapters/express';
|
|
40
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
41
40
|
import cookieParser from 'cookie-parser';
|
|
42
41
|
import cors from 'cors';
|
|
43
42
|
import express from 'express';
|
|
@@ -64,13 +63,8 @@ const router = es.router({
|
|
|
64
63
|
|
|
65
64
|
export type EdgeStoreRouter = typeof router;
|
|
66
65
|
|
|
67
|
-
const configuredEdgeStore = createEdgeStore({
|
|
68
|
-
router,
|
|
69
|
-
provider: edgestore(),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
66
|
const handler = createEdgeStoreExpressHandler({
|
|
73
|
-
|
|
67
|
+
router,
|
|
74
68
|
});
|
|
75
69
|
|
|
76
70
|
app.get('/edgestore/*splat', handler);
|
package/agent-docs/fastify.md
CHANGED
|
@@ -9,7 +9,7 @@ Source: https://next.edgestore.dev/docs/adapters/fastify
|
|
|
9
9
|
Packages to install (use the application’s package manager):
|
|
10
10
|
|
|
11
11
|
```text
|
|
12
|
-
@edgestore/server @edgestore/react
|
|
12
|
+
@edgestore/server@rc @edgestore/react@rc
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Environment variables
|
|
@@ -35,9 +35,8 @@ load it automatically. Reuse existing cookie and CORS registrations.
|
|
|
35
35
|
This bucket's files are accessible to anyone with the link.
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
-
import {
|
|
38
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
39
39
|
import { createEdgeStoreFastifyHandler } from '@edgestore/server/adapters/fastify';
|
|
40
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
41
40
|
import cors from '@fastify/cors';
|
|
42
41
|
import cookie from '@fastify/cookie';
|
|
43
42
|
import fastify from 'fastify';
|
|
@@ -62,13 +61,8 @@ const router = es.router({
|
|
|
62
61
|
|
|
63
62
|
export type EdgeStoreRouter = typeof router;
|
|
64
63
|
|
|
65
|
-
const configuredEdgeStore = createEdgeStore({
|
|
66
|
-
router,
|
|
67
|
-
provider: edgestore(),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
64
|
const handler = createEdgeStoreFastifyHandler({
|
|
71
|
-
|
|
65
|
+
router,
|
|
72
66
|
});
|
|
73
67
|
|
|
74
68
|
app.get('/edgestore/*', handler);
|
package/agent-docs/hono.md
CHANGED
|
@@ -11,7 +11,7 @@ Install `@edgestore/server` in the backend and `@edgestore/react` in the fronten
|
|
|
11
11
|
Packages to install (use the application’s package manager):
|
|
12
12
|
|
|
13
13
|
```text
|
|
14
|
-
@edgestore/server @edgestore/react
|
|
14
|
+
@edgestore/server@rc @edgestore/react@rc
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
### Environment variables
|
|
@@ -35,9 +35,8 @@ EDGE_STORE_SECRET_KEY=your-secret-key
|
|
|
35
35
|
This bucket's files are accessible to anyone with the link.
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
-
import {
|
|
38
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
39
39
|
import { createEdgeStoreHonoHandler } from '@edgestore/server/adapters/hono';
|
|
40
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
41
40
|
import { serve } from '@hono/node-server';
|
|
42
41
|
import { Hono } from 'hono';
|
|
43
42
|
import { cors } from 'hono/cors';
|
|
@@ -62,13 +61,8 @@ const router = es.router({
|
|
|
62
61
|
|
|
63
62
|
export type EdgeStoreRouter = typeof router;
|
|
64
63
|
|
|
65
|
-
const configuredEdgeStore = createEdgeStore({
|
|
66
|
-
router,
|
|
67
|
-
provider: edgestore(),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
64
|
const handler = createEdgeStoreHonoHandler({
|
|
71
|
-
|
|
65
|
+
router,
|
|
72
66
|
});
|
|
73
67
|
|
|
74
68
|
app.all('/edgestore/*', handler);
|
package/agent-docs/next.md
CHANGED
|
@@ -7,7 +7,7 @@ Source: https://next.edgestore.dev/docs/quick-start
|
|
|
7
7
|
Packages to install (use the application’s package manager):
|
|
8
8
|
|
|
9
9
|
```text
|
|
10
|
-
@edgestore/server @edgestore/react
|
|
10
|
+
@edgestore/server@rc @edgestore/react@rc
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### Environment Variables
|
|
@@ -32,9 +32,8 @@ Choose your router below. This bucket's files are accessible to anyone with the
|
|
|
32
32
|
Example: tab="app" title="src/app/api/edgestore/\[...edgestore]/route.ts"
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
|
-
import {
|
|
35
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
36
36
|
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';
|
|
37
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
38
37
|
|
|
39
38
|
const es = initEdgeStore.create();
|
|
40
39
|
|
|
@@ -45,13 +44,8 @@ const router = es.router({
|
|
|
45
44
|
publicFiles: es.fileBucket(),
|
|
46
45
|
});
|
|
47
46
|
|
|
48
|
-
const configuredEdgeStore = createEdgeStore({
|
|
49
|
-
router,
|
|
50
|
-
provider: edgestore(),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
47
|
const handler = createEdgeStoreNextHandler({
|
|
54
|
-
|
|
48
|
+
router,
|
|
55
49
|
});
|
|
56
50
|
|
|
57
51
|
export { handler as GET, handler as POST };
|
|
@@ -65,9 +59,8 @@ export type EdgeStoreRouter = typeof router;
|
|
|
65
59
|
Example: tab="pages" title="src/pages/api/edgestore/\[...edgestore].ts"
|
|
66
60
|
|
|
67
61
|
```ts
|
|
68
|
-
import {
|
|
62
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
69
63
|
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/pages';
|
|
70
|
-
import { edgestore } from '@edgestore/server/providers/edgestore';
|
|
71
64
|
|
|
72
65
|
const es = initEdgeStore.create();
|
|
73
66
|
|
|
@@ -78,13 +71,8 @@ const router = es.router({
|
|
|
78
71
|
publicFiles: es.fileBucket(),
|
|
79
72
|
});
|
|
80
73
|
|
|
81
|
-
const configuredEdgeStore = createEdgeStore({
|
|
82
|
-
router,
|
|
83
|
-
provider: edgestore(),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
74
|
export default createEdgeStoreNextHandler({
|
|
87
|
-
|
|
75
|
+
router,
|
|
88
76
|
});
|
|
89
77
|
|
|
90
78
|
/**
|
|
@@ -2,86 +2,177 @@
|
|
|
2
2
|
|
|
3
3
|
Source: https://next.edgestore.dev/docs/providers/azure-blob
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use the Azure Blob provider when your files must live in your own Azure
|
|
6
|
+
storage account. It supports direct browser uploads, automatic block uploads
|
|
7
|
+
for large files, backend uploads, private signed reads, and stable key
|
|
8
|
+
references. Your application owns the container's CORS, access, and lifecycle
|
|
9
|
+
configuration.
|
|
6
10
|
|
|
7
11
|
The provider creates short-lived, blob-scoped SAS URLs for browser uploads and
|
|
8
|
-
private reads.
|
|
9
|
-
features such as image processing
|
|
12
|
+
private reads. The account key stays on the server, and permanent file URLs
|
|
13
|
+
never contain credentials. Hosted features such as image processing are not
|
|
14
|
+
available.
|
|
10
15
|
|
|
11
16
|
## Installation
|
|
12
17
|
|
|
13
|
-
You need to install some peer dependencies to use this provider.
|
|
14
|
-
|
|
15
18
|
Packages to install (use the application’s package manager):
|
|
16
19
|
|
|
17
20
|
```text
|
|
18
21
|
@azure/storage-blob
|
|
19
22
|
```
|
|
20
23
|
|
|
21
|
-
Then configure the provider together with the router and pass the resulting
|
|
22
|
-
`configuredEdgeStore` instance to the adapter.
|
|
23
|
-
|
|
24
24
|
```ts
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
createEdgeStoreNextHandler,
|
|
28
|
-
type CreateContextOptions,
|
|
29
|
-
} from '@edgestore/server/adapters/next/pages';
|
|
30
|
-
// [!code ++]
|
|
25
|
+
import { initEdgeStore } from '@edgestore/server';
|
|
31
26
|
import { azureBlob } from '@edgestore/server/providers/azure-blob';
|
|
32
|
-
import { z } from 'zod';
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
const es = initEdgeStore.create();
|
|
29
|
+
export const router = es.router({
|
|
30
|
+
documents: es.fileBucket().accessControl('private'),
|
|
31
|
+
}).provider(
|
|
32
|
+
azureBlob({
|
|
33
|
+
storageAccountName: 'myaccount',
|
|
34
|
+
containerName: 'edgestore',
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export type EdgeStoreRouter = typeof router;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Pass `router` to your framework adapter as its `router` option. Set
|
|
42
|
+
`ES_AZURE_ACCOUNT_KEY` on the server, and set `EDGE_STORE_JWT_SECRET` to a
|
|
43
|
+
stable random secret, for example one generated with `openssl rand -base64 32`.
|
|
44
|
+
All application instances must share it. Credentials are only checked when the
|
|
45
|
+
provider is first used, so defining a router does not require them.
|
|
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` | `EDGE_STORE_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 `EDGE_STORE_JWT_SECRET` or `EDGE_STORE_SECRET_KEY` |
|
|
60
|
+
|
|
61
|
+
Signed URL lifetimes must be between 1 and 604800 seconds. Upload URLs grant
|
|
62
|
+
only create/write permission on one blob, and read URLs grant only read
|
|
63
|
+
permission.
|
|
64
|
+
|
|
65
|
+
## Paths and object settings
|
|
35
66
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
67
|
+
Blobs are stored as `<router bucket>/<path>`. The default path adds `_public/`
|
|
68
|
+
for public buckets, then the router path values and the file name. Use `path`
|
|
69
|
+
to change everything after the router bucket, which is always kept:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
azureBlob({
|
|
73
|
+
path: ({ defaultPath }) => `tenants/${defaultPath}`,
|
|
74
|
+
objectOptions: {
|
|
75
|
+
cacheControl: 'private, max-age=3600',
|
|
76
|
+
contentDisposition: 'attachment',
|
|
77
|
+
metadata: { source: 'edgestore' },
|
|
78
|
+
},
|
|
40
79
|
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`objectOptions` can also be a function that receives the same arguments as
|
|
83
|
+
`path`. The content type comes from the uploaded file. Browser and backend
|
|
84
|
+
uploads apply the same settings.
|
|
85
|
+
|
|
86
|
+
## Large files and cancellation
|
|
87
|
+
|
|
88
|
+
Files above the threshold are uploaded as blocks, in parallel, with retries.
|
|
89
|
+
The browser requests block upload URLs as it reaches each block, so
|
|
90
|
+
`uploadUrlExpiresIn` only needs to cover one block transfer. A session can
|
|
91
|
+
request URLs and complete until `multipart.sessionExpiresIn` passes. Before
|
|
92
|
+
committing, the provider checks that every block exists with the expected size,
|
|
93
|
+
which catches incomplete uploads.
|
|
94
|
+
|
|
95
|
+
Azure has no multipart session to cancel. Blocks that are never committed are
|
|
96
|
+
discarded automatically after seven days, so canceled and failed uploads need
|
|
97
|
+
no lifecycle rule.
|
|
98
|
+
|
|
99
|
+
Backend uploads use the same paths, object settings, and block configuration,
|
|
100
|
+
and send up to four blocks at a time.
|
|
41
101
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
102
|
+
## Private files
|
|
103
|
+
|
|
104
|
+
Use `accessControl('private')` for private buckets. Cookie-based access-control
|
|
105
|
+
rules are not supported and fail at initialization. Create read URLs from the
|
|
106
|
+
backend client:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const { signedUrl } = await router.client.documents.createSignedUrl({
|
|
110
|
+
url: { key: 'documents/report.pdf' },
|
|
111
|
+
expiresIn: 300,
|
|
45
112
|
});
|
|
46
113
|
```
|
|
47
114
|
|
|
48
|
-
|
|
115
|
+
Add `.autoSignedUrls({ expiresIn: 300 })` to a private router bucket to receive
|
|
116
|
+
a read URL with each upload response.
|
|
117
|
+
|
|
118
|
+
## Container configuration
|
|
119
|
+
|
|
120
|
+
Keep the container private. Azure grants anonymous read access to a whole
|
|
121
|
+
container, not to a prefix, so public buckets need their own read path.
|
|
122
|
+
Public uploads return an unsigned URL under `_public/`, which a private
|
|
123
|
+
container answers with 403. Either:
|
|
124
|
+
|
|
125
|
+
* serve `_public/` through a CDN or proxy that can read the private container,
|
|
126
|
+
such as Azure Front Door with a private origin, and set `baseUrl` to it; or
|
|
127
|
+
* if the container holds only public buckets, set its public access level to
|
|
128
|
+
**Blob** (anonymous reads of individual blobs, no listing). Every file in
|
|
129
|
+
that container is then readable by URL, so never combine this with private
|
|
130
|
+
buckets.
|
|
131
|
+
|
|
132
|
+
Configure blob service CORS for your application origins so browsers can
|
|
133
|
+
upload:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
[{
|
|
137
|
+
"AllowedOrigins": ["http://localhost:3000", "https://app.example.com"],
|
|
138
|
+
"AllowedMethods": ["PUT", "GET", "HEAD"],
|
|
139
|
+
"AllowedHeaders": ["*"],
|
|
140
|
+
"ExposedHeaders": ["*"],
|
|
141
|
+
"MaxAgeInSeconds": 3600
|
|
142
|
+
}]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Local development with Azurite
|
|
146
|
+
|
|
147
|
+
[Azurite](https://learn.microsoft.com/azure/storage/common/storage-use-azurite)
|
|
148
|
+
emulates Blob Storage locally:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0
|
|
152
|
+
```
|
|
49
153
|
|
|
50
154
|
```ts
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* Can also be set via the `ES_AZURE_ACCOUNT_KEY` environment variable.
|
|
60
|
-
*/
|
|
61
|
-
storageAccountKey?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Azure Blob Storage container name
|
|
64
|
-
* Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
|
|
65
|
-
*/
|
|
66
|
-
containerName?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Optional base URL for Azurite or another compatible endpoint.
|
|
69
|
-
* Can also be set via the `ES_AZURE_BASE_URL` environment variable.
|
|
70
|
-
*/
|
|
71
|
-
customBaseUrl?: string;
|
|
72
|
-
/**
|
|
73
|
-
* Lifetime of browser upload URLs in seconds.
|
|
74
|
-
* @default 3600
|
|
75
|
-
*/
|
|
76
|
-
uploadUrlExpiresIn?: number;
|
|
77
|
-
/**
|
|
78
|
-
* Default lifetime of private read URLs in seconds.
|
|
79
|
-
* @default 3600
|
|
80
|
-
*/
|
|
81
|
-
signedUrlExpiresIn?: number;
|
|
82
|
-
};
|
|
155
|
+
azureBlob({
|
|
156
|
+
storageAccountName: 'devstoreaccount1',
|
|
157
|
+
// Azurite's documented development account key.
|
|
158
|
+
storageAccountKey:
|
|
159
|
+
'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==',
|
|
160
|
+
containerName: 'edgestore',
|
|
161
|
+
endpoint: 'http://127.0.0.1:10000/devstoreaccount1',
|
|
162
|
+
});
|
|
83
163
|
```
|
|
84
164
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
165
|
+
## Limitations
|
|
166
|
+
|
|
167
|
+
* `temporary` and `replaceTargetUrl` are rejected. Track application-owned files
|
|
168
|
+
in your database and delete old files after a successful replacement.
|
|
169
|
+
* Azure SAS URLs grant write access to one blob and cannot limit its size or
|
|
170
|
+
the write operation. A browser holding an upload URL can therefore write
|
|
171
|
+
that blob directly, with any size and blob headers. The router's `maxSize`,
|
|
172
|
+
mime-type checks, and `objectOptions` apply to the declared upload and to
|
|
173
|
+
backend uploads, but are not enforced on bytes a browser sends. If you need
|
|
174
|
+
those guarantees, validate each stored blob after upload from a storage
|
|
175
|
+
event, for example an Event Grid `BlobCreated` subscription that triggers an
|
|
176
|
+
Azure Function, and delete blobs that fail your checks.
|
|
177
|
+
* Confirmation, listing, restore, and generated thumbnails are unsupported.
|
|
178
|
+
* Only account-key authentication is supported.
|