@streamline-pulse/formkrafter-core 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +215 -3
- package/dist/index.js.map +9 -7
- package/dist/utils/registries.d.ts +21 -0
- package/dist/utils/units.d.ts +32 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export { RecapItem, collectRecapItems } from "./utils/recap.js";
|
|
|
10
10
|
export { FieldDescriptor, CollectFieldsOptions, collectFields } from "./utils/fields.js";
|
|
11
11
|
export { IdentityFormat, IDENTITY_FORMATS, checkIdentity, checkFrNir, checkBjNpi, checkDigits, checkLuhn, checkFrSiren, checkFrSiret, checkBjIfu, checkIban, formatIban } from "./utils/identity.js";
|
|
12
12
|
export { MrzResult, parseMrz, mrzLines, mrzCheckDigit } from "./utils/mrz.js";
|
|
13
|
+
export { MeasureFamily, MeasureUnit, MeasureValue, MEASURE_FAMILIES, measureFamilyOf, measureUnits, unitOf, convertMeasure, measureValue, formatMeasure } from "./utils/units.js";
|
|
14
|
+
export { PLATE_FORMATS, REGISTRY_FORMATS, checkPlate, formatPlate, compactPlate, checkCompanyRegistry, formatCompanyRegistry } from "./utils/registries.js";
|
|
13
15
|
export { Slot, SlotRules, generateSlots, readSlots, groupSlotsByDay, slotDate } from "./utils/slots.js";
|
|
14
16
|
export { DocumentField, parseDocumentFields, parseDocumentFills, documentFillPatch } from "./utils/documents.js";
|
|
15
17
|
export { FieldAnnotation, FieldAnnotations, flaggedKeys } from "./review.js";
|
package/dist/index.js
CHANGED
|
@@ -6924,7 +6924,9 @@ var DEFAULT_MESSAGES = {
|
|
|
6924
6924
|
identity: "Invalid identifier for this format",
|
|
6925
6925
|
iban: "Invalid IBAN",
|
|
6926
6926
|
dateRange: "The end before the start is not allowed",
|
|
6927
|
-
mrz: "Machine-readable zone unreadable or inconsistent"
|
|
6927
|
+
mrz: "Machine-readable zone unreadable or inconsistent",
|
|
6928
|
+
plate: "Invalid registration plate for this format",
|
|
6929
|
+
registry: "Invalid registration number for this format"
|
|
6928
6930
|
},
|
|
6929
6931
|
fr: {
|
|
6930
6932
|
required: "Ce champ est obligatoire",
|
|
@@ -6942,7 +6944,9 @@ var DEFAULT_MESSAGES = {
|
|
|
6942
6944
|
identity: "Identifiant invalide pour ce format",
|
|
6943
6945
|
iban: "IBAN invalide",
|
|
6944
6946
|
dateRange: "La fin ne peut pas précéder le début",
|
|
6945
|
-
mrz: "Zone de lecture illisible ou incohérente"
|
|
6947
|
+
mrz: "Zone de lecture illisible ou incohérente",
|
|
6948
|
+
plate: "Immatriculation invalide pour ce format",
|
|
6949
|
+
registry: "Numéro d’immatriculation invalide pour ce format"
|
|
6946
6950
|
}
|
|
6947
6951
|
};
|
|
6948
6952
|
function registerValidationMessages(locale, messages) {
|
|
@@ -7051,6 +7055,16 @@ function buildValidationSchema(brickSpecs, locale) {
|
|
|
7051
7055
|
property.dateRange = true;
|
|
7052
7056
|
messages.dateRange = defaultValidationMessage("dateRange", locale);
|
|
7053
7057
|
}
|
|
7058
|
+
if (brick.id === "vehicle-plate") {
|
|
7059
|
+
const format = typeof brick.configs?.plateFormat === "string" && brick.configs.plateFormat ? brick.configs.plateFormat : "generic";
|
|
7060
|
+
property.format = `plate-${format}`;
|
|
7061
|
+
messages.format = defaultValidationMessage("plate", locale);
|
|
7062
|
+
}
|
|
7063
|
+
if (brick.id === "company-registry") {
|
|
7064
|
+
const format = typeof brick.configs?.registryFormat === "string" && brick.configs.registryFormat ? brick.configs.registryFormat : "generic";
|
|
7065
|
+
property.format = `registry-${format}`;
|
|
7066
|
+
messages.format = defaultValidationMessage("registry", locale);
|
|
7067
|
+
}
|
|
7054
7068
|
if (brick.id === "mrz") {
|
|
7055
7069
|
property.mrzValid = true;
|
|
7056
7070
|
messages.mrzValid = defaultValidationMessage("mrz", locale);
|
|
@@ -7329,6 +7343,24 @@ var en = {
|
|
|
7329
7343
|
"panel.documentLanguage": "Document language (fr, en…)",
|
|
7330
7344
|
"panel.cfg.capture": "Offer the camera on mobile",
|
|
7331
7345
|
"panel.cfg.keepFile": "Keep the file in the answer",
|
|
7346
|
+
"brick.key-value.name": "Key / value",
|
|
7347
|
+
"keyValue.key": "Key",
|
|
7348
|
+
"keyValue.value": "Value",
|
|
7349
|
+
"keyValue.add": "+ Add a row",
|
|
7350
|
+
"keyValue.remove": "Remove row",
|
|
7351
|
+
"keyValue.empty": "No value",
|
|
7352
|
+
"category.Measures": "Measures",
|
|
7353
|
+
"category.Registries": "Vehicles & companies",
|
|
7354
|
+
"brick.measure.name": "Measure",
|
|
7355
|
+
"brick.vehicle-plate.name": "Vehicle plate",
|
|
7356
|
+
"brick.company-registry.name": "Company registration",
|
|
7357
|
+
"measure.value": "Value",
|
|
7358
|
+
"measure.unit": "Unit",
|
|
7359
|
+
"panel.family": "Measure family (length, area, mass, volume, duration)",
|
|
7360
|
+
"panel.units": "Units offered (ids, comma-separated; empty = all)",
|
|
7361
|
+
"panel.unit": "Default unit",
|
|
7362
|
+
"panel.plateFormat": "Plate format (fr, bj, ci, sn, generic)",
|
|
7363
|
+
"panel.registryFormat": "Registration format (ohada-rccm, fr-rcs, generic)",
|
|
7332
7364
|
"panel.slotsUrl": "Slots URL (empty = opening rules)",
|
|
7333
7365
|
"panel.slotDays": "Open days (1 = Monday … 7 = Sunday)",
|
|
7334
7366
|
"panel.slotFrom": "Opens at",
|
|
@@ -7554,6 +7586,24 @@ var frFkTranslations = {
|
|
|
7554
7586
|
"panel.documentLanguage": "Langue du document (fr, en…)",
|
|
7555
7587
|
"panel.cfg.capture": "Proposer l’appareil photo sur mobile",
|
|
7556
7588
|
"panel.cfg.keepFile": "Conserver le fichier dans la réponse",
|
|
7589
|
+
"brick.key-value.name": "Clé / valeur",
|
|
7590
|
+
"keyValue.key": "Clé",
|
|
7591
|
+
"keyValue.value": "Valeur",
|
|
7592
|
+
"keyValue.add": "+ Ajouter une ligne",
|
|
7593
|
+
"keyValue.remove": "Retirer la ligne",
|
|
7594
|
+
"keyValue.empty": "Aucune valeur",
|
|
7595
|
+
"category.Measures": "Mesures",
|
|
7596
|
+
"category.Registries": "Véhicules & entreprises",
|
|
7597
|
+
"brick.measure.name": "Mesure",
|
|
7598
|
+
"brick.vehicle-plate.name": "Immatriculation",
|
|
7599
|
+
"brick.company-registry.name": "Registre d’entreprise",
|
|
7600
|
+
"measure.value": "Valeur",
|
|
7601
|
+
"measure.unit": "Unité",
|
|
7602
|
+
"panel.family": "Famille de mesure (length, area, mass, volume, duration)",
|
|
7603
|
+
"panel.units": "Unités proposées (identifiants séparés par des virgules ; vide = toutes)",
|
|
7604
|
+
"panel.unit": "Unité par défaut",
|
|
7605
|
+
"panel.plateFormat": "Format d’immatriculation (fr, bj, ci, sn, generic)",
|
|
7606
|
+
"panel.registryFormat": "Format du registre (ohada-rccm, fr-rcs, generic)",
|
|
7557
7607
|
"panel.slotsUrl": "URL des créneaux (vide = règles d’ouverture)",
|
|
7558
7608
|
"panel.slotDays": "Jours ouverts (1 = lundi … 7 = dimanche)",
|
|
7559
7609
|
"panel.slotFrom": "Ouverture",
|
|
@@ -8624,6 +8674,150 @@ function parseTd1(l1, l2, l3, raw) {
|
|
|
8624
8674
|
errors
|
|
8625
8675
|
};
|
|
8626
8676
|
}
|
|
8677
|
+
// lib/utils/units.ts
|
|
8678
|
+
var MEASURE_FAMILIES = {
|
|
8679
|
+
length: {
|
|
8680
|
+
base: "m",
|
|
8681
|
+
units: [
|
|
8682
|
+
{ id: "mm", symbol: "mm", factor: 0.001 },
|
|
8683
|
+
{ id: "cm", symbol: "cm", factor: 0.01 },
|
|
8684
|
+
{ id: "m", symbol: "m", factor: 1 },
|
|
8685
|
+
{ id: "km", symbol: "km", factor: 1000 }
|
|
8686
|
+
]
|
|
8687
|
+
},
|
|
8688
|
+
area: {
|
|
8689
|
+
base: "m2",
|
|
8690
|
+
units: [
|
|
8691
|
+
{ id: "m2", symbol: "m²", factor: 1 },
|
|
8692
|
+
{ id: "a", symbol: "a", factor: 100 },
|
|
8693
|
+
{ id: "ha", symbol: "ha", factor: 1e4 },
|
|
8694
|
+
{ id: "km2", symbol: "km²", factor: 1e6 }
|
|
8695
|
+
]
|
|
8696
|
+
},
|
|
8697
|
+
mass: {
|
|
8698
|
+
base: "kg",
|
|
8699
|
+
units: [
|
|
8700
|
+
{ id: "g", symbol: "g", factor: 0.001 },
|
|
8701
|
+
{ id: "kg", symbol: "kg", factor: 1 },
|
|
8702
|
+
{ id: "t", symbol: "t", factor: 1000 }
|
|
8703
|
+
]
|
|
8704
|
+
},
|
|
8705
|
+
volume: {
|
|
8706
|
+
base: "l",
|
|
8707
|
+
units: [
|
|
8708
|
+
{ id: "ml", symbol: "ml", factor: 0.001 },
|
|
8709
|
+
{ id: "l", symbol: "l", factor: 1 },
|
|
8710
|
+
{ id: "m3", symbol: "m³", factor: 1000 }
|
|
8711
|
+
]
|
|
8712
|
+
},
|
|
8713
|
+
duration: {
|
|
8714
|
+
base: "h",
|
|
8715
|
+
units: [
|
|
8716
|
+
{ id: "min", symbol: "min", factor: 1 / 60 },
|
|
8717
|
+
{ id: "h", symbol: "h", factor: 1 },
|
|
8718
|
+
{ id: "d", symbol: "j", factor: 24 }
|
|
8719
|
+
]
|
|
8720
|
+
}
|
|
8721
|
+
};
|
|
8722
|
+
var measureFamilyOf = (value) => typeof value === "string" && (value in MEASURE_FAMILIES) ? value : "length";
|
|
8723
|
+
function measureUnits(family, allowed) {
|
|
8724
|
+
const all = MEASURE_FAMILIES[family].units;
|
|
8725
|
+
if (typeof allowed !== "string" || !allowed.trim())
|
|
8726
|
+
return all;
|
|
8727
|
+
const wanted = allowed.split(",").map((id) => id.trim().toLowerCase()).filter(Boolean);
|
|
8728
|
+
const picked = all.filter((unit) => wanted.includes(unit.id));
|
|
8729
|
+
return picked.length ? picked : all;
|
|
8730
|
+
}
|
|
8731
|
+
function unitOf(family, id) {
|
|
8732
|
+
return MEASURE_FAMILIES[family].units.find((unit) => unit.id === id);
|
|
8733
|
+
}
|
|
8734
|
+
var round = (n) => Math.round(n * 1e9) / 1e9;
|
|
8735
|
+
function convertMeasure(family, value, from, to) {
|
|
8736
|
+
const source = unitOf(family, from);
|
|
8737
|
+
const target = unitOf(family, to);
|
|
8738
|
+
if (!source || !target)
|
|
8739
|
+
return;
|
|
8740
|
+
return round(value * source.factor / target.factor);
|
|
8741
|
+
}
|
|
8742
|
+
function measureValue(family, value, unit) {
|
|
8743
|
+
const source = unitOf(family, unit);
|
|
8744
|
+
if (!source || !Number.isFinite(value))
|
|
8745
|
+
return;
|
|
8746
|
+
return { value, unit, base: round(value * source.factor) };
|
|
8747
|
+
}
|
|
8748
|
+
function formatMeasure(family, value, locale) {
|
|
8749
|
+
if (!value)
|
|
8750
|
+
return "";
|
|
8751
|
+
const unit = unitOf(family, value.unit);
|
|
8752
|
+
const number = new Intl.NumberFormat(locale, { maximumFractionDigits: 3 }).format(value.value);
|
|
8753
|
+
return `${number} ${unit?.symbol ?? value.unit}`;
|
|
8754
|
+
}
|
|
8755
|
+
// lib/utils/registries.ts
|
|
8756
|
+
var compact2 = (value) => value.replace(/[\s.-]/g, "").toUpperCase();
|
|
8757
|
+
var group = (value, pattern, template) => value.replace(pattern, template);
|
|
8758
|
+
var PLATE_FORMATS = [
|
|
8759
|
+
{
|
|
8760
|
+
id: "fr",
|
|
8761
|
+
label: "France · AA-123-AA",
|
|
8762
|
+
test: (v) => /^[A-HJ-NP-Z]{2}\d{3}[A-HJ-NP-Z]{2}$/.test(v),
|
|
8763
|
+
format: (v) => group(v, /^([A-Z]{2})(\d{3})([A-Z]{2})$/, "$1-$2-$3")
|
|
8764
|
+
},
|
|
8765
|
+
{
|
|
8766
|
+
id: "bj",
|
|
8767
|
+
label: "Bénin · AB 1234 RB",
|
|
8768
|
+
test: (v) => /^[A-Z]{1,2}\d{4}[A-Z]{2}$/.test(v),
|
|
8769
|
+
format: (v) => group(v, /^([A-Z]{1,2})(\d{4})([A-Z]{2})$/, "$1 $2 $3")
|
|
8770
|
+
},
|
|
8771
|
+
{
|
|
8772
|
+
id: "ci",
|
|
8773
|
+
label: "Côte d’Ivoire · 1234 AB 01",
|
|
8774
|
+
test: (v) => /^\d{4}[A-Z]{2}\d{2}$/.test(v),
|
|
8775
|
+
format: (v) => group(v, /^(\d{4})([A-Z]{2})(\d{2})$/, "$1 $2 $3")
|
|
8776
|
+
},
|
|
8777
|
+
{
|
|
8778
|
+
id: "sn",
|
|
8779
|
+
label: "Sénégal · AA 123 AA",
|
|
8780
|
+
test: (v) => /^[A-Z]{2}\d{3,4}[A-Z]{1,2}$/.test(v),
|
|
8781
|
+
format: (v) => group(v, /^([A-Z]{2})(\d{3,4})([A-Z]{1,2})$/, "$1 $2 $3")
|
|
8782
|
+
},
|
|
8783
|
+
{ id: "generic", label: "Libre (4 à 10 lettres ou chiffres)", test: (v) => /^[A-Z0-9]{4,10}$/.test(v) }
|
|
8784
|
+
];
|
|
8785
|
+
var REGISTRY_FORMATS = [
|
|
8786
|
+
{
|
|
8787
|
+
id: "ohada-rccm",
|
|
8788
|
+
label: "OHADA · RCCM (RB/COT/01 B 1234)",
|
|
8789
|
+
test: (v) => /^[A-Z]{2}\/[A-Z]{2,4}\/\d{2,4}[A-Z]\d{3,7}$/.test(v.replace(/[\s]/g, "")),
|
|
8790
|
+
format: (v) => v.replace(/^([A-Z]{2}\/[A-Z]{2,4}\/\d{2,4})([A-Z])(\d{3,7})$/, "$1 $2 $3")
|
|
8791
|
+
},
|
|
8792
|
+
{
|
|
8793
|
+
id: "fr-rcs",
|
|
8794
|
+
label: "France · RCS (SIREN + ville)",
|
|
8795
|
+
test: (v) => /^\d{9}RCS[A-Z]{2,}$/.test(v.replace(/[\s]/g, "")),
|
|
8796
|
+
format: (v) => v.replace(/^(\d{3})(\d{3})(\d{3})RCS(.+)$/, "$1 $2 $3 RCS $4")
|
|
8797
|
+
},
|
|
8798
|
+
{ id: "generic", label: "Libre (4 à 20 caractères)", test: (v) => /^[A-Z0-9/-]{4,20}$/.test(v) }
|
|
8799
|
+
];
|
|
8800
|
+
var find = (list, id) => list.find((format) => format.id === id);
|
|
8801
|
+
var compactPlate = (value) => compact2(value);
|
|
8802
|
+
function checkPlate(format, value) {
|
|
8803
|
+
const rule = find(PLATE_FORMATS, format) ?? find(PLATE_FORMATS, "generic");
|
|
8804
|
+
return rule.test(compact2(value));
|
|
8805
|
+
}
|
|
8806
|
+
function formatPlate(format, value) {
|
|
8807
|
+
const rule = find(PLATE_FORMATS, format);
|
|
8808
|
+
const compacted = compact2(value);
|
|
8809
|
+
return rule?.format && rule.test(compacted) ? rule.format(compacted) : value.trim().toUpperCase();
|
|
8810
|
+
}
|
|
8811
|
+
var compactRegistry = (value) => value.replace(/\s+/g, "").toUpperCase();
|
|
8812
|
+
function checkCompanyRegistry(format, value) {
|
|
8813
|
+
const rule = find(REGISTRY_FORMATS, format) ?? find(REGISTRY_FORMATS, "generic");
|
|
8814
|
+
return rule.test(compactRegistry(value));
|
|
8815
|
+
}
|
|
8816
|
+
function formatCompanyRegistry(format, value) {
|
|
8817
|
+
const rule = find(REGISTRY_FORMATS, format);
|
|
8818
|
+
const compacted = compactRegistry(value);
|
|
8819
|
+
return rule?.format && rule.test(compacted) ? rule.format(compacted) : value.trim().toUpperCase();
|
|
8820
|
+
}
|
|
8627
8821
|
// lib/utils/slots.ts
|
|
8628
8822
|
var pad = (n) => String(n).padStart(2, "0");
|
|
8629
8823
|
var localIso = (date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
@@ -8892,6 +9086,10 @@ import_ajv_formats.default(ajv, ["email", "uri"]);
|
|
|
8892
9086
|
import_ajv_errors.default(ajv);
|
|
8893
9087
|
for (const format of ["fr-nir", "bj-npi", "fr-siren", "fr-siret", "bj-ifu", "iban", ...Array.from({ length: 20 }, (_, i) => `digits-${i + 1}`)])
|
|
8894
9088
|
ajv.addFormat(`identity-${format}`, (value) => checkIdentity(format, value));
|
|
9089
|
+
for (const { id } of PLATE_FORMATS)
|
|
9090
|
+
ajv.addFormat(`plate-${id}`, (value) => checkPlate(id, value));
|
|
9091
|
+
for (const { id } of REGISTRY_FORMATS)
|
|
9092
|
+
ajv.addFormat(`registry-${id}`, (value) => checkCompanyRegistry(id, value));
|
|
8895
9093
|
ajv.addKeyword({
|
|
8896
9094
|
keyword: "dateRange",
|
|
8897
9095
|
type: "object",
|
|
@@ -9841,6 +10039,9 @@ export {
|
|
|
9841
10039
|
FetchOptionSourceService,
|
|
9842
10040
|
FetchSpecSourceService,
|
|
9843
10041
|
IDENTITY_FORMATS,
|
|
10042
|
+
MEASURE_FAMILIES,
|
|
10043
|
+
PLATE_FORMATS,
|
|
10044
|
+
REGISTRY_FORMATS,
|
|
9844
10045
|
SandboxJsRunnerService,
|
|
9845
10046
|
SpecHistory,
|
|
9846
10047
|
UnsafeEvalJsRunnerService,
|
|
@@ -9850,6 +10051,7 @@ export {
|
|
|
9850
10051
|
buildValidationSchema,
|
|
9851
10052
|
checkBjIfu,
|
|
9852
10053
|
checkBjNpi,
|
|
10054
|
+
checkCompanyRegistry,
|
|
9853
10055
|
checkDigits,
|
|
9854
10056
|
checkFrNir,
|
|
9855
10057
|
checkFrSiren,
|
|
@@ -9857,9 +10059,12 @@ export {
|
|
|
9857
10059
|
checkIban,
|
|
9858
10060
|
checkIdentity,
|
|
9859
10061
|
checkLuhn,
|
|
10062
|
+
checkPlate,
|
|
9860
10063
|
collectFields,
|
|
9861
10064
|
collectRecapItems,
|
|
10065
|
+
compactPlate,
|
|
9862
10066
|
convertFormioForm,
|
|
10067
|
+
convertMeasure,
|
|
9863
10068
|
defaultFormData,
|
|
9864
10069
|
defaultValidationMessage,
|
|
9865
10070
|
documentFillPatch,
|
|
@@ -9870,7 +10075,10 @@ export {
|
|
|
9870
10075
|
fkT,
|
|
9871
10076
|
fkTOr,
|
|
9872
10077
|
flaggedKeys,
|
|
10078
|
+
formatCompanyRegistry,
|
|
9873
10079
|
formatIban,
|
|
10080
|
+
formatMeasure,
|
|
10081
|
+
formatPlate,
|
|
9874
10082
|
frFkTranslations,
|
|
9875
10083
|
generateSlots,
|
|
9876
10084
|
getAffectedProperties,
|
|
@@ -9883,6 +10091,9 @@ export {
|
|
|
9883
10091
|
iterateBricks,
|
|
9884
10092
|
iterateSchemaBricks,
|
|
9885
10093
|
lintSpec,
|
|
10094
|
+
measureFamilyOf,
|
|
10095
|
+
measureUnits,
|
|
10096
|
+
measureValue,
|
|
9886
10097
|
moveBrick,
|
|
9887
10098
|
mrzCheckDigit,
|
|
9888
10099
|
mrzLines,
|
|
@@ -9904,6 +10115,7 @@ export {
|
|
|
9904
10115
|
slotDate,
|
|
9905
10116
|
stripBrickUids,
|
|
9906
10117
|
stripUidsFromPatches,
|
|
10118
|
+
unitOf,
|
|
9907
10119
|
updateBrickConfigs,
|
|
9908
10120
|
updateBrickRules,
|
|
9909
10121
|
updateBrickStyles,
|
|
@@ -9914,5 +10126,5 @@ export {
|
|
|
9914
10126
|
wrapBrickData
|
|
9915
10127
|
};
|
|
9916
10128
|
|
|
9917
|
-
//# debugId=
|
|
10129
|
+
//# debugId=66D34BADA4DA021964756E2164756E21
|
|
9918
10130
|
//# sourceMappingURL=index.js.map
|