@vtex/country-forms 1.0.1 → 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/CHANGELOG.md +45 -1
- package/README.md +2 -1
- package/dist/{BRA-PMVV6KOM.js → BRA-CWGYPPBD.js} +43 -27
- package/dist/BRA-CWGYPPBD.js.map +1 -0
- package/dist/{BRA-PCJDRSEF.mjs → BRA-JUHEOV7J.mjs} +3 -3
- package/dist/{BRA-PCJDRSEF.mjs.map → BRA-JUHEOV7J.mjs.map} +1 -1
- package/dist/{BRA-ZBZXE5II.mjs → BRA-R2DBJTZ2.mjs} +43 -27
- package/dist/BRA-R2DBJTZ2.mjs.map +1 -0
- package/dist/{BRA-WGCSNRCO.js → BRA-VIVRV7X7.js} +3 -3
- package/dist/{BRA-WGCSNRCO.js.map → BRA-VIVRV7X7.js.map} +1 -1
- package/dist/CAN-RDQPFPZU.mjs +127 -0
- package/dist/CAN-RDQPFPZU.mjs.map +1 -0
- package/dist/CAN-ZJQJFUW4.js +129 -0
- package/dist/CAN-ZJQJFUW4.js.map +1 -0
- package/dist/MEX-6CJCALY3.js +125 -0
- package/dist/MEX-6CJCALY3.js.map +1 -0
- package/dist/MEX-ZQL7ZS3G.mjs +123 -0
- package/dist/MEX-ZQL7ZS3G.mjs.map +1 -0
- package/dist/USA-2QW25XAI.mjs +128 -0
- package/dist/USA-2QW25XAI.mjs.map +1 -0
- package/dist/USA-MWP4SDGW.js +130 -0
- package/dist/USA-MWP4SDGW.js.map +1 -0
- package/dist/{bra-PZBWBUGB.js → bra-DQO5W7HB.js} +23 -31
- package/dist/bra-DQO5W7HB.js.map +1 -0
- package/dist/{bra-ZDFUVAXT.mjs → bra-MJUXI46I.mjs} +16 -27
- package/dist/bra-MJUXI46I.mjs.map +1 -0
- package/dist/can-3MOZIOGB.js +65 -0
- package/dist/can-3MOZIOGB.js.map +1 -0
- package/dist/can-DKTB2M6I.mjs +41 -0
- package/dist/can-DKTB2M6I.mjs.map +1 -0
- package/dist/can-LLWX4LC2.js +48 -0
- package/dist/can-LLWX4LC2.js.map +1 -0
- package/dist/can-OONXPDKH.mjs +59 -0
- package/dist/can-OONXPDKH.mjs.map +1 -0
- package/dist/chunk-B2XPLIJU.mjs +19 -0
- package/dist/chunk-B2XPLIJU.mjs.map +1 -0
- package/dist/{chunk-HKDTDE53.js → chunk-CFX5EF4R.js} +2 -2
- package/dist/{chunk-HKDTDE53.js.map → chunk-CFX5EF4R.js.map} +1 -1
- package/dist/{chunk-IVJED4TG.mjs → chunk-KWESVZKV.mjs} +2 -2
- package/dist/{chunk-IVJED4TG.mjs.map → chunk-KWESVZKV.mjs.map} +1 -1
- package/dist/chunk-ZQQPNXLP.js +21 -0
- package/dist/chunk-ZQQPNXLP.js.map +1 -0
- package/dist/common-E4IN3G46.mjs +4 -0
- package/dist/common-E4IN3G46.mjs.map +1 -0
- package/dist/common-LFDTUEMM.js +13 -0
- package/dist/common-LFDTUEMM.js.map +1 -0
- package/dist/{en-US-67K5REMQ.mjs → en-US-KHII5INO.mjs} +29 -14
- package/dist/en-US-KHII5INO.mjs.map +1 -0
- package/dist/{en-US-DXYSM6Q2.js → en-US-RCNO3BZC.js} +29 -14
- package/dist/en-US-RCNO3BZC.js.map +1 -0
- package/dist/{es-MX-UL5OL7HT.js → es-MX-IGOEW2P4.js} +28 -13
- package/dist/es-MX-IGOEW2P4.js.map +1 -0
- package/dist/{es-MX-2R6G2ZLS.mjs → es-MX-R24GRBU5.mjs} +28 -13
- package/dist/es-MX-R24GRBU5.mjs.map +1 -0
- package/dist/{fr-FR-GGR2M6TJ.mjs → fr-FR-N4WJAN23.mjs} +29 -14
- package/dist/fr-FR-N4WJAN23.mjs.map +1 -0
- package/dist/{fr-FR-LWA6B3MW.js → fr-FR-WZBI6O4O.js} +29 -14
- package/dist/fr-FR-WZBI6O4O.js.map +1 -0
- package/dist/index.d.mts +227 -11
- package/dist/index.d.ts +227 -11
- package/dist/index.js +127 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -44
- package/dist/index.mjs.map +1 -1
- package/dist/mex-AMEX6IHY.mjs +108 -0
- package/dist/mex-AMEX6IHY.mjs.map +1 -0
- package/dist/mex-DYWVMWB6.js +38 -0
- package/dist/mex-DYWVMWB6.js.map +1 -0
- package/dist/mex-VX3Y5I6I.mjs +33 -0
- package/dist/mex-VX3Y5I6I.mjs.map +1 -0
- package/dist/mex-Y56WV2L7.js +114 -0
- package/dist/mex-Y56WV2L7.js.map +1 -0
- package/dist/{pt-BR-KH6RW3HM.mjs → pt-BR-PIBP3JHL.mjs} +31 -13
- package/dist/pt-BR-PIBP3JHL.mjs.map +1 -0
- package/dist/{pt-BR-WVTTIEAH.js → pt-BR-ZDM55ITO.js} +31 -13
- package/dist/pt-BR-ZDM55ITO.js.map +1 -0
- package/dist/usa-AC7YPVS3.mjs +52 -0
- package/dist/usa-AC7YPVS3.mjs.map +1 -0
- package/dist/usa-B6NCCTF6.js +61 -0
- package/dist/usa-B6NCCTF6.js.map +1 -0
- package/dist/usa-LOOP7MRM.mjs +55 -0
- package/dist/usa-LOOP7MRM.mjs.map +1 -0
- package/dist/usa-OQ44AFEI.js +61 -0
- package/dist/usa-OQ44AFEI.js.map +1 -0
- package/package.json +1 -1
- package/dist/BRA-PMVV6KOM.js.map +0 -1
- package/dist/BRA-ZBZXE5II.mjs.map +0 -1
- package/dist/bra-PZBWBUGB.js.map +0 -1
- package/dist/bra-ZDFUVAXT.mjs.map +0 -1
- package/dist/can-7TMYDEJF.mjs +0 -17
- package/dist/can-7TMYDEJF.mjs.map +0 -1
- package/dist/can-B5ME2ZFN.js +0 -20
- package/dist/can-B5ME2ZFN.js.map +0 -1
- package/dist/can-BUKTOPLB.js +0 -21
- package/dist/can-BUKTOPLB.js.map +0 -1
- package/dist/can-SHRLPUU5.mjs +0 -19
- package/dist/can-SHRLPUU5.mjs.map +0 -1
- package/dist/en-US-67K5REMQ.mjs.map +0 -1
- package/dist/en-US-DXYSM6Q2.js.map +0 -1
- package/dist/es-MX-2R6G2ZLS.mjs.map +0 -1
- package/dist/es-MX-UL5OL7HT.js.map +0 -1
- package/dist/fr-FR-GGR2M6TJ.mjs.map +0 -1
- package/dist/fr-FR-LWA6B3MW.js.map +0 -1
- package/dist/mex-I3LUVYVC.mjs +0 -19
- package/dist/mex-I3LUVYVC.mjs.map +0 -1
- package/dist/mex-QT4CJZDD.js +0 -21
- package/dist/mex-QT4CJZDD.js.map +0 -1
- package/dist/pt-BR-KH6RW3HM.mjs.map +0 -1
- package/dist/pt-BR-WVTTIEAH.js.map +0 -1
- package/dist/usa-6PGU5UHS.mjs +0 -18
- package/dist/usa-6PGU5UHS.mjs.map +0 -1
- package/dist/usa-I7DK2CTL.mjs +0 -18
- package/dist/usa-I7DK2CTL.mjs.map +0 -1
- package/dist/usa-LFLDXKPA.js +0 -20
- package/dist/usa-LFLDXKPA.js.map +0 -1
- package/dist/usa-LXT6WW64.js +0 -21
- package/dist/usa-LXT6WW64.js.map +0 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/engine/createFormState.ts","../src/engine/setValue.ts","../src/engine/getVisibleFields.ts","../src/engine/validate.ts","../src/engine/format.ts","../src/engine/resolveFieldOptions.ts","../src/schemas/fallback.ts","../src/schemas/address/loader.ts","../src/schemas/personal-data/loader.ts","../src/engine/loadSchema.ts","../src/i18n/loader.ts","../src/i18n/resolveLabel.ts","../src/i18n/types.ts"],"names":[],"mappings":";;;;;AA4BO,SAAS,eAAA,CACd,QACA,QAAA,EACW;AACX,EAAA,MAAM,SAAqB,EAAC;AAC5B,EAAA,MAAM,UAAmC,EAAC;AAE1C,EAAA,KAAA,MAAW,KAAA,IAAS,OAAO,MAAA,EAAQ;AACjC,IAAA,MAAA,CAAO,MAAM,IAAI,CAAA,GAAI,QAAA,GAAW,KAAA,CAAM,IAAI,CAAA,IAAK,EAAA;AAC/C,IAAA,OAAA,CAAQ,KAA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M,EAAE,OAAO,CAAA;AAAA;AAE7D;;;ACxBO,SAAS,YAAA,CACd,GAAA,EACA,MAAA,EACA,SAAA,EACQ;AACR,EAAA,IAAI,cAAc,MAAA,EAAW;AAC3B,IAAA,MAAM,QAAA,GAAW,UAAU,GAAG,CAAA;AAC9B,IAAA,IAAI,QAAA,KAAa,QAAW,OAAO,QAAA;AAAA,EACrC;AAEA,EAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,EAAA,IAAI,KAAA,KAAU,QAAW,OAAO,KAAA;AAEhC,EAAA,OAAO,GAAA;AACT;;;AClCO,IAAM,iBAAA,GAAoB,CAAC,OAAA,EAAS,OAAA,EAAS,SAAS,OAAO","file":"index.mjs","sourcesContent":["/**\n * @module engine/createFormState\n */\n\nimport type { FormSchema, FormState, FormValues } from '../types'\n\n/**\n * Creates an initial {@link FormState} from a schema, optionally pre-filled\n * with default values.\n *\n * - `values`: initialized to the matching default or empty string for each field\n * - `errors`: empty map (no validation has run yet)\n * - `touched`: all `false` (no user interaction yet)\n *\n * @param schema - The `FormSchema` whose fields define the state shape\n * @param defaults - Optional partial map of field name → initial value\n * @returns A fresh, immutable `FormState`\n *\n * @example\n * const state = createFormState(schema)\n * // state.values → { postalCode: '', street: '', ... }\n * // state.errors → {}\n * // state.touched → { postalCode: false, street: false, ... }\n *\n * @example\n * const state = createFormState(schema, { city: 'São Paulo' })\n * // state.values.city → 'São Paulo'\n */\nexport function createFormState(\n schema: FormSchema,\n defaults?: Partial<FormValues>,\n): FormState {\n const values: FormValues = {}\n const touched: Record<string, boolean> = {}\n\n for (const field of schema.fields) {\n values[field.name] = defaults?.[field.name] ?? ''\n touched[field.name] = false\n }\n\n return { values, errors: {}, touched }\n}\n","/**\n * @module engine/setValue\n */\n\nimport type { FormSchema, FormState } from '../types'\n\n/**\n * Returns a new {@link FormState} with an updated field value.\n *\n * The operation is **immutable** — the original state is never mutated.\n * The updated field is automatically marked as `touched: true`.\n *\n * When the changed field is referenced by another field's `dependsOn` and that\n * field has `conditionalOptions`, the dependent field's value is automatically\n * reset to `''`. This prevents stale values when the controller field changes\n * (e.g. selecting a different state clears the previously selected city).\n *\n * Existing errors are preserved so the consumer can decide when to re-validate.\n * To clear all errors after a change, spread: `{ ...setValue(state, schema, f, v), errors: {} }`.\n *\n * @param state - Current form state (not mutated)\n * @param schema - The form schema (used to detect dependent fields)\n * @param fieldName - `FieldDefinition.name` of the field to update\n * @param value - New value for the field\n * @returns A new `FormState` with the updated value, touched flag, and dependent fields reset\n *\n * @example\n * const next = setValue(state, schema, 'street', 'Rua Augusta')\n * // next.values.street → 'Rua Augusta'\n * // next.touched.street → true\n * // state.values.street → '' (original unchanged)\n *\n * @example\n * // Dependent field reset: changing state clears city\n * const next = setValue(state, braSchema, 'state', 'RJ')\n * // next.values.state → 'RJ'\n * // next.values.city → '' (reset because city depends on state)\n */\nexport function setValue(\n state: FormState,\n schema: FormSchema,\n fieldName: string,\n value: string,\n): FormState {\n const next: FormState = {\n values: { ...state.values, [fieldName]: value },\n errors: { ...state.errors },\n touched: { ...state.touched, [fieldName]: true },\n }\n\n for (const field of schema.fields) {\n if (\n field.dependsOn === fieldName &&\n field.conditionalOptions !== undefined\n ) {\n next.values[field.name] = ''\n }\n }\n\n return next\n}\n","/**\n * @module engine/getVisibleFields\n *\n * Evaluates declarative `conditionalVisibility` expressions to determine which\n * fields should be shown — and therefore validated — given the current form values.\n *\n * ## Supported expressions\n *\n * Each field may declare a `conditionalVisibility` object with one condition\n * referencing a sibling field. The supported operators are:\n *\n * | Operator | Condition value type | Field is visible when… |\n * |----------------|----------------------|------------------------------------------------|\n * | `\"equals\"` | `string` | `values[field] === value` |\n * | `\"notEquals\"` | `string` | `values[field] !== value` |\n * | `\"includes\"` | `string \\| string[]` | `condition.value` contains `values[field]` |\n * | `\"notIncludes\"`| `string \\| string[]` | `condition.value` does not contain `values[field]` |\n *\n * A field with **no** `conditionalVisibility` is **always visible**.\n *\n * ## Usage\n *\n * ```typescript\n * const visibleFields = getVisibleFields(schema, state.values)\n * // Render only visibleFields; validate() uses this automatically.\n * ```\n *\n * ## Integration with validate\n *\n * `validate(state, schema)` calls `getVisibleFields` internally before running\n * rules, ensuring that hidden required fields never produce blocking errors.\n *\n * ## Missing controller value\n *\n * If the controller field named in `conditionalVisibility.field` has no value\n * in `values`, it is treated as an empty string `\"\"` when evaluating the condition.\n *\n * ## Composite conditions (future)\n *\n * The current implementation evaluates a single `ConditionalVisibility` object\n * per field (one condition, one operator). Logical composition (`and` / `or`) of\n * multiple conditions is reserved for a future schema version.\n */\n\nimport type { FieldDefinition, FormSchema, ConditionalVisibility } from '../types'\nimport type { FormValues } from '../types/engine'\n\n/**\n * Returns the ordered subset of `schema.fields` that are visible given `values`.\n *\n * Fields without `conditionalVisibility` are always included.\n * Fields whose condition evaluates to `false` are excluded — they will not be\n * rendered by the consumer and will not be validated by `validate()`.\n *\n * @param schema - The form schema containing all field definitions\n * @param values - Current form values keyed by field name\n * @returns Ordered array of visible `FieldDefinition` objects\n *\n * @example\n * // Field \"cnpj\" is only shown when \"personType\" === \"business\"\n * const visible = getVisibleFields(schema, state.values)\n * visible.forEach(field => renderField(field))\n */\nexport function getVisibleFields(schema: FormSchema, values: FormValues): FieldDefinition[] {\n return schema.fields.filter((field) => isFieldVisible(field, values))\n}\n\n/**\n * Evaluates whether a single field is visible given the current values.\n * Returns `true` when the field has no condition (unconditionally visible).\n */\nfunction isFieldVisible(field: FieldDefinition, values: FormValues): boolean {\n if (field.conditionalVisibility === undefined) {\n return true\n }\n\n return evaluateCondition(field.conditionalVisibility, values)\n}\n\n/**\n * Evaluates a `ConditionalVisibility` condition against the current form values.\n *\n * The controller field's current value defaults to `\"\"` when absent from `values`.\n * For `\"includes\"` / `\"notIncludes\"`, a scalar `condition.value` is treated as a\n * single-element array, so the operator is always safe to call regardless of whether\n * the schema author used a string or an array.\n */\nfunction evaluateCondition(condition: ConditionalVisibility, values: FormValues): boolean {\n const currentValue = values[condition.field] ?? ''\n\n switch (condition.operator) {\n case 'equals':\n return currentValue === condition.value\n\n case 'notEquals':\n return currentValue !== condition.value\n\n case 'includes': {\n const allowed = Array.isArray(condition.value) ? condition.value : [condition.value]\n return allowed.includes(currentValue)\n }\n\n case 'notIncludes': {\n const excluded = Array.isArray(condition.value) ? condition.value : [condition.value]\n return !excluded.includes(currentValue)\n }\n }\n}\n","/**\n * @module engine/validate\n *\n * Synchronous form validation — no network calls, no async, no UI dependencies.\n *\n * ## Validation order (per field, short-circuit on first error)\n *\n * 1. **required** — field is required and value is blank (trim-aware)\n * 2. **minLength** — value is shorter than the minimum\n * 3. **maxLength** — value is longer than the maximum\n * 4. **pattern** — value does not match the regex string\n * 5. **customValidator** — named function resolved from the rules registry\n *\n * Short-circuiting: validation stops at the first failing rule for each field.\n * Only one error key is produced per field at a time.\n *\n * ## Error values\n *\n * Every error in the returned `FormErrors` map is an **i18n key** (or the string\n * returned directly by a `customValidator`). Consumers resolve it via `resolveLabel`.\n *\n * ## Conditional visibility\n *\n * Fields with `conditionalVisibility` are only validated when they are visible.\n * `validate` calls `getVisibleFields(schema, state.values)` internally — hidden\n * required fields are silently skipped and never appear in the returned error map.\n */\n\nimport type { FieldDefinition, FormSchema } from '../types'\nimport type { FormErrors, FormState } from '../types/engine'\nimport { resolveValidator } from '../rules/validators'\nimport { getVisibleFields } from './getVisibleFields'\n\n/**\n * i18n key used when a required field has no value.\n * Consumers resolve this via `resolveLabel(key, bundle, overrides)`.\n */\nexport const VALIDATION_REQUIRED_KEY = 'country-forms.validation.required'\n\n/**\n * i18n key used as fallback when a `customValidator` returns `false`\n * (invalid but without a specific message).\n */\nexport const VALIDATION_INVALID_KEY = 'country-forms.validation.invalid'\n\n/**\n * Runs all synchronous validation rules in `schema` against the current `state`.\n *\n * Rules applied per field (in order, short-circuit on first error):\n * `required` → `minLength` → `maxLength` → `pattern` → `customValidator`\n *\n * @param state - Current form state (values to validate against)\n * @param schema - Schema whose validation rules are applied\n * @returns Sparse `FormErrors` map — empty object means the form is valid.\n * Only fields with errors appear as keys.\n *\n * @example\n * const errors = validate(state, schema)\n * if (Object.keys(errors).length > 0) {\n * state = { ...state, errors }\n * return\n * }\n */\nexport function validate(state: FormState, schema: FormSchema): FormErrors {\n const errors: FormErrors = {}\n\n for (const field of getVisibleFields(schema, state.values)) {\n const value = state.values[field.name] ?? ''\n const error = validateField(field, value)\n\n if (error !== null) {\n errors[field.name] = error\n }\n }\n\n return errors\n}\n\n/**\n * Validates a single field value against its definition.\n * Returns the i18n error key (or custom message) on failure, `null` on success.\n */\nfunction validateField(field: FieldDefinition, value: string): string | null {\n const trimmed = value.trim()\n\n // ── 1. required ────────────────────────────────────────────────────────────\n if (field.required && trimmed === '') {\n return VALIDATION_REQUIRED_KEY\n }\n\n // Optional field with no meaningful value — skip format rules.\n if (trimmed === '') {\n return null\n }\n\n const rules = field.validation\n\n if (!rules) {\n return null\n }\n\n // ── 2. minLength ───────────────────────────────────────────────────────────\n if (rules.minLength !== undefined && value.length < rules.minLength.value) {\n return rules.minLength.message\n }\n\n // ── 3. maxLength ───────────────────────────────────────────────────────────\n if (rules.maxLength !== undefined && value.length > rules.maxLength.value) {\n return rules.maxLength.message\n }\n\n // ── 4. pattern ──────────────────────────────────────────────────────────────\n if (rules.pattern !== undefined) {\n // Compile the serializable regex string. An invalid pattern string is a\n // schema-authoring error and is allowed to throw (caught at dev time by tests).\n const regex = new RegExp(rules.pattern.value)\n\n if (!regex.test(value)) {\n return rules.pattern.message\n }\n }\n\n // ── 5. customValidator ───────────────────────────────────────────────────────\n if (rules.customValidator !== undefined) {\n const fn = resolveValidator(rules.customValidator)\n const result = fn(value)\n\n if (result === true) {\n return null\n }\n\n // Validator returned a specific i18n error key — use it directly.\n if (typeof result === 'string') {\n return result\n }\n\n // Validator returned false — field is invalid but no specific message provided.\n return VALIDATION_INVALID_KEY\n }\n\n return null\n}\n","/**\n * @module engine/format\n *\n * Format and unformat helpers that apply mask functions from the rules registry\n * to a field's value, driven by the field's `formatRef` / `unformatRef`.\n *\n * ## Typical usage\n *\n * ```typescript\n * // Display: raw → formatted (e.g. \"01310100\" → \"01310-100\")\n * const displayed = formatValue(field.formatRef, rawValue)\n *\n * // Submission: formatted → raw (e.g. \"01310-100\" → \"01310100\")\n * const raw = unformatValue(field.unformatRef, displayedValue)\n * ```\n *\n * ## Identity behaviour (no mask)\n *\n * When `ref` is `undefined` (field has no mask) or the ref has not been registered,\n * the function returns the value unchanged. This makes both functions safe to call\n * unconditionally — consumers can always pass `field.formatRef` without guarding.\n */\n\nimport { resolveMask, hasMask } from '../rules/masks'\n\n/**\n * Returns the **display** representation of `value`.\n *\n * Resolves `ref` from the masks registry and applies the registered format function.\n *\n * `ref` accepts `string | undefined` so callers can forward `field.formatRef` directly\n * without guarding against fields that have no mask. This removes boilerplate at every\n * call site — the trade-off is that passing `undefined` by mistake produces no error signal,\n * returning `value` silently unchanged instead.\n *\n * @param ref - `FieldDefinition.formatRef`, e.g. `\"formatCEP\"`.\n * Pass `undefined` (or omit the guard) for fields that carry no mask.\n * @param value - Raw value to format (e.g. `\"01310100\"`).\n * @returns Formatted display string (e.g. `\"01310-100\"`) when `ref` is a registered key;\n * `value` unchanged (identity) when `ref` is `undefined` or not found in the registry.\n *\n * @example\n * formatValue(field.formatRef, '01310100') // → \"01310-100\" (mask applied)\n * formatValue(undefined, 'Av Paulista') // → \"Av Paulista\" (no ref — identity)\n * formatValue('unknownRef', '01310100') // → \"01310100\" (not registered — identity)\n */\nexport function formatValue(\n ref: string | undefined,\n value: string,\n): string {\n if (ref === undefined || !hasMask(ref)) {\n return value\n }\n\n return resolveMask(ref)(value)\n}\n\n/**\n * Returns the **raw/API** representation of `value`, stripping any display formatting.\n *\n * Resolves `ref` from the masks registry and applies the registered unformat function.\n * Symmetric to {@link formatValue} — same `string | undefined` ergonomic contract applies.\n *\n * The round-trip invariant holds when masks are correctly paired:\n * `unformatValue(field.unformatRef, formatValue(field.formatRef, raw)) === raw`\n *\n * @param ref - `FieldDefinition.unformatRef`, e.g. `\"unformatCEP\"`.\n * Pass `undefined` (or omit the guard) for fields that carry no mask.\n * @param value - Display value to strip (e.g. `\"01310-100\"`).\n * @returns Raw string suitable for API submission (e.g. `\"01310100\"`) when `ref` is a registered key;\n * `value` unchanged (identity) when `ref` is `undefined` or not found in the registry.\n *\n * @example\n * unformatValue(field.unformatRef, '01310-100') // → \"01310100\" (mask applied)\n * unformatValue(undefined, 'Av Paulista') // → \"Av Paulista\" (no ref — identity)\n * unformatValue('unknownRef', '01310-100') // → \"01310-100\" (not registered — identity)\n */\nexport function unformatValue(\n ref: string | undefined,\n value: string,\n): string {\n if (ref === undefined || !hasMask(ref)) {\n return value\n }\n\n return resolveMask(ref)(value)\n}\n","/**\n * @module engine/resolveFieldOptions\n */\n\nimport type { FieldDefinition, FormValues, SelectOption } from '../types'\nimport { hasOptions, resolveOptions } from '../rules/options'\n\ntype OptionSource = SelectOption[] | string | undefined\n\n/**\n * Resolves the effective options for a field, including dependent options.\n *\n * Resolution order:\n * 1) `conditionalOptions` entry matching `values[dependsOn]`\n * 2) `options` fallback on the field\n *\n * @param field - The field definition to resolve options for\n * @param values - Current form values (used to look up the controller field via `dependsOn`)\n * @returns `SelectOption[]` when options are available, `null` when no source is resolvable\n */\nexport function resolveFieldOptions(\n field: FieldDefinition,\n values: FormValues,\n): SelectOption[] | null {\n const source = getOptionSource(field, values)\n if (source === undefined) {\n return null\n }\n\n if (Array.isArray(source)) {\n return source\n }\n\n if (hasOptions(source)) {\n return resolveOptions(source)\n }\n\n return null\n}\n\nfunction getOptionSource(field: FieldDefinition, values: FormValues): OptionSource {\n if (field.dependsOn !== undefined && field.conditionalOptions !== undefined) {\n const controllerValue = values[field.dependsOn] ?? ''\n if (controllerValue in field.conditionalOptions) {\n return field.conditionalOptions[controllerValue]\n }\n }\n\n return field.options\n}\n","/**\n * Generic fallback schemas returned by `loadSchema` when an unsupported country\n * code is requested.\n *\n * ## Fallback contract\n *\n * - `loadSchema` never throws for an unknown country — it returns a deterministic fallback.\n * - The fallback schema carries the **requested** `iso3` code in `country`, so the\n * caller always receives a structurally valid `FormSchema`.\n * - Fallback fields are a minimal, internationally-recognizable subset.\n * - No validator/mask refs are included to avoid registry resolution errors.\n *\n * ## Design rationale\n *\n * **Address**: Many countries don't use postal codes and address structures vary\n * wildly. The fallback provides a single free-text `street` field so the user can\n * enter whatever format is conventional in their country.\n *\n * **Personal data**: Some regions prefer phone numbers over email for user\n * identification. The fallback lets the user choose between email and phone via a\n * `contactType` radio group with conditional visibility on the corresponding field.\n *\n * ## When a country becomes supported\n *\n * Add a named schema file (e.g. `src/schemas/address/FRA.ts`) and register it in\n * the corresponding loader (`src/schemas/address/loader.ts` or\n * `src/schemas/personal-data/loader.ts`). The fallback will no longer be used\n * for that country.\n */\n\nimport type { FormSchema, FormType } from '../types'\n\nconst FALLBACK_ADDRESS_FIELDS: FormSchema['fields'] = [\n {\n name: 'street',\n type: 'text',\n label: 'country-forms.address.street.label',\n placeholder: 'country-forms.address.street.placeholder',\n required: true,\n inputMode: 'text',\n },\n]\n\nconst FALLBACK_PERSONAL_DATA_FIELDS: FormSchema['fields'] = [\n {\n name: 'firstName',\n type: 'text',\n label: 'country-forms.personal-data.firstName.label',\n required: true,\n inputMode: 'text',\n },\n {\n name: 'lastName',\n type: 'text',\n label: 'country-forms.personal-data.lastName.label',\n required: true,\n inputMode: 'text',\n },\n {\n name: 'contactType',\n type: 'radio-group',\n label: 'country-forms.personal-data.contactType.label',\n required: true,\n options: [\n { value: 'email', displayValue: 'country-forms.personal-data.contactType.email' },\n { value: 'phone', displayValue: 'country-forms.personal-data.contactType.phone' },\n ],\n },\n {\n name: 'email',\n type: 'email',\n label: 'country-forms.personal-data.email.label',\n required: true,\n inputMode: 'email',\n conditionalVisibility: {\n field: 'contactType',\n operator: 'equals',\n value: 'email',\n },\n },\n {\n name: 'phone',\n type: 'text',\n label: 'country-forms.personal-data.phone.label',\n required: true,\n inputMode: 'tel',\n conditionalVisibility: {\n field: 'contactType',\n operator: 'equals',\n value: 'phone',\n },\n },\n]\n\n/**\n * Creates a minimal generic `FormSchema` for a country/formType combination that has\n * no dedicated schema registered.\n *\n * The schema is deterministic: the same inputs always produce the same output.\n * No validator or mask refs are included (to avoid registry errors for unknown countries).\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"XYZ\"`)\n * @param formType - `\"address\"` or `\"personal-data\"`\n * @returns A generic `FormSchema` with minimal internationally-recognizable fields\n */\nexport function createFallbackSchema(\n iso3: string,\n formType: FormType,\n): FormSchema {\n const fields =\n formType === 'address'\n ? FALLBACK_ADDRESS_FIELDS\n : FALLBACK_PERSONAL_DATA_FIELDS\n\n return {\n id: `${formType}-${iso3}`,\n country: iso3,\n formType,\n fields,\n }\n}\n","/**\n * Dynamic import map for address schemas.\n * Each country is loaded on demand via `import()` for code-splitting.\n *\n * When adding a new country schema:\n * 1. Add the ISO 3166-1 alpha-3 code to `SUPPORTED_ADDRESS_COUNTRIES`\n * 2. Add a `case` in `loadAddressSchema` with `import('./<CODE>')`\n * 3. Import the country's rule modules (validators, masks, options) in the case body\n */\n\nimport type { FormSchema } from '../../types'\nimport { createFallbackSchema } from '../fallback'\n\n/**\n * ISO 3166-1 alpha-3 codes for countries with a dedicated address schema.\n * Grows as country schemas are implemented.\n * Consumers can import this to build country selectors or validate input.\n *\n * @example\n * import { SUPPORTED_ADDRESS_COUNTRIES } from '@vtex/country-forms'\n * // currently supported countries: → ['BRA', 'CAN', 'MEX', 'USA']\n */\nexport const SUPPORTED_ADDRESS_COUNTRIES: readonly string[] = ['BRA', 'CAN', 'MEX', 'USA']\n\n/**\n * Loads the address schema for a given country via dynamic `import()`.\n * Falls back to a generic schema for unrecognized country codes.\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"BRA\"`, `\"USA\"`)\n * @returns The address `FormSchema` for the country, or a generic fallback schema\n */\nexport async function loadAddressSchema(iso3: string): Promise<FormSchema> {\n switch (iso3) {\n case 'BRA': {\n const [{ default: schema }] = await Promise.all([\n import('./BRA'),\n import('../../rules/validators/bra'),\n import('../../rules/masks/bra'),\n import('../../rules/options/bra-states'),\n ])\n return schema\n }\n\n case 'CAN': {\n const [{ default: schema }] = await Promise.all([\n import('./CAN'),\n import('../../rules/validators/can'),\n import('../../rules/masks/can'),\n import('../../rules/options/can-provinces'),\n ])\n return schema\n }\n\n case 'MEX': {\n const [{ default: schema }] = await Promise.all([\n import('./MEX'),\n import('../../rules/validators/mex'),\n import('../../rules/options/mex-states'),\n ])\n return schema\n }\n\n case 'USA': {\n const [{ default: schema }] = await Promise.all([\n import('./USA'),\n import('../../rules/validators/usa'),\n import('../../rules/masks/usa'),\n import('../../rules/options/usa-states'),\n ])\n return schema\n }\n\n default:\n return createFallbackSchema(iso3, 'address')\n }\n}\n","/**\n * Dynamic import map for personal-data schemas.\n * Each country is loaded on demand via `import()` for code-splitting.\n *\n * When adding a new country schema:\n * 1. Add the ISO 3166-1 alpha-3 code to `SUPPORTED_PERSONAL_DATA_COUNTRIES`\n * 2. Add a `case` in `loadPersonalDataSchema` with dynamic imports\n * 3. Import the country's rule modules (validators, masks, options) in the case body\n */\n\nimport type { FormSchema } from '../../types'\nimport { createFallbackSchema } from '../fallback'\n\n/**\n * ISO 3166-1 alpha-3 codes for countries with a dedicated personal-data schema.\n * Grows as country schemas are implemented.\n *\n * @example\n * import { SUPPORTED_PERSONAL_DATA_COUNTRIES } from '@vtex/country-forms'\n * // currently supported countries: → ['BRA']\n */\nexport const SUPPORTED_PERSONAL_DATA_COUNTRIES: readonly string[] = ['BRA']\n\n/**\n * Loads the personal-data schema for a given country via dynamic `import()`.\n * Falls back to a generic schema for unrecognized country codes.\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"BRA\"`)\n * @returns The personal-data `FormSchema` for the country, or a generic fallback schema\n */\nexport async function loadPersonalDataSchema(\n iso3: string,\n): Promise<FormSchema> {\n switch (iso3) {\n case 'BRA': {\n const [{ default: schema }] = await Promise.all([\n import('./BRA'),\n import('../../rules/validators/bra'),\n import('../../rules/masks/bra'),\n ])\n return schema\n }\n\n default:\n return createFallbackSchema(iso3, 'personal-data')\n }\n}\n","/**\n * @module engine/loadSchema\n *\n * Loads a `FormSchema` for a given country code and form type on demand.\n * Each country's schema is a separate module, enabling **code-splitting**: only the\n * requested country's code enters the consumer's bundle.\n *\n * ## Fallback behaviour\n *\n * If `iso3` is not supported (or `formType` has no dedicated schemas yet),\n * `loadSchema` returns a **deterministic generic fallback schema** — it never throws\n * at runtime for an unknown country code. The fallback carries the requested `iso3`\n * in `schema.country` and provides a minimal set of generic fields.\n */\n\nimport type { FormSchema, FormType } from '../types'\nimport {\n loadAddressSchema,\n SUPPORTED_ADDRESS_COUNTRIES,\n} from '../schemas/address/loader'\nimport {\n loadPersonalDataSchema,\n SUPPORTED_PERSONAL_DATA_COUNTRIES,\n} from '../schemas/personal-data/loader'\n\nexport { SUPPORTED_ADDRESS_COUNTRIES, SUPPORTED_PERSONAL_DATA_COUNTRIES }\n\n/**\n * Loads and returns the `FormSchema` for the given country code and form type.\n *\n * - Uses dynamic `import()` internally for each country module (code-splitting).\n * - Returns a **generic fallback schema** for unsupported country codes — never throws.\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"BRA\"`, `\"USA\"`)\n * @param formType - Form category: `\"address\"` or `\"personal-data\"`\n * @returns Promise resolving to the country's `FormSchema`\n *\n * @example\n * const schema = await loadSchema('BRA', 'address')\n * // → FormSchema { id: \"address-BRA\", country: \"BRA\", formType: \"address\", fields: [...] }\n *\n * const unknown = await loadSchema('XYZ', 'address')\n * // → fallback FormSchema { id: \"address-XYZ\", country: \"XYZ\", ... }\n */\nexport async function loadSchema(\n iso3: string,\n formType: FormType,\n): Promise<FormSchema> {\n switch (formType) {\n case 'address':\n return loadAddressSchema(iso3)\n case 'personal-data':\n return loadPersonalDataSchema(iso3)\n }\n}\n","/**\n * @module i18n/loader\n *\n * `loadLocale(locale)` — dynamically imports the i18n bundle for the requested\n * BCP 47 locale tag, enabling code-splitting: only the locale actually used\n * enters the consumer's bundle.\n *\n * ## Resolution order\n *\n * 1. **Exact match** on the canonical supported tag (`en-US`, `es-MX`, `fr-FR`, `pt-BR`).\n * 2. **Language-subtag fallback** — the language portion before the `-` is used\n * to match a bundle, so regional variants resolve gracefully:\n * - `en-GB`, `en-AU` → `en-US` bundle\n * - `es-419`, `es-ES` → `es-MX` bundle\n * - `fr-CA` → `fr-FR` bundle\n * - `pt-PT` → `pt-BR` bundle\n * 3. **Default fallback** — any unrecognized tag returns the `en-US` bundle.\n *\n * The function **never throws** for an unsupported locale.\n *\n * @param locale - BCP 47 locale tag (e.g. `\"pt-BR\"`, `\"en-US\"`, `\"es-419\"`)\n * @returns Resolved `I18nBundle` for the best-matching locale\n *\n * @example\n * const bundle = await loadLocale('pt-BR')\n * bundle['country-forms.address.postalCode.label'] // \"CEP\"\n *\n * @example\n * const bundle = await loadLocale('de-DE') // → en-US bundle (fallback)\n */\n\nimport type { I18nBundle } from '../types/i18n'\n\nexport async function loadLocale(locale: string): Promise<I18nBundle> {\n switch (locale) {\n case 'en-US':\n return import('./messages/en-US').then((m) => m.default)\n case 'es-MX':\n return import('./messages/es-MX').then((m) => m.default)\n case 'fr-FR':\n return import('./messages/fr-FR').then((m) => m.default)\n case 'pt-BR':\n return import('./messages/pt-BR').then((m) => m.default)\n }\n\n const lang = locale.split('-')[0]?.toLowerCase()\n\n switch (lang) {\n case 'en':\n return import('./messages/en-US').then((m) => m.default)\n case 'es':\n return import('./messages/es-MX').then((m) => m.default)\n case 'fr':\n return import('./messages/fr-FR').then((m) => m.default)\n case 'pt':\n return import('./messages/pt-BR').then((m) => m.default)\n default:\n return import('./messages/en-US').then((m) => m.default)\n }\n}\n","/**\n * @module i18n/resolveLabel\n *\n * Resolves an i18n key to its display string using a three-level cascade:\n *\n * 1. **Consumer override** — `overrides[key]` wins if present.\n * 2. **Bundle value** — `bundle[key]` from `loadLocale()`.\n * 3. **Raw key** — the key itself is returned as a last resort, so the UI\n * never shows `undefined` or crashes.\n *\n * This design lets consumers customize individual labels without forking the\n * library or replacing the entire bundle.\n *\n * @param key - i18n key (e.g. `\"country-forms.address.postalCode.label\"`)\n * @param bundle - Locale bundle loaded via `loadLocale()`\n * @param overrides - Optional consumer-supplied overrides\n * @returns Resolved display string\n *\n * @example\n * const bundle = await loadLocale('pt-BR')\n * resolveLabel('country-forms.address.postalCode.label', bundle)\n * // → \"CEP\"\n *\n * @example\n * const overrides = { 'country-forms.address.postalCode.label': 'ZIP / CEP' }\n * resolveLabel('country-forms.address.postalCode.label', bundle, overrides)\n * // → \"ZIP / CEP\" (override wins)\n *\n * @example\n * resolveLabel('country-forms.unknown.key', bundle)\n * // → \"country-forms.unknown.key\" (raw key fallback)\n */\n\nimport type { I18nBundle, I18nOverrides } from '../types/i18n'\n\nexport function resolveLabel(\n key: string,\n bundle: I18nBundle,\n overrides?: I18nOverrides,\n): string {\n if (overrides !== undefined) {\n const override = overrides[key]\n if (override !== undefined) return override\n }\n\n const value = bundle[key]\n if (value !== undefined) return value\n\n return key\n}\n","/**\n * BCP 47 locale tags supported by the library's built-in translation bundles.\n *\n * | Tag | Language |\n * |----------|---------------------------|\n * | `en-US` | English (United States) |\n * | `es-MX` | Spanish (Mexico) |\n * | `fr-FR` | French (France) |\n * | `pt-BR` | Portuguese (Brazil) |\n *\n * Any other tag passed to `loadLocale` falls back to `en-US`.\n * Regional variants (e.g. `en-GB`, `es-419`) also resolve via the language\n * subtag — see `loadLocale` for details.\n */\n/** @const BCP 47 tags with built-in bundles. See `loadLocale` for resolution. */\nexport const SUPPORTED_LOCALES = ['en-US', 'es-MX', 'fr-FR', 'pt-BR'] as const\n\n/** Union of BCP 47 tags with dedicated built-in bundles. */\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/engine/createFormState.ts","../src/engine/setValue.ts","../src/engine/getVisibleFields.ts","../src/engine/resolveField.ts","../src/engine/validate.ts","../src/engine/format.ts","../src/engine/resolveFieldOptions.ts","../src/schemas/fallback.ts","../src/schemas/address/loader.ts","../src/schemas/personal-data/loader.ts","../src/engine/loadSchema.ts","../src/i18n/loader.ts","../src/i18n/resolveLabel.ts","../src/i18n/types.ts"],"names":[],"mappings":";;;;;AA4BO,SAAS,eAAA,CACd,QACA,QAAA,EACW;AACX,EAAA,MAAM,SAAqB,EAAC;AAC5B,EAAA,MAAM,UAAmC,EAAC;AAE1C,EAAA,KAAA,MAAW,KAAA,IAAS,OAAO,MAAA,EAAQ;AACjC,IAAA,MAAA,CAAO,MAAM,IAAI,CAAA,GAAI,QAAA,GAAW,KAAA,CAAM,IAAI,CAAA,IAAK,EAAA;AAC/C,IAAA,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,GAAI,KAAA;AAAA,EACxB;AAGA,EAAA,KAAA,MAAW,KAAA,IAAS,OAAO,MAAA,EAAQ;AACjC,IAAA,IAAI,KAAA,CAAM,gBAAgB,MAAA,EAAW;AACnC,MAAA,MAAM,eAAA,GAAkB,MAAA,CAAO,KAAA,CAAM,WAAW,CAAA,IAAK,EAAA;AACrD,MAAA,MAAA,CAAO,MAAM,IAAI,CAAA,GAAI,KAAA,CAAM,YAAA,GAAe,eAAe,CAAA,IAAK,EAAA;AAAA,IAChE;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,MAAA,EAAQ,IAAI,OAAA,EAAQ;AACvC;;;ACLO,SAAS,QAAA,CACd,KAAA,EACA,MAAA,EACA,SAAA,EACA,KAAA,EACW;AACX,EAAA,MAAM,IAAA,GAAkB;AAAA,IACtB,MAAA,EAAQ,EAAE,GAAG,KAAA,CAAM,QAAQ,CAAC,SAAS,GAAG,KAAA,EAAM;AAAA,IAC9C,MAAA,EAAQ,EAAE,GAAG,KAAA,CAAM,MAAA,EAAO;AAAA,IAC1B,OAAA,EAAS,EAAE,GAAG,KAAA,CAAM,SAAS,CAAC,SAAS,GAAG,IAAA;AAA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AI,KAAA,KAAU,QAAW,QAAA,GAAW,KAAA;AAAA,IACtC;AAAA,EACF,CAAA,MAAO;AACL,IAAA,MAAM,KAAA,GAAQ,OAAO,GAAG,CAAA;AACxB,IAAA,IAAI,KAAA,KAAU,QAAW,QAAA,GAAW,KAAA;AAAA,EACtC;AAEA,EAAA,IAAI,MAAA,KAAW,QAAW,OAAO,QAAA;AAEjC,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,iBAAA,EAAmB,CAAC,OAAO,IAAA,KAAiB;AAClE,IAAA,MAAM,WAAA,GAAc,OAAO,IAAI,CAAA;AAC/B,IAAA,OAAO,WAAA,KAAgB,MAAA,GAAY,KAAA,GAAQ,MAAA,CAAO,WAAW,CAAA;AAAA,EAC/D,CAAC,CAAA;AACH;;;AC3EO,IAAM,iBAAA,GAAoB,CAAC,OAAA,EAAS,OAAA,EAAS,SAAS,OAAO","file":"index.mjs","sourcesContent":["/**\n * @module engine/createFormState\n */\n\nimport type { FormSchema, FormState, FormValues } from '../types'\n\n/**\n * Creates an initial {@link FormState} from a schema, optionally pre-filled\n * with default values.\n *\n * - `values`: initialized to the matching default or empty string for each field\n * - `errors`: empty map (no validation has run yet)\n * - `touched`: all `false` (no user interaction yet)\n *\n * @param schema - The `FormSchema` whose fields define the state shape\n * @param defaults - Optional partial map of field name → initial value\n * @returns A fresh, immutable `FormState`\n *\n * @example\n * const state = createFormState(schema)\n * // state.values → { postalCode: '', street: '', ... }\n * // state.errors → {}\n * // state.touched → { postalCode: false, street: false, ... }\n *\n * @example\n * const state = createFormState(schema, { city: 'São Paulo' })\n * // state.values.city → 'São Paulo'\n */\nexport function createFormState(\n schema: FormSchema,\n defaults?: Partial<FormValues>,\n): FormState {\n const values: FormValues = {}\n const touched: Record<string, boolean> = {}\n\n for (const field of schema.fields) {\n values[field.name] = defaults?.[field.name] ?? ''\n touched[field.name] = false\n }\n\n // Seed derived, data-only fields from their controller's initial value.\n for (const field of schema.fields) {\n if (field.derivedFrom !== undefined) {\n const controllerValue = values[field.derivedFrom] ?? ''\n values[field.name] = field.derivedValue?.[controllerValue] ?? ''\n }\n }\n\n return { values, errors: {}, touched }\n}\n","/**\n * @module engine/setValue\n */\n\nimport type { FormSchema, FormState } from '../types'\n\n/**\n * Returns a new {@link FormState} with an updated field value.\n *\n * The operation is **immutable** — the original state is never mutated.\n * The updated field is automatically marked as `touched: true`.\n *\n * When the changed field is referenced by another field's `dependsOn` and that\n * field has `conditionalOptions` or `conditionalValidator`, the dependent field's\n * value is automatically reset to `''`. This prevents stale values when the\n * controller field changes — e.g. selecting a different state clears the previously\n * selected city, or switching `personType` clears the `document` whose validator\n * (CPF vs CNPJ) just changed.\n *\n * Derived, data-only fields ({@link FieldDefinition.derivedFrom}) referencing the\n * changed field are recomputed from their `derivedValue` map (e.g. `documentType`\n * follows `personType`).\n *\n * Existing errors are preserved so the consumer can decide when to re-validate.\n * To clear all errors after a change, spread: `{ ...setValue(state, schema, f, v), errors: {} }`.\n *\n * @param state - Current form state (not mutated)\n * @param schema - The form schema (used to detect dependent fields)\n * @param fieldName - `FieldDefinition.name` of the field to update\n * @param value - New value for the field\n * @returns A new `FormState` with the updated value, touched flag, and dependent fields reset\n *\n * @example\n * const next = setValue(state, schema, 'street', 'Rua Augusta')\n * // next.values.street → 'Rua Augusta'\n * // next.touched.street → true\n * // state.values.street → '' (original unchanged)\n *\n * @example\n * // Dependent field reset: changing state clears city\n * const next = setValue(state, braSchema, 'state', 'RJ')\n * // next.values.state → 'RJ'\n * // next.values.city → '' (reset because city depends on state)\n */\nexport function setValue(\n state: FormState,\n schema: FormSchema,\n fieldName: string,\n value: string,\n): FormState {\n const next: FormState = {\n values: { ...state.values, [fieldName]: value },\n errors: { ...state.errors },\n touched: { ...state.touched, [fieldName]: true },\n }\n\n for (const field of schema.fields) {\n // Reset dependents whose value domain changes with the controller.\n if (\n field.dependsOn === fieldName &&\n (field.conditionalOptions !== undefined || field.conditionalValidator !== undefined)\n ) {\n next.values[field.name] = ''\n }\n\n // Recompute derived, data-only fields from their controller's new value.\n if (field.derivedFrom === fieldName) {\n next.values[field.name] = field.derivedValue?.[value] ?? ''\n }\n }\n\n return next\n}\n","/**\n * @module engine/getVisibleFields\n *\n * Evaluates declarative `conditionalVisibility` expressions to determine which\n * fields should be shown — and therefore validated — given the current form values.\n *\n * ## Supported expressions\n *\n * Each field may declare a `conditionalVisibility` object with one condition\n * referencing a sibling field. The supported operators are:\n *\n * | Operator | Condition value type | Field is visible when… |\n * |----------------|----------------------|------------------------------------------------|\n * | `\"equals\"` | `string` | `values[field] === value` |\n * | `\"notEquals\"` | `string` | `values[field] !== value` |\n * | `\"includes\"` | `string \\| string[]` | `condition.value` contains `values[field]` |\n * | `\"notIncludes\"`| `string \\| string[]` | `condition.value` does not contain `values[field]` |\n *\n * A field with **no** `conditionalVisibility` is **always visible**.\n *\n * ## Usage\n *\n * ```typescript\n * const visibleFields = getVisibleFields(schema, state.values)\n * // Render only visibleFields; validate() uses this automatically.\n * ```\n *\n * ## Integration with validate\n *\n * `validate(state, schema)` calls `getVisibleFields` internally before running\n * rules, ensuring that hidden required fields never produce blocking errors.\n *\n * ## Missing controller value\n *\n * If the controller field named in `conditionalVisibility.field` has no value\n * in `values`, it is treated as an empty string `\"\"` when evaluating the condition.\n *\n * ## Composite conditions (future)\n *\n * The current implementation evaluates a single `ConditionalVisibility` object\n * per field (one condition, one operator). Logical composition (`and` / `or`) of\n * multiple conditions is reserved for a future schema version.\n */\n\nimport type { FieldDefinition, FormSchema, ConditionalVisibility } from '../types'\nimport type { FormValues } from '../types/engine'\n\n/**\n * Returns the ordered subset of `schema.fields` that are visible given `values`.\n *\n * Fields without `conditionalVisibility` are always included.\n * Fields whose condition evaluates to `false` are excluded — they will not be\n * rendered by the consumer and will not be validated by `validate()`.\n *\n * @param schema - The form schema containing all field definitions\n * @param values - Current form values keyed by field name\n * @returns Ordered array of visible `FieldDefinition` objects\n *\n * @example\n * // Field \"cnpj\" is only shown when \"personType\" === \"business\"\n * const visible = getVisibleFields(schema, state.values)\n * visible.forEach(field => renderField(field))\n */\nexport function getVisibleFields(schema: FormSchema, values: FormValues): FieldDefinition[] {\n return schema.fields.filter((field) => isFieldVisible(field, values))\n}\n\n/**\n * Evaluates whether a single field is visible given the current values.\n * Returns `true` when the field has no condition (unconditionally visible).\n *\n * Derived, data-only fields ({@link FieldDefinition.derivedFrom}) are never\n * visible: their value is computed automatically and they are not rendered.\n */\nfunction isFieldVisible(field: FieldDefinition, values: FormValues): boolean {\n if (field.derivedFrom !== undefined) {\n return false\n }\n\n if (field.conditionalVisibility === undefined) {\n return true\n }\n\n return evaluateCondition(field.conditionalVisibility, values)\n}\n\n/**\n * Evaluates a `ConditionalVisibility` condition against the current form values.\n *\n * The controller field's current value defaults to `\"\"` when absent from `values`.\n * For `\"includes\"` / `\"notIncludes\"`, a scalar `condition.value` is treated as a\n * single-element array, so the operator is always safe to call regardless of whether\n * the schema author used a string or an array.\n */\nfunction evaluateCondition(condition: ConditionalVisibility, values: FormValues): boolean {\n const currentValue = values[condition.field] ?? ''\n\n switch (condition.operator) {\n case 'equals':\n return currentValue === condition.value\n\n case 'notEquals':\n return currentValue !== condition.value\n\n case 'includes': {\n const allowed = Array.isArray(condition.value) ? condition.value : [condition.value]\n return allowed.includes(currentValue)\n }\n\n case 'notIncludes': {\n const excluded = Array.isArray(condition.value) ? condition.value : [condition.value]\n return !excluded.includes(currentValue)\n }\n }\n}\n","/**\n * @module engine/resolveField\n *\n * Resolvers for fields whose label, placeholder, validator, or mask change based\n * on a sibling controller field (declared via `dependsOn`).\n *\n * These mirror {@link resolveFieldOptions}: each resolver looks up the controller\n * value in the field's conditional map and falls back to the field's static\n * property when no entry matches. They let a single field — e.g. a `document`\n * field — behave as a CPF for individuals and a CNPJ for businesses without the\n * consumer hard-coding the mapping.\n */\n\nimport type { FieldDefinition, FormValues, InputMode } from '../types'\n\n/**\n * Looks up `field[dependsOn]`'s current value in `map` and returns the matching\n * entry, or `undefined` when there is no controller, no map, or no matching key.\n */\nfunction resolveConditional(\n field: FieldDefinition,\n map: Record<string, string> | undefined,\n values: FormValues,\n): string | undefined {\n if (field.dependsOn === undefined || map === undefined) {\n return undefined\n }\n\n const controllerValue = values[field.dependsOn] ?? ''\n // `hasOwnProperty.call` (not the `in` operator) so inherited keys like\n // `constructor` or `toString` from the object prototype never match.\n return Object.prototype.hasOwnProperty.call(map, controllerValue)\n ? map[controllerValue]\n : undefined\n}\n\n/**\n * Resolves the effective i18n label **key** for a field given the current values.\n *\n * Resolution order:\n * 1) `conditionalLabel` entry matching `values[dependsOn]`\n * 2) `field.label` fallback\n *\n * @returns The i18n key to pass to `resolveLabel`.\n */\nexport function resolveFieldLabel(field: FieldDefinition, values: FormValues): string {\n return resolveConditional(field, field.conditionalLabel, values) ?? field.label\n}\n\n/**\n * Resolves the effective i18n placeholder **key** for a field, or `undefined`\n * when the field has neither a conditional nor a static placeholder.\n *\n * Resolution order:\n * 1) `conditionalPlaceholder` entry matching `values[dependsOn]`\n * 2) `field.placeholder` fallback\n */\nexport function resolveFieldPlaceholder(\n field: FieldDefinition,\n values: FormValues,\n): string | undefined {\n return resolveConditional(field, field.conditionalPlaceholder, values) ?? field.placeholder\n}\n\n/**\n * Resolves the effective validator name for a field given the current values.\n *\n * Resolution order:\n * 1) `conditionalValidator` entry matching `values[dependsOn]`\n * 2) `field.validation.customValidator` fallback\n *\n * @returns The validator name to resolve from the rules registry, or `undefined`\n * when the field has no custom validator for the current controller value.\n */\nexport function resolveFieldValidator(\n field: FieldDefinition,\n values: FormValues,\n): string | undefined {\n return resolveConditional(field, field.conditionalValidator, values) ?? field.validation?.customValidator\n}\n\n/**\n * Resolves the effective format function name for a field given the current values.\n *\n * Resolution order:\n * 1) `conditionalFormatRef` entry matching `values[dependsOn]`\n * 2) `field.formatRef` fallback\n *\n * Pass the result to `formatValue(ref, raw)`; `undefined` yields identity.\n */\nexport function resolveFieldFormatRef(\n field: FieldDefinition,\n values: FormValues,\n): string | undefined {\n return resolveConditional(field, field.conditionalFormatRef, values) ?? field.formatRef\n}\n\n/**\n * Resolves the effective unformat function name for a field given the current values.\n *\n * Resolution order:\n * 1) `conditionalUnformatRef` entry matching `values[dependsOn]`\n * 2) `field.unformatRef` fallback\n *\n * Pass the result to `unformatValue(ref, display)`; `undefined` yields identity.\n */\nexport function resolveFieldUnformatRef(\n field: FieldDefinition,\n values: FormValues,\n): string | undefined {\n return resolveConditional(field, field.conditionalUnformatRef, values) ?? field.unformatRef\n}\n\n/**\n * Resolves the effective `inputMode` (mobile keyboard hint) for a field given\n * the current values.\n *\n * Resolution order:\n * 1) `conditionalInputMode` entry matching `values[dependsOn]`\n * 2) `field.inputMode` fallback\n *\n * Lets a single field hint a different virtual keyboard per controller value —\n * e.g. a `document` field that is numeric for an individual (CPF) and text for a\n * business (alphanumeric CNPJ).\n */\nexport function resolveFieldInputMode(\n field: FieldDefinition,\n values: FormValues,\n): InputMode | undefined {\n return (\n (resolveConditional(field, field.conditionalInputMode, values) as InputMode | undefined) ??\n field.inputMode\n )\n}\n","/**\n * @module engine/validate\n *\n * Synchronous form validation — no network calls, no async, no UI dependencies.\n *\n * ## Validation order (per field, short-circuit on first error)\n *\n * 1. **required** — field is required and value is blank (trim-aware)\n * 2. **minLength** — value is shorter than the minimum\n * 3. **maxLength** — value is longer than the maximum\n * 4. **pattern** — value does not match the regex string\n * 5. **customValidator** — named function resolved from the rules registry\n *\n * Short-circuiting: validation stops at the first failing rule for each field.\n * Only one error key is produced per field at a time.\n *\n * ## Error values\n *\n * Every error in the returned `FormErrors` map is an **i18n key** (or the string\n * returned directly by a `customValidator`). Consumers resolve it via `resolveLabel`.\n *\n * ## Conditional visibility\n *\n * Fields with `conditionalVisibility` are only validated when they are visible.\n * `validate` calls `getVisibleFields(schema, state.values)` internally — hidden\n * required fields are silently skipped and never appear in the returned error map.\n */\n\nimport type { FieldDefinition, FormSchema } from '../types'\nimport type { FormErrors, FormState, FormValues } from '../types/engine'\nimport { resolveValidator } from '../rules/validators'\nimport { getVisibleFields } from './getVisibleFields'\nimport { resolveFieldValidator } from './resolveField'\n\n/**\n * i18n key used when a required field has no value.\n * Consumers resolve this via `resolveLabel(key, bundle, overrides)`.\n */\nexport const VALIDATION_REQUIRED_KEY = 'country-forms.validation.required'\n\n/**\n * i18n key used as fallback when a `customValidator` returns `false`\n * (invalid but without a specific message).\n */\nexport const VALIDATION_INVALID_KEY = 'country-forms.validation.invalid'\n\n/**\n * Runs all synchronous validation rules in `schema` against the current `state`.\n *\n * Rules applied per field (in order, short-circuit on first error):\n * `required` → `minLength` → `maxLength` → `pattern` → `customValidator`\n *\n * @param state - Current form state (values to validate against)\n * @param schema - Schema whose validation rules are applied\n * @returns Sparse `FormErrors` map — empty object means the form is valid.\n * Only fields with errors appear as keys.\n *\n * @example\n * const errors = validate(state, schema)\n * if (Object.keys(errors).length > 0) {\n * state = { ...state, errors }\n * return\n * }\n */\nexport function validate(state: FormState, schema: FormSchema): FormErrors {\n const errors: FormErrors = {}\n\n for (const field of getVisibleFields(schema, state.values)) {\n const value = state.values[field.name] ?? ''\n const error = validateField(field, value, state.values)\n\n if (error !== null) {\n errors[field.name] = error\n }\n }\n\n return errors\n}\n\n/**\n * Validates a single field value against its definition.\n * Returns the i18n error key (or custom message) on failure, `null` on success.\n *\n * The `customValidator` is resolved via {@link resolveFieldValidator}, so a field\n * with `conditionalValidator` picks the validator matching the current controller\n * value (e.g. CPF vs CNPJ on a `document` field).\n */\nfunction validateField(field: FieldDefinition, value: string, values: FormValues): string | null {\n const trimmed = value.trim()\n\n // ── 1. required ────────────────────────────────────────────────────────────\n if (field.required && trimmed === '') {\n return VALIDATION_REQUIRED_KEY\n }\n\n // Optional field with no meaningful value — skip format rules.\n if (trimmed === '') {\n return null\n }\n\n // Static rules (minLength → maxLength → pattern) only run when the field\n // declares `validation`. Fields like `document` carry no static `validation`\n // (their rule comes from `conditionalValidator`), so this whole block is skipped\n // for them — but the customValidator below still runs.\n const rules = field.validation\n\n if (rules) {\n // ── 2. minLength ───────────────────────────────────────────────────────────\n if (rules.minLength !== undefined && value.length < rules.minLength.value) {\n return rules.minLength.message\n }\n\n // ── 3. maxLength ───────────────────────────────────────────────────────────\n if (rules.maxLength !== undefined && value.length > rules.maxLength.value) {\n return rules.maxLength.message\n }\n\n // ── 4. pattern ──────────────────────────────────────────────────────────────\n if (rules.pattern !== undefined) {\n // Compile the serializable regex string. An invalid pattern string is a\n // schema-authoring error and is allowed to throw (caught at dev time by tests).\n const regex = new RegExp(rules.pattern.value)\n\n if (!regex.test(value)) {\n return rules.pattern.message\n }\n }\n }\n\n // ── 5. customValidator ───────────────────────────────────────────────────────\n // Runs last, after the length/pattern rules (documented short-circuit order).\n // Resolved via resolveFieldValidator so `conditionalValidator` picks the right\n // function for the current controller value (e.g. CPF vs CNPJ on `document`).\n const customValidator = resolveFieldValidator(field, values)\n if (customValidator !== undefined) {\n const fn = resolveValidator(customValidator)\n const result = fn(value)\n\n if (result === true) {\n return null\n }\n\n // Validator returned a specific i18n error key — use it directly.\n if (typeof result === 'string') {\n return result\n }\n\n // Validator returned false — field is invalid but no specific message provided.\n return VALIDATION_INVALID_KEY\n }\n\n return null\n}\n","/**\n * @module engine/format\n *\n * Format and unformat helpers that apply mask functions from the rules registry\n * to a field's value, driven by the field's `formatRef` / `unformatRef`.\n *\n * ## Typical usage\n *\n * ```typescript\n * // Display: raw → formatted (e.g. \"01310100\" → \"01310-100\")\n * const displayed = formatValue(field.formatRef, rawValue)\n *\n * // Submission: formatted → raw (e.g. \"01310-100\" → \"01310100\")\n * const raw = unformatValue(field.unformatRef, displayedValue)\n * ```\n *\n * ## Identity behaviour (no mask)\n *\n * When `ref` is `undefined` (field has no mask) or the ref has not been registered,\n * the function returns the value unchanged. This makes both functions safe to call\n * unconditionally — consumers can always pass `field.formatRef` without guarding.\n */\n\nimport { resolveMask, hasMask } from '../rules/masks'\n\n/**\n * Returns the **display** representation of `value`.\n *\n * Resolves `ref` from the masks registry and applies the registered format function.\n *\n * `ref` accepts `string | undefined` so callers can forward `field.formatRef` directly\n * without guarding against fields that have no mask. This removes boilerplate at every\n * call site — the trade-off is that passing `undefined` by mistake produces no error signal,\n * returning `value` silently unchanged instead.\n *\n * @param ref - `FieldDefinition.formatRef`, e.g. `\"formatCEP\"`.\n * Pass `undefined` (or omit the guard) for fields that carry no mask.\n * @param value - Raw value to format (e.g. `\"01310100\"`).\n * @returns Formatted display string (e.g. `\"01310-100\"`) when `ref` is a registered key;\n * `value` unchanged (identity) when `ref` is `undefined` or not found in the registry.\n *\n * @example\n * formatValue(field.formatRef, '01310100') // → \"01310-100\" (mask applied)\n * formatValue(undefined, 'Av Paulista') // → \"Av Paulista\" (no ref — identity)\n * formatValue('unknownRef', '01310100') // → \"01310100\" (not registered — identity)\n */\nexport function formatValue(\n ref: string | undefined,\n value: string,\n): string {\n if (ref === undefined || !hasMask(ref)) {\n return value\n }\n\n return resolveMask(ref)(value)\n}\n\n/**\n * Returns the **raw/API** representation of `value`, stripping any display formatting.\n *\n * Resolves `ref` from the masks registry and applies the registered unformat function.\n * Symmetric to {@link formatValue} — same `string | undefined` ergonomic contract applies.\n *\n * The round-trip invariant holds when masks are correctly paired:\n * `unformatValue(field.unformatRef, formatValue(field.formatRef, raw)) === raw`\n *\n * @param ref - `FieldDefinition.unformatRef`, e.g. `\"unformatCEP\"`.\n * Pass `undefined` (or omit the guard) for fields that carry no mask.\n * @param value - Display value to strip (e.g. `\"01310-100\"`).\n * @returns Raw string suitable for API submission (e.g. `\"01310100\"`) when `ref` is a registered key;\n * `value` unchanged (identity) when `ref` is `undefined` or not found in the registry.\n *\n * @example\n * unformatValue(field.unformatRef, '01310-100') // → \"01310100\" (mask applied)\n * unformatValue(undefined, 'Av Paulista') // → \"Av Paulista\" (no ref — identity)\n * unformatValue('unknownRef', '01310-100') // → \"01310-100\" (not registered — identity)\n */\nexport function unformatValue(\n ref: string | undefined,\n value: string,\n): string {\n if (ref === undefined || !hasMask(ref)) {\n return value\n }\n\n return resolveMask(ref)(value)\n}\n","/**\n * @module engine/resolveFieldOptions\n */\n\nimport type { FieldDefinition, FormValues, SelectOption } from '../types'\nimport { hasOptions, resolveOptions } from '../rules/options'\n\ntype OptionSource = SelectOption[] | string | undefined\n\n/**\n * Resolves the effective options for a field, including dependent options.\n *\n * Resolution order:\n * 1) `conditionalOptions` entry matching `values[dependsOn]`\n * 2) `options` fallback on the field\n *\n * @param field - The field definition to resolve options for\n * @param values - Current form values (used to look up the controller field via `dependsOn`)\n * @returns `SelectOption[]` when options are available, `null` when no source is resolvable\n */\nexport function resolveFieldOptions(\n field: FieldDefinition,\n values: FormValues,\n): SelectOption[] | null {\n const source = getOptionSource(field, values)\n if (source === undefined) {\n return null\n }\n\n if (Array.isArray(source)) {\n return source\n }\n\n if (hasOptions(source)) {\n return resolveOptions(source)\n }\n\n return null\n}\n\nfunction getOptionSource(field: FieldDefinition, values: FormValues): OptionSource {\n if (field.dependsOn !== undefined && field.conditionalOptions !== undefined) {\n const controllerValue = values[field.dependsOn] ?? ''\n if (controllerValue in field.conditionalOptions) {\n return field.conditionalOptions[controllerValue]\n }\n }\n\n return field.options\n}\n","/**\n * Generic fallback schemas returned by `loadSchema` when an unsupported country\n * code is requested.\n *\n * ## Fallback contract\n *\n * - `loadSchema` never throws for an unknown country — it returns a deterministic fallback.\n * - The fallback schema carries the **requested** `iso3` code in `country`, so the\n * caller always receives a structurally valid `FormSchema`.\n * - Fallback fields are a minimal, internationally-recognizable subset.\n * - No validator/mask refs are included to avoid registry resolution errors.\n *\n * ## Design rationale\n *\n * **Address**: Many countries don't use postal codes and address structures vary\n * wildly. The fallback provides a single free-text `street` field so the user can\n * enter whatever format is conventional in their country.\n *\n * **Personal data**: Some regions prefer phone numbers over email for user\n * identification. The fallback lets the user choose between email and phone via a\n * `contactType` radio group with conditional visibility on the corresponding field.\n *\n * ## When a country becomes supported\n *\n * Add a named schema file (e.g. `src/schemas/address/FRA.ts`) and register it in\n * the corresponding loader (`src/schemas/address/loader.ts` or\n * `src/schemas/personal-data/loader.ts`). The fallback will no longer be used\n * for that country.\n */\n\nimport type { FormSchema, FormType } from '../types'\n\nconst FALLBACK_ADDRESS_FIELDS: FormSchema['fields'] = [\n {\n name: 'street',\n type: 'text',\n label: 'country-forms.address.street.label',\n placeholder: 'country-forms.address.street.placeholder',\n required: true,\n inputMode: 'text',\n },\n]\n\nconst FALLBACK_PERSONAL_DATA_FIELDS: FormSchema['fields'] = [\n {\n name: 'firstName',\n type: 'text',\n label: 'country-forms.personal-data.firstName.label',\n required: true,\n inputMode: 'text',\n },\n {\n name: 'lastName',\n type: 'text',\n label: 'country-forms.personal-data.lastName.label',\n required: true,\n inputMode: 'text',\n },\n {\n name: 'contactType',\n type: 'radio-group',\n label: 'country-forms.personal-data.contactType.label',\n required: true,\n options: [\n { value: 'email', displayValue: 'country-forms.personal-data.contactType.email' },\n { value: 'phone', displayValue: 'country-forms.personal-data.contactType.phone' },\n ],\n },\n {\n name: 'email',\n type: 'email',\n label: 'country-forms.personal-data.email.label',\n required: true,\n inputMode: 'email',\n conditionalVisibility: {\n field: 'contactType',\n operator: 'equals',\n value: 'email',\n },\n },\n {\n name: 'phone',\n type: 'text',\n label: 'country-forms.personal-data.phone.label',\n required: true,\n inputMode: 'tel',\n conditionalVisibility: {\n field: 'contactType',\n operator: 'equals',\n value: 'phone',\n },\n },\n]\n\n/**\n * Creates a minimal generic `FormSchema` for a country/formType combination that has\n * no dedicated schema registered.\n *\n * The schema is deterministic: the same inputs always produce the same output.\n * No validator or mask refs are included (to avoid registry errors for unknown countries).\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"XYZ\"`)\n * @param formType - `\"address\"` or `\"personal-data\"`\n * @returns A generic `FormSchema` with minimal internationally-recognizable fields\n */\nexport function createFallbackSchema(\n iso3: string,\n formType: FormType,\n): FormSchema {\n const fields =\n formType === 'address'\n ? FALLBACK_ADDRESS_FIELDS\n : FALLBACK_PERSONAL_DATA_FIELDS\n\n return {\n id: `${formType}-${iso3}`,\n country: iso3,\n formType,\n fields,\n }\n}\n","/**\n * Dynamic import map for address schemas.\n * Each country is loaded on demand via `import()` for code-splitting.\n *\n * When adding a new country schema:\n * 1. Add the ISO 3166-1 alpha-3 code to `SUPPORTED_ADDRESS_COUNTRIES`\n * 2. Add a `case` in `loadAddressSchema` with `import('./<CODE>')`\n * 3. Import the country's rule modules (validators, masks, options) in the case body\n */\n\nimport type { FormSchema } from '../../types'\nimport { createFallbackSchema } from '../fallback'\n\n/**\n * ISO 3166-1 alpha-3 codes for countries with a dedicated address schema.\n * Grows as country schemas are implemented.\n * Consumers can import this to build country selectors or validate input.\n *\n * @example\n * import { SUPPORTED_ADDRESS_COUNTRIES } from '@vtex/country-forms'\n * // currently supported countries: → ['BRA', 'CAN', 'MEX', 'USA']\n */\nexport const SUPPORTED_ADDRESS_COUNTRIES: readonly string[] = ['BRA', 'CAN', 'MEX', 'USA']\n\n/**\n * Loads the address schema for a given country via dynamic `import()`.\n * Falls back to a generic schema for unrecognized country codes.\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"BRA\"`, `\"USA\"`)\n * @returns The address `FormSchema` for the country, or a generic fallback schema\n */\nexport async function loadAddressSchema(iso3: string): Promise<FormSchema> {\n switch (iso3) {\n case 'BRA': {\n const [{ default: schema }] = await Promise.all([\n import('./BRA'),\n import('../../rules/validators/bra'),\n import('../../rules/masks/bra'),\n import('../../rules/options/bra-states'),\n ])\n return schema\n }\n\n case 'CAN': {\n const [{ default: schema }] = await Promise.all([\n import('./CAN'),\n import('../../rules/validators/can'),\n import('../../rules/masks/can'),\n import('../../rules/options/can-provinces'),\n ])\n return schema\n }\n\n case 'MEX': {\n const [{ default: schema }] = await Promise.all([\n import('./MEX'),\n import('../../rules/validators/mex'),\n import('../../rules/options/mex-states'),\n ])\n return schema\n }\n\n case 'USA': {\n const [{ default: schema }] = await Promise.all([\n import('./USA'),\n import('../../rules/validators/usa'),\n import('../../rules/masks/usa'),\n import('../../rules/options/usa-states'),\n ])\n return schema\n }\n\n default:\n return createFallbackSchema(iso3, 'address')\n }\n}\n","/**\n * Dynamic import map for personal-data schemas.\n * Each country is loaded on demand via `import()` for code-splitting.\n *\n * When adding a new country schema:\n * 1. Add the ISO 3166-1 alpha-3 code to `SUPPORTED_PERSONAL_DATA_COUNTRIES`\n * 2. Add a `case` in `loadPersonalDataSchema` with dynamic imports\n * 3. Import the country's rule modules (validators, masks, options) in the case body\n */\n\nimport type { FormSchema } from '../../types'\nimport { createFallbackSchema } from '../fallback'\n\n/**\n * ISO 3166-1 alpha-3 codes for countries with a dedicated personal-data schema.\n * Grows as country schemas are implemented.\n *\n * @example\n * import { SUPPORTED_PERSONAL_DATA_COUNTRIES } from '@vtex/country-forms'\n * // currently supported countries: → ['BRA', 'CAN', 'USA']\n */\nexport const SUPPORTED_PERSONAL_DATA_COUNTRIES: readonly string[] = ['BRA', 'CAN', 'MEX', 'USA']\n\n/**\n * Loads the personal-data schema for a given country via dynamic `import()`.\n * Falls back to a generic schema for unrecognized country codes.\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"BRA\"`)\n * @returns The personal-data `FormSchema` for the country, or a generic fallback schema\n */\nexport async function loadPersonalDataSchema(\n iso3: string,\n): Promise<FormSchema> {\n switch (iso3) {\n case 'BRA': {\n const [{ default: schema }] = await Promise.all([\n import('./BRA'),\n import('../../rules/validators/bra'),\n import('../../rules/masks/bra'),\n ])\n return schema\n }\n\n case 'CAN': {\n const [{ default: schema }] = await Promise.all([\n import('./CAN'),\n import('../../rules/validators/common'),\n import('../../rules/validators/can'),\n import('../../rules/masks/can'),\n ])\n return schema\n }\n\n case 'MEX': {\n const [{ default: schema }] = await Promise.all([\n import('./MEX'),\n import('../../rules/validators/common'),\n import('../../rules/validators/mex'),\n import('../../rules/masks/mex'),\n ])\n return schema\n }\n\n case 'USA': {\n const [{ default: schema }] = await Promise.all([\n import('./USA'),\n import('../../rules/validators/common'),\n import('../../rules/validators/usa'),\n import('../../rules/masks/usa'),\n ])\n return schema\n }\n\n default:\n return createFallbackSchema(iso3, 'personal-data')\n }\n}\n","/**\n * @module engine/loadSchema\n *\n * Loads a `FormSchema` for a given country code and form type on demand.\n * Each country's schema is a separate module, enabling **code-splitting**: only the\n * requested country's code enters the consumer's bundle.\n *\n * ## Fallback behaviour\n *\n * If `iso3` is not supported (or `formType` has no dedicated schemas yet),\n * `loadSchema` returns a **deterministic generic fallback schema** — it never throws\n * at runtime for an unknown country code. The fallback carries the requested `iso3`\n * in `schema.country` and provides a minimal set of generic fields.\n */\n\nimport type { FormSchema, FormType } from '../types'\nimport {\n loadAddressSchema,\n SUPPORTED_ADDRESS_COUNTRIES,\n} from '../schemas/address/loader'\nimport {\n loadPersonalDataSchema,\n SUPPORTED_PERSONAL_DATA_COUNTRIES,\n} from '../schemas/personal-data/loader'\n\nexport { SUPPORTED_ADDRESS_COUNTRIES, SUPPORTED_PERSONAL_DATA_COUNTRIES }\n\n/**\n * Loads and returns the `FormSchema` for the given country code and form type.\n *\n * - Uses dynamic `import()` internally for each country module (code-splitting).\n * - Returns a **generic fallback schema** for unsupported country codes — never throws.\n *\n * @param iso3 - ISO 3166-1 alpha-3 country code (e.g. `\"BRA\"`, `\"USA\"`)\n * @param formType - Form category: `\"address\"` or `\"personal-data\"`\n * @returns Promise resolving to the country's `FormSchema`\n *\n * @example\n * const schema = await loadSchema('BRA', 'address')\n * // → FormSchema { id: \"address-BRA\", country: \"BRA\", formType: \"address\", fields: [...] }\n *\n * const unknown = await loadSchema('XYZ', 'address')\n * // → fallback FormSchema { id: \"address-XYZ\", country: \"XYZ\", ... }\n */\nexport async function loadSchema(\n iso3: string,\n formType: FormType,\n): Promise<FormSchema> {\n switch (formType) {\n case 'address':\n return loadAddressSchema(iso3)\n case 'personal-data':\n return loadPersonalDataSchema(iso3)\n }\n}\n","/**\n * @module i18n/loader\n *\n * `loadLocale(locale)` — dynamically imports the i18n bundle for the requested\n * BCP 47 locale tag, enabling code-splitting: only the locale actually used\n * enters the consumer's bundle.\n *\n * ## Resolution order\n *\n * 1. **Exact match** on the canonical supported tag (`en-US`, `es-MX`, `fr-FR`, `pt-BR`).\n * 2. **Language-subtag fallback** — the language portion before the `-` is used\n * to match a bundle, so regional variants resolve gracefully:\n * - `en-GB`, `en-AU` → `en-US` bundle\n * - `es-419`, `es-ES` → `es-MX` bundle\n * - `fr-CA` → `fr-FR` bundle\n * - `pt-PT` → `pt-BR` bundle\n * 3. **Default fallback** — any unrecognized tag returns the `en-US` bundle.\n *\n * The function **never throws** for an unsupported locale.\n *\n * @param locale - BCP 47 locale tag (e.g. `\"pt-BR\"`, `\"en-US\"`, `\"es-419\"`)\n * @returns Resolved `I18nBundle` for the best-matching locale\n *\n * @example\n * const bundle = await loadLocale('pt-BR')\n * bundle['country-forms.address.postalCode.label'] // \"CEP\"\n *\n * @example\n * const bundle = await loadLocale('de-DE') // → en-US bundle (fallback)\n */\n\nimport type { I18nBundle } from '../types/i18n'\n\nexport async function loadLocale(locale: string): Promise<I18nBundle> {\n switch (locale) {\n case 'en-US':\n return import('./messages/en-US').then((m) => m.default)\n case 'es-MX':\n return import('./messages/es-MX').then((m) => m.default)\n case 'fr-FR':\n return import('./messages/fr-FR').then((m) => m.default)\n case 'pt-BR':\n return import('./messages/pt-BR').then((m) => m.default)\n }\n\n const lang = locale.split('-')[0]?.toLowerCase()\n\n switch (lang) {\n case 'en':\n return import('./messages/en-US').then((m) => m.default)\n case 'es':\n return import('./messages/es-MX').then((m) => m.default)\n case 'fr':\n return import('./messages/fr-FR').then((m) => m.default)\n case 'pt':\n return import('./messages/pt-BR').then((m) => m.default)\n default:\n return import('./messages/en-US').then((m) => m.default)\n }\n}\n","/**\n * @module i18n/resolveLabel\n *\n * Resolves an i18n key to its display string using a three-level cascade and,\n * optionally, interpolates `{name}` placeholders found in the resolved string.\n *\n * ## Cascade\n *\n * 1. **Consumer override** — `overrides[key]` wins if present.\n * 2. **Bundle value** — `bundle[key]` from `loadLocale()`.\n * 3. **Raw key** — the key itself is returned as a last resort, so the UI\n * never shows `undefined` or crashes.\n *\n * This design lets consumers customize individual labels without forking the\n * library or replacing the entire bundle.\n *\n * ## Interpolation\n *\n * When `params` is provided, every `{name}` placeholder in the resolved string\n * is replaced with `String(params[name])`. Replacement is **global** — the same\n * placeholder may appear more than once in a message and is replaced everywhere\n * it occurs. Placeholders without a matching `params` entry are left untouched\n * so unfulfilled substitutions remain visible to developers.\n *\n * Interpolation is applied after the cascade, so it works equally for override\n * strings, bundle strings, and the raw-key fallback.\n *\n * @param key - i18n key (e.g. `\"country-forms.address.postalCode.label\"`)\n * @param bundle - Locale bundle loaded via `loadLocale()`\n * @param overrides - Optional consumer-supplied overrides\n * @param params - Optional interpolation parameters for `{name}` placeholders\n * @returns Resolved (and optionally interpolated) display string\n *\n * @example\n * const bundle = await loadLocale('pt-BR')\n * resolveLabel('country-forms.address.postalCode.label', bundle)\n * // → \"CEP\"\n *\n * @example\n * const overrides = { 'country-forms.address.postalCode.label': 'ZIP / CEP' }\n * resolveLabel('country-forms.address.postalCode.label', bundle, overrides)\n * // → \"ZIP / CEP\" (override wins)\n *\n * @example\n * resolveLabel('country-forms.unknown.key', bundle)\n * // → \"country-forms.unknown.key\" (raw key fallback)\n *\n * @example\n * // bundle: { 'country-forms.validation.maxLength':\n * // '{fieldName} deve ter até {maxLength} caracteres' }\n * resolveLabel(\n * 'country-forms.validation.maxLength',\n * bundle,\n * undefined,\n * { fieldName: 'CEP', maxLength: 9 },\n * )\n * // → \"CEP deve ter até 9 caracteres\"\n */\n\nimport type { I18nBundle, I18nOverrides, I18nParams } from '../types/i18n'\n\nconst PLACEHOLDER_REGEX = /\\{(\\w+)\\}/g\n\nexport function resolveLabel(\n key: string,\n bundle: I18nBundle,\n overrides?: I18nOverrides,\n params?: I18nParams,\n): string {\n let resolved = key\n\n if (overrides !== undefined) {\n const override = overrides[key]\n if (override !== undefined) {\n resolved = override\n } else {\n const value = bundle[key]\n if (value !== undefined) resolved = value\n }\n } else {\n const value = bundle[key]\n if (value !== undefined) resolved = value\n }\n\n if (params === undefined) return resolved\n\n return resolved.replace(PLACEHOLDER_REGEX, (match, name: string) => {\n const replacement = params[name]\n return replacement === undefined ? match : String(replacement)\n })\n}\n","/**\n * BCP 47 locale tags supported by the library's built-in translation bundles.\n *\n * | Tag | Language |\n * |----------|---------------------------|\n * | `en-US` | English (United States) |\n * | `es-MX` | Spanish (Mexico) |\n * | `fr-FR` | French (France) |\n * | `pt-BR` | Portuguese (Brazil) |\n *\n * Any other tag passed to `loadLocale` falls back to `en-US`.\n * Regional variants (e.g. `en-GB`, `es-419`) also resolve via the language\n * subtag — see `loadLocale` for details.\n */\n/** @const BCP 47 tags with built-in bundles. See `loadLocale` for resolution. */\nexport const SUPPORTED_LOCALES = ['en-US', 'es-MX', 'fr-FR', 'pt-BR'] as const\n\n/** Union of BCP 47 tags with dedicated built-in bundles. */\nexport type SupportedLocale = (typeof SUPPORTED_LOCALES)[number]\n"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { registerValidator } from './chunk-KWESVZKV.mjs';
|
|
2
|
+
|
|
3
|
+
// src/rules/validators/mex.ts
|
|
4
|
+
var PHONE_MEX_REGEX = /^[2-9]\d{9}$/;
|
|
5
|
+
var RFC_INCONVENIENT_WORDS = /* @__PURE__ */ new Set([
|
|
6
|
+
"BUEI",
|
|
7
|
+
"BUEY",
|
|
8
|
+
"CACA",
|
|
9
|
+
"CACO",
|
|
10
|
+
"CAGA",
|
|
11
|
+
"CAGO",
|
|
12
|
+
"CAKA",
|
|
13
|
+
"CAKO",
|
|
14
|
+
"COGE",
|
|
15
|
+
"COJA",
|
|
16
|
+
"COJE",
|
|
17
|
+
"COJI",
|
|
18
|
+
"COJO",
|
|
19
|
+
"CULO",
|
|
20
|
+
"FETO",
|
|
21
|
+
"GUEY",
|
|
22
|
+
"JOTO",
|
|
23
|
+
"KACA",
|
|
24
|
+
"KACO",
|
|
25
|
+
"KAGA",
|
|
26
|
+
"KAGO",
|
|
27
|
+
"KAKA",
|
|
28
|
+
"KOGE",
|
|
29
|
+
"KOJO",
|
|
30
|
+
"KULO",
|
|
31
|
+
"MAME",
|
|
32
|
+
"MAMO",
|
|
33
|
+
"MEAR",
|
|
34
|
+
"MEAS",
|
|
35
|
+
"MEON",
|
|
36
|
+
"MION",
|
|
37
|
+
"MOCO",
|
|
38
|
+
"MULA",
|
|
39
|
+
"PEDA",
|
|
40
|
+
"PEDO",
|
|
41
|
+
"PENE",
|
|
42
|
+
"PUTA",
|
|
43
|
+
"PUTO",
|
|
44
|
+
"QULO",
|
|
45
|
+
"RATA",
|
|
46
|
+
"RUIN"
|
|
47
|
+
]);
|
|
48
|
+
function unformatPhoneMEXDigits(value) {
|
|
49
|
+
const digits = value.replace(/\D/g, "");
|
|
50
|
+
if (digits.length > 10 && digits.startsWith("52")) {
|
|
51
|
+
return digits.slice(2);
|
|
52
|
+
}
|
|
53
|
+
return digits;
|
|
54
|
+
}
|
|
55
|
+
function validatePostalCodeMEX(value) {
|
|
56
|
+
const trimmed = value.trim();
|
|
57
|
+
if (!/^\d{5}$/.test(trimmed)) {
|
|
58
|
+
return "country-forms.validation.postalCode.MEX";
|
|
59
|
+
}
|
|
60
|
+
const n = parseInt(trimmed, 10);
|
|
61
|
+
if (n < 1e3) {
|
|
62
|
+
return "country-forms.validation.postalCode.MEX";
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function validatePhoneMEX(value) {
|
|
67
|
+
const phone = unformatPhoneMEXDigits(value);
|
|
68
|
+
if (!PHONE_MEX_REGEX.test(phone)) {
|
|
69
|
+
return "country-forms.validation.invalid";
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function hasPlausibleRFCDate(yymmdd) {
|
|
74
|
+
const month = Number(yymmdd.slice(2, 4));
|
|
75
|
+
const day = Number(yymmdd.slice(4, 6));
|
|
76
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= 31;
|
|
77
|
+
}
|
|
78
|
+
function validateRFC(value) {
|
|
79
|
+
const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
80
|
+
if (!/^[A-Z]{4}\d{6}[A-Z0-9]{3}$/.test(rfc)) {
|
|
81
|
+
return "country-forms.validation.invalid";
|
|
82
|
+
}
|
|
83
|
+
if (!hasPlausibleRFCDate(rfc.slice(4, 10))) {
|
|
84
|
+
return "country-forms.validation.invalid";
|
|
85
|
+
}
|
|
86
|
+
if (RFC_INCONVENIENT_WORDS.has(rfc.slice(0, 4))) {
|
|
87
|
+
return "country-forms.validation.invalid";
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
function validateRFCCorporate(value) {
|
|
92
|
+
const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
93
|
+
if (!/^[A-Z]{3}\d{6}[A-Z0-9]{3}$/.test(rfc)) {
|
|
94
|
+
return "country-forms.validation.invalid";
|
|
95
|
+
}
|
|
96
|
+
if (!hasPlausibleRFCDate(rfc.slice(3, 9))) {
|
|
97
|
+
return "country-forms.validation.invalid";
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
registerValidator("validatePostalCodeMEX", validatePostalCodeMEX);
|
|
102
|
+
registerValidator("validatePhoneMEX", validatePhoneMEX);
|
|
103
|
+
registerValidator("validateRFC", validateRFC);
|
|
104
|
+
registerValidator("validateRFCCorporate", validateRFCCorporate);
|
|
105
|
+
|
|
106
|
+
export { unformatPhoneMEXDigits, validatePhoneMEX, validatePostalCodeMEX, validateRFC, validateRFCCorporate };
|
|
107
|
+
//# sourceMappingURL=mex-AMEX6IHY.mjs.map
|
|
108
|
+
//# sourceMappingURL=mex-AMEX6IHY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/validators/mex.ts"],"names":[],"mappings":";;;AAgCA,IAAM,eAAA,GAAkB,cAAA;AAOxB,IAAM,sBAA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,kCAAA;AAAA,EACT;AAEA,EAAA,OAAO,IAAA;AACT;AAmBO,SAAS,qBAAqB,KAAA,EAAiC;AACpE,EAAA,MAAM,MAAM,KAAA,CAAM,WAAA,EAAY,CAAE,OAAA,CAAQ,cAAc,EAAE,CAAA;AAExD,EAAA,IAAI,CAAC,4BAAA,CAA6B,IAAA,CAAK,GAAG,CAAA,EAAG;AAC3C,IAAA,OAAO,kCAAA;AAAA,EACT;AACA,EAAA,IAAI,CAAC,mBAAA,CAAoB,GAAA,CAAI,MAAM,CAAA,EAAG,CAAC,CAAC,CAAA,EAAG;AACzC,IAAA,OAAO,kCAAA;AAAA,EACT;AAEA,EAAA,OAAO,IAAA;AACT;AAEA,iBAAA,CAAkB,yBAAyB,qBAAqB,CAAA;AAChE,iBAAA,CAAkB,oBAAoB,gBAAgB,CAAA;AACtD,iBAAA,CAAkB,eAAe,WAAW,CAAA;AAC5C,iBAAA,CAAkB,wBAAwB,oBAAoB,CAAA","file":"mex-AMEX6IHY.mjs","sourcesContent":["/**\n * @module rules/validators/mex\n *\n * Synchronous validators for Mexican address and personal-data fields.\n * Importing this module registers all validators in the shared registry.\n *\n * Registered refs:\n * - `\"validatePostalCodeMEX\"` — Mexican Código Postal (CP) format validation\n * - `\"validatePhoneMEX\"` — Mexican phone number (10 digits, optional `+52`)\n * - `\"validateRFC\"` — RFC for individuals / persona física (13 chars)\n * - `\"validateRFCCorporate\"` — RFC for companies / persona moral (12 chars)\n */\n\nimport { registerValidator } from './index'\n\n/**\n * Structural Mexican phone check: 10 national digits whose first digit is 2-9\n * (Mexican geographic and mobile numbers never start with 0 or 1). Applied to\n * the digits-only string after stripping the optional `+52` country code\n * (see {@link unformatPhoneMEXDigits}).\n *\n * We validate the *structure* on purpose instead of an allowlist of IFT area\n * codes. A hardcoded allowlist (the previous ~4 KB regex) silently rejects valid\n * numbers from regions whose area codes the IFT allocated after the list was\n * written, with no actionable error and no mechanism to flag the staleness —\n * blocking legitimate submissions in production. Structural validation accepts\n * any future allocation while still rejecting the impossible leading `0`/`1`.\n *\n * The 2-digit-metro vs 3-digit-area split only affects *display* grouping and\n * lives solely in `rules/masks/mex.ts`; validation does not depend on it, so the\n * two files no longer need to share an area-code list.\n */\nconst PHONE_MEX_REGEX = /^[2-9]\\d{9}$/\n\n/**\n * RFC name prefixes (first 4 letters of a persona física RFC) that the SAT\n * replaces because they spell inappropriate words. A real RFC never starts with\n * these, so they are rejected.\n */\nconst RFC_INCONVENIENT_WORDS = new Set([\n 'BUEI', 'BUEY', 'CACA', 'CACO', 'CAGA', 'CAGO', 'CAKA', 'CAKO', 'COGE', 'COJA',\n 'COJE', 'COJI', 'COJO', 'CULO', 'FETO', 'GUEY', 'JOTO', 'KACA', 'KACO', 'KAGA',\n 'KAGO', 'KAKA', 'KOGE', 'KOJO', 'KULO', 'MAME', 'MAMO', 'MEAR', 'MEAS', 'MEON',\n 'MION', 'MOCO', 'MULA', 'PEDA', 'PEDO', 'PENE', 'PUTA', 'PUTO', 'QULO', 'RATA',\n 'RUIN',\n])\n\n/**\n * Strips non-digits and the optional leading `52` country code, returning the\n * 10-digit national number when possible.\n *\n * NOTE: this mirrors `unformatPhoneMEX` in `rules/masks/mex.ts` by design. The\n * duplication is intentional: validators and masks are independent modules that\n * load separately (a consumer can import one without the other, preserving\n * tree-shaking and module isolation). Validators must NOT import from masks, so\n * the small amount of shared logic is copied rather than shared. It is exported\n * so a cross-module test can assert that both copies stay in sync — keep both\n * implementations identical if the unformat rule changes.\n */\nexport function unformatPhoneMEXDigits(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('52')) {\n return digits.slice(2)\n }\n return digits\n}\n\n/**\n * Validates a Mexican Código Postal (CP).\n *\n * Rules:\n * - Must be exactly 5 digits (leading zeros are valid, e.g. `\"06600\"`).\n * - Numeric value must be in the range 01000–99999.\n * Codes 00001–00999 are not assigned by Correos de México.\n *\n * @param value - The postal code string to validate (digits only, no mask)\n * @returns `true` when valid, or an i18n error key string when invalid\n */\nexport function validatePostalCodeMEX(value: string): boolean | string {\n const trimmed = value.trim()\n\n if (!/^\\d{5}$/.test(trimmed)) {\n return 'country-forms.validation.postalCode.MEX'\n }\n\n const n = parseInt(trimmed, 10)\n\n if (n < 1000) {\n return 'country-forms.validation.postalCode.MEX'\n }\n\n return true\n}\n\n/**\n * Validates a Mexican phone number.\n *\n * Accepts masked (`\"(55) 1234 5678\"`) and unmasked (`\"5512345678\"`) forms, as\n * well as numbers prefixed with the country code `+52` / `52`. Non-digit\n * characters are stripped before validation.\n *\n * Rules:\n * - After stripping the optional country code, the number must be 10 digits.\n * - Structural: the first digit must be 2-9 (Mexican numbers never start with\n * 0 or 1; see {@link PHONE_MEX_REGEX} for why this replaces an allowlist).\n *\n * @param value - Phone string to validate (with or without mask or `+52` prefix)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validatePhoneMEX(value: string): boolean | string {\n const phone = unformatPhoneMEXDigits(value)\n if (!PHONE_MEX_REGEX.test(phone)) {\n return 'country-forms.validation.invalid'\n }\n return true\n}\n\n/**\n * Range-checks the 6 date digits (`YYMMDD`) embedded in an RFC: month must be\n * 01–12 and day 01–31.\n *\n * This is a **range** check, not a calendar check — it does not account for month\n * length or leap years (e.g. `\"000230\"` / Feb 30 passes). It exists to reject\n * obviously impossible dates the `\\d{6}` pattern would otherwise accept, such as\n * `000000` (month/day 00) or `001399` (month 13, day 99).\n *\n * @param yymmdd - The 6 date digits from the RFC\n * @returns `true` when the month and day fall within plausible ranges\n */\nfunction hasPlausibleRFCDate(yymmdd: string): boolean {\n const month = Number(yymmdd.slice(2, 4))\n const day = Number(yymmdd.slice(4, 6))\n return month >= 1 && month <= 12 && day >= 1 && day <= 31\n}\n\n/**\n * Validates a Mexican RFC for an individual (persona física).\n *\n * Accepts masked and unmasked forms; case-insensitive (normalized to uppercase,\n * non-alphanumeric characters stripped).\n *\n * Rules:\n * - Format: 4 letters + 6 digits (birth date) + 3 alphanumeric (homoclave) = 13 chars.\n * - The 6 date digits (`YYMMDD`) must have a plausible month (01–12) and day (01–31).\n * - The 4-letter name prefix must not be one of the SAT's inconvenient-word list.\n *\n * Limitation: the date is only **range**-checked, not calendar-validated (Feb 30\n * passes), and the homoclave check digit is **not** verified (its algorithm is\n * not public). Treat this as a format + plausible-date + blacklist check.\n *\n * @param value - RFC string to validate (with or without separators)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validateRFC(value: string): boolean | string {\n const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n\n if (!/^[A-Z]{4}\\d{6}[A-Z0-9]{3}$/.test(rfc)) {\n return 'country-forms.validation.invalid'\n }\n if (!hasPlausibleRFCDate(rfc.slice(4, 10))) {\n return 'country-forms.validation.invalid'\n }\n if (RFC_INCONVENIENT_WORDS.has(rfc.slice(0, 4))) {\n return 'country-forms.validation.invalid'\n }\n\n return true\n}\n\n/**\n * Validates a Mexican RFC for a company (persona moral).\n *\n * Accepts masked and unmasked forms; case-insensitive (normalized to uppercase,\n * non-alphanumeric characters stripped).\n *\n * Rules:\n * - Format: 3 letters + 6 digits (incorporation date) + 3 alphanumeric (homoclave) = 12 chars.\n * - The 6 date digits (`YYMMDD`) must have a plausible month (01–12) and day (01–31).\n *\n * Limitation: the date is only **range**-checked, not calendar-validated (Feb 30\n * passes), and the homoclave check digit is **not** verified, so this is a\n * format + plausible-date check only.\n *\n * @param value - RFC string to validate (with or without separators)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validateRFCCorporate(value: string): boolean | string {\n const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n\n if (!/^[A-Z]{3}\\d{6}[A-Z0-9]{3}$/.test(rfc)) {\n return 'country-forms.validation.invalid'\n }\n if (!hasPlausibleRFCDate(rfc.slice(3, 9))) {\n return 'country-forms.validation.invalid'\n }\n\n return true\n}\n\nregisterValidator('validatePostalCodeMEX', validatePostalCodeMEX)\nregisterValidator('validatePhoneMEX', validatePhoneMEX)\nregisterValidator('validateRFC', validateRFC)\nregisterValidator('validateRFCCorporate', validateRFCCorporate)\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBQPGLWMB_js = require('./chunk-BQPGLWMB.js');
|
|
4
|
+
|
|
5
|
+
// src/rules/masks/mex.ts
|
|
6
|
+
var METRO_AREA_CODES = ["33", "55", "56", "81"];
|
|
7
|
+
function formatPhoneMEX(value) {
|
|
8
|
+
const phone = unformatPhoneMEX(value);
|
|
9
|
+
if (phone.length !== 10) return phone;
|
|
10
|
+
if (METRO_AREA_CODES.includes(phone.slice(0, 2))) {
|
|
11
|
+
return `(${phone.slice(0, 2)}) ${phone.slice(2, 6)} ${phone.slice(6)}`;
|
|
12
|
+
}
|
|
13
|
+
return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`;
|
|
14
|
+
}
|
|
15
|
+
function unformatPhoneMEX(value) {
|
|
16
|
+
const digits = value.replace(/\D/g, "");
|
|
17
|
+
if (digits.length > 10 && digits.startsWith("52")) {
|
|
18
|
+
return digits.slice(2);
|
|
19
|
+
}
|
|
20
|
+
return digits;
|
|
21
|
+
}
|
|
22
|
+
function formatRFC(value) {
|
|
23
|
+
return value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
24
|
+
}
|
|
25
|
+
function unformatRFC(value) {
|
|
26
|
+
return value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
27
|
+
}
|
|
28
|
+
chunkBQPGLWMB_js.registerMask("formatPhoneMEX", formatPhoneMEX);
|
|
29
|
+
chunkBQPGLWMB_js.registerMask("unformatPhoneMEX", unformatPhoneMEX);
|
|
30
|
+
chunkBQPGLWMB_js.registerMask("formatRFC", formatRFC);
|
|
31
|
+
chunkBQPGLWMB_js.registerMask("unformatRFC", unformatRFC);
|
|
32
|
+
|
|
33
|
+
exports.formatPhoneMEX = formatPhoneMEX;
|
|
34
|
+
exports.formatRFC = formatRFC;
|
|
35
|
+
exports.unformatPhoneMEX = unformatPhoneMEX;
|
|
36
|
+
exports.unformatRFC = unformatRFC;
|
|
37
|
+
//# sourceMappingURL=mex-DYWVMWB6.js.map
|
|
38
|
+
//# sourceMappingURL=mex-DYWVMWB6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/masks/mex.ts"],"names":["registerMask"],"mappings":";;;;;AAsBA,IAAM,gBAAA,GAAmB,CAAC,IAAA,EAAM,IAAA,EAAM,MAAM,IAAI,CAAA;AAazC,SAAS,eAAe,KAAA,EAAuB;AACpD,EAAA,MAAM,KAAA,GAAQ,iBAAiB,KAAK,CAAA;AACpC,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,EAAA,EAAI,OAAO,KAAA;AAEhC,EAAA,IAAI,iBAAiB,QAAA,CAAS,KAAA,CAAM,MAAM,CAAA,EAAG,CAAC,CAAC,CAAA,EAAG;AAChD,IAAA,OAAO,IAAI,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,EAAA,EAAK,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,IAAI,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,EAAA,EAAK,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AACtE;AAWO,SAAS,iBAAiB,KAAA,EAAuB;AACtD,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACtC,EAAA,IAAI,OAAO,MAAA,GAAS,EAAA,IAAM,MAAA,CAAO,UAAA,CAAW,IAAI,CAAA,EAAG;AACjD,IAAA,OAAO,MAAA,CAAO,MAAM,CAAC,CAAA;AAAA,EACvB;AACA,EAAA,OAAO,MAAA;AACT;AAcO,SAAS,UAAU,KAAA,EAAuB;AAC/C,EAAA,OAAO,KAAA,CAAM,WAAA,EAAY,CAAE,OAAA,CAAQ,cAAc,EAAE,CAAA;AACrD;AAcO,SAAS,YAAY,KAAA,EAAuB;AACjD,EAAA,OAAO,KAAA,CAAM,WAAA,EAAY,CAAE,OAAA,CAAQ,cAAc,EAAE,CAAA;AACrD;AAEAA,6BAAA,CAAa,kBAAkB,cAAc,CAAA;AAC7CA,6BAAA,CAAa,oBAAoB,gBAAgB,CAAA;AACjDA,6BAAA,CAAa,aAAa,SAAS,CAAA;AACnCA,6BAAA,CAAa,eAAe,WAAW,CAAA","file":"mex-DYWVMWB6.js","sourcesContent":["/**\n * @module rules/masks/mex\n *\n * Format/unformat functions for Mexican personal-data fields.\n * Importing this module registers all masks in the shared registry.\n *\n * Registered refs:\n * - `\"formatPhoneMEX\"` / `\"unformatPhoneMEX\"` — Mexican phone ((99) 9999 9999 metro / (999) 999 9999)\n * - `\"formatRFC\"` / `\"unformatRFC\"` — RFC normalization (uppercase, alphanumeric only)\n */\n\nimport { registerMask } from './index'\n\n/**\n * 2-digit metro area codes that are displayed as `(99) 9999 9999` instead of the\n * 3-digit `(999) 999 9999` grouping.\n *\n * This list is a **display-only** concern: `validatePhoneMEX` validates phones\n * structurally (10 digits, first digit 2-9) and does NOT consult it, so there is\n * no cross-file allowlist to keep in sync. An out-of-date entry here only changes\n * how a number is grouped on screen, never whether it is accepted.\n */\nconst METRO_AREA_CODES = ['33', '55', '56', '81']\n\n/**\n * Formats a raw Mexican phone string for display.\n *\n * - Strips non-digits and a leading `52` country code (when more than 10 digits)\n * - 10 digits, metro area (33/55/56/81) → `\"(55) 1234 5678\"` (2-digit area)\n * - 10 digits, other area → `\"(221) 123 4567\"` (3-digit area)\n * - Otherwise returns the digits-only input unchanged (partial input while typing)\n *\n * @param value - Raw or partially formatted Mexican phone string\n * @returns Display string in `(99) 9999 9999` or `(999) 999 9999` format\n */\nexport function formatPhoneMEX(value: string): string {\n const phone = unformatPhoneMEX(value)\n if (phone.length !== 10) return phone\n\n if (METRO_AREA_CODES.includes(phone.slice(0, 2))) {\n return `(${phone.slice(0, 2)}) ${phone.slice(2, 6)} ${phone.slice(6)}`\n }\n\n return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`\n}\n\n/**\n * `\"(55) 1234 5678\"` → `\"5512345678\"`\n *\n * Strips all non-digit characters. A leading country code `\"52\"` is stripped\n * only when the remainder still has at least 10 digits.\n *\n * @param value - Display-formatted Mexican phone string\n * @returns Raw digit-only string without the country code\n */\nexport function unformatPhoneMEX(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('52')) {\n return digits.slice(2)\n }\n return digits\n}\n\n/**\n * Normalizes an RFC for display: uppercase, alphanumeric characters only.\n *\n * `\"xaxx010101000\"` → `\"XAXX010101000\"`\n *\n * The RFC has no separators, so format and unformat are equivalent — both\n * normalize the value. Used by both the persona física (13-char) and persona\n * moral (12-char) RFC fields.\n *\n * @param value - Raw or partially formatted RFC string\n * @returns Uppercased, alphanumeric-only RFC string\n */\nexport function formatRFC(value: string): string {\n return value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n}\n\n/**\n * `\"xaxx010101000\"` → `\"XAXX010101000\"`\n *\n * Currently byte-for-byte identical to {@link formatRFC} because the RFC has no\n * separators. This function must **always** return an alphanumeric-only,\n * uppercase string suitable for API submission, even if `formatRFC` later starts\n * adding display separators (e.g. `\"XAXX-010101-000\"`). Do not collapse the two:\n * `formatRFC` owns the display contract, `unformatRFC` owns the storage contract.\n *\n * @param value - Display-formatted RFC string\n * @returns Uppercased, alphanumeric-only RFC string suitable for API submission\n */\nexport function unformatRFC(value: string): string {\n return value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n}\n\nregisterMask('formatPhoneMEX', formatPhoneMEX)\nregisterMask('unformatPhoneMEX', unformatPhoneMEX)\nregisterMask('formatRFC', formatRFC)\nregisterMask('unformatRFC', unformatRFC)\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { registerMask } from './chunk-BMZHOWIP.mjs';
|
|
2
|
+
|
|
3
|
+
// src/rules/masks/mex.ts
|
|
4
|
+
var METRO_AREA_CODES = ["33", "55", "56", "81"];
|
|
5
|
+
function formatPhoneMEX(value) {
|
|
6
|
+
const phone = unformatPhoneMEX(value);
|
|
7
|
+
if (phone.length !== 10) return phone;
|
|
8
|
+
if (METRO_AREA_CODES.includes(phone.slice(0, 2))) {
|
|
9
|
+
return `(${phone.slice(0, 2)}) ${phone.slice(2, 6)} ${phone.slice(6)}`;
|
|
10
|
+
}
|
|
11
|
+
return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`;
|
|
12
|
+
}
|
|
13
|
+
function unformatPhoneMEX(value) {
|
|
14
|
+
const digits = value.replace(/\D/g, "");
|
|
15
|
+
if (digits.length > 10 && digits.startsWith("52")) {
|
|
16
|
+
return digits.slice(2);
|
|
17
|
+
}
|
|
18
|
+
return digits;
|
|
19
|
+
}
|
|
20
|
+
function formatRFC(value) {
|
|
21
|
+
return value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
22
|
+
}
|
|
23
|
+
function unformatRFC(value) {
|
|
24
|
+
return value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
25
|
+
}
|
|
26
|
+
registerMask("formatPhoneMEX", formatPhoneMEX);
|
|
27
|
+
registerMask("unformatPhoneMEX", unformatPhoneMEX);
|
|
28
|
+
registerMask("formatRFC", formatRFC);
|
|
29
|
+
registerMask("unformatRFC", unformatRFC);
|
|
30
|
+
|
|
31
|
+
export { formatPhoneMEX, formatRFC, unformatPhoneMEX, unformatRFC };
|
|
32
|
+
//# sourceMappingURL=mex-VX3Y5I6I.mjs.map
|
|
33
|
+
//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AAE,OAAA,CAAQ,cAAc,EAAE,CAAA;AACrD;AAcO,SAAS,YAAY,KAAA,EAAuB;AACjD,EAAA,OAAO,KAAA,CAAM,WAAA,EAAY,CAAE,OAAA,CAAQ,cAAc,EAAE,CAAA;AACrD;AAEA,YAAA,CAAa,kBAAkB,cAAc,CAAA;AAC7C,YAAA,CAAa,oBAAoB,gBAAgB,CAAA;AACjD,YAAA,CAAa,aAAa,SAAS,CAAA;AACnC,YAAA,CAAa,eAAe,WAAW,CAAA","file":"mex-VX3Y5I6I.mjs","sourcesContent":["/**\n * @module rules/masks/mex\n *\n * Format/unformat functions for Mexican personal-data fields.\n * Importing this module registers all masks in the shared registry.\n *\n * Registered refs:\n * - `\"formatPhoneMEX\"` / `\"unformatPhoneMEX\"` — Mexican phone ((99) 9999 9999 metro / (999) 999 9999)\n * - `\"formatRFC\"` / `\"unformatRFC\"` — RFC normalization (uppercase, alphanumeric only)\n */\n\nimport { registerMask } from './index'\n\n/**\n * 2-digit metro area codes that are displayed as `(99) 9999 9999` instead of the\n * 3-digit `(999) 999 9999` grouping.\n *\n * This list is a **display-only** concern: `validatePhoneMEX` validates phones\n * structurally (10 digits, first digit 2-9) and does NOT consult it, so there is\n * no cross-file allowlist to keep in sync. An out-of-date entry here only changes\n * how a number is grouped on screen, never whether it is accepted.\n */\nconst METRO_AREA_CODES = ['33', '55', '56', '81']\n\n/**\n * Formats a raw Mexican phone string for display.\n *\n * - Strips non-digits and a leading `52` country code (when more than 10 digits)\n * - 10 digits, metro area (33/55/56/81) → `\"(55) 1234 5678\"` (2-digit area)\n * - 10 digits, other area → `\"(221) 123 4567\"` (3-digit area)\n * - Otherwise returns the digits-only input unchanged (partial input while typing)\n *\n * @param value - Raw or partially formatted Mexican phone string\n * @returns Display string in `(99) 9999 9999` or `(999) 999 9999` format\n */\nexport function formatPhoneMEX(value: string): string {\n const phone = unformatPhoneMEX(value)\n if (phone.length !== 10) return phone\n\n if (METRO_AREA_CODES.includes(phone.slice(0, 2))) {\n return `(${phone.slice(0, 2)}) ${phone.slice(2, 6)} ${phone.slice(6)}`\n }\n\n return `(${phone.slice(0, 3)}) ${phone.slice(3, 6)} ${phone.slice(6)}`\n}\n\n/**\n * `\"(55) 1234 5678\"` → `\"5512345678\"`\n *\n * Strips all non-digit characters. A leading country code `\"52\"` is stripped\n * only when the remainder still has at least 10 digits.\n *\n * @param value - Display-formatted Mexican phone string\n * @returns Raw digit-only string without the country code\n */\nexport function unformatPhoneMEX(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('52')) {\n return digits.slice(2)\n }\n return digits\n}\n\n/**\n * Normalizes an RFC for display: uppercase, alphanumeric characters only.\n *\n * `\"xaxx010101000\"` → `\"XAXX010101000\"`\n *\n * The RFC has no separators, so format and unformat are equivalent — both\n * normalize the value. Used by both the persona física (13-char) and persona\n * moral (12-char) RFC fields.\n *\n * @param value - Raw or partially formatted RFC string\n * @returns Uppercased, alphanumeric-only RFC string\n */\nexport function formatRFC(value: string): string {\n return value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n}\n\n/**\n * `\"xaxx010101000\"` → `\"XAXX010101000\"`\n *\n * Currently byte-for-byte identical to {@link formatRFC} because the RFC has no\n * separators. This function must **always** return an alphanumeric-only,\n * uppercase string suitable for API submission, even if `formatRFC` later starts\n * adding display separators (e.g. `\"XAXX-010101-000\"`). Do not collapse the two:\n * `formatRFC` owns the display contract, `unformatRFC` owns the storage contract.\n *\n * @param value - Display-formatted RFC string\n * @returns Uppercased, alphanumeric-only RFC string suitable for API submission\n */\nexport function unformatRFC(value: string): string {\n return value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n}\n\nregisterMask('formatPhoneMEX', formatPhoneMEX)\nregisterMask('unformatPhoneMEX', unformatPhoneMEX)\nregisterMask('formatRFC', formatRFC)\nregisterMask('unformatRFC', unformatRFC)\n"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkCFX5EF4R_js = require('./chunk-CFX5EF4R.js');
|
|
4
|
+
|
|
5
|
+
// src/rules/validators/mex.ts
|
|
6
|
+
var PHONE_MEX_REGEX = /^[2-9]\d{9}$/;
|
|
7
|
+
var RFC_INCONVENIENT_WORDS = /* @__PURE__ */ new Set([
|
|
8
|
+
"BUEI",
|
|
9
|
+
"BUEY",
|
|
10
|
+
"CACA",
|
|
11
|
+
"CACO",
|
|
12
|
+
"CAGA",
|
|
13
|
+
"CAGO",
|
|
14
|
+
"CAKA",
|
|
15
|
+
"CAKO",
|
|
16
|
+
"COGE",
|
|
17
|
+
"COJA",
|
|
18
|
+
"COJE",
|
|
19
|
+
"COJI",
|
|
20
|
+
"COJO",
|
|
21
|
+
"CULO",
|
|
22
|
+
"FETO",
|
|
23
|
+
"GUEY",
|
|
24
|
+
"JOTO",
|
|
25
|
+
"KACA",
|
|
26
|
+
"KACO",
|
|
27
|
+
"KAGA",
|
|
28
|
+
"KAGO",
|
|
29
|
+
"KAKA",
|
|
30
|
+
"KOGE",
|
|
31
|
+
"KOJO",
|
|
32
|
+
"KULO",
|
|
33
|
+
"MAME",
|
|
34
|
+
"MAMO",
|
|
35
|
+
"MEAR",
|
|
36
|
+
"MEAS",
|
|
37
|
+
"MEON",
|
|
38
|
+
"MION",
|
|
39
|
+
"MOCO",
|
|
40
|
+
"MULA",
|
|
41
|
+
"PEDA",
|
|
42
|
+
"PEDO",
|
|
43
|
+
"PENE",
|
|
44
|
+
"PUTA",
|
|
45
|
+
"PUTO",
|
|
46
|
+
"QULO",
|
|
47
|
+
"RATA",
|
|
48
|
+
"RUIN"
|
|
49
|
+
]);
|
|
50
|
+
function unformatPhoneMEXDigits(value) {
|
|
51
|
+
const digits = value.replace(/\D/g, "");
|
|
52
|
+
if (digits.length > 10 && digits.startsWith("52")) {
|
|
53
|
+
return digits.slice(2);
|
|
54
|
+
}
|
|
55
|
+
return digits;
|
|
56
|
+
}
|
|
57
|
+
function validatePostalCodeMEX(value) {
|
|
58
|
+
const trimmed = value.trim();
|
|
59
|
+
if (!/^\d{5}$/.test(trimmed)) {
|
|
60
|
+
return "country-forms.validation.postalCode.MEX";
|
|
61
|
+
}
|
|
62
|
+
const n = parseInt(trimmed, 10);
|
|
63
|
+
if (n < 1e3) {
|
|
64
|
+
return "country-forms.validation.postalCode.MEX";
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
function validatePhoneMEX(value) {
|
|
69
|
+
const phone = unformatPhoneMEXDigits(value);
|
|
70
|
+
if (!PHONE_MEX_REGEX.test(phone)) {
|
|
71
|
+
return "country-forms.validation.invalid";
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
function hasPlausibleRFCDate(yymmdd) {
|
|
76
|
+
const month = Number(yymmdd.slice(2, 4));
|
|
77
|
+
const day = Number(yymmdd.slice(4, 6));
|
|
78
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= 31;
|
|
79
|
+
}
|
|
80
|
+
function validateRFC(value) {
|
|
81
|
+
const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
82
|
+
if (!/^[A-Z]{4}\d{6}[A-Z0-9]{3}$/.test(rfc)) {
|
|
83
|
+
return "country-forms.validation.invalid";
|
|
84
|
+
}
|
|
85
|
+
if (!hasPlausibleRFCDate(rfc.slice(4, 10))) {
|
|
86
|
+
return "country-forms.validation.invalid";
|
|
87
|
+
}
|
|
88
|
+
if (RFC_INCONVENIENT_WORDS.has(rfc.slice(0, 4))) {
|
|
89
|
+
return "country-forms.validation.invalid";
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
function validateRFCCorporate(value) {
|
|
94
|
+
const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, "");
|
|
95
|
+
if (!/^[A-Z]{3}\d{6}[A-Z0-9]{3}$/.test(rfc)) {
|
|
96
|
+
return "country-forms.validation.invalid";
|
|
97
|
+
}
|
|
98
|
+
if (!hasPlausibleRFCDate(rfc.slice(3, 9))) {
|
|
99
|
+
return "country-forms.validation.invalid";
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
chunkCFX5EF4R_js.registerValidator("validatePostalCodeMEX", validatePostalCodeMEX);
|
|
104
|
+
chunkCFX5EF4R_js.registerValidator("validatePhoneMEX", validatePhoneMEX);
|
|
105
|
+
chunkCFX5EF4R_js.registerValidator("validateRFC", validateRFC);
|
|
106
|
+
chunkCFX5EF4R_js.registerValidator("validateRFCCorporate", validateRFCCorporate);
|
|
107
|
+
|
|
108
|
+
exports.unformatPhoneMEXDigits = unformatPhoneMEXDigits;
|
|
109
|
+
exports.validatePhoneMEX = validatePhoneMEX;
|
|
110
|
+
exports.validatePostalCodeMEX = validatePostalCodeMEX;
|
|
111
|
+
exports.validateRFC = validateRFC;
|
|
112
|
+
exports.validateRFCCorporate = validateRFCCorporate;
|
|
113
|
+
//# sourceMappingURL=mex-Y56WV2L7.js.map
|
|
114
|
+
//# sourceMappingURL=mex-Y56WV2L7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/validators/mex.ts"],"names":["registerValidator"],"mappings":";;;;;AAgCA,IAAM,eAAA,GAAkB,cAAA;AAOxB,IAAM,sBAAA,uBAA6B,GAAA,CAAI;AAAA,EACrC,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EACxE,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EAAQ,MAAA;AAAA,EACxE,MAAA;AAA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ACT;AAEAA,kCAAA,CAAkB,yBAAyB,qBAAqB,CAAA;AAChEA,kCAAA,CAAkB,oBAAoB,gBAAgB,CAAA;AACtDA,kCAAA,CAAkB,eAAe,WAAW,CAAA;AAC5CA,kCAAA,CAAkB,wBAAwB,oBAAoB,CAAA","file":"mex-Y56WV2L7.js","sourcesContent":["/**\n * @module rules/validators/mex\n *\n * Synchronous validators for Mexican address and personal-data fields.\n * Importing this module registers all validators in the shared registry.\n *\n * Registered refs:\n * - `\"validatePostalCodeMEX\"` — Mexican Código Postal (CP) format validation\n * - `\"validatePhoneMEX\"` — Mexican phone number (10 digits, optional `+52`)\n * - `\"validateRFC\"` — RFC for individuals / persona física (13 chars)\n * - `\"validateRFCCorporate\"` — RFC for companies / persona moral (12 chars)\n */\n\nimport { registerValidator } from './index'\n\n/**\n * Structural Mexican phone check: 10 national digits whose first digit is 2-9\n * (Mexican geographic and mobile numbers never start with 0 or 1). Applied to\n * the digits-only string after stripping the optional `+52` country code\n * (see {@link unformatPhoneMEXDigits}).\n *\n * We validate the *structure* on purpose instead of an allowlist of IFT area\n * codes. A hardcoded allowlist (the previous ~4 KB regex) silently rejects valid\n * numbers from regions whose area codes the IFT allocated after the list was\n * written, with no actionable error and no mechanism to flag the staleness —\n * blocking legitimate submissions in production. Structural validation accepts\n * any future allocation while still rejecting the impossible leading `0`/`1`.\n *\n * The 2-digit-metro vs 3-digit-area split only affects *display* grouping and\n * lives solely in `rules/masks/mex.ts`; validation does not depend on it, so the\n * two files no longer need to share an area-code list.\n */\nconst PHONE_MEX_REGEX = /^[2-9]\\d{9}$/\n\n/**\n * RFC name prefixes (first 4 letters of a persona física RFC) that the SAT\n * replaces because they spell inappropriate words. A real RFC never starts with\n * these, so they are rejected.\n */\nconst RFC_INCONVENIENT_WORDS = new Set([\n 'BUEI', 'BUEY', 'CACA', 'CACO', 'CAGA', 'CAGO', 'CAKA', 'CAKO', 'COGE', 'COJA',\n 'COJE', 'COJI', 'COJO', 'CULO', 'FETO', 'GUEY', 'JOTO', 'KACA', 'KACO', 'KAGA',\n 'KAGO', 'KAKA', 'KOGE', 'KOJO', 'KULO', 'MAME', 'MAMO', 'MEAR', 'MEAS', 'MEON',\n 'MION', 'MOCO', 'MULA', 'PEDA', 'PEDO', 'PENE', 'PUTA', 'PUTO', 'QULO', 'RATA',\n 'RUIN',\n])\n\n/**\n * Strips non-digits and the optional leading `52` country code, returning the\n * 10-digit national number when possible.\n *\n * NOTE: this mirrors `unformatPhoneMEX` in `rules/masks/mex.ts` by design. The\n * duplication is intentional: validators and masks are independent modules that\n * load separately (a consumer can import one without the other, preserving\n * tree-shaking and module isolation). Validators must NOT import from masks, so\n * the small amount of shared logic is copied rather than shared. It is exported\n * so a cross-module test can assert that both copies stay in sync — keep both\n * implementations identical if the unformat rule changes.\n */\nexport function unformatPhoneMEXDigits(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('52')) {\n return digits.slice(2)\n }\n return digits\n}\n\n/**\n * Validates a Mexican Código Postal (CP).\n *\n * Rules:\n * - Must be exactly 5 digits (leading zeros are valid, e.g. `\"06600\"`).\n * - Numeric value must be in the range 01000–99999.\n * Codes 00001–00999 are not assigned by Correos de México.\n *\n * @param value - The postal code string to validate (digits only, no mask)\n * @returns `true` when valid, or an i18n error key string when invalid\n */\nexport function validatePostalCodeMEX(value: string): boolean | string {\n const trimmed = value.trim()\n\n if (!/^\\d{5}$/.test(trimmed)) {\n return 'country-forms.validation.postalCode.MEX'\n }\n\n const n = parseInt(trimmed, 10)\n\n if (n < 1000) {\n return 'country-forms.validation.postalCode.MEX'\n }\n\n return true\n}\n\n/**\n * Validates a Mexican phone number.\n *\n * Accepts masked (`\"(55) 1234 5678\"`) and unmasked (`\"5512345678\"`) forms, as\n * well as numbers prefixed with the country code `+52` / `52`. Non-digit\n * characters are stripped before validation.\n *\n * Rules:\n * - After stripping the optional country code, the number must be 10 digits.\n * - Structural: the first digit must be 2-9 (Mexican numbers never start with\n * 0 or 1; see {@link PHONE_MEX_REGEX} for why this replaces an allowlist).\n *\n * @param value - Phone string to validate (with or without mask or `+52` prefix)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validatePhoneMEX(value: string): boolean | string {\n const phone = unformatPhoneMEXDigits(value)\n if (!PHONE_MEX_REGEX.test(phone)) {\n return 'country-forms.validation.invalid'\n }\n return true\n}\n\n/**\n * Range-checks the 6 date digits (`YYMMDD`) embedded in an RFC: month must be\n * 01–12 and day 01–31.\n *\n * This is a **range** check, not a calendar check — it does not account for month\n * length or leap years (e.g. `\"000230\"` / Feb 30 passes). It exists to reject\n * obviously impossible dates the `\\d{6}` pattern would otherwise accept, such as\n * `000000` (month/day 00) or `001399` (month 13, day 99).\n *\n * @param yymmdd - The 6 date digits from the RFC\n * @returns `true` when the month and day fall within plausible ranges\n */\nfunction hasPlausibleRFCDate(yymmdd: string): boolean {\n const month = Number(yymmdd.slice(2, 4))\n const day = Number(yymmdd.slice(4, 6))\n return month >= 1 && month <= 12 && day >= 1 && day <= 31\n}\n\n/**\n * Validates a Mexican RFC for an individual (persona física).\n *\n * Accepts masked and unmasked forms; case-insensitive (normalized to uppercase,\n * non-alphanumeric characters stripped).\n *\n * Rules:\n * - Format: 4 letters + 6 digits (birth date) + 3 alphanumeric (homoclave) = 13 chars.\n * - The 6 date digits (`YYMMDD`) must have a plausible month (01–12) and day (01–31).\n * - The 4-letter name prefix must not be one of the SAT's inconvenient-word list.\n *\n * Limitation: the date is only **range**-checked, not calendar-validated (Feb 30\n * passes), and the homoclave check digit is **not** verified (its algorithm is\n * not public). Treat this as a format + plausible-date + blacklist check.\n *\n * @param value - RFC string to validate (with or without separators)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validateRFC(value: string): boolean | string {\n const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n\n if (!/^[A-Z]{4}\\d{6}[A-Z0-9]{3}$/.test(rfc)) {\n return 'country-forms.validation.invalid'\n }\n if (!hasPlausibleRFCDate(rfc.slice(4, 10))) {\n return 'country-forms.validation.invalid'\n }\n if (RFC_INCONVENIENT_WORDS.has(rfc.slice(0, 4))) {\n return 'country-forms.validation.invalid'\n }\n\n return true\n}\n\n/**\n * Validates a Mexican RFC for a company (persona moral).\n *\n * Accepts masked and unmasked forms; case-insensitive (normalized to uppercase,\n * non-alphanumeric characters stripped).\n *\n * Rules:\n * - Format: 3 letters + 6 digits (incorporation date) + 3 alphanumeric (homoclave) = 12 chars.\n * - The 6 date digits (`YYMMDD`) must have a plausible month (01–12) and day (01–31).\n *\n * Limitation: the date is only **range**-checked, not calendar-validated (Feb 30\n * passes), and the homoclave check digit is **not** verified, so this is a\n * format + plausible-date check only.\n *\n * @param value - RFC string to validate (with or without separators)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validateRFCCorporate(value: string): boolean | string {\n const rfc = value.toUpperCase().replace(/[^A-Z0-9]/g, '')\n\n if (!/^[A-Z]{3}\\d{6}[A-Z0-9]{3}$/.test(rfc)) {\n return 'country-forms.validation.invalid'\n }\n if (!hasPlausibleRFCDate(rfc.slice(3, 9))) {\n return 'country-forms.validation.invalid'\n }\n\n return true\n}\n\nregisterValidator('validatePostalCodeMEX', validatePostalCodeMEX)\nregisterValidator('validatePhoneMEX', validatePhoneMEX)\nregisterValidator('validateRFC', validateRFC)\nregisterValidator('validateRFCCorporate', validateRFCCorporate)\n"]}
|