@flytedesk/app-kit 0.7.1 → 1.0.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 (37) hide show
  1. package/dist/auth/client/httpClient.d.ts +4 -2
  2. package/dist/auth/client/httpClient.js +20 -4
  3. package/dist/auth/client/httpClient.js.map +1 -1
  4. package/dist/auth/client/index.d.ts +4 -2
  5. package/dist/auth/client/index.js +3 -1
  6. package/dist/auth/client/index.js.map +1 -1
  7. package/dist/auth/client/silentAuth.d.ts +17 -0
  8. package/dist/auth/client/silentAuth.js +106 -0
  9. package/dist/auth/client/silentAuth.js.map +1 -0
  10. package/dist/auth/client/useAuthSession.d.ts +41 -14
  11. package/dist/auth/client/useAuthSession.js +56 -40
  12. package/dist/auth/client/useAuthSession.js.map +1 -1
  13. package/dist/auth/errors.d.ts +12 -0
  14. package/dist/auth/errors.js +15 -0
  15. package/dist/auth/errors.js.map +1 -1
  16. package/dist/auth/index.d.ts +22 -6
  17. package/dist/auth/index.js +20 -4
  18. package/dist/auth/index.js.map +1 -1
  19. package/dist/auth/oidc-client.d.ts +29 -0
  20. package/dist/auth/oidc-client.js +50 -11
  21. package/dist/auth/oidc-client.js.map +1 -1
  22. package/dist/auth/plugin.js +194 -62
  23. package/dist/auth/plugin.js.map +1 -1
  24. package/dist/auth/shared-types.d.ts +57 -1
  25. package/dist/auth/shared-types.js +51 -1
  26. package/dist/auth/shared-types.js.map +1 -1
  27. package/dist/auth/testing/fake-idp.d.ts +12 -0
  28. package/dist/auth/testing/fake-idp.js +43 -0
  29. package/dist/auth/testing/fake-idp.js.map +1 -1
  30. package/dist/auth/types.d.ts +90 -2
  31. package/dist/spa-server/cli.d.ts +10 -0
  32. package/dist/spa-server/cli.js +60 -0
  33. package/dist/spa-server/cli.js.map +1 -0
  34. package/dist/spa-server/index.d.ts +53 -0
  35. package/dist/spa-server/index.js +50 -0
  36. package/dist/spa-server/index.js.map +1 -0
  37. package/package.json +14 -3
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A small, dependency-light static file server for a built single-page app — AK-18.
3
+ * Generalizes media-planner's `apps/web/server.mjs` (the one that actually has the
4
+ * fix: hashed assets served immutable with a year-long max-age, `index.html` and every
5
+ * SPA-fallback route served `no-cache`) so every `@flytedesk/app-kit` consumer's web
6
+ * Docker image runs THIS, instead of each one hand-rolling — or, worse, silently
7
+ * dropping — the same ~25 lines. sms-app's own `apps/web/server.mjs` is exactly that:
8
+ * a copy created without the Cache-Control fix, which is the real stale-bundle bug
9
+ * media-planner's version exists to prevent (a user saw a broken login button keep
10
+ * loading a stale bundle across a same-day deploy until a hard refresh).
11
+ *
12
+ * Uses `sirv` (the library, not `sirv-cli`) for the same reason media-planner's version
13
+ * does: `sirv-cli`'s flags can't express a DIFFERENT Cache-Control per path, only one
14
+ * value for the whole tree.
15
+ */
16
+ import { type Server } from "node:http";
17
+ export interface SpaServerOptions {
18
+ /** Directory containing the built SPA (e.g. Vite's "dist"). */
19
+ dir: string;
20
+ /** Path prefix under which Vite (or an equivalent bundler) content-hashes every
21
+ * filename — those never need revalidating, since a new build produces new
22
+ * filenames instead of overwriting these. Default "/assets/" (Vite's own default
23
+ * output directory). Everything else — `index.html`, and every SPA-fallback route
24
+ * that resolves to it — is served `no-cache`: its own filename never changes
25
+ * between deploys, so without this, browsers' heuristic caching can keep serving a
26
+ * stale HTML shell (and the old JS bundle it references) long after a new deploy
27
+ * has shipped. This is not a hypothetical: it is the exact bug media-planner hit in
28
+ * production, which is why this rule exists at all. */
29
+ assetPrefix?: string;
30
+ }
31
+ /** Builds the request handler — everything BUT actually binding a port, so a consumer
32
+ * that already owns an HTTP server (or wants to compose this behind its own routing)
33
+ * can still get the same Cache-Control behaviour. `serveSpa` (below) is the one-call
34
+ * version for a consumer that just wants a running server. */
35
+ export declare function createSpaServer(options: SpaServerOptions): Server;
36
+ export interface ServeSpaOptions extends SpaServerOptions {
37
+ /** Default 8080 (Cloud Run's own default, and every @flytedesk app's web image's
38
+ * current EXPOSE). */
39
+ port?: number;
40
+ /** Default "0.0.0.0" — every @flytedesk app's web image runs this inside a
41
+ * container, where the request arrives on the container's external interface, not
42
+ * loopback. */
43
+ host?: string;
44
+ /** Called once the server is actually listening, with the resolved port — e.g. to
45
+ * log it. Default: logs "web listening on :{port}" to stdout, matching what every
46
+ * @flytedesk app's web image already logs today. */
47
+ onListening?: (port: number) => void;
48
+ }
49
+ /** The one-call version: builds the server (see createSpaServer) and starts it
50
+ * listening. An app's web Docker image's ENTIRE runtime CMD is calling this (or the
51
+ * CLI wrapper, ./cli.js) — no per-app server.mjs to keep in sync with the Cache-Control
52
+ * fix any more. */
53
+ export declare function serveSpa(options: ServeSpaOptions): Server;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * A small, dependency-light static file server for a built single-page app — AK-18.
3
+ * Generalizes media-planner's `apps/web/server.mjs` (the one that actually has the
4
+ * fix: hashed assets served immutable with a year-long max-age, `index.html` and every
5
+ * SPA-fallback route served `no-cache`) so every `@flytedesk/app-kit` consumer's web
6
+ * Docker image runs THIS, instead of each one hand-rolling — or, worse, silently
7
+ * dropping — the same ~25 lines. sms-app's own `apps/web/server.mjs` is exactly that:
8
+ * a copy created without the Cache-Control fix, which is the real stale-bundle bug
9
+ * media-planner's version exists to prevent (a user saw a broken login button keep
10
+ * loading a stale bundle across a same-day deploy until a hard refresh).
11
+ *
12
+ * Uses `sirv` (the library, not `sirv-cli`) for the same reason media-planner's version
13
+ * does: `sirv-cli`'s flags can't express a DIFFERENT Cache-Control per path, only one
14
+ * value for the whole tree.
15
+ */
16
+ import { createServer } from "node:http";
17
+ import sirv from "sirv";
18
+ /** Builds the request handler — everything BUT actually binding a port, so a consumer
19
+ * that already owns an HTTP server (or wants to compose this behind its own routing)
20
+ * can still get the same Cache-Control behaviour. `serveSpa` (below) is the one-call
21
+ * version for a consumer that just wants a running server. */
22
+ export function createSpaServer(options) {
23
+ const assetPrefix = options.assetPrefix ?? "/assets/";
24
+ const serve = sirv(options.dir, {
25
+ single: true,
26
+ etag: true,
27
+ setHeaders(res, pathname) {
28
+ res.setHeader("Cache-Control", pathname.startsWith(assetPrefix) ? "public, max-age=31536000, immutable" : "no-cache");
29
+ },
30
+ });
31
+ return createServer((req, res) => {
32
+ serve(req, res, () => {
33
+ res.statusCode = 404;
34
+ res.end("Not found");
35
+ });
36
+ });
37
+ }
38
+ /** The one-call version: builds the server (see createSpaServer) and starts it
39
+ * listening. An app's web Docker image's ENTIRE runtime CMD is calling this (or the
40
+ * CLI wrapper, ./cli.js) — no per-app server.mjs to keep in sync with the Cache-Control
41
+ * fix any more. */
42
+ export function serveSpa(options) {
43
+ const server = createSpaServer(options);
44
+ const port = options.port ?? 8080;
45
+ const host = options.host ?? "0.0.0.0";
46
+ const onListening = options.onListening ?? ((p) => console.log(`web listening on :${p}`));
47
+ server.listen(port, host, () => onListening(port));
48
+ return server;
49
+ }
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,CAAC,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC;IAClG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flytedesk/app-kit",
3
- "version": "0.7.1",
3
+ "version": "1.0.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",
@@ -30,13 +30,18 @@
30
30
  "bin": {
31
31
  "trace-sync": "./dist/cli/trace-sync.js",
32
32
  "profile-sync": "./dist/cli/profile-sync.js",
33
- "flags-sync": "./dist/cli/flags-sync.js"
33
+ "flags-sync": "./dist/cli/flags-sync.js",
34
+ "spa-server": "./dist/spa-server/cli.js"
34
35
  },
35
36
  "exports": {
36
37
  "./auth": {
37
38
  "types": "./dist/auth/index.d.ts",
38
39
  "import": "./dist/auth/index.js"
39
40
  },
41
+ "./auth/plugin": {
42
+ "types": "./dist/auth/plugin.d.ts",
43
+ "import": "./dist/auth/plugin.js"
44
+ },
40
45
  "./auth/testing": {
41
46
  "types": "./dist/auth/testing/index.d.ts",
42
47
  "import": "./dist/auth/testing/index.js"
@@ -68,6 +73,10 @@
68
73
  "./chat": {
69
74
  "types": "./dist/chat/index.d.ts",
70
75
  "import": "./dist/chat/index.js"
76
+ },
77
+ "./spa-server": {
78
+ "types": "./dist/spa-server/index.d.ts",
79
+ "import": "./dist/spa-server/index.js"
71
80
  }
72
81
  },
73
82
  "scripts": {
@@ -131,12 +140,14 @@
131
140
  "testcontainers": "^12.1.0",
132
141
  "typescript": "^7.0.2",
133
142
  "typescript-eslint": "^8.69.0",
143
+ "undici": "^8.11.2",
134
144
  "vitest": "^4.1.11"
135
145
  },
136
146
  "dependencies": {
137
147
  "@fastify/cookie": "^11.0.1",
138
148
  "cross-spawn": "^7.0.6",
139
149
  "fastify-plugin": "^6.0.0",
140
- "jose": "^6.2.10"
150
+ "jose": "^6.2.10",
151
+ "sirv": "^3.0.2"
141
152
  }
142
153
  }