@marlinjai/clearify 1.18.0 → 1.19.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.
@@ -282,7 +282,7 @@ ${hasInternal ? `
282
282
  `);
283
283
  const secretMode = options.secretMode ?? "prompt";
284
284
  if (options.hub) {
285
- const { registerWithHub } = await import("./hub-register-VJBXLOKV.js");
285
+ const { registerWithHub } = await import("./hub-register-M7C3G3FE.js");
286
286
  await registerWithHub({
287
287
  projectName: detectProjectName(),
288
288
  hubToken: options.hubToken,
@@ -298,7 +298,7 @@ ${hasInternal ? `
298
298
  });
299
299
  rl.close();
300
300
  if (answer.toLowerCase() === "y") {
301
- const { registerWithHub } = await import("./hub-register-VJBXLOKV.js");
301
+ const { registerWithHub } = await import("./hub-register-M7C3G3FE.js");
302
302
  await registerWithHub({
303
303
  projectName: detectProjectName(),
304
304
  hubToken: options.hubToken,
@@ -39,6 +39,80 @@ async function ghApiFetch(url, options = {}) {
39
39
  const data = await res.json().catch(() => null);
40
40
  return { status: res.status, data };
41
41
  }
42
+ async function encryptSecret(plaintext, publicKey) {
43
+ const sodium = (await import("libsodium-wrappers")).default;
44
+ await sodium.ready;
45
+ const keyBytes = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
46
+ const messageBytes = sodium.from_string(plaintext);
47
+ const sealed = sodium.crypto_box_seal(messageBytes, keyBytes);
48
+ return sodium.to_base64(sealed, sodium.base64_variants.ORIGINAL);
49
+ }
50
+ async function getRepoPublicKey(token, owner, repo) {
51
+ const url = `https://api.github.com/repos/${owner}/${repo}/actions/secrets/public-key`;
52
+ const res = await ghApiFetch(url, {
53
+ headers: { Authorization: `token ${token}` }
54
+ });
55
+ if (res.status !== 200 || !res.data?.key || !res.data?.key_id) {
56
+ throw new Error(
57
+ `Failed to fetch public key for ${owner}/${repo}: ${res.status} ${JSON.stringify(res.data)}`
58
+ );
59
+ }
60
+ return { key_id: res.data.key_id, key: res.data.key };
61
+ }
62
+ async function storeDispatchToken(token, owner, repo, secretValue) {
63
+ const { key_id, key } = await getRepoPublicKey(token, owner, repo);
64
+ const encrypted_value = await encryptSecret(secretValue, key);
65
+ const url = `https://api.github.com/repos/${owner}/${repo}/actions/secrets/HUB_DISPATCH_TOKEN`;
66
+ const res = await ghApiFetch(url, {
67
+ method: "PUT",
68
+ headers: { Authorization: `token ${token}` },
69
+ body: JSON.stringify({ encrypted_value, key_id })
70
+ });
71
+ if (res.status !== 201 && res.status !== 204) {
72
+ throw new Error(
73
+ `Failed to write HUB_DISPATCH_TOKEN on ${owner}/${repo}: ${res.status} ${JSON.stringify(res.data)}`
74
+ );
75
+ }
76
+ }
77
+ async function secretExists(token, owner, repo, name) {
78
+ const url = `https://api.github.com/repos/${owner}/${repo}/actions/secrets/${name}`;
79
+ const res = await ghApiFetch(url, { headers: { Authorization: `token ${token}` } });
80
+ return res.status === 200;
81
+ }
82
+ async function promptSecretMode() {
83
+ const { createInterface } = await import("readline");
84
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
85
+ console.log("\n How would you like to provision HUB_DISPATCH_TOKEN on this sub-repo?");
86
+ console.log(" 1) auto paste a PAT now, Clearify encrypts and PUTs it via the Secrets API");
87
+ console.log(" 2) manual print instructions for the GitHub UI (I will paste it myself)");
88
+ console.log(" 3) skip leave it alone (I manage it via Terraform)\n");
89
+ const answer = await new Promise((res) => {
90
+ rl.question(" Choose [1/2/3] (default: 2): ", res);
91
+ });
92
+ rl.close();
93
+ const trimmed = answer.trim();
94
+ if (trimmed === "1" || trimmed.toLowerCase() === "auto") return "auto";
95
+ if (trimmed === "3" || trimmed.toLowerCase() === "skip") return "skip";
96
+ return "manual";
97
+ }
98
+ async function promptHiddenInput(prompt) {
99
+ const password = (await import("@inquirer/password")).default;
100
+ const value = await password({ message: prompt, mask: "*" });
101
+ if (!value) {
102
+ throw new Error("Empty input; aborting.");
103
+ }
104
+ return value;
105
+ }
106
+ function printManualSecretInstructions(subRepo, hub) {
107
+ const url = `https://github.com/${subRepo.owner}/${subRepo.repo}/settings/secrets/actions/new`;
108
+ console.log("\n Manual secret provisioning");
109
+ console.log(` 1. Open: ${url}`);
110
+ console.log(" 2. Secret name: HUB_DISPATCH_TOKEN");
111
+ console.log(
112
+ ` 3. Value: a fine-grained PAT with "Contents: Read and Write" scope on ${hub.owner}/${hub.repo}, 90-day expiry.`
113
+ );
114
+ console.log(" 4. Save and push a doc change to verify the dispatch fires.\n");
115
+ }
42
116
  async function githubDeviceAuth(clientId) {
43
117
  const codeRes = await fetch("https://github.com/login/device/code", {
44
118
  method: "POST",
@@ -267,14 +341,46 @@ async function registerWithHub(options) {
267
341
  console.log(" Generating local files...");
268
342
  generateConfig(projectName, options.hubProject);
269
343
  generateWorkflow(hub);
344
+ if (options.secretMode !== "skip") {
345
+ const mode = options.secretMode === "prompt" || options.secretMode === void 0 ? await promptSecretMode() : options.secretMode;
346
+ if (mode === "auto") {
347
+ if (!options.rotateSecret) {
348
+ const exists = await secretExists(
349
+ token,
350
+ currentRepo.owner,
351
+ currentRepo.repo,
352
+ "HUB_DISPATCH_TOKEN"
353
+ );
354
+ if (exists) {
355
+ console.log(
356
+ " HUB_DISPATCH_TOKEN already exists on this sub-repo; pass --rotate-secret to overwrite"
357
+ );
358
+ printSuccessFooter(currentRepo);
359
+ return;
360
+ }
361
+ }
362
+ const secretValue = options.secretPat ?? options.hubToken ?? await promptHiddenInput("Paste the PAT to store as HUB_DISPATCH_TOKEN: ");
363
+ try {
364
+ await storeDispatchToken(token, currentRepo.owner, currentRepo.repo, secretValue);
365
+ console.log(" HUB_DISPATCH_TOKEN written to sub-repo");
366
+ } catch (err) {
367
+ console.warn(` Could not write secret: ${err.message}`);
368
+ printManualSecretInstructions(currentRepo, hub);
369
+ }
370
+ } else if (mode === "manual") {
371
+ printManualSecretInstructions(currentRepo, hub);
372
+ }
373
+ }
374
+ printSuccessFooter(currentRepo);
375
+ }
376
+ function printSuccessFooter(currentRepo) {
270
377
  console.log(`
271
378
  Hub registration complete!
272
379
 
273
380
  Next steps:
274
381
  1. Review clearify.config.ts and update the hubProject description
275
- 2. Add "${currentRepo.repo}" to the repos list in infra/deployments/hub-dispatch/github.tf
276
- 3. Run: cd infra/deployments/hub-dispatch && ../../scripts/tfrun.sh apply
277
- 4. Commit the generated files and push to main
382
+ 2. If you manage HUB_DISPATCH_TOKEN via Terraform, add "${currentRepo.repo}" to the repos list in infra/deployments/hub-dispatch/github.tf and apply
383
+ 3. Commit the generated files and push to main
278
384
  `);
279
385
  }
280
386
  export {
@@ -11,7 +11,7 @@ import {
11
11
  import "../chunk-B2Q23JW3.js";
12
12
  import {
13
13
  init
14
- } from "../chunk-7Z2GR22P.js";
14
+ } from "../chunk-HVHCUAVU.js";
15
15
  import {
16
16
  checkFrontmatter,
17
17
  checkLinks
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  init
3
- } from "../chunk-7Z2GR22P.js";
3
+ } from "../chunk-HVHCUAVU.js";
4
4
  export {
5
5
  init
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marlinjai/clearify",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "An open-source documentation site generator. Turn markdown into beautiful docs.",
5
5
  "type": "module",
6
6
  "bin": {