@vibe-agent-toolkit/utils 0.2.0-rc.2 → 0.2.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -15
- package/dist/compare-code-units.d.ts +28 -0
- package/dist/compare-code-units.d.ts.map +1 -0
- package/dist/compare-code-units.js +33 -0
- package/dist/compare-code-units.js.map +1 -0
- package/dist/crawl-timing.d.ts +657 -0
- package/dist/crawl-timing.d.ts.map +1 -0
- package/dist/crawl-timing.js +765 -0
- package/dist/crawl-timing.js.map +1 -0
- package/dist/crawl.d.ts +2 -4
- package/dist/crawl.d.ts.map +1 -1
- package/dist/crawl.js +2 -4
- package/dist/crawl.js.map +1 -1
- package/dist/file-crawler.d.ts +22 -0
- package/dist/file-crawler.d.ts.map +1 -1
- package/dist/file-crawler.js +31 -7
- package/dist/file-crawler.js.map +1 -1
- package/dist/fs-utils.d.ts +17 -0
- package/dist/fs-utils.d.ts.map +1 -1
- package/dist/fs-utils.js +69 -0
- package/dist/fs-utils.js.map +1 -1
- package/dist/fs.d.ts +3 -1
- package/dist/fs.d.ts.map +1 -1
- package/dist/fs.js +5 -1
- package/dist/fs.js.map +1 -1
- package/dist/git-run.d.ts +167 -0
- package/dist/git-run.d.ts.map +1 -0
- package/dist/git-run.js +154 -0
- package/dist/git-run.js.map +1 -0
- package/dist/git-snapshot.d.ts +181 -0
- package/dist/git-snapshot.d.ts.map +1 -0
- package/dist/git-snapshot.js +232 -0
- package/dist/git-snapshot.js.map +1 -0
- package/dist/git-tracker.d.ts +94 -1
- package/dist/git-tracker.d.ts.map +1 -1
- package/dist/git-tracker.js +135 -3
- package/dist/git-tracker.js.map +1 -1
- package/dist/git-utils.d.ts +38 -0
- package/dist/git-utils.d.ts.map +1 -1
- package/dist/git-utils.js +103 -80
- package/dist/git-utils.js.map +1 -1
- package/dist/git.d.ts +12 -4
- package/dist/git.d.ts.map +1 -1
- package/dist/git.js +12 -4
- package/dist/git.js.map +1 -1
- package/dist/gitignore-checker.d.ts.map +1 -1
- package/dist/gitignore-checker.js +6 -3
- package/dist/gitignore-checker.js.map +1 -1
- package/dist/index.d.ts +24 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -30
- package/dist/index.js.map +1 -1
- package/dist/path-core.d.ts +1 -1
- package/dist/path-core.js +1 -1
- package/dist/project-utils.d.ts.map +1 -1
- package/dist/project-utils.js +6 -3
- package/dist/project-utils.js.map +1 -1
- package/dist/project.d.ts +7 -5
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +7 -5
- package/dist/project.js.map +1 -1
- package/dist/safe-exec.d.ts +38 -10
- package/dist/safe-exec.d.ts.map +1 -1
- package/dist/safe-exec.js +88 -19
- package/dist/safe-exec.js.map +1 -1
- package/dist/skill-test/index.d.ts +1 -1
- package/dist/skill-test/index.d.ts.map +1 -1
- package/dist/skill-test/index.js +1 -1
- package/dist/skill-test/index.js.map +1 -1
- package/dist/skill-test/spawn-claude.d.ts +28 -0
- package/dist/skill-test/spawn-claude.d.ts.map +1 -1
- package/dist/skill-test/spawn-claude.js +51 -2
- package/dist/skill-test/spawn-claude.js.map +1 -1
- package/dist/skill-test/transcript.d.ts +41 -2
- package/dist/skill-test/transcript.d.ts.map +1 -1
- package/dist/skill-test/transcript.js +47 -3
- package/dist/skill-test/transcript.js.map +1 -1
- package/dist/test-helpers.d.ts +185 -13
- package/dist/test-helpers.d.ts.map +1 -1
- package/dist/test-helpers.js +274 -27
- package/dist/test-helpers.js.map +1 -1
- package/dist/testing.d.ts +73 -3
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +93 -3
- package/dist/testing.js.map +1 -1
- package/dist/text-content.d.ts +197 -0
- package/dist/text-content.d.ts.map +1 -0
- package/dist/text-content.js +348 -0
- package/dist/text-content.js.map +1 -0
- package/dist/text-file.d.ts +45 -0
- package/dist/text-file.d.ts.map +1 -0
- package/dist/text-file.js +53 -0
- package/dist/text-file.js.map +1 -0
- package/dist/text.d.ts +16 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +16 -0
- package/dist/text.js.map +1 -0
- package/dist/timing-dump.d.ts +136 -0
- package/dist/timing-dump.d.ts.map +1 -0
- package/dist/timing-dump.js +230 -0
- package/dist/timing-dump.js.map +1 -0
- package/eslint/README.md +105 -3
- package/eslint/index.cjs +50 -0
- package/eslint/index.d.cts +14 -4
- package/eslint/rules/no-bare-symlink-in-tests.cjs +200 -0
- package/eslint/rules/no-process-exit-in-phase.cjs +117 -0
- package/eslint/rules/no-raw-text-decode.cjs +296 -0
- package/eslint/rules/no-self-package-import.cjs +157 -0
- package/package.json +13 -8
- package/dist/link-auth/build-headers.d.ts +0 -34
- package/dist/link-auth/build-headers.d.ts.map +0 -1
- package/dist/link-auth/build-headers.js +0 -58
- package/dist/link-auth/build-headers.js.map +0 -1
- package/dist/link-auth/expand-macro.d.ts +0 -38
- package/dist/link-auth/expand-macro.d.ts.map +0 -1
- package/dist/link-auth/expand-macro.js +0 -133
- package/dist/link-auth/expand-macro.js.map +0 -1
- package/dist/link-auth/macros.yaml +0 -50
- package/dist/link-auth/resolve-token.d.ts +0 -83
- package/dist/link-auth/resolve-token.d.ts.map +0 -1
- package/dist/link-auth/resolve-token.js +0 -101
- package/dist/link-auth/resolve-token.js.map +0 -1
- package/dist/link-auth/resolve.d.ts +0 -102
- package/dist/link-auth/resolve.d.ts.map +0 -1
- package/dist/link-auth/resolve.js +0 -66
- package/dist/link-auth/resolve.js.map +0 -1
- package/dist/link-auth/rewrite.d.ts +0 -52
- package/dist/link-auth/rewrite.d.ts.map +0 -1
- package/dist/link-auth/rewrite.js +0 -102
- package/dist/link-auth/rewrite.js.map +0 -1
- package/dist/link-auth/select-provider.d.ts +0 -30
- package/dist/link-auth/select-provider.d.ts.map +0 -1
- package/dist/link-auth/select-provider.js +0 -55
- package/dist/link-auth/select-provider.js.map +0 -1
- package/dist/link-auth/template.d.ts +0 -40
- package/dist/link-auth/template.d.ts.map +0 -1
- package/dist/link-auth/template.js +0 -89
- package/dist/link-auth/template.js.map +0 -1
- package/dist/link-auth/transforms.d.ts +0 -46
- package/dist/link-auth/transforms.d.ts.map +0 -1
- package/dist/link-auth/transforms.js +0 -52
- package/dist/link-auth/transforms.js.map +0 -1
- package/dist/template-entry.d.ts +0 -10
- package/dist/template-entry.d.ts.map +0 -1
- package/dist/template-entry.js +0 -10
- package/dist/template-entry.js.map +0 -1
- package/dist/template.d.ts +0 -7
- package/dist/template.d.ts.map +0 -1
- package/dist/template.js +0 -18
- package/dist/template.js.map +0 -1
|
@@ -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
|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S,CAAC;IACtC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACrC,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,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":[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E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B,GACD;IAAE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;CAAE,GACnC;IAAE,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,IAAI,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAClC,cAAc,CAqChB"}
|
|
@@ -1,66 +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 { buildHeaders } from './build-headers.js';
|
|
22
|
-
import { resolveToken, } from './resolve-token.js';
|
|
23
|
-
import { rewriteUrl } from './rewrite.js';
|
|
24
|
-
import { selectProvider } from './select-provider.js';
|
|
25
|
-
/**
|
|
26
|
-
* Resolve an authenticated fetch plan for `url` against the configured providers.
|
|
27
|
-
*
|
|
28
|
-
* @param deps - Optional dependency injection for token resolution (`env` map
|
|
29
|
-
* + `runCommand`). Production callers omit this; tests supply mocks.
|
|
30
|
-
*/
|
|
31
|
-
export function resolveAuthenticatedUrl(url, config, deps) {
|
|
32
|
-
const provider = selectProvider(url, config.providers);
|
|
33
|
-
if (provider === undefined)
|
|
34
|
-
return { outcome: 'unsupported' };
|
|
35
|
-
const rewrite = rewriteUrl(url, provider.rewrite);
|
|
36
|
-
if (!rewrite.matched)
|
|
37
|
-
return { outcome: 'unsupported' };
|
|
38
|
-
const token = resolveToken(provider.token, deps);
|
|
39
|
-
// eslint-disable-next-line security/detect-possible-timing-attacks -- compare to undefined sentinel, not secret content
|
|
40
|
-
if (token === undefined) {
|
|
41
|
-
return {
|
|
42
|
-
outcome: 'unverified',
|
|
43
|
-
reason: 'No token source resolved a non-empty value — configure `token` or log in.',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// Headers see captures + vars + the resolved token. The resolved token wins
|
|
47
|
-
// over any regex capture named "token" (later in Object.assign wins), so
|
|
48
|
-
// URL-derived data never leaks into Authorization values.
|
|
49
|
-
const headerContext = Object.create(null);
|
|
50
|
-
Object.assign(headerContext, rewrite.context);
|
|
51
|
-
headerContext['token'] = token;
|
|
52
|
-
const headers = buildHeaders(provider.auth.headers, headerContext);
|
|
53
|
-
// Expand fetch.headers against the same context so the resolved token wins
|
|
54
|
-
// over any URL-captured "token" group here too — the precedence discipline
|
|
55
|
-
// applies to both header sets, not just auth.headers.
|
|
56
|
-
const fetchHeaders = provider.fetch === undefined
|
|
57
|
-
? undefined
|
|
58
|
-
: buildHeaders(provider.fetch.headers, headerContext);
|
|
59
|
-
return {
|
|
60
|
-
fetchUrl: rewrite.rewrittenUrl,
|
|
61
|
-
headers,
|
|
62
|
-
...(fetchHeaders === undefined ? {} : { fetchHeaders }),
|
|
63
|
-
check: provider.check,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=resolve.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/link-auth/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAoB,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAsB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA6E1E;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAW,EACX,MAAsB,EACtB,IAAmC;IAEnC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IACvD,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IAE9D,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO,CAAC,OAAO;QAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IAExD,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjD,wHAAwH;IACxH,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO;YACL,OAAO,EAAE,YAAY;YACrB,MAAM,EAAE,2EAA2E;SACpF,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,yEAAyE;IACzE,0DAA0D;IAC1D,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC;IACpE,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,aAAa,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;IAE/B,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACnE,2EAA2E;IAC3E,2EAA2E;IAC3E,sDAAsD;IACtD,MAAM,YAAY,GAChB,QAAQ,CAAC,KAAK,KAAK,SAAS;QAC1B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC1D,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,YAAY;QAC9B,OAAO;QACP,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC;QACvD,KAAK,EAAE,QAAQ,CAAC,KAAK;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rewrite pipeline: ordered when → vars → to.
|
|
3
|
-
*
|
|
4
|
-
* Each provider declares one or more rewrite rules. For an input URL the
|
|
5
|
-
* pipeline strips `?query` and `#fragment`, finds the first rule whose
|
|
6
|
-
* `when` regex matches, computes `vars` (templates over captures), and
|
|
7
|
-
* renders the `to` template against captures + vars merged. The merged
|
|
8
|
-
* context flows out so downstream header templates can interpolate the
|
|
9
|
-
* same variables.
|
|
10
|
-
*
|
|
11
|
-
* Per design issue #113 §4 (vocabulary) and §5.2 (fragment/query
|
|
12
|
-
* stripping must precede a greedy `(?<path>.+)` capture).
|
|
13
|
-
*/
|
|
14
|
-
export interface RewriteRule {
|
|
15
|
-
readonly when: string;
|
|
16
|
-
readonly vars?: Record<string, string>;
|
|
17
|
-
readonly to: string;
|
|
18
|
-
}
|
|
19
|
-
export type RewriteOutcome = {
|
|
20
|
-
readonly matched: true;
|
|
21
|
-
readonly rewrittenUrl: string;
|
|
22
|
-
readonly context: Record<string, string>;
|
|
23
|
-
} | {
|
|
24
|
-
readonly matched: false;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Thrown when a rule's `when` field is not a compilable regex.
|
|
28
|
-
*/
|
|
29
|
-
export declare class InvalidRewriteRuleError extends Error {
|
|
30
|
-
constructor(pattern: string, cause: unknown);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Thrown when a `vars` key collides with a named capture in `when`.
|
|
34
|
-
* Adopter must rename one — vars cannot shadow captures (the design's
|
|
35
|
-
* intent is captures + vars in a single namespace).
|
|
36
|
-
*/
|
|
37
|
-
export declare class VarCaptureCollisionError extends Error {
|
|
38
|
-
constructor(name: string);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Apply an ordered list of rewrite rules to a URL.
|
|
42
|
-
*
|
|
43
|
-
* @returns `{ matched: true, rewrittenUrl, context }` for the first matching
|
|
44
|
-
* rule, or `{ matched: false }` if no rule claims the URL.
|
|
45
|
-
* @throws {InvalidRewriteRuleError} if a `when` field does not compile
|
|
46
|
-
* @throws {VarCaptureCollisionError} if a vars name shadows a capture name
|
|
47
|
-
* @throws {TemplateMissingVarError} from a template referencing an unknown name
|
|
48
|
-
* @throws {TemplateSyntaxError} from a malformed template expression
|
|
49
|
-
* @throws {UnknownTransformError} from a template calling an unknown transform
|
|
50
|
-
*/
|
|
51
|
-
export declare function rewriteUrl(url: string, rules: readonly RewriteRule[]): RewriteOutcome;
|
|
52
|
-
//# sourceMappingURL=rewrite.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../src/link-auth/rewrite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,cAAc,GACtB;IACE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,GACD;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;AAEhC;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;CAK5C;AAED;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,IAAI,EAAE,MAAM;CAMzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,WAAW,EAAE,GAAG,cAAc,CAerF"}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rewrite pipeline: ordered when → vars → to.
|
|
3
|
-
*
|
|
4
|
-
* Each provider declares one or more rewrite rules. For an input URL the
|
|
5
|
-
* pipeline strips `?query` and `#fragment`, finds the first rule whose
|
|
6
|
-
* `when` regex matches, computes `vars` (templates over captures), and
|
|
7
|
-
* renders the `to` template against captures + vars merged. The merged
|
|
8
|
-
* context flows out so downstream header templates can interpolate the
|
|
9
|
-
* same variables.
|
|
10
|
-
*
|
|
11
|
-
* Per design issue #113 §4 (vocabulary) and §5.2 (fragment/query
|
|
12
|
-
* stripping must precede a greedy `(?<path>.+)` capture).
|
|
13
|
-
*/
|
|
14
|
-
import { renderTemplate } from './template.js';
|
|
15
|
-
/**
|
|
16
|
-
* Thrown when a rule's `when` field is not a compilable regex.
|
|
17
|
-
*/
|
|
18
|
-
export class InvalidRewriteRuleError extends Error {
|
|
19
|
-
constructor(pattern, cause) {
|
|
20
|
-
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
21
|
-
super(`Invalid rewrite rule "when" regex: ${pattern}. ${reason}`);
|
|
22
|
-
this.name = 'InvalidRewriteRuleError';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Thrown when a `vars` key collides with a named capture in `when`.
|
|
27
|
-
* Adopter must rename one — vars cannot shadow captures (the design's
|
|
28
|
-
* intent is captures + vars in a single namespace).
|
|
29
|
-
*/
|
|
30
|
-
export class VarCaptureCollisionError extends Error {
|
|
31
|
-
constructor(name) {
|
|
32
|
-
super(`Rewrite var "${name}" collides with a regex capture of the same name. Rename one.`);
|
|
33
|
-
this.name = 'VarCaptureCollisionError';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Apply an ordered list of rewrite rules to a URL.
|
|
38
|
-
*
|
|
39
|
-
* @returns `{ matched: true, rewrittenUrl, context }` for the first matching
|
|
40
|
-
* rule, or `{ matched: false }` if no rule claims the URL.
|
|
41
|
-
* @throws {InvalidRewriteRuleError} if a `when` field does not compile
|
|
42
|
-
* @throws {VarCaptureCollisionError} if a vars name shadows a capture name
|
|
43
|
-
* @throws {TemplateMissingVarError} from a template referencing an unknown name
|
|
44
|
-
* @throws {TemplateSyntaxError} from a malformed template expression
|
|
45
|
-
* @throws {UnknownTransformError} from a template calling an unknown transform
|
|
46
|
-
*/
|
|
47
|
-
export function rewriteUrl(url, rules) {
|
|
48
|
-
const stripped = stripFragmentAndQuery(url);
|
|
49
|
-
for (const rule of rules) {
|
|
50
|
-
const regex = compileWhen(rule.when);
|
|
51
|
-
const match = regex.exec(stripped);
|
|
52
|
-
if (match === null)
|
|
53
|
-
continue;
|
|
54
|
-
const captures = collectCaptures(match);
|
|
55
|
-
const context = computeContext(captures, rule.vars);
|
|
56
|
-
const rewrittenUrl = renderTemplate(rule.to, context);
|
|
57
|
-
return { matched: true, rewrittenUrl, context };
|
|
58
|
-
}
|
|
59
|
-
return { matched: false };
|
|
60
|
-
}
|
|
61
|
-
function stripFragmentAndQuery(url) {
|
|
62
|
-
const idx = url.search(/[?#]/);
|
|
63
|
-
return idx === -1 ? url : url.slice(0, idx);
|
|
64
|
-
}
|
|
65
|
-
function compileWhen(pattern) {
|
|
66
|
-
try {
|
|
67
|
-
// Rule patterns originate in trusted config (see design §8); runtime
|
|
68
|
-
// compilation is intentional, not user-input regex injection.
|
|
69
|
-
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
70
|
-
return new RegExp(pattern);
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
throw new InvalidRewriteRuleError(pattern, e);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function collectCaptures(match) {
|
|
77
|
-
const captures = Object.create(null);
|
|
78
|
-
// The lib typedef for RegExpMatchArray.groups says values are `string`, but
|
|
79
|
-
// optional named groups that did not match show up at runtime as `undefined`.
|
|
80
|
-
// Cast to reflect runtime reality so the filter below is type-meaningful.
|
|
81
|
-
const groups = (match.groups ?? {});
|
|
82
|
-
for (const [key, value] of Object.entries(groups)) {
|
|
83
|
-
if (value !== undefined) {
|
|
84
|
-
captures[key] = value;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return captures;
|
|
88
|
-
}
|
|
89
|
-
function computeContext(captures, vars) {
|
|
90
|
-
const context = Object.create(null);
|
|
91
|
-
Object.assign(context, captures);
|
|
92
|
-
if (vars === undefined)
|
|
93
|
-
return context;
|
|
94
|
-
for (const [name, template] of Object.entries(vars)) {
|
|
95
|
-
if (Object.hasOwn(captures, name)) {
|
|
96
|
-
throw new VarCaptureCollisionError(name);
|
|
97
|
-
}
|
|
98
|
-
context[name] = renderTemplate(template, captures);
|
|
99
|
-
}
|
|
100
|
-
return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c,CACrB,QAAgC,EAChC,IAAwC;IAExC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAA2B,CAAC;IAC9D,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEjC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAEvC,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,wBAAwB,CAAC,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider selection by URL host.
|
|
3
|
-
*
|
|
4
|
-
* Iterates the configured providers in order; the first one whose `match.host`
|
|
5
|
-
* glob matches the URL hostname (and no `match.excludeHost` glob excludes it)
|
|
6
|
-
* claims the URL. Returns `undefined` if no provider claims it — the caller
|
|
7
|
-
* then falls back to anonymous link-checking.
|
|
8
|
-
*
|
|
9
|
-
* Hostname matching is case-insensitive per RFC 3986. Pattern syntax follows
|
|
10
|
-
* `picomatch` (already a utils dep): `*` matches any character, `**` matches
|
|
11
|
-
* across `/`. For hostnames (no slashes) the practical effect is that `*`
|
|
12
|
-
* happily matches dots — e.g. `*.sharepoint.com` claims both
|
|
13
|
-
* `contoso.sharepoint.com` and `foo.bar.sharepoint.com`.
|
|
14
|
-
*
|
|
15
|
-
* Per design issue #113 §4 (vocabulary item 1: match.host + excludeHost).
|
|
16
|
-
*/
|
|
17
|
-
export interface ProviderMatch {
|
|
18
|
-
readonly host: string;
|
|
19
|
-
readonly excludeHost?: readonly string[];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Find the first provider whose `match` claims the given URL.
|
|
23
|
-
*
|
|
24
|
-
* @returns the matching provider, or `undefined` if none claim the URL (no
|
|
25
|
-
* pattern matched, all candidates were excluded, or the URL is malformed).
|
|
26
|
-
*/
|
|
27
|
-
export declare function selectProvider<P extends {
|
|
28
|
-
readonly match: ProviderMatch;
|
|
29
|
-
}>(url: string, providers: readonly P[]): P | undefined;
|
|
30
|
-
//# sourceMappingURL=select-provider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-provider.d.ts","sourceRoot":"","sources":["../../src/link-auth/select-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAA;CAAE,EACxE,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,SAAS,CAAC,EAAE,GACtB,CAAC,GAAG,SAAS,CAUf"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider selection by URL host.
|
|
3
|
-
*
|
|
4
|
-
* Iterates the configured providers in order; the first one whose `match.host`
|
|
5
|
-
* glob matches the URL hostname (and no `match.excludeHost` glob excludes it)
|
|
6
|
-
* claims the URL. Returns `undefined` if no provider claims it — the caller
|
|
7
|
-
* then falls back to anonymous link-checking.
|
|
8
|
-
*
|
|
9
|
-
* Hostname matching is case-insensitive per RFC 3986. Pattern syntax follows
|
|
10
|
-
* `picomatch` (already a utils dep): `*` matches any character, `**` matches
|
|
11
|
-
* across `/`. For hostnames (no slashes) the practical effect is that `*`
|
|
12
|
-
* happily matches dots — e.g. `*.sharepoint.com` claims both
|
|
13
|
-
* `contoso.sharepoint.com` and `foo.bar.sharepoint.com`.
|
|
14
|
-
*
|
|
15
|
-
* Per design issue #113 §4 (vocabulary item 1: match.host + excludeHost).
|
|
16
|
-
*/
|
|
17
|
-
import picomatch from 'picomatch';
|
|
18
|
-
/**
|
|
19
|
-
* Find the first provider whose `match` claims the given URL.
|
|
20
|
-
*
|
|
21
|
-
* @returns the matching provider, or `undefined` if none claim the URL (no
|
|
22
|
-
* pattern matched, all candidates were excluded, or the URL is malformed).
|
|
23
|
-
*/
|
|
24
|
-
export function selectProvider(url, providers) {
|
|
25
|
-
const host = extractHostname(url);
|
|
26
|
-
if (host === undefined)
|
|
27
|
-
return undefined;
|
|
28
|
-
for (const provider of providers) {
|
|
29
|
-
if (matches(host, provider.match)) {
|
|
30
|
-
return provider;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
function extractHostname(url) {
|
|
36
|
-
try {
|
|
37
|
-
return new URL(url).hostname;
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function matches(host, match) {
|
|
44
|
-
const lowerHost = host.toLowerCase();
|
|
45
|
-
if (!picomatch.isMatch(lowerHost, match.host.toLowerCase()))
|
|
46
|
-
return false;
|
|
47
|
-
if (match.excludeHost !== undefined) {
|
|
48
|
-
for (const pattern of match.excludeHost) {
|
|
49
|
-
if (picomatch.isMatch(lowerHost, pattern.toLowerCase()))
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=select-provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-provider.js","sourceRoot":"","sources":["../../src/link-auth/select-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH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5
|
-
* - `${name}` → context[name]
|
|
6
|
-
* - `${transform(name)}` → applyTransform(transform, context[name])
|
|
7
|
-
*
|
|
8
|
-
* Anything else inside `${...}` throws `TemplateSyntaxError`. Missing context
|
|
9
|
-
* keys throw `TemplateMissingVarError`. Unknown transform names propagate
|
|
10
|
-
* `UnknownTransformError` from the transforms allowlist.
|
|
11
|
-
*
|
|
12
|
-
* This is NOT the project's general-purpose Handlebars renderer
|
|
13
|
-
* (`utils/template.ts`) — that one is `{{...}}` and consumed widely. linkAuth
|
|
14
|
-
* needs different syntax and a closed transform set; the two coexist by
|
|
15
|
-
* namespace (`link-auth/template.ts`).
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Thrown when a template references a variable not present in the context.
|
|
19
|
-
* Message names the missing variable and includes the full template for
|
|
20
|
-
* caller-side debugging.
|
|
21
|
-
*/
|
|
22
|
-
export declare class TemplateMissingVarError extends Error {
|
|
23
|
-
constructor(varName: string, template: string);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Thrown when a template contains syntactically invalid content inside `${...}`
|
|
27
|
-
* (empty expression, whitespace, unrecognized form) or an unterminated `${`.
|
|
28
|
-
*/
|
|
29
|
-
export declare class TemplateSyntaxError extends Error {
|
|
30
|
-
constructor(detail: string, template: string);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Render a template by substituting `${...}` expressions from a context map.
|
|
34
|
-
*
|
|
35
|
-
* @throws {TemplateMissingVarError} if a referenced variable is absent
|
|
36
|
-
* @throws {TemplateSyntaxError} for invalid expressions or unterminated `${`
|
|
37
|
-
* @throws {UnknownTransformError} from a `${transform(name)}` call
|
|
38
|
-
*/
|
|
39
|
-
export declare function renderTemplate(template: string, context: Record<string, string>): string;
|
|
40
|
-
//# sourceMappingURL=template.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/link-auth/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI9C;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAI7C;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAUxF"}
|