@pikku/cli 0.12.45 → 0.12.47

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/console-app/assets/index-Cb-SEeMM.js +254 -0
  2. package/console-app/index.html +1 -1
  3. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  4. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
  5. package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
  6. package/dist/.pikku/cli/pikku-cli-channel.js +1 -1
  7. package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
  8. package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
  9. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
  10. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
  11. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  12. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  13. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
  14. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  15. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  16. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  17. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  18. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  19. package/dist/.pikku/function/pikku-function-types.gen.d.ts +1 -1
  20. package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
  21. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  22. package/dist/.pikku/function/pikku-functions-meta.gen.json +124 -124
  23. package/dist/.pikku/function/pikku-functions.gen.js +1 -1
  24. package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
  25. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  26. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
  27. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  28. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  29. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
  30. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
  31. package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
  32. package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
  33. package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
  34. package/dist/.pikku/pikku-meta-service.gen.js +1 -1
  35. package/dist/.pikku/pikku-services.gen.d.ts +1 -1
  36. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  37. package/dist/.pikku/pikku-types.gen.js +1 -1
  38. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  39. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  40. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
  41. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
  42. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
  43. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
  44. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  45. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  46. package/dist/.pikku/schemas/register.gen.js +5 -5
  47. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  48. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  49. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  50. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  51. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  52. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  53. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  54. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  55. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  56. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  57. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
  58. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
  59. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  60. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  61. package/dist/bin/pikku-bin.mjs +2 -2
  62. package/dist/src/deploy/build-pipeline.js +2 -0
  63. package/dist/src/deploy/bundler/bundler.d.ts +1 -0
  64. package/dist/src/deploy/bundler/bundler.js +36 -5
  65. package/dist/src/deploy/provider-adapter.d.ts +7 -0
  66. package/dist/src/fabric/functions/validate.function.js +185 -0
  67. package/dist/src/functions/commands/tests-init.js +54 -8
  68. package/dist/src/functions/wirings/auth/pikku-command-auth.js +10 -1
  69. package/dist/src/scaffold/rpc-remote.gen.js +1 -1
  70. package/package.json +6 -6
  71. package/skills/pikku-better-auth/SKILL.md +19 -3
  72. package/console-app/assets/index-CRLT8CXr.js +0 -254
@@ -1,4 +1,6 @@
1
1
  import { join, dirname } from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+ import { rm } from 'node:fs/promises';
2
4
  import { pikkuSessionlessFunc } from '#pikku';
3
5
  import { writeFileInDir } from '../../../utils/file-writer.js';
4
6
  import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js';
@@ -24,10 +26,17 @@ export const pikkuAuth = pikkuSessionlessFunc({
24
26
  await writeFileInDir(logger, authFile, wiring);
25
27
  await writeFileInDir(logger, secretsFile, secrets);
26
28
  // Stateless split: session middleware in its own file (see serializeAuthGen).
29
+ // Skip it when the project registers its own betterAuthStatelessSession — the
30
+ // generated default-map one would run first and pre-empt the user's custom
31
+ // mapSession (pikkujs/pikku#754). Remove a stale file so it can't linger and
32
+ // double-register.
27
33
  const middlewareFile = join(dirname(authFile), 'auth-middleware.gen.ts');
28
- if (middleware) {
34
+ if (middleware && !state.auth.userStatelessSession) {
29
35
  await writeFileInDir(logger, middlewareFile, middleware);
30
36
  }
37
+ else if (existsSync(middlewareFile)) {
38
+ await rm(middlewareFile, { force: true });
39
+ }
31
40
  // Static metadata of the enabled providers/plugins for the console SSO page,
32
41
  // following the `*-meta.gen.json` convention. Read at runtime by the console
33
42
  // getAuthProviders function instead of a runtime registry.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file was generated by @pikku/cli@0.12.45
2
+ * This file was generated by @pikku/cli@0.12.47
3
3
  */
4
4
  /**
5
5
  * Auto-generated remote internal RPC queue worker and HTTP endpoint
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/cli",
3
- "version": "0.12.45",
3
+ "version": "0.12.47",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "BUSL-1.1",
6
6
  "imports": {
@@ -27,11 +27,11 @@
27
27
  "dependencies": {
28
28
  "@electric-sql/pglite": "^0.5.1",
29
29
  "@openapi-contrib/json-schema-to-openapi-schema": "^4.3.1",
30
- "@pikku/better-auth": "^0.12.9",
31
- "@pikku/core": "^0.12.35",
32
- "@pikku/deploy-cloudflare": "^0.12.3",
33
- "@pikku/fetch": "^0.12.3",
34
- "@pikku/inspector": "^0.12.23",
30
+ "@pikku/better-auth": "^0.12.10",
31
+ "@pikku/core": "^0.12.36",
32
+ "@pikku/deploy-cloudflare": "^0.12.4",
33
+ "@pikku/fetch": "^0.12.4",
34
+ "@pikku/inspector": "^0.12.24",
35
35
  "@pikku/kysely": "^0.12.16",
36
36
  "@pikku/kysely-node-sqlite": "^0.12.2",
37
37
  "@pikku/node-http-server": "^0.12.2",
@@ -46,9 +46,9 @@ yarn add @pikku/better-auth better-auth
46
46
  Better Auth owns its own HTTP surface, database tables, and session cookie. The Pikku integration is thin:
47
47
 
48
48
  1. **`pikkuBetterAuth(factory)`** — you export ONE `pikkuBetterAuth` call whose factory returns a configured `betterAuth({...})` instance. The pikku CLI inspects this export and generates everything else.
49
- 2. **Generated `auth.gen.ts`** — a catch-all `${basePath}{/*splat}` HTTP route per method (GET + POST) that forwards every request under the base path to better-auth's own internal router, plus `addHTTPMiddleware('*', [betterAuthSession({ auth })])`. The enabled providers and plugins are written to `auth/pikku-auth-meta.gen.json` (read by the console SSO page via `getAuthProviders`).
50
- 3. **Generated `auth-secrets.gen.ts`** a `wireSecret` for `BETTER_AUTH_SECRET` and for each social provider's OAuth credentials, plus a `wireVariable` for any non-secret provider config (e.g. `tenantId`).
51
- 4. **`betterAuthSession`** — middleware that reads better-auth's session on every request and populates the Pikku session object.
49
+ 2. **Generated `auth.gen.ts`** — a catch-all `${basePath}{/*splat}` HTTP route per method (GET + POST) that forwards every request under the base path to better-auth's own internal router. The enabled providers and plugins are written to `auth/pikku-auth-meta.gen.json` (read by the console SSO page via `getAuthProviders`).
50
+ 3. **Generated session middleware** — with `session.cookieCache` enabled (recommended), a separate `auth-middleware.gen.ts` adds the lean stateless `betterAuthStatelessSession()`; without it, `auth.gen.ts` adds the stateful `betterAuthSession()` that bundles the full server into every unit. See "Stateless session" below.
51
+ 4. **Generated `auth-secrets.gen.ts`** — a `wireSecret` for `BETTER_AUTH_SECRET` and for each social provider's OAuth credentials, plus a `wireVariable` for any non-secret provider config (e.g. `tenantId`).
52
52
 
53
53
  You do NOT hand-write routes, the session middleware, or the secret wiring — `pikkuBetterAuth` + the CLI generate all of it. Re-run `pikku auth` (or `pikku all`) to regenerate.
54
54
 
@@ -78,6 +78,8 @@ export const auth = pikkuBetterAuth(async ({ secrets }) => {
78
78
  // at runtime. Swap for the Kysely adapter in production (see below).
79
79
  database: memoryAdapter({ user: [], session: [], account: [], verification: [] }),
80
80
  emailAndPassword: { enabled: true },
81
+ // ALWAYS enable for deployed apps — see "Stateless session" below.
82
+ session: { cookieCache: { enabled: true } },
81
83
  socialProviders: {
82
84
  github: GITHUB_OAUTH,
83
85
  },
@@ -89,6 +91,19 @@ export const auth = pikkuBetterAuth(async ({ secrets }) => {
89
91
  - `socialProviders` keys must be string literals — the CLI reads them statically to emit a `wireSecret` per provider. Provider keys mirror better-auth's built-in ids exactly (e.g. `microsoft`, NOT `microsoft-entra-id`; `cognito`; `github`).
90
92
  - The factory runs lazily on the first auth request, so it pulls secrets/DB off the injected `services`.
91
93
  - The default `basePath` is `/api/auth`. Override it by passing `basePath` to `betterAuth`.
94
+ - **Enable `session: { cookieCache: { enabled: true } }`** so non-auth units tree-shake the better-auth server out (see below).
95
+
96
+ ## ⚠️ Stateless session — ALWAYS enable `cookieCache` for deployed apps
97
+
98
+ By default the CLI wires the **stateful** `betterAuthSession` bridge globally — it calls `services.auth()`, so EVERY unit/worker bundles the full better-auth server (~2.5MB each). On per-unit deploy targets (Fabric/Cloudflare) that bloats every bundle and the serial upload phase.
99
+
100
+ Enabling `session: { cookieCache: { enabled: true } }` makes the CLI split out a lean `betterAuthStatelessSession` (`src/scaffold/auth-middleware.gen.ts`) that verifies the signed session cookie using only `BETTER_AUTH_SECRET` — no `services.auth()`, no server bundled. Non-auth units drop from ~2.5MB to ~20KB. Only the auth unit carries the server. `pikku fabric validate` warns (`better-auth-stateless-session-disabled`) when it's off.
101
+
102
+ **Tradeoff:** server-side session revocation isn't seen until the cookie cache expires (sign-out is still immediate — it deletes the cookie).
103
+
104
+ **Do NOT also hand-write a global `addHTTPMiddleware('*', [betterAuthSession()])`** — that re-drags the stateful server into every unit and defeats the split (validate flags it as `better-auth-stateful-session-global`). The generated middleware is enough.
105
+
106
+ **Custom session fields (`role`, `locale`, …):** the generated stateless middleware uses the default map (`{ userId }` only). To use a custom map, register your own `betterAuthStatelessSession({ mapSession })` **globally** — `addHTTPMiddleware('*', [...])` or `addGlobalMiddleware([...])`. The CLI detects a global user registration and skips generating its own (pikkujs/pikku#754), so you keep cookieCache's lean bundles *and* your custom fields. A route-scoped registration (`addHTTPMiddleware('/some/path', [...])`) does not count — the generated global middleware is still emitted.
92
107
 
93
108
  ### 2. Production database adapter
94
109
 
@@ -105,6 +120,7 @@ export const auth = pikkuBetterAuth(async ({ secrets, kysely }) => {
105
120
  secret: BETTER_AUTH_SECRET,
106
121
  database: kyselyAdapter(kysely, { type: 'postgres' }),
107
122
  emailAndPassword: { enabled: true },
123
+ session: { cookieCache: { enabled: true } },
108
124
  })
109
125
  })
110
126
  ```