@pithy-sh/auth 0.7.0 → 0.8.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.
@@ -1 +1 @@
1
- {"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/http/adminRoutes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAc1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAmJhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAgM7F"}
1
+ {"version":3,"file":"adminRoutes.d.ts","sourceRoot":"","sources":["../../src/http/adminRoutes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAO7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAc1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAmJhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAoO7F"}
@@ -7,11 +7,12 @@ import { deleteDevice, deviceSessionTokens } from "../device/registry.js";
7
7
  import { getAuthInstance, resolveDb } from "./resolve.js";
8
8
  import { AUTH_DEVICES_READ_SCOPE, AUTH_DEVICES_REVOKE_SCOPE, AUTH_SESSIONS_REVOKE_SCOPE, AUTH_USERS_LOGOUT_SCOPE, AUTH_USERS_READ_SCOPE } from "./guards.js";
9
9
  import { findSessionById, getUser, listDeviceRegistry, listUserDevices, listUserSessions, listUsers, userProviders, userSessionTokens } from "../admin/users.js";
10
+ import { AdminDeviceRevokeResponse, AdminDevicesResponse, AdminRevokeResponse, AdminUserResponse, AdminUsersResponse } from "./responses.js";
10
11
  import { ListDevicesQuery, ListUsersQuery, RevokeDeviceBody, RevokeSessionBody, UserIdParam } from "./schemas.js";
11
12
  import { deviceView, sessionView, userView } from "./views.js";
12
13
  import { InternalError, NotFoundError } from "@pithy-sh/core/src/error/pithyError";
13
- import { zValidator } from "@hono/zod-validator";
14
- import { validationHook } from "@pithy-sh/core/src/http/validation";
14
+ import { describeRoute } from "@pithy-sh/core/src/http/routeSpec";
15
+ import { validate } from "@pithy-sh/core/src/http/validation";
15
16
  import { requireControlPlane } from "@pithy-sh/core/src/controlPlane/http/guard";
16
17
  import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
17
18
  //#region src/http/adminRoutes.ts
@@ -137,7 +138,12 @@ async function revokeTokens(c, wiring, tokens) {
137
138
  function registerAuthAdminRoutes(wiring) {
138
139
  return (app) => {
139
140
  const base = wiring.config.basePath;
140
- app.get(`${base}/admin/users`, requireControlPlane(AUTH_USERS_READ_SCOPE), zValidator("query", ListUsersQuery, validationHook), async (c) => {
141
+ app.get(`${base}/admin/users`, describeRoute({
142
+ summary: "Page through the users, newest first, optionally searching by email or name.",
143
+ verification: "control-plane",
144
+ scopes: [AUTH_USERS_READ_SCOPE],
145
+ responses: { 200: AdminUsersResponse }
146
+ }), requireControlPlane(AUTH_USERS_READ_SCOPE), validate("query", ListUsersQuery), async (c) => {
141
147
  const query = c.req.valid("query");
142
148
  const caller = controlPlaneCaller(c);
143
149
  const page = await listUsers(db(c, wiring), query);
@@ -157,7 +163,12 @@ function registerAuthAdminRoutes(wiring) {
157
163
  nextCursor: page.nextCursor
158
164
  });
159
165
  });
160
- app.get(`${base}/admin/users/:userId`, requireControlPlane(AUTH_USERS_READ_SCOPE), zValidator("param", UserIdParam, validationHook), async (c) => {
166
+ app.get(`${base}/admin/users/:userId`, describeRoute({
167
+ summary: "Read one user with their sessions, devices and linked providers.",
168
+ verification: "control-plane",
169
+ scopes: [AUTH_USERS_READ_SCOPE],
170
+ responses: { 200: AdminUserResponse }
171
+ }), requireControlPlane(AUTH_USERS_READ_SCOPE), validate("param", UserIdParam), async (c) => {
161
172
  const { userId } = c.req.valid("param");
162
173
  const caller = controlPlaneCaller(c);
163
174
  const database = db(c, wiring);
@@ -190,7 +201,12 @@ function registerAuthAdminRoutes(wiring) {
190
201
  devices
191
202
  });
192
203
  });
193
- app.get(`${base}/admin/devices`, requireControlPlane(AUTH_DEVICES_READ_SCOPE), zValidator("query", ListDevicesQuery, validationHook), async (c) => {
204
+ app.get(`${base}/admin/devices`, describeRoute({
205
+ summary: "Page through the device registry, most recently seen first.",
206
+ verification: "control-plane",
207
+ scopes: [AUTH_DEVICES_READ_SCOPE],
208
+ responses: { 200: AdminDevicesResponse }
209
+ }), requireControlPlane(AUTH_DEVICES_READ_SCOPE), validate("query", ListDevicesQuery), async (c) => {
194
210
  const query = c.req.valid("query");
195
211
  const caller = controlPlaneCaller(c);
196
212
  const page = await listDeviceRegistry(db(c, wiring), query);
@@ -211,7 +227,12 @@ function registerAuthAdminRoutes(wiring) {
211
227
  nextCursor: page.nextCursor
212
228
  });
213
229
  });
214
- app.post(`${base}/admin/sessions/revoke`, requireControlPlane(AUTH_SESSIONS_REVOKE_SCOPE), zValidator("json", RevokeSessionBody, validationHook), async (c) => {
230
+ app.post(`${base}/admin/sessions/revoke`, describeRoute({
231
+ summary: "Revoke one session by its id.",
232
+ verification: "control-plane",
233
+ scopes: [AUTH_SESSIONS_REVOKE_SCOPE],
234
+ responses: { 200: AdminRevokeResponse }
235
+ }), requireControlPlane(AUTH_SESSIONS_REVOKE_SCOPE), validate("json", RevokeSessionBody), async (c) => {
215
236
  const { sessionId } = c.req.valid("json");
216
237
  const caller = controlPlaneCaller(c);
217
238
  const session = await findSessionById(db(c, wiring), sessionId);
@@ -230,7 +251,12 @@ function registerAuthAdminRoutes(wiring) {
230
251
  });
231
252
  return c.json({ revoked });
232
253
  });
233
- app.post(`${base}/admin/users/:userId/sessions/revoke`, requireControlPlane(AUTH_USERS_LOGOUT_SCOPE), zValidator("param", UserIdParam, validationHook), async (c) => {
254
+ app.post(`${base}/admin/users/:userId/sessions/revoke`, describeRoute({
255
+ summary: "Sign one user out everywhere.",
256
+ verification: "control-plane",
257
+ scopes: [AUTH_USERS_LOGOUT_SCOPE],
258
+ responses: { 200: AdminRevokeResponse }
259
+ }), requireControlPlane(AUTH_USERS_LOGOUT_SCOPE), validate("param", UserIdParam), async (c) => {
234
260
  const { userId } = c.req.valid("param");
235
261
  const caller = controlPlaneCaller(c);
236
262
  const revoked = await revokeTokens(c, wiring, await userSessionTokens(db(c, wiring), userId));
@@ -245,7 +271,12 @@ function registerAuthAdminRoutes(wiring) {
245
271
  });
246
272
  return c.json({ revoked });
247
273
  });
248
- app.post(`${base}/admin/users/:userId/devices/revoke`, requireControlPlane(AUTH_DEVICES_REVOKE_SCOPE), zValidator("param", UserIdParam, validationHook), zValidator("json", RevokeDeviceBody, validationHook), async (c) => {
274
+ app.post(`${base}/admin/users/:userId/devices/revoke`, describeRoute({
275
+ summary: "Sign out one of a user's devices and remove it from the registry.",
276
+ verification: "control-plane",
277
+ scopes: [AUTH_DEVICES_REVOKE_SCOPE],
278
+ responses: { 200: AdminDeviceRevokeResponse }
279
+ }), requireControlPlane(AUTH_DEVICES_REVOKE_SCOPE), validate("param", UserIdParam), validate("json", RevokeDeviceBody), async (c) => {
249
280
  const { userId } = c.req.valid("param");
250
281
  const { deviceId } = c.req.valid("json");
251
282
  const caller = controlPlaneCaller(c);
@@ -1 +1 @@
1
- {"version":3,"file":"devLoginRoute.d.ts","sourceRoot":"","sources":["../../src/http/devLoginRoute.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,KAAK,UAAU,EAAsC,MAAM,gCAAgC,CAAC;AAMrG,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,EAClB,GAAG,GAAE,UAAyB,GAC7B,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAYnC"}
1
+ {"version":3,"file":"devLoginRoute.d.ts","sourceRoot":"","sources":["../../src/http/devLoginRoute.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAE7E,OAAO,EAAE,KAAK,UAAU,EAAsC,MAAM,gCAAgC,CAAC;AAQrG,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,UAAU,EAClB,GAAG,GAAE,UAAyB,GAC7B,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAuBnC"}
@@ -8,9 +8,11 @@ import { resolveDb } from "./resolve.js";
8
8
  import { NotFoundError } from "@pithy-sh/core/src/error/pithyError";
9
9
  import { z } from "zod";
10
10
  import { ambientEnv, compositionEnvironment } from "@pithy-sh/core/src/env/ambient";
11
- import { zValidator } from "@hono/zod-validator";
11
+ import { commandName, pithyCommand } from "@pithy-sh/core/src/cli/command";
12
12
  import { isContinuousIntegration } from "@pithy-sh/core/src/env/ci";
13
- import { validationHook } from "@pithy-sh/core/src/http/validation";
13
+ import { describeRoute } from "@pithy-sh/core/src/http/routeSpec";
14
+ import { validate } from "@pithy-sh/core/src/http/validation";
15
+ import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
14
16
  import { DEV_LOGIN_CLAIM_PARAM, DEV_LOGIN_ROUTE } from "@pithy-sh/core/src/seed/devLogin";
15
17
  //#region src/http/devLoginRoute.ts
16
18
  /**
@@ -53,7 +55,12 @@ function registerDevLoginRoute(wiring, env = ambientEnv()) {
53
55
  return (app) => {
54
56
  if (compositionEnvironment(env) !== "dev") return;
55
57
  if (isContinuousIntegration(env)) return;
56
- app.get(DEV_LOGIN_ROUTE, zValidator("query", DevLoginQuery, validationHook), (c) => serveDevLogin(c, wiring, c.req.valid("query")[DEV_LOGIN_CLAIM_PARAM]));
58
+ app.get(DEV_LOGIN_ROUTE, describeRoute({
59
+ summary: "Sign the browser in as the seeded dev user.",
60
+ description: "Mounted only in a `dev` composition outside CI. It takes no credential: the signed claim `pithy seed` wrote into the URL is the whole of what it checks.",
61
+ verification: "public",
62
+ responses: { 302: { description: "Signed in: sets the session cookie and redirects to `/`." } }
63
+ }), validate("query", DevLoginQuery), (c) => serveDevLogin(c, wiring, c.req.valid("query")[DEV_LOGIN_CLAIM_PARAM]));
57
64
  };
58
65
  }
59
66
  /**
@@ -70,7 +77,7 @@ function registerDevLoginRoute(wiring, env = ambientEnv()) {
70
77
  * which is the opposite of a field nobody classified carrying it everywhere.
71
78
  */
72
79
  function noSeededSession() {
73
- return new NotFoundError({ message: "No dev login has been seeded for this environment. Run pithy seed, then open this URL again." });
80
+ return new NotFoundError({ message: `No dev login has been seeded for this environment. Run ${pithyCommand("seed", { flags: { "--env": LOCAL_ENVIRONMENT } })}, then open this URL again.` });
74
81
  }
75
82
  /**
76
83
  * What the route takes: the claim, in the query.
@@ -110,7 +117,7 @@ async function serveDevLogin(c, wiring, presented) {
110
117
  createdAt: now,
111
118
  updatedAt: now,
112
119
  ipAddress: "127.0.0.1",
113
- userAgent: "pithy dev login",
120
+ userAgent: `${commandName("dev")} login`,
114
121
  deviceId: null,
115
122
  familyId: null,
116
123
  authenticatedAt: now
@@ -151,4 +151,56 @@ 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
+ /** `POST {base}/token/rotate`. */
155
+ export declare const TokenRotateResponse: z.ZodObject<{
156
+ accessToken: z.ZodString;
157
+ refreshToken: z.ZodString;
158
+ expiresAt: z.ZodISODateTime;
159
+ }, z.core.$strip>;
160
+ export type TokenRotateResponse = z.output<typeof TokenRotateResponse>;
161
+ /** One of the caller's own registered devices. */
162
+ export declare const MyDeviceView: z.ZodObject<{
163
+ id: z.ZodString;
164
+ userId: z.ZodString;
165
+ platform: z.ZodEnum<{
166
+ android: "android";
167
+ ios: "ios";
168
+ web: "web";
169
+ }>;
170
+ name: z.ZodNullable<z.ZodString>;
171
+ model: z.ZodNullable<z.ZodString>;
172
+ osVersion: z.ZodNullable<z.ZodString>;
173
+ appVersion: z.ZodNullable<z.ZodString>;
174
+ pushToken: z.ZodNullable<z.ZodString>;
175
+ lastIp: z.ZodNullable<z.ZodString>;
176
+ lastSeenAt: z.ZodISODateTime;
177
+ createdAt: z.ZodISODateTime;
178
+ }, z.core.$strip>;
179
+ export type MyDeviceView = z.output<typeof MyDeviceView>;
180
+ /** `GET {base}/devices`. */
181
+ export declare const MyDevicesResponse: z.ZodObject<{
182
+ devices: z.ZodArray<z.ZodObject<{
183
+ id: z.ZodString;
184
+ userId: z.ZodString;
185
+ platform: z.ZodEnum<{
186
+ android: "android";
187
+ ios: "ios";
188
+ web: "web";
189
+ }>;
190
+ name: z.ZodNullable<z.ZodString>;
191
+ model: z.ZodNullable<z.ZodString>;
192
+ osVersion: z.ZodNullable<z.ZodString>;
193
+ appVersion: z.ZodNullable<z.ZodString>;
194
+ pushToken: z.ZodNullable<z.ZodString>;
195
+ lastIp: z.ZodNullable<z.ZodString>;
196
+ lastSeenAt: z.ZodISODateTime;
197
+ createdAt: z.ZodISODateTime;
198
+ }, z.core.$strip>>;
199
+ }, z.core.$strip>;
200
+ export type MyDevicesResponse = z.output<typeof MyDevicesResponse>;
201
+ /** `POST {base}/devices/revoke`. */
202
+ export declare const MyDeviceRevokeResponse: z.ZodObject<{
203
+ revoked: z.ZodNumber;
204
+ }, z.core.$strip>;
205
+ export type MyDeviceRevokeResponse = z.output<typeof MyDeviceRevokeResponse>;
154
206
  //# 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;;;;;;;;iBAUiF,CAAC;AAC/G,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEjE,0GAA0G;AAC1G,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;iBAawF,CAAC;AACrH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC;AAE/D,gCAAgC;AAChC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;iBAKQ,CAAC;AACxC,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAoDrE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAY3B,CAAC;AACJ,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEnE,kCAAkC;AAClC,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;iBAKY,CAAC;AAC9C,MAAM,MAAM,oBAAoB,GAAG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B,CAAC,CAAC;AAEnE,kCAAkC;AAClC,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;iBAKY,CAAC;AAC9C,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEzE;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;iBAEsB,CAAC;AACvD,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEvE,wDAAwD;AACxD,eAAO,MAAM,yBAAyB;;;iBAKoE,CAAC;AAC3G,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAQnF,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"}
@@ -119,5 +119,29 @@ 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
+ /** `POST {base}/token/rotate`. */
123
+ const TokenRotateResponse = z.object({
124
+ accessToken: z.string().describe("A fresh short-lived access token (a JWT) for the `Authorization: Bearer` header."),
125
+ refreshToken: z.string().describe("The successor refresh credential: a new session token. The one presented is spent, and presenting it again past a short grace window revokes the whole family."),
126
+ expiresAt: z.iso.datetime().describe("When the successor session lapses, ISO-8601.")
127
+ }).describe("The rotated credential pair: a new access token and the session token that replaces the one presented.");
128
+ /** One of the caller's own registered devices. */
129
+ const MyDeviceView = z.object({
130
+ id: z.string().describe("The client-generated device id it registered at sign-in."),
131
+ userId: z.string().describe("The owning user's id: always the caller's own."),
132
+ platform: DevicePlatform.describe("The platform the device registered as."),
133
+ name: z.string().nullable().describe("The device's human label, or null."),
134
+ model: z.string().nullable().describe("The hardware model, or null."),
135
+ osVersion: z.string().nullable().describe("The device OS version at last sign-in, or null."),
136
+ appVersion: z.string().nullable().describe("The client app version at last sign-in, or null."),
137
+ pushToken: z.string().nullable().describe("The APNs or FCM push token the device registered, or null."),
138
+ lastIp: z.string().nullable().describe("The client IP at the device's most recent sign-in, or null."),
139
+ lastSeenAt: z.iso.datetime().describe("When the device was last seen, ISO-8601."),
140
+ createdAt: z.iso.datetime().describe("When the device first registered, ISO-8601.")
141
+ }).describe("One device registered to the caller's own account.");
142
+ /** `GET {base}/devices`. */
143
+ 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
+ /** `POST {base}/devices/revoke`. */
145
+ 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.");
122
146
  //#endregion
123
- export { AdminDeviceRevokeResponse, AdminDeviceView, AdminDevicesResponse, AdminRevokeResponse, AdminSessionView, AdminUserResponse, AdminUserView, AdminUsersResponse };
147
+ export { AdminDeviceRevokeResponse, AdminDeviceView, AdminDevicesResponse, AdminRevokeResponse, AdminSessionView, AdminUserResponse, AdminUserView, AdminUsersResponse, MyDeviceRevokeResponse, MyDeviceView, MyDevicesResponse, TokenRotateResponse };
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/http/routes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAO7E,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AA0BhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CA4CtF"}
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;AAqChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,CAAC,KAAK,IAAI,CAuHtF"}
@@ -9,18 +9,28 @@ import { collapseProviderRefusal } from "./providerRefusal.js";
9
9
  import { getAuthInstance, resolveDb } from "./resolve.js";
10
10
  import { requireAuth } from "./middleware.js";
11
11
  import { consumeSession, findConsumedToken, pruneConsumedTokens, recordConsumedToken, revokeFamily } from "../token/rotation.js";
12
+ import { MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses.js";
12
13
  import { RevokeDeviceBody } from "./schemas.js";
13
14
  import { registerAuthAdminRoutes } from "./adminRoutes.js";
14
15
  import { guardErrorCallbackURL } from "./errorCallbackUrl.js";
15
16
  import { apiErrorToPithy } from "./errors.js";
16
17
  import { NotFoundError, UnauthorizedError } from "@pithy-sh/core/src/error/pithyError";
17
18
  import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
18
- import { zValidator } from "@hono/zod-validator";
19
- import { validationHook } from "@pithy-sh/core/src/http/validation";
19
+ import { describeRoute } from "@pithy-sh/core/src/http/routeSpec";
20
+ import { validate } from "@pithy-sh/core/src/http/validation";
20
21
  import { STORED_IMAGE_HEADERS, storedImageBytes } from "@pithy-sh/core/src/image/storedImage";
21
22
  import { requireSameOrigin } from "@pithy-sh/core/src/http/sameOrigin";
22
23
  import { turnstile } from "@pithy-sh/turnstile/src/http/middleware";
23
24
  //#region src/http/routes.ts
25
+ /**
26
+ * What a route answers when the answer is Better Auth's: the catch-all, and the two endpoints of its that
27
+ * are mounted ahead of it for a gate. Its wire is its own contract (`handleBetterAuth` says why), so the
28
+ * kit's contract points at it rather than restating it.
29
+ */
30
+ const BETTER_AUTH_ANSWER = {
31
+ description: "Better Auth's own answer. See its endpoint reference.",
32
+ contentType: "application/json"
33
+ };
24
34
  function db(c, wiring) {
25
35
  return authDatabase(resolveDb(c.env, wiring.config.database));
26
36
  }
@@ -65,14 +75,55 @@ function createAuthRoutes(wiring) {
65
75
  app.use(`${base}/sign-in/magic-link`, guard);
66
76
  app.use(`${base}/email-otp/send-verification-otp`, guard);
67
77
  }
68
- app.post(`${base}/token/rotate`, csrf, (c) => rotateToken(c, wiring));
69
- app.get(`${base}/devices`, requireAuth(), (c) => listMyDevices(c, wiring));
70
- app.post(`${base}/devices/revoke`, requireAuth(), csrf, zValidator("json", RevokeDeviceBody, validationHook), (c) => revokeMyDevice(c, wiring, c.req.valid("json")));
71
- app.post(`${base}/link-social`, requireFreshAuthentication("link"), (c) => handleBetterAuth(c, wiring));
72
- app.post(`${base}/unlink-account`, requireFreshAuthentication("unlink"), (c) => handleBetterAuth(c, wiring));
73
- app.get(`${base}${PROFILE_IMAGE_PATH}`, requireAuth(), (c) => serveMyImage(c, wiring));
78
+ app.post(`${base}/token/rotate`, describeRoute({
79
+ summary: "Trade the current refresh credential for a new access token and its successor.",
80
+ description: "The presented session is spent. Presenting it again after a short grace window is read as theft, and revokes every session descended from the same sign-in.",
81
+ verification: ["bearer", "session"],
82
+ responses: { 200: TokenRotateResponse }
83
+ }), csrf, (c) => rotateToken(c, wiring));
84
+ app.get(`${base}/devices`, describeRoute({
85
+ summary: "List the caller's own registered devices.",
86
+ verification: ["bearer", "session"],
87
+ responses: { 200: MyDevicesResponse }
88
+ }), requireAuth(), (c) => listMyDevices(c, wiring));
89
+ app.post(`${base}/devices/revoke`, describeRoute({
90
+ summary: "Sign out one of the caller's own devices and forget it.",
91
+ verification: ["bearer", "session"],
92
+ responses: { 200: MyDeviceRevokeResponse }
93
+ }), requireAuth(), csrf, validate("json", RevokeDeviceBody), (c) => revokeMyDevice(c, wiring, c.req.valid("json")));
94
+ app.post(`${base}/link-social`, describeRoute({
95
+ summary: "Connect another sign-in provider to the caller's account.",
96
+ 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`.",
97
+ verification: ["bearer", "session"],
98
+ responses: { 200: BETTER_AUTH_ANSWER }
99
+ }), requireFreshAuthentication("link"), (c) => handleBetterAuth(c, wiring));
100
+ app.post(`${base}/unlink-account`, describeRoute({
101
+ summary: "Disconnect a sign-in provider from the caller's account.",
102
+ 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`.",
103
+ verification: ["bearer", "session"],
104
+ responses: { 200: BETTER_AUTH_ANSWER }
105
+ }), requireFreshAuthentication("unlink"), (c) => handleBetterAuth(c, wiring));
106
+ app.get(`${base}${PROFILE_IMAGE_PATH}`, describeRoute({
107
+ summary: "Read the caller's own stored picture.",
108
+ description: "A picture linked from a provider, or stored as a vector, is not served here and answers 404. The response is private and immutable: the URL a client is handed carries the picture's version.",
109
+ verification: ["bearer", "session"],
110
+ responses: { 200: {
111
+ description: "The caller's stored picture, as PNG, JPEG or WebP bytes.",
112
+ contentType: "image/*"
113
+ } }
114
+ }), requireAuth(), (c) => serveMyImage(c, wiring));
74
115
  registerAuthAdminRoutes(wiring)(app);
75
- app.all(`${base}/*`, (c) => handleBetterAuth(c, wiring));
116
+ app.all(`${base}/*`, describeRoute({
117
+ summary: "Everything else under the auth path, answered by Better Auth.",
118
+ description: "Sign-in, sign-up, verification, OAuth callbacks, sign-out, `/token`, `/jwks` and the rest of Better Auth's endpoints. Which credential an endpoint takes, if any, is its own decision.",
119
+ verification: [
120
+ "public",
121
+ "session",
122
+ "bearer"
123
+ ],
124
+ methods: ["get", "post"],
125
+ responses: { 200: BETTER_AUTH_ANSWER }
126
+ }), (c) => handleBetterAuth(c, wiring));
76
127
  };
77
128
  }
78
129
  /** The statuses that mean somebody was turned away, rather than that something is broken. */
@@ -3,7 +3,7 @@
3
3
  import { z } from "zod";
4
4
  /**
5
5
  * The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
6
- * (CLAUDE.md §Zod), declared on the route line with `zValidator(target, Schema, validationHook)` — so
6
+ * (CLAUDE.md §Zod), declared on the route line with `validate(target, Schema)` — so
7
7
  * reading `routes.ts` and `adminRoutes.ts` tells you what each route accepts without opening a handler.
8
8
  *
9
9
  * Only Pithy's own routes appear here. Everything under `basePath` that Better Auth owns validates
@@ -6,7 +6,7 @@ import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
6
6
  //#region src/http/schemas.ts
7
7
  /**
8
8
  * The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
9
- * (CLAUDE.md §Zod), declared on the route line with `zValidator(target, Schema, validationHook)` — so
9
+ * (CLAUDE.md §Zod), declared on the route line with `validate(target, Schema)` — so
10
10
  * reading `routes.ts` and `adminRoutes.ts` tells you what each route accepts without opening a handler.
11
11
  *
12
12
  * Only Pithy's own routes appear here. Everything under `basePath` that Better Auth owns validates
@@ -1 +1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B,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,0FAA0F;IAC1F,MAAM,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IACjD,0FAA0F;IAC1F,KAAK,EAAE,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAC/C,4FAA4F;IAC5F,QAAQ,EAAE,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;IACrD,0FAA0F;IAC1F,MAAM,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,iBAAiB,CAK3D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAC/C,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,GAC/B,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAOxC;AAyBD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,iBAAiB,GAC3B,gBAAgB,GAAG,SAAS,CAO9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,UAAU,CAQ1E"}
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { PithyError } from "@pithy-sh/core/src/error/pithyError";
4
4
  import { z } from "zod";
5
+ import { pithyCommand } from "@pithy-sh/core/src/cli/command";
5
6
  //#region src/instance/providers.ts
6
7
  /**
7
8
  * The one `disabled` value, so the state has one spelling.
@@ -105,7 +106,7 @@ function providerUnavailable(provider) {
105
106
  code: "auth/provider_unavailable",
106
107
  status: 503,
107
108
  message: `Signing in with ${provider} is unavailable right now. Use a magic link instead.`,
108
- action: `Provision \`auth-${provider}-credentials\` for this environment with \`pithy secrets create\`, or set \`${provider}.enabled\` to false in pithy.config.ts.`,
109
+ action: `Provision \`auth-${provider}-credentials\` for this environment with \`${pithyCommand("secrets create", { args: [`auth-${provider}-credentials`] })}\`, or set \`${provider}.enabled\` to false in pithy.config.ts.`,
109
110
  detail: `provider ${provider} is enabled and its credential could not be resolved; the instance was built without it`
110
111
  });
111
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"devSession.d.ts","sourceRoot":"","sources":["../../src/seeds/devSession.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkC,KAAK,QAAQ,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC5G,OAAO,EAA6D,KAAK,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,QAAiB,CAAC;AAM1D;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,QAAkC,CAAC;AAUvE,kHAAkH;AAClH,eAAO,MAAM,cAAc;;iBAWxB,CAAC;AACJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAE7D;;;;;;GAMG;AACH,eAAO,MAAM,UAAU;;;iBAKgF,CAAC;AACxG,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAErD,sGAAsG;AACtG,MAAM,WAAW,cAAc;IAC7B,gEAAgE;IAChE,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWpF;AAED,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IAChC,qCA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;;;GAWG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE;IACzC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ,GAAG,OAAO,CAAC,SAAS,CAAC,CAKrB;AAuDD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,OA2C/B,CAAC"}
@@ -4,6 +4,7 @@ import { DEV_PROTOCOL, sessionCookieName } from "../http/baseUrl.js";
4
4
  import { AUTH_SESSION_SECRET } from "../instance/secrets.js";
5
5
  import { ValidationError, fromZodError } from "@pithy-sh/core/src/error/pithyError";
6
6
  import { z } from "zod";
7
+ import { commandName } from "@pithy-sh/core/src/cli/command";
7
8
  import { DEV_LOGIN_FILE, DevLogins } from "@pithy-sh/core/src/seed/devLogin";
8
9
  import { normalizeAddress } from "@pithy-sh/core/src/address/address";
9
10
  import { MAX_SEED_ORDER } from "@pithy-sh/core/src/seed/compose";
@@ -286,7 +287,7 @@ const authDevSessionSeed = defineSeed({
286
287
  const secret = await context.secret(AUTH_SESSION_SECRET);
287
288
  if (!secret) throw new ValidationError({
288
289
  message: "Cannot mint a dev session without this environment's auth secret.",
289
- action: `Add ${AUTH_SESSION_SECRET} to this project's dev secrets file — pithy doctor prints its path — then seed again.`
290
+ action: `Add ${AUTH_SESSION_SECRET} to this project's dev secrets file — ${commandName("doctor")} prints its path — then seed again.`
290
291
  });
291
292
  const minted = await mintDevLogins({
292
293
  users: [preferred, ...users.filter((user) => user.id !== preferred.id)],
@@ -1 +1 @@
1
- {"version":3,"file":"liveApp.d.ts","sourceRoot":"","sources":["../../src/test-utils/liveApp.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAuB3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,iHAAiH;AACjH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,mDAAmD;IACnD,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,0GAA0G;IAC1G,QAAQ,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACrC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9C,yFAAyF;IACzF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAyF5E"}
@@ -19,7 +19,7 @@ import { devEncryptionKeys } from "@pithy-sh/secrets/src/test-utils/devEncryptio
19
19
  import { seedSecrets } from "@pithy-sh/secrets/src/test-utils/secretFixtures";
20
20
  import { turnstileSecretsRegistry } from "@pithy-sh/turnstile/src/secret/registry";
21
21
  import { Hono } from "hono";
22
- import { Miniflare } from "miniflare";
22
+ import { Miniflare, convertV4MiniflareOptions } from "miniflare";
23
23
  //#region src/test-utils/liveApp.ts
24
24
  /**
25
25
  * A real auth Worker on a real port, for the live suites (#84).
@@ -80,14 +80,14 @@ const SESSION_SECRET = "live-e2e-secret-please-rotate-000000";
80
80
  * forgets leaves a workerd process behind.
81
81
  */
82
82
  async function startLiveApp(options) {
83
- const miniflare = new Miniflare({
83
+ const miniflare = new Miniflare(convertV4MiniflareOptions({
84
84
  modules: true,
85
85
  script: "export default {};",
86
86
  d1Databases: {
87
87
  DB: "DB",
88
88
  SECRETS: "SECRETS"
89
89
  }
90
- });
90
+ }));
91
91
  const db = await miniflare.getD1Database("DB");
92
92
  const env = {
93
93
  DB: db,
@@ -3,5 +3,5 @@
3
3
  /** This package's npm name — the join key against a release feed. */
4
4
  export declare const PACKAGE_NAME = "@pithy-sh/auth";
5
5
  /** This package's version, stamped from its own package.json at generation time. */
6
- export declare const PACKAGE_VERSION = "0.7.0";
6
+ export declare const PACKAGE_VERSION = "0.8.0";
7
7
  //# sourceMappingURL=version.generated.d.ts.map
@@ -4,6 +4,6 @@
4
4
  /** This package's npm name — the join key against a release feed. */
5
5
  const PACKAGE_NAME = "@pithy-sh/auth";
6
6
  /** This package's version, stamped from its own package.json at generation time. */
7
- const PACKAGE_VERSION = "0.7.0";
7
+ const PACKAGE_VERSION = "0.8.0";
8
8
  //#endregion
9
9
  export { PACKAGE_NAME, PACKAGE_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pithy-sh/auth",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,16 +42,16 @@
42
42
  "better-auth": "^1.7.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "@pithy-sh/core": "^0.9.0",
46
- "@pithy-sh/email": "^0.3.11",
47
- "@pithy-sh/secrets": "^0.3.2",
48
- "@pithy-sh/turnstile": "^0.4.2",
45
+ "@pithy-sh/core": "^0.10.0",
46
+ "@pithy-sh/email": "^0.4.0",
47
+ "@pithy-sh/secrets": "^0.4.0",
48
+ "@pithy-sh/turnstile": "^0.4.3",
49
49
  "hono": "^4.13.2",
50
50
  "kysely": "^0.29.0",
51
51
  "zod": "^4.4.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@cloudflare/vitest-plugin": "^1.0.0",
54
+ "@cloudflare/vitest-plugin": "^1.4.2",
55
55
  "@pithy-sh/cloudflare": "workspace:*",
56
56
  "@pithy-sh/core": "workspace:*",
57
57
  "@pithy-sh/email": "workspace:*",
@@ -63,11 +63,11 @@
63
63
  "hono": "^4.13.2",
64
64
  "kysely": "^0.29.0",
65
65
  "kysely-d1": "^0.4.0",
66
- "miniflare": "^4.20260722.1",
66
+ "miniflare": "5.20261012.0-beta",
67
67
  "tsdown": "^0.23.0",
68
68
  "typescript": "^7.0.2",
69
69
  "vitest": "^4.1.0",
70
- "wrangler": "^4.115.0",
70
+ "wrangler": "^4.151.0",
71
71
  "zod": "^4.4.0"
72
72
  }
73
73
  }
@@ -1,13 +1,13 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { zValidator } from "@hono/zod-validator";
5
4
  import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
6
5
  import type { ControlPlaneContext } from "@pithy-sh/core/src/controlPlane/context";
7
6
  import { requireControlPlane } from "@pithy-sh/core/src/controlPlane/http/guard";
8
7
  import { MAX_PAGE_SIZE } from "@pithy-sh/core/src/data/cursor";
9
8
  import { InternalError, NotFoundError } from "@pithy-sh/core/src/error/pithyError";
10
- import { validationHook } from "@pithy-sh/core/src/http/validation";
9
+ import { describeRoute } from "@pithy-sh/core/src/http/routeSpec";
10
+ import { validate } from "@pithy-sh/core/src/http/validation";
11
11
  import type { Context, Hono } from "hono";
12
12
  import {
13
13
  type AdminSubList,
@@ -33,7 +33,7 @@ import {
33
33
  AUTH_USERS_READ_SCOPE,
34
34
  } from "./guards";
35
35
  import { getAuthInstance, resolveDb } from "./resolve";
36
- import type {
36
+ import {
37
37
  AdminDeviceRevokeResponse,
38
38
  AdminDevicesResponse,
39
39
  AdminRevokeResponse,
@@ -179,8 +179,14 @@ export function registerAuthAdminRoutes(wiring: AuthWiring): (app: Hono<PithyHon
179
179
 
180
180
  app.get(
181
181
  `${base}/admin/users`,
182
+ describeRoute({
183
+ summary: "Page through the users, newest first, optionally searching by email or name.",
184
+ verification: "control-plane",
185
+ scopes: [AUTH_USERS_READ_SCOPE],
186
+ responses: { 200: AdminUsersResponse },
187
+ }),
182
188
  requireControlPlane(AUTH_USERS_READ_SCOPE),
183
- zValidator("query", ListUsersQuery, validationHook),
189
+ validate("query", ListUsersQuery),
184
190
  async (c) => {
185
191
  const query = c.req.valid("query");
186
192
  const caller = controlPlaneCaller(c);
@@ -204,8 +210,14 @@ export function registerAuthAdminRoutes(wiring: AuthWiring): (app: Hono<PithyHon
204
210
 
205
211
  app.get(
206
212
  `${base}/admin/users/:userId`,
213
+ describeRoute({
214
+ summary: "Read one user with their sessions, devices and linked providers.",
215
+ verification: "control-plane",
216
+ scopes: [AUTH_USERS_READ_SCOPE],
217
+ responses: { 200: AdminUserResponse },
218
+ }),
207
219
  requireControlPlane(AUTH_USERS_READ_SCOPE),
208
- zValidator("param", UserIdParam, validationHook),
220
+ validate("param", UserIdParam),
209
221
  async (c) => {
210
222
  const { userId } = c.req.valid("param");
211
223
  const caller = controlPlaneCaller(c);
@@ -254,8 +266,14 @@ export function registerAuthAdminRoutes(wiring: AuthWiring): (app: Hono<PithyHon
254
266
 
255
267
  app.get(
256
268
  `${base}/admin/devices`,
269
+ describeRoute({
270
+ summary: "Page through the device registry, most recently seen first.",
271
+ verification: "control-plane",
272
+ scopes: [AUTH_DEVICES_READ_SCOPE],
273
+ responses: { 200: AdminDevicesResponse },
274
+ }),
257
275
  requireControlPlane(AUTH_DEVICES_READ_SCOPE),
258
- zValidator("query", ListDevicesQuery, validationHook),
276
+ validate("query", ListDevicesQuery),
259
277
  async (c) => {
260
278
  const query = c.req.valid("query");
261
279
  const caller = controlPlaneCaller(c);
@@ -278,8 +296,14 @@ export function registerAuthAdminRoutes(wiring: AuthWiring): (app: Hono<PithyHon
278
296
 
279
297
  app.post(
280
298
  `${base}/admin/sessions/revoke`,
299
+ describeRoute({
300
+ summary: "Revoke one session by its id.",
301
+ verification: "control-plane",
302
+ scopes: [AUTH_SESSIONS_REVOKE_SCOPE],
303
+ responses: { 200: AdminRevokeResponse },
304
+ }),
281
305
  requireControlPlane(AUTH_SESSIONS_REVOKE_SCOPE),
282
- zValidator("json", RevokeSessionBody, validationHook),
306
+ validate("json", RevokeSessionBody),
283
307
  async (c) => {
284
308
  const { sessionId } = c.req.valid("json");
285
309
  const caller = controlPlaneCaller(c);
@@ -309,8 +333,14 @@ export function registerAuthAdminRoutes(wiring: AuthWiring): (app: Hono<PithyHon
309
333
 
310
334
  app.post(
311
335
  `${base}/admin/users/:userId/sessions/revoke`,
336
+ describeRoute({
337
+ summary: "Sign one user out everywhere.",
338
+ verification: "control-plane",
339
+ scopes: [AUTH_USERS_LOGOUT_SCOPE],
340
+ responses: { 200: AdminRevokeResponse },
341
+ }),
312
342
  requireControlPlane(AUTH_USERS_LOGOUT_SCOPE),
313
- zValidator("param", UserIdParam, validationHook),
343
+ validate("param", UserIdParam),
314
344
  async (c) => {
315
345
  const { userId } = c.req.valid("param");
316
346
  const caller = controlPlaneCaller(c);
@@ -335,9 +365,15 @@ export function registerAuthAdminRoutes(wiring: AuthWiring): (app: Hono<PithyHon
335
365
 
336
366
  app.post(
337
367
  `${base}/admin/users/:userId/devices/revoke`,
368
+ describeRoute({
369
+ summary: "Sign out one of a user's devices and remove it from the registry.",
370
+ verification: "control-plane",
371
+ scopes: [AUTH_DEVICES_REVOKE_SCOPE],
372
+ responses: { 200: AdminDeviceRevokeResponse },
373
+ }),
338
374
  requireControlPlane(AUTH_DEVICES_REVOKE_SCOPE),
339
- zValidator("param", UserIdParam, validationHook),
340
- zValidator("json", RevokeDeviceBody, validationHook),
375
+ validate("param", UserIdParam),
376
+ validate("json", RevokeDeviceBody),
341
377
  async (c) => {
342
378
  const { userId } = c.req.valid("param");
343
379
  const { deviceId } = c.req.valid("json");
@@ -1,12 +1,14 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { zValidator } from "@hono/zod-validator";
5
4
  import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
5
+ import { commandName, pithyCommand } from "@pithy-sh/core/src/cli/command";
6
6
  import { type AmbientEnv, ambientEnv, compositionEnvironment } from "@pithy-sh/core/src/env/ambient";
7
7
  import { isContinuousIntegration } from "@pithy-sh/core/src/env/ci";
8
8
  import { NotFoundError } from "@pithy-sh/core/src/error/pithyError";
9
- import { validationHook } from "@pithy-sh/core/src/http/validation";
9
+ import { describeRoute } from "@pithy-sh/core/src/http/routeSpec";
10
+ import { validate } from "@pithy-sh/core/src/http/validation";
11
+ import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
10
12
  import { DEV_LOGIN_CLAIM_PARAM, DEV_LOGIN_ROUTE } from "@pithy-sh/core/src/seed/devLogin";
11
13
  import type { SecretsStoreEnv } from "@pithy-sh/secrets/src/env/bindings";
12
14
  import type { Context, Hono } from "hono";
@@ -65,8 +67,19 @@ export function registerDevLoginRoute(
65
67
  if (isContinuousIntegration(env)) return;
66
68
  // The claim is read here rather than inside the handler: `c.req.valid` is typed off the chain it was
67
69
  // declared on, and a handler taking a bare `Context` has no validator to read from.
68
- app.get(DEV_LOGIN_ROUTE, zValidator("query", DevLoginQuery, validationHook), (c) =>
69
- serveDevLogin(c, wiring, c.req.valid("query")[DEV_LOGIN_CLAIM_PARAM]),
70
+ app.get(
71
+ DEV_LOGIN_ROUTE,
72
+ describeRoute({
73
+ summary: "Sign the browser in as the seeded dev user.",
74
+ description:
75
+ "Mounted only in a `dev` composition outside CI. It takes no credential: the signed claim `pithy seed` wrote into the URL is the whole of what it checks.",
76
+ verification: "public",
77
+ responses: {
78
+ 302: { description: "Signed in: sets the session cookie and redirects to `/`." },
79
+ },
80
+ }),
81
+ validate("query", DevLoginQuery),
82
+ (c) => serveDevLogin(c, wiring, c.req.valid("query")[DEV_LOGIN_CLAIM_PARAM]),
70
83
  );
71
84
  };
72
85
  }
@@ -86,7 +99,7 @@ export function registerDevLoginRoute(
86
99
  */
87
100
  function noSeededSession(): NotFoundError {
88
101
  return new NotFoundError({
89
- message: "No dev login has been seeded for this environment. Run pithy seed, then open this URL again.",
102
+ message: `No dev login has been seeded for this environment. Run ${pithyCommand("seed", { flags: { "--env": LOCAL_ENVIRONMENT } })}, then open this URL again.`,
90
103
  });
91
104
  }
92
105
 
@@ -162,7 +175,7 @@ async function serveDevLogin(
162
175
  createdAt: now,
163
176
  updatedAt: now,
164
177
  ipAddress: "127.0.0.1",
165
- userAgent: "pithy dev login",
178
+ userAgent: `${commandName("dev")} login`,
166
179
  deviceId: null,
167
180
  familyId: null,
168
181
  // A dev login is a real sign-in, so it is authenticated now — what the live hook stamps.
@@ -197,3 +197,57 @@ export const AdminDeviceRevokeResponse = z
197
197
  })
198
198
  .describe("How many sessions the device revocation ended, and whether the registry row went with them.");
199
199
  export type AdminDeviceRevokeResponse = z.output<typeof AdminDeviceRevokeResponse>;
200
+
201
+ /*
202
+ * The routes a signed-in person calls on their own account. These are not read across the management
203
+ * version boundary the admin schemas above are, but a client generated from the contract reads Workers on
204
+ * older releases too, so the same rule holds: a field added here later is `.optional()`.
205
+ */
206
+
207
+ /** `POST {base}/token/rotate`. */
208
+ export const TokenRotateResponse = z
209
+ .object({
210
+ accessToken: z
211
+ .string()
212
+ .describe("A fresh short-lived access token (a JWT) for the `Authorization: Bearer` header."),
213
+ refreshToken: z
214
+ .string()
215
+ .describe(
216
+ "The successor refresh credential: a new session token. The one presented is spent, and presenting it again past a short grace window revokes the whole family.",
217
+ ),
218
+ expiresAt: z.iso.datetime().describe("When the successor session lapses, ISO-8601."),
219
+ })
220
+ .describe("The rotated credential pair: a new access token and the session token that replaces the one presented.");
221
+ export type TokenRotateResponse = z.output<typeof TokenRotateResponse>;
222
+
223
+ /** One of the caller's own registered devices. */
224
+ export const MyDeviceView = z
225
+ .object({
226
+ id: z.string().describe("The client-generated device id it registered at sign-in."),
227
+ userId: z.string().describe("The owning user's id: always the caller's own."),
228
+ platform: DevicePlatform.describe("The platform the device registered as."),
229
+ name: z.string().nullable().describe("The device's human label, or null."),
230
+ model: z.string().nullable().describe("The hardware model, or null."),
231
+ osVersion: z.string().nullable().describe("The device OS version at last sign-in, or null."),
232
+ appVersion: z.string().nullable().describe("The client app version at last sign-in, or null."),
233
+ pushToken: z.string().nullable().describe("The APNs or FCM push token the device registered, or null."),
234
+ lastIp: z.string().nullable().describe("The client IP at the device's most recent sign-in, or null."),
235
+ lastSeenAt: z.iso.datetime().describe("When the device was last seen, ISO-8601."),
236
+ createdAt: z.iso.datetime().describe("When the device first registered, ISO-8601."),
237
+ })
238
+ .describe("One device registered to the caller's own account.");
239
+ export type MyDeviceView = z.output<typeof MyDeviceView>;
240
+
241
+ /** `GET {base}/devices`. */
242
+ export const MyDevicesResponse = z
243
+ .object({
244
+ devices: z.array(MyDeviceView).describe("Every device registered to the caller, most recently seen first."),
245
+ })
246
+ .describe("The caller's own registered devices.");
247
+ export type MyDevicesResponse = z.output<typeof MyDevicesResponse>;
248
+
249
+ /** `POST {base}/devices/revoke`. */
250
+ export const MyDeviceRevokeResponse = z
251
+ .object({ revoked: RevokedCount })
252
+ .describe("How many of the device's sessions the revocation signed out. The device's row goes with them.");
253
+ export type MyDeviceRevokeResponse = z.output<typeof MyDeviceRevokeResponse>;
@@ -1,11 +1,11 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { zValidator } from "@hono/zod-validator";
5
4
  import type { PithyHonoEnv } from "@pithy-sh/core/src/capability/capability";
6
5
  import { NotFoundError, UnauthorizedError } from "@pithy-sh/core/src/error/pithyError";
6
+ import { describeRoute, type RouteResponse } from "@pithy-sh/core/src/http/routeSpec";
7
7
  import { requireSameOrigin } from "@pithy-sh/core/src/http/sameOrigin";
8
- import { validationHook } from "@pithy-sh/core/src/http/validation";
8
+ import { validate } from "@pithy-sh/core/src/http/validation";
9
9
  import { STORED_IMAGE_HEADERS, storedImageBytes } from "@pithy-sh/core/src/image/storedImage";
10
10
  import { TURNSTILE_LOGIN_ACTION } from "@pithy-sh/turnstile/src/config/config";
11
11
  import { turnstile } from "@pithy-sh/turnstile/src/http/middleware";
@@ -29,10 +29,21 @@ import { requireAuth } from "./middleware";
29
29
  import { requireFreshAuthentication } from "./providerFreshness";
30
30
  import { collapseProviderRefusal } from "./providerRefusal";
31
31
  import { getAuthInstance, resolveDb } from "./resolve";
32
+ import { MyDeviceRevokeResponse, MyDevicesResponse, TokenRotateResponse } from "./responses";
32
33
  import { RevokeDeviceBody } from "./schemas";
33
34
 
34
35
  type Ctx = Context<PithyHonoEnv>;
35
36
 
37
+ /**
38
+ * What a route answers when the answer is Better Auth's: the catch-all, and the two endpoints of its that
39
+ * are mounted ahead of it for a gate. Its wire is its own contract (`handleBetterAuth` says why), so the
40
+ * kit's contract points at it rather than restating it.
41
+ */
42
+ const BETTER_AUTH_ANSWER: RouteResponse = {
43
+ description: "Better Auth's own answer. See its endpoint reference.",
44
+ contentType: "application/json",
45
+ };
46
+
36
47
  function db(c: Ctx, wiring: AuthWiring) {
37
48
  return authDatabase(resolveDb(c.env, wiring.config.database));
38
49
  }
@@ -85,11 +96,40 @@ export function createAuthRoutes(wiring: AuthWiring): (app: Hono<PithyHonoEnv>)
85
96
  }
86
97
 
87
98
  // Rotate the refresh credential: mint a new session, revoke the presented one, return a fresh JWT.
88
- app.post(`${base}/token/rotate`, csrf, (c) => rotateToken(c, wiring));
99
+ app.post(
100
+ `${base}/token/rotate`,
101
+ describeRoute({
102
+ summary: "Trade the current refresh credential for a new access token and its successor.",
103
+ description:
104
+ "The presented session is spent. Presenting it again after a short grace window is read as theft, and revokes every session descended from the same sign-in.",
105
+ verification: ["bearer", "session"],
106
+ responses: { 200: TokenRotateResponse },
107
+ }),
108
+ csrf,
109
+ (c) => rotateToken(c, wiring),
110
+ );
89
111
  // Device management (bearer/session gated; the revoke is CSRF-guarded as a mutating route).
90
- app.get(`${base}/devices`, requireAuth(), (c) => listMyDevices(c, wiring));
91
- app.post(`${base}/devices/revoke`, requireAuth(), csrf, zValidator("json", RevokeDeviceBody, validationHook), (c) =>
92
- revokeMyDevice(c, wiring, c.req.valid("json")),
112
+ app.get(
113
+ `${base}/devices`,
114
+ describeRoute({
115
+ summary: "List the caller's own registered devices.",
116
+ verification: ["bearer", "session"],
117
+ responses: { 200: MyDevicesResponse },
118
+ }),
119
+ requireAuth(),
120
+ (c) => listMyDevices(c, wiring),
121
+ );
122
+ app.post(
123
+ `${base}/devices/revoke`,
124
+ describeRoute({
125
+ summary: "Sign out one of the caller's own devices and forget it.",
126
+ verification: ["bearer", "session"],
127
+ responses: { 200: MyDeviceRevokeResponse },
128
+ }),
129
+ requireAuth(),
130
+ csrf,
131
+ validate("json", RevokeDeviceBody),
132
+ (c) => revokeMyDevice(c, wiring, c.req.valid("json")),
93
133
  );
94
134
 
95
135
  // **Changing which providers can sign you in requires a recent authentication — both directions.**
@@ -97,18 +137,64 @@ export function createAuthRoutes(wiring: AuthWiring): (app: Hono<PithyHonoEnv>)
97
137
  // carries the argument: Better Auth guards the two unevenly, and its guard on the unlink side reads
98
138
  // `session.createdAt`, which `/token/rotate` resets. Neither takes a kit validator — the body is
99
139
  // Better Auth's, and `handleBetterAuth` hands it `c.req.raw`, which is the catch-all's own reason.
100
- app.post(`${base}/link-social`, requireFreshAuthentication("link"), (c) => handleBetterAuth(c, wiring));
101
- app.post(`${base}/unlink-account`, requireFreshAuthentication("unlink"), (c) => handleBetterAuth(c, wiring));
140
+ app.post(
141
+ `${base}/link-social`,
142
+ describeRoute({
143
+ summary: "Connect another sign-in provider to the caller's account.",
144
+ description:
145
+ "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`.",
146
+ verification: ["bearer", "session"],
147
+ responses: { 200: BETTER_AUTH_ANSWER },
148
+ }),
149
+ requireFreshAuthentication("link"),
150
+ (c) => handleBetterAuth(c, wiring),
151
+ );
152
+ app.post(
153
+ `${base}/unlink-account`,
154
+ describeRoute({
155
+ summary: "Disconnect a sign-in provider from the caller's account.",
156
+ description:
157
+ "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`.",
158
+ verification: ["bearer", "session"],
159
+ responses: { 200: BETTER_AUTH_ANSWER },
160
+ }),
161
+ requireFreshAuthentication("unlink"),
162
+ (c) => handleBetterAuth(c, wiring),
163
+ );
102
164
 
103
165
  // The caller's own stored picture, as bytes a browser can cache. No id in the path — see
104
166
  // `serveMyImage`, which is where the reason lives.
105
- app.get(`${base}${PROFILE_IMAGE_PATH}`, requireAuth(), (c) => serveMyImage(c, wiring));
167
+ app.get(
168
+ `${base}${PROFILE_IMAGE_PATH}`,
169
+ describeRoute({
170
+ summary: "Read the caller's own stored picture.",
171
+ description:
172
+ "A picture linked from a provider, or stored as a vector, is not served here and answers 404. The response is private and immutable: the URL a client is handed carries the picture's version.",
173
+ verification: ["bearer", "session"],
174
+ responses: {
175
+ 200: { description: "The caller's stored picture, as PNG, JPEG or WebP bytes.", contentType: "image/*" },
176
+ },
177
+ }),
178
+ requireAuth(),
179
+ (c) => serveMyImage(c, wiring),
180
+ );
106
181
 
107
182
  // The control-plane management surface. Registered here, before the catch-all below, or it is dead.
108
183
  registerAuthAdminRoutes(wiring)(app);
109
184
 
110
185
  // Better Auth owns the rest (sign-in, verify, callback, sign-out, /token, /jwks, revoke-sessions…).
111
- app.all(`${base}/*`, (c) => handleBetterAuth(c, wiring));
186
+ app.all(
187
+ `${base}/*`,
188
+ describeRoute({
189
+ summary: "Everything else under the auth path, answered by Better Auth.",
190
+ description:
191
+ "Sign-in, sign-up, verification, OAuth callbacks, sign-out, `/token`, `/jwks` and the rest of Better Auth's endpoints. Which credential an endpoint takes, if any, is its own decision.",
192
+ verification: ["public", "session", "bearer"],
193
+ methods: ["get", "post"],
194
+ responses: { 200: BETTER_AUTH_ANSWER },
195
+ }),
196
+ (c) => handleBetterAuth(c, wiring),
197
+ );
112
198
  };
113
199
  }
114
200
 
@@ -7,7 +7,7 @@ import { DevicePlatform } from "../data/device";
7
7
 
8
8
  /**
9
9
  * The request schemas for the auth routes Pithy owns. Validation happens at the HTTP boundary
10
- * (CLAUDE.md §Zod), declared on the route line with `zValidator(target, Schema, validationHook)` — so
10
+ * (CLAUDE.md §Zod), declared on the route line with `validate(target, Schema)` — so
11
11
  * reading `routes.ts` and `adminRoutes.ts` tells you what each route accepts without opening a handler.
12
12
  *
13
13
  * Only Pithy's own routes appear here. Everything under `basePath` that Better Auth owns validates
@@ -1,6 +1,7 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
+ import { pithyCommand } from "@pithy-sh/core/src/cli/command";
4
5
  import { PithyError } from "@pithy-sh/core/src/error/pithyError";
5
6
  import { z } from "zod";
6
7
  import type {
@@ -179,7 +180,7 @@ export function providerUnavailable(provider: SocialProviderId): PithyError {
179
180
  code: "auth/provider_unavailable",
180
181
  status: 503,
181
182
  message: `Signing in with ${provider} is unavailable right now. Use a magic link instead.`,
182
- action: `Provision \`auth-${provider}-credentials\` for this environment with \`pithy secrets create\`, or set \`${provider}.enabled\` to false in pithy.config.ts.`,
183
+ action: `Provision \`auth-${provider}-credentials\` for this environment with \`${pithyCommand("secrets create", { args: [`auth-${provider}-credentials`] })}\`, or set \`${provider}.enabled\` to false in pithy.config.ts.`,
183
184
  detail: `provider ${provider} is enabled and its credential could not be resolved; the instance was built without it`,
184
185
  });
185
186
  }
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { normalizeAddress } from "@pithy-sh/core/src/address/address";
5
+ import { commandName } from "@pithy-sh/core/src/cli/command";
5
6
  import { fromZodError, ValidationError } from "@pithy-sh/core/src/error/pithyError";
6
7
  import { MAX_SEED_ORDER } from "@pithy-sh/core/src/seed/compose";
7
8
  import { DEV_LOGIN_FILE, DEV_LOGIN_PATH, type DevLogin, DevLogins } from "@pithy-sh/core/src/seed/devLogin";
@@ -376,7 +377,7 @@ export const authDevSessionSeed: SeedSet = defineSeed({
376
377
  // fail again with the same sentence. The path is deliberately unnamed rather than guessed: this
377
378
  // set runs inside a Worker with no filesystem and no config directory to resolve, and `pithy
378
379
  // doctor` prints the resolved path on every run precisely so a message like this does not have to.
379
- action: `Add ${AUTH_SESSION_SECRET} to this project's dev secrets file — pithy doctor prints its path — then seed again.`,
380
+ action: `Add ${AUTH_SESSION_SECRET} to this project's dev secrets file — ${commandName("doctor")} prints its path — then seed again.`,
380
381
  });
381
382
  }
382
383
 
@@ -17,7 +17,7 @@ import { devEncryptionKeys } from "@pithy-sh/secrets/src/test-utils/devEncryptio
17
17
  import { type SecretFixture, seedSecrets } from "@pithy-sh/secrets/src/test-utils/secretFixtures";
18
18
  import { turnstileSecretsRegistry } from "@pithy-sh/turnstile/src/secret/registry";
19
19
  import { Hono } from "hono";
20
- import { Miniflare } from "miniflare";
20
+ import { convertV4MiniflareOptions, Miniflare } from "miniflare";
21
21
  import { AuthConfig, type AuthWiring } from "../capability";
22
22
  import { publishSameOrigin } from "../http/csrf";
23
23
  import { createSessionMiddleware } from "../http/middleware";
@@ -150,11 +150,13 @@ export interface LiveApp {
150
150
  * forgets leaves a workerd process behind.
151
151
  */
152
152
  export async function startLiveApp(options: LiveAppOptions): Promise<LiveApp> {
153
- const miniflare = new Miniflare({
154
- modules: true,
155
- script: "export default {};",
156
- d1Databases: { DB: "DB", SECRETS: "SECRETS" },
157
- });
153
+ const miniflare = new Miniflare(
154
+ convertV4MiniflareOptions({
155
+ modules: true,
156
+ script: "export default {};",
157
+ d1Databases: { DB: "DB", SECRETS: "SECRETS" },
158
+ }),
159
+ );
158
160
  const db = (await miniflare.getD1Database("DB")) as unknown as D1Database;
159
161
  const secretsDb = (await miniflare.getD1Database("SECRETS")) as unknown as D1Database;
160
162
 
@@ -13,4 +13,4 @@
13
13
  export const PACKAGE_NAME = "@pithy-sh/auth";
14
14
 
15
15
  /** This package's version, stamped from its own package.json at generation time. */
16
- export const PACKAGE_VERSION = "0.7.0";
16
+ export const PACKAGE_VERSION = "0.8.0";