@samebase/alchemy-convex 0.16.0 → 0.18.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/NOTICE +3 -0
- package/README.md +28 -1
- package/lib/{HubClient-BYBV7cF5.js → HubClient-BZKweNfD.js} +2 -2
- package/lib/{HubClient-BYBV7cF5.js.map → HubClient-BZKweNfD.js.map} +1 -1
- package/lib/cli.js +215 -9
- package/lib/cli.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/HubClient.ts +3 -3
- package/src/StackComment.ts +307 -0
- package/src/cli.ts +50 -32
package/lib/cli.js
CHANGED
|
@@ -1,9 +1,207 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { I as ManagementApiLive, M as installedCli, V as fromConfig, a as registerDevelopmentClient } from "./HubClient-
|
|
2
|
+
import { I as ManagementApiLive, M as installedCli, V as fromConfig, a as registerDevelopmentClient, c as RUN_RECORD_KEY, s as state, u as runRecord } from "./HubClient-BZKweNfD.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
4
5
|
import * as Layer from "effect/Layer";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
7
|
+
import { State } from "alchemy/State";
|
|
6
8
|
import { execFileSync } from "node:child_process";
|
|
9
|
+
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
10
|
+
//#region src/StackComment.ts
|
|
11
|
+
/** The first text of the comment, which finds it again. */
|
|
12
|
+
const MARKER = "<!-- samebase-stacks -->";
|
|
13
|
+
/** GitHub does not proxy this host, so a new icon needs no purge of its image cache. */
|
|
14
|
+
const ICONS = "https://raw.githubusercontent.com/samebase/alchemy-convex/main/assets/stack-comment";
|
|
15
|
+
const GITHUB_API = "https://api.github.com";
|
|
16
|
+
/** The resources that a card shows. A row of any other type, or without `attr` from an interrupted deploy, is left out. */
|
|
17
|
+
const Resource = Schema.Union([
|
|
18
|
+
Schema.Struct({
|
|
19
|
+
resourceType: Schema.Literal("Convex.Deployment"),
|
|
20
|
+
attr: Schema.Struct({
|
|
21
|
+
name: Schema.String,
|
|
22
|
+
siteUrl: Schema.String
|
|
23
|
+
})
|
|
24
|
+
}),
|
|
25
|
+
Schema.Struct({
|
|
26
|
+
resourceType: Schema.Literal("Cloudflare.Worker"),
|
|
27
|
+
attr: Schema.Struct({
|
|
28
|
+
workerName: Schema.String,
|
|
29
|
+
url: Schema.optional(Schema.String)
|
|
30
|
+
})
|
|
31
|
+
}),
|
|
32
|
+
Schema.Struct({
|
|
33
|
+
resourceType: Schema.Literal("Cloudflare.R2.Bucket"),
|
|
34
|
+
attr: Schema.Struct({
|
|
35
|
+
bucketName: Schema.String,
|
|
36
|
+
accountId: Schema.String,
|
|
37
|
+
jurisdiction: Schema.String
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
]);
|
|
41
|
+
/** The fields of the run record that a card shows. */
|
|
42
|
+
const StageOutput = Schema.Struct({ [RUN_RECORD_KEY]: Schema.Struct({
|
|
43
|
+
headCommit: Schema.String,
|
|
44
|
+
runUrl: Schema.NullOr(Schema.String),
|
|
45
|
+
recordedAt: Schema.String
|
|
46
|
+
}) });
|
|
47
|
+
var StackCommentError = class extends Schema.TaggedError()("StackCommentError", { reason: Schema.String }) {
|
|
48
|
+
get message() {
|
|
49
|
+
return `The stack comment cannot be updated: ${this.reason}`;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/** The cards of the stacks of `repository` that have `stage`, in name order. */
|
|
53
|
+
const readStackCards = ({ repository, stage }) => Effect.gen(function* () {
|
|
54
|
+
const state = yield* yield* State;
|
|
55
|
+
const names = (yield* state.listStacks()).filter((name) => name === repository || name.startsWith(`${repository}/`));
|
|
56
|
+
const cards = [];
|
|
57
|
+
for (const name of names) {
|
|
58
|
+
if (!(yield* state.listStages(name)).includes(stage)) continue;
|
|
59
|
+
const request = {
|
|
60
|
+
stack: name,
|
|
61
|
+
stage
|
|
62
|
+
};
|
|
63
|
+
const rows = yield* Effect.forEach(yield* state.list(request), (fqn) => state.get({
|
|
64
|
+
...request,
|
|
65
|
+
fqn
|
|
66
|
+
}));
|
|
67
|
+
const output = yield* state.getOutput(request);
|
|
68
|
+
cards.push({
|
|
69
|
+
name,
|
|
70
|
+
stage,
|
|
71
|
+
resources: rows.filter(Schema.is(Resource)),
|
|
72
|
+
run: Schema.is(StageOutput)(output) ? output : null
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return cards;
|
|
76
|
+
});
|
|
77
|
+
/** A stack can create a deployment in one resource and push to it in another: a card shows it once. */
|
|
78
|
+
const withoutRepeats = (resources) => {
|
|
79
|
+
const deployments = /* @__PURE__ */ new Set();
|
|
80
|
+
return resources.filter((resource) => {
|
|
81
|
+
if (resource.resourceType !== "Convex.Deployment") return true;
|
|
82
|
+
const repeated = deployments.has(resource.attr.name);
|
|
83
|
+
deployments.add(resource.attr.name);
|
|
84
|
+
return !repeated;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
const escapeHtml = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
88
|
+
const link = (href, text) => `<a href="${escapeHtml(href)}">${text}</a>`;
|
|
89
|
+
const named = (href, icon, alt, name) => {
|
|
90
|
+
const image = `<img src="${ICONS}/${icon}.svg" width="16" align="absmiddle" alt="${alt}">`;
|
|
91
|
+
return `${link(href, image)} ${link(href, escapeHtml(name))}`;
|
|
92
|
+
};
|
|
93
|
+
const hostOf = (url) => escapeHtml(new URL(url).host);
|
|
94
|
+
/** Where a stack serves: its Convex deployment, else its first Worker with a URL. */
|
|
95
|
+
const addressOf = (resources) => {
|
|
96
|
+
for (const resource of resources) if (resource.resourceType === "Convex.Deployment") return resource.attr.siteUrl;
|
|
97
|
+
for (const resource of resources) if (resource.resourceType === "Cloudflare.Worker" && resource.attr.url !== void 0) return resource.attr.url;
|
|
98
|
+
return null;
|
|
99
|
+
};
|
|
100
|
+
const resourceRow = (resource, address) => {
|
|
101
|
+
switch (resource.resourceType) {
|
|
102
|
+
case "Convex.Deployment": {
|
|
103
|
+
const { name } = resource.attr;
|
|
104
|
+
return named(`https://dashboard.convex.dev/d/${encodeURIComponent(name)}`, "convex", "Convex", name);
|
|
105
|
+
}
|
|
106
|
+
case "Cloudflare.Worker": {
|
|
107
|
+
const { url, workerName } = resource.attr;
|
|
108
|
+
const row = named(`https://dash.cloudflare.com/?to=/:account/workers/services/view/${encodeURIComponent(workerName)}`, "worker", "Worker", workerName);
|
|
109
|
+
return url === void 0 || url === address ? row : `${row}<br><sub>${link(url, hostOf(url))}</sub>`;
|
|
110
|
+
}
|
|
111
|
+
case "Cloudflare.R2.Bucket": {
|
|
112
|
+
const { accountId, bucketName, jurisdiction } = resource.attr;
|
|
113
|
+
return named(`https://dash.cloudflare.com/${encodeURIComponent(accountId)}/r2/${encodeURIComponent(jurisdiction)}/buckets/${encodeURIComponent(bucketName)}`, "r2", "R2 bucket", bucketName);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const runLine = ({ run }) => {
|
|
118
|
+
if (run === null) return "";
|
|
119
|
+
const { headCommit, recordedAt, runUrl } = run[RUN_RECORD_KEY];
|
|
120
|
+
const commit = escapeHtml(headCommit.slice(0, 7));
|
|
121
|
+
const time = `${recordedAt.slice(0, 16).replace("T", " ")} UTC`;
|
|
122
|
+
return `<br><sub>${runUrl === null ? commit : link(runUrl, commit)} ${escapeHtml(time)}</sub>`;
|
|
123
|
+
};
|
|
124
|
+
const SPACER = `<div><img src="${ICONS}/spacer.svg" width="460" align="left" alt=""></div>`;
|
|
125
|
+
/** `alone`: the one card of the repository. A card at the root then has no folder, as on the repository page. */
|
|
126
|
+
const renderCard = (card, repository, alone) => {
|
|
127
|
+
const folder = card.name.slice(repository.length + 1);
|
|
128
|
+
const heading = [folder === "" && alone ? "" : `<b>${escapeHtml(folder || "/")}</b> `, `<sub>${escapeHtml(card.stage)}</sub>`].join("");
|
|
129
|
+
const resources = withoutRepeats(card.resources);
|
|
130
|
+
const address = addressOf(resources);
|
|
131
|
+
const addressLine = address === null ? "" : `<br>${link(address, hostOf(address))}`;
|
|
132
|
+
const rows = resources.map((resource) => `<tbody><tr><td>${resourceRow(resource, address)}</td></tr></tbody>`).join("\n");
|
|
133
|
+
return `<table>
|
|
134
|
+
<tbody><tr><td>${SPACER}${heading}${addressLine}${runLine(card)}</td></tr></tbody>
|
|
135
|
+
${rows}
|
|
136
|
+
</table>`;
|
|
137
|
+
};
|
|
138
|
+
const renderStackComment = (cards, repository) => `${MARKER}
|
|
139
|
+
${cards.map((card) => renderCard(card, repository, cards.length === 1)).join("\n\n")}
|
|
140
|
+
`;
|
|
141
|
+
const Comments = Schema.Array(Schema.Struct({
|
|
142
|
+
id: Schema.Number,
|
|
143
|
+
body: Schema.String
|
|
144
|
+
}));
|
|
145
|
+
const SavedComment = Schema.Struct({ html_url: Schema.String });
|
|
146
|
+
const github = (token, path, init) => Effect.tryPromise({
|
|
147
|
+
try: async () => {
|
|
148
|
+
const response = await fetch(`${GITHUB_API}${path}`, {
|
|
149
|
+
...init,
|
|
150
|
+
headers: {
|
|
151
|
+
Accept: "application/vnd.github+json",
|
|
152
|
+
Authorization: `Bearer ${token}`,
|
|
153
|
+
"Content-Type": "application/json",
|
|
154
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
158
|
+
return await response.json();
|
|
159
|
+
},
|
|
160
|
+
catch: (error) => new StackCommentError({ reason: `GitHub ${init.method} ${path} failed (${error instanceof Error ? error.message : String(error)})` })
|
|
161
|
+
});
|
|
162
|
+
const decode = (schema, what) => (value) => Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(() => new StackCommentError({ reason: `GitHub gave a bad ${what}` })));
|
|
163
|
+
const findComment = (token, path) => Effect.gen(function* () {
|
|
164
|
+
for (let page = 1;; page += 1) {
|
|
165
|
+
const comments = yield* github(token, `${path}?per_page=100&page=${page}`, { method: "GET" }).pipe(Effect.flatMap(decode(Comments, "comment list")));
|
|
166
|
+
const comment = comments.find(({ body }) => body.startsWith(MARKER));
|
|
167
|
+
if (comment !== void 0 || comments.length < 100) return comment;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
/** Replaces the body of the comment of this command, or posts it on the first run, and gives its URL. */
|
|
171
|
+
const saveStackComment = (args) => Effect.gen(function* () {
|
|
172
|
+
const { body, pullRequest, repository, token } = args;
|
|
173
|
+
const comments = `/repos/${repository}/issues/${pullRequest}/comments`;
|
|
174
|
+
const comment = yield* findComment(token, comments);
|
|
175
|
+
const reply = yield* comment === void 0 ? github(token, comments, {
|
|
176
|
+
method: "POST",
|
|
177
|
+
body: JSON.stringify({ body })
|
|
178
|
+
}) : github(token, `/repos/${repository}/issues/comments/${comment.id}`, {
|
|
179
|
+
method: "PATCH",
|
|
180
|
+
body: JSON.stringify({ body })
|
|
181
|
+
});
|
|
182
|
+
return (yield* decode(SavedComment, "comment")(reply)).html_url;
|
|
183
|
+
});
|
|
184
|
+
/** The step of a workflow: the run record names the repository and the pull request of the run. */
|
|
185
|
+
const updateStackComment = Effect.gen(function* () {
|
|
186
|
+
const { pullRequest, repository } = yield* runRecord({
|
|
187
|
+
cwd: process.cwd(),
|
|
188
|
+
env: process.env
|
|
189
|
+
});
|
|
190
|
+
if (pullRequest === null) return yield* new StackCommentError({ reason: "this run has no pull request" });
|
|
191
|
+
const token = process.env["GITHUB_TOKEN"];
|
|
192
|
+
if (token === void 0 || token === "") return yield* new StackCommentError({ reason: "GITHUB_TOKEN is not set" });
|
|
193
|
+
const cards = yield* readStackCards({
|
|
194
|
+
repository,
|
|
195
|
+
stage: `pr-${pullRequest}`
|
|
196
|
+
});
|
|
197
|
+
return yield* saveStackComment({
|
|
198
|
+
token,
|
|
199
|
+
repository,
|
|
200
|
+
pullRequest,
|
|
201
|
+
body: renderStackComment(cards, repository)
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
//#endregion
|
|
7
205
|
//#region src/cli.ts
|
|
8
206
|
const { positionals, values } = parseArgs({
|
|
9
207
|
allowPositionals: true,
|
|
@@ -14,16 +212,13 @@ const { positionals, values } = parseArgs({
|
|
|
14
212
|
}
|
|
15
213
|
});
|
|
16
214
|
const { team, app, "callback-path": callbackPath } = values;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const program = Effect.gen(function* () {
|
|
215
|
+
const USAGE = `Usage:
|
|
216
|
+
alchemy-convex hub-client --team <team> --app <app> --callback-path <path>
|
|
217
|
+
alchemy-convex stack-comment [--team <team>]`;
|
|
218
|
+
const hubClient = (hub) => Effect.gen(function* () {
|
|
22
219
|
const [command, ...prefix] = yield* installedCli(process.cwd());
|
|
23
220
|
const callbackUrl = yield* registerDevelopmentClient({
|
|
24
|
-
|
|
25
|
-
app,
|
|
26
|
-
callbackPath,
|
|
221
|
+
...hub,
|
|
27
222
|
convex: (args, input) => execFileSync(command, [...prefix, ...args], {
|
|
28
223
|
encoding: "utf8",
|
|
29
224
|
input,
|
|
@@ -36,6 +231,17 @@ const program = Effect.gen(function* () {
|
|
|
36
231
|
});
|
|
37
232
|
console.log(callbackUrl === void 0 ? "Hub client already registered." : `Hub client registered for ${callbackUrl}.`);
|
|
38
233
|
}).pipe(Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig()))));
|
|
234
|
+
const stackComment = (options) => updateStackComment.pipe(Effect.tap((url) => Effect.sync(() => console.log(url))), Effect.provide(state(options).pipe(Layer.provide(NodeServices.layer))));
|
|
235
|
+
const subcommand = positionals.join(" ");
|
|
236
|
+
const program = subcommand === "stack-comment" ? stackComment(team === void 0 ? {} : { team }) : subcommand === "hub-client" && team !== void 0 && app !== void 0 && callbackPath !== void 0 ? hubClient({
|
|
237
|
+
team,
|
|
238
|
+
app,
|
|
239
|
+
callbackPath
|
|
240
|
+
}) : void 0;
|
|
241
|
+
if (program === void 0) {
|
|
242
|
+
console.error(USAGE);
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
39
245
|
await Effect.runPromise(program).catch((error) => {
|
|
40
246
|
console.error(error instanceof Error ? error.message : String(error));
|
|
41
247
|
process.exit(1);
|
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n// The command of the package:\n//\n// alchemy-convex hub-client --team <team> --app <app> --callback-path <path>\n//\n// It runs in the directory of a Convex app, and gives the development deployment of that directory\n// a client of the identity hub of the team: see registerDevelopmentClient. It uses\n// CONVEX_ACCESS_TOKEN or the Convex CLI login.\nimport { execFileSync } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport { fromConfig } from \"./Credentials.ts\";\nimport { registerDevelopmentClient } from \"./HubClient.ts\";\nimport { ManagementApiLive } from \"./ManagementApi.ts\";\nimport { installedCli } from \"./Push.ts\";\n\nconst { positionals, values } = parseArgs({\n allowPositionals: true,\n options: {\n team: { type: \"string\" },\n app: { type: \"string\" },\n \"callback-path\": { type: \"string\" },\n },\n});\nconst { team, app, \"callback-path\": callbackPath } = values;\nif (\n positionals.join(\" \") !== \"hub-client\" ||\n team === undefined ||\n app === undefined ||\n callbackPath === undefined\n) {\n console.error(\n \"Usage: alchemy-convex hub-client --team <team> --app <app> --callback-path <path>\",\n );\n process.exit(1);\n}\n\nconst program = Effect.gen(function* () {\n const [command, ...prefix] = yield* installedCli(process.cwd());\n const callbackUrl = yield* registerDevelopmentClient({\n team,\n app,\n callbackPath,\n convex: (args, input) =>\n execFileSync(command, [...prefix, ...args], {\n encoding: \"utf8\",\n input,\n stdio: [\"pipe\", \"pipe\", \"inherit\"],\n }).trim(),\n });\n console.log(\n callbackUrl === undefined\n ? \"Hub client already registered.\"\n : `Hub client registered for ${callbackUrl}.`,\n );\n}).pipe(Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig()))));\n\nawait Effect.runPromise(program).catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;;AAiBA,MAAM,EAAE,aAAa,WAAW,UAAU;CACxC,kBAAkB;CAClB,SAAS;EACP,MAAM,EAAE,MAAM,SAAS;EACvB,KAAK,EAAE,MAAM,SAAS;EACtB,iBAAiB,EAAE,MAAM,SAAS;CACpC;AACF,CAAC;AACD,MAAM,EAAE,MAAM,KAAK,iBAAiB,iBAAiB;AACrD,IACE,YAAY,KAAK,GAAG,MAAM,gBAC1B,SAAS,KAAA,KACT,QAAQ,KAAA,KACR,iBAAiB,KAAA,GACjB;CACA,QAAQ,MACN,mFACF;CACA,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,UAAU,OAAO,IAAI,aAAa;CACtC,MAAM,CAAC,SAAS,GAAG,UAAU,OAAO,aAAa,QAAQ,IAAI,CAAC;CAC9D,MAAM,cAAc,OAAO,0BAA0B;EACnD;EACA;EACA;EACA,SAAS,MAAM,UACb,aAAa,SAAS,CAAC,GAAG,QAAQ,GAAG,IAAI,GAAG;GAC1C,UAAU;GACV;GACA,OAAO;IAAC;IAAQ;IAAQ;GAAS;EACnC,CAAC,CAAC,CAAC,KAAK;CACZ,CAAC;CACD,QAAQ,IACN,gBAAgB,KAAA,IACZ,mCACA,6BAA6B,YAAY,EAC/C;AACF,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,kBAAkB,CAAC,CAAC,KAAK,MAAM,QAAQ,WAAW,CAAC,CAAC,CAAC,CAAC;AAE7E,MAAM,OAAO,WAAW,OAAO,CAAC,CAAC,OAAO,UAAmB;CACzD,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/StackComment.ts","../src/cli.ts"],"sourcesContent":["// The command `alchemy-convex stack-comment`: one comment on a pull request with the stacks of the\n// repository, read from the state store after the deploys.\n//\n// A stack sees only itself, so a comment that a stack declares cannot show the other stacks of the\n// repository. This command runs as a step after them and reads each stack named `owner/name` or\n// `owner/name/<folder>` that has the stage `pr-<number>`. A stack without that stage has no card. A\n// run replaces the whole body, so the last run shows the newest state.\n//\n// It reads only the fields of the rows below, because Alchemy state holds secrets in clear text.\n//\n// GitHub keeps a fixed set of HTML in a comment and removes `style` and `class`, so every choice of\n// the markup is a fact about the sanitizer or the CSS of github.com:\n// - A table has `display: block` and `width: max-content`, so a `width` on it does nothing. The\n// spacer, a floated image one pixel high in a block of its own, gives every card one width, and\n// it shrinks on a narrow page.\n// - The CSS colors the even rows of a group, so each row has its own `tbody`.\n// - An HTML block ends at a blank line, so a table has none and is not indented.\n// - A bare image links to its raw file, and one link around an image and text underlines the space\n// between them, so the icon and the name are two links to one place.\n// - An image with `height` gets a gray background, so each icon is square and has only `width`.\n// - `align=\"middle\"` is `-webkit-baseline-middle` in Chrome, which is below the text.\n// `align=\"absmiddle\"` is the CSS value `middle`.\nimport { State } from \"alchemy/State\";\nimport * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\nimport { RUN_RECORD_KEY, runRecord } from \"./RunRecord.ts\";\n\n/** The first text of the comment, which finds it again. */\nconst MARKER = \"<!-- samebase-stacks -->\";\n\n/** GitHub does not proxy this host, so a new icon needs no purge of its image cache. */\nconst ICONS = \"https://raw.githubusercontent.com/samebase/alchemy-convex/main/assets/stack-comment\";\n\nconst GITHUB_API = \"https://api.github.com\";\n\n/** The resources that a card shows. A row of any other type, or without `attr` from an interrupted deploy, is left out. */\nconst Resource = Schema.Union([\n Schema.Struct({\n resourceType: Schema.Literal(\"Convex.Deployment\"),\n attr: Schema.Struct({ name: Schema.String, siteUrl: Schema.String }),\n }),\n Schema.Struct({\n resourceType: Schema.Literal(\"Cloudflare.Worker\"),\n attr: Schema.Struct({ workerName: Schema.String, url: Schema.optional(Schema.String) }),\n }),\n Schema.Struct({\n resourceType: Schema.Literal(\"Cloudflare.R2.Bucket\"),\n attr: Schema.Struct({\n bucketName: Schema.String,\n accountId: Schema.String,\n jurisdiction: Schema.String,\n }),\n }),\n]);\ntype Resource = typeof Resource.Type;\n\n/** The fields of the run record that a card shows. */\nconst StageOutput = Schema.Struct({\n [RUN_RECORD_KEY]: Schema.Struct({\n headCommit: Schema.String,\n runUrl: Schema.NullOr(Schema.String),\n recordedAt: Schema.String,\n }),\n});\n\nexport interface StackCard {\n readonly name: string;\n readonly stage: string;\n readonly resources: readonly Resource[];\n readonly run: typeof StageOutput.Type | null;\n}\n\nexport class StackCommentError extends Schema.TaggedError<StackCommentError>()(\n \"StackCommentError\",\n { reason: Schema.String },\n) {\n override get message() {\n return `The stack comment cannot be updated: ${this.reason}`;\n }\n}\n\n/** The cards of the stacks of `repository` that have `stage`, in name order. */\nexport const readStackCards = ({ repository, stage }: { repository: string; stage: string }) =>\n Effect.gen(function* () {\n const state = yield* yield* State;\n const names = (yield* state.listStacks()).filter(\n (name) => name === repository || name.startsWith(`${repository}/`),\n );\n const cards: StackCard[] = [];\n for (const name of names) {\n if (!(yield* state.listStages(name)).includes(stage)) {\n continue;\n }\n const request = { stack: name, stage };\n const rows = yield* Effect.forEach(yield* state.list(request), (fqn) =>\n state.get({ ...request, fqn }),\n );\n const output = yield* state.getOutput(request);\n cards.push({\n name,\n stage,\n resources: rows.filter(Schema.is(Resource)),\n run: Schema.is(StageOutput)(output) ? output : null,\n });\n }\n return cards;\n });\n\n/** A stack can create a deployment in one resource and push to it in another: a card shows it once. */\nconst withoutRepeats = (resources: readonly Resource[]) => {\n const deployments = new Set<string>();\n return resources.filter((resource) => {\n if (resource.resourceType !== \"Convex.Deployment\") {\n return true;\n }\n const repeated = deployments.has(resource.attr.name);\n deployments.add(resource.attr.name);\n return !repeated;\n });\n};\n\nconst escapeHtml = (text: string) =>\n text\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\");\n\nconst link = (href: string, text: string) => `<a href=\"${escapeHtml(href)}\">${text}</a>`;\n\nconst named = (href: string, icon: string, alt: string, name: string) => {\n const image = `<img src=\"${ICONS}/${icon}.svg\" width=\"16\" align=\"absmiddle\" alt=\"${alt}\">`;\n return `${link(href, image)} ${link(href, escapeHtml(name))}`;\n};\n\nconst hostOf = (url: string) => escapeHtml(new URL(url).host);\n\n/** Where a stack serves: its Convex deployment, else its first Worker with a URL. */\nconst addressOf = (resources: readonly Resource[]) => {\n for (const resource of resources) {\n if (resource.resourceType === \"Convex.Deployment\") {\n return resource.attr.siteUrl;\n }\n }\n for (const resource of resources) {\n if (resource.resourceType === \"Cloudflare.Worker\" && resource.attr.url !== undefined) {\n return resource.attr.url;\n }\n }\n return null;\n};\n\nconst resourceRow = (resource: Resource, address: string | null) => {\n switch (resource.resourceType) {\n case \"Convex.Deployment\": {\n const { name } = resource.attr;\n return named(\n `https://dashboard.convex.dev/d/${encodeURIComponent(name)}`,\n \"convex\",\n \"Convex\",\n name,\n );\n }\n case \"Cloudflare.Worker\": {\n const { url, workerName } = resource.attr;\n const row = named(\n `https://dash.cloudflare.com/?to=/:account/workers/services/view/${encodeURIComponent(workerName)}`,\n \"worker\",\n \"Worker\",\n workerName,\n );\n return url === undefined || url === address\n ? row\n : `${row}<br><sub>${link(url, hostOf(url))}</sub>`;\n }\n case \"Cloudflare.R2.Bucket\": {\n const { accountId, bucketName, jurisdiction } = resource.attr;\n return named(\n `https://dash.cloudflare.com/${encodeURIComponent(accountId)}/r2/${encodeURIComponent(jurisdiction)}/buckets/${encodeURIComponent(bucketName)}`,\n \"r2\",\n \"R2 bucket\",\n bucketName,\n );\n }\n }\n};\n\nconst runLine = ({ run }: StackCard) => {\n if (run === null) {\n return \"\";\n }\n const { headCommit, recordedAt, runUrl } = run[RUN_RECORD_KEY];\n const commit = escapeHtml(headCommit.slice(0, 7));\n const time = `${recordedAt.slice(0, 16).replace(\"T\", \" \")} UTC`;\n return `<br><sub>${runUrl === null ? commit : link(runUrl, commit)} ${escapeHtml(time)}</sub>`;\n};\n\nconst SPACER = `<div><img src=\"${ICONS}/spacer.svg\" width=\"460\" align=\"left\" alt=\"\"></div>`;\n\n/** `alone`: the one card of the repository. A card at the root then has no folder, as on the repository page. */\nconst renderCard = (card: StackCard, repository: string, alone: boolean) => {\n const folder = card.name.slice(repository.length + 1);\n const heading = [\n folder === \"\" && alone ? \"\" : `<b>${escapeHtml(folder || \"/\")}</b> `,\n `<sub>${escapeHtml(card.stage)}</sub>`,\n ].join(\"\");\n const resources = withoutRepeats(card.resources);\n const address = addressOf(resources);\n const addressLine = address === null ? \"\" : `<br>${link(address, hostOf(address))}`;\n const rows = resources\n .map((resource) => `<tbody><tr><td>${resourceRow(resource, address)}</td></tr></tbody>`)\n .join(\"\\n\");\n return `<table>\n<tbody><tr><td>${SPACER}${heading}${addressLine}${runLine(card)}</td></tr></tbody>\n${rows}\n</table>`;\n};\n\nexport const renderStackComment = (cards: readonly StackCard[], repository: string) => `${MARKER}\n${cards.map((card) => renderCard(card, repository, cards.length === 1)).join(\"\\n\\n\")}\n`;\n\nconst Comments = Schema.Array(Schema.Struct({ id: Schema.Number, body: Schema.String }));\nconst SavedComment = Schema.Struct({ html_url: Schema.String });\n\nconst github = (token: string, path: string, init: { method: string; body?: string }) =>\n Effect.tryPromise({\n try: async (): Promise<unknown> => {\n const response = await fetch(`${GITHUB_API}${path}`, {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n },\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n return await response.json();\n },\n catch: (error) =>\n new StackCommentError({\n reason: `GitHub ${init.method} ${path} failed (${error instanceof Error ? error.message : String(error)})`,\n }),\n });\n\nconst decode =\n <S extends Schema.Codec<unknown, unknown>>(schema: S, what: string) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => new StackCommentError({ reason: `GitHub gave a bad ${what}` })),\n );\n\nconst findComment = (token: string, path: string) =>\n Effect.gen(function* () {\n for (let page = 1; ; page += 1) {\n const comments = yield* github(token, `${path}?per_page=100&page=${page}`, {\n method: \"GET\",\n }).pipe(Effect.flatMap(decode(Comments, \"comment list\")));\n const comment = comments.find(({ body }) => body.startsWith(MARKER));\n if (comment !== undefined || comments.length < 100) {\n return comment;\n }\n }\n });\n\n/** Replaces the body of the comment of this command, or posts it on the first run, and gives its URL. */\nexport const saveStackComment = (args: {\n readonly token: string;\n readonly repository: string;\n readonly pullRequest: number;\n readonly body: string;\n}) =>\n Effect.gen(function* () {\n const { body, pullRequest, repository, token } = args;\n const comments = `/repos/${repository}/issues/${pullRequest}/comments`;\n const comment = yield* findComment(token, comments);\n const reply = yield* comment === undefined\n ? github(token, comments, { method: \"POST\", body: JSON.stringify({ body }) })\n : github(token, `/repos/${repository}/issues/comments/${comment.id}`, {\n method: \"PATCH\",\n body: JSON.stringify({ body }),\n });\n const saved = yield* decode(SavedComment, \"comment\")(reply);\n return saved.html_url;\n });\n\n/** The step of a workflow: the run record names the repository and the pull request of the run. */\nexport const updateStackComment = Effect.gen(function* () {\n const { pullRequest, repository } = yield* runRecord({ cwd: process.cwd(), env: process.env });\n if (pullRequest === null) {\n return yield* new StackCommentError({ reason: \"this run has no pull request\" });\n }\n const token = process.env[\"GITHUB_TOKEN\"];\n if (token === undefined || token === \"\") {\n return yield* new StackCommentError({ reason: \"GITHUB_TOKEN is not set\" });\n }\n const cards = yield* readStackCards({ repository, stage: `pr-${pullRequest}` });\n return yield* saveStackComment({\n token,\n repository,\n pullRequest,\n body: renderStackComment(cards, repository),\n });\n});\n","#!/usr/bin/env node\n// The commands of the package:\n//\n// alchemy-convex hub-client --team <team> --app <app> --callback-path <path>\n// alchemy-convex stack-comment [--team <team>]\n//\n// hub-client runs in the directory of a Convex app, and gives the development deployment of that\n// directory a client of the identity hub of the team: see registerDevelopmentClient. stack-comment\n// runs as a step of a pull request workflow after the deploys, and keeps one comment with the stacks\n// of the repository: see src/StackComment.ts. It needs GITHUB_TOKEN and, with a team access token,\n// no --team. Both use CONVEX_ACCESS_TOKEN or the Convex CLI login.\nimport { execFileSync } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport * as NodeServices from \"@effect/platform-node/NodeServices\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport { fromConfig } from \"./Credentials.ts\";\nimport { registerDevelopmentClient } from \"./HubClient.ts\";\nimport { ManagementApiLive } from \"./ManagementApi.ts\";\nimport { installedCli } from \"./Push.ts\";\nimport { updateStackComment } from \"./StackComment.ts\";\nimport { state } from \"./State.ts\";\n\nconst { positionals, values } = parseArgs({\n allowPositionals: true,\n options: {\n team: { type: \"string\" },\n app: { type: \"string\" },\n \"callback-path\": { type: \"string\" },\n },\n});\nconst { team, app, \"callback-path\": callbackPath } = values;\nconst USAGE = `Usage:\n alchemy-convex hub-client --team <team> --app <app> --callback-path <path>\n alchemy-convex stack-comment [--team <team>]`;\n\nconst hubClient = (hub: { team: string; app: string; callbackPath: string }) =>\n Effect.gen(function* () {\n const [command, ...prefix] = yield* installedCli(process.cwd());\n const callbackUrl = yield* registerDevelopmentClient({\n ...hub,\n convex: (args, input) =>\n execFileSync(command, [...prefix, ...args], {\n encoding: \"utf8\",\n input,\n stdio: [\"pipe\", \"pipe\", \"inherit\"],\n }).trim(),\n });\n console.log(\n callbackUrl === undefined\n ? \"Hub client already registered.\"\n : `Hub client registered for ${callbackUrl}.`,\n );\n }).pipe(Effect.provide(ManagementApiLive().pipe(Layer.provide(fromConfig()))));\n\nconst stackComment = (options: { team?: string }) =>\n updateStackComment.pipe(\n Effect.tap((url) => Effect.sync(() => console.log(url))),\n Effect.provide(state(options).pipe(Layer.provide(NodeServices.layer))),\n );\n\nconst subcommand = positionals.join(\" \");\nconst program: Effect.Effect<unknown, unknown> | undefined =\n subcommand === \"stack-comment\"\n ? stackComment(team === undefined ? {} : { team })\n : subcommand === \"hub-client\" &&\n team !== undefined &&\n app !== undefined &&\n callbackPath !== undefined\n ? hubClient({ team, app, callbackPath })\n : undefined;\nif (program === undefined) {\n console.error(USAGE);\n process.exit(1);\n}\n\nawait Effect.runPromise(program).catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,SAAS;;AAGf,MAAM,QAAQ;AAEd,MAAM,aAAa;;AAGnB,MAAM,WAAW,OAAO,MAAM;CAC5B,OAAO,OAAO;EACZ,cAAc,OAAO,QAAQ,mBAAmB;EAChD,MAAM,OAAO,OAAO;GAAE,MAAM,OAAO;GAAQ,SAAS,OAAO;EAAO,CAAC;CACrE,CAAC;CACD,OAAO,OAAO;EACZ,cAAc,OAAO,QAAQ,mBAAmB;EAChD,MAAM,OAAO,OAAO;GAAE,YAAY,OAAO;GAAQ,KAAK,OAAO,SAAS,OAAO,MAAM;EAAE,CAAC;CACxF,CAAC;CACD,OAAO,OAAO;EACZ,cAAc,OAAO,QAAQ,sBAAsB;EACnD,MAAM,OAAO,OAAO;GAClB,YAAY,OAAO;GACnB,WAAW,OAAO;GAClB,cAAc,OAAO;EACvB,CAAC;CACH,CAAC;AACH,CAAC;;AAID,MAAM,cAAc,OAAO,OAAO,GAC/B,iBAAiB,OAAO,OAAO;CAC9B,YAAY,OAAO;CACnB,QAAQ,OAAO,OAAO,OAAO,MAAM;CACnC,YAAY,OAAO;AACrB,CAAC,EACH,CAAC;AASD,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA,EAAE,QAAQ,OAAO,OAAO,CAC1B,CAAC,CAAC;CACA,IAAa,UAAU;EACrB,OAAO,wCAAwC,KAAK;CACtD;AACF;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AACF,CAAC,CAAC,CAAC,KAAK,OAAO,QAAQ,kBAAkB,CAAC,CAAC,KAAK,MAAM,QAAQ,WAAW,CAAC,CAAC,CAAC,CAAC;AAE/E,MAAM,gBAAgB,YACpB,mBAAmB,KACjB,OAAO,KAAK,QAAQ,OAAO,WAAW,QAAQ,IAAI,GAAG,CAAC,CAAC,GACvD,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,MAAM,QAAQ,aAAa,KAAK,CAAC,CAAC,CACvE;AAEF,MAAM,aAAa,YAAY,KAAK,GAAG;AACvC,MAAM,UACJ,eAAe,kBACX,aAAa,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK,CAAC,IAC/C,eAAe,gBACb,SAAS,KAAA,KACT,QAAQ,KAAA,KACR,iBAAiB,KAAA,IACjB,UAAU;CAAE;CAAM;CAAK;AAAa,CAAC,IACrC,KAAA;AACR,IAAI,YAAY,KAAA,GAAW;CACzB,QAAQ,MAAM,KAAK;CACnB,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,OAAO,WAAW,OAAO,CAAC,CAAC,OAAO,UAAmB;CACzD,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -409,10 +409,10 @@ export declare class ProjectNotFound extends ProjectNotFound_base {
|
|
|
409
409
|
//#endregion
|
|
410
410
|
//#region src/HubClient.d.ts
|
|
411
411
|
/** The name of the project of the hub in each team. */
|
|
412
|
-
export declare const HUB_PROJECT_NAME = "
|
|
412
|
+
export declare const HUB_PROJECT_NAME = "identity-hub";
|
|
413
413
|
type HubDeploymentType = "production" | "development" | "preview";
|
|
414
414
|
interface HubClientProps {
|
|
415
|
-
/** The Convex team, a slug or an id, whose project `
|
|
415
|
+
/** The Convex team, a slug or an id, whose project `identity-hub` holds the hub. */
|
|
416
416
|
readonly team: string | number;
|
|
417
417
|
/** The app on the hub, such as `scout`. The first client of an app creates it, as a first-party app. */
|
|
418
418
|
readonly app: string;
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as PushTargetMismatch, B as DEPLOY_KEY_ENV, C as DeploymentProvider, D as ConvexAppNotFound, E as CodePushFailed, F as ManagementApi, H as fromValues, I as ManagementApiLive, L as ACCESS_TOKEN_ENV, N as parseDeployOutput, O as ConvexCliNotFound, P as ConvexApiError, R as Credentials, S as DeploymentIdentityChange, T as ProductionDeploymentNotFound, V as fromConfig, _ as ProjectProvider, b as AmbiguousDeployment, c as RUN_RECORD_KEY, d as withRunRecord, f as AmbiguousProject, g as ProjectNotFound, h as ProjectDeploymentChange, i as HubClientProvider, j as VariablesOwnedBySomeoneElse, k as EnvironmentNeedsDeployKey, l as RunRecordError, m as Project, n as HubClient, o as STORE_PROJECT_NAME, p as CreatedProjectNotFound, r as HubClientFailed, s as state, t as HUB_PROJECT_NAME, u as runRecord, v as ProjectTeamChange, w as DeploymentResource, x as Deployment, y as AbsoluteRootDir, z as CredentialsError } from "./HubClient-
|
|
1
|
+
import { A as PushTargetMismatch, B as DEPLOY_KEY_ENV, C as DeploymentProvider, D as ConvexAppNotFound, E as CodePushFailed, F as ManagementApi, H as fromValues, I as ManagementApiLive, L as ACCESS_TOKEN_ENV, N as parseDeployOutput, O as ConvexCliNotFound, P as ConvexApiError, R as Credentials, S as DeploymentIdentityChange, T as ProductionDeploymentNotFound, V as fromConfig, _ as ProjectProvider, b as AmbiguousDeployment, c as RUN_RECORD_KEY, d as withRunRecord, f as AmbiguousProject, g as ProjectNotFound, h as ProjectDeploymentChange, i as HubClientProvider, j as VariablesOwnedBySomeoneElse, k as EnvironmentNeedsDeployKey, l as RunRecordError, m as Project, n as HubClient, o as STORE_PROJECT_NAME, p as CreatedProjectNotFound, r as HubClientFailed, s as state, t as HUB_PROJECT_NAME, u as runRecord, v as ProjectTeamChange, w as DeploymentResource, x as Deployment, y as AbsoluteRootDir, z as CredentialsError } from "./HubClient-BZKweNfD.js";
|
|
2
2
|
import { toPath } from "alchemy/FQN";
|
|
3
3
|
import { Stack } from "alchemy/Stack";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
package/package.json
CHANGED
package/src/HubClient.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Convex.HubClient: one deployment of an app as a client of the identity hub
|
|
2
2
|
// of its team.
|
|
3
3
|
//
|
|
4
|
-
// The hub is the production deployment of the project `
|
|
4
|
+
// The hub is the production deployment of the project `identity-hub` of the team.
|
|
5
5
|
// It has the internal functions of `@samebase/identity-broker` in its module
|
|
6
6
|
// `identityBroker`. This resource finds the project by name and runs those
|
|
7
7
|
// functions with a short-lived key, so a stack that has the Convex credential
|
|
@@ -26,12 +26,12 @@ import { withPushKey } from "./Push.ts";
|
|
|
26
26
|
import { type FunctionApi, makeFunctionApi, RUN_KEY_ACTIONS } from "./State.ts";
|
|
27
27
|
|
|
28
28
|
/** The name of the project of the hub in each team. */
|
|
29
|
-
export const HUB_PROJECT_NAME = "
|
|
29
|
+
export const HUB_PROJECT_NAME = "identity-hub";
|
|
30
30
|
|
|
31
31
|
export type HubDeploymentType = "production" | "development" | "preview";
|
|
32
32
|
|
|
33
33
|
export interface HubClientProps {
|
|
34
|
-
/** The Convex team, a slug or an id, whose project `
|
|
34
|
+
/** The Convex team, a slug or an id, whose project `identity-hub` holds the hub. */
|
|
35
35
|
readonly team: string | number;
|
|
36
36
|
/** The app on the hub, such as `scout`. The first client of an app creates it, as a first-party app. */
|
|
37
37
|
readonly app: string;
|