@gadicc/loom 0.0.0-oidc-bootstrap.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 (342) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +6 -0
  3. package/README.md +448 -0
  4. package/THIRD_PARTY_NOTICES.md +25 -0
  5. package/db/drizzle-config.d.ts +20 -0
  6. package/db/drizzle-config.js +34 -0
  7. package/db/fixtures.d.ts +31 -0
  8. package/db/fixtures.js +52 -0
  9. package/db/neon.d.ts +3 -0
  10. package/db/neon.js +20 -0
  11. package/db/neonFull.d.ts +12 -0
  12. package/db/neonFull.js +33 -0
  13. package/db/package.json +3 -0
  14. package/db/testing.d.ts +26 -0
  15. package/db/testing.js +76 -0
  16. package/db/testing.test.ts +28 -0
  17. package/db/valibot.d.ts +23 -0
  18. package/db/valibot.js +8 -0
  19. package/esm/_dnt.polyfills.d.ts +149 -0
  20. package/esm/_dnt.polyfills.d.ts.map +1 -0
  21. package/esm/_dnt.polyfills.js +163 -0
  22. package/esm/_dnt.shims.d.ts +2 -0
  23. package/esm/_dnt.shims.d.ts.map +1 -0
  24. package/esm/_dnt.shims.js +57 -0
  25. package/esm/bin/loom.d.ts +2 -0
  26. package/esm/bin/loom.d.ts.map +1 -0
  27. package/esm/bin/loom.js +11 -0
  28. package/esm/mod.d.ts +9 -0
  29. package/esm/mod.d.ts.map +1 -0
  30. package/esm/mod.js +8 -0
  31. package/esm/package.json +3 -0
  32. package/esm/src/apiKeys/authorize.d.ts +4 -0
  33. package/esm/src/apiKeys/authorize.d.ts.map +1 -0
  34. package/esm/src/apiKeys/authorize.js +184 -0
  35. package/esm/src/apiKeys/country.d.ts +3 -0
  36. package/esm/src/apiKeys/country.d.ts.map +1 -0
  37. package/esm/src/apiKeys/country.js +7 -0
  38. package/esm/src/apiKeys/credentials.d.ts +4 -0
  39. package/esm/src/apiKeys/credentials.d.ts.map +1 -0
  40. package/esm/src/apiKeys/credentials.js +55 -0
  41. package/esm/src/apiKeys/fingerprint.d.ts +3 -0
  42. package/esm/src/apiKeys/fingerprint.d.ts.map +1 -0
  43. package/esm/src/apiKeys/fingerprint.js +5 -0
  44. package/esm/src/apiKeys/mod.d.ts +9 -0
  45. package/esm/src/apiKeys/mod.d.ts.map +1 -0
  46. package/esm/src/apiKeys/mod.js +8 -0
  47. package/esm/src/apiKeys/policy.d.ts +59 -0
  48. package/esm/src/apiKeys/policy.d.ts.map +1 -0
  49. package/esm/src/apiKeys/policy.js +88 -0
  50. package/esm/src/apiKeys/retention.d.ts +55 -0
  51. package/esm/src/apiKeys/retention.d.ts.map +1 -0
  52. package/esm/src/apiKeys/retention.js +65 -0
  53. package/esm/src/apiKeys/types.d.ts +175 -0
  54. package/esm/src/apiKeys/types.d.ts.map +1 -0
  55. package/esm/src/apiKeys/types.js +1 -0
  56. package/esm/src/cli/externalSkills.d.ts +39 -0
  57. package/esm/src/cli/externalSkills.d.ts.map +1 -0
  58. package/esm/src/cli/externalSkills.js +177 -0
  59. package/esm/src/cli/mod.d.ts +337 -0
  60. package/esm/src/cli/mod.d.ts.map +1 -0
  61. package/esm/src/cli/mod.js +9268 -0
  62. package/esm/src/cli/projectSkills.d.ts +102 -0
  63. package/esm/src/cli/projectSkills.d.ts.map +1 -0
  64. package/esm/src/cli/projectSkills.js +592 -0
  65. package/esm/src/files/client.d.ts +29 -0
  66. package/esm/src/files/client.d.ts.map +1 -0
  67. package/esm/src/files/client.js +41 -0
  68. package/esm/src/files/errors.d.ts +37 -0
  69. package/esm/src/files/errors.d.ts.map +1 -0
  70. package/esm/src/files/errors.js +66 -0
  71. package/esm/src/files/hash.d.ts +15 -0
  72. package/esm/src/files/hash.d.ts.map +1 -0
  73. package/esm/src/files/hash.js +82 -0
  74. package/esm/src/files/memory.d.ts +29 -0
  75. package/esm/src/files/memory.d.ts.map +1 -0
  76. package/esm/src/files/memory.js +109 -0
  77. package/esm/src/files/metadata.d.ts +10 -0
  78. package/esm/src/files/metadata.d.ts.map +1 -0
  79. package/esm/src/files/metadata.js +186 -0
  80. package/esm/src/files/mod.d.ts +10 -0
  81. package/esm/src/files/mod.d.ts.map +1 -0
  82. package/esm/src/files/mod.js +9 -0
  83. package/esm/src/files/s3.d.ts +29 -0
  84. package/esm/src/files/s3.d.ts.map +1 -0
  85. package/esm/src/files/s3.js +107 -0
  86. package/esm/src/files/service.d.ts +27 -0
  87. package/esm/src/files/service.d.ts.map +1 -0
  88. package/esm/src/files/service.js +136 -0
  89. package/esm/src/files/types.d.ts +134 -0
  90. package/esm/src/files/types.d.ts.map +1 -0
  91. package/esm/src/files/types.js +1 -0
  92. package/esm/src/jobs/catalog.d.ts +32 -0
  93. package/esm/src/jobs/catalog.d.ts.map +1 -0
  94. package/esm/src/jobs/catalog.js +208 -0
  95. package/esm/src/jobs/controller.d.ts +28 -0
  96. package/esm/src/jobs/controller.d.ts.map +1 -0
  97. package/esm/src/jobs/controller.js +95 -0
  98. package/esm/src/jobs/direct.d.ts +36 -0
  99. package/esm/src/jobs/direct.d.ts.map +1 -0
  100. package/esm/src/jobs/direct.js +122 -0
  101. package/esm/src/jobs/events.d.ts +15 -0
  102. package/esm/src/jobs/events.d.ts.map +1 -0
  103. package/esm/src/jobs/events.js +30 -0
  104. package/esm/src/jobs/format.d.ts +16 -0
  105. package/esm/src/jobs/format.d.ts.map +1 -0
  106. package/esm/src/jobs/format.js +183 -0
  107. package/esm/src/jobs/http.d.ts +22 -0
  108. package/esm/src/jobs/http.d.ts.map +1 -0
  109. package/esm/src/jobs/http.js +44 -0
  110. package/esm/src/jobs/log.d.ts +2 -0
  111. package/esm/src/jobs/log.d.ts.map +1 -0
  112. package/esm/src/jobs/log.js +10 -0
  113. package/esm/src/jobs/mod.d.ts +10 -0
  114. package/esm/src/jobs/mod.d.ts.map +1 -0
  115. package/esm/src/jobs/mod.js +9 -0
  116. package/esm/src/jobs/run.d.ts +20 -0
  117. package/esm/src/jobs/run.d.ts.map +1 -0
  118. package/esm/src/jobs/run.js +57 -0
  119. package/esm/src/jobs/types.d.ts +31 -0
  120. package/esm/src/jobs/types.d.ts.map +1 -0
  121. package/esm/src/jobs/types.js +1 -0
  122. package/esm/src/mui/apiKeys.d.ts +65 -0
  123. package/esm/src/mui/apiKeys.d.ts.map +1 -0
  124. package/esm/src/mui/apiKeys.js +301 -0
  125. package/esm/src/mui/apiKeysView.d.ts +48 -0
  126. package/esm/src/mui/apiKeysView.d.ts.map +1 -0
  127. package/esm/src/mui/apiKeysView.js +34 -0
  128. package/esm/src/mui/confirm.d.ts +12 -0
  129. package/esm/src/mui/confirm.d.ts.map +1 -0
  130. package/esm/src/mui/confirm.js +78 -0
  131. package/esm/src/mui/mod.d.ts +4 -0
  132. package/esm/src/mui/mod.d.ts.map +1 -0
  133. package/esm/src/mui/mod.js +2 -0
  134. package/esm/src/next/apiKeys/mod.d.ts +64 -0
  135. package/esm/src/next/apiKeys/mod.d.ts.map +1 -0
  136. package/esm/src/next/apiKeys/mod.js +217 -0
  137. package/esm/src/next/auth/config.d.ts +34 -0
  138. package/esm/src/next/auth/config.d.ts.map +1 -0
  139. package/esm/src/next/auth/config.js +103 -0
  140. package/esm/src/next/auth/mod.d.ts +3 -0
  141. package/esm/src/next/auth/mod.d.ts.map +1 -0
  142. package/esm/src/next/auth/mod.js +2 -0
  143. package/esm/src/next/auth/server.d.ts +28 -0
  144. package/esm/src/next/auth/server.d.ts.map +1 -0
  145. package/esm/src/next/auth/server.js +24 -0
  146. package/esm/src/next/files/mod.d.ts +3 -0
  147. package/esm/src/next/files/mod.d.ts.map +1 -0
  148. package/esm/src/next/files/mod.js +2 -0
  149. package/esm/src/next/files/route.d.ts +99 -0
  150. package/esm/src/next/files/route.d.ts.map +1 -0
  151. package/esm/src/next/files/route.js +349 -0
  152. package/esm/src/next/jobs/list.d.ts +25 -0
  153. package/esm/src/next/jobs/list.d.ts.map +1 -0
  154. package/esm/src/next/jobs/list.js +39 -0
  155. package/esm/src/next/jobs/mod.d.ts +6 -0
  156. package/esm/src/next/jobs/mod.d.ts.map +1 -0
  157. package/esm/src/next/jobs/mod.js +5 -0
  158. package/esm/src/next/jobs/paths.d.ts +14 -0
  159. package/esm/src/next/jobs/paths.d.ts.map +1 -0
  160. package/esm/src/next/jobs/paths.js +40 -0
  161. package/esm/src/next/jobs/route.d.ts +48 -0
  162. package/esm/src/next/jobs/route.d.ts.map +1 -0
  163. package/esm/src/next/jobs/route.js +101 -0
  164. package/esm/src/next/jobs/run.d.ts +51 -0
  165. package/esm/src/next/jobs/run.d.ts.map +1 -0
  166. package/esm/src/next/jobs/run.js +563 -0
  167. package/esm/src/next/jobs/stream.d.ts +3 -0
  168. package/esm/src/next/jobs/stream.d.ts.map +1 -0
  169. package/esm/src/next/jobs/stream.js +25 -0
  170. package/esm/src/next/pwa/mod.d.ts +104 -0
  171. package/esm/src/next/pwa/mod.d.ts.map +1 -0
  172. package/esm/src/next/pwa/mod.js +169 -0
  173. package/esm/src/next/pwa/worker.d.ts +27 -0
  174. package/esm/src/next/pwa/worker.d.ts.map +1 -0
  175. package/esm/src/next/pwa/worker.js +27 -0
  176. package/package.json +293 -0
  177. package/script/_dnt.polyfills.d.ts +149 -0
  178. package/script/_dnt.polyfills.d.ts.map +1 -0
  179. package/script/_dnt.polyfills.js +166 -0
  180. package/script/_dnt.shims.d.ts +2 -0
  181. package/script/_dnt.shims.d.ts.map +1 -0
  182. package/script/_dnt.shims.js +60 -0
  183. package/script/bin/loom.d.ts +2 -0
  184. package/script/bin/loom.d.ts.map +1 -0
  185. package/script/bin/loom.js +17 -0
  186. package/script/mod.d.ts +9 -0
  187. package/script/mod.d.ts.map +1 -0
  188. package/script/mod.js +24 -0
  189. package/script/package.json +3 -0
  190. package/script/src/apiKeys/authorize.d.ts +4 -0
  191. package/script/src/apiKeys/authorize.d.ts.map +1 -0
  192. package/script/src/apiKeys/authorize.js +187 -0
  193. package/script/src/apiKeys/country.d.ts +3 -0
  194. package/script/src/apiKeys/country.d.ts.map +1 -0
  195. package/script/src/apiKeys/country.js +10 -0
  196. package/script/src/apiKeys/credentials.d.ts +4 -0
  197. package/script/src/apiKeys/credentials.d.ts.map +1 -0
  198. package/script/src/apiKeys/credentials.js +58 -0
  199. package/script/src/apiKeys/fingerprint.d.ts +3 -0
  200. package/script/src/apiKeys/fingerprint.d.ts.map +1 -0
  201. package/script/src/apiKeys/fingerprint.js +8 -0
  202. package/script/src/apiKeys/mod.d.ts +9 -0
  203. package/script/src/apiKeys/mod.d.ts.map +1 -0
  204. package/script/src/apiKeys/mod.js +24 -0
  205. package/script/src/apiKeys/policy.d.ts +59 -0
  206. package/script/src/apiKeys/policy.d.ts.map +1 -0
  207. package/script/src/apiKeys/policy.js +92 -0
  208. package/script/src/apiKeys/retention.d.ts +55 -0
  209. package/script/src/apiKeys/retention.d.ts.map +1 -0
  210. package/script/src/apiKeys/retention.js +70 -0
  211. package/script/src/apiKeys/types.d.ts +175 -0
  212. package/script/src/apiKeys/types.d.ts.map +1 -0
  213. package/script/src/apiKeys/types.js +2 -0
  214. package/script/src/cli/externalSkills.d.ts +39 -0
  215. package/script/src/cli/externalSkills.d.ts.map +1 -0
  216. package/script/src/cli/externalSkills.js +181 -0
  217. package/script/src/cli/mod.d.ts +337 -0
  218. package/script/src/cli/mod.d.ts.map +1 -0
  219. package/script/src/cli/mod.js +9337 -0
  220. package/script/src/cli/projectSkills.d.ts +102 -0
  221. package/script/src/cli/projectSkills.d.ts.map +1 -0
  222. package/script/src/cli/projectSkills.js +606 -0
  223. package/script/src/files/client.d.ts +29 -0
  224. package/script/src/files/client.d.ts.map +1 -0
  225. package/script/src/files/client.js +45 -0
  226. package/script/src/files/errors.d.ts +37 -0
  227. package/script/src/files/errors.d.ts.map +1 -0
  228. package/script/src/files/errors.js +76 -0
  229. package/script/src/files/hash.d.ts +15 -0
  230. package/script/src/files/hash.d.ts.map +1 -0
  231. package/script/src/files/hash.js +89 -0
  232. package/script/src/files/memory.d.ts +29 -0
  233. package/script/src/files/memory.d.ts.map +1 -0
  234. package/script/src/files/memory.js +113 -0
  235. package/script/src/files/metadata.d.ts +10 -0
  236. package/script/src/files/metadata.d.ts.map +1 -0
  237. package/script/src/files/metadata.js +189 -0
  238. package/script/src/files/mod.d.ts +10 -0
  239. package/script/src/files/mod.d.ts.map +1 -0
  240. package/script/src/files/mod.js +25 -0
  241. package/script/src/files/s3.d.ts +29 -0
  242. package/script/src/files/s3.d.ts.map +1 -0
  243. package/script/src/files/s3.js +110 -0
  244. package/script/src/files/service.d.ts +27 -0
  245. package/script/src/files/service.d.ts.map +1 -0
  246. package/script/src/files/service.js +139 -0
  247. package/script/src/files/types.d.ts +134 -0
  248. package/script/src/files/types.d.ts.map +1 -0
  249. package/script/src/files/types.js +2 -0
  250. package/script/src/jobs/catalog.d.ts +32 -0
  251. package/script/src/jobs/catalog.d.ts.map +1 -0
  252. package/script/src/jobs/catalog.js +223 -0
  253. package/script/src/jobs/controller.d.ts +28 -0
  254. package/script/src/jobs/controller.d.ts.map +1 -0
  255. package/script/src/jobs/controller.js +100 -0
  256. package/script/src/jobs/direct.d.ts +36 -0
  257. package/script/src/jobs/direct.d.ts.map +1 -0
  258. package/script/src/jobs/direct.js +128 -0
  259. package/script/src/jobs/events.d.ts +15 -0
  260. package/script/src/jobs/events.d.ts.map +1 -0
  261. package/script/src/jobs/events.js +37 -0
  262. package/script/src/jobs/format.d.ts +16 -0
  263. package/script/src/jobs/format.d.ts.map +1 -0
  264. package/script/src/jobs/format.js +193 -0
  265. package/script/src/jobs/http.d.ts +22 -0
  266. package/script/src/jobs/http.d.ts.map +1 -0
  267. package/script/src/jobs/http.js +50 -0
  268. package/script/src/jobs/log.d.ts +2 -0
  269. package/script/src/jobs/log.d.ts.map +1 -0
  270. package/script/src/jobs/log.js +13 -0
  271. package/script/src/jobs/mod.d.ts +10 -0
  272. package/script/src/jobs/mod.d.ts.map +1 -0
  273. package/script/src/jobs/mod.js +25 -0
  274. package/script/src/jobs/run.d.ts +20 -0
  275. package/script/src/jobs/run.d.ts.map +1 -0
  276. package/script/src/jobs/run.js +61 -0
  277. package/script/src/jobs/types.d.ts +31 -0
  278. package/script/src/jobs/types.d.ts.map +1 -0
  279. package/script/src/jobs/types.js +2 -0
  280. package/script/src/mui/apiKeys.d.ts +65 -0
  281. package/script/src/mui/apiKeys.d.ts.map +1 -0
  282. package/script/src/mui/apiKeys.js +327 -0
  283. package/script/src/mui/apiKeysView.d.ts +48 -0
  284. package/script/src/mui/apiKeysView.d.ts.map +1 -0
  285. package/script/src/mui/apiKeysView.js +40 -0
  286. package/script/src/mui/confirm.d.ts +12 -0
  287. package/script/src/mui/confirm.d.ts.map +1 -0
  288. package/script/src/mui/confirm.js +85 -0
  289. package/script/src/mui/mod.d.ts +4 -0
  290. package/script/src/mui/mod.d.ts.map +1 -0
  291. package/script/src/mui/mod.js +19 -0
  292. package/script/src/next/apiKeys/mod.d.ts +64 -0
  293. package/script/src/next/apiKeys/mod.d.ts.map +1 -0
  294. package/script/src/next/apiKeys/mod.js +224 -0
  295. package/script/src/next/auth/config.d.ts +34 -0
  296. package/script/src/next/auth/config.d.ts.map +1 -0
  297. package/script/src/next/auth/config.js +142 -0
  298. package/script/src/next/auth/mod.d.ts +3 -0
  299. package/script/src/next/auth/mod.d.ts.map +1 -0
  300. package/script/src/next/auth/mod.js +18 -0
  301. package/script/src/next/auth/server.d.ts +28 -0
  302. package/script/src/next/auth/server.d.ts.map +1 -0
  303. package/script/src/next/auth/server.js +27 -0
  304. package/script/src/next/files/mod.d.ts +3 -0
  305. package/script/src/next/files/mod.d.ts.map +1 -0
  306. package/script/src/next/files/mod.js +18 -0
  307. package/script/src/next/files/route.d.ts +99 -0
  308. package/script/src/next/files/route.d.ts.map +1 -0
  309. package/script/src/next/files/route.js +353 -0
  310. package/script/src/next/jobs/list.d.ts +25 -0
  311. package/script/src/next/jobs/list.d.ts.map +1 -0
  312. package/script/src/next/jobs/list.js +48 -0
  313. package/script/src/next/jobs/mod.d.ts +6 -0
  314. package/script/src/next/jobs/mod.d.ts.map +1 -0
  315. package/script/src/next/jobs/mod.js +21 -0
  316. package/script/src/next/jobs/paths.d.ts +14 -0
  317. package/script/src/next/jobs/paths.d.ts.map +1 -0
  318. package/script/src/next/jobs/paths.js +47 -0
  319. package/script/src/next/jobs/route.d.ts +48 -0
  320. package/script/src/next/jobs/route.d.ts.map +1 -0
  321. package/script/src/next/jobs/route.js +105 -0
  322. package/script/src/next/jobs/run.d.ts +51 -0
  323. package/script/src/next/jobs/run.d.ts.map +1 -0
  324. package/script/src/next/jobs/run.js +570 -0
  325. package/script/src/next/jobs/stream.d.ts +3 -0
  326. package/script/src/next/jobs/stream.d.ts.map +1 -0
  327. package/script/src/next/jobs/stream.js +28 -0
  328. package/script/src/next/pwa/mod.d.ts +104 -0
  329. package/script/src/next/pwa/mod.d.ts.map +1 -0
  330. package/script/src/next/pwa/mod.js +192 -0
  331. package/script/src/next/pwa/worker.d.ts +27 -0
  332. package/script/src/next/pwa/worker.d.ts.map +1 -0
  333. package/script/src/next/pwa/worker.js +33 -0
  334. package/skills/loom/SKILL.md +200 -0
  335. package/skills/loom-api-keys/SKILL.md +123 -0
  336. package/skills/loom-auth/SKILL.md +70 -0
  337. package/skills/loom-db/SKILL.md +94 -0
  338. package/skills/loom-db/references/db-stack.md +39 -0
  339. package/skills/loom-files/SKILL.md +97 -0
  340. package/skills/loom-jobs/SKILL.md +148 -0
  341. package/skills/upgrade-deps/SKILL.md +165 -0
  342. package/skills/upgrade-deps/agents/openai.yaml +4 -0
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeApiKeyCountryCode = normalizeApiKeyCountryCode;
4
+ /** Normalizes a two-letter ISO country-code candidate for audit storage. */
5
+ function normalizeApiKeyCountryCode(value) {
6
+ const countryCode = value?.trim().toUpperCase();
7
+ return countryCode && /^[A-Z]{2}$/.test(countryCode)
8
+ ? countryCode
9
+ : undefined;
10
+ }
@@ -0,0 +1,4 @@
1
+ import type { ApiKeyCredentialExtractionResult, ApiKeyCredentialOptions, ApiKeyCredentialSource } from "./types.js";
2
+ /** Extracts exactly one API-key credential without selecting a precedence. */
3
+ export declare function extractApiKeyCredential(source: ApiKeyCredentialSource, options?: ApiKeyCredentialOptions): ApiKeyCredentialExtractionResult;
4
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gCAAgC,EAChC,uBAAuB,EACvB,sBAAsB,EAEvB,MAAM,YAAY,CAAC;AAgCpB,8EAA8E;AAC9E,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE,uBAA4B,GACpC,gCAAgC,CAwClC"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractApiKeyCredential = extractApiKeyCredential;
4
+ const DEFAULT_QUERY_NAME = "apiKey";
5
+ const DEFAULT_X_API_KEY_HEADER = "x-api-key";
6
+ function bearerCandidate(headers) {
7
+ const value = headers.get("authorization");
8
+ if (value === null)
9
+ return null;
10
+ const match = /^Bearer ([^\s]+)$/.exec(value);
11
+ return match
12
+ ? { credential: match[1], transport: "authorization-bearer" }
13
+ : { malformed: true, transport: "authorization-bearer" };
14
+ }
15
+ function valueCandidate(value, transport) {
16
+ if (value === null)
17
+ return null;
18
+ if (value.trim() === "" || value !== value.trim()) {
19
+ return { malformed: true, transport };
20
+ }
21
+ return { credential: value, transport };
22
+ }
23
+ /** Extracts exactly one API-key credential without selecting a precedence. */
24
+ function extractApiKeyCredential(source, options = {}) {
25
+ const candidates = [];
26
+ if (options.allowAuthorizationBearer !== false) {
27
+ const candidate = bearerCandidate(source.headers);
28
+ if (candidate)
29
+ candidates.push(candidate);
30
+ }
31
+ if (options.allowXApiKey !== false) {
32
+ const candidate = valueCandidate(source.headers.get(options.xApiKeyHeaderName ?? DEFAULT_X_API_KEY_HEADER), "x-api-key");
33
+ if (candidate)
34
+ candidates.push(candidate);
35
+ }
36
+ if (options.allowQuery === true) {
37
+ const candidate = valueCandidate(source.searchParams?.get(options.queryName ?? DEFAULT_QUERY_NAME) ?? null, "query");
38
+ if (candidate)
39
+ candidates.push(candidate);
40
+ }
41
+ if (candidates.length === 0)
42
+ return { kind: "missing" };
43
+ if (candidates.length > 1) {
44
+ return {
45
+ kind: "ambiguous",
46
+ transports: candidates.map((candidate) => candidate.transport),
47
+ };
48
+ }
49
+ const candidate = candidates[0];
50
+ if (candidate.malformed || candidate.credential === undefined) {
51
+ return { kind: "malformed", transport: candidate.transport };
52
+ }
53
+ return {
54
+ credential: candidate.credential,
55
+ kind: "present",
56
+ transport: candidate.transport,
57
+ };
58
+ }
@@ -0,0 +1,3 @@
1
+ /** Produces a lowercase SHA-256 fingerprint without retaining the credential. */
2
+ export declare function fingerprintApiKeyCredential(credential: string): Promise<string>;
3
+ //# sourceMappingURL=fingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/fingerprint.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,wBAAsB,2BAA2B,CAAC,UAAU,EAAE,MAAM,mBASnE"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fingerprintApiKeyCredential = fingerprintApiKeyCredential;
4
+ /** Produces a lowercase SHA-256 fingerprint without retaining the credential. */
5
+ async function fingerprintApiKeyCredential(credential) {
6
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(credential));
7
+ return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("");
8
+ }
@@ -0,0 +1,9 @@
1
+ import "../../_dnt.polyfills.js";
2
+ export * from "./authorize.js";
3
+ export * from "./country.js";
4
+ export * from "./credentials.js";
5
+ export * from "./fingerprint.js";
6
+ export * from "./policy.js";
7
+ export * from "./retention.js";
8
+ export * from "./types.js";
9
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/mod.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ require("../../_dnt.polyfills.js");
18
+ __exportStar(require("./authorize.js"), exports);
19
+ __exportStar(require("./country.js"), exports);
20
+ __exportStar(require("./credentials.js"), exports);
21
+ __exportStar(require("./fingerprint.js"), exports);
22
+ __exportStar(require("./policy.js"), exports);
23
+ __exportStar(require("./retention.js"), exports);
24
+ __exportStar(require("./types.js"), exports);
@@ -0,0 +1,59 @@
1
+ import type { ApiKeyAuthorizationDescriptor, ApiKeyPermission, ApiKeyPolicy, ApiKeyPolicyResult, ApiKeyPrincipal } from "./types.js";
2
+ /** Minimum shape for one app-owned API-key scope definition. */
3
+ export interface ApiKeyScopeDefinition {
4
+ /** Native resource/action permission stored and verified by the auth provider. */
5
+ permission: ApiKeyPermission;
6
+ }
7
+ export type ApiKeyScopeDefinitions = Readonly<Record<string, ApiKeyScopeDefinition>>;
8
+ type ApiKeyScopeId<TDefinitions extends ApiKeyScopeDefinitions> = Extract<keyof TDefinitions, string>;
9
+ /** A scope definition projected into a list with its record key as `id`. */
10
+ export type ApiKeyScopeListItem<TDefinitions extends ApiKeyScopeDefinitions> = {
11
+ [TId in ApiKeyScopeId<TDefinitions>]: Readonly<{
12
+ id: TId;
13
+ } & TDefinitions[TId]>;
14
+ }[ApiKeyScopeId<TDefinitions>];
15
+ /** Typed projections derived from one app-owned scope definition record. */
16
+ export interface DefinedApiKeyScopes<TDefinitions extends ApiKeyScopeDefinitions> {
17
+ /** Original definitions indexed by stable app-owned scope ID. */
18
+ readonly byId: TDefinitions;
19
+ /** Stable scope IDs in definition order. */
20
+ readonly ids: readonly ApiKeyScopeId<TDefinitions>[];
21
+ /** Definitions in UI-friendly list form with an added `id`. */
22
+ readonly list: readonly ApiKeyScopeListItem<TDefinitions>[];
23
+ /** Native permissions indexed by stable app-owned scope ID. */
24
+ readonly permissions: {
25
+ readonly [TId in ApiKeyScopeId<TDefinitions>]: TDefinitions[TId]["permission"];
26
+ };
27
+ }
28
+ /** Context supplied to an app-owned dynamic policy rule. */
29
+ export interface ApiKeyPolicyRuleContext {
30
+ /** Protected operation and exact permission requested by the route. */
31
+ descriptor: ApiKeyAuthorizationDescriptor;
32
+ /** Explicit key principal returned by the consumer verifier. */
33
+ principal: ApiKeyPrincipal;
34
+ }
35
+ /** A static decision or fresh app-owned eligibility check for one scope. */
36
+ export type ApiKeyPolicyRule = "allow" | "deny" | ((context: ApiKeyPolicyRuleContext) => ApiKeyPolicyResult | Promise<ApiKeyPolicyResult>);
37
+ /** Exhaustive policy rules keyed by the registry's stable scope IDs. */
38
+ export type ApiKeyPolicyRules<TDefinitions extends ApiKeyScopeDefinitions> = {
39
+ readonly [TId in ApiKeyScopeId<TDefinitions>]: ApiKeyPolicyRule;
40
+ };
41
+ /**
42
+ * Defines one app's scopes and derives typed list and permission projections.
43
+ *
44
+ * Scope IDs and native resource/action pairs should remain stable after keys
45
+ * have been issued. Duplicate pairs are rejected because policy dispatch would
46
+ * otherwise be ambiguous.
47
+ */
48
+ export declare function defineApiKeyScopes<const TDefinitions extends ApiKeyScopeDefinitions>(definitions: TDefinitions): DefinedApiKeyScopes<TDefinitions>;
49
+ /**
50
+ * Creates an exact-match, default-deny policy from a typed scope registry.
51
+ *
52
+ * The verifier remains responsible for proving that the key owns the requested
53
+ * native permission. Dynamic rules are for fresh app-owned checks such as
54
+ * current role membership; thrown errors intentionally reach Loom's existing
55
+ * `policy_error` handling.
56
+ */
57
+ export declare function createApiKeyPolicy<const TDefinitions extends ApiKeyScopeDefinitions>(registry: DefinedApiKeyScopes<TDefinitions>, rules: ApiKeyPolicyRules<TDefinitions>): ApiKeyPolicy;
58
+ export {};
59
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EAChB,MAAM,YAAY,CAAC;AAEpB,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IACpC,kFAAkF;IAClF,UAAU,EAAE,gBAAgB,CAAC;CAC9B;AAED,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CACtC,CAAC;AAEF,KAAK,aAAa,CAAC,YAAY,SAAS,sBAAsB,IAAI,OAAO,CACvE,MAAM,YAAY,EAClB,MAAM,CACP,CAAC;AAEF,4EAA4E;AAC5E,MAAM,MAAM,mBAAmB,CAC7B,YAAY,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AE,YAAY,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAkB9D;AAsBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,CAAC,YAAY,SAAS,sBAAsB,EAEjD,QAAQ,EAAE,mBAAmB,CAAC,YAAY,CAAC,EAC3C,KAAK,EAAE,iBAAiB,CAAC,YAAY,CAAC,GACrC,YAAY,CAiBd"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineApiKeyScopes = defineApiKeyScopes;
4
+ exports.createApiKeyPolicy = createApiKeyPolicy;
5
+ function permissionKey(permission) {
6
+ return JSON.stringify([permission.resource, permission.action]);
7
+ }
8
+ function assertPermission(scopeId, permission) {
9
+ for (const field of ["resource", "action"]) {
10
+ const value = permission[field];
11
+ if (typeof value !== "string" ||
12
+ value.length === 0 ||
13
+ value !== value.trim()) {
14
+ throw new Error(`API-key scope "${scopeId}" has an invalid permission ${field}.`);
15
+ }
16
+ }
17
+ }
18
+ function indexScopePermissions(definitions) {
19
+ const scopeIdByPermission = new Map();
20
+ for (const scopeId of Object.keys(definitions)) {
21
+ const permission = definitions[scopeId].permission;
22
+ assertPermission(scopeId, permission);
23
+ const key = permissionKey(permission);
24
+ const existing = scopeIdByPermission.get(key);
25
+ if (existing !== undefined) {
26
+ throw new Error(`API-key scopes "${existing}" and "${scopeId}" use the same permission.`);
27
+ }
28
+ scopeIdByPermission.set(key, scopeId);
29
+ }
30
+ return scopeIdByPermission;
31
+ }
32
+ /**
33
+ * Defines one app's scopes and derives typed list and permission projections.
34
+ *
35
+ * Scope IDs and native resource/action pairs should remain stable after keys
36
+ * have been issued. Duplicate pairs are rejected because policy dispatch would
37
+ * otherwise be ambiguous.
38
+ */
39
+ function defineApiKeyScopes(definitions) {
40
+ const ids = Object.keys(definitions);
41
+ if (ids.length === 0) {
42
+ throw new Error("Define at least one API-key scope.");
43
+ }
44
+ indexScopePermissions(definitions);
45
+ const list = ids.map((id) => ({
46
+ ...definitions[id],
47
+ id,
48
+ }));
49
+ const permissions = Object.fromEntries(ids.map((id) => [id, definitions[id].permission]));
50
+ return { byId: definitions, ids, list, permissions };
51
+ }
52
+ function assertPolicyRules(registry, rules) {
53
+ const scopeIds = new Set(registry.ids);
54
+ for (const scopeId of registry.ids) {
55
+ if (!Object.prototype.hasOwnProperty.call(rules, scopeId)) {
56
+ throw new Error(`Missing API-key policy rule for scope "${scopeId}".`);
57
+ }
58
+ }
59
+ for (const [scopeId, rule] of Object.entries(rules)) {
60
+ if (!scopeIds.has(scopeId)) {
61
+ throw new Error(`Unknown API-key policy rule scope "${scopeId}".`);
62
+ }
63
+ if (rule !== "allow" && rule !== "deny" && typeof rule !== "function") {
64
+ throw new Error(`Invalid API-key policy rule for scope "${scopeId}".`);
65
+ }
66
+ }
67
+ }
68
+ /**
69
+ * Creates an exact-match, default-deny policy from a typed scope registry.
70
+ *
71
+ * The verifier remains responsible for proving that the key owns the requested
72
+ * native permission. Dynamic rules are for fresh app-owned checks such as
73
+ * current role membership; thrown errors intentionally reach Loom's existing
74
+ * `policy_error` handling.
75
+ */
76
+ function createApiKeyPolicy(registry, rules) {
77
+ const scopeIdByPermission = indexScopePermissions(registry.byId);
78
+ assertPolicyRules(registry, rules);
79
+ return {
80
+ async authorize(principal, descriptor) {
81
+ const scopeId = scopeIdByPermission.get(permissionKey(descriptor.permission));
82
+ if (scopeId === undefined)
83
+ return { ok: false, code: "forbidden" };
84
+ const rule = rules[scopeId];
85
+ if (rule === "allow")
86
+ return { ok: true };
87
+ if (rule === "deny")
88
+ return { ok: false, code: "forbidden" };
89
+ return await rule({ descriptor, principal });
90
+ },
91
+ };
92
+ }
@@ -0,0 +1,55 @@
1
+ export declare const DEFAULT_API_KEY_AUDIT_RETENTION: Readonly<{
2
+ cleanupBatchSize: 1000;
3
+ maxAgeDays: 180;
4
+ maxRequestsPerKey: 5000;
5
+ }>;
6
+ /** Bounded retention for API-key request groups. */
7
+ export interface ApiKeyAuditRetentionPolicy {
8
+ /** Maximum authorization request groups deleted in one transaction. */
9
+ cleanupBatchSize: number;
10
+ /** Maximum age of all events, including denials without an attributed key. */
11
+ maxAgeDays: number;
12
+ /** Maximum authorization request groups retained for each attributed key. */
13
+ maxRequestsPerKey: number;
14
+ }
15
+ export interface ApiKeyAuditPruneBatchRequest {
16
+ /** Delete request groups older than this instant before applying the key cap. */
17
+ cutoffOccurredAt: string;
18
+ maxRequestsPerKey: number;
19
+ requestBatchSize: number;
20
+ }
21
+ export interface ApiKeyAuditPruneBatchResult {
22
+ /** Number of physical authorization and completion rows deleted. */
23
+ deletedEvents: number;
24
+ /** Number of authorization request groups deleted. */
25
+ deletedRequests: number;
26
+ /** Whether another batch currently qualifies for the same policy. */
27
+ hasMore: boolean;
28
+ }
29
+ /**
30
+ * App-owned transactional deletion for API-key audit retention.
31
+ * Implementations must delete an authorization event and its completion event
32
+ * together, retain the newest request groups when enforcing the per-key cap,
33
+ * and apply the age cutoff to unattributed denials.
34
+ */
35
+ export interface ApiKeyAuditRetentionRepository {
36
+ pruneBatch(request: ApiKeyAuditPruneBatchRequest): Promise<ApiKeyAuditPruneBatchResult>;
37
+ }
38
+ export interface ApiKeyAuditRetentionResult {
39
+ batches: number;
40
+ complete: boolean;
41
+ cutoffOccurredAt: string;
42
+ deletedEvents: number;
43
+ deletedRequests: number;
44
+ }
45
+ /** Validates overrides and fills the recommended general-purpose defaults. */
46
+ export declare function createApiKeyAuditRetentionPolicy(overrides?: Partial<ApiKeyAuditRetentionPolicy>): ApiKeyAuditRetentionPolicy;
47
+ /** Runs bounded retention batches without coupling Loom to an app database. */
48
+ export declare function runApiKeyAuditRetention(options: {
49
+ /** Safety bound for one scheduled invocation; defaults to 100 batches. */
50
+ maxBatches?: number;
51
+ now?: Date;
52
+ policy?: Partial<ApiKeyAuditRetentionPolicy>;
53
+ repository: ApiKeyAuditRetentionRepository;
54
+ }): Promise<ApiKeyAuditRetentionResult>;
55
+ //# sourceMappingURL=retention.d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AO,CAAC,0BAA0B,CAAC,CAAC;IAC7C,UAAU,EAAE,8BAA8B,CAAC;CAC5C,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAyCtC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_API_KEY_AUDIT_RETENTION = void 0;
4
+ exports.createApiKeyAuditRetentionPolicy = createApiKeyAuditRetentionPolicy;
5
+ exports.runApiKeyAuditRetention = runApiKeyAuditRetention;
6
+ exports.DEFAULT_API_KEY_AUDIT_RETENTION = Object.freeze({
7
+ cleanupBatchSize: 1_000,
8
+ maxAgeDays: 180,
9
+ maxRequestsPerKey: 5_000,
10
+ });
11
+ function positiveInteger(value, name) {
12
+ if (!Number.isSafeInteger(value) || value < 1) {
13
+ throw new TypeError(`${name} must be a positive safe integer.`);
14
+ }
15
+ return value;
16
+ }
17
+ /** Validates overrides and fills the recommended general-purpose defaults. */
18
+ function createApiKeyAuditRetentionPolicy(overrides = {}) {
19
+ return {
20
+ cleanupBatchSize: positiveInteger(overrides.cleanupBatchSize ??
21
+ exports.DEFAULT_API_KEY_AUDIT_RETENTION.cleanupBatchSize, "cleanupBatchSize"),
22
+ maxAgeDays: positiveInteger(overrides.maxAgeDays ?? exports.DEFAULT_API_KEY_AUDIT_RETENTION.maxAgeDays, "maxAgeDays"),
23
+ maxRequestsPerKey: positiveInteger(overrides.maxRequestsPerKey ??
24
+ exports.DEFAULT_API_KEY_AUDIT_RETENTION.maxRequestsPerKey, "maxRequestsPerKey"),
25
+ };
26
+ }
27
+ /** Runs bounded retention batches without coupling Loom to an app database. */
28
+ async function runApiKeyAuditRetention(options) {
29
+ const policy = createApiKeyAuditRetentionPolicy(options.policy);
30
+ const maxBatches = positiveInteger(options.maxBatches ?? 100, "maxBatches");
31
+ const now = options.now ?? new Date();
32
+ if (Number.isNaN(now.valueOf())) {
33
+ throw new TypeError("now must be a valid Date.");
34
+ }
35
+ const cutoffOccurredAt = new Date(now.valueOf() - policy.maxAgeDays * 24 * 60 * 60 * 1_000).toISOString();
36
+ let deletedEvents = 0;
37
+ let deletedRequests = 0;
38
+ for (let batches = 1; batches <= maxBatches; batches++) {
39
+ const batch = await options.repository.pruneBatch({
40
+ cutoffOccurredAt,
41
+ maxRequestsPerKey: policy.maxRequestsPerKey,
42
+ requestBatchSize: policy.cleanupBatchSize,
43
+ });
44
+ positiveIntegerOrZero(batch.deletedEvents, "deletedEvents");
45
+ positiveIntegerOrZero(batch.deletedRequests, "deletedRequests");
46
+ deletedEvents += batch.deletedEvents;
47
+ deletedRequests += batch.deletedRequests;
48
+ if (!batch.hasMore) {
49
+ return {
50
+ batches,
51
+ complete: true,
52
+ cutoffOccurredAt,
53
+ deletedEvents,
54
+ deletedRequests,
55
+ };
56
+ }
57
+ }
58
+ return {
59
+ batches: maxBatches,
60
+ complete: false,
61
+ cutoffOccurredAt,
62
+ deletedEvents,
63
+ deletedRequests,
64
+ };
65
+ }
66
+ function positiveIntegerOrZero(value, name) {
67
+ if (!Number.isSafeInteger(value) || value < 0) {
68
+ throw new TypeError(`${name} must be a non-negative safe integer.`);
69
+ }
70
+ }
@@ -0,0 +1,175 @@
1
+ /** A single resource/action permission required by a protected operation. */
2
+ export interface ApiKeyPermission {
3
+ action: string;
4
+ resource: string;
5
+ }
6
+ /** The explicit identity returned by an app-owned API-key verifier. */
7
+ export interface ApiKeyPrincipal {
8
+ keyId: string;
9
+ keyName?: string;
10
+ keyStart?: string;
11
+ ownerId: string;
12
+ permissions: ApiKeyPermission[];
13
+ }
14
+ export type ApiKeyCredentialTransport = "authorization-bearer" | "x-api-key" | "query";
15
+ export type ApiKeyCredentialExtractionResult = {
16
+ kind: "missing";
17
+ } | {
18
+ kind: "malformed";
19
+ transport: ApiKeyCredentialTransport;
20
+ } | {
21
+ kind: "ambiguous";
22
+ transports: ApiKeyCredentialTransport[];
23
+ } | {
24
+ credential: string;
25
+ kind: "present";
26
+ transport: ApiKeyCredentialTransport;
27
+ };
28
+ export interface ApiKeyCredentialOptions {
29
+ allowAuthorizationBearer?: boolean;
30
+ allowQuery?: boolean;
31
+ allowXApiKey?: boolean;
32
+ queryName?: string;
33
+ xApiKeyHeaderName?: string;
34
+ }
35
+ export interface ApiKeyCredentialSource {
36
+ headers: Headers;
37
+ searchParams?: URLSearchParams;
38
+ }
39
+ export type ApiKeyDenialCode = "ambiguous_credentials" | "audit_unavailable" | "credential_malformed" | "credential_missing" | "forbidden" | "insufficient_permission" | "invalid_credential" | "policy_error" | "rate_limited" | "verification_error";
40
+ export interface ApiKeyAuthorizationDescriptor {
41
+ actionName?: string;
42
+ functionName?: string;
43
+ metadata?: Record<string, unknown>;
44
+ operation: string;
45
+ pageName?: string;
46
+ permission: ApiKeyPermission;
47
+ }
48
+ export interface ApiKeyRequestAuditContext {
49
+ /** ISO 3166-1 alpha-2 country snapshot resolved from the originating IP. */
50
+ countryCode?: string;
51
+ ipAddress?: string;
52
+ method?: string;
53
+ requestId?: string;
54
+ routeTemplate?: string;
55
+ userAgent?: string;
56
+ }
57
+ export type ApiKeyAuthorizationOutcome = "allowed" | "denied" | "error";
58
+ export type ApiKeyOperationOutcome = "succeeded" | "failed" | "unknown";
59
+ export interface ApiKeyAuthorizationAuditEvent {
60
+ actionName?: string;
61
+ authorizationOutcome: ApiKeyAuthorizationOutcome;
62
+ credentialFingerprint?: string;
63
+ countryCode?: string;
64
+ eventType: "authorization";
65
+ functionName?: string;
66
+ httpStatus?: number;
67
+ ipAddress?: string;
68
+ keyId?: string;
69
+ keyNameSnapshot?: string;
70
+ keyStartSnapshot?: string;
71
+ metadata?: Record<string, unknown>;
72
+ method?: string;
73
+ operation: string;
74
+ ownerId?: string;
75
+ pageName?: string;
76
+ reasonCode?: ApiKeyDenialCode;
77
+ requestId?: string;
78
+ routeTemplate?: string;
79
+ scopeAction: string;
80
+ scopeResource: string;
81
+ transport?: ApiKeyCredentialTransport;
82
+ userAgent?: string;
83
+ }
84
+ /** App-owned IP geolocation resolver; implementations should not use request-time network calls. */
85
+ export type ApiKeyCountryResolver = (ipAddress: string) => string | null | undefined | Promise<string | null | undefined>;
86
+ export interface ApiKeyCompletionAuditEvent {
87
+ actionName?: string;
88
+ authorizationEventId: string;
89
+ durationMs?: number;
90
+ eventType: "completion";
91
+ functionName?: string;
92
+ httpStatus?: number;
93
+ keyId: string;
94
+ keyNameSnapshot?: string;
95
+ keyStartSnapshot?: string;
96
+ metadata?: Record<string, unknown>;
97
+ operation: string;
98
+ operationOutcome: ApiKeyOperationOutcome;
99
+ ownerId: string;
100
+ pageName?: string;
101
+ reasonCode?: string;
102
+ requestId?: string;
103
+ scopeAction: string;
104
+ scopeResource: string;
105
+ }
106
+ export type ApiKeyAuditEvent = ApiKeyAuthorizationAuditEvent | ApiKeyCompletionAuditEvent;
107
+ export interface ApiKeyAuditPageRequest {
108
+ cursor?: string;
109
+ keyId?: string;
110
+ limit: number;
111
+ ownerId?: string;
112
+ }
113
+ export interface ApiKeyAuditPage {
114
+ events: Array<ApiKeyAuditEvent & {
115
+ id: string;
116
+ occurredAt: string;
117
+ }>;
118
+ nextCursor?: string;
119
+ }
120
+ /** App-owned persistence for immutable API-key audit events. */
121
+ export interface ApiKeyAuditRepository {
122
+ append(event: ApiKeyAuditEvent): Promise<{
123
+ id: string;
124
+ }>;
125
+ list?(request: ApiKeyAuditPageRequest): Promise<ApiKeyAuditPage>;
126
+ }
127
+ export interface ApiKeyVerifierRequest {
128
+ credential: string;
129
+ permission: ApiKeyPermission;
130
+ }
131
+ export type ApiKeyVerifierResult = {
132
+ ok: true;
133
+ principal: ApiKeyPrincipal;
134
+ } | {
135
+ code: "insufficient_permission" | "invalid_credential" | "rate_limited";
136
+ ok: false;
137
+ status?: 401 | 403 | 429;
138
+ };
139
+ /** App adapter that performs exactly one verification call per authorization. */
140
+ export interface ApiKeyVerifier {
141
+ verify(request: ApiKeyVerifierRequest): Promise<ApiKeyVerifierResult>;
142
+ }
143
+ export type ApiKeyPolicyResult = {
144
+ ok: true;
145
+ } | {
146
+ code?: "forbidden";
147
+ ok: false;
148
+ status?: 403;
149
+ };
150
+ /** Fresh app-owned eligibility checks, such as current admin membership. */
151
+ export interface ApiKeyPolicy {
152
+ authorize(principal: ApiKeyPrincipal, descriptor: ApiKeyAuthorizationDescriptor): Promise<ApiKeyPolicyResult>;
153
+ }
154
+ export type ApiKeyAuthorizationResult = {
155
+ authorizationEventId: string;
156
+ credentialFingerprint: string;
157
+ ok: true;
158
+ principal: ApiKeyPrincipal;
159
+ transport: ApiKeyCredentialTransport;
160
+ } | {
161
+ authorizationEventId?: string;
162
+ code: ApiKeyDenialCode;
163
+ ok: false;
164
+ status: 400 | 401 | 403 | 429 | 500 | 503;
165
+ };
166
+ export interface AuthorizeApiKeyOptions {
167
+ audit: ApiKeyAuditRepository;
168
+ credentialOptions?: ApiKeyCredentialOptions;
169
+ descriptor: ApiKeyAuthorizationDescriptor;
170
+ policy: ApiKeyPolicy;
171
+ request?: ApiKeyRequestAuditContext;
172
+ source: ApiKeyCredentialSource;
173
+ verifier: ApiKeyVerifier;
174
+ }
175
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/src/apiKeys/types.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,gBAAgB,EAAE,CAAC;CACjC;AAED,MAAM,MAAM,yBAAyB,GACjC,sBAAsB,GACtB,WAAW,GACX,OAAO,CAAC;AAEZ,MAAM,MAAM,gCAAgC,GACxC;IAAE,IAAI,E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AAE,KAAK,CAAC;IACV,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAC3C,CAAC;AAEJ,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,qBAAqB,CAAC;IAC7B,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C,UAAU,EAAE,6BAA6B,CAAC;IAC1C,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,EAAE,yBAAyB,CAAC;IACpC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,QAAQ,EAAE,cAAc,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,39 @@
1
+ type PackageJson = {
2
+ dependencies?: Record<string, string>;
3
+ devDependencies?: Record<string, string>;
4
+ packageManager?: string;
5
+ };
6
+ /** License evidence recorded without redistributing the upstream skill. */
7
+ export type ExternalSkillLicense = {
8
+ evidenceUrl?: string;
9
+ spdx?: string;
10
+ status: "missing" | "restricted" | "unknown" | "verified";
11
+ };
12
+ /** Immutable upstream source identity and reviewed content digest. */
13
+ export type ExternalSkillSource = {
14
+ contentHash: string;
15
+ ref: string;
16
+ repositoryUrl: string;
17
+ revision: string;
18
+ sourcePath: string;
19
+ };
20
+ type ExternalSkillRule = {
21
+ description: string;
22
+ dependencyAnyOf?: string[];
23
+ dependencyPrefixAnyOf?: string[];
24
+ featureAnyOf?: string[];
25
+ license: ExternalSkillLicense;
26
+ skillName: string;
27
+ source: ExternalSkillSource;
28
+ sourceLabel: string;
29
+ sourceUrl: string;
30
+ usesPnpm?: boolean;
31
+ };
32
+ /** Public metadata for one externally installed skill. */
33
+ export type ExternalSkill = Omit<ExternalSkillRule, "dependencyAnyOf" | "dependencyPrefixAnyOf" | "featureAnyOf" | "usesPnpm">;
34
+ /** Selects catalog skills applicable to the current project's dependencies. */
35
+ export declare function getRecommendedExternalSkills(packageJson: PackageJson, activeFeatureKeys: Set<string>, hasPnpmLock: boolean): ExternalSkill[];
36
+ /** Returns the complete metadata-only external skill catalog. */
37
+ export declare function getAllExternalSkills(): ExternalSkill[];
38
+ export {};
39
+ //# sourceMappingURL=externalSkills.d.ts.map