@mp-lb/arcnet 0.1.0 → 0.2.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 (78) hide show
  1. package/README.md +33 -4
  2. package/dist/createCli.d.ts.map +1 -1
  3. package/dist/createCli.js +12 -5
  4. package/dist/createCli.js.map +1 -1
  5. package/dist/secrets/assertNewSource.d.ts +3 -0
  6. package/dist/secrets/assertNewSource.d.ts.map +1 -0
  7. package/dist/secrets/assertNewSource.js +32 -0
  8. package/dist/secrets/assertNewSource.js.map +1 -0
  9. package/dist/secrets/config.d.ts +37 -0
  10. package/dist/secrets/config.d.ts.map +1 -0
  11. package/dist/secrets/config.js +67 -0
  12. package/dist/secrets/config.js.map +1 -0
  13. package/dist/secrets/createSecretsCommands.d.ts +3 -0
  14. package/dist/secrets/createSecretsCommands.d.ts.map +1 -0
  15. package/dist/secrets/createSecretsCommands.js +93 -0
  16. package/dist/secrets/createSecretsCommands.js.map +1 -0
  17. package/dist/secrets/loadSecrets.d.ts +3 -0
  18. package/dist/secrets/loadSecrets.d.ts.map +1 -0
  19. package/dist/secrets/loadSecrets.js +35 -0
  20. package/dist/secrets/loadSecrets.js.map +1 -0
  21. package/dist/secrets/promptPassword.d.ts +2 -0
  22. package/dist/secrets/promptPassword.d.ts.map +1 -0
  23. package/dist/secrets/promptPassword.js +42 -0
  24. package/dist/secrets/promptPassword.js.map +1 -0
  25. package/dist/secrets/provisionSource.d.ts +25 -0
  26. package/dist/secrets/provisionSource.d.ts.map +1 -0
  27. package/dist/secrets/provisionSource.js +141 -0
  28. package/dist/secrets/provisionSource.js.map +1 -0
  29. package/dist/secrets/readRemoteSource.d.ts +7 -0
  30. package/dist/secrets/readRemoteSource.d.ts.map +1 -0
  31. package/dist/secrets/readRemoteSource.js +32 -0
  32. package/dist/secrets/readRemoteSource.js.map +1 -0
  33. package/dist/secrets/runWithSecrets.d.ts +6 -0
  34. package/dist/secrets/runWithSecrets.d.ts.map +1 -0
  35. package/dist/secrets/runWithSecrets.js +59 -0
  36. package/dist/secrets/runWithSecrets.js.map +1 -0
  37. package/dist/secrets/secretCommand.d.ts +2 -0
  38. package/dist/secrets/secretCommand.d.ts.map +1 -0
  39. package/dist/secrets/secretCommand.js +17 -0
  40. package/dist/secrets/secretCommand.js.map +1 -0
  41. package/dist/secrets/selectSecrets.d.ts +3 -0
  42. package/dist/secrets/selectSecrets.d.ts.map +1 -0
  43. package/dist/secrets/selectSecrets.js +18 -0
  44. package/dist/secrets/selectSecrets.js.map +1 -0
  45. package/dist/secrets/syncSecrets.d.ts +10 -0
  46. package/dist/secrets/syncSecrets.d.ts.map +1 -0
  47. package/dist/secrets/syncSecrets.js +43 -0
  48. package/dist/secrets/syncSecrets.js.map +1 -0
  49. package/dist/secrets/wireSecretsWorkflows.d.ts +2 -0
  50. package/dist/secrets/wireSecretsWorkflows.d.ts.map +1 -0
  51. package/dist/secrets/wireSecretsWorkflows.js +48 -0
  52. package/dist/secrets/wireSecretsWorkflows.js.map +1 -0
  53. package/dist/secrets/withDeploymentSecrets.d.ts +2 -0
  54. package/dist/secrets/withDeploymentSecrets.d.ts.map +1 -0
  55. package/dist/secrets/withDeploymentSecrets.js +58 -0
  56. package/dist/secrets/withDeploymentSecrets.js.map +1 -0
  57. package/dist/secrets/writeSecretsWorkflow.d.ts +3 -0
  58. package/dist/secrets/writeSecretsWorkflow.d.ts.map +1 -0
  59. package/dist/secrets/writeSecretsWorkflow.js +60 -0
  60. package/dist/secrets/writeSecretsWorkflow.js.map +1 -0
  61. package/docs/public/commands.md +74 -0
  62. package/docs/public/llms-full.txt +107 -4
  63. package/package.json +2 -1
  64. package/src/createCli.ts +18 -8
  65. package/src/secrets/assertNewSource.ts +40 -0
  66. package/src/secrets/config.ts +91 -0
  67. package/src/secrets/createSecretsCommands.ts +189 -0
  68. package/src/secrets/loadSecrets.ts +53 -0
  69. package/src/secrets/promptPassword.ts +46 -0
  70. package/src/secrets/provisionSource.ts +238 -0
  71. package/src/secrets/readRemoteSource.ts +73 -0
  72. package/src/secrets/runWithSecrets.ts +71 -0
  73. package/src/secrets/secretCommand.ts +26 -0
  74. package/src/secrets/selectSecrets.ts +33 -0
  75. package/src/secrets/syncSecrets.ts +60 -0
  76. package/src/secrets/wireSecretsWorkflows.ts +57 -0
  77. package/src/secrets/withDeploymentSecrets.ts +77 -0
  78. package/src/secrets/writeSecretsWorkflow.ts +83 -0
@@ -0,0 +1,141 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { safeTargetPath } from "../safeTargetPath.js";
6
+ import { readSecretsConfig, secretsConfigSchema, sourceSchema, } from "./config.js";
7
+ import { promptPassword } from "./promptPassword.js";
8
+ import { secretCommand } from "./secretCommand.js";
9
+ import { readRemoteSource } from "./readRemoteSource.js";
10
+ import { syncSecrets } from "./syncSecrets.js";
11
+ import { writeSecretsWorkflow } from "./writeSecretsWorkflow.js";
12
+ import { assertNewSource } from "./assertNewSource.js";
13
+ export const provisionSource = async (mode, options, root, configFile) => {
14
+ if (configFile !== ".arcnet/secrets.json")
15
+ throw new Error("Provisioning uses .arcnet/secrets.json so generated CI has a fixed entry point.");
16
+ if (process.env.GITHUB_ACTIONS === "true")
17
+ throw new Error("Provision secrets from an authorized local terminal, not CI.");
18
+ const source = sourceSchema.parse({
19
+ name: options.name,
20
+ store: options.store,
21
+ path: options.path.startsWith("/") ? options.path : `/${options.path}`,
22
+ keyEnv: options.keyEnv,
23
+ });
24
+ const configPath = safeTargetPath(root, configFile);
25
+ const config = existsSync(configPath)
26
+ ? readSecretsConfig(root, configFile)
27
+ : {
28
+ version: 1,
29
+ repository: options.repository,
30
+ sources: [],
31
+ consumers: {},
32
+ };
33
+ if (config.repository !== options.repository)
34
+ throw new Error("Repository differs from secrets configuration.");
35
+ const prior = config.sources.find((entry) => entry.name === source.name);
36
+ if (prior) {
37
+ if (prior.store !== source.store ||
38
+ prior.path !== source.path ||
39
+ prior.keyEnv !== source.keyEnv)
40
+ throw new Error("Source name already has different settings.");
41
+ return {
42
+ operation: `secrets.${mode}`,
43
+ status: "unchanged",
44
+ message: "Source is already configured; use secrets sync to refresh snapshots.",
45
+ };
46
+ }
47
+ const next = secretsConfigSchema.parse({
48
+ ...config,
49
+ sources: [...config.sources, source],
50
+ });
51
+ const known = JSON.parse(secretCommand("gh", ["secret", "list", "--repo", config.repository, "--json", "name"], root));
52
+ if (options.existingKey &&
53
+ !known.some((entry) => entry.name === source.keyEnv))
54
+ throw new Error("The named GitHub repository secret does not exist.");
55
+ if (!options.existingKey &&
56
+ known.some((entry) => entry.name === source.keyEnv))
57
+ throw new Error("GitHub secret already exists; use --existing-key to reuse it without overwriting.");
58
+ if (mode === "init" && options.existingKey)
59
+ throw new Error("A new encrypted file needs a new recipient; omit --existing-key.");
60
+ const original = mode === "add" ? readRemoteSource(source, root) : undefined;
61
+ if (mode === "init")
62
+ assertNewSource(source, root);
63
+ const temporary = mkdtempSync(join(tmpdir(), "arcnet-secrets-"));
64
+ try {
65
+ if (!options.existingKey) {
66
+ const password = await promptPassword(options.noninteractive);
67
+ const env = { ...process.env, DOCTRINE_ENCRYPTION_PASSWORD: password };
68
+ const ciphertext = join(temporary, "source.json.enc");
69
+ if (mode === "init") {
70
+ const plaintext = options.input
71
+ ? readFileSync(options.input, "utf8")
72
+ : "{}";
73
+ try {
74
+ const data = JSON.parse(plaintext);
75
+ if (!data || Array.isArray(data) || typeof data !== "object")
76
+ throw new Error();
77
+ }
78
+ catch {
79
+ throw new Error("Initial secrets must be a JSON object (values omitted).");
80
+ }
81
+ const input = join(temporary, "input.json");
82
+ writeFileSync(input, plaintext, { mode: 0o600 });
83
+ writeFileSync(ciphertext, secretCommand("fm", ["encrypt", "--file", input], root, undefined, env), { mode: 0o600 });
84
+ }
85
+ else
86
+ writeFileSync(ciphertext, original.text, { mode: 0o600 });
87
+ const recipientText = secretCommand("fm", [
88
+ "encrypt-add-recipient",
89
+ "--file",
90
+ ciphertext,
91
+ "--name",
92
+ `arcnet-${config.repository.replace("/", "-")}-${source.name}-${randomUUID()}`,
93
+ "--json",
94
+ ], root, undefined, env);
95
+ let recipient;
96
+ try {
97
+ recipient = JSON.parse(recipientText);
98
+ }
99
+ catch {
100
+ throw new Error("Forum returned an invalid recipient response (value omitted).");
101
+ }
102
+ if (typeof recipient.secret !== "string" ||
103
+ !recipient.secret.startsWith("doctrine-recipient-v1_"))
104
+ throw new Error("Forum did not return a valid recipient key.");
105
+ if (original) {
106
+ const current = readRemoteSource(source, root);
107
+ if (current.fileId !== original.fileId ||
108
+ current.revision !== original.revision)
109
+ throw new Error("Forum source changed during setup; retry before writing.");
110
+ }
111
+ if (mode === "init")
112
+ assertNewSource(source, root);
113
+ secretCommand("fm", [
114
+ "file",
115
+ "write",
116
+ source.path,
117
+ "--store",
118
+ source.store,
119
+ "--file",
120
+ ciphertext,
121
+ ], root, undefined, env);
122
+ try {
123
+ secretCommand("gh", ["secret", "set", source.keyEnv, "--repo", config.repository], root, recipient.secret);
124
+ }
125
+ catch {
126
+ throw new Error("Forum recipient was saved, but GitHub secret upload failed. Rerun setup to issue another recipient; remove the unused recipient in Forum later.");
127
+ }
128
+ }
129
+ const result = syncSecrets(next, root, configFile);
130
+ writeSecretsWorkflow(readSecretsConfig(root, configFile), root, configFile);
131
+ return {
132
+ ...result,
133
+ operation: `secrets.${mode}`,
134
+ githubSecret: source.keyEnv,
135
+ };
136
+ }
137
+ finally {
138
+ rmSync(temporary, { recursive: true, force: true });
139
+ }
140
+ };
141
+ //# sourceMappingURL=provisionSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provisionSource.js","sourceRoot":"","sources":["../../src/secrets/provisionSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,MA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O;YACL,GAAG,MAAM;YACT,SAAS,EAAE,WAAW,IAAI,EAAE;YAC5B,YAAY,EAAE,MAAM,CAAC,MAAM;SAC5B,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { SecretSource } from "./config.js";
2
+ export declare const readRemoteSource: (source: SecretSource, root: string, environment?: NodeJS.ProcessEnv) => {
3
+ text: string;
4
+ fileId: string;
5
+ revision: number;
6
+ };
7
+ //# sourceMappingURL=readRemoteSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readRemoteSource.d.ts","sourceRoot":"","sources":["../../src/secrets/readRemoteSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAUhD,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,YAAY,EACpB,MAAM,MAAM,EACZ,+BAAyB;;;;CA0D1B,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { z } from "zod";
2
+ import { secretCommand } from "./secretCommand.js";
3
+ const infoSchema = z.object({
4
+ id: z.string(),
5
+ revisionNumber: z.number().int(),
6
+ path: z.string(),
7
+ type: z.literal("text"),
8
+ });
9
+ export const readRemoteSource = (source, root, environment = process.env) => {
10
+ const env = { ...environment };
11
+ if (source.tokenEnv) {
12
+ if (!env[source.tokenEnv])
13
+ throw new Error(`Missing Forum access credential: ${source.tokenEnv}.`);
14
+ env.DOCTRINE_TOKEN = env[source.tokenEnv];
15
+ }
16
+ const args = [source.path, "--store", source.store];
17
+ try {
18
+ const before = infoSchema.parse(JSON.parse(secretCommand("fm", ["file", "info", ...args, "--json"], root, undefined, env)));
19
+ const text = secretCommand("fm", ["file", "read", ...args], root, undefined, env);
20
+ const after = infoSchema.parse(JSON.parse(secretCommand("fm", ["file", "info", ...args, "--json"], root, undefined, env)));
21
+ if (before.id !== after.id ||
22
+ before.revisionNumber !== after.revisionNumber ||
23
+ after.path !== source.path ||
24
+ (source.snapshot && after.id !== source.snapshot.fileId))
25
+ throw new Error("Source changed");
26
+ return { text, fileId: after.id, revision: after.revisionNumber };
27
+ }
28
+ catch {
29
+ throw new Error(`Cannot read stable Forum source ${source.name}; check access, identity and concurrent edits.`);
30
+ }
31
+ };
32
+ //# sourceMappingURL=readRemoteSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readRemoteSource.js","sourceRoot":"","sources":["../../src/secrets/readRemoteSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IAChC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAoB,EACpB,IAAY,EACZ,WAAW,GAAG,OAAO,CAAC,GAAG,EACzB,EAAE;IACF,MAAM,GAAG,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;IAE/B,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC1E,GAAG,CAAC,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,MAAM,CAA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: string[], values: Record<string, string>, root: string, environment?: NodeJS.ProcessEnv) => {
2
+ operation: string;
3
+ status: string;
4
+ keys: string[];
5
+ };
6
+ //# sourceMappingURL=runWithSecrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runWithSecrets.d.ts","sourceRoot":"","sources":["../../src/secrets/runWithSecrets.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,GACzB,SAAS,MAAM,EAAE,EACjB,QAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,MAAM,MAAM,EACZ,+BAAyB;;;;CA6D1B,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ export const runWithSecrets = (command, values, root, environment = process.env) => {
6
+ if (!command.length)
7
+ throw new Error("Supply a command after --.");
8
+ const inherited = [
9
+ "PATH",
10
+ "SystemRoot",
11
+ "LANG",
12
+ "CI",
13
+ "GITHUB_ACTIONS",
14
+ "GITHUB_REPOSITORY",
15
+ "GITHUB_REF",
16
+ "GITHUB_SHA",
17
+ "NPM_CONFIG_USERCONFIG",
18
+ "npm_config_userconfig",
19
+ ];
20
+ const temporary = mkdtempSync(join(tmpdir(), "arcnet-env-"));
21
+ try {
22
+ const env = {
23
+ ...Object.fromEntries(inherited
24
+ .filter((key) => environment[key] !== undefined)
25
+ .map((key) => [key, environment[key]])),
26
+ ...values,
27
+ HOME: temporary,
28
+ TMPDIR: temporary,
29
+ TMP: temporary,
30
+ TEMP: temporary,
31
+ XDG_CACHE_HOME: join(temporary, "cache"),
32
+ NPM_CONFIG_CACHE: join(temporary, "npm-cache"),
33
+ NPM_CONFIG_LOGS_MAX: "0",
34
+ NO_UPDATE_NOTIFIER: "1",
35
+ };
36
+ const result = spawnSync(command[0], command.slice(1), {
37
+ cwd: root,
38
+ env,
39
+ stdio: ["ignore", "pipe", "pipe"],
40
+ maxBuffer: 16 * 1024 * 1024,
41
+ });
42
+ if (result.error || result.status !== 0)
43
+ throw new Error("Credential-consuming command failed; output withheld to protect secrets.");
44
+ return {
45
+ operation: "env.run",
46
+ status: "passed",
47
+ keys: Object.keys(values),
48
+ };
49
+ }
50
+ finally {
51
+ rmSync(temporary, {
52
+ recursive: true,
53
+ force: true,
54
+ maxRetries: 5,
55
+ retryDelay: 200,
56
+ });
57
+ }
58
+ };
59
+ //# sourceMappingURL=runWithSecrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runWithSecrets.js","sourceRoot":"","sources":["../../src/secrets/runWithSecrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAAiB,EACjB,MAA8B,EAC9B,IAAY,EACZ,WAAW,GAAG,OAAO,CAAC,GAAG,EACzB,EAAE;IACF,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAEnE,MAAM,SAAS,GAAG;QAChB,MAAM;QACN,YAAY;QACZ,MAAM;QACN,IAAI;QACJ,gBAAgB;QAChB,mBAAmB;QACnB,YAAY;QACZ,YAAY;QACZ,uBAAuB;QACvB,uBAAuB;KACxB,CAAC;IAEF,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;IAE7D,IAAI,CAAC;QACH,MAAM,GAAG,GAAG;YACV,GAAG,MAAM,CAAC,WAAW,CACnB,SAAS;iBACN,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC;iBAC/C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CACzC;YACD,GAAG,MAAM;YACT,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,SAAS;YACjB,GAAG,EAAE,SAAS;YACd,IAAI,EAAE,SAAS;YACf,cAAc,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC;YACxC,gBAAgB,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC;YAC9C,mBAAmB,EAAE,GAAG;YACxB,kBAAkB,EAAE,GAAG;SACxB,CAAC;QAEF,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACtD,GAAG,EAAE,IAAI;YACT,GAAG;YACH,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;YACjC,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;SAC5B,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,0EAA0E,CAC3E,CAAC;QACJ,OAAO;YACL,SAAS,EAAE,SAAS;YACpB,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SAC1B,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,SAAS,EAAE;YAChB,SAAS,EAAE,IAAI;YACf,KAAK,EAAE,IAAI;YACX,UAAU,EAAE,CAAC;YACb,UAAU,EAAE,GAAG;SAChB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const secretCommand: (command: string, args: string[], root: string, input?: string, env?: NodeJS.ProcessEnv) => string;
2
+ //# sourceMappingURL=secretCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secretCommand.d.ts","sourceRoot":"","sources":["../../src/secrets/secretCommand.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,GACxB,SAAS,MAAM,EACf,MAAM,MAAM,EAAE,EACd,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,uBAAiB,KAChB,MAgBF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { spawnSync } from "node:child_process";
2
+ // Never include subprocess output in errors: it may contain plaintext or keys.
3
+ export const secretCommand = (command, args, root, input, env = process.env) => {
4
+ const result = spawnSync(command, args, {
5
+ cwd: root,
6
+ env,
7
+ input,
8
+ encoding: "utf8",
9
+ stdio: ["pipe", "pipe", "pipe"],
10
+ maxBuffer: 16 * 1024 * 1024,
11
+ timeout: 120000,
12
+ });
13
+ if (result.error || result.status !== 0)
14
+ throw new Error(`${command} ${args[0] ?? ""} failed; output withheld to protect credentials. Check authentication and permissions.`);
15
+ return result.stdout;
16
+ };
17
+ //# sourceMappingURL=secretCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secretCommand.js","sourceRoot":"","sources":["../../src/secrets/secretCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,IAAc,EACd,IAAY,EACZ,KAAc,EACd,GAAG,GAAG,OAAO,CAAC,GAAG,EACT,EAAE;IACV,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE;QACtC,GAAG,EAAE,IAAI;QACT,GAAG;QACH,KAAK;QACL,QAAQ,EAAE,MAAM;QAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;QAC/B,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;QAC3B,OAAO,EAAE,MAAM;KAChB,CAAC,CAAC;IAEH,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,wFAAwF,CACpH,CAAC;IACJ,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SecretsConfig } from "./config.js";
2
+ export declare const selectSecrets: (values: Record<string, unknown>, config: SecretsConfig, consumer: string) => Record<string, string>;
3
+ //# sourceMappingURL=selectSecrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectSecrets.d.ts","sourceRoot":"","sources":["../../src/secrets/selectSecrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,QAAQ,aAAa,EACrB,UAAU,MAAM,KACf,MAAM,CAAC,MAAM,EAAE,MAAM,CA0BvB,CAAC"}
@@ -0,0 +1,18 @@
1
+ export const selectSecrets = (values, config, consumer) => {
2
+ const mapping = config.consumers[consumer];
3
+ if (!mapping)
4
+ throw new Error(`Unknown secrets consumer: ${consumer}.`);
5
+ return Object.fromEntries(Object.entries(mapping).map(([output, input]) => {
6
+ const aliases = Array.isArray(input) ? input : [input];
7
+ const found = aliases
8
+ .filter((name) => Object.hasOwn(values, name))
9
+ .map((name) => values[name]);
10
+ if (!found.length ||
11
+ found.some((value) => typeof value !== "string" || !value.trim() || value.includes("\0")))
12
+ throw new Error(`Missing or invalid required secret for ${output} (values omitted).`);
13
+ if (new Set(found).size !== 1)
14
+ throw new Error(`Conflicting aliases for ${output} (values omitted).`);
15
+ return [output, found[0]];
16
+ }));
17
+ };
18
+ //# sourceMappingURL=selectSecrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectSecrets.js","sourceRoot":"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,CAAC;IACtC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { SecretsConfig } from "./config.js";
2
+ export declare const syncSecrets: (config: SecretsConfig, root: string, file: string) => {
3
+ operation: string;
4
+ sources: {
5
+ name: string;
6
+ revision: number;
7
+ }[];
8
+ message: string;
9
+ };
10
+ //# sourceMappingURL=syncSecrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncSecrets.d.ts","sourceRoot":"","sources":["../../src/secrets/syncSecrets.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,eAAO,MAAM,WAAW,GACtB,QAAQ,aAAa,EACrB,MAAM,MAAM,EACZ,MAAM,MAAM;;;;;;;CAgDb,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { parseForumEncryptedFilePayload } from "@mp-lb/forum-secrets";
2
+ import { createHash } from "node:crypto";
3
+ import { mkdirSync, renameSync, writeFileSync } from "node:fs";
4
+ import { dirname } from "node:path";
5
+ import { safeTargetPath } from "../safeTargetPath.js";
6
+ import { readRemoteSource } from "./readRemoteSource.js";
7
+ export const syncSecrets = (config, root, file) => {
8
+ const sources = config.sources.map((source) => {
9
+ const remote = readRemoteSource(source, root);
10
+ try {
11
+ parseForumEncryptedFilePayload(remote.text);
12
+ }
13
+ catch {
14
+ throw new Error(`Source ${source.name} is not a supported encrypted file.`);
15
+ }
16
+ const sha256 = createHash("sha256").update(remote.text).digest("hex");
17
+ // Content-addressed snapshots keep the previous config valid if interrupted.
18
+ const snapshot = {
19
+ file: `.arcnet/secrets/${source.name}-${sha256.slice(0, 16)}.json.enc`,
20
+ fileId: remote.fileId,
21
+ revision: remote.revision,
22
+ sha256,
23
+ };
24
+ const target = safeTargetPath(root, snapshot.file);
25
+ mkdirSync(dirname(target), { recursive: true });
26
+ writeFileSync(target, remote.text, { mode: 0o600 });
27
+ return { ...source, snapshot };
28
+ });
29
+ const target = safeTargetPath(root, file);
30
+ mkdirSync(dirname(target), { recursive: true });
31
+ const temporary = safeTargetPath(root, `${file}.tmp`);
32
+ writeFileSync(temporary, JSON.stringify({ ...config, sources }, null, 2) + "\n", { mode: 0o600 });
33
+ renameSync(temporary, target);
34
+ return {
35
+ operation: "secrets.sync",
36
+ sources: sources.map((s) => ({
37
+ name: s.name,
38
+ revision: s.snapshot.revision,
39
+ })),
40
+ message: "Review and commit the encrypted snapshots and configuration together.",
41
+ };
42
+ };
43
+ //# sourceMappingURL=syncSecrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncSecrets.js","sourceRoot":"","sources":["../../src/secrets/syncSecrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAqB,EACrB,IAAY,EACZ,IAAY,EACZ,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAE9C,IAAI,CAAC;YACH,8BAA8B,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CACb,UAAU,MAAM,CAAC,IAAI,qCAAqC,CAC3D,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,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AAE,CAAC,CAAC;YAC3B,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ;SAC9B,CAAC,CAAC;QACH,OAAO,EACL,uEAAuE;KAC1E,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const wireSecretsWorkflows: (folder: string, env: Record<string, string>) => void;
2
+ //# sourceMappingURL=wireSecretsWorkflows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wireSecretsWorkflows.d.ts","sourceRoot":"","sources":["../../src/secrets/wireSecretsWorkflows.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,MAAM,EACd,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,SAkD5B,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { readdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { isMap, isSeq, parseDocument } from "yaml";
4
+ export const wireSecretsWorkflows = (folder, env) => {
5
+ for (const file of readdirSync(folder).filter((name) => /\.ya?ml$/.test(name))) {
6
+ const path = join(folder, file);
7
+ const document = parseDocument(readFileSync(path, "utf8"));
8
+ if (document.errors.length)
9
+ throw new Error(`Cannot update malformed workflow: ${file}.`);
10
+ const jobs = document.get("jobs");
11
+ if (!isMap(jobs))
12
+ continue;
13
+ let changed = false;
14
+ for (const pair of jobs.items) {
15
+ if (!isMap(pair.value))
16
+ continue;
17
+ const steps = pair.value.get("steps");
18
+ if (!isSeq(steps))
19
+ continue;
20
+ for (const step of steps.items) {
21
+ if (!isMap(step))
22
+ continue;
23
+ const run = step.get("run");
24
+ if (typeof run !== "string" ||
25
+ !/\barcnet\s+(?:env\s+(?:check|run|export)|deploy|preview|inspect|plan)\b/.test(run))
26
+ continue;
27
+ if (step.has("env") && !isMap(step.get("env")))
28
+ throw new Error(`Workflow step env must be a mapping: ${file}.`);
29
+ if (!step.has("env"))
30
+ step.set("env", document.createNode({}));
31
+ const mapping = step.get("env");
32
+ if (!isMap(mapping))
33
+ continue;
34
+ for (const [name, value] of Object.entries(env)) {
35
+ if (mapping.has(name) && mapping.get(name) !== value)
36
+ throw new Error(`Workflow has a conflicting source-key mapping: ${file} / ${name}.`);
37
+ if (!mapping.has(name)) {
38
+ mapping.set(name, value);
39
+ changed = true;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ if (changed)
45
+ writeFileSync(path, document.toString());
46
+ }
47
+ };
48
+ //# sourceMappingURL=wireSecretsWorkflows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wireSecretsWorkflows.js","sourceRoot":"","sources":["../../src/secrets/wireSecretsWorkflows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAEnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,GAA2B,EAC3B,EAAE;IACF,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CACrD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CACtB,EAAE,CAAC;QACF,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3D,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM;YACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,IAAI,GAAG,CAAC,CAAC;QAChE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,CAAC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AO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK;wBAClD,MAAM,IAAI,KAAK,CACb,kDAAkD,IAAI,MAAM,IAAI,GAAG,CACpE,CAAC;oBAEJ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;wBACvB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;wBACzB,OAAO,GAAG,IAAI,CAAC;oBACjB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,OAAO;YAAE,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACxD,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const withDeploymentSecrets: <T>(root: string, mode: string | undefined, action: () => T | Promise<T>) => Promise<T>;
2
+ //# sourceMappingURL=withDeploymentSecrets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withDeploymentSecrets.d.ts","sourceRoot":"","sources":["../../src/secrets/withDeploymentSecrets.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,qBAAqB,GAAU,CAAC,EAC3C,MAAM,MAAM,EACZ,MAAM,MAAM,GAAG,SAAS,EACxB,QAAQ,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAC3B,OAAO,CAAC,CAAC,CAiEX,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parse } from "yaml";
4
+ import { readSecretsConfig } from "./config.js";
5
+ import { loadSecrets } from "./loadSecrets.js";
6
+ import { selectSecrets } from "./selectSecrets.js";
7
+ export const withDeploymentSecrets = async (root, mode, action) => {
8
+ if (!existsSync(join(root, ".arcnet/secrets.json")))
9
+ return action();
10
+ const config = readSecretsConfig(root);
11
+ if (process.env.GITHUB_ACTIONS === "true" &&
12
+ (process.env.GITHUB_REPOSITORY !== config.repository ||
13
+ process.env.GITHUB_REF !== "refs/heads/main"))
14
+ throw new Error("Secrets commands in CI require the configured repository main branch.");
15
+ const pool = await loadSecrets(config, root);
16
+ const selected = selectSecrets(pool, config, "deploy");
17
+ if (mode !== "vercel") {
18
+ const manifest = parse(readFileSync(join(root, "zap.yaml"), "utf8"));
19
+ const keys = Object.values(manifest.deploy?.services ?? {})
20
+ .flatMap((service) => service.env ?? [])
21
+ .filter((key) => !key.includes("="));
22
+ const app = Object.fromEntries(keys
23
+ .filter((key) => Object.hasOwn(pool, key))
24
+ .map((key) => {
25
+ if (typeof pool[key] !== "string")
26
+ throw new Error(`Invalid application value for ${key} (value omitted).`);
27
+ return [key, pool[key]];
28
+ }));
29
+ selected.ARCNET_ENV_JSON = JSON.stringify(app);
30
+ }
31
+ const removed = config.sources
32
+ .flatMap((source) => [
33
+ source.keyEnv,
34
+ ...(source.tokenEnv ? [source.tokenEnv] : []),
35
+ ])
36
+ .concat([
37
+ "DOCTRINE_ENCRYPTION_PASSWORD",
38
+ "DOCTRINE_TOKEN",
39
+ "DOCTRINE_RECIPIENT_SECRET",
40
+ ]);
41
+ const names = new Set([...removed, ...Object.keys(selected)]);
42
+ const previous = Object.fromEntries([...names].map((key) => [key, process.env[key]]));
43
+ try {
44
+ for (const key of removed)
45
+ delete process.env[key];
46
+ Object.assign(process.env, selected);
47
+ return await action();
48
+ }
49
+ finally {
50
+ for (const key of names) {
51
+ if (previous[key] === undefined)
52
+ delete process.env[key];
53
+ else
54
+ process.env[key] = previous[key];
55
+ }
56
+ }
57
+ };
58
+ //# sourceMappingURL=withDeploymentSecrets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withDeploymentSecrets.js","sourceRoot":"","sources":["../../src/secrets/withDeploymentSecrets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MA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E,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACrC,OAAO,MAAM,MAAM,EAAE,CAAC;IACxB,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;;gBACpD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { SecretsConfig } from "./config.js";
2
+ export declare const writeSecretsWorkflow: (config: SecretsConfig, root: string, configFile: string) => void;
3
+ //# sourceMappingURL=writeSecretsWorkflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeSecretsWorkflow.d.ts","sourceRoot":"","sources":["../../src/secrets/writeSecretsWorkflow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,aAAa,EACrB,MAAM,MAAM,EACZ,YAAY,MAAM,SAwEnB,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { mkdirSync, existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ import { stringify } from "yaml";
4
+ import { safeTargetPath } from "../safeTargetPath.js";
5
+ import { wireSecretsWorkflows } from "./wireSecretsWorkflows.js";
6
+ export const writeSecretsWorkflow = (config, root, configFile) => {
7
+ const path = safeTargetPath(root, ".github/workflows/validate-arcnet-secrets.yaml");
8
+ const marker = "# Generated by arcnet secrets; configure sources in .arcnet/secrets.json.\n";
9
+ if (existsSync(path) && !readFileSync(path, "utf8").startsWith(marker))
10
+ throw new Error("Existing validate-arcnet-secrets.yaml is not ArcNet-managed; move it before continuing.");
11
+ if (configFile !== ".arcnet/secrets.json")
12
+ throw new Error("Generated CI requires the standard .arcnet/secrets.json location.");
13
+ mkdirSync(dirname(path), { recursive: true });
14
+ const env = Object.fromEntries(config.sources
15
+ .flatMap((source) => [
16
+ source.keyEnv,
17
+ ...(!source.snapshot && source.tokenEnv ? [source.tokenEnv] : []),
18
+ ])
19
+ .map((key) => [key, `\u0024{{ secrets.${key} }}`]));
20
+ writeFileSync(path, marker +
21
+ stringify({
22
+ name: "Validate ArcNet secrets",
23
+ on: {
24
+ workflow_dispatch: {},
25
+ push: {
26
+ branches: ["main"],
27
+ paths: [
28
+ ".arcnet/**",
29
+ ".github/workflows/validate-arcnet-secrets.yaml",
30
+ "package.json",
31
+ "pnpm-lock.yaml",
32
+ ],
33
+ },
34
+ },
35
+ permissions: { contents: "read" },
36
+ jobs: {
37
+ validate: {
38
+ if: `github.repository == '${config.repository}' && github.ref == 'refs/heads/main'`,
39
+ "runs-on": "ubuntu-latest",
40
+ "timeout-minutes": 10,
41
+ steps: [
42
+ {
43
+ uses: "actions/checkout@v4",
44
+ with: { "persist-credentials": false },
45
+ },
46
+ { uses: "pnpm/action-setup@v4" },
47
+ { uses: "actions/setup-node@v4", with: { "node-version": 22 } },
48
+ { run: "pnpm install --frozen-lockfile --ignore-scripts" },
49
+ {
50
+ name: "Decrypt, merge and validate selected keys",
51
+ run: "pnpm exec arcnet env check",
52
+ env,
53
+ },
54
+ ],
55
+ },
56
+ },
57
+ }));
58
+ wireSecretsWorkflows(dirname(path), env);
59
+ };
60
+ //# sourceMappingURL=writeSecretsWorkflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeSecretsWorkflow.js","sourceRoot":"","sources":["../../src/secrets/writeSecretsWorkflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,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