@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
|
@@ -0,0 +1,143 @@
|
|
|
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 Fastify request
|
|
12
|
+
function getCookie(req, name) {
|
|
13
|
+
// Check if cookies plugin is available
|
|
14
|
+
if ('cookies' in req) {
|
|
15
|
+
// Type assertion for TypeScript
|
|
16
|
+
return req.cookies[name];
|
|
17
|
+
}
|
|
18
|
+
// Fallback to parsing cookie header
|
|
19
|
+
const cookieHeader = req.headers.cookie;
|
|
20
|
+
if (!cookieHeader) return undefined;
|
|
21
|
+
const cookies = cookieHeader.split(';').reduce((acc, cookie)=>{
|
|
22
|
+
const [key, value] = cookie.trim().split('=');
|
|
23
|
+
if (key && value) acc[key] = value;
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
return cookies[name];
|
|
27
|
+
}
|
|
28
|
+
function createEdgeStoreFastifyHandler(config) {
|
|
29
|
+
const { provider = EdgeStoreProvider() } = config;
|
|
30
|
+
const log = new Logger(config.logLevel);
|
|
31
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
32
|
+
log.debug('Creating EdgeStore Fastify handler');
|
|
33
|
+
return async (req, reply)=>{
|
|
34
|
+
try {
|
|
35
|
+
// Get the URL from the request - simplified approach
|
|
36
|
+
const pathname = req.url;
|
|
37
|
+
if (matchPath(pathname, '/health')) {
|
|
38
|
+
return reply.send('OK');
|
|
39
|
+
} else if (matchPath(pathname, '/init')) {
|
|
40
|
+
let ctx = {};
|
|
41
|
+
try {
|
|
42
|
+
ctx = 'createContext' in config ? await config.createContext({
|
|
43
|
+
req,
|
|
44
|
+
reply
|
|
45
|
+
}) : {};
|
|
46
|
+
} catch (err) {
|
|
47
|
+
throw new EdgeStoreError({
|
|
48
|
+
message: 'Error creating context',
|
|
49
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
50
|
+
cause: err instanceof Error ? err : undefined
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const { newCookies, token, baseUrl } = await init({
|
|
54
|
+
ctx,
|
|
55
|
+
provider,
|
|
56
|
+
router: config.router
|
|
57
|
+
});
|
|
58
|
+
// Set cookies more efficiently - handling them using void operator
|
|
59
|
+
// to explicitly mark these synchronous calls as intentionally not awaited
|
|
60
|
+
if (Array.isArray(newCookies)) {
|
|
61
|
+
// If it's an array of cookies, set them all
|
|
62
|
+
for (const cookie of newCookies){
|
|
63
|
+
void reply.header('Set-Cookie', cookie);
|
|
64
|
+
}
|
|
65
|
+
} else if (newCookies) {
|
|
66
|
+
// If it's a single cookie string
|
|
67
|
+
void reply.header('Set-Cookie', newCookies);
|
|
68
|
+
}
|
|
69
|
+
return reply.send({
|
|
70
|
+
token,
|
|
71
|
+
baseUrl
|
|
72
|
+
});
|
|
73
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
74
|
+
return reply.send(await requestUpload({
|
|
75
|
+
provider,
|
|
76
|
+
router: config.router,
|
|
77
|
+
body: req.body,
|
|
78
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
79
|
+
}));
|
|
80
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
81
|
+
return reply.send(await requestUploadParts({
|
|
82
|
+
provider,
|
|
83
|
+
router: config.router,
|
|
84
|
+
body: req.body,
|
|
85
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
86
|
+
}));
|
|
87
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
88
|
+
await completeMultipartUpload({
|
|
89
|
+
provider,
|
|
90
|
+
router: config.router,
|
|
91
|
+
body: req.body,
|
|
92
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
93
|
+
});
|
|
94
|
+
return reply.status(200).send();
|
|
95
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
96
|
+
return reply.send(await confirmUpload({
|
|
97
|
+
provider,
|
|
98
|
+
router: config.router,
|
|
99
|
+
body: req.body,
|
|
100
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
101
|
+
}));
|
|
102
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
103
|
+
return reply.send(await deleteFile({
|
|
104
|
+
provider,
|
|
105
|
+
router: config.router,
|
|
106
|
+
body: req.body,
|
|
107
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
108
|
+
}));
|
|
109
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
110
|
+
const url = req.query ? req.query.url : undefined;
|
|
111
|
+
if (typeof url === 'string') {
|
|
112
|
+
const cookieHeader = req.headers.cookie ?? '';
|
|
113
|
+
const proxyRes = await fetch(url, {
|
|
114
|
+
headers: {
|
|
115
|
+
cookie: cookieHeader
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const data = await proxyRes.arrayBuffer();
|
|
119
|
+
void reply.header('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
120
|
+
return reply.send(Buffer.from(data));
|
|
121
|
+
} else {
|
|
122
|
+
return reply.status(400).send();
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
return reply.status(404).send();
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
if (err instanceof EdgeStoreError) {
|
|
129
|
+
log[err.level](err.formattedMessage());
|
|
130
|
+
if (err.cause) log[err.level](err.cause);
|
|
131
|
+
return reply.status(EDGE_STORE_ERROR_CODES[err.code]).send(err.formattedJson());
|
|
132
|
+
} else {
|
|
133
|
+
log.error(err);
|
|
134
|
+
return reply.status(500).send(new EdgeStoreError({
|
|
135
|
+
message: 'Internal Server Error',
|
|
136
|
+
code: 'SERVER_ERROR'
|
|
137
|
+
}).formattedJson());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { createEdgeStoreFastifyHandler };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type EdgeStoreErrorCodeKey, type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
|
+
import { type Context } from 'hono';
|
|
3
|
+
import { type LogLevel } from '../../libs/logger';
|
|
4
|
+
export type CreateContextOptions = {
|
|
5
|
+
c: Context;
|
|
6
|
+
};
|
|
7
|
+
export type Config<TCtx> = {
|
|
8
|
+
provider?: Provider;
|
|
9
|
+
router: EdgeStoreRouter<TCtx>;
|
|
10
|
+
logLevel?: LogLevel;
|
|
11
|
+
} & (TCtx extends Record<string, never> ? object : {
|
|
12
|
+
provider?: Provider;
|
|
13
|
+
router: EdgeStoreRouter<TCtx>;
|
|
14
|
+
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
15
|
+
});
|
|
16
|
+
export declare function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>): (c: Context) => Promise<(Response & import("hono").TypedResponse<"OK", import("hono/utils/http-status").ContentfulStatusCode, "text">) | (Response & import("hono").TypedResponse<{
|
|
17
|
+
token: string | undefined;
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
20
|
+
uploadUrl: string;
|
|
21
|
+
accessUrl: string;
|
|
22
|
+
thumbnailUrl?: (string | null) | undefined;
|
|
23
|
+
size: number;
|
|
24
|
+
uploadedAt: string;
|
|
25
|
+
path: {
|
|
26
|
+
[x: string]: string;
|
|
27
|
+
};
|
|
28
|
+
pathOrder: string[];
|
|
29
|
+
metadata: {
|
|
30
|
+
[x: string]: string | null | undefined;
|
|
31
|
+
};
|
|
32
|
+
} | {
|
|
33
|
+
multipart: {
|
|
34
|
+
key: string;
|
|
35
|
+
uploadId: string;
|
|
36
|
+
partSize: number;
|
|
37
|
+
totalParts: number;
|
|
38
|
+
parts: {
|
|
39
|
+
partNumber: number;
|
|
40
|
+
uploadUrl: string;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
accessUrl: string;
|
|
44
|
+
thumbnailUrl?: (string | null) | undefined;
|
|
45
|
+
size: number;
|
|
46
|
+
uploadedAt: string;
|
|
47
|
+
path: {
|
|
48
|
+
[x: string]: string;
|
|
49
|
+
};
|
|
50
|
+
pathOrder: string[];
|
|
51
|
+
metadata: {
|
|
52
|
+
[x: string]: string | null | undefined;
|
|
53
|
+
};
|
|
54
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
55
|
+
multipart: {
|
|
56
|
+
uploadId: string;
|
|
57
|
+
parts: {
|
|
58
|
+
partNumber: number;
|
|
59
|
+
uploadUrl: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
|
|
63
|
+
success: boolean;
|
|
64
|
+
}, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<unknown, import("hono/utils/http-status").ContentfulStatusCode, "body">) | (Response & import("hono").TypedResponse<{
|
|
65
|
+
message: string;
|
|
66
|
+
code: "FILE_TOO_LARGE";
|
|
67
|
+
details: {
|
|
68
|
+
maxFileSize: number;
|
|
69
|
+
fileSize: number;
|
|
70
|
+
};
|
|
71
|
+
} | {
|
|
72
|
+
message: string;
|
|
73
|
+
code: "MIME_TYPE_NOT_ALLOWED";
|
|
74
|
+
details: {
|
|
75
|
+
allowedMimeTypes: string[];
|
|
76
|
+
mimeType: string;
|
|
77
|
+
};
|
|
78
|
+
} | {
|
|
79
|
+
message: string;
|
|
80
|
+
code: Exclude<EdgeStoreErrorCodeKey, "FILE_TOO_LARGE" | "MIME_TYPE_NOT_ALLOWED">;
|
|
81
|
+
}, 400 | 401 | 403 | 500, "json">)>;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/hono/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAiB1D,MAAM,MAAM,oBAAoB,GAAG;IACjC,CAAC,EAAE,OAAO,CAAC;CACZ,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;AAeP,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,OAMlD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oCAqIzB"}
|
|
@@ -0,0 +1,137 @@
|
|
|
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 get a cookie value from Hono Context
|
|
16
|
+
function getCookie(c, name) {
|
|
17
|
+
const cookies = c.req.header('cookie');
|
|
18
|
+
if (!cookies) return undefined;
|
|
19
|
+
const match = new RegExp(`${name}=([^;]+)`).exec(cookies);
|
|
20
|
+
return match ? match[1] : undefined;
|
|
21
|
+
}
|
|
22
|
+
function createEdgeStoreHonoHandler(config) {
|
|
23
|
+
const { provider = providers_edgestore_index.EdgeStoreProvider() } = config;
|
|
24
|
+
const log = new utils.Logger(config.logLevel);
|
|
25
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
26
|
+
log.debug('Creating EdgeStore Hono handler');
|
|
27
|
+
return async (c)=>{
|
|
28
|
+
try {
|
|
29
|
+
const pathname = new URL(c.req.url).pathname;
|
|
30
|
+
if (utils.matchPath(pathname, '/health')) {
|
|
31
|
+
return c.text('OK');
|
|
32
|
+
} else if (utils.matchPath(pathname, '/init')) {
|
|
33
|
+
let ctx = {};
|
|
34
|
+
try {
|
|
35
|
+
ctx = 'createContext' in config ? await config.createContext({
|
|
36
|
+
c
|
|
37
|
+
}) : {};
|
|
38
|
+
} catch (err) {
|
|
39
|
+
throw new shared.EdgeStoreError({
|
|
40
|
+
message: 'Error creating context',
|
|
41
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
42
|
+
cause: err instanceof Error ? err : undefined
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const { newCookies, token, baseUrl } = await shared$1.init({
|
|
46
|
+
ctx,
|
|
47
|
+
provider,
|
|
48
|
+
router: config.router
|
|
49
|
+
});
|
|
50
|
+
// Set cookies
|
|
51
|
+
if (Array.isArray(newCookies)) {
|
|
52
|
+
for (const cookie of newCookies){
|
|
53
|
+
c.header('Set-Cookie', cookie);
|
|
54
|
+
}
|
|
55
|
+
} else if (newCookies) {
|
|
56
|
+
c.header('Set-Cookie', newCookies);
|
|
57
|
+
}
|
|
58
|
+
return c.json({
|
|
59
|
+
token,
|
|
60
|
+
baseUrl
|
|
61
|
+
});
|
|
62
|
+
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
63
|
+
const body = await c.req.json();
|
|
64
|
+
return c.json(await shared$1.requestUpload({
|
|
65
|
+
provider,
|
|
66
|
+
router: config.router,
|
|
67
|
+
body,
|
|
68
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
69
|
+
}));
|
|
70
|
+
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
71
|
+
const body = await c.req.json();
|
|
72
|
+
return c.json(await shared$1.requestUploadParts({
|
|
73
|
+
provider,
|
|
74
|
+
router: config.router,
|
|
75
|
+
body,
|
|
76
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
77
|
+
}));
|
|
78
|
+
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
79
|
+
const body = await c.req.json();
|
|
80
|
+
await shared$1.completeMultipartUpload({
|
|
81
|
+
provider,
|
|
82
|
+
router: config.router,
|
|
83
|
+
body,
|
|
84
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
85
|
+
});
|
|
86
|
+
return c.body(null, 200);
|
|
87
|
+
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
88
|
+
const body = await c.req.json();
|
|
89
|
+
return c.json(await shared$1.confirmUpload({
|
|
90
|
+
provider,
|
|
91
|
+
router: config.router,
|
|
92
|
+
body,
|
|
93
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
94
|
+
}));
|
|
95
|
+
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
96
|
+
const body = await c.req.json();
|
|
97
|
+
return c.json(await shared$1.deleteFile({
|
|
98
|
+
provider,
|
|
99
|
+
router: config.router,
|
|
100
|
+
body,
|
|
101
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
102
|
+
}));
|
|
103
|
+
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
104
|
+
const url = c.req.query('url');
|
|
105
|
+
if (typeof url === 'string') {
|
|
106
|
+
const cookieHeader = c.req.header('cookie') ?? '';
|
|
107
|
+
const proxyRes = await fetch(url, {
|
|
108
|
+
headers: {
|
|
109
|
+
cookie: cookieHeader
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const data = await proxyRes.arrayBuffer();
|
|
113
|
+
c.header('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
114
|
+
return c.body(Buffer.from(data));
|
|
115
|
+
} else {
|
|
116
|
+
return c.body(null, 400);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
return c.body(null, 404);
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
if (err instanceof shared.EdgeStoreError) {
|
|
123
|
+
log[err.level](err.formattedMessage());
|
|
124
|
+
if (err.cause) log[err.level](err.cause);
|
|
125
|
+
return c.json(err.formattedJson(), shared.EDGE_STORE_ERROR_CODES[err.code]);
|
|
126
|
+
} else {
|
|
127
|
+
log.error(err);
|
|
128
|
+
return c.json(new shared.EdgeStoreError({
|
|
129
|
+
message: 'Internal Server Error',
|
|
130
|
+
code: 'SERVER_ERROR'
|
|
131
|
+
}).formattedJson(), 500);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.createEdgeStoreHonoHandler = createEdgeStoreHonoHandler;
|
|
@@ -0,0 +1,133 @@
|
|
|
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 get a cookie value from Hono Context
|
|
12
|
+
function getCookie(c, name) {
|
|
13
|
+
const cookies = c.req.header('cookie');
|
|
14
|
+
if (!cookies) return undefined;
|
|
15
|
+
const match = new RegExp(`${name}=([^;]+)`).exec(cookies);
|
|
16
|
+
return match ? match[1] : undefined;
|
|
17
|
+
}
|
|
18
|
+
function createEdgeStoreHonoHandler(config) {
|
|
19
|
+
const { provider = EdgeStoreProvider() } = config;
|
|
20
|
+
const log = new Logger(config.logLevel);
|
|
21
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
22
|
+
log.debug('Creating EdgeStore Hono handler');
|
|
23
|
+
return async (c)=>{
|
|
24
|
+
try {
|
|
25
|
+
const pathname = new URL(c.req.url).pathname;
|
|
26
|
+
if (matchPath(pathname, '/health')) {
|
|
27
|
+
return c.text('OK');
|
|
28
|
+
} else if (matchPath(pathname, '/init')) {
|
|
29
|
+
let ctx = {};
|
|
30
|
+
try {
|
|
31
|
+
ctx = 'createContext' in config ? await config.createContext({
|
|
32
|
+
c
|
|
33
|
+
}) : {};
|
|
34
|
+
} catch (err) {
|
|
35
|
+
throw new EdgeStoreError({
|
|
36
|
+
message: 'Error creating context',
|
|
37
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
38
|
+
cause: err instanceof Error ? err : undefined
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const { newCookies, token, baseUrl } = await init({
|
|
42
|
+
ctx,
|
|
43
|
+
provider,
|
|
44
|
+
router: config.router
|
|
45
|
+
});
|
|
46
|
+
// Set cookies
|
|
47
|
+
if (Array.isArray(newCookies)) {
|
|
48
|
+
for (const cookie of newCookies){
|
|
49
|
+
c.header('Set-Cookie', cookie);
|
|
50
|
+
}
|
|
51
|
+
} else if (newCookies) {
|
|
52
|
+
c.header('Set-Cookie', newCookies);
|
|
53
|
+
}
|
|
54
|
+
return c.json({
|
|
55
|
+
token,
|
|
56
|
+
baseUrl
|
|
57
|
+
});
|
|
58
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
59
|
+
const body = await c.req.json();
|
|
60
|
+
return c.json(await requestUpload({
|
|
61
|
+
provider,
|
|
62
|
+
router: config.router,
|
|
63
|
+
body,
|
|
64
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
65
|
+
}));
|
|
66
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
67
|
+
const body = await c.req.json();
|
|
68
|
+
return c.json(await requestUploadParts({
|
|
69
|
+
provider,
|
|
70
|
+
router: config.router,
|
|
71
|
+
body,
|
|
72
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
73
|
+
}));
|
|
74
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
75
|
+
const body = await c.req.json();
|
|
76
|
+
await completeMultipartUpload({
|
|
77
|
+
provider,
|
|
78
|
+
router: config.router,
|
|
79
|
+
body,
|
|
80
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
81
|
+
});
|
|
82
|
+
return c.body(null, 200);
|
|
83
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
84
|
+
const body = await c.req.json();
|
|
85
|
+
return c.json(await confirmUpload({
|
|
86
|
+
provider,
|
|
87
|
+
router: config.router,
|
|
88
|
+
body,
|
|
89
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
90
|
+
}));
|
|
91
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
92
|
+
const body = await c.req.json();
|
|
93
|
+
return c.json(await deleteFile({
|
|
94
|
+
provider,
|
|
95
|
+
router: config.router,
|
|
96
|
+
body,
|
|
97
|
+
ctxToken: getCookie(c, 'edgestore-ctx')
|
|
98
|
+
}));
|
|
99
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
100
|
+
const url = c.req.query('url');
|
|
101
|
+
if (typeof url === 'string') {
|
|
102
|
+
const cookieHeader = c.req.header('cookie') ?? '';
|
|
103
|
+
const proxyRes = await fetch(url, {
|
|
104
|
+
headers: {
|
|
105
|
+
cookie: cookieHeader
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const data = await proxyRes.arrayBuffer();
|
|
109
|
+
c.header('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
110
|
+
return c.body(Buffer.from(data));
|
|
111
|
+
} else {
|
|
112
|
+
return c.body(null, 400);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
return c.body(null, 404);
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (err instanceof EdgeStoreError) {
|
|
119
|
+
log[err.level](err.formattedMessage());
|
|
120
|
+
if (err.cause) log[err.level](err.cause);
|
|
121
|
+
return c.json(err.formattedJson(), EDGE_STORE_ERROR_CODES[err.code]);
|
|
122
|
+
} else {
|
|
123
|
+
log.error(err);
|
|
124
|
+
return c.json(new EdgeStoreError({
|
|
125
|
+
message: 'Internal Server Error',
|
|
126
|
+
code: 'SERVER_ERROR'
|
|
127
|
+
}).formattedJson(), 500);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { createEdgeStoreHonoHandler };
|
|
@@ -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 createEdgeStoreNextHandler(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 Next handler (app adapter)');
|
|
20
20
|
return async (req)=>{
|
|
21
21
|
try {
|
|
22
22
|
if (!('nextUrl' in req)) throw new shared.EdgeStoreError({
|
|
@@ -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 createEdgeStoreNextHandler(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 Next handler (app adapter)');
|
|
16
16
|
return async (req)=>{
|
|
17
17
|
try {
|
|
18
18
|
if (!('nextUrl' in req)) throw new EdgeStoreError({
|
|
@@ -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 createEdgeStoreNextHandler(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 Next handler (pages adapter)');
|
|
20
20
|
return async (req, res)=>{
|
|
21
21
|
try {
|
|
22
22
|
if (!('json' in res)) throw new shared.EdgeStoreError({
|
|
@@ -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 createEdgeStoreNextHandler(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 Next handler (pages adapter)');
|
|
16
16
|
return async (req, res)=>{
|
|
17
17
|
try {
|
|
18
18
|
if (!('json' in res)) throw new EdgeStoreError({
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type EdgeStoreRouter, type MaybePromise, type Provider } from '@edgestore/shared';
|
|
2
|
+
import { type LogLevel } from '../../libs/logger';
|
|
3
|
+
export type CreateContextOptions = {
|
|
4
|
+
req: Request;
|
|
5
|
+
};
|
|
6
|
+
export type Config<TCtx> = {
|
|
7
|
+
provider?: Provider;
|
|
8
|
+
router: EdgeStoreRouter<TCtx>;
|
|
9
|
+
logLevel?: LogLevel;
|
|
10
|
+
} & (TCtx extends Record<string, never> ? object : {
|
|
11
|
+
provider?: Provider;
|
|
12
|
+
router: EdgeStoreRouter<TCtx>;
|
|
13
|
+
createContext: (opts: CreateContextOptions) => MaybePromise<TCtx>;
|
|
14
|
+
});
|
|
15
|
+
export declare function createEdgeStoreRemixHandler<TCtx>(config: Config<TCtx>): ({ request: req }: {
|
|
16
|
+
request: Request;
|
|
17
|
+
}) => Promise<Response>;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/remix/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAe,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAiB1D,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,OAAO,CAAC;CACd,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;AAsBP,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,sBAMpC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,uBAqIrD"}
|