@pithy-sh/auth 0.10.0 → 0.12.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/README.md +30 -2
- package/dist/admin/users.js +1 -1
- package/dist/audit/actions.d.ts +58 -0
- package/dist/audit/actions.d.ts.map +1 -1
- package/dist/audit/actions.js +59 -1
- package/dist/audit/emit.d.ts +36 -0
- package/dist/audit/emit.d.ts.map +1 -1
- package/dist/audit/emit.js +48 -2
- package/dist/audit/evidence.d.ts +8 -2
- package/dist/audit/evidence.d.ts.map +1 -1
- package/dist/capability.d.ts +47 -8
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +56 -6
- package/dist/client/api.d.ts +55 -12
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +57 -18
- package/dist/client/bearer.d.ts +110 -0
- package/dist/client/bearer.d.ts.map +1 -0
- package/dist/client/bearer.js +265 -0
- package/dist/client/handoff.d.ts +77 -0
- package/dist/client/handoff.d.ts.map +1 -0
- package/dist/client/handoff.js +119 -0
- package/dist/client/mcp.d.ts +70 -0
- package/dist/client/mcp.d.ts.map +1 -0
- package/dist/client/mcp.js +65 -0
- package/dist/data/betterAuth.d.ts +3 -2
- package/dist/data/betterAuth.d.ts.map +1 -1
- package/dist/data/betterAuth.js +5 -3
- package/dist/data/kitFields.d.ts +5 -0
- package/dist/data/kitFields.d.ts.map +1 -1
- package/dist/data/kitFields.js +5 -0
- package/dist/data/tables.d.ts +26 -4
- package/dist/data/tables.d.ts.map +1 -1
- package/dist/data/tables.js +5 -3
- package/dist/data/userLifecycle.d.ts +10 -0
- package/dist/data/userLifecycle.d.ts.map +1 -1
- package/dist/data/userLifecycle.js +8 -3
- package/dist/data/verificationOutcome.d.ts +53 -0
- package/dist/data/verificationOutcome.d.ts.map +1 -0
- package/dist/data/verificationOutcome.js +50 -0
- package/dist/email/send.js +6 -2
- package/dist/http/adminRoutes.d.ts.map +1 -1
- package/dist/http/adminRoutes.js +319 -8
- package/dist/http/csrf.d.ts.map +1 -1
- package/dist/http/csrf.js +2 -1
- package/dist/http/guards.d.ts +15 -10
- package/dist/http/guards.d.ts.map +1 -1
- package/dist/http/guards.js +76 -10
- package/dist/http/handoff.d.ts +76 -0
- package/dist/http/handoff.d.ts.map +1 -0
- package/dist/http/handoff.js +316 -0
- package/dist/http/middleware.d.ts +37 -1
- package/dist/http/middleware.d.ts.map +1 -1
- package/dist/http/middleware.js +68 -6
- package/dist/http/resolve.d.ts.map +1 -1
- package/dist/http/resolve.js +9 -3
- package/dist/http/responses.d.ts +322 -0
- package/dist/http/responses.d.ts.map +1 -1
- package/dist/http/responses.js +202 -5
- package/dist/http/routes.d.ts +3 -0
- package/dist/http/routes.d.ts.map +1 -1
- package/dist/http/routes.js +78 -5
- package/dist/http/schemas.d.ts +114 -0
- package/dist/http/schemas.d.ts.map +1 -1
- package/dist/http/schemas.js +94 -1
- package/dist/http/views.d.ts +60 -3
- package/dist/http/views.d.ts.map +1 -1
- package/dist/http/views.js +143 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/instance/auth.d.ts +148 -10
- package/dist/instance/auth.d.ts.map +1 -1
- package/dist/instance/auth.js +87 -42
- package/dist/instance/plugins.d.ts +6 -0
- package/dist/instance/plugins.d.ts.map +1 -1
- package/dist/instance/plugins.js +14 -1
- package/dist/ledger/read.d.ts +53 -0
- package/dist/ledger/read.d.ts.map +1 -0
- package/dist/ledger/read.js +85 -0
- package/dist/ledger/record.d.ts +35 -0
- package/dist/ledger/record.d.ts.map +1 -0
- package/dist/ledger/record.js +98 -0
- package/dist/lifecycle/audited.d.ts +48 -0
- package/dist/lifecycle/audited.d.ts.map +1 -0
- package/dist/lifecycle/audited.js +65 -0
- package/dist/lifecycle/enforce.d.ts +37 -2
- package/dist/lifecycle/enforce.d.ts.map +1 -1
- package/dist/lifecycle/enforce.js +46 -5
- package/dist/lifecycle/erasure.d.ts +9 -0
- package/dist/lifecycle/erasure.d.ts.map +1 -0
- package/dist/lifecycle/erasure.js +96 -0
- package/dist/lifecycle/inactivity.d.ts +19 -0
- package/dist/lifecycle/inactivity.d.ts.map +1 -0
- package/dist/lifecycle/inactivity.js +28 -0
- package/dist/lifecycle/reason.d.ts +11 -0
- package/dist/lifecycle/reason.d.ts.map +1 -0
- package/dist/lifecycle/reason.js +13 -0
- package/dist/lifecycle/request.d.ts +5 -2
- package/dist/lifecycle/request.d.ts.map +1 -1
- package/dist/lifecycle/request.js +6 -2
- package/dist/lifecycle/transitions.d.ts +179 -18
- package/dist/lifecycle/transitions.d.ts.map +1 -1
- package/dist/lifecycle/transitions.js +391 -70
- package/dist/mcp/argumentClass.d.ts +51 -0
- package/dist/mcp/argumentClass.d.ts.map +1 -0
- package/dist/mcp/argumentClass.js +69 -0
- package/dist/mcp/capability.d.ts +50 -0
- package/dist/mcp/capability.d.ts.map +1 -0
- package/dist/mcp/capability.js +140 -0
- package/dist/mcp/clientMetadata.d.ts +40 -0
- package/dist/mcp/clientMetadata.d.ts.map +1 -0
- package/dist/mcp/clientMetadata.js +68 -0
- package/dist/mcp/consent.d.ts +49 -0
- package/dist/mcp/consent.d.ts.map +1 -0
- package/dist/mcp/consent.js +69 -0
- package/dist/mcp/dispatch.d.ts +35 -0
- package/dist/mcp/dispatch.d.ts.map +1 -0
- package/dist/mcp/dispatch.js +135 -0
- package/dist/mcp/floor.d.ts +37 -0
- package/dist/mcp/floor.d.ts.map +1 -0
- package/dist/mcp/floor.js +41 -0
- package/dist/mcp/host.d.ts +34 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +2 -0
- package/dist/mcp/http/redirectList.d.ts +9 -0
- package/dist/mcp/http/redirectList.d.ts.map +1 -0
- package/dist/mcp/http/redirectList.js +24 -0
- package/dist/mcp/http/responses.d.ts +143 -0
- package/dist/mcp/http/responses.d.ts.map +1 -0
- package/dist/mcp/http/responses.js +83 -0
- package/dist/mcp/http/routes.d.ts +28 -0
- package/dist/mcp/http/routes.d.ts.map +1 -0
- package/dist/mcp/http/routes.js +517 -0
- package/dist/mcp/http/schemas.d.ts +24 -0
- package/dist/mcp/http/schemas.d.ts.map +1 -0
- package/dist/mcp/http/schemas.js +18 -0
- package/dist/mcp/marker.d.ts +15 -0
- package/dist/mcp/marker.d.ts.map +1 -0
- package/dist/mcp/marker.js +15 -0
- package/dist/mcp/provider.d.ts +78 -0
- package/dist/mcp/provider.d.ts.map +1 -0
- package/dist/mcp/provider.js +108 -0
- package/dist/mcp/purge.d.ts +15 -0
- package/dist/mcp/purge.d.ts.map +1 -0
- package/dist/mcp/purge.js +31 -0
- package/dist/mcp/rpc.d.ts +79 -0
- package/dist/mcp/rpc.d.ts.map +1 -0
- package/dist/mcp/rpc.js +103 -0
- package/dist/mcp/toolAudit.d.ts +76 -0
- package/dist/mcp/toolAudit.d.ts.map +1 -0
- package/dist/mcp/toolAudit.js +86 -0
- package/dist/migrations/0005_purge_once.d.ts +22 -0
- package/dist/migrations/0005_purge_once.d.ts.map +1 -0
- package/dist/migrations/0005_purge_once.js +35 -0
- package/dist/migrations/0006_verification_outcomes.d.ts +15 -0
- package/dist/migrations/0006_verification_outcomes.d.ts.map +1 -0
- package/dist/migrations/0006_verification_outcomes.js +35 -0
- package/dist/migrations/0007_erasure_record.d.ts +17 -0
- package/dist/migrations/0007_erasure_record.d.ts.map +1 -0
- package/dist/migrations/0007_erasure_record.js +36 -0
- package/dist/migrations/0008_last_active.d.ts +15 -0
- package/dist/migrations/0008_last_active.d.ts.map +1 -0
- package/dist/migrations/0008_last_active.js +29 -0
- package/dist/migrations/pluginTables.d.ts +8 -0
- package/dist/migrations/pluginTables.d.ts.map +1 -1
- package/dist/migrations/pluginTables.js +8 -1
- package/dist/migrations/set.d.ts +5 -1
- package/dist/migrations/set.d.ts.map +1 -1
- package/dist/migrations/set.js +10 -2
- package/dist/peer.d.ts +3 -2
- package/dist/peer.d.ts.map +1 -1
- package/dist/processing/activities.d.ts +6 -0
- package/dist/processing/activities.d.ts.map +1 -0
- package/dist/processing/activities.js +12 -0
- package/dist/purge/contribution.d.ts +62 -0
- package/dist/purge/contribution.d.ts.map +1 -0
- package/dist/purge/contribution.js +155 -0
- package/dist/purge/retryPolicy.d.ts +22 -0
- package/dist/purge/retryPolicy.d.ts.map +1 -0
- package/dist/purge/retryPolicy.js +26 -0
- package/dist/purge/run.d.ts +158 -0
- package/dist/purge/run.d.ts.map +1 -0
- package/dist/purge/run.js +205 -0
- package/dist/purge/specs.d.ts +71 -0
- package/dist/purge/specs.d.ts.map +1 -0
- package/dist/purge/specs.js +72 -0
- package/dist/purge/start.d.ts +42 -0
- package/dist/purge/start.d.ts.map +1 -0
- package/dist/purge/start.js +37 -0
- package/dist/purge/workflow.d.ts +71 -0
- package/dist/purge/workflow.d.ts.map +1 -0
- package/dist/purge/workflow.js +140 -0
- package/dist/test-utils/accountFootprint.d.ts +13 -0
- package/dist/test-utils/accountFootprint.d.ts.map +1 -0
- package/dist/test-utils/accountFootprint.js +49 -0
- package/dist/test-utils/liveApp.d.ts +6 -0
- package/dist/test-utils/liveApp.d.ts.map +1 -1
- package/dist/test-utils/liveApp.js +7 -2
- package/dist/token/handoff.d.ts +80 -0
- package/dist/token/handoff.d.ts.map +1 -0
- package/dist/token/handoff.js +136 -0
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +1 -1
- package/docs/account-lifecycle.md +176 -12
- package/docs/apple-signin.md +32 -4
- package/docs/facebook-oauth.md +2 -2
- package/docs/github-oauth.md +2 -2
- package/docs/google-oauth.md +9 -7
- package/docs/microsoft-oauth.md +2 -2
- package/package.json +11 -5
- package/pithy.manifest.json +2 -2
- package/pithy.mcp.manifest.json +36 -0
- package/src/audit/actions.ts +58 -0
- package/src/audit/emit.ts +66 -1
- package/src/audit/evidence.ts +8 -4
- package/src/capability.ts +122 -18
- package/src/client/api.ts +69 -19
- package/src/client/bearer.ts +388 -0
- package/src/client/handoff.ts +172 -0
- package/src/client/mcp.ts +140 -0
- package/src/data/betterAuth.ts +8 -4
- package/src/data/kitFields.ts +2 -0
- package/src/data/tables.ts +4 -2
- package/src/data/userLifecycle.ts +19 -4
- package/src/data/verificationOutcome.ts +86 -0
- package/src/email/send.ts +2 -2
- package/src/http/adminRoutes.ts +465 -4
- package/src/http/csrf.ts +4 -1
- package/src/http/guards.ts +79 -10
- package/src/http/handoff.ts +350 -0
- package/src/http/middleware.ts +74 -5
- package/src/http/resolve.ts +25 -25
- package/src/http/responses.ts +374 -3
- package/src/http/routes.ts +116 -5
- package/src/http/schemas.ts +195 -0
- package/src/http/views.ts +192 -3
- package/src/index.ts +2 -0
- package/src/instance/auth.ts +58 -3
- package/src/instance/plugins.ts +20 -2
- package/src/ledger/read.ts +133 -0
- package/src/ledger/record.ts +198 -0
- package/src/lifecycle/audited.ts +104 -0
- package/src/lifecycle/enforce.ts +55 -5
- package/src/lifecycle/erasure.ts +118 -0
- package/src/lifecycle/inactivity.ts +56 -0
- package/src/lifecycle/reason.ts +11 -0
- package/src/lifecycle/request.ts +10 -2
- package/src/lifecycle/transitions.ts +552 -93
- package/src/mcp/argumentClass.ts +112 -0
- package/src/mcp/capability.ts +194 -0
- package/src/mcp/clientMetadata.ts +81 -0
- package/src/mcp/consent.ts +95 -0
- package/src/mcp/dispatch.ts +154 -0
- package/src/mcp/floor.ts +62 -0
- package/src/mcp/host.ts +36 -0
- package/src/mcp/http/redirectList.ts +26 -0
- package/src/mcp/http/responses.ts +157 -0
- package/src/mcp/http/routes.ts +635 -0
- package/src/mcp/http/schemas.ts +37 -0
- package/src/mcp/marker.ts +18 -0
- package/src/mcp/provider.ts +151 -0
- package/src/mcp/purge.ts +39 -0
- package/src/mcp/rpc.ts +135 -0
- package/src/mcp/toolAudit.ts +132 -0
- package/src/migrations/0005_purge_once.ts +42 -0
- package/src/migrations/0006_verification_outcomes.ts +51 -0
- package/src/migrations/0007_erasure_record.ts +43 -0
- package/src/migrations/0008_last_active.ts +30 -0
- package/src/migrations/pluginTables.ts +19 -1
- package/src/migrations/set.ts +9 -1
- package/src/processing/activities.ts +14 -0
- package/src/purge/contribution.ts +218 -0
- package/src/purge/retryPolicy.ts +26 -0
- package/src/purge/run.ts +348 -0
- package/src/purge/specs.ts +95 -0
- package/src/purge/start.ts +79 -0
- package/src/purge/workflow.ts +202 -0
- package/src/seeds/example.ts +2 -2
- package/src/test-utils/accountFootprint.ts +104 -0
- package/src/test-utils/liveApp.ts +10 -1
- package/src/token/handoff.ts +180 -0
- package/src/version.generated.ts +1 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { ErasureHistoryReader, ErasureHistoryRow, ErasureRecords } from "@pithy-sh/core/src/capability/erasure";
|
|
5
|
+
import { SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
6
|
+
import { AuthAuditActions } from "../audit/actions";
|
|
7
|
+
import { type AuthDatabase, authDatabase } from "../data/tables";
|
|
8
|
+
import { UserLifecycleEvent } from "../data/userLifecycle";
|
|
9
|
+
import { resolveDb } from "../http/resolve";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* **A user's erasure record, read back for the control plane's attestation (#823).**
|
|
13
|
+
*
|
|
14
|
+
* `pithy_auth_user_lifecycle` is the one `pithy_auth_*` table a purge leaves behind, and it names the account by id
|
|
15
|
+
* and nothing else. This reads the rows an erasure is made of — the deletion, any restore, each step, a failure, the
|
|
16
|
+
* end — and hands them to core through the {@link ErasureRecords} seam, so the control plane never imports auth.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** The rows an erasure is made of. A suspension is not one. */
|
|
20
|
+
const ERASURE_ACTIONS = ["deleted", "restored", "purge_step", "purge_retained", "purge_failed", "purged"] as const;
|
|
21
|
+
|
|
22
|
+
/** The rows that are the purge itself, rather than the deletion it runs under. */
|
|
23
|
+
const PURGE_ACTIONS = ["purge_step", "purge_retained", "purge_failed", "purged"] as const;
|
|
24
|
+
|
|
25
|
+
/** The rows that end a deletion: its purge finishing, or the subject coming back. */
|
|
26
|
+
const CLOSING_ACTIONS = ["purged", "restored"] as const;
|
|
27
|
+
|
|
28
|
+
/** The reader, over one auth database. */
|
|
29
|
+
export function userErasureReader(db: AuthDatabase): ErasureHistoryReader {
|
|
30
|
+
return {
|
|
31
|
+
history: async (userIds) => {
|
|
32
|
+
if (userIds.length === 0) return [];
|
|
33
|
+
const rows = await db
|
|
34
|
+
.selectFrom("pithyAuthUserLifecycle")
|
|
35
|
+
.selectAll()
|
|
36
|
+
.where("userId", "in", [...userIds])
|
|
37
|
+
.where("action", "in", [...ERASURE_ACTIONS])
|
|
38
|
+
.orderBy("id", "asc")
|
|
39
|
+
.execute();
|
|
40
|
+
return rows.map((raw): ErasureHistoryRow => {
|
|
41
|
+
const row = UserLifecycleEvent.parse(raw);
|
|
42
|
+
return {
|
|
43
|
+
subjectId: row.userId,
|
|
44
|
+
action: row.action as ErasureHistoryRow["action"],
|
|
45
|
+
actorType: row.actorType,
|
|
46
|
+
reason: row.reason,
|
|
47
|
+
step: row.step,
|
|
48
|
+
mode: row.mode,
|
|
49
|
+
purgeAfter: row.purgeAfter,
|
|
50
|
+
at: row.createdAt,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
subjectsIn: async (since, until) => {
|
|
55
|
+
const from = SQLiteDate.encode(since);
|
|
56
|
+
const to = SQLiteDate.encode(until);
|
|
57
|
+
const rows = await db
|
|
58
|
+
.selectFrom("pithyAuthUserLifecycle as row")
|
|
59
|
+
.select("row.userId")
|
|
60
|
+
.distinct()
|
|
61
|
+
.where((eb) =>
|
|
62
|
+
eb.or([
|
|
63
|
+
eb.and([
|
|
64
|
+
eb("row.action", "in", [...PURGE_ACTIONS]),
|
|
65
|
+
eb("row.createdAt", ">=", from),
|
|
66
|
+
eb("row.createdAt", "<=", to),
|
|
67
|
+
]),
|
|
68
|
+
eb.and([
|
|
69
|
+
eb("row.action", "=", "deleted"),
|
|
70
|
+
eb("row.purgeAfter", ">=", from),
|
|
71
|
+
eb("row.purgeAfter", "<=", to),
|
|
72
|
+
]),
|
|
73
|
+
// Outstanding in the window: due by its end, or recorded before the due instant was, and neither purged
|
|
74
|
+
// nor restored before it opened. A purge that came due earlier and has written nothing since is the one
|
|
75
|
+
// the period read exists to name.
|
|
76
|
+
eb.and([
|
|
77
|
+
eb("row.action", "=", "deleted"),
|
|
78
|
+
eb("row.createdAt", "<=", to),
|
|
79
|
+
eb.or([eb("row.purgeAfter", "<=", to), eb("row.purgeAfter", "is", null)]),
|
|
80
|
+
eb.not(
|
|
81
|
+
eb.exists(
|
|
82
|
+
eb
|
|
83
|
+
.selectFrom("pithyAuthUserLifecycle as closed")
|
|
84
|
+
.select("closed.id")
|
|
85
|
+
.whereRef("closed.userId", "=", "row.userId")
|
|
86
|
+
.whereRef("closed.id", ">", "row.id")
|
|
87
|
+
.where("closed.action", "in", [...CLOSING_ACTIONS])
|
|
88
|
+
.where("closed.createdAt", "<", from),
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
]),
|
|
92
|
+
]),
|
|
93
|
+
)
|
|
94
|
+
.orderBy("row.userId")
|
|
95
|
+
.execute();
|
|
96
|
+
return rows.map((row) => row.userId);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What auth declares: the `user` subject, the actions its purge records, and the reader over its database. */
|
|
102
|
+
export function authErasureRecords(database: string): ErasureRecords {
|
|
103
|
+
return {
|
|
104
|
+
subject: "user",
|
|
105
|
+
resourceType: "user",
|
|
106
|
+
auditActions: {
|
|
107
|
+
deleted: [
|
|
108
|
+
AuthAuditActions.adminUserSoftDeleted,
|
|
109
|
+
AuthAuditActions.adminUserHardDeleted,
|
|
110
|
+
AuthAuditActions.userSelfDeleted,
|
|
111
|
+
],
|
|
112
|
+
step: AuthAuditActions.adminUserPurgeStep,
|
|
113
|
+
failed: AuthAuditActions.adminUserPurgeFailed,
|
|
114
|
+
purged: AuthAuditActions.adminUserPurged,
|
|
115
|
+
},
|
|
116
|
+
read: (env) => userErasureReader(authDatabase(resolveDb(env, database))),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { SQLiteDate } from "@pithy-sh/core/src/data/codecs";
|
|
5
|
+
import type { AuthDatabase } from "../data/tables";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* **Inactivity, as the retention policy's class ages count it.**
|
|
9
|
+
*
|
|
10
|
+
* An account is active when it opens a session: a sign-in, or a token refresh. Each one stamps `lastActiveAt` on the
|
|
11
|
+
* account, and a live session refreshed since counts too. An account untouched for longer than the strictest class
|
|
12
|
+
* age it holds is soft-deleted through the lifecycle — `../purge/run.ts` runs the pass — with the same notice mail,
|
|
13
|
+
* the same window and the same purge as any other deletion.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Stamp an account active now. Moves the clock forward only, so a late write never makes it look older. */
|
|
17
|
+
export async function recordActivity(db: AuthDatabase, userId: string, at: Date): Promise<void> {
|
|
18
|
+
const ms = SQLiteDate.encode(at);
|
|
19
|
+
await db
|
|
20
|
+
.updateTable("pithyAuthUsers")
|
|
21
|
+
.set({ lastActiveAt: ms })
|
|
22
|
+
.where("id", "=", userId)
|
|
23
|
+
.where((eb) => eb.or([eb("lastActiveAt", "is", null), eb("lastActiveAt", "<", ms)]))
|
|
24
|
+
.execute();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The accounts inactive since `cutoff`, oldest first, at most `limit`: not deleted, last active before it (or, never
|
|
29
|
+
* stamped, created before it), and holding no session refreshed since.
|
|
30
|
+
*/
|
|
31
|
+
export async function inactiveAccounts(db: AuthDatabase, cutoff: Date, limit: number): Promise<string[]> {
|
|
32
|
+
const ms = SQLiteDate.encode(cutoff);
|
|
33
|
+
const iso = cutoff.toISOString();
|
|
34
|
+
const rows = await db
|
|
35
|
+
.selectFrom("pithyAuthUsers")
|
|
36
|
+
.select("id")
|
|
37
|
+
.where("deletedAt", "is", null)
|
|
38
|
+
.where((eb) =>
|
|
39
|
+
eb.or([eb("lastActiveAt", "<", ms), eb.and([eb("lastActiveAt", "is", null), eb("createdAt", "<", iso)])]),
|
|
40
|
+
)
|
|
41
|
+
.where(({ not, exists, selectFrom }) =>
|
|
42
|
+
not(
|
|
43
|
+
exists(
|
|
44
|
+
selectFrom("pithyAuthSessions")
|
|
45
|
+
.select("pithyAuthSessions.id")
|
|
46
|
+
.whereRef("pithyAuthSessions.userId", "=", "pithyAuthUsers.id")
|
|
47
|
+
.where("pithyAuthSessions.updatedAt", ">=", iso),
|
|
48
|
+
),
|
|
49
|
+
),
|
|
50
|
+
)
|
|
51
|
+
.orderBy("lastActiveAt", "asc")
|
|
52
|
+
.orderBy("id", "asc")
|
|
53
|
+
.limit(limit)
|
|
54
|
+
.execute();
|
|
55
|
+
return rows.map((row) => row.id);
|
|
56
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 Pithy
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The longest reason the kit stores. It is shown to the person, so it is a sentence, not a case file.
|
|
6
|
+
*
|
|
7
|
+
* A leaf with no imports, because two programs read it: the transitions, which refuse a longer one, and the
|
|
8
|
+
* request schemas in `../http/schemas.ts`, which a browser program compiles (`tooling/browser-scopes`). Kept
|
|
9
|
+
* in `./transitions.ts`, it pulled the email capability and the Workers types into that program (#621).
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_REASON = 500;
|
package/src/lifecycle/request.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Context } from "hono";
|
|
|
7
7
|
import type { AuthWiring } from "../capability";
|
|
8
8
|
import { authDatabase } from "../data/tables";
|
|
9
9
|
import { resolveDb } from "../http/resolve";
|
|
10
|
-
import type { LifecycleDeps } from "./transitions";
|
|
10
|
+
import type { LifecycleAuditContext, LifecycleDeps } from "./transitions";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The transitions' dependencies, resolved from one request — what a lifecycle route hands `./transitions.ts`.
|
|
@@ -15,8 +15,15 @@ import type { LifecycleDeps } from "./transitions";
|
|
|
15
15
|
* One function so every route resolves them the same way: this request's database, its audit seam and logger,
|
|
16
16
|
* the composed email capability's enqueue bound to this request's env, and the adopter's hooks as `auth()` was
|
|
17
17
|
* handed them. A route that assembled its own would be the second place a hook could be forgotten.
|
|
18
|
+
*
|
|
19
|
+
* `context` is what the caller adds to each audit event: the request's correlation, and for a management call
|
|
20
|
+
* the connection it came through. The caller passes it because only the caller knows who it is.
|
|
18
21
|
*/
|
|
19
|
-
export function lifecycleDeps(
|
|
22
|
+
export function lifecycleDeps(
|
|
23
|
+
c: Context<PithyHonoEnv>,
|
|
24
|
+
wiring: AuthWiring,
|
|
25
|
+
context?: LifecycleAuditContext,
|
|
26
|
+
): LifecycleDeps {
|
|
20
27
|
const d1 = resolveDb(c.env, wiring.config.database);
|
|
21
28
|
const enqueue = wiring.enqueueEmail;
|
|
22
29
|
return {
|
|
@@ -27,5 +34,6 @@ export function lifecycleDeps(c: Context<PithyHonoEnv>, wiring: AuthWiring): Lif
|
|
|
27
34
|
hooks: wiring.lifecycleHooks ?? {},
|
|
28
35
|
enqueueEmail: enqueue ? (input) => enqueue(c.env as unknown as EmailEnqueueEnv, input) : undefined,
|
|
29
36
|
log: c.var.log?.child("auth"),
|
|
37
|
+
...(context ? { context } : {}),
|
|
30
38
|
};
|
|
31
39
|
}
|