@t0.labs/daxta 0.4.18 → 0.4.20

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.
@@ -39,6 +39,9 @@ exports.STATUS_TEXT = {
39
39
  const METHOD_ALIASES = {
40
40
  update: ['patch', 'put'],
41
41
  upsert: ['put', 'post', 'patch'],
42
+ insert: ['post'],
43
+ merge: ['post', 'put', 'patch'],
44
+ replace: ['put'],
42
45
  };
43
46
  const CASE_SECTION_RE = /^(POSITIVE CASES|SEMANTIC ERROR CASES(?:\s*-\s*AUTH)?|INVALID CASES|OMITTED(?: FIELD)? CASES)\s+/i;
44
47
  function declaredMethods(test) {
@@ -49,7 +52,7 @@ function declaredMethods(test) {
49
52
  const method = fromLabel.method.toLowerCase();
50
53
  return METHOD_ALIASES[method] ?? [method];
51
54
  }
52
- const declared = test.match(/\[(GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]/i);
55
+ const declared = test.match(new RegExp(`\\[(${test_title_1.HTTP_VERBS})\\]`, 'i'));
53
56
  if (!declared)
54
57
  return null;
55
58
  const method = declared[1].toLowerCase();
@@ -157,10 +160,10 @@ function apiTitle(test) {
157
160
  if (fromLabel)
158
161
  return fromLabel;
159
162
  const patterns = [
160
- /^(.+?\bAPI)\s*[-–—]\s*(?:GET|POST|PUT|PATCH|DELETE)\b/i,
163
+ /^(.+?\bAPI)\s*[-–—]\s*(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT|INSERT|MERGE|REPLACE)\b/i,
161
164
  /\]\s*(?:\([^)]*\)\s*)?(.+?\bAPI)\s+(?:POSITIVE|SEMANTIC|INVALID|OMITTED)\b/i,
162
165
  /^(.+?\bAPI)\s+\/\S+\s+\[(?:GET|POST|PUT|PATCH|DELETE)/i,
163
- /\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]\s*(?:\([^)]*\)\s*)?(.+?\bAPI)\b/i,
166
+ new RegExp(`\\[(?:${test_title_1.HTTP_VERBS})\\]\\s*(?:\\([^)]*\\)\\s*)?(.+?\\bAPI)\\b`, 'i'),
164
167
  ];
165
168
  for (const re of patterns) {
166
169
  const match = test.match(re);
@@ -174,8 +177,8 @@ function caseName(test) {
174
177
  if (!test)
175
178
  return 'example';
176
179
  let rest = test
177
- .replace(/^.+?\s+[—–-]\s+(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\s+\S+\s*/i, '')
178
- .replace(/^.*?\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]\s*(?:\(integration\))?\s*/i, '')
180
+ .replace(new RegExp(`^.+?\\s+[—–-]\\s+(?:${test_title_1.HTTP_VERBS})\\s+\\S+\\s*`, 'i'), '')
181
+ .replace(new RegExp(`^.*?\\[(?:${test_title_1.HTTP_VERBS})\\]\\s*(?:\\(integration\\))?\\s*`, 'i'), '')
179
182
  .replace(CASE_SECTION_RE, '')
180
183
  .trim();
181
184
  // "Admin Find One Basket By Id API - GET /path POSITIVE CASES returns…"
@@ -1,7 +1,21 @@
1
1
  export type CaseSection = 'positive' | 'semantic' | 'invalid' | 'omitted' | 'auth';
2
2
  export declare function parseCaseSection(raw?: string): CaseSection | undefined;
3
+ export declare function isDynamicItName(name?: string): boolean;
4
+ export declare function isGenericItName(name?: string): boolean;
3
5
  export declare function isValidItCase(name?: string): boolean;
4
6
  /**
5
- * Deterministic it() suggestions: `{outcome} when {condition}`.
7
+ * Keep the unique clause from `should …` / existing it() text.
8
+ * Never collapse many cases into one generic sentence.
6
9
  */
7
- export declare function suggestItCases(section: CaseSection | undefined, method?: string, pathTemplate?: string): string[];
10
+ export declare function rewriteItFromOriginal(raw: string, section?: CaseSection, method?: string, pathTemplate?: string): string | undefined;
11
+ export type ItSuggestion = {
12
+ names: string[];
13
+ /** Safe for --yes / `a` — rewritten from this case's own text. */
14
+ auto: boolean;
15
+ };
16
+ /**
17
+ * Prefer a unique rewrite of the current it() name.
18
+ * Generic section templates are never auto-applied.
19
+ */
20
+ export declare function suggestItCases(section: CaseSection | undefined, method?: string, pathTemplate?: string, original?: string): string[];
21
+ export declare function suggestItCaseResult(section: CaseSection | undefined, method?: string, pathTemplate?: string, original?: string): ItSuggestion;
@@ -1,10 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCaseSection = parseCaseSection;
4
+ exports.isDynamicItName = isDynamicItName;
5
+ exports.isGenericItName = isGenericItName;
4
6
  exports.isValidItCase = isValidItCase;
7
+ exports.rewriteItFromOriginal = rewriteItFromOriginal;
5
8
  exports.suggestItCases = suggestItCases;
9
+ exports.suggestItCaseResult = suggestItCaseResult;
6
10
  const test_title_1 = require("./test-title");
7
- const CASE_START = /^(returns|creates|updates|deletes|lists|rejects|conflicts)\b/i;
11
+ const CASE_START = /^(returns|creates|updates|upserts|inserts|merges|replaces|deletes|lists|rejects|conflicts)\b/i;
12
+ const GENERIC_IT = new Set([
13
+ 'returns resource list when query is valid',
14
+ 'returns resource when payload is valid',
15
+ 'returns resource when request is valid',
16
+ 'rejects when resource already exists',
17
+ 'rejects when payload is invalid',
18
+ 'rejects when a required field is omitted',
19
+ 'rejects when unauthorized',
20
+ ]);
8
21
  function parseCaseSection(raw) {
9
22
  if (!raw)
10
23
  return undefined;
@@ -20,13 +33,28 @@ function parseCaseSection(raw) {
20
33
  return 'omitted';
21
34
  return undefined;
22
35
  }
36
+ function isDynamicItName(name) {
37
+ return Boolean(name && /\$\{/.test(name));
38
+ }
39
+ function isGenericItName(name) {
40
+ const value = name?.trim().toLowerCase() ?? '';
41
+ if (GENERIC_IT.has(value))
42
+ return true;
43
+ if (/^rejects when (resource|payload) (already exists|is invalid)$/i.test(value))
44
+ return true;
45
+ if (/^returns [\w\s]+ list when query is valid$/i.test(value))
46
+ return true;
47
+ if (/^creates [\w\s]+ when payload is valid$/i.test(value))
48
+ return true;
49
+ return false;
50
+ }
23
51
  function isValidItCase(name) {
24
52
  const value = name?.trim() ?? '';
25
- if (value.length < 12 || value.length > 100)
53
+ if (value.length < 12 || value.length > 120)
26
54
  return false;
27
55
  if (value.startsWith('/'))
28
56
  return false;
29
- if (/\[(GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]/i.test(value))
57
+ if (/\[(GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT|INSERT|MERGE|REPLACE)\]/i.test(value))
30
58
  return false;
31
59
  if (/(POSITIVE CASES|SEMANTIC ERROR CASES|INVALID CASES|OMITTED)/i.test(value))
32
60
  return false;
@@ -36,57 +64,117 @@ function isValidItCase(name) {
36
64
  return false;
37
65
  return true;
38
66
  }
39
- function resourcePhrase(pathTemplate) {
40
- if (!pathTemplate)
41
- return 'resource';
42
- return (0, test_title_1.resourceLabel)(pathTemplate).toLowerCase();
67
+ function stemVerb(raw) {
68
+ const v = raw.toLowerCase().replace(/s$/, '');
69
+ if (v === 'create')
70
+ return 'creates';
71
+ if (v === 'update')
72
+ return 'updates';
73
+ if (v === 'delete')
74
+ return 'deletes';
75
+ if (v === 'insert')
76
+ return 'inserts';
77
+ if (v === 'upsert')
78
+ return 'upserts';
79
+ if (v === 'merge')
80
+ return 'merges';
81
+ if (v === 'replace')
82
+ return 'replaces';
83
+ if (v === 'return')
84
+ return 'returns';
85
+ if (v === 'list')
86
+ return 'lists';
87
+ if (v === 'reject')
88
+ return 'rejects';
89
+ return `${v}s`;
90
+ }
91
+ function outcomeVerb(section, method) {
92
+ if (section === 'auth' || section === 'invalid' || section === 'omitted' || section === 'semantic')
93
+ return 'rejects';
94
+ const m = (method || 'get').toLowerCase();
95
+ if (m === 'post')
96
+ return 'creates';
97
+ if (m === 'upsert')
98
+ return 'upserts';
99
+ if (m === 'insert')
100
+ return 'inserts';
101
+ if (m === 'merge')
102
+ return 'merges';
103
+ if (m === 'replace')
104
+ return 'replaces';
105
+ if (m === 'delete')
106
+ return 'deletes';
107
+ if (m === 'put' || m === 'patch' || m === 'update')
108
+ return 'updates';
109
+ return 'returns';
110
+ }
111
+ function fitItName(value) {
112
+ let next = value.replace(/\s+/g, ' ').trim().replace(/[.,;:]+$/, '');
113
+ if (next.length > 120) {
114
+ next = next.slice(0, 117).replace(/\s+\S*$/, '').trim();
115
+ }
116
+ if (!isValidItCase(next) || isGenericItName(next))
117
+ return undefined;
118
+ return next;
43
119
  }
44
120
  /**
45
- * Deterministic it() suggestions: `{outcome} when {condition}`.
121
+ * Keep the unique clause from `should …` / existing it() text.
122
+ * Never collapse many cases into one generic sentence.
46
123
  */
47
- function suggestItCases(section, method, pathTemplate) {
48
- const res = resourcePhrase(pathTemplate);
49
- const m = (method || 'get').toLowerCase();
50
- const hasParam = Boolean(pathTemplate?.split('/').some((part) => part.startsWith('{') || part.startsWith(':')));
51
- const out = [];
52
- const add = (value) => {
53
- const next = value.replace(/\s+/g, ' ').trim();
54
- if (next && !out.includes(next))
55
- out.push(next);
56
- };
57
- if (section === 'auth') {
58
- add('rejects when unauthorized');
59
- add('rejects when authorization is missing');
60
- return out;
124
+ function rewriteItFromOriginal(raw, section, method, pathTemplate) {
125
+ if (isDynamicItName(raw))
126
+ return undefined;
127
+ let s = raw.trim().replace(/\s+/g, ' ').replace(/[.,;:]+$/, '');
128
+ if (!s)
129
+ return undefined;
130
+ s = s.replace(/^should\s+/i, '');
131
+ const res = pathTemplate ? (0, test_title_1.resourceLabel)(pathTemplate).toLowerCase() : 'resource';
132
+ const outcome = outcomeVerb(section, method);
133
+ s = s
134
+ .replace(/^returns?\s+unauthorized\s+/i, 'rejects ')
135
+ .replace(/^returns?\s+conflict\s+/i, 'rejects ')
136
+ .replace(/^returns?\s+error\s+/i, 'rejects ')
137
+ .replace(/^returns?\s+bad request\s+/i, 'rejects ')
138
+ .replace(/^returns?\s+not found\s+/i, 'rejects ');
139
+ if (/^not\s+/i.test(s)) {
140
+ const beforeWhen = s.replace(/^not\s+/i, '').split(/\bwhen\b/i)[0].trim();
141
+ return fitItName(`${outcome} ${res} when not ${beforeWhen}`);
61
142
  }
62
- if (section === 'invalid') {
63
- add('rejects when payload is invalid');
64
- add(`rejects when ${res} payload is invalid`);
65
- return out;
143
+ const withMatch = s.match(/^(create|update|delete|insert|upsert|merge|replace)s?\s+(.+?)\s+with\s+(.+)$/i);
144
+ if (withMatch) {
145
+ return fitItName(`${stemVerb(withMatch[1])} ${withMatch[2]} when ${withMatch[3]}`);
66
146
  }
67
- if (section === 'omitted') {
68
- add('rejects when a required field is omitted');
69
- add(`rejects when ${res} field is omitted`);
70
- return out;
147
+ if (!/\bwhen\b/i.test(s)) {
148
+ s = s.replace(/\bwith\b/i, 'when');
71
149
  }
72
- if (section === 'semantic') {
73
- add(`rejects when ${res} already exists`);
74
- add(`rejects when ${res} is not found`);
75
- return out;
150
+ if (CASE_START.test(s) && /\bwhen\b/i.test(s))
151
+ return fitItName(s);
152
+ const led = s.match(/^(create|update|delete|insert|upsert|merge|replace|return)s?\s+(.+)$/i);
153
+ if (led) {
154
+ const rest = led[2];
155
+ if (/\bwhen\b/i.test(rest))
156
+ return fitItName(`${stemVerb(led[1])} ${rest}`);
157
+ return fitItName(`${stemVerb(led[1])} ${rest.replace(/\bwith\b/i, 'when')}`);
76
158
  }
77
- // positive / unknown
78
- if (m === 'post')
79
- add(`creates ${res} when payload is valid`);
80
- else if (m === 'delete')
81
- add(`deletes ${res} when it exists`);
82
- else if (m === 'put' || m === 'patch' || m === 'update')
83
- add(`updates ${res} when payload is valid`);
84
- else if (m === 'get' && hasParam)
85
- add(`returns ${res} when found by id`);
86
- else if (m === 'get')
87
- add(`returns ${res} list when query is valid`);
88
- else
89
- add(`returns ${res} when request is valid`);
90
- add(`returns ${res} when payload is valid`);
91
- return out.slice(0, 3);
159
+ if (/\bwhen\b/i.test(s)) {
160
+ if (/^when\s+/i.test(s))
161
+ return fitItName(`${outcome} ${s}`);
162
+ return fitItName(`${outcome} when ${s}`);
163
+ }
164
+ return fitItName(`${outcome} when ${s}`);
165
+ }
166
+ /**
167
+ * Prefer a unique rewrite of the current it() name.
168
+ * Generic section templates are never auto-applied.
169
+ */
170
+ function suggestItCases(section, method, pathTemplate, original) {
171
+ return suggestItCaseResult(section, method, pathTemplate, original).names;
172
+ }
173
+ function suggestItCaseResult(section, method, pathTemplate, original) {
174
+ if (original && isDynamicItName(original))
175
+ return { names: [], auto: false };
176
+ const fromOriginal = original ? rewriteItFromOriginal(original, section, method, pathTemplate) : undefined;
177
+ if (fromOriginal)
178
+ return { names: [fromOriginal], auto: true };
179
+ return { names: [], auto: false };
92
180
  }
@@ -1,3 +1,5 @@
1
+ /** Verbs that appear in TEST_TITLE `[METHOD]` / `— METHOD path`. */
2
+ export declare const HTTP_VERBS = "GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT|INSERT|MERGE|REPLACE";
1
3
  export type ParsedOperationLabel = {
2
4
  title?: string;
3
5
  path: string;
@@ -21,9 +23,11 @@ export type TitleSuggestion = {
21
23
  };
22
24
  /**
23
25
  * POST /v1/admin/mock-tbs → Create Mock Tbs
24
- * GET /v1/admin/mock-tbs/:id → Find One Mock Tbs By Id
25
- * POST /v1/admin/products/bulk → Create Bulk Products
26
- * POST /v1/admin/validator/tax-id/validate → Validate Tax Id
26
+ * GET /v1/me/branches → Find All Branches
27
+ * GET /v1/integrator/merchants/{id}/branches → Find All Branches By Merchant Id
28
+ * GET /v1/admin/addresses/:id → Find One Address By Id
29
+ * POST /v1/me/branches/:id/addresses/billing → Create Billing Address
30
+ * POST /v1/public/external-checkout/:id/complete → Complete External Checkout
27
31
  */
28
32
  export declare function suggestOperationTitleResult(method: string, pathTemplate: string): TitleSuggestion;
29
33
  export declare function suggestOperationTitles(method: string, pathTemplate: string): string[];
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_VERBS = void 0;
3
4
  exports.isPathParam = isPathParam;
4
5
  exports.titleCaseToken = titleCaseToken;
5
6
  exports.isHumanOperationTitle = isHumanOperationTitle;
@@ -8,7 +9,9 @@ exports.formatTestTitle = formatTestTitle;
8
9
  exports.resourceLabel = resourceLabel;
9
10
  exports.suggestOperationTitleResult = suggestOperationTitleResult;
10
11
  exports.suggestOperationTitles = suggestOperationTitles;
11
- const METHODS = 'GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT';
12
+ /** Verbs that appear in TEST_TITLE `[METHOD]` / `— METHOD path`. */
13
+ exports.HTTP_VERBS = 'GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT|INSERT|MERGE|REPLACE';
14
+ const METHODS = exports.HTTP_VERBS;
12
15
  const PATH_ONLY_BRACKET_RE = new RegExp(`^(?<path>\\/\\S+)\\s+\\[(?<method>${METHODS})\\](?:\\s+\\(integration\\))?\\s*$`, 'i');
13
16
  const TITLE_BRACKET_RE = new RegExp(`^(?<title>.+?)\\s+(?<path>\\/\\S+)\\s+\\[(?<method>${METHODS})\\](?:\\s+\\(integration\\))?\\s*$`, 'i');
14
17
  /** `Create Mock Tbs — POST /v1/admin/mock-tbs` */
@@ -18,9 +21,14 @@ const ROLE_WORDS = new Set([
18
21
  'admin',
19
22
  'user',
20
23
  'users',
24
+ 'me',
21
25
  'public',
22
26
  'internal',
27
+ 'internal-application',
28
+ 'internal-service',
29
+ 'integrator',
23
30
  'partner',
31
+ 'device',
24
32
  'staff',
25
33
  'customer',
26
34
  'vendor',
@@ -29,7 +37,7 @@ const ROLE_WORDS = new Set([
29
37
  'system',
30
38
  'superadmin',
31
39
  ]);
32
- const MODULE_WORDS = new Set(['validator', 'validation', 'validators']);
40
+ const MODULE_WORDS = new Set(['validator', 'validation', 'validators', 'business-data']);
33
41
  const ACTION_WORDS = new Set([
34
42
  'validate',
35
43
  'approve',
@@ -48,14 +56,37 @@ const ACTION_WORDS = new Set([
48
56
  'restore',
49
57
  'verify',
50
58
  'confirm',
59
+ 'complete',
51
60
  'activate',
52
61
  'deactivate',
53
62
  'check',
54
63
  'calculate',
64
+ 'retry',
65
+ 'send',
66
+ 'insert',
67
+ 'merge',
68
+ 'upsert',
69
+ 'onboard',
70
+ 'assign',
55
71
  ]);
72
+ const NOTIFY_WORDS = new Set(['sms', 'email', 'phone', 'push']);
56
73
  function isPathParam(part) {
57
74
  const value = part.trim();
58
- return value.startsWith('{') || value.startsWith(':') || /^:.+/.test(value);
75
+ if (!value)
76
+ return false;
77
+ if (value.startsWith('{') || value.startsWith(':') || value.startsWith('${'))
78
+ return true;
79
+ if (/\$\{[^}]+\}/.test(value))
80
+ return true;
81
+ return false;
82
+ }
83
+ function paramName(part) {
84
+ return part
85
+ .trim()
86
+ .replace(/^\$\{/, '')
87
+ .replace(/^[:{]+/, '')
88
+ .replace(/[}]+$/, '')
89
+ .replace(/^\$/, '');
59
90
  }
60
91
  function titleCaseToken(value) {
61
92
  return value
@@ -132,18 +163,102 @@ function lastSegment(pathTemplate) {
132
163
  const rest = operationSegments(pathTemplate);
133
164
  return (rest[rest.length - 1] || '').toLowerCase();
134
165
  }
166
+ function singularSimple(raw) {
167
+ const value = raw.toLowerCase();
168
+ if (value.length <= 3)
169
+ return value;
170
+ if (value.endsWith('ies') && value.length > 4)
171
+ return value.slice(0, -3) + 'y';
172
+ if (value.endsWith('ches') || value.endsWith('shes') || value.endsWith('sses'))
173
+ return value.slice(0, -2);
174
+ if (value.endsWith('ses') && value.length > 4)
175
+ return value.slice(0, -2);
176
+ if (value.endsWith('s') && !value.endsWith('ss'))
177
+ return value.slice(0, -1);
178
+ return value;
179
+ }
180
+ function singularStem(token) {
181
+ if (token.includes('-')) {
182
+ const bits = token.split('-');
183
+ bits[bits.length - 1] = singularSimple(bits[bits.length - 1]);
184
+ return bits.join('-');
185
+ }
186
+ return singularSimple(token);
187
+ }
188
+ /** `{id}` after `merchants` (parent) → Merchant Id; trailing `:id` → Id */
189
+ function byClauseFromParam(param, precedingNamed, role) {
190
+ const name = paramName(param);
191
+ if (!name)
192
+ return 'By Id';
193
+ if (/^id$/i.test(name)) {
194
+ if (role === 'parent' && precedingNamed) {
195
+ return `By ${titleCaseToken(singularStem(precedingNamed))} Id`;
196
+ }
197
+ return 'By Id';
198
+ }
199
+ if (/Id$/i.test(name))
200
+ return `By ${titleCaseToken(name.replace(/Id$/i, ''))} Id`;
201
+ return `By ${titleCaseToken(name)}`;
202
+ }
203
+ function pathTokens(pathTemplate) {
204
+ return pathTemplate.split('/').filter(Boolean);
205
+ }
206
+ function trailingParam(pathTemplate) {
207
+ const tokens = pathTokens(pathTemplate);
208
+ const last = tokens[tokens.length - 1];
209
+ return last && isPathParam(last) ? last : undefined;
210
+ }
211
+ function parentParam(pathTemplate) {
212
+ const tokens = pathTokens(pathTemplate);
213
+ for (let i = tokens.length - 1; i >= 1; i -= 1) {
214
+ if (!isPathParam(tokens[i]))
215
+ continue;
216
+ if (i === tokens.length - 1)
217
+ continue;
218
+ let named = '';
219
+ for (let j = i - 1; j >= 0; j -= 1) {
220
+ if (!isPathParam(tokens[j]) && !/^v\d+$/i.test(tokens[j]) && !ROLE_WORDS.has(tokens[j].toLowerCase())) {
221
+ named = tokens[j];
222
+ break;
223
+ }
224
+ }
225
+ return { param: tokens[i], named };
226
+ }
227
+ return undefined;
228
+ }
229
+ function collectionAll(rest, leafAll) {
230
+ const last = rest[rest.length - 1];
231
+ const prev = rest[rest.length - 2];
232
+ if (prev && /^(items?|entries)$/i.test(last || '')) {
233
+ return `${titleCaseToken(prev)} ${titleCaseToken(last)}`;
234
+ }
235
+ return leafAll;
236
+ }
237
+ function collectionOne(rest, leafOne) {
238
+ const last = rest[rest.length - 1];
239
+ const prev = rest[rest.length - 2];
240
+ if (prev && /^(items?|entries)$/i.test(last || '')) {
241
+ return `${titleCaseToken(prev)} ${titleCaseToken(singularStem(last))}`;
242
+ }
243
+ return leafOne;
244
+ }
135
245
  /**
136
246
  * POST /v1/admin/mock-tbs → Create Mock Tbs
137
- * GET /v1/admin/mock-tbs/:id → Find One Mock Tbs By Id
138
- * POST /v1/admin/products/bulk → Create Bulk Products
139
- * POST /v1/admin/validator/tax-id/validate → Validate Tax Id
247
+ * GET /v1/me/branches → Find All Branches
248
+ * GET /v1/integrator/merchants/{id}/branches → Find All Branches By Merchant Id
249
+ * GET /v1/admin/addresses/:id → Find One Address By Id
250
+ * POST /v1/me/branches/:id/addresses/billing → Create Billing Address
251
+ * POST /v1/public/external-checkout/:id/complete → Complete External Checkout
140
252
  */
141
253
  function suggestOperationTitleResult(method, pathTemplate) {
142
- const resource = resourceLabel(pathTemplate);
143
254
  const rest = operationSegments(pathTemplate);
144
255
  const last = lastSegment(pathTemplate);
145
- const byId = pathTemplate.split('/').some((part) => isPathParam(part));
256
+ const prev = rest.length >= 2 ? rest[rest.length - 2] : undefined;
257
+ const leafAll = collectionAll(rest, last ? titleCaseToken(last) : resourceLabel(pathTemplate));
258
+ const leafOne = collectionOne(rest, last ? titleCaseToken(singularStem(last)) : leafAll);
146
259
  const m = method.toLowerCase();
260
+ const endParam = trailingParam(pathTemplate);
261
+ const nested = parentParam(pathTemplate);
147
262
  const out = [];
148
263
  const add = (value) => {
149
264
  const next = value.replace(/\s+/g, ' ').trim();
@@ -151,34 +266,88 @@ function suggestOperationTitleResult(method, pathTemplate) {
151
266
  out.push(next);
152
267
  };
153
268
  if (last === 'bulk') {
269
+ const resource = resourceLabel(pathTemplate);
154
270
  add(m === 'get' ? `Find Bulk ${resource}` : `Create Bulk ${resource}`);
155
271
  return { titles: out.slice(0, 3), auto: out.length > 0 };
156
272
  }
273
+ if (last.startsWith('by-')) {
274
+ const target = prev ? titleCaseToken(prev) : resourceLabel(pathTemplate);
275
+ const by = titleCaseToken(last);
276
+ if (m === 'get') {
277
+ add(`Find All ${target} ${by}`);
278
+ add(`Find ${target} ${by}`);
279
+ }
280
+ else if (m === 'post')
281
+ add(`Create ${target} ${by}`);
282
+ else
283
+ add(`${titleCaseToken(m)} ${target} ${by}`);
284
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
285
+ }
286
+ if (NOTIFY_WORDS.has(last) && (prev === 'send' || prev === 'validations' || ACTION_WORDS.has(prev || ''))) {
287
+ if (prev === 'send' || last !== 'phone')
288
+ add(`Send ${titleCaseToken(last)}`);
289
+ if (prev === 'validations' || prev === 'validate')
290
+ add(`Validate ${titleCaseToken(last)}`);
291
+ if (out.length)
292
+ return { titles: out.slice(0, 3), auto: true };
293
+ }
294
+ if (NOTIFY_WORDS.has(last) && m === 'post') {
295
+ add(`Send ${titleCaseToken(last)}`);
296
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
297
+ }
298
+ if (last.endsWith('-retries') || last === 'retries') {
299
+ const subject = prev ? titleCaseToken(prev) : titleCaseToken(last.replace(/-?retries$/, '') || 'operation');
300
+ add(`Retry ${subject}`);
301
+ add('Retry Operation');
302
+ return { titles: out.slice(0, 3), auto: out.length > 0 };
303
+ }
157
304
  if (ACTION_WORDS.has(last)) {
305
+ const resource = prev ? titleCaseToken(prev) : resourceLabel(pathTemplate);
158
306
  add(`${titleCaseToken(last)} ${resource}`);
159
307
  return { titles: out.slice(0, 3), auto: out.length > 0 };
160
308
  }
161
- const extraTail = rest.length > 1;
162
- if (extraTail) {
163
- // e.g. /validator/tax-id/something-unknown — do not invent a CRUD name
164
- return { titles: [], auto: false };
309
+ if (prev && /^(addresses?|items?)$/i.test(prev) && !ACTION_WORDS.has(last) && !endParam) {
310
+ const kind = titleCaseToken(last);
311
+ const noun = titleCaseToken(singularStem(prev));
312
+ if (m === 'post')
313
+ add(`Create ${kind} ${noun}`);
314
+ else if (m === 'get')
315
+ add(`Find ${kind} ${noun}`);
316
+ else
317
+ add(`${titleCaseToken(m)} ${kind} ${noun}`);
318
+ if (out.length)
319
+ return { titles: out.slice(0, 3), auto: true };
320
+ }
321
+ const byEnd = endParam ? byClauseFromParam(endParam, last, 'end') : undefined;
322
+ const byParent = nested ? byClauseFromParam(nested.param, nested.named, 'parent') : undefined;
323
+ if (m === 'get' && endParam)
324
+ add(`Find One ${leafOne} ${byEnd}`);
325
+ else if (m === 'get' && byParent) {
326
+ add(`Find All ${leafAll} ${byParent}`);
327
+ add(`Find All ${leafAll}`);
165
328
  }
166
- if (m === 'get' && byId)
167
- add(`Find One ${resource} By Id`);
168
329
  else if (m === 'get')
169
- add(`Find All ${resource}`);
330
+ add(`Find All ${leafAll}`);
170
331
  else if (m === 'post')
171
- add(`Create ${resource}`);
172
- else if (m === 'delete' && byId)
173
- add(`Delete One ${resource} By Id`);
332
+ add(`Create ${leafOne}`);
333
+ else if (m === 'upsert')
334
+ add(`Upsert ${leafAll}`);
335
+ else if (m === 'insert')
336
+ add(`Insert ${leafOne}`);
337
+ else if (m === 'merge')
338
+ add(`Merge ${leafAll}`);
339
+ else if (m === 'replace')
340
+ add(`Replace ${leafOne}`);
341
+ else if (m === 'delete' && endParam)
342
+ add(`Delete One ${leafOne} ${byEnd}`);
174
343
  else if (m === 'delete')
175
- add(`Delete ${resource}`);
176
- else if ((m === 'put' || m === 'patch' || m === 'update') && byId)
177
- add(`Update ${resource} By Id`);
344
+ add(`Delete ${leafAll}`);
345
+ else if ((m === 'put' || m === 'patch' || m === 'update') && endParam)
346
+ add(`Update ${leafOne} ${byEnd}`);
178
347
  else if (m === 'put' || m === 'patch' || m === 'update')
179
- add(`Update ${resource}`);
348
+ add(`Update ${leafAll}`);
180
349
  else
181
- return { titles: [], auto: false };
350
+ add(`${titleCaseToken(m)} ${leafAll}`);
182
351
  return { titles: out.slice(0, 3), auto: out.length > 0 };
183
352
  }
184
353
  function suggestOperationTitles(method, pathTemplate) {
@@ -106,22 +106,34 @@ async function resolveTestScript(options) {
106
106
  return null;
107
107
  return typed;
108
108
  }
109
- const def = choices[0];
109
+ const shown = choices.slice(0, 8);
110
+ const def = shown[0];
110
111
  if (options.yes || !process.stdin.isTTY)
111
112
  return def.name;
112
- console.log(` ${ui_1.c.dim('your scripts')}`);
113
- choices.slice(0, 8).forEach((choice, i) => {
114
- const mark = i === 0 ? ui_1.c.ice('●') : ui_1.c.dim('○');
115
- const label = i === 0 ? ui_1.c.bold(choice.name) : ui_1.c.dim(choice.name);
116
- const cmd = isDaxtaWrappedScript(choice.command) ? '(already wired → daxta test)' : choice.command.slice(0, 56);
117
- console.log(` ${mark} ${label} ${ui_1.c.dim(cmd)}`);
113
+ console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— reporter + globalSetup')}`);
114
+ shown.forEach((choice, i) => {
115
+ const n = String(i + 1);
116
+ const rec = i === 0 ? ui_1.c.dim(' recommended') : '';
117
+ const cmd = isDaxtaWrappedScript(choice.command)
118
+ ? '(already wired → daxta test)'
119
+ : choice.command.length > 52
120
+ ? `${choice.command.slice(0, 52)}…`
121
+ : choice.command;
122
+ console.log(` ${ui_1.c.ice(n)} ${ui_1.c.bold(choice.name)}${rec}`);
123
+ console.log(` ${ui_1.c.dim(cmd)}`);
118
124
  });
119
- const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.gold('?')} Attach DAxTA plugin to ${ui_1.c.ice(def.name)}?\n` +
120
- ` ${ui_1.c.dim('Y yes · n skip · or another script name')}\n ${ui_1.c.ice('›')} `);
121
- if (!answer || /^y(es)?$/i.test(answer))
125
+ console.log(` ${ui_1.c.dim('n')} skip`);
126
+ const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.dim(`Enter = 1 (${def.name})`)} ${ui_1.c.dim('·')} ${ui_1.c.dim('or type a script name')}\n ${ui_1.c.ice('›')} `);
127
+ if (!answer)
122
128
  return def.name;
123
129
  if (/^n(o)?$/i.test(answer))
124
130
  return null;
131
+ if (/^\d+$/.test(answer)) {
132
+ const picked = shown[Number(answer) - 1];
133
+ if (!picked)
134
+ throw new Error(`No script #${answer}`);
135
+ return picked.name;
136
+ }
125
137
  return answer;
126
138
  }
127
139
  function upsertConfigFields(cwd, fields, dryRun = false) {
@@ -94,21 +94,27 @@ async function resolveMainPath(cwd, candidates) {
94
94
  return full;
95
95
  }
96
96
  const rel = path.relative(cwd, def);
97
- if (candidates.length > 1) {
98
- console.log(` ${ui_1.c.dim('candidates')}`);
99
- for (const file of candidates.slice(0, 5)) {
100
- const r = path.relative(cwd, file);
101
- console.log(` ${r === rel ? ui_1.c.cyan('●') : ui_1.c.dim('○')} ${r === rel ? ui_1.c.bold(r) : ui_1.c.dim(r)}`);
102
- }
103
- if (candidates.length > 5)
104
- console.log(` ${ui_1.c.dim(`… +${candidates.length - 5} more`)}`);
105
- }
106
- const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.gold('?')} Inject ${ui_1.c.bold('apiDocs(app)')} into ${ui_1.c.ice(rel)}?\n` +
107
- ` ${ui_1.c.dim('Y yes · n skip · or another path')}\n ${ui_1.c.ice('›')} `);
108
- if (!answer || /^y(es)?$/i.test(answer))
97
+ const shown = candidates.slice(0, 8);
98
+ console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Nest entry')} ${ui_1.c.dim('— apiDocs(app)')}`);
99
+ shown.forEach((file, i) => {
100
+ const r = path.relative(cwd, file);
101
+ const rec = i === 0 ? ui_1.c.dim(' recommended') : '';
102
+ console.log(` ${ui_1.c.ice(String(i + 1))} ${ui_1.c.bold(r)}${rec}`);
103
+ });
104
+ if (candidates.length > shown.length)
105
+ console.log(` ${ui_1.c.dim(`… +${candidates.length - shown.length} more`)}`);
106
+ console.log(` ${ui_1.c.dim('n')} skip`);
107
+ const answer = await (0, ui_1.readlineAsk)(` ${ui_1.c.dim(`Enter = 1 (${rel})`)} ${ui_1.c.dim('·')} ${ui_1.c.dim('or type a path')}\n ${ui_1.c.ice('›')} `);
108
+ if (!answer)
109
109
  return def;
110
110
  if (/^n(o)?$/i.test(answer))
111
111
  return null;
112
+ if (/^\d+$/.test(answer)) {
113
+ const picked = shown[Number(answer) - 1];
114
+ if (!picked)
115
+ throw new Error(`No file #${answer}`);
116
+ return picked;
117
+ }
112
118
  const full = path.isAbsolute(answer) ? answer : path.join(cwd, answer);
113
119
  if (!(0, fs_1.existsSync)(full))
114
120
  throw new Error(`File not found: ${full}`);
@@ -258,8 +258,6 @@ async function installDaxta(options = {}) {
258
258
  await (0, ui_1.step)('Set DAXTA_DOCS in env', () => ensureEnvDaxtaDocs(cwd, dryRun), { paceMs, n: 2, of });
259
259
  (0, ui_1.phase)(3, of, 'Nest', 'apiDocs(app) on the HTTP bootstrap');
260
260
  if (!options.skipMain) {
261
- console.log('');
262
- console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Nest entry')} ${ui_1.c.dim('— wire apiDocs(app)')}`);
263
261
  const target = await (0, inject_main_1.resolveMainTarget)({
264
262
  cwd,
265
263
  yes: options.yes,
@@ -286,7 +284,6 @@ async function installDaxta(options = {}) {
286
284
  await (0, ui_1.step)('Inject apiDocs(app)', () => 'skipped (--skip-main)', { paceMs, n: 3, of });
287
285
  }
288
286
  (0, ui_1.phase)(4, of, 'Tests', 'Jest plugin — your script stays the parent');
289
- console.log(` ${ui_1.c.gold('?')} ${ui_1.c.bold('Test script')} ${ui_1.c.dim('— attach reporter + globalSetup')}`);
290
287
  const testScript = await (0, discover_test_1.resolveTestScript)({
291
288
  cwd,
292
289
  scripts: pkg.scripts,
@@ -13,16 +13,20 @@ async function pickFromSuggestions(finding, extra, validate) {
13
13
  if (extra)
14
14
  console.log(` ${ui_1.c.dim(extra)}`);
15
15
  if (!suggestions.length) {
16
- console.log(` ${ui_1.c.gold('no auto suggestion')} ${ui_1.c.dim('— type a custom title (c). --yes will not skip this.')}`);
16
+ console.log(` ${ui_1.c.gold('no auto suggestion')} ${ui_1.c.dim('— type a title, or s to skip')}`);
17
17
  }
18
18
  suggestions.forEach((name, index) => {
19
- const mark = index === 0 ? ui_1.c.dim(' (recommended)') : '';
19
+ const mark = index === 0 ? ui_1.c.dim(' recommended') : '';
20
20
  console.log(` ${ui_1.c.ice(String(index + 1))} ${name}${mark}`);
21
21
  });
22
- console.log(` ${ui_1.c.ice('1–3')} pick ${ui_1.c.ice('y')} this recommended ${ui_1.c.ice('a')} all remaining recommended ${ui_1.c.ice('s')} skip ${ui_1.c.ice('c')} custom`);
22
+ console.log(suggestions.length
23
+ ? ` ${ui_1.c.dim('Enter = 1')} ${ui_1.c.dim('·')} ${ui_1.c.ice('a')} remaining auto ${ui_1.c.dim('·')} ${ui_1.c.ice('s')} skip ${ui_1.c.dim('·')} ${ui_1.c.ice('c')} custom`
24
+ : ` ${ui_1.c.ice('c')} custom ${ui_1.c.dim('·')} ${ui_1.c.ice('s')} skip`);
23
25
  const answer = (await (0, ui_1.readlineAsk)(` ${ui_1.c.ice('›')} `)).trim();
24
26
  const lower = answer.toLowerCase();
25
- if (!answer || lower === 's')
27
+ if (!answer)
28
+ return suggestions[0] ? suggestions[0] : 'skip';
29
+ if (lower === 's')
26
30
  return 'skip';
27
31
  if (lower === 'a' || lower === 'all')
28
32
  return 'all';
@@ -52,6 +56,8 @@ function writeTitle(cwd, finding) {
52
56
  return (0, scan_1.applyTitle)(cwd, finding, name);
53
57
  }
54
58
  function writeIt(cwd, finding) {
59
+ if (!finding.auto)
60
+ return false;
55
61
  const name = finding.suggestions[0];
56
62
  if (!name || !(0, it_case_1.isValidItCase)(name))
57
63
  return false;
@@ -75,6 +81,10 @@ function applyAllRecommended(cwd, titles, cases, fromTitleIndex, fromCaseIndex)
75
81
  }
76
82
  const caseStart = fromTitleIndex < titles.length ? 0 : fromCaseIndex;
77
83
  for (let i = caseStart; i < cases.length; i += 1) {
84
+ if (!cases[i].auto || !cases[i].suggestions[0]) {
85
+ skipped += 1;
86
+ continue;
87
+ }
78
88
  if (writeIt(cwd, cases[i])) {
79
89
  console.log(` ${ui_1.c.mint('✔')} ${cases[i].suggestions[0]} ${ui_1.c.dim(cases[i].file + ':' + cases[i].line)}`);
80
90
  written += 1;
@@ -120,7 +130,7 @@ async function runTitleCheck(options) {
120
130
  }
121
131
  (0, ui_1.banner)('Test naming', 'runs before Jest — docs / Postman labels');
122
132
  console.log(` ${ui_1.c.dim('Title')} Create Mock Tbs — POST /v1/admin/mock-tbs`);
123
- console.log(` ${ui_1.c.dim('it()')} creates mock tbs when payload is valid`);
133
+ console.log(` ${ui_1.c.dim('it()')} unique per case — from should …, not one shared template`);
124
134
  console.log(` ${ui_1.c.gold(String(total))} to review — ${ui_1.c.ice('y')} one recommended, ${ui_1.c.ice('a')} all remaining, ${ui_1.c.ice('s')} skip.`);
125
135
  let written = 0;
126
136
  let skipped = 0;
package/dist/path.util.js CHANGED
@@ -10,6 +10,7 @@ exports.pathParamNames = pathParamNames;
10
10
  exports.extractPathParams = extractPathParams;
11
11
  exports.materializePath = materializePath;
12
12
  const config_1 = require("./config");
13
+ const test_title_1 = require("./catalog/test-title");
13
14
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
14
15
  const NUMERIC_ID_RE = /^-?\d+(\.\d+)?$/;
15
16
  const TOKENISH_RE = /^[A-Za-z0-9_-]{16,}$/;
@@ -51,7 +52,7 @@ function toOpenApiTemplate(path) {
51
52
  function templateFromTestName(test) {
52
53
  if (!test)
53
54
  return null;
54
- const match = test.match(/^\/?(\S+)\s+\[(?:GET|POST|PUT|PATCH|DELETE|UPDATE|UPSERT)\]/i);
55
+ const match = test.match(new RegExp(`^/?(\\S+)\\s+\\[(?:${test_title_1.HTTP_VERBS})\\]`, 'i'));
55
56
  if (!match)
56
57
  return null;
57
58
  const raw = `/${match[1].replace(/^\/+/, '')}`.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, ':$1').replace(/\/+$/, '') || '/';
@@ -28,6 +28,7 @@ export type ItFinding = {
28
28
  path?: string;
29
29
  method?: string;
30
30
  suggestions: string[];
31
+ auto: boolean;
31
32
  };
32
33
  export type NamingReport = {
33
34
  titles: TitleFinding[];
@@ -215,9 +215,14 @@ function scanFileCases(rel, text) {
215
215
  const section = [...describes].reverse().find((entry) => entry.index < index && entry.section)?.section;
216
216
  if (!section)
217
217
  continue;
218
- if ((0, it_case_1.isValidItCase)(body))
218
+ if ((0, it_case_1.isDynamicItName)(body))
219
219
  continue;
220
220
  const label = [...labels].reverse().find((entry) => entry.index < index);
221
+ const suggestion = (0, it_case_1.suggestItCaseResult)(section, label?.method, label?.path, body);
222
+ if (!suggestion.names.length)
223
+ continue;
224
+ if (suggestion.auto && suggestion.names[0] === body.replace(/\s+/g, ' ').trim().replace(/[.,;:]+$/, ''))
225
+ continue;
221
226
  const { line, column } = indexToLineCol(text, index);
222
227
  findings.push({
223
228
  file: rel,
@@ -228,7 +233,8 @@ function scanFileCases(rel, text) {
228
233
  section,
229
234
  path: label?.path,
230
235
  method: label?.method,
231
- suggestions: (0, it_case_1.suggestItCases)(section, label?.method, label?.path),
236
+ suggestions: suggestion.names,
237
+ auto: suggestion.auto,
232
238
  });
233
239
  }
234
240
  return findings;
@@ -277,8 +283,8 @@ function printNamingFindings(report, paint) {
277
283
  // spacer already from titles
278
284
  }
279
285
  console.log('');
280
- console.log(` ${paint.yellow('!')} ${paint.bold(`${report.cases.length} it() case(s) off format`)} ${paint.dim('{outcome} when {condition}')}`);
281
- console.log(` ${paint.dim('Format:')} ${paint.cyan('creates mock tbs when payload is valid')}`);
286
+ console.log(` ${paint.yellow('!')} ${paint.bold(`${report.cases.length} it() case(s) can keep unique wording`)} ${paint.dim('should … → outcome when …')}`);
287
+ console.log(` ${paint.dim('Never collapse')} ${paint.cyan('nace codes / TRNC / not-found')} ${paint.dim('into one shared line')}`);
282
288
  for (const item of report.cases) {
283
289
  console.log('');
284
290
  console.log(` ${paint.cyan(item.file)}${paint.dim(`:${item.line}:${item.column}`)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.18",
3
+ "version": "0.4.20",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {