@dudko.dev/baton-format 0.1.0 → 0.1.2
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/src/parse.js +73 -1
- package/dist/src/serialize.js +50 -1
- package/dist/src/types.d.ts +41 -0
- package/package.json +1 -1
package/dist/src/parse.js
CHANGED
|
@@ -171,6 +171,42 @@ function parseAuth(obj, path) {
|
|
|
171
171
|
},
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
|
+
case "digest": {
|
|
175
|
+
checkKeys(auth, ["type", "digest"], authPath);
|
|
176
|
+
const cfg = optRecord(auth, "digest", authPath);
|
|
177
|
+
if (cfg === undefined) {
|
|
178
|
+
throw new FormatError("missing-field", join(authPath, "digest"), "required field is missing");
|
|
179
|
+
}
|
|
180
|
+
const cfgPath = join(authPath, "digest");
|
|
181
|
+
checkKeys(cfg, ["username", "password"], cfgPath);
|
|
182
|
+
return {
|
|
183
|
+
type: "digest",
|
|
184
|
+
digest: {
|
|
185
|
+
username: reqString(cfg, "username", cfgPath),
|
|
186
|
+
password: reqString(cfg, "password", cfgPath),
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
case "awsSigV4": {
|
|
191
|
+
checkKeys(auth, ["type", "awsSigV4"], authPath);
|
|
192
|
+
const cfg = optRecord(auth, "awsSigV4", authPath);
|
|
193
|
+
if (cfg === undefined) {
|
|
194
|
+
throw new FormatError("missing-field", join(authPath, "awsSigV4"), "required field is missing");
|
|
195
|
+
}
|
|
196
|
+
const cfgPath = join(authPath, "awsSigV4");
|
|
197
|
+
checkKeys(cfg, ["accessKey", "secretKey", "sessionToken", "region", "service"], cfgPath);
|
|
198
|
+
const sessionToken = optString(cfg, "sessionToken", cfgPath);
|
|
199
|
+
return {
|
|
200
|
+
type: "awsSigV4",
|
|
201
|
+
awsSigV4: {
|
|
202
|
+
accessKey: reqString(cfg, "accessKey", cfgPath),
|
|
203
|
+
secretKey: reqString(cfg, "secretKey", cfgPath),
|
|
204
|
+
...(sessionToken !== undefined ? { sessionToken } : {}),
|
|
205
|
+
region: reqString(cfg, "region", cfgPath),
|
|
206
|
+
service: reqString(cfg, "service", cfgPath),
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
174
210
|
case "bearer": {
|
|
175
211
|
checkKeys(auth, ["type", "bearer"], authPath);
|
|
176
212
|
const cfg = optRecord(auth, "bearer", authPath);
|
|
@@ -392,11 +428,47 @@ export function parseWorkspaceManifest(text) {
|
|
|
392
428
|
const settingsObj = optRecord(obj, "settings", "");
|
|
393
429
|
let settings = { ...DEFAULT_SETTINGS };
|
|
394
430
|
if (settingsObj !== undefined) {
|
|
395
|
-
checkKeys(settingsObj, ["followRedirects", "timeoutMs", "validateTls"], "settings");
|
|
431
|
+
checkKeys(settingsObj, ["followRedirects", "timeoutMs", "validateTls", "tls", "proxy"], "settings");
|
|
432
|
+
let tls = { clientCertificates: [] };
|
|
433
|
+
const tlsObj = optRecord(settingsObj, "tls", "settings");
|
|
434
|
+
if (tlsObj !== undefined) {
|
|
435
|
+
checkKeys(tlsObj, ["caFile", "clientCertificates"], "settings.tls");
|
|
436
|
+
const caFile = optString(tlsObj, "caFile", "settings.tls");
|
|
437
|
+
tls = {
|
|
438
|
+
...(caFile !== undefined ? { caFile } : {}),
|
|
439
|
+
clientCertificates: optArray(tlsObj, "clientCertificates", "settings.tls").map((item, i) => {
|
|
440
|
+
const itemPath = `settings.tls.clientCertificates[${i}]`;
|
|
441
|
+
const cert = itemRecord(item, itemPath);
|
|
442
|
+
checkKeys(cert, ["hostPattern", "certSecret", "keySecret", "passphraseSecret"], itemPath);
|
|
443
|
+
const passphraseSecret = optString(cert, "passphraseSecret", itemPath);
|
|
444
|
+
return {
|
|
445
|
+
hostPattern: reqString(cert, "hostPattern", itemPath),
|
|
446
|
+
certSecret: reqString(cert, "certSecret", itemPath),
|
|
447
|
+
keySecret: reqString(cert, "keySecret", itemPath),
|
|
448
|
+
...(passphraseSecret !== undefined ? { passphraseSecret } : {}),
|
|
449
|
+
};
|
|
450
|
+
}),
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
let proxy;
|
|
454
|
+
const proxyObj = optRecord(settingsObj, "proxy", "settings");
|
|
455
|
+
if (proxyObj !== undefined) {
|
|
456
|
+
checkKeys(proxyObj, ["url", "noProxy", "usernameSecret", "passwordSecret"], "settings.proxy");
|
|
457
|
+
const usernameSecret = optString(proxyObj, "usernameSecret", "settings.proxy");
|
|
458
|
+
const passwordSecret = optString(proxyObj, "passwordSecret", "settings.proxy");
|
|
459
|
+
proxy = {
|
|
460
|
+
url: reqString(proxyObj, "url", "settings.proxy"),
|
|
461
|
+
noProxy: parseStringList(proxyObj, "noProxy", "settings.proxy"),
|
|
462
|
+
...(usernameSecret !== undefined ? { usernameSecret } : {}),
|
|
463
|
+
...(passwordSecret !== undefined ? { passwordSecret } : {}),
|
|
464
|
+
};
|
|
465
|
+
}
|
|
396
466
|
settings = {
|
|
397
467
|
followRedirects: optBool(settingsObj, "followRedirects", "settings", DEFAULT_SETTINGS.followRedirects),
|
|
398
468
|
timeoutMs: optInt(settingsObj, "timeoutMs", "settings", DEFAULT_SETTINGS.timeoutMs),
|
|
399
469
|
validateTls: optBool(settingsObj, "validateTls", "settings", DEFAULT_SETTINGS.validateTls),
|
|
470
|
+
...(tls.caFile !== undefined || tls.clientCertificates.length > 0 ? { tls } : {}),
|
|
471
|
+
...(proxy !== undefined ? { proxy } : {}),
|
|
400
472
|
};
|
|
401
473
|
}
|
|
402
474
|
const description = optString(obj, "description", "");
|
package/dist/src/serialize.js
CHANGED
|
@@ -153,6 +153,21 @@ function emitAuth(out, indent, auth) {
|
|
|
153
153
|
out.kv(indent + 4, "username", auth.basic.username);
|
|
154
154
|
out.kv(indent + 4, "password", auth.basic.password);
|
|
155
155
|
break;
|
|
156
|
+
case "digest":
|
|
157
|
+
out.line(indent + 2, "digest:");
|
|
158
|
+
out.kv(indent + 4, "username", auth.digest.username);
|
|
159
|
+
out.kv(indent + 4, "password", auth.digest.password);
|
|
160
|
+
break;
|
|
161
|
+
case "awsSigV4":
|
|
162
|
+
out.line(indent + 2, "awsSigV4:");
|
|
163
|
+
out.kv(indent + 4, "accessKey", auth.awsSigV4.accessKey);
|
|
164
|
+
out.kv(indent + 4, "secretKey", auth.awsSigV4.secretKey);
|
|
165
|
+
if (auth.awsSigV4.sessionToken !== undefined) {
|
|
166
|
+
out.kv(indent + 4, "sessionToken", auth.awsSigV4.sessionToken);
|
|
167
|
+
}
|
|
168
|
+
out.kv(indent + 4, "region", auth.awsSigV4.region);
|
|
169
|
+
out.kv(indent + 4, "service", auth.awsSigV4.service);
|
|
170
|
+
break;
|
|
156
171
|
case "bearer":
|
|
157
172
|
out.line(indent + 2, "bearer:");
|
|
158
173
|
out.kv(indent + 4, "token", auth.bearer.token);
|
|
@@ -296,10 +311,44 @@ export function serializeWorkspaceManifest(ws) {
|
|
|
296
311
|
nonDefault.push(["timeoutMs", s.timeoutMs]);
|
|
297
312
|
if (s.validateTls !== DEFAULT_SETTINGS.validateTls)
|
|
298
313
|
nonDefault.push(["validateTls", s.validateTls]);
|
|
299
|
-
|
|
314
|
+
const tls = s.tls ?? { clientCertificates: [] };
|
|
315
|
+
const tlsEmpty = tls.caFile === undefined && tls.clientCertificates.length === 0;
|
|
316
|
+
const proxy = s.proxy;
|
|
317
|
+
if (nonDefault.length > 0 || !tlsEmpty || proxy !== undefined) {
|
|
300
318
|
out.line(0, "settings:");
|
|
301
319
|
for (const [key, value] of nonDefault)
|
|
302
320
|
out.kv(2, key, value);
|
|
321
|
+
if (!tlsEmpty) {
|
|
322
|
+
out.line(2, "tls:");
|
|
323
|
+
if (tls.caFile !== undefined)
|
|
324
|
+
out.kv(4, "caFile", tls.caFile);
|
|
325
|
+
if (tls.clientCertificates.length > 0) {
|
|
326
|
+
out.line(4, "clientCertificates:");
|
|
327
|
+
for (const cert of tls.clientCertificates) {
|
|
328
|
+
out.line(6, `- hostPattern: ${scalar(cert.hostPattern)}`);
|
|
329
|
+
out.kv(8, "certSecret", cert.certSecret);
|
|
330
|
+
out.kv(8, "keySecret", cert.keySecret);
|
|
331
|
+
if (cert.passphraseSecret !== undefined) {
|
|
332
|
+
out.kv(8, "passphraseSecret", cert.passphraseSecret);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (proxy !== undefined) {
|
|
338
|
+
out.line(2, "proxy:");
|
|
339
|
+
out.kv(4, "url", proxy.url);
|
|
340
|
+
if (proxy.noProxy.length > 0) {
|
|
341
|
+
out.line(4, "noProxy:");
|
|
342
|
+
for (const pattern of proxy.noProxy)
|
|
343
|
+
out.line(6, `- ${scalar(pattern)}`);
|
|
344
|
+
}
|
|
345
|
+
if (proxy.usernameSecret !== undefined) {
|
|
346
|
+
out.kv(4, "usernameSecret", proxy.usernameSecret);
|
|
347
|
+
}
|
|
348
|
+
if (proxy.passwordSecret !== undefined) {
|
|
349
|
+
out.kv(4, "passwordSecret", proxy.passwordSecret);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
303
352
|
}
|
|
304
353
|
return out.toString();
|
|
305
354
|
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -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: {
|
|
@@ -126,10 +141,36 @@ export interface EnvironmentFile {
|
|
|
126
141
|
/** Secret names only — values never live in the workspace. */
|
|
127
142
|
secrets: string[];
|
|
128
143
|
}
|
|
144
|
+
export interface ClientCertificateConfig {
|
|
145
|
+
/** `api.corp.example` exact, `*.corp.example` for subdomains, `*` for all. */
|
|
146
|
+
hostPattern: string;
|
|
147
|
+
/** Secret names whose values are the PEM texts (invariant 2). */
|
|
148
|
+
certSecret: string;
|
|
149
|
+
keySecret: string;
|
|
150
|
+
passphraseSecret?: string;
|
|
151
|
+
}
|
|
152
|
+
export interface TlsSettings {
|
|
153
|
+
/** Workspace-relative PEM bundle appended to the system trust roots. */
|
|
154
|
+
caFile?: string;
|
|
155
|
+
clientCertificates: ClientCertificateConfig[];
|
|
156
|
+
}
|
|
157
|
+
export interface ProxyConfig {
|
|
158
|
+
/** `http://host:port` (or `https://`) of the proxy itself. */
|
|
159
|
+
url: string;
|
|
160
|
+
/** Host patterns that go direct — same matcher as TLS host binding. */
|
|
161
|
+
noProxy: string[];
|
|
162
|
+
/** Secret names for proxy Basic auth (invariant 2); both or neither. */
|
|
163
|
+
usernameSecret?: string;
|
|
164
|
+
passwordSecret?: string;
|
|
165
|
+
}
|
|
129
166
|
export interface WorkspaceSettings {
|
|
130
167
|
followRedirects: boolean;
|
|
131
168
|
timeoutMs: number;
|
|
132
169
|
validateTls: boolean;
|
|
170
|
+
/** Custom CA and client certificates; absent means system defaults only. */
|
|
171
|
+
tls?: TlsSettings;
|
|
172
|
+
/** Outbound proxy; absent means direct (or the platform environment). */
|
|
173
|
+
proxy?: ProxyConfig;
|
|
133
174
|
}
|
|
134
175
|
export declare const DEFAULT_SETTINGS: WorkspaceSettings;
|
|
135
176
|
/** `baton.yaml` — the workspace manifest. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudko.dev/baton-format",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|