@t0.labs/daxta 0.3.3 → 0.3.5

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.
@@ -1358,8 +1358,19 @@
1358
1358
  return currentBaseUrl() + path + (qs ? "?" + qs : "");
1359
1359
  };
1360
1360
 
1361
+ /** Headers for this recorded example; fall back to env group only if none were recorded. */
1362
+ const requestHeadersForScenario = (scenario) => {
1363
+ const recorded = { ...(scenario.headers || {}) };
1364
+ const vars = varMap();
1365
+ for (const [name, value] of Object.entries(recorded)) {
1366
+ recorded[name] = String(interpolate(value, vars));
1367
+ }
1368
+ if (Object.keys(recorded).length) return recorded;
1369
+ return resolvedHeaders();
1370
+ };
1371
+
1361
1372
  const toCurl = (item, scenario) => {
1362
- const headers = resolvedHeaders();
1373
+ const headers = requestHeadersForScenario(scenario);
1363
1374
  const body = scenario.reqBody !== undefined ? interpolate(scenario.reqBody, varMap()) : undefined;
1364
1375
  const lines = ["curl -X " + item.method.toUpperCase() + " '" + resolvedUrl(item, scenario).replace(/'/g, "'\\''") + "'"];
1365
1376
  for (const [name, value] of Object.entries(headers)) {
@@ -1384,7 +1395,7 @@
1384
1395
 
1385
1396
  const sendRequest = async (item, scenario) => {
1386
1397
  const target = resolvedUrl(item, scenario);
1387
- const headers = { ...resolvedHeaders() };
1398
+ const headers = { ...requestHeadersForScenario(scenario) };
1388
1399
  const body = scenario.reqBody !== undefined ? interpolate(scenario.reqBody, varMap()) : undefined;
1389
1400
  if (body !== undefined && !headers["content-type"] && !headers["Content-Type"]) {
1390
1401
  headers["content-type"] = "application/json";
@@ -1675,6 +1686,7 @@
1675
1686
  const fields = item.docs.fields || [];
1676
1687
  ensureRequiredHeaderGroup(item.op);
1677
1688
  const injectedHeaders = resolvedHeaders();
1689
+ const recordedHeaders = scenario.headers || {};
1678
1690
  const recordedOk = scenario.status >= 200 && scenario.status < 300;
1679
1691
  const statusText = STATUS[scenario.status] || item.op.responses?.[String(scenario.status)]?.description || "";
1680
1692
  const emptyResponse = scenario.resBody === undefined || scenario.status === 204;
@@ -1687,9 +1699,13 @@
1687
1699
  const displayEmpty = showingLive ? displayBody === undefined || displayBody === "" : emptyResponse;
1688
1700
  const resCopyText = displayEmpty ? null : copyBodyText(displayBody);
1689
1701
  const responseTitle = showingLive ? "Live response" : "Recorded response";
1690
- const headersHtml = Object.keys(injectedHeaders).length
1691
- ? Object.entries(injectedHeaders).map(([name, value]) => kv(name, value)).join("")
1692
- : `<div class="meta-empty">No headers in the active group - pick the required group in the env panel.</div>`;
1702
+ // Request card shows the recorded scenario headers (match this example).
1703
+ // Send / cURL still use env header groups so secrets stay editable.
1704
+ const headersHtml = Object.keys(recordedHeaders).length
1705
+ ? Object.entries(recordedHeaders).map(([name, value]) => kv(name, value)).join("")
1706
+ : Object.keys(injectedHeaders).length
1707
+ ? Object.entries(injectedHeaders).map(([name, value]) => kv(name, value)).join("")
1708
+ : `<div class="meta-empty">No headers recorded for this example</div>`;
1693
1709
  const pathParamsHtml = Object.entries(scenario.pathParams || {})
1694
1710
  .map(([name, value]) => kv(name, value))
1695
1711
  .join("");
@@ -134,6 +134,22 @@ function slug(value, index) {
134
134
  .slice(0, 72);
135
135
  return base || `example-${index + 1}`;
136
136
  }
137
+ function valueFingerprint(value) {
138
+ try {
139
+ return JSON.stringify(value) ?? 'undefined';
140
+ }
141
+ catch {
142
+ return Object.prototype.toString.call(value);
143
+ }
144
+ }
145
+ /** Stable shared key so request + response examples from the same hit stay paired. */
146
+ function exampleKeyForHit(hit, index) {
147
+ const base = slug(exampleLabel(hit), index);
148
+ return `${base}-${index}`;
149
+ }
150
+ function putExample(store, key, summary, value) {
151
+ store[key] = { summary, value };
152
+ }
137
153
  function isPrimaryHit(hit) {
138
154
  if (!hit.test)
139
155
  return false;
@@ -144,15 +160,6 @@ function isPrimaryHit(hit) {
144
160
  return true;
145
161
  return methods.includes(hit.method);
146
162
  }
147
- function addUniqueExample(store, name, value) {
148
- const serialized = JSON.stringify(value);
149
- if (Object.values(store).some((example) => JSON.stringify(example.value) === serialized))
150
- return;
151
- let key = slug(name, Object.keys(store).length);
152
- if (store[key])
153
- key = `${key}-${Object.keys(store).length}`;
154
- store[key] = { summary: name, value };
155
- }
156
163
  function pathParamsFromHit(hit) {
157
164
  if (hit.pathParams && Object.keys(hit.pathParams).length)
158
165
  return hit.pathParams;
@@ -350,7 +357,17 @@ function sortScenarios(scenarios) {
350
357
  function dedupeScenarios(scenarios) {
351
358
  const seen = new Set();
352
359
  return scenarios.filter((scenario) => {
353
- const key = JSON.stringify([scenario.group, scenario.name, scenario.status, scenario.reqBody, scenario.query, scenario.pathParams]);
360
+ // Full request+response fingerprint so matching headers/body stay with each example.
361
+ const key = JSON.stringify([
362
+ scenario.group,
363
+ scenario.name,
364
+ scenario.status,
365
+ scenario.reqBody,
366
+ scenario.resBody,
367
+ scenario.query,
368
+ scenario.pathParams,
369
+ scenario.headers,
370
+ ]);
354
371
  if (seen.has(key))
355
372
  return false;
356
373
  seen.add(key);
@@ -440,14 +457,16 @@ function buildSpec(hits) {
440
457
  const parameters = buildParameters(pathTemplate, opHits);
441
458
  if (parameters.length)
442
459
  operation.parameters = parameters;
443
- for (const hit of opHits) {
460
+ for (let index = 0; index < opHits.length; index += 1) {
461
+ const hit = opHits[index];
444
462
  const label = exampleLabel(hit);
463
+ const exampleKey = exampleKeyForHit(hit, index);
445
464
  if (hit.reqBody !== undefined) {
446
465
  operation.requestBody ??= { required: method === 'post' || method === 'put', content: { 'application/json': { schema: inferSchema(hit.reqBody), examples: {} } } };
447
466
  const media = operation.requestBody.content['application/json'];
448
467
  media.schema = mergeSchema(media.schema, inferSchema(hit.reqBody));
449
468
  media.examples ??= {};
450
- addUniqueExample(media.examples, label, hit.reqBody);
469
+ putExample(media.examples, exampleKey, label, hit.reqBody);
451
470
  }
452
471
  const status = String(hit.status);
453
472
  operation.responses[status] ??= {
@@ -458,7 +477,7 @@ function buildSpec(hits) {
458
477
  const responseMedia = operation.responses[status].content['application/json'];
459
478
  responseMedia.schema = mergeSchema(responseMedia.schema, inferSchema(hit.resBody));
460
479
  responseMedia.examples ??= {};
461
- addUniqueExample(responseMedia.examples, label, hit.resBody);
480
+ putExample(responseMedia.examples, exampleKey, label, hit.resBody);
462
481
  }
463
482
  }
464
483
  operation['x-scenarios'] = sortScenarios(dedupeScenarios(opHits.map(toScenario)));
@@ -515,15 +534,21 @@ function scenarioSignature(scenario) {
515
534
  status: scenario.status,
516
535
  queryKeys: sortedKeys(scenario.query),
517
536
  pathParamKeys: sortedKeys(scenario.pathParams),
537
+ headerKeys: sortedKeys(scenario.headers),
518
538
  reqSchema: signatureSchema(scenario.reqBody),
519
539
  resSchema: signatureSchema(scenario.resBody),
540
+ reqValue: valueFingerprint(scenario.reqBody),
541
+ resValue: valueFingerprint(scenario.resBody),
542
+ headerValue: valueFingerprint(scenario.headers),
543
+ queryValue: valueFingerprint(scenario.query),
544
+ pathParamValue: valueFingerprint(scenario.pathParams),
520
545
  });
521
546
  }
522
- function exampleSummaries(operation) {
523
- const summaries = [];
547
+ function exampleFingerprints(operation) {
548
+ const fingerprints = [];
524
549
  const collect = (examples) => {
525
- for (const example of Object.values(examples ?? {})) {
526
- summaries.push(String(example?.summary ?? ''));
550
+ for (const [key, example] of Object.entries(examples ?? {})) {
551
+ fingerprints.push(`${key}:${example?.summary ?? ''}:${valueFingerprint(example?.value)}`);
527
552
  }
528
553
  };
529
554
  const requestBody = operation.requestBody;
@@ -532,7 +557,7 @@ function exampleSummaries(operation) {
532
557
  for (const response of Object.values(responses)) {
533
558
  collect(response?.content?.['application/json']?.examples);
534
559
  }
535
- return summaries.sort((left, right) => left.localeCompare(right));
560
+ return fingerprints.sort((left, right) => left.localeCompare(right));
536
561
  }
537
562
  function operationSignature(operation) {
538
563
  const scenarios = (operation['x-scenarios'] ?? []).map(scenarioSignature).sort((left, right) => left.localeCompare(right));
@@ -548,7 +573,7 @@ function operationSignature(operation) {
548
573
  security: operation.security,
549
574
  docs: operation['x-docs'],
550
575
  responseStatuses: Object.keys(operation.responses ?? {}).sort(),
551
- examples: exampleSummaries(operation),
576
+ examples: exampleFingerprints(operation),
552
577
  scenarios,
553
578
  });
554
579
  }
@@ -563,8 +588,14 @@ function hitSignature(hit) {
563
588
  test: hit.test,
564
589
  queryKeys: sortedKeys(hit.query),
565
590
  pathParamKeys: sortedKeys(hit.pathParams),
591
+ headerKeys: sortedKeys(hit.headers),
566
592
  reqSchema: signatureSchema(hit.reqBody),
567
593
  resSchema: signatureSchema(hit.resBody),
594
+ reqValue: valueFingerprint(hit.reqBody),
595
+ resValue: valueFingerprint(hit.resBody),
596
+ headerValue: valueFingerprint(hit.headers),
597
+ queryValue: valueFingerprint(hit.query),
598
+ pathParamValue: valueFingerprint(hit.pathParams),
568
599
  });
569
600
  }
570
601
  function hitsStructureSame(existing, fresh) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",