wcz-layout 10.1.9 → 10.2.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.
- package/dist/{Approval-DoD-GRRH.mjs → Approval-D1TfISUL.mjs} +11 -21
- package/dist/Approval-D1TfISUL.mjs.map +1 -0
- package/dist/{LayoutTable-CRo43iWr.d.mts → ChatLayout-BmLySLXy.d.mts} +11 -18
- package/dist/ChatLayout-Tpuwo8-b.mjs +1622 -0
- package/dist/ChatLayout-Tpuwo8-b.mjs.map +1 -0
- package/dist/{DialogsContext-DLqA8RJ_.mjs → DialogsContext-D23fJjYR.mjs} +2 -3
- package/dist/DialogsContext-D23fJjYR.mjs.map +1 -0
- package/dist/{Email-CKUxOURX.d.mts → Email-Dz5k0UWE.d.mts} +1 -3
- package/dist/{Email-BzQQkbe9.mjs → Email-rnz3H0x3.mjs} +3 -5
- package/dist/Email-rnz3H0x3.mjs.map +1 -0
- package/dist/{Employee-agVPiGrJ.d.mts → Employee-C8xIlBxY.d.mts} +1 -7
- package/dist/{FileMeta-Be9viU7D.d.mts → FileMeta-B39e2FLC.d.mts} +1 -3
- package/dist/{FileMeta-DDqUju1Y.mjs → FileMeta-CPBWI_jA.mjs} +2 -3
- package/dist/FileMeta-CPBWI_jA.mjs.map +1 -0
- package/dist/{QueryClientParam-JcH0mJWl.d.mts → QueryClientParam-CTV1vj76.d.mts} +1 -3
- package/dist/RouterListItemButton-CF-8w-08.mjs +62 -0
- package/dist/RouterListItemButton-CF-8w-08.mjs.map +1 -0
- package/dist/{User-D4__w1I1.d.mts → User-aJksXItw.d.mts} +1 -3
- package/dist/{approval-L09uPzTU.mjs → approval-HB2w5jzc.mjs} +4 -5
- package/dist/approval-HB2w5jzc.mjs.map +1 -0
- package/dist/auth.d.mts +0 -4
- package/dist/auth.mjs +5 -6
- package/dist/auth.mjs.map +1 -1
- package/dist/components.d.mts +63 -33
- package/dist/components.mjs +658 -748
- package/dist/components.mjs.map +1 -1
- package/dist/{createApi-BhNkG4jz.mjs → createApi-CKgFi53y.mjs} +4 -6
- package/dist/createApi-CKgFi53y.mjs.map +1 -0
- package/dist/data/client.d.mts +2 -8
- package/dist/data/client.mjs +6 -9
- package/dist/data/client.mjs.map +1 -1
- package/dist/data/server.d.mts +2 -4
- package/dist/data/server.mjs +6 -7
- package/dist/data/server.mjs.map +1 -1
- package/dist/env-BwFl7nWc.mjs +48 -0
- package/dist/env-BwFl7nWc.mjs.map +1 -0
- package/dist/{file-Chlljz3o.mjs → file-X1sK4ok6.mjs} +7 -8
- package/dist/file-X1sK4ok6.mjs.map +1 -0
- package/dist/{file-Dl8JCcqy.mjs → file-tkfsnk5F.mjs} +8 -8
- package/dist/file-tkfsnk5F.mjs.map +1 -0
- package/dist/generatedChart-k7NEdi5Z.mjs +211 -0
- package/dist/generatedChart-k7NEdi5Z.mjs.map +1 -0
- package/dist/hooks.d.mts +30 -30
- package/dist/hooks.mjs +1828 -1304
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +11 -14
- package/dist/index.mjs +1273 -1051
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.d.mts +1 -7
- package/dist/middleware.mjs +5 -8
- package/dist/middleware.mjs.map +1 -1
- package/dist/models.d.mts +4 -32
- package/dist/models.mjs +7 -11
- package/dist/models.mjs.map +1 -1
- package/dist/{peoplesoft-D6q3cYsH.d.mts → peoplesoft-C-zPdRVj.d.mts} +3 -9
- package/dist/{peoplesoft-BhintHQz.mjs → peoplesoft-RnvfLbWH.mjs} +5 -25
- package/dist/peoplesoft-RnvfLbWH.mjs.map +1 -0
- package/dist/{providers-BvuZWkpD.mjs → providers-BfFg_3eo.mjs} +5 -23
- package/dist/providers-BfFg_3eo.mjs.map +1 -0
- package/dist/{tokens-XuFhVbh5.mjs → tokens-C4SErO-K.mjs} +12 -8
- package/dist/tokens-C4SErO-K.mjs.map +1 -0
- package/dist/{utils-CaeVFWF-.mjs → utils-C2MZoH9U.mjs} +8 -39
- package/dist/utils-C2MZoH9U.mjs.map +1 -0
- package/dist/{utils-Bhi0KiBx.d.mts → utils-CNYCSgip.d.mts} +3 -5
- package/dist/utils-DnMFybj3.mjs +27 -0
- package/dist/utils-DnMFybj3.mjs.map +1 -0
- package/dist/utils.d.mts +11 -2
- package/dist/utils.mjs +3 -5
- package/dist/vite.d.mts +0 -2
- package/dist/vite.mjs +2 -4
- package/dist/vite.mjs.map +1 -1
- package/package.json +131 -131
- package/skills/ai/SKILL.md +136 -39
- package/skills/client-db/SKILL.md +104 -90
- package/skills/db-schema/SKILL.md +28 -20
- package/skills/dialogs/SKILL.md +26 -38
- package/skills/forms/SKILL.md +133 -73
- package/skills/general/SKILL.md +99 -105
- package/skills/general/references/auth.md +70 -0
- package/skills/migrations/versions/migrate-v10-to-v11.md +30 -4
- package/skills/routing/SKILL.md +60 -58
- package/skills/scanning/SKILL.md +67 -0
- package/skills/server-functions/SKILL.md +71 -26
- package/skills/services/SKILL.md +4 -4
- package/skills/services/docs/approval.md +70 -24
- package/skills/services/docs/email.md +24 -3
- package/skills/services/docs/file.md +69 -27
- package/skills/services/docs/peoplesoft.md +55 -39
- package/skills/start/steps/03-apm-setup.md +9 -9
- package/skills/table/SKILL.md +250 -267
- package/dist/AggregatedCell-oGcwbetF.mjs +0 -559
- package/dist/AggregatedCell-oGcwbetF.mjs.map +0 -1
- package/dist/Approval-DoD-GRRH.mjs.map +0 -1
- package/dist/DialogsContext-DLqA8RJ_.mjs.map +0 -1
- package/dist/Email-BzQQkbe9.mjs.map +0 -1
- package/dist/FileMeta-DDqUju1Y.mjs.map +0 -1
- package/dist/RouterListItemButton-ULMlaQh6.mjs +0 -80
- package/dist/RouterListItemButton-ULMlaQh6.mjs.map +0 -1
- package/dist/approval-L09uPzTU.mjs.map +0 -1
- package/dist/createApi-BhNkG4jz.mjs.map +0 -1
- package/dist/file-Chlljz3o.mjs.map +0 -1
- package/dist/file-Dl8JCcqy.mjs.map +0 -1
- package/dist/peoplesoft-BhintHQz.mjs.map +0 -1
- package/dist/providers-BvuZWkpD.mjs.map +0 -1
- package/dist/tokens-XuFhVbh5.mjs.map +0 -1
- package/dist/utils-CaeVFWF-.mjs.map +0 -1
- package/skills/general/references/exports.md +0 -114
package/skills/forms/SKILL.md
CHANGED
|
@@ -1,48 +1,58 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: forms
|
|
3
|
-
description:
|
|
3
|
+
description: 'Use when building or changing a form in app: create and edit pages or dialogs, fields (text, number, autocomplete, date/time, switch, checkbox, radio, slider), Zod validation and messages, default values, submit, reset and failed saves, or splitting a long form; also when a form throws "Maximum update depth exceeded".'
|
|
4
4
|
metadata:
|
|
5
5
|
type: convention
|
|
6
6
|
library: wcz-layout
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
> TanStack Form v1. `useLayoutForm` is its `useAppForm` and `withLayoutForm` its `withForm`,
|
|
13
|
-
> pre-bound to the MUI field set below.
|
|
9
|
+
TanStack Form v1 ships no agent skill. `useLayoutForm` is its `useAppForm` and
|
|
10
|
+
`withLayoutForm` its `withForm` (both `wcz-layout/hooks`), pre-bound to the MUI fields below;
|
|
11
|
+
the rest is upstream API.
|
|
14
12
|
|
|
15
13
|
## Rules
|
|
16
14
|
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
15
|
+
- A feature has one `-components/Form.tsx`, shared by create and edit: props
|
|
16
|
+
`defaultValues: <Entity>` and `onSubmit: (value: <Entity>) => Promise<void>`. It validates
|
|
17
|
+
with the entity schema (`validators: { onChange: <Entity>Schema }`) and resets once
|
|
18
|
+
`onSubmit` resolves.
|
|
19
|
+
- Fields come only from render props. `form.AppField` gives `field.TextField`, `NumberField`,
|
|
20
|
+
`Autocomplete`, `Checkbox`, `Switch`, `RadioGroup`, `Slider`, `DatePicker`, `TimePicker`,
|
|
21
|
+
`DateTimePicker`; `form.AppForm` gives `form.SubmitButton`, which submits and owns its
|
|
22
|
+
loading/busy state. It disables while submitting, not merely because values are invalid;
|
|
23
|
+
`handleSubmit()` validates. Never wire a raw MUI input to the form; a missing kind of field
|
|
24
|
+
is a custom field (last rule).
|
|
25
|
+
- Size every field for its expected content (`sx={{ width: 420 }}`); labels, helper texts and
|
|
26
|
+
the submit text go through `t`; mark required fields `required`.
|
|
27
|
+
- The page's `onSubmit` runs the optimistic action (client-db), awaits `when("settled")`, then
|
|
28
|
+
navigates. On failure it alerts and rethrows: the rejection stops the reset, so the input
|
|
29
|
+
survives a failed save.
|
|
30
|
+
The current SubmitButton also propagates that rejection from its click handler; handle
|
|
31
|
+
event-boundary reporting in the library, never hide failure by resolving the page callback.
|
|
32
|
+
- A form that stays open after a create (dialog, "add another") resets with a fresh id,
|
|
33
|
+
`formApi.reset({ ...defaultValues, id: uuidv7() })`; a reused id makes the next insert a
|
|
34
|
+
silent no-op.
|
|
35
|
+
- Standard Schema validators check but do not transform `value`; the server validator
|
|
36
|
+
normalizes simple rows. Explicitly parse at the client submit boundary when converting
|
|
37
|
+
form values or when optimistic UI depends on normalized values.
|
|
38
|
+
- When a field holds what the entity type can't, give the form its own schema (example):
|
|
39
|
+
pickers hold `Dayjs | null`; required pickers/autocompletes must allow `null` in their input
|
|
40
|
+
type but reject it in validation. Type the form
|
|
41
|
+
with `z.input` of it, map rows in (`dayjs(row.dueAt)`), and turn the value back into the
|
|
42
|
+
entity with `<Entity>Schema.parse({ ...value, dueAt: value.dueAt?.toDate() })` before the action.
|
|
43
|
+
- `Autocomplete` stores the chosen option: for a foreign key pass ids as `options` with
|
|
44
|
+
`getOptionLabel`, so the value is the id.
|
|
45
|
+
- Split a long form into `withLayoutForm({ defaultValues, render })` sections. A custom field
|
|
46
|
+
reads `useFieldContext<T>()` from `wcz-layout/hooks`.
|
|
41
47
|
|
|
42
48
|
## Examples
|
|
43
49
|
|
|
44
50
|
```tsx
|
|
45
|
-
// Form
|
|
51
|
+
// src/routes/<feature>s/-components/Form.tsx
|
|
52
|
+
import type { FC } from "react";
|
|
53
|
+
import { useLayoutForm, useTranslation } from "wcz-layout/hooks";
|
|
54
|
+
import { FeatureSchema, type Feature } from "~/lib/schemas/feature";
|
|
55
|
+
|
|
46
56
|
interface FormProps {
|
|
47
57
|
defaultValues: Feature;
|
|
48
58
|
onSubmit: (value: Feature) => Promise<void>;
|
|
@@ -68,36 +78,11 @@ export const Form: FC<FormProps> = ({ defaultValues, onSubmit }) => {
|
|
|
68
78
|
await form.handleSubmit();
|
|
69
79
|
}}
|
|
70
80
|
>
|
|
71
|
-
<form.AppField name="
|
|
72
|
-
{(field) => <field.TextField label={t("Feature.
|
|
73
|
-
</form.AppField>
|
|
74
|
-
|
|
75
|
-
<form.AppField name="property2">
|
|
76
|
-
{(field) => (
|
|
77
|
-
<field.Autocomplete
|
|
78
|
-
options={options}
|
|
79
|
-
autoHighlight
|
|
80
|
-
autoSelect
|
|
81
|
-
autoComplete
|
|
82
|
-
loading={isLoading}
|
|
83
|
-
sx={{ width: 250 }}
|
|
84
|
-
textFieldProps={{ label: t("Feature.Property2"), required: true }}
|
|
85
|
-
/>
|
|
86
|
-
)}
|
|
87
|
-
</form.AppField>
|
|
88
|
-
|
|
89
|
-
<form.AppField name="property3">
|
|
90
|
-
{(field) => (
|
|
91
|
-
<field.NumberField label={t("Feature.Property3")} required sx={{ width: 120 }} />
|
|
92
|
-
)}
|
|
93
|
-
</form.AppField>
|
|
94
|
-
|
|
95
|
-
<form.AppField name="property4">
|
|
96
|
-
{(field) => <field.Switch label={t("Feature.Property4")} />}
|
|
81
|
+
<form.AppField name="name">
|
|
82
|
+
{(field) => <field.TextField label={t("Feature.Name")} required sx={{ width: 420 }} />}
|
|
97
83
|
</form.AppField>
|
|
98
|
-
|
|
99
84
|
<form.AppForm>
|
|
100
|
-
<form.SubmitButton
|
|
85
|
+
<form.SubmitButton>{t("Submit")}</form.SubmitButton>
|
|
101
86
|
</form.AppForm>
|
|
102
87
|
</form>
|
|
103
88
|
);
|
|
@@ -105,18 +90,93 @@ export const Form: FC<FormProps> = ({ defaultValues, onSubmit }) => {
|
|
|
105
90
|
```
|
|
106
91
|
|
|
107
92
|
```tsx
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
93
|
+
// src/routes/<feature>s/create.tsx. edit.$id.tsx: the detail route's options (routing),
|
|
94
|
+
// defaultValues={data} after the RouterNotFound guard, update in onMutate, navigate to the detail
|
|
95
|
+
export const Route = createFileRoute("/features/create")({
|
|
96
|
+
component: RouteComponent,
|
|
97
|
+
beforeLoad: requireAuth("admin"),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function RouteComponent() {
|
|
101
|
+
const { alert } = useDialogs();
|
|
102
|
+
const navigate = useNavigate();
|
|
103
|
+
const features = useFeatureCollection();
|
|
104
|
+
|
|
105
|
+
const handleOnSubmit = createOptimisticAction<Feature>({
|
|
106
|
+
onMutate: (value) => {
|
|
107
|
+
features.insert(value);
|
|
108
|
+
},
|
|
109
|
+
mutationFn: async (value) => {
|
|
110
|
+
await insertFeature({ data: value });
|
|
111
|
+
await features.utils.refetch({ throwOnError: true });
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<Form
|
|
117
|
+
defaultValues={{ id: uuidv7(), name: "", quantity: 0, active: true }}
|
|
118
|
+
onSubmit={async (value) => {
|
|
119
|
+
try {
|
|
120
|
+
await handleOnSubmit(value).when("settled");
|
|
121
|
+
await navigate({ to: "/features" });
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (error instanceof Error) await alert(error.message);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
// src/lib/schemas/<feature>.ts, below FeatureSchema: a form with a library picker and a due date
|
|
134
|
+
const required = { error: () => t("Validation.Required") };
|
|
135
|
+
|
|
136
|
+
export const FeatureFormSchema = FeatureSchema.extend({
|
|
137
|
+
libraryId: z
|
|
138
|
+
.uuid(required)
|
|
139
|
+
.nullable()
|
|
140
|
+
.refine((id) => id !== null, required),
|
|
141
|
+
dueAt: z
|
|
142
|
+
.custom<Dayjs>((value) => dayjs.isDayjs(value) && value.isValid(), {
|
|
143
|
+
error: () => t("Validation.InvalidDate"),
|
|
144
|
+
})
|
|
145
|
+
.nullable()
|
|
146
|
+
.refine((value) => value !== null, required),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
export type FeatureForm = z.input<typeof FeatureFormSchema>;
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
// Inside Form.tsx: defaults typed FeatureForm, validators.onChange = FeatureFormSchema.
|
|
154
|
+
const { data: libraries } = useLiveQuery(librariesQueryOptions);
|
|
155
|
+
|
|
156
|
+
const pickerFields = (
|
|
157
|
+
<>
|
|
158
|
+
<form.AppField name="libraryId">
|
|
159
|
+
{(field) => (
|
|
160
|
+
<field.Autocomplete
|
|
161
|
+
options={libraries.map(({ id }) => id)}
|
|
162
|
+
getOptionLabel={(id) => libraries.find((library) => library.id === id)?.name ?? ""}
|
|
163
|
+
sx={{ width: 300 }}
|
|
164
|
+
textFieldProps={{ label: t("Feature.Library"), required: true }}
|
|
165
|
+
/>
|
|
166
|
+
)}
|
|
167
|
+
</form.AppField>
|
|
168
|
+
<form.AppField name="dueAt">
|
|
169
|
+
{(field) => (
|
|
170
|
+
<field.DatePicker
|
|
171
|
+
label={t("Feature.DueAt")}
|
|
172
|
+
textFieldProps={{ required: true }}
|
|
173
|
+
sx={{ width: 200 }}
|
|
174
|
+
/>
|
|
175
|
+
)}
|
|
176
|
+
</form.AppField>
|
|
177
|
+
</>
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// create defaults { …, libraryId: null, dueAt: null }; edit { ...data, dueAt: dayjs(data.dueAt) };
|
|
181
|
+
// submit: handleOnSubmit(FeatureSchema.parse({ ...value, dueAt: value.dueAt?.toDate() }))
|
|
122
182
|
```
|
package/skills/general/SKILL.md
CHANGED
|
@@ -1,127 +1,121 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: general
|
|
3
|
-
description: "Use ALWAYS, before any other skill here, for every code change
|
|
3
|
+
description: "Use ALWAYS, before any other skill here, for every code change. Sets the approved stack, coding, UI and translation conventions, tests and the validation command, where each new file goes, and the skills to load, in order, to build or remove a feature."
|
|
4
4
|
metadata:
|
|
5
5
|
type: convention
|
|
6
6
|
library: wcz-layout
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
wcz-layout skills sit on top of the TanStack skills they name: load both. Where they disagree,
|
|
10
|
+
the wcz-layout skill wins. Permissions, scopes, the signed-in user and downstream tokens:
|
|
11
|
+
[references/auth.md](references/auth.md).
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Stack
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
- TanStack owns each concern: Start (app, server functions), Router, DB (client data), Form,
|
|
16
|
+
Table (through `LayoutTable`), Query (fetches outside collections), Virtual (long lists),
|
|
17
|
+
Hotkeys, Pacer (debounce, throttle, queue), AI, Charts. MUI for components and icons.
|
|
18
|
+
Vite+ (`vp`) runs, formats, lints and tests.
|
|
19
|
+
- Anything else: install a maintained, typed library rather than hand-rolling logic, unless it
|
|
20
|
+
takes a few lines.
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
- **Vite+:** Use Vite+ for the development server, formatting, linting and testing.
|
|
17
|
-
- **Material UI:** Use Material UI for interface components and icons.
|
|
22
|
+
## Code
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
- Strict ES2023 TypeScript: no `any`, keep local inference, type public boundaries.
|
|
25
|
+
- Double quotes, semicolons, `~/` for imports from `src/`.
|
|
26
|
+
- The React Compiler memoizes: no `useMemo`, `useCallback` or `memo`.
|
|
27
|
+
- Comment only intent the code cannot show.
|
|
28
|
+
- Done means the narrowest relevant test passes and `vp check --fix` (format, lint,
|
|
29
|
+
type-check) is clean.
|
|
20
30
|
|
|
21
|
-
##
|
|
31
|
+
## UI
|
|
22
32
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
33
|
+
- Every screen works in light and dark (`theme.applyStyles("dark", …)`; the theme sets
|
|
34
|
+
`colorSchemeSelector: "data-mui-color-scheme"`) and on desktop and mobile (breakpoints).
|
|
35
|
+
- Dates: `dayjs(value).format("L LT")`, or `"L"` for a date alone.
|
|
36
|
+
- Loading states are skeletons of the final layout.
|
|
37
|
+
- A component fetching its own `useQuery` waits until visible:
|
|
38
|
+
`const { ref, inView } = useInView({ triggerOnce: true })` (`wcz-layout/hooks`),
|
|
39
|
+
`enabled: inView`, `ref` on the skeleton wrapper. Route-preloaded data stays eager.
|
|
40
|
+
Infinite scroll: `useInView()` on a sentinel after the last item.
|
|
41
|
+
- Content that fills the rest of the viewport (table, map, chart) goes in `Fullscreen`
|
|
42
|
+
(`wcz-layout/components`; Box props, scrolls inside).
|
|
43
|
+
- Success shows no message: the changed item animates where it lives (created enters, deleted
|
|
44
|
+
collapses out, edited briefly tints). When it is out of sight (you navigate away), the
|
|
45
|
+
trigger button morphs into a check for ~400 ms. Failures go to `alert()` (dialogs).
|
|
46
|
+
- Ids: `uuidv7()` from `wcz-layout/utils`, generated on the client. OS:
|
|
47
|
+
`Platform.isAndroid | isIOS | isWindows | isMacOS` from `wcz-layout/utils`.
|
|
28
48
|
|
|
29
|
-
##
|
|
49
|
+
## Translations
|
|
30
50
|
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
- Every user-facing string goes through `t`: `useTranslation()` from `wcz-layout/hooks` in
|
|
52
|
+
components, `t` from `wcz-layout/utils`. `t()` translates when called, so never at module scope (Zod messages: see
|
|
53
|
+
db-schema).
|
|
54
|
+
- Add each key to `src/lib/locales/*.json`.
|
|
55
|
+
Feature keys go under the feature's namespace (`"Feature": { "Name": "Name" }`), shared ones at the root.
|
|
56
|
+
Counts use plural keys: `_one`, `_other`, and `_few` in Czech.
|
|
37
57
|
|
|
38
|
-
##
|
|
58
|
+
## Building a feature
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- `npm run test:e2e` runs Playwright against the dev server, signed in as admin by `tests/e2e/auth.setup.ts`.
|
|
43
|
-
- Add or update tests for any new functionality or bug fixes where it matters, don't write tests just for the sake of having them.
|
|
60
|
+
Ask for the permission key when the task names none; a new key goes in
|
|
61
|
+
`src/lib/auth/permissions.ts`. Then, loading each skill on the way:
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
1. Table `src/server/db/schemas/<entity>.ts` (+ `relations.ts`), Zod schema and type
|
|
64
|
+
`src/lib/schemas/<entity>.ts`: **db-schema**
|
|
65
|
+
2. Server functions `src/server/actions/<entity>.ts`: **server-functions**
|
|
66
|
+
3. Collection `src/db/collections/<entity>.ts`, live queries `src/db/queries/<entity>.ts`:
|
|
67
|
+
**client-db**
|
|
68
|
+
4. Pages `src/routes/<entities>/` (`index.tsx` list, `$id.tsx` detail, `create.tsx`,
|
|
69
|
+
`edit.$id.tsx`, `-components/Form.tsx`, `-components/<Entity>Skeleton.tsx`), the
|
|
70
|
+
navigation item and the locale keys: **routing**, **table**, **forms**, **dialogs**
|
|
71
|
+
5. Tests, below
|
|
46
72
|
|
|
47
|
-
|
|
73
|
+
## File layout
|
|
74
|
+
|
|
75
|
+
Feature UI stays next to its route; root UI folders are for cross-feature reuse.
|
|
76
|
+
Schema, server and client-data layers use the paths below even for one feature.
|
|
48
77
|
|
|
49
78
|
```txt
|
|
50
|
-
src/
|
|
51
|
-
├── components/
|
|
52
|
-
├──
|
|
53
|
-
|
|
54
|
-
│
|
|
55
|
-
│ └── queries
|
|
56
|
-
|
|
57
|
-
├──
|
|
58
|
-
├──
|
|
59
|
-
│ └──
|
|
60
|
-
├──
|
|
61
|
-
│ ├──
|
|
62
|
-
│
|
|
63
|
-
│
|
|
64
|
-
│
|
|
65
|
-
|
|
66
|
-
│
|
|
67
|
-
│
|
|
68
|
-
│
|
|
69
|
-
├──
|
|
70
|
-
├──
|
|
71
|
-
|
|
72
|
-
│ ├── index.tsx
|
|
73
|
-
│ ├── login.tsx # required by requireAuth
|
|
74
|
-
│ ├── health.ts # Docker HEALTHCHECK, pings the database
|
|
75
|
-
│ ├── auth/ # OAuth handlers
|
|
76
|
-
│ │ ├── login.ts
|
|
77
|
-
│ │ ├── callback.ts
|
|
78
|
-
│ │ └── logout.ts
|
|
79
|
-
│ ├── api/ # REST API routes (only when a public API is required)
|
|
80
|
-
│ │ └── features/
|
|
81
|
-
│ │ ├── index.ts
|
|
82
|
-
│ │ └── $id.ts
|
|
83
|
-
│ └── features/ # feature folder with multiple routes (kebab-case, plural)
|
|
84
|
-
│ ├── -components/ # route-specific components
|
|
85
|
-
│ ├── -hooks/ # route-specific hooks
|
|
86
|
-
│ ├── index.tsx
|
|
87
|
-
│ ├── create.tsx
|
|
88
|
-
│ ├── $id.tsx
|
|
89
|
-
│ └── edit.$id.tsx
|
|
90
|
-
├── server/ # server-only code, never imported from a component
|
|
91
|
-
│ ├── actions/
|
|
92
|
-
│ │ └── <table>.ts
|
|
93
|
-
│ ├── db/
|
|
94
|
-
│ │ ├── migrations/
|
|
95
|
-
│ │ ├── schemas/ # Drizzle schemas
|
|
96
|
-
│ │ │ ├── <table>.ts
|
|
97
|
-
│ │ │ └── relations.ts
|
|
98
|
-
│ │ └── index.ts # pool, search_path, auto-migrate
|
|
99
|
-
│ └── middleware/
|
|
100
|
-
│ └── databaseMiddleware.ts # app-local, not a library export
|
|
101
|
-
├── types/
|
|
102
|
-
│ ├── i18next.d.ts # types t() against en.json
|
|
103
|
-
│ └── wcz-layout.d.ts # declares virtual:wcz-layout
|
|
104
|
-
tests/
|
|
105
|
-
├── unit/
|
|
106
|
-
│ ├── lib/
|
|
107
|
-
│ │ └── schemas/
|
|
108
|
-
│ │ └── <table>.test.ts
|
|
109
|
-
│ ├── hooks/
|
|
110
|
-
│ │ └── useX.test.ts
|
|
111
|
-
│ └── routes/
|
|
112
|
-
│ └── features/
|
|
113
|
-
│ └── -components/
|
|
114
|
-
│ └── XCard.test.tsx
|
|
115
|
-
├── integration/
|
|
116
|
-
│ ├── server/
|
|
117
|
-
│ │ └── db/ # real Postgres from DATABASE_URL
|
|
118
|
-
│ │ └── <table>.test.ts
|
|
119
|
-
│ └── db/
|
|
120
|
-
│ └── collections/ # server function mocked
|
|
121
|
-
│ └── <table>.test.ts
|
|
122
|
-
└── e2e/ # Playwright
|
|
123
|
-
├── auth.setup.ts # signs in as admin, no Microsoft login
|
|
124
|
-
├── utils.ts # gotoHydrated
|
|
125
|
-
└── features/
|
|
126
|
-
└── crud.spec.ts
|
|
79
|
+
src/
|
|
80
|
+
├── components/ # shared by several features
|
|
81
|
+
├── hooks/ # shared hooks; useTheme.ts (MUI theme)
|
|
82
|
+
├── db/
|
|
83
|
+
│ ├── collections/<entity>.ts # collection descriptor + use<Entity>Collection
|
|
84
|
+
│ └── queries/<entity>.ts # live query options
|
|
85
|
+
├── lib/ # isomorphic: client and server
|
|
86
|
+
│ ├── auth/ # permissions.ts, scopes.ts
|
|
87
|
+
│ ├── locales/ # en.json, cs.json
|
|
88
|
+
│ └── schemas/<entity>.ts # Zod schema + type
|
|
89
|
+
├── routes/
|
|
90
|
+
│ ├── __root.tsx # shell, navigation, root beforeLoad
|
|
91
|
+
│ ├── index.tsx, login.tsx, health.ts, auth/ # from the template, keep
|
|
92
|
+
│ ├── api/<entities>/ # REST routes, only for a requested public API
|
|
93
|
+
│ └── <entities>/ # feature pages; -components/, -hooks/
|
|
94
|
+
├── server/ # server-only
|
|
95
|
+
│ ├── actions/<entity>.ts # server functions
|
|
96
|
+
│ ├── db/ # index.ts, schemas/<entity>.ts, schemas/relations.ts, migrations/
|
|
97
|
+
│ └── middleware/databaseMiddleware.ts
|
|
98
|
+
├── env.ts # clientEnv, serverEnv (createEnv)
|
|
99
|
+
├── router.tsx # QueryClient, DbClient, router defaults
|
|
100
|
+
└── types/ # i18next.d.ts, wcz-layout.d.ts
|
|
127
101
|
```
|
|
102
|
+
|
|
103
|
+
## Tests
|
|
104
|
+
|
|
105
|
+
Test what guards real behavior (schema rules, form behavior, queries, constraints, a fixed
|
|
106
|
+
bug), not coverage. `vp test` runs `tests/unit` and `tests/integration`, paths mirroring
|
|
107
|
+
`src/`; `npm run test:e2e` runs `tests/e2e`.
|
|
108
|
+
|
|
109
|
+
- No globals: import from `vite-plus/test`. Component tests start with
|
|
110
|
+
`// @vitest-environment jsdom` and call `afterEach(cleanup)`.
|
|
111
|
+
- Without an initialized i18n fixture, assert Zod issue `path` and `code`, not messages.
|
|
112
|
+
- Collection tests mock the select server function, not TanStack DB. Use a fresh `DbClient`
|
|
113
|
+
per case; for one query, await `preloadLiveQuery(q)` and read
|
|
114
|
+
`dehydrate().liveQueries?.[0]?.snapshot?.rows.map(({ value }) => value)`.
|
|
115
|
+
Clean up with `await dbClient.cleanup()` and `queryClient.clear()`.
|
|
116
|
+
- Database tests need an intended test `DATABASE_URL`, always roll back and `pool.end()`.
|
|
117
|
+
Server functions themselves need a Start request context; pure DB tests do not prove RPC
|
|
118
|
+
validation, auth or HTTP behavior. Do not assume CI skips these tests.
|
|
119
|
+
- e2e uses `auth.setup.ts` and `gotoHydrated(page, url)` before interacting. Match the browser
|
|
120
|
+
locale to translated selectors. The fake session tests app access, not OAuth/delegated APIs.
|
|
121
|
+
Check create/edit/delete after reload, missing rows and rejected saves, not only type-checks.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# wcz-layout auth
|
|
2
|
+
|
|
3
|
+
## Rules
|
|
4
|
+
|
|
5
|
+
- Everything is public by default; protection is opt-in on both layers. The route guard only
|
|
6
|
+
hides UI, the middleware is the security boundary (see `routing` and `server-functions`).
|
|
7
|
+
- `requireAuth` redirects a signed-out user to `/auth/login?returnTo=…`; a signed-in user
|
|
8
|
+
without the permission gets an error, not a redirect.
|
|
9
|
+
- `hasPermission(user, key)` is for conditional UI only (navigation, buttons), never a guard.
|
|
10
|
+
- Read signed-in user from `Route.useRouteContext()` on client or `context.user` on server.
|
|
11
|
+
- `userMiddleware` gives `context.user: User | null` without throwing.
|
|
12
|
+
It is a single instance, deduped with `authMiddleware`; in server routes list both in the
|
|
13
|
+
same `middleware` array so the caller is resolved once.
|
|
14
|
+
- Permissions are evaluated per request, so moving an existing group between keys applies
|
|
15
|
+
immediately. A group name new to `permissions.ts` applies only after the user signs in
|
|
16
|
+
again (the cookie keeps only groups listed there).
|
|
17
|
+
- AWS users have no groups, so `requireAuth(key)` / `authMiddleware(key)` always reject them.
|
|
18
|
+
Use the bare form for routes AWS users must reach.
|
|
19
|
+
- Offline, guards use a cached user snapshot from `localStorage` — UI state only, the server still authorizes every call.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// src/lib/auth/permissions.ts — permission key -> group names (sAMAccountName)
|
|
23
|
+
import type { Permissions } from "wcz-layout/models";
|
|
24
|
+
|
|
25
|
+
export const permissions = {
|
|
26
|
+
admin: ["wcz-developers"],
|
|
27
|
+
} as const satisfies Permissions;
|
|
28
|
+
|
|
29
|
+
// src/lib/auth/scopes.ts — scope key -> one scope per API
|
|
30
|
+
import type { Scopes } from "wcz-layout/models";
|
|
31
|
+
|
|
32
|
+
export const scopes = {
|
|
33
|
+
graph: "User.Read", // bare string = Entra only
|
|
34
|
+
file: {
|
|
35
|
+
entra: "api://wistron.com/file-api/access_as_user",
|
|
36
|
+
aws: "https://file-api.wistron.com/access_as_user",
|
|
37
|
+
},
|
|
38
|
+
} as const satisfies Scopes;
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Gates
|
|
42
|
+
|
|
43
|
+
| Gate | Route `beforeLoad` | Server function / API route |
|
|
44
|
+
| ----------------------- | ------------------ | --------------------------- |
|
|
45
|
+
| Anyone (default) | — | — or `userMiddleware` |
|
|
46
|
+
| Signed in, any provider | `requireAuth()` | `authMiddleware()` |
|
|
47
|
+
| Signed in + permission | `requireAuth(key)` | `authMiddleware(key)` |
|
|
48
|
+
|
|
49
|
+
## Tokens for downstream APIs
|
|
50
|
+
|
|
51
|
+
From `wcz-layout/auth`, server-only (call inside a server function or server route):
|
|
52
|
+
|
|
53
|
+
- `getAccessToken(scopeKey)` — delegated token for the signed-in user from their session.
|
|
54
|
+
Requires a browser session (a Bearer caller has none). An expired session clears the cookie
|
|
55
|
+
and throws a 401 `Response`.
|
|
56
|
+
- `getAppToken(scopeKey)` — app-only Entra token (client credentials, `<resource>/.default`),
|
|
57
|
+
cached in memory. For background jobs and calls with no user.
|
|
58
|
+
- Downstream APIs must trust both issuers to accept AWS users; Cognito tokens have no `aud`
|
|
59
|
+
and are authorized by the `scope` claim.
|
|
60
|
+
|
|
61
|
+
## Example
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
65
|
+
import { authMiddleware } from "wcz-layout/middleware";
|
|
66
|
+
|
|
67
|
+
export const getGreeting = createServerFn()
|
|
68
|
+
.middleware([authMiddleware("admin")])
|
|
69
|
+
.handler(({ context }) => `Hello ${context.user.name}`);
|
|
70
|
+
```
|
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
File HTTP streaming, signed URL
|
|
2
|
+
|
|
3
|
+
# Internationalization (attach template project)
|
|
4
|
+
|
|
5
|
+
Read https://tanstack.com/router/latest/docs/guide/internationalization-i18n
|
|
6
|
+
|
|
7
|
+
Please research on what works best with tanstack-start (i18n or Paraglide) and implement that.
|
|
8
|
+
I'm about to raise a major version, so don't be afraid of big architecture change. I'm into the best tool for my use-case.
|
|
9
|
+
What I need:
|
|
10
|
+
|
|
11
|
+
- SSR implementation to tanstack-start (correct hydratation).
|
|
12
|
+
- Browser language detection.
|
|
13
|
+
- In `LayoutProvider` I'd like to set that language correctly into `zod`, `dayjs` and `LocalizationProvider`.
|
|
14
|
+
- It would be great, if user changing the language would not refresh the state (for example half-written form), but also change immediately the three libraries language.
|
|
15
|
+
- Be able to get user language on server (for example if I send some mail on server, it can be written in user selected language.)
|
|
16
|
+
- Because this is library published on npm, it would be nice if I would be able to merge locale translation keys with this project and the project where this library will be. So in `src/lib/locales` there is "Layout" object - which is just used in this project, but right now this object must be manully copied to any other project, otherwise the layout will show no translation. I would like to get rid of needing this particular object in template (keep it only in this project). But project specific translation keys will be in the same file in that particular project.
|
|
17
|
+
- Keep typesafety, right now it's only for English in `src/types/i18next`. If possible, expand to all available languages in `src/lib/locales/*`.
|
|
18
|
+
- Add into general skill, if user want's another language, here are some instructions, and put under references the language. It will be about the project as I have template. So adding file into `src/lib/locales/*` should automatically refresh the server and new language will show up, then I needs to be added in `useTheme` and also in `__root.tsx` for dayjs. I think that's it (with current implementation, before you've made some changes - but please try to keep it simple, do the logic mostly in here in layout - to have shared config across all apps).
|
|
19
|
+
|
|
20
|
+
# Environment variables
|
|
21
|
+
|
|
22
|
+
Read https://tanstack.com/start/latest/docs/framework/react/guide/environment-variables#runtime-validation
|
|
23
|
+
|
|
24
|
+
Please research if I can replace `@t3-oss/env-core` in `src/env.ts` with this tanstack-start & zod native approach.
|
|
25
|
+
It would be nice to keep current typesafety + runtime validation, while shrinking the dependency list. This package is still in 0.x.x version anyway, it's not even first major.
|
|
26
|
+
Note that there is one catch that in that. This project is public npm library and has it's own environments. That's why currently I have for example `AI_BASE_URL` optional, because as it was built and installed in template project, the project itself doesn't need that, but this library needs it for some page functionality. So the thing is, that every project should have it's own required environment variables.
|
|
27
|
+
|
|
28
|
+
# Material UI 10
|
|
29
|
+
|
|
30
|
+
One of the changes (instead of "react-number-format"): https://mui.com/material-ui/react-number-field/
|