@jskit-ai/agent-docs 0.1.363 → 0.1.365

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 (83) hide show
  1. package/guide/agent/app-extras/mobile-capacitor.md +5 -0
  2. package/guide/agent/app-setup/authentication.md +10 -8
  3. package/guide/agent/app-setup/database-layer.md +67 -43
  4. package/guide/agent/app-setup/existing-application-migration.md +3 -1
  5. package/guide/agent/app-setup/upgrading-jskit.md +13 -3
  6. package/guide/agent/framework/application-operations.md +9 -0
  7. package/guide/agent/framework/client-features.md +22 -0
  8. package/guide/agent/framework/speed-pass.md +6 -94
  9. package/guide/agent/framework/test-pass.md +210 -0
  10. package/guide/agent/framework/typed-features.md +64 -1
  11. package/guide/agent/framework/ui-operations.md +43 -8
  12. package/guide/agent/index.md +40 -4
  13. package/guide/agent/recipes/another-language.md +129 -0
  14. package/guide/agent/recipes/file-uploads-and-images.md +125 -0
  15. package/guide/agent/recipes/installable-app.md +383 -0
  16. package/guide/agent/recipes/invite-people-with-roles.md +142 -0
  17. package/guide/agent/recipes/offline-study.md +163 -0
  18. package/guide/agent/recipes/payments-and-subscriptions.md +156 -0
  19. package/guide/agent/recipes/reminders-and-digests.md +153 -0
  20. package/guide/agent/recipes/usefulness-study.md +137 -0
  21. package/package.json +1 -1
  22. package/patterns/minimal-foundation/PATTERN.md +2 -0
  23. package/patterns/minimal-foundation/example/AGENTS.md +54 -101
  24. package/patterns/minimal-foundation/example/gitignore +1 -1
  25. package/patterns/minimal-foundation/example/package.json +3 -3
  26. package/patterns/minimal-foundation/example/server/lib/loggerOptions.js +6 -3
  27. package/patterns/minimal-foundation/example/server.js +1 -1
  28. package/patterns/minimal-foundation/example/vite.config.mjs +3 -2
  29. package/patterns/shell-foundation/PATTERN.md +2 -0
  30. package/patterns/shell-foundation/example/AGENTS.md +54 -101
  31. package/patterns/shell-foundation/example/gitignore +1 -1
  32. package/patterns/shell-foundation/example/package.json +4 -4
  33. package/patterns/shell-foundation/example/server/lib/loggerOptions.js +6 -3
  34. package/patterns/shell-foundation/example/server.js +1 -1
  35. package/patterns/shell-foundation/example/vite.config.mjs +3 -2
  36. package/reference/autogen/PATTERN_INDEX.md +36 -36
  37. package/reference/autogen/packages/agent-docs.md +2 -2
  38. package/reference/autogen/packages/assistant-runtime.md +4 -0
  39. package/reference/autogen/packages/auth-provider-local-core.md +1 -0
  40. package/reference/autogen/packages/auth-web.md +3 -2
  41. package/reference/autogen/packages/database-runtime.md +8 -17
  42. package/reference/autogen/packages/material-web.md +4 -0
  43. package/reference/autogen/tooling/config-eslint.md +8 -0
  44. package/reference/autogen/tooling/jskit-catalog.md +58 -5
  45. package/skills/jskit/SKILL.md +8 -4
  46. package/skills/jskit/references/app-operations.md +9 -0
  47. package/skills/jskit/references/client-features.md +22 -0
  48. package/skills/jskit/references/database-layer.md +67 -43
  49. package/skills/jskit/references/existing-application-migration.md +3 -1
  50. package/skills/jskit/references/heuristics/INDEX.md +2 -2
  51. package/skills/jskit/references/heuristics/client-requests.md +3 -1
  52. package/skills/jskit/references/heuristics/crud-authoring.md +10 -0
  53. package/skills/jskit/references/heuristics/placements.md +1 -0
  54. package/skills/jskit/references/heuristics/ui-testing.md +10 -7
  55. package/skills/jskit/references/pattern-index.md +36 -36
  56. package/skills/jskit/references/patterns/app/minimal-foundation/PATTERN.md +2 -0
  57. package/skills/jskit/references/patterns/app/minimal-foundation/example/AGENTS.md +54 -101
  58. package/skills/jskit/references/patterns/app/minimal-foundation/example/gitignore +1 -1
  59. package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +3 -3
  60. package/skills/jskit/references/patterns/app/minimal-foundation/example/server/lib/loggerOptions.js +6 -3
  61. package/skills/jskit/references/patterns/app/minimal-foundation/example/server.js +1 -1
  62. package/skills/jskit/references/patterns/app/minimal-foundation/example/vite.config.mjs +3 -2
  63. package/skills/jskit/references/patterns/app/shell-foundation/PATTERN.md +2 -0
  64. package/skills/jskit/references/patterns/app/shell-foundation/example/AGENTS.md +54 -101
  65. package/skills/jskit/references/patterns/app/shell-foundation/example/gitignore +1 -1
  66. package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +4 -4
  67. package/skills/jskit/references/patterns/app/shell-foundation/example/server/lib/loggerOptions.js +6 -3
  68. package/skills/jskit/references/patterns/app/shell-foundation/example/server.js +1 -1
  69. package/skills/jskit/references/patterns/app/shell-foundation/example/vite.config.mjs +3 -2
  70. package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
  71. package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
  72. package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +4 -4
  73. package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +1 -1
  74. package/skills/jskit/references/patterns/database/mysql-application/PATTERN.md +6 -5
  75. package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
  76. package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
  77. package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
  78. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +2 -2
  79. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +4 -4
  80. package/skills/jskit/references/speed-pass.md +5 -93
  81. package/skills/jskit/references/test-pass.md +205 -0
  82. package/skills/jskit/references/typed-features.md +64 -1
  83. package/skills/jskit/references/ui-operations.md +43 -8
@@ -1069,7 +1069,8 @@ its own app server, and no more than the memory available holds at the peak
1069
1069
  the last run's largest app server reached.**
1070
1070
 
1071
1071
  - The budget is `V64_TEST_CONCURRENCY` when it is a positive whole number (a
1072
- test runner that hands out slots exports it for each run), otherwise half of
1072
+ host's variable, not JSKIT's: the budget a host or test runner sets for the
1073
+ machine's test slots, read when set), otherwise half of
1073
1074
  the CPUs the process may use, rounded down and at least 1: a 2-vCPU VPS runs
1074
1075
  one file at a time, an 8-thread machine four, and a container or slice whose
1075
1076
  cgroup `cpu.max` quota gives it 3 CPUs of a 16-thread machine one
@@ -1134,6 +1135,17 @@ the last run's largest app server reached.**
1134
1135
  `// jskit-test: alone - <reason>`. `jskit test` runs it after the others,
1135
1136
  one such file at a time, and fails on a marker without a reason or below the
1136
1137
  first line.
1138
+ - Tests never reach an outside service, even when a developer's real keys sit
1139
+ in the environment they inherit. Every Node process `jskit test` and the
1140
+ browser test servers start, and every one those start, connects only to
1141
+ loopback, `localhost`, unix sockets and the database host the environment
1142
+ names (`DB_HOST`, `DATABASE_URL`); any other connection fails before its
1143
+ name is looked up, with `JSKIT_TEST_NETWORK_REFUSED` naming the host. Stub
1144
+ the service at the seam the app already uses: an injected client or provider
1145
+ double, or a test-only env value pointing at a local fake. A test file that
1146
+ must reach one says why on its first line,
1147
+ `// jskit-test: network - <reason>`, and `jskit test` runs it without the
1148
+ guard, after the others; a marker without a reason fails the run.
1137
1149
  - `jskit test` ends with its 10 slowest test files and tests, records each
1138
1150
  file's time in `node_modules/.cache/jskit-test/file-times.json`, and fails
1139
1151
  when a file takes more than 10 minutes or the whole command more than 45:
@@ -1408,6 +1420,7 @@ that must run alone says so on its own first line instead.
1408
1420
  | `test/playwright-isolation` | a Playwright webServer every worker shares, without `browserTestConfig()` | [Test files run in parallel](#test-files-run-in-parallel) |
1409
1421
  | `test/playwright-global-timeout` | a Playwright config without a `globalTimeout` (or `browserTestConfig()`), or with `globalTimeout: 0` | [Test files run in parallel](#test-files-run-in-parallel) |
1410
1422
  | `test/vitest-workers` | `--maxWorkers`, `--minWorkers` or `--no-file-parallelism` passed to Vitest, or its config without `maxWorkers: testConcurrency()` or with `fileParallelism: false` | [Test files run in parallel](#test-files-run-in-parallel) |
1423
+ | `test/script-files` | a script that gives `jskit test` files or globs (`jskit test --databases tests/*.test.js`), so `npm test -- <file>` runs every file and that one; drop them, as `jskit test` finds test files by node's default pattern | [Test files run in parallel](#test-files-run-in-parallel) |
1411
1424
 
1412
1425
  The rules see shapes, not intent. Feature files, owned state beyond
1413
1426
  registries, shutdown, loggers, shared action fields, strict inputs, the action
@@ -1415,6 +1428,56 @@ policy, request context, validated input, one reader per fact, routes,
1415
1428
  internal failures, swallowed failures, test doubles, tests as callers, data
1416
1429
  modules and names are checked by reading.
1417
1430
 
1431
+ ### Test-source rules
1432
+
1433
+ `jskit check` also reads an application's test files (`*.test.*`,
1434
+ `*.spec.*` and every file under a `test` or `tests` folder), its test
1435
+ scripts, its Playwright and Vitest configs, its CI workflows and its root
1436
+ Vite config, and reports what makes a test run slow, fragile or unsafe.
1437
+
1438
+ | Rule | Reports | Fix |
1439
+ | --- | --- | --- |
1440
+ | `test/fixed-sleep` | in a test file, `page.waitForTimeout(…)`, a `new Promise` that resolves on `setTimeout(…, <ms>)`, or an awaited `setTimeout`, `sleep`, `delay`, `wait` or `pause` of a number of milliseconds | wait for the condition: a web-first assertion (`await expect(locator).toBeVisible()`), `expect.poll()`, the event itself, or a fake clock (`mock.timers`, `vi.useFakeTimers()`, `page.clock`) |
1441
+ | `test/fixed-database-name` | a test script that sets `TEST_DB_NAME`, `BROWSER_TEST_DB_NAME` or `DB_NAME`; a test file or runner config that falls back to or assigns a name for one (`process.env.TEST_DB_NAME \|\| "shop_test"`); a runner config that names one (`DB_NAME: "shop_e2e"`) | drop the name: the run's test-only env file or the host names the database, `jskit test --databases` gives each test file its own copy of `TEST_DB_NAME`, and `browserTestConfig()`'s `prepare` module derives each worker's from `BROWSER_TEST_DB_NAME` |
1442
+ | `test/test-database-is-app-database` | a CI workflow whose `TEST_DB_NAME` or `BROWSER_TEST_DB_NAME` is its `DB_NAME`, by value or as an `env.DB_NAME` expression | give it a name of its own, such as `<DB_NAME>_test`: a test run replaces its test databases from the snapshot, and JSKIT refuses to run one on `DB_NAME` |
1443
+ | `test/generated-into-src` | a `dts` path under `src/` in the root `vite.config.*`, such as vue-router's `src/typed-router.d.ts` or a components declaration file | write it outside `src`, such as `dts: "types/typed-router.d.ts"`, and move the file and its `.gitignore` line: a file written into `src` while the frontend builds keeps the browser tests from reusing that build (`not kept for reuse, as src changed while it ran`) |
1444
+
1445
+ A 0 ms timer yields a turn and is not reported. The one fixed wait a test
1446
+ needs is a window that proves nothing happens, such as no second read within
1447
+ it, and it says so on the line before, with its reason; a marker without a
1448
+ reason is a finding itself, and no other comment excuses these rules:
1449
+
1450
+ ```js
1451
+ // jskit-test: fixed-wait - the window in which the list must make no second read
1452
+ await page.waitForTimeout(2000);
1453
+ ```
1454
+
1455
+ Why: a fixed sleep makes every run as slow as its longest guess and fails on
1456
+ a loaded machine; a test database name in the project makes two runs wipe
1457
+ each other's rows; a test database that is the application's own is replaced
1458
+ from the snapshot; and a build that writes into its own sources is never
1459
+ reused.
1460
+
1461
+ ### Agent instructions
1462
+
1463
+ `npx jskit agents` writes JSKIT's app guidance, the guide's links and the
1464
+ rules no check enforces, in the app's `AGENTS.md`, between these markers:
1465
+
1466
+ ```md
1467
+ <!-- jskit:begin app guidance (written by npx jskit agents; edit outside this block) -->
1468
+ <!-- jskit:end app guidance -->
1469
+ ```
1470
+
1471
+ It replaces what lies between them and leaves the text outside as it is; in a
1472
+ file without them it puts the block at the top, and it makes the file when
1473
+ there is none. `npm run jskit:update` writes it after updating the packages, so
1474
+ commit `AGENTS.md` with the manifests. Write the app's own rules outside the
1475
+ block.
1476
+
1477
+ | Rule | Reports | Section |
1478
+ | --- | --- | --- |
1479
+ | `agents/jskit-block` | an app whose `package.json` declares `@jskit-ai/jskit-catalog` without that catalog's block in `AGENTS.md`, or with the block changed | [Agent instructions](#agent-instructions) |
1480
+
1418
1481
  ### Exceptions
1419
1482
 
1420
1483
  A justified exception carries a comment on the line before it, naming the
@@ -88,18 +88,53 @@ main-menu destinations show no arrow, a reload keeps the trail, and Save or
88
88
  Cancel never leaves the form in it. Find a field by its exact label:
89
89
  `page.getByLabel("Email", { exact: true })`.
90
90
 
91
- Where the host provides a managed browser runner, every Playwright suite runs
92
- through it from the first run, never through `npx playwright test`,
93
- `playwright test` or a package script such as `npm run test:e2e`. The host owns
94
- its browser and may provide `PLAYWRIGHT_STORAGE_STATE`; never print or commit
95
- that value, bypass it, or install another browser. If tests run signed out
96
- despite that state, report the host defect with evidence and stop; never
97
- rewrite its cookies or add a login.
91
+ Where the host provides a managed browser runner, such as Vibe64's, every
92
+ Playwright suite runs through it from the first run, on a declared test target:
93
+ give the runner the package script (on Vibe64,
94
+ `vibe64-helper playwright --target test-app npm-run test:e2e`), and never start
95
+ `npx playwright test`, `playwright test` or `npm run test:e2e` yourself. Specs
96
+ that write run only on a test target with its own database, never on the
97
+ person's development target or database. The host owns its browser and may
98
+ provide `PLAYWRIGHT_STORAGE_STATE`; never print or commit that value, bypass
99
+ it, or install another browser. If tests run signed out despite that state,
100
+ report the host defect with evidence and stop; never rewrite its cookies or add
101
+ a login.
102
+
103
+ A test target runs `jskit browser-test-server` on the host's ports: `{workers}`
104
+ servers of the app's own `browserTestConfig()`, each with the production build,
105
+ the database its `prepare` module gives that worker and `APP_ENV=test`. Keep
106
+ `BROWSER_TEST_DB_NAME` distinct from `TEST_DB_NAME`, which the Node tests'
107
+ copies come from. A Vibe64 project declares it in `genesis/stack.md`'s
108
+ `## Outputs` (Genesis's `jskit` Stack piece writes it into a new project); one
109
+ without it adds:
110
+
111
+ ```md
112
+ ### Target `test-app`: Test Preview
113
+
114
+ - Mode: `interactive`
115
+ - Data: `test`
116
+ - Runtimes: `nodejs`
117
+ - Run `Serve on the test database`: `node_modules/.bin/jskit` `browser-test-server` `{host}` `{port}` `{workers}`
118
+
119
+ #### Presentation
120
+
121
+ - Kind: `web`
122
+ - URL path: `/`
123
+ - Ready when: `GET` `/api/health` returns `200`
124
+ ```
125
+
126
+ The build and the snapshot are reused while their sources are unchanged, so a
127
+ focused check never rebuilds them. After a change to the browser-test setup,
128
+ run the suite twice: the second run says `Frontend build unchanged, reused` and
129
+ passes the same tests.
130
+
98
131
  For explicitly enabled direct-local auth, use
99
132
  `loginAsExistingUser()` from `@jskit-ai/auth-web/test/playwright`; never expose
100
133
  the exchange secret to browser code, URLs, or client environment.
101
134
 
102
- Without a managed runner, run the narrow test directly:
135
+ Without a managed runner, `npm run test:e2e` runs the whole suite locally,
136
+ each worker on its own server, port and database; run the narrow test
137
+ directly:
103
138
 
104
139
  ```bash
105
140
  npx playwright test <test-file> -g "<changed behavior>"
@@ -56,9 +56,12 @@ apply or adapt. It does not prescribe an agent host or project orchestrator.
56
56
  - [User experience pass](/guide/framework/ux-pass): navigation, the next
57
57
  action, form defaults, where a save lands, undo and the words people read,
58
58
  each main task walked before and after
59
- - [Speed pass](/guide/framework/speed-pass): test suite time, parallel files and
60
- preparation once per run, first-load chunks, requests per screen and route
61
- times, each measured before and after
59
+ - [Speed pass](/guide/framework/speed-pass): first-load chunks, requests per
60
+ screen and route times, each measured before and after
61
+ - [Test pass](/guide/framework/test-pass): the command, file or check that
62
+ proves each item of a test pass: test rules, parallel runs, per-file
63
+ databases, refused outside connections, browser tests on the built app and
64
+ what a JSKIT update breaks
62
65
  - [Sanity checks](/guide/framework/sanity-checks): JSKIT's own pitfalls, and
63
66
  the JSKIT calls that check data access, tests, a refactor, a screen or a
64
67
  deployment before calling it done
@@ -76,6 +79,38 @@ apply or adapt. It does not prescribe an agent host or project orchestrator.
76
79
  - [Embeddable assistant conversations](/guide/app-extras/assistant-conversation)
77
80
  - [Voice conversations](/guide/app-extras/assistant-voice)
78
81
 
82
+ ## Recipes
83
+
84
+ Ready prompts for what people commonly ask an app to do, each naming JSKIT's
85
+ own owners so nothing gets invented. Paste one into a session as it is. Each
86
+ says how to answer the person: propose the simple way first, then say there
87
+ are other options if you want to discuss. A study changes nothing and ends in
88
+ a plan.
89
+
90
+ - [An app people install from its website](/guide/recipes/installable-app):
91
+ use when someone wants the app on their phone, an icon, push
92
+ notifications, an unread badge or sharing into the app; a native store app
93
+ through Capacitor is the other option
94
+ - [Offline study](/guide/recipes/offline-study): use when someone wants the
95
+ app to work offline or without signal; recommends what works offline,
96
+ section by section
97
+ - [Usefulness study](/guide/recipes/usefulness-study): use when someone asks
98
+ whether the app is any good, what is missing or what to build next; judges
99
+ value and gaps, not ease of use
100
+ - [Payments and subscriptions](/guide/recipes/payments-and-subscriptions): use
101
+ when someone wants to charge for the app, sell plans, gate features behind
102
+ a plan or sell credits
103
+ - [Inviting people with roles](/guide/recipes/invite-people-with-roles): use
104
+ when someone wants to invite their team, share records with colleagues or
105
+ give people different permissions
106
+ - [File uploads and images](/guide/recipes/file-uploads-and-images): use when
107
+ someone wants photos, documents or other files attached to records
108
+ - [Reminders and digests](/guide/recipes/reminders-and-digests): use when
109
+ someone wants reminders, scheduled emails or a daily or weekly summary sent
110
+ to people
111
+ - [Another language](/guide/recipes/another-language): use when someone wants
112
+ the app translated or available in more than one language
113
+
79
114
  ## How to use the guide
80
115
 
81
116
  Begin with the Quickstart and one application-foundation pattern. Add only the
@@ -89,4 +124,5 @@ documents and examples, but no agent host is required to install it.
89
124
  There are no source-generator chapters. Package-owned patterns replace their
90
125
  useful source examples; questionnaire, mutation, and provenance machinery is
91
126
  not part of JSKIT. The supported `jskit update` and `jskit check` commands own
92
- only dependency manifests and lockfile conformance.
127
+ only dependency manifests, lockfile conformance and the JSKIT block of the
128
+ app's `AGENTS.md`.
@@ -0,0 +1,129 @@
1
+ <!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/another-language.md`. Do not edit manually. -->
2
+
3
+ ---
4
+ title: "Recipe: another language"
5
+ description: Make a JSKIT app available in another language, with JSKIT's own texts from one exported catalog, the app's texts as message keys, and the person's saved language followed.
6
+ ---
7
+
8
+ # Make `<APP_NAME>` available in another language
9
+
10
+ People use `<APP_NAME>` in their own language: every screen, button, message,
11
+ error, email, date and number, chosen in their account settings and kept from
12
+ then on. JSKIT's own screens come translated from one exported catalog per
13
+ language; the app's own texts become message keys; English stays the fallback,
14
+ so a text not yet translated still reads well.
15
+
16
+ ## When to propose it
17
+
18
+ - "In Italian", "in Spanish too", "translate the app", "multi-language",
19
+ "localise it".
20
+ - "Our users don't speak English", "a version for another country".
21
+ - "Dates and prices look wrong for our customers."
22
+
23
+ ## How to answer the person
24
+
25
+ Propose the simple way first: "We add the language to the app: JSKIT's own
26
+ screens come translated from one file we fill in, the app's own texts move into
27
+ message files, and each person picks their language in their account settings.
28
+ I draft the translation; someone who speaks the language should read it before
29
+ it goes live."
30
+
31
+ Then say: "There are other options if you want to discuss." They are
32
+ translating what people write in the app (machine translation, the app's own
33
+ work), right-to-left languages, a language per workspace rather than per
34
+ person, and a translation service that manages the files with translators.
35
+
36
+ ## Product decisions (defaults)
37
+
38
+ - Languages: English plus the one asked for, listed in `config.languages`
39
+ with their BCP 47 codes and names in their own language.
40
+ - The signed-in person's saved language wins; signed out, the browser's
41
+ language if the app has it, else English.
42
+ - Dates, times and numbers follow the person's language.
43
+ - The agent drafts every translation; a native speaker reviews it before
44
+ production.
45
+ - Content the app ships as data (template names, catalogue items) is
46
+ translated too; what people write is not.
47
+
48
+ ## Make a careful saved plan first
49
+
50
+ Write a careful saved plan first, then implement it item by item, proving each
51
+ one:
52
+
53
+ 1. Install `vue-i18n` and pass the app's instance to the client bootstrap.
54
+ 2. Export JSKIT's catalog for the language, translate it, and check it.
55
+ 3. Move every text of the app's own (pages, components, placements, copied
56
+ pattern files, refusal messages, emails, `index.html`'s startup text) into
57
+ message keys with English and the new language.
58
+ 4. Follow the person's saved language; offer the languages in account
59
+ preferences.
60
+ 5. Translate Vuetify's own texts.
61
+ 6. Translate content the app ships as data.
62
+ 7. Format dates and numbers through JSKIT's helpers.
63
+ 8. Add the catalog check to verification.
64
+
65
+ ## Technical details
66
+
67
+ - **Read first:** [Translating a JSKIT app](/guide/framework/translation)
68
+ completely.
69
+ - **The instance:** `createI18n()` from `vue-i18n` with `legacy: false`,
70
+ `locale: "en"`, `fallbackLocale: "en"` and the messages, passed to
71
+ `bootstrapClientShellApp({ ..., i18n })` from `@jskit-ai/kernel/client`;
72
+ JSKIT merges every installed package's English into it and refuses a legacy
73
+ instance ([Pass the app's vue-i18n instance](/guide/framework/translation#pass-the-app-s-vue-i18n-instance)).
74
+ - **JSKIT's texts:** `npx jskit i18n export <code>` writes
75
+ `src/locales/<code>/jskit.json`; translate its values keeping every
76
+ `{placeholder}` and plural choice; `npx jskit i18n check <code>` fails on
77
+ missing keys, invalid messages and placeholder mismatches, so it runs in
78
+ verification ([Add a language](/guide/framework/translation#add-a-language)).
79
+ - **The app's texts:** through `useJskitText()` and the app's own keys; a
80
+ placement `label` may be a key or `{ key, fallback }`
81
+ ([Placement labels](/guide/framework/translation#placement-labels)). An app
82
+ that wants raw template text caught can add `@intlify/eslint-plugin-vue-i18n`'s
83
+ `no-raw-text` rule to its own `eslint.config.mjs`, as JSKIT's repository
84
+ does for its client code.
85
+ - **Refusals:** the server sends a `code` and `params` with the English
86
+ `message` and the client renders the code in the person's language, so
87
+ every refusal of the app's own carries its own code with a message in the
88
+ catalog
89
+ ([Refusals carry their own code](/guide/framework/typed-features#refusals-carry-their-own-code),
90
+ [How errors are shown](/guide/framework/translation#how-errors-are-shown)).
91
+ - **The saved language:** `config.languages` in `config/public.js` lists the
92
+ choices in account preferences; `useAccountLocale()` from
93
+ `@jskit-ai/users-web/client` is the saved locale, which the app follows with
94
+ a `watch` that sets `i18n.global.locale.value` through its own
95
+ `pickSupportedLocale`. Signed out, the app picks from `navigator.languages`
96
+ the same way ([Use the user's saved language](/guide/framework/translation#use-the-user-s-saved-language)).
97
+ - **Data and emails:** shipped content stores message keys shown with
98
+ `text()` ([Content the app ships as data](/guide/framework/translation#content-the-app-ships-as-data));
99
+ emails render with `createServerI18n` in the recipient's saved locale
100
+ ([Emails](/guide/framework/translation#emails)).
101
+ - **Formats:** `formatDate`, `formatTime`, `formatDateTime`, `formatNumber`
102
+ and `formatRelativeTime` from `useJskitText()`
103
+ ([Dates and numbers](/guide/framework/translation#dates-and-numbers)).
104
+ - **Vuetify and the startup page:** Vuetify's texts through its locale
105
+ options or `createVueI18nAdapter`; `index.html`'s startup text is the app's
106
+ ([What the app translates itself](/guide/framework/translation#what-the-app-translates-itself)).
107
+
108
+ ## Proof
109
+
110
+ Prove each behaviour at the cheapest level, never against development data
111
+ and never through a translation service.
112
+
113
+ - `npx jskit i18n check <code>` passes.
114
+ - **Client tests:** a placement label key and a refusal code render in the
115
+ new language.
116
+ - **Server tests:** an email of the app's renders in the recipient's saved
117
+ language and time zone; a refusal carries its code.
118
+ - **Browser tests** (`npm run test:e2e`): with a pseudo-locale (every value
119
+ marked, exported with `jskit i18n export` as JSKIT's own browser test does),
120
+ the app's main screens show no unmarked English; a person saves the language
121
+ in account preferences and the app switches at once and after a reload; the
122
+ sign-in, settings and a main task in the new language at 390 and 1280 px,
123
+ where longer words must not break the layout.
124
+
125
+ ## Leftovers for the person
126
+
127
+ - A native speaker's review of the translation, and of legal pages and
128
+ emails.
129
+ - Prices and currencies per country, if they change with the language.
@@ -0,0 +1,125 @@
1
+ <!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/file-uploads-and-images.md`. Do not edit manually. -->
2
+
3
+ ---
4
+ title: "Recipe: file uploads and images"
5
+ description: Let people attach photos and files to records in a JSKIT app, edited and compressed in the browser, stored through runtime.storage and served only to people allowed to see them.
6
+ ---
7
+
8
+ # Let people add photos and files to `<APP_NAME>`
9
+
10
+ People attach photos and files to the records they work on. A photo is cropped
11
+ and compressed in the browser before it uploads; every file is checked by its
12
+ real bytes and size, stored in the app's storage (a folder on one server, a
13
+ bucket when there are several), shown or downloaded only by people allowed to
14
+ see its record, and removed with it. Every refusal says what was wrong.
15
+
16
+ ## When to propose it
17
+
18
+ - "Upload photos", "attach files", "add documents", "receipts", "a picture
19
+ for each product".
20
+ - "Profile pictures" beyond the account's avatar, "a gallery".
21
+ - "Where do the files go when we have two servers?"
22
+
23
+ ## How to answer the person
24
+
25
+ Propose the simple way first: "People pick a photo or file on the record; a
26
+ photo can be cropped and is made smaller before it uploads. The files live in
27
+ the app's own storage, a folder on the server today and a storage bucket once
28
+ the app runs on more than one server, and only people who can see the record
29
+ can open them."
30
+
31
+ Then say: "There are other options if you want to discuss." They are uploads
32
+ straight from the browser to a bucket with short-lived signed addresses for
33
+ very large files (app-owned; JSKIT has no piece for it), an image service or
34
+ CDN that makes sizes on the fly, and video, which needs its own processing.
35
+
36
+ ## Product decisions (defaults)
37
+
38
+ - What attaches to what: files on the app's main record; photos only
39
+ (JPEG, PNG, WebP) unless documents are asked for, then PDF too.
40
+ - Size: 5 MB a photo (`DEFAULT_IMAGE_UPLOAD_MAX_BYTES`), 10 MB a document;
41
+ at most 10 files a record.
42
+ - Who sees: whoever may see the record; who deletes: its author and those who
43
+ may edit the record.
44
+ - Photos are edited (crop, rotate) and compressed before upload.
45
+ - A file goes when its record goes.
46
+
47
+ ## Make a careful saved plan first
48
+
49
+ Write a careful saved plan first, then implement it item by item, proving each
50
+ one:
51
+
52
+ 1. Choose the storage driver per environment: `fs` on one server, `s3` where
53
+ copies run on more than one.
54
+ 2. Add an attachments table resource holding each file's storage key and
55
+ facts, never its bytes.
56
+ 3. Add the upload route and its action: read the multipart file, check its
57
+ size and real type, save it under a key the server makes, write the row.
58
+ 4. Add the read route that checks access before sending the bytes, and the
59
+ delete action; remove files with their record.
60
+ 5. Add the upload control: the image runtime for photos, a file input for
61
+ documents.
62
+ 6. Word every refusal (too large, wrong type, too many) and the empty state.
63
+
64
+ ## Technical details
65
+
66
+ - **Storage:** `@jskit-ai/storage-runtime` provides `runtime.storage`; the
67
+ driver is `JSKIT_STORAGE_DRIVER` (`fs` by default, `s3` with the
68
+ `JSKIT_STORAGE_S3_*` settings), and copies on several servers share files
69
+ only through `s3`
70
+ ([Run on more than one server, Files](/guide/app-setup/more-than-one-server#files)).
71
+ - **The table:** a file people upload goes to storage and the table keeps its
72
+ key; a `blob` field is only for a few bytes the record itself needs
73
+ ([Layer 1](/guide/framework/data-access#layer-1-the-table-resource)). The
74
+ attachments table resource has the record's ownership, the record id, the
75
+ storage key, the original name, the detected type, the size and the author.
76
+ - **Upload:** a feature requiring `runtime.uploads` (from
77
+ `@jskit-ai/uploads-runtime`, whose provider registers multipart support) and
78
+ `runtime.storage`. Its route reads the file with
79
+ `uploads.readSingleMultipartFile(request, options)` (`fieldName`,
80
+ `required`, `label`, `maxBytes`) and runs an action with the stream; the
81
+ action reads it with `readUploadBuffer(stream, { maxBytes, fieldName, label })`,
82
+ checks the real bytes with `detectCommonMimeTypeFromBuffer` and
83
+ `validateUploadMimeType(mimeType, policy, { fieldName, label })`, and saves
84
+ with `saveFile({ storageKey, buffer })` of
85
+ `createUploadStorageService({ storage })`. The server makes the key from the owner, the record and a random
86
+ id, never from the file's name. users-core's avatar upload
87
+ (`/api/settings/profile/avatar`) is the working example to follow.
88
+ - **Read and delete:** a `GET` route runs an action that reads the
89
+ attachment through its handle in the request's context, so a file of a
90
+ record the caller can't see answers 404 like a missing one; it sends the
91
+ bytes from `readFile(storageKey)` with the stored type, as an attachment
92
+ for anything but images. Deleting the row and the file happen in one action;
93
+ remove the file after the row's transaction commits.
94
+ - **Client, photos:** `createManagedImageAssetRuntime` (or
95
+ `createImageUploadRuntime`) from `@jskit-ai/uploads-image-web`, with
96
+ `allowedMimeTypes`, `maxUploadBytes` and `resolveRequestHeaders` sending the
97
+ session's `csrf-token`, as users-web's account avatar does.
98
+ - **Client, documents:** a file input whose `FormData` goes through the app's
99
+ JSKIT HTTP client, which sends a `FormData` body as it is; the list of
100
+ attachments is an ordinary `useList()` or CRUD list.
101
+ - **Refusals** carry their field error from `buildUploadFieldError`, shown
102
+ beside the control; a lost connection is reported through JSKIT's request
103
+ recovery.
104
+
105
+ ## Proof
106
+
107
+ Prove each behaviour at the cheapest level, never against development data
108
+ and never against a real bucket: tests use `JSKIT_STORAGE_DRIVER=memory`.
109
+
110
+ - **Server tests** (`jskit test`, on `TEST_DB_NAME`, through `app.inject`):
111
+ upload, read and delete as the author; a reader without access gets 404;
112
+ too large and wrong-type files refused with their field error, a file whose
113
+ name says `.jpg` but whose bytes are not refused; a key from a crafted name
114
+ cannot leave its folder; the file goes with its record; listing a record's
115
+ attachments takes the same number of queries at 3 and 300 files
116
+ (`expectFlatQueries()`).
117
+ - **Client tests:** the upload control's states (pending, refused, done).
118
+ - **Browser tests** (`npm run test:e2e`): attach a photo with
119
+ `setInputFiles`, crop it, see it on the record; at 390 and 1280 px.
120
+
121
+ ## Leftovers for the person
122
+
123
+ - The bucket and its access key for staging and production when the app runs
124
+ on more than one server.
125
+ - Uploading real photos from their own phones.