@flytedesk/app-kit 11.3.0 → 11.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +25 -0
  2. package/dist/auth/guards.d.ts +4 -0
  3. package/dist/auth/guards.js +22 -0
  4. package/dist/auth/guards.js.map +1 -1
  5. package/dist/auth/index.d.ts +1 -1
  6. package/dist/auth/index.js +1 -1
  7. package/dist/auth/index.js.map +1 -1
  8. package/dist/auth/prisma/index.d.ts +1 -0
  9. package/dist/auth/prisma/index.js +2 -0
  10. package/dist/auth/prisma/index.js.map +1 -0
  11. package/dist/auth/prisma/prismaAuthStore.d.ts +181 -0
  12. package/dist/auth/prisma/prismaAuthStore.js +273 -0
  13. package/dist/auth/prisma/prismaAuthStore.js.map +1 -0
  14. package/dist/cli/auth-sync.d.ts +2 -0
  15. package/dist/cli/auth-sync.js +23 -0
  16. package/dist/cli/auth-sync.js.map +1 -0
  17. package/dist/repo-check/checkNarration.d.ts +13 -0
  18. package/dist/repo-check/checkNarration.js +346 -0
  19. package/dist/repo-check/checkNarration.js.map +1 -0
  20. package/dist/repo-check/checkNoNul.d.ts +3 -0
  21. package/dist/repo-check/checkNoNul.js +35 -0
  22. package/dist/repo-check/checkNoNul.js.map +1 -0
  23. package/dist/repo-check/cli.d.ts +9 -0
  24. package/dist/repo-check/cli.js +103 -0
  25. package/dist/repo-check/cli.js.map +1 -0
  26. package/dist/repo-check/config.d.ts +13 -0
  27. package/dist/repo-check/config.js +39 -0
  28. package/dist/repo-check/config.js.map +1 -0
  29. package/dist/repo-check/repoFiles.d.ts +8 -0
  30. package/dist/repo-check/repoFiles.js +44 -0
  31. package/dist/repo-check/repoFiles.js.map +1 -0
  32. package/dist/repo-check/repoHygiene.d.ts +5 -0
  33. package/dist/repo-check/repoHygiene.js +12 -0
  34. package/dist/repo-check/repoHygiene.js.map +1 -0
  35. package/dist/repo-check/scriptComments.d.ts +28 -0
  36. package/dist/repo-check/scriptComments.js +243 -0
  37. package/dist/repo-check/scriptComments.js.map +1 -0
  38. package/dist/spa-server/index.d.ts +25 -0
  39. package/dist/spa-server/index.js +35 -2
  40. package/dist/spa-server/index.js.map +1 -1
  41. package/package.json +10 -2
  42. package/prisma/fragments/auth.meta.json +4 -0
  43. package/prisma/fragments/auth.prisma +75 -0
  44. package/prisma/migrations/0004_app_kit_auth_init/migration.sql +47 -0
  45. package/prisma/migrations/manifest.json +7 -0
package/README.md CHANGED
@@ -97,6 +97,23 @@ await api.register(flytedeskAuth, {
97
97
  });
98
98
  ```
99
99
 
100
+ **Three pieces an app uses from app-kit and never writes itself** (each used to be copied
101
+ from app to app):
102
+
103
+ - **The `AuthStore`**: `PrismaAuthStore` from `@flytedesk/app-kit/auth/prisma`. It holds
104
+ the refresh-token rotation, family revocation (with the reuse-detection audit row) and
105
+ the session lock. It takes the app's own generated Prisma client (typed structurally,
106
+ so no generated client is imported). Install its models with `npx auth-sync init`
107
+ (`prisma/fragments/auth.prisma`: `IdpSession`, `RefreshToken`, `AuthAuditLog`), then
108
+ `new PrismaAuthStore(prisma)` is the `store` above.
109
+ - **The any-of-these-permissions guard**: `requireAnyPermission("chat", "admin")` from
110
+ `@flytedesk/app-kit/auth`, beside `requirePermission` (which wants all keys). It
111
+ refuses with the same 401/503/403 bodies.
112
+ - **The SPA cache policy**: hashed assets `public, max-age=31536000, immutable`,
113
+ `index.html` and every SPA-fallback route `no-cache`. `createSpaServer` and the
114
+ `spa-server` bin apply it; a Fastify app that serves its own SPA registers
115
+ `spaCachePolicy` from `@flytedesk/app-kit/spa-server` inside a scope that holds only its SPA routes (or calls `spaCacheControl(pathname)`).
116
+
100
117
  Its `AuthStore` persists `IdpSessionRow.idToken`, which is sent back to flytedesk ID as the
101
118
  logout's `id_token_hint`. That is what lets flytedesk ID end its session without a
102
119
  confirmation step for a real sign-out, while still asking on a forged one.
@@ -620,3 +637,11 @@ tip (or a given ref), runs `npm run check`, applies pending changesets
620
637
  and prints a final `RESULT:` line. Every change under `src/` merges to `main` with a
621
638
  changeset in `.changeset/`; it sits there until the next release. Full steps:
622
639
  `.danxbot/config/workflow.md`, "Publishing".
640
+
641
+ ## Repo hygiene checks (`app-kit-repo-check`)
642
+
643
+ `app-kit-repo-check <narration|no-nul|hygiene|script-comments|repo-files> [--root <dir>] [--config <file>]`
644
+ runs the shared hygiene checks over a tree and exits 1 naming each finding. Per-repo values
645
+ live in `app-kit-repo-check.json` at the root (all optional): `excludedDirs` (added to the
646
+ built-in `node_modules`, `.git`, `dist`, ...), `narrationAllowlist` (exact strings the
647
+ narration check accepts) and `narrationExcludedBasenames` (files never read).
@@ -16,6 +16,10 @@ export declare function requireAuth(request: FastifyRequest, reply: FastifyReply
16
16
  /** Every route re-checks permissions server-side. 403s name the missing permission(s)
17
17
  * in `detail`, so a caller (or its UI) can tell exactly what was missing. */
18
18
  export declare function requirePermission(...permission: string[]): (request: FastifyRequest, reply: FastifyReply, done: () => void) => void;
19
+ /** For a route open to a caller holding ANY ONE of `permissions` (`requirePermission`
20
+ * wants all of them). Refuses like `requirePermission` does — 401/503 first, then the
21
+ * same 403 body — with `detail` naming the keys of which one was needed. */
22
+ export declare function requireAnyPermission(...permissions: string[]): (request: FastifyRequest, reply: FastifyReply, done: () => void) => void;
19
23
  /**
20
24
  * Answers the request unless it carries a signed-in PERSON, and returns whether it did:
21
25
  * `rejectUnauthenticated`'s 401/503 first, then `403 person_only` for a service
@@ -43,6 +43,28 @@ export function requirePermission(...permission) {
43
43
  done();
44
44
  };
45
45
  }
46
+ /** For a route open to a caller holding ANY ONE of `permissions` (`requirePermission`
47
+ * wants all of them). Refuses like `requirePermission` does — 401/503 first, then the
48
+ * same 403 body — with `detail` naming the keys of which one was needed. */
49
+ export function requireAnyPermission(...permissions) {
50
+ // An empty list would refuse everyone silently; it is a route written wrong.
51
+ if (permissions.length === 0) {
52
+ throw new Error("@flytedesk/app-kit/auth: requireAnyPermission() needs at least one permission key");
53
+ }
54
+ return function anyPermissionPreHandler(request, reply, done) {
55
+ if (rejectUnauthenticated(request, reply))
56
+ return;
57
+ if (!permissions.some((p) => request.authUser.permissions.includes(p))) {
58
+ reply.code(403).send({
59
+ error: "Missing permission",
60
+ code: "forbidden",
61
+ detail: `one of: ${permissions.join(", ")}`,
62
+ });
63
+ return;
64
+ }
65
+ done();
66
+ };
67
+ }
46
68
  /**
47
69
  * Answers the request unless it carries a signed-in PERSON, and returns whether it did:
48
70
  * `rejectUnauthenticated`'s 401/503 first, then `403 person_only` for a service
@@ -1 +1 @@
1
- {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/auth/guards.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAuB,EAAE,KAAmB;IAChF,IAAI,OAAO,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;QAC5B,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,yBAAyB,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACpF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAuB,EAAE,KAAmB,EAAE,IAAgB;IACxF,IAAI,qBAAqB,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO;IAClD,IAAI,EAAE,CAAC;AACT,CAAC;AAED;8EAC8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,GAAG,UAAoB;IACvD,OAAO,SAAS,oBAAoB,CAClC,OAAuB,EACvB,KAAmB,EACnB,IAAgB;QAEhB,IAAI,qBAAqB,CAAC,OAAO,EAAE,KAAK,CA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K,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,4CAA4C,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;IACnG,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;oDAEoD;AACpD,MAAM,UAAU,aAAa,CAAC,OAAuB,EAAE,KAAmB,EAAE,IAAgB;IAC1F,IAAI,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO;IAC/C,IAAI,EAAE,CAAC;AACT,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAuB;IAClD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;IAC9B,IAAI,IAAI,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CACb,oFAAoF,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,iBAAiB,wCAAwC,CAClL,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -47,7 +47,7 @@
47
47
  * `readRoute` and `requirePerson`, and `@flytedesk/app-kit/auth/service` for the
48
48
  * caller's side.
49
49
  */
50
- export { authedPerson, requireAuth, requirePermission, requirePerson } from "./guards.js";
50
+ export { authedPerson, requireAnyPermission, requireAuth, requirePermission, requirePerson } from "./guards.js";
51
51
  export { readRoute } from "./readRoute.js";
52
52
  export type { AuthedUser, AuthStore, CreateIdpSessionInput, CreateRefreshTokenInput, DelegatedIdentity, DelegatedOutcome, FlytedeskAuthOptions, IdpRole, IdpSessionLockedStore, IdpSessionRow, RefreshTokenRevocation, RefreshTokenRevocationReason, RefreshTokenRow, RevokeFamilyReason, ServicePrincipalUser, UpdateIdpSessionInput, UserinfoClaims, } from "./types.js";
53
53
  export type { AppSwitcherEntry, IdpAuthorization, IdpServiceAuthorization, IdpTokenResponse, IdTokenClaims, OidcClient, OidcClientOptions, ServiceAccessTokenClaims, } from "./oidc-client.js";
@@ -47,7 +47,7 @@
47
47
  * `readRoute` and `requirePerson`, and `@flytedesk/app-kit/auth/service` for the
48
48
  * caller's side.
49
49
  */
50
- export { authedPerson, requireAuth, requirePermission, requirePerson } from "./guards.js";
50
+ export { authedPerson, requireAnyPermission, requireAuth, requirePermission, requirePerson } from "./guards.js";
51
51
  export { readRoute } from "./readRoute.js";
52
52
  export { createOidcClient, DEFAULT_OIDC_SCOPES, DEFAULT_IDP_REQUEST_TIMEOUT_MS } from "./oidc-client.js";
53
53
  export { AUTH_REQUEST_DEADLINE_MS, AUTH_ROUTE_PREFIX, AUTH_ROUTE_SEGMENTS, AUTH_UNAVAILABLE_CODES, authRoutePath, SIGNIN_ERROR_QUERY_PARAM, SIGNIN_ERROR_CODES, } from "./shared-types.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAgC3C,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAOzG,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAErE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAElB,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAChH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAgC3C,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAOzG,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,wBAAwB,EACxB,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAErE,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAElB,MAAM,aAAa,CAAC"}
@@ -0,0 +1 @@
1
+ export { PrismaAuthStore, type PrismaAuthClient } from "./prismaAuthStore.js";
@@ -0,0 +1,2 @@
1
+ export { PrismaAuthStore } from "./prismaAuthStore.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/prisma/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAyB,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,181 @@
1
+ import type { AuthStore, CreateIdpSessionInput, CreateRefreshTokenInput, IdpSessionLockedStore, IdpSessionRow, RefreshTokenRow, RevokeFamilyReason, UpdateIdpSessionInput } from "../types.js";
2
+ interface IdpSessionData {
3
+ id: string;
4
+ subject: string;
5
+ name: string;
6
+ email: string;
7
+ idpAccessToken: string;
8
+ idpAccessTokenExpiresAt: Date;
9
+ idpRefreshToken: string | null;
10
+ idToken: string;
11
+ }
12
+ interface RefreshTokenData {
13
+ id: string;
14
+ familyId: string;
15
+ userId: string;
16
+ idpSessionId: string;
17
+ expiresAt: Date;
18
+ ip: string;
19
+ userAgent: string | null;
20
+ revokedAt: Date | null;
21
+ revokedReason: string | null;
22
+ }
23
+ /** The IdP-session half of the structural client. */
24
+ interface IdpSessionModel {
25
+ findUnique(args: {
26
+ where: {
27
+ id: string;
28
+ };
29
+ }): Promise<IdpSessionData | null>;
30
+ update(args: {
31
+ where: {
32
+ id: string;
33
+ };
34
+ data: {
35
+ idpAccessToken?: string;
36
+ idpAccessTokenExpiresAt?: Date;
37
+ idpRefreshToken?: string | null;
38
+ };
39
+ }): Promise<unknown>;
40
+ create(args: {
41
+ data: Omit<IdpSessionData, "id">;
42
+ select: {
43
+ id: true;
44
+ };
45
+ }): Promise<{
46
+ id: string;
47
+ }>;
48
+ delete(args: {
49
+ where: {
50
+ id: string;
51
+ };
52
+ }): Promise<unknown>;
53
+ }
54
+ interface RefreshTokenModel {
55
+ create(args: {
56
+ data: {
57
+ id: string;
58
+ familyId: string;
59
+ userId: string;
60
+ tokenHash: string;
61
+ expiresAt: Date;
62
+ idpSessionId: string;
63
+ userAgent: string | null;
64
+ ip: string;
65
+ replacesId: string | null;
66
+ };
67
+ }): Promise<unknown>;
68
+ findUnique(args: {
69
+ where: {
70
+ tokenHash: string;
71
+ };
72
+ }): Promise<RefreshTokenData | null>;
73
+ findFirst(args: {
74
+ where: {
75
+ idpSessionId: string;
76
+ revokedAt: null;
77
+ expiresAt: {
78
+ gt: Date;
79
+ };
80
+ };
81
+ orderBy: {
82
+ createdAt: "desc";
83
+ };
84
+ }): Promise<RefreshTokenData | null>;
85
+ updateMany(args: {
86
+ where: {
87
+ id: string;
88
+ revokedAt: null;
89
+ } | {
90
+ familyId: string;
91
+ revokedAt: null;
92
+ };
93
+ data: {
94
+ revokedAt: Date;
95
+ revokedReason: string;
96
+ };
97
+ }): Promise<{
98
+ count: number;
99
+ }>;
100
+ }
101
+ interface AuthAuditLogModel {
102
+ create(args: {
103
+ data: {
104
+ familyId: string;
105
+ reason: string;
106
+ rotatedAt: Date;
107
+ ip: string | null;
108
+ userAgent: string | null;
109
+ };
110
+ }): Promise<unknown>;
111
+ }
112
+ /** What a transaction (or the pool) must expose: the three fragment models plus the raw
113
+ * executor the advisory lock goes through. */
114
+ interface PrismaAuthTransaction {
115
+ idpSession: IdpSessionModel;
116
+ refreshToken: RefreshTokenModel;
117
+ authAuditLog: AuthAuditLogModel;
118
+ $executeRaw(query: TemplateStringsArray, ...values: unknown[]): Promise<number>;
119
+ }
120
+ /** A generated Prisma client (carrying `prisma/fragments/auth.prisma`'s models) satisfies this. */
121
+ export interface PrismaAuthClient extends PrismaAuthTransaction {
122
+ $transaction<T>(fn: (tx: PrismaAuthTransaction) => Promise<T>, options: {
123
+ timeout: number;
124
+ maxWait: number;
125
+ }): Promise<T>;
126
+ }
127
+ /**
128
+ * `withIdpSessionLock` hands its callback a store bound to the SAME transaction the
129
+ * advisory lock lives on; `rotateRefreshToken` is one atomic transaction end to end;
130
+ * `revokeFamily` takes the same per-family lock so it can never race a concurrent
131
+ * rotation. The advisory-lock primitive itself lives in `@flytedesk/app-kit/postgres`.
132
+ */
133
+ export declare class PrismaAuthStore implements AuthStore {
134
+ private readonly prisma;
135
+ /** The pooled (unlocked) store — `POST {routePrefix}/refresh`'s initial read runs here,
136
+ * outside any lock; only reads/writes done WHILE holding `withIdpSessionLock` run on
137
+ * that lock's own transaction. */
138
+ private readonly pooled;
139
+ constructor(prisma: PrismaAuthClient);
140
+ findIdpSession(id: string): Promise<IdpSessionRow | null>;
141
+ updateIdpSession(id: string, patch: UpdateIdpSessionInput): Promise<void>;
142
+ createRefreshToken(row: CreateRefreshTokenInput): Promise<void>;
143
+ findRefreshTokenByHash(hash: string): Promise<RefreshTokenRow | null>;
144
+ /**
145
+ * Whether the IdP session is still signed in. Reuse detection and an authorization
146
+ * rejection revoke the family without deleting the session, so the session row existing
147
+ * proves nothing; a live refresh token (not revoked, not expired at `now`, the app's
148
+ * clock) of the session does. A sign-out deletes the session, cascading its tokens.
149
+ */
150
+ findLiveRefreshTokenForSession(idpSessionId: string, now: Date): Promise<RefreshTokenRow | null>;
151
+ /**
152
+ * One transaction — take the family lock, conditionally revoke `presentedId` with reason
153
+ * "rotated" (claims iff it was still live), and only then insert `successor`. `rotatedAt`
154
+ * (not `new Date()`) is persisted: the ONE-clock rule in `AuthStore`'s doc comment.
155
+ */
156
+ rotateRefreshToken(presentedId: string, successor: CreateRefreshTokenInput, rotatedAt: Date): Promise<boolean>;
157
+ /**
158
+ * Takes the SAME per-family lock as `rotateRefreshToken` before revoking, so whichever
159
+ * of a concurrent sign-out/rotation pair runs second sees the other's committed rows
160
+ * (under READ COMMITTED, skipping the lock lets a rotation's successor survive a revoke
161
+ * that started just before it committed). The reuse-detection audit write is in the SAME
162
+ * transaction as the revoke: a reuse is revoked AND audited, or neither.
163
+ */
164
+ revokeFamily(familyId: string, reason: RevokeFamilyReason, revokedAt: Date): Promise<void>;
165
+ createIdpSession(row: CreateIdpSessionInput): Promise<{
166
+ id: string;
167
+ }>;
168
+ deleteIdpSession(id: string): Promise<void>;
169
+ /**
170
+ * `fn` is handed an `IdpSessionLockedStore` bound to the SAME transaction the advisory
171
+ * lock lives on, so a lock holder never needs a second pooled connection: one that had
172
+ * to reach back into the pool would let concurrent stale-session refreshes exhaust it
173
+ * and sign out every session still waiting once their number reached the pool's size.
174
+ *
175
+ * Residual risk (documented on the contract): if `updateIdpSession` or this transaction's
176
+ * commit fails after flytedesk-id already rotated its own refresh token, that new token
177
+ * is lost and the user must sign in again.
178
+ */
179
+ withIdpSessionLock<T>(sessionId: string, fn: (locked: IdpSessionLockedStore) => Promise<T>): Promise<T>;
180
+ }
181
+ export {};
@@ -0,0 +1,273 @@
1
+ /**
2
+ * `PrismaAuthStore` (AK-59): the one Prisma implementation of the `AuthStore` seam — the
3
+ * security-critical rotation, family revocation and locking logic every flytedesk ID app
4
+ * used to copy (sms-app's `authStore.ts` was the reference, Flytebot copied it verbatim).
5
+ *
6
+ * Typed against `PrismaAuthClient`, a structural client of just the models and methods
7
+ * used, never a generated client: each app passes its own `PrismaClient` generated from
8
+ * a schema holding `prisma/fragments/auth.prisma` (installed with `auth-sync init`).
9
+ */
10
+ import { acquireAdvisoryLock } from "../../postgres/index.js";
11
+ /** How long a lock (the IdP-session lock or the refresh-token-family lock) may wait for a
12
+ * competing holder before failing with Postgres 55P03 — comfortably under the
13
+ * transaction `timeout` below (which must exceed lock wait + one IdP call). */
14
+ const LOCK_TIMEOUT_MS = 5_000;
15
+ /**
16
+ * Options of every multi-statement transaction this store opens (`rotateRefreshToken`,
17
+ * `revokeFamily`, `withIdpSessionLock`) — defined once so the numbers can never drift.
18
+ *
19
+ * `timeout` bounds how long the transaction's OWN work may run once started: it must
20
+ * exceed `LOCK_TIMEOUT_MS` plus one IdP round trip (`idpRequestTimeoutMs`, default 5s),
21
+ * so a lock holder legitimately waiting on flytedesk-id is never killed by its own timeout.
22
+ *
23
+ * `maxWait` bounds only how long Prisma queues for a free POOLED CONNECTION before the
24
+ * transaction may start — deliberately 5s, not `timeout`'s 15s: a pool under contention
25
+ * (an IdP outage, a pile-up of lock waiters) should fail fast with Prisma's P2028 and
26
+ * let the caller answer 503, rather than queue 25+ requests 15s deep for a connection
27
+ * that may never free up in time to matter.
28
+ */
29
+ const AUTH_STORE_TRANSACTION_OPTIONS = {
30
+ timeout: 15_000,
31
+ maxWait: 5_000,
32
+ };
33
+ const REFRESH_TOKEN_FAMILY_LOCK_NAMESPACE = "refresh-token-family";
34
+ const IDP_SESSION_LOCK_NAMESPACE = "idp-session";
35
+ const REVOCATION_REASONS = [
36
+ "rotated",
37
+ "reuse_detected",
38
+ "signed_out",
39
+ "authorization_rejected",
40
+ ];
41
+ /** `IdpSessionLockedStore` bound to whichever client `db` is — the lock's own transaction
42
+ * inside `withIdpSessionLock`, so a lock holder never needs a second pooled connection. */
43
+ function idpSessionStoreOn(db) {
44
+ return {
45
+ async findIdpSession(id) {
46
+ const row = await db.idpSession.findUnique({ where: { id } });
47
+ if (!row)
48
+ return null;
49
+ return {
50
+ id: row.id,
51
+ subject: row.subject,
52
+ name: row.name,
53
+ email: row.email,
54
+ idpAccessToken: row.idpAccessToken,
55
+ idpAccessTokenExpiresAt: row.idpAccessTokenExpiresAt,
56
+ idpRefreshToken: row.idpRefreshToken,
57
+ idToken: row.idToken,
58
+ };
59
+ },
60
+ async updateIdpSession(id, patch) {
61
+ await db.idpSession.update({
62
+ where: { id },
63
+ data: {
64
+ idpAccessToken: patch.idpAccessToken,
65
+ idpAccessTokenExpiresAt: patch.idpAccessTokenExpiresAt,
66
+ idpRefreshToken: patch.idpRefreshToken,
67
+ },
68
+ });
69
+ },
70
+ };
71
+ }
72
+ function toRevocation(revokedAt, revokedReason) {
73
+ if (!revokedAt)
74
+ return null;
75
+ // The migration's CHECK constraint makes a revoked row without a reason impossible from
76
+ // any write this store makes; reaching it means a write bypassed this store, which must
77
+ // fail loudly rather than guess a reason (there is no safe default).
78
+ if (!revokedReason || !REVOCATION_REASONS.includes(revokedReason)) {
79
+ throw new Error(`RefreshToken revoked at ${revokedAt.toISOString()} carries ${revokedReason === null ? "no revokedReason" : `an unknown revokedReason "${revokedReason}"`}`);
80
+ }
81
+ return {
82
+ at: revokedAt,
83
+ reason: revokedReason,
84
+ };
85
+ }
86
+ function toRefreshTokenRow(row) {
87
+ return {
88
+ id: row.id,
89
+ familyId: row.familyId,
90
+ userId: row.userId,
91
+ idpSessionId: row.idpSessionId,
92
+ expiresAt: row.expiresAt,
93
+ ip: row.ip,
94
+ userAgent: row.userAgent,
95
+ revocation: toRevocation(row.revokedAt, row.revokedReason),
96
+ };
97
+ }
98
+ /** Prisma's "record to delete does not exist" error, recognised by code so this module
99
+ * needs no `@prisma/client` import. */
100
+ function isRecordNotFound(err) {
101
+ return (typeof err === "object" &&
102
+ err !== null &&
103
+ err.code === "P2025");
104
+ }
105
+ /**
106
+ * `withIdpSessionLock` hands its callback a store bound to the SAME transaction the
107
+ * advisory lock lives on; `rotateRefreshToken` is one atomic transaction end to end;
108
+ * `revokeFamily` takes the same per-family lock so it can never race a concurrent
109
+ * rotation. The advisory-lock primitive itself lives in `@flytedesk/app-kit/postgres`.
110
+ */
111
+ export class PrismaAuthStore {
112
+ prisma;
113
+ /** The pooled (unlocked) store — `POST {routePrefix}/refresh`'s initial read runs here,
114
+ * outside any lock; only reads/writes done WHILE holding `withIdpSessionLock` run on
115
+ * that lock's own transaction. */
116
+ pooled;
117
+ constructor(prisma) {
118
+ this.prisma = prisma;
119
+ this.pooled = idpSessionStoreOn(prisma);
120
+ }
121
+ findIdpSession(id) {
122
+ return this.pooled.findIdpSession(id);
123
+ }
124
+ updateIdpSession(id, patch) {
125
+ return this.pooled.updateIdpSession(id, patch);
126
+ }
127
+ async createRefreshToken(row) {
128
+ await this.prisma.refreshToken.create({
129
+ data: refreshTokenData(row, null),
130
+ });
131
+ }
132
+ async findRefreshTokenByHash(hash) {
133
+ const row = await this.prisma.refreshToken.findUnique({
134
+ where: { tokenHash: hash },
135
+ });
136
+ return row ? toRefreshTokenRow(row) : null;
137
+ }
138
+ /**
139
+ * Whether the IdP session is still signed in. Reuse detection and an authorization
140
+ * rejection revoke the family without deleting the session, so the session row existing
141
+ * proves nothing; a live refresh token (not revoked, not expired at `now`, the app's
142
+ * clock) of the session does. A sign-out deletes the session, cascading its tokens.
143
+ */
144
+ async findLiveRefreshTokenForSession(idpSessionId, now) {
145
+ const row = await this.prisma.refreshToken.findFirst({
146
+ where: { idpSessionId, revokedAt: null, expiresAt: { gt: now } },
147
+ orderBy: { createdAt: "desc" },
148
+ });
149
+ return row ? toRefreshTokenRow(row) : null;
150
+ }
151
+ /**
152
+ * One transaction — take the family lock, conditionally revoke `presentedId` with reason
153
+ * "rotated" (claims iff it was still live), and only then insert `successor`. `rotatedAt`
154
+ * (not `new Date()`) is persisted: the ONE-clock rule in `AuthStore`'s doc comment.
155
+ */
156
+ async rotateRefreshToken(presentedId, successor, rotatedAt) {
157
+ return this.prisma.$transaction(async (tx) => {
158
+ await lockFamily(tx, successor.familyId);
159
+ const claimed = await tx.refreshToken.updateMany({
160
+ where: { id: presentedId, revokedAt: null },
161
+ data: { revokedAt: rotatedAt, revokedReason: "rotated" },
162
+ });
163
+ if (claimed.count !== 1)
164
+ return false;
165
+ await tx.refreshToken.create({
166
+ data: refreshTokenData(successor, presentedId),
167
+ });
168
+ return true;
169
+ }, AUTH_STORE_TRANSACTION_OPTIONS);
170
+ }
171
+ /**
172
+ * Takes the SAME per-family lock as `rotateRefreshToken` before revoking, so whichever
173
+ * of a concurrent sign-out/rotation pair runs second sees the other's committed rows
174
+ * (under READ COMMITTED, skipping the lock lets a rotation's successor survive a revoke
175
+ * that started just before it committed). The reuse-detection audit write is in the SAME
176
+ * transaction as the revoke: a reuse is revoked AND audited, or neither.
177
+ */
178
+ async revokeFamily(familyId, reason, revokedAt) {
179
+ await this.prisma.$transaction(async (tx) => {
180
+ await lockFamily(tx, familyId);
181
+ await tx.refreshToken.updateMany({
182
+ where: { familyId, revokedAt: null },
183
+ data: { revokedAt, revokedReason: reason.type },
184
+ });
185
+ // An audit row only for reuse detection — the one reason that is a real, actionable
186
+ // security event (a replayed refresh token); the others are ordinary session
187
+ // lifecycle, already explained by the RefreshToken rows' own revocation.
188
+ if (reason.type === "reuse_detected") {
189
+ const rotation = reason.replayedToken.revocation;
190
+ if (!rotation) {
191
+ // The plugin raises `reuse_detected` only for a row it just read as revoked
192
+ // "rotated"; a null revocation means the row is not what the contract
193
+ // describes, and guessing a timestamp would misrecord a real security event.
194
+ throw new Error(`reuse_detected for family ${familyId}: replayedToken ${reason.replayedToken.id} carries no revocation`);
195
+ }
196
+ await tx.authAuditLog.create({
197
+ data: {
198
+ familyId,
199
+ reason: reason.type,
200
+ // The exact instant `rotateRefreshToken` persisted for this row — never
201
+ // re-derived from `reason.sinceRotatedMs`, which would drift by however long
202
+ // this request took to reach the revoke (and overflows a 32-bit column after
203
+ // ~24.8 idle days).
204
+ rotatedAt: rotation.at,
205
+ ip: reason.ip,
206
+ userAgent: reason.userAgent,
207
+ },
208
+ });
209
+ }
210
+ }, AUTH_STORE_TRANSACTION_OPTIONS);
211
+ }
212
+ async createIdpSession(row) {
213
+ return this.prisma.idpSession.create({
214
+ data: {
215
+ subject: row.subject,
216
+ name: row.name,
217
+ email: row.email,
218
+ idpAccessToken: row.idpAccessToken,
219
+ idpAccessTokenExpiresAt: row.idpAccessTokenExpiresAt,
220
+ idpRefreshToken: row.idpRefreshToken,
221
+ idToken: row.idToken,
222
+ },
223
+ select: { id: true },
224
+ });
225
+ }
226
+ async deleteIdpSession(id) {
227
+ // The row already being gone (P2025 — deleted concurrently, or never existed) is the
228
+ // one expected outcome. Every OTHER failure must reach the caller: the logout route
229
+ // surfaces it (502 `logout_store_failed`) instead of reporting "signed out" while the
230
+ // IdpSession row (and the IdP tokens it holds) leaked.
231
+ try {
232
+ await this.prisma.idpSession.delete({ where: { id } });
233
+ }
234
+ catch (err) {
235
+ if (isRecordNotFound(err))
236
+ return;
237
+ throw err;
238
+ }
239
+ }
240
+ /**
241
+ * `fn` is handed an `IdpSessionLockedStore` bound to the SAME transaction the advisory
242
+ * lock lives on, so a lock holder never needs a second pooled connection: one that had
243
+ * to reach back into the pool would let concurrent stale-session refreshes exhaust it
244
+ * and sign out every session still waiting once their number reached the pool's size.
245
+ *
246
+ * Residual risk (documented on the contract): if `updateIdpSession` or this transaction's
247
+ * commit fails after flytedesk-id already rotated its own refresh token, that new token
248
+ * is lost and the user must sign in again.
249
+ */
250
+ async withIdpSessionLock(sessionId, fn) {
251
+ return this.prisma.$transaction(async (tx) => {
252
+ await acquireAdvisoryLock(tx, { namespace: IDP_SESSION_LOCK_NAMESPACE, id: sessionId }, LOCK_TIMEOUT_MS);
253
+ return fn(idpSessionStoreOn(tx));
254
+ }, AUTH_STORE_TRANSACTION_OPTIONS);
255
+ }
256
+ }
257
+ function refreshTokenData(row, replacesId) {
258
+ return {
259
+ id: row.id,
260
+ familyId: row.familyId,
261
+ userId: row.userId,
262
+ tokenHash: row.tokenHash,
263
+ expiresAt: row.expiresAt,
264
+ idpSessionId: row.idpSessionId,
265
+ userAgent: row.userAgent,
266
+ ip: row.ip,
267
+ replacesId,
268
+ };
269
+ }
270
+ function lockFamily(tx, familyId) {
271
+ return acquireAdvisoryLock(tx, { namespace: REFRESH_TOKEN_FAMILY_LOCK_NAMESPACE, id: familyId }, LOCK_TIMEOUT_MS);
272
+ }
273
+ //# sourceMappingURL=prismaAuthStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prismaAuthStore.js","sourceRoot":"","sources":["../../../src/auth/prisma/prismaAuthStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAa9D;;gFAEgF;AAChF,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;;;;;;GAaG;AACH,MAAM,8BAA8B,GAAG;IACrC,OAAO,EAAE,MAAM;IACf,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,MAAM,mCAAmC,GAAG,sBAAsB,CAAC;AACnE,MAAM,0BAA0B,GAAG,aAAa,CAAC;AAEjD,MAAM,kBAAkB,GAAsB;IAC5C,SAAS;IACT,gBAAgB;IAChB,YAAY;IACZ,wBAAwB;CACgB,CAAC;AAuG3C;4FAC4F;AAC5F,SAAS,iBAAiB,CAAC,EAE1B;IACC,OAAO;QACL,KAAK,CAAC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E,EACF,EAAE,SAAS,EAAE,0BAA0B,EAAE,EAAE,EAAE,SAAS,EAAE,EACxD,eAAe,CAChB,CAAC;YACF,OAAO,EAAE,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,CAAC,EAAE,8BAA8B,CAAC,CAAC;IACrC,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,GAA4B,EAC5B,UAAyB;IAEzB,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,YAAY,EAAE,GAAG,CAAC,YAAY;QAC9B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,UAAU;KACX,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,EAAyB,EACzB,QAAgB;IAEhB,OAAO,mBAAmB,CACxB,EAAE,EACF,EAAE,SAAS,EAAE,mCAAmC,EAAE,EAAE,EAAE,QAAQ,EAAE,EAChE,eAAe,CAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(argv: string[]): Promise<void>;
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * auth-sync — the CLI half of @flytedesk/app-kit/auth (DEC-39).
4
+ *
5
+ * A thin wrapper around the generalized sync engine in ./sync-engine.js — see that
6
+ * file's doc comment for the full subcommand reference (init/diff/apply/status) and
7
+ * how fragments/migrations/lock files work. This file only supplies the "auth"
8
+ * fragment name and the "auth-sync" bin name; trace-sync.ts/profile-sync.ts are the
9
+ * same wrapper for the trace/profile fragments.
10
+ */
11
+ import { isRunningAsMain, runSyncCli, SyncCliError } from "./sync-engine.js";
12
+ export async function main(argv) {
13
+ return runSyncCli(argv, { name: "auth", binName: "auth-sync" });
14
+ }
15
+ if (isRunningAsMain(import.meta.url)) {
16
+ main(process.argv.slice(2)).catch((err) => {
17
+ if (!(err instanceof SyncCliError)) {
18
+ console.error(err);
19
+ }
20
+ process.exitCode = process.exitCode ?? 1;
21
+ });
22
+ }
23
+ //# sourceMappingURL=auth-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-sync.js","sourceRoot":"","sources":["../../src/cli/auth-sync.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE7E,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAc;IACvC,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,IAAI,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;QACjD,IAAI,CAAC,CAAC,GAAG,YAAY,YAAY,CAAC,EAAE,CAAC;YACnC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { RepoCheckConfig } from "./config.js";
2
+ export declare const NARRATION_PATTERN: RegExp;
3
+ export interface NarrationHit {
4
+ file: string;
5
+ line: number;
6
+ match: string;
7
+ }
8
+ /** Scans every source file under `rootDir` for `NARRATION_PATTERN`, inside
9
+ * comments and test titles only (see `extractFragments`). A match listed in
10
+ * `config.narrationAllowlist` is skipped; a file whose basename is in
11
+ * `config.narrationExcludedBasenames` is not read (a checker's own module and
12
+ * test spell out the forbidden patterns as data). */
13
+ export declare function scanForNarration(rootDir: string, config: RepoCheckConfig): NarrationHit[];