@edgestore/server 0.7.0 → 0.8.1
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/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +2 -26
- package/dist/adapters/astro/index.mjs +2 -26
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +2 -20
- package/dist/adapters/express/index.mjs +2 -20
- package/dist/adapters/fastify/index.d.ts +1 -1
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +2 -21
- package/dist/adapters/fastify/index.mjs +2 -21
- package/dist/adapters/hono/index.d.ts +4 -70
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +5 -22
- package/dist/adapters/hono/index.mjs +5 -22
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +2 -26
- package/dist/adapters/next/app/index.mjs +2 -26
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +2 -20
- package/dist/adapters/next/pages/index.mjs +2 -20
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +2 -25
- package/dist/adapters/remix/index.mjs +2 -25
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +20 -12
- package/dist/adapters/shared.mjs +20 -12
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +2 -26
- package/dist/adapters/start/index.mjs +2 -26
- package/dist/core/client/index.d.ts +114 -74
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/client/index.js +54 -24
- package/dist/core/client/index.mjs +55 -25
- package/dist/core/sdk/index.d.ts +44 -2
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/core/sdk/index.js +36 -6
- package/dist/core/sdk/index.mjs +36 -6
- package/dist/providers/aws/index.d.ts +1 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +3 -3
- package/dist/providers/aws/index.mjs +3 -3
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +33 -7
- package/dist/providers/azure/index.mjs +33 -7
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +24 -4
- package/dist/providers/edgestore/index.mjs +24 -4
- package/dist/test-utils/edgestoreSmoke.d.ts +32 -0
- package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.mjs +4 -0
- package/package.json +11 -2
- package/src/adapters/astro/index.ts +2 -32
- package/src/adapters/express/index.ts +2 -25
- package/src/adapters/fastify/index.ts +3 -31
- package/src/adapters/hono/index.ts +7 -33
- package/src/adapters/next/app/index.ts +6 -36
- package/src/adapters/next/pages/index.ts +2 -25
- package/src/adapters/remix/index.ts +2 -22
- package/src/adapters/shared.ts +25 -9
- package/src/adapters/start/index.ts +2 -20
- package/src/core/client/index.ts +204 -104
- package/src/core/sdk/index.ts +75 -0
- package/src/providers/aws/index.ts +4 -4
- package/src/providers/azure/index.ts +40 -10
- package/src/providers/edgestore/index.ts +29 -0
- package/src/test-utils/edgestoreSmoke.ts +141 -0
- package/src/version.ts +2 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type MaybePromise,
|
|
7
7
|
type Provider,
|
|
8
8
|
} from '@edgestore/shared';
|
|
9
|
-
import { type Context } from 'hono';
|
|
9
|
+
import { type Context as HonoContext } from 'hono';
|
|
10
10
|
import Logger, { type LogLevel } from '../../libs/logger';
|
|
11
11
|
import { matchPath } from '../../libs/utils';
|
|
12
12
|
import { EdgeStoreProvider } from '../../providers/edgestore';
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from '../shared';
|
|
28
28
|
|
|
29
29
|
export type CreateContextOptions = {
|
|
30
|
-
c:
|
|
30
|
+
c: HonoContext;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export type Config<TCtx> = {
|
|
@@ -49,7 +49,7 @@ declare const globalThis: {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
// Helper to get a cookie value from Hono Context
|
|
52
|
-
function getCookie(c:
|
|
52
|
+
function getCookie(c: HonoContext, name: string): string | undefined {
|
|
53
53
|
const cookies = c.req.header('cookie');
|
|
54
54
|
if (!cookies) return undefined;
|
|
55
55
|
|
|
@@ -65,7 +65,7 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
65
65
|
|
|
66
66
|
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
67
67
|
|
|
68
|
-
return async (c:
|
|
68
|
+
return async (c: HonoContext): Promise<Response> => {
|
|
69
69
|
try {
|
|
70
70
|
const pathname = new URL(c.req.url).pathname;
|
|
71
71
|
|
|
@@ -85,7 +85,7 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
85
85
|
cause: err instanceof Error ? err : undefined,
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
const { newCookies,
|
|
88
|
+
const { newCookies, ...body } = await init({
|
|
89
89
|
ctx,
|
|
90
90
|
provider,
|
|
91
91
|
router: config.router,
|
|
@@ -95,17 +95,13 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
95
95
|
// Set cookies
|
|
96
96
|
if (Array.isArray(newCookies)) {
|
|
97
97
|
for (const cookie of newCookies) {
|
|
98
|
-
c.header('Set-Cookie', cookie);
|
|
98
|
+
c.header('Set-Cookie', cookie, { append: true });
|
|
99
99
|
}
|
|
100
100
|
} else if (newCookies) {
|
|
101
101
|
c.header('Set-Cookie', newCookies);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
return c.json(
|
|
105
|
-
token,
|
|
106
|
-
baseUrl,
|
|
107
|
-
providerName,
|
|
108
|
-
});
|
|
104
|
+
return c.json(body);
|
|
109
105
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
110
106
|
const body = await c.req.json<RequestUploadBody>();
|
|
111
107
|
return c.json(
|
|
@@ -155,28 +151,6 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
|
|
|
155
151
|
ctxToken: getCookie(c, resolvedCookieConfig.ctx.name),
|
|
156
152
|
}),
|
|
157
153
|
);
|
|
158
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
159
|
-
const url = c.req.query('url');
|
|
160
|
-
|
|
161
|
-
if (typeof url === 'string') {
|
|
162
|
-
const cookieHeader = c.req.header('cookie') ?? '';
|
|
163
|
-
|
|
164
|
-
const proxyRes = await fetch(url, {
|
|
165
|
-
headers: {
|
|
166
|
-
cookie: cookieHeader,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const data = await proxyRes.arrayBuffer();
|
|
171
|
-
c.header(
|
|
172
|
-
'Content-Type',
|
|
173
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
return c.body(Buffer.from(data));
|
|
177
|
-
} else {
|
|
178
|
-
return c.body(null, 400);
|
|
179
|
-
}
|
|
180
154
|
} else {
|
|
181
155
|
return c.body(null, 404);
|
|
182
156
|
}
|
|
@@ -85,25 +85,18 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
85
85
|
cause: err instanceof Error ? err : undefined,
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
|
-
const { newCookies,
|
|
88
|
+
const { newCookies, ...body } = await init({
|
|
89
89
|
ctx,
|
|
90
90
|
provider,
|
|
91
91
|
router: config.router,
|
|
92
92
|
cookieConfig,
|
|
93
93
|
});
|
|
94
|
-
const res = new Response(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
providerName,
|
|
99
|
-
}),
|
|
100
|
-
{
|
|
101
|
-
status: 200,
|
|
102
|
-
headers: {
|
|
103
|
-
'Content-Type': 'application/json',
|
|
104
|
-
},
|
|
94
|
+
const res = new Response(JSON.stringify(body), {
|
|
95
|
+
status: 200,
|
|
96
|
+
headers: {
|
|
97
|
+
'Content-Type': 'application/json',
|
|
105
98
|
},
|
|
106
|
-
);
|
|
99
|
+
});
|
|
107
100
|
for (const cookie of newCookies) {
|
|
108
101
|
res.headers.append('Set-Cookie', cookie);
|
|
109
102
|
}
|
|
@@ -170,29 +163,6 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
170
163
|
'Content-Type': 'application/json',
|
|
171
164
|
},
|
|
172
165
|
});
|
|
173
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
174
|
-
const url = req.nextUrl.searchParams.get('url');
|
|
175
|
-
if (typeof url === 'string') {
|
|
176
|
-
const proxyRes = await fetch(url, {
|
|
177
|
-
headers: {
|
|
178
|
-
cookie: req.cookies.toString() ?? '',
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const data = await proxyRes.arrayBuffer();
|
|
183
|
-
return new Response(data, {
|
|
184
|
-
status: proxyRes.status,
|
|
185
|
-
headers: {
|
|
186
|
-
'Content-Type':
|
|
187
|
-
proxyRes.headers.get('Content-Type') ??
|
|
188
|
-
'application/octet-stream',
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
} else {
|
|
192
|
-
return new Response(null, {
|
|
193
|
-
status: 400,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
166
|
} else {
|
|
197
167
|
return new Response(null, {
|
|
198
168
|
status: 404,
|
|
@@ -82,18 +82,14 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
82
82
|
cause: err instanceof Error ? err : undefined,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
const { newCookies,
|
|
85
|
+
const { newCookies, ...body } = await init({
|
|
86
86
|
ctx,
|
|
87
87
|
provider,
|
|
88
88
|
router: config.router,
|
|
89
89
|
cookieConfig,
|
|
90
90
|
});
|
|
91
91
|
res.setHeader('Set-Cookie', newCookies);
|
|
92
|
-
res.json(
|
|
93
|
-
token,
|
|
94
|
-
baseUrl,
|
|
95
|
-
providerName,
|
|
96
|
-
});
|
|
92
|
+
res.json(body);
|
|
97
93
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
98
94
|
res.json(
|
|
99
95
|
await requestUpload({
|
|
@@ -138,25 +134,6 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
|
|
|
138
134
|
ctxToken: req.cookies[resolvedCookieConfig.ctx.name],
|
|
139
135
|
}),
|
|
140
136
|
);
|
|
141
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
142
|
-
const { url } = req.query;
|
|
143
|
-
if (typeof url === 'string') {
|
|
144
|
-
const proxyRes = await fetch(url, {
|
|
145
|
-
headers: {
|
|
146
|
-
cookie: req.headers.cookie ?? '',
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const data = await proxyRes.arrayBuffer();
|
|
151
|
-
res.setHeader(
|
|
152
|
-
'Content-Type',
|
|
153
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
res.end(Buffer.from(data));
|
|
157
|
-
} else {
|
|
158
|
-
res.status(400).end();
|
|
159
|
-
}
|
|
160
137
|
} else {
|
|
161
138
|
res.status(404).end();
|
|
162
139
|
}
|
|
@@ -92,7 +92,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
92
92
|
cause: err instanceof Error ? err : undefined,
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
const { newCookies,
|
|
95
|
+
const { newCookies, ...body } = await init({
|
|
96
96
|
ctx,
|
|
97
97
|
provider,
|
|
98
98
|
router: config.router,
|
|
@@ -110,7 +110,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
110
110
|
responseHeaders.append('Set-Cookie', newCookies);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
return new Response(JSON.stringify(
|
|
113
|
+
return new Response(JSON.stringify(body), {
|
|
114
114
|
headers: responseHeaders,
|
|
115
115
|
status: 200,
|
|
116
116
|
});
|
|
@@ -163,26 +163,6 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
163
163
|
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
164
164
|
}),
|
|
165
165
|
);
|
|
166
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
167
|
-
const url = new URL(req.url).searchParams.get('url');
|
|
168
|
-
if (typeof url === 'string') {
|
|
169
|
-
const proxyRes = await fetch(url, {
|
|
170
|
-
headers: {
|
|
171
|
-
cookie: req.headers.get('cookie') ?? '',
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const data = await proxyRes.arrayBuffer();
|
|
176
|
-
const headers = new Headers();
|
|
177
|
-
headers.set(
|
|
178
|
-
'Content-Type',
|
|
179
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
return new Response(data, { headers });
|
|
183
|
-
} else {
|
|
184
|
-
return new Response(null, { status: 400 });
|
|
185
|
-
}
|
|
186
166
|
} else {
|
|
187
167
|
return new Response(null, { status: 404 });
|
|
188
168
|
}
|
package/src/adapters/shared.ts
CHANGED
|
@@ -145,10 +145,24 @@ export async function init<TCtx>(params: {
|
|
|
145
145
|
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
146
146
|
|
|
147
147
|
const ctxToken = await encryptJWT(ctx);
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
router
|
|
151
|
-
|
|
148
|
+
const requiresFileAccessCookie =
|
|
149
|
+
provider.name === 'edgestore' &&
|
|
150
|
+
Object.values(router.buckets).some(
|
|
151
|
+
(bucket) =>
|
|
152
|
+
bucket._def.accessControl !== undefined &&
|
|
153
|
+
bucket._def.accessControl !== 'private',
|
|
154
|
+
);
|
|
155
|
+
const shouldRunProviderInit =
|
|
156
|
+
provider.name !== 'edgestore' || requiresFileAccessCookie;
|
|
157
|
+
|
|
158
|
+
let token: string | undefined;
|
|
159
|
+
if (shouldRunProviderInit) {
|
|
160
|
+
const initRes = await provider.init({
|
|
161
|
+
ctx,
|
|
162
|
+
router: router,
|
|
163
|
+
});
|
|
164
|
+
token = initRes.token;
|
|
165
|
+
}
|
|
152
166
|
const newCookies = [
|
|
153
167
|
serialize(
|
|
154
168
|
resolvedCookieConfig.ctx.name,
|
|
@@ -173,6 +187,7 @@ export async function init<TCtx>(params: {
|
|
|
173
187
|
token,
|
|
174
188
|
baseUrl,
|
|
175
189
|
providerName: provider.name,
|
|
190
|
+
requiresFileAccessCookie,
|
|
176
191
|
});
|
|
177
192
|
|
|
178
193
|
return {
|
|
@@ -180,6 +195,7 @@ export async function init<TCtx>(params: {
|
|
|
180
195
|
token,
|
|
181
196
|
baseUrl,
|
|
182
197
|
providerName: provider.name,
|
|
198
|
+
requiresFileAccessCookie,
|
|
183
199
|
};
|
|
184
200
|
}
|
|
185
201
|
|
|
@@ -313,6 +329,7 @@ export async function requestUpload<TCtx>(params: {
|
|
|
313
329
|
});
|
|
314
330
|
const metadata = await bucket._def.metadata?.({ ctx, input });
|
|
315
331
|
const isPublic = bucket._def.accessControl === undefined;
|
|
332
|
+
const autoSignedUrls = bucket._def.autoSignedUrls;
|
|
316
333
|
|
|
317
334
|
log.debug('upload info', {
|
|
318
335
|
path,
|
|
@@ -330,6 +347,7 @@ export async function requestUpload<TCtx>(params: {
|
|
|
330
347
|
isPublic,
|
|
331
348
|
metadata,
|
|
332
349
|
},
|
|
350
|
+
autoSignedUrls,
|
|
333
351
|
});
|
|
334
352
|
const { parsedPath, pathOrder } = parsePath(path);
|
|
335
353
|
|
|
@@ -655,11 +673,9 @@ async function getContext(token: string) {
|
|
|
655
673
|
}
|
|
656
674
|
|
|
657
675
|
/**
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
* This function is used to get the original URL,
|
|
662
|
-
* so that we can delete or confirm the upload.
|
|
676
|
+
* Older clients rewrote protected file URLs to the removed `/proxy-file` route
|
|
677
|
+
* in development. This recovers the original URL from those rewritten URLs,
|
|
678
|
+
* so that we can still delete or confirm the upload.
|
|
663
679
|
*/
|
|
664
680
|
function unproxyUrl(url: string) {
|
|
665
681
|
if (isDev() && url.startsWith('http://')) {
|
|
@@ -90,7 +90,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
90
90
|
cause: err instanceof Error ? err : undefined,
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
|
-
const { newCookies,
|
|
93
|
+
const { newCookies, ...body } = await init({
|
|
94
94
|
ctx,
|
|
95
95
|
provider,
|
|
96
96
|
router: config.router,
|
|
@@ -101,7 +101,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
101
101
|
headers.append('Set-Cookie', cookie);
|
|
102
102
|
});
|
|
103
103
|
headers.set('Content-Type', 'application/json');
|
|
104
|
-
return new Response(JSON.stringify(
|
|
104
|
+
return new Response(JSON.stringify(body), {
|
|
105
105
|
status: 200,
|
|
106
106
|
headers,
|
|
107
107
|
});
|
|
@@ -167,24 +167,6 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
167
167
|
status: 200,
|
|
168
168
|
headers: { 'Content-Type': 'application/json' },
|
|
169
169
|
});
|
|
170
|
-
} else if (matchPath(pathname, '/proxy-file')) {
|
|
171
|
-
const urlParam = new URL(request.url).searchParams.get('url');
|
|
172
|
-
if (typeof urlParam === 'string') {
|
|
173
|
-
const proxyRes = await fetch(urlParam, {
|
|
174
|
-
headers: {
|
|
175
|
-
cookie: request.headers.get('cookie') ?? '',
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
const data = await proxyRes.arrayBuffer();
|
|
179
|
-
const headers = new Headers();
|
|
180
|
-
headers.set(
|
|
181
|
-
'Content-Type',
|
|
182
|
-
proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
|
|
183
|
-
);
|
|
184
|
-
return new Response(data, { status: proxyRes.status, headers });
|
|
185
|
-
} else {
|
|
186
|
-
return new Response(null, { status: 400 });
|
|
187
|
-
}
|
|
188
170
|
} else {
|
|
189
171
|
return new Response(null, { status: 404 });
|
|
190
172
|
}
|