@t0.labs/daxta 1.1.7 → 1.2.0

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/config.d.ts CHANGED
@@ -3,6 +3,8 @@ export type TreeLayout = 'role-resource' | 'resource-role';
3
3
  /** @deprecated use role-resource / resource-role */
4
4
  export type LegacyTreeLayout = 'url-order' | 'resource-first';
5
5
  export type ExampleLabelStyle = 'status-case' | 'status-title-case' | 'full';
6
+ export type WriteMode = 'on-complete' | 'incremental';
7
+ export type SubResourceMode = 'nested' | 'merge' | 'root';
6
8
  export type SpecInfo = {
7
9
  title?: string;
8
10
  version?: string;
@@ -48,7 +50,19 @@ export type DaxtaConfig = {
48
50
  * One level only. Default true.
49
51
  */
50
52
  treeCollapseSingle?: boolean;
53
+ /**
54
+ * How segments after the main resource are grouped into folders:
55
+ * - nested → v1 › shopping-cart › public › items (default)
56
+ * - merge → v1 › shopping-cart-items › public
57
+ * - root → v1 › shopping-cart › public (all sub-routes under main resource)
58
+ */
59
+ treeSubResourceMode?: SubResourceMode;
51
60
  treePathOverrides?: Record<string, string[]>;
61
+ /**
62
+ * Merge multi-segment resource paths into a single folder name, e.g.
63
+ * `{ 'shopping-cart/items': 'shopping-cart-items' }`.
64
+ */
65
+ treeResourceAliases?: Record<string, string>;
52
66
  /**
53
67
  * OpenAPI example + scenario labels:
54
68
  * - status-case → `201 — cyprus payload shape`
@@ -57,6 +71,12 @@ export type DaxtaConfig = {
57
71
  * Ideal it(): docs take the when-clause. Parametric it(): pre-when field context is kept.
58
72
  */
59
73
  exampleLabelStyle?: ExampleLabelStyle;
74
+ /**
75
+ * When to build OpenAPI + HTML during Jest runs:
76
+ * - on-complete → once after all tests finish (fastest, default)
77
+ * - incremental → after each test suite finishes (live updates)
78
+ */
79
+ writeMode?: WriteMode;
60
80
  port?: number;
61
81
  fieldsFile?: string;
62
82
  /**
@@ -77,12 +97,22 @@ export type DaxtaConfig = {
77
97
  operationTag?: (pathTemplate: string, method: string) => string | undefined;
78
98
  operationTitle?: (method: string, pathTemplate: string) => string | undefined;
79
99
  securitySchemeId?: (headerName: string) => string | undefined;
100
+ /**
101
+ * Map recorded header names to Postman/Try-it template values, e.g.:
102
+ * `{ 'x-user-id': '{{X_USER_ID}}', authorization: 'Bearer {{AUTH_TOKEN}}' }`
103
+ */
104
+ headerVariables?: Record<string, string>;
105
+ /**
106
+ * Dynamic header-to-template-value resolver, e.g.:
107
+ * `(name) => \`{{\${name.toUpperCase().replace(/-/g, '_')}}}\``
108
+ */
109
+ headerVariable?: (headerName: string) => string | undefined;
80
110
  specInfo?: () => SpecInfo | undefined;
81
111
  operationOrder?: (opKey: string) => number | undefined;
82
112
  includeHit?: (method: string, pathTemplate: string, test?: string) => boolean;
83
113
  treePathSegments?: (pathTemplate: string) => string[] | undefined;
84
114
  };
85
- export type ResolvedDaxtaConfig = Required<Pick<DaxtaConfig, 'workspace' | 'baseUrl' | 'controllersRoot' | 'outDir' | 'treeLayout' | 'treePathOverrides' | 'treeSkipParams' | 'treeCollapseSingle' | 'exampleLabelStyle' | 'port' | 'fieldsFile' | 'docsPath' | 'viewerStoreFile'>> & DaxtaConfig;
115
+ export type ResolvedDaxtaConfig = Required<Pick<DaxtaConfig, 'workspace' | 'baseUrl' | 'controllersRoot' | 'outDir' | 'treeLayout' | 'treePathOverrides' | 'treeResourceAliases' | 'treeSkipParams' | 'treeCollapseSingle' | 'treeSubResourceMode' | 'exampleLabelStyle' | 'writeMode' | 'port' | 'fieldsFile' | 'docsPath' | 'viewerStoreFile'>> & DaxtaConfig;
86
116
  export declare const DEFAULT_DOCS_PATH = "/docs";
87
117
  export declare function normalizeDocsPath(raw?: string | null): string;
88
118
  export declare function defineConfig(config: DaxtaConfig): DaxtaConfig;
package/dist/config.js CHANGED
@@ -53,8 +53,12 @@ const DEFAULTS = {
53
53
  treeLayout: 'role-resource',
54
54
  treeSkipParams: true,
55
55
  treeCollapseSingle: true,
56
+ treeSubResourceMode: 'nested',
56
57
  treePathOverrides: {},
58
+ treeResourceAliases: {},
59
+ headerVariables: {},
57
60
  exampleLabelStyle: 'status-title-case',
61
+ writeMode: 'on-complete',
58
62
  port: 5199,
59
63
  fieldsFile: '.daxta/out/fields.json',
60
64
  docsPath: '/docs',
@@ -118,6 +122,10 @@ function resolveConfig(cwd = process.cwd(), overrides) {
118
122
  merged.treeCollapseSingle = DEFAULTS.treeCollapseSingle;
119
123
  if (merged.exampleLabelStyle == null)
120
124
  merged.exampleLabelStyle = DEFAULTS.exampleLabelStyle;
125
+ if (merged.writeMode == null)
126
+ merged.writeMode = DEFAULTS.writeMode;
127
+ if (merged.treeSubResourceMode == null)
128
+ merged.treeSubResourceMode = DEFAULTS.treeSubResourceMode;
121
129
  merged.envPresets = normalizeEnvPresets(merged.envPresets, merged.baseUrl);
122
130
  merged.docsPath = normalizeDocsPath(process.env.DAXTA_DOCS_PATH || merged.docsPath);
123
131
  merged.controllersRoot = path.isAbsolute(merged.controllersRoot)
@@ -0,0 +1,150 @@
1
+ type OpenApiExample = {
2
+ summary?: string;
3
+ description?: string;
4
+ value?: unknown;
5
+ };
6
+ type OpenApiScenario = {
7
+ name: string;
8
+ group?: string;
9
+ status: number;
10
+ pathParams?: Record<string, string>;
11
+ query?: Record<string, string>;
12
+ headers?: Record<string, string>;
13
+ reqBody?: unknown;
14
+ resBody?: unknown;
15
+ };
16
+ type OpenApiOperation = {
17
+ summary?: string;
18
+ description?: string;
19
+ tags?: string[];
20
+ security?: Array<Record<string, unknown[]>>;
21
+ parameters?: Array<{
22
+ name: string;
23
+ in: string;
24
+ required?: boolean;
25
+ example?: unknown;
26
+ }>;
27
+ requestBody?: {
28
+ content?: Record<string, {
29
+ examples?: Record<string, OpenApiExample>;
30
+ }>;
31
+ };
32
+ responses?: Record<string, {
33
+ description?: string;
34
+ content?: Record<string, {
35
+ examples?: Record<string, OpenApiExample>;
36
+ }>;
37
+ }>;
38
+ 'x-tree-segments'?: string[];
39
+ 'x-scenarios'?: OpenApiScenario[];
40
+ 'x-daxta-url-path'?: string;
41
+ };
42
+ type OpenApiSpecLike = {
43
+ info?: {
44
+ title?: string;
45
+ version?: string;
46
+ description?: string;
47
+ 'x-workspace'?: string;
48
+ };
49
+ servers?: Array<{
50
+ url?: string;
51
+ description?: string;
52
+ }>;
53
+ paths?: Record<string, Record<string, OpenApiOperation>>;
54
+ };
55
+ export type PostmanHeader = {
56
+ key: string;
57
+ value: string;
58
+ type?: string;
59
+ };
60
+ export type PostmanRequest = {
61
+ method: string;
62
+ header: PostmanHeader[];
63
+ url: {
64
+ raw: string;
65
+ host: string[];
66
+ path: string[];
67
+ query?: Array<{
68
+ key: string;
69
+ value: string;
70
+ }>;
71
+ variable?: Array<{
72
+ key: string;
73
+ value: string;
74
+ }>;
75
+ };
76
+ body?: {
77
+ mode: 'raw';
78
+ raw: string;
79
+ options: {
80
+ raw: {
81
+ language: 'json';
82
+ };
83
+ };
84
+ };
85
+ description?: string;
86
+ };
87
+ export type PostmanResponseExample = {
88
+ name: string;
89
+ originalRequest: PostmanRequest;
90
+ status: string;
91
+ code: number;
92
+ _postman_previewlanguage: 'json';
93
+ header: Array<{
94
+ key: string;
95
+ value: string;
96
+ }>;
97
+ body: string;
98
+ };
99
+ export type PostmanRequestItem = {
100
+ name: string;
101
+ request: PostmanRequest;
102
+ response: PostmanResponseExample[];
103
+ };
104
+ export type PostmanFolderItem = {
105
+ name: string;
106
+ item: Array<PostmanFolderItem | PostmanRequestItem>;
107
+ };
108
+ export type PostmanCollection = {
109
+ info: {
110
+ _postman_id: string;
111
+ name: string;
112
+ description: string;
113
+ schema: string;
114
+ };
115
+ item: Array<PostmanFolderItem | PostmanRequestItem>;
116
+ };
117
+ export type PostmanEnvironment = {
118
+ id: string;
119
+ name: string;
120
+ values: Array<{
121
+ key: string;
122
+ value: string;
123
+ type: 'default' | 'secret';
124
+ enabled: boolean;
125
+ }>;
126
+ _postman_variable_scope: 'environment';
127
+ _postman_exported_at: string;
128
+ _postman_exported_using: string;
129
+ };
130
+ export declare function buildPostmanCollection(spec: OpenApiSpecLike, options?: {
131
+ useEnvVar?: boolean;
132
+ envName?: string;
133
+ }): {
134
+ collection: PostmanCollection;
135
+ operations: number;
136
+ examples: number;
137
+ };
138
+ export declare function buildPostmanEnvironment(envName?: string): PostmanEnvironment;
139
+ export declare function exportPostmanFiles(options?: {
140
+ out?: string;
141
+ envName?: string;
142
+ includeEnv?: boolean;
143
+ useEnvVar?: boolean;
144
+ }): {
145
+ collectionPath: string;
146
+ environmentPath?: string;
147
+ operations: number;
148
+ examples: number;
149
+ };
150
+ export {};
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildPostmanCollection = buildPostmanCollection;
37
+ exports.buildPostmanEnvironment = buildPostmanEnvironment;
38
+ exports.exportPostmanFiles = exportPostmanFiles;
39
+ const crypto_1 = require("crypto");
40
+ const fs_1 = require("fs");
41
+ const path = __importStar(require("path"));
42
+ const catalog_1 = require("../catalog");
43
+ const config_1 = require("../config");
44
+ const paths_1 = require("../serve/paths");
45
+ const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'options', 'head'];
46
+ function postmanUrl(serverUrl, pathTemplate, pathParams, query) {
47
+ const base = (serverUrl || '{{baseUrl}}').replace(/\/$/, '');
48
+ const cleanPath = pathTemplate.startsWith('/') ? pathTemplate : `/${pathTemplate}`;
49
+ const segments = cleanPath.split('/').filter(Boolean);
50
+ const paramKeys = [...cleanPath.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
51
+ const queryEntries = Object.entries(query ?? {}).map(([key, value]) => ({
52
+ key,
53
+ value: value ?? '',
54
+ }));
55
+ const querySuffix = queryEntries.length
56
+ ? `?${queryEntries.map((q) => `${encodeURIComponent(q.key)}=${encodeURIComponent(q.value)}`).join('&')}`
57
+ : '';
58
+ return {
59
+ raw: `${base}${cleanPath.replace(/\{([^}]+)\}/g, ':$1')}${querySuffix}`,
60
+ host: base.startsWith('{{') ? [base] : [base.replace(/^https?:\/\//, '').split('/')[0]],
61
+ path: segments.map((seg) => (seg.startsWith('{') && seg.endsWith('}') ? `:${seg.slice(1, -1)}` : seg)),
62
+ ...(queryEntries.length ? { query: queryEntries } : {}),
63
+ ...(paramKeys.length
64
+ ? { variable: paramKeys.map((key) => ({ key, value: pathParams?.[key] ?? '' })) }
65
+ : {}),
66
+ };
67
+ }
68
+ function resolveConfiguredHeaderValue(key) {
69
+ const config = (0, config_1.getConfig)();
70
+ const lower = key.toLowerCase();
71
+ const fromFn = config.headerVariable?.(lower) ?? config.headerVariable?.(key);
72
+ if (fromFn)
73
+ return fromFn;
74
+ const map = config.headerVariables ?? {};
75
+ for (const [k, v] of Object.entries(map)) {
76
+ if (k.toLowerCase() === lower)
77
+ return v;
78
+ }
79
+ return undefined;
80
+ }
81
+ function buildHeaders(operation, scenarioHeaders, hasBody) {
82
+ const byLower = new Map();
83
+ const add = (key, value) => {
84
+ const lower = key.toLowerCase();
85
+ if (lower === 'host' || lower === 'content-length')
86
+ return;
87
+ const configured = lower === 'content-type' ? undefined : resolveConfiguredHeaderValue(key);
88
+ byLower.set(lower, { key, value: configured ?? value, type: 'text' });
89
+ };
90
+ for (const param of operation.parameters ?? []) {
91
+ if (param.in === 'header' && param.name) {
92
+ add(param.name, param.example != null ? String(param.example) : '');
93
+ }
94
+ }
95
+ for (const sec of operation.security ?? []) {
96
+ if ('bearerAuth' in sec && !byLower.has('authorization')) {
97
+ add('Authorization', 'Bearer {{authToken}}');
98
+ }
99
+ }
100
+ for (const [key, value] of Object.entries(scenarioHeaders ?? {})) {
101
+ add(key, value);
102
+ }
103
+ if (hasBody && !byLower.has('content-type')) {
104
+ add('Content-Type', 'application/json');
105
+ }
106
+ return [...byLower.values()];
107
+ }
108
+ function stringifyJson(value) {
109
+ if (value === undefined || value === null)
110
+ return '';
111
+ return typeof value === 'string' ? value : JSON.stringify(value, null, 2);
112
+ }
113
+ function folderSegmentsForOperation(urlPath, operation) {
114
+ const fromTree = operation['x-tree-segments'];
115
+ const parts = Array.isArray(fromTree) && fromTree.length ? fromTree.map(String) : urlPath.split('/').filter(Boolean);
116
+ const named = parts.filter((part) => part && !part.startsWith('{'));
117
+ return named.length ? named : ['API'];
118
+ }
119
+ function pushIntoFolderTree(root, segments, requestItem) {
120
+ let level = root;
121
+ for (let i = 0; i < segments.length; i += 1) {
122
+ const name = segments[i];
123
+ let folder = level.find((entry) => entry.name === name && 'item' in entry && !('request' in entry));
124
+ if (!folder) {
125
+ folder = { name, item: [] };
126
+ level.push(folder);
127
+ }
128
+ if (i === segments.length - 1)
129
+ folder.item.push(requestItem);
130
+ else
131
+ level = folder.item;
132
+ }
133
+ }
134
+ function sortCollectionTree(items) {
135
+ const folders = items.filter((entry) => 'item' in entry && !('request' in entry));
136
+ const requests = items.filter((entry) => 'request' in entry);
137
+ folders.sort((a, b) => a.name.localeCompare(b.name));
138
+ for (const folder of folders)
139
+ folder.item = sortCollectionTree(folder.item);
140
+ requests.sort((a, b) => a.name.localeCompare(b.name));
141
+ return [...folders, ...requests];
142
+ }
143
+ function resolveEnvPreset(envName) {
144
+ const config = (0, config_1.getConfig)();
145
+ const presets = config.envPresets ?? {};
146
+ if (envName && presets[envName])
147
+ return { name: envName, preset: presets[envName] };
148
+ const firstKey = Object.keys(presets)[0];
149
+ if (firstKey)
150
+ return { name: firstKey, preset: presets[firstKey] };
151
+ return { name: 'local', preset: { baseUrl: config.baseUrl, baseUrlKey: 'baseUrl' } };
152
+ }
153
+ function buildPostmanCollection(spec, options = {}) {
154
+ const useEnvVar = options.useEnvVar !== false;
155
+ const { preset } = resolveEnvPreset(options.envName);
156
+ const baseUrlKey = preset.baseUrlKey || 'baseUrl';
157
+ const serverUrl = useEnvVar ? `{{${baseUrlKey}}}` : spec.servers?.[0]?.url || preset.baseUrl;
158
+ const root = [];
159
+ let operations = 0;
160
+ let totalExamples = 0;
161
+ for (const [urlPath, pathItem] of Object.entries(spec.paths ?? {})) {
162
+ if (!pathItem || typeof pathItem !== 'object')
163
+ continue;
164
+ for (const method of HTTP_METHODS) {
165
+ const operation = pathItem[method];
166
+ if (!operation || typeof operation !== 'object')
167
+ continue;
168
+ operations += 1;
169
+ const requestPath = operation['x-daxta-url-path'] || urlPath;
170
+ const scenarios = Array.isArray(operation['x-scenarios']) ? operation['x-scenarios'] : [];
171
+ const primaryScenario = scenarios.find((s) => s.status >= 200 && s.status < 300) ?? scenarios[0];
172
+ const reqExamples = operation.requestBody?.content?.['application/json']?.examples ?? {};
173
+ const firstReqExample = Object.values(reqExamples)[0];
174
+ const defaultReqBody = primaryScenario?.reqBody !== undefined ? primaryScenario.reqBody : firstReqExample?.value;
175
+ const hasDefaultBody = defaultReqBody !== undefined;
176
+ const baseRequest = {
177
+ method: method.toUpperCase(),
178
+ header: buildHeaders(operation, primaryScenario?.headers, hasDefaultBody),
179
+ url: postmanUrl(serverUrl, requestPath, primaryScenario?.pathParams, primaryScenario?.query),
180
+ description: operation.summary || operation.description || '',
181
+ ...(hasDefaultBody
182
+ ? {
183
+ body: {
184
+ mode: 'raw',
185
+ raw: stringifyJson(defaultReqBody),
186
+ options: { raw: { language: 'json' } },
187
+ },
188
+ }
189
+ : {}),
190
+ };
191
+ const responses = [];
192
+ if (scenarios.length) {
193
+ for (const scenario of scenarios) {
194
+ const hasBody = scenario.reqBody !== undefined;
195
+ const originalRequest = {
196
+ method: method.toUpperCase(),
197
+ header: buildHeaders(operation, scenario.headers, hasBody),
198
+ url: postmanUrl(serverUrl, requestPath, scenario.pathParams, scenario.query),
199
+ description: operation.summary || '',
200
+ ...(hasBody
201
+ ? {
202
+ body: {
203
+ mode: 'raw',
204
+ raw: stringifyJson(scenario.reqBody),
205
+ options: { raw: { language: 'json' } },
206
+ },
207
+ }
208
+ : {}),
209
+ };
210
+ const code = Number(scenario.status) || 0;
211
+ responses.push({
212
+ name: scenario.name,
213
+ originalRequest,
214
+ status: catalog_1.STATUS_TEXT[String(code)] ?? String(code),
215
+ code,
216
+ _postman_previewlanguage: 'json',
217
+ header: [{ key: 'Content-Type', value: 'application/json' }],
218
+ body: stringifyJson(scenario.resBody),
219
+ });
220
+ }
221
+ }
222
+ else {
223
+ for (const [status, response] of Object.entries(operation.responses ?? {})) {
224
+ const examples = response?.content?.['application/json']?.examples ?? {};
225
+ const entries = Object.entries(examples);
226
+ const code = Number(status) || 0;
227
+ if (!entries.length) {
228
+ responses.push({
229
+ name: response.description || catalog_1.STATUS_TEXT[status] || status,
230
+ originalRequest: baseRequest,
231
+ status: catalog_1.STATUS_TEXT[status] || response.description || status,
232
+ code,
233
+ _postman_previewlanguage: 'json',
234
+ header: [{ key: 'Content-Type', value: 'application/json' }],
235
+ body: '',
236
+ });
237
+ continue;
238
+ }
239
+ for (const [exKey, example] of entries) {
240
+ const name = example.summary || example.description || exKey;
241
+ const reqMatch = reqExamples[exKey] || reqExamples[name] || firstReqExample;
242
+ const hasBody = reqMatch?.value !== undefined;
243
+ const originalRequest = {
244
+ ...baseRequest,
245
+ header: buildHeaders(operation, undefined, hasBody),
246
+ ...(hasBody
247
+ ? {
248
+ body: {
249
+ mode: 'raw',
250
+ raw: stringifyJson(reqMatch.value),
251
+ options: { raw: { language: 'json' } },
252
+ },
253
+ }
254
+ : {}),
255
+ };
256
+ responses.push({
257
+ name,
258
+ originalRequest,
259
+ status: catalog_1.STATUS_TEXT[status] || status,
260
+ code,
261
+ _postman_previewlanguage: 'json',
262
+ header: [{ key: 'Content-Type', value: 'application/json' }],
263
+ body: stringifyJson(example.value),
264
+ });
265
+ }
266
+ }
267
+ }
268
+ totalExamples += responses.length;
269
+ pushIntoFolderTree(root, folderSegmentsForOperation(urlPath, operation), {
270
+ name: operation.summary || `${method.toUpperCase()} ${requestPath}`,
271
+ request: baseRequest,
272
+ response: responses,
273
+ });
274
+ }
275
+ }
276
+ const collection = {
277
+ info: {
278
+ _postman_id: (0, crypto_1.randomUUID)(),
279
+ name: spec.info?.title || spec.info?.['x-workspace'] || (0, config_1.getConfig)().workspace || 'API',
280
+ description: spec.info?.description || 'Generated by DAxTA from observed test execution.',
281
+ schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json',
282
+ },
283
+ item: sortCollectionTree(root),
284
+ };
285
+ return { collection, operations, examples: totalExamples };
286
+ }
287
+ function buildPostmanEnvironment(envName) {
288
+ const { name, preset } = resolveEnvPreset(envName);
289
+ const baseUrlKey = preset.baseUrlKey || 'baseUrl';
290
+ const values = [
291
+ { key: baseUrlKey, value: preset.baseUrl, type: 'default', enabled: true },
292
+ ];
293
+ const known = new Set([baseUrlKey]);
294
+ for (const [key, value] of Object.entries(preset.variables ?? {})) {
295
+ if (key === baseUrlKey)
296
+ continue;
297
+ known.add(key);
298
+ values.push({
299
+ key,
300
+ value: String(value ?? ''),
301
+ type: /token|secret|key|password/i.test(key) ? 'secret' : 'default',
302
+ enabled: true,
303
+ });
304
+ }
305
+ for (const tmpl of Object.values((0, config_1.getConfig)().headerVariables ?? {})) {
306
+ for (const match of String(tmpl).matchAll(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g)) {
307
+ if (known.has(match[1]))
308
+ continue;
309
+ known.add(match[1]);
310
+ values.push({
311
+ key: match[1],
312
+ value: '',
313
+ type: /token|secret|key|password/i.test(match[1]) ? 'secret' : 'default',
314
+ enabled: true,
315
+ });
316
+ }
317
+ }
318
+ return {
319
+ id: (0, crypto_1.randomUUID)(),
320
+ name: `${(0, config_1.getConfig)().workspace || 'API'} (${name})`,
321
+ values,
322
+ _postman_variable_scope: 'environment',
323
+ _postman_exported_at: new Date().toISOString(),
324
+ _postman_exported_using: 'DAxTA',
325
+ };
326
+ }
327
+ function exportPostmanFiles(options = {}) {
328
+ const specPath = (0, paths_1.getSpecJsonPath)();
329
+ if (!(0, fs_1.existsSync)(specPath)) {
330
+ throw new Error(`OpenAPI spec not found at ${specPath}. Run \`daxta generate\` or your tests first.`);
331
+ }
332
+ const spec = JSON.parse((0, fs_1.readFileSync)(specPath, 'utf8'));
333
+ const { collection, operations, examples } = buildPostmanCollection(spec, {
334
+ useEnvVar: options.useEnvVar,
335
+ envName: options.envName,
336
+ });
337
+ const outDir = (0, paths_1.getOutDir)();
338
+ const collectionPath = options.out
339
+ ? path.resolve(options.out.endsWith('.json') ? options.out : path.join(options.out, 'postman_collection.json'))
340
+ : path.join(outDir, 'postman_collection.json');
341
+ (0, fs_1.mkdirSync)(path.dirname(collectionPath), { recursive: true });
342
+ (0, fs_1.writeFileSync)(collectionPath, `${JSON.stringify(collection, null, 2)}\n`);
343
+ let environmentPath;
344
+ if (options.includeEnv !== false) {
345
+ const envDir = path.dirname(collectionPath);
346
+ const baseName = path.basename(collectionPath).replace(/\.postman_collection\.json$|\.json$/i, '');
347
+ environmentPath = path.join(envDir, `${baseName}.postman_environment.json`);
348
+ (0, fs_1.writeFileSync)(environmentPath, `${JSON.stringify(buildPostmanEnvironment(options.envName), null, 2)}\n`);
349
+ }
350
+ return { collectionPath, environmentPath, operations, examples };
351
+ }
@@ -49,7 +49,7 @@ class DaxtaJestReporter {
49
49
  require('reflect-metadata');
50
50
  // eslint-disable-next-line @typescript-eslint/no-var-requires
51
51
  const { rebuildFromDisk } = require('../build/incremental');
52
- const result = rebuildFromDisk({ silent: true, force: true, html: true });
52
+ const result = rebuildFromDisk({ silent: true, force: true, html: true, clearWorkers: true });
53
53
  if (result && !result.skipped) {
54
54
  printDocsReady(result.hits ?? 0, result.operations ?? 0);
55
55
  return;