archivist: fix invalid JSON (unescaped quotes), use expr raw strings (backticks) in expressions

This commit is contained in:
2026-10-31 12:58:25 +01:00
parent 1fbb0229c9
commit 7f1fbb7f4b
+18 -17
View File
@@ -25,7 +25,8 @@
//
// Each rule contains four keys:
// when (required): expr-lang expression; the rest of the rule runs only
// if it evaluates to true
// if it evaluates to true. String literals inside
// expressions are written as raw strings with backticks.
// set : list of assignments
// { "field": "x", "value": <fixed value> } constant
// { "field": "x", "eval": "<expression>" } evaluated in the
@@ -43,13 +44,13 @@
{
"when": "true",
"set": [
{ "field": "date", "eval": "firstMatch("[0-9]{2}/[0-9]{2}/[0-9]{4}")" }
{ "field": "date", "eval": "firstMatch(`[0-9]{2}/[0-9]{2}/[0-9]{4}`)" }
]
},
// --- Bank statements (relevés de compte) ----------------------------------
{
"when": "firstPageText contains "Relevé de compte"",
"when": "firstPageText contains `Relevé de compte`",
"set": [
{ "field": "documentType", "value": "Relevé de compte" },
{ "field": "template", "value": "bank_statement" }
@@ -57,24 +58,24 @@
"rules": [
// Issuing bank
{
"when": "firstPageText contains "BRED"",
"when": "firstPageText contains `BRED`",
"set": [ { "field": "emittingCompany", "value": "BRED" } ]
},
{
"when": "firstPageText contains "Fortunéo"",
"when": "firstPageText contains `Fortunéo`",
"set": [ { "field": "emittingCompany", "value": "Fortunéo" } ]
},
{
"when": "firstPageText contains "Crédit Mutuel"",
"when": "firstPageText contains `Crédit Mutuel`",
"set": [ { "field": "emittingCompany", "value": "Crédit Mutuel" } ]
},
// Personal accounts, matched on the account number printed on page 1
{
"when": "firstPageText contains "12345678901"",
"when": "firstPageText contains `12345678901`",
"set": [ { "field": "bankAccount", "value": "Compte Thomas" } ]
},
{
"when": "firstPageText contains "98765432109"",
"when": "firstPageText contains `98765432109`",
"set": [ { "field": "bankAccount", "value": "Compte joint" } ]
}
]
@@ -82,7 +83,7 @@
// --- Taxe d'habitation, one child rule per address ------------------------
{
"when": "firstPageText contains "Taxe d'habitation"",
"when": "firstPageText contains `Taxe d'habitation`",
"set": [
{ "field": "documentType", "value": "Taxe d'habitation" },
{ "field": "emittingCompany", "value": "DGFiP" },
@@ -90,11 +91,11 @@
],
"rules": [
{
"when": "firstPageText contains "12 rue des Lilas"",
"when": "firstPageText contains `12 rue des Lilas`",
"set": [ { "field": "address", "value": "12 rue des Lilas, Paris" } ]
},
{
"when": "firstPageText contains "34 avenue Jean Jaurès"",
"when": "firstPageText contains `34 avenue Jean Jaurès`",
"set": [ { "field": "address", "value": "34 avenue Jean Jaurès, Bordeaux" } ]
}
]
@@ -102,7 +103,7 @@
// --- Avis d'impôt sur le revenu --------------------------------------------
{
"when": "firstPageText contains "Impôt sur le revenu" && firstPageText contains "avis d'imposition"",
"when": "firstPageText contains `Impôt sur le revenu` && firstPageText contains `avis d'imposition`",
"set": [
{ "field": "documentType", "value": "Avis d'impôt sur le revenu" },
{ "field": "emittingCompany", "value": "DGFiP" },
@@ -112,27 +113,27 @@
// --- Generic invoices (e-commerce and others) -----------------------------
{
"when": "firstPageText contains "Facture" && firstPageText contains "TVA"",
"when": "firstPageText contains `Facture` && firstPageText contains `TVA`",
"set": [
{ "field": "documentType", "value": "Facture" },
{ "field": "template", "value": "invoice" },
// Invoice number, e.g. "Facture n° F-2026-0123" -> "F-2026-0123"
{ "field": "reference", "eval": "firstMatch("[Ff]acture n° ?([A-Za-z0-9-]+)")" }
{ "field": "reference", "eval": "firstMatch(`[Ff]acture n° ?([A-Za-z0-9-]+)`)" }
],
// Fields that do not apply to invoices, in case an earlier rule
// set them
"delete": [ "bankAccount", "address" ],
"rules": [
{
"when": "firstPageText contains "Amazon"",
"when": "firstPageText contains `Amazon`",
"set": [ { "field": "emittingCompany", "value": "Amazon" } ]
},
{
"when": "firstPageText contains "LDLC"",
"when": "firstPageText contains `LDLC`",
"set": [ { "field": "emittingCompany", "value": "LDLC" } ]
},
{
"when": "firstPageText contains "Cdiscount"",
"when": "firstPageText contains `Cdiscount`",
"set": [ { "field": "emittingCompany", "value": "Cdiscount" } ]
}
]