@jskit-ai/agent-docs 0.1.331 → 0.1.333
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/realtime.md +11 -3
- package/guide/agent/app-setup/authentication.md +135 -32
- package/guide/agent/app-setup/initial-scaffolding.md +10 -9
- package/guide/agent/app-setup/more-than-one-server.md +111 -0
- package/guide/agent/app-setup/multi-homing.md +2 -2
- package/guide/agent/app-setup/package-with-nix.md +60 -15
- package/guide/agent/app-setup/upgrading-jskit.md +36 -1
- package/guide/agent/framework/crud-form-actions.md +18 -7
- package/guide/agent/framework/environments.md +174 -0
- package/guide/agent/framework/material-3.md +9 -3
- package/guide/agent/framework/quality-pass.md +8 -2
- package/guide/agent/framework/sanity-checks.md +3 -3
- package/guide/agent/framework/security-pass.md +7 -5
- package/guide/agent/index.md +6 -2
- package/package.json +1 -1
- package/patterns/feature-package/example/booking-engine/package.json +1 -1
- package/patterns/minimal-foundation/example/.env.example +8 -0
- package/patterns/minimal-foundation/example/AGENTS.md +7 -5
- package/patterns/minimal-foundation/example/bin/develop.js +2 -0
- package/patterns/minimal-foundation/example/package.json +7 -7
- package/patterns/shell-foundation/example/.env.example +8 -0
- package/patterns/shell-foundation/example/AGENTS.md +7 -5
- package/patterns/shell-foundation/example/bin/develop.js +2 -0
- package/patterns/shell-foundation/example/package.json +8 -8
- package/patterns/shell-foundation/example/packages/main/package.json +1 -1
- package/reference/autogen/KERNEL_MAP.md +10 -11
- package/reference/autogen/PATTERN_INDEX.md +38 -38
- package/reference/autogen/packages/auth-core.md +15 -2
- package/reference/autogen/packages/auth-provider-local-core.md +48 -13
- package/reference/autogen/packages/auth-provider-local-db-core.md +15 -0
- package/reference/autogen/packages/auth-provider-oidc-core.md +1 -1
- package/reference/autogen/packages/auth-provider-supabase-core.md +2 -2
- package/reference/autogen/packages/auth-web.md +26 -0
- package/reference/autogen/packages/connectors-core.md +2 -2
- package/reference/autogen/packages/http-web.md +2 -0
- package/reference/autogen/packages/kernel.md +32 -27
- package/reference/autogen/packages/oidc-issuer-core.md +4 -4
- package/reference/autogen/packages/payments-core.md +1 -1
- package/reference/autogen/packages/shell-web.md +40 -13
- package/reference/autogen/packages/storage-runtime.md +6 -0
- package/reference/autogen/packages/workspaces-core.md +4 -4
- package/reference/autogen/tooling/jskit-catalog.md +6 -1
- package/skills/jskit/SKILL.md +2 -1
- package/skills/jskit/references/crud-form-actions.md +18 -7
- package/skills/jskit/references/environments.md +169 -0
- package/skills/jskit/references/heuristics/INDEX.md +1 -1
- package/skills/jskit/references/heuristics/client-requests.md +1 -1
- package/skills/jskit/references/heuristics/crud-authoring.md +3 -2
- package/skills/jskit/references/heuristics/live-actions.md +4 -1
- package/skills/jskit/references/heuristics/ui-contract.md +9 -1
- package/skills/jskit/references/material-3.md +9 -3
- package/skills/jskit/references/multi-homing.md +2 -2
- package/skills/jskit/references/package-with-nix.md +60 -15
- package/skills/jskit/references/pattern-index.md +38 -38
- package/skills/jskit/references/patterns/app/minimal-foundation/example/.env.example +8 -0
- package/skills/jskit/references/patterns/app/minimal-foundation/example/AGENTS.md +7 -5
- package/skills/jskit/references/patterns/app/minimal-foundation/example/bin/develop.js +2 -0
- package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +7 -7
- package/skills/jskit/references/patterns/app/shell-foundation/example/.env.example +8 -0
- package/skills/jskit/references/patterns/app/shell-foundation/example/AGENTS.md +7 -5
- package/skills/jskit/references/patterns/app/shell-foundation/example/bin/develop.js +2 -0
- package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +8 -8
- package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
- package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
- package/skills/jskit/references/patterns/auth/auth-surface/PATTERN.md +10 -8
- package/skills/jskit/references/patterns/auth/auth-surface/example/src/pages/auth/email-change.vue +17 -0
- package/skills/jskit/references/patterns/auth/auth-surface/example/src/views/auth/EmailChangeView.vue +12 -0
- package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
- package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
- package/skills/jskit/references/patterns/connectors/api-key-connection/PATTERN.md +4 -1
- package/skills/jskit/references/patterns/connectors/api-key-connection/example/connections.js +3 -3
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/.env.example +1 -0
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +5 -4
- package/skills/jskit/references/patterns/connectors/calendar-cli/example/scripts/calendar.js +3 -1
- package/skills/jskit/references/patterns/connectors/firebase-messaging/example/server/notifications.js +3 -3
- package/skills/jskit/references/patterns/connectors/oauth-connection/PATTERN.md +3 -1
- package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
- 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/.env.example +1 -0
- package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
- package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
- package/skills/jskit/references/patterns/users/account-settings/example/src/components/account/settings/AccountSettingsNotificationsSection.vue +3 -1
- package/skills/jskit/references/patterns/users/account-settings/example/src/components/account/settings/AccountSettingsPreferencesSection.vue +3 -1
- package/skills/jskit/references/patterns/users/account-settings/example/src/components/account/settings/AccountSettingsProfileSection.vue +4 -1
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
- package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
- package/skills/jskit/references/quality-pass.md +8 -2
- package/skills/jskit/references/sanity-checks.md +3 -3
- package/skills/jskit/references/security-pass.md +7 -5
- package/guide/agent/framework/side-effects.md +0 -77
- package/skills/jskit/references/side-effects.md +0 -72
|
@@ -183,9 +183,17 @@ events may still describe distinct intermediate states.
|
|
|
183
183
|
|
|
184
184
|
## Single process and Redis
|
|
185
185
|
|
|
186
|
-
The in-process adapter is correct for one server process
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
The in-process adapter is correct for one server process: an event reaches
|
|
187
|
+
only the browsers connected to the process that published it. Set
|
|
188
|
+
`REALTIME_REDIS_URL` only when multiple processes need a shared backplane, to
|
|
189
|
+
the same Redis on every one; each then delivers every event to its own
|
|
190
|
+
browsers. Socket.IO opens each connection with HTTP long-polling, whose
|
|
191
|
+
requests must all reach the process that opened it: keep each browser on one
|
|
192
|
+
process at the load balancer, or connect by WebSocket only with
|
|
193
|
+
`realtimeClient: { options: { transports: ["websocket"] } }` in the app's
|
|
194
|
+
public config. Credentials stay outside Git and never enter public client
|
|
195
|
+
config. [Run on more than one server](/guide/app-setup/more-than-one-server)
|
|
196
|
+
covers the rest of what several copies need.
|
|
189
197
|
|
|
190
198
|
## Shutdown
|
|
191
199
|
|
|
@@ -98,8 +98,8 @@ declares a `rateLimit`, which the kernel enforces for each client address. A
|
|
|
98
98
|
request over it is refused with status 429, the code `kernel.http.rateLimited`
|
|
99
99
|
(`params.count` is the seconds to wait) and a `Retry-After` header. The
|
|
100
100
|
defaults, per minute: `login`, `register`, `registerConfirm`,
|
|
101
|
-
`loginOtpRequest` and `
|
|
102
|
-
`passwordForgot` 5;
|
|
101
|
+
`loginOtpRequest`, `loginOtpVerify` and `emailChangeConfirm` 10;
|
|
102
|
+
`registerConfirmationResend`, `passwordForgot` and `emailChange` 5;
|
|
103
103
|
`oauthStart`, `oauthComplete`, `passSignIn`, `passwordRecovery` and `passwordReset` 20;
|
|
104
104
|
`devLoginAs` 30. Change one in the application's server configuration;
|
|
105
105
|
`false` removes it:
|
|
@@ -163,10 +163,25 @@ sign-in factor, and at least 8 when it is used with another factor; set
|
|
|
163
163
|
|
|
164
164
|
The login page shows either refusal, translated, with the wait.
|
|
165
165
|
|
|
166
|
+
**Sign-in events (local auth).** Each sign-in and each refused one is an
|
|
167
|
+
event, for a page that lists an account's sign-ins or for an audit log:
|
|
168
|
+
`type` (`signedIn` or `failed`), `method` (`password`, `registration`,
|
|
169
|
+
`confirmation`, `recovery`, `pass`, or `provider` with `provider`, such as
|
|
170
|
+
`google`), a refusal's `reason` (`invalidCredentials`, `locked`,
|
|
171
|
+
`unconfirmed` or `disabled`), `userId` (the local account, "" when the email
|
|
172
|
+
names none), `email`, the request's `ip` and `userAgent`, and `at`; never a
|
|
173
|
+
password, secret or token. An application that keeps them installs the
|
|
174
|
+
`auth.local.sign-in-events` capability, a function given each event
|
|
175
|
+
(`AuthLocalSignInEvent` in `@jskit-ai/auth-provider-local-core/server/types`),
|
|
176
|
+
and stores them in a table of its own, with how long it keeps them. It is
|
|
177
|
+
called after the request has answered, so a refused sign-in takes the same
|
|
178
|
+
time whatever it does; when it fails, local auth logs the failure, and a
|
|
179
|
+
stopping server waits for it a while. Without one, local auth logs each event.
|
|
180
|
+
|
|
166
181
|
## Sign-in cookies and SameSite
|
|
167
182
|
|
|
168
183
|
Local auth's cookies (access, refresh, recovery and OAuth attempt) and
|
|
169
|
-
auth-core's CSRF cookie are httpOnly, at `Path=/`, and in production Secure
|
|
184
|
+
auth-core's CSRF cookie are httpOnly, at `Path=/`, and in staging and production Secure
|
|
170
185
|
with the `__Host-` prefix. One setting gives them all their SameSite:
|
|
171
186
|
|
|
172
187
|
| Env | Default | Meaning |
|
|
@@ -202,10 +217,10 @@ choice, route by route or role by role; nothing asks for it by default.
|
|
|
202
217
|
OIDC and Supabase sign-in answer `AUTH_OPERATION_UNSUPPORTED`, and
|
|
203
218
|
`features.secondFactor` in the auth capabilities is false there.
|
|
204
219
|
|
|
205
|
-
**Setting it up.** In production, set `AUTH_LOCAL_SECOND_FACTOR_KEY` to a
|
|
220
|
+
**Setting it up.** In staging and production, set `AUTH_LOCAL_SECOND_FACTOR_KEY` to a
|
|
206
221
|
random secret of at least 32 characters, and `APP_PUBLIC_URL`, whose host the
|
|
207
|
-
authenticator app shows beside the codes; without the key a production server
|
|
208
|
-
has no second factor.
|
|
222
|
+
authenticator app shows beside the codes; without the key a staging or production server
|
|
223
|
+
has no second factor. In development and test the session secret stands in for the
|
|
209
224
|
key. The key seals each account's authenticator secret (AES-256-GCM, bound to
|
|
210
225
|
the account) and keys the hashes of its recovery codes, so keep it: a factor
|
|
211
226
|
sealed under one key does not open under another, and verifying it then fails
|
|
@@ -348,7 +363,7 @@ capability, an async function accepting `{ email, confirmationUrl }`, built
|
|
|
348
363
|
like the recovery sender below; with it, `APP_PUBLIC_URL` is required and the
|
|
349
364
|
link is never returned or logged. In development without one, the link is in
|
|
350
365
|
the registration's answer (`confirmationUrl`) and the log, and the sign-in page
|
|
351
|
-
shows it with a button that confirms it with the password typed. In production (`
|
|
366
|
+
shows it with a button that confirms it with the password typed. In staging or production (`APP_ENV`)
|
|
352
367
|
without one, while anyone may register, the server refuses to start, naming
|
|
353
368
|
the ways out: install a sender, set `AUTH_LOCAL_EMAIL_CONFIRMATION=false`, or
|
|
354
369
|
set `AUTH_LOCAL_SELF_REGISTRATION=false`. For direct library
|
|
@@ -357,14 +372,18 @@ composition, pass the sender as `confirmationSender` to
|
|
|
357
372
|
`resolveLocalAuthConfig()`; without one, pass
|
|
358
373
|
`createLoggedConfirmationSender(logger)`.
|
|
359
374
|
|
|
360
|
-
|
|
361
|
-
[
|
|
362
|
-
|
|
363
|
-
`
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
375
|
+
An installed `auth.local.confirmation-sender` sends as `APP_ENV` says (see
|
|
376
|
+
[Environments](/guide/framework/environments)): in production to the address
|
|
377
|
+
that registered; in staging only to `STAGING_EMAIL_TO`, called with that
|
|
378
|
+
address as `email` and the registered one as `originalEmail`, which its email
|
|
379
|
+
should show (`markStagingEmail` from
|
|
380
|
+
`@jskit-ai/kernel/server/runtime/appEnvironment` does), or not at all when
|
|
381
|
+
`STAGING_EMAIL_TO` is unset; in development and test never. Where it is not
|
|
382
|
+
called, local auth logs each link for the person testing and keeps it out of
|
|
383
|
+
the answer. So no code may depend on the sender having run, such as code that
|
|
384
|
+
confirms a registration with the link its sender was given: in development,
|
|
385
|
+
test and staging without `STAGING_EMAIL_TO` that code gets no link. The
|
|
386
|
+
recovery sender is called the same way.
|
|
368
387
|
|
|
369
388
|
An application that confirms new accounts at once while its email isn't set up
|
|
370
389
|
says so with the optional `auth.local.confirmation-mode` capability, a function
|
|
@@ -376,9 +395,9 @@ account it creates has an address nobody proved, so answer `"without-link"`
|
|
|
376
395
|
only when the application accepts that. Any other answer means `"link"` and
|
|
377
396
|
logs a warning. Local auth asks only while email confirmation is on and the
|
|
378
397
|
address isn't proven already (an invitation or the first account's setup
|
|
379
|
-
code). The mode sends nothing, so
|
|
380
|
-
|
|
381
|
-
sender: a production server still needs one, or
|
|
398
|
+
code). The mode sends nothing, so it applies in every environment, whatever
|
|
399
|
+
happens to the sender's emails there. It does not stand in for a
|
|
400
|
+
sender: a staging or production server still needs one, or
|
|
382
401
|
`AUTH_LOCAL_EMAIL_CONFIRMATION=false`, and `"link"` registrations are sent
|
|
383
402
|
through it. An application that never sends a link sets
|
|
384
403
|
`AUTH_LOCAL_EMAIL_CONFIRMATION=false` instead.
|
|
@@ -448,8 +467,8 @@ error.
|
|
|
448
467
|
|
|
449
468
|
| Capability | Methods |
|
|
450
469
|
| --- | --- |
|
|
451
|
-
| `auth.local.accounts` | `create(account, options)`, `findById(userId, options)`, `findByEmail(email, options)`, `updatePassword(userId, passwordRecord, options)`, `updateProfile(userId, { displayName }, options)`, `markEmailVerified(userId, options)` |
|
|
452
|
-
| `auth.local.sessions` | `create(session, options)`, `update(sessionId, { purpose, expiresAt }, { ...options, onlyIf })`, `revoke(sessionId, options)`, `revokeForUser(userId, { ...options, exceptSessionId })`, `deleteExpired(now, options)` |
|
|
470
|
+
| `auth.local.accounts` | `create(account, options)`, `findById(userId, options)`, `findByEmail(email, options)`, `updatePassword(userId, passwordRecord, options)`, `updateProfile(userId, { displayName }, options)`, `markEmailVerified(userId, options)`, `disable(userId, { message }, options)`, `enable(userId, options)` |
|
|
471
|
+
| `auth.local.sessions` | `create(session, options)`, `update(sessionId, { purpose, expiresAt }, { ...options, onlyIf })`, `revoke(sessionId, options)`, `revokeForUser(userId, { ...options, exceptSessionId })`, `deleteExpired(now, options)`, `listForUser(userId, options)` |
|
|
453
472
|
| `auth.local.recovery` | `create(token, options)`, `findByTokenHash(tokenHash, options)`, `consume(tokenId, options)`, `consumeForUser(userId, { ...options, idPrefix })` |
|
|
454
473
|
|
|
455
474
|
`markEmailVerified` records that the account proved it owns its email address,
|
|
@@ -458,6 +477,40 @@ for example by using an emailed link, in the `email_verified_at` column (run
|
|
|
458
477
|
`emailVerifiedAt` (empty until then). `deleteExpired` deletes the sessions that
|
|
459
478
|
expired by `now` and answers how many.
|
|
460
479
|
|
|
480
|
+
`disable` stops an account signing in, for example while an application
|
|
481
|
+
suspends or closes it: every sign-in and every session of the account is
|
|
482
|
+
refused from its next request, until `enable`. `message`, at most 500
|
|
483
|
+
characters, is what the person is told when they sign in with the right
|
|
484
|
+
password, a linked provider or a one-time pass, such as `This account is
|
|
485
|
+
suspended until 14 Dec. We've emailed you why.`: status 403, the code
|
|
486
|
+
`auth.local.login.disabled`, and the message as the error's text, which the
|
|
487
|
+
sign-in page shows as written. Without a message the text is `This account is
|
|
488
|
+
disabled.`, translated like any other. A wrong password is an ordinary failed
|
|
489
|
+
sign-in, so only someone who could sign in learns that the account is
|
|
490
|
+
disabled. The message is kept in the `disabled_message` column (run
|
|
491
|
+
`npm run db:migrate`) until `enable` clears it. Both answer the account
|
|
492
|
+
(`disabled`, `disabledMessage`, "" when it has none), or null when there is no
|
|
493
|
+
such account, and refuse a missing id, as `disable` refuses a message that is
|
|
494
|
+
not text of at most 500 characters, with a `TypeError`. Neither signs the
|
|
495
|
+
account out: its sessions work again after `enable`, unless
|
|
496
|
+
`auth.local.sessions`' `revokeForUser` ended them.
|
|
497
|
+
|
|
498
|
+
Every session keeps where and when it was last seen: `ip` (the request's
|
|
499
|
+
address, Fastify's `request.ip`, so set `TRUSTED_PROXIES` behind a proxy),
|
|
500
|
+
`userAgent` (the browser's `User-Agent`, at most 512 characters) and
|
|
501
|
+
`lastSeenAt`. Signing in sets them from the sign-in's request, and a request
|
|
502
|
+
that finds the session more than five minutes after it was last seen sets them
|
|
503
|
+
again, so most requests write nothing; one that does not say where it comes
|
|
504
|
+
from keeps the address and browser. Each is "" when unknown, as for sessions
|
|
505
|
+
from before (run `npm run db:migrate` for the `ip`, `user_agent` and
|
|
506
|
+
`last_seen_at` columns). `listForUser` answers the account's sessions that are
|
|
507
|
+
neither revoked nor expired, the newest first, every one of them, and refuses
|
|
508
|
+
a missing id with a `TypeError`. For a person's own list, name the account
|
|
509
|
+
from the request's authentication, never from what the client sends:
|
|
510
|
+
`authenticateRequest(request)` answers `actor.providerUserId` and the
|
|
511
|
+
request's own `sessionId`, which the list can mark as this browser. End one
|
|
512
|
+
session with `revoke(sessionId)` once the list showed it is that account's.
|
|
513
|
+
|
|
461
514
|
A recovery token's kind is the start of its id: local sign-in's password resets
|
|
462
515
|
are `rec_…`, and an app's own kind (a sign-in link, say) takes a prefix of its
|
|
463
516
|
own, such as `magic_…`. `consumeForUser` consumes the user's open tokens of the
|
|
@@ -475,9 +528,9 @@ and treat null as a refused link. Their types are `AuthLocalAccounts`,
|
|
|
475
528
|
## The first account in production (local auth)
|
|
476
529
|
|
|
477
530
|
The first account to register becomes the application's owner, so on a
|
|
478
|
-
production server (`
|
|
531
|
+
staging or production server (`APP_ENV`) whose local auth has no account yet,
|
|
479
532
|
registering needs a one-time setup code that only the server's operator can
|
|
480
|
-
read. Development
|
|
533
|
+
read. Development and test need no code.
|
|
481
534
|
|
|
482
535
|
Each start of such a server makes a new code, such as
|
|
483
536
|
`7KQ2M-X9D4F-0RWHN-3TBZC`, and keeps only its hash. It writes the code:
|
|
@@ -507,8 +560,8 @@ A hosting tool that shows the code to the operator itself supplies it in
|
|
|
507
560
|
`AUTH_LOCAL_SETUP_CODE`, at least 20 letters and digits, for example a
|
|
508
561
|
generated production secret. The server then asks for that code at every start
|
|
509
562
|
and on every server, writes no `first-account-setup-code` file, and logs only
|
|
510
|
-
that the code is in `AUTH_LOCAL_SETUP_CODE`, never the code itself.
|
|
511
|
-
|
|
563
|
+
that the code is in `AUTH_LOCAL_SETUP_CODE`, never the code itself. In
|
|
564
|
+
development and test the variable is ignored.
|
|
512
565
|
|
|
513
566
|
## One-time pass sign-in (local auth)
|
|
514
567
|
|
|
@@ -585,7 +638,8 @@ page shows the reason:
|
|
|
585
638
|
| `auth.pass.wrongResource` | 401 | For another resource. |
|
|
586
639
|
| `auth.pass.expired` | 401 | Expired (30 seconds of clock difference are allowed). |
|
|
587
640
|
| `auth.pass.replayed` | 401 | Already used, on this server or another sharing its store. |
|
|
588
|
-
| `auth.pass.unmapped` | 403 | The mapping names no account
|
|
641
|
+
| `auth.pass.unmapped` | 403 | The mapping names no account. |
|
|
642
|
+
| `auth.local.login.disabled` | 403 | The mapping names a disabled account; the reason is the account's message (see `disable` above). |
|
|
589
643
|
|
|
590
644
|
Each pass signs in once. Local auth records each pass it accepts, by the hash
|
|
591
645
|
of its id, until it could no longer be used anyway (30 seconds after it
|
|
@@ -708,10 +762,11 @@ taken. A test that composes the library directly and reads the sent email
|
|
|
708
762
|
waits for it: it passes `deliveries: createLocalDeliveries({ logger })` to
|
|
709
763
|
`createLocalAuthService()` and awaits `deliveries.settled()`.
|
|
710
764
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
765
|
+
Staging and production are `APP_ENV=staging` and `APP_ENV=production` (see
|
|
766
|
+
[Environments](/guide/framework/environments)), which the host that serves the
|
|
767
|
+
application sets. A staging or production server with
|
|
768
|
+
`AUTH_LOCAL_RECOVERY_DEV_OUTPUT` set refuses to start and names the setting to
|
|
769
|
+
remove, rather than ignoring it.
|
|
715
770
|
|
|
716
771
|
### Pre-release migration
|
|
717
772
|
|
|
@@ -735,6 +790,53 @@ or compatibility adapter.
|
|
|
735
790
|
the completed password-reset flow before releasing the updated application.
|
|
736
791
|
This change does not alter identity, session or recovery-token storage.
|
|
737
792
|
|
|
793
|
+
## Email change (local auth)
|
|
794
|
+
|
|
795
|
+
A person changes their email by proving the new address: local auth sends it a
|
|
796
|
+
link, and only using the link changes the email.
|
|
797
|
+
|
|
798
|
+
- The signed-in person asks with their password: `POST /api/email-change`
|
|
799
|
+
with `{ email, password }` (the action `auth.emailChange.request`, the
|
|
800
|
+
service's `requestEmailChange(request, input)`). An account with no password
|
|
801
|
+
sets one first, through a password reset.
|
|
802
|
+
- The application asks for an account it chose, without a password:
|
|
803
|
+
`authService.requestEmailChangeForUser({ userId, email })`, for example an
|
|
804
|
+
operator's change for a person who lost their old address. Who may ask is the
|
|
805
|
+
application's decision, so it has no route; the application's own action
|
|
806
|
+
checks its caller first.
|
|
807
|
+
- The link opens `/auth/email-change?token=...`, the `auth.email-change` route,
|
|
808
|
+
whose page (`DefaultEmailChangeView` from `@jskit-ai/auth-web`) posts the
|
|
809
|
+
token to `POST /api/email-change/confirm` (`confirmEmailChange({ token })`),
|
|
810
|
+
public, since the link proves who uses it, and shows the new email. The
|
|
811
|
+
application adds the page as it adds the reset page, rendering the view in
|
|
812
|
+
`src/pages/auth/email-change.vue`.
|
|
813
|
+
|
|
814
|
+
The account keeps the new address as its waiting change until the link is
|
|
815
|
+
used; a newer request replaces it, so an earlier link stops working. A link
|
|
816
|
+
works for a day and once. Using it changes the email, ends the password resets
|
|
817
|
+
sent to the old address, and sends the old address a notice; the account's
|
|
818
|
+
sessions stay signed in and show the new email from their next request. Each
|
|
819
|
+
refusal has its code: `auth.local.emailChange.passwordInvalid` and `sameEmail`
|
|
820
|
+
(400), `emailTaken` (409, also when another account took the address after the
|
|
821
|
+
link was sent), `linkInvalid` (400: used, replaced, expired or altered) and
|
|
822
|
+
`accountNotFound` (404, the application's request for an id with no account).
|
|
823
|
+
|
|
824
|
+
The application sends the links and notices through the optional
|
|
825
|
+
`auth.local.email-change-sender` capability, an async function given
|
|
826
|
+
`{ type: "confirmation", email, currentEmail, confirmationUrl }` (to the new
|
|
827
|
+
address) or `{ type: "notice", email, newEmail }` (to the old one). It is wired
|
|
828
|
+
like the recovery sender above and sends as `APP_ENV` says, as it does:
|
|
829
|
+
production to each address, staging only to `STAGING_EMAIL_TO` (with
|
|
830
|
+
`originalEmail`), development and test to the log. It runs after the request
|
|
831
|
+
has answered, and a failure is logged with the address, never answered.
|
|
832
|
+
Without one, development and test log each link and notice, and a staging or
|
|
833
|
+
production server has no email change: `features.emailChange` is false and the
|
|
834
|
+
operations answer
|
|
835
|
+
`AUTH_OPERATION_UNSUPPORTED`. A sender needs `APP_PUBLIC_URL`, which its links
|
|
836
|
+
name. The database backend keeps the waiting change in
|
|
837
|
+
`auth_local_users.pending_email` (migration `auth_local_db_users_pending_email`)
|
|
838
|
+
and sets `email_verified_at` when the link is used.
|
|
839
|
+
|
|
738
840
|
## Google, Microsoft and GitHub sign-in with local auth
|
|
739
841
|
|
|
740
842
|
Local auth signs people in through Google, Microsoft and GitHub when the
|
|
@@ -798,8 +900,8 @@ the `auth_local_identities` and `auth_local_oauth_attempts` tables.
|
|
|
798
900
|
## Browser boundary
|
|
799
901
|
|
|
800
902
|
`@jskit-ai/auth-web` owns the normal auth views, guard runtime, sign-out flow,
|
|
801
|
-
and auth-aware HTTP integration. `DefaultLoginView`, `DefaultResetPasswordView
|
|
802
|
-
and `DefaultSignOutView` fill the window themselves: a card on
|
|
903
|
+
and auth-aware HTTP integration. `DefaultLoginView`, `DefaultResetPasswordView`,
|
|
904
|
+
`DefaultEmailChangeView` and `DefaultSignOutView` fill the window themselves: a card on
|
|
803
905
|
`surface-container` on wide windows, the whole screen on phones, and each
|
|
804
906
|
screen's one `h1` ("Sign in", "Create your account", "Reset password", ...).
|
|
805
907
|
Every app shows its identity there, so a person always sees which app they are
|
|
@@ -808,7 +910,8 @@ beside the card on wide windows (`primary-container`, its children from top to
|
|
|
808
910
|
bottom) and a compact row above the card on phones. The slot gets `{ compact }`
|
|
809
911
|
to choose what to show, and holds no heading. The `auth/auth-surface` pattern
|
|
810
912
|
does this already: its pages render the app's view wrappers
|
|
811
|
-
(`src/views/auth/LoginView.vue`, `ResetPasswordView.vue`, `
|
|
913
|
+
(`src/views/auth/LoginView.vue`, `ResetPasswordView.vue`, `EmailChangeView.vue`,
|
|
914
|
+
`SignOutView.vue`),
|
|
812
915
|
and each fills the slot with `src/components/AppBrand.vue`, the app's name as
|
|
813
916
|
`index.html`'s `<title>` spells it. Renaming the app renames both:
|
|
814
917
|
|
|
@@ -128,15 +128,16 @@ these headers itself keeps its own value.
|
|
|
128
128
|
| --- | --- | --- |
|
|
129
129
|
| `X-Content-Type-Options: nosniff` | always | on |
|
|
130
130
|
| `Referrer-Policy` | always | `strict-origin-when-cross-origin` |
|
|
131
|
-
| `Strict-Transport-Security` | production | `max-age=31536000` |
|
|
132
|
-
| `Content-Security-Policy: frame-ancestors` | production | `'self'` |
|
|
133
|
-
| `Content-Security-Policy-Report-Only` | production | the content policy below |
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
nosniff and the Referrer-Policy, so
|
|
139
|
-
frame the application and inject its
|
|
131
|
+
| `Strict-Transport-Security` | staging, production | `max-age=31536000` |
|
|
132
|
+
| `Content-Security-Policy: frame-ancestors` | staging, production | `'self'` |
|
|
133
|
+
| `Content-Security-Policy-Report-Only` | staging, production | the content policy below |
|
|
134
|
+
|
|
135
|
+
Staging and production are `APP_ENV=staging` and `APP_ENV=production` (see
|
|
136
|
+
[Environments](/guide/framework/environments)), which the host sets beside
|
|
137
|
+
`NODE_ENV=production`, for example `env APP_ENV=production NODE_ENV=production
|
|
138
|
+
npm start`. Development and test send only nosniff and the Referrer-Policy, so
|
|
139
|
+
an editor's preview, such as Vibe64's, can frame the application and inject its
|
|
140
|
+
bridge script.
|
|
140
141
|
|
|
141
142
|
The content policy allows JSKIT's client: the application's own scripts and
|
|
142
143
|
WebAssembly, inline styles (Vuetify and the loading shell use them), images
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/app-setup/more-than-one-server.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
title: Run on More than One Server
|
|
5
|
+
description: Run a JSKIT app as several copies behind a load balancer, with files in an S3 bucket, live updates through Redis, sessions in the database, the same secrets on every copy, a lock for scheduled work and one migration run.
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Run on More than One Server
|
|
9
|
+
|
|
10
|
+
An app can run as several copies, on one machine or several, behind a load
|
|
11
|
+
balancer that sends each request to any of them. The copies share the
|
|
12
|
+
database. What one copy keeps on its own disk or in its own memory, the others
|
|
13
|
+
never see. Settle each item below before starting a second copy.
|
|
14
|
+
|
|
15
|
+
## Files
|
|
16
|
+
|
|
17
|
+
`runtime.storage`, where uploads and profile pictures go, keeps its files in a
|
|
18
|
+
folder on the machine by default, so a picture saved through one copy is
|
|
19
|
+
missing on the others. Point every copy at the same bucket:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
JSKIT_STORAGE_DRIVER=s3
|
|
23
|
+
JSKIT_STORAGE_S3_BUCKET=shop-files
|
|
24
|
+
JSKIT_STORAGE_S3_REGION=eu-west-1
|
|
25
|
+
# R2, MinIO or another S3-compatible store; empty for AWS.
|
|
26
|
+
JSKIT_STORAGE_S3_ENDPOINT=
|
|
27
|
+
JSKIT_STORAGE_S3_ACCESS_KEY_ID=
|
|
28
|
+
JSKIT_STORAGE_S3_SECRET_ACCESS_KEY=
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A missing required setting stops the app at startup, naming it. Give the
|
|
32
|
+
storage a bucket of its own. The `@jskit-ai/storage-runtime` README lists what
|
|
33
|
+
the `s3` driver does not do, such as listing past 1,000 objects; JSKIT's own
|
|
34
|
+
packages need none of it.
|
|
35
|
+
|
|
36
|
+
## Live updates
|
|
37
|
+
|
|
38
|
+
With `@jskit-ai/realtime`, each copy delivers an event only to the browsers
|
|
39
|
+
connected to it, unless every copy names the same Redis:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
REALTIME_REDIS_URL=redis://redis.internal:6379
|
|
43
|
+
# Only when other apps share this Redis: keeps this app's channels apart.
|
|
44
|
+
REDIS_NAMESPACE=shop
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Socket.IO starts each connection with HTTP long-polling, whose requests must
|
|
48
|
+
all reach the copy that opened it. Keep each browser on one copy at the load
|
|
49
|
+
balancer (sticky sessions), or connect by WebSocket only with
|
|
50
|
+
`realtimeClient: { options: { transports: ["websocket"] } }` in the app's
|
|
51
|
+
public config.
|
|
52
|
+
|
|
53
|
+
An assistant conversation's live progress reaches only the browsers connected
|
|
54
|
+
to the copy running its turn, with or without Redis; a browser on another copy
|
|
55
|
+
sees the saved conversation when it opens it again.
|
|
56
|
+
|
|
57
|
+
## Sign-in sessions
|
|
58
|
+
|
|
59
|
+
- Local sign-in with `@jskit-ai/auth-provider-local-db-core` keeps accounts and
|
|
60
|
+
sessions in the database, so any copy reads any session and a sign-out or
|
|
61
|
+
revocation holds on all of them. Without that package, they are files in
|
|
62
|
+
`AUTH_LOCAL_STORE_DIR` (`.jskit/auth`) on each machine, which several copies
|
|
63
|
+
cannot share, not even on a shared folder: its lock assumes one machine.
|
|
64
|
+
- OIDC sign-in keeps sessions in the database, and Supabase sign-in in the
|
|
65
|
+
browser's cookies; both work on any copy.
|
|
66
|
+
- Every copy needs the same `AUTH_LOCAL_SESSION_SECRET`,
|
|
67
|
+
`AUTH_LOCAL_SECOND_FACTOR_KEY`, `AUTH_OIDC_SESSION_SECRET` and
|
|
68
|
+
`OIDC_HUB_SECRET`, as the app uses them. Staging and production (`APP_ENV`,
|
|
69
|
+
see [Environments](/guide/framework/environments)) refuse to start without
|
|
70
|
+
the session secrets; in development and test a missing one is generated into
|
|
71
|
+
a file on each machine, so set them there too for several copies.
|
|
72
|
+
- On an empty staging or production database each copy makes its own
|
|
73
|
+
first-account setup code, and a code from one copy is refused by the others.
|
|
74
|
+
Set `AUTH_LOCAL_SETUP_CODE` on every copy, or run one copy until the first
|
|
75
|
+
account exists.
|
|
76
|
+
|
|
77
|
+
## What each copy keeps to itself
|
|
78
|
+
|
|
79
|
+
- Request limits, a route's `rateLimit` and auth's limits on sign-in,
|
|
80
|
+
registration, recovery and codes, count in each copy's memory: with three
|
|
81
|
+
copies a client gets up to three times the limit. Local sign-in's wait for
|
|
82
|
+
an account after repeated failures is kept in the database and holds across
|
|
83
|
+
copies.
|
|
84
|
+
- An assistant conversation's one-turn-at-a-time check, steer and stop act on
|
|
85
|
+
the copy running the turn. Sent to another copy, a second message is not
|
|
86
|
+
refused and a stop does not stop the turn. Sticky sessions keep a browser's
|
|
87
|
+
requests on one copy.
|
|
88
|
+
- `@jskit-ai/agent-runtime` writes command output under the system's temporary
|
|
89
|
+
folder, so another copy cannot read a command's full output; point
|
|
90
|
+
`createCommands`' `outputDir` at a folder every copy shares.
|
|
91
|
+
|
|
92
|
+
## Scheduled work
|
|
93
|
+
|
|
94
|
+
Work the app runs on a timer inside its own process, with `setInterval` or a
|
|
95
|
+
cron library, runs once in every copy. Make each run take a lock before it
|
|
96
|
+
works, as `@jskit-ai/agent-runtime`'s goal, run and summary loops do: one copy
|
|
97
|
+
claims a lease row with a conditional update, and the others find it taken
|
|
98
|
+
and skip. Work that only deletes expired rows can run in every copy, as the
|
|
99
|
+
OIDC hub's upkeep does.
|
|
100
|
+
|
|
101
|
+
## Migrations
|
|
102
|
+
|
|
103
|
+
Where the host has a Migrate step, run migrations once per release through
|
|
104
|
+
it, `npm run db:migrate` (`<name>-migrate` in a
|
|
105
|
+
[Nix package](/guide/app-setup/package-with-nix)), before the new copies
|
|
106
|
+
start. `npm run db:prepare` also runs the app's seed, so it runs once too, not
|
|
107
|
+
on every copy. A host with no such step migrates from each copy's start
|
|
108
|
+
(`<name> --migrate`) and restarts a copy that fails: Knex's migration lock
|
|
109
|
+
lets one copy migrate, and on PostgreSQL the others wait and then find nothing
|
|
110
|
+
left to do, while on MySQL they fail and start again, as the Nix guide's
|
|
111
|
+
[Migrations](/guide/app-setup/package-with-nix#migrations) section says.
|
|
@@ -228,8 +228,8 @@ To send invitation email, provide the optional `workspaces.invite-mailer`
|
|
|
228
228
|
capability from one of the application's providers. Without one, invitations
|
|
229
229
|
are still created and delivery reports `mailer_unconfigured`. After **Send
|
|
230
230
|
invite**, the Members panel's notice follows the delivery status: `sent` says
|
|
231
|
-
the invite was sent; `simulated` (
|
|
232
|
-
|
|
231
|
+
the invite was sent; `simulated` (logged outside production, see
|
|
232
|
+
[Environments](/guide/framework/environments)) and `mailer_unconfigured` say no email was sent; `held` says email
|
|
233
233
|
isn't set up yet, so the invite will be sent once it is; `failed` is a warning
|
|
234
234
|
that the email failed. Each of those four points to the invite link, which
|
|
235
235
|
the panel shows under the form with its **Copy** button. For a status the
|
|
@@ -83,36 +83,81 @@ environment's. The option is not called `--env-file` because Node reads an
|
|
|
83
83
|
|
|
84
84
|
| Program | What it does |
|
|
85
85
|
| --- | --- |
|
|
86
|
-
| `<name> [--env FILE] [--migrate]` | Runs the app's `start` script as `npm start` would, without npm, in place of itself: from `lib/<name>`, with `node_modules/.bin` and Node first on `PATH`, and `NODE_ENV=production` unless the environment or the file says otherwise. With `--migrate`, runs `db:migrate` first and starts nothing when it fails. |
|
|
86
|
+
| `<name> [--env FILE] [--migrate]` | Runs the app's `start` script as `npm start` would, without npm, in place of itself: from `lib/<name>`, with `node_modules/.bin` and Node first on `PATH`, and `NODE_ENV=production` unless the environment or the file says otherwise. With `--migrate`, runs `db:migrate` first and starts nothing when it fails; an app with no `db:migrate` script has nothing to migrate, so it starts (and says so), and one service command fits every app. |
|
|
87
87
|
| `<name>-migrate [--env FILE]` | Runs the `db:migrate` script the same way. Only an app with one has it. |
|
|
88
88
|
| `<name>-check [--env FILE] [--wait SECONDS]` | Exits 0 once `GET /api/health` answers 200 on `HOST`:`PORT` (127.0.0.1 when `HOST` is unset or any address; port 3000 when `PORT` is unset), and 1 after `--wait` seconds (60). |
|
|
89
|
-
| `<name>-prepare --settings JSON --env FILE [--user NAME]` | Writes the settings, one JSON object of environment variables (each a string, a number or `true`/`false`), as `FILE`, mode 0600, owned by `NAME` (`chown NAME:`). It is for a host that hands an app's settings to a step run as root before its services start. |
|
|
89
|
+
| `<name>-prepare --settings JSON --env FILE [--user NAME]` | Writes the settings, one JSON object of environment variables (each a string, a number or `true`/`false`), as `FILE`, mode 0600, owned by `NAME` (`chown NAME:`). It also makes each folder the settings name for the app's files with an absolute path (`JSKIT_STORAGE_FS_BASE_PATH`, `AUTH_LOCAL_STORE_DIR`, `AUTH_OIDC_STORE_DIR`), mode 0700 when it makes it, owned by `NAME`. It is for a host that hands an app's settings to a step run as root before its services start. |
|
|
90
90
|
|
|
91
91
|
## Running it
|
|
92
92
|
|
|
93
93
|
- The app's folder is read-only. A JSKIT package that writes files keeps them
|
|
94
94
|
under the app's folder unless told otherwise, so point those at a writable
|
|
95
95
|
data folder in the settings: `JSKIT_STORAGE_FS_BASE_PATH` (uploads and
|
|
96
|
-
`runtime.storage`; `data/storage` by default)
|
|
96
|
+
`runtime.storage`; `data/storage` by default), `AUTH_LOCAL_STORE_DIR`
|
|
97
97
|
(local sign-in's files, such as the first account's setup code;
|
|
98
|
-
`.jskit/auth` by default)
|
|
98
|
+
`.jskit/auth` by default) and, with OIDC sign-in, `AUTH_OIDC_STORE_DIR`.
|
|
99
|
+
`<name>-prepare --user NAME` makes those folders for the user the service
|
|
100
|
+
runs as, so a host's data folder that root owns needs nothing else. With
|
|
101
|
+
`JSKIT_STORAGE_DRIVER=s3`, `runtime.storage` writes to an S3 bucket instead,
|
|
102
|
+
as several instances need.
|
|
99
103
|
- Secrets come at run time, in the env file or the service's environment,
|
|
100
104
|
never in the package: anyone who can read the Nix store can read a package.
|
|
101
|
-
- The server listens where its `server.js` says: in a JSKIT
|
|
102
|
-
|
|
105
|
+
- The server listens where its `server.js` says: `HOST` (0.0.0.0 in a JSKIT
|
|
106
|
+
app) and `PORT`, whose default differs between apps (3000 or 3001). Set
|
|
107
|
+
`PORT` in the settings, so the server, the check and the host agree.
|
|
103
108
|
- The database comes from the app's own settings: `DATABASE_URL`, or
|
|
104
|
-
`DB_CLIENT`, `DB_HOST`, `DB_NAME` and
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
`DB_CLIENT`, `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and `DB_PASSWORD`
|
|
110
|
+
(each of these wins over the same part of the URL), as the
|
|
111
|
+
[database layer](/guide/app-setup/database-layer) guide says. Set
|
|
112
|
+
`DB_CLIENT` (`pg` or `mysql2`) when the app's own server code picks a
|
|
113
|
+
default for it. `/api/health` answers 200 only while the database answers,
|
|
114
|
+
so a host's check of a new build needs a database too.
|
|
115
|
+
- `APP_ENV` says where the app runs: `production`, or `staging` for a copy
|
|
116
|
+
that must not act for real, such as a build-check machine, which leaves the
|
|
117
|
+
`STAGING_*` addresses unset so everything is logged
|
|
118
|
+
([Environments](/guide/framework/environments)). The host sets it: the
|
|
119
|
+
package never guesses it, and a server without one refuses to start. The
|
|
120
|
+
programs default `NODE_ENV` to `production`, the build the package holds.
|
|
121
|
+
- Behind a load balancer or proxy, `TRUSTED_PROXIES` names its addresses, as
|
|
122
|
+
the [authentication](/guide/app-setup/authentication) guide says, and
|
|
123
|
+
`APP_PUBLIC_URL` is the address people use.
|
|
124
|
+
|
|
125
|
+
Several instances of one app behind a load balancer need the same settings
|
|
126
|
+
on every instance and nothing kept on one server's disk: files in S3,
|
|
127
|
+
sessions in the database, the same secrets and setup code, and Redis for live
|
|
128
|
+
updates, as [Run on more than one server](/guide/app-setup/more-than-one-server)
|
|
129
|
+
says.
|
|
130
|
+
|
|
131
|
+
## Migrations
|
|
132
|
+
|
|
133
|
+
Run them in the service: `<name> --migrate`. A host that runs no release step
|
|
134
|
+
needs nothing else, and a database that is not up yet only delays the start:
|
|
135
|
+
the migration fails, the service exits, and the host's restart tries again.
|
|
136
|
+
|
|
137
|
+
When several instances start at once, each runs `db:migrate` and Knex's own
|
|
138
|
+
lock lets one migrate. Knex takes that lock in the transaction its migrations
|
|
139
|
+
run in (every JSKIT migration runs in one), so:
|
|
140
|
+
|
|
141
|
+
- on PostgreSQL the others wait for that transaction, then find nothing left
|
|
142
|
+
to migrate and start. A migrator that dies has its transaction rolled back,
|
|
143
|
+
its lock with it, and the next start migrates;
|
|
144
|
+
- on MySQL and MariaDB a table change commits at once, so the others fail
|
|
145
|
+
(`Migration table is already locked`) and start again once their service
|
|
146
|
+
restarts them, and a migrator that dies part way leaves the lock set until
|
|
147
|
+
`knex migrate:unlock` frees it;
|
|
148
|
+
- on a database that has never been migrated, instances that start at the
|
|
149
|
+
same moment can both try to create Knex's own tables: one fails, and its
|
|
150
|
+
restart finds them there.
|
|
151
|
+
|
|
152
|
+
So every host that starts several instances must restart a failed one, and
|
|
153
|
+
migrations must be written to run next to the release before them while a
|
|
154
|
+
rollout replaces instances (add first, remove in a later release).
|
|
110
155
|
|
|
111
156
|
A host that runs apps as Nix packages typically runs the app `shop` as:
|
|
112
157
|
|
|
113
158
|
- a step run as root at each start, before the service:
|
|
114
159
|
`bin/shop-prepare --settings <the host's settings file> --env /run/shop/env --user shop`;
|
|
115
|
-
- one service, run as the user `shop
|
|
116
|
-
`bin/shop --env /run/shop/env --migrate`, on port
|
|
117
|
-
`/api/health` answers 200;
|
|
160
|
+
- one service, run as the user `shop` and restarted when it fails:
|
|
161
|
+
`bin/shop --env /run/shop/env --migrate`, on the port its `PORT` setting
|
|
162
|
+
names, healthy when `/api/health` answers 200;
|
|
118
163
|
- a check after it starts: `bin/shop-check --env /run/shop/env`.
|
|
@@ -338,7 +338,7 @@ that advertises it.
|
|
|
338
338
|
|
|
339
339
|
## Host-only production cookies
|
|
340
340
|
|
|
341
|
-
In production (`
|
|
341
|
+
In staging and production (`APP_ENV`, served over HTTPS) the session cookies of
|
|
342
342
|
the local, Supabase and OIDC auth providers and the CSRF secret cookie use the
|
|
343
343
|
`__Host-` prefix, for example `__Host-jskit_local_access_token` and
|
|
344
344
|
`__Host-_csrf`. Browsers accept these only with `Secure`, `Path=/` and no
|
|
@@ -370,3 +370,38 @@ defaults need no change and an unreachable read makes three requests, not nine.
|
|
|
370
370
|
Writes and `requestStream()` have no default overall deadline. They accept an
|
|
371
371
|
explicit `timeoutMs`; long-lived streams still need lifecycle cancellation.
|
|
372
372
|
These safeguards do not limit request volume or govern raw `fetch` calls.
|
|
373
|
+
|
|
374
|
+
## Say where the application runs: APP_ENV
|
|
375
|
+
|
|
376
|
+
`APP_ENV` (`development`, `test`, `staging` or `production`) replaces
|
|
377
|
+
`SIDE_EFFECTS` and every decision `NODE_ENV` used to make; `NODE_ENV` now only
|
|
378
|
+
picks optimised builds ([Environments](/guide/framework/environments)). A server
|
|
379
|
+
without a known `APP_ENV` refuses to start, naming the fix.
|
|
380
|
+
|
|
381
|
+
- Development: add `APP_ENV=development` to `.env` and to `.env.example`. The
|
|
382
|
+
foundations' `bin/develop.js` sets it, and their `dev` scripts run
|
|
383
|
+
`APP_ENV=development vite`; an older application adds the same.
|
|
384
|
+
- Staging: set `APP_ENV=staging` and `NODE_ENV=production`, plus
|
|
385
|
+
`STAGING_EMAIL_TO` and `STAGING_SMS_TO` for the testers' inbox and phone
|
|
386
|
+
(unset, email and SMS are logged). Staging needs production's secrets.
|
|
387
|
+
- Production: set `APP_ENV=production` and `NODE_ENV=production`, and remove
|
|
388
|
+
`SIDE_EFFECTS`.
|
|
389
|
+
- Tests: `jskit test` and the browser test servers set `APP_ENV=test`. A test
|
|
390
|
+
that passes its own environment object to a runtime, a provider or a gate adds
|
|
391
|
+
`APP_ENV`, since nothing guesses it; one that proves a real sender passes
|
|
392
|
+
`APP_ENV: "production"` instead of `SIDE_EFFECTS: "live"`.
|
|
393
|
+
- Code: `createConnectionService` and `createPaymentCheckoutService` take
|
|
394
|
+
`appEnv: appEnvironment(env)` in place of `sideEffects`, and require it. The
|
|
395
|
+
live-payment refusal's code is `payment_sandbox_only`, not
|
|
396
|
+
`payment_test_copy`. `@jskit-ai/kernel/shared/support/sideEffects`,
|
|
397
|
+
`@jskit-ai/kernel/server/runtime/sideEffects` and
|
|
398
|
+
`@jskit-ai/kernel/server/runtime/runtimeMode` are gone: read
|
|
399
|
+
`@jskit-ai/kernel/shared/support/appEnvironment` (`appEnvironment`,
|
|
400
|
+
`isDeployed`) and `@jskit-ai/kernel/server/runtime/appEnvironment`
|
|
401
|
+
(`deliverMessage`, `markStagingEmail`, `logSideEffect`,
|
|
402
|
+
`assertDevelopmentOnlySettings`). The page's meta tag is
|
|
403
|
+
`jskit-app-environment` and the banner's test id
|
|
404
|
+
`jskit-app-environment-banner`.
|
|
405
|
+
- An installed `auth.local.confirmation-sender` or `auth.local.recovery-sender`
|
|
406
|
+
receives `originalEmail` in staging; show it in the email
|
|
407
|
+
(`markStagingEmail`).
|