@asteby/metacore-runtime-react 32.0.0 → 32.1.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/CHANGELOG.md +9 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +49 -71
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +27 -28
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/server-error.d.ts +17 -8
- package/dist/server-error.d.ts.map +1 -1
- package/dist/server-error.js +75 -28
- package/dist/types.d.ts +4 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/validation-catalog.d.ts +8 -0
- package/dist/validation-catalog.d.ts.map +1 -0
- package/dist/validation-catalog.js +59 -0
- package/dist/validator.d.ts +22 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +261 -0
- package/package.json +1 -1
- package/src/__tests__/extract-field-errors.test.ts +25 -1
- package/src/__tests__/validator.test.ts +70 -0
- package/src/action-modal-dispatcher.tsx +53 -68
- package/src/dialogs/dynamic-record.tsx +25 -28
- package/src/dynamic-form-schema.ts +3 -2
- package/src/index.ts +13 -0
- package/src/server-error.ts +85 -30
- package/src/types.ts +9 -12
- package/src/validation-catalog.ts +60 -0
- package/src/validator.ts +275 -0
package/dist/server-error.js
CHANGED
|
@@ -10,17 +10,36 @@
|
|
|
10
10
|
// or report it. This module keeps the headline but ALSO surfaces the cause as
|
|
11
11
|
// the toast description, in ONE place so every call site behaves identically.
|
|
12
12
|
import { toast } from 'sonner';
|
|
13
|
+
import { validationCatalog, validationMessageKey } from './validation-catalog';
|
|
14
|
+
function formatIssueEntry(v) {
|
|
15
|
+
if (v == null)
|
|
16
|
+
return '';
|
|
17
|
+
if (typeof v === 'string')
|
|
18
|
+
return v;
|
|
19
|
+
if (typeof v === 'object' && 'code' in v) {
|
|
20
|
+
const e = v;
|
|
21
|
+
if (typeof e.message === 'string' && e.message.trim())
|
|
22
|
+
return e.message.trim();
|
|
23
|
+
if (typeof e.code === 'string' && e.code)
|
|
24
|
+
return e.code;
|
|
25
|
+
}
|
|
26
|
+
return String(v);
|
|
27
|
+
}
|
|
13
28
|
/** Flattens a validation `errors` payload (string | string[] | field→msgs map)
|
|
14
|
-
* into a single newline-joined string, or undefined when empty.
|
|
29
|
+
* into a single newline-joined string, or undefined when empty. Object entries
|
|
30
|
+
* `{code, params}` render as the code (never `[object Object]`). */
|
|
15
31
|
function joinErrors(errors) {
|
|
16
32
|
if (!errors)
|
|
17
33
|
return undefined;
|
|
18
34
|
if (typeof errors === 'string')
|
|
19
35
|
return errors || undefined;
|
|
20
36
|
if (Array.isArray(errors))
|
|
21
|
-
return errors.
|
|
37
|
+
return errors.map(formatIssueEntry).filter(Boolean).join('\n') || undefined;
|
|
22
38
|
if (typeof errors === 'object') {
|
|
23
|
-
const parts = Object.entries(errors).map(([k, v]) =>
|
|
39
|
+
const parts = Object.entries(errors).map(([k, v]) => {
|
|
40
|
+
const body = Array.isArray(v) ? v.map(formatIssueEntry).filter(Boolean).join(', ') : formatIssueEntry(v);
|
|
41
|
+
return body ? `${k}: ${body}` : '';
|
|
42
|
+
}).filter(Boolean);
|
|
24
43
|
return parts.join('\n') || undefined;
|
|
25
44
|
}
|
|
26
45
|
return undefined;
|
|
@@ -59,17 +78,12 @@ export function extractServerError(err, fallbackTitle) {
|
|
|
59
78
|
return { title: fallbackTitle, description: raw.trim() };
|
|
60
79
|
return { title: fallbackTitle };
|
|
61
80
|
}
|
|
62
|
-
/** Spanish
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
not_found: 'El {{label}} seleccionado no existe',
|
|
69
|
-
duplicate: 'Ya existe un registro con ese {{label}}',
|
|
70
|
-
invalid_type: 'El campo {{label}} tiene un formato inválido',
|
|
71
|
-
};
|
|
72
|
-
const VALIDATION_FALLBACK = '{{label}}: valor inválido';
|
|
81
|
+
/** Spanish/English catalogs live in `validation-catalog.ts`. Hosts override any
|
|
82
|
+
* key via i18next `validation.<code>`. `{{label}}` and code params (min/max/
|
|
83
|
+
* allowed/ref/expected) interpolate through i18next. */
|
|
84
|
+
function humanizeKey(k) {
|
|
85
|
+
return k.replace(/[._-]+/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
86
|
+
}
|
|
73
87
|
/** Normalize one raw `errors` value entry into a `FieldIssue`.
|
|
74
88
|
* A string → `{message}` (pre-localized, shown verbatim); an object → `{code,params}`. */
|
|
75
89
|
function toFieldIssue(entry) {
|
|
@@ -113,17 +127,28 @@ export function extractFieldErrors(err) {
|
|
|
113
127
|
return Object.keys(out).length ? out : undefined;
|
|
114
128
|
}
|
|
115
129
|
/**
|
|
116
|
-
* Localize a single `FieldIssue` to a human
|
|
117
|
-
*
|
|
118
|
-
* `code` is translated via `t('validation.'+
|
|
119
|
-
*
|
|
130
|
+
* Localize a single `FieldIssue` to a human string using the field `label` and
|
|
131
|
+
* the operator's language. A pre-localized `message` passes through verbatim.
|
|
132
|
+
* Otherwise `code` is translated via `t('validation.'+key)` with a catalog
|
|
133
|
+
* default (es unless `language` is `en` / `en-*`).
|
|
120
134
|
*/
|
|
121
|
-
export function localizeFieldIssue(issue, label, t) {
|
|
135
|
+
export function localizeFieldIssue(issue, label, t, language) {
|
|
122
136
|
if (issue.message)
|
|
123
137
|
return issue.message;
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
138
|
+
const key = validationMessageKey(issue.code ?? '', issue.params);
|
|
139
|
+
const cat = validationCatalog(language);
|
|
140
|
+
const defaultValue = cat[key] ?? cat.fallback ?? '{{label}}: valor inválido';
|
|
141
|
+
return t(`validation.${key}`, { defaultValue, label, ...(issue.params ?? {}) });
|
|
142
|
+
}
|
|
143
|
+
/** Localize a whole 422 `errors` map into `{ [field]: firstMessage }` using
|
|
144
|
+
* optional per-key labels (already translated) and the current language. */
|
|
145
|
+
export function localizeFieldErrorMap(map, t, opts) {
|
|
146
|
+
const out = {};
|
|
147
|
+
for (const [k, issues] of Object.entries(map)) {
|
|
148
|
+
const label = opts?.labels?.[k] ?? humanizeKey(k);
|
|
149
|
+
out[k] = localizeFieldIssue(issues[0], label, t, opts?.language);
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
127
152
|
}
|
|
128
153
|
/** A dotted, space-free token (e.g. "pos.rate.created") — the shape of an i18n
|
|
129
154
|
* key, as opposed to human prose ("Record created successfully"). Used to
|
|
@@ -153,14 +178,36 @@ export function toastServerSuccess(data, opts) {
|
|
|
153
178
|
}
|
|
154
179
|
/**
|
|
155
180
|
* Toast a server/network error, surfacing the REAL cause as the description
|
|
156
|
-
* instead of a bare generic line.
|
|
157
|
-
*
|
|
158
|
-
*
|
|
181
|
+
* instead of a bare generic line. A 422 `{errors:{field:[{code}]}}` bag is
|
|
182
|
+
* localized per-field (never `[object Object]` / English "validation failed").
|
|
183
|
+
* Pass `language` (i18n.language) so catalogs match the operator's lang;
|
|
184
|
+
* pass `labels` so field keys map to translated headers.
|
|
159
185
|
*/
|
|
160
186
|
export function toastServerError(err, opts) {
|
|
161
187
|
const t = opts?.t;
|
|
188
|
+
const lang = opts?.language;
|
|
189
|
+
const cat = validationCatalog(lang);
|
|
190
|
+
const map = extractFieldErrors(err);
|
|
191
|
+
if (map) {
|
|
192
|
+
const localized = t
|
|
193
|
+
? localizeFieldErrorMap(map, t, { labels: opts?.labels, language: lang })
|
|
194
|
+
: undefined;
|
|
195
|
+
const title = t
|
|
196
|
+
? t('validation.failed', { defaultValue: cat.failed })
|
|
197
|
+
: cat.failed;
|
|
198
|
+
const description = localized
|
|
199
|
+
? Object.values(localized).join('\n')
|
|
200
|
+
: Object.entries(map)
|
|
201
|
+
.map(([k, issues]) => `${k}: ${issues[0]?.code ?? issues[0]?.message ?? ''}`)
|
|
202
|
+
.join('\n');
|
|
203
|
+
toast.error(title, description ? { description } : undefined);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
162
206
|
const fallback = opts?.fallback ?? (t ? t('common.error', { defaultValue: 'Something went wrong' }) : 'Something went wrong');
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
207
|
+
const extracted = extractServerError(err, fallback);
|
|
208
|
+
let shownTitle = t ? t(extracted.title, { defaultValue: extracted.title }) : extracted.title;
|
|
209
|
+
if (extracted.title === 'validation failed' || extracted.title === 'validation.failed') {
|
|
210
|
+
shownTitle = t ? t('validation.failed', { defaultValue: cat.failed }) : cat.failed;
|
|
211
|
+
}
|
|
212
|
+
toast.error(shownTitle, extracted.description ? { description: extracted.description } : undefined);
|
|
166
213
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -291,11 +291,10 @@ export interface ColumnDefinition {
|
|
|
291
291
|
*/
|
|
292
292
|
ref?: string;
|
|
293
293
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* reference resolved through the OrgConfigProvider.
|
|
294
|
+
* Write-time rules the SDK also pre-flights. Object form `{regex,min,max,custom}`
|
|
295
|
+
* or a Laravel / go-playground string (`required|min:2|email`).
|
|
297
296
|
*/
|
|
298
|
-
validation?: FieldValidation;
|
|
297
|
+
validation?: FieldValidation | string;
|
|
299
298
|
/**
|
|
300
299
|
* Declared schema for a jsonb line-items column (kernel v3 `item_fields`).
|
|
301
300
|
* Each entry describes one sub-field of the array's row objects: a `key`
|
|
@@ -415,7 +414,7 @@ export interface ActionFieldDef {
|
|
|
415
414
|
defaultValue?: any;
|
|
416
415
|
placeholder?: string;
|
|
417
416
|
searchEndpoint?: string;
|
|
418
|
-
validation?: FieldValidation;
|
|
417
|
+
validation?: FieldValidation | string;
|
|
419
418
|
widget?: FieldWidget | string;
|
|
420
419
|
/**
|
|
421
420
|
* FK target model — same semantics as ColumnDefinition.ref. When
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 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B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,UAAU,EAAE,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAA;CACzC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Laravel-style validation catalogs. Hosts override any key via i18next
|
|
2
|
+
* `validation.<code>`; these are the defaults when the key is missing, picked
|
|
3
|
+
* by the operator's language (es by default — the product language). */
|
|
4
|
+
export declare const VALIDATION_CATALOGS: Record<string, Record<string, string>>;
|
|
5
|
+
export declare function validationCatalog(language?: string): Record<string, string>;
|
|
6
|
+
/** Pick the catalog key for a code, folding min/max + kind=length into *_length. */
|
|
7
|
+
export declare function validationMessageKey(code: string, params?: Record<string, unknown>): string;
|
|
8
|
+
//# sourceMappingURL=validation-catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-catalog.d.ts","sourceRoot":"","sources":["../src/validation-catalog.ts"],"names":[],"mappings":"AAAA;;yEAEyE;AAEzE,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2CtE,CAAA;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG3E;AAED,oFAAoF;AACpF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAI3F"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** Laravel-style validation catalogs. Hosts override any key via i18next
|
|
2
|
+
* `validation.<code>`; these are the defaults when the key is missing, picked
|
|
3
|
+
* by the operator's language (es by default — the product language). */
|
|
4
|
+
export const VALIDATION_CATALOGS = {
|
|
5
|
+
es: {
|
|
6
|
+
failed: 'Revisa los campos marcados',
|
|
7
|
+
required: 'El campo {{label}} es obligatorio',
|
|
8
|
+
invalid_option: 'El valor de {{label}} no es válido',
|
|
9
|
+
not_found: 'El {{label}} seleccionado no existe',
|
|
10
|
+
duplicate: 'Ya existe un registro con ese {{label}}',
|
|
11
|
+
invalid_type: 'El campo {{label}} tiene un formato inválido',
|
|
12
|
+
min: 'El campo {{label}} debe ser al menos {{min}}',
|
|
13
|
+
min_length: '{{label}} debe tener al menos {{min}} caracteres',
|
|
14
|
+
max: 'El campo {{label}} no puede ser mayor que {{max}}',
|
|
15
|
+
max_length: '{{label}} no puede tener más de {{max}} caracteres',
|
|
16
|
+
regex: 'El formato de {{label}} no es válido',
|
|
17
|
+
email: '{{label}} debe ser un correo válido',
|
|
18
|
+
uuid: '{{label}} no es un identificador válido',
|
|
19
|
+
url: '{{label}} debe ser una URL válida',
|
|
20
|
+
numeric: '{{label}} debe ser un número',
|
|
21
|
+
integer: '{{label}} debe ser un entero',
|
|
22
|
+
custom: '{{label}} no es válido',
|
|
23
|
+
line_items_required: '{{label}} requiere al menos un renglón',
|
|
24
|
+
fallback: '{{label}}: valor inválido',
|
|
25
|
+
},
|
|
26
|
+
en: {
|
|
27
|
+
failed: 'Please check the highlighted fields',
|
|
28
|
+
required: 'The {{label}} field is required',
|
|
29
|
+
invalid_option: 'The selected {{label}} is invalid',
|
|
30
|
+
not_found: 'The selected {{label}} does not exist',
|
|
31
|
+
duplicate: 'A record with that {{label}} already exists',
|
|
32
|
+
invalid_type: 'The {{label}} field has an invalid format',
|
|
33
|
+
min: 'The {{label}} must be at least {{min}}',
|
|
34
|
+
min_length: 'The {{label}} must be at least {{min}} characters',
|
|
35
|
+
max: 'The {{label}} may not be greater than {{max}}',
|
|
36
|
+
max_length: 'The {{label}} may not be greater than {{max}} characters',
|
|
37
|
+
regex: 'The {{label}} format is invalid',
|
|
38
|
+
email: 'The {{label}} must be a valid email address',
|
|
39
|
+
uuid: 'The {{label}} is not a valid identifier',
|
|
40
|
+
url: 'The {{label}} must be a valid URL',
|
|
41
|
+
numeric: 'The {{label}} must be a number',
|
|
42
|
+
integer: 'The {{label}} must be an integer',
|
|
43
|
+
custom: 'The {{label}} is invalid',
|
|
44
|
+
line_items_required: '{{label}} requires at least one row',
|
|
45
|
+
fallback: '{{label}}: invalid value',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
export function validationCatalog(language) {
|
|
49
|
+
const short = (language ?? 'es').split(/[-_]/)[0].toLowerCase();
|
|
50
|
+
return VALIDATION_CATALOGS[short] ?? VALIDATION_CATALOGS.es;
|
|
51
|
+
}
|
|
52
|
+
/** Pick the catalog key for a code, folding min/max + kind=length into *_length. */
|
|
53
|
+
export function validationMessageKey(code, params) {
|
|
54
|
+
if (code === 'min' && params?.kind === 'length')
|
|
55
|
+
return 'min_length';
|
|
56
|
+
if (code === 'max' && params?.kind === 'length')
|
|
57
|
+
return 'max_length';
|
|
58
|
+
return code;
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ActionFieldDef, FieldValidation } from './types';
|
|
2
|
+
import type { FieldIssue } from './server-error';
|
|
3
|
+
export interface ValidationSpec {
|
|
4
|
+
required?: boolean;
|
|
5
|
+
type?: string;
|
|
6
|
+
regex?: string;
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
custom?: string;
|
|
10
|
+
options?: string[];
|
|
11
|
+
}
|
|
12
|
+
/** Parse `required|min:2|email` or `required,min=2,max=100` or a custom slug. */
|
|
13
|
+
export declare function parseRuleString(s: string): ValidationSpec;
|
|
14
|
+
/** Normalize ActionFieldDef.validation (object, laravel string, or `rules`). */
|
|
15
|
+
export declare function fieldValidationOf(field: ActionFieldDef | Record<string, unknown>): FieldValidation;
|
|
16
|
+
/** Evaluate spec against one value; collect every issue (not fail-fast). */
|
|
17
|
+
export declare function checkValue(value: unknown, spec: ValidationSpec): FieldIssue[];
|
|
18
|
+
/** Validate a form payload the way Laravel's Validator does: collect every
|
|
19
|
+
* field issue, dotted keys for line-items (`items.0.qty`). */
|
|
20
|
+
export declare function validateValues(fields: readonly ActionFieldDef[], values: Record<string, unknown>): Record<string, FieldIssue[]>;
|
|
21
|
+
export declare function bagHasErrors(bag: Record<string, FieldIssue[]>): boolean;
|
|
22
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAKhD,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAQD,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,cAAc,CAyCzD;AAqCD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,CAUlG;AAiCD,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,UAAU,EAAE,CAmC7E;AAgDD;+DAC+D;AAC/D,wBAAgB,cAAc,CAC1B,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAI9B;AA8BD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO,CAEvE"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
|
|
2
|
+
const NUMERIC_TYPES = new Set(['int', 'integer', 'bigint', 'decimal', 'numeric', 'number', 'float', 'double']);
|
|
3
|
+
const RULE_NAMES = new Set([
|
|
4
|
+
'required', 'nullable', 'sometimes', 'present',
|
|
5
|
+
'min', 'max', 'regex', 'email', 'uuid', 'url',
|
|
6
|
+
'numeric', 'integer', 'int', 'in',
|
|
7
|
+
]);
|
|
8
|
+
/** Parse `required|min:2|email` or `required,min=2,max=100` or a custom slug. */
|
|
9
|
+
export function parseRuleString(s) {
|
|
10
|
+
const spec = {};
|
|
11
|
+
const trimmed = s.trim();
|
|
12
|
+
if (!trimmed)
|
|
13
|
+
return spec;
|
|
14
|
+
for (const part of splitRules(trimmed)) {
|
|
15
|
+
const { name, param } = splitNameParam(part);
|
|
16
|
+
switch (name.toLowerCase()) {
|
|
17
|
+
case 'required':
|
|
18
|
+
spec.required = true;
|
|
19
|
+
break;
|
|
20
|
+
case 'min': {
|
|
21
|
+
const n = Number(param);
|
|
22
|
+
if (!Number.isNaN(n))
|
|
23
|
+
spec.min = n;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case 'max': {
|
|
27
|
+
const n = Number(param);
|
|
28
|
+
if (!Number.isNaN(n))
|
|
29
|
+
spec.max = n;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case 'regex':
|
|
33
|
+
spec.regex = trimLaravelRegex(param);
|
|
34
|
+
break;
|
|
35
|
+
case 'email':
|
|
36
|
+
case 'uuid':
|
|
37
|
+
case 'url':
|
|
38
|
+
case 'numeric':
|
|
39
|
+
case 'integer':
|
|
40
|
+
spec.custom = name.toLowerCase();
|
|
41
|
+
break;
|
|
42
|
+
case 'int':
|
|
43
|
+
spec.custom = 'integer';
|
|
44
|
+
break;
|
|
45
|
+
case 'in':
|
|
46
|
+
spec.options = param.split(',').map(x => x.trim()).filter(Boolean);
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
if (!spec.custom)
|
|
50
|
+
spec.custom = part;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return spec;
|
|
54
|
+
}
|
|
55
|
+
function splitRules(s) {
|
|
56
|
+
if (s.includes('|'))
|
|
57
|
+
return s.split('|').map(x => x.trim()).filter(Boolean);
|
|
58
|
+
const raw = s.split(',');
|
|
59
|
+
const out = [];
|
|
60
|
+
for (const p of raw) {
|
|
61
|
+
const part = p.trim();
|
|
62
|
+
if (!part)
|
|
63
|
+
continue;
|
|
64
|
+
const { name } = splitNameParam(part);
|
|
65
|
+
if (!RULE_NAMES.has(name.toLowerCase()) && out.length) {
|
|
66
|
+
const prev = splitNameParam(out[out.length - 1]).name;
|
|
67
|
+
if (prev.toLowerCase() === 'in') {
|
|
68
|
+
out[out.length - 1] += `,${part}`;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
out.push(part);
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
function splitNameParam(p) {
|
|
77
|
+
const colon = p.indexOf(':');
|
|
78
|
+
const eq = p.indexOf('=');
|
|
79
|
+
const i = colon >= 0 && (eq < 0 || colon < eq) ? colon : eq;
|
|
80
|
+
if (i < 0)
|
|
81
|
+
return { name: p.trim(), param: '' };
|
|
82
|
+
return { name: p.slice(0, i).trim(), param: p.slice(i + 1).trim() };
|
|
83
|
+
}
|
|
84
|
+
function trimLaravelRegex(p) {
|
|
85
|
+
if (p.length >= 2 && p.startsWith('/') && p.lastIndexOf('/') > 0) {
|
|
86
|
+
return p.slice(1, p.lastIndexOf('/'));
|
|
87
|
+
}
|
|
88
|
+
return p;
|
|
89
|
+
}
|
|
90
|
+
/** Normalize ActionFieldDef.validation (object, laravel string, or `rules`). */
|
|
91
|
+
export function fieldValidationOf(field) {
|
|
92
|
+
const rec = field;
|
|
93
|
+
const raw = rec.validation ?? rec.rules ?? rec.validation_rule;
|
|
94
|
+
if (!raw)
|
|
95
|
+
return {};
|
|
96
|
+
if (typeof raw === 'string') {
|
|
97
|
+
const s = parseRuleString(raw);
|
|
98
|
+
return { regex: s.regex, min: s.min, max: s.max, custom: s.custom };
|
|
99
|
+
}
|
|
100
|
+
if (typeof raw === 'object' && !Array.isArray(raw))
|
|
101
|
+
return raw;
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
function isEmpty(raw) {
|
|
105
|
+
if (raw == null)
|
|
106
|
+
return true;
|
|
107
|
+
if (typeof raw === 'string') {
|
|
108
|
+
const t = raw.trim();
|
|
109
|
+
return t === '' || t === NIL_UUID;
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(raw))
|
|
112
|
+
return raw.length === 0;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
function asString(raw) {
|
|
116
|
+
if (raw == null)
|
|
117
|
+
return '';
|
|
118
|
+
return String(raw).trim();
|
|
119
|
+
}
|
|
120
|
+
function isNumeric(raw) {
|
|
121
|
+
if (typeof raw === 'number' && Number.isFinite(raw))
|
|
122
|
+
return true;
|
|
123
|
+
if (typeof raw === 'string')
|
|
124
|
+
return raw.trim() !== '' && !Number.isNaN(Number(raw));
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
function numericValue(raw) {
|
|
128
|
+
return typeof raw === 'number' ? raw : Number(asString(raw));
|
|
129
|
+
}
|
|
130
|
+
function lengthOf(raw) {
|
|
131
|
+
if (typeof raw === 'string')
|
|
132
|
+
return [...raw.trim()].length;
|
|
133
|
+
if (Array.isArray(raw))
|
|
134
|
+
return raw.length;
|
|
135
|
+
return [...asString(raw)].length;
|
|
136
|
+
}
|
|
137
|
+
/** Evaluate spec against one value; collect every issue (not fail-fast). */
|
|
138
|
+
export function checkValue(value, spec) {
|
|
139
|
+
const empty = isEmpty(value);
|
|
140
|
+
if (spec.required && empty)
|
|
141
|
+
return [{ code: 'required' }];
|
|
142
|
+
if (empty)
|
|
143
|
+
return [];
|
|
144
|
+
const out = [];
|
|
145
|
+
const typ = (spec.type ?? '').toLowerCase();
|
|
146
|
+
if (NUMERIC_TYPES.has(typ) && !isNumeric(value)) {
|
|
147
|
+
out.push({ code: 'invalid_type', params: { expected: 'number' } });
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
if (spec.options && spec.options.length) {
|
|
151
|
+
const want = asString(value);
|
|
152
|
+
if (!spec.options.includes(want)) {
|
|
153
|
+
out.push({ code: 'invalid_option', params: { allowed: spec.options } });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (spec.regex) {
|
|
157
|
+
try {
|
|
158
|
+
if (!new RegExp(spec.regex).test(asString(value))) {
|
|
159
|
+
out.push({ code: 'regex', params: { pattern: spec.regex } });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch { /* malformed — skip */ }
|
|
163
|
+
}
|
|
164
|
+
if (spec.min != null || spec.max != null) {
|
|
165
|
+
const isNum = NUMERIC_TYPES.has(typ);
|
|
166
|
+
const kind = isNum ? 'value' : 'length';
|
|
167
|
+
const n = isNum ? numericValue(value) : lengthOf(value);
|
|
168
|
+
if (spec.min != null && n < spec.min)
|
|
169
|
+
out.push({ code: 'min', params: { min: spec.min, kind } });
|
|
170
|
+
if (spec.max != null && n > spec.max)
|
|
171
|
+
out.push({ code: 'max', params: { max: spec.max, kind } });
|
|
172
|
+
}
|
|
173
|
+
if (spec.custom) {
|
|
174
|
+
const custom = checkBuiltin(spec.custom, value);
|
|
175
|
+
if (custom)
|
|
176
|
+
out.push(custom);
|
|
177
|
+
}
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
function checkBuiltin(slug, value) {
|
|
181
|
+
const s = asString(value);
|
|
182
|
+
switch (slug) {
|
|
183
|
+
case 'email':
|
|
184
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s) ? undefined : { code: 'email' };
|
|
185
|
+
case 'uuid':
|
|
186
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(s)
|
|
187
|
+
? undefined : { code: 'uuid' };
|
|
188
|
+
case 'url':
|
|
189
|
+
try {
|
|
190
|
+
const u = new URL(s);
|
|
191
|
+
return u.protocol && u.host ? undefined : { code: 'url' };
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return { code: 'url' };
|
|
195
|
+
}
|
|
196
|
+
case 'numeric':
|
|
197
|
+
return isNumeric(value) ? undefined : { code: 'numeric', params: { expected: 'number' } };
|
|
198
|
+
case 'integer':
|
|
199
|
+
case 'int':
|
|
200
|
+
return /^-?\d+$/.test(s) || (typeof value === 'number' && Number.isInteger(value))
|
|
201
|
+
? undefined : { code: 'integer', params: { expected: 'integer' } };
|
|
202
|
+
default:
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function specFromField(field) {
|
|
207
|
+
const v = fieldValidationOf(field);
|
|
208
|
+
const spec = {
|
|
209
|
+
required: !!field.required,
|
|
210
|
+
type: field.type,
|
|
211
|
+
regex: v.regex,
|
|
212
|
+
min: v.min,
|
|
213
|
+
max: v.max,
|
|
214
|
+
custom: v.custom,
|
|
215
|
+
};
|
|
216
|
+
if (field.options?.length)
|
|
217
|
+
spec.options = field.options.map(o => String(o.value));
|
|
218
|
+
return spec;
|
|
219
|
+
}
|
|
220
|
+
function isLineItems(field) {
|
|
221
|
+
const raw = field.itemFields ?? field.item_fields;
|
|
222
|
+
return Array.isArray(raw) && raw.length > 0;
|
|
223
|
+
}
|
|
224
|
+
function itemFieldsOf(field) {
|
|
225
|
+
const raw = field.itemFields ?? field.item_fields;
|
|
226
|
+
return Array.isArray(raw) ? raw : [];
|
|
227
|
+
}
|
|
228
|
+
/** Validate a form payload the way Laravel's Validator does: collect every
|
|
229
|
+
* field issue, dotted keys for line-items (`items.0.qty`). */
|
|
230
|
+
export function validateValues(fields, values) {
|
|
231
|
+
const bag = {};
|
|
232
|
+
walk(fields, values ?? {}, '', bag);
|
|
233
|
+
return bag;
|
|
234
|
+
}
|
|
235
|
+
function walk(fields, values, prefix, bag) {
|
|
236
|
+
for (const field of fields) {
|
|
237
|
+
const key = field.key;
|
|
238
|
+
if (!key)
|
|
239
|
+
continue;
|
|
240
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
241
|
+
const raw = values[key];
|
|
242
|
+
if (isLineItems(field)) {
|
|
243
|
+
const rows = Array.isArray(raw) ? raw : [];
|
|
244
|
+
if (field.required && rows.length === 0) {
|
|
245
|
+
bag[path] = [{ code: 'line_items_required' }];
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
rows.forEach((row, i) => {
|
|
249
|
+
const obj = row && typeof row === 'object' ? row : {};
|
|
250
|
+
walk(itemFieldsOf(field), obj, `${path}.${i}`, bag);
|
|
251
|
+
});
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const issues = checkValue(raw, specFromField(field));
|
|
255
|
+
if (issues.length)
|
|
256
|
+
bag[path] = issues;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
export function bagHasErrors(bag) {
|
|
260
|
+
return Object.keys(bag).length > 0;
|
|
261
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { extractFieldErrors, localizeFieldIssue, type FieldIssue } from '../server-error'
|
|
2
|
+
import { extractFieldErrors, localizeFieldIssue, extractServerError, type FieldIssue } from '../server-error'
|
|
3
3
|
|
|
4
4
|
// A minimal i18next-like translator: honors defaultValue and does {{var}}
|
|
5
5
|
// interpolation, so the tests assert BOTH the resolved Spanish default and that
|
|
@@ -70,6 +70,22 @@ describe('extractFieldErrors', () => {
|
|
|
70
70
|
})
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
+
describe('extractServerError', () => {
|
|
74
|
+
it('does not stringify field-error objects as [object Object]', () => {
|
|
75
|
+
const { title, description } = extractServerError(
|
|
76
|
+
{
|
|
77
|
+
success: false,
|
|
78
|
+
message: 'validation failed',
|
|
79
|
+
errors: { sku: [{ code: 'required', params: {} }] },
|
|
80
|
+
},
|
|
81
|
+
'fallback',
|
|
82
|
+
)
|
|
83
|
+
expect(title).toBe('validation failed')
|
|
84
|
+
expect(description).toBe('sku: required')
|
|
85
|
+
expect(description).not.toContain('[object Object]')
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
73
89
|
describe('localizeFieldIssue', () => {
|
|
74
90
|
it('required → interpolates label', () => {
|
|
75
91
|
expect(localizeFieldIssue({ code: 'required' }, 'Nombre', t)).toBe('El campo Nombre es obligatorio')
|
|
@@ -95,6 +111,14 @@ describe('localizeFieldIssue', () => {
|
|
|
95
111
|
it('unknown code → generic fallback with label', () => {
|
|
96
112
|
expect(localizeFieldIssue({ code: 'weird_code' }, 'Campo', t)).toBe('Campo: valor inválido')
|
|
97
113
|
})
|
|
114
|
+
it('min + kind=length uses min_length catalog', () => {
|
|
115
|
+
expect(localizeFieldIssue({ code: 'min', params: { min: 3, kind: 'length' } }, 'SKU', t)).toBe(
|
|
116
|
+
'SKU debe tener al menos 3 caracteres',
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
it('en catalog when language is en', () => {
|
|
120
|
+
expect(localizeFieldIssue({ code: 'required' }, 'Name', t, 'en')).toBe('The Name field is required')
|
|
121
|
+
})
|
|
98
122
|
it('message passthrough (pre-localized) ignores code/label', () => {
|
|
99
123
|
const issue: FieldIssue = { message: 'Texto ya localizado' }
|
|
100
124
|
expect(localizeFieldIssue(issue, 'Ignorado', t)).toBe('Texto ya localizado')
|