@edgestore/server 1.0.0-next.3 → 1.0.0-next.4

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.
@@ -0,0 +1,94 @@
1
+ # Quick Start
2
+
3
+ Source: https://next.edgestore.dev/docs/quick-start
4
+
5
+ ### Install
6
+
7
+ Packages to install (use the application’s package manager):
8
+
9
+ ```text
10
+ @edgestore/server @edgestore/react
11
+ ```
12
+
13
+ ### Environment Variables
14
+
15
+ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/) to the backend env file:
16
+
17
+ Example: title=".env.local"
18
+
19
+ ```sh
20
+ EDGE_STORE_ACCESS_KEY=your-access-key
21
+ EDGE_STORE_SECRET_KEY=your-secret-key
22
+ ```
23
+
24
+ > WARNING
25
+ >
26
+ > Use the app's existing env file, or `.env.local` for a new app. Keep it gitignored.
27
+
28
+ ### Backend
29
+
30
+ Choose your router below. This bucket's files are accessible to anyone with the link.
31
+
32
+ Example: tab="app" title="src/app/api/edgestore/\[...edgestore]/route.ts"
33
+
34
+ ```ts
35
+ import { createEdgeStore, initEdgeStore } from '@edgestore/server';
36
+ import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';
37
+ import { edgestore } from '@edgestore/server/providers/edgestore';
38
+
39
+ const es = initEdgeStore.create();
40
+
41
+ /**
42
+ * This is the main router for the EdgeStore buckets.
43
+ */
44
+ const router = es.router({
45
+ publicFiles: es.fileBucket(),
46
+ });
47
+
48
+ const configuredEdgeStore = createEdgeStore({
49
+ router,
50
+ provider: edgestore(),
51
+ });
52
+
53
+ const handler = createEdgeStoreNextHandler({
54
+ edgestore: configuredEdgeStore,
55
+ });
56
+
57
+ export { handler as GET, handler as POST };
58
+
59
+ /**
60
+ * This type is used to create the type-safe client for the frontend.
61
+ */
62
+ export type EdgeStoreRouter = typeof router;
63
+ ```
64
+
65
+ Example: tab="pages" title="src/pages/api/edgestore/\[...edgestore].ts"
66
+
67
+ ```ts
68
+ import { createEdgeStore, initEdgeStore } from '@edgestore/server';
69
+ import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/pages';
70
+ import { edgestore } from '@edgestore/server/providers/edgestore';
71
+
72
+ const es = initEdgeStore.create();
73
+
74
+ /**
75
+ * This is the main router for the edgestore buckets.
76
+ */
77
+ const router = es.router({
78
+ publicFiles: es.fileBucket(),
79
+ });
80
+
81
+ const configuredEdgeStore = createEdgeStore({
82
+ router,
83
+ provider: edgestore(),
84
+ });
85
+
86
+ export default createEdgeStoreNextHandler({
87
+ edgestore: configuredEdgeStore,
88
+ });
89
+
90
+ /**
91
+ * This type is used to create the type-safe client for the frontend.
92
+ */
93
+ export type EdgeStoreRouter = typeof router;
94
+ ```
@@ -0,0 +1,87 @@
1
+ # Azure Blob Storage
2
+
3
+ Source: https://next.edgestore.dev/docs/providers/azure-blob
4
+
5
+ You can also use the EdgeStore package with your own Azure Blob Storage. You might want to do that in case you have strict company policies that require you to have all the data in your own Azure account.
6
+
7
+ The provider creates short-lived, blob-scoped SAS URLs for browser uploads and
8
+ private reads. Permanent file URLs never contain credentials. Advanced hosted
9
+ features such as image processing still require separate infrastructure.
10
+
11
+ ## Installation
12
+
13
+ You need to install some peer dependencies to use this provider.
14
+
15
+ Packages to install (use the application’s package manager):
16
+
17
+ ```text
18
+ @azure/storage-blob
19
+ ```
20
+
21
+ Then configure the provider together with the router and pass the resulting
22
+ `configuredEdgeStore` instance to the adapter.
23
+
24
+ ```ts
25
+ import { createEdgeStore, initEdgeStore } from '@edgestore/server';
26
+ import {
27
+ createEdgeStoreNextHandler,
28
+ type CreateContextOptions,
29
+ } from '@edgestore/server/adapters/next/pages';
30
+ // [!code ++]
31
+ import { azureBlob } from '@edgestore/server/providers/azure-blob';
32
+ import { z } from 'zod';
33
+
34
+ // ...
35
+
36
+ const configuredEdgeStore = createEdgeStore({
37
+ router,
38
+ // [!code ++]
39
+ provider: azureBlob(),
40
+ });
41
+
42
+ export default createEdgeStoreNextHandler<Context>({
43
+ edgestore: configuredEdgeStore,
44
+ createContext,
45
+ });
46
+ ```
47
+
48
+ ## Options
49
+
50
+ ```ts
51
+ export type AzureBlobProviderOptions = {
52
+ /**
53
+ * The storage account name for Azure Blob Storage
54
+ * Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
55
+ */
56
+ storageAccountName?: string;
57
+ /**
58
+ * Account key used for server-side requests and signing short-lived URLs.
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
+ };
83
+ ```
84
+
85
+ The account key stays on the server. Upload URLs receive only create/write
86
+ permissions, while private read URLs receive only read permission and expire
87
+ independently.
@@ -0,0 +1,266 @@
1
+ # Custom
2
+
3
+ Source: https://next.edgestore.dev/docs/providers/custom
4
+
5
+ Use `defineProvider` to integrate another storage service or a custom storage
6
+ implementation. The same provider instance powers the EdgeStore HTTP handler
7
+ and the router-derived backend client:
8
+
9
+ ```ts
10
+ const configuredEdgeStore = createEdgeStore({
11
+ router,
12
+ provider: myProvider,
13
+ });
14
+
15
+ createEdgeStoreNextHandler({ edgestore: configuredEdgeStore });
16
+ configuredEdgeStore.client.files.get({ key: 'files/report.pdf' });
17
+ ```
18
+
19
+ Method inputs are contextually typed. File references, cursors, returned file
20
+ fields, and provider-specific errors are inferred from the definition, so you
21
+ do not need to maintain a parallel provider interface or backend-operation
22
+ map.
23
+
24
+ ## Minimal provider
25
+
26
+ A provider must implement the upload-planning operations used by browser
27
+ uploads and `files.get`, which EdgeStore uses to resolve a file before running
28
+ router lifecycle hooks. Other operations are optional and only appear on the
29
+ backend client when implemented.
30
+
31
+ This single-part example delegates storage-specific work to a small driver:
32
+
33
+ Example: title="src/lib/my-provider.ts"
34
+
35
+ ```ts
36
+ import { defineProvider } from '@edgestore/server';
37
+ import { z } from 'zod';
38
+ import { storage } from './storage';
39
+
40
+ const baseUrl = 'https://files.example.com';
41
+
42
+ export const myProvider = defineProvider({
43
+ name: 'my-storage',
44
+ baseUrl,
45
+ async init() {
46
+ return {};
47
+ },
48
+ reference: {
49
+ schema: z.object({ key: z.string().min(1) }),
50
+ fromUrl(url) {
51
+ return { key: new URL(url).pathname.slice(1) };
52
+ },
53
+ },
54
+ uploads: {
55
+ async request({ bucketName, fileInfo }) {
56
+ const key = storage.createKey({ bucketName, fileInfo });
57
+ return {
58
+ uploadUrl: await storage.signUpload(key),
59
+ accessUrl: `${baseUrl}/${key}`,
60
+ };
61
+ },
62
+ },
63
+ files: {
64
+ async get({ bucketName, file }) {
65
+ const object = await storage.head({
66
+ bucketName,
67
+ key: file.key,
68
+ });
69
+ return {
70
+ url: `${baseUrl}/${file.key}`,
71
+ sizeBytes: object.size,
72
+ path: object.path,
73
+ metadata: object.metadata,
74
+ uploadedAt: object.createdAt,
75
+ updatedAt: object.updatedAt,
76
+ };
77
+ },
78
+ },
79
+ });
80
+ ```
81
+
82
+ The resulting backend client exposes `get`, but not `upload`, `list`, or
83
+ mutations, because those optional capabilities were not defined.
84
+
85
+ ## Complete provider
86
+
87
+ A complete provider can add direct backend uploads, pagination, mutations, and
88
+ signed read URLs. Standard Schema transformations let callers use convenient
89
+ input references while provider methods receive one normalized output shape:
90
+
91
+ Example: title="src/lib/my-provider.ts"
92
+
93
+ ```ts
94
+ import { defineProvider } from '@edgestore/server';
95
+ import { z } from 'zod';
96
+ import { storage } from './storage';
97
+
98
+ const baseUrl = 'https://files.example.com';
99
+ const referenceSchema = z
100
+ .union([z.string().url(), z.object({ key: z.string().min(1) })])
101
+ .transform((reference) =>
102
+ typeof reference === 'string'
103
+ ? { key: new URL(reference).pathname.slice(1) }
104
+ : reference,
105
+ );
106
+
107
+ const toFile = (object: Awaited<ReturnType<typeof storage.head>>) => ({
108
+ url: `${baseUrl}/${object.key}`,
109
+ sizeBytes: object.size,
110
+ path: object.path,
111
+ metadata: object.metadata,
112
+ uploadedAt: object.createdAt,
113
+ updatedAt: object.updatedAt,
114
+ etag: object.etag,
115
+ });
116
+
117
+ export const myProvider = defineProvider({
118
+ name: 'my-storage',
119
+ baseUrl,
120
+ async init() {
121
+ return {};
122
+ },
123
+ reference: {
124
+ schema: referenceSchema,
125
+ fromUrl: (url) => url,
126
+ },
127
+ uploads: {
128
+ async request({ bucketName, fileInfo }) {
129
+ return storage.createUploadPlan({ bucketName, fileInfo });
130
+ },
131
+ multipart: {
132
+ async requestParts({ multipart, path }) {
133
+ return storage.createUploadParts({ multipart, path });
134
+ },
135
+ async complete({ uploadId, key, parts }) {
136
+ await storage.completeMultipart({ uploadId, key, parts });
137
+ },
138
+ },
139
+ async upload({ bucketName, fileInfo, source, signal, onProgress }) {
140
+ const object = await storage.upload({
141
+ bucketName,
142
+ fileInfo,
143
+ source,
144
+ signal,
145
+ onProgress,
146
+ });
147
+ return { file: toFile(object) };
148
+ },
149
+ },
150
+ files: {
151
+ cursorSchema: z.string().min(1),
152
+ async get({ bucketName, file }) {
153
+ return toFile(
154
+ await storage.head({
155
+ bucketName,
156
+ key: file.key,
157
+ }),
158
+ );
159
+ },
160
+ async list({ bucketName, cursor, filter, limit = 20 }) {
161
+ const page = await storage.list({ bucketName, cursor, filter, limit });
162
+ return {
163
+ items: page.objects.map(toFile),
164
+ limit,
165
+ nextCursor: page.nextCursor,
166
+ hasMore: page.nextCursor !== null,
167
+ };
168
+ },
169
+ async confirm({ bucketName, files }) {
170
+ return {
171
+ results: await storage.confirm({
172
+ bucketName,
173
+ files,
174
+ }),
175
+ };
176
+ },
177
+ async delete({ bucketName, files }) {
178
+ return {
179
+ results: await storage.delete({
180
+ bucketName,
181
+ files,
182
+ }),
183
+ };
184
+ },
185
+ async restore({ bucketName, files }) {
186
+ return {
187
+ results: await storage.restore({
188
+ bucketName,
189
+ files,
190
+ }),
191
+ };
192
+ },
193
+ async getSignedUrls({ bucketName, files, expiresIn = 3600 }) {
194
+ return Promise.all(
195
+ files.map(async (file) => ({
196
+ url: `${baseUrl}/${file.key}`,
197
+ signedUrl: await storage.signRead({
198
+ bucketName,
199
+ key: file.key,
200
+ expiresIn,
201
+ }),
202
+ expiresAt: new Date(Date.now() + expiresIn * 1000),
203
+ expiresIn,
204
+ })),
205
+ );
206
+ },
207
+ },
208
+ });
209
+ ```
210
+
211
+ Here, callers may pass either a URL or `{ key }`, but every provider operation
212
+ receives `{ key: string }` after runtime validation. The backend client also
213
+ inherits the string cursor, the extra `etag` file field, and any literal
214
+ mutation error codes returned by the storage driver.
215
+
216
+ The backend client uses bucket-scoped names: `get`, `list`, `confirm`,
217
+ `confirmMany`, `delete`, `deleteMany`, `restore`, `restoreMany`,
218
+ `createSignedUrl`, and `createSignedUrls`. Provider method names remain
219
+ resource operations (`files.get`, `files.list`, `files.getSignedUrls`) and do
220
+ not need to mirror that public client surface.
221
+
222
+ `get` and `list` preserve the exact file fields inferred from the provider,
223
+ including its `path` and `metadata` shapes. An `upload` result instead exposes
224
+ the path and metadata EdgeStore computed from the router, even if the storage
225
+ driver returns different placeholders.
226
+
227
+ Every file operation must enforce the logical EdgeStore `bucketName`. Treat
228
+ `bucketName` and the normalized file reference as the complete storage
229
+ identity, and reject a reference that belongs to another logical bucket. This
230
+ keeps a frontend request authorized through bucket A from loading or mutating a
231
+ file in bucket B. The official providers enforce the same ownership invariant.
232
+
233
+ Mutation providers return exactly one status for each input file, in the same
234
+ order. EdgeStore attaches the original file references and derives success and
235
+ failure counts for the public client. A provider result therefore contains
236
+ only `{ success: true }` or `{ success: false, error }`; it does not repeat the
237
+ file reference or calculate counts.
238
+
239
+ Multipart support is optional. A single-part provider defines only
240
+ `uploads.request`. When `uploads.multipart` is present, `uploads.request` may
241
+ return a multipart plan and EdgeStore exposes the matching part-request and
242
+ completion routes.
243
+
244
+ `uploads.request` and `uploads.upload` remain separate because they perform
245
+ different work: the former creates signed instructions for a browser transfer,
246
+ while the latter receives bytes and performs a privileged server-side upload.
247
+
248
+ ## Operation groups
249
+
250
+ The provider is organized by storage resource, not by caller:
251
+
252
+ * `uploads` contains browser upload planning and optional direct backend
253
+ upload.
254
+ * `files` contains canonical file operations shared by HTTP adapters and the
255
+ backend client.
256
+ * `reference` defines how frontend URLs and backend inputs become the
257
+ provider's normalized file reference.
258
+
259
+ Frontend deletion still obeys the router: EdgeStore loads every file and runs
260
+ `beforeDelete` for all of them before calling `files.delete`. The privileged
261
+ backend client calls `files.delete` directly and is responsible for its own
262
+ authorization.
263
+
264
+ The official EdgeStore, S3, and Azure Blob providers use `defineProvider`
265
+ themselves and are useful reference implementations. If your provider could be
266
+ useful to others, consider contributing it to EdgeStore.
@@ -0,0 +1,53 @@
1
+ # EdgeStore
2
+
3
+ Source: https://next.edgestore.dev/docs/providers/edgestore
4
+
5
+ The hosted `edgestore()` provider uses EdgeStore API v2. Configure it together
6
+ with your router, then pass that configured instance to the HTTP adapter.
7
+
8
+ ```ts
9
+ import { createEdgeStore, initEdgeStore } from '@edgestore/server';
10
+ import {
11
+ createEdgeStoreNextHandler,
12
+ type CreateContextOptions,
13
+ } from '@edgestore/server/adapters/next/pages';
14
+ // [!code ++]
15
+ import { edgestore } from '@edgestore/server/providers/edgestore';
16
+ import { z } from 'zod';
17
+
18
+ const configuredEdgeStore = createEdgeStore({
19
+ router,
20
+ // [!code ++]
21
+ provider: edgestore(),
22
+ });
23
+
24
+ export default createEdgeStoreNextHandler<Context>({
25
+ edgestore: configuredEdgeStore,
26
+ createContext,
27
+ });
28
+ ```
29
+
30
+ ## Options
31
+
32
+ ```ts
33
+ export type EdgeStoreProviderOptions = {
34
+ /**
35
+ * Access key for your EdgeStore project.
36
+ * Can be found in the EdgeStore dashboard.
37
+ *
38
+ * This can be omitted if the `EDGE_STORE_ACCESS_KEY` environment variable is set.
39
+ */
40
+ accessKey?: string;
41
+ /**
42
+ * Secret key for your EdgeStore project.
43
+ * Can be found in the EdgeStore dashboard.
44
+ *
45
+ * This can be omitted if the `EDGE_STORE_SECRET_KEY` environment variable is set.
46
+ */
47
+ secretKey?: string;
48
+ /**
49
+ * Override the API v2 base URL.
50
+ */
51
+ apiUrl?: string;
52
+ };
53
+ ```
@@ -0,0 +1,166 @@
1
+ # S3
2
+
3
+ Source: https://next.edgestore.dev/docs/providers/s3
4
+
5
+ You can also use the EdgeStore package with your own AWS S3 bucket. You might want to do that in case you have strict company policies that require you to have all the data in your own AWS account.
6
+
7
+ You can also use the S3 provider with other S3-compatible storage services like [MinIO](https://min.io/).
8
+
9
+ By using this provider, you will be able to use most of the basic features of EdgeStore. However, for some of the more advanced features like access control with protected files, you will have to create your own infrastructure and logic from scratch.
10
+
11
+ ## Installation
12
+
13
+ You need to install some peer dependencies to use this provider.
14
+
15
+ Packages to install (use the application’s package manager):
16
+
17
+ ```text
18
+ @aws-sdk/client-s3 @aws-sdk/s3-request-presigner
19
+ ```
20
+
21
+ Then configure the provider together with the router and pass the resulting
22
+ `configuredEdgeStore` instance to the adapter.
23
+
24
+ ```ts
25
+ import { createEdgeStore, initEdgeStore } from '@edgestore/server';
26
+ import {
27
+ createEdgeStoreNextHandler,
28
+ type CreateContextOptions,
29
+ } from '@edgestore/server/adapters/next/pages';
30
+ // [!code ++]
31
+ import { s3 } from '@edgestore/server/providers/s3';
32
+ import { z } from 'zod';
33
+
34
+ // ...
35
+
36
+ const configuredEdgeStore = createEdgeStore({
37
+ router,
38
+ // [!code ++]
39
+ provider: s3(),
40
+ });
41
+
42
+ export default createEdgeStoreNextHandler<Context>({
43
+ edgestore: configuredEdgeStore,
44
+ createContext,
45
+ });
46
+ ```
47
+
48
+ ## Options
49
+
50
+ ```ts
51
+ export type S3ProviderOptions = {
52
+ /**
53
+ * AWS SDK credentials (or credentials provider) to use for S3 requests.
54
+ *
55
+ * If unset, the AWS SDK will use its default credential provider chain
56
+ * (environment variables, shared config files, instance/task roles, etc).
57
+ */
58
+ credentials?: S3ClientConfig['credentials'];
59
+ /**
60
+ * AWS region to use.
61
+ * Can also be set via the `ES_AWS_REGION` environment variable.
62
+ */
63
+ region?: string;
64
+ /**
65
+ * Name of the S3 bucket to use.
66
+ * Can also be set via the `ES_AWS_BUCKET_NAME` environment variable.
67
+ */
68
+ bucketName?: string;
69
+ /**
70
+ * Custom endpoint for S3-compatible storage providers (e.g., MinIO).
71
+ * Can also be set via the `ES_AWS_ENDPOINT` environment variable.
72
+ */
73
+ endpoint?: string;
74
+ /**
75
+ * Force path style for S3-compatible storage providers.
76
+ * Can also be set via the `ES_AWS_FORCE_PATH_STYLE` environment variable.
77
+ * Defaults to false for AWS S3, but should be true for most S3-compatible providers.
78
+ */
79
+ forcePathStyle?: boolean;
80
+ /**
81
+ * Base URL to use for accessing files.
82
+ * Only needed if you are using a custom domain or cloudfront.
83
+ *
84
+ * Can also be set via the `EDGE_STORE_BASE_URL` environment variable.
85
+ */
86
+ baseUrl?: string;
87
+ /**
88
+ * Secret to use for encrypting JWT tokens.
89
+ * Can be generated with `openssl rand -base64 32`.
90
+ *
91
+ * Can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
92
+ */
93
+ jwtSecret?: string;
94
+ /**
95
+ * Customizes the object path beneath the logical EdgeStore bucket prefix.
96
+ *
97
+ * The logical bucket prefix is always preserved so router authorization for
98
+ * one bucket cannot access objects from another.
99
+ */
100
+ path?: (args: {
101
+ edgestoreBucketName: string;
102
+ fileInfo: FileInfo;
103
+ defaultPath: string;
104
+ }) => Promise<string> | string;
105
+ };
106
+ ```
107
+
108
+ ## Customizing S3 Object Paths
109
+
110
+ By default, the S3 provider uses the same path-generation logic as the hosted
111
+ provider. The first object-key segment is always the logical EdgeStore router
112
+ bucket. This lets multiple logical buckets safely share one physical S3 bucket:
113
+
114
+ ```text
115
+ documents/_public/acme/invoice.pdf
116
+ avatars/_public/user-123/profile.png
117
+ ```
118
+
119
+ Use `path` to customize everything beneath that protected prefix. For example,
120
+ this removes `_public` while keeping the remaining generated path:
121
+
122
+ Example: title="src/server/edgestore.ts"
123
+
124
+ ```ts
125
+ const configuredEdgeStore = createEdgeStore({
126
+ router,
127
+ provider: s3({
128
+ path: ({ defaultPath }) => {
129
+ // `documents/_public/acme/invoice.pdf`
130
+ // becomes `documents/acme/invoice.pdf`
131
+ return defaultPath.replace(/^_public\//, '');
132
+ },
133
+ }),
134
+ });
135
+
136
+ const handler = createEdgeStoreNextHandler({
137
+ edgestore: configuredEdgeStore,
138
+ createContext,
139
+ });
140
+ ```
141
+
142
+ The callback returns a path relative to the logical bucket and cannot escape
143
+ that boundary. It also receives `edgestoreBucketName` and `fileInfo` when you
144
+ need provider-specific naming logic.
145
+
146
+ If you remove `_public`, you might also want to disable the development proxy
147
+ in `createEdgeStoreProvider`.
148
+
149
+ ```ts
150
+ const { EdgeStoreProvider, useEdgeStore } =
151
+ createEdgeStoreProvider<EdgeStoreRouter>({
152
+ disableDevProxy: true,
153
+ });
154
+ ```
155
+
156
+ ## Using with Minio
157
+
158
+ You can use the S3 provider with MinIO or other S3-compatible storage providers
159
+ by setting the `endpoint` and `forcePathStyle` options.
160
+
161
+ ```ts
162
+ provider: s3({
163
+ endpoint: 'http://localhost:9000', // can be set via the `ES_AWS_ENDPOINT` environment variable
164
+ forcePathStyle: true, // can be set via the `ES_AWS_FORCE_PATH_STYLE` environment variable
165
+ }),
166
+ ```