miqro 7.1.0 → 7.2.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/README.md +92 -24
- package/build/editor.bundle.js +3 -3
- package/build/esm/editor/auth.js +3 -1
- package/build/esm/editor/auth.js.map +1 -0
- package/build/esm/editor/common/admin-interface.js +1 -0
- package/build/esm/editor/common/admin-interface.js.map +1 -0
- package/build/esm/editor/common/constants.js +1 -0
- package/build/esm/editor/common/constants.js.map +1 -0
- package/build/esm/editor/common/constants.server.js +1 -0
- package/build/esm/editor/common/constants.server.js.map +1 -0
- package/build/esm/editor/common/editor-index.js +1 -0
- package/build/esm/editor/common/editor-index.js.map +1 -0
- package/build/esm/editor/common/html-encode.js +1 -0
- package/build/esm/editor/common/html-encode.js.map +1 -0
- package/build/esm/editor/common/log-socket.js +1 -0
- package/build/esm/editor/common/log-socket.js.map +1 -0
- package/build/esm/editor/common/templates.js +1 -0
- package/build/esm/editor/common/templates.js.map +1 -0
- package/build/esm/editor/components/api-preview.js +1 -0
- package/build/esm/editor/components/api-preview.js.map +1 -0
- package/build/esm/editor/components/editor.js +1 -0
- package/build/esm/editor/components/editor.js.map +1 -0
- package/build/esm/editor/components/file-browser.js +1 -0
- package/build/esm/editor/components/file-browser.js.map +1 -0
- package/build/esm/editor/components/file-editor-toolbar.js +1 -0
- package/build/esm/editor/components/file-editor-toolbar.js.map +1 -0
- package/build/esm/editor/components/file-editor.js +1 -0
- package/build/esm/editor/components/file-editor.js.map +1 -0
- package/build/esm/editor/components/filter-query.js +1 -0
- package/build/esm/editor/components/filter-query.js.map +1 -0
- package/build/esm/editor/components/highlight-text-area.js +1 -0
- package/build/esm/editor/components/highlight-text-area.js.map +1 -0
- package/build/esm/editor/components/log-viewer.js +1 -0
- package/build/esm/editor/components/log-viewer.js.map +1 -0
- package/build/esm/editor/components/new-file.js +1 -0
- package/build/esm/editor/components/new-file.js.map +1 -0
- package/build/esm/editor/components/scroll-query.js +1 -0
- package/build/esm/editor/components/scroll-query.js.map +1 -0
- package/build/esm/editor/components/start-page.js +1 -0
- package/build/esm/editor/components/start-page.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +3 -2
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +1 -0
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +1 -0
- package/build/esm/editor/http/admin/editor/editor.js +1 -0
- package/build/esm/editor/http/admin/editor/editor.js.map +1 -0
- package/build/esm/editor/http/admin/editor/index.api.js +1 -0
- package/build/esm/editor/http/admin/editor/index.api.js.map +1 -0
- package/build/esm/editor/server.js +1 -0
- package/build/esm/editor/server.js.map +1 -0
- package/build/esm/editor/ws.js +2 -1
- package/build/esm/editor/ws.js.map +1 -0
- package/build/esm/src/bin/compile.js +1 -0
- package/build/esm/src/bin/compile.js.map +1 -0
- package/build/esm/src/bin/doc-md.js +1 -0
- package/build/esm/src/bin/doc-md.js.map +1 -0
- package/build/esm/src/bin/generate-doc.js +1 -0
- package/build/esm/src/bin/generate-doc.js.map +1 -0
- package/build/esm/src/bin/test.d.ts +2 -1
- package/build/esm/src/bin/test.js +3 -2
- package/build/esm/src/bin/test.js.map +1 -0
- package/build/esm/src/bin/types.js +1 -0
- package/build/esm/src/bin/types.js.map +1 -0
- package/build/esm/src/cluster.js +1 -0
- package/build/esm/src/cluster.js.map +1 -0
- package/build/esm/src/common/arguments.d.ts +8 -0
- package/build/esm/src/common/arguments.js +78 -1
- package/build/esm/src/common/arguments.js.map +1 -0
- package/build/esm/src/common/assets.d.ts +1 -1
- package/build/esm/src/common/assets.js +2 -1
- package/build/esm/src/common/assets.js.map +1 -0
- package/build/esm/src/common/checksum.js +1 -0
- package/build/esm/src/common/checksum.js.map +1 -0
- package/build/esm/src/common/constants.d.ts +1 -0
- package/build/esm/src/common/constants.js +2 -0
- package/build/esm/src/common/constants.js.map +1 -0
- package/build/esm/src/common/content-type.js +1 -0
- package/build/esm/src/common/content-type.js.map +1 -0
- package/build/esm/src/common/esbuild.js +2 -1
- package/build/esm/src/common/esbuild.js.map +1 -0
- package/build/esm/src/common/exit.js +1 -0
- package/build/esm/src/common/exit.js.map +1 -0
- package/build/esm/src/common/fs.js +1 -0
- package/build/esm/src/common/fs.js.map +1 -0
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +7 -1
- package/build/esm/src/common/help.js.map +1 -0
- package/build/esm/src/common/jsx.d.ts +20 -16
- package/build/esm/src/common/jsx.js +34 -29
- package/build/esm/src/common/jsx.js.map +1 -0
- package/build/esm/src/common/jwt.js +1 -0
- package/build/esm/src/common/jwt.js.map +1 -0
- package/build/esm/src/common/paths.js +1 -0
- package/build/esm/src/common/paths.js.map +1 -0
- package/build/esm/src/common/watch.js +1 -0
- package/build/esm/src/common/watch.js.map +1 -0
- package/build/esm/src/inflate/inflate-sea.js +1 -0
- package/build/esm/src/inflate/inflate-sea.js.map +1 -0
- package/build/esm/src/inflate/inflate.d.ts +5 -1
- package/build/esm/src/inflate/inflate.js +6 -5
- package/build/esm/src/inflate/inflate.js.map +1 -0
- package/build/esm/src/inflate/md.js +1 -0
- package/build/esm/src/inflate/md.js.map +1 -0
- package/build/esm/src/inflate/setup-auth.d.ts +2 -2
- package/build/esm/src/inflate/setup-auth.js +3 -2
- package/build/esm/src/inflate/setup-auth.js.map +1 -0
- package/build/esm/src/inflate/setup-cors.d.ts +2 -2
- package/build/esm/src/inflate/setup-cors.js +3 -2
- package/build/esm/src/inflate/setup-cors.js.map +1 -0
- package/build/esm/src/inflate/setup-db.d.ts +3 -3
- package/build/esm/src/inflate/setup-db.js +6 -5
- package/build/esm/src/inflate/setup-db.js.map +1 -0
- package/build/esm/src/inflate/setup-error.d.ts +2 -2
- package/build/esm/src/inflate/setup-error.js +3 -2
- package/build/esm/src/inflate/setup-error.js.map +1 -0
- package/build/esm/src/inflate/setup-http.d.ts +7 -2
- package/build/esm/src/inflate/setup-http.js +54 -45
- package/build/esm/src/inflate/setup-http.js.map +1 -0
- package/build/esm/src/inflate/setup-log.d.ts +2 -2
- package/build/esm/src/inflate/setup-log.js +3 -2
- package/build/esm/src/inflate/setup-log.js.map +1 -0
- package/build/esm/src/inflate/setup-middleware.d.ts +2 -2
- package/build/esm/src/inflate/setup-middleware.js +3 -2
- package/build/esm/src/inflate/setup-middleware.js.map +1 -0
- package/build/esm/src/inflate/setup-server-config.d.ts +2 -2
- package/build/esm/src/inflate/setup-server-config.js +3 -2
- package/build/esm/src/inflate/setup-server-config.js.map +1 -0
- package/build/esm/src/inflate/setup-test.d.ts +2 -1
- package/build/esm/src/inflate/setup-test.js +3 -2
- package/build/esm/src/inflate/setup-test.js.map +1 -0
- package/build/esm/src/inflate/setup-ws.d.ts +2 -2
- package/build/esm/src/inflate/setup-ws.js +3 -2
- package/build/esm/src/inflate/setup-ws.js.map +1 -0
- package/build/esm/src/inflate/setup.doc.d.ts +2 -2
- package/build/esm/src/inflate/setup.doc.js +5 -4
- package/build/esm/src/inflate/setup.doc.js.map +1 -0
- package/build/esm/src/inflate/utils/sea-utils.js +1 -0
- package/build/esm/src/inflate/utils/sea-utils.js.map +1 -0
- package/build/esm/src/lib.js +1 -0
- package/build/esm/src/lib.js.map +1 -0
- package/build/esm/src/main.js +9 -2
- package/build/esm/src/main.js.map +1 -0
- package/build/esm/src/services/app.d.ts +5 -2
- package/build/esm/src/services/app.js +22 -9
- package/build/esm/src/services/app.js.map +1 -0
- package/build/esm/src/services/editor.js +1 -0
- package/build/esm/src/services/editor.js.map +1 -0
- package/build/esm/src/services/hot-reload.d.ts +1 -0
- package/build/esm/src/services/hot-reload.js +9 -5
- package/build/esm/src/services/hot-reload.js.map +1 -0
- package/build/esm/src/services/migrations.d.ts +3 -2
- package/build/esm/src/services/migrations.js +5 -4
- package/build/esm/src/services/migrations.js.map +1 -0
- package/build/esm/src/services/utils/admin-interface.js +1 -0
- package/build/esm/src/services/utils/admin-interface.js.map +1 -0
- package/build/esm/src/services/utils/cache.js +1 -0
- package/build/esm/src/services/utils/cache.js.map +1 -0
- package/build/esm/src/services/utils/cluster-cache.js +91 -64
- package/build/esm/src/services/utils/cluster-cache.js.map +1 -0
- package/build/esm/src/services/utils/cluster-ws.js +1 -0
- package/build/esm/src/services/utils/cluster-ws.js.map +1 -0
- package/build/esm/src/services/utils/db-manager.js +1 -0
- package/build/esm/src/services/utils/db-manager.js.map +1 -0
- package/build/esm/src/services/utils/get-route.js +1 -0
- package/build/esm/src/services/utils/get-route.js.map +1 -0
- package/build/esm/src/services/utils/jwt.js +1 -0
- package/build/esm/src/services/utils/jwt.js.map +1 -0
- package/build/esm/src/services/utils/log-transport.js +1 -0
- package/build/esm/src/services/utils/log-transport.js.map +1 -0
- package/build/esm/src/services/utils/log.js +1 -0
- package/build/esm/src/services/utils/log.js.map +1 -0
- package/build/esm/src/services/utils/middleware.js +1 -0
- package/build/esm/src/services/utils/middleware.js.map +1 -0
- package/build/esm/src/services/utils/server-interface.js +1 -0
- package/build/esm/src/services/utils/server-interface.js.map +1 -0
- package/build/esm/src/services/utils/websocketmanager.js +3 -1
- package/build/esm/src/services/utils/websocketmanager.js.map +1 -0
- package/build/esm/src/types.js +1 -0
- package/build/esm/src/types.js.map +1 -0
- package/build/lib.cjs +1178 -1153
- package/editor/auth.ts +2 -1
- package/editor/http/admin/editor/api/fs/read.api.tsx +2 -2
- package/editor/ws.ts +1 -1
- package/package.json +10 -10
- package/sea/install-esbuild.sh +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/src/bin/test.ts +3 -2
- package/src/common/arguments.ts +92 -1
- package/src/common/assets.ts +2 -2
- package/src/common/constants.ts +1 -0
- package/src/common/esbuild.ts +1 -1
- package/src/common/help.ts +6 -1
- package/src/common/jsx.ts +41 -30
- package/src/inflate/inflate.ts +9 -5
- package/src/inflate/setup-auth.ts +3 -3
- package/src/inflate/setup-cors.ts +4 -3
- package/src/inflate/setup-db.ts +6 -6
- package/src/inflate/setup-error.ts +3 -3
- package/src/inflate/setup-http.ts +61 -45
- package/src/inflate/setup-log.ts +3 -3
- package/src/inflate/setup-middleware.ts +3 -3
- package/src/inflate/setup-server-config.ts +3 -3
- package/src/inflate/setup-test.ts +3 -3
- package/src/inflate/setup-ws.ts +3 -3
- package/src/inflate/setup.doc.ts +5 -5
- package/src/main.ts +8 -2
- package/src/services/app.ts +27 -12
- package/src/services/hot-reload.ts +9 -5
- package/src/services/migrations.ts +5 -5
- package/src/services/utils/cluster-cache.ts +90 -65
- package/src/services/utils/websocketmanager.ts +2 -1
package/build/lib.cjs
CHANGED
|
@@ -230,8 +230,8 @@ function parseBoolean(value) {
|
|
|
230
230
|
return value === "true" || value === true ? true : value === "false" || value === false ? false : void 0;
|
|
231
231
|
}
|
|
232
232
|
function parseDict(value, args, parser4) {
|
|
233
|
-
const
|
|
234
|
-
if (!
|
|
233
|
+
const isObject2 = typeof value === "object";
|
|
234
|
+
if (!isObject2 || !value) {
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
237
237
|
if (args.dictType !== void 0) {
|
|
@@ -253,7 +253,7 @@ function parseEmail(value, args) {
|
|
|
253
253
|
if (!emailRegex.test(String(str).toLowerCase())) {
|
|
254
254
|
return;
|
|
255
255
|
}
|
|
256
|
-
return
|
|
256
|
+
return str;
|
|
257
257
|
}
|
|
258
258
|
function parseEnum(value, args, parser4) {
|
|
259
259
|
const enumValues = parseArray(args.enumValues, {
|
|
@@ -281,8 +281,8 @@ function decodeHTML(str) {
|
|
|
281
281
|
}
|
|
282
282
|
function encodeHTML(str) {
|
|
283
283
|
const buf = [];
|
|
284
|
-
for (let i =
|
|
285
|
-
buf.
|
|
284
|
+
for (let i = 0; i < str.length; i++) {
|
|
285
|
+
buf.push("&#" + str[i].charCodeAt(0) + ";");
|
|
286
286
|
}
|
|
287
287
|
return buf.join("");
|
|
288
288
|
}
|
|
@@ -312,7 +312,7 @@ function parseInteger(value, args, parser4) {
|
|
|
312
312
|
}
|
|
313
313
|
function parseNumber(value, args) {
|
|
314
314
|
const sValue = String(value);
|
|
315
|
-
if (!(value === null || value === void 0 ? false : !isNaN(parseInt(sValue, 10)))) {
|
|
315
|
+
if (!(value === null || value === void 0 ? false : !isNaN(Number(sValue)) && !isNaN(parseInt(sValue, 10)))) {
|
|
316
316
|
return;
|
|
317
317
|
}
|
|
318
318
|
const parsedValue = parseFloat(sValue);
|
|
@@ -335,8 +335,8 @@ function parseNumber(value, args) {
|
|
|
335
335
|
return parsedValue;
|
|
336
336
|
}
|
|
337
337
|
function parseObject(value, args, parser4) {
|
|
338
|
-
const
|
|
339
|
-
if (!
|
|
338
|
+
const isObject2 = typeof value === "object" ? value : void 0;
|
|
339
|
+
if (!isObject2 || !value) {
|
|
340
340
|
return;
|
|
341
341
|
}
|
|
342
342
|
if (args.properties !== void 0) {
|
|
@@ -372,7 +372,7 @@ function parseObject(value, args, parser4) {
|
|
|
372
372
|
throw new Error(`unsupported mode [${mode}]`);
|
|
373
373
|
}
|
|
374
374
|
} else {
|
|
375
|
-
return
|
|
375
|
+
return isObject2;
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
function parseRegex(value, args) {
|
|
@@ -443,7 +443,7 @@ function parseURL(value, args) {
|
|
|
443
443
|
if (args.stringMaxLength !== void 0 && parsedValue.length > args.stringMaxLength) {
|
|
444
444
|
return;
|
|
445
445
|
}
|
|
446
|
-
const str = parseString(
|
|
446
|
+
const str = parseString(parsedValue, args);
|
|
447
447
|
if (str === void 0) {
|
|
448
448
|
return void 0;
|
|
449
449
|
} else {
|
|
@@ -605,7 +605,7 @@ var init_lib = __esm({
|
|
|
605
605
|
throw new Error("parser must be a function or Schema or a string");
|
|
606
606
|
}
|
|
607
607
|
if (typeof noList !== "boolean") {
|
|
608
|
-
throw new Error("noList must be a
|
|
608
|
+
throw new Error("noList must be a boolean");
|
|
609
609
|
}
|
|
610
610
|
for (const reserved of RESERVED) {
|
|
611
611
|
if (type.indexOf(reserved) !== -1) {
|
|
@@ -714,7 +714,7 @@ function ReadBuffer(options) {
|
|
|
714
714
|
req.removeListener("error", errorListener);
|
|
715
715
|
req.removeListener("data", chunkListener);
|
|
716
716
|
req.removeListener("end", endListener);
|
|
717
|
-
|
|
717
|
+
reject(new BadRequestError(`Read Timeout`));
|
|
718
718
|
return;
|
|
719
719
|
}, timeout);
|
|
720
720
|
let cLength = 0;
|
|
@@ -860,12 +860,12 @@ function JSONParser(options) {
|
|
|
860
860
|
}
|
|
861
861
|
function TextParser(options) {
|
|
862
862
|
let limit = DEFAULT_READ_BUFFER_LIMIT;
|
|
863
|
-
let type = "plain
|
|
863
|
+
let type = "text/plain";
|
|
864
864
|
if (options) {
|
|
865
865
|
limit = options.limit !== void 0 ? options.limit : limit;
|
|
866
866
|
type = options.type !== void 0 ? options.type : type;
|
|
867
867
|
} else {
|
|
868
|
-
const [limitS, typeS] = checkEnvVariables(["BODY_TEXT_PARSER_LIMIT", "BODY_TEXT_PARSER_TYPE"], [String(DEFAULT_READ_BUFFER_LIMIT), "plain
|
|
868
|
+
const [limitS, typeS] = checkEnvVariables(["BODY_TEXT_PARSER_LIMIT", "BODY_TEXT_PARSER_TYPE"], [String(DEFAULT_READ_BUFFER_LIMIT), "text/plain"]);
|
|
869
869
|
limit = parseInt(limitS, 10);
|
|
870
870
|
type = typeS;
|
|
871
871
|
}
|
|
@@ -992,7 +992,7 @@ function ResultParser(options, parser4) {
|
|
|
992
992
|
const mappedLastResult = {
|
|
993
993
|
...lastResult
|
|
994
994
|
};
|
|
995
|
-
const parsedStatus = (parser4 ? parser4 : DEFAULT_PARSER).parse(lastResult.status, "number?", `ctx.results.status
|
|
995
|
+
const parsedStatus = (parser4 ? parser4 : DEFAULT_PARSER).parse(lastResult.status, "number?", `ctx.results.status`);
|
|
996
996
|
if (statusParserSet) {
|
|
997
997
|
if (parsedStatus === void 0) {
|
|
998
998
|
throw new Error(`error parsing lastResult.status[${lastResult.status}] not defined as [${statusParserSet}]`);
|
|
@@ -1201,8 +1201,6 @@ function SessionHandler(config) {
|
|
|
1201
1201
|
throw new Error("authService must be provided!");
|
|
1202
1202
|
}
|
|
1203
1203
|
if (!config.options || !config.options.setCookieOptions) {
|
|
1204
|
-
console.dir(config);
|
|
1205
|
-
process.exit(1);
|
|
1206
1204
|
throw new Error("config.options not populated!");
|
|
1207
1205
|
}
|
|
1208
1206
|
const tokenLocation = config.options.tokenLocation;
|
|
@@ -1734,7 +1732,7 @@ var init_types = __esm({
|
|
|
1734
1732
|
return this.asyncEnd({
|
|
1735
1733
|
status: status !== void 0 ? status : 200,
|
|
1736
1734
|
headers: {
|
|
1737
|
-
["Content-Type"]: "plain
|
|
1735
|
+
["Content-Type"]: "text/plain; charset=utf-8",
|
|
1738
1736
|
...headers
|
|
1739
1737
|
},
|
|
1740
1738
|
body: text
|
|
@@ -1750,9 +1748,9 @@ var init_types = __esm({
|
|
|
1750
1748
|
const newValue = current ? `${current}, ${nV}` : nV;
|
|
1751
1749
|
return this.setHeader("Vary", newValue.indexOf("*") !== -1 ? "*" : newValue);
|
|
1752
1750
|
}
|
|
1753
|
-
async asyncClose() {
|
|
1751
|
+
async asyncClose(status = 400) {
|
|
1754
1752
|
return this.asyncEnd({
|
|
1755
|
-
status
|
|
1753
|
+
status,
|
|
1756
1754
|
headers: {
|
|
1757
1755
|
connection: "close"
|
|
1758
1756
|
}
|
|
@@ -2009,7 +2007,7 @@ function defaultAppErrorHandler() {
|
|
|
2009
2007
|
}
|
|
2010
2008
|
};
|
|
2011
2009
|
}
|
|
2012
|
-
var import_node_util, import_node_fs, import_node_path, Logger, FILE_TRANSPORT_ENV_VARIABLE, FileTransportCacheMap, FILE_TRANSPORT_TIMEOUT,
|
|
2010
|
+
var import_node_util, import_node_fs, import_node_path, Logger, FILE_TRANSPORT_ENV_VARIABLE, FileTransportCacheMap, FILE_TRANSPORT_TIMEOUT, FILE_TRANSPORT_THRESHOLD, FileTransport, DEFAULT_LOGGER_TRANSPORTS, DEFAULT_LOGGER_FORMATTER, LOG_LEVEL_MAP, LoggerEvents, loggerContainer, DEFAULT_ENV_NAME, customLoggerFactory, BadRequestError, ForbiddenError, UnAuthorizedError, HTML_HEADERS, STATUS, checkEnvVariables, checkEnvVariable, getEnvVariable;
|
|
2013
2011
|
var init_common = __esm({
|
|
2014
2012
|
"node_modules/@miqro/core/build/common.js"() {
|
|
2015
2013
|
import_node_util = require("node:util");
|
|
@@ -2033,7 +2031,7 @@ var init_common = __esm({
|
|
|
2033
2031
|
};
|
|
2034
2032
|
}
|
|
2035
2033
|
setLevel(level) {
|
|
2036
|
-
if (
|
|
2034
|
+
if (LOG_LEVEL_MAP[level] === void 0) {
|
|
2037
2035
|
throw new Error(`Unknown level [${level}]`);
|
|
2038
2036
|
}
|
|
2039
2037
|
this.level = level;
|
|
@@ -2110,7 +2108,7 @@ var init_common = __esm({
|
|
|
2110
2108
|
FILE_TRANSPORT_ENV_VARIABLE = "LOG_FILE";
|
|
2111
2109
|
FileTransportCacheMap = {};
|
|
2112
2110
|
FILE_TRANSPORT_TIMEOUT = 150;
|
|
2113
|
-
|
|
2111
|
+
FILE_TRANSPORT_THRESHOLD = 2 * 1024 * 1024;
|
|
2114
2112
|
FileTransport = (filePath = process.env[FILE_TRANSPORT_ENV_VARIABLE] ? process.env[FILE_TRANSPORT_ENV_VARIABLE] : null, level) => {
|
|
2115
2113
|
if (filePath && !FileTransportCacheMap[filePath]) {
|
|
2116
2114
|
FileTransportCacheMap[filePath] = {
|
|
@@ -2134,7 +2132,7 @@ var init_common = __esm({
|
|
|
2134
2132
|
FileTransportCacheMap[filePath].fileHandler = null;
|
|
2135
2133
|
});
|
|
2136
2134
|
}
|
|
2137
|
-
FileTransportCacheMap[filePath].lastWrite = now;
|
|
2135
|
+
FileTransportCacheMap[filePath].lastWrite = Date.now();
|
|
2138
2136
|
const oldBuffer = FileTransportCacheMap[filePath].flushBuffer;
|
|
2139
2137
|
FileTransportCacheMap[filePath].flushBuffer = "";
|
|
2140
2138
|
fileHandler.write(oldBuffer, (err) => {
|
|
@@ -2152,7 +2150,7 @@ var init_common = __esm({
|
|
|
2152
2150
|
FileTransportCacheMap[filePath].currentTimeout = null;
|
|
2153
2151
|
if (filePath) {
|
|
2154
2152
|
const now2 = Date.now();
|
|
2155
|
-
if (FileTransportCacheMap[filePath].flushBuffer && (now2 - FileTransportCacheMap[filePath].lastWrite > FILE_TRANSPORT_TIMEOUT || FileTransportCacheMap[filePath].flushBuffer.length >
|
|
2153
|
+
if (FileTransportCacheMap[filePath].flushBuffer && (now2 - FileTransportCacheMap[filePath].lastWrite > FILE_TRANSPORT_TIMEOUT || FileTransportCacheMap[filePath].flushBuffer.length > FILE_TRANSPORT_THRESHOLD)) {
|
|
2156
2154
|
flush(false);
|
|
2157
2155
|
}
|
|
2158
2156
|
}
|
|
@@ -2162,10 +2160,9 @@ var init_common = __esm({
|
|
|
2162
2160
|
};
|
|
2163
2161
|
};
|
|
2164
2162
|
const now = Date.now();
|
|
2165
|
-
FileTransportCacheMap[filePath].lastWrite = Date.now();
|
|
2166
2163
|
FileTransportCacheMap[filePath].flushBuffer += `${out}
|
|
2167
2164
|
`;
|
|
2168
|
-
if (now - FileTransportCacheMap[filePath].lastWrite > FILE_TRANSPORT_TIMEOUT || FileTransportCacheMap[filePath].flushBuffer.length >
|
|
2165
|
+
if (now - FileTransportCacheMap[filePath].lastWrite > FILE_TRANSPORT_TIMEOUT || FileTransportCacheMap[filePath].flushBuffer.length > FILE_TRANSPORT_THRESHOLD) {
|
|
2169
2166
|
clearTimeout(FileTransportCacheMap[filePath].currentTimeout);
|
|
2170
2167
|
FileTransportCacheMap[filePath].currentTimeout = null;
|
|
2171
2168
|
return flush(true);
|
|
@@ -2255,6 +2252,7 @@ var init_router = __esm({
|
|
|
2255
2252
|
init_session();
|
|
2256
2253
|
init_body_parser();
|
|
2257
2254
|
init_lib2();
|
|
2255
|
+
init_built_in_parsers();
|
|
2258
2256
|
Router2 = class {
|
|
2259
2257
|
constructor(config) {
|
|
2260
2258
|
this.config = config;
|
|
@@ -2689,26 +2687,30 @@ function parseFrame(buffer) {
|
|
|
2689
2687
|
const opCode = firstByte & 15;
|
|
2690
2688
|
if (opCode === OPCODES.close) {
|
|
2691
2689
|
return null;
|
|
2690
|
+
} else if (opCode === OPCODES.ping) {
|
|
2691
|
+
return PING;
|
|
2692
2692
|
} else if (opCode !== OPCODES.text) {
|
|
2693
|
-
return;
|
|
2693
|
+
return null;
|
|
2694
2694
|
}
|
|
2695
2695
|
const secondByte = buffer.readUInt8(1);
|
|
2696
2696
|
let offset = 2;
|
|
2697
2697
|
let payloadLength = secondByte & 127;
|
|
2698
2698
|
if (payloadLength === 126) {
|
|
2699
|
+
payloadLength = buffer.readUInt16BE(offset);
|
|
2699
2700
|
offset += 2;
|
|
2700
2701
|
} else if (payloadLength === 127) {
|
|
2702
|
+
payloadLength = Number(buffer.readBigUInt64BE(offset));
|
|
2701
2703
|
offset += 8;
|
|
2702
2704
|
}
|
|
2703
2705
|
const isMasked = Boolean(secondByte >>> 7 & 1);
|
|
2704
2706
|
if (isMasked) {
|
|
2705
2707
|
const maskingKey = buffer.readUInt32BE(offset);
|
|
2706
2708
|
offset += 4;
|
|
2707
|
-
const payload = buffer.subarray(offset);
|
|
2709
|
+
const payload = buffer.subarray(offset, offset + payloadLength);
|
|
2708
2710
|
const result = unmask(payload, maskingKey);
|
|
2709
2711
|
return result.toString("utf-8");
|
|
2710
2712
|
}
|
|
2711
|
-
return buffer.subarray(offset).toString("utf-8");
|
|
2713
|
+
return buffer.subarray(offset, offset + payloadLength).toString("utf-8");
|
|
2712
2714
|
}
|
|
2713
2715
|
function unmask(payload, maskingKey) {
|
|
2714
2716
|
const result = Buffer.alloc(payload.byteLength);
|
|
@@ -2737,13 +2739,13 @@ function createFrame(payload) {
|
|
|
2737
2739
|
buffer[1] = payloadLength;
|
|
2738
2740
|
if (payloadLength === 126) {
|
|
2739
2741
|
buffer.writeUInt16BE(payloadByteLength, 2);
|
|
2740
|
-
} else if (
|
|
2742
|
+
} else if (payloadLength === 127) {
|
|
2741
2743
|
buffer.writeBigUInt64BE(BigInt(payloadByteLength), 2);
|
|
2742
2744
|
}
|
|
2743
2745
|
buffer.write(payload, payloadBytesOffset);
|
|
2744
2746
|
return buffer;
|
|
2745
2747
|
}
|
|
2746
|
-
var import_crypto3, WebSocketServer, OPCODES, GUID;
|
|
2748
|
+
var import_crypto3, WebSocketServer, PING, OPCODES, GUID;
|
|
2747
2749
|
var init_websocket = __esm({
|
|
2748
2750
|
"node_modules/@miqro/core/build/websocket.js"() {
|
|
2749
2751
|
import_crypto3 = require("crypto");
|
|
@@ -2767,14 +2769,7 @@ var init_websocket = __esm({
|
|
|
2767
2769
|
const clients = this.clients.values();
|
|
2768
2770
|
for (const client of clients) {
|
|
2769
2771
|
if (fromUUID === void 0 || client.uuid !== fromUUID) {
|
|
2770
|
-
tR.push(
|
|
2771
|
-
try {
|
|
2772
|
-
await this.writeTo(client.uuid, data);
|
|
2773
|
-
resolve24();
|
|
2774
|
-
} catch (e) {
|
|
2775
|
-
reject(e);
|
|
2776
|
-
}
|
|
2777
|
-
}));
|
|
2772
|
+
tR.push(this.writeTo(client.uuid, data));
|
|
2778
2773
|
}
|
|
2779
2774
|
}
|
|
2780
2775
|
await Promise.allSettled(tR);
|
|
@@ -2850,7 +2845,13 @@ var init_websocket = __esm({
|
|
|
2850
2845
|
socket.write(createUpgradeHeaders(acceptKey, extraHeaders));
|
|
2851
2846
|
socket.on("data", (data) => {
|
|
2852
2847
|
const frame = parseFrame(data);
|
|
2853
|
-
if (frame
|
|
2848
|
+
if (frame === PING) {
|
|
2849
|
+
try {
|
|
2850
|
+
socket.write(Buffer.from([138, 0]));
|
|
2851
|
+
} catch (e) {
|
|
2852
|
+
req.logger.error(e);
|
|
2853
|
+
}
|
|
2854
|
+
} else if (frame !== null) {
|
|
2854
2855
|
if (!this.options.onMessage) {
|
|
2855
2856
|
socket.end();
|
|
2856
2857
|
socket.destroy();
|
|
@@ -2861,6 +2862,14 @@ var init_websocket = __esm({
|
|
|
2861
2862
|
req.logger.error(e);
|
|
2862
2863
|
}
|
|
2863
2864
|
}
|
|
2865
|
+
} else {
|
|
2866
|
+
try {
|
|
2867
|
+
socket.write(Buffer.from([136, 0]));
|
|
2868
|
+
} catch (e) {
|
|
2869
|
+
req.logger.error(e);
|
|
2870
|
+
}
|
|
2871
|
+
socket.end();
|
|
2872
|
+
socket.destroy();
|
|
2864
2873
|
}
|
|
2865
2874
|
});
|
|
2866
2875
|
socket.on("error", (error2) => {
|
|
@@ -2899,7 +2908,8 @@ var init_websocket = __esm({
|
|
|
2899
2908
|
}
|
|
2900
2909
|
}
|
|
2901
2910
|
};
|
|
2902
|
-
|
|
2911
|
+
PING = /* @__PURE__ */ Symbol();
|
|
2912
|
+
OPCODES = { text: 1, close: 8, ping: 9, pong: 10 };
|
|
2903
2913
|
GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
2904
2914
|
}
|
|
2905
2915
|
});
|
|
@@ -3544,7 +3554,7 @@ var require_showdown = __commonJS({
|
|
|
3544
3554
|
};
|
|
3545
3555
|
showdown2.helper.encodeEmailAddress = function(mail) {
|
|
3546
3556
|
"use strict";
|
|
3547
|
-
var
|
|
3557
|
+
var encode3 = [
|
|
3548
3558
|
function(ch) {
|
|
3549
3559
|
return "&#" + ch.charCodeAt(0) + ";";
|
|
3550
3560
|
},
|
|
@@ -3557,10 +3567,10 @@ var require_showdown = __commonJS({
|
|
|
3557
3567
|
];
|
|
3558
3568
|
mail = mail.replace(/./g, function(ch) {
|
|
3559
3569
|
if (ch === "@") {
|
|
3560
|
-
ch =
|
|
3570
|
+
ch = encode3[Math.floor(Math.random() * 2)](ch);
|
|
3561
3571
|
} else {
|
|
3562
3572
|
var r = Math.random();
|
|
3563
|
-
ch = r > 0.9 ?
|
|
3573
|
+
ch = r > 0.9 ? encode3[2](ch) : r > 0.45 ? encode3[1](ch) : encode3[0](ch);
|
|
3564
3574
|
}
|
|
3565
3575
|
return ch;
|
|
3566
3576
|
});
|
|
@@ -6772,7 +6782,7 @@ function readFile2(path) {
|
|
|
6772
6782
|
}
|
|
6773
6783
|
}
|
|
6774
6784
|
function getPath(path) {
|
|
6775
|
-
const realPath = (0, import_node_path21.resolve)(BASE_PATH, path);
|
|
6785
|
+
const realPath = (0, import_node_fs19.realpathSync)((0, import_node_path21.resolve)(BASE_PATH, path));
|
|
6776
6786
|
if ((0, import_node_path21.relative)(BASE_PATH, realPath).startsWith("..")) {
|
|
6777
6787
|
throw new Error("invalid path! [" + path + "]");
|
|
6778
6788
|
}
|
|
@@ -7585,7 +7595,7 @@ function getDefaultOptions() {
|
|
|
7585
7595
|
}
|
|
7586
7596
|
|
|
7587
7597
|
// node_modules/@miqro/jsx/build/esm/jsx.js
|
|
7588
|
-
var Fragment = Symbol("Fragment");
|
|
7598
|
+
var Fragment = /* @__PURE__ */ Symbol("Fragment");
|
|
7589
7599
|
function createElement(tag2, attributes, ...children) {
|
|
7590
7600
|
if (!tag2) {
|
|
7591
7601
|
throw new Error(`cannot call createElement with [${String(tag2)}] `);
|
|
@@ -8564,7 +8574,7 @@ function useElement() {
|
|
|
8564
8574
|
|
|
8565
8575
|
// node_modules/@miqro/jsx/build/esm/hooks/context.js
|
|
8566
8576
|
function createContext(defaultValue) {
|
|
8567
|
-
const symbol = Symbol();
|
|
8577
|
+
const symbol = /* @__PURE__ */ Symbol();
|
|
8568
8578
|
return {
|
|
8569
8579
|
provider: createContextProvider(symbol, defaultValue),
|
|
8570
8580
|
symbol
|
|
@@ -9171,7 +9181,7 @@ var ASSETS_ROUTER = {
|
|
|
9171
9181
|
};
|
|
9172
9182
|
function getAsset(key) {
|
|
9173
9183
|
if ((0, import_node_sea.isSea)()) {
|
|
9174
|
-
return (0, import_node_sea.getAsset)(key);
|
|
9184
|
+
return Buffer.from((0, import_node_sea.getAsset)(key));
|
|
9175
9185
|
} else {
|
|
9176
9186
|
if (!ASSETS_ROUTER[key]) {
|
|
9177
9187
|
if (key === "esbuild-binary") {
|
|
@@ -9362,7 +9372,7 @@ async function esBuild2(options, logger) {
|
|
|
9362
9372
|
return new Promise(async (resolve24, reject) => {
|
|
9363
9373
|
try {
|
|
9364
9374
|
const valid = await validateESBuild(logger);
|
|
9365
|
-
const esBuildCMD = `${getESBuildBinaryPath()} "${options.entryPoints[0]}" ${(options.external ? options.external : NODEJS_EXTERNAL).map((e) => `--external
|
|
9375
|
+
const esBuildCMD = `${getESBuildBinaryPath()} "${options.entryPoints[0]}" ${(options.external ? options.external : NODEJS_EXTERNAL).map((e) => `--external:"${e}"`).join(" ")} --loader:.js=jsx --jsx-factory=${options.jsxFactory} --jsx-fragment=${options.jsxFragment} ${options.bundle ? " --bundle" : ""}${options.minify ? " --minify" : ""}${options.outfile ? ` --outfile="${options.outfile}"` : ""}${options.platform ? ` --platform=${options.platform}` : ""}${options.mainFields ? ` --main-fields=${options.mainFields}` : ""}${options.keepNames ? ` --keep-names` : ""}`;
|
|
9366
9376
|
logger?.trace(esBuildCMD);
|
|
9367
9377
|
if (!valid) {
|
|
9368
9378
|
const err = new Error(`esbuild installation at [${getESBuildBinaryPath()}] tampered`);
|
|
@@ -9403,6 +9413,7 @@ var EXIT_CODES = {
|
|
|
9403
9413
|
var CLEAR_JSX_CACHE = (process.env["CLEAR_JSX_CACHE"] !== void 0 ? process.env["CLEAR_JSX_CACHE"] : "1") === "1";
|
|
9404
9414
|
var EDITOR_CONFIG_KEY = "$$editor$$";
|
|
9405
9415
|
var HOT_RELOAD_PATH = "/hot-reload";
|
|
9416
|
+
var HOT_RELOAD_SCRIPT_PATH = "/hot-reload.js";
|
|
9406
9417
|
|
|
9407
9418
|
// src/common/jsx.ts
|
|
9408
9419
|
init_types();
|
|
@@ -9611,9 +9622,9 @@ var DocConfigSchema = {
|
|
|
9611
9622
|
}
|
|
9612
9623
|
}
|
|
9613
9624
|
};
|
|
9614
|
-
async function importAPIRoute(inFile, logger) {
|
|
9625
|
+
async function importAPIRoute(inFile, options, logger) {
|
|
9615
9626
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9616
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9627
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9617
9628
|
const module2 = typeof mod === "function" ? { handler: mod } : parser.parse(mod, APIRouteSchema, (0, import_node_path6.basename)(inFile));
|
|
9618
9629
|
if (module2 !== void 0) {
|
|
9619
9630
|
return module2;
|
|
@@ -9621,9 +9632,9 @@ async function importAPIRoute(inFile, logger) {
|
|
|
9621
9632
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9622
9633
|
}
|
|
9623
9634
|
}
|
|
9624
|
-
async function importMigrationModule(inFile, logger) {
|
|
9635
|
+
async function importMigrationModule(inFile, options, logger) {
|
|
9625
9636
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9626
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9637
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9627
9638
|
const module2 = parser.parse(mod, MigrationSchema, (0, import_node_path6.basename)(inFile));
|
|
9628
9639
|
if (module2 !== void 0) {
|
|
9629
9640
|
return module2;
|
|
@@ -9631,8 +9642,8 @@ async function importMigrationModule(inFile, logger) {
|
|
|
9631
9642
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9632
9643
|
}
|
|
9633
9644
|
}
|
|
9634
|
-
async function importHTMLModule(inFile, logger) {
|
|
9635
|
-
const module2 = await importJSXFile(inFile, logger);
|
|
9645
|
+
async function importHTMLModule(inFile, options, logger) {
|
|
9646
|
+
const module2 = await importJSXFile(inFile, options, logger);
|
|
9636
9647
|
parser.parse(module2.default, HTMLModuleSchema.properties.default, `${(0, import_node_path6.basename)(inFile)}.default`);
|
|
9637
9648
|
parser.parse(module2.apiOptions, APIOptionsSchema, `${(0, import_node_path6.basename)(inFile)}.apiOptions`);
|
|
9638
9649
|
if (module2 !== void 0) {
|
|
@@ -9641,8 +9652,8 @@ async function importHTMLModule(inFile, logger) {
|
|
|
9641
9652
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9642
9653
|
}
|
|
9643
9654
|
}
|
|
9644
|
-
async function importJSONModule(inFile, logger) {
|
|
9645
|
-
const module2 = await importJSXFile(inFile, logger);
|
|
9655
|
+
async function importJSONModule(inFile, options, logger) {
|
|
9656
|
+
const module2 = await importJSXFile(inFile, options, logger);
|
|
9646
9657
|
parser.parse(module2.default, JSONModuleSchema.properties.default, `${(0, import_node_path6.basename)(inFile)}.default`);
|
|
9647
9658
|
parser.parse(module2.apiOptions, APIOptionsSchema, `${(0, import_node_path6.basename)(inFile)}.apiOptions`);
|
|
9648
9659
|
if (module2 !== void 0) {
|
|
@@ -9651,9 +9662,9 @@ async function importJSONModule(inFile, logger) {
|
|
|
9651
9662
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9652
9663
|
}
|
|
9653
9664
|
}
|
|
9654
|
-
async function importAuthModule(inFile, logger) {
|
|
9665
|
+
async function importAuthModule(inFile, options, logger) {
|
|
9655
9666
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9656
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9667
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9657
9668
|
const module2 = parser.parse(mod, AuthConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9658
9669
|
if (module2 !== void 0) {
|
|
9659
9670
|
return module2;
|
|
@@ -9661,9 +9672,9 @@ async function importAuthModule(inFile, logger) {
|
|
|
9661
9672
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9662
9673
|
}
|
|
9663
9674
|
}
|
|
9664
|
-
async function importMiddlewareConfigModule(inFile, logger) {
|
|
9675
|
+
async function importMiddlewareConfigModule(inFile, options, logger) {
|
|
9665
9676
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9666
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9677
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9667
9678
|
const module2 = parser.parse(mod, MiddlewareConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9668
9679
|
if (module2 !== void 0) {
|
|
9669
9680
|
return module2;
|
|
@@ -9671,9 +9682,9 @@ async function importMiddlewareConfigModule(inFile, logger) {
|
|
|
9671
9682
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9672
9683
|
}
|
|
9673
9684
|
}
|
|
9674
|
-
async function importErrorConfigModule(inFile, logger) {
|
|
9685
|
+
async function importErrorConfigModule(inFile, options, logger) {
|
|
9675
9686
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9676
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9687
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9677
9688
|
const module2 = parser.parse(mod, ErrorConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9678
9689
|
if (module2 !== void 0) {
|
|
9679
9690
|
return module2;
|
|
@@ -9681,9 +9692,9 @@ async function importErrorConfigModule(inFile, logger) {
|
|
|
9681
9692
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9682
9693
|
}
|
|
9683
9694
|
}
|
|
9684
|
-
async function importDocConfigModule(inFile, logger) {
|
|
9695
|
+
async function importDocConfigModule(inFile, options, logger) {
|
|
9685
9696
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9686
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9697
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9687
9698
|
const module2 = parser.parse(mod, DocConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9688
9699
|
if (module2 !== void 0) {
|
|
9689
9700
|
return module2;
|
|
@@ -9691,9 +9702,9 @@ async function importDocConfigModule(inFile, logger) {
|
|
|
9691
9702
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9692
9703
|
}
|
|
9693
9704
|
}
|
|
9694
|
-
async function importCORSModule(inFile, logger) {
|
|
9705
|
+
async function importCORSModule(inFile, options, logger) {
|
|
9695
9706
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9696
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9707
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9697
9708
|
const module2 = parser.parse(mod, CORSOptionsSchema, (0, import_node_path6.basename)(inFile));
|
|
9698
9709
|
if (module2 !== void 0) {
|
|
9699
9710
|
return module2;
|
|
@@ -9701,9 +9712,9 @@ async function importCORSModule(inFile, logger) {
|
|
|
9701
9712
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9702
9713
|
}
|
|
9703
9714
|
}
|
|
9704
|
-
async function importWSConfigModule(inFile, logger) {
|
|
9715
|
+
async function importWSConfigModule(inFile, options, logger) {
|
|
9705
9716
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9706
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9717
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9707
9718
|
const module2 = parser.parse(mod, WSConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9708
9719
|
if (module2 !== void 0) {
|
|
9709
9720
|
return module2;
|
|
@@ -9711,9 +9722,9 @@ async function importWSConfigModule(inFile, logger) {
|
|
|
9711
9722
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9712
9723
|
}
|
|
9713
9724
|
}
|
|
9714
|
-
async function importDBConfigModule(inFile, logger) {
|
|
9725
|
+
async function importDBConfigModule(inFile, options, logger) {
|
|
9715
9726
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9716
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9727
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9717
9728
|
const module2 = parser.parse(mod, DBConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9718
9729
|
if (module2 !== void 0) {
|
|
9719
9730
|
return module2;
|
|
@@ -9721,17 +9732,17 @@ async function importDBConfigModule(inFile, logger) {
|
|
|
9721
9732
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9722
9733
|
}
|
|
9723
9734
|
}
|
|
9724
|
-
async function importLogConfigModule(inFile, logger) {
|
|
9725
|
-
const module2 = parser.parse((await importJSXFile(inFile, logger)).default, LogConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9735
|
+
async function importLogConfigModule(inFile, options, logger) {
|
|
9736
|
+
const module2 = parser.parse((await importJSXFile(inFile, options, logger)).default, LogConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9726
9737
|
if (module2 !== void 0) {
|
|
9727
9738
|
return module2;
|
|
9728
9739
|
} else {
|
|
9729
9740
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9730
9741
|
}
|
|
9731
9742
|
}
|
|
9732
|
-
async function importServerConfigModule(inFile, logger) {
|
|
9743
|
+
async function importServerConfigModule(inFile, options, logger) {
|
|
9733
9744
|
const isCJS = (0, import_node_path6.extname)(inFile) === ".cjs";
|
|
9734
|
-
const mod = isCJS ? (await importJSXFile(inFile, logger)).default.default : (await importJSXFile(inFile, logger)).default;
|
|
9745
|
+
const mod = isCJS ? (await importJSXFile(inFile, options, logger)).default.default : (await importJSXFile(inFile, options, logger)).default;
|
|
9735
9746
|
const module2 = parser.parse(mod, ServerConfigSchema, (0, import_node_path6.basename)(inFile));
|
|
9736
9747
|
if (module2 !== void 0) {
|
|
9737
9748
|
return module2;
|
|
@@ -9739,7 +9750,11 @@ async function importServerConfigModule(inFile, logger) {
|
|
|
9739
9750
|
throw new Error(`error with module [${inFile}] undefined`);
|
|
9740
9751
|
}
|
|
9741
9752
|
}
|
|
9742
|
-
async function importJSXFile(inFile, logger) {
|
|
9753
|
+
async function importJSXFile(inFile, options, logger) {
|
|
9754
|
+
if (options.noBuild) {
|
|
9755
|
+
const module2 = await import((0, import_node_path6.resolve)(inFile));
|
|
9756
|
+
return module2;
|
|
9757
|
+
}
|
|
9743
9758
|
const inflatedCode = await inflateJSX(inFile, {
|
|
9744
9759
|
// embemedJSX: false,
|
|
9745
9760
|
minify: false,
|
|
@@ -10022,7 +10037,7 @@ function getWhereStatement(where) {
|
|
|
10022
10037
|
case "gte": {
|
|
10023
10038
|
const { _column, _value } = getWhereFilterColumnName(filter);
|
|
10024
10039
|
ret = mergePrepareArgs(ret, {
|
|
10025
|
-
sql: `${renderColumn(
|
|
10040
|
+
sql: `${renderColumn(_column)}>=?`,
|
|
10026
10041
|
values: [_value]
|
|
10027
10042
|
});
|
|
10028
10043
|
break;
|
|
@@ -11514,9 +11529,26 @@ var ClusterCache = class {
|
|
|
11514
11529
|
this.listener = async (data) => {
|
|
11515
11530
|
try {
|
|
11516
11531
|
const msg = data;
|
|
11517
|
-
if (msg && msg.key && msg.action && msg.type === ClusterCacheType && msg.fromPID !== process.pid
|
|
11532
|
+
if (msg && msg.key && msg.action && msg.type === ClusterCacheType && msg.fromPID !== process.pid && (msg.action === "set_clear" || msg.action === "array_clear" || msg.action === "set_add" || msg.action === "set" || msg.action === "unset" || msg.action === "set_delete" || msg.action === "array_push") && msg.target === this.name) {
|
|
11518
11533
|
this.logger?.debug("remote cluster cache message from [%s] [%s] [%s] [%s]", msg.fromPID, msg.target, msg.action, msg.key);
|
|
11519
11534
|
switch (msg.action) {
|
|
11535
|
+
case "set_clear": {
|
|
11536
|
+
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : /* @__PURE__ */ new Set();
|
|
11537
|
+
if (!(list instanceof Set)) {
|
|
11538
|
+
throw new Error("cannot apply clear on non set");
|
|
11539
|
+
}
|
|
11540
|
+
list.clear();
|
|
11541
|
+
this.localCache.set(msg.key, list);
|
|
11542
|
+
break;
|
|
11543
|
+
}
|
|
11544
|
+
case "array_clear": {
|
|
11545
|
+
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : [];
|
|
11546
|
+
if (!(list instanceof Array)) {
|
|
11547
|
+
throw new Error("cannot apply clear on non array");
|
|
11548
|
+
}
|
|
11549
|
+
this.localCache.set(msg.key, []);
|
|
11550
|
+
break;
|
|
11551
|
+
}
|
|
11520
11552
|
case "unset":
|
|
11521
11553
|
this.localCache.delete(msg.key);
|
|
11522
11554
|
break;
|
|
@@ -11526,7 +11558,7 @@ var ClusterCache = class {
|
|
|
11526
11558
|
case "set_add": {
|
|
11527
11559
|
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : /* @__PURE__ */ new Set();
|
|
11528
11560
|
if (!(list instanceof Set)) {
|
|
11529
|
-
throw new Error("cannot apply
|
|
11561
|
+
throw new Error("cannot apply add on non set");
|
|
11530
11562
|
}
|
|
11531
11563
|
if (!list.has(msg.value)) {
|
|
11532
11564
|
list.add(msg.value);
|
|
@@ -11537,7 +11569,7 @@ var ClusterCache = class {
|
|
|
11537
11569
|
case "set_delete": {
|
|
11538
11570
|
const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : /* @__PURE__ */ new Set();
|
|
11539
11571
|
if (!(list instanceof Set)) {
|
|
11540
|
-
throw new Error("cannot apply
|
|
11572
|
+
throw new Error("cannot apply delete on non set");
|
|
11541
11573
|
}
|
|
11542
11574
|
if (list.has(msg.value)) {
|
|
11543
11575
|
list.delete(msg.value);
|
|
@@ -11581,33 +11613,25 @@ var ClusterCache = class {
|
|
|
11581
11613
|
set(key, value) {
|
|
11582
11614
|
this.localCache.set(key, value);
|
|
11583
11615
|
this.logger?.trace("set(%s, ...)", key);
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
|
|
11592
|
-
value
|
|
11593
|
-
});
|
|
11594
|
-
}, 10);
|
|
11595
|
-
}
|
|
11616
|
+
sendTimeout({
|
|
11617
|
+
type: ClusterCacheType,
|
|
11618
|
+
action: "set",
|
|
11619
|
+
target: this.name,
|
|
11620
|
+
fromPID: process.pid,
|
|
11621
|
+
key,
|
|
11622
|
+
value
|
|
11623
|
+
});
|
|
11596
11624
|
}
|
|
11597
11625
|
unset(key) {
|
|
11598
11626
|
this.logger?.trace("unset(%s)", key);
|
|
11599
11627
|
this.localCache.delete(key);
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
key
|
|
11608
|
-
});
|
|
11609
|
-
}, 10);
|
|
11610
|
-
}
|
|
11628
|
+
sendTimeout({
|
|
11629
|
+
type: ClusterCacheType,
|
|
11630
|
+
target: this.name,
|
|
11631
|
+
action: "unset",
|
|
11632
|
+
fromPID: process.pid,
|
|
11633
|
+
key
|
|
11634
|
+
});
|
|
11611
11635
|
}
|
|
11612
11636
|
has(key) {
|
|
11613
11637
|
this.logger?.trace("has(%s)", key);
|
|
@@ -11623,18 +11647,14 @@ var ClusterCache = class {
|
|
|
11623
11647
|
list.add(value);
|
|
11624
11648
|
}
|
|
11625
11649
|
this.localCache.set(key, list);
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
value
|
|
11635
|
-
});
|
|
11636
|
-
}, 10);
|
|
11637
|
-
}
|
|
11650
|
+
sendTimeout({
|
|
11651
|
+
type: ClusterCacheType,
|
|
11652
|
+
target: this.name,
|
|
11653
|
+
action: "set_add",
|
|
11654
|
+
fromPID: process.pid,
|
|
11655
|
+
key,
|
|
11656
|
+
value
|
|
11657
|
+
});
|
|
11638
11658
|
}
|
|
11639
11659
|
set_delete(key, value) {
|
|
11640
11660
|
this.logger?.trace("delete(%s)", key);
|
|
@@ -11646,18 +11666,14 @@ var ClusterCache = class {
|
|
|
11646
11666
|
list.delete(value);
|
|
11647
11667
|
}
|
|
11648
11668
|
this.localCache.set(key, list);
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
|
|
11653
|
-
|
|
11654
|
-
|
|
11655
|
-
|
|
11656
|
-
|
|
11657
|
-
value
|
|
11658
|
-
});
|
|
11659
|
-
}, 10);
|
|
11660
|
-
}
|
|
11669
|
+
sendTimeout({
|
|
11670
|
+
type: ClusterCacheType,
|
|
11671
|
+
target: this.name,
|
|
11672
|
+
action: "set_delete",
|
|
11673
|
+
fromPID: process.pid,
|
|
11674
|
+
key,
|
|
11675
|
+
value
|
|
11676
|
+
});
|
|
11661
11677
|
}
|
|
11662
11678
|
set_has(key, value) {
|
|
11663
11679
|
this.logger?.trace("set_has(%s)", key);
|
|
@@ -11677,6 +11693,13 @@ var ClusterCache = class {
|
|
|
11677
11693
|
}
|
|
11678
11694
|
list.clear();
|
|
11679
11695
|
this.localCache.set(key, list);
|
|
11696
|
+
sendTimeout({
|
|
11697
|
+
type: ClusterCacheType,
|
|
11698
|
+
target: this.name,
|
|
11699
|
+
action: "set_clear",
|
|
11700
|
+
fromPID: process.pid,
|
|
11701
|
+
key
|
|
11702
|
+
});
|
|
11680
11703
|
}
|
|
11681
11704
|
array_push(key, value) {
|
|
11682
11705
|
this.logger?.trace("array_push(%s)", key);
|
|
@@ -11686,18 +11709,14 @@ var ClusterCache = class {
|
|
|
11686
11709
|
}
|
|
11687
11710
|
list.push(value);
|
|
11688
11711
|
this.localCache.set(key, list);
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
value
|
|
11698
|
-
});
|
|
11699
|
-
}, 10);
|
|
11700
|
-
}
|
|
11712
|
+
sendTimeout({
|
|
11713
|
+
type: ClusterCacheType,
|
|
11714
|
+
target: this.name,
|
|
11715
|
+
action: "array_push",
|
|
11716
|
+
fromPID: process.pid,
|
|
11717
|
+
key,
|
|
11718
|
+
value
|
|
11719
|
+
});
|
|
11701
11720
|
}
|
|
11702
11721
|
array_clear(key) {
|
|
11703
11722
|
this.logger?.trace("array_clear(%s)", key);
|
|
@@ -11705,8 +11724,28 @@ var ClusterCache = class {
|
|
|
11705
11724
|
throw new Error("cannot apply on non Array");
|
|
11706
11725
|
}
|
|
11707
11726
|
this.localCache.set(key, []);
|
|
11727
|
+
sendTimeout({
|
|
11728
|
+
type: ClusterCacheType,
|
|
11729
|
+
target: this.name,
|
|
11730
|
+
action: "array_clear",
|
|
11731
|
+
fromPID: process.pid,
|
|
11732
|
+
key
|
|
11733
|
+
});
|
|
11708
11734
|
}
|
|
11709
11735
|
};
|
|
11736
|
+
function sendTimeout(msg) {
|
|
11737
|
+
if (process.send) {
|
|
11738
|
+
setTimeout(() => {
|
|
11739
|
+
try {
|
|
11740
|
+
if (process.send) {
|
|
11741
|
+
process.send(msg);
|
|
11742
|
+
}
|
|
11743
|
+
} catch (e) {
|
|
11744
|
+
console.error(e);
|
|
11745
|
+
}
|
|
11746
|
+
}, 10);
|
|
11747
|
+
}
|
|
11748
|
+
}
|
|
11710
11749
|
|
|
11711
11750
|
// src/services/utils/cache.ts
|
|
11712
11751
|
var LocalCache = class {
|
|
@@ -11810,7 +11849,8 @@ var WebSocketManager = class {
|
|
|
11810
11849
|
deleteWS(path) {
|
|
11811
11850
|
const ws = this.runningGlobalWSMap.get(path);
|
|
11812
11851
|
this.disconnectAllFrom(path);
|
|
11813
|
-
ws
|
|
11852
|
+
if (ws)
|
|
11853
|
+
ws.dispose();
|
|
11814
11854
|
this.runningGlobalWSMap.delete(path);
|
|
11815
11855
|
}
|
|
11816
11856
|
deleteAllWS() {
|
|
@@ -12156,8 +12196,7 @@ var CONTENT_TYPE_MAP = {
|
|
|
12156
12196
|
};
|
|
12157
12197
|
|
|
12158
12198
|
// src/services/hot-reload.ts
|
|
12159
|
-
|
|
12160
|
-
const HOT_RELOAD_JS_SCRIPT = `
|
|
12199
|
+
var HOT_RELOAD_JS_SCRIPT = `
|
|
12161
12200
|
// Create WebSocket connection.
|
|
12162
12201
|
|
|
12163
12202
|
function getSocket() {
|
|
@@ -12167,13 +12206,14 @@ function getSocket() {
|
|
|
12167
12206
|
const socket = getSocket();
|
|
12168
12207
|
|
|
12169
12208
|
let timeout;
|
|
12209
|
+
let reloadtimeout;
|
|
12170
12210
|
|
|
12171
12211
|
function tryConnection() {
|
|
12172
12212
|
try {
|
|
12173
12213
|
const newSocket = getSocket();
|
|
12174
12214
|
newSocket.addEventListener("open", (event) => {
|
|
12175
12215
|
console.log("reloading");
|
|
12176
|
-
setTimeout(()=>{
|
|
12216
|
+
reloadtimeout = setTimeout(()=>{
|
|
12177
12217
|
window.location.reload();
|
|
12178
12218
|
}, 500);
|
|
12179
12219
|
|
|
@@ -12191,13 +12231,16 @@ function tryConnection() {
|
|
|
12191
12231
|
// Connection closed
|
|
12192
12232
|
socket.addEventListener("close", (event) => {
|
|
12193
12233
|
clearTimeout(timeout);
|
|
12234
|
+
clearTimeout(reloadtimeout);
|
|
12194
12235
|
timeout = setTimeout(tryConnection, 500);
|
|
12195
12236
|
});
|
|
12196
12237
|
|
|
12197
12238
|
socket.addEventListener("error", (err) => {
|
|
12239
|
+
clearTimeout(reloadtimeout);
|
|
12198
12240
|
console.error(err);
|
|
12199
12241
|
});`;
|
|
12200
|
-
|
|
12242
|
+
function getHotReloadScript() {
|
|
12243
|
+
return `<script src="${HOT_RELOAD_SCRIPT_PATH}"></script>`;
|
|
12201
12244
|
}
|
|
12202
12245
|
|
|
12203
12246
|
// src/inflate/setup-http.ts
|
|
@@ -12208,12 +12251,12 @@ var import_node_fs6 = require("node:fs");
|
|
|
12208
12251
|
init_lib3();
|
|
12209
12252
|
var import_node_path7 = require("node:path");
|
|
12210
12253
|
var import_node_process4 = require("node:process");
|
|
12211
|
-
async function setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors) {
|
|
12254
|
+
async function setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, options, errors) {
|
|
12212
12255
|
const corsPath = getCORSConfigPath(servicePath);
|
|
12213
12256
|
if (corsPath) {
|
|
12214
12257
|
try {
|
|
12215
|
-
const corsOptions = await importCORSModule(corsPath, logger);
|
|
12216
12258
|
logger.debug("setting up cors from [%s]", (0, import_node_path7.join)(service, (0, import_node_path7.basename)(corsPath)));
|
|
12259
|
+
const corsOptions = await importCORSModule(corsPath, options, logger);
|
|
12217
12260
|
mainRouter.use(CORS(corsOptions));
|
|
12218
12261
|
if (inflateDir && inflateSea) {
|
|
12219
12262
|
const inflatePath = (0, import_node_path7.resolve)(inflateDir, service, "cors.cjs");
|
|
@@ -12245,11 +12288,11 @@ init_lib3();
|
|
|
12245
12288
|
var import_node_path8 = require("node:path");
|
|
12246
12289
|
var import_node_fs7 = require("node:fs");
|
|
12247
12290
|
var import_node_process5 = require("node:process");
|
|
12248
|
-
async function setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors) {
|
|
12291
|
+
async function setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, options, errors) {
|
|
12249
12292
|
const authPath = getAuthConfigPath(servicePath);
|
|
12250
12293
|
if (authPath) {
|
|
12251
12294
|
try {
|
|
12252
|
-
const authModule = await importAuthModule(authPath, logger);
|
|
12295
|
+
const authModule = await importAuthModule(authPath, options, logger);
|
|
12253
12296
|
logger.debug("setting up authentication from [%s]", (0, import_node_path8.join)(service, (0, import_node_path8.basename)(authPath)));
|
|
12254
12297
|
mainRouter.use(SessionHandler(authModule));
|
|
12255
12298
|
if (inflateDir && inflateSea) {
|
|
@@ -12360,11 +12403,11 @@ function inflateMDString2HTML(text, logger) {
|
|
|
12360
12403
|
var import_node_path10 = require("node:path");
|
|
12361
12404
|
var import_node_fs9 = require("node:fs");
|
|
12362
12405
|
var import_node_process6 = require("node:process");
|
|
12363
|
-
async function setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors) {
|
|
12406
|
+
async function setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, options, errors) {
|
|
12364
12407
|
const middlewarePath = getMiddlewareConfigPath(servicePath);
|
|
12365
12408
|
if (middlewarePath) {
|
|
12366
12409
|
try {
|
|
12367
|
-
const middewareModule = await importMiddlewareConfigModule(middlewarePath, logger);
|
|
12410
|
+
const middewareModule = await importMiddlewareConfigModule(middlewarePath, options, logger);
|
|
12368
12411
|
logger.debug("setting up middleware from [%s]", (0, import_node_path10.join)(service, (0, import_node_path10.basename)(middlewarePath)));
|
|
12369
12412
|
if (middewareModule && middewareModule.middleware) {
|
|
12370
12413
|
for (const m of middewareModule.middleware) {
|
|
@@ -12402,11 +12445,11 @@ async function setupMiddleware(logger, servicePath, service, mainRouter, inflate
|
|
|
12402
12445
|
var import_node_path11 = require("node:path");
|
|
12403
12446
|
var import_node_fs10 = require("node:fs");
|
|
12404
12447
|
var import_node_process7 = require("node:process");
|
|
12405
|
-
async function setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors) {
|
|
12448
|
+
async function setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, options, errors) {
|
|
12406
12449
|
const errorPath = getErrorConfigPath(servicePath);
|
|
12407
12450
|
if (errorPath) {
|
|
12408
12451
|
try {
|
|
12409
|
-
const errorModule = await importErrorConfigModule(errorPath, logger);
|
|
12452
|
+
const errorModule = await importErrorConfigModule(errorPath, options, logger);
|
|
12410
12453
|
logger.debug("setting up error handling from [%s]", (0, import_node_path11.join)(service, (0, import_node_path11.basename)(errorPath)));
|
|
12411
12454
|
if (errorModule && errorModule.catch) {
|
|
12412
12455
|
for (const m of errorModule.catch) {
|
|
@@ -12439,23 +12482,23 @@ async function setupError(logger, servicePath, service, mainRouter, inflateDir,
|
|
|
12439
12482
|
}
|
|
12440
12483
|
|
|
12441
12484
|
// src/inflate/setup-http.ts
|
|
12442
|
-
async function setupHTTPRouter(server, logger, hotreload, servicePath, service, routeFileMap, staticFileMap, inflateDir, inflateSea, errors, inflateParallel) {
|
|
12485
|
+
async function setupHTTPRouter(importOptions, inflateOptions, server, logger, hotreload, servicePath, service, routeFileMap, staticFileMap, inflateDir, inflateSea, errors, inflateParallel) {
|
|
12443
12486
|
const mainRouter = new Router2();
|
|
12444
12487
|
const apiRouterPath = getHTTPRouterPath(servicePath);
|
|
12445
12488
|
let middlewareConfig = null;
|
|
12446
|
-
await setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
12447
|
-
await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
12448
|
-
await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
12449
|
-
middlewareConfig = await setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, errors);
|
|
12489
|
+
await setupError(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
12490
|
+
await setupCORS(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
12491
|
+
await setupAUTH(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
12492
|
+
middlewareConfig = await setupMiddleware(logger, servicePath, service, mainRouter, inflateDir, inflateSea, importOptions, errors);
|
|
12450
12493
|
if (apiRouterPath) {
|
|
12451
12494
|
logger.trace("setting up http routes from [%s]", service);
|
|
12452
|
-
const { router: httpRouter } = await createRouterFromDirectory(server, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea, inflateParallel);
|
|
12495
|
+
const { router: httpRouter } = await createRouterFromDirectory(importOptions, inflateOptions, server, hotreload, service, logger, apiRouterPath, errors, routeFileMap, staticFileMap, inflateDir, inflateSea, inflateParallel);
|
|
12453
12496
|
mainRouter.use(httpRouter);
|
|
12454
12497
|
}
|
|
12455
12498
|
const staticFilesPath = getStaticFilesPath(servicePath);
|
|
12456
12499
|
if (staticFilesPath) {
|
|
12457
12500
|
logger.trace("setting up static file routes from [%s]", service);
|
|
12458
|
-
const staticRouter = await createStaticRouterFromDirectory(service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap, inflateParallel);
|
|
12501
|
+
const staticRouter = await createStaticRouterFromDirectory(inflateOptions, service, logger, staticFilesPath, inflateDir, routeFileMap, staticFileMap, inflateParallel);
|
|
12459
12502
|
mainRouter.use(staticRouter);
|
|
12460
12503
|
}
|
|
12461
12504
|
if (middlewareConfig && middlewareConfig.post) {
|
|
@@ -12465,7 +12508,7 @@ async function setupHTTPRouter(server, logger, hotreload, servicePath, service,
|
|
|
12465
12508
|
}
|
|
12466
12509
|
return mainRouter;
|
|
12467
12510
|
}
|
|
12468
|
-
async function createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap) {
|
|
12511
|
+
async function createStaticRoute(inflateJSXOptions, service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap) {
|
|
12469
12512
|
return new Promise(async (resolve24, reject) => {
|
|
12470
12513
|
try {
|
|
12471
12514
|
logger.trace("creating static route for [%s]", file.filePath);
|
|
@@ -12484,8 +12527,8 @@ async function createStaticRoute(service, logger, router, dir, file, inflateDir,
|
|
|
12484
12527
|
filePath: file.filePath,
|
|
12485
12528
|
previewMethod: "html"
|
|
12486
12529
|
};
|
|
12487
|
-
if (inflateDir) {
|
|
12488
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
|
|
12530
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12531
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
12489
12532
|
(0, import_node_fs11.mkdir)((0, import_node_path12.dirname)(inflatePath), {
|
|
12490
12533
|
recursive: true
|
|
12491
12534
|
}, (err) => {
|
|
@@ -12504,7 +12547,7 @@ async function createStaticRoute(service, logger, router, dir, file, inflateDir,
|
|
|
12504
12547
|
method: "GET",
|
|
12505
12548
|
path: normalizePath2(path),
|
|
12506
12549
|
body: Buffer.from(body),
|
|
12507
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
|
|
12550
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : void 0
|
|
12508
12551
|
};
|
|
12509
12552
|
}
|
|
12510
12553
|
}
|
|
@@ -12540,14 +12583,14 @@ async function createStaticRoute(service, logger, router, dir, file, inflateDir,
|
|
|
12540
12583
|
}
|
|
12541
12584
|
});
|
|
12542
12585
|
}
|
|
12543
|
-
async function createStaticRouterFromDirectory(service, logger, dir, inflateDir, routeFileMap, staticFileMap, inflateParallel) {
|
|
12586
|
+
async function createStaticRouterFromDirectory(inflateOptions, service, logger, dir, inflateDir, routeFileMap, staticFileMap, inflateParallel) {
|
|
12544
12587
|
const router = new Router2();
|
|
12545
12588
|
const maxParallel = inflateParallel ? inflateParallel : 1;
|
|
12546
12589
|
logger.debug("loading static directory with parallel [%s]", maxParallel);
|
|
12547
12590
|
let tR = [];
|
|
12548
12591
|
const files = scanFiles(dir);
|
|
12549
12592
|
for (const file of files) {
|
|
12550
|
-
tR.push(await createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap));
|
|
12593
|
+
tR.push(await createStaticRoute(inflateOptions, service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap));
|
|
12551
12594
|
if (tR.length >= maxParallel) {
|
|
12552
12595
|
await Promise.all(tR);
|
|
12553
12596
|
tR = [];
|
|
@@ -12559,7 +12602,7 @@ async function createStaticRouterFromDirectory(service, logger, dir, inflateDir,
|
|
|
12559
12602
|
}
|
|
12560
12603
|
return router;
|
|
12561
12604
|
}
|
|
12562
|
-
async function createRouterFromDirectory(server, hotreload, service, logger, dir, errors = [], routeFileMap = {}, staticFileMap = null, inflateDir, inflateSea, inflateParallel) {
|
|
12605
|
+
async function createRouterFromDirectory(importOptions, inflateJSXOptions, server, hotreload, service, logger, dir, errors = [], routeFileMap = {}, staticFileMap = null, inflateDir, inflateSea, inflateParallel) {
|
|
12563
12606
|
const router = new Router2();
|
|
12564
12607
|
const maxParallel = inflateParallel ? inflateParallel : 1;
|
|
12565
12608
|
server.logger.debug("loading http directory with parallel [%s]", maxParallel);
|
|
@@ -12581,7 +12624,11 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12581
12624
|
logger.warn("ignoring [%s]", file.filePath);
|
|
12582
12625
|
return resolve24();
|
|
12583
12626
|
case ".api": {
|
|
12584
|
-
|
|
12627
|
+
if (inflateJSXOptions.inflateOnlyAssets) {
|
|
12628
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
12629
|
+
return resolve24();
|
|
12630
|
+
}
|
|
12631
|
+
const module2 = await importAPIRoute(file.filePath, importOptions, logger);
|
|
12585
12632
|
const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName, module2);
|
|
12586
12633
|
routeFileMap[file.filePath] = {
|
|
12587
12634
|
routes,
|
|
@@ -12589,7 +12636,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12589
12636
|
filePath: file.filePath,
|
|
12590
12637
|
previewMethod: "api"
|
|
12591
12638
|
};
|
|
12592
|
-
const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
|
|
12639
|
+
const inflatedCode = inflateDir && inflateSea && (!inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0) ? await inflateJSX(file.filePath, {
|
|
12593
12640
|
// embemedJSX: false,
|
|
12594
12641
|
minify: false,
|
|
12595
12642
|
useExport: true,
|
|
@@ -12599,7 +12646,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12599
12646
|
for (const r of routes) {
|
|
12600
12647
|
if (inflateDir && r.defaultInflatePath && inflateSea) {
|
|
12601
12648
|
const rPath = r.defaultInflatePath;
|
|
12602
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "http", rPath + ".api.cjs");
|
|
12649
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "http", rPath + ".api.cjs");
|
|
12603
12650
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12604
12651
|
recursive: true
|
|
12605
12652
|
});
|
|
@@ -12611,7 +12658,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12611
12658
|
return resolve24();
|
|
12612
12659
|
}
|
|
12613
12660
|
case ".json": {
|
|
12614
|
-
const module2 = await importJSONModule(file.filePath, logger);
|
|
12661
|
+
const module2 = await importJSONModule(file.filePath, importOptions, logger);
|
|
12615
12662
|
const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName + ".json", module2.apiOptions);
|
|
12616
12663
|
routeFileMap[file.filePath] = {
|
|
12617
12664
|
routes,
|
|
@@ -12621,10 +12668,10 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12621
12668
|
};
|
|
12622
12669
|
for (const r of routes) {
|
|
12623
12670
|
const contentType = CONTENT_TYPE_MAP[".json"] ? CONTENT_TYPE_MAP[".json"] : DEFAULT_CONTENT_TYPE;
|
|
12624
|
-
if (inflateDir) {
|
|
12671
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12625
12672
|
if (r.inflatePath) {
|
|
12626
12673
|
const rPath = r.inflatePath;
|
|
12627
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", rPath);
|
|
12674
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", rPath);
|
|
12628
12675
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12629
12676
|
recursive: true
|
|
12630
12677
|
});
|
|
@@ -12643,7 +12690,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12643
12690
|
previewMethod: "html",
|
|
12644
12691
|
path: r.path,
|
|
12645
12692
|
body: Buffer.from(JSON_STATIC),
|
|
12646
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", r.inflatePath) : void 0
|
|
12693
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", r.inflatePath) : void 0
|
|
12647
12694
|
};
|
|
12648
12695
|
}
|
|
12649
12696
|
}
|
|
@@ -12662,7 +12709,11 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12662
12709
|
return resolve24();
|
|
12663
12710
|
}
|
|
12664
12711
|
case ".html": {
|
|
12665
|
-
|
|
12712
|
+
if (inflateJSXOptions.inflateOnlyAssets) {
|
|
12713
|
+
logger.warn("ignoring [%s]", file.filePath);
|
|
12714
|
+
return resolve24();
|
|
12715
|
+
}
|
|
12716
|
+
const module2 = await importHTMLModule(file.filePath, importOptions, logger);
|
|
12666
12717
|
const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName + ".html", module2.apiOptions);
|
|
12667
12718
|
routeFileMap[file.filePath] = {
|
|
12668
12719
|
routes,
|
|
@@ -12672,10 +12723,10 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12672
12723
|
};
|
|
12673
12724
|
for (const r of routes) {
|
|
12674
12725
|
const contentType = CONTENT_TYPE_MAP[".html"] ? CONTENT_TYPE_MAP[".html"] : DEFAULT_CONTENT_TYPE;
|
|
12675
|
-
if (inflateDir) {
|
|
12726
|
+
if (inflateDir && (!inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12676
12727
|
if (r.inflatePath) {
|
|
12677
12728
|
const rPath = r.inflatePath;
|
|
12678
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", rPath);
|
|
12729
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", rPath);
|
|
12679
12730
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12680
12731
|
recursive: true
|
|
12681
12732
|
});
|
|
@@ -12687,7 +12738,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12687
12738
|
const HTML_STATIC = await getHTML(hotreload, { server }, null, newURL2(r.path), module2.apiOptions?.basePath, await toRender);
|
|
12688
12739
|
logger.log("writing [%s]", (0, import_node_path12.relative)((0, import_node_process8.cwd)(), inflatePath));
|
|
12689
12740
|
await writeFileASync(inflatePath, HTML_STATIC);
|
|
12690
|
-
if (staticFileMap && inflateSea) {
|
|
12741
|
+
if (staticFileMap && inflateSea && (!inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12691
12742
|
staticFileMap[file.filePath + r.method + r.path] = {
|
|
12692
12743
|
filePath: file.filePath,
|
|
12693
12744
|
contentType,
|
|
@@ -12695,7 +12746,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12695
12746
|
previewMethod: "html",
|
|
12696
12747
|
path: r.path,
|
|
12697
12748
|
body: Buffer.from(HTML_STATIC),
|
|
12698
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", r.inflatePath) : void 0
|
|
12749
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", r.inflatePath) : void 0
|
|
12699
12750
|
};
|
|
12700
12751
|
}
|
|
12701
12752
|
}
|
|
@@ -12718,7 +12769,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12718
12769
|
case ".js":
|
|
12719
12770
|
default: {
|
|
12720
12771
|
if (file.ext !== ".js" && file.ext !== ".ts") {
|
|
12721
|
-
const code = await inflateJSX(file.filePath, {
|
|
12772
|
+
const code = inflateJSXOptions.noMinify ? (0, import_node_fs11.readFileSync)(file.filePath).toString() : await inflateJSX(file.filePath, {
|
|
12722
12773
|
// embemedJSX: true,
|
|
12723
12774
|
minify: file.subExt === ".min" ? true : false,
|
|
12724
12775
|
useExport: true,
|
|
@@ -12735,8 +12786,8 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12735
12786
|
service,
|
|
12736
12787
|
previewMethod: "html"
|
|
12737
12788
|
};
|
|
12738
|
-
if (inflateDir) {
|
|
12739
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
|
|
12789
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12790
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
12740
12791
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12741
12792
|
recursive: true
|
|
12742
12793
|
});
|
|
@@ -12750,7 +12801,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12750
12801
|
previewMethod: "html",
|
|
12751
12802
|
path,
|
|
12752
12803
|
body: Buffer.from(code),
|
|
12753
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
|
|
12804
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : void 0
|
|
12754
12805
|
};
|
|
12755
12806
|
}
|
|
12756
12807
|
}
|
|
@@ -12783,8 +12834,8 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12783
12834
|
filePath: file.filePath,
|
|
12784
12835
|
previewMethod: "html"
|
|
12785
12836
|
};
|
|
12786
|
-
if (inflateDir) {
|
|
12787
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
|
|
12837
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12838
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
12788
12839
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12789
12840
|
recursive: true
|
|
12790
12841
|
});
|
|
@@ -12798,7 +12849,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12798
12849
|
previewMethod: "html",
|
|
12799
12850
|
path,
|
|
12800
12851
|
body: Buffer.from(code),
|
|
12801
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
|
|
12852
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : void 0
|
|
12802
12853
|
};
|
|
12803
12854
|
}
|
|
12804
12855
|
}
|
|
@@ -12824,7 +12875,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12824
12875
|
}
|
|
12825
12876
|
case ".bundle":
|
|
12826
12877
|
case ".min": {
|
|
12827
|
-
const code = await inflateJSX(file.filePath, {
|
|
12878
|
+
const code = inflateJSXOptions.noMinify ? (0, import_node_fs11.readFileSync)(file.filePath).toString() : await inflateJSX(file.filePath, {
|
|
12828
12879
|
// embemedJSX: false,
|
|
12829
12880
|
minify: file.subExt === ".min" ? true : false,
|
|
12830
12881
|
useExport: true,
|
|
@@ -12841,8 +12892,8 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12841
12892
|
service,
|
|
12842
12893
|
previewMethod: "html"
|
|
12843
12894
|
};
|
|
12844
|
-
if (inflateDir) {
|
|
12845
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
|
|
12895
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12896
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
12846
12897
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12847
12898
|
recursive: true
|
|
12848
12899
|
});
|
|
@@ -12856,7 +12907,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12856
12907
|
previewMethod: "html",
|
|
12857
12908
|
path,
|
|
12858
12909
|
body: Buffer.from(code),
|
|
12859
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
|
|
12910
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : void 0
|
|
12860
12911
|
};
|
|
12861
12912
|
}
|
|
12862
12913
|
}
|
|
@@ -12891,8 +12942,8 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12891
12942
|
filePath: file.filePath,
|
|
12892
12943
|
previewMethod: "html"
|
|
12893
12944
|
};
|
|
12894
|
-
if (inflateDir) {
|
|
12895
|
-
const inflatePath = (0, import_node_path12.join)(inflateDir, service, "static", path);
|
|
12945
|
+
if (inflateDir && (inflateJSXOptions.inflateOnlyAssets || inflateJSXOptions.inflateOnlyAssets === void 0)) {
|
|
12946
|
+
const inflatePath = (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path);
|
|
12896
12947
|
await mkdirASync((0, import_node_path12.dirname)(inflatePath), {
|
|
12897
12948
|
recursive: true
|
|
12898
12949
|
});
|
|
@@ -12906,7 +12957,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12906
12957
|
previewMethod: "html",
|
|
12907
12958
|
path,
|
|
12908
12959
|
body: Buffer.from(code),
|
|
12909
|
-
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, service, "static", path) : void 0
|
|
12960
|
+
inflatePath: inflateDir ? (0, import_node_path12.join)(inflateDir, !inflateJSXOptions.inflateFlat ? service : "", "static", path) : void 0
|
|
12910
12961
|
};
|
|
12911
12962
|
}
|
|
12912
12963
|
}
|
|
@@ -12923,7 +12974,7 @@ async function createRouterFromDirectory(server, hotreload, service, logger, dir
|
|
|
12923
12974
|
}
|
|
12924
12975
|
}
|
|
12925
12976
|
}
|
|
12926
|
-
await createStaticRoute(service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
|
|
12977
|
+
await createStaticRoute(inflateJSXOptions, service, logger, router, dir, file, inflateDir, routeFileMap, staticFileMap);
|
|
12927
12978
|
return resolve24();
|
|
12928
12979
|
}
|
|
12929
12980
|
} catch (e) {
|
|
@@ -12971,13 +13022,11 @@ function scanFiles(path, ret = []) {
|
|
|
12971
13022
|
}
|
|
12972
13023
|
function getHTML(hotreload, req, res, url, basePath, out) {
|
|
12973
13024
|
let HTML = `<!DOCTYPE html>
|
|
12974
|
-
${
|
|
13025
|
+
${hotreload ? `${getHotReloadScript()}
|
|
13026
|
+
` : ""}${jsx2HTML(out, createNodeRuntime({
|
|
12975
13027
|
url,
|
|
12976
13028
|
basePath
|
|
12977
13029
|
}))}`;
|
|
12978
|
-
if (hotreload) {
|
|
12979
|
-
HTML += getHotReloadScript();
|
|
12980
|
-
}
|
|
12981
13030
|
return HTML;
|
|
12982
13031
|
}
|
|
12983
13032
|
async function getJSON(req, res, url, basePath, out) {
|
|
@@ -12989,12 +13038,12 @@ async function getJSON(req, res, url, basePath, out) {
|
|
|
12989
13038
|
var import_node_path13 = require("node:path");
|
|
12990
13039
|
var import_node_process9 = require("node:process");
|
|
12991
13040
|
var import_node_fs12 = require("node:fs");
|
|
12992
|
-
async function inflateWSConfig(logger, servicePath, service, wsConfigList, inflateDir, errors) {
|
|
13041
|
+
async function inflateWSConfig(logger, servicePath, service, wsConfigList, inflateDir, errors, options) {
|
|
12993
13042
|
const wsPath = getWSConfigPath(servicePath);
|
|
12994
13043
|
if (wsPath) {
|
|
12995
13044
|
try {
|
|
12996
13045
|
logger.debug("importing websocket socket for service [%s]", service);
|
|
12997
|
-
const wsConfig = await importWSConfigModule(wsPath, logger);
|
|
13046
|
+
const wsConfig = await importWSConfigModule(wsPath, options, logger);
|
|
12998
13047
|
if (wsConfig && wsConfigList.filter((c) => c.path === wsConfig.path).length > 0) {
|
|
12999
13048
|
throw new Error(`ws path [${wsConfig.path}] already defined! from [${wsPath}]`);
|
|
13000
13049
|
} else if (wsConfigList) {
|
|
@@ -13269,11 +13318,11 @@ function writeFile2(logger, path, buffer) {
|
|
|
13269
13318
|
var import_node_path15 = require("node:path");
|
|
13270
13319
|
var import_node_fs14 = require("node:fs");
|
|
13271
13320
|
var import_node_process11 = require("node:process");
|
|
13272
|
-
async function setupLogConfig(logger, servicePath, service, logConfigMap, inflateDir, errors) {
|
|
13321
|
+
async function setupLogConfig(logger, servicePath, service, logConfigMap, inflateDir, options, errors) {
|
|
13273
13322
|
const logPath = getLogConfigPath(servicePath);
|
|
13274
13323
|
if (logPath) {
|
|
13275
13324
|
try {
|
|
13276
|
-
const logConfig = await importLogConfigModule(logPath, logger);
|
|
13325
|
+
const logConfig = await importLogConfigModule(logPath, options, logger);
|
|
13277
13326
|
logConfigMap[service] = logConfig;
|
|
13278
13327
|
if (inflateDir) {
|
|
13279
13328
|
const inflatePath = (0, import_node_path15.resolve)(inflateDir, service, "log.cjs");
|
|
@@ -13569,11 +13618,11 @@ async function getDocOutput(router, fileMap, generateDocAll, generateDocType) {
|
|
|
13569
13618
|
}
|
|
13570
13619
|
|
|
13571
13620
|
// src/inflate/setup.doc.ts
|
|
13572
|
-
async function setupDoc(logger, servicePath, service, mainRouter, fileMap, staticFileMap, inflateDir, errors) {
|
|
13621
|
+
async function setupDoc(logger, servicePath, service, mainRouter, fileMap, staticFileMap, inflateDir, errors, options, inflateFlat) {
|
|
13573
13622
|
const docPath = getDocConfigPath(servicePath);
|
|
13574
13623
|
if (docPath) {
|
|
13575
13624
|
try {
|
|
13576
|
-
const docModule = await importDocConfigModule(docPath, logger);
|
|
13625
|
+
const docModule = await importDocConfigModule(docPath, options, logger);
|
|
13577
13626
|
logger.debug("setting up error handling from [%s]", (0, import_node_path16.join)(service, (0, import_node_path16.basename)(docPath)));
|
|
13578
13627
|
if (docModule && docModule.publish) {
|
|
13579
13628
|
const paths = Object.keys(docModule.publish);
|
|
@@ -13603,7 +13652,7 @@ async function setupDoc(logger, servicePath, service, mainRouter, fileMap, stati
|
|
|
13603
13652
|
}
|
|
13604
13653
|
});
|
|
13605
13654
|
if (inflateDir) {
|
|
13606
|
-
const inflatePath = (0, import_node_path16.join)(inflateDir, service, "static", path);
|
|
13655
|
+
const inflatePath = (0, import_node_path16.join)(inflateDir, !inflateFlat ? service : "", "static", path);
|
|
13607
13656
|
(0, import_node_fs15.mkdirSync)((0, import_node_path16.dirname)(inflatePath), {
|
|
13608
13657
|
recursive: true
|
|
13609
13658
|
});
|
|
@@ -13626,7 +13675,7 @@ async function setupDoc(logger, servicePath, service, mainRouter, fileMap, stati
|
|
|
13626
13675
|
method: "GET",
|
|
13627
13676
|
path,
|
|
13628
13677
|
body: Buffer.from(body),
|
|
13629
|
-
inflatePath: inflateDir ? (0, import_node_path16.join)(inflateDir, service, "static", path) : void 0
|
|
13678
|
+
inflatePath: inflateDir ? (0, import_node_path16.join)(inflateDir, !inflateFlat ? service : "", "static", path) : void 0
|
|
13630
13679
|
};
|
|
13631
13680
|
}
|
|
13632
13681
|
}
|
|
@@ -13645,7 +13694,7 @@ async function setupDoc(logger, servicePath, service, mainRouter, fileMap, stati
|
|
|
13645
13694
|
}
|
|
13646
13695
|
|
|
13647
13696
|
// src/inflate/inflate.ts
|
|
13648
|
-
async function inflateApp({ inflateParallel, serverInterface, logger, hotreload, services, inflateDir, inflateSea, port }) {
|
|
13697
|
+
async function inflateApp({ inflateParallel, serverInterface, logger, hotreload, services, inflateDir, inflateSea, port, noBuild, noMinify, inflateOnlyAssets, inflateFlat }) {
|
|
13649
13698
|
logger.trace("inflateApp");
|
|
13650
13699
|
const errors = [];
|
|
13651
13700
|
let routeFileMap = {};
|
|
@@ -13656,14 +13705,14 @@ async function inflateApp({ inflateParallel, serverInterface, logger, hotreload,
|
|
|
13656
13705
|
const serviceRouteFileMap = {};
|
|
13657
13706
|
const serviceStaticFileMap = inflateSea ? {} : null;
|
|
13658
13707
|
const servicePath = getServicePath(service);
|
|
13659
|
-
await setupLogConfig(logger, servicePath, service, logConfigMap, inflateSea ? inflateDir : false, errors);
|
|
13660
|
-
router.use(await setupHTTPRouter(serverInterface, logger, hotreload ? hotreload : false, servicePath, service, serviceRouteFileMap, serviceStaticFileMap, inflateDir, inflateSea, errors, inflateParallel));
|
|
13708
|
+
await setupLogConfig(logger, servicePath, service, logConfigMap, inflateSea ? inflateDir : false, { noBuild }, errors);
|
|
13709
|
+
router.use(await setupHTTPRouter({ noBuild }, { noMinify, inflateOnlyAssets, inflateFlat }, serverInterface, logger, hotreload ? hotreload : false, servicePath, service, serviceRouteFileMap, serviceStaticFileMap, inflateDir, inflateSea, errors, inflateParallel));
|
|
13661
13710
|
routeFileMap = {
|
|
13662
13711
|
...routeFileMap,
|
|
13663
13712
|
...serviceRouteFileMap
|
|
13664
13713
|
};
|
|
13665
|
-
await setupDoc(logger, servicePath, service, router, routeFileMap, serviceStaticFileMap, inflateDir, errors);
|
|
13666
|
-
await inflateWSConfig(logger, servicePath, service, wsConfigList, inflateSea ? inflateDir : void 0, errors);
|
|
13714
|
+
await setupDoc(logger, servicePath, service, router, routeFileMap, serviceStaticFileMap, inflateDir, errors, { noBuild }, inflateFlat);
|
|
13715
|
+
await inflateWSConfig(logger, servicePath, service, wsConfigList, inflateSea ? inflateDir : void 0, errors, { noBuild });
|
|
13667
13716
|
if (inflateDir && inflateSea) {
|
|
13668
13717
|
await inflateServiceForSea(logger, inflateDir, service, servicePath, serviceRouteFileMap, serviceStaticFileMap);
|
|
13669
13718
|
}
|
|
@@ -13678,11 +13727,11 @@ async function inflateApp({ inflateParallel, serverInterface, logger, hotreload,
|
|
|
13678
13727
|
var import_node_fs16 = require("node:fs");
|
|
13679
13728
|
var import_node_path17 = require("node:path");
|
|
13680
13729
|
var import_node_process13 = require("node:process");
|
|
13681
|
-
async function setupServerConfig(logger, servicePath, service, serverConfigMap, inflateDir, errors) {
|
|
13730
|
+
async function setupServerConfig(logger, servicePath, service, serverConfigMap, inflateDir, errors, options) {
|
|
13682
13731
|
const serverPath = getServerConfigPath(servicePath);
|
|
13683
13732
|
if (serverPath) {
|
|
13684
13733
|
try {
|
|
13685
|
-
const serverConfig = await importServerConfigModule(serverPath, logger);
|
|
13734
|
+
const serverConfig = await importServerConfigModule(serverPath, options, logger);
|
|
13686
13735
|
serverConfigMap[service] = serverConfig;
|
|
13687
13736
|
if (inflateDir) {
|
|
13688
13737
|
const inflatePath = (0, import_node_path17.resolve)(inflateDir, service, "server.cjs");
|
|
@@ -13721,17 +13770,18 @@ var ws_default = {
|
|
|
13721
13770
|
const cache2 = admin ? admin.getCache() : req.server.cache;
|
|
13722
13771
|
const KEY = cache2.get("AUTH_KEY");
|
|
13723
13772
|
const cookieToken = req.cookies["auth"];
|
|
13724
|
-
return cookieToken === KEY ? true : false;
|
|
13773
|
+
return cookieToken && KEY && cookieToken === KEY ? true : false;
|
|
13725
13774
|
}
|
|
13726
13775
|
};
|
|
13727
13776
|
|
|
13728
13777
|
// editor/server.ts
|
|
13729
|
-
var
|
|
13778
|
+
var import_node_crypto5 = require("node:crypto");
|
|
13730
13779
|
init_constants();
|
|
13731
13780
|
var import_node_fs17 = require("node:fs");
|
|
13732
13781
|
var import_node_path18 = require("node:path");
|
|
13733
13782
|
|
|
13734
13783
|
// editor/auth.ts
|
|
13784
|
+
var import_node_crypto4 = require("node:crypto");
|
|
13735
13785
|
var ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
|
|
13736
13786
|
var ADMIN_EDITOR_AUTH_QUERY = "key";
|
|
13737
13787
|
var ADMIN_EDITOR_AUTH_COOKIE = ADMIN_EDITOR_AUTH_KEY;
|
|
@@ -13750,7 +13800,7 @@ var auth_default = {
|
|
|
13750
13800
|
const queryToken = args.req.query[ADMIN_EDITOR_AUTH_QUERY];
|
|
13751
13801
|
const cookieToken = args.req.cookies[ADMIN_EDITOR_AUTH_COOKIE];
|
|
13752
13802
|
if (queryToken) {
|
|
13753
|
-
if (queryToken === KEY) {
|
|
13803
|
+
if (typeof queryToken === "string" && (0, import_node_crypto4.timingSafeEqual)(Buffer.from(queryToken), Buffer.from(KEY))) {
|
|
13754
13804
|
args.res.setCookie(ADMIN_EDITOR_AUTH_COOKIE, KEY, {
|
|
13755
13805
|
expires: new Date(Date.now() + 1e3 * 60 * 60 * 24 * 31 * 12 * 500),
|
|
13756
13806
|
httpOnly: true,
|
|
@@ -13784,7 +13834,7 @@ var server_default = {
|
|
|
13784
13834
|
serverInterface.logger.warn("loading static ADMIN_KEY from [%s]", (0, import_node_path18.relative)(process.cwd(), adminKEYPath));
|
|
13785
13835
|
cache2.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_fs17.readFileSync)(adminKEYPath).toString().trim());
|
|
13786
13836
|
} else {
|
|
13787
|
-
cache2.set(ADMIN_EDITOR_AUTH_KEY, (0,
|
|
13837
|
+
cache2.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_crypto5.randomUUID)());
|
|
13788
13838
|
}
|
|
13789
13839
|
}
|
|
13790
13840
|
}
|
|
@@ -14022,14 +14072,14 @@ function setupExitHandlers(app) {
|
|
|
14022
14072
|
var import_node_path28 = require("node:path");
|
|
14023
14073
|
var import_node_fs25 = require("node:fs");
|
|
14024
14074
|
var import_node_process15 = require("node:process");
|
|
14025
|
-
async function inflateDBConfig(logger, service, dbConfigList, inflateDir, errors) {
|
|
14075
|
+
async function inflateDBConfig(logger, service, dbConfigList, inflateDir, options, errors) {
|
|
14026
14076
|
const servicePath = getServicePath(service);
|
|
14027
14077
|
const dbConfigPath = getDBConfigPath(servicePath);
|
|
14028
14078
|
if (dbConfigPath) {
|
|
14029
14079
|
try {
|
|
14030
|
-
const config = await importDBConfigModule(dbConfigPath, logger);
|
|
14080
|
+
const config = await importDBConfigModule(dbConfigPath, options, logger);
|
|
14031
14081
|
if (config && dbConfigList && dbConfigList.filter((c) => c.name === config.name).length > 0) {
|
|
14032
|
-
throw new Error(`
|
|
14082
|
+
throw new Error(`db name [${config.name}] already defined! error from [${dbConfigPath}]`);
|
|
14033
14083
|
} else if (config) {
|
|
14034
14084
|
if (dbConfigList) {
|
|
14035
14085
|
dbConfigList.push(config);
|
|
@@ -14064,7 +14114,7 @@ async function inflateDBConfig(logger, service, dbConfigList, inflateDir, errors
|
|
|
14064
14114
|
}
|
|
14065
14115
|
return false;
|
|
14066
14116
|
}
|
|
14067
|
-
async function inflateDBMigrations(logger, service, dbName, inflateDir, errors) {
|
|
14117
|
+
async function inflateDBMigrations(logger, service, dbName, inflateDir, options, errors) {
|
|
14068
14118
|
const servicePath = getServicePath(service);
|
|
14069
14119
|
const migrationsFolderPath = getMigrationsPath(servicePath);
|
|
14070
14120
|
if (migrationsFolderPath) {
|
|
@@ -14074,7 +14124,7 @@ async function inflateDBMigrations(logger, service, dbName, inflateDir, errors)
|
|
|
14074
14124
|
for (const migrationName of serviceMigrations) {
|
|
14075
14125
|
const migrationPath = (0, import_node_path28.resolve)(migrationsFolderPath, migrationName);
|
|
14076
14126
|
try {
|
|
14077
|
-
const migrationModule = await importMigrationModule(migrationPath);
|
|
14127
|
+
const migrationModule = await importMigrationModule(migrationPath, options, logger);
|
|
14078
14128
|
migrationModules.push({
|
|
14079
14129
|
name: migrationName,
|
|
14080
14130
|
service,
|
|
@@ -14160,6 +14210,17 @@ function uint32be(value) {
|
|
|
14160
14210
|
writeUInt32BE(buf, value);
|
|
14161
14211
|
return buf;
|
|
14162
14212
|
}
|
|
14213
|
+
function encode(string) {
|
|
14214
|
+
const bytes = new Uint8Array(string.length);
|
|
14215
|
+
for (let i = 0; i < string.length; i++) {
|
|
14216
|
+
const code = string.charCodeAt(i);
|
|
14217
|
+
if (code > 127) {
|
|
14218
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
14219
|
+
}
|
|
14220
|
+
bytes[i] = code;
|
|
14221
|
+
}
|
|
14222
|
+
return bytes;
|
|
14223
|
+
}
|
|
14163
14224
|
|
|
14164
14225
|
// node_modules/jose/dist/webapi/lib/base64.js
|
|
14165
14226
|
function encodeBase64(input) {
|
|
@@ -14196,14 +14257,14 @@ function decode(input) {
|
|
|
14196
14257
|
if (encoded instanceof Uint8Array) {
|
|
14197
14258
|
encoded = decoder.decode(encoded);
|
|
14198
14259
|
}
|
|
14199
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/")
|
|
14260
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
14200
14261
|
try {
|
|
14201
14262
|
return decodeBase64(encoded);
|
|
14202
14263
|
} catch {
|
|
14203
14264
|
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
14204
14265
|
}
|
|
14205
14266
|
}
|
|
14206
|
-
function
|
|
14267
|
+
function encode2(input) {
|
|
14207
14268
|
let unencoded = input;
|
|
14208
14269
|
if (typeof unencoded === "string") {
|
|
14209
14270
|
unencoded = encoder.encode(unencoded);
|
|
@@ -14214,122 +14275,17 @@ function encode(input) {
|
|
|
14214
14275
|
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
14215
14276
|
}
|
|
14216
14277
|
|
|
14217
|
-
// node_modules/jose/dist/webapi/util/errors.js
|
|
14218
|
-
var JOSEError = class extends Error {
|
|
14219
|
-
static code = "ERR_JOSE_GENERIC";
|
|
14220
|
-
code = "ERR_JOSE_GENERIC";
|
|
14221
|
-
constructor(message2, options) {
|
|
14222
|
-
super(message2, options);
|
|
14223
|
-
this.name = this.constructor.name;
|
|
14224
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
14225
|
-
}
|
|
14226
|
-
};
|
|
14227
|
-
var JWTClaimValidationFailed = class extends JOSEError {
|
|
14228
|
-
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
14229
|
-
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
14230
|
-
claim;
|
|
14231
|
-
reason;
|
|
14232
|
-
payload;
|
|
14233
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
14234
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
14235
|
-
this.claim = claim;
|
|
14236
|
-
this.reason = reason;
|
|
14237
|
-
this.payload = payload;
|
|
14238
|
-
}
|
|
14239
|
-
};
|
|
14240
|
-
var JWTExpired = class extends JOSEError {
|
|
14241
|
-
static code = "ERR_JWT_EXPIRED";
|
|
14242
|
-
code = "ERR_JWT_EXPIRED";
|
|
14243
|
-
claim;
|
|
14244
|
-
reason;
|
|
14245
|
-
payload;
|
|
14246
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
14247
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
14248
|
-
this.claim = claim;
|
|
14249
|
-
this.reason = reason;
|
|
14250
|
-
this.payload = payload;
|
|
14251
|
-
}
|
|
14252
|
-
};
|
|
14253
|
-
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
14254
|
-
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
14255
|
-
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
14256
|
-
};
|
|
14257
|
-
var JOSENotSupported = class extends JOSEError {
|
|
14258
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
14259
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
14260
|
-
};
|
|
14261
|
-
var JWEDecryptionFailed = class extends JOSEError {
|
|
14262
|
-
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
14263
|
-
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
14264
|
-
constructor(message2 = "decryption operation failed", options) {
|
|
14265
|
-
super(message2, options);
|
|
14266
|
-
}
|
|
14267
|
-
};
|
|
14268
|
-
var JWEInvalid = class extends JOSEError {
|
|
14269
|
-
static code = "ERR_JWE_INVALID";
|
|
14270
|
-
code = "ERR_JWE_INVALID";
|
|
14271
|
-
};
|
|
14272
|
-
var JWSInvalid = class extends JOSEError {
|
|
14273
|
-
static code = "ERR_JWS_INVALID";
|
|
14274
|
-
code = "ERR_JWS_INVALID";
|
|
14275
|
-
};
|
|
14276
|
-
var JWTInvalid = class extends JOSEError {
|
|
14277
|
-
static code = "ERR_JWT_INVALID";
|
|
14278
|
-
code = "ERR_JWT_INVALID";
|
|
14279
|
-
};
|
|
14280
|
-
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
14281
|
-
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
14282
|
-
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
14283
|
-
constructor(message2 = "signature verification failed", options) {
|
|
14284
|
-
super(message2, options);
|
|
14285
|
-
}
|
|
14286
|
-
};
|
|
14287
|
-
|
|
14288
|
-
// node_modules/jose/dist/webapi/lib/iv.js
|
|
14289
|
-
function bitLength(alg) {
|
|
14290
|
-
switch (alg) {
|
|
14291
|
-
case "A128GCM":
|
|
14292
|
-
case "A128GCMKW":
|
|
14293
|
-
case "A192GCM":
|
|
14294
|
-
case "A192GCMKW":
|
|
14295
|
-
case "A256GCM":
|
|
14296
|
-
case "A256GCMKW":
|
|
14297
|
-
return 96;
|
|
14298
|
-
case "A128CBC-HS256":
|
|
14299
|
-
case "A192CBC-HS384":
|
|
14300
|
-
case "A256CBC-HS512":
|
|
14301
|
-
return 128;
|
|
14302
|
-
default:
|
|
14303
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
14304
|
-
}
|
|
14305
|
-
}
|
|
14306
|
-
var iv_default = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
|
|
14307
|
-
|
|
14308
|
-
// node_modules/jose/dist/webapi/lib/check_iv_length.js
|
|
14309
|
-
var check_iv_length_default = (enc, iv) => {
|
|
14310
|
-
if (iv.length << 3 !== bitLength(enc)) {
|
|
14311
|
-
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
14312
|
-
}
|
|
14313
|
-
};
|
|
14314
|
-
|
|
14315
|
-
// node_modules/jose/dist/webapi/lib/check_cek_length.js
|
|
14316
|
-
var check_cek_length_default = (cek, expected) => {
|
|
14317
|
-
const actual = cek.byteLength << 3;
|
|
14318
|
-
if (actual !== expected) {
|
|
14319
|
-
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
14320
|
-
}
|
|
14321
|
-
};
|
|
14322
|
-
|
|
14323
14278
|
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
14324
|
-
|
|
14325
|
-
|
|
14326
|
-
}
|
|
14327
|
-
function isAlgorithm(algorithm, name) {
|
|
14328
|
-
return algorithm.name === name;
|
|
14329
|
-
}
|
|
14279
|
+
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
14280
|
+
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
14330
14281
|
function getHashLength(hash) {
|
|
14331
14282
|
return parseInt(hash.name.slice(4), 10);
|
|
14332
14283
|
}
|
|
14284
|
+
function checkHashLength(algorithm, expected) {
|
|
14285
|
+
const actual = getHashLength(algorithm.hash);
|
|
14286
|
+
if (actual !== expected)
|
|
14287
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
14288
|
+
}
|
|
14333
14289
|
function getNamedCurve(alg) {
|
|
14334
14290
|
switch (alg) {
|
|
14335
14291
|
case "ES256":
|
|
@@ -14354,10 +14310,7 @@ function checkSigCryptoKey(key, alg, usage2) {
|
|
|
14354
14310
|
case "HS512": {
|
|
14355
14311
|
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
14356
14312
|
throw unusable("HMAC");
|
|
14357
|
-
|
|
14358
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
14359
|
-
if (actual !== expected)
|
|
14360
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
14313
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
14361
14314
|
break;
|
|
14362
14315
|
}
|
|
14363
14316
|
case "RS256":
|
|
@@ -14365,10 +14318,7 @@ function checkSigCryptoKey(key, alg, usage2) {
|
|
|
14365
14318
|
case "RS512": {
|
|
14366
14319
|
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
14367
14320
|
throw unusable("RSASSA-PKCS1-v1_5");
|
|
14368
|
-
|
|
14369
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
14370
|
-
if (actual !== expected)
|
|
14371
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
14321
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
14372
14322
|
break;
|
|
14373
14323
|
}
|
|
14374
14324
|
case "PS256":
|
|
@@ -14376,10 +14326,7 @@ function checkSigCryptoKey(key, alg, usage2) {
|
|
|
14376
14326
|
case "PS512": {
|
|
14377
14327
|
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
14378
14328
|
throw unusable("RSA-PSS");
|
|
14379
|
-
|
|
14380
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
14381
|
-
if (actual !== expected)
|
|
14382
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
14329
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
14383
14330
|
break;
|
|
14384
14331
|
}
|
|
14385
14332
|
case "Ed25519":
|
|
@@ -14457,10 +14404,7 @@ function checkEncCryptoKey(key, alg, usage2) {
|
|
|
14457
14404
|
case "RSA-OAEP-512": {
|
|
14458
14405
|
if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
|
|
14459
14406
|
throw unusable("RSA-OAEP");
|
|
14460
|
-
|
|
14461
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
14462
|
-
if (actual !== expected)
|
|
14463
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
14407
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(9), 10) || 1);
|
|
14464
14408
|
break;
|
|
14465
14409
|
}
|
|
14466
14410
|
default:
|
|
@@ -14491,63 +14435,196 @@ function message(msg, actual, ...types) {
|
|
|
14491
14435
|
}
|
|
14492
14436
|
return msg;
|
|
14493
14437
|
}
|
|
14494
|
-
var
|
|
14495
|
-
|
|
14496
|
-
};
|
|
14497
|
-
function withAlg(alg, actual, ...types) {
|
|
14498
|
-
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
14499
|
-
}
|
|
14438
|
+
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
14439
|
+
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
14500
14440
|
|
|
14501
|
-
// node_modules/jose/dist/webapi/
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14441
|
+
// node_modules/jose/dist/webapi/util/errors.js
|
|
14442
|
+
var JOSEError = class extends Error {
|
|
14443
|
+
static code = "ERR_JOSE_GENERIC";
|
|
14444
|
+
code = "ERR_JOSE_GENERIC";
|
|
14445
|
+
constructor(message2, options) {
|
|
14446
|
+
super(message2, options);
|
|
14447
|
+
this.name = this.constructor.name;
|
|
14448
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
14505
14449
|
}
|
|
14506
|
-
}
|
|
14507
|
-
function isCryptoKey(key) {
|
|
14508
|
-
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
14509
|
-
}
|
|
14510
|
-
function isKeyObject(key) {
|
|
14511
|
-
return key?.[Symbol.toStringTag] === "KeyObject";
|
|
14512
|
-
}
|
|
14513
|
-
var is_key_like_default = (key) => {
|
|
14514
|
-
return isCryptoKey(key) || isKeyObject(key);
|
|
14515
14450
|
};
|
|
14516
|
-
|
|
14517
|
-
|
|
14518
|
-
|
|
14519
|
-
|
|
14520
|
-
|
|
14451
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
14452
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
14453
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
14454
|
+
claim;
|
|
14455
|
+
reason;
|
|
14456
|
+
payload;
|
|
14457
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
14458
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
14459
|
+
this.claim = claim;
|
|
14460
|
+
this.reason = reason;
|
|
14461
|
+
this.payload = payload;
|
|
14521
14462
|
}
|
|
14522
|
-
|
|
14523
|
-
|
|
14463
|
+
};
|
|
14464
|
+
var JWTExpired = class extends JOSEError {
|
|
14465
|
+
static code = "ERR_JWT_EXPIRED";
|
|
14466
|
+
code = "ERR_JWT_EXPIRED";
|
|
14467
|
+
claim;
|
|
14468
|
+
reason;
|
|
14469
|
+
payload;
|
|
14470
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
14471
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
14472
|
+
this.claim = claim;
|
|
14473
|
+
this.reason = reason;
|
|
14474
|
+
this.payload = payload;
|
|
14524
14475
|
}
|
|
14525
|
-
|
|
14526
|
-
|
|
14527
|
-
|
|
14528
|
-
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
14476
|
+
};
|
|
14477
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
14478
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
14479
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
14480
|
+
};
|
|
14481
|
+
var JOSENotSupported = class extends JOSEError {
|
|
14482
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
14483
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
14484
|
+
};
|
|
14485
|
+
var JWEDecryptionFailed = class extends JOSEError {
|
|
14486
|
+
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
14487
|
+
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
14488
|
+
constructor(message2 = "decryption operation failed", options) {
|
|
14489
|
+
super(message2, options);
|
|
14490
|
+
}
|
|
14491
|
+
};
|
|
14492
|
+
var JWEInvalid = class extends JOSEError {
|
|
14493
|
+
static code = "ERR_JWE_INVALID";
|
|
14494
|
+
code = "ERR_JWE_INVALID";
|
|
14495
|
+
};
|
|
14496
|
+
var JWSInvalid = class extends JOSEError {
|
|
14497
|
+
static code = "ERR_JWS_INVALID";
|
|
14498
|
+
code = "ERR_JWS_INVALID";
|
|
14499
|
+
};
|
|
14500
|
+
var JWTInvalid = class extends JOSEError {
|
|
14501
|
+
static code = "ERR_JWT_INVALID";
|
|
14502
|
+
code = "ERR_JWT_INVALID";
|
|
14503
|
+
};
|
|
14504
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
14505
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
14506
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
14507
|
+
constructor(message2 = "signature verification failed", options) {
|
|
14508
|
+
super(message2, options);
|
|
14509
|
+
}
|
|
14510
|
+
};
|
|
14511
|
+
|
|
14512
|
+
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
14513
|
+
function assertCryptoKey(key) {
|
|
14514
|
+
if (!isCryptoKey(key)) {
|
|
14515
|
+
throw new Error("CryptoKey instance expected");
|
|
14533
14516
|
}
|
|
14534
|
-
return out === 0;
|
|
14535
14517
|
}
|
|
14536
|
-
|
|
14518
|
+
var isCryptoKey = (key) => {
|
|
14519
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
14520
|
+
return true;
|
|
14521
|
+
try {
|
|
14522
|
+
return key instanceof CryptoKey;
|
|
14523
|
+
} catch {
|
|
14524
|
+
return false;
|
|
14525
|
+
}
|
|
14526
|
+
};
|
|
14527
|
+
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
14528
|
+
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
14529
|
+
|
|
14530
|
+
// node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
14531
|
+
function cekLength(alg) {
|
|
14532
|
+
switch (alg) {
|
|
14533
|
+
case "A128GCM":
|
|
14534
|
+
return 128;
|
|
14535
|
+
case "A192GCM":
|
|
14536
|
+
return 192;
|
|
14537
|
+
case "A256GCM":
|
|
14538
|
+
case "A128CBC-HS256":
|
|
14539
|
+
return 256;
|
|
14540
|
+
case "A192CBC-HS384":
|
|
14541
|
+
return 384;
|
|
14542
|
+
case "A256CBC-HS512":
|
|
14543
|
+
return 512;
|
|
14544
|
+
default:
|
|
14545
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
14546
|
+
}
|
|
14547
|
+
}
|
|
14548
|
+
var generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
|
|
14549
|
+
function checkCekLength(cek, expected) {
|
|
14550
|
+
const actual = cek.byteLength << 3;
|
|
14551
|
+
if (actual !== expected) {
|
|
14552
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
14553
|
+
}
|
|
14554
|
+
}
|
|
14555
|
+
function ivBitLength(alg) {
|
|
14556
|
+
switch (alg) {
|
|
14557
|
+
case "A128GCM":
|
|
14558
|
+
case "A128GCMKW":
|
|
14559
|
+
case "A192GCM":
|
|
14560
|
+
case "A192GCMKW":
|
|
14561
|
+
case "A256GCM":
|
|
14562
|
+
case "A256GCMKW":
|
|
14563
|
+
return 96;
|
|
14564
|
+
case "A128CBC-HS256":
|
|
14565
|
+
case "A192CBC-HS384":
|
|
14566
|
+
case "A256CBC-HS512":
|
|
14567
|
+
return 128;
|
|
14568
|
+
default:
|
|
14569
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
14570
|
+
}
|
|
14571
|
+
}
|
|
14572
|
+
var generateIv = (alg) => crypto.getRandomValues(new Uint8Array(ivBitLength(alg) >> 3));
|
|
14573
|
+
function checkIvLength(enc, iv) {
|
|
14574
|
+
if (iv.length << 3 !== ivBitLength(enc)) {
|
|
14575
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
14576
|
+
}
|
|
14577
|
+
}
|
|
14578
|
+
async function cbcKeySetup(enc, cek, usage2) {
|
|
14537
14579
|
if (!(cek instanceof Uint8Array)) {
|
|
14538
|
-
throw new TypeError(
|
|
14580
|
+
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
14539
14581
|
}
|
|
14540
14582
|
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
14541
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [
|
|
14583
|
+
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [usage2]);
|
|
14542
14584
|
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
14543
14585
|
hash: `SHA-${keySize << 1}`,
|
|
14544
14586
|
name: "HMAC"
|
|
14545
14587
|
}, false, ["sign"]);
|
|
14588
|
+
return { encKey, macKey, keySize };
|
|
14589
|
+
}
|
|
14590
|
+
async function cbcHmacTag(macKey, macData, keySize) {
|
|
14591
|
+
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
14592
|
+
}
|
|
14593
|
+
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
14594
|
+
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, "encrypt");
|
|
14595
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
14596
|
+
iv,
|
|
14597
|
+
name: "AES-CBC"
|
|
14598
|
+
}, encKey, plaintext));
|
|
14599
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
14600
|
+
const tag2 = await cbcHmacTag(macKey, macData, keySize);
|
|
14601
|
+
return { ciphertext, tag: tag2, iv };
|
|
14602
|
+
}
|
|
14603
|
+
async function timingSafeEqual2(a, b) {
|
|
14604
|
+
if (!(a instanceof Uint8Array)) {
|
|
14605
|
+
throw new TypeError("First argument must be a buffer");
|
|
14606
|
+
}
|
|
14607
|
+
if (!(b instanceof Uint8Array)) {
|
|
14608
|
+
throw new TypeError("Second argument must be a buffer");
|
|
14609
|
+
}
|
|
14610
|
+
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
14611
|
+
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
14612
|
+
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
14613
|
+
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
14614
|
+
let out = 0;
|
|
14615
|
+
let i = -1;
|
|
14616
|
+
while (++i < 32) {
|
|
14617
|
+
out |= aHmac[i] ^ bHmac[i];
|
|
14618
|
+
}
|
|
14619
|
+
return out === 0;
|
|
14620
|
+
}
|
|
14621
|
+
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
14622
|
+
const { encKey, macKey, keySize } = await cbcKeySetup(enc, cek, "decrypt");
|
|
14546
14623
|
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
14547
|
-
const expectedTag =
|
|
14624
|
+
const expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
14548
14625
|
let macCheckPassed;
|
|
14549
14626
|
try {
|
|
14550
|
-
macCheckPassed = await
|
|
14627
|
+
macCheckPassed = await timingSafeEqual2(tag2, expectedTag);
|
|
14551
14628
|
} catch {
|
|
14552
14629
|
}
|
|
14553
14630
|
if (!macCheckPassed) {
|
|
@@ -14563,6 +14640,24 @@ async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
|
14563
14640
|
}
|
|
14564
14641
|
return plaintext;
|
|
14565
14642
|
}
|
|
14643
|
+
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
14644
|
+
let encKey;
|
|
14645
|
+
if (cek instanceof Uint8Array) {
|
|
14646
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
14647
|
+
} else {
|
|
14648
|
+
checkEncCryptoKey(cek, enc, "encrypt");
|
|
14649
|
+
encKey = cek;
|
|
14650
|
+
}
|
|
14651
|
+
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
14652
|
+
additionalData: aad,
|
|
14653
|
+
iv,
|
|
14654
|
+
name: "AES-GCM",
|
|
14655
|
+
tagLength: 128
|
|
14656
|
+
}, encKey, plaintext));
|
|
14657
|
+
const tag2 = encrypted.slice(-16);
|
|
14658
|
+
const ciphertext = encrypted.slice(0, -16);
|
|
14659
|
+
return { ciphertext, tag: tag2, iv };
|
|
14660
|
+
}
|
|
14566
14661
|
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
14567
14662
|
let encKey;
|
|
14568
14663
|
if (cek instanceof Uint8Array) {
|
|
@@ -14582,9 +14677,38 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
|
14582
14677
|
throw new JWEDecryptionFailed();
|
|
14583
14678
|
}
|
|
14584
14679
|
}
|
|
14585
|
-
var
|
|
14680
|
+
var unsupportedEnc = "Unsupported JWE Content Encryption Algorithm";
|
|
14681
|
+
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
14682
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
14683
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
14684
|
+
}
|
|
14685
|
+
if (iv) {
|
|
14686
|
+
checkIvLength(enc, iv);
|
|
14687
|
+
} else {
|
|
14688
|
+
iv = generateIv(enc);
|
|
14689
|
+
}
|
|
14690
|
+
switch (enc) {
|
|
14691
|
+
case "A128CBC-HS256":
|
|
14692
|
+
case "A192CBC-HS384":
|
|
14693
|
+
case "A256CBC-HS512":
|
|
14694
|
+
if (cek instanceof Uint8Array) {
|
|
14695
|
+
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
14696
|
+
}
|
|
14697
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
14698
|
+
case "A128GCM":
|
|
14699
|
+
case "A192GCM":
|
|
14700
|
+
case "A256GCM":
|
|
14701
|
+
if (cek instanceof Uint8Array) {
|
|
14702
|
+
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
14703
|
+
}
|
|
14704
|
+
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
14705
|
+
default:
|
|
14706
|
+
throw new JOSENotSupported(unsupportedEnc);
|
|
14707
|
+
}
|
|
14708
|
+
}
|
|
14709
|
+
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
14586
14710
|
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
14587
|
-
throw new TypeError(
|
|
14711
|
+
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
14588
14712
|
}
|
|
14589
14713
|
if (!iv) {
|
|
14590
14714
|
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
@@ -14592,27 +14716,60 @@ var decrypt_default = async (enc, cek, ciphertext, iv, tag2, aad) => {
|
|
|
14592
14716
|
if (!tag2) {
|
|
14593
14717
|
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
14594
14718
|
}
|
|
14595
|
-
|
|
14719
|
+
checkIvLength(enc, iv);
|
|
14596
14720
|
switch (enc) {
|
|
14597
14721
|
case "A128CBC-HS256":
|
|
14598
14722
|
case "A192CBC-HS384":
|
|
14599
14723
|
case "A256CBC-HS512":
|
|
14600
14724
|
if (cek instanceof Uint8Array)
|
|
14601
|
-
|
|
14725
|
+
checkCekLength(cek, parseInt(enc.slice(-3), 10));
|
|
14602
14726
|
return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
14603
14727
|
case "A128GCM":
|
|
14604
14728
|
case "A192GCM":
|
|
14605
14729
|
case "A256GCM":
|
|
14606
14730
|
if (cek instanceof Uint8Array)
|
|
14607
|
-
|
|
14731
|
+
checkCekLength(cek, parseInt(enc.slice(1, 4), 10));
|
|
14608
14732
|
return gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
14609
14733
|
default:
|
|
14610
|
-
throw new JOSENotSupported(
|
|
14734
|
+
throw new JOSENotSupported(unsupportedEnc);
|
|
14611
14735
|
}
|
|
14612
|
-
}
|
|
14736
|
+
}
|
|
14737
|
+
|
|
14738
|
+
// node_modules/jose/dist/webapi/lib/helpers.js
|
|
14739
|
+
var unprotected = /* @__PURE__ */ Symbol();
|
|
14740
|
+
function assertNotSet(value, name) {
|
|
14741
|
+
if (value) {
|
|
14742
|
+
throw new TypeError(`${name} can only be called once`);
|
|
14743
|
+
}
|
|
14744
|
+
}
|
|
14745
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
14746
|
+
try {
|
|
14747
|
+
return decode(value);
|
|
14748
|
+
} catch {
|
|
14749
|
+
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
14750
|
+
}
|
|
14751
|
+
}
|
|
14752
|
+
async function digest(algorithm, data) {
|
|
14753
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
14754
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
14755
|
+
}
|
|
14613
14756
|
|
|
14614
|
-
// node_modules/jose/dist/webapi/lib/
|
|
14615
|
-
var
|
|
14757
|
+
// node_modules/jose/dist/webapi/lib/type_checks.js
|
|
14758
|
+
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
14759
|
+
function isObject(input) {
|
|
14760
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
14761
|
+
return false;
|
|
14762
|
+
}
|
|
14763
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
14764
|
+
return true;
|
|
14765
|
+
}
|
|
14766
|
+
let proto = input;
|
|
14767
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
14768
|
+
proto = Object.getPrototypeOf(proto);
|
|
14769
|
+
}
|
|
14770
|
+
return Object.getPrototypeOf(input) === proto;
|
|
14771
|
+
}
|
|
14772
|
+
function isDisjoint(...headers) {
|
|
14616
14773
|
const sources = headers.filter(Boolean);
|
|
14617
14774
|
if (sources.length === 0 || sources.length === 1) {
|
|
14618
14775
|
return true;
|
|
@@ -14632,25 +14789,11 @@ var is_disjoint_default = (...headers) => {
|
|
|
14632
14789
|
}
|
|
14633
14790
|
}
|
|
14634
14791
|
return true;
|
|
14635
|
-
};
|
|
14636
|
-
|
|
14637
|
-
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
14638
|
-
function isObjectLike(value) {
|
|
14639
|
-
return typeof value === "object" && value !== null;
|
|
14640
14792
|
}
|
|
14641
|
-
var
|
|
14642
|
-
|
|
14643
|
-
|
|
14644
|
-
|
|
14645
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
14646
|
-
return true;
|
|
14647
|
-
}
|
|
14648
|
-
let proto = input;
|
|
14649
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
14650
|
-
proto = Object.getPrototypeOf(proto);
|
|
14651
|
-
}
|
|
14652
|
-
return Object.getPrototypeOf(input) === proto;
|
|
14653
|
-
};
|
|
14793
|
+
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
14794
|
+
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
14795
|
+
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
14796
|
+
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
14654
14797
|
|
|
14655
14798
|
// node_modules/jose/dist/webapi/lib/aeskw.js
|
|
14656
14799
|
function checkKeySize(key, alg) {
|
|
@@ -14678,12 +14821,6 @@ async function unwrap(alg, key, encryptedKey) {
|
|
|
14678
14821
|
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
14679
14822
|
}
|
|
14680
14823
|
|
|
14681
|
-
// node_modules/jose/dist/webapi/lib/digest.js
|
|
14682
|
-
var digest_default = async (algorithm, data) => {
|
|
14683
|
-
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
14684
|
-
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
14685
|
-
};
|
|
14686
|
-
|
|
14687
14824
|
// node_modules/jose/dist/webapi/lib/ecdhes.js
|
|
14688
14825
|
function lengthAndInput(input) {
|
|
14689
14826
|
return concat(uint32be(input.length), input);
|
|
@@ -14698,19 +14835,19 @@ async function concatKdf(Z, L, OtherInfo) {
|
|
|
14698
14835
|
hashInput.set(uint32be(i), 0);
|
|
14699
14836
|
hashInput.set(Z, 4);
|
|
14700
14837
|
hashInput.set(OtherInfo, 4 + Z.length);
|
|
14701
|
-
const hashResult = await
|
|
14838
|
+
const hashResult = await digest("sha256", hashInput);
|
|
14702
14839
|
dk.set(hashResult, (i - 1) * hashLen);
|
|
14703
14840
|
}
|
|
14704
14841
|
return dk.slice(0, dkLen);
|
|
14705
14842
|
}
|
|
14706
|
-
async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(
|
|
14843
|
+
async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
14707
14844
|
checkEncCryptoKey(publicKey, "ECDH");
|
|
14708
14845
|
checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
|
|
14709
|
-
const algorithmID = lengthAndInput(
|
|
14846
|
+
const algorithmID = lengthAndInput(encode(algorithm));
|
|
14710
14847
|
const partyUInfo = lengthAndInput(apu);
|
|
14711
14848
|
const partyVInfo = lengthAndInput(apv);
|
|
14712
14849
|
const suppPubInfo = uint32be(keyLength);
|
|
14713
|
-
const suppPrivInfo = new Uint8Array(
|
|
14850
|
+
const suppPrivInfo = new Uint8Array();
|
|
14714
14851
|
const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
|
|
14715
14852
|
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
14716
14853
|
name: publicKey.algorithm.name,
|
|
@@ -14738,12 +14875,14 @@ function allowed(key) {
|
|
|
14738
14875
|
// node_modules/jose/dist/webapi/lib/pbes2kw.js
|
|
14739
14876
|
function getCryptoKey2(key, alg) {
|
|
14740
14877
|
if (key instanceof Uint8Array) {
|
|
14741
|
-
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
14878
|
+
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
14879
|
+
"deriveBits"
|
|
14880
|
+
]);
|
|
14742
14881
|
}
|
|
14743
14882
|
checkEncCryptoKey(key, alg, "deriveBits");
|
|
14744
14883
|
return key;
|
|
14745
14884
|
}
|
|
14746
|
-
var concatSalt = (alg, p2sInput) => concat(
|
|
14885
|
+
var concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0), p2sInput);
|
|
14747
14886
|
async function deriveKey2(p2s, alg, p2c, key) {
|
|
14748
14887
|
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
14749
14888
|
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
@@ -14762,25 +14901,81 @@ async function deriveKey2(p2s, alg, p2c, key) {
|
|
|
14762
14901
|
async function wrap2(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
|
|
14763
14902
|
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
14764
14903
|
const encryptedKey = await wrap(alg.slice(-6), derived, cek);
|
|
14765
|
-
return { encryptedKey, p2c, p2s:
|
|
14904
|
+
return { encryptedKey, p2c, p2s: encode2(p2s) };
|
|
14766
14905
|
}
|
|
14767
14906
|
async function unwrap2(alg, key, encryptedKey, p2c, p2s) {
|
|
14768
14907
|
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
14769
14908
|
return unwrap(alg.slice(-6), derived, encryptedKey);
|
|
14770
14909
|
}
|
|
14771
14910
|
|
|
14772
|
-
// node_modules/jose/dist/webapi/lib/
|
|
14773
|
-
|
|
14911
|
+
// node_modules/jose/dist/webapi/lib/signing.js
|
|
14912
|
+
function checkKeyLength(alg, key) {
|
|
14774
14913
|
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
14775
14914
|
const { modulusLength } = key.algorithm;
|
|
14776
14915
|
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
14777
14916
|
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
14778
14917
|
}
|
|
14779
14918
|
}
|
|
14780
|
-
}
|
|
14919
|
+
}
|
|
14920
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
14921
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
14922
|
+
switch (alg) {
|
|
14923
|
+
case "HS256":
|
|
14924
|
+
case "HS384":
|
|
14925
|
+
case "HS512":
|
|
14926
|
+
return { hash, name: "HMAC" };
|
|
14927
|
+
case "PS256":
|
|
14928
|
+
case "PS384":
|
|
14929
|
+
case "PS512":
|
|
14930
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
14931
|
+
case "RS256":
|
|
14932
|
+
case "RS384":
|
|
14933
|
+
case "RS512":
|
|
14934
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
14935
|
+
case "ES256":
|
|
14936
|
+
case "ES384":
|
|
14937
|
+
case "ES512":
|
|
14938
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
14939
|
+
case "Ed25519":
|
|
14940
|
+
case "EdDSA":
|
|
14941
|
+
return { name: "Ed25519" };
|
|
14942
|
+
case "ML-DSA-44":
|
|
14943
|
+
case "ML-DSA-65":
|
|
14944
|
+
case "ML-DSA-87":
|
|
14945
|
+
return { name: alg };
|
|
14946
|
+
default:
|
|
14947
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
14948
|
+
}
|
|
14949
|
+
}
|
|
14950
|
+
async function getSigKey(alg, key, usage2) {
|
|
14951
|
+
if (key instanceof Uint8Array) {
|
|
14952
|
+
if (!alg.startsWith("HS")) {
|
|
14953
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
14954
|
+
}
|
|
14955
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage2]);
|
|
14956
|
+
}
|
|
14957
|
+
checkSigCryptoKey(key, alg, usage2);
|
|
14958
|
+
return key;
|
|
14959
|
+
}
|
|
14960
|
+
async function sign(alg, key, data) {
|
|
14961
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
14962
|
+
checkKeyLength(alg, cryptoKey);
|
|
14963
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
14964
|
+
return new Uint8Array(signature);
|
|
14965
|
+
}
|
|
14966
|
+
async function verify(alg, key, signature, data) {
|
|
14967
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
14968
|
+
checkKeyLength(alg, cryptoKey);
|
|
14969
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
14970
|
+
try {
|
|
14971
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
14972
|
+
} catch {
|
|
14973
|
+
return false;
|
|
14974
|
+
}
|
|
14975
|
+
}
|
|
14781
14976
|
|
|
14782
14977
|
// node_modules/jose/dist/webapi/lib/rsaes.js
|
|
14783
|
-
var
|
|
14978
|
+
var subtleAlgorithm2 = (alg) => {
|
|
14784
14979
|
switch (alg) {
|
|
14785
14980
|
case "RSA-OAEP":
|
|
14786
14981
|
case "RSA-OAEP-256":
|
|
@@ -14791,38 +14986,19 @@ var subtleAlgorithm = (alg) => {
|
|
|
14791
14986
|
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
14792
14987
|
}
|
|
14793
14988
|
};
|
|
14794
|
-
async function
|
|
14989
|
+
async function encrypt2(alg, key, cek) {
|
|
14795
14990
|
checkEncCryptoKey(key, alg, "encrypt");
|
|
14796
|
-
|
|
14797
|
-
return new Uint8Array(await crypto.subtle.encrypt(
|
|
14991
|
+
checkKeyLength(alg, key);
|
|
14992
|
+
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm2(alg), key, cek));
|
|
14798
14993
|
}
|
|
14799
|
-
async function
|
|
14994
|
+
async function decrypt2(alg, key, encryptedKey) {
|
|
14800
14995
|
checkEncCryptoKey(key, alg, "decrypt");
|
|
14801
|
-
|
|
14802
|
-
return new Uint8Array(await crypto.subtle.decrypt(
|
|
14996
|
+
checkKeyLength(alg, key);
|
|
14997
|
+
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm2(alg), key, encryptedKey));
|
|
14803
14998
|
}
|
|
14804
14999
|
|
|
14805
|
-
// node_modules/jose/dist/webapi/lib/cek.js
|
|
14806
|
-
function bitLength2(alg) {
|
|
14807
|
-
switch (alg) {
|
|
14808
|
-
case "A128GCM":
|
|
14809
|
-
return 128;
|
|
14810
|
-
case "A192GCM":
|
|
14811
|
-
return 192;
|
|
14812
|
-
case "A256GCM":
|
|
14813
|
-
case "A128CBC-HS256":
|
|
14814
|
-
return 256;
|
|
14815
|
-
case "A192CBC-HS384":
|
|
14816
|
-
return 384;
|
|
14817
|
-
case "A256CBC-HS512":
|
|
14818
|
-
return 512;
|
|
14819
|
-
default:
|
|
14820
|
-
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
14821
|
-
}
|
|
14822
|
-
}
|
|
14823
|
-
var cek_default = (alg) => crypto.getRandomValues(new Uint8Array(bitLength2(alg) >> 3));
|
|
14824
|
-
|
|
14825
15000
|
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
15001
|
+
var unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
|
|
14826
15002
|
function subtleMapping(jwk) {
|
|
14827
15003
|
let algorithm;
|
|
14828
15004
|
let keyUsages;
|
|
@@ -14836,7 +15012,7 @@ function subtleMapping(jwk) {
|
|
|
14836
15012
|
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
14837
15013
|
break;
|
|
14838
15014
|
default:
|
|
14839
|
-
throw new JOSENotSupported(
|
|
15015
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
14840
15016
|
}
|
|
14841
15017
|
break;
|
|
14842
15018
|
}
|
|
@@ -14865,22 +15041,19 @@ function subtleMapping(jwk) {
|
|
|
14865
15041
|
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
14866
15042
|
break;
|
|
14867
15043
|
default:
|
|
14868
|
-
throw new JOSENotSupported(
|
|
15044
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
14869
15045
|
}
|
|
14870
15046
|
break;
|
|
14871
15047
|
}
|
|
14872
15048
|
case "EC": {
|
|
14873
15049
|
switch (jwk.alg) {
|
|
14874
15050
|
case "ES256":
|
|
14875
|
-
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
14876
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
14877
|
-
break;
|
|
14878
15051
|
case "ES384":
|
|
14879
|
-
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
14880
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
14881
|
-
break;
|
|
14882
15052
|
case "ES512":
|
|
14883
|
-
algorithm = {
|
|
15053
|
+
algorithm = {
|
|
15054
|
+
name: "ECDSA",
|
|
15055
|
+
namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
|
|
15056
|
+
};
|
|
14884
15057
|
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
14885
15058
|
break;
|
|
14886
15059
|
case "ECDH-ES":
|
|
@@ -14891,7 +15064,7 @@ function subtleMapping(jwk) {
|
|
|
14891
15064
|
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
14892
15065
|
break;
|
|
14893
15066
|
default:
|
|
14894
|
-
throw new JOSENotSupported(
|
|
15067
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
14895
15068
|
}
|
|
14896
15069
|
break;
|
|
14897
15070
|
}
|
|
@@ -14910,7 +15083,7 @@ function subtleMapping(jwk) {
|
|
|
14910
15083
|
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
14911
15084
|
break;
|
|
14912
15085
|
default:
|
|
14913
|
-
throw new JOSENotSupported(
|
|
15086
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
14914
15087
|
}
|
|
14915
15088
|
break;
|
|
14916
15089
|
}
|
|
@@ -14919,7 +15092,7 @@ function subtleMapping(jwk) {
|
|
|
14919
15092
|
}
|
|
14920
15093
|
return { algorithm, keyUsages };
|
|
14921
15094
|
}
|
|
14922
|
-
|
|
15095
|
+
async function jwkToKey(jwk) {
|
|
14923
15096
|
if (!jwk.alg) {
|
|
14924
15097
|
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
14925
15098
|
}
|
|
@@ -14930,295 +15103,10 @@ var jwk_to_key_default = async (jwk) => {
|
|
|
14930
15103
|
}
|
|
14931
15104
|
delete keyData.use;
|
|
14932
15105
|
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
14933
|
-
};
|
|
14934
|
-
|
|
14935
|
-
// node_modules/jose/dist/webapi/key/import.js
|
|
14936
|
-
async function importJWK(jwk, alg, options) {
|
|
14937
|
-
if (!is_object_default(jwk)) {
|
|
14938
|
-
throw new TypeError("JWK must be an object");
|
|
14939
|
-
}
|
|
14940
|
-
let ext;
|
|
14941
|
-
alg ??= jwk.alg;
|
|
14942
|
-
ext ??= options?.extractable ?? jwk.ext;
|
|
14943
|
-
switch (jwk.kty) {
|
|
14944
|
-
case "oct":
|
|
14945
|
-
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
14946
|
-
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
14947
|
-
}
|
|
14948
|
-
return decode(jwk.k);
|
|
14949
|
-
case "RSA":
|
|
14950
|
-
if ("oth" in jwk && jwk.oth !== void 0) {
|
|
14951
|
-
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
14952
|
-
}
|
|
14953
|
-
return jwk_to_key_default({ ...jwk, alg, ext });
|
|
14954
|
-
case "AKP": {
|
|
14955
|
-
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
14956
|
-
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
14957
|
-
}
|
|
14958
|
-
if (alg !== void 0 && alg !== jwk.alg) {
|
|
14959
|
-
throw new TypeError("JWK alg and alg option value mismatch");
|
|
14960
|
-
}
|
|
14961
|
-
return jwk_to_key_default({ ...jwk, ext });
|
|
14962
|
-
}
|
|
14963
|
-
case "EC":
|
|
14964
|
-
case "OKP":
|
|
14965
|
-
return jwk_to_key_default({ ...jwk, alg, ext });
|
|
14966
|
-
default:
|
|
14967
|
-
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
14968
|
-
}
|
|
14969
|
-
}
|
|
14970
|
-
|
|
14971
|
-
// node_modules/jose/dist/webapi/lib/encrypt.js
|
|
14972
|
-
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
14973
|
-
if (!(cek instanceof Uint8Array)) {
|
|
14974
|
-
throw new TypeError(invalid_key_input_default(cek, "Uint8Array"));
|
|
14975
|
-
}
|
|
14976
|
-
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
14977
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["encrypt"]);
|
|
14978
|
-
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
14979
|
-
hash: `SHA-${keySize << 1}`,
|
|
14980
|
-
name: "HMAC"
|
|
14981
|
-
}, false, ["sign"]);
|
|
14982
|
-
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
14983
|
-
iv,
|
|
14984
|
-
name: "AES-CBC"
|
|
14985
|
-
}, encKey, plaintext));
|
|
14986
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
14987
|
-
const tag2 = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
14988
|
-
return { ciphertext, tag: tag2, iv };
|
|
14989
|
-
}
|
|
14990
|
-
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
14991
|
-
let encKey;
|
|
14992
|
-
if (cek instanceof Uint8Array) {
|
|
14993
|
-
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
14994
|
-
} else {
|
|
14995
|
-
checkEncCryptoKey(cek, enc, "encrypt");
|
|
14996
|
-
encKey = cek;
|
|
14997
|
-
}
|
|
14998
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
14999
|
-
additionalData: aad,
|
|
15000
|
-
iv,
|
|
15001
|
-
name: "AES-GCM",
|
|
15002
|
-
tagLength: 128
|
|
15003
|
-
}, encKey, plaintext));
|
|
15004
|
-
const tag2 = encrypted.slice(-16);
|
|
15005
|
-
const ciphertext = encrypted.slice(0, -16);
|
|
15006
|
-
return { ciphertext, tag: tag2, iv };
|
|
15007
|
-
}
|
|
15008
|
-
var encrypt_default = async (enc, plaintext, cek, iv, aad) => {
|
|
15009
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
15010
|
-
throw new TypeError(invalid_key_input_default(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
15011
|
-
}
|
|
15012
|
-
if (iv) {
|
|
15013
|
-
check_iv_length_default(enc, iv);
|
|
15014
|
-
} else {
|
|
15015
|
-
iv = iv_default(enc);
|
|
15016
|
-
}
|
|
15017
|
-
switch (enc) {
|
|
15018
|
-
case "A128CBC-HS256":
|
|
15019
|
-
case "A192CBC-HS384":
|
|
15020
|
-
case "A256CBC-HS512":
|
|
15021
|
-
if (cek instanceof Uint8Array) {
|
|
15022
|
-
check_cek_length_default(cek, parseInt(enc.slice(-3), 10));
|
|
15023
|
-
}
|
|
15024
|
-
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
15025
|
-
case "A128GCM":
|
|
15026
|
-
case "A192GCM":
|
|
15027
|
-
case "A256GCM":
|
|
15028
|
-
if (cek instanceof Uint8Array) {
|
|
15029
|
-
check_cek_length_default(cek, parseInt(enc.slice(1, 4), 10));
|
|
15030
|
-
}
|
|
15031
|
-
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
15032
|
-
default:
|
|
15033
|
-
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
15034
|
-
}
|
|
15035
|
-
};
|
|
15036
|
-
|
|
15037
|
-
// node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
15038
|
-
async function wrap3(alg, key, cek, iv) {
|
|
15039
|
-
const jweAlgorithm = alg.slice(0, 7);
|
|
15040
|
-
const wrapped = await encrypt_default(jweAlgorithm, cek, key, iv, new Uint8Array(0));
|
|
15041
|
-
return {
|
|
15042
|
-
encryptedKey: wrapped.ciphertext,
|
|
15043
|
-
iv: encode(wrapped.iv),
|
|
15044
|
-
tag: encode(wrapped.tag)
|
|
15045
|
-
};
|
|
15046
|
-
}
|
|
15047
|
-
async function unwrap3(alg, key, encryptedKey, iv, tag2) {
|
|
15048
|
-
const jweAlgorithm = alg.slice(0, 7);
|
|
15049
|
-
return decrypt_default(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array(0));
|
|
15050
|
-
}
|
|
15051
|
-
|
|
15052
|
-
// node_modules/jose/dist/webapi/lib/decrypt_key_management.js
|
|
15053
|
-
var decrypt_key_management_default = async (alg, key, encryptedKey, joseHeader, options) => {
|
|
15054
|
-
switch (alg) {
|
|
15055
|
-
case "dir": {
|
|
15056
|
-
if (encryptedKey !== void 0)
|
|
15057
|
-
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
15058
|
-
return key;
|
|
15059
|
-
}
|
|
15060
|
-
case "ECDH-ES":
|
|
15061
|
-
if (encryptedKey !== void 0)
|
|
15062
|
-
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
15063
|
-
case "ECDH-ES+A128KW":
|
|
15064
|
-
case "ECDH-ES+A192KW":
|
|
15065
|
-
case "ECDH-ES+A256KW": {
|
|
15066
|
-
if (!is_object_default(joseHeader.epk))
|
|
15067
|
-
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
15068
|
-
assertCryptoKey(key);
|
|
15069
|
-
if (!allowed(key))
|
|
15070
|
-
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
15071
|
-
const epk = await importJWK(joseHeader.epk, alg);
|
|
15072
|
-
assertCryptoKey(epk);
|
|
15073
|
-
let partyUInfo;
|
|
15074
|
-
let partyVInfo;
|
|
15075
|
-
if (joseHeader.apu !== void 0) {
|
|
15076
|
-
if (typeof joseHeader.apu !== "string")
|
|
15077
|
-
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
15078
|
-
try {
|
|
15079
|
-
partyUInfo = decode(joseHeader.apu);
|
|
15080
|
-
} catch {
|
|
15081
|
-
throw new JWEInvalid("Failed to base64url decode the apu");
|
|
15082
|
-
}
|
|
15083
|
-
}
|
|
15084
|
-
if (joseHeader.apv !== void 0) {
|
|
15085
|
-
if (typeof joseHeader.apv !== "string")
|
|
15086
|
-
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
15087
|
-
try {
|
|
15088
|
-
partyVInfo = decode(joseHeader.apv);
|
|
15089
|
-
} catch {
|
|
15090
|
-
throw new JWEInvalid("Failed to base64url decode the apv");
|
|
15091
|
-
}
|
|
15092
|
-
}
|
|
15093
|
-
const sharedSecret = await deriveKey(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? bitLength2(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
15094
|
-
if (alg === "ECDH-ES")
|
|
15095
|
-
return sharedSecret;
|
|
15096
|
-
if (encryptedKey === void 0)
|
|
15097
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
15098
|
-
return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
15099
|
-
}
|
|
15100
|
-
case "RSA-OAEP":
|
|
15101
|
-
case "RSA-OAEP-256":
|
|
15102
|
-
case "RSA-OAEP-384":
|
|
15103
|
-
case "RSA-OAEP-512": {
|
|
15104
|
-
if (encryptedKey === void 0)
|
|
15105
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
15106
|
-
assertCryptoKey(key);
|
|
15107
|
-
return decrypt(alg, key, encryptedKey);
|
|
15108
|
-
}
|
|
15109
|
-
case "PBES2-HS256+A128KW":
|
|
15110
|
-
case "PBES2-HS384+A192KW":
|
|
15111
|
-
case "PBES2-HS512+A256KW": {
|
|
15112
|
-
if (encryptedKey === void 0)
|
|
15113
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
15114
|
-
if (typeof joseHeader.p2c !== "number")
|
|
15115
|
-
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
15116
|
-
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
15117
|
-
if (joseHeader.p2c > p2cLimit)
|
|
15118
|
-
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
15119
|
-
if (typeof joseHeader.p2s !== "string")
|
|
15120
|
-
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
15121
|
-
let p2s;
|
|
15122
|
-
try {
|
|
15123
|
-
p2s = decode(joseHeader.p2s);
|
|
15124
|
-
} catch {
|
|
15125
|
-
throw new JWEInvalid("Failed to base64url decode the p2s");
|
|
15126
|
-
}
|
|
15127
|
-
return unwrap2(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
15128
|
-
}
|
|
15129
|
-
case "A128KW":
|
|
15130
|
-
case "A192KW":
|
|
15131
|
-
case "A256KW": {
|
|
15132
|
-
if (encryptedKey === void 0)
|
|
15133
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
15134
|
-
return unwrap(alg, key, encryptedKey);
|
|
15135
|
-
}
|
|
15136
|
-
case "A128GCMKW":
|
|
15137
|
-
case "A192GCMKW":
|
|
15138
|
-
case "A256GCMKW": {
|
|
15139
|
-
if (encryptedKey === void 0)
|
|
15140
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
15141
|
-
if (typeof joseHeader.iv !== "string")
|
|
15142
|
-
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
15143
|
-
if (typeof joseHeader.tag !== "string")
|
|
15144
|
-
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
15145
|
-
let iv;
|
|
15146
|
-
try {
|
|
15147
|
-
iv = decode(joseHeader.iv);
|
|
15148
|
-
} catch {
|
|
15149
|
-
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
15150
|
-
}
|
|
15151
|
-
let tag2;
|
|
15152
|
-
try {
|
|
15153
|
-
tag2 = decode(joseHeader.tag);
|
|
15154
|
-
} catch {
|
|
15155
|
-
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
15156
|
-
}
|
|
15157
|
-
return unwrap3(alg, key, encryptedKey, iv, tag2);
|
|
15158
|
-
}
|
|
15159
|
-
default: {
|
|
15160
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
15161
|
-
}
|
|
15162
|
-
}
|
|
15163
|
-
};
|
|
15164
|
-
|
|
15165
|
-
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
15166
|
-
var validate_crit_default = (Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) => {
|
|
15167
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
15168
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
15169
|
-
}
|
|
15170
|
-
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
15171
|
-
return /* @__PURE__ */ new Set();
|
|
15172
|
-
}
|
|
15173
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
15174
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
15175
|
-
}
|
|
15176
|
-
let recognized;
|
|
15177
|
-
if (recognizedOption !== void 0) {
|
|
15178
|
-
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
15179
|
-
} else {
|
|
15180
|
-
recognized = recognizedDefault;
|
|
15181
|
-
}
|
|
15182
|
-
for (const parameter of protectedHeader.crit) {
|
|
15183
|
-
if (!recognized.has(parameter)) {
|
|
15184
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
15185
|
-
}
|
|
15186
|
-
if (joseHeader[parameter] === void 0) {
|
|
15187
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
15188
|
-
}
|
|
15189
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
15190
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
15191
|
-
}
|
|
15192
|
-
}
|
|
15193
|
-
return new Set(protectedHeader.crit);
|
|
15194
|
-
};
|
|
15195
|
-
|
|
15196
|
-
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
15197
|
-
var validate_algorithms_default = (option, algorithms) => {
|
|
15198
|
-
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
15199
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
15200
|
-
}
|
|
15201
|
-
if (!algorithms) {
|
|
15202
|
-
return void 0;
|
|
15203
|
-
}
|
|
15204
|
-
return new Set(algorithms);
|
|
15205
|
-
};
|
|
15206
|
-
|
|
15207
|
-
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
15208
|
-
function isJWK(key) {
|
|
15209
|
-
return is_object_default(key) && typeof key.kty === "string";
|
|
15210
|
-
}
|
|
15211
|
-
function isPrivateJWK(key) {
|
|
15212
|
-
return key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
15213
|
-
}
|
|
15214
|
-
function isPublicJWK(key) {
|
|
15215
|
-
return key.kty !== "oct" && typeof key.d === "undefined" && typeof key.priv === "undefined";
|
|
15216
|
-
}
|
|
15217
|
-
function isSecretJWK(key) {
|
|
15218
|
-
return key.kty === "oct" && typeof key.k === "string";
|
|
15219
15106
|
}
|
|
15220
15107
|
|
|
15221
15108
|
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
15109
|
+
var unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
15222
15110
|
var cache;
|
|
15223
15111
|
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
15224
15112
|
cache ||= /* @__PURE__ */ new WeakMap();
|
|
@@ -15226,7 +15114,7 @@ var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
|
15226
15114
|
if (cached?.[alg]) {
|
|
15227
15115
|
return cached[alg];
|
|
15228
15116
|
}
|
|
15229
|
-
const cryptoKey = await
|
|
15117
|
+
const cryptoKey = await jwkToKey({ ...jwk, alg });
|
|
15230
15118
|
if (freeze)
|
|
15231
15119
|
Object.freeze(key);
|
|
15232
15120
|
if (!cached) {
|
|
@@ -15253,13 +15141,13 @@ var handleKeyObject = (keyObject, alg) => {
|
|
|
15253
15141
|
case "ECDH-ES+A256KW":
|
|
15254
15142
|
break;
|
|
15255
15143
|
default:
|
|
15256
|
-
throw new TypeError(
|
|
15144
|
+
throw new TypeError(unusableForAlg);
|
|
15257
15145
|
}
|
|
15258
15146
|
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
15259
15147
|
}
|
|
15260
15148
|
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
15261
15149
|
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
15262
|
-
throw new TypeError(
|
|
15150
|
+
throw new TypeError(unusableForAlg);
|
|
15263
15151
|
}
|
|
15264
15152
|
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
15265
15153
|
isPublic ? "verify" : "sign"
|
|
@@ -15270,7 +15158,7 @@ var handleKeyObject = (keyObject, alg) => {
|
|
|
15270
15158
|
case "ml-dsa-65":
|
|
15271
15159
|
case "ml-dsa-87": {
|
|
15272
15160
|
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
15273
|
-
throw new TypeError(
|
|
15161
|
+
throw new TypeError(unusableForAlg);
|
|
15274
15162
|
}
|
|
15275
15163
|
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
15276
15164
|
isPublic ? "verify" : "sign"
|
|
@@ -15299,7 +15187,7 @@ var handleKeyObject = (keyObject, alg) => {
|
|
|
15299
15187
|
hash = "SHA-512";
|
|
15300
15188
|
break;
|
|
15301
15189
|
default:
|
|
15302
|
-
throw new TypeError(
|
|
15190
|
+
throw new TypeError(unusableForAlg);
|
|
15303
15191
|
}
|
|
15304
15192
|
if (alg.startsWith("RSA-OAEP")) {
|
|
15305
15193
|
return keyObject.toCryptoKey({
|
|
@@ -15320,21 +15208,10 @@ var handleKeyObject = (keyObject, alg) => {
|
|
|
15320
15208
|
]);
|
|
15321
15209
|
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
15322
15210
|
if (!namedCurve) {
|
|
15323
|
-
throw new TypeError(
|
|
15324
|
-
}
|
|
15325
|
-
if (alg === "ES256" && namedCurve === "P-256") {
|
|
15326
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
15327
|
-
name: "ECDSA",
|
|
15328
|
-
namedCurve
|
|
15329
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
15330
|
-
}
|
|
15331
|
-
if (alg === "ES384" && namedCurve === "P-384") {
|
|
15332
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
15333
|
-
name: "ECDSA",
|
|
15334
|
-
namedCurve
|
|
15335
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
15211
|
+
throw new TypeError(unusableForAlg);
|
|
15336
15212
|
}
|
|
15337
|
-
|
|
15213
|
+
const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
15214
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
|
|
15338
15215
|
cryptoKey = keyObject.toCryptoKey({
|
|
15339
15216
|
name: "ECDSA",
|
|
15340
15217
|
namedCurve
|
|
@@ -15348,7 +15225,7 @@ var handleKeyObject = (keyObject, alg) => {
|
|
|
15348
15225
|
}
|
|
15349
15226
|
}
|
|
15350
15227
|
if (!cryptoKey) {
|
|
15351
|
-
throw new TypeError(
|
|
15228
|
+
throw new TypeError(unusableForAlg);
|
|
15352
15229
|
}
|
|
15353
15230
|
if (!cached) {
|
|
15354
15231
|
cache.set(keyObject, { [alg]: cryptoKey });
|
|
@@ -15357,7 +15234,7 @@ var handleKeyObject = (keyObject, alg) => {
|
|
|
15357
15234
|
}
|
|
15358
15235
|
return cryptoKey;
|
|
15359
15236
|
};
|
|
15360
|
-
|
|
15237
|
+
async function normalizeKey(key, alg) {
|
|
15361
15238
|
if (key instanceof Uint8Array) {
|
|
15362
15239
|
return key;
|
|
15363
15240
|
}
|
|
@@ -15380,14 +15257,314 @@ var normalize_key_default = async (key, alg) => {
|
|
|
15380
15257
|
let jwk = key.export({ format: "jwk" });
|
|
15381
15258
|
return handleJWK(key, jwk, alg);
|
|
15382
15259
|
}
|
|
15383
|
-
if (isJWK(key)) {
|
|
15384
|
-
if (key.k) {
|
|
15385
|
-
return decode(key.k);
|
|
15260
|
+
if (isJWK(key)) {
|
|
15261
|
+
if (key.k) {
|
|
15262
|
+
return decode(key.k);
|
|
15263
|
+
}
|
|
15264
|
+
return handleJWK(key, key, alg, true);
|
|
15265
|
+
}
|
|
15266
|
+
throw new Error("unreachable");
|
|
15267
|
+
}
|
|
15268
|
+
|
|
15269
|
+
// node_modules/jose/dist/webapi/key/import.js
|
|
15270
|
+
async function importJWK(jwk, alg, options) {
|
|
15271
|
+
if (!isObject(jwk)) {
|
|
15272
|
+
throw new TypeError("JWK must be an object");
|
|
15273
|
+
}
|
|
15274
|
+
let ext;
|
|
15275
|
+
alg ??= jwk.alg;
|
|
15276
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
15277
|
+
switch (jwk.kty) {
|
|
15278
|
+
case "oct":
|
|
15279
|
+
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
15280
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
15281
|
+
}
|
|
15282
|
+
return decode(jwk.k);
|
|
15283
|
+
case "RSA":
|
|
15284
|
+
if ("oth" in jwk && jwk.oth !== void 0) {
|
|
15285
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
15286
|
+
}
|
|
15287
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
15288
|
+
case "AKP": {
|
|
15289
|
+
if (typeof jwk.alg !== "string" || !jwk.alg) {
|
|
15290
|
+
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
15291
|
+
}
|
|
15292
|
+
if (alg !== void 0 && alg !== jwk.alg) {
|
|
15293
|
+
throw new TypeError("JWK alg and alg option value mismatch");
|
|
15294
|
+
}
|
|
15295
|
+
return jwkToKey({ ...jwk, ext });
|
|
15296
|
+
}
|
|
15297
|
+
case "EC":
|
|
15298
|
+
case "OKP":
|
|
15299
|
+
return jwkToKey({ ...jwk, alg, ext });
|
|
15300
|
+
default:
|
|
15301
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
15302
|
+
}
|
|
15303
|
+
}
|
|
15304
|
+
|
|
15305
|
+
// node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
15306
|
+
async function keyToJWK(key) {
|
|
15307
|
+
if (isKeyObject(key)) {
|
|
15308
|
+
if (key.type === "secret") {
|
|
15309
|
+
key = key.export();
|
|
15310
|
+
} else {
|
|
15311
|
+
return key.export({ format: "jwk" });
|
|
15312
|
+
}
|
|
15313
|
+
}
|
|
15314
|
+
if (key instanceof Uint8Array) {
|
|
15315
|
+
return {
|
|
15316
|
+
kty: "oct",
|
|
15317
|
+
k: encode2(key)
|
|
15318
|
+
};
|
|
15319
|
+
}
|
|
15320
|
+
if (!isCryptoKey(key)) {
|
|
15321
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
15322
|
+
}
|
|
15323
|
+
if (!key.extractable) {
|
|
15324
|
+
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
15325
|
+
}
|
|
15326
|
+
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
15327
|
+
if (jwk.kty === "AKP") {
|
|
15328
|
+
;
|
|
15329
|
+
jwk.alg = alg;
|
|
15330
|
+
}
|
|
15331
|
+
return jwk;
|
|
15332
|
+
}
|
|
15333
|
+
|
|
15334
|
+
// node_modules/jose/dist/webapi/key/export.js
|
|
15335
|
+
async function exportJWK(key) {
|
|
15336
|
+
return keyToJWK(key);
|
|
15337
|
+
}
|
|
15338
|
+
|
|
15339
|
+
// node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
15340
|
+
async function wrap3(alg, key, cek, iv) {
|
|
15341
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
15342
|
+
const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array());
|
|
15343
|
+
return {
|
|
15344
|
+
encryptedKey: wrapped.ciphertext,
|
|
15345
|
+
iv: encode2(wrapped.iv),
|
|
15346
|
+
tag: encode2(wrapped.tag)
|
|
15347
|
+
};
|
|
15348
|
+
}
|
|
15349
|
+
async function unwrap3(alg, key, encryptedKey, iv, tag2) {
|
|
15350
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
15351
|
+
return decrypt(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array());
|
|
15352
|
+
}
|
|
15353
|
+
|
|
15354
|
+
// node_modules/jose/dist/webapi/lib/key_management.js
|
|
15355
|
+
var unsupportedAlgHeader = 'Invalid or unsupported "alg" (JWE Algorithm) header value';
|
|
15356
|
+
function assertEncryptedKey(encryptedKey) {
|
|
15357
|
+
if (encryptedKey === void 0)
|
|
15358
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
15359
|
+
}
|
|
15360
|
+
async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
|
|
15361
|
+
switch (alg) {
|
|
15362
|
+
case "dir": {
|
|
15363
|
+
if (encryptedKey !== void 0)
|
|
15364
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
15365
|
+
return key;
|
|
15366
|
+
}
|
|
15367
|
+
case "ECDH-ES":
|
|
15368
|
+
if (encryptedKey !== void 0)
|
|
15369
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
15370
|
+
case "ECDH-ES+A128KW":
|
|
15371
|
+
case "ECDH-ES+A192KW":
|
|
15372
|
+
case "ECDH-ES+A256KW": {
|
|
15373
|
+
if (!isObject(joseHeader.epk))
|
|
15374
|
+
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
15375
|
+
assertCryptoKey(key);
|
|
15376
|
+
if (!allowed(key))
|
|
15377
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
15378
|
+
const epk = await importJWK(joseHeader.epk, alg);
|
|
15379
|
+
assertCryptoKey(epk);
|
|
15380
|
+
let partyUInfo;
|
|
15381
|
+
let partyVInfo;
|
|
15382
|
+
if (joseHeader.apu !== void 0) {
|
|
15383
|
+
if (typeof joseHeader.apu !== "string")
|
|
15384
|
+
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
15385
|
+
partyUInfo = decodeBase64url(joseHeader.apu, "apu", JWEInvalid);
|
|
15386
|
+
}
|
|
15387
|
+
if (joseHeader.apv !== void 0) {
|
|
15388
|
+
if (typeof joseHeader.apv !== "string")
|
|
15389
|
+
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
15390
|
+
partyVInfo = decodeBase64url(joseHeader.apv, "apv", JWEInvalid);
|
|
15391
|
+
}
|
|
15392
|
+
const sharedSecret = await deriveKey(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? cekLength(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
15393
|
+
if (alg === "ECDH-ES")
|
|
15394
|
+
return sharedSecret;
|
|
15395
|
+
assertEncryptedKey(encryptedKey);
|
|
15396
|
+
return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
15397
|
+
}
|
|
15398
|
+
case "RSA-OAEP":
|
|
15399
|
+
case "RSA-OAEP-256":
|
|
15400
|
+
case "RSA-OAEP-384":
|
|
15401
|
+
case "RSA-OAEP-512": {
|
|
15402
|
+
assertEncryptedKey(encryptedKey);
|
|
15403
|
+
assertCryptoKey(key);
|
|
15404
|
+
return decrypt2(alg, key, encryptedKey);
|
|
15405
|
+
}
|
|
15406
|
+
case "PBES2-HS256+A128KW":
|
|
15407
|
+
case "PBES2-HS384+A192KW":
|
|
15408
|
+
case "PBES2-HS512+A256KW": {
|
|
15409
|
+
assertEncryptedKey(encryptedKey);
|
|
15410
|
+
if (typeof joseHeader.p2c !== "number")
|
|
15411
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
15412
|
+
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
15413
|
+
if (joseHeader.p2c > p2cLimit)
|
|
15414
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
15415
|
+
if (typeof joseHeader.p2s !== "string")
|
|
15416
|
+
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
15417
|
+
let p2s;
|
|
15418
|
+
p2s = decodeBase64url(joseHeader.p2s, "p2s", JWEInvalid);
|
|
15419
|
+
return unwrap2(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
15420
|
+
}
|
|
15421
|
+
case "A128KW":
|
|
15422
|
+
case "A192KW":
|
|
15423
|
+
case "A256KW": {
|
|
15424
|
+
assertEncryptedKey(encryptedKey);
|
|
15425
|
+
return unwrap(alg, key, encryptedKey);
|
|
15426
|
+
}
|
|
15427
|
+
case "A128GCMKW":
|
|
15428
|
+
case "A192GCMKW":
|
|
15429
|
+
case "A256GCMKW": {
|
|
15430
|
+
assertEncryptedKey(encryptedKey);
|
|
15431
|
+
if (typeof joseHeader.iv !== "string")
|
|
15432
|
+
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
15433
|
+
if (typeof joseHeader.tag !== "string")
|
|
15434
|
+
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
15435
|
+
let iv;
|
|
15436
|
+
iv = decodeBase64url(joseHeader.iv, "iv", JWEInvalid);
|
|
15437
|
+
let tag2;
|
|
15438
|
+
tag2 = decodeBase64url(joseHeader.tag, "tag", JWEInvalid);
|
|
15439
|
+
return unwrap3(alg, key, encryptedKey, iv, tag2);
|
|
15440
|
+
}
|
|
15441
|
+
default: {
|
|
15442
|
+
throw new JOSENotSupported(unsupportedAlgHeader);
|
|
15443
|
+
}
|
|
15444
|
+
}
|
|
15445
|
+
}
|
|
15446
|
+
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
15447
|
+
let encryptedKey;
|
|
15448
|
+
let parameters;
|
|
15449
|
+
let cek;
|
|
15450
|
+
switch (alg) {
|
|
15451
|
+
case "dir": {
|
|
15452
|
+
cek = key;
|
|
15453
|
+
break;
|
|
15454
|
+
}
|
|
15455
|
+
case "ECDH-ES":
|
|
15456
|
+
case "ECDH-ES+A128KW":
|
|
15457
|
+
case "ECDH-ES+A192KW":
|
|
15458
|
+
case "ECDH-ES+A256KW": {
|
|
15459
|
+
assertCryptoKey(key);
|
|
15460
|
+
if (!allowed(key)) {
|
|
15461
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
15462
|
+
}
|
|
15463
|
+
const { apu, apv } = providedParameters;
|
|
15464
|
+
let ephemeralKey;
|
|
15465
|
+
if (providedParameters.epk) {
|
|
15466
|
+
ephemeralKey = await normalizeKey(providedParameters.epk, alg);
|
|
15467
|
+
} else {
|
|
15468
|
+
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
15469
|
+
}
|
|
15470
|
+
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
15471
|
+
const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
15472
|
+
parameters = { epk: { x, crv, kty } };
|
|
15473
|
+
if (kty === "EC")
|
|
15474
|
+
parameters.epk.y = y;
|
|
15475
|
+
if (apu)
|
|
15476
|
+
parameters.apu = encode2(apu);
|
|
15477
|
+
if (apv)
|
|
15478
|
+
parameters.apv = encode2(apv);
|
|
15479
|
+
if (alg === "ECDH-ES") {
|
|
15480
|
+
cek = sharedSecret;
|
|
15481
|
+
break;
|
|
15482
|
+
}
|
|
15483
|
+
cek = providedCek || generateCek(enc);
|
|
15484
|
+
const kwAlg = alg.slice(-6);
|
|
15485
|
+
encryptedKey = await wrap(kwAlg, sharedSecret, cek);
|
|
15486
|
+
break;
|
|
15487
|
+
}
|
|
15488
|
+
case "RSA-OAEP":
|
|
15489
|
+
case "RSA-OAEP-256":
|
|
15490
|
+
case "RSA-OAEP-384":
|
|
15491
|
+
case "RSA-OAEP-512": {
|
|
15492
|
+
cek = providedCek || generateCek(enc);
|
|
15493
|
+
assertCryptoKey(key);
|
|
15494
|
+
encryptedKey = await encrypt2(alg, key, cek);
|
|
15495
|
+
break;
|
|
15496
|
+
}
|
|
15497
|
+
case "PBES2-HS256+A128KW":
|
|
15498
|
+
case "PBES2-HS384+A192KW":
|
|
15499
|
+
case "PBES2-HS512+A256KW": {
|
|
15500
|
+
cek = providedCek || generateCek(enc);
|
|
15501
|
+
const { p2c, p2s } = providedParameters;
|
|
15502
|
+
({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, p2c, p2s));
|
|
15503
|
+
break;
|
|
15504
|
+
}
|
|
15505
|
+
case "A128KW":
|
|
15506
|
+
case "A192KW":
|
|
15507
|
+
case "A256KW": {
|
|
15508
|
+
cek = providedCek || generateCek(enc);
|
|
15509
|
+
encryptedKey = await wrap(alg, key, cek);
|
|
15510
|
+
break;
|
|
15511
|
+
}
|
|
15512
|
+
case "A128GCMKW":
|
|
15513
|
+
case "A192GCMKW":
|
|
15514
|
+
case "A256GCMKW": {
|
|
15515
|
+
cek = providedCek || generateCek(enc);
|
|
15516
|
+
const { iv } = providedParameters;
|
|
15517
|
+
({ encryptedKey, ...parameters } = await wrap3(alg, key, cek, iv));
|
|
15518
|
+
break;
|
|
15519
|
+
}
|
|
15520
|
+
default: {
|
|
15521
|
+
throw new JOSENotSupported(unsupportedAlgHeader);
|
|
15522
|
+
}
|
|
15523
|
+
}
|
|
15524
|
+
return { cek, encryptedKey, parameters };
|
|
15525
|
+
}
|
|
15526
|
+
|
|
15527
|
+
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
15528
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
15529
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
15530
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
15531
|
+
}
|
|
15532
|
+
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
15533
|
+
return /* @__PURE__ */ new Set();
|
|
15534
|
+
}
|
|
15535
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
15536
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
15537
|
+
}
|
|
15538
|
+
let recognized;
|
|
15539
|
+
if (recognizedOption !== void 0) {
|
|
15540
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
15541
|
+
} else {
|
|
15542
|
+
recognized = recognizedDefault;
|
|
15543
|
+
}
|
|
15544
|
+
for (const parameter of protectedHeader.crit) {
|
|
15545
|
+
if (!recognized.has(parameter)) {
|
|
15546
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
15547
|
+
}
|
|
15548
|
+
if (joseHeader[parameter] === void 0) {
|
|
15549
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
15550
|
+
}
|
|
15551
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
15552
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
15386
15553
|
}
|
|
15387
|
-
return handleJWK(key, key, alg, true);
|
|
15388
15554
|
}
|
|
15389
|
-
|
|
15390
|
-
}
|
|
15555
|
+
return new Set(protectedHeader.crit);
|
|
15556
|
+
}
|
|
15557
|
+
|
|
15558
|
+
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
15559
|
+
function validateAlgorithms(option, algorithms) {
|
|
15560
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
15561
|
+
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
15562
|
+
}
|
|
15563
|
+
if (!algorithms) {
|
|
15564
|
+
return void 0;
|
|
15565
|
+
}
|
|
15566
|
+
return new Set(algorithms);
|
|
15567
|
+
}
|
|
15391
15568
|
|
|
15392
15569
|
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
15393
15570
|
var tag = (key) => key?.[Symbol.toStringTag];
|
|
@@ -15450,7 +15627,7 @@ var symmetricTypeCheck = (alg, key, usage2) => {
|
|
|
15450
15627
|
return;
|
|
15451
15628
|
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
15452
15629
|
}
|
|
15453
|
-
if (!
|
|
15630
|
+
if (!isKeyLike(key)) {
|
|
15454
15631
|
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
15455
15632
|
}
|
|
15456
15633
|
if (key.type !== "secret") {
|
|
@@ -15464,15 +15641,15 @@ var asymmetricTypeCheck = (alg, key, usage2) => {
|
|
|
15464
15641
|
case "sign":
|
|
15465
15642
|
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage2))
|
|
15466
15643
|
return;
|
|
15467
|
-
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
15644
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
15468
15645
|
case "encrypt":
|
|
15469
15646
|
case "verify":
|
|
15470
15647
|
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage2))
|
|
15471
15648
|
return;
|
|
15472
|
-
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
15649
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
15473
15650
|
}
|
|
15474
15651
|
}
|
|
15475
|
-
if (!
|
|
15652
|
+
if (!isKeyLike(key)) {
|
|
15476
15653
|
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
15477
15654
|
}
|
|
15478
15655
|
if (key.type === "secret") {
|
|
@@ -15484,8 +15661,6 @@ var asymmetricTypeCheck = (alg, key, usage2) => {
|
|
|
15484
15661
|
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
15485
15662
|
case "decrypt":
|
|
15486
15663
|
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
15487
|
-
default:
|
|
15488
|
-
break;
|
|
15489
15664
|
}
|
|
15490
15665
|
}
|
|
15491
15666
|
if (key.type === "private") {
|
|
@@ -15494,23 +15669,70 @@ var asymmetricTypeCheck = (alg, key, usage2) => {
|
|
|
15494
15669
|
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
15495
15670
|
case "encrypt":
|
|
15496
15671
|
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
15497
|
-
default:
|
|
15498
|
-
break;
|
|
15499
15672
|
}
|
|
15500
15673
|
}
|
|
15501
15674
|
};
|
|
15502
|
-
|
|
15503
|
-
|
|
15504
|
-
|
|
15505
|
-
|
|
15506
|
-
|
|
15507
|
-
|
|
15675
|
+
function checkKeyType(alg, key, usage2) {
|
|
15676
|
+
switch (alg.substring(0, 2)) {
|
|
15677
|
+
case "A1":
|
|
15678
|
+
case "A2":
|
|
15679
|
+
case "di":
|
|
15680
|
+
case "HS":
|
|
15681
|
+
case "PB":
|
|
15682
|
+
symmetricTypeCheck(alg, key, usage2);
|
|
15683
|
+
break;
|
|
15684
|
+
default:
|
|
15685
|
+
asymmetricTypeCheck(alg, key, usage2);
|
|
15508
15686
|
}
|
|
15509
|
-
}
|
|
15687
|
+
}
|
|
15688
|
+
|
|
15689
|
+
// node_modules/jose/dist/webapi/lib/deflate.js
|
|
15690
|
+
function supported(name) {
|
|
15691
|
+
if (typeof globalThis[name] === "undefined") {
|
|
15692
|
+
throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
|
|
15693
|
+
}
|
|
15694
|
+
}
|
|
15695
|
+
async function compress(input) {
|
|
15696
|
+
supported("CompressionStream");
|
|
15697
|
+
const cs = new CompressionStream("deflate-raw");
|
|
15698
|
+
const writer = cs.writable.getWriter();
|
|
15699
|
+
writer.write(input);
|
|
15700
|
+
writer.close();
|
|
15701
|
+
const chunks = [];
|
|
15702
|
+
const reader = cs.readable.getReader();
|
|
15703
|
+
for (; ; ) {
|
|
15704
|
+
const { value, done } = await reader.read();
|
|
15705
|
+
if (done)
|
|
15706
|
+
break;
|
|
15707
|
+
chunks.push(value);
|
|
15708
|
+
}
|
|
15709
|
+
return concat(...chunks);
|
|
15710
|
+
}
|
|
15711
|
+
async function decompress(input, maxLength) {
|
|
15712
|
+
supported("DecompressionStream");
|
|
15713
|
+
const ds = new DecompressionStream("deflate-raw");
|
|
15714
|
+
const writer = ds.writable.getWriter();
|
|
15715
|
+
writer.write(input);
|
|
15716
|
+
writer.close();
|
|
15717
|
+
const chunks = [];
|
|
15718
|
+
let length = 0;
|
|
15719
|
+
const reader = ds.readable.getReader();
|
|
15720
|
+
for (; ; ) {
|
|
15721
|
+
const { value, done } = await reader.read();
|
|
15722
|
+
if (done)
|
|
15723
|
+
break;
|
|
15724
|
+
chunks.push(value);
|
|
15725
|
+
length += value.byteLength;
|
|
15726
|
+
if (maxLength !== Infinity && length > maxLength) {
|
|
15727
|
+
throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
|
|
15728
|
+
}
|
|
15729
|
+
}
|
|
15730
|
+
return concat(...chunks);
|
|
15731
|
+
}
|
|
15510
15732
|
|
|
15511
15733
|
// node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
15512
15734
|
async function flattenedDecrypt(jwe, key, options) {
|
|
15513
|
-
if (!
|
|
15735
|
+
if (!isObject(jwe)) {
|
|
15514
15736
|
throw new JWEInvalid("Flattened JWE must be an object");
|
|
15515
15737
|
}
|
|
15516
15738
|
if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
|
|
@@ -15534,10 +15756,10 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
15534
15756
|
if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
|
|
15535
15757
|
throw new JWEInvalid("JWE AAD incorrect type");
|
|
15536
15758
|
}
|
|
15537
|
-
if (jwe.header !== void 0 && !
|
|
15759
|
+
if (jwe.header !== void 0 && !isObject(jwe.header)) {
|
|
15538
15760
|
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
15539
15761
|
}
|
|
15540
|
-
if (jwe.unprotected !== void 0 && !
|
|
15762
|
+
if (jwe.unprotected !== void 0 && !isObject(jwe.unprotected)) {
|
|
15541
15763
|
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
15542
15764
|
}
|
|
15543
15765
|
let parsedProt;
|
|
@@ -15549,7 +15771,7 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
15549
15771
|
throw new JWEInvalid("JWE Protected Header is invalid");
|
|
15550
15772
|
}
|
|
15551
15773
|
}
|
|
15552
|
-
if (!
|
|
15774
|
+
if (!isDisjoint(parsedProt, jwe.header, jwe.unprotected)) {
|
|
15553
15775
|
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
15554
15776
|
}
|
|
15555
15777
|
const joseHeader = {
|
|
@@ -15557,9 +15779,12 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
15557
15779
|
...jwe.header,
|
|
15558
15780
|
...jwe.unprotected
|
|
15559
15781
|
};
|
|
15560
|
-
|
|
15561
|
-
if (joseHeader.zip !== void 0) {
|
|
15562
|
-
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter
|
|
15782
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
|
|
15783
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") {
|
|
15784
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
15785
|
+
}
|
|
15786
|
+
if (joseHeader.zip !== void 0 && !parsedProt?.zip) {
|
|
15787
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
15563
15788
|
}
|
|
15564
15789
|
const { alg, enc } = joseHeader;
|
|
15565
15790
|
if (typeof alg !== "string" || !alg) {
|
|
@@ -15568,8 +15793,8 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
15568
15793
|
if (typeof enc !== "string" || !enc) {
|
|
15569
15794
|
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
15570
15795
|
}
|
|
15571
|
-
const keyManagementAlgorithms = options &&
|
|
15572
|
-
const contentEncryptionAlgorithms = options &&
|
|
15796
|
+
const keyManagementAlgorithms = options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms);
|
|
15797
|
+
const contentEncryptionAlgorithms = options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
|
|
15573
15798
|
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
15574
15799
|
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
15575
15800
|
}
|
|
@@ -15578,68 +15803,57 @@ async function flattenedDecrypt(jwe, key, options) {
|
|
|
15578
15803
|
}
|
|
15579
15804
|
let encryptedKey;
|
|
15580
15805
|
if (jwe.encrypted_key !== void 0) {
|
|
15581
|
-
|
|
15582
|
-
encryptedKey = decode(jwe.encrypted_key);
|
|
15583
|
-
} catch {
|
|
15584
|
-
throw new JWEInvalid("Failed to base64url decode the encrypted_key");
|
|
15585
|
-
}
|
|
15806
|
+
encryptedKey = decodeBase64url(jwe.encrypted_key, "encrypted_key", JWEInvalid);
|
|
15586
15807
|
}
|
|
15587
15808
|
let resolvedKey = false;
|
|
15588
15809
|
if (typeof key === "function") {
|
|
15589
15810
|
key = await key(parsedProt, jwe);
|
|
15590
15811
|
resolvedKey = true;
|
|
15591
15812
|
}
|
|
15592
|
-
|
|
15593
|
-
const k = await
|
|
15813
|
+
checkKeyType(alg === "dir" ? enc : alg, key, "decrypt");
|
|
15814
|
+
const k = await normalizeKey(key, alg);
|
|
15594
15815
|
let cek;
|
|
15595
15816
|
try {
|
|
15596
|
-
cek = await
|
|
15817
|
+
cek = await decryptKeyManagement(alg, k, encryptedKey, joseHeader, options);
|
|
15597
15818
|
} catch (err) {
|
|
15598
15819
|
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
15599
15820
|
throw err;
|
|
15600
15821
|
}
|
|
15601
|
-
cek =
|
|
15822
|
+
cek = generateCek(enc);
|
|
15602
15823
|
}
|
|
15603
15824
|
let iv;
|
|
15604
15825
|
let tag2;
|
|
15605
15826
|
if (jwe.iv !== void 0) {
|
|
15606
|
-
|
|
15607
|
-
iv = decode(jwe.iv);
|
|
15608
|
-
} catch {
|
|
15609
|
-
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
15610
|
-
}
|
|
15827
|
+
iv = decodeBase64url(jwe.iv, "iv", JWEInvalid);
|
|
15611
15828
|
}
|
|
15612
15829
|
if (jwe.tag !== void 0) {
|
|
15613
|
-
|
|
15614
|
-
tag2 = decode(jwe.tag);
|
|
15615
|
-
} catch {
|
|
15616
|
-
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
15617
|
-
}
|
|
15830
|
+
tag2 = decodeBase64url(jwe.tag, "tag", JWEInvalid);
|
|
15618
15831
|
}
|
|
15619
|
-
const protectedHeader =
|
|
15832
|
+
const protectedHeader = jwe.protected !== void 0 ? encode(jwe.protected) : new Uint8Array();
|
|
15620
15833
|
let additionalData;
|
|
15621
15834
|
if (jwe.aad !== void 0) {
|
|
15622
|
-
additionalData = concat(protectedHeader,
|
|
15835
|
+
additionalData = concat(protectedHeader, encode("."), encode(jwe.aad));
|
|
15623
15836
|
} else {
|
|
15624
15837
|
additionalData = protectedHeader;
|
|
15625
15838
|
}
|
|
15626
|
-
|
|
15627
|
-
|
|
15628
|
-
ciphertext = decode(jwe.ciphertext);
|
|
15629
|
-
} catch {
|
|
15630
|
-
throw new JWEInvalid("Failed to base64url decode the ciphertext");
|
|
15631
|
-
}
|
|
15632
|
-
const plaintext = await decrypt_default(enc, cek, ciphertext, iv, tag2, additionalData);
|
|
15839
|
+
const ciphertext = decodeBase64url(jwe.ciphertext, "ciphertext", JWEInvalid);
|
|
15840
|
+
const plaintext = await decrypt(enc, cek, ciphertext, iv, tag2, additionalData);
|
|
15633
15841
|
const result = { plaintext };
|
|
15842
|
+
if (joseHeader.zip === "DEF") {
|
|
15843
|
+
const maxDecompressedLength = options?.maxDecompressedLength ?? 25e4;
|
|
15844
|
+
if (maxDecompressedLength === 0) {
|
|
15845
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
15846
|
+
}
|
|
15847
|
+
if (maxDecompressedLength !== Infinity && (!Number.isSafeInteger(maxDecompressedLength) || maxDecompressedLength < 1)) {
|
|
15848
|
+
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
15849
|
+
}
|
|
15850
|
+
result.plaintext = await decompress(plaintext, maxDecompressedLength);
|
|
15851
|
+
}
|
|
15634
15852
|
if (jwe.protected !== void 0) {
|
|
15635
15853
|
result.protectedHeader = parsedProt;
|
|
15636
15854
|
}
|
|
15637
15855
|
if (jwe.aad !== void 0) {
|
|
15638
|
-
|
|
15639
|
-
result.additionalAuthenticatedData = decode(jwe.aad);
|
|
15640
|
-
} catch {
|
|
15641
|
-
throw new JWEInvalid("Failed to base64url decode the aad");
|
|
15642
|
-
}
|
|
15856
|
+
result.additionalAuthenticatedData = decodeBase64url(jwe.aad, "aad", JWEInvalid);
|
|
15643
15857
|
}
|
|
15644
15858
|
if (jwe.unprotected !== void 0) {
|
|
15645
15859
|
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
@@ -15679,125 +15893,6 @@ async function compactDecrypt(jwe, key, options) {
|
|
|
15679
15893
|
return result;
|
|
15680
15894
|
}
|
|
15681
15895
|
|
|
15682
|
-
// node_modules/jose/dist/webapi/lib/private_symbols.js
|
|
15683
|
-
var unprotected = Symbol();
|
|
15684
|
-
|
|
15685
|
-
// node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
15686
|
-
async function keyToJWK(key) {
|
|
15687
|
-
if (isKeyObject(key)) {
|
|
15688
|
-
if (key.type === "secret") {
|
|
15689
|
-
key = key.export();
|
|
15690
|
-
} else {
|
|
15691
|
-
return key.export({ format: "jwk" });
|
|
15692
|
-
}
|
|
15693
|
-
}
|
|
15694
|
-
if (key instanceof Uint8Array) {
|
|
15695
|
-
return {
|
|
15696
|
-
kty: "oct",
|
|
15697
|
-
k: encode(key)
|
|
15698
|
-
};
|
|
15699
|
-
}
|
|
15700
|
-
if (!isCryptoKey(key)) {
|
|
15701
|
-
throw new TypeError(invalid_key_input_default(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
15702
|
-
}
|
|
15703
|
-
if (!key.extractable) {
|
|
15704
|
-
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
15705
|
-
}
|
|
15706
|
-
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
15707
|
-
if (jwk.kty === "AKP") {
|
|
15708
|
-
;
|
|
15709
|
-
jwk.alg = alg;
|
|
15710
|
-
}
|
|
15711
|
-
return jwk;
|
|
15712
|
-
}
|
|
15713
|
-
|
|
15714
|
-
// node_modules/jose/dist/webapi/key/export.js
|
|
15715
|
-
async function exportJWK(key) {
|
|
15716
|
-
return keyToJWK(key);
|
|
15717
|
-
}
|
|
15718
|
-
|
|
15719
|
-
// node_modules/jose/dist/webapi/lib/encrypt_key_management.js
|
|
15720
|
-
var encrypt_key_management_default = async (alg, enc, key, providedCek, providedParameters = {}) => {
|
|
15721
|
-
let encryptedKey;
|
|
15722
|
-
let parameters;
|
|
15723
|
-
let cek;
|
|
15724
|
-
switch (alg) {
|
|
15725
|
-
case "dir": {
|
|
15726
|
-
cek = key;
|
|
15727
|
-
break;
|
|
15728
|
-
}
|
|
15729
|
-
case "ECDH-ES":
|
|
15730
|
-
case "ECDH-ES+A128KW":
|
|
15731
|
-
case "ECDH-ES+A192KW":
|
|
15732
|
-
case "ECDH-ES+A256KW": {
|
|
15733
|
-
assertCryptoKey(key);
|
|
15734
|
-
if (!allowed(key)) {
|
|
15735
|
-
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
15736
|
-
}
|
|
15737
|
-
const { apu, apv } = providedParameters;
|
|
15738
|
-
let ephemeralKey;
|
|
15739
|
-
if (providedParameters.epk) {
|
|
15740
|
-
ephemeralKey = await normalize_key_default(providedParameters.epk, alg);
|
|
15741
|
-
} else {
|
|
15742
|
-
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
15743
|
-
}
|
|
15744
|
-
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
15745
|
-
const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? bitLength2(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
15746
|
-
parameters = { epk: { x, crv, kty } };
|
|
15747
|
-
if (kty === "EC")
|
|
15748
|
-
parameters.epk.y = y;
|
|
15749
|
-
if (apu)
|
|
15750
|
-
parameters.apu = encode(apu);
|
|
15751
|
-
if (apv)
|
|
15752
|
-
parameters.apv = encode(apv);
|
|
15753
|
-
if (alg === "ECDH-ES") {
|
|
15754
|
-
cek = sharedSecret;
|
|
15755
|
-
break;
|
|
15756
|
-
}
|
|
15757
|
-
cek = providedCek || cek_default(enc);
|
|
15758
|
-
const kwAlg = alg.slice(-6);
|
|
15759
|
-
encryptedKey = await wrap(kwAlg, sharedSecret, cek);
|
|
15760
|
-
break;
|
|
15761
|
-
}
|
|
15762
|
-
case "RSA-OAEP":
|
|
15763
|
-
case "RSA-OAEP-256":
|
|
15764
|
-
case "RSA-OAEP-384":
|
|
15765
|
-
case "RSA-OAEP-512": {
|
|
15766
|
-
cek = providedCek || cek_default(enc);
|
|
15767
|
-
assertCryptoKey(key);
|
|
15768
|
-
encryptedKey = await encrypt(alg, key, cek);
|
|
15769
|
-
break;
|
|
15770
|
-
}
|
|
15771
|
-
case "PBES2-HS256+A128KW":
|
|
15772
|
-
case "PBES2-HS384+A192KW":
|
|
15773
|
-
case "PBES2-HS512+A256KW": {
|
|
15774
|
-
cek = providedCek || cek_default(enc);
|
|
15775
|
-
const { p2c, p2s } = providedParameters;
|
|
15776
|
-
({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, p2c, p2s));
|
|
15777
|
-
break;
|
|
15778
|
-
}
|
|
15779
|
-
case "A128KW":
|
|
15780
|
-
case "A192KW":
|
|
15781
|
-
case "A256KW": {
|
|
15782
|
-
cek = providedCek || cek_default(enc);
|
|
15783
|
-
encryptedKey = await wrap(alg, key, cek);
|
|
15784
|
-
break;
|
|
15785
|
-
}
|
|
15786
|
-
case "A128GCMKW":
|
|
15787
|
-
case "A192GCMKW":
|
|
15788
|
-
case "A256GCMKW": {
|
|
15789
|
-
cek = providedCek || cek_default(enc);
|
|
15790
|
-
const { iv } = providedParameters;
|
|
15791
|
-
({ encryptedKey, ...parameters } = await wrap3(alg, key, cek, iv));
|
|
15792
|
-
break;
|
|
15793
|
-
}
|
|
15794
|
-
default: {
|
|
15795
|
-
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
15796
|
-
}
|
|
15797
|
-
}
|
|
15798
|
-
return { cek, encryptedKey, parameters };
|
|
15799
|
-
};
|
|
15800
|
-
|
|
15801
15896
|
// node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
15802
15897
|
var FlattenedEncrypt = class {
|
|
15803
15898
|
#plaintext;
|
|
@@ -15815,30 +15910,22 @@ var FlattenedEncrypt = class {
|
|
|
15815
15910
|
this.#plaintext = plaintext;
|
|
15816
15911
|
}
|
|
15817
15912
|
setKeyManagementParameters(parameters) {
|
|
15818
|
-
|
|
15819
|
-
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
15820
|
-
}
|
|
15913
|
+
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
15821
15914
|
this.#keyManagementParameters = parameters;
|
|
15822
15915
|
return this;
|
|
15823
15916
|
}
|
|
15824
15917
|
setProtectedHeader(protectedHeader) {
|
|
15825
|
-
|
|
15826
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
15827
|
-
}
|
|
15918
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
15828
15919
|
this.#protectedHeader = protectedHeader;
|
|
15829
15920
|
return this;
|
|
15830
15921
|
}
|
|
15831
15922
|
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
15832
|
-
|
|
15833
|
-
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
15834
|
-
}
|
|
15923
|
+
assertNotSet(this.#sharedUnprotectedHeader, "setSharedUnprotectedHeader");
|
|
15835
15924
|
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
15836
15925
|
return this;
|
|
15837
15926
|
}
|
|
15838
15927
|
setUnprotectedHeader(unprotectedHeader) {
|
|
15839
|
-
|
|
15840
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
15841
|
-
}
|
|
15928
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
15842
15929
|
this.#unprotectedHeader = unprotectedHeader;
|
|
15843
15930
|
return this;
|
|
15844
15931
|
}
|
|
@@ -15847,16 +15934,12 @@ var FlattenedEncrypt = class {
|
|
|
15847
15934
|
return this;
|
|
15848
15935
|
}
|
|
15849
15936
|
setContentEncryptionKey(cek) {
|
|
15850
|
-
|
|
15851
|
-
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
15852
|
-
}
|
|
15937
|
+
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
15853
15938
|
this.#cek = cek;
|
|
15854
15939
|
return this;
|
|
15855
15940
|
}
|
|
15856
15941
|
setInitializationVector(iv) {
|
|
15857
|
-
|
|
15858
|
-
throw new TypeError("setInitializationVector can only be called once");
|
|
15859
|
-
}
|
|
15942
|
+
assertNotSet(this.#iv, "setInitializationVector");
|
|
15860
15943
|
this.#iv = iv;
|
|
15861
15944
|
return this;
|
|
15862
15945
|
}
|
|
@@ -15864,7 +15947,7 @@ var FlattenedEncrypt = class {
|
|
|
15864
15947
|
if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
|
|
15865
15948
|
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
15866
15949
|
}
|
|
15867
|
-
if (!
|
|
15950
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, this.#sharedUnprotectedHeader)) {
|
|
15868
15951
|
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
15869
15952
|
}
|
|
15870
15953
|
const joseHeader = {
|
|
@@ -15872,9 +15955,12 @@ var FlattenedEncrypt = class {
|
|
|
15872
15955
|
...this.#unprotectedHeader,
|
|
15873
15956
|
...this.#sharedUnprotectedHeader
|
|
15874
15957
|
};
|
|
15875
|
-
|
|
15876
|
-
if (joseHeader.zip !== void 0) {
|
|
15877
|
-
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter
|
|
15958
|
+
validateCrit(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this.#protectedHeader, joseHeader);
|
|
15959
|
+
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") {
|
|
15960
|
+
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
15961
|
+
}
|
|
15962
|
+
if (joseHeader.zip !== void 0 && !this.#protectedHeader?.zip) {
|
|
15963
|
+
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
15878
15964
|
}
|
|
15879
15965
|
const { alg, enc } = joseHeader;
|
|
15880
15966
|
if (typeof alg !== "string" || !alg) {
|
|
@@ -15887,12 +15973,12 @@ var FlattenedEncrypt = class {
|
|
|
15887
15973
|
if (this.#cek && (alg === "dir" || alg === "ECDH-ES")) {
|
|
15888
15974
|
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
15889
15975
|
}
|
|
15890
|
-
|
|
15976
|
+
checkKeyType(alg === "dir" ? enc : alg, key, "encrypt");
|
|
15891
15977
|
let cek;
|
|
15892
15978
|
{
|
|
15893
15979
|
let parameters;
|
|
15894
|
-
const k = await
|
|
15895
|
-
({ cek, encryptedKey, parameters } = await
|
|
15980
|
+
const k = await normalizeKey(key, alg);
|
|
15981
|
+
({ cek, encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, this.#cek, this.#keyManagementParameters));
|
|
15896
15982
|
if (parameters) {
|
|
15897
15983
|
if (options && unprotected in options) {
|
|
15898
15984
|
if (!this.#unprotectedHeader) {
|
|
@@ -15908,37 +15994,45 @@ var FlattenedEncrypt = class {
|
|
|
15908
15994
|
}
|
|
15909
15995
|
}
|
|
15910
15996
|
let additionalData;
|
|
15911
|
-
let
|
|
15997
|
+
let protectedHeaderS;
|
|
15998
|
+
let protectedHeaderB;
|
|
15912
15999
|
let aadMember;
|
|
15913
16000
|
if (this.#protectedHeader) {
|
|
15914
|
-
|
|
16001
|
+
protectedHeaderS = encode2(JSON.stringify(this.#protectedHeader));
|
|
16002
|
+
protectedHeaderB = encode(protectedHeaderS);
|
|
15915
16003
|
} else {
|
|
15916
|
-
|
|
16004
|
+
protectedHeaderS = "";
|
|
16005
|
+
protectedHeaderB = new Uint8Array();
|
|
15917
16006
|
}
|
|
15918
16007
|
if (this.#aad) {
|
|
15919
|
-
aadMember =
|
|
15920
|
-
|
|
16008
|
+
aadMember = encode2(this.#aad);
|
|
16009
|
+
const aadMemberBytes = encode(aadMember);
|
|
16010
|
+
additionalData = concat(protectedHeaderB, encode("."), aadMemberBytes);
|
|
15921
16011
|
} else {
|
|
15922
|
-
additionalData =
|
|
16012
|
+
additionalData = protectedHeaderB;
|
|
15923
16013
|
}
|
|
15924
|
-
|
|
16014
|
+
let plaintext = this.#plaintext;
|
|
16015
|
+
if (joseHeader.zip === "DEF") {
|
|
16016
|
+
plaintext = await compress(plaintext);
|
|
16017
|
+
}
|
|
16018
|
+
const { ciphertext, tag: tag2, iv } = await encrypt(enc, plaintext, cek, this.#iv, additionalData);
|
|
15925
16019
|
const jwe = {
|
|
15926
|
-
ciphertext:
|
|
16020
|
+
ciphertext: encode2(ciphertext)
|
|
15927
16021
|
};
|
|
15928
16022
|
if (iv) {
|
|
15929
|
-
jwe.iv =
|
|
16023
|
+
jwe.iv = encode2(iv);
|
|
15930
16024
|
}
|
|
15931
16025
|
if (tag2) {
|
|
15932
|
-
jwe.tag =
|
|
16026
|
+
jwe.tag = encode2(tag2);
|
|
15933
16027
|
}
|
|
15934
16028
|
if (encryptedKey) {
|
|
15935
|
-
jwe.encrypted_key =
|
|
16029
|
+
jwe.encrypted_key = encode2(encryptedKey);
|
|
15936
16030
|
}
|
|
15937
16031
|
if (aadMember) {
|
|
15938
16032
|
jwe.aad = aadMember;
|
|
15939
16033
|
}
|
|
15940
16034
|
if (this.#protectedHeader) {
|
|
15941
|
-
jwe.protected =
|
|
16035
|
+
jwe.protected = protectedHeaderS;
|
|
15942
16036
|
}
|
|
15943
16037
|
if (this.#sharedUnprotectedHeader) {
|
|
15944
16038
|
jwe.unprotected = this.#sharedUnprotectedHeader;
|
|
@@ -15950,65 +16044,9 @@ var FlattenedEncrypt = class {
|
|
|
15950
16044
|
}
|
|
15951
16045
|
};
|
|
15952
16046
|
|
|
15953
|
-
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
15954
|
-
var subtle_dsa_default = (alg, algorithm) => {
|
|
15955
|
-
const hash = `SHA-${alg.slice(-3)}`;
|
|
15956
|
-
switch (alg) {
|
|
15957
|
-
case "HS256":
|
|
15958
|
-
case "HS384":
|
|
15959
|
-
case "HS512":
|
|
15960
|
-
return { hash, name: "HMAC" };
|
|
15961
|
-
case "PS256":
|
|
15962
|
-
case "PS384":
|
|
15963
|
-
case "PS512":
|
|
15964
|
-
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
15965
|
-
case "RS256":
|
|
15966
|
-
case "RS384":
|
|
15967
|
-
case "RS512":
|
|
15968
|
-
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
15969
|
-
case "ES256":
|
|
15970
|
-
case "ES384":
|
|
15971
|
-
case "ES512":
|
|
15972
|
-
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
15973
|
-
case "Ed25519":
|
|
15974
|
-
case "EdDSA":
|
|
15975
|
-
return { name: "Ed25519" };
|
|
15976
|
-
case "ML-DSA-44":
|
|
15977
|
-
case "ML-DSA-65":
|
|
15978
|
-
case "ML-DSA-87":
|
|
15979
|
-
return { name: alg };
|
|
15980
|
-
default:
|
|
15981
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
15982
|
-
}
|
|
15983
|
-
};
|
|
15984
|
-
|
|
15985
|
-
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
15986
|
-
var get_sign_verify_key_default = async (alg, key, usage2) => {
|
|
15987
|
-
if (key instanceof Uint8Array) {
|
|
15988
|
-
if (!alg.startsWith("HS")) {
|
|
15989
|
-
throw new TypeError(invalid_key_input_default(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
15990
|
-
}
|
|
15991
|
-
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage2]);
|
|
15992
|
-
}
|
|
15993
|
-
checkSigCryptoKey(key, alg, usage2);
|
|
15994
|
-
return key;
|
|
15995
|
-
};
|
|
15996
|
-
|
|
15997
|
-
// node_modules/jose/dist/webapi/lib/verify.js
|
|
15998
|
-
var verify_default = async (alg, key, signature, data) => {
|
|
15999
|
-
const cryptoKey = await get_sign_verify_key_default(alg, key, "verify");
|
|
16000
|
-
check_key_length_default(alg, cryptoKey);
|
|
16001
|
-
const algorithm = subtle_dsa_default(alg, cryptoKey.algorithm);
|
|
16002
|
-
try {
|
|
16003
|
-
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
16004
|
-
} catch {
|
|
16005
|
-
return false;
|
|
16006
|
-
}
|
|
16007
|
-
};
|
|
16008
|
-
|
|
16009
16047
|
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
16010
16048
|
async function flattenedVerify(jws, key, options) {
|
|
16011
|
-
if (!
|
|
16049
|
+
if (!isObject(jws)) {
|
|
16012
16050
|
throw new JWSInvalid("Flattened JWS must be an object");
|
|
16013
16051
|
}
|
|
16014
16052
|
if (jws.protected === void 0 && jws.header === void 0) {
|
|
@@ -16023,7 +16061,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
16023
16061
|
if (typeof jws.signature !== "string") {
|
|
16024
16062
|
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
16025
16063
|
}
|
|
16026
|
-
if (jws.header !== void 0 && !
|
|
16064
|
+
if (jws.header !== void 0 && !isObject(jws.header)) {
|
|
16027
16065
|
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
16028
16066
|
}
|
|
16029
16067
|
let parsedProt = {};
|
|
@@ -16035,14 +16073,14 @@ async function flattenedVerify(jws, key, options) {
|
|
|
16035
16073
|
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
16036
16074
|
}
|
|
16037
16075
|
}
|
|
16038
|
-
if (!
|
|
16076
|
+
if (!isDisjoint(parsedProt, jws.header)) {
|
|
16039
16077
|
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
16040
16078
|
}
|
|
16041
16079
|
const joseHeader = {
|
|
16042
16080
|
...parsedProt,
|
|
16043
16081
|
...jws.header
|
|
16044
16082
|
};
|
|
16045
|
-
const extensions =
|
|
16083
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
16046
16084
|
let b64 = true;
|
|
16047
16085
|
if (extensions.has("b64")) {
|
|
16048
16086
|
b64 = parsedProt.b64;
|
|
@@ -16054,7 +16092,7 @@ async function flattenedVerify(jws, key, options) {
|
|
|
16054
16092
|
if (typeof alg !== "string" || !alg) {
|
|
16055
16093
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
16056
16094
|
}
|
|
16057
|
-
const algorithms = options &&
|
|
16095
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
16058
16096
|
if (algorithms && !algorithms.has(alg)) {
|
|
16059
16097
|
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
16060
16098
|
}
|
|
@@ -16070,26 +16108,17 @@ async function flattenedVerify(jws, key, options) {
|
|
|
16070
16108
|
key = await key(parsedProt, jws);
|
|
16071
16109
|
resolvedKey = true;
|
|
16072
16110
|
}
|
|
16073
|
-
|
|
16074
|
-
const data = concat(
|
|
16075
|
-
|
|
16076
|
-
|
|
16077
|
-
|
|
16078
|
-
} catch {
|
|
16079
|
-
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
16080
|
-
}
|
|
16081
|
-
const k = await normalize_key_default(key, alg);
|
|
16082
|
-
const verified = await verify_default(alg, k, signature, data);
|
|
16111
|
+
checkKeyType(alg, key, "verify");
|
|
16112
|
+
const data = concat(jws.protected !== void 0 ? encode(jws.protected) : new Uint8Array(), encode("."), typeof jws.payload === "string" ? b64 ? encode(jws.payload) : encoder.encode(jws.payload) : jws.payload);
|
|
16113
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
16114
|
+
const k = await normalizeKey(key, alg);
|
|
16115
|
+
const verified = await verify(alg, k, signature, data);
|
|
16083
16116
|
if (!verified) {
|
|
16084
16117
|
throw new JWSSignatureVerificationFailed();
|
|
16085
16118
|
}
|
|
16086
16119
|
let payload;
|
|
16087
16120
|
if (b64) {
|
|
16088
|
-
|
|
16089
|
-
payload = decode(jws.payload);
|
|
16090
|
-
} catch {
|
|
16091
|
-
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
16092
|
-
}
|
|
16121
|
+
payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
16093
16122
|
} else if (typeof jws.payload === "string") {
|
|
16094
16123
|
payload = encoder.encode(jws.payload);
|
|
16095
16124
|
} else {
|
|
@@ -16128,17 +16157,15 @@ async function compactVerify(jws, key, options) {
|
|
|
16128
16157
|
return result;
|
|
16129
16158
|
}
|
|
16130
16159
|
|
|
16131
|
-
// node_modules/jose/dist/webapi/lib/
|
|
16132
|
-
var
|
|
16133
|
-
|
|
16134
|
-
// node_modules/jose/dist/webapi/lib/secs.js
|
|
16160
|
+
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
16161
|
+
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
16135
16162
|
var minute = 60;
|
|
16136
16163
|
var hour = minute * 60;
|
|
16137
16164
|
var day = hour * 24;
|
|
16138
16165
|
var week = day * 7;
|
|
16139
16166
|
var year = day * 365.25;
|
|
16140
16167
|
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
16141
|
-
|
|
16168
|
+
function secs(str) {
|
|
16142
16169
|
const matched = REGEX.exec(str);
|
|
16143
16170
|
if (!matched || matched[4] && matched[1]) {
|
|
16144
16171
|
throw new TypeError("Invalid time period format");
|
|
@@ -16186,9 +16213,7 @@ var secs_default = (str) => {
|
|
|
16186
16213
|
return -numericDate;
|
|
16187
16214
|
}
|
|
16188
16215
|
return numericDate;
|
|
16189
|
-
}
|
|
16190
|
-
|
|
16191
|
-
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
16216
|
+
}
|
|
16192
16217
|
function validateInput(label, input) {
|
|
16193
16218
|
if (!Number.isFinite(input)) {
|
|
16194
16219
|
throw new TypeError(`Invalid ${label} input`);
|
|
@@ -16216,7 +16241,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
16216
16241
|
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
16217
16242
|
} catch {
|
|
16218
16243
|
}
|
|
16219
|
-
if (!
|
|
16244
|
+
if (!isObject(payload)) {
|
|
16220
16245
|
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
16221
16246
|
}
|
|
16222
16247
|
const { typ } = options;
|
|
@@ -16250,7 +16275,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
16250
16275
|
let tolerance;
|
|
16251
16276
|
switch (typeof options.clockTolerance) {
|
|
16252
16277
|
case "string":
|
|
16253
|
-
tolerance =
|
|
16278
|
+
tolerance = secs(options.clockTolerance);
|
|
16254
16279
|
break;
|
|
16255
16280
|
case "number":
|
|
16256
16281
|
tolerance = options.clockTolerance;
|
|
@@ -16262,7 +16287,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
16262
16287
|
throw new TypeError("Invalid clockTolerance option type");
|
|
16263
16288
|
}
|
|
16264
16289
|
const { currentDate } = options;
|
|
16265
|
-
const now =
|
|
16290
|
+
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
16266
16291
|
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
|
|
16267
16292
|
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
|
|
16268
16293
|
}
|
|
@@ -16284,7 +16309,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
16284
16309
|
}
|
|
16285
16310
|
if (maxTokenAge) {
|
|
16286
16311
|
const age = now - payload.iat;
|
|
16287
|
-
const max = typeof maxTokenAge === "number" ? maxTokenAge :
|
|
16312
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
16288
16313
|
if (age - tolerance > max) {
|
|
16289
16314
|
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
|
|
16290
16315
|
}
|
|
@@ -16297,7 +16322,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
|
16297
16322
|
var JWTClaimsBuilder = class {
|
|
16298
16323
|
#payload;
|
|
16299
16324
|
constructor(payload) {
|
|
16300
|
-
if (!
|
|
16325
|
+
if (!isObject(payload)) {
|
|
16301
16326
|
throw new TypeError("JWT Claims Set MUST be an object");
|
|
16302
16327
|
}
|
|
16303
16328
|
this.#payload = structuredClone(payload);
|
|
@@ -16330,27 +16355,27 @@ var JWTClaimsBuilder = class {
|
|
|
16330
16355
|
if (typeof value === "number") {
|
|
16331
16356
|
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
16332
16357
|
} else if (value instanceof Date) {
|
|
16333
|
-
this.#payload.nbf = validateInput("setNotBefore",
|
|
16358
|
+
this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
16334
16359
|
} else {
|
|
16335
|
-
this.#payload.nbf =
|
|
16360
|
+
this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
16336
16361
|
}
|
|
16337
16362
|
}
|
|
16338
16363
|
set exp(value) {
|
|
16339
16364
|
if (typeof value === "number") {
|
|
16340
16365
|
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
16341
16366
|
} else if (value instanceof Date) {
|
|
16342
|
-
this.#payload.exp = validateInput("setExpirationTime",
|
|
16367
|
+
this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
16343
16368
|
} else {
|
|
16344
|
-
this.#payload.exp =
|
|
16369
|
+
this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
16345
16370
|
}
|
|
16346
16371
|
}
|
|
16347
16372
|
set iat(value) {
|
|
16348
|
-
if (
|
|
16349
|
-
this.#payload.iat =
|
|
16373
|
+
if (value === void 0) {
|
|
16374
|
+
this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
16350
16375
|
} else if (value instanceof Date) {
|
|
16351
|
-
this.#payload.iat = validateInput("setIssuedAt",
|
|
16376
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
16352
16377
|
} else if (typeof value === "string") {
|
|
16353
|
-
this.#payload.iat = validateInput("setIssuedAt",
|
|
16378
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
16354
16379
|
} else {
|
|
16355
16380
|
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
16356
16381
|
}
|
|
@@ -16420,14 +16445,6 @@ var CompactEncrypt = class {
|
|
|
16420
16445
|
}
|
|
16421
16446
|
};
|
|
16422
16447
|
|
|
16423
|
-
// node_modules/jose/dist/webapi/lib/sign.js
|
|
16424
|
-
var sign_default = async (alg, key, data) => {
|
|
16425
|
-
const cryptoKey = await get_sign_verify_key_default(alg, key, "sign");
|
|
16426
|
-
check_key_length_default(alg, cryptoKey);
|
|
16427
|
-
const signature = await crypto.subtle.sign(subtle_dsa_default(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
16428
|
-
return new Uint8Array(signature);
|
|
16429
|
-
};
|
|
16430
|
-
|
|
16431
16448
|
// node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
16432
16449
|
var FlattenedSign = class {
|
|
16433
16450
|
#payload;
|
|
@@ -16440,16 +16457,12 @@ var FlattenedSign = class {
|
|
|
16440
16457
|
this.#payload = payload;
|
|
16441
16458
|
}
|
|
16442
16459
|
setProtectedHeader(protectedHeader) {
|
|
16443
|
-
|
|
16444
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
16445
|
-
}
|
|
16460
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
16446
16461
|
this.#protectedHeader = protectedHeader;
|
|
16447
16462
|
return this;
|
|
16448
16463
|
}
|
|
16449
16464
|
setUnprotectedHeader(unprotectedHeader) {
|
|
16450
|
-
|
|
16451
|
-
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
16452
|
-
}
|
|
16465
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
16453
16466
|
this.#unprotectedHeader = unprotectedHeader;
|
|
16454
16467
|
return this;
|
|
16455
16468
|
}
|
|
@@ -16457,14 +16470,14 @@ var FlattenedSign = class {
|
|
|
16457
16470
|
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
16458
16471
|
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
16459
16472
|
}
|
|
16460
|
-
if (!
|
|
16473
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
16461
16474
|
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
16462
16475
|
}
|
|
16463
16476
|
const joseHeader = {
|
|
16464
16477
|
...this.#protectedHeader,
|
|
16465
16478
|
...this.#unprotectedHeader
|
|
16466
16479
|
};
|
|
16467
|
-
const extensions =
|
|
16480
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
16468
16481
|
let b64 = true;
|
|
16469
16482
|
if (extensions.has("b64")) {
|
|
16470
16483
|
b64 = this.#protectedHeader.b64;
|
|
@@ -16476,32 +16489,37 @@ var FlattenedSign = class {
|
|
|
16476
16489
|
if (typeof alg !== "string" || !alg) {
|
|
16477
16490
|
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
16478
16491
|
}
|
|
16479
|
-
|
|
16480
|
-
let
|
|
16492
|
+
checkKeyType(alg, key, "sign");
|
|
16493
|
+
let payloadS;
|
|
16494
|
+
let payloadB;
|
|
16481
16495
|
if (b64) {
|
|
16482
|
-
|
|
16496
|
+
payloadS = encode2(this.#payload);
|
|
16497
|
+
payloadB = encode(payloadS);
|
|
16498
|
+
} else {
|
|
16499
|
+
payloadB = this.#payload;
|
|
16500
|
+
payloadS = "";
|
|
16483
16501
|
}
|
|
16484
|
-
let
|
|
16502
|
+
let protectedHeaderString;
|
|
16503
|
+
let protectedHeaderBytes;
|
|
16485
16504
|
if (this.#protectedHeader) {
|
|
16486
|
-
|
|
16505
|
+
protectedHeaderString = encode2(JSON.stringify(this.#protectedHeader));
|
|
16506
|
+
protectedHeaderBytes = encode(protectedHeaderString);
|
|
16487
16507
|
} else {
|
|
16488
|
-
|
|
16508
|
+
protectedHeaderString = "";
|
|
16509
|
+
protectedHeaderBytes = new Uint8Array();
|
|
16489
16510
|
}
|
|
16490
|
-
const data = concat(
|
|
16491
|
-
const k = await
|
|
16492
|
-
const signature = await
|
|
16511
|
+
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
16512
|
+
const k = await normalizeKey(key, alg);
|
|
16513
|
+
const signature = await sign(alg, k, data);
|
|
16493
16514
|
const jws = {
|
|
16494
|
-
signature:
|
|
16495
|
-
payload:
|
|
16515
|
+
signature: encode2(signature),
|
|
16516
|
+
payload: payloadS
|
|
16496
16517
|
};
|
|
16497
|
-
if (b64) {
|
|
16498
|
-
jws.payload = decoder.decode(payload);
|
|
16499
|
-
}
|
|
16500
16518
|
if (this.#unprotectedHeader) {
|
|
16501
16519
|
jws.header = this.#unprotectedHeader;
|
|
16502
16520
|
}
|
|
16503
16521
|
if (this.#protectedHeader) {
|
|
16504
|
-
jws.protected =
|
|
16522
|
+
jws.protected = protectedHeaderString;
|
|
16505
16523
|
}
|
|
16506
16524
|
return jws;
|
|
16507
16525
|
}
|
|
@@ -16617,30 +16635,22 @@ var EncryptJWT = class {
|
|
|
16617
16635
|
return this;
|
|
16618
16636
|
}
|
|
16619
16637
|
setProtectedHeader(protectedHeader) {
|
|
16620
|
-
|
|
16621
|
-
throw new TypeError("setProtectedHeader can only be called once");
|
|
16622
|
-
}
|
|
16638
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
16623
16639
|
this.#protectedHeader = protectedHeader;
|
|
16624
16640
|
return this;
|
|
16625
16641
|
}
|
|
16626
16642
|
setKeyManagementParameters(parameters) {
|
|
16627
|
-
|
|
16628
|
-
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
16629
|
-
}
|
|
16643
|
+
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
16630
16644
|
this.#keyManagementParameters = parameters;
|
|
16631
16645
|
return this;
|
|
16632
16646
|
}
|
|
16633
16647
|
setContentEncryptionKey(cek) {
|
|
16634
|
-
|
|
16635
|
-
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
16636
|
-
}
|
|
16648
|
+
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
16637
16649
|
this.#cek = cek;
|
|
16638
16650
|
return this;
|
|
16639
16651
|
}
|
|
16640
16652
|
setInitializationVector(iv) {
|
|
16641
|
-
|
|
16642
|
-
throw new TypeError("setInitializationVector can only be called once");
|
|
16643
|
-
}
|
|
16653
|
+
assertNotSet(this.#iv, "setInitializationVector");
|
|
16644
16654
|
this.#iv = iv;
|
|
16645
16655
|
return this;
|
|
16646
16656
|
}
|
|
@@ -16701,7 +16711,7 @@ function decodeProtectedHeader(token) {
|
|
|
16701
16711
|
throw new Error();
|
|
16702
16712
|
}
|
|
16703
16713
|
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
16704
|
-
if (!
|
|
16714
|
+
if (!isObject(result)) {
|
|
16705
16715
|
throw new Error();
|
|
16706
16716
|
}
|
|
16707
16717
|
return result;
|
|
@@ -16733,7 +16743,7 @@ function decodeJwt(jwt2) {
|
|
|
16733
16743
|
} catch {
|
|
16734
16744
|
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
16735
16745
|
}
|
|
16736
|
-
if (!
|
|
16746
|
+
if (!isObject(result))
|
|
16737
16747
|
throw new JWTInvalid("Invalid JWT Claims Set");
|
|
16738
16748
|
return result;
|
|
16739
16749
|
}
|
|
@@ -16753,10 +16763,10 @@ async function verifyJWT(jwt2, secret, options) {
|
|
|
16753
16763
|
return await jwtVerify(jwt2, secret, options);
|
|
16754
16764
|
}
|
|
16755
16765
|
async function signJWT(payload, secret, options) {
|
|
16756
|
-
const
|
|
16766
|
+
const sign2 = new SignJWT(payload).setProtectedHeader({
|
|
16757
16767
|
alg: options?.alg ? options?.alg : "HS256"
|
|
16758
16768
|
}).setIssuedAt(options?.iat).setIssuer(options?.iss ? options?.iss : "urn:example:issuer").setAudience(options?.aud ? options?.aud : "urn:example:audience").setExpirationTime(options?.exp ? options?.exp : "2h");
|
|
16759
|
-
return
|
|
16769
|
+
return sign2.sign(secret, options?.options);
|
|
16760
16770
|
}
|
|
16761
16771
|
function decodeProtectedHeaderJWT(token) {
|
|
16762
16772
|
return decodeProtectedHeader(token);
|
|
@@ -16766,9 +16776,9 @@ function decodeJWT(jwt2) {
|
|
|
16766
16776
|
}
|
|
16767
16777
|
|
|
16768
16778
|
// src/services/utils/jwt.ts
|
|
16769
|
-
var
|
|
16779
|
+
var import_node_crypto6 = require("node:crypto");
|
|
16770
16780
|
var jwt = {
|
|
16771
|
-
createSecretKey:
|
|
16781
|
+
createSecretKey: import_node_crypto6.createSecretKey,
|
|
16772
16782
|
decode(jwt2) {
|
|
16773
16783
|
return decodeJWT(jwt2);
|
|
16774
16784
|
},
|
|
@@ -16905,6 +16915,10 @@ var MiqroJSONSchema = {
|
|
|
16905
16915
|
properties: {
|
|
16906
16916
|
name: "string?",
|
|
16907
16917
|
services: "string[]?",
|
|
16918
|
+
noBuild: "boolean?",
|
|
16919
|
+
noMinify: "boolean?",
|
|
16920
|
+
inflateOnlyAssets: "boolean?",
|
|
16921
|
+
inflateFlat: "boolean?",
|
|
16908
16922
|
port: "number?|string?",
|
|
16909
16923
|
inflateDir: "string?",
|
|
16910
16924
|
browser: "boolean?|string?",
|
|
@@ -17037,8 +17051,10 @@ var Miqro = class _Miqro {
|
|
|
17037
17051
|
watcher;
|
|
17038
17052
|
constructor(options) {
|
|
17039
17053
|
this.options = {
|
|
17054
|
+
noMinify: false,
|
|
17040
17055
|
editor: false,
|
|
17041
17056
|
name: "server",
|
|
17057
|
+
noBuild: false,
|
|
17042
17058
|
port: getPORT(),
|
|
17043
17059
|
services: [],
|
|
17044
17060
|
...options ? options : {}
|
|
@@ -17051,7 +17067,7 @@ var Miqro = class _Miqro {
|
|
|
17051
17067
|
this.listener = async (data) => {
|
|
17052
17068
|
try {
|
|
17053
17069
|
const msg = data;
|
|
17054
|
-
if (msg && msg.action && msg.type === MiqroApplicationMessageType && msg.target === this.options.name
|
|
17070
|
+
if (msg && msg.action && msg.type === MiqroApplicationMessageType && msg.target === this.options.name && msg.fromPID !== process.pid && (msg.action === "reload" || msg.action === "restart")) {
|
|
17055
17071
|
this.logger?.debug("remote server message from [%s] [%s]", msg.fromPID, msg.action);
|
|
17056
17072
|
switch (msg.action) {
|
|
17057
17073
|
case "reload":
|
|
@@ -17061,7 +17077,7 @@ var Miqro = class _Miqro {
|
|
|
17061
17077
|
await this.restart(true);
|
|
17062
17078
|
break;
|
|
17063
17079
|
default:
|
|
17064
|
-
throw new Error("
|
|
17080
|
+
throw new Error("unsupported message for ApplicationServer");
|
|
17065
17081
|
}
|
|
17066
17082
|
}
|
|
17067
17083
|
} catch (e) {
|
|
@@ -17102,6 +17118,7 @@ var Miqro = class _Miqro {
|
|
|
17102
17118
|
name: miqroJSON.name ? miqroJSON.name : void 0,
|
|
17103
17119
|
port: miqroJSON.port ? String(miqroJSON.port) : void 0,
|
|
17104
17120
|
services: miqroJSON.services ? miqroJSON.services.map((s) => (0, import_node_path30.join)((0, import_node_path30.relative)((0, import_node_process16.cwd)(), miqroJSONDir), s)) : void 0,
|
|
17121
|
+
noBuild: miqroJSON.noBuild !== void 0 ? miqroJSON.noBuild : false,
|
|
17105
17122
|
...options ? options : {}
|
|
17106
17123
|
});
|
|
17107
17124
|
await app.inflate({
|
|
@@ -17153,7 +17170,7 @@ var Miqro = class _Miqro {
|
|
|
17153
17170
|
const errors = [];
|
|
17154
17171
|
for (const service of this.options.services) {
|
|
17155
17172
|
const servicePath = getServicePath(service);
|
|
17156
|
-
await setupServerConfig(this.logger, servicePath, service, serverConfigMap, options && options.inflateSea ? options.inflateDir : void 0, errors);
|
|
17173
|
+
await setupServerConfig(this.logger, servicePath, service, serverConfigMap, options && options.inflateSea ? options.inflateDir : void 0, errors, this.options);
|
|
17157
17174
|
}
|
|
17158
17175
|
return {
|
|
17159
17176
|
serverConfigMap,
|
|
@@ -17165,9 +17182,9 @@ var Miqro = class _Miqro {
|
|
|
17165
17182
|
const dbList = [];
|
|
17166
17183
|
const dbConfigListALL = [];
|
|
17167
17184
|
for (const service of this.options.services) {
|
|
17168
|
-
const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : void 0, errors);
|
|
17185
|
+
const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : void 0, this.options, errors);
|
|
17169
17186
|
if (dbConfig) {
|
|
17170
|
-
const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : void 0, errors);
|
|
17187
|
+
const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : void 0, this.options, errors);
|
|
17171
17188
|
dbList.push({
|
|
17172
17189
|
service,
|
|
17173
17190
|
dbConfig,
|
|
@@ -17220,7 +17237,7 @@ var Miqro = class _Miqro {
|
|
|
17220
17237
|
}
|
|
17221
17238
|
try {
|
|
17222
17239
|
this.inflated = void 0;
|
|
17223
|
-
if (_Miqro.initAssetsPromise === null) {
|
|
17240
|
+
if (_Miqro.initAssetsPromise === null && (this.options.noBuild === false || this.options.noMinify === false)) {
|
|
17224
17241
|
_Miqro.initAssetsPromise = initAssets(this.logger);
|
|
17225
17242
|
}
|
|
17226
17243
|
await _Miqro.initAssetsPromise;
|
|
@@ -17242,6 +17259,10 @@ var Miqro = class _Miqro {
|
|
|
17242
17259
|
wsConfigList.push({
|
|
17243
17260
|
path: HOT_RELOAD_PATH
|
|
17244
17261
|
});
|
|
17262
|
+
this.logger?.debug("setting up hot-reload script on [%s]", HOT_RELOAD_SCRIPT_PATH);
|
|
17263
|
+
const hotReloadScriptRouter = new Router2();
|
|
17264
|
+
hotReloadScriptRouter.get(HOT_RELOAD_SCRIPT_PATH, async (req, res) => res.js(HOT_RELOAD_JS_SCRIPT));
|
|
17265
|
+
router.use(hotReloadScriptRouter);
|
|
17245
17266
|
}
|
|
17246
17267
|
await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, serverConfigMap, "preload");
|
|
17247
17268
|
const [serviceRouter, errors, fileMap, serviceWSConfigList, serviceLogConfigMap] = await inflateApp({
|
|
@@ -17254,7 +17275,11 @@ var Miqro = class _Miqro {
|
|
|
17254
17275
|
inflateSea: options?.inflateSea ? true : false,
|
|
17255
17276
|
//inflateTests: options?.inflateTests ? true : false,
|
|
17256
17277
|
hotreload: this.options?.hotreload ? true : false,
|
|
17257
|
-
inflateParallel: options?.inflateParallel
|
|
17278
|
+
inflateParallel: options?.inflateParallel,
|
|
17279
|
+
noBuild: this.options?.noBuild,
|
|
17280
|
+
noMinify: this.options?.noMinify,
|
|
17281
|
+
inflateOnlyAssets: options?.inflateOnlyAssets,
|
|
17282
|
+
inflateFlat: options?.inflateFlat
|
|
17258
17283
|
});
|
|
17259
17284
|
wsConfigList.push(...serviceWSConfigList);
|
|
17260
17285
|
router.use(serviceRouter);
|