/** * Trusted system context * * Privileged service methods resolve their actor from request context. Code that runs * outside a request — a seeding script, a data migration, a queue worker — has no * actor, and is denied rather than waved through: "no context means trusted" would * silently authorize any background job reachable from user input. * * `runAsSystem` is the deliberate, greppable exception. */ /** * Run trusted work that bypasses authorization. * * Everything inside the callback — including nested async calls, since the flag rides * on `AsyncLocalStorage` — skips the authorization provider entirely. The provider is * not consulted with a null actor; it is not consulted at all. * * **Never call this on a request path.** It defeats the authorization model completely. * It exists for code with no authenticated caller and no business having one: database * seeds, migrations, scheduled jobs, tests. * * Nests safely, and restores the previous state on exit even if the callback throws. * * @param fn - The work to run as the system * @returns Whatever `fn` returns, including a promise if it is async * * @example * ```typescript * // A seeding script: no HTTP request, no signed-in admin. * await runAsSystem(async () => { * await adminAuthService.signup({ email: 'owner@example.com', password: seed }); * await adminAuthService.setMustChangePassword({ sub, mustChangePassword: true }); * }); * ``` */ export declare function runAsSystem(fn: () => T): T; /** * Whether the current execution was marked trusted by {@link runAsSystem}. * * @returns true when authorization should be bypassed */ export declare function isSystemContext(): boolean; //# sourceMappingURL=run-as-system.d.ts.map