sanoma 0.1.0 → 0.4.0

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 (64) hide show
  1. package/README.md +91 -24
  2. package/dist/check.d.ts +10 -5
  3. package/dist/check.js +77 -17
  4. package/dist/check.js.map +1 -1
  5. package/dist/cli.js +91 -23
  6. package/dist/cli.js.map +1 -1
  7. package/dist/config.d.ts +5 -0
  8. package/dist/config.js +29 -3
  9. package/dist/config.js.map +1 -1
  10. package/dist/data.d.ts +1 -0
  11. package/dist/data.js +4 -0
  12. package/dist/data.js.map +1 -0
  13. package/dist/dev.d.ts +3 -1
  14. package/dist/dev.js +5 -2
  15. package/dist/dev.js.map +1 -1
  16. package/dist/env.js +9 -0
  17. package/dist/env.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +2 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/init.d.ts +41 -0
  22. package/dist/init.js +141 -0
  23. package/dist/init.js.map +1 -0
  24. package/dist/key.d.ts +16 -0
  25. package/dist/key.js +43 -0
  26. package/dist/key.js.map +1 -0
  27. package/dist/oxlint-plugin.d.ts +7 -1
  28. package/dist/oxlint-plugin.js +10 -4
  29. package/dist/oxlint-plugin.js.map +1 -1
  30. package/dist/resources.d.ts +1 -0
  31. package/dist/resources.js +5 -0
  32. package/dist/resources.js.map +1 -0
  33. package/dist/serve.d.ts +25 -8
  34. package/dist/serve.js +160 -9
  35. package/dist/serve.js.map +1 -1
  36. package/dist/site-lint.d.ts +33 -0
  37. package/dist/site-lint.js +70 -0
  38. package/dist/site-lint.js.map +1 -0
  39. package/dist/sites.d.ts +7 -0
  40. package/dist/sites.js +11 -0
  41. package/dist/sites.js.map +1 -0
  42. package/dist/source.d.ts +7 -0
  43. package/dist/source.js +42 -0
  44. package/dist/source.js.map +1 -0
  45. package/oxlint.json +113 -18
  46. package/package.json +24 -9
  47. package/site.d.ts +3 -0
  48. package/site.js +3 -0
  49. package/template/.env.example +24 -0
  50. package/template/AGENTS.md +41 -0
  51. package/template/gitignore +11 -0
  52. package/template/package.json +17 -0
  53. package/template/pnpm-workspace.yaml +4 -0
  54. package/template/policies/policy.cedar +17 -0
  55. package/template/resources/billing/.gitkeep +0 -0
  56. package/template/resources/data.ts +21 -0
  57. package/template/resources/finance/.gitkeep +0 -0
  58. package/template/resources/identity/.gitkeep +0 -0
  59. package/template/resources/people/.gitkeep +0 -0
  60. package/template/resources/people.ts +20 -0
  61. package/template/sanoma.config.ts +10 -0
  62. package/template/scenarios/publish-post/publish.feature +28 -0
  63. package/template/tsconfig.json +4 -0
  64. package/template/workflows/publish-post.ts +20 -0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This package's `package.json`, by real path: a sites build's server bundle imports the runtime
3
+ * as it resolves from here, the launcher's own copy, so the worker and the app share one.
4
+ */
5
+ export declare const runtimeFrom: () => string;
6
+ /** `@sanoma-ai/app/build` when the repo has a `sites/` directory: a repo without one never loads the app's build. */
7
+ export declare const siteBuild: (root: string) => Promise<typeof import("@sanoma-ai/app/build") | undefined>;
package/dist/sites.js ADDED
@@ -0,0 +1,11 @@
1
+ import { existsSync, realpathSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ /**
5
+ * This package's `package.json`, by real path: a sites build's server bundle imports the runtime
6
+ * as it resolves from here, the launcher's own copy, so the worker and the app share one.
7
+ */
8
+ export const runtimeFrom = () => realpathSync(fileURLToPath(new URL("../package.json", import.meta.url)));
9
+ /** `@sanoma-ai/app/build` when the repo has a `sites/` directory: a repo without one never loads the app's build. */
10
+ export const siteBuild = async (root) => existsSync(join(root, "sites")) ? await import("@sanoma-ai/app/build") : undefined;
11
+ //# sourceMappingURL=sites.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sites.js","sourceRoot":"","sources":["../src/sites.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAE1G,qHAAqH;AACrH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE,CAC9C,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Source } from "@sanoma-ai/workflows";
2
+ /**
3
+ * The local git checkout at `root` as a `Source`: commits on the current branch, as the
4
+ * machine's git identity with the author named `<author> via Sanoma`, and pushes a branch to a
5
+ * repository by its URL with a token.
6
+ */
7
+ export declare function localGitSource(root: string): Source;
package/dist/source.js ADDED
@@ -0,0 +1,42 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const run = promisify(execFile);
4
+ /**
5
+ * The local git checkout at `root` as a `Source`: commits on the current branch, as the
6
+ * machine's git identity with the author named `<author> via Sanoma`, and pushes a branch to a
7
+ * repository by its URL with a token.
8
+ */
9
+ export function localGitSource(root) {
10
+ const git = async (args, env) => (await run("git", args, { cwd: root, env: { ...process.env, ...env } })).stdout.trim();
11
+ return {
12
+ root,
13
+ async commit({ paths, message, author }) {
14
+ // No paths would be every path to git.
15
+ if (!paths.length)
16
+ return undefined;
17
+ await git(["add", "--", ...paths]);
18
+ if (!(await git(["status", "--porcelain", "--", ...paths])))
19
+ return undefined;
20
+ // Only these paths, whatever else is staged; the email stays the machine's.
21
+ await git(["commit", "--quiet", "-m", message, "--", ...paths], { GIT_AUTHOR_NAME: `${author} via Sanoma` });
22
+ return { revision: await git(["rev-parse", "HEAD"]) };
23
+ },
24
+ head: (ref = "HEAD") => git(["rev-parse", "--verify", `${ref}^{commit}`]),
25
+ async push({ url, token, ref }) {
26
+ // The token goes in a header, through the environment, as the runtime image sends it: never
27
+ // in the URL, the arguments, .git/config or an error. No prompt for anything else.
28
+ const header = `Authorization: Basic ${Buffer.from(`x-access-token:${token}`).toString("base64")}`;
29
+ const env = {
30
+ GIT_TERMINAL_PROMPT: "0",
31
+ GIT_CONFIG_COUNT: "1",
32
+ GIT_CONFIG_KEY_0: "http.extraHeader",
33
+ GIT_CONFIG_VALUE_0: header,
34
+ };
35
+ await git(["push", "--quiet", "--", url, `refs/heads/${ref}:refs/heads/${ref}`], env).catch((err) => {
36
+ const why = (err.stderr?.trim() || err.message).replaceAll(token, "<token>");
37
+ throw new Error(`git push to ${url} failed: ${why}`);
38
+ });
39
+ },
40
+ };
41
+ }
42
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEhC;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,GAAG,GAAG,KAAK,EAAE,IAAc,EAAE,GAAuB,EAAE,EAAE,CAC5D,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACzF,OAAO;QACL,IAAI;QACJ,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE;YACrC,uCAAuC;YACvC,IAAI,CAAC,KAAK,CAAC,MAAM;gBAAE,OAAO,SAAS,CAAC;YACpC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;YACnC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;gBAAE,OAAO,SAAS,CAAC;YAC9E,4EAA4E;YAC5E,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE,EAAE,eAAe,EAAE,GAAG,MAAM,aAAa,EAAE,CAAC,CAAC;YAC7G,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;QACxD,CAAC;QACD,IAAI,EAAE,CAAC,GAAG,GAAG,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,GAAG,WAAW,CAAC,CAAC;QACzE,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE;YAC5B,4FAA4F;YAC5F,mFAAmF;YACnF,MAAM,MAAM,GAAG,wBAAwB,MAAM,CAAC,IAAI,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACnG,MAAM,GAAG,GAAG;gBACV,mBAAmB,EAAE,GAAG;gBACxB,gBAAgB,EAAE,GAAG;gBACrB,gBAAgB,EAAE,kBAAkB;gBACpC,kBAAkB,EAAE,MAAM;aAC3B,CAAC;YACF,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,GAAG,eAAe,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CACzF,CAAC,GAAyC,EAAE,EAAE;gBAC5C,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;gBAC7E,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,YAAY,GAAG,EAAE,CAAC,CAAC;YACvD,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/oxlint.json CHANGED
@@ -26,8 +26,7 @@
26
26
  "overrides": [
27
27
  {
28
28
  "files": [
29
- "workflows/**",
30
- "policies/**"
29
+ "workflows/**"
31
30
  ],
32
31
  "rules": {
33
32
  "no-restricted-globals": [
@@ -82,11 +81,11 @@
82
81
  },
83
82
  {
84
83
  "name": "eval",
85
- "message": "Not allowed in a workflow or policy."
84
+ "message": "Not allowed in a workflow."
86
85
  },
87
86
  {
88
87
  "name": "Function",
89
- "message": "Not allowed in a workflow or policy."
88
+ "message": "Not allowed in a workflow."
90
89
  },
91
90
  {
92
91
  "name": "globalThis",
@@ -141,35 +140,23 @@
141
140
  "name": "@sanoma-ai/workflows",
142
141
  "allowImportNames": [
143
142
  "defineWorkflow",
144
- "definePolicy",
145
- "allow",
146
- "deny",
147
- "approve",
148
- "approvedFor",
149
- "allowAll",
150
143
  "mayDecide",
151
144
  "errorCode",
152
145
  "z"
153
146
  ],
154
147
  "allowTypeImports": true,
155
- "message": "A workflow or policy imports only these and types from @sanoma-ai/workflows: the rest (SanomaClient, startWorker, the ledger stores, config helpers) could start runs, approve its own approvals, forge the ledger or read credentials. Ask for approval with `ctx.approval`."
148
+ "message": "A workflow imports only these and types from @sanoma-ai/workflows: the rest (SanomaClient, startWorker, the ledger stores, config helpers) could start runs, approve its own approvals, forge the ledger or read credentials. Ask for approval with `ctx.approval`."
156
149
  },
157
150
  {
158
151
  "name": "sanoma",
159
152
  "allowImportNames": [
160
153
  "defineWorkflow",
161
- "definePolicy",
162
- "allow",
163
- "deny",
164
- "approve",
165
- "approvedFor",
166
- "allowAll",
167
154
  "mayDecide",
168
155
  "errorCode",
169
156
  "z"
170
157
  ],
171
158
  "allowTypeImports": true,
172
- "message": "A workflow or policy imports only these and types from sanoma: the rest (defineConfig, the ledger stores) belongs in sanoma.config.ts, where the drivers and credentials are. Ask for approval with `ctx.approval`."
159
+ "message": "A workflow imports only these and types from sanoma: the rest (defineConfig, the ledger stores) belongs in sanoma.config.ts, where the drivers and credentials are. Ask for approval with `ctx.approval`."
173
160
  }
174
161
  ],
175
162
  "patterns": [
@@ -206,6 +193,114 @@
206
193
  "rules": {
207
194
  "sanoma/data-file": "error"
208
195
  }
196
+ },
197
+ {
198
+ "files": [
199
+ "sites/**"
200
+ ],
201
+ "excludeFiles": [
202
+ "sites/__virtual.ts"
203
+ ],
204
+ "jsPlugins": [
205
+ "./dist/oxlint-plugin.js"
206
+ ],
207
+ "rules": {
208
+ "no-restricted-imports": [
209
+ "error",
210
+ {
211
+ "paths": [
212
+ {
213
+ "name": "sanoma",
214
+ "message": "A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`.",
215
+ "allowTypeImports": true
216
+ },
217
+ {
218
+ "name": "@sanoma-ai/workflows",
219
+ "message": "A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`.",
220
+ "allowTypeImports": true
221
+ },
222
+ {
223
+ "name": "@sanoma-ai/bridge",
224
+ "message": "A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`.",
225
+ "allowTypeImports": true
226
+ },
227
+ {
228
+ "name": "pg",
229
+ "message": "A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`.",
230
+ "allowTypeImports": true
231
+ },
232
+ {
233
+ "name": "@sanoma-ai/app",
234
+ "message": "A site imports the app's components from `@sanoma-ai/app/ui`; the rest of the app is its server.",
235
+ "allowTypeImports": true
236
+ },
237
+ {
238
+ "name": "@tanstack/react-start",
239
+ "message": "A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`. Its route APIs (`Link`, `useNavigate`, …) come from `sanoma/site`, and `createFileRoute` from `@tanstack/react-router`.",
240
+ "allowTypeImports": true
241
+ }
242
+ ],
243
+ "patterns": [
244
+ {
245
+ "group": [
246
+ "sanoma/**",
247
+ "!sanoma/site",
248
+ "@sanoma-ai/workflows/**",
249
+ "@sanoma-ai/bridge/**",
250
+ "@dbos-inc/**",
251
+ "pg/**",
252
+ "@tanstack/react-start/**"
253
+ ],
254
+ "message": "A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`.",
255
+ "allowTypeImports": true
256
+ },
257
+ {
258
+ "group": [
259
+ "@sanoma-ai/app/**",
260
+ "!@sanoma-ai/app/ui"
261
+ ],
262
+ "message": "A site imports the app's components from `@sanoma-ai/app/ui`; the rest of the app is its server.",
263
+ "allowTypeImports": true
264
+ },
265
+ {
266
+ "group": [
267
+ "@sanoma-ai/testing",
268
+ "@sanoma-ai/testing/**"
269
+ ],
270
+ "message": "Fakes and test helpers belong in tests. A site has no server code: call an operation or start a workflow through `api` from `sanoma/site`.",
271
+ "allowTypeImports": true
272
+ },
273
+ {
274
+ "group": [
275
+ "@sanoma-ai/connector-*",
276
+ "@sanoma-ai/connector-*/**"
277
+ ],
278
+ "message": "A site calls no vendor itself, so the policy sees every call: call an operation or start a workflow through `api` from `sanoma/site`.",
279
+ "allowTypeImports": true
280
+ },
281
+ {
282
+ "group": [
283
+ "node:*"
284
+ ],
285
+ "message": "A site runs in the browser: call an operation or start a workflow through `api` from `sanoma/site`.",
286
+ "allowTypeImports": true
287
+ }
288
+ ]
289
+ }
290
+ ],
291
+ "no-restricted-globals": [
292
+ "error",
293
+ {
294
+ "name": "process",
295
+ "message": "A site runs in the browser and holds no credentials: call an operation or start a workflow through `api` from `sanoma/site`."
296
+ },
297
+ {
298
+ "name": "require",
299
+ "message": "A site runs in the browser and imports with `import`: call an operation or start a workflow through `api` from `sanoma/site`."
300
+ }
301
+ ],
302
+ "sanoma/site-file": "error"
303
+ }
209
304
  }
210
305
  ]
211
306
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanoma",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "One command over a Sanoma repo: run the worker and the app, check it, write its .env.example, export a run's ledger",
5
5
  "keywords": [
6
6
  "approvals",
@@ -22,10 +22,13 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
+ "template",
25
26
  "tsconfig.base.json",
26
27
  "oxlint.json",
27
28
  "README.md",
28
- "LICENSE"
29
+ "LICENSE",
30
+ "site.js",
31
+ "site.d.ts"
29
32
  ],
30
33
  "type": "module",
31
34
  "sideEffects": false,
@@ -36,25 +39,37 @@
36
39
  "types": "./dist/index.d.ts",
37
40
  "default": "./dist/index.js"
38
41
  },
42
+ "./resources": {
43
+ "types": "./dist/resources.d.ts",
44
+ "default": "./dist/resources.js"
45
+ },
46
+ "./site": {
47
+ "types": "./site.d.ts",
48
+ "default": "./site.js"
49
+ },
50
+ "./data": {
51
+ "types": "./dist/data.d.ts",
52
+ "default": "./dist/data.js"
53
+ },
39
54
  "./tsconfig.json": "./tsconfig.base.json"
40
55
  },
41
56
  "publishConfig": {
42
57
  "access": "public"
43
58
  },
44
59
  "dependencies": {
60
+ "@sanoma-ai/app": "0.4.0",
61
+ "@sanoma-ai/bridge": "0.4.0",
62
+ "@sanoma-ai/workflows": "0.4.0",
45
63
  "@types/node": "^26.6.4",
46
64
  "oxlint": "^1.87.0",
47
65
  "pg": "^8.23.1",
48
66
  "typescript": "^7.0.2",
49
- "zod": "^4.6.5",
50
- "@sanoma-ai/app": "0.1.0",
51
- "@sanoma-ai/workflows": "0.1.0",
52
- "@sanoma-ai/bridge": "0.1.0"
67
+ "zod": "^4.6.5"
53
68
  },
54
69
  "devDependencies": {
55
- "@types/pg": "^8.23.1",
56
- "@sanoma-ai/connector-ghost": "0.1.0",
57
- "@sanoma-ai/testing": "0.1.0"
70
+ "@sanoma-ai/connector-ghost": "0.4.0",
71
+ "@sanoma-ai/testing": "0.1.0",
72
+ "@types/pg": "^8.23.1"
58
73
  },
59
74
  "engines": {
60
75
  "node": "^24.2 || >=26"
package/site.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ // `sanoma/site`, what a site imports: the app's site surface (`@sanoma-ai/app/site`), which ships as
2
+ // source for the company's Vite build. Outside src/, so this package's own tsc never follows it.
3
+ export * from "@sanoma-ai/app/site";
package/site.js ADDED
@@ -0,0 +1,3 @@
1
+ // `sanoma/site`, what a site imports: the app's site surface (`@sanoma-ai/app/site`), which ships as
2
+ // source for the company's Vite build. Outside src/, so this package's own tsc never follows it.
3
+ export * from "@sanoma-ai/app/site";
@@ -0,0 +1,24 @@
1
+ # Copy to .env (ignored by git; `sanoma` loads it before reading the config). Never commit values.
2
+ # The first block is what sanoma needs before anything runs. The vendor variables below it can
3
+ # also be set on the app's connector pages (stored in the database and loaded by the worker); a
4
+ # value set here wins over a stored one and cannot be changed from the page. An empty value is
5
+ # the same as unset.
6
+
7
+ # Optional. Postgres for the worker and the app; default postgresql://postgres:dbos@localhost:5433/sanoma.
8
+ # SANOMA_DATABASE_URL=
9
+ # Optional. Encrypts the stored credentials, and signs GitHub sign-in's cookie: 32 random bytes,
10
+ # base64. `sanoma` writes one here when none is set; keep it with the database.
11
+ # SANOMA_SECRETS_KEY=
12
+ # Optional. The app's port; default 3000.
13
+ # SANOMA_APP_PORT=
14
+ # Optional. The address the app listens on; default 127.0.0.1. Any other needs GitHub sign-in.
15
+ # SANOMA_APP_HOST=
16
+ # Optional. GitHub sign-in: the OAuth client of the company's GitHub App. Who may sign in is
17
+ # resources/people.ts. Both or neither.
18
+ # SANOMA_GITHUB_CLIENT_ID=
19
+ # SANOMA_GITHUB_CLIENT_SECRET=
20
+
21
+ # ghost: the site's admin URL, such as https://example.ghost.io
22
+ GHOST_ADMIN_URL=
23
+ # ghost: a custom integration's Admin API key, <id>:<secret>
24
+ GHOST_ADMIN_API_KEY=
@@ -0,0 +1,41 @@
1
+ # A company on Sanoma
2
+
3
+ This repository is a company's operations as code, run by [Sanoma](https://github.com/Sanoma-AI/sanoma): workflows that call vendors through connectors, the people who use it, Cedar policies that decide which calls and runs wait for someone's approval or are refused, and the vendor objects the company owns, declared as data. `npx sanoma` in an empty directory started it; `sanoma` from npm runs it. The `sanoma` package's README (`node_modules/sanoma/README.md`) is the manual.
4
+
5
+ ## Layout
6
+
7
+ ```
8
+ sanoma.config.ts the workflows and the connectors
9
+ workflows/ one workflow per file (defineWorkflow)
10
+ policies/*.cedar who may do what: Cedar forbids, each a hold for an approver (@hold) or a deny (@reason)
11
+ resources/ data files: the vendor objects this company declares, by area
12
+ resources/data.ts collections: the company's own records (collection, from sanoma/data)
13
+ resources/people.ts who may use the app, the agents, and the groups (sanoma.person, .agent and .group, from sanoma/resources)
14
+ scenarios/ Gherkin: how each workflow should go against the connectors' fakes
15
+ sites/ pages the app serves under /sites/<name>: sites/<name>/routes/ holds TanStack Router file routes (none yet)
16
+ .env this machine's settings and secrets, never committed (SANOMA_SECRETS_KEY encrypts stored credentials)
17
+ ```
18
+
19
+ The app's name is `package.json`'s `name`. `.env.example` (written by `sanoma env`) and `.oxlintrc.json` (written by `sanoma check` when missing) are generated, and so are `sites/__virtual.ts` and `sites/tsconfig.json` once there is a site: commit them, never edit them. `.sanoma/` holds what `sanoma` builds (ignored), `.sanoma/api.ts` among it: the typed `api` for sites, and `.sanoma/schema.cedarschema`, the schema the policies are checked against, both generated from the config by `sanoma check` and at start, never edited.
20
+
21
+ ## Run
22
+
23
+ With the package manager whose lockfile is here (`npm run <script>`, `pnpm <script>`, …):
24
+
25
+ ```sh
26
+ npm run dev # Postgres (in Docker when nothing answers), the worker and the app; the app at the printed address
27
+ npm run check # tsc, the lint, the policies, what the worker would refuse, the sites' build and types, and every scenario
28
+ npm run env # rewrites .env.example from the connectors' variables
29
+ ```
30
+
31
+ ## Rules
32
+
33
+ - A workflow imports only from `sanoma`, its connectors and relative files, and does the same thing every time it is replayed: `ctx.now()` and `ctx.sleep()`, never `Date` or timers; configuration comes in as input, never from `process.env`. The `check` script holds workflows and data files to this.
34
+ - Define each workflow's `name` as a string literal: the app finds the workflow in its file by it.
35
+ - Every operation a workflow calls is listed in its `uses`; add the connector to `sanoma.config.ts` and to `package.json`.
36
+ - Declare the company's own records as collections in `resources/data.ts`, which imports only `collection` from `sanoma/data` and holds nothing else: the runtime imports it, and so does a workflow that names a collection's operations (`import { outbound } from "../resources/data.ts"`, the one file outside `workflows/` a workflow may import). Every other data file is read, never run.
37
+ - Only a person declared with `sanoma.person` (in `resources/people.ts` by convention, a data file like any other) signs in to the app (by `id` on this machine; with GitHub sign-in by email, then `github` login), starts a run, calls an operation or decides an approval, in the groups that list them (`sanoma.group({ name, members: [ada, refundBot] })`, the one place a membership is written). An agent (`sanoma.agent({ id, onBehalfOf: bo })`) is in the group `agents` besides; it never signs in. A new colleague is an edit to that file before their first sign-in. Nobody decides an approval on a run they started while someone else in the group could; alone in it, they decide, and the ledger says so.
38
+ - The policies are `policies/*.cedar`, written in [Cedar](https://docs.cedarpolicy.com) against `.sanoma/schema.cedarschema`. Everything is allowed unless a `forbid` refuses it; the runtime writes the one `permit`, so a `permit` here is a problem. A `forbid` with `@hold("<group>")` (or a person's id, or `"on-behalf-of"` for whom an agent acts) waits for that approver, with `@title` as its title in the Inbox, and the run goes on once they approve; one without `@hold` is denied, with `@reason` as the message. Actions are each operation's id (`Sanoma::Action::"ghost.post.publish"`), in its effect's group (`Sanoma::Action::"effect:publish"`), and `Sanoma::Action::"workflow:<name>"` for starting a run; `principal in Sanoma::Group::"editor"` is membership; `context.input` is the call's input. The app's Permissions page shows what they answer for each group. The `check` script reports a policy problem (a field, action or group the schema lacks, a `@hold` naming no one declared) at its `file:line:col`, and runs no scenario until there are none; `npm run dev` refuses to start on them.
39
+ - Describe each workflow's expected runs in `scenarios/<workflow>/<name>.feature`, and run the `check` script after every change. A scenario runs as the runtime's own agent `scenarios` unless it says who is acting (`Given reviewer is acting`), and checks the policy with `Then <op> was held for group "<group>"` and `Then <op> was denied with "<reason>"`; a scenario's approver (`is approved by reviewer`) must be declared. `reviewer` in `resources/people.ts` is a stand-in who can sign in and approve: replace them with a real colleague, in the scenarios too.
40
+ - A site, `sites/<name>/routes/` (pages the app serves under `/sites/<name>/`, with an optional `sites/<name>/site.ts` naming it with `defineSite`), is browser code: no server code, credential or `process.env` under `sites/`, which the `check` script holds it to, and the folder's name is its URL segment (lowercase letters, digits and dashes). Its route files import `createFileRoute` from `@tanstack/react-router`, routing (`Link`, `Outlet`, `useNavigate`, `defineSite`, …) from `sanoma/site`, and UI from `@sanoma-ai/app/ui`: the app's own components (`Button`, `Card`, `Table`, `Region`, `Facts`, …) and `<RunForm workflow="<name>" />`, the app's start form for a workflow. A page reaches data and workflows only through `api` from `sanoma/site`, as the person on the page: `api.data.<collection>.list()`, a vendor's read such as `api.<vendor>.<resource>.get(…)`, `await api.<workflow>(input)` or `api.<workflow>.start(input)` (the workflow's name in camelCase); see the app package's README (Sites). Name what a page calls with literals (`workflow="announce"`, `api.announce.start(…)`, not a variable): the app reads a site's calls from its code to list them under each workflow's Used by, and the `check` script fails on a call to a workflow, collection or operation that does not exist. While the `dev` script runs, an edit to a site shows in the open page as it is saved, and a new site folder is live without a restart.
41
+ - Never put credentials in a file here. They live in `.env` or on the app's connector pages, which store them encrypted in the database.
@@ -0,0 +1,11 @@
1
+ # Secrets must never be committed: .env holds this company's key and credentials.
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+ *.pem
6
+ *.key
7
+
8
+ node_modules/
9
+ dist/
10
+ .sanoma/
11
+ .DS_Store
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "company",
3
+ "private": true,
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "sanoma",
7
+ "check": "sanoma check",
8
+ "env": "sanoma env"
9
+ },
10
+ "dependencies": {
11
+ "@sanoma-ai/connector-ghost": "^0.4.0",
12
+ "sanoma": "^0.4.0"
13
+ },
14
+ "engines": {
15
+ "node": "^24.2 || >=26"
16
+ }
17
+ }
@@ -0,0 +1,4 @@
1
+ # pnpm holds back a release younger than its minimum age; a fresh Sanoma release is one.
2
+ minimumReleaseAgeExclude:
3
+ - sanoma
4
+ - "@sanoma-ai/*"
@@ -0,0 +1,17 @@
1
+ // Who may do what. Everything a login admits is allowed unless a `forbid` here refuses it: one
2
+ // with @hold waits for that group's (or person's) approval, with @title as the Inbox's title;
3
+ // one without is denied, with @reason as the message. Every operation call and run start is
4
+ // decided here. Write against .sanoma/schema.cedarschema, which `sanoma check` writes: the
5
+ // actions (each operation's id, in its effect's group, and `workflow:<name>`), the groups
6
+ // resources/people.ts declares, and each operation's input as `context.input`.
7
+
8
+ // Publishing or sending waits for someone in editor, unless someone in editor asked for it.
9
+ @id("editor-reviews")
10
+ @hold("editor")
11
+ @title("Review before it goes out")
12
+ forbid (
13
+ principal,
14
+ action in [Sanoma::Action::"effect:publish", Sanoma::Action::"effect:send"],
15
+ resource
16
+ )
17
+ unless { principal in Sanoma::Group::"editor" };
File without changes
@@ -0,0 +1,21 @@
1
+ // The company's own records, kept in its database. A collection's operations (`data.<name>.get`,
2
+ // `.list`, `.save` and `.delete`) are what a workflow names in `uses` and calls on
3
+ // `ctx.data.<name>`, under the policy and in the ledger. Workflows import this file
4
+ // (`import { outbound } from "../resources/data.ts"`), so it imports only from "sanoma/data" and
5
+ // holds only collections.
6
+ import { collection } from "sanoma/data";
7
+
8
+ /** The outbound pipeline: which lead is at which stage, and who owns it. */
9
+ export const outbound = collection({
10
+ name: "outbound",
11
+ title: "Outbound",
12
+ // Each record is found by its company: a required text field.
13
+ key: "company",
14
+ fields: {
15
+ company: "text",
16
+ contact: "text",
17
+ stage: { enum: ["researched", "contacted", "replied", "meeting", "won", "lost"] },
18
+ owner: "person",
19
+ lastTouched: { type: "date", optional: true },
20
+ },
21
+ });
File without changes
File without changes
File without changes
@@ -0,0 +1,20 @@
1
+ // Who may use this company's app, the agents that act in it, and the groups: resources like any
2
+ // other, read without running. Only a declared person signs in (the loopback sign-in by id,
3
+ // GitHub sign-in by email, then login), and acts in the groups that list them; an agent is in
4
+ // the group `agents` besides. Policies (policies/*.cedar) and approvals name people by id and
5
+ // groups by name.
6
+ import { sanoma } from "sanoma/resources";
7
+
8
+ /** Who started the company: `sanoma init` wrote them here. */
9
+ export const founder = sanoma.person({ id: "founder" });
10
+
11
+ /**
12
+ * Who reviews a post the scenarios publish: a stand-in, who can sign in and approve like anyone
13
+ * declared. Replace them with a real colleague, here and in the scenarios.
14
+ */
15
+ export const reviewer = sanoma.person({ id: "reviewer", name: "Reviewer" });
16
+
17
+ export const admin = sanoma.group({ name: "admin", members: [founder] });
18
+
19
+ /** Whoever publishes or sends without a review, and reviews everyone else's (policies/policy.cedar). */
20
+ export const editor = sanoma.group({ name: "editor", members: [founder, reviewer] });
@@ -0,0 +1,10 @@
1
+ // Never put credentials in this file or anywhere in this repo. The drivers read theirs from the
2
+ // environment or from the app's connector pages (see .env.example).
3
+ import { ghost } from "@sanoma-ai/connector-ghost";
4
+ import { defineConfig } from "sanoma";
5
+ import publishPost from "./workflows/publish-post.ts";
6
+
7
+ export default defineConfig({
8
+ workflows: [publishPost],
9
+ connectors: [ghost],
10
+ });
@@ -0,0 +1,28 @@
1
+ Feature: Publish a post
2
+ The post is drafted and published. The policy holds the publish for the editor group, unless
3
+ someone in editor started the run. A scenario runs as the agent `scenarios` unless it says who
4
+ is acting.
5
+
6
+ Scenario: The editor approves
7
+ When publish-post runs with
8
+ | title | Hello from us |
9
+ | html | <p>Our first post.</p> |
10
+ And "Review before it goes out" is approved by reviewer
11
+ Then ghost.post.publish was held for group "editor"
12
+ And a post titled "Hello from us" is created
13
+ And step "Publish the post" ran 1 time
14
+ And the run succeeds
15
+
16
+ Scenario: The editor rejects
17
+ When publish-post runs with
18
+ | title | Hello from us |
19
+ And "Review before it goes out" is rejected by reviewer
20
+ Then ghost.post.publish was not called
21
+ And the run fails with "approval_rejected"
22
+
23
+ Scenario: An editor publishes without a review
24
+ Given reviewer is acting
25
+ When publish-post runs with
26
+ | title | Hello from us |
27
+ Then ghost.post.publish was called
28
+ And the run succeeds
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "sanoma/tsconfig.json",
3
+ "include": ["sanoma.config.ts", "workflows", "resources", "scenarios"]
4
+ }
@@ -0,0 +1,20 @@
1
+ import { ghost } from "@sanoma-ai/connector-ghost";
2
+ import { defineWorkflow, z } from "sanoma";
3
+
4
+ /** Draft a blog post, then publish it: the policy has an editor review it first (policies/policy.cedar). */
5
+ export default defineWorkflow({
6
+ name: "publish-post",
7
+ title: "Publish a post",
8
+ trigger: "manual",
9
+ input: z.object({
10
+ title: z.string().min(1),
11
+ /** The post's body, as HTML. */
12
+ html: z.string().min(1),
13
+ }),
14
+ uses: [ghost.post.create, ghost.post.publish],
15
+ run: async (ctx, { title, html }) => {
16
+ const post = await ctx.ghost.post.create({ title, html, status: "draft" }, { name: "Draft the post" });
17
+ const published = await ctx.ghost.post.publish({ id: post.id }, { name: "Publish the post" });
18
+ return { url: published.url };
19
+ },
20
+ });