@jskit-ai/agent-docs 0.1.364 → 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.
- package/guide/agent/app-extras/mobile-capacitor.md +5 -0
- package/guide/agent/app-setup/authentication.md +10 -8
- package/guide/agent/app-setup/database-layer.md +51 -39
- package/guide/agent/app-setup/existing-application-migration.md +3 -1
- package/guide/agent/app-setup/upgrading-jskit.md +13 -3
- package/guide/agent/framework/application-operations.md +9 -0
- package/guide/agent/framework/client-features.md +22 -0
- package/guide/agent/framework/speed-pass.md +6 -94
- package/guide/agent/framework/test-pass.md +210 -0
- package/guide/agent/framework/typed-features.md +64 -1
- package/guide/agent/framework/ui-operations.md +43 -8
- package/guide/agent/index.md +40 -4
- package/guide/agent/recipes/another-language.md +129 -0
- package/guide/agent/recipes/file-uploads-and-images.md +125 -0
- package/guide/agent/recipes/installable-app.md +383 -0
- package/guide/agent/recipes/invite-people-with-roles.md +142 -0
- package/guide/agent/recipes/offline-study.md +163 -0
- package/guide/agent/recipes/payments-and-subscriptions.md +156 -0
- package/guide/agent/recipes/reminders-and-digests.md +153 -0
- package/guide/agent/recipes/usefulness-study.md +137 -0
- package/package.json +1 -1
- package/patterns/minimal-foundation/PATTERN.md +2 -0
- package/patterns/minimal-foundation/example/AGENTS.md +54 -101
- package/patterns/minimal-foundation/example/gitignore +1 -1
- package/patterns/minimal-foundation/example/package.json +3 -3
- package/patterns/minimal-foundation/example/server/lib/loggerOptions.js +6 -3
- package/patterns/minimal-foundation/example/server.js +1 -1
- package/patterns/minimal-foundation/example/vite.config.mjs +3 -2
- package/patterns/shell-foundation/PATTERN.md +2 -0
- package/patterns/shell-foundation/example/AGENTS.md +54 -101
- package/patterns/shell-foundation/example/gitignore +1 -1
- package/patterns/shell-foundation/example/package.json +4 -4
- package/patterns/shell-foundation/example/server/lib/loggerOptions.js +6 -3
- package/patterns/shell-foundation/example/server.js +1 -1
- package/patterns/shell-foundation/example/vite.config.mjs +3 -2
- package/reference/autogen/PATTERN_INDEX.md +36 -36
- package/reference/autogen/packages/agent-docs.md +2 -2
- package/reference/autogen/packages/assistant-runtime.md +4 -0
- package/reference/autogen/packages/auth-provider-local-core.md +1 -0
- package/reference/autogen/packages/auth-web.md +3 -2
- package/reference/autogen/packages/database-runtime.md +5 -17
- package/reference/autogen/packages/material-web.md +4 -0
- package/reference/autogen/tooling/config-eslint.md +8 -0
- package/reference/autogen/tooling/jskit-catalog.md +58 -5
- package/skills/jskit/SKILL.md +8 -4
- package/skills/jskit/references/app-operations.md +9 -0
- package/skills/jskit/references/client-features.md +22 -0
- package/skills/jskit/references/database-layer.md +51 -39
- package/skills/jskit/references/existing-application-migration.md +3 -1
- package/skills/jskit/references/heuristics/INDEX.md +2 -2
- package/skills/jskit/references/heuristics/client-requests.md +3 -1
- package/skills/jskit/references/heuristics/crud-authoring.md +10 -0
- package/skills/jskit/references/heuristics/placements.md +1 -0
- package/skills/jskit/references/heuristics/ui-testing.md +10 -7
- package/skills/jskit/references/pattern-index.md +36 -36
- package/skills/jskit/references/patterns/app/minimal-foundation/PATTERN.md +2 -0
- package/skills/jskit/references/patterns/app/minimal-foundation/example/AGENTS.md +54 -101
- package/skills/jskit/references/patterns/app/minimal-foundation/example/gitignore +1 -1
- package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +3 -3
- package/skills/jskit/references/patterns/app/minimal-foundation/example/server/lib/loggerOptions.js +6 -3
- package/skills/jskit/references/patterns/app/minimal-foundation/example/server.js +1 -1
- package/skills/jskit/references/patterns/app/minimal-foundation/example/vite.config.mjs +3 -2
- package/skills/jskit/references/patterns/app/shell-foundation/PATTERN.md +2 -0
- package/skills/jskit/references/patterns/app/shell-foundation/example/AGENTS.md +54 -101
- package/skills/jskit/references/patterns/app/shell-foundation/example/gitignore +1 -1
- package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +4 -4
- package/skills/jskit/references/patterns/app/shell-foundation/example/server/lib/loggerOptions.js +6 -3
- package/skills/jskit/references/patterns/app/shell-foundation/example/server.js +1 -1
- package/skills/jskit/references/patterns/app/shell-foundation/example/vite.config.mjs +3 -2
- package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
- package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +4 -4
- package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +1 -1
- package/skills/jskit/references/patterns/database/mysql-application/PATTERN.md +6 -5
- package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +2 -2
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +4 -4
- package/skills/jskit/references/speed-pass.md +5 -93
- package/skills/jskit/references/test-pass.md +205 -0
- package/skills/jskit/references/typed-features.md +64 -1
- package/skills/jskit/references/ui-operations.md +43 -8
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/installable-app.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Recipe: an app people install from its website"
|
|
5
|
+
description: Make a JSKIT app installable from its own website on Android, iPhone, iPad and computers, with push notifications, an unread count on its icon and sharing in, and no app store.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Make `<APP_NAME>` an app people install from its website: no app stores, real notifications, sharing in
|
|
9
|
+
|
|
10
|
+
Turn this JSKIT app into an installable web app (PWA) on Android, iPhone/iPad
|
|
11
|
+
and desktop. It opens from its own icon, full screen, starts instantly, works
|
|
12
|
+
gracefully offline, sends push notifications even when closed, shows an unread
|
|
13
|
+
count on its icon, and (on Android and desktop) accepts photos, files and links
|
|
14
|
+
shared from other apps. Payments, if any, stay exactly as they are today.
|
|
15
|
+
|
|
16
|
+
## When to propose it
|
|
17
|
+
|
|
18
|
+
- "Make it an app", "put it on my phone", "an icon on the home screen", "can
|
|
19
|
+
people install it?", "we need a mobile app".
|
|
20
|
+
- "Send notifications", "tell people when something happens even when the app
|
|
21
|
+
is closed", "a badge with the unread count".
|
|
22
|
+
- "Share a photo from my gallery into the app".
|
|
23
|
+
|
|
24
|
+
## How to answer the person
|
|
25
|
+
|
|
26
|
+
Propose the simple way first: people install `<APP_NAME>` from its own
|
|
27
|
+
website. On Android and computers the browser offers **Install**; on iPhone and
|
|
28
|
+
iPad they add it to the Home Screen once. It gets its own icon and window,
|
|
29
|
+
notifications (on iPhone and iPad once it is on the Home Screen), an unread
|
|
30
|
+
count on the icon, and sharing in from other apps (Android and computers). There
|
|
31
|
+
is no store account, review or fee, every release reaches everyone at once, and
|
|
32
|
+
it is the same app the website already is.
|
|
33
|
+
|
|
34
|
+
Then say: "There are other options if you want to discuss." The other option is
|
|
35
|
+
a native app in the stores, built with Capacitor: the host's `## Packaging`
|
|
36
|
+
section builds the Android shell where the host packages phone apps itself,
|
|
37
|
+
otherwise the app owns its Android project as
|
|
38
|
+
[Mobile Capacitor](/guide/app-extras/mobile-capacitor) shows. It needs store
|
|
39
|
+
developer accounts, store listings, review and signing keys, and it is worth it
|
|
40
|
+
when the person needs a store presence or a capability only a native shell has.
|
|
41
|
+
The installable app is usually the first step either way.
|
|
42
|
+
|
|
43
|
+
## Product decisions (defaults)
|
|
44
|
+
|
|
45
|
+
Use these unless one clearly doesn't fit this app; ask only then.
|
|
46
|
+
|
|
47
|
+
- Notifications are on for all three kinds once someone allows them, with a
|
|
48
|
+
switch per kind: **results** (background work finished), **waiting** (the
|
|
49
|
+
app needs the person's answer or approval), **messages** (a direct message, a
|
|
50
|
+
mention, a message in a chat that concerns them). Message text is shown
|
|
51
|
+
unless switched off. Quiet hours are off by default. An app without one of
|
|
52
|
+
these kinds leaves it out.
|
|
53
|
+
- A notification waits **15 seconds** and is sent only if the message is still
|
|
54
|
+
unread then, so nothing pops up for a chat the person is reading.
|
|
55
|
+
- Real pushes leave **only when `APP_ENV=production`**; development, test and
|
|
56
|
+
staging log each one with `logSideEffect`
|
|
57
|
+
([Environments](/guide/framework/environments#the-application-s-own-side-effects)).
|
|
58
|
+
A **Send a test notification** button shows one on the device itself,
|
|
59
|
+
everywhere.
|
|
60
|
+
- Permission is never asked on first visit: only from Settings, or from a
|
|
61
|
+
one-time offer right after the person sets up their first piece of
|
|
62
|
+
background work ("Get a notification when it runs?" **Turn on** /
|
|
63
|
+
**Not now**).
|
|
64
|
+
|
|
65
|
+
## Make a careful saved plan first
|
|
66
|
+
|
|
67
|
+
Write a careful saved plan first (this checklist and very detailed Technical
|
|
68
|
+
details), then implement it item by item, proving each one. Before writing
|
|
69
|
+
anything, map this app's own equivalents of the concepts below: what a "chat"
|
|
70
|
+
or "conversation" is, how unread is tracked, how mute works, what background
|
|
71
|
+
work produces results (routines, jobs, watches), what "waiting for the person"
|
|
72
|
+
means (approvals, questions), who a message concerns, and where Settings
|
|
73
|
+
lives. Use the app's existing owners, seams and patterns for each; never build
|
|
74
|
+
a parallel system. Read JSKIT's
|
|
75
|
+
[Typed features](/guide/framework/typed-features),
|
|
76
|
+
[Client features](/guide/framework/client-features),
|
|
77
|
+
[Data access](/guide/framework/data-access) and
|
|
78
|
+
[Material 3](/guide/framework/material-3) guides before writing server,
|
|
79
|
+
client, data or UI code.
|
|
80
|
+
|
|
81
|
+
Each item is proven before it is ticked:
|
|
82
|
+
|
|
83
|
+
1. Installable: web-app manifest, icons (any, maskable for Android's adaptive
|
|
84
|
+
shape, 180px apple-touch-icon, monochrome badge), light and dark theme
|
|
85
|
+
colours, a standalone window that focuses the one already open, 3 app
|
|
86
|
+
shortcuts to the app's most useful places, store-style screenshots for
|
|
87
|
+
Android's install sheet.
|
|
88
|
+
2. Service worker: instant start, a friendly "You're offline" page instead of
|
|
89
|
+
the browser's error, never caches anything private or the API, a new
|
|
90
|
+
release takes over cleanly.
|
|
91
|
+
3. Installing is offered where it helps: **Install app** in the account menu
|
|
92
|
+
(only when installing is possible), a one-time banner on phones, an
|
|
93
|
+
iPhone/iPad guide (Share → Add to Home Screen), nothing once installed.
|
|
94
|
+
4. Feels native: safe areas around notches and home bars, status bar coloured
|
|
95
|
+
to match the theme, no stray pull-to-refresh or double-tap zoom, outside
|
|
96
|
+
links open in the browser, every sign-in method works inside the installed
|
|
97
|
+
app.
|
|
98
|
+
5. Push notifications for the three kinds; each opens the right chat; one
|
|
99
|
+
notification per chat (newer replaces older); the icon shows the unread
|
|
100
|
+
count.
|
|
101
|
+
6. Settings: allow on this device, a switch per kind, show or hide message
|
|
102
|
+
text, quiet hours, the person's devices (each removable), **Send a test
|
|
103
|
+
notification**. Muted chats never notify.
|
|
104
|
+
7. Permission asked at a sensible moment with a clear explanation; a refusal
|
|
105
|
+
is handled kindly (how to re-allow in browser or phone settings); an iPhone
|
|
106
|
+
outside the Home Screen app is told to add it first, with the guide.
|
|
107
|
+
8. Sharing in (Android and desktop): share a photo, file or link from another
|
|
108
|
+
app, pick a chat, and it arrives attached in that chat's message box.
|
|
109
|
+
9. The website's "get the mobile app" places (if any) become one real install
|
|
110
|
+
page for the person's device; store placeholders go; old addresses
|
|
111
|
+
redirect; help pages explain installing, notifications and sharing.
|
|
112
|
+
10. Proven: server tests, client tests, browser tests and preview checks as
|
|
113
|
+
Proof describes.
|
|
114
|
+
|
|
115
|
+
After the plan, where the project runs Genesis passes, run the Review,
|
|
116
|
+
Security pass, Data pass, Quality pass and Deslop, each on this plan's
|
|
117
|
+
changes.
|
|
118
|
+
|
|
119
|
+
## Technical details
|
|
120
|
+
|
|
121
|
+
JSKIT has no installable-app, service-worker or push package. Everything below
|
|
122
|
+
that this page does not name as JSKIT's is the app's own code, built on the
|
|
123
|
+
JSKIT owners it links.
|
|
124
|
+
|
|
125
|
+
### 1. Manifest and icons
|
|
126
|
+
|
|
127
|
+
- Draw the icons from the app's logo (`src/components/BrandLogo.vue` and
|
|
128
|
+
`favicon.svg`, as [Visual identity](/guide/framework/visual-identity) places
|
|
129
|
+
them) and commit them as files in Vite's `public/` folder, which the build
|
|
130
|
+
copies to `dist/` unchanged: 192 and 512 `any`, 512 `maskable` (the logo
|
|
131
|
+
inside the 80% safe zone on the brand colour), 180 `apple-touch-icon`, 96
|
|
132
|
+
monochrome badge. ImageMagick renders them from the SVG.
|
|
133
|
+
- `public/manifest.webmanifest`: `id: "/"`, `start_url` and `scope` `/`,
|
|
134
|
+
name and short_name, `display: "standalone"`,
|
|
135
|
+
`launch_handler.client_mode: "focus-existing"`, background and theme colours
|
|
136
|
+
matching the startup shell in `index.html`, shortcuts, `share_target`
|
|
137
|
+
(section 6) and committed phone and desktop screenshots. An app served under
|
|
138
|
+
a sub-path puts that path in every URL the manifest holds.
|
|
139
|
+
- Each shortcut opens an in-app page address. Signed out, the route's auth
|
|
140
|
+
guard sends the person to sign in with that page as `returnTo`, so they land
|
|
141
|
+
where the shortcut points. An action with no page of its own gets one, or a
|
|
142
|
+
query parameter its page reads once and removes.
|
|
143
|
+
- `index.html`: the manifest link, the apple-touch-icon,
|
|
144
|
+
`apple-mobile-web-app-capable`, a `black-translucent` status bar, light and
|
|
145
|
+
dark `theme-color` and `viewport-fit=cover` on the viewport. The status bar
|
|
146
|
+
colour follows the chosen theme at runtime.
|
|
147
|
+
- The foundation's `server.js` already lists `/manifest.webmanifest` in
|
|
148
|
+
`STATIC_GLOBAL_UI_PATHS`; add `/sw.js`, `/offline.html` and the icons' paths
|
|
149
|
+
there too.
|
|
150
|
+
|
|
151
|
+
### 2. Service worker (`/sw.js`, scope `/`, `Service-Worker-Allowed: /`)
|
|
152
|
+
|
|
153
|
+
- JSKIT installs no service worker; this one is the app's own, written by hand
|
|
154
|
+
in `public/sw.js`, and follows the rules in
|
|
155
|
+
[Development modules and service-worker caching](/guide/app-setup/initial-scaffolding#development-modules-and-service-worker-caching).
|
|
156
|
+
Register it only from a production build. The server sends `/sw.js` with
|
|
157
|
+
`Service-Worker-Allowed: /` and without long caching.
|
|
158
|
+
- Navigations go network first, falling back to a cached `offline.html` drawn
|
|
159
|
+
like the startup shell ("You're offline. `<APP_NAME>` will reconnect by
|
|
160
|
+
itself.", **Try again**). Back online, the page's first loads can still fail,
|
|
161
|
+
because the page's network and the worker's come back a moment apart. So the
|
|
162
|
+
offline page keeps retrying the page it stands in for, one attempt at a time,
|
|
163
|
+
waiting 1 s and doubling to 30 s, and reloads once it answers. **Try again**
|
|
164
|
+
tries at once in that same loop. Its own script and icon come from the
|
|
165
|
+
worker's cache.
|
|
166
|
+
- Only content-hashed build assets (`/assets/`) are cache first; old builds'
|
|
167
|
+
caches are deleted on activate. **Never** touch the API (`/api/`), event
|
|
168
|
+
streams and sockets, uploads, public or anonymous pages, or any admin or
|
|
169
|
+
console surface, and never let those fall back to the offline page. JSKIT
|
|
170
|
+
already answers every API request with `Cache-Control: no-store`
|
|
171
|
+
(`config.securityHeaders.apiCacheControl`).
|
|
172
|
+
- `skipWaiting()` and `clients.claim()`. Where `@jskit-ai/realtime` is
|
|
173
|
+
installed, JSKIT's own client update offer still asks the person to reload
|
|
174
|
+
when a new build is served
|
|
175
|
+
([Client updates](/guide/app-extras/realtime#client-updates)).
|
|
176
|
+
- A notification click may open **only the app's own pages**, never another
|
|
177
|
+
site or scheme.
|
|
178
|
+
- Browser tests that intercept scripts with `page.route` run with Playwright's
|
|
179
|
+
`test.use({ serviceWorkers: "block" })`, because the worker answers built
|
|
180
|
+
files itself.
|
|
181
|
+
|
|
182
|
+
### 3. Installing (client)
|
|
183
|
+
|
|
184
|
+
- The app's own install composable (`useInstall()`) keeps
|
|
185
|
+
`beforeinstallprompt` from the moment it fires, knows when the app is
|
|
186
|
+
installed (`display-mode: standalone`, `navigator.standalone`) and when it
|
|
187
|
+
runs in iPhone or iPad Safari. The event fires once per page, before any
|
|
188
|
+
component may exist, so its state is shared: a client provider provides it,
|
|
189
|
+
or one module-level ref with a `shared resource:` allow comment holds it
|
|
190
|
+
([Client providers](/guide/framework/client-features#client-providers),
|
|
191
|
+
[Module state](/guide/framework/client-features#module-state)). The window
|
|
192
|
+
probes go through the package's one `hasWindowFunction()` helper
|
|
193
|
+
([Platform probes](/guide/framework/client-features#platform-probes)), and
|
|
194
|
+
its listeners are released
|
|
195
|
+
([Released listeners](/guide/framework/client-features#released-listeners)).
|
|
196
|
+
- **Install app** is a link in the account menu, the `auth.profile-menu`
|
|
197
|
+
placement, shown only while installing is possible.
|
|
198
|
+
- The phone offer is JSKIT's snackbar:
|
|
199
|
+
`useShellWebErrorRuntime().report({ ..., action, additionalActions })`
|
|
200
|
+
from `@jskit-ai/shell-web/client/error`, which `@jskit-ai/material-web`
|
|
201
|
+
draws on `inverse-surface` with `inverse-primary` actions. Never restyle it;
|
|
202
|
+
a banner of the app's own uses those same roles, or **Not now** becomes
|
|
203
|
+
unreadable. Check light and dark.
|
|
204
|
+
- The phone offer comes once, a few seconds in, and **Not now** is remembered
|
|
205
|
+
per device.
|
|
206
|
+
|
|
207
|
+
### 4. Native feel
|
|
208
|
+
|
|
209
|
+
- `env(safe-area-inset-*)` on the top bar, composer, drawers and dialogs (zero
|
|
210
|
+
off a phone); `overscroll-behavior` on the shell;
|
|
211
|
+
`touch-action: manipulation`; text inputs at least 16px on iPhone so Safari
|
|
212
|
+
doesn't zoom.
|
|
213
|
+
- Every custom switch or toggle needs its own visible `:focus-visible` ring
|
|
214
|
+
(2px solid, a theme role). The browser's default is near-invisible on dark
|
|
215
|
+
schemes.
|
|
216
|
+
- In standalone mode, links outside the app's origin open in the browser
|
|
217
|
+
(`leaveApp(url)` from `@jskit-ai/shell-web/client` leaves for another site).
|
|
218
|
+
Signed out, the installed app opens on sign-in; a browser tab still shows the
|
|
219
|
+
front page.
|
|
220
|
+
|
|
221
|
+
### 5. Push notifications (server)
|
|
222
|
+
|
|
223
|
+
- **Keys:** derive the VAPID P-256 key pair from one generated secret
|
|
224
|
+
(`PUSH_SECRET`, named as the app's other settings are) with HKDF, so every
|
|
225
|
+
server agrees and there is no manual key setup. Read it from the
|
|
226
|
+
`runtime.env` capability, never a request
|
|
227
|
+
([Environment from the caller](/guide/framework/typed-features#environment-from-the-caller)).
|
|
228
|
+
Name it in the project's environment contract and `.env.example` without a
|
|
229
|
+
value; in a Genesis project add it to the Deployment's `Generated secrets`
|
|
230
|
+
beside `AUTH_LOCAL_SESSION_SECRET`, so every deployment has its own, and give
|
|
231
|
+
development a value of its own. Without it, push is off and Settings says
|
|
232
|
+
so. Use `web-push`, pinned.
|
|
233
|
+
- **Tables:** one table resource each (`defineTableResource`), owned by one
|
|
234
|
+
feature, created by an add-only Knex migration
|
|
235
|
+
([Data access, Layer 1](/guide/framework/data-access#layer-1-the-table-resource)).
|
|
236
|
+
Ownership `user` (`workspace_user` where the app has workspaces) keeps each
|
|
237
|
+
person to their own rows on every statement. In a Genesis project, put each
|
|
238
|
+
table in its owning package's subsystem.
|
|
239
|
+
- `push_devices`: user, endpoint (unique), p256dh, auth, label, created and
|
|
240
|
+
last sent, failures. At most 20 a person, the oldest going.
|
|
241
|
+
- `push_settings`: user, per-kind switches, show_text, quiet_from and
|
|
242
|
+
quiet_to, time_zone. One row a person who changed theirs.
|
|
243
|
+
- `push_queue`: workspace (or the scope unread is counted in), user, chat,
|
|
244
|
+
kind, message, send_after, claimed_at.
|
|
245
|
+
- **Queueing:** beside the code that marks messages unread, insert one queue
|
|
246
|
+
row per person the message concerns: the other person in a one-person or
|
|
247
|
+
direct chat, the mentioned people and the person the background work was for
|
|
248
|
+
in a room, never the author, never anyone who muted the chat. One
|
|
249
|
+
`createMany(rows, options)` per write, not one insert per person.
|
|
250
|
+
- **Sweep:** a feature with a `systemScope` whose `boot()` starts the timer
|
|
251
|
+
(`setInterval(runOnce, 5000).unref()`) and whose `shutdown()` stops it and
|
|
252
|
+
awaits a run in progress; tests call `runOnce()` itself. JSKIT ships no
|
|
253
|
+
scheduler ([Owned state](/guide/framework/typed-features#owned-state)).
|
|
254
|
+
Every web server runs the timer and takes due rows with
|
|
255
|
+
`claim({ filters, sort, take }, txOptions)`, which skips rows another server
|
|
256
|
+
holds ([Layer 4: locks](/guide/framework/data-access#layer-4-locks)), batch
|
|
257
|
+
after batch until a batch comes back short (at most about 20 batches): one
|
|
258
|
+
batch of 100 a tick falls minutes behind a burst of 250. Per row: skip it if
|
|
259
|
+
read, in quiet hours (across midnight, in the person's time zone) or that
|
|
260
|
+
kind is off. Fold a person's rows for one chat into one notification about
|
|
261
|
+
the newest message at the most pressing kind. Claim exact (person, chat)
|
|
262
|
+
pairs, never a capped cross-product narrowed in code
|
|
263
|
+
([Narrow in the query](/guide/framework/data-access#narrow-in-the-query)).
|
|
264
|
+
- **Queue rows carry their workspace id** to the sweep. A sweep that reads it
|
|
265
|
+
as `undefined` sends nothing at all, and a test stand-in that reads ids
|
|
266
|
+
differently from the real table resource hides it: test on the real handle on
|
|
267
|
+
`TEST_DB_NAME`
|
|
268
|
+
([Doubles use documented seams](/guide/framework/typed-features#doubles-use-documented-seams)).
|
|
269
|
+
- A direct message's title is **the other person's** name, both ways round;
|
|
270
|
+
test it with both orders of the two people's ids.
|
|
271
|
+
- Payload: chat title, kind, short text (or "New message" when text is
|
|
272
|
+
hidden), the chat's URL, the unread count (counted per person **and
|
|
273
|
+
workspace**, matching what the open app shows), tag `chat-<id>` with
|
|
274
|
+
`renotify`.
|
|
275
|
+
- Sending: 10 devices at a time, a few statements per batch whatever the
|
|
276
|
+
number of devices. A 404 or 410 forgets the device, and so do 5 consecutive
|
|
277
|
+
failures. Outside production, `logSideEffect()` with
|
|
278
|
+
`kind: "push notification"` replaces the send.
|
|
279
|
+
- **Security, all required:**
|
|
280
|
+
- A device's endpoint must be a known push service (FCM, Mozilla, Apple,
|
|
281
|
+
WNS) on its default port with no credentials, because the server POSTs
|
|
282
|
+
there. Refuse anything else with 400 (localhost, metadata IPs and internal
|
|
283
|
+
hosts must all be refused). An address stored before the check is never
|
|
284
|
+
called and is forgotten at the next send.
|
|
285
|
+
- Re-posting another person's endpoint moves the device only with that
|
|
286
|
+
device's own keys (the same browser). Otherwise 409.
|
|
287
|
+
- Non-object bodies give 400, not a 500: the kernel's body validation already
|
|
288
|
+
answers a body that is not a JSON object with 400
|
|
289
|
+
([Routes](/guide/framework/typed-features#routes)); keep it. Device labels
|
|
290
|
+
are one line, with no control characters.
|
|
291
|
+
- **Sign-out forgets this browser's device:** a signed-in
|
|
292
|
+
`POST /api/push/devices/forget { endpoint }` (a locked delete by address
|
|
293
|
+
and person), then unsubscribe in the browser, waiting at most 3 s.
|
|
294
|
+
Otherwise the next person on a shared browser gets the last person's
|
|
295
|
+
notifications. JSKIT has no step before sign-out: the app's own
|
|
296
|
+
`src/views/auth/SignOutView.vue` (from the
|
|
297
|
+
[auth surface pattern](/patterns/auth/auth-surface)) runs both steps first
|
|
298
|
+
and renders `DefaultSignOutView`, which signs out as it mounts, only after
|
|
299
|
+
them. While they run it shows a pending card ("Signing you out"); offline
|
|
300
|
+
it says so and **Try again** retries both steps.
|
|
301
|
+
- **Routes**, `auth: "required"`, each running an action on the caller's own
|
|
302
|
+
rows: get settings, devices and the public key; put settings; add device;
|
|
303
|
+
delete device; forget device. Test them through `app.inject` signed out
|
|
304
|
+
(401), without CSRF (403), as another member (404) and with malformed input
|
|
305
|
+
(400) ([Security pass](/guide/framework/security-pass#try-each-refusal)).
|
|
306
|
+
|
|
307
|
+
### 6. Sharing in
|
|
308
|
+
|
|
309
|
+
- Manifest `share_target`: `action: "/share"`, POST, multipart `title`,
|
|
310
|
+
`text`, `url`, `files`. The worker keeps them in Cache Storage under a
|
|
311
|
+
one-time key for an hour and redirects (303) to the app's share page,
|
|
312
|
+
`/share?key=<key>`.
|
|
313
|
+
- The share page opens the app's existing picker for where it goes (the chat
|
|
314
|
+
picker) and puts text and files into that chat's message box through the
|
|
315
|
+
existing upload path; over-limit files get the upload's own refusal. The
|
|
316
|
+
share goes **only** into the chosen chat. If that chat doesn't open within
|
|
317
|
+
about 2 s, the picker comes back saying "That chat didn't open. Choose it
|
|
318
|
+
again." A share that's gone says "What you shared is no longer here. Share
|
|
319
|
+
it again from the other app." Delete the cache entry once used.
|
|
320
|
+
|
|
321
|
+
### 7. Settings and permission (client)
|
|
322
|
+
|
|
323
|
+
- A **Notifications** group in the account settings, in the
|
|
324
|
+
[account settings pattern](/patterns/users/account-settings)'s notifications
|
|
325
|
+
section or a section of the app's own (an `account-settings:sections`
|
|
326
|
+
placement at `/account/<section>`), with Material skeleton rows in the card's
|
|
327
|
+
shape and `aria-busy` while it loads (not "Loading…" that jumps to nine
|
|
328
|
+
rows), and **Try again** on failure.
|
|
329
|
+
- `Notification.requestPermission()` only from those controls or the one-time
|
|
330
|
+
offer. Explain a refusal. When the server's push secret changed, replace the
|
|
331
|
+
browser's old subscription instead of reusing it. When the push service
|
|
332
|
+
doesn't answer, say why, in the same words in both places.
|
|
333
|
+
- Text comes through `useJskitText()` and the app's message keys
|
|
334
|
+
([Translation](/guide/framework/translation)).
|
|
335
|
+
|
|
336
|
+
### 8. Website and help
|
|
337
|
+
|
|
338
|
+
- One install page with the right steps per device (**Install** where the
|
|
339
|
+
browser offers it); old store addresses redirect to it. Read the headers on
|
|
340
|
+
a production build: JSKIT's content security policy
|
|
341
|
+
([Security headers](/guide/app-setup/initial-scaffolding#security-headers))
|
|
342
|
+
already allows a same-origin worker (`worker-src 'self' blob:`) and manifest
|
|
343
|
+
(`default-src 'self'`). A directive set in
|
|
344
|
+
`config.securityHeaders.contentSecurityPolicy.directives` replaces JSKIT's
|
|
345
|
+
sources for that directive, so keep `'self'` there.
|
|
346
|
+
- Help: a "`<APP_NAME>` on your phone" page (install on Android, iPhone and
|
|
347
|
+
computers; notifications; sharing), the notifications section of Settings,
|
|
348
|
+
and remove any line saying the app sends no notifications. In a Genesis
|
|
349
|
+
project, record a decision for this work and update the Blueprint, the
|
|
350
|
+
Program pages and `genesis/subsystems.md`.
|
|
351
|
+
|
|
352
|
+
## Proof
|
|
353
|
+
|
|
354
|
+
Prove each behaviour at the cheapest level that shows it, browser tests only
|
|
355
|
+
for what needs a browser, never against development data and never against a
|
|
356
|
+
real push service. Each fix is seen failing first.
|
|
357
|
+
|
|
358
|
+
- **Server tests** (`jskit test`, on `TEST_DB_NAME`): own rows only; folding
|
|
359
|
+
per chat; the 15-second read check; quiet hours across midnight in the
|
|
360
|
+
person's zone; muted chats; kinds switched off; 410 forgets a device;
|
|
361
|
+
production-only sending (a stubbed `web-push`, `APP_ENV: "production"`);
|
|
362
|
+
the endpoint allow-list and device takeover refusals; sign-out forget; the
|
|
363
|
+
direct-message title both ways round. Query counts must be **equal** at two
|
|
364
|
+
sizes with `expectFlatQueries()` from `@jskit-ai/resource-runtime/test`
|
|
365
|
+
(a sweep batch at 150 and 10,000 waiting rows, 3 and 30 devices, 5 and 41
|
|
366
|
+
recipients), not a fixed ceiling; read the sweep's plans with `EXPLAIN`
|
|
367
|
+
([Data pass](/guide/framework/data-pass#tests-at-realistic-sizes)).
|
|
368
|
+
- **Client tests** (Vitest): install state, share handling (gone, chosen,
|
|
369
|
+
chat didn't open), the sign-out sequence, settings loading.
|
|
370
|
+
- **Browser tests** (`npm run test:e2e`, `browserTestConfig()`): manifest and
|
|
371
|
+
icons, worker and offline page, Install with a synthetic
|
|
372
|
+
`beforeinstallprompt`, the iPhone guide, Settings with permission granted and
|
|
373
|
+
denied, the test notification, a notification click, sharing a file, the
|
|
374
|
+
switch focus ring (solid 2px). Stub `PushManager`, since headless Chromium
|
|
375
|
+
has no push service.
|
|
376
|
+
- **Preview:** 390 and 1280 px, light and dark, emulated standalone, on the
|
|
377
|
+
test database; walk every state above.
|
|
378
|
+
|
|
379
|
+
## Leftovers for the person
|
|
380
|
+
|
|
381
|
+
- Real installs on their own phones: notches, Safari's text-box zoom, every
|
|
382
|
+
sign-in method inside the installed app.
|
|
383
|
+
- Real pushes, after a production release.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/invite-people-with-roles.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Recipe: inviting people with roles"
|
|
5
|
+
description: Let people share a JSKIT app with their team through workspaces, email invitations and roles, with @jskit-ai/workspaces-core and @jskit-ai/workspaces-web.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Let people invite others to `<APP_NAME>` with roles
|
|
9
|
+
|
|
10
|
+
People work together in shared workspaces: an owner invites others by email
|
|
11
|
+
with a role, the invited person joins from the link (signing up if they have
|
|
12
|
+
no account), and each role decides what its members may see and do. Owners
|
|
13
|
+
manage members, change roles and withdraw invitations, and nobody reaches
|
|
14
|
+
another workspace's records.
|
|
15
|
+
|
|
16
|
+
## When to propose it
|
|
17
|
+
|
|
18
|
+
- "Invite my team", "add users", "share it with colleagues", "my staff need
|
|
19
|
+
access".
|
|
20
|
+
- "Admins and members", "roles", "permissions", "read-only users".
|
|
21
|
+
- "Teams", "organisations", "companies", "clubs" sharing the same records.
|
|
22
|
+
|
|
23
|
+
## How to answer the person
|
|
24
|
+
|
|
25
|
+
Propose the simple way first: "People get workspaces. Whoever creates one owns
|
|
26
|
+
it and invites others by email, choosing a role for each; invited people join
|
|
27
|
+
from the link. JSKIT already has the members page, the invitation page and the
|
|
28
|
+
role checks, so we choose the roles and what each may do, and move your
|
|
29
|
+
records into workspaces."
|
|
30
|
+
|
|
31
|
+
Then say: "There are other options if you want to discuss." They are sharing
|
|
32
|
+
single records with named people instead of whole workspaces (no workspace
|
|
33
|
+
machinery when one owner per record is enough), signing in through an
|
|
34
|
+
organisation's own identity provider
|
|
35
|
+
([Sign in through an OIDC issuer](/guide/app-setup/sign-in-through-oidc-issuer)),
|
|
36
|
+
and one sign-in shared by several apps
|
|
37
|
+
([Run an accounts hub](/guide/app-setup/run-an-accounts-hub)).
|
|
38
|
+
|
|
39
|
+
## Product decisions (defaults)
|
|
40
|
+
|
|
41
|
+
- Tenancy: `tenancyMode: "workspaces"` with a personal workspace for people
|
|
42
|
+
who came on their own (`autoProvision: "unless-member"`) and
|
|
43
|
+
`allowSelfCreate: true`; an invited person joins the inviting workspace
|
|
44
|
+
instead.
|
|
45
|
+
- Roles: `owner` (everything, never assignable), `admin` (members, invitations
|
|
46
|
+
and settings), `member` (the app's records), each with a display `label`;
|
|
47
|
+
the default invitation role is `member`.
|
|
48
|
+
- Only the invited address may accept, unless the person asks for any signed-in
|
|
49
|
+
account holding the link.
|
|
50
|
+
- Invitations last 7 days; the owner can withdraw one.
|
|
51
|
+
- Outside production invitation email is logged and the inviter copies the
|
|
52
|
+
link; production sends it through the app's email provider.
|
|
53
|
+
- Existing records move into their owner's personal workspace.
|
|
54
|
+
|
|
55
|
+
## Make a careful saved plan first
|
|
56
|
+
|
|
57
|
+
Write a careful saved plan first, then implement it item by item, proving each
|
|
58
|
+
one:
|
|
59
|
+
|
|
60
|
+
1. Set `tenancyMode` and `tenancyPolicy` in `config/public.js` after reading
|
|
61
|
+
[Decide the tenancy model first](/guide/app-setup/multi-homing#decide-the-tenancy-model-first),
|
|
62
|
+
and the two server settings the server refuses to start without,
|
|
63
|
+
`config.workspaceSettings.defaults.invitesEnabled` and
|
|
64
|
+
`config.workspaceMembers.defaults.inviteExpiresInMs`, in `config/server.js`
|
|
65
|
+
([Server composition](/guide/app-setup/multi-homing#server-composition)).
|
|
66
|
+
2. Install `@jskit-ai/workspaces-web` and run `npm run db:migrate`.
|
|
67
|
+
3. Add the workspace surfaces and the `workspace_member` access policy from the
|
|
68
|
+
[workspace surfaces pattern](/patterns/workspaces/workspace-surfaces).
|
|
69
|
+
4. Write the role catalog with permissions, labels, `customPermissions` and
|
|
70
|
+
`workspace.defaultInviteRole`.
|
|
71
|
+
5. Give the app's tables workspace ownership, with an add-only migration that
|
|
72
|
+
moves existing rows into their owner's workspace.
|
|
73
|
+
6. Make the app's features and routes workspace-scoped.
|
|
74
|
+
7. Provide the invitation mailer.
|
|
75
|
+
8. Gate controls in the browser by permission.
|
|
76
|
+
9. Seed the browser tests' workspaces and members.
|
|
77
|
+
|
|
78
|
+
## Technical details
|
|
79
|
+
|
|
80
|
+
- **Read first:** [Workspace tenancy](/guide/app-setup/multi-homing)
|
|
81
|
+
completely, and the [workspace server pattern](/patterns/workspaces/workspace-server).
|
|
82
|
+
- **Surfaces:** workspace pages live under `pagesRoot: "w/[workspaceSlug]"`
|
|
83
|
+
with `requiresWorkspace: true`, administration under
|
|
84
|
+
`w/[workspaceSlug]/admin`; the default surface stays free of a workspace so
|
|
85
|
+
`/` and `/invite/:token` work
|
|
86
|
+
([Surfaces and where / lands](/guide/app-setup/multi-homing#surfaces-and-where-lands)).
|
|
87
|
+
The **Your workspaces** page is `WorkspacesClientElement` from
|
|
88
|
+
`@jskit-ai/workspaces-web/client/components/WorkspacesClientElement`.
|
|
89
|
+
- **Roles:** `roleCatalog.roles.<id>.permissions` grant `crud.<namespace>.*`
|
|
90
|
+
operations, the workspace actions (`workspace.members.invite`,
|
|
91
|
+
`workspace.members.manage`, `workspace.invites.revoke`, ...) and the app's own
|
|
92
|
+
permissions listed in `roleCatalog.customPermissions`. A grant nothing
|
|
93
|
+
requires stops the server in development and test
|
|
94
|
+
([Role permissions](/guide/app-setup/multi-homing#role-permissions)); labels
|
|
95
|
+
go in `label` ([Role display labels](/guide/app-setup/multi-homing#role-display-labels)).
|
|
96
|
+
- **Data:** each table resource takes `ownership: "workspace"` (or
|
|
97
|
+
`workspace_user` for a member's own rows); the handle stamps and scopes
|
|
98
|
+
every statement from the request's context, never from input
|
|
99
|
+
([Layer 1](/guide/framework/data-access#layer-1-the-table-resource)). Jobs
|
|
100
|
+
across workspaces use `systemContext(reason).forWorkspace(id)` and
|
|
101
|
+
`workspaces.listForSystem`
|
|
102
|
+
([Background work](/guide/framework/data-access#background-work)).
|
|
103
|
+
- **Features and routes:** as
|
|
104
|
+
[Workspace-scoped features and routes](/guide/app-setup/multi-homing#workspace-scoped-features-and-routes)
|
|
105
|
+
shows; a route's `permission` is checked on the server, always.
|
|
106
|
+
- **Invitations:** who may accept is `config.workspaceInvitations`
|
|
107
|
+
(`anyAccount`) and each workspace's `invitesRequireSameEmail`
|
|
108
|
+
([Who may accept an invitation](/guide/app-setup/multi-homing#who-may-accept-an-invitation)).
|
|
109
|
+
Email goes through a `workspaces.invite-mailer` capability the app provides;
|
|
110
|
+
JSKIT has no mail transport, so the mailer is the app's own (its email
|
|
111
|
+
provider's client), and JSKIT applies `APP_ENV` to it: outside production
|
|
112
|
+
the panel reports `simulated` and shows the link to copy
|
|
113
|
+
([Invitation email](/guide/app-setup/multi-homing#invitation-email)). A
|
|
114
|
+
custom template is the `workspaces.invite-email-template` capability.
|
|
115
|
+
- **Browser:** a command names its permission with
|
|
116
|
+
`useCommand({ runPermissions })` and the control hides or disables from
|
|
117
|
+
`canRun`; the server still refuses.
|
|
118
|
+
- **Development sign-in** runs no provisioning: seed the workspaces and
|
|
119
|
+
memberships the browser tests use
|
|
120
|
+
([Development sign-in](/guide/app-setup/multi-homing#development-sign-in)).
|
|
121
|
+
|
|
122
|
+
## Proof
|
|
123
|
+
|
|
124
|
+
Prove each behaviour at the cheapest level, never against development data
|
|
125
|
+
and never through a real email service.
|
|
126
|
+
|
|
127
|
+
- **Server tests** (`jskit test`, on `TEST_DB_NAME`, through `app.inject`):
|
|
128
|
+
each role boundary (an action allowed and refused per role); another
|
|
129
|
+
workspace's records unseen and unchanged with `expectScoped()`; a slug the
|
|
130
|
+
caller is not in answers 404; invitation accept, refuse, expiry, withdrawal
|
|
131
|
+
and the wrong address (403 `workspaces.invite.emailMismatchUser`); the
|
|
132
|
+
mailer called in production with a fake transport and logged elsewhere.
|
|
133
|
+
- **Migration test:** existing rows land in their owner's workspace.
|
|
134
|
+
- **Browser tests** (`npm run test:e2e`): invite by email with a role, open the
|
|
135
|
+
link as the invited person, join, see the shared records; a member without
|
|
136
|
+
permission sees no invite control; switching workspaces keeps each one's
|
|
137
|
+
records apart; at 390 and 1280 px.
|
|
138
|
+
|
|
139
|
+
## Leftovers for the person
|
|
140
|
+
|
|
141
|
+
- The email provider account and sending domain for production invitations.
|
|
142
|
+
- Real invitations sent to real inboxes on staging or production.
|