@kya-os/checkpoint-shared 1.7.0 → 1.9.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 (277) hide show
  1. package/CHANGELOG.md +159 -9
  2. package/README.md +24 -7
  3. package/dist/agent-catalog.d.mts +12 -0
  4. package/dist/agent-catalog.d.mts.map +1 -0
  5. package/dist/agent-catalog.d.ts +12 -0
  6. package/dist/agent-catalog.d.ts.map +1 -0
  7. package/dist/agent-catalog.js +105 -0
  8. package/dist/agent-catalog.mjs +105 -0
  9. package/dist/agent-catalog.mjs.map +1 -0
  10. package/dist/beacon-nonce/index.d.mts +1 -0
  11. package/dist/beacon-nonce/index.d.mts.map +1 -1
  12. package/dist/beacon-nonce/index.d.ts +1 -0
  13. package/dist/beacon-nonce/index.d.ts.map +1 -1
  14. package/dist/beacon-nonce/index.js +9 -3
  15. package/dist/beacon-nonce/index.mjs +9 -4
  16. package/dist/beacon-nonce/index.mjs.map +1 -1
  17. package/dist/beacon-types/index.d.mts +41 -1
  18. package/dist/beacon-types/index.d.mts.map +1 -1
  19. package/dist/beacon-types/index.d.ts +41 -1
  20. package/dist/beacon-types/index.d.ts.map +1 -1
  21. package/dist/beacon-types/index.js +153 -4
  22. package/dist/beacon-types/index.mjs +139 -4
  23. package/dist/beacon-types/index.mjs.map +1 -1
  24. package/dist/{browser-posture-BLhw-MON.d.mts → browser-posture-5fPrsxx7.d.mts} +6 -6
  25. package/dist/{browser-posture-BLhw-MON.d.mts.map → browser-posture-5fPrsxx7.d.mts.map} +1 -1
  26. package/dist/{browser-posture-B8YiPa5c.d.ts → browser-posture-CCR1kh5e.d.ts} +6 -6
  27. package/dist/{browser-posture-B8YiPa5c.d.ts.map → browser-posture-CCR1kh5e.d.ts.map} +1 -1
  28. package/dist/browser-posture-cookie.js +1 -1
  29. package/dist/browser-posture-cookie.mjs +1 -1
  30. package/dist/browser-posture-cookie.mjs.map +1 -1
  31. package/dist/browser-posture-proof-verifier-DvsOmFrM.js +202 -0
  32. package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs +180 -0
  33. package/dist/browser-posture-proof-verifier-I0HP2Ics.mjs.map +1 -0
  34. package/dist/browser-posture-proof-verifier.d.mts +25 -0
  35. package/dist/browser-posture-proof-verifier.d.mts.map +1 -0
  36. package/dist/browser-posture-proof-verifier.d.ts +25 -0
  37. package/dist/browser-posture-proof-verifier.d.ts.map +1 -0
  38. package/dist/browser-posture-proof-verifier.js +7 -0
  39. package/dist/browser-posture-proof-verifier.mjs +3 -0
  40. package/dist/browser-posture-proof.d.mts +4 -5
  41. package/dist/browser-posture-proof.d.mts.map +1 -1
  42. package/dist/browser-posture-proof.d.ts +4 -5
  43. package/dist/browser-posture-proof.d.ts.map +1 -1
  44. package/dist/browser-posture-proof.js +10 -79
  45. package/dist/browser-posture-proof.mjs +6 -77
  46. package/dist/browser-posture-proof.mjs.map +1 -1
  47. package/dist/browser-posture.d.mts +1 -1
  48. package/dist/browser-posture.d.ts +1 -1
  49. package/dist/browser-posture.js +6 -5
  50. package/dist/browser-posture.mjs +4 -3
  51. package/dist/browser-posture.mjs.map +1 -1
  52. package/dist/browser.d.mts +25 -286
  53. package/dist/browser.d.mts.map +1 -1
  54. package/dist/browser.d.ts +25 -286
  55. package/dist/browser.d.ts.map +1 -1
  56. package/dist/browser.js +1 -1
  57. package/dist/browser.mjs +1 -1
  58. package/dist/browser.mjs.map +1 -1
  59. package/dist/canonical-signer/index.js +30 -28
  60. package/dist/canonical-signer/index.mjs +31 -1
  61. package/dist/canonical-signer/index.mjs.map +1 -1
  62. package/dist/clearance.d.mts +1 -1
  63. package/dist/clearance.d.ts +1 -1
  64. package/dist/clearance.js +2 -2
  65. package/dist/clearance.mjs +2 -2
  66. package/dist/client-ip-B7w-uHfS.d.mts +55 -0
  67. package/dist/client-ip-B7w-uHfS.d.mts.map +1 -0
  68. package/dist/client-ip-B7w-uHfS.d.ts +55 -0
  69. package/dist/client-ip-B7w-uHfS.d.ts.map +1 -0
  70. package/dist/{client-ip-CW6pRyLf.js → client-ip-B8wFzJ5f.js} +117 -7
  71. package/dist/{client-ip-B2Xeo-GK.mjs → client-ip-DIJyr6px.mjs} +113 -9
  72. package/dist/client-ip-DIJyr6px.mjs.map +1 -0
  73. package/dist/client-ip.d.mts +2 -2
  74. package/dist/client-ip.d.ts +2 -2
  75. package/dist/client-ip.js +3 -2
  76. package/dist/client-ip.mjs +2 -2
  77. package/dist/consent-handoff.d.mts +0 -3
  78. package/dist/consent-handoff.d.mts.map +1 -1
  79. package/dist/consent-handoff.d.ts +0 -3
  80. package/dist/consent-handoff.d.ts.map +1 -1
  81. package/dist/consent-handoff.mjs.map +1 -1
  82. package/dist/default-sign-in-host.d.mts +10 -0
  83. package/dist/default-sign-in-host.d.mts.map +1 -0
  84. package/dist/default-sign-in-host.d.ts +10 -0
  85. package/dist/default-sign-in-host.d.ts.map +1 -0
  86. package/dist/default-sign-in-host.js +72 -0
  87. package/dist/default-sign-in-host.mjs +66 -0
  88. package/dist/default-sign-in-host.mjs.map +1 -0
  89. package/dist/detection-reason-mapping-B9RSkOs8.js +277 -0
  90. package/dist/detection-reason-mapping-BGymWIPl.mjs +249 -0
  91. package/dist/detection-reason-mapping-BGymWIPl.mjs.map +1 -0
  92. package/dist/detection-reason-mapping-CQexNvR7.d.mts +52 -0
  93. package/dist/detection-reason-mapping-CQexNvR7.d.mts.map +1 -0
  94. package/dist/detection-reason-mapping-CQexNvR7.d.ts +52 -0
  95. package/dist/detection-reason-mapping-CQexNvR7.d.ts.map +1 -0
  96. package/dist/engine-enforcing-AYEcgNsb.js +39 -0
  97. package/dist/engine-enforcing-B5eNfCpG.mjs +29 -0
  98. package/dist/engine-enforcing-B5eNfCpG.mjs.map +1 -0
  99. package/dist/engine-enforcing-DiOclGqf.d.mts +11 -0
  100. package/dist/engine-enforcing-DiOclGqf.d.mts.map +1 -0
  101. package/dist/engine-enforcing-DiOclGqf.d.ts +11 -0
  102. package/dist/engine-enforcing-DiOclGqf.d.ts.map +1 -0
  103. package/dist/engine-info.d.mts +2 -0
  104. package/dist/engine-info.d.ts +2 -0
  105. package/dist/engine-info.js +4 -0
  106. package/dist/engine-info.mjs +3 -0
  107. package/dist/errors/index.d.mts +6 -0
  108. package/dist/errors/index.d.mts.map +1 -1
  109. package/dist/errors/index.d.ts +6 -0
  110. package/dist/errors/index.d.ts.map +1 -1
  111. package/dist/errors/index.js +28 -6
  112. package/dist/errors/index.mjs +28 -6
  113. package/dist/errors/index.mjs.map +1 -1
  114. package/dist/{external-B7WI9FyQ.d.ts → external-m3Kmafwj.d.mts} +2 -2
  115. package/dist/{external-B7WI9FyQ.d.mts.map → external-m3Kmafwj.d.mts.map} +1 -1
  116. package/dist/{external-B7WI9FyQ.d.mts → external-m3Kmafwj.d.ts} +2 -2
  117. package/dist/{external-B7WI9FyQ.d.ts.map → external-m3Kmafwj.d.ts.map} +1 -1
  118. package/dist/fetcher-C8qvwdnA.d.ts +44 -0
  119. package/dist/fetcher-C8qvwdnA.d.ts.map +1 -0
  120. package/dist/fetcher-D2vjr7jB.d.mts +44 -0
  121. package/dist/fetcher-D2vjr7jB.d.mts.map +1 -0
  122. package/dist/gateway-client-ip.d.mts +1 -3
  123. package/dist/gateway-client-ip.d.mts.map +1 -1
  124. package/dist/gateway-client-ip.d.ts +1 -3
  125. package/dist/gateway-client-ip.d.ts.map +1 -1
  126. package/dist/gateway-client-ip.js +2 -2
  127. package/dist/gateway-client-ip.mjs +2 -2
  128. package/dist/gateway-client-ip.mjs.map +1 -1
  129. package/dist/host-adapter/index.d.mts +2 -2
  130. package/dist/host-adapter/index.d.ts +2 -2
  131. package/dist/host-adapter/index.js +2 -1
  132. package/dist/host-adapter/index.mjs +2 -2
  133. package/dist/{host-adapter-C-4IxmqM.mjs → host-adapter-BKdQHwbi.mjs} +56 -3
  134. package/dist/{host-adapter-C-4IxmqM.mjs.map → host-adapter-BKdQHwbi.mjs.map} +1 -1
  135. package/dist/{host-adapter-CwW9YB0U.js → host-adapter-bWftXA9T.js} +60 -1
  136. package/dist/index-DnFsmr_o.d.ts +156 -0
  137. package/dist/index-DnFsmr_o.d.ts.map +1 -0
  138. package/dist/index-rvw5Bz-r.d.mts +156 -0
  139. package/dist/index-rvw5Bz-r.d.mts.map +1 -0
  140. package/dist/index.d.mts +6681 -11335
  141. package/dist/index.d.mts.map +1 -1
  142. package/dist/index.d.ts +6681 -11335
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +2322 -6900
  145. package/dist/index.mjs +2236 -6574
  146. package/dist/index.mjs.map +1 -1
  147. package/dist/{kya-http-error-codes-UYb1zpGM.js → kya-http-error-codes-B4rUmUEI.js} +2 -0
  148. package/dist/{kya-http-error-codes-7ewV5RuK.d.ts → kya-http-error-codes-C14E4gi3.d.mts} +2 -1
  149. package/dist/kya-http-error-codes-C14E4gi3.d.mts.map +1 -0
  150. package/dist/{kya-http-error-codes-7ewV5RuK.d.mts → kya-http-error-codes-C14E4gi3.d.ts} +2 -1
  151. package/dist/kya-http-error-codes-C14E4gi3.d.ts.map +1 -0
  152. package/dist/{kya-http-error-codes-C2JiWPsi.mjs → kya-http-error-codes-DSBrxNry.mjs} +3 -1
  153. package/dist/kya-http-error-codes-DSBrxNry.mjs.map +1 -0
  154. package/dist/kya-http.d.mts +3 -3
  155. package/dist/kya-http.d.ts +3 -3
  156. package/dist/kya-http.js +10 -2
  157. package/dist/kya-http.mjs +4 -3
  158. package/dist/mcpi/dashboard-config/index.d.mts.map +1 -1
  159. package/dist/mcpi/dashboard-config/index.d.ts.map +1 -1
  160. package/dist/mcpi/dashboard-config/index.mjs.map +1 -1
  161. package/dist/mcpi/status-list/index.d.mts +72 -0
  162. package/dist/mcpi/status-list/index.d.mts.map +1 -0
  163. package/dist/mcpi/status-list/index.d.ts +72 -0
  164. package/dist/mcpi/status-list/index.d.ts.map +1 -0
  165. package/dist/mcpi/status-list/index.js +703 -0
  166. package/dist/mcpi/status-list/index.mjs +684 -0
  167. package/dist/mcpi/status-list/index.mjs.map +1 -0
  168. package/dist/patterns-Bp40cwh2.d.mts +110 -0
  169. package/dist/patterns-Bp40cwh2.d.mts.map +1 -0
  170. package/dist/patterns-Bp40cwh2.d.ts +110 -0
  171. package/dist/patterns-Bp40cwh2.d.ts.map +1 -0
  172. package/dist/patterns-CiMpbdAF.js +243 -0
  173. package/dist/patterns-D4OAsNQY.mjs +173 -0
  174. package/dist/patterns-D4OAsNQY.mjs.map +1 -0
  175. package/dist/patterns.d.mts +2 -0
  176. package/dist/patterns.d.ts +2 -0
  177. package/dist/patterns.js +15 -0
  178. package/dist/patterns.mjs +3 -0
  179. package/dist/policy/enforcement.d.mts +3 -2
  180. package/dist/policy/enforcement.d.ts +3 -2
  181. package/dist/policy/enforcement.js +8 -2
  182. package/dist/policy/enforcement.mjs +3 -2
  183. package/dist/policy/fetcher.d.mts +2 -0
  184. package/dist/policy/fetcher.d.ts +2 -0
  185. package/dist/policy/fetcher.js +240 -0
  186. package/dist/policy/fetcher.mjs +238 -0
  187. package/dist/policy/fetcher.mjs.map +1 -0
  188. package/dist/policy/schemas.d.mts +3 -0
  189. package/dist/policy/schemas.d.ts +3 -0
  190. package/dist/policy/schemas.js +27 -0
  191. package/dist/policy/schemas.mjs +4 -0
  192. package/dist/{posture-origins-Ba83O0cD.mjs → posture-origins-Ci6k4Zh1.js} +24 -173
  193. package/dist/{posture-origins-CdVOdiMT.js → posture-origins-DGyS4Vuk.mjs} +2 -267
  194. package/dist/posture-origins-DGyS4Vuk.mjs.map +1 -0
  195. package/dist/{project-verification-key-BccT12tQ.js → project-verification-key-B-L3D2nC.js} +1 -1
  196. package/dist/{project-verification-key-66N4edKn.mjs → project-verification-key-CWXdu3-n.mjs} +2 -2
  197. package/dist/{project-verification-key-66N4edKn.mjs.map → project-verification-key-CWXdu3-n.mjs.map} +1 -1
  198. package/dist/provider-registry.d.mts +2 -0
  199. package/dist/provider-registry.d.ts +2 -0
  200. package/dist/provider-registry.js +51 -0
  201. package/dist/provider-registry.mjs +3 -0
  202. package/dist/reason-codes.d.mts +2 -0
  203. package/dist/reason-codes.d.ts +2 -0
  204. package/dist/reason-codes.js +8 -0
  205. package/dist/reason-codes.mjs +3 -0
  206. package/dist/{registered-sid-hUl-bvM5.mjs → registered-sid-26hNxp6t.mjs} +11 -2
  207. package/dist/registered-sid-26hNxp6t.mjs.map +1 -0
  208. package/dist/registered-sid-D6KCaT1E.d.mts +33 -0
  209. package/dist/registered-sid-D6KCaT1E.d.mts.map +1 -0
  210. package/dist/registered-sid-D6KCaT1E.d.ts +33 -0
  211. package/dist/registered-sid-D6KCaT1E.d.ts.map +1 -0
  212. package/dist/{registered-sid-eLCNZvIF.js → registered-sid-DVGTSH0L.js} +15 -0
  213. package/dist/ruleset-hash-Cmv8MSO5.js +34 -0
  214. package/dist/ruleset-hash-IRN5eI9H.d.mts +5 -0
  215. package/dist/ruleset-hash-IRN5eI9H.d.mts.map +1 -0
  216. package/dist/ruleset-hash-IRN5eI9H.d.ts +5 -0
  217. package/dist/ruleset-hash-IRN5eI9H.d.ts.map +1 -0
  218. package/dist/ruleset-hash-QQIaLuPi.mjs +30 -0
  219. package/dist/ruleset-hash-QQIaLuPi.mjs.map +1 -0
  220. package/dist/{schemas-YhagYDx_.js → schemas-BlScS1it.js} +0 -20
  221. package/dist/{index-HaqfPtaL.d.ts → schemas-CGKHzcMV.d.ts} +23 -195
  222. package/dist/schemas-CGKHzcMV.d.ts.map +1 -0
  223. package/dist/schemas-Cm4C4Z5G.js +703 -0
  224. package/dist/schemas-DPIT8usF.mjs +525 -0
  225. package/dist/schemas-DPIT8usF.mjs.map +1 -0
  226. package/dist/{schemas-7qodsG-Z.mjs → schemas-IHAhH3gV.mjs} +2 -16
  227. package/dist/schemas-IHAhH3gV.mjs.map +1 -0
  228. package/dist/{index-B7rTovHa.d.mts → schemas-m-GqyfyO.d.mts} +23 -195
  229. package/dist/schemas-m-GqyfyO.d.mts.map +1 -0
  230. package/dist/{step-up-COlmWJN8.mjs → step-up-BK0oBi11.mjs} +91 -41
  231. package/dist/step-up-BK0oBi11.mjs.map +1 -0
  232. package/dist/{step-up-C2d8C20x.js → step-up-Bp8RAQwv.js} +117 -55
  233. package/dist/{step-up-BjP--hG-.d.mts → step-up-Bz12gYKT.d.mts} +28 -12
  234. package/dist/step-up-Bz12gYKT.d.mts.map +1 -0
  235. package/dist/{step-up-BjP--hG-.d.ts → step-up-Bz12gYKT.d.ts} +28 -12
  236. package/dist/step-up-Bz12gYKT.d.ts.map +1 -0
  237. package/dist/test-fixtures/index.d.mts +4 -4
  238. package/dist/test-fixtures/index.d.mts.map +1 -1
  239. package/dist/test-fixtures/index.d.ts +4 -4
  240. package/dist/test-fixtures/index.d.ts.map +1 -1
  241. package/dist/test-fixtures/index.js +4 -4
  242. package/dist/test-fixtures/index.mjs +4 -4
  243. package/dist/test-fixtures/index.mjs.map +1 -1
  244. package/dist/tool-protection/index.d.mts +12 -0
  245. package/dist/tool-protection/index.d.mts.map +1 -1
  246. package/dist/tool-protection/index.d.ts +12 -0
  247. package/dist/tool-protection/index.d.ts.map +1 -1
  248. package/dist/tool-protection/index.js +46 -0
  249. package/dist/tool-protection/index.mjs +44 -1
  250. package/dist/tool-protection/index.mjs.map +1 -1
  251. package/dist/verification-BAw9N8Pt.js +181 -0
  252. package/dist/verification-Cvvv86TT.mjs +123 -0
  253. package/dist/verification-Cvvv86TT.mjs.map +1 -0
  254. package/fixtures/client-ip-resolution.n01.json +101 -0
  255. package/fixtures/kya-http/error-codes.json +2 -1
  256. package/fixtures/reviewer-grant-revocation.v1.json +53 -81
  257. package/package.json +55 -4
  258. package/dist/client-ip-B2Xeo-GK.mjs.map +0 -1
  259. package/dist/client-ip-DFamiNoz.d.mts +0 -34
  260. package/dist/client-ip-DFamiNoz.d.mts.map +0 -1
  261. package/dist/client-ip-DFamiNoz.d.ts +0 -34
  262. package/dist/client-ip-DFamiNoz.d.ts.map +0 -1
  263. package/dist/index-B7rTovHa.d.mts.map +0 -1
  264. package/dist/index-HaqfPtaL.d.ts.map +0 -1
  265. package/dist/kya-http-error-codes-7ewV5RuK.d.mts.map +0 -1
  266. package/dist/kya-http-error-codes-7ewV5RuK.d.ts.map +0 -1
  267. package/dist/kya-http-error-codes-C2JiWPsi.mjs.map +0 -1
  268. package/dist/posture-origins-Ba83O0cD.mjs.map +0 -1
  269. package/dist/registered-sid-D3g-gZQF.d.mts +0 -11
  270. package/dist/registered-sid-D3g-gZQF.d.mts.map +0 -1
  271. package/dist/registered-sid-D3g-gZQF.d.ts +0 -11
  272. package/dist/registered-sid-D3g-gZQF.d.ts.map +0 -1
  273. package/dist/registered-sid-hUl-bvM5.mjs.map +0 -1
  274. package/dist/schemas-7qodsG-Z.mjs.map +0 -1
  275. package/dist/step-up-BjP--hG-.d.mts.map +0 -1
  276. package/dist/step-up-BjP--hG-.d.ts.map +0 -1
  277. package/dist/step-up-COlmWJN8.mjs.map +0 -1
@@ -133,6 +133,106 @@ function normalizeClientIp(raw) {
133
133
  }
134
134
  return null;
135
135
  }
136
+ function getObservedHeader(headers, name) {
137
+ if ("get" in headers && typeof headers.get === "function") return headers.get(name) ?? void 0;
138
+ const matches = Object.entries(headers).filter(([key, value]) => key.toLowerCase() === name && value !== void 0);
139
+ if (matches.length === 0) return void 0;
140
+ if (matches.length !== 1) return "";
141
+ const value = matches[0][1];
142
+ return typeof value === "string" ? value : value.length === 1 ? value[0] : "";
143
+ }
144
+ function singleAddress(raw) {
145
+ const tokens = boundedTokens(raw);
146
+ return tokens?.length === 1 ? normalizeToken(tokens[0]) : null;
147
+ }
148
+ function unavailable(reason) {
149
+ return {
150
+ ip: null,
151
+ observedClientAddress: null,
152
+ source: "none",
153
+ trusted: false,
154
+ status: "unavailable",
155
+ reason
156
+ };
157
+ }
158
+ function observed(ip, source, reason) {
159
+ return {
160
+ ip,
161
+ observedClientAddress: ip,
162
+ source,
163
+ trusted: true,
164
+ status: "observed",
165
+ reason
166
+ };
167
+ }
168
+ function authenticatedPeer(input, policy) {
169
+ const peer = singleAddress(input.directAddress);
170
+ if (!peer || !policy.isTrustedPeer) return false;
171
+ try {
172
+ return policy.isTrustedPeer(peer) === true;
173
+ } catch {
174
+ return false;
175
+ }
176
+ }
177
+ function resolveVercel(input) {
178
+ if (input.vercelRuntime !== true) return unavailable("untrusted-peer");
179
+ const platformHeader = getObservedHeader(input.headers, "x-vercel-forwarded-for");
180
+ const ip = singleAddress(platformHeader ?? getObservedHeader(input.headers, "x-forwarded-for"));
181
+ return ip ? observed(ip, platformHeader === void 0 ? "x-forwarded-for" : "x-vercel-forwarded-for", "vercel-runtime") : unavailable("invalid-chain");
182
+ }
183
+ function ipv4Octets(ip) {
184
+ const ipv4 = parseIpv4(ip);
185
+ if (ipv4) return ipv4;
186
+ const groups = parseIpv6(ip);
187
+ return groups.slice(0, 5).every((group) => group === 0) && groups[5] === 65535 ? [
188
+ groups[6] >> 8,
189
+ groups[6] & 255,
190
+ groups[7] >> 8,
191
+ groups[7] & 255
192
+ ] : null;
193
+ }
194
+ function resolveCloudflare(input, policy) {
195
+ if (!authenticatedPeer(input, policy)) return unavailable("untrusted-peer");
196
+ const ip = singleAddress(getObservedHeader(input.headers, "cf-connecting-ip"));
197
+ if (!ip) return unavailable("invalid-chain");
198
+ if (getObservedHeader(input.headers, "cf-worker") !== void 0 || ip === "2a06:98c0:3600::103") return unavailable("unsupported-worker");
199
+ const ipv4 = ipv4Octets(ip);
200
+ if (ipv4 && ipv4[0] >= 240) {
201
+ const native = singleAddress(getObservedHeader(input.headers, "cf-connecting-ipv6"));
202
+ if (policy.pseudoIpv4 !== "overwrite" || !native || ipv4Octets(native)) return unavailable("unsupported-synthetic");
203
+ if (native === "2a06:98c0:3600::103") return unavailable("unsupported-worker");
204
+ return observed(native, "cf-connecting-ipv6", "authenticated-proxy");
205
+ }
206
+ return observed(ip, "cf-connecting-ip", "authenticated-proxy");
207
+ }
208
+ function resolveTrustedProxy(input, policy) {
209
+ if (!authenticatedPeer(input, policy)) return unavailable("untrusted-peer");
210
+ const tokens = boundedTokens(getObservedHeader(input.headers, "x-forwarded-for"));
211
+ const hops = policy.trustedHops;
212
+ if (!tokens || !Number.isInteger(hops) || hops < 0 || tokens.length !== hops + 1) return unavailable("invalid-chain");
213
+ const parsed = tokens.map(normalizeToken);
214
+ if (parsed.some((token) => token === null)) return unavailable("invalid-chain");
215
+ return observed(parsed[parsed.length - hops - 1], "x-forwarded-for", "authenticated-proxy");
216
+ }
217
+ /** Resolve the observed client address only through an authenticated deployment boundary. */
218
+ function resolveObservedClientAddress(input) {
219
+ if (input.explicitAddressTrusted === true) {
220
+ const explicit = singleAddress(input.explicitAddress);
221
+ if (explicit) return observed(explicit, "explicit", "authenticated-explicit");
222
+ }
223
+ switch (input.policy.platform) {
224
+ case "vercel": return resolveVercel(input);
225
+ case "cloudflare": return resolveCloudflare(input, input.policy);
226
+ case "trusted-proxy": return resolveTrustedProxy(input, input.policy);
227
+ default: return unavailable("untrusted-peer");
228
+ case "direct": {
229
+ const socket = singleAddress(input.directAddress);
230
+ if (socket) return observed(socket, "socket", "direct-peer");
231
+ const framework = singleAddress(input.frameworkAddress);
232
+ return framework ? observed(framework, "framework", "direct-peer") : unavailable("missing-address");
233
+ }
234
+ }
235
+ }
136
236
  function getHeader(headers, name) {
137
237
  if ("get" in headers && typeof headers.get === "function") return headers.get(name) ?? void 0;
138
238
  const wanted = name.toLowerCase();
@@ -155,7 +255,7 @@ function resolveExplicit(input) {
155
255
  if (input.explicitAddressTrusted !== true) return null;
156
256
  return result(normalizeClientIp(input.explicitAddress), "explicit", true);
157
257
  }
158
- function resolveVercel(input) {
258
+ function resolveLegacyVercel(input) {
159
259
  const platform = result(normalizeClientIp(getHeader(input.headers, "x-vercel-forwarded-for")), "x-vercel-forwarded-for", true);
160
260
  if (platform) return platform;
161
261
  const overwrittenXff = result(normalizeClientIp(getHeader(input.headers, "x-forwarded-for")), "x-forwarded-for", true);
@@ -168,7 +268,7 @@ function resolveVercel(input) {
168
268
  trusted: false
169
269
  };
170
270
  }
171
- function resolveCloudflare(input) {
271
+ function resolveLegacyCloudflare(input) {
172
272
  const cloudflare = result(normalizeClientIp(getHeader(input.headers, "cf-connecting-ip")), "cf-connecting-ip", true);
173
273
  if (cloudflare) return cloudflare;
174
274
  return resolveAddress(input.directAddress, "socket") ?? resolveAddress(input.frameworkAddress, "framework") ?? result(normalizeClientIp(getHeader(input.headers, "x-forwarded-for")), "x-forwarded-for", false) ?? result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false) ?? {
@@ -177,7 +277,7 @@ function resolveCloudflare(input) {
177
277
  trusted: false
178
278
  };
179
279
  }
180
- function resolveTrustedProxy(input, trustedHops) {
280
+ function resolveLegacyTrustedProxy(input, trustedHops) {
181
281
  const tokens = boundedTokens(getHeader(input.headers, "x-forwarded-for"));
182
282
  if (tokens && Number.isInteger(trustedHops) && trustedHops >= 0 && tokens.length > trustedHops) {
183
283
  const parsed = tokens.map(normalizeToken);
@@ -194,14 +294,18 @@ function resolveTrustedProxy(input, trustedHops) {
194
294
  trusted: false
195
295
  };
196
296
  }
197
- /** Resolve a client IP using an explicit deployment trust profile. */
297
+ /**
298
+ * Legacy platform-assumed resolver retained for existing gateway and runtime integrations.
299
+ * This API does not authenticate a nearest peer. New ingress integrations must use
300
+ * resolveObservedClientAddress and qualify their actual deployment boundary.
301
+ */
198
302
  function resolveClientIp(input) {
199
303
  const explicit = resolveExplicit(input);
200
304
  if (explicit) return explicit;
201
305
  switch (input.policy.platform) {
202
- case "vercel": return resolveVercel(input);
203
- case "cloudflare": return resolveCloudflare(input);
204
- case "trusted-proxy": return resolveTrustedProxy(input, input.policy.trustedHops);
306
+ case "vercel": return resolveLegacyVercel(input);
307
+ case "cloudflare": return resolveLegacyCloudflare(input);
308
+ case "trusted-proxy": return resolveLegacyTrustedProxy(input, input.policy.trustedHops);
205
309
  case "direct": return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? {
206
310
  ip: null,
207
311
  source: "none",
@@ -211,5 +315,5 @@ function resolveClientIp(input) {
211
315
  }
212
316
 
213
317
  //#endregion
214
- export { resolveClientIp as i, normalizeClientIp as n, parseIpv6 as r, compressIpv6 as t };
215
- //# sourceMappingURL=client-ip-B2Xeo-GK.mjs.map
318
+ export { resolveObservedClientAddress as a, resolveClientIp as i, normalizeClientIp as n, parseIpv6 as r, compressIpv6 as t };
319
+ //# sourceMappingURL=client-ip-DIJyr6px.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-ip-DIJyr6px.mjs","names":[],"sources":["../src/utils/client-ip.ts"],"sourcesContent":["/**\n * Runtime-agnostic client-IP normalization and trust resolution.\n *\n * Header presence is not proof of provenance. Callers must select the\n * deployment profile that describes which infrastructure has already\n * authenticated a value before using the result for security decisions.\n */\n\nexport type ClientIpSource =\n | 'explicit'\n | 'cf-connecting-ip'\n | 'cf-connecting-ipv6'\n | 'x-vercel-forwarded-for'\n | 'x-forwarded-for'\n | 'x-real-ip'\n | 'framework'\n | 'socket'\n | 'none';\n\n/** Legacy platform-assumed result. Use ObservedClientAddressResolution for new ingress integrations. */\nexport interface ClientIpResolution {\n ip: string | null;\n source: ClientIpSource;\n trusted: boolean;\n}\n\nexport type ObservedClientAddressResolution =\n | {\n /** Compatibility alias for observedClientAddress. */\n ip: string;\n observedClientAddress: string;\n source: Exclude<ClientIpSource, 'none'>;\n trusted: true;\n status: 'observed';\n reason: 'direct-peer' | 'authenticated-explicit' | 'vercel-runtime' | 'authenticated-proxy';\n }\n | {\n ip: null;\n observedClientAddress: null;\n source: 'none';\n trusted: false;\n status: 'unavailable';\n reason:\n | 'missing-address'\n | 'untrusted-peer'\n | 'invalid-chain'\n | 'unsupported-synthetic'\n | 'unsupported-worker';\n };\n\ninterface PeerTrust {\n /** Check the transport peer against the deployment's proxy allowlist, never a request header. */\n isTrustedPeer?: (peerAddress: string) => boolean;\n}\n\nexport type ClientIpTrustPolicy =\n | { platform: 'vercel' }\n | ({ platform: 'cloudflare'; pseudoIpv4?: 'off' | 'add-header' | 'overwrite' } & PeerTrust)\n | ({ platform: 'trusted-proxy'; trustedHops: number } & PeerTrust)\n | { platform: 'direct' };\n\nexport type ClientIpHeaderValue = string | readonly string[] | undefined;\nexport type ClientIpHeaders = Headers | Record<string, ClientIpHeaderValue>;\n\nexport interface ResolveClientIpInput {\n headers: ClientIpHeaders;\n directAddress?: string | null;\n frameworkAddress?: string | null;\n explicitAddress?: string | null;\n /** True only after the caller has authenticated the explicit value. */\n explicitAddressTrusted?: boolean;\n vercelRuntime?: boolean;\n policy: ClientIpTrustPolicy;\n}\n\nconst MAX_INPUT_LENGTH = 4096;\nconst MAX_TOKEN_LENGTH = 128;\nconst MAX_FORWARDED_HOPS = 32;\n\nfunction hasControlCharacter(value: string): boolean {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1f || code === 0x7f) return true;\n }\n return false;\n}\n\nfunction parsePort(value: string): boolean {\n return /^(?:0|[1-9]\\d{0,4})$/.test(value) && Number(value) <= 65535;\n}\n\nfunction parseIpv4(value: string): number[] | null {\n const parts = value.split('.');\n if (parts.length !== 4) return null;\n\n const octets: number[] = [];\n for (const part of parts) {\n if (!/^\\d{1,3}$/.test(part)) return null;\n const octet = Number(part);\n if (octet > 255) return null;\n octets.push(octet);\n }\n return octets;\n}\n\nfunction parseHexGroup(value: string): number | null {\n if (!/^[0-9a-fA-F]{1,4}$/.test(value)) return null;\n return Number.parseInt(value, 16);\n}\n\n/** Parses a bare IPv6 address into its 8 groups (`::` expanded). Exported for reuse by anything that needs to mask/truncate an address (see `anonymize-ip.ts`), not just resolve one. */\nexport function parseIpv6(value: string): number[] | null {\n if (!value || value.includes('%') || hasControlCharacter(value)) return null;\n\n let address = value;\n if (address.includes('.')) {\n const lastColon = address.lastIndexOf(':');\n if (lastColon < 0) return null;\n const ipv4 = parseIpv4(address.slice(lastColon + 1));\n if (!ipv4) return null;\n const first = (ipv4[0]! << 8) | ipv4[1]!;\n const second = (ipv4[2]! << 8) | ipv4[3]!;\n address = `${address.slice(0, lastColon + 1)}${first.toString(16)}:${second.toString(16)}`;\n }\n\n const doubleColon = address.indexOf('::');\n if (doubleColon !== address.lastIndexOf('::')) return null;\n\n const parseGroups = (part: string): number[] | null => {\n if (!part) return [];\n const groups = part.split(':');\n const parsed: number[] = [];\n for (const group of groups) {\n const number = parseHexGroup(group);\n if (number === null) return null;\n parsed.push(number);\n }\n return parsed;\n };\n\n if (doubleColon >= 0) {\n const head = parseGroups(address.slice(0, doubleColon));\n const tail = parseGroups(address.slice(doubleColon + 2));\n if (!head || !tail) return null;\n const missing = 8 - head.length - tail.length;\n if (missing < 1) return null;\n return [...head, ...Array<number>(missing).fill(0), ...tail];\n }\n\n const groups = parseGroups(address);\n return groups?.length === 8 ? groups : null;\n}\n\n/** RFC 5952 canonical `::` compression for 8 IPv6 groups. Exported alongside `parseIpv6`. */\nexport function compressIpv6(groups: number[]): string {\n const rendered = groups.map((group) => group.toString(16));\n let bestStart = -1;\n let bestLength = 1;\n let runStart = -1;\n\n for (let index = 0; index <= groups.length; index += 1) {\n if (index < groups.length && groups[index] === 0) {\n if (runStart < 0) runStart = index;\n continue;\n }\n if (runStart >= 0) {\n const runLength = index - runStart;\n if (runLength > bestLength) {\n bestStart = runStart;\n bestLength = runLength;\n }\n runStart = -1;\n }\n }\n\n if (bestStart < 0) return rendered.join(':');\n const before = rendered.slice(0, bestStart).join(':');\n const after = rendered.slice(bestStart + bestLength).join(':');\n if (!before && !after) return '::';\n if (!before) return `::${after}`;\n if (!after) return `${before}::`;\n return `${before}::${after}`;\n}\n\nfunction normalizeToken(rawToken: string): string | null {\n const token = rawToken.trim();\n if (!token || token.length > MAX_TOKEN_LENGTH || hasControlCharacter(token)) return null;\n\n let address = token;\n if (token.startsWith('[')) {\n const closing = token.indexOf(']');\n if (closing <= 1) return null;\n const suffix = token.slice(closing + 1);\n if (suffix && (!suffix.startsWith(':') || !parsePort(suffix.slice(1)))) return null;\n address = token.slice(1, closing);\n } else if ((token.match(/:/g) ?? []).length === 1 && token.includes('.')) {\n const colon = token.indexOf(':');\n if (!parsePort(token.slice(colon + 1))) return null;\n address = token.slice(0, colon);\n }\n\n const ipv4 = parseIpv4(address);\n if (ipv4) return ipv4.join('.');\n\n const ipv6 = parseIpv6(address);\n return ipv6 ? compressIpv6(ipv6) : null;\n}\n\nfunction boundedTokens(raw: string | null | undefined): string[] | null {\n if (raw == null || !raw || raw.length > MAX_INPUT_LENGTH || hasControlCharacter(raw)) return null;\n const tokens = raw.split(',');\n if (tokens.length > MAX_FORWARDED_HOPS) return null;\n return tokens;\n}\n\n/** Normalize the first valid address in a bounded header value. */\nexport function normalizeClientIp(raw: string | null | undefined): string | null {\n const tokens = boundedTokens(raw);\n if (!tokens) return null;\n for (const token of tokens) {\n const normalized = normalizeToken(token);\n if (normalized) return normalized;\n }\n return null;\n}\n\nfunction getObservedHeader(headers: ClientIpHeaders, name: string): string | undefined {\n if ('get' in headers && typeof headers.get === 'function') {\n return headers.get(name) ?? undefined;\n }\n\n const matches = Object.entries(headers).filter(\n ([key, value]) => key.toLowerCase() === name && value !== undefined\n );\n if (matches.length === 0) return undefined;\n if (matches.length !== 1) return '';\n const value = matches[0]![1] as string | readonly string[];\n return typeof value === 'string' ? value : value.length === 1 ? value[0] : '';\n}\n\nfunction singleAddress(raw: string | null | undefined): string | null {\n const tokens = boundedTokens(raw);\n return tokens?.length === 1 ? normalizeToken(tokens[0]!) : null;\n}\n\nfunction unavailable(\n reason: Extract<ObservedClientAddressResolution, { trusted: false }>['reason']\n): ObservedClientAddressResolution {\n return {\n ip: null,\n observedClientAddress: null,\n source: 'none',\n trusted: false,\n status: 'unavailable',\n reason,\n };\n}\n\nfunction observed(\n ip: string,\n source: Exclude<ClientIpSource, 'none'>,\n reason: Extract<ObservedClientAddressResolution, { trusted: true }>['reason']\n): ObservedClientAddressResolution {\n return { ip, observedClientAddress: ip, source, trusted: true, status: 'observed', reason };\n}\n\nfunction authenticatedPeer(input: ResolveClientIpInput, policy: PeerTrust): boolean {\n const peer = singleAddress(input.directAddress);\n if (!peer || !policy.isTrustedPeer) return false;\n try {\n return policy.isTrustedPeer(peer) === true;\n } catch {\n return false;\n }\n}\n\nfunction resolveVercel(input: ResolveClientIpInput): ObservedClientAddressResolution {\n // Vercel overwrites these values before invoking the managed runtime.\n if (input.vercelRuntime !== true) return unavailable('untrusted-peer');\n const platformHeader = getObservedHeader(input.headers, 'x-vercel-forwarded-for');\n const raw = platformHeader ?? getObservedHeader(input.headers, 'x-forwarded-for');\n const ip = singleAddress(raw);\n return ip\n ? observed(\n ip,\n platformHeader === undefined ? 'x-forwarded-for' : 'x-vercel-forwarded-for',\n 'vercel-runtime'\n )\n : unavailable('invalid-chain');\n}\n\nfunction ipv4Octets(ip: string): number[] | null {\n const ipv4 = parseIpv4(ip);\n if (ipv4) return ipv4;\n const groups = parseIpv6(ip)!;\n return groups.slice(0, 5).every((group) => group === 0) && groups[5] === 0xffff\n ? [groups[6]! >> 8, groups[6]! & 255, groups[7]! >> 8, groups[7]! & 255]\n : null;\n}\n\nfunction resolveCloudflare(\n input: ResolveClientIpInput,\n policy: Extract<ClientIpTrustPolicy, { platform: 'cloudflare' }>\n): ObservedClientAddressResolution {\n if (!authenticatedPeer(input, policy)) return unavailable('untrusted-peer');\n const ip = singleAddress(getObservedHeader(input.headers, 'cf-connecting-ip'));\n if (!ip) return unavailable('invalid-chain');\n // Worker subrequests can replace the visitor address. They need their own authenticated binding.\n if (getObservedHeader(input.headers, 'cf-worker') !== undefined || ip === '2a06:98c0:3600::103')\n return unavailable('unsupported-worker');\n const ipv4 = ipv4Octets(ip);\n if (ipv4 && ipv4[0]! >= 240) {\n const native = singleAddress(getObservedHeader(input.headers, 'cf-connecting-ipv6'));\n if (policy.pseudoIpv4 !== 'overwrite' || !native || ipv4Octets(native))\n return unavailable('unsupported-synthetic');\n if (native === '2a06:98c0:3600::103') return unavailable('unsupported-worker');\n return observed(native, 'cf-connecting-ipv6', 'authenticated-proxy');\n }\n return observed(ip, 'cf-connecting-ip', 'authenticated-proxy');\n}\n\nfunction resolveTrustedProxy(\n input: ResolveClientIpInput,\n policy: Extract<ClientIpTrustPolicy, { platform: 'trusted-proxy' }>\n): ObservedClientAddressResolution {\n if (!authenticatedPeer(input, policy)) return unavailable('untrusted-peer');\n const tokens = boundedTokens(getObservedHeader(input.headers, 'x-forwarded-for'));\n const hops = policy.trustedHops;\n // trustedHops counts addresses to the right of the client, excluding the socket peer.\n if (!tokens || !Number.isInteger(hops) || hops < 0 || tokens.length !== hops + 1)\n return unavailable('invalid-chain');\n const parsed = tokens.map(normalizeToken);\n if (parsed.some((token) => token === null)) return unavailable('invalid-chain');\n return observed(parsed[parsed.length - hops - 1]!, 'x-forwarded-for', 'authenticated-proxy');\n}\n\n/** Resolve the observed client address only through an authenticated deployment boundary. */\nexport function resolveObservedClientAddress(\n input: ResolveClientIpInput\n): ObservedClientAddressResolution {\n if (input.explicitAddressTrusted === true) {\n const explicit = singleAddress(input.explicitAddress);\n if (explicit) return observed(explicit, 'explicit', 'authenticated-explicit');\n }\n switch (input.policy.platform) {\n case 'vercel':\n return resolveVercel(input);\n case 'cloudflare':\n return resolveCloudflare(input, input.policy);\n case 'trusted-proxy':\n return resolveTrustedProxy(input, input.policy);\n default:\n return unavailable('untrusted-peer');\n case 'direct': {\n const socket = singleAddress(input.directAddress);\n if (socket) return observed(socket, 'socket', 'direct-peer');\n const framework = singleAddress(input.frameworkAddress);\n return framework\n ? observed(framework, 'framework', 'direct-peer')\n : unavailable('missing-address');\n }\n }\n}\n\nfunction getHeader(headers: ClientIpHeaders, name: string): string | undefined {\n if ('get' in headers && typeof headers.get === 'function') {\n return headers.get(name) ?? undefined;\n }\n\n const wanted = name.toLowerCase();\n for (const [key, value] of Object.entries(headers)) {\n if (key.toLowerCase() !== wanted || value === undefined) continue;\n return Array.isArray(value) ? value.join(',') : value;\n }\n return undefined;\n}\n\nfunction result(\n ip: string | null,\n source: Exclude<ClientIpSource, 'none'>,\n trusted: boolean\n): ClientIpResolution | null {\n return ip ? { ip, source, trusted } : null;\n}\n\nfunction resolveAddress(\n raw: string | null | undefined,\n source: 'framework' | 'socket'\n): ClientIpResolution | null {\n return result(normalizeClientIp(raw), source, true);\n}\n\nfunction resolveExplicit(input: ResolveClientIpInput): ClientIpResolution | null {\n if (input.explicitAddressTrusted !== true) return null;\n return result(normalizeClientIp(input.explicitAddress), 'explicit', true);\n}\n\nfunction resolveLegacyVercel(input: ResolveClientIpInput): ClientIpResolution {\n const platform = result(\n normalizeClientIp(getHeader(input.headers, 'x-vercel-forwarded-for')),\n 'x-vercel-forwarded-for',\n true\n );\n if (platform) return platform;\n\n const overwrittenXff = result(\n normalizeClientIp(getHeader(input.headers, 'x-forwarded-for')),\n 'x-forwarded-for',\n true\n );\n if (overwrittenXff) return overwrittenXff;\n\n const realIp = result(\n normalizeClientIp(getHeader(input.headers, 'x-real-ip')),\n 'x-real-ip',\n false\n );\n if (realIp) return realIp;\n\n return (\n resolveAddress(input.frameworkAddress, 'framework') ??\n resolveAddress(input.directAddress, 'socket') ?? { ip: null, source: 'none', trusted: false }\n );\n}\n\nfunction resolveLegacyCloudflare(input: ResolveClientIpInput): ClientIpResolution {\n const cloudflare = result(\n normalizeClientIp(getHeader(input.headers, 'cf-connecting-ip')),\n 'cf-connecting-ip',\n true\n );\n if (cloudflare) return cloudflare;\n\n return (\n resolveAddress(input.directAddress, 'socket') ??\n resolveAddress(input.frameworkAddress, 'framework') ??\n result(\n normalizeClientIp(getHeader(input.headers, 'x-forwarded-for')),\n 'x-forwarded-for',\n false\n ) ??\n result(normalizeClientIp(getHeader(input.headers, 'x-real-ip')), 'x-real-ip', false) ?? {\n ip: null,\n source: 'none',\n trusted: false,\n }\n );\n}\n\nfunction resolveLegacyTrustedProxy(\n input: ResolveClientIpInput,\n trustedHops: number\n): ClientIpResolution {\n const raw = getHeader(input.headers, 'x-forwarded-for');\n const tokens = boundedTokens(raw);\n if (tokens && Number.isInteger(trustedHops) && trustedHops >= 0 && tokens.length > trustedHops) {\n const parsed = tokens.map(normalizeToken);\n const selectedIndex = tokens.length - trustedHops - 1;\n const selected = parsed[selectedIndex];\n // Parse every token before selecting one. Otherwise an invalid token could\n // silently move the trusted boundary toward an attacker-controlled value.\n if (selected && parsed.every((token) => token !== null)) {\n return { ip: selected, source: 'x-forwarded-for', trusted: true };\n }\n }\n\n return (\n resolveAddress(input.frameworkAddress, 'framework') ??\n resolveAddress(input.directAddress, 'socket') ??\n result(normalizeClientIp(getHeader(input.headers, 'x-real-ip')), 'x-real-ip', false) ?? {\n ip: null,\n source: 'none',\n trusted: false,\n }\n );\n}\n\n/**\n * Legacy platform-assumed resolver retained for existing gateway and runtime integrations.\n * This API does not authenticate a nearest peer. New ingress integrations must use\n * resolveObservedClientAddress and qualify their actual deployment boundary.\n */\nexport function resolveClientIp(input: ResolveClientIpInput): ClientIpResolution {\n const explicit = resolveExplicit(input);\n if (explicit) return explicit;\n\n switch (input.policy.platform) {\n case 'vercel':\n return resolveLegacyVercel(input);\n case 'cloudflare':\n return resolveLegacyCloudflare(input);\n case 'trusted-proxy':\n return resolveLegacyTrustedProxy(input, input.policy.trustedHops);\n case 'direct':\n return (\n resolveAddress(input.frameworkAddress, 'framework') ??\n resolveAddress(input.directAddress, 'socket') ?? {\n ip: null,\n source: 'none',\n trusted: false,\n }\n );\n }\n}\n"],"mappings":";AA2EA,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,OAAwB;CACnD,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM,WAAW,CAAC;EAC/B,IAAI,QAAQ,MAAQ,SAAS,KAAM,OAAO;CAC5C;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,uBAAuB,KAAK,KAAK,KAAK,OAAO,KAAK,KAAK;AAChE;AAEA,SAAS,UAAU,OA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W,OADK,OAAO,SAAS,cAAc;EAIpD,IAAI,YAAY,OAAO,OAAO,UAAU,UAAU,IAAI,GACpD,OAAO;GAAE,IAAI;GAAU,QAAQ;GAAmB,SAAS;EAAK;CAEpE;CAEA,OACE,eAAe,MAAM,kBAAkB,WAAW,KAClD,eAAe,MAAM,eAAe,QAAQ,KAC5C,OAAO,kBAAkB,UAAU,MAAM,SAAS,WAAW,CAAC,GAAG,aAAa,KAAK,KAAK;EACtF,IAAI;EACJ,QAAQ;EACR,SAAS;CACX;AAEJ;;;;;;AAOA,SAAgB,gBAAgB,OAAiD;CAC/E,MAAM,WAAW,gBAAgB,KAAK;CACtC,IAAI,UAAU,OAAO;CAErB,QAAQ,MAAM,OAAO,UAArB;EACE,KAAK,UACH,OAAO,oBAAoB,KAAK;EAClC,KAAK,cACH,OAAO,wBAAwB,KAAK;EACtC,KAAK,iBACH,OAAO,0BAA0B,OAAO,MAAM,OAAO,WAAW;EAClE,KAAK,UACH,OACE,eAAe,MAAM,kBAAkB,WAAW,KAClD,eAAe,MAAM,eAAe,QAAQ,KAAK;GAC/C,IAAI;GACJ,QAAQ;GACR,SAAS;EACX;CAEN;AACF"}
@@ -1,2 +1,2 @@
1
- import { a as ClientIpTrustPolicy, c as normalizeClientIp, i as ClientIpSource, l as parseIpv6, n as ClientIpHeaders, o as ResolveClientIpInput, r as ClientIpResolution, s as compressIpv6, t as ClientIpHeaderValue, u as resolveClientIp } from "./client-ip-DFamiNoz.mjs";
2
- export { ClientIpHeaderValue, ClientIpHeaders, ClientIpResolution, ClientIpSource, ClientIpTrustPolicy, ResolveClientIpInput, compressIpv6, normalizeClientIp, parseIpv6, resolveClientIp };
1
+ import { a as ClientIpTrustPolicy, c as compressIpv6, d as resolveClientIp, f as resolveObservedClientAddress, i as ClientIpSource, l as normalizeClientIp, n as ClientIpHeaders, o as ObservedClientAddressResolution, r as ClientIpResolution, s as ResolveClientIpInput, t as ClientIpHeaderValue, u as parseIpv6 } from "./client-ip-B7w-uHfS.mjs";
2
+ export { ClientIpHeaderValue, ClientIpHeaders, ClientIpResolution, ClientIpSource, ClientIpTrustPolicy, ObservedClientAddressResolution, ResolveClientIpInput, compressIpv6, normalizeClientIp, parseIpv6, resolveClientIp, resolveObservedClientAddress };
@@ -1,2 +1,2 @@
1
- import { a as ClientIpTrustPolicy, c as normalizeClientIp, i as ClientIpSource, l as parseIpv6, n as ClientIpHeaders, o as ResolveClientIpInput, r as ClientIpResolution, s as compressIpv6, t as ClientIpHeaderValue, u as resolveClientIp } from "./client-ip-DFamiNoz.js";
2
- export { ClientIpHeaderValue, ClientIpHeaders, ClientIpResolution, ClientIpSource, ClientIpTrustPolicy, ResolveClientIpInput, compressIpv6, normalizeClientIp, parseIpv6, resolveClientIp };
1
+ import { a as ClientIpTrustPolicy, c as compressIpv6, d as resolveClientIp, f as resolveObservedClientAddress, i as ClientIpSource, l as normalizeClientIp, n as ClientIpHeaders, o as ObservedClientAddressResolution, r as ClientIpResolution, s as ResolveClientIpInput, t as ClientIpHeaderValue, u as parseIpv6 } from "./client-ip-B7w-uHfS.js";
2
+ export { ClientIpHeaderValue, ClientIpHeaders, ClientIpResolution, ClientIpSource, ClientIpTrustPolicy, ObservedClientAddressResolution, ResolveClientIpInput, compressIpv6, normalizeClientIp, parseIpv6, resolveClientIp, resolveObservedClientAddress };
package/dist/client-ip.js CHANGED
@@ -1,7 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_client_ip = require('./client-ip-CW6pRyLf.js');
2
+ const require_client_ip = require('./client-ip-B8wFzJ5f.js');
3
3
 
4
4
  exports.compressIpv6 = require_client_ip.compressIpv6;
5
5
  exports.normalizeClientIp = require_client_ip.normalizeClientIp;
6
6
  exports.parseIpv6 = require_client_ip.parseIpv6;
7
- exports.resolveClientIp = require_client_ip.resolveClientIp;
7
+ exports.resolveClientIp = require_client_ip.resolveClientIp;
8
+ exports.resolveObservedClientAddress = require_client_ip.resolveObservedClientAddress;
@@ -1,3 +1,3 @@
1
- import { i as resolveClientIp, n as normalizeClientIp, r as parseIpv6, t as compressIpv6 } from "./client-ip-B2Xeo-GK.mjs";
1
+ import { a as resolveObservedClientAddress, i as resolveClientIp, n as normalizeClientIp, r as parseIpv6, t as compressIpv6 } from "./client-ip-DIJyr6px.mjs";
2
2
 
3
- export { compressIpv6, normalizeClientIp, parseIpv6, resolveClientIp };
3
+ export { compressIpv6, normalizeClientIp, parseIpv6, resolveClientIp, resolveObservedClientAddress };
@@ -3,11 +3,8 @@ import { z } from "zod";
3
3
  export declare const CONSENT_HANDOFF_SOURCES: readonly ["module", "probe"];
4
4
  export type ConsentHandoffSource = (typeof CONSENT_HANDOFF_SOURCES)[number];
5
5
  export declare const CONSENT_HANDOFF_REPORT_OUTCOMES: readonly ["registered", "registration_failed", "not_configured"];
6
- export type ConsentHandoffReportOutcome = (typeof CONSENT_HANDOFF_REPORT_OUTCOMES)[number];
7
6
  export declare const CONSENT_HANDOFF_MODULE_REASONS: readonly ["http_401", "http_403", "http_404", "http_4xx", "http_5xx", "http_other", "timeout", "network_error", "invalid_response", "missing_proof", "placeholder_proof", "invalid_config"];
8
- export type ConsentHandoffModuleReason = (typeof CONSENT_HANDOFF_MODULE_REASONS)[number];
9
7
  export declare const CONSENT_HANDOFF_PROBE_CODES: readonly ["challenge_missing", "challenge_proof_unsigned", "challenge_proof_invalid", "pickup_not_202", "consent_page_unreachable"];
10
- export type ConsentHandoffProbeCode = (typeof CONSENT_HANDOFF_PROBE_CODES)[number];
11
8
  export declare const CONSENT_HANDOFF_CODES: readonly ["http_401", "http_403", "http_404", "http_4xx", "http_5xx", "http_other", "timeout", "network_error", "invalid_response", "missing_proof", "placeholder_proof", "invalid_config", "challenge_missing", "challenge_proof_unsigned", "challenge_proof_invalid", "pickup_not_202", "consent_page_unreachable"];
12
9
  export type ConsentHandoffCode = (typeof CONSENT_HANDOFF_CODES)[number];
13
10
  export declare const CONSENT_HANDOFF_HEALTH_OUTCOMES: readonly ["ok", "failed", "not_configured"];
@@ -1 +1 @@
1
- {"version":3,"file":"consent-handoff.d.mts","names":[],"sources":["../src/consent-handoff.ts"],"mappings":";;qBAgBa;YACD,+BAA+B;qBAG9B;YAKD,sCAAsC;qBAGrC;YAcD,qCAAqC;qBAGpC;YAOD,kCAAkC;qBAGjC;YAID,6BAA6B;qBAG5B;YACD,sCAAsC;qBAMrC,0BAAwB,EAAA;qBAQxB,4BAA0B,EAAA;;;;;;;;;;;;;;;;;;;;;;GAKrC,EAAA,KAAA;YACU,uBAAuB,EAAE,aAAa"}
1
+ {"version":3,"file":"consent-handoff.d.mts","names":[],"sources":["../src/consent-handoff.ts"],"mappings":";;qBAgBa;YACD,+BAA+B;qBAG9B;qBAOA;qBAgBA;qBASA;YAID,6BAA6B;qBAG5B;YACD,sCAAsC;qBAMrC,0BAAwB,EAAA;qBAQxB,4BAA0B,EAAA;;;;;;;;;;;;;;;;;;;;;;GAKrC,EAAA,KAAA;YACU,uBAAuB,EAAE,aAAa"}
@@ -3,11 +3,8 @@ import { z } from "zod";
3
3
  export declare const CONSENT_HANDOFF_SOURCES: readonly ["module", "probe"];
4
4
  export type ConsentHandoffSource = (typeof CONSENT_HANDOFF_SOURCES)[number];
5
5
  export declare const CONSENT_HANDOFF_REPORT_OUTCOMES: readonly ["registered", "registration_failed", "not_configured"];
6
- export type ConsentHandoffReportOutcome = (typeof CONSENT_HANDOFF_REPORT_OUTCOMES)[number];
7
6
  export declare const CONSENT_HANDOFF_MODULE_REASONS: readonly ["http_401", "http_403", "http_404", "http_4xx", "http_5xx", "http_other", "timeout", "network_error", "invalid_response", "missing_proof", "placeholder_proof", "invalid_config"];
8
- export type ConsentHandoffModuleReason = (typeof CONSENT_HANDOFF_MODULE_REASONS)[number];
9
7
  export declare const CONSENT_HANDOFF_PROBE_CODES: readonly ["challenge_missing", "challenge_proof_unsigned", "challenge_proof_invalid", "pickup_not_202", "consent_page_unreachable"];
10
- export type ConsentHandoffProbeCode = (typeof CONSENT_HANDOFF_PROBE_CODES)[number];
11
8
  export declare const CONSENT_HANDOFF_CODES: readonly ["http_401", "http_403", "http_404", "http_4xx", "http_5xx", "http_other", "timeout", "network_error", "invalid_response", "missing_proof", "placeholder_proof", "invalid_config", "challenge_missing", "challenge_proof_unsigned", "challenge_proof_invalid", "pickup_not_202", "consent_page_unreachable"];
12
9
  export type ConsentHandoffCode = (typeof CONSENT_HANDOFF_CODES)[number];
13
10
  export declare const CONSENT_HANDOFF_HEALTH_OUTCOMES: readonly ["ok", "failed", "not_configured"];
@@ -1 +1 @@
1
- {"version":3,"file":"consent-handoff.d.ts","names":[],"sources":["../src/consent-handoff.ts"],"mappings":";;qBAgBa;YACD,+BAA+B;qBAG9B;YAKD,sCAAsC;qBAGrC;YAcD,qCAAqC;qBAGpC;YAOD,kCAAkC;qBAGjC;YAID,6BAA6B;qBAG5B;YACD,sCAAsC;qBAMrC,0BAAwB,EAAA;qBAQxB,4BAA0B,EAAA;;;;;;;;;;;;;;;;;;;;;;GAKrC,EAAA,KAAA;YACU,uBAAuB,EAAE,aAAa"}
1
+ {"version":3,"file":"consent-handoff.d.ts","names":[],"sources":["../src/consent-handoff.ts"],"mappings":";;qBAgBa;YACD,+BAA+B;qBAG9B;qBAOA;qBAgBA;qBASA;YAID,6BAA6B;qBAG5B;YACD,sCAAsC;qBAMrC,0BAAwB,EAAA;qBAQxB,4BAA0B,EAAA;;;;;;;;;;;;;;;;;;;;;;GAKrC,EAAA,KAAA;YACU,uBAAuB,EAAE,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"consent-handoff.mjs","names":[],"sources":["../src/consent-handoff.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Consent-handoff health vocabulary: whether an agent that hits a delegation\n * challenge gets a consent link that can actually be redeemed.\n *\n * Two sources report into one health record per project:\n * - `module`: the PEP itself (the .NET module today), on its log-detection\n * report, right after it tries to register the challenge anchor.\n * - `probe`: the scheduled external check that plays an agent against the site.\n *\n * The module vocabulary is pinned by\n * `fixtures/kya-http/consent-handoff.codes.json`, which the .NET registrar also\n * asserts against.\n */\n\nexport const CONSENT_HANDOFF_SOURCES = ['module', 'probe'] as const;\nexport type ConsentHandoffSource = (typeof CONSENT_HANDOFF_SOURCES)[number];\n\n/** `consentHandoff.outcome` as a PEP reports it. */\nexport const CONSENT_HANDOFF_REPORT_OUTCOMES = [\n 'registered',\n 'registration_failed',\n 'not_configured',\n] as const;\nexport type ConsentHandoffReportOutcome = (typeof CONSENT_HANDOFF_REPORT_OUTCOMES)[number];\n\n/** Why a PEP's anchor registration failed. Every `http_*` code carries `httpStatus`. */\nexport const CONSENT_HANDOFF_MODULE_REASONS = [\n 'http_401',\n 'http_403',\n 'http_404',\n 'http_4xx',\n 'http_5xx',\n 'http_other',\n 'timeout',\n 'network_error',\n 'invalid_response',\n 'missing_proof',\n 'placeholder_proof',\n 'invalid_config',\n] as const;\nexport type ConsentHandoffModuleReason = (typeof CONSENT_HANDOFF_MODULE_REASONS)[number];\n\n/** Which stage of the handoff the external probe saw fail. */\nexport const CONSENT_HANDOFF_PROBE_CODES = [\n 'challenge_missing',\n 'challenge_proof_unsigned',\n 'challenge_proof_invalid',\n 'pickup_not_202',\n 'consent_page_unreachable',\n] as const;\nexport type ConsentHandoffProbeCode = (typeof CONSENT_HANDOFF_PROBE_CODES)[number];\n\n/** Every failure code either source can record. */\nexport const CONSENT_HANDOFF_CODES = [\n ...CONSENT_HANDOFF_MODULE_REASONS,\n ...CONSENT_HANDOFF_PROBE_CODES,\n] as const;\nexport type ConsentHandoffCode = (typeof CONSENT_HANDOFF_CODES)[number];\n\n/** A health observation: the handoff worked, failed, or is not set up on purpose. */\nexport const CONSENT_HANDOFF_HEALTH_OUTCOMES = ['ok', 'failed', 'not_configured'] as const;\nexport type ConsentHandoffHealthOutcome = (typeof CONSENT_HANDOFF_HEALTH_OUTCOMES)[number];\n\n// host[:port] only: never a path, query or userinfo.\nconst AUTHORITY_PATTERN = /^(?:[A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*|\\[[0-9A-Fa-f:.]+\\])(?::\\d{1,5})?$/;\n\n/** A strict `host[:port]`. The probe route requires it; reports only prefer it. */\nexport const ConsentHandoffHostSchema = z.string().max(261).regex(AUTHORITY_PATTERN);\n\n/**\n * The `consentHandoff` block of a log-detection report. A detail that doesn't\n * validate is dropped on its own, so the outcome and reason still count: .NET's\n * `Uri.Authority` can give a host this pattern refuses (an underscore, a Unicode\n * label, a trailing dot), and losing the host must never lose the 401 with it.\n */\nexport const ConsentHandoffReportSchema = z.object({\n outcome: z.enum(CONSENT_HANDOFF_REPORT_OUTCOMES),\n reason: z.enum(CONSENT_HANDOFF_MODULE_REASONS).optional(),\n httpStatus: z.number().int().min(100).max(599).optional().catch(undefined),\n host: ConsentHandoffHostSchema.optional().catch(undefined),\n});\nexport type ConsentHandoffReport = z.infer<typeof ConsentHandoffReportSchema>;\n"],"mappings":"wBAgBA,MAAa,EAA0B,CAAC,SAAU,OAAO,EAI5C,EAAkC,CAC7C,aACA,sBACA,gBACF,EAIa,EAAiC,CAC5C,WACA,WACA,WACA,WACA,WACA,aACA,UACA,gBACA,mBACA,gBACA,oBACA,gBACF,EAIa,EAA8B,CACzC,oBACA,2BACA,0BACA,iBACA,0BACF,EAIa,EAAwB,CACnC,GAAG,EACH,GAAG,CACL,EAIa,EAAkC,CAAC,KAAM,SAAU,gBAAgB,EAOnE,EAA2B,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,yEAAiB,EAQtE,EAA6B,EAAE,OAAO,CACjD,QAAS,EAAE,KAAK,CAA+B,EAC/C,OAAQ,EAAE,KAAK,CAA8B,CAAC,CAAC,SAAS,EACxD,WAAY,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,IAAA,EAAS,EACzE,KAAM,EAAyB,SAAS,CAAC,CAAC,MAAM,IAAA,EAAS,CAC3D,CAAC"}
1
+ {"version":3,"file":"consent-handoff.mjs","names":[],"sources":["../src/consent-handoff.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Consent-handoff health vocabulary: whether an agent that hits a delegation\n * challenge gets a consent link that can actually be redeemed.\n *\n * Two sources report into one health record per project:\n * - `module`: the PEP itself (the .NET module today), on its log-detection\n * report, right after it tries to register the challenge anchor.\n * - `probe`: the scheduled external check that plays an agent against the site.\n *\n * The module vocabulary is pinned by\n * `fixtures/kya-http/consent-handoff.codes.json`, which the .NET registrar also\n * asserts against.\n */\n\nexport const CONSENT_HANDOFF_SOURCES = ['module', 'probe'] as const;\nexport type ConsentHandoffSource = (typeof CONSENT_HANDOFF_SOURCES)[number];\n\n/** `consentHandoff.outcome` as a PEP reports it. */\nexport const CONSENT_HANDOFF_REPORT_OUTCOMES = [\n 'registered',\n 'registration_failed',\n 'not_configured',\n] as const;\n\n/** Why a PEP's anchor registration failed. Every `http_*` code carries `httpStatus`. */\nexport const CONSENT_HANDOFF_MODULE_REASONS = [\n 'http_401',\n 'http_403',\n 'http_404',\n 'http_4xx',\n 'http_5xx',\n 'http_other',\n 'timeout',\n 'network_error',\n 'invalid_response',\n 'missing_proof',\n 'placeholder_proof',\n 'invalid_config',\n] as const;\n\n/** Which stage of the handoff the external probe saw fail. */\nexport const CONSENT_HANDOFF_PROBE_CODES = [\n 'challenge_missing',\n 'challenge_proof_unsigned',\n 'challenge_proof_invalid',\n 'pickup_not_202',\n 'consent_page_unreachable',\n] as const;\n\n/** Every failure code either source can record. */\nexport const CONSENT_HANDOFF_CODES = [\n ...CONSENT_HANDOFF_MODULE_REASONS,\n ...CONSENT_HANDOFF_PROBE_CODES,\n] as const;\nexport type ConsentHandoffCode = (typeof CONSENT_HANDOFF_CODES)[number];\n\n/** A health observation: the handoff worked, failed, or is not set up on purpose. */\nexport const CONSENT_HANDOFF_HEALTH_OUTCOMES = ['ok', 'failed', 'not_configured'] as const;\nexport type ConsentHandoffHealthOutcome = (typeof CONSENT_HANDOFF_HEALTH_OUTCOMES)[number];\n\n// host[:port] only: never a path, query or userinfo.\nconst AUTHORITY_PATTERN = /^(?:[A-Za-z0-9-]+(?:\\.[A-Za-z0-9-]+)*|\\[[0-9A-Fa-f:.]+\\])(?::\\d{1,5})?$/;\n\n/** A strict `host[:port]`. The probe route requires it; reports only prefer it. */\nexport const ConsentHandoffHostSchema = z.string().max(261).regex(AUTHORITY_PATTERN);\n\n/**\n * The `consentHandoff` block of a log-detection report. A detail that doesn't\n * validate is dropped on its own, so the outcome and reason still count: .NET's\n * `Uri.Authority` can give a host this pattern refuses (an underscore, a Unicode\n * label, a trailing dot), and losing the host must never lose the 401 with it.\n */\nexport const ConsentHandoffReportSchema = z.object({\n outcome: z.enum(CONSENT_HANDOFF_REPORT_OUTCOMES),\n reason: z.enum(CONSENT_HANDOFF_MODULE_REASONS).optional(),\n httpStatus: z.number().int().min(100).max(599).optional().catch(undefined),\n host: ConsentHandoffHostSchema.optional().catch(undefined),\n});\nexport type ConsentHandoffReport = z.infer<typeof ConsentHandoffReportSchema>;\n"],"mappings":"wBAgBA,MAAa,EAA0B,CAAC,SAAU,OAAO,EAI5C,EAAkC,CAC7C,aACA,sBACA,gBACF,EAGa,EAAiC,CAC5C,WACA,WACA,WACA,WACA,WACA,aACA,UACA,gBACA,mBACA,gBACA,oBACA,gBACF,EAGa,EAA8B,CACzC,oBACA,2BACA,0BACA,iBACA,0BACF,EAGa,EAAwB,CACnC,GAAG,EACH,GAAG,CACL,EAIa,EAAkC,CAAC,KAAM,SAAU,gBAAgB,EAOnE,EAA2B,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,MAAM,yEAAiB,EAQtE,EAA6B,EAAE,OAAO,CACjD,QAAS,EAAE,KAAK,CAA+B,EAC/C,OAAQ,EAAE,KAAK,CAA8B,CAAC,CAAC,SAAS,EACxD,WAAY,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,IAAA,EAAS,EACzE,KAAM,EAAyB,SAAS,CAAC,CAAC,MAAM,IAAA,EAAS,CAC3D,CAAC"}
@@ -0,0 +1,10 @@
1
+ //#region src/default-sign-in-host.d.ts
2
+ export declare const AUTH_DOMAIN = "auth.knowthat.ai";
3
+ export declare function isDnsLabel(value: string): boolean;
4
+ export declare function isDefaultSignInHostLabel(label: string): boolean;
5
+ export declare function defaultSignInHost(label: string): string | null;
6
+ export declare function defaultSignInHostLabel(host: string): string | null;
7
+ export declare function isUnderAuthDomain(host: string): boolean;
8
+ export declare function withoutTrailingDots(host: string): string;
9
+ //#endregion
10
+ //# sourceMappingURL=default-sign-in-host.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-sign-in-host.d.mts","names":[],"sources":["../src/default-sign-in-host.ts"],"mappings":";qBAWa;wBAMG,WAAW;wBAUX,yBAAyB;wBAKzB,kBAAkB;wBAUlB,uBAAuB;wBAYvB,kBAAkB;wBAUlB,oBAAoB"}
@@ -0,0 +1,10 @@
1
+ //#region src/default-sign-in-host.d.ts
2
+ export declare const AUTH_DOMAIN = "auth.knowthat.ai";
3
+ export declare function isDnsLabel(value: string): boolean;
4
+ export declare function isDefaultSignInHostLabel(label: string): boolean;
5
+ export declare function defaultSignInHost(label: string): string | null;
6
+ export declare function defaultSignInHostLabel(host: string): string | null;
7
+ export declare function isUnderAuthDomain(host: string): boolean;
8
+ export declare function withoutTrailingDots(host: string): string;
9
+ //#endregion
10
+ //# sourceMappingURL=default-sign-in-host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-sign-in-host.d.ts","names":[],"sources":["../src/default-sign-in-host.ts"],"mappings":";qBAWa;wBAMG,WAAW;wBAUX,yBAAyB;wBAKzB,kBAAkB;wBAUlB,uBAAuB;wBAYvB,kBAAkB;wBAUlB,oBAAoB"}
@@ -0,0 +1,72 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region src/default-sign-in-host.ts
3
+ /**
4
+ * Default sign-in hosts (F5): an org without its own verified authorization
5
+ * domain signs in at `<label>.auth.knowthat.ai`, one host per org.
6
+ *
7
+ * The platform names the host (`defaultIssuerHost`, apps/web) and the gateway
8
+ * routes it; both read the domain and the host's shape from here, so the two
9
+ * can't drift apart. Which labels an org may hold (reserved names, the slug
10
+ * rule) is the platform's call, not this module's.
11
+ */
12
+ /** The parent of every default sign-in host. */
13
+ const AUTH_DOMAIN = "auth.knowthat.ai";
14
+ /** One DNS label: 1-63 of lowercase a-z, 0-9 and hyphen, no leading or trailing hyphen. */
15
+ const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
16
+ /** Whether `value` is exactly one lowercase DNS label. */
17
+ function isDnsLabel(value) {
18
+ return value.length <= 63 && DNS_LABEL.test(value);
19
+ }
20
+ /**
21
+ * Whether `label` can name a default sign-in host: one DNS label, and not a
22
+ * reserved one. A label with `--` in its third and fourth places is reserved
23
+ * (RFC 5891 §4.2.3.1), and `xn--` is one: an IDNA label, which a browser shows
24
+ * as Unicode that can pass for another name.
25
+ */
26
+ function isDefaultSignInHostLabel(label) {
27
+ return isDnsLabel(label) && label.slice(2, 4) !== "--";
28
+ }
29
+ /** The default sign-in host for `label`, or null when it can't name one. */
30
+ function defaultSignInHost(label) {
31
+ return isDefaultSignInHostLabel(label) ? `${label}.${AUTH_DOMAIN}` : null;
32
+ }
33
+ /**
34
+ * The label of a default sign-in host: exactly one label before
35
+ * `.auth.knowthat.ai` that can name one. Null for any other host, the bare
36
+ * domain, or a deeper name. Hosts are compared as given; pass them lowercase,
37
+ * as an attested host is.
38
+ */
39
+ function defaultSignInHostLabel(host) {
40
+ const suffix = `.${AUTH_DOMAIN}`;
41
+ if (!host.endsWith(suffix)) return null;
42
+ const label = host.slice(0, -suffix.length);
43
+ return isDefaultSignInHostLabel(label) ? label : null;
44
+ }
45
+ /**
46
+ * Whether `host` is the auth domain or any name under it, valid default host
47
+ * or not. No project may add one as its own domain: every name there is an
48
+ * org's default sign-in host, or one an org could come to hold.
49
+ */
50
+ function isUnderAuthDomain(host) {
51
+ const name = withoutTrailingDots(host.toLowerCase());
52
+ return name === "auth.knowthat.ai" || name.endsWith(`.${"auth.knowthat.ai"}`);
53
+ }
54
+ /**
55
+ * `host` with any trailing dots dropped. A plain scan, not a regex: the host
56
+ * is uncontrolled input, and an anchored `\.+$` backtracks on a long run of
57
+ * dots.
58
+ */
59
+ function withoutTrailingDots(host) {
60
+ let end = host.length;
61
+ while (end > 0 && host.charCodeAt(end - 1) === 46) end -= 1;
62
+ return host.slice(0, end);
63
+ }
64
+
65
+ //#endregion
66
+ exports.AUTH_DOMAIN = AUTH_DOMAIN;
67
+ exports.defaultSignInHost = defaultSignInHost;
68
+ exports.defaultSignInHostLabel = defaultSignInHostLabel;
69
+ exports.isDefaultSignInHostLabel = isDefaultSignInHostLabel;
70
+ exports.isDnsLabel = isDnsLabel;
71
+ exports.isUnderAuthDomain = isUnderAuthDomain;
72
+ exports.withoutTrailingDots = withoutTrailingDots;
@@ -0,0 +1,66 @@
1
+ //#region src/default-sign-in-host.ts
2
+ /**
3
+ * Default sign-in hosts (F5): an org without its own verified authorization
4
+ * domain signs in at `<label>.auth.knowthat.ai`, one host per org.
5
+ *
6
+ * The platform names the host (`defaultIssuerHost`, apps/web) and the gateway
7
+ * routes it; both read the domain and the host's shape from here, so the two
8
+ * can't drift apart. Which labels an org may hold (reserved names, the slug
9
+ * rule) is the platform's call, not this module's.
10
+ */
11
+ /** The parent of every default sign-in host. */
12
+ const AUTH_DOMAIN = "auth.knowthat.ai";
13
+ /** One DNS label: 1-63 of lowercase a-z, 0-9 and hyphen, no leading or trailing hyphen. */
14
+ const DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
15
+ /** Whether `value` is exactly one lowercase DNS label. */
16
+ function isDnsLabel(value) {
17
+ return value.length <= 63 && DNS_LABEL.test(value);
18
+ }
19
+ /**
20
+ * Whether `label` can name a default sign-in host: one DNS label, and not a
21
+ * reserved one. A label with `--` in its third and fourth places is reserved
22
+ * (RFC 5891 §4.2.3.1), and `xn--` is one: an IDNA label, which a browser shows
23
+ * as Unicode that can pass for another name.
24
+ */
25
+ function isDefaultSignInHostLabel(label) {
26
+ return isDnsLabel(label) && label.slice(2, 4) !== "--";
27
+ }
28
+ /** The default sign-in host for `label`, or null when it can't name one. */
29
+ function defaultSignInHost(label) {
30
+ return isDefaultSignInHostLabel(label) ? `${label}.${AUTH_DOMAIN}` : null;
31
+ }
32
+ /**
33
+ * The label of a default sign-in host: exactly one label before
34
+ * `.auth.knowthat.ai` that can name one. Null for any other host, the bare
35
+ * domain, or a deeper name. Hosts are compared as given; pass them lowercase,
36
+ * as an attested host is.
37
+ */
38
+ function defaultSignInHostLabel(host) {
39
+ const suffix = `.${AUTH_DOMAIN}`;
40
+ if (!host.endsWith(suffix)) return null;
41
+ const label = host.slice(0, -suffix.length);
42
+ return isDefaultSignInHostLabel(label) ? label : null;
43
+ }
44
+ /**
45
+ * Whether `host` is the auth domain or any name under it, valid default host
46
+ * or not. No project may add one as its own domain: every name there is an
47
+ * org's default sign-in host, or one an org could come to hold.
48
+ */
49
+ function isUnderAuthDomain(host) {
50
+ const name = withoutTrailingDots(host.toLowerCase());
51
+ return name === "auth.knowthat.ai" || name.endsWith(`.${"auth.knowthat.ai"}`);
52
+ }
53
+ /**
54
+ * `host` with any trailing dots dropped. A plain scan, not a regex: the host
55
+ * is uncontrolled input, and an anchored `\.+$` backtracks on a long run of
56
+ * dots.
57
+ */
58
+ function withoutTrailingDots(host) {
59
+ let end = host.length;
60
+ while (end > 0 && host.charCodeAt(end - 1) === 46) end -= 1;
61
+ return host.slice(0, end);
62
+ }
63
+
64
+ //#endregion
65
+ export { AUTH_DOMAIN, defaultSignInHost, defaultSignInHostLabel, isDefaultSignInHostLabel, isDnsLabel, isUnderAuthDomain, withoutTrailingDots };
66
+ //# sourceMappingURL=default-sign-in-host.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-sign-in-host.mjs","names":[],"sources":["../src/default-sign-in-host.ts"],"sourcesContent":["/**\n * Default sign-in hosts (F5): an org without its own verified authorization\n * domain signs in at `<label>.auth.knowthat.ai`, one host per org.\n *\n * The platform names the host (`defaultIssuerHost`, apps/web) and the gateway\n * routes it; both read the domain and the host's shape from here, so the two\n * can't drift apart. Which labels an org may hold (reserved names, the slug\n * rule) is the platform's call, not this module's.\n */\n\n/** The parent of every default sign-in host. */\nexport const AUTH_DOMAIN = 'auth.knowthat.ai';\n\n/** One DNS label: 1-63 of lowercase a-z, 0-9 and hyphen, no leading or trailing hyphen. */\nconst DNS_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;\n\n/** Whether `value` is exactly one lowercase DNS label. */\nexport function isDnsLabel(value: string): boolean {\n return value.length <= 63 && DNS_LABEL.test(value);\n}\n\n/**\n * Whether `label` can name a default sign-in host: one DNS label, and not a\n * reserved one. A label with `--` in its third and fourth places is reserved\n * (RFC 5891 §4.2.3.1), and `xn--` is one: an IDNA label, which a browser shows\n * as Unicode that can pass for another name.\n */\nexport function isDefaultSignInHostLabel(label: string): boolean {\n return isDnsLabel(label) && label.slice(2, 4) !== '--';\n}\n\n/** The default sign-in host for `label`, or null when it can't name one. */\nexport function defaultSignInHost(label: string): string | null {\n return isDefaultSignInHostLabel(label) ? `${label}.${AUTH_DOMAIN}` : null;\n}\n\n/**\n * The label of a default sign-in host: exactly one label before\n * `.auth.knowthat.ai` that can name one. Null for any other host, the bare\n * domain, or a deeper name. Hosts are compared as given; pass them lowercase,\n * as an attested host is.\n */\nexport function defaultSignInHostLabel(host: string): string | null {\n const suffix = `.${AUTH_DOMAIN}`;\n if (!host.endsWith(suffix)) return null;\n const label = host.slice(0, -suffix.length);\n return isDefaultSignInHostLabel(label) ? label : null;\n}\n\n/**\n * Whether `host` is the auth domain or any name under it, valid default host\n * or not. No project may add one as its own domain: every name there is an\n * org's default sign-in host, or one an org could come to hold.\n */\nexport function isUnderAuthDomain(host: string): boolean {\n const name = withoutTrailingDots(host.toLowerCase());\n return name === AUTH_DOMAIN || name.endsWith(`.${AUTH_DOMAIN}`);\n}\n\n/**\n * `host` with any trailing dots dropped. A plain scan, not a regex: the host\n * is uncontrolled input, and an anchored `\\.+$` backtracks on a long run of\n * dots.\n */\nexport function withoutTrailingDots(host: string): string {\n let end = host.length;\n while (end > 0 && host.charCodeAt(end - 1) === 46 /* '.' */) end -= 1;\n return host.slice(0, end);\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,cAAc;;AAG3B,MAAM,YAAY;;AAGlB,SAAgB,WAAW,OAAwB;CACjD,OAAO,MAAM,UAAU,MAAM,UAAU,KAAK,KAAK;AACnD;;;;;;;AAQA,SAAgB,yBAAyB,OAAwB;CAC/D,OAAO,WAAW,KAAK,KAAK,MAAM,MAAM,GAAG,CAAC,MAAM;AACpD;;AAGA,SAAgB,kBAAkB,OAA8B;CAC9D,OAAO,yBAAyB,KAAK,IAAI,GAAG,MAAM,GAAG,gBAAgB;AACvE;;;;;;;AAQA,SAAgB,uBAAuB,MAA6B;CAClE,MAAM,SAAS,IAAI;CACnB,IAAI,CAAC,KAAK,SAAS,MAAM,GAAG,OAAO;CACnC,MAAM,QAAQ,KAAK,MAAM,GAAG,CAAC,OAAO,MAAM;CAC1C,OAAO,yBAAyB,KAAK,IAAI,QAAQ;AACnD;;;;;;AAOA,SAAgB,kBAAkB,MAAuB;CACvD,MAAM,OAAO,oBAAoB,KAAK,YAAY,CAAC;CACnD,OAAO,+BAAwB,KAAK,SAAS,wBAAiB;AAChE;;;;;;AAOA,SAAgB,oBAAoB,MAAsB;CACxD,IAAI,MAAM,KAAK;CACf,OAAO,MAAM,KAAK,KAAK,WAAW,MAAM,CAAC,MAAM,IAAc,OAAO;CACpE,OAAO,KAAK,MAAM,GAAG,GAAG;AAC1B"}