@flytedesk/app-kit 11.3.0 → 11.5.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 (72) hide show
  1. package/README.md +128 -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/chat/tools/index.d.ts +38 -0
  15. package/dist/chat/tools/index.js +60 -0
  16. package/dist/chat/tools/index.js.map +1 -0
  17. package/dist/cli/auth-sync.d.ts +2 -0
  18. package/dist/cli/auth-sync.js +23 -0
  19. package/dist/cli/auth-sync.js.map +1 -0
  20. package/dist/flytebot/client.d.ts +66 -0
  21. package/dist/flytebot/client.js +377 -0
  22. package/dist/flytebot/client.js.map +1 -0
  23. package/dist/flytebot/env.d.ts +11 -0
  24. package/dist/flytebot/env.js +25 -0
  25. package/dist/flytebot/env.js.map +1 -0
  26. package/dist/flytebot/error.d.ts +36 -0
  27. package/dist/flytebot/error.js +60 -0
  28. package/dist/flytebot/error.js.map +1 -0
  29. package/dist/flytebot/index.d.ts +32 -0
  30. package/dist/flytebot/index.js +28 -0
  31. package/dist/flytebot/index.js.map +1 -0
  32. package/dist/flytebot/sse.d.ts +11 -0
  33. package/dist/flytebot/sse.js +55 -0
  34. package/dist/flytebot/sse.js.map +1 -0
  35. package/dist/flytebot/testing/fake.d.ts +77 -0
  36. package/dist/flytebot/testing/fake.js +399 -0
  37. package/dist/flytebot/testing/fake.js.map +1 -0
  38. package/dist/flytebot/testing/index.d.ts +18 -0
  39. package/dist/flytebot/testing/index.js +18 -0
  40. package/dist/flytebot/testing/index.js.map +1 -0
  41. package/dist/flytebot/webhook.d.ts +24 -0
  42. package/dist/flytebot/webhook.js +63 -0
  43. package/dist/flytebot/webhook.js.map +1 -0
  44. package/dist/repo-check/checkNarration.d.ts +13 -0
  45. package/dist/repo-check/checkNarration.js +346 -0
  46. package/dist/repo-check/checkNarration.js.map +1 -0
  47. package/dist/repo-check/checkNoNul.d.ts +3 -0
  48. package/dist/repo-check/checkNoNul.js +35 -0
  49. package/dist/repo-check/checkNoNul.js.map +1 -0
  50. package/dist/repo-check/cli.d.ts +9 -0
  51. package/dist/repo-check/cli.js +103 -0
  52. package/dist/repo-check/cli.js.map +1 -0
  53. package/dist/repo-check/config.d.ts +13 -0
  54. package/dist/repo-check/config.js +39 -0
  55. package/dist/repo-check/config.js.map +1 -0
  56. package/dist/repo-check/repoFiles.d.ts +8 -0
  57. package/dist/repo-check/repoFiles.js +44 -0
  58. package/dist/repo-check/repoFiles.js.map +1 -0
  59. package/dist/repo-check/repoHygiene.d.ts +5 -0
  60. package/dist/repo-check/repoHygiene.js +12 -0
  61. package/dist/repo-check/repoHygiene.js.map +1 -0
  62. package/dist/repo-check/scriptComments.d.ts +28 -0
  63. package/dist/repo-check/scriptComments.js +243 -0
  64. package/dist/repo-check/scriptComments.js.map +1 -0
  65. package/dist/spa-server/index.d.ts +25 -0
  66. package/dist/spa-server/index.js +35 -2
  67. package/dist/spa-server/index.js.map +1 -1
  68. package/package.json +26 -3
  69. package/prisma/fragments/auth.meta.json +4 -0
  70. package/prisma/fragments/auth.prisma +75 -0
  71. package/prisma/migrations/0004_app_kit_auth_init/migration.sql +47 -0
  72. package/prisma/migrations/manifest.json +7 -0
@@ -0,0 +1,75 @@
1
+ // @flytedesk/app-kit/auth/prisma — canonical Prisma model fragment (AK-59).
2
+ //
3
+ // The three tables behind `PrismaAuthStore` (the `AuthStore` on Prisma): the IdP
4
+ // session, the rotating refresh tokens and the reuse-detection audit trail. Like every
5
+ // other fragment it is NOT built into a client by this package: `auth-sync init` copies
6
+ // it into the consumer's own Prisma schema, and the consumer generates their own client.
7
+ //
8
+ // Design constraints (same reasoning as trace.prisma / profile.prisma):
9
+ // - No Prisma `enum`: `revokedReason` is a plain String column, holding exactly
10
+ // app-kit's `RefreshTokenRevocationReason` union. `PrismaAuthStore` validates it on
11
+ // read and throws on anything else.
12
+ // - Models are named IdpSession / RefreshToken / AuthAuditLog so a client exposes
13
+ // `idpSession`, `refreshToken` and `authAuditLog`, exactly what `PrismaAuthStore`'s
14
+ // structural client asks for. Tables are prefixed `app_kit_` via `@@map`; columns are snake_case via `@map`,
15
+ // matching prisma/migrations/0004_app_kit_auth_init/migration.sql exactly.
16
+ // - The only relation is IdpSession -> RefreshToken (both models are in this
17
+ // fragment): signing out deletes the session and the cascade removes its tokens.
18
+ // - `refresh_tokens_revocation_complete` (a CHECK in the migration) makes
19
+ // `revokedAt` and `revokedReason` NULL together: a revoked row always says why.
20
+
21
+ model IdpSession {
22
+ id String @id @default(uuid())
23
+ subject String
24
+ name String
25
+ email String
26
+ idpAccessToken String @map("idp_access_token")
27
+ idpAccessTokenExpiresAt DateTime @map("idp_access_token_expires_at")
28
+ idpRefreshToken String? @map("idp_refresh_token")
29
+ /// The OIDC `id_token` flytedesk ID issued at sign-in; sign-out sends it back as the
30
+ /// `id_token_hint` of RP-initiated logout.
31
+ idToken String @map("id_token")
32
+ createdAt DateTime @default(now()) @map("created_at")
33
+ refreshTokens RefreshToken[]
34
+
35
+ @@map("app_kit_idp_session")
36
+ }
37
+
38
+ model RefreshToken {
39
+ id String @id
40
+ familyId String @map("family_id")
41
+ userId String @map("user_id")
42
+ tokenHash String @unique @map("token_hash")
43
+ idpSessionId String @map("idp_session_id")
44
+ idpSession IdpSession @relation(fields: [idpSessionId], references: [id], onDelete: Cascade)
45
+ revokedAt DateTime? @map("revoked_at")
46
+ /// NULL exactly when `revokedAt` is NULL (CHECK constraint in the migration).
47
+ revokedReason String? @map("revoked_reason")
48
+ expiresAt DateTime @map("expires_at")
49
+ userAgent String? @map("user_agent")
50
+ ip String
51
+ /// The id of the token this one was rotated FROM; null for the first token of a family.
52
+ replacesId String? @map("replaces_id")
53
+ createdAt DateTime @default(now()) @map("created_at")
54
+
55
+ @@index([familyId])
56
+ @@index([replacesId])
57
+ @@index([idpSessionId])
58
+ @@map("app_kit_refresh_token")
59
+ }
60
+
61
+ /// Written once per detected reuse (a refresh token already rotated away was presented
62
+ /// again), in the same transaction as the family revoke. `rotatedAt` is the exact instant
63
+ /// `rotateRefreshToken` persisted for the replayed row, never derived from a duration.
64
+ model AuthAuditLog {
65
+ id String @id @default(uuid())
66
+ familyId String @map("family_id")
67
+ reason String
68
+ rotatedAt DateTime @map("rotated_at")
69
+ ip String?
70
+ userAgent String? @map("user_agent")
71
+ createdAt DateTime @default(now()) @map("created_at")
72
+
73
+ @@index([familyId])
74
+ @@map("app_kit_auth_audit_log")
75
+ }
@@ -0,0 +1,47 @@
1
+ -- @flytedesk/app-kit/auth/prisma :: 0004_app_kit_auth_init
2
+ --
3
+ -- Hand-written raw SQL (this package does not run `prisma migrate dev` against its
4
+ -- own schema — see 0001_app_kit_trace_init's migration.sql). Columns match
5
+ -- prisma/fragments/auth.prisma exactly.
6
+ CREATE TABLE app_kit_idp_session (
7
+ id TEXT PRIMARY KEY,
8
+ subject TEXT NOT NULL,
9
+ name TEXT NOT NULL,
10
+ email TEXT NOT NULL,
11
+ idp_access_token TEXT NOT NULL,
12
+ idp_access_token_expires_at TIMESTAMPTZ NOT NULL,
13
+ idp_refresh_token TEXT,
14
+ id_token TEXT NOT NULL,
15
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
16
+ );
17
+
18
+ CREATE TABLE app_kit_refresh_token (
19
+ id TEXT PRIMARY KEY,
20
+ family_id TEXT NOT NULL,
21
+ user_id TEXT NOT NULL,
22
+ token_hash TEXT NOT NULL UNIQUE,
23
+ idp_session_id TEXT NOT NULL REFERENCES app_kit_idp_session(id) ON DELETE CASCADE,
24
+ revoked_at TIMESTAMPTZ,
25
+ revoked_reason TEXT,
26
+ expires_at TIMESTAMPTZ NOT NULL,
27
+ user_agent TEXT,
28
+ ip TEXT NOT NULL,
29
+ replaces_id TEXT,
30
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
31
+ -- A revoked row always says why, and a live one never does.
32
+ CONSTRAINT app_kit_refresh_token_revocation_complete CHECK ((revoked_at IS NULL) = (revoked_reason IS NULL))
33
+ );
34
+ CREATE INDEX app_kit_refresh_token_family_id_idx ON app_kit_refresh_token (family_id);
35
+ CREATE INDEX app_kit_refresh_token_replaces_id_idx ON app_kit_refresh_token (replaces_id);
36
+ CREATE INDEX app_kit_refresh_token_idp_session_id_idx ON app_kit_refresh_token (idp_session_id);
37
+
38
+ CREATE TABLE app_kit_auth_audit_log (
39
+ id TEXT PRIMARY KEY,
40
+ family_id TEXT NOT NULL,
41
+ reason TEXT NOT NULL,
42
+ rotated_at TIMESTAMPTZ NOT NULL,
43
+ ip TEXT,
44
+ user_agent TEXT,
45
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
46
+ );
47
+ CREATE INDEX app_kit_auth_audit_log_family_id_idx ON app_kit_auth_audit_log (family_id);
@@ -19,5 +19,12 @@
19
19
  "file": "0003_app_kit_flags_init/migration.sql",
20
20
  "checksum": "sha256:55a781c3118fdaf7c4aa9405a8867cecfd8c4b9de0a6e14ef90fc364c63f7d39",
21
21
  "introducedInFragmentVersion": "1.0.0"
22
+ },
23
+ {
24
+ "id": "0004_app_kit_auth_init",
25
+ "fragment": "auth",
26
+ "file": "0004_app_kit_auth_init/migration.sql",
27
+ "checksum": "sha256:250648ba01fa97e5f48cd6940b1b7d54de5c7d3ed88d4ea259c90d8c59d35077",
28
+ "introducedInFragmentVersion": "1.0.0"
22
29
  }
23
30
  ]