History

Move product access rules out of the SDK

Rhys Sullivan committed 1 month ago

Commit c676e561 parent a72e51d161 files · +3935 −867Browse files

Showing the changes to scripts (3 of 161 files). Show all

Unified · Split

3 files
  1. scripts/publish-packages.ts +1 −0
  2. scripts/smoke-docs-install.ts +40 −5
  3. scripts/smoke-test-packed.ts +1 −0
scripts/publish-packages.ts+1−0
@@ -31,6 +31,7 @@ const PUBLIC_PACKAGE_DIRS = [ · 30 unmodified lines
3131 "packages/kernel/core",
3232 "packages/kernel/runtime-quickjs",
3333 "packages/core/sdk",
34+ "packages/core/product-access",
3435 "packages/core/config",
3536 "packages/core/execution",
3637 "packages/core/cli",
scripts/smoke-docs-install.ts+40−5
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 * name (`@executor-js/sdk`) instead of relying on workspace resolution.
88 */
99 import { $ } from "bun";
10+import { Schema } from "effect";
1011 import { existsSync, readdirSync } from "node:fs";
1112 import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
1213 import { tmpdir } from "node:os";
@@ -14,10 +15,15 @@ import { dirname, join, resolve } from "node:path"; · 1 unmodified line
1415 import { fileURLToPath } from "node:url";
1516
1617 const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
17−const documentedPackages = ["@executor-js/sdk", "@executor-js/plugin-openapi"] as const;
18+const documentedPackages = [
19+ "@executor-js/sdk",
20+ "@executor-js/product-access",
21+ "@executor-js/plugin-openapi",
22+] as const;
1823 const publicPackageDirs = [
1924 "packages/core/fumadb",
2025 "packages/core/sdk",
26+ "packages/core/product-access",
2127 "packages/core/config",
2228 "packages/plugins/openapi",
2329 ] as const;
@@ -27,6 +33,21 @@ const readPackageName = async (pkgDir: string): Promise<string> => { · 3 unmodified lines
2733 return (JSON.parse(raw) as { name: string }).name;
2834 };
2935
36+// `effect` is the SDK's (and product-access's) required peer, and the docs
37+// install command tells consumers to add it themselves. `npm install
38+// --legacy-peer-deps` below skips auto-installing peers, so the fixture must
39+// declare it like a real consumer would — pinned from the workspace catalog
40+// so it matches what the packed manifests resolved `catalog:` to.
41+const decodeCatalog = Schema.decodeUnknownSync(
42+ Schema.Struct({ catalog: Schema.Struct({ effect: Schema.NonEmptyString }) }),
43+);
44+
45+const readCatalogEffectVersion = async (): Promise<string> => {
46+ const raw = await readFile(join(repoRoot, "package.json"), "utf8");
47+ const manifest = decodeCatalog(JSON.parse(raw));
48+ return manifest.catalog.effect;
49+};
50+
3051 const findTarball = (pkgDir: string, packageName: string): string => {
3152 const tarball = readdirSync(pkgDir).find((entry) => entry.endsWith(".tgz"));
3253 if (!tarball) {
@@ -48,7 +69,7 @@ for (const relDir of publicPackageDirs) { · 15 unmodified lines
4869 const tmp = await mkdtemp(join(tmpdir(), "executor-docs-install-"));
4970
5071 try {
51− const dependencies: Record<string, string> = {};
72+ const dependencies: Record<string, string> = { effect: await readCatalogEffectVersion() };
5273 const overrides: Record<string, string> = {};
5374 for (const [name, tarball] of tarballs) {
5475 overrides[name] = `file:${tarball}`;
@@ -89,9 +110,23 @@ try { · 34 unmodified lines
89110 }
90111
91112 console.log(`[docs-smoke] import documented SDK packages`);
92− await $`node --input-type=module --eval ${`const sdk = await import("@executor-js/sdk"); const openapi = await import("@executor-js/plugin-openapi"); if (typeof sdk.createExecutor !== "function") throw new Error("missing createExecutor"); if (typeof openapi.openApiPlugin !== "function") throw new Error("missing openApiPlugin");`}`.cwd(
93− tmp,
94− );
113+ // The documented minimal embed: the SDK root export is the Promise façade
114+ // and ships no access posture of its own, so the probe constructs a
115+ // subject-less workspace-service executor with the posture from
116+ // `@executor-js/product-access` (ephemeral in-memory backend, nothing
117+ // invoked over the network) and closes it.
118+ const importProbe = [
119+ `const sdk = await import("@executor-js/sdk");`,
120+ `const access = await import("@executor-js/product-access");`,
121+ `const openapi = await import("@executor-js/plugin-openapi");`,
122+ `if (typeof sdk.createExecutor !== "function") throw new Error("missing createExecutor");`,
123+ `if (typeof access.workspaceServiceAccess !== "function") throw new Error("missing workspaceServiceAccess");`,
124+ `if (typeof openapi.openApiPlugin !== "function") throw new Error("missing openApiPlugin");`,
125+ `const executor = await sdk.createExecutor({ access: access.workspaceServiceAccess(), onElicitation: "accept-all" });`,
126+ `if (typeof executor.close !== "function") throw new Error("missing executor.close");`,
127+ `await executor.close();`,
128+ ].join("\n");
129+ await $`node --input-type=module --eval ${importProbe}`.cwd(tmp);
95130 } finally {
96131 await rm(tmp, { recursive: true, force: true });
97132 }
scripts/smoke-test-packed.ts+1−0
@@ -37,6 +37,7 @@ const PUBLIC_PACKAGE_DIRS = [ · 36 unmodified lines
3737 "packages/kernel/core",
3838 "packages/kernel/runtime-quickjs",
3939 "packages/core/sdk",
40+ "packages/core/product-access",
4041 "packages/core/config",
4142 "packages/core/execution",
4243 "packages/core/cli",