jive-abstract-organization 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.
Files changed (39) hide show
  1. package/README.md +47 -2
  2. package/dist/deploy/cli.js +63 -0
  3. package/dist/deploy/cli.js.map +1 -0
  4. package/dist/deploy/command.js +22 -0
  5. package/dist/deploy/command.js.map +1 -0
  6. package/dist/deploy/convex-deployer.js +29 -0
  7. package/dist/deploy/convex-deployer.js.map +1 -0
  8. package/dist/deploy/deployment-provisioner.js +35 -0
  9. package/dist/deploy/deployment-provisioner.js.map +1 -0
  10. package/dist/deploy/hooks.js +17 -0
  11. package/dist/deploy/hooks.js.map +1 -0
  12. package/dist/deploy/manifest.js +12 -0
  13. package/dist/deploy/manifest.js.map +1 -0
  14. package/dist/deploy/organization-directory.js +23 -0
  15. package/dist/deploy/organization-directory.js.map +1 -0
  16. package/dist/expose-workforce.js +9 -0
  17. package/dist/expose-workforce.js.map +1 -0
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -0
  20. package/package.json +47 -4
  21. package/src/deploy/cli.ts +73 -0
  22. package/src/deploy/command.ts +47 -0
  23. package/src/deploy/convex-deployer.ts +51 -0
  24. package/src/deploy/deployment-provisioner.ts +59 -0
  25. package/src/deploy/hooks.ts +19 -0
  26. package/src/deploy/manifest.ts +14 -0
  27. package/src/deploy/organization-directory.ts +28 -0
  28. package/src/expose-workforce.ts +14 -0
  29. package/src/index.ts +1 -0
  30. package/template/.gitignore.ejs +7 -0
  31. package/template/README.md.ejs +16 -0
  32. package/template/convex.json.ejs +3 -0
  33. package/template/package.json.ejs +51 -0
  34. package/template/src/convex/convex.config.ts.ejs +9 -0
  35. package/template/src/convex/tsconfig.json.ejs +25 -0
  36. package/template/src/convex/workforce.ts.ejs +30 -0
  37. package/template/test/deploy.test.ts.ejs +38 -0
  38. package/template/test/harness.ts.ejs +19 -0
  39. package/template/tsconfig.json.ejs +16 -0
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # jive-abstract-organization
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
+ The Jive abstract an organization extends. An organization is a Convex server: the Convex app its workforce runs on,
4
+ hosted by Jive in Jive's own Convex team (managed) or by the organization (self-hosted), as the organization chose when
5
+ it was created on `@jive-sh/server` (`organizations:create`). Its workforce, the workflows it runs, lives in the app,
6
+ and the organization gives those workflows the implementations of the interfaces they use.
7
+
8
+ This package is a library: its pipeline publishes it to npm.
9
+
10
+ ## What it provides
11
+
12
+ - The CLI `jive-organization cicd <hook>`, which runs an organization package's six CI/CD hooks (below).
13
+ - `exposeQuery`, `exposeMutation` and `exposeAction`: an organization that installs a workforce as a component (as
14
+ open-empires-organization does) exposes each of its functions publicly through them, since only the app that
15
+ installs a component can call it.
16
+
17
+ ## Making an organization
18
+
19
+ `jive create organization --name <package name> --organization <Jive organization>` makes `packages/<package name>`
20
+ from the template, a working sample organization at `src/template/` (`example-organization`). Its replacements are
21
+ `"example-organization": "name"`, the package's name, and `"example-jive-organization": "organization"`, the Jive
22
+ organization it deploys. The sample's workforce runs no workflow yet. Its test runs against a local Convex deployment
23
+ in the package made from it, never in this repository.
24
+
25
+ `bun run jive:cicd:build` builds the template into `dist/base/template`, which `jive create` reads.
26
+
27
+ ## Deploying an organization
28
+
29
+ An organization package names its Jive organization in `jive.organization.name`. The organization's Convex server is
30
+ recorded on `@jive-sh/server`, chosen when the organization was created there: managed, a production deployment Jive
31
+ created in the organization's own Convex team, or self-hosted, a Convex backend the person runs. The manifest never
32
+ says which, and the package needs no secret for it.
33
+
34
+ - `jive-organization cicd deploy-plan` prints `{"deploy":true,"url":"<server address>"}` and nothing else on stdout,
35
+ reading the address from Jive's server (`organizations:convexServerUrl`, through `@jive-sh/server-client`). It runs
36
+ in the build job, which cannot sign in, so it asks with no session.
37
+ - `jive-organization cicd deploy` signs the deploy job in (`jive login --cicd`) and asks Jive for the server
38
+ (`jive provision convex-deployment <organization>`), which prints `{"hosting":"managed","url",…,"deployKey"}` or
39
+ `{"hosting":"selfHosted","url",…,"adminKey"}`. It then pushes the Convex app with the package's own `convex` CLI
40
+ and registers the workforce's workflows there (`workforce:register`). Each CLI gets only the variables naming its
41
+ target (the jive CLI also gets GitHub Actions' ID token request variables), so a job's stray `CONVEX_*` variable
42
+ never redirects it.
43
+ - `get-config` prints the package's `jive` block, `audit` type-checks it, and `build` and `upload-artifacts` have
44
+ nothing to do, since the deploy pushes source.
45
+
46
+ `bun test test` checks the deploy hooks against a fake Jive server only. A real push to a self-hosted server is tested
47
+ by the sample's own tests, in a package made from it. The jive CLI calls themselves run first in a consumer's deploy
48
+ job.
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env bun
2
+ import { BunRuntime, BunServices } from "@effect/platform-bun";
3
+ import { Effect, FileSystem, Layer, Path, pipe, Schema } from "effect";
4
+ import { ChildProcessSpawner } from "effect/process";
5
+ import { runCommand } from "./command";
6
+ import { ConvexCliDeployer, ConvexDeployer } from "./convex-deployer";
7
+ import { DeploymentProvisioner, JiveCliDeploymentProvisioner } from "./deployment-provisioner";
8
+ import { deploy, deployPlan } from "./hooks";
9
+ import { decodeOrganizationManifest } from "./manifest";
10
+ import { JiveServerOrganizationDirectory, OrganizationDirectory } from "./organization-directory";
11
+ /**
12
+ * `jive-organization cicd <hook>`: the six CI/CD hooks of an organization package, run from its root. `get-config` and
13
+ * `deploy-plan` print only their JSON answer on stdout, as the CI/CD contract requires; everything else goes to stderr.
14
+ * An organization's Convex app is pushed as source by `deploy`, so `build` and `upload-artifacts` have nothing to do.
15
+ */
16
+ const [, , group, hook] = process.argv;
17
+ const JiveBlock = Schema.fromJsonString(Schema.Struct({ jive: Schema.Unknown }));
18
+ const program = Effect.gen(function* () {
19
+ const fileSystem = yield* FileSystem.FileSystem;
20
+ const path = yield* Path.Path;
21
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
22
+ const root = process.cwd();
23
+ const manifestText = yield* fileSystem.readFileString(path.join(root, "package.json"));
24
+ const base = { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "" };
25
+ // The jive CLI also gets the variables GitHub Actions sets for requesting the job's ID token, which `jive login --cicd` exchanges.
26
+ const idTokenRequest = Object.fromEntries(["ACTIONS_ID_TOKEN_REQUEST_URL", "ACTIONS_ID_TOKEN_REQUEST_TOKEN"].flatMap((name) => {
27
+ const value = process.env[name];
28
+ return value === undefined ? [] : [[name, value]];
29
+ }));
30
+ const organization = Effect.map(decodeOrganizationManifest(manifestText), (manifest) => manifest.jive.organization.name);
31
+ const services = Layer.mergeAll(Layer.succeed(DeploymentProvisioner, new JiveCliDeploymentProvisioner({ spawner, cwd: root, env: { ...base, ...idTokenRequest } })), Layer.succeed(ConvexDeployer, new ConvexCliDeployer({ spawner, convex: path.join(root, "node_modules", ".bin", "convex"), cwd: root, base })), Layer.succeed(OrganizationDirectory, new JiveServerOrganizationDirectory()));
32
+ if (group !== "cicd")
33
+ return yield* Effect.fail(new Error(`usage: jive-organization cicd <hook> (got ${group})`));
34
+ switch (hook) {
35
+ case "get-config": {
36
+ const { jive } = yield* Schema.decodeUnknownEffect(JiveBlock)(manifestText);
37
+ yield* decodeOrganizationManifest(manifestText);
38
+ return yield* Effect.sync(() => process.stdout.write(`${JSON.stringify(jive)}\n`));
39
+ }
40
+ case "build":
41
+ return yield* Effect.logInfo("Nothing to build: deploy pushes the Convex app's source");
42
+ case "audit": {
43
+ const result = yield* runCommand({ spawner, command: path.join(root, "node_modules", ".bin", "tsc"), args: ["--noEmit", "-p", "tsconfig.json"], cwd: root, env: base });
44
+ return yield* Effect.sync(() => process.stderr.write(result.stdout));
45
+ }
46
+ case "upload-artifacts":
47
+ return yield* Effect.logInfo("Nothing to upload: an organization has no build artifacts");
48
+ case "deploy-plan": {
49
+ const name = yield* organization;
50
+ const plan = yield* pipe(Effect.gen(() => deployPlan(name)), Effect.provide(services));
51
+ return yield* Effect.sync(() => process.stdout.write(`${JSON.stringify(plan)}\n`));
52
+ }
53
+ case "deploy": {
54
+ const name = yield* organization;
55
+ const target = yield* pipe(Effect.gen(() => deploy(name)), Effect.provide(services));
56
+ return yield* Effect.sync(() => process.stderr.write(`deployed the organization ${name} to its ${target.hosting} Convex server at ${target.url} and registered its workflows\n`));
57
+ }
58
+ default:
59
+ return yield* Effect.fail(new Error(`usage: jive-organization cicd get-config | build | audit | deploy-plan | upload-artifacts | deploy (got ${hook})`));
60
+ }
61
+ });
62
+ BunRuntime.runMain(pipe(program, Effect.provide(BunServices.layer)));
63
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../src/deploy/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAA;AAC9F,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAEjG;;;;GAIG;AACH,MAAM,CAAC,EAAE,AAAD,EAAG,KAAK,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAA;AAEtC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CA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AK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,IAAI,WAAW,MAAM,CAAC,OAAO,qBAAqB,MAAM,CAAC,GAAG,iCAAiC,CAAC,CAAC,CAAA;QACnL,CAAC;QACD;YACE,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,2GAA2G,IAAI,GAAG,CAAC,CAAC,CAAA;IAC5J,CAAC;AACH,CAAC,CAAC,CAAA;AAEF,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ import { Data, Effect, pipe, Stream } from "effect";
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
3
+ export class CommandFailed extends Data.TaggedError("CommandFailed") {
4
+ get message() {
5
+ return `${this.command} exited with ${this.exitCode}: ${this.output}`;
6
+ }
7
+ }
8
+ /**
9
+ * Runs one command to its end, with exactly the environment given (nothing is inherited, so no stray `CONVEX_*`
10
+ * variable reaches a CLI), and fails with its output when it exits non-zero.
11
+ */
12
+ export const runCommand = (input) => pipe(Effect.gen(function* () {
13
+ const handle = yield* ChildProcess.make(input.command, [...input.args], { cwd: input.cwd, env: { ...input.env }, extendEnv: false });
14
+ const { stdout, stderr } = yield* Effect.all({ stdout: pipe(handle.stdout, Stream.decodeText(), Stream.mkString), stderr: pipe(handle.stderr, Stream.decodeText(), Stream.mkString) }, { concurrency: 2 });
15
+ const exitCode = yield* handle.exitCode;
16
+ if (exitCode !== 0) {
17
+ return yield* Effect.fail(new CommandFailed({ command: [input.command, ...input.args].join(" "), exitCode, output: `${stderr}${stdout}` }));
18
+ }
19
+ const result = { stdout, stderr };
20
+ return result;
21
+ }), Effect.scoped, Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, input.spawner));
22
+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Q,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAA;IACvC,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,CAAA;IAC7I,CAAC;IACD,MAAM,MAAM,GAAkB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;IAChD,OAAO,MAAM,CAAA;AACf,CAAC,CAAC,EACF,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,cAAc,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,KAAK,CAAC,OAAO,CAAC,CAC9E,CAAA"}
@@ -0,0 +1,29 @@
1
+ import { Context, Data, Effect, pipe, Redacted } from "effect";
2
+ import { runCommand } from "./command";
3
+ export class DeployFailed extends Data.TaggedError("DeployFailed") {
4
+ get message() {
5
+ return `deploying to ${this.url} failed: ${String(this.cause)}`;
6
+ }
7
+ }
8
+ export class ConvexDeployer extends Context.Service()("ConvexDeployer") {
9
+ }
10
+ /**
11
+ * Deploys with the package's own `convex` CLI. The CLI gets only the variables naming the target, plus `PATH` and
12
+ * `HOME`, so a `CONVEX_*` variable of the job never redirects it.
13
+ */
14
+ export class ConvexCliDeployer {
15
+ input;
16
+ constructor(input) {
17
+ this.input = input;
18
+ }
19
+ *deploy(target) {
20
+ // An empty CONVEX_DEPLOYMENT keeps a checkout's `.env.local` (which `convex dev` writes) from choosing the
21
+ // deployment: the CLI loads that file without overriding variables already set.
22
+ const env = target.hosting === "managed"
23
+ ? { ...this.input.base, CONVEX_DEPLOYMENT: "", CONVEX_DEPLOY_KEY: Redacted.value(target.deployKey) }
24
+ : { ...this.input.base, CONVEX_DEPLOYMENT: "", CONVEX_SELF_HOSTED_URL: target.url, CONVEX_SELF_HOSTED_ADMIN_KEY: Redacted.value(target.adminKey) };
25
+ const convex = (args) => runCommand({ spawner: this.input.spawner, command: this.input.convex, args, cwd: this.input.cwd, env });
26
+ yield* pipe(convex(["deploy", "--yes", "--typecheck", "disable"]), Effect.andThen(convex(["run", "workforce:register", "{}"])), Effect.mapError((cause) => new DeployFailed({ url: target.url, cause })));
27
+ }
28
+ }
29
+ //# sourceMappingURL=convex-deployer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convex-deployer.js","sourceRoot":"","sources":["../../../../src/deploy/convex-deployer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,MAAM,OAAO,YAAa,SAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAAoD;IACnH,IAAa,OAAO;QAClB,OAAO,gBAAgB,IAAI,CAAC,GAAG,YAAY,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;IACjE,CAAC;CACF;AAYD,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,OAAO,EAAmC,CAAC,gBAAgB,CAAC;CAAG;AAE3G;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAET;IADnB,YACmB,KAKhB;QALgB,UAAK,GAAL,KAAK,CAKrB;IACA,CAAC;IAEJ,CAAC,MAAM,CAAC,MAAwB;QAC9B,2GAA2G;QAC3G,gFAAgF;QAChF,MAAM,GAAG,GACP,MAAM,CAAC,OAAO,KAAK,SAAS;YAC1B,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,iBAAiB,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YACpG,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,sBAAsB,EAAE,MAAM,CAAC,GAAG,EAAE,4BAA4B,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QACtJ,MAAM,MAAM,GAAG,CAAC,IAA2B,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;QACvJ,KAAK,CAAC,CAAC,IAAI,CACT,MAAM,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,EACrD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,oBAAoB,EAAE,IAAI,CAAC,CAAC,CAAC,EAC3D,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CACzE,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ import { Context, Data, Effect, pipe, Redacted, Schema } from "effect";
2
+ import { runCommand } from "./command";
3
+ export class ProvisionFailed extends Data.TaggedError("ProvisionFailed") {
4
+ get message() {
5
+ return `Jive could not hand over the Convex server of the organization ${this.organization}: ${String(this.cause)}`;
6
+ }
7
+ }
8
+ export class DeploymentProvisioner extends Context.Service()("DeploymentProvisioner") {
9
+ }
10
+ /** What `jive provision convex-deployment <organization>` prints on stdout. */
11
+ const ProvisionAnswer = Schema.Union([
12
+ Schema.Struct({ hosting: Schema.Literal("managed"), url: Schema.String, deployKey: Schema.String }),
13
+ Schema.Struct({ hosting: Schema.Literal("selfHosted"), url: Schema.String, adminKey: Schema.String }),
14
+ ]);
15
+ /** The jive CLI the deploy runs, by exact version so a release of jive never changes a deploy by itself. */
16
+ export const JIVE_CLI_PACKAGE = "@jive-sh/jive@0.15.1";
17
+ /**
18
+ * Signs the deploy job in with its GitHub Actions ID token (`jive login --cicd`), then asks for the organization's
19
+ * server (`jive provision convex-deployment <organization>`), through the jive CLI run by `bun x`.
20
+ */
21
+ export class JiveCliDeploymentProvisioner {
22
+ input;
23
+ constructor(input) {
24
+ this.input = input;
25
+ }
26
+ *provision(organization) {
27
+ const jive = (args) => runCommand({ spawner: this.input.spawner, command: "bun", args: ["x", JIVE_CLI_PACKAGE, ...args], cwd: this.input.cwd, env: this.input.env });
28
+ const answer = yield* pipe(jive(["login", "--cicd"]), Effect.andThen(jive(["provision", "convex-deployment", organization])), Effect.flatMap((result) => Schema.decodeUnknownEffect(Schema.fromJsonString(ProvisionAnswer))(result.stdout.trim())), Effect.mapError((cause) => new ProvisionFailed({ organization, cause })));
29
+ const target = answer.hosting === "managed"
30
+ ? { hosting: "managed", url: answer.url, deployKey: Redacted.make(answer.deployKey) }
31
+ : { hosting: "selfHosted", url: answer.url, adminKey: Redacted.make(answer.adminKey) };
32
+ return target;
33
+ }
34
+ }
35
+ //# sourceMappingURL=deployment-provisioner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deployment-provisioner.js","sourceRoot":"","sources":["../../../../src/deploy/deployment-provisioner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,MAAM,OAAO,eAAgB,SAAQ,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAA6D;IAClI,IAAa,OAAO;QAClB,OAAO,kEAAkE,IAAI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EACzB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,mBAAmB,EAAE,YAAY,CAAC,CAAC,CAAC,EACtE,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EACpH,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,CACzE,CAAA;QACD,MAAM,MAAM,GACV,MAAM,CAAC,OAAO,KAAK,SAAS;YAC1B,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;YACrF,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAA;QAC1F,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ import { ConvexDeployer } from "./convex-deployer";
2
+ import { DeploymentProvisioner } from "./deployment-provisioner";
3
+ import { OrganizationDirectory } from "./organization-directory";
4
+ /** `jive:cicd:deploy:plan`: an organization always deploys, to its Convex server's address. */
5
+ export const deployPlan = function* (organization) {
6
+ const directory = yield* OrganizationDirectory;
7
+ return { deploy: true, url: yield* directory.convexServerUrl(organization) };
8
+ };
9
+ /** `jive:cicd:deploy`: pushes the organization's Convex app to its server and registers its workflows there. */
10
+ export const deploy = function* (organization) {
11
+ const provisioner = yield* DeploymentProvisioner;
12
+ const target = yield* provisioner.provision(organization);
13
+ const deployer = yield* ConvexDeployer;
14
+ yield* deployer.deploy(target);
15
+ return target;
16
+ };
17
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../src/deploy/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAyB,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAEhE,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,EAAE,YAAoB;IACvD,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,qBAAqB,CAAA;IAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,CAAA;AAC9E,CAAC,CAAA;AAED,gHAAgH;AAChH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,YAAoB;IACnD,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,qBAAqB,CAAA;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IACzD,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,cAAc,CAAA;IACtC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC9B,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * The part of an organization package's `package.json` its deploy hooks read: `jive.organization.name`, the Jive
4
+ * organization whose Convex server the package deploys. Whether that server is managed by Jive or self-hosted is the
5
+ * organization's choice, recorded on `@jive-sh/server` when the organization was created, never in the manifest.
6
+ */
7
+ export const OrganizationManifest = Schema.Struct({
8
+ jive: Schema.Struct({ organization: Schema.Struct({ name: Schema.String }) }),
9
+ });
10
+ /** Decodes a `package.json` file's text. */
11
+ export const decodeOrganizationManifest = Schema.decodeUnknownEffect(Schema.fromJsonString(OrganizationManifest));
12
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../../../src/deploy/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC;IAChD,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;CAC9E,CAAC,CAAA;AAGF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,23 @@
1
+ import { api, convexUrl } from "@jive-sh/server-client";
2
+ import { ConvexHttpClient } from "convex/browser";
3
+ import { Context, Data, Effect } from "effect";
4
+ export class NoConvexServer extends Data.TaggedError("NoConvexServer") {
5
+ get message() {
6
+ return `the organization ${this.organization} has no Convex server on Jive: ${String(this.cause)}`;
7
+ }
8
+ }
9
+ export class OrganizationDirectory extends Context.Service()("OrganizationDirectory") {
10
+ }
11
+ /** Asks Jive's server over Convex's HTTP API (`organizations:convexServerUrl`). */
12
+ export class JiveServerOrganizationDirectory {
13
+ *convexServerUrl(organization) {
14
+ const url = yield* Effect.tryPromise({
15
+ try: () => new ConvexHttpClient(convexUrl).query(api.organizations.convexServerUrl, { name: organization }),
16
+ catch: (cause) => new NoConvexServer({ organization, cause }),
17
+ });
18
+ if (url === null)
19
+ return yield* Effect.fail(new NoConvexServer({ organization, cause: "none is recorded" }));
20
+ return url;
21
+ }
22
+ }
23
+ //# sourceMappingURL=organization-directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization-directory.js","sourceRoot":"","sources":["../../../../src/deploy/organization-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE9C,MAAM,OAAO,cAAe,SAAQ,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAA6D;IAChI,IAAa,OAAO;QAClB,OAAO,oBAAoB,IAAI,CAAC,YAAY,kCAAkC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAA;IACpG,CAAC;CACF;AAOD,MAAM,OAAO,qBAAsB,SAAQ,OAAO,CAAC,OAAO,EAAiD,CAAC,uBAAuB,CAAC;CAAG;AAEvI,mFAAmF;AACnF,MAAM,OAAO,+BAA+B;IAC1C,CAAC,eAAe,CAAC,YAAoB;QACnC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;YACnC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;YAC3G,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;SAC9D,CAAC,CAAA;QACF,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAA;QAC5G,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { actionGeneric, mutationGeneric, queryGeneric } from "convex/server";
2
+ /**
3
+ * A component's functions are reachable only from the app that installs it, so the organization exposes each workforce
4
+ * function its clients and workers call as a public one forwarding to it. The workforce function checks the arguments.
5
+ */
6
+ export const exposeQuery = (reference) => queryGeneric({ handler: (ctx, args) => ctx.runQuery(reference, args) });
7
+ export const exposeMutation = (reference) => mutationGeneric({ handler: (ctx, args) => ctx.runMutation(reference, args) });
8
+ export const exposeAction = (reference) => actionGeneric({ handler: (ctx, args) => ctx.runAction(reference, args) });
9
+ //# sourceMappingURL=expose-workforce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expose-workforce.js","sourceRoot":"","sources":["../../../src/expose-workforce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA0B,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEpG;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAA2D,EAAE,EAAE,CACzF,YAAY,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,IAA6B,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;AAElG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAA8D,EAAE,EAAE,CAC/F,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,IAA6B,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;AAExG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,SAA4D,EAAE,EAAE,CAC3F,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,IAA6B,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { exposeAction, exposeMutation, exposeQuery } from "./expose-workforce";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "jive-abstract-organization",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "description": "The Jive abstract an organization extends: an organization is a Convex server, managed by Jive or self-hosted, that runs its workforce's workflows.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/jive-sh/jive-abstract-organization.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "provenance": true
14
+ },
15
+ "main": "./dist/index.js",
16
+ "module": "./dist/index.js",
17
+ "types": "./src/index.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./src/index.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "README.md",
26
+ "dist",
27
+ "src",
28
+ "template"
29
+ ],
30
+ "dependencies": {
31
+ "@effect/platform-bun": "4.1.7",
32
+ "@jive-sh/server-client": "0.19.0",
33
+ "jive-abstract-abstraction": "0.1.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@jive-sh/workflow-platform": "^1.4.0",
37
+ "convex": "^1.51.0",
38
+ "effect": "^4.1.7",
39
+ "typescript": "^5.9.3"
40
+ },
41
+ "jive": {
42
+ "abstract": {
43
+ "replacements": {
44
+ "example-organization": "name",
45
+ "example-jive-organization": "organization"
46
+ }
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env bun
2
+ import { BunRuntime, BunServices } from "@effect/platform-bun"
3
+ import { Effect, FileSystem, Layer, Path, pipe, Schema } from "effect"
4
+ import { ChildProcessSpawner } from "effect/process"
5
+ import { runCommand } from "./command"
6
+ import { ConvexCliDeployer, ConvexDeployer } from "./convex-deployer"
7
+ import { DeploymentProvisioner, JiveCliDeploymentProvisioner } from "./deployment-provisioner"
8
+ import { deploy, deployPlan } from "./hooks"
9
+ import { decodeOrganizationManifest } from "./manifest"
10
+ import { JiveServerOrganizationDirectory, OrganizationDirectory } from "./organization-directory"
11
+
12
+ /**
13
+ * `jive-organization cicd <hook>`: the six CI/CD hooks of an organization package, run from its root. `get-config` and
14
+ * `deploy-plan` print only their JSON answer on stdout, as the CI/CD contract requires; everything else goes to stderr.
15
+ * An organization's Convex app is pushed as source by `deploy`, so `build` and `upload-artifacts` have nothing to do.
16
+ */
17
+ const [, , group, hook] = process.argv
18
+
19
+ const JiveBlock = Schema.fromJsonString(Schema.Struct({ jive: Schema.Unknown }))
20
+
21
+ const program = Effect.gen(function* () {
22
+ const fileSystem = yield* FileSystem.FileSystem
23
+ const path = yield* Path.Path
24
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
25
+ const root = process.cwd()
26
+ const manifestText = yield* fileSystem.readFileString(path.join(root, "package.json"))
27
+ const base = { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "" }
28
+ // The jive CLI also gets the variables GitHub Actions sets for requesting the job's ID token, which `jive login --cicd` exchanges.
29
+ const idTokenRequest = Object.fromEntries(
30
+ ["ACTIONS_ID_TOKEN_REQUEST_URL", "ACTIONS_ID_TOKEN_REQUEST_TOKEN"].flatMap((name) => {
31
+ const value = process.env[name]
32
+ return value === undefined ? [] : [[name, value]]
33
+ }),
34
+ )
35
+
36
+ const organization = Effect.map(decodeOrganizationManifest(manifestText), (manifest) => manifest.jive.organization.name)
37
+ const services = Layer.mergeAll(
38
+ Layer.succeed(DeploymentProvisioner, new JiveCliDeploymentProvisioner({ spawner, cwd: root, env: { ...base, ...idTokenRequest } })),
39
+ Layer.succeed(ConvexDeployer, new ConvexCliDeployer({ spawner, convex: path.join(root, "node_modules", ".bin", "convex"), cwd: root, base })),
40
+ Layer.succeed(OrganizationDirectory, new JiveServerOrganizationDirectory()),
41
+ )
42
+
43
+ if (group !== "cicd") return yield* Effect.fail(new Error(`usage: jive-organization cicd <hook> (got ${group})`))
44
+ switch (hook) {
45
+ case "get-config": {
46
+ const { jive } = yield* Schema.decodeUnknownEffect(JiveBlock)(manifestText)
47
+ yield* decodeOrganizationManifest(manifestText)
48
+ return yield* Effect.sync(() => process.stdout.write(`${JSON.stringify(jive)}\n`))
49
+ }
50
+ case "build":
51
+ return yield* Effect.logInfo("Nothing to build: deploy pushes the Convex app's source")
52
+ case "audit": {
53
+ const result = yield* runCommand({ spawner, command: path.join(root, "node_modules", ".bin", "tsc"), args: ["--noEmit", "-p", "tsconfig.json"], cwd: root, env: base })
54
+ return yield* Effect.sync(() => process.stderr.write(result.stdout))
55
+ }
56
+ case "upload-artifacts":
57
+ return yield* Effect.logInfo("Nothing to upload: an organization has no build artifacts")
58
+ case "deploy-plan": {
59
+ const name = yield* organization
60
+ const plan = yield* pipe(Effect.gen(() => deployPlan(name)), Effect.provide(services))
61
+ return yield* Effect.sync(() => process.stdout.write(`${JSON.stringify(plan)}\n`))
62
+ }
63
+ case "deploy": {
64
+ const name = yield* organization
65
+ const target = yield* pipe(Effect.gen(() => deploy(name)), Effect.provide(services))
66
+ return yield* Effect.sync(() => process.stderr.write(`deployed the organization ${name} to its ${target.hosting} Convex server at ${target.url} and registered its workflows\n`))
67
+ }
68
+ default:
69
+ return yield* Effect.fail(new Error(`usage: jive-organization cicd get-config | build | audit | deploy-plan | upload-artifacts | deploy (got ${hook})`))
70
+ }
71
+ })
72
+
73
+ BunRuntime.runMain(pipe(program, Effect.provide(BunServices.layer)))
@@ -0,0 +1,47 @@
1
+ import { Data, Effect, pipe, Stream } from "effect"
2
+ import { ChildProcess, ChildProcessSpawner } from "effect/process"
3
+
4
+ export class CommandFailed extends Data.TaggedError("CommandFailed")<{
5
+ readonly command: string
6
+ readonly exitCode: number
7
+ readonly output: string
8
+ }> {
9
+ override get message() {
10
+ return `${this.command} exited with ${this.exitCode}: ${this.output}`
11
+ }
12
+ }
13
+
14
+ /** What a finished command printed. */
15
+ export interface CommandResult {
16
+ readonly stdout: string
17
+ readonly stderr: string
18
+ }
19
+
20
+ /**
21
+ * Runs one command to its end, with exactly the environment given (nothing is inherited, so no stray `CONVEX_*`
22
+ * variable reaches a CLI), and fails with its output when it exits non-zero.
23
+ */
24
+ export const runCommand = (input: {
25
+ readonly spawner: ChildProcessSpawner.ChildProcessSpawner["Service"]
26
+ readonly command: string
27
+ readonly args: ReadonlyArray<string>
28
+ readonly cwd: string
29
+ readonly env: Readonly<Record<string, string>>
30
+ }) =>
31
+ pipe(
32
+ Effect.gen(function* () {
33
+ const handle = yield* ChildProcess.make(input.command, [...input.args], { cwd: input.cwd, env: { ...input.env }, extendEnv: false })
34
+ const { stdout, stderr } = yield* Effect.all(
35
+ { stdout: pipe(handle.stdout, Stream.decodeText(), Stream.mkString), stderr: pipe(handle.stderr, Stream.decodeText(), Stream.mkString) },
36
+ { concurrency: 2 },
37
+ )
38
+ const exitCode = yield* handle.exitCode
39
+ if (exitCode !== 0) {
40
+ return yield* Effect.fail(new CommandFailed({ command: [input.command, ...input.args].join(" "), exitCode, output: `${stderr}${stdout}` }))
41
+ }
42
+ const result: CommandResult = { stdout, stderr }
43
+ return result
44
+ }),
45
+ Effect.scoped,
46
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, input.spawner),
47
+ )
@@ -0,0 +1,51 @@
1
+ import { Context, Data, Effect, pipe, Redacted } from "effect"
2
+ import type { ChildProcessSpawner } from "effect/process"
3
+ import { runCommand } from "./command"
4
+
5
+ export class DeployFailed extends Data.TaggedError("DeployFailed")<{ readonly url: string; readonly cause: unknown }> {
6
+ override get message() {
7
+ return `deploying to ${this.url} failed: ${String(this.cause)}`
8
+ }
9
+ }
10
+
11
+ /** The organization's Convex server, and the key the push proves it may with. */
12
+ export type DeploymentTarget =
13
+ | { readonly hosting: "managed"; readonly url: string; readonly deployKey: Redacted.Redacted<string> }
14
+ | { readonly hosting: "selfHosted"; readonly url: string; readonly adminKey: Redacted.Redacted<string> }
15
+
16
+ /** Pushes the organization's Convex app to its deployment, then registers its workforce's workflows there. */
17
+ export interface IConvexDeployer {
18
+ deploy(target: DeploymentTarget): Effect.fn.Return<void, DeployFailed>
19
+ }
20
+
21
+ export class ConvexDeployer extends Context.Service<ConvexDeployer, IConvexDeployer>()("ConvexDeployer") {}
22
+
23
+ /**
24
+ * Deploys with the package's own `convex` CLI. The CLI gets only the variables naming the target, plus `PATH` and
25
+ * `HOME`, so a `CONVEX_*` variable of the job never redirects it.
26
+ */
27
+ export class ConvexCliDeployer implements IConvexDeployer {
28
+ constructor(
29
+ private readonly input: {
30
+ readonly spawner: ChildProcessSpawner.ChildProcessSpawner["Service"]
31
+ readonly convex: string
32
+ readonly cwd: string
33
+ readonly base: { readonly PATH: string; readonly HOME: string }
34
+ },
35
+ ) {}
36
+
37
+ *deploy(target: DeploymentTarget) {
38
+ // An empty CONVEX_DEPLOYMENT keeps a checkout's `.env.local` (which `convex dev` writes) from choosing the
39
+ // deployment: the CLI loads that file without overriding variables already set.
40
+ const env: Record<string, string> =
41
+ target.hosting === "managed"
42
+ ? { ...this.input.base, CONVEX_DEPLOYMENT: "", CONVEX_DEPLOY_KEY: Redacted.value(target.deployKey) }
43
+ : { ...this.input.base, CONVEX_DEPLOYMENT: "", CONVEX_SELF_HOSTED_URL: target.url, CONVEX_SELF_HOSTED_ADMIN_KEY: Redacted.value(target.adminKey) }
44
+ const convex = (args: ReadonlyArray<string>) => runCommand({ spawner: this.input.spawner, command: this.input.convex, args, cwd: this.input.cwd, env })
45
+ yield* pipe(
46
+ convex(["deploy", "--yes", "--typecheck", "disable"]),
47
+ Effect.andThen(convex(["run", "workforce:register", "{}"])),
48
+ Effect.mapError((cause) => new DeployFailed({ url: target.url, cause })),
49
+ )
50
+ }
51
+ }
@@ -0,0 +1,59 @@
1
+ import { Context, Data, Effect, pipe, Redacted, Schema } from "effect"
2
+ import type { ChildProcessSpawner } from "effect/process"
3
+ import { runCommand } from "./command"
4
+ import type { DeploymentTarget } from "./convex-deployer"
5
+
6
+ export class ProvisionFailed extends Data.TaggedError("ProvisionFailed")<{ readonly organization: string; readonly cause: unknown }> {
7
+ override get message() {
8
+ return `Jive could not hand over the Convex server of the organization ${this.organization}: ${String(this.cause)}`
9
+ }
10
+ }
11
+
12
+ /**
13
+ * Gets the deploy job the organization's Convex server and the key that deploys to it, from `@jive-sh/server`, which
14
+ * holds both: a managed server's deploy key, or a self-hosted server's admin key.
15
+ */
16
+ export interface IDeploymentProvisioner {
17
+ provision(organization: string): Effect.fn.Return<DeploymentTarget, ProvisionFailed>
18
+ }
19
+
20
+ export class DeploymentProvisioner extends Context.Service<DeploymentProvisioner, IDeploymentProvisioner>()("DeploymentProvisioner") {}
21
+
22
+ /** What `jive provision convex-deployment <organization>` prints on stdout. */
23
+ const ProvisionAnswer = Schema.Union([
24
+ Schema.Struct({ hosting: Schema.Literal("managed"), url: Schema.String, deployKey: Schema.String }),
25
+ Schema.Struct({ hosting: Schema.Literal("selfHosted"), url: Schema.String, adminKey: Schema.String }),
26
+ ])
27
+
28
+ /** The jive CLI the deploy runs, by exact version so a release of jive never changes a deploy by itself. */
29
+ export const JIVE_CLI_PACKAGE = "@jive-sh/jive@0.15.1"
30
+
31
+ /**
32
+ * Signs the deploy job in with its GitHub Actions ID token (`jive login --cicd`), then asks for the organization's
33
+ * server (`jive provision convex-deployment <organization>`), through the jive CLI run by `bun x`.
34
+ */
35
+ export class JiveCliDeploymentProvisioner implements IDeploymentProvisioner {
36
+ constructor(
37
+ private readonly input: {
38
+ readonly spawner: ChildProcessSpawner.ChildProcessSpawner["Service"]
39
+ readonly cwd: string
40
+ readonly env: Readonly<Record<string, string>>
41
+ },
42
+ ) {}
43
+
44
+ *provision(organization: string) {
45
+ const jive = (args: ReadonlyArray<string>) =>
46
+ runCommand({ spawner: this.input.spawner, command: "bun", args: ["x", JIVE_CLI_PACKAGE, ...args], cwd: this.input.cwd, env: this.input.env })
47
+ const answer = yield* pipe(
48
+ jive(["login", "--cicd"]),
49
+ Effect.andThen(jive(["provision", "convex-deployment", organization])),
50
+ Effect.flatMap((result) => Schema.decodeUnknownEffect(Schema.fromJsonString(ProvisionAnswer))(result.stdout.trim())),
51
+ Effect.mapError((cause) => new ProvisionFailed({ organization, cause })),
52
+ )
53
+ const target: DeploymentTarget =
54
+ answer.hosting === "managed"
55
+ ? { hosting: "managed", url: answer.url, deployKey: Redacted.make(answer.deployKey) }
56
+ : { hosting: "selfHosted", url: answer.url, adminKey: Redacted.make(answer.adminKey) }
57
+ return target
58
+ }
59
+ }
@@ -0,0 +1,19 @@
1
+ import { Effect } from "effect"
2
+ import { ConvexDeployer, type DeploymentTarget } from "./convex-deployer"
3
+ import { DeploymentProvisioner } from "./deployment-provisioner"
4
+ import { OrganizationDirectory } from "./organization-directory"
5
+
6
+ /** `jive:cicd:deploy:plan`: an organization always deploys, to its Convex server's address. */
7
+ export const deployPlan = function* (organization: string): Effect.fn.Return<{ readonly deploy: true; readonly url: string }, unknown, OrganizationDirectory> {
8
+ const directory = yield* OrganizationDirectory
9
+ return { deploy: true, url: yield* directory.convexServerUrl(organization) }
10
+ }
11
+
12
+ /** `jive:cicd:deploy`: pushes the organization's Convex app to its server and registers its workflows there. */
13
+ export const deploy = function* (organization: string): Effect.fn.Return<DeploymentTarget, unknown, DeploymentProvisioner | ConvexDeployer> {
14
+ const provisioner = yield* DeploymentProvisioner
15
+ const target = yield* provisioner.provision(organization)
16
+ const deployer = yield* ConvexDeployer
17
+ yield* deployer.deploy(target)
18
+ return target
19
+ }
@@ -0,0 +1,14 @@
1
+ import { Schema } from "effect"
2
+
3
+ /**
4
+ * The part of an organization package's `package.json` its deploy hooks read: `jive.organization.name`, the Jive
5
+ * organization whose Convex server the package deploys. Whether that server is managed by Jive or self-hosted is the
6
+ * organization's choice, recorded on `@jive-sh/server` when the organization was created, never in the manifest.
7
+ */
8
+ export const OrganizationManifest = Schema.Struct({
9
+ jive: Schema.Struct({ organization: Schema.Struct({ name: Schema.String }) }),
10
+ })
11
+ export type OrganizationManifest = typeof OrganizationManifest.Type
12
+
13
+ /** Decodes a `package.json` file's text. */
14
+ export const decodeOrganizationManifest = Schema.decodeUnknownEffect(Schema.fromJsonString(OrganizationManifest))
@@ -0,0 +1,28 @@
1
+ import { api, convexUrl } from "@jive-sh/server-client"
2
+ import { ConvexHttpClient } from "convex/browser"
3
+ import { Context, Data, Effect } from "effect"
4
+
5
+ export class NoConvexServer extends Data.TaggedError("NoConvexServer")<{ readonly organization: string; readonly cause: unknown }> {
6
+ override get message() {
7
+ return `the organization ${this.organization} has no Convex server on Jive: ${String(this.cause)}`
8
+ }
9
+ }
10
+
11
+ /** Reads an organization's Convex server address from `@jive-sh/server`, with no session: what `deploy-plan` names. */
12
+ export interface IOrganizationDirectory {
13
+ convexServerUrl(organization: string): Effect.fn.Return<string, NoConvexServer>
14
+ }
15
+
16
+ export class OrganizationDirectory extends Context.Service<OrganizationDirectory, IOrganizationDirectory>()("OrganizationDirectory") {}
17
+
18
+ /** Asks Jive's server over Convex's HTTP API (`organizations:convexServerUrl`). */
19
+ export class JiveServerOrganizationDirectory implements IOrganizationDirectory {
20
+ *convexServerUrl(organization: string) {
21
+ const url = yield* Effect.tryPromise({
22
+ try: () => new ConvexHttpClient(convexUrl).query(api.organizations.convexServerUrl, { name: organization }),
23
+ catch: (cause) => new NoConvexServer({ organization, cause }),
24
+ })
25
+ if (url === null) return yield* Effect.fail(new NoConvexServer({ organization, cause: "none is recorded" }))
26
+ return url
27
+ }
28
+ }
@@ -0,0 +1,14 @@
1
+ import { actionGeneric, type FunctionReference, mutationGeneric, queryGeneric } from "convex/server"
2
+
3
+ /**
4
+ * A component's functions are reachable only from the app that installs it, so the organization exposes each workforce
5
+ * function its clients and workers call as a public one forwarding to it. The workforce function checks the arguments.
6
+ */
7
+ export const exposeQuery = (reference: FunctionReference<"query", "internal", any, any>) =>
8
+ queryGeneric({ handler: (ctx, args: Record<string, unknown>) => ctx.runQuery(reference, args) })
9
+
10
+ export const exposeMutation = (reference: FunctionReference<"mutation", "internal", any, any>) =>
11
+ mutationGeneric({ handler: (ctx, args: Record<string, unknown>) => ctx.runMutation(reference, args) })
12
+
13
+ export const exposeAction = (reference: FunctionReference<"action", "internal", any, any>) =>
14
+ actionGeneric({ handler: (ctx, args: Record<string, unknown>) => ctx.runAction(reference, args) })
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { exposeAction, exposeMutation, exposeQuery } from "./expose-workforce"
@@ -0,0 +1,7 @@
1
+ node_modules
2
+ dist
3
+ package.schema.json
4
+ .env.local
5
+ .convex
6
+ .home
7
+ .files
@@ -0,0 +1,16 @@
1
+ # <%= name %>
2
+
3
+ The organization `<%= organization %>` on Jive: its Convex server, made with `jive create organization` from
4
+ [jive-abstract-organization](https://github.com/jive-sh/jive-abstract-organization). Jive hosts the server (managed),
5
+ or the organization runs it (self-hosted), as the organization chose when it was created on Jive.
6
+
7
+ - `src/convex/` is the Convex app. `workforce.ts` holds the organization's workforce, the workflows it runs: none yet.
8
+ A workflow joins by installing its component in `convex.config.ts` and adding it to the workforce's list.
9
+ - `jive.organization.name` in `package.json` names the Jive organization whose server this app is deployed to. Its
10
+ deploy job gets the server's address and key from Jive, so the repository holds no secret for it.
11
+
12
+ ## Tests
13
+
14
+ `bun test test` runs against the anonymous local deployment `convex dev` writes to `.env.local`, and refuses any other.
15
+ Start one with `CONVEX_AGENT_MODE=anonymous bunx convex dev` first. The test pushes the app to that local backend the way
16
+ the deploy pushes to a self-hosted server, then checks the workforce answers.
@@ -0,0 +1,3 @@
1
+ {
2
+ "functions": "src/convex"
3
+ }
@@ -0,0 +1,51 @@
1
+ {
2
+ "$schema": "./package.schema.json",
3
+ "license": "MIT",
4
+ "name": "<%= name %>",
5
+ "description": "An organization: the Convex server its workforce runs on, deployed to the organization's Convex server on Jive.",
6
+ "version": "0.1.0",
7
+ "private": true,
8
+ "type": "module",
9
+ "dependencies": {
10
+ "@effect/platform-bun": "4.1.7",
11
+ "@jive-sh/workflow-platform": "^1.4.3",
12
+ "convex": "1.51.0",
13
+ "effect": "4.1.7",
14
+ "jive-abstract-agentic-workforce": "0.1.0",
15
+ "jive-abstract-organization": "link:../.."
16
+ },
17
+ "devDependencies": {
18
+ "@types/bun": "1.4.4",
19
+ "typescript": "5.9.3"
20
+ },
21
+ "scripts": {
22
+ "jive:cicd:get-config": "jive-organization cicd get-config",
23
+ "jive:cicd:build": "jive-organization cicd build",
24
+ "jive:cicd:audit": "jive-organization cicd audit",
25
+ "jive:cicd:deploy:plan": "jive-organization cicd deploy-plan",
26
+ "jive:cicd:upload-artifacts": "jive-organization cicd upload-artifacts",
27
+ "jive:cicd:deploy": "jive-organization cicd deploy",
28
+ "typecheck": "tsc --noEmit -p tsconfig.json",
29
+ "test": "bun test test"
30
+ },
31
+ "jive": {
32
+ "cicd": {
33
+ "deploy": {
34
+ "verb": "Deploy to",
35
+ "branches": {
36
+ "main": [
37
+ "Production"
38
+ ]
39
+ },
40
+ "previews": false,
41
+ "sequentially": true
42
+ },
43
+ "runsOnPullRequests": true,
44
+ "runsOn": "ubuntu-latest",
45
+ "requiredSecrets": []
46
+ },
47
+ "organization": {
48
+ "name": "<%= organization %>"
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,9 @@
1
+ import { defineApp } from "convex/server"
2
+
3
+ /**
4
+ * The organization's Convex app, its server, hosted by Jive (managed) or self-hosted. It installs a workflow's component
5
+ * here, beside the workforce's functions in `workforce.ts`, once its workforce runs that workflow.
6
+ */
7
+ const app = defineApp()
8
+
9
+ export default app
@@ -0,0 +1,25 @@
1
+ {
2
+ /* This TypeScript project config describes the environment that
3
+ * Convex functions run in and is used to typecheck them.
4
+ * You can modify it, but some settings are required to use Convex.
5
+ */
6
+ "compilerOptions": {
7
+ /* These settings are not required by Convex and can be modified. */
8
+ "allowJs": true,
9
+ "strict": true,
10
+ "moduleResolution": "Bundler",
11
+ "jsx": "react-jsx",
12
+ "skipLibCheck": true,
13
+ "allowSyntheticDefaultImports": true,
14
+
15
+ /* These compiler options are required by Convex */
16
+ "target": "ESNext",
17
+ "lib": ["ES2023", "dom"],
18
+ "forceConsistentCasingInFileNames": true,
19
+ "module": "ESNext",
20
+ "isolatedModules": true,
21
+ "noEmit": true
22
+ },
23
+ "include": ["./**/*"],
24
+ "exclude": ["./_generated"]
25
+ }
@@ -0,0 +1,30 @@
1
+ import { workforceFunctions } from "jive-abstract-agentic-workforce/src/index"
2
+
3
+ /**
4
+ * The organization's workforce: the workflows it runs, each with its component installed in `convex.config.ts`. It runs
5
+ * none yet. Its clients and workers call these functions, and the deploy runs `workforce:register` after each push.
6
+ */
7
+ export const {
8
+ register,
9
+ remove,
10
+ setBudgets,
11
+ createTask,
12
+ setTaskFields,
13
+ requeueTask,
14
+ moveToFront,
15
+ task,
16
+ subWorkflowTasks,
17
+ counts,
18
+ tasksAt,
19
+ stepStats,
20
+ stepRuns,
21
+ workflow,
22
+ take,
23
+ complete,
24
+ fail,
25
+ heartbeat,
26
+ findTasks,
27
+ prune,
28
+ startSubWorkflowTasks,
29
+ subWorkflowTaskEnded,
30
+ } = workforceFunctions({ module: "workforce", workflows: [] })
@@ -0,0 +1,38 @@
1
+ import { describe, expect, setDefaultTimeout, test } from "bun:test"
2
+ import { BunServices } from "@effect/platform-bun"
3
+ import { Effect, pipe, Redacted } from "effect"
4
+ import { ChildProcessSpawner } from "effect/process"
5
+ import { makeFunctionReference } from "convex/server"
6
+ import { ConvexCliDeployer } from "jive-abstract-organization/src/deploy/convex-deployer"
7
+ import { newClient, url } from "./harness"
8
+
9
+ // A real deploy runs the Convex CLI twice on a machine that queues commands behind a CPU limit.
10
+ setDefaultTimeout(180_000)
11
+
12
+ describe("organization deploy to a self-hosted server (the local backend)", () => {
13
+ /**
14
+ * The push `jive-organization cicd deploy` makes once Jive has handed over a self-hosted server's address and admin
15
+ * key, with only the variables a deploy job has: no stray `CONVEX_*` one, and `.env.local` left as it was.
16
+ */
17
+ test("the deploy pushes the app and registers its workforce, which runs no workflow yet", async () => {
18
+ const config = (await Bun.file(new URL("../.convex/local/default/config.json", import.meta.url)).json()) as { adminKey: string }
19
+ const envBefore = await Bun.file(new URL("../.env.local", import.meta.url)).text()
20
+ await Effect.runPromise(
21
+ pipe(
22
+ Effect.gen(function* () {
23
+ const deployer = new ConvexCliDeployer({
24
+ spawner: yield* ChildProcessSpawner.ChildProcessSpawner,
25
+ convex: new URL("../node_modules/.bin/convex", import.meta.url).pathname,
26
+ cwd: new URL("..", import.meta.url).pathname,
27
+ base: { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "" },
28
+ })
29
+ yield* Effect.gen(() => deployer.deploy({ hosting: "selfHosted", url, adminKey: Redacted.make(config.adminKey) }))
30
+ }),
31
+ Effect.provide(BunServices.layer),
32
+ ),
33
+ )
34
+ const counts = makeFunctionReference<"query", { workflow: string }>("workforce:counts")
35
+ await expect(newClient().query(counts, { workflow: "none" })).rejects.toThrow("workflow none is not installed in this workforce")
36
+ expect(await Bun.file(new URL("../.env.local", import.meta.url)).text()).toBe(envBefore)
37
+ })
38
+ })
@@ -0,0 +1,19 @@
1
+ import { ConvexHttpClient } from "convex/browser"
2
+
3
+ /**
4
+ * The tests run against the anonymous local deployment `convex dev` wrote to `.env.local`, and refuse any other, so no
5
+ * test can write to a cloud deployment.
6
+ */
7
+ const localDeploymentUrl = async (): Promise<string> => {
8
+ const env = await Bun.file(new URL("../.env.local", import.meta.url)).text()
9
+ const deployment = /^CONVEX_DEPLOYMENT=(.*)$/m.exec(env)?.[1] ?? ""
10
+ const url = /^CONVEX_URL=(.*)$/m.exec(env)?.[1] ?? ""
11
+ if (!deployment.startsWith("anonymous:") || !url.startsWith("http://127.0.0.1:")) {
12
+ throw new Error(`.env.local names ${deployment} at ${url}; the tests only run against an anonymous local deployment`)
13
+ }
14
+ return url
15
+ }
16
+
17
+ export const url = await localDeploymentUrl()
18
+
19
+ export const newClient = () => new ConvexHttpClient(url)
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "lib": ["ES2023", "DOM"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "isolatedModules": true,
11
+ "allowJs": true,
12
+ "types": ["bun"]
13
+ },
14
+ "include": ["src", "test"],
15
+ "exclude": ["node_modules"]
16
+ }