@tricoteuses/senat 2.20.25 → 2.20.27

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.
@@ -73,6 +73,8 @@ function detectLecture(objet) {
73
73
  return undefined;
74
74
  }
75
75
  function computeCodeEtape(ev, dossier) {
76
+ // In order to match with etape, we need to remove the '-SEANCE' suffix from the codeActe
77
+ const cleanCode = (code) => code.replace(/-SEANCE$/, "");
76
78
  const lecture = detectLecture(ev.objet ?? "");
77
79
  const organe = ev.organe ?? "";
78
80
  const nature = organe.toLowerCase().includes("commission")
@@ -82,7 +84,7 @@ function computeCodeEtape(ev, dossier) {
82
84
  : "";
83
85
  const evDate = ev.date.split("T")[0];
84
86
  const flat = buildFlatActes(dossier);
85
- // 1) Match strict : même date + nature (COM / DEBATS si connue)
87
+ // 1) Strict matching : same date + nature
86
88
  let candidates = flat.filter((a) => {
87
89
  if (a.date !== evDate)
88
90
  return false;
@@ -90,50 +92,48 @@ function computeCodeEtape(ev, dossier) {
90
92
  return false;
91
93
  return true;
92
94
  });
93
- // console.log(` → candidats STRICT (date==${evDate} & nature=${nature || "ANY"}): ${candidates.length}`)
94
- // candidates.forEach((c) => console.log(` STRICT MATCH: ${c.codeActe} (date=${c.date}, lecture=${c.ordreLecture})`))
95
- // Si lecture détectée → on filtre si ça garde des candidats
95
+ // If lecture is specified, filter by it
96
96
  if (lecture !== undefined && candidates.length > 0) {
97
97
  const withLecture = candidates.filter((c) => c.ordreLecture === lecture);
98
98
  if (withLecture.length > 0) {
99
- // console.log(` → filtre lecture=${lecture} : ${withLecture.length} candidats`)
100
99
  candidates = withLecture;
101
100
  }
102
101
  }
103
102
  // Multiple candidates : we take the longest ?
104
103
  if (candidates.length > 0) {
105
104
  candidates.sort((a, b) => b.codeActe.length - a.codeActe.length);
106
- // console.log(` ✔ match FINAL (intervalle) : ${candidates[0].codeActe}`)
107
- return candidates[0].codeActe;
105
+ return cleanCode(candidates[0].codeActe);
108
106
  }
109
- // 2) fallback COM : dernier acte COM avant la date
107
+ // 2) fallback COM
110
108
  if (nature === "COM") {
111
109
  let comActs = flat.filter((a) => a.codeActe.includes("COM") && a.date <= evDate);
112
- // console.log(` → fallback COM: actes COM <= date : ${comActs.length}`)
113
110
  if (lecture !== undefined) {
114
111
  const byLecture = comActs.filter((a) => a.ordreLecture === lecture);
115
112
  if (byLecture.length > 0) {
116
113
  comActs = byLecture;
117
- // console.log(` → filtrés lecture=${lecture}: ${comActs.length}`)
118
114
  }
119
115
  }
120
116
  if (comActs.length > 0) {
121
117
  comActs.sort((a, b) => b.date.localeCompare(a.date) || b.codeActe.length - a.codeActe.length);
122
- // console.log(` ✔ match FINAL (fallback COM): ${comActs[0].codeActe}`)
123
- return comActs[0].codeActe;
118
+ return cleanCode(comActs[0].codeActe);
124
119
  }
125
120
  }
126
- // 3) Fallback lecture générale (SN1, SN2…) depuis la structure d’origine
121
+ // 3) Fallback lecture générale
127
122
  if (lecture !== undefined) {
128
123
  const lectures = dossier["actes_legislatifs"] ?? [];
129
124
  const lectureNode = lectures.find((l) => l.ordre_lecture === lecture);
130
125
  const rootCode = lectureNode?.code_acte;
131
126
  if (rootCode && typeof rootCode === "string") {
132
- // console.log(` ✔ FALLBACK LECTURE: ${rootCode}`)
133
- return rootCode;
127
+ return cleanCode(rootCode);
134
128
  }
135
129
  }
136
- console.log(` ✖ aucun code d’étape trouvé pour ev=${ev.id}`);
130
+ console.log(`✖ Échec pour ev=${ev.id}`, {
131
+ evDate,
132
+ nature,
133
+ lecture,
134
+ nbCandidatesInitial: flat.length,
135
+ firstFlatDate: flat[0]?.date,
136
+ });
137
137
  return null;
138
138
  }
139
139
  function buildFlatActes(dossier) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tricoteuses/senat",
3
- "version": "2.20.25",
3
+ "version": "2.20.27",
4
4
  "description": "Handle French Sénat's open data",
5
5
  "keywords": [
6
6
  "France",