@jskit-ai/agent-docs 0.1.364 → 0.1.366
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,163 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/offline-study.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Recipe: a study of using the app offline"
|
|
5
|
+
description: Walk the whole JSKIT app and recommend the best way to make it work offline, section by section, ending in a plan and changing nothing.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Study how `<APP_NAME>` could work offline: a recommended plan, nothing changed
|
|
9
|
+
|
|
10
|
+
Go through the whole app and recommend the best way to make it available
|
|
11
|
+
offline: which sections, what each keeps on the device, what can be edited
|
|
12
|
+
offline and synced later, how conflicts resolve, and what must stay online.
|
|
13
|
+
The study changes nothing in the code or the data. It ends in a recommended
|
|
14
|
+
plan the person can accept, trim or send back, with the smallest useful first
|
|
15
|
+
step at its top.
|
|
16
|
+
|
|
17
|
+
## When to propose it
|
|
18
|
+
|
|
19
|
+
- "Make it work offline", "it must work without signal", "in the basement, on
|
|
20
|
+
the farm, on a plane".
|
|
21
|
+
- "It breaks when the connection drops", "people lose what they typed".
|
|
22
|
+
- Before building anything offline, when the person asks for offline in
|
|
23
|
+
passing: the study decides how much is worth it.
|
|
24
|
+
|
|
25
|
+
## How to answer the person
|
|
26
|
+
|
|
27
|
+
Propose the simple way first: "I'll go through every section of
|
|
28
|
+
`<APP_NAME>` and come back with a plan, without changing anything. The simple
|
|
29
|
+
way is usually: what people last saw stays readable offline, a clear offline
|
|
30
|
+
state replaces broken screens, and only the few changes that matter offline
|
|
31
|
+
(a note, a checklist tick, a new entry) are kept on the device and sent when
|
|
32
|
+
the connection returns. Everything that needs other people's latest data
|
|
33
|
+
stays online."
|
|
34
|
+
|
|
35
|
+
Then say: "There are other options if you want to discuss." They are a full
|
|
36
|
+
offline-first app with a local database and sync for every section (much more
|
|
37
|
+
work, conflicts everywhere, storage limits on phones), or a native app in the
|
|
38
|
+
stores with device storage through Capacitor
|
|
39
|
+
([Mobile Capacitor](/guide/app-extras/mobile-capacitor)).
|
|
40
|
+
|
|
41
|
+
## Product decisions (defaults)
|
|
42
|
+
|
|
43
|
+
- Each section gets the lowest level that serves what people do there:
|
|
44
|
+
**online only** (a clear "You're offline" state, nothing lost), **read**
|
|
45
|
+
(what the person last saw), **read and add** (new entries queued),
|
|
46
|
+
**read and edit** (changes queued, each checked for conflicts when sent).
|
|
47
|
+
- The device keeps only the signed-in person's own data, for at most 14 days
|
|
48
|
+
since it was last read, and forgets it at sign-out.
|
|
49
|
+
- Conflicts: a record that changed on the server since the device read it is
|
|
50
|
+
never overwritten silently. The person sees "This record changed" with their
|
|
51
|
+
change kept beside it to apply again; new entries never conflict.
|
|
52
|
+
- Must stay online: sign-in, payments, roles, invitations and permissions,
|
|
53
|
+
anything limited by others (stock, bookings, capacity, money), sending
|
|
54
|
+
messages or email to other people, admin and console surfaces.
|
|
55
|
+
- Nothing private goes in the service worker's caches, and the API is never
|
|
56
|
+
cached by the worker; device data lives in IndexedDB, under the person's id.
|
|
57
|
+
|
|
58
|
+
## Make a careful saved plan first
|
|
59
|
+
|
|
60
|
+
The study's own plan, saved before it starts and ticked as it goes:
|
|
61
|
+
|
|
62
|
+
1. List every section: the pages under `src/pages`, the main navigation
|
|
63
|
+
placements (`shell.primary-nav`) and each page's surface.
|
|
64
|
+
2. For each section, list what it reads (`useList()`, `useView()`,
|
|
65
|
+
`useCrudList()`, `useEndpointResource()`, realtime events) and what it
|
|
66
|
+
writes (`useCommand()`, CRUD add and edit), down to the actions and table
|
|
67
|
+
resources behind them.
|
|
68
|
+
3. For each section, say who uses it, where and how often, from the
|
|
69
|
+
Blueprint (in a Genesis project) or the app's own pages and help; ask the
|
|
70
|
+
person only what nothing says.
|
|
71
|
+
4. Measure how much a person needs on the device for each section: rows and
|
|
72
|
+
bytes at a realistic size, on seeded test data (`TEST_DB_NAME`), never the
|
|
73
|
+
development database.
|
|
74
|
+
5. For each write, decide whether it can wait: does it depend on other
|
|
75
|
+
people's data at the moment it runs, is a repeat of it harmless, does its
|
|
76
|
+
record carry a version?
|
|
77
|
+
6. Walk the app offline today, in Playwright with
|
|
78
|
+
`context.setOffline(true)` against the test target, and note each blank
|
|
79
|
+
screen, lost input and misleading message.
|
|
80
|
+
7. Check sign-in, session expiry and reconnection, uploads and realtime while
|
|
81
|
+
offline.
|
|
82
|
+
8. Write the plan this page's last section describes, and save it.
|
|
83
|
+
|
|
84
|
+
## Technical details
|
|
85
|
+
|
|
86
|
+
JSKIT owns no offline store, sync engine or service worker, and the
|
|
87
|
+
foundations install no service worker. The study recommends the smallest
|
|
88
|
+
app-owned pieces, built on what JSKIT already does:
|
|
89
|
+
|
|
90
|
+
- **The app shell offline:** the installable app's service worker and offline
|
|
91
|
+
page ([installable app](/guide/recipes/installable-app), sections 1 and 2) are
|
|
92
|
+
the first step of any offline plan. Its caching rules are JSKIT's
|
|
93
|
+
([Development modules and service-worker caching](/guide/app-setup/initial-scaffolding#development-modules-and-service-worker-caching)).
|
|
94
|
+
- **What is on screen:** `@jskit-ai/http-web` keeps reads in TanStack Query
|
|
95
|
+
(`@tanstack/vue-query`), in memory. Keeping a section readable offline means
|
|
96
|
+
saving the reads that section needs to IndexedDB for this person and reading
|
|
97
|
+
them back while offline: app-owned code, sized by step 4.
|
|
98
|
+
- **When a request cannot reach the server:** `@jskit-ai/shell-web`'s request
|
|
99
|
+
recovery already offers a retry or a reload for network failures
|
|
100
|
+
(`isRecoverableRequestError`). Realtime pauses its retries while the device
|
|
101
|
+
is offline and reconnects when it is back
|
|
102
|
+
([Visible connection state](/guide/app-extras/realtime#visible-connection-state));
|
|
103
|
+
the app refreshes what it shows after reconnecting, without resending
|
|
104
|
+
changes.
|
|
105
|
+
- **Changes made offline:** an app-owned outbox in IndexedDB, replayed in
|
|
106
|
+
order through the same commands once the session is confirmed. JSKIT
|
|
107
|
+
actions declare no idempotency
|
|
108
|
+
([No idempotency](/guide/framework/typed-features#no-idempotency)), so a
|
|
109
|
+
queued create carries a key the device makes, stored in a column with a
|
|
110
|
+
unique index beside its owner, and the server writes it as an upsert that
|
|
111
|
+
ignores a repeat:
|
|
112
|
+
`createMany(rows, { ...options, onConflict: { keys, action: "ignore" } })`.
|
|
113
|
+
The key is never the record's id: `findOrCreate`
|
|
114
|
+
takes only ids the server makes
|
|
115
|
+
([Layer 3](/guide/framework/data-access#layer-3-many-rows-at-once),
|
|
116
|
+
[Layer 1](/guide/framework/data-access#layer-1-the-table-resource)).
|
|
117
|
+
- **Conflicts:** a record edited offline carries a version
|
|
118
|
+
(`lockVersionField`); a stale save answers 409
|
|
119
|
+
`crud.document.lockVersionConflict` and writes nothing, which is the
|
|
120
|
+
"This record changed" moment
|
|
121
|
+
([Layer 4: locks](/guide/framework/data-access#layer-4-locks)).
|
|
122
|
+
- **Catching up:** on PostgreSQL, a section reads what changed since the
|
|
123
|
+
device's cursor with a change stamp and `changeHorizon()`
|
|
124
|
+
([What changed since](/guide/framework/data-access#what-changed-since)); on
|
|
125
|
+
MySQL and MariaDB, which have no change horizon, it reads its bounded set
|
|
126
|
+
again.
|
|
127
|
+
- **Sign-out:** the device's data and outbox are wiped before signing out,
|
|
128
|
+
in the app's `src/views/auth/SignOutView.vue`, as the installable app does
|
|
129
|
+
for its push device.
|
|
130
|
+
- **Storage:** browsers may evict site data; the plan says what is kept,
|
|
131
|
+
whether to ask for persistent storage, and what the app shows when data was
|
|
132
|
+
evicted.
|
|
133
|
+
|
|
134
|
+
## Proof
|
|
135
|
+
|
|
136
|
+
Each finding in the plan carries its evidence: the file and line it comes
|
|
137
|
+
from, a size measured on realistic seeded test data, or a step of the offline
|
|
138
|
+
walk on the test target. Nothing runs against development data or a real
|
|
139
|
+
outside service. The study changes nothing: at its end the working tree holds
|
|
140
|
+
only the saved plan.
|
|
141
|
+
|
|
142
|
+
## The plan it ends in
|
|
143
|
+
|
|
144
|
+
A recommended plan, saved where the project keeps plans:
|
|
145
|
+
|
|
146
|
+
- A table of sections: the recommended level, what the device keeps and its
|
|
147
|
+
measured size, which writes are queued, the conflict rule, and what stays
|
|
148
|
+
online and why.
|
|
149
|
+
- The recommended first step, the smallest one that helps the most people,
|
|
150
|
+
usually the installable app's shell and offline page plus read-only
|
|
151
|
+
offline for the one or two sections people use away from a connection.
|
|
152
|
+
- The steps after it, in order, each naming the JSKIT owners above and the
|
|
153
|
+
tests that would prove it (offline walks in Playwright, conflict and repeat
|
|
154
|
+
tests on the server, query counts with `expectFlatQueries()`).
|
|
155
|
+
- The risks (storage limits, stale data shown as current, shared devices) and
|
|
156
|
+
what each step costs.
|
|
157
|
+
- What needs the person's decision.
|
|
158
|
+
|
|
159
|
+
## Leftovers for the person
|
|
160
|
+
|
|
161
|
+
- Which sections matter offline in real use, if the Blueprint doesn't say.
|
|
162
|
+
- How long data may stay on a device, and whether shared devices are common.
|
|
163
|
+
- Real phones with a weak or dropping connection, once something is built.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/payments-and-subscriptions.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Recipe: payments and subscriptions"
|
|
5
|
+
description: Let people pay for a JSKIT app with plans, hosted checkout, a billing page and features unlocked by verified provider events, through @jskit-ai/payments-core and @jskit-ai/payments-web.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Let people pay for `<APP_NAME>`: plans, subscriptions and a billing page
|
|
9
|
+
|
|
10
|
+
People choose a plan and pay on Stripe's hosted Checkout, manage or cancel
|
|
11
|
+
their subscription in Stripe's customer portal, and see their plan on a
|
|
12
|
+
billing page in `<APP_NAME>`. The app unlocks each plan's features only from
|
|
13
|
+
verified provider events, never from a redirect. Card details never reach the
|
|
14
|
+
app, and outside production only the sandbox is used.
|
|
15
|
+
|
|
16
|
+
## When to propose it
|
|
17
|
+
|
|
18
|
+
- "Charge for it", "subscriptions", "pricing plans", "a paid tier",
|
|
19
|
+
"paywall", "Stripe", "Paddle".
|
|
20
|
+
- "Credits", "pay as you go", "top up".
|
|
21
|
+
- "Only paying customers can export / invite / use X".
|
|
22
|
+
|
|
23
|
+
## How to answer the person
|
|
24
|
+
|
|
25
|
+
Propose the simple way first: "People pay on Stripe's own checkout page and
|
|
26
|
+
manage their subscription in Stripe's portal; `<APP_NAME>` shows their plan
|
|
27
|
+
and unlocks its features once Stripe confirms the payment. You set up a Stripe
|
|
28
|
+
account and keys; we start in Stripe's test mode and only production ever
|
|
29
|
+
takes real money."
|
|
30
|
+
|
|
31
|
+
Then say: "There are other options if you want to discuss." They are Paddle
|
|
32
|
+
instead of Stripe (Paddle sells as the merchant of record and handles sales
|
|
33
|
+
tax), prepaid top-ups that add credit to a balance, usage credits debited per
|
|
34
|
+
operation, and in-app purchases in store apps, which JSKIT does not cover.
|
|
35
|
+
|
|
36
|
+
## Product decisions (defaults)
|
|
37
|
+
|
|
38
|
+
- Provider: Stripe, hosted Checkout and customer portal.
|
|
39
|
+
- Who pays: the workspace in an app with workspaces, else the user.
|
|
40
|
+
- Plans: one free level with no subscription and one paid plan, monthly, in
|
|
41
|
+
one currency; each plan lists the features it unlocks and, optionally,
|
|
42
|
+
credits each renewal.
|
|
43
|
+
- Who manages billing: the workspace owner (a permission of the app's own,
|
|
44
|
+
listed in `roleCatalog.customPermissions`); any member may read the plan.
|
|
45
|
+
- A refused feature explains itself and links the billing page.
|
|
46
|
+
- Failed payments: the subscription's status comes from Stripe; features
|
|
47
|
+
follow it, and the billing page says what to do.
|
|
48
|
+
|
|
49
|
+
## Make a careful saved plan first
|
|
50
|
+
|
|
51
|
+
Write a careful saved plan first, then implement it item by item, proving each
|
|
52
|
+
one:
|
|
53
|
+
|
|
54
|
+
1. The person creates the Stripe account, a restricted key with the
|
|
55
|
+
permissions the payments-core setup guide lists, a webhook destination for
|
|
56
|
+
the events it lists, and its signing secret, in test mode first.
|
|
57
|
+
2. Declare the plans in `integrations.json` at `extensions.payments`, with the
|
|
58
|
+
`sandbox` environment's binding; keys are Env references, never values.
|
|
59
|
+
3. Install `@jskit-ai/payments-core` and `@jskit-ai/connectors-core` (and
|
|
60
|
+
`@jskit-ai/payments-web` for the billing page), run `npm run db:migrate`,
|
|
61
|
+
and register `PaymentStoreFeature`, the payment tables' one owner.
|
|
62
|
+
4. Compose the payment service, the Stripe adapter, the catalogue and the
|
|
63
|
+
checkout service in a server feature, with the app's `authorizeBilling`.
|
|
64
|
+
5. Publish the catalogue once with an administrator's preview and publish.
|
|
65
|
+
6. Routes: account, checkout, portal and history, signed in; the webhook,
|
|
66
|
+
with the request's raw bytes.
|
|
67
|
+
7. Gate each paid feature's actions with `requireFeature`.
|
|
68
|
+
8. The billing page with `PaymentAccount`, and the return page that refreshes
|
|
69
|
+
from the server.
|
|
70
|
+
9. A pricing page and help text; the refusals' words.
|
|
71
|
+
|
|
72
|
+
## Technical details
|
|
73
|
+
|
|
74
|
+
- **Read first:** the installed `@jskit-ai/payments-core/README.md`,
|
|
75
|
+
`docs/standalone.md` and `docs/contract.md`
|
|
76
|
+
([standalone setup](https://github.com/mobily-enterprises/jskit-ai/blob/main/packages/payments-core/docs/standalone.md)),
|
|
77
|
+
and `@jskit-ai/payments-web/README.md`. Compose exactly what they show;
|
|
78
|
+
never call Stripe's SDK from the app's own code for these flows.
|
|
79
|
+
- **Configuration:** `extensions.payments` in `integrations.json`, checked
|
|
80
|
+
with `validatePaymentConfiguration(document)` from
|
|
81
|
+
`@jskit-ai/payments-core/shared`. The provider API key lives in the
|
|
82
|
+
environment named by `integrations.billing.authentication.secretRef`; the
|
|
83
|
+
webhook signing secret and return URL through the binding's
|
|
84
|
+
`webhookSecretRef` and `returnUrlRef`, resolved on the server with
|
|
85
|
+
`createEnvironmentReferenceResolver` from `@jskit-ai/connectors-core/server`.
|
|
86
|
+
A missing value fails setup visibly.
|
|
87
|
+
- **Storage:** `PaymentStoreFeature` from
|
|
88
|
+
`@jskit-ai/payments-core/server/storage` provides `payments.store`; the
|
|
89
|
+
composing feature requires it. Payment tables are the package's, migrated
|
|
90
|
+
through normal discovery; the app copies none.
|
|
91
|
+
- **Composition:** `createPaymentService({ store, configuration })`,
|
|
92
|
+
`createStripePaymentAdapter({ ..., appEnv: appEnvironment(env) })`,
|
|
93
|
+
`createPaymentCatalogue({ store, adapter, scope, configuration })` and
|
|
94
|
+
`createPaymentCheckoutService()` with `adapter`, `store`, `payments`,
|
|
95
|
+
`merchantScope`, `returnUrl`, `authorize` and `appEnv`, as
|
|
96
|
+
`docs/standalone.md` shows. A live key
|
|
97
|
+
is refused outside production (`payment_live_key_refused`) and live checkout
|
|
98
|
+
is refused there (`payment_sandbox_only`)
|
|
99
|
+
([Environments](/guide/framework/environments#what-jskit-does)).
|
|
100
|
+
- **Authorization:** `authorize(actor, { subjectId, action })` returns
|
|
101
|
+
exactly `true` only for an actor allowed that action (`account`, `history`,
|
|
102
|
+
`checkout`, `portal`, `topUp`, and administrator-only `reconcile`) on that
|
|
103
|
+
subject, taken from the signed-in membership, never from a request's claim.
|
|
104
|
+
- **Catalogue:** an administrator runs `catalogue.preview()` and then
|
|
105
|
+
`catalogue.publish({ reviewId })`, from a small CLI as the setup guide's
|
|
106
|
+
"Payments from a script or CLI" shows; rebuild the composition after
|
|
107
|
+
publishing.
|
|
108
|
+
- **Routes:** `auth: "required"` routes call `checkout.account`,
|
|
109
|
+
`checkout.checkout`, `checkout.portal` and `checkout.history` with the
|
|
110
|
+
signed-in actor; each returns provider URLs to navigate to. The webhook
|
|
111
|
+
route passes the unmodified request `Buffer` to
|
|
112
|
+
`checkout.webhook({ rawBody, signature })`. JSKIT's router has no raw-body
|
|
113
|
+
option: register the webhook in a Fastify scope of its own (the
|
|
114
|
+
`runtime.fastify` capability) whose JSON parser keeps the bytes
|
|
115
|
+
(`addContentTypeParser("application/json", { parseAs: "buffer" }, ...)`),
|
|
116
|
+
and answer success only after the call completes.
|
|
117
|
+
- **Features:** an action that needs a plan calls
|
|
118
|
+
`payments.requireFeature({ ...merchantScope, subjectId }, "export")` before
|
|
119
|
+
its work; credits are debited with a stable business reference. The refusal
|
|
120
|
+
carries its own code, shown through `useJskitText()`'s `serverMessage()`
|
|
121
|
+
([Refusals carry their own code](/guide/framework/typed-features#refusals-carry-their-own-code)).
|
|
122
|
+
- **Billing page:** `PaymentAccount` from
|
|
123
|
+
`@jskit-ai/payments-web/client/components/PaymentAccount`, fed by the
|
|
124
|
+
account route, with display plans built on the server; it emits
|
|
125
|
+
`checkout`, `portal`, `refresh` and `history`. Navigate to a returned URL
|
|
126
|
+
with `openPaymentPage(url)` from
|
|
127
|
+
`@jskit-ai/payments-web/client/openPaymentPage`. The return page refreshes
|
|
128
|
+
from the server: a redirect is not proof of payment.
|
|
129
|
+
- **Top-ups**, when chosen: `topUps` in the configuration, `PaymentTopUp`, and
|
|
130
|
+
`checkout.topUp` and `checkout.confirmTopUp` with the app's own
|
|
131
|
+
`credit` function, as the README's "Prepaid top-ups" shows.
|
|
132
|
+
|
|
133
|
+
## Proof
|
|
134
|
+
|
|
135
|
+
Prove each behaviour at the cheapest level, never against development data
|
|
136
|
+
and never against Stripe itself.
|
|
137
|
+
|
|
138
|
+
- **Server tests** (`jskit test`, on `TEST_DB_NAME`): each `authorize` action
|
|
139
|
+
for owner, member and another workspace; checkout refused for a subject the
|
|
140
|
+
actor can't manage; `requireFeature` refusing without the plan and allowing
|
|
141
|
+
with it; the webhook refusing a bad signature and a parsed (not raw) body;
|
|
142
|
+
live keys refused outside production. Use a stand-in for Stripe's API
|
|
143
|
+
through the adapter's `apiBaseUrl`, which only development and test accept,
|
|
144
|
+
as payments-core's own tests do.
|
|
145
|
+
- **Client tests:** the billing page's loading, error, free, active and
|
|
146
|
+
overdue states.
|
|
147
|
+
- **Browser tests** (`npm run test:e2e`): a refused feature leads to the
|
|
148
|
+
billing page; the checkout button navigates to the URL the stubbed route
|
|
149
|
+
returns; the return page refreshes the plan.
|
|
150
|
+
|
|
151
|
+
## Leftovers for the person
|
|
152
|
+
|
|
153
|
+
- The Stripe (or Paddle) account, its restricted key, webhook destination and
|
|
154
|
+
signing secret, the customer portal's settings, and tax registration.
|
|
155
|
+
- One real test-mode payment end to end on a deployed staging app, then the
|
|
156
|
+
live keys in production only.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/reminders-and-digests.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Recipe: reminders, scheduled emails and digests"
|
|
5
|
+
description: Send reminders, scheduled emails and daily or weekly digests from a JSKIT app, each once, in the person's time zone and language, with APP_ENV deciding what really goes out.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Send reminders, scheduled emails and digests from `<APP_NAME>`
|
|
9
|
+
|
|
10
|
+
`<APP_NAME>` sends people what they need at the right time: a reminder before
|
|
11
|
+
something is due, an email the app scheduled, and a daily or weekly digest of
|
|
12
|
+
what changed. Each goes exactly once, at a sensible hour in the person's own
|
|
13
|
+
time zone and language, skips itself when there is nothing to say, and every
|
|
14
|
+
email has a one-click way to stop that kind. Outside production nothing
|
|
15
|
+
reaches anyone: development and test log each one, and staging sends only to
|
|
16
|
+
its testers' inbox.
|
|
17
|
+
|
|
18
|
+
## When to propose it
|
|
19
|
+
|
|
20
|
+
- "Remind people", "send a reminder the day before", "follow up
|
|
21
|
+
automatically".
|
|
22
|
+
- "A weekly summary", "a daily digest", "email me when", "send a report every
|
|
23
|
+
Monday".
|
|
24
|
+
- "People forget to come back."
|
|
25
|
+
|
|
26
|
+
## How to answer the person
|
|
27
|
+
|
|
28
|
+
Propose the simple way first: "A small job inside `<APP_NAME>` checks every
|
|
29
|
+
minute for what is due and sends it by email, each one once, at a sensible
|
|
30
|
+
local hour. People choose which ones they get in Settings, and every email has
|
|
31
|
+
an unsubscribe link. Nothing real is sent until the app runs in production."
|
|
32
|
+
|
|
33
|
+
Then say: "There are other options if you want to discuss." They are push
|
|
34
|
+
notifications to phones (the [installable app](/guide/recipes/installable-app)),
|
|
35
|
+
text messages (the same delivery rules, through the SMS channel), a hosted
|
|
36
|
+
workflow service that runs the schedule (JSKIT's
|
|
37
|
+
[event delivery pattern](/patterns/connectors/event-delivery) sends it events;
|
|
38
|
+
the schedules stay that service's), and a mailing-list tool for newsletters to
|
|
39
|
+
everyone.
|
|
40
|
+
|
|
41
|
+
## Product decisions (defaults)
|
|
42
|
+
|
|
43
|
+
- Reminders: one, 24 hours before the due time; none for something already
|
|
44
|
+
done or deleted.
|
|
45
|
+
- Digest: weekly, Monday at 08:00 in the person's saved time zone, only when
|
|
46
|
+
there is something in it.
|
|
47
|
+
- Nothing sends between 21:00 and 08:00 local time; it waits for the morning.
|
|
48
|
+
- Language and time zone: the person's saved `locale` and `timeZone`, else
|
|
49
|
+
English and UTC.
|
|
50
|
+
- Each kind has a switch in Settings, on by default; every email's
|
|
51
|
+
unsubscribe link turns its kind off without signing in.
|
|
52
|
+
- A failed send is retried 3 times over an hour, then marked failed where an
|
|
53
|
+
administrator can see it; it is never sent twice.
|
|
54
|
+
- In a workspace app, someone who left the workspace gets nothing more from it.
|
|
55
|
+
|
|
56
|
+
## Make a careful saved plan first
|
|
57
|
+
|
|
58
|
+
Write a careful saved plan first, then implement it item by item, proving each
|
|
59
|
+
one:
|
|
60
|
+
|
|
61
|
+
1. A table of scheduled sends, one row per message to go, unique on what makes
|
|
62
|
+
it one (person, kind, subject record, occurrence).
|
|
63
|
+
2. Where each reminder's record is created, changed or deleted, write, move or
|
|
64
|
+
remove its scheduled send in the same transaction.
|
|
65
|
+
3. A job that runs every minute in every server copy, claims due rows and
|
|
66
|
+
sends them, in batches.
|
|
67
|
+
4. Digests: a job that, per person or workspace, builds the digest in one batch
|
|
68
|
+
of reads and schedules its send.
|
|
69
|
+
5. The app's mailer, behind JSKIT's delivery rules, and the messages in the
|
|
70
|
+
people's languages.
|
|
71
|
+
6. Settings switches per kind, and signed unsubscribe links.
|
|
72
|
+
7. The unsubscribe secret in the environment, required in staging and
|
|
73
|
+
production.
|
|
74
|
+
|
|
75
|
+
## Technical details
|
|
76
|
+
|
|
77
|
+
JSKIT ships no scheduler and no mail transport. It owns the delivery rules by
|
|
78
|
+
`APP_ENV`, background work's contexts and row claiming; the timer, the
|
|
79
|
+
scheduled-sends table and the mailer are the app's own, built on them.
|
|
80
|
+
|
|
81
|
+
- **The table:** a table resource with ownership `user` (or
|
|
82
|
+
`workspace_user`), fields for kind, subject id, `sendAfter`, `claimedAt`,
|
|
83
|
+
`sentAt`, attempts and the last error, and a unique index on the keys that
|
|
84
|
+
make one send; writers upsert with
|
|
85
|
+
`createMany(rows, { ...options, onConflict: { keys, action: "ignore" } })`
|
|
86
|
+
so a send is scheduled once
|
|
87
|
+
([Layer 3](/guide/framework/data-access#layer-3-many-rows-at-once)).
|
|
88
|
+
- **The job:** a feature that declares `systemScope` and whose `boot()` starts
|
|
89
|
+
`setInterval(runOnce, 60_000).unref()`; `shutdown()` clears it and awaits a
|
|
90
|
+
run in progress, and tests call `runOnce()` itself
|
|
91
|
+
([Owned state](/guide/framework/typed-features#owned-state)). Every server
|
|
92
|
+
runs the timer, so a run takes due rows with
|
|
93
|
+
`claim({ filters, sort, take }, txOptions)`, which skips rows another copy
|
|
94
|
+
holds, marks them claimed in that transaction, sends after it commits and
|
|
95
|
+
marks each sent; a row claimed long ago without being sent is due again
|
|
96
|
+
([Scheduled work](/guide/app-setup/more-than-one-server#scheduled-work),
|
|
97
|
+
[Background work](/guide/framework/data-access#background-work)). It takes
|
|
98
|
+
batch after batch until a batch comes back short.
|
|
99
|
+
- **Whom it is for:** work for one person runs in
|
|
100
|
+
`systemContext(reason).forUser(id)` (or `forWorkspaceUser`); a digest per
|
|
101
|
+
workspace pages through the `workspaces` owner API's
|
|
102
|
+
`listForSystem({ afterId, limit }, { context })`; a
|
|
103
|
+
job finds its people with an `aggregate` grouped by the ownership field
|
|
104
|
+
([Background work](/guide/framework/data-access#background-work)). Saved
|
|
105
|
+
time zones and languages come from users-core's `users.settings`
|
|
106
|
+
(`listByUserIds(userIds, options)`), one read per batch.
|
|
107
|
+
- **Sending:** every email goes through `deliverMessage()` from
|
|
108
|
+
`@jskit-ai/kernel/server/runtime/appEnvironment`, with
|
|
109
|
+
`channel: "email"`, `to`, `summary`, `details` and a `send` function that
|
|
110
|
+
uses `markStagingEmail`
|
|
111
|
+
in `send`; production sends, staging sends to `STAGING_EMAIL_TO` or logs,
|
|
112
|
+
development and test log
|
|
113
|
+
([The application's own side effects](/guide/framework/environments#the-application-s-own-side-effects)).
|
|
114
|
+
The `send` function is the app's mailer: its email provider's client, with
|
|
115
|
+
the provider's key in the environment.
|
|
116
|
+
- **Words and dates:** the email's text comes from the app's catalog in the
|
|
117
|
+
person's language through `createServerI18n` from
|
|
118
|
+
`@jskit-ai/kernel/server/i18n`, and its dates through `Intl` in their time
|
|
119
|
+
zone ([Emails](/guide/framework/translation#emails)).
|
|
120
|
+
- **Settings:** users-core's notification settings hold JSKIT's own three
|
|
121
|
+
switches; the app's kinds get their own settings table and an
|
|
122
|
+
`account-settings:sections` placement
|
|
123
|
+
([account settings pattern](/patterns/users/account-settings)).
|
|
124
|
+
- **Unsubscribe:** each email links a public page with a token signed (HMAC)
|
|
125
|
+
with the app's unsubscribe secret over the person and the kind; the page
|
|
126
|
+
turns that kind off and says so. Add the `List-Unsubscribe` and
|
|
127
|
+
`List-Unsubscribe-Post` headers for one-click unsubscribe in mail apps. The
|
|
128
|
+
route declares a `rateLimit`
|
|
129
|
+
([Routes](/guide/framework/typed-features#routes)).
|
|
130
|
+
|
|
131
|
+
## Proof
|
|
132
|
+
|
|
133
|
+
Prove each behaviour at the cheapest level, never against development data
|
|
134
|
+
and never through a real email service.
|
|
135
|
+
|
|
136
|
+
- **Server tests** (`jskit test`, on `TEST_DB_NAME`, with a fixed clock):
|
|
137
|
+
`runOnce()` sends what is due and nothing else; two runners at once send
|
|
138
|
+
each row once; a reminder moves with its record and goes with its deletion;
|
|
139
|
+
the night hold and the 08:00 digest in two time zones, across a daylight
|
|
140
|
+
saving change; an empty digest is skipped; retries stop after 3; a tampered
|
|
141
|
+
unsubscribe token is refused and a good one turns the kind off; production
|
|
142
|
+
sends through a fake transport (`APP_ENV: "production"`), staging only to
|
|
143
|
+
`STAGING_EMAIL_TO`, development logs. A batch takes the same number of
|
|
144
|
+
queries at 10 and 1,000 due rows (`expectFlatQueries()`).
|
|
145
|
+
- **Browser tests** (`npm run test:e2e`): the Settings switches, and the
|
|
146
|
+
unsubscribe page signed out.
|
|
147
|
+
|
|
148
|
+
## Leftovers for the person
|
|
149
|
+
|
|
150
|
+
- The email provider account, a verified sending domain (SPF, DKIM, DMARC)
|
|
151
|
+
and its key in staging and production.
|
|
152
|
+
- Reading real reminders and digests in their own inbox on staging
|
|
153
|
+
(`STAGING_EMAIL_TO`) before production.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/recipes/usefulness-study.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: "Recipe: a study of how useful the app is"
|
|
5
|
+
description: Check how useful a JSKIT app is for what people come to do, judging value and gaps rather than ease of use, ending in ranked recommendations and changing nothing.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Study how useful `<APP_NAME>` is for what people come to do: ranked recommendations, nothing changed
|
|
9
|
+
|
|
10
|
+
Check how well `<APP_NAME>` serves what people come to it for: whether each
|
|
11
|
+
kind of person can get their job done inside the app from start to finish,
|
|
12
|
+
what they still have to do elsewhere, what the app knows but never gives back,
|
|
13
|
+
and what it could do for them without being asked. The study changes nothing.
|
|
14
|
+
It ends in recommendations ranked by value, each with its evidence, the
|
|
15
|
+
smallest change that delivers it and the JSKIT owner or recipe that builds it.
|
|
16
|
+
|
|
17
|
+
## When to propose it
|
|
18
|
+
|
|
19
|
+
- "Is this app any good?", "what's missing?", "what should we build next?",
|
|
20
|
+
"how can it be more useful?", "review the product".
|
|
21
|
+
- "People sign up and don't come back", "people still use a spreadsheet next
|
|
22
|
+
to it".
|
|
23
|
+
- After a big feature lands, to see what the app now lacks around it.
|
|
24
|
+
|
|
25
|
+
## How to answer the person
|
|
26
|
+
|
|
27
|
+
Propose the simple way first: "I'll go through `<APP_NAME>` as each kind of
|
|
28
|
+
person who uses it, on realistic test data, check what they come to do and
|
|
29
|
+
whether the app lets them finish it, and come back with a ranked list of what
|
|
30
|
+
would make it more useful. I won't change anything." This judges value and
|
|
31
|
+
gaps, not ease of use: how easy each step is belongs to the user experience
|
|
32
|
+
pass ([User experience pass](/guide/framework/ux-pass)), which can follow.
|
|
33
|
+
|
|
34
|
+
Then say: "There are other options if you want to discuss." They are talking
|
|
35
|
+
to real users or reading how the app is really used (the person's data and
|
|
36
|
+
their consent decide that), comparing with the products people use instead
|
|
37
|
+
(the person names them), or a user experience pass when the problem is that
|
|
38
|
+
things are hard to do rather than missing.
|
|
39
|
+
|
|
40
|
+
## Product decisions (defaults)
|
|
41
|
+
|
|
42
|
+
- The people are the kinds the Blueprint names (in a Genesis project), else
|
|
43
|
+
the app's roles (`roleCatalog` in `config/roles.js`), else signed-out
|
|
44
|
+
visitors and signed-in users.
|
|
45
|
+
- Each kind of person has three to seven jobs they come to do, written as the
|
|
46
|
+
outcome they want ("know which invoices are overdue"), not as a screen.
|
|
47
|
+
- A recommendation's rank is its value to those people, times how many of
|
|
48
|
+
them it reaches and how often, against what it costs to build and run.
|
|
49
|
+
- Evidence comes from realistic seeded test data and the code, never the
|
|
50
|
+
development database or real outside services.
|
|
51
|
+
|
|
52
|
+
## Make a careful saved plan first
|
|
53
|
+
|
|
54
|
+
The study's own plan, saved before it starts and ticked as it goes:
|
|
55
|
+
|
|
56
|
+
1. Write who the app is for and their jobs, from the Blueprint, the front
|
|
57
|
+
page and the help; ask the person only what nothing says.
|
|
58
|
+
2. Map what the app offers: the main navigation (`shell.primary-nav`
|
|
59
|
+
placements), the pages under `src/pages`, the server features' actions and
|
|
60
|
+
routes, the roles and permissions, what goes out (email, exports, links)
|
|
61
|
+
and what comes in (imports, integrations in `integrations.json`).
|
|
62
|
+
3. For each job, walk it end to end as that person on the test target with
|
|
63
|
+
realistic data (a Playwright script, or the app's preview on its test
|
|
64
|
+
database). Note where it finishes, where it stops, what the person must
|
|
65
|
+
do outside the app, what information is missing at the moment they decide,
|
|
66
|
+
and what the app makes them repeat.
|
|
67
|
+
4. Find the gaps: jobs with no path, half paths, data the app holds but never
|
|
68
|
+
shows back (totals, history, what changed), moments it could act for the
|
|
69
|
+
person (a reminder, a summary, a nudge), work shared with other people it
|
|
70
|
+
doesn't support, and features no job needs.
|
|
71
|
+
5. Check what holds at a realistic size: a list that cannot be searched or
|
|
72
|
+
filtered at hundreds of rows is a gap in value, not in ease of use.
|
|
73
|
+
6. Rank the recommendations and write the plan this page's last section
|
|
74
|
+
describes.
|
|
75
|
+
|
|
76
|
+
## Technical details
|
|
77
|
+
|
|
78
|
+
Where a JSKIT app keeps what the study reads:
|
|
79
|
+
|
|
80
|
+
- **What people can reach:** main tasks are `shell.primary-nav` placements
|
|
81
|
+
and each inner page declares `jskit.parent`
|
|
82
|
+
([Where people find each task](/guide/framework/ux-pass#where-people-find-each-task));
|
|
83
|
+
the account menu is the `auth.profile-menu` placement and settings
|
|
84
|
+
sections are `account-settings:sections` placements.
|
|
85
|
+
- **What the app can do:** each server feature's actions (one
|
|
86
|
+
`create<Name>Actions` each) and routes
|
|
87
|
+
([Typed features](/guide/framework/typed-features#actions)); CRUD features
|
|
88
|
+
([CRUD operations](/guide/framework/crud-operations)).
|
|
89
|
+
- **What it knows:** each table resource (`defineTableResource`) and its
|
|
90
|
+
`searchSchema`, which says what a list can be searched and filtered by
|
|
91
|
+
([Data access](/guide/framework/data-access#layer-1-the-table-resource)).
|
|
92
|
+
- **What it does on its own:** `jskit check` lists every system scope, the
|
|
93
|
+
background work the app runs
|
|
94
|
+
([Background work](/guide/framework/data-access#background-work)).
|
|
95
|
+
- **Who may do what:** `roleCatalog` and its permissions
|
|
96
|
+
([Role permissions](/guide/app-setup/multi-homing#role-permissions)).
|
|
97
|
+
- **What goes out:** email and SMS through `deliverMessage`, other outside
|
|
98
|
+
effects through `logSideEffect`
|
|
99
|
+
([Environments](/guide/framework/environments#the-application-s-own-side-effects)).
|
|
100
|
+
|
|
101
|
+
A recommendation names the JSKIT owner or recipe that would build it, for
|
|
102
|
+
example the [installable app](/guide/recipes/installable-app),
|
|
103
|
+
[reminders and digests](/guide/recipes/reminders-and-digests),
|
|
104
|
+
[file uploads and images](/guide/recipes/file-uploads-and-images),
|
|
105
|
+
[inviting people with roles](/guide/recipes/invite-people-with-roles),
|
|
106
|
+
[payments and subscriptions](/guide/recipes/payments-and-subscriptions),
|
|
107
|
+
[another language](/guide/recipes/another-language) or
|
|
108
|
+
[working offline](/guide/recipes/offline-study).
|
|
109
|
+
|
|
110
|
+
## Proof
|
|
111
|
+
|
|
112
|
+
Each finding carries its evidence: a walk on the test target with realistic
|
|
113
|
+
seeded data (the step where the job stops), the file and line that shows what
|
|
114
|
+
exists or is missing, or a measurement. Nothing runs against development data
|
|
115
|
+
or a real outside service. The study changes nothing: at its end the working
|
|
116
|
+
tree holds only the saved plan.
|
|
117
|
+
|
|
118
|
+
## The plan it ends in
|
|
119
|
+
|
|
120
|
+
Ranked recommendations, saved where the project keeps plans, most valuable
|
|
121
|
+
first. Each one says:
|
|
122
|
+
|
|
123
|
+
- the people and the job it serves, and how often they do it;
|
|
124
|
+
- the gap, with its evidence;
|
|
125
|
+
- the smallest change that closes it, and the JSKIT owner or recipe that
|
|
126
|
+
builds it;
|
|
127
|
+
- what it costs to build and to run;
|
|
128
|
+
- how the person will know it worked (a job that now finishes in the app, a
|
|
129
|
+
step people no longer do elsewhere).
|
|
130
|
+
|
|
131
|
+
It ends with what the study could not judge without the person or real users.
|
|
132
|
+
|
|
133
|
+
## Leftovers for the person
|
|
134
|
+
|
|
135
|
+
- Whether the jobs are the right ones, when nothing in the project says.
|
|
136
|
+
- What real users say and do, if the person can ask them or share usage.
|
|
137
|
+
- Which recommendations to build, in what order, against their budget.
|
package/package.json
CHANGED
|
@@ -76,6 +76,8 @@ questionnaire or infer tenancy, authentication, or database requirements.
|
|
|
76
76
|
`server.js` takes `API_BASE_PATH` and `toRequestPathname` from the kernel's
|
|
77
77
|
`shared/surface/paths`. `server/lib/envFile.js` loads `.env` once per process
|
|
78
78
|
for every entry point. `server/lib/loggerOptions.js` gives Fastify's logger
|
|
79
|
+
the level `LOG_LEVEL` names, info without one (`jskit test` and the browser
|
|
80
|
+
test servers set warn, so a test server does not log every request), and
|
|
79
81
|
pino's error serializer under `error` as well as `err`, so
|
|
80
82
|
`logger.error({ error }, "...")` keeps the error's message and stack. `eslint.config.mjs` holds
|
|
81
83
|
server and shared code to every typed-features rule (`typedFeaturesConfig`),
|