wcz-layout 10.1.2 → 10.1.7
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/{AggregatedCell-C7nAQyMO.mjs → AggregatedCell-CqGptV6i.mjs} +199 -150
- package/dist/AggregatedCell-CqGptV6i.mjs.map +1 -0
- package/dist/Approval-DoD-GRRH.mjs.map +1 -1
- package/dist/DialogsContext-DLqA8RJ_.mjs.map +1 -1
- package/dist/Email-BzQQkbe9.mjs.map +1 -1
- package/dist/FileMeta-DDqUju1Y.mjs.map +1 -1
- package/dist/{LayoutTable-DX9IaO8V.d.mts → LayoutTable-CRo43iWr.d.mts} +7 -3
- package/dist/{RouterListItemButton-ULMlaQh6.mjs → RouterListItemButton-ke6iPKkL.mjs} +9 -9
- package/dist/RouterListItemButton-ke6iPKkL.mjs.map +1 -0
- package/dist/{approval-DiNOXd4B.mjs → approval-L09uPzTU.mjs} +2 -2
- package/dist/approval-L09uPzTU.mjs.map +1 -0
- package/dist/auth.d.mts +1 -0
- package/dist/auth.mjs +15 -12
- package/dist/auth.mjs.map +1 -1
- package/dist/components.d.mts +1 -1
- package/dist/components.mjs +594 -361
- package/dist/components.mjs.map +1 -1
- package/dist/{createApi-DGJJ4I_R.mjs → createApi-BhNkG4jz.mjs} +3 -3
- package/dist/createApi-BhNkG4jz.mjs.map +1 -0
- package/dist/data/client.mjs +3 -3
- package/dist/data/client.mjs.map +1 -1
- package/dist/data/server.mjs +4 -4
- package/dist/data/server.mjs.map +1 -1
- package/dist/{file-C14fhUeg.mjs → file-Chlljz3o.mjs} +4 -4
- package/dist/file-Chlljz3o.mjs.map +1 -0
- package/dist/{file-C5BOj1q8.mjs → file-Dl8JCcqy.mjs} +4 -4
- package/dist/file-Dl8JCcqy.mjs.map +1 -0
- package/dist/hooks.d.mts +2 -1
- package/dist/hooks.mjs +541 -591
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +438 -428
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.mjs +2 -2
- package/dist/middleware.mjs.map +1 -1
- package/dist/models.mjs.map +1 -1
- package/dist/{peoplesoft-BkJMCcHb.mjs → peoplesoft-BhintHQz.mjs} +3 -3
- package/dist/peoplesoft-BhintHQz.mjs.map +1 -0
- package/dist/{providers-DrairEO2.mjs → providers-BvuZWkpD.mjs} +2 -2
- package/dist/providers-BvuZWkpD.mjs.map +1 -0
- package/dist/{tokens-BLRreL1j.mjs → tokens-XuFhVbh5.mjs} +9 -6
- package/dist/tokens-XuFhVbh5.mjs.map +1 -0
- package/dist/{utils-BUpDoqme.mjs → utils-CaeVFWF-.mjs} +18 -7
- package/dist/utils-CaeVFWF-.mjs.map +1 -0
- package/dist/utils.mjs +1 -1
- package/dist/vite.mjs +11 -0
- package/dist/vite.mjs.map +1 -1
- package/package.json +131 -130
- package/skills/client-db/SKILL.md +136 -136
- package/skills/db-schema/SKILL.md +98 -98
- package/skills/dialogs/SKILL.md +74 -74
- package/skills/forms/SKILL.md +122 -122
- package/skills/general/SKILL.md +127 -127
- package/skills/general/references/exports.md +6 -1
- package/skills/migrations/SKILL.md +57 -57
- package/skills/migrations/versions/migrate-v10-to-v11.md +2 -1
- package/skills/migrations/versions/migrate-v9-to-v10.md +582 -582
- package/skills/routing/SKILL.md +87 -87
- package/skills/server-functions/SKILL.md +95 -95
- package/skills/services/SKILL.md +34 -34
- package/skills/services/docs/email.md +32 -32
- package/skills/services/docs/file.md +108 -108
- package/skills/services/docs/peoplesoft.md +114 -114
- package/skills/start/SKILL.md +52 -52
- package/skills/start/steps/01-git-setup.md +10 -10
- package/skills/start/steps/02-project-name-setup.md +19 -19
- package/skills/start/steps/03-apm-setup.md +97 -208
- package/skills/start/steps/04-wicop-setup.md +105 -105
- package/skills/start/steps/05-database-setup.md +52 -52
- package/skills/start/steps/06-entra-setup.md +96 -96
- package/skills/start/steps/07-vault-setup.md +115 -115
- package/skills/start/steps/08-generate-favicon.md +8 -8
- package/skills/start/steps/09-gitlab-ci.md +25 -25
- package/skills/start/steps/10-commit.md +15 -15
- package/skills/table/SKILL.md +266 -264
- package/dist/AggregatedCell-C7nAQyMO.mjs.map +0 -1
- package/dist/RouterListItemButton-ULMlaQh6.mjs.map +0 -1
- package/dist/approval-DiNOXd4B.mjs.map +0 -1
- package/dist/createApi-DGJJ4I_R.mjs.map +0 -1
- package/dist/file-C14fhUeg.mjs.map +0 -1
- package/dist/file-C5BOj1q8.mjs.map +0 -1
- package/dist/peoplesoft-BkJMCcHb.mjs.map +0 -1
- package/dist/providers-DrairEO2.mjs.map +0 -1
- package/dist/tokens-BLRreL1j.mjs.map +0 -1
- package/dist/utils-BUpDoqme.mjs.map +0 -1
package/skills/routing/SKILL.md
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: routing
|
|
3
|
-
description: "Use when adding or changing a page, route file, navigation entry, search params, or route-level access control. Covers createFileRoute, beforeLoad requireAuth, loader preloads, validateSearch, useSearch, src/routes/ naming and colocation, __root.tsx navigation, the auth and login routes, and the RouterLink/RouterButton link components."
|
|
4
|
-
metadata:
|
|
5
|
-
type: convention
|
|
6
|
-
library: wcz-layout
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
> Mechanics (route definitions, loaders, context, guards, navigation, search params,
|
|
10
|
-
> route-tree fundamentals) are covered by TanStack's own skills. List the skills shipped by
|
|
11
|
-
> `@tanstack/router-core` and `@tanstack/react-router` and load whichever cover the task at
|
|
12
|
-
> hand. This skill adds the wcz-layout conventions.
|
|
13
|
-
|
|
14
|
-
## Rules
|
|
15
|
-
|
|
16
|
-
- Include `requireAuth(<permissionKey>)` in the route's `beforeLoad` to enforce access
|
|
17
|
-
control — pass a key defined in your app's `src/lib/auth/permissions.ts`. Use bare
|
|
18
|
-
`requireAuth()` when any signed-in user may enter, and omit it entirely only for
|
|
19
|
-
intentionally public routes.
|
|
20
|
-
- Route-level `requireAuth` only hides the UI. Every server function or server route that
|
|
21
|
-
accesses protected data still needs `authMiddleware`; see the `server-functions` skill.
|
|
22
|
-
- Use `Route.useRouteContext()` to access the authenticated user. `user` can be `null` if
|
|
23
|
-
the route doesn't include `requireAuth`.
|
|
24
|
-
- Preload the route's live queries in the loader and return the promise:
|
|
25
|
-
`loader: ({ context }) => context.dbClient.preloadLiveQuery(<x>QueryOptions)`. Detail
|
|
26
|
-
routes await it and throw `notFound()` for a missing row; see the `client-db` skill.
|
|
27
|
-
- Literal URL segments and feature folders use kebab-case. Entity feature names are plural;
|
|
28
|
-
TanStack special route tokens retain their required syntax.
|
|
29
|
-
- If a feature contains only one route, create a single file route: `src/routes/<feature>s.tsx`
|
|
30
|
-
- If a feature contains multiple related routes, create a folder: `src/routes/<feature>s/index.tsx`
|
|
31
|
-
- Colocate route-specific components/hooks inside `routes/<feature>s/-components` or `-hooks`.
|
|
32
|
-
- When a route needs its own components/hooks that no sibling route uses, wrap it in a route
|
|
33
|
-
group folder named after the route and colocate them there: `routes/<feature>s/(index)/index.tsx` with `(index)/-components` and `(index)/-hooks`.
|
|
34
|
-
- Root-level `components/` and `hooks/` are only for code shared across multiple routes.
|
|
35
|
-
- After creating a new route, add a navigation item with a unique icon from
|
|
36
|
-
`@mui/icons-material` in `src/routes/__root.tsx`.
|
|
37
|
-
- Hide a navigation entry from users who cannot open it: `hidden: !hasPermission(user, <key>)`
|
|
38
|
-
with the same key as its route's `requireAuth(<key>)`.
|
|
39
|
-
- For user-clickable in-app navigation, use the type-safe router components from
|
|
40
|
-
`wcz-layout/components` (`RouterButton`, `RouterIconButton`, `RouterLink`, `RouterFab`,
|
|
41
|
-
`RouterTab`, `RouterListItemButton`) rather than raw MUI with a manual `href` — they wrap
|
|
42
|
-
`createLink`, so `to`/`params`/`search` are type-checked.
|
|
43
|
-
|
|
44
|
-
## Examples
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
// imports
|
|
48
|
-
import AccountTree from "@mui/icons-material/AccountTree";
|
|
49
|
-
import Code from "@mui/icons-material/Code";
|
|
50
|
-
import Home from "@mui/icons-material/Home";
|
|
51
|
-
import Widgets from "@mui/icons-material/Widgets";
|
|
52
|
-
import { createFileRoute } from "@tanstack/react-router";
|
|
53
|
-
import type { Navigation } from "wcz-layout";
|
|
54
|
-
import { useDialogs, useTranslation } from "wcz-layout/hooks";
|
|
55
|
-
import { hasPermission, requireAuth } from "wcz-layout/utils";
|
|
56
|
-
|
|
57
|
-
// src/routes/<feature>s/index.tsx
|
|
58
|
-
export const Route = createFileRoute("/<feature>s/")({
|
|
59
|
-
component: RouteComponent,
|
|
60
|
-
beforeLoad: requireAuth("admin"),
|
|
61
|
-
loader: ({ context }) => context.dbClient.preloadLiveQuery(featuresQueryOptions),
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
function RouteComponent() {
|
|
65
|
-
const { t } = useTranslation();
|
|
66
|
-
const { alert, confirm } = useDialogs();
|
|
67
|
-
const { user } = Route.useRouteContext();
|
|
68
|
-
// route component code...
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// __root.tsx navigation
|
|
72
|
-
const navigation: Navigation = [
|
|
73
|
-
{ kind: "item", to: "/", title: t("Home"), icon: <Home /> },
|
|
74
|
-
{ kind: "header", title: t("Documentation") },
|
|
75
|
-
{
|
|
76
|
-
kind: "group",
|
|
77
|
-
title: t("Components"),
|
|
78
|
-
icon: <Widgets />,
|
|
79
|
-
hidden: !hasPermission(user, "admin"),
|
|
80
|
-
children: [
|
|
81
|
-
{ kind: "item", to: "/components/navigation", title: t("Navigation"), icon: <AccountTree /> },
|
|
82
|
-
{ kind: "divider" },
|
|
83
|
-
{ kind: "item", to: "/components/forms", title: t("Forms"), icon: <Code /> },
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
```
|
|
1
|
+
---
|
|
2
|
+
name: routing
|
|
3
|
+
description: "Use when adding or changing a page, route file, navigation entry, search params, or route-level access control. Covers createFileRoute, beforeLoad requireAuth, loader preloads, validateSearch, useSearch, src/routes/ naming and colocation, __root.tsx navigation, the auth and login routes, and the RouterLink/RouterButton link components."
|
|
4
|
+
metadata:
|
|
5
|
+
type: convention
|
|
6
|
+
library: wcz-layout
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
> Mechanics (route definitions, loaders, context, guards, navigation, search params,
|
|
10
|
+
> route-tree fundamentals) are covered by TanStack's own skills. List the skills shipped by
|
|
11
|
+
> `@tanstack/router-core` and `@tanstack/react-router` and load whichever cover the task at
|
|
12
|
+
> hand. This skill adds the wcz-layout conventions.
|
|
13
|
+
|
|
14
|
+
## Rules
|
|
15
|
+
|
|
16
|
+
- Include `requireAuth(<permissionKey>)` in the route's `beforeLoad` to enforce access
|
|
17
|
+
control — pass a key defined in your app's `src/lib/auth/permissions.ts`. Use bare
|
|
18
|
+
`requireAuth()` when any signed-in user may enter, and omit it entirely only for
|
|
19
|
+
intentionally public routes.
|
|
20
|
+
- Route-level `requireAuth` only hides the UI. Every server function or server route that
|
|
21
|
+
accesses protected data still needs `authMiddleware`; see the `server-functions` skill.
|
|
22
|
+
- Use `Route.useRouteContext()` to access the authenticated user. `user` can be `null` if
|
|
23
|
+
the route doesn't include `requireAuth`.
|
|
24
|
+
- Preload the route's live queries in the loader and return the promise:
|
|
25
|
+
`loader: ({ context }) => context.dbClient.preloadLiveQuery(<x>QueryOptions)`. Detail
|
|
26
|
+
routes await it and throw `notFound()` for a missing row; see the `client-db` skill.
|
|
27
|
+
- Literal URL segments and feature folders use kebab-case. Entity feature names are plural;
|
|
28
|
+
TanStack special route tokens retain their required syntax.
|
|
29
|
+
- If a feature contains only one route, create a single file route: `src/routes/<feature>s.tsx`
|
|
30
|
+
- If a feature contains multiple related routes, create a folder: `src/routes/<feature>s/index.tsx`
|
|
31
|
+
- Colocate route-specific components/hooks inside `routes/<feature>s/-components` or `-hooks`.
|
|
32
|
+
- When a route needs its own components/hooks that no sibling route uses, wrap it in a route
|
|
33
|
+
group folder named after the route and colocate them there: `routes/<feature>s/(index)/index.tsx` with `(index)/-components` and `(index)/-hooks`.
|
|
34
|
+
- Root-level `components/` and `hooks/` are only for code shared across multiple routes.
|
|
35
|
+
- After creating a new route, add a navigation item with a unique icon from
|
|
36
|
+
`@mui/icons-material` in `src/routes/__root.tsx`.
|
|
37
|
+
- Hide a navigation entry from users who cannot open it: `hidden: !hasPermission(user, <key>)`
|
|
38
|
+
with the same key as its route's `requireAuth(<key>)`.
|
|
39
|
+
- For user-clickable in-app navigation, use the type-safe router components from
|
|
40
|
+
`wcz-layout/components` (`RouterButton`, `RouterIconButton`, `RouterLink`, `RouterFab`,
|
|
41
|
+
`RouterTab`, `RouterListItemButton`) rather than raw MUI with a manual `href` — they wrap
|
|
42
|
+
`createLink`, so `to`/`params`/`search` are type-checked.
|
|
43
|
+
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
// imports
|
|
48
|
+
import AccountTree from "@mui/icons-material/AccountTree";
|
|
49
|
+
import Code from "@mui/icons-material/Code";
|
|
50
|
+
import Home from "@mui/icons-material/Home";
|
|
51
|
+
import Widgets from "@mui/icons-material/Widgets";
|
|
52
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
53
|
+
import type { Navigation } from "wcz-layout";
|
|
54
|
+
import { useDialogs, useTranslation } from "wcz-layout/hooks";
|
|
55
|
+
import { hasPermission, requireAuth } from "wcz-layout/utils";
|
|
56
|
+
|
|
57
|
+
// src/routes/<feature>s/index.tsx
|
|
58
|
+
export const Route = createFileRoute("/<feature>s/")({
|
|
59
|
+
component: RouteComponent,
|
|
60
|
+
beforeLoad: requireAuth("admin"),
|
|
61
|
+
loader: ({ context }) => context.dbClient.preloadLiveQuery(featuresQueryOptions),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function RouteComponent() {
|
|
65
|
+
const { t } = useTranslation();
|
|
66
|
+
const { alert, confirm } = useDialogs();
|
|
67
|
+
const { user } = Route.useRouteContext();
|
|
68
|
+
// route component code...
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// __root.tsx navigation
|
|
72
|
+
const navigation: Navigation = [
|
|
73
|
+
{ kind: "item", to: "/", title: t("Home"), icon: <Home /> },
|
|
74
|
+
{ kind: "header", title: t("Documentation") },
|
|
75
|
+
{
|
|
76
|
+
kind: "group",
|
|
77
|
+
title: t("Components"),
|
|
78
|
+
icon: <Widgets />,
|
|
79
|
+
hidden: !hasPermission(user, "admin"),
|
|
80
|
+
children: [
|
|
81
|
+
{ kind: "item", to: "/components/navigation", title: t("Navigation"), icon: <AccountTree /> },
|
|
82
|
+
{ kind: "divider" },
|
|
83
|
+
{ kind: "item", to: "/components/forms", title: t("Forms"), icon: <Code /> },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
```
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: server-functions
|
|
3
|
-
description: "Use when adding or changing server functions, REST/API routes, background-job endpoints, or server-side data access."
|
|
4
|
-
metadata:
|
|
5
|
-
type: convention
|
|
6
|
-
library: wcz-layout
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
> Mechanics (`createServerFn`, `.validator`, `createMiddleware`, `createHandlers`) are covered by TanStack's own skills. List the skills shipped by `@tanstack/start-client-core` and `@tanstack/react-start` and load whichever cover the task at hand. This skill adds only the wcz-layout middleware conventions on top.
|
|
10
|
-
|
|
11
|
-
## Rules
|
|
12
|
-
|
|
13
|
-
- Before generating code, clarify whether the feature should be exposed as public REST API routes or implemented as internal TanStack Start server functions (recommended), and what permission should be required for access.
|
|
14
|
-
- Include `authMiddleware` in every server function by default — server functions are callable RPC endpoints, so a route-level `requireAuth` in `beforeLoad` only hides the UI and does not protect them. Omit it only for server functions backing intentionally public routes.
|
|
15
|
-
- Order inside a middleware **array** matters, because the array runs in order and the later entry wins the merged context type. Always `databaseMiddleware()` → `authMiddleware(<permissionKey>)` → `validationMiddleware(<schema>)`. `databaseMiddleware` declares `userMiddleware` and so contributes `user: User | null`; putting it first lets `authMiddleware` narrow `context.user` to `User` for the handler. `authMiddleware` still comes before `validationMiddleware` — otherwise an unauthenticated caller gets their body parsed and gets your validation errors back.
|
|
16
|
-
- The builder itself accepts its links in any order. Write them as `.validator()` → `.middleware()` → `.handler()` to match the reference app. Middleware always runs before the handler regardless of where it appears.
|
|
17
|
-
- `validationMiddleware` is for REST API routes only. Server functions use `.validator()`.
|
|
18
|
-
- `databaseMiddleware` is **app-local**, not a wcz-layout export. Every app writes it once (see below). It owns the transaction, so never open another one in a handler.
|
|
19
|
-
- Reuse schemas from `src/lib/schemas/`.
|
|
20
|
-
- Everything under `src/server/**` is server-only, but Start's import protection only guards `**/*.server.*` filenames. Never import from `src/server/` in a component or route file. Import the server function, not what it uses.
|
|
21
|
-
- Background jobs are API routes
|
|
22
|
-
|
|
23
|
-
## Examples
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
// src/server/actions/<table>.ts
|
|
27
|
-
import { createFileRoute } from "@tanstack/react-router";
|
|
28
|
-
import { createServerFn } from "@tanstack/react-start";
|
|
29
|
-
import { eq, inArray } from "drizzle-orm";
|
|
30
|
-
import { authMiddleware, validationMiddleware } from "wcz-layout/middleware";
|
|
31
|
-
import z from "zod";
|
|
32
|
-
import { FeatureSchema } from "~/lib/schemas/feature";
|
|
33
|
-
import { featureTable } from "../db/schemas/feature";
|
|
34
|
-
import { databaseMiddleware } from "../middleware/databaseMiddleware";
|
|
35
|
-
|
|
36
|
-
export const selectFeatures = createServerFn()
|
|
37
|
-
.middleware([databaseMiddleware(), authMiddleware()])
|
|
38
|
-
.handler(({ context }) => {
|
|
39
|
-
return context.db.select().from(featureTable);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const insertFeature = createServerFn({ method: "POST" })
|
|
43
|
-
.validator(FeatureSchema)
|
|
44
|
-
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
45
|
-
.handler(async ({ data, context }) => {
|
|
46
|
-
await context.db
|
|
47
|
-
.insert(featureTable)
|
|
48
|
-
.values(data)
|
|
49
|
-
.onConflictDoNothing({ target: featureTable.id });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export const updateFeature = createServerFn({ method: "POST" })
|
|
53
|
-
.validator(FeatureSchema)
|
|
54
|
-
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
55
|
-
.handler(async ({ data, context }) => {
|
|
56
|
-
await context.db.update(featureTable).set(data).where(eq(featureTable.id, data.id));
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export const deleteFeatures = createServerFn({ method: "POST" })
|
|
60
|
-
.validator(z.array(z.uuid()))
|
|
61
|
-
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
62
|
-
.handler(async ({ data, context }) => {
|
|
63
|
-
await context.db.delete(featureTable).where(inArray(featureTable.id, data));
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// src/routes/api/<feature>s/index.ts
|
|
67
|
-
export const Route = createFileRoute("/api/features/")({
|
|
68
|
-
server: {
|
|
69
|
-
handlers: ({ createHandlers }) =>
|
|
70
|
-
createHandlers({
|
|
71
|
-
GET: {
|
|
72
|
-
middleware: [databaseMiddleware(), authMiddleware()],
|
|
73
|
-
handler: async ({ context }) => {
|
|
74
|
-
const items = await context.db.select().from(featureTable);
|
|
75
|
-
return Response.json(items);
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
POST: {
|
|
79
|
-
middleware: [
|
|
80
|
-
databaseMiddleware(),
|
|
81
|
-
authMiddleware("admin"),
|
|
82
|
-
validationMiddleware(FeatureSchema),
|
|
83
|
-
],
|
|
84
|
-
handler: async ({ context }) => {
|
|
85
|
-
const [response] = await context.db
|
|
86
|
-
.insert(featureTable)
|
|
87
|
-
.values(context.data)
|
|
88
|
-
.returning();
|
|
89
|
-
return Response.json(response, { status: 201 });
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
}),
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
```
|
|
1
|
+
---
|
|
2
|
+
name: server-functions
|
|
3
|
+
description: "Use when adding or changing server functions, REST/API routes, background-job endpoints, or server-side data access."
|
|
4
|
+
metadata:
|
|
5
|
+
type: convention
|
|
6
|
+
library: wcz-layout
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
> Mechanics (`createServerFn`, `.validator`, `createMiddleware`, `createHandlers`) are covered by TanStack's own skills. List the skills shipped by `@tanstack/start-client-core` and `@tanstack/react-start` and load whichever cover the task at hand. This skill adds only the wcz-layout middleware conventions on top.
|
|
10
|
+
|
|
11
|
+
## Rules
|
|
12
|
+
|
|
13
|
+
- Before generating code, clarify whether the feature should be exposed as public REST API routes or implemented as internal TanStack Start server functions (recommended), and what permission should be required for access.
|
|
14
|
+
- Include `authMiddleware` in every server function by default — server functions are callable RPC endpoints, so a route-level `requireAuth` in `beforeLoad` only hides the UI and does not protect them. Omit it only for server functions backing intentionally public routes.
|
|
15
|
+
- Order inside a middleware **array** matters, because the array runs in order and the later entry wins the merged context type. Always `databaseMiddleware()` → `authMiddleware(<permissionKey>)` → `validationMiddleware(<schema>)`. `databaseMiddleware` declares `userMiddleware` and so contributes `user: User | null`; putting it first lets `authMiddleware` narrow `context.user` to `User` for the handler. `authMiddleware` still comes before `validationMiddleware` — otherwise an unauthenticated caller gets their body parsed and gets your validation errors back.
|
|
16
|
+
- The builder itself accepts its links in any order. Write them as `.validator()` → `.middleware()` → `.handler()` to match the reference app. Middleware always runs before the handler regardless of where it appears.
|
|
17
|
+
- `validationMiddleware` is for REST API routes only. Server functions use `.validator()`.
|
|
18
|
+
- `databaseMiddleware` is **app-local**, not a wcz-layout export. Every app writes it once (see below). It owns the transaction, so never open another one in a handler.
|
|
19
|
+
- Reuse schemas from `src/lib/schemas/`.
|
|
20
|
+
- Everything under `src/server/**` is server-only, but Start's import protection only guards `**/*.server.*` filenames. Never import from `src/server/` in a component or route file. Import the server function, not what it uses.
|
|
21
|
+
- Background jobs are API routes with exactly `[databaseMiddleware(), authMiddleware()]` — plain `authMiddleware()`, no permission key. Cron runs in Kubernetes and authenticates via app token. This is intentional and sufficient: do not add any other extra security layer, even if any signed-in user could trigger the job.
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
// src/server/actions/<table>.ts
|
|
27
|
+
import { createFileRoute } from "@tanstack/react-router";
|
|
28
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
29
|
+
import { eq, inArray } from "drizzle-orm";
|
|
30
|
+
import { authMiddleware, validationMiddleware } from "wcz-layout/middleware";
|
|
31
|
+
import z from "zod";
|
|
32
|
+
import { FeatureSchema } from "~/lib/schemas/feature";
|
|
33
|
+
import { featureTable } from "../db/schemas/feature";
|
|
34
|
+
import { databaseMiddleware } from "../middleware/databaseMiddleware";
|
|
35
|
+
|
|
36
|
+
export const selectFeatures = createServerFn()
|
|
37
|
+
.middleware([databaseMiddleware(), authMiddleware()])
|
|
38
|
+
.handler(({ context }) => {
|
|
39
|
+
return context.db.select().from(featureTable);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const insertFeature = createServerFn({ method: "POST" })
|
|
43
|
+
.validator(FeatureSchema)
|
|
44
|
+
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
45
|
+
.handler(async ({ data, context }) => {
|
|
46
|
+
await context.db
|
|
47
|
+
.insert(featureTable)
|
|
48
|
+
.values(data)
|
|
49
|
+
.onConflictDoNothing({ target: featureTable.id });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const updateFeature = createServerFn({ method: "POST" })
|
|
53
|
+
.validator(FeatureSchema)
|
|
54
|
+
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
55
|
+
.handler(async ({ data, context }) => {
|
|
56
|
+
await context.db.update(featureTable).set(data).where(eq(featureTable.id, data.id));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const deleteFeatures = createServerFn({ method: "POST" })
|
|
60
|
+
.validator(z.array(z.uuid()))
|
|
61
|
+
.middleware([databaseMiddleware(), authMiddleware("admin")])
|
|
62
|
+
.handler(async ({ data, context }) => {
|
|
63
|
+
await context.db.delete(featureTable).where(inArray(featureTable.id, data));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/routes/api/<feature>s/index.ts
|
|
67
|
+
export const Route = createFileRoute("/api/features/")({
|
|
68
|
+
server: {
|
|
69
|
+
handlers: ({ createHandlers }) =>
|
|
70
|
+
createHandlers({
|
|
71
|
+
GET: {
|
|
72
|
+
middleware: [databaseMiddleware(), authMiddleware()],
|
|
73
|
+
handler: async ({ context }) => {
|
|
74
|
+
const items = await context.db.select().from(featureTable);
|
|
75
|
+
return Response.json(items);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
POST: {
|
|
79
|
+
middleware: [
|
|
80
|
+
databaseMiddleware(),
|
|
81
|
+
authMiddleware("admin"),
|
|
82
|
+
validationMiddleware(FeatureSchema),
|
|
83
|
+
],
|
|
84
|
+
handler: async ({ context }) => {
|
|
85
|
+
const [response] = await context.db
|
|
86
|
+
.insert(featureTable)
|
|
87
|
+
.values(context.data)
|
|
88
|
+
.returning();
|
|
89
|
+
return Response.json(response, { status: 201 });
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
```
|
package/skills/services/SKILL.md
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: services
|
|
3
|
-
description: "Use when a feature needs a built-in wcz-layout backend service: file upload, download, thumbnails; approval requests, approvers and flows; PeopleSoft employee, manager, department lookups; or sending email."
|
|
4
|
-
metadata:
|
|
5
|
-
type: integration
|
|
6
|
-
library: wcz-layout
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Info
|
|
10
|
-
|
|
11
|
-
You can read about each service in the links below. Services are categorized as either client or server exports, depending on their intended usage.
|
|
12
|
-
|
|
13
|
-
- **Client exports** — React Query option factories from `wcz-layout/data/client`.
|
|
14
|
-
- **Server exports** — Direct service operations from `wcz-layout/data/server`; import them only in server code.
|
|
15
|
-
- Invalidating mutation factories take `{ queryClient }`.
|
|
16
|
-
- Access `queryClient` with `Route.useRouteContext()` in a route file, or `useRouteContext({ from: "path" })` in a component.
|
|
17
|
-
- To read about a service, open the linked file in the **File** column directly.
|
|
18
|
-
|
|
19
|
-
## Import Paths
|
|
20
|
-
|
|
21
|
-
- Client exports: `wcz-layout/data/client`
|
|
22
|
-
- Server exports: `wcz-layout/data/server`
|
|
23
|
-
- Schemas & Models: `wcz-layout/models`
|
|
24
|
-
|
|
25
|
-
## Services
|
|
26
|
-
|
|
27
|
-
| Service | File | Summary |
|
|
28
|
-
| ---------- | ----------------------------------- | ----------------------------------------------------------------------- |
|
|
29
|
-
| file | [file.md](docs/file.md) | File metadata, thumbnails, binary download/open, upload, update, delete |
|
|
30
|
-
| approval | [approval.md](docs/approval.md) | Approval request lifecycle, approvers, flows, statuses, step results |
|
|
31
|
-
| peoplesoft | [peoplesoft.md](docs/peoplesoft.md) | Employee, manager, department, and company general manager lookups |
|
|
32
|
-
| email | [email.md](docs/email.md) | Server-only email sending with optional file attachment references |
|
|
33
|
-
|
|
34
|
-
> The attendance service is not available yet — do not generate code against it; tell the user it is coming in a future release.
|
|
1
|
+
---
|
|
2
|
+
name: services
|
|
3
|
+
description: "Use when a feature needs a built-in wcz-layout backend service: file upload, download, thumbnails; approval requests, approvers and flows; PeopleSoft employee, manager, department lookups; or sending email."
|
|
4
|
+
metadata:
|
|
5
|
+
type: integration
|
|
6
|
+
library: wcz-layout
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Info
|
|
10
|
+
|
|
11
|
+
You can read about each service in the links below. Services are categorized as either client or server exports, depending on their intended usage.
|
|
12
|
+
|
|
13
|
+
- **Client exports** — React Query option factories from `wcz-layout/data/client`.
|
|
14
|
+
- **Server exports** — Direct service operations from `wcz-layout/data/server`; import them only in server code.
|
|
15
|
+
- Invalidating mutation factories take `{ queryClient }`.
|
|
16
|
+
- Access `queryClient` with `Route.useRouteContext()` in a route file, or `useRouteContext({ from: "path" })` in a component.
|
|
17
|
+
- To read about a service, open the linked file in the **File** column directly.
|
|
18
|
+
|
|
19
|
+
## Import Paths
|
|
20
|
+
|
|
21
|
+
- Client exports: `wcz-layout/data/client`
|
|
22
|
+
- Server exports: `wcz-layout/data/server`
|
|
23
|
+
- Schemas & Models: `wcz-layout/models`
|
|
24
|
+
|
|
25
|
+
## Services
|
|
26
|
+
|
|
27
|
+
| Service | File | Summary |
|
|
28
|
+
| ---------- | ----------------------------------- | ----------------------------------------------------------------------- |
|
|
29
|
+
| file | [file.md](docs/file.md) | File metadata, thumbnails, binary download/open, upload, update, delete |
|
|
30
|
+
| approval | [approval.md](docs/approval.md) | Approval request lifecycle, approvers, flows, statuses, step results |
|
|
31
|
+
| peoplesoft | [peoplesoft.md](docs/peoplesoft.md) | Employee, manager, department, and company general manager lookups |
|
|
32
|
+
| email | [email.md](docs/email.md) | Server-only email sending with optional file attachment references |
|
|
33
|
+
|
|
34
|
+
> The attendance service is not available yet — do not generate code against it; tell the user it is coming in a future release.
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
# email
|
|
2
|
-
|
|
3
|
-
## Server
|
|
4
|
-
|
|
5
|
-
- `sendEmail`
|
|
6
|
-
|
|
7
|
-
## Schemas/Models
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
const EmailSchema = z.object({
|
|
11
|
-
subject: z.string().trim().min(1).max(60),
|
|
12
|
-
body: z.string().trim().min(1),
|
|
13
|
-
to: z.array(z.email()).min(1),
|
|
14
|
-
bcc: z.array(z.email()).optional(),
|
|
15
|
-
cc: z.array(z.email()).optional(),
|
|
16
|
-
attachments: z.array(EmailAttachmentSchema).optional(),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const EmailAttachmentSchema = z.object({
|
|
20
|
-
appName: z.string().trim().min(1).max(100),
|
|
21
|
-
subId: z.uuid(),
|
|
22
|
-
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Examples
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { sendEmail } from "wcz-layout/data/server";
|
|
29
|
-
|
|
30
|
-
// server
|
|
31
|
-
await sendEmail({ data: { subject: "Hello", body: "<p>Hi</p>", to: ["user@example.com"] } });
|
|
32
|
-
```
|
|
1
|
+
# email
|
|
2
|
+
|
|
3
|
+
## Server
|
|
4
|
+
|
|
5
|
+
- `sendEmail`
|
|
6
|
+
|
|
7
|
+
## Schemas/Models
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const EmailSchema = z.object({
|
|
11
|
+
subject: z.string().trim().min(1).max(60),
|
|
12
|
+
body: z.string().trim().min(1),
|
|
13
|
+
to: z.array(z.email()).min(1),
|
|
14
|
+
bcc: z.array(z.email()).optional(),
|
|
15
|
+
cc: z.array(z.email()).optional(),
|
|
16
|
+
attachments: z.array(EmailAttachmentSchema).optional(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const EmailAttachmentSchema = z.object({
|
|
20
|
+
appName: z.string().trim().min(1).max(100),
|
|
21
|
+
subId: z.uuid(),
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { sendEmail } from "wcz-layout/data/server";
|
|
29
|
+
|
|
30
|
+
// server
|
|
31
|
+
await sendEmail({ data: { subject: "Hello", body: "<p>Hi</p>", to: ["user@example.com"] } });
|
|
32
|
+
```
|