@jskit-ai/agent-docs 0.1.331 → 0.1.332

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/guide/agent/app-extras/realtime.md +11 -3
  2. package/guide/agent/app-setup/authentication.md +29 -24
  3. package/guide/agent/app-setup/initial-scaffolding.md +10 -9
  4. package/guide/agent/app-setup/more-than-one-server.md +111 -0
  5. package/guide/agent/app-setup/multi-homing.md +2 -2
  6. package/guide/agent/app-setup/package-with-nix.md +60 -15
  7. package/guide/agent/app-setup/upgrading-jskit.md +36 -1
  8. package/guide/agent/framework/environments.md +174 -0
  9. package/guide/agent/framework/sanity-checks.md +3 -3
  10. package/guide/agent/framework/security-pass.md +7 -5
  11. package/guide/agent/index.md +6 -2
  12. package/package.json +1 -1
  13. package/patterns/feature-package/example/booking-engine/package.json +1 -1
  14. package/patterns/minimal-foundation/example/.env.example +8 -0
  15. package/patterns/minimal-foundation/example/AGENTS.md +7 -5
  16. package/patterns/minimal-foundation/example/bin/develop.js +2 -0
  17. package/patterns/minimal-foundation/example/package.json +6 -6
  18. package/patterns/shell-foundation/example/.env.example +8 -0
  19. package/patterns/shell-foundation/example/AGENTS.md +7 -5
  20. package/patterns/shell-foundation/example/bin/develop.js +2 -0
  21. package/patterns/shell-foundation/example/package.json +7 -7
  22. package/patterns/shell-foundation/example/packages/main/package.json +1 -1
  23. package/reference/autogen/KERNEL_MAP.md +10 -11
  24. package/reference/autogen/PATTERN_INDEX.md +38 -38
  25. package/reference/autogen/packages/auth-core.md +2 -2
  26. package/reference/autogen/packages/auth-provider-local-core.md +9 -9
  27. package/reference/autogen/packages/auth-provider-oidc-core.md +1 -1
  28. package/reference/autogen/packages/auth-provider-supabase-core.md +2 -2
  29. package/reference/autogen/packages/connectors-core.md +2 -2
  30. package/reference/autogen/packages/kernel.md +32 -27
  31. package/reference/autogen/packages/oidc-issuer-core.md +4 -4
  32. package/reference/autogen/packages/payments-core.md +1 -1
  33. package/reference/autogen/packages/shell-web.md +13 -13
  34. package/reference/autogen/packages/storage-runtime.md +6 -0
  35. package/reference/autogen/packages/workspaces-core.md +4 -4
  36. package/reference/autogen/tooling/jskit-catalog.md +6 -1
  37. package/skills/jskit/SKILL.md +2 -1
  38. package/skills/jskit/references/environments.md +169 -0
  39. package/skills/jskit/references/heuristics/INDEX.md +1 -1
  40. package/skills/jskit/references/multi-homing.md +2 -2
  41. package/skills/jskit/references/package-with-nix.md +60 -15
  42. package/skills/jskit/references/pattern-index.md +38 -38
  43. package/skills/jskit/references/patterns/app/minimal-foundation/example/.env.example +8 -0
  44. package/skills/jskit/references/patterns/app/minimal-foundation/example/AGENTS.md +7 -5
  45. package/skills/jskit/references/patterns/app/minimal-foundation/example/bin/develop.js +2 -0
  46. package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +6 -6
  47. package/skills/jskit/references/patterns/app/shell-foundation/example/.env.example +8 -0
  48. package/skills/jskit/references/patterns/app/shell-foundation/example/AGENTS.md +7 -5
  49. package/skills/jskit/references/patterns/app/shell-foundation/example/bin/develop.js +2 -0
  50. package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +7 -7
  51. package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
  52. package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
  53. package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
  54. package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
  55. package/skills/jskit/references/patterns/connectors/api-key-connection/PATTERN.md +4 -1
  56. package/skills/jskit/references/patterns/connectors/api-key-connection/example/connections.js +3 -3
  57. package/skills/jskit/references/patterns/connectors/calendar-cli/example/.env.example +1 -0
  58. package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +5 -4
  59. package/skills/jskit/references/patterns/connectors/calendar-cli/example/scripts/calendar.js +3 -1
  60. package/skills/jskit/references/patterns/connectors/firebase-messaging/example/server/notifications.js +3 -3
  61. package/skills/jskit/references/patterns/connectors/oauth-connection/PATTERN.md +3 -1
  62. package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
  63. package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
  64. package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
  65. package/skills/jskit/references/patterns/realtime/realtime-application/example/.env.example +1 -0
  66. package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
  67. package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
  68. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
  69. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
  70. package/skills/jskit/references/sanity-checks.md +3 -3
  71. package/skills/jskit/references/security-pass.md +7 -5
  72. package/guide/agent/framework/side-effects.md +0 -77
  73. package/skills/jskit/references/side-effects.md +0 -72
@@ -49,12 +49,12 @@ Exports
49
49
  - `resolveLocalAuthConfig({ appRoot, env, fileBackend, emailRecovery, emailConfirmationSender = false })`
50
50
  Local functions
51
51
  - `resolveStoreDir(env, appRoot)`
52
- - `resolveSessionSecret(env, { storeDir, isProduction })`
53
- - `resolveSecondFactorKey(env, { isProduction, sessionSecret })`
54
- - `resolveSetupCode(env, { isProduction })`
55
- - `resolveAppPublicUrl(env, { emailRecovery, emailedConfirmation, oauthEnabled, productionSecondFactor })`
56
- - `resolveRecoveryDelivery(env, { emailRecovery, isProduction })`
57
- - `resolveConfirmationDelivery(env, { emailConfirmationSender, isProduction, selfRegistration })`
52
+ - `resolveSessionSecret(env, { storeDir, isDeployed })`
53
+ - `resolveSecondFactorKey(env, { isDeployed, sessionSecret })`
54
+ - `resolveSetupCode(env, { isDeployed })`
55
+ - `resolveAppPublicUrl(env, { emailRecovery, emailedConfirmation, oauthEnabled, deployedSecondFactor })`
56
+ - `resolveRecoveryDelivery(env, { emailRecovery, isDeployed })`
57
+ - `resolveConfirmationDelivery(env, { emailConfirmationSender, isDeployed, selfRegistration })`
58
58
  - `resolvePasswordMinLength(env)`
59
59
 
60
60
  ### `src/server/lib/deliveries.js`
@@ -68,7 +68,6 @@ Exports
68
68
  - `confirmEveryRegistrationByLink()`
69
69
  - `createLocalEmailConfirmation({ backend, config, confirmationMode, confirmationSender, deliveries, firstAccountSetup, invitationContextResolver, logger, passwords, profileProjector, sessions })`
70
70
  - `createLoggedConfirmationSender(logger)`
71
- - `createSimulatedConfirmationSender(logger)`
72
71
  Local functions
73
72
  - `emailTakenError()`
74
73
  - `confirmationInvalidError()`
@@ -173,7 +172,6 @@ Exports
173
172
  Exports
174
173
  - `createLocalPasswordFlows({ backend, config, deliveries, passwords, profileProjector, recoverySender, sessions })`
175
174
  - `createLoggedRecoverySender(logger)`
176
- - `createSimulatedRecoverySender(logger)`
177
175
 
178
176
  ### `src/server/lib/passwords.js`
179
177
  Exports
@@ -235,7 +233,7 @@ Exports
235
233
 
236
234
  ### `src/server/lib/sessions.js`
237
235
  Exports
238
- - `cookieOptions({ isProduction, cookieSameSite }, maxAge)`
236
+ - `cookieOptions({ isDeployed, cookieSameSite }, maxAge)`
239
237
  - `createLocalSessions({ appProfileProjection, backend, config, profileProjector })`
240
238
  - `safeRequestCookies(request)`
241
239
  Local functions
@@ -274,6 +272,8 @@ Local functions
274
272
  ### `src/server/providers/AuthLocalProvider.js`
275
273
  Exports
276
274
  - `AuthLocalProvider`
275
+ Local functions
276
+ - `sendAsAppEnvironmentSays({ env, logger, sender, name })`
277
277
 
278
278
  ### `src/server/types.js`
279
279
  Exports
@@ -28,7 +28,7 @@ Local functions
28
28
  - `text(value)`
29
29
  - `parseAddress(value, name)`
30
30
  - `resolveAppName(appRoot)`
31
- - `resolveSessionSecret(env, { appRoot, isProduction })`
31
+ - `resolveSessionSecret(env, { appRoot, isDeployed })`
32
32
 
33
33
  ### `src/server/lib/index.js`
34
34
  Exports
@@ -25,8 +25,8 @@ Exports
25
25
  ### `src/server/lib/authCookies.js`
26
26
  Exports
27
27
  - `safeRequestCookies(request)`
28
- - `cookieOptions(isProduction, maxAge)`
29
- - `cookieClearOptions(isProduction)`
28
+ - `cookieOptions(isDeployed, maxAge)`
29
+ - `cookieClearOptions(isDeployed)`
30
30
 
31
31
  ### `src/server/lib/authenticatedProfile.js`
32
32
  Exports
@@ -22,7 +22,7 @@ Local functions
22
22
 
23
23
  ### `src/server/connectionService.js`
24
24
  Exports
25
- - `createConnectionService({ configuration, providers, resolveReference, store, authorize, executionMode = "application", fetchImpl = globalThis.fetch, now = Date.now, sideEffects = "simulate", logger = console })`
25
+ - `createConnectionService({ configuration, providers, resolveReference, store, authorize, executionMode = "application", fetchImpl = globalThis.fetch, now = Date.now, appEnv, logger = console })`
26
26
  Local functions
27
27
  - `publicConnection(connection)`
28
28
  - `connectionMatches(connection, integration, providerId, registration)`
@@ -94,7 +94,7 @@ Exports
94
94
  Exports
95
95
  - `SIMULATED_RESULT`
96
96
  - `connectionProvider(definition, integration)`
97
- - `createProviderRequests({ fetchImpl, now, resolveReference, sideEffects = "simulate", logger = console })`
97
+ - `createProviderRequests({ fetchImpl, now, resolveReference, appEnv, logger = console })`
98
98
  - `operationRequest(operation, input, settings, providerData)`
99
99
  - `requireOperationScope(operation, scopes, message, { messageCode })`
100
100
  - `tokenResponse(provider, response, details)`
@@ -64,6 +64,16 @@ Exports
64
64
  - `resolveLinkPath`
65
65
  - `normalizePathname`
66
66
 
67
+ ### `shared/support/appEnvironment.js`
68
+ Exports
69
+ - `APP_ENV_KEY`
70
+ - `APP_ENVIRONMENTS`
71
+ - `APP_ENVIRONMENT_META_NAME`
72
+ - `appEnvironment(env)`
73
+ - `isDeployed(env)`
74
+ - `pageAppEnvironment(documentObject = globalThis.document)`
75
+ - `withAppEnvironmentMeta(html, environment)`
76
+
67
77
  ### `shared/support/clientBuild.js`
68
78
  Exports
69
79
  - `CLIENT_BUILD_META_NAME`
@@ -215,17 +225,6 @@ Exports
215
225
  Local functions
216
226
  - `normalizePlacementRenderers(value = {})`
217
227
 
218
- ### `shared/support/sideEffects.js`
219
- Exports
220
- - `SIDE_EFFECTS_ENV_KEY`
221
- - `SIDE_EFFECTS_LIVE`
222
- - `SIDE_EFFECTS_META_NAME`
223
- - `SIDE_EFFECTS_SIMULATE`
224
- - `pageSideEffectsMode(documentObject = globalThis.document)`
225
- - `resolveSideEffectsMode(env)`
226
- - `sideEffectsAreLive(env)`
227
- - `withSideEffectsMeta(html, mode)`
228
-
229
228
  ### `shared/support/silentLogger.js`
230
229
  Exports
231
230
  - `silentLogger`
@@ -780,6 +779,12 @@ Exports
780
779
  Exports
781
780
  - `compileRouteValidator`
782
781
 
782
+ ### `server/http/appEnvironmentPage.js`
783
+ Exports
784
+ - `registerAppEnvironmentPage(fastify, { env })`
785
+ - `type RuntimeEnv`
786
+ - `type RuntimeFastify`
787
+
783
788
  ### `server/http/capabilityHttpRuntime.js`
784
789
  Exports
785
790
  - `createCapabilityHttpRuntime({ fastify, actions })`
@@ -947,12 +952,6 @@ Local functions
947
952
  - `resolveContentSecurityPolicyHeaders(settings)`
948
953
  - `resolveSecurityHeaders({ config, env })`
949
954
 
950
- ### `server/http/sideEffectsPage.js`
951
- Exports
952
- - `registerSideEffectsPage(fastify, { env })`
953
- - `type RuntimeEnv`
954
- - `type RuntimeFastify`
955
-
956
955
  ### `server/http/trustedProxies.js`
957
956
  Exports
958
957
  - `DEFAULT_TRUSTED_PROXIES`
@@ -1029,6 +1028,22 @@ Exports
1029
1028
  Local functions
1030
1029
  - `matchesGlobalUiPath(pathname, globalUiPaths)`
1031
1030
 
1031
+ ### `server/runtime/appEnvironment.js`
1032
+ Exports
1033
+ - `STAGING_ORIGINAL_TO_HEADER`
1034
+ - `assertAppEnvironment(env)`
1035
+ - `assertDevelopmentOnlySettings(env, names)`
1036
+ - `deliverMessage({ env, logger, channel, to, summary, details = {}, send })`
1037
+ - `logAppEnvironment(logger, env)`
1038
+ - `logSideEffect(logger, environment, { kind, summary, details = {}, reason = "" })`
1039
+ - `markStagingEmail(email, originalTo)`
1040
+ - `type RuntimeEnv`
1041
+ - `type RuntimeLogger`
1042
+ - `type AppEnvironment`
1043
+ Local functions
1044
+ - `stagingAddress(env, kind)`
1045
+ - `escapeHtml(value)`
1046
+
1032
1047
  ### `server/runtime/BootstrapProvider.js`
1033
1048
  Exports
1034
1049
  - `BootstrapProvider`
@@ -1097,11 +1112,6 @@ Exports
1097
1112
  - `safePathnameFromRequest(request)`
1098
1113
  - `resolveClientIpAddress(request)`
1099
1114
 
1100
- ### `server/runtime/runtimeMode.js`
1101
- Exports
1102
- - `assertDevelopmentOnlySettings(env, names)`
1103
- - `isProductionEnv(env)`
1104
-
1105
1115
  ### `server/runtime/serviceAuthorization.js`
1106
1116
  Exports
1107
1117
  - `requireAuth(source = {}, options = {})`
@@ -1111,11 +1121,6 @@ Local functions
1111
1121
  - `normalizeRequireAuthOptions(options = {})`
1112
1122
  - `requireAuthenticatedActor(context = {}, options = {})`
1113
1123
 
1114
- ### `server/runtime/sideEffects.js`
1115
- Exports
1116
- - `logSideEffectsMode(logger, env)`
1117
- - `logSimulatedSideEffect(logger, { kind, summary, details = {} })`
1118
-
1119
1124
  ### `server/support/appConfig.js`
1120
1125
  Exports
1121
1126
  - `resolveMobileConfig(appConfig)`
@@ -68,11 +68,11 @@ Exports
68
68
  - `resolveHubDevAuth(env)`
69
69
  Local functions
70
70
  - `text(value)`
71
- - `resolveIssuer(env, isProduction)`
71
+ - `resolveIssuer(env, deployed)`
72
72
  - `readOrCreateDevSecret(appRoot)`
73
- - `resolveSecret(env, { isProduction, appRoot })`
73
+ - `resolveSecret(env, { deployed, appRoot })`
74
74
  - `parseDevOriginPatterns(value)`
75
- - `resolveMail(env, { isProduction })`
75
+ - `resolveMail(env, { deployed })`
76
76
  - `resolveGoogle(env)`
77
77
 
78
78
  ### `src/server/crypto.js`
@@ -181,7 +181,7 @@ Local functions
181
181
  ### `src/server/mailer.js`
182
182
  Exports
183
183
  - `composeMessage({ heading, body, actionLabel, actionUrl, footer })`
184
- - `createMailer({ mail, logger, isProduction, fetchImpl })`
184
+ - `createMailer({ mail, env, logger, fetchImpl })`
185
185
 
186
186
  ### `src/server/oidcProvider.js`
187
187
  Exports
@@ -23,7 +23,7 @@ Local functions
23
23
 
24
24
  ### `src/server/checkout.js`
25
25
  Exports
26
- - `createPaymentCheckoutService({ adapter, store, payments, merchantScope, returnUrl, authorize, sideEffects = "simulate" })`
26
+ - `createPaymentCheckoutService({ adapter, store, payments, merchantScope, returnUrl, authorize, appEnv })`
27
27
 
28
28
  ### `src/server/errors.js`
29
29
  Exports
@@ -22,6 +22,14 @@ Exports
22
22
  Exports
23
23
  - `inspectVueArchitecture`
24
24
 
25
+ ### `src/client/appEnvironment/appEnvironmentBanner.js`
26
+ Exports
27
+ - `APP_ENVIRONMENT_BANNER_ID`
28
+ - `createAppEnvironmentBannerRuntime(options)`
29
+ - `installAppEnvironmentBanner({ documentObject = pageDocument(), environment = pageAppEnvironment(documentObject) } = {})`
30
+ Local functions
31
+ - `removeNothing()`
32
+
25
33
  ### `src/client/asyncModuleRecovery/index.js`
26
34
  Exports
27
35
  - `NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME`
@@ -566,14 +574,6 @@ Exports
566
574
  Local functions
567
575
  - `isPullRefreshQuery(query)`
568
576
 
569
- ### `src/client/sideEffects/testCopyBanner.js`
570
- Exports
571
- - `TEST_COPY_BANNER_ID`
572
- - `createTestCopyBannerRuntime(options)`
573
- - `installTestCopyBanner({ documentObject = pageDocument(), mode = pageSideEffectsMode(documentObject) } = {})`
574
- Local functions
575
- - `removeNothing()`
576
-
577
577
  ### `src/client/stores/useShellErrorPresentationStore.js`
578
578
  Exports
579
579
  - `useShellErrorPresentationStore`
@@ -806,23 +806,23 @@ Exports
806
806
  Exports
807
807
  - None
808
808
 
809
- ### `fixtures/production-build/src/App.vue`
809
+ ### `fixtures/app-environment-banner/src/main.js`
810
810
  Exports
811
811
  - None
812
812
 
813
- ### `fixtures/production-build/src/main.js`
813
+ ### `fixtures/app-environment-banner/vite.config.mjs`
814
814
  Exports
815
815
  - None
816
816
 
817
- ### `fixtures/production-build/vite.config.mjs`
817
+ ### `fixtures/production-build/src/App.vue`
818
818
  Exports
819
819
  - None
820
820
 
821
- ### `fixtures/test-copy-banner/src/main.js`
821
+ ### `fixtures/production-build/src/main.js`
822
822
  Exports
823
823
  - None
824
824
 
825
- ### `fixtures/test-copy-banner/vite.config.mjs`
825
+ ### `fixtures/production-build/vite.config.mjs`
826
826
  Exports
827
827
  - None
828
828
 
@@ -26,11 +26,17 @@ Exports
26
26
  Exports
27
27
  - `STORAGE_DRIVER_ENV_KEY`
28
28
  - `STORAGE_FS_BASE_PATH_ENV_KEY`
29
+ - `STORAGE_S3_ACCESS_KEY_ID_ENV_KEY`
30
+ - `STORAGE_S3_BUCKET_ENV_KEY`
31
+ - `STORAGE_S3_ENDPOINT_ENV_KEY`
32
+ - `STORAGE_S3_REGION_ENV_KEY`
33
+ - `STORAGE_S3_SECRET_ACCESS_KEY_ENV_KEY`
29
34
  - `DEFAULT_STORAGE_DRIVER`
30
35
  - `normalizeStorageDriver(value)`
31
36
  - `createStorageBinding({ env, appRoot })`
32
37
  Local functions
33
38
  - `resolveFsBasePath(fsBasePath, appRoot)`
39
+ - `createS3Driver(env)`
34
40
 
35
41
  ### `src/server/types.js`
36
42
  Exports
@@ -204,6 +204,10 @@ Local functions
204
204
  Exports
205
205
  - `registerWorkspaceDirectoryRoutes(router, { config, workspaceSelfCreateEnabled })`
206
206
 
207
+ ### `src/server/workspaceMembers/appEnvironmentInviteMailer.js`
208
+ Exports
209
+ - `createAppEnvironmentInviteMailer({ env, logger, mailer })`
210
+
207
211
  ### `src/server/workspaceMembers/defaultWorkspaceInviteEmail.js`
208
212
  Exports
209
213
  - `formatInviteExpiry(expiresAt, locale, timeZone)`
@@ -211,10 +215,6 @@ Exports
211
215
  Local functions
212
216
  - `escapeHtml(value)`
213
217
 
214
- ### `src/server/workspaceMembers/simulatedWorkspaceInviteMailer.js`
215
- Exports
216
- - `createSimulatedWorkspaceInviteMailer(logger)`
217
-
218
218
  ### `src/server/workspaceMembers/unconfiguredWorkspaceInviteMailer.js`
219
219
  Exports
220
220
  - `buildMailerUnconfiguredDelivery()`
@@ -294,9 +294,10 @@ Exports
294
294
  Local functions
295
295
  - `isObject(value)`
296
296
  - `scriptEnvironment({ app, envFile })`
297
- - `scriptOf(app, name)`
297
+ - `scriptOf(app, name, { optional = false } = {})`
298
298
  - `replaceWithScript({ app, shell, envFile, name, first })`
299
299
  - `check({ envFile, wait })`
300
+ - `chownTo(user, file)`
300
301
  - `prepare({ settings, envFile, user })`
301
302
  - `npmCache(list, cache)`
302
303
  - `isCliEntrypoint(argvPath = process.argv[1])`
@@ -417,6 +418,10 @@ Local functions
417
418
  - `exportedTableResources(namespace, isTableResource)`
418
419
  - `keyText({ tableName, columns, referencedTableName, referencedColumns })`
419
420
 
421
+ ### `scripts/test-environment.mjs`
422
+ Exports
423
+ - `useTestAppEnvironment(env, command)`
424
+
420
425
  ### `scripts/test-file-stop.mjs`
421
426
  Exports
422
427
  - `STOPPED_PREFIX`
@@ -50,7 +50,8 @@ manifests, migrations, tests, and runtime behaviour are the evidence.
50
50
  - [multi-homing](references/multi-homing.md) for workspaces or invitations.
51
51
  - [translation](references/translation.md) for languages, translated texts
52
52
  or error codes.
53
- - [side effects](references/side-effects.md) before sending email, messages or payments.
53
+ - [environments](references/environments.md) before code that sends email, messages or payments, or that
54
+ depends on where the app runs (APP_ENV).
54
55
  - [Nix packaging](references/package-with-nix.md) to package an app for a host
55
56
  that runs apps only as Nix packages, built with no network access.
56
57
  - For creation, foundation patterns, or package selection, read
@@ -0,0 +1,169 @@
1
+ <!-- Generated from `packages/agent-docs/site/guide/framework/environments.md`. -->
2
+
3
+ # Environments
4
+
5
+ Where an application runs is one environment variable, `APP_ENV`, with four
6
+ values. Everything JSKIT does differently by place reads it: what the
7
+ application sends, the development shortcuts, the security headers and the
8
+ banner on each page. `NODE_ENV` decides nothing else: it only picks optimised
9
+ builds, and staging and production set it to `production`.
10
+
11
+ | `APP_ENV` | Where | Email and SMS | Push, webhooks, connector writes | Payments | Development shortcuts | Banner |
12
+ | --- | --- | --- | --- | --- | --- | --- |
13
+ | `development` | a developer's machine, a session, a preview | logged | logged | sandbox only | allowed | "Development" |
14
+ | `test` | automated test runs | logged | logged | sandbox only | allowed | "Test" |
15
+ | `staging` | a deployed copy for checking the application | only to `STAGING_EMAIL_TO` and `STAGING_SMS_TO`; logged when unset | logged | sandbox only | refused | "Staging" |
16
+ | `production` | the application serving real people | sent | sent | live | refused | none |
17
+
18
+ The development shortcuts are dev sign-in (`AUTH_DEV_BYPASS_ENABLED`), cookies
19
+ without `Secure`, links in answers (`AUTH_LOCAL_RECOVERY_DEV_OUTPUT`), a first
20
+ account without a setup code, test databases, and a server that refuses to
21
+ start over a role grant no action requires (staging and production log it
22
+ instead). Staging and production add HSTS and the content security policy, and
23
+ need production's secrets, such as `AUTH_LOCAL_SESSION_SECRET` and a sender for
24
+ the emails they send.
25
+
26
+ ## Who sets what
27
+
28
+ The host sets `APP_ENV`; a request never chooses it. JSKIT's own commands set
29
+ it where they own the run.
30
+
31
+ | Who | `APP_ENV` | `NODE_ENV` | `STAGING_EMAIL_TO`, `STAGING_SMS_TO` |
32
+ | --- | --- | --- | --- |
33
+ | `npm run develop`, `npm run dev` on a developer's machine | `development`, set by the scripts | unset | unset |
34
+ | A hosted session or preview | `development` | unset | unset |
35
+ | `jskit test` and the browser test servers | `test`, set by JSKIT | anything | unset |
36
+ | A build-check machine that starts the packaged build to see it start and answer health | `staging` | `production` | unset, so everything is logged |
37
+ | A staging server | `staging` | `production` | the testers' inbox and phone |
38
+ | A production server | `production` | `production` | ignored |
39
+
40
+ A server started with `npm start` reads `APP_ENV` from its environment, or from
41
+ `.env` (`APP_ENV=development` on a developer's machine; the foundations'
42
+ `.env.example` says so). A host puts both variables in the server's
43
+ environment, beside its other settings:
44
+
45
+ ```sh
46
+ APP_ENV=staging NODE_ENV=production STAGING_EMAIL_TO=qa@example.com npm start
47
+ ```
48
+
49
+ `jskit test` and the browser test servers run as `APP_ENV=test` whatever the
50
+ shell says, and refuse to run where `APP_ENV` is `staging` or `production`.
51
+
52
+ ## Starting refuses what is not clear
53
+
54
+ A server stops at startup, saying what to do, when:
55
+
56
+ - `APP_ENV` is missing: `APP_ENV is not set. Set APP_ENV to development, test,
57
+ staging or production: development on a developer's machine or in a preview,
58
+ staging or production (with NODE_ENV=production) on a server.`
59
+ - `APP_ENV` is anything else: `APP_ENV is "dev", which is not an environment
60
+ JSKIT knows. Set APP_ENV to development, test, staging or production.`
61
+ - `APP_ENV` is `staging` or `production` and `NODE_ENV` is not `production`:
62
+ `APP_ENV is staging, so NODE_ENV must be production, and it is not set. Set
63
+ NODE_ENV=production: it only picks optimised builds, and APP_ENV decides
64
+ everything else.`
65
+ - `SIDE_EFFECTS`, which `APP_ENV` replaced, is set: `SIDE_EFFECTS was replaced
66
+ by APP_ENV: remove SIDE_EFFECTS. APP_ENV=production acts for real; staging
67
+ sends email and SMS only to STAGING_EMAIL_TO and STAGING_SMS_TO; development
68
+ and test only log.`
69
+ - A development-only setting is set in staging or production, for example
70
+ `AUTH_LOCAL_RECOVERY_DEV_OUTPUT is for development only and APP_ENV is
71
+ staging. Remove it from the staging environment.`
72
+
73
+ It then logs one line saying where it runs and what that means, such as
74
+ `APP_ENV is staging: email goes only to qa@example.com (STAGING_EMAIL_TO), SMS
75
+ is logged (STAGING_SMS_TO is not set); …`.
76
+
77
+ ## Staging's test addresses
78
+
79
+ Staging is production's code and settings with nobody real at the other end.
80
+ `STAGING_EMAIL_TO` is one address, such as the testers' shared inbox; every
81
+ email goes there instead of to its recipient. The email's first line, in its
82
+ text and HTML, says `Staging: this email was for ada@example.com.`, it carries
83
+ an `X-Staging-Original-To` header, and the log says
84
+ `Staging: the password reset email to ada@example.com was sent to
85
+ qa@example.com (STAGING_EMAIL_TO) instead.` `STAGING_SMS_TO` is one phone
86
+ number, and SMS goes there the same way. Unset, each is logged as development
87
+ logs it, with what a tester needs, such as its link. Push notifications,
88
+ webhooks and connector writes are always logged in staging, and live payments
89
+ are refused there, as everywhere but production.
90
+
91
+ ## What JSKIT does
92
+
93
+ - Every HTML page the server sends, and every page the Vite development server
94
+ sends, names its environment in a `jskit-app-environment` meta tag. The
95
+ shell (`@jskit-ai/shell-web`) shows a small "Development", "Test" or
96
+ "Staging" banner from it, with no application code, and none in production.
97
+ The banner never takes a click or a tap. Screen readers read it as a note,
98
+ with a sentence such as "Development: emails and messages are logged, not
99
+ sent; payments use the sandbox." as its description. It has no label, so a
100
+ browser test's `getByLabel("Email")` never finds it.
101
+ - Local-password emails (confirmation and password reset) with an installed
102
+ sender go out as the table says. In staging the sender gets
103
+ `STAGING_EMAIL_TO` as `email` and the person's address as `originalEmail`,
104
+ which its email should show (`markStagingEmail` does). An application that
105
+ confirms new accounts at once while its email isn't set up uses
106
+ `auth.local.confirmation-mode`, which applies everywhere (see
107
+ [Authentication](/guide/app-setup/authentication)).
108
+ - Workspace invitations with a provided mailer go out as the table says, the
109
+ staging copy marked with whom it was for. A logged invitation answers
110
+ `status: "simulated"`, and the inviter copies the link.
111
+ - Accounts-hub email goes out as the table says.
112
+ - Connector operations that act on the world (send an email or message, post,
113
+ book or cancel, charge, invoice, trigger another system's events) are marked
114
+ `sideEffect`. Outside production they are checked like real ones, then
115
+ logged, and `invoke` answers `{ simulated: true }`. Reads run for real.
116
+ `createConnectorsFeature` reads `APP_ENV` itself; give
117
+ `createConnectionService` and `createPaymentCheckoutService`
118
+ `appEnv: appEnvironment(env)`, which they require.
119
+ - Payment checkout and the billing portal in the live payment environment are
120
+ refused outside production with `payment_sandbox_only`; the sandbox
121
+ environment works everywhere.
122
+
123
+ Supabase sends its own authentication emails from Supabase's servers; JSKIT
124
+ cannot redirect them. Point development and staging at a separate Supabase
125
+ project.
126
+
127
+ ## The application's own side effects
128
+
129
+ Code the application writes that reaches the world follows the same rule. Send
130
+ email and SMS through `deliverMessage`, which sends, redirects or logs each as
131
+ `APP_ENV` says; log anything else outside production with `logSideEffect`.
132
+
133
+ ```js
134
+ import { deliverMessage, logSideEffect, markStagingEmail } from "@jskit-ai/kernel/server/runtime/appEnvironment";
135
+ import { appEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
136
+
137
+ function sendReminder({ env, logger, mailer }, message) {
138
+ return deliverMessage({
139
+ env,
140
+ logger,
141
+ channel: "email",
142
+ to: message.to,
143
+ summary: `the reminder to ${message.to}`,
144
+ details: { subject: message.subject },
145
+ send: (to, { originalTo }) => mailer.send(markStagingEmail({ ...message, to }, originalTo))
146
+ });
147
+ }
148
+
149
+ async function notifyDevice({ env, logger, push }, notification) {
150
+ const appEnv = appEnvironment(env);
151
+ if (appEnv !== "production") {
152
+ logSideEffect(logger, appEnv, {
153
+ kind: "push notification",
154
+ summary: `the reminder to device ${notification.deviceId}`,
155
+ details: { deviceId: notification.deviceId }
156
+ });
157
+ return { simulated: true };
158
+ }
159
+ return push.send(notification);
160
+ }
161
+ ```
162
+
163
+ - Read `env` from the `runtime.env` capability, never a request.
164
+ - A configured driver or key (`EMAIL_DRIVER=ses`, a live payment key) does not
165
+ make anything real; only `APP_ENV=production` does.
166
+ - Test each environment the code treats differently. A test that proves a real
167
+ sender against a fake transport passes `APP_ENV: "production"` (and
168
+ `NODE_ENV: "production"` when it starts a whole server), and a staging test
169
+ sets `STAGING_EMAIL_TO` and checks that only that address received it.
@@ -50,5 +50,5 @@ How to use it:
50
50
  - [typed-features.md](./typed-features.md)
51
51
  - client features, composable, `use<Name>`, Vue component, client provider, props, emits, `inject`, `provide`, `ref`, `reactive`, `watch`, `addEventListener`, `setInterval`, module state, `Object.freeze` on a composable, `?.()` in a template, `jskit/typed-inject`, `jskit/collaborator-props`, `jskit/fixed-result-shape`, `jskit/released-listeners`, `jskit/no-module-state`, `jskit/no-frozen-vue-state`, `clientFeaturesConfig`, `shared resource:`
52
52
  - [client-features.md](./client-features.md)
53
- - sanity checks, is this sane, query count that grows with the rows, a list that stops at 20 or 100 rows, `createDocument()` per row of a batch, `jskit test`, one file at a time, test database preparation, `TEST_DB_NAME`, `mode: "patch"`, a route `rateLimit` nothing tests, `input.workspaceId`, a refactor or consolidation that drops behaviour, a JSKIT update, a changed theme or Vuetify default, `jskit.surface` with a parent, an assistant tool's output contract, a screen that renders everything, feedback covering an action, `NODE_ENV=production`, a production start
53
+ - sanity checks, is this sane, query count that grows with the rows, a list that stops at 20 or 100 rows, `createDocument()` per row of a batch, `jskit test`, one file at a time, test database preparation, `TEST_DB_NAME`, `mode: "patch"`, a route `rateLimit` nothing tests, `input.workspaceId`, a refactor or consolidation that drops behaviour, a JSKIT update, a changed theme or Vuetify default, `jskit.surface` with a parent, an assistant tool's output contract, a screen that renders everything, feedback covering an action, `APP_ENV=staging` or `production`, a production start
54
54
  - [Sanity checks](../sanity-checks.md)
@@ -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` (a test copy, whose `SIDE_EFFECTS` is not
232
- `live`) and `mailer_unconfigured` say no email was sent; `held` says email
231
+ the invite was sent; `simulated` (logged outside production, see
232
+ [Environments](environments.md)) 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
@@ -78,36 +78,81 @@ environment's. The option is not called `--env-file` because Node reads an
78
78
 
79
79
  | Program | What it does |
80
80
  | --- | --- |
81
- | `<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. |
81
+ | `<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. |
82
82
  | `<name>-migrate [--env FILE]` | Runs the `db:migrate` script the same way. Only an app with one has it. |
83
83
  | `<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). |
84
- | `<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. |
84
+ | `<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. |
85
85
 
86
86
  ## Running it
87
87
 
88
88
  - The app's folder is read-only. A JSKIT package that writes files keeps them
89
89
  under the app's folder unless told otherwise, so point those at a writable
90
90
  data folder in the settings: `JSKIT_STORAGE_FS_BASE_PATH` (uploads and
91
- `runtime.storage`; `data/storage` by default) and `AUTH_LOCAL_STORE_DIR`
91
+ `runtime.storage`; `data/storage` by default), `AUTH_LOCAL_STORE_DIR`
92
92
  (local sign-in's files, such as the first account's setup code;
93
- `.jskit/auth` by default).
93
+ `.jskit/auth` by default) and, with OIDC sign-in, `AUTH_OIDC_STORE_DIR`.
94
+ `<name>-prepare --user NAME` makes those folders for the user the service
95
+ runs as, so a host's data folder that root owns needs nothing else. With
96
+ `JSKIT_STORAGE_DRIVER=s3`, `runtime.storage` writes to an S3 bucket instead,
97
+ as several instances need.
94
98
  - Secrets come at run time, in the env file or the service's environment,
95
99
  never in the package: anyone who can read the Nix store can read a package.
96
- - The server listens where its `server.js` says: in a JSKIT app, `HOST`
97
- (0.0.0.0) and `PORT` (3000).
100
+ - The server listens where its `server.js` says: `HOST` (0.0.0.0 in a JSKIT
101
+ app) and `PORT`, whose default differs between apps (3000 or 3001). Set
102
+ `PORT` in the settings, so the server, the check and the host agree.
98
103
  - The database comes from the app's own settings: `DATABASE_URL`, or
99
- `DB_CLIENT`, `DB_HOST`, `DB_NAME` and the rest, as the
100
- [database layer](database-layer.md) guide says.
101
- - Migrations run with `<name>-migrate` before the release starts, or with
102
- `<name> --migrate` where the host has no such step. When several instances
103
- start at once, Knex's migration lock lets one run them; the others fail and
104
- start again once it is done, as a service restarted on failure does.
104
+ `DB_CLIENT`, `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER` and `DB_PASSWORD`
105
+ (each of these wins over the same part of the URL), as the
106
+ [database layer](database-layer.md) guide says. Set
107
+ `DB_CLIENT` (`pg` or `mysql2`) when the app's own server code picks a
108
+ default for it. `/api/health` answers 200 only while the database answers,
109
+ so a host's check of a new build needs a database too.
110
+ - `APP_ENV` says where the app runs: `production`, or `staging` for a copy
111
+ that must not act for real, such as a build-check machine, which leaves the
112
+ `STAGING_*` addresses unset so everything is logged
113
+ ([Environments](environments.md)). The host sets it: the
114
+ package never guesses it, and a server without one refuses to start. The
115
+ programs default `NODE_ENV` to `production`, the build the package holds.
116
+ - Behind a load balancer or proxy, `TRUSTED_PROXIES` names its addresses, as
117
+ the [authentication](/guide/app-setup/authentication) guide says, and
118
+ `APP_PUBLIC_URL` is the address people use.
119
+
120
+ Several instances of one app behind a load balancer need the same settings
121
+ on every instance and nothing kept on one server's disk: files in S3,
122
+ sessions in the database, the same secrets and setup code, and Redis for live
123
+ updates, as [Run on more than one server](/guide/app-setup/more-than-one-server)
124
+ says.
125
+
126
+ ## Migrations
127
+
128
+ Run them in the service: `<name> --migrate`. A host that runs no release step
129
+ needs nothing else, and a database that is not up yet only delays the start:
130
+ the migration fails, the service exits, and the host's restart tries again.
131
+
132
+ When several instances start at once, each runs `db:migrate` and Knex's own
133
+ lock lets one migrate. Knex takes that lock in the transaction its migrations
134
+ run in (every JSKIT migration runs in one), so:
135
+
136
+ - on PostgreSQL the others wait for that transaction, then find nothing left
137
+ to migrate and start. A migrator that dies has its transaction rolled back,
138
+ its lock with it, and the next start migrates;
139
+ - on MySQL and MariaDB a table change commits at once, so the others fail
140
+ (`Migration table is already locked`) and start again once their service
141
+ restarts them, and a migrator that dies part way leaves the lock set until
142
+ `knex migrate:unlock` frees it;
143
+ - on a database that has never been migrated, instances that start at the
144
+ same moment can both try to create Knex's own tables: one fails, and its
145
+ restart finds them there.
146
+
147
+ So every host that starts several instances must restart a failed one, and
148
+ migrations must be written to run next to the release before them while a
149
+ rollout replaces instances (add first, remove in a later release).
105
150
 
106
151
  A host that runs apps as Nix packages typically runs the app `shop` as:
107
152
 
108
153
  - a step run as root at each start, before the service:
109
154
  `bin/shop-prepare --settings <the host's settings file> --env /run/shop/env --user shop`;
110
- - one service, run as the user `shop`:
111
- `bin/shop --env /run/shop/env --migrate`, on port 3000, healthy when
112
- `/api/health` answers 200;
155
+ - one service, run as the user `shop` and restarted when it fails:
156
+ `bin/shop --env /run/shop/env --migrate`, on the port its `PORT` setting
157
+ names, healthy when `/api/health` answers 200;
113
158
  - a check after it starts: `bin/shop-check --env /run/shop/env`.