@tricoteuses/assemblee 3.6.1 → 3.7.1
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/lib/eliasse-CP5wde9Z.js +275 -0
- package/lib/eliasse-details.d.ts +14 -0
- package/lib/eliasse-details.test.d.ts +1 -0
- package/lib/eliasse-retry.d.ts +54 -0
- package/lib/eliasse-retry.test.d.ts +1 -0
- package/lib/eliasse-socket.d.ts +22 -0
- package/lib/eliasse-socket.js +62 -8
- package/lib/eliasse-sync.d.ts +31 -3
- package/lib/eliasse-sync.js +116 -46
- package/lib/eliasse.d.ts +1 -0
- package/lib/eliasse.js +2 -150
- package/lib/open_data/artifacts.d.ts +4 -0
- package/lib/parsers.js +130 -68
- package/lib/scripts/prepare_targeted_documents.d.ts +1 -0
- package/lib/scripts/retrieve_documents.d.ts +4 -0
- package/lib/scripts/shared/senateur_photo.d.ts +1 -0
- package/lib/scripts/shared/senateur_photo.test.d.ts +1 -0
- package/lib/scripts/validate_targeted_document_content.d.ts +1 -0
- package/lib/targeted_documents.d.ts +14 -0
- package/lib/targeted_documents.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { t as e } from "./zod_errors-qS8sQ67W.js";
|
|
2
|
+
import { z as t } from "zod";
|
|
3
|
+
//#region src/eliasse-retry.ts
|
|
4
|
+
var n = class extends Error {
|
|
5
|
+
constructor(e, t) {
|
|
6
|
+
super(`Eliasse ${e.kind}${e.status === void 0 ? "" : ` (${e.status})`}${e.code ? ` [${e.code}]` : ""}: ${e.message} ${t}`), this.failure = e, this.url = t, this.name = "EliasseRequestError";
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
function r(e) {
|
|
10
|
+
if (e instanceof n || e instanceof Error && e.name === "EliasseRequestError" && "failure" in e) return e.failure;
|
|
11
|
+
let t = e instanceof Error ? e.name : "", r = e?.cause;
|
|
12
|
+
return {
|
|
13
|
+
code: typeof r?.code == "string" ? r.code : void 0,
|
|
14
|
+
kind: t === "TimeoutError" || t === "AbortError" ? "timeout" : "network",
|
|
15
|
+
message: e instanceof Error ? e.message : String(e)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function i(e, t, n, r = {}) {
|
|
19
|
+
let i = (e?.attempts ?? 0) + 1, a = r.baseMs ?? 6e4, o = r.maxMs ?? 36e5, s = .8 + .4 * (r.random?.() ?? Math.random()), c = Math.min(o, a * 2 ** Math.min(i - 1, 20) * s);
|
|
20
|
+
return {
|
|
21
|
+
...e,
|
|
22
|
+
attempts: i,
|
|
23
|
+
firstFailureAt: e?.attempts ? e.firstFailureAt ?? n : n,
|
|
24
|
+
lastFailureAt: n,
|
|
25
|
+
lastAttemptAt: n,
|
|
26
|
+
failure: t,
|
|
27
|
+
nextRetryAt: n + Math.max(c, t.retryAfterMs ?? 0)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var a = class extends Error {
|
|
31
|
+
constructor(e, t) {
|
|
32
|
+
super(`Eliasse retry deferred for ${e} until ${new Date(t.nextRetryAt).toISOString()}`), this.key = e, this.state = t, this.name = "EliasseRetryDeferredError";
|
|
33
|
+
}
|
|
34
|
+
}, o = class {
|
|
35
|
+
constructor(e, t = {}) {
|
|
36
|
+
this.store = e, this.options = t;
|
|
37
|
+
}
|
|
38
|
+
async run(e, t, n = !1) {
|
|
39
|
+
let o = this.options.now?.() ?? Date.now(), s = await this.store.load(e) ?? { attempts: 0 };
|
|
40
|
+
if (n && !s.active && s.failure?.kind !== "rate-limit" && !s.failure?.retryAfterMs && (s = {
|
|
41
|
+
...s,
|
|
42
|
+
nextRetryAt: void 0
|
|
43
|
+
}), s = {
|
|
44
|
+
...s,
|
|
45
|
+
active: n,
|
|
46
|
+
lastSeenAt: o
|
|
47
|
+
}, (s.nextRetryAt ?? 0) > o) throw await this.store.save(e, s), new a(e, s);
|
|
48
|
+
s.lastAttemptAt = o;
|
|
49
|
+
let c;
|
|
50
|
+
try {
|
|
51
|
+
c = await t();
|
|
52
|
+
} catch (t) {
|
|
53
|
+
let a = r(t), o = i(s, a, this.options.now?.() ?? Date.now(), {
|
|
54
|
+
baseMs: n ? 15e3 : 6e4,
|
|
55
|
+
maxMs: n ? 15e3 : 36e5,
|
|
56
|
+
random: this.options.random
|
|
57
|
+
});
|
|
58
|
+
throw await this.store.save(e, o), t;
|
|
59
|
+
}
|
|
60
|
+
return await this.store.save(e, {
|
|
61
|
+
attempts: 0,
|
|
62
|
+
active: n,
|
|
63
|
+
lastSeenAt: o,
|
|
64
|
+
lastAttemptAt: o,
|
|
65
|
+
lastSuccessAt: this.options.now?.() ?? Date.now()
|
|
66
|
+
}), c;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
async function s(e, t, n) {
|
|
70
|
+
if (!Number.isInteger(t) || t < 1) throw Error("Concurrency must be a positive integer");
|
|
71
|
+
let r = Array(e.length), i = 0;
|
|
72
|
+
return await Promise.all(Array.from({ length: Math.min(t, e.length) }, async () => {
|
|
73
|
+
for (; i < e.length;) {
|
|
74
|
+
let t = i++;
|
|
75
|
+
try {
|
|
76
|
+
r[t] = {
|
|
77
|
+
status: "fulfilled",
|
|
78
|
+
value: await n(e[t])
|
|
79
|
+
};
|
|
80
|
+
} catch (e) {
|
|
81
|
+
r[t] = {
|
|
82
|
+
status: "rejected",
|
|
83
|
+
reason: e
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})), r;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/eliasse.ts
|
|
91
|
+
var c = "https://eliasse.assemblee-nationale.fr/api-eliasse/", l = t.object({
|
|
92
|
+
uid: t.string(),
|
|
93
|
+
abreviation: t.string(),
|
|
94
|
+
libelle: t.string(),
|
|
95
|
+
libelleAbrege: t.string(),
|
|
96
|
+
libelleAbregeRaccourci: t.string(),
|
|
97
|
+
dateFin: t.string().nullable()
|
|
98
|
+
}), u = t.object({
|
|
99
|
+
codeMinefi: t.string().nullable().optional(),
|
|
100
|
+
libelle: t.string().nullable().optional(),
|
|
101
|
+
missionLibelle: t.string().nullable().optional(),
|
|
102
|
+
nombreAmendementsMissionTotal: t.number().nullable().optional(),
|
|
103
|
+
nombreAmendementsMissionExamines: t.number().nullable().optional(),
|
|
104
|
+
nombreAmendementsMissionRestants: t.number().nullable().optional()
|
|
105
|
+
}), d = t.object({
|
|
106
|
+
uid: t.string(),
|
|
107
|
+
organeRef: t.string(),
|
|
108
|
+
statut: t.string(),
|
|
109
|
+
texte: t.object({
|
|
110
|
+
uid: t.string(),
|
|
111
|
+
libelle: t.string(),
|
|
112
|
+
bibard: t.string(),
|
|
113
|
+
partie: t.number()
|
|
114
|
+
}),
|
|
115
|
+
estSecondeDeliberation: t.boolean(),
|
|
116
|
+
missions: t.array(u)
|
|
117
|
+
}), f = t.object({
|
|
118
|
+
uidOrgane: t.string(),
|
|
119
|
+
uidTexte: t.string(),
|
|
120
|
+
uidExamen: t.string(),
|
|
121
|
+
uidAmendement: t.string().nullable()
|
|
122
|
+
}), p = t.object({ libelle: t.string() }), m = t.object({
|
|
123
|
+
id: t.string(),
|
|
124
|
+
uid: t.string(),
|
|
125
|
+
numero: t.string(),
|
|
126
|
+
estSousAmendement: t.boolean(),
|
|
127
|
+
sort: t.string().nullable(),
|
|
128
|
+
ordre: t.string(),
|
|
129
|
+
auteur: p,
|
|
130
|
+
positionDiscussionIdentique: t.string().nullable(),
|
|
131
|
+
positionDiscussionCommune: t.string().nullable(),
|
|
132
|
+
positionDiscussionIdentiqueSousAmendement: t.string().nullable(),
|
|
133
|
+
positionDiscussionCommuneSousAmendement: t.string().nullable(),
|
|
134
|
+
estVisible: t.boolean(),
|
|
135
|
+
codeMinefi: t.string().nullable(),
|
|
136
|
+
numeroParent: t.string().nullable().optional(),
|
|
137
|
+
amendementParentRef: t.string().nullable().optional()
|
|
138
|
+
}), h = t.object({
|
|
139
|
+
places: t.array(t.object({
|
|
140
|
+
id: t.string(),
|
|
141
|
+
libelle: t.string(),
|
|
142
|
+
amendements: t.array(m)
|
|
143
|
+
})),
|
|
144
|
+
version: t.number()
|
|
145
|
+
}), g = t.object({
|
|
146
|
+
divisionRef: t.string().nullable(),
|
|
147
|
+
titre: t.string().nullable(),
|
|
148
|
+
articleDesignationCourte: t.string().nullable(),
|
|
149
|
+
articleDesignation: t.string().nullable(),
|
|
150
|
+
type: t.string().nullable(),
|
|
151
|
+
avantApres: t.string().nullable(),
|
|
152
|
+
urlDivisionTexteVise: t.string().nullable(),
|
|
153
|
+
estArticleAdditionnel: t.boolean(),
|
|
154
|
+
estChapitreAdditionnel: t.boolean(),
|
|
155
|
+
contenuHtml: t.string().nullable()
|
|
156
|
+
}), _ = t.object({
|
|
157
|
+
typeAuteur: t.string().nullable(),
|
|
158
|
+
ref: t.string().nullable(),
|
|
159
|
+
libelle: t.string(),
|
|
160
|
+
urlPhoto: t.string().nullable(),
|
|
161
|
+
urlFicheActeur: t.string().nullable()
|
|
162
|
+
}), v = t.object({
|
|
163
|
+
uid: t.string(),
|
|
164
|
+
libelle: t.string(),
|
|
165
|
+
prenom: t.string().nullable(),
|
|
166
|
+
nom: t.string().nullable(),
|
|
167
|
+
civilite: t.string().nullable(),
|
|
168
|
+
urlPhoto: t.string().nullable(),
|
|
169
|
+
urlFicheActeur: t.string().nullable()
|
|
170
|
+
}), y = t.object({
|
|
171
|
+
uid: t.string(),
|
|
172
|
+
numero: t.string(),
|
|
173
|
+
numeroParent: t.string().nullable(),
|
|
174
|
+
amendementParentRef: t.string().nullable(),
|
|
175
|
+
estSousAmendement: t.boolean(),
|
|
176
|
+
sort: t.string().nullable(),
|
|
177
|
+
ordre: t.string(),
|
|
178
|
+
division: g.nullable(),
|
|
179
|
+
auteur: _.nullable(),
|
|
180
|
+
auteurParent: _.nullable(),
|
|
181
|
+
cosignataires: t.array(v),
|
|
182
|
+
cosignatairesSuffixe: t.string().nullable(),
|
|
183
|
+
cosignatairesLibelle: t.string().nullable(),
|
|
184
|
+
positionDiscussionIdentique: t.string().nullable(),
|
|
185
|
+
positionDiscussionCommune: t.string().nullable(),
|
|
186
|
+
positionDiscussionIdentiqueSousAmendement: t.string().nullable(),
|
|
187
|
+
positionDiscussionCommuneSousAmendement: t.string().nullable(),
|
|
188
|
+
dispositif: t.string().nullable(),
|
|
189
|
+
exposeSommaire: t.string().nullable(),
|
|
190
|
+
contenuHtmlDuTexteDeReference: t.string().nullable(),
|
|
191
|
+
missionLibelle: t.string().nullable()
|
|
192
|
+
}), b = t.object({
|
|
193
|
+
codeMinefi: t.string().nullable().optional(),
|
|
194
|
+
missionLibelle: t.string().nullable().optional(),
|
|
195
|
+
nombreAmendementsMissionTotal: t.number().nullable().optional(),
|
|
196
|
+
nombreAmendementsMissionExamines: t.number().nullable().optional(),
|
|
197
|
+
nombreAmendementsMissionRestants: t.number().nullable().optional()
|
|
198
|
+
}), x = t.object({
|
|
199
|
+
nombreAmendementsTotal: t.number(),
|
|
200
|
+
nombreAmendementsExamines: t.number(),
|
|
201
|
+
nombreAmendementsRestants: t.number(),
|
|
202
|
+
missions: t.array(b)
|
|
203
|
+
});
|
|
204
|
+
function S(e) {
|
|
205
|
+
let t = /L(\d+)/.exec(e);
|
|
206
|
+
return t === null ? void 0 : Number(t[1]);
|
|
207
|
+
}
|
|
208
|
+
async function C(t, i, a, o) {
|
|
209
|
+
let s = o?.baseUrl ?? "https://eliasse.assemblee-nationale.fr/api-eliasse/", c = new URL(t, s.endsWith("/") ? s : `${s}/`), l;
|
|
210
|
+
try {
|
|
211
|
+
l = await fetch(c, {
|
|
212
|
+
headers: { Accept: "application/json" },
|
|
213
|
+
signal: o?.signal
|
|
214
|
+
});
|
|
215
|
+
} catch (e) {
|
|
216
|
+
throw new n(r(e), String(c));
|
|
217
|
+
}
|
|
218
|
+
if (!l.ok) {
|
|
219
|
+
let e = l.headers.get("retry-after"), t = e === null ? void 0 : /^\d+$/.test(e) ? Number(e) * 1e3 : Math.max(0, Date.parse(e) - Date.now());
|
|
220
|
+
throw new n({
|
|
221
|
+
kind: l.status === 404 ? "not-found" : l.status === 429 ? "rate-limit" : "http",
|
|
222
|
+
status: l.status,
|
|
223
|
+
message: l.statusText,
|
|
224
|
+
retryAfterMs: Number.isFinite(t) ? t : void 0
|
|
225
|
+
}, String(c));
|
|
226
|
+
}
|
|
227
|
+
let u;
|
|
228
|
+
try {
|
|
229
|
+
u = await l.text();
|
|
230
|
+
} catch (e) {
|
|
231
|
+
throw new n(r(e), String(c));
|
|
232
|
+
}
|
|
233
|
+
if (u.trim() === "") throw new n({
|
|
234
|
+
kind: "empty",
|
|
235
|
+
status: l.status,
|
|
236
|
+
message: "Empty response body"
|
|
237
|
+
}, String(c));
|
|
238
|
+
let d;
|
|
239
|
+
try {
|
|
240
|
+
d = JSON.parse(u);
|
|
241
|
+
} catch {
|
|
242
|
+
throw new n({
|
|
243
|
+
kind: "invalid",
|
|
244
|
+
status: l.status,
|
|
245
|
+
message: "Invalid JSON response"
|
|
246
|
+
}, String(c));
|
|
247
|
+
}
|
|
248
|
+
let f = i.safeParse(d);
|
|
249
|
+
if (!f.success) throw new n({
|
|
250
|
+
kind: "invalid",
|
|
251
|
+
status: l.status,
|
|
252
|
+
message: e(a, f.error, d)
|
|
253
|
+
}, String(c));
|
|
254
|
+
return d;
|
|
255
|
+
}
|
|
256
|
+
function w(e) {
|
|
257
|
+
return C("organes", t.array(l), "organes", e);
|
|
258
|
+
}
|
|
259
|
+
function T(e) {
|
|
260
|
+
return C("examens", t.array(d), "examens", e);
|
|
261
|
+
}
|
|
262
|
+
function E(e) {
|
|
263
|
+
return C("prochainadiscuter", t.array(f), "prochains à discuter", e);
|
|
264
|
+
}
|
|
265
|
+
function D(e, t) {
|
|
266
|
+
return C(`examens/${encodeURIComponent(e)}/derouleur`, h, "dérouleur", t);
|
|
267
|
+
}
|
|
268
|
+
function O(e, t) {
|
|
269
|
+
return C(`examens/${encodeURIComponent(e)}/statistiques`, x, "statistiques", t);
|
|
270
|
+
}
|
|
271
|
+
function k(e, n, r, i) {
|
|
272
|
+
return C(`textes/${encodeURIComponent(e)}/examens/${encodeURIComponent(n)}/amendements/${encodeURIComponent(r)}/with_neighbors`, t.array(y), "amendements", i);
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
export { o as C, i as D, s as E, n as S, r as T, D as _, m as a, E as b, g as c, l as d, f, k as g, S as h, c as i, d as l, x as m, y as n, p as o, b as p, v as r, h as s, _ as t, u, T as v, a as w, O as x, w as y };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EliasseAmendement } from './eliasse.js';
|
|
2
|
+
import { EliasseFailure } from './eliasse-retry.js';
|
|
3
|
+
export interface EliasseDetailBatch {
|
|
4
|
+
details: Map<string, EliasseAmendement>;
|
|
5
|
+
failures: Map<string, EliasseFailure>;
|
|
6
|
+
rateLimit?: EliasseFailure;
|
|
7
|
+
}
|
|
8
|
+
/** Windowed, bounded detail recovery. The first target (usually current) is
|
|
9
|
+
* requested first. Missing neighbors get individual recovery; partial successes
|
|
10
|
+
* survive later failures. Unattempted targets are deferred, never unavailable. */
|
|
11
|
+
export declare function fetchEliasseDetailBatch(uids: string[], readWindow: (uid: string, signal: AbortSignal) => Promise<EliasseAmendement[]>, options?: {
|
|
12
|
+
budgetMs?: number;
|
|
13
|
+
requestTimeoutMs?: number;
|
|
14
|
+
}): Promise<EliasseDetailBatch>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Browser-safe error classification, durable route backoff and bounded workers. */
|
|
2
|
+
export type EliasseFailureKind = "not-found" | "empty" | "invalid" | "rate-limit" | "http" | "timeout" | "network" | "deferred";
|
|
3
|
+
export interface EliasseFailure {
|
|
4
|
+
kind: EliasseFailureKind;
|
|
5
|
+
message: string;
|
|
6
|
+
status?: number;
|
|
7
|
+
retryAfterMs?: number;
|
|
8
|
+
code?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class EliasseRequestError extends Error {
|
|
11
|
+
readonly failure: EliasseFailure;
|
|
12
|
+
readonly url: string;
|
|
13
|
+
constructor(failure: EliasseFailure, url: string);
|
|
14
|
+
}
|
|
15
|
+
export declare function classifyEliasseFailure(error: unknown): EliasseFailure;
|
|
16
|
+
export interface EliasseRetryState {
|
|
17
|
+
attempts: number;
|
|
18
|
+
firstFailureAt?: number;
|
|
19
|
+
lastFailureAt?: number;
|
|
20
|
+
failure?: EliasseFailure;
|
|
21
|
+
nextRetryAt?: number;
|
|
22
|
+
lastAttemptAt?: number;
|
|
23
|
+
lastSuccessAt?: number;
|
|
24
|
+
lastSeenAt?: number;
|
|
25
|
+
active?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function nextEliasseRetry(previous: EliasseRetryState | undefined, failure: EliasseFailure, now: number, options?: {
|
|
28
|
+
baseMs?: number;
|
|
29
|
+
maxMs?: number;
|
|
30
|
+
random?: () => number;
|
|
31
|
+
}): EliasseRetryState;
|
|
32
|
+
export declare class EliasseRetryDeferredError extends Error {
|
|
33
|
+
readonly key: string;
|
|
34
|
+
readonly state: EliasseRetryState;
|
|
35
|
+
constructor(key: string, state: EliasseRetryState);
|
|
36
|
+
}
|
|
37
|
+
export interface EliasseRetryStore {
|
|
38
|
+
load(key: string): Promise<EliasseRetryState | undefined>;
|
|
39
|
+
save(key: string, state: EliasseRetryState): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** A key must identify a single route. Calls for that key are serialized by the
|
|
42
|
+
* caller (the synchronizer does this per examen). Deferred calls update liveness
|
|
43
|
+
* but do not issue HTTP. Current targets recover rapidly, except Retry-After. */
|
|
44
|
+
export declare class EliasseRequestScheduler {
|
|
45
|
+
private store;
|
|
46
|
+
private options;
|
|
47
|
+
constructor(store: EliasseRetryStore, options?: {
|
|
48
|
+
now?: () => number;
|
|
49
|
+
random?: () => number;
|
|
50
|
+
});
|
|
51
|
+
run<T>(key: string, request: () => Promise<T>, active?: boolean): Promise<T>;
|
|
52
|
+
}
|
|
53
|
+
/** Stable result ordering; slow or rejected jobs do not stop other workers. */
|
|
54
|
+
export declare function mapEliasseConcurrent<T, R>(items: T[], concurrency: number, work: (item: T) => Promise<R>): Promise<PromiseSettledResult<R>[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/eliasse-socket.d.ts
CHANGED
|
@@ -41,14 +41,30 @@ interface WebSocketLike {
|
|
|
41
41
|
reason?: string;
|
|
42
42
|
}) => void) | null;
|
|
43
43
|
onerror: ((event?: unknown) => void) | null;
|
|
44
|
+
addEventListener?(type: "message", listener: () => void): void;
|
|
44
45
|
}
|
|
45
46
|
type WebSocketConstructor = new (url: string | URL, protocols?: string | string[]) => WebSocketLike;
|
|
46
47
|
export type EliasseSocketStatus = "connecting" | "connected" | "disconnected";
|
|
48
|
+
export interface EliasseSocketDiagnostic {
|
|
49
|
+
type: "connected" | "closed" | "heartbeat-lost" | "keepalive";
|
|
50
|
+
at: number;
|
|
51
|
+
heartbeat?: string;
|
|
52
|
+
code?: number;
|
|
53
|
+
reason?: string;
|
|
54
|
+
wasClean?: boolean;
|
|
55
|
+
intentional?: boolean;
|
|
56
|
+
connectedForMs?: number;
|
|
57
|
+
receiveIdleMs?: number;
|
|
58
|
+
sendIdleMs?: number;
|
|
59
|
+
}
|
|
47
60
|
export interface EliasseSocketOptions {
|
|
48
61
|
socketUrl?: string;
|
|
49
62
|
/** Requested heart-beat period; negotiation is handled by stompjs. */
|
|
50
63
|
heartbeatMs?: number;
|
|
51
64
|
reconnectDelayMs?: number;
|
|
65
|
+
/** Optional STOMP newline to keep an idle transport open when the broker
|
|
66
|
+
* negotiates 0,0. Disabled by default; this does not require incoming beats. */
|
|
67
|
+
keepAliveMs?: number;
|
|
52
68
|
WebSocket?: WebSocketConstructor;
|
|
53
69
|
}
|
|
54
70
|
/** Browser-safe STOMP client. Framing, subscription routing, negotiated
|
|
@@ -59,6 +75,12 @@ export declare class EliasseSocket {
|
|
|
59
75
|
readonly reconnectDelayMs: number;
|
|
60
76
|
onStatusChange?: (status: EliasseSocketStatus) => void;
|
|
61
77
|
onError?: (error: Error) => void;
|
|
78
|
+
onDiagnostic?: (event: EliasseSocketDiagnostic) => void;
|
|
79
|
+
private connectedAt?;
|
|
80
|
+
private lastReceivedAt?;
|
|
81
|
+
private lastSentAt?;
|
|
82
|
+
private stopping;
|
|
83
|
+
private keepAliveTimer?;
|
|
62
84
|
private client;
|
|
63
85
|
private statusValue;
|
|
64
86
|
private subscriptionCounter;
|
package/lib/eliasse-socket.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./zod_errors-qS8sQ67W.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a as t, f as n, m as r } from "./eliasse-CP5wde9Z.js";
|
|
3
3
|
import { z as i } from "zod";
|
|
4
4
|
import { Client as a } from "@stomp/stompjs";
|
|
5
5
|
//#region src/eliasse-socket.ts
|
|
@@ -58,25 +58,78 @@ function f(e, t) {
|
|
|
58
58
|
}
|
|
59
59
|
var p = class {
|
|
60
60
|
constructor(e = {}) {
|
|
61
|
-
this.statusValue = "disconnected", this.subscriptionCounter = 0, this.subscriptions = /* @__PURE__ */ new Map(), this.socketUrl = e.socketUrl ?? "wss://eliasse.assemblee-nationale.fr/ws-eliasse", this.heartbeatMs = e.heartbeatMs ?? 4e3, this.reconnectDelayMs = e.reconnectDelayMs ?? 5e3;
|
|
61
|
+
if (this.stopping = !1, this.statusValue = "disconnected", this.subscriptionCounter = 0, this.subscriptions = /* @__PURE__ */ new Map(), this.socketUrl = e.socketUrl ?? "wss://eliasse.assemblee-nationale.fr/ws-eliasse", this.heartbeatMs = e.heartbeatMs ?? 4e3, this.reconnectDelayMs = e.reconnectDelayMs ?? 5e3, !Number.isFinite(e.keepAliveMs ?? 0) || (e.keepAliveMs ?? 0) < 0) throw Error("keepAliveMs must be nonnegative");
|
|
62
62
|
let t = e.WebSocket ?? globalThis.WebSocket;
|
|
63
63
|
if (t === void 0) throw Error("WebSocket is not available: use a browser or Node.js >= 22, or provide options.WebSocket.");
|
|
64
64
|
this.client = new a({
|
|
65
|
-
webSocketFactory: () =>
|
|
65
|
+
webSocketFactory: () => {
|
|
66
|
+
let e = new t(this.socketUrl, ["v12.stomp"]), n = e.send.bind(e);
|
|
67
|
+
if (e.send = (e) => {
|
|
68
|
+
n(e), this.lastSentAt = Date.now();
|
|
69
|
+
}, e.addEventListener) e.addEventListener("message", () => {
|
|
70
|
+
this.lastReceivedAt = Date.now();
|
|
71
|
+
});
|
|
72
|
+
else {
|
|
73
|
+
let t = e.onmessage;
|
|
74
|
+
Object.defineProperty(e, "onmessage", {
|
|
75
|
+
configurable: !0,
|
|
76
|
+
get: () => t,
|
|
77
|
+
set: (n) => {
|
|
78
|
+
t = n === null ? null : (t) => {
|
|
79
|
+
this.lastReceivedAt = Date.now(), n.call(e, t);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return e;
|
|
85
|
+
},
|
|
66
86
|
connectHeaders: { host: new URL(this.socketUrl).hostname },
|
|
67
87
|
reconnectDelay: this.reconnectDelayMs,
|
|
68
88
|
connectionTimeout: 15e3,
|
|
69
89
|
heartbeatIncoming: this.heartbeatMs,
|
|
70
90
|
heartbeatOutgoing: this.heartbeatMs,
|
|
71
|
-
beforeConnect: () =>
|
|
72
|
-
|
|
91
|
+
beforeConnect: () => {
|
|
92
|
+
this.connectedAt = this.lastReceivedAt = this.lastSentAt = void 0, this.setStatus("connecting");
|
|
93
|
+
},
|
|
94
|
+
onConnect: (t) => {
|
|
95
|
+
this.connectedAt = Date.now(), this.onDiagnostic?.({
|
|
96
|
+
type: "connected",
|
|
97
|
+
at: this.connectedAt,
|
|
98
|
+
heartbeat: t.headers["heart-beat"]
|
|
99
|
+
});
|
|
73
100
|
for (let [e, t] of this.subscriptions) this.subscribe(e, t);
|
|
74
|
-
this.setStatus("connected")
|
|
101
|
+
this.setStatus("connected"), e.keepAliveMs && (this.keepAliveTimer = setInterval(() => {
|
|
102
|
+
if (!(this.statusValue !== "connected" || Date.now() - (this.lastSentAt ?? 0) < e.keepAliveMs)) try {
|
|
103
|
+
this.client.webSocket?.send("\n"), this.lastSentAt = Date.now(), this.onDiagnostic?.({
|
|
104
|
+
type: "keepalive",
|
|
105
|
+
at: this.lastSentAt
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
this.onError?.(/* @__PURE__ */ Error("Eliasse keepalive send failed"));
|
|
109
|
+
}
|
|
110
|
+
}, e.keepAliveMs));
|
|
75
111
|
},
|
|
76
|
-
onWebSocketClose: () => {
|
|
112
|
+
onWebSocketClose: (e) => {
|
|
113
|
+
clearInterval(this.keepAliveTimer), this.keepAliveTimer = void 0;
|
|
114
|
+
let t = Date.now();
|
|
115
|
+
this.onDiagnostic?.({
|
|
116
|
+
type: "closed",
|
|
117
|
+
at: t,
|
|
118
|
+
code: e.code,
|
|
119
|
+
reason: e.reason,
|
|
120
|
+
wasClean: e.wasClean,
|
|
121
|
+
intentional: this.stopping,
|
|
122
|
+
connectedForMs: this.connectedAt === void 0 ? void 0 : t - this.connectedAt,
|
|
123
|
+
receiveIdleMs: this.lastReceivedAt === void 0 ? void 0 : t - this.lastReceivedAt,
|
|
124
|
+
sendIdleMs: this.lastSentAt === void 0 ? void 0 : t - this.lastSentAt
|
|
125
|
+
});
|
|
77
126
|
for (let e of this.subscriptions.values()) e.active = void 0;
|
|
78
127
|
this.setStatus("disconnected");
|
|
79
128
|
},
|
|
129
|
+
onHeartbeatLost: () => this.onDiagnostic?.({
|
|
130
|
+
type: "heartbeat-lost",
|
|
131
|
+
at: Date.now()
|
|
132
|
+
}),
|
|
80
133
|
onWebSocketError: () => this.onError?.(/* @__PURE__ */ Error("Eliasse WebSocket transport error")),
|
|
81
134
|
onStompError: (e) => this.onError?.(/* @__PURE__ */ Error(`STOMP ERROR (${e.headers.message ?? ""}): ${e.body}`))
|
|
82
135
|
});
|
|
@@ -88,9 +141,10 @@ var p = class {
|
|
|
88
141
|
return this.client.webSocket;
|
|
89
142
|
}
|
|
90
143
|
connect() {
|
|
91
|
-
this.client.activate();
|
|
144
|
+
this.stopping = !1, this.client.activate();
|
|
92
145
|
}
|
|
93
146
|
async disconnect() {
|
|
147
|
+
this.stopping = !0, clearInterval(this.keepAliveTimer), this.keepAliveTimer = void 0;
|
|
94
148
|
let e = setTimeout(() => {
|
|
95
149
|
this.client.deactivate({ force: !0 });
|
|
96
150
|
}, 1e3);
|
package/lib/eliasse-sync.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { EliasseAmendement, EliasseDerouleur, EliasseDerouleurAmendement, EliasseStatistiques } from './eliasse.js';
|
|
2
2
|
import { EliasseDerouleurUpdate } from './eliasse-socket.js';
|
|
3
|
+
import { EliasseFailure, EliasseRetryState } from './eliasse-retry.js';
|
|
4
|
+
export * from './eliasse-retry.js';
|
|
5
|
+
export * from './eliasse-details.js';
|
|
3
6
|
export interface EliasseSyncTarget {
|
|
4
7
|
uidExamen: string;
|
|
5
8
|
uidTexte: string;
|
|
@@ -20,6 +23,9 @@ export interface EliasseStoredAmendement {
|
|
|
20
23
|
detailPending: boolean;
|
|
21
24
|
detailFetchedAt?: number;
|
|
22
25
|
detailRetryAt?: number;
|
|
26
|
+
detailAttempts?: number;
|
|
27
|
+
detailPendingSince?: number;
|
|
28
|
+
detailRetry?: EliasseRetryState;
|
|
23
29
|
}
|
|
24
30
|
export interface EliasseSyncState {
|
|
25
31
|
/** Optional opaque optimistic-concurrency token managed by the repository. */
|
|
@@ -34,21 +40,43 @@ export interface EliasseSyncCounts {
|
|
|
34
40
|
/** Actual open data changes, not attempted writes. */
|
|
35
41
|
patched: number;
|
|
36
42
|
pendingDetails: number;
|
|
43
|
+
pendingCurrentDetails?: number;
|
|
44
|
+
pendingHistoricalDetails?: number;
|
|
45
|
+
outcomes?: Array<{
|
|
46
|
+
uid: string;
|
|
47
|
+
before: string | null;
|
|
48
|
+
after: string | null;
|
|
49
|
+
}>;
|
|
50
|
+
rowsChanged?: number;
|
|
51
|
+
detailsChanged?: number;
|
|
52
|
+
membershipsChanged?: number;
|
|
53
|
+
referencesChanged?: number;
|
|
54
|
+
retriesChanged?: number;
|
|
55
|
+
receivedAt?: number;
|
|
37
56
|
}
|
|
38
57
|
export interface EliasseSyncRepository {
|
|
39
58
|
load(uidExamen: string): Promise<EliasseSyncState>;
|
|
40
59
|
/** Must be atomic; a rejection must leave the previous checkpoint intact. */
|
|
41
|
-
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques
|
|
42
|
-
|
|
60
|
+
commit(target: EliasseSyncTarget, state: EliasseSyncState, statistiques?: EliasseStatistiques, context?: {
|
|
61
|
+
source: "http" | "patch";
|
|
62
|
+
snapshotReceivedAt?: number;
|
|
63
|
+
statisticsReceivedAt?: number;
|
|
64
|
+
}): Promise<Pick<EliasseSyncCounts, "stored" | "patched" | "outcomes" | "rowsChanged" | "detailsChanged" | "membershipsChanged" | "referencesChanged" | "retriesChanged">>;
|
|
65
|
+
saveStatistics(uidExamen: string, statistiques: EliasseStatistiques, receivedAt?: number): Promise<void>;
|
|
43
66
|
}
|
|
44
67
|
export interface EliasseSynchronizerOptions {
|
|
45
68
|
repository: EliasseSyncRepository;
|
|
46
69
|
fetchDerouleur(target: EliasseSyncTarget): Promise<EliasseDerouleur>;
|
|
47
70
|
fetchStatistiques(target: EliasseSyncTarget): Promise<EliasseStatistiques>;
|
|
48
|
-
fetchDetails(target: EliasseSyncTarget, uids: string[]): Promise<Map<string, EliasseAmendement
|
|
71
|
+
fetchDetails(target: EliasseSyncTarget, uids: string[]): Promise<Map<string, EliasseAmendement> | {
|
|
72
|
+
details: Map<string, EliasseAmendement>;
|
|
73
|
+
failures: Map<string, EliasseFailure>;
|
|
74
|
+
}>;
|
|
49
75
|
limit?: number;
|
|
50
76
|
detailRefreshMs?: number;
|
|
51
77
|
retryMs?: number;
|
|
78
|
+
historicalRetryMaxMs?: number;
|
|
79
|
+
random?: () => number;
|
|
52
80
|
now?: () => number;
|
|
53
81
|
onError?: (error: unknown) => void;
|
|
54
82
|
}
|