kitcn 0.12.17 → 0.12.19
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.
- package/dist/aggregate/index.d.ts +1 -1
- package/dist/{api-entry-BckXqaLb.js → api-entry-BMCQSsCw.js} +6 -1
- package/dist/auth/client/index.js +82 -1
- package/dist/auth/generated/index.d.ts +1 -1
- package/dist/auth/index.d.ts +13 -13
- package/dist/auth/index.js +1 -1
- package/dist/auth/nextjs/index.d.ts +1 -1
- package/dist/auth/start/index.d.ts +7 -1
- package/dist/auth/start/index.js +37 -0
- package/dist/{auth-store-Cljlmdmi.js → auth-store-C0iMu34r.js} +53 -1
- package/dist/{backend-core-Rv9NorIW.mjs → backend-core-C0uwGXLx.mjs} +202 -167
- package/dist/{builder-CBdG5W6A.js → builder-Cb6gloDB.js} +161 -6
- package/dist/cli.mjs +1 -1
- package/dist/{context-utils-HPC5nXzx.d.ts → context-utils-BvWW0Ilq.d.ts} +8 -1
- package/dist/crpc/index.d.ts +2 -2
- package/dist/{generated-contract-disabled-Dzx2IRId.d.ts → generated-contract-disabled-UsFjh8jz.d.ts} +30 -30
- package/dist/{http-types-BS63Nsug.d.ts → http-types-BLFA9zS7.d.ts} +2 -1
- package/dist/{middleware-C2qTZ3V7.js → middleware-DkIhQXwg.js} +1 -1
- package/dist/{middleware-CU0mDiRs.d.ts → middleware-nS_qXecO.d.ts} +1 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/{procedure-caller-MWcxhQDv.js → procedure-caller-AjLfkHyF.js} +1 -1
- package/dist/{procedure-caller-C15h5Iel.d.ts → procedure-name-D-fDCBlo.d.ts} +33 -131
- package/dist/ratelimit/index.d.ts +2 -2
- package/dist/ratelimit/index.js +3 -3
- package/dist/react/index.js +7 -2
- package/dist/rsc/index.d.ts +3 -3
- package/dist/server/index.d.ts +5 -5
- package/dist/server/index.js +4 -4
- package/dist/{types-DrB2VeNb.d.ts → types-C6pQrnzD.d.ts} +1 -1
- package/dist/{types-BqUIoMfT.d.ts → types-a-RHmrDZ.d.ts} +9 -1
- package/dist/watcher.mjs +12 -9
- package/dist/{where-clause-compiler-DdjN63Io.d.ts → where-clause-compiler-CuH2JNxb.d.ts} +12 -12
- package/package.json +1 -1
- package/skills/convex/SKILL.md +8 -4
- package/skills/convex/references/features/auth-organizations.md +7 -2
- package/skills/convex/references/features/react.md +18 -3
package/skills/convex/SKILL.md
CHANGED
|
@@ -54,7 +54,7 @@ Only remember these non-parity deltas:
|
|
|
54
54
|
19. On the kitcn auth client path, use `createAuthMutations(authClient)` wrappers so logout unsubscribes auth queries before sign out. Raw Convex preset keeps a smaller plain `authClient`.
|
|
55
55
|
20. **NEVER** use `ctx.runQuery`/`ctx.runMutation`/`ctx.runAction` directly for module-to-module calls. Use `create<Module>Handler(ctx)` or `create<Module>Caller(ctx)` from `convex/functions/generated/<module>.runtime` instead.
|
|
56
56
|
21. **`create<Module>Handler(ctx)`** — default choice for queries/mutations. Bypasses input validation, middleware, output validation → zero overhead. Query/mutation ctx only. Import from `./generated/<module>.runtime`.
|
|
57
|
-
22. **`create<Module>Caller(ctx)`** — use in actions and HTTP routes (where handler is unavailable). Goes through validation + middleware. Root caller exposes query+mutation procedures. In `ActionCtx`, action procedures are under `caller.actions.*`; scheduling is under `caller.schedule.now|after|at` with `caller.schedule.cancel(id)`. If your code widened `ctx` to a union like `MutationCtx | ActionCtx`, narrow it before accessing `caller.actions.*` (for example with `requireActionCtx(ctx)`). Import from `./generated/<module>.runtime`. Each caller/handler eagerly loads every procedure in its module (no lazy loading) — split large modules to keep bundles lean.
|
|
57
|
+
22. **`create<Module>Caller(ctx)`** — use in actions and HTTP routes (where handler is unavailable). Goes through validation + middleware. Root caller exposes query+mutation procedures. In `ActionCtx`, action procedures are under `caller.actions.*`; scheduling is under `caller.schedule.now|after|at` with `caller.schedule.cancel(id)`. If your code widened `ctx` to a union like `MutationCtx | ActionCtx`, narrow it before accessing `caller.actions.*` (for example with `requireActionCtx(ctx)`). For scheduling from `GenericCtx` or `MutationCtx | ActionCtx`, use `requireSchedulerCtx(ctx)` instead of pretending the path is action-only. Import from `./generated/<module>.runtime`. Each caller/handler eagerly loads every procedure in its module (no lazy loading) — split large modules to keep bundles lean.
|
|
58
58
|
23. API types (`Api`, `ApiInputs`, `ApiOutputs`, `Select`, `Insert`, `TableName`) import from `@convex/api` — no manual `inferApiInputs<typeof api>`.
|
|
59
59
|
24. HTTP router must export as `httpRouter` (not `appRouter`) for codegen.
|
|
60
60
|
25. Server wiring imports come from `convex/functions/generated/` directory: `getAuth`, `defineAuth` from `generated/auth`; `initCRPC`, `QueryCtx`, `MutationCtx`, `OrmCtx` from `generated/server`; `create<Module>Caller`, `create<Module>Handler` from `generated/<module>.runtime`. No manual `convex/lib/orm.ts`.
|
|
@@ -226,9 +226,10 @@ Builder rules that matter:
|
|
|
226
226
|
|
|
227
227
|
1. Build `public`, `optional`, `auth`, and `private` procedure families once in `convex/lib/crpc.ts`.
|
|
228
228
|
2. `.meta(...)` is client-visible via generated API metadata. Never put secrets there.
|
|
229
|
-
3.
|
|
230
|
-
4.
|
|
231
|
-
5.
|
|
229
|
+
3. Middleware receives server-only `procedure` info. When procedures are built from your app `generated/server` helper, standard `export const` queries, mutations, and actions infer `module:function` automatically from file path + export name. Use `.name("module:function")` only to override or cover unusual export shapes.
|
|
230
|
+
4. Resolve session/user once in middleware. Do not re-fetch auth state in every procedure.
|
|
231
|
+
5. Shared `c.middleware()` chains preserve mutation writer types on mutation procedures. If the middleware itself performs writes, type it as mutation-only with `c.middleware<MutationCtx>(...)`.
|
|
232
|
+
6. Keep deeper auth/runtime edge cases in `references/setup/server.md` and `references/features/auth*.md`.
|
|
232
233
|
|
|
233
234
|
### 3) Query + Mutation Procedure Template
|
|
234
235
|
|
|
@@ -317,6 +318,9 @@ Use this map consistently:
|
|
|
317
318
|
5. `CONFLICT`: duplicate or conflicting write.
|
|
318
319
|
6. `TOO_MANY_REQUESTS`: rate limit.
|
|
319
320
|
7. `INTERNAL_SERVER_ERROR`: unexpected failures only.
|
|
321
|
+
8. Add small custom `data` payloads on `CRPCError` when the client needs
|
|
322
|
+
domain metadata like conflicting ids. Read them on the client from
|
|
323
|
+
`error.data`.
|
|
320
324
|
|
|
321
325
|
Required tests:
|
|
322
326
|
|
|
@@ -11,7 +11,7 @@ See [Better Auth Organization Plugin](https://www.better-auth.com/docs/plugins/o
|
|
|
11
11
|
```ts
|
|
12
12
|
// convex/functions/auth.ts
|
|
13
13
|
import { organization } from "better-auth/plugins";
|
|
14
|
-
import
|
|
14
|
+
import { requireSchedulerCtx } from "kitcn/server";
|
|
15
15
|
import { defineAuth } from "./generated/auth";
|
|
16
16
|
|
|
17
17
|
export default defineAuth((ctx) => ({
|
|
@@ -28,12 +28,13 @@ export default defineAuth((ctx) => ({
|
|
|
28
28
|
invitationExpiresIn: 48 * 60 * 60, // 48 hours
|
|
29
29
|
teams: { enabled: true, maximumTeams: 10 },
|
|
30
30
|
sendInvitationEmail: async (data) => {
|
|
31
|
+
const schedulerCtx = requireSchedulerCtx(ctx);
|
|
31
32
|
const inviterName = data.inviter.user.name || "Team Admin";
|
|
32
33
|
const organizationName = data.organization.name;
|
|
33
34
|
const roleSuffix = data.role ? ` as ${data.role}` : "";
|
|
34
35
|
const acceptUrl = `${process.env.SITE_URL!}/w/${data.organization.slug}?invite=${data.id}`;
|
|
35
36
|
|
|
36
|
-
await
|
|
37
|
+
await schedulerCtx.scheduler.runAfter(
|
|
37
38
|
0,
|
|
38
39
|
internal.plugins.email.sendTemplatedEmail,
|
|
39
40
|
{
|
|
@@ -51,6 +52,10 @@ export default defineAuth((ctx) => ({
|
|
|
51
52
|
}));
|
|
52
53
|
```
|
|
53
54
|
|
|
55
|
+
`sendInvitationEmail` can run from mutation-driven auth flows. Use
|
|
56
|
+
`requireSchedulerCtx(ctx)` when you need scheduling. Do not narrow to
|
|
57
|
+
`ActionCtx` unless the callback truly runs only inside an action.
|
|
58
|
+
|
|
54
59
|
## Client Config
|
|
55
60
|
|
|
56
61
|
```ts
|
|
@@ -418,11 +418,21 @@ Each page maintains its own WebSocket subscription. Auto-recovers on `InvalidCur
|
|
|
418
418
|
|
|
419
419
|
### Server Errors
|
|
420
420
|
|
|
421
|
-
`CRPCError` thrown server-side → arrives as `ConvexError` on client. Access
|
|
421
|
+
`CRPCError` thrown server-side → arrives as `ConvexError` on client. Access
|
|
422
|
+
the built-in fields and any custom payload via `error.data`:
|
|
422
423
|
|
|
423
424
|
```ts
|
|
424
|
-
// Server:
|
|
425
|
+
// Server:
|
|
426
|
+
throw new CRPCError({
|
|
427
|
+
code: 'CONFLICT',
|
|
428
|
+
message: 'Domain already exists',
|
|
429
|
+
data: { existingSiteId: 'site_123' },
|
|
430
|
+
});
|
|
431
|
+
|
|
425
432
|
// Client:
|
|
433
|
+
error.data?.message; // 'Domain already exists'
|
|
434
|
+
error.data?.existingSiteId; // 'site_123'
|
|
435
|
+
|
|
426
436
|
const { error, isError } = useQuery(crpc.posts.get.queryOptions({ id }));
|
|
427
437
|
if (isError) toast.error(error.data?.message ?? 'Something went wrong');
|
|
428
438
|
|
|
@@ -430,7 +440,12 @@ if (isError) toast.error(error.data?.message ?? 'Something went wrong');
|
|
|
430
440
|
crpc.posts.create.mutationOptions({ onError: (error) => toast.error(error.data?.message ?? 'Failed') });
|
|
431
441
|
|
|
432
442
|
// Try/catch:
|
|
433
|
-
const error = err as Error & {
|
|
443
|
+
const error = err as Error & {
|
|
444
|
+
data?: {
|
|
445
|
+
message?: string;
|
|
446
|
+
existingSiteId?: string;
|
|
447
|
+
};
|
|
448
|
+
};
|
|
434
449
|
```
|
|
435
450
|
|
|
436
451
|
### Client Errors
|