@vielzeug/ward 2.1.0 → 2.3.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.
package/dist/devtools.js DELETED
@@ -1,16 +0,0 @@
1
- import { createWard as e } from "./factory.js";
2
- //#region src/devtools.ts
3
- function t(t, n) {
4
- let r = (e) => {
5
- let t = e.principal ? e.principal.roles.length > 0 ? e.principal.roles.join(", ") : e.principal.id : "anonymous", n = (e.allowed ? "allow" : e.reason).padEnd(16), r = "rule" in e ? `(${e.rule.effect})`.padEnd(8) : " ";
6
- console.debug(`[ward:decision] ${n} ${r} ${t} ${e.resource} ${e.action}`);
7
- };
8
- return e(t, {
9
- ...n,
10
- logger: r
11
- });
12
- }
13
- //#endregion
14
- export { t as debugWard };
15
-
16
- //# sourceMappingURL=devtools.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools.js","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["/**\n * @vielzeug/ward — debug utilities for authorization decision visualisation.\n *\n * Import from the dedicated sub-path so it is tree-shaken from production bundles:\n * ```ts\n * import { debugWard } from '@vielzeug/ward/devtools';\n * ```\n */\n\nimport { createWard } from './factory';\nimport type { Ward, WardLoggerContext, WardOptions, WardRule } from './types';\n\n/**\n * Creates a {@link Ward} with authorization decision logging pre-wired to `console.debug`.\n *\n * Equivalent to `createWard(rules, { ...options, logger: ctx => console.debug(...) })` but\n * imported from a dedicated sub-path so `console.debug` references are tree-shaken from\n * production bundles when this sub-path is not imported.\n *\n * Logs every authorization decision made by any decision method (`checkAll`, `explain`)\n * with `[ward:decision]` prefixes showing the outcome,\n * principal, resource, action, and — when a rule matched — its effect.\n *\n * @example\n * ```ts\n * import { debugWard } from '@vielzeug/ward/devtools';\n *\n * const permit = debugWard(rules);\n * permit.explain({ action: 'read', principal: { id: 'u1', roles: ['viewer'] }, resource: 'posts' });\n * // [ward:decision] allow (allow) viewer posts read\n *\n * permit.explain({ action: 'delete', principal: { id: 'u1', roles: ['viewer'] }, resource: 'posts' });\n * // [ward:decision] no-matching-rule viewer posts delete\n *\n * // Note: `trace()` does NOT fire the logger — it is a side-channel-free inspection tool.\n * ```\n */\nexport function debugWard<TAction extends string = string, TData = unknown>(\n rules: readonly WardRule<TAction, TData>[],\n options?: Omit<WardOptions<TAction, TData>, 'logger'>,\n): Ward<TAction, TData> {\n const logger = (ctx: WardLoggerContext<TAction, TData>): void => {\n const principal = ctx.principal\n ? ctx.principal.roles.length > 0\n ? ctx.principal.roles.join(', ')\n : ctx.principal.id\n : 'anonymous';\n const outcome = ctx.allowed ? 'allow' : ctx.reason;\n const decision = outcome.padEnd(16);\n const effect = 'rule' in ctx ? `(${ctx.rule.effect})`.padEnd(8) : ' ';\n\n console.debug(`[ward:decision] ${decision} ${effect} ${principal} ${ctx.resource} ${ctx.action}`);\n };\n\n return createWard<TAction, TData>(rules, { ...options, logger });\n}\n"],"mappings":";;AAqCA,SAAgB,EACd,GACA,GACsB;CACtB,IAAM,KAAU,MAAiD;EAC/D,IAAM,IAAY,EAAI,YAClB,EAAI,UAAU,MAAM,SAAS,IAC3B,EAAI,UAAU,MAAM,KAAK,IAAI,IAC7B,EAAI,UAAU,KAChB,aAEE,KADU,EAAI,UAAU,UAAU,EAAI,OAAA,CACnB,OAAO,EAAE,GAC5B,IAAS,UAAU,IAAM,IAAI,EAAI,KAAK,OAAO,GAAG,OAAO,CAAC,IAAI;EAElE,QAAQ,MAAM,mBAAmB,EAAS,IAAI,EAAO,IAAI,EAAU,IAAI,EAAI,SAAS,IAAI,EAAI,QAAQ;CACtG;CAEA,OAAO,EAA2B,GAAO;EAAE,GAAG;EAAS;CAAO,CAAC;AACjE"}