@pithy-sh/auth 0.10.0 → 0.11.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.
Files changed (116) hide show
  1. package/README.md +1 -1
  2. package/dist/admin/users.js +1 -1
  3. package/dist/audit/actions.d.ts +19 -0
  4. package/dist/audit/actions.d.ts.map +1 -1
  5. package/dist/audit/actions.js +20 -1
  6. package/dist/audit/emit.d.ts +2 -0
  7. package/dist/audit/emit.d.ts.map +1 -1
  8. package/dist/audit/emit.js +1 -1
  9. package/dist/capability.d.ts +19 -0
  10. package/dist/capability.d.ts.map +1 -1
  11. package/dist/capability.js +20 -3
  12. package/dist/data/tables.d.ts +1 -0
  13. package/dist/data/tables.d.ts.map +1 -1
  14. package/dist/data/userLifecycle.d.ts +1 -0
  15. package/dist/data/userLifecycle.d.ts.map +1 -1
  16. package/dist/data/userLifecycle.js +2 -1
  17. package/dist/http/adminRoutes.d.ts.map +1 -1
  18. package/dist/http/adminRoutes.js +270 -5
  19. package/dist/http/guards.d.ts +8 -7
  20. package/dist/http/guards.d.ts.map +1 -1
  21. package/dist/http/guards.js +38 -7
  22. package/dist/http/middleware.d.ts +25 -1
  23. package/dist/http/middleware.d.ts.map +1 -1
  24. package/dist/http/middleware.js +44 -3
  25. package/dist/http/responses.d.ts +180 -0
  26. package/dist/http/responses.d.ts.map +1 -1
  27. package/dist/http/responses.js +142 -1
  28. package/dist/http/routes.d.ts +1 -0
  29. package/dist/http/routes.d.ts.map +1 -1
  30. package/dist/http/routes.js +45 -3
  31. package/dist/http/schemas.d.ts +57 -0
  32. package/dist/http/schemas.d.ts.map +1 -1
  33. package/dist/http/schemas.js +51 -1
  34. package/dist/http/views.d.ts +39 -2
  35. package/dist/http/views.d.ts.map +1 -1
  36. package/dist/http/views.js +105 -1
  37. package/dist/instance/auth.d.ts.map +1 -1
  38. package/dist/instance/auth.js +2 -2
  39. package/dist/lifecycle/audited.d.ts +48 -0
  40. package/dist/lifecycle/audited.d.ts.map +1 -0
  41. package/dist/lifecycle/audited.js +65 -0
  42. package/dist/lifecycle/enforce.d.ts +37 -2
  43. package/dist/lifecycle/enforce.d.ts.map +1 -1
  44. package/dist/lifecycle/enforce.js +46 -5
  45. package/dist/lifecycle/reason.d.ts +11 -0
  46. package/dist/lifecycle/reason.d.ts.map +1 -0
  47. package/dist/lifecycle/reason.js +13 -0
  48. package/dist/lifecycle/request.d.ts +5 -2
  49. package/dist/lifecycle/request.d.ts.map +1 -1
  50. package/dist/lifecycle/request.js +6 -2
  51. package/dist/lifecycle/transitions.d.ts +158 -18
  52. package/dist/lifecycle/transitions.d.ts.map +1 -1
  53. package/dist/lifecycle/transitions.js +344 -70
  54. package/dist/migrations/0005_purge_once.d.ts +22 -0
  55. package/dist/migrations/0005_purge_once.d.ts.map +1 -0
  56. package/dist/migrations/0005_purge_once.js +35 -0
  57. package/dist/migrations/pluginTables.d.ts +8 -0
  58. package/dist/migrations/pluginTables.d.ts.map +1 -1
  59. package/dist/migrations/pluginTables.js +8 -1
  60. package/dist/migrations/set.d.ts +2 -1
  61. package/dist/migrations/set.d.ts.map +1 -1
  62. package/dist/migrations/set.js +4 -2
  63. package/dist/purge/contribution.d.ts +47 -0
  64. package/dist/purge/contribution.d.ts.map +1 -0
  65. package/dist/purge/contribution.js +141 -0
  66. package/dist/purge/retryPolicy.d.ts +22 -0
  67. package/dist/purge/retryPolicy.d.ts.map +1 -0
  68. package/dist/purge/retryPolicy.js +26 -0
  69. package/dist/purge/run.d.ts +88 -0
  70. package/dist/purge/run.d.ts.map +1 -0
  71. package/dist/purge/run.js +102 -0
  72. package/dist/purge/specs.d.ts +71 -0
  73. package/dist/purge/specs.d.ts.map +1 -0
  74. package/dist/purge/specs.js +72 -0
  75. package/dist/purge/start.d.ts +42 -0
  76. package/dist/purge/start.d.ts.map +1 -0
  77. package/dist/purge/start.js +37 -0
  78. package/dist/purge/workflow.d.ts +58 -0
  79. package/dist/purge/workflow.d.ts.map +1 -0
  80. package/dist/purge/workflow.js +96 -0
  81. package/dist/test-utils/accountFootprint.d.ts +10 -0
  82. package/dist/test-utils/accountFootprint.d.ts.map +1 -0
  83. package/dist/test-utils/accountFootprint.js +44 -0
  84. package/dist/version.generated.d.ts +1 -1
  85. package/dist/version.generated.js +1 -1
  86. package/docs/account-lifecycle.md +123 -11
  87. package/package.json +5 -5
  88. package/pithy.manifest.json +1 -1
  89. package/src/audit/actions.ts +19 -0
  90. package/src/audit/emit.ts +3 -1
  91. package/src/capability.ts +48 -1
  92. package/src/data/userLifecycle.ts +4 -1
  93. package/src/http/adminRoutes.ts +398 -2
  94. package/src/http/guards.ts +39 -7
  95. package/src/http/middleware.ts +45 -2
  96. package/src/http/responses.ts +245 -0
  97. package/src/http/routes.ts +55 -3
  98. package/src/http/schemas.ts +110 -0
  99. package/src/http/views.ts +147 -2
  100. package/src/instance/auth.ts +7 -2
  101. package/src/lifecycle/audited.ts +104 -0
  102. package/src/lifecycle/enforce.ts +55 -5
  103. package/src/lifecycle/reason.ts +11 -0
  104. package/src/lifecycle/request.ts +10 -2
  105. package/src/lifecycle/transitions.ts +482 -93
  106. package/src/migrations/0005_purge_once.ts +42 -0
  107. package/src/migrations/pluginTables.ts +19 -1
  108. package/src/migrations/set.ts +3 -1
  109. package/src/purge/contribution.ts +191 -0
  110. package/src/purge/retryPolicy.ts +26 -0
  111. package/src/purge/run.ts +185 -0
  112. package/src/purge/specs.ts +95 -0
  113. package/src/purge/start.ts +79 -0
  114. package/src/purge/workflow.ts +144 -0
  115. package/src/test-utils/accountFootprint.ts +95 -0
  116. package/src/version.generated.ts +1 -1
@@ -151,6 +151,176 @@ export declare const AdminDeviceRevokeResponse: z.ZodObject<{
151
151
  removed: z.ZodBoolean;
152
152
  }, z.core.$strip>;
153
153
  export type AdminDeviceRevokeResponse = z.output<typeof AdminDeviceRevokeResponse>;
154
+ /**
155
+ * `POST {base}/admin/users/:userId/suspend` (#621).
156
+ *
157
+ * The suspension the account is now under, how many sessions ended with it, and whether the person was told.
158
+ * Not the reason: the caller wrote it, the trail keeps it, and echoing it back would put it in one more place
159
+ * a dashboard logs.
160
+ */
161
+ export declare const AdminUserSuspendResponse: z.ZodObject<{
162
+ userId: z.ZodString;
163
+ state: z.ZodLiteral<"suspended">;
164
+ outcome: z.ZodEnum<{
165
+ suspended: "suspended";
166
+ updated: "updated";
167
+ }>;
168
+ suspendedAt: z.ZodISODateTime;
169
+ suspendedUntil: z.ZodNullable<z.ZodISODateTime>;
170
+ sessionsRevoked: z.ZodNumber;
171
+ mailed: z.ZodBoolean;
172
+ }, z.core.$strip>;
173
+ export type AdminUserSuspendResponse = z.output<typeof AdminUserSuspendResponse>;
174
+ /**
175
+ * `POST {base}/admin/users/:userId/reinstate` (#621).
176
+ *
177
+ * No session count: a reinstatement restores none. The person signs in again.
178
+ */
179
+ export declare const AdminUserReinstateResponse: z.ZodObject<{
180
+ userId: z.ZodString;
181
+ state: z.ZodLiteral<"active">;
182
+ outcome: z.ZodEnum<{
183
+ reinstated: "reinstated";
184
+ unchanged: "unchanged";
185
+ }>;
186
+ mailed: z.ZodBoolean;
187
+ }, z.core.$strip>;
188
+ export type AdminUserReinstateResponse = z.output<typeof AdminUserReinstateResponse>;
189
+ /**
190
+ * `DELETE {base}/admin/users/:userId` (#622).
191
+ *
192
+ * What the deletion left in force, how many sessions ended with it, whether the person was told, and what
193
+ * became of the purge. Not the reason: the caller wrote it and the trail keeps it.
194
+ */
195
+ export declare const AdminUserDeleteResponse: z.ZodObject<{
196
+ userId: z.ZodString;
197
+ state: z.ZodLiteral<"deleted">;
198
+ mode: z.ZodEnum<{
199
+ hard: "hard";
200
+ soft: "soft";
201
+ }>;
202
+ outcome: z.ZodEnum<{
203
+ brought_forward: "brought_forward";
204
+ deleted: "deleted";
205
+ unchanged: "unchanged";
206
+ }>;
207
+ deletedAt: z.ZodISODateTime;
208
+ purgeAfter: z.ZodISODateTime;
209
+ purge: z.ZodEnum<{
210
+ pending: "pending";
211
+ scheduled: "scheduled";
212
+ started: "started";
213
+ }>;
214
+ sessionsRevoked: z.ZodNumber;
215
+ mailed: z.ZodBoolean;
216
+ }, z.core.$strip>;
217
+ export type AdminUserDeleteResponse = z.output<typeof AdminUserDeleteResponse>;
218
+ /**
219
+ * `POST {base}/admin/users/:userId/restore` (#622). No session count: a restoration restores none.
220
+ */
221
+ export declare const AdminUserRestoreResponse: z.ZodObject<{
222
+ userId: z.ZodString;
223
+ state: z.ZodEnum<{
224
+ active: "active";
225
+ suspended: "suspended";
226
+ }>;
227
+ outcome: z.ZodEnum<{
228
+ restored: "restored";
229
+ unchanged: "unchanged";
230
+ }>;
231
+ }, z.core.$strip>;
232
+ export type AdminUserRestoreResponse = z.output<typeof AdminUserRestoreResponse>;
233
+ /**
234
+ * What `@pithy-sh/auth` holds about one account, as its purge contribution exports it (#622) — the `data` of
235
+ * the `auth` entry in an export.
236
+ *
237
+ * The person's own data and none of their credentials: no session token, no provider token, no push token.
238
+ * Every list is whole, because an export that stopped at a bound would answer an access request with part of
239
+ * an answer.
240
+ */
241
+ export declare const AuthUserExport: z.ZodObject<{
242
+ user: z.ZodObject<{
243
+ id: z.ZodString;
244
+ email: z.ZodString;
245
+ name: z.ZodString;
246
+ emailVerified: z.ZodBoolean;
247
+ image: z.ZodNullable<z.ZodString>;
248
+ locale: z.ZodOptional<z.ZodNullable<z.ZodString>>;
249
+ createdAt: z.ZodISODateTime;
250
+ updatedAt: z.ZodISODateTime;
251
+ suspendedAt: z.ZodNullable<z.ZodISODateTime>;
252
+ suspendedUntil: z.ZodNullable<z.ZodISODateTime>;
253
+ deletedAt: z.ZodNullable<z.ZodISODateTime>;
254
+ purgeAfter: z.ZodNullable<z.ZodISODateTime>;
255
+ }, z.core.$strip>;
256
+ sessions: z.ZodArray<z.ZodObject<{
257
+ id: z.ZodString;
258
+ deviceId: z.ZodNullable<z.ZodString>;
259
+ ipAddress: z.ZodNullable<z.ZodString>;
260
+ userAgent: z.ZodNullable<z.ZodString>;
261
+ createdAt: z.ZodISODateTime;
262
+ updatedAt: z.ZodISODateTime;
263
+ expiresAt: z.ZodISODateTime;
264
+ }, z.core.$strip>>;
265
+ providers: z.ZodArray<z.ZodObject<{
266
+ providerId: z.ZodString;
267
+ createdAt: z.ZodISODateTime;
268
+ }, z.core.$strip>>;
269
+ devices: z.ZodArray<z.ZodObject<{
270
+ id: z.ZodString;
271
+ userId: z.ZodString;
272
+ platform: z.ZodEnum<{
273
+ android: "android";
274
+ ios: "ios";
275
+ web: "web";
276
+ }>;
277
+ name: z.ZodNullable<z.ZodString>;
278
+ model: z.ZodNullable<z.ZodString>;
279
+ osVersion: z.ZodNullable<z.ZodString>;
280
+ appVersion: z.ZodNullable<z.ZodString>;
281
+ lastIp: z.ZodNullable<z.ZodString>;
282
+ lastSeenAt: z.ZodISODateTime;
283
+ createdAt: z.ZodISODateTime;
284
+ }, z.core.$strip>>;
285
+ history: z.ZodArray<z.ZodObject<{
286
+ action: z.ZodString;
287
+ actorType: z.ZodString;
288
+ reason: z.ZodNullable<z.ZodString>;
289
+ suspendedUntil: z.ZodNullable<z.ZodISODateTime>;
290
+ createdAt: z.ZodISODateTime;
291
+ }, z.core.$strip>>;
292
+ plugins: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
293
+ }, z.core.$strip>;
294
+ export type AuthUserExport = z.output<typeof AuthUserExport>;
295
+ /**
296
+ * `GET {base}/admin/users/:userId/export` (#622).
297
+ *
298
+ * Everything the kit holds about one account — the answer to an access request. One entry per composed
299
+ * capability that declares a purge contribution, in the order the purge runs them, each read on its own so
300
+ * one that will not read costs its own entry and not the document.
301
+ */
302
+ export declare const AdminUserExportResponse: z.ZodObject<{
303
+ subject: z.ZodObject<{
304
+ type: z.ZodLiteral<"user">;
305
+ id: z.ZodString;
306
+ }, z.core.$strip>;
307
+ exportedAt: z.ZodISODateTime;
308
+ capabilities: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
309
+ capability: z.ZodString;
310
+ summary: z.ZodString;
311
+ state: z.ZodLiteral<"exported">;
312
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
313
+ }, z.core.$strip>, z.ZodObject<{
314
+ capability: z.ZodString;
315
+ summary: z.ZodString;
316
+ state: z.ZodLiteral<"not_exported">;
317
+ }, z.core.$strip>, z.ZodObject<{
318
+ capability: z.ZodString;
319
+ summary: z.ZodString;
320
+ state: z.ZodLiteral<"unavailable">;
321
+ }, z.core.$strip>], "state">>;
322
+ }, z.core.$strip>;
323
+ export type AdminUserExportResponse = z.output<typeof AdminUserExportResponse>;
154
324
  /** `POST {base}/token/rotate`. */
155
325
  export declare const TokenRotateResponse: z.ZodObject<{
156
326
  accessToken: z.ZodString;
@@ -203,4 +373,14 @@ export declare const MyDeviceRevokeResponse: z.ZodObject<{
203
373
  revoked: z.ZodNumber;
204
374
  }, z.core.$strip>;
205
375
  export type MyDeviceRevokeResponse = z.output<typeof MyDeviceRevokeResponse>;
376
+ /**
377
+ * `DELETE {base}/account` (#622) — the signed-in person deleted their own account. Always soft, on the
378
+ * configured window. Their sessions end with it, this one included.
379
+ */
380
+ export declare const AccountDeleteResponse: z.ZodObject<{
381
+ state: z.ZodLiteral<"deleted">;
382
+ purgeAfter: z.ZodISODateTime;
383
+ mailed: z.ZodBoolean;
384
+ }, z.core.$strip>;
385
+ export type AccountDeleteResponse = z.output<typeof AccountDeleteResponse>;
206
386
  //# sourceMappingURL=responses.d.ts.map
@@ -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;AAwCxB,kDAAkD;AAClD,eAAO,MAAM,aAAa;;;;;;;;;iBAiBsF,CAAC;AACjH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB;;;;;;;;i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;;;;;;;;;;;;iBAoB8D,CAAC;AAC1F,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAuC7D;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;iBAauE,CAAC;AAC5G,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAQ/E,kCAAkC;AAClC,eAAO,MAAM,mBAAmB;;;;iBAYqF,CAAC;AACtH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE,kDAAkD;AAClD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;iBAcwC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEzD,4BAA4B;AAC5B,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;iBAIqB,CAAC;AACpD,MAAM,MAAM,iBAAiB,GAAG,CAAC,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"}
@@ -119,6 +119,138 @@ const AdminDeviceRevokeResponse = z.object({
119
119
  revoked: RevokedCount,
120
120
  removed: z.boolean().describe("Whether a device row was deleted. False when the user had no such device.")
121
121
  }).describe("How many sessions the device revocation ended, and whether the registry row went with them.");
122
+ /**
123
+ * `POST {base}/admin/users/:userId/suspend` (#621).
124
+ *
125
+ * The suspension the account is now under, how many sessions ended with it, and whether the person was told.
126
+ * Not the reason: the caller wrote it, the trail keeps it, and echoing it back would put it in one more place
127
+ * a dashboard logs.
128
+ */
129
+ const AdminUserSuspendResponse = z.object({
130
+ userId: z.string().describe("The account suspended, as `pithy_auth_users.id` stores it."),
131
+ state: z.literal("suspended").describe("Where the account stands now. Every sign-in and refresh is refused."),
132
+ outcome: z.enum(["suspended", "updated"]).describe("`suspended` when this call suspended an account in good standing; `updated` when it was already suspended and this call restated the reason and the end."),
133
+ suspendedAt: z.iso.datetime().describe("When the suspension in force began, ISO-8601. A restatement keeps the original start."),
134
+ suspendedUntil: z.iso.datetime().nullable().describe("When it ends by itself, ISO-8601, with nothing written to end it. Null lasts until a reinstatement."),
135
+ sessionsRevoked: RevokedCount,
136
+ mailed: z.boolean().describe("Whether the account-suspended mail was enqueued. False for `notify: false`, when the config turns it off, or when no email capability is composed.")
137
+ }).describe("A suspended account: since when, until when, how many sessions it cost, and whether the person was told.");
138
+ /**
139
+ * `POST {base}/admin/users/:userId/reinstate` (#621).
140
+ *
141
+ * No session count: a reinstatement restores none. The person signs in again.
142
+ */
143
+ const AdminUserReinstateResponse = z.object({
144
+ userId: z.string().describe("The account reinstated, as `pithy_auth_users.id` stores it."),
145
+ state: z.literal("active").describe("Where the account stands now. It can sign in again."),
146
+ outcome: z.enum(["reinstated", "unchanged"]).describe("`reinstated` when this call lifted a suspension; `unchanged` when there was none in force — never suspended, or past its end — and nothing was written."),
147
+ mailed: z.boolean().describe("Whether the account-reinstated mail was enqueued. Always false for `unchanged`, and on the same rule as a suspension's otherwise.")
148
+ }).describe("A reinstated account, and whether the person was told. Its revoked sessions stay revoked.");
149
+ /** When the purge may erase a deleted account, ISO-8601. */
150
+ const PurgeAfter = z.iso.datetime().describe("When the purge may erase the account, ISO-8601. It can be restored until then; a hard deletion's is the moment it was deleted.");
151
+ /**
152
+ * `DELETE {base}/admin/users/:userId` (#622).
153
+ *
154
+ * What the deletion left in force, how many sessions ended with it, whether the person was told, and what
155
+ * became of the purge. Not the reason: the caller wrote it and the trail keeps it.
156
+ */
157
+ const AdminUserDeleteResponse = z.object({
158
+ userId: z.string().describe("The account deleted, as `pithy_auth_users.id` stores it."),
159
+ state: z.literal("deleted").describe("Where the account stands now. Every sign-in and refresh is refused."),
160
+ mode: z.enum(["soft", "hard"]).describe("The mode this call ran in — `soft` unless the caller named `hard`."),
161
+ outcome: z.enum([
162
+ "deleted",
163
+ "brought_forward",
164
+ "unchanged"
165
+ ]).describe("`deleted` when this call deleted an account in good standing; `brought_forward` when a hard deletion moved an already-deleted account's purge to now; `unchanged` when it was already deleted and there was nothing to move."),
166
+ deletedAt: z.iso.datetime().describe("When the account was deleted, ISO-8601. Kept by a deletion brought forward."),
167
+ purgeAfter: PurgeAfter,
168
+ purge: z.enum([
169
+ "scheduled",
170
+ "started",
171
+ "pending"
172
+ ]).describe("`scheduled`: the daily purge erases it once `purgeAfter` passes. `started`: the purge Workflow was started by this call. `pending`: the purge is due and this Worker binds no purge Workflow to start, so it runs once one is bound."),
173
+ sessionsRevoked: RevokedCount,
174
+ mailed: z.boolean().describe("Whether the deletion-scheduled mail was enqueued. Always false for `hard`, whose mail the purge sends, for `notify: false`, and when the config turns it off.")
175
+ }).describe("A deleted account: when, until when it can be restored, what became of the purge, and its sessions.");
176
+ /**
177
+ * `POST {base}/admin/users/:userId/restore` (#622). No session count: a restoration restores none.
178
+ */
179
+ const AdminUserRestoreResponse = z.object({
180
+ userId: z.string().describe("The account restored, as `pithy_auth_users.id` stores it."),
181
+ state: z.enum(["active", "suspended"]).describe("Where the account stands now: `active`, or `suspended` when a suspension it was under before the deletion is still in force."),
182
+ outcome: z.enum(["restored", "unchanged"]).describe("`restored` when this call restored a deleted account; `unchanged` when it was not deleted.")
183
+ }).describe("A restored account, inside its purge window. Its revoked sessions stay revoked.");
184
+ /** One provider link an account holds, as an export carries it — no provider token. */
185
+ const AuthExportProvider = z.object({
186
+ providerId: z.string().describe("The sign-in provider's slug — `google`, `apple`, `github`."),
187
+ createdAt: z.iso.datetime().describe("When the provider was linked, ISO-8601.")
188
+ }).describe("One sign-in provider linked to the account. The provider's tokens are credentials and are not here.");
189
+ /** One transition in an account's history, as an export carries it — not who made it. */
190
+ const AuthExportTransition = z.object({
191
+ action: z.string().describe("What happened: `suspended`, `reinstated`, `deleted`, `restored`, `purge_step`, `purged`."),
192
+ actorType: z.string().describe("Who made it: `control-plane`, `user` (the account's holder), or `system`."),
193
+ reason: z.string().nullable().describe("The reason given, in the words of whoever made the transition, or null."),
194
+ suspendedUntil: z.iso.datetime().nullable().describe("For a suspension, when it ends by itself, ISO-8601."),
195
+ createdAt: z.iso.datetime().describe("When it happened, ISO-8601.")
196
+ }).describe("One transition in the account's history. The operator's identity is theirs, not the person's, so it is not here.");
197
+ /**
198
+ * What `@pithy-sh/auth` holds about one account, as its purge contribution exports it (#622) — the `data` of
199
+ * the `auth` entry in an export.
200
+ *
201
+ * The person's own data and none of their credentials: no session token, no provider token, no push token.
202
+ * Every list is whole, because an export that stopped at a bound would answer an access request with part of
203
+ * an answer.
204
+ */
205
+ const AuthUserExport = z.object({
206
+ user: AdminUserView.extend({
207
+ suspendedAt: z.iso.datetime().nullable().describe("When a suspension in force began, ISO-8601, or null."),
208
+ suspendedUntil: z.iso.datetime().nullable().describe("When that suspension ends by itself, ISO-8601, or null."),
209
+ deletedAt: z.iso.datetime().nullable().describe("When the account was deleted, ISO-8601, or null."),
210
+ purgeAfter: z.iso.datetime().nullable().describe("When the purge may erase it, ISO-8601, or null.")
211
+ }).describe("The account itself, with where it stands."),
212
+ sessions: z.array(AdminSessionView).describe("Every live session, newest first. Without the tokens."),
213
+ providers: z.array(AuthExportProvider).describe("Every linked sign-in provider."),
214
+ devices: z.array(AdminDeviceView).describe("Every registered device, most recently seen first. Without push tokens."),
215
+ history: z.array(AuthExportTransition).describe("Every lifecycle transition, oldest first."),
216
+ plugins: z.record(z.string(), z.array(z.record(z.string(), z.unknown()))).describe("The account's rows in each table a composed Better Auth plugin created keyed by `userId` — two-factor, passkeys, API keys — keyed by table. Without a column that holds a credential. Empty when no such plugin is composed.")
217
+ }).describe("Everything `@pithy-sh/auth` holds about one account, without a credential.");
218
+ /** Fields every capability's export entry carries. */
219
+ const exportEntry = {
220
+ capability: z.string().describe("The capability whose rows these are — the purge step that erases them."),
221
+ summary: z.string().describe("What that capability's purge erases or anonymizes, in its own sentence.")
222
+ };
223
+ /** One capability's part of an export. */
224
+ const AdminUserExportEntry = z.discriminatedUnion("state", [
225
+ z.object({
226
+ ...exportEntry,
227
+ state: z.literal("exported").describe("The capability answered."),
228
+ data: z.record(z.string(), z.unknown()).describe("What it holds about the account, in the shape that capability exports. `auth`'s is `AuthUserExport`.")
229
+ }).describe("A capability's rows about the account."),
230
+ z.object({
231
+ ...exportEntry,
232
+ state: z.literal("not_exported").describe("The capability erases rows about the account and does not say how to export them.")
233
+ }).describe("A capability that holds rows it does not export. Ask its owner."),
234
+ z.object({
235
+ ...exportEntry,
236
+ state: z.literal("unavailable").describe("The capability's rows could not be read on this request.")
237
+ }).describe("Nothing was established about this capability's rows. Deliberately empty — it is not 'none'.")
238
+ ]).describe("One capability's part of an export, behind a state, so an unread part cannot be taken for an empty one.");
239
+ /**
240
+ * `GET {base}/admin/users/:userId/export` (#622).
241
+ *
242
+ * Everything the kit holds about one account — the answer to an access request. One entry per composed
243
+ * capability that declares a purge contribution, in the order the purge runs them, each read on its own so
244
+ * one that will not read costs its own entry and not the document.
245
+ */
246
+ const AdminUserExportResponse = z.object({
247
+ subject: z.object({
248
+ type: z.literal("user").describe("The kind of subject: one person's account."),
249
+ id: z.string().describe("The account's id, as `pithy_auth_users.id` stores it.")
250
+ }).describe("Who this export is about."),
251
+ exportedAt: z.iso.datetime().describe("When the export was read, ISO-8601."),
252
+ capabilities: z.array(AdminUserExportEntry).describe("Every composed capability's part, in the order the purge erases them.")
253
+ }).describe("Everything the kit holds about one account, from every composed capability, as one document.");
122
254
  /** `POST {base}/token/rotate`. */
123
255
  const TokenRotateResponse = z.object({
124
256
  accessToken: z.string().describe("A fresh short-lived access token (a JWT) for the `Authorization: Bearer` header."),
@@ -143,5 +275,14 @@ const MyDeviceView = z.object({
143
275
  const MyDevicesResponse = z.object({ devices: z.array(MyDeviceView).describe("Every device registered to the caller, most recently seen first.") }).describe("The caller's own registered devices.");
144
276
  /** `POST {base}/devices/revoke`. */
145
277
  const MyDeviceRevokeResponse = z.object({ revoked: RevokedCount }).describe("How many of the device's sessions the revocation signed out. The device's row goes with them.");
278
+ /**
279
+ * `DELETE {base}/account` (#622) — the signed-in person deleted their own account. Always soft, on the
280
+ * configured window. Their sessions end with it, this one included.
281
+ */
282
+ const AccountDeleteResponse = z.object({
283
+ state: z.literal("deleted").describe("The account is deleted. This session and every other one has ended."),
284
+ purgeAfter: PurgeAfter,
285
+ mailed: z.boolean().describe("Whether the deletion-scheduled mail, with the purge date and how to ask for the account back, was sent.")
286
+ }).describe("The caller's own account, deleted: when its data will be erased, and whether they were mailed.");
146
287
  //#endregion
147
- export { AdminDeviceRevokeResponse, AdminDeviceView, AdminDevicesResponse, AdminRevokeResponse, AdminSessionView, AdminUserResponse, AdminUserView, AdminUsersResponse, MyDeviceRevokeResponse, MyDeviceView, MyDevicesResponse, TokenRotateResponse };
288
+ export { AccountDeleteResponse, AdminDeviceRevokeResponse, AdminDeviceView, AdminDevicesResponse, AdminRevokeResponse, AdminSessionView, AdminUserDeleteResponse, AdminUserExportResponse, AdminUserReinstateResponse, AdminUserResponse, AdminUserRestoreResponse, AdminUserSuspendResponse, AdminUserView, AdminUsersResponse, AuthUserExport, MyDeviceRevokeResponse, MyDeviceView, MyDevicesResponse, TokenRotateResponse };
@@ -19,6 +19,7 @@ import type { AuthWiring } from "../capability";
19
19
  * | `POST /token/rotate` | bearer/session | none — the credential only |
20
20
  * | `GET /devices` | bearer/session | none |
21
21
  * | `POST /devices/revoke` | bearer/session | json `RevokeDeviceBody` |
22
+ * | `DELETE /account` | bearer/session | json `DeleteAccountBody` |
22
23
  * | `* /admin/*` | control-plane | see `./adminRoutes` |
23
24
  *
24
25
  * The catch-all takes NO validator, deliberately: `handleBetterAuth` hands Better Auth `c.req.raw`,
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAQ7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAwChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAuHtF"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAQ7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAG1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AA2ChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CA0ItF"}
@@ -9,10 +9,14 @@ import { noticedRefusal } from "../lifecycle/enforce.js";
9
9
  import { PROFILE_IMAGE_PATH } from "../profile/profile.js";
10
10
  import { collapseProviderRefusal } from "./providerRefusal.js";
11
11
  import { getAuthInstance, resolveDb } from "./resolve.js";
12
- import { requireAuth } from "./middleware.js";
12
+ import { accountHolder, requireAccountHolder, requireAuth } from "./middleware.js";
13
+ import { userSessionTokens } from "../admin/users.js";
14
+ import { lifecycleDeps } from "../lifecycle/request.js";
15
+ import { deleteUser } from "../lifecycle/transitions.js";
13
16
  import { consumeSession, findConsumedToken, pruneConsumedTokens, recordConsumedToken, revokeFamily } from "../token/rotation.js";
14
- import { MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses.js";
15
- import { RevokeDeviceBody } from "./schemas.js";
17
+ import { AccountDeleteResponse, MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses.js";
18
+ import { DeleteAccountBody, RevokeDeviceBody } from "./schemas.js";
19
+ import { accountDeletionView } from "./views.js";
16
20
  import { registerAuthAdminRoutes } from "./adminRoutes.js";
17
21
  import { guardErrorCallbackURL } from "./errorCallbackUrl.js";
18
22
  import { apiErrorToPithy } from "./errors.js";
@@ -53,6 +57,7 @@ function db(c, wiring) {
53
57
  * | `POST /token/rotate` | bearer/session | none — the credential only |
54
58
  * | `GET /devices` | bearer/session | none |
55
59
  * | `POST /devices/revoke` | bearer/session | json `RevokeDeviceBody` |
60
+ * | `DELETE /account` | bearer/session | json `DeleteAccountBody` |
56
61
  * | `* /admin/*` | control-plane | see `./adminRoutes` |
57
62
  *
58
63
  * The catch-all takes NO validator, deliberately: `handleBetterAuth` hands Better Auth `c.req.raw`,
@@ -94,6 +99,12 @@ function createAuthRoutes(wiring) {
94
99
  verification: ["bearer", "session"],
95
100
  responses: { 200: MyDeviceRevokeResponse }
96
101
  }), requireAuth(), csrf, validate("json", RevokeDeviceBody), (c) => revokeMyDevice(c, wiring, c.req.valid("json")));
102
+ app.delete(`${base}/account`, describeRoute({
103
+ summary: "Delete the caller's own account. Always soft: restorable until the purge window closes.",
104
+ description: "What the App Store and Google Play require of an app with accounts. A suspended account may still delete itself, with the session a sign-in carrying `x-pithy-intent: delete-account` gets it; a deleted one is refused with `auth/account_deleted`. Every session ends, this one included. The body must carry `confirm: true`.",
105
+ verification: ["bearer", "session"],
106
+ responses: { 200: AccountDeleteResponse }
107
+ }), requireAccountHolder(), csrf, validate("json", DeleteAccountBody), (c) => deleteMyAccount(c, wiring));
97
108
  app.post(`${base}/link-social`, describeRoute({
98
109
  summary: "Connect another sign-in provider to the caller's account.",
99
110
  description: "Better Auth's endpoint, behind a kit gate: the caller must have signed in within the last fifteen minutes, or it is refused with `auth/session_not_fresh`.",
@@ -339,6 +350,37 @@ async function listMyDevices(c, wiring) {
339
350
  if (!userId) throw new UnauthorizedError({ message: "Authentication required." });
340
351
  return c.json({ devices: await listDevices(db(c, wiring), userId) });
341
352
  }
353
+ /**
354
+ * Delete the caller's own account (#622): soft, on the configured window, audited as `auth/user_self_deleted`
355
+ * with them as the actor, and every session they hold ended after the columns are written — through Better
356
+ * Auth's adapter, so `onSessionRevoked` hears each. No reason: a person leaving owes nobody one.
357
+ */
358
+ async function deleteMyAccount(c, wiring) {
359
+ const holder = accountHolder(c);
360
+ if (!holder) throw new UnauthorizedError({ message: "Authentication required." });
361
+ const { ip, userAgent } = correlation(c.req.raw.headers);
362
+ const deps = lifecycleDeps(c, wiring, {
363
+ ip,
364
+ userAgent,
365
+ requestId: c.req.header("cf-ray"),
366
+ metadata: {
367
+ sessionId: holder.sessionId,
368
+ suspended: holder.suspended
369
+ }
370
+ });
371
+ const result = await deleteUser(deps, {
372
+ userId: holder.userId,
373
+ actor: {
374
+ type: "user",
375
+ id: holder.userId
376
+ },
377
+ reason: null
378
+ });
379
+ const tokens = await userSessionTokens(db(c, wiring), holder.userId);
380
+ const ctx = await (await getAuthInstance(c, wiring)).$context;
381
+ for (const token of tokens) await ctx.internalAdapter.deleteSession(token);
382
+ return c.json(accountDeletionView(result));
383
+ }
342
384
  /** Revoke one of the authenticated user's devices: sign out its sessions, then drop the device row. */
343
385
  async function revokeMyDevice(c, wiring, body) {
344
386
  const userId = c.var.auth?.userId;
@@ -65,4 +65,61 @@ export declare const RevokeSessionBody: z.ZodObject<{
65
65
  sessionId: z.ZodString;
66
66
  }, z.core.$strip>;
67
67
  export type RevokeSessionBody = z.output<typeof RevokeSessionBody>;
68
+ /** The body of `POST /admin/users/:userId/suspend`. */
69
+ export declare const SuspendUserBody: z.ZodObject<{
70
+ reason: z.ZodString;
71
+ until: z.ZodOptional<z.ZodCodec<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodDate]>, z.ZodDate>>;
72
+ notify: z.ZodOptional<z.ZodBoolean>;
73
+ }, z.core.$strip>;
74
+ export type SuspendUserBody = z.output<typeof SuspendUserBody>;
75
+ /** The body of `POST /admin/users/:userId/reinstate`. */
76
+ export declare const ReinstateUserBody: z.ZodObject<{
77
+ reason: z.ZodString;
78
+ notify: z.ZodOptional<z.ZodBoolean>;
79
+ }, z.core.$strip>;
80
+ export type ReinstateUserBody = z.output<typeof ReinstateUserBody>;
81
+ /**
82
+ * How a deletion runs (#622). `soft` is the default and the only thing an omission reaches: the account is shut
83
+ * now and erased once the window closes, restorable until then. `hard` starts the purge at once, with no
84
+ * window, and is reached only by naming it — a typo is a 400, never either mode.
85
+ */
86
+ export declare const DeletionMode: z.ZodEnum<{
87
+ hard: "hard";
88
+ soft: "soft";
89
+ }>;
90
+ export type DeletionMode = z.output<typeof DeletionMode>;
91
+ /** The body of `DELETE /admin/users/:userId`. */
92
+ export declare const DeleteUserBody: z.ZodObject<{
93
+ mode: z.ZodDefault<z.ZodEnum<{
94
+ hard: "hard";
95
+ soft: "soft";
96
+ }>>;
97
+ reason: z.ZodString;
98
+ notify: z.ZodOptional<z.ZodBoolean>;
99
+ }, z.core.$strip>;
100
+ export type DeleteUserBody = z.output<typeof DeleteUserBody>;
101
+ /** The body of `POST /admin/users/:userId/restore`. */
102
+ export declare const RestoreUserBody: z.ZodObject<{
103
+ reason: z.ZodString;
104
+ }, z.core.$strip>;
105
+ export type RestoreUserBody = z.output<typeof RestoreUserBody>;
106
+ /**
107
+ * The query of `GET /admin/users/:userId/export`. A disclosure of everything the kit holds about one person
108
+ * says why, like every lifecycle call: the reason goes on the trail beside who asked.
109
+ */
110
+ export declare const ExportUserQuery: z.ZodObject<{
111
+ reason: z.ZodString;
112
+ }, z.core.$strip>;
113
+ export type ExportUserQuery = z.output<typeof ExportUserQuery>;
114
+ /**
115
+ * The body of `DELETE /account`, the signed-in person deleting their own account (#622).
116
+ *
117
+ * The confirmation is the literal `true`, so a client must say it on purpose: a stray `DELETE` with an empty
118
+ * body, or a form posting `"false"`, deletes nothing. There is no field naming an account — the subject is the
119
+ * session's own, always — and a key that tries is dropped.
120
+ */
121
+ export declare const DeleteAccountBody: z.ZodObject<{
122
+ confirm: z.ZodLiteral<true>;
123
+ }, z.core.$strip>;
124
+ export type DeleteAccountBody = z.output<typeof DeleteAccountBody>;
68
125
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/http/schemas.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;iBAQ2E,CAAC;AACzG,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEjE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;;iBAIoD,CAAC;AAC7E,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAkBvD,8BAA8B;AAC9B,eAAO,MAAM,cAAc;;;;iBAawE,CAAC;AACpG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D,yCAAyC;AACzC,eAAO,MAAM,gBAAgB;;;;;;;;;iBAYwE,CAAC;AACtG,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;iBAQqC,CAAC;AACpE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,M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ACJ,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAEzD,iDAAiD;AACjD,eAAO,MAAM,cAAc;;;;;;;iBAakD,CAAC;AAC9E,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D,uDAAuD;AACvD,eAAO,MAAM,eAAe;;iBAEiF,CAAC;AAC9G,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,eAAe;;iBAMmB,CAAC;AAChD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;iBAM+E,CAAC;AAC9G,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
@@ -1,7 +1,9 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { DevicePlatform } from "../data/device.js";
4
+ import "../lifecycle/reason.js";
4
5
  import { z } from "zod";
6
+ import { JsonDate } from "@pithy-sh/core/src/data/codecs";
5
7
  import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
6
8
  //#region src/http/schemas.ts
7
9
  /**
@@ -57,5 +59,53 @@ const ListDevicesQuery = z.object({
57
59
  * the read routes project.
58
60
  */
59
61
  const RevokeSessionBody = z.object({ sessionId: z.string().min(1).max(255).describe("The session's id, as the admin read routes report it. Not the session token.") }).describe("The body identifying which single session to revoke.");
62
+ /**
63
+ * Why an account's access is changing — required on both lifecycle routes (#621).
64
+ *
65
+ * Trimmed, then bounded by the same constant the transition enforces, so a reason the transition would refuse
66
+ * is a 400 here rather than a conflict later. Required rather than defaulted: a suspension nobody explained is
67
+ * a lockout the person cannot answer, and the trail would record nothing about why.
68
+ */
69
+ const LifecycleReason = z.string().trim().min(1).max(500).describe("Why, in a sentence written for the person. A suspension's reason is what every refused sign-in shows them.");
70
+ /** Whether the person is mailed. */
71
+ const Notify = z.boolean().optional().describe("Whether to mail the person. Absent is true. The config can turn a lifecycle mail off for every call; this turns it off for one.");
72
+ /** The body of `POST /admin/users/:userId/suspend`. */
73
+ const SuspendUserBody = z.object({
74
+ reason: LifecycleReason,
75
+ until: JsonDate.optional().describe("When the suspension ends by itself, as an ISO-8601 timestamp. Must be in the future. Absent lasts until a reinstatement. Nothing is written when it passes."),
76
+ notify: Notify
77
+ }).describe("A suspension: why, until when, and whether to tell the person. Suspending a suspended account restates the reason and the end.");
78
+ /** The body of `POST /admin/users/:userId/reinstate`. */
79
+ const ReinstateUserBody = z.object({
80
+ reason: LifecycleReason,
81
+ notify: Notify
82
+ }).describe("A reinstatement: why, and whether to tell the person. It restores no session.");
83
+ /**
84
+ * How a deletion runs (#622). `soft` is the default and the only thing an omission reaches: the account is shut
85
+ * now and erased once the window closes, restorable until then. `hard` starts the purge at once, with no
86
+ * window, and is reached only by naming it — a typo is a 400, never either mode.
87
+ */
88
+ const DeletionMode = z.enum(["soft", "hard"]).describe("`soft` (the default): the account is shut now and its data erased once `retention.purgeAfterDays` have passed; it can be restored until then. `hard`: the purge starts now, with no window and nothing to restore.");
89
+ /** The body of `DELETE /admin/users/:userId`. */
90
+ const DeleteUserBody = z.object({
91
+ mode: DeletionMode.default("soft").describe("`soft` unless named: the window, then the purge. `hard` purges now. Anything else is refused."),
92
+ reason: LifecycleReason,
93
+ notify: z.boolean().optional().describe("Whether to mail the person. Absent is true. It silences the mail this call sends: the deletion-scheduled notice for `soft`, the deletion-complete notice for `hard`.")
94
+ }).describe("A deletion: soft or hard, why, and whether to tell the person.");
95
+ /** The body of `POST /admin/users/:userId/restore`. */
96
+ const RestoreUserBody = z.object({ reason: LifecycleReason }).describe("A restoration inside the purge window: why. It restores no session; the person signs in again.");
97
+ /**
98
+ * The query of `GET /admin/users/:userId/export`. A disclosure of everything the kit holds about one person
99
+ * says why, like every lifecycle call: the reason goes on the trail beside who asked.
100
+ */
101
+ const ExportUserQuery = z.object({ reason: LifecycleReason.describe("Why this person's data is being exported — the access request it answers. Recorded on the audit trail.") }).describe("An export: why it is being made.");
102
+ /**
103
+ * The body of `DELETE /account`, the signed-in person deleting their own account (#622).
104
+ *
105
+ * The confirmation is the literal `true`, so a client must say it on purpose: a stray `DELETE` with an empty
106
+ * body, or a form posting `"false"`, deletes nothing. There is no field naming an account — the subject is the
107
+ * session's own, always — and a key that tries is dropped.
108
+ */
109
+ const DeleteAccountBody = z.object({ confirm: z.literal(true).describe("Must be `true`. The person confirmed, in your app, that they want their account deleted.") }).describe("A self-service deletion: the person's own confirmation. Always soft, on the configured window.");
60
110
  //#endregion
61
- export { ListDevicesQuery, ListUsersQuery, RevokeDeviceBody, RevokeSessionBody, UserIdParam };
111
+ export { DeleteAccountBody, DeleteUserBody, DeletionMode, ExportUserQuery, ListDevicesQuery, ListUsersQuery, ReinstateUserBody, RestoreUserBody, RevokeDeviceBody, RevokeSessionBody, SuspendUserBody, UserIdParam };
@@ -1,8 +1,11 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
- import type { Session, User } from "../data/betterAuth";
3
+ import type { PurgeExportEntry } from "@pithy-sh/core/src/capability/purge";
4
+ import type { Account, Session, User } from "../data/betterAuth";
4
5
  import type { Device } from "../data/device";
5
- import type { AdminDeviceView, AdminSessionView, AdminUserView } from "./responses";
6
+ import type { UserLifecycleEvent } from "../data/userLifecycle";
7
+ import type { DeleteTransition, DeletionMode, LifecycleTransition, RestoreTransition, SuspendTransition } from "../lifecycle/transitions";
8
+ import type { AccountDeleteResponse, AdminDeviceView, AdminSessionView, AdminUserDeleteResponse, AdminUserExportResponse, AdminUserReinstateResponse, AdminUserRestoreResponse, AdminUserSuspendResponse, AdminUserView, AuthUserExport } from "./responses";
6
9
  /**
7
10
  * The admin projections — what a management client is shown of a user, a session, and a device.
8
11
  *
@@ -52,4 +55,38 @@ export declare function sessionView(session: Session): AdminSessionView;
52
55
  * adopter's users under the adopter's own app identity. It never leaves the Worker.
53
56
  */
54
57
  export declare function deviceView(device: Device): AdminDeviceView;
58
+ /**
59
+ * The suspension projection (#621): the suspension the transition left in force, and the sessions the route
60
+ * revoked after it. Dates cross as ISO-8601, like every other response here.
61
+ */
62
+ export declare function suspensionView(userId: string, result: SuspendTransition, sessionsRevoked: number): AdminUserSuspendResponse;
63
+ /** The reinstatement projection (#621). A call that found no suspension in force is `unchanged`. */
64
+ export declare function reinstatementView(userId: string, result: LifecycleTransition): AdminUserReinstateResponse;
65
+ /** What became of a deletion's purge: due later, started by the call, or due with nothing bound to start it. */
66
+ export type PurgeDisposition = AdminUserDeleteResponse["purge"];
67
+ /**
68
+ * The deletion projection (#622): the deletion the transition left in force, the sessions the route revoked
69
+ * after it, and what became of the purge.
70
+ */
71
+ export declare function deletionView(userId: string, mode: DeletionMode, result: DeleteTransition, purge: PurgeDisposition, sessionsRevoked: number): AdminUserDeleteResponse;
72
+ /** The restoration projection (#622). A call that found the account not deleted is `unchanged`. */
73
+ export declare function restorationView(userId: string, result: RestoreTransition): AdminUserRestoreResponse;
74
+ /** The self-service deletion projection (#622). */
75
+ export declare function accountDeletionView(result: DeleteTransition): AccountDeleteResponse;
76
+ /**
77
+ * What auth holds about one account, as its export carries it (#622) — the person's own data, projected through
78
+ * the same views a support pane sees, so a session token, a provider token and a push token are absent here by
79
+ * the same construction that keeps them out of every other response. The operator who made a transition is
80
+ * theirs to disclose, not the person's, so the history carries the kind of actor and not its id.
81
+ */
82
+ export declare function authUserExportView(input: {
83
+ user: User;
84
+ sessions: readonly Session[];
85
+ accounts: readonly Pick<Account, "providerId" | "createdAt">[];
86
+ devices: readonly Device[];
87
+ history: readonly UserLifecycleEvent[];
88
+ plugins?: Record<string, Record<string, unknown>[]>;
89
+ }): AuthUserExport;
90
+ /** The export document (#622): who it is about, when it was read, and every capability's part. */
91
+ export declare function exportView(userId: string, exportedAt: Date, entries: readonly PurgeExportEntry[]): AdminUserExportResponse;
55
92
  //# sourceMappingURL=views.d.ts.map