wcz-layout 10.2.1 → 11.0.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.
Files changed (122) hide show
  1. package/dist/ChatLayout-B0MBrI-Y.mjs +2394 -0
  2. package/dist/ChatLayout-B0MBrI-Y.mjs.map +1 -0
  3. package/dist/{Employee-C8xIlBxY.d.mts → ExtractFile-BQUXpuBS.d.mts} +44 -3
  4. package/dist/FileMeta-B5VU-eCi.d.mts +55 -0
  5. package/dist/FileMeta-BexXC_45.mjs +35 -0
  6. package/dist/FileMeta-BexXC_45.mjs.map +1 -0
  7. package/dist/QueryClientParam-BG9Q_9XU.d.mts +6 -0
  8. package/dist/Translate-Ad784Dps.d.mts +24 -0
  9. package/dist/{Approval-D1TfISUL.mjs → Translate-C43AmXYW.mjs} +44 -36
  10. package/dist/Translate-C43AmXYW.mjs.map +1 -0
  11. package/dist/User-CvLutatT.d.mts +10 -0
  12. package/dist/ai.d.mts +31 -4
  13. package/dist/ai.mjs +154 -10
  14. package/dist/ai.mjs.map +1 -1
  15. package/dist/auth.d.mts +7 -14
  16. package/dist/auth.mjs +15 -38
  17. package/dist/auth.mjs.map +1 -1
  18. package/dist/authMiddleware-ANa9Tlmp.mjs +45 -0
  19. package/dist/authMiddleware-ANa9Tlmp.mjs.map +1 -0
  20. package/dist/{ChatLayout-BmLySLXy.d.mts → components-2HKj8GpC.d.mts} +219 -255
  21. package/dist/components.d.mts +2 -126
  22. package/dist/components.mjs +876 -916
  23. package/dist/components.mjs.map +1 -1
  24. package/dist/data/client.d.mts +313 -55
  25. package/dist/data/client.mjs +10 -5
  26. package/dist/data/client.mjs.map +1 -1
  27. package/dist/data/server.d.mts +19 -3
  28. package/dist/data/server.mjs +3 -5
  29. package/dist/data/server.mjs.map +1 -1
  30. package/dist/env-C4WLVJMm.mjs +32 -0
  31. package/dist/env-C4WLVJMm.mjs.map +1 -0
  32. package/dist/file-DBqTibcr.mjs +176 -0
  33. package/dist/file-DBqTibcr.mjs.map +1 -0
  34. package/dist/file-hecCQszp.mjs +114 -0
  35. package/dist/file-hecCQszp.mjs.map +1 -0
  36. package/dist/generatedChart-k7NEdi5Z.mjs.map +1 -1
  37. package/dist/hooks.d.mts +13 -93
  38. package/dist/hooks.mjs +353 -1059
  39. package/dist/hooks.mjs.map +1 -1
  40. package/dist/i18n-ZRiIIdpb.mjs +563 -0
  41. package/dist/i18n-ZRiIIdpb.mjs.map +1 -0
  42. package/dist/index.d.mts +3 -35
  43. package/dist/index.mjs +630 -680
  44. package/dist/index.mjs.map +1 -1
  45. package/dist/layout-DeTB6Ai1.mjs +224 -0
  46. package/dist/layout-DeTB6Ai1.mjs.map +1 -0
  47. package/dist/middleware.d.mts +1 -1
  48. package/dist/middleware.mjs +2 -46
  49. package/dist/middleware.mjs.map +1 -1
  50. package/dist/models.d.mts +35 -43
  51. package/dist/models.mjs +4 -6
  52. package/dist/models.mjs.map +1 -1
  53. package/dist/oidc--D2ox365.mjs +97 -0
  54. package/dist/oidc--D2ox365.mjs.map +1 -0
  55. package/dist/peoplesoft-DhwB8jrM.d.mts +204 -0
  56. package/dist/tokens-C4djIAhl.mjs +97 -0
  57. package/dist/tokens-C4djIAhl.mjs.map +1 -0
  58. package/dist/useDialogs-QER-2rVG.mjs +297 -0
  59. package/dist/useDialogs-QER-2rVG.mjs.map +1 -0
  60. package/dist/user-DQx1BanQ.mjs +120 -0
  61. package/dist/user-DQx1BanQ.mjs.map +1 -0
  62. package/dist/{utils-CNYCSgip.d.mts → utils-BnyAEKW7.d.mts} +7 -9
  63. package/dist/utils-H4BskGF8.mjs +132 -0
  64. package/dist/utils-H4BskGF8.mjs.map +1 -0
  65. package/dist/utils.d.mts +21 -4
  66. package/dist/utils.mjs +5 -4
  67. package/dist/vite.mjs +98 -32
  68. package/dist/vite.mjs.map +1 -1
  69. package/package.json +23 -29
  70. package/skills/ai/SKILL.md +105 -75
  71. package/skills/general/SKILL.md +15 -8
  72. package/skills/general/references/auth.md +15 -17
  73. package/skills/general/references/languages.md +56 -0
  74. package/skills/migrations/versions/migrate-v10-to-v11.md +98 -22
  75. package/skills/migrations/versions/migrate-v9-to-v10.md +22 -22
  76. package/skills/services/SKILL.md +41 -7
  77. package/skills/services/docs/email.md +2 -2
  78. package/skills/services/docs/file.md +100 -85
  79. package/skills/services/docs/layout.md +129 -0
  80. package/skills/start/steps/02-project-name-setup.md +1 -1
  81. package/skills/start/steps/03-apm-setup.md +8 -1
  82. package/skills/start/steps/06-entra-setup.md +1 -1
  83. package/skills/start/steps/08-generate-favicon.md +1 -1
  84. package/skills/table/SKILL.md +18 -5
  85. package/src/lib/locales/cs.json +120 -0
  86. package/src/lib/locales/en.json +119 -0
  87. package/src/lib/locales/uk.json +121 -0
  88. package/src/lib/locales/zh-TW.json +118 -0
  89. package/dist/Approval-D1TfISUL.mjs.map +0 -1
  90. package/dist/ChatLayout-BpRj5rlH.mjs +0 -1639
  91. package/dist/ChatLayout-BpRj5rlH.mjs.map +0 -1
  92. package/dist/DialogsContext-D23fJjYR.mjs +0 -6
  93. package/dist/DialogsContext-D23fJjYR.mjs.map +0 -1
  94. package/dist/Email-Dz5k0UWE.d.mts +0 -15
  95. package/dist/FileMeta-B39e2FLC.d.mts +0 -17
  96. package/dist/FileMeta-CPBWI_jA.mjs +0 -18
  97. package/dist/FileMeta-CPBWI_jA.mjs.map +0 -1
  98. package/dist/QueryClientParam-CTV1vj76.d.mts +0 -8
  99. package/dist/RouterListItemButton-CF-8w-08.mjs +0 -62
  100. package/dist/RouterListItemButton-CF-8w-08.mjs.map +0 -1
  101. package/dist/User-aJksXItw.d.mts +0 -12
  102. package/dist/approval-B3ZQn9aH.mjs +0 -83
  103. package/dist/approval-B3ZQn9aH.mjs.map +0 -1
  104. package/dist/createApi-BXjkj4fM.mjs +0 -25
  105. package/dist/createApi-BXjkj4fM.mjs.map +0 -1
  106. package/dist/env-BwFl7nWc.mjs +0 -48
  107. package/dist/env-BwFl7nWc.mjs.map +0 -1
  108. package/dist/file-BQ-Bu2g8.mjs +0 -150
  109. package/dist/file-BQ-Bu2g8.mjs.map +0 -1
  110. package/dist/file-DZ0KYhoB.mjs +0 -151
  111. package/dist/file-DZ0KYhoB.mjs.map +0 -1
  112. package/dist/peoplesoft-C-zPdRVj.d.mts +0 -161
  113. package/dist/peoplesoft-CvwdApCK.mjs +0 -125
  114. package/dist/peoplesoft-CvwdApCK.mjs.map +0 -1
  115. package/dist/providers-BfFg_3eo.mjs +0 -56
  116. package/dist/providers-BfFg_3eo.mjs.map +0 -1
  117. package/dist/session-B_jK90RC.mjs +0 -23
  118. package/dist/session-B_jK90RC.mjs.map +0 -1
  119. package/dist/tokens-CkWpu7Qp.mjs +0 -150
  120. package/dist/tokens-CkWpu7Qp.mjs.map +0 -1
  121. package/dist/utils-DJx-7b4M.mjs +0 -244
  122. package/dist/utils-DJx-7b4M.mjs.map +0 -1
@@ -1,34 +1,110 @@
1
- File HTTP streaming, signed URL
1
+ # Files: signed URLs, direct chunked upload
2
2
 
3
- # Internationalization (attach template project)
3
+ The file service is the new Rust one (same `FILE_BASE_URL` variable, now the bare host: drop a trailing `/file`). Browsers read files through
4
+ URLs it signs (2-3 hours, one file each) and upload straight to it in 1 MiB chunks, so no Entra
5
+ token reaches the browser any more. `tus-js-client` and `getFileUploadToken` are gone. Files live
6
+ under the app's `package.json` name, which wcz-layout now sets itself: `appName` is gone from
7
+ every file call and from `FileViewer`. Grep `src/` for every name on the left.
4
8
 
5
- Read https://tanstack.com/router/latest/docs/guide/internationalization-i18n
9
+ | v10 | v11 |
10
+ | -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
11
+ | `fileThumbnailQueryOptions({ appName, id })` (object URL) | `meta.urls.thumbnail` |
12
+ | `fileQueryOptions({ appName, id })` (object URL) | `meta.urls.view`; with only an id: `useQuery(fileMetaQueryOptions({ id }))` |
13
+ | `downloadFileMutationOptions()` + `download({ … })` | `<a href={meta.urls.download}>` (or `href` on a MUI `Button`/`MenuItem`) |
14
+ | `openFileMutationOptions({ target })` + `window.open("about:blank")` | `window.open(meta.urls.view, "_blank", "noopener")` in the click handler |
15
+ | server `getFile`, `downloadFile`, `getFileThumbnail` (`Response`) | `fetch(meta.urls.view / .download / .thumbnail)` |
16
+ | `fileMetasQueryOptions({ appName, subId })`, `batchDelete…` likewise | `({ subId })` |
17
+ | `deleteFile…({ appName, id })`, `FileSchema` with `appName` | `({ id })` |
18
+ | `<FileViewer appName={…} subId={…}>` | `<FileViewer subId={…}>` |
19
+ | `updateFileMeta…({ …wholeFileMeta, fileName })` | `({ id, fileName?, subId?, public?, permissions? })` → updated `FileMeta`; `fileName` without the extension |
20
+ | `uploadFile…({ appName, subId, file })` → `{ id, appName, … }` | `({ subId, file })` → the created `FileMeta`; also takes `public`, `permissions`, `signal` |
21
+ | `meta.createdBy`, `meta.createdDate` | gone: the file service keeps who and when in its audit log |
22
+ | hand-built iOS `.plist` + no-auth `/na/file/…` URL | `meta.urls.install` of the `.ipa` (manifest generated from its `Info.plist`) |
6
23
 
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:
24
+ 1. Apply the table. `FileMeta` gained `public`, `permissions`, `canWrite` and `urls`; `subId` is
25
+ any 1-255 character string, no longer only a UUID. The type of a file now comes from its
26
+ extension.
27
+ 2. Never store `urls` (state, database, email body): they expire. Store the file `id` and read
28
+ the URLs from `fileMetasQueryOptions` / `fileMetaQueryOptions`, which refresh them hourly.
29
+ 3. Show rename and delete only where `meta.canWrite`.
30
+ 4. Restricting a file: pass `permissions: { read, write }` (see `skills/services/docs/file.md`).
31
+ Without it everyone the app serves reads and changes the file, as before. Public routes keep
32
+ working without a user, through the app token, which reaches only files without a list: on a
33
+ public route, restrict `write` to keep anonymous visitors from deleting files.
10
34
 
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).
35
+ # Internationalization
36
+
37
+ The server now renders the language of each request (the `i18next` cookie, else
38
+ `Accept-Language`), wcz-layout ships its own `Layout.*` strings, and a language switch
39
+ re-renders in place instead of remounting the page, so typed form values survive it.
40
+
41
+ 1. `src/routes/__root.tsx`: delete `setLanguageFromRequest` (the import and the `await` in
42
+ `beforeLoad`) and every `import "dayjs/locale/…"`. Call `useTheme()` without the language.
43
+ `useTranslation` there must come from `wcz-layout/hooks`: react-i18next's own renders the
44
+ server's default language above `LayoutProvider`.
45
+ 2. `src/hooks/useTheme.ts`: delete the `@mui/material/locale` and `@mui/x-date-pickers/locales`
46
+ imports, `MUI_LOCALE_MAP`, its type guard and the `locale` parameter. `LayoutProvider`
47
+ applies the MUI locales of every app language.
48
+ 3. `src/lib/locales/en.json`, `cs.json`, `uk.json` and `zh-TW.json`: delete the `"Layout"`
49
+ object; a copy would hide wcz-layout's later changes. In any other language's file keep it:
50
+ it now overrides wcz-layout's English key by key.
51
+ 4. Every app ships Ukrainian and Traditional Chinese (Taiwan). Where `src/lib/locales/uk.json`
52
+ or `zh-TW.json` is missing, create it next to the existing files with every key of the
53
+ app's `en.json`, translated into that language yourself as part of this step; do not ask
54
+ and do not leave English values. Plurals: `uk` needs `_one`, `_few`, `_many` and
55
+ `_other`; `zh-TW` has only `_other`. Keep `{{placeholders}}` and `<tags>` as they are. No
56
+ `"Layout"` object: wcz-layout ships both.
57
+ 5. Delete `src/types/i18next.d.ts`. `vp dev` writes `src/types/i18next.gen.ts`, which also
58
+ checks every locale against `en.json`; commit it and add the keys the type-check reports
59
+ missing.
60
+ 6. Dates formatted in components: `dayjs(value).format(…)` becomes
61
+ `dayjs(value).locale(i18n.language).format(…)`, `i18n` from `useTranslation()`, or the date
62
+ keeps its old format after a language switch.
63
+
64
+ Server code needs no change: `t` from `wcz-layout/utils` now translates into the request's
65
+ language, and `getLanguage()` is new there.
19
66
 
20
67
  # Environment variables
21
68
 
22
- Read https://tanstack.com/start/latest/docs/framework/react/guide/environment-variables#runtime-validation
69
+ `@t3-oss/env-core` is gone. `src/env.ts` now only names variables: wcz-layout validates them
70
+ (empty values count as unset) and serves the values as `serverEnv` and `clientEnv` from
71
+ `wcz-layout/utils`. wcz-layout reads only what the app names, its own variables included.
23
72
 
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.
73
+ 1. Rewrite `src/env.ts` like `scopes.ts`: `export const env = { server: { … }, client: { … } }
74
+ satisfies Env;`, `Env` from `wcz-layout/models`. `server` takes the old `server` block,
75
+ `client` the old `client` block (`VITE_` only, `{}` when empty): UPPER_SNAKE_CASE keys, Zod
76
+ schemas as values. Only `import type` from wcz-layout there; a runtime import is a cycle.
77
+ 2. Name in `server` every variable the app reads, wcz-layout's too: `ENTRA_CLIENT_ID`,
78
+ `ENTRA_TENANT_ID`, `ENTRA_CLIENT_SECRET` and `SESSION_SECRET` (`z.string().min(32)`) always,
79
+ the `*_BASE_URL` of each wcz-layout service it uses (file, approval, PeopleSoft, email,
80
+ layout), `AI_BASE_URL` and `AI_SUBSCRIPTION_KEY` for AI. An unnamed variable stays
81
+ `undefined` to wcz-layout even when it is set.
82
+ 3. Import `serverEnv` and `clientEnv` from `wcz-layout/utils` instead of `~/env`.
83
+ 4. `src/types/wcz-layout.d.ts`: replace the `serverEnv` line with
84
+ `export const env: typeof import("~/env").env;`.
27
85
 
28
- # Material UI 10
86
+ # Sign-in
29
87
 
30
- One of the changes (instead of "react-number-format"): https://mui.com/material-ui/react-number-field/
88
+ Entra is the only sign-in: `/auth/login` redirects straight to it, so the provider chooser is
89
+ gone. Delete `src/routes/login.tsx` (`LoginForm` and `loginProvidersQueryOptions` no longer
90
+ exist) and any `AWS_*` variables.
91
+
92
+ # Web app manifest
31
93
 
32
- # Export
94
+ `viteWczLayout()` and `rootRouteHead()` now use `public/manifest.webmanifest` instead of
95
+ `public/manifest.json`.
33
96
 
34
- Remove "src/exports/ai.ts" and put it into utils
97
+ Rename `public/manifest.json` to `public/manifest.webmanifest`.
98
+ `rootRouteHead()` now also emits `<meta name="theme-color">` from `theme_color` in the
99
+ manifest when present.
100
+
101
+ # package.json overrides
102
+
103
+ v11 needs no `overrides` for wcz-layout. Delete the `"wcz-layout"` entry (such as
104
+ `{ "@tanstack/react-db": "$@tanstack/react-db" }`) and add none. If `npm install wcz-layout@11`
105
+ then fails with `ERESOLVE` on a peer of the new AI packages, the old lockfile is in the way:
106
+ delete `package-lock.json` and install again instead of adding an override.
107
+
108
+ # Material UI 10
109
+
110
+ One of the changes (instead of "react-number-format"): https://mui.com/material-ui/react-number-field/
@@ -286,26 +286,28 @@ Delete `src/components/DataGridToolbar.tsx`; `LayoutTable` renders the toolbar,
286
286
  quick filter, columns panel and filter panel itself. In `useTheme.ts`, drop
287
287
  `import { csCZ, enUS } from "@mui/x-data-grid/locales"` and its two entries.
288
288
 
289
- | DataGridPremium | LayoutTable |
290
- | --------------------------------------------------- | ------------------------------------------------------------------ |
291
- | `Array<GridColDef<Row>>` | `columnHelper.columns([...])` from `createLayoutColumnHelper` |
292
- | `field` / `headerName` | the accessor key / `header` |
293
- | `width`, `flex`, `minWidth` | `size` |
294
- | `renderCell` | `cell: ({ cell }) => <cell.ValueCell />` |
295
- | `valueGetter: (_v, row) => row.x.y` | `columnHelper.accessor((row) => row.x.y, { id: "..." })` |
296
- | `align` / `headerAlign` | `meta: { align }` |
297
- | `initialState.pinnedColumns.left` / `.right` | `initialState.columnPinning.start` / `.end` |
298
- | `initialState.sorting.sortModel` `{field, sort}` | `initialState.sorting` `[{ id, desc }]` |
299
- | `valueFormatter` on a date column | `cell.DateCell` or `cell.DateTimeCell` |
300
- | `valueFormatter` with an `Intl.NumberFormat` | `cell.NumberCell options={...}`, same options object |
301
- | `type: "singleSelect"` with `valueOptions` | `meta: { variant: "select", options }` |
302
- | `type: "number"` / `"date"` / `"boolean"` | `meta: { variant: "number" \| "date" \| "boolean" }` |
303
- | `rows` and `columns` props | `useLayoutTable({ data, columns })`, then `table={table}` |
304
- | `showToolbar` with `slots.toolbar` | `showToolbar` with `title` and `actions` on `LayoutTable` |
305
- | `ignoreDiacritics` | always on |
306
- | `rowSelectionModel` state | `table.getSelectedRowIds()`, `table.resetRowSelection()` |
307
- | `cellSelection` | always on, `Mod+C` copies the range as TSV |
308
- | `GridActionsCellItem` in a `type: "actions"` column | a `display` column rendering `cell.ActionsCell`, `showInMenu` kept |
289
+ | DataGridPremium | LayoutTable |
290
+ | --------------------------------------------------- | ------------------------------------------------------------------------- |
291
+ | `Array<GridColDef<Row>>` | `columnHelper.columns([...])` from `createLayoutColumnHelper` |
292
+ | `field` / `headerName` | the accessor key / `header` |
293
+ | `width`, `flex`, `minWidth` | `size` |
294
+ | `renderCell` | `cell: ({ cell }) => <cell.ValueCell />` |
295
+ | `valueGetter: (_v, row) => row.x.y` | `columnHelper.accessor((row) => row.x.y, { id: "..." })` |
296
+ | `align` / `headerAlign` | `meta: { align }` |
297
+ | `initialState.pinnedColumns.left` / `.right` | `initialState.columnPinning.start` / `.end` |
298
+ | `initialState.sorting.sortModel` `{field, sort}` | `initialState.sorting` `[{ id, desc }]` |
299
+ | `valueFormatter` on a date column | `cell.DateCell` or `cell.DateTimeCell` |
300
+ | `valueFormatter` with an `Intl.NumberFormat` | `cell.NumberCell options={...}`, same options object |
301
+ | `type: "singleSelect"` with `valueOptions` | `meta: { variant: "select", options }` |
302
+ | `type: "number"` / `"date"` / `"boolean"` | `meta: { variant: "number" \| "date" \| "boolean" }` |
303
+ | `rows` and `columns` props | `useLayoutTable({ data, columns })`, then `table={table}` |
304
+ | `showToolbar` with `slots.toolbar` | `showToolbar` with `title` and `actions` on `LayoutTable` |
305
+ | `ignoreDiacritics` | always on |
306
+ | `rowSelectionModel` state | `table.getSelectedRowIds()`, `table.resetRowSelection()` |
307
+ | `cellSelection` | always on, `Mod+C` copies the range as TSV |
308
+ | `GridActionsCellItem` in a `type: "actions"` column | a `display` column rendering `cell.ActionsCell`, `showInMenu` kept |
309
+ | `pagination`, `pageSizeOptions`, `paginationModel` | `pagination` only: always 25 rows per page, drop the sizes |
310
+ | `paginationMode="server"` with `rowCount` | `manualPagination: true` and `rowCount` on `useLayoutTable` (table skill) |
309
311
 
310
312
  **Every row needs an `id`.** `getRowId` is not an option — the library hardcodes
311
313
  `row.id`. A table over a view or a natural-key table without an `id` column must add
@@ -455,7 +457,6 @@ it over the app's block. For any other language, translate the English block.
455
457
  "SelectedCount_other": "{{count}} selected",
456
458
  "MoveLeft": "Move left",
457
459
  "MoveRight": "Move right",
458
- "All": "All",
459
460
  "Columns": "Columns",
460
461
  "ShowHideAll": "Show/Hide all",
461
462
  "HideColumn": "Hide column",
@@ -548,7 +549,6 @@ it over the app's block. For any other language, translate the English block.
548
549
  "SelectedCount_other": "{{count}} vybraných",
549
550
  "MoveLeft": "Posunout doleva",
550
551
  "MoveRight": "Posunout doprava",
551
- "All": "Vše",
552
552
  "Columns": "Sloupce",
553
553
  "ShowHideAll": "Zobrazit/skrýt vše",
554
554
  "HideColumn": "Skrýt sloupec",
@@ -1,6 +1,6 @@
1
1
  ---
2
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."
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; sending email; or AI features: translating text into several languages with language detection, and extracting fields from an uploaded PDF or image. Also when an app calls another downstream REST API that wcz-layout has no service for."
4
4
  metadata:
5
5
  type: integration
6
6
  library: wcz-layout
@@ -26,9 +26,43 @@ You can read about each service in the links below. Services are categorized as
26
26
 
27
27
  ## Services
28
28
 
29
- | Service | File | Summary |
30
- | ---------- | ----------------------------------- | ----------------------------------------------------------------------- |
31
- | file | [file.md](docs/file.md) | File metadata, thumbnails, binary download/open, upload, update, delete |
32
- | approval | [approval.md](docs/approval.md) | Approval request lifecycle, approvers, flows, statuses, step results |
33
- | peoplesoft | [peoplesoft.md](docs/peoplesoft.md) | Employee, manager, department, and company general manager lookups |
34
- | email | [email.md](docs/email.md) | Server-only email sending with optional file attachment references |
29
+ | Service | File | Summary |
30
+ | ---------- | ----------------------------------- | ------------------------------------------------------------------------ |
31
+ | file | [file.md](docs/file.md) | File metadata, thumbnails, binary download/open, upload, update, delete |
32
+ | approval | [approval.md](docs/approval.md) | Approval request lifecycle, approvers, flows, statuses, step results |
33
+ | peoplesoft | [peoplesoft.md](docs/peoplesoft.md) | Employee, manager, department, and company general manager lookups |
34
+ | email | [email.md](docs/email.md) | Server-only email sending with optional file attachment references |
35
+ | layout | [layout.md](docs/layout.md) | Layout app AI: translation with language detection, file data extraction |
36
+
37
+ ## Custom API
38
+
39
+ When the app needs a downstream REST API that no service above covers, build the client with
40
+ `createApi` from `wcz-layout/data/server`. It resolves the base URL from env, attaches the
41
+ signed-in user's token for the scope and turns error responses into `Error(message)`. It is
42
+ server-only: call it inside a server function handler, never at module scope.
43
+
44
+ 1. `src/env.ts`: add `MY_API_BASE_URL: z.url()` to `server` (`createApi` takes only `z.url()` variables).
45
+ 2. `src/lib/auth/scopes.ts`: add `myApi: "api://wistron.com/my-api/access_as_user"`.
46
+ 3. `src/lib/schemas/<name>.ts`: Zod input schemas and response models.
47
+ 4. `src/server/actions/<name>.ts`: one server function per endpoint, gated with `authMiddleware`
48
+ (the token belongs to the signed-in user); see **server-functions**.
49
+
50
+ ```ts
51
+ import { createServerFn } from "@tanstack/react-start";
52
+ import { createApi } from "wcz-layout/data/server";
53
+ import { authMiddleware } from "wcz-layout/middleware";
54
+ import { MyModelSchema, type MyModel } from "~/lib/schemas/inventory";
55
+
56
+ const myApi = () => createApi({ baseURL: "MY_API_BASE_URL", scopeKey: "myApi" });
57
+
58
+ export const getItem = createServerFn({ method: "GET" })
59
+ .validator(MyModelSchema)
60
+ .middleware([authMiddleware()])
61
+ .handler(async ({ data }) => {
62
+ const api = await myApi();
63
+ const { data: item } = await api.get<MyModel>(`/items/${encodeURIComponent(data.id)}`);
64
+ return item;
65
+ });
66
+ ```
67
+
68
+ Wrap reads in `queryOptions` and writes in `mutationOptions`, the same shape as the built-in client exports.
@@ -6,7 +6,7 @@
6
6
 
7
7
  - `sendEmail({ data: EmailSchema })` → `void` // server-only, call inside another server function
8
8
  - `body` // HTML string
9
- - `attachments` // `appName` + `subId` used when uploading the files (see [file.md](file.md)); the email service attaches all files stored under that `subId`
9
+ - `attachments` // `appName` (the app's package.json name, under which wcz-layout stores its files) + the `subId` used when uploading them (see [file.md](file.md)); the email service attaches all files stored under that `subId`
10
10
 
11
11
  ## Schemas/Models
12
12
 
@@ -40,7 +40,7 @@ await sendEmail({
40
40
  },
41
41
  });
42
42
 
43
- // with cc and attachments (files previously uploaded with uploadFileMutationOptions({ appName, subId, file }))
43
+ // with cc and attachments (files previously uploaded with uploadFileMutationOptions({ subId, file }))
44
44
  await sendEmail({
45
45
  data: {
46
46
  subject: "Document Submission",
@@ -1,43 +1,60 @@
1
1
  # file
2
2
 
3
+ Files live in the WCZ file service, under the app's `package.json` name (set automatically; never
4
+ passed). App servers call it with the signed-in user's Entra token, or with the app token when
5
+ nobody is signed in (public routes, jobs). Browsers use the URLs it returns (`<img src>`,
6
+ `<a href>`, `window.open`) and upload straight to it. No token ever reaches the browser: every URL
7
+ is signed for one file, for 2-3 hours, unless the file is `public`.
8
+
3
9
  ## Client
4
10
 
5
11
  `import { ... } from "wcz-layout/data/client";`
6
12
 
7
- - Query:
8
- `fileMetasQueryOptions(GetFileMetasSchema)` → `FileMeta[]` // metadata of all files under `subId`
9
- `fileThumbnailQueryOptions(FileSchema)` → `string` // thumbnail as object URL, disabled while `id` is empty
10
- `fileQueryOptions(FileSchema)` → `string` // file content as object URL for preview, disabled while `id` is empty
13
+ - Query (refreshed hourly so their URLs never expire; read URLs from the query, never store them):
14
+ `fileMetasQueryOptions({ subId })` → `FileMeta[]` // files under `subId` the caller can read
15
+ `fileMetaQueryOptions({ id })` → `FileMeta` // one file, disabled while `id` is empty
11
16
  - Mutation:
12
- `downloadFileMutationOptions()` → `mutate(FileSchema & { fileName, fileExtension })` // downloads and saves as `fileName.fileExtension`
13
- `openFileMutationOptions({ target })` → `mutate(FileSchema)` // opens file in new tab; `target` is a `useRef<Window | null>`, open `about:blank` into it synchronously in the click handler to avoid popup blockers
14
- `updateFileMetaMutationOptions({ queryClient })` → `mutate(UpdateFileMetaSchema)` // update metadata (e.g. rename `fileName`), invalidates metas
15
- `deleteFileMutationOptions({ queryClient })` → `mutate(FileSchema)` // delete single file, invalidates metas
16
- `batchDeleteFilesMutationOptions({ queryClient })` → `mutate(GetFileMetasSchema)` // delete all files under `subId`, invalidates metas
17
- `uploadFileMutationOptions({ queryClient })` → `mutate(UploadFileMetaSchema & { setProgress? })` → `{ id, appName, subId, fileName }` // uploads directly from browser via TUS (1 MB chunks), `setProgress(percent)` for a progress bar, invalidates metas of `subId`
17
+ `uploadFileMutationOptions({ queryClient })` → `mutate({ subId, file, id?, public?, permissions?, setProgress?, signal? })` → `FileMeta` // 1 MiB chunks straight to the file service; retries network failures for ~2 min and resumes; `setProgress(percent)`; `signal` cancels; the type comes from the extension; invalidates metas of `subId`
18
+ `updateFileMetaMutationOptions({ queryClient })` → `mutate(UpdateFileMetaSchema)` → `FileMeta` // rename (base name), move to another `subId`, change `public` / `permissions`; needs write
19
+ `deleteFileMutationOptions({ queryClient })` → `mutate({ id })` // needs write
20
+ `batchDeleteFilesMutationOptions({ queryClient })` → `mutate({ subId })` // every file under `subId`, or none when the caller can't delete one of them
21
+
22
+ Open, show and download with the URLs: `window.open(meta.urls.view)` (Office files open as PDF,
23
+ types the browser can't show download), `<img src={meta.urls.thumbnail}>` (default icon for
24
+ non-images), `<a href={meta.urls.download}>` (always the original, as an attachment).
18
25
 
19
26
  ## Server
20
27
 
21
28
  `import { ... } from "wcz-layout/data/server";`
22
29
 
23
- - Fetch:
24
- `getFileMetas({ data: GetFileMetasSchema })` → `FileMeta[]` // metadata of all files under `subId`
25
- `getFileThumbnail({ data: FileSchema })` → `Response` // thumbnail binary stream
26
- `getFile({ data: FileSchema })` → `Response` // file binary stream, `Content-Disposition: inline`
27
- `downloadFile({ data: FileSchema })` → `Response` // file binary stream for download
28
- - Mutate:
29
- `updateFileMeta({ data: UpdateFileMetaSchema })` → `void` // update metadata
30
- `deleteFile({ data: FileSchema })` → `void` // delete single file
31
- `batchDeleteFiles({ data: GetFileMetasSchema })` → `void` // delete all files under `subId`
32
- `uploadFile({ data: UploadFileMetaSchema })` → `{ id, appName, subId, fileName }` // server-originated uploads only, client uploads go direct via `uploadFileMutationOptions`
30
+ `getFileMetas`, `getFileMeta`, `updateFileMeta`, `deleteFile`, `batchDeleteFiles` take
31
+ `{ data }` like the client ones.
32
+ `uploadFile({ data: UploadFileSchema })` → `FileMeta` // server-originated files, e.g. a generated report
33
+ File bytes on the server: `fetch(meta.urls.download)`.
34
+
35
+ ## Permissions
36
+
37
+ `public` and `permissions` decide access; omitted, everyone the app serves reads and changes the
38
+ file: every employee, and anonymous visitors of a public route.
39
+
40
+ - `public: true` — anyone reads it without signing in (stable, unsigned URLs). Never grants write.
41
+ - `permissions: { read, write }` — both required when sent. Each is `null` (no restriction:
42
+ read = everyone, write = whoever can read) or a non-empty list of
43
+ `{ group: "<sAMAccountName>" }` / `{ employeeId: "<id>" }`. Write implies read.
44
+ - Anonymous visitors (the app token) have no groups and no employee ID: they reach only files
45
+ without a list, so restrict `write` (e.g. to an admin group) to keep them from changing or
46
+ deleting files, and `read` to hide files from them.
47
+ - A group must reach the File API token: with "Groups assigned to the application" it has to be
48
+ assigned to the File API registration. Employee entries have no such limit.
49
+ - `meta.canWrite` tells whether the caller may rename or delete it; hide those actions otherwise.
33
50
 
34
51
  ## Components
35
52
 
36
53
  `import { Dropzone, FileViewer } from "wcz-layout/components";`
37
54
 
38
55
  - `<Dropzone onDrop progress? sx? {...DropzoneOptions} />` // react-dropzone area (`accept`, `maxFiles`, `disabled`, `onDropAccepted`, …), `progress` (0-100) shows upload progress
39
- - `<FileViewer appName subId actions? onDelete?>{(component) => <component.Grid /> | <component.List />}</FileViewer>` // fetches metas itself, renders nothing when there are no files
40
- - `actions?: { download?: boolean, delete?: boolean }` // both enabled by default
56
+ - `<FileViewer subId actions? onDelete?>{(component) => <component.Grid /> | <component.List />}</FileViewer>` // fetches metas itself, renders nothing when there are no files; thumbnails load lazily, and hovering a file (up to 20 MB) prefetches it so it opens instantly
57
+ - `actions?: { download?: boolean, delete?: boolean }` // both enabled by default; delete shows only where `canWrite`
41
58
  - `onDelete?: ({ remainingFileMetas: FileMeta[], deletedFileMeta: FileMeta }) => void`
42
59
  - `component.Grid` props: `size?: number` (default 150), `itemBar?: "hidden" | "always" | "onMouseEnter"` (default on hover), `sx?`
43
60
  - `component.List` props: `sx?`
@@ -45,81 +62,83 @@
45
62
  ## Schemas/Models
46
63
 
47
64
  ```ts
48
- const FileMetaSchema = z.object({
49
- id: z.uuid(),
50
- subId: z.uuid(),
51
- appName: z.string().trim().min(1).max(255),
52
- fileName: z.string().trim().min(1).max(255),
53
- fileExtension: z.string().trim().min(1).max(255),
54
- fileSize: z.number().min(0),
55
- mediaSubType: z.string().trim().min(1).max(255),
56
- mediaType: z.string().trim().min(1).max(255),
57
- mimeType: z.string().trim().min(1).max(255),
58
- createdBy: z.string().trim().min(1).max(255),
59
- createdDate: z.date(),
65
+ const FilePrincipalSchema = z.union([
66
+ z.strictObject({ group: z.string().trim().min(1) }),
67
+ z.strictObject({ employeeId: z.string().trim().min(1) }),
68
+ ]);
69
+ const FilePermissionsSchema = z.object({
70
+ read: z.array(FilePrincipalSchema).min(1).nullable(),
71
+ write: z.array(FilePrincipalSchema).min(1).nullable(),
60
72
  });
61
73
 
62
- const GetFileMetasSchema = z.object({
63
- appName: z.string().min(1).max(255),
64
- subId: z.uuid(),
65
- });
66
-
67
- const FileSchema = z.object({
68
- appName: z.string().min(1).max(255),
74
+ const FileMetaSchema = z.object({
69
75
  id: z.uuid(),
76
+ appName: z.string(),
77
+ subId: z.string(),
78
+ fileName: z.string(), // without the extension
79
+ fileExtension: z.string(),
80
+ fileSize: z.number(),
81
+ mimeType: z.string(), // from the extension
82
+ mediaType: z.string(), // "image", "video", "application", …
83
+ mediaSubType: z.string(),
84
+ public: z.boolean(),
85
+ permissions: FilePermissionsSchema,
86
+ canWrite: z.boolean(),
87
+ urls: z.object({
88
+ view: z.url(),
89
+ download: z.url(),
90
+ thumbnail: z.url(),
91
+ install: z.string().optional(), // .ipa only: itms-services:// install link
92
+ }),
70
93
  });
71
94
 
72
- const UpdateFileMetaSchema = FileMetaSchema.extend({
73
- fileName: z.string().min(1).max(255),
95
+ const GetFileMetasSchema = z.object({ subId: z.string().min(1).max(255) });
96
+ const FileSchema = z.object({ id: z.uuid() });
97
+ const UpdateFileMetaSchema = FileSchema.extend({
98
+ fileName: z.string().trim().min(1).max(255).optional(),
99
+ subId: z.string().min(1).max(255).optional(),
100
+ public: z.boolean().optional(),
101
+ permissions: FilePermissionsSchema.optional(),
74
102
  });
75
-
76
- const UploadFileMetaSchema = z.object({
77
- id: z.uuid().default(uuidv7),
78
- appName: z.string().min(1).max(255),
79
- subId: z.uuid(),
103
+ const UploadFileSchema = z.object({
104
+ id: z.uuidv7().default(uuidv7),
105
+ subId: z.string().min(1).max(255),
80
106
  file: z.instanceof(File),
107
+ public: z.boolean().optional(),
108
+ permissions: FilePermissionsSchema.optional(),
81
109
  });
82
110
  ```
83
111
 
84
112
  ## Examples
85
113
 
86
114
  ```tsx
87
- import { useRef, useState } from "react";
115
+ import { useState } from "react";
88
116
  import { useMutation, useQuery } from "@tanstack/react-query";
89
117
  import {
90
118
  deleteFileMutationOptions,
91
- downloadFileMutationOptions,
92
119
  fileMetasQueryOptions,
93
- fileQueryOptions,
94
- openFileMutationOptions,
95
120
  uploadFileMutationOptions,
96
121
  } from "wcz-layout/data/client";
97
122
  import { Dropzone, FileViewer } from "wcz-layout/components";
98
- import { useInView } from "wcz-layout/hooks";
99
-
100
- const { queryClient } = Route.useRouteContext();
101
123
 
102
- // fetch metas (lazily when in view) + fetch first file
103
- const { ref, inView } = useInView({ triggerOnce: true });
124
+ const { queryClient, user } = Route.useRouteContext();
104
125
 
105
- const { data: fileMetas = [] } = useQuery({
106
- ...fileMetasQueryOptions({ appName: packageJson.name, subId }),
107
- enabled: inView,
108
- });
109
-
110
- const { data: file } = useQuery({
111
- ...fileQueryOptions({ appName: packageJson.name, id: fileMetas[0]?.id ?? "" }),
112
- enabled: !!fileMetas[0],
113
- });
114
-
115
- // upload via Dropzone
126
+ // upload via Dropzone; only the uploader and HR may read, only HR may change
116
127
  const [progress, setProgress] = useState(0);
117
128
  const { mutateAsync: uploadFile } = useMutation(uploadFileMutationOptions({ queryClient }));
118
129
 
119
130
  const onDrop = async (acceptedFiles: File[]) => {
120
131
  await Promise.allSettled(
121
132
  acceptedFiles.map((file) =>
122
- uploadFile({ appName: packageJson.name, subId, file, setProgress }),
133
+ uploadFile({
134
+ subId,
135
+ file,
136
+ setProgress,
137
+ permissions: {
138
+ read: [{ employeeId: user.employeeId }, { group: "hr" }],
139
+ write: [{ group: "hr" }],
140
+ },
141
+ }),
123
142
  ),
124
143
  );
125
144
  setProgress(0);
@@ -127,24 +146,20 @@ const onDrop = async (acceptedFiles: File[]) => {
127
146
 
128
147
  <Dropzone onDrop={onDrop} progress={progress} />;
129
148
 
130
- // download / delete
131
- const { mutate: download } = useMutation(downloadFileMutationOptions());
132
- const { mutate: remove } = useMutation(deleteFileMutationOptions({ queryClient }));
149
+ // public route (no requireAuth): anonymous visitors add photos only admins may delete
150
+ uploadFile({ subId, file, permissions: { read: null, write: [{ group: "canteen-admins" }] } });
133
151
 
134
- download({
135
- appName: packageJson.name,
136
- id: meta.id,
137
- fileName: meta.fileName,
138
- fileExtension: meta.fileExtension,
139
- });
140
- remove({ appName: packageJson.name, id: meta.id });
152
+ // own list: open, show, download, delete
153
+ const { data: fileMetas = [] } = useQuery(fileMetasQueryOptions({ subId }));
154
+ const { mutate: remove } = useMutation(deleteFileMutationOptions({ queryClient }));
141
155
 
142
- // open file
143
- const target = useRef<Window | null>(null);
144
- const { mutate: openFile } = useMutation(openFileMutationOptions({ target }));
156
+ <img src={meta.urls.thumbnail} alt="" loading="lazy" />;
157
+ <Button onClick={() => window.open(meta.urls.view, "_blank", "noopener")}>Open</Button>;
158
+ <Button href={meta.urls.download}>Download</Button>;
159
+ {
160
+ meta.canWrite && <Button onClick={() => remove({ id: meta.id })}>Delete</Button>;
161
+ }
145
162
 
146
163
  // File Viewer - no manual fetch of metas needed
147
- <FileViewer appName={packageJson.name} subId={subId}>
148
- {(component) => <component.Grid />} // or component.List
149
- </FileViewer>;
164
+ <FileViewer subId={subId}>{(component) => <component.Grid />} // or component.List</FileViewer>;
150
165
  ```