@volter/world 3.0.137 → 3.0.139

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 (80) hide show
  1. package/dist/examples/customer-onboarding/.env.example +3 -0
  2. package/dist/examples/customer-onboarding/LICENSE +202 -0
  3. package/dist/examples/customer-onboarding/README.md +99 -0
  4. package/dist/examples/customer-onboarding/demo.mjs +30 -0
  5. package/dist/examples/customer-onboarding/gitignore.template +8 -0
  6. package/dist/examples/customer-onboarding/onboarding.mjs +55 -0
  7. package/dist/examples/customer-onboarding/package.json +21 -0
  8. package/dist/examples/customer-onboarding/prepare-ui.mjs +20 -0
  9. package/dist/examples/customer-onboarding/public-files.json +14 -0
  10. package/dist/examples/customer-onboarding/run.mjs +22 -0
  11. package/dist/examples/customer-onboarding/server.mjs +32 -0
  12. package/dist/examples/customer-onboarding/style.css +8 -0
  13. package/dist/examples/index.json +52 -0
  14. package/dist/examples/integration-branches/.env.example +1 -0
  15. package/dist/examples/integration-branches/LICENSE +202 -0
  16. package/dist/examples/integration-branches/README.md +102 -0
  17. package/dist/examples/integration-branches/customer.mjs +11 -0
  18. package/dist/examples/integration-branches/gitignore.template +8 -0
  19. package/dist/examples/integration-branches/package.json +18 -0
  20. package/dist/examples/integration-branches/public-files.json +10 -0
  21. package/dist/examples/integration-branches/receipt.mjs +3 -0
  22. package/dist/examples/workplace-agent/.env.example +3 -0
  23. package/dist/examples/workplace-agent/LICENSE +202 -0
  24. package/dist/examples/workplace-agent/README.md +106 -0
  25. package/dist/examples/workplace-agent/clients.mjs +7 -0
  26. package/dist/examples/workplace-agent/create-organization.mjs +11 -0
  27. package/dist/examples/workplace-agent/gitignore.template +8 -0
  28. package/dist/examples/workplace-agent/handoff.mjs +30 -0
  29. package/dist/examples/workplace-agent/operate.mjs +21 -0
  30. package/dist/examples/workplace-agent/package.json +22 -0
  31. package/dist/examples/workplace-agent/public-files.json +14 -0
  32. package/dist/examples/workplace-agent/reset-receipts.mjs +5 -0
  33. package/dist/examples/workplace-agent/seed.mjs +16 -0
  34. package/dist/src/agent-prompt.js +5 -5
  35. package/dist/src/cli.d.ts +1 -1
  36. package/dist/src/cli.js +56 -11
  37. package/dist/src/examples.d.ts +8 -0
  38. package/dist/src/examples.js +30 -0
  39. package/dist/src/mcp.js +2 -2
  40. package/dist/src/world.d.ts +4 -3
  41. package/dist/src/world.js +27 -14
  42. package/examples/customer-onboarding/.env.example +3 -0
  43. package/examples/customer-onboarding/LICENSE +202 -0
  44. package/examples/customer-onboarding/README.md +99 -0
  45. package/examples/customer-onboarding/demo.mjs +30 -0
  46. package/examples/customer-onboarding/gitignore.template +8 -0
  47. package/examples/customer-onboarding/onboarding.mjs +55 -0
  48. package/examples/customer-onboarding/package.json +21 -0
  49. package/examples/customer-onboarding/prepare-ui.mjs +20 -0
  50. package/examples/customer-onboarding/public-files.json +14 -0
  51. package/examples/customer-onboarding/run.mjs +22 -0
  52. package/examples/customer-onboarding/server.mjs +32 -0
  53. package/examples/customer-onboarding/style.css +8 -0
  54. package/examples/index.json +52 -0
  55. package/examples/integration-branches/.env.example +1 -0
  56. package/examples/integration-branches/LICENSE +202 -0
  57. package/examples/integration-branches/README.md +102 -0
  58. package/examples/integration-branches/customer.mjs +11 -0
  59. package/examples/integration-branches/gitignore.template +8 -0
  60. package/examples/integration-branches/package.json +18 -0
  61. package/examples/integration-branches/public-files.json +10 -0
  62. package/examples/integration-branches/receipt.mjs +3 -0
  63. package/examples/workplace-agent/.env.example +3 -0
  64. package/examples/workplace-agent/LICENSE +202 -0
  65. package/examples/workplace-agent/README.md +106 -0
  66. package/examples/workplace-agent/clients.mjs +7 -0
  67. package/examples/workplace-agent/create-organization.mjs +11 -0
  68. package/examples/workplace-agent/gitignore.template +8 -0
  69. package/examples/workplace-agent/handoff.mjs +30 -0
  70. package/examples/workplace-agent/operate.mjs +21 -0
  71. package/examples/workplace-agent/package.json +22 -0
  72. package/examples/workplace-agent/public-files.json +14 -0
  73. package/examples/workplace-agent/reset-receipts.mjs +5 -0
  74. package/examples/workplace-agent/seed.mjs +16 -0
  75. package/package.json +9 -8
  76. package/src/agent-prompt.ts +5 -5
  77. package/src/cli.ts +45 -7
  78. package/src/examples.ts +24 -0
  79. package/src/mcp.ts +2 -2
  80. package/src/world.ts +27 -15
@@ -0,0 +1,3 @@
1
+ STRIPE_SECRET_KEY=
2
+ RESEND_API_KEY=
3
+ DATABASE_URL=
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,99 @@
1
+ ---
2
+ title: Customer onboarding with Stripe, email and SQL
3
+ ---
4
+
5
+ # Customer onboarding with Stripe, email and SQL
6
+
7
+ Create a Stripe customer, save the application's signup row in PostgreSQL, and request a welcome email with Resend. Inspect each stored outcome through the real SDKs. The browser form and command-line workflow use the same application code.
8
+
9
+ You need Node 22.6+, npm and registry access during installation. The browser page also prepares public Volter brand assets before entering the World. No platform account or real vendor credential is needed. PostgreSQL is a World-managed application database; its records are application state, separate from SaaS history.
10
+
11
+ ## Obtain the application
12
+
13
+ Copy this starter into a new folder:
14
+
15
+ ```console
16
+ $ npx @volter/world@3.0.139 example customer-onboarding --dir onboarding
17
+ $ cd onboarding
18
+ $ npm install
19
+ ```
20
+
21
+ The command copies source; it neither installs dependencies nor starts a World. Its manifest pins the CLI, core, runtime, console, twins and SDKs. The installed starter creates a lockfile during installation. The repository's [package manifest](./package.json) and [lockfile](./package-lock.json) identify the source example's dependency cohort. Keep your own lockfile with the application when sharing it.
22
+
23
+ Read [onboarding.mjs](./onboarding.mjs) for the application and [run.mjs](./run.mjs) for the command entry. Empty keys in [.env.example](./.env.example) tell init what the app reads; init supplies throwaway credentials. Do not add real keys.
24
+
25
+ ```console
26
+ $ npx volter world init --name onboarding --twins stripe,resend
27
+ ```
28
+
29
+ Review Stripe and Resend's exact sources in `.volter/world.json`. The `pg` dependency and `DATABASE_URL` also request a managed PostgreSQL service. Keep it: this app needs SQL. SaaS selection does not exclude a declared native database. `world covers` describes the configured database as part of this workflow.
30
+
31
+ ## Create and read an account
32
+
33
+ ```console
34
+ $ npx volter world up
35
+ $ npx volter world clock set 2026-01-15T12:00:00Z
36
+ $ npx volter world run -- node run.mjs create Ada owner@world.test
37
+ $ npx volter world clock advance 5s
38
+ $ npx volter world run -- node run.mjs read
39
+ $ npx volter world log
40
+ ```
41
+
42
+ Read the customer returned by Stripe, the signup row returned by SQL and the email returned by Resend. `completion: complete` means delivery was observed, not merely that a send request was accepted. Opaque IDs can differ between fresh Worlds; customer identity, stored fields and delivery status are the useful outcomes.
43
+
44
+ ## Observe two different failures
45
+
46
+ A refusing recipient's mail server creates a bounce after the send was accepted:
47
+
48
+ ```console
49
+ $ npx volter world run -- node run.mjs bounce
50
+ $ npx volter world run -- node run.mjs create Grace owner@world.test
51
+ $ npx volter world clock advance 5s
52
+ $ npx volter world run -- node run.mjs read
53
+ ```
54
+
55
+ Grace's customer and SQL row remain. Her email exists and has `last_event: bounced`; the application reports `partial-email-bounced`. The `bounce` command uses Resend's declared synthetic recipient setting, not a successful-send handler. Restore delivery before later signups:
56
+
57
+ ```console
58
+ $ npx volter world run -- node run.mjs deliver
59
+ ```
60
+
61
+ An unverified sender is refused before an email is accepted:
62
+
63
+ ```console
64
+ $ npx volter world run -- node run.mjs refused
65
+ $ npx volter world run -- node run.mjs retry
66
+ $ npx volter world clock advance 5s
67
+ $ npx volter world run -- node run.mjs read
68
+ ```
69
+
70
+ The first command creates Lin's customer and SQL row, then records the email refusal. The second resumes that pending welcome on the same customer. It refuses to resend an email that already has an accepted ID. These application receipts do not guarantee exactly-once delivery after an ambiguous network failure; resolve acceptance before retrying an uncertain send.
71
+
72
+ ## Use the browser form
73
+
74
+ Prepare its fonts and logo outside the World:
75
+
76
+ ```console
77
+ $ node prepare-ui.mjs
78
+ ```
79
+
80
+ Then start the app through the World:
81
+
82
+ ```console
83
+ $ npx volter world run -- node server.mjs
84
+ ```
85
+
86
+ Open the printed app URL in your browser. Submit a signup, advance the World clock in another terminal and reload. The page shows the completion state and full stored outcome. Its server registers its app URL with the World after listening; consumers can discover it with `world app-url`.
87
+
88
+ To open the World dashboard, stop the app with Ctrl-C first, then switch the owned compute to the viewer:
89
+
90
+ ```console
91
+ $ npx volter world down
92
+ $ npx volter world view --no-open
93
+ ```
94
+
95
+ The viewer prints the dashboard URL and keeps running. Start `world run -- node server.mjs` in a second terminal if you want the application alongside it. Open **Stripe** under **Records**, then select the customer to inspect its name, email and stored ID. Open **Resend** to inspect the accepted email and delivery event. **Board** opens the vendor pages declared by the installed twin; its root workspace may cover settings rather than customers. Provisioning remains in full history even when hidden from the business-activity view. Read the application's SQL completion record with `run.mjs read` or its browser page.
96
+
97
+ Stop app consumers before stopping the viewer. `down` retains vendor and declared application state. [Resume](https://world.volter.ai/docs/guides/resume-a-world.html) explains continuing it; [demo a workflow](https://world.volter.ai/docs/guides/demo-a-workflow.html) uses this same application for a repeatable baseline, refusal and retry. Reset only your disposable example World; it discards that branch's work.
98
+
99
+ [Source files](./public-files.json) are also in the CLI starter. This page describes the source workflow; it does not inherit execution evidence from another example or an older release.
@@ -0,0 +1,30 @@
1
+ import { World } from '@volter/world';
2
+ import { initialize, onboard, listSignups, retryWelcome, close } from './onboarding.mjs';
3
+ if (!process.env.VOLTER_WORLD) throw new Error('Run this demo with volter world run');
4
+ const world = World.open(), at = '2026-01-15T12:00:00Z';
5
+ const summarize = row => ({ name: row.name, customer: row.customer_id, created: row.customer.created, completion: row.completion, email: row.email_id, delivery: row.delivery?.data?.last_event, error: row.email_error });
6
+ try {
7
+ await initialize();
8
+ switch (process.argv[2]) {
9
+ case 'baseline': {
10
+ world.setClock(at);
11
+ const rows = await listSignups();
12
+ if (rows.length > 1 || rows.some(r => r.name !== 'Grace')) throw new Error('This demo contains customer work; use an explicit reset only in your disposable demo World.');
13
+ const grace = rows.find(r => r.name === 'Grace') ?? await onboard({ name: 'Grace', email: 'owner@world.test' });
14
+ world.advanceClock('5s');
15
+ console.log('Baseline', JSON.stringify(summarize((await listSignups()).find(r => r.customer_id === grace.customer_id)))); break;
16
+ }
17
+ case 'present': {
18
+ const rows = await listSignups();
19
+ if (rows.length !== 1 || rows[0].name !== 'Grace') throw new Error('Prepare the Grace-only baseline first.');
20
+ world.setClock(new Date(Date.parse(at) + 10_000).toISOString());
21
+ const partial = await onboard({ name: 'Ada', email: 'owner@world.test', from: 'Example <welcome@unverified.world.test>' });
22
+ console.log('Email refusal; customer and SQL row retained', JSON.stringify(summarize(partial)));
23
+ const retry = await retryWelcome(partial.customer_id);
24
+ console.log('Retry accepted on the same customer', JSON.stringify(summarize(retry)));
25
+ world.advanceClock('5s');
26
+ console.log('Delivered', JSON.stringify((await listSignups()).map(summarize))); break;
27
+ }
28
+ default: throw new Error('Use baseline or present');
29
+ }
30
+ } finally { await close(); }
@@ -0,0 +1,8 @@
1
+ node_modules/
2
+ .volter/worlds/
3
+ .volter/world.env
4
+ .volter/*.world.env
5
+ .volter/token*
6
+ company.json
7
+ outcomes/
8
+ brand/
@@ -0,0 +1,55 @@
1
+ import Stripe from 'stripe';
2
+ import { Resend } from 'resend';
3
+ import pg from 'pg';
4
+
5
+ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { maxNetworkRetries: 0, timeout: 1500 });
6
+ const resend = new Resend(process.env.RESEND_API_KEY);
7
+ const db = new pg.Pool({ connectionString: process.env.DATABASE_URL, connectionTimeoutMillis: 1500 });
8
+ export async function initialize() {
9
+ await db.query(`CREATE TABLE IF NOT EXISTS signup (
10
+ customer_id text PRIMARY KEY, name text NOT NULL, email text NOT NULL,
11
+ email_id text, email_error jsonb, completion text NOT NULL)`);
12
+ }
13
+ export async function onboard({ name, email, from = 'Example <onboarding@resend.dev>' }) {
14
+ if (!name?.trim() || !email?.includes('@')) throw new Error('Name and email are required');
15
+ const customer = await stripe.customers.create({ name, email });
16
+ await db.query('INSERT INTO signup(customer_id,name,email,completion) VALUES ($1,$2,$3,$4)',
17
+ [customer.id, name, email, 'customer-created-email-pending']);
18
+ // Stripe and SQL are already committed. Keep that partial result if delivery cannot be requested.
19
+ try {
20
+ const result = await resend.emails.send({ from, to: [email], subject: 'Welcome', text: `Your account is ${customer.id}.` });
21
+ await db.query('UPDATE signup SET email_id=$2,email_error=$3,completion=$4 WHERE customer_id=$1',
22
+ [customer.id, result.data?.id ?? null, result.error ?? null, result.error ? 'partial-email-refused' : 'email-accepted-delivery-pending']);
23
+ } catch (error) {
24
+ await db.query('UPDATE signup SET email_error=$2,completion=$3 WHERE customer_id=$1',
25
+ [customer.id, { message: error.message }, 'partial-email-request-failed']);
26
+ }
27
+ return readSignup(customer.id);
28
+ }
29
+ export async function readSignup(id) {
30
+ const { rows: [row] } = await db.query('SELECT * FROM signup WHERE customer_id=$1', [id]);
31
+ if (!row) throw new Error(`No signup ${id}`);
32
+ const customer = await stripe.customers.retrieve(id);
33
+ const delivery = row.email_id ? await resend.emails.get(row.email_id) : null;
34
+ const event = delivery?.data?.last_event;
35
+ const completion = row.email_error ? row.completion : event === 'delivered' ? 'complete' : event === 'bounced' ? 'partial-email-bounced' : row.completion;
36
+ return { ...row, completion, customer, delivery };
37
+ }
38
+ export async function retryWelcome(id) {
39
+ const row = await readSignup(id);
40
+ if (row.email_id) throw new Error('The email was already accepted. Inspect delivery instead of submitting another welcome email.');
41
+ try {
42
+ const sent = await resend.emails.send({ from: 'Example <onboarding@resend.dev>', to: [row.email], subject: 'Welcome', text: `Your account is ${id}.` });
43
+ await db.query('UPDATE signup SET email_id=$2,email_error=$3,completion=$4 WHERE customer_id=$1',
44
+ [id, sent.data?.id ?? null, sent.error ?? null, sent.error ? 'partial-email-refused' : 'email-accepted-delivery-pending']);
45
+ } catch (error) {
46
+ await db.query('UPDATE signup SET email_error=$2,completion=$3 WHERE customer_id=$1',
47
+ [id, { message: error.message }, 'partial-email-request-failed']);
48
+ }
49
+ return readSignup(id);
50
+ }
51
+ export async function listSignups() {
52
+ const { rows } = await db.query('SELECT customer_id FROM signup ORDER BY customer_id');
53
+ return Promise.all(rows.map(r => readSignup(r.customer_id)));
54
+ }
55
+ export const close = () => db.end();
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "world-customer-onboarding",
3
+ "private": true,
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=22.6"
7
+ },
8
+ "dependencies": {
9
+ "stripe": "17.7.0",
10
+ "resend": "6.6.0",
11
+ "pg": "8.16.3"
12
+ },
13
+ "devDependencies": {
14
+ "@volter/world": "3.0.139",
15
+ "@volter/world-core": "3.0.139",
16
+ "@volter/world-runtime": "3.0.139",
17
+ "@volter/world-console": "3.0.134",
18
+ "@volter/twin-stripe": "3.0.2",
19
+ "@volter/twin-resend": "1.0.1"
20
+ }
21
+ }
@@ -0,0 +1,20 @@
1
+ // Fetch the brand at preparation time. Serving the app never fetches third-party assets.
2
+ import { mkdirSync, writeFileSync } from 'node:fs';
3
+ const base = 'https://brand.volter.ai', signal = AbortSignal.timeout(8000);
4
+ async function read(path) {
5
+ const response = await fetch(base + path, { signal });
6
+ if (!response.ok) throw new Error(`Brand ${path}: ${response.status}`);
7
+ return new Uint8Array(await response.arrayBuffer());
8
+ }
9
+ const css = new TextDecoder().decode(await read('/tokens.css')).replaceAll(base + '/fonts/', 'fonts/');
10
+ if (css.includes('@import')) throw new Error('Unexpected imported brand stylesheet');
11
+ const faces = [...new Set([...css.matchAll(/url\(["']?fonts\/([^)'"\s]+)["']?\)/g)].map(m => m[1]))];
12
+ const assets = await Promise.all([
13
+ ...faces.map(async face => ['fonts/' + face, await read('/fonts/' + face)]),
14
+ (async () => ['fonts/LICENSES.txt', await read('/fonts/LICENSES.txt')])(),
15
+ (async () => ['world.svg', await read('/logo/twin-world/svg?size=32&variant=mono')])(),
16
+ ]);
17
+ mkdirSync('brand/fonts', { recursive: true });
18
+ writeFileSync('brand/tokens.css', css);
19
+ for (const [name, bytes] of assets) writeFileSync('brand/' + name, bytes);
20
+ console.log('App assets prepared');
@@ -0,0 +1,14 @@
1
+ [
2
+ ".env.example",
3
+ ".gitignore",
4
+ "README.md",
5
+ "demo.mjs",
6
+ "onboarding.mjs",
7
+ "package-lock.json",
8
+ "package.json",
9
+ "prepare-ui.mjs",
10
+ "public-files.json",
11
+ "run.mjs",
12
+ "server.mjs",
13
+ "style.css"
14
+ ]
@@ -0,0 +1,22 @@
1
+ import { initialize, onboard, listSignups, retryWelcome, close } from './onboarding.mjs';
2
+ if (!process.env.VOLTER_WORLD) throw new Error('Run this application with volter world run');
3
+ try {
4
+ await initialize();
5
+ const mode = process.argv[2] ?? 'create';
6
+ if (mode === 'create') console.log(JSON.stringify(await onboard({ name: process.argv[3] ?? 'Ada', email: process.argv[4] ?? 'owner@world.test', from: process.env.WELCOME_FROM }), null, 2));
7
+ else if (mode === 'refused') console.log(JSON.stringify(await onboard({ name: 'Lin', email: 'owner@world.test', from: 'Example <welcome@unverified.world.test>' }), null, 2));
8
+ else if (mode === 'retry') {
9
+ const pending = (await listSignups()).filter(r => r.name === 'Lin' && !r.email_id);
10
+ const id = process.argv[3] ?? (pending.length === 1 ? pending[0].customer_id : null);
11
+ if (!id) throw new Error('Use retry <customer-id> when there is not exactly one pending Lin signup');
12
+ console.log(JSON.stringify(await retryWelcome(id), null, 2));
13
+ }
14
+ else if (mode === 'read') console.log(JSON.stringify(await listSignups(), null, 2));
15
+ else if (mode === 'bounce' || mode === 'deliver') {
16
+ const response = await fetch(`${process.env.RESEND_TWIN_URL}/_twin/recipients/world.test`, {
17
+ method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ rejects: mode === 'bounce' }), signal: AbortSignal.timeout(1500),
18
+ });
19
+ if (!response.ok) throw new Error(`Recipient setting: ${response.status} ${await response.text()}`);
20
+ console.log(`world.test delivery ${mode === 'bounce' ? 'refused' : 'accepted'}`);
21
+ } else throw new Error('Use create [name email], read, bounce, deliver, refused or retry [customer-id]');
22
+ } finally { await close(); }
@@ -0,0 +1,32 @@
1
+ import { createServer } from 'node:http';
2
+ import { readFileSync } from 'node:fs';
3
+ import { setAppUrl } from '@volter/world-runtime';
4
+ import { initialize, onboard, listSignups, close } from './onboarding.mjs';
5
+ if (!process.env.VOLTER_WORLD) throw new Error('Start with volter world run -- node server.mjs');
6
+ const escape = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
7
+ await initialize();
8
+ const server = createServer(async (request, response) => {
9
+ const url = new URL(request.url, 'http://localhost');
10
+ try {
11
+ if (url.pathname === '/style.css') { response.setHeader('Content-Type', 'text/css'); return response.end(readFileSync('style.css')); }
12
+ if (url.pathname.startsWith('/brand/') && /^\/brand\/(?:tokens\.css|world\.svg|fonts\/[\w.-]+)$/.test(url.pathname)) {
13
+ response.setHeader('Content-Type', url.pathname.endsWith('.css') ? 'text/css' : url.pathname.endsWith('.svg') ? 'image/svg+xml' : 'application/octet-stream');
14
+ return response.end(readFileSync('.' + url.pathname));
15
+ }
16
+ if (request.method === 'POST' && url.pathname === '/signup') {
17
+ let body = ''; for await (const chunk of request) { body += chunk; if (body.length > 8192) throw new Error('Form too large'); }
18
+ const form = new URLSearchParams(body);
19
+ await onboard({ name: form.get('name'), email: form.get('email') });
20
+ response.writeHead(303, { location: '/' }); return response.end();
21
+ }
22
+ if (request.method !== 'GET' || url.pathname !== '/') { response.writeHead(404); return response.end('Not found'); }
23
+ const rows = await listSignups();
24
+ response.setHeader('Content-Type', 'text/html; charset=utf-8');
25
+ response.end(`<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Customer onboarding</title><link rel="stylesheet" href="/brand/tokens.css"><link rel="stylesheet" href="/style.css"><main><header><img src="/brand/world.svg" width="32" height="32" alt="Volter World"><h1>Customer onboarding</h1></header><p>Create a customer, save an application row and request a welcome email.</p><form method="post" action="/signup"><label>Name <input name="name" value="Ada" required></label><label>Email <input name="email" type="email" value="owner@world.test" required></label><button>Create account</button></form><h2>Accounts</h2><p>Reload after advancing the World clock to observe delivery. A refused email leaves the customer and application row intact.</p>${rows.map(r => `<article><h3>${escape(r.name)}</h3><p>${escape(r.email)} · <strong>${escape(r.completion)}</strong></p><p>Stripe: <code>${escape(r.customer_id)}</code> · Email: <code>${escape(r.email_id ?? 'not accepted')}</code></p><details><summary>Stored outcome</summary><pre>${escape(JSON.stringify(r, null, 2))}</pre></details></article>`).join('') || '<p>No customers yet.</p>'}</main></html>`);
26
+ } catch (error) { response.writeHead(500, { 'Content-Type': 'text/plain' }); response.end(error.message); }
27
+ });
28
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
29
+ const url = `http://127.0.0.1:${server.address().port}`;
30
+ setAppUrl(process.env.VOLTER_WORLD, url, { root: process.cwd() });
31
+ console.log(`Customer onboarding ${url}`);
32
+ for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => server.close(async () => { await close(); process.exit(0); }));
@@ -0,0 +1,8 @@
1
+ :root { color-scheme: light dark; }
2
+ body { background: var(--volter-surface-page); color: var(--volter-text-primary); font-family: var(--volter-font-ui); margin: 0; }
3
+ main { padding: var(--volter-space-6); max-width: 72rem; margin: auto; }
4
+ header, form { display: flex; align-items: center; gap: var(--volter-space-4); flex-wrap: wrap; }
5
+ label { display: grid; gap: var(--volter-space-2); }
6
+ input, button { font: inherit; color: inherit; background: var(--volter-surface-raised); border: 1px solid var(--volter-border-default); border-radius: var(--volter-radius-control); padding: var(--volter-space-2); }
7
+ article { border-top: 1px solid var(--volter-border-default); padding-block: var(--volter-space-4); }
8
+ pre { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--volter-font-data); }
@@ -0,0 +1,52 @@
1
+ [
2
+ {
3
+ "id": "customer-onboarding",
4
+ "title": "Customer, welcome email and SQL application state",
5
+ "files": [
6
+ ".env.example",
7
+ ".gitignore",
8
+ "README.md",
9
+ "demo.mjs",
10
+ "onboarding.mjs",
11
+ "package.json",
12
+ "prepare-ui.mjs",
13
+ "public-files.json",
14
+ "run.mjs",
15
+ "server.mjs",
16
+ "style.css",
17
+ "LICENSE"
18
+ ]
19
+ },
20
+ {
21
+ "id": "workplace-agent",
22
+ "title": "GitHub issue to Linear ticket and Slack update",
23
+ "files": [
24
+ ".env.example",
25
+ ".gitignore",
26
+ "README.md",
27
+ "clients.mjs",
28
+ "create-organization.mjs",
29
+ "handoff.mjs",
30
+ "operate.mjs",
31
+ "package.json",
32
+ "public-files.json",
33
+ "reset-receipts.mjs",
34
+ "seed.mjs",
35
+ "LICENSE"
36
+ ]
37
+ },
38
+ {
39
+ "id": "integration-branches",
40
+ "title": "Shared baseline, isolated workers and an integration World",
41
+ "files": [
42
+ ".env.example",
43
+ ".gitignore",
44
+ "README.md",
45
+ "customer.mjs",
46
+ "package.json",
47
+ "public-files.json",
48
+ "receipt.mjs",
49
+ "LICENSE"
50
+ ]
51
+ }
52
+ ]
@@ -0,0 +1 @@
1
+ STRIPE_SECRET_KEY=