@vibe-agent-toolkit/utils 0.1.42 → 0.2.0-rc.10

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 (279) hide show
  1. package/README.md +81 -19
  2. package/dist/asset-reference.js +3 -11
  3. package/dist/asset-reference.js.map +1 -1
  4. package/dist/compare-code-units.d.ts +28 -0
  5. package/dist/compare-code-units.d.ts.map +1 -0
  6. package/dist/compare-code-units.js +33 -0
  7. package/dist/compare-code-units.js.map +1 -0
  8. package/dist/crawl-timing.d.ts +657 -0
  9. package/dist/crawl-timing.d.ts.map +1 -0
  10. package/dist/crawl-timing.js +765 -0
  11. package/dist/crawl-timing.js.map +1 -0
  12. package/dist/crawl.d.ts +2 -4
  13. package/dist/crawl.d.ts.map +1 -1
  14. package/dist/crawl.js +2 -4
  15. package/dist/crawl.js.map +1 -1
  16. package/dist/dirent-kind.d.ts +83 -0
  17. package/dist/dirent-kind.d.ts.map +1 -0
  18. package/dist/dirent-kind.js +129 -0
  19. package/dist/dirent-kind.js.map +1 -0
  20. package/dist/entrypoint.d.ts +54 -0
  21. package/dist/entrypoint.d.ts.map +1 -0
  22. package/dist/entrypoint.js +71 -0
  23. package/dist/entrypoint.js.map +1 -0
  24. package/dist/env-flag.d.ts +51 -0
  25. package/dist/env-flag.d.ts.map +1 -0
  26. package/dist/env-flag.js +62 -0
  27. package/dist/env-flag.js.map +1 -0
  28. package/dist/errors/errno.d.ts +51 -0
  29. package/dist/errors/errno.d.ts.map +1 -0
  30. package/dist/errors/errno.js +112 -0
  31. package/dist/errors/errno.js.map +1 -0
  32. package/dist/errors/vat-error.d.ts +60 -0
  33. package/dist/errors/vat-error.d.ts.map +1 -0
  34. package/dist/errors/vat-error.js +86 -0
  35. package/dist/errors/vat-error.js.map +1 -0
  36. package/dist/file-crawler.d.ts +60 -0
  37. package/dist/file-crawler.d.ts.map +1 -1
  38. package/dist/file-crawler.js +214 -24
  39. package/dist/file-crawler.js.map +1 -1
  40. package/dist/fs/file-hash.d.ts.map +1 -1
  41. package/dist/fs/file-hash.js +0 -1
  42. package/dist/fs/file-hash.js.map +1 -1
  43. package/dist/fs-utils.d.ts +628 -38
  44. package/dist/fs-utils.d.ts.map +1 -1
  45. package/dist/fs-utils.js +770 -71
  46. package/dist/fs-utils.js.map +1 -1
  47. package/dist/fs.d.ts +5 -1
  48. package/dist/fs.d.ts.map +1 -1
  49. package/dist/fs.js +9 -1
  50. package/dist/fs.js.map +1 -1
  51. package/dist/git-root-cache.d.ts +44 -0
  52. package/dist/git-root-cache.d.ts.map +1 -0
  53. package/dist/git-root-cache.js +68 -0
  54. package/dist/git-root-cache.js.map +1 -0
  55. package/dist/git-run.d.ts +167 -0
  56. package/dist/git-run.d.ts.map +1 -0
  57. package/dist/git-run.js +154 -0
  58. package/dist/git-run.js.map +1 -0
  59. package/dist/git-snapshot.d.ts +199 -0
  60. package/dist/git-snapshot.d.ts.map +1 -0
  61. package/dist/git-snapshot.js +250 -0
  62. package/dist/git-snapshot.js.map +1 -0
  63. package/dist/git-tracker.d.ts +166 -3
  64. package/dist/git-tracker.d.ts.map +1 -1
  65. package/dist/git-tracker.js +250 -22
  66. package/dist/git-tracker.js.map +1 -1
  67. package/dist/git-utils.d.ts +95 -1
  68. package/dist/git-utils.d.ts.map +1 -1
  69. package/dist/git-utils.js +227 -81
  70. package/dist/git-utils.js.map +1 -1
  71. package/dist/git.d.ts +13 -4
  72. package/dist/git.d.ts.map +1 -1
  73. package/dist/git.js +12 -4
  74. package/dist/git.js.map +1 -1
  75. package/dist/gitignore-checker.d.ts.map +1 -1
  76. package/dist/gitignore-checker.js +15 -6
  77. package/dist/gitignore-checker.js.map +1 -1
  78. package/dist/glob/glob-pattern.js +5 -5
  79. package/dist/glob/glob-pattern.js.map +1 -1
  80. package/dist/index.d.ts +33 -19
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +113 -33
  83. package/dist/index.js.map +1 -1
  84. package/dist/listing-refusal.d.ts +112 -0
  85. package/dist/listing-refusal.d.ts.map +1 -0
  86. package/dist/listing-refusal.js +105 -0
  87. package/dist/listing-refusal.js.map +1 -0
  88. package/dist/numeric-args.d.ts +24 -0
  89. package/dist/numeric-args.d.ts.map +1 -0
  90. package/dist/numeric-args.js +37 -0
  91. package/dist/numeric-args.js.map +1 -0
  92. package/dist/path-containment.d.ts +64 -0
  93. package/dist/path-containment.d.ts.map +1 -0
  94. package/dist/path-containment.js +111 -0
  95. package/dist/path-containment.js.map +1 -0
  96. package/dist/path-core.d.ts +143 -18
  97. package/dist/path-core.d.ts.map +1 -1
  98. package/dist/path-core.js +171 -23
  99. package/dist/path-core.js.map +1 -1
  100. package/dist/path-utils.d.ts.map +1 -1
  101. package/dist/path-utils.js +42 -47
  102. package/dist/path-utils.js.map +1 -1
  103. package/dist/path.d.ts +1 -1
  104. package/dist/path.d.ts.map +1 -1
  105. package/dist/path.js +1 -1
  106. package/dist/path.js.map +1 -1
  107. package/dist/process.d.ts +7 -0
  108. package/dist/process.d.ts.map +1 -1
  109. package/dist/process.js +7 -0
  110. package/dist/process.js.map +1 -1
  111. package/dist/project-utils.d.ts +7 -1
  112. package/dist/project-utils.d.ts.map +1 -1
  113. package/dist/project-utils.js +24 -10
  114. package/dist/project-utils.js.map +1 -1
  115. package/dist/project.d.ts +7 -5
  116. package/dist/project.d.ts.map +1 -1
  117. package/dist/project.js +7 -5
  118. package/dist/project.js.map +1 -1
  119. package/dist/safe-exec.d.ts +40 -11
  120. package/dist/safe-exec.d.ts.map +1 -1
  121. package/dist/safe-exec.js +111 -25
  122. package/dist/safe-exec.js.map +1 -1
  123. package/dist/skill-targets.d.ts +2 -2
  124. package/dist/skill-targets.js +2 -2
  125. package/dist/skill-test/auth-resolver.d.ts +10 -2
  126. package/dist/skill-test/auth-resolver.d.ts.map +1 -1
  127. package/dist/skill-test/auth-resolver.js +26 -11
  128. package/dist/skill-test/auth-resolver.js.map +1 -1
  129. package/dist/skill-test/index.d.ts +1 -1
  130. package/dist/skill-test/index.d.ts.map +1 -1
  131. package/dist/skill-test/index.js +1 -1
  132. package/dist/skill-test/index.js.map +1 -1
  133. package/dist/skill-test/spawn-claude.d.ts +30 -1
  134. package/dist/skill-test/spawn-claude.d.ts.map +1 -1
  135. package/dist/skill-test/spawn-claude.js +71 -5
  136. package/dist/skill-test/spawn-claude.js.map +1 -1
  137. package/dist/skill-test/transcript.d.ts +41 -2
  138. package/dist/skill-test/transcript.d.ts.map +1 -1
  139. package/dist/skill-test/transcript.js +55 -10
  140. package/dist/skill-test/transcript.js.map +1 -1
  141. package/dist/spawn-hardened.js +0 -1
  142. package/dist/spawn-hardened.js.map +1 -1
  143. package/dist/stdio-blocking.js +13 -14
  144. package/dist/stdio-blocking.js.map +1 -1
  145. package/dist/test-helpers.d.ts +130 -79
  146. package/dist/test-helpers.d.ts.map +1 -1
  147. package/dist/test-helpers.js +229 -124
  148. package/dist/test-helpers.js.map +1 -1
  149. package/dist/testing/executables.d.ts +32 -0
  150. package/dist/testing/executables.d.ts.map +1 -0
  151. package/dist/testing/executables.js +70 -0
  152. package/dist/testing/executables.js.map +1 -0
  153. package/dist/testing/hostile-tree.d.ts +79 -0
  154. package/dist/testing/hostile-tree.d.ts.map +1 -0
  155. package/dist/testing/hostile-tree.js +164 -0
  156. package/dist/testing/hostile-tree.js.map +1 -0
  157. package/dist/testing/platform-gates.d.ts +31 -0
  158. package/dist/testing/platform-gates.d.ts.map +1 -0
  159. package/dist/testing/platform-gates.js +31 -0
  160. package/dist/testing/platform-gates.js.map +1 -0
  161. package/dist/testing/temp-dir.d.ts +255 -0
  162. package/dist/testing/temp-dir.d.ts.map +1 -0
  163. package/dist/testing/temp-dir.js +363 -0
  164. package/dist/testing/temp-dir.js.map +1 -0
  165. package/dist/testing.d.ts +94 -3
  166. package/dist/testing.d.ts.map +1 -1
  167. package/dist/testing.js +119 -3
  168. package/dist/testing.js.map +1 -1
  169. package/dist/text-content.d.ts +197 -0
  170. package/dist/text-content.d.ts.map +1 -0
  171. package/dist/text-content.js +354 -0
  172. package/dist/text-content.js.map +1 -0
  173. package/dist/text-file.d.ts +45 -0
  174. package/dist/text-file.d.ts.map +1 -0
  175. package/dist/text-file.js +51 -0
  176. package/dist/text-file.js.map +1 -0
  177. package/dist/text.d.ts +16 -0
  178. package/dist/text.d.ts.map +1 -0
  179. package/dist/text.js +16 -0
  180. package/dist/text.js.map +1 -0
  181. package/dist/timing-dump.d.ts +136 -0
  182. package/dist/timing-dump.d.ts.map +1 -0
  183. package/dist/timing-dump.js +229 -0
  184. package/dist/timing-dump.js.map +1 -0
  185. package/dist/windows-shell.d.ts +0 -1
  186. package/dist/windows-shell.d.ts.map +1 -1
  187. package/dist/windows-shell.js +0 -1
  188. package/dist/windows-shell.js.map +1 -1
  189. package/dist/zod-introspection.js +2 -2
  190. package/dist/zod-introspection.js.map +1 -1
  191. package/eslint/README.md +224 -50
  192. package/eslint/index.cjs +111 -97
  193. package/eslint/index.d.cts +16 -6
  194. package/eslint/rules/callee-name.cjs +23 -0
  195. package/eslint/rules/commands-import-boundary.cjs +148 -0
  196. package/eslint/rules/dead-import.cjs +62 -12
  197. package/eslint/rules/dirent-type-needs-symlink-check.cjs +282 -0
  198. package/eslint/rules/eslint-rule-factory.cjs +21 -3
  199. package/eslint/rules/exempt-path-matcher.cjs +2 -1
  200. package/eslint/rules/explicit-zod-strictness.cjs +120 -0
  201. package/eslint/rules/no-bare-dynamic-import-path.cjs +5 -1
  202. package/eslint/rules/no-bare-executable-spawn.cjs +70 -0
  203. package/eslint/rules/no-bare-symlink-in-tests.cjs +213 -0
  204. package/eslint/rules/no-blind-catch.cjs +171 -0
  205. package/eslint/rules/no-child-process-execSync.cjs +8 -0
  206. package/eslint/rules/no-decaying-referent.cjs +217 -0
  207. package/eslint/rules/no-dotdot-containment.cjs +160 -0
  208. package/eslint/rules/no-file-url-string-concat.cjs +4 -1
  209. package/eslint/rules/no-fragile-entrypoint-guard.cjs +228 -0
  210. package/eslint/rules/no-fs-mkdirSync.cjs +8 -0
  211. package/eslint/rules/no-fs-promises-cp.cjs +7 -0
  212. package/eslint/rules/no-fs-realpathSync.cjs +8 -0
  213. package/eslint/rules/no-hardcoded-path-split.cjs +29 -18
  214. package/eslint/rules/no-io-in-unit-tier.cjs +129 -0
  215. package/eslint/rules/no-literal-process-exit.cjs +129 -0
  216. package/eslint/rules/no-manual-path-normalize.cjs +146 -96
  217. package/eslint/rules/no-os-tmpdir.cjs +8 -0
  218. package/eslint/rules/no-path-operations-in-comparisons.cjs +7 -2
  219. package/eslint/rules/no-path-sep-in-strings.cjs +7 -2
  220. package/eslint/rules/no-path-startswith.cjs +7 -2
  221. package/eslint/rules/no-process-exit-in-phase.cjs +127 -0
  222. package/eslint/rules/no-raw-node-path.cjs +563 -0
  223. package/eslint/rules/no-raw-text-decode.cjs +305 -0
  224. package/eslint/rules/no-registry-count-pin.cjs +255 -0
  225. package/eslint/rules/no-self-package-import.cjs +168 -0
  226. package/eslint/rules/no-test-scoped-functions.cjs +10 -3
  227. package/eslint/rules/no-unix-shell-commands.cjs +6 -2
  228. package/eslint/rules/no-unsafe-root-join.cjs +23 -2
  229. package/eslint/rules/no-url-pathname-for-fs.cjs +5 -1
  230. package/eslint/rules/no-version-literal.cjs +151 -0
  231. package/eslint/rules/prefer-startswith-over-regex.cjs +33 -1
  232. package/eslint/rules/require-justified-skip.cjs +8 -2
  233. package/eslint/rules/safe-import.cjs +1 -1
  234. package/package.json +16 -16
  235. package/dist/link-auth/build-headers.d.ts +0 -34
  236. package/dist/link-auth/build-headers.d.ts.map +0 -1
  237. package/dist/link-auth/build-headers.js +0 -58
  238. package/dist/link-auth/build-headers.js.map +0 -1
  239. package/dist/link-auth/expand-macro.d.ts +0 -38
  240. package/dist/link-auth/expand-macro.d.ts.map +0 -1
  241. package/dist/link-auth/expand-macro.js +0 -133
  242. package/dist/link-auth/expand-macro.js.map +0 -1
  243. package/dist/link-auth/macros.yaml +0 -50
  244. package/dist/link-auth/resolve-token.d.ts +0 -83
  245. package/dist/link-auth/resolve-token.d.ts.map +0 -1
  246. package/dist/link-auth/resolve-token.js +0 -101
  247. package/dist/link-auth/resolve-token.js.map +0 -1
  248. package/dist/link-auth/resolve.d.ts +0 -102
  249. package/dist/link-auth/resolve.d.ts.map +0 -1
  250. package/dist/link-auth/resolve.js +0 -66
  251. package/dist/link-auth/resolve.js.map +0 -1
  252. package/dist/link-auth/rewrite.d.ts +0 -52
  253. package/dist/link-auth/rewrite.d.ts.map +0 -1
  254. package/dist/link-auth/rewrite.js +0 -102
  255. package/dist/link-auth/rewrite.js.map +0 -1
  256. package/dist/link-auth/select-provider.d.ts +0 -30
  257. package/dist/link-auth/select-provider.d.ts.map +0 -1
  258. package/dist/link-auth/select-provider.js +0 -55
  259. package/dist/link-auth/select-provider.js.map +0 -1
  260. package/dist/link-auth/template.d.ts +0 -40
  261. package/dist/link-auth/template.d.ts.map +0 -1
  262. package/dist/link-auth/template.js +0 -89
  263. package/dist/link-auth/template.js.map +0 -1
  264. package/dist/link-auth/transforms.d.ts +0 -46
  265. package/dist/link-auth/transforms.d.ts.map +0 -1
  266. package/dist/link-auth/transforms.js +0 -52
  267. package/dist/link-auth/transforms.js.map +0 -1
  268. package/dist/template-entry.d.ts +0 -10
  269. package/dist/template-entry.d.ts.map +0 -1
  270. package/dist/template-entry.js +0 -10
  271. package/dist/template-entry.js.map +0 -1
  272. package/dist/template.d.ts +0 -7
  273. package/dist/template.d.ts.map +0 -1
  274. package/dist/template.js +0 -18
  275. package/dist/template.js.map +0 -1
  276. package/eslint/rules/no-path-join.cjs +0 -14
  277. package/eslint/rules/no-path-relative.cjs +0 -14
  278. package/eslint/rules/no-path-resolve.cjs +0 -14
  279. package/eslint/rules/path-function-rule-factory.cjs +0 -417
@@ -1,58 +0,0 @@
1
- /**
2
- * Render auth-header templates with rendered values, and a structural
3
- * redaction helper for serialization.
4
- *
5
- * `buildHeaders` renders each header value template against a context that
6
- * carries `${token}` plus any named captures / vars from the rewrite step.
7
- * `redactHeaders` masks `Authorization` values for any caller that needs to
8
- * serialize headers into logs, errors, or cache entries — the design's §8
9
- * "tokens never leak" claim depends on every such site routing through this.
10
- *
11
- * Per design issue #113 §4 (auth.headers vocabulary) and §8 (redaction is
12
- * structural; Authorization values never appear in serialized output).
13
- */
14
- import { renderTemplate } from './template.js';
15
- export const REDACTED_VALUE = '<redacted>';
16
- /**
17
- * Header names whose values must be masked when serialized.
18
- *
19
- * v1 ships only `authorization` because that is the only secret-bearing
20
- * header the current macros emit. **Omission is the security risk** — any
21
- * future macro that emits a header carrying a secret (`Cookie`,
22
- * `Proxy-Authorization`, `X-API-Key`, custom bearer-style headers) must add
23
- * that name here, or the token will silently leak through serialization.
24
- * Extending the set is not the dangerous edit; forgetting to extend it is.
25
- */
26
- const SENSITIVE_HEADER_NAMES = new Set(['authorization']);
27
- /**
28
- * Render a map of header templates into a map of concrete header values.
29
- *
30
- * @throws {TemplateMissingVarError} if a header template references an
31
- * unknown context key
32
- * @throws {TemplateSyntaxError} from a malformed template expression
33
- * @throws {UnknownTransformError} from a template calling an unknown transform
34
- */
35
- export function buildHeaders(templates, context) {
36
- const headers = Object.create(null);
37
- for (const [name, template] of Object.entries(templates)) {
38
- headers[name] = renderTemplate(template, context);
39
- }
40
- return headers;
41
- }
42
- /**
43
- * Return a copy of `headers` with sensitive values replaced by `REDACTED_VALUE`.
44
- * Header-name matching is case-insensitive but exact (no prefix matching) — a
45
- * header like `X-Authorization-Foo` is NOT considered sensitive.
46
- *
47
- * **Input must be a plain key-value object.** A `Headers` instance (Web Fetch
48
- * API) or a `Map` yields `[]` from `Object.entries` and would silently no-op
49
- * redaction — converting to a plain object is the caller's responsibility.
50
- */
51
- export function redactHeaders(headers) {
52
- const redacted = Object.create(null);
53
- for (const [name, value] of Object.entries(headers)) {
54
- redacted[name] = SENSITIVE_HEADER_NAMES.has(name.toLowerCase()) ? REDACTED_VALUE : value;
55
- }
56
- return redacted;
57
- }
58
- //# sourceMappingURL=build-headers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-headers.js","sourceRoot":"","sources":["../../src/link-auth/build-headers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAE3C;;;;;;;;;GASG;AACH,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAiC,EACjC,OAA+B;IAE/B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC;IAC9D,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,OAA+B;IAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC;IAC/D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACpD,QAAQ,CAAC,IAAI,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC;IAC3F,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,38 +0,0 @@
1
- /**
2
- * Macro loader + expander.
3
- *
4
- * Loads the bundled `macros.yaml` once at module init and exposes
5
- * `expandMacro(name, overrides?)` which deep-merges the named macro with any
6
- * adopter overrides. The merge is "adopter wins": objects merge recursively,
7
- * arrays and primitives are replaced wholesale (no element-wise array merge).
8
- *
9
- * The shipped macro file is at `link-auth/macros.yaml`, copied into the dist
10
- * tree by `packages/dev-tools/src/copy-yaml-assets.ts` during build so the
11
- * runtime `fs.readFileSync(new URL('./macros.yaml', import.meta.url))`
12
- * resolves in both source-mode (vitest) and built-mode (dist).
13
- *
14
- * Per design issue #113 §5 (macros are config, not a privileged code path).
15
- */
16
- /**
17
- * Thrown when a `use: <name>` references a macro not in the shipped set.
18
- * Message lists the available macros so a typo surfaces clearly.
19
- */
20
- export declare class UnknownMacroError extends Error {
21
- constructor(name: string, available: readonly string[]);
22
- }
23
- /**
24
- * Look up a macro by name and deep-merge optional adopter overrides on top.
25
- *
26
- * Merge semantics:
27
- * - Plain objects merge recursively (sibling keys preserved).
28
- * - Arrays are replaced wholesale (override's array wins; no concat).
29
- * - Primitives are replaced.
30
- * - `undefined` in an override is treated as "not provided" (base wins).
31
- *
32
- * The returned object and all nested plain objects use null prototypes so
33
- * `__proto__` / `constructor` keys can never poison consumers.
34
- *
35
- * @throws {UnknownMacroError} if `name` is not in the shipped macro set
36
- */
37
- export declare function expandMacro(name: string, overrides?: Record<string, unknown>): Record<string, unknown>;
38
- //# sourceMappingURL=expand-macro.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"expand-macro.d.ts","sourceRoot":"","sources":["../../src/link-auth/expand-macro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyCH;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE;CAIvD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB"}
@@ -1,133 +0,0 @@
1
- /**
2
- * Macro loader + expander.
3
- *
4
- * Loads the bundled `macros.yaml` once at module init and exposes
5
- * `expandMacro(name, overrides?)` which deep-merges the named macro with any
6
- * adopter overrides. The merge is "adopter wins": objects merge recursively,
7
- * arrays and primitives are replaced wholesale (no element-wise array merge).
8
- *
9
- * The shipped macro file is at `link-auth/macros.yaml`, copied into the dist
10
- * tree by `packages/dev-tools/src/copy-yaml-assets.ts` during build so the
11
- * runtime `fs.readFileSync(new URL('./macros.yaml', import.meta.url))`
12
- * resolves in both source-mode (vitest) and built-mode (dist).
13
- *
14
- * Per design issue #113 §5 (macros are config, not a privileged code path).
15
- */
16
- import { readFileSync } from 'node:fs';
17
- import { fileURLToPath } from 'node:url';
18
- import { parse as parseYaml } from 'yaml';
19
- let macrosCache;
20
- /**
21
- * Load macros lazily on first use rather than at module init.
22
- *
23
- * Why lazy: vitest tests elsewhere in the repo mock `node:fs` (replacing
24
- * `readFileSync` with `vi.fn()` that returns `undefined`). If we eagerly read
25
- * at module load, any unrelated test that imports `@vibe-agent-toolkit/utils`
26
- * and mocks fs crashes inside `parseYaml(undefined)` — module-init code runs
27
- * unconditionally, before the mock-setup intent reaches our file.
28
- *
29
- * Lazy load makes module import side-effect-free; only callers of
30
- * `expandMacro` pay the fs cost. `macrosPath` is also computed here (not at
31
- * module top level) so that merely importing this module leaves no `new URL()`
32
- * reference for bundler static analysis to trip over.
33
- */
34
- function getMacros() {
35
- if (macrosCache !== undefined)
36
- return macrosCache;
37
- // Path is derived from `import.meta.url`, not user input — points at the
38
- // shipped macros.yaml asset next to this module in both src and dist trees.
39
- const macrosPath = fileURLToPath(new URL('./macros.yaml', import.meta.url));
40
- // eslint-disable-next-line security/detect-non-literal-fs-filename
41
- const macrosFileContent = readFileSync(macrosPath, 'utf8');
42
- const parsed = parseYaml(macrosFileContent);
43
- if (!isPlainObject(parsed)) {
44
- throw new Error('macros.yaml: expected top-level object mapping macro name → provider config.');
45
- }
46
- macrosCache = freezeMacros(parsed);
47
- return macrosCache;
48
- }
49
- /**
50
- * Thrown when a `use: <name>` references a macro not in the shipped set.
51
- * Message lists the available macros so a typo surfaces clearly.
52
- */
53
- export class UnknownMacroError extends Error {
54
- constructor(name, available) {
55
- super(`Unknown macro "${name}". Available: ${available.join(', ')}.`);
56
- this.name = 'UnknownMacroError';
57
- }
58
- }
59
- /**
60
- * Look up a macro by name and deep-merge optional adopter overrides on top.
61
- *
62
- * Merge semantics:
63
- * - Plain objects merge recursively (sibling keys preserved).
64
- * - Arrays are replaced wholesale (override's array wins; no concat).
65
- * - Primitives are replaced.
66
- * - `undefined` in an override is treated as "not provided" (base wins).
67
- *
68
- * The returned object and all nested plain objects use null prototypes so
69
- * `__proto__` / `constructor` keys can never poison consumers.
70
- *
71
- * @throws {UnknownMacroError} if `name` is not in the shipped macro set
72
- */
73
- export function expandMacro(name, overrides) {
74
- const macros = getMacros();
75
- const base = macros[name];
76
- if (base === undefined) {
77
- throw new UnknownMacroError(name, Object.keys(macros));
78
- }
79
- if (overrides === undefined) {
80
- return cloneWithNullProto(base);
81
- }
82
- const merged = deepMerge(base, overrides);
83
- // Top-level result is guaranteed object here because base is.
84
- return merged;
85
- }
86
- function deepMerge(base, override) {
87
- if (override === undefined)
88
- return base;
89
- if (!isPlainObject(base) || !isPlainObject(override))
90
- return cloneValue(override);
91
- const result = Object.create(null);
92
- for (const [key, value] of Object.entries(base)) {
93
- result[key] = cloneValue(value);
94
- }
95
- for (const [key, value] of Object.entries(override)) {
96
- const existing = Object.hasOwn(result, key) ? result[key] : undefined;
97
- if (isPlainObject(existing) && isPlainObject(value)) {
98
- result[key] = deepMerge(existing, value);
99
- }
100
- else {
101
- result[key] = cloneValue(value);
102
- }
103
- }
104
- return result;
105
- }
106
- function cloneValue(value) {
107
- if (Array.isArray(value))
108
- return value.map(cloneValue);
109
- if (isPlainObject(value))
110
- return cloneWithNullProto(value);
111
- return value;
112
- }
113
- function cloneWithNullProto(obj) {
114
- const cloned = Object.create(null);
115
- for (const [key, value] of Object.entries(obj)) {
116
- cloned[key] = cloneValue(value);
117
- }
118
- return cloned;
119
- }
120
- function freezeMacros(parsed) {
121
- const frozen = Object.create(null);
122
- for (const [name, value] of Object.entries(parsed)) {
123
- if (!isPlainObject(value)) {
124
- throw new Error(`macros.yaml: macro "${name}" is not an object.`);
125
- }
126
- frozen[name] = cloneWithNullProto(value);
127
- }
128
- return frozen;
129
- }
130
- function isPlainObject(v) {
131
- return typeof v === 'object' && v !== null && !Array.isArray(v);
132
- }
133
- //# sourceMappingURL=expand-macro.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"expand-macro.js","sourceRoot":"","sources":["../../src/link-auth/expand-macro.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,IAAI,WAAgE,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,SAAS,SAAS;IAChB,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAElD,yEAAyE;IACzE,4EAA4E;IAC5E,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5E,mEAAmE;IACnE,MAAM,iBAAiB,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAY,CAAC;IAEvD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAClG,CAAC;IAED,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACnC,OAAO,WAAW,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C,IAAI,CAAC,CAAC;IAC5E,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,qBAAqB,CAAC,CAAC;QACpE,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -1,50 +0,0 @@
1
- # linkAuth provider macros — shipped defaults referenced by `use: <name>` in
2
- # adopter `vibe-agent-toolkit.config.yaml` files.
3
- #
4
- # Each entry is a full provider config in the §4 vocabulary (match, rewrite,
5
- # auth, token, check). Adopters reference a macro by name and may deep-merge
6
- # overrides on top — see design issue #113 §5.
7
- #
8
- # Adding a new host is intended to be a config-only PR: append an entry here
9
- # and add unit tests. Only `vocabulary` changes (e.g. a new transform) require
10
- # engine code.
11
-
12
- github:
13
- match:
14
- host: github.com
15
- rewrite:
16
- - when: '^https://github\.com/(?<owner>[^/]+)/(?<repo>[^/]+)/(?:blob|tree)/(?<ref>[^/]+)/(?<path>.+)$'
17
- to: 'https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${ref}'
18
- auth:
19
- headers:
20
- Authorization: 'Bearer ${token}'
21
- Accept: application/vnd.github+json
22
- token:
23
- - command: gh auth token
24
- - env: GITHUB_TOKEN
25
- check:
26
- method: GET
27
- aliveStatus: [200]
28
- notFoundMeaning: ambiguous
29
-
30
- sharepoint:
31
- match:
32
- host: '*.sharepoint.com'
33
- excludeHost:
34
- - '*-my.sharepoint.com'
35
- rewrite:
36
- - when: '^(?<u>https://.+)$'
37
- vars:
38
- shareId: 'u!${base64url(u)}'
39
- to: 'https://graph.microsoft.com/v1.0/shares/${shareId}/driveItem'
40
- auth:
41
- headers:
42
- Authorization: 'Bearer ${token}'
43
- # SharePoint has no zero-config token source (design §5.1 note): a SharePoint-
44
- # scoped token requires an Entra app registration; the stock `az` token does
45
- # not work. Adopter must supply their own token command.
46
- token: []
47
- check:
48
- method: GET
49
- aliveStatus: [200]
50
- notFoundMeaning: dead
@@ -1,83 +0,0 @@
1
- /**
2
- * Token resolution — ordered, first-non-empty-wins.
3
- *
4
- * Iterates a provider's `token` source list and returns the first source that
5
- * yields a non-empty value. Two source shapes:
6
- * - `{ env: "NAME" }` — read from process env (no trimming)
7
- * - `{ command: argv }` — run a command, return trimmed stdout
8
- * - `{ command: "gh auth token" }` — convenience: whitespace-tokenized into
9
- * argv. **Not** passed through a shell — operators (`|`, `&&`, `$(...)`)
10
- * become literal argv elements, per the design's §6.1 sharp-edge note.
11
- *
12
- * Command sources can be disabled at runtime with `VAT_LINKAUTH_ALLOW_COMMAND=0`
13
- * (or by passing `allowCommand: false` in deps). Useful in security-sensitive
14
- * environments where arbitrary command execution is undesirable.
15
- *
16
- * Returns `undefined` if every source fails or yields an empty/whitespace
17
- * value — the caller's `resolveAuthenticatedUrl` translates that to the
18
- * `unverified` outcome (surfaced as `LINK_AUTH_UNVERIFIED` by the validator).
19
- *
20
- * Per design issue #113 §4 (token vocabulary) and §6.1 (command execution,
21
- * `safeExecSync`-backed, `shell: false`).
22
- */
23
- export type TokenSource = {
24
- readonly env: string;
25
- } | {
26
- readonly command: string | readonly string[];
27
- };
28
- export interface TokenResolutionDeps {
29
- /**
30
- * Environment lookup map. Defaults to `process.env`. Injectable for tests so
31
- * unit tests don't depend on ambient environment state.
32
- */
33
- readonly env: Record<string, string | undefined>;
34
- /**
35
- * Command runner. Defaults to `safeExecResult`-wrapped invocation. Injectable
36
- * for tests. Receives argv; returns `success` + `stdout`. Should NOT throw
37
- * for normal exec failures (return `success: false` instead). Throws are
38
- * propagated by `resolveToken` — they indicate operator-level bugs.
39
- */
40
- readonly runCommand: (argv: readonly string[]) => {
41
- success: boolean;
42
- stdout: string;
43
- };
44
- /**
45
- * Whether `{ command: ... }` sources are allowed. Defaults to reading
46
- * `VAT_LINKAUTH_ALLOW_COMMAND` from the resolved `env` map (not ambient
47
- * `process.env`), so a caller supplying a curated `deps.env` can control the
48
- * flag without touching real process state. Set to `false` (or set
49
- * `VAT_LINKAUTH_ALLOW_COMMAND=0` in the env) to skip all command sources and
50
- * rely solely on env-var sources — useful in locked-down CI or security reviews.
51
- */
52
- readonly allowCommand: boolean;
53
- }
54
- /**
55
- * Return a copy of the given env with all `GIT_*` keys removed. Case-insensitive
56
- * on the key so Windows env vars (which are case-insensitive at the OS level,
57
- * though `process.env` preserves original case) can't sneak through as e.g.
58
- * `Git_Dir`.
59
- *
60
- * Exported for unit testing and for callers assembling their own `runCommand`
61
- * who want the exact same scrub `defaultRunCommand` applies.
62
- *
63
- * Rationale: `vat resources validate` is often invoked from git pre-commit
64
- * hooks, which pre-set `GIT_DIR` / `GIT_WORK_TREE` / `GIT_INDEX_FILE`. These
65
- * poison any nested tool that shells out to git, notably `gh auth token`.
66
- */
67
- export declare function scrubGitEnv(source: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
68
- /**
69
- * Default `runCommand` implementation — exported so callers that want to
70
- * memoize per-validate-run can wrap it without duplicating the spawn logic.
71
- * Forwards to `safeExecResult` (no shell, argv-based), with `GIT_*` vars
72
- * stripped from the child env — see {@link scrubGitEnv}.
73
- */
74
- export declare const defaultRunCommand: TokenResolutionDeps['runCommand'];
75
- /**
76
- * Resolve a token from an ordered list of sources.
77
- *
78
- * @returns the first non-empty value, or `undefined` if every source failed.
79
- * @throws whatever the injected `runCommand` throws (operator-level bug; not
80
- * swallowed). Standard `safeExecResult` does not throw under normal use.
81
- */
82
- export declare function resolveToken(sources: readonly TokenSource[], deps?: Partial<TokenResolutionDeps>): string | undefined;
83
- //# sourceMappingURL=resolve-token.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-token.d.ts","sourceRoot":"","sources":["../../src/link-auth/resolve-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEtG,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAEvF;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAIxE;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,mBAAmB,CAAC,YAAY,CAO/D,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,IAAI,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAClC,MAAM,GAAG,SAAS,CAWpB"}
@@ -1,101 +0,0 @@
1
- /**
2
- * Token resolution — ordered, first-non-empty-wins.
3
- *
4
- * Iterates a provider's `token` source list and returns the first source that
5
- * yields a non-empty value. Two source shapes:
6
- * - `{ env: "NAME" }` — read from process env (no trimming)
7
- * - `{ command: argv }` — run a command, return trimmed stdout
8
- * - `{ command: "gh auth token" }` — convenience: whitespace-tokenized into
9
- * argv. **Not** passed through a shell — operators (`|`, `&&`, `$(...)`)
10
- * become literal argv elements, per the design's §6.1 sharp-edge note.
11
- *
12
- * Command sources can be disabled at runtime with `VAT_LINKAUTH_ALLOW_COMMAND=0`
13
- * (or by passing `allowCommand: false` in deps). Useful in security-sensitive
14
- * environments where arbitrary command execution is undesirable.
15
- *
16
- * Returns `undefined` if every source fails or yields an empty/whitespace
17
- * value — the caller's `resolveAuthenticatedUrl` translates that to the
18
- * `unverified` outcome (surfaced as `LINK_AUTH_UNVERIFIED` by the validator).
19
- *
20
- * Per design issue #113 §4 (token vocabulary) and §6.1 (command execution,
21
- * `safeExecSync`-backed, `shell: false`).
22
- */
23
- import { safeExecResult } from '../safe-exec.js';
24
- /**
25
- * Return a copy of the given env with all `GIT_*` keys removed. Case-insensitive
26
- * on the key so Windows env vars (which are case-insensitive at the OS level,
27
- * though `process.env` preserves original case) can't sneak through as e.g.
28
- * `Git_Dir`.
29
- *
30
- * Exported for unit testing and for callers assembling their own `runCommand`
31
- * who want the exact same scrub `defaultRunCommand` applies.
32
- *
33
- * Rationale: `vat resources validate` is often invoked from git pre-commit
34
- * hooks, which pre-set `GIT_DIR` / `GIT_WORK_TREE` / `GIT_INDEX_FILE`. These
35
- * poison any nested tool that shells out to git, notably `gh auth token`.
36
- */
37
- export function scrubGitEnv(source) {
38
- return Object.fromEntries(Object.entries(source).filter(([k]) => !k.toUpperCase().startsWith('GIT_')));
39
- }
40
- /**
41
- * Default `runCommand` implementation — exported so callers that want to
42
- * memoize per-validate-run can wrap it without duplicating the spawn logic.
43
- * Forwards to `safeExecResult` (no shell, argv-based), with `GIT_*` vars
44
- * stripped from the child env — see {@link scrubGitEnv}.
45
- */
46
- export const defaultRunCommand = (argv) => {
47
- if (argv.length === 0)
48
- return { success: false, stdout: '' };
49
- const [bin, ...args] = argv;
50
- if (bin === undefined)
51
- return { success: false, stdout: '' };
52
- const result = safeExecResult(bin, [...args], { encoding: 'utf8', env: scrubGitEnv(process.env) });
53
- const stdout = typeof result.stdout === 'string' ? result.stdout : result.stdout.toString('utf8');
54
- return { success: result.success, stdout };
55
- };
56
- /**
57
- * Resolve a token from an ordered list of sources.
58
- *
59
- * @returns the first non-empty value, or `undefined` if every source failed.
60
- * @throws whatever the injected `runCommand` throws (operator-level bug; not
61
- * swallowed). Standard `safeExecResult` does not throw under normal use.
62
- */
63
- export function resolveToken(sources, deps) {
64
- const env = deps?.env ?? process.env;
65
- const runCommand = deps?.runCommand ?? defaultRunCommand;
66
- const allowCommand = deps?.allowCommand ?? (env['VAT_LINKAUTH_ALLOW_COMMAND'] !== '0');
67
- for (const source of sources) {
68
- if (!allowCommand && 'command' in source)
69
- continue;
70
- const value = tryResolveSource(source, env, runCommand);
71
- if (value !== undefined && value.length > 0)
72
- return value;
73
- }
74
- return undefined;
75
- }
76
- function tryResolveSource(source, env, runCommand) {
77
- if ('env' in source) {
78
- // Object.hasOwn defends against env names like "__proto__" returning
79
- // Object.prototype via the prototype chain.
80
- if (!Object.hasOwn(env, source.env))
81
- return undefined;
82
- return env[source.env];
83
- }
84
- const argv = toArgv(source.command);
85
- if (argv.length === 0)
86
- return undefined;
87
- const result = runCommand(argv);
88
- if (!result.success)
89
- return undefined;
90
- const trimmed = result.stdout.trim();
91
- return trimmed.length === 0 ? undefined : trimmed;
92
- }
93
- function toArgv(command) {
94
- if (Array.isArray(command))
95
- return command;
96
- // Whitespace-tokenize the string form. Empty segments (from multiple spaces)
97
- // are filtered. Shell operators ('|', '&&', etc.) become literal argv, NOT
98
- // pipes — see design §6.1.
99
- return command.split(/\s+/).filter((s) => s.length > 0);
100
- }
101
- //# sourceMappingURL=resolve-token.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-token.js","sourceRoot":"","sources":["../../src/link-auth/resolve-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GA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CAAC,CAAC,CAAC,OAAO,CAAC;AACpD,CAAC;AAED,SAAS,MAAM,CAAC,OAAmC;IACjD,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC3C,6EAA6E;IAC7E,2EAA2E;IAC3E,2BAA2B;IAC3B,OAAQ,OAAkB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACtE,CAAC"}
@@ -1,102 +0,0 @@
1
- /**
2
- * Public API for the linkAuth pure engine.
3
- *
4
- * `resolveAuthenticatedUrl(url, config)` is the single entry point per design
5
- * §6: select the first provider whose `match.host` claims the URL, run its
6
- * rewrite pipeline, resolve a token, build the auth headers, and return
7
- * everything the caller needs to issue an authenticated fetch.
8
- *
9
- * Three outcomes:
10
- * - `{ fetchUrl, headers }` — ready to fetch (provider claimed,
11
- * rewrite matched, token resolved)
12
- * - `{ outcome: 'unsupported' }` — no provider claims the host, OR
13
- * host matched but no rewrite did
14
- * (per §4: "the provider does not
15
- * claim the URL for rewriting")
16
- * - `{ outcome: 'unverified', reason }` — claimed and rewrote, but no token
17
- * source resolved a non-empty value
18
- *
19
- * Per design issue #113 §6.
20
- */
21
- import { type TokenResolutionDeps, type TokenSource } from './resolve-token.js';
22
- import { type RewriteRule } from './rewrite.js';
23
- import { type ProviderMatch } from './select-provider.js';
24
- export interface ProviderAuth {
25
- readonly headers: Record<string, string>;
26
- }
27
- /**
28
- * Optional content-fetch header overrides (design issue #113 §6.2).
29
- *
30
- * Health-check and content retrieval often need different `Accept` (or other)
31
- * headers. The canonical example: GitHub's `application/vnd.github+json`
32
- * returns 200 for any size but omits bytes >1 MiB, while
33
- * `application/vnd.github.raw` streams the bytes inline. The provider declares
34
- * `auth.headers` for health-check and an optional `fetch.headers` for content
35
- * retrieval. Both are templated against the same context (URL captures + token).
36
- */
37
- export interface ProviderFetch {
38
- readonly headers: Record<string, string>;
39
- }
40
- export interface ProviderCheck {
41
- readonly method: 'GET' | 'HEAD';
42
- readonly aliveStatus: readonly number[];
43
- readonly notFoundMeaning: 'ambiguous' | 'dead';
44
- }
45
- export interface Provider {
46
- readonly match: ProviderMatch;
47
- readonly rewrite: readonly RewriteRule[];
48
- readonly auth: ProviderAuth;
49
- /**
50
- * Optional — present when a provider needs different headers for content
51
- * retrieval than for health-check. Absent for hosts where one header set
52
- * does both jobs.
53
- */
54
- readonly fetch?: ProviderFetch;
55
- readonly token: readonly TokenSource[];
56
- readonly check: ProviderCheck;
57
- }
58
- export interface LinkAuthConfig {
59
- readonly providers: readonly Provider[];
60
- /**
61
- * Optional content-cache config (consumed by the slice-3 content-fetch
62
- * primitive, not by the engine itself). The engine stays stateless; this
63
- * field rides along on the config object so the primitive doesn't need a
64
- * second source of truth.
65
- */
66
- readonly cache?: {
67
- readonly ttlMinutes?: number;
68
- };
69
- }
70
- export type ResolveOutcome = {
71
- readonly fetchUrl: string;
72
- readonly headers: Record<string, string>;
73
- /**
74
- * Expanded fetch-mode headers, only present when the provider declared
75
- * a `fetch` block. Templated against the same context as `headers`
76
- * (URL captures + resolved token), so callers do not need to re-resolve
77
- * the token to send these. Per §6.2 — content-fetch consumers send
78
- * these instead of (or merged over) `headers` for the request body.
79
- */
80
- readonly fetchHeaders?: Record<string, string>;
81
- /**
82
- * The matched provider's `check` block, passed through so the post-fetch
83
- * classifier (in `packages/resources`) can route status codes to outcomes
84
- * without re-running `selectProvider`. Reading this from the engine —
85
- * rather than asking the validator to re-derive it — keeps the
86
- * provider-match decision in exactly one place.
87
- */
88
- readonly check: ProviderCheck;
89
- } | {
90
- readonly outcome: 'unsupported';
91
- } | {
92
- readonly outcome: 'unverified';
93
- readonly reason: string;
94
- };
95
- /**
96
- * Resolve an authenticated fetch plan for `url` against the configured providers.
97
- *
98
- * @param deps - Optional dependency injection for token resolution (`env` map
99
- * + `runCommand`). Production callers omit this; tests supply mocks.
100
- */
101
- export declare function resolveAuthenticatedUrl(url: string, config: LinkAuthConfig, deps?: Partial<TokenResolutionDeps>): ResolveOutcome;
102
- //# sourceMappingURL=resolve.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/link-auth/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,sBAAsB,CAAC;AAE1E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,QAAQ,CAAC,eAAe,EAAE,WAAW,GAAG,MAAM,CAAC;CAChD;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,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