sanoma 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  One command over a company repo: `sanoma` runs its workflows and the app, `sanoma check` checks it, `sanoma env` writes its `.env.example`, `sanoma ledger export` exports a run. It also carries the surface a workflow or policy imports (`defineWorkflow`, `definePolicy`, the decisions, `defineConfig` and the types), so a repo depends on `sanoma` and its connectors, and writes no `worker.ts`, `app.ts`, compose file or vitest config.
4
4
 
5
+ ## Start a company
6
+
7
+ ```sh
8
+ mkdir acme && cd acme
9
+ npx sanoma
10
+ ```
11
+
12
+ In an empty directory (dotfiles aside), `sanoma` starts a company there, then runs it: it copies the template this package ships (`template/`: `sanoma.config.ts`, a `publish-post` workflow with its scenarios, a policy, an empty `resources/` tree, `AGENTS.md`, `.env.example`), names the package after the directory, writes `.env` with the default `SANOMA_DATABASE_URL` and a new `SANOMA_SECRETS_KEY` (keeping what a `.env` there already sets), commits what it wrote (never a dotfile that was already there) as the first commit of a git repository on `main`, "Start a Sanoma company", as your git user, then installs with the package manager that ran it (`npm_config_user_agent`; pnpm when it names none) and adds the lockfile to that commit. The `sanoma` it installed then serves the company. Without git or a git user it stops before writing anything; a failed install leaves the commit, to install and run `sanoma` again in. A directory holding anything else and no `sanoma.config.ts` is refused, as for every command.
13
+
5
14
  ## Install
6
15
 
7
16
  ```sh
@@ -55,16 +64,16 @@ A workflow or policy imports from `sanoma` what the lint lets it (`defineWorkflo
55
64
 
56
65
  Run them from the directory that holds `sanoma.config.ts`. Each loads `.env` there first, when there is one (a variable already set wins), then the config.
57
66
 
58
- | Command | What it does |
59
- | --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60
- | `sanoma` | Makes sure Postgres answers (see [Postgres](#postgres)), then starts the worker (promoted, so a local worker takes every queued run) and the app in one process, and prints `<appName> running <workflows>` and `<appName> at http://127.0.0.1:3000; ctrl-c to stop`; the worker says `sanoma: 2 of 5 connectors not configured yet: ghost, resend; …` first when some vendors' variables are missing or invalid (a call to one fails, naming them, until they are set; nothing when all are set). In [dev mode](#dev-mode) it runs them in a child it restarts. |
61
- | `sanoma worker`, `sanoma app` | One of the two alone, for a deployment that runs them apart. Neither touches Docker. |
62
- | `sanoma check` | `tsc -p tsconfig.json`; oxlint over `workflows/`, `policies/` and `resources/` with the repo's `.oxlintrc.json`, written when missing (see [the lint](#the-lint)); every problem `describeConfig` finds (an import a workflow may not make, what its graph cannot draw, a data file outside the subset: what the worker would refuse); then every scenario against the fakes, on a database of its own (`<database>_check`), each step that did not hold a problem. Prints each problem on a line, `file:line:col: message` or `scenario › step: message`, and exits 1 when there is one. No vitest. |
63
- | `sanoma env [--check]` | Writes `.env.example`: the variables `sanoma` reads, then every variable the connectors' drivers declare, by vendor, with its description; optional ones commented out. `--check` writes nothing and exits 1 with "`.env.example` is out of date: run `sanoma env`" when the file differs, for CI. |
64
- | `sanoma ledger export <runId> [--out <file>]` | A run's ledger records from the config's store (the Postgres ledger on its database when it names none), as JSON lines (the shape `jsonlLedger` keeps), to stdout or `--out`. |
65
- | `sanoma --help` | The usage. |
67
+ | Command | What it does |
68
+ | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
69
+ | `sanoma` | Makes `SANOMA_SECRETS_KEY`, which encrypts the stored credentials, when the environment and `.env` have none, appending it to `.env` with one line saying so; makes sure Postgres answers (see [Postgres](#postgres)), then starts the worker (promoted, so a local worker takes every queued run) and the app in one process, and prints `<appName> running <workflows>` and `<appName> at http://127.0.0.1:3000; ctrl-c to stop`; the worker says `sanoma: 2 of 5 connectors not configured yet: ghost, resend; …` first when some vendors' variables are missing or invalid (a call to one fails, naming them, until they are set; nothing when all are set). In [dev mode](#dev-mode) it runs them in a child it restarts. In an empty directory it first [starts a company](#start-a-company). The worker and the app are given the repo's git checkout as their `source`, which commits to the current branch. |
70
+ | `sanoma worker`, `sanoma app` | One of the two alone, for a deployment that runs them apart. Neither touches Docker. |
71
+ | `sanoma check` | `tsc -p tsconfig.json`; oxlint over `workflows/`, `policies/` and `resources/` with the repo's `.oxlintrc.json`, written when missing (see [the lint](#the-lint)); every problem `describeConfig` finds (an import a workflow may not make, what its graph cannot draw, a data file outside the subset: what the worker would refuse); then every scenario against the fakes, on a database of its own (`<database>_check`), each step that did not hold a problem. Prints each problem on a line, `file:line:col: message` or `scenario › step: message`, and exits 1 when there is one. No vitest. |
72
+ | `sanoma env [--check]` | Writes `.env.example`: the variables `sanoma` reads, then every variable the connectors' drivers declare, by vendor, with its description; optional ones commented out. `--check` writes nothing and exits 1 with "`.env.example` is out of date: run `sanoma env`" when the file differs, for CI. |
73
+ | `sanoma ledger export <runId> [--out <file>]` | A run's ledger records from the config's store (the Postgres ledger on its database when it names none), as JSON lines (the shape `jsonlLedger` keeps), to stdout or `--out`. |
74
+ | `sanoma --help` | The usage. |
66
75
 
67
- Exit codes: 2 for a mistake in the call or the repo (no `sanoma.config.ts`, an unknown command or option, a bad argument), printed with the usage where it helps; 1 for failed checks and failures while running; 0 otherwise. `SANOMA_APP_PORT` is the app's port (default 3000; 0 for any free port, which the printed address reports). On SIGINT or SIGTERM the app, then the worker, stop, and the process exits 0.
76
+ Exit codes: 2 for a mistake in the call or the repo (no `sanoma.config.ts`, an unknown command or option, a bad argument), printed with the usage where it helps; 1 for failed checks and failures while running; 0 otherwise. `SANOMA_APP_PORT` is the app's port (default 3000; 0 for any free port, which the printed address reports). `SANOMA_APP_HOST` is its address (default 127.0.0.1); any other needs [GitHub sign-in](../app/README.md#github), which `SANOMA_GITHUB_CLIENT_ID`, `SANOMA_GITHUB_CLIENT_SECRET` and `SANOMA_GITHUB_REPO` turn on (all three or none, with `SANOMA_SECRETS_KEY` set; the client id and secret may instead be the stored ones the app's Go live page saved when it created the GitHub App); a mistake in them exits 2 before anything starts. On SIGINT or SIGTERM the app, then the worker, stop, and the process exits 0.
68
77
 
69
78
  ## Postgres
70
79
 
@@ -72,7 +81,7 @@ The worker and the app run on `SANOMA_DATABASE_URL` (default `postgresql://postg
72
81
 
73
82
  ## `.env.example`
74
83
 
75
- `sanoma env` keeps `.env.example` the manual of the variables: `SANOMA_DATABASE_URL` and `SANOMA_APP_PORT` first, with their defaults, then a block per vendor in the connectors' order, each variable its driver's `env` declares with its `.describe()` text. A required variable is `NAME=`; an optional one is commented out, `# NAME=`, with `Optional.` before its description. The same config gives the same text, which `--check` compares byte for byte. Copy it to `.env` (ignored by git) and fill it in; the vendor variables can also be set on the app's connector pages, where a value from the environment wins over a stored one.
84
+ `sanoma env` keeps `.env.example` the manual of the variables: `SANOMA_DATABASE_URL`, `SANOMA_APP_PORT`, `SANOMA_APP_HOST` and the GitHub sign-in variables first, with their defaults, then a block per vendor in the connectors' order, each variable its driver's `env` declares with its `.describe()` text. A required variable is `NAME=`; an optional one is commented out, `# NAME=`, with `Optional.` before its description. The same config gives the same text, which `--check` compares byte for byte. Copy it to `.env` (ignored by git) and fill it in; the vendor variables can also be set on the app's connector pages, where a value from the environment wins over a stored one.
76
85
 
77
86
  ## The lint
78
87
 
@@ -103,4 +112,6 @@ Linking some of `sanoma`, `@sanoma-ai/workflows`, `@sanoma-ai/app` and `@sanoma-
103
112
 
104
113
  `sanoma worker` and `sanoma app` are the deployment's two processes. A host that composes its own process keeps `startWorker` from `@sanoma-ai/workflows` and `startApp` from `@sanoma-ai/app`, which the bin runs.
105
114
 
115
+ [`runtime/`](runtime/Dockerfile) is the image a container host runs: Node 24, git, pnpm (corepack) and `provider-bridge`, and no company code. At start it clones `SANOMA_SOURCE` at `SANOMA_REVISION` (with `SANOMA_SOURCE_TOKEN` as an HTTP header when set), runs `pnpm install --frozen-lockfile` and `sanoma serve` on `0.0.0.0` and `PORT` (default 3000); the host passes `SANOMA_DATABASE_URL`, `SANOMA_SECRETS_KEY` and, as the app is not on loopback, the `SANOMA_GITHUB_*` sign-in variables too. Its health check is the app's `/healthz`. `provider-bridge` is built from source at a pinned commit; `--build-arg BRIDGE_FROM=release --build-arg BRIDGE_VERSION=<x.y.z>` downloads a release instead. CI builds the image and pushes it nowhere.
116
+
106
117
  Status: early (0.x). License: FSL-1.1-ALv2.
package/dist/cli.js CHANGED
@@ -1,8 +1,16 @@
1
1
  #!/usr/bin/env node
2
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
3
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
4
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
5
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
6
+ });
7
+ }
8
+ return path;
9
+ };
2
10
  import { spawn } from "node:child_process";
3
- import { writeFileSync } from "node:fs";
11
+ import { existsSync, writeFileSync } from "node:fs";
4
12
  import { join } from "node:path";
5
- import { fileURLToPath } from "node:url";
13
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
14
  import { parseArgs } from "node:util";
7
15
  import { loadConfig, UsageError } from "./config.js";
8
16
  // Only Node's modules and ./config.ts are imported here: each command imports what it runs, so
@@ -11,7 +19,9 @@ const USAGE = `usage: sanoma [command]
11
19
 
12
20
  Runs the repo in the working directory, from its sanoma.config.ts (after its .env, when there is one).
13
21
 
14
- sanoma the worker and the app; starts Postgres in Docker when nothing answers
22
+ sanoma the worker and the app; starts Postgres in Docker when nothing answers. In an
23
+ empty directory, first starts a company there: the template, .env, an install
24
+ and a git repository
15
25
  sanoma worker the worker alone, for a deployment
16
26
  sanoma app the app alone, for a deployment
17
27
  sanoma check typecheck, lint, read the config, run every scenario; exit 1 on a problem
@@ -20,7 +30,8 @@ Runs the repo in the working directory, from its sanoma.config.ts (after its .en
20
30
  a run's ledger records as JSON lines
21
31
 
22
32
  SANOMA_DATABASE_URL names Postgres (default postgresql://postgres:dbos@localhost:5433/sanoma); SANOMA_APP_PORT the
23
- app's port (default 3000; 0 for any free port). With sanoma or a @sanoma-ai package linked from a sanoma checkout,
33
+ app's port (default 3000; 0 for any free port); SANOMA_APP_HOST its address (default 127.0.0.1; any other needs
34
+ GitHub sign-in, see .env.example). With sanoma or a @sanoma-ai package linked from a sanoma checkout,
24
35
  or SANOMA_DEV_REPO set, \`sanoma\` also runs each linked package's watch build and restarts on a new build.
25
36
  `;
26
37
  /** Exit codes: 2 for how the bin was called or what it found, 1 for failed checks and failures while running. */
@@ -44,6 +55,11 @@ export async function main(argv) {
44
55
  const [command, ...rest] = positionals;
45
56
  switch (command) {
46
57
  case undefined: {
58
+ if (!existsSync(join(process.cwd(), "sanoma.config.ts"))) {
59
+ const { startCompany } = await import("./init.js");
60
+ if (await startCompany(process.cwd(), { log }))
61
+ return serveStarted(process.cwd());
62
+ }
47
63
  const { devRepo, linkedPackages } = await import("./dev.js");
48
64
  const linked = linkedPackages(process.cwd());
49
65
  const repo = devRepo(process.cwd(), linked);
@@ -105,12 +121,24 @@ async function keep({ config, resolved }, start) {
105
121
  /** `sanoma serve` (and `sanoma` outside dev mode): Postgres, then the worker and the app in this process. */
106
122
  async function serveCommand() {
107
123
  const loaded = await load();
124
+ (await import("./key.js")).ensureSecretsKey(process.cwd(), log);
108
125
  const { appName, databaseUrl } = loaded.resolved;
109
126
  const { ensurePostgres } = await import("./postgres.js");
110
127
  await ensurePostgres(databaseUrl, { appName, log });
111
128
  const { serve } = await import("./serve.js");
112
129
  return keep(loaded, (config) => serve(config, { port: port() }));
113
130
  }
131
+ /**
132
+ * A company just started in `cwd`: the `sanoma` it installed serves it, in this process, so that
133
+ * the config and the worker load the same packages; this one when it installed none there.
134
+ */
135
+ async function serveStarted(cwd) {
136
+ const installed = join(cwd, "node_modules/sanoma/dist/cli.js");
137
+ if (!existsSync(installed))
138
+ return serveCommand();
139
+ const { main: run } = (await import(__rewriteRelativeImportExtension(pathToFileURL(installed).href)));
140
+ return run([]);
141
+ }
114
142
  /**
115
143
  * Dev mode: `sanoma serve` in a child it restarts on a new build, and each linked package's
116
144
  * `watch`. Each runs in a process group of its own, so a terminal's ctrl-c reaches this process
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAe,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGlE,+FAA+F;AAC/F,gGAAgG;AAEhG,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;CAeb,CAAC;AAEF,iHAAiH;AACjH,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,MAAM,GAAG,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAElD,MAAM,SAAS,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAEvF,wGAAwG;AACxG,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAc;IACvC,IAAI,IAA8B,CAAC;IACnC,IAAI,CAAC;QAC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AAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QACpB,OAAO,CAAC,QAAQ,GAAG,GAAG,YAAY,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
package/dist/env.js CHANGED
@@ -20,8 +20,18 @@ export function renderEnvExample({ config, resolved }) {
20
20
  // The default: the config's own, else sanoma's, never this environment's.
21
21
  `# Optional. Postgres for the worker and the app; default ${resolveDatabaseUrl(config, {})}.`,
22
22
  "# SANOMA_DATABASE_URL=",
23
+ "# Optional. Encrypts the stored credentials, and signs GitHub sign-in's cookie: 32 random bytes,",
24
+ "# base64. `sanoma` writes one here when none is set; keep it with the database.",
25
+ "# SANOMA_SECRETS_KEY=",
23
26
  "# Optional. The app's port; default 3000.",
24
27
  "# SANOMA_APP_PORT=",
28
+ "# Optional. The address the app listens on; default 127.0.0.1. Any other needs GitHub sign-in.",
29
+ "# SANOMA_APP_HOST=",
30
+ "# Optional. GitHub sign-in: the OAuth client of the company's GitHub App, and the owner/name of the",
31
+ "# repository whose collaborators with write access or more may sign in. All three or none.",
32
+ "# SANOMA_GITHUB_CLIENT_ID=",
33
+ "# SANOMA_GITHUB_CLIENT_SECRET=",
34
+ "# SANOMA_GITHUB_REPO=",
25
35
  ];
26
36
  for (const [vendor, variables] of credentialsOf(resolved.driversByVendor, () => undefined)) {
27
37
  lines.push("");
package/dist/env.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACj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AI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE,CAAC;YACxD,MAAM,KAAK,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,WAAW,EAAE,CAAC;YAClE,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,GAAG,KAAK,EAAE,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,CAAC,CAAC;QACtG,CAAC;IACH,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,EAAE,KAAK,EAAsB;IAC3E,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1E,MAAM,OAAO,GAAG,OAAO,KAAK,IAAI,CAAC;IACjC,IAAI,OAAO,IAAI,CAAC,KAAK;QAAE,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
package/dist/init.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /** The company template this package ships (`files`): `template/` beside `src/` and `dist/`. */
2
+ export declare const TEMPLATE: import("node:url").URL;
3
+ /** The runtime's default database (`resolveDatabaseUrl`), which this module does not load `@sanoma-ai/workflows` for; a test holds them equal. */
4
+ export declare const DATABASE_URL = "postgresql://postgres:dbos@localhost:5433/sanoma";
5
+ export declare const FIRST_COMMIT = "Start a Sanoma company";
6
+ export interface StartOptions {
7
+ /** Runs `<packageManager> install` in the directory; the default inherits this process's stdio. */
8
+ install?: (cwd: string, packageManager: string) => Promise<void>;
9
+ log?: (line: string) => void;
10
+ }
11
+ /**
12
+ * `sanoma` where there is no `sanoma.config.ts`: in an empty directory (dotfiles aside) it starts
13
+ * a company there and says so; anywhere else it does nothing and says it did not. Starting copies
14
+ * the template, names the package after the directory, writes `.env` (the default database and a
15
+ * new `SANOMA_SECRETS_KEY`, keeping what it already holds), commits what it wrote as the first
16
+ * commit of a git repository, as the machine's git user, then installs with the package manager
17
+ * that ran this (`npm_config_user_agent`, else pnpm) and adds the lockfile to that commit. Throws
18
+ * before writing anything when git is missing or has no user to commit as.
19
+ */
20
+ export declare function startCompany(cwd: string, { install, log }?: StartOptions): Promise<boolean>;
21
+ /** The package manager named first in `npm_config_user_agent` (`pnpm/11.1.0 npm/? node/v24…`), else pnpm. */
22
+ export declare function packageManagerOf(userAgent: string | undefined): string;
23
+ /** A directory's name as a package's: lower case, runs of anything else made one `-`; `company` when nothing is left. */
24
+ export declare const packageName: (dir: string) => string;
package/dist/init.js ADDED
@@ -0,0 +1,86 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { appendFileSync, cpSync, existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from "node:fs";
3
+ import { basename, join } from "node:path";
4
+ import { promisify } from "node:util";
5
+ import { addToEnv, writeSecretsKey } from "./key.js";
6
+ const run = promisify(execFile);
7
+ /** The company template this package ships (`files`): `template/` beside `src/` and `dist/`. */
8
+ export const TEMPLATE = new URL("../template/", import.meta.url);
9
+ /** The runtime's default database (`resolveDatabaseUrl`), which this module does not load `@sanoma-ai/workflows` for; a test holds them equal. */
10
+ export const DATABASE_URL = "postgresql://postgres:dbos@localhost:5433/sanoma";
11
+ export const FIRST_COMMIT = "Start a Sanoma company";
12
+ /** What each package manager writes beside `package.json`. */
13
+ const LOCKFILES = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
14
+ /**
15
+ * `sanoma` where there is no `sanoma.config.ts`: in an empty directory (dotfiles aside) it starts
16
+ * a company there and says so; anywhere else it does nothing and says it did not. Starting copies
17
+ * the template, names the package after the directory, writes `.env` (the default database and a
18
+ * new `SANOMA_SECRETS_KEY`, keeping what it already holds), commits what it wrote as the first
19
+ * commit of a git repository, as the machine's git user, then installs with the package manager
20
+ * that ran this (`npm_config_user_agent`, else pnpm) and adds the lockfile to that commit. Throws
21
+ * before writing anything when git is missing or has no user to commit as.
22
+ */
23
+ export async function startCompany(cwd, { install = installWith, log = () => { } } = {}) {
24
+ if (readdirSync(cwd).some((name) => !name.startsWith(".")))
25
+ return false;
26
+ await run("git", ["var", "GIT_AUTHOR_IDENT"]).catch((err) => {
27
+ const missing = err.code === "ENOENT";
28
+ throw new Error(missing ? "git is not installed" : "git needs a user to commit as: set git config user.name and user.email", { cause: err });
29
+ });
30
+ log(`starting a Sanoma company in ${cwd}`);
31
+ cpSync(TEMPLATE, cwd, { recursive: true, force: false });
32
+ // npm drops a package's .gitignore, so the template carries it as gitignore.
33
+ const [carried, ignore] = [join(cwd, "gitignore"), join(cwd, ".gitignore")];
34
+ if (!existsSync(ignore))
35
+ renameSync(carried, ignore);
36
+ else {
37
+ appendFileSync(ignore, `\n${readFileSync(carried, "utf8")}`);
38
+ rmSync(carried);
39
+ }
40
+ const own = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
41
+ const manifest = join(cwd, "package.json");
42
+ const pkg = JSON.parse(readFileSync(manifest, "utf8"));
43
+ const name = packageName(basename(cwd));
44
+ // npm refuses to install a package into one of the same name (`sanoma` in `sanoma/`).
45
+ pkg.name = name in pkg.dependencies ? `${name}-company` : name;
46
+ // The template's packages at this launcher's version: Sanoma releases them together.
47
+ for (const dep of Object.keys(pkg.dependencies))
48
+ pkg.dependencies[dep] = `^${own.version}`;
49
+ writeFileSync(manifest, `${JSON.stringify(pkg, null, 2)}\n`);
50
+ addToEnv(join(cwd, ".env"), { SANOMA_DATABASE_URL: DATABASE_URL });
51
+ writeSecretsKey(join(cwd, ".env"));
52
+ const packageManager = packageManagerOf(process.env.npm_config_user_agent);
53
+ if (packageManager !== "pnpm")
54
+ rmSync(join(cwd, "pnpm-workspace.yaml"));
55
+ // Committed before the install, so a failed install leaves a repository to rerun it in; the
56
+ // lockfile joins the same commit after. Only what this wrote: a dotfile already here may be a secret.
57
+ const commit = async (...args) => {
58
+ const wrote = [...readdirSync(TEMPLATE), ...LOCKFILES]
59
+ .map((file) => (file === "gitignore" ? ".gitignore" : file))
60
+ .filter((file) => existsSync(join(cwd, file)));
61
+ await run("git", ["add", "--", ...wrote], { cwd });
62
+ await run("git", ["commit", "--quiet", "-m", FIRST_COMMIT, ...args], { cwd });
63
+ };
64
+ await run("git", ["init", "--quiet", "--initial-branch=main"], { cwd });
65
+ await commit();
66
+ log(`committed "${FIRST_COMMIT}"; installing with ${packageManager}`);
67
+ await install(cwd, packageManager);
68
+ await commit("--amend");
69
+ return true;
70
+ }
71
+ /** The package manager named first in `npm_config_user_agent` (`pnpm/11.1.0 npm/? node/v24…`), else pnpm. */
72
+ export function packageManagerOf(userAgent) {
73
+ const name = userAgent?.split("/")[0];
74
+ return name === "npm" || name === "yarn" || name === "bun" ? name : "pnpm";
75
+ }
76
+ /** A directory's name as a package's: lower case, runs of anything else made one `-`; `company` when nothing is left. */
77
+ export const packageName = (dir) => dir
78
+ .toLowerCase()
79
+ .replace(/[^a-z0-9._-]+/g, "-")
80
+ .replace(/^[-._]+|-+$/g, "") || "company";
81
+ const installWith = (cwd, packageManager) => new Promise((resolve, reject) => {
82
+ const child = spawn(packageManager, ["install"], { cwd, stdio: "inherit" });
83
+ child.once("error", reject);
84
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`${packageManager} install failed; run it in ${cwd}, then sanoma`)));
85
+ });
86
+ //# sourceMappingURL=init.js.map
@@ -0,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AC,cAAc,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC5E,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAC1B,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,cAAc,8BAA8B,GAAG,eAAe,CAAC,CAAC,CAC9G,CAAC;AACJ,CAAC,CAAC,CAAC"}
package/dist/key.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Adds each variable `file` (a `.env`) does not set yet, an empty value counting as unset, and
3
+ * keeps the file's own; a new file is readable by its owner alone. Returns the names it added.
4
+ */
5
+ export declare function addToEnv(file: string, values: Record<string, string>): string[];
6
+ /**
7
+ * The one writer of `SANOMA_SECRETS_KEY`, which encrypts the stored credentials: unless `file`
8
+ * already sets it, makes one (32 random bytes, base64) and adds it (`addToEnv`). Returns the key
9
+ * it made, or undefined when it kept the file's.
10
+ */
11
+ export declare function writeSecretsKey(file: string): string | undefined;
12
+ /**
13
+ * Makes sure `SANOMA_SECRETS_KEY` is set: when the environment (with `<dir>/.env` loaded) has
14
+ * none, writes one to `<dir>/.env` (`writeSecretsKey`), sets it here, and logs one line.
15
+ */
16
+ export declare function ensureSecretsKey(dir: string, log: (line: string) => void): void;
package/dist/key.js ADDED
@@ -0,0 +1,43 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { appendFileSync, existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { parseEnv } from "node:util";
5
+ const KEY = "SANOMA_SECRETS_KEY";
6
+ /**
7
+ * Adds each variable `file` (a `.env`) does not set yet, an empty value counting as unset, and
8
+ * keeps the file's own; a new file is readable by its owner alone. Returns the names it added.
9
+ */
10
+ export function addToEnv(file, values) {
11
+ const text = existsSync(file) ? readFileSync(file, "utf8") : "";
12
+ const set = parseEnv(text);
13
+ const added = Object.keys(values).filter((name) => !set[name]);
14
+ if (!added.length)
15
+ return added;
16
+ const gap = text === "" || text.endsWith("\n") ? "" : "\n";
17
+ appendFileSync(file, gap + added.map((name) => `${name}=${values[name]}\n`).join(""), { mode: 0o600 });
18
+ return added;
19
+ }
20
+ /**
21
+ * The one writer of `SANOMA_SECRETS_KEY`, which encrypts the stored credentials: unless `file`
22
+ * already sets it, makes one (32 random bytes, base64) and adds it (`addToEnv`). Returns the key
23
+ * it made, or undefined when it kept the file's.
24
+ */
25
+ export function writeSecretsKey(file) {
26
+ const key = randomBytes(32).toString("base64");
27
+ return addToEnv(file, { [KEY]: key }).length ? key : undefined;
28
+ }
29
+ /**
30
+ * Makes sure `SANOMA_SECRETS_KEY` is set: when the environment (with `<dir>/.env` loaded) has
31
+ * none, writes one to `<dir>/.env` (`writeSecretsKey`), sets it here, and logs one line.
32
+ */
33
+ export function ensureSecretsKey(dir, log) {
34
+ if (process.env[KEY])
35
+ return;
36
+ const file = join(dir, ".env");
37
+ const key = writeSecretsKey(file);
38
+ if (key === undefined)
39
+ return;
40
+ process.env[KEY] = key;
41
+ log(`created ${KEY} in ${file}: it encrypts the stored credentials, so keep it with the database`);
42
+ }
43
+ //# sourceMappingURL=key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key.js","sourceRoot":"","sources":["../src/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,GAAG,GAAG,oBAAoB,CAAC;AAEjC;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,IA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AC;QAAE,OAAO;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO;IAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACvB,GAAG,CAAC,WAAW,GAAG,OAAO,IAAI,oEAAoE,CAAC,CAAC;AACrG,CAAC"}
@@ -0,0 +1 @@
1
+ export { secret, type Secret } from "@sanoma-ai/workflows/resources";
@@ -0,0 +1,4 @@
1
+ // What a data file under `resources/` imports from sanoma: `secret`, which names a stored secret
2
+ // for a write-only field (`secret("SUPABASE_DB_PASSWORD", { generate: true })`).
3
+ export { secret } from "@sanoma-ai/workflows/resources";
4
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,iFAAiF;AACjF,OAAO,EAAE,MAAM,EAAe,MAAM,gCAAgC,CAAC"}
package/dist/serve.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type AppOptions } from "@sanoma-ai/app";
1
2
  import { type SanomaConfig } from "@sanoma-ai/workflows";
2
3
  export interface Stoppable {
3
4
  stop(): Promise<void>;
@@ -8,10 +9,20 @@ export interface Served extends Stoppable {
8
9
  }
9
10
  /** Starts the worker, promoted: a local worker is always the version to take queued runs, even one seen before. */
10
11
  export declare function runWorker(config: SanomaConfig): Promise<Stoppable>;
11
- /** Starts the app on `port` (0 for any free port); `url` says where. */
12
+ /** Starts the app on `port` (0 for any free port), with the host and login `appOptions` reads; `url` says where. */
12
13
  export declare function runApp(config: SanomaConfig, { port }: {
13
14
  port: number;
14
15
  }): Promise<Served>;
16
+ /** Reads stored secrets by name (`SanomaClient.secrets`): the values found, the environment's first. */
17
+ export type ReadSecrets = (names: string[]) => Promise<Map<string, string>>;
18
+ /**
19
+ * The app's host (`SANOMA_APP_HOST`, default 127.0.0.1) and, when the `SANOMA_GITHUB_*` variables
20
+ * are set, GitHub sign-in; all three or none, and any host but this machine needs it. An empty
21
+ * value is the same as unset. With the repository set, a client id or secret the environment
22
+ * leaves unset is read from the stored secrets (`readSecrets`), where creating the GitHub App on
23
+ * the app's connect page put them. A mistake in them is a UsageError.
24
+ */
25
+ export declare function appOptions(readSecrets?: ReadSecrets): Promise<Pick<AppOptions, "host" | "login">>;
15
26
  /** The worker first, then the app, in this process; `stop` stops the app, then the worker. */
16
27
  export declare function serve(config: SanomaConfig, { port }: {
17
28
  port: number;
package/dist/serve.js CHANGED
@@ -1,21 +1,80 @@
1
- import { startApp } from "@sanoma-ai/app";
2
- import { startWorker } from "@sanoma-ai/workflows";
1
+ import { dirname } from "node:path";
2
+ import { githubLogin, startApp } from "@sanoma-ai/app";
3
+ import { errorMessage, isLoopback, SanomaClient, startWorker } from "@sanoma-ai/workflows";
4
+ import { UsageError } from "./config.js";
5
+ import { localGitSource } from "./source.js";
6
+ /** The checkout the config was loaded from (`loadConfig` sets its `file`), as the worker's and the app's `source`. */
7
+ const sourceOf = (config) => localGitSource(config.root ?? dirname(config.file));
3
8
  /** Starts the worker, promoted: a local worker is always the version to take queued runs, even one seen before. */
4
9
  export async function runWorker(config) {
5
- const worker = await startWorker(config, { promote: true });
10
+ const worker = await startWorker(config, { promote: true, source: sourceOf(config) });
6
11
  return { stop: () => worker.stop() };
7
12
  }
8
- /** Starts the app on `port` (0 for any free port); `url` says where. */
13
+ /** Starts the app on `port` (0 for any free port), with the host and login `appOptions` reads; `url` says where. */
9
14
  export async function runApp(config, { port }) {
10
- const app = await startApp(config, { port });
15
+ return served(config, { port, ...(await appOptions(secretsOf(config))) });
16
+ }
17
+ async function served(config, options) {
18
+ const app = await startApp(config, { ...options, source: sourceOf(config) });
11
19
  return { url: app.url, stop: () => app.close() };
12
20
  }
21
+ const GITHUB = ["SANOMA_GITHUB_CLIENT_ID", "SANOMA_GITHUB_CLIENT_SECRET", "SANOMA_GITHUB_REPO"];
22
+ const CLIENT = GITHUB.slice(0, 2);
23
+ /** The config's stored secrets, through a client opened for the read. */
24
+ const secretsOf = (config) => async (names) => {
25
+ const client = await SanomaClient.connect(config);
26
+ try {
27
+ return new Map([...(await client.secrets(names))].map(([name, { value }]) => [name, value]));
28
+ }
29
+ finally {
30
+ await client.close();
31
+ }
32
+ };
33
+ /**
34
+ * The app's host (`SANOMA_APP_HOST`, default 127.0.0.1) and, when the `SANOMA_GITHUB_*` variables
35
+ * are set, GitHub sign-in; all three or none, and any host but this machine needs it. An empty
36
+ * value is the same as unset. With the repository set, a client id or secret the environment
37
+ * leaves unset is read from the stored secrets (`readSecrets`), where creating the GitHub App on
38
+ * the app's connect page put them. A mistake in them is a UsageError.
39
+ */
40
+ export async function appOptions(readSecrets) {
41
+ const env = process.env;
42
+ const host = env.SANOMA_APP_HOST || undefined;
43
+ const found = new Map(GITHUB.flatMap((name) => (env[name] ? [[name, env[name]]] : [])));
44
+ if (found.has("SANOMA_GITHUB_REPO") && readSecrets && CLIENT.some((name) => !found.has(name))) {
45
+ const stored = await readSecrets(CLIENT).catch((err) => {
46
+ throw new UsageError(`GitHub sign-in could not read the stored client id and secret: ${errorMessage(err)}`);
47
+ });
48
+ for (const [name, value] of stored)
49
+ if (value)
50
+ found.set(name, value);
51
+ }
52
+ const [clientId, clientSecret, repo] = GITHUB.map((name) => found.get(name));
53
+ if (!clientId && !clientSecret && !repo) {
54
+ if (host && !isLoopback(host)) {
55
+ throw new UsageError(`SANOMA_APP_HOST=${host} needs GitHub sign-in: set ${GITHUB.join(", ")}`);
56
+ }
57
+ return { host };
58
+ }
59
+ if (!clientId || !clientSecret || !repo) {
60
+ const missing = GITHUB.filter((name) => !found.has(name));
61
+ throw new UsageError(`GitHub sign-in needs ${GITHUB.join(", ")}: ${missing.join(", ")} not set`);
62
+ }
63
+ try {
64
+ return { host, login: githubLogin({ clientId, clientSecret, repo }) };
65
+ }
66
+ catch (err) {
67
+ throw new UsageError(errorMessage(err));
68
+ }
69
+ }
13
70
  /** The worker first, then the app, in this process; `stop` stops the app, then the worker. */
14
71
  export async function serve(config, { port }) {
72
+ // Read before the worker starts, so a mistake in the variables starts nothing.
73
+ const options = { port, ...(await appOptions(secretsOf(config))) };
15
74
  const worker = await runWorker(config);
16
75
  let app;
17
76
  try {
18
- app = await runApp(config, { port });
77
+ app = await served(config, options);
19
78
  }
20
79
  catch (err) {
21
80
  await worker.stop().catch(() => { });
package/dist/serve.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAqB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAWtE,mHAAmH;AACnH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAoB;IAClD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;AACvC,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,MAAoB,EAAE,EAAE,IAAI,EAAoB;IAC3E,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;AACnD,CAAC;AAED,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,MAAoB,EAAE,EAAE,IAAI,EAAoB;IAC1E,MAAM,MAAM,GAAG,MAAM,SA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AAC,MAAM,CAAC,CAAC;IACvC,IAAI,GAAW,CAAC;IAChB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACpC,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,CAAC,IAAI;YACR,IAAI,CAAC;gBACH,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YACnB,CAAC;oBAAS,CAAC;gBACT,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACtB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,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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E,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanoma",
3
- "version": "0.1.0",
3
+ "version": "0.2.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,6 +22,7 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
+ "template",
25
26
  "tsconfig.base.json",
26
27
  "oxlint.json",
27
28
  "README.md",
@@ -36,6 +37,10 @@
36
37
  "types": "./dist/index.d.ts",
37
38
  "default": "./dist/index.js"
38
39
  },
40
+ "./resources": {
41
+ "types": "./dist/resources.d.ts",
42
+ "default": "./dist/resources.js"
43
+ },
39
44
  "./tsconfig.json": "./tsconfig.base.json"
40
45
  },
41
46
  "publishConfig": {
@@ -47,13 +52,13 @@
47
52
  "pg": "^8.23.1",
48
53
  "typescript": "^7.0.2",
49
54
  "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"
55
+ "@sanoma-ai/app": "0.2.0",
56
+ "@sanoma-ai/bridge": "0.2.0",
57
+ "@sanoma-ai/workflows": "0.2.0"
53
58
  },
54
59
  "devDependencies": {
55
60
  "@types/pg": "^8.23.1",
56
- "@sanoma-ai/connector-ghost": "0.1.0",
61
+ "@sanoma-ai/connector-ghost": "0.2.0",
57
62
  "@sanoma-ai/testing": "0.1.0"
58
63
  },
59
64
  "engines": {
@@ -0,0 +1,25 @@
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, and the owner/name of the
17
+ # repository whose collaborators with write access or more may sign in. All three or none.
18
+ # SANOMA_GITHUB_CLIENT_ID=
19
+ # SANOMA_GITHUB_CLIENT_SECRET=
20
+ # SANOMA_GITHUB_REPO=
21
+
22
+ # ghost: the site's admin URL, such as https://example.ghost.io
23
+ GHOST_ADMIN_URL=
24
+ # ghost: a custom integration's Admin API key, <id>:<secret>
25
+ GHOST_ADMIN_API_KEY=
@@ -0,0 +1,34 @@
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, a policy that decides which calls need a person's approval, 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, the connectors and the policy
9
+ workflows/ one workflow per file (defineWorkflow)
10
+ policies/policy.ts which calls need whose approval (definePolicy)
11
+ resources/ data files: the vendor objects this company declares, by area
12
+ scenarios/ Gherkin: how each workflow should go against the connectors' fakes
13
+ .env this machine's settings and secrets, never committed (SANOMA_SECRETS_KEY encrypts stored credentials)
14
+ ```
15
+
16
+ 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.
17
+
18
+ ## Run
19
+
20
+ With the package manager whose lockfile is here (`npm run <script>`, `pnpm <script>`, …):
21
+
22
+ ```sh
23
+ npm run dev # Postgres (in Docker when nothing answers), the worker and the app; the app at the printed address
24
+ npm run check # tsc, the lint, what the worker would refuse, and every scenario
25
+ npm run env # rewrites .env.example from the connectors' variables
26
+ ```
27
+
28
+ ## Rules
29
+
30
+ - 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, policies and data files to this.
31
+ - Define each workflow's `name` as a string literal: the app finds the workflow in its file by it.
32
+ - Every operation a workflow calls is listed in its `uses`; add the connector to `sanoma.config.ts` and to `package.json`.
33
+ - Describe each workflow's expected runs in `scenarios/<workflow>/<name>.feature`, and run the `check` script after every change.
34
+ - 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.2.0",
12
+ "sanoma": "^0.2.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,19 @@
1
+ import { allow, approve, approvedFor, definePolicy } from "sanoma";
2
+
3
+ const EDITOR = "editor";
4
+
5
+ /**
6
+ * Checked before every call a workflow makes: `allow()`, `deny(reason)` (the run fails) or
7
+ * `approve(who)` (the run waits until that person approves).
8
+ *
9
+ * Anything that publishes or sends needs the editor; everything else is allowed. A call passes
10
+ * when the editor approved an approval in this run that was addressed to them and covers it
11
+ * (`approvedFor`); otherwise it is held until they approve it.
12
+ *
13
+ * Deterministic: the decision depends on the call alone (no clock, randomness or network), so
14
+ * a replayed run decides the same way.
15
+ */
16
+ export default definePolicy(({ op, effect, run }) => {
17
+ if (effect !== "publish" && effect !== "send") return allow();
18
+ return approvedFor(run.approvals, op.id, EDITOR) ? allow() : approve(EDITOR);
19
+ });
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,12 @@
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 policy from "./policies/policy.ts";
6
+ import publishPost from "./workflows/publish-post.ts";
7
+
8
+ export default defineConfig({
9
+ workflows: [publishPost],
10
+ connectors: [ghost],
11
+ policy,
12
+ });
@@ -0,0 +1,18 @@
1
+ Feature: Publish a post
2
+ The post is drafted, the editor reviews it, and it is published.
3
+
4
+ Scenario: The editor approves
5
+ When publish-post runs with
6
+ | title | Hello from us |
7
+ | html | <p>Our first post.</p> |
8
+ And "Review the post" is approved by editor
9
+ Then a post titled "Hello from us" is created
10
+ And step "Publish the post" ran 1 time
11
+ And the run succeeds
12
+
13
+ Scenario: The editor rejects
14
+ When publish-post runs with
15
+ | title | Hello from us |
16
+ And "Review the post" is rejected by editor
17
+ Then ghost.post.publish was not called
18
+ And the run fails with "approval_rejected"
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "sanoma/tsconfig.json",
3
+ "include": ["sanoma.config.ts", "workflows", "policies", "resources", "scenarios"]
4
+ }
@@ -0,0 +1,22 @@
1
+ import { ghost } from "@sanoma-ai/connector-ghost";
2
+ import { defineWorkflow, z } from "sanoma";
3
+
4
+ /** Draft a blog post, have the editor review it, then publish it. */
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, "approval"],
15
+ run: async (ctx, { title, html }) => {
16
+ const post = await ctx.ghost.post.create({ title, html, status: "draft" }, { name: "Draft the post" });
17
+ // Covers the publish, so the policy lets it through on this one sign-off.
18
+ await ctx.approval("Review the post", { approver: "editor", covers: [ghost.post.publish], links: [post.url] });
19
+ const published = await ctx.ghost.post.publish({ id: post.id }, { name: "Publish the post" });
20
+ return { url: published.url };
21
+ },
22
+ });