@tool-bridge/server 0.16.0 → 0.17.0

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.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
  7. package/dist/chunk-JXHMDBAY.js +45 -0
  8. package/dist/chunk-LMLX3DJF.js +50 -0
  9. package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
  10. package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
  11. package/dist/chunk-U5UHT7CX.js +977 -0
  12. package/dist/chunk-U67V476Y.js +35 -0
  13. package/dist/chunk-WW2IMPQK.js +283 -0
  14. package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
  44. package/dist/index.d.ts +57 -50
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.js} +124 -150
  107. package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
  108. package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-BNXOJMB6.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
  112. package/package.json +5 -5
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. package/dist/chunk-MLKGABMK.js +0 -9
@@ -0,0 +1,977 @@
1
+ import {
2
+ TBError
3
+ } from "./chunk-RVWZN3CI.js";
4
+ import {
5
+ __commonJS,
6
+ __toESM
7
+ } from "./chunk-U67V476Y.js";
8
+
9
+ // ../../node_modules/.pnpm/ipaddr.js@2.5.0/node_modules/ipaddr.js/lib/ipaddr.js
10
+ var require_ipaddr = __commonJS({
11
+ "../../node_modules/.pnpm/ipaddr.js@2.5.0/node_modules/ipaddr.js/lib/ipaddr.js"(exports, module) {
12
+ "use strict";
13
+ (function(root) {
14
+ "use strict";
15
+ const ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
16
+ const ipv4Regexes = {
17
+ fourOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}$`, "i"),
18
+ threeOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}$`, "i"),
19
+ twoOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}$`, "i"),
20
+ longValue: new RegExp(`^${ipv4Part}$`, "i")
21
+ };
22
+ const octalRegex = new RegExp(`^0[0-7]+$`, "i");
23
+ const hexRegex = new RegExp(`^0x[a-f0-9]+$`, "i");
24
+ const zoneIndex = "%[0-9a-z]{1,}";
25
+ const ipv6Part = "(?:[0-9a-f]+::?)+";
26
+ const ipv6Regexes = {
27
+ zoneIndex: new RegExp(zoneIndex, "i"),
28
+ "native": new RegExp(`^(::)?(${ipv6Part})?([0-9a-f]+)?(::)?(${zoneIndex})?$`, "i"),
29
+ deprecatedTransitional: new RegExp(`^(?:::)(${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}(${zoneIndex})?)$`, "i"),
30
+ transitional: new RegExp(`^((?:${ipv6Part})|(?:::)(?:${ipv6Part})?)${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}(${zoneIndex})?$`, "i")
31
+ };
32
+ function expandIPv6(string, parts) {
33
+ if (string.indexOf("::") !== string.lastIndexOf("::")) {
34
+ return null;
35
+ }
36
+ let colonCount = 0;
37
+ let lastColon = -1;
38
+ let zoneId = (string.match(ipv6Regexes.zoneIndex) || [])[0];
39
+ let replacement, replacementCount;
40
+ if (zoneId) {
41
+ zoneId = zoneId.substring(1);
42
+ string = string.replace(/%.+$/, "");
43
+ }
44
+ while ((lastColon = string.indexOf(":", lastColon + 1)) >= 0) {
45
+ colonCount++;
46
+ }
47
+ if (string.substr(0, 2) === "::") {
48
+ colonCount--;
49
+ }
50
+ if (string.substr(-2, 2) === "::") {
51
+ colonCount--;
52
+ }
53
+ if (colonCount >= parts) {
54
+ return null;
55
+ }
56
+ replacementCount = parts - colonCount;
57
+ replacement = ":";
58
+ while (replacementCount--) {
59
+ replacement += "0:";
60
+ }
61
+ string = string.replace("::", replacement);
62
+ if (string[0] === ":") {
63
+ string = string.slice(1);
64
+ }
65
+ if (string[string.length - 1] === ":") {
66
+ string = string.slice(0, -1);
67
+ }
68
+ parts = (function() {
69
+ const ref = string.split(":");
70
+ const results = [];
71
+ for (let i = 0; i < ref.length; i++) {
72
+ results.push(ref[i].length > 4 ? NaN : parseInt(ref[i], 16));
73
+ }
74
+ return results;
75
+ })();
76
+ return {
77
+ parts,
78
+ zoneId
79
+ };
80
+ }
81
+ function matchCIDR(first, second, partSize, cidrBits) {
82
+ if (first.length !== second.length) {
83
+ throw new Error("ipaddr: cannot match CIDR for objects with different lengths");
84
+ }
85
+ let part = 0;
86
+ let shift;
87
+ while (cidrBits > 0) {
88
+ shift = partSize - cidrBits;
89
+ if (shift < 0) {
90
+ shift = 0;
91
+ }
92
+ if (first[part] >> shift !== second[part] >> shift) {
93
+ return false;
94
+ }
95
+ cidrBits -= partSize;
96
+ part += 1;
97
+ }
98
+ return true;
99
+ }
100
+ function parseIntAuto(string) {
101
+ if (hexRegex.test(string)) {
102
+ return parseInt(string, 16);
103
+ }
104
+ if (string[0] === "0" && !isNaN(parseInt(string[1], 10))) {
105
+ if (octalRegex.test(string)) {
106
+ return parseInt(string, 8);
107
+ }
108
+ throw new Error(`ipaddr: cannot parse ${string} as octal`);
109
+ }
110
+ return parseInt(string, 10);
111
+ }
112
+ function padPart(part, length) {
113
+ while (part.length < length) {
114
+ part = `0${part}`;
115
+ }
116
+ return part;
117
+ }
118
+ const ipaddr2 = {};
119
+ ipaddr2.IPv4 = (function() {
120
+ function IPv4(octets) {
121
+ if (octets.length !== 4) {
122
+ throw new Error("ipaddr: ipv4 octet count should be 4");
123
+ }
124
+ let i, octet;
125
+ for (i = 0; i < octets.length; i++) {
126
+ octet = octets[i];
127
+ if (!(0 <= octet && octet <= 255)) {
128
+ throw new Error("ipaddr: ipv4 octet should fit in 8 bits");
129
+ }
130
+ }
131
+ this.octets = octets;
132
+ }
133
+ IPv4.prototype.SpecialRanges = {
134
+ unspecified: [[new IPv4([0, 0, 0, 0]), 8]],
135
+ broadcast: [[new IPv4([255, 255, 255, 255]), 32]],
136
+ // RFC3171
137
+ multicast: [[new IPv4([224, 0, 0, 0]), 4]],
138
+ // RFC3927
139
+ linkLocal: [[new IPv4([169, 254, 0, 0]), 16]],
140
+ // RFC5735
141
+ loopback: [[new IPv4([127, 0, 0, 0]), 8]],
142
+ // RFC6598
143
+ carrierGradeNat: [[new IPv4([100, 64, 0, 0]), 10]],
144
+ // RFC1918
145
+ "private": [
146
+ [new IPv4([10, 0, 0, 0]), 8],
147
+ [new IPv4([172, 16, 0, 0]), 12],
148
+ [new IPv4([192, 168, 0, 0]), 16]
149
+ ],
150
+ // Reserved and testing-only ranges; RFCs 5735, 5737, 2544, 1700
151
+ reserved: [
152
+ [new IPv4([192, 0, 0, 0]), 24],
153
+ [new IPv4([192, 0, 2, 0]), 24],
154
+ [new IPv4([192, 88, 99, 0]), 24],
155
+ [new IPv4([198, 18, 0, 0]), 15],
156
+ [new IPv4([198, 51, 100, 0]), 24],
157
+ [new IPv4([203, 0, 113, 0]), 24],
158
+ [new IPv4([240, 0, 0, 0]), 4]
159
+ ],
160
+ // RFC7534, RFC7535
161
+ as112: [
162
+ [new IPv4([192, 175, 48, 0]), 24],
163
+ [new IPv4([192, 31, 196, 0]), 24]
164
+ ],
165
+ // RFC7450
166
+ amt: [
167
+ [new IPv4([192, 52, 193, 0]), 24]
168
+ ]
169
+ };
170
+ IPv4.prototype.kind = function() {
171
+ return "ipv4";
172
+ };
173
+ IPv4.prototype.match = function(other, cidrRange) {
174
+ let ref;
175
+ if (cidrRange === void 0) {
176
+ ref = other;
177
+ other = ref[0];
178
+ cidrRange = ref[1];
179
+ }
180
+ if (other.kind() !== "ipv4") {
181
+ throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");
182
+ }
183
+ return matchCIDR(this.octets, other.octets, 8, cidrRange);
184
+ };
185
+ IPv4.prototype.prefixLengthFromSubnetMask = function() {
186
+ let cidr = 0;
187
+ let stop = false;
188
+ const zerotable = {
189
+ 0: 8,
190
+ 128: 7,
191
+ 192: 6,
192
+ 224: 5,
193
+ 240: 4,
194
+ 248: 3,
195
+ 252: 2,
196
+ 254: 1,
197
+ 255: 0
198
+ };
199
+ let i, octet, zeros;
200
+ for (i = 3; i >= 0; i -= 1) {
201
+ octet = this.octets[i];
202
+ if (octet in zerotable) {
203
+ zeros = zerotable[octet];
204
+ if (stop && zeros !== 0) {
205
+ return null;
206
+ }
207
+ if (zeros !== 8) {
208
+ stop = true;
209
+ }
210
+ cidr += zeros;
211
+ } else {
212
+ return null;
213
+ }
214
+ }
215
+ return 32 - cidr;
216
+ };
217
+ IPv4.prototype.range = function() {
218
+ return ipaddr2.subnetMatch(this, this.SpecialRanges);
219
+ };
220
+ IPv4.prototype.toByteArray = function() {
221
+ return this.octets.slice(0);
222
+ };
223
+ IPv4.prototype.toIPv4MappedAddress = function() {
224
+ return ipaddr2.IPv6.parse(`::ffff:${this.toString()}`);
225
+ };
226
+ IPv4.prototype.toNormalizedString = function() {
227
+ return this.toString();
228
+ };
229
+ IPv4.prototype.toString = function() {
230
+ return this.octets.join(".");
231
+ };
232
+ return IPv4;
233
+ })();
234
+ ipaddr2.IPv4.broadcastAddressFromCIDR = function(string) {
235
+ try {
236
+ const cidr = this.parseCIDR(string);
237
+ const ipInterfaceOctets = cidr[0].toByteArray();
238
+ const subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
239
+ const octets = [];
240
+ let i = 0;
241
+ while (i < 4) {
242
+ octets.push(parseInt(ipInterfaceOctets[i], 10) | parseInt(subnetMaskOctets[i], 10) ^ 255);
243
+ i++;
244
+ }
245
+ return new this(octets);
246
+ } catch (e) {
247
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
248
+ }
249
+ };
250
+ ipaddr2.IPv4.isIPv4 = function(string) {
251
+ return this.parser(string) !== null;
252
+ };
253
+ ipaddr2.IPv4.isValid = function(string) {
254
+ try {
255
+ new this(this.parser(string));
256
+ return true;
257
+ } catch {
258
+ return false;
259
+ }
260
+ };
261
+ ipaddr2.IPv4.isValidCIDR = function(string) {
262
+ try {
263
+ this.parseCIDR(string);
264
+ return true;
265
+ } catch {
266
+ return false;
267
+ }
268
+ };
269
+ ipaddr2.IPv4.isValidFourPartDecimal = function(string) {
270
+ if (ipaddr2.IPv4.isValid(string) && string.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/)) {
271
+ return true;
272
+ } else {
273
+ return false;
274
+ }
275
+ };
276
+ ipaddr2.IPv4.isValidCIDRFourPartDecimal = function(string) {
277
+ const match = string.match(/^(.+)\/(\d+)$/);
278
+ if (!ipaddr2.IPv4.isValidCIDR(string) || !match) {
279
+ return false;
280
+ }
281
+ return ipaddr2.IPv4.isValidFourPartDecimal(match[1]);
282
+ };
283
+ ipaddr2.IPv4.networkAddressFromCIDR = function(string) {
284
+ let cidr, i, ipInterfaceOctets, octets, subnetMaskOctets;
285
+ try {
286
+ cidr = this.parseCIDR(string);
287
+ ipInterfaceOctets = cidr[0].toByteArray();
288
+ subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
289
+ octets = [];
290
+ i = 0;
291
+ while (i < 4) {
292
+ octets.push(parseInt(ipInterfaceOctets[i], 10) & parseInt(subnetMaskOctets[i], 10));
293
+ i++;
294
+ }
295
+ return new this(octets);
296
+ } catch (e) {
297
+ throw new Error("ipaddr: the address does not have IPv4 CIDR format", { cause: e });
298
+ }
299
+ };
300
+ ipaddr2.IPv4.parse = function(string) {
301
+ const parts = this.parser(string);
302
+ if (parts === null) {
303
+ throw new Error("ipaddr: string is not formatted like an IPv4 Address");
304
+ }
305
+ return new this(parts);
306
+ };
307
+ ipaddr2.IPv4.parseCIDR = function(string) {
308
+ let match;
309
+ if (match = string.match(/^(.+)\/(\d+)$/)) {
310
+ const maskLength = parseInt(match[2]);
311
+ if (maskLength >= 0 && maskLength <= 32) {
312
+ const parsed = [this.parse(match[1]), maskLength];
313
+ Object.defineProperty(parsed, "toString", {
314
+ value: function() {
315
+ return this.join("/");
316
+ }
317
+ });
318
+ return parsed;
319
+ }
320
+ }
321
+ throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range");
322
+ };
323
+ ipaddr2.IPv4.parser = function(string) {
324
+ let match, part, value;
325
+ if (match = string.match(ipv4Regexes.fourOctet)) {
326
+ return (function() {
327
+ const ref = match.slice(1, 6);
328
+ const results = [];
329
+ for (let i = 0; i < ref.length; i++) {
330
+ part = ref[i];
331
+ results.push(parseIntAuto(part));
332
+ }
333
+ return results;
334
+ })();
335
+ } else if (match = string.match(ipv4Regexes.longValue)) {
336
+ value = parseIntAuto(match[1]);
337
+ if (value > 4294967295 || value < 0) {
338
+ throw new Error("ipaddr: address outside defined range");
339
+ }
340
+ return (function() {
341
+ const results = [];
342
+ let shift;
343
+ for (shift = 0; shift <= 24; shift += 8) {
344
+ results.push(value >> shift & 255);
345
+ }
346
+ return results;
347
+ })().reverse();
348
+ } else if (match = string.match(ipv4Regexes.twoOctet)) {
349
+ return (function() {
350
+ const ref = match.slice(1, 4);
351
+ const results = [];
352
+ value = parseIntAuto(ref[1]);
353
+ if (value > 16777215 || value < 0) {
354
+ throw new Error("ipaddr: address outside defined range");
355
+ }
356
+ results.push(parseIntAuto(ref[0]));
357
+ results.push(value >> 16 & 255);
358
+ results.push(value >> 8 & 255);
359
+ results.push(value & 255);
360
+ return results;
361
+ })();
362
+ } else if (match = string.match(ipv4Regexes.threeOctet)) {
363
+ return (function() {
364
+ const ref = match.slice(1, 5);
365
+ const results = [];
366
+ value = parseIntAuto(ref[2]);
367
+ if (value > 65535 || value < 0) {
368
+ throw new Error("ipaddr: address outside defined range");
369
+ }
370
+ results.push(parseIntAuto(ref[0]));
371
+ results.push(parseIntAuto(ref[1]));
372
+ results.push(value >> 8 & 255);
373
+ results.push(value & 255);
374
+ return results;
375
+ })();
376
+ } else {
377
+ return null;
378
+ }
379
+ };
380
+ ipaddr2.IPv4.subnetMaskFromPrefixLength = function(prefix) {
381
+ prefix = parseInt(prefix);
382
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 32) {
383
+ throw new Error("ipaddr: invalid IPv4 prefix length");
384
+ }
385
+ const octets = [0, 0, 0, 0];
386
+ let j = 0;
387
+ const filledOctetCount = Math.floor(prefix / 8);
388
+ while (j < filledOctetCount) {
389
+ octets[j] = 255;
390
+ j++;
391
+ }
392
+ if (filledOctetCount < 4) {
393
+ octets[filledOctetCount] = Math.pow(2, prefix % 8) - 1 << 8 - prefix % 8;
394
+ }
395
+ return new this(octets);
396
+ };
397
+ ipaddr2.IPv6 = (function() {
398
+ function IPv6(parts, zoneId) {
399
+ let i, part;
400
+ if (parts.length === 16) {
401
+ this.parts = [];
402
+ for (i = 0; i <= 14; i += 2) {
403
+ this.parts.push(parts[i] << 8 | parts[i + 1]);
404
+ }
405
+ } else if (parts.length === 8) {
406
+ this.parts = parts;
407
+ } else {
408
+ throw new Error("ipaddr: ipv6 part count should be 8 or 16");
409
+ }
410
+ for (i = 0; i < this.parts.length; i++) {
411
+ part = this.parts[i];
412
+ if (!(0 <= part && part <= 65535)) {
413
+ throw new Error("ipaddr: ipv6 part should fit in 16 bits");
414
+ }
415
+ }
416
+ if (zoneId) {
417
+ this.zoneId = zoneId;
418
+ }
419
+ }
420
+ IPv6.prototype.SpecialRanges = {
421
+ // RFC4291, here and after
422
+ unspecified: [new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128],
423
+ linkLocal: [new IPv6([65152, 0, 0, 0, 0, 0, 0, 0]), 10],
424
+ multicast: [new IPv6([65280, 0, 0, 0, 0, 0, 0, 0]), 8],
425
+ loopback: [new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128],
426
+ uniqueLocal: [new IPv6([64512, 0, 0, 0, 0, 0, 0, 0]), 7],
427
+ ipv4Mapped: [new IPv6([0, 0, 0, 0, 0, 65535, 0, 0]), 96],
428
+ // RFC3879
429
+ deprecatedSiteLocal: [new IPv6([65216, 0, 0, 0, 0, 0, 0, 0]), 10],
430
+ // RFC6666
431
+ discard: [new IPv6([256, 0, 0, 0, 0, 0, 0, 0]), 64],
432
+ // RFC6145
433
+ rfc6145: [new IPv6([0, 0, 0, 0, 65535, 0, 0, 0]), 96],
434
+ rfc6052: [
435
+ // RFC6052
436
+ [new IPv6([100, 65435, 0, 0, 0, 0, 0, 0]), 96],
437
+ // RFC8215
438
+ [new IPv6([100, 65435, 1, 0, 0, 0, 0, 0]), 48]
439
+ ],
440
+ // RFC3056
441
+ "6to4": [new IPv6([8194, 0, 0, 0, 0, 0, 0, 0]), 16],
442
+ // RFC6052, RFC6146
443
+ teredo: [new IPv6([8193, 0, 0, 0, 0, 0, 0, 0]), 32],
444
+ // RFC5180
445
+ benchmarking: [new IPv6([8193, 2, 0, 0, 0, 0, 0, 0]), 48],
446
+ // RFC7450
447
+ amt: [new IPv6([8193, 3, 0, 0, 0, 0, 0, 0]), 32],
448
+ as112v6: [
449
+ // RFC7535
450
+ [new IPv6([8193, 4, 274, 0, 0, 0, 0, 0]), 48],
451
+ // RFC7534
452
+ [new IPv6([9760, 79, 32768, 0, 0, 0, 0, 0]), 48]
453
+ ],
454
+ // RFC4843
455
+ deprecatedOrchid: [new IPv6([8193, 16, 0, 0, 0, 0, 0, 0]), 28],
456
+ // RFC7343
457
+ orchid2: [new IPv6([8193, 32, 0, 0, 0, 0, 0, 0]), 28],
458
+ // RFC9374
459
+ droneRemoteIdProtocolEntityTags: [new IPv6([8193, 48, 0, 0, 0, 0, 0, 0]), 28],
460
+ // RFC9602
461
+ segmentRouting: [new IPv6([24320, 0, 0, 0, 0, 0, 0, 0]), 16],
462
+ reserved: [
463
+ // RFC3849
464
+ [new IPv6([8193, 0, 0, 0, 0, 0, 0, 0]), 23],
465
+ // RFC2928
466
+ [new IPv6([8193, 3512, 0, 0, 0, 0, 0, 0]), 32],
467
+ // RFC9637
468
+ [new IPv6([16383, 0, 0, 0, 0, 0, 0, 0]), 20]
469
+ ]
470
+ };
471
+ IPv6.prototype.isIPv4MappedAddress = function() {
472
+ return this.range() === "ipv4Mapped";
473
+ };
474
+ IPv6.prototype.kind = function() {
475
+ return "ipv6";
476
+ };
477
+ IPv6.prototype.match = function(other, cidrRange) {
478
+ let ref;
479
+ if (cidrRange === void 0) {
480
+ ref = other;
481
+ other = ref[0];
482
+ cidrRange = ref[1];
483
+ }
484
+ if (other.kind() !== "ipv6") {
485
+ throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");
486
+ }
487
+ return matchCIDR(this.parts, other.parts, 16, cidrRange);
488
+ };
489
+ IPv6.prototype.prefixLengthFromSubnetMask = function() {
490
+ let cidr = 0;
491
+ let stop = false;
492
+ const zerotable = {
493
+ 0: 16,
494
+ 32768: 15,
495
+ 49152: 14,
496
+ 57344: 13,
497
+ 61440: 12,
498
+ 63488: 11,
499
+ 64512: 10,
500
+ 65024: 9,
501
+ 65280: 8,
502
+ 65408: 7,
503
+ 65472: 6,
504
+ 65504: 5,
505
+ 65520: 4,
506
+ 65528: 3,
507
+ 65532: 2,
508
+ 65534: 1,
509
+ 65535: 0
510
+ };
511
+ let part, zeros;
512
+ for (let i = 7; i >= 0; i -= 1) {
513
+ part = this.parts[i];
514
+ if (part in zerotable) {
515
+ zeros = zerotable[part];
516
+ if (stop && zeros !== 0) {
517
+ return null;
518
+ }
519
+ if (zeros !== 16) {
520
+ stop = true;
521
+ }
522
+ cidr += zeros;
523
+ } else {
524
+ return null;
525
+ }
526
+ }
527
+ return 128 - cidr;
528
+ };
529
+ IPv6.prototype.range = function() {
530
+ return ipaddr2.subnetMatch(this, this.SpecialRanges);
531
+ };
532
+ IPv6.prototype.toByteArray = function() {
533
+ let part;
534
+ const bytes = [];
535
+ const ref = this.parts;
536
+ for (let i = 0; i < ref.length; i++) {
537
+ part = ref[i];
538
+ bytes.push(part >> 8);
539
+ bytes.push(part & 255);
540
+ }
541
+ return bytes;
542
+ };
543
+ IPv6.prototype.toFixedLengthString = function() {
544
+ const addr = (function() {
545
+ const results = [];
546
+ for (let i = 0; i < this.parts.length; i++) {
547
+ results.push(padPart(this.parts[i].toString(16), 4));
548
+ }
549
+ return results;
550
+ }).call(this).join(":");
551
+ let suffix = "";
552
+ if (this.zoneId) {
553
+ suffix = `%${this.zoneId}`;
554
+ }
555
+ return addr + suffix;
556
+ };
557
+ IPv6.prototype.toIPv4Address = function() {
558
+ if (!this.isIPv4MappedAddress()) {
559
+ throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");
560
+ }
561
+ const ref = this.parts.slice(-2);
562
+ const high = ref[0];
563
+ const low = ref[1];
564
+ return new ipaddr2.IPv4([high >> 8, high & 255, low >> 8, low & 255]);
565
+ };
566
+ IPv6.prototype.toNormalizedString = function() {
567
+ const addr = (function() {
568
+ const results = [];
569
+ for (let i = 0; i < this.parts.length; i++) {
570
+ results.push(this.parts[i].toString(16));
571
+ }
572
+ return results;
573
+ }).call(this).join(":");
574
+ let suffix = "";
575
+ if (this.zoneId) {
576
+ suffix = `%${this.zoneId}`;
577
+ }
578
+ return addr + suffix;
579
+ };
580
+ IPv6.prototype.toRFC5952String = function() {
581
+ const regex = /((^|:)(0(:|$)){2,})/g;
582
+ let suffix = "";
583
+ if (this.zoneId) {
584
+ suffix = `%${this.zoneId}`;
585
+ }
586
+ const normalized = this.toNormalizedString();
587
+ const string = normalized.slice(0, normalized.length - suffix.length);
588
+ let bestMatchIndex = 0;
589
+ let bestMatchLength = -1;
590
+ let bestMatchGroups = -1;
591
+ let match;
592
+ while (match = regex.exec(string)) {
593
+ const groups = (match[0].match(/0/g) || []).length;
594
+ if (groups > bestMatchGroups) {
595
+ bestMatchGroups = groups;
596
+ bestMatchIndex = match.index;
597
+ bestMatchLength = match[0].length;
598
+ }
599
+ }
600
+ if (bestMatchLength < 0) {
601
+ return string + suffix;
602
+ }
603
+ return `${string.substring(0, bestMatchIndex)}::${string.substring(bestMatchIndex + bestMatchLength)}${suffix}`;
604
+ };
605
+ IPv6.prototype.toString = function() {
606
+ return this.toRFC5952String();
607
+ };
608
+ return IPv6;
609
+ })();
610
+ ipaddr2.IPv6.broadcastAddressFromCIDR = function(string) {
611
+ try {
612
+ const cidr = this.parseCIDR(string);
613
+ const ipInterfaceOctets = cidr[0].toByteArray();
614
+ const subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
615
+ const octets = [];
616
+ let i = 0;
617
+ while (i < 16) {
618
+ octets.push(parseInt(ipInterfaceOctets[i], 10) | parseInt(subnetMaskOctets[i], 10) ^ 255);
619
+ i++;
620
+ }
621
+ return new this(octets);
622
+ } catch (e) {
623
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
624
+ }
625
+ };
626
+ ipaddr2.IPv6.isIPv6 = function(string) {
627
+ return this.parser(string) !== null;
628
+ };
629
+ ipaddr2.IPv6.isValid = function(string) {
630
+ if (typeof string === "string" && string.indexOf(":") === -1) {
631
+ return false;
632
+ }
633
+ try {
634
+ const addr = this.parser(string);
635
+ new this(addr.parts, addr.zoneId);
636
+ return true;
637
+ } catch {
638
+ return false;
639
+ }
640
+ };
641
+ ipaddr2.IPv6.isValidCIDR = function(string) {
642
+ if (typeof string === "string" && string.indexOf(":") === -1) {
643
+ return false;
644
+ }
645
+ try {
646
+ this.parseCIDR(string);
647
+ return true;
648
+ } catch {
649
+ return false;
650
+ }
651
+ };
652
+ ipaddr2.IPv6.networkAddressFromCIDR = function(string) {
653
+ let cidr, i, ipInterfaceOctets, octets, subnetMaskOctets;
654
+ try {
655
+ cidr = this.parseCIDR(string);
656
+ ipInterfaceOctets = cidr[0].toByteArray();
657
+ subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray();
658
+ octets = [];
659
+ i = 0;
660
+ while (i < 16) {
661
+ octets.push(parseInt(ipInterfaceOctets[i], 10) & parseInt(subnetMaskOctets[i], 10));
662
+ i++;
663
+ }
664
+ return new this(octets);
665
+ } catch (e) {
666
+ throw new Error("ipaddr: the address does not have IPv6 CIDR format", { cause: e });
667
+ }
668
+ };
669
+ ipaddr2.IPv6.parse = function(string) {
670
+ const addr = this.parser(string);
671
+ if (addr === null) {
672
+ throw new Error("ipaddr: string is not formatted like an IPv6 Address");
673
+ }
674
+ return new this(addr.parts, addr.zoneId);
675
+ };
676
+ ipaddr2.IPv6.parseCIDR = function(string) {
677
+ let maskLength, match, parsed;
678
+ if (match = string.match(/^(.+)\/(\d+)$/)) {
679
+ maskLength = parseInt(match[2]);
680
+ if (maskLength >= 0 && maskLength <= 128) {
681
+ parsed = [this.parse(match[1]), maskLength];
682
+ Object.defineProperty(parsed, "toString", {
683
+ value: function() {
684
+ return this.join("/");
685
+ }
686
+ });
687
+ return parsed;
688
+ }
689
+ }
690
+ throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range");
691
+ };
692
+ ipaddr2.IPv6.parser = function(string) {
693
+ let addr, i, match, octet, octets, zoneId;
694
+ if (match = string.match(ipv6Regexes.deprecatedTransitional)) {
695
+ return this.parser(`::ffff:${match[1]}`);
696
+ }
697
+ if (ipv6Regexes.native.test(string)) {
698
+ return expandIPv6(string, 8);
699
+ }
700
+ if (match = string.match(ipv6Regexes.transitional)) {
701
+ zoneId = match[6] || "";
702
+ addr = match[1];
703
+ if (!match[1].endsWith("::")) {
704
+ addr = addr.slice(0, -1);
705
+ }
706
+ addr = expandIPv6(addr + zoneId, 6);
707
+ if (addr && addr.parts) {
708
+ octets = [
709
+ parseInt(match[2]),
710
+ parseInt(match[3]),
711
+ parseInt(match[4]),
712
+ parseInt(match[5])
713
+ ];
714
+ for (i = 0; i < octets.length; i++) {
715
+ octet = octets[i];
716
+ if (!(0 <= octet && octet <= 255)) {
717
+ return null;
718
+ }
719
+ }
720
+ addr.parts.push(octets[0] << 8 | octets[1]);
721
+ addr.parts.push(octets[2] << 8 | octets[3]);
722
+ return {
723
+ parts: addr.parts,
724
+ zoneId: addr.zoneId
725
+ };
726
+ }
727
+ }
728
+ return null;
729
+ };
730
+ ipaddr2.IPv6.subnetMaskFromPrefixLength = function(prefix) {
731
+ prefix = parseInt(prefix);
732
+ if (Number.isNaN(prefix) || prefix < 0 || prefix > 128) {
733
+ throw new Error("ipaddr: invalid IPv6 prefix length");
734
+ }
735
+ const octets = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
736
+ let j = 0;
737
+ const filledOctetCount = Math.floor(prefix / 8);
738
+ while (j < filledOctetCount) {
739
+ octets[j] = 255;
740
+ j++;
741
+ }
742
+ if (filledOctetCount < 16) {
743
+ octets[filledOctetCount] = Math.pow(2, prefix % 8) - 1 << 8 - prefix % 8;
744
+ }
745
+ return new this(octets);
746
+ };
747
+ ipaddr2.fromByteArray = function(bytes) {
748
+ const length = bytes.length;
749
+ if (length === 4) {
750
+ return new ipaddr2.IPv4(bytes);
751
+ } else if (length === 16) {
752
+ return new ipaddr2.IPv6(bytes);
753
+ } else {
754
+ throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address");
755
+ }
756
+ };
757
+ ipaddr2.isValid = function(string) {
758
+ return ipaddr2.IPv6.isValid(string) || ipaddr2.IPv4.isValid(string);
759
+ };
760
+ ipaddr2.isValidCIDR = function(string) {
761
+ return ipaddr2.IPv6.isValidCIDR(string) || ipaddr2.IPv4.isValidCIDR(string);
762
+ };
763
+ ipaddr2.parse = function(string) {
764
+ if (ipaddr2.IPv6.isValid(string)) {
765
+ return ipaddr2.IPv6.parse(string);
766
+ } else if (ipaddr2.IPv4.isValid(string)) {
767
+ return ipaddr2.IPv4.parse(string);
768
+ } else {
769
+ throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format");
770
+ }
771
+ };
772
+ ipaddr2.parseCIDR = function(string) {
773
+ try {
774
+ return ipaddr2.IPv6.parseCIDR(string);
775
+ } catch {
776
+ try {
777
+ return ipaddr2.IPv4.parseCIDR(string);
778
+ } catch (e) {
779
+ throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format", { cause: e });
780
+ }
781
+ }
782
+ };
783
+ ipaddr2.process = function(string) {
784
+ const addr = this.parse(string);
785
+ if (addr.kind() === "ipv6" && addr.isIPv4MappedAddress()) {
786
+ return addr.toIPv4Address();
787
+ } else {
788
+ return addr;
789
+ }
790
+ };
791
+ ipaddr2.subnetMatch = function(address, rangeList, defaultName) {
792
+ let i, rangeName, rangeSubnets, subnet;
793
+ if (defaultName === void 0 || defaultName === null) {
794
+ defaultName = "unicast";
795
+ }
796
+ for (rangeName in rangeList) {
797
+ if (Object.prototype.hasOwnProperty.call(rangeList, rangeName)) {
798
+ rangeSubnets = rangeList[rangeName];
799
+ if (rangeSubnets[0] && !(rangeSubnets[0] instanceof Array)) {
800
+ rangeSubnets = [rangeSubnets];
801
+ }
802
+ for (i = 0; i < rangeSubnets.length; i++) {
803
+ subnet = rangeSubnets[i];
804
+ if (address.kind() === subnet[0].kind() && address.match.apply(address, subnet)) {
805
+ return rangeName;
806
+ }
807
+ }
808
+ }
809
+ }
810
+ return defaultName;
811
+ };
812
+ if (typeof module !== "undefined" && module.exports) {
813
+ module.exports = ipaddr2;
814
+ } else {
815
+ root.ipaddr = ipaddr2;
816
+ }
817
+ })(exports);
818
+ }
819
+ });
820
+
821
+ // ../plugins/src/_runtime/ipPolicy.ts
822
+ var import_ipaddr = __toESM(require_ipaddr(), 1);
823
+ function isStrictIpv4(value) {
824
+ return import_ipaddr.default.IPv4.isValidFourPartDecimal(value) && value.split(".").every((part) => part === "0" || !part.startsWith("0"));
825
+ }
826
+ function parseAddress(value) {
827
+ let text = value;
828
+ if (text.startsWith("[") && text.endsWith("]")) text = text.slice(1, -1);
829
+ const embeddedIpv4 = text.includes(".") ? text.slice(text.lastIndexOf(":") + 1) : void 0;
830
+ if (embeddedIpv4 !== void 0 && !isStrictIpv4(embeddedIpv4)) return void 0;
831
+ try {
832
+ if (isStrictIpv4(text)) return import_ipaddr.default.IPv4.parse(text);
833
+ if (import_ipaddr.default.IPv6.isValid(text)) return import_ipaddr.default.IPv6.parse(text);
834
+ } catch {
835
+ }
836
+ return void 0;
837
+ }
838
+ function classifyIpv4(octets) {
839
+ const a = octets[0];
840
+ const b = octets[1];
841
+ const c = octets[2];
842
+ if (a === 0) return "blocked";
843
+ if (a === 10) return "blocked";
844
+ if (a === 127) return "blocked";
845
+ if (a === 169 && b === 254) return "blocked";
846
+ if (a === 172 && b >= 16 && b <= 31) return "blocked";
847
+ if (a === 192 && b === 0 && c === 0) return "blocked";
848
+ if (a === 192 && b === 0 && c === 2) return "blocked";
849
+ if (a === 192 && b === 168) return "blocked";
850
+ if (a === 198 && (b === 18 || b === 19)) return "blocked";
851
+ if (a === 198 && b === 51 && c === 100) return "blocked";
852
+ if (a === 203 && b === 0 && c === 113) return "blocked";
853
+ if (a === 100 && b >= 64 && b <= 127) return "blocked";
854
+ if (a >= 224) return "blocked";
855
+ return "public";
856
+ }
857
+ function classifyIpv6(bytes) {
858
+ const isZero = bytes.every((byte) => byte === 0);
859
+ if (isZero) return "blocked";
860
+ if (bytes.slice(0, 15).every((byte) => byte === 0) && bytes[15] === 1) return "blocked";
861
+ const v4Mapped = bytes.slice(0, 10).every((byte) => byte === 0) && (bytes[10] === 255 && bytes[11] === 255 || bytes[10] === 0 && bytes[11] === 0);
862
+ if (v4Mapped) {
863
+ return classifyIpv4([bytes[12], bytes[13], bytes[14], bytes[15]]);
864
+ }
865
+ const first = bytes[0];
866
+ if ((first & 254) === 252) return "blocked";
867
+ if (first === 254 && (bytes[1] & 192) === 128) return "blocked";
868
+ if (first === 255) return "blocked";
869
+ if (first === 32 && bytes[1] === 1 && bytes[2] === 13 && bytes[3] === 184) return "blocked";
870
+ return "public";
871
+ }
872
+ function isIpAddress(value) {
873
+ return parseAddress(value) !== void 0;
874
+ }
875
+ function classifyIpAddress(address) {
876
+ const parsed = parseAddress(address);
877
+ if (parsed === void 0) return "blocked";
878
+ if (parsed instanceof import_ipaddr.default.IPv4) return classifyIpv4(parsed.octets);
879
+ const bytes = new Uint8Array(parsed.toByteArray());
880
+ if (parsed.isIPv4MappedAddress()) return classifyIpv4(parsed.toIPv4Address().octets);
881
+ return classifyIpv6(bytes);
882
+ }
883
+
884
+ // ../plugins/src/_runtime/guardedFetch.ts
885
+ var MAX_REDIRECTS = 5;
886
+ var CROSS_ORIGIN_STRIPPED_HEADERS = [
887
+ "authorization",
888
+ "cookie",
889
+ "proxy-authorization"
890
+ // 各家自定义的密钥头没有统一命名,凡是名字里带 key/token/secret 的一律剥掉:
891
+ // 宁可让跨源跳转少带一个无关头,也不能漏带走一个凭证。
892
+ ];
893
+ var REQUEST_BODY_HEADERS = [
894
+ "content-encoding",
895
+ "content-language",
896
+ "content-location",
897
+ "content-type"
898
+ ];
899
+ function looksLikeCredentialHeader(name) {
900
+ return /(?:^|-)(?:api[-_]?key|key|token|secret|auth)(?:$|-)/i.test(name);
901
+ }
902
+ function stripCredentials(headers, sensitiveHeaders) {
903
+ const next = new Headers(headers);
904
+ for (const [name] of headers) {
905
+ if (CROSS_ORIGIN_STRIPPED_HEADERS.includes(name.toLowerCase()) || looksLikeCredentialHeader(name) || sensitiveHeaders.has(name.toLowerCase())) {
906
+ next.delete(name);
907
+ }
908
+ }
909
+ return next;
910
+ }
911
+ var EgressBlockedError = class extends TBError {
912
+ constructor(message) {
913
+ super("invalid_argument", message);
914
+ this.name = "EgressBlockedError";
915
+ }
916
+ };
917
+ function assertPublicHttpUrl(value) {
918
+ let url;
919
+ try {
920
+ url = value instanceof URL ? value : new URL(value);
921
+ } catch {
922
+ throw new EgressBlockedError(`\u51FA\u7AD9\u76EE\u6807\u4E0D\u662F\u5408\u6CD5 URL: ${String(value)}`);
923
+ }
924
+ if (url.protocol !== "https:" && url.protocol !== "http:") {
925
+ throw new EgressBlockedError(`\u51FA\u7AD9\u76EE\u6807\u534F\u8BAE\u4E0D\u88AB\u5141\u8BB8: ${url.protocol}`);
926
+ }
927
+ const hostname = url.hostname.startsWith("[") && url.hostname.endsWith("]") ? url.hostname.slice(1, -1) : url.hostname;
928
+ if (hostname === "") throw new EgressBlockedError("\u51FA\u7AD9\u76EE\u6807\u7F3A\u5C11\u4E3B\u673A\u540D");
929
+ if (isIpAddress(hostname) && classifyIpAddress(hostname) === "blocked") {
930
+ throw new EgressBlockedError("\u51FA\u7AD9\u76EE\u6807\u6307\u5411\u79C1\u6709\u6216\u4FDD\u7559\u5730\u5740");
931
+ }
932
+ return url;
933
+ }
934
+ function createGuardedFetch(options = {}) {
935
+ const crossOriginRedirect = options.crossOriginRedirect ?? "error";
936
+ const maxRedirects = options.maxRedirects ?? MAX_REDIRECTS;
937
+ const sensitiveHeaders = new Set(
938
+ (options.sensitiveHeaders ?? []).map((name) => name.toLowerCase())
939
+ );
940
+ return async function guardedFetch2(input, init) {
941
+ const transport = options.fetch ?? globalThis.fetch;
942
+ const initial = input instanceof Request ? input.url : String(input);
943
+ let url = assertPublicHttpUrl(initial);
944
+ let request = input instanceof Request ? new Request(url, new Request(input, init)) : new Request(url, { ...init, redirect: "manual" });
945
+ for (let hop = 0; ; hop += 1) {
946
+ const response = await transport(new Request(request.clone(), { redirect: "manual" }));
947
+ const location = response.headers.get("location");
948
+ if (response.status < 300 || response.status > 399 || location === null) return response;
949
+ if (hop >= maxRedirects) {
950
+ throw new EgressBlockedError(`\u51FA\u7AD9\u91CD\u5B9A\u5411\u8D85\u8FC7 ${maxRedirects} \u8DF3`);
951
+ }
952
+ const previousOrigin = new URL(request.url).origin;
953
+ url = assertPublicHttpUrl(new URL(location, url));
954
+ const crossesOrigin = url.origin !== previousOrigin;
955
+ if (crossesOrigin && crossOriginRedirect === "error") {
956
+ throw new EgressBlockedError("\u643A\u5E26\u654F\u611F\u4FE1\u606F\u7684\u51FA\u7AD9\u8BF7\u6C42\u4E0D\u5141\u8BB8\u8DE8\u6E90\u91CD\u5B9A\u5411");
957
+ }
958
+ const headers = !crossesOrigin ? request.headers : stripCredentials(request.headers, sensitiveHeaders);
959
+ const downgrade = (response.status === 301 || response.status === 302) && request.method === "POST" || response.status === 303 && request.method !== "GET" && request.method !== "HEAD";
960
+ if (downgrade) {
961
+ const redirectedHeaders = new Headers(headers);
962
+ for (const name of REQUEST_BODY_HEADERS) redirectedHeaders.delete(name);
963
+ request = new Request(url, { method: "GET", headers: redirectedHeaders, redirect: "manual" });
964
+ } else {
965
+ const redirected = new Request(url, request);
966
+ request = crossesOrigin ? new Request(redirected, { headers, redirect: "manual" }) : redirected;
967
+ }
968
+ }
969
+ };
970
+ }
971
+ var guardedFetch = createGuardedFetch();
972
+
973
+ export {
974
+ assertPublicHttpUrl,
975
+ createGuardedFetch,
976
+ guardedFetch
977
+ };