@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/dist/index.mjs ADDED
@@ -0,0 +1,2365 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
6
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
7
+ }) : x)(function(x) {
8
+ if (typeof require !== "undefined") return require.apply(this, arguments);
9
+ throw Error('Dynamic require of "' + x + '" is not supported');
10
+ });
11
+ var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
12
+
13
+ // src/classes/apikeyauthorizer/ApiKeyAuthorizer.class.ts
14
+ import crypto from "crypto";
15
+ function SafeTimingEqual(params) {
16
+ const left_buffer = Buffer.from(params.left_value, "utf8");
17
+ const right_buffer = Buffer.from(params.right_value, "utf8");
18
+ if (left_buffer.length !== right_buffer.length) {
19
+ const left_digest = crypto.createHash("sha256").update(left_buffer).digest();
20
+ const right_digest = crypto.createHash("sha256").update(right_buffer).digest();
21
+ crypto.timingSafeEqual(left_digest, right_digest);
22
+ return false;
23
+ }
24
+ return crypto.timingSafeEqual(left_buffer, right_buffer);
25
+ }
26
+ __name(SafeTimingEqual, "SafeTimingEqual");
27
+ var _ApiKeyAuthorizer = class _ApiKeyAuthorizer {
28
+ constructor(params) {
29
+ __publicField(this, "api_key_entries");
30
+ this.api_key_entries = [
31
+ ...params.api_key_entries
32
+ ];
33
+ }
34
+ async authenticate(params) {
35
+ for (const api_key_entry of this.api_key_entries) {
36
+ if (!api_key_entry.enabled) {
37
+ continue;
38
+ }
39
+ if (!SafeTimingEqual({
40
+ left_value: api_key_entry.api_key,
41
+ right_value: params.auth_callback_params.api_key
42
+ })) {
43
+ continue;
44
+ }
45
+ if (!this.matchesIdentityConstraints({
46
+ api_key_entry,
47
+ auth_callback_params: params.auth_callback_params
48
+ })) {
49
+ continue;
50
+ }
51
+ return {
52
+ state: "authenticated",
53
+ privileges: [
54
+ ...api_key_entry.privileges
55
+ ]
56
+ };
57
+ }
58
+ return "failed";
59
+ }
60
+ matchesIdentityConstraints(params) {
61
+ const constraints = params.api_key_entry.identity_constraints;
62
+ if (!constraints) {
63
+ return true;
64
+ }
65
+ if (constraints.remote_address_regex && !constraints.remote_address_regex.test(params.auth_callback_params.remote_address)) {
66
+ return false;
67
+ }
68
+ if (constraints.tls_peer_subject_regex && !this.matchOptionalValue({
69
+ regex: constraints.tls_peer_subject_regex,
70
+ value: params.auth_callback_params.tls_peer_subject
71
+ })) {
72
+ return false;
73
+ }
74
+ if (constraints.tls_peer_san_regex && !this.matchOptionalValue({
75
+ regex: constraints.tls_peer_san_regex,
76
+ value: params.auth_callback_params.tls_peer_san
77
+ })) {
78
+ return false;
79
+ }
80
+ if (constraints.tls_peer_fingerprint256_regex && !this.matchOptionalValue({
81
+ regex: constraints.tls_peer_fingerprint256_regex,
82
+ value: params.auth_callback_params.tls_peer_fingerprint256
83
+ })) {
84
+ return false;
85
+ }
86
+ if (constraints.tls_peer_serial_number_regex && !this.matchOptionalValue({
87
+ regex: constraints.tls_peer_serial_number_regex,
88
+ value: params.auth_callback_params.tls_peer_serial_number
89
+ })) {
90
+ return false;
91
+ }
92
+ return true;
93
+ }
94
+ matchOptionalValue(params) {
95
+ if (!params.value) {
96
+ return false;
97
+ }
98
+ return params.regex.test(params.value);
99
+ }
100
+ };
101
+ __name(_ApiKeyAuthorizer, "ApiKeyAuthorizer");
102
+ var ApiKeyAuthorizer = _ApiKeyAuthorizer;
103
+
104
+ // src/classes/configfileloader/ConfigFileLoader.class.ts
105
+ import fs from "fs";
106
+ import path from "path";
107
+
108
+ // node_modules/json5/dist/index.mjs
109
+ var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
110
+ 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]/;
111
+ 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]/;
112
+ var unicode = {
113
+ Space_Separator,
114
+ ID_Start,
115
+ ID_Continue
116
+ };
117
+ var util = {
118
+ isSpaceSeparator(c2) {
119
+ return typeof c2 === "string" && unicode.Space_Separator.test(c2);
120
+ },
121
+ isIdStartChar(c2) {
122
+ return typeof c2 === "string" && (c2 >= "a" && c2 <= "z" || c2 >= "A" && c2 <= "Z" || c2 === "$" || c2 === "_" || unicode.ID_Start.test(c2));
123
+ },
124
+ isIdContinueChar(c2) {
125
+ 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));
126
+ },
127
+ isDigit(c2) {
128
+ return typeof c2 === "string" && /[0-9]/.test(c2);
129
+ },
130
+ isHexDigit(c2) {
131
+ return typeof c2 === "string" && /[0-9A-Fa-f]/.test(c2);
132
+ }
133
+ };
134
+ var source;
135
+ var parseState;
136
+ var stack;
137
+ var pos;
138
+ var line;
139
+ var column;
140
+ var token;
141
+ var key;
142
+ var root;
143
+ var parse = /* @__PURE__ */ __name(function parse2(text, reviver) {
144
+ source = String(text);
145
+ parseState = "start";
146
+ stack = [];
147
+ pos = 0;
148
+ line = 1;
149
+ column = 0;
150
+ token = void 0;
151
+ key = void 0;
152
+ root = void 0;
153
+ do {
154
+ token = lex();
155
+ parseStates[parseState]();
156
+ } while (token.type !== "eof");
157
+ if (typeof reviver === "function") {
158
+ return internalize({ "": root }, "", reviver);
159
+ }
160
+ return root;
161
+ }, "parse");
162
+ function internalize(holder, name, reviver) {
163
+ const value = holder[name];
164
+ if (value != null && typeof value === "object") {
165
+ if (Array.isArray(value)) {
166
+ for (let i = 0; i < value.length; i++) {
167
+ const key2 = String(i);
168
+ const replacement = internalize(value, key2, reviver);
169
+ if (replacement === void 0) {
170
+ delete value[key2];
171
+ } else {
172
+ Object.defineProperty(value, key2, {
173
+ value: replacement,
174
+ writable: true,
175
+ enumerable: true,
176
+ configurable: true
177
+ });
178
+ }
179
+ }
180
+ } else {
181
+ for (const key2 in value) {
182
+ const replacement = internalize(value, key2, reviver);
183
+ if (replacement === void 0) {
184
+ delete value[key2];
185
+ } else {
186
+ Object.defineProperty(value, key2, {
187
+ value: replacement,
188
+ writable: true,
189
+ enumerable: true,
190
+ configurable: true
191
+ });
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return reviver.call(holder, name, value);
197
+ }
198
+ __name(internalize, "internalize");
199
+ var lexState;
200
+ var buffer;
201
+ var doubleQuote;
202
+ var sign;
203
+ var c;
204
+ function lex() {
205
+ lexState = "default";
206
+ buffer = "";
207
+ doubleQuote = false;
208
+ sign = 1;
209
+ for (; ; ) {
210
+ c = peek();
211
+ const token2 = lexStates[lexState]();
212
+ if (token2) {
213
+ return token2;
214
+ }
215
+ }
216
+ }
217
+ __name(lex, "lex");
218
+ function peek() {
219
+ if (source[pos]) {
220
+ return String.fromCodePoint(source.codePointAt(pos));
221
+ }
222
+ }
223
+ __name(peek, "peek");
224
+ function read() {
225
+ const c2 = peek();
226
+ if (c2 === "\n") {
227
+ line++;
228
+ column = 0;
229
+ } else if (c2) {
230
+ column += c2.length;
231
+ } else {
232
+ column++;
233
+ }
234
+ if (c2) {
235
+ pos += c2.length;
236
+ }
237
+ return c2;
238
+ }
239
+ __name(read, "read");
240
+ var lexStates = {
241
+ default() {
242
+ switch (c) {
243
+ case " ":
244
+ case "\v":
245
+ case "\f":
246
+ case " ":
247
+ case "\xA0":
248
+ case "\uFEFF":
249
+ case "\n":
250
+ case "\r":
251
+ case "\u2028":
252
+ case "\u2029":
253
+ read();
254
+ return;
255
+ case "/":
256
+ read();
257
+ lexState = "comment";
258
+ return;
259
+ case void 0:
260
+ read();
261
+ return newToken("eof");
262
+ }
263
+ if (util.isSpaceSeparator(c)) {
264
+ read();
265
+ return;
266
+ }
267
+ return lexStates[parseState]();
268
+ },
269
+ comment() {
270
+ switch (c) {
271
+ case "*":
272
+ read();
273
+ lexState = "multiLineComment";
274
+ return;
275
+ case "/":
276
+ read();
277
+ lexState = "singleLineComment";
278
+ return;
279
+ }
280
+ throw invalidChar(read());
281
+ },
282
+ multiLineComment() {
283
+ switch (c) {
284
+ case "*":
285
+ read();
286
+ lexState = "multiLineCommentAsterisk";
287
+ return;
288
+ case void 0:
289
+ throw invalidChar(read());
290
+ }
291
+ read();
292
+ },
293
+ multiLineCommentAsterisk() {
294
+ switch (c) {
295
+ case "*":
296
+ read();
297
+ return;
298
+ case "/":
299
+ read();
300
+ lexState = "default";
301
+ return;
302
+ case void 0:
303
+ throw invalidChar(read());
304
+ }
305
+ read();
306
+ lexState = "multiLineComment";
307
+ },
308
+ singleLineComment() {
309
+ switch (c) {
310
+ case "\n":
311
+ case "\r":
312
+ case "\u2028":
313
+ case "\u2029":
314
+ read();
315
+ lexState = "default";
316
+ return;
317
+ case void 0:
318
+ read();
319
+ return newToken("eof");
320
+ }
321
+ read();
322
+ },
323
+ value() {
324
+ switch (c) {
325
+ case "{":
326
+ case "[":
327
+ return newToken("punctuator", read());
328
+ case "n":
329
+ read();
330
+ literal("ull");
331
+ return newToken("null", null);
332
+ case "t":
333
+ read();
334
+ literal("rue");
335
+ return newToken("boolean", true);
336
+ case "f":
337
+ read();
338
+ literal("alse");
339
+ return newToken("boolean", false);
340
+ case "-":
341
+ case "+":
342
+ if (read() === "-") {
343
+ sign = -1;
344
+ }
345
+ lexState = "sign";
346
+ return;
347
+ case ".":
348
+ buffer = read();
349
+ lexState = "decimalPointLeading";
350
+ return;
351
+ case "0":
352
+ buffer = read();
353
+ lexState = "zero";
354
+ return;
355
+ case "1":
356
+ case "2":
357
+ case "3":
358
+ case "4":
359
+ case "5":
360
+ case "6":
361
+ case "7":
362
+ case "8":
363
+ case "9":
364
+ buffer = read();
365
+ lexState = "decimalInteger";
366
+ return;
367
+ case "I":
368
+ read();
369
+ literal("nfinity");
370
+ return newToken("numeric", Infinity);
371
+ case "N":
372
+ read();
373
+ literal("aN");
374
+ return newToken("numeric", NaN);
375
+ case '"':
376
+ case "'":
377
+ doubleQuote = read() === '"';
378
+ buffer = "";
379
+ lexState = "string";
380
+ return;
381
+ }
382
+ throw invalidChar(read());
383
+ },
384
+ identifierNameStartEscape() {
385
+ if (c !== "u") {
386
+ throw invalidChar(read());
387
+ }
388
+ read();
389
+ const u = unicodeEscape();
390
+ switch (u) {
391
+ case "$":
392
+ case "_":
393
+ break;
394
+ default:
395
+ if (!util.isIdStartChar(u)) {
396
+ throw invalidIdentifier();
397
+ }
398
+ break;
399
+ }
400
+ buffer += u;
401
+ lexState = "identifierName";
402
+ },
403
+ identifierName() {
404
+ switch (c) {
405
+ case "$":
406
+ case "_":
407
+ case "\u200C":
408
+ case "\u200D":
409
+ buffer += read();
410
+ return;
411
+ case "\\":
412
+ read();
413
+ lexState = "identifierNameEscape";
414
+ return;
415
+ }
416
+ if (util.isIdContinueChar(c)) {
417
+ buffer += read();
418
+ return;
419
+ }
420
+ return newToken("identifier", buffer);
421
+ },
422
+ identifierNameEscape() {
423
+ if (c !== "u") {
424
+ throw invalidChar(read());
425
+ }
426
+ read();
427
+ const u = unicodeEscape();
428
+ switch (u) {
429
+ case "$":
430
+ case "_":
431
+ case "\u200C":
432
+ case "\u200D":
433
+ break;
434
+ default:
435
+ if (!util.isIdContinueChar(u)) {
436
+ throw invalidIdentifier();
437
+ }
438
+ break;
439
+ }
440
+ buffer += u;
441
+ lexState = "identifierName";
442
+ },
443
+ sign() {
444
+ switch (c) {
445
+ case ".":
446
+ buffer = read();
447
+ lexState = "decimalPointLeading";
448
+ return;
449
+ case "0":
450
+ buffer = read();
451
+ lexState = "zero";
452
+ return;
453
+ case "1":
454
+ case "2":
455
+ case "3":
456
+ case "4":
457
+ case "5":
458
+ case "6":
459
+ case "7":
460
+ case "8":
461
+ case "9":
462
+ buffer = read();
463
+ lexState = "decimalInteger";
464
+ return;
465
+ case "I":
466
+ read();
467
+ literal("nfinity");
468
+ return newToken("numeric", sign * Infinity);
469
+ case "N":
470
+ read();
471
+ literal("aN");
472
+ return newToken("numeric", NaN);
473
+ }
474
+ throw invalidChar(read());
475
+ },
476
+ zero() {
477
+ switch (c) {
478
+ case ".":
479
+ buffer += read();
480
+ lexState = "decimalPoint";
481
+ return;
482
+ case "e":
483
+ case "E":
484
+ buffer += read();
485
+ lexState = "decimalExponent";
486
+ return;
487
+ case "x":
488
+ case "X":
489
+ buffer += read();
490
+ lexState = "hexadecimal";
491
+ return;
492
+ }
493
+ return newToken("numeric", sign * 0);
494
+ },
495
+ decimalInteger() {
496
+ switch (c) {
497
+ case ".":
498
+ buffer += read();
499
+ lexState = "decimalPoint";
500
+ return;
501
+ case "e":
502
+ case "E":
503
+ buffer += read();
504
+ lexState = "decimalExponent";
505
+ return;
506
+ }
507
+ if (util.isDigit(c)) {
508
+ buffer += read();
509
+ return;
510
+ }
511
+ return newToken("numeric", sign * Number(buffer));
512
+ },
513
+ decimalPointLeading() {
514
+ if (util.isDigit(c)) {
515
+ buffer += read();
516
+ lexState = "decimalFraction";
517
+ return;
518
+ }
519
+ throw invalidChar(read());
520
+ },
521
+ decimalPoint() {
522
+ switch (c) {
523
+ case "e":
524
+ case "E":
525
+ buffer += read();
526
+ lexState = "decimalExponent";
527
+ return;
528
+ }
529
+ if (util.isDigit(c)) {
530
+ buffer += read();
531
+ lexState = "decimalFraction";
532
+ return;
533
+ }
534
+ return newToken("numeric", sign * Number(buffer));
535
+ },
536
+ decimalFraction() {
537
+ switch (c) {
538
+ case "e":
539
+ case "E":
540
+ buffer += read();
541
+ lexState = "decimalExponent";
542
+ return;
543
+ }
544
+ if (util.isDigit(c)) {
545
+ buffer += read();
546
+ return;
547
+ }
548
+ return newToken("numeric", sign * Number(buffer));
549
+ },
550
+ decimalExponent() {
551
+ switch (c) {
552
+ case "+":
553
+ case "-":
554
+ buffer += read();
555
+ lexState = "decimalExponentSign";
556
+ return;
557
+ }
558
+ if (util.isDigit(c)) {
559
+ buffer += read();
560
+ lexState = "decimalExponentInteger";
561
+ return;
562
+ }
563
+ throw invalidChar(read());
564
+ },
565
+ decimalExponentSign() {
566
+ if (util.isDigit(c)) {
567
+ buffer += read();
568
+ lexState = "decimalExponentInteger";
569
+ return;
570
+ }
571
+ throw invalidChar(read());
572
+ },
573
+ decimalExponentInteger() {
574
+ if (util.isDigit(c)) {
575
+ buffer += read();
576
+ return;
577
+ }
578
+ return newToken("numeric", sign * Number(buffer));
579
+ },
580
+ hexadecimal() {
581
+ if (util.isHexDigit(c)) {
582
+ buffer += read();
583
+ lexState = "hexadecimalInteger";
584
+ return;
585
+ }
586
+ throw invalidChar(read());
587
+ },
588
+ hexadecimalInteger() {
589
+ if (util.isHexDigit(c)) {
590
+ buffer += read();
591
+ return;
592
+ }
593
+ return newToken("numeric", sign * Number(buffer));
594
+ },
595
+ string() {
596
+ switch (c) {
597
+ case "\\":
598
+ read();
599
+ buffer += escape();
600
+ return;
601
+ case '"':
602
+ if (doubleQuote) {
603
+ read();
604
+ return newToken("string", buffer);
605
+ }
606
+ buffer += read();
607
+ return;
608
+ case "'":
609
+ if (!doubleQuote) {
610
+ read();
611
+ return newToken("string", buffer);
612
+ }
613
+ buffer += read();
614
+ return;
615
+ case "\n":
616
+ case "\r":
617
+ throw invalidChar(read());
618
+ case "\u2028":
619
+ case "\u2029":
620
+ separatorChar(c);
621
+ break;
622
+ case void 0:
623
+ throw invalidChar(read());
624
+ }
625
+ buffer += read();
626
+ },
627
+ start() {
628
+ switch (c) {
629
+ case "{":
630
+ case "[":
631
+ return newToken("punctuator", read());
632
+ }
633
+ lexState = "value";
634
+ },
635
+ beforePropertyName() {
636
+ switch (c) {
637
+ case "$":
638
+ case "_":
639
+ buffer = read();
640
+ lexState = "identifierName";
641
+ return;
642
+ case "\\":
643
+ read();
644
+ lexState = "identifierNameStartEscape";
645
+ return;
646
+ case "}":
647
+ return newToken("punctuator", read());
648
+ case '"':
649
+ case "'":
650
+ doubleQuote = read() === '"';
651
+ lexState = "string";
652
+ return;
653
+ }
654
+ if (util.isIdStartChar(c)) {
655
+ buffer += read();
656
+ lexState = "identifierName";
657
+ return;
658
+ }
659
+ throw invalidChar(read());
660
+ },
661
+ afterPropertyName() {
662
+ if (c === ":") {
663
+ return newToken("punctuator", read());
664
+ }
665
+ throw invalidChar(read());
666
+ },
667
+ beforePropertyValue() {
668
+ lexState = "value";
669
+ },
670
+ afterPropertyValue() {
671
+ switch (c) {
672
+ case ",":
673
+ case "}":
674
+ return newToken("punctuator", read());
675
+ }
676
+ throw invalidChar(read());
677
+ },
678
+ beforeArrayValue() {
679
+ if (c === "]") {
680
+ return newToken("punctuator", read());
681
+ }
682
+ lexState = "value";
683
+ },
684
+ afterArrayValue() {
685
+ switch (c) {
686
+ case ",":
687
+ case "]":
688
+ return newToken("punctuator", read());
689
+ }
690
+ throw invalidChar(read());
691
+ },
692
+ end() {
693
+ throw invalidChar(read());
694
+ }
695
+ };
696
+ function newToken(type, value) {
697
+ return {
698
+ type,
699
+ value,
700
+ line,
701
+ column
702
+ };
703
+ }
704
+ __name(newToken, "newToken");
705
+ function literal(s) {
706
+ for (const c2 of s) {
707
+ const p = peek();
708
+ if (p !== c2) {
709
+ throw invalidChar(read());
710
+ }
711
+ read();
712
+ }
713
+ }
714
+ __name(literal, "literal");
715
+ function escape() {
716
+ const c2 = peek();
717
+ switch (c2) {
718
+ case "b":
719
+ read();
720
+ return "\b";
721
+ case "f":
722
+ read();
723
+ return "\f";
724
+ case "n":
725
+ read();
726
+ return "\n";
727
+ case "r":
728
+ read();
729
+ return "\r";
730
+ case "t":
731
+ read();
732
+ return " ";
733
+ case "v":
734
+ read();
735
+ return "\v";
736
+ case "0":
737
+ read();
738
+ if (util.isDigit(peek())) {
739
+ throw invalidChar(read());
740
+ }
741
+ return "\0";
742
+ case "x":
743
+ read();
744
+ return hexEscape();
745
+ case "u":
746
+ read();
747
+ return unicodeEscape();
748
+ case "\n":
749
+ case "\u2028":
750
+ case "\u2029":
751
+ read();
752
+ return "";
753
+ case "\r":
754
+ read();
755
+ if (peek() === "\n") {
756
+ read();
757
+ }
758
+ return "";
759
+ case "1":
760
+ case "2":
761
+ case "3":
762
+ case "4":
763
+ case "5":
764
+ case "6":
765
+ case "7":
766
+ case "8":
767
+ case "9":
768
+ throw invalidChar(read());
769
+ case void 0:
770
+ throw invalidChar(read());
771
+ }
772
+ return read();
773
+ }
774
+ __name(escape, "escape");
775
+ function hexEscape() {
776
+ let buffer2 = "";
777
+ let c2 = peek();
778
+ if (!util.isHexDigit(c2)) {
779
+ throw invalidChar(read());
780
+ }
781
+ buffer2 += read();
782
+ c2 = peek();
783
+ if (!util.isHexDigit(c2)) {
784
+ throw invalidChar(read());
785
+ }
786
+ buffer2 += read();
787
+ return String.fromCodePoint(parseInt(buffer2, 16));
788
+ }
789
+ __name(hexEscape, "hexEscape");
790
+ function unicodeEscape() {
791
+ let buffer2 = "";
792
+ let count = 4;
793
+ while (count-- > 0) {
794
+ const c2 = peek();
795
+ if (!util.isHexDigit(c2)) {
796
+ throw invalidChar(read());
797
+ }
798
+ buffer2 += read();
799
+ }
800
+ return String.fromCodePoint(parseInt(buffer2, 16));
801
+ }
802
+ __name(unicodeEscape, "unicodeEscape");
803
+ var parseStates = {
804
+ start() {
805
+ if (token.type === "eof") {
806
+ throw invalidEOF();
807
+ }
808
+ push();
809
+ },
810
+ beforePropertyName() {
811
+ switch (token.type) {
812
+ case "identifier":
813
+ case "string":
814
+ key = token.value;
815
+ parseState = "afterPropertyName";
816
+ return;
817
+ case "punctuator":
818
+ pop();
819
+ return;
820
+ case "eof":
821
+ throw invalidEOF();
822
+ }
823
+ },
824
+ afterPropertyName() {
825
+ if (token.type === "eof") {
826
+ throw invalidEOF();
827
+ }
828
+ parseState = "beforePropertyValue";
829
+ },
830
+ beforePropertyValue() {
831
+ if (token.type === "eof") {
832
+ throw invalidEOF();
833
+ }
834
+ push();
835
+ },
836
+ beforeArrayValue() {
837
+ if (token.type === "eof") {
838
+ throw invalidEOF();
839
+ }
840
+ if (token.type === "punctuator" && token.value === "]") {
841
+ pop();
842
+ return;
843
+ }
844
+ push();
845
+ },
846
+ afterPropertyValue() {
847
+ if (token.type === "eof") {
848
+ throw invalidEOF();
849
+ }
850
+ switch (token.value) {
851
+ case ",":
852
+ parseState = "beforePropertyName";
853
+ return;
854
+ case "}":
855
+ pop();
856
+ }
857
+ },
858
+ afterArrayValue() {
859
+ if (token.type === "eof") {
860
+ throw invalidEOF();
861
+ }
862
+ switch (token.value) {
863
+ case ",":
864
+ parseState = "beforeArrayValue";
865
+ return;
866
+ case "]":
867
+ pop();
868
+ }
869
+ },
870
+ end() {
871
+ }
872
+ };
873
+ function push() {
874
+ let value;
875
+ switch (token.type) {
876
+ case "punctuator":
877
+ switch (token.value) {
878
+ case "{":
879
+ value = {};
880
+ break;
881
+ case "[":
882
+ value = [];
883
+ break;
884
+ }
885
+ break;
886
+ case "null":
887
+ case "boolean":
888
+ case "numeric":
889
+ case "string":
890
+ value = token.value;
891
+ break;
892
+ }
893
+ if (root === void 0) {
894
+ root = value;
895
+ } else {
896
+ const parent = stack[stack.length - 1];
897
+ if (Array.isArray(parent)) {
898
+ parent.push(value);
899
+ } else {
900
+ Object.defineProperty(parent, key, {
901
+ value,
902
+ writable: true,
903
+ enumerable: true,
904
+ configurable: true
905
+ });
906
+ }
907
+ }
908
+ if (value !== null && typeof value === "object") {
909
+ stack.push(value);
910
+ if (Array.isArray(value)) {
911
+ parseState = "beforeArrayValue";
912
+ } else {
913
+ parseState = "beforePropertyName";
914
+ }
915
+ } else {
916
+ const current = stack[stack.length - 1];
917
+ if (current == null) {
918
+ parseState = "end";
919
+ } else if (Array.isArray(current)) {
920
+ parseState = "afterArrayValue";
921
+ } else {
922
+ parseState = "afterPropertyValue";
923
+ }
924
+ }
925
+ }
926
+ __name(push, "push");
927
+ function pop() {
928
+ stack.pop();
929
+ const current = stack[stack.length - 1];
930
+ if (current == null) {
931
+ parseState = "end";
932
+ } else if (Array.isArray(current)) {
933
+ parseState = "afterArrayValue";
934
+ } else {
935
+ parseState = "afterPropertyValue";
936
+ }
937
+ }
938
+ __name(pop, "pop");
939
+ function invalidChar(c2) {
940
+ if (c2 === void 0) {
941
+ return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
942
+ }
943
+ return syntaxError(`JSON5: invalid character '${formatChar(c2)}' at ${line}:${column}`);
944
+ }
945
+ __name(invalidChar, "invalidChar");
946
+ function invalidEOF() {
947
+ return syntaxError(`JSON5: invalid end of input at ${line}:${column}`);
948
+ }
949
+ __name(invalidEOF, "invalidEOF");
950
+ function invalidIdentifier() {
951
+ column -= 5;
952
+ return syntaxError(`JSON5: invalid identifier character at ${line}:${column}`);
953
+ }
954
+ __name(invalidIdentifier, "invalidIdentifier");
955
+ function separatorChar(c2) {
956
+ console.warn(`JSON5: '${formatChar(c2)}' in strings is not valid ECMAScript; consider escaping`);
957
+ }
958
+ __name(separatorChar, "separatorChar");
959
+ function formatChar(c2) {
960
+ const replacements = {
961
+ "'": "\\'",
962
+ '"': '\\"',
963
+ "\\": "\\\\",
964
+ "\b": "\\b",
965
+ "\f": "\\f",
966
+ "\n": "\\n",
967
+ "\r": "\\r",
968
+ " ": "\\t",
969
+ "\v": "\\v",
970
+ "\0": "\\0",
971
+ "\u2028": "\\u2028",
972
+ "\u2029": "\\u2029"
973
+ };
974
+ if (replacements[c2]) {
975
+ return replacements[c2];
976
+ }
977
+ if (c2 < " ") {
978
+ const hexString = c2.charCodeAt(0).toString(16);
979
+ return "\\x" + ("00" + hexString).substring(hexString.length);
980
+ }
981
+ return c2;
982
+ }
983
+ __name(formatChar, "formatChar");
984
+ function syntaxError(message) {
985
+ const err = new SyntaxError(message);
986
+ err.lineNumber = line;
987
+ err.columnNumber = column;
988
+ return err;
989
+ }
990
+ __name(syntaxError, "syntaxError");
991
+ var stringify = /* @__PURE__ */ __name(function stringify2(value, replacer, space) {
992
+ const stack2 = [];
993
+ let indent = "";
994
+ let propertyList;
995
+ let replacerFunc;
996
+ let gap = "";
997
+ let quote;
998
+ if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
999
+ space = replacer.space;
1000
+ quote = replacer.quote;
1001
+ replacer = replacer.replacer;
1002
+ }
1003
+ if (typeof replacer === "function") {
1004
+ replacerFunc = replacer;
1005
+ } else if (Array.isArray(replacer)) {
1006
+ propertyList = [];
1007
+ for (const v of replacer) {
1008
+ let item;
1009
+ if (typeof v === "string") {
1010
+ item = v;
1011
+ } else if (typeof v === "number" || v instanceof String || v instanceof Number) {
1012
+ item = String(v);
1013
+ }
1014
+ if (item !== void 0 && propertyList.indexOf(item) < 0) {
1015
+ propertyList.push(item);
1016
+ }
1017
+ }
1018
+ }
1019
+ if (space instanceof Number) {
1020
+ space = Number(space);
1021
+ } else if (space instanceof String) {
1022
+ space = String(space);
1023
+ }
1024
+ if (typeof space === "number") {
1025
+ if (space > 0) {
1026
+ space = Math.min(10, Math.floor(space));
1027
+ gap = " ".substr(0, space);
1028
+ }
1029
+ } else if (typeof space === "string") {
1030
+ gap = space.substr(0, 10);
1031
+ }
1032
+ return serializeProperty("", { "": value });
1033
+ function serializeProperty(key2, holder) {
1034
+ let value2 = holder[key2];
1035
+ if (value2 != null) {
1036
+ if (typeof value2.toJSON5 === "function") {
1037
+ value2 = value2.toJSON5(key2);
1038
+ } else if (typeof value2.toJSON === "function") {
1039
+ value2 = value2.toJSON(key2);
1040
+ }
1041
+ }
1042
+ if (replacerFunc) {
1043
+ value2 = replacerFunc.call(holder, key2, value2);
1044
+ }
1045
+ if (value2 instanceof Number) {
1046
+ value2 = Number(value2);
1047
+ } else if (value2 instanceof String) {
1048
+ value2 = String(value2);
1049
+ } else if (value2 instanceof Boolean) {
1050
+ value2 = value2.valueOf();
1051
+ }
1052
+ switch (value2) {
1053
+ case null:
1054
+ return "null";
1055
+ case true:
1056
+ return "true";
1057
+ case false:
1058
+ return "false";
1059
+ }
1060
+ if (typeof value2 === "string") {
1061
+ return quoteString(value2, false);
1062
+ }
1063
+ if (typeof value2 === "number") {
1064
+ return String(value2);
1065
+ }
1066
+ if (typeof value2 === "object") {
1067
+ return Array.isArray(value2) ? serializeArray(value2) : serializeObject(value2);
1068
+ }
1069
+ return void 0;
1070
+ }
1071
+ __name(serializeProperty, "serializeProperty");
1072
+ function quoteString(value2) {
1073
+ const quotes = {
1074
+ "'": 0.1,
1075
+ '"': 0.2
1076
+ };
1077
+ const replacements = {
1078
+ "'": "\\'",
1079
+ '"': '\\"',
1080
+ "\\": "\\\\",
1081
+ "\b": "\\b",
1082
+ "\f": "\\f",
1083
+ "\n": "\\n",
1084
+ "\r": "\\r",
1085
+ " ": "\\t",
1086
+ "\v": "\\v",
1087
+ "\0": "\\0",
1088
+ "\u2028": "\\u2028",
1089
+ "\u2029": "\\u2029"
1090
+ };
1091
+ let product = "";
1092
+ for (let i = 0; i < value2.length; i++) {
1093
+ const c2 = value2[i];
1094
+ switch (c2) {
1095
+ case "'":
1096
+ case '"':
1097
+ quotes[c2]++;
1098
+ product += c2;
1099
+ continue;
1100
+ case "\0":
1101
+ if (util.isDigit(value2[i + 1])) {
1102
+ product += "\\x00";
1103
+ continue;
1104
+ }
1105
+ }
1106
+ if (replacements[c2]) {
1107
+ product += replacements[c2];
1108
+ continue;
1109
+ }
1110
+ if (c2 < " ") {
1111
+ let hexString = c2.charCodeAt(0).toString(16);
1112
+ product += "\\x" + ("00" + hexString).substring(hexString.length);
1113
+ continue;
1114
+ }
1115
+ product += c2;
1116
+ }
1117
+ const quoteChar = quote || Object.keys(quotes).reduce((a, b) => quotes[a] < quotes[b] ? a : b);
1118
+ product = product.replace(new RegExp(quoteChar, "g"), replacements[quoteChar]);
1119
+ return quoteChar + product + quoteChar;
1120
+ }
1121
+ __name(quoteString, "quoteString");
1122
+ function serializeObject(value2) {
1123
+ if (stack2.indexOf(value2) >= 0) {
1124
+ throw TypeError("Converting circular structure to JSON5");
1125
+ }
1126
+ stack2.push(value2);
1127
+ let stepback = indent;
1128
+ indent = indent + gap;
1129
+ let keys = propertyList || Object.keys(value2);
1130
+ let partial = [];
1131
+ for (const key2 of keys) {
1132
+ const propertyString = serializeProperty(key2, value2);
1133
+ if (propertyString !== void 0) {
1134
+ let member = serializeKey(key2) + ":";
1135
+ if (gap !== "") {
1136
+ member += " ";
1137
+ }
1138
+ member += propertyString;
1139
+ partial.push(member);
1140
+ }
1141
+ }
1142
+ let final;
1143
+ if (partial.length === 0) {
1144
+ final = "{}";
1145
+ } else {
1146
+ let properties;
1147
+ if (gap === "") {
1148
+ properties = partial.join(",");
1149
+ final = "{" + properties + "}";
1150
+ } else {
1151
+ let separator = ",\n" + indent;
1152
+ properties = partial.join(separator);
1153
+ final = "{\n" + indent + properties + ",\n" + stepback + "}";
1154
+ }
1155
+ }
1156
+ stack2.pop();
1157
+ indent = stepback;
1158
+ return final;
1159
+ }
1160
+ __name(serializeObject, "serializeObject");
1161
+ function serializeKey(key2) {
1162
+ if (key2.length === 0) {
1163
+ return quoteString(key2, true);
1164
+ }
1165
+ const firstChar = String.fromCodePoint(key2.codePointAt(0));
1166
+ if (!util.isIdStartChar(firstChar)) {
1167
+ return quoteString(key2, true);
1168
+ }
1169
+ for (let i = firstChar.length; i < key2.length; i++) {
1170
+ if (!util.isIdContinueChar(String.fromCodePoint(key2.codePointAt(i)))) {
1171
+ return quoteString(key2, true);
1172
+ }
1173
+ }
1174
+ return key2;
1175
+ }
1176
+ __name(serializeKey, "serializeKey");
1177
+ function serializeArray(value2) {
1178
+ if (stack2.indexOf(value2) >= 0) {
1179
+ throw TypeError("Converting circular structure to JSON5");
1180
+ }
1181
+ stack2.push(value2);
1182
+ let stepback = indent;
1183
+ indent = indent + gap;
1184
+ let partial = [];
1185
+ for (let i = 0; i < value2.length; i++) {
1186
+ const propertyString = serializeProperty(String(i), value2);
1187
+ partial.push(propertyString !== void 0 ? propertyString : "null");
1188
+ }
1189
+ let final;
1190
+ if (partial.length === 0) {
1191
+ final = "[]";
1192
+ } else {
1193
+ if (gap === "") {
1194
+ let properties = partial.join(",");
1195
+ final = "[" + properties + "]";
1196
+ } else {
1197
+ let separator = ",\n" + indent;
1198
+ let properties = partial.join(separator);
1199
+ final = "[\n" + indent + properties + ",\n" + stepback + "]";
1200
+ }
1201
+ }
1202
+ stack2.pop();
1203
+ indent = stepback;
1204
+ return final;
1205
+ }
1206
+ __name(serializeArray, "serializeArray");
1207
+ }, "stringify");
1208
+ var JSON5 = {
1209
+ parse,
1210
+ stringify
1211
+ };
1212
+ var lib = JSON5;
1213
+ var dist_default = lib;
1214
+
1215
+ // src/classes/configvalidator/ConfigValidator.class.ts
1216
+ import { z } from "zod";
1217
+ var privilege_name_list = [
1218
+ "invoke_functions",
1219
+ "define_functions",
1220
+ "undefine_functions",
1221
+ "define_constants",
1222
+ "undefine_constants",
1223
+ "define_dependencies",
1224
+ "undefine_dependencies",
1225
+ "admin_privileges",
1226
+ "all_privileges"
1227
+ ];
1228
+ var tls_min_version_list = [
1229
+ "TLSv1.2",
1230
+ "TLSv1.3"
1231
+ ];
1232
+ var worker_runtime_options_schema = z.object({
1233
+ call_timeout_ms: z.number().int().positive().optional(),
1234
+ control_timeout_ms: z.number().int().positive().optional(),
1235
+ start_timeout_ms: z.number().int().positive().optional(),
1236
+ stop_timeout_ms: z.number().int().positive().optional(),
1237
+ restart_on_failure: z.boolean().optional(),
1238
+ max_restarts_per_worker: z.number().int().nonnegative().optional(),
1239
+ max_pending_calls_per_worker: z.number().int().positive().optional(),
1240
+ restart_base_delay_ms: z.number().int().positive().optional(),
1241
+ restart_max_delay_ms: z.number().int().positive().optional(),
1242
+ restart_jitter_ms: z.number().int().nonnegative().optional()
1243
+ }).strict();
1244
+ var rate_limiter_schema = z.object({
1245
+ enabled: z.boolean().optional(),
1246
+ tokens_per_interval: z.number().int().positive().optional(),
1247
+ interval_ms: z.number().int().positive().optional(),
1248
+ burst_tokens: z.number().int().positive().optional(),
1249
+ disconnect_on_limit: z.boolean().optional()
1250
+ }).strict();
1251
+ var abuse_controls_schema = z.object({
1252
+ connection_controls: z.object({
1253
+ max_concurrent_sockets: z.number().int().positive().optional(),
1254
+ max_concurrent_handshakes: z.number().int().positive().optional(),
1255
+ max_unauthenticated_sessions: z.number().int().positive().optional(),
1256
+ global_connection_window_ms: z.number().int().positive().optional(),
1257
+ global_max_new_connections_per_window: z.number().int().positive().optional(),
1258
+ per_ip_max_new_connections_per_window: z.number().int().positive().optional(),
1259
+ tls_handshake_timeout_ms: z.number().int().positive().optional(),
1260
+ auth_message_timeout_ms: z.number().int().positive().optional(),
1261
+ max_pre_auth_frame_bytes: z.number().int().positive().optional(),
1262
+ max_post_auth_frame_bytes: z.number().int().positive().optional()
1263
+ }).strict().optional(),
1264
+ auth_controls: z.object({
1265
+ pending_auth_window_ms: z.number().int().positive().optional(),
1266
+ max_pending_auth_attempts_per_ip_per_window: z.number().int().positive().optional(),
1267
+ failed_auth_window_ms: z.number().int().positive().optional(),
1268
+ max_failed_auth_per_ip_per_window: z.number().int().positive().optional(),
1269
+ max_failed_auth_per_api_key_per_window: z.number().int().positive().optional(),
1270
+ block_duration_ms: z.number().int().positive().optional(),
1271
+ enable_blocklist: z.boolean().optional()
1272
+ }).strict().optional(),
1273
+ request_controls: z.object({
1274
+ max_in_flight_requests_per_connection: z.number().int().positive().optional(),
1275
+ per_connection: rate_limiter_schema.optional(),
1276
+ per_api_key: rate_limiter_schema.optional(),
1277
+ per_ip: rate_limiter_schema.optional()
1278
+ }).strict().optional(),
1279
+ observability: z.object({
1280
+ enable_console_log: z.boolean().optional()
1281
+ }).strict().optional()
1282
+ }).strict();
1283
+ var daemon_server_config_schema = z.object({
1284
+ information: z.object({
1285
+ server_name: z.string().min(1)
1286
+ }).strict(),
1287
+ network: z.object({
1288
+ bind_addr: z.string().min(1),
1289
+ tcp_listen_port: z.number().int().positive().max(65535)
1290
+ }).strict(),
1291
+ tls_mtls: z.object({
1292
+ key_file: z.string().min(1),
1293
+ cert_file: z.string().min(1),
1294
+ ca_file: z.string().min(1),
1295
+ crl_file: z.string().min(1).optional(),
1296
+ min_version: z.enum(tls_min_version_list).optional(),
1297
+ cipher_suites: z.string().min(1).optional(),
1298
+ handshake_timeout_ms: z.number().int().positive().optional(),
1299
+ request_timeout_ms: z.number().int().positive().optional(),
1300
+ max_frame_bytes: z.number().int().positive().optional()
1301
+ }).strict(),
1302
+ workerprocedurecall: z.object({
1303
+ count: z.number().int().positive(),
1304
+ constructor_options: worker_runtime_options_schema.optional(),
1305
+ start_options: worker_runtime_options_schema.optional()
1306
+ }).strict(),
1307
+ abuse_controls: abuse_controls_schema.optional(),
1308
+ observability: z.object({
1309
+ enable_console_log: z.boolean().optional(),
1310
+ log_worker_events: z.boolean().optional(),
1311
+ metrics_log_interval_ms: z.number().int().positive().optional()
1312
+ }).strict().optional()
1313
+ }).strict();
1314
+ var daemon_api_key_config_schema = z.object({
1315
+ api_keys: z.array(z.object({
1316
+ key_id: z.string().min(1),
1317
+ api_key: z.string().min(1),
1318
+ privileges: z.array(z.enum(privilege_name_list)).min(1),
1319
+ enabled: z.boolean().optional(),
1320
+ identity_constraints: z.object({
1321
+ remote_address_regex: z.string().min(1).optional(),
1322
+ tls_peer_subject_regex: z.string().min(1).optional(),
1323
+ tls_peer_san_regex: z.string().min(1).optional(),
1324
+ tls_peer_fingerprint256_regex: z.string().min(1).optional(),
1325
+ tls_peer_serial_number_regex: z.string().min(1).optional()
1326
+ }).strict().optional()
1327
+ }).strict()).min(1)
1328
+ }).strict();
1329
+ function BuildZodErrorMessage(params) {
1330
+ const message_lines = params.error.issues.map((issue) => {
1331
+ const issue_path = issue.path.length > 0 ? issue.path.join(".") : "<root>";
1332
+ return `${issue_path}: ${issue.message}`;
1333
+ });
1334
+ return `${params.prefix}
1335
+ ${message_lines.join("\n")}`;
1336
+ }
1337
+ __name(BuildZodErrorMessage, "BuildZodErrorMessage");
1338
+ function CompileRegex(params) {
1339
+ try {
1340
+ return new RegExp(params.source);
1341
+ } catch (error) {
1342
+ const error_message = error instanceof Error ? error.message : String(error);
1343
+ throw new Error(`Invalid regex for ${params.label}: ${error_message}`);
1344
+ }
1345
+ }
1346
+ __name(CompileRegex, "CompileRegex");
1347
+ var _ConfigValidator = class _ConfigValidator {
1348
+ validateServerConfig(params) {
1349
+ const parse_result = daemon_server_config_schema.safeParse(params.server_config_raw);
1350
+ if (!parse_result.success) {
1351
+ throw new Error(BuildZodErrorMessage({
1352
+ prefix: "Invalid server config.",
1353
+ error: parse_result.error
1354
+ }));
1355
+ }
1356
+ return parse_result.data;
1357
+ }
1358
+ validateApiKeysConfig(params) {
1359
+ const parse_result = daemon_api_key_config_schema.safeParse(params.api_keys_config_raw);
1360
+ if (!parse_result.success) {
1361
+ throw new Error(BuildZodErrorMessage({
1362
+ prefix: "Invalid api-keys config.",
1363
+ error: parse_result.error
1364
+ }));
1365
+ }
1366
+ this.assertUniqueApiKeys({
1367
+ api_keys: parse_result.data.api_keys
1368
+ });
1369
+ this.assertUniqueKeyIds({
1370
+ api_keys: parse_result.data.api_keys
1371
+ });
1372
+ return parse_result.data;
1373
+ }
1374
+ toRuntimeApiKeysConfig(params) {
1375
+ return params.api_keys_config.api_keys.map((api_key_entry) => {
1376
+ const compiled_identity_constraints = this.compileIdentityConstraints({
1377
+ api_key_entry
1378
+ });
1379
+ const runtime_entry = {
1380
+ key_id: api_key_entry.key_id,
1381
+ api_key: api_key_entry.api_key,
1382
+ privileges: [
1383
+ ...api_key_entry.privileges
1384
+ ],
1385
+ enabled: api_key_entry.enabled ?? true,
1386
+ identity_constraints: compiled_identity_constraints
1387
+ };
1388
+ return runtime_entry;
1389
+ });
1390
+ }
1391
+ compileIdentityConstraints(params) {
1392
+ const constraints = params.api_key_entry.identity_constraints;
1393
+ if (!constraints) {
1394
+ return void 0;
1395
+ }
1396
+ const compiled_constraints = {};
1397
+ if (constraints.remote_address_regex) {
1398
+ compiled_constraints.remote_address_regex = CompileRegex({
1399
+ source: constraints.remote_address_regex,
1400
+ label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.remote_address_regex`
1401
+ });
1402
+ }
1403
+ if (constraints.tls_peer_subject_regex) {
1404
+ compiled_constraints.tls_peer_subject_regex = CompileRegex({
1405
+ source: constraints.tls_peer_subject_regex,
1406
+ label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_subject_regex`
1407
+ });
1408
+ }
1409
+ if (constraints.tls_peer_san_regex) {
1410
+ compiled_constraints.tls_peer_san_regex = CompileRegex({
1411
+ source: constraints.tls_peer_san_regex,
1412
+ label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_san_regex`
1413
+ });
1414
+ }
1415
+ if (constraints.tls_peer_fingerprint256_regex) {
1416
+ compiled_constraints.tls_peer_fingerprint256_regex = CompileRegex({
1417
+ source: constraints.tls_peer_fingerprint256_regex,
1418
+ label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_fingerprint256_regex`
1419
+ });
1420
+ }
1421
+ if (constraints.tls_peer_serial_number_regex) {
1422
+ compiled_constraints.tls_peer_serial_number_regex = CompileRegex({
1423
+ source: constraints.tls_peer_serial_number_regex,
1424
+ label: `api_keys[${params.api_key_entry.key_id}].identity_constraints.tls_peer_serial_number_regex`
1425
+ });
1426
+ }
1427
+ return compiled_constraints;
1428
+ }
1429
+ assertUniqueApiKeys(params) {
1430
+ const seen_api_keys = /* @__PURE__ */ new Set();
1431
+ for (const api_key_entry of params.api_keys) {
1432
+ if (seen_api_keys.has(api_key_entry.api_key)) {
1433
+ throw new Error(`Duplicate api_key found in api-keys config: ${api_key_entry.api_key}`);
1434
+ }
1435
+ seen_api_keys.add(api_key_entry.api_key);
1436
+ }
1437
+ }
1438
+ assertUniqueKeyIds(params) {
1439
+ const seen_key_ids = /* @__PURE__ */ new Set();
1440
+ for (const api_key_entry of params.api_keys) {
1441
+ if (seen_key_ids.has(api_key_entry.key_id)) {
1442
+ throw new Error(`Duplicate key_id found in api-keys config: ${api_key_entry.key_id}`);
1443
+ }
1444
+ seen_key_ids.add(api_key_entry.key_id);
1445
+ }
1446
+ }
1447
+ };
1448
+ __name(_ConfigValidator, "ConfigValidator");
1449
+ var ConfigValidator = _ConfigValidator;
1450
+
1451
+ // src/classes/configfileloader/ConfigFileLoader.class.ts
1452
+ function ReadUtf8File(params) {
1453
+ try {
1454
+ return fs.readFileSync(params.file_path, "utf8");
1455
+ } catch (error) {
1456
+ const error_message = error instanceof Error ? error.message : String(error);
1457
+ throw new Error(`Unable to read file "${params.file_path}": ${error_message}`);
1458
+ }
1459
+ }
1460
+ __name(ReadUtf8File, "ReadUtf8File");
1461
+ function ResolvePath(params) {
1462
+ if (path.isAbsolute(params.file_path)) {
1463
+ return params.file_path;
1464
+ }
1465
+ return path.resolve(params.base_dir, params.file_path);
1466
+ }
1467
+ __name(ResolvePath, "ResolvePath");
1468
+ function ParseJson5(params) {
1469
+ try {
1470
+ return dist_default.parse(params.content);
1471
+ } catch (error) {
1472
+ const error_message = error instanceof Error ? error.message : String(error);
1473
+ throw new Error(`Invalid JSON5 in "${params.source_path}": ${error_message}`);
1474
+ }
1475
+ }
1476
+ __name(ParseJson5, "ParseJson5");
1477
+ var _ConfigFileLoader = class _ConfigFileLoader {
1478
+ constructor(params) {
1479
+ __publicField(this, "config_validator");
1480
+ this.config_validator = params?.config_validator ?? new ConfigValidator();
1481
+ }
1482
+ loadDaemonConfig(params) {
1483
+ const server_config_path = ResolvePath({
1484
+ file_path: params.config_paths.server_config_path,
1485
+ base_dir: process.cwd()
1486
+ });
1487
+ const api_keys_config_path = ResolvePath({
1488
+ file_path: params.config_paths.api_keys_config_path,
1489
+ base_dir: process.cwd()
1490
+ });
1491
+ const server_config_raw = this.readJson5File({
1492
+ file_path: server_config_path
1493
+ });
1494
+ const api_keys_config_raw = this.readJson5File({
1495
+ file_path: api_keys_config_path
1496
+ });
1497
+ const server_config = this.config_validator.validateServerConfig({
1498
+ server_config_raw
1499
+ });
1500
+ const api_keys_config = this.config_validator.validateApiKeysConfig({
1501
+ api_keys_config_raw
1502
+ });
1503
+ const runtime_tls_mtls = this.resolveTlsMaterial({
1504
+ tls_file_config: server_config.tls_mtls,
1505
+ config_file_dir: path.dirname(server_config_path)
1506
+ });
1507
+ const runtime_api_keys = this.config_validator.toRuntimeApiKeysConfig({
1508
+ api_keys_config
1509
+ });
1510
+ return {
1511
+ server_config: {
1512
+ ...server_config,
1513
+ tls_mtls: runtime_tls_mtls
1514
+ },
1515
+ api_keys_config: {
1516
+ api_keys: runtime_api_keys
1517
+ }
1518
+ };
1519
+ }
1520
+ readJson5File(params) {
1521
+ const file_content = ReadUtf8File({
1522
+ file_path: params.file_path
1523
+ });
1524
+ return ParseJson5({
1525
+ content: file_content,
1526
+ source_path: params.file_path
1527
+ });
1528
+ }
1529
+ resolveTlsMaterial(params) {
1530
+ const key_pem = this.readPemFile({
1531
+ pem_path: params.tls_file_config.key_file,
1532
+ config_file_dir: params.config_file_dir,
1533
+ label: "tls_mtls.key_file"
1534
+ });
1535
+ const cert_pem = this.readPemFile({
1536
+ pem_path: params.tls_file_config.cert_file,
1537
+ config_file_dir: params.config_file_dir,
1538
+ label: "tls_mtls.cert_file"
1539
+ });
1540
+ const ca_pem = this.readPemFile({
1541
+ pem_path: params.tls_file_config.ca_file,
1542
+ config_file_dir: params.config_file_dir,
1543
+ label: "tls_mtls.ca_file"
1544
+ });
1545
+ const crl_pem = params.tls_file_config.crl_file ? this.readPemFile({
1546
+ pem_path: params.tls_file_config.crl_file,
1547
+ config_file_dir: params.config_file_dir,
1548
+ label: "tls_mtls.crl_file"
1549
+ }) : void 0;
1550
+ return {
1551
+ key_pem,
1552
+ cert_pem,
1553
+ ca_pem,
1554
+ crl_pem,
1555
+ min_version: params.tls_file_config.min_version,
1556
+ cipher_suites: params.tls_file_config.cipher_suites,
1557
+ handshake_timeout_ms: params.tls_file_config.handshake_timeout_ms,
1558
+ request_timeout_ms: params.tls_file_config.request_timeout_ms,
1559
+ max_frame_bytes: params.tls_file_config.max_frame_bytes
1560
+ };
1561
+ }
1562
+ readPemFile(params) {
1563
+ const absolute_file_path = ResolvePath({
1564
+ file_path: params.pem_path,
1565
+ base_dir: params.config_file_dir
1566
+ });
1567
+ const pem_content = ReadUtf8File({
1568
+ file_path: absolute_file_path
1569
+ }).trim();
1570
+ if (!pem_content.includes("BEGIN")) {
1571
+ throw new Error(`File "${absolute_file_path}" for ${params.label} does not look like a PEM file.`);
1572
+ }
1573
+ return `${pem_content}
1574
+ `;
1575
+ }
1576
+ };
1577
+ __name(_ConfigFileLoader, "ConfigFileLoader");
1578
+ var ConfigFileLoader = _ConfigFileLoader;
1579
+
1580
+ // src/classes/daemoncli/DaemonCli.class.ts
1581
+ var default_server_config_path = "./config/server.config.json5";
1582
+ var default_api_keys_config_path = "./config/api_keys.config.json5";
1583
+ var default_tls_output_dir = "./config/certs";
1584
+ var default_ca_common_name = "nodenetproccalld-local-ca";
1585
+ var default_server_common_name = "localhost";
1586
+ var default_client_common_name = "nodenetproccalld-client";
1587
+ var default_tls_valid_days = 825;
1588
+ var _DaemonCli = class _DaemonCli {
1589
+ parseOptions() {
1590
+ const options = {
1591
+ server_config_path: default_server_config_path,
1592
+ api_keys_config_path: default_api_keys_config_path,
1593
+ help: false,
1594
+ tls_generation: {
1595
+ enabled: false,
1596
+ output_dir: default_tls_output_dir,
1597
+ overwrite: false,
1598
+ ca_common_name: default_ca_common_name,
1599
+ server_common_name: default_server_common_name,
1600
+ client_common_name: default_client_common_name,
1601
+ valid_days: default_tls_valid_days
1602
+ }
1603
+ };
1604
+ const argv = process.argv.slice(2);
1605
+ for (let index = 0; index < argv.length; index += 1) {
1606
+ const token2 = argv[index];
1607
+ if (token2 === "--help" || token2 === "-h") {
1608
+ options.help = true;
1609
+ continue;
1610
+ }
1611
+ if (token2 === "--server-config") {
1612
+ const next_value = argv[index + 1];
1613
+ if (!next_value) {
1614
+ throw new Error("Missing value for --server-config");
1615
+ }
1616
+ options.server_config_path = next_value;
1617
+ index += 1;
1618
+ continue;
1619
+ }
1620
+ if (token2 === "--api-keys-config") {
1621
+ const next_value = argv[index + 1];
1622
+ if (!next_value) {
1623
+ throw new Error("Missing value for --api-keys-config");
1624
+ }
1625
+ options.api_keys_config_path = next_value;
1626
+ index += 1;
1627
+ continue;
1628
+ }
1629
+ if (token2 === "--generate-tls-material") {
1630
+ options.tls_generation.enabled = true;
1631
+ continue;
1632
+ }
1633
+ if (token2 === "--tls-output-dir") {
1634
+ const next_value = argv[index + 1];
1635
+ if (!next_value) {
1636
+ throw new Error("Missing value for --tls-output-dir");
1637
+ }
1638
+ options.tls_generation.output_dir = next_value;
1639
+ index += 1;
1640
+ continue;
1641
+ }
1642
+ if (token2 === "--tls-overwrite") {
1643
+ options.tls_generation.overwrite = true;
1644
+ continue;
1645
+ }
1646
+ if (token2 === "--tls-ca-cn") {
1647
+ const next_value = argv[index + 1];
1648
+ if (!next_value) {
1649
+ throw new Error("Missing value for --tls-ca-cn");
1650
+ }
1651
+ options.tls_generation.ca_common_name = next_value;
1652
+ index += 1;
1653
+ continue;
1654
+ }
1655
+ if (token2 === "--tls-server-cn") {
1656
+ const next_value = argv[index + 1];
1657
+ if (!next_value) {
1658
+ throw new Error("Missing value for --tls-server-cn");
1659
+ }
1660
+ options.tls_generation.server_common_name = next_value;
1661
+ index += 1;
1662
+ continue;
1663
+ }
1664
+ if (token2 === "--tls-client-cn") {
1665
+ const next_value = argv[index + 1];
1666
+ if (!next_value) {
1667
+ throw new Error("Missing value for --tls-client-cn");
1668
+ }
1669
+ options.tls_generation.client_common_name = next_value;
1670
+ index += 1;
1671
+ continue;
1672
+ }
1673
+ if (token2 === "--tls-valid-days") {
1674
+ const next_value = argv[index + 1];
1675
+ if (!next_value) {
1676
+ throw new Error("Missing value for --tls-valid-days");
1677
+ }
1678
+ const valid_days = Number(next_value);
1679
+ if (!Number.isInteger(valid_days) || valid_days <= 0) {
1680
+ throw new Error("--tls-valid-days must be a positive integer.");
1681
+ }
1682
+ options.tls_generation.valid_days = valid_days;
1683
+ index += 1;
1684
+ continue;
1685
+ }
1686
+ throw new Error(`Unknown argument: ${token2}`);
1687
+ }
1688
+ return options;
1689
+ }
1690
+ printHelp() {
1691
+ const help_text = [
1692
+ "nodenetproccalld",
1693
+ "",
1694
+ "Usage:",
1695
+ " node dist/index.js [options]",
1696
+ "",
1697
+ "Options:",
1698
+ " --server-config <path> Path to server JSON5 config file.",
1699
+ " Default: ./config/server.config.json5",
1700
+ " --api-keys-config <path> Path to api keys JSON5 config file.",
1701
+ " Default: ./config/api_keys.config.json5",
1702
+ " --generate-tls-material Generate CA/server/client TLS material and exit.",
1703
+ " --tls-output-dir <path> Output directory for generated TLS files.",
1704
+ " Default: ./config/certs",
1705
+ " --tls-overwrite Overwrite existing TLS files in output dir.",
1706
+ " --tls-ca-cn <value> CA certificate common name.",
1707
+ " Default: nodenetproccalld-local-ca",
1708
+ " --tls-server-cn <value> Server certificate common name.",
1709
+ " Default: localhost",
1710
+ " --tls-client-cn <value> Client certificate common name.",
1711
+ " Default: nodenetproccalld-client",
1712
+ " --tls-valid-days <number> Certificate validity in days.",
1713
+ " Default: 825",
1714
+ " -h, --help Show this help message."
1715
+ ].join("\n");
1716
+ console.log(help_text);
1717
+ }
1718
+ };
1719
+ __name(_DaemonCli, "DaemonCli");
1720
+ var DaemonCli = _DaemonCli;
1721
+
1722
+ // src/classes/networkprocedurecalldaemon/NetworkProcedureCallDaemon.class.ts
1723
+ import { NetworkProcedureCall } from "@opsimathically/networkprocedurecall";
1724
+ import { WorkerProcedureCall } from "@opsimathically/workerprocedurecall";
1725
+ function ToIsoTimestamp() {
1726
+ return (/* @__PURE__ */ new Date()).toISOString();
1727
+ }
1728
+ __name(ToIsoTimestamp, "ToIsoTimestamp");
1729
+ var _NetworkProcedureCallDaemon = class _NetworkProcedureCallDaemon {
1730
+ constructor(params) {
1731
+ __publicField(this, "config_paths");
1732
+ __publicField(this, "config_file_loader");
1733
+ __publicField(this, "lifecycle_state", "stopped");
1734
+ __publicField(this, "daemon_config", null);
1735
+ __publicField(this, "workerprocedurecall", null);
1736
+ __publicField(this, "networkprocedurecall", null);
1737
+ __publicField(this, "api_key_authorizer", null);
1738
+ __publicField(this, "worker_event_listener_id", null);
1739
+ __publicField(this, "metrics_log_interval_handle", null);
1740
+ this.config_paths = params.config_paths;
1741
+ this.config_file_loader = params.config_file_loader ?? new ConfigFileLoader();
1742
+ }
1743
+ async start() {
1744
+ if (this.lifecycle_state === "running") {
1745
+ throw new Error("Daemon is already running.");
1746
+ }
1747
+ if (this.lifecycle_state === "starting") {
1748
+ throw new Error("Daemon startup is already in progress.");
1749
+ }
1750
+ if (this.lifecycle_state === "stopping") {
1751
+ throw new Error("Daemon stop is in progress. Wait for stop to complete.");
1752
+ }
1753
+ this.lifecycle_state = "starting";
1754
+ try {
1755
+ this.daemon_config = this.config_file_loader.loadDaemonConfig({
1756
+ config_paths: this.config_paths
1757
+ });
1758
+ this.api_key_authorizer = new ApiKeyAuthorizer({
1759
+ api_key_entries: this.daemon_config.api_keys_config.api_keys
1760
+ });
1761
+ const constructor_options = this.daemon_config.server_config.workerprocedurecall.constructor_options;
1762
+ this.workerprocedurecall = constructor_options ? new WorkerProcedureCall(constructor_options) : new WorkerProcedureCall();
1763
+ const log_worker_events = this.daemon_config.server_config.observability?.log_worker_events ?? true;
1764
+ if (log_worker_events) {
1765
+ this.worker_event_listener_id = this.workerprocedurecall.onWorkerEvent({
1766
+ listener: /* @__PURE__ */ __name((worker_event) => {
1767
+ this.logWorkerEvent({
1768
+ worker_event
1769
+ });
1770
+ }, "listener")
1771
+ });
1772
+ }
1773
+ await this.workerprocedurecall.startWorkers({
1774
+ count: this.daemon_config.server_config.workerprocedurecall.count,
1775
+ ...this.daemon_config.server_config.workerprocedurecall.start_options ?? {}
1776
+ });
1777
+ const networkprocedurecall_workerprocedurecall = this.workerprocedurecall;
1778
+ this.networkprocedurecall = new NetworkProcedureCall({
1779
+ workerprocedurecall: networkprocedurecall_workerprocedurecall
1780
+ });
1781
+ const auth_callback = this.createAuthCallback();
1782
+ const start_params = this.buildServerStartParams({
1783
+ auth_callback
1784
+ });
1785
+ await this.networkprocedurecall.start(start_params);
1786
+ this.startMetricsLogging();
1787
+ this.lifecycle_state = "running";
1788
+ this.logMessage({
1789
+ severity: "info",
1790
+ message: `Daemon started: ${start_params.information.server_name} on ${start_params.network.bind_addr}:${start_params.network.tcp_listen_port}`
1791
+ });
1792
+ } catch (error) {
1793
+ this.lifecycle_state = "stopped";
1794
+ await this.stopBestEffort();
1795
+ throw error;
1796
+ }
1797
+ }
1798
+ async stop() {
1799
+ if (this.lifecycle_state === "stopped") {
1800
+ return;
1801
+ }
1802
+ if (this.lifecycle_state === "stopping") {
1803
+ return;
1804
+ }
1805
+ this.lifecycle_state = "stopping";
1806
+ await this.stopBestEffort();
1807
+ this.lifecycle_state = "stopped";
1808
+ this.logMessage({
1809
+ severity: "info",
1810
+ message: "Daemon stopped."
1811
+ });
1812
+ }
1813
+ getRuntimeSnapshot() {
1814
+ return {
1815
+ lifecycle_state: this.lifecycle_state,
1816
+ server_name: this.daemon_config?.server_config.information.server_name,
1817
+ bind_addr: this.daemon_config?.server_config.network.bind_addr,
1818
+ tcp_listen_port: this.daemon_config?.server_config.network.tcp_listen_port,
1819
+ worker_health_states: this.workerprocedurecall?.getWorkerHealthStates(),
1820
+ abuse_metrics: this.networkprocedurecall?.getAbuseMetrics()
1821
+ };
1822
+ }
1823
+ createAuthCallback() {
1824
+ return async (auth_callback_params) => {
1825
+ const authorizer = this.requireApiKeyAuthorizer();
1826
+ return await authorizer.authenticate({
1827
+ auth_callback_params
1828
+ });
1829
+ };
1830
+ }
1831
+ buildServerStartParams(params) {
1832
+ const daemon_config = this.requireDaemonConfig();
1833
+ const abuse_controls_from_file = daemon_config.server_config.abuse_controls;
1834
+ const enable_console_log = daemon_config.server_config.observability?.enable_console_log;
1835
+ let merged_abuse_controls = abuse_controls_from_file;
1836
+ if (enable_console_log !== void 0) {
1837
+ merged_abuse_controls = {
1838
+ ...abuse_controls_from_file ?? {},
1839
+ observability: {
1840
+ ...abuse_controls_from_file?.observability ?? {},
1841
+ enable_console_log
1842
+ }
1843
+ };
1844
+ }
1845
+ return {
1846
+ information: {
1847
+ server_name: daemon_config.server_config.information.server_name
1848
+ },
1849
+ network: {
1850
+ bind_addr: daemon_config.server_config.network.bind_addr,
1851
+ tcp_listen_port: daemon_config.server_config.network.tcp_listen_port
1852
+ },
1853
+ tls_mtls: {
1854
+ ...daemon_config.server_config.tls_mtls
1855
+ },
1856
+ abuse_controls: merged_abuse_controls,
1857
+ auth_callback: params.auth_callback
1858
+ };
1859
+ }
1860
+ startMetricsLogging() {
1861
+ this.clearMetricsLoggingInterval();
1862
+ const daemon_config = this.requireDaemonConfig();
1863
+ const metrics_log_interval_ms = daemon_config.server_config.observability?.metrics_log_interval_ms;
1864
+ if (!metrics_log_interval_ms) {
1865
+ return;
1866
+ }
1867
+ this.metrics_log_interval_handle = setInterval(() => {
1868
+ if (!this.networkprocedurecall || !this.workerprocedurecall) {
1869
+ return;
1870
+ }
1871
+ const abuse_metrics = this.networkprocedurecall.getAbuseMetrics();
1872
+ const worker_health_states = this.workerprocedurecall.getWorkerHealthStates();
1873
+ this.logMessage({
1874
+ severity: "info",
1875
+ message: `runtime_metrics abuse=${JSON.stringify(abuse_metrics)} worker_health=${JSON.stringify(worker_health_states)}`
1876
+ });
1877
+ }, metrics_log_interval_ms);
1878
+ this.metrics_log_interval_handle.unref();
1879
+ }
1880
+ clearMetricsLoggingInterval() {
1881
+ if (this.metrics_log_interval_handle) {
1882
+ clearInterval(this.metrics_log_interval_handle);
1883
+ this.metrics_log_interval_handle = null;
1884
+ }
1885
+ }
1886
+ async stopBestEffort() {
1887
+ this.clearMetricsLoggingInterval();
1888
+ const stop_errors = [];
1889
+ if (this.networkprocedurecall) {
1890
+ try {
1891
+ await this.networkprocedurecall.stop();
1892
+ } catch (error) {
1893
+ stop_errors.push(error);
1894
+ }
1895
+ this.networkprocedurecall = null;
1896
+ }
1897
+ if (this.workerprocedurecall && this.worker_event_listener_id !== null) {
1898
+ try {
1899
+ this.workerprocedurecall.offWorkerEvent({
1900
+ listener_id: this.worker_event_listener_id
1901
+ });
1902
+ } catch (error) {
1903
+ stop_errors.push(error);
1904
+ }
1905
+ this.worker_event_listener_id = null;
1906
+ }
1907
+ if (this.workerprocedurecall) {
1908
+ try {
1909
+ await this.workerprocedurecall.stopWorkers();
1910
+ } catch (error) {
1911
+ stop_errors.push(error);
1912
+ }
1913
+ this.workerprocedurecall = null;
1914
+ }
1915
+ this.api_key_authorizer = null;
1916
+ this.daemon_config = null;
1917
+ if (stop_errors.length > 0) {
1918
+ const first_error = stop_errors[0];
1919
+ throw first_error;
1920
+ }
1921
+ }
1922
+ requireDaemonConfig() {
1923
+ if (!this.daemon_config) {
1924
+ throw new Error("Daemon config is not initialized.");
1925
+ }
1926
+ return this.daemon_config;
1927
+ }
1928
+ requireApiKeyAuthorizer() {
1929
+ if (!this.api_key_authorizer) {
1930
+ throw new Error("ApiKeyAuthorizer is not initialized.");
1931
+ }
1932
+ return this.api_key_authorizer;
1933
+ }
1934
+ logWorkerEvent(params) {
1935
+ this.logMessage({
1936
+ severity: params.worker_event.severity,
1937
+ message: `worker_event ${JSON.stringify(params.worker_event)}`
1938
+ });
1939
+ }
1940
+ logMessage(params) {
1941
+ const output_message = `[${ToIsoTimestamp()}] [${params.severity}] ${params.message}`;
1942
+ if (params.severity === "error") {
1943
+ console.error(output_message);
1944
+ return;
1945
+ }
1946
+ if (params.severity === "warn") {
1947
+ console.warn(output_message);
1948
+ return;
1949
+ }
1950
+ console.log(output_message);
1951
+ }
1952
+ };
1953
+ __name(_NetworkProcedureCallDaemon, "NetworkProcedureCallDaemon");
1954
+ var NetworkProcedureCallDaemon = _NetworkProcedureCallDaemon;
1955
+
1956
+ // src/classes/daemonprocess/DaemonProcess.class.ts
1957
+ var _DaemonProcess = class _DaemonProcess {
1958
+ constructor(params) {
1959
+ __publicField(this, "daemon");
1960
+ __publicField(this, "is_running", false);
1961
+ __publicField(this, "stop_in_progress", false);
1962
+ __publicField(this, "stop_resolve", null);
1963
+ __publicField(this, "stop_waiter");
1964
+ __publicField(this, "handleSignal", /* @__PURE__ */ __name((signal) => {
1965
+ void this.requestStop({
1966
+ reason: `Received ${signal}.`
1967
+ });
1968
+ }, "handleSignal"));
1969
+ __publicField(this, "handleUncaughtException", /* @__PURE__ */ __name((error) => {
1970
+ console.error(`Uncaught exception: ${error.stack ?? error.message}`);
1971
+ process.exitCode = 1;
1972
+ void this.requestStop({
1973
+ reason: "Stopping daemon after uncaught exception."
1974
+ });
1975
+ }, "handleUncaughtException"));
1976
+ __publicField(this, "handleUnhandledRejection", /* @__PURE__ */ __name((error) => {
1977
+ const error_message = error instanceof Error ? error.stack ?? error.message : String(error);
1978
+ console.error(`Unhandled rejection: ${error_message}`);
1979
+ process.exitCode = 1;
1980
+ void this.requestStop({
1981
+ reason: "Stopping daemon after unhandled rejection."
1982
+ });
1983
+ }, "handleUnhandledRejection"));
1984
+ this.daemon = new NetworkProcedureCallDaemon({
1985
+ config_paths: params.config_paths
1986
+ });
1987
+ this.stop_waiter = new Promise((resolve) => {
1988
+ this.stop_resolve = resolve;
1989
+ });
1990
+ }
1991
+ async run() {
1992
+ if (this.is_running) {
1993
+ throw new Error("DaemonProcess is already running.");
1994
+ }
1995
+ this.is_running = true;
1996
+ this.attachProcessHandlers();
1997
+ try {
1998
+ await this.daemon.start();
1999
+ } catch (error) {
2000
+ this.detachProcessHandlers();
2001
+ this.is_running = false;
2002
+ throw error;
2003
+ }
2004
+ await this.stop_waiter;
2005
+ }
2006
+ attachProcessHandlers() {
2007
+ process.on("SIGINT", this.handleSignal);
2008
+ process.on("SIGTERM", this.handleSignal);
2009
+ process.on("uncaughtException", this.handleUncaughtException);
2010
+ process.on("unhandledRejection", this.handleUnhandledRejection);
2011
+ }
2012
+ detachProcessHandlers() {
2013
+ process.off("SIGINT", this.handleSignal);
2014
+ process.off("SIGTERM", this.handleSignal);
2015
+ process.off("uncaughtException", this.handleUncaughtException);
2016
+ process.off("unhandledRejection", this.handleUnhandledRejection);
2017
+ }
2018
+ async requestStop(params) {
2019
+ if (!this.is_running || this.stop_in_progress) {
2020
+ return;
2021
+ }
2022
+ this.stop_in_progress = true;
2023
+ console.log(params.reason);
2024
+ try {
2025
+ await this.daemon.stop();
2026
+ } catch (error) {
2027
+ const error_message = error instanceof Error ? error.stack ?? error.message : String(error);
2028
+ console.error(`Error while stopping daemon: ${error_message}`);
2029
+ process.exitCode = 1;
2030
+ } finally {
2031
+ this.detachProcessHandlers();
2032
+ this.is_running = false;
2033
+ this.stop_in_progress = false;
2034
+ if (this.stop_resolve) {
2035
+ this.stop_resolve();
2036
+ }
2037
+ }
2038
+ }
2039
+ };
2040
+ __name(_DaemonProcess, "DaemonProcess");
2041
+ var DaemonProcess = _DaemonProcess;
2042
+
2043
+ // src/classes/tlsmaterialgenerator/TlsMaterialGenerator.class.ts
2044
+ import { execFileSync } from "child_process";
2045
+ import fs2 from "fs";
2046
+ import path2 from "path";
2047
+ function EnsurePositiveInteger(params) {
2048
+ if (!Number.isInteger(params.value) || params.value <= 0) {
2049
+ throw new Error(`${params.label} must be a positive integer.`);
2050
+ }
2051
+ }
2052
+ __name(EnsurePositiveInteger, "EnsurePositiveInteger");
2053
+ function MakeDirRecursive(params) {
2054
+ fs2.mkdirSync(params.dir_path, {
2055
+ recursive: true
2056
+ });
2057
+ }
2058
+ __name(MakeDirRecursive, "MakeDirRecursive");
2059
+ function WriteTextFile(params) {
2060
+ fs2.writeFileSync(params.file_path, params.content, "utf8");
2061
+ }
2062
+ __name(WriteTextFile, "WriteTextFile");
2063
+ var _TlsMaterialGenerator = class _TlsMaterialGenerator {
2064
+ generateTlsMaterial(params) {
2065
+ const options = params.tls_generation_options;
2066
+ EnsurePositiveInteger({
2067
+ value: options.valid_days,
2068
+ label: "tls_generation.valid_days"
2069
+ });
2070
+ const output_dir = path2.resolve(process.cwd(), options.output_dir);
2071
+ MakeDirRecursive({
2072
+ dir_path: output_dir
2073
+ });
2074
+ this.assertOpenSslAvailable();
2075
+ const tls_files = this.buildTlsFileMap({
2076
+ output_dir
2077
+ });
2078
+ this.assertTargetFilesAreWritable({
2079
+ tls_files,
2080
+ overwrite: options.overwrite
2081
+ });
2082
+ try {
2083
+ this.generateCa({
2084
+ tls_files,
2085
+ valid_days: options.valid_days,
2086
+ ca_common_name: options.ca_common_name
2087
+ });
2088
+ this.generateServerCertificate({
2089
+ tls_files,
2090
+ valid_days: options.valid_days,
2091
+ server_common_name: options.server_common_name
2092
+ });
2093
+ this.generateClientCertificate({
2094
+ tls_files,
2095
+ valid_days: options.valid_days,
2096
+ client_common_name: options.client_common_name
2097
+ });
2098
+ this.cleanupIntermediateFiles({
2099
+ tls_files
2100
+ });
2101
+ } catch (error) {
2102
+ throw new Error(`Failed to generate TLS material in "${output_dir}": ${this.getErrorMessage({
2103
+ error
2104
+ })}`);
2105
+ }
2106
+ return {
2107
+ output_dir,
2108
+ ca_key_path: tls_files.ca_key_path,
2109
+ ca_cert_path: tls_files.ca_cert_path,
2110
+ server_key_path: tls_files.server_key_path,
2111
+ server_cert_path: tls_files.server_cert_path,
2112
+ client_key_path: tls_files.client_key_path,
2113
+ client_cert_path: tls_files.client_cert_path
2114
+ };
2115
+ }
2116
+ assertOpenSslAvailable() {
2117
+ try {
2118
+ execFileSync("openssl", [
2119
+ "version"
2120
+ ], {
2121
+ stdio: "ignore"
2122
+ });
2123
+ } catch {
2124
+ throw new Error("openssl command is required but was not found. Please install openssl and retry.");
2125
+ }
2126
+ }
2127
+ buildTlsFileMap(params) {
2128
+ return {
2129
+ ca_key_path: path2.join(params.output_dir, "ca.key.pem"),
2130
+ ca_cert_path: path2.join(params.output_dir, "ca.cert.pem"),
2131
+ server_key_path: path2.join(params.output_dir, "server.key.pem"),
2132
+ server_csr_path: path2.join(params.output_dir, "server.csr.pem"),
2133
+ server_cert_path: path2.join(params.output_dir, "server.cert.pem"),
2134
+ server_ext_path: path2.join(params.output_dir, "server.ext"),
2135
+ client_key_path: path2.join(params.output_dir, "client.key.pem"),
2136
+ client_csr_path: path2.join(params.output_dir, "client.csr.pem"),
2137
+ client_cert_path: path2.join(params.output_dir, "client.cert.pem"),
2138
+ client_ext_path: path2.join(params.output_dir, "client.ext"),
2139
+ ca_serial_path: path2.join(params.output_dir, "ca.cert.srl")
2140
+ };
2141
+ }
2142
+ assertTargetFilesAreWritable(params) {
2143
+ const target_paths = [
2144
+ params.tls_files.ca_key_path,
2145
+ params.tls_files.ca_cert_path,
2146
+ params.tls_files.server_key_path,
2147
+ params.tls_files.server_cert_path,
2148
+ params.tls_files.client_key_path,
2149
+ params.tls_files.client_cert_path
2150
+ ];
2151
+ if (!params.overwrite) {
2152
+ for (const target_path of target_paths) {
2153
+ if (fs2.existsSync(target_path)) {
2154
+ throw new Error(`Refusing to overwrite existing file "${target_path}". Use --tls-overwrite to replace existing material.`);
2155
+ }
2156
+ }
2157
+ return;
2158
+ }
2159
+ for (const target_path of target_paths) {
2160
+ fs2.rmSync(target_path, {
2161
+ force: true
2162
+ });
2163
+ }
2164
+ fs2.rmSync(params.tls_files.ca_serial_path, {
2165
+ force: true
2166
+ });
2167
+ }
2168
+ generateCa(params) {
2169
+ this.runOpenSslCommand({
2170
+ args: [
2171
+ "req",
2172
+ "-x509",
2173
+ "-newkey",
2174
+ "rsa:4096",
2175
+ "-sha256",
2176
+ "-nodes",
2177
+ "-keyout",
2178
+ params.tls_files.ca_key_path,
2179
+ "-out",
2180
+ params.tls_files.ca_cert_path,
2181
+ "-days",
2182
+ String(params.valid_days),
2183
+ "-subj",
2184
+ `/CN=${params.ca_common_name}`
2185
+ ]
2186
+ });
2187
+ }
2188
+ generateServerCertificate(params) {
2189
+ WriteTextFile({
2190
+ file_path: params.tls_files.server_ext_path,
2191
+ content: [
2192
+ "subjectAltName=DNS:localhost,IP:127.0.0.1",
2193
+ "extendedKeyUsage=serverAuth",
2194
+ "keyUsage=digitalSignature,keyEncipherment"
2195
+ ].join("\n")
2196
+ });
2197
+ this.runOpenSslCommand({
2198
+ args: [
2199
+ "req",
2200
+ "-new",
2201
+ "-newkey",
2202
+ "rsa:4096",
2203
+ "-sha256",
2204
+ "-nodes",
2205
+ "-keyout",
2206
+ params.tls_files.server_key_path,
2207
+ "-out",
2208
+ params.tls_files.server_csr_path,
2209
+ "-subj",
2210
+ `/CN=${params.server_common_name}`
2211
+ ]
2212
+ });
2213
+ this.runOpenSslCommand({
2214
+ args: [
2215
+ "x509",
2216
+ "-req",
2217
+ "-in",
2218
+ params.tls_files.server_csr_path,
2219
+ "-CA",
2220
+ params.tls_files.ca_cert_path,
2221
+ "-CAkey",
2222
+ params.tls_files.ca_key_path,
2223
+ "-CAserial",
2224
+ params.tls_files.ca_serial_path,
2225
+ "-CAcreateserial",
2226
+ "-out",
2227
+ params.tls_files.server_cert_path,
2228
+ "-days",
2229
+ String(params.valid_days),
2230
+ "-sha256",
2231
+ "-extfile",
2232
+ params.tls_files.server_ext_path
2233
+ ]
2234
+ });
2235
+ }
2236
+ generateClientCertificate(params) {
2237
+ const client_uri = `spiffe://nodenetproccalld/${params.client_common_name.replace(/[^a-zA-Z0-9_.-]/g, "_").toLowerCase()}`;
2238
+ WriteTextFile({
2239
+ file_path: params.tls_files.client_ext_path,
2240
+ content: [
2241
+ "extendedKeyUsage=clientAuth",
2242
+ "keyUsage=digitalSignature,keyEncipherment",
2243
+ `subjectAltName=URI:${client_uri}`
2244
+ ].join("\n")
2245
+ });
2246
+ this.runOpenSslCommand({
2247
+ args: [
2248
+ "req",
2249
+ "-new",
2250
+ "-newkey",
2251
+ "rsa:4096",
2252
+ "-sha256",
2253
+ "-nodes",
2254
+ "-keyout",
2255
+ params.tls_files.client_key_path,
2256
+ "-out",
2257
+ params.tls_files.client_csr_path,
2258
+ "-subj",
2259
+ `/CN=${params.client_common_name}`
2260
+ ]
2261
+ });
2262
+ this.runOpenSslCommand({
2263
+ args: [
2264
+ "x509",
2265
+ "-req",
2266
+ "-in",
2267
+ params.tls_files.client_csr_path,
2268
+ "-CA",
2269
+ params.tls_files.ca_cert_path,
2270
+ "-CAkey",
2271
+ params.tls_files.ca_key_path,
2272
+ "-CAserial",
2273
+ params.tls_files.ca_serial_path,
2274
+ "-out",
2275
+ params.tls_files.client_cert_path,
2276
+ "-days",
2277
+ String(params.valid_days),
2278
+ "-sha256",
2279
+ "-extfile",
2280
+ params.tls_files.client_ext_path
2281
+ ]
2282
+ });
2283
+ }
2284
+ cleanupIntermediateFiles(params) {
2285
+ fs2.rmSync(params.tls_files.server_csr_path, {
2286
+ force: true
2287
+ });
2288
+ fs2.rmSync(params.tls_files.client_csr_path, {
2289
+ force: true
2290
+ });
2291
+ fs2.rmSync(params.tls_files.server_ext_path, {
2292
+ force: true
2293
+ });
2294
+ fs2.rmSync(params.tls_files.client_ext_path, {
2295
+ force: true
2296
+ });
2297
+ fs2.rmSync(params.tls_files.ca_serial_path, {
2298
+ force: true
2299
+ });
2300
+ }
2301
+ runOpenSslCommand(params) {
2302
+ execFileSync("openssl", params.args, {
2303
+ stdio: "ignore"
2304
+ });
2305
+ }
2306
+ getErrorMessage(params) {
2307
+ if (params.error instanceof Error) {
2308
+ return params.error.message;
2309
+ }
2310
+ return String(params.error);
2311
+ }
2312
+ };
2313
+ __name(_TlsMaterialGenerator, "TlsMaterialGenerator");
2314
+ var TlsMaterialGenerator = _TlsMaterialGenerator;
2315
+
2316
+ // src/index.ts
2317
+ async function StartDaemonFromCli() {
2318
+ const daemon_cli = new DaemonCli();
2319
+ const cli_options = daemon_cli.parseOptions();
2320
+ if (cli_options.help) {
2321
+ daemon_cli.printHelp();
2322
+ return;
2323
+ }
2324
+ if (cli_options.tls_generation.enabled) {
2325
+ const tls_material_generator = new TlsMaterialGenerator();
2326
+ const generated_tls_material = tls_material_generator.generateTlsMaterial({
2327
+ tls_generation_options: cli_options.tls_generation
2328
+ });
2329
+ console.log("TLS material generated successfully.");
2330
+ console.log(`Output directory: ${generated_tls_material.output_dir}`);
2331
+ console.log(`CA cert: ${generated_tls_material.ca_cert_path}`);
2332
+ console.log(`Server cert: ${generated_tls_material.server_cert_path}`);
2333
+ console.log(`Server key: ${generated_tls_material.server_key_path}`);
2334
+ console.log(`Client cert: ${generated_tls_material.client_cert_path}`);
2335
+ console.log(`Client key: ${generated_tls_material.client_key_path}`);
2336
+ console.log("");
2337
+ console.log("If using default config, set tls_mtls key_file/cert_file/ca_file in config/server.config.json5 to these files.");
2338
+ return;
2339
+ }
2340
+ const daemon_process = new DaemonProcess({
2341
+ config_paths: {
2342
+ server_config_path: cli_options.server_config_path,
2343
+ api_keys_config_path: cli_options.api_keys_config_path
2344
+ }
2345
+ });
2346
+ await daemon_process.run();
2347
+ }
2348
+ __name(StartDaemonFromCli, "StartDaemonFromCli");
2349
+ if (__require.main === module) {
2350
+ void StartDaemonFromCli().catch((error) => {
2351
+ const error_message = error instanceof Error ? error.stack ?? error.message : String(error);
2352
+ console.error(`Daemon startup failed: ${error_message}`);
2353
+ process.exitCode = 1;
2354
+ });
2355
+ }
2356
+ export {
2357
+ ApiKeyAuthorizer,
2358
+ ConfigFileLoader,
2359
+ ConfigValidator,
2360
+ DaemonCli,
2361
+ DaemonProcess,
2362
+ NetworkProcedureCallDaemon,
2363
+ TlsMaterialGenerator
2364
+ };
2365
+ //# sourceMappingURL=index.mjs.map