@edgestore/server 0.5.2 → 0.5.3
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/client/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -3
- package/dist/core/index.mjs +7 -4
- 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
- package/src/core/client/index.ts +7 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
2
|
import type { APIContext } from 'astro';
|
|
3
3
|
import { type LogLevel } from '../../libs/logger';
|
|
4
|
+
import { type CookieConfig } from '../shared';
|
|
4
5
|
export type Config<TCtx> = {
|
|
5
6
|
provider?: Provider;
|
|
6
7
|
router: EdgeStoreRouter<TCtx>;
|
|
7
8
|
logLevel?: LogLevel;
|
|
9
|
+
cookieConfig?: CookieConfig;
|
|
8
10
|
} & (TCtx extends Record<string, never> ? object : {
|
|
9
11
|
provider?: Provider;
|
|
10
12
|
router: EdgeStoreRouter<TCtx>;
|
|
11
13
|
createContext: (opts: APIContext) => MaybePromise<TCtx>;
|
|
14
|
+
cookieConfig?: CookieConfig;
|
|
12
15
|
});
|
|
13
16
|
export declare function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>): (context: APIContext) => Promise<Response>;
|
|
14
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/astro/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/astro/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG1D,OAAO,EAUL,KAAK,YAAY,EAIlB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,MAAM,GACN;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,aAAa,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IACxD,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC,CAAC;AAsBP,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,aAQ7C,UAAU,uBAiKlC"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var shared = require('@edgestore/shared');
|
|
6
|
-
var utils = require('../../utils-
|
|
5
|
+
var shared$1 = require('@edgestore/shared');
|
|
6
|
+
var utils = require('../../utils-681a13a7.js');
|
|
7
7
|
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
|
-
var shared
|
|
9
|
-
require('../../index-
|
|
8
|
+
var shared = require('../../shared-8a6bcddb.js');
|
|
9
|
+
require('../../index-0c5489b9.js');
|
|
10
10
|
require('@panva/hkdf');
|
|
11
11
|
require('cookie');
|
|
12
12
|
require('jose');
|
|
@@ -24,10 +24,11 @@ function getCookie(request, name) {
|
|
|
24
24
|
return cookies[name];
|
|
25
25
|
}
|
|
26
26
|
function createEdgeStoreAstroHandler(config) {
|
|
27
|
-
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
27
|
+
const { provider = providers_edgestore_index.EdgeStoreProvider(), cookieConfig } = config;
|
|
28
28
|
const log = new utils.Logger(config.logLevel);
|
|
29
29
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
30
30
|
log.debug('Creating EdgeStore Astro handler');
|
|
31
|
+
const resolvedCookieConfig = shared.getCookieConfig(cookieConfig);
|
|
31
32
|
return async (context)=>{
|
|
32
33
|
try {
|
|
33
34
|
const { request } = context;
|
|
@@ -39,16 +40,17 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
39
40
|
try {
|
|
40
41
|
ctx = 'createContext' in config ? await config.createContext(context) : {};
|
|
41
42
|
} catch (err) {
|
|
42
|
-
throw new shared.EdgeStoreError({
|
|
43
|
+
throw new shared$1.EdgeStoreError({
|
|
43
44
|
message: 'Error creating context',
|
|
44
45
|
code: 'CREATE_CONTEXT_ERROR',
|
|
45
46
|
cause: err instanceof Error ? err : undefined
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
|
-
const { newCookies, token, baseUrl } = await shared
|
|
49
|
+
const { newCookies, token, baseUrl } = await shared.init({
|
|
49
50
|
ctx,
|
|
50
51
|
provider,
|
|
51
|
-
router: config.router
|
|
52
|
+
router: config.router,
|
|
53
|
+
cookieConfig
|
|
52
54
|
});
|
|
53
55
|
const headers = new Headers();
|
|
54
56
|
headers.set('Content-Type', 'application/json');
|
|
@@ -68,11 +70,11 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
68
70
|
});
|
|
69
71
|
} else if (utils.matchPath(url.pathname, 'request-upload')) {
|
|
70
72
|
const body = await request.json();
|
|
71
|
-
const result = await shared
|
|
73
|
+
const result = await shared.requestUpload({
|
|
72
74
|
provider,
|
|
73
75
|
router: config.router,
|
|
74
76
|
body,
|
|
75
|
-
ctxToken: getCookie(request,
|
|
77
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
76
78
|
});
|
|
77
79
|
return new Response(JSON.stringify(result), {
|
|
78
80
|
headers: {
|
|
@@ -81,11 +83,11 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
81
83
|
});
|
|
82
84
|
} else if (utils.matchPath(url.pathname, 'request-upload-parts')) {
|
|
83
85
|
const body = await request.json();
|
|
84
|
-
const result = await shared
|
|
86
|
+
const result = await shared.requestUploadParts({
|
|
85
87
|
provider,
|
|
86
88
|
router: config.router,
|
|
87
89
|
body,
|
|
88
|
-
ctxToken: getCookie(request,
|
|
90
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
89
91
|
});
|
|
90
92
|
return new Response(JSON.stringify(result), {
|
|
91
93
|
headers: {
|
|
@@ -94,22 +96,22 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
94
96
|
});
|
|
95
97
|
} else if (utils.matchPath(url.pathname, 'complete-multipart-upload')) {
|
|
96
98
|
const body = await request.json();
|
|
97
|
-
await shared
|
|
99
|
+
await shared.completeMultipartUpload({
|
|
98
100
|
provider,
|
|
99
101
|
router: config.router,
|
|
100
102
|
body,
|
|
101
|
-
ctxToken: getCookie(request,
|
|
103
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
102
104
|
});
|
|
103
105
|
return new Response(null, {
|
|
104
106
|
status: 200
|
|
105
107
|
});
|
|
106
108
|
} else if (utils.matchPath(url.pathname, 'confirm-upload')) {
|
|
107
109
|
const body = await request.json();
|
|
108
|
-
const result = await shared
|
|
110
|
+
const result = await shared.confirmUpload({
|
|
109
111
|
provider,
|
|
110
112
|
router: config.router,
|
|
111
113
|
body,
|
|
112
|
-
ctxToken: getCookie(request,
|
|
114
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
113
115
|
});
|
|
114
116
|
return new Response(JSON.stringify(result), {
|
|
115
117
|
headers: {
|
|
@@ -118,11 +120,11 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
118
120
|
});
|
|
119
121
|
} else if (utils.matchPath(url.pathname, 'delete-file')) {
|
|
120
122
|
const body = await request.json();
|
|
121
|
-
const result = await shared
|
|
123
|
+
const result = await shared.deleteFile({
|
|
122
124
|
provider,
|
|
123
125
|
router: config.router,
|
|
124
126
|
body,
|
|
125
|
-
ctxToken: getCookie(request,
|
|
127
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
126
128
|
});
|
|
127
129
|
return new Response(JSON.stringify(result), {
|
|
128
130
|
headers: {
|
|
@@ -155,18 +157,18 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
155
157
|
});
|
|
156
158
|
}
|
|
157
159
|
} catch (err) {
|
|
158
|
-
if (err instanceof shared.EdgeStoreError) {
|
|
160
|
+
if (err instanceof shared$1.EdgeStoreError) {
|
|
159
161
|
log[err.level](err.formattedMessage());
|
|
160
162
|
if (err.cause) log[err.level](err.cause);
|
|
161
163
|
return new Response(JSON.stringify(err.formattedJson()), {
|
|
162
|
-
status: shared.EDGE_STORE_ERROR_CODES[err.code],
|
|
164
|
+
status: shared$1.EDGE_STORE_ERROR_CODES[err.code],
|
|
163
165
|
headers: {
|
|
164
166
|
'Content-Type': 'application/json'
|
|
165
167
|
}
|
|
166
168
|
});
|
|
167
169
|
} else {
|
|
168
170
|
log.error(err);
|
|
169
|
-
return new Response(JSON.stringify(new shared.EdgeStoreError({
|
|
171
|
+
return new Response(JSON.stringify(new shared$1.EdgeStoreError({
|
|
170
172
|
message: 'Internal Server Error',
|
|
171
173
|
code: 'SERVER_ERROR'
|
|
172
174
|
}).formattedJson()), {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import { L as Logger, m as matchPath } from '../../utils-
|
|
2
|
+
import { L as Logger, m as matchPath } from '../../utils-2dd5613c.mjs';
|
|
3
3
|
import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
|
|
4
|
-
import { a as init, r as requestUpload,
|
|
5
|
-
import '../../index-
|
|
4
|
+
import { a as getCookieConfig, c as init, r as requestUpload, d as requestUploadParts, e as completeMultipartUpload, f as confirmUpload, h as deleteFile } from '../../shared-d2a0d681.mjs';
|
|
5
|
+
import '../../index-e0432eed.mjs';
|
|
6
6
|
import '@panva/hkdf';
|
|
7
7
|
import 'cookie';
|
|
8
8
|
import 'jose';
|
|
@@ -20,10 +20,11 @@ function getCookie(request, name) {
|
|
|
20
20
|
return cookies[name];
|
|
21
21
|
}
|
|
22
22
|
function createEdgeStoreAstroHandler(config) {
|
|
23
|
-
const { provider = EdgeStoreProvider() } = config;
|
|
23
|
+
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
24
24
|
const log = new Logger(config.logLevel);
|
|
25
25
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
26
26
|
log.debug('Creating EdgeStore Astro handler');
|
|
27
|
+
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
27
28
|
return async (context)=>{
|
|
28
29
|
try {
|
|
29
30
|
const { request } = context;
|
|
@@ -44,7 +45,8 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
44
45
|
const { newCookies, token, baseUrl } = await init({
|
|
45
46
|
ctx,
|
|
46
47
|
provider,
|
|
47
|
-
router: config.router
|
|
48
|
+
router: config.router,
|
|
49
|
+
cookieConfig
|
|
48
50
|
});
|
|
49
51
|
const headers = new Headers();
|
|
50
52
|
headers.set('Content-Type', 'application/json');
|
|
@@ -68,7 +70,7 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
68
70
|
provider,
|
|
69
71
|
router: config.router,
|
|
70
72
|
body,
|
|
71
|
-
ctxToken: getCookie(request,
|
|
73
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
72
74
|
});
|
|
73
75
|
return new Response(JSON.stringify(result), {
|
|
74
76
|
headers: {
|
|
@@ -81,7 +83,7 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
81
83
|
provider,
|
|
82
84
|
router: config.router,
|
|
83
85
|
body,
|
|
84
|
-
ctxToken: getCookie(request,
|
|
86
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
85
87
|
});
|
|
86
88
|
return new Response(JSON.stringify(result), {
|
|
87
89
|
headers: {
|
|
@@ -94,7 +96,7 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
94
96
|
provider,
|
|
95
97
|
router: config.router,
|
|
96
98
|
body,
|
|
97
|
-
ctxToken: getCookie(request,
|
|
99
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
98
100
|
});
|
|
99
101
|
return new Response(null, {
|
|
100
102
|
status: 200
|
|
@@ -105,7 +107,7 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
105
107
|
provider,
|
|
106
108
|
router: config.router,
|
|
107
109
|
body,
|
|
108
|
-
ctxToken: getCookie(request,
|
|
110
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
109
111
|
});
|
|
110
112
|
return new Response(JSON.stringify(result), {
|
|
111
113
|
headers: {
|
|
@@ -118,7 +120,7 @@ function createEdgeStoreAstroHandler(config) {
|
|
|
118
120
|
provider,
|
|
119
121
|
router: config.router,
|
|
120
122
|
body,
|
|
121
|
-
ctxToken: getCookie(request,
|
|
123
|
+
ctxToken: getCookie(request, resolvedCookieConfig.ctx.name)
|
|
122
124
|
});
|
|
123
125
|
return new Response(JSON.stringify(result), {
|
|
124
126
|
headers: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
2
|
import { type Request, type Response } from 'express';
|
|
3
3
|
import { type LogLevel } from '../../libs/logger';
|
|
4
|
+
import { type CookieConfig } from '../shared';
|
|
4
5
|
export type CreateContextOptions = {
|
|
5
6
|
req: Request;
|
|
6
7
|
res: Response;
|
|
@@ -9,10 +10,12 @@ export type Config<TCtx> = {
|
|
|
9
10
|
provider?: Provider;
|
|
10
11
|
router: EdgeStoreRouter<TCtx>;
|
|
11
12
|
logLevel?: LogLevel;
|
|
13
|
+
cookieConfig?: CookieConfig;
|
|
12
14
|
} & (TCtx extends Record<string, never> ? object : {
|
|
13
15
|
provider?: Provider;
|
|
14
16
|
router: EdgeStoreRouter<TCtx>;
|
|
15
17
|
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
18
|
+
cookieConfig?: CookieConfig;
|
|
16
19
|
});
|
|
17
20
|
export declare function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>): (req: Request, res: Response) => Promise<void>;
|
|
18
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtD,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG1D,OAAO,EAUL,KAAK,YAAY,EAIlB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,MAAM,GACN;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IAClE,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC,CAAC;AAMP,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAQnD,OAAO,OAAO,QAAQ,mBAkH1C"}
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var shared = require('@edgestore/shared');
|
|
6
|
-
var utils = require('../../utils-
|
|
5
|
+
var shared$1 = require('@edgestore/shared');
|
|
6
|
+
var utils = require('../../utils-681a13a7.js');
|
|
7
7
|
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
|
-
var shared
|
|
9
|
-
require('../../index-
|
|
8
|
+
var shared = require('../../shared-8a6bcddb.js');
|
|
9
|
+
require('../../index-0c5489b9.js');
|
|
10
10
|
require('@panva/hkdf');
|
|
11
11
|
require('cookie');
|
|
12
12
|
require('jose');
|
|
13
13
|
require('uuid');
|
|
14
14
|
|
|
15
15
|
function createEdgeStoreExpressHandler(config) {
|
|
16
|
-
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
16
|
+
const { provider = providers_edgestore_index.EdgeStoreProvider(), cookieConfig } = config;
|
|
17
17
|
const log = new utils.Logger(config.logLevel);
|
|
18
18
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
19
19
|
log.debug('Creating EdgeStore Express handler');
|
|
20
|
+
const resolvedCookieConfig = shared.getCookieConfig(cookieConfig);
|
|
20
21
|
return async (req, res)=>{
|
|
21
22
|
try {
|
|
22
23
|
const pathname = req.url ?? '';
|
|
@@ -30,16 +31,17 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
30
31
|
res
|
|
31
32
|
}) : {};
|
|
32
33
|
} catch (err) {
|
|
33
|
-
throw new shared.EdgeStoreError({
|
|
34
|
+
throw new shared$1.EdgeStoreError({
|
|
34
35
|
message: 'Error creating context',
|
|
35
36
|
code: 'CREATE_CONTEXT_ERROR',
|
|
36
37
|
cause: err instanceof Error ? err : undefined
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
|
-
const { newCookies, token, baseUrl } = await shared
|
|
40
|
+
const { newCookies, token, baseUrl } = await shared.init({
|
|
40
41
|
ctx,
|
|
41
42
|
provider,
|
|
42
|
-
router: config.router
|
|
43
|
+
router: config.router,
|
|
44
|
+
cookieConfig
|
|
43
45
|
});
|
|
44
46
|
res.setHeader('Set-Cookie', newCookies);
|
|
45
47
|
res.json({
|
|
@@ -47,40 +49,40 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
47
49
|
baseUrl
|
|
48
50
|
});
|
|
49
51
|
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
50
|
-
res.json(await shared
|
|
52
|
+
res.json(await shared.requestUpload({
|
|
51
53
|
provider,
|
|
52
54
|
router: config.router,
|
|
53
55
|
body: req.body,
|
|
54
|
-
ctxToken: req.cookies[
|
|
56
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
55
57
|
}));
|
|
56
58
|
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
57
|
-
res.json(await shared
|
|
59
|
+
res.json(await shared.requestUploadParts({
|
|
58
60
|
provider,
|
|
59
61
|
router: config.router,
|
|
60
62
|
body: req.body,
|
|
61
|
-
ctxToken: req.cookies[
|
|
63
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
62
64
|
}));
|
|
63
65
|
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
64
|
-
await shared
|
|
66
|
+
await shared.completeMultipartUpload({
|
|
65
67
|
provider,
|
|
66
68
|
router: config.router,
|
|
67
69
|
body: req.body,
|
|
68
|
-
ctxToken: req.cookies[
|
|
70
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
69
71
|
});
|
|
70
72
|
res.status(200).end();
|
|
71
73
|
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
72
|
-
res.json(await shared
|
|
74
|
+
res.json(await shared.confirmUpload({
|
|
73
75
|
provider,
|
|
74
76
|
router: config.router,
|
|
75
77
|
body: req.body,
|
|
76
|
-
ctxToken: req.cookies[
|
|
78
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
77
79
|
}));
|
|
78
80
|
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
79
|
-
res.json(await shared
|
|
81
|
+
res.json(await shared.deleteFile({
|
|
80
82
|
provider,
|
|
81
83
|
router: config.router,
|
|
82
84
|
body: req.body,
|
|
83
|
-
ctxToken: req.cookies[
|
|
85
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
84
86
|
}));
|
|
85
87
|
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
86
88
|
const { url } = req.query;
|
|
@@ -100,13 +102,13 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
100
102
|
res.status(404).end();
|
|
101
103
|
}
|
|
102
104
|
} catch (err) {
|
|
103
|
-
if (err instanceof shared.EdgeStoreError) {
|
|
105
|
+
if (err instanceof shared$1.EdgeStoreError) {
|
|
104
106
|
log[err.level](err.formattedMessage());
|
|
105
107
|
if (err.cause) log[err.level](err.cause);
|
|
106
|
-
res.status(shared.EDGE_STORE_ERROR_CODES[err.code]).json(err.formattedJson());
|
|
108
|
+
res.status(shared$1.EDGE_STORE_ERROR_CODES[err.code]).json(err.formattedJson());
|
|
107
109
|
} else {
|
|
108
110
|
log.error(err);
|
|
109
|
-
res.status(500).send(new shared.EdgeStoreError({
|
|
111
|
+
res.status(500).send(new shared$1.EdgeStoreError({
|
|
110
112
|
message: 'Internal Server Error',
|
|
111
113
|
code: 'SERVER_ERROR'
|
|
112
114
|
}).formattedJson());
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
-
import { L as Logger, m as matchPath } from '../../utils-
|
|
2
|
+
import { L as Logger, m as matchPath } from '../../utils-2dd5613c.mjs';
|
|
3
3
|
import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
|
|
4
|
-
import { a as init, r as requestUpload,
|
|
5
|
-
import '../../index-
|
|
4
|
+
import { a as getCookieConfig, c as init, r as requestUpload, d as requestUploadParts, e as completeMultipartUpload, f as confirmUpload, h as deleteFile } from '../../shared-d2a0d681.mjs';
|
|
5
|
+
import '../../index-e0432eed.mjs';
|
|
6
6
|
import '@panva/hkdf';
|
|
7
7
|
import 'cookie';
|
|
8
8
|
import 'jose';
|
|
9
9
|
import 'uuid';
|
|
10
10
|
|
|
11
11
|
function createEdgeStoreExpressHandler(config) {
|
|
12
|
-
const { provider = EdgeStoreProvider() } = config;
|
|
12
|
+
const { provider = EdgeStoreProvider(), cookieConfig } = config;
|
|
13
13
|
const log = new Logger(config.logLevel);
|
|
14
14
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
15
15
|
log.debug('Creating EdgeStore Express handler');
|
|
16
|
+
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
16
17
|
return async (req, res)=>{
|
|
17
18
|
try {
|
|
18
19
|
const pathname = req.url ?? '';
|
|
@@ -35,7 +36,8 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
35
36
|
const { newCookies, token, baseUrl } = await init({
|
|
36
37
|
ctx,
|
|
37
38
|
provider,
|
|
38
|
-
router: config.router
|
|
39
|
+
router: config.router,
|
|
40
|
+
cookieConfig
|
|
39
41
|
});
|
|
40
42
|
res.setHeader('Set-Cookie', newCookies);
|
|
41
43
|
res.json({
|
|
@@ -47,21 +49,21 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
47
49
|
provider,
|
|
48
50
|
router: config.router,
|
|
49
51
|
body: req.body,
|
|
50
|
-
ctxToken: req.cookies[
|
|
52
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
51
53
|
}));
|
|
52
54
|
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
53
55
|
res.json(await requestUploadParts({
|
|
54
56
|
provider,
|
|
55
57
|
router: config.router,
|
|
56
58
|
body: req.body,
|
|
57
|
-
ctxToken: req.cookies[
|
|
59
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
58
60
|
}));
|
|
59
61
|
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
60
62
|
await completeMultipartUpload({
|
|
61
63
|
provider,
|
|
62
64
|
router: config.router,
|
|
63
65
|
body: req.body,
|
|
64
|
-
ctxToken: req.cookies[
|
|
66
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
65
67
|
});
|
|
66
68
|
res.status(200).end();
|
|
67
69
|
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
@@ -69,14 +71,14 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
69
71
|
provider,
|
|
70
72
|
router: config.router,
|
|
71
73
|
body: req.body,
|
|
72
|
-
ctxToken: req.cookies[
|
|
74
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
73
75
|
}));
|
|
74
76
|
} else if (matchPath(pathname, '/delete-file')) {
|
|
75
77
|
res.json(await deleteFile({
|
|
76
78
|
provider,
|
|
77
79
|
router: config.router,
|
|
78
80
|
body: req.body,
|
|
79
|
-
ctxToken: req.cookies[
|
|
81
|
+
ctxToken: req.cookies[resolvedCookieConfig.ctx.name]
|
|
80
82
|
}));
|
|
81
83
|
} else if (matchPath(pathname, '/proxy-file')) {
|
|
82
84
|
const { url } = req.query;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FastifyReply, type FastifyRequest } from 'fastify';
|
|
3
3
|
import { type LogLevel } from '../../libs/logger';
|
|
4
|
+
import { type CookieConfig } from '../shared';
|
|
4
5
|
export type CreateContextOptions = {
|
|
5
6
|
req: FastifyRequest;
|
|
6
7
|
reply: FastifyReply;
|
|
@@ -9,10 +10,12 @@ export type Config<TCtx> = {
|
|
|
9
10
|
provider?: Provider;
|
|
10
11
|
router: EdgeStoreRouter<TCtx>;
|
|
11
12
|
logLevel?: LogLevel;
|
|
13
|
+
cookieConfig?: CookieConfig;
|
|
12
14
|
} & (TCtx extends Record<string, never> ? object : {
|
|
13
15
|
provider?: Provider;
|
|
14
16
|
router: EdgeStoreRouter<TCtx>;
|
|
15
17
|
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
18
|
+
cookieConfig?: CookieConfig;
|
|
16
19
|
});
|
|
17
20
|
export declare function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>): (req: FastifyRequest, reply: FastifyReply) => Promise<never>;
|
|
18
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AACjE,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG1D,OAAO,EAUL,KAAK,YAAY,EAIlB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,IAAI,IAAI;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,MAAM,GACN;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IAClE,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC,CAAC;AA6BP,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAQnD,cAAc,SAAS,YAAY,oBAqIvD"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var shared = require('@edgestore/shared');
|
|
6
|
-
var utils = require('../../utils-
|
|
5
|
+
var shared$1 = require('@edgestore/shared');
|
|
6
|
+
var utils = require('../../utils-681a13a7.js');
|
|
7
7
|
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
|
-
var shared
|
|
9
|
-
require('../../index-
|
|
8
|
+
var shared = require('../../shared-8a6bcddb.js');
|
|
9
|
+
require('../../index-0c5489b9.js');
|
|
10
10
|
require('@panva/hkdf');
|
|
11
11
|
require('cookie');
|
|
12
12
|
require('jose');
|
|
@@ -30,10 +30,11 @@ function getCookie(req, name) {
|
|
|
30
30
|
return cookies[name];
|
|
31
31
|
}
|
|
32
32
|
function createEdgeStoreFastifyHandler(config) {
|
|
33
|
-
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
33
|
+
const { provider = providers_edgestore_index.EdgeStoreProvider(), cookieConfig } = config;
|
|
34
34
|
const log = new utils.Logger(config.logLevel);
|
|
35
35
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
36
36
|
log.debug('Creating EdgeStore Fastify handler');
|
|
37
|
+
const resolvedCookieConfig = shared.getCookieConfig(cookieConfig);
|
|
37
38
|
return async (req, reply)=>{
|
|
38
39
|
try {
|
|
39
40
|
// Get the URL from the request - simplified approach
|
|
@@ -48,16 +49,17 @@ function createEdgeStoreFastifyHandler(config) {
|
|
|
48
49
|
reply
|
|
49
50
|
}) : {};
|
|
50
51
|
} catch (err) {
|
|
51
|
-
throw new shared.EdgeStoreError({
|
|
52
|
+
throw new shared$1.EdgeStoreError({
|
|
52
53
|
message: 'Error creating context',
|
|
53
54
|
code: 'CREATE_CONTEXT_ERROR',
|
|
54
55
|
cause: err instanceof Error ? err : undefined
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
|
-
const { newCookies, token, baseUrl } = await shared
|
|
58
|
+
const { newCookies, token, baseUrl } = await shared.init({
|
|
58
59
|
ctx,
|
|
59
60
|
provider,
|
|
60
|
-
router: config.router
|
|
61
|
+
router: config.router,
|
|
62
|
+
cookieConfig
|
|
61
63
|
});
|
|
62
64
|
// Set cookies more efficiently - handling them using void operator
|
|
63
65
|
// to explicitly mark these synchronous calls as intentionally not awaited
|
|
@@ -75,40 +77,40 @@ function createEdgeStoreFastifyHandler(config) {
|
|
|
75
77
|
baseUrl
|
|
76
78
|
});
|
|
77
79
|
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
78
|
-
return reply.send(await shared
|
|
80
|
+
return reply.send(await shared.requestUpload({
|
|
79
81
|
provider,
|
|
80
82
|
router: config.router,
|
|
81
83
|
body: req.body,
|
|
82
|
-
ctxToken: getCookie(req,
|
|
84
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
83
85
|
}));
|
|
84
86
|
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
85
|
-
return reply.send(await shared
|
|
87
|
+
return reply.send(await shared.requestUploadParts({
|
|
86
88
|
provider,
|
|
87
89
|
router: config.router,
|
|
88
90
|
body: req.body,
|
|
89
|
-
ctxToken: getCookie(req,
|
|
91
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
90
92
|
}));
|
|
91
93
|
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
92
|
-
await shared
|
|
94
|
+
await shared.completeMultipartUpload({
|
|
93
95
|
provider,
|
|
94
96
|
router: config.router,
|
|
95
97
|
body: req.body,
|
|
96
|
-
ctxToken: getCookie(req,
|
|
98
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
97
99
|
});
|
|
98
100
|
return reply.status(200).send();
|
|
99
101
|
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
100
|
-
return reply.send(await shared
|
|
102
|
+
return reply.send(await shared.confirmUpload({
|
|
101
103
|
provider,
|
|
102
104
|
router: config.router,
|
|
103
105
|
body: req.body,
|
|
104
|
-
ctxToken: getCookie(req,
|
|
106
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
105
107
|
}));
|
|
106
108
|
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
107
|
-
return reply.send(await shared
|
|
109
|
+
return reply.send(await shared.deleteFile({
|
|
108
110
|
provider,
|
|
109
111
|
router: config.router,
|
|
110
112
|
body: req.body,
|
|
111
|
-
ctxToken: getCookie(req,
|
|
113
|
+
ctxToken: getCookie(req, resolvedCookieConfig.ctx.name)
|
|
112
114
|
}));
|
|
113
115
|
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
114
116
|
const url = req.query ? req.query.url : undefined;
|
|
@@ -129,13 +131,13 @@ function createEdgeStoreFastifyHandler(config) {
|
|
|
129
131
|
return reply.status(404).send();
|
|
130
132
|
}
|
|
131
133
|
} catch (err) {
|
|
132
|
-
if (err instanceof shared.EdgeStoreError) {
|
|
134
|
+
if (err instanceof shared$1.EdgeStoreError) {
|
|
133
135
|
log[err.level](err.formattedMessage());
|
|
134
136
|
if (err.cause) log[err.level](err.cause);
|
|
135
|
-
return reply.status(shared.EDGE_STORE_ERROR_CODES[err.code]).send(err.formattedJson());
|
|
137
|
+
return reply.status(shared$1.EDGE_STORE_ERROR_CODES[err.code]).send(err.formattedJson());
|
|
136
138
|
} else {
|
|
137
139
|
log.error(err);
|
|
138
|
-
return reply.status(500).send(new shared.EdgeStoreError({
|
|
140
|
+
return reply.status(500).send(new shared$1.EdgeStoreError({
|
|
139
141
|
message: 'Internal Server Error',
|
|
140
142
|
code: 'SERVER_ERROR'
|
|
141
143
|
}).formattedJson());
|