sanoma 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 Sanoma-AI
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,106 @@
1
- # Temporary Holding Version
1
+ # sanoma
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install sanoma @sanoma-ai/connector-ghost
9
+ ```
10
+
11
+ `sanoma` brings `@sanoma-ai/workflows`, `@sanoma-ai/app`, `zod`, `typescript`, `@types/node` and `oxlint` with it: a repo installs nothing else but its connectors. Node's types reach the repo's `tsc` through `sanoma` itself (its declarations reference them, resolved from where it is installed), under pnpm, npm or a link alike, so a repo lists no `@types/node`. A repo that lists its own of another major gets two sets of Node's declarations, which conflict: keep one, by matching sanoma's or letting the installer dedupe them. A tsconfig project that imports nothing from `sanoma` (a scripts directory with a tsconfig of its own, say) gets none this way: it sets `"types": ["node"]` and lists `@types/node` itself. Node 24.2 or later, but not 25 (the bin uses `import.meta.main`, and Cucumber, which runs the scenarios, does not support 25); Docker for the Postgres it starts when none answers.
12
+
13
+ A repo holds `sanoma.config.ts` at its root, with `workflows/`, `policies/`, optional `resources/` (data files) and `scenarios/` (feature files) beside it, and a `tsconfig.json` that extends the one this package ships:
14
+
15
+ ```json
16
+ {
17
+ "extends": "sanoma/tsconfig.json",
18
+ "include": ["sanoma.config.ts", "workflows", "policies", "resources"]
19
+ }
20
+ ```
21
+
22
+ ```ts
23
+ // sanoma.config.ts
24
+ import { ghost } from "@sanoma-ai/connector-ghost";
25
+ import { defineConfig } from "sanoma";
26
+ import policy from "./policies/policy.ts";
27
+ import publish from "./workflows/publish.ts";
28
+
29
+ export default defineConfig({
30
+ workflows: [publish],
31
+ connectors: [ghost],
32
+ policy,
33
+ });
34
+ ```
35
+
36
+ Each connector carries its driver and its fake, so the config names neither. The rest is the repo's layout: the app's name is `package.json`'s `name`, the scenarios are `scenarios/` and the data files `resources/`, beside `sanoma.config.ts`. The ledger is Postgres's, on the config's database; `ledger: jsonlLedger(dir)` keeps it in files instead.
37
+
38
+ ```ts
39
+ // workflows/publish.ts
40
+ import { ghost } from "@sanoma-ai/connector-ghost";
41
+ import { defineWorkflow, z } from "sanoma";
42
+
43
+ export default defineWorkflow({
44
+ name: "publish",
45
+ trigger: "manual",
46
+ input: z.object({ id: z.string() }),
47
+ uses: [ghost.post.publish],
48
+ run: (ctx, { id }) => ctx.ghost.post.publish({ id }),
49
+ });
50
+ ```
51
+
52
+ A workflow or policy imports from `sanoma` what the lint lets it (`defineWorkflow`, `definePolicy`, `allow`, `deny`, `approve`, `approvedFor`, `allowAll`, `mayDecide`, `errorCode`, `z`, and types); `zod` itself and `@sanoma-ai/workflows` are accepted too. The config file imports `defineConfig` (and a ledger store, `jsonlLedger`, `memoryLedger` or `postgresLedger`, when it names one) from `sanoma`, and its connectors from their packages.
53
+
54
+ ## Commands
55
+
56
+ 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
+
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. |
66
+
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.
68
+
69
+ ## Postgres
70
+
71
+ The worker and the app run on `SANOMA_DATABASE_URL` (default `postgresql://postgres:dbos@localhost:5433/sanoma`), or the config's `databaseUrl`. `sanoma` (through `sanoma serve`) and `sanoma check` first probe it (`SELECT 1` as its user; `check` meanwhile runs tsc, oxlint and reads the config, and waits for Postgres only before the scenarios). When nothing answers and the host is this machine (`localhost`, `127.x.x.x`, `::1`), they start Postgres in Docker: the container `sanoma-<appName>-postgres` is started when it exists and is stopped, created from `postgres:17` on the URL's port, user, password and database when it does not, and left alone when it runs; then the probe is repeated until it answers (up to a minute). A container is never removed: `docker rm sanoma-<appName>-postgres` does that. A server that answers with an error (a wrong password), nothing answering at another host, and a missing Docker each stop the command with a message.
72
+
73
+ ## `.env.example`
74
+
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.
76
+
77
+ ## The lint
78
+
79
+ `sanoma check` lints `workflows/`, `policies/` and `resources/` with oxlint, run in the repo's root on the repo's own `.oxlintrc.json`, so an editor's oxlint reads the same file and the rules' `workflows/**` globs match against the root. `sanoma check` writes that file when there is none:
80
+
81
+ ```json
82
+ {
83
+ "extends": ["./node_modules/sanoma/oxlint.json"]
84
+ }
85
+ ```
86
+
87
+ `sanoma/oxlint.json` is self-contained (it extends nothing): `@sanoma-ai/workflows`'s rules (the clock, randomness, the network, the environment, the imports a workflow may make, the data-file subset, with its plugin inside `sanoma`) and the rules this repo holds its own code to. Add your own rules beside the `extends`; `sanoma check` leaves an existing file alone.
88
+
89
+ ## Generated files
90
+
91
+ | File | Written by | Commit it |
92
+ | ---------------- | ---------------------------- | --------- |
93
+ | `.env.example` | `sanoma env` | yes |
94
+ | `.oxlintrc.json` | `sanoma check`, when missing | yes |
95
+
96
+ ## Dev mode
97
+
98
+ When the repo's `node_modules/sanoma` or any `node_modules/@sanoma-ai/*` is a link into a sanoma checkout (`pnpm link`), or `SANOMA_DEV_REPO` names one, `sanoma` runs `sanoma serve` in a child process and, in every linked package's directory, its `pnpm run watch` (each package's own watch build: `tsc --watch`, and `vite build --watch` too for the app). A change under any linked package's `dist/` restarts the child, after three quarters of a second of quiet, one restart at a time; a child that exits on its own is reported and started again on the next change. The child and each watch run in a process group of their own, so a terminal's ctrl-c reaches `sanoma` alone, which then ends each group (SIGTERM, SIGKILL after 5 seconds) and exits.
99
+
100
+ Linking some of `sanoma`, `@sanoma-ai/workflows`, `@sanoma-ai/app` and `@sanoma-ai/bridge` and not the others works, with two copies of a package in one process (the linked one, and the one an installed package depends on), and `sanoma` says which still come from their tarballs before it starts the child: `dev mode: sanoma, @sanoma-ai/app, @sanoma-ai/bridge still come from their tarballs: edits to them in the checkout will not show until you pnpm link them too`. Link all four to run the checkout alone.
101
+
102
+ ## Hosting it yourself
103
+
104
+ `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
+
106
+ Status: early (0.x). License: FSL-1.1-ALv2.
@@ -0,0 +1,27 @@
1
+ import type { Loaded } from "./config.ts";
2
+ export interface CheckResult {
3
+ ok: boolean;
4
+ /** One printable line each: `<file>:<line>:<col>: <message>`, or `<scenario> › <step>: <message>`. */
5
+ problems: string[];
6
+ }
7
+ export interface CheckOptions {
8
+ /** The Postgres the scenarios' worker runs on: a database of its own, never the config's. */
9
+ databaseUrl: string;
10
+ /**
11
+ * Settles once Postgres answers at `databaseUrl`'s server (the bin's `ensurePostgres`, started
12
+ * before `check`): awaited only before the scenarios, so tsc, oxlint and the config's reading
13
+ * do not wait on it. A failure is the check's only when there are scenarios to run.
14
+ */
15
+ ready?: Promise<unknown>;
16
+ log: (line: string) => void;
17
+ }
18
+ /**
19
+ * Checks a repo the way its tests would, without a test framework: `tsc -p tsconfig.json` in
20
+ * its root; oxlint in the root, with the repo's `.oxlintrc.json` (written when missing, to extend
21
+ * this package's `oxlint.json`), over `workflows/`, `policies/` and `resources/`; every problem
22
+ * `describeConfig` finds in the data files and the workflows' files (the import rules and what
23
+ * the outline cannot draw: what the worker refuses to start with); these three at once, their
24
+ * problems in that order. Then every scenario against the fakes (`runScenarios`), each step that
25
+ * did not hold a problem. `ok` when there are no problems.
26
+ */
27
+ export declare function check({ config, root, resolved }: Loaded, { databaseUrl, ready, log }: CheckOptions): Promise<CheckResult>;
package/dist/check.js ADDED
@@ -0,0 +1,129 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { join, relative } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { promisify } from "node:util";
6
+ import { describeConfig } from "@sanoma-ai/workflows/describe";
7
+ import { problemLine } from "@sanoma-ai/workflows/shared";
8
+ import { runScenarios } from "@sanoma-ai/workflows/scenarios";
9
+ /** The directories oxlint reads, those that exist. */
10
+ const LINTED = ["workflows", "policies", "resources"];
11
+ /**
12
+ * Checks a repo the way its tests would, without a test framework: `tsc -p tsconfig.json` in
13
+ * its root; oxlint in the root, with the repo's `.oxlintrc.json` (written when missing, to extend
14
+ * this package's `oxlint.json`), over `workflows/`, `policies/` and `resources/`; every problem
15
+ * `describeConfig` finds in the data files and the workflows' files (the import rules and what
16
+ * the outline cannot draw: what the worker refuses to start with); these three at once, their
17
+ * problems in that order. Then every scenario against the fakes (`runScenarios`), each step that
18
+ * did not hold a problem. `ok` when there are no problems.
19
+ */
20
+ export async function check({ config, root, resolved }, { databaseUrl, ready = Promise.resolve(), log }) {
21
+ // Awaited below when there are scenarios; otherwise its failure is nobody's.
22
+ ready.catch(() => { });
23
+ const found = await Promise.all([typecheck(root, log), lint(root, log), configProblems(config, root, log)]);
24
+ const problems = found.flat();
25
+ if (resolved.scenarios === undefined) {
26
+ log("no scenarios: the config's root has no `scenarios/` directory");
27
+ }
28
+ else {
29
+ await ready;
30
+ log("scenarios");
31
+ const { failed } = await runScenarios(config, { databaseUrl, log });
32
+ for (const f of failed)
33
+ problems.push(`${f.scenario} › ${f.step}: ${f.message}`);
34
+ }
35
+ return { ok: problems.length === 0, problems };
36
+ }
37
+ /** `tsc -p tsconfig.json` in the root. */
38
+ async function typecheck(root, log) {
39
+ log("tsc");
40
+ const tsc = await run(binOf("typescript"), ["-p", "tsconfig.json", "--pretty", "false"], root);
41
+ return tsc.code === 0 ? [] : tscProblems(tsc);
42
+ }
43
+ /** oxlint in the root, on its `.oxlintrc.json` (written when missing), over the directories that exist. */
44
+ async function lint(root, log) {
45
+ const dirs = LINTED.filter((dir) => existsSync(join(root, dir)));
46
+ if (!dirs.length)
47
+ return [];
48
+ if (writeOxlintrc(root))
49
+ log("wrote .oxlintrc.json");
50
+ log(`oxlint ${dirs.join(" ")}`);
51
+ return oxlintProblems(await run(binOf("oxlint"), ["--deny-warnings", "-f", "json", ...dirs], root));
52
+ }
53
+ /**
54
+ * `describeConfig`'s problems: the data files', then each workflow's, its file relative to the
55
+ * root. A file defining several workflows gives each its problems: one line each here.
56
+ */
57
+ async function configProblems(config, root, log) {
58
+ log("config");
59
+ const { problems, workflows } = describeConfig(config);
60
+ const lines = new Set([
61
+ ...problems.map(problemLine),
62
+ ...workflows.flatMap((wf) => wf.problems.map((p) => problemLine({ file: relative(root, wf.file), ...p }))),
63
+ ]);
64
+ return [...lines];
65
+ }
66
+ /** Runs a JavaScript bin with this Node, in `cwd`; never throws for its exit code. */
67
+ async function run(bin, args, cwd) {
68
+ try {
69
+ const { stdout, stderr } = await promisify(execFile)(process.execPath, [bin, ...args], {
70
+ cwd,
71
+ maxBuffer: 64 * 1024 * 1024,
72
+ });
73
+ return { code: 0, stdout, stderr };
74
+ }
75
+ catch (err) {
76
+ const { code, stdout, stderr } = err;
77
+ if (typeof code !== "number")
78
+ throw err;
79
+ return { code, stdout: stdout ?? "", stderr: stderr ?? "" };
80
+ }
81
+ }
82
+ /** A package's bin (its only one), found from this package by its `package.json`: neither `typescript` nor `oxlint` exports it. */
83
+ function binOf(pkg) {
84
+ const manifest = new URL(import.meta.resolve(`${pkg}/package.json`));
85
+ const { bin } = JSON.parse(readFileSync(manifest, "utf8"));
86
+ return fileURLToPath(new URL(typeof bin === "string" ? bin : Object.values(bin)[0], manifest));
87
+ }
88
+ /**
89
+ * tsc's `--pretty false` lines, `file(line,col): error TS1234: message`, as `file:line:col: message`;
90
+ * anything else it printed as it is, and its exit code when it printed nothing.
91
+ */
92
+ function tscProblems({ code, stdout, stderr }) {
93
+ const lines = `${stdout}${stderr}`.split(/\r?\n/).filter((l) => l.trim());
94
+ if (lines.length === 0)
95
+ return [`tsc exited with ${code}`];
96
+ return lines.map((line) => line.replace(/^(.+?)\((\d+),(\d+)\): /, "$1:$2:$3: "));
97
+ }
98
+ /** The repo's `.oxlintrc.json`: this package's lint, for `sanoma check` and an editor alike. */
99
+ const OXLINTRC = `${JSON.stringify({ extends: ["./node_modules/sanoma/oxlint.json"] }, null, 2)}\n`;
100
+ /**
101
+ * Writes `<root>/.oxlintrc.json` when there is none, and says whether it did. oxlint, run in the
102
+ * root, reads it and matches the rules' `workflows/**` globs against the root.
103
+ */
104
+ function writeOxlintrc(root) {
105
+ const file = join(root, ".oxlintrc.json");
106
+ if (existsSync(file))
107
+ return false;
108
+ writeFileSync(file, OXLINTRC);
109
+ return true;
110
+ }
111
+ /** oxlint's JSON diagnostics as lines; what it printed instead when the output is not JSON (a config it refused). */
112
+ function oxlintProblems({ code, stdout, stderr }) {
113
+ let diagnostics;
114
+ try {
115
+ ({ diagnostics } = JSON.parse(stdout));
116
+ }
117
+ catch {
118
+ return code === 0 ? [] : [`oxlint exited with ${code}: ${stderr.trim() || stdout.trim()}`];
119
+ }
120
+ const lines = diagnostics.map(({ filename, message, help, labels }) => {
121
+ const span = labels[0]?.span;
122
+ const where = span ? `${filename}:${span.line}:${span.column}` : filename;
123
+ return `${where}: ${message}${help ? ` ${help}` : ""}`;
124
+ });
125
+ if (code !== 0 && lines.length === 0)
126
+ lines.push(`oxlint exited with ${code}: ${stderr.trim()}`);
127
+ return lines;
128
+ }
129
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,W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AAqH;AACrH,SAAS,cAAc,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAO;IACnD,IAAI,WAAyB,CAAC;IAC9B,IAAI,CAAC;QACH,CAAC,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAkC,CAAC,CAAC;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,sBAAsB,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7F,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QACpE,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC1E,OAAO,GAAG,KAAK,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACzD,CAAC,CAAC,CAAC;IACH,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,sBAAsB,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACjG,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ /** Runs the command line; returns the exit code, or never, for a command that serves until a signal. */
3
+ export declare function main(argv: string[]): Promise<number>;
package/dist/cli.js ADDED
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { writeFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { parseArgs } from "node:util";
7
+ import { loadConfig, UsageError } from "./config.js";
8
+ // Only Node's modules and ./config.ts are imported here: each command imports what it runs, so
9
+ // `--help`, `env`, `ledger export` and the dev-mode parent load neither the worker nor the app.
10
+ const USAGE = `usage: sanoma [command]
11
+
12
+ Runs the repo in the working directory, from its sanoma.config.ts (after its .env, when there is one).
13
+
14
+ sanoma the worker and the app; starts Postgres in Docker when nothing answers
15
+ sanoma worker the worker alone, for a deployment
16
+ sanoma app the app alone, for a deployment
17
+ sanoma check typecheck, lint, read the config, run every scenario; exit 1 on a problem
18
+ sanoma env [--check] write .env.example from the drivers' variables; --check exits 1 when it is out of date
19
+ sanoma ledger export <runId> [--out <file>]
20
+ a run's ledger records as JSON lines
21
+
22
+ 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,
24
+ or SANOMA_DEV_REPO set, \`sanoma\` also runs each linked package's watch build and restarts on a new build.
25
+ `;
26
+ /** Exit codes: 2 for how the bin was called or what it found, 1 for failed checks and failures while running. */
27
+ const USAGE_EXIT = 2;
28
+ const log = (line) => console.error(line);
29
+ const messageOf = (err) => (err instanceof Error ? err.message : String(err));
30
+ /** Runs the command line; returns the exit code, or never, for a command that serves until a signal. */
31
+ export async function main(argv) {
32
+ let args;
33
+ try {
34
+ args = parse(argv);
35
+ }
36
+ catch (err) {
37
+ throw new UsageError(`${messageOf(err)}\n\n${USAGE.trimEnd()}`);
38
+ }
39
+ const { positionals, values } = args;
40
+ if (values.help) {
41
+ console.log(USAGE.trimEnd());
42
+ return 0;
43
+ }
44
+ const [command, ...rest] = positionals;
45
+ switch (command) {
46
+ case undefined: {
47
+ const { devRepo, linkedPackages } = await import("./dev.js");
48
+ const linked = linkedPackages(process.cwd());
49
+ const repo = devRepo(process.cwd(), linked);
50
+ return repo === undefined ? serveCommand() : dev(repo, linked);
51
+ }
52
+ case "serve":
53
+ return serveCommand();
54
+ case "worker": {
55
+ const { runWorker } = await import("./serve.js");
56
+ return keep(await load(), runWorker);
57
+ }
58
+ case "app": {
59
+ const { runApp } = await import("./serve.js");
60
+ return keep(await load(), (config) => runApp(config, { port: port() }));
61
+ }
62
+ case "check":
63
+ return runCheck();
64
+ case "env":
65
+ return env(values.check ?? false);
66
+ case "ledger": {
67
+ const [sub, runId, ...extra] = rest;
68
+ if (sub !== "export" || !runId || extra.length)
69
+ throw new UsageError(`usage: sanoma ledger export <runId> [--out <file>]`);
70
+ return ledgerExport(runId, values.out);
71
+ }
72
+ default:
73
+ throw new UsageError(`unknown command "${command}"\n\n${USAGE.trimEnd()}`);
74
+ }
75
+ }
76
+ const parse = (argv) => parseArgs({
77
+ args: argv,
78
+ allowPositionals: true,
79
+ options: { help: { type: "boolean", short: "h" }, check: { type: "boolean" }, out: { type: "string" } },
80
+ });
81
+ const port = () => Number(process.env.SANOMA_APP_PORT ?? 3000);
82
+ async function load() {
83
+ const loaded = await loadConfig();
84
+ const { resolveConfig } = await import("@sanoma-ai/workflows");
85
+ return { ...loaded, resolved: resolveConfig(loaded.config) };
86
+ }
87
+ /**
88
+ * Starts what `start` starts over the loaded config, prints what runs (and where, when it
89
+ * listens), and stops it on SIGINT or SIGTERM, then exits 0. The worker names the vendors not
90
+ * configured yet itself, in one line.
91
+ */
92
+ async function keep({ config, resolved }, start) {
93
+ const started = await start(config);
94
+ const running = `${resolved.appName} running ${[...resolved.workflows.keys()].join(", ")}`;
95
+ if (started.url === undefined) {
96
+ console.log(`${running}; ctrl-c to stop`);
97
+ }
98
+ else {
99
+ console.log(running);
100
+ console.log(`${resolved.appName} at ${started.url}; ctrl-c to stop`);
101
+ }
102
+ onSignal(() => started.stop());
103
+ return new Promise(() => { });
104
+ }
105
+ /** `sanoma serve` (and `sanoma` outside dev mode): Postgres, then the worker and the app in this process. */
106
+ async function serveCommand() {
107
+ const loaded = await load();
108
+ const { appName, databaseUrl } = loaded.resolved;
109
+ const { ensurePostgres } = await import("./postgres.js");
110
+ await ensurePostgres(databaseUrl, { appName, log });
111
+ const { serve } = await import("./serve.js");
112
+ return keep(loaded, (config) => serve(config, { port: port() }));
113
+ }
114
+ /**
115
+ * Dev mode: `sanoma serve` in a child it restarts on a new build, and each linked package's
116
+ * `watch`. Each runs in a process group of its own, so a terminal's ctrl-c reaches this process
117
+ * alone, and its `stop` is the one path that ends them.
118
+ */
119
+ async function dev(repo, packages) {
120
+ const { partialLink, startWatchers, supervise } = await import("./dev.js");
121
+ const cwd = process.cwd();
122
+ log(`dev mode: ${repo}; building ${packages.map((p) => p.name).join(", ") || "nothing"} as it changes`);
123
+ const fromTarballs = partialLink(cwd);
124
+ if (fromTarballs.length) {
125
+ log(`dev mode: ${fromTarballs.join(", ")} still come from their tarballs: ` +
126
+ "edits to them in the checkout will not show until you pnpm link them too");
127
+ }
128
+ const watchers = startWatchers(packages, log);
129
+ const cli = fileURLToPath(import.meta.url);
130
+ const child = supervise({
131
+ spawn: () => spawn(process.execPath, [cli, "serve"], { cwd, env: process.env, stdio: "inherit", detached: true }),
132
+ watch: packages.map((p) => join(p.dir, "dist")),
133
+ log,
134
+ });
135
+ onSignal(async () => {
136
+ await child.stop();
137
+ await watchers.stop();
138
+ });
139
+ return new Promise(() => { });
140
+ }
141
+ /** `sanoma check`: Postgres made to answer while tsc, oxlint and the config are read; the scenarios on `<database>_check`. */
142
+ async function runCheck() {
143
+ const loaded = await load();
144
+ const { appName, databaseUrl } = loaded.resolved;
145
+ const [{ ensurePostgres }, { check }] = await Promise.all([import("./postgres.js"), import("./check.js")]);
146
+ const own = new URL(databaseUrl);
147
+ own.pathname = `${own.pathname}_check`;
148
+ // Started here, handed to check at once (which handles its failure), awaited before the scenarios.
149
+ const ready = ensurePostgres(databaseUrl, { appName, log });
150
+ const { ok, problems } = await check(loaded, { databaseUrl: own.toString(), ready, log });
151
+ for (const problem of problems)
152
+ console.log(problem);
153
+ log(ok ? "ok" : `${problems.length} problem${problems.length === 1 ? "" : "s"}`);
154
+ return ok ? 0 : 1;
155
+ }
156
+ async function env(checkOnly) {
157
+ const loaded = await load();
158
+ const { writeEnvExample } = await import("./env.js");
159
+ const { changed } = writeEnvExample(loaded, { check: checkOnly });
160
+ if (!checkOnly) {
161
+ log(changed ? "wrote .env.example" : ".env.example is up to date");
162
+ return 0;
163
+ }
164
+ if (changed)
165
+ log("`.env.example` is out of date: run `sanoma env`");
166
+ return changed ? 1 : 0;
167
+ }
168
+ async function ledgerExport(runId, out) {
169
+ const { config } = await loadConfig();
170
+ const { exportLedger } = await import("./ledger.js");
171
+ const text = await exportLedger(config, runId);
172
+ if (out === undefined)
173
+ process.stdout.write(text);
174
+ else {
175
+ writeFileSync(out, text);
176
+ log(`wrote ${out}`);
177
+ }
178
+ return 0;
179
+ }
180
+ /** On the first SIGINT or SIGTERM, stops what runs and exits 0; a second signal exits at once. */
181
+ function onSignal(stop) {
182
+ let stopping = false;
183
+ const handle = () => {
184
+ if (stopping)
185
+ process.exit(130);
186
+ stopping = true;
187
+ stop().then(() => process.exit(0), (err) => {
188
+ log(messageOf(err));
189
+ process.exit(1);
190
+ });
191
+ };
192
+ process.once("SIGINT", handle);
193
+ process.once("SIGTERM", handle);
194
+ }
195
+ if (import.meta.main) {
196
+ try {
197
+ process.exitCode = await main(process.argv.slice(2));
198
+ }
199
+ catch (err) {
200
+ log(messageOf(err));
201
+ process.exitCode = err instanceof UsageError ? USAGE_EXIT : 1;
202
+ }
203
+ }
204
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C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,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC/B,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,IAAI,CAAC;QACH,OAAO,CAAC,QAAQ,GAAG,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"}
@@ -0,0 +1,21 @@
1
+ import type { ResolvedConfig, SanomaConfig } from "@sanoma-ai/workflows";
2
+ /** A mistake in how the bin was called or in what it found: its message is printed alone, and the exit code is 2. */
3
+ export declare class UsageError extends Error {
4
+ }
5
+ export interface LoadedConfig {
6
+ config: SanomaConfig;
7
+ /** The config's directory: its `root`, else the file's. Data files are `resources/` in it. */
8
+ root: string;
9
+ }
10
+ /** The config, loaded once, and resolved once (`resolveConfig`): what the commands that read it take. */
11
+ export interface Loaded extends LoadedConfig {
12
+ resolved: ResolvedConfig;
13
+ }
14
+ /**
15
+ * Loads `<cwd>/sanoma.config.ts`, after `<cwd>/.env` when there is one (`process.loadEnvFile`:
16
+ * a variable already set wins). The module's default export is the config; it is not run
17
+ * through `defineConfig` again, since the config module's own call recorded its `file`, and a
18
+ * config made without it gets this file as its `file`. Throws a `UsageError` when the file is
19
+ * missing or its default export is no config.
20
+ */
21
+ export declare function loadConfig(cwd?: string): Promise<LoadedConfig>;