@jskit-ai/agent-docs 0.1.330 → 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.
- package/guide/agent/app-extras/realtime.md +11 -3
- package/guide/agent/app-setup/authentication.md +29 -24
- 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/data-access.md +9 -3
- package/guide/agent/framework/environments.md +174 -0
- 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 +6 -6
- 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 +7 -7
- 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 +2 -2
- package/reference/autogen/packages/auth-provider-local-core.md +9 -9
- 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/connectors-core.md +2 -2
- 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 +13 -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/data-access.md +9 -3
- package/skills/jskit/references/environments.md +169 -0
- package/skills/jskit/references/heuristics/INDEX.md +1 -1
- 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 +6 -6
- 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 +7 -7
- 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/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/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/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
|
@@ -161,6 +161,7 @@ A server module or manually written CLI composes the same library calls:
|
|
|
161
161
|
import { readFile } from "node:fs/promises";
|
|
162
162
|
import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/configuration";
|
|
163
163
|
import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
|
|
164
|
+
import { appEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
164
165
|
import { createFileConnectionStore, createCredentialProtection } from "@jskit-ai/connectors-core/server/file-storage";
|
|
165
166
|
import { resendProvider } from "@jskit-ai/connectors-catalog/server/resend";
|
|
166
167
|
import { firecrawlProvider } from "@jskit-ai/connectors-catalog/server/firecrawl";
|
|
@@ -175,7 +176,9 @@ const store = createFileConnectionStore({ directory: process.env.CONNECTOR_STATE
|
|
|
175
176
|
const connections = createConnectionService({
|
|
176
177
|
configuration, providers, store,
|
|
177
178
|
resolveReference: createEnvironmentReferenceResolver(process.env),
|
|
178
|
-
authorize: applicationConnectionPolicy
|
|
179
|
+
authorize: applicationConnectionPolicy,
|
|
180
|
+
// Only production (APP_ENV) sends side-effect operations, such as an email; elsewhere they are logged.
|
|
181
|
+
appEnv: appEnvironment(process.env)
|
|
179
182
|
});
|
|
180
183
|
|
|
181
184
|
// context comes from the existing application's authentication or local operator policy.
|
package/skills/jskit/references/patterns/connectors/api-key-connection/example/connections.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/configuration";
|
|
3
3
|
import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
|
|
4
|
-
import {
|
|
4
|
+
import { appEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
5
5
|
import { createFileConnectionStore, createCredentialProtection } from "@jskit-ai/connectors-core/server/file-storage";
|
|
6
6
|
import { resendProvider } from "@jskit-ai/connectors-catalog/server/resend";
|
|
7
7
|
import { firecrawlProvider } from "@jskit-ai/connectors-catalog/server/firecrawl";
|
|
@@ -18,7 +18,7 @@ export async function applicationConnections({ authorize, env = process.env, con
|
|
|
18
18
|
keys: { current: Buffer.from(env.CONNECTOR_STORAGE_KEY, "base64") }, activeKeyId: "current"
|
|
19
19
|
});
|
|
20
20
|
const store = createFileConnectionStore({ directory: env.CONNECTOR_STATE_DIRECTORY, protection });
|
|
21
|
-
// Sending email is a side effect:
|
|
21
|
+
// Sending email is a side effect: only production (APP_ENV) sends it; elsewhere it is logged and answers { simulated: true }.
|
|
22
22
|
return createConnectionService({ configuration, providers, store, authorize, resolveReference: createEnvironmentReferenceResolver(env),
|
|
23
|
-
|
|
23
|
+
appEnv: appEnvironment(env) });
|
|
24
24
|
}
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
"db:migrate:status": "knex --knexfile ./knexfile.js migrate:list"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@jskit-ai/connectors-core": "0.2.
|
|
11
|
-
"@jskit-ai/connector-google-calendar": "0.2.
|
|
12
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
13
|
-
"@jskit-ai/database-runtime-mysql": "0.1.
|
|
10
|
+
"@jskit-ai/connectors-core": "0.2.40",
|
|
11
|
+
"@jskit-ai/connector-google-calendar": "0.2.40",
|
|
12
|
+
"@jskit-ai/database-runtime": "0.1.276",
|
|
13
|
+
"@jskit-ai/database-runtime-mysql": "0.1.274",
|
|
14
|
+
"@jskit-ai/kernel": "0.2.27",
|
|
14
15
|
"knex": "^3.1.0"
|
|
15
16
|
}
|
|
16
17
|
}
|
package/skills/jskit/references/patterns/connectors/calendar-cli/example/scripts/calendar.js
CHANGED
|
@@ -6,6 +6,7 @@ import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/
|
|
|
6
6
|
import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
|
|
7
7
|
import { createCredentialProtection, createKnexConnectionStore } from "@jskit-ai/connectors-core/server/storage";
|
|
8
8
|
import { googleCalendarProvider } from "@jskit-ai/connector-google-calendar/server";
|
|
9
|
+
import { appEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* A local operator command owns this HTTP listener; web apps use authenticated routes.
|
|
@@ -86,7 +87,8 @@ async function main() {
|
|
|
86
87
|
configuration, providers: [googleCalendarProvider],
|
|
87
88
|
store: createKnexConnectionStore({ knex, protection }),
|
|
88
89
|
resolveReference: createEnvironmentReferenceResolver(process.env),
|
|
89
|
-
authorize: async () => context
|
|
90
|
+
authorize: async () => context,
|
|
91
|
+
appEnv: appEnvironment(process.env)
|
|
90
92
|
});
|
|
91
93
|
const request = { context, integrationId: "calendar" };
|
|
92
94
|
let result;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/configuration";
|
|
3
3
|
import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
|
|
4
|
-
import {
|
|
4
|
+
import { appEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
5
5
|
import { createFileConnectionStore, createCredentialProtection } from "@jskit-ai/connectors-core/server/file-storage";
|
|
6
6
|
import { firebaseCloudMessagingProvider } from "@jskit-ai/connectors-catalog/server/firebase-cloud-messaging";
|
|
7
7
|
|
|
@@ -28,7 +28,7 @@ export async function openNotificationConnections({
|
|
|
28
28
|
return createConnectionService({ configuration, providers, store,
|
|
29
29
|
resolveReference: createEnvironmentReferenceResolver(environment),
|
|
30
30
|
authorize: authorizeConnectionOperation,
|
|
31
|
-
// A push notification is a side effect:
|
|
32
|
-
|
|
31
|
+
// A push notification is a side effect: only production (APP_ENV) sends it; elsewhere it is logged.
|
|
32
|
+
appEnv: appEnvironment(environment)
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -58,6 +58,7 @@ package APIs in an application module:
|
|
|
58
58
|
import { readFile } from "node:fs/promises";
|
|
59
59
|
import { parseIntegrationConfiguration } from "@jskit-ai/connectors-core/shared/configuration";
|
|
60
60
|
import { createConnectionService, createEnvironmentReferenceResolver } from "@jskit-ai/connectors-core/server";
|
|
61
|
+
import { appEnvironment } from "@jskit-ai/kernel/shared/support/appEnvironment";
|
|
61
62
|
import { createFileConnectionStore, createCredentialProtection } from "@jskit-ai/connectors-core/server/file-storage";
|
|
62
63
|
import { wordpressComProvider } from "@jskit-ai/connectors-catalog/server/wordpress-com";
|
|
63
64
|
|
|
@@ -69,7 +70,8 @@ const protection = createCredentialProtection({
|
|
|
69
70
|
const connections = createConnectionService({
|
|
70
71
|
configuration, providers,
|
|
71
72
|
store: createFileConnectionStore({ directory: process.env.CONNECTOR_STATE_DIRECTORY, protection }),
|
|
72
|
-
resolveReference: createEnvironmentReferenceResolver(process.env), authorize: applicationConnectionPolicy
|
|
73
|
+
resolveReference: createEnvironmentReferenceResolver(process.env), authorize: applicationConnectionPolicy,
|
|
74
|
+
appEnv: appEnvironment(process.env)
|
|
73
75
|
});
|
|
74
76
|
```
|
|
75
77
|
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"./shared": "./src/shared/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/crud-core": "0.2.
|
|
13
|
-
"@jskit-ai/resource-core": "0.1.
|
|
14
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
12
|
+
"@jskit-ai/crud-core": "0.2.41",
|
|
13
|
+
"@jskit-ai/resource-core": "0.1.218",
|
|
14
|
+
"@jskit-ai/resource-crud-core": "0.1.220"
|
|
15
15
|
},
|
|
16
16
|
"jskit": {
|
|
17
17
|
"kind": "runtime",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"test": "jskit test --databases"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@jskit-ai/database-runtime": "0.1.
|
|
13
|
-
"@jskit-ai/database-runtime-postgres": "0.1.
|
|
12
|
+
"@jskit-ai/database-runtime": "0.1.276",
|
|
13
|
+
"@jskit-ai/database-runtime-postgres": "0.1.273"
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"./shared": "./src/shared/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/crud-core": "0.2.
|
|
14
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
15
|
-
"@jskit-ai/users-core": "0.2.
|
|
13
|
+
"@jskit-ai/crud-core": "0.2.41",
|
|
14
|
+
"@jskit-ai/resource-crud-core": "0.1.220",
|
|
15
|
+
"@jskit-ai/users-core": "0.2.49"
|
|
16
16
|
},
|
|
17
17
|
"jskit": {
|
|
18
18
|
"kind": "runtime",
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
"./shared": "./src/shared/index.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@jskit-ai/crud-core": "0.2.
|
|
14
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
15
|
-
"@jskit-ai/users-core": "0.2.
|
|
16
|
-
"@jskit-ai/workspaces-core": "0.2.
|
|
13
|
+
"@jskit-ai/crud-core": "0.2.41",
|
|
14
|
+
"@jskit-ai/resource-crud-core": "0.1.220",
|
|
15
|
+
"@jskit-ai/users-core": "0.2.49",
|
|
16
|
+
"@jskit-ai/workspaces-core": "0.2.49"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@jskit-ai/kernel": "0.2.
|
|
20
|
-
"@jskit-ai/resource-runtime": "0.2.
|
|
19
|
+
"@jskit-ai/kernel": "0.2.27",
|
|
20
|
+
"@jskit-ai/resource-runtime": "0.2.37"
|
|
21
21
|
},
|
|
22
22
|
"jskit": {
|
|
23
23
|
"kind": "runtime",
|
|
@@ -167,9 +167,9 @@ A consolidation drops behaviour there without a failing build.
|
|
|
167
167
|
|
|
168
168
|
### Production settings
|
|
169
169
|
|
|
170
|
-
- `
|
|
171
|
-
|
|
172
|
-
development
|
|
170
|
+
- A deployed server sets `APP_ENV=staging` or `production` and
|
|
171
|
+
`NODE_ENV=production` ([Environments](environments.md)); only
|
|
172
|
+
then does local auth ask for a setup code and refuse development settings.
|
|
173
173
|
- On an empty production database, local auth asks for the first account's
|
|
174
174
|
setup code, so whoever reaches a new deployment first cannot own it ([The
|
|
175
175
|
first account in
|
|
@@ -89,10 +89,12 @@ a JSKIT app. The rules it applies are already in [Typed features](typed-features
|
|
|
89
89
|
|
|
90
90
|
## Production settings and secrets
|
|
91
91
|
|
|
92
|
-
- `NODE_ENV=production`, set by
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
refuses
|
|
92
|
+
- `APP_ENV=staging` or `APP_ENV=production`, with `NODE_ENV=production`, set by
|
|
93
|
+
the Deployment's Serve step, makes a server deployed
|
|
94
|
+
([Environments](environments.md)). There local auth requires
|
|
95
|
+
`AUTH_LOCAL_SESSION_SECRET`, refuses `AUTH_DEV_BYPASS_ENABLED` and
|
|
96
|
+
`AUTH_LOCAL_RECOVERY_DEV_OUTPUT`, and refuses to start without a confirmation
|
|
97
|
+
sender while anyone may register
|
|
96
98
|
([Production settings](sanity-checks.md#production-settings)).
|
|
97
99
|
- On an empty production database the first account needs the setup code
|
|
98
100
|
(403 `auth.local.setup.codeRequired`), so whoever reaches a new deployment
|
|
@@ -125,7 +127,7 @@ a JSKIT app. The rules it applies are already in [Typed features](typed-features
|
|
|
125
127
|
workspace), a write without `csrf-token`, and one request past each
|
|
126
128
|
`rateLimit` (429). A body that does not validate, sent without a session,
|
|
127
129
|
must get the refusal, not field errors.
|
|
128
|
-
- Production settings: start the server with `NODE_ENV=production` and the
|
|
130
|
+
- Production settings: start the server with `APP_ENV=staging`, `NODE_ENV=production` and the
|
|
129
131
|
test database, and check that it stops without `AUTH_LOCAL_SESSION_SECRET`,
|
|
130
132
|
that registering asks for the setup code, and the response headers.
|
|
131
133
|
- Run `npm audit` and `npm run verify`.
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
<!-- Generated by `npm run agent-docs:build` from `packages/agent-docs/site/guide/framework/side-effects.md`. Do not edit manually. -->
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
title: Side effects and test copies
|
|
5
|
-
description: Follow SIDE_EFFECTS so a test copy never sends real email, messages or payments.
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Side effects and test copies
|
|
9
|
-
|
|
10
|
-
An application reads one environment variable, `SIDE_EFFECTS`:
|
|
11
|
-
|
|
12
|
-
- `live`: the application acts for real.
|
|
13
|
-
- Anything else, including unset, means `simulate`: the copy is a **test
|
|
14
|
-
copy**. It sends no real email, SMS, push notification, payment or
|
|
15
|
-
third-party webhook. It simulates each one, writes it to the log, and every
|
|
16
|
-
page shows a small "Test copy" banner.
|
|
17
|
-
|
|
18
|
-
Only the copy that serves real people sets `SIDE_EFFECTS=live`. Development,
|
|
19
|
-
previews, tests and staging leave it unset. The name has no platform prefix on
|
|
20
|
-
purpose: any host can set it. The host sets it; a request never chooses it.
|
|
21
|
-
|
|
22
|
-
## What JSKIT does
|
|
23
|
-
|
|
24
|
-
- Every HTML page the server sends, and every page the Vite development server
|
|
25
|
-
sends, names the setting in a `jskit-side-effects` meta tag. The shell
|
|
26
|
-
(`@jskit-ai/shell-web`) shows the "Test copy" banner from it, with no
|
|
27
|
-
application code. The banner never takes a click or a tap. Screen readers
|
|
28
|
-
read it as a note, with "emails, messages and payments are simulated, not
|
|
29
|
-
sent" as its description. It has no label, so a browser test's
|
|
30
|
-
`getByLabel("Email")` never finds it.
|
|
31
|
-
- The server logs once at startup whether it acts for real. A production server
|
|
32
|
-
that simulates logs a warning.
|
|
33
|
-
- Local-password emails (confirmation and password reset) with an installed
|
|
34
|
-
sender are logged, not sent: local auth uses its own simulated sender in
|
|
35
|
-
place of the application's, which never runs in a test copy. An application
|
|
36
|
-
that confirms new accounts at once while its email isn't set up uses
|
|
37
|
-
`auth.local.confirmation-mode`, which a test copy keeps (see
|
|
38
|
-
[Authentication](/guide/app-setup/authentication)).
|
|
39
|
-
- Workspace invitations with a provided mailer are logged. The invitation
|
|
40
|
-
answers `status: "simulated"`, and the inviter copies the link.
|
|
41
|
-
- Accounts-hub email is logged, not sent.
|
|
42
|
-
- Connector operations that act on the world (send an email or message, post,
|
|
43
|
-
book or cancel, charge, invoice, trigger another system's events) are marked
|
|
44
|
-
`sideEffect`. They are checked like real ones, then logged, and `invoke`
|
|
45
|
-
answers `{ simulated: true }`. Reads run for real. `createConnectorsFeature`
|
|
46
|
-
reads the setting itself; give `createConnectionService` and
|
|
47
|
-
`createPaymentCheckoutService` `sideEffects: resolveSideEffectsMode(env)`.
|
|
48
|
-
- Payment checkout and the billing portal in the live payment environment are
|
|
49
|
-
refused with `payment_test_copy`; the sandbox environment works either way.
|
|
50
|
-
|
|
51
|
-
Supabase sends its own authentication emails from Supabase's servers; JSKIT
|
|
52
|
-
cannot simulate them. Point a test copy at a separate Supabase project.
|
|
53
|
-
|
|
54
|
-
## The application's own side effects
|
|
55
|
-
|
|
56
|
-
Code the application writes that reaches the world follows the same rule.
|
|
57
|
-
Decide at the point of the effect: log what would happen and answer as if it
|
|
58
|
-
were done.
|
|
59
|
-
|
|
60
|
-
```js
|
|
61
|
-
import { sideEffectsAreLive } from "@jskit-ai/kernel/shared/support/sideEffects";
|
|
62
|
-
import { logSimulatedSideEffect } from "@jskit-ai/kernel/server/runtime/sideEffects";
|
|
63
|
-
|
|
64
|
-
async function sendReminder({ env, logger, mailer }, message) {
|
|
65
|
-
if (!sideEffectsAreLive(env)) {
|
|
66
|
-
logSimulatedSideEffect(logger, { kind: "email", summary: `the reminder to ${message.to}`, details: { to: message.to } });
|
|
67
|
-
return { simulated: true };
|
|
68
|
-
}
|
|
69
|
-
return mailer.send(message);
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
- Read `env` from the `runtime.env` capability, never a request.
|
|
74
|
-
- A configured driver or key (`EMAIL_DRIVER=ses`, a live payment key) does not
|
|
75
|
-
make a test copy live; only `SIDE_EFFECTS=live` does.
|
|
76
|
-
- Test both modes. A test that proves a real sender against a fake transport
|
|
77
|
-
sets `SIDE_EFFECTS: "live"` in its environment.
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
<!-- Generated from `packages/agent-docs/site/guide/framework/side-effects.md`. -->
|
|
2
|
-
|
|
3
|
-
# Side effects and test copies
|
|
4
|
-
|
|
5
|
-
An application reads one environment variable, `SIDE_EFFECTS`:
|
|
6
|
-
|
|
7
|
-
- `live`: the application acts for real.
|
|
8
|
-
- Anything else, including unset, means `simulate`: the copy is a **test
|
|
9
|
-
copy**. It sends no real email, SMS, push notification, payment or
|
|
10
|
-
third-party webhook. It simulates each one, writes it to the log, and every
|
|
11
|
-
page shows a small "Test copy" banner.
|
|
12
|
-
|
|
13
|
-
Only the copy that serves real people sets `SIDE_EFFECTS=live`. Development,
|
|
14
|
-
previews, tests and staging leave it unset. The name has no platform prefix on
|
|
15
|
-
purpose: any host can set it. The host sets it; a request never chooses it.
|
|
16
|
-
|
|
17
|
-
## What JSKIT does
|
|
18
|
-
|
|
19
|
-
- Every HTML page the server sends, and every page the Vite development server
|
|
20
|
-
sends, names the setting in a `jskit-side-effects` meta tag. The shell
|
|
21
|
-
(`@jskit-ai/shell-web`) shows the "Test copy" banner from it, with no
|
|
22
|
-
application code. The banner never takes a click or a tap. Screen readers
|
|
23
|
-
read it as a note, with "emails, messages and payments are simulated, not
|
|
24
|
-
sent" as its description. It has no label, so a browser test's
|
|
25
|
-
`getByLabel("Email")` never finds it.
|
|
26
|
-
- The server logs once at startup whether it acts for real. A production server
|
|
27
|
-
that simulates logs a warning.
|
|
28
|
-
- Local-password emails (confirmation and password reset) with an installed
|
|
29
|
-
sender are logged, not sent: local auth uses its own simulated sender in
|
|
30
|
-
place of the application's, which never runs in a test copy. An application
|
|
31
|
-
that confirms new accounts at once while its email isn't set up uses
|
|
32
|
-
`auth.local.confirmation-mode`, which a test copy keeps (see
|
|
33
|
-
[Authentication](/guide/app-setup/authentication)).
|
|
34
|
-
- Workspace invitations with a provided mailer are logged. The invitation
|
|
35
|
-
answers `status: "simulated"`, and the inviter copies the link.
|
|
36
|
-
- Accounts-hub email is logged, not sent.
|
|
37
|
-
- Connector operations that act on the world (send an email or message, post,
|
|
38
|
-
book or cancel, charge, invoice, trigger another system's events) are marked
|
|
39
|
-
`sideEffect`. They are checked like real ones, then logged, and `invoke`
|
|
40
|
-
answers `{ simulated: true }`. Reads run for real. `createConnectorsFeature`
|
|
41
|
-
reads the setting itself; give `createConnectionService` and
|
|
42
|
-
`createPaymentCheckoutService` `sideEffects: resolveSideEffectsMode(env)`.
|
|
43
|
-
- Payment checkout and the billing portal in the live payment environment are
|
|
44
|
-
refused with `payment_test_copy`; the sandbox environment works either way.
|
|
45
|
-
|
|
46
|
-
Supabase sends its own authentication emails from Supabase's servers; JSKIT
|
|
47
|
-
cannot simulate them. Point a test copy at a separate Supabase project.
|
|
48
|
-
|
|
49
|
-
## The application's own side effects
|
|
50
|
-
|
|
51
|
-
Code the application writes that reaches the world follows the same rule.
|
|
52
|
-
Decide at the point of the effect: log what would happen and answer as if it
|
|
53
|
-
were done.
|
|
54
|
-
|
|
55
|
-
```js
|
|
56
|
-
import { sideEffectsAreLive } from "@jskit-ai/kernel/shared/support/sideEffects";
|
|
57
|
-
import { logSimulatedSideEffect } from "@jskit-ai/kernel/server/runtime/sideEffects";
|
|
58
|
-
|
|
59
|
-
async function sendReminder({ env, logger, mailer }, message) {
|
|
60
|
-
if (!sideEffectsAreLive(env)) {
|
|
61
|
-
logSimulatedSideEffect(logger, { kind: "email", summary: `the reminder to ${message.to}`, details: { to: message.to } });
|
|
62
|
-
return { simulated: true };
|
|
63
|
-
}
|
|
64
|
-
return mailer.send(message);
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
- Read `env` from the `runtime.env` capability, never a request.
|
|
69
|
-
- A configured driver or key (`EMAIL_DRIVER=ses`, a live payment key) does not
|
|
70
|
-
make a test copy live; only `SIDE_EFFECTS=live` does.
|
|
71
|
-
- Test both modes. A test that proves a real sender against a fake transport
|
|
72
|
-
sets `SIDE_EFFECTS: "live"` in its environment.
|