@streamline-pulse/formkrafter-core 0.29.0 → 0.30.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 +203 -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,18 @@ 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
|
+
"category.Measures": "Measures",
|
|
7347
|
+
"category.Registries": "Vehicles & companies",
|
|
7348
|
+
"brick.measure.name": "Measure",
|
|
7349
|
+
"brick.vehicle-plate.name": "Vehicle plate",
|
|
7350
|
+
"brick.company-registry.name": "Company registration",
|
|
7351
|
+
"measure.value": "Value",
|
|
7352
|
+
"measure.unit": "Unit",
|
|
7353
|
+
"panel.family": "Measure family (length, area, mass, volume, duration)",
|
|
7354
|
+
"panel.units": "Units offered (ids, comma-separated; empty = all)",
|
|
7355
|
+
"panel.unit": "Default unit",
|
|
7356
|
+
"panel.plateFormat": "Plate format (fr, bj, ci, sn, generic)",
|
|
7357
|
+
"panel.registryFormat": "Registration format (ohada-rccm, fr-rcs, generic)",
|
|
7332
7358
|
"panel.slotsUrl": "Slots URL (empty = opening rules)",
|
|
7333
7359
|
"panel.slotDays": "Open days (1 = Monday … 7 = Sunday)",
|
|
7334
7360
|
"panel.slotFrom": "Opens at",
|
|
@@ -7554,6 +7580,18 @@ var frFkTranslations = {
|
|
|
7554
7580
|
"panel.documentLanguage": "Langue du document (fr, en…)",
|
|
7555
7581
|
"panel.cfg.capture": "Proposer l’appareil photo sur mobile",
|
|
7556
7582
|
"panel.cfg.keepFile": "Conserver le fichier dans la réponse",
|
|
7583
|
+
"category.Measures": "Mesures",
|
|
7584
|
+
"category.Registries": "Véhicules & entreprises",
|
|
7585
|
+
"brick.measure.name": "Mesure",
|
|
7586
|
+
"brick.vehicle-plate.name": "Immatriculation",
|
|
7587
|
+
"brick.company-registry.name": "Registre d’entreprise",
|
|
7588
|
+
"measure.value": "Valeur",
|
|
7589
|
+
"measure.unit": "Unité",
|
|
7590
|
+
"panel.family": "Famille de mesure (length, area, mass, volume, duration)",
|
|
7591
|
+
"panel.units": "Unités proposées (identifiants séparés par des virgules ; vide = toutes)",
|
|
7592
|
+
"panel.unit": "Unité par défaut",
|
|
7593
|
+
"panel.plateFormat": "Format d’immatriculation (fr, bj, ci, sn, generic)",
|
|
7594
|
+
"panel.registryFormat": "Format du registre (ohada-rccm, fr-rcs, generic)",
|
|
7557
7595
|
"panel.slotsUrl": "URL des créneaux (vide = règles d’ouverture)",
|
|
7558
7596
|
"panel.slotDays": "Jours ouverts (1 = lundi … 7 = dimanche)",
|
|
7559
7597
|
"panel.slotFrom": "Ouverture",
|
|
@@ -8624,6 +8662,150 @@ function parseTd1(l1, l2, l3, raw) {
|
|
|
8624
8662
|
errors
|
|
8625
8663
|
};
|
|
8626
8664
|
}
|
|
8665
|
+
// lib/utils/units.ts
|
|
8666
|
+
var MEASURE_FAMILIES = {
|
|
8667
|
+
length: {
|
|
8668
|
+
base: "m",
|
|
8669
|
+
units: [
|
|
8670
|
+
{ id: "mm", symbol: "mm", factor: 0.001 },
|
|
8671
|
+
{ id: "cm", symbol: "cm", factor: 0.01 },
|
|
8672
|
+
{ id: "m", symbol: "m", factor: 1 },
|
|
8673
|
+
{ id: "km", symbol: "km", factor: 1000 }
|
|
8674
|
+
]
|
|
8675
|
+
},
|
|
8676
|
+
area: {
|
|
8677
|
+
base: "m2",
|
|
8678
|
+
units: [
|
|
8679
|
+
{ id: "m2", symbol: "m²", factor: 1 },
|
|
8680
|
+
{ id: "a", symbol: "a", factor: 100 },
|
|
8681
|
+
{ id: "ha", symbol: "ha", factor: 1e4 },
|
|
8682
|
+
{ id: "km2", symbol: "km²", factor: 1e6 }
|
|
8683
|
+
]
|
|
8684
|
+
},
|
|
8685
|
+
mass: {
|
|
8686
|
+
base: "kg",
|
|
8687
|
+
units: [
|
|
8688
|
+
{ id: "g", symbol: "g", factor: 0.001 },
|
|
8689
|
+
{ id: "kg", symbol: "kg", factor: 1 },
|
|
8690
|
+
{ id: "t", symbol: "t", factor: 1000 }
|
|
8691
|
+
]
|
|
8692
|
+
},
|
|
8693
|
+
volume: {
|
|
8694
|
+
base: "l",
|
|
8695
|
+
units: [
|
|
8696
|
+
{ id: "ml", symbol: "ml", factor: 0.001 },
|
|
8697
|
+
{ id: "l", symbol: "l", factor: 1 },
|
|
8698
|
+
{ id: "m3", symbol: "m³", factor: 1000 }
|
|
8699
|
+
]
|
|
8700
|
+
},
|
|
8701
|
+
duration: {
|
|
8702
|
+
base: "h",
|
|
8703
|
+
units: [
|
|
8704
|
+
{ id: "min", symbol: "min", factor: 1 / 60 },
|
|
8705
|
+
{ id: "h", symbol: "h", factor: 1 },
|
|
8706
|
+
{ id: "d", symbol: "j", factor: 24 }
|
|
8707
|
+
]
|
|
8708
|
+
}
|
|
8709
|
+
};
|
|
8710
|
+
var measureFamilyOf = (value) => typeof value === "string" && (value in MEASURE_FAMILIES) ? value : "length";
|
|
8711
|
+
function measureUnits(family, allowed) {
|
|
8712
|
+
const all = MEASURE_FAMILIES[family].units;
|
|
8713
|
+
if (typeof allowed !== "string" || !allowed.trim())
|
|
8714
|
+
return all;
|
|
8715
|
+
const wanted = allowed.split(",").map((id) => id.trim().toLowerCase()).filter(Boolean);
|
|
8716
|
+
const picked = all.filter((unit) => wanted.includes(unit.id));
|
|
8717
|
+
return picked.length ? picked : all;
|
|
8718
|
+
}
|
|
8719
|
+
function unitOf(family, id) {
|
|
8720
|
+
return MEASURE_FAMILIES[family].units.find((unit) => unit.id === id);
|
|
8721
|
+
}
|
|
8722
|
+
var round = (n) => Math.round(n * 1e9) / 1e9;
|
|
8723
|
+
function convertMeasure(family, value, from, to) {
|
|
8724
|
+
const source = unitOf(family, from);
|
|
8725
|
+
const target = unitOf(family, to);
|
|
8726
|
+
if (!source || !target)
|
|
8727
|
+
return;
|
|
8728
|
+
return round(value * source.factor / target.factor);
|
|
8729
|
+
}
|
|
8730
|
+
function measureValue(family, value, unit) {
|
|
8731
|
+
const source = unitOf(family, unit);
|
|
8732
|
+
if (!source || !Number.isFinite(value))
|
|
8733
|
+
return;
|
|
8734
|
+
return { value, unit, base: round(value * source.factor) };
|
|
8735
|
+
}
|
|
8736
|
+
function formatMeasure(family, value, locale) {
|
|
8737
|
+
if (!value)
|
|
8738
|
+
return "";
|
|
8739
|
+
const unit = unitOf(family, value.unit);
|
|
8740
|
+
const number = new Intl.NumberFormat(locale, { maximumFractionDigits: 3 }).format(value.value);
|
|
8741
|
+
return `${number} ${unit?.symbol ?? value.unit}`;
|
|
8742
|
+
}
|
|
8743
|
+
// lib/utils/registries.ts
|
|
8744
|
+
var compact2 = (value) => value.replace(/[\s.-]/g, "").toUpperCase();
|
|
8745
|
+
var group = (value, pattern, template) => value.replace(pattern, template);
|
|
8746
|
+
var PLATE_FORMATS = [
|
|
8747
|
+
{
|
|
8748
|
+
id: "fr",
|
|
8749
|
+
label: "France · AA-123-AA",
|
|
8750
|
+
test: (v) => /^[A-HJ-NP-Z]{2}\d{3}[A-HJ-NP-Z]{2}$/.test(v),
|
|
8751
|
+
format: (v) => group(v, /^([A-Z]{2})(\d{3})([A-Z]{2})$/, "$1-$2-$3")
|
|
8752
|
+
},
|
|
8753
|
+
{
|
|
8754
|
+
id: "bj",
|
|
8755
|
+
label: "Bénin · AB 1234 RB",
|
|
8756
|
+
test: (v) => /^[A-Z]{1,2}\d{4}[A-Z]{2}$/.test(v),
|
|
8757
|
+
format: (v) => group(v, /^([A-Z]{1,2})(\d{4})([A-Z]{2})$/, "$1 $2 $3")
|
|
8758
|
+
},
|
|
8759
|
+
{
|
|
8760
|
+
id: "ci",
|
|
8761
|
+
label: "Côte d’Ivoire · 1234 AB 01",
|
|
8762
|
+
test: (v) => /^\d{4}[A-Z]{2}\d{2}$/.test(v),
|
|
8763
|
+
format: (v) => group(v, /^(\d{4})([A-Z]{2})(\d{2})$/, "$1 $2 $3")
|
|
8764
|
+
},
|
|
8765
|
+
{
|
|
8766
|
+
id: "sn",
|
|
8767
|
+
label: "Sénégal · AA 123 AA",
|
|
8768
|
+
test: (v) => /^[A-Z]{2}\d{3,4}[A-Z]{1,2}$/.test(v),
|
|
8769
|
+
format: (v) => group(v, /^([A-Z]{2})(\d{3,4})([A-Z]{1,2})$/, "$1 $2 $3")
|
|
8770
|
+
},
|
|
8771
|
+
{ id: "generic", label: "Libre (4 à 10 lettres ou chiffres)", test: (v) => /^[A-Z0-9]{4,10}$/.test(v) }
|
|
8772
|
+
];
|
|
8773
|
+
var REGISTRY_FORMATS = [
|
|
8774
|
+
{
|
|
8775
|
+
id: "ohada-rccm",
|
|
8776
|
+
label: "OHADA · RCCM (RB/COT/01 B 1234)",
|
|
8777
|
+
test: (v) => /^[A-Z]{2}\/[A-Z]{2,4}\/\d{2,4}[A-Z]\d{3,7}$/.test(v.replace(/[\s]/g, "")),
|
|
8778
|
+
format: (v) => v.replace(/^([A-Z]{2}\/[A-Z]{2,4}\/\d{2,4})([A-Z])(\d{3,7})$/, "$1 $2 $3")
|
|
8779
|
+
},
|
|
8780
|
+
{
|
|
8781
|
+
id: "fr-rcs",
|
|
8782
|
+
label: "France · RCS (SIREN + ville)",
|
|
8783
|
+
test: (v) => /^\d{9}RCS[A-Z]{2,}$/.test(v.replace(/[\s]/g, "")),
|
|
8784
|
+
format: (v) => v.replace(/^(\d{3})(\d{3})(\d{3})RCS(.+)$/, "$1 $2 $3 RCS $4")
|
|
8785
|
+
},
|
|
8786
|
+
{ id: "generic", label: "Libre (4 à 20 caractères)", test: (v) => /^[A-Z0-9/-]{4,20}$/.test(v) }
|
|
8787
|
+
];
|
|
8788
|
+
var find = (list, id) => list.find((format) => format.id === id);
|
|
8789
|
+
var compactPlate = (value) => compact2(value);
|
|
8790
|
+
function checkPlate(format, value) {
|
|
8791
|
+
const rule = find(PLATE_FORMATS, format) ?? find(PLATE_FORMATS, "generic");
|
|
8792
|
+
return rule.test(compact2(value));
|
|
8793
|
+
}
|
|
8794
|
+
function formatPlate(format, value) {
|
|
8795
|
+
const rule = find(PLATE_FORMATS, format);
|
|
8796
|
+
const compacted = compact2(value);
|
|
8797
|
+
return rule?.format && rule.test(compacted) ? rule.format(compacted) : value.trim().toUpperCase();
|
|
8798
|
+
}
|
|
8799
|
+
var compactRegistry = (value) => value.replace(/\s+/g, "").toUpperCase();
|
|
8800
|
+
function checkCompanyRegistry(format, value) {
|
|
8801
|
+
const rule = find(REGISTRY_FORMATS, format) ?? find(REGISTRY_FORMATS, "generic");
|
|
8802
|
+
return rule.test(compactRegistry(value));
|
|
8803
|
+
}
|
|
8804
|
+
function formatCompanyRegistry(format, value) {
|
|
8805
|
+
const rule = find(REGISTRY_FORMATS, format);
|
|
8806
|
+
const compacted = compactRegistry(value);
|
|
8807
|
+
return rule?.format && rule.test(compacted) ? rule.format(compacted) : value.trim().toUpperCase();
|
|
8808
|
+
}
|
|
8627
8809
|
// lib/utils/slots.ts
|
|
8628
8810
|
var pad = (n) => String(n).padStart(2, "0");
|
|
8629
8811
|
var localIso = (date) => `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
@@ -8892,6 +9074,10 @@ import_ajv_formats.default(ajv, ["email", "uri"]);
|
|
|
8892
9074
|
import_ajv_errors.default(ajv);
|
|
8893
9075
|
for (const format of ["fr-nir", "bj-npi", "fr-siren", "fr-siret", "bj-ifu", "iban", ...Array.from({ length: 20 }, (_, i) => `digits-${i + 1}`)])
|
|
8894
9076
|
ajv.addFormat(`identity-${format}`, (value) => checkIdentity(format, value));
|
|
9077
|
+
for (const { id } of PLATE_FORMATS)
|
|
9078
|
+
ajv.addFormat(`plate-${id}`, (value) => checkPlate(id, value));
|
|
9079
|
+
for (const { id } of REGISTRY_FORMATS)
|
|
9080
|
+
ajv.addFormat(`registry-${id}`, (value) => checkCompanyRegistry(id, value));
|
|
8895
9081
|
ajv.addKeyword({
|
|
8896
9082
|
keyword: "dateRange",
|
|
8897
9083
|
type: "object",
|
|
@@ -9841,6 +10027,9 @@ export {
|
|
|
9841
10027
|
FetchOptionSourceService,
|
|
9842
10028
|
FetchSpecSourceService,
|
|
9843
10029
|
IDENTITY_FORMATS,
|
|
10030
|
+
MEASURE_FAMILIES,
|
|
10031
|
+
PLATE_FORMATS,
|
|
10032
|
+
REGISTRY_FORMATS,
|
|
9844
10033
|
SandboxJsRunnerService,
|
|
9845
10034
|
SpecHistory,
|
|
9846
10035
|
UnsafeEvalJsRunnerService,
|
|
@@ -9850,6 +10039,7 @@ export {
|
|
|
9850
10039
|
buildValidationSchema,
|
|
9851
10040
|
checkBjIfu,
|
|
9852
10041
|
checkBjNpi,
|
|
10042
|
+
checkCompanyRegistry,
|
|
9853
10043
|
checkDigits,
|
|
9854
10044
|
checkFrNir,
|
|
9855
10045
|
checkFrSiren,
|
|
@@ -9857,9 +10047,12 @@ export {
|
|
|
9857
10047
|
checkIban,
|
|
9858
10048
|
checkIdentity,
|
|
9859
10049
|
checkLuhn,
|
|
10050
|
+
checkPlate,
|
|
9860
10051
|
collectFields,
|
|
9861
10052
|
collectRecapItems,
|
|
10053
|
+
compactPlate,
|
|
9862
10054
|
convertFormioForm,
|
|
10055
|
+
convertMeasure,
|
|
9863
10056
|
defaultFormData,
|
|
9864
10057
|
defaultValidationMessage,
|
|
9865
10058
|
documentFillPatch,
|
|
@@ -9870,7 +10063,10 @@ export {
|
|
|
9870
10063
|
fkT,
|
|
9871
10064
|
fkTOr,
|
|
9872
10065
|
flaggedKeys,
|
|
10066
|
+
formatCompanyRegistry,
|
|
9873
10067
|
formatIban,
|
|
10068
|
+
formatMeasure,
|
|
10069
|
+
formatPlate,
|
|
9874
10070
|
frFkTranslations,
|
|
9875
10071
|
generateSlots,
|
|
9876
10072
|
getAffectedProperties,
|
|
@@ -9883,6 +10079,9 @@ export {
|
|
|
9883
10079
|
iterateBricks,
|
|
9884
10080
|
iterateSchemaBricks,
|
|
9885
10081
|
lintSpec,
|
|
10082
|
+
measureFamilyOf,
|
|
10083
|
+
measureUnits,
|
|
10084
|
+
measureValue,
|
|
9886
10085
|
moveBrick,
|
|
9887
10086
|
mrzCheckDigit,
|
|
9888
10087
|
mrzLines,
|
|
@@ -9904,6 +10103,7 @@ export {
|
|
|
9904
10103
|
slotDate,
|
|
9905
10104
|
stripBrickUids,
|
|
9906
10105
|
stripUidsFromPatches,
|
|
10106
|
+
unitOf,
|
|
9907
10107
|
updateBrickConfigs,
|
|
9908
10108
|
updateBrickRules,
|
|
9909
10109
|
updateBrickStyles,
|
|
@@ -9914,5 +10114,5 @@ export {
|
|
|
9914
10114
|
wrapBrickData
|
|
9915
10115
|
};
|
|
9916
10116
|
|
|
9917
|
-
//# debugId=
|
|
10117
|
+
//# debugId=4C355ABE22E4DDEC64756E2164756E21
|
|
9918
10118
|
//# sourceMappingURL=index.js.map
|