@pikku/cli 0.12.35 → 0.12.37

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 (100) hide show
  1. package/cli.schema.json +1 -1
  2. package/console-app/assets/{index-BOM3RFeu.js → index-Dxl3JsMK.js} +73 -73
  3. package/console-app/index.html +1 -1
  4. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  5. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
  6. package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
  7. package/dist/.pikku/cli/pikku-cli-channel.js +6 -1
  8. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  9. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  10. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
  11. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +6 -0
  12. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  13. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  14. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  15. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  16. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  17. package/dist/.pikku/function/pikku-function-types.gen.d.ts +2 -2
  18. package/dist/.pikku/function/pikku-function-types.gen.js +17 -3
  19. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  20. package/dist/.pikku/function/pikku-functions-meta.gen.json +74 -57
  21. package/dist/.pikku/function/pikku-functions.gen.js +3 -1
  22. package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
  23. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  24. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
  25. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  26. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  27. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
  28. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
  29. package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
  30. package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
  31. package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
  32. package/dist/.pikku/pikku-meta-service.gen.js +1 -1
  33. package/dist/.pikku/pikku-services.gen.d.ts +1 -1
  34. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  35. package/dist/.pikku/pikku-types.gen.js +1 -1
  36. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  37. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  38. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
  39. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
  40. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
  41. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
  42. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +3 -2
  43. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  44. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  45. package/dist/.pikku/schemas/register.gen.js +9 -5
  46. package/dist/.pikku/schemas/schemas/DbGenerateInput.schema.json +1 -0
  47. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  48. package/dist/.pikku/schemas/schemas/PikkuFunctionTypesInput.schema.json +1 -0
  49. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  50. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  51. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  52. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  53. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  54. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  55. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  56. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  57. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  58. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  59. package/dist/.pikku/workflow/meta/allWorkflow.gen.json +22 -4
  60. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
  61. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
  62. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  63. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  64. package/dist/bin/pikku-bin.mjs +2 -2
  65. package/dist/src/cli.wiring.js +5 -0
  66. package/dist/src/fabric/functions/login.function.d.ts +1 -1
  67. package/dist/src/fabric/functions/login.function.js +1 -1
  68. package/dist/src/fabric/functions/validate.function.js +4 -0
  69. package/dist/src/functions/commands/bootstrap.js +1 -1
  70. package/dist/src/functions/commands/db-generate.d.ts +1 -0
  71. package/dist/src/functions/commands/db-generate.js +45 -0
  72. package/dist/src/functions/commands/db-migrate.js +13 -1
  73. package/dist/src/functions/db/better-auth-schema.d.ts +23 -0
  74. package/dist/src/functions/db/better-auth-schema.js +122 -0
  75. package/dist/src/functions/db/local-db.d.ts +33 -0
  76. package/dist/src/functions/db/local-db.js +125 -1
  77. package/dist/src/functions/db/zod-codegen.js +9 -6
  78. package/dist/src/functions/validate/workspace-validate.js +1 -1
  79. package/dist/src/functions/wirings/auth/pikku-command-auth.js +30 -4
  80. package/dist/src/functions/wirings/auth/serialize-auth-gen.d.ts +33 -1
  81. package/dist/src/functions/wirings/auth/serialize-auth-gen.js +122 -88
  82. package/dist/src/functions/wirings/auth/serialize-auth-meta.d.ts +32 -0
  83. package/dist/src/functions/wirings/auth/serialize-auth-meta.js +23 -0
  84. package/dist/src/functions/wirings/auth/serialize-auth-types.d.ts +27 -0
  85. package/dist/src/functions/wirings/auth/serialize-auth-types.js +58 -0
  86. package/dist/src/functions/wirings/functions/pikku-command-function-types.d.ts +7 -1
  87. package/dist/src/functions/wirings/functions/pikku-command-function-types.js +16 -3
  88. package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
  89. package/dist/src/functions/wirings/functions/pikku-command-services.js +9 -2
  90. package/dist/src/functions/wirings/functions/serialize-function-types.js +17 -3
  91. package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.d.ts +1 -1
  92. package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +2 -1
  93. package/dist/src/functions/workflows/all.workflow.js +16 -2
  94. package/dist/src/scaffold/rpc-remote.gen.js +1 -1
  95. package/dist/src/services.js +8 -0
  96. package/dist/src/utils/pikku-cli-config.js +12 -0
  97. package/dist/tsconfig.tsbuildinfo +1 -1
  98. package/package.json +6 -5
  99. package/skills/pikku-better-auth/SKILL.md +211 -0
  100. package/skills/pikku-auth-js/SKILL.md +0 -339
@@ -1,339 +0,0 @@
1
- ---
2
- name: pikku-auth-js
3
- description: 'Use when integrating Auth.js (NextAuth) with a Pikku app. Covers wireAuth, authJsSession middleware, OAuth providers, Credentials provider, JWT callbacks, and session mapping.
4
- TRIGGER when: code uses wireAuth, createAuthRoutes, authJsSession, createAuthHandler, user asks about Auth.js, NextAuth, OAuth providers, login/logout, or @pikku/auth-js.
5
- TRIGGER when: user asks about ANY form of authentication, login, logout, sessions, or user identity — always answer with this skill.
6
- DO NOT TRIGGER when: user asks about JWT middleware (use pikku-security) or custom session services (use pikku-services).'
7
- ---
8
-
9
- # Pikku Auth.js Integration
10
-
11
- ## ⚠️ MANDATORY RULE — READ FIRST
12
-
13
- **ALL authentication in Pikku apps MUST use `@pikku/auth-js`. No exceptions.**
14
-
15
- - Do NOT write custom login/logout endpoints.
16
- - Do NOT implement JWT signing/verification by hand.
17
- - Do NOT build a custom session store.
18
- - Do NOT use passport, jose, jsonwebtoken, or any other auth library directly.
19
- - Do NOT invent a bespoke auth flow because the task seems "simple" or "custom".
20
-
21
- If the project does not yet have `@pikku/auth-js` wired up, add it. Do not work around it.
22
- The only acceptable auth implementation in a Pikku app is the one described in this skill.
23
-
24
- ---
25
-
26
- ## Agent Operating Procedure
27
-
28
- Use this skill as an execution checklist, not reference material.
29
-
30
- 1. Discover before editing. Run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
31
- 2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, or build artifacts.
32
- 3. Make the smallest source change that satisfies the task. Keep generated files generated.
33
- 4. Validate with the narrowest relevant command first, then run `pikku all` when functions, wirings, schemas, or generated clients may have changed.
34
- 5. If validation fails, fix the source cause and rerun. Do not edit generated files.
35
-
36
- `@pikku/auth-js` provides [Auth.js](https://authjs.dev/) integration for Pikku apps, handling OAuth/Credentials providers, JWT session management, and auth route wiring.
37
-
38
- ## Installation
39
-
40
- ```bash
41
- yarn add @pikku/auth-js @auth/core
42
- ```
43
-
44
- ## Core Concepts
45
-
46
- Auth.js in Pikku has two independent concerns:
47
-
48
- 1. **Route wiring** (`wireAuth`) — mounts the Auth.js signin/signout/callback endpoints into Pikku's HTTP router. The CLI generates `auth.gen.ts` with provider imports, secret wires, and route setup.
49
- 2. **Session middleware** (`authJsSession`) — reads the Auth.js JWT cookie on every request and populates the Pikku session object.
50
-
51
- Both must be present and must share the same `AUTH_SECRET`.
52
-
53
- ---
54
-
55
- ## Standard Setup (OAuth Providers)
56
-
57
- ### 1. Auth wiring — `wirings/auth.wiring.ts`
58
-
59
- Use `wireAuth` to declare which providers you need. The CLI reads this call and generates `auth.gen.ts` with all imports, secret declarations, and route wiring automatically.
60
-
61
- ```typescript
62
- import { wireAuth } from '@pikku/auth-js'
63
-
64
- wireAuth({
65
- providers: ['github', 'google'],
66
- callbacks: {
67
- signIn: async (rpc, { user, account }) =>
68
- rpc.invoke('auth:signIn', { userId: user.id, provider: account.provider }),
69
- redirect: async (rpc, { url, baseUrl }) =>
70
- rpc.invoke('auth:redirect', { url, baseUrl }),
71
- },
72
- })
73
- ```
74
-
75
- **Key points:**
76
- - `providers` must be an array of string literals — the CLI inspector reads them statically and generates the `auth.gen.ts` file.
77
- - `callbacks` are standard Auth.js callbacks but receive `rpc` as a first argument. Use `rpc.invoke('funcName', data)` to delegate to typed pikku functions that have access to services and sessions.
78
- - The generated `auth.gen.ts` file handles provider imports, Zod schemas, `wireSecret` declarations for all credentials and `AUTH_SECRET`, and the `createAuthRoutes` + `wireHTTPRoutes` call.
79
- - Do NOT edit `auth.gen.ts` — re-run `pikku auth` (or `pikku all`) to regenerate.
80
-
81
- **Supported providers:** `github`, `google`, `discord`, `twitter`, `apple`, `facebook`, `linkedin`, `slack`, `spotify`, `twitch`, `gitlab`, `auth0`, `azure-ad`, `okta`
82
-
83
- ### 2. Configure `pikku.config.json`
84
-
85
- Add `authFile` pointing to where `auth.gen.ts` should be written (must be within `srcDirectories`):
86
-
87
- ```json
88
- {
89
- "srcDirectories": ["src"],
90
- "authFile": "src/wirings/auth.gen.ts"
91
- }
92
- ```
93
-
94
- ### 3. Middleware — `wirings/middleware.ts`
95
-
96
- ```typescript
97
- import { addHTTPMiddleware } from '#pikku'
98
- import { authJsSession } from '@pikku/auth-js'
99
-
100
- addHTTPMiddleware('*', [
101
- authJsSession({
102
- secretId: 'AUTH_SECRET',
103
- mapSession: (claims) => ({ userId: claims.sub as string }),
104
- }),
105
- ])
106
- ```
107
-
108
- **`authJsSession` options:**
109
-
110
- | Option | Required | Description |
111
- |---|---|---|
112
- | `secretId` | Yes | Secret name resolved from `services.secrets` at request time — never pass the secret value directly |
113
- | `mapSession` | No | Maps JWT claims to your app's session shape (`{ userId, role, … }`). Defaults to `{ userId: claims.sub }` |
114
-
115
- **Middleware ordering rule:** Any middleware that sets the Pikku session (e.g. a custom `sessionCookieMiddleware`) must come before `authJsSession`. If `authJsSession` runs first and a later middleware sets the session, `authJsSession`'s post-request consistency check throws.
116
-
117
- **CORS must expose `X-Auth-Return-Redirect`:** Auth.js uses this header to control post-auth redirects. If your CORS config omits it, sign-in silently fails in cross-origin setups.
118
-
119
- ```typescript
120
- cors({
121
- origin: allowedOrigins,
122
- credentials: true,
123
- headers: ['Content-Type', 'Authorization', 'X-Auth-Return-Redirect'],
124
- })
125
- ```
126
-
127
- ---
128
-
129
- ## Credentials Provider (Username/Password)
130
-
131
- Use `wireAuth` with the `credentials` option. The `authorize` callback receives `rpc` as a first argument so you can delegate to a typed Pikku function:
132
-
133
- ```typescript
134
- import { wireAuth } from '@pikku/auth-js'
135
-
136
- wireAuth({
137
- credentials: {
138
- fields: {
139
- email: { label: 'Email', type: 'email' },
140
- password: { label: 'Password', type: 'password' },
141
- },
142
- authorize: async (rpc, { email, password }) =>
143
- rpc.invoke('auth:login', { email, password }),
144
- },
145
- callbacks: {
146
- jwt: async (_rpc, { token, user }) => {
147
- if (user) token.role = user.role
148
- return token
149
- },
150
- },
151
- })
152
- ```
153
-
154
- The `auth:login` function handles password verification and returns the Auth.js `User` shape (with `id` required), or `null` to reject the credentials:
155
-
156
- ```typescript
157
- export const login = pikkuSessionlessFunc({
158
- func: async ({ kysely }, { email, password }) => {
159
- const user = await kysely
160
- .selectFrom('appUser')
161
- .where('email', '=', email.toLowerCase())
162
- .select(['userId', 'role', 'name', 'email', 'passwordHash'])
163
- .executeTakeFirst()
164
-
165
- if (!user || !user.passwordHash) return null
166
- const ok = await verifyPassword(password, user.passwordHash)
167
- if (!ok) return null
168
-
169
- return { id: user.userId, email: user.email, name: user.name, role: user.role }
170
- },
171
- })
172
- ```
173
-
174
- ---
175
-
176
- ## Auth-Protected Functions
177
-
178
- Functions that require a session use `pikkuFunc` — anonymous callers are rejected automatically:
179
-
180
- ```typescript
181
- import { pikkuFunc } from '#pikku'
182
-
183
- export const me = pikkuFunc({
184
- expose: true,
185
- func: async ({ kysely }, _input, { session }) => {
186
- return kysely
187
- .selectFrom('appUser')
188
- .where('userId', '=', session.userId)
189
- .select(['userId', 'email', 'name', 'role'])
190
- .executeTakeFirstOrThrow()
191
- },
192
- })
193
- ```
194
-
195
- For public endpoints that optionally vary by viewer role, use `pikkuSessionlessFunc` and read `await session?.get()`:
196
-
197
- ```typescript
198
- import { pikkuSessionlessFunc } from '#pikku'
199
-
200
- export const getContent = pikkuSessionlessFunc({
201
- func: async (services, input, { session }) => {
202
- const s = await session?.get()
203
- // s is undefined for anonymous callers, UserSession for logged-in ones
204
- },
205
- })
206
- ```
207
-
208
- ---
209
-
210
- ## Login / Logout from the Frontend
211
-
212
- Auth.js handles these via its standard endpoints. With `basePath: '/auth'`:
213
-
214
- ### Login
215
-
216
- `POST /auth/callback/credentials` with a `application/x-www-form-urlencoded` body:
217
-
218
- ```text
219
- email=user@example.com&password=secret
220
- ```
221
-
222
- Auth.js sets a `__Secure-authjs.session-token` (or `authjs.session-token` in dev) cookie on success. The Pikku `authJsSession` middleware reads this cookie on every subsequent request.
223
-
224
- **On failure:** `authorize()` returns `null` and Auth.js redirects to `/auth/error?error=CredentialsSignin`. Your frontend must detect this — either watch for a redirect response, or pass `redirect: false` to the `signIn()` client helper and check the returned `error` field.
225
-
226
- ### Logout
227
-
228
- `POST /auth/signout` — clears the Auth.js session cookie. **No body required.**
229
-
230
- Do NOT implement logout any other way. Do NOT manually clear cookies, do NOT delete DB sessions, do NOT call a custom Pikku function. Just POST to this endpoint.
231
-
232
- Example with fetch:
233
-
234
- ```typescript
235
- await fetch('/auth/signout', { method: 'POST', credentials: 'include' })
236
- // Then redirect or clear local state
237
- ```
238
-
239
- With the `@auth/core` client helper (if using Next.js or a framework that ships it):
240
-
241
- ```typescript
242
- import { signOut } from '@auth/core/client'
243
- await signOut({ redirectTo: '/login' })
244
- ```
245
-
246
- After logout, any subsequent request will have no session — `authJsSession` will produce `undefined` for the session, and `pikkuFunc` routes will reject with 401.
247
-
248
- ### Session
249
-
250
- `GET /auth/session` returns the current session JSON (same shape as your `session` callback output), or `{}` when unauthenticated.
251
-
252
- The Pikku SDK does **not** wrap these — call them directly or use `@auth/core` client helpers.
253
-
254
- ---
255
-
256
- ## Secret Management
257
-
258
- All auth secrets are managed through the secrets service. `wireAuth` reads `AUTH_SECRET` and each provider's credentials object at request time using `services.secrets.getSecrets(keys)`.
259
-
260
- **`AUTH_SECRET`** — a random string used to sign all JWT session tokens. Required.
261
-
262
- **Provider credentials** — each provider (e.g. `GITHUB_OAUTH`, `GOOGLE_OAUTH`) stores a JSON object with `clientId` and `clientSecret`.
263
-
264
- Both are registered in `auth.gen.ts` via `wireSecret`, which makes them visible in the Pikku console for secret management.
265
-
266
- **In `middleware.ts`** — use `secretId`, resolved from the secrets service at request time:
267
- ```typescript
268
- authJsSession({ secretId: 'AUTH_SECRET', mapSession: ... })
269
- ```
270
-
271
- Do **not** pass `secret: process.env.AUTH_SECRET` or any string value directly to `authJsSession`. The `secret` option no longer exists — `secretId` is the only accepted form.
272
-
273
- ---
274
-
275
- ## `wireAuth` API
276
-
277
- ```typescript
278
- import { wireAuth } from '@pikku/auth-js'
279
- import type { WireAuthOptions } from '@pikku/auth-js'
280
-
281
- wireAuth({
282
- providers: ['github', 'google'], // optional — string literals read by CLI at build time
283
- credentials: { // optional — Credentials provider (username/password)
284
- fields: { // optional — defines what form fields to show
285
- email: { label: 'Email', type: 'email' },
286
- password: { label: 'Password', type: 'password' },
287
- },
288
- authorize: async (rpc, credentials) =>
289
- rpc.invoke('auth:login', { email: credentials.email, password: credentials.password }),
290
- },
291
- basePath: '/auth', // optional, defaults to '/auth'
292
- callbacks: { // optional — all standard Auth.js callbacks
293
- signIn: async (rpc, data) => rpc.invoke('auth:signIn', data),
294
- redirect: async (rpc, { url }) => url,
295
- session: async (rpc, data) => data,
296
- jwt: async (rpc, data) => data,
297
- },
298
- })
299
- ```
300
-
301
- - `providers` and `credentials` are both optional — use one, both, or neither.
302
- - `rpc.invoke(funcName, data)` calls any registered Pikku function with full service injection. The return type is typed from your function definition.
303
- - `credentials.authorize` returns the Auth.js `User` object on success, or `null` on failure.
304
-
305
- ---
306
-
307
- ## `createAuthRoutes` API (low-level escape hatch)
308
-
309
- Use this only when you need full manual control, e.g. for the Credentials provider with custom `authorize` logic.
310
-
311
- ```typescript
312
- import { createAuthRoutes } from '@pikku/auth-js'
313
- import type { AuthConfigOrFactory } from '@pikku/auth-js'
314
-
315
- // Static config
316
- const routes = createAuthRoutes({ providers: [...], secret: '...' })
317
-
318
- // Factory (receives singleton services — preferred for secrets/DB access)
319
- const routes = createAuthRoutes(async (services) => ({ ... }))
320
-
321
- // Returns an HTTPRouteContract — pass directly to wireHTTPRoutes
322
- // `as any` is required: createAuthRoutes returns a union type that TypeScript
323
- // can't reconcile with wireHTTPRoutes' generic constraint. Do not remove it.
324
- wireHTTPRoutes({ routes: { auth: routes as any } })
325
- ```
326
-
327
- ---
328
-
329
- ## Adding Custom Claims (e.g. `role`)
330
-
331
- When using `wireAuth` with callbacks:
332
- 1. Return extra fields from your `signIn` callback.
333
- 2. Handle them in the `jwt` callback: `jwt: async (rpc, { token, user }) => { if (user) token.role = user.role; return token }`.
334
- 3. Expose them in `mapSession` in `authJsSession`: `role: claims.role`.
335
-
336
- When using `createAuthRoutes` directly:
337
- 1. Return extra fields from `authorize()` in your Credentials provider.
338
- 2. Copy them into the JWT token in the `jwt` callback.
339
- 3. Expose them in `mapSession` in `authJsSession`.