@bolttech/form-engine-core 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/credit-card.d.ts +743 -0
  3. package/credit-card.esm.js +1 -0
  4. package/currency.d.ts +131 -0
  5. package/currency.esm.js +1 -0
  6. package/date.d.ts +582 -0
  7. package/date.esm.js +1 -0
  8. package/document.d.ts +527 -0
  9. package/document.esm.js +1 -0
  10. package/index.d.ts +52 -5
  11. package/index.esm.js +1 -4570
  12. package/lite.d.ts +2393 -0
  13. package/lite.esm.js +1 -0
  14. package/package.json +34 -2
  15. package/src/constants/constants.d.ts +11 -0
  16. package/src/formatters/creditCard.d.ts +23 -0
  17. package/src/formatters/custom.d.ts +29 -0
  18. package/src/formatters/handler.d.ts +2 -0
  19. package/src/formatters/regex.d.ts +47 -0
  20. package/src/formatters/splitter.d.ts +17 -0
  21. package/src/formatters/string.d.ts +88 -0
  22. package/src/helpers/SafeSubject.d.ts +21 -0
  23. package/src/helpers/creditCard.d.ts +95 -0
  24. package/src/helpers/helpers.d.ts +66 -0
  25. package/src/helpers/lodash-replacements.d.ts +41 -0
  26. package/src/helpers/validation.d.ts +28 -0
  27. package/src/index.d.ts +15 -0
  28. package/src/interfaces/schema.d.ts +161 -0
  29. package/src/interfaces/state.d.ts +22 -0
  30. package/src/lite.d.ts +30 -0
  31. package/src/managers/field.d.ts +339 -0
  32. package/src/managers/form.d.ts +357 -0
  33. package/src/managers/formGroup.d.ts +110 -0
  34. package/src/managers/index.d.ts +3 -0
  35. package/src/masks/creditCard.d.ts +60 -0
  36. package/src/masks/currency.d.ts +29 -0
  37. package/src/masks/generic.d.ts +39 -0
  38. package/src/masks/handler.d.ts +2 -0
  39. package/src/masks/string.d.ts +37 -0
  40. package/src/plugins/credit-card.d.ts +4 -0
  41. package/src/plugins/currency.d.ts +2 -0
  42. package/src/plugins/date.d.ts +2 -0
  43. package/src/plugins/document.d.ts +2 -0
  44. package/src/registry.d.ts +20 -0
  45. package/src/types/event.d.ts +175 -0
  46. package/src/types/form.d.ts +55 -0
  47. package/src/types/mapper.d.ts +87 -0
  48. package/src/types/schema.d.ts +1001 -0
  49. package/src/types/template.d.ts +65 -0
  50. package/src/types/utility.d.ts +12 -0
  51. package/src/validations/creditCard.d.ts +52 -0
  52. package/src/validations/custom.d.ts +27 -0
  53. package/src/validations/date.d.ts +79 -0
  54. package/src/validations/document.d.ts +25 -0
  55. package/src/validations/handler.d.ts +2 -0
  56. package/src/validations/length.d.ts +39 -0
  57. package/src/validations/list.d.ts +32 -0
  58. package/src/validations/logical.d.ts +75 -0
  59. package/src/validations/multiple.d.ts +31 -0
  60. package/src/validations/namedRule.d.ts +22 -0
  61. package/src/validations/number.d.ts +145 -0
  62. package/src/validations/object.d.ts +44 -0
  63. package/src/validations/regex.d.ts +217 -0
  64. package/src/validations/string.d.ts +53 -0
package/document.d.ts ADDED
@@ -0,0 +1,527 @@
1
+ import { TCurrencyLocalCode } from '@gaignoux/currency';
2
+
3
+ /**
4
+ * @type TFormValues<T>
5
+ * Represents the values and state of a form. It has a generic type that allows the importer to determine which type values key will return.
6
+ *
7
+ * @property {Generic Type} values - The current values of the form fields.
8
+ * @property {string[]} erroredFields - A list of field names that have errors.
9
+ * @property {boolean} isValid - Indicates whether the form is valid.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const formValues: TFormValues = {
14
+ * values: { name: 'John', age: 30 },
15
+ * erroredFields: ['email'],
16
+ * isValid: false
17
+ * };
18
+ * ```
19
+ */
20
+ type TFormValues<T> = {
21
+ values: T;
22
+ metadata: unknown;
23
+ erroredFields: string[];
24
+ isValid: boolean;
25
+ };
26
+
27
+ /** @virtual */
28
+
29
+ /**
30
+ * @type TLengthValidation
31
+ * Represents the validation rules based on the length of the input.
32
+ *
33
+ * @property {'equal' | 'notEqual' | 'less' | 'lessOrEqual' | 'greater' | 'greaterOrEqual'} rule - The rule to apply.
34
+ * @property {number} target - The target value to compare against.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const lengthValidation: TLengthValidation = { rule: 'greaterOrEqual', target: 8 };
39
+ * ```
40
+ */
41
+ type TLengthValidation = {
42
+ rule: 'equal' | 'notEqual' | 'less' | 'lessOrEqual' | 'greater' | 'greaterOrEqual';
43
+ target: number;
44
+ };
45
+ /**
46
+ * @type TCallbackValidation
47
+ * A custom validation function.
48
+ *
49
+ * @param {unknown} value - The value to validate.
50
+ * @returns {boolean} - The result of the validation.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const callbackValidation: TCallbackValidation = (value) => typeof value === 'string';
55
+ * ```
56
+ */
57
+ type TCallbackValidation = (value: unknown, formValues: Pick<TFormValues<unknown>, 'values' | 'metadata'>) => boolean;
58
+ /**
59
+ * @type TBetweenValidation
60
+ * Represents validation rules that check if a value is between a range.
61
+ *
62
+ * @property {number} start - The start of the range.
63
+ * @property {number} end - The end of the range.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const betweenValidation: TBetweenValidation = { start: 1, end: 10 };
68
+ * ```
69
+ */
70
+ type TBetweenValidation = {
71
+ start: number;
72
+ end: number;
73
+ };
74
+ /**
75
+ * @type TCreditCardMatch
76
+ * Represents the options for credit card matching.
77
+ *
78
+ * @property {string} numberCard - The credit card number.
79
+ * @property {string[]} availableOptions - The available options for matching.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const creditCardMatch: TCreditCardMatch = { numberCard: '1234', availableOptions: ['Visa', 'MasterCard'] };
84
+ * ```
85
+ */
86
+ type TCreditCardMatch = {
87
+ numberCard: string;
88
+ availableOptions: string[];
89
+ };
90
+ /**
91
+ * @type TDocumentValidation
92
+ * Represents validation for specific document types.
93
+ *
94
+ * @property {'NIF' | 'NIE' | 'CIF' | 'IBAN'} type - The type of document.
95
+ * @property {TCurrencyLocalCode} [locale] - The locale code for validation.
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * const documentValidation: TDocumentValidation = { type: 'NIF', locale: 'ES' };
100
+ * ```
101
+ */
102
+ type TDocumentValidation = {
103
+ type: 'NIF' | 'NIE' | 'CIF' | 'IBAN';
104
+ locale?: TCurrencyLocalCode;
105
+ };
106
+ /**
107
+ * @type TDateOperatorsValidation
108
+ * Represents the operators used for date validation conditions.
109
+ *
110
+ * @property {'<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin'}
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const operator: TDateOperatorsValidation = '<';
115
+ * ```
116
+ */
117
+ type TDateOperatorsValidation = '<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin';
118
+ /**
119
+ * @type TConditionsValidationSet
120
+ * Represents a single validation condition set.
121
+ *
122
+ * @property {boolean} [forceDefinedOrigin] - Flag to force the origin value to be defined.
123
+ * @property {boolean} [forceDefinedTarget] - Flag to force the target value to be defined.
124
+ * @property {string | number | boolean} [origin] - The origin value for the condition.
125
+ * @property {TDateOperatorsValidation} condition - The validation condition operator.
126
+ * @property {string | number | boolean} [target] - The target value for the condition.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const conditionSet: TConditionsValidationSet = {
131
+ * forceDefinedOrigin: true,
132
+ * forceDefinedTarget: true,
133
+ * origin: '2023-01-01',
134
+ * condition: '>',
135
+ * target: '2022-01-01'
136
+ * };
137
+ * ```
138
+ */
139
+ type TConditionsValidationSet = {
140
+ forceDefinedOrigin?: boolean;
141
+ forceDefinedTarget?: boolean;
142
+ origin?: string | number | boolean | null;
143
+ condition: TDateOperatorsValidation;
144
+ target?: string | number | boolean;
145
+ };
146
+ /**
147
+ * @type TConditionsValidation
148
+ * Represents a set of validation conditions.
149
+ *
150
+ * @property {'and' | 'or'} rule - The logical rule to combine the conditions (AND/OR).
151
+ * @property {TConditionsValidationSet[]} set - The array of validation condition sets.
152
+ * @property {TConditionsValidation} [conditions] - Nested conditions for more complex validation logic.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const conditionsValidation: TConditionsValidation = {
157
+ * rule: 'and',
158
+ * set: [
159
+ * {
160
+ * forceDefinedOrigin: true,
161
+ * forceDefinedTarget: true,
162
+ * origin: '2023-01-01',
163
+ * condition: '>',
164
+ * target: '2022-01-01'
165
+ * }
166
+ * ],
167
+ * conditions: {
168
+ * rule: 'or',
169
+ * set: [
170
+ * {
171
+ * origin: true,
172
+ * condition: '!!origin',
173
+ * target: false
174
+ * }
175
+ * ]
176
+ * }
177
+ * };
178
+ * ```
179
+ */
180
+ type TConditionsValidation = {
181
+ rule: 'and' | 'or';
182
+ set: TConditionsValidationSet[];
183
+ conditions?: TConditionsValidation;
184
+ };
185
+ type TAvailableValidations = Omit<TValidationMethods, 'multipleValidations'> | TGenericValidationRule;
186
+ /**
187
+ * @type TMultipleValidation
188
+ * Represents a set of multiple validation methods combined with a logical rule.
189
+ *
190
+ * @property {'AND' | 'OR' | 'NOT'} rule - The logical rule to combine the validation methods (AND, OR, NOT).
191
+ * @property {TAvailableValidations} validations - The validation methods to be combined.
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const multipleValidation: TMultipleValidation = {
196
+ * rule: 'AND',
197
+ * validations: {
198
+ * required: true,
199
+ * min: 5,
200
+ * max: 10
201
+ * }
202
+ * };
203
+ * ```
204
+ */
205
+ type TMultipleValidation = {
206
+ rule: 'AND' | 'OR' | 'NOT';
207
+ validations: TAvailableValidations;
208
+ };
209
+ /**
210
+ * @type TBetweenDatesValidation
211
+ * Represents a validation method to check if a value falls between specified dates.
212
+ *
213
+ * @property {TDateValidation[]} [TBetweenDatesValidation] - An array of date validation methods.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * const betweenDatesValidation: TBetweenDatesValidation = [
218
+ * {
219
+ * onlyValidDate: true,
220
+ * operator: '>=',
221
+ * origin: {
222
+ * format: 'MMDDYYYY',
223
+ * intervals: {
224
+ * years: 1
225
+ * }
226
+ * },
227
+ * target: {
228
+ * value: Date.now(),
229
+ * format: 'timestamp',
230
+ * value: '01/01/2023',
231
+ * }
232
+ * },
233
+ * {
234
+ * onlyValidDate: true,
235
+ * operator: '<=',
236
+ * origin: {
237
+ * format: 'MMDDYYYY',
238
+ * intervals: {
239
+ * years: 1
240
+ * }
241
+ * },
242
+ * target: {
243
+ * format: 'timestamp',
244
+ * value: '31/12/2023',
245
+ * }
246
+ * }
247
+ * ];
248
+ * ```
249
+ */
250
+ type TBetweenDatesValidation = TDateValidation[];
251
+ /**
252
+ * @type TDateFormatsValidation
253
+ * Represents the supported date formats for validation.
254
+ *
255
+ * @type {'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp'}
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const dateFormat: TDateFormatsValidation = 'MMDDYYYY';
260
+ * ```
261
+ */
262
+ type TDateFormatsValidation = 'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp';
263
+ type TDateInterval = {
264
+ years?: number;
265
+ months?: number;
266
+ days?: number;
267
+ };
268
+ /**
269
+ * @type TDateValidation
270
+ * Represents a validation method for date values.
271
+ *
272
+ * @property {boolean} [onlyValidDate] - Flag to validate only if the date is valid.
273
+ * @property {TDateOperatorsValidation} operator - The validation operator to be used.
274
+ * @property {Object} origin - The origin date configuration.
275
+ * @property {string | number} [origin.value] - The origin date value.
276
+ * @property {TDateFormatsValidation} origin.format - The format of the origin date.
277
+ * @property {Object} [origin.intervals] - The intervals to add to the origin date for comparison.
278
+ * @property {number} [origin.intervals.years] - The number of years to add.
279
+ * @property {number} [origin.intervals.months] - The number of months to add.
280
+ * @property {number} [origin.intervals.days] - The number of days to add.
281
+ * @property {Object} [target] - The target date configuration.
282
+ * @property {string | number} target.value - The target date value.
283
+ * @property {TDateFormatsValidation} target.format - The format of the target date.
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * const dateValidation: TDateValidation = {
288
+ * onlyValidDate: true,
289
+ * operator: '===',
290
+ * origin: {
291
+ * value: '10/10/2022',
292
+ * format: 'MMDDYYYY',
293
+ * intervals: {
294
+ * years: 1
295
+ * }
296
+ * },
297
+ * target: {
298
+ * value: Date.now(),
299
+ * format: 'timestamp'
300
+ * }
301
+ * };
302
+ * ```
303
+ */
304
+ type TDateValidation = {
305
+ onlyValidDate?: boolean;
306
+ operator: TDateOperatorsValidation;
307
+ origin: {
308
+ value?: string | number;
309
+ format: TDateFormatsValidation;
310
+ /**
311
+ * Intervals to compare with the original date.
312
+ *
313
+ * It will use today's date for comparison.
314
+ *
315
+ * @example
316
+ * ```typescript
317
+ * origin date = 10/10/2022
318
+ * interval.year = 1
319
+ * operator = '==='
320
+ * ```
321
+ *
322
+ * It will compare (10/10/2022 + 1) with the current date and check if they are the same
323
+ */
324
+ intervals?: TDateInterval;
325
+ };
326
+ target?: {
327
+ value: string | number;
328
+ format: TDateFormatsValidation;
329
+ };
330
+ };
331
+ /**
332
+ * @type TValidationMethods
333
+ * Represents the various validation methods that can be applied to form fields.
334
+ *
335
+ * @property {number} [max] - Maximum value or length.
336
+ * @property {number} [min] - Minimum value or length.
337
+ * @property {number} [lessThan] - Minimum value or length.
338
+ * @property {number} [greaterThan] - Minimum value or length.
339
+ * @property {TLengthValidation} [length] - Length validation rule.
340
+ * @property {boolean} [required] - Indicates if the field is required.
341
+ * @property {unknown} [value] - Specific value to match.
342
+ * @property {string} [regex] - Regular expression for validation.
343
+ * @property {boolean} [email] - Indicates if the value should be a valid email.
344
+ * @property {boolean} [url] - Indicates if the value should be a valid URL.
345
+ * @property {boolean} [onlyLetters] - Indicates if the value should contain only letters.
346
+ * @property {boolean} [notAllowSpaces] - Indicates if spaces are not allowed.
347
+ * @property {TCallbackValidation} [callback] - Custom validation callback function.
348
+ * @property {boolean} [isNumber] - Indicates if the value should be a number.
349
+ * @property {boolean} [bool] - Indicates if the value should be a boolean or a string that can be converted to a boolean.
350
+ * @property {boolean | string} [exists] - Indicates if the value should exist or match a specific existence condition.
351
+ * @property {boolean} [hasNoExtraSpaces] - Indicates if there should be no extra spaces.
352
+ * @property {boolean} [notEmpty] - Indicates if the field should not be empty.
353
+ * @property {TBetweenValidation} [between] - Validation rule for range between two values.
354
+ * @property {boolean} [sequential] - Indicates if the value should be sequential.
355
+ * @property {boolean} [repeated] - Indicates if the value should not be repeated.
356
+ * @property {string[] | number[]} [includes] - Array of values that should be included.
357
+ * @property {string[]} [isCreditCard] - Array of valid credit card numbers.
358
+ * @property {TCreditCardMatch} [isCreditCodeMatch] - Validation rule for credit card matching.
359
+ * @property {string[]} [isCreditCardAndLength] - Array of valid credit card numbers with length check.
360
+ * @property {TDocumentValidation} [document] - Document validation rule.
361
+ * @property {TConditionsValidation} [conditions] - Conditional validation rules.
362
+ * @property {TMultipleValidation} [multipleValidations] - Multiple validation rules combined with a logical rule.
363
+ * @property {TBetweenDatesValidation} [betweenDates] - Validation rule for checking if a date falls between two dates.
364
+ * @property {TDateValidation} [date] - Validation rule for date values.
365
+ * @property {TDateFormatsValidation} [validDate] - Validation rule for valid date formats.
366
+ *
367
+ * @example
368
+ * ```typescript
369
+ * const validationMethods: TValidationMethods = {
370
+ * max: 100,
371
+ * min: 1,
372
+ * lessThan: 1995,
373
+ * greaterThan: 82000,
374
+ * length: { rule: 'greaterOrEqual', target: 8 },
375
+ * required: true,
376
+ * regex: '^[a-zA-Z0-9]+$',
377
+ * email: true,
378
+ * conditions: {
379
+ * rule: 'and',
380
+ * set: [
381
+ * {
382
+ * forceDefinedOrigin: true,
383
+ * forceDefinedTarget: true,
384
+ * origin: '2023-01-01',
385
+ * condition: '>',
386
+ * target: '2022-01-01'
387
+ * }
388
+ * ]
389
+ * },
390
+ * multipleValidations: {
391
+ * rule: 'AND',
392
+ * validations: {
393
+ * required: true,
394
+ * min: 5,
395
+ * max: 10
396
+ * }
397
+ * },
398
+ * betweenDates: {
399
+ * start: Date.parse('2023-01-01'),
400
+ * end: Date.parse('2023-12-31'),
401
+ * isIncludedBoundaries: true
402
+ * },
403
+ * date: {
404
+ * operator: '===',
405
+ * origin: {
406
+ * value: '10/10/2022',
407
+ * format: 'MMDDYYYY',
408
+ * intervals: {
409
+ * years: 1
410
+ * }
411
+ * },
412
+ * target: {
413
+ * value: Date.now(),
414
+ * format: 'timestamp'
415
+ * }
416
+ * },
417
+ * validDate: 'MMDDYYYY'
418
+ * };
419
+ * ```
420
+ */
421
+ type TValidationMethods = {
422
+ /** Maximum value or length. */
423
+ max?: number;
424
+ /** Minimum value or length. */
425
+ min?: number;
426
+ /** Minimum value or length. */
427
+ lessThan?: number;
428
+ /** Minimum value or length. */
429
+ greaterThan?: number;
430
+ /** Length validation rule. */
431
+ length?: TLengthValidation;
432
+ /** Indicates if the field is required. */
433
+ required?: boolean;
434
+ /** Specific value to match. */
435
+ value?: unknown;
436
+ /** Regular expression for validation. */
437
+ regex?: string;
438
+ /** Indicates if the value should be a valid email. */
439
+ email?: boolean;
440
+ /** Indicates if the value should be a valid URL. */
441
+ url?: boolean;
442
+ /** Indicates if the value should contain only letters. */
443
+ onlyLetters?: boolean;
444
+ /** Indicates if spaces are not allowed. */
445
+ notAllowSpaces?: boolean;
446
+ /** Custom validation callback function. */
447
+ callback?: TCallbackValidation;
448
+ /** Indicates if the value should be a number. */
449
+ isNumber?: boolean;
450
+ /** Indicates if the value should be a boolean or a string that can be converted to a boolean. */
451
+ bool?: boolean | string;
452
+ /** Indicates if the value should exist or match a specific existence condition. */
453
+ exists?: boolean | string;
454
+ /** Indicates if there should be no extra spaces. */
455
+ hasNoExtraSpaces?: boolean;
456
+ /** Indicates if the field should not be empty. */
457
+ notEmpty?: boolean;
458
+ /** Validation rule for range between two values. */
459
+ between?: TBetweenValidation;
460
+ /** Indicates if the value should be sequential. */
461
+ sequential?: boolean;
462
+ /** Indicates if the value should not be repeated. */
463
+ repeated?: boolean;
464
+ /** Array of values that should be included. */
465
+ includes?: (string | number)[];
466
+ /** Array of valid credit card numbers. */
467
+ isCreditCard?: string[];
468
+ /** Validation rule for credit card matching. */
469
+ isCreditCodeMatch?: TCreditCardMatch;
470
+ /** Array of valid credit card numbers with length check. */
471
+ isCreditCardAndLength?: string[];
472
+ /** Document validation rule. */
473
+ document?: TDocumentValidation;
474
+ /** Conditional validation rules. */
475
+ conditions?: TConditionsValidation;
476
+ /** Multiple validation rules combined with a logical rule. */
477
+ multipleValidations?: TMultipleValidation;
478
+ /** Validation rule for checking if a date falls between two dates. */
479
+ betweenDates?: TBetweenDatesValidation;
480
+ /** Validation rule for date values. */
481
+ date?: TDateValidation;
482
+ /** Validation rule for valid date formats. */
483
+ validDate?: TDateFormatsValidation;
484
+ };
485
+ /**
486
+ * @type {Object.<string, TValidationMethods>} TGenericValidationRule
487
+ * Represents a generic validation rule where each key is associated with a set of validation methods.
488
+ *
489
+ * @example
490
+ * const genericValidationRule = {
491
+ * email: {
492
+ * required: true,
493
+ * email: true,
494
+ * },
495
+ * password: {
496
+ * required: true,
497
+ * minLength: 8,
498
+ * },
499
+ * };
500
+ */
501
+ type TGenericValidationRule = Record<string, TValidationMethods>;
502
+
503
+ /**
504
+ * General validation function for various document types based on the provided validation methods.
505
+ *
506
+ * @param value - The document value to validate.
507
+ * @param validations - An object containing validation methods.
508
+ * @returns `true` if the document is valid, otherwise `false`.
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * import validateDocument from './path/to/validationFunctions';
513
+ *
514
+ * const validations = {
515
+ * document: {
516
+ * type: 'NIF',
517
+ * locale: 'pt-PT'
518
+ * }
519
+ * };
520
+ *
521
+ * const isValid = validateDocument('123456789', validations);
522
+ * console.log(isValid); // Output: true or false based on validation
523
+ * ```
524
+ */
525
+ declare const _default: (value: string, validations: TValidationMethods) => boolean;
526
+
527
+ export { _default as document };
@@ -0,0 +1 @@
1
+ const t=t=>{if(9!==t.length)return!0;if(!/^\d{8}$/.test(t.slice(0,8)))return!0;const e="TRWAGMYFPDXBNJZSQVHLCKE"[parseInt(t.slice(0,8),10)%23];return!(t[8].toUpperCase()===e)};var e=(e,r)=>{if(!e||!r.document)return!0;const s={NIF:(e,r)=>((e,r)=>{switch(r){case"pt-PT":return(t=>{if(!/^\d{9}$/.test(t))return!1;const e=parseInt(t[8],10),r=11-Array.from(t.substring(0,8)).reduce((t,e,r)=>t+parseInt(e,10)*(9-r),0)%11;return 10===r||11===r?0===e:r===e})(e);case"es-ES":return t(e);case"it-IT":return/^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/.test(e);case"de-DE":return(t=>/^\d{11}$/.test(t))(e);case"fr-FR":return(t=>/^\d{2} \d{3} \d{3} \d{3} \d{3}$/.test(t))(e);case"en-GB":return/^GB\d{9}|\d{12}|\d{3}[A-Z]{5}$/.test(e);case"nl-BE":case"fr-BE":return(t=>!!/^\d{11}$/.test(t)&&97-parseInt(t.substring(0,9),10)%97===parseInt(t.substring(9),10))(e);case"nl-NL":return(t=>!!/^\d{9}$/.test(t)&&t.split("").map((t,e)=>parseInt(t,10)*(9-e)).reduce((t,e)=>t+e,0)%11==0)(e);case"sv-SE":return(t=>!!/^\d{10,12}$/.test(t)&&(12===t.length?t.substring(2):t).split("").map((t,e)=>{let r=parseInt(t,10)*(e%2==0?2:1);return r>9&&(r-=9),r}).reduce((t,e)=>t+e,0)%10==0)(e);default:throw new Error(`NIF validation not supported for locale: ${r}`)}})(e,r),NIE:e=>(e=>{if(9!==e.length)return!0;if(!/^[XYZ]\d{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(e))return!0;let r=e.toUpperCase().padStart(9,"0");return r=r[0].replace(/[XYZ]/g,t=>({X:"0",Y:"1",Z:"2"}[t]||t))+r.slice(1),t(r)})(e),CIF:t=>(t=>!/^[A-Z][0-9]{7}[A-J0-9]$/.test(t))(t),IBAN:t=>(t=>{const e=t.replace(/\s/g,"");return 24!==e.length||!/^(ES)[0-9]{22}$/.test(e)||1!==(t=>{for(;t.length>2;){const e=t.slice(0,6),r=parseInt(e,10);if(isNaN(r))return NaN;t=r%97+t.slice(e.length)}return parseInt(t,10)%97})(e.substring(4)+1428+e.substring(2,4))})(t)};return s[r.document.type](e,r.document.locale)};Object.assign({},{document:e});export{e as document};
package/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as rxjs from 'rxjs';
2
2
  import { Subject, BehaviorSubject, Subscription } from 'rxjs';
3
3
  import { TCurrencyLocalCode, TCurrencyCode } from '@gaignoux/currency';
4
- import { OutgoingHttpHeaders } from 'http2';
5
4
 
6
5
  type AllowOnly<T, K extends keyof T> = Pick<T, K> & {
7
6
  [P in keyof Omit<T, K>]?: never;
@@ -229,6 +228,33 @@ interface IFormSchema {
229
228
  iVars?: Record<string, unknown>;
230
229
  components?: IComponentSchema[];
231
230
  stopEventsOnSubmit?: boolean;
231
+ /** Pre-fetched API response data for SSR. Keys are field names, values contain the API responses to hydrate. */
232
+ prefetchedData?: Record<string, TPrefetchedFieldData>;
233
+ }
234
+ /**
235
+ * Represents pre-fetched API data for a single field.
236
+ * Used to hydrate API response caches during SSR so templates referencing API data resolve correctly.
237
+ *
238
+ * @property {unknown} [defaultResponse] - The pre-fetched response for the field's default API config.
239
+ * @property {Record<string, unknown>} [namedResponses] - Pre-fetched responses for named API configs.
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const prefetchedData = {
244
+ * countryField: {
245
+ * defaultResponse: [{ id: 'BR', label: 'Brazil' }, { id: 'US', label: 'United States' }],
246
+ * },
247
+ * stateField: {
248
+ * namedResponses: { statesByCountry: [{ id: 'SP', label: 'São Paulo' }] },
249
+ * },
250
+ * };
251
+ * ```
252
+ */
253
+ interface TPrefetchedFieldData {
254
+ /** The pre-fetched response for the field's default API config. */
255
+ defaultResponse?: unknown;
256
+ /** Pre-fetched responses keyed by named API config name. */
257
+ namedResponses?: Record<string, unknown>;
232
258
  }
233
259
 
234
260
  /**
@@ -1055,7 +1081,7 @@ type TResetPathMethods = {
1055
1081
  *
1056
1082
  * @property {'GET' | 'POST'} method - The HTTP method for the request.
1057
1083
  * @property {string} url - The URL for the request.
1058
- * @property {OutgoingHttpHeaders} [headers] - The headers for the request.
1084
+ * @property {Record<string, string>} [headers] - The headers for the request.
1059
1085
  * @property {Record<string, string>} queryParams - query parameters for request.
1060
1086
  * @property {string} [resultPath] - The path to extract the result from the response.
1061
1087
  * @property {unknown} [fallbackValue] - The fallback value if the request fails.
@@ -1085,7 +1111,7 @@ type TApiConfig = {
1085
1111
  /** The body payload for the request. */
1086
1112
  body?: Record<string, unknown>;
1087
1113
  /** The headers for the request. */
1088
- headers?: OutgoingHttpHeaders;
1114
+ headers?: Record<string, string>;
1089
1115
  /** Query parameters for the request. */
1090
1116
  queryParams?: Record<string, string>;
1091
1117
  /** The path to extract the result from the response. */
@@ -1756,6 +1782,7 @@ declare class FormCore {
1756
1782
  value: unknown;
1757
1783
  }>;
1758
1784
  queuedInitialValues: Map<string, unknown>;
1785
+ prefetchedData?: Record<string, TPrefetchedFieldData>;
1759
1786
  _valid: boolean;
1760
1787
  stopEventsOnSubmit: boolean;
1761
1788
  submitted: boolean;
@@ -2342,5 +2369,25 @@ type TFormGroupOnValidEventPayload = {
2342
2369
  */
2343
2370
  type TFormGroupOnSubmitEventPayload<T> = Record<string, TFormValues<T> | undefined>;
2344
2371
 
2345
- export { FormCore, FormField, FormGroup, TMutationEnum };
2346
- export type { AllowOnly, IComponentSchema, IComponentSchemaAsFormField, IFormField, IFormSchema, IState, OneOf, TAllowedResetPropsMutationsEnum, TApiConfig, TApiEvent, TApiResponse, TApiResponsePayload, TAvailableValidations, TBetweenDatesValidation, TBetweenValidation, TCallbackValidation, TComponentPropsMapping, TConditionsValidation, TConditionsValidationSet, TCreditCardMatch, TCurrencyMask, TDateFormatsValidation, TDateInterval, TDateOperatorsValidation, TDateValidation, TDocumentValidation, TErrorMessages, TEvent, TEventDataProps, TEventDataPropsEnum, TEventEnum, TEventMessages, TEventMessagesValidationMethods, TEventProps, TEventPropsEnum, TEvents, TFieldEvent, TFieldValidationPayload, TFormCore, TFormDataPayload, TFormDataValues, TFormEntry, TFormGroup, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload, TFormSubmitPayload, TFormValidationPayload, TFormValues, TFormatters, TGenericValidationRule, TLengthValidation, TMapper, TMaskGeneric, TMasks, TMultipleValidation, TMutationEvents, TProps, TResetPathMethods, TResetValueMethods, TSchemaFormConfig, TSchemaValidation, TSplitterFormatterValue, TSubscribedTemplates, TTemplateAvaliableScopes, TTemplateAvaliableScopesEnum, TTemplateEvent, TValidationHandler, TValidationMethods, TValidationPayload, TValidations, TValueChangeEvent, TVisibility };
2372
+ /**
2373
+ * Global mutable registries for validations, formatters, and masks.
2374
+ * Plugins (sub-path exports) can extend these at import time.
2375
+ */
2376
+ declare const validationRegistry: TValidationHandler;
2377
+ declare const formatterRegistry: Record<string, (value: unknown, formatters?: any) => unknown>;
2378
+ declare const maskRegistry: Record<string, (value: unknown, masks?: any) => unknown>;
2379
+ /**
2380
+ * Registers additional validation methods into the global registry.
2381
+ */
2382
+ declare function registerValidations(methods: TValidationHandler): void;
2383
+ /**
2384
+ * Registers additional formatter methods into the global registry.
2385
+ */
2386
+ declare function registerFormatters(methods: Record<string, (value: unknown, formatters?: any) => unknown>): void;
2387
+ /**
2388
+ * Registers additional mask methods into the global registry.
2389
+ */
2390
+ declare function registerMasks(methods: Record<string, (value: unknown, masks?: any) => unknown>): void;
2391
+
2392
+ export { FormCore, FormField, FormGroup, TMutationEnum, formatterRegistry, maskRegistry, registerFormatters, registerMasks, registerValidations, validationRegistry };
2393
+ export type { AllowOnly, IComponentSchema, IComponentSchemaAsFormField, IFormField, IFormSchema, IState, OneOf, TAllowedResetPropsMutationsEnum, TApiConfig, TApiEvent, TApiResponse, TApiResponsePayload, TAvailableValidations, TBetweenDatesValidation, TBetweenValidation, TCallbackValidation, TComponentPropsMapping, TConditionsValidation, TConditionsValidationSet, TCreditCardMatch, TCurrencyMask, TDateFormatsValidation, TDateInterval, TDateOperatorsValidation, TDateValidation, TDocumentValidation, TErrorMessages, TEvent, TEventDataProps, TEventDataPropsEnum, TEventEnum, TEventMessages, TEventMessagesValidationMethods, TEventProps, TEventPropsEnum, TEvents, TFieldEvent, TFieldValidationPayload, TFormCore, TFormDataPayload, TFormDataValues, TFormEntry, TFormGroup, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload, TFormSubmitPayload, TFormValidationPayload, TFormValues, TFormatters, TGenericValidationRule, TLengthValidation, TMapper, TMaskGeneric, TMasks, TMultipleValidation, TMutationEvents, TPrefetchedFieldData, TProps, TResetPathMethods, TResetValueMethods, TSchemaFormConfig, TSchemaValidation, TSplitterFormatterValue, TSubscribedTemplates, TTemplateAvaliableScopes, TTemplateAvaliableScopesEnum, TTemplateEvent, TValidationHandler, TValidationMethods, TValidationPayload, TValidations, TValueChangeEvent, TVisibility };