@edgestore/server 0.3.3 → 0.5.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/README.md +3 -3
- package/adapters/astro/index.d.ts +1 -0
- package/adapters/astro/index.js +1 -0
- package/adapters/fastify/index.d.ts +1 -0
- package/adapters/fastify/index.js +1 -0
- package/adapters/hono/index.d.ts +1 -0
- package/adapters/hono/index.js +1 -0
- package/adapters/remix/index.d.ts +1 -0
- package/adapters/remix/index.js +1 -0
- package/dist/adapters/astro/index.d.ts +14 -0
- package/dist/adapters/astro/index.d.ts.map +1 -0
- package/dist/adapters/astro/index.js +183 -0
- package/dist/adapters/astro/index.mjs +179 -0
- package/dist/adapters/express/index.js +4 -4
- package/dist/adapters/express/index.mjs +4 -4
- package/dist/adapters/fastify/index.d.ts +18 -0
- package/dist/adapters/fastify/index.d.ts.map +1 -0
- package/dist/adapters/fastify/index.js +147 -0
- package/dist/adapters/fastify/index.mjs +143 -0
- package/dist/adapters/hono/index.d.ts +82 -0
- package/dist/adapters/hono/index.d.ts.map +1 -0
- package/dist/adapters/hono/index.js +137 -0
- package/dist/adapters/hono/index.mjs +133 -0
- package/dist/adapters/next/app/index.js +4 -4
- package/dist/adapters/next/app/index.mjs +4 -4
- package/dist/adapters/next/pages/index.js +4 -4
- package/dist/adapters/next/pages/index.mjs +4 -4
- package/dist/adapters/remix/index.d.ts +18 -0
- package/dist/adapters/remix/index.d.ts.map +1 -0
- package/dist/adapters/remix/index.js +158 -0
- package/dist/adapters/remix/index.mjs +154 -0
- package/dist/adapters/shared.d.ts +2 -0
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/start/index.d.ts.map +1 -1
- package/dist/adapters/start/index.js +4 -4
- package/dist/adapters/start/index.mjs +4 -4
- package/dist/core/client/index.d.ts +1 -1
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -3
- package/dist/core/index.mjs +4 -4
- package/dist/core/sdk/index.d.ts +4 -4
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/{index-28efdacf.mjs → index-2848cb40.mjs} +4 -3
- package/dist/{index-beed799d.js → index-421c502f.js} +4 -3
- package/dist/{index-4491caf0.js → index-7b259533.js} +6 -5
- package/dist/libs/logger.d.ts +1 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +7 -2
- package/dist/providers/aws/index.mjs +7 -2
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +6 -1
- package/dist/providers/azure/index.mjs +6 -1
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +13 -6
- package/dist/providers/edgestore/index.mjs +10 -3
- package/dist/{shared-83f288f6.js → shared-25dbfab4.js} +19 -6
- package/dist/{shared-039276af.mjs → shared-4b199b96.mjs} +17 -5
- package/dist/{shared-7c700083.js → shared-685c8a0c.js} +18 -4
- package/dist/{utils-5819d5e1.js → utils-0aab6e3b.js} +3 -1
- package/dist/{utils-f6f56d38.mjs → utils-7349adab.mjs} +3 -1
- package/dist/{utils-461a2e3b.js → utils-b3d35894.js} +3 -2
- package/package.json +31 -8
- package/src/adapters/astro/index.ts +222 -0
- package/src/adapters/express/index.ts +1 -1
- package/src/adapters/fastify/index.ts +205 -0
- package/src/adapters/hono/index.ts +195 -0
- package/src/adapters/next/app/index.ts +1 -1
- package/src/adapters/next/pages/index.ts +1 -1
- package/src/adapters/remix/index.ts +201 -0
- package/src/adapters/shared.ts +21 -4
- package/src/adapters/start/index.ts +1 -1
- package/src/core/client/index.ts +11 -3
- package/src/core/sdk/index.ts +4 -3
- package/src/libs/errors/EdgeStoreCredentialsError.ts +1 -1
- package/src/libs/logger.ts +4 -3
- package/src/providers/aws/index.ts +8 -7
- package/src/providers/azure/index.ts +5 -4
- package/src/providers/edgestore/index.ts +8 -3
- package/adapters/index.d.ts +0 -1
- package/adapters/index.js +0 -1
- package/providers/index.d.ts +0 -1
- package/providers/index.js +0 -1
package/README.md
CHANGED
|
@@ -26,9 +26,9 @@ EDGE_STORE_SECRET_KEY=your-secret-key
|
|
|
26
26
|
### Backend
|
|
27
27
|
|
|
28
28
|
Now we can create the backend code for our Next.js app.<br/>
|
|
29
|
-
|
|
29
|
+
EdgeStore is compatible with both types of Next.js apps (`pages router` and `app router`).
|
|
30
30
|
|
|
31
|
-
The example below is the simplest bucket you can create with
|
|
31
|
+
The example below is the simplest bucket you can create with EdgeStore. Just a simple file bucket with no validation that will be accessible by anyone with the link.
|
|
32
32
|
|
|
33
33
|
You can have multiple buckets in your app, each with its own configuration.
|
|
34
34
|
|
|
@@ -39,7 +39,7 @@ import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app'
|
|
|
39
39
|
const es = initEdgeStore.create();
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
* This is the main router for the
|
|
42
|
+
* This is the main router for the EdgeStore buckets.
|
|
43
43
|
*/
|
|
44
44
|
const edgeStoreRouter = es.router({
|
|
45
45
|
publicFiles: es.fileBucket(),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/adapters/astro';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/adapters/astro');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/adapters/fastify';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/adapters/fastify');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/adapters/hono';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/adapters/hono');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/adapters/remix';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/adapters/remix');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
|
+
import type { APIContext } from 'astro';
|
|
3
|
+
import { type LogLevel } from '../../libs/logger';
|
|
4
|
+
export type Config<TCtx> = {
|
|
5
|
+
provider?: Provider;
|
|
6
|
+
router: EdgeStoreRouter<TCtx>;
|
|
7
|
+
logLevel?: LogLevel;
|
|
8
|
+
} & (TCtx extends Record<string, never> ? object : {
|
|
9
|
+
provider?: Provider;
|
|
10
|
+
router: EdgeStoreRouter<TCtx>;
|
|
11
|
+
createContext: (opts: APIContext) => MaybePromise<TCtx>;
|
|
12
|
+
});
|
|
13
|
+
export declare function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>): (context: APIContext) => Promise<Response>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAiB1D,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;CACrB,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;CACzD,CAAC,CAAC;AAsBP,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,aAM7C,UAAU,uBA6JlC"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var shared = require('@edgestore/shared');
|
|
6
|
+
var utils = require('../../utils-0aab6e3b.js');
|
|
7
|
+
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
|
+
var shared$1 = require('../../shared-685c8a0c.js');
|
|
9
|
+
require('../../index-7b259533.js');
|
|
10
|
+
require('@panva/hkdf');
|
|
11
|
+
require('cookie');
|
|
12
|
+
require('jose');
|
|
13
|
+
require('uuid');
|
|
14
|
+
|
|
15
|
+
// Helper to safely get cookies from Astro request
|
|
16
|
+
function getCookie(request, name) {
|
|
17
|
+
const cookieHeader = request.headers.get('cookie');
|
|
18
|
+
if (!cookieHeader) return undefined;
|
|
19
|
+
const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
|
|
20
|
+
const [key, value] = cookie.trim().split('=');
|
|
21
|
+
if (key && value) acc[key] = value;
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
return cookies[name];
|
|
25
|
+
}
|
|
26
|
+
function createEdgeStoreAstroHandler(config) {
|
|
27
|
+
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
28
|
+
const log = new utils.Logger(config.logLevel);
|
|
29
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
30
|
+
log.debug('Creating EdgeStore Astro handler');
|
|
31
|
+
return async (context)=>{
|
|
32
|
+
try {
|
|
33
|
+
const { request } = context;
|
|
34
|
+
const url = new URL(request.url);
|
|
35
|
+
if (utils.matchPath(url.pathname, 'health')) {
|
|
36
|
+
return new Response('OK');
|
|
37
|
+
} else if (utils.matchPath(url.pathname, 'init')) {
|
|
38
|
+
let ctx = {};
|
|
39
|
+
try {
|
|
40
|
+
ctx = 'createContext' in config ? await config.createContext(context) : {};
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw new shared.EdgeStoreError({
|
|
43
|
+
message: 'Error creating context',
|
|
44
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
45
|
+
cause: err instanceof Error ? err : undefined
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const { newCookies, token, baseUrl } = await shared$1.init({
|
|
49
|
+
ctx,
|
|
50
|
+
provider,
|
|
51
|
+
router: config.router
|
|
52
|
+
});
|
|
53
|
+
const headers = new Headers();
|
|
54
|
+
headers.set('Content-Type', 'application/json');
|
|
55
|
+
// Set cookies
|
|
56
|
+
if (Array.isArray(newCookies)) {
|
|
57
|
+
for (const cookie of newCookies){
|
|
58
|
+
headers.append('Set-Cookie', cookie);
|
|
59
|
+
}
|
|
60
|
+
} else if (newCookies) {
|
|
61
|
+
headers.append('Set-Cookie', newCookies);
|
|
62
|
+
}
|
|
63
|
+
return new Response(JSON.stringify({
|
|
64
|
+
token,
|
|
65
|
+
baseUrl
|
|
66
|
+
}), {
|
|
67
|
+
headers
|
|
68
|
+
});
|
|
69
|
+
} else if (utils.matchPath(url.pathname, 'request-upload')) {
|
|
70
|
+
const body = await request.json();
|
|
71
|
+
const result = await shared$1.requestUpload({
|
|
72
|
+
provider,
|
|
73
|
+
router: config.router,
|
|
74
|
+
body,
|
|
75
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
76
|
+
});
|
|
77
|
+
return new Response(JSON.stringify(result), {
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else if (utils.matchPath(url.pathname, 'request-upload-parts')) {
|
|
83
|
+
const body = await request.json();
|
|
84
|
+
const result = await shared$1.requestUploadParts({
|
|
85
|
+
provider,
|
|
86
|
+
router: config.router,
|
|
87
|
+
body,
|
|
88
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
89
|
+
});
|
|
90
|
+
return new Response(JSON.stringify(result), {
|
|
91
|
+
headers: {
|
|
92
|
+
'Content-Type': 'application/json'
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
} else if (utils.matchPath(url.pathname, 'complete-multipart-upload')) {
|
|
96
|
+
const body = await request.json();
|
|
97
|
+
await shared$1.completeMultipartUpload({
|
|
98
|
+
provider,
|
|
99
|
+
router: config.router,
|
|
100
|
+
body,
|
|
101
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
102
|
+
});
|
|
103
|
+
return new Response(null, {
|
|
104
|
+
status: 200
|
|
105
|
+
});
|
|
106
|
+
} else if (utils.matchPath(url.pathname, 'confirm-upload')) {
|
|
107
|
+
const body = await request.json();
|
|
108
|
+
const result = await shared$1.confirmUpload({
|
|
109
|
+
provider,
|
|
110
|
+
router: config.router,
|
|
111
|
+
body,
|
|
112
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
113
|
+
});
|
|
114
|
+
return new Response(JSON.stringify(result), {
|
|
115
|
+
headers: {
|
|
116
|
+
'Content-Type': 'application/json'
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
} else if (utils.matchPath(url.pathname, 'delete-file')) {
|
|
120
|
+
const body = await request.json();
|
|
121
|
+
const result = await shared$1.deleteFile({
|
|
122
|
+
provider,
|
|
123
|
+
router: config.router,
|
|
124
|
+
body,
|
|
125
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
126
|
+
});
|
|
127
|
+
return new Response(JSON.stringify(result), {
|
|
128
|
+
headers: {
|
|
129
|
+
'Content-Type': 'application/json'
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
} else if (utils.matchPath(url.pathname, 'proxy-file')) {
|
|
133
|
+
const url = new URL(request.url).searchParams.get('url');
|
|
134
|
+
if (typeof url === 'string') {
|
|
135
|
+
const cookieHeader = request.headers.get('cookie') ?? '';
|
|
136
|
+
const proxyRes = await fetch(url, {
|
|
137
|
+
headers: {
|
|
138
|
+
cookie: cookieHeader
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const data = await proxyRes.arrayBuffer();
|
|
142
|
+
const headers = new Headers();
|
|
143
|
+
headers.set('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
144
|
+
return new Response(data, {
|
|
145
|
+
headers
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
return new Response(null, {
|
|
149
|
+
status: 400
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
return new Response(null, {
|
|
154
|
+
status: 404
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
if (err instanceof shared.EdgeStoreError) {
|
|
159
|
+
log[err.level](err.formattedMessage());
|
|
160
|
+
if (err.cause) log[err.level](err.cause);
|
|
161
|
+
return new Response(JSON.stringify(err.formattedJson()), {
|
|
162
|
+
status: shared.EDGE_STORE_ERROR_CODES[err.code],
|
|
163
|
+
headers: {
|
|
164
|
+
'Content-Type': 'application/json'
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
log.error(err);
|
|
169
|
+
return new Response(JSON.stringify(new shared.EdgeStoreError({
|
|
170
|
+
message: 'Internal Server Error',
|
|
171
|
+
code: 'SERVER_ERROR'
|
|
172
|
+
}).formattedJson()), {
|
|
173
|
+
status: 500,
|
|
174
|
+
headers: {
|
|
175
|
+
'Content-Type': 'application/json'
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
exports.createEdgeStoreAstroHandler = createEdgeStoreAstroHandler;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { EdgeStoreError, EDGE_STORE_ERROR_CODES } from '@edgestore/shared';
|
|
2
|
+
import { L as Logger, m as matchPath } from '../../utils-7349adab.mjs';
|
|
3
|
+
import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
|
|
4
|
+
import { a as init, r as requestUpload, c as requestUploadParts, d as completeMultipartUpload, e as confirmUpload, f as deleteFile } from '../../shared-4b199b96.mjs';
|
|
5
|
+
import '../../index-2848cb40.mjs';
|
|
6
|
+
import '@panva/hkdf';
|
|
7
|
+
import 'cookie';
|
|
8
|
+
import 'jose';
|
|
9
|
+
import 'uuid';
|
|
10
|
+
|
|
11
|
+
// Helper to safely get cookies from Astro request
|
|
12
|
+
function getCookie(request, name) {
|
|
13
|
+
const cookieHeader = request.headers.get('cookie');
|
|
14
|
+
if (!cookieHeader) return undefined;
|
|
15
|
+
const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
|
|
16
|
+
const [key, value] = cookie.trim().split('=');
|
|
17
|
+
if (key && value) acc[key] = value;
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
return cookies[name];
|
|
21
|
+
}
|
|
22
|
+
function createEdgeStoreAstroHandler(config) {
|
|
23
|
+
const { provider = EdgeStoreProvider() } = config;
|
|
24
|
+
const log = new Logger(config.logLevel);
|
|
25
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
26
|
+
log.debug('Creating EdgeStore Astro handler');
|
|
27
|
+
return async (context)=>{
|
|
28
|
+
try {
|
|
29
|
+
const { request } = context;
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
if (matchPath(url.pathname, 'health')) {
|
|
32
|
+
return new Response('OK');
|
|
33
|
+
} else if (matchPath(url.pathname, 'init')) {
|
|
34
|
+
let ctx = {};
|
|
35
|
+
try {
|
|
36
|
+
ctx = 'createContext' in config ? await config.createContext(context) : {};
|
|
37
|
+
} catch (err) {
|
|
38
|
+
throw new EdgeStoreError({
|
|
39
|
+
message: 'Error creating context',
|
|
40
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
41
|
+
cause: err instanceof Error ? err : undefined
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const { newCookies, token, baseUrl } = await init({
|
|
45
|
+
ctx,
|
|
46
|
+
provider,
|
|
47
|
+
router: config.router
|
|
48
|
+
});
|
|
49
|
+
const headers = new Headers();
|
|
50
|
+
headers.set('Content-Type', 'application/json');
|
|
51
|
+
// Set cookies
|
|
52
|
+
if (Array.isArray(newCookies)) {
|
|
53
|
+
for (const cookie of newCookies){
|
|
54
|
+
headers.append('Set-Cookie', cookie);
|
|
55
|
+
}
|
|
56
|
+
} else if (newCookies) {
|
|
57
|
+
headers.append('Set-Cookie', newCookies);
|
|
58
|
+
}
|
|
59
|
+
return new Response(JSON.stringify({
|
|
60
|
+
token,
|
|
61
|
+
baseUrl
|
|
62
|
+
}), {
|
|
63
|
+
headers
|
|
64
|
+
});
|
|
65
|
+
} else if (matchPath(url.pathname, 'request-upload')) {
|
|
66
|
+
const body = await request.json();
|
|
67
|
+
const result = await requestUpload({
|
|
68
|
+
provider,
|
|
69
|
+
router: config.router,
|
|
70
|
+
body,
|
|
71
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
72
|
+
});
|
|
73
|
+
return new Response(JSON.stringify(result), {
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/json'
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
} else if (matchPath(url.pathname, 'request-upload-parts')) {
|
|
79
|
+
const body = await request.json();
|
|
80
|
+
const result = await requestUploadParts({
|
|
81
|
+
provider,
|
|
82
|
+
router: config.router,
|
|
83
|
+
body,
|
|
84
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
85
|
+
});
|
|
86
|
+
return new Response(JSON.stringify(result), {
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': 'application/json'
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
} else if (matchPath(url.pathname, 'complete-multipart-upload')) {
|
|
92
|
+
const body = await request.json();
|
|
93
|
+
await completeMultipartUpload({
|
|
94
|
+
provider,
|
|
95
|
+
router: config.router,
|
|
96
|
+
body,
|
|
97
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
98
|
+
});
|
|
99
|
+
return new Response(null, {
|
|
100
|
+
status: 200
|
|
101
|
+
});
|
|
102
|
+
} else if (matchPath(url.pathname, 'confirm-upload')) {
|
|
103
|
+
const body = await request.json();
|
|
104
|
+
const result = await confirmUpload({
|
|
105
|
+
provider,
|
|
106
|
+
router: config.router,
|
|
107
|
+
body,
|
|
108
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
109
|
+
});
|
|
110
|
+
return new Response(JSON.stringify(result), {
|
|
111
|
+
headers: {
|
|
112
|
+
'Content-Type': 'application/json'
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
} else if (matchPath(url.pathname, 'delete-file')) {
|
|
116
|
+
const body = await request.json();
|
|
117
|
+
const result = await deleteFile({
|
|
118
|
+
provider,
|
|
119
|
+
router: config.router,
|
|
120
|
+
body,
|
|
121
|
+
ctxToken: getCookie(request, 'edgestore-ctx')
|
|
122
|
+
});
|
|
123
|
+
return new Response(JSON.stringify(result), {
|
|
124
|
+
headers: {
|
|
125
|
+
'Content-Type': 'application/json'
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
} else if (matchPath(url.pathname, 'proxy-file')) {
|
|
129
|
+
const url = new URL(request.url).searchParams.get('url');
|
|
130
|
+
if (typeof url === 'string') {
|
|
131
|
+
const cookieHeader = request.headers.get('cookie') ?? '';
|
|
132
|
+
const proxyRes = await fetch(url, {
|
|
133
|
+
headers: {
|
|
134
|
+
cookie: cookieHeader
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const data = await proxyRes.arrayBuffer();
|
|
138
|
+
const headers = new Headers();
|
|
139
|
+
headers.set('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
140
|
+
return new Response(data, {
|
|
141
|
+
headers
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
return new Response(null, {
|
|
145
|
+
status: 400
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
return new Response(null, {
|
|
150
|
+
status: 404
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
if (err instanceof EdgeStoreError) {
|
|
155
|
+
log[err.level](err.formattedMessage());
|
|
156
|
+
if (err.cause) log[err.level](err.cause);
|
|
157
|
+
return new Response(JSON.stringify(err.formattedJson()), {
|
|
158
|
+
status: EDGE_STORE_ERROR_CODES[err.code],
|
|
159
|
+
headers: {
|
|
160
|
+
'Content-Type': 'application/json'
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
164
|
+
log.error(err);
|
|
165
|
+
return new Response(JSON.stringify(new EdgeStoreError({
|
|
166
|
+
message: 'Internal Server Error',
|
|
167
|
+
code: 'SERVER_ERROR'
|
|
168
|
+
}).formattedJson()), {
|
|
169
|
+
status: 500,
|
|
170
|
+
headers: {
|
|
171
|
+
'Content-Type': 'application/json'
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { createEdgeStoreAstroHandler };
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var shared = require('@edgestore/shared');
|
|
6
|
-
var utils = require('../../utils-
|
|
6
|
+
var utils = require('../../utils-0aab6e3b.js');
|
|
7
7
|
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
|
-
var shared$1 = require('../../shared-
|
|
9
|
-
require('../../index-
|
|
8
|
+
var shared$1 = require('../../shared-685c8a0c.js');
|
|
9
|
+
require('../../index-7b259533.js');
|
|
10
10
|
require('@panva/hkdf');
|
|
11
11
|
require('cookie');
|
|
12
12
|
require('jose');
|
|
@@ -16,7 +16,7 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
16
16
|
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
17
17
|
const log = new utils.Logger(config.logLevel);
|
|
18
18
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
19
|
-
log.debug('Creating
|
|
19
|
+
log.debug('Creating EdgeStore Express handler');
|
|
20
20
|
return async (req, res)=>{
|
|
21
21
|
try {
|
|
22
22
|
const pathname = req.url ?? '';
|
|
@@ -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-7349adab.mjs';
|
|
3
3
|
import { EdgeStoreProvider } from '../../providers/edgestore/index.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import '../../index-
|
|
4
|
+
import { a as init, r as requestUpload, c as requestUploadParts, d as completeMultipartUpload, e as confirmUpload, f as deleteFile } from '../../shared-4b199b96.mjs';
|
|
5
|
+
import '../../index-2848cb40.mjs';
|
|
6
6
|
import '@panva/hkdf';
|
|
7
7
|
import 'cookie';
|
|
8
8
|
import 'jose';
|
|
@@ -12,7 +12,7 @@ function createEdgeStoreExpressHandler(config) {
|
|
|
12
12
|
const { provider = EdgeStoreProvider() } = config;
|
|
13
13
|
const log = new Logger(config.logLevel);
|
|
14
14
|
globalThis._EDGE_STORE_LOGGER = log;
|
|
15
|
-
log.debug('Creating
|
|
15
|
+
log.debug('Creating EdgeStore Express handler');
|
|
16
16
|
return async (req, res)=>{
|
|
17
17
|
try {
|
|
18
18
|
const pathname = req.url ?? '';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
|
+
import { type FastifyRequest, type FastifyReply } from 'fastify';
|
|
3
|
+
import { type LogLevel } from '../../libs/logger';
|
|
4
|
+
export type CreateContextOptions = {
|
|
5
|
+
req: FastifyRequest;
|
|
6
|
+
reply: FastifyReply;
|
|
7
|
+
};
|
|
8
|
+
export type Config<TCtx> = {
|
|
9
|
+
provider?: Provider;
|
|
10
|
+
router: EdgeStoreRouter<TCtx>;
|
|
11
|
+
logLevel?: LogLevel;
|
|
12
|
+
} & (TCtx extends Record<string, never> ? object : {
|
|
13
|
+
provider?: Provider;
|
|
14
|
+
router: EdgeStoreRouter<TCtx>;
|
|
15
|
+
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
16
|
+
});
|
|
17
|
+
export declare function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>): (req: FastifyRequest, reply: FastifyReply) => Promise<never>;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAiB1D,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;CACrB,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;CACnE,CAAC,CAAC;AA2BP,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,SAMnD,cAAc,SAAS,YAAY,oBAkIvD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var shared = require('@edgestore/shared');
|
|
6
|
+
var utils = require('../../utils-0aab6e3b.js');
|
|
7
|
+
var providers_edgestore_index = require('../../providers/edgestore/index.js');
|
|
8
|
+
var shared$1 = require('../../shared-685c8a0c.js');
|
|
9
|
+
require('../../index-7b259533.js');
|
|
10
|
+
require('@panva/hkdf');
|
|
11
|
+
require('cookie');
|
|
12
|
+
require('jose');
|
|
13
|
+
require('uuid');
|
|
14
|
+
|
|
15
|
+
// Helper to safely get cookies from Fastify request
|
|
16
|
+
function getCookie(req, name) {
|
|
17
|
+
// Check if cookies plugin is available
|
|
18
|
+
if ('cookies' in req) {
|
|
19
|
+
// Type assertion for TypeScript
|
|
20
|
+
return req.cookies[name];
|
|
21
|
+
}
|
|
22
|
+
// Fallback to parsing cookie header
|
|
23
|
+
const cookieHeader = req.headers.cookie;
|
|
24
|
+
if (!cookieHeader) return undefined;
|
|
25
|
+
const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
|
|
26
|
+
const [key, value] = cookie.trim().split('=');
|
|
27
|
+
if (key && value) acc[key] = value;
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
return cookies[name];
|
|
31
|
+
}
|
|
32
|
+
function createEdgeStoreFastifyHandler(config) {
|
|
33
|
+
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
34
|
+
const log = new utils.Logger(config.logLevel);
|
|
35
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
36
|
+
log.debug('Creating EdgeStore Fastify handler');
|
|
37
|
+
return async (req, reply)=>{
|
|
38
|
+
try {
|
|
39
|
+
// Get the URL from the request - simplified approach
|
|
40
|
+
const pathname = req.url;
|
|
41
|
+
if (utils.matchPath(pathname, '/health')) {
|
|
42
|
+
return reply.send('OK');
|
|
43
|
+
} else if (utils.matchPath(pathname, '/init')) {
|
|
44
|
+
let ctx = {};
|
|
45
|
+
try {
|
|
46
|
+
ctx = 'createContext' in config ? await config.createContext({
|
|
47
|
+
req,
|
|
48
|
+
reply
|
|
49
|
+
}) : {};
|
|
50
|
+
} catch (err) {
|
|
51
|
+
throw new shared.EdgeStoreError({
|
|
52
|
+
message: 'Error creating context',
|
|
53
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
54
|
+
cause: err instanceof Error ? err : undefined
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const { newCookies, token, baseUrl } = await shared$1.init({
|
|
58
|
+
ctx,
|
|
59
|
+
provider,
|
|
60
|
+
router: config.router
|
|
61
|
+
});
|
|
62
|
+
// Set cookies more efficiently - handling them using void operator
|
|
63
|
+
// to explicitly mark these synchronous calls as intentionally not awaited
|
|
64
|
+
if (Array.isArray(newCookies)) {
|
|
65
|
+
// If it's an array of cookies, set them all
|
|
66
|
+
for (const cookie of newCookies){
|
|
67
|
+
void reply.header('Set-Cookie', cookie);
|
|
68
|
+
}
|
|
69
|
+
} else if (newCookies) {
|
|
70
|
+
// If it's a single cookie string
|
|
71
|
+
void reply.header('Set-Cookie', newCookies);
|
|
72
|
+
}
|
|
73
|
+
return reply.send({
|
|
74
|
+
token,
|
|
75
|
+
baseUrl
|
|
76
|
+
});
|
|
77
|
+
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
78
|
+
return reply.send(await shared$1.requestUpload({
|
|
79
|
+
provider,
|
|
80
|
+
router: config.router,
|
|
81
|
+
body: req.body,
|
|
82
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
83
|
+
}));
|
|
84
|
+
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
85
|
+
return reply.send(await shared$1.requestUploadParts({
|
|
86
|
+
provider,
|
|
87
|
+
router: config.router,
|
|
88
|
+
body: req.body,
|
|
89
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
90
|
+
}));
|
|
91
|
+
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
92
|
+
await shared$1.completeMultipartUpload({
|
|
93
|
+
provider,
|
|
94
|
+
router: config.router,
|
|
95
|
+
body: req.body,
|
|
96
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
97
|
+
});
|
|
98
|
+
return reply.status(200).send();
|
|
99
|
+
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
100
|
+
return reply.send(await shared$1.confirmUpload({
|
|
101
|
+
provider,
|
|
102
|
+
router: config.router,
|
|
103
|
+
body: req.body,
|
|
104
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
105
|
+
}));
|
|
106
|
+
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
107
|
+
return reply.send(await shared$1.deleteFile({
|
|
108
|
+
provider,
|
|
109
|
+
router: config.router,
|
|
110
|
+
body: req.body,
|
|
111
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
112
|
+
}));
|
|
113
|
+
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
114
|
+
const url = req.query ? req.query.url : undefined;
|
|
115
|
+
if (typeof url === 'string') {
|
|
116
|
+
const cookieHeader = req.headers.cookie ?? '';
|
|
117
|
+
const proxyRes = await fetch(url, {
|
|
118
|
+
headers: {
|
|
119
|
+
cookie: cookieHeader
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const data = await proxyRes.arrayBuffer();
|
|
123
|
+
void reply.header('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
124
|
+
return reply.send(Buffer.from(data));
|
|
125
|
+
} else {
|
|
126
|
+
return reply.status(400).send();
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
return reply.status(404).send();
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err instanceof shared.EdgeStoreError) {
|
|
133
|
+
log[err.level](err.formattedMessage());
|
|
134
|
+
if (err.cause) log[err.level](err.cause);
|
|
135
|
+
return reply.status(shared.EDGE_STORE_ERROR_CODES[err.code]).send(err.formattedJson());
|
|
136
|
+
} else {
|
|
137
|
+
log.error(err);
|
|
138
|
+
return reply.status(500).send(new shared.EdgeStoreError({
|
|
139
|
+
message: 'Internal Server Error',
|
|
140
|
+
code: 'SERVER_ERROR'
|
|
141
|
+
}).formattedJson());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
exports.createEdgeStoreFastifyHandler = createEdgeStoreFastifyHandler;
|