@t0.labs/daxta 0.4.12 → 0.4.14

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/README.md CHANGED
@@ -128,12 +128,12 @@ Company-wide choices (saved in `daxta.config.ts`):
128
128
 
129
129
  | Option | Meaning |
130
130
  | --- | --- |
131
- | `treeLayout` | `role-resource` (`v1 › admin › baskets`) or `resource-role` (`v1 › baskets › admin`) — sidebar **and** OpenAPI export path keys |
131
+ | `treeLayout` | `role-resource` (`v1 › admin › baskets`) or `resource-role` (`v1 › baskets › admin`) — sidebar **and** Postman export folders |
132
132
  | `treeSkipParams` | Don’t nest folders under `{id}` (recommended `true`) |
133
133
  | `envPresets` | Multi-base Try-it presets (`local` / `staging` / `production` + optional variables) |
134
134
  | `exampleLabelStyle` | OpenAPI example labels: `status-title-case` / `status-case` / `full` |
135
135
 
136
- OpenAPI export remaps path keys to match the sidebar tree. Real URLs are kept on `x-daxta-url-path` when the layout differs (e.g. `/v1/admin/baskets` → export `/v1/baskets/admin`).
136
+ OpenAPI path keys in the generated spec still follow the sidebar tree. Real URLs stay on `x-daxta-url-path` when the layout differs (e.g. `/v1/admin/baskets` → tree `/v1/baskets/admin`).
137
137
 
138
138
  ### Try-it env / headers (persisted)
139
139
 
@@ -156,14 +156,7 @@ envPresets: {
156
156
 
157
157
  Sidebar: expand the chevron on an endpoint to list recorded examples underneath; click one to open it in the workbench.
158
158
 
159
- Export: the download button opens a picker (All / None / Success only) so the OpenAPI JSON only includes the selected examples.
160
-
161
- For Postman-friendly fills, export can bake the **active Try-it env + header group** into the OpenAPI (`servers` + header `example`s). Two modes:
162
-
163
- - **Resolved values** — literals in the OpenAPI (import with parameter generation = Example)
164
- - **Postman `{{variables}}`** — placeholders in OpenAPI + a companion `.postman_environment.json`
165
-
166
- Also download **Postman Collection** (default on): example names stay as `201 — should create…` instead of generic `Created` / `Bad Request` (Postman’s OpenAPI importer names examples from status description).
159
+ Export: download is **Postman Collection** (nested folders like the sidebar) plus, by default, the active Try-it **environment + header group** as a `.postman_environment.json`. Pick All / None / Success only for which examples to include. Import the collection, then the environment, and select that env in Postman.
167
160
 
168
161
  Example label (`status-title-case`):
169
162
 
@@ -642,28 +642,6 @@
642
642
  color: var(--stone);
643
643
  font-family: var(--mono);
644
644
  }
645
- .export-mode {
646
- display: flex;
647
- flex-direction: column;
648
- gap: 6px;
649
- margin-left: 22px;
650
- }
651
- .export-mode label {
652
- display: flex;
653
- align-items: flex-start;
654
- gap: 8px;
655
- font-size: 12px;
656
- color: var(--charcoal);
657
- cursor: pointer;
658
- line-height: 1.35;
659
- }
660
- .export-mode.disabled { opacity: 0.45; pointer-events: none; }
661
- .export-tip {
662
- margin: 0 0 0 22px;
663
- font-size: 11px;
664
- color: var(--stone);
665
- line-height: 1.4;
666
- }
667
645
  .export-toolbar {
668
646
  display: flex;
669
647
  flex-wrap: wrap;
@@ -1097,7 +1075,7 @@
1097
1075
  <div class="search-panel" id="search-panel" role="listbox"></div>
1098
1076
  </div>
1099
1077
  <div class="nav-tools">
1100
- <button class="btn icon" id="export-openapi" type="button" data-tip="Export OpenAPI" aria-label="Export OpenAPI">
1078
+ <button class="btn icon" id="export-openapi" type="button" data-tip="Export Postman" aria-label="Export Postman">
1101
1079
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
1102
1080
  </button>
1103
1081
  <div class="env-wrap" id="env-wrap">
@@ -1110,30 +1088,15 @@
1110
1088
  <div class="export-backdrop" id="export-backdrop" role="dialog" aria-modal="true" aria-labelledby="export-title">
1111
1089
  <div class="export-modal" id="export-modal">
1112
1090
  <div class="export-head">
1113
- <h2 id="export-title">Export OpenAPI</h2>
1114
- <p>Choose examples to include. Optionally bake Try-it env/headers so Postman can auto-fill on import.</p>
1091
+ <h2 id="export-title">Export Postman</h2>
1092
+ <p>Pick examples, then download a Collection with the docs folder tree. Env + headers come from the active Try-it preset.</p>
1115
1093
  </div>
1116
1094
  <div class="export-options">
1117
1095
  <label class="export-check">
1118
1096
  <input type="checkbox" id="export-include-tryit" checked />
1119
- <span>Include active Try-it env + header group</span>
1097
+ <span>Include env + headers <span style="color:var(--stone)">(Collection uses <code>{{baseUrl}}</code> / <code>{{vars}}</code> + environment file)</span></span>
1120
1098
  </label>
1121
1099
  <div class="export-tryit-meta" id="export-tryit-meta">—</div>
1122
- <div class="export-mode" id="export-mode-wrap">
1123
- <label>
1124
- <input type="radio" name="export-fill" value="resolved" checked />
1125
- <span>Resolved values in OpenAPI <span style="color:var(--stone)">(headers/server filled literally)</span></span>
1126
- </label>
1127
- <label>
1128
- <input type="radio" name="export-fill" value="variables" />
1129
- <span>Postman <code>{{variables}}</code> + download environment file</span>
1130
- </label>
1131
- </div>
1132
- <p class="export-tip">Postman names saved examples from OpenAPI <em>response description</em> (“Created”), so also download a Collection with the real scenario titles. Import → advanced → parameter generation = <strong>Example</strong>.</p>
1133
- <label class="export-check">
1134
- <input type="checkbox" id="export-postman-collection" checked />
1135
- <span>Also download Postman Collection <span style="color:var(--stone)">(named examples)</span></span>
1136
- </label>
1137
1100
  </div>
1138
1101
  <div class="export-toolbar">
1139
1102
  <button type="button" class="btn sm" id="export-all">All</button>
@@ -2139,64 +2102,6 @@
2139
2102
  return groups[store.activeGroup] || groups[Object.keys(groups)[0]] || [];
2140
2103
  };
2141
2104
 
2142
- const applyTryItFill = (exported, fillMode) => {
2143
- const vars = varMap();
2144
- const rows = headerRowsForExport();
2145
- const finalServer =
2146
- fillMode === "variables" ? "{{baseUrl}}" : String(interpolate(vars.baseUrl || defaultBaseUrl, vars)).replace(/\/$/, "") || defaultBaseUrl;
2147
-
2148
- exported.servers = [{ url: finalServer }];
2149
-
2150
- const paths = exported.paths || {};
2151
- for (const pathItem of Object.values(paths)) {
2152
- if (!pathItem || typeof pathItem !== "object") continue;
2153
- for (const method of HTTP_EXPORT) {
2154
- if (!pathItem[method] || typeof pathItem[method] !== "object") continue;
2155
- const operation = { ...pathItem[method] };
2156
- const params = Array.isArray(operation.parameters) ? operation.parameters.map((p) => ({ ...p })) : [];
2157
-
2158
- for (const row of rows) {
2159
- if (!row.key) continue;
2160
- const lower = String(row.key).toLowerCase();
2161
- if (lower === "host" || lower === "content-length") continue;
2162
- const exampleValue =
2163
- fillMode === "resolved"
2164
- ? String(interpolate(row.value || "", vars))
2165
- : String(row.value ?? "");
2166
- const existing = params.findIndex(
2167
- (param) => param && param.in === "header" && String(param.name).toLowerCase() === lower,
2168
- );
2169
- if (existing >= 0) {
2170
- const prev = params[existing];
2171
- params[existing] = {
2172
- ...prev,
2173
- required: prev.required !== false,
2174
- example: exampleValue,
2175
- schema: {
2176
- ...(prev.schema && typeof prev.schema === "object" ? prev.schema : {}),
2177
- type: "string",
2178
- example: exampleValue,
2179
- },
2180
- };
2181
- } else {
2182
- params.push({
2183
- name: row.key,
2184
- in: "header",
2185
- required: true,
2186
- schema: { type: "string", example: exampleValue },
2187
- example: exampleValue,
2188
- });
2189
- }
2190
- }
2191
-
2192
- operation.parameters = params;
2193
- pathItem[method] = operation;
2194
- }
2195
- }
2196
-
2197
- return exported;
2198
- };
2199
-
2200
2105
  const buildPostmanEnvironment = () => {
2201
2106
  const env = activeEnvConfig();
2202
2107
  const values = (env.variables || [])
@@ -2209,6 +2114,15 @@
2209
2114
  }));
2210
2115
  // Ensure header template vars referenced as {{x}} appear even if missing from variables list.
2211
2116
  const known = new Set(values.map((row) => row.key));
2117
+ if (!known.has("baseUrl")) {
2118
+ known.add("baseUrl");
2119
+ values.unshift({
2120
+ key: "baseUrl",
2121
+ value: String(presetBaseUrl(store.activeEnv) || defaultBaseUrl || ""),
2122
+ type: "default",
2123
+ enabled: true,
2124
+ });
2125
+ }
2212
2126
  for (const row of headerRowsForExport()) {
2213
2127
  const text = String(row.value || "");
2214
2128
  const matches = text.matchAll(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g);
@@ -2286,12 +2200,30 @@
2286
2200
  return [...folders, ...requests];
2287
2201
  };
2288
2202
 
2203
+ const collectionRequestHeaders = (operation, includeTryIt) => {
2204
+ const byLower = new Map();
2205
+ const add = (key, value) => {
2206
+ if (!key) return;
2207
+ const lower = String(key).toLowerCase();
2208
+ if (lower === "host" || lower === "content-length") return;
2209
+ byLower.set(lower, { key, value: value != null ? String(value) : "", type: "text" });
2210
+ };
2211
+ for (const param of operation.parameters || []) {
2212
+ if (param && param.in === "header" && param.name) add(param.name, param.example != null ? param.example : "");
2213
+ }
2214
+ if (includeTryIt) {
2215
+ for (const row of headerRowsForExport()) add(row.key, row.value ?? "");
2216
+ }
2217
+ return [...byLower.values()];
2218
+ };
2219
+
2289
2220
  /**
2290
- * Postman Collection v2.1 — example `name` = scenario title (not "Created" / "Bad Request").
2291
- * Folders follow the docs tree (v1 → admin → product), not a single joined tag.
2221
+ * Postman Collection v2.1 — nested folders + named examples.
2222
+ * When includeTryIt, requests use {{baseUrl}} and the active header group; env file is downloaded separately.
2292
2223
  */
2293
- const buildPostmanCollection = (openapi) => {
2294
- const serverUrl = (openapi.servers && openapi.servers[0] && openapi.servers[0].url) || "{{baseUrl}}";
2224
+ const buildPostmanCollection = (openapi, includeTryIt) => {
2225
+ const specServer = (openapi.servers && openapi.servers[0] && openapi.servers[0].url) || "{{baseUrl}}";
2226
+ const serverUrl = includeTryIt ? "{{baseUrl}}" : specServer;
2295
2227
  const root = [];
2296
2228
 
2297
2229
  for (const [urlPath, pathItem] of Object.entries(openapi.paths || {})) {
@@ -2300,13 +2232,7 @@
2300
2232
  const operation = pathItem[method];
2301
2233
  if (!operation || typeof operation !== "object") continue;
2302
2234
  const requestPath = operation["x-daxta-url-path"] || urlPath;
2303
-
2304
- const headerParams = (operation.parameters || []).filter((param) => param && param.in === "header" && param.name);
2305
- const requestHeaders = headerParams.map((param) => ({
2306
- key: param.name,
2307
- value: param.example != null ? String(param.example) : "",
2308
- type: "text",
2309
- }));
2235
+ const requestHeaders = collectionRequestHeaders(operation, includeTryIt);
2310
2236
 
2311
2237
  const reqExamples = operation.requestBody?.content?.["application/json"]?.examples || {};
2312
2238
  const firstReq = Object.values(reqExamples)[0];
@@ -2395,10 +2321,7 @@
2395
2321
 
2396
2322
  const syncExportTryItUi = () => {
2397
2323
  const meta = document.getElementById("export-tryit-meta");
2398
- const modeWrap = document.getElementById("export-mode-wrap");
2399
- const include = document.getElementById("export-include-tryit");
2400
2324
  if (meta) meta.textContent = store.activeEnv + " · " + store.activeGroup;
2401
- if (modeWrap) modeWrap.classList.toggle("disabled", !(include && include.checked));
2402
2325
  };
2403
2326
 
2404
2327
  const openExportModal = () => {
@@ -2457,35 +2380,19 @@
2457
2380
  String(workspace || title || "openapi")
2458
2381
  .toLowerCase()
2459
2382
  .replace(/[^a-z0-9]+/g, "-")
2460
- .replace(/^-|-$/g, "") || "openapi";
2383
+ .replace(/^-|-$/g, "") || "daxta";
2461
2384
 
2462
2385
  const runExportDownload = () => {
2463
2386
  const selectedByOpId = collectSelectedExamples();
2464
- let exported = toExportSpec(spec, selectedByOpId);
2387
+ const exported = toExportSpec(spec, selectedByOpId);
2465
2388
  const includeTryIt = Boolean(document.getElementById("export-include-tryit")?.checked);
2466
- const wantCollection = Boolean(document.getElementById("export-postman-collection")?.checked);
2467
- const fillMode =
2468
- document.querySelector('input[name="export-fill"]:checked')?.value === "variables" ? "variables" : "resolved";
2469
2389
  const base = exportSafeName();
2470
2390
 
2391
+ downloadJsonFile(base + ".postman_collection.json", buildPostmanCollection(exported, includeTryIt));
2471
2392
  if (includeTryIt) {
2472
- exported = applyTryItFill(exported, fillMode);
2473
- }
2474
-
2475
- downloadJsonFile(base + ".openapi.json", exported);
2476
-
2477
- let delay = 120;
2478
- if (wantCollection) {
2479
- setTimeout(() => {
2480
- downloadJsonFile(base + ".postman_collection.json", buildPostmanCollection(exported));
2481
- }, delay);
2482
- delay += 120;
2483
- }
2484
-
2485
- if (includeTryIt && fillMode === "variables") {
2486
2393
  setTimeout(() => {
2487
2394
  downloadJsonFile(base + ".postman_environment.json", buildPostmanEnvironment());
2488
- }, delay);
2395
+ }, 120);
2489
2396
  }
2490
2397
  };
2491
2398
 
@@ -2498,7 +2405,6 @@
2498
2405
  if (event.target.id === "export-backdrop") closeExportModal();
2499
2406
  });
2500
2407
  document.getElementById("export-modal").addEventListener("click", (event) => event.stopPropagation());
2501
- document.getElementById("export-include-tryit").addEventListener("change", syncExportTryItUi);
2502
2408
  document.getElementById("export-all").addEventListener("click", () => {
2503
2409
  document.querySelectorAll("#export-body input[type=checkbox]").forEach((input) => {
2504
2410
  input.checked = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {