@opsimathically/nodenetproccalld 0.0.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/LICENSE.txt +1 -0
- package/README.md +199 -0
- package/config/api_keys.config.json5 +21 -0
- package/config/server.config.json5 +79 -0
- package/dist/index.d.mts +246 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +2400 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2365 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2400 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key2 of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
19
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
|
|
33
|
+
|
|
34
|
+
// src/index.ts
|
|
35
|
+
var index_exports = {};
|
|
36
|
+
__export(index_exports, {
|
|
37
|
+
ApiKeyAuthorizer: () => ApiKeyAuthorizer,
|
|
38
|
+
ConfigFileLoader: () => ConfigFileLoader,
|
|
39
|
+
ConfigValidator: () => ConfigValidator,
|
|
40
|
+
DaemonCli: () => DaemonCli,
|
|
41
|
+
DaemonProcess: () => DaemonProcess,
|
|
42
|
+
NetworkProcedureCallDaemon: () => NetworkProcedureCallDaemon,
|
|
43
|
+
TlsMaterialGenerator: () => TlsMaterialGenerator
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(index_exports);
|
|
46
|
+
|
|
47
|
+
// src/classes/apikeyauthorizer/ApiKeyAuthorizer.class.ts
|
|
48
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
49
|
+
function SafeTimingEqual(params) {
|
|
50
|
+
const left_buffer = Buffer.from(params.left_value, "utf8");
|
|
51
|
+
const right_buffer = Buffer.from(params.right_value, "utf8");
|
|
52
|
+
if (left_buffer.length !== right_buffer.length) {
|
|
53
|
+
const left_digest = import_node_crypto.default.createHash("sha256").update(left_buffer).digest();
|
|
54
|
+
const right_digest = import_node_crypto.default.createHash("sha256").update(right_buffer).digest();
|
|
55
|
+
import_node_crypto.default.timingSafeEqual(left_digest, right_digest);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return import_node_crypto.default.timingSafeEqual(left_buffer, right_buffer);
|
|
59
|
+
}
|
|
60
|
+
__name(SafeTimingEqual, "SafeTimingEqual");
|
|
61
|
+
var _ApiKeyAuthorizer = class _ApiKeyAuthorizer {
|
|
62
|
+
constructor(params) {
|
|
63
|
+
__publicField(this, "api_key_entries");
|
|
64
|
+
this.api_key_entries = [
|
|
65
|
+
...params.api_key_entries
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
async authenticate(params) {
|
|
69
|
+
for (const api_key_entry of this.api_key_entries) {
|
|
70
|
+
if (!api_key_entry.enabled) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!SafeTimingEqual({
|
|
74
|
+
left_value: api_key_entry.api_key,
|
|
75
|
+
right_value: params.auth_callback_params.api_key
|
|
76
|
+
})) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!this.matchesIdentityConstraints({
|
|
80
|
+
api_key_entry,
|
|
81
|
+
auth_callback_params: params.auth_callback_params
|
|
82
|
+
})) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
state: "authenticated",
|
|
87
|
+
privileges: [
|
|
88
|
+
...api_key_entry.privileges
|
|
89
|
+
]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return "failed";
|
|
93
|
+
}
|
|
94
|
+
matchesIdentityConstraints(params) {
|
|
95
|
+
const constraints = params.api_key_entry.identity_constraints;
|
|
96
|
+
if (!constraints) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (constraints.remote_address_regex && !constraints.remote_address_regex.test(params.auth_callback_params.remote_address)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (constraints.tls_peer_subject_regex && !this.matchOptionalValue({
|
|
103
|
+
regex: constraints.tls_peer_subject_regex,
|
|
104
|
+
value: params.auth_callback_params.tls_peer_subject
|
|
105
|
+
})) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (constraints.tls_peer_san_regex && !this.matchOptionalValue({
|
|
109
|
+
regex: constraints.tls_peer_san_regex,
|
|
110
|
+
value: params.auth_callback_params.tls_peer_san
|
|
111
|
+
})) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (constraints.tls_peer_fingerprint256_regex && !this.matchOptionalValue({
|
|
115
|
+
regex: constraints.tls_peer_fingerprint256_regex,
|
|
116
|
+
value: params.auth_callback_params.tls_peer_fingerprint256
|
|
117
|
+
})) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (constraints.tls_peer_serial_number_regex && !this.matchOptionalValue({
|
|
121
|
+
regex: constraints.tls_peer_serial_number_regex,
|
|
122
|
+
value: params.auth_callback_params.tls_peer_serial_number
|
|
123
|
+
})) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
matchOptionalValue(params) {
|
|
129
|
+
if (!params.value) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return params.regex.test(params.value);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
__name(_ApiKeyAuthorizer, "ApiKeyAuthorizer");
|
|
136
|
+
var ApiKeyAuthorizer = _ApiKeyAuthorizer;
|
|
137
|
+
|
|
138
|
+
// src/classes/configfileloader/ConfigFileLoader.class.ts
|
|
139
|
+
var import_node_fs = __toESM(require("fs"));
|
|
140
|
+
var import_node_path = __toESM(require("path"));
|
|
141
|
+
|
|
142
|
+
// node_modules/json5/dist/index.mjs
|
|
143
|
+
var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
144
|
+
var ID_Start = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/;
|
|
145
|
+
var ID_Continue = /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/;
|
|
146
|
+
var unicode = {
|
|
147
|
+
Space_Separator,
|
|
148
|
+
ID_Start,
|
|
149
|
+
ID_Continue
|
|
150
|
+
};
|
|
151
|
+
var util = {
|
|
152
|
+
isSpaceSeparator(c2) {
|
|
153
|
+
return typeof c2 === "string" && unicode.Space_Separator.test(c2);
|
|
154
|
+
},
|
|
155
|
+
isIdStartChar(c2) {
|
|
156
|
+
return typeof c2 === "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 === "$" || c2 === "_" || unicode.ID_Start.test(c2));
|
|
157
|
+
},
|
|
158
|
+
isIdContinueChar(c2) {
|
|
159
|
+
return typeof c2 === "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 >= "0" && c2 <= "9" || c2 === "$" || c2 === "_" || c2 === "\u200C" || c2 === "\u200D" || unicode.ID_Continue.test(c2));
|
|
160
|
+
},
|
|
161
|
+
isDigit(c2) {
|
|
162
|
+
return typeof c2 === "string" && /[0-9]/.test(c2);
|
|
163
|
+
},
|
|
164
|
+
isHexDigit(c2) {
|
|
165
|
+
return typeof c2 === "string" && /[0-9A-Fa-f]/.test(c2);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var source;
|
|
169
|
+
var parseState;
|
|
170
|
+
var stack;
|
|
171
|
+
var pos;
|
|
172
|
+
var line;
|
|
173
|
+
var column;
|
|
174
|
+
var token;
|
|
175
|
+
var key;
|
|
176
|
+
var root;
|
|
177
|
+
var parse = /* @__PURE__ */ __name(function parse2(text, reviver) {
|
|
178
|
+
source = String(text);
|
|
179
|
+
parseState = "start";
|
|
180
|
+
stack = [];
|
|
181
|
+
pos = 0;
|
|
182
|
+
line = 1;
|
|
183
|
+
column = 0;
|
|
184
|
+
token = void 0;
|
|
185
|
+
key = void 0;
|
|
186
|
+
root = void 0;
|
|
187
|
+
do {
|
|
188
|
+
token = lex();
|
|
189
|
+
parseStates[parseState]();
|
|
190
|
+
} while (token.type !== "eof");
|
|
191
|
+
if (typeof reviver === "function") {
|
|
192
|
+
return internalize({ "": root }, "", reviver);
|
|
193
|
+
}
|
|
194
|
+
return root;
|
|
195
|
+
}, "parse");
|
|
196
|
+
function internalize(holder, name, reviver) {
|
|
197
|
+
const value = holder[name];
|
|
198
|
+
if (value != null && typeof value === "object") {
|
|
199
|
+
if (Array.isArray(value)) {
|
|
200
|
+
for (let i = 0; i < value.length; i++) {
|
|
201
|
+
const key2 = String(i);
|
|
202
|
+
const replacement = internalize(value, key2, reviver);
|
|
203
|
+
if (replacement === void 0) {
|
|
204
|
+
delete value[key2];
|
|
205
|
+
} else {
|
|
206
|
+
Object.defineProperty(value, key2, {
|
|
207
|
+
value: replacement,
|
|
208
|
+
writable: true,
|
|
209
|
+
enumerable: true,
|
|
210
|
+
configurable: true
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
for (const key2 in value) {
|
|
216
|
+
const replacement = internalize(value, key2, reviver);
|
|
217
|
+
if (replacement === void 0) {
|
|
218
|
+
delete value[key2];
|
|
219
|
+
} else {
|
|
220
|
+
Object.defineProperty(value, key2, {
|
|
221
|
+
value: replacement,
|
|
222
|
+
writable: true,
|
|
223
|
+
enumerable: true,
|
|
224
|
+
configurable: true
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return reviver.call(holder, name, value);
|
|
231
|
+
}
|
|
232
|
+
__name(internalize, "internalize");
|
|
233
|
+
var lexState;
|
|
234
|
+
var buffer;
|
|
235
|
+
var doubleQuote;
|
|
236
|
+
var sign;
|
|
237
|
+
var c;
|
|
238
|
+
function lex() {
|
|
239
|
+
lexState = "default";
|
|
240
|
+
buffer = "";
|
|
241
|
+
doubleQuote = false;
|
|
242
|
+
sign = 1;
|
|
243
|
+
for (; ; ) {
|
|
244
|
+
c = peek();
|
|
245
|
+
const token2 = lexStates[lexState]();
|
|
246
|
+
if (token2) {
|
|
247
|
+
return token2;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
__name(lex, "lex");
|
|
252
|
+
function peek() {
|
|
253
|
+
if (source[pos]) {
|
|
254
|
+
return String.fromCodePoint(source.codePointAt(pos));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
__name(peek, "peek");
|
|
258
|
+
function read() {
|
|
259
|
+
const c2 = peek();
|
|
260
|
+
if (c2 === "\n") {
|
|
261
|
+
line++;
|
|
262
|
+
column = 0;
|
|
263
|
+
} else if (c2) {
|
|
264
|
+
column += c2.length;
|
|
265
|
+
} else {
|
|
266
|
+
column++;
|
|
267
|
+
}
|
|
268
|
+
if (c2) {
|
|
269
|
+
pos += c2.length;
|
|
270
|
+
}
|
|
271
|
+
return c2;
|
|
272
|
+
}
|
|
273
|
+
__name(read, "read");
|
|
274
|
+
var lexStates = {
|
|
275
|
+
default() {
|
|
276
|
+
switch (c) {
|
|
277
|
+
case " ":
|
|
278
|
+
case "\v":
|
|
279
|
+
case "\f":
|
|
280
|
+
case " ":
|
|
281
|
+
case "\xA0":
|
|
282
|
+
case "\uFEFF":
|
|
283
|
+
case "\n":
|
|
284
|
+
case "\r":
|
|
285
|
+
case "\u2028":
|
|
286
|
+
case "\u2029":
|
|
287
|
+
read();
|
|
288
|
+
return;
|
|
289
|
+
case "/":
|
|
290
|
+
read();
|
|
291
|
+
lexState = "comment";
|
|
292
|
+
return;
|
|
293
|
+
case void 0:
|
|
294
|
+
read();
|
|
295
|
+
return newToken("eof");
|
|
296
|
+
}
|
|
297
|
+
if (util.isSpaceSeparator(c)) {
|
|
298
|
+
read();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
return lexStates[parseState]();
|
|
302
|
+
},
|
|
303
|
+
comment() {
|
|
304
|
+
switch (c) {
|
|
305
|
+
case "*":
|
|
306
|
+
read();
|
|
307
|
+
lexState = "multiLineComment";
|
|
308
|
+
return;
|
|
309
|
+
case "/":
|
|
310
|
+
read();
|
|
311
|
+
lexState = "singleLineComment";
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
throw invalidChar(read());
|
|
315
|
+
},
|
|
316
|
+
multiLineComment() {
|
|
317
|
+
switch (c) {
|
|
318
|
+
case "*":
|
|
319
|
+
read();
|
|
320
|
+
lexState = "multiLineCommentAsterisk";
|
|
321
|
+
return;
|
|
322
|
+
case void 0:
|
|
323
|
+
throw invalidChar(read());
|
|
324
|
+
}
|
|
325
|
+
read();
|
|
326
|
+
},
|
|
327
|
+
multiLineCommentAsterisk() {
|
|
328
|
+
switch (c) {
|
|
329
|
+
case "*":
|
|
330
|
+
read();
|
|
331
|
+
return;
|
|
332
|
+
case "/":
|
|
333
|
+
read();
|
|
334
|
+
lexState = "default";
|
|
335
|
+
return;
|
|
336
|
+
case void 0:
|
|
337
|
+
throw invalidChar(read());
|
|
338
|
+
}
|
|
339
|
+
read();
|
|
340
|
+
lexState = "multiLineComment";
|
|
341
|
+
},
|
|
342
|
+
singleLineComment() {
|
|
343
|
+
switch (c) {
|
|
344
|
+
case "\n":
|
|
345
|
+
case "\r":
|
|
346
|
+
case "\u2028":
|
|
347
|
+
case "\u2029":
|
|
348
|
+
read();
|
|
349
|
+
lexState = "default";
|
|
350
|
+
return;
|
|
351
|
+
case void 0:
|
|
352
|
+
read();
|
|
353
|
+
return newToken("eof");
|
|
354
|
+
}
|
|
355
|
+
read();
|
|
356
|
+
},
|
|
357
|
+
value() {
|
|
358
|
+
switch (c) {
|
|
359
|
+
case "{":
|
|
360
|
+
case "[":
|
|
361
|
+
return newToken("punctuator", read());
|
|
362
|
+
case "n":
|
|
363
|
+
read();
|
|
364
|
+
literal("ull");
|
|
365
|
+
return newToken("null", null);
|
|
366
|
+
case "t":
|
|
367
|
+
read();
|
|
368
|
+
literal("rue");
|
|
369
|
+
return newToken("boolean", true);
|
|
370
|
+
case "f":
|
|
371
|
+
read();
|
|
372
|
+
literal("alse");
|
|
373
|
+
return newToken("boolean", false);
|
|
374
|
+
case "-":
|
|
375
|
+
case "+":
|
|
376
|
+
if (read() === "-") {
|
|
377
|
+
sign = -1;
|
|
378
|
+
}
|
|
379
|
+
lexState = "sign";
|
|
380
|
+
return;
|
|
381
|
+
case ".":
|
|
382
|
+
buffer = read();
|
|
383
|
+
lexState = "decimalPointLeading";
|
|
384
|
+
return;
|
|
385
|
+
case "0":
|
|
386
|
+
buffer = read();
|
|
387
|
+
lexState = "zero";
|
|
388
|
+
return;
|
|
389
|
+
case "1":
|
|
390
|
+
case "2":
|
|
391
|
+
case "3":
|
|
392
|
+
case "4":
|
|
393
|
+
case "5":
|
|
394
|
+
case "6":
|
|
395
|
+
case "7":
|
|
396
|
+
case "8":
|
|
397
|
+
case "9":
|
|
398
|
+
buffer = read();
|
|
399
|
+
lexState = "decimalInteger";
|
|
400
|
+
return;
|
|
401
|
+
case "I":
|
|
402
|
+
read();
|
|
403
|
+
literal("nfinity");
|
|
404
|
+
return newToken("numeric", Infinity);
|
|
405
|
+
case "N":
|
|
406
|
+
read();
|
|
407
|
+
literal("aN");
|
|
408
|
+
return newToken("numeric", NaN);
|
|
409
|
+
case '"':
|
|
410
|
+
case "'":
|
|
411
|
+
doubleQuote = read() === '"';
|
|
412
|
+
buffer = "";
|
|
413
|
+
lexState = "string";
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
throw invalidChar(read());
|
|
417
|
+
},
|
|
418
|
+
identifierNameStartEscape() {
|
|
419
|
+
if (c !== "u") {
|
|
420
|
+
throw invalidChar(read());
|
|
421
|
+
}
|
|
422
|
+
read();
|
|
423
|
+
const u = unicodeEscape();
|
|
424
|
+
switch (u) {
|
|
425
|
+
case "$":
|
|
426
|
+
case "_":
|
|
427
|
+
break;
|
|
428
|
+
default:
|
|
429
|
+
if (!util.isIdStartChar(u)) {
|
|
430
|
+
throw invalidIdentifier();
|
|
431
|
+
}
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
buffer += u;
|
|
435
|
+
lexState = "identifierName";
|
|
436
|
+
},
|
|
437
|
+
identifierName() {
|
|
438
|
+
switch (c) {
|
|
439
|
+
case "$":
|
|
440
|
+
case "_":
|
|
441
|
+
case "\u200C":
|
|
442
|
+
case "\u200D":
|
|
443
|
+
buffer += read();
|
|
444
|
+
return;
|
|
445
|
+
case "\\":
|
|
446
|
+
read();
|
|
447
|
+
lexState = "identifierNameEscape";
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (util.isIdContinueChar(c)) {
|
|
451
|
+
buffer += read();
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
return newToken("identifier", buffer);
|
|
455
|
+
},
|
|
456
|
+
identifierNameEscape() {
|
|
457
|
+
if (c !== "u") {
|
|
458
|
+
throw invalidChar(read());
|
|
459
|
+
}
|
|
460
|
+
read();
|
|
461
|
+
const u = unicodeEscape();
|
|
462
|
+
switch (u) {
|
|
463
|
+
case "$":
|
|
464
|
+
case "_":
|
|
465
|
+
case "\u200C":
|
|
466
|
+
case "\u200D":
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
469
|
+
if (!util.isIdContinueChar(u)) {
|
|
470
|
+
throw invalidIdentifier();
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
buffer += u;
|
|
475
|
+
lexState = "identifierName";
|
|
476
|
+
},
|
|
477
|
+
sign() {
|
|
478
|
+
switch (c) {
|
|
479
|
+
case ".":
|
|
480
|
+
buffer = read();
|
|
481
|
+
lexState = "decimalPointLeading";
|
|
482
|
+
return;
|
|
483
|
+
case "0":
|
|
484
|
+
buffer = read();
|
|
485
|
+
lexState = "zero";
|
|
486
|
+
return;
|
|
487
|
+
case "1":
|
|
488
|
+
case "2":
|
|
489
|
+
case "3":
|
|
490
|
+
case "4":
|
|
491
|
+
case "5":
|
|
492
|
+
case "6":
|
|
493
|
+
case "7":
|
|
494
|
+
case "8":
|
|
495
|
+
case "9":
|
|
496
|
+
buffer = read();
|
|
497
|
+
lexState = "decimalInteger";
|
|
498
|
+
return;
|
|
499
|
+
case "I":
|
|
500
|
+
read();
|
|
501
|
+
literal("nfinity");
|
|
502
|
+
return newToken("numeric", sign * Infinity);
|
|
503
|
+
case "N":
|
|
504
|
+
read();
|
|
505
|
+
literal("aN");
|
|
506
|
+
return newToken("numeric", NaN);
|
|
507
|
+
}
|
|
508
|
+
throw invalidChar(read());
|
|
509
|
+
},
|
|
510
|
+
zero() {
|
|
511
|
+
switch (c) {
|
|
512
|
+
case ".":
|
|
513
|
+
buffer += read();
|
|
514
|
+
lexState = "decimalPoint";
|
|
515
|
+
return;
|
|
516
|
+
case "e":
|
|
517
|
+
case "E":
|
|
518
|
+
buffer += read();
|
|
519
|
+
lexState = "decimalExponent";
|
|
520
|
+
return;
|
|
521
|
+
case "x":
|
|
522
|
+
case "X":
|
|
523
|
+
buffer += read();
|
|
524
|
+
lexState = "hexadecimal";
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
return newToken("numeric", sign * 0);
|
|
528
|
+
},
|
|
529
|
+
decimalInteger() {
|
|
530
|
+
switch (c) {
|
|
531
|
+
case ".":
|
|
532
|
+
buffer += read();
|
|
533
|
+
lexState = "decimalPoint";
|
|
534
|
+
return;
|
|
535
|
+
case "e":
|
|
536
|
+
case "E":
|
|
537
|
+
buffer += read();
|
|
538
|
+
lexState = "decimalExponent";
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
if (util.isDigit(c)) {
|
|
542
|
+
buffer += read();
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
return newToken("numeric", sign * Number(buffer));
|
|
546
|
+
},
|
|
547
|
+
decimalPointLeading() {
|
|
548
|
+
if (util.isDigit(c)) {
|
|
549
|
+
buffer += read();
|
|
550
|
+
lexState = "decimalFraction";
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
throw invalidChar(read());
|
|
554
|
+
},
|
|
555
|
+
decimalPoint() {
|
|
556
|
+
switch (c) {
|
|
557
|
+
case "e":
|
|
558
|
+
case "E":
|
|
559
|
+
buffer += read();
|
|
560
|
+
lexState = "decimalExponent";
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (util.isDigit(c)) {
|
|
564
|
+
buffer += read();
|
|
565
|
+
lexState = "decimalFraction";
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
return newToken("numeric", sign * Number(buffer));
|
|
569
|
+
},
|
|
570
|
+
decimalFraction() {
|
|
571
|
+
switch (c) {
|
|
572
|
+
case "e":
|
|
573
|
+
case "E":
|
|
574
|
+
buffer += read();
|
|
575
|
+
lexState = "decimalExponent";
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
if (util.isDigit(c)) {
|
|
579
|
+
buffer += read();
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
return newToken("numeric", sign * Number(buffer));
|
|
583
|
+
},
|
|
584
|
+
decimalExponent() {
|
|
585
|
+
switch (c) {
|
|
586
|
+
case "+":
|
|
587
|
+
case "-":
|
|
588
|
+
buffer += read();
|
|
589
|
+
lexState = "decimalExponentSign";
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (util.isDigit(c)) {
|
|
593
|
+
buffer += read();
|
|
594
|
+
lexState = "decimalExponentInteger";
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
throw invalidChar(read());
|
|
598
|
+
},
|
|
599
|
+
decimalExponentSign() {
|
|
600
|
+
if (util.isDigit(c)) {
|
|
601
|
+
buffer += read();
|
|
602
|
+
lexState = "decimalExponentInteger";
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
throw invalidChar(read());
|
|
606
|
+
},
|
|
607
|
+
decimalExponentInteger() {
|
|
608
|
+
if (util.isDigit(c)) {
|
|
609
|
+
buffer += read();
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
return newToken("numeric", sign * Number(buffer));
|
|
613
|
+
},
|
|
614
|
+
hexadecimal() {
|
|
615
|
+
if (util.isHexDigit(c)) {
|
|
616
|
+
buffer += read();
|
|
617
|
+
lexState = "hexadecimalInteger";
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
throw invalidChar(read());
|
|
621
|
+
},
|
|
622
|
+
hexadecimalInteger() {
|
|
623
|
+
if (util.isHexDigit(c)) {
|
|
624
|
+
buffer += read();
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
return newToken("numeric", sign * Number(buffer));
|
|
628
|
+
},
|
|
629
|
+
string() {
|
|
630
|
+
switch (c) {
|
|
631
|
+
case "\\":
|
|
632
|
+
read();
|
|
633
|
+
buffer += escape();
|
|
634
|
+
return;
|
|
635
|
+
case '"':
|
|
636
|
+
if (doubleQuote) {
|
|
637
|
+
read();
|
|
638
|
+
return newToken("string", buffer);
|
|
639
|
+
}
|
|
640
|
+
buffer += read();
|
|
641
|
+
return;
|
|
642
|
+
case "'":
|
|
643
|
+
if (!doubleQuote) {
|
|
644
|
+
read();
|
|
645
|
+
return newToken("string", buffer);
|
|
646
|
+
}
|
|
647
|
+
buffer += read();
|
|
648
|
+
return;
|
|
649
|
+
case "\n":
|
|
650
|
+
case "\r":
|
|
651
|
+
throw invalidChar(read());
|
|
652
|
+
case "\u2028":
|
|
653
|
+
case "\u2029":
|
|
654
|
+
separatorChar(c);
|
|
655
|
+
break;
|
|
656
|
+
case void 0:
|
|
657
|
+
throw invalidChar(read());
|
|
658
|
+
}
|
|
659
|
+
buffer += read();
|
|
660
|
+
},
|
|
661
|
+
start() {
|
|
662
|
+
switch (c) {
|
|
663
|
+
case "{":
|
|
664
|
+
case "[":
|
|
665
|
+
return newToken("punctuator", read());
|
|
666
|
+
}
|
|
667
|
+
lexState = "value";
|
|
668
|
+
},
|
|
669
|
+
beforePropertyName() {
|
|
670
|
+
switch (c) {
|
|
671
|
+
case "$":
|
|
672
|
+
case "_":
|
|
673
|
+
buffer = read();
|
|
674
|
+
lexState = "identifierName";
|
|
675
|
+
return;
|
|
676
|
+
case "\\":
|
|
677
|
+
read();
|
|
678
|
+
lexState = "identifierNameStartEscape";
|
|
679
|
+
return;
|
|
680
|
+
case "}":
|
|
681
|
+
return newToken("punctuator", read());
|
|
682
|
+
case '"':
|
|
683
|
+
case "'":
|
|
684
|
+
doubleQuote = read() === '"';
|
|
685
|
+
lexState = "string";
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (util.isIdStartChar(c)) {
|
|
689
|
+
buffer += read();
|
|
690
|
+
lexState = "identifierName";
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
throw invalidChar(read());
|
|
694
|
+
},
|
|
695
|
+
afterPropertyName() {
|
|
696
|
+
if (c === ":") {
|
|
697
|
+
return newToken("punctuator", read());
|
|
698
|
+
}
|
|
699
|
+
throw invalidChar(read());
|
|
700
|
+
},
|
|
701
|
+
beforePropertyValue() {
|
|
702
|
+
lexState = "value";
|
|
703
|
+
},
|
|
704
|
+
afterPropertyValue() {
|
|
705
|
+
switch (c) {
|
|
706
|
+
case ",":
|
|
707
|
+
case "}":
|
|
708
|
+
return newToken("punctuator", read());
|
|
709
|
+
}
|
|
710
|
+
throw invalidChar(read());
|
|
711
|
+
},
|
|
712
|
+
beforeArrayValue() {
|
|
713
|
+
if (c === "]") {
|
|
714
|
+
return newToken("punctuator", read());
|
|
715
|
+
}
|
|
716
|
+
lexState = "value";
|
|
717
|
+
},
|
|
718
|
+
afterArrayValue() {
|
|
719
|
+
switch (c) {
|
|
720
|
+
case ",":
|
|
721
|
+
case "]":
|
|
722
|
+
return newToken("punctuator", read());
|
|
723
|
+
}
|
|
724
|
+
throw invalidChar(read());
|
|
725
|
+
},
|
|
726
|
+
end() {
|
|
727
|
+
throw invalidChar(read());
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
function newToken(type, value) {
|
|
731
|
+
return {
|
|
732
|
+
type,
|
|
733
|
+
value,
|
|
734
|
+
line,
|
|
735
|
+
column
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
__name(newToken, "newToken");
|
|
739
|
+
function literal(s) {
|
|
740
|
+
for (const c2 of s) {
|
|
741
|
+
const p = peek();
|
|
742
|
+
if (p !== c2) {
|
|
743
|
+
throw invalidChar(read());
|
|
744
|
+
}
|
|
745
|
+
read();
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
__name(literal, "literal");
|
|
749
|
+
function escape() {
|
|
750
|
+
const c2 = peek();
|
|
751
|
+
switch (c2) {
|
|
752
|
+
case "b":
|
|
753
|
+
read();
|
|
754
|
+
return "\b";
|
|
755
|
+
case "f":
|
|
756
|
+
read();
|
|
757
|
+
return "\f";
|
|
758
|
+
case "n":
|
|
759
|
+
read();
|
|
760
|
+
return "\n";
|
|
761
|
+
case "r":
|
|
762
|
+
read();
|
|
763
|
+
return "\r";
|
|
764
|
+
case "t":
|
|
765
|
+
read();
|
|
766
|
+
return " ";
|
|
767
|
+
case "v":
|
|
768
|
+
read();
|
|
769
|
+
return "\v";
|
|
770
|
+
case "0":
|
|
771
|
+
read();
|
|
772
|
+
if (util.isDigit(peek())) {
|
|
773
|
+
throw invalidChar(read());
|
|
774
|
+
}
|
|
775
|
+
return "\0";
|
|
776
|
+
case "x":
|
|
777
|
+
read();
|
|
778
|
+
return hexEscape();
|
|
779
|
+
case "u":
|
|
780
|
+
read();
|
|
781
|
+
return unicodeEscape();
|
|
782
|
+
case "\n":
|
|
783
|
+
case "\u2028":
|
|
784
|
+
case "\u2029":
|
|
785
|
+
read();
|
|
786
|
+
return "";
|
|
787
|
+
case "\r":
|
|
788
|
+
read();
|
|
789
|
+
if (peek() === "\n") {
|
|
790
|
+
read();
|
|
791
|
+
}
|
|
792
|
+
return "";
|
|
793
|
+
case "1":
|
|
794
|
+
case "2":
|
|
795
|
+
case "3":
|
|
796
|
+
case "4":
|
|
797
|
+
case "5":
|
|
798
|
+
case "6":
|
|
799
|
+
case "7":
|
|
800
|
+
case "8":
|
|
801
|
+
case "9":
|
|
802
|
+
throw invalidChar(read());
|
|
803
|
+
case void 0:
|
|
804
|
+
throw invalidChar(read());
|
|
805
|
+
}
|
|
806
|
+
return read();
|
|
807
|
+
}
|
|
808
|
+
__name(escape, "escape");
|
|
809
|
+
function hexEscape() {
|
|
810
|
+
let buffer2 = "";
|
|
811
|
+
let c2 = peek();
|
|
812
|
+
if (!util.isHexDigit(c2)) {
|
|
813
|
+
throw invalidChar(read());
|
|
814
|
+
}
|
|
815
|
+
buffer2 += read();
|
|
816
|
+
c2 = peek();
|
|
817
|
+
if (!util.isHexDigit(c2)) {
|
|
818
|
+
throw invalidChar(read());
|
|
819
|
+
}
|
|
820
|
+
buffer2 += read();
|
|
821
|
+
return String.fromCodePoint(parseInt(buffer2, 16));
|
|
822
|
+
}
|
|
823
|
+
__name(hexEscape, "hexEscape");
|
|
824
|
+
function unicodeEscape() {
|
|
825
|
+
let buffer2 = "";
|
|
826
|
+
let count = 4;
|
|
827
|
+
while (count-- > 0) {
|
|
828
|
+
const c2 = peek();
|
|
829
|
+
if (!util.isHexDigit(c2)) {
|
|
830
|
+
throw invalidChar(read());
|
|
831
|
+
}
|
|
832
|
+
buffer2 += read();
|
|
833
|
+
}
|
|
834
|
+
return String.fromCodePoint(parseInt(buffer2, 16));
|
|
835
|
+
}
|
|
836
|
+
__name(unicodeEscape, "unicodeEscape");
|
|
837
|
+
var parseStates = {
|
|
838
|
+
start() {
|
|
839
|
+
if (token.type === "eof") {
|
|
840
|
+
throw invalidEOF();
|
|
841
|
+
}
|
|
842
|
+
push();
|
|
843
|
+
},
|
|
844
|
+
beforePropertyName() {
|
|
845
|
+
switch (token.type) {
|
|
846
|
+
case "identifier":
|
|
847
|
+
case "string":
|
|
848
|
+
key = token.value;
|
|
849
|
+
parseState = "afterPropertyName";
|
|
850
|
+
return;
|
|
851
|
+
case "punctuator":
|
|
852
|
+
pop();
|
|
853
|
+
return;
|
|
854
|
+
case "eof":
|
|
855
|
+
throw invalidEOF();
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
afterPropertyName() {
|
|
859
|
+
if (token.type === "eof") {
|
|
860
|
+
throw invalidEOF();
|
|
861
|
+
}
|
|
862
|
+
parseState = "beforePropertyValue";
|
|
863
|
+
},
|
|
864
|
+
beforePropertyValue() {
|
|
865
|
+
if (token.type === "eof") {
|
|
866
|
+
throw invalidEOF();
|
|
867
|
+
}
|
|
868
|
+
push();
|
|
869
|
+
},
|
|
870
|
+
beforeArrayValue() {
|
|
871
|
+
if (token.type === "eof") {
|
|
872
|
+
throw invalidEOF();
|
|
873
|
+
}
|
|
874
|
+
if (token.type === "punctuator" && token.value === "]") {
|
|
875
|
+
pop();
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
push();
|
|
879
|
+
},
|
|
880
|
+
afterPropertyValue() {
|
|
881
|
+
if (token.type === "eof") {
|
|
882
|
+
throw invalidEOF();
|
|
883
|
+
}
|
|
884
|
+
switch (token.value) {
|
|
885
|
+
case ",":
|
|
886
|
+
parseState = "beforePropertyName";
|
|
887
|
+
return;
|
|
888
|
+
case "}":
|
|
889
|
+
pop();
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
afterArrayValue() {
|
|
893
|
+
if (token.type === "eof") {
|
|
894
|
+
throw invalidEOF();
|
|
895
|
+
}
|
|
896
|
+
switch (token.value) {
|
|
897
|
+
case ",":
|
|
898
|
+
parseState = "beforeArrayValue";
|
|
899
|
+
return;
|
|
900
|
+
case "]":
|
|
901
|
+
pop();
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
end() {
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
function push() {
|
|
908
|
+
let value;
|
|
909
|
+
switch (token.type) {
|
|
910
|
+
case "punctuator":
|
|
911
|
+
switch (token.value) {
|
|
912
|
+
case "{":
|
|
913
|
+
value = {};
|
|
914
|
+
break;
|
|
915
|
+
case "[":
|
|
916
|
+
value = [];
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
break;
|
|
920
|
+
case "null":
|
|
921
|
+
case "boolean":
|
|
922
|
+
case "numeric":
|
|
923
|
+
case "string":
|
|
924
|
+
value = token.value;
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
if (root === void 0) {
|
|
928
|
+
root = value;
|
|
929
|
+
} else {
|
|
930
|
+
const parent = stack[stack.length - 1];
|
|
931
|
+
if (Array.isArray(parent)) {
|
|
932
|
+
parent.push(value);
|
|
933
|
+
} else {
|
|
934
|
+
Object.defineProperty(parent, key, {
|
|
935
|
+
value,
|
|
936
|
+
writable: true,
|
|
937
|
+
enumerable: true,
|
|
938
|
+
configurable: true
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
if (value !== null && typeof value === "object") {
|
|
943
|
+
stack.push(value);
|
|
944
|
+
if (Array.isArray(value)) {
|
|
945
|
+
parseState = "beforeArrayValue";
|
|
946
|
+
} else {
|
|
947
|
+
parseState = "beforePropertyName";
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
const current = stack[stack.length - 1];
|
|
951
|
+
if (current == null) {
|
|
952
|
+
parseState = "end";
|
|
953
|
+
} else if (Array.isArray(current)) {
|
|
954
|
+
parseState = "afterArrayValue";
|
|
955
|
+
} else {
|
|
956
|
+
parseState = "afterPropertyValue";
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
__name(push, "push");
|
|
961
|
+
function pop() {
|
|
962
|
+
stack.pop();
|
|
963
|
+
const current = stack[stack.length - 1];
|
|
964
|
+
if (current == null) {
|
|
965
|
+
parseState = "end";
|
|
966
|
+
} else if (Array.isArray(current)) {
|
|
967
|
+
parseState = "afterArrayValue";
|
|
968
|
+
} else {
|
|
969
|
+
parseState = "afterPropertyValue";
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
__name(pop, "pop");
|
|
973
|
+
function invalidChar(c2) {
|
|
974
|
+
if (c2 === void 0) {
|
|
975
|
+
return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
|
|
976
|
+
}
|
|
977
|
+
return syntaxError(`JSON5: invalid character '${formatChar(c2)}' at ${line}:${column}`);
|
|
978
|
+
}
|
|
979
|
+
__name(invalidChar, "invalidChar");
|
|
980
|
+
function invalidEOF() {
|
|
981
|
+
return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
|
|
982
|
+
}
|
|
983
|
+
__name(invalidEOF, "invalidEOF");
|
|
984
|
+
function invalidIdentifier() {
|
|
985
|
+
column -= 5;
|
|
986
|
+
return syntaxError(`JSON5: invalid identifier character at ${line}:${column}`);
|
|
987
|
+
}
|
|
988
|
+
__name(invalidIdentifier, "invalidIdentifier");
|
|
989
|
+
function separatorChar(c2) {
|
|
990
|
+
console.warn(`JSON5: '${formatChar(c2)}' in strings is not valid ECMAScript; consider escaping`);
|
|
991
|
+
}
|
|
992
|
+
__name(separatorChar, "separatorChar");
|
|
993
|
+
function formatChar(c2) {
|
|
994
|
+
const replacements = {
|
|
995
|
+
"'": "\\'",
|
|
996
|
+
'"': '\\"',
|
|
997
|
+
"\\": "\\\\",
|
|
998
|
+
"\b": "\\b",
|
|
999
|
+
"\f": "\\f",
|
|
1000
|
+
"\n": "\\n",
|
|
1001
|
+
"\r": "\\r",
|
|
1002
|
+
" ": "\\t",
|
|
1003
|
+
"\v": "\\v",
|
|
1004
|
+
"\0": "\\0",
|
|
1005
|
+
"\u2028": "\\u2028",
|
|
1006
|
+
"\u2029": "\\u2029"
|
|
1007
|
+
};
|
|
1008
|
+
if (replacements[c2]) {
|
|
1009
|
+
return replacements[c2];
|
|
1010
|
+
}
|
|
1011
|
+
if (c2 < " ") {
|
|
1012
|
+
const hexString = c2.charCodeAt(0).toString(16);
|
|
1013
|
+
return "\\x" + ("00" + hexString).substring(hexString.length);
|
|
1014
|
+
}
|
|
1015
|
+
return c2;
|
|
1016
|
+
}
|
|
1017
|
+
__name(formatChar, "formatChar");
|
|
1018
|
+
function syntaxError(message) {
|
|
1019
|
+
const err = new SyntaxError(message);
|
|
1020
|
+
err.lineNumber = line;
|
|
1021
|
+
err.columnNumber = column;
|
|
1022
|
+
return err;
|
|
1023
|
+
}
|
|
1024
|
+
__name(syntaxError, "syntaxError");
|
|
1025
|
+
var stringify = /* @__PURE__ */ __name(function stringify2(value, replacer, space) {
|
|
1026
|
+
const stack2 = [];
|
|
1027
|
+
let indent = "";
|
|
1028
|
+
let propertyList;
|
|
1029
|
+
let replacerFunc;
|
|
1030
|
+
let gap = "";
|
|
1031
|
+
let quote;
|
|
1032
|
+
if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
|
|
1033
|
+
space = replacer.space;
|
|
1034
|
+
quote = replacer.quote;
|
|
1035
|
+
replacer = replacer.replacer;
|
|
1036
|
+
}
|
|
1037
|
+
if (typeof replacer === "function") {
|
|
1038
|
+
replacerFunc = replacer;
|
|
1039
|
+
} else if (Array.isArray(replacer)) {
|
|
1040
|
+
propertyList = [];
|
|
1041
|
+
for (const v of replacer) {
|
|
1042
|
+
let item;
|
|
1043
|
+
if (typeof v === "string") {
|
|
1044
|
+
item = v;
|
|
1045
|
+
} else if (typeof v === "number" || v instanceof String || v instanceof Number) {
|
|
1046
|
+
item = String(v);
|
|
1047
|
+
}
|
|
1048
|
+
if (item !== void 0 && propertyList.indexOf(item) < 0) {
|
|
1049
|
+
propertyList.push(item);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
if (space instanceof Number) {
|
|
1054
|
+
space = Number(space);
|
|
1055
|
+
} else if (space instanceof String) {
|
|
1056
|
+
space = String(space);
|
|
1057
|
+
}
|
|
1058
|
+
if (typeof space === "number") {
|
|
1059
|
+
if (space > 0) {
|
|
1060
|
+
space = Math.min(10, Math.floor(space));
|
|
1061
|
+
gap = " ".substr(0, space);
|
|
1062
|
+
}
|
|
1063
|
+
} else if (typeof space === "string") {
|
|
1064
|
+
gap = space.substr(0, 10);
|
|
1065
|
+
}
|
|
1066
|
+
return serializeProperty("", { "": value });
|
|
1067
|
+
function serializeProperty(key2, holder) {
|
|
1068
|
+
let value2 = holder[key2];
|
|
1069
|
+
if (value2 != null) {
|
|
1070
|
+
if (typeof value2.toJSON5 === "function") {
|
|
1071
|
+
value2 = value2.toJSON5(key2);
|
|
1072
|
+
} else if (typeof value2.toJSON === "function") {
|
|
1073
|
+
value2 = value2.toJSON(key2);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (replacerFunc) {
|
|
1077
|
+
value2 = replacerFunc.call(holder, key2, value2);
|
|
1078
|
+
}
|
|
1079
|
+
if (value2 instanceof Number) {
|
|
1080
|
+
value2 = Number(value2);
|
|
1081
|
+
} else if (value2 instanceof String) {
|
|
1082
|
+
value2 = String(value2);
|
|
1083
|
+
} else if (value2 instanceof Boolean) {
|
|
1084
|
+
value2 = value2.valueOf();
|
|
1085
|
+
}
|
|
1086
|
+
switch (value2) {
|
|
1087
|
+
case null:
|
|
1088
|
+
return "null";
|
|
1089
|
+
case true:
|
|
1090
|
+
return "true";
|
|
1091
|
+
case false:
|
|
1092
|
+
return "false";
|
|
1093
|
+
}
|
|
1094
|
+
if (typeof value2 === "string") {
|
|
1095
|
+
return quoteString(value2, false);
|
|
1096
|
+
}
|
|
1097
|
+
if (typeof value2 === "number") {
|
|
1098
|
+
return String(value2);
|
|
1099
|
+
}
|
|
1100
|
+
if (typeof value2 === "object") {
|
|
1101
|
+
return Array.isArray(value2) ? serializeArray(value2) : serializeObject(value2);
|
|
1102
|
+
}
|
|
1103
|
+
return void 0;
|
|
1104
|
+
}
|
|
1105
|
+
__name(serializeProperty, "serializeProperty");
|
|
1106
|
+
function quoteString(value2) {
|
|
1107
|
+
const quotes = {
|
|
1108
|
+
"'": 0.1,
|
|
1109
|
+
'"': 0.2
|
|
1110
|
+
};
|
|
1111
|
+
const replacements = {
|
|
1112
|
+
"'": "\\'",
|
|
1113
|
+
'"': '\\"',
|
|
1114
|
+
"\\": "\\\\",
|
|
1115
|
+
"\b": "\\b",
|
|
1116
|
+
"\f": "\\f",
|
|
1117
|
+
"\n": "\\n",
|
|
1118
|
+
"\r": "\\r",
|
|
1119
|
+
" ": "\\t",
|
|
1120
|
+
"\v": "\\v",
|
|
1121
|
+
"\0": "\\0",
|
|
1122
|
+
"\u2028": "\\u2028",
|
|
1123
|
+
"\u2029": "\\u2029"
|
|
1124
|
+
};
|
|
1125
|
+
let product = "";
|
|
1126
|
+
for (let i = 0; i < value2.length; i++) {
|
|
1127
|
+
const c2 = value2[i];
|
|
1128
|
+
switch (c2) {
|
|
1129
|
+
case "'":
|
|
1130
|
+
case '"':
|
|
1131
|
+
quotes[c2]++;
|
|
1132
|
+
product += c2;
|
|
1133
|
+
continue;
|
|
1134
|
+
case "\0":
|
|
1135
|
+
if (util.isDigit(value2[i + 1])) {
|
|
1136
|
+
product += "\\x00";
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
if (replacements[c2]) {
|
|
1141
|
+
product += replacements[c2];
|
|
1142
|
+
continue;
|
|
1143
|
+
}
|
|
1144
|
+
if (c2 < " ") {
|
|
1145
|
+
let hexString = c2.charCodeAt(0).toString(16);
|
|
1146
|
+
product += "\\x" + ("00" + hexString).substring(hexString.length);
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
product += c2;
|
|
1150
|
+
}
|
|
1151
|
+
const quoteChar = quote || Object.keys(quotes).reduce((a, b) => quotes[a] < quotes[b] ? a : b);
|
|
1152
|
+
product = product.replace(new RegExp(quoteChar, "g"), replacements[quoteChar]);
|
|
1153
|
+
return quoteChar + product + quoteChar;
|
|
1154
|
+
}
|
|
1155
|
+
__name(quoteString, "quoteString");
|
|
1156
|
+
function serializeObject(value2) {
|
|
1157
|
+
if (stack2.indexOf(value2) >= 0) {
|
|
1158
|
+
throw TypeError("Converting circular structure to JSON5");
|
|
1159
|
+
}
|
|
1160
|
+
stack2.push(value2);
|
|
1161
|
+
let stepback = indent;
|
|
1162
|
+
indent = indent + gap;
|
|
1163
|
+
let keys = propertyList || Object.keys(value2);
|
|
1164
|
+
let partial = [];
|
|
1165
|
+
for (const key2 of keys) {
|
|
1166
|
+
const propertyString = serializeProperty(key2, value2);
|
|
1167
|
+
if (propertyString !== void 0) {
|
|
1168
|
+
let member = serializeKey(key2) + ":";
|
|
1169
|
+
if (gap !== "") {
|
|
1170
|
+
member += " ";
|
|
1171
|
+
}
|
|
1172
|
+
member += propertyString;
|
|
1173
|
+
partial.push(member);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
let final;
|
|
1177
|
+
if (partial.length === 0) {
|
|
1178
|
+
final = "{}";
|
|
1179
|
+
} else {
|
|
1180
|
+
let properties;
|
|
1181
|
+
if (gap === "") {
|
|
1182
|
+
properties = partial.join(",");
|
|
1183
|
+
final = "{" + properties + "}";
|
|
1184
|
+
} else {
|
|
1185
|
+
let separator = ",\n" + indent;
|
|
1186
|
+
properties = partial.join(separator);
|
|
1187
|
+
final = "{\n" + indent + properties + ",\n" + stepback + "}";
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
stack2.pop();
|
|
1191
|
+
indent = stepback;
|
|
1192
|
+
return final;
|
|
1193
|
+
}
|
|
1194
|
+
__name(serializeObject, "serializeObject");
|
|
1195
|
+
function serializeKey(key2) {
|
|
1196
|
+
if (key2.length === 0) {
|
|
1197
|
+
return quoteString(key2, true);
|
|
1198
|
+
}
|
|
1199
|
+
const firstChar = String.fromCodePoint(key2.codePointAt(0));
|
|
1200
|
+
if (!util.isIdStartChar(firstChar)) {
|
|
1201
|
+
return quoteString(key2, true);
|
|
1202
|
+
}
|
|
1203
|
+
for (let i = firstChar.length; i < key2.length; i++) {
|
|
1204
|
+
if (!util.isIdContinueChar(String.fromCodePoint(key2.codePointAt(i)))) {
|
|
1205
|
+
return quoteString(key2, true);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return key2;
|
|
1209
|
+
}
|
|
1210
|
+
__name(serializeKey, "serializeKey");
|
|
1211
|
+
function serializeArray(value2) {
|
|
1212
|
+
if (stack2.indexOf(value2) >= 0) {
|
|
1213
|
+
throw TypeError("Converting circular structure to JSON5");
|
|
1214
|
+
}
|
|
1215
|
+
stack2.push(value2);
|
|
1216
|
+
let stepback = indent;
|
|
1217
|
+
indent = indent + gap;
|
|
1218
|
+
let partial = [];
|
|
1219
|
+
for (let i = 0; i < value2.length; i++) {
|
|
1220
|
+
const propertyString = serializeProperty(String(i), value2);
|
|
1221
|
+
partial.push(propertyString !== void 0 ? propertyString : "null");
|
|
1222
|
+
}
|
|
1223
|
+
let final;
|
|
1224
|
+
if (partial.length === 0) {
|
|
1225
|
+
final = "[]";
|
|
1226
|
+
} else {
|
|
1227
|
+
if (gap === "") {
|
|
1228
|
+
let properties = partial.join(",");
|
|
1229
|
+
final = "[" + properties + "]";
|
|
1230
|
+
} else {
|
|
1231
|
+
let separator = ",\n" + indent;
|
|
1232
|
+
let properties = partial.join(separator);
|
|
1233
|
+
final = "[\n" + indent + properties + ",\n" + stepback + "]";
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
stack2.pop();
|
|
1237
|
+
indent = stepback;
|
|
1238
|
+
return final;
|
|
1239
|
+
}
|
|
1240
|
+
__name(serializeArray, "serializeArray");
|
|
1241
|
+
}, "stringify");
|
|
1242
|
+
var JSON5 = {
|
|
1243
|
+
parse,
|
|
1244
|
+
stringify
|
|
1245
|
+
};
|
|
1246
|
+
var lib = JSON5;
|
|
1247
|
+
var dist_default = lib;
|
|
1248
|
+
|
|
1249
|
+
// src/classes/configvalidator/ConfigValidator.class.ts
|
|
1250
|
+
var import_zod = require("zod");
|
|
1251
|
+
var privilege_name_list = [
|
|
1252
|
+
"invoke_functions",
|
|
1253
|
+
"define_functions",
|
|
1254
|
+
"undefine_functions",
|
|
1255
|
+
"define_constants",
|
|
1256
|
+
"undefine_constants",
|
|
1257
|
+
"define_dependencies",
|
|
1258
|
+
"undefine_dependencies",
|
|
1259
|
+
"admin_privileges",
|
|
1260
|
+
"all_privileges"
|
|
1261
|
+
];
|
|
1262
|
+
var tls_min_version_list = [
|
|
1263
|
+
"TLSv1.2",
|
|
1264
|
+
"TLSv1.3"
|
|
1265
|
+
];
|
|
1266
|
+
var worker_runtime_options_schema = import_zod.z.object({
|
|
1267
|
+
call_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1268
|
+
control_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1269
|
+
start_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1270
|
+
stop_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1271
|
+
restart_on_failure: import_zod.z.boolean().optional(),
|
|
1272
|
+
max_restarts_per_worker: import_zod.z.number().int().nonnegative().optional(),
|
|
1273
|
+
max_pending_calls_per_worker: import_zod.z.number().int().positive().optional(),
|
|
1274
|
+
restart_base_delay_ms: import_zod.z.number().int().positive().optional(),
|
|
1275
|
+
restart_max_delay_ms: import_zod.z.number().int().positive().optional(),
|
|
1276
|
+
restart_jitter_ms: import_zod.z.number().int().nonnegative().optional()
|
|
1277
|
+
}).strict();
|
|
1278
|
+
var rate_limiter_schema = import_zod.z.object({
|
|
1279
|
+
enabled: import_zod.z.boolean().optional(),
|
|
1280
|
+
tokens_per_interval: import_zod.z.number().int().positive().optional(),
|
|
1281
|
+
interval_ms: import_zod.z.number().int().positive().optional(),
|
|
1282
|
+
burst_tokens: import_zod.z.number().int().positive().optional(),
|
|
1283
|
+
disconnect_on_limit: import_zod.z.boolean().optional()
|
|
1284
|
+
}).strict();
|
|
1285
|
+
var abuse_controls_schema = import_zod.z.object({
|
|
1286
|
+
connection_controls: import_zod.z.object({
|
|
1287
|
+
max_concurrent_sockets: import_zod.z.number().int().positive().optional(),
|
|
1288
|
+
max_concurrent_handshakes: import_zod.z.number().int().positive().optional(),
|
|
1289
|
+
max_unauthenticated_sessions: import_zod.z.number().int().positive().optional(),
|
|
1290
|
+
global_connection_window_ms: import_zod.z.number().int().positive().optional(),
|
|
1291
|
+
global_max_new_connections_per_window: import_zod.z.number().int().positive().optional(),
|
|
1292
|
+
per_ip_max_new_connections_per_window: import_zod.z.number().int().positive().optional(),
|
|
1293
|
+
tls_handshake_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1294
|
+
auth_message_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1295
|
+
max_pre_auth_frame_bytes: import_zod.z.number().int().positive().optional(),
|
|
1296
|
+
max_post_auth_frame_bytes: import_zod.z.number().int().positive().optional()
|
|
1297
|
+
}).strict().optional(),
|
|
1298
|
+
auth_controls: import_zod.z.object({
|
|
1299
|
+
pending_auth_window_ms: import_zod.z.number().int().positive().optional(),
|
|
1300
|
+
max_pending_auth_attempts_per_ip_per_window: import_zod.z.number().int().positive().optional(),
|
|
1301
|
+
failed_auth_window_ms: import_zod.z.number().int().positive().optional(),
|
|
1302
|
+
max_failed_auth_per_ip_per_window: import_zod.z.number().int().positive().optional(),
|
|
1303
|
+
max_failed_auth_per_api_key_per_window: import_zod.z.number().int().positive().optional(),
|
|
1304
|
+
block_duration_ms: import_zod.z.number().int().positive().optional(),
|
|
1305
|
+
enable_blocklist: import_zod.z.boolean().optional()
|
|
1306
|
+
}).strict().optional(),
|
|
1307
|
+
request_controls: import_zod.z.object({
|
|
1308
|
+
max_in_flight_requests_per_connection: import_zod.z.number().int().positive().optional(),
|
|
1309
|
+
per_connection: rate_limiter_schema.optional(),
|
|
1310
|
+
per_api_key: rate_limiter_schema.optional(),
|
|
1311
|
+
per_ip: rate_limiter_schema.optional()
|
|
1312
|
+
}).strict().optional(),
|
|
1313
|
+
observability: import_zod.z.object({
|
|
1314
|
+
enable_console_log: import_zod.z.boolean().optional()
|
|
1315
|
+
}).strict().optional()
|
|
1316
|
+
}).strict();
|
|
1317
|
+
var daemon_server_config_schema = import_zod.z.object({
|
|
1318
|
+
information: import_zod.z.object({
|
|
1319
|
+
server_name: import_zod.z.string().min(1)
|
|
1320
|
+
}).strict(),
|
|
1321
|
+
network: import_zod.z.object({
|
|
1322
|
+
bind_addr: import_zod.z.string().min(1),
|
|
1323
|
+
tcp_listen_port: import_zod.z.number().int().positive().max(65535)
|
|
1324
|
+
}).strict(),
|
|
1325
|
+
tls_mtls: import_zod.z.object({
|
|
1326
|
+
key_file: import_zod.z.string().min(1),
|
|
1327
|
+
cert_file: import_zod.z.string().min(1),
|
|
1328
|
+
ca_file: import_zod.z.string().min(1),
|
|
1329
|
+
crl_file: import_zod.z.string().min(1).optional(),
|
|
1330
|
+
min_version: import_zod.z.enum(tls_min_version_list).optional(),
|
|
1331
|
+
cipher_suites: import_zod.z.string().min(1).optional(),
|
|
1332
|
+
handshake_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1333
|
+
request_timeout_ms: import_zod.z.number().int().positive().optional(),
|
|
1334
|
+
max_frame_bytes: import_zod.z.number().int().positive().optional()
|
|
1335
|
+
}).strict(),
|
|
1336
|
+
workerprocedurecall: import_zod.z.object({
|
|
1337
|
+
count: import_zod.z.number().int().positive(),
|
|
1338
|
+
constructor_options: worker_runtime_options_schema.optional(),
|
|
1339
|
+
start_options: worker_runtime_options_schema.optional()
|
|
1340
|
+
}).strict(),
|
|
1341
|
+
abuse_controls: abuse_controls_schema.optional(),
|
|
1342
|
+
observability: import_zod.z.object({
|
|
1343
|
+
enable_console_log: import_zod.z.boolean().optional(),
|
|
1344
|
+
log_worker_events: import_zod.z.boolean().optional(),
|
|
1345
|
+
metrics_log_interval_ms: import_zod.z.number().int().positive().optional()
|
|
1346
|
+
}).strict().optional()
|
|
1347
|
+
}).strict();
|
|
1348
|
+
var daemon_api_key_config_schema = import_zod.z.object({
|
|
1349
|
+
api_keys: import_zod.z.array(import_zod.z.object({
|
|
1350
|
+
key_id: import_zod.z.string().min(1),
|
|
1351
|
+
api_key: import_zod.z.string().min(1),
|
|
1352
|
+
privileges: import_zod.z.array(import_zod.z.enum(privilege_name_list)).min(1),
|
|
1353
|
+
enabled: import_zod.z.boolean().optional(),
|
|
1354
|
+
identity_constraints: import_zod.z.object({
|
|
1355
|
+
remote_address_regex: import_zod.z.string().min(1).optional(),
|
|
1356
|
+
tls_peer_subject_regex: import_zod.z.string().min(1).optional(),
|
|
1357
|
+
tls_peer_san_regex: import_zod.z.string().min(1).optional(),
|
|
1358
|
+
tls_peer_fingerprint256_regex: import_zod.z.string().min(1).optional(),
|
|
1359
|
+
tls_peer_serial_number_regex: import_zod.z.string().min(1).optional()
|
|
1360
|
+
}).strict().optional()
|
|
1361
|
+
}).strict()).min(1)
|
|
1362
|
+
}).strict();
|
|
1363
|
+
function BuildZodErrorMessage(params) {
|
|
1364
|
+
const message_lines = params.error.issues.map((issue) => {
|
|
1365
|
+
const issue_path = issue.path.length > 0 ? issue.path.join(".") : "<root>";
|
|
1366
|
+
return `${issue_path}: ${issue.message}`;
|
|
1367
|
+
});
|
|
1368
|
+
return `${params.prefix}
|
|
1369
|
+
${message_lines.join("\n")}`;
|
|
1370
|
+
}
|
|
1371
|
+
__name(BuildZodErrorMessage, "BuildZodErrorMessage");
|
|
1372
|
+
function CompileRegex(params) {
|
|
1373
|
+
try {
|
|
1374
|
+
return new RegExp(params.source);
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
1377
|
+
throw new Error(`Invalid regex for ${params.label}: ${error_message}`);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
__name(CompileRegex, "CompileRegex");
|
|
1381
|
+
var _ConfigValidator = class _ConfigValidator {
|
|
1382
|
+
validateServerConfig(params) {
|
|
1383
|
+
const parse_result = daemon_server_config_schema.safeParse(params.server_config_raw);
|
|
1384
|
+
if (!parse_result.success) {
|
|
1385
|
+
throw new Error(BuildZodErrorMessage({
|
|
1386
|
+
prefix: "Invalid server config.",
|
|
1387
|
+
error: parse_result.error
|
|
1388
|
+
}));
|
|
1389
|
+
}
|
|
1390
|
+
return parse_result.data;
|
|
1391
|
+
}
|
|
1392
|
+
validateApiKeysConfig(params) {
|
|
1393
|
+
const parse_result = daemon_api_key_config_schema.safeParse(params.api_keys_config_raw);
|
|
1394
|
+
if (!parse_result.success) {
|
|
1395
|
+
throw new Error(BuildZodErrorMessage({
|
|
1396
|
+
prefix: "Invalid api-keys config.",
|
|
1397
|
+
error: parse_result.error
|
|
1398
|
+
}));
|
|
1399
|
+
}
|
|
1400
|
+
this.assertUniqueApiKeys({
|
|
1401
|
+
api_keys: parse_result.data.api_keys
|
|
1402
|
+
});
|
|
1403
|
+
this.assertUniqueKeyIds({
|
|
1404
|
+
api_keys: parse_result.data.api_keys
|
|
1405
|
+
});
|
|
1406
|
+
return parse_result.data;
|
|
1407
|
+
}
|
|
1408
|
+
toRuntimeApiKeysConfig(params) {
|
|
1409
|
+
return params.api_keys_config.api_keys.map((api_key_entry) => {
|
|
1410
|
+
const compiled_identity_constraints = this.compileIdentityConstraints({
|
|
1411
|
+
api_key_entry
|
|
1412
|
+
});
|
|
1413
|
+
const runtime_entry = {
|
|
1414
|
+
key_id: api_key_entry.key_id,
|
|
1415
|
+
api_key: api_key_entry.api_key,
|
|
1416
|
+
privileges: [
|
|
1417
|
+
...api_key_entry.privileges
|
|
1418
|
+
],
|
|
1419
|
+
enabled: api_key_entry.enabled ?? true,
|
|
1420
|
+
identity_constraints: compiled_identity_constraints
|
|
1421
|
+
};
|
|
1422
|
+
return runtime_entry;
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
compileIdentityConstraints(params) {
|
|
1426
|
+
const constraints = params.api_key_entry.identity_constraints;
|
|
1427
|
+
if (!constraints) {
|
|
1428
|
+
return void 0;
|
|
1429
|
+
}
|
|
1430
|
+
const compiled_constraints = {};
|
|
1431
|
+
if (constraints.remote_address_regex) {
|
|
1432
|
+
compiled_constraints.remote_address_regex = CompileRegex({
|
|
1433
|
+
source: constraints.remote_address_regex,
|
|
1434
|
+
label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.remote_address_regex`
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
if (constraints.tls_peer_subject_regex) {
|
|
1438
|
+
compiled_constraints.tls_peer_subject_regex = CompileRegex({
|
|
1439
|
+
source: constraints.tls_peer_subject_regex,
|
|
1440
|
+
label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_subject_regex`
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
if (constraints.tls_peer_san_regex) {
|
|
1444
|
+
compiled_constraints.tls_peer_san_regex = CompileRegex({
|
|
1445
|
+
source: constraints.tls_peer_san_regex,
|
|
1446
|
+
label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_san_regex`
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
if (constraints.tls_peer_fingerprint256_regex) {
|
|
1450
|
+
compiled_constraints.tls_peer_fingerprint256_regex = CompileRegex({
|
|
1451
|
+
source: constraints.tls_peer_fingerprint256_regex,
|
|
1452
|
+
label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_fingerprint256_regex`
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
if (constraints.tls_peer_serial_number_regex) {
|
|
1456
|
+
compiled_constraints.tls_peer_serial_number_regex = CompileRegex({
|
|
1457
|
+
source: constraints.tls_peer_serial_number_regex,
|
|
1458
|
+
label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_serial_number_regex`
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
return compiled_constraints;
|
|
1462
|
+
}
|
|
1463
|
+
assertUniqueApiKeys(params) {
|
|
1464
|
+
const seen_api_keys = /* @__PURE__ */ new Set();
|
|
1465
|
+
for (const api_key_entry of params.api_keys) {
|
|
1466
|
+
if (seen_api_keys.has(api_key_entry.api_key)) {
|
|
1467
|
+
throw new Error(`Duplicate api_key found in api-keys config: ${api_key_entry.api_key}`);
|
|
1468
|
+
}
|
|
1469
|
+
seen_api_keys.add(api_key_entry.api_key);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
assertUniqueKeyIds(params) {
|
|
1473
|
+
const seen_key_ids = /* @__PURE__ */ new Set();
|
|
1474
|
+
for (const api_key_entry of params.api_keys) {
|
|
1475
|
+
if (seen_key_ids.has(api_key_entry.key_id)) {
|
|
1476
|
+
throw new Error(`Duplicate key_id found in api-keys config: ${api_key_entry.key_id}`);
|
|
1477
|
+
}
|
|
1478
|
+
seen_key_ids.add(api_key_entry.key_id);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
__name(_ConfigValidator, "ConfigValidator");
|
|
1483
|
+
var ConfigValidator = _ConfigValidator;
|
|
1484
|
+
|
|
1485
|
+
// src/classes/configfileloader/ConfigFileLoader.class.ts
|
|
1486
|
+
function ReadUtf8File(params) {
|
|
1487
|
+
try {
|
|
1488
|
+
return import_node_fs.default.readFileSync(params.file_path, "utf8");
|
|
1489
|
+
} catch (error) {
|
|
1490
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
1491
|
+
throw new Error(`Unable to read file "${params.file_path}": ${error_message}`);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
__name(ReadUtf8File, "ReadUtf8File");
|
|
1495
|
+
function ResolvePath(params) {
|
|
1496
|
+
if (import_node_path.default.isAbsolute(params.file_path)) {
|
|
1497
|
+
return params.file_path;
|
|
1498
|
+
}
|
|
1499
|
+
return import_node_path.default.resolve(params.base_dir, params.file_path);
|
|
1500
|
+
}
|
|
1501
|
+
__name(ResolvePath, "ResolvePath");
|
|
1502
|
+
function ParseJson5(params) {
|
|
1503
|
+
try {
|
|
1504
|
+
return dist_default.parse(params.content);
|
|
1505
|
+
} catch (error) {
|
|
1506
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
1507
|
+
throw new Error(`Invalid JSON5 in "${params.source_path}": ${error_message}`);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
__name(ParseJson5, "ParseJson5");
|
|
1511
|
+
var _ConfigFileLoader = class _ConfigFileLoader {
|
|
1512
|
+
constructor(params) {
|
|
1513
|
+
__publicField(this, "config_validator");
|
|
1514
|
+
this.config_validator = params?.config_validator ?? new ConfigValidator();
|
|
1515
|
+
}
|
|
1516
|
+
loadDaemonConfig(params) {
|
|
1517
|
+
const server_config_path = ResolvePath({
|
|
1518
|
+
file_path: params.config_paths.server_config_path,
|
|
1519
|
+
base_dir: process.cwd()
|
|
1520
|
+
});
|
|
1521
|
+
const api_keys_config_path = ResolvePath({
|
|
1522
|
+
file_path: params.config_paths.api_keys_config_path,
|
|
1523
|
+
base_dir: process.cwd()
|
|
1524
|
+
});
|
|
1525
|
+
const server_config_raw = this.readJson5File({
|
|
1526
|
+
file_path: server_config_path
|
|
1527
|
+
});
|
|
1528
|
+
const api_keys_config_raw = this.readJson5File({
|
|
1529
|
+
file_path: api_keys_config_path
|
|
1530
|
+
});
|
|
1531
|
+
const server_config = this.config_validator.validateServerConfig({
|
|
1532
|
+
server_config_raw
|
|
1533
|
+
});
|
|
1534
|
+
const api_keys_config = this.config_validator.validateApiKeysConfig({
|
|
1535
|
+
api_keys_config_raw
|
|
1536
|
+
});
|
|
1537
|
+
const runtime_tls_mtls = this.resolveTlsMaterial({
|
|
1538
|
+
tls_file_config: server_config.tls_mtls,
|
|
1539
|
+
config_file_dir: import_node_path.default.dirname(server_config_path)
|
|
1540
|
+
});
|
|
1541
|
+
const runtime_api_keys = this.config_validator.toRuntimeApiKeysConfig({
|
|
1542
|
+
api_keys_config
|
|
1543
|
+
});
|
|
1544
|
+
return {
|
|
1545
|
+
server_config: {
|
|
1546
|
+
...server_config,
|
|
1547
|
+
tls_mtls: runtime_tls_mtls
|
|
1548
|
+
},
|
|
1549
|
+
api_keys_config: {
|
|
1550
|
+
api_keys: runtime_api_keys
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
readJson5File(params) {
|
|
1555
|
+
const file_content = ReadUtf8File({
|
|
1556
|
+
file_path: params.file_path
|
|
1557
|
+
});
|
|
1558
|
+
return ParseJson5({
|
|
1559
|
+
content: file_content,
|
|
1560
|
+
source_path: params.file_path
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
resolveTlsMaterial(params) {
|
|
1564
|
+
const key_pem = this.readPemFile({
|
|
1565
|
+
pem_path: params.tls_file_config.key_file,
|
|
1566
|
+
config_file_dir: params.config_file_dir,
|
|
1567
|
+
label: "tls_mtls.key_file"
|
|
1568
|
+
});
|
|
1569
|
+
const cert_pem = this.readPemFile({
|
|
1570
|
+
pem_path: params.tls_file_config.cert_file,
|
|
1571
|
+
config_file_dir: params.config_file_dir,
|
|
1572
|
+
label: "tls_mtls.cert_file"
|
|
1573
|
+
});
|
|
1574
|
+
const ca_pem = this.readPemFile({
|
|
1575
|
+
pem_path: params.tls_file_config.ca_file,
|
|
1576
|
+
config_file_dir: params.config_file_dir,
|
|
1577
|
+
label: "tls_mtls.ca_file"
|
|
1578
|
+
});
|
|
1579
|
+
const crl_pem = params.tls_file_config.crl_file ? this.readPemFile({
|
|
1580
|
+
pem_path: params.tls_file_config.crl_file,
|
|
1581
|
+
config_file_dir: params.config_file_dir,
|
|
1582
|
+
label: "tls_mtls.crl_file"
|
|
1583
|
+
}) : void 0;
|
|
1584
|
+
return {
|
|
1585
|
+
key_pem,
|
|
1586
|
+
cert_pem,
|
|
1587
|
+
ca_pem,
|
|
1588
|
+
crl_pem,
|
|
1589
|
+
min_version: params.tls_file_config.min_version,
|
|
1590
|
+
cipher_suites: params.tls_file_config.cipher_suites,
|
|
1591
|
+
handshake_timeout_ms: params.tls_file_config.handshake_timeout_ms,
|
|
1592
|
+
request_timeout_ms: params.tls_file_config.request_timeout_ms,
|
|
1593
|
+
max_frame_bytes: params.tls_file_config.max_frame_bytes
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
readPemFile(params) {
|
|
1597
|
+
const absolute_file_path = ResolvePath({
|
|
1598
|
+
file_path: params.pem_path,
|
|
1599
|
+
base_dir: params.config_file_dir
|
|
1600
|
+
});
|
|
1601
|
+
const pem_content = ReadUtf8File({
|
|
1602
|
+
file_path: absolute_file_path
|
|
1603
|
+
}).trim();
|
|
1604
|
+
if (!pem_content.includes("BEGIN")) {
|
|
1605
|
+
throw new Error(`File "${absolute_file_path}" for ${params.label} does not look like a PEM file.`);
|
|
1606
|
+
}
|
|
1607
|
+
return `${pem_content}
|
|
1608
|
+
`;
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
__name(_ConfigFileLoader, "ConfigFileLoader");
|
|
1612
|
+
var ConfigFileLoader = _ConfigFileLoader;
|
|
1613
|
+
|
|
1614
|
+
// src/classes/daemoncli/DaemonCli.class.ts
|
|
1615
|
+
var default_server_config_path = "./config/server.config.json5";
|
|
1616
|
+
var default_api_keys_config_path = "./config/api_keys.config.json5";
|
|
1617
|
+
var default_tls_output_dir = "./config/certs";
|
|
1618
|
+
var default_ca_common_name = "nodenetproccalld-local-ca";
|
|
1619
|
+
var default_server_common_name = "localhost";
|
|
1620
|
+
var default_client_common_name = "nodenetproccalld-client";
|
|
1621
|
+
var default_tls_valid_days = 825;
|
|
1622
|
+
var _DaemonCli = class _DaemonCli {
|
|
1623
|
+
parseOptions() {
|
|
1624
|
+
const options = {
|
|
1625
|
+
server_config_path: default_server_config_path,
|
|
1626
|
+
api_keys_config_path: default_api_keys_config_path,
|
|
1627
|
+
help: false,
|
|
1628
|
+
tls_generation: {
|
|
1629
|
+
enabled: false,
|
|
1630
|
+
output_dir: default_tls_output_dir,
|
|
1631
|
+
overwrite: false,
|
|
1632
|
+
ca_common_name: default_ca_common_name,
|
|
1633
|
+
server_common_name: default_server_common_name,
|
|
1634
|
+
client_common_name: default_client_common_name,
|
|
1635
|
+
valid_days: default_tls_valid_days
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
const argv = process.argv.slice(2);
|
|
1639
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
1640
|
+
const token2 = argv[index];
|
|
1641
|
+
if (token2 === "--help" || token2 === "-h") {
|
|
1642
|
+
options.help = true;
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1645
|
+
if (token2 === "--server-config") {
|
|
1646
|
+
const next_value = argv[index + 1];
|
|
1647
|
+
if (!next_value) {
|
|
1648
|
+
throw new Error("Missing value for --server-config");
|
|
1649
|
+
}
|
|
1650
|
+
options.server_config_path = next_value;
|
|
1651
|
+
index += 1;
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
if (token2 === "--api-keys-config") {
|
|
1655
|
+
const next_value = argv[index + 1];
|
|
1656
|
+
if (!next_value) {
|
|
1657
|
+
throw new Error("Missing value for --api-keys-config");
|
|
1658
|
+
}
|
|
1659
|
+
options.api_keys_config_path = next_value;
|
|
1660
|
+
index += 1;
|
|
1661
|
+
continue;
|
|
1662
|
+
}
|
|
1663
|
+
if (token2 === "--generate-tls-material") {
|
|
1664
|
+
options.tls_generation.enabled = true;
|
|
1665
|
+
continue;
|
|
1666
|
+
}
|
|
1667
|
+
if (token2 === "--tls-output-dir") {
|
|
1668
|
+
const next_value = argv[index + 1];
|
|
1669
|
+
if (!next_value) {
|
|
1670
|
+
throw new Error("Missing value for --tls-output-dir");
|
|
1671
|
+
}
|
|
1672
|
+
options.tls_generation.output_dir = next_value;
|
|
1673
|
+
index += 1;
|
|
1674
|
+
continue;
|
|
1675
|
+
}
|
|
1676
|
+
if (token2 === "--tls-overwrite") {
|
|
1677
|
+
options.tls_generation.overwrite = true;
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1680
|
+
if (token2 === "--tls-ca-cn") {
|
|
1681
|
+
const next_value = argv[index + 1];
|
|
1682
|
+
if (!next_value) {
|
|
1683
|
+
throw new Error("Missing value for --tls-ca-cn");
|
|
1684
|
+
}
|
|
1685
|
+
options.tls_generation.ca_common_name = next_value;
|
|
1686
|
+
index += 1;
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
if (token2 === "--tls-server-cn") {
|
|
1690
|
+
const next_value = argv[index + 1];
|
|
1691
|
+
if (!next_value) {
|
|
1692
|
+
throw new Error("Missing value for --tls-server-cn");
|
|
1693
|
+
}
|
|
1694
|
+
options.tls_generation.server_common_name = next_value;
|
|
1695
|
+
index += 1;
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1698
|
+
if (token2 === "--tls-client-cn") {
|
|
1699
|
+
const next_value = argv[index + 1];
|
|
1700
|
+
if (!next_value) {
|
|
1701
|
+
throw new Error("Missing value for --tls-client-cn");
|
|
1702
|
+
}
|
|
1703
|
+
options.tls_generation.client_common_name = next_value;
|
|
1704
|
+
index += 1;
|
|
1705
|
+
continue;
|
|
1706
|
+
}
|
|
1707
|
+
if (token2 === "--tls-valid-days") {
|
|
1708
|
+
const next_value = argv[index + 1];
|
|
1709
|
+
if (!next_value) {
|
|
1710
|
+
throw new Error("Missing value for --tls-valid-days");
|
|
1711
|
+
}
|
|
1712
|
+
const valid_days = Number(next_value);
|
|
1713
|
+
if (!Number.isInteger(valid_days) || valid_days <= 0) {
|
|
1714
|
+
throw new Error("--tls-valid-days must be a positive integer.");
|
|
1715
|
+
}
|
|
1716
|
+
options.tls_generation.valid_days = valid_days;
|
|
1717
|
+
index += 1;
|
|
1718
|
+
continue;
|
|
1719
|
+
}
|
|
1720
|
+
throw new Error(`Unknown argument: ${token2}`);
|
|
1721
|
+
}
|
|
1722
|
+
return options;
|
|
1723
|
+
}
|
|
1724
|
+
printHelp() {
|
|
1725
|
+
const help_text = [
|
|
1726
|
+
"nodenetproccalld",
|
|
1727
|
+
"",
|
|
1728
|
+
"Usage:",
|
|
1729
|
+
" node dist/index.js [options]",
|
|
1730
|
+
"",
|
|
1731
|
+
"Options:",
|
|
1732
|
+
" --server-config <path> Path to server JSON5 config file.",
|
|
1733
|
+
" Default: ./config/server.config.json5",
|
|
1734
|
+
" --api-keys-config <path> Path to api keys JSON5 config file.",
|
|
1735
|
+
" Default: ./config/api_keys.config.json5",
|
|
1736
|
+
" --generate-tls-material Generate CA/server/client TLS material and exit.",
|
|
1737
|
+
" --tls-output-dir <path> Output directory for generated TLS files.",
|
|
1738
|
+
" Default: ./config/certs",
|
|
1739
|
+
" --tls-overwrite Overwrite existing TLS files in output dir.",
|
|
1740
|
+
" --tls-ca-cn <value> CA certificate common name.",
|
|
1741
|
+
" Default: nodenetproccalld-local-ca",
|
|
1742
|
+
" --tls-server-cn <value> Server certificate common name.",
|
|
1743
|
+
" Default: localhost",
|
|
1744
|
+
" --tls-client-cn <value> Client certificate common name.",
|
|
1745
|
+
" Default: nodenetproccalld-client",
|
|
1746
|
+
" --tls-valid-days <number> Certificate validity in days.",
|
|
1747
|
+
" Default: 825",
|
|
1748
|
+
" -h, --help Show this help message."
|
|
1749
|
+
].join("\n");
|
|
1750
|
+
console.log(help_text);
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
__name(_DaemonCli, "DaemonCli");
|
|
1754
|
+
var DaemonCli = _DaemonCli;
|
|
1755
|
+
|
|
1756
|
+
// src/classes/networkprocedurecalldaemon/NetworkProcedureCallDaemon.class.ts
|
|
1757
|
+
var import_networkprocedurecall = require("@opsimathically/networkprocedurecall");
|
|
1758
|
+
var import_workerprocedurecall = require("@opsimathically/workerprocedurecall");
|
|
1759
|
+
function ToIsoTimestamp() {
|
|
1760
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1761
|
+
}
|
|
1762
|
+
__name(ToIsoTimestamp, "ToIsoTimestamp");
|
|
1763
|
+
var _NetworkProcedureCallDaemon = class _NetworkProcedureCallDaemon {
|
|
1764
|
+
constructor(params) {
|
|
1765
|
+
__publicField(this, "config_paths");
|
|
1766
|
+
__publicField(this, "config_file_loader");
|
|
1767
|
+
__publicField(this, "lifecycle_state", "stopped");
|
|
1768
|
+
__publicField(this, "daemon_config", null);
|
|
1769
|
+
__publicField(this, "workerprocedurecall", null);
|
|
1770
|
+
__publicField(this, "networkprocedurecall", null);
|
|
1771
|
+
__publicField(this, "api_key_authorizer", null);
|
|
1772
|
+
__publicField(this, "worker_event_listener_id", null);
|
|
1773
|
+
__publicField(this, "metrics_log_interval_handle", null);
|
|
1774
|
+
this.config_paths = params.config_paths;
|
|
1775
|
+
this.config_file_loader = params.config_file_loader ?? new ConfigFileLoader();
|
|
1776
|
+
}
|
|
1777
|
+
async start() {
|
|
1778
|
+
if (this.lifecycle_state === "running") {
|
|
1779
|
+
throw new Error("Daemon is already running.");
|
|
1780
|
+
}
|
|
1781
|
+
if (this.lifecycle_state === "starting") {
|
|
1782
|
+
throw new Error("Daemon startup is already in progress.");
|
|
1783
|
+
}
|
|
1784
|
+
if (this.lifecycle_state === "stopping") {
|
|
1785
|
+
throw new Error("Daemon stop is in progress. Wait for stop to complete.");
|
|
1786
|
+
}
|
|
1787
|
+
this.lifecycle_state = "starting";
|
|
1788
|
+
try {
|
|
1789
|
+
this.daemon_config = this.config_file_loader.loadDaemonConfig({
|
|
1790
|
+
config_paths: this.config_paths
|
|
1791
|
+
});
|
|
1792
|
+
this.api_key_authorizer = new ApiKeyAuthorizer({
|
|
1793
|
+
api_key_entries: this.daemon_config.api_keys_config.api_keys
|
|
1794
|
+
});
|
|
1795
|
+
const constructor_options = this.daemon_config.server_config.workerprocedurecall.constructor_options;
|
|
1796
|
+
this.workerprocedurecall = constructor_options ? new import_workerprocedurecall.WorkerProcedureCall(constructor_options) : new import_workerprocedurecall.WorkerProcedureCall();
|
|
1797
|
+
const log_worker_events = this.daemon_config.server_config.observability?.log_worker_events ?? true;
|
|
1798
|
+
if (log_worker_events) {
|
|
1799
|
+
this.worker_event_listener_id = this.workerprocedurecall.onWorkerEvent({
|
|
1800
|
+
listener: /* @__PURE__ */ __name((worker_event) => {
|
|
1801
|
+
this.logWorkerEvent({
|
|
1802
|
+
worker_event
|
|
1803
|
+
});
|
|
1804
|
+
}, "listener")
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
await this.workerprocedurecall.startWorkers({
|
|
1808
|
+
count: this.daemon_config.server_config.workerprocedurecall.count,
|
|
1809
|
+
...this.daemon_config.server_config.workerprocedurecall.start_options ?? {}
|
|
1810
|
+
});
|
|
1811
|
+
const networkprocedurecall_workerprocedurecall = this.workerprocedurecall;
|
|
1812
|
+
this.networkprocedurecall = new import_networkprocedurecall.NetworkProcedureCall({
|
|
1813
|
+
workerprocedurecall: networkprocedurecall_workerprocedurecall
|
|
1814
|
+
});
|
|
1815
|
+
const auth_callback = this.createAuthCallback();
|
|
1816
|
+
const start_params = this.buildServerStartParams({
|
|
1817
|
+
auth_callback
|
|
1818
|
+
});
|
|
1819
|
+
await this.networkprocedurecall.start(start_params);
|
|
1820
|
+
this.startMetricsLogging();
|
|
1821
|
+
this.lifecycle_state = "running";
|
|
1822
|
+
this.logMessage({
|
|
1823
|
+
severity: "info",
|
|
1824
|
+
message: `Daemon started: ${start_params.information.server_name} on ${start_params.network.bind_addr}:${start_params.network.tcp_listen_port}`
|
|
1825
|
+
});
|
|
1826
|
+
} catch (error) {
|
|
1827
|
+
this.lifecycle_state = "stopped";
|
|
1828
|
+
await this.stopBestEffort();
|
|
1829
|
+
throw error;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
async stop() {
|
|
1833
|
+
if (this.lifecycle_state === "stopped") {
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
if (this.lifecycle_state === "stopping") {
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
this.lifecycle_state = "stopping";
|
|
1840
|
+
await this.stopBestEffort();
|
|
1841
|
+
this.lifecycle_state = "stopped";
|
|
1842
|
+
this.logMessage({
|
|
1843
|
+
severity: "info",
|
|
1844
|
+
message: "Daemon stopped."
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
getRuntimeSnapshot() {
|
|
1848
|
+
return {
|
|
1849
|
+
lifecycle_state: this.lifecycle_state,
|
|
1850
|
+
server_name: this.daemon_config?.server_config.information.server_name,
|
|
1851
|
+
bind_addr: this.daemon_config?.server_config.network.bind_addr,
|
|
1852
|
+
tcp_listen_port: this.daemon_config?.server_config.network.tcp_listen_port,
|
|
1853
|
+
worker_health_states: this.workerprocedurecall?.getWorkerHealthStates(),
|
|
1854
|
+
abuse_metrics: this.networkprocedurecall?.getAbuseMetrics()
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
createAuthCallback() {
|
|
1858
|
+
return async (auth_callback_params) => {
|
|
1859
|
+
const authorizer = this.requireApiKeyAuthorizer();
|
|
1860
|
+
return await authorizer.authenticate({
|
|
1861
|
+
auth_callback_params
|
|
1862
|
+
});
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
buildServerStartParams(params) {
|
|
1866
|
+
const daemon_config = this.requireDaemonConfig();
|
|
1867
|
+
const abuse_controls_from_file = daemon_config.server_config.abuse_controls;
|
|
1868
|
+
const enable_console_log = daemon_config.server_config.observability?.enable_console_log;
|
|
1869
|
+
let merged_abuse_controls = abuse_controls_from_file;
|
|
1870
|
+
if (enable_console_log !== void 0) {
|
|
1871
|
+
merged_abuse_controls = {
|
|
1872
|
+
...abuse_controls_from_file ?? {},
|
|
1873
|
+
observability: {
|
|
1874
|
+
...abuse_controls_from_file?.observability ?? {},
|
|
1875
|
+
enable_console_log
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
return {
|
|
1880
|
+
information: {
|
|
1881
|
+
server_name: daemon_config.server_config.information.server_name
|
|
1882
|
+
},
|
|
1883
|
+
network: {
|
|
1884
|
+
bind_addr: daemon_config.server_config.network.bind_addr,
|
|
1885
|
+
tcp_listen_port: daemon_config.server_config.network.tcp_listen_port
|
|
1886
|
+
},
|
|
1887
|
+
tls_mtls: {
|
|
1888
|
+
...daemon_config.server_config.tls_mtls
|
|
1889
|
+
},
|
|
1890
|
+
abuse_controls: merged_abuse_controls,
|
|
1891
|
+
auth_callback: params.auth_callback
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
startMetricsLogging() {
|
|
1895
|
+
this.clearMetricsLoggingInterval();
|
|
1896
|
+
const daemon_config = this.requireDaemonConfig();
|
|
1897
|
+
const metrics_log_interval_ms = daemon_config.server_config.observability?.metrics_log_interval_ms;
|
|
1898
|
+
if (!metrics_log_interval_ms) {
|
|
1899
|
+
return;
|
|
1900
|
+
}
|
|
1901
|
+
this.metrics_log_interval_handle = setInterval(() => {
|
|
1902
|
+
if (!this.networkprocedurecall || !this.workerprocedurecall) {
|
|
1903
|
+
return;
|
|
1904
|
+
}
|
|
1905
|
+
const abuse_metrics = this.networkprocedurecall.getAbuseMetrics();
|
|
1906
|
+
const worker_health_states = this.workerprocedurecall.getWorkerHealthStates();
|
|
1907
|
+
this.logMessage({
|
|
1908
|
+
severity: "info",
|
|
1909
|
+
message: `runtime_metrics abuse=${JSON.stringify(abuse_metrics)} worker_health=${JSON.stringify(worker_health_states)}`
|
|
1910
|
+
});
|
|
1911
|
+
}, metrics_log_interval_ms);
|
|
1912
|
+
this.metrics_log_interval_handle.unref();
|
|
1913
|
+
}
|
|
1914
|
+
clearMetricsLoggingInterval() {
|
|
1915
|
+
if (this.metrics_log_interval_handle) {
|
|
1916
|
+
clearInterval(this.metrics_log_interval_handle);
|
|
1917
|
+
this.metrics_log_interval_handle = null;
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
async stopBestEffort() {
|
|
1921
|
+
this.clearMetricsLoggingInterval();
|
|
1922
|
+
const stop_errors = [];
|
|
1923
|
+
if (this.networkprocedurecall) {
|
|
1924
|
+
try {
|
|
1925
|
+
await this.networkprocedurecall.stop();
|
|
1926
|
+
} catch (error) {
|
|
1927
|
+
stop_errors.push(error);
|
|
1928
|
+
}
|
|
1929
|
+
this.networkprocedurecall = null;
|
|
1930
|
+
}
|
|
1931
|
+
if (this.workerprocedurecall && this.worker_event_listener_id !== null) {
|
|
1932
|
+
try {
|
|
1933
|
+
this.workerprocedurecall.offWorkerEvent({
|
|
1934
|
+
listener_id: this.worker_event_listener_id
|
|
1935
|
+
});
|
|
1936
|
+
} catch (error) {
|
|
1937
|
+
stop_errors.push(error);
|
|
1938
|
+
}
|
|
1939
|
+
this.worker_event_listener_id = null;
|
|
1940
|
+
}
|
|
1941
|
+
if (this.workerprocedurecall) {
|
|
1942
|
+
try {
|
|
1943
|
+
await this.workerprocedurecall.stopWorkers();
|
|
1944
|
+
} catch (error) {
|
|
1945
|
+
stop_errors.push(error);
|
|
1946
|
+
}
|
|
1947
|
+
this.workerprocedurecall = null;
|
|
1948
|
+
}
|
|
1949
|
+
this.api_key_authorizer = null;
|
|
1950
|
+
this.daemon_config = null;
|
|
1951
|
+
if (stop_errors.length > 0) {
|
|
1952
|
+
const first_error = stop_errors[0];
|
|
1953
|
+
throw first_error;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
requireDaemonConfig() {
|
|
1957
|
+
if (!this.daemon_config) {
|
|
1958
|
+
throw new Error("Daemon config is not initialized.");
|
|
1959
|
+
}
|
|
1960
|
+
return this.daemon_config;
|
|
1961
|
+
}
|
|
1962
|
+
requireApiKeyAuthorizer() {
|
|
1963
|
+
if (!this.api_key_authorizer) {
|
|
1964
|
+
throw new Error("ApiKeyAuthorizer is not initialized.");
|
|
1965
|
+
}
|
|
1966
|
+
return this.api_key_authorizer;
|
|
1967
|
+
}
|
|
1968
|
+
logWorkerEvent(params) {
|
|
1969
|
+
this.logMessage({
|
|
1970
|
+
severity: params.worker_event.severity,
|
|
1971
|
+
message: `worker_event ${JSON.stringify(params.worker_event)}`
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
logMessage(params) {
|
|
1975
|
+
const output_message = `[${ToIsoTimestamp()}] [${params.severity}] ${params.message}`;
|
|
1976
|
+
if (params.severity === "error") {
|
|
1977
|
+
console.error(output_message);
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1980
|
+
if (params.severity === "warn") {
|
|
1981
|
+
console.warn(output_message);
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
console.log(output_message);
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
__name(_NetworkProcedureCallDaemon, "NetworkProcedureCallDaemon");
|
|
1988
|
+
var NetworkProcedureCallDaemon = _NetworkProcedureCallDaemon;
|
|
1989
|
+
|
|
1990
|
+
// src/classes/daemonprocess/DaemonProcess.class.ts
|
|
1991
|
+
var _DaemonProcess = class _DaemonProcess {
|
|
1992
|
+
constructor(params) {
|
|
1993
|
+
__publicField(this, "daemon");
|
|
1994
|
+
__publicField(this, "is_running", false);
|
|
1995
|
+
__publicField(this, "stop_in_progress", false);
|
|
1996
|
+
__publicField(this, "stop_resolve", null);
|
|
1997
|
+
__publicField(this, "stop_waiter");
|
|
1998
|
+
__publicField(this, "handleSignal", /* @__PURE__ */ __name((signal) => {
|
|
1999
|
+
void this.requestStop({
|
|
2000
|
+
reason: `Received ${signal}.`
|
|
2001
|
+
});
|
|
2002
|
+
}, "handleSignal"));
|
|
2003
|
+
__publicField(this, "handleUncaughtException", /* @__PURE__ */ __name((error) => {
|
|
2004
|
+
console.error(`Uncaught exception: ${error.stack ?? error.message}`);
|
|
2005
|
+
process.exitCode = 1;
|
|
2006
|
+
void this.requestStop({
|
|
2007
|
+
reason: "Stopping daemon after uncaught exception."
|
|
2008
|
+
});
|
|
2009
|
+
}, "handleUncaughtException"));
|
|
2010
|
+
__publicField(this, "handleUnhandledRejection", /* @__PURE__ */ __name((error) => {
|
|
2011
|
+
const error_message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
2012
|
+
console.error(`Unhandled rejection: ${error_message}`);
|
|
2013
|
+
process.exitCode = 1;
|
|
2014
|
+
void this.requestStop({
|
|
2015
|
+
reason: "Stopping daemon after unhandled rejection."
|
|
2016
|
+
});
|
|
2017
|
+
}, "handleUnhandledRejection"));
|
|
2018
|
+
this.daemon = new NetworkProcedureCallDaemon({
|
|
2019
|
+
config_paths: params.config_paths
|
|
2020
|
+
});
|
|
2021
|
+
this.stop_waiter = new Promise((resolve) => {
|
|
2022
|
+
this.stop_resolve = resolve;
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
async run() {
|
|
2026
|
+
if (this.is_running) {
|
|
2027
|
+
throw new Error("DaemonProcess is already running.");
|
|
2028
|
+
}
|
|
2029
|
+
this.is_running = true;
|
|
2030
|
+
this.attachProcessHandlers();
|
|
2031
|
+
try {
|
|
2032
|
+
await this.daemon.start();
|
|
2033
|
+
} catch (error) {
|
|
2034
|
+
this.detachProcessHandlers();
|
|
2035
|
+
this.is_running = false;
|
|
2036
|
+
throw error;
|
|
2037
|
+
}
|
|
2038
|
+
await this.stop_waiter;
|
|
2039
|
+
}
|
|
2040
|
+
attachProcessHandlers() {
|
|
2041
|
+
process.on("SIGINT", this.handleSignal);
|
|
2042
|
+
process.on("SIGTERM", this.handleSignal);
|
|
2043
|
+
process.on("uncaughtException", this.handleUncaughtException);
|
|
2044
|
+
process.on("unhandledRejection", this.handleUnhandledRejection);
|
|
2045
|
+
}
|
|
2046
|
+
detachProcessHandlers() {
|
|
2047
|
+
process.off("SIGINT", this.handleSignal);
|
|
2048
|
+
process.off("SIGTERM", this.handleSignal);
|
|
2049
|
+
process.off("uncaughtException", this.handleUncaughtException);
|
|
2050
|
+
process.off("unhandledRejection", this.handleUnhandledRejection);
|
|
2051
|
+
}
|
|
2052
|
+
async requestStop(params) {
|
|
2053
|
+
if (!this.is_running || this.stop_in_progress) {
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
2056
|
+
this.stop_in_progress = true;
|
|
2057
|
+
console.log(params.reason);
|
|
2058
|
+
try {
|
|
2059
|
+
await this.daemon.stop();
|
|
2060
|
+
} catch (error) {
|
|
2061
|
+
const error_message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
2062
|
+
console.error(`Error while stopping daemon: ${error_message}`);
|
|
2063
|
+
process.exitCode = 1;
|
|
2064
|
+
} finally {
|
|
2065
|
+
this.detachProcessHandlers();
|
|
2066
|
+
this.is_running = false;
|
|
2067
|
+
this.stop_in_progress = false;
|
|
2068
|
+
if (this.stop_resolve) {
|
|
2069
|
+
this.stop_resolve();
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
__name(_DaemonProcess, "DaemonProcess");
|
|
2075
|
+
var DaemonProcess = _DaemonProcess;
|
|
2076
|
+
|
|
2077
|
+
// src/classes/tlsmaterialgenerator/TlsMaterialGenerator.class.ts
|
|
2078
|
+
var import_node_child_process = require("child_process");
|
|
2079
|
+
var import_node_fs2 = __toESM(require("fs"));
|
|
2080
|
+
var import_node_path2 = __toESM(require("path"));
|
|
2081
|
+
function EnsurePositiveInteger(params) {
|
|
2082
|
+
if (!Number.isInteger(params.value) || params.value <= 0) {
|
|
2083
|
+
throw new Error(`${params.label} must be a positive integer.`);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
__name(EnsurePositiveInteger, "EnsurePositiveInteger");
|
|
2087
|
+
function MakeDirRecursive(params) {
|
|
2088
|
+
import_node_fs2.default.mkdirSync(params.dir_path, {
|
|
2089
|
+
recursive: true
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
__name(MakeDirRecursive, "MakeDirRecursive");
|
|
2093
|
+
function WriteTextFile(params) {
|
|
2094
|
+
import_node_fs2.default.writeFileSync(params.file_path, params.content, "utf8");
|
|
2095
|
+
}
|
|
2096
|
+
__name(WriteTextFile, "WriteTextFile");
|
|
2097
|
+
var _TlsMaterialGenerator = class _TlsMaterialGenerator {
|
|
2098
|
+
generateTlsMaterial(params) {
|
|
2099
|
+
const options = params.tls_generation_options;
|
|
2100
|
+
EnsurePositiveInteger({
|
|
2101
|
+
value: options.valid_days,
|
|
2102
|
+
label: "tls_generation.valid_days"
|
|
2103
|
+
});
|
|
2104
|
+
const output_dir = import_node_path2.default.resolve(process.cwd(), options.output_dir);
|
|
2105
|
+
MakeDirRecursive({
|
|
2106
|
+
dir_path: output_dir
|
|
2107
|
+
});
|
|
2108
|
+
this.assertOpenSslAvailable();
|
|
2109
|
+
const tls_files = this.buildTlsFileMap({
|
|
2110
|
+
output_dir
|
|
2111
|
+
});
|
|
2112
|
+
this.assertTargetFilesAreWritable({
|
|
2113
|
+
tls_files,
|
|
2114
|
+
overwrite: options.overwrite
|
|
2115
|
+
});
|
|
2116
|
+
try {
|
|
2117
|
+
this.generateCa({
|
|
2118
|
+
tls_files,
|
|
2119
|
+
valid_days: options.valid_days,
|
|
2120
|
+
ca_common_name: options.ca_common_name
|
|
2121
|
+
});
|
|
2122
|
+
this.generateServerCertificate({
|
|
2123
|
+
tls_files,
|
|
2124
|
+
valid_days: options.valid_days,
|
|
2125
|
+
server_common_name: options.server_common_name
|
|
2126
|
+
});
|
|
2127
|
+
this.generateClientCertificate({
|
|
2128
|
+
tls_files,
|
|
2129
|
+
valid_days: options.valid_days,
|
|
2130
|
+
client_common_name: options.client_common_name
|
|
2131
|
+
});
|
|
2132
|
+
this.cleanupIntermediateFiles({
|
|
2133
|
+
tls_files
|
|
2134
|
+
});
|
|
2135
|
+
} catch (error) {
|
|
2136
|
+
throw new Error(`Failed to generate TLS material in "${output_dir}": ${this.getErrorMessage({
|
|
2137
|
+
error
|
|
2138
|
+
})}`);
|
|
2139
|
+
}
|
|
2140
|
+
return {
|
|
2141
|
+
output_dir,
|
|
2142
|
+
ca_key_path: tls_files.ca_key_path,
|
|
2143
|
+
ca_cert_path: tls_files.ca_cert_path,
|
|
2144
|
+
server_key_path: tls_files.server_key_path,
|
|
2145
|
+
server_cert_path: tls_files.server_cert_path,
|
|
2146
|
+
client_key_path: tls_files.client_key_path,
|
|
2147
|
+
client_cert_path: tls_files.client_cert_path
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
assertOpenSslAvailable() {
|
|
2151
|
+
try {
|
|
2152
|
+
(0, import_node_child_process.execFileSync)("openssl", [
|
|
2153
|
+
"version"
|
|
2154
|
+
], {
|
|
2155
|
+
stdio: "ignore"
|
|
2156
|
+
});
|
|
2157
|
+
} catch {
|
|
2158
|
+
throw new Error("openssl command is required but was not found. Please install openssl and retry.");
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
buildTlsFileMap(params) {
|
|
2162
|
+
return {
|
|
2163
|
+
ca_key_path: import_node_path2.default.join(params.output_dir, "ca.key.pem"),
|
|
2164
|
+
ca_cert_path: import_node_path2.default.join(params.output_dir, "ca.cert.pem"),
|
|
2165
|
+
server_key_path: import_node_path2.default.join(params.output_dir, "server.key.pem"),
|
|
2166
|
+
server_csr_path: import_node_path2.default.join(params.output_dir, "server.csr.pem"),
|
|
2167
|
+
server_cert_path: import_node_path2.default.join(params.output_dir, "server.cert.pem"),
|
|
2168
|
+
server_ext_path: import_node_path2.default.join(params.output_dir, "server.ext"),
|
|
2169
|
+
client_key_path: import_node_path2.default.join(params.output_dir, "client.key.pem"),
|
|
2170
|
+
client_csr_path: import_node_path2.default.join(params.output_dir, "client.csr.pem"),
|
|
2171
|
+
client_cert_path: import_node_path2.default.join(params.output_dir, "client.cert.pem"),
|
|
2172
|
+
client_ext_path: import_node_path2.default.join(params.output_dir, "client.ext"),
|
|
2173
|
+
ca_serial_path: import_node_path2.default.join(params.output_dir, "ca.cert.srl")
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
assertTargetFilesAreWritable(params) {
|
|
2177
|
+
const target_paths = [
|
|
2178
|
+
params.tls_files.ca_key_path,
|
|
2179
|
+
params.tls_files.ca_cert_path,
|
|
2180
|
+
params.tls_files.server_key_path,
|
|
2181
|
+
params.tls_files.server_cert_path,
|
|
2182
|
+
params.tls_files.client_key_path,
|
|
2183
|
+
params.tls_files.client_cert_path
|
|
2184
|
+
];
|
|
2185
|
+
if (!params.overwrite) {
|
|
2186
|
+
for (const target_path of target_paths) {
|
|
2187
|
+
if (import_node_fs2.default.existsSync(target_path)) {
|
|
2188
|
+
throw new Error(`Refusing to overwrite existing file "${target_path}". Use --tls-overwrite to replace existing material.`);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return;
|
|
2192
|
+
}
|
|
2193
|
+
for (const target_path of target_paths) {
|
|
2194
|
+
import_node_fs2.default.rmSync(target_path, {
|
|
2195
|
+
force: true
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
import_node_fs2.default.rmSync(params.tls_files.ca_serial_path, {
|
|
2199
|
+
force: true
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
generateCa(params) {
|
|
2203
|
+
this.runOpenSslCommand({
|
|
2204
|
+
args: [
|
|
2205
|
+
"req",
|
|
2206
|
+
"-x509",
|
|
2207
|
+
"-newkey",
|
|
2208
|
+
"rsa:4096",
|
|
2209
|
+
"-sha256",
|
|
2210
|
+
"-nodes",
|
|
2211
|
+
"-keyout",
|
|
2212
|
+
params.tls_files.ca_key_path,
|
|
2213
|
+
"-out",
|
|
2214
|
+
params.tls_files.ca_cert_path,
|
|
2215
|
+
"-days",
|
|
2216
|
+
String(params.valid_days),
|
|
2217
|
+
"-subj",
|
|
2218
|
+
`/CN=${params.ca_common_name}`
|
|
2219
|
+
]
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
generateServerCertificate(params) {
|
|
2223
|
+
WriteTextFile({
|
|
2224
|
+
file_path: params.tls_files.server_ext_path,
|
|
2225
|
+
content: [
|
|
2226
|
+
"subjectAltName=DNS:localhost,IP:127.0.0.1",
|
|
2227
|
+
"extendedKeyUsage=serverAuth",
|
|
2228
|
+
"keyUsage=digitalSignature,keyEncipherment"
|
|
2229
|
+
].join("\n")
|
|
2230
|
+
});
|
|
2231
|
+
this.runOpenSslCommand({
|
|
2232
|
+
args: [
|
|
2233
|
+
"req",
|
|
2234
|
+
"-new",
|
|
2235
|
+
"-newkey",
|
|
2236
|
+
"rsa:4096",
|
|
2237
|
+
"-sha256",
|
|
2238
|
+
"-nodes",
|
|
2239
|
+
"-keyout",
|
|
2240
|
+
params.tls_files.server_key_path,
|
|
2241
|
+
"-out",
|
|
2242
|
+
params.tls_files.server_csr_path,
|
|
2243
|
+
"-subj",
|
|
2244
|
+
`/CN=${params.server_common_name}`
|
|
2245
|
+
]
|
|
2246
|
+
});
|
|
2247
|
+
this.runOpenSslCommand({
|
|
2248
|
+
args: [
|
|
2249
|
+
"x509",
|
|
2250
|
+
"-req",
|
|
2251
|
+
"-in",
|
|
2252
|
+
params.tls_files.server_csr_path,
|
|
2253
|
+
"-CA",
|
|
2254
|
+
params.tls_files.ca_cert_path,
|
|
2255
|
+
"-CAkey",
|
|
2256
|
+
params.tls_files.ca_key_path,
|
|
2257
|
+
"-CAserial",
|
|
2258
|
+
params.tls_files.ca_serial_path,
|
|
2259
|
+
"-CAcreateserial",
|
|
2260
|
+
"-out",
|
|
2261
|
+
params.tls_files.server_cert_path,
|
|
2262
|
+
"-days",
|
|
2263
|
+
String(params.valid_days),
|
|
2264
|
+
"-sha256",
|
|
2265
|
+
"-extfile",
|
|
2266
|
+
params.tls_files.server_ext_path
|
|
2267
|
+
]
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
generateClientCertificate(params) {
|
|
2271
|
+
const client_uri = `spiffe://nodenetproccalld/${params.client_common_name.replace(/[^a-zA-Z0-9_.-]/g, "_").toLowerCase()}`;
|
|
2272
|
+
WriteTextFile({
|
|
2273
|
+
file_path: params.tls_files.client_ext_path,
|
|
2274
|
+
content: [
|
|
2275
|
+
"extendedKeyUsage=clientAuth",
|
|
2276
|
+
"keyUsage=digitalSignature,keyEncipherment",
|
|
2277
|
+
`subjectAltName=URI:${client_uri}`
|
|
2278
|
+
].join("\n")
|
|
2279
|
+
});
|
|
2280
|
+
this.runOpenSslCommand({
|
|
2281
|
+
args: [
|
|
2282
|
+
"req",
|
|
2283
|
+
"-new",
|
|
2284
|
+
"-newkey",
|
|
2285
|
+
"rsa:4096",
|
|
2286
|
+
"-sha256",
|
|
2287
|
+
"-nodes",
|
|
2288
|
+
"-keyout",
|
|
2289
|
+
params.tls_files.client_key_path,
|
|
2290
|
+
"-out",
|
|
2291
|
+
params.tls_files.client_csr_path,
|
|
2292
|
+
"-subj",
|
|
2293
|
+
`/CN=${params.client_common_name}`
|
|
2294
|
+
]
|
|
2295
|
+
});
|
|
2296
|
+
this.runOpenSslCommand({
|
|
2297
|
+
args: [
|
|
2298
|
+
"x509",
|
|
2299
|
+
"-req",
|
|
2300
|
+
"-in",
|
|
2301
|
+
params.tls_files.client_csr_path,
|
|
2302
|
+
"-CA",
|
|
2303
|
+
params.tls_files.ca_cert_path,
|
|
2304
|
+
"-CAkey",
|
|
2305
|
+
params.tls_files.ca_key_path,
|
|
2306
|
+
"-CAserial",
|
|
2307
|
+
params.tls_files.ca_serial_path,
|
|
2308
|
+
"-out",
|
|
2309
|
+
params.tls_files.client_cert_path,
|
|
2310
|
+
"-days",
|
|
2311
|
+
String(params.valid_days),
|
|
2312
|
+
"-sha256",
|
|
2313
|
+
"-extfile",
|
|
2314
|
+
params.tls_files.client_ext_path
|
|
2315
|
+
]
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
cleanupIntermediateFiles(params) {
|
|
2319
|
+
import_node_fs2.default.rmSync(params.tls_files.server_csr_path, {
|
|
2320
|
+
force: true
|
|
2321
|
+
});
|
|
2322
|
+
import_node_fs2.default.rmSync(params.tls_files.client_csr_path, {
|
|
2323
|
+
force: true
|
|
2324
|
+
});
|
|
2325
|
+
import_node_fs2.default.rmSync(params.tls_files.server_ext_path, {
|
|
2326
|
+
force: true
|
|
2327
|
+
});
|
|
2328
|
+
import_node_fs2.default.rmSync(params.tls_files.client_ext_path, {
|
|
2329
|
+
force: true
|
|
2330
|
+
});
|
|
2331
|
+
import_node_fs2.default.rmSync(params.tls_files.ca_serial_path, {
|
|
2332
|
+
force: true
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
runOpenSslCommand(params) {
|
|
2336
|
+
(0, import_node_child_process.execFileSync)("openssl", params.args, {
|
|
2337
|
+
stdio: "ignore"
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
getErrorMessage(params) {
|
|
2341
|
+
if (params.error instanceof Error) {
|
|
2342
|
+
return params.error.message;
|
|
2343
|
+
}
|
|
2344
|
+
return String(params.error);
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
__name(_TlsMaterialGenerator, "TlsMaterialGenerator");
|
|
2348
|
+
var TlsMaterialGenerator = _TlsMaterialGenerator;
|
|
2349
|
+
|
|
2350
|
+
// src/index.ts
|
|
2351
|
+
async function StartDaemonFromCli() {
|
|
2352
|
+
const daemon_cli = new DaemonCli();
|
|
2353
|
+
const cli_options = daemon_cli.parseOptions();
|
|
2354
|
+
if (cli_options.help) {
|
|
2355
|
+
daemon_cli.printHelp();
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
if (cli_options.tls_generation.enabled) {
|
|
2359
|
+
const tls_material_generator = new TlsMaterialGenerator();
|
|
2360
|
+
const generated_tls_material = tls_material_generator.generateTlsMaterial({
|
|
2361
|
+
tls_generation_options: cli_options.tls_generation
|
|
2362
|
+
});
|
|
2363
|
+
console.log("TLS material generated successfully.");
|
|
2364
|
+
console.log(`Output directory: ${generated_tls_material.output_dir}`);
|
|
2365
|
+
console.log(`CA cert: ${generated_tls_material.ca_cert_path}`);
|
|
2366
|
+
console.log(`Server cert: ${generated_tls_material.server_cert_path}`);
|
|
2367
|
+
console.log(`Server key: ${generated_tls_material.server_key_path}`);
|
|
2368
|
+
console.log(`Client cert: ${generated_tls_material.client_cert_path}`);
|
|
2369
|
+
console.log(`Client key: ${generated_tls_material.client_key_path}`);
|
|
2370
|
+
console.log("");
|
|
2371
|
+
console.log("If using default config, set tls_mtls key_file/cert_file/ca_file in config/server.config.json5 to these files.");
|
|
2372
|
+
return;
|
|
2373
|
+
}
|
|
2374
|
+
const daemon_process = new DaemonProcess({
|
|
2375
|
+
config_paths: {
|
|
2376
|
+
server_config_path: cli_options.server_config_path,
|
|
2377
|
+
api_keys_config_path: cli_options.api_keys_config_path
|
|
2378
|
+
}
|
|
2379
|
+
});
|
|
2380
|
+
await daemon_process.run();
|
|
2381
|
+
}
|
|
2382
|
+
__name(StartDaemonFromCli, "StartDaemonFromCli");
|
|
2383
|
+
if (require.main === module) {
|
|
2384
|
+
void StartDaemonFromCli().catch((error) => {
|
|
2385
|
+
const error_message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
2386
|
+
console.error(`Daemon startup failed: ${error_message}`);
|
|
2387
|
+
process.exitCode = 1;
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2391
|
+
0 && (module.exports = {
|
|
2392
|
+
ApiKeyAuthorizer,
|
|
2393
|
+
ConfigFileLoader,
|
|
2394
|
+
ConfigValidator,
|
|
2395
|
+
DaemonCli,
|
|
2396
|
+
DaemonProcess,
|
|
2397
|
+
NetworkProcedureCallDaemon,
|
|
2398
|
+
TlsMaterialGenerator
|
|
2399
|
+
});
|
|
2400
|
+
//# sourceMappingURL=index.js.map
|