@pithy-sh/auth 0.16.0 → 0.17.1
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/capability.d.ts +9 -6
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +4 -2
- package/dist/data/tables.d.ts +1 -0
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/userLifecycle.d.ts +1 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +3 -2
- package/dist/hooks/runtime.d.ts +32 -0
- package/dist/hooks/runtime.d.ts.map +1 -0
- package/dist/hooks/runtime.js +25 -0
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +4 -2
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +2 -1
- package/dist/http/responses.d.ts +3 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +2 -1
- package/dist/lifecycle/erasure.d.ts.map +1 -1
- package/dist/lifecycle/erasure.js +2 -1
- package/dist/lifecycle/hooks.d.ts +18 -10
- package/dist/lifecycle/hooks.d.ts.map +1 -1
- package/dist/lifecycle/request.d.ts +2 -1
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +4 -1
- package/dist/lifecycle/transitions.d.ts +24 -16
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +27 -16
- package/dist/migrations/0011_retained_basis_key.d.ts +10 -0
- package/dist/migrations/0011_retained_basis_key.d.ts.map +1 -0
- package/dist/migrations/0011_retained_basis_key.js +18 -0
- package/dist/migrations/set.d.ts +1 -0
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +3 -1
- package/dist/purge/run.d.ts +11 -11
- package/dist/purge/run.d.ts.map +1 -1
- package/dist/purge/run.js +9 -8
- package/dist/purge/workflow.d.ts +7 -1
- package/dist/purge/workflow.d.ts.map +1 -1
- package/dist/purge/workflow.js +6 -2
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +46 -10
- package/package.json +5 -5
- package/src/capability.ts +21 -8
- package/src/data/userLifecycle.ts +9 -2
- package/src/hooks/runtime.ts +41 -0
- package/src/http/adminRoutes.ts +14 -7
- package/src/http/resolve.ts +8 -4
- package/src/http/responses.ts +7 -1
- package/src/lifecycle/erasure.ts +2 -1
- package/src/lifecycle/hooks.ts +22 -10
- package/src/lifecycle/request.ts +4 -1
- package/src/lifecycle/transitions.ts +47 -28
- package/src/migrations/0011_retained_basis_key.ts +19 -0
- package/src/migrations/set.ts +2 -0
- package/src/purge/run.ts +29 -17
- package/src/purge/workflow.ts +7 -3
- package/src/version.generated.ts +1 -1
package/dist/capability.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { z } from "zod";
|
|
|
12
12
|
import { AttestationConfig } from "./attestation/config";
|
|
13
13
|
import { type AttestationVerifiers } from "./attestation/verifier";
|
|
14
14
|
import type { AuthClientProjection } from "./client/projection";
|
|
15
|
+
import type { HookRuntime } from "./hooks/runtime";
|
|
15
16
|
import type { GithubUserInfoResolver } from "./instance/githubUserInfo";
|
|
16
17
|
import type { UserLifecycleHooks } from "./lifecycle/hooks";
|
|
17
18
|
import type { McpHost, McpWiring } from "./mcp/host";
|
|
@@ -168,12 +169,14 @@ export type ScopeResolver = (c: Context<PithyHonoEnv>, session: ScopeResolverSes
|
|
|
168
169
|
* **Handed this request's D1 binding**, because the auth instance is built per request and the listener
|
|
169
170
|
* almost certainly wants to write to the same database under a different capability's view of it. Taking
|
|
170
171
|
* the binding rather than a typed database keeps this seam out of the business of knowing whose tables
|
|
171
|
-
* the listener is about to touch.
|
|
172
|
+
* the listener is about to touch. **And handed the request's runtime**: its env, typed as `auth<Env>()` names
|
|
173
|
+
* it, and its `waitUntil`, so the listener can reach another binding or keep work running past the response.
|
|
174
|
+
* A listener that takes only `(session, d1)` is still one.
|
|
172
175
|
*/
|
|
173
|
-
export type SessionRevokedListener = (session: {
|
|
176
|
+
export type SessionRevokedListener<Env = Record<string, unknown>> = (session: {
|
|
174
177
|
id: string;
|
|
175
178
|
userId: string;
|
|
176
|
-
}, d1: D1Database) => Promise<void>;
|
|
179
|
+
}, d1: D1Database, runtime: HookRuntime<Env>) => Promise<void>;
|
|
177
180
|
/**
|
|
178
181
|
* What `auth()` takes: the config, plus the seams that are **behavior rather than data**.
|
|
179
182
|
*
|
|
@@ -182,7 +185,7 @@ export type SessionRevokedListener = (session: {
|
|
|
182
185
|
* `PaymentsOptions`: everything describable stays in {@link AuthConfig}, and a resolver is a sibling key
|
|
183
186
|
* destructured off before the parse.
|
|
184
187
|
*/
|
|
185
|
-
export type AuthOptions = AuthConfigInput & UserLifecycleHooks & {
|
|
188
|
+
export type AuthOptions<Env = Record<string, unknown>> = AuthConfigInput & UserLifecycleHooks<Env> & {
|
|
186
189
|
/**
|
|
187
190
|
* Resolve a GitHub identity yourself, replacing the kit's primary-only rule.
|
|
188
191
|
*
|
|
@@ -213,7 +216,7 @@ export type AuthOptions = AuthConfigInput & UserLifecycleHooks & {
|
|
|
213
216
|
*
|
|
214
217
|
* A function, so it is destructured off before `AuthConfig.parse` for the reason above.
|
|
215
218
|
*/
|
|
216
|
-
onSessionRevoked?: SessionRevokedListener
|
|
219
|
+
onSessionRevoked?: SessionRevokedListener<Env>;
|
|
217
220
|
/**
|
|
218
221
|
* Decide, per request, what this request's caller is — and so which scope gates it opens.
|
|
219
222
|
*
|
|
@@ -278,7 +281,7 @@ export declare function attestationProjection(config: AttestationConfig, environ
|
|
|
278
281
|
* `AuthContext` seam. Depends on `secrets` and `email`; auto-gates its send routes with `turnstile`
|
|
279
282
|
* and emits `auth/*` through `audit` when those are composed.
|
|
280
283
|
*/
|
|
281
|
-
export declare function auth(options: AuthOptions): AuthCapability;
|
|
284
|
+
export declare function auth<Env = Record<string, unknown>>(options: AuthOptions<Env>): AuthCapability;
|
|
282
285
|
/** Type guard: is this capability the auth capability? */
|
|
283
286
|
export declare function isAuthCapability(capability: Capability): capability is AuthCapability;
|
|
284
287
|
//# sourceMappingURL=capability.d.ts.map
|
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAmB,MAAM,0CAA0C,CAAC;AAE1G,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,qCAAqC,CAAC;AAEjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACrG,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAA0C,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,KAAK,oBAAoB,EAAsB,MAAM,wBAAwB,CAAC;AAEvF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAmB,MAAM,0CAA0C,CAAC;AAE1G,OAAO,EAAE,KAAK,SAAS,EAAc,MAAM,qC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,CAAA;CAAE,CAAC,EAAE,aAAa,CAAC,CAevE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,cAAc,CAgP7F;AAED,0DAA0D;AAC1D,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,IAAI,cAAc,CAErF"}
|
package/dist/capability.js
CHANGED
|
@@ -145,14 +145,16 @@ function attestationProjection(config, environment, verifiers) {
|
|
|
145
145
|
* and emits `auth/*` through `audit` when those are composed.
|
|
146
146
|
*/
|
|
147
147
|
function auth(options) {
|
|
148
|
-
const { resolveGithubUserInfo, onSessionRevoked, resolveScopes, onUserSuspended, onUserReinstated, onUserDeleted, onUserPurged, ...config } = options;
|
|
148
|
+
const { resolveGithubUserInfo, onSessionRevoked, resolveScopes, onUserSuspended, onUserReinstated, onUserDeleted, onUserRestored, onUserPurged, ...config } = options;
|
|
149
149
|
const resolved = AuthConfig.parse(config);
|
|
150
150
|
const lifecycleHooks = {
|
|
151
151
|
...onUserSuspended ? { onUserSuspended } : {},
|
|
152
152
|
...onUserReinstated ? { onUserReinstated } : {},
|
|
153
153
|
...onUserDeleted ? { onUserDeleted } : {},
|
|
154
|
+
...onUserRestored ? { onUserRestored } : {},
|
|
154
155
|
...onUserPurged ? { onUserPurged } : {}
|
|
155
156
|
};
|
|
157
|
+
const sessionRevoked = onSessionRevoked;
|
|
156
158
|
assertAdditivePlugins(resolved.plugins);
|
|
157
159
|
const pluginPlan = authPluginPlan(resolved.plugins);
|
|
158
160
|
const wiring = {
|
|
@@ -160,7 +162,7 @@ function auth(options) {
|
|
|
160
162
|
resolveGithubUserInfo,
|
|
161
163
|
enqueueEmail: void 0,
|
|
162
164
|
turnstile: void 0,
|
|
163
|
-
onSessionRevoked,
|
|
165
|
+
onSessionRevoked: sessionRevoked,
|
|
164
166
|
resolveScopes,
|
|
165
167
|
lifecycleHooks,
|
|
166
168
|
purgeSteps: []
|
package/dist/data/tables.d.ts
CHANGED
|
@@ -131,6 +131,7 @@ export declare const authTables: {
|
|
|
131
131
|
soft: "soft";
|
|
132
132
|
}>>>;
|
|
133
133
|
purgeAfter: import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>>>;
|
|
134
|
+
basisKey: import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
134
135
|
createdAt: import("zod").ZodCodec<import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString, import("zod").ZodDate]>, import("zod").ZodDate>;
|
|
135
136
|
}, import("zod/v4/core").$strip>;
|
|
136
137
|
pithyAuthVerificationOutcomes: import("zod").ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AASrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;IACrB,cAAc;;;;;;;;;;;;;;;IACd,iBAAiB;;;;;;;;;;;;;IACjB,iBAAiB;;;;;;;;;;;;;;;;IACjB,sBAAsB;;;;;;;;IACtB,aAAa;;;;;;;;;IACb,kBAAkB;;;;;;IAClB,gBAAgB;;;;;;;;;;;;;;;;;IAChB,sBAAsB;;;;;;IACtB,sBAAsB
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../src/data/tables.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AASrC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU;IACrB,cAAc;;;;;;;;;;;;;;;IACd,iBAAiB;;;;;;;;;;;;;IACjB,iBAAiB;;;;;;;;;;;;;;;;IACjB,sBAAsB;;;;;;;;IACtB,aAAa;;;;;;;;;IACb,kBAAkB;;;;;;IAClB,gBAAgB;;;;;;;;;;;;;;;;;IAChB,sBAAsB;;;;;;IACtB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IACtB,6BAA6B;;;;;;;;;;;;;IAC7B,8BAA8B;;;;;IAC9B,sBAAsB;;;;;;;;;;;;CACvB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC;AAE3C,8GAA8G;AAC9G,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;AAE9D,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,EAAE,EAAE,UAAU,GAAG,YAAY,CAEzD"}
|
|
@@ -65,6 +65,7 @@ export declare const UserLifecycleEvent: z.ZodObject<{
|
|
|
65
65
|
soft: "soft";
|
|
66
66
|
}>>>;
|
|
67
67
|
purgeAfter: z.ZodDefault<z.ZodNullable<z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>>>;
|
|
68
|
+
basisKey: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
68
69
|
createdAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
|
|
69
70
|
}, z.core.$strip>;
|
|
70
71
|
export type UserLifecycleEvent = z.output<typeof UserLifecycleEvent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userLifecycle.d.ts","sourceRoot":"","sources":["../../src/data/userLifecycle.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH,oCAAoC;AACpC,eAAO,MAAM,mBAAmB;;;;;;;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE,+BAA+B;AAC/B,eAAO,MAAM,sBAAsB;;;;EAIhC,CAAC;AACJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE7E,iCAAiC;AACjC,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"userLifecycle.d.ts","sourceRoot":"","sources":["../../src/data/userLifecycle.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AAEH,oCAAoC;AACpC,eAAO,MAAM,mBAAmB;;;;;;;;;EAI7B,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE,+BAA+B;AAC/B,eAAO,MAAM,sBAAsB;;;;EAIhC,CAAC;AACJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE7E,iCAAiC;AACjC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4D5B,CAAC;AACJ,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -35,20 +35,21 @@ const UserLifecycleActorType = z.enum([
|
|
|
35
35
|
"control-plane",
|
|
36
36
|
"user",
|
|
37
37
|
"system"
|
|
38
|
-
]).describe("Who made the transition: `control-plane` (a management client, under a scoped grant), `user` (the account's own holder
|
|
38
|
+
]).describe("Who made the transition: `control-plane` (a management client, under a scoped grant), `user` (a signed-in person: the account's own holder deleting it, or an organization's owner whose deletion of that organization reached it through the sole-member cascade), or `system` (the scheduled purge, with nobody calling).");
|
|
39
39
|
/** One transition, as stored. */
|
|
40
40
|
const UserLifecycleEvent = z.object({
|
|
41
41
|
id: z.number().int().describe("Primary key. Auto-incrementing, so a user's history reads in the order it was written."),
|
|
42
42
|
userId: z.string().describe("The account this happened to. Not a foreign key: the row outlives the user it names, because a purge must leave its own record behind. Indexed."),
|
|
43
43
|
action: UserLifecycleAction.describe("What happened to the account."),
|
|
44
44
|
actorType: UserLifecycleActorType.describe("Who made the transition."),
|
|
45
|
-
actorId: z.string().nullable().describe("The acting principal's id — the user's own id for a self-service deletion, the connection's for a management client. Null for `system`, and for a management client that named none."),
|
|
45
|
+
actorId: z.string().nullable().describe("The acting principal's id — the user's own id for a self-service deletion, the deleting owner's for an organization's cascade, the connection's for a management client. Null for `system`, and for a management client that named none."),
|
|
46
46
|
reason: z.string().nullable().describe("Why, in the words of whoever made the transition. For a suspension this is the sentence the locked-out person is shown, so it is written for them. Null for a transition nobody had to justify — a purge, a self-service deletion."),
|
|
47
47
|
suspendedUntil: SQLiteDate.nullable().describe("For a `suspended` row, when that suspension ends by itself; null for one that lasts until a reinstatement, and for every other action. Ms-epoch in SQLite."),
|
|
48
48
|
step: z.string().nullable().describe("For a `purge_step` row, the capability whose rows that step erased; for a `purge_retained` row, the capability whose rows it kept; for a `purge_failed` row, the step the purge gave up at — a capability, `mail` or `complete`. Null for every other action."),
|
|
49
49
|
notify: SQLiteBoolean.nullable().describe("For a hard deletion's `deleted` row, whether the purge sends the deletion-complete mail — false when the deletion asked for none. Null for every other row, and for a hard deletion that did not say. The purge reads it, so a purge the daily pass starts keeps the choice (#622)."),
|
|
50
50
|
mode: z.enum(["soft", "hard"]).nullable().default(null).describe("For a `deleted` row, how the deletion was asked for: `soft` with a window, `hard` with none — a hard deletion bringing a soft one forward writes its own `hard` row. Null for every other row, and for a deletion recorded before `0007_erasure_record` (#823)."),
|
|
51
51
|
purgeAfter: SQLiteDate.nullable().default(null).describe("For a `deleted` row, when its purge comes due — kept here because the purge erases the account's own column. Null for every other row, and before `0007_erasure_record` (#823). Ms-epoch in SQLite."),
|
|
52
|
+
basisKey: z.string().nullable().default(null).describe("For a `purge_retained` row, the catalog key its basis in `reason` translates through, under the retaining capability's own domain — `payments/purge.retained`. Null for every other row, for a retained step that names no key, and before `0011_retained_basis_key`."),
|
|
52
53
|
createdAt: SQLiteDate.describe("When the transition happened. Ms-epoch in SQLite; a `Date` in app code.")
|
|
53
54
|
}).describe("One transition in `pithy_auth_user_lifecycle`: an account suspended, reinstated, deleted, restored or purged, with who did it and why.");
|
|
54
55
|
//#endregion
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
/**
|
|
4
|
+
* What a hook is handed beside its event and the D1 binding: the Worker it runs in.
|
|
5
|
+
*
|
|
6
|
+
* `env` is the Worker's environment, typed as the adopter's own through `auth<Env>()` or
|
|
7
|
+
* `organization.withEnv<Env>()(...)`, so a hook can read a secret, start a Workflow or send to a queue. `waitUntil` is the request's
|
|
8
|
+
* `ExecutionContext.waitUntil`, already bound, present when the hook fires inside a request and absent when it fires
|
|
9
|
+
* from a purge Workflow, which has no `ExecutionContext` — a Workflow step already runs to completion.
|
|
10
|
+
*/
|
|
11
|
+
export interface HookRuntime<Env = Record<string, unknown>> {
|
|
12
|
+
/** The Worker's environment: every binding and secret. */
|
|
13
|
+
readonly env: Env;
|
|
14
|
+
/** Keep work running after the response, inside a request. Absent in a Workflow. */
|
|
15
|
+
readonly waitUntil?: (promise: Promise<unknown>) => void;
|
|
16
|
+
}
|
|
17
|
+
/** What {@link requestRuntime} reads off a Hono context. */
|
|
18
|
+
interface RuntimeSource {
|
|
19
|
+
readonly env: unknown;
|
|
20
|
+
readonly executionCtx?: {
|
|
21
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
22
|
+
} | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The runtime for a hook fired inside a request: the request's env, and its `waitUntil` bound to the context.
|
|
26
|
+
*
|
|
27
|
+
* Hono's `executionCtx` getter throws when the request carries none, as under `app.request()` with no context, so
|
|
28
|
+
* that case reads as absent rather than failing the hook's caller.
|
|
29
|
+
*/
|
|
30
|
+
export declare function requestRuntime<Env = Record<string, unknown>>(c: RuntimeSource): HookRuntime<Env>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/hooks/runtime.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACxD,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,oFAAoF;IACpF,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CAC1D;AAED,4DAA4D;AAC5D,UAAU,aAAa;IACrB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,YAAY,CAAC,EAAE;QAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;KAAE,GAAG,SAAS,CAAC;CACpF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,aAAa,GAAG,WAAW,CAAC,GAAG,CAAC,CAUhG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
//#region src/hooks/runtime.ts
|
|
4
|
+
/**
|
|
5
|
+
* The runtime for a hook fired inside a request: the request's env, and its `waitUntil` bound to the context.
|
|
6
|
+
*
|
|
7
|
+
* Hono's `executionCtx` getter throws when the request carries none, as under `app.request()` with no context, so
|
|
8
|
+
* that case reads as absent rather than failing the hook's caller.
|
|
9
|
+
*/
|
|
10
|
+
function requestRuntime(c) {
|
|
11
|
+
const env = c.env;
|
|
12
|
+
let ctx;
|
|
13
|
+
try {
|
|
14
|
+
ctx = c.executionCtx;
|
|
15
|
+
} catch {
|
|
16
|
+
ctx = void 0;
|
|
17
|
+
}
|
|
18
|
+
if (!ctx) return { env };
|
|
19
|
+
return {
|
|
20
|
+
env,
|
|
21
|
+
waitUntil: ctx.waitUntil.bind(ctx)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { requestRuntime };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/http/adminRoutes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;
|
|
1
|
+
{"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/http/adminRoutes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAU7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAe1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAgUhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAkiB7F"}
|
package/dist/http/adminRoutes.js
CHANGED
|
@@ -23,6 +23,7 @@ import { describeRoute } from "@pithy-sh/core/src/http/routeSpec";
|
|
|
23
23
|
import { validate } from "@pithy-sh/core/src/http/validation";
|
|
24
24
|
import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
|
|
25
25
|
import { requireControlPlane } from "@pithy-sh/core/src/controlPlane/http/guard";
|
|
26
|
+
import { composedTranslator } from "@pithy-sh/core/src/i18n/composed";
|
|
26
27
|
import { workflowBindingFor } from "@pithy-sh/core/src/workflow/dispatch";
|
|
27
28
|
//#region src/http/adminRoutes.ts
|
|
28
29
|
/**
|
|
@@ -605,7 +606,8 @@ function registerAuthAdminRoutes(wiring) {
|
|
|
605
606
|
...call.audit
|
|
606
607
|
}, async () => {
|
|
607
608
|
const database = db(c, wiring);
|
|
608
|
-
await requirePresent(database, userId);
|
|
609
|
+
const { locale } = await requirePresent(database, userId);
|
|
610
|
+
const t = composedTranslator(wiring.composed ?? [], locale);
|
|
609
611
|
return purgeExports(wiring.purgeSteps ?? [], {
|
|
610
612
|
subject: {
|
|
611
613
|
type: "user",
|
|
@@ -613,7 +615,7 @@ function registerAuthAdminRoutes(wiring) {
|
|
|
613
615
|
},
|
|
614
616
|
env: c.env,
|
|
615
617
|
address: () => purgeAddress(database, userId)
|
|
616
|
-
});
|
|
618
|
+
}, t ? (key) => t.maybe(key) : void 0);
|
|
617
619
|
}, () => false);
|
|
618
620
|
await emitControlPlaneAction(c.var.emit, {
|
|
619
621
|
action: AuthAuditActions.adminUserExported,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/http/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAK7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/http/resolve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAK7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,OAAO,EAAE,KAAK,YAAY,EAAY,MAAM,kBAAkB,CAAC;AAwB/D,2GAA2G;AAC3G,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,UAAU,CASvF;AA0BD,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAMnG"}
|
package/dist/http/resolve.js
CHANGED
|
@@ -4,6 +4,7 @@ import { resolveAppleCredentials, resolveFacebookCredentials, resolveGithubCrede
|
|
|
4
4
|
import { authDatabase } from "../data/tables.js";
|
|
5
5
|
import { baseURLResolver } from "./baseUrl.js";
|
|
6
6
|
import { makeSendAuthEmail } from "../email/send.js";
|
|
7
|
+
import { requestRuntime } from "../hooks/runtime.js";
|
|
7
8
|
import { resolveProvider } from "../instance/providers.js";
|
|
8
9
|
import { makeAuth } from "../instance/auth.js";
|
|
9
10
|
import { ensureJwksSealedUnderCurrent } from "../instance/jwksReencryption.js";
|
|
@@ -90,7 +91,7 @@ async function buildAuthInstance(c, wiring) {
|
|
|
90
91
|
const baseURL = baseURLResolver(cfg.baseURL)(c.req.raw);
|
|
91
92
|
return makeAuth({
|
|
92
93
|
db: authDatabase(d1),
|
|
93
|
-
...listener ? { onSessionRevoked: (session) => listener(session, d1) } : {},
|
|
94
|
+
...listener ? { onSessionRevoked: (session) => listener(session, d1, requestRuntime(c)) } : {},
|
|
94
95
|
secret,
|
|
95
96
|
sessionSecrets,
|
|
96
97
|
baseURL,
|
package/dist/http/responses.d.ts
CHANGED
|
@@ -434,6 +434,7 @@ export declare const AdminUserExportResponse: z.ZodObject<{
|
|
|
434
434
|
retain: "retain";
|
|
435
435
|
}>>;
|
|
436
436
|
basis: z.ZodOptional<z.ZodString>;
|
|
437
|
+
basisKey: z.ZodOptional<z.ZodString>;
|
|
437
438
|
state: z.ZodLiteral<"exported">;
|
|
438
439
|
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
439
440
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -444,6 +445,7 @@ export declare const AdminUserExportResponse: z.ZodObject<{
|
|
|
444
445
|
retain: "retain";
|
|
445
446
|
}>>;
|
|
446
447
|
basis: z.ZodOptional<z.ZodString>;
|
|
448
|
+
basisKey: z.ZodOptional<z.ZodString>;
|
|
447
449
|
state: z.ZodLiteral<"not_exported">;
|
|
448
450
|
}, z.core.$strip>, z.ZodObject<{
|
|
449
451
|
capability: z.ZodString;
|
|
@@ -453,6 +455,7 @@ export declare const AdminUserExportResponse: z.ZodObject<{
|
|
|
453
455
|
retain: "retain";
|
|
454
456
|
}>>;
|
|
455
457
|
basis: z.ZodOptional<z.ZodString>;
|
|
458
|
+
basisKey: z.ZodOptional<z.ZodString>;
|
|
456
459
|
state: z.ZodLiteral<"unavailable">;
|
|
457
460
|
}, z.core.$strip>], "state">>;
|
|
458
461
|
}, z.core.$strip>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/http/responses.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAyCxB,kDAAkD;AAClD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;iBAuCsF,CAAC;AACjH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D,2FAA2F;AAC3F,eAAO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AAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEnE,oCAAoC;AACpC,eAAO,MAAM,sBAAsB;;iBAEyE,CAAC;AAC7G,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;iBAU2E,CAAC;AAC9G,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
package/dist/http/responses.js
CHANGED
|
@@ -269,7 +269,8 @@ const exportEntry = {
|
|
|
269
269
|
capability: z.string().describe("The capability whose rows these are — the purge step that erases or keeps them."),
|
|
270
270
|
summary: z.string().describe("What that capability's purge erases, anonymizes or keeps, in its own sentence."),
|
|
271
271
|
disposition: z.enum(["erase", "retain"]).optional().describe("What a purge does with these rows: `erase` (erased or anonymized) or `retain` (kept, for the reason in `basis`) (#814). Absent from a Worker that predates it, where every entry is `erase`."),
|
|
272
|
-
basis: z.string().optional().describe("For a `retain` entry, why the rows are kept, in one sentence written for the person — `Kept for tax records.` Absent for `erase`.")
|
|
272
|
+
basis: z.string().optional().describe("For a `retain` entry, why the rows are kept, in one sentence written for the person and in their stored locale where a catalog translates it — `Kept for tax records.` Absent for `erase`."),
|
|
273
|
+
basisKey: z.string().optional().describe("For a `retain` entry, the catalog key `basis` was translated from, under the capability's own domain — `payments/purge.retained`. Absent when the capability names none, for `erase`, and from a Worker that predates it.")
|
|
273
274
|
};
|
|
274
275
|
/** One capability's part of an export. */
|
|
275
276
|
const AdminUserExportEntry = z.discriminatedUnion("state", [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erasure.d.ts","sourceRoot":"","sources":["../../src/lifecycle/erasure.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAqB,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGrH,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAqBjE,0CAA0C;AAC1C,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"erasure.d.ts","sourceRoot":"","sources":["../../src/lifecycle/erasure.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAqB,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGrH,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAqBjE,0CAA0C;AAC1C,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,oBAAoB,CAuExE;AAED,+GAA+G;AAC/G,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAgBnE"}
|
|
@@ -7,7 +7,7 @@ import { resolveDb } from "../http/resolve.js";
|
|
|
7
7
|
import { SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
8
8
|
//#region src/lifecycle/erasure.ts
|
|
9
9
|
/**
|
|
10
|
-
* **A user's erasure record, read back for the control plane's attestation
|
|
10
|
+
* **A user's erasure record, read back for the control plane's attestation.**
|
|
11
11
|
*
|
|
12
12
|
* `pithy_auth_user_lifecycle` is the one `pithy_auth_*` table a purge leaves behind, and it names the account by id
|
|
13
13
|
* and nothing else. This reads the rows an erasure is made of — the deletion, any restore, each step, a failure, the
|
|
@@ -44,6 +44,7 @@ function userErasureReader(db) {
|
|
|
44
44
|
actorType: row.actorType,
|
|
45
45
|
reason: row.reason,
|
|
46
46
|
step: row.step,
|
|
47
|
+
basisKey: row.basisKey,
|
|
47
48
|
mode: row.mode,
|
|
48
49
|
purgeAfter: row.purgeAfter,
|
|
49
50
|
at: row.createdAt
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import type { D1Database } from "@cloudflare/workers-types";
|
|
4
4
|
import type { UserLifecycleActorType } from "../data/userLifecycle";
|
|
5
|
+
import type { HookRuntime } from "../hooks/runtime";
|
|
5
6
|
/**
|
|
6
|
-
* The
|
|
7
|
+
* The five seams an adopter's own code follows the account lifecycle through, without polling.
|
|
7
8
|
*
|
|
8
9
|
* **On the transition, not on a route.** An account is suspended from the management surface today and may be
|
|
9
10
|
* from somewhere else tomorrow; a listener hung off one route would miss the others, which is the argument
|
|
@@ -35,19 +36,26 @@ export interface UserLifecycleHookEvent {
|
|
|
35
36
|
readonly purgeAfter?: Date | null;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* One hook. Handed the
|
|
39
|
-
*
|
|
39
|
+
* One hook. Handed the run's D1 binding, for the reason `SessionRevokedListener` is: the listener almost certainly
|
|
40
|
+
* writes to the same database under a different capability's view of it. And handed the Worker it runs in, so it
|
|
41
|
+
* can reach a secret or another binding — start a Workflow, send to a queue, call out. `runtime.waitUntil` is there
|
|
42
|
+
* in a request and absent in the purge Workflow. A hook that takes only `(event, d1)` is still one.
|
|
40
43
|
*/
|
|
41
|
-
export type UserLifecycleListener = (event: UserLifecycleHookEvent, d1: D1Database) => void | Promise<void>;
|
|
42
|
-
/** The
|
|
43
|
-
export interface UserLifecycleHooks {
|
|
44
|
+
export type UserLifecycleListener<Env = Record<string, unknown>> = (event: UserLifecycleHookEvent, d1: D1Database, runtime: HookRuntime<Env>) => void | Promise<void>;
|
|
45
|
+
/** The five hooks, each optional. Passed to `auth()` beside the config; `Env` is the adopter's Worker env. */
|
|
46
|
+
export interface UserLifecycleHooks<Env = Record<string, unknown>> {
|
|
44
47
|
/** An account was suspended. */
|
|
45
|
-
readonly onUserSuspended?: UserLifecycleListener
|
|
48
|
+
readonly onUserSuspended?: UserLifecycleListener<Env>;
|
|
46
49
|
/** A suspended account was reinstated. */
|
|
47
|
-
readonly onUserReinstated?: UserLifecycleListener
|
|
50
|
+
readonly onUserReinstated?: UserLifecycleListener<Env>;
|
|
48
51
|
/** An account was deleted — by an operator or by its owner — and its purge window began. */
|
|
49
|
-
readonly onUserDeleted?: UserLifecycleListener
|
|
52
|
+
readonly onUserDeleted?: UserLifecycleListener<Env>;
|
|
53
|
+
/**
|
|
54
|
+
* A deleted account was restored inside its purge window. The undo for whatever `onUserDeleted` did: the account
|
|
55
|
+
* is back, and a suspension it was under is still in force.
|
|
56
|
+
*/
|
|
57
|
+
readonly onUserRestored?: UserLifecycleListener<Env>;
|
|
50
58
|
/** A deleted account's data was erased. The last thing that happens to it. */
|
|
51
|
-
readonly onUserPurged?: UserLifecycleListener
|
|
59
|
+
readonly onUserPurged?: UserLifecycleListener<Env>;
|
|
52
60
|
}
|
|
53
61
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/lifecycle/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/lifecycle/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;;;;GAaG;AAEH,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,kCAAkC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACtF,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,uCAAuC;IACvC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,+FAA+F;IAC/F,QAAQ,CAAC,cAAc,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACtC,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CACjE,KAAK,EAAE,sBAAsB,EAC7B,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,KACtB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B,8GAA8G;AAC9G,MAAM,WAAW,kBAAkB,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/D,gCAAgC;IAChC,QAAQ,CAAC,eAAe,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACtD,0CAA0C;IAC1C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACvD,4FAA4F;IAC5F,QAAQ,CAAC,aAAa,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACpD;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;IACrD,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,CAAC;CACpD"}
|
|
@@ -9,7 +9,8 @@ import type { LifecycleAuditContext, LifecycleDeps } from "./transitions";
|
|
|
9
9
|
*
|
|
10
10
|
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
11
11
|
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
12
|
-
* handed them. A route that assembled its own would be the second
|
|
12
|
+
* handed them, with this request's env and `waitUntil` to run in. A route that assembled its own would be the second
|
|
13
|
+
* place a hook could be forgotten.
|
|
13
14
|
*
|
|
14
15
|
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
15
16
|
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/lifecycle/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/lifecycle/request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,aAAa,CAcf"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { authDatabase } from "../data/tables.js";
|
|
4
|
+
import { requestRuntime } from "../hooks/runtime.js";
|
|
4
5
|
import { resolveDb } from "../http/resolve.js";
|
|
5
6
|
//#region src/lifecycle/request.ts
|
|
6
7
|
/**
|
|
@@ -8,7 +9,8 @@ import { resolveDb } from "../http/resolve.js";
|
|
|
8
9
|
*
|
|
9
10
|
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
10
11
|
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
11
|
-
* handed them. A route that assembled its own would be the second
|
|
12
|
+
* handed them, with this request's env and `waitUntil` to run in. A route that assembled its own would be the second
|
|
13
|
+
* place a hook could be forgotten.
|
|
12
14
|
*
|
|
13
15
|
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
14
16
|
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
@@ -22,6 +24,7 @@ function lifecycleDeps(c, wiring, context) {
|
|
|
22
24
|
emit: c.var.emit,
|
|
23
25
|
config: wiring.config,
|
|
24
26
|
hooks: wiring.lifecycleHooks ?? {},
|
|
27
|
+
runtime: requestRuntime(c),
|
|
25
28
|
enqueueEmail: enqueue ? (input) => enqueue(c.env, input) : void 0,
|
|
26
29
|
log: c.var.log?.child("auth"),
|
|
27
30
|
...context ? { context } : {}
|
|
@@ -7,11 +7,12 @@ import type { EnqueueInput } from "@pithy-sh/email/src/send/enqueue";
|
|
|
7
7
|
import type { AuthConfig } from "../capability";
|
|
8
8
|
import type { AuthDatabase } from "../data/tables";
|
|
9
9
|
import type { UserLifecycleActorType } from "../data/userLifecycle";
|
|
10
|
+
import type { HookRuntime } from "../hooks/runtime";
|
|
10
11
|
import type { UserLifecycleHooks } from "./hooks";
|
|
11
12
|
/**
|
|
12
|
-
* The account-lifecycle transitions — the one place an account's state is ever changed
|
|
13
|
+
* The account-lifecycle transitions — the one place an account's state is ever changed.
|
|
13
14
|
*
|
|
14
|
-
* The admin routes
|
|
15
|
+
* The admin routes, the self-service deletion, and the purge Workflow call these and write
|
|
15
16
|
* nothing themselves, so each transition happens the same way whoever asked for it:
|
|
16
17
|
*
|
|
17
18
|
* 1. **The columns move, conditionally, and the history row is written with them.** The `update` names the
|
|
@@ -52,6 +53,8 @@ export interface LifecycleDeps {
|
|
|
52
53
|
readonly config: Pick<AuthConfig, "retention" | "lifecycleEmails">;
|
|
53
54
|
/** The adopter's hooks. */
|
|
54
55
|
readonly hooks: UserLifecycleHooks;
|
|
56
|
+
/** The Worker the hooks run in: this run's env, and `waitUntil` inside a request. */
|
|
57
|
+
readonly runtime: HookRuntime;
|
|
55
58
|
/** The email capability's enqueue, bound to this run's env. Absent, nothing is mailed. */
|
|
56
59
|
readonly enqueueEmail?: ((input: EnqueueInput) => Promise<unknown>) | undefined;
|
|
57
60
|
/** Where a swallowed failure is reported. Absent, it is swallowed silently. */
|
|
@@ -85,7 +88,7 @@ export interface LifecycleTransition {
|
|
|
85
88
|
/** What a suspension did, and the suspension it left in force. */
|
|
86
89
|
export interface SuspendTransition extends LifecycleTransition {
|
|
87
90
|
/**
|
|
88
|
-
* True when the account was already suspended and this call restated the reason and the end instead
|
|
91
|
+
* True when the account was already suspended and this call restated the reason and the end instead.
|
|
89
92
|
* That is not a transition — `changed` is false and no hook fires — but it is written, audited and mailed.
|
|
90
93
|
*/
|
|
91
94
|
readonly updated: boolean;
|
|
@@ -101,7 +104,7 @@ export interface SuspendTransition extends LifecycleTransition {
|
|
|
101
104
|
* conflict rather than a no-op, and names `restoreRoute` when the caller gives one. A suspension whose end has
|
|
102
105
|
* passed is not in force, and a new one replaces it.
|
|
103
106
|
*
|
|
104
|
-
* **An account already suspended has its terms restated
|
|
107
|
+
* **An account already suspended has its terms restated.** The reason and the end are replaced, a
|
|
105
108
|
* `suspended` row records the new reason — the newest one is what the person is shown — and the audit event
|
|
106
109
|
* and the mail say so. The start is kept, and no hook fires: the account was suspended and still is, so
|
|
107
110
|
* nothing transitioned. A fresh suspension that loses the race to another suspension finds the account
|
|
@@ -163,7 +166,7 @@ export interface DeleteTransition extends LifecycleTransition {
|
|
|
163
166
|
* Restorable until then. The deletion-scheduled mail carries the purge date and, when the config names one,
|
|
164
167
|
* the restore path. A deleted account deleted softly again is no transition.
|
|
165
168
|
*
|
|
166
|
-
* **Hard
|
|
169
|
+
* **Hard**: `purgeAfter` is now, so the window is already closed — nothing can restore it — and the
|
|
167
170
|
* caller starts the purge. No deletion-scheduled mail, because nothing is scheduled; the purge sends the
|
|
168
171
|
* deletion-complete one. An account already deleted softly has its purge brought forward to now, which is
|
|
169
172
|
* written and audited but fires no hook: the account was deleted and still is. One already due is unchanged.
|
|
@@ -192,7 +195,8 @@ export interface RestoreTransition extends LifecycleTransition {
|
|
|
192
195
|
* 404 whose action says the data is gone — read off the history row the purge leaves behind, so it is told
|
|
193
196
|
* apart from an id that never existed.
|
|
194
197
|
*
|
|
195
|
-
* An account that is not deleted is no transition. A suspension it was under is still in force
|
|
198
|
+
* An account that is not deleted is no transition, and fires nothing. A suspension it was under is still in force
|
|
199
|
+
* after. `onUserRestored` fires once the restore is written, so an adopter can undo what it did on `onUserDeleted`.
|
|
196
200
|
*/
|
|
197
201
|
export declare function restoreUser(deps: LifecycleDeps, input: {
|
|
198
202
|
userId: string;
|
|
@@ -200,11 +204,13 @@ export declare function restoreUser(deps: LifecycleDeps, input: {
|
|
|
200
204
|
reason: string | null;
|
|
201
205
|
}): Promise<RestoreTransition>;
|
|
202
206
|
/**
|
|
203
|
-
* The account's
|
|
204
|
-
* purge erased it, and the plain one otherwise. For a route that reads an account outside a transition: the
|
|
205
|
-
* export.
|
|
207
|
+
* The account's stored locale, or the refusal for an account that is not there — the 404 that says the data is gone
|
|
208
|
+
* when the purge erased it, and the plain one otherwise. For a route that reads an account outside a transition: the
|
|
209
|
+
* export, which answers in the person's own language.
|
|
206
210
|
*/
|
|
207
|
-
export declare function requirePresent(db: AuthDatabase, userId: string): Promise<
|
|
211
|
+
export declare function requirePresent(db: AuthDatabase, userId: string): Promise<{
|
|
212
|
+
locale: string | null;
|
|
213
|
+
}>;
|
|
208
214
|
/** Who the purge's last mail goes to, captured before any step erases the address. */
|
|
209
215
|
export interface PurgeRecipient {
|
|
210
216
|
readonly email: string;
|
|
@@ -212,7 +218,7 @@ export interface PurgeRecipient {
|
|
|
212
218
|
readonly locale: string | null;
|
|
213
219
|
}
|
|
214
220
|
/**
|
|
215
|
-
* Whether one account is due for its purge, who its last mail goes to, and whether it goes
|
|
221
|
+
* Whether one account is due for its purge, who its last mail goes to, and whether it goes.
|
|
216
222
|
*
|
|
217
223
|
* `due` only for an account that is deleted and whose `purgeAfter` has passed — the cron and a hard deletion
|
|
218
224
|
* both start a purge, and this is the one check either passes through, so an account restored in between is
|
|
@@ -233,7 +239,7 @@ export declare function purgeSubject(deps: LifecycleDeps, userId: string): Promi
|
|
|
233
239
|
state: "gone";
|
|
234
240
|
}>;
|
|
235
241
|
/**
|
|
236
|
-
* The account's address, as a purge step reads it
|
|
242
|
+
* The account's address, as a purge step reads it — `null` when there is no account, or no address. Read
|
|
237
243
|
* inside the step that asks, so it is never carried in a Workflow's journal.
|
|
238
244
|
*/
|
|
239
245
|
export declare function purgeAddress(db: AuthDatabase, userId: string): Promise<string | null>;
|
|
@@ -243,7 +249,7 @@ export interface DuePurge {
|
|
|
243
249
|
readonly deletedAt: number;
|
|
244
250
|
}
|
|
245
251
|
/**
|
|
246
|
-
* The accounts whose purge is due — deleted, with `purgeAfter` passed — oldest first, at most `limit
|
|
252
|
+
* The accounts whose purge is due — deleted, with `purgeAfter` passed — oldest first, at most `limit`.
|
|
247
253
|
* What the daily cron starts a purge for. An account still inside its window is not here, and neither is one
|
|
248
254
|
* that was restored. Each carries its deletion's start, which names the purge's instance (`../purge/start.ts`).
|
|
249
255
|
*/
|
|
@@ -251,16 +257,18 @@ export declare function duePurges(deps: LifecycleDeps, limit: number): Promise<D
|
|
|
251
257
|
/**
|
|
252
258
|
* Record that one purge step — one capability's contribution — erased its rows. The contribution's summary is
|
|
253
259
|
* the row's reason, so the history says what the step erased and not only that it ran. With `retained`, the step
|
|
254
|
-
* kept its rows instead
|
|
260
|
+
* kept its rows instead: the row is `purge_retained`, its reason is the basis the capability gave, and its
|
|
261
|
+
* `basisKey` the catalog key that translates it, when the capability names one.
|
|
255
262
|
*/
|
|
256
263
|
export declare function recordPurgeStep(deps: LifecycleDeps, input: {
|
|
257
264
|
userId: string;
|
|
258
265
|
step: string;
|
|
259
266
|
summary?: string | null;
|
|
260
267
|
retained?: boolean;
|
|
268
|
+
basisKey?: string;
|
|
261
269
|
}): Promise<void>;
|
|
262
270
|
/**
|
|
263
|
-
* Record that a purge gave up
|
|
271
|
+
* Record that a purge gave up: the step it stopped at, in the history and in the trail. The daily pass starts
|
|
264
272
|
* the purge again tomorrow, so this is where it stands until then, not an end. The failure's message is never
|
|
265
273
|
* written: it is code the kit did not write, and it may name the person.
|
|
266
274
|
*/
|
|
@@ -269,7 +277,7 @@ export declare function recordPurgeFailure(deps: LifecycleDeps, input: {
|
|
|
269
277
|
step: string;
|
|
270
278
|
}): Promise<void>;
|
|
271
279
|
/**
|
|
272
|
-
* The deletion-complete mail, sent **before the address is erased
|
|
280
|
+
* The deletion-complete mail, sent **before the address is erased**. The purge calls this after every
|
|
273
281
|
* other capability's rows are gone and before auth's own, which holds the address, so the last mail is
|
|
274
282
|
* enqueued while there is still an account to have sent it to. The address is handed in, captured before the
|
|
275
283
|
* first step. `notify: false` sends nothing, whatever the config says.
|