@edgestore/server 0.5.1 → 0.5.3-alpha.0
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 +3 -0
- package/dist/adapters/astro/index.d.ts.map +1 -1
- package/dist/adapters/astro/index.js +23 -21
- package/dist/adapters/astro/index.mjs +12 -10
- package/dist/adapters/express/index.d.ts +3 -0
- package/dist/adapters/express/index.d.ts.map +1 -1
- package/dist/adapters/express/index.js +23 -21
- package/dist/adapters/express/index.mjs +12 -10
- package/dist/adapters/fastify/index.d.ts +4 -1
- package/dist/adapters/fastify/index.d.ts.map +1 -1
- package/dist/adapters/fastify/index.js +23 -21
- package/dist/adapters/fastify/index.mjs +12 -10
- package/dist/adapters/hono/index.d.ts +3 -0
- package/dist/adapters/hono/index.d.ts.map +1 -1
- package/dist/adapters/hono/index.js +23 -21
- package/dist/adapters/hono/index.mjs +12 -10
- package/dist/adapters/next/app/index.d.ts +3 -0
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +24 -22
- package/dist/adapters/next/app/index.mjs +12 -10
- package/dist/adapters/next/pages/index.d.ts +3 -0
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +24 -22
- package/dist/adapters/next/pages/index.mjs +12 -10
- package/dist/adapters/remix/index.d.ts +3 -0
- package/dist/adapters/remix/index.d.ts.map +1 -1
- package/dist/adapters/remix/index.js +23 -21
- package/dist/adapters/remix/index.mjs +12 -10
- package/dist/adapters/shared.d.ts +74 -0
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/start/index.d.ts +3 -0
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +26 -22
- package/dist/adapters/start/index.mjs +15 -11
- package/dist/core/index.js +2 -2
- package/dist/core/index.mjs +3 -3
- package/dist/{index-7b259533.js → index-0c5489b9.js} +1 -1
- package/dist/{index-421c502f.js → index-c5c3cdaa.js} +1 -1
- package/dist/{index-2848cb40.mjs → index-e0432eed.mjs} +1 -1
- package/dist/providers/aws/index.js +1 -1
- package/dist/providers/aws/index.mjs +1 -1
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/azure/index.mjs +1 -1
- package/dist/providers/edgestore/index.js +2 -2
- package/dist/providers/edgestore/index.mjs +2 -2
- package/dist/{shared-25dbfab4.js → shared-8397d4db.js} +37 -10
- package/dist/{shared-685c8a0c.js → shared-8a6bcddb.js} +38 -9
- package/dist/{shared-4b199b96.mjs → shared-d2a0d681.mjs} +38 -10
- package/dist/{utils-7349adab.mjs → utils-2dd5613c.mjs} +1 -1
- package/dist/{utils-0aab6e3b.js → utils-681a13a7.js} +1 -1
- package/dist/{utils-b3d35894.js → utils-b30649cc.js} +1 -1
- package/package.json +7 -7
- package/src/adapters/astro/index.ts +19 -9
- package/src/adapters/express/index.ts +13 -6
- package/src/adapters/fastify/index.ts +33 -22
- package/src/adapters/hono/index.ts +13 -6
- package/src/adapters/next/app/index.ts +13 -6
- package/src/adapters/next/pages/index.ts +13 -6
- package/src/adapters/remix/index.ts +13 -6
- package/src/adapters/shared.ts +125 -9
- package/src/adapters/start/index.ts +16 -7
|
@@ -13,11 +13,13 @@ import {
|
|
|
13
13
|
completeMultipartUpload,
|
|
14
14
|
confirmUpload,
|
|
15
15
|
deleteFile,
|
|
16
|
+
getCookieConfig,
|
|
16
17
|
init,
|
|
17
18
|
requestUpload,
|
|
18
19
|
requestUploadParts,
|
|
19
20
|
type CompleteMultipartUploadBody,
|
|
20
21
|
type ConfirmUploadBody,
|
|
22
|
+
type CookieConfig,
|
|
21
23
|
type DeleteFileBody,
|
|
22
24
|
type RequestUploadBody,
|
|
23
25
|
type RequestUploadPartsParams,
|
|
@@ -31,12 +33,14 @@ export type Config<TCtx> = {
|
|
|
31
33
|
provider?: Provider;
|
|
32
34
|
router: EdgeStoreRouter<TCtx>;
|
|
33
35
|
logLevel?: LogLevel;
|
|
36
|
+
cookieConfig?: CookieConfig;
|
|
34
37
|
} & (TCtx extends Record<string, never>
|
|
35
38
|
? object
|
|
36
39
|
: {
|
|
37
40
|
provider?: Provider;
|
|
38
41
|
router: EdgeStoreRouter<TCtx>;
|
|
39
42
|
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
43
|
+
cookieConfig?: CookieConfig;
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
declare const globalThis: {
|
|
@@ -60,11 +64,13 @@ function getCookie(req: Request, name: string): string | undefined {
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
63
|
-
const { provider = EdgeStoreProvider() } = config;
|
|
67
|
+
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
64
68
|
const log = new Logger(config.logLevel);
|
|
65
69
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
66
70
|
log.debug('Creating EdgeStore Remix handler');
|
|
67
71
|
|
|
72
|
+
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
73
|
+
|
|
68
74
|
return async ({ request: req }: { request: Request }) => {
|
|
69
75
|
try {
|
|
70
76
|
const url = new URL(req.url);
|
|
@@ -90,6 +96,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
90
96
|
ctx,
|
|
91
97
|
provider,
|
|
92
98
|
router: config.router,
|
|
99
|
+
cookieConfig,
|
|
93
100
|
});
|
|
94
101
|
|
|
95
102
|
// Create response with cookies and token
|
|
@@ -114,7 +121,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
114
121
|
provider,
|
|
115
122
|
router: config.router,
|
|
116
123
|
body,
|
|
117
|
-
ctxToken: getCookie(req,
|
|
124
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
118
125
|
}),
|
|
119
126
|
);
|
|
120
127
|
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
@@ -124,7 +131,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
124
131
|
provider,
|
|
125
132
|
router: config.router,
|
|
126
133
|
body,
|
|
127
|
-
ctxToken: getCookie(req,
|
|
134
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
128
135
|
}),
|
|
129
136
|
);
|
|
130
137
|
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
@@ -133,7 +140,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
133
140
|
provider,
|
|
134
141
|
router: config.router,
|
|
135
142
|
body,
|
|
136
|
-
ctxToken: getCookie(req,
|
|
143
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
137
144
|
});
|
|
138
145
|
return new Response(null, { status: 200 });
|
|
139
146
|
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
@@ -143,7 +150,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
143
150
|
provider,
|
|
144
151
|
router: config.router,
|
|
145
152
|
body,
|
|
146
|
-
ctxToken: getCookie(req,
|
|
153
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
147
154
|
}),
|
|
148
155
|
);
|
|
149
156
|
} else if (matchPath(pathname, '/delete-file')) {
|
|
@@ -153,7 +160,7 @@ export function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>) {
|
|
|
153
160
|
provider,
|
|
154
161
|
router: config.router,
|
|
155
162
|
body,
|
|
156
|
-
ctxToken: getCookie(req,
|
|
163
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name),
|
|
157
164
|
}),
|
|
158
165
|
);
|
|
159
166
|
} else if (matchPath(pathname, '/proxy-file')) {
|
package/src/adapters/shared.ts
CHANGED
|
@@ -22,31 +22,147 @@ declare const globalThis: {
|
|
|
22
22
|
_EDGE_STORE_LOGGER: Logger;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
export type CookieOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* Cookie path
|
|
28
|
+
* @default "/"
|
|
29
|
+
*/
|
|
30
|
+
path?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Cookie max age in seconds
|
|
33
|
+
* @default 2592000 (30 days)
|
|
34
|
+
*/
|
|
35
|
+
maxAge?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Cookie domain
|
|
38
|
+
*/
|
|
39
|
+
domain?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Cookie same site policy
|
|
42
|
+
*/
|
|
43
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
44
|
+
/**
|
|
45
|
+
* Cookie secure flag
|
|
46
|
+
*/
|
|
47
|
+
secure?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Cookie http only flag
|
|
50
|
+
*/
|
|
51
|
+
httpOnly?: boolean;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type CookieConfig = {
|
|
55
|
+
/**
|
|
56
|
+
* Context cookie configuration
|
|
57
|
+
*/
|
|
58
|
+
ctx?: {
|
|
59
|
+
/**
|
|
60
|
+
* Name of the context cookie
|
|
61
|
+
* @default "edgestore-ctx"
|
|
62
|
+
*/
|
|
63
|
+
name?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Cookie options for context cookie
|
|
66
|
+
*/
|
|
67
|
+
options?: CookieOptions;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Token cookie configuration
|
|
71
|
+
*/
|
|
72
|
+
token?: {
|
|
73
|
+
/**
|
|
74
|
+
* Name of the token cookie
|
|
75
|
+
* @default "edgestore-token"
|
|
76
|
+
*/
|
|
77
|
+
name?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Cookie options for token cookie
|
|
80
|
+
*/
|
|
81
|
+
options?: CookieOptions;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type ResolvedCookieConfig = {
|
|
86
|
+
ctx: {
|
|
87
|
+
name: string;
|
|
88
|
+
options: CookieOptions;
|
|
89
|
+
};
|
|
90
|
+
token: {
|
|
91
|
+
name: string;
|
|
92
|
+
options: CookieOptions;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Merges the provided cookie configuration with default values
|
|
98
|
+
*/
|
|
99
|
+
export function getCookieConfig(
|
|
100
|
+
cookieConfig?: CookieConfig,
|
|
101
|
+
): ResolvedCookieConfig {
|
|
102
|
+
const defaultOptions: CookieOptions = {
|
|
103
|
+
path: '/',
|
|
104
|
+
maxAge: DEFAULT_MAX_AGE,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Helper function to merge options, filtering out undefined values
|
|
108
|
+
const mergeOptions = (configOptions?: CookieOptions): CookieOptions => {
|
|
109
|
+
const merged = { ...defaultOptions };
|
|
110
|
+
|
|
111
|
+
if (configOptions) {
|
|
112
|
+
Object.keys(configOptions).forEach((key) => {
|
|
113
|
+
const value = configOptions[key as keyof CookieOptions];
|
|
114
|
+
if (value !== undefined) {
|
|
115
|
+
(merged as any)[key] = value;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return merged;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
ctx: {
|
|
125
|
+
name: cookieConfig?.ctx?.name ?? 'edgestore-ctx',
|
|
126
|
+
options: mergeOptions(cookieConfig?.ctx?.options),
|
|
127
|
+
},
|
|
128
|
+
token: {
|
|
129
|
+
name: cookieConfig?.token?.name ?? 'edgestore-token',
|
|
130
|
+
options: mergeOptions(cookieConfig?.token?.options),
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
25
135
|
export async function init<TCtx>(params: {
|
|
26
136
|
provider: Provider;
|
|
27
137
|
router: EdgeStoreRouter<TCtx>;
|
|
28
138
|
ctx: TCtx;
|
|
139
|
+
cookieConfig?: CookieConfig;
|
|
29
140
|
}): Promise<SharedInitRes> {
|
|
30
141
|
const log = globalThis._EDGE_STORE_LOGGER;
|
|
31
|
-
const { ctx, provider, router } = params;
|
|
142
|
+
const { ctx, provider, router, cookieConfig } = params;
|
|
32
143
|
log.debug('Running [init]', { ctx });
|
|
144
|
+
|
|
145
|
+
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
146
|
+
|
|
33
147
|
const ctxToken = await encryptJWT(ctx);
|
|
34
148
|
const { token } = await provider.init({
|
|
35
149
|
ctx,
|
|
36
150
|
router: router,
|
|
37
151
|
});
|
|
38
152
|
const newCookies = [
|
|
39
|
-
serialize(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
153
|
+
serialize(
|
|
154
|
+
resolvedCookieConfig.ctx.name,
|
|
155
|
+
ctxToken,
|
|
156
|
+
resolvedCookieConfig.ctx.options,
|
|
157
|
+
),
|
|
43
158
|
];
|
|
44
159
|
if (token) {
|
|
45
160
|
newCookies.push(
|
|
46
|
-
serialize(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
161
|
+
serialize(
|
|
162
|
+
resolvedCookieConfig.token.name,
|
|
163
|
+
token,
|
|
164
|
+
resolvedCookieConfig.token.options,
|
|
165
|
+
),
|
|
50
166
|
);
|
|
51
167
|
}
|
|
52
168
|
const baseUrl = await provider.getBaseUrl();
|
|
@@ -13,11 +13,13 @@ import {
|
|
|
13
13
|
completeMultipartUpload,
|
|
14
14
|
confirmUpload,
|
|
15
15
|
deleteFile,
|
|
16
|
+
getCookieConfig,
|
|
16
17
|
init,
|
|
17
18
|
requestUpload,
|
|
18
19
|
requestUploadParts,
|
|
19
20
|
type CompleteMultipartUploadBody,
|
|
20
21
|
type ConfirmUploadBody,
|
|
22
|
+
type CookieConfig,
|
|
21
23
|
type DeleteFileBody,
|
|
22
24
|
type RequestUploadBody,
|
|
23
25
|
type RequestUploadPartsParams,
|
|
@@ -31,12 +33,14 @@ export type Config<TCtx> = {
|
|
|
31
33
|
provider?: Provider;
|
|
32
34
|
router: EdgeStoreRouter<TCtx>;
|
|
33
35
|
logLevel?: LogLevel;
|
|
36
|
+
cookieConfig?: CookieConfig;
|
|
34
37
|
} & (TCtx extends Record<string, never>
|
|
35
38
|
? object
|
|
36
39
|
: {
|
|
37
40
|
provider?: Provider;
|
|
38
41
|
router: EdgeStoreRouter<TCtx>;
|
|
39
42
|
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
43
|
+
cookieConfig?: CookieConfig;
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
declare const globalThis: {
|
|
@@ -60,11 +64,13 @@ function getCookie(req: Request, cookieName: string): string | undefined {
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
63
|
-
const { provider = EdgeStoreProvider() } = config;
|
|
67
|
+
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
64
68
|
const log = new Logger(config.logLevel);
|
|
65
69
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
66
70
|
log.debug('Creating EdgeStore TanStack Start handler');
|
|
67
71
|
|
|
72
|
+
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
73
|
+
|
|
68
74
|
return async ({ request }: { request: Request }) => {
|
|
69
75
|
try {
|
|
70
76
|
const { pathname } = new URL(request.url);
|
|
@@ -88,9 +94,12 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
88
94
|
ctx,
|
|
89
95
|
provider,
|
|
90
96
|
router: config.router,
|
|
97
|
+
cookieConfig,
|
|
91
98
|
});
|
|
92
99
|
const headers = new Headers();
|
|
93
|
-
newCookies.forEach((cookie) =>
|
|
100
|
+
newCookies.forEach((cookie) => {
|
|
101
|
+
headers.append('Set-Cookie', cookie);
|
|
102
|
+
});
|
|
94
103
|
headers.set('Content-Type', 'application/json');
|
|
95
104
|
return new Response(JSON.stringify({ token, baseUrl }), {
|
|
96
105
|
status: 200,
|
|
@@ -98,7 +107,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
98
107
|
});
|
|
99
108
|
} else if (matchPath(pathname, '/request-upload')) {
|
|
100
109
|
const body = await request.json();
|
|
101
|
-
const ctxToken = getCookie(request,
|
|
110
|
+
const ctxToken = getCookie(request, resolvedCookieConfig.ctx.name);
|
|
102
111
|
const result = await requestUpload({
|
|
103
112
|
provider,
|
|
104
113
|
router: config.router,
|
|
@@ -111,7 +120,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
111
120
|
});
|
|
112
121
|
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
113
122
|
const body = await request.json();
|
|
114
|
-
const ctxToken = getCookie(request,
|
|
123
|
+
const ctxToken = getCookie(request, resolvedCookieConfig.ctx.name);
|
|
115
124
|
const result = await requestUploadParts({
|
|
116
125
|
provider,
|
|
117
126
|
router: config.router,
|
|
@@ -124,7 +133,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
124
133
|
});
|
|
125
134
|
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
126
135
|
const body = await request.json();
|
|
127
|
-
const ctxToken = getCookie(request,
|
|
136
|
+
const ctxToken = getCookie(request, resolvedCookieConfig.ctx.name);
|
|
128
137
|
await completeMultipartUpload({
|
|
129
138
|
provider,
|
|
130
139
|
router: config.router,
|
|
@@ -134,7 +143,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
134
143
|
return new Response(null, { status: 200 });
|
|
135
144
|
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
136
145
|
const body = await request.json();
|
|
137
|
-
const ctxToken = getCookie(request,
|
|
146
|
+
const ctxToken = getCookie(request, resolvedCookieConfig.ctx.name);
|
|
138
147
|
const result = await confirmUpload({
|
|
139
148
|
provider,
|
|
140
149
|
router: config.router,
|
|
@@ -147,7 +156,7 @@ export function createEdgeStoreStartHandler<TCtx>(config: Config<TCtx>) {
|
|
|
147
156
|
});
|
|
148
157
|
} else if (matchPath(pathname, '/delete-file')) {
|
|
149
158
|
const body = await request.json();
|
|
150
|
-
const ctxToken = getCookie(request,
|
|
159
|
+
const ctxToken = getCookie(request, resolvedCookieConfig.ctx.name);
|
|
151
160
|
const result = await deleteFile({
|
|
152
161
|
provider,
|
|
153
162
|
router: config.router,
|