@theholocron/holocron-plugin-bruno 5.0.0-alpha.483 → 5.0.0-alpha.484

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/dist/index.d.mts CHANGED
@@ -18,11 +18,17 @@ interface BrunoToolingOptions {
18
18
  version?: string;
19
19
  /**
20
20
  * Secret variable name to the name of the entry that holds its value, e.g. `{ webhookSecret: "SENTINEL_WEBHOOK_SECRET" }`.
21
- * `workspace()` writes each such secret into the `.bruno/` environments as a plain variable that refers to the entry
22
- * (`{{process.env.SENTINEL_WEBHOOK_SECRET}}`), which `holocron open requests` fills from the layer's vault
23
- * Environment. The request files keep the secret blank.
21
+ * With `environmentLayers`, `workspace()` writes each such secret into the `.bruno/` environments as a plain variable
22
+ * that refers to its own layer's copy of the entry (`{{process.env.DEV_SENTINEL_WEBHOOK_SECRET}}` in a `dev`
23
+ * environment), which `holocron open requests` fills from that layer's vault Environment. The request files keep the
24
+ * secret blank.
24
25
  */
25
26
  secretRefs?: Record<string, string>;
27
+ /**
28
+ * Bruno environment name to the vault layer (`local`, `dev` or `prod`) whose Environment holds its secrets, e.g.
29
+ * `{ "Sentinel (prod)": "prod" }`. An environment with no layer keeps its secrets blank.
30
+ */
31
+ environmentLayers?: Record<string, string>;
26
32
  /** The program that starts Bruno for `open()`. Defaults to the macOS app's; set it on any other platform. */
27
33
  app?: string;
28
34
  /** Working repo root. Defaults to `process.cwd()`. */
@@ -41,6 +47,8 @@ export declare class BrunoTooling implements Tooling {
41
47
  sync(): Promise<void>;
42
48
  doctor(): Promise<ToolingDoctorReport>;
43
49
  export(input: ToolingExportInput): Promise<ToolingExportResult>;
50
+ /** The secret wiring the options give, or `undefined` without `secretRefs`. */
51
+ private wiring;
44
52
  open(input: ToolingOpenInput): Promise<ToolingOpenPlan>;
45
53
  workspace(input: ToolingWorkspaceInput): Promise<ToolingWorkspaceResult>;
46
54
  }
package/dist/index.mjs CHANGED
@@ -194,34 +194,53 @@ function referencedName(value) {
194
194
  return value === void 0 ? void 0 : REFERENCE.exec(value.trim())?.[1];
195
195
  }
196
196
  /**
197
- * The environment with each secret variable named in `refs` (variable name to entry name) made a plain variable whose
198
- * value is the reference to its entry. Everything else is left as it was.
197
+ * The name a layer's copy of an entry has in the `.env` file: the layer word in capitals, then the entry
198
+ * (`dev` and `SENTINEL_WEBHOOK_SECRET` give `DEV_SENTINEL_WEBHOOK_SECRET`). The one place the scheme lives: the
199
+ * workspace's references and the values `open requests` writes both come from it, so each Bruno environment reads its
200
+ * own layer's value and a layer that was not loaded leaves its variable unresolved.
199
201
  */
200
- function withSecretReferences(environment, refs) {
201
- if (!refs || !environment.variables) return environment;
202
+ const layeredName = (layer, entry) => `${layer.toUpperCase()}_${entry}`;
203
+ /** The reference a variable of `environment` should hold, or `undefined` when the wiring does not cover it. */
204
+ function wantedReference(environmentName, variableName, wiring) {
205
+ const layer = environmentName === void 0 ? void 0 : wiring.layers[environmentName];
206
+ const entry = wiring.refs[variableName];
207
+ return layer === void 0 || entry === void 0 ? void 0 : referenceTo(layeredName(layer, entry));
208
+ }
209
+ /**
210
+ * The environment with each variable the wiring covers made a plain variable whose value is the reference to its
211
+ * layer's copy of the entry: a secret variable named in `refs`, in an environment named in `layers`, and a variable that
212
+ * already holds a different reference. Everything else is left as it was, so a secret of an environment with no layer
213
+ * stays blank.
214
+ */
215
+ function withSecretReferences(environment, wiring) {
216
+ if (!wiring || !environment.variables) return environment;
202
217
  return {
203
218
  ...environment,
204
219
  variables: environment.variables.map((variable) => {
205
- const entry = variable.secret ? refs[variable.name] : void 0;
206
- return entry === void 0 ? variable : {
220
+ const reference = wantedReference(environment.name, variable.name, wiring);
221
+ const refers = variable.secret || referencedName(variable.value) !== void 0;
222
+ return reference === void 0 || !refers ? variable : {
207
223
  ...variable,
208
224
  secret: false,
209
- value: referenceTo(entry)
225
+ value: reference
210
226
  };
211
227
  })
212
228
  };
213
229
  }
214
230
  /**
215
- * The text of a workspace environment file with each secret variable named in `refs` made a reference, as
216
- * {@link withSecretReferences} does for a generated one: for a file that is already written, whose secrets
217
- * `sync requests` would otherwise find in step and leave blank. A file with nothing to change comes back as it is,
218
- * byte for byte, so Bruno's own layout is never rewritten for nothing.
231
+ * The text of a workspace environment file with its variables wired as {@link withSecretReferences} does for a generated
232
+ * one: for a file that is already written, whose secrets `sync requests` would otherwise find in step and leave blank,
233
+ * or whose reference names another layer's copy. A file with nothing to change comes back as it is, byte for byte, so
234
+ * Bruno's own layout is never rewritten for nothing.
219
235
  */
220
- function healReferences(text, refs) {
221
- if (!refs) return text;
236
+ function healReferences(text, wiring) {
237
+ if (!wiring) return text;
222
238
  const environment = parseEnvironment(text, { format: "yml" });
223
- if (!environment.variables.some((variable) => variable.secret && refs[variable.name] !== void 0)) return text;
224
- return stringifyEnvironment(withSecretReferences(environment, refs), { format: "yml" });
239
+ if (!environment.variables.some((variable) => {
240
+ const reference = wantedReference(environment.name, variable.name, wiring);
241
+ return reference !== void 0 && (variable.secret || referencedName(variable.value) !== void 0) && variable.value !== reference;
242
+ })) return text;
243
+ return stringifyEnvironment(withSecretReferences(environment, wiring), { format: "yml" });
225
244
  }
226
245
  // src/open-plan.ts
227
246
  /** The folder at the repo root that holds the workspace Bruno opens. */
@@ -238,7 +257,8 @@ async function environmentFiles(dir) {
238
257
  /**
239
258
  * What it takes to open the committed `.bruno/` workspace with its secrets filled in: for each collection the baseline
240
259
  * lists, the secret variables its environments hold. A variable that is a reference to an entry (`{{process.env.NAME}}`,
241
- * written by `sync requests` for each name in the `secretRefs` option) is a value to fill; a secret variable with no
260
+ * written by `sync requests` from the `secretRefs` and `environmentLayers` options, as that layer's copy of the entry) is a value
261
+ * to fill, for its layer; a secret variable with no
242
262
  * reference is reported as unfilled. Reads files only and returns names and paths, never a value.
243
263
  *
244
264
  * @throws {Error} When there is no workspace to open, or the platform has no known program for Bruno and `app` is not set.
@@ -255,22 +275,28 @@ async function openPlan(input, options = {}) {
255
275
  const dir = join(repoRoot, WORKSPACE, folder, "environments");
256
276
  for (const file of await environmentFiles(dir)) {
257
277
  const environment = parseEnvironment(await readFile(join(dir, file), "utf8"), { format: "yml" });
278
+ const layer = options.wiring?.layers[environment.name];
258
279
  for (const variable of environment.variables) {
259
- const entry = referencedName(variable.value);
260
- if (entry !== void 0) {
261
- if (!wants.some((w) => w.collection === folder && w.variable === variable.name)) wants.push({
280
+ const name = referencedName(variable.value);
281
+ const entry = options.wiring?.refs[variable.name];
282
+ if (name === void 0) {
283
+ if (variable.secret) unfilled.add(`${folder} (${environment.name}): ${variable.name}`);
284
+ } else if (layer !== void 0 && entry !== void 0 && name === layeredName(layer, entry)) {
285
+ if (!wants.some((w) => w.collection === folder && w.variable === variable.name && w.layer === layer)) wants.push({
262
286
  collection: folder,
263
287
  variable: variable.name,
264
- entry
288
+ layer,
289
+ entry,
290
+ name
265
291
  });
266
- } else if (variable.secret) unfilled.add(`${folder}: ${variable.name}`);
292
+ } else unfilled.add(`${folder} (${environment.name}): ${variable.name} refers to ${name}, which no secretRefs and environmentLayers give`);
267
293
  }
268
294
  }
269
295
  }
270
296
  return {
271
297
  app: "Bruno",
272
298
  wants,
273
- unfilled: [...unfilled].filter((label) => !wants.some((w) => `${w.collection}: ${w.variable}` === label)),
299
+ unfilled: [...unfilled],
274
300
  targets: folders.map((folder) => join(repoRoot, WORKSPACE, folder, ".env")),
275
301
  launch: {
276
302
  command,
@@ -704,13 +730,13 @@ function environmentToSource(text, path) {
704
730
  const environment = reading(path, () => parseEnvironment(text, { format: "yml" }));
705
731
  return {
706
732
  name: environment.name,
707
- values: (environment.variables ?? []).map((variable) => {
733
+ values: environment.variables.map((variable) => {
708
734
  const hidden = variable.secret || referencedName(variable.value) !== void 0;
709
735
  return {
710
736
  key: variable.name,
711
737
  value: hidden ? "" : variable.value,
712
738
  type: hidden ? "secret" : "default",
713
- enabled: variable.enabled ?? true
739
+ enabled: variable.enabled
714
740
  };
715
741
  })
716
742
  };
@@ -1285,8 +1311,19 @@ var BrunoTooling = class {
1285
1311
  issues
1286
1312
  };
1287
1313
  }
1314
+ /** The secret wiring the options give, or `undefined` without `secretRefs`. */
1315
+ wiring() {
1316
+ const { secretRefs, environmentLayers } = this.options;
1317
+ return secretRefs ? {
1318
+ refs: secretRefs,
1319
+ layers: environmentLayers ?? {}
1320
+ } : void 0;
1321
+ }
1288
1322
  open(input) {
1289
- return openPlan(input, { app: this.options.app });
1323
+ return openPlan(input, {
1324
+ app: this.options.app,
1325
+ wiring: this.wiring()
1326
+ });
1290
1327
  }
1291
1328
  async workspace(input) {
1292
1329
  const { collectionFiles, envFiles, repoRoot } = input;
@@ -1308,7 +1345,7 @@ var BrunoTooling = class {
1308
1345
  collections,
1309
1346
  repoRoot,
1310
1347
  ...version === void 0 ? {} : { version },
1311
- ...this.options.secretRefs ? { secretRefs: this.options.secretRefs } : {},
1348
+ ...this.wiring() ? { secretRefs: this.wiring() } : {},
1312
1349
  ...input.dryRun ? { dryRun: true } : {},
1313
1350
  ...input.prefer ? { prefer: input.prefer } : {}
1314
1351
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-bruno",
3
- "version": "5.0.0-alpha.483",
3
+ "version": "5.0.0-alpha.484",
4
4
  "description": "Holocron plugin for Bruno. Implements the tooling capability over files: it exports the repo's request collections as Bruno JSON files.",
5
5
  "keywords": [
6
6
  "bruno",
@@ -44,14 +44,14 @@
44
44
  "tsx": "4.23.15",
45
45
  "typescript": "^5.9.3",
46
46
  "vitest": "^5.1.0",
47
- "@theholocron/cli": "5.0.0-alpha.483",
48
47
  "@theholocron/eslint-config": "^8.9.0-alpha.21",
49
- "@theholocron/tsdown-config": "^8.9.0-alpha.21",
48
+ "@theholocron/cli": "5.0.0-alpha.484",
50
49
  "@theholocron/tsconfig": "^8.9.0-alpha.21",
50
+ "@theholocron/tsdown-config": "^8.9.0-alpha.21",
51
51
  "@theholocron/vitest-config": "^8.9.0-alpha.21"
52
52
  },
53
53
  "peerDependencies": {
54
- "@theholocron/cli": "5.0.0-alpha.483"
54
+ "@theholocron/cli": "5.0.0-alpha.484"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=22"