sanoma 0.2.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 (53) hide show
  1. package/README.md +81 -25
  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 +63 -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 +2 -3
  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 +19 -2
  22. package/dist/init.js +57 -2
  23. package/dist/init.js.map +1 -1
  24. package/dist/oxlint-plugin.d.ts +7 -1
  25. package/dist/oxlint-plugin.js +10 -4
  26. package/dist/oxlint-plugin.js.map +1 -1
  27. package/dist/resources.d.ts +1 -1
  28. package/dist/resources.js +3 -2
  29. package/dist/resources.js.map +1 -1
  30. package/dist/serve.d.ts +18 -12
  31. package/dist/serve.js +118 -26
  32. package/dist/serve.js.map +1 -1
  33. package/dist/site-lint.d.ts +33 -0
  34. package/dist/site-lint.js +70 -0
  35. package/dist/site-lint.js.map +1 -0
  36. package/dist/sites.d.ts +7 -0
  37. package/dist/sites.js +11 -0
  38. package/dist/sites.js.map +1 -0
  39. package/oxlint.json +113 -18
  40. package/package.json +19 -9
  41. package/site.d.ts +3 -0
  42. package/site.js +3 -0
  43. package/template/.env.example +2 -3
  44. package/template/AGENTS.md +14 -7
  45. package/template/package.json +2 -2
  46. package/template/policies/policy.cedar +17 -0
  47. package/template/resources/data.ts +21 -0
  48. package/template/resources/people.ts +20 -0
  49. package/template/sanoma.config.ts +0 -2
  50. package/template/scenarios/publish-post/publish.feature +16 -6
  51. package/template/tsconfig.json +1 -1
  52. package/template/workflows/publish-post.ts +2 -4
  53. package/template/policies/policy.ts +0 -19
package/dist/serve.js CHANGED
@@ -1,25 +1,117 @@
1
- import { dirname } from "node:path";
1
+ import { spawn } from "node:child_process";
2
+ import { realpathSync } from "node:fs";
3
+ import { dirname, extname, isAbsolute, relative, sep } from "node:path";
4
+ import { fileURLToPath } from "node:url";
2
5
  import { githubLogin, startApp } from "@sanoma-ai/app";
3
- import { errorMessage, isLoopback, SanomaClient, startWorker } from "@sanoma-ai/workflows";
6
+ import { errorMessage, isLoopback, resolveConfig, SanomaClient, startWorker, } from "@sanoma-ai/workflows";
7
+ import { describeConfig, readPeople, schemaOf, writeGenerated } from "@sanoma-ai/workflows/describe";
4
8
  import { UsageError } from "./config.js";
9
+ import { runtimeFrom, siteBuild } from "./sites.js";
5
10
  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));
11
+ /** The checkout the config was loaded from (`loadConfig` sets its `file`). */
12
+ const rootOf = (config) => config.root ?? dirname(config.file);
13
+ /** The checkout, as the worker's and the app's `source`. */
14
+ const sourceOf = (config) => localGitSource(rootOf(config));
8
15
  /** Starts the worker, promoted: a local worker is always the version to take queued runs, even one seen before. */
9
16
  export async function runWorker(config) {
10
17
  const worker = await startWorker(config, { promote: true, source: sourceOf(config) });
11
18
  return { stop: () => worker.stop() };
12
19
  }
13
- /** Starts the app on `port` (0 for any free port), with the host and login `appOptions` reads; `url` says where. */
14
- export async function runApp(config, { port }) {
15
- return served(config, { port, ...(await appOptions(secretsOf(config))) });
20
+ /** Starts the app on `port`, with the host and login `appOptions` reads, and the sites built; `url` says where. */
21
+ export async function runApp(config, options) {
22
+ return served(config, await appStart(config, options));
23
+ }
24
+ /**
25
+ * What the app starts with: the port, the host and login `appOptions` reads, and what it serves
26
+ * (`appSites`); the generated files written first (`writeGenerated`: `.sanoma/api.ts` and the
27
+ * Cedar schema), for an editor, the sites and the policies' author.
28
+ */
29
+ async function appStart(config, { port, log, dev = false, resolved = resolveConfig(config) }) {
30
+ const options = { port, ...(await appOptions(secretsOf(config))) };
31
+ // For an editor and the sites' types only: a checkout it cannot write still serves.
32
+ await writeGenerated(rootOf(config), describeConfig(config), schemaOf(resolved, readPeople(rootOf(config)).people)).catch((err) => log(`could not write .sanoma/: ${errorMessage(err)}`));
33
+ const sites = await appSites(rootOf(config), log, dev ? options.host : false);
34
+ return { ...options, ...sites, ...(sites.dev && { dev: { ...sites.dev, onFileChange: apiWriter(config, log) } }) };
16
35
  }
17
36
  async function served(config, options) {
18
37
  const app = await startApp(config, { ...options, source: sourceOf(config) });
19
38
  return { url: app.url, stop: () => app.close() };
20
39
  }
21
- const GITHUB = ["SANOMA_GITHUB_CLIENT_ID", "SANOMA_GITHUB_CLIENT_SECRET", "SANOMA_GITHUB_REPO"];
22
- const CLIENT = GITHUB.slice(0, 2);
40
+ /**
41
+ * What the app serves: with sites, its own build of the app and every site, built into
42
+ * `.sanoma/app/build/<key>` or reused when the key matches, or with `dev` (the app's host, when
43
+ * it is this machine's) the app and the sites on Vite's dev server; with none, the build the app
44
+ * ships. A folder that is not a site for its name is logged and left out.
45
+ */
46
+ async function appSites(root, log, dev) {
47
+ const build = await siteBuild(root);
48
+ if (!build)
49
+ return {};
50
+ const { sites, refused } = build.sitesOf(root);
51
+ const named = `${sites.length} site${sites.length === 1 ? "" : "s"} (${sites.join(", ")})`;
52
+ // The dev server listens on this machine only.
53
+ const hot = dev !== false && (dev === undefined || isLoopback(dev));
54
+ if (sites.length && !hot) {
55
+ if (dev)
56
+ log(`SANOMA_APP_HOST=${dev} is not this machine: the sites are built, not served hot`);
57
+ log(`building the app with ${named}`);
58
+ const { distDir, built } = await build.buildApp(root, { log, runtimeFrom: runtimeFrom() });
59
+ if (!built)
60
+ log("app build up to date");
61
+ return { distDir };
62
+ }
63
+ // buildApp says the same of each when there is a build to run.
64
+ for (const name of refused) {
65
+ log(`sites/${name} is not mounted: a site's folder name is a URL segment (lowercase letters, digits and dashes)`);
66
+ }
67
+ if (!sites.length)
68
+ return {};
69
+ log(`serving the app with ${named} from Vite's dev server: edits show as they are saved`);
70
+ return { dev: { repo: root } };
71
+ }
72
+ /** Where a change cannot reach the config from: the sites, what sanoma writes, the install, git. */
73
+ const NOT_CONFIG = new Set(["sites", ".sanoma", "node_modules", ".git"]);
74
+ /**
75
+ * Writes the generated files again on a change to a file the config may be read from: the config's
76
+ * own, or TypeScript under the root outside `NOT_CONFIG` (a workflow may import a relative file
77
+ * anywhere). In a child `sanoma api`, in the config's directory, where it loads the config: this
78
+ * process holds the config as it was loaded, and Node imports a module once. One child at a time;
79
+ * changes while one runs are one more run after it.
80
+ */
81
+ function apiWriter(config, log) {
82
+ const cli = fileURLToPath(new URL(`./cli${extname(fileURLToPath(import.meta.url))}`, import.meta.url));
83
+ // By real path, as the dev server's watcher names files.
84
+ const root = realpathSync(rootOf(config));
85
+ const cwd = config.file ? dirname(config.file) : root;
86
+ const readsConfig = (file) => {
87
+ if (file === config.file)
88
+ return true;
89
+ const path = relative(root, file);
90
+ return /\.tsx?$/.test(path) && !path.startsWith("..") && !isAbsolute(path) && !NOT_CONFIG.has(path.split(sep)[0]);
91
+ };
92
+ let running = false;
93
+ let again = false;
94
+ const run = () => {
95
+ running = true;
96
+ again = false;
97
+ spawn(process.execPath, [cli, "api"], { cwd, stdio: "inherit" })
98
+ .once("error", (err) => log(`could not write .sanoma/: ${err.message}`))
99
+ .once("close", () => {
100
+ running = false;
101
+ if (again)
102
+ run();
103
+ });
104
+ };
105
+ return (file) => {
106
+ if (!readsConfig(file))
107
+ return;
108
+ if (running)
109
+ again = true;
110
+ else
111
+ run();
112
+ };
113
+ }
114
+ const GITHUB = ["SANOMA_GITHUB_CLIENT_ID", "SANOMA_GITHUB_CLIENT_SECRET"];
23
115
  /** The config's stored secrets, through a client opened for the read. */
24
116
  const secretsOf = (config) => async (names) => {
25
117
  const client = await SanomaClient.connect(config);
@@ -32,45 +124,45 @@ const secretsOf = (config) => async (names) => {
32
124
  };
33
125
  /**
34
126
  * 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.
127
+ * are set, GitHub sign-in; both or neither, and any host but this machine needs it. An empty
128
+ * value is the same as unset. On a host beyond this machine, or with one of them set, one the
129
+ * environment leaves unset is read from the stored secrets (`readSecrets`), where creating the
130
+ * GitHub App on the app's connect page put them. A mistake in them is a UsageError.
39
131
  */
40
132
  export async function appOptions(readSecrets) {
41
133
  const env = process.env;
42
134
  const host = env.SANOMA_APP_HOST || undefined;
135
+ const beyond = host !== undefined && !isLoopback(host);
43
136
  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) => {
137
+ if ((beyond || found.size) && readSecrets && found.size < GITHUB.length) {
138
+ const stored = await readSecrets([...GITHUB]).catch((err) => {
46
139
  throw new UsageError(`GitHub sign-in could not read the stored client id and secret: ${errorMessage(err)}`);
47
140
  });
48
141
  for (const [name, value] of stored)
49
- if (value)
142
+ if (value && !found.has(name))
50
143
  found.set(name, value);
51
144
  }
52
- const [clientId, clientSecret, repo] = GITHUB.map((name) => found.get(name));
53
- if (!clientId && !clientSecret && !repo) {
54
- if (host && !isLoopback(host)) {
145
+ const [clientId, clientSecret] = GITHUB.map((name) => found.get(name));
146
+ if (!clientId && !clientSecret) {
147
+ if (beyond)
55
148
  throw new UsageError(`SANOMA_APP_HOST=${host} needs GitHub sign-in: set ${GITHUB.join(", ")}`);
56
- }
57
149
  return { host };
58
150
  }
59
- if (!clientId || !clientSecret || !repo) {
151
+ if (!clientId || !clientSecret) {
60
152
  const missing = GITHUB.filter((name) => !found.has(name));
61
153
  throw new UsageError(`GitHub sign-in needs ${GITHUB.join(", ")}: ${missing.join(", ")} not set`);
62
154
  }
63
155
  try {
64
- return { host, login: githubLogin({ clientId, clientSecret, repo }) };
156
+ return { host, login: githubLogin({ clientId, clientSecret }) };
65
157
  }
66
158
  catch (err) {
67
159
  throw new UsageError(errorMessage(err));
68
160
  }
69
161
  }
70
- /** The worker first, then the app, in this process; `stop` stops the app, then the worker. */
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))) };
162
+ /** The sites' build, the worker, then the app, in this process; `stop` stops the app, then the worker. */
163
+ export async function serve(config, serveOptions) {
164
+ // Read and built before the worker starts, so a mistake in the variables or a site starts nothing.
165
+ const options = await appStart(config, serveOptions);
74
166
  const worker = await runWorker(config);
75
167
  let app;
76
168
  try {
package/dist/serve.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAmB,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAqB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAW7C,sHAAsH;AACtH,MAAM,QAAQ,GAAG,CAAC,MAAoB,EAAE,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,IAAK,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AAC;oBAAS,CAAC;gBACT,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YACtB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,33 @@
1
+ /** An ESTree node, by the little this rule reads of it. */
2
+ interface AstNode {
3
+ type: string;
4
+ range: [number, number];
5
+ [field: string]: any;
6
+ }
7
+ interface RuleContext {
8
+ filename: string;
9
+ cwd: string;
10
+ report(diagnostic: {
11
+ message: string;
12
+ node: Pick<AstNode, "range">;
13
+ }): void;
14
+ }
15
+ /** What a site does instead of server code: the remedy every refusal under `sites/` names. */
16
+ export declare const REMEDY = "call an operation or start a workflow through `api` from `sanoma/site`.";
17
+ export declare const siteFile: {
18
+ meta: {
19
+ type: string;
20
+ docs: {
21
+ description: string;
22
+ };
23
+ };
24
+ create(context: RuleContext): {
25
+ Program(program: AstNode): void;
26
+ ImportDeclaration: (node: AstNode) => void;
27
+ ExportNamedDeclaration: (node: AstNode) => void;
28
+ ExportAllDeclaration: (node: AstNode) => void;
29
+ ImportExpression: (node: AstNode) => void;
30
+ CallExpression(call: AstNode): void;
31
+ };
32
+ };
33
+ export {};
@@ -0,0 +1,70 @@
1
+ import { basename, dirname, join, relative, resolve, sep } from "node:path";
2
+ /** What a site does instead of server code: the remedy every refusal under `sites/` names. */
3
+ export const REMEDY = "call an operation or start a workflow through `api` from `sanoma/site`.";
4
+ /** The server-side builders TanStack Start exports; a site has no server code. */
5
+ const SERVER_CALLS = new Set(["createServerFn", "createServerOnlyFn", "createMiddleware"]);
6
+ /** `f` for a call `f(…)`: a namespace import of TanStack Start is refused by the imports rule. */
7
+ const calleeName = (callee) => (callee.type === "Identifier" ? callee.name : undefined);
8
+ /** Whether `path` is `dir` or inside it. */
9
+ const inside = (dir, path) => {
10
+ const to = relative(dir, path);
11
+ return to !== ".." && !to.startsWith(`..${sep}`);
12
+ };
13
+ export const siteFile = {
14
+ meta: {
15
+ type: "problem",
16
+ docs: {
17
+ description: "A file under sites/ is client code: no *.server.* file, server function, middleware, route `server` handlers or relative import out of sites/",
18
+ },
19
+ },
20
+ create(context) {
21
+ // oxlint runs in the repo's root, where the override's `sites/**` matches.
22
+ const sites = join(context.cwd, "sites");
23
+ /** A relative import, not of types alone, that resolves outside `sites/`. */
24
+ const leaves = (node) => {
25
+ const source = node.source?.value;
26
+ if (typeof source !== "string" || !source.startsWith(".") || !inside(sites, context.filename))
27
+ return false;
28
+ if (node.importKind === "type" || node.exportKind === "type")
29
+ return false;
30
+ return !inside(sites, resolve(dirname(context.filename), source));
31
+ };
32
+ const imported = (node) => {
33
+ if (leaves(node)) {
34
+ context.report({
35
+ message: `A site imports only from inside sites/, \`sanoma/site\`, \`@sanoma-ai/app/ui\` and its packages: ${String(node.source.value)} leaves sites/.`,
36
+ node: node.source,
37
+ });
38
+ }
39
+ };
40
+ return {
41
+ Program(program) {
42
+ if (basename(context.filename).includes(".server.")) {
43
+ context.report({
44
+ message: `A site has no server code, so no *.server.* file: ${REMEDY}`,
45
+ node: program,
46
+ });
47
+ }
48
+ },
49
+ ImportDeclaration: imported,
50
+ ExportNamedDeclaration: imported,
51
+ ExportAllDeclaration: imported,
52
+ ImportExpression: imported,
53
+ CallExpression(call) {
54
+ const name = calleeName(call.callee);
55
+ if (name !== undefined && SERVER_CALLS.has(name)) {
56
+ context.report({ message: `A site has no server code, so no ${name}: ${REMEDY}`, node: call.callee });
57
+ return;
58
+ }
59
+ // createFileRoute("/path")({ server: { handlers } })
60
+ if (call.callee.type !== "CallExpression" || calleeName(call.callee.callee) !== "createFileRoute")
61
+ return;
62
+ const server = call.arguments[0]?.properties?.find((p) => p.type === "Property" && !p.computed && (p.key.name ?? p.key.value) === "server");
63
+ if (server) {
64
+ context.report({ message: `A site's route has no \`server\` handlers: ${REMEDY}`, node: server });
65
+ }
66
+ },
67
+ };
68
+ },
69
+ };
70
+ //# sourceMappingURL=site-lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-lint.js","sourceRoot":"","sources":["../src/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,IAAI,KAAK,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;oBACtG,OAAO;gBACT,CAAC;gBACD,qDAAqD;gBACrD,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,iBAAiB;oBAAE,OAAO;gBAC1G,MAAM,MAAM,GAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,UAAoC,EAAE,IAAI,CAC3E,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,QAAQ,CACxF,CAAC;gBACF,IAAI,MAAM,EAAE,CAAC;oBACX,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,8CAA8C,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;gBACpG,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -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"}
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.2.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",
@@ -26,7 +26,9 @@
26
26
  "tsconfig.base.json",
27
27
  "oxlint.json",
28
28
  "README.md",
29
- "LICENSE"
29
+ "LICENSE",
30
+ "site.js",
31
+ "site.d.ts"
30
32
  ],
31
33
  "type": "module",
32
34
  "sideEffects": false,
@@ -41,25 +43,33 @@
41
43
  "types": "./dist/resources.d.ts",
42
44
  "default": "./dist/resources.js"
43
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
+ },
44
54
  "./tsconfig.json": "./tsconfig.base.json"
45
55
  },
46
56
  "publishConfig": {
47
57
  "access": "public"
48
58
  },
49
59
  "dependencies": {
60
+ "@sanoma-ai/app": "0.4.0",
61
+ "@sanoma-ai/bridge": "0.4.0",
62
+ "@sanoma-ai/workflows": "0.4.0",
50
63
  "@types/node": "^26.6.4",
51
64
  "oxlint": "^1.87.0",
52
65
  "pg": "^8.23.1",
53
66
  "typescript": "^7.0.2",
54
- "zod": "^4.6.5",
55
- "@sanoma-ai/app": "0.2.0",
56
- "@sanoma-ai/bridge": "0.2.0",
57
- "@sanoma-ai/workflows": "0.2.0"
67
+ "zod": "^4.6.5"
58
68
  },
59
69
  "devDependencies": {
60
- "@types/pg": "^8.23.1",
61
- "@sanoma-ai/connector-ghost": "0.2.0",
62
- "@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"
63
73
  },
64
74
  "engines": {
65
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";
@@ -13,11 +13,10 @@
13
13
  # SANOMA_APP_PORT=
14
14
  # Optional. The address the app listens on; default 127.0.0.1. Any other needs GitHub sign-in.
15
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.
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
18
  # SANOMA_GITHUB_CLIENT_ID=
19
19
  # SANOMA_GITHUB_CLIENT_SECRET=
20
- # SANOMA_GITHUB_REPO=
21
20
 
22
21
  # ghost: the site's admin URL, such as https://example.ghost.io
23
22
  GHOST_ADMIN_URL=