@edgestore/server 0.5.7 → 0.6.0-canary.1
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/package.json +1 -0
- package/adapters/express/package.json +1 -0
- package/adapters/fastify/package.json +1 -0
- package/adapters/hono/package.json +1 -0
- package/adapters/next/app/package.json +1 -0
- package/adapters/next/pages/package.json +1 -0
- package/adapters/remix/package.json +1 -0
- package/adapters/start/package.json +1 -0
- package/core/package.json +1 -0
- package/dist/adapters/astro/index.cjs +134 -0
- package/dist/adapters/astro/index.d.cts +20 -0
- package/dist/adapters/astro/index.d.cts.map +1 -0
- package/dist/adapters/astro/index.d.mts +20 -0
- package/dist/adapters/astro/index.d.mts.map +1 -0
- package/dist/adapters/astro/index.mjs +128 -175
- package/dist/adapters/astro/index.mjs.map +1 -0
- package/dist/adapters/express/index.cjs +104 -0
- package/dist/adapters/express/index.d.cts +24 -0
- package/dist/adapters/express/index.d.cts.map +1 -0
- package/dist/adapters/express/index.d.mts +24 -0
- package/dist/adapters/express/index.d.mts.map +1 -0
- package/dist/adapters/express/index.mjs +100 -112
- package/dist/adapters/express/index.mjs.map +1 -0
- package/dist/adapters/fastify/index.cjs +115 -0
- package/dist/adapters/fastify/index.d.cts +24 -0
- package/dist/adapters/fastify/index.d.cts.map +1 -0
- package/dist/adapters/fastify/index.d.mts +24 -0
- package/dist/adapters/fastify/index.d.mts.map +1 -0
- package/dist/adapters/fastify/index.mjs +109 -139
- package/dist/adapters/fastify/index.mjs.map +1 -0
- package/dist/adapters/hono/index.cjs +117 -0
- package/dist/adapters/hono/index.d.cts +91 -0
- package/dist/adapters/hono/index.d.cts.map +1 -0
- package/dist/adapters/hono/index.d.mts +91 -0
- package/dist/adapters/hono/index.d.mts.map +1 -0
- package/dist/adapters/hono/index.mjs +111 -129
- package/dist/adapters/hono/index.mjs.map +1 -0
- package/dist/adapters/next/app/index.cjs +140 -0
- package/dist/adapters/next/app/index.d.cts +23 -0
- package/dist/adapters/next/app/index.d.cts.map +1 -0
- package/dist/adapters/next/app/index.d.mts +23 -0
- package/dist/adapters/next/app/index.d.mts.map +1 -0
- package/dist/adapters/next/app/index.mjs +136 -168
- package/dist/adapters/next/app/index.mjs.map +1 -0
- package/dist/adapters/next/pages/index.cjs +108 -0
- package/dist/adapters/next/pages/index.d.cts +24 -0
- package/dist/adapters/next/pages/index.d.cts.map +1 -0
- package/dist/adapters/next/pages/index.d.mts +24 -0
- package/dist/adapters/next/pages/index.d.mts.map +1 -0
- package/dist/adapters/next/pages/index.mjs +104 -116
- package/dist/adapters/next/pages/index.mjs.map +1 -0
- package/dist/adapters/remix/index.cjs +124 -0
- package/dist/adapters/remix/index.d.cts +26 -0
- package/dist/adapters/remix/index.d.cts.map +1 -0
- package/dist/adapters/remix/index.d.mts +26 -0
- package/dist/adapters/remix/index.d.mts.map +1 -0
- package/dist/adapters/remix/index.mjs +118 -150
- package/dist/adapters/remix/index.mjs.map +1 -0
- package/dist/adapters/start/index.cjs +156 -0
- package/dist/adapters/start/index.d.cts +26 -0
- package/dist/adapters/start/index.d.cts.map +1 -0
- package/dist/adapters/start/index.d.mts +26 -0
- package/dist/adapters/start/index.d.mts.map +1 -0
- package/dist/adapters/start/index.mjs +150 -184
- package/dist/adapters/start/index.mjs.map +1 -0
- package/dist/core/index.cjs +148 -0
- package/dist/core/index.d.cts +500 -0
- package/dist/core/index.d.cts.map +1 -0
- package/dist/core/index.d.mts +500 -0
- package/dist/core/index.d.mts.map +1 -0
- package/dist/core/index.mjs +135 -169
- package/dist/core/index.mjs.map +1 -0
- package/dist/edgestore-Cr88uKUx.mjs +142 -0
- package/dist/edgestore-Cr88uKUx.mjs.map +1 -0
- package/dist/edgestore-Dqb-EoFm.cjs +146 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -1
- package/dist/providers/aws/index.cjs +89 -0
- package/dist/providers/aws/index.d.cts +71 -0
- package/dist/providers/aws/index.d.cts.map +1 -0
- package/dist/providers/aws/index.d.mts +71 -0
- package/dist/providers/aws/index.d.mts.map +1 -0
- package/dist/providers/aws/index.mjs +85 -102
- package/dist/providers/aws/index.mjs.map +1 -0
- package/dist/providers/azure/index.cjs +56 -0
- package/dist/providers/azure/index.d.cts +44 -0
- package/dist/providers/azure/index.d.cts.map +1 -0
- package/dist/providers/azure/index.d.mts +44 -0
- package/dist/providers/azure/index.d.mts.map +1 -0
- package/dist/providers/azure/index.mjs +52 -58
- package/dist/providers/azure/index.mjs.map +1 -0
- package/dist/providers/edgestore/index.cjs +5 -0
- package/dist/providers/edgestore/index.d.cts +23 -0
- package/dist/providers/edgestore/index.d.cts.map +1 -0
- package/dist/providers/edgestore/index.d.mts +23 -0
- package/dist/providers/edgestore/index.d.mts.map +1 -0
- package/dist/providers/edgestore/index.mjs +4 -146
- package/dist/sdk-AhXUPMy1.cjs +238 -0
- package/dist/sdk-CKRQe75P.mjs +222 -0
- package/dist/sdk-CKRQe75P.mjs.map +1 -0
- package/dist/shared-B39MtSQo.d.cts +68 -0
- package/dist/shared-B39MtSQo.d.cts.map +1 -0
- package/dist/shared-Bd7-gfqa.mjs +457 -0
- package/dist/shared-Bd7-gfqa.mjs.map +1 -0
- package/dist/shared-DsWTtQ1-.d.mts +68 -0
- package/dist/shared-DsWTtQ1-.d.mts.map +1 -0
- package/dist/shared-pWGwhEsU.cjs +527 -0
- package/dist/utils--x-q_GK5.mjs +44 -0
- package/dist/utils--x-q_GK5.mjs.map +1 -0
- package/dist/utils-D6YuBNUV.cjs +54 -0
- package/package.json +121 -57
- package/providers/aws/package.json +1 -0
- package/providers/azure/package.json +1 -0
- package/providers/edgestore/package.json +1 -0
- package/adapters/astro/index.d.ts +0 -1
- package/adapters/astro/index.js +0 -1
- package/adapters/express/index.d.ts +0 -1
- package/adapters/express/index.js +0 -1
- package/adapters/fastify/index.d.ts +0 -1
- package/adapters/fastify/index.js +0 -1
- package/adapters/hono/index.d.ts +0 -1
- package/adapters/hono/index.js +0 -1
- package/adapters/next/app/index.d.ts +0 -1
- package/adapters/next/app/index.js +0 -1
- package/adapters/next/pages/index.d.ts +0 -1
- package/adapters/next/pages/index.js +0 -1
- package/adapters/remix/index.d.ts +0 -1
- package/adapters/remix/index.js +0 -1
- package/adapters/start/index.d.ts +0 -1
- package/adapters/start/index.js +0 -1
- package/core/index.d.ts +0 -1
- package/core/index.js +0 -1
- package/dist/adapters/astro/index.d.ts +0 -17
- package/dist/adapters/astro/index.d.ts.map +0 -1
- package/dist/adapters/astro/index.js +0 -186
- package/dist/adapters/express/index.d.ts +0 -21
- package/dist/adapters/express/index.d.ts.map +0 -1
- package/dist/adapters/express/index.js +0 -121
- package/dist/adapters/fastify/index.d.ts +0 -21
- package/dist/adapters/fastify/index.d.ts.map +0 -1
- package/dist/adapters/fastify/index.js +0 -150
- package/dist/adapters/hono/index.d.ts +0 -86
- package/dist/adapters/hono/index.d.ts.map +0 -1
- package/dist/adapters/hono/index.js +0 -140
- package/dist/adapters/imageTypes.d.ts +0 -2
- package/dist/adapters/imageTypes.d.ts.map +0 -1
- package/dist/adapters/next/app/index.d.ts +0 -20
- package/dist/adapters/next/app/index.d.ts.map +0 -1
- package/dist/adapters/next/app/index.js +0 -177
- package/dist/adapters/next/pages/index.d.ts +0 -21
- package/dist/adapters/next/pages/index.d.ts.map +0 -1
- package/dist/adapters/next/pages/index.js +0 -125
- package/dist/adapters/remix/index.d.ts +0 -21
- package/dist/adapters/remix/index.d.ts.map +0 -1
- package/dist/adapters/remix/index.js +0 -161
- package/dist/adapters/shared.d.ts +0 -167
- package/dist/adapters/shared.d.ts.map +0 -1
- package/dist/adapters/start/index.d.ts +0 -21
- package/dist/adapters/start/index.d.ts.map +0 -1
- package/dist/adapters/start/index.js +0 -195
- package/dist/core/client/index.d.ts +0 -217
- package/dist/core/client/index.d.ts.map +0 -1
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -186
- package/dist/core/sdk/index.d.ts +0 -240
- package/dist/core/sdk/index.d.ts.map +0 -1
- package/dist/index-1e7b1b93.js +0 -235
- package/dist/index-a36b09a6.mjs +0 -231
- package/dist/index-b0fff508.js +0 -231
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -12
- package/dist/libs/errors/EdgeStoreCredentialsError.d.ts +0 -5
- package/dist/libs/errors/EdgeStoreCredentialsError.d.ts.map +0 -1
- package/dist/libs/logger.d.ts +0 -13
- package/dist/libs/logger.d.ts.map +0 -1
- package/dist/libs/utils.d.ts +0 -5
- package/dist/libs/utils.d.ts.map +0 -1
- package/dist/providers/aws/index.d.ts +0 -68
- package/dist/providers/aws/index.d.ts.map +0 -1
- package/dist/providers/aws/index.js +0 -111
- package/dist/providers/azure/index.d.ts +0 -39
- package/dist/providers/azure/index.d.ts.map +0 -1
- package/dist/providers/azure/index.js +0 -67
- package/dist/providers/edgestore/index.d.ts +0 -19
- package/dist/providers/edgestore/index.d.ts.map +0 -1
- package/dist/providers/edgestore/index.js +0 -151
- package/dist/shared-4ec2dc90.js +0 -466
- package/dist/shared-64e9c30c.js +0 -435
- package/dist/shared-c6527780.mjs +0 -454
- package/dist/utils-26113e02.js +0 -65
- package/dist/utils-ab564a9e.js +0 -44
- package/dist/utils-cba23eef.mjs +0 -62
- package/providers/aws/index.d.ts +0 -1
- package/providers/aws/index.js +0 -1
- package/providers/azure/index.d.ts +0 -1
- package/providers/azure/index.js +0 -1
- package/providers/edgestore/index.d.ts +0 -1
- package/providers/edgestore/index.js +0 -1
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { EdgeStoreError } from "@edgestore/shared";
|
|
2
|
+
import { hkdf } from "@panva/hkdf";
|
|
3
|
+
import { serialize } from "cookie";
|
|
4
|
+
import { EncryptJWT, jwtDecrypt } from "jose";
|
|
5
|
+
import { v4 } from "uuid";
|
|
6
|
+
|
|
7
|
+
//#region src/adapters/imageTypes.ts
|
|
8
|
+
const IMAGE_MIME_TYPES = [
|
|
9
|
+
"image/jpeg",
|
|
10
|
+
"image/png",
|
|
11
|
+
"image/gif",
|
|
12
|
+
"image/webp",
|
|
13
|
+
"image/svg+xml",
|
|
14
|
+
"image/tiff",
|
|
15
|
+
"image/bmp",
|
|
16
|
+
"image/x-icon"
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
21
|
+
function _typeof(o) {
|
|
22
|
+
"@babel/helpers - typeof";
|
|
23
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
24
|
+
return typeof o$1;
|
|
25
|
+
} : function(o$1) {
|
|
26
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
27
|
+
}, _typeof(o);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
32
|
+
function toPrimitive(t, r) {
|
|
33
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
34
|
+
var e = t[Symbol.toPrimitive];
|
|
35
|
+
if (void 0 !== e) {
|
|
36
|
+
var i = e.call(t, r || "default");
|
|
37
|
+
if ("object" != _typeof(i)) return i;
|
|
38
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
39
|
+
}
|
|
40
|
+
return ("string" === r ? String : Number)(t);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
45
|
+
function toPropertyKey(t) {
|
|
46
|
+
var i = toPrimitive(t, "string");
|
|
47
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
52
|
+
function _defineProperty(e, r, t) {
|
|
53
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
54
|
+
value: t,
|
|
55
|
+
enumerable: !0,
|
|
56
|
+
configurable: !0,
|
|
57
|
+
writable: !0
|
|
58
|
+
}) : e[r] = t, e;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/objectSpread2.js
|
|
63
|
+
function ownKeys(e, r) {
|
|
64
|
+
var t = Object.keys(e);
|
|
65
|
+
if (Object.getOwnPropertySymbols) {
|
|
66
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
67
|
+
r && (o = o.filter(function(r$1) {
|
|
68
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
69
|
+
})), t.push.apply(t, o);
|
|
70
|
+
}
|
|
71
|
+
return t;
|
|
72
|
+
}
|
|
73
|
+
function _objectSpread2(e) {
|
|
74
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
75
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
76
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
77
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
78
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
79
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return e;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/adapters/shared.ts
|
|
87
|
+
const DEFAULT_MAX_AGE = 720 * 60 * 60;
|
|
88
|
+
/**
|
|
89
|
+
* Merges the provided cookie configuration with default values
|
|
90
|
+
*/
|
|
91
|
+
function getCookieConfig(cookieConfig) {
|
|
92
|
+
var _cookieConfig$ctx$nam, _cookieConfig$ctx, _cookieConfig$ctx2, _cookieConfig$token$n, _cookieConfig$token, _cookieConfig$token2;
|
|
93
|
+
const defaultOptions = {
|
|
94
|
+
path: "/",
|
|
95
|
+
maxAge: DEFAULT_MAX_AGE
|
|
96
|
+
};
|
|
97
|
+
const mergeOptions = (configOptions) => {
|
|
98
|
+
const merged = _objectSpread2({}, defaultOptions);
|
|
99
|
+
if (configOptions) Object.keys(configOptions).forEach((key) => {
|
|
100
|
+
const value = configOptions[key];
|
|
101
|
+
if (value !== void 0) merged[key] = value;
|
|
102
|
+
});
|
|
103
|
+
return merged;
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
ctx: {
|
|
107
|
+
name: (_cookieConfig$ctx$nam = cookieConfig === null || cookieConfig === void 0 || (_cookieConfig$ctx = cookieConfig.ctx) === null || _cookieConfig$ctx === void 0 ? void 0 : _cookieConfig$ctx.name) !== null && _cookieConfig$ctx$nam !== void 0 ? _cookieConfig$ctx$nam : "edgestore-ctx",
|
|
108
|
+
options: mergeOptions(cookieConfig === null || cookieConfig === void 0 || (_cookieConfig$ctx2 = cookieConfig.ctx) === null || _cookieConfig$ctx2 === void 0 ? void 0 : _cookieConfig$ctx2.options)
|
|
109
|
+
},
|
|
110
|
+
token: {
|
|
111
|
+
name: (_cookieConfig$token$n = cookieConfig === null || cookieConfig === void 0 || (_cookieConfig$token = cookieConfig.token) === null || _cookieConfig$token === void 0 ? void 0 : _cookieConfig$token.name) !== null && _cookieConfig$token$n !== void 0 ? _cookieConfig$token$n : "edgestore-token",
|
|
112
|
+
options: mergeOptions(cookieConfig === null || cookieConfig === void 0 || (_cookieConfig$token2 = cookieConfig.token) === null || _cookieConfig$token2 === void 0 ? void 0 : _cookieConfig$token2.options)
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function init(params) {
|
|
117
|
+
const log = globalThis._EDGE_STORE_LOGGER;
|
|
118
|
+
const { ctx, provider, router, cookieConfig } = params;
|
|
119
|
+
log.debug("Running [init]", { ctx });
|
|
120
|
+
const resolvedCookieConfig = getCookieConfig(cookieConfig);
|
|
121
|
+
const ctxToken = await encryptJWT(ctx);
|
|
122
|
+
const { token } = await provider.init({
|
|
123
|
+
ctx,
|
|
124
|
+
router
|
|
125
|
+
});
|
|
126
|
+
const newCookies = [serialize(resolvedCookieConfig.ctx.name, ctxToken, resolvedCookieConfig.ctx.options)];
|
|
127
|
+
if (token) newCookies.push(serialize(resolvedCookieConfig.token.name, token, resolvedCookieConfig.token.options));
|
|
128
|
+
const baseUrl = await provider.getBaseUrl();
|
|
129
|
+
log.debug("Finished [init]", {
|
|
130
|
+
ctx,
|
|
131
|
+
newCookies,
|
|
132
|
+
token,
|
|
133
|
+
baseUrl,
|
|
134
|
+
providerName: provider.name
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
newCookies,
|
|
138
|
+
token,
|
|
139
|
+
baseUrl,
|
|
140
|
+
providerName: provider.name
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async function requestUpload(params) {
|
|
144
|
+
var _bucket$_def$bucketCo, _bucket$_def$bucketCo2, _bucket$_def$metadata, _bucket$_def2;
|
|
145
|
+
const { provider, router, ctxToken, body: { bucketName, input, fileInfo } } = params;
|
|
146
|
+
const log = globalThis._EDGE_STORE_LOGGER;
|
|
147
|
+
log.debug("Running [requestUpload]", {
|
|
148
|
+
bucketName,
|
|
149
|
+
input,
|
|
150
|
+
fileInfo
|
|
151
|
+
});
|
|
152
|
+
if (!ctxToken) throw new EdgeStoreError({
|
|
153
|
+
message: "Missing edgestore-ctx cookie",
|
|
154
|
+
code: "UNAUTHORIZED"
|
|
155
|
+
});
|
|
156
|
+
const ctx = await getContext(ctxToken);
|
|
157
|
+
log.debug("Decrypted Context", { ctx });
|
|
158
|
+
const bucket = router.buckets[bucketName];
|
|
159
|
+
if (!bucket) throw new EdgeStoreError({
|
|
160
|
+
message: `Bucket ${bucketName} not found`,
|
|
161
|
+
code: "BAD_REQUEST"
|
|
162
|
+
});
|
|
163
|
+
if (bucket._def.beforeUpload) {
|
|
164
|
+
var _bucket$_def$beforeUp, _bucket$_def;
|
|
165
|
+
log.debug("Running [beforeUpload]");
|
|
166
|
+
const canUpload = await ((_bucket$_def$beforeUp = (_bucket$_def = bucket._def).beforeUpload) === null || _bucket$_def$beforeUp === void 0 ? void 0 : _bucket$_def$beforeUp.call(_bucket$_def, {
|
|
167
|
+
ctx,
|
|
168
|
+
input,
|
|
169
|
+
fileInfo: {
|
|
170
|
+
size: fileInfo.size,
|
|
171
|
+
type: fileInfo.type,
|
|
172
|
+
fileName: fileInfo.fileName,
|
|
173
|
+
extension: fileInfo.extension,
|
|
174
|
+
replaceTargetUrl: fileInfo.replaceTargetUrl,
|
|
175
|
+
temporary: fileInfo.temporary
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
log.debug("Finished [beforeUpload]", { canUpload });
|
|
179
|
+
if (!canUpload) throw new EdgeStoreError({
|
|
180
|
+
message: "Upload not allowed for the current context",
|
|
181
|
+
code: "UPLOAD_NOT_ALLOWED"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (bucket._def.type === "IMAGE") {
|
|
185
|
+
if (!IMAGE_MIME_TYPES.includes(fileInfo.type)) throw new EdgeStoreError({
|
|
186
|
+
code: "MIME_TYPE_NOT_ALLOWED",
|
|
187
|
+
message: "Only images are allowed in this bucket",
|
|
188
|
+
details: {
|
|
189
|
+
allowedMimeTypes: IMAGE_MIME_TYPES,
|
|
190
|
+
mimeType: fileInfo.type
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if ((_bucket$_def$bucketCo = bucket._def.bucketConfig) === null || _bucket$_def$bucketCo === void 0 ? void 0 : _bucket$_def$bucketCo.maxSize) {
|
|
195
|
+
if (fileInfo.size > bucket._def.bucketConfig.maxSize) throw new EdgeStoreError({
|
|
196
|
+
code: "FILE_TOO_LARGE",
|
|
197
|
+
message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`,
|
|
198
|
+
details: {
|
|
199
|
+
maxFileSize: bucket._def.bucketConfig.maxSize,
|
|
200
|
+
fileSize: fileInfo.size
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if ((_bucket$_def$bucketCo2 = bucket._def.bucketConfig) === null || _bucket$_def$bucketCo2 === void 0 ? void 0 : _bucket$_def$bucketCo2.accept) {
|
|
205
|
+
const accept = bucket._def.bucketConfig.accept;
|
|
206
|
+
let accepted = false;
|
|
207
|
+
for (const acceptedMimeType of accept) if (acceptedMimeType.endsWith("/*")) {
|
|
208
|
+
const mimeType = acceptedMimeType.replace("/*", "");
|
|
209
|
+
if (fileInfo.type.startsWith(mimeType)) {
|
|
210
|
+
accepted = true;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
} else if (fileInfo.type === acceptedMimeType) {
|
|
214
|
+
accepted = true;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (!accepted) throw new EdgeStoreError({
|
|
218
|
+
code: "MIME_TYPE_NOT_ALLOWED",
|
|
219
|
+
message: `"${fileInfo.type}" is not allowed. Accepted types are ${JSON.stringify(accept)}`,
|
|
220
|
+
details: {
|
|
221
|
+
allowedMimeTypes: accept,
|
|
222
|
+
mimeType: fileInfo.type
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const path = buildPath({
|
|
227
|
+
fileInfo,
|
|
228
|
+
bucket,
|
|
229
|
+
pathAttrs: {
|
|
230
|
+
ctx,
|
|
231
|
+
input
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const metadata = await ((_bucket$_def$metadata = (_bucket$_def2 = bucket._def).metadata) === null || _bucket$_def$metadata === void 0 ? void 0 : _bucket$_def$metadata.call(_bucket$_def2, {
|
|
235
|
+
ctx,
|
|
236
|
+
input
|
|
237
|
+
}));
|
|
238
|
+
const isPublic = bucket._def.accessControl === void 0;
|
|
239
|
+
log.debug("upload info", {
|
|
240
|
+
path,
|
|
241
|
+
metadata,
|
|
242
|
+
isPublic,
|
|
243
|
+
bucketType: bucket._def.type
|
|
244
|
+
});
|
|
245
|
+
const requestUploadRes = await provider.requestUpload({
|
|
246
|
+
bucketName,
|
|
247
|
+
bucketType: bucket._def.type,
|
|
248
|
+
fileInfo: _objectSpread2(_objectSpread2({}, fileInfo), {}, {
|
|
249
|
+
path,
|
|
250
|
+
isPublic,
|
|
251
|
+
metadata
|
|
252
|
+
})
|
|
253
|
+
});
|
|
254
|
+
const { parsedPath, pathOrder } = parsePath(path);
|
|
255
|
+
log.debug("Finished [requestUpload]");
|
|
256
|
+
return _objectSpread2(_objectSpread2({}, requestUploadRes), {}, {
|
|
257
|
+
size: fileInfo.size,
|
|
258
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
259
|
+
path: parsedPath,
|
|
260
|
+
pathOrder,
|
|
261
|
+
metadata
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
async function requestUploadParts(params) {
|
|
265
|
+
const { provider, ctxToken, body: { multipart, path } } = params;
|
|
266
|
+
const log = globalThis._EDGE_STORE_LOGGER;
|
|
267
|
+
log.debug("Running [requestUploadParts]", {
|
|
268
|
+
multipart,
|
|
269
|
+
path
|
|
270
|
+
});
|
|
271
|
+
if (!ctxToken) throw new EdgeStoreError({
|
|
272
|
+
message: "Missing edgestore-ctx cookie",
|
|
273
|
+
code: "UNAUTHORIZED"
|
|
274
|
+
});
|
|
275
|
+
await getContext(ctxToken);
|
|
276
|
+
const res = await provider.requestUploadParts({
|
|
277
|
+
multipart,
|
|
278
|
+
path
|
|
279
|
+
});
|
|
280
|
+
log.debug("Finished [requestUploadParts]");
|
|
281
|
+
return res;
|
|
282
|
+
}
|
|
283
|
+
async function completeMultipartUpload(params) {
|
|
284
|
+
const { provider, router, ctxToken, body: { bucketName, uploadId, key, parts } } = params;
|
|
285
|
+
const log = globalThis._EDGE_STORE_LOGGER;
|
|
286
|
+
log.debug("Running [completeMultipartUpload]", {
|
|
287
|
+
bucketName,
|
|
288
|
+
uploadId,
|
|
289
|
+
key
|
|
290
|
+
});
|
|
291
|
+
if (!ctxToken) throw new EdgeStoreError({
|
|
292
|
+
message: "Missing edgestore-ctx cookie",
|
|
293
|
+
code: "UNAUTHORIZED"
|
|
294
|
+
});
|
|
295
|
+
await getContext(ctxToken);
|
|
296
|
+
if (!router.buckets[bucketName]) throw new EdgeStoreError({
|
|
297
|
+
message: `Bucket ${bucketName} not found`,
|
|
298
|
+
code: "BAD_REQUEST"
|
|
299
|
+
});
|
|
300
|
+
const res = await provider.completeMultipartUpload({
|
|
301
|
+
uploadId,
|
|
302
|
+
key,
|
|
303
|
+
parts
|
|
304
|
+
});
|
|
305
|
+
log.debug("Finished [completeMultipartUpload]");
|
|
306
|
+
return res;
|
|
307
|
+
}
|
|
308
|
+
async function confirmUpload(params) {
|
|
309
|
+
const { provider, router, ctxToken, body: { bucketName, url } } = params;
|
|
310
|
+
const log = globalThis._EDGE_STORE_LOGGER;
|
|
311
|
+
log.debug("Running [confirmUpload]", {
|
|
312
|
+
bucketName,
|
|
313
|
+
url
|
|
314
|
+
});
|
|
315
|
+
if (!ctxToken) throw new EdgeStoreError({
|
|
316
|
+
message: "Missing edgestore-ctx cookie",
|
|
317
|
+
code: "UNAUTHORIZED"
|
|
318
|
+
});
|
|
319
|
+
await getContext(ctxToken);
|
|
320
|
+
const bucket = router.buckets[bucketName];
|
|
321
|
+
if (!bucket) throw new EdgeStoreError({
|
|
322
|
+
message: `Bucket ${bucketName} not found`,
|
|
323
|
+
code: "BAD_REQUEST"
|
|
324
|
+
});
|
|
325
|
+
const res = await provider.confirmUpload({
|
|
326
|
+
bucket,
|
|
327
|
+
url: unproxyUrl(url)
|
|
328
|
+
});
|
|
329
|
+
log.debug("Finished [confirmUpload]");
|
|
330
|
+
return res;
|
|
331
|
+
}
|
|
332
|
+
async function deleteFile(params) {
|
|
333
|
+
const { provider, router, ctxToken, body: { bucketName, url } } = params;
|
|
334
|
+
const log = globalThis._EDGE_STORE_LOGGER;
|
|
335
|
+
log.debug("Running [deleteFile]", {
|
|
336
|
+
bucketName,
|
|
337
|
+
url
|
|
338
|
+
});
|
|
339
|
+
if (!ctxToken) throw new EdgeStoreError({
|
|
340
|
+
message: "Missing edgestore-ctx cookie",
|
|
341
|
+
code: "UNAUTHORIZED"
|
|
342
|
+
});
|
|
343
|
+
const ctx = await getContext(ctxToken);
|
|
344
|
+
const bucket = router.buckets[bucketName];
|
|
345
|
+
if (!bucket) throw new EdgeStoreError({
|
|
346
|
+
message: `Bucket ${bucketName} not found`,
|
|
347
|
+
code: "BAD_REQUEST"
|
|
348
|
+
});
|
|
349
|
+
if (!bucket._def.beforeDelete) throw new EdgeStoreError({
|
|
350
|
+
message: "You need to define beforeDelete if you want to delete files directly from the frontend.",
|
|
351
|
+
code: "SERVER_ERROR"
|
|
352
|
+
});
|
|
353
|
+
const fileInfo = await provider.getFile({ url: unproxyUrl(url) });
|
|
354
|
+
if (!await bucket._def.beforeDelete({
|
|
355
|
+
ctx,
|
|
356
|
+
fileInfo
|
|
357
|
+
})) throw new EdgeStoreError({
|
|
358
|
+
message: "Delete not allowed for the current context",
|
|
359
|
+
code: "DELETE_NOT_ALLOWED"
|
|
360
|
+
});
|
|
361
|
+
const res = await provider.deleteFile({
|
|
362
|
+
bucket,
|
|
363
|
+
url: unproxyUrl(url)
|
|
364
|
+
});
|
|
365
|
+
log.debug("Finished [deleteFile]");
|
|
366
|
+
return res;
|
|
367
|
+
}
|
|
368
|
+
async function encryptJWT(ctx) {
|
|
369
|
+
var _getEnv;
|
|
370
|
+
const secret = (_getEnv = getEnv("EDGE_STORE_JWT_SECRET")) !== null && _getEnv !== void 0 ? _getEnv : getEnv("EDGE_STORE_SECRET_KEY");
|
|
371
|
+
if (!secret) throw new EdgeStoreError({
|
|
372
|
+
message: "EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined",
|
|
373
|
+
code: "SERVER_ERROR"
|
|
374
|
+
});
|
|
375
|
+
const encryptionSecret = await getDerivedEncryptionKey(secret);
|
|
376
|
+
return await new EncryptJWT(ctx).setProtectedHeader({
|
|
377
|
+
alg: "dir",
|
|
378
|
+
enc: "A256GCM"
|
|
379
|
+
}).setIssuedAt().setExpirationTime(Date.now() / 1e3 + DEFAULT_MAX_AGE).setJti(v4()).encrypt(encryptionSecret);
|
|
380
|
+
}
|
|
381
|
+
async function decryptJWT(token) {
|
|
382
|
+
var _getEnv2;
|
|
383
|
+
const secret = (_getEnv2 = getEnv("EDGE_STORE_JWT_SECRET")) !== null && _getEnv2 !== void 0 ? _getEnv2 : getEnv("EDGE_STORE_SECRET_KEY");
|
|
384
|
+
if (!secret) throw new EdgeStoreError({
|
|
385
|
+
message: "EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined",
|
|
386
|
+
code: "SERVER_ERROR"
|
|
387
|
+
});
|
|
388
|
+
const { payload } = await jwtDecrypt(token, await getDerivedEncryptionKey(secret), { clockTolerance: 15 });
|
|
389
|
+
return payload;
|
|
390
|
+
}
|
|
391
|
+
async function getDerivedEncryptionKey(secret) {
|
|
392
|
+
return await hkdf("sha256", secret, "", "EdgeStore Generated Encryption Key", 32);
|
|
393
|
+
}
|
|
394
|
+
function buildPath(params) {
|
|
395
|
+
const { bucket } = params;
|
|
396
|
+
const pathParams = bucket._def.path;
|
|
397
|
+
return pathParams.map((param) => {
|
|
398
|
+
const paramEntries = Object.entries(param);
|
|
399
|
+
if (paramEntries[0] === void 0) throw new EdgeStoreError({
|
|
400
|
+
message: `Empty path param found in: ${JSON.stringify(pathParams)}`,
|
|
401
|
+
code: "SERVER_ERROR"
|
|
402
|
+
});
|
|
403
|
+
const [key, value] = paramEntries[0];
|
|
404
|
+
return {
|
|
405
|
+
key,
|
|
406
|
+
value: value().split(".").reduce((acc2, key$1) => {
|
|
407
|
+
if (acc2[key$1] === void 0) throw new EdgeStoreError({
|
|
408
|
+
message: `Missing key ${key$1} in ${JSON.stringify(acc2)}`,
|
|
409
|
+
code: "BAD_REQUEST"
|
|
410
|
+
});
|
|
411
|
+
return acc2[key$1];
|
|
412
|
+
}, params.pathAttrs)
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function parsePath(path) {
|
|
417
|
+
return {
|
|
418
|
+
parsedPath: path.reduce((acc, curr) => {
|
|
419
|
+
acc[curr.key] = curr.value;
|
|
420
|
+
return acc;
|
|
421
|
+
}, {}),
|
|
422
|
+
pathOrder: path.map((p) => p.key)
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
async function getContext(token) {
|
|
426
|
+
return await decryptJWT(token);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* On local development, protected files are proxied to the server,
|
|
430
|
+
* which changes the original URL.
|
|
431
|
+
*
|
|
432
|
+
* This function is used to get the original URL,
|
|
433
|
+
* so that we can delete or confirm the upload.
|
|
434
|
+
*/
|
|
435
|
+
function unproxyUrl(url) {
|
|
436
|
+
if (isDev() && url.startsWith("http://")) {
|
|
437
|
+
const urlParam = new URL(url).searchParams.get("url");
|
|
438
|
+
if (urlParam) return urlParam;
|
|
439
|
+
}
|
|
440
|
+
return url;
|
|
441
|
+
}
|
|
442
|
+
function getEnv(key) {
|
|
443
|
+
var _import$meta$env2;
|
|
444
|
+
if (typeof process !== "undefined" && process.env) {
|
|
445
|
+
var _process$env$key, _import$meta$env;
|
|
446
|
+
return (_process$env$key = process.env[key]) !== null && _process$env$key !== void 0 ? _process$env$key : (_import$meta$env = import.meta.env) === null || _import$meta$env === void 0 ? void 0 : _import$meta$env[key];
|
|
447
|
+
}
|
|
448
|
+
return (_import$meta$env2 = import.meta.env) === null || _import$meta$env2 === void 0 ? void 0 : _import$meta$env2[key];
|
|
449
|
+
}
|
|
450
|
+
function isDev() {
|
|
451
|
+
var _process, _import$meta$env3;
|
|
452
|
+
return ((_process = process) === null || _process === void 0 || (_process = _process.env) === null || _process === void 0 ? void 0 : _process.NODE_ENV) === "development" || ((_import$meta$env3 = import.meta.env) === null || _import$meta$env3 === void 0 ? void 0 : _import$meta$env3.DEV);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
//#endregion
|
|
456
|
+
export { getCookieConfig as a, isDev as c, requestUploadParts as d, _objectSpread2 as f, deleteFile as i, parsePath as l, completeMultipartUpload as n, getEnv as o, confirmUpload as r, init as s, buildPath as t, requestUpload as u };
|
|
457
|
+
//# sourceMappingURL=shared-Bd7-gfqa.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-Bd7-gfqa.mjs","names":["defaultOptions: CookieOptions","uuidv4","key"],"sources":["../src/adapters/imageTypes.ts","../src/adapters/shared.ts"],"sourcesContent":["export const IMAGE_MIME_TYPES = [\n 'image/jpeg',\n 'image/png',\n 'image/gif',\n 'image/webp',\n 'image/svg+xml',\n 'image/tiff',\n 'image/bmp',\n 'image/x-icon',\n];\n","import {\n EdgeStoreError,\n type AnyBuilder,\n type EdgeStoreRouter,\n type Provider,\n type SharedDeleteFileRes,\n type SharedInitRes,\n type SharedRequestUploadPartsRes,\n type SharedRequestUploadRes,\n} from '@edgestore/shared';\nimport { hkdf } from '@panva/hkdf';\nimport { serialize } from 'cookie';\nimport { EncryptJWT, jwtDecrypt } from 'jose';\nimport { v4 as uuidv4 } from 'uuid';\nimport type Logger from '../libs/logger';\nimport { IMAGE_MIME_TYPES } from './imageTypes';\n\n// TODO: change it to 1 hour when we have a way to refresh the token\nconst DEFAULT_MAX_AGE = 30 * 24 * 60 * 60; // 30 days\n\ndeclare const globalThis: {\n _EDGE_STORE_LOGGER: Logger;\n};\n\nexport type CookieOptions = {\n /**\n * Cookie path\n * @default \"/\"\n */\n path?: string;\n /**\n * Cookie max age in seconds\n * @default 2592000 (30 days)\n */\n maxAge?: number;\n /**\n * Cookie domain\n */\n domain?: string;\n /**\n * Cookie same site policy\n */\n sameSite?: 'strict' | 'lax' | 'none';\n /**\n * Cookie secure flag\n */\n secure?: boolean;\n /**\n * Cookie http only flag\n */\n httpOnly?: boolean;\n};\n\nexport type CookieConfig = {\n /**\n * Context cookie configuration\n */\n ctx?: {\n /**\n * Name of the context cookie\n * @default \"edgestore-ctx\"\n */\n name?: string;\n /**\n * Cookie options for context cookie\n */\n options?: CookieOptions;\n };\n /**\n * Token cookie configuration\n */\n token?: {\n /**\n * Name of the token cookie\n * @default \"edgestore-token\"\n */\n name?: string;\n /**\n * Cookie options for token cookie\n */\n options?: CookieOptions;\n };\n};\n\ntype ResolvedCookieConfig = {\n ctx: {\n name: string;\n options: CookieOptions;\n };\n token: {\n name: string;\n options: CookieOptions;\n };\n};\n\n/**\n * Merges the provided cookie configuration with default values\n */\nexport function getCookieConfig(\n cookieConfig?: CookieConfig,\n): ResolvedCookieConfig {\n const defaultOptions: CookieOptions = {\n path: '/',\n maxAge: DEFAULT_MAX_AGE,\n };\n\n // Helper function to merge options, filtering out undefined values\n const mergeOptions = (configOptions?: CookieOptions): CookieOptions => {\n const merged = { ...defaultOptions };\n\n if (configOptions) {\n Object.keys(configOptions).forEach((key) => {\n const value = configOptions[key as keyof CookieOptions];\n if (value !== undefined) {\n (merged as any)[key] = value;\n }\n });\n }\n\n return merged;\n };\n\n return {\n ctx: {\n name: cookieConfig?.ctx?.name ?? 'edgestore-ctx',\n options: mergeOptions(cookieConfig?.ctx?.options),\n },\n token: {\n name: cookieConfig?.token?.name ?? 'edgestore-token',\n options: mergeOptions(cookieConfig?.token?.options),\n },\n };\n}\n\nexport async function init<TCtx>(params: {\n provider: Provider;\n router: EdgeStoreRouter<TCtx>;\n ctx: TCtx;\n cookieConfig?: CookieConfig;\n}): Promise<SharedInitRes> {\n const log = globalThis._EDGE_STORE_LOGGER;\n const { ctx, provider, router, cookieConfig } = params;\n log.debug('Running [init]', { ctx });\n\n const resolvedCookieConfig = getCookieConfig(cookieConfig);\n\n const ctxToken = await encryptJWT(ctx);\n const { token } = await provider.init({\n ctx,\n router: router,\n });\n const newCookies = [\n serialize(\n resolvedCookieConfig.ctx.name,\n ctxToken,\n resolvedCookieConfig.ctx.options,\n ),\n ];\n if (token) {\n newCookies.push(\n serialize(\n resolvedCookieConfig.token.name,\n token,\n resolvedCookieConfig.token.options,\n ),\n );\n }\n const baseUrl = await provider.getBaseUrl();\n\n log.debug('Finished [init]', {\n ctx,\n newCookies,\n token,\n baseUrl,\n providerName: provider.name,\n });\n\n return {\n newCookies,\n token,\n baseUrl,\n providerName: provider.name,\n };\n}\n\nexport type RequestUploadBody = {\n bucketName: string;\n input: any;\n fileInfo: {\n size: number;\n type: string;\n extension: string;\n fileName?: string;\n replaceTargetUrl?: string;\n temporary: boolean;\n };\n};\n\nexport async function requestUpload<TCtx>(params: {\n provider: Provider;\n router: EdgeStoreRouter<TCtx>;\n ctxToken: string | undefined;\n body: RequestUploadBody;\n}): Promise<SharedRequestUploadRes> {\n const {\n provider,\n router,\n ctxToken,\n body: { bucketName, input, fileInfo },\n } = params;\n const log = globalThis._EDGE_STORE_LOGGER;\n log.debug('Running [requestUpload]', { bucketName, input, fileInfo });\n\n if (!ctxToken) {\n throw new EdgeStoreError({\n message: 'Missing edgestore-ctx cookie',\n code: 'UNAUTHORIZED',\n });\n }\n const ctx = await getContext(ctxToken);\n\n log.debug('Decrypted Context', { ctx });\n\n const bucket = router.buckets[bucketName];\n if (!bucket) {\n throw new EdgeStoreError({\n message: `Bucket ${bucketName} not found`,\n code: 'BAD_REQUEST',\n });\n }\n if (bucket._def.beforeUpload) {\n log.debug('Running [beforeUpload]');\n const canUpload = await bucket._def.beforeUpload?.({\n ctx,\n input,\n fileInfo: {\n size: fileInfo.size,\n type: fileInfo.type,\n fileName: fileInfo.fileName,\n extension: fileInfo.extension,\n replaceTargetUrl: fileInfo.replaceTargetUrl,\n temporary: fileInfo.temporary,\n },\n });\n log.debug('Finished [beforeUpload]', { canUpload });\n if (!canUpload) {\n throw new EdgeStoreError({\n message: 'Upload not allowed for the current context',\n code: 'UPLOAD_NOT_ALLOWED',\n });\n }\n }\n\n if (bucket._def.type === 'IMAGE') {\n if (!IMAGE_MIME_TYPES.includes(fileInfo.type)) {\n throw new EdgeStoreError({\n code: 'MIME_TYPE_NOT_ALLOWED',\n message: 'Only images are allowed in this bucket',\n details: {\n allowedMimeTypes: IMAGE_MIME_TYPES,\n mimeType: fileInfo.type,\n },\n });\n }\n }\n\n if (bucket._def.bucketConfig?.maxSize) {\n if (fileInfo.size > bucket._def.bucketConfig.maxSize) {\n throw new EdgeStoreError({\n code: 'FILE_TOO_LARGE',\n message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`,\n details: {\n maxFileSize: bucket._def.bucketConfig.maxSize,\n fileSize: fileInfo.size,\n },\n });\n }\n }\n\n if (bucket._def.bucketConfig?.accept) {\n const accept = bucket._def.bucketConfig.accept;\n let accepted = false;\n for (const acceptedMimeType of accept) {\n if (acceptedMimeType.endsWith('/*')) {\n const mimeType = acceptedMimeType.replace('/*', '');\n if (fileInfo.type.startsWith(mimeType)) {\n accepted = true;\n break;\n }\n } else if (fileInfo.type === acceptedMimeType) {\n accepted = true;\n break;\n }\n }\n if (!accepted) {\n throw new EdgeStoreError({\n code: 'MIME_TYPE_NOT_ALLOWED',\n message: `\"${\n fileInfo.type\n }\" is not allowed. Accepted types are ${JSON.stringify(accept)}`,\n details: {\n allowedMimeTypes: accept,\n mimeType: fileInfo.type,\n },\n });\n }\n }\n\n const path = buildPath({\n fileInfo,\n bucket,\n pathAttrs: { ctx, input },\n });\n const metadata = await bucket._def.metadata?.({ ctx, input });\n const isPublic = bucket._def.accessControl === undefined;\n\n log.debug('upload info', {\n path,\n metadata,\n isPublic,\n bucketType: bucket._def.type,\n });\n\n const requestUploadRes = await provider.requestUpload({\n bucketName,\n bucketType: bucket._def.type,\n fileInfo: {\n ...fileInfo,\n path,\n isPublic,\n metadata,\n },\n });\n const { parsedPath, pathOrder } = parsePath(path);\n\n log.debug('Finished [requestUpload]');\n\n return {\n ...requestUploadRes,\n size: fileInfo.size,\n uploadedAt: new Date().toISOString(), // TODO: maybe delete this field since it's not the actual upload time\n path: parsedPath,\n pathOrder,\n metadata,\n };\n}\n\nexport type RequestUploadPartsParams = {\n multipart: {\n uploadId: string;\n parts: number[];\n };\n path: string;\n};\n\nexport async function requestUploadParts<TCtx>(params: {\n provider: Provider;\n router: EdgeStoreRouter<TCtx>;\n ctxToken: string | undefined;\n body: RequestUploadPartsParams;\n}): Promise<SharedRequestUploadPartsRes> {\n const {\n provider,\n ctxToken,\n body: { multipart, path },\n } = params;\n\n const log = globalThis._EDGE_STORE_LOGGER;\n log.debug('Running [requestUploadParts]', { multipart, path });\n\n if (!ctxToken) {\n throw new EdgeStoreError({\n message: 'Missing edgestore-ctx cookie',\n code: 'UNAUTHORIZED',\n });\n }\n await getContext(ctxToken); // just to check if the token is valid\n\n const res = await provider.requestUploadParts({\n multipart,\n path,\n });\n\n log.debug('Finished [requestUploadParts]');\n\n return res;\n}\n\nexport type CompleteMultipartUploadBody = {\n bucketName: string;\n uploadId: string;\n key: string;\n parts: {\n partNumber: number;\n eTag: string;\n }[];\n};\n\nexport async function completeMultipartUpload<TCtx>(params: {\n provider: Provider;\n router: EdgeStoreRouter<TCtx>;\n ctxToken: string | undefined;\n body: CompleteMultipartUploadBody;\n}) {\n const {\n provider,\n router,\n ctxToken,\n body: { bucketName, uploadId, key, parts },\n } = params;\n\n const log = globalThis._EDGE_STORE_LOGGER;\n log.debug('Running [completeMultipartUpload]', {\n bucketName,\n uploadId,\n key,\n });\n\n if (!ctxToken) {\n throw new EdgeStoreError({\n message: 'Missing edgestore-ctx cookie',\n code: 'UNAUTHORIZED',\n });\n }\n await getContext(ctxToken); // just to check if the token is valid\n const bucket = router.buckets[bucketName];\n if (!bucket) {\n throw new EdgeStoreError({\n message: `Bucket ${bucketName} not found`,\n code: 'BAD_REQUEST',\n });\n }\n\n const res = await provider.completeMultipartUpload({\n uploadId,\n key,\n parts,\n });\n\n log.debug('Finished [completeMultipartUpload]');\n\n return res;\n}\n\nexport type ConfirmUploadBody = {\n bucketName: string;\n url: string;\n};\n\nexport async function confirmUpload<TCtx>(params: {\n provider: Provider;\n router: EdgeStoreRouter<TCtx>;\n ctxToken: string | undefined;\n body: ConfirmUploadBody;\n}) {\n const {\n provider,\n router,\n ctxToken,\n body: { bucketName, url },\n } = params;\n\n const log = globalThis._EDGE_STORE_LOGGER;\n log.debug('Running [confirmUpload]', { bucketName, url });\n\n if (!ctxToken) {\n throw new EdgeStoreError({\n message: 'Missing edgestore-ctx cookie',\n code: 'UNAUTHORIZED',\n });\n }\n await getContext(ctxToken); // just to check if the token is valid\n const bucket = router.buckets[bucketName];\n if (!bucket) {\n throw new EdgeStoreError({\n message: `Bucket ${bucketName} not found`,\n code: 'BAD_REQUEST',\n });\n }\n\n const res = await provider.confirmUpload({\n bucket,\n url: unproxyUrl(url),\n });\n\n log.debug('Finished [confirmUpload]');\n return res;\n}\n\nexport type DeleteFileBody = {\n bucketName: string;\n url: string;\n};\n\nexport async function deleteFile<TCtx>(params: {\n provider: Provider;\n router: EdgeStoreRouter<TCtx>;\n ctxToken: string | undefined;\n body: DeleteFileBody;\n}): Promise<SharedDeleteFileRes> {\n const {\n provider,\n router,\n ctxToken,\n body: { bucketName, url },\n } = params;\n\n const log = globalThis._EDGE_STORE_LOGGER;\n log.debug('Running [deleteFile]', { bucketName, url });\n\n if (!ctxToken) {\n throw new EdgeStoreError({\n message: 'Missing edgestore-ctx cookie',\n code: 'UNAUTHORIZED',\n });\n }\n const ctx = await getContext(ctxToken);\n const bucket = router.buckets[bucketName];\n if (!bucket) {\n throw new EdgeStoreError({\n message: `Bucket ${bucketName} not found`,\n code: 'BAD_REQUEST',\n });\n }\n\n if (!bucket._def.beforeDelete) {\n throw new EdgeStoreError({\n message:\n 'You need to define beforeDelete if you want to delete files directly from the frontend.',\n code: 'SERVER_ERROR',\n });\n }\n\n const fileInfo = await provider.getFile({\n url: unproxyUrl(url),\n });\n\n const canDelete = await bucket._def.beforeDelete({\n ctx,\n fileInfo,\n });\n if (!canDelete) {\n throw new EdgeStoreError({\n message: 'Delete not allowed for the current context',\n code: 'DELETE_NOT_ALLOWED',\n });\n }\n const res = await provider.deleteFile({\n bucket,\n url: unproxyUrl(url),\n });\n\n log.debug('Finished [deleteFile]');\n\n return res;\n}\n\nasync function encryptJWT(ctx: any) {\n const secret =\n getEnv('EDGE_STORE_JWT_SECRET') ?? getEnv('EDGE_STORE_SECRET_KEY');\n if (!secret) {\n throw new EdgeStoreError({\n message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',\n code: 'SERVER_ERROR',\n });\n }\n const encryptionSecret = await getDerivedEncryptionKey(secret);\n return await new EncryptJWT(ctx)\n .setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })\n .setIssuedAt()\n .setExpirationTime(Date.now() / 1000 + DEFAULT_MAX_AGE)\n .setJti(uuidv4())\n .encrypt(encryptionSecret);\n}\n\nasync function decryptJWT(token: string) {\n const secret =\n getEnv('EDGE_STORE_JWT_SECRET') ?? getEnv('EDGE_STORE_SECRET_KEY');\n if (!secret) {\n throw new EdgeStoreError({\n message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',\n code: 'SERVER_ERROR',\n });\n }\n const encryptionSecret = await getDerivedEncryptionKey(secret);\n const { payload } = await jwtDecrypt(token, encryptionSecret, {\n clockTolerance: 15,\n });\n return payload;\n}\n\nasync function getDerivedEncryptionKey(secret: string) {\n return await hkdf(\n 'sha256',\n secret,\n '',\n 'EdgeStore Generated Encryption Key',\n 32,\n );\n}\n\nexport function buildPath(params: {\n fileInfo: RequestUploadBody['fileInfo'];\n bucket: AnyBuilder;\n pathAttrs: {\n ctx: any;\n input: any;\n };\n}) {\n const { bucket } = params;\n const pathParams = bucket._def.path;\n const path = pathParams.map((param) => {\n const paramEntries = Object.entries(param);\n if (paramEntries[0] === undefined) {\n throw new EdgeStoreError({\n message: `Empty path param found in: ${JSON.stringify(pathParams)}`,\n code: 'SERVER_ERROR',\n });\n }\n const [key, value] = paramEntries[0];\n // this is a string like: \"ctx.xxx\" or \"input.yyy.zzz\"\n const currParamVal = value()\n .split('.')\n .reduce((acc2: any, key: string) => {\n if (acc2[key] === undefined) {\n throw new EdgeStoreError({\n message: `Missing key ${key} in ${JSON.stringify(acc2)}`,\n code: 'BAD_REQUEST',\n });\n }\n return acc2[key];\n }, params.pathAttrs as any) as string;\n return {\n key,\n value: currParamVal,\n };\n });\n return path;\n}\n\nexport function parsePath(path: { key: string; value: string }[]) {\n const parsedPath = path.reduce<Record<string, string>>((acc, curr) => {\n acc[curr.key] = curr.value;\n return acc;\n }, {});\n const pathOrder = path.map((p) => p.key);\n return {\n parsedPath,\n pathOrder,\n };\n}\n\nasync function getContext(token: string) {\n return await decryptJWT(token);\n}\n\n/**\n * On local development, protected files are proxied to the server,\n * which changes the original URL.\n *\n * This function is used to get the original URL,\n * so that we can delete or confirm the upload.\n */\nfunction unproxyUrl(url: string) {\n if (isDev() && url.startsWith('http://')) {\n // get the url param from the query string\n const urlParam = new URL(url).searchParams.get('url');\n if (urlParam) {\n return urlParam;\n }\n }\n return url;\n}\n\nexport function getEnv(key: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n // @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.\n return process.env[key] ?? import.meta.env?.[key];\n }\n // @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.\n return import.meta.env?.[key];\n}\n\nexport function isDev(): boolean {\n return (\n process?.env?.NODE_ENV === 'development' ||\n // @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.\n import.meta.env?.DEV\n );\n}\n"],"mappings":";;;;;;;AAAA,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACSD,MAAM,kBAAk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EAAS,yDAAK,cAAa,uCAE3B,OAAO,KAAK,2EAAK"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AnyBuilder, EdgeStoreRouter, Provider } from "@edgestore/shared";
|
|
2
|
+
|
|
3
|
+
//#region src/libs/logger.d.ts
|
|
4
|
+
declare const logLevel: readonly ["debug", "info", "warn", "error", "none"];
|
|
5
|
+
type LogLevel = (typeof logLevel)[number];
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/adapters/shared.d.ts
|
|
8
|
+
type CookieOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Cookie path
|
|
11
|
+
* @default "/"
|
|
12
|
+
*/
|
|
13
|
+
path?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Cookie max age in seconds
|
|
16
|
+
* @default 2592000 (30 days)
|
|
17
|
+
*/
|
|
18
|
+
maxAge?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Cookie domain
|
|
21
|
+
*/
|
|
22
|
+
domain?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Cookie same site policy
|
|
25
|
+
*/
|
|
26
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
27
|
+
/**
|
|
28
|
+
* Cookie secure flag
|
|
29
|
+
*/
|
|
30
|
+
secure?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Cookie http only flag
|
|
33
|
+
*/
|
|
34
|
+
httpOnly?: boolean;
|
|
35
|
+
};
|
|
36
|
+
type CookieConfig = {
|
|
37
|
+
/**
|
|
38
|
+
* Context cookie configuration
|
|
39
|
+
*/
|
|
40
|
+
ctx?: {
|
|
41
|
+
/**
|
|
42
|
+
* Name of the context cookie
|
|
43
|
+
* @default "edgestore-ctx"
|
|
44
|
+
*/
|
|
45
|
+
name?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Cookie options for context cookie
|
|
48
|
+
*/
|
|
49
|
+
options?: CookieOptions;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Token cookie configuration
|
|
53
|
+
*/
|
|
54
|
+
token?: {
|
|
55
|
+
/**
|
|
56
|
+
* Name of the token cookie
|
|
57
|
+
* @default "edgestore-token"
|
|
58
|
+
*/
|
|
59
|
+
name?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Cookie options for token cookie
|
|
62
|
+
*/
|
|
63
|
+
options?: CookieOptions;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { LogLevel as n, CookieConfig as t };
|
|
68
|
+
//# sourceMappingURL=shared-DsWTtQ1-.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-DsWTtQ1-.d.mts","names":[],"sources":["../src/libs/logger.ts","../src/adapters/shared.ts"],"sourcesContent":[],"mappings":";;;cAIM;KAEM,QAAA,WAAmB;;;KCkBnB,aAAA;;;ADlBZ;;;;ACkBA;AA6BA;;;;;;;;;;;;;;;;;;;;KAAY,YAAA;;;;;;;;;;;;;cAaE;;;;;;;;;;;;;;cAcA"}
|