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

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.
Files changed (115) hide show
  1. package/README.md +2 -8
  2. package/agent-docs/README.md +20 -0
  3. package/agent-docs/astro.md +147 -0
  4. package/agent-docs/backend-client.md +284 -0
  5. package/agent-docs/configuration.md +300 -0
  6. package/agent-docs/express.md +124 -0
  7. package/agent-docs/fastify.md +123 -0
  8. package/agent-docs/hono.md +131 -0
  9. package/agent-docs/next.md +82 -0
  10. package/agent-docs/provider-azure-blob.md +85 -0
  11. package/agent-docs/provider-custom.md +281 -0
  12. package/agent-docs/provider-edgestore.md +53 -0
  13. package/agent-docs/provider-s3.md +270 -0
  14. package/agent-docs/remix.md +117 -0
  15. package/agent-docs/tanstack-start.md +99 -0
  16. package/agent-docs/troubleshooting.md +83 -0
  17. package/dist/adapters/astro/index.d.ts +2 -2
  18. package/dist/adapters/astro/index.d.ts.map +1 -1
  19. package/dist/adapters/astro/index.js +1 -2
  20. package/dist/adapters/dispatcher.d.ts +2 -3
  21. package/dist/adapters/dispatcher.d.ts.map +1 -1
  22. package/dist/adapters/dispatcher.js +17 -22
  23. package/dist/adapters/express/index.d.ts +2 -2
  24. package/dist/adapters/express/index.d.ts.map +1 -1
  25. package/dist/adapters/express/index.js +1 -5
  26. package/dist/adapters/fastify/index.d.ts +2 -2
  27. package/dist/adapters/fastify/index.d.ts.map +1 -1
  28. package/dist/adapters/fastify/index.js +1 -5
  29. package/dist/adapters/hono/index.d.ts +2 -2
  30. package/dist/adapters/hono/index.d.ts.map +1 -1
  31. package/dist/adapters/hono/index.js +1 -2
  32. package/dist/adapters/next/app/index.d.ts +2 -2
  33. package/dist/adapters/next/app/index.d.ts.map +1 -1
  34. package/dist/adapters/next/app/index.js +1 -2
  35. package/dist/adapters/next/pages/index.d.ts +2 -2
  36. package/dist/adapters/next/pages/index.d.ts.map +1 -1
  37. package/dist/adapters/next/pages/index.js +1 -5
  38. package/dist/adapters/remix/index.d.ts +2 -2
  39. package/dist/adapters/remix/index.d.ts.map +1 -1
  40. package/dist/adapters/remix/index.js +1 -2
  41. package/dist/adapters/shared.d.ts +45 -67
  42. package/dist/adapters/shared.d.ts.map +1 -1
  43. package/dist/adapters/shared.js +60 -97
  44. package/dist/adapters/start/index.d.ts +2 -2
  45. package/dist/adapters/start/index.d.ts.map +1 -1
  46. package/dist/adapters/start/index.js +1 -2
  47. package/dist/core/client/bucketClient.d.ts +0 -1
  48. package/dist/core/client/bucketClient.d.ts.map +1 -1
  49. package/dist/core/client/bucketClient.js +6 -28
  50. package/dist/core/client/index.d.ts +29 -26
  51. package/dist/core/client/index.d.ts.map +1 -1
  52. package/dist/core/client/index.js +2 -3
  53. package/dist/core/index.d.ts +2 -20
  54. package/dist/core/index.d.ts.map +1 -1
  55. package/dist/core/index.js +2 -13
  56. package/dist/core/provider.d.ts +11 -1
  57. package/dist/core/provider.d.ts.map +1 -1
  58. package/dist/core/provider.js +21 -1
  59. package/dist/core/router.d.ts +25 -0
  60. package/dist/core/router.d.ts.map +1 -0
  61. package/dist/core/router.js +49 -0
  62. package/dist/core/routerRules.d.ts +1 -1
  63. package/dist/index.d.ts +2 -2
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +1 -2
  66. package/dist/providers/azure-blob/index.d.ts +7 -0
  67. package/dist/providers/azure-blob/index.d.ts.map +1 -1
  68. package/dist/providers/azure-blob/index.js +7 -0
  69. package/dist/providers/edgestore/index.d.ts +10 -11
  70. package/dist/providers/edgestore/index.d.ts.map +1 -1
  71. package/dist/providers/edgestore/index.js +26 -15
  72. package/dist/providers/s3/backendUpload.d.ts +13 -0
  73. package/dist/providers/s3/backendUpload.d.ts.map +1 -0
  74. package/dist/providers/s3/backendUpload.js +97 -0
  75. package/dist/providers/s3/index.d.ts +57 -93
  76. package/dist/providers/s3/index.d.ts.map +1 -1
  77. package/dist/providers/s3/index.js +241 -90
  78. package/dist/providers/s3/keys.d.ts +10 -0
  79. package/dist/providers/s3/keys.d.ts.map +1 -0
  80. package/dist/providers/s3/keys.js +40 -0
  81. package/dist/providers/s3/multipart.d.ts +25 -0
  82. package/dist/providers/s3/multipart.d.ts.map +1 -0
  83. package/dist/providers/s3/multipart.js +132 -0
  84. package/dist/providers/s3/objectHeaders.d.ts +4 -0
  85. package/dist/providers/s3/objectHeaders.d.ts.map +1 -0
  86. package/dist/providers/s3/objectHeaders.js +22 -0
  87. package/dist/providers/s3/options.d.ts +107 -0
  88. package/dist/providers/s3/options.d.ts.map +1 -0
  89. package/dist/version.d.ts +1 -1
  90. package/package.json +7 -5
  91. package/src/adapters/astro/index.ts +3 -4
  92. package/src/adapters/dispatcher.ts +21 -30
  93. package/src/adapters/express/index.ts +3 -9
  94. package/src/adapters/fastify/index.ts +3 -9
  95. package/src/adapters/hono/index.ts +3 -4
  96. package/src/adapters/next/app/index.ts +3 -4
  97. package/src/adapters/next/pages/index.ts +3 -9
  98. package/src/adapters/remix/index.ts +3 -4
  99. package/src/adapters/shared.ts +90 -163
  100. package/src/adapters/start/index.ts +3 -4
  101. package/src/core/client/bucketClient.ts +10 -41
  102. package/src/core/client/index.ts +32 -48
  103. package/src/core/index.ts +2 -36
  104. package/src/core/provider.ts +28 -5
  105. package/src/core/router.ts +97 -0
  106. package/src/index.ts +1 -3
  107. package/src/providers/azure-blob/index.ts +2 -0
  108. package/src/providers/edgestore/index.ts +28 -14
  109. package/src/providers/s3/backendUpload.ts +117 -0
  110. package/src/providers/s3/index.ts +302 -223
  111. package/src/providers/s3/keys.ts +59 -0
  112. package/src/providers/s3/multipart.ts +196 -0
  113. package/src/providers/s3/objectHeaders.ts +23 -0
  114. package/src/providers/s3/options.ts +125 -0
  115. package/src/version.ts +1 -1
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 { createEdgeStore, initEdgeStore } from '@edgestore/server';
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
- edgestore: configuredEdgeStore,
49
+ router,
56
50
  });
57
51
 
58
52
  export { handler as GET, handler as POST };
@@ -0,0 +1,20 @@
1
+ # @edgestore/server 1.0.0-next.5: agent references
2
+
3
+ These references ship with this exact package version. Prefer them over newer online examples.
4
+ Generated from the authored documentation; do not edit these files directly.
5
+ For other EdgeStore packages, read their own agent-docs directory and installed types.
6
+
7
+ - [next.md](next.md)
8
+ - [configuration.md](configuration.md)
9
+ - [backend-client.md](backend-client.md)
10
+ - [hono.md](hono.md)
11
+ - [tanstack-start.md](tanstack-start.md)
12
+ - [remix.md](remix.md)
13
+ - [astro.md](astro.md)
14
+ - [express.md](express.md)
15
+ - [fastify.md](fastify.md)
16
+ - [troubleshooting.md](troubleshooting.md)
17
+ - [provider-edgestore.md](provider-edgestore.md)
18
+ - [provider-s3.md](provider-s3.md)
19
+ - [provider-azure-blob.md](provider-azure-blob.md)
20
+ - [provider-custom.md](provider-custom.md)
@@ -0,0 +1,147 @@
1
+ # Astro
2
+
3
+ Source: https://next.edgestore.dev/docs/adapters/astro
4
+
5
+ The Astro adapter handles server requests. The upload UI below uses a hydrated
6
+ React component.
7
+
8
+ ## Setup
9
+
10
+ ### Install
11
+
12
+ Packages to install (use the application’s package manager):
13
+
14
+ ```text
15
+ @edgestore/server @edgestore/react
16
+ ```
17
+
18
+ ### Environment variables
19
+
20
+ Copy your project's keys from the [dashboard](https://dashboard.edgestore.dev/) to the backend env file:
21
+
22
+ Example: title=".env"
23
+
24
+ ```sh
25
+ EDGE_STORE_ACCESS_KEY=your-access-key
26
+ EDGE_STORE_SECRET_KEY=your-secret-key
27
+ ```
28
+
29
+ > WARNING
30
+ >
31
+ > Add `.env` to `.gitignore`.
32
+
33
+ ### Backend
34
+
35
+ Configure an [Astro server adapter](https://docs.astro.build/en/guides/on-demand-rendering/)
36
+ for your deployment and enable the React integration for the UI below. The
37
+ EdgeStore endpoint must run on demand; a static-only deployment cannot serve it.
38
+
39
+ Create `src/pages/api/edgestore/[...edgestore].ts`:
40
+
41
+ ```ts
42
+ import { initEdgeStore } from '@edgestore/server';
43
+ import { createEdgeStoreAstroHandler } from '@edgestore/server/adapters/astro';
44
+
45
+ export const prerender = false;
46
+
47
+ const es = initEdgeStore.create();
48
+
49
+ const router = es.router({
50
+ publicFiles: es.fileBucket(),
51
+ });
52
+
53
+ const handler = createEdgeStoreAstroHandler({
54
+ router,
55
+ });
56
+
57
+ export { handler as GET, handler as POST };
58
+
59
+ export type EdgeStoreRouter = typeof router;
60
+ ```
61
+
62
+ This bucket's files are accessible to anyone with the link.
63
+
64
+ ### Frontend
65
+
66
+ Create the React provider:
67
+
68
+ Example: title="src/lib/edgestore.ts"
69
+
70
+ ```tsx
71
+ import { createEdgeStoreProvider } from '@edgestore/react';
72
+ import type { EdgeStoreRouter } from '../pages/api/edgestore/[...edgestore].ts';
73
+
74
+ const { EdgeStoreProvider, useEdgeStore } =
75
+ createEdgeStoreProvider<EdgeStoreRouter>();
76
+
77
+ export { EdgeStoreProvider, useEdgeStore };
78
+ ```
79
+
80
+ Create the upload component:
81
+
82
+ Example: title="src/components/FileUploader.tsx"
83
+
84
+ ```tsx
85
+ import { useState } from 'react';
86
+ import { EdgeStoreProvider, useEdgeStore } from '../lib/edgestore';
87
+
88
+ export function FileUploader() {
89
+ return (
90
+ <EdgeStoreProvider>
91
+ <FileUploaderInner />
92
+ </EdgeStoreProvider>
93
+ );
94
+ }
95
+
96
+ function FileUploaderInner() {
97
+ const [file, setFile] = useState<File | null>(null);
98
+ const { edgestore } = useEdgeStore();
99
+
100
+ return (
101
+ <div>
102
+ <input
103
+ type="file"
104
+ onChange={(e) => {
105
+ setFile(e.target.files?.[0] ?? null);
106
+ }}
107
+ />
108
+ <button
109
+ onClick={async () => {
110
+ if (file) {
111
+ const res = await edgestore.publicFiles.upload({
112
+ file,
113
+ onProgressChange: (progress) => {
114
+ // you can use this to show a progress bar
115
+ console.log(progress);
116
+ },
117
+ });
118
+ // you can run some server action or api here
119
+ // to add the necessary data to your database
120
+ console.log(res);
121
+ }
122
+ }}
123
+ >
124
+ Upload
125
+ </button>
126
+ </div>
127
+ );
128
+ }
129
+ ```
130
+
131
+ Hydrate the component with `client:load`:
132
+
133
+ Example: title="src/pages/index.astro"
134
+
135
+ ```astro
136
+ ---
137
+ import { FileUploader } from '../components/FileUploader';
138
+ ---
139
+
140
+ <html lang="en">
141
+ {/* ... */}
142
+ <body>
143
+ <h1>EdgeStore with Astro</h1>
144
+ <FileUploader client:load />
145
+ </body>
146
+ </html>
147
+ ```
@@ -0,0 +1,284 @@
1
+ # Backend Client
2
+
3
+ Source: https://next.edgestore.dev/docs/backend-client
4
+
5
+ Sometimes you might want to use the EdgeStore functionality directly from your backend. Things like deleting, uploading or even listing files can be done with the use of the backend client.
6
+
7
+ ## Setup
8
+
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.
12
+
13
+ Since Next.js doesn't allow exports in the api route, you will need to move your router to an external file.
14
+
15
+ Example: title="src/lib/edgestore-server.ts"
16
+
17
+ ```ts
18
+ import { initEdgeStore } from '@edgestore/server';
19
+ import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';
20
+
21
+ const es = initEdgeStore.create();
22
+
23
+ export const router = es.router({
24
+ publicFiles: es.fileBucket(),
25
+ });
26
+
27
+ export const handler = createEdgeStoreNextHandler({
28
+ router,
29
+ });
30
+
31
+ export const backendClient = router.client;
32
+ ```
33
+
34
+ Then you will need to update your api route to use the exported handler.
35
+
36
+ Example: title="src/app/api/edgestore/\[...edgestore]/route.ts"
37
+
38
+ ```ts
39
+ import { handler } from '@/lib/edgestore-server';
40
+
41
+ export { handler as GET, handler as POST };
42
+ ```
43
+
44
+ > NOTE
45
+ >
46
+ > You can find an example of the backend client usage in the
47
+ > [next-advanced](https://github.com/edgestorejs/edgestore/tree/main/examples/next-advanced)
48
+ > example.
49
+
50
+ > WARN
51
+ >
52
+ > The backend client is privileged. It validates router input and applies file
53
+ > type, size, transform, path, and metadata rules, but it does not run
54
+ > `accessControl`, `beforeUpload`, or `beforeDelete`. Perform authorization in
55
+ > the server code that calls it.
56
+
57
+ The hosted `edgestore()` provider supports the complete backend client. S3
58
+ supports `upload`, `get`, `delete`, `deleteMany`, and private-read
59
+ `createSignedUrl` / `createSignedUrls`, accepting key or URL references.
60
+ Azure Blob Storage supports lookup, deletion, and private signed reads.
61
+ Unsupported operations, such as S3 listing and confirmation or Azure backend
62
+ upload, remain absent from each provider's client type.
63
+
64
+ ## Backend Upload
65
+
66
+ You can use the `upload` function to upload files from your backend.
67
+
68
+ ### Upload a text file
69
+
70
+ The simplest use case would be to just upload a `txt` file:
71
+
72
+ ```ts
73
+ const res = await backendClient.publicFiles.upload({
74
+ content: 'some text content',
75
+ });
76
+ ```
77
+
78
+ ### Upload a blob
79
+
80
+ You can also upload a more complex file using the Blob object. And there are also all the other options available in the normal upload.
81
+
82
+ ```ts
83
+ const res = await backendClient.publicFiles.upload({
84
+ content: {
85
+ blob: new Blob(['col1,col2,col2'], { type: 'text/csv' }),
86
+ extension: 'csv',
87
+ },
88
+ options: {
89
+ temporary: true,
90
+ },
91
+ ctx: {
92
+ userId: '123',
93
+ userRole: 'admin',
94
+ },
95
+ input: {
96
+ type: 'post',
97
+ },
98
+ signal,
99
+ onProgress: ({ percentage, phase }) => {
100
+ console.log(phase, `${percentage}%`);
101
+ },
102
+ });
103
+
104
+ console.log(res.id, res.key, res.sizeBytes);
105
+ ```
106
+
107
+ ### Copy an existing file
108
+
109
+ You can use an existing file's URL to copy it into the EdgeStore bucket. This can be an external file (from outside of EdgeStore) or an existing EdgeStore file.
110
+
111
+ ```ts
112
+ const res = await backendClient.publicFiles.upload({
113
+ content: {
114
+ url: 'https://some-url.com/file.txt',
115
+ extension: 'txt',
116
+ },
117
+ });
118
+ ```
119
+
120
+ ### Transform a file before upload
121
+
122
+ You can transform backend uploads before EdgeStore validates and uploads them.
123
+ The transform receives the resolved `Blob` and extension, and returns the new
124
+ `Blob` and extension.
125
+
126
+ For example, you can use `sharp` to convert an image to WebP before upload:
127
+
128
+ Packages to install (use the application’s package manager):
129
+
130
+ ```text
131
+ npm install sharp
132
+ ```
133
+
134
+ ```ts
135
+ import sharp from 'sharp';
136
+
137
+ const res = await backendClient.publicImages.upload({
138
+ content: {
139
+ url: 'https://some-url.com/image.jpg',
140
+ extension: 'jpg',
141
+ },
142
+ options: {
143
+ transform: async ({ blob }) => {
144
+ const input = Buffer.from(await blob.arrayBuffer());
145
+ const output = await sharp(input).webp({ quality: 80 }).toBuffer();
146
+
147
+ return {
148
+ blob: new Blob([output], { type: 'image/webp' }),
149
+ extension: 'webp',
150
+ };
151
+ },
152
+ },
153
+ });
154
+ ```
155
+
156
+ ### Confirm a temporary file upload
157
+
158
+ If you upload a temporary file, you can confirm it by using the `confirm` function.
159
+
160
+ ```ts
161
+ const res = await backendClient.publicFiles.confirm({
162
+ id: file.id,
163
+ });
164
+ ```
165
+
166
+ File operations accept a stable file ID, storage key, or URL. Singular
167
+ operations throw `EdgeStoreFileMutationError` when that file fails. Use the
168
+ plural form when partial success should be preserved:
169
+
170
+ ```ts
171
+ const result = await backendClient.publicFiles.confirmMany({
172
+ refs: [{ id: first.id }, { key: second.key }],
173
+ });
174
+
175
+ for (const failure of result.failed) {
176
+ console.error(failure.ref, failure.error.code);
177
+ }
178
+ ```
179
+
180
+ ## Backend Delete
181
+
182
+ You can use the `delete` function to delete files from your backend.
183
+
184
+ ```ts
185
+ const res = await backendClient.publicFiles.delete({
186
+ id: file.id,
187
+ });
188
+ ```
189
+
190
+ `deleteMany`, `restore`, and `restoreMany` use the same singular and
191
+ partial-batch semantics.
192
+
193
+ ## Backend List Files (search)
194
+
195
+ You can use the `list` function to list files from your backend. It's also possible to filter the results by path, metadata or upload timing.
196
+
197
+ ```ts
198
+ // simple usage
199
+ // get the first 20 files in the bucket
200
+ const res = await backendClient.publicFiles.list();
201
+
202
+ // with filter and pagination
203
+ const res = await backendClient.publicFiles.list({
204
+ filter: {
205
+ metadata: {
206
+ role: 'admin',
207
+ },
208
+ path: {
209
+ type: 'post',
210
+ },
211
+ uploadedAt: {
212
+ gt: new Date(Date.now() - 1000 * 60 * 60 * 24 * 7), // past 7 days
213
+ },
214
+ },
215
+ cursor: 'cursor-from-previous-response',
216
+ limit: 50, // default: 20 (max: 100)
217
+ });
218
+
219
+ for (const file of res.items) {
220
+ console.log(file.id, file.url);
221
+ }
222
+
223
+ if (res.hasMore) {
224
+ console.log('Next cursor:', res.nextCursor);
225
+ }
226
+ ```
227
+
228
+ ## Private read URLs
229
+
230
+ Providers with signed-read support expose `createSignedUrl` on protected
231
+ buckets:
232
+
233
+ ```ts
234
+ const access = await backendClient.privateFiles.createSignedUrl({
235
+ url: { id: file.id },
236
+ expiresIn: 15 * 60,
237
+ });
238
+
239
+ console.log(access.signedUrl, access.expiresAt);
240
+ ```
241
+
242
+ Use `createSignedUrls` to sign several references in one provider call.
243
+
244
+ ## Reusing backend client types
245
+
246
+ Derive a single method's exact input or output directly from the configured
247
+ client:
248
+
249
+ ```ts
250
+ type UploadInput = Parameters<
251
+ typeof router.client.publicFiles.upload
252
+ >[0];
253
+
254
+ type UploadOutput = Awaited<
255
+ ReturnType<typeof router.client.publicFiles.upload>
256
+ >;
257
+ ```
258
+
259
+ This includes the router's context, input, path, and metadata configuration and
260
+ the provider's file and reference types.
261
+
262
+ Use `InferClientInputs` and `InferClientOutputs` when you need a reusable map of
263
+ every bucket and method:
264
+
265
+ Example: title="src/lib/edgestore-server.ts"
266
+
267
+ ```ts
268
+ import type {
269
+ InferClientInputs,
270
+ InferClientOutputs,
271
+ } from '@edgestore/server';
272
+
273
+ export type BackendInputs = InferClientInputs<typeof router>;
274
+ export type BackendOutputs = InferClientOutputs<typeof router>;
275
+
276
+ type UploadInput = BackendInputs['publicFiles']['upload'];
277
+ type UploadOutput = BackendOutputs['publicFiles']['upload'];
278
+ ```
279
+
280
+ The helpers infer capabilities and provider-specific types directly from the
281
+ router, including custom providers. Use `EdgeStoreClient<typeof router>` for
282
+ the complete backend client type.
283
+
284
+ `InferClientResponse` remains as a deprecated alias of `InferClientOutputs`.