@pithy-sh/auth 0.6.7 → 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,6 +1,6 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
- import { DevLogin } from "@pithy-sh/core/src/seed/devLogin";
3
+ import { type DevLogin, DevLogins } from "@pithy-sh/core/src/seed/devLogin";
4
4
  import { type SeedSet } from "@pithy-sh/core/src/seed/seed";
5
5
  import { z } from "zod";
6
6
  /**
@@ -51,7 +51,7 @@ export declare const AUTH_DEV_SESSION_SEED_ORDER: number;
51
51
  export declare const DEV_SESSION_COOKIE_NAME: string;
52
52
  /** The developer's machine-local preferences for this project, read from `~/.config/pithy/<project>/dev.json`. */
53
53
  export declare const DevPreferences: z.ZodObject<{
54
- user: z.ZodString;
54
+ user: z.ZodOptional<z.ZodString>;
55
55
  }, z.core.$strip>;
56
56
  export type DevPreferences = z.output<typeof DevPreferences>;
57
57
  /**
@@ -127,6 +127,23 @@ export declare function verifyDevLoginClaim(claim: string, secret: string, now?:
127
127
  * opens the link, so the session is real, is theirs, and is the only thing a sign-out takes away.
128
128
  */
129
129
  export declare function mintDevLogin(input: MintDevLoginInput): Promise<MintedDevLogin>;
130
+ /**
131
+ * Mint a claim for **every** user this run seeds, keyed by user id — `#667`.
132
+ *
133
+ * Cheap by construction: a claim is a signature over a user id and an expiry, so N of them add no seeded
134
+ * rows and a few hundred bytes each.
135
+ *
136
+ * **The record keeps the order it is handed, except for integer-like ids — and that is JS, not us.** Keys
137
+ * that are canonical array indices are enumerated first and in ascending numeric order, by the language and
138
+ * again by `JSON.parse`, so an adopter whose users carry stringified integer PKs gets a numerically ordered
139
+ * picker and `dev.json`'s "offered first" does not survive for them. Keying the artifact by user id is the
140
+ * design; holding the order for every possible id would mean a different artifact shape.
141
+ */
142
+ export declare function mintDevLogins(input: {
143
+ users: readonly SeededUser[];
144
+ secret: string;
145
+ now?: Date;
146
+ }): Promise<DevLogins>;
130
147
  /**
131
148
  * The dev-login seed set. Composed by the auth capability; runs only in `dev`, only for a user this same run
132
149
  * creates, and only when the developer has opted in with a `dev.json`.
@@ -1 +1 @@
1
- {"version":3,"file":"devSession.d.ts","sourceRoot":"","sources":["../../src/seeds/devSession.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkC,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5F,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;;iBAUxB,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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G;AACH,eAAO,MAAM,kBAAkB,EAAE,OA2C/B,CAAC"}
@@ -4,7 +4,8 @@ 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 { DEV_LOGIN_FILE, DevLogin } from "@pithy-sh/core/src/seed/devLogin";
7
+ import { commandName } from "@pithy-sh/core/src/cli/command";
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";
10
11
  import { defineSeed } from "@pithy-sh/core/src/seed/seed";
@@ -66,7 +67,7 @@ const DEV_SESSION_COOKIE_NAME = sessionCookieName(DEV_PROTOCOL);
66
67
  */
67
68
  const DEV_LOGIN_LIFETIME_MS = 31536e6;
68
69
  /** The developer's machine-local preferences for this project, read from `~/.config/pithy/<project>/dev.json`. */
69
- const DevPreferences = z.object({ user: z.string().describe("The email of the seeded user to sign in as. Must be a user this seed run creates, or the seed fails rather than signing in as nobody.") }).describe("A developer's machine-local dev preferences, from the Pithy config directory (`~/.config/pithy/<project>/dev.json`, or `%APPDATA%\\pithy\\<project>\\dev.json` on Windows) — outside the repo, so opting in needs no commit.");
70
+ const DevPreferences = z.object({ user: z.string().optional().describe("The email of the seeded user to sign in as first. **This key is the dev-login opt-in**: without it no claim is minted at all, because `dev.json` has other tenants and its mere existence is not consent. With it, every seeded user gets a claim and this one is offered first. Must be a user this seed run creates, or the seed fails rather than naming nobody.") }).describe("A developer's machine-local dev preferences, from the Pithy config directory (`~/.config/pithy/<project>/dev.json`, or `%APPDATA%\\pithy\\<project>\\dev.json` on Windows) — outside the repo, so opting in needs no commit.");
70
71
  /**
71
72
  * A user this run seeds, read back out of the composed plan.
72
73
  *
@@ -209,6 +210,26 @@ async function mintDevLogin(input) {
209
210
  } };
210
211
  }
211
212
  /**
213
+ * Mint a claim for **every** user this run seeds, keyed by user id — `#667`.
214
+ *
215
+ * Cheap by construction: a claim is a signature over a user id and an expiry, so N of them add no seeded
216
+ * rows and a few hundred bytes each.
217
+ *
218
+ * **The record keeps the order it is handed, except for integer-like ids — and that is JS, not us.** Keys
219
+ * that are canonical array indices are enumerated first and in ascending numeric order, by the language and
220
+ * again by `JSON.parse`, so an adopter whose users carry stringified integer PKs gets a numerically ordered
221
+ * picker and `dev.json`'s "offered first" does not survive for them. Keying the artifact by user id is the
222
+ * design; holding the order for every possible id would mean a different artifact shape.
223
+ */
224
+ async function mintDevLogins(input) {
225
+ const minted = await Promise.all(input.users.map((user) => mintDevLogin({
226
+ user,
227
+ secret: input.secret,
228
+ ...input.now ? { now: input.now } : {}
229
+ })));
230
+ return Object.fromEntries(minted.map(({ login }) => [login.userId, login]));
231
+ }
232
+ /**
212
233
  * The users this run creates, whichever set contributes them.
213
234
  *
214
235
  * A row that does not parse is skipped rather than fatal: it belongs to some other set, which owns its own
@@ -225,17 +246,26 @@ function nameOneOf(users) {
225
246
  if (users.length === 0) return "This run seeds no users at all. Add a user fixture to your app's seed set, or turn on seed.includeExamples for the example cast.";
226
247
  return `Name one of the users this run seeds instead: ${users.map((user) => user.email).join(", ")}.`;
227
248
  }
228
- /** Resolve the preference file into the user to sign in as, or fail saying who this run does seed. */
229
- function requireUser(preferences, users) {
249
+ /**
250
+ * The email `dev.json` names, or `undefined` when it names none. A file that does not parse is a failure.
251
+ *
252
+ * Split from resolving it because the two answers differ: naming nobody is a valid file that wants no dev
253
+ * login, and naming somebody this run does not create is a typo worth failing over.
254
+ */
255
+ function namedUser(preferences, users) {
230
256
  const parsed = DevPreferences.safeParse(preferences);
231
257
  if (!parsed.success) throw fromZodError(parsed.error, {
232
- message: "The dev.json preference file does not name a user.",
258
+ message: "The dev.json preference file does not parse.",
233
259
  action: `Set { "user": "<email>" } in it. ${nameOneOf(users)}`
234
260
  });
235
- const wanted = normalizeAddress(parsed.data.user);
261
+ return parsed.data.user;
262
+ }
263
+ /** Resolve the named email to a user this run seeds, or fail saying who it does seed. */
264
+ function requireNamedUser(named, users) {
265
+ const wanted = normalizeAddress(named);
236
266
  const user = users.find((candidate) => normalizeAddress(candidate.email) === wanted);
237
267
  if (!user) throw new ValidationError({
238
- message: `dev.json asks to sign in as ${parsed.data.user}, which this seed run does not create.`,
268
+ message: `dev.json asks to sign in as ${named}, which this seed run does not create.`,
239
269
  action: nameOneOf(users)
240
270
  });
241
271
  return user;
@@ -250,21 +280,24 @@ const authDevSessionSeed = defineSeed({
250
280
  environments: ["dev"],
251
281
  prepare: async (context) => {
252
282
  if (context.preferences === void 0 || context.preferences === null) return {};
253
- const user = requireUser(context.preferences, seededUsers(context.seeded));
283
+ const users = seededUsers(context.seeded);
284
+ const named = namedUser(context.preferences, users);
285
+ if (named === void 0) return {};
286
+ const preferred = requireNamedUser(named, users);
254
287
  const secret = await context.secret(AUTH_SESSION_SECRET);
255
288
  if (!secret) throw new ValidationError({
256
289
  message: "Cannot mint a dev session without this environment's auth secret.",
257
- 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.`
258
291
  });
259
- const minted = await mintDevLogin({
260
- user,
292
+ const minted = await mintDevLogins({
293
+ users: [preferred, ...users.filter((user) => user.id !== preferred.id)],
261
294
  secret
262
295
  });
263
296
  return { artifacts: [{
264
297
  file: DEV_LOGIN_FILE,
265
- contents: `${JSON.stringify(DevLogin.encode(minted.login), null, 2)}\n`
298
+ contents: `${JSON.stringify(DevLogins.encode(minted), null, 2)}\n`
266
299
  }] };
267
300
  }
268
301
  });
269
302
  //#endregion
270
- export { AUTH_DEV_SESSION_SEED_ORDER, DEV_SESSION_COOKIE_NAME, DevPreferences, SeededUser, authDevSessionSeed, mintDevLogin, signCookieValue, signDevLoginClaim, verifyDevLoginClaim };
303
+ export { AUTH_DEV_SESSION_SEED_ORDER, DEV_SESSION_COOKIE_NAME, DevPreferences, SeededUser, authDevSessionSeed, mintDevLogin, mintDevLogins, signCookieValue, signDevLoginClaim, verifyDevLoginClaim };
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAA0D,CAAC;AAErF,4GAA4G;AAC5G,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAwBD,4GAA4G;AAC5G,MAAM,WAAW,aAAa;IAC5B,qFAAqF;IACrF,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,uGAAuG;AACvG,MAAM,WAAW,cAAc;IAC7B;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,mFAAmF;IACnF,MAAM,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAChE,yGAAyG;IACzG,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC7E;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,sGAAsG;IACtG,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,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAChE,yGAAyG;IACzG,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IAC7E;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,mFAAmF;AACnF,MAAM,WAAW,OAAO;IACtB,sGAAsG;IACtG,MAAM,EAAE,MAAM,CAAC;IACf,uGAAuG;IACvG,QAAQ,EAAE,MAAM,CAAC;IACjB,mGAAmG;IACnG,WAAW,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.6.7";
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.6.7";
7
+ const PACKAGE_VERSION = "0.8.0";
8
8
  //#endregion
9
9
  export { PACKAGE_NAME, PACKAGE_VERSION };