@edgestore/server 0.4.0 → 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/adapters/astro/index.d.ts +1 -0
- package/adapters/astro/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 +3 -3
- package/dist/adapters/express/index.mjs +3 -3
- package/dist/adapters/fastify/index.js +3 -3
- package/dist/adapters/fastify/index.mjs +3 -3
- 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 +3 -3
- package/dist/adapters/next/app/index.mjs +3 -3
- package/dist/adapters/next/pages/index.js +3 -3
- package/dist/adapters/next/pages/index.mjs +3 -3
- 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.js +3 -3
- package/dist/adapters/start/index.mjs +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/index.mjs +4 -4
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/{index-a7cc3cd3.mjs → index-2848cb40.mjs} +3 -2
- package/dist/{index-474a21c4.js → index-421c502f.js} +3 -2
- package/dist/{index-b689bf59.js → index-7b259533.js} +5 -4
- 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-d27101a7.js → shared-25dbfab4.js} +17 -4
- package/dist/{shared-c9442cbb.mjs → shared-4b199b96.mjs} +16 -4
- package/dist/{shared-6f6fd0bd.js → shared-685c8a0c.js} +17 -3
- 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 +20 -3
- package/src/adapters/astro/index.ts +222 -0
- package/src/adapters/hono/index.ts +195 -0
- package/src/adapters/remix/index.ts +201 -0
- package/src/adapters/shared.ts +20 -3
- package/src/core/client/index.ts +2 -2
- package/src/core/sdk/index.ts +4 -3
- 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,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');
|
|
@@ -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';
|
|
@@ -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');
|
|
@@ -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';
|
|
@@ -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"}
|
|
@@ -0,0 +1,158 @@
|
|
|
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 Remix request
|
|
16
|
+
function getCookie(req, name) {
|
|
17
|
+
const cookieHeader = req.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 createEdgeStoreRemixHandler(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 Remix handler');
|
|
31
|
+
return async ({ request: req })=>{
|
|
32
|
+
try {
|
|
33
|
+
const url = new URL(req.url);
|
|
34
|
+
const pathname = url.pathname;
|
|
35
|
+
if (utils.matchPath(pathname, '/health')) {
|
|
36
|
+
return new Response('OK');
|
|
37
|
+
} else if (utils.matchPath(pathname, '/init')) {
|
|
38
|
+
let ctx = {};
|
|
39
|
+
try {
|
|
40
|
+
ctx = 'createContext' in config ? await config.createContext({
|
|
41
|
+
req
|
|
42
|
+
}) : {};
|
|
43
|
+
} catch (err) {
|
|
44
|
+
throw new shared.EdgeStoreError({
|
|
45
|
+
message: 'Error creating context',
|
|
46
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
47
|
+
cause: err instanceof Error ? err : undefined
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const { newCookies, token, baseUrl } = await shared$1.init({
|
|
51
|
+
ctx,
|
|
52
|
+
provider,
|
|
53
|
+
router: config.router
|
|
54
|
+
});
|
|
55
|
+
// Create response with cookies and token
|
|
56
|
+
const responseHeaders = new Headers();
|
|
57
|
+
if (Array.isArray(newCookies)) {
|
|
58
|
+
for (const cookie of newCookies){
|
|
59
|
+
responseHeaders.append('Set-Cookie', cookie);
|
|
60
|
+
}
|
|
61
|
+
} else if (newCookies) {
|
|
62
|
+
responseHeaders.append('Set-Cookie', newCookies);
|
|
63
|
+
}
|
|
64
|
+
return new Response(JSON.stringify({
|
|
65
|
+
token,
|
|
66
|
+
baseUrl
|
|
67
|
+
}), {
|
|
68
|
+
headers: responseHeaders,
|
|
69
|
+
status: 200
|
|
70
|
+
});
|
|
71
|
+
} else if (utils.matchPath(pathname, '/request-upload')) {
|
|
72
|
+
const body = await req.json();
|
|
73
|
+
return Response.json(await shared$1.requestUpload({
|
|
74
|
+
provider,
|
|
75
|
+
router: config.router,
|
|
76
|
+
body,
|
|
77
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
78
|
+
}));
|
|
79
|
+
} else if (utils.matchPath(pathname, '/request-upload-parts')) {
|
|
80
|
+
const body = await req.json();
|
|
81
|
+
return Response.json(await shared$1.requestUploadParts({
|
|
82
|
+
provider,
|
|
83
|
+
router: config.router,
|
|
84
|
+
body,
|
|
85
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
86
|
+
}));
|
|
87
|
+
} else if (utils.matchPath(pathname, '/complete-multipart-upload')) {
|
|
88
|
+
const body = await req.json();
|
|
89
|
+
await shared$1.completeMultipartUpload({
|
|
90
|
+
provider,
|
|
91
|
+
router: config.router,
|
|
92
|
+
body,
|
|
93
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
94
|
+
});
|
|
95
|
+
return new Response(null, {
|
|
96
|
+
status: 200
|
|
97
|
+
});
|
|
98
|
+
} else if (utils.matchPath(pathname, '/confirm-upload')) {
|
|
99
|
+
const body = await req.json();
|
|
100
|
+
return Response.json(await shared$1.confirmUpload({
|
|
101
|
+
provider,
|
|
102
|
+
router: config.router,
|
|
103
|
+
body,
|
|
104
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
105
|
+
}));
|
|
106
|
+
} else if (utils.matchPath(pathname, '/delete-file')) {
|
|
107
|
+
const body = await req.json();
|
|
108
|
+
return Response.json(await shared$1.deleteFile({
|
|
109
|
+
provider,
|
|
110
|
+
router: config.router,
|
|
111
|
+
body,
|
|
112
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
113
|
+
}));
|
|
114
|
+
} else if (utils.matchPath(pathname, '/proxy-file')) {
|
|
115
|
+
const url = new URL(req.url).searchParams.get('url');
|
|
116
|
+
if (typeof url === 'string') {
|
|
117
|
+
const proxyRes = await fetch(url, {
|
|
118
|
+
headers: {
|
|
119
|
+
cookie: req.headers.get('cookie') ?? ''
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const data = await proxyRes.arrayBuffer();
|
|
123
|
+
const headers = new Headers();
|
|
124
|
+
headers.set('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
125
|
+
return new Response(data, {
|
|
126
|
+
headers
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
return new Response(null, {
|
|
130
|
+
status: 400
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
return new Response(null, {
|
|
135
|
+
status: 404
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (err instanceof shared.EdgeStoreError) {
|
|
140
|
+
log[err.level](err.formattedMessage());
|
|
141
|
+
if (err.cause) log[err.level](err.cause);
|
|
142
|
+
return Response.json(err.formattedJson(), {
|
|
143
|
+
status: shared.EDGE_STORE_ERROR_CODES[err.code]
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
log.error(err);
|
|
147
|
+
return Response.json(new shared.EdgeStoreError({
|
|
148
|
+
message: 'Internal Server Error',
|
|
149
|
+
code: 'SERVER_ERROR'
|
|
150
|
+
}).formattedJson(), {
|
|
151
|
+
status: 500
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
exports.createEdgeStoreRemixHandler = createEdgeStoreRemixHandler;
|
|
@@ -0,0 +1,154 @@
|
|
|
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 Remix request
|
|
12
|
+
function getCookie(req, name) {
|
|
13
|
+
const cookieHeader = req.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 createEdgeStoreRemixHandler(config) {
|
|
23
|
+
const { provider = EdgeStoreProvider() } = config;
|
|
24
|
+
const log = new Logger(config.logLevel);
|
|
25
|
+
globalThis._EDGE_STORE_LOGGER = log;
|
|
26
|
+
log.debug('Creating EdgeStore Remix handler');
|
|
27
|
+
return async ({ request: req })=>{
|
|
28
|
+
try {
|
|
29
|
+
const url = new URL(req.url);
|
|
30
|
+
const pathname = url.pathname;
|
|
31
|
+
if (matchPath(pathname, '/health')) {
|
|
32
|
+
return new Response('OK');
|
|
33
|
+
} else if (matchPath(pathname, '/init')) {
|
|
34
|
+
let ctx = {};
|
|
35
|
+
try {
|
|
36
|
+
ctx = 'createContext' in config ? await config.createContext({
|
|
37
|
+
req
|
|
38
|
+
}) : {};
|
|
39
|
+
} catch (err) {
|
|
40
|
+
throw new EdgeStoreError({
|
|
41
|
+
message: 'Error creating context',
|
|
42
|
+
code: 'CREATE_CONTEXT_ERROR',
|
|
43
|
+
cause: err instanceof Error ? err : undefined
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const { newCookies, token, baseUrl } = await init({
|
|
47
|
+
ctx,
|
|
48
|
+
provider,
|
|
49
|
+
router: config.router
|
|
50
|
+
});
|
|
51
|
+
// Create response with cookies and token
|
|
52
|
+
const responseHeaders = new Headers();
|
|
53
|
+
if (Array.isArray(newCookies)) {
|
|
54
|
+
for (const cookie of newCookies){
|
|
55
|
+
responseHeaders.append('Set-Cookie', cookie);
|
|
56
|
+
}
|
|
57
|
+
} else if (newCookies) {
|
|
58
|
+
responseHeaders.append('Set-Cookie', newCookies);
|
|
59
|
+
}
|
|
60
|
+
return new Response(JSON.stringify({
|
|
61
|
+
token,
|
|
62
|
+
baseUrl
|
|
63
|
+
}), {
|
|
64
|
+
headers: responseHeaders,
|
|
65
|
+
status: 200
|
|
66
|
+
});
|
|
67
|
+
} else if (matchPath(pathname, '/request-upload')) {
|
|
68
|
+
const body = await req.json();
|
|
69
|
+
return Response.json(await requestUpload({
|
|
70
|
+
provider,
|
|
71
|
+
router: config.router,
|
|
72
|
+
body,
|
|
73
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
74
|
+
}));
|
|
75
|
+
} else if (matchPath(pathname, '/request-upload-parts')) {
|
|
76
|
+
const body = await req.json();
|
|
77
|
+
return Response.json(await requestUploadParts({
|
|
78
|
+
provider,
|
|
79
|
+
router: config.router,
|
|
80
|
+
body,
|
|
81
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
82
|
+
}));
|
|
83
|
+
} else if (matchPath(pathname, '/complete-multipart-upload')) {
|
|
84
|
+
const body = await req.json();
|
|
85
|
+
await completeMultipartUpload({
|
|
86
|
+
provider,
|
|
87
|
+
router: config.router,
|
|
88
|
+
body,
|
|
89
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
90
|
+
});
|
|
91
|
+
return new Response(null, {
|
|
92
|
+
status: 200
|
|
93
|
+
});
|
|
94
|
+
} else if (matchPath(pathname, '/confirm-upload')) {
|
|
95
|
+
const body = await req.json();
|
|
96
|
+
return Response.json(await confirmUpload({
|
|
97
|
+
provider,
|
|
98
|
+
router: config.router,
|
|
99
|
+
body,
|
|
100
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
101
|
+
}));
|
|
102
|
+
} else if (matchPath(pathname, '/delete-file')) {
|
|
103
|
+
const body = await req.json();
|
|
104
|
+
return Response.json(await deleteFile({
|
|
105
|
+
provider,
|
|
106
|
+
router: config.router,
|
|
107
|
+
body,
|
|
108
|
+
ctxToken: getCookie(req, 'edgestore-ctx')
|
|
109
|
+
}));
|
|
110
|
+
} else if (matchPath(pathname, '/proxy-file')) {
|
|
111
|
+
const url = new URL(req.url).searchParams.get('url');
|
|
112
|
+
if (typeof url === 'string') {
|
|
113
|
+
const proxyRes = await fetch(url, {
|
|
114
|
+
headers: {
|
|
115
|
+
cookie: req.headers.get('cookie') ?? ''
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const data = await proxyRes.arrayBuffer();
|
|
119
|
+
const headers = new Headers();
|
|
120
|
+
headers.set('Content-Type', proxyRes.headers.get('Content-Type') ?? 'application/octet-stream');
|
|
121
|
+
return new Response(data, {
|
|
122
|
+
headers
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
return new Response(null, {
|
|
126
|
+
status: 400
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
return new Response(null, {
|
|
131
|
+
status: 404
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
} catch (err) {
|
|
135
|
+
if (err instanceof EdgeStoreError) {
|
|
136
|
+
log[err.level](err.formattedMessage());
|
|
137
|
+
if (err.cause) log[err.level](err.cause);
|
|
138
|
+
return Response.json(err.formattedJson(), {
|
|
139
|
+
status: EDGE_STORE_ERROR_CODES[err.code]
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
log.error(err);
|
|
143
|
+
return Response.json(new EdgeStoreError({
|
|
144
|
+
message: 'Internal Server Error',
|
|
145
|
+
code: 'SERVER_ERROR'
|
|
146
|
+
}).formattedJson(), {
|
|
147
|
+
status: 500
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { createEdgeStoreRemixHandler };
|