@dudko.dev/baton-format 0.1.1 → 0.1.3

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.
@@ -1,4 +1,5 @@
1
1
  export * from "./types.js";
2
2
  export { FormatError, type FormatErrorCode } from "./errors.js";
3
- export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, } from "./parse.js";
4
- export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, } from "./serialize.js";
3
+ export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, parseExamplesFile, parseMockFile, } from "./parse.js";
4
+ export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, serializeExamplesFile, serializeMockFile, } from "./serialize.js";
5
+ export { parseVaultRef, formatVaultRef, type VaultRef } from "./vault.js";
package/dist/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./types.js";
2
2
  export { FormatError } from "./errors.js";
3
- export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, } from "./parse.js";
4
- export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, } from "./serialize.js";
3
+ export { parseRequestFile, parseCollectionFile, parseEnvironmentFile, parseWorkspaceManifest, parseSchedulesFile, parseExamplesFile, parseMockFile, } from "./parse.js";
4
+ export { serializeRequestFile, serializeCollectionFile, serializeEnvironmentFile, serializeWorkspaceManifest, serializeSchedulesFile, serializeExamplesFile, serializeMockFile, } from "./serialize.js";
5
+ export { parseVaultRef, formatVaultRef } from "./vault.js";
5
6
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest } from "./types.js";
1
+ import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest, ExamplesFile, MockFile } from "./types.js";
2
2
  /** Parse and validate a `*.req.yaml` file into its normalized form. */
3
3
  export declare function parseRequestFile(text: string): RequestFile;
4
4
  /** Parse and validate a `collection.yaml` / `folder.yaml` file. */
@@ -9,3 +9,7 @@ export declare function parseEnvironmentFile(text: string): EnvironmentFile;
9
9
  export declare function parseWorkspaceManifest(text: string): WorkspaceManifest;
10
10
  /** Parse and validate a `schedules.yaml` file. */
11
11
  export declare function parseSchedulesFile(text: string): SchedulesFile;
12
+ /** Parse and validate a `<slug>.examples.yaml` file. */
13
+ export declare function parseExamplesFile(text: string): ExamplesFile;
14
+ /** Parse and validate a `mocks/<name>.yaml` file. */
15
+ export declare function parseMockFile(text: string): MockFile;
package/dist/src/parse.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { parse as parseYaml } from "yaml";
2
2
  import { FormatError } from "./errors.js";
3
+ import { parseVaultRef } from "./vault.js";
3
4
  import { DEFAULT_SETTINGS, FORMAT_VERSION, METHODS, } from "./types.js";
4
5
  const ULID_RE = /^[0-9A-HJKMNP-TV-Z]{26}$/;
5
6
  // MARK: - Primitive readers
@@ -52,6 +53,17 @@ function reqString(obj, key, path) {
52
53
  }
53
54
  return value;
54
55
  }
56
+ /** A required string that may be empty. */
57
+ function reqText(obj, key, path) {
58
+ if (!(key in obj)) {
59
+ throw new FormatError("missing-field", join(path, key), "required field is missing");
60
+ }
61
+ const value = obj[key];
62
+ if (typeof value !== "string") {
63
+ throw new FormatError("invalid-field", join(path, key), "must be a string");
64
+ }
65
+ return value;
66
+ }
55
67
  function optString(obj, key, path) {
56
68
  const value = obj[key];
57
69
  if (value === undefined)
@@ -70,6 +82,16 @@ function optBool(obj, key, path, dflt) {
70
82
  }
71
83
  return value;
72
84
  }
85
+ function reqInt(obj, key, path) {
86
+ const value = obj[key];
87
+ if (value === undefined) {
88
+ throw new FormatError("missing-field", join(path, key), "is required");
89
+ }
90
+ if (typeof value !== "number" || !Number.isInteger(value)) {
91
+ throw new FormatError("invalid-field", join(path, key), "must be an integer");
92
+ }
93
+ return value;
94
+ }
73
95
  function optInt(obj, key, path, dflt) {
74
96
  const value = obj[key];
75
97
  if (value === undefined)
@@ -118,7 +140,9 @@ function parseKvRows(obj, key, path) {
118
140
  checkKeys(row, ["name", "value", "enabled"], itemPath);
119
141
  return {
120
142
  name: reqString(row, "name", itemPath),
121
- value: reqString(row, "value", itemPath),
143
+ // Empty is a value here: `curl -H 'Name;'` sends an empty header, and
144
+ // a documented parameter may have no sample yet.
145
+ value: reqText(row, "value", itemPath),
122
146
  enabled: optBool(row, "enabled", itemPath, true),
123
147
  };
124
148
  });
@@ -171,6 +195,42 @@ function parseAuth(obj, path) {
171
195
  },
172
196
  };
173
197
  }
198
+ case "digest": {
199
+ checkKeys(auth, ["type", "digest"], authPath);
200
+ const cfg = optRecord(auth, "digest", authPath);
201
+ if (cfg === undefined) {
202
+ throw new FormatError("missing-field", join(authPath, "digest"), "required field is missing");
203
+ }
204
+ const cfgPath = join(authPath, "digest");
205
+ checkKeys(cfg, ["username", "password"], cfgPath);
206
+ return {
207
+ type: "digest",
208
+ digest: {
209
+ username: reqString(cfg, "username", cfgPath),
210
+ password: reqString(cfg, "password", cfgPath),
211
+ },
212
+ };
213
+ }
214
+ case "awsSigV4": {
215
+ checkKeys(auth, ["type", "awsSigV4"], authPath);
216
+ const cfg = optRecord(auth, "awsSigV4", authPath);
217
+ if (cfg === undefined) {
218
+ throw new FormatError("missing-field", join(authPath, "awsSigV4"), "required field is missing");
219
+ }
220
+ const cfgPath = join(authPath, "awsSigV4");
221
+ checkKeys(cfg, ["accessKey", "secretKey", "sessionToken", "region", "service"], cfgPath);
222
+ const sessionToken = optString(cfg, "sessionToken", cfgPath);
223
+ return {
224
+ type: "awsSigV4",
225
+ awsSigV4: {
226
+ accessKey: reqString(cfg, "accessKey", cfgPath),
227
+ secretKey: reqString(cfg, "secretKey", cfgPath),
228
+ ...(sessionToken !== undefined ? { sessionToken } : {}),
229
+ region: reqString(cfg, "region", cfgPath),
230
+ service: reqString(cfg, "service", cfgPath),
231
+ },
232
+ };
233
+ }
174
234
  case "bearer": {
175
235
  checkKeys(auth, ["type", "bearer"], authPath);
176
236
  const cfg = optRecord(auth, "bearer", authPath);
@@ -364,11 +424,13 @@ export function parseRequestFile(text) {
364
424
  /** Parse and validate a `collection.yaml` / `folder.yaml` file. */
365
425
  export function parseCollectionFile(text) {
366
426
  const obj = root(text);
367
- checkKeys(obj, ["format", "id", "name", "auth", "variables", "order"], "");
427
+ checkKeys(obj, ["format", "id", "name", "spec", "auth", "variables", "order"], "");
428
+ const spec = optString(obj, "spec", "");
368
429
  return {
369
430
  format: checkFormat(obj, ""),
370
431
  id: ulid(obj, "id", ""),
371
432
  name: reqString(obj, "name", ""),
433
+ ...(spec !== undefined ? { spec } : {}),
372
434
  auth: parseAuth(obj, ""),
373
435
  variables: parseVariables(obj, "variables", ""),
374
436
  order: parseStringList(obj, "order", ""),
@@ -377,14 +439,45 @@ export function parseCollectionFile(text) {
377
439
  /** Parse and validate a `*.env.yaml` file. */
378
440
  export function parseEnvironmentFile(text) {
379
441
  const obj = root(text);
380
- checkKeys(obj, ["format", "name", "variables", "secrets"], "");
442
+ checkKeys(obj, ["format", "name", "production", "variables", "secrets"], "");
443
+ const { secrets, vault } = parseSecrets(obj, "");
444
+ const production = optBool(obj, "production", "", false);
381
445
  return {
382
446
  format: checkFormat(obj, ""),
383
447
  name: reqString(obj, "name", ""),
384
448
  variables: parseVariables(obj, "variables", ""),
385
- secrets: parseStringList(obj, "secrets", ""),
449
+ secrets,
450
+ ...(Object.keys(vault).length > 0 ? { vault } : {}),
451
+ ...(production ? { production: true } : {}),
386
452
  };
387
453
  }
454
+ /**
455
+ * `secrets:` entries: a bare name (device store), or `{name, vault}` for a
456
+ * value read from Vault. Order is the list's; the Vault map is by name.
457
+ */
458
+ function parseSecrets(obj, path) {
459
+ const secrets = [];
460
+ const vault = {};
461
+ optArray(obj, "secrets", path).forEach((item, i) => {
462
+ const itemPath = `${join(path, "secrets")}[${i}]`;
463
+ if (typeof item === "string") {
464
+ if (item === "")
465
+ throw new FormatError("invalid-field", itemPath, "must be a non-empty string");
466
+ secrets.push(item);
467
+ return;
468
+ }
469
+ const entry = itemRecord(item, itemPath);
470
+ checkKeys(entry, ["name", "vault"], itemPath);
471
+ const name = reqString(entry, "name", itemPath);
472
+ const ref = reqString(entry, "vault", itemPath);
473
+ // Validated here so a bad reference is a format error at its field, not
474
+ // a send-time failure in whichever engine reads it first.
475
+ parseVaultRef(ref, `${itemPath}.vault`);
476
+ secrets.push(name);
477
+ vault[name] = ref;
478
+ });
479
+ return { secrets, vault };
480
+ }
388
481
  /** Parse and validate the `baton.yaml` workspace manifest. */
389
482
  export function parseWorkspaceManifest(text) {
390
483
  const obj = root(text);
@@ -392,11 +485,59 @@ export function parseWorkspaceManifest(text) {
392
485
  const settingsObj = optRecord(obj, "settings", "");
393
486
  let settings = { ...DEFAULT_SETTINGS };
394
487
  if (settingsObj !== undefined) {
395
- checkKeys(settingsObj, ["followRedirects", "timeoutMs", "validateTls"], "settings");
488
+ checkKeys(settingsObj, ["followRedirects", "timeoutMs", "validateTls", "tls", "proxy", "vault"], "settings");
489
+ let tls = { clientCertificates: [] };
490
+ const tlsObj = optRecord(settingsObj, "tls", "settings");
491
+ if (tlsObj !== undefined) {
492
+ checkKeys(tlsObj, ["caFile", "clientCertificates"], "settings.tls");
493
+ const caFile = optString(tlsObj, "caFile", "settings.tls");
494
+ tls = {
495
+ ...(caFile !== undefined ? { caFile } : {}),
496
+ clientCertificates: optArray(tlsObj, "clientCertificates", "settings.tls").map((item, i) => {
497
+ const itemPath = `settings.tls.clientCertificates[${i}]`;
498
+ const cert = itemRecord(item, itemPath);
499
+ checkKeys(cert, ["hostPattern", "certSecret", "keySecret", "passphraseSecret"], itemPath);
500
+ const passphraseSecret = optString(cert, "passphraseSecret", itemPath);
501
+ return {
502
+ hostPattern: reqString(cert, "hostPattern", itemPath),
503
+ certSecret: reqString(cert, "certSecret", itemPath),
504
+ keySecret: reqString(cert, "keySecret", itemPath),
505
+ ...(passphraseSecret !== undefined ? { passphraseSecret } : {}),
506
+ };
507
+ }),
508
+ };
509
+ }
510
+ let proxy;
511
+ const proxyObj = optRecord(settingsObj, "proxy", "settings");
512
+ if (proxyObj !== undefined) {
513
+ checkKeys(proxyObj, ["url", "noProxy", "usernameSecret", "passwordSecret"], "settings.proxy");
514
+ const usernameSecret = optString(proxyObj, "usernameSecret", "settings.proxy");
515
+ const passwordSecret = optString(proxyObj, "passwordSecret", "settings.proxy");
516
+ proxy = {
517
+ url: reqString(proxyObj, "url", "settings.proxy"),
518
+ noProxy: parseStringList(proxyObj, "noProxy", "settings.proxy"),
519
+ ...(usernameSecret !== undefined ? { usernameSecret } : {}),
520
+ ...(passwordSecret !== undefined ? { passwordSecret } : {}),
521
+ };
522
+ }
523
+ let vault;
524
+ const vaultObj = optRecord(settingsObj, "vault", "settings");
525
+ if (vaultObj !== undefined) {
526
+ checkKeys(vaultObj, ["address", "namespace"], "settings.vault");
527
+ const address = reqString(vaultObj, "address", "settings.vault");
528
+ if (!address.startsWith("http://") && !address.startsWith("https://")) {
529
+ throw new FormatError("invalid-field", "settings.vault.address", "must start with http:// or https://");
530
+ }
531
+ const namespace = optString(vaultObj, "namespace", "settings.vault");
532
+ vault = { address, ...(namespace !== undefined ? { namespace } : {}) };
533
+ }
396
534
  settings = {
397
535
  followRedirects: optBool(settingsObj, "followRedirects", "settings", DEFAULT_SETTINGS.followRedirects),
398
536
  timeoutMs: optInt(settingsObj, "timeoutMs", "settings", DEFAULT_SETTINGS.timeoutMs),
399
537
  validateTls: optBool(settingsObj, "validateTls", "settings", DEFAULT_SETTINGS.validateTls),
538
+ ...(tls.caFile !== undefined || tls.clientCertificates.length > 0 ? { tls } : {}),
539
+ ...(proxy !== undefined ? { proxy } : {}),
540
+ ...(vault !== undefined ? { vault } : {}),
400
541
  };
401
542
  }
402
543
  const description = optString(obj, "description", "");
@@ -456,4 +597,54 @@ export function parseSchedulesFile(text) {
456
597
  });
457
598
  return { format: checkFormat(obj, ""), schedules };
458
599
  }
600
+ /** Parse and validate a `<slug>.examples.yaml` file. */
601
+ export function parseExamplesFile(text) {
602
+ const obj = root(text);
603
+ checkKeys(obj, ["format", "examples"], "");
604
+ const seen = new Set();
605
+ const examples = optArray(obj, "examples", "").map((item, i) => {
606
+ const itemPath = `examples[${i}]`;
607
+ const entry = itemRecord(item, itemPath);
608
+ checkKeys(entry, ["name", "status", "headers", "body"], itemPath);
609
+ const name = reqString(entry, "name", itemPath);
610
+ if (seen.has(name)) {
611
+ throw new FormatError("invalid-field", `${itemPath}.name`, `duplicate example name "${name}"`);
612
+ }
613
+ seen.add(name);
614
+ const status = reqInt(entry, "status", itemPath);
615
+ if (status < 100 || status > 599) {
616
+ throw new FormatError("invalid-field", `${itemPath}.status`, "must be an HTTP status (100–599)");
617
+ }
618
+ return {
619
+ name,
620
+ status,
621
+ headers: parseKvRows(entry, "headers", itemPath),
622
+ body: optString(entry, "body", itemPath) ?? "",
623
+ };
624
+ });
625
+ return { format: checkFormat(obj, ""), examples };
626
+ }
627
+ /** Parse and validate a `mocks/<name>.yaml` file. */
628
+ export function parseMockFile(text) {
629
+ const obj = root(text);
630
+ checkKeys(obj, ["format", "name", "port", "collections", "example"], "");
631
+ const port = reqInt(obj, "port", "");
632
+ if (port < 1 || port > 65535) {
633
+ throw new FormatError("invalid-field", "port", "must be 1–65535");
634
+ }
635
+ const collections = parseStringList(obj, "collections", "");
636
+ collections.forEach((path, i) => {
637
+ if (!path.startsWith("collections/") || path.includes("..")) {
638
+ throw new FormatError("invalid-field", `collections[${i}]`, "must be a workspace-relative collection path (collections/<name>)");
639
+ }
640
+ });
641
+ const example = optString(obj, "example", "");
642
+ return {
643
+ format: checkFormat(obj, ""),
644
+ name: reqString(obj, "name", ""),
645
+ port,
646
+ collections,
647
+ ...(example === undefined ? {} : { example }),
648
+ };
649
+ }
459
650
  //# sourceMappingURL=parse.js.map
@@ -1,4 +1,4 @@
1
- import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest } from "./types.js";
1
+ import { CollectionFile, EnvironmentFile, RequestFile, SchedulesFile, WorkspaceManifest, ExamplesFile, MockFile } from "./types.js";
2
2
  /** Serialize a normalized request to canonical `*.req.yaml` bytes. */
3
3
  export declare function serializeRequestFile(req: RequestFile): string;
4
4
  /** Serialize a normalized collection/folder to canonical bytes. */
@@ -9,3 +9,7 @@ export declare function serializeEnvironmentFile(env: EnvironmentFile): string;
9
9
  export declare function serializeWorkspaceManifest(ws: WorkspaceManifest): string;
10
10
  /** Serialize normalized schedules to canonical bytes. */
11
11
  export declare function serializeSchedulesFile(file: SchedulesFile): string;
12
+ /** Serialize a request's examples to canonical bytes. */
13
+ export declare function serializeExamplesFile(file: ExamplesFile): string;
14
+ /** Serialize a mock definition to canonical bytes. */
15
+ export declare function serializeMockFile(mock: MockFile): string;
@@ -90,7 +90,10 @@ class Out {
90
90
  * or nothing but newlines, which reads back as the empty string.
91
91
  */
92
92
  block(indent, key, text) {
93
- if (text.includes("\r") || text.replace(/\n+$/, "") === "") {
93
+ // A carriage return or any other control character (a response body is
94
+ // whatever the API sent — ANSI colors, NUL bytes) cannot live in a block
95
+ // scalar; quoted, it round-trips byte for byte.
96
+ if (/[\x00-\x08\x0b-\x1f\x7f]/.test(text) || text.replace(/\n+$/, "") === "") {
94
97
  this.line(indent, `${key}: ${JSON.stringify(text)}`);
95
98
  return;
96
99
  }
@@ -153,6 +156,21 @@ function emitAuth(out, indent, auth) {
153
156
  out.kv(indent + 4, "username", auth.basic.username);
154
157
  out.kv(indent + 4, "password", auth.basic.password);
155
158
  break;
159
+ case "digest":
160
+ out.line(indent + 2, "digest:");
161
+ out.kv(indent + 4, "username", auth.digest.username);
162
+ out.kv(indent + 4, "password", auth.digest.password);
163
+ break;
164
+ case "awsSigV4":
165
+ out.line(indent + 2, "awsSigV4:");
166
+ out.kv(indent + 4, "accessKey", auth.awsSigV4.accessKey);
167
+ out.kv(indent + 4, "secretKey", auth.awsSigV4.secretKey);
168
+ if (auth.awsSigV4.sessionToken !== undefined) {
169
+ out.kv(indent + 4, "sessionToken", auth.awsSigV4.sessionToken);
170
+ }
171
+ out.kv(indent + 4, "region", auth.awsSigV4.region);
172
+ out.kv(indent + 4, "service", auth.awsSigV4.service);
173
+ break;
156
174
  case "bearer":
157
175
  out.line(indent + 2, "bearer:");
158
176
  out.kv(indent + 4, "token", auth.bearer.token);
@@ -264,6 +282,8 @@ export function serializeCollectionFile(col) {
264
282
  out.kv(0, "format", col.format);
265
283
  out.kv(0, "id", col.id);
266
284
  out.kv(0, "name", col.name);
285
+ if (col.spec !== undefined)
286
+ out.kv(0, "spec", col.spec);
267
287
  emitAuth(out, 0, col.auth);
268
288
  emitVariables(out, 0, "variables", col.variables);
269
289
  if (col.order.length > 0)
@@ -275,9 +295,22 @@ export function serializeEnvironmentFile(env) {
275
295
  const out = new Out();
276
296
  out.kv(0, "format", env.format);
277
297
  out.kv(0, "name", env.name);
298
+ if (env.production === true)
299
+ out.kv(0, "production", true);
278
300
  emitVariables(out, 0, "variables", env.variables);
279
- if (env.secrets.length > 0)
280
- out.list(0, "secrets", env.secrets);
301
+ if (env.secrets.length > 0) {
302
+ out.line(0, "secrets:");
303
+ for (const name of env.secrets) {
304
+ const ref = env.vault?.[name];
305
+ if (ref === undefined) {
306
+ out.line(2, `- ${scalar(name)}`);
307
+ }
308
+ else {
309
+ out.line(2, `- name: ${scalar(name)}`);
310
+ out.kv(4, "vault", ref);
311
+ }
312
+ }
313
+ }
281
314
  return out.toString();
282
315
  }
283
316
  /** Serialize a normalized workspace manifest to canonical bytes. */
@@ -296,10 +329,51 @@ export function serializeWorkspaceManifest(ws) {
296
329
  nonDefault.push(["timeoutMs", s.timeoutMs]);
297
330
  if (s.validateTls !== DEFAULT_SETTINGS.validateTls)
298
331
  nonDefault.push(["validateTls", s.validateTls]);
299
- if (nonDefault.length > 0) {
332
+ const tls = s.tls ?? { clientCertificates: [] };
333
+ const tlsEmpty = tls.caFile === undefined && tls.clientCertificates.length === 0;
334
+ const proxy = s.proxy;
335
+ const vault = s.vault;
336
+ if (nonDefault.length > 0 || !tlsEmpty || proxy !== undefined || vault !== undefined) {
300
337
  out.line(0, "settings:");
301
338
  for (const [key, value] of nonDefault)
302
339
  out.kv(2, key, value);
340
+ if (!tlsEmpty) {
341
+ out.line(2, "tls:");
342
+ if (tls.caFile !== undefined)
343
+ out.kv(4, "caFile", tls.caFile);
344
+ if (tls.clientCertificates.length > 0) {
345
+ out.line(4, "clientCertificates:");
346
+ for (const cert of tls.clientCertificates) {
347
+ out.line(6, `- hostPattern: ${scalar(cert.hostPattern)}`);
348
+ out.kv(8, "certSecret", cert.certSecret);
349
+ out.kv(8, "keySecret", cert.keySecret);
350
+ if (cert.passphraseSecret !== undefined) {
351
+ out.kv(8, "passphraseSecret", cert.passphraseSecret);
352
+ }
353
+ }
354
+ }
355
+ }
356
+ if (proxy !== undefined) {
357
+ out.line(2, "proxy:");
358
+ out.kv(4, "url", proxy.url);
359
+ if (proxy.noProxy.length > 0) {
360
+ out.line(4, "noProxy:");
361
+ for (const pattern of proxy.noProxy)
362
+ out.line(6, `- ${scalar(pattern)}`);
363
+ }
364
+ if (proxy.usernameSecret !== undefined) {
365
+ out.kv(4, "usernameSecret", proxy.usernameSecret);
366
+ }
367
+ if (proxy.passwordSecret !== undefined) {
368
+ out.kv(4, "passwordSecret", proxy.passwordSecret);
369
+ }
370
+ }
371
+ if (vault !== undefined) {
372
+ out.line(2, "vault:");
373
+ out.kv(4, "address", vault.address);
374
+ if (vault.namespace !== undefined)
375
+ out.kv(4, "namespace", vault.namespace);
376
+ }
303
377
  }
304
378
  return out.toString();
305
379
  }
@@ -331,4 +405,32 @@ export function serializeSchedulesFile(file) {
331
405
  }
332
406
  return out.toString();
333
407
  }
408
+ /** Serialize a request's examples to canonical bytes. */
409
+ export function serializeExamplesFile(file) {
410
+ const out = new Out();
411
+ out.kv(0, "format", file.format);
412
+ if (file.examples.length > 0) {
413
+ out.line(0, "examples:");
414
+ for (const example of file.examples) {
415
+ out.line(2, `- name: ${scalar(example.name)}`);
416
+ out.kv(4, "status", example.status);
417
+ emitKvRows(out, 4, "headers", example.headers);
418
+ if (example.body.length > 0)
419
+ out.block(4, "body", example.body);
420
+ }
421
+ }
422
+ return out.toString();
423
+ }
424
+ /** Serialize a mock definition to canonical bytes. */
425
+ export function serializeMockFile(mock) {
426
+ const out = new Out();
427
+ out.kv(0, "format", mock.format);
428
+ out.kv(0, "name", mock.name);
429
+ out.kv(0, "port", mock.port);
430
+ if (mock.collections.length > 0)
431
+ out.list(0, "collections", mock.collections);
432
+ if (mock.example !== undefined)
433
+ out.kv(0, "example", mock.example);
434
+ return out.toString();
435
+ }
334
436
  //# sourceMappingURL=serialize.js.map
@@ -31,6 +31,21 @@ export type AuthConfig = {
31
31
  username: string;
32
32
  password: string;
33
33
  };
34
+ } | {
35
+ type: "digest";
36
+ digest: {
37
+ username: string;
38
+ password: string;
39
+ };
40
+ } | {
41
+ type: "awsSigV4";
42
+ awsSigV4: {
43
+ accessKey: string;
44
+ secretKey: string;
45
+ sessionToken?: string;
46
+ region: string;
47
+ service: string;
48
+ };
34
49
  } | {
35
50
  type: "bearer";
36
51
  bearer: {
@@ -114,6 +129,12 @@ export interface CollectionFile {
114
129
  format: number;
115
130
  id: string;
116
131
  name: string;
132
+ /**
133
+ * An OpenAPI document this collection follows: a workspace-relative path
134
+ * or an http(s) URL. The app lists the drift between the two; nothing here
135
+ * writes to it. Absent when the collection is hand-made.
136
+ */
137
+ spec?: string;
117
138
  auth: AuthConfig;
118
139
  variables: Variable[];
119
140
  order: string[];
@@ -125,11 +146,61 @@ export interface EnvironmentFile {
125
146
  variables: Variable[];
126
147
  /** Secret names only — values never live in the workspace. */
127
148
  secrets: string[];
149
+ /**
150
+ * Marks an environment whose targets are real: a send into it from an
151
+ * agent is confirmed in the app first. Absent means false.
152
+ */
153
+ production?: boolean;
154
+ /**
155
+ * Secrets read from Vault rather than the device store, by name:
156
+ * `apiToken` → `kv/billing/prod#password`. A location, not a value. Every
157
+ * key also appears in `secrets`, which keeps the order. Absent when empty.
158
+ */
159
+ vault?: Record<string, string>;
160
+ }
161
+ /**
162
+ * Where the workspace's Vault is — `settings.vault`. Infrastructure, so it is
163
+ * committed like the proxy; the token is a secret of its own
164
+ * (`BATON_VAULT_TOKEN` on the worker, the OS store in the app).
165
+ */
166
+ export interface VaultSettings {
167
+ /** `https://vault.example:8200` — scheme and host, no trailing path. */
168
+ address: string;
169
+ /** Vault Enterprise / HCP namespace, sent as `X-Vault-Namespace`. */
170
+ namespace?: string;
171
+ }
172
+ export interface ClientCertificateConfig {
173
+ /** `api.corp.example` exact, `*.corp.example` for subdomains, `*` for all. */
174
+ hostPattern: string;
175
+ /** Secret names whose values are the PEM texts (invariant 2). */
176
+ certSecret: string;
177
+ keySecret: string;
178
+ passphraseSecret?: string;
179
+ }
180
+ export interface TlsSettings {
181
+ /** Workspace-relative PEM bundle appended to the system trust roots. */
182
+ caFile?: string;
183
+ clientCertificates: ClientCertificateConfig[];
184
+ }
185
+ export interface ProxyConfig {
186
+ /** `http://host:port` (or `https://`) of the proxy itself. */
187
+ url: string;
188
+ /** Host patterns that go direct — same matcher as TLS host binding. */
189
+ noProxy: string[];
190
+ /** Secret names for proxy Basic auth (invariant 2); both or neither. */
191
+ usernameSecret?: string;
192
+ passwordSecret?: string;
128
193
  }
129
194
  export interface WorkspaceSettings {
130
195
  followRedirects: boolean;
131
196
  timeoutMs: number;
132
197
  validateTls: boolean;
198
+ /** Custom CA and client certificates; absent means system defaults only. */
199
+ tls?: TlsSettings;
200
+ /** Outbound proxy; absent means direct (or the platform environment). */
201
+ proxy?: ProxyConfig;
202
+ /** The workspace's Vault; absent means no secret may name a Vault path. */
203
+ vault?: VaultSettings;
133
204
  }
134
205
  export declare const DEFAULT_SETTINGS: WorkspaceSettings;
135
206
  /** `baton.yaml` — the workspace manifest. */
@@ -162,3 +233,28 @@ export interface SchedulesFile {
162
233
  format: number;
163
234
  schedules: Schedule[];
164
235
  }
236
+ /**
237
+ * One saved response for a request: what a real call answered, or what the
238
+ * API is meant to answer. Lives beside the request in `<slug>.examples.yaml`.
239
+ */
240
+ export interface ResponseExample {
241
+ name: string;
242
+ status: number;
243
+ headers: KeyValueRow[];
244
+ body: string;
245
+ }
246
+ /** `<slug>.examples.yaml`: the examples a request carries, in order. */
247
+ export interface ExamplesFile {
248
+ format: number;
249
+ examples: ResponseExample[];
250
+ }
251
+ /** `mocks/<name>.yaml`: a mock server stood up from examples. */
252
+ export interface MockFile {
253
+ format: number;
254
+ name: string;
255
+ port: number;
256
+ /** Workspace-relative collection paths whose requests the mock answers. */
257
+ collections: string[];
258
+ /** The example to answer with, by name; the first one when absent. */
259
+ example?: string;
260
+ }
@@ -0,0 +1,15 @@
1
+ /** A reference into KV v2: `<mount>/<path>#<key>` — a location, never a value. */
2
+ export interface VaultRef {
3
+ mount: string;
4
+ path: string;
5
+ key: string;
6
+ }
7
+ /**
8
+ * Parses `<mount>/<path>#<key>`; throws a FormatError at `fieldPath` on
9
+ * anything else. Mount and path parts may not be empty, contain whitespace,
10
+ * or walk upward (`..`), so a reference cannot escape the mount it names.
11
+ * Mirrors `VaultRef.parse` in baton_core (invariant 6).
12
+ */
13
+ export declare function parseVaultRef(text: string, fieldPath: string): VaultRef;
14
+ /** The canonical text form — what the writer emits. */
15
+ export declare function formatVaultRef(ref: VaultRef): string;
@@ -0,0 +1,32 @@
1
+ import { FormatError } from "./errors.js";
2
+ /**
3
+ * Parses `<mount>/<path>#<key>`; throws a FormatError at `fieldPath` on
4
+ * anything else. Mount and path parts may not be empty, contain whitespace,
5
+ * or walk upward (`..`), so a reference cannot escape the mount it names.
6
+ * Mirrors `VaultRef.parse` in baton_core (invariant 6).
7
+ */
8
+ export function parseVaultRef(text, fieldPath) {
9
+ const bad = (reason) => new FormatError("invalid-field", fieldPath, reason);
10
+ const hash = text.indexOf("#");
11
+ if (hash < 0 || text.indexOf("#", hash + 1) >= 0)
12
+ throw bad("must be <mount>/<path>#<key>");
13
+ const location = text.slice(0, hash);
14
+ const key = text.slice(hash + 1);
15
+ if (key === "" || /\s/.test(key))
16
+ throw bad("key after # must be a non-empty word");
17
+ const slash = location.indexOf("/");
18
+ if (slash <= 0 || slash === location.length - 1)
19
+ throw bad("must be <mount>/<path>#<key>");
20
+ const segments = location.split("/");
21
+ for (const segment of segments) {
22
+ if (segment === "" || segment === "." || segment === ".." || /\s/.test(segment)) {
23
+ throw bad("mount and path segments must be non-empty words");
24
+ }
25
+ }
26
+ return { mount: segments[0], path: segments.slice(1).join("/"), key };
27
+ }
28
+ /** The canonical text form — what the writer emits. */
29
+ export function formatVaultRef(ref) {
30
+ return `${ref.mount}/${ref.path}#${ref.key}`;
31
+ }
32
+ //# sourceMappingURL=vault.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudko.dev/baton-format",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Baton workspace file format: parsing, validation, and deterministic serialization.",
5
5
  "keywords": ["baton", "api-client", "yaml", "workspace", "format"],
6
6
  "homepage": "https://baton.dudko.dev",