@flytedesk/app-kit 11.2.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 (48) hide show
  1. package/README.md +26 -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/csv/index.d.ts +19 -0
  18. package/dist/csv/index.js +36 -0
  19. package/dist/csv/index.js.map +1 -0
  20. package/dist/repo-check/checkNarration.d.ts +13 -0
  21. package/dist/repo-check/checkNarration.js +346 -0
  22. package/dist/repo-check/checkNarration.js.map +1 -0
  23. package/dist/repo-check/checkNoNul.d.ts +3 -0
  24. package/dist/repo-check/checkNoNul.js +35 -0
  25. package/dist/repo-check/checkNoNul.js.map +1 -0
  26. package/dist/repo-check/cli.d.ts +9 -0
  27. package/dist/repo-check/cli.js +103 -0
  28. package/dist/repo-check/cli.js.map +1 -0
  29. package/dist/repo-check/config.d.ts +13 -0
  30. package/dist/repo-check/config.js +39 -0
  31. package/dist/repo-check/config.js.map +1 -0
  32. package/dist/repo-check/repoFiles.d.ts +8 -0
  33. package/dist/repo-check/repoFiles.js +44 -0
  34. package/dist/repo-check/repoFiles.js.map +1 -0
  35. package/dist/repo-check/repoHygiene.d.ts +5 -0
  36. package/dist/repo-check/repoHygiene.js +12 -0
  37. package/dist/repo-check/repoHygiene.js.map +1 -0
  38. package/dist/repo-check/scriptComments.d.ts +28 -0
  39. package/dist/repo-check/scriptComments.js +243 -0
  40. package/dist/repo-check/scriptComments.js.map +1 -0
  41. package/dist/spa-server/index.d.ts +25 -0
  42. package/dist/spa-server/index.js +35 -2
  43. package/dist/spa-server/index.js.map +1 -1
  44. package/package.json +14 -2
  45. package/prisma/fragments/auth.meta.json +4 -0
  46. package/prisma/fragments/auth.prisma +75 -0
  47. package/prisma/migrations/0004_app_kit_auth_init/migration.sql +47 -0
  48. package/prisma/migrations/manifest.json +7 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The one walk over the repo's files that the whole-repo hygiene checks share: every
3
+ * file under a root whose extension is in a given set, skipping the directories named in a given
4
+ * set. A check names what it reads and what it skips; it never walks the tree itself.
5
+ */
6
+ import { readdirSync, statSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ /** Directories no check reads: dependency/build output no one hand-writes into, VCS internals,
9
+ * and a checked-out worktree (a full separate copy of the same repo — scanning it would just
10
+ * double-report, or scan another in-flight change's uncommitted work). A repo's config adds
11
+ * its own to these. */
12
+ export const DEFAULT_EXCLUDED_DIRS = [
13
+ "node_modules",
14
+ ".git",
15
+ "dist",
16
+ "build",
17
+ "coverage",
18
+ ".turbo",
19
+ ".claude",
20
+ "playwright-report",
21
+ "test-results",
22
+ ];
23
+ export function extensionOf(fileName) {
24
+ const dot = fileName.lastIndexOf(".");
25
+ return dot === -1 ? "" : fileName.slice(dot);
26
+ }
27
+ /** The absolute paths of the files under `rootDir` with one of `extensions`, outside `excludedDirs`. */
28
+ export function listRepoFiles(rootDir, extensions, excludedDirs) {
29
+ const out = [];
30
+ const walk = (dir) => {
31
+ for (const entry of readdirSync(dir)) {
32
+ if (excludedDirs.includes(entry))
33
+ continue;
34
+ const full = join(dir, entry);
35
+ if (statSync(full).isDirectory())
36
+ walk(full);
37
+ else if (extensions.has(extensionOf(entry)))
38
+ out.push(full);
39
+ }
40
+ };
41
+ walk(rootDir);
42
+ return out;
43
+ }
44
+ //# sourceMappingURL=repoFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repoFiles.js","sourceRoot":"","sources":["../../src/repo-check/repoFiles.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;wBAGwB;AACxB,MAAM,CAAC,MAAM,qBAAqB,GAAsB;IACtD,cAAc;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACP,UAAU;IACV,QAAQ;IACR,SAAS;IACT,mBAAmB;IACnB,cAAc;CACf,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,aAAa,CAC3B,OAAe,EACf,UAA+B,EAC/B,YAA+B;IAE/B,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,IAAI,GAAG,CAAC,GAAW,EAAQ,EAAE;QACjC,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,IAAI,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAAE,SAAS;YAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC9B,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;gBAAE,IAAI,CAAC,IAAI,CAAC,CAAC;iBACxC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,CAAC,CAAC;IACd,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { RepoCheckConfig } from "./config.js";
2
+ /** One line per finding of either whole-repo hygiene check under `rootDir`; empty when the tree
3
+ * is clean. A NUL byte makes grep and git treat a file as binary, and review narration rots
4
+ * once the review is over, so both are checked across the whole tree by every repo's gate. */
5
+ export declare function repoHygieneFindings(rootDir: string, config: RepoCheckConfig): string[];
@@ -0,0 +1,12 @@
1
+ import { scanForNarration } from "./checkNarration.js";
2
+ import { findFilesWithNul } from "./checkNoNul.js";
3
+ /** One line per finding of either whole-repo hygiene check under `rootDir`; empty when the tree
4
+ * is clean. A NUL byte makes grep and git treat a file as binary, and review narration rots
5
+ * once the review is over, so both are checked across the whole tree by every repo's gate. */
6
+ export function repoHygieneFindings(rootDir, config) {
7
+ return [
8
+ ...findFilesWithNul(rootDir, config).map((file) => `${file}: holds a NUL byte`),
9
+ ...scanForNarration(rootDir, config).map((hit) => `${hit.file.replaceAll("\\", "/")}:${hit.line}: review narration "${hit.match}"`),
10
+ ];
11
+ }
12
+ //# sourceMappingURL=repoHygiene.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repoHygiene.js","sourceRoot":"","sources":["../../src/repo-check/repoHygiene.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;+FAE+F;AAC/F,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,MAAuB;IAEvB,OAAO;QACL,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CACtC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,oBAAoB,CACtC;QACD,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CACtC,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,uBAAuB,GAAG,CAAC,KAAK,GAAG,CACnF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Comment extraction for the two non-JavaScript languages this repo's
3
+ * infrastructure is written in: shell (`.sh`) and Terraform's HCL (`.tf`).
4
+ *
5
+ * Like the JavaScript extractor in `checkNarration.ts`, this is a lightweight
6
+ * tokenizer, not a parser. It only has to answer one question well: which
7
+ * characters are comment text and which are code or string content. A `#`
8
+ * inside a quoted string, inside `$#`, `${#name}` or `${name#prefix}`, or in a
9
+ * URL fragment is never a comment; a `#` that begins a word in shell, or any
10
+ * `#` outside a string in HCL, is one.
11
+ *
12
+ * Handled: single-quoted and double-quoted strings, `$(...)` command
13
+ * substitution (nested quotes included) inside shell double quotes, `${...}`
14
+ * template interpolation (nested strings included) inside HCL strings, and
15
+ * here-document / heredoc bodies, whose contents are neither comments nor code.
16
+ * Known limits (no script in this repo uses them today): a shell `${param}` expansion
17
+ * whose own text contains an unpaired quote character is not tracked separately
18
+ * (paired quotes inside one tokenize correctly); a comment inside a `$(...)` in double
19
+ * quotes is skipped, not reported; and `<< word` used as a shift is read as a heredoc.
20
+ */
21
+ export interface CommentFragment {
22
+ /** 1-based line the comment text starts on. */
23
+ line: number;
24
+ text: string;
25
+ }
26
+ export type ScriptDialect = "shell" | "hcl";
27
+ /** Every comment in `source`, with the line it starts on. */
28
+ export declare function extractScriptComments(source: string, dialect: ScriptDialect): CommentFragment[];
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Comment extraction for the two non-JavaScript languages this repo's
3
+ * infrastructure is written in: shell (`.sh`) and Terraform's HCL (`.tf`).
4
+ *
5
+ * Like the JavaScript extractor in `checkNarration.ts`, this is a lightweight
6
+ * tokenizer, not a parser. It only has to answer one question well: which
7
+ * characters are comment text and which are code or string content. A `#`
8
+ * inside a quoted string, inside `$#`, `${#name}` or `${name#prefix}`, or in a
9
+ * URL fragment is never a comment; a `#` that begins a word in shell, or any
10
+ * `#` outside a string in HCL, is one.
11
+ *
12
+ * Handled: single-quoted and double-quoted strings, `$(...)` command
13
+ * substitution (nested quotes included) inside shell double quotes, `${...}`
14
+ * template interpolation (nested strings included) inside HCL strings, and
15
+ * here-document / heredoc bodies, whose contents are neither comments nor code.
16
+ * Known limits (no script in this repo uses them today): a shell `${param}` expansion
17
+ * whose own text contains an unpaired quote character is not tracked separately
18
+ * (paired quotes inside one tokenize correctly); a comment inside a `$(...)` in double
19
+ * quotes is skipped, not reported; and `<< word` used as a shift is read as a heredoc.
20
+ */
21
+ const RULES = {
22
+ shell: { hashNeedsWordStart: true, slashComments: false },
23
+ hcl: { hashNeedsWordStart: false, slashComments: true },
24
+ };
25
+ function skipShellSingleQuoted(src, i) {
26
+ const end = src.indexOf("'", i + 1);
27
+ return end === -1 ? src.length : end + 1;
28
+ }
29
+ function skipBacktickSubstitution(src, i) {
30
+ let j = i + 1;
31
+ while (j < src.length) {
32
+ if (src[j] === "\\")
33
+ j += 2;
34
+ else if (src[j] === "`")
35
+ return j + 1;
36
+ else
37
+ j++;
38
+ }
39
+ return src.length;
40
+ }
41
+ /** `start` is the index right after `$(`; returns the index right after the
42
+ * matching `)`. Strings inside are consumed whole so a paren in one never
43
+ * counts. */
44
+ function skipShellCommandSubstitution(src, start) {
45
+ let depth = 1;
46
+ let j = start;
47
+ while (j < src.length && depth > 0) {
48
+ const ch = src[j];
49
+ if (ch === "\\") {
50
+ j += 2;
51
+ continue;
52
+ }
53
+ if (ch === "'") {
54
+ j = skipShellSingleQuoted(src, j);
55
+ continue;
56
+ }
57
+ if (ch === '"') {
58
+ j = skipShellDoubleQuoted(src, j);
59
+ continue;
60
+ }
61
+ if (ch === "#" && (j === start || /[\s;&|(]/.test(src[j - 1]))) {
62
+ // A comment inside the substitution runs to the end of its line, quotes and all.
63
+ const newline = src.indexOf("\n", j);
64
+ if (newline === -1)
65
+ return src.length;
66
+ j = newline;
67
+ continue;
68
+ }
69
+ if (ch === "(")
70
+ depth++;
71
+ else if (ch === ")")
72
+ depth--;
73
+ j++;
74
+ }
75
+ return j;
76
+ }
77
+ function skipShellDoubleQuoted(src, i) {
78
+ let j = i + 1;
79
+ while (j < src.length) {
80
+ const ch = src[j];
81
+ if (ch === "\\") {
82
+ j += 2;
83
+ }
84
+ else if (ch === '"') {
85
+ return j + 1;
86
+ }
87
+ else if (ch === "$" && src[j + 1] === "(") {
88
+ j = skipShellCommandSubstitution(src, j + 2);
89
+ }
90
+ else if (ch === "`") {
91
+ j = skipBacktickSubstitution(src, j);
92
+ }
93
+ else {
94
+ j++;
95
+ }
96
+ }
97
+ return src.length;
98
+ }
99
+ /** `start` is the index right after `${`; returns the index right after the
100
+ * matching `}`. */
101
+ function skipHclInterpolation(src, start) {
102
+ let depth = 1;
103
+ let j = start;
104
+ while (j < src.length && depth > 0) {
105
+ const ch = src[j];
106
+ if (ch === '"') {
107
+ j = skipHclString(src, j);
108
+ continue;
109
+ }
110
+ if (ch === "{")
111
+ depth++;
112
+ else if (ch === "}")
113
+ depth--;
114
+ j++;
115
+ }
116
+ return j;
117
+ }
118
+ function skipHclString(src, i) {
119
+ let j = i + 1;
120
+ while (j < src.length) {
121
+ const ch = src[j];
122
+ if (ch === "\\") {
123
+ j += 2;
124
+ }
125
+ else if (ch === '"') {
126
+ return j + 1;
127
+ }
128
+ else if (src.startsWith("$${", j) || src.startsWith("%%{", j)) {
129
+ j += 3;
130
+ }
131
+ else if ((ch === "$" || ch === "%") && src[j + 1] === "{") {
132
+ j = skipHclInterpolation(src, j + 2);
133
+ }
134
+ else {
135
+ j++;
136
+ }
137
+ }
138
+ return src.length;
139
+ }
140
+ const HEREDOC_START = /^<<-?[ \t]*(?:'([A-Za-z_]\w*)'|"([A-Za-z_]\w*)"|([A-Za-z_]\w*))/;
141
+ /** Index right after the terminator line of a heredoc whose body starts at
142
+ * `bodyStart` (the first character of the line after the opener). */
143
+ function skipHeredocBody(src, bodyStart, terminator) {
144
+ let lineStart = bodyStart;
145
+ while (lineStart < src.length) {
146
+ const newline = src.indexOf("\n", lineStart);
147
+ const lineEnd = newline === -1 ? src.length : newline;
148
+ if (src.slice(lineStart, lineEnd).trim() === terminator)
149
+ return lineEnd;
150
+ lineStart = lineEnd + 1;
151
+ }
152
+ return src.length;
153
+ }
154
+ function lineLocator(src) {
155
+ const lineStarts = [0];
156
+ for (let i = 0; i < src.length; i++) {
157
+ if (src[i] === "\n")
158
+ lineStarts.push(i + 1);
159
+ }
160
+ return (pos) => {
161
+ let lo = 0;
162
+ let hi = lineStarts.length - 1;
163
+ while (lo < hi) {
164
+ const mid = (lo + hi + 1) >> 1;
165
+ if (lineStarts[mid] <= pos)
166
+ lo = mid;
167
+ else
168
+ hi = mid - 1;
169
+ }
170
+ return lo + 1;
171
+ };
172
+ }
173
+ /** Every comment in `source`, with the line it starts on. */
174
+ export function extractScriptComments(source, dialect) {
175
+ const rules = RULES[dialect];
176
+ const lineOf = lineLocator(source);
177
+ const fragments = [];
178
+ const n = source.length;
179
+ let pendingHeredoc = null;
180
+ // Index right after a backslash-escaped character: a `#` there belongs to the same word.
181
+ let afterEscape = -1;
182
+ let i = 0;
183
+ while (i < n) {
184
+ const ch = source[i];
185
+ if (ch === "\n") {
186
+ if (pendingHeredoc !== null) {
187
+ i = skipHeredocBody(source, i + 1, pendingHeredoc);
188
+ pendingHeredoc = null;
189
+ }
190
+ else {
191
+ i++;
192
+ }
193
+ continue;
194
+ }
195
+ const startsComment = ch === "#" &&
196
+ i !== afterEscape &&
197
+ (!rules.hashNeedsWordStart || i === 0 || /[\s;&|(]/.test(source[i - 1]));
198
+ if (startsComment || (rules.slashComments && source.startsWith("//", i))) {
199
+ const newline = source.indexOf("\n", i);
200
+ const stop = newline === -1 ? n : newline;
201
+ fragments.push({ line: lineOf(i), text: source.slice(i, stop) });
202
+ i = stop;
203
+ continue;
204
+ }
205
+ if (rules.slashComments && source.startsWith("/*", i)) {
206
+ const close = source.indexOf("*/", i + 2);
207
+ const stop = close === -1 ? n : close + 2;
208
+ fragments.push({ line: lineOf(i), text: source.slice(i, stop) });
209
+ i = stop;
210
+ continue;
211
+ }
212
+ // `<<<word` is a here-string, not a heredoc.
213
+ if (ch === "<" &&
214
+ source.startsWith("<<", i) &&
215
+ source[i - 1] !== "<" &&
216
+ source[i + 2] !== "<") {
217
+ const opener = HEREDOC_START.exec(source.slice(i, i + 80));
218
+ if (opener) {
219
+ pendingHeredoc = opener[1] ?? opener[2] ?? opener[3] ?? null;
220
+ i += opener[0].length;
221
+ continue;
222
+ }
223
+ }
224
+ if (dialect === "shell" && ch === "\\") {
225
+ afterEscape = i + 2;
226
+ i += 2;
227
+ }
228
+ else if (dialect === "shell" && ch === "'") {
229
+ i = skipShellSingleQuoted(source, i);
230
+ }
231
+ else if (dialect === "shell" && ch === '"') {
232
+ i = skipShellDoubleQuoted(source, i);
233
+ }
234
+ else if (dialect === "hcl" && ch === '"') {
235
+ i = skipHclString(source, i);
236
+ }
237
+ else {
238
+ i++;
239
+ }
240
+ }
241
+ return fragments;
242
+ }
243
+ //# sourceMappingURL=scriptComments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptComments.js","sourceRoot":"","sources":["../../src/repo-check/scriptComments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAiBH,MAAM,KAAK,GAAwC;IACjD,KAAK,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE;IACzD,GAAG,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE;CACxD,CAAC;AAEF,SAAS,qBAAqB,CAAC,GAAW,EAAE,CAAS;IACnD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GA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AC,KAAK,GAAG;YACrB,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EACrB,CAAC;YACD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC3D,IAAI,MAAM,EAAE,CAAC;gBACX,cAAc,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;gBAC7D,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBACtB,SAAS;YACX,CAAC;QACH,CAAC;QAED,IAAI,OAAO,KAAK,OAAO,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YACvC,WAAW,GAAG,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC,IAAI,CAAC,CAAC;QACT,CAAC;aAAM,IAAI,OAAO,KAAK,OAAO,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YAC7C,CAAC,GAAG,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,KAAK,OAAO,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YAC7C,CAAC,GAAG,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YAC3C,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,CAAC,EAAE,CAAC;QACN,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -14,6 +14,31 @@
14
14
  * value for the whole tree.
15
15
  */
16
16
  import { type Server } from "node:http";
17
+ /** Vite's own default output directory for content-hashed files. */
18
+ export declare const DEFAULT_ASSET_PREFIX = "/assets/";
19
+ /**
20
+ * THE Cache-Control policy of a served SPA (AK-18, AK-59) — the one place it is written.
21
+ * `createSpaServer`, the `spa-server` bin and `spaCachePolicy` (the Fastify plugin) all
22
+ * answer through it: a path under `assetPrefix` (content-hashed, so a new build never
23
+ * overwrites it) is immutable for a year; everything else — `index.html` and every
24
+ * SPA-fallback route — is `no-cache`, so a deploy is never hidden behind a stale shell.
25
+ */
26
+ export declare function spaCacheControl(pathname: string, assetPrefix?: string): string;
27
+ export interface SpaCachePolicyOptions {
28
+ /** See `SpaServerOptions.assetPrefix`. Default "/assets/". */
29
+ assetPrefix?: string;
30
+ }
31
+ /**
32
+ * The same policy for a Fastify app that serves its SPA itself (e.g. with
33
+ * `@fastify/static`): `app.register(spaCachePolicy, { assetPrefix })` stamps
34
+ * `spaCacheControl` on every successful (status < 400) response of the routes in the
35
+ * scope it is registered in, unless the route set its own Cache-Control. The hook covers the
36
+ * scope the plugin is registered in and its children, never the parent: register it
37
+ * inside a scope that holds only the SPA routes (`app.register(async (spa) => {
38
+ * await spa.register(spaCachePolicy); ...static routes... })`) so the app's API routes
39
+ * keep their own headers.
40
+ */
41
+ export declare const spaCachePolicy: import("fastify").FastifyPluginCallback<SpaCachePolicyOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
17
42
  export interface SpaServerOptions {
18
43
  /** Directory containing the built SPA (e.g. Vite's "dist"). */
19
44
  dir: string;
@@ -14,18 +14,51 @@
14
14
  * value for the whole tree.
15
15
  */
16
16
  import { createServer } from "node:http";
17
+ import fp from "fastify-plugin";
17
18
  import sirv from "sirv";
19
+ /** Vite's own default output directory for content-hashed files. */
20
+ export const DEFAULT_ASSET_PREFIX = "/assets/";
21
+ /**
22
+ * THE Cache-Control policy of a served SPA (AK-18, AK-59) — the one place it is written.
23
+ * `createSpaServer`, the `spa-server` bin and `spaCachePolicy` (the Fastify plugin) all
24
+ * answer through it: a path under `assetPrefix` (content-hashed, so a new build never
25
+ * overwrites it) is immutable for a year; everything else — `index.html` and every
26
+ * SPA-fallback route — is `no-cache`, so a deploy is never hidden behind a stale shell.
27
+ */
28
+ export function spaCacheControl(pathname, assetPrefix = DEFAULT_ASSET_PREFIX) {
29
+ return pathname.startsWith(assetPrefix)
30
+ ? "public, max-age=31536000, immutable"
31
+ : "no-cache";
32
+ }
33
+ /**
34
+ * The same policy for a Fastify app that serves its SPA itself (e.g. with
35
+ * `@fastify/static`): `app.register(spaCachePolicy, { assetPrefix })` stamps
36
+ * `spaCacheControl` on every successful (status < 400) response of the routes in the
37
+ * scope it is registered in, unless the route set its own Cache-Control. The hook covers the
38
+ * scope the plugin is registered in and its children, never the parent: register it
39
+ * inside a scope that holds only the SPA routes (`app.register(async (spa) => {
40
+ * await spa.register(spaCachePolicy); ...static routes... })`) so the app's API routes
41
+ * keep their own headers.
42
+ */
43
+ export const spaCachePolicy = fp(async (app, options) => {
44
+ app.addHook("onSend", async (request, reply, payload) => {
45
+ if (reply.statusCode < 400 && !reply.hasHeader("cache-control")) {
46
+ const pathname = request.url.split("?")[0] ?? request.url;
47
+ reply.header("cache-control", spaCacheControl(pathname, options.assetPrefix));
48
+ }
49
+ return payload;
50
+ });
51
+ }, { name: "@flytedesk/app-kit/spa-cache-policy", fastify: "4.x || 5.x" });
18
52
  /** Builds the request handler — everything BUT actually binding a port, so a consumer
19
53
  * that already owns an HTTP server (or wants to compose this behind its own routing)
20
54
  * can still get the same Cache-Control behaviour. `serveSpa` (below) is the one-call
21
55
  * version for a consumer that just wants a running server. */
22
56
  export function createSpaServer(options) {
23
- const assetPrefix = options.assetPrefix ?? "/assets/";
24
57
  const serve = sirv(options.dir, {
25
58
  single: true,
26
59
  etag: true,
27
60
  setHeaders(res, pathname) {
28
- res.setHeader("Cache-Control", pathname.startsWith(assetPrefix) ? "public, max-age=31536000, immutable" : "no-cache");
61
+ res.setHeader("Cache-Control", spaCacheControl(pathname, options.assetPrefix));
29
62
  },
30
63
  });
31
64
  return createServer((req, res) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/spa-server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AACjG,OAAO,IAAI,MAAM,MAAM,CAAC;AAiBxB;;;+DAG+D;AAC/D,MAAM,UAAU,eAAe,CAAC,OAAyB;IACvD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,UAAU,CAAC;IACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC9B,MAAM,EAAE,IAAI;QACZ,IAAI,EAAE,IAAI;QACV,UAAU,CAAC,GAAG,EAAE,QAAQ;YACtB,GAAG,CAAC,SAAS,CACX,eAAe,EACf,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,UAAU,CACtF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IACH,OAAO,YAAY,CAAC,CAAC,GAAoB,EAAE,GAAmB,EAAE,EAAE;QAChE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YACnB,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAgBD;;;oBAGoB;AACpB,MAAM,UAAU,QAAQ,CAAC,OAAwB;IAC/C,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;IACvC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO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AO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flytedesk/app-kit",
3
- "version": "11.2.0",
3
+ "version": "11.4.0",
4
4
  "description": "Shared platform kit for flytedesk apps: flytedesk-id auth (BFF/OIDC client) and a Postgres-native trace/audit layer.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -32,13 +32,19 @@
32
32
  "profile-sync": "./dist/cli/profile-sync.js",
33
33
  "flags-sync": "./dist/cli/flags-sync.js",
34
34
  "spa-server": "./dist/spa-server/cli.js",
35
- "app-kit-chat-mcp": "./dist/chat/mcp/entry.js"
35
+ "app-kit-chat-mcp": "./dist/chat/mcp/entry.js",
36
+ "app-kit-repo-check": "./dist/repo-check/cli.js",
37
+ "auth-sync": "./dist/cli/auth-sync.js"
36
38
  },
37
39
  "exports": {
38
40
  "./auth": {
39
41
  "types": "./dist/auth/index.d.ts",
40
42
  "import": "./dist/auth/index.js"
41
43
  },
44
+ "./auth/prisma": {
45
+ "types": "./dist/auth/prisma/index.d.ts",
46
+ "import": "./dist/auth/prisma/index.js"
47
+ },
42
48
  "./auth/plugin": {
43
49
  "types": "./dist/auth/plugin.d.ts",
44
50
  "import": "./dist/auth/plugin.js"
@@ -67,6 +73,10 @@
67
73
  "types": "./dist/bigquery/index.d.ts",
68
74
  "import": "./dist/bigquery/index.js"
69
75
  },
76
+ "./csv": {
77
+ "types": "./dist/csv/index.d.ts",
78
+ "import": "./dist/csv/index.js"
79
+ },
70
80
  "./rate-limit": {
71
81
  "types": "./dist/rate-limit/index.d.ts",
72
82
  "import": "./dist/rate-limit/index.js"
@@ -136,6 +146,7 @@
136
146
  "@changesets/cli": "^3.0.1",
137
147
  "@google-cloud/bigquery": "^9.1.0",
138
148
  "@playwright/test": "^1.63.0",
149
+ "@prisma/adapter-pg": "^7.10.1",
139
150
  "@prisma/client": "^7.10.0",
140
151
  "@testcontainers/mysql": "^12.2.1",
141
152
  "@testcontainers/postgresql": "^12.1.0",
@@ -157,6 +168,7 @@
157
168
  "mysql2": "^3.24.6",
158
169
  "pg": "^8.23.0",
159
170
  "prettier": "^3.9.6",
171
+ "prisma": "^7.10.1",
160
172
  "publint": "^0.3.24",
161
173
  "react": "^19.3.0",
162
174
  "react-dom": "^19.3.0",
@@ -0,0 +1,4 @@
1
+ {
2
+ "fragmentVersion": "1.0.0",
3
+ "minCliVersion": "1.0.0"
4
+ }
@@ -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
  ]