@codemem/mcp 0.43.2 → 0.44.0-alpha.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/http.js CHANGED
@@ -1,53 +1,223 @@
1
1
  #!/usr/bin/env node
2
- import { n as e, t } from "./server-Kv95NnLs.js";
2
+ import { n as e, t } from "./server-C8Yl-9J0.js";
3
3
  import { createHash as n, createHmac as r, createPublicKey as i, randomBytes as a, randomUUID as o, timingSafeEqual as s, verify as c } from "node:crypto";
4
4
  import { createServer as l } from "node:http";
5
5
  import { isIP as u, isIPv6 as d } from "node:net";
6
6
  import { pathToFileURL as f } from "node:url";
7
7
  import { MemoryStore as p, resolveDbPath as m } from "@codemem/core";
8
8
  import { requireBearerAuth as h } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
9
- import { createOAuthMetadata as g, getOAuthProtectedResourceMetadataUrl as ee, mcpAuthRouter as te } from "@modelcontextprotocol/sdk/server/auth/router.js";
10
- import { StreamableHTTPServerTransport as ne } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
11
- import re from "express";
12
- import { Buffer as _ } from "node:buffer";
13
- import { existsSync as v, mkdirSync as y, readFileSync as ie, renameSync as b, writeFileSync as x } from "node:fs";
14
- import { chmod as S } from "node:fs/promises";
15
- import { homedir as C } from "node:os";
16
- import { dirname as w, join as T } from "node:path";
17
- import { AccessDeniedError as E, InvalidClientError as ae, InvalidClientMetadataError as D, InvalidGrantError as O, InvalidRequestError as oe, InvalidTokenError as se, ServerError as ce, TemporarilyUnavailableError as k, UnsupportedResponseTypeError as le } from "@modelcontextprotocol/sdk/server/auth/errors.js";
18
- import { OAuthProtectedResourceMetadataSchema as ue, OAuthTokensSchema as de } from "@modelcontextprotocol/sdk/shared/auth.js";
9
+ import { createOAuthMetadata as g, getOAuthProtectedResourceMetadataUrl as _, mcpAuthRouter as v } from "@modelcontextprotocol/sdk/server/auth/router.js";
10
+ import { StreamableHTTPServerTransport as y } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
11
+ import b from "express";
12
+ import { Buffer as x } from "node:buffer";
13
+ import { existsSync as S, mkdirSync as C, readFileSync as ee, renameSync as w, writeFileSync as T } from "node:fs";
14
+ import { chmod as E } from "node:fs/promises";
15
+ import { homedir as D } from "node:os";
16
+ import { dirname as O, join as k } from "node:path";
17
+ import { AccessDeniedError as A, InvalidClientError as te, InvalidClientMetadataError as j, InvalidGrantError as M, InvalidRequestError as ne, InvalidTokenError as re, ServerError as ie, TemporarilyUnavailableError as N, UnsupportedResponseTypeError as ae } from "@modelcontextprotocol/sdk/server/auth/errors.js";
18
+ import { OAuthProtectedResourceMetadataSchema as oe, OAuthTokensSchema as se } from "@modelcontextprotocol/sdk/shared/auth.js";
19
19
  //#region \0rolldown/runtime.js
20
- var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), j = /* @__PURE__ */ A(((e) => {
21
- Object.defineProperty(e, "__esModule", { value: !0 }), e.isInSubnet = t, e.isCorrect = n, e.numberToPaddedHex = r, e.stringToPaddedHex = i, e.testBit = a;
22
- function t(e) {
23
- return this.subnetMask < e.subnetMask ? !1 : this.mask(e.subnetMask) === e.mask();
24
- }
20
+ var ce = Object.create, le = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, de = Object.getOwnPropertyNames, fe = Object.getPrototypeOf, pe = Object.prototype.hasOwnProperty, P = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), me = (e, t, n, r) => {
21
+ if (t && typeof t == "object" || typeof t == "function") for (var i = de(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !pe.call(e, s) && s !== n && le(e, s, {
22
+ get: ((e) => t[e]).bind(null, s),
23
+ enumerable: !(r = ue(t, s)) || r.enumerable
24
+ });
25
+ return e;
26
+ }, he = (e, t, n) => (n = e == null ? {} : ce(fe(e)), me(t || !e || !e.__esModule || !pe.call(e, "default") ? le(n, "default", {
27
+ value: e,
28
+ enumerable: !0
29
+ }) : n, e)), F = /* @__PURE__ */ P(((e) => {
30
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.AddressError = void 0, e.AddressError = class extends Error {
31
+ constructor(e, t) {
32
+ super(e), this.name = "AddressError", this.parseMessage = t;
33
+ }
34
+ };
35
+ })), ge = /* @__PURE__ */ P(((e) => {
36
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.isInSubnet = n, e.isHostInSubnet = r, e.isGloballyReachable = i, e.offsetBigInt = a, e.isCorrect = o, e.prefixLengthFromMask = s, e.assertByteArray = c, e.numberToPaddedHex = l, e.stringToPaddedHex = u, e.testBit = d;
37
+ var t = F();
25
38
  function n(e) {
39
+ return this.subnetMask < e.subnetMask ? !1 : r.call(this, e);
40
+ }
41
+ function r(e) {
42
+ return this.mask(e.subnetMask) === e.mask();
43
+ }
44
+ function i(e) {
45
+ let t = null;
46
+ for (let n = 0; n < e.length; n++) {
47
+ let i = e[n];
48
+ i.reachable !== null && r.call(this, i.subnet) && (t === null || i.subnet.subnetMask > t.subnet.subnetMask) && (t = i);
49
+ }
50
+ return t === null || t.reachable;
51
+ }
52
+ function a(e, n, r, i) {
53
+ if (typeof n == "number" && !Number.isSafeInteger(n) || typeof n != "number" && typeof n != "bigint") throw new t.AddressError(`${i} offset must be an integer`);
54
+ let a = e + BigInt(n);
55
+ if (a < BigInt(0) || a > (BigInt(1) << BigInt(r)) - BigInt(1)) throw new t.AddressError(`${i} offset leaves the address space`);
56
+ return a;
57
+ }
58
+ function o(e) {
26
59
  return function() {
27
- return this.addressMinusSuffix === this.correctForm() ? this.subnetMask === e && !this.parsedSubnet ? !0 : this.parsedSubnet === String(this.subnetMask) : !1;
60
+ return this.addressMinusSuffix === this.correctForm() ? this.subnetMask === e && !this.parsedSubnet || this.parsedSubnet === String(this.subnetMask) : !1;
28
61
  };
29
62
  }
30
- function r(e) {
63
+ function s(e, n) {
64
+ let r = e.toString(2).padStart(n, "0");
65
+ if (r.length > n) throw new t.AddressError("Invalid subnet mask.");
66
+ let i = r.indexOf("0");
67
+ if (i === -1) return n;
68
+ if (r.slice(i).includes("1")) throw new t.AddressError("Invalid subnet mask.");
69
+ return i;
70
+ }
71
+ function c(e, n, r, i) {
72
+ if (e.length !== n) throw new t.AddressError(`${r} addresses require exactly ${n} bytes`);
73
+ for (let n = 0; n < e.length; n++) if (!Number.isInteger(e[n]) || e[n] < i || e[n] > 255) throw new t.AddressError(`All bytes must be integers between ${i} and 255`);
74
+ }
75
+ function l(e) {
31
76
  return e.toString(16).padStart(2, "0");
32
77
  }
33
- function i(e) {
34
- return r(parseInt(e, 10));
78
+ function u(e) {
79
+ return l(parseInt(e, 10));
35
80
  }
36
- function a(e, t) {
81
+ function d(e, t) {
37
82
  let { length: n } = e;
38
83
  if (t > n) return !1;
39
84
  let r = n - t;
40
85
  return e.substring(r, r + 1) === "1";
41
86
  }
42
- })), fe = /* @__PURE__ */ A(((e) => {
43
- Object.defineProperty(e, "__esModule", { value: !0 }), e.RE_SUBNET_STRING = e.RE_ADDRESS = e.GROUPS = e.BITS = void 0, e.BITS = 32, e.GROUPS = 4, e.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g, e.RE_SUBNET_STRING = /\/\d{1,2}$/;
44
- })), pe = /* @__PURE__ */ A(((e) => {
45
- Object.defineProperty(e, "__esModule", { value: !0 }), e.AddressError = void 0, e.AddressError = class extends Error {
46
- constructor(e, t) {
47
- super(e), this.name = "AddressError", this.parseMessage = t;
48
- }
49
- };
50
- })), me = /* @__PURE__ */ A(((e) => {
87
+ })), _e = /* @__PURE__ */ P(((e) => {
88
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.SPECIAL_PURPOSE = e.RE_SUBNET_STRING = e.RE_ADDRESS = e.GROUPS = e.BITS = void 0, e.BITS = 32, e.GROUPS = 4, e.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/g, e.RE_SUBNET_STRING = /\/\d{1,2}$/, e.SPECIAL_PURPOSE = [
89
+ [
90
+ "0.0.0.0/8",
91
+ "This network",
92
+ !1
93
+ ],
94
+ [
95
+ "0.0.0.0/32",
96
+ "This host on this network",
97
+ !1
98
+ ],
99
+ [
100
+ "10.0.0.0/8",
101
+ "Private-Use",
102
+ !1
103
+ ],
104
+ [
105
+ "100.64.0.0/10",
106
+ "Shared Address Space",
107
+ !1
108
+ ],
109
+ [
110
+ "127.0.0.0/8",
111
+ "Loopback",
112
+ !1
113
+ ],
114
+ [
115
+ "169.254.0.0/16",
116
+ "Link Local",
117
+ !1
118
+ ],
119
+ [
120
+ "172.16.0.0/12",
121
+ "Private-Use",
122
+ !1
123
+ ],
124
+ [
125
+ "192.0.0.0/24",
126
+ "IETF Protocol Assignments",
127
+ !1
128
+ ],
129
+ [
130
+ "192.0.0.0/29",
131
+ "IPv4 Service Continuity Prefix",
132
+ !1
133
+ ],
134
+ [
135
+ "192.0.0.8/32",
136
+ "IPv4 dummy address",
137
+ !1
138
+ ],
139
+ [
140
+ "192.0.0.9/32",
141
+ "Port Control Protocol Anycast",
142
+ !0
143
+ ],
144
+ [
145
+ "192.0.0.10/32",
146
+ "Traversal Using Relays around NAT Anycast",
147
+ !0
148
+ ],
149
+ [
150
+ "192.0.0.170/32",
151
+ "NAT64/DNS64 Discovery",
152
+ !1
153
+ ],
154
+ [
155
+ "192.0.0.171/32",
156
+ "NAT64/DNS64 Discovery",
157
+ !1
158
+ ],
159
+ [
160
+ "192.0.2.0/24",
161
+ "Documentation (TEST-NET-1)",
162
+ !1
163
+ ],
164
+ [
165
+ "192.31.196.0/24",
166
+ "AS112-v4",
167
+ !0
168
+ ],
169
+ [
170
+ "192.52.193.0/24",
171
+ "AMT",
172
+ !0
173
+ ],
174
+ [
175
+ "192.88.99.0/24",
176
+ "Deprecated (6to4 Relay Anycast)",
177
+ null
178
+ ],
179
+ [
180
+ "192.88.99.2/32",
181
+ "6a44-relay anycast address",
182
+ !1
183
+ ],
184
+ [
185
+ "192.168.0.0/16",
186
+ "Private-Use",
187
+ !1
188
+ ],
189
+ [
190
+ "192.175.48.0/24",
191
+ "Direct Delegation AS112 Service",
192
+ !0
193
+ ],
194
+ [
195
+ "198.18.0.0/15",
196
+ "Benchmarking",
197
+ !1
198
+ ],
199
+ [
200
+ "198.51.100.0/24",
201
+ "Documentation (TEST-NET-2)",
202
+ !1
203
+ ],
204
+ [
205
+ "203.0.113.0/24",
206
+ "Documentation (TEST-NET-3)",
207
+ !1
208
+ ],
209
+ [
210
+ "240.0.0.0/4",
211
+ "Reserved",
212
+ !1
213
+ ],
214
+ [
215
+ "255.255.255.255/32",
216
+ "Limited Broadcast",
217
+ !1
218
+ ]
219
+ ];
220
+ })), ve = /* @__PURE__ */ P(((e) => {
51
221
  var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
52
222
  r === void 0 && (r = n);
53
223
  var i = Object.getOwnPropertyDescriptor(t, n);
@@ -73,10 +243,9 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
73
243
  return n(r, e), r;
74
244
  };
75
245
  Object.defineProperty(e, "__esModule", { value: !0 }), e.Address4 = void 0;
76
- var i = r(j()), a = r(fe()), o = pe();
77
- e.Address4 = class e {
246
+ var i = r(ge()), a = r(_e()), o = F(), s = i.isCorrect(a.BITS), c = class e {
78
247
  constructor(e) {
79
- this.groups = a.GROUPS, this.parsedAddress = [], this.parsedSubnet = "", this.subnet = "/32", this.subnetMask = 32, this.v4 = !0, this.isCorrect = i.isCorrect(a.BITS), this.isInSubnet = i.isInSubnet, this.address = e;
248
+ this.addressMinusSuffix = "", this.groups = a.GROUPS, this.parsedAddress = [], this.parsedSubnet = "", this.subnet = "/32", this.subnetMask = 32, this.v4 = !0, this.isCorrect = s, this.isInSubnet = i.isInSubnet, this.isHostInSubnet = i.isHostInSubnet, this.address = e;
80
249
  let t = a.RE_SUBNET_STRING.exec(e);
81
250
  if (t) {
82
251
  if (this.parsedSubnet = t[0].replace("/", ""), this.subnetMask = parseInt(this.parsedSubnet, 10), this.subnet = `/${this.subnetMask}`, this.subnetMask < 0 || this.subnetMask > a.BITS) throw new o.AddressError("Invalid subnet mask.");
@@ -93,25 +262,44 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
93
262
  }
94
263
  parse(e) {
95
264
  let t = e.split(".");
265
+ if (t.some((e) => /^0\d/.test(e))) throw new o.AddressError("IPv4 addresses can't have leading zeroes.");
96
266
  if (!e.match(a.RE_ADDRESS)) throw new o.AddressError("Invalid IPv4 address.");
97
267
  return t;
98
268
  }
99
269
  correctForm() {
100
270
  return this.parsedAddress.map((e) => parseInt(e, 10)).join(".");
101
271
  }
272
+ static fromAddressAndMask(t, n) {
273
+ let r = i.prefixLengthFromMask(new e(n).bigInt(), a.BITS);
274
+ return new e(`${t}/${r}`);
275
+ }
276
+ static fromAddressAndWildcardMask(t, n) {
277
+ let r = new e(n).bigInt() ^ (BigInt(1) << BigInt(a.BITS)) - BigInt(1), o = i.prefixLengthFromMask(r, a.BITS);
278
+ return new e(`${t}/${o}`);
279
+ }
280
+ static fromWildcard(t) {
281
+ let n = t.split(".");
282
+ if (n.length !== a.GROUPS) throw new o.AddressError("Wildcard pattern must have 4 octets");
283
+ let r = -1;
284
+ for (let e = 0; e < n.length; e++) if (n[e] === "*") r === -1 && (r = e);
285
+ else if (r !== -1) throw new o.AddressError("Wildcard `*` must only appear in trailing octets (e.g. `192.168.0.*`)");
286
+ let i = r === -1 ? 0 : n.length - r, s = n.map((e) => e === "*" ? "0" : e), c = a.BITS - i * 8;
287
+ return new e(`${s.join(".")}/${c}`);
288
+ }
102
289
  static fromHex(t) {
103
- let n = t.replace(/:/g, "").padStart(8, "0"), r = [], i;
104
- for (i = 0; i < 8; i += 2) {
105
- let e = n.slice(i, i + 2);
106
- r.push(parseInt(e, 16));
107
- }
290
+ let n = t.replace(/:/g, "");
291
+ if (!/^[0-9a-fA-F]{8}$/.test(n)) throw new o.AddressError("IPv4 hex must be exactly 8 hex digits");
292
+ let r = [];
293
+ for (let e = 0; e < 8; e += 2) r.push(parseInt(n.slice(e, e + 2), 16));
108
294
  return new e(r.join("."));
109
295
  }
110
296
  static fromInteger(t) {
111
- return e.fromHex(t.toString(16));
297
+ if (!Number.isInteger(t) || t < 0 || t > 4294967295) throw new o.AddressError("IPv4 integer must be in the range 0 to 2**32 - 1");
298
+ return e.fromHex(t.toString(16).padStart(8, "0"));
112
299
  }
113
300
  static fromArpa(t) {
114
- return new e(t.replace(/(\.in-addr\.arpa)?\.$/, "").split(".").reverse().join("."));
301
+ let n = t.replace(/(\.in-addr\.arpa)?\.$/, "").split(".").reverse().join(".");
302
+ return new e(n);
115
303
  }
116
304
  toHex() {
117
305
  return this.parsedAddress.map((e) => i.stringToPaddedHex(e)).join(":");
@@ -137,6 +325,15 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
137
325
  let t = BigInt("1");
138
326
  return e.fromBigInt(this._startAddress() + t);
139
327
  }
328
+ offset(t) {
329
+ return e.fromBigInt(i.offsetBigInt(this.bigInt(), t, a.BITS, "IPv4")).withSubnetMask(this.subnetMask);
330
+ }
331
+ nextNetwork() {
332
+ return e.fromBigInt(i.offsetBigInt(this._endAddress(), 1, a.BITS, "IPv4")).withSubnetMask(this.subnetMask);
333
+ }
334
+ withSubnetMask(t) {
335
+ return new e(`${this.correctForm()}/${t}`);
336
+ }
140
337
  _endAddress() {
141
338
  return BigInt(`0b${this.mask() + "1".repeat(a.BITS - this.subnetMask)}`);
142
339
  }
@@ -147,17 +344,26 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
147
344
  let t = BigInt("1");
148
345
  return e.fromBigInt(this._endAddress() - t);
149
346
  }
347
+ subnetMaskAddress() {
348
+ return e.fromBigInt(BigInt(`0b${"1".repeat(this.subnetMask)}${"0".repeat(a.BITS - this.subnetMask)}`));
349
+ }
350
+ wildcardMask() {
351
+ return e.fromBigInt(BigInt(`0b${"0".repeat(this.subnetMask)}${"1".repeat(a.BITS - this.subnetMask)}`));
352
+ }
353
+ networkForm() {
354
+ return `${this.startAddress().correctForm()}/${this.subnetMask}`;
355
+ }
150
356
  static fromBigInt(t) {
151
- return e.fromHex(t.toString(16));
357
+ if (t < BigInt(0) || t > BigInt(4294967295)) throw new o.AddressError("IPv4 BigInt must be in the range 0 to 2**32 - 1");
358
+ return e.fromHex(t.toString(16).padStart(8, "0"));
152
359
  }
153
360
  static fromByteArray(e) {
154
- if (e.length !== 4) throw new o.AddressError("IPv4 addresses require exactly 4 bytes");
155
- for (let t = 0; t < e.length; t++) if (!Number.isInteger(e[t]) || e[t] < 0 || e[t] > 255) throw new o.AddressError("All bytes must be integers between 0 and 255");
156
- return this.fromUnsignedByteArray(e);
361
+ return i.assertByteArray(e, 4, "IPv4", 0), this.fromUnsignedByteArray(e);
157
362
  }
158
363
  static fromUnsignedByteArray(t) {
159
364
  if (t.length !== 4) throw new o.AddressError("IPv4 addresses require exactly 4 bytes");
160
- return new e(t.join("."));
365
+ let n = t.join(".");
366
+ return new e(n);
161
367
  }
162
368
  mask(e) {
163
369
  return e === void 0 && (e = this.subnetMask), this.getBitsBase2(0, e);
@@ -171,18 +377,61 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
171
377
  return e.omitSuffix ? t : `${t}.in-addr.arpa.`;
172
378
  }
173
379
  isMulticast() {
174
- return this.isInSubnet(new e("224.0.0.0/4"));
380
+ return this.isHostInSubnet(l);
381
+ }
382
+ isPrivate() {
383
+ return u.some((e) => this.isHostInSubnet(e));
384
+ }
385
+ isLoopback() {
386
+ return this.isHostInSubnet(d);
387
+ }
388
+ isLinkLocal() {
389
+ return this.isHostInSubnet(f);
390
+ }
391
+ isUnspecified() {
392
+ return this.isHostInSubnet(p);
393
+ }
394
+ isBroadcast() {
395
+ return this.isHostInSubnet(m);
396
+ }
397
+ isCGNAT() {
398
+ return this.isHostInSubnet(h);
399
+ }
400
+ isDocumentation() {
401
+ return g.some((e) => this.isHostInSubnet(e));
402
+ }
403
+ isBenchmarking() {
404
+ return this.isHostInSubnet(_);
405
+ }
406
+ isReserved() {
407
+ return this.isHostInSubnet(v);
408
+ }
409
+ isGlobal() {
410
+ return !this.isMulticast() && i.isGloballyReachable.call(this, y);
175
411
  }
176
412
  binaryZeroPad() {
177
- return this.bigInt().toString(2).padStart(a.BITS, "0");
413
+ return this._binaryZeroPad === void 0 && (this._binaryZeroPad = this.bigInt().toString(2).padStart(a.BITS, "0")), this._binaryZeroPad;
178
414
  }
179
415
  groupForV6() {
180
416
  let e = this.parsedAddress;
181
- return this.address.replace(a.RE_ADDRESS, `<span class="hover-group group-v4 group-6">${e.slice(0, 2).join(".")}</span>.<span class="hover-group group-v4 group-7">${e.slice(2, 4).join(".")}</span>`);
417
+ return this.correctForm().replace(a.RE_ADDRESS, `<span class="hover-group group-v4 group-6">${e.slice(0, 2).join(".")}</span>.<span class="hover-group group-v4 group-7">${e.slice(2, 4).join(".")}</span>`);
182
418
  }
183
419
  };
184
- })), he = /* @__PURE__ */ A(((e) => {
185
- Object.defineProperty(e, "__esModule", { value: !0 }), e.RE_URL_WITH_PORT = e.RE_URL = e.RE_ZONE_STRING = e.RE_SUBNET_STRING = e.RE_BAD_ADDRESS = e.RE_BAD_CHARACTERS = e.TYPES = e.SCOPES = e.GROUPS = e.BITS = void 0, e.BITS = 128, e.GROUPS = 8, e.SCOPES = {
420
+ e.Address4 = c;
421
+ var l = new c("224.0.0.0/4"), u = [
422
+ new c("10.0.0.0/8"),
423
+ new c("172.16.0.0/12"),
424
+ new c("192.168.0.0/16")
425
+ ], d = new c("127.0.0.0/8"), f = new c("169.254.0.0/16"), p = new c("0.0.0.0/32"), m = new c("255.255.255.255/32"), h = new c("100.64.0.0/10"), g = [
426
+ new c("192.0.2.0/24"),
427
+ new c("198.51.100.0/24"),
428
+ new c("203.0.113.0/24")
429
+ ], _ = new c("198.18.0.0/15"), v = new c("240.0.0.0/4"), y = a.SPECIAL_PURPOSE.map(([e, , t]) => ({
430
+ subnet: new c(e),
431
+ reachable: t
432
+ }));
433
+ })), ye = /* @__PURE__ */ P(((e) => {
434
+ Object.defineProperty(e, "__esModule", { value: !0 }), e.SPECIAL_PURPOSE = e.RE_URL_WITH_PORT = e.RE_URL = e.RE_ZONE_STRING = e.RE_SUBNET_STRING = e.RE_BAD_ADDRESS = e.RE_BAD_CHARACTERS = e.TYPES = e.SCOPES = e.GROUPS = e.BITS = void 0, e.BITS = 128, e.GROUPS = 8, e.SCOPES = {
186
435
  0: "Reserved",
187
436
  1: "Interface local",
188
437
  2: "Link local",
@@ -212,10 +461,148 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
212
461
  "ff05::1:3/128": "Multicast (All DHCP servers in this site)",
213
462
  "::/128": "Unspecified",
214
463
  "::1/128": "Loopback",
464
+ "::ffff:0:0/96": "IPv4-mapped",
215
465
  "ff00::/8": "Multicast",
216
- "fe80::/10": "Link-local unicast"
217
- }, e.RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi, e.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi, e.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/, e.RE_ZONE_STRING = /%.*$/, e.RE_URL = /^\[{0,1}([0-9a-f:]+)\]{0,1}/, e.RE_URL_WITH_PORT = /\[([0-9a-f:]+)\]:([0-9]{1,5})/;
218
- })), ge = /* @__PURE__ */ A(((e) => {
466
+ "fe80::/10": "Link-local unicast",
467
+ "fc00::/7": "Unique local",
468
+ "2001::/32": "Teredo",
469
+ "2001:2::/48": "Benchmarking",
470
+ "2002::/16": "6to4",
471
+ "2001:db8::/32": "Documentation",
472
+ "3fff::/20": "Documentation",
473
+ "100::/64": "Discard-only",
474
+ "fec0::/10": "Site-local unicast (deprecated)",
475
+ "::/96": "IPv4-compatible (deprecated)",
476
+ "64:ff9b::/96": "NAT64 (well-known)",
477
+ "64:ff9b:1::/48": "NAT64 (local-use)"
478
+ }, e.RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi, e.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi, e.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/, e.RE_ZONE_STRING = /%.*$/, e.RE_URL = /^(?:\[([0-9a-f:.]+)\]|([0-9a-f:.]+))(?:[/?#].*)?$/i, e.RE_URL_WITH_PORT = /^\[([0-9a-f:.]+)\]:([0-9]{1,5})(?:[/?#].*)?$/i, e.SPECIAL_PURPOSE = [
479
+ [
480
+ "::1/128",
481
+ "Loopback Address",
482
+ !1
483
+ ],
484
+ [
485
+ "::/128",
486
+ "Unspecified Address",
487
+ !1
488
+ ],
489
+ [
490
+ "::ffff:0:0/96",
491
+ "IPv4-mapped Address",
492
+ !1
493
+ ],
494
+ [
495
+ "64:ff9b::/96",
496
+ "IPv4-IPv6 Translat.",
497
+ !0
498
+ ],
499
+ [
500
+ "64:ff9b:1::/48",
501
+ "IPv4-IPv6 Translat.",
502
+ !1
503
+ ],
504
+ [
505
+ "100::/64",
506
+ "Discard-Only Address Block",
507
+ !1
508
+ ],
509
+ [
510
+ "100:0:0:1::/64",
511
+ "Dummy IPv6 Prefix",
512
+ !1
513
+ ],
514
+ [
515
+ "2001::/23",
516
+ "IETF Protocol Assignments",
517
+ !1
518
+ ],
519
+ [
520
+ "2001::/32",
521
+ "TEREDO",
522
+ !1
523
+ ],
524
+ [
525
+ "2001:1::1/128",
526
+ "Port Control Protocol Anycast",
527
+ !0
528
+ ],
529
+ [
530
+ "2001:1::2/128",
531
+ "Traversal Using Relays around NAT Anycast",
532
+ !0
533
+ ],
534
+ [
535
+ "2001:1::3/128",
536
+ "DNS-SD Service Registration Protocol Anycast",
537
+ !0
538
+ ],
539
+ [
540
+ "2001:2::/48",
541
+ "Benchmarking",
542
+ !1
543
+ ],
544
+ [
545
+ "2001:3::/32",
546
+ "AMT",
547
+ !0
548
+ ],
549
+ [
550
+ "2001:4:112::/48",
551
+ "AS112-v6",
552
+ !0
553
+ ],
554
+ [
555
+ "2001:10::/28",
556
+ "Deprecated (previously ORCHID)",
557
+ null
558
+ ],
559
+ [
560
+ "2001:20::/28",
561
+ "ORCHIDv2",
562
+ !0
563
+ ],
564
+ [
565
+ "2001:30::/28",
566
+ "Drone Remote ID Protocol Entity Tags (DETs) Prefix",
567
+ !0
568
+ ],
569
+ [
570
+ "2001:db8::/32",
571
+ "Documentation",
572
+ !1
573
+ ],
574
+ [
575
+ "2002::/16",
576
+ "6to4",
577
+ !1
578
+ ],
579
+ [
580
+ "2620:4f:8000::/48",
581
+ "Direct Delegation AS112 Service",
582
+ !0
583
+ ],
584
+ [
585
+ "3fff::/20",
586
+ "Documentation",
587
+ !1
588
+ ],
589
+ [
590
+ "5f00::/16",
591
+ "Segment Routing (SRv6) SIDs",
592
+ !1
593
+ ],
594
+ [
595
+ "fc00::/7",
596
+ "Unique-Local",
597
+ !1
598
+ ],
599
+ [
600
+ "fe80::/10",
601
+ "Link-Local Unicast",
602
+ !1
603
+ ]
604
+ ];
605
+ })), be = /* @__PURE__ */ P(((e) => {
219
606
  Object.defineProperty(e, "__esModule", { value: !0 }), e.escapeHtml = t, e.spanAllZeroes = n, e.spanAll = r, e.spanLeadingZeroes = a, e.simpleGroup = o;
220
607
  function t(e) {
221
608
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
@@ -235,7 +622,7 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
235
622
  function o(e, t = 0) {
236
623
  return e.split(":").map((e, n) => /group-v4/.test(e) ? e : `<span class="hover-group group-${n + t}">${i(e)}</span>`);
237
624
  }
238
- })), _e = /* @__PURE__ */ A(((e) => {
625
+ })), xe = /* @__PURE__ */ P(((e) => {
239
626
  var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
240
627
  r === void 0 && (r = n);
241
628
  var i = Object.getOwnPropertyDescriptor(t, n);
@@ -261,7 +648,7 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
261
648
  return n(r, e), r;
262
649
  };
263
650
  Object.defineProperty(e, "__esModule", { value: !0 }), e.ADDRESS_BOUNDARY = void 0, e.groupPossibilities = a, e.padGroup = o, e.simpleRegularExpression = s, e.possibleElisions = c;
264
- var i = r(he());
651
+ var i = r(ye());
265
652
  function a(e) {
266
653
  return `(${e.join("|")})`;
267
654
  }
@@ -289,7 +676,7 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
289
676
  for (let t = 1; t < e - 1; t++) for (let n = 1; n < e - t; n++) o.push(`(0{1,4}:){${n}}:(0{1,4}:){${e - n - t - 1}}0{1,4}`);
290
677
  return a(o);
291
678
  }
292
- })), ve = /* @__PURE__ */ A(((e) => {
679
+ })), Se = /* @__PURE__ */ P(((e) => {
293
680
  var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
294
681
  r === void 0 && (r = n);
295
682
  var i = Object.getOwnPropertyDescriptor(t, n);
@@ -315,37 +702,38 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
315
702
  return n(r, e), r;
316
703
  };
317
704
  Object.defineProperty(e, "__esModule", { value: !0 }), e.Address6 = void 0;
318
- var i = r(j()), a = r(fe()), o = r(he()), s = r(ge()), c = me(), l = _e(), u = pe(), d = j();
319
- function f(e) {
705
+ var i = r(ge()), a = r(_e()), o = r(ye()), s = r(be()), c = ve(), l = xe(), u = F(), d = ge(), f = i.isCorrect(o.BITS);
706
+ function p(e) {
320
707
  if (!e) throw Error("Assertion failed.");
321
708
  }
322
- function p(e) {
709
+ function m(e) {
323
710
  let t = /(\d+)(\d{3})/;
324
711
  for (; t.test(e);) e = e.replace(t, "$1,$2");
325
712
  return e;
326
713
  }
327
- function m(e) {
714
+ function h(e) {
328
715
  return e = e.replace(/^(0{1,})([1-9]+)$/, "<span class=\"parse-error\">$1</span>$2"), e = e.replace(/^(0{1,})(0)$/, "<span class=\"parse-error\">$1</span>$2"), e;
329
716
  }
330
- function h(e, t) {
717
+ function g(e, t) {
331
718
  let n = [], r = [], i;
332
719
  for (i = 0; i < e.length; i++) i < t[0] ? n.push(e[i]) : i > t[1] && r.push(e[i]);
333
720
  return n.concat(["compact"]).concat(r);
334
721
  }
335
- function g(e) {
722
+ function _(e) {
336
723
  return parseInt(e, 16).toString(16).padStart(4, "0");
337
724
  }
338
- function ee(e) {
725
+ function v(e) {
339
726
  return e & 255;
340
727
  }
341
- e.Address6 = class e {
728
+ var y = class e {
342
729
  constructor(e, t) {
343
- this.addressMinusSuffix = "", this.parsedSubnet = "", this.subnet = "/128", this.subnetMask = 128, this.v4 = !1, this.zone = "", this.isInSubnet = i.isInSubnet, this.isCorrect = i.isCorrect(o.BITS), t === void 0 ? this.groups = o.GROUPS : this.groups = t, this.address = e;
730
+ this.addressMinusSuffix = "", this.parsedSubnet = "", this.subnet = "/128", this.subnetMask = 128, this.v4 = !1, this.zone = "", this.isInSubnet = i.isInSubnet, this.isHostInSubnet = i.isHostInSubnet, this.isCorrect = f, this.groups = t === void 0 ? o.GROUPS : t, this.address = e;
344
731
  let n = o.RE_SUBNET_STRING.exec(e);
345
732
  if (n) {
346
733
  if (this.parsedSubnet = n[0].replace("/", ""), this.subnetMask = parseInt(this.parsedSubnet, 10), this.subnet = `/${this.subnetMask}`, Number.isNaN(this.subnetMask) || this.subnetMask < 0 || this.subnetMask > o.BITS) throw new u.AddressError("Invalid subnet mask.");
347
734
  e = e.replace(o.RE_SUBNET_STRING, "");
348
- } else if (/\//.test(e)) throw new u.AddressError("Invalid subnet mask.");
735
+ }
736
+ if (/\//.test(e)) throw new u.AddressError("Invalid subnet mask.");
349
737
  let r = o.RE_ZONE_STRING.exec(e);
350
738
  r && (this.zone = r[0], e = e.replace(o.RE_ZONE_STRING, "")), this.addressMinusSuffix = e, this.parsedAddress = this.parse(this.addressMinusSuffix);
351
739
  }
@@ -357,45 +745,83 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
357
745
  }
358
746
  }
359
747
  static fromBigInt(t) {
360
- let n = t.toString(16).padStart(32, "0"), r = [], i;
361
- for (i = 0; i < o.GROUPS; i++) r.push(n.slice(i * 4, (i + 1) * 4));
748
+ if (t < BigInt(0) || t > (BigInt(1) << BigInt(o.BITS)) - BigInt(1)) throw new u.AddressError("IPv6 BigInt must be in the range 0 to 2**128 - 1");
749
+ let n = t.toString(16).padStart(32, "0"), r = [];
750
+ for (let e = 0; e < o.GROUPS; e++) r.push(n.slice(e * 4, (e + 1) * 4));
362
751
  return new e(r.join(":"));
363
752
  }
364
753
  static fromURL(t) {
365
- let n, r = null, i;
366
- if (t.indexOf("[") !== -1 && t.indexOf("]:") !== -1) {
367
- if (i = o.RE_URL_WITH_PORT.exec(t), i === null) return {
368
- error: "failed to parse address with port",
754
+ let n, r = null, i, a, s = t.replace(/^[a-z][a-z0-9+.-]*:\/\//i, "");
755
+ if (s.indexOf("[") !== -1 && s.indexOf("]:") !== -1) {
756
+ if (a = "failed to parse address with port", i = o.RE_URL_WITH_PORT.exec(s), i === null) return {
757
+ error: a,
369
758
  address: null,
370
759
  port: null
371
760
  };
372
761
  n = i[1], r = i[2];
373
- } else if (t.indexOf("/") !== -1) {
374
- if (t = t.replace(/^[a-z0-9]+:\/\//, ""), i = o.RE_URL.exec(t), i === null) return {
375
- error: "failed to parse address from URL",
762
+ } else {
763
+ if (a = "failed to parse address from URL", i = o.RE_URL.exec(s), i === null) return {
764
+ error: a,
765
+ address: null,
766
+ port: null
767
+ };
768
+ n = i[1] ?? i[2];
769
+ }
770
+ r ? (r = parseInt(r, 10), (r < 0 || r > 65535) && (r = null)) : r = null;
771
+ let c;
772
+ try {
773
+ c = new e(n);
774
+ } catch {
775
+ return {
776
+ error: a,
376
777
  address: null,
377
778
  port: null
378
779
  };
379
- n = i[1];
380
- } else n = t;
381
- return r ? (r = parseInt(r, 10), (r < 0 || r > 65536) && (r = null)) : r = null, {
382
- address: new e(n),
780
+ }
781
+ return {
782
+ address: c,
383
783
  port: r
384
784
  };
385
785
  }
786
+ static fromAddressAndMask(t, n) {
787
+ let r = i.prefixLengthFromMask(new e(n).bigInt(), o.BITS);
788
+ return new e(`${t}/${r}`);
789
+ }
790
+ static fromAddressAndWildcardMask(t, n) {
791
+ let r = new e(n).bigInt() ^ (BigInt(1) << BigInt(o.BITS)) - BigInt(1), a = i.prefixLengthFromMask(r, o.BITS);
792
+ return new e(`${t}/${a}`);
793
+ }
794
+ static fromWildcard(t) {
795
+ if (t.includes("%") || t.includes("/")) throw new u.AddressError("Wildcard pattern must not include a zone or CIDR suffix");
796
+ let n = t.split("::");
797
+ if (n.length > 2) throw new u.AddressError("Wildcard pattern cannot contain more than one '::'");
798
+ let r;
799
+ if (n.length === 2) {
800
+ let e = n[0] === "" ? [] : n[0].split(":"), t = n[1] === "" ? [] : n[1].split(":"), i = o.GROUPS - e.length - t.length;
801
+ if (i < 1) throw new u.AddressError("Wildcard pattern with '::' has too many groups");
802
+ r = [
803
+ ...e,
804
+ ...Array(i).fill("0"),
805
+ ...t
806
+ ];
807
+ } else r = t.split(":");
808
+ if (r.length !== o.GROUPS) throw new u.AddressError("Wildcard pattern must have 8 groups");
809
+ let i = -1;
810
+ for (let e = 0; e < r.length; e++) if (r[e] === "*") i === -1 && (i = e);
811
+ else if (i !== -1) throw new u.AddressError("Wildcard `*` must only appear in trailing groups (e.g. `2001:db8:*:*:*:*:*:*`)");
812
+ let a = i === -1 ? 0 : r.length - i, s = r.map((e) => e === "*" ? "0" : e), c = o.BITS - a * 16;
813
+ return new e(`${s.join(":")}/${c}`);
814
+ }
386
815
  static fromAddress4(t) {
387
816
  let n = new c.Address4(t), r = o.BITS - (a.BITS - n.subnetMask);
388
817
  return new e(`::ffff:${n.correctForm()}/${r}`);
389
818
  }
390
819
  static fromArpa(t) {
391
- let n = t.replace(/(\.ip6\.arpa)?\.$/, "");
392
- if (n.length !== 63) throw new u.AddressError("Invalid 'ip6.arpa' form.");
393
- let r = n.split(".").reverse();
394
- for (let e = 7; e > 0; e--) {
395
- let t = e * 4;
396
- r.splice(t, 0, ":");
397
- }
398
- return n = r.join(""), new e(n);
820
+ let n = t.replace(/(\.ip6\.arpa)?\.?$/, "");
821
+ if (!/^[0-9a-f](\.[0-9a-f]){0,31}$/i.test(n)) throw new u.AddressError("Invalid 'ip6.arpa' form.");
822
+ let r = n.split(".").reverse(), i = r.length * 4, a = r.join("").padEnd(32, "0"), s = [];
823
+ for (let e = 0; e < o.GROUPS; e++) s.push(a.slice(e * 4, (e + 1) * 4));
824
+ return new e(`${s.join(":")}/${i}`);
399
825
  }
400
826
  microsoftTranscription() {
401
827
  return `${this.correctForm().replace(/:/g, "-")}.ipv6-literal.net`;
@@ -405,7 +831,7 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
405
831
  }
406
832
  possibleSubnets(e = 128) {
407
833
  let t = o.BITS - this.subnetMask - Math.abs(e - o.BITS);
408
- return t < 0 ? "0" : p((BigInt("2") ** BigInt(t)).toString(10));
834
+ return t < 0 ? "0" : m((BigInt("2") ** BigInt(t)).toString(10));
409
835
  }
410
836
  _startAddress() {
411
837
  return BigInt(`0b${this.mask() + "0".repeat(o.BITS - this.subnetMask)}`);
@@ -427,12 +853,33 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
427
853
  let t = BigInt("1");
428
854
  return e.fromBigInt(this._endAddress() - t);
429
855
  }
856
+ offset(t) {
857
+ return e.fromBigInt(i.offsetBigInt(this.bigInt(), t, o.BITS, "IPv6")).withSubnetMask(this.subnetMask);
858
+ }
859
+ nextNetwork() {
860
+ return e.fromBigInt(i.offsetBigInt(this._endAddress(), 1, o.BITS, "IPv6")).withSubnetMask(this.subnetMask);
861
+ }
862
+ withSubnetMask(t) {
863
+ return new e(`${this.correctForm()}/${t}`);
864
+ }
865
+ subnetMaskAddress() {
866
+ return e.fromBigInt(BigInt(`0b${"1".repeat(this.subnetMask)}${"0".repeat(o.BITS - this.subnetMask)}`));
867
+ }
868
+ wildcardMask() {
869
+ return e.fromBigInt(BigInt(`0b${"0".repeat(this.subnetMask)}${"1".repeat(o.BITS - this.subnetMask)}`));
870
+ }
871
+ networkForm() {
872
+ return `${this.startAddress().correctForm()}/${this.subnetMask}`;
873
+ }
430
874
  getScope() {
431
- let e = o.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)];
432
- return this.getType() === "Global unicast" && e !== "Link local" && (e = "Global"), e || "Unknown";
875
+ let e = this.getType();
876
+ return e === "Multicast" || e.startsWith("Multicast ") ? o.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)] || "Unknown" : e === "Link-local unicast" || e === "Loopback" ? "Link local" : e === "Unspecified" ? "Unknown" : "Global";
433
877
  }
434
878
  getType() {
435
- for (let t of Object.keys(o.TYPES)) if (this.isInSubnet(new e(t))) return o.TYPES[t];
879
+ for (let e = 0; e < b.length; e++) {
880
+ let t = b[e];
881
+ if (this.isHostInSubnet(t[0])) return t[1];
882
+ }
436
883
  return "Global unicast";
437
884
  }
438
885
  getBits(e, t) {
@@ -464,24 +911,27 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
464
911
  let i = r.map((e) => e[1] - e[0] + 1);
465
912
  if (r.length > 0) {
466
913
  let e = i.indexOf(Math.max(...i));
467
- t = h(this.parsedAddress, r[e]);
914
+ t = g(this.parsedAddress, r[e]);
468
915
  } else t = this.parsedAddress;
469
916
  for (e = 0; e < t.length; e++) t[e] !== "compact" && (t[e] = parseInt(t[e], 16).toString(16));
470
917
  let a = t.join(":");
471
918
  return a = a.replace(/^compact$/, "::"), a = a.replace(/(^compact)|(compact$)/, ":"), a = a.replace(/compact/, ""), a;
472
919
  }
473
920
  binaryZeroPad() {
474
- return this.bigInt().toString(2).padStart(o.BITS, "0");
921
+ return this._binaryZeroPad === void 0 && (this._binaryZeroPad = this.bigInt().toString(2).padStart(o.BITS, "0")), this._binaryZeroPad;
475
922
  }
476
923
  parse4in6(e) {
477
- let t = e.split(":"), n = t.slice(-1)[0].match(a.RE_ADDRESS);
478
- if (n) {
479
- this.parsedAddress4 = n[0], this.address4 = new c.Address4(this.parsedAddress4);
480
- for (let e = 0; e < this.address4.groups; e++) if (/^0[0-9]+/.test(this.address4.parsedAddress[e])) {
481
- let e = this.address4.parsedAddress.map(m).join("."), n = t.slice(0, -1).map(s.escapeHtml).join(":"), r = t.length > 1 ? ":" : "";
482
- throw new u.AddressError("IPv4 addresses can't have leading zeroes.", `${n}${r}${e}`);
483
- }
484
- this.v4 = !0, t[t.length - 1] = this.address4.toGroup6(), e = t.join(":");
924
+ if (e.indexOf(".") === -1) return e;
925
+ let t = e.split(":"), n = t.slice(-1)[0], r = n.split(".");
926
+ if (r.length === a.GROUPS && r.every((e) => /^\d{1,3}$/.test(e)) && r.some((e) => /^0\d/.test(e))) {
927
+ let e = r.map(h).join("."), n = t.slice(0, -1).map(s.escapeHtml).join(":"), i = t.length > 1 ? ":" : "";
928
+ throw new u.AddressError("IPv4 addresses can't have leading zeroes.", `${n}${i}${e}`);
929
+ }
930
+ let i = n.match(a.RE_ADDRESS);
931
+ if (i) {
932
+ this.parsedAddress4 = i[0];
933
+ let n = this.subnetMask >= 96 ? `/${this.subnetMask - 96}` : "";
934
+ this.address4 = new c.Address4(`${this.parsedAddress4}${n}`), this.v4 = !0, t[t.length - 1] = this.address4.toGroup6(), e = t.join(":");
485
935
  }
486
936
  return e;
487
937
  }
@@ -506,24 +956,29 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
506
956
  return r;
507
957
  }
508
958
  canonicalForm() {
509
- return this.parsedAddress.map(g).join(":");
959
+ return this.parsedAddress.map(_).join(":");
510
960
  }
511
961
  decimal() {
512
962
  return this.parsedAddress.map((e) => parseInt(e, 16).toString(10).padStart(5, "0")).join(":");
513
963
  }
514
964
  bigInt() {
515
- return BigInt(`0x${this.parsedAddress.map(g).join("")}`);
965
+ return BigInt(`0x${this.parsedAddress.map(_).join("")}`);
516
966
  }
517
967
  to4() {
518
- let e = this.binaryZeroPad().split("");
519
- return c.Address4.fromHex(BigInt(`0b${e.slice(96, 128).join("")}`).toString(16));
968
+ let e = this.binaryZeroPad().split(""), t = BigInt(`0b${e.slice(96, 128).join("")}`).toString(16).padStart(8, "0");
969
+ if (this.subnetMask >= 96) {
970
+ let e = this.subnetMask - 96, n = [];
971
+ for (let e = 0; e < 8; e += 2) n.push(parseInt(t.slice(e, e + 2), 16));
972
+ return new c.Address4(`${n.join(".")}/${e}`);
973
+ }
974
+ return c.Address4.fromHex(t);
520
975
  }
521
976
  to4in6() {
522
977
  let t = this.to4(), n = new e(this.parsedAddress.slice(0, 6).join(":"), 6).correctForm(), r = "";
523
- return /:$/.test(n) || (r = ":"), n + r + t.address;
978
+ return /:$/.test(n) || (r = ":"), n + r + t.correctForm();
524
979
  }
525
980
  inspectTeredo() {
526
- let e = this.getBitsBase16(0, 32), t = (this.getBits(80, 96) ^ BigInt("0xffff")).toString(), n = c.Address4.fromHex(this.getBitsBase16(32, 64)), r = this.getBits(96, 128), i = c.Address4.fromHex((r ^ BigInt("0xffffffff")).toString(16)), a = this.getBitsBase2(64, 80), o = (0, d.testBit)(a, 15), s = (0, d.testBit)(a, 14), l = (0, d.testBit)(a, 8), u = (0, d.testBit)(a, 9), f = BigInt(`0b${a.slice(2, 6) + a.slice(8, 16)}`).toString(10);
981
+ let e = this.getBitsBase16(0, 32), t = (this.getBits(80, 96) ^ BigInt("0xffff")).toString(), n = c.Address4.fromHex(this.getBitsBase16(32, 64)), r = this.getBits(96, 128), i = c.Address4.fromHex((r ^ BigInt("0xffffffff")).toString(16).padStart(8, "0")), a = this.getBitsBase2(64, 80), o = (0, d.testBit)(a, 15), s = (0, d.testBit)(a, 14), l = (0, d.testBit)(a, 8), u = (0, d.testBit)(a, 9), f = BigInt(`0b${a.slice(2, 6) + a.slice(8, 16)}`).toString(10);
527
982
  return {
528
983
  prefix: `${e.slice(0, 4)}:${e.slice(4, 8)}`,
529
984
  server4: n.address,
@@ -547,50 +1002,127 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
547
1002
  };
548
1003
  }
549
1004
  to6to4() {
550
- return this.is4() ? new e([
1005
+ if (!this.is4()) return null;
1006
+ let t = [
551
1007
  "2002",
552
1008
  this.getBitsBase16(96, 112),
553
1009
  this.getBitsBase16(112, 128),
554
1010
  "",
555
1011
  "/16"
556
- ].join(":")) : null;
1012
+ ].join(":");
1013
+ return new e(t);
1014
+ }
1015
+ static fromAddress4Nat64(t, n = "64:ff9b::/96") {
1016
+ let r = new c.Address4(t), i = new e(n), a = i.subnetMask;
1017
+ if (a !== 32 && a !== 40 && a !== 48 && a !== 56 && a !== 64 && a !== 96) throw new u.AddressError("NAT64 prefix length must be 32, 40, 48, 56, 64, or 96");
1018
+ let o = i.binaryZeroPad(), s = r.binaryZeroPad(), l;
1019
+ if (a === 96) l = o.slice(0, 96) + s;
1020
+ else {
1021
+ let e = 64 - a;
1022
+ l = [
1023
+ o.slice(0, a),
1024
+ s.slice(0, e),
1025
+ "00000000",
1026
+ s.slice(e),
1027
+ "0".repeat(56 - (32 - e))
1028
+ ].join("");
1029
+ }
1030
+ let d = BigInt(`0b${l}`).toString(16).padStart(32, "0"), f = [];
1031
+ for (let e = 0; e < 8; e++) f.push(d.slice(e * 4, (e + 1) * 4));
1032
+ return new e(f.join(":"));
1033
+ }
1034
+ toAddress4Nat64(t = "64:ff9b::/96") {
1035
+ let n = new e(t), r = n.subnetMask;
1036
+ if (r !== 32 && r !== 40 && r !== 48 && r !== 56 && r !== 64 && r !== 96) throw new u.AddressError("NAT64 prefix length must be 32, 40, 48, 56, 64, or 96");
1037
+ if (!this.isHostInSubnet(n)) return null;
1038
+ let i = this.binaryZeroPad(), a;
1039
+ if (r === 96) a = i.slice(96, 128);
1040
+ else {
1041
+ let e = 64 - r;
1042
+ a = i.slice(r, r + e) + i.slice(72, 72 + (32 - e));
1043
+ }
1044
+ let o = [];
1045
+ for (let e = 0; e < 4; e++) o.push(parseInt(a.slice(e * 8, (e + 1) * 8), 2).toString());
1046
+ return new c.Address4(o.join("."));
557
1047
  }
558
1048
  toByteArray() {
559
- let e = this.bigInt().toString(16), t = `${"0".repeat(e.length % 2)}${e}`, n = [];
560
- for (let e = 0, r = t.length; e < r; e += 2) n.push(parseInt(t.substring(e, e + 2), 16));
561
- return n;
1049
+ let e = this.bigInt().toString(16).padStart(o.BITS / 4, "0"), t = [];
1050
+ for (let n = 0, r = e.length; n < r; n += 2) t.push(parseInt(e.substring(n, n + 2), 16));
1051
+ return t;
562
1052
  }
563
1053
  toUnsignedByteArray() {
564
- return this.toByteArray().map(ee);
1054
+ return this.toByteArray().map(v);
565
1055
  }
566
1056
  static fromByteArray(e) {
567
- return this.fromUnsignedByteArray(e.map(ee));
1057
+ return i.assertByteArray(e, 16, "IPv6", -128), this.fromUnsignedByteArray(e.map(v));
568
1058
  }
569
1059
  static fromUnsignedByteArray(t) {
570
- let n = BigInt("256"), r = BigInt("0"), i = BigInt("1");
571
- for (let e = t.length - 1; e >= 0; e--) r += i * BigInt(t[e].toString(10)), i *= n;
1060
+ i.assertByteArray(t, 16, "IPv6", 0);
1061
+ let n = BigInt("256"), r = BigInt("0"), a = BigInt("1");
1062
+ for (let e = t.length - 1; e >= 0; e--) r += a * BigInt(t[e].toString(10)), a *= n;
572
1063
  return e.fromBigInt(r);
573
1064
  }
574
1065
  isCanonical() {
575
1066
  return this.addressMinusSuffix === this.canonicalForm();
576
1067
  }
577
1068
  isLinkLocal() {
578
- return this.getBitsBase2(0, 64) === "1111111010000000000000000000000000000000000000000000000000000000";
1069
+ let e = this.embeddedIPv4();
1070
+ return e ? e.isLinkLocal() : this.isHostInSubnet(ee);
579
1071
  }
580
1072
  isMulticast() {
581
- return this.getType() === "Multicast";
1073
+ let e = this.embeddedIPv4();
1074
+ if (e) return e.isMulticast();
1075
+ let t = this.getType();
1076
+ return t === "Multicast" || t.startsWith("Multicast ");
582
1077
  }
583
1078
  is4() {
584
1079
  return this.v4;
585
1080
  }
1081
+ isMapped4() {
1082
+ return this.isHostInSubnet(O);
1083
+ }
1084
+ embeddedIPv4() {
1085
+ return this.isMapped4() || this.isHostInSubnet(k) ? this.to4() : null;
1086
+ }
586
1087
  isTeredo() {
587
- return this.isInSubnet(new e("2001::/32"));
1088
+ return this.isHostInSubnet(x);
588
1089
  }
589
1090
  is6to4() {
590
- return this.isInSubnet(new e("2002::/16"));
1091
+ return this.isHostInSubnet(S);
591
1092
  }
592
1093
  isLoopback() {
593
- return this.getType() === "Loopback";
1094
+ let e = this.embeddedIPv4();
1095
+ return e ? e.isLoopback() : this.getType() === "Loopback";
1096
+ }
1097
+ isULA() {
1098
+ return this.isHostInSubnet(C);
1099
+ }
1100
+ isPrivate() {
1101
+ let e = this.embeddedIPv4();
1102
+ return e ? e.isPrivate() : this.isULA() || this.isHostInSubnet(A);
1103
+ }
1104
+ isCGNAT() {
1105
+ let e = this.embeddedIPv4();
1106
+ return e ? e.isCGNAT() : !1;
1107
+ }
1108
+ isBroadcast() {
1109
+ let e = this.embeddedIPv4();
1110
+ return e ? e.isBroadcast() : !1;
1111
+ }
1112
+ isUnspecified() {
1113
+ let e = this.embeddedIPv4();
1114
+ return e ? e.isUnspecified() : this.getType() === "Unspecified";
1115
+ }
1116
+ isDocumentation() {
1117
+ return w.some((e) => this.isHostInSubnet(e));
1118
+ }
1119
+ isBenchmarking() {
1120
+ let e = this.embeddedIPv4();
1121
+ return e ? e.isBenchmarking() : this.isHostInSubnet(T);
1122
+ }
1123
+ isGlobal() {
1124
+ let e = this.embeddedIPv4();
1125
+ return e ? e.isGlobal() : this.isHostInSubnet(E) && i.isGloballyReachable.call(this, D);
594
1126
  }
595
1127
  href(e) {
596
1128
  return e = e === void 0 ? "" : `:${e}`, `http://[${this.correctForm()}]${e}/`;
@@ -604,12 +1136,12 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
604
1136
  }
605
1137
  group() {
606
1138
  if (this.elidedGroups === 0) return s.simpleGroup(this.addressMinusSuffix).join(":");
607
- f(typeof this.elidedGroups == "number"), f(typeof this.elisionBegin == "number");
1139
+ p(typeof this.elidedGroups == "number"), p(typeof this.elisionBegin == "number");
608
1140
  let e = [], [t, n] = this.addressMinusSuffix.split("::");
609
1141
  t.length ? e.push(...s.simpleGroup(t)) : e.push("");
610
1142
  let r = ["hover-group"];
611
1143
  for (let e = this.elisionBegin; e < this.elisionBegin + this.elidedGroups; e++) r.push(`group-${e}`);
612
- return e.push(`<span class="${r.join(" ")}"></span>`), n.length ? e.push(...s.simpleGroup(n, this.elisionEnd)) : e.push(""), this.is4() && (f(this.address4 instanceof c.Address4), e.pop(), e.push(this.address4.groupForV6())), e.join(":");
1144
+ return e.push(`<span class="${r.join(" ")}"></span>`), n.length ? e.push(...s.simpleGroup(n, this.elisionEnd)) : e.push(""), this.is4() && (p(this.address4 instanceof c.Address4), e.pop(), e.push(this.address4.groupForV6())), e.join(":");
613
1145
  }
614
1146
  regularExpressionString(t = !1) {
615
1147
  let n = [], r = new e(this.correctForm());
@@ -617,7 +1149,7 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
617
1149
  else if (r.elidedGroups === o.GROUPS) n.push((0, l.possibleElisions)(o.GROUPS));
618
1150
  else {
619
1151
  let e = r.address.split("::");
620
- e[0].length && n.push((0, l.simpleRegularExpression)(e[0].split(":"))), f(typeof r.elidedGroups == "number"), n.push((0, l.possibleElisions)(r.elidedGroups, e[0].length !== 0, e[1].length !== 0)), e[1].length && n.push((0, l.simpleRegularExpression)(e[1].split(":"))), n = [n.join(":")];
1152
+ e[0].length && n.push((0, l.simpleRegularExpression)(e[0].split(":"))), p(typeof r.elidedGroups == "number"), n.push((0, l.possibleElisions)(r.elidedGroups, e[0].length !== 0, e[1].length !== 0)), e[1].length && n.push((0, l.simpleRegularExpression)(e[1].split(":"))), n = [n.join(":")];
621
1153
  }
622
1154
  return t || (n = [
623
1155
  "(?=^|",
@@ -633,7 +1165,12 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
633
1165
  return new RegExp(this.regularExpressionString(e), "i");
634
1166
  }
635
1167
  };
636
- })), ye = (/* @__PURE__ */ A(((e) => {
1168
+ e.Address6 = y;
1169
+ var b = Object.keys(o.TYPES).map((e) => [new y(e), o.TYPES[e]]), x = new y("2001::/32"), S = new y("2002::/16"), C = new y("fc00::/7"), ee = new y("fe80::/10"), w = [new y("2001:db8::/32"), new y("3fff::/20")], T = new y("2001:2::/48"), E = new y("2000::/3"), D = o.SPECIAL_PURPOSE.map(([e, , t]) => ({
1170
+ subnet: new y(e),
1171
+ reachable: t
1172
+ })), O = new y("::ffff:0:0/96"), k = new y("64:ff9b::/96"), A = new y("64:ff9b:1::/48");
1173
+ })), Ce = /* @__PURE__ */ P(((e) => {
637
1174
  var t = e && e.__createBinding || (Object.create ? (function(e, t, n, r) {
638
1175
  r === void 0 && (r = n);
639
1176
  var i = Object.getOwnPropertyDescriptor(t, n);
@@ -659,37 +1196,222 @@ var A = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
659
1196
  return n(r, e), r;
660
1197
  };
661
1198
  Object.defineProperty(e, "__esModule", { value: !0 }), e.v6 = e.AddressError = e.Address6 = e.Address4 = void 0;
662
- var i = me();
1199
+ var i = ve();
663
1200
  Object.defineProperty(e, "Address4", {
664
1201
  enumerable: !0,
665
1202
  get: function() {
666
1203
  return i.Address4;
667
1204
  }
668
1205
  });
669
- var a = ve();
1206
+ var a = Se();
670
1207
  Object.defineProperty(e, "Address6", {
671
1208
  enumerable: !0,
672
1209
  get: function() {
673
1210
  return a.Address6;
674
1211
  }
675
1212
  });
676
- var o = pe();
1213
+ var o = F();
677
1214
  Object.defineProperty(e, "AddressError", {
678
1215
  enumerable: !0,
679
1216
  get: function() {
680
1217
  return o.AddressError;
681
1218
  }
682
- }), e.v6 = { helpers: r(ge()) };
683
- })))();
684
- function be(e, t = 56) {
1219
+ }), e.v6 = { helpers: r(be()) };
1220
+ })), we = /* @__PURE__ */ P(((e, t) => {
1221
+ var n = 1e3, r = n * 60, i = r * 60, a = i * 24, o = a * 7, s = a * 365.25;
1222
+ t.exports = function(e, t) {
1223
+ t ||= {};
1224
+ var n = typeof e;
1225
+ if (n === "string" && e.length > 0) return c(e);
1226
+ if (n === "number" && isFinite(e)) return t.long ? u(e) : l(e);
1227
+ throw Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(e));
1228
+ };
1229
+ function c(e) {
1230
+ if (e = String(e), !(e.length > 100)) {
1231
+ var t = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);
1232
+ if (t) {
1233
+ var c = parseFloat(t[1]);
1234
+ switch ((t[2] || "ms").toLowerCase()) {
1235
+ case "years":
1236
+ case "year":
1237
+ case "yrs":
1238
+ case "yr":
1239
+ case "y": return c * s;
1240
+ case "weeks":
1241
+ case "week":
1242
+ case "w": return c * o;
1243
+ case "days":
1244
+ case "day":
1245
+ case "d": return c * a;
1246
+ case "hours":
1247
+ case "hour":
1248
+ case "hrs":
1249
+ case "hr":
1250
+ case "h": return c * i;
1251
+ case "minutes":
1252
+ case "minute":
1253
+ case "mins":
1254
+ case "min":
1255
+ case "m": return c * r;
1256
+ case "seconds":
1257
+ case "second":
1258
+ case "secs":
1259
+ case "sec":
1260
+ case "s": return c * n;
1261
+ case "milliseconds":
1262
+ case "millisecond":
1263
+ case "msecs":
1264
+ case "msec":
1265
+ case "ms": return c;
1266
+ default: return;
1267
+ }
1268
+ }
1269
+ }
1270
+ }
1271
+ function l(e) {
1272
+ var t = Math.abs(e);
1273
+ return t >= a ? Math.round(e / a) + "d" : t >= i ? Math.round(e / i) + "h" : t >= r ? Math.round(e / r) + "m" : t >= n ? Math.round(e / n) + "s" : e + "ms";
1274
+ }
1275
+ function u(e) {
1276
+ var t = Math.abs(e);
1277
+ return t >= a ? d(e, t, a, "day") : t >= i ? d(e, t, i, "hour") : t >= r ? d(e, t, r, "minute") : t >= n ? d(e, t, n, "second") : e + " ms";
1278
+ }
1279
+ function d(e, t, n, r) {
1280
+ var i = t >= n * 1.5;
1281
+ return Math.round(e / n) + " " + r + (i ? "s" : "");
1282
+ }
1283
+ })), Te = /* @__PURE__ */ P(((e, t) => {
1284
+ function n(e) {
1285
+ n.debug = n, n.default = n, n.coerce = c, n.disable = o, n.enable = i, n.enabled = s, n.humanize = we(), n.destroy = l, Object.keys(e).forEach((t) => {
1286
+ n[t] = e[t];
1287
+ }), n.names = [], n.skips = [], n.formatters = {};
1288
+ function t(e) {
1289
+ let t = 0;
1290
+ for (let n = 0; n < e.length; n++) t = (t << 5) - t + e.charCodeAt(n), t |= 0;
1291
+ return n.colors[Math.abs(t) % n.colors.length];
1292
+ }
1293
+ n.selectColor = t;
1294
+ function n(e) {
1295
+ let t, i = null, a, o;
1296
+ function s(...e) {
1297
+ if (!s.enabled) return;
1298
+ let r = s, i = Number(/* @__PURE__ */ new Date());
1299
+ r.diff = i - (t || i), r.prev = t, r.curr = i, t = i, e[0] = n.coerce(e[0]), typeof e[0] != "string" && e.unshift("%O");
1300
+ let a = 0;
1301
+ e[0] = e[0].replace(/%([a-zA-Z%])/g, (t, i) => {
1302
+ if (t === "%%") return "%";
1303
+ a++;
1304
+ let o = n.formatters[i];
1305
+ if (typeof o == "function") {
1306
+ let n = e[a];
1307
+ t = o.call(r, n), e.splice(a, 1), a--;
1308
+ }
1309
+ return t;
1310
+ }), n.formatArgs.call(r, e), (r.log || n.log).apply(r, e);
1311
+ }
1312
+ return s.namespace = e, s.useColors = n.useColors(), s.color = n.selectColor(e), s.extend = r, s.destroy = n.destroy, Object.defineProperty(s, "enabled", {
1313
+ enumerable: !0,
1314
+ configurable: !1,
1315
+ get: () => i === null ? (a !== n.namespaces && (a = n.namespaces, o = n.enabled(e)), o) : i,
1316
+ set: (e) => {
1317
+ i = e;
1318
+ }
1319
+ }), typeof n.init == "function" && n.init(s), s;
1320
+ }
1321
+ function r(e, t) {
1322
+ let r = n(this.namespace + (t === void 0 ? ":" : t) + e);
1323
+ return r.log = this.log, r;
1324
+ }
1325
+ function i(e) {
1326
+ n.save(e), n.namespaces = e, n.names = [], n.skips = [];
1327
+ let t = (typeof e == "string" ? e : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
1328
+ for (let e of t) e[0] === "-" ? n.skips.push(e.slice(1)) : n.names.push(e);
1329
+ }
1330
+ function a(e, t) {
1331
+ let n = 0, r = 0, i = -1, a = 0;
1332
+ for (; n < e.length;) if (r < t.length && (t[r] === e[n] || t[r] === "*")) t[r] === "*" ? (i = r, a = n, r++) : (n++, r++);
1333
+ else if (i !== -1) r = i + 1, a++, n = a;
1334
+ else return !1;
1335
+ for (; r < t.length && t[r] === "*";) r++;
1336
+ return r === t.length;
1337
+ }
1338
+ function o() {
1339
+ let e = [...n.names, ...n.skips.map((e) => "-" + e)].join(",");
1340
+ return n.enable(""), e;
1341
+ }
1342
+ function s(e) {
1343
+ for (let t of n.skips) if (a(e, t)) return !1;
1344
+ for (let t of n.names) if (a(e, t)) return !0;
1345
+ return !1;
1346
+ }
1347
+ function c(e) {
1348
+ return e instanceof Error ? e.stack || e.message : e;
1349
+ }
1350
+ function l() {
1351
+ console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
1352
+ }
1353
+ return n.enable(n.load()), n;
1354
+ }
1355
+ t.exports = n;
1356
+ })), Ee = /* @__PURE__ */ P(((e, t) => {
1357
+ e.formatArgs = r, e.save = i, e.load = a, e.useColors = n, e.storage = o(), e.destroy = (() => {
1358
+ let e = !1;
1359
+ return () => {
1360
+ e || (e = !0, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."));
1361
+ };
1362
+ })(), e.colors = /* @__PURE__ */ "#0000CC.#0000FF.#0033CC.#0033FF.#0066CC.#0066FF.#0099CC.#0099FF.#00CC00.#00CC33.#00CC66.#00CC99.#00CCCC.#00CCFF.#3300CC.#3300FF.#3333CC.#3333FF.#3366CC.#3366FF.#3399CC.#3399FF.#33CC00.#33CC33.#33CC66.#33CC99.#33CCCC.#33CCFF.#6600CC.#6600FF.#6633CC.#6633FF.#66CC00.#66CC33.#9900CC.#9900FF.#9933CC.#9933FF.#99CC00.#99CC33.#CC0000.#CC0033.#CC0066.#CC0099.#CC00CC.#CC00FF.#CC3300.#CC3333.#CC3366.#CC3399.#CC33CC.#CC33FF.#CC6600.#CC6633.#CC9900.#CC9933.#CCCC00.#CCCC33.#FF0000.#FF0033.#FF0066.#FF0099.#FF00CC.#FF00FF.#FF3300.#FF3333.#FF3366.#FF3399.#FF33CC.#FF33FF.#FF6600.#FF6633.#FF9900.#FF9933.#FFCC00.#FFCC33".split(".");
1363
+ function n() {
1364
+ if (typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return !0;
1365
+ if (typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return !1;
1366
+ let e;
1367
+ return typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator < "u" && navigator.userAgent && (e = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(e[1], 10) >= 31 || typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
1368
+ }
1369
+ function r(e) {
1370
+ if (e[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + e[0] + (this.useColors ? "%c " : " ") + "+" + t.exports.humanize(this.diff), !this.useColors) return;
1371
+ let n = "color: " + this.color;
1372
+ e.splice(1, 0, n, "color: inherit");
1373
+ let r = 0, i = 0;
1374
+ e[0].replace(/%[a-zA-Z%]/g, (e) => {
1375
+ e !== "%%" && (r++, e === "%c" && (i = r));
1376
+ }), e.splice(i, 0, n);
1377
+ }
1378
+ e.log = console.debug || console.log || (() => {});
1379
+ function i(t) {
1380
+ try {
1381
+ t ? e.storage.setItem("debug", t) : e.storage.removeItem("debug");
1382
+ } catch {}
1383
+ }
1384
+ function a() {
1385
+ let t;
1386
+ try {
1387
+ t = e.storage.getItem("debug") || e.storage.getItem("DEBUG");
1388
+ } catch {}
1389
+ return !t && typeof process < "u" && "env" in process && (t = process.env.DEBUG), t;
1390
+ }
1391
+ function o() {
1392
+ try {
1393
+ return localStorage;
1394
+ } catch {}
1395
+ }
1396
+ t.exports = Te()(e);
1397
+ var { formatters: s } = t.exports;
1398
+ s.j = function(e) {
1399
+ try {
1400
+ return JSON.stringify(e);
1401
+ } catch (e) {
1402
+ return "[UnexpectedJSONParseError]: " + e.message;
1403
+ }
1404
+ };
1405
+ })), De = Ce(), Oe = /* @__PURE__ */ he(Ee(), 1), ke = new De.Address6("::/96");
1406
+ function Ae(e, t = 56) {
685
1407
  if (d(e)) {
686
- let n = new ye.Address6(e);
687
- if (n.is4()) return n.to4().correctForm();
688
- if (t) return new ye.Address6(`${e}/${t}`).networkForm();
1408
+ let n = new De.Address6(e);
1409
+ if (n.isMapped4() || n.is4() && n.isInSubnet(ke)) return n.to4().correctForm();
1410
+ if (t) return new De.Address6(`${e}/${t}`).networkForm();
689
1411
  }
690
1412
  return e;
691
1413
  }
692
- var xe = class {
1414
+ var je = class {
693
1415
  constructor(e) {
694
1416
  this.validations = e, this.previous = /* @__PURE__ */ new Map(), this.current = /* @__PURE__ */ new Map(), this.localKeys = !0;
695
1417
  }
@@ -732,110 +1454,110 @@ var xe = class {
732
1454
  clearExpired() {
733
1455
  this.previous = this.current, this.current = /* @__PURE__ */ new Map();
734
1456
  }
735
- }, Se = {
1457
+ }, Me = {
736
1458
  warn(...e) {
737
1459
  console.warn(...e.reverse());
738
1460
  },
739
1461
  error(...e) {
740
1462
  console.error(...e.reverse());
741
1463
  }
742
- }, Ce = [
1464
+ }, Ne = [
743
1465
  "draft-6",
744
1466
  "draft-7",
745
1467
  "draft-8"
746
- ], M = (e, t) => {
1468
+ ], I = (e, t) => {
747
1469
  let n;
748
1470
  if (t) {
749
1471
  let e = Math.ceil((t.getTime() - Date.now()) / 1e3);
750
1472
  n = Math.max(0, e);
751
1473
  } else n = Math.ceil(e / 1e3);
752
1474
  return n;
753
- }, we = (e) => {
1475
+ }, Pe = (e) => {
754
1476
  let t = n("sha256");
755
1477
  t.update(e);
756
1478
  let r = t.digest("hex").slice(0, 12);
757
- return _.from(r).toString("base64");
758
- }, Te = (e, t) => {
1479
+ return x.from(r).toString("base64");
1480
+ }, Fe = (e, t) => {
759
1481
  e.headersSent || (e.setHeader("X-RateLimit-Limit", t.limit.toString()), e.setHeader("X-RateLimit-Remaining", t.remaining.toString()), t.resetTime instanceof Date && (e.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString()), e.setHeader("X-RateLimit-Reset", Math.ceil(t.resetTime.getTime() / 1e3).toString())));
760
- }, Ee = (e, t, n) => {
1482
+ }, Ie = (e, t, n) => {
761
1483
  if (e.headersSent) return;
762
- let r = Math.ceil(n / 1e3), i = M(n, t.resetTime);
1484
+ let r = Math.ceil(n / 1e3), i = I(n, t.resetTime);
763
1485
  e.setHeader("RateLimit-Policy", `${t.limit};w=${r}`), e.setHeader("RateLimit-Limit", t.limit.toString()), e.setHeader("RateLimit-Remaining", t.remaining.toString()), typeof i == "number" && e.setHeader("RateLimit-Reset", i.toString());
764
- }, De = (e, t, n) => {
1486
+ }, Le = (e, t, n) => {
765
1487
  if (e.headersSent) return;
766
- let r = Math.ceil(n / 1e3), i = M(n, t.resetTime);
1488
+ let r = Math.ceil(n / 1e3), i = I(n, t.resetTime);
767
1489
  e.setHeader("RateLimit-Policy", `${t.limit};w=${r}`), e.setHeader("RateLimit", `limit=${t.limit}, remaining=${t.remaining}, reset=${i}`);
768
- }, Oe = (e, t, n, r, i) => {
1490
+ }, Re = (e, t, n, r, i) => {
769
1491
  if (e.headersSent) return;
770
- let a = Math.ceil(n / 1e3), o = M(n, t.resetTime), s = we(i), c = `r=${t.remaining}; t=${o}`, l = `q=${t.limit}; w=${a}; pk=:${s}:`;
1492
+ let a = Math.ceil(n / 1e3), o = I(n, t.resetTime), s = Pe(i), c = `r=${t.remaining}; t=${o}`, l = `q=${t.limit}; w=${a}; pk=:${s}:`;
771
1493
  e.append("RateLimit", `"${r}"; ${c}`), e.append("RateLimit-Policy", `"${r}"; ${l}`);
772
- }, ke = (e, t, n) => {
1494
+ }, ze = (e, t, n, r) => {
773
1495
  if (e.headersSent) return;
774
- let r = M(n, t.resetTime);
775
- e.setHeader("Retry-After", r.toString());
776
- }, Ae = (e) => {
1496
+ let i = r ?? I(n, t.resetTime);
1497
+ e.setHeader("Retry-After", i.toString());
1498
+ }, Be = (e) => {
777
1499
  let t = {};
778
1500
  for (let n of Object.keys(e)) {
779
1501
  let r = n;
780
1502
  e[r] !== void 0 && (t[r] = e[r]);
781
1503
  }
782
1504
  return t;
783
- }, N = class extends Error {
1505
+ }, L = class extends Error {
784
1506
  constructor(e, t) {
785
1507
  let n = `https://express-rate-limit.github.io/${e}/`;
786
1508
  super(`${t} See ${n} for more information.`), this.name = this.constructor.name, this.code = e, this.help = n;
787
1509
  }
788
- }, P = class extends N {}, je = /* @__PURE__ */ new Set(), Me = /* @__PURE__ */ new WeakMap(), Ne = {
1510
+ }, R = class extends L {}, Ve = /* @__PURE__ */ new Set(), He = /* @__PURE__ */ new WeakMap(), Ue = {
789
1511
  enabled: { default: !0 },
790
1512
  disable() {
791
1513
  for (let e of Object.keys(this.enabled)) this.enabled[e] = !1;
792
1514
  },
793
1515
  ip(e) {
794
- if (e === void 0) throw new N("ERR_ERL_UNDEFINED_IP_ADDRESS", "An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely.");
795
- if (!u(e)) throw new N("ERR_ERL_INVALID_IP_ADDRESS", `An invalid 'request.ip' (${e}) was detected. Consider passing a custom 'keyGenerator' function to the rate limiter.`);
1516
+ if (e === void 0) throw new L("ERR_ERL_UNDEFINED_IP_ADDRESS", "An undefined 'request.ip' was detected. This might indicate a misconfiguration or the connection being destroyed prematurely.");
1517
+ if (!u(e)) throw new L("ERR_ERL_INVALID_IP_ADDRESS", `An invalid 'request.ip' (${e}) was detected. Consider passing a custom 'keyGenerator' function to the rate limiter.`);
796
1518
  },
797
1519
  trustProxy(e) {
798
- if (e.app.get("trust proxy") === !0) throw new N("ERR_ERL_PERMISSIVE_TRUST_PROXY", "The Express 'trust proxy' setting is true, which allows anyone to trivially bypass IP-based rate limiting.");
1520
+ if (e.app.get("trust proxy") === !0) throw new L("ERR_ERL_PERMISSIVE_TRUST_PROXY", "The Express 'trust proxy' setting is true, which allows anyone to trivially bypass IP-based rate limiting.");
799
1521
  },
800
1522
  xForwardedForHeader(e) {
801
- if (e.headers["x-forwarded-for"] && e.app.get("trust proxy") === !1) throw new N("ERR_ERL_UNEXPECTED_X_FORWARDED_FOR", "The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default). This could indicate a misconfiguration which would prevent express-rate-limit from accurately identifying users.");
1523
+ if (e.headers["x-forwarded-for"] && e.app.get("trust proxy") === !1) throw new L("ERR_ERL_UNEXPECTED_X_FORWARDED_FOR", "The 'X-Forwarded-For' header is set but the Express 'trust proxy' setting is false (default). This could indicate a misconfiguration which would prevent express-rate-limit from accurately identifying users.");
802
1524
  },
803
1525
  forwardedHeader(e) {
804
- if (e.headers.forwarded && e.ip === e.socket?.remoteAddress) throw new N("ERR_ERL_FORWARDED_HEADER", "The 'Forwarded' header (standardized X-Forwarded-For) is set but currently being ignored. Add a custom keyGenerator to use a value from this header.");
1526
+ if (e.headers.forwarded && e.ip === e.socket?.remoteAddress) throw new L("ERR_ERL_FORWARDED_HEADER", "The 'Forwarded' header (standardized X-Forwarded-For) is set but currently being ignored. Add a custom keyGenerator to use a value from this header.");
805
1527
  },
806
1528
  positiveHits(e) {
807
- if (typeof e != "number" || e < 1 || e !== Math.round(e)) throw new N("ERR_ERL_INVALID_HITS", `The totalHits value returned from the store must be a positive integer, got ${e}`);
1529
+ if (typeof e != "number" || e < 1 || e !== Math.round(e)) throw new L("ERR_ERL_INVALID_HITS", `The totalHits value returned from the store must be a positive integer, got ${e}`);
808
1530
  },
809
1531
  unsharedStore(e) {
810
- if (je.has(e)) {
1532
+ if (Ve.has(e)) {
811
1533
  let t = e?.localKeys ? "" : " (with a unique prefix)";
812
- throw new N("ERR_ERL_STORE_REUSE", `A Store instance must not be shared across multiple rate limiters. Create a new instance of ${e.constructor.name}${t} for each limiter instead.`);
1534
+ throw new L("ERR_ERL_STORE_REUSE", `A Store instance must not be shared across multiple rate limiters. Create a new instance of ${e.constructor.name}${t} for each limiter instead.`);
813
1535
  }
814
- je.add(e);
1536
+ Ve.add(e);
815
1537
  },
816
1538
  singleCount(e, t, n) {
817
- let r = Me.get(e);
818
- r || (r = /* @__PURE__ */ new Map(), Me.set(e, r));
1539
+ let r = He.get(e);
1540
+ r || (r = /* @__PURE__ */ new Map(), He.set(e, r));
819
1541
  let i = t.localKeys ? t : t.constructor.name, a = r.get(i);
820
1542
  a || (a = [], r.set(i, a));
821
1543
  let o = `${t.prefix ?? ""}${n}`;
822
- if (a.includes(o)) throw new N("ERR_ERL_DOUBLE_COUNT", `The hit count for ${n} was incremented more than once for a single request.`);
1544
+ if (a.includes(o)) throw new L("ERR_ERL_DOUBLE_COUNT", `The hit count for ${n} was incremented more than once for a single request.`);
823
1545
  a.push(o);
824
1546
  },
825
1547
  limit(e) {
826
- if (e === 0) throw new P("WRN_ERL_MAX_ZERO", "Setting limit or max to 0 disables rate limiting in express-rate-limit v6 and older, but will cause all requests to be blocked in v7");
1548
+ if (e === 0) throw new R("WRN_ERL_MAX_ZERO", "Setting limit or max to 0 disables rate limiting in express-rate-limit v6 and older, but will cause all requests to be blocked in v7");
827
1549
  },
828
1550
  draftPolliHeaders(e) {
829
- if (e) throw new P("WRN_ERL_DEPRECATED_DRAFT_POLLI_HEADERS", "The draft_polli_ratelimit_headers configuration option is deprecated and has been removed in express-rate-limit v7, please set standardHeaders: 'draft-6' instead.");
1551
+ if (e) throw new R("WRN_ERL_DEPRECATED_DRAFT_POLLI_HEADERS", "The draft_polli_ratelimit_headers configuration option is deprecated and has been removed in express-rate-limit v7, please set standardHeaders: 'draft-6' instead.");
830
1552
  },
831
1553
  onLimitReached(e) {
832
- if (e) throw new P("WRN_ERL_DEPRECATED_ON_LIMIT_REACHED", "The onLimitReached configuration option is deprecated and has been removed in express-rate-limit v7.");
1554
+ if (e) throw new R("WRN_ERL_DEPRECATED_ON_LIMIT_REACHED", "The onLimitReached configuration option is deprecated and has been removed in express-rate-limit v7.");
833
1555
  },
834
1556
  headersDraftVersion(e) {
835
- if (typeof e != "string" || !Ce.includes(e)) throw new N("ERR_ERL_HEADERS_UNSUPPORTED_DRAFT_VERSION", `standardHeaders: only the following versions of the IETF draft specification are supported: ${Ce.join(", ")}.`);
1557
+ if (typeof e != "string" || !Ne.includes(e)) throw new L("ERR_ERL_HEADERS_UNSUPPORTED_DRAFT_VERSION", `standardHeaders: only the following versions of the IETF draft specification are supported: ${Ne.join(", ")}.`);
836
1558
  },
837
1559
  headersResetTime(e) {
838
- if (!e) throw new N("ERR_ERL_HEADERS_NO_RESET", "standardHeaders: 'draft-7' requires a 'resetTime', but the store did not provide one. The 'windowMs' value will be used instead, which may cause clients to wait longer than necessary.");
1560
+ if (!e) throw new L("ERR_ERL_HEADERS_NO_RESET", "standardHeaders: 'draft-7' requires a 'resetTime', but the store did not provide one. The 'windowMs' value will be used instead, which may cause clients to wait longer than necessary.");
839
1561
  },
840
1562
  knownOptions(e) {
841
1563
  if (!e) return;
@@ -847,6 +1569,7 @@ var xe = class {
847
1569
  legacyHeaders: !0,
848
1570
  standardHeaders: !0,
849
1571
  identifier: !0,
1572
+ retryAfter: !0,
850
1573
  requestPropertyName: !0,
851
1574
  skipFailedRequests: !0,
852
1575
  skipSuccessfulRequests: !0,
@@ -862,54 +1585,58 @@ var xe = class {
862
1585
  passOnStoreError: !0,
863
1586
  logger: !0
864
1587
  }).concat("draft_polli_ratelimit_headers", "delayAfter", "delayMs", "maxDelayMs");
865
- for (let n of Object.keys(e)) if (!t.includes(n)) throw new N("ERR_ERL_UNKNOWN_OPTION", `Unexpected configuration option: ${n}`);
1588
+ for (let n of Object.keys(e)) if (!t.includes(n)) throw new L("ERR_ERL_UNKNOWN_OPTION", `Unexpected configuration option: ${n}`);
866
1589
  },
867
1590
  validationsConfig() {
868
1591
  let e = Object.keys(this).filter((e) => !["enabled", "disable"].includes(e));
869
1592
  e.push("default");
870
- for (let t of Object.keys(this.enabled)) if (!e.includes(t)) throw new N("ERR_ERL_UNKNOWN_VALIDATION", `options.validate.${t} is not recognized. Supported validate options are: ${e.join(", ")}.`);
1593
+ for (let t of Object.keys(this.enabled)) if (!e.includes(t)) throw new L("ERR_ERL_UNKNOWN_VALIDATION", `options.validate.${t} is not recognized. Supported validate options are: ${e.join(", ")}.`);
871
1594
  },
872
1595
  creationStack(e) {
873
1596
  let { stack: t } = /* @__PURE__ */ Error("express-rate-limit validation check (set options.validate.creationStack=false to disable)");
874
- if (t?.includes("Layer.handle [as handle_request]") || t?.includes("Layer.handleRequest")) throw e.localKeys ? new N("ERR_ERL_CREATED_IN_REQUEST_HANDLER", "express-rate-limit instance should be created at app initialization, not when responding to a request.") : new N("ERR_ERL_CREATED_IN_REQUEST_HANDLER", "express-rate-limit instance should *usually* be created at app initialization, not when responding to a request.");
1597
+ if (t?.includes("Layer.handle [as handle_request]") || t?.includes("Layer.handleRequest")) throw e.localKeys ? new L("ERR_ERL_CREATED_IN_REQUEST_HANDLER", "express-rate-limit instance should be created at app initialization, not when responding to a request.") : new L("ERR_ERL_CREATED_IN_REQUEST_HANDLER", "express-rate-limit instance should *usually* be created at app initialization, not when responding to a request.");
875
1598
  },
876
1599
  ipv6Subnet(e) {
877
- if (e !== !1 && (!Number.isInteger(e) || e < 32 || e > 64)) throw new N("ERR_ERL_IPV6_SUBNET", `Unexpected ipv6Subnet value: ${e}. Expected an integer between 32 and 64 (usually 48-64).`);
1600
+ if (e !== !1 && (!Number.isInteger(e) || e < 32 || e > 64)) throw new L("ERR_ERL_IPV6_SUBNET", `Unexpected ipv6Subnet value: ${e}. Expected an integer between 32 and 64 (usually 48-64).`);
878
1601
  },
879
1602
  ipv6SubnetOrKeyGenerator(e) {
880
- if (e.ipv6Subnet !== void 0 && e.keyGenerator) throw new N("ERR_ERL_IPV6SUBNET_OR_KEYGENERATOR", "Incompatible options: the 'ipv6Subnet' option is ignored when a custom 'keyGenerator' function is also set.");
1603
+ if (e.ipv6Subnet !== void 0 && e.keyGenerator) throw new L("ERR_ERL_IPV6SUBNET_OR_KEYGENERATOR", "Incompatible options: the 'ipv6Subnet' option is ignored when a custom 'keyGenerator' function is also set.");
881
1604
  },
882
1605
  keyGeneratorIpFallback(e) {
883
1606
  if (!e) return;
884
1607
  let t = e.toString();
885
- if ((t.includes("req.ip") || t.includes("request.ip")) && !t.includes("ipKeyGenerator")) throw new N("ERR_ERL_KEY_GEN_IPV6", "Custom keyGenerator appears to use request IP without calling the ipKeyGenerator helper function for IPv6 addresses. This could allow IPv6 users to bypass limits.");
1608
+ if ((t.includes("req.ip") || t.includes("request.ip")) && !t.includes("ipKeyGenerator")) throw new L("ERR_ERL_KEY_GEN_IPV6", "Custom keyGenerator appears to use request IP without calling the ipKeyGenerator helper function for IPv6 addresses. This could allow IPv6 users to bypass limits.");
886
1609
  },
887
1610
  windowMs(e) {
888
1611
  let t = 2 ** 31 - 1;
889
- if (typeof e != "number" || Number.isNaN(e) || e < 1 || e > t) throw new N("ERR_ERL_WINDOW_MS", `Invalid windowMs value: ${e}${typeof e == "number" ? "" : ` (${typeof e})`}, must be a number between 1 and ${t} when using the default MemoryStore`);
1612
+ if (typeof e != "number" || Number.isNaN(e) || e < 1 || e > t) throw new L("ERR_ERL_WINDOW_MS", `Invalid windowMs value: ${e}${typeof e == "number" ? "" : ` (${typeof e})`}, must be a number between 1 and ${t} when using the default MemoryStore`);
890
1613
  }
891
1614
  };
892
- function Pe(e) {
1615
+ function We(e) {
893
1616
  if (typeof e != "object" || typeof e.error != "function" || typeof e.warn != "function") throw TypeError("Provided logger does not implement the Logger interface");
894
1617
  }
895
- var Fe = (e, t) => {
896
- Pe(t);
1618
+ var Ge = (e, t) => {
1619
+ We(t);
897
1620
  let n;
898
1621
  n = typeof e == "boolean" ? { default: e } : {
899
1622
  default: !0,
900
1623
  ...e
901
1624
  };
902
1625
  let r = { enabled: n };
903
- for (let [e, i] of Object.entries(Ne)) typeof i == "function" && (r[e] = (...a) => {
904
- if (n[e] ?? n.default) try {
905
- i.apply(r, a);
906
- } catch (e) {
907
- e instanceof P ? t.warn(e) : t.error(e);
1626
+ for (let [e, i] of Object.entries(Ue)) typeof i == "function" && (r[e] = (...a) => {
1627
+ if (n[e] ?? n.default) {
1628
+ n[e] = !1;
1629
+ try {
1630
+ i.apply(r, a);
1631
+ } catch (e) {
1632
+ e instanceof R ? t.warn(e) : t.error(e);
1633
+ }
908
1634
  }
909
1635
  });
910
- return r;
911
- }, Ie = (e) => typeof e.incr == "function" && typeof e.increment != "function", Le = (e) => {
912
- if (!Ie(e)) return e;
1636
+ let i = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
1637
+ return i && (r[i] = () => r.enabled), r;
1638
+ }, Ke = (e) => typeof e.incr == "function" && typeof e.increment != "function", qe = (e) => {
1639
+ if (!Ke(e)) return e;
913
1640
  let t = e;
914
1641
  class n {
915
1642
  async increment(e) {
@@ -934,25 +1661,25 @@ var Fe = (e, t) => {
934
1661
  }
935
1662
  }
936
1663
  return new n();
937
- }, Re = (e) => {
1664
+ }, Je = (e) => {
938
1665
  let { validations: t, ...n } = e;
939
1666
  return {
940
1667
  ...n,
941
1668
  validate: t.enabled
942
1669
  };
943
- }, ze = (e) => {
944
- let t = Ae(e), n = e.logger ?? Se, r = Fe(t?.validate ?? !0, n);
1670
+ }, Ye = (e) => {
1671
+ let t = Be(e), n = e.logger ?? Me, r = Ge(t?.validate ?? !0, n);
945
1672
  r.validationsConfig(), r.knownOptions(e), r.draftPolliHeaders(t.draft_polli_ratelimit_headers), r.onLimitReached(t.onLimitReached), t.ipv6Subnet !== void 0 && typeof t.ipv6Subnet != "function" && r.ipv6Subnet(t.ipv6Subnet), r.keyGeneratorIpFallback(t.keyGenerator), r.ipv6SubnetOrKeyGenerator(t);
946
1673
  let i = t.standardHeaders ?? !1;
947
1674
  i === !0 && (i = "draft-6");
948
1675
  let a = {
949
- windowMs: 60 * 1e3,
1676
+ windowMs: 6e4,
950
1677
  limit: e.max ?? 5,
951
1678
  message: "Too many requests, please try again later.",
952
1679
  statusCode: 429,
953
1680
  legacyHeaders: e.headers ?? !0,
954
1681
  identifier(e, t) {
955
- let n = "", { limit: r } = e[a.requestPropertyName], i = a.windowMs / 1e3, o = a.windowMs / (1e3 * 60), s = a.windowMs / (1e3 * 60 * 60), c = a.windowMs / (1e3 * 60 * 60 * 24);
1682
+ let n = "", { limit: r } = e[a.requestPropertyName], i = a.windowMs / 1e3, o = a.windowMs / 6e4, s = a.windowMs / 36e5, c = a.windowMs / 864e5;
956
1683
  return n = i < 60 ? `${i}sec` : o < 60 ? `${o}min` : s < 24 ? `${s}hr${s > 1 ? "s" : ""}` : `${c}day${c > 1 ? "s" : ""}`, `${r}-in-${n}`;
957
1684
  },
958
1685
  requestPropertyName: "rateLimit",
@@ -963,7 +1690,7 @@ var Fe = (e, t) => {
963
1690
  async keyGenerator(e, t) {
964
1691
  r.ip(e.ip), r.trustProxy(e), r.xForwardedForHeader(e), r.forwardedHeader(e);
965
1692
  let n = e.ip, i = 56;
966
- return d(n) && (i = typeof a.ipv6Subnet == "function" ? await a.ipv6Subnet(e, t) : a.ipv6Subnet, typeof a.ipv6Subnet == "function" && r.ipv6Subnet(i)), be(n, i);
1693
+ return d(n) && (i = typeof a.ipv6Subnet == "function" ? await a.ipv6Subnet(e, t) : a.ipv6Subnet, typeof a.ipv6Subnet == "function" && r.ipv6Subnet(i)), Ae(n, i);
967
1694
  },
968
1695
  ipv6Subnet: 56,
969
1696
  async handler(e, t, n, r) {
@@ -974,97 +1701,113 @@ var Fe = (e, t) => {
974
1701
  passOnStoreError: !1,
975
1702
  ...t,
976
1703
  standardHeaders: i,
977
- store: Le(t.store ?? new xe(r)),
1704
+ store: qe(t.store ?? new je(r)),
978
1705
  validations: r,
979
1706
  logger: n
980
1707
  };
981
1708
  if (typeof a.store.increment != "function" || typeof a.store.decrement != "function" || typeof a.store.resetKey != "function" || a.store.resetAll !== void 0 && typeof a.store.resetAll != "function" || a.store.init !== void 0 && typeof a.store.init != "function") throw TypeError("An invalid store was passed. Please ensure that the store is a class that implements the `Store` interface.");
982
1709
  return a;
983
- }, Be = (e) => async (t, n, r) => {
1710
+ }, Xe = (e) => async (t, n, r) => {
984
1711
  try {
985
1712
  await Promise.resolve(e(t, n, r)).catch(r);
986
1713
  } catch (e) {
987
1714
  r(e);
988
1715
  }
989
- }, Ve = (e) => {
990
- let t = ze(e ?? {}), n = Re(t);
991
- if (t.validations.creationStack(t.store), t.validations.unsharedStore(t.store), typeof t.store.init == "function") try {
992
- let e = t.store.init(n);
993
- e instanceof Promise && e.catch((e) => t.logger.error(e, "express-rate-limit: async error during store initialization."));
994
- } catch (e) {
995
- t.logger.error(e, "express-rate-limit: error during store initialization.");
1716
+ }, Ze = (e) => {
1717
+ let t = Ye(e ?? {}), n = Je(t), r = (0, Oe.default)("express-rate-limit");
1718
+ r("creating new rate limiter with %o", t.store.constructor.name);
1719
+ for (let [e, n] of Object.entries(t)) r("set %s to %o", e, n);
1720
+ if (t.validations.creationStack(t.store), t.validations.unsharedStore(t.store), typeof t.store.init == "function") {
1721
+ r("executing init for store");
1722
+ try {
1723
+ let e = t.store.init(n);
1724
+ e instanceof Promise && e.catch((e) => t.logger.error(e, "express-rate-limit: async error during store initialization."));
1725
+ } catch (e) {
1726
+ t.logger.error(e, "express-rate-limit: error during store initialization.");
1727
+ }
996
1728
  }
997
- let r = Be(async (e, r, i) => {
998
- let a = t.skipFailedRequests && new Promise((e) => r.once("close", e)), o = (t.skipFailedRequests || t.skipSuccessfulRequests) && new Promise((e) => r.once("finish", e)), s = t.skipFailedRequests && new Promise((e) => r.once("error", e));
999
- if (await t.skip(e, r)) {
1000
- i();
1729
+ let i = Xe(async (e, i, a) => {
1730
+ let o = t.skipFailedRequests && new Promise((e) => i.once("close", e)), s = (t.skipFailedRequests || t.skipSuccessfulRequests) && new Promise((e) => i.once("finish", e)), c = t.skipFailedRequests && new Promise((e) => i.once("error", e));
1731
+ if (r("requested %o", e.originalUrl), r("request from ip %o", e.ip), await t.skip(e, i)) {
1732
+ r("skipping request"), a();
1001
1733
  return;
1002
1734
  }
1003
- let c = e, l = await t.keyGenerator(e, r), u = 0, d;
1735
+ let l = e, u = await t.keyGenerator(e, i);
1736
+ r("computed key %o", u), r("incrementing count");
1737
+ let d = 0, f;
1004
1738
  try {
1005
- let e = await t.store.increment(l);
1006
- u = e.totalHits, d = e.resetTime;
1739
+ let e = await t.store.increment(u);
1740
+ d = e.totalHits, f = e.resetTime;
1007
1741
  } catch (e) {
1008
1742
  if (t.passOnStoreError) {
1009
- t.logger.error(e, "express-rate-limit: error from store, allowing request without rate-limiting."), i();
1743
+ t.logger.error(e, "express-rate-limit: error from store, allowing request without rate-limiting."), a();
1010
1744
  return;
1011
1745
  }
1012
1746
  throw e;
1013
1747
  }
1014
- t.validations.positiveHits(u), t.validations.singleCount(e, t.store, l);
1015
- let f = await (typeof t.limit == "function" ? t.limit(e, r) : t.limit);
1016
- t.validations.limit(f);
1017
- let p = {
1018
- limit: f,
1019
- used: u,
1020
- remaining: Math.max(f - u, 0),
1021
- resetTime: d,
1022
- key: l
1748
+ t.validations.positiveHits(d), t.validations.singleCount(e, t.store, u);
1749
+ let p = await (typeof t.limit == "function" ? t.limit(e, i) : t.limit);
1750
+ t.validations.limit(p);
1751
+ let m = {
1752
+ limit: p,
1753
+ used: d,
1754
+ remaining: Math.max(p - d, 0),
1755
+ resetTime: f,
1756
+ key: u
1023
1757
  };
1024
- if (Object.defineProperty(p, "current", {
1758
+ for (let [e, n] of Object.entries(m)) r("set request.%s.%s to be %o", t.requestPropertyName, e, n);
1759
+ if (Object.defineProperty(m, "current", {
1025
1760
  configurable: !1,
1026
1761
  enumerable: !1,
1027
- value: u
1028
- }), c[t.requestPropertyName] = p, t.legacyHeaders && !r.headersSent && Te(r, p), t.standardHeaders && !r.headersSent) switch (t.standardHeaders) {
1762
+ value: d
1763
+ }), l[t.requestPropertyName] = m, t.legacyHeaders && !i.headersSent && (r("set legacy headers"), Fe(i, m)), t.standardHeaders && !i.headersSent) switch (t.standardHeaders) {
1029
1764
  case "draft-6":
1030
- Ee(r, p, t.windowMs);
1765
+ r("set ietf draft 6 headers"), Ie(i, m, t.windowMs);
1031
1766
  break;
1032
1767
  case "draft-7":
1033
- t.validations.headersResetTime(p.resetTime), De(r, p, t.windowMs);
1768
+ r("set ietf draft 7 headers"), t.validations.headersResetTime(m.resetTime), Le(i, m, t.windowMs);
1034
1769
  break;
1035
1770
  case "draft-8": {
1036
- let n = await (typeof t.identifier == "function" ? t.identifier(e, r) : t.identifier);
1037
- t.validations.headersResetTime(p.resetTime), Oe(r, p, t.windowMs, n, l);
1771
+ let n = await (typeof t.identifier == "function" ? t.identifier(e, i) : t.identifier);
1772
+ r("set ietf draft 8 headers"), r("set name to %o", n), t.validations.headersResetTime(m.resetTime), Re(i, m, t.windowMs, n, u);
1038
1773
  break;
1039
1774
  }
1040
- default:
1041
- t.validations.headersDraftVersion(t.standardHeaders);
1042
- break;
1775
+ default: t.validations.headersDraftVersion(t.standardHeaders);
1043
1776
  }
1044
1777
  if (t.skipFailedRequests || t.skipSuccessfulRequests) {
1045
- let n = !1, i = async () => {
1046
- n ||= (await t.store.decrement(l), !0);
1778
+ let n = !1, a = async () => {
1779
+ if (!n) {
1780
+ if (f && Date.now() >= f.getTime()) return;
1781
+ r("decrementing count"), await t.store.decrement(u), n = !0;
1782
+ }
1047
1783
  };
1048
- t.skipFailedRequests && (o && o.then(async () => {
1049
- await t.requestWasSuccessful(e, r) || await i();
1050
- }), a && a.then(async () => {
1051
- r.writableEnded || await i();
1052
- }), s && s.then(async () => {
1053
- await i();
1054
- })), t.skipSuccessfulRequests && o && o.then(async () => {
1055
- await t.requestWasSuccessful(e, r) && await i();
1784
+ t.skipFailedRequests && (s && s.then(async () => {
1785
+ let n = await t.requestWasSuccessful(e, i);
1786
+ r("computed requestWasSuccessful as %o", n), n || await a();
1787
+ }), o && o.then(async () => {
1788
+ i.writableEnded || await a();
1789
+ }), c && c.then(async () => {
1790
+ await a();
1791
+ })), t.skipSuccessfulRequests && s && s.then(async () => {
1792
+ let n = await t.requestWasSuccessful(e, i);
1793
+ r("computed requestWasSuccessful as %o", n), n && await a();
1056
1794
  });
1057
1795
  }
1058
- if (t.validations.disable(), u > f) {
1059
- (t.legacyHeaders || t.standardHeaders) && ke(r, p, t.windowMs), t.handler(e, r, i, n);
1796
+ if (d > p) {
1797
+ if (r("limit exceeded"), t.legacyHeaders || t.standardHeaders) {
1798
+ r("set retry-after header");
1799
+ let n = await (typeof t.retryAfter == "function" ? t.retryAfter(e, i) : t.retryAfter);
1800
+ ze(i, m, t.windowMs, n);
1801
+ }
1802
+ t.handler(e, i, a, n);
1060
1803
  return;
1061
1804
  }
1062
- i();
1805
+ a();
1063
1806
  });
1064
- return r.resetKey = t.store.resetKey.bind(t.store), r.getKey = typeof t.store.get == "function" ? t.store.get.bind(t.store) : () => {
1807
+ return i.resetKey = t.store.resetKey.bind(t.store), i.getKey = typeof t.store.get == "function" ? t.store.get.bind(t.store) : () => {
1065
1808
  throw Error("The current store does not support the get/getKey method");
1066
- }, r;
1067
- }, He = new Set([
1809
+ }, i;
1810
+ }, Qe = /* @__PURE__ */ new Set([
1068
1811
  "token",
1069
1812
  "accesstoken",
1070
1813
  "refreshtoken",
@@ -1077,11 +1820,11 @@ var Fe = (e, t) => {
1077
1820
  "password",
1078
1821
  "secret"
1079
1822
  ]);
1080
- function Ue(e) {
1823
+ function $e(e) {
1081
1824
  return e.toLowerCase().replace(/[^a-z0-9]/g, "");
1082
1825
  }
1083
- function F(e, t) {
1084
- for (let e of Object.keys(t)) if (He.has(Ue(e))) throw Error(`OAuth audit event must not carry forbidden field: ${e}`);
1826
+ function z(e, t) {
1827
+ for (let e of Object.keys(t)) if (Qe.has($e(e))) throw Error(`OAuth audit event must not carry forbidden field: ${e}`);
1085
1828
  let { now: n, ...r } = t;
1086
1829
  return {
1087
1830
  kind: e,
@@ -1089,7 +1832,7 @@ function F(e, t) {
1089
1832
  ...r
1090
1833
  };
1091
1834
  }
1092
- function We(e) {
1835
+ function et(e) {
1093
1836
  let t = !1;
1094
1837
  return (n) => {
1095
1838
  try {
@@ -1099,7 +1842,7 @@ function We(e) {
1099
1842
  }
1100
1843
  };
1101
1844
  }
1102
- function Ge(e = process.stderr) {
1845
+ function tt(e = process.stderr) {
1103
1846
  return (t) => {
1104
1847
  e.write(`${JSON.stringify({
1105
1848
  source: "codemem-mcp-oauth-audit",
@@ -1107,28 +1850,28 @@ function Ge(e = process.stderr) {
1107
1850
  })}\n`);
1108
1851
  };
1109
1852
  }
1110
- function Ke() {
1853
+ function nt() {
1111
1854
  return () => {};
1112
1855
  }
1113
- function qe(e = process.env.CODEMEM_MCP_AUDIT) {
1856
+ function rt(e = process.env.CODEMEM_MCP_AUDIT) {
1114
1857
  let t = e?.trim().toLowerCase();
1115
- return t === "0" || t === "false" || t === "no" ? Ke() : Ge();
1858
+ return t === "0" || t === "false" || t === "no" ? nt() : tt();
1116
1859
  }
1117
- var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github.com/kunickiaj/codemem#readme", Ye = "https://claude.ai/api/mcp/auth_callback", Xe = "https://chatgpt.com/connector_platform_oauth_redirect", Ze = new Set([
1860
+ var it = "codemem MCP", at = ["memory:read", "memory:write"], ot = "https://github.com/kunickiaj/codemem#readme", st = "https://claude.ai/api/mcp/auth_callback", ct = "https://chatgpt.com/connector_platform_oauth_redirect", lt = /* @__PURE__ */ new Set([
1118
1861
  "localhost",
1119
1862
  "127.0.0.1",
1120
1863
  "::1"
1121
- ]), Qe = new Set(["authorization_code", "refresh_token"]), $e = new Set(["code"]), R = 3600, z = 720 * 60 * 60, et = 100, tt = 100, nt = 100, rt = 32, it = 43, at = /^[A-Za-z0-9_-]{43}$/, ot = /^[A-Za-z0-9_-]{43}$/, st = /^[A-Za-z0-9_-]{1,128}$/, ct = class {
1864
+ ]), ut = /* @__PURE__ */ new Set(["authorization_code", "refresh_token"]), dt = /* @__PURE__ */ new Set(["code"]), B = 3600, V = 2592e3, ft = 100, pt = 100, mt = 100, ht = 32, gt = 43, _t = /^[A-Za-z0-9_-]{43}$/, vt = /^[A-Za-z0-9_-]{43}$/, yt = /^[A-Za-z0-9_-]{1,128}$/, bt = class {
1122
1865
  #e = /* @__PURE__ */ new Map();
1123
1866
  getClient(e) {
1124
1867
  return this.#e.get(e);
1125
1868
  }
1126
1869
  registerClient(e) {
1127
- let t = wt(e.redirect_uris);
1128
- if (t) throw new D(t);
1129
- if (e.client_secret || e.token_endpoint_auth_method !== "none") throw new D("Only public clients with token_endpoint_auth_method=none are supported");
1130
- if (e.grant_types && !B(e.grant_types, Qe)) throw new D("Only authorization_code and refresh_token grant_types are supported");
1131
- if (e.response_types && !B(e.response_types, $e)) throw new D("Only code response_type is supported");
1870
+ let t = It(e.redirect_uris);
1871
+ if (t) throw new j(t);
1872
+ if (e.client_secret || e.token_endpoint_auth_method !== "none") throw new j("Only public clients with token_endpoint_auth_method=none are supported");
1873
+ if (e.grant_types && !H(e.grant_types, ut)) throw new j("Only authorization_code and refresh_token grant_types are supported");
1874
+ if (e.response_types && !H(e.response_types, dt)) throw new j("Only code response_type is supported");
1132
1875
  if (this.#e.size >= 100) {
1133
1876
  let e = this.#e.keys().next().value;
1134
1877
  e && this.#e.delete(e);
@@ -1143,10 +1886,10 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1143
1886
  };
1144
1887
  return this.#e.set(n.client_id, n), n;
1145
1888
  }
1146
- }, lt = class {
1889
+ }, xt = class {
1147
1890
  #e = /* @__PURE__ */ new Map();
1148
1891
  issueCode(e, t = Date.now()) {
1149
- if (this.#t(t), this.#e.size >= et) return;
1892
+ if (this.#t(t), this.#e.size >= ft) return;
1150
1893
  let n = o();
1151
1894
  return this.#e.set(n, {
1152
1895
  ...e,
@@ -1164,12 +1907,12 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1164
1907
  #t(e) {
1165
1908
  for (let [t, n] of this.#e) n.expiresAt <= e && this.#e.delete(t);
1166
1909
  }
1167
- }, ut = class {
1910
+ }, St = class {
1168
1911
  #e = /* @__PURE__ */ new Map();
1169
1912
  #t = a(32);
1170
1913
  issueToken(e, t = Date.now(), n, r, i = []) {
1171
- if (this.#n(t), this.#e.size >= tt) return;
1172
- let o = a(rt), s = K(o, this.#t);
1914
+ if (this.#n(t), this.#e.size >= pt) return;
1915
+ let o = a(ht), s = Wt(o, this.#t);
1173
1916
  return this.#e.set(s, {
1174
1917
  clientId: e,
1175
1918
  grantId: r,
@@ -1177,22 +1920,22 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1177
1920
  resource: n,
1178
1921
  tokenHash: s,
1179
1922
  issuedAt: t,
1180
- expiresAt: t + R * 1e3,
1923
+ expiresAt: t + B * 1e3,
1181
1924
  lastUsedAt: null,
1182
1925
  revokedAt: null
1183
1926
  }), {
1184
1927
  token: o.toString("base64url"),
1185
- expiresIn: R
1928
+ expiresIn: B
1186
1929
  };
1187
1930
  }
1188
1931
  verifyToken(e, t = Date.now()) {
1189
- let n = H(e);
1932
+ let n = W(e);
1190
1933
  if (!n) return {
1191
1934
  ok: !1,
1192
1935
  reason: "unknown_token"
1193
1936
  };
1194
- let r = K(n, this.#t), i = this.#e.get(r);
1195
- return !i || !q(i.tokenHash, r) ? {
1937
+ let r = Wt(n, this.#t), i = this.#e.get(r);
1938
+ return !i || !J(i.tokenHash, r) ? {
1196
1939
  ok: !1,
1197
1940
  reason: "unknown_token"
1198
1941
  } : i.revokedAt === null ? i.expiresAt <= t ? {
@@ -1207,27 +1950,27 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1207
1950
  };
1208
1951
  }
1209
1952
  revokeToken(e, t = Date.now()) {
1210
- let n = H(e);
1953
+ let n = W(e);
1211
1954
  if (!n) return !1;
1212
- let r = K(n, this.#t), i = this.#e.get(r);
1213
- return !i || !q(i.tokenHash, r) ? !1 : (i.revokedAt === null && (i.revokedAt = t), !0);
1955
+ let r = Wt(n, this.#t), i = this.#e.get(r);
1956
+ return !i || !J(i.tokenHash, r) ? !1 : (i.revokedAt === null && (i.revokedAt = t), !0);
1214
1957
  }
1215
1958
  revokeTokensForGrant(e, t = Date.now()) {
1216
1959
  let n = 0;
1217
- for (let r of this.#e.values()) r.grantId !== e || r.revokedAt !== null || (r.revokedAt = t, n += 1);
1960
+ for (let r of this.#e.values()) r.grantId === e && r.revokedAt === null && (r.revokedAt = t, n += 1);
1218
1961
  return n;
1219
1962
  }
1220
1963
  #n(e) {
1221
1964
  for (let [t, n] of this.#e) (n.expiresAt <= e || n.revokedAt !== null) && this.#e.delete(t);
1222
1965
  }
1223
- }, dt = class {
1966
+ }, Ct = class {
1224
1967
  #e = /* @__PURE__ */ new Map();
1225
1968
  #t = /* @__PURE__ */ new Map();
1226
1969
  #n = /* @__PURE__ */ new Map();
1227
1970
  #r = a(32);
1228
1971
  issueGrant(e, t = Date.now()) {
1229
- if (this.#i(t), this.#e.size >= nt) return;
1230
- let n = U(), r = W(n, this.#r);
1972
+ if (this.#i(t), this.#e.size >= mt) return;
1973
+ let n = G(), r = K(n, this.#r);
1231
1974
  if (!r) return;
1232
1975
  let i = {
1233
1976
  grantId: o(),
@@ -1237,21 +1980,21 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1237
1980
  currentRefreshTokenHash: r,
1238
1981
  previousRefreshTokenHash: null,
1239
1982
  issuedAt: t,
1240
- expiresAt: t + z * 1e3,
1983
+ expiresAt: t + V * 1e3,
1241
1984
  rotatedAt: null,
1242
1985
  revokedAt: null
1243
1986
  };
1244
- return this.#e.set(i.grantId, i), this.#t.set(r, i.grantId), this.#n.set(i.grantId, new Set([r])), {
1987
+ return this.#e.set(i.grantId, i), this.#t.set(r, i.grantId), this.#n.set(i.grantId, /* @__PURE__ */ new Set([r])), {
1245
1988
  grant: {
1246
1989
  ...i,
1247
1990
  scopes: [...i.scopes]
1248
1991
  },
1249
1992
  refreshToken: n,
1250
- expiresIn: z
1993
+ expiresIn: V
1251
1994
  };
1252
1995
  }
1253
1996
  rotateRefreshToken(e, t, n = {}, r = Date.now()) {
1254
- let i = W(t, this.#r);
1997
+ let i = K(t, this.#r);
1255
1998
  if (!i) return {
1256
1999
  ok: !1,
1257
2000
  reason: "unknown_refresh_token"
@@ -1281,7 +2024,7 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1281
2024
  reason: "client_mismatch",
1282
2025
  grantId: a
1283
2026
  };
1284
- if (!Nt(n.scopes ?? o.scopes, o.scopes)) return {
2027
+ if (!Kt(n.scopes ?? o.scopes, o.scopes)) return {
1285
2028
  ok: !1,
1286
2029
  reason: "scope_mismatch",
1287
2030
  grantId: a
@@ -1291,13 +2034,13 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1291
2034
  reason: "resource_mismatch",
1292
2035
  grantId: a
1293
2036
  };
1294
- let s = q(o.currentRefreshTokenHash, i), c = o.previousRefreshTokenHash !== null && q(o.previousRefreshTokenHash, i);
2037
+ let s = J(o.currentRefreshTokenHash, i), c = o.previousRefreshTokenHash !== null && J(o.previousRefreshTokenHash, i);
1295
2038
  if (!s && !c) return this.revokeGrant(a, r), {
1296
2039
  ok: !1,
1297
2040
  reason: "refresh_token_replay",
1298
2041
  grantId: a
1299
2042
  };
1300
- let l = U(), u = W(l, this.#r);
2043
+ let l = G(), u = K(l, this.#r);
1301
2044
  return u ? (o.scopes = [...n.scopes ?? o.scopes], o.previousRefreshTokenHash = s ? o.currentRefreshTokenHash : null, o.currentRefreshTokenHash = u, o.rotatedAt = r, this.#t.set(u, a), this.#n.get(a)?.add(u), {
1302
2045
  ok: !0,
1303
2046
  grant: {
@@ -1312,14 +2055,14 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1312
2055
  };
1313
2056
  }
1314
2057
  revokeRefreshToken(e, t = Date.now()) {
1315
- let n = W(e, this.#r);
2058
+ let n = K(e, this.#r);
1316
2059
  if (!n) return;
1317
2060
  let r = this.#t.get(n);
1318
2061
  if (r) return this.revokeGrant(r, t), r;
1319
2062
  }
1320
2063
  revokeGrant(e, t = Date.now()) {
1321
2064
  let n = this.#e.get(e);
1322
- return n ? n.revokedAt === null ? (n.revokedAt = t, this.#a(n), !0) : !0 : !1;
2065
+ return n ? n.revokedAt !== null || (n.revokedAt = t, this.#a(n), !0) : !1;
1323
2066
  }
1324
2067
  #i(e) {
1325
2068
  for (let [t, n] of this.#e) n.expiresAt > e && n.revokedAt === null || (this.#e.delete(t), this.#a(n));
@@ -1333,7 +2076,7 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1333
2076
  }
1334
2077
  this.#t.delete(e.currentRefreshTokenHash), e.previousRefreshTokenHash && this.#t.delete(e.previousRefreshTokenHash);
1335
2078
  }
1336
- }, ft = class {
2079
+ }, wt = class {
1337
2080
  #e;
1338
2081
  #t = /* @__PURE__ */ new Map();
1339
2082
  #n = /* @__PURE__ */ new Map();
@@ -1341,18 +2084,18 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1341
2084
  #i = /* @__PURE__ */ new Map();
1342
2085
  #a = /* @__PURE__ */ new Map();
1343
2086
  #o = /* @__PURE__ */ new Map();
1344
- constructor(e = vt()) {
2087
+ constructor(e = At()) {
1345
2088
  this.#e = e, this.#s();
1346
2089
  }
1347
2090
  getClient(e) {
1348
2091
  return this.#n.get(e);
1349
2092
  }
1350
2093
  registerClient(e) {
1351
- let t = wt(e.redirect_uris);
1352
- if (t) throw new D(t);
1353
- if (e.client_secret || e.token_endpoint_auth_method !== "none") throw new D("Only public clients with token_endpoint_auth_method=none are supported");
1354
- if (e.grant_types && !B(e.grant_types, Qe)) throw new D("Only authorization_code and refresh_token grant_types are supported");
1355
- if (e.response_types && !B(e.response_types, $e)) throw new D("Only code response_type is supported");
2094
+ let t = It(e.redirect_uris);
2095
+ if (t) throw new j(t);
2096
+ if (e.client_secret || e.token_endpoint_auth_method !== "none") throw new j("Only public clients with token_endpoint_auth_method=none are supported");
2097
+ if (e.grant_types && !H(e.grant_types, ut)) throw new j("Only authorization_code and refresh_token grant_types are supported");
2098
+ if (e.response_types && !H(e.response_types, dt)) throw new j("Only code response_type is supported");
1356
2099
  if (this.#u(Date.now()), this.#n.size >= 100) {
1357
2100
  let e = this.#n.keys().next().value;
1358
2101
  e && this.#n.delete(e);
@@ -1368,7 +2111,7 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1368
2111
  return this.#n.set(n.client_id, n), this.#c(), n;
1369
2112
  }
1370
2113
  issueCode(e, t = Date.now()) {
1371
- if (this.#l(t), this.#t.size >= et) return;
2114
+ if (this.#l(t), this.#t.size >= ft) return;
1372
2115
  let n = o();
1373
2116
  return this.#t.set(n, {
1374
2117
  ...e,
@@ -1384,8 +2127,8 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1384
2127
  if (!(!t || t.used)) return t.used = !0, t;
1385
2128
  }
1386
2129
  issueToken(e, t = Date.now(), n, r, i = []) {
1387
- if (this.#u(t), this.#r.size >= tt) return;
1388
- let a = U(), o = G(a);
2130
+ if (this.#u(t), this.#r.size >= pt) return;
2131
+ let a = G(), o = q(a);
1389
2132
  if (o) return this.#r.set(o, {
1390
2133
  clientId: e,
1391
2134
  grantId: r,
@@ -1393,22 +2136,22 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1393
2136
  resource: n,
1394
2137
  tokenHash: o,
1395
2138
  issuedAt: t,
1396
- expiresAt: t + R * 1e3,
2139
+ expiresAt: t + B * 1e3,
1397
2140
  lastUsedAt: null,
1398
2141
  revokedAt: null
1399
2142
  }), this.#c(), {
1400
2143
  token: a,
1401
- expiresIn: R
2144
+ expiresIn: B
1402
2145
  };
1403
2146
  }
1404
2147
  verifyToken(e, t = Date.now()) {
1405
- let n = G(e);
2148
+ let n = q(e);
1406
2149
  if (!n) return {
1407
2150
  ok: !1,
1408
2151
  reason: "unknown_token"
1409
2152
  };
1410
2153
  let r = this.#r.get(n);
1411
- return !r || !q(r.tokenHash, n) ? {
2154
+ return !r || !J(r.tokenHash, n) ? {
1412
2155
  ok: !1,
1413
2156
  reason: "unknown_token"
1414
2157
  } : r.revokedAt === null ? r.expiresAt <= t ? {
@@ -1426,19 +2169,19 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1426
2169
  };
1427
2170
  }
1428
2171
  revokeToken(e, t = Date.now()) {
1429
- let n = G(e);
2172
+ let n = q(e);
1430
2173
  if (!n) return !1;
1431
2174
  let r = this.#r.get(n);
1432
- return !r || !q(r.tokenHash, n) ? !1 : r.revokedAt === null ? (r.revokedAt = t, this.#c(), !0) : !0;
2175
+ return !r || !J(r.tokenHash, n) ? !1 : r.revokedAt !== null || (r.revokedAt = t, this.#c(), !0);
1433
2176
  }
1434
2177
  revokeTokensForGrant(e, t = Date.now()) {
1435
2178
  let n = 0;
1436
- for (let r of this.#r.values()) r.grantId !== e || r.revokedAt !== null || (r.revokedAt = t, n += 1);
2179
+ for (let r of this.#r.values()) r.grantId === e && r.revokedAt === null && (r.revokedAt = t, n += 1);
1437
2180
  return n > 0 && this.#c(), n;
1438
2181
  }
1439
2182
  issueGrant(e, t = Date.now()) {
1440
- if (this.#u(t), this.#i.size >= nt) return;
1441
- let n = U(), r = G(n);
2183
+ if (this.#u(t), this.#i.size >= mt) return;
2184
+ let n = G(), r = q(n);
1442
2185
  if (!r) return;
1443
2186
  let i = {
1444
2187
  grantId: o(),
@@ -1448,21 +2191,21 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1448
2191
  currentRefreshTokenHash: r,
1449
2192
  previousRefreshTokenHash: null,
1450
2193
  issuedAt: t,
1451
- expiresAt: t + z * 1e3,
2194
+ expiresAt: t + V * 1e3,
1452
2195
  rotatedAt: null,
1453
2196
  revokedAt: null
1454
2197
  };
1455
- return this.#i.set(i.grantId, i), this.#a.set(r, i.grantId), this.#o.set(i.grantId, new Set([r])), this.#c(), {
2198
+ return this.#i.set(i.grantId, i), this.#a.set(r, i.grantId), this.#o.set(i.grantId, /* @__PURE__ */ new Set([r])), this.#c(), {
1456
2199
  grant: {
1457
2200
  ...i,
1458
2201
  scopes: [...i.scopes]
1459
2202
  },
1460
2203
  refreshToken: n,
1461
- expiresIn: z
2204
+ expiresIn: V
1462
2205
  };
1463
2206
  }
1464
2207
  rotateRefreshToken(e, t, n = {}, r = Date.now()) {
1465
- let i = G(t);
2208
+ let i = q(t);
1466
2209
  if (!i) return {
1467
2210
  ok: !1,
1468
2211
  reason: "unknown_refresh_token"
@@ -1492,7 +2235,7 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1492
2235
  reason: "client_mismatch",
1493
2236
  grantId: a
1494
2237
  };
1495
- if (!Nt(n.scopes ?? o.scopes, o.scopes)) return {
2238
+ if (!Kt(n.scopes ?? o.scopes, o.scopes)) return {
1496
2239
  ok: !1,
1497
2240
  reason: "scope_mismatch",
1498
2241
  grantId: a
@@ -1502,13 +2245,13 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1502
2245
  reason: "resource_mismatch",
1503
2246
  grantId: a
1504
2247
  };
1505
- let s = q(o.currentRefreshTokenHash, i), c = o.previousRefreshTokenHash !== null && q(o.previousRefreshTokenHash, i);
2248
+ let s = J(o.currentRefreshTokenHash, i), c = o.previousRefreshTokenHash !== null && J(o.previousRefreshTokenHash, i);
1506
2249
  if (!s && !c) return this.revokeGrant(a, r), {
1507
2250
  ok: !1,
1508
2251
  reason: "refresh_token_replay",
1509
2252
  grantId: a
1510
2253
  };
1511
- let l = U(), u = G(l);
2254
+ let l = G(), u = q(l);
1512
2255
  return u ? (o.scopes = [...n.scopes ?? o.scopes], o.previousRefreshTokenHash = s ? o.currentRefreshTokenHash : null, o.currentRefreshTokenHash = u, o.rotatedAt = r, this.#a.set(u, a), this.#o.get(a)?.add(u), this.#c(), {
1513
2256
  ok: !0,
1514
2257
  grant: {
@@ -1523,20 +2266,20 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1523
2266
  };
1524
2267
  }
1525
2268
  revokeRefreshToken(e, t = Date.now()) {
1526
- let n = G(e);
2269
+ let n = q(e);
1527
2270
  if (!n) return;
1528
2271
  let r = this.#a.get(n);
1529
2272
  if (r) return this.revokeGrant(r, t), r;
1530
2273
  }
1531
2274
  revokeGrant(e, t = Date.now()) {
1532
2275
  let n = this.#i.get(e);
1533
- return n ? n.revokedAt === null ? (n.revokedAt = t, this.#d(n), this.#c(), !0) : !0 : !1;
2276
+ return n ? n.revokedAt !== null || (n.revokedAt = t, this.#d(n), this.#c(), !0) : !1;
1534
2277
  }
1535
2278
  #s() {
1536
- if (!v(this.#e)) return;
2279
+ if (!S(this.#e)) return;
1537
2280
  let e;
1538
2281
  try {
1539
- e = JSON.parse(ie(this.#e, "utf8"));
2282
+ e = JSON.parse(ee(this.#e, "utf8"));
1540
2283
  } catch {
1541
2284
  return;
1542
2285
  }
@@ -1551,7 +2294,7 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1551
2294
  }
1552
2295
  }
1553
2296
  #c() {
1554
- y(w(this.#e), {
2297
+ C(O(this.#e), {
1555
2298
  recursive: !0,
1556
2299
  mode: 448
1557
2300
  });
@@ -1562,7 +2305,7 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1562
2305
  refreshGrants: [...this.#i.values()],
1563
2306
  refreshHashesByGrantId: Object.fromEntries([...this.#o.entries()].map(([e, t]) => [e, [...t]]))
1564
2307
  }, t = `${this.#e}.${process.pid}.${Date.now()}.tmp`;
1565
- x(t, `${JSON.stringify(e, null, 2)}\n`, { mode: 384 }), b(t, this.#e), S(this.#e, 384).catch(() => void 0);
2308
+ T(t, `${JSON.stringify(e, null, 2)}\n`, { mode: 384 }), w(t, this.#e), E(this.#e, 384).catch(() => void 0);
1566
2309
  }
1567
2310
  #l(e) {
1568
2311
  for (let [t, n] of this.#t) n.expiresAt <= e && this.#t.delete(t);
@@ -1583,58 +2326,58 @@ var Je = "codemem MCP", I = ["memory:read", "memory:write"], L = "https://github
1583
2326
  this.#a.delete(e.currentRefreshTokenHash), e.previousRefreshTokenHash && this.#a.delete(e.previousRefreshTokenHash);
1584
2327
  }
1585
2328
  };
1586
- function pt() {
1587
- return new ct();
2329
+ function Tt() {
2330
+ return new bt();
1588
2331
  }
1589
- function mt() {
1590
- return new lt();
2332
+ function Et() {
2333
+ return new xt();
1591
2334
  }
1592
- function ht() {
1593
- return new ut();
2335
+ function Dt() {
2336
+ return new St();
1594
2337
  }
1595
- function gt() {
1596
- return new dt();
2338
+ function Ot() {
2339
+ return new Ct();
1597
2340
  }
1598
- function _t(e) {
1599
- return new ft(e);
2341
+ function kt(e) {
2342
+ return new wt(e);
1600
2343
  }
1601
- function vt() {
1602
- return T(process.env.HOME?.trim() || C(), ".codemem", "mcp-oauth-state.json");
2344
+ function At() {
2345
+ return k(process.env.HOME?.trim() || D(), ".codemem", "mcp-oauth-state.json");
1603
2346
  }
1604
- function yt(e) {
1605
- let t = Ct(St(e.mcpUrl));
2347
+ function jt(e) {
2348
+ let t = Ft(Pt(e.mcpUrl)), n = qt(e.clientsStore);
1606
2349
  return {
1607
2350
  ...g({
1608
- provider: Pt(e.clientsStore),
2351
+ provider: n,
1609
2352
  issuerUrl: t,
1610
2353
  baseUrl: t
1611
2354
  }),
1612
2355
  grant_types_supported: ["authorization_code", "refresh_token"],
1613
2356
  token_endpoint_auth_methods_supported: ["none"],
1614
- scopes_supported: I,
1615
- service_documentation: L,
2357
+ scopes_supported: at,
2358
+ service_documentation: ot,
1616
2359
  revocation_endpoint: new URL("/revoke", t).href,
1617
2360
  revocation_endpoint_auth_methods_supported: ["none"],
1618
2361
  client_id_metadata_document_supported: !1
1619
2362
  };
1620
2363
  }
1621
- function bt(e) {
1622
- let t = St(e), n = {
2364
+ function Mt(e) {
2365
+ let t = Pt(e), n = {
1623
2366
  resource: t.href,
1624
- authorization_servers: [Ct(t).href],
1625
- scopes_supported: I,
2367
+ authorization_servers: [Ft(t).href],
2368
+ scopes_supported: at,
1626
2369
  bearer_methods_supported: ["header"],
1627
- resource_name: Je,
1628
- resource_documentation: L
2370
+ resource_name: it,
2371
+ resource_documentation: ot
1629
2372
  };
1630
- return ue.parse(n);
1631
- }
1632
- function xt(e, t) {
1633
- let n = e.get("client_id") ?? "", r = e.get("redirect_uri") ?? "", i = e.get("response_type") ?? "", a = e.get("code_challenge") ?? "", o = e.get("code_challenge_method") ?? "", s = e.get("resource"), c = At(e.get("scope")), l = e.get("state");
1634
- if (i !== "code") return V("unsupported_response_type");
1635
- if (o !== "S256") return V("invalid_request", "PKCE code_challenge_method=S256 is required");
1636
- if (!ot.test(a)) return V("invalid_request", "Valid PKCE S256 code_challenge is required");
1637
- let u = jt(t, n);
2373
+ return oe.parse(n);
2374
+ }
2375
+ function Nt(e, t) {
2376
+ let n = e.get("client_id") ?? "", r = e.get("redirect_uri") ?? "", i = e.get("response_type") ?? "", a = e.get("code_challenge") ?? "", o = e.get("code_challenge_method") ?? "", s = e.get("resource"), c = Ht(e.get("scope")), l = e.get("state");
2377
+ if (i !== "code") return U("unsupported_response_type");
2378
+ if (o !== "S256") return U("invalid_request", "PKCE code_challenge_method=S256 is required");
2379
+ if (!vt.test(a)) return U("invalid_request", "Valid PKCE S256 code_challenge is required");
2380
+ let u = Ut(t, n);
1638
2381
  return u ? u.redirect_uris.includes(r) ? {
1639
2382
  clientId: n,
1640
2383
  redirectUri: r,
@@ -1642,55 +2385,55 @@ function xt(e, t) {
1642
2385
  scopes: c,
1643
2386
  resource: s,
1644
2387
  state: l
1645
- } : V("invalid_request", "redirect_uri is not registered for this client") : V("invalid_client", "Unknown OAuth client_id");
2388
+ } : U("invalid_request", "redirect_uri is not registered for this client") : U("invalid_client", "Unknown OAuth client_id");
1646
2389
  }
1647
- function St(e) {
2390
+ function Pt(e) {
1648
2391
  let t;
1649
2392
  try {
1650
2393
  t = new URL(e);
1651
2394
  } catch {
1652
2395
  throw Error("Invalid MCP HTTP public URL; expected an HTTPS /mcp URL");
1653
2396
  }
1654
- if (t.protocol !== "https:" && !Ot(t)) throw Error("Invalid MCP HTTP public URL; use HTTPS for non-loopback URLs");
2397
+ if (t.protocol !== "https:" && !Bt(t)) throw Error("Invalid MCP HTTP public URL; use HTTPS for non-loopback URLs");
1655
2398
  if (t.username || t.password || t.search || t.hash) throw Error("Invalid MCP HTTP public URL; credentials, query strings, and fragments are not allowed");
1656
2399
  if (t.pathname === "/" && (t.pathname = "/mcp"), t.pathname !== "/mcp") throw Error("Invalid MCP HTTP public URL; expected /mcp path");
1657
2400
  return t;
1658
2401
  }
1659
- function Ct(e) {
2402
+ function Ft(e) {
1660
2403
  return new URL(e.origin);
1661
2404
  }
1662
- function wt(e) {
2405
+ function It(e) {
1663
2406
  for (let t of e) {
1664
2407
  let e = new URL(t);
1665
2408
  if (e.username || e.password || e.hash) return "Invalid redirect URI";
1666
- if (!Tt(e) && !Dt(e)) return "Unsupported redirect URI";
2409
+ if (!Lt(e) && !zt(e)) return "Unsupported redirect URI";
1667
2410
  }
1668
2411
  return null;
1669
2412
  }
1670
- function Tt(e) {
1671
- return e.search === "" ? e.href === Ye || e.href === Xe ? !0 : e.protocol === "https:" && e.hostname === "chatgpt.com" && Et(e) : !1;
2413
+ function Lt(e) {
2414
+ return e.search === "" ? e.href === st || e.href === ct || e.protocol === "https:" && e.hostname === "chatgpt.com" && Rt(e) : !1;
1672
2415
  }
1673
- function Et(e) {
2416
+ function Rt(e) {
1674
2417
  let t = e.pathname.split("/").filter(Boolean);
1675
- return t.length === 3 && t[0] === "connector" && t[1] === "oauth" && st.test(t[2] ?? "");
2418
+ return t.length === 3 && t[0] === "connector" && t[1] === "oauth" && yt.test(t[2] ?? "");
1676
2419
  }
1677
- function B(e, t) {
2420
+ function H(e, t) {
1678
2421
  return e.length > 0 && e.every((e) => t.has(e));
1679
2422
  }
1680
- function Dt(e) {
1681
- return e.protocol === "http:" && Ze.has(kt(e.hostname)) && (e.pathname === "/callback" || e.pathname === "/oauth/callback") && e.search === "";
2423
+ function zt(e) {
2424
+ return e.protocol === "http:" && lt.has(Vt(e.hostname)) && (e.pathname === "/callback" || e.pathname === "/oauth/callback") && e.search === "";
1682
2425
  }
1683
- function Ot(e) {
1684
- let t = kt(e.hostname);
1685
- return e.protocol === "http:" && Ze.has(t);
2426
+ function Bt(e) {
2427
+ let t = Vt(e.hostname);
2428
+ return e.protocol === "http:" && lt.has(t);
1686
2429
  }
1687
- function kt(e) {
2430
+ function Vt(e) {
1688
2431
  return e.replace(/^\[(.*)]$/, "$1").toLowerCase();
1689
2432
  }
1690
- function At(e) {
2433
+ function Ht(e) {
1691
2434
  return e?.split(/\s+/).map((e) => e.trim()).filter(Boolean) ?? [];
1692
2435
  }
1693
- function V(e, t) {
2436
+ function U(e, t) {
1694
2437
  return {
1695
2438
  status: 400,
1696
2439
  body: t ? {
@@ -1699,42 +2442,42 @@ function V(e, t) {
1699
2442
  } : { error: e }
1700
2443
  };
1701
2444
  }
1702
- function jt(e, t) {
2445
+ function Ut(e, t) {
1703
2446
  let n = e.getClient(t);
1704
2447
  if (n instanceof Promise) throw Error("Asynchronous OAuth client stores are not supported by this HTTP bootstrap yet");
1705
2448
  return n;
1706
2449
  }
1707
- function H(e) {
1708
- if (typeof e != "string" || e.length !== it || !at.test(e)) return null;
2450
+ function W(e) {
2451
+ if (typeof e != "string" || e.length !== gt || !_t.test(e)) return null;
1709
2452
  let t = Buffer.from(e, "base64url");
1710
- return t.length === rt ? t : null;
2453
+ return t.length === ht ? t : null;
1711
2454
  }
1712
- function U() {
1713
- return a(rt).toString("base64url");
2455
+ function G() {
2456
+ return a(ht).toString("base64url");
1714
2457
  }
1715
- function W(e, t) {
1716
- let n = H(e);
1717
- return n ? Mt(n, t) : null;
2458
+ function K(e, t) {
2459
+ let n = W(e);
2460
+ return n ? Gt(n, t) : null;
1718
2461
  }
1719
- function G(e) {
1720
- let t = H(e);
2462
+ function q(e) {
2463
+ let t = W(e);
1721
2464
  return t ? n("sha256").update(t).digest("base64url") : null;
1722
2465
  }
1723
- function K(e, t) {
1724
- return Mt(e, t);
2466
+ function Wt(e, t) {
2467
+ return Gt(e, t);
1725
2468
  }
1726
- function Mt(e, t) {
2469
+ function Gt(e, t) {
1727
2470
  return r("sha256", t).update(e).digest("base64url");
1728
2471
  }
1729
- function q(e, t) {
2472
+ function J(e, t) {
1730
2473
  let n = Buffer.from(e), r = Buffer.from(t);
1731
2474
  return n.length === r.length && s(n, r);
1732
2475
  }
1733
- function Nt(e, t) {
2476
+ function Kt(e, t) {
1734
2477
  let n = new Set(t);
1735
2478
  return e.every((e) => n.has(e));
1736
2479
  }
1737
- function Pt(e) {
2480
+ function qt(e) {
1738
2481
  return {
1739
2482
  clientsStore: e,
1740
2483
  async authorize() {
@@ -1756,14 +2499,14 @@ function Pt(e) {
1756
2499
  }
1757
2500
  //#endregion
1758
2501
  //#region src/oidc.ts
1759
- var Ft = "CODEMEM_MCP_OIDC_ISSUER_URL", It = "CODEMEM_MCP_OIDC_CLIENT_ID", Lt = "CODEMEM_MCP_OIDC_CLIENT_SECRET", Rt = "CODEMEM_MCP_OAUTH_ALLOWED_SUBJECT", zt = "CODEMEM_MCP_OAUTH_ALLOWED_EMAIL", Bt = 300 * 1e3, Vt = 100, Ht = 300 * 1e3, Ut = class {
2502
+ var Jt = "CODEMEM_MCP_OIDC_ISSUER_URL", Yt = "CODEMEM_MCP_OIDC_CLIENT_ID", Xt = "CODEMEM_MCP_OIDC_CLIENT_SECRET", Zt = "CODEMEM_MCP_OAUTH_ALLOWED_SUBJECT", Qt = "CODEMEM_MCP_OAUTH_ALLOWED_EMAIL", $t = 3e5, en = 100, tn = 3e5, nn = class {
1760
2503
  #e = /* @__PURE__ */ new Map();
1761
2504
  issue(e, t = Date.now()) {
1762
- if (this.#t(t), this.#e.size >= Vt) return;
2505
+ if (this.#t(t), this.#e.size >= en) return;
1763
2506
  let n = o();
1764
2507
  return this.#e.set(n, {
1765
2508
  ...e,
1766
- expiresAt: t + Bt
2509
+ expiresAt: t + $t
1767
2510
  }), n;
1768
2511
  }
1769
2512
  consume(e) {
@@ -1774,14 +2517,14 @@ var Ft = "CODEMEM_MCP_OIDC_ISSUER_URL", It = "CODEMEM_MCP_OIDC_CLIENT_ID", Lt =
1774
2517
  for (let [t, n] of this.#e) n.expiresAt <= e && this.#e.delete(t);
1775
2518
  }
1776
2519
  };
1777
- function Wt() {
1778
- return new Ut();
2520
+ function rn() {
2521
+ return new nn();
1779
2522
  }
1780
- function Gt(e = process.env) {
1781
- let t = e[Ft]?.trim(), n = e[It]?.trim(), r = e[Lt]?.trim(), i = e[Rt]?.trim(), a = e[zt]?.trim().toLowerCase();
2523
+ function an(e = process.env) {
2524
+ let t = e[Jt]?.trim(), n = e[Yt]?.trim(), r = e[Xt]?.trim(), i = e[Zt]?.trim(), a = e[Qt]?.trim().toLowerCase();
1782
2525
  if (!(!t && !n && !r && !i && !a)) {
1783
2526
  if (!t || !n || !r) throw Error("Incomplete MCP OIDC configuration");
1784
- if (J(t, "issuer", { allowLoopbackHttp: !0 }), !i && !a) throw Error("MCP OIDC requires CODEMEM_MCP_OAUTH_ALLOWED_SUBJECT or CODEMEM_MCP_OAUTH_ALLOWED_EMAIL");
2527
+ if (Y(t, "issuer", { allowLoopbackHttp: !0 }), !i && !a) throw Error("MCP OIDC requires CODEMEM_MCP_OAUTH_ALLOWED_SUBJECT or CODEMEM_MCP_OAUTH_ALLOWED_EMAIL");
1785
2528
  return {
1786
2529
  issuerUrl: t,
1787
2530
  clientId: n,
@@ -1791,39 +2534,39 @@ function Gt(e = process.env) {
1791
2534
  };
1792
2535
  }
1793
2536
  }
1794
- async function Kt(e, t, n, r, i, a = Date.now()) {
1795
- if (!r) return Y("temporarily_unavailable", "OIDC is not configured");
1796
- let s = xt(e, t);
2537
+ async function on(e, t, n, r, i, a = Date.now()) {
2538
+ if (!r) return X("temporarily_unavailable", "OIDC is not configured");
2539
+ let s = Nt(e, t);
1797
2540
  if ("status" in s) return s;
1798
- let c = await Yt(r.issuerUrl), l = o(), u = n.issue({
2541
+ let c = await ln(r.issuerUrl), l = o(), u = n.issue({
1799
2542
  oauthParams: e.toString(),
1800
2543
  nonce: l
1801
2544
  }, a);
1802
- if (!u) return Y("temporarily_unavailable", "Too many pending OIDC authorizations");
1803
- let d = Jt(i), f = new URL(c.authorization_endpoint);
2545
+ if (!u) return X("temporarily_unavailable", "Too many pending OIDC authorizations");
2546
+ let d = cn(i), f = new URL(c.authorization_endpoint);
1804
2547
  return f.searchParams.set("response_type", "code"), f.searchParams.set("client_id", r.clientId), f.searchParams.set("redirect_uri", d), f.searchParams.set("scope", "openid email"), f.searchParams.set("state", u), f.searchParams.set("nonce", l), {
1805
2548
  status: 302,
1806
2549
  location: f.href
1807
2550
  };
1808
2551
  }
1809
- async function qt(e, t, n, r, i = Date.now()) {
2552
+ async function sn(e, t, n, r, i = Date.now()) {
1810
2553
  try {
1811
2554
  let a = e.get("code") ?? "", o = e.get("state") ?? "";
1812
- if (!o) return Y("invalid_request", "Missing OIDC state");
2555
+ if (!o) return X("invalid_request", "Missing OIDC state");
1813
2556
  let s = t.consume(o);
1814
- if (!s || s.expiresAt <= i) return Y("invalid_request", "Expired or unknown OIDC state");
1815
- if (!a) return Y("invalid_request", "Missing OIDC code");
1816
- let c = await Yt(n.issuerUrl), l = await Xt(c.token_endpoint, n, Jt(r), a);
1817
- return l.id_token ? tn(await Zt(l.id_token, c, n.clientId, s.nonce, i), n) ? { oauthParams: new URLSearchParams(s.oauthParams) } : Y("access_denied", "OIDC identity is not allowed") : Y("invalid_request", "OIDC token exchange failed");
2557
+ if (!s || s.expiresAt <= i) return X("invalid_request", "Expired or unknown OIDC state");
2558
+ if (!a) return X("invalid_request", "Missing OIDC code");
2559
+ let c = await ln(n.issuerUrl), l = await un(c.token_endpoint, n, cn(r), a);
2560
+ return l.id_token ? hn(await dn(l.id_token, c, n.clientId, s.nonce, i), n) ? { oauthParams: new URLSearchParams(s.oauthParams) } : X("access_denied", "OIDC identity is not allowed") : X("invalid_request", "OIDC token exchange failed");
1818
2561
  } catch {
1819
- return Y("access_denied", "OIDC identity verification failed");
2562
+ return X("access_denied", "OIDC identity verification failed");
1820
2563
  }
1821
2564
  }
1822
- function Jt(e) {
2565
+ function cn(e) {
1823
2566
  let t = new URL(e);
1824
2567
  return new URL("/oauth/callback", t.origin).href;
1825
2568
  }
1826
- async function Yt(e) {
2569
+ async function ln(e) {
1827
2570
  let t = new URL(e);
1828
2571
  if (t.search || t.hash) throw Error("OIDC issuer must not include query or fragment");
1829
2572
  if (t.username || t.password) throw Error("OIDC issuer must not include credentials");
@@ -1832,10 +2575,10 @@ async function Yt(e) {
1832
2575
  let i = await r.json();
1833
2576
  if (i.issuer !== t.href && i.issuer !== t.href.replace(/\/$/, "")) throw Error("OIDC discovery issuer mismatch");
1834
2577
  if (!i.authorization_endpoint || !i.token_endpoint || !i.jwks_uri) throw Error("OIDC discovery metadata is incomplete");
1835
- let a = t.protocol === "http:" && nn(t.hostname);
1836
- return J(i.authorization_endpoint, "authorization endpoint", { allowLoopbackHttp: a }), J(i.token_endpoint, "token endpoint", { allowLoopbackHttp: a }), J(i.jwks_uri, "JWKS URI", { allowLoopbackHttp: a }), i;
2578
+ let a = t.protocol === "http:" && gn(t.hostname);
2579
+ return Y(i.authorization_endpoint, "authorization endpoint", { allowLoopbackHttp: a }), Y(i.token_endpoint, "token endpoint", { allowLoopbackHttp: a }), Y(i.jwks_uri, "JWKS URI", { allowLoopbackHttp: a }), i;
1837
2580
  }
1838
- async function Xt(e, t, n, r) {
2581
+ async function un(e, t, n, r) {
1839
2582
  let i = new URLSearchParams({
1840
2583
  grant_type: "authorization_code",
1841
2584
  code: r,
@@ -1850,17 +2593,17 @@ async function Xt(e, t, n, r) {
1850
2593
  if (!a.ok) throw Error("OIDC token request failed");
1851
2594
  return await a.json();
1852
2595
  }
1853
- async function Zt(e, t, n, r, a) {
2596
+ async function dn(e, t, n, r, a) {
1854
2597
  let [o, s, l] = e.split(".");
1855
2598
  if (!o || !s || !l) throw Error("Invalid OIDC id_token");
1856
- let u = Qt(o), d = Qt(s);
2599
+ let u = fn(o), d = fn(s);
1857
2600
  if (u.alg !== "RS256" || !u.kid) throw Error("Unsupported OIDC id_token signature");
1858
2601
  if (d.iss !== t.issuer) throw Error("OIDC id_token issuer mismatch");
1859
- if (!$t(d.aud, n)) throw Error("OIDC id_token audience mismatch");
1860
- if (!en(d.aud, d.azp, n)) throw Error("OIDC id_token authorized party mismatch");
2602
+ if (!pn(d.aud, n)) throw Error("OIDC id_token audience mismatch");
2603
+ if (!mn(d.aud, d.azp, n)) throw Error("OIDC id_token authorized party mismatch");
1861
2604
  if (typeof d.exp != "number" || !Number.isFinite(d.exp) || d.exp * 1e3 <= a) throw Error("OIDC id_token is expired");
1862
2605
  if (typeof d.iat != "number" || !Number.isFinite(d.iat)) throw Error("OIDC id_token issued-at time is missing");
1863
- if (d.iat * 1e3 > a + Ht) throw Error("OIDC id_token issued-at time is in the future");
2606
+ if (d.iat * 1e3 > a + tn) throw Error("OIDC id_token issued-at time is in the future");
1864
2607
  if (d.nonce !== r) throw Error("OIDC id_token nonce mismatch");
1865
2608
  if (!d.sub) throw Error("OIDC id_token subject is missing");
1866
2609
  let f = await fetch(t.jwks_uri);
@@ -1874,28 +2617,28 @@ async function Zt(e, t, n, r, a) {
1874
2617
  if (!c("RSA-SHA256", Buffer.from(h), m, Buffer.from(l, "base64url"))) throw Error("OIDC id_token signature verification failed");
1875
2618
  return d;
1876
2619
  }
1877
- function Qt(e) {
2620
+ function fn(e) {
1878
2621
  return JSON.parse(Buffer.from(e, "base64url").toString("utf8"));
1879
2622
  }
1880
- function $t(e, t) {
2623
+ function pn(e, t) {
1881
2624
  return Array.isArray(e) ? e.includes(t) : e === t;
1882
2625
  }
1883
- function en(e, t, n) {
2626
+ function mn(e, t, n) {
1884
2627
  return t && t !== n ? !1 : !Array.isArray(e) || e.length <= 1 || t === n;
1885
2628
  }
1886
- function tn(e, t) {
2629
+ function hn(e, t) {
1887
2630
  return t.allowedSubject && e.sub === t.allowedSubject ? !0 : t.allowedEmail ? e.email_verified === !0 && e.email?.toLowerCase() === t.allowedEmail : !1;
1888
2631
  }
1889
- function J(e, t, n = {}) {
2632
+ function Y(e, t, n = {}) {
1890
2633
  let r = new URL(e);
1891
2634
  if (r.username || r.password) throw Error(`OIDC ${t} must not include credentials`);
1892
- if (r.protocol !== "https:" && !(n.allowLoopbackHttp && r.protocol === "http:" && nn(r.hostname))) throw Error(`OIDC ${t} must use HTTPS`);
2635
+ if (r.protocol !== "https:" && !(n.allowLoopbackHttp && r.protocol === "http:" && gn(r.hostname))) throw Error(`OIDC ${t} must use HTTPS`);
1893
2636
  }
1894
- function nn(e) {
2637
+ function gn(e) {
1895
2638
  let t = e.replace(/^\[(.*)]$/, "$1").toLowerCase();
1896
2639
  return t === "localhost" || t === "127.0.0.1" || t === "::1";
1897
2640
  }
1898
- function Y(e, t) {
2641
+ function X(e, t) {
1899
2642
  return {
1900
2643
  status: 400,
1901
2644
  body: t ? {
@@ -1906,7 +2649,7 @@ function Y(e, t) {
1906
2649
  }
1907
2650
  //#endregion
1908
2651
  //#region src/provider.ts
1909
- var rn = class {
2652
+ var _n = class {
1910
2653
  #e;
1911
2654
  #t;
1912
2655
  #n;
@@ -1916,44 +2659,44 @@ var rn = class {
1916
2659
  #o;
1917
2660
  #s;
1918
2661
  constructor(e) {
1919
- this.#e = e.clientsStore, this.#t = e.codeStore, this.#n = e.tokenStore, this.#r = e.refreshTokenStore ?? gt(), this.#i = e.publicMcpUrl, this.#a = new URL(e.publicMcpUrl).href, this.#o = e.oidc, this.#s = e.now ?? Date.now;
2662
+ this.#e = e.clientsStore, this.#t = e.codeStore, this.#n = e.tokenStore, this.#r = e.refreshTokenStore ?? Ot(), this.#i = e.publicMcpUrl, this.#a = new URL(e.publicMcpUrl).href, this.#o = e.oidc, this.#s = e.now ?? Date.now;
1920
2663
  }
1921
2664
  get clientsStore() {
1922
2665
  return this.#e;
1923
2666
  }
1924
2667
  async authorize(e, t, n) {
1925
- if (!this.#o) throw new k("OIDC is not configured");
1926
- let r = await Kt(an(e, t), this.#e, this.#o.pendingStore, this.#o.config, this.#i, this.#s());
2668
+ if (!this.#o) throw new N("OIDC is not configured");
2669
+ let r = await on(vn(e, t), this.#e, this.#o.pendingStore, this.#o.config, this.#i, this.#s());
1927
2670
  if (r.status === 302) {
1928
2671
  n.redirect(302, r.location);
1929
2672
  return;
1930
2673
  }
1931
- throw on(r.body);
2674
+ throw yn(r.body);
1932
2675
  }
1933
2676
  async challengeForAuthorizationCode(e, t) {
1934
2677
  let n = this.#t.peekCode(t);
1935
- if (!n) throw new O("Invalid or already used code");
1936
- if (n.clientId !== e.client_id) throw new O("Code does not match client");
1937
- if (n.expiresAt <= this.#s()) throw this.#t.consumeCode(t), new O("Expired code");
2678
+ if (!n) throw new M("Invalid or already used code");
2679
+ if (n.clientId !== e.client_id) throw new M("Code does not match client");
2680
+ if (n.expiresAt <= this.#s()) throw this.#t.consumeCode(t), new M("Expired code");
1938
2681
  return n.codeChallenge;
1939
2682
  }
1940
2683
  async exchangeAuthorizationCode(e, t, n, r, i) {
1941
2684
  let a = this.#s(), o = this.#t.peekCode(t);
1942
- if (!o) throw new O("Invalid or already used code");
1943
- if (o.expiresAt <= a) throw this.#t.consumeCode(t), new O("Expired code");
1944
- if (o.clientId !== e.client_id) throw this.#t.consumeCode(t), new O("Code does not match client");
1945
- if (r === void 0 || o.redirectUri !== r) throw this.#t.consumeCode(t), new O("Code does not match redirect_uri");
1946
- if ((o.resource ?? null) !== (i?.href ?? null)) throw this.#t.consumeCode(t), new O("Code does not match resource");
1947
- let s = cn(o.scopes) ?? [], c = this.#r.issueGrant({
2685
+ if (!o) throw new M("Invalid or already used code");
2686
+ if (o.expiresAt <= a) throw this.#t.consumeCode(t), new M("Expired code");
2687
+ if (o.clientId !== e.client_id) throw this.#t.consumeCode(t), new M("Code does not match client");
2688
+ if (r === void 0 || o.redirectUri !== r) throw this.#t.consumeCode(t), new M("Code does not match redirect_uri");
2689
+ if ((o.resource ?? null) !== (i?.href ?? null)) throw this.#t.consumeCode(t), new M("Code does not match resource");
2690
+ let s = xn(o.scopes) ?? [], c = this.#r.issueGrant({
1948
2691
  clientId: e.client_id,
1949
2692
  scopes: s,
1950
2693
  resource: o.resource
1951
2694
  }, a);
1952
- if (!c) throw new k("Too many active refresh grants");
2695
+ if (!c) throw new N("Too many active refresh grants");
1953
2696
  let l = this.#n.issueToken(e.client_id, a, o.resource, c.grant.grantId, s);
1954
- if (!l) throw this.#r.revokeGrant(c.grant.grantId, a), new k("Too many active access tokens");
1955
- if (!this.#t.consumeCode(t)) throw this.#n.revokeToken(l.token, a), this.#r.revokeGrant(c.grant.grantId, a), new O("Authorization code already used");
1956
- return de.parse({
2697
+ if (!l) throw this.#r.revokeGrant(c.grant.grantId, a), new N("Too many active access tokens");
2698
+ if (!this.#t.consumeCode(t)) throw this.#n.revokeToken(l.token, a), this.#r.revokeGrant(c.grant.grantId, a), new M("Authorization code already used");
2699
+ return se.parse({
1957
2700
  access_token: l.token,
1958
2701
  token_type: "Bearer",
1959
2702
  expires_in: l.expiresIn,
@@ -1962,13 +2705,13 @@ var rn = class {
1962
2705
  }
1963
2706
  async exchangeRefreshToken(e, t, n, r) {
1964
2707
  let i = this.#s(), a = this.#r.rotateRefreshToken(e.client_id, t, {
1965
- scopes: cn(n),
2708
+ scopes: xn(n),
1966
2709
  ...r ? { resource: r.href } : {}
1967
2710
  }, i);
1968
- if (!a.ok) throw a.reason === "refresh_token_replay" && a.grantId && this.#n.revokeTokensForGrant?.(a.grantId, i), new O(sn(a.reason));
2711
+ if (!a.ok) throw a.reason === "refresh_token_replay" && a.grantId && this.#n.revokeTokensForGrant?.(a.grantId, i), new M(bn(a.reason));
1969
2712
  let o = this.#n.issueToken(e.client_id, i, a.grant.resource, a.grant.grantId, a.grant.scopes);
1970
- if (!o) throw new k("Too many active access tokens");
1971
- return de.parse({
2713
+ if (!o) throw new N("Too many active access tokens");
2714
+ return se.parse({
1972
2715
  access_token: o.token,
1973
2716
  token_type: "Bearer",
1974
2717
  expires_in: o.expiresIn,
@@ -1977,7 +2720,10 @@ var rn = class {
1977
2720
  }
1978
2721
  async verifyAccessToken(e) {
1979
2722
  let t = this.#n.verifyToken(e, this.#s());
1980
- if (!t.ok) throw new se(t.reason === "expired_token" ? "Token has expired" : t.reason === "revoked_token" ? "Token has been revoked" : "Token is invalid");
2723
+ if (!t.ok) {
2724
+ let e = t.reason === "expired_token" ? "Token has expired" : t.reason === "revoked_token" ? "Token has been revoked" : "Token is invalid";
2725
+ throw new re(e);
2726
+ }
1981
2727
  let n = {
1982
2728
  token: e,
1983
2729
  clientId: t.record.clientId,
@@ -1985,7 +2731,7 @@ var rn = class {
1985
2731
  expiresAt: Math.floor(t.record.expiresAt / 1e3)
1986
2732
  };
1987
2733
  if (t.record.resource) {
1988
- if (new URL(t.record.resource).href !== this.#a) throw new se("Token audience does not match this resource server");
2734
+ if (new URL(t.record.resource).href !== this.#a) throw new re("Token audience does not match this resource server");
1989
2735
  n.resource = new URL(t.record.resource);
1990
2736
  }
1991
2737
  return n;
@@ -1997,22 +2743,22 @@ var rn = class {
1997
2743
  r && this.#n.revokeTokensForGrant?.(r, n);
1998
2744
  }
1999
2745
  };
2000
- function an(e, t) {
2746
+ function vn(e, t) {
2001
2747
  let n = new URLSearchParams();
2002
2748
  return n.set("client_id", e.client_id), n.set("redirect_uri", t.redirectUri), n.set("response_type", "code"), n.set("code_challenge", t.codeChallenge), n.set("code_challenge_method", "S256"), t.state && n.set("state", t.state), t.scopes?.length && n.set("scope", t.scopes.join(" ")), t.resource && n.set("resource", t.resource.href), n;
2003
2749
  }
2004
- function on(e) {
2750
+ function yn(e) {
2005
2751
  let t = e.error_description ?? e.error;
2006
2752
  switch (e.error) {
2007
- case "temporarily_unavailable": return new k(t);
2008
- case "invalid_request": return new oe(t);
2009
- case "invalid_client": return new ae(t);
2010
- case "access_denied": return new E(t);
2011
- case "unsupported_response_type": return new le(t);
2012
- default: return new ce(t);
2753
+ case "temporarily_unavailable": return new N(t);
2754
+ case "invalid_request": return new ne(t);
2755
+ case "invalid_client": return new te(t);
2756
+ case "access_denied": return new A(t);
2757
+ case "unsupported_response_type": return new ae(t);
2758
+ default: return new ie(t);
2013
2759
  }
2014
2760
  }
2015
- function sn(e) {
2761
+ function bn(e) {
2016
2762
  switch (e) {
2017
2763
  case "expired_refresh_token": return "Refresh token has expired";
2018
2764
  case "revoked_refresh_token": return "Refresh token has been revoked";
@@ -2023,18 +2769,18 @@ function sn(e) {
2023
2769
  default: return "Invalid refresh token";
2024
2770
  }
2025
2771
  }
2026
- function cn(e) {
2772
+ function xn(e) {
2027
2773
  let t = e?.map((e) => e.trim()).filter(Boolean).map((e) => e === "memory:read_access" ? "memory:read" : e === "memory:write_access" ? "memory:write" : e);
2028
2774
  return t && t.length > 0 ? t : void 0;
2029
2775
  }
2030
2776
  //#endregion
2031
2777
  //#region src/http.ts
2032
- var ln = "127.0.0.1", X = 38889, un = 80, dn = new Set(["https://chatgpt.com", "https://claude.ai"]), fn = "authorization,content-type,mcp-session-id", pn = "600", mn = 256, hn = 900 * 1e3, gn = 600, _n = 4 * 1024 * 1024, vn = 300 * 1e3, yn = 2e3, bn = /^[a-zA-Z0-9.-]+$/, xn = new Set([
2778
+ var Sn = "127.0.0.1", Cn = 38889, wn = 80, Tn = /* @__PURE__ */ new Set(["https://chatgpt.com", "https://claude.ai"]), En = "authorization,content-type,mcp-session-id", Dn = "600", On = 256, kn = 9e5, An = 600, jn = 4194304, Mn = 3e5, Nn = 2e3, Pn = /^[a-zA-Z0-9.-]+$/, Fn = /* @__PURE__ */ new Set([
2033
2779
  "127.0.0.1",
2034
2780
  "::1",
2035
2781
  "localhost"
2036
2782
  ]);
2037
- function Sn(t) {
2783
+ function In(t) {
2038
2784
  let n = t?.extra?.sub;
2039
2785
  if (typeof n == "string" && n.trim().length > 0) {
2040
2786
  let r = n.trim(), i = t?.clientId?.trim();
@@ -2042,23 +2788,23 @@ function Sn(t) {
2042
2788
  }
2043
2789
  return t?.token ? `token:${t.token}` : void 0;
2044
2790
  }
2045
- function Cn(e, t = !1) {
2791
+ function Ln(e, t = !1) {
2046
2792
  let n = e?.trim() || "127.0.0.1";
2047
- if (n.includes("://") || n.includes("/") || n.includes("\\") || !(u(n) || n === "localhost" || bn.test(n))) throw Error(`Invalid MCP HTTP host: ${e}`);
2793
+ if (n.includes("://") || n.includes("/") || n.includes("\\") || !(u(n) || n === "localhost" || Pn.test(n))) throw Error(`Invalid MCP HTTP host: ${e}`);
2048
2794
  if (!t && !Z(n)) throw Error(`Refusing unsafe MCP HTTP host ${n}; set CODEMEM_MCP_HTTP_UNSAFE_PUBLIC=1 to allow non-loopback binding`);
2049
2795
  return n;
2050
2796
  }
2051
2797
  function Z(e) {
2052
- return xn.has(Q(e));
2798
+ return Fn.has(Q(e));
2053
2799
  }
2054
- function wn(e = process.env.CODEMEM_MCP_HTTP_UNSAFE_PUBLIC) {
2800
+ function Rn(e = process.env.CODEMEM_MCP_HTTP_UNSAFE_PUBLIC) {
2055
2801
  return e === "1" || e?.toLowerCase() === "true" || e?.toLowerCase() === "yes";
2056
2802
  }
2057
- function Tn(e, t) {
2058
- let n = On(e);
2059
- return !n || !Z(n.host) ? !1 : n.port === null ? t === un : n.port === t;
2803
+ function zn(e, t) {
2804
+ let n = Hn(e);
2805
+ return !n || !Z(n.host) ? !1 : n.port === null ? t === wn : n.port === t;
2060
2806
  }
2061
- function En(e, t) {
2807
+ function Bn(e, t) {
2062
2808
  if (!e) return !0;
2063
2809
  try {
2064
2810
  let n = new URL(e), r = n.port ? Number(n.port) : n.protocol === "https:" ? 443 : 80;
@@ -2067,13 +2813,13 @@ function En(e, t) {
2067
2813
  return !1;
2068
2814
  }
2069
2815
  }
2070
- function Dn(e) {
2816
+ function Vn(e) {
2071
2817
  return e ? Z(e.replace(/^::ffff:/, "")) : !1;
2072
2818
  }
2073
2819
  function Q(e) {
2074
2820
  return e.replace(/^\[(.*)]$/, "$1").toLowerCase();
2075
2821
  }
2076
- function On(e) {
2822
+ function Hn(e) {
2077
2823
  if (!e) return null;
2078
2824
  if (e.startsWith("[")) {
2079
2825
  let t = /^\[([^\]]+)]:(\d+)$/.exec(e);
@@ -2098,70 +2844,70 @@ function On(e) {
2098
2844
  port: r
2099
2845
  } : null;
2100
2846
  }
2101
- function kn(e) {
2102
- if (e === void 0 || e === "") return X;
2847
+ function Un(e) {
2848
+ if (e === void 0 || e === "") return Cn;
2103
2849
  let t = typeof e == "number" ? e : Number(e);
2104
2850
  if (!Number.isInteger(t) || t < 0 || t > 65535) throw Error(`Invalid MCP HTTP port: ${e}`);
2105
2851
  return t;
2106
2852
  }
2107
- async function An(e = {}) {
2108
- let n = Cn(e.host ?? process.env.CODEMEM_MCP_HTTP_HOST, e.allowUnsafePublic ?? wn()), r = kn(e.port ?? process.env.CODEMEM_MCP_HTTP_PORT), i = e.publicUrl ?? process.env.CODEMEM_MCP_HTTP_PUBLIC_URL, a = i ? St(i) : void 0, o = new p(e.dbPath ?? m()), s = e.oauthAccessTokenStore ? void 0 : _t(e.oauthStatePath), c = s ?? pt(), u = s ?? mt(), d = e.oauthAccessTokenStore ?? s ?? ht(), f = Gt(), g = Wt(), _ = a !== void 0 || f !== void 0, v = We(e.auditEmitter ?? qe()), y = /* @__PURE__ */ new Set(), ie = Hn(), b = null, x = re();
2109
- x.disable("x-powered-by"), x.set("trust proxy", "loopback");
2110
- let S = l(x);
2853
+ async function Wn(e = {}) {
2854
+ let n = Ln(e.host ?? process.env.CODEMEM_MCP_HTTP_HOST, e.allowUnsafePublic ?? Rn()), r = Un(e.port ?? process.env.CODEMEM_MCP_HTTP_PORT), i = e.publicUrl ?? process.env.CODEMEM_MCP_HTTP_PUBLIC_URL, a = i ? Pt(i) : void 0, o = new p(e.dbPath ?? m()), s = e.oauthAccessTokenStore ? void 0 : kt(e.oauthStatePath), c = s ?? Tt(), u = s ?? Et(), d = e.oauthAccessTokenStore ?? s ?? Dt(), f = an(), g = rn(), x = a !== void 0 || f !== void 0, S = et(e.auditEmitter ?? rt()), C = /* @__PURE__ */ new Set(), ee = nr(), w = null, T = b();
2855
+ T.disable("x-powered-by"), T.set("trust proxy", "loopback");
2856
+ let E = l(T);
2111
2857
  await new Promise((e, t) => {
2112
- S.once("error", t), S.listen({
2858
+ E.once("error", t), E.listen({
2113
2859
  host: n,
2114
2860
  port: r
2115
2861
  }, () => {
2116
- S.off("error", t), e();
2862
+ E.off("error", t), e();
2117
2863
  });
2118
2864
  });
2119
- let C = a?.href ?? Vn(S, n), w = new URL(C), T = Kn(w, $(S)), E = new rn({
2865
+ let D = a?.href ?? tr(E, n), O = new URL(D), k = or(O, $(E)), A = new _n({
2120
2866
  clientsStore: c,
2121
2867
  codeStore: u,
2122
2868
  tokenStore: d,
2123
- publicMcpUrl: C,
2869
+ publicMcpUrl: D,
2124
2870
  ...s ? { refreshTokenStore: s } : {},
2125
2871
  ...f ? { oidc: {
2126
2872
  config: f,
2127
2873
  pendingStore: g
2128
2874
  } } : {}
2129
- }), ae = ee(w);
2130
- x.use(Ve({
2131
- windowMs: hn,
2132
- limit: gn,
2875
+ }), te = _(O);
2876
+ T.use(Ze({
2877
+ windowMs: kn,
2878
+ limit: An,
2133
2879
  standardHeaders: "draft-8",
2134
2880
  legacyHeaders: !1,
2135
2881
  ipv6Subnet: !1
2136
- })), x.use((e, t, n) => {
2137
- let r = $(S), i = Jn(e.path);
2882
+ })), T.use((e, t, n) => {
2883
+ let r = $(E), i = cr(e.path);
2138
2884
  if (i === "/mcp") {
2139
- if (jn(e, r, a)) {
2140
- if (Fn(e, t, a), e.method === "OPTIONS") {
2885
+ if (Gn(e, r, a)) {
2886
+ if (Yn(e, t, a), e.method === "OPTIONS") {
2141
2887
  t.status(204).send("");
2142
2888
  return;
2143
2889
  }
2144
2890
  return n();
2145
2891
  }
2146
- Ln(e, i, a), t.status(403).type("text/plain").send("Forbidden");
2892
+ Zn(e, i, a), t.status(403).type("text/plain").send("Forbidden");
2147
2893
  return;
2148
2894
  }
2149
- if (qn(i)) {
2150
- if (Nn(e, r, a)) {
2151
- if (Fn(e, t, a), e.method === "OPTIONS") {
2895
+ if (sr(i)) {
2896
+ if (qn(e, r, a)) {
2897
+ if (Yn(e, t, a), e.method === "OPTIONS") {
2152
2898
  t.status(204).send("");
2153
2899
  return;
2154
2900
  }
2155
2901
  return n();
2156
2902
  }
2157
- Ln(e, i, a), t.status(403).type("text/plain").send("Forbidden");
2903
+ Zn(e, i, a), t.status(403).type("text/plain").send("Forbidden");
2158
2904
  return;
2159
2905
  }
2160
2906
  n();
2161
- }), x.use(Yn(v)), x.get("/oauth/callback", async (e, t) => {
2907
+ }), T.use(lr(S)), T.get("/oauth/callback", async (e, t) => {
2162
2908
  let n = e.socket.remoteAddress ?? void 0;
2163
2909
  if (!f) {
2164
- v(F("oidc_callback", {
2910
+ S(z("oidc_callback", {
2165
2911
  outcome: "denied",
2166
2912
  reason: "oidc_not_configured",
2167
2913
  remoteAddress: n
@@ -2171,9 +2917,9 @@ async function An(e = {}) {
2171
2917
  });
2172
2918
  return;
2173
2919
  }
2174
- let r = await qt(new URLSearchParams(e.query), g, f, C);
2920
+ let r = await sn(new URLSearchParams(e.query), g, f, D);
2175
2921
  if ("status" in r) {
2176
- v(F("oidc_callback", {
2922
+ S(z("oidc_callback", {
2177
2923
  outcome: "denied",
2178
2924
  reason: r.body.error,
2179
2925
  remoteAddress: n
@@ -2184,12 +2930,12 @@ async function An(e = {}) {
2184
2930
  clientId: r.oauthParams.get("client_id") ?? "",
2185
2931
  redirectUri: r.oauthParams.get("redirect_uri") ?? "",
2186
2932
  codeChallenge: r.oauthParams.get("code_challenge") ?? "",
2187
- scopes: ir(r.oauthParams.get("scope")),
2933
+ scopes: vr(r.oauthParams.get("scope")),
2188
2934
  ...r.oauthParams.get("resource") ? { resource: r.oauthParams.get("resource") ?? void 0 } : {},
2189
- expiresAt: Date.now() + 300 * 1e3
2935
+ expiresAt: Date.now() + 3e5
2190
2936
  });
2191
2937
  if (!a) {
2192
- v(F("oidc_callback", {
2938
+ S(z("oidc_callback", {
2193
2939
  outcome: "denied",
2194
2940
  reason: "temporarily_unavailable",
2195
2941
  clientId: i,
@@ -2203,107 +2949,107 @@ async function An(e = {}) {
2203
2949
  let o = new URL(r.oauthParams.get("redirect_uri") ?? "");
2204
2950
  o.searchParams.set("code", a);
2205
2951
  let s = r.oauthParams.get("state");
2206
- s && o.searchParams.set("state", s), v(F("oidc_callback", {
2952
+ s && o.searchParams.set("state", s), S(z("oidc_callback", {
2207
2953
  outcome: "success",
2208
2954
  reason: "code_issued",
2209
2955
  clientId: i,
2210
2956
  remoteAddress: n
2211
2957
  })), t.redirect(302, o.href);
2212
- }), x.get("/.well-known/oauth-authorization-server", (e, t) => {
2213
- t.status(200).json(yt({
2214
- mcpUrl: C,
2958
+ }), T.get("/.well-known/oauth-authorization-server", (e, t) => {
2959
+ t.status(200).json(jt({
2960
+ mcpUrl: D,
2215
2961
  clientsStore: c
2216
2962
  }));
2217
- }), x.get("/.well-known/oauth-protected-resource/mcp", (e, t) => {
2218
- t.status(200).json(bt(C));
2219
- }), x.use(te({
2220
- provider: E,
2221
- issuerUrl: T,
2222
- baseUrl: T,
2223
- resourceServerUrl: w,
2224
- resourceName: Je,
2225
- scopesSupported: I,
2226
- serviceDocumentationUrl: new URL(L),
2963
+ }), T.get("/.well-known/oauth-protected-resource/mcp", (e, t) => {
2964
+ t.status(200).json(Mt(D));
2965
+ }), T.use(v({
2966
+ provider: A,
2967
+ issuerUrl: k,
2968
+ baseUrl: k,
2969
+ resourceServerUrl: O,
2970
+ resourceName: it,
2971
+ scopesSupported: at,
2972
+ serviceDocumentationUrl: new URL(ot),
2227
2973
  clientRegistrationOptions: { clientSecretExpirySeconds: 0 }
2228
2974
  }));
2229
- let D = _ ? h({
2230
- verifier: E,
2231
- resourceMetadataUrl: ae
2232
- }) : (e, t, n) => n(), O = _ ? nr(v, d) : (e, t, n) => n();
2233
- return x.post("/mcp", O, D, re.json({ limit: _n }), async (n, r) => {
2234
- n.auth && v(F("bearer", {
2975
+ let j = x ? h({
2976
+ verifier: A,
2977
+ resourceMetadataUrl: te
2978
+ }) : (e, t, n) => n(), M = x ? gr(S, d) : (e, t, n) => n();
2979
+ return T.post("/mcp", M, j, b.json({ limit: jn }), async (n, r) => {
2980
+ n.auth && S(z("bearer", {
2235
2981
  outcome: "success",
2236
2982
  clientId: n.auth.clientId,
2237
2983
  remoteAddress: n.socket.remoteAddress ?? void 0
2238
2984
  }));
2239
- let i = t(o, {
2240
- retrievalLedgerScopeId: ie({
2241
- endpoint: w,
2242
- principal: Sn(n.auth),
2243
- requestBody: n.body,
2244
- now: e.retrievalLedgerNow?.() ?? Date.now()
2245
- }),
2985
+ let i = In(n.auth), a = ee({
2986
+ endpoint: O,
2987
+ principal: i,
2988
+ requestBody: n.body,
2989
+ now: e.retrievalLedgerNow?.() ?? Date.now()
2990
+ }), s = t(o, {
2991
+ retrievalLedgerScopeId: a,
2246
2992
  retrievalLedgerIdentityMode: "stateless"
2247
- }), a = new ne({ sessionIdGenerator: void 0 }), s = { mcpServer: i };
2248
- y.add(s);
2993
+ }), c = new y({ sessionIdGenerator: void 0 }), l = { mcpServer: s };
2994
+ C.add(l);
2249
2995
  try {
2250
- await i.connect(a), await a.handleRequest(n, r, n.body);
2996
+ await s.connect(c), await c.handleRequest(n, r, n.body);
2251
2997
  } finally {
2252
- y.delete(s), await i.close();
2998
+ C.delete(l), await s.close();
2253
2999
  }
2254
- }, Wn), x.all("/mcp", (e, t) => {
3000
+ }, ir), T.all("/mcp", (e, t) => {
2255
3001
  t.setHeader("Allow", "POST"), t.status(405).type("text/plain").send("Method not allowed");
2256
- }), x.use((e, t) => {
3002
+ }), T.use((e, t) => {
2257
3003
  t.status(404).type("text/plain").send("Not found");
2258
3004
  }), {
2259
- server: S,
3005
+ server: E,
2260
3006
  store: o,
2261
- url: `http://${Bn(n)}:${$(S)}/mcp`,
2262
- close: () => (b ??= (async () => {
2263
- await Promise.allSettled([...y].map(({ mcpServer: e }) => e.close())), await new Promise((e, t) => {
2264
- S.close((n) => {
3007
+ url: `http://${er(n)}:${$(E)}/mcp`,
3008
+ close: () => (w ??= (async () => {
3009
+ await Promise.allSettled([...C].map(({ mcpServer: e }) => e.close())), await new Promise((e, t) => {
3010
+ E.close((n) => {
2265
3011
  if (!n || n.code === "ERR_SERVER_NOT_RUNNING") {
2266
3012
  e();
2267
3013
  return;
2268
3014
  }
2269
3015
  t(n);
2270
- }), S.closeAllConnections();
3016
+ }), E.closeAllConnections();
2271
3017
  }), o.close();
2272
- })(), b)
3018
+ })(), w)
2273
3019
  };
2274
3020
  }
2275
- function jn(e, t, n) {
2276
- return Mn(e, t) ? !0 : n ? zn(e.headers.host, n) && Pn(e.headers.origin, n) : !1;
3021
+ function Gn(e, t, n) {
3022
+ return Kn(e, t) ? !0 : n ? $n(e.headers.host, n) && Jn(e.headers.origin, n) : !1;
2277
3023
  }
2278
- function Mn(e, t) {
2279
- return Dn(e.socket.remoteAddress) && Tn(e.headers.host, t) && En(e.headers.origin, t);
3024
+ function Kn(e, t) {
3025
+ return Vn(e.socket.remoteAddress) && zn(e.headers.host, t) && Bn(e.headers.origin, t);
2280
3026
  }
2281
- function Nn(e, t, n) {
2282
- return Mn(e, t) ? !0 : n ? zn(e.headers.host, n) && Pn(e.headers.origin, n) : !1;
3027
+ function qn(e, t, n) {
3028
+ return Kn(e, t) ? !0 : n ? $n(e.headers.host, n) && Jn(e.headers.origin, n) : !1;
2283
3029
  }
2284
- function Pn(e, t) {
3030
+ function Jn(e, t) {
2285
3031
  if (!e) return !0;
2286
3032
  try {
2287
3033
  let n = new URL(e);
2288
- return n.origin === t.origin || dn.has(n.origin);
3034
+ return n.origin === t.origin || Tn.has(n.origin);
2289
3035
  } catch {
2290
3036
  return !1;
2291
3037
  }
2292
3038
  }
2293
- function Fn(e, t, n) {
3039
+ function Yn(e, t, n) {
2294
3040
  if (!n) return;
2295
- let r = In(e.headers.origin, n);
2296
- r && (t.setHeader("Access-Control-Allow-Origin", r), t.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS"), t.setHeader("Access-Control-Allow-Headers", e.headers["access-control-request-headers"] ?? fn), t.setHeader("Access-Control-Max-Age", pn), t.setHeader("Vary", "Origin"));
3041
+ let r = Xn(e.headers.origin, n);
3042
+ r && (t.setHeader("Access-Control-Allow-Origin", r), t.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS"), t.setHeader("Access-Control-Allow-Headers", e.headers["access-control-request-headers"] ?? En), t.setHeader("Access-Control-Max-Age", Dn), t.setHeader("Vary", "Origin"));
2297
3043
  }
2298
- function In(e, t) {
3044
+ function Xn(e, t) {
2299
3045
  if (e) try {
2300
3046
  let n = new URL(e).origin;
2301
- if (n === t.origin || dn.has(n)) return n;
3047
+ if (n === t.origin || Tn.has(n)) return n;
2302
3048
  } catch {
2303
3049
  return;
2304
3050
  }
2305
3051
  }
2306
- function Ln(e, t, n) {
3052
+ function Zn(e, t, n) {
2307
3053
  console.warn(JSON.stringify({
2308
3054
  source: "codemem-mcp-http-guard",
2309
3055
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -2311,35 +3057,35 @@ function Ln(e, t, n) {
2311
3057
  reason: "host_or_origin_mismatch",
2312
3058
  method: e.method,
2313
3059
  path: t,
2314
- host: Rn(e.headers.host),
2315
- origin: Rn(e.headers.origin),
3060
+ host: Qn(e.headers.host),
3061
+ origin: Qn(e.headers.origin),
2316
3062
  expectedOrigin: n?.origin,
2317
3063
  remoteAddress: e.socket.remoteAddress ?? void 0
2318
3064
  }));
2319
3065
  }
2320
- function Rn(e) {
2321
- return !e || e.length <= mn ? e : `${e.slice(0, mn)}…`;
3066
+ function Qn(e) {
3067
+ return !e || e.length <= On ? e : `${e.slice(0, On)}…`;
2322
3068
  }
2323
- function zn(e, t) {
2324
- let n = On(e);
3069
+ function $n(e, t) {
3070
+ let n = Hn(e);
2325
3071
  if (!n) return !1;
2326
3072
  let r = t.port ? Number(t.port) : t.protocol === "https:" ? 443 : 80, i = t.protocol === "https:" ? 443 : 80, a = n.port ?? i;
2327
3073
  return Q(n.host) === Q(t.hostname) && a === r;
2328
3074
  }
2329
3075
  function $(e) {
2330
3076
  let t = e.address();
2331
- return !t || typeof t == "string" ? X : t.port;
3077
+ return !t || typeof t == "string" ? Cn : t.port;
2332
3078
  }
2333
- function Bn(e) {
3079
+ function er(e) {
2334
3080
  return u(e) === 6 ? `[${e}]` : e;
2335
3081
  }
2336
- function Vn(e, t) {
2337
- return `http://${Bn(t)}:${$(e)}/mcp`;
3082
+ function tr(e, t) {
3083
+ return `http://${er(t)}:${$(e)}/mcp`;
2338
3084
  }
2339
- function Hn() {
3085
+ function nr() {
2340
3086
  let t = /* @__PURE__ */ new Map();
2341
3087
  return (r) => {
2342
- if (!r.principal) return Un(o());
3088
+ if (!r.principal) return rr(o());
2343
3089
  for (let [e, n] of t) n.expiresAt <= r.now && t.delete(e);
2344
3090
  let i = n("sha256").update(JSON.stringify([
2345
3091
  r.endpoint.href,
@@ -2347,11 +3093,11 @@ function Hn() {
2347
3093
  e(r.requestBody)
2348
3094
  ])).digest("hex"), a = t.get(i);
2349
3095
  if (a) return a.scopeId;
2350
- let s = Un(JSON.stringify([i, r.now]));
3096
+ let s = rr(JSON.stringify([i, r.now]));
2351
3097
  for (t.set(i, {
2352
3098
  scopeId: s,
2353
- expiresAt: r.now + vn
2354
- }); t.size > yn;) {
3099
+ expiresAt: r.now + Mn
3100
+ }); t.size > Nn;) {
2355
3101
  let e = t.keys().next().value;
2356
3102
  if (e === void 0) break;
2357
3103
  t.delete(e);
@@ -2359,11 +3105,11 @@ function Hn() {
2359
3105
  return s;
2360
3106
  };
2361
3107
  }
2362
- function Un(e) {
3108
+ function rr(e) {
2363
3109
  return `mcp-http:${n("sha256").update(e).digest("hex")}`;
2364
3110
  }
2365
- function Wn(e, t, n, r) {
2366
- let i = Gn(e);
3111
+ function ir(e, t, n, r) {
3112
+ let i = ar(e);
2367
3113
  if (i === null) {
2368
3114
  r(e);
2369
3115
  return;
@@ -2377,31 +3123,31 @@ function Wn(e, t, n, r) {
2377
3123
  id: null
2378
3124
  });
2379
3125
  }
2380
- function Gn(e) {
3126
+ function ar(e) {
2381
3127
  if (typeof e != "object" || !e) return null;
2382
3128
  let t = e;
2383
3129
  return t.type === "entity.too.large" ? 413 : t.type === "entity.parse.failed" ? 400 : null;
2384
3130
  }
2385
- function Kn(e, t) {
3131
+ function or(e, t) {
2386
3132
  return e.protocol === "https:" || Z(e.hostname) && Q(e.hostname) !== "::1" ? new URL(e.origin) : new URL(`http://localhost:${t}/`);
2387
3133
  }
2388
- function qn(e) {
3134
+ function sr(e) {
2389
3135
  return e === "/register" || e === "/authorize" || e === "/token" || e === "/revoke" || e === "/oauth/callback" || e === "/.well-known/oauth-authorization-server" || e === "/.well-known/oauth-protected-resource/mcp";
2390
3136
  }
2391
- function Jn(e) {
3137
+ function cr(e) {
2392
3138
  return e.length > 1 ? e.replace(/\/+$/, "") : e;
2393
3139
  }
2394
- function Yn(e) {
3140
+ function lr(e) {
2395
3141
  return (t, n, r) => {
2396
3142
  let i = t.path;
2397
- if (!Xn(i)) return r();
3143
+ if (!ur(i)) return r();
2398
3144
  let a, o = n.json.bind(n);
2399
3145
  n.json = ((e) => (a = e, o(e))), n.on("finish", () => {
2400
3146
  if (i === "/oauth/callback") return;
2401
- let r = Zn(i, t);
3147
+ let r = dr(i, t);
2402
3148
  if (!r) return;
2403
- let o = $n(n, a), s = tr(t, a);
2404
- e(F(r, {
3149
+ let o = pr(n, a), s = hr(t, a);
3150
+ e(z(r, {
2405
3151
  outcome: o ? "denied" : "success",
2406
3152
  ...o ? { reason: o } : {},
2407
3153
  ...s ? { clientId: s } : {},
@@ -2410,17 +3156,17 @@ function Yn(e) {
2410
3156
  }), r();
2411
3157
  };
2412
3158
  }
2413
- function Xn(e) {
2414
- return Qn(e) !== null;
3159
+ function ur(e) {
3160
+ return fr(e) !== null;
2415
3161
  }
2416
- function Zn(e, t) {
2417
- return e === "/token" && t.body?.grant_type === "refresh_token" ? "refresh" : Qn(e);
3162
+ function dr(e, t) {
3163
+ return e === "/token" && t.body?.grant_type === "refresh_token" ? "refresh" : fr(e);
2418
3164
  }
2419
- function Qn(e) {
3165
+ function fr(e) {
2420
3166
  return e === "/register" ? "registration" : e === "/authorize" ? "authorize" : e === "/token" ? "token" : e === "/revoke" ? "revocation" : null;
2421
3167
  }
2422
- function $n(e, t) {
2423
- let n = er(t);
3168
+ function pr(e, t) {
3169
+ let n = mr(t);
2424
3170
  if (n) return n;
2425
3171
  let r = e.getHeader("location");
2426
3172
  if (typeof r == "string") try {
@@ -2429,38 +3175,38 @@ function $n(e, t) {
2429
3175
  return;
2430
3176
  }
2431
3177
  }
2432
- function er(e) {
3178
+ function mr(e) {
2433
3179
  if (typeof e == "object" && e && "error" in e && typeof e.error == "string") return e.error;
2434
3180
  }
2435
- function tr(e, t) {
3181
+ function hr(e, t) {
2436
3182
  return typeof t == "object" && t && "client_id" in t && typeof t.client_id == "string" ? t.client_id : (typeof e.body?.client_id == "string" ? e.body.client_id : void 0) || (typeof e.query.client_id == "string" ? e.query.client_id : void 0);
2437
3183
  }
2438
- function nr(e, t) {
3184
+ function gr(e, t) {
2439
3185
  return (n, r, i) => {
2440
- let a = rr(n.headers.authorization, t);
2441
- a && e(F("bearer", {
3186
+ let a = _r(n.headers.authorization, t);
3187
+ a && e(z("bearer", {
2442
3188
  outcome: "denied",
2443
3189
  reason: a,
2444
3190
  remoteAddress: n.socket.remoteAddress ?? void 0
2445
3191
  })), i();
2446
3192
  };
2447
3193
  }
2448
- function rr(e, t) {
3194
+ function _r(e, t) {
2449
3195
  if (!e) return "missing_authorization_header";
2450
3196
  let [n, r, i] = e.trim().split(/\s+/);
2451
3197
  if (!n || !r || i || n.toLowerCase() !== "bearer") return "malformed_authorization_header";
2452
3198
  let a = t.verifyToken(r);
2453
3199
  return a.ok ? null : a.reason;
2454
3200
  }
2455
- function ir(e) {
3201
+ function vr(e) {
2456
3202
  return e?.split(/\s+/).map((e) => e.trim()).filter(Boolean) ?? [];
2457
3203
  }
2458
- function ar() {
3204
+ function yr() {
2459
3205
  let e = process.argv[1];
2460
3206
  return e ? import.meta.url === f(e).href : !1;
2461
3207
  }
2462
- async function or() {
2463
- let e = await An();
3208
+ async function br() {
3209
+ let e = await Wn();
2464
3210
  console.error(`codemem MCP HTTP server listening at ${e.url}`);
2465
3211
  let t = async () => {
2466
3212
  try {
@@ -2470,10 +3216,10 @@ async function or() {
2470
3216
  };
2471
3217
  process.on("SIGINT", t), process.on("SIGTERM", t);
2472
3218
  }
2473
- ar() && or().catch((e) => {
3219
+ yr() && br().catch((e) => {
2474
3220
  console.error("codemem MCP HTTP server failed to start:", e), process.exit(1);
2475
3221
  });
2476
3222
  //#endregion
2477
- export { ln as DEFAULT_MCP_HTTP_HOST, X as DEFAULT_MCP_HTTP_PORT, _n as MCP_HTTP_MAX_JSON_BODY_BYTES, vn as MCP_HTTP_RETRIEVAL_RETRY_WINDOW_MS, Sn as authenticatedRetrievalPrincipal, Tn as isAllowedMcpHttpRequestHost, En as isAllowedMcpHttpRequestOrigin, Dn as isAllowedMcpHttpRequestRemoteAddress, Z as isLoopbackHost, wn as isUnsafePublicBindAllowed, kn as parseMcpHttpPort, An as startCodememMcpHttpServer, Cn as validateMcpHttpHost };
3223
+ export { Sn as DEFAULT_MCP_HTTP_HOST, Cn as DEFAULT_MCP_HTTP_PORT, jn as MCP_HTTP_MAX_JSON_BODY_BYTES, Mn as MCP_HTTP_RETRIEVAL_RETRY_WINDOW_MS, In as authenticatedRetrievalPrincipal, zn as isAllowedMcpHttpRequestHost, Bn as isAllowedMcpHttpRequestOrigin, Vn as isAllowedMcpHttpRequestRemoteAddress, Z as isLoopbackHost, Rn as isUnsafePublicBindAllowed, Un as parseMcpHttpPort, Wn as startCodememMcpHttpServer, Ln as validateMcpHttpHost };
2478
3224
 
2479
3225
  //# sourceMappingURL=http.js.map