@choosemycompany/lib 0.10.0 → 1.0.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.js CHANGED
@@ -1,303 +1,651 @@
1
- import { mande as q } from "mande";
2
- import { ref as A, computed as T, onMounted as F, onBeforeUnmount as x, onUnmounted as Z } from "vue";
3
- import { defineStore as V } from "pinia";
4
- import { useI18n as y } from "vue-i18n";
5
- import { createError as J } from "h3";
6
- import { showError as j, useRuntimeConfig as _, useState as $ } from "nuxt/app";
7
- let k;
8
- function he(e) {
1
+ import { mande as De } from "mande";
2
+ import { ref as L, computed as ie, reactive as Ke, shallowRef as Ne, onMounted as fe, onBeforeUnmount as He, onUnmounted as Oe } from "vue";
3
+ import { defineStore as _e } from "pinia";
4
+ import { useI18n as V } from "vue-i18n";
5
+ import { createError as Fe } from "h3";
6
+ import { showError as qe, useRuntimeConfig as xe, useState as je } from "nuxt/app";
7
+ let x;
8
+ function ha(e) {
9
9
  if (!e.baseUrl)
10
10
  throw new Error("@choosemycompany/lib: configureHttp() needs a non-empty baseUrl");
11
- k = e;
11
+ x = e;
12
12
  }
13
- function O(e) {
14
- if (!k)
13
+ function pe(e) {
14
+ if (!x)
15
15
  throw new Error(
16
16
  "@choosemycompany/lib: useHttp() was called before configureHttp(). Declare the base URLs from an app plugin."
17
17
  );
18
- if (e === void 0) return k.baseUrl;
19
- const a = k.targets ?? {}, i = Object.hasOwn(a, e) ? a[e] : void 0;
18
+ if (e === void 0) return x.baseUrl;
19
+ const n = x.targets ?? {}, i = Object.hasOwn(n, e) ? n[e] : void 0;
20
20
  if (typeof i != "string" || !i) {
21
- const t = Object.keys(a), n = t.length > 0 ? t.join(", ") : "none";
21
+ const s = Object.keys(n), o = s.length > 0 ? s.join(", ") : "none";
22
22
  throw new Error(
23
- `@choosemycompany/lib: no HTTP target named "${e}". Declared targets: ${n}.`
23
+ `@choosemycompany/lib: no HTTP target named "${e}". Declared targets: ${o}.`
24
24
  );
25
25
  }
26
26
  return i;
27
27
  }
28
- const W = "/auth/api/v2/session/tokens", Q = "/auth/api/v2/", Y = "cmc-auth-session-refresh", X = V("cmc-auth-session", () => {
29
- const e = A(!1), a = A(!1), i = A(void 0);
30
- let t, n = 0;
31
- const o = T(() => e.value && !a.value);
32
- function u() {
33
- e.value = !0, a.value = !1, i.value = void 0;
28
+ const Ve = "/auth/api/v2/session/tokens", Ze = "/auth/api/v2/", $e = "cmc-auth-session-refresh", Je = _e("cmc-auth-session", () => {
29
+ const e = L(!1), n = L(!1), i = L(void 0);
30
+ let s, o = 0;
31
+ const u = ie(() => e.value && !n.value);
32
+ function l() {
33
+ e.value = !0, n.value = !1, i.value = void 0;
34
34
  }
35
35
  function f() {
36
- n += 1, e.value = !1, a.value = !1, i.value = void 0;
36
+ o += 1, e.value = !1, n.value = !1, i.value = void 0;
37
37
  }
38
38
  function g() {
39
- n += 1, e.value = !1, a.value = !0, i.value = "logout";
39
+ o += 1, e.value = !1, n.value = !0, i.value = "logout";
40
40
  }
41
- function l(v) {
42
- n += 1, e.value = !1, a.value = !0, i.value = v;
41
+ function h(S) {
42
+ o += 1, e.value = !1, n.value = !0, i.value = S;
43
43
  }
44
- async function b() {
45
- if (a.value)
44
+ async function A() {
45
+ if (n.value)
46
46
  throw new Error("Session is expired: no refresh will be attempted");
47
- return t ??= m(h).finally(() => {
48
- t = void 0;
49
- }), t;
50
- }
51
- async function m(v) {
52
- const p = globalThis.navigator?.locks;
53
- if (!p) return v();
54
- await p.request(Y, v);
55
- }
56
- async function h() {
57
- const v = n, p = () => v !== n, P = new URL(W, O()).href;
58
- let M;
47
+ return s ??= y(k).finally(() => {
48
+ s = void 0;
49
+ }), s;
50
+ }
51
+ async function y(S) {
52
+ const v = globalThis.navigator?.locks;
53
+ if (!v) return S();
54
+ await v.request($e, S);
55
+ }
56
+ async function k() {
57
+ const S = o, v = () => S !== o, Z = new URL(Ve, pe()).href;
58
+ let U;
59
59
  try {
60
- M = await fetch(P, {
60
+ U = await fetch(Z, {
61
61
  method: "POST",
62
62
  credentials: "include"
63
63
  });
64
- } catch (U) {
65
- throw p() || C(), U;
64
+ } catch ($) {
65
+ throw v() || R(), $;
66
66
  }
67
- if (!M.ok)
68
- throw p() || (M.status === 401 ? l(e.value ? "refresh-rejected" : "no-session") : C()), new Error(`Token refresh failed with status ${M.status}`);
69
- if (p())
67
+ if (!U.ok)
68
+ throw v() || (U.status === 401 ? h(e.value ? "refresh-rejected" : "no-session") : R()), new Error(`Token refresh failed with status ${U.status}`);
69
+ if (v())
70
70
  throw new Error("Session was dropped while the refresh was in flight");
71
- u();
71
+ l();
72
72
  }
73
- function C() {
73
+ function R() {
74
74
  i.value = "refresh-unreachable";
75
75
  }
76
76
  return {
77
77
  isOpen: e,
78
- isExpired: a,
78
+ isExpired: n,
79
79
  expiryReason: i,
80
- isAuthenticated: o,
81
- open: u,
82
- expire: l,
80
+ isAuthenticated: u,
81
+ open: l,
82
+ expire: h,
83
83
  clear: f,
84
84
  logout: g,
85
- refresh: b
85
+ refresh: A
86
86
  };
87
87
  });
88
- function ee() {
88
+ function We() {
89
89
  return import.meta.server || typeof document > "u";
90
90
  }
91
- function ae(e) {
92
- return (typeof e == "string" ? e : e instanceof URL ? e.href : e.url).includes(Q);
91
+ function Qe(e) {
92
+ return (typeof e == "string" ? e : e instanceof URL ? e.href : e.url).includes(Ze);
93
93
  }
94
- function ne() {
95
- return async (e, a) => {
96
- if (ee()) return fetch(e, a);
97
- const i = await fetch(e, a);
98
- if (i.status !== 401 || ae(e) || new Headers(a?.headers).has("Authorization")) return i;
99
- let t;
94
+ function Ye() {
95
+ return async (e, n) => {
96
+ if (We()) return fetch(e, n);
97
+ const i = await fetch(e, n);
98
+ if (i.status !== 401 || Qe(e) || new Headers(n?.headers).has("Authorization")) return i;
99
+ let s;
100
100
  try {
101
- t = X();
101
+ s = Je();
102
102
  } catch {
103
103
  return i;
104
104
  }
105
- if (t.isExpired) return i;
105
+ if (s.isExpired) return i;
106
106
  try {
107
- await t.refresh();
108
- } catch (n) {
109
- return t.isExpired || console.warn("[cmc-lib] token refresh failed, returning the original 401", n), i;
107
+ await s.refresh();
108
+ } catch (o) {
109
+ return s.isExpired || console.warn("[cmc-lib] token refresh failed, returning the original 401", o), i;
110
110
  }
111
- return fetch(e, a);
111
+ return fetch(e, n);
112
112
  };
113
113
  }
114
- function be(e) {
115
- const a = q(O(e), {
114
+ function ba(e) {
115
+ const n = De(pe(e), {
116
116
  headers: {}
117
- }, ne());
118
- function i(n) {
119
- a.options.headers = {
120
- ...a.options.headers ?? {},
121
- Authorization: `Bearer ${n}`
117
+ }, Ye());
118
+ function i(o) {
119
+ n.options.headers = {
120
+ ...n.options.headers ?? {},
121
+ Authorization: `Bearer ${o}`
122
122
  };
123
123
  }
124
- function t() {
125
- a.options.headers && delete a.options.headers.Authorization;
124
+ function s() {
125
+ n.options.headers && delete n.options.headers.Authorization;
126
126
  }
127
- return { http: a, setToken: i, clearToken: t };
127
+ return { http: n, setToken: i, clearToken: s };
128
128
  }
129
- function ve(e, a) {
130
- return e.replace(ie, (i, t) => {
131
- const n = Object.hasOwn(a, t) ? a[t] : void 0;
132
- if (typeof n != "string" && typeof n != "number")
133
- throw new Error(`Missing URL parameter "${t}" for template "${e}"`);
134
- return encodeURIComponent(String(n));
129
+ function va(e, n) {
130
+ return e.replace(Xe, (i, s) => {
131
+ const o = Object.hasOwn(n, s) ? n[s] : void 0;
132
+ if (typeof o != "string" && typeof o != "number")
133
+ throw new Error(`Missing URL parameter "${s}" for template "${e}"`);
134
+ return encodeURIComponent(String(o));
135
135
  });
136
136
  }
137
- const ie = /\{(\w+)\}/g;
138
- function N(e) {
139
- return Object.entries(e).sort(([a], [i]) => a.localeCompare(i)).map(([a, i]) => `${a}=${i}`).join("|");
140
- }
141
- const te = "create";
142
- function Be(e) {
143
- const a = A({}), i = A({}), t = A({}), n = A({}), o = A(0);
144
- let u = 0;
145
- const f = e.getItemId ?? ((r) => {
146
- const d = r.id;
147
- if (d === void 0)
148
- throw new Error(
149
- "useStore: no `getItemId` option provided and item has no `id` property. Either pass `getItemId` in the store options, or expose an `id` field on your items."
150
- );
151
- return d;
152
- });
153
- function g(r) {
154
- return !!n.value[r];
137
+ const Xe = /\{(\w+)\}/g;
138
+ class ea extends Error {
139
+ constructor(n) {
140
+ super(n ? "useStore: getItemId found no id in the received item." : "useStore: getItemId found no id in the received item. Pass `getItemId` in the store options, or give your items an `id` field."), this.name = "MissingItemIdError";
155
141
  }
156
- async function l(r, d) {
157
- n.value[r] = d;
158
- try {
159
- const s = await d;
160
- return delete t.value[r], s;
161
- } catch (s) {
162
- throw t.value[r] = s, s;
163
- } finally {
164
- n.value[r] === d && delete n.value[r];
165
- }
142
+ }
143
+ class aa extends Error {
144
+ constructor() {
145
+ super("useStore: the store was reset before this queued work started"), this.name = "StoreResetError";
146
+ }
147
+ }
148
+ function j(e) {
149
+ return re(e).join("|");
150
+ }
151
+ function Ba(e) {
152
+ const n = L({}), i = L({}), s = Ke({ items: n, views: i }), o = /* @__PURE__ */ new Map(), u = Ne(0);
153
+ let l = 0, f = 0;
154
+ const g = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Set();
155
+ function S(a, t, r = {}) {
156
+ return Q(a, t, r);
157
+ }
158
+ function v(a) {
159
+ _();
160
+ for (const t of o.values())
161
+ if (t.status === "pending" && D(t, a))
162
+ return !0;
163
+ return !1;
166
164
  }
167
- async function b(r, d = {}) {
165
+ function Z(a) {
166
+ _();
167
+ let t = 0;
168
+ for (const r of o.values())
169
+ r.status === "pending" && D(r, a) && (t += 1);
170
+ return t;
171
+ }
172
+ function U(a) {
173
+ return v({ kind: "item", id: a });
174
+ }
175
+ function $(a, t = {}) {
176
+ return v(a ? { kind: "view", params: a, exact: t.exact } : { kind: "view" });
177
+ }
178
+ function he(a = {}) {
179
+ return v({ ...a, kind: "mutation" });
180
+ }
181
+ function be(a = {}) {
182
+ return v({ ...a, kind: "query" });
183
+ }
184
+ function ve(a) {
185
+ _();
186
+ const t = [];
187
+ for (const r of o.values())
188
+ r.status === "error" && D(r, a) && t.push({ scope: r.scope, error: r.error });
189
+ return t;
190
+ }
191
+ function Be(a) {
192
+ _();
193
+ for (const t of o.values())
194
+ if (t.status === "error" && D(t, a))
195
+ return t.error;
196
+ }
197
+ function K(a) {
198
+ for (const t of [...o.values()])
199
+ t.status === "error" && D(t, a) && o.delete(t.token);
200
+ P();
201
+ }
202
+ async function we(a, t = {}) {
168
203
  if (!e.fetchOne)
169
204
  throw new Error("useStore.retrieve called but fetchOne is not defined in store options");
170
- const { force: s = !1 } = d;
171
- if (a.value[r] && !s)
172
- return a.value[r];
173
- const c = n.value[r];
174
- if (c)
175
- return c;
176
- const B = e.fetchOne, S = (async () => {
177
- const I = u;
178
- try {
179
- const E = await B(r);
180
- if (I !== u)
181
- return;
182
- const R = e.enrichItem ? e.enrichItem(E) : E;
183
- return a.value[r] = R, delete t.value[r], a.value[r];
184
- } catch (E) {
185
- I === u && (t.value[r] = E);
186
- return;
187
- } finally {
188
- I === u && delete n.value[r];
205
+ const { force: r = !1 } = t, d = n.value[a];
206
+ if (d !== void 0 && !r && (!e.isComplete || e.isComplete(d)))
207
+ return d;
208
+ const p = h.get(E(a));
209
+ if (p && !r)
210
+ return G(p);
211
+ const B = e.fetchOne, I = e.isGone ?? ia, M = f, b = l, C = oe(h, E(a), (c) => Q(
212
+ { kind: "item", id: a },
213
+ async () => {
214
+ let w;
215
+ try {
216
+ w = await B(a);
217
+ } catch (m) {
218
+ if (c.supersededBy)
219
+ return;
220
+ throw M === f && !q(m) && I(m) && H(a), m;
221
+ }
222
+ if (!(M !== f || c.supersededBy)) {
223
+ if (Y(a, b)) {
224
+ const m = n.value[a];
225
+ if (m === void 0 || X(a) !== void 0)
226
+ return m;
227
+ const F = l;
228
+ let T;
229
+ try {
230
+ T = await B(a);
231
+ } catch (ae) {
232
+ if (c.supersededBy)
233
+ return;
234
+ throw M === f && !q(ae) && I(ae) && H(a), ae;
235
+ }
236
+ return M !== f || c.supersededBy || Y(a, F) ? X(a) : z(a, e.enrichItem ? e.enrichItem(T) : T);
237
+ }
238
+ return z(a, e.enrichItem ? e.enrichItem(w) : w);
239
+ }
240
+ },
241
+ {},
242
+ (w) => {
243
+ c.entryToken = w.token;
189
244
  }
190
- })();
191
- return n.value[r] = S, S;
245
+ ).catch((w) => q(w) ? X(a) : void 0));
246
+ return G(C);
192
247
  }
193
- function m(r) {
194
- const d = N(r), s = i.value[d];
195
- if (s)
248
+ function N(a) {
249
+ const t = j(a), r = i.value[t];
250
+ if (r)
196
251
  return {
197
- items: s.itemIds.map((c) => a.value[c]).filter((c) => c !== void 0),
198
- total: s.total,
199
- hasMore: s.hasMore,
200
- page: s.page,
201
- limit: s.limit
252
+ items: r.itemIds.map((d) => n.value[d]).filter((d) => d !== void 0),
253
+ total: r.total,
254
+ hasMore: r.hasMore,
255
+ page: r.page,
256
+ limit: r.limit
202
257
  };
203
258
  }
204
- async function h(r, d = {}) {
259
+ function Ae(a) {
260
+ return n.value[a];
261
+ }
262
+ function ke() {
263
+ return Object.values(n.value);
264
+ }
265
+ function Ce(a) {
266
+ const t = e.enrichItem ? e.enrichItem(a) : a;
267
+ z(W(t), t);
268
+ }
269
+ function H(a, t = {}) {
270
+ const { clearError: r = !0 } = t;
271
+ delete n.value[a];
272
+ for (const d of Object.values(i.value)) {
273
+ const p = d.itemIds.findIndex((B) => E(B) === E(a));
274
+ p !== -1 && (d.itemIds.splice(p, 1), d.total = Math.max(0, d.total - 1));
275
+ }
276
+ r && (K({ kind: "item", id: a }), K({ kind: "mutation", name: "update", id: a }), K({ kind: "mutation", name: "remove", id: a }));
277
+ }
278
+ function O(a) {
279
+ for (const t of Object.keys(i.value))
280
+ ne(t, a) && g.add(t);
281
+ for (const [t, r] of A)
282
+ ne(t, a) && (r.stale = !0);
283
+ }
284
+ function Se(a) {
285
+ return a.kind === "item" ? n.value[a.id] !== void 0 : i.value[j(a.params)] !== void 0;
286
+ }
287
+ async function ye(a, t = {}) {
205
288
  if (!e.fetchPage)
206
289
  throw new Error("useStore.list called but fetchPage is not defined in store options");
207
- const s = N(r), { force: c = !1 } = d;
208
- if (i.value[s]?.revision === o.value && !c)
209
- return m(r);
210
- const B = n.value[s];
211
- if (B)
212
- return await B, m(r);
213
- const S = e.fetchPage, I = (async () => {
214
- const E = o.value, R = u;
215
- try {
216
- const w = await S(r);
217
- if (R !== u)
290
+ const r = j(a), { force: d = !1 } = t;
291
+ if (i.value[r] !== void 0 && !g.has(r) && !d)
292
+ return N(a);
293
+ const p = A.get(r);
294
+ if (p && !d)
295
+ return await G(p), N(a);
296
+ const B = e.fetchPage, I = f, M = l, b = oe(A, r, (C) => Q(
297
+ { kind: "view", params: a },
298
+ async () => {
299
+ let c;
300
+ try {
301
+ c = await B(a);
302
+ } catch (m) {
303
+ if (C.supersededBy)
304
+ return;
305
+ throw m;
306
+ }
307
+ if (I !== f || C.supersededBy)
218
308
  return;
219
- const L = [];
220
- for (const G of w.items) {
221
- const z = e.enrichItem ? e.enrichItem(G) : G, D = f(z);
222
- a.value[D] = z, L.push(D);
309
+ const w = [];
310
+ for (const m of c.items) {
311
+ const F = e.enrichItem ? e.enrichItem(m) : m, T = W(F);
312
+ Y(T, M) || z(T, F), w.push(T);
223
313
  }
224
- i.value[s] = {
225
- itemIds: L,
226
- total: w.total,
227
- hasMore: w.hasMore,
228
- page: w.page,
229
- limit: w.limit,
230
- revision: E
231
- }, delete t.value[s];
232
- } catch (w) {
233
- R === u && (t.value[s] = w);
234
- } finally {
235
- R === u && delete n.value[s];
314
+ i.value[r] = {
315
+ itemIds: w,
316
+ total: c.total,
317
+ hasMore: c.hasMore,
318
+ page: c.page,
319
+ limit: c.limit
320
+ }, C.stale ? g.add(r) : g.delete(r);
321
+ },
322
+ {},
323
+ (c) => {
324
+ C.entryToken = c.token;
236
325
  }
237
- })();
238
- return n.value[s] = I, await I, m(r);
326
+ ).catch(() => {
327
+ }));
328
+ return await G(b), N(a);
239
329
  }
240
- async function C(r, d = te) {
330
+ async function Ie(a, t = {}) {
241
331
  if (!e.createMutation)
242
332
  throw new Error("useStore.create called but createMutation is not defined in store options");
243
- const s = e.createMutation, c = await l(d, (async () => s(r))()), B = e.enrichItem ? e.enrichItem(c) : c, S = f(B);
244
- return a.value[S] = B, i.value = {}, p(), B;
333
+ const r = e.createMutation;
334
+ return J({ name: "create", ...t }, () => r(a), {}, void 0, !0);
245
335
  }
246
- async function v(r, d) {
336
+ async function Me(a, t) {
247
337
  if (!e.updateMutation)
248
338
  throw new Error("useStore.update called but updateMutation is not defined in store options");
249
- const s = e.updateMutation, c = await l(r, (async () => s(r, d))()), B = e.enrichItem ? e.enrichItem(c) : c;
250
- return a.value[r] = B, p(), B;
339
+ const r = e.updateMutation;
340
+ return J({ name: "update", id: a }, () => r(a, t), {}, a, !1);
251
341
  }
252
- function p() {
253
- o.value += 1;
342
+ function Re(a, t, r = {}) {
343
+ return J(a, t, r, a.id, !1);
254
344
  }
255
- async function P(r) {
345
+ async function Ee(a) {
256
346
  if (!e.removeMutation)
257
347
  throw new Error("useStore.remove called but removeMutation is not defined in store options");
258
- const d = e.removeMutation;
259
- await l(r, (async () => d(r))()), delete a.value[r];
260
- for (const s of Object.values(i.value)) {
261
- const c = s.itemIds.indexOf(r);
262
- c !== -1 && (s.itemIds.splice(c, 1), s.total = Math.max(0, s.total - 1));
348
+ const t = e.removeMutation, r = f;
349
+ if (await S({ kind: "mutation", name: "remove", id: a }, () => t(a)), r === f) {
350
+ H(a);
351
+ const d = l++;
352
+ y.set(E(a), d), k.set(E(a), d), O();
353
+ }
354
+ }
355
+ function Pe() {
356
+ f++, n.value = {}, i.value = {}, o.clear(), h.clear(), A.clear(), y.clear(), k.clear(), g.clear();
357
+ for (const a of R)
358
+ a(new aa());
359
+ R.clear(), P();
360
+ }
361
+ async function J(a, t, r, d, p) {
362
+ const B = f, I = l;
363
+ return S({ kind: "mutation", ...a }, async () => {
364
+ const M = await t(), b = e.enrichItem ? e.enrichItem(M) : M;
365
+ if (B !== f)
366
+ return b;
367
+ let C;
368
+ try {
369
+ C = W(b, d);
370
+ } catch (w) {
371
+ throw O(), w;
372
+ }
373
+ if (!p && Te(C, I))
374
+ return b;
375
+ const c = z(C, b);
376
+ return y.set(E(C), l++), O(), c;
377
+ }, r);
378
+ }
379
+ function W(a, t) {
380
+ const r = e.getItemId ? e.getItemId(a) : a.id;
381
+ if (r != null)
382
+ return r;
383
+ if (t !== void 0)
384
+ return t;
385
+ throw new ea(e.getItemId !== void 0);
386
+ }
387
+ async function Q(a, t, r, d) {
388
+ const { mode: p = "parallel", channel: B } = r, I = B ?? de(a);
389
+ if (p !== "parallel" && typeof t != "function")
390
+ throw new Error(
391
+ `useStore.withPending: mode '${p}' requires a thunk, not an already-started promise. Pass \`() => doWork()\` instead of \`doWork()\`.`
392
+ );
393
+ if (p === "dedupe") {
394
+ const c = ze(I);
395
+ if (c)
396
+ return c.promise;
263
397
  }
398
+ const M = p === "queue" ? Ge(I) : [], b = Le(a, I);
399
+ if (d?.(b), p === "queue") {
400
+ const c = t, w = M.length > 0 ? Ue(Promise.all(M.map((m) => m.then(() => {
401
+ }, () => {
402
+ }))).then(() => {
403
+ })).then(c) : (async () => c())();
404
+ b.promise = w, P();
405
+ try {
406
+ const m = await w;
407
+ return se(b), m;
408
+ } catch (m) {
409
+ throw ue(b, m), m;
410
+ }
411
+ }
412
+ const C = typeof t == "function" ? (async () => t())() : t;
413
+ b.promise = C, P();
414
+ try {
415
+ const c = await C;
416
+ return se(b), c;
417
+ } catch (c) {
418
+ throw ue(b, c), c;
419
+ }
420
+ }
421
+ function oe(a, t, r) {
422
+ let d;
423
+ const p = {
424
+ supersededBy: null,
425
+ stale: !1,
426
+ entryToken: null,
427
+ result: new Promise((I) => {
428
+ d = I;
429
+ })
430
+ }, B = a.get(t);
431
+ return B && (B.supersededBy = p, B.entryToken !== null && (o.delete(B.entryToken), P())), a.set(t, p), d(r(p).finally(() => {
432
+ a.get(t) === p && a.delete(t);
433
+ })), p;
434
+ }
435
+ async function G(a) {
436
+ const t = await a.result;
437
+ return a.supersededBy ? G(a.supersededBy) : t;
438
+ }
439
+ function Te(a, t) {
440
+ const r = k.get(E(a));
441
+ return r !== void 0 && r >= t;
442
+ }
443
+ function Y(a, t) {
444
+ const r = y.get(E(a));
445
+ return r !== void 0 && r >= t;
446
+ }
447
+ function Ue(a) {
448
+ return new Promise((t, r) => {
449
+ R.add(r), a.then(() => {
450
+ R.delete(r), t();
451
+ });
452
+ });
264
453
  }
265
- function M() {
266
- t.value = {};
454
+ function X(a) {
455
+ const t = n.value[a];
456
+ if (!(t === void 0 || e.isComplete && !e.isComplete(t)))
457
+ return t;
267
458
  }
268
- function U() {
269
- u += 1, a.value = {}, i.value = {}, t.value = {}, n.value = {};
459
+ function z(a, t) {
460
+ const r = e.mergeItem ? e.mergeItem(n.value[a], t) : t;
461
+ return n.value[a] = r, r;
462
+ }
463
+ function P() {
464
+ u.value++;
465
+ }
466
+ function _() {
467
+ u.value;
468
+ }
469
+ function Le(a, t) {
470
+ const r = a.kind === "view" ? { ...a, params: { ...a.params } } : a, d = de(r);
471
+ r.kind === "mutation" && ee(d, l);
472
+ const p = {
473
+ token: l++,
474
+ key: t,
475
+ address: d,
476
+ scope: r,
477
+ status: "pending",
478
+ promise: null,
479
+ error: null,
480
+ failedAt: null
481
+ };
482
+ return o.set(p.token, p), P(), p;
483
+ }
484
+ function ee(a, t) {
485
+ for (const r of [...o.values()])
486
+ r.status === "error" && r.address === a && r.failedAt !== null && r.failedAt < t && o.delete(r.token);
487
+ }
488
+ function se(a) {
489
+ o.has(a.token) && (o.delete(a.token), ee(a.address, a.token), P());
490
+ }
491
+ function ue(a, t) {
492
+ if (o.has(a.token)) {
493
+ if (a.scope.kind !== "mutation") {
494
+ if (q(t)) {
495
+ o.delete(a.token), P();
496
+ return;
497
+ }
498
+ ee(a.address, l);
499
+ }
500
+ a.status = "error", a.error = t, a.promise = null, a.failedAt = l++, P();
501
+ }
270
502
  }
271
- return { items: a, views: i, errors: t, isPending: g, list: h, reset: U, retrieve: b, getView: m, withPending: l, create: C, update: v, markViewsStale: p, remove: P, clearErrors: M };
503
+ function Ge(a) {
504
+ const t = [];
505
+ for (const r of o.values())
506
+ r.status === "pending" && r.key === a && r.promise && t.push(r.promise);
507
+ return t;
508
+ }
509
+ function ze(a) {
510
+ for (const t of o.values())
511
+ if (t.status === "pending" && t.key === a && t.promise)
512
+ return t;
513
+ }
514
+ return {
515
+ state: s,
516
+ getItem: Ae,
517
+ getItems: ke,
518
+ setItem: Ce,
519
+ removeItem: H,
520
+ markViewsStale: O,
521
+ hasData: Se,
522
+ getErrors: ve,
523
+ getError: Be,
524
+ clearErrors: K,
525
+ isPending: v,
526
+ pendingCount: Z,
527
+ isRetrieving: U,
528
+ isListing: $,
529
+ isMutating: he,
530
+ isQuerying: be,
531
+ withPending: S,
532
+ retrieve: we,
533
+ list: ye,
534
+ getView: N,
535
+ create: Ie,
536
+ update: Me,
537
+ mutate: Re,
538
+ remove: Ee,
539
+ reset: Pe
540
+ };
541
+ }
542
+ function E(e) {
543
+ return String(e);
544
+ }
545
+ function de(e) {
546
+ switch (e.kind) {
547
+ case "item":
548
+ return `item:${String(e.id)}`;
549
+ case "view":
550
+ return `view:${j(e.params)}`;
551
+ case "query":
552
+ return `query:${e.name}:${e.id === void 0 ? "*" : String(e.id)}`;
553
+ case "mutation":
554
+ return `mutation:${e.name}:${e.id === void 0 ? "*" : String(e.id)}:${e.lid ?? "*"}`;
555
+ }
556
+ }
557
+ function D(e, n) {
558
+ if (!n)
559
+ return !0;
560
+ const i = e.scope;
561
+ if (n.kind !== void 0 && n.kind !== i.kind)
562
+ return !1;
563
+ if (n.id !== void 0) {
564
+ const s = i.kind === "view" ? void 0 : i.id;
565
+ if (s === void 0 || E(s) !== E(n.id))
566
+ return !1;
567
+ }
568
+ if (n.params !== void 0) {
569
+ if (i.kind !== "view")
570
+ return !1;
571
+ const s = e.address.slice(5);
572
+ if (n.exact ? s !== re(n.params).join("|") : !ne(s, n.params))
573
+ return !1;
574
+ }
575
+ return n.name !== void 0 && (i.kind !== "mutation" && i.kind !== "query" || i.name !== n.name) || n.lid !== void 0 && (i.kind !== "mutation" || i.lid !== n.lid) ? !1 : n.predicate ? n.predicate(i) : !0;
272
576
  }
273
- function Ae(e, a) {
274
- const i = (t) => {
275
- const n = e.value, o = t.target;
276
- !n || !o || n.contains(o) || a();
577
+ function ne(e, n) {
578
+ if (!n)
579
+ return !0;
580
+ const i = new Set(na(e));
581
+ return re(n).every((s) => i.has(s));
582
+ }
583
+ function na(e) {
584
+ const n = [];
585
+ let i = 0, s = !1;
586
+ for (let o = 0; o < e.length; o++) {
587
+ const u = e[o];
588
+ s && u === "\\" ? o++ : u === '"' ? s = !s : u === "|" && !s && (n.push(e.slice(i, o)), i = o + 1);
589
+ }
590
+ return n.push(e.slice(i)), n;
591
+ }
592
+ function re(e) {
593
+ return Object.entries(e).filter(([, n]) => n !== void 0).sort(([n], [i]) => me(n, i)).map(([n, i]) => `${n}=${ta(i)}`);
594
+ }
595
+ function ta(e) {
596
+ return e instanceof Date ? ge(e) : typeof e == "string" || typeof e == "object" && e !== null ? JSON.stringify(te(e)) : String(e);
597
+ }
598
+ function te(e) {
599
+ return e instanceof Date ? ge(e) : Array.isArray(e) ? e.map(te) : typeof e == "object" && e !== null ? Object.fromEntries(
600
+ Object.entries(e).sort(([n], [i]) => me(n, i)).map(([n, i]) => [n, te(i)])
601
+ ) : e;
602
+ }
603
+ function me(e, n) {
604
+ return e < n ? -1 : e > n ? 1 : 0;
605
+ }
606
+ function ge(e) {
607
+ return Number.isNaN(e.getTime()) ? String(e) : e.toISOString();
608
+ }
609
+ function ia(e) {
610
+ if (typeof e != "object" || e === null)
611
+ return !1;
612
+ const n = e.response;
613
+ if (typeof n != "object" || n === null)
614
+ return !1;
615
+ const i = n.status;
616
+ return i === 404 || i === 410 || i === 403;
617
+ }
618
+ function q(e) {
619
+ return typeof e == "object" && e !== null && e.name === "AbortError";
620
+ }
621
+ function wa(e, n) {
622
+ const i = (s) => {
623
+ const o = e.value, u = s.target;
624
+ !o || !u || o.contains(u) || n();
277
625
  };
278
- F(() => {
626
+ fe(() => {
279
627
  document.addEventListener("click", i);
280
- }), x(() => {
628
+ }), He(() => {
281
629
  document.removeEventListener("click", i);
282
630
  });
283
631
  }
284
- function Ce() {
285
- const { locale: e } = y();
286
- function a(i, t = null) {
287
- const n = re[i.trim().toUpperCase()];
288
- if (!n)
632
+ function Aa() {
633
+ const { locale: e } = V();
634
+ function n(i, s = null) {
635
+ const o = ra[i.trim().toUpperCase()];
636
+ if (!o)
289
637
  throw new Error(`Unknown country code: ${i}`);
290
- if (t && n[t])
291
- return n[t];
292
- if (n[e.value])
293
- return n[e.value];
294
- if (e.value !== "en" && n.en)
295
- return n.en;
638
+ if (s && o[s])
639
+ return o[s];
640
+ if (o[e.value])
641
+ return o[e.value];
642
+ if (e.value !== "en" && o.en)
643
+ return o.en;
296
644
  throw new Error(`Unknown country code: ${i}`);
297
645
  }
298
- return a;
646
+ return n;
299
647
  }
300
- const re = {
648
+ const ra = {
301
649
  AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
302
650
  AE: { en: "United Arab Emirates", fr: "Émirats arabes unis", es: "Emiratos Árabes Unidos", de: "Vereinigte Arabische Emirate", it: "Emirati Arabi Uniti", pt: "Emirados Árabes Unidos", da: "De Forenede Arabiske Emirater" },
303
651
  AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
@@ -435,153 +783,154 @@ const re = {
435
783
  ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
436
784
  ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
437
785
  ZW: { en: "Zimbabwe", fr: "Zimbabwe", es: "Zimbabue", de: "Simbabwe", it: "Zimbabwe", pt: "Zimbábue", da: "Zimbabwe" }
438
- }, we = ({ code: e, message: a, data: i }) => {
439
- const t = a || "An unexpected error occurred", n = J({
786
+ }, ka = ({ code: e, message: n, data: i }) => {
787
+ const s = n || "An unexpected error occurred", o = Fe({
440
788
  statusCode: e,
441
- statusMessage: t,
442
- message: t,
789
+ statusMessage: s,
790
+ message: s,
443
791
  data: i
444
792
  });
445
- throw j(n), n;
446
- }, oe = "ilcJCL_lmpwcEJfSkKND";
447
- function Me() {
448
- const { gtagId: e } = _().public;
793
+ throw qe(o), o;
794
+ }, oa = "ilcJCL_lmpwcEJfSkKND";
795
+ function Ca() {
796
+ const { gtagId: e } = xe().public;
449
797
  return { reportConversion: () => {
450
798
  if (typeof window > "u" || typeof window.gtag > "u" || !e)
451
799
  return;
452
- const i = `${e}/${oe}`;
800
+ const i = `${e}/${oa}`;
453
801
  window.gtag("event", "conversion", {
454
802
  send_to: i
455
803
  });
456
804
  } };
457
805
  }
458
- const H = "https://5509641.hs-sites-eu1.com";
459
- function Se() {
460
- const { locale: e } = y();
461
- return { contactUrl: T(() => e.value === "fr" ? `${H}/contact` : `${H}/${e.value}/contact`) };
806
+ const le = "https://5509641.hs-sites-eu1.com";
807
+ function Sa() {
808
+ const { locale: e } = V();
809
+ return { contactUrl: ie(() => e.value === "fr" ? `${le}/contact` : `${le}/${e.value}/contact`) };
462
810
  }
463
- function Ie() {
464
- async function e(t) {
811
+ function ya() {
812
+ async function e(s) {
465
813
  await Promise.all(
466
- t.map(
467
- (n) => new Promise((o) => {
468
- if (!n) return o(null);
469
- const u = new Image();
470
- u.onload = () => o(null), u.onerror = () => o(null), u.src = n;
814
+ s.map(
815
+ (o) => new Promise((u) => {
816
+ if (!o) return u(null);
817
+ const l = new Image();
818
+ l.onload = () => u(null), l.onerror = () => u(null), l.src = o;
471
819
  })
472
820
  )
473
821
  );
474
822
  }
475
- function a(t, n) {
476
- return n.split(".").reduce((o, u) => o && typeof o == "object" && u in o ? o[u] : "", t) ?? "";
823
+ function n(s, o) {
824
+ return o.split(".").reduce((u, l) => u && typeof u == "object" && l in u ? u[l] : "", s) ?? "";
477
825
  }
478
- function i(t, n, o) {
826
+ function i(s, o, u) {
479
827
  if (import.meta.server)
480
828
  return async (f) => {
481
- t.value = !0;
829
+ s.value = !0;
482
830
  };
483
- const u = $(
484
- `${n}LoadedImageCache`,
831
+ const l = je(
832
+ `${o}LoadedImageCache`,
485
833
  () => ({})
486
834
  );
487
835
  return async (f) => {
488
836
  if (!f) {
489
- t.value = !1;
837
+ s.value = !1;
490
838
  return;
491
839
  }
492
- const g = o.map((m) => a(f, m)), l = `${n}|${g.join("|")}`;
493
- if (u.value[l]) {
494
- t.value = !0;
840
+ const g = u.map((y) => n(f, y)), h = `${o}|${g.join("|")}`;
841
+ if (l.value[h]) {
842
+ s.value = !0;
495
843
  return;
496
844
  }
497
- t.value = !1;
498
- const b = g.filter(Boolean).map(String);
499
- await e(b), u.value[l] = !0, t.value = !0;
845
+ s.value = !1;
846
+ const A = g.filter(Boolean).map(String);
847
+ await e(A), l.value[h] = !0, s.value = !0;
500
848
  };
501
849
  }
502
850
  return i;
503
851
  }
504
- const se = {
852
+ const sa = {
505
853
  en: ["US", "UK"]
506
- }, ue = "FR";
507
- function de(e) {
508
- const a = e.trim().replace("_", "-"), [i, t] = a.split("-");
854
+ }, ua = "FR";
855
+ function da(e) {
856
+ const n = e.trim().replace("_", "-"), [i, s] = n.split("-");
509
857
  return {
510
858
  language: i?.toLowerCase() ?? "",
511
- region: t?.toUpperCase() ?? ""
859
+ region: s?.toUpperCase() ?? ""
512
860
  };
513
861
  }
514
- function K(e) {
862
+ function ce(e) {
515
863
  return e.toString().trim().toUpperCase();
516
864
  }
517
- function Ee() {
518
- function e(a, i) {
865
+ function Ia() {
866
+ function e(n, i) {
519
867
  if (!i.length) return;
520
- const t = i.map(K), n = new Set(t), { language: o, region: u } = de(a), f = [];
521
- u && f.push(u);
522
- const g = se[o];
523
- g?.length && f.push(...g.map(K)), o && f.push(o.toUpperCase()), f.push(ue);
524
- for (const l of f)
525
- if (n.has(l))
526
- return l;
527
- return t[0];
868
+ const s = i.map(ce), o = new Set(s), { language: u, region: l } = da(n), f = [];
869
+ l && f.push(l);
870
+ const g = sa[u];
871
+ g?.length && f.push(...g.map(ce)), u && f.push(u.toUpperCase()), f.push(ua);
872
+ for (const h of f)
873
+ if (o.has(h))
874
+ return h;
875
+ return s[0];
528
876
  }
529
877
  return { getRegionFromLocale: e };
530
878
  }
531
- function Re() {
532
- const { t: e } = y();
533
- function a(i, t) {
534
- const n = e(i), o = [], f = t.map((h) => h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), g = new RegExp(`\\[(${f})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), l = t.reduce((h, C) => (h[C] = !1, h), {});
535
- let b = 0, m = g.exec(n);
536
- for (; m; ) {
537
- const { index: h, 0: C, 1: v, 2: p } = m;
538
- h > b && o.push({ text: n.slice(b, h), ...l }), p && v && o.push({ text: p, ...l, [v]: !0 }), b = h + C.length, m = g.exec(n);
879
+ function Ma() {
880
+ const { t: e } = V();
881
+ function n(i, s) {
882
+ const o = e(i), u = [], f = s.map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), g = new RegExp(`\\[(${f})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), h = s.reduce((k, R) => (k[R] = !1, k), {});
883
+ let A = 0, y = g.exec(o);
884
+ for (; y; ) {
885
+ const { index: k, 0: R, 1: S, 2: v } = y;
886
+ k > A && u.push({ text: o.slice(A, k), ...h }), v && S && u.push({ text: v, ...h, [S]: !0 }), A = k + R.length, y = g.exec(o);
539
887
  }
540
- return b < n.length && o.push({ text: n.slice(b), ...l }), o;
888
+ return A < o.length && u.push({ text: o.slice(A), ...h }), u;
541
889
  }
542
- return { parse: a };
890
+ return { parse: n };
543
891
  }
544
- function ke(e, a, i = 768) {
545
- const t = A(i - 1), n = T(
546
- () => t.value >= i ? a : e
892
+ function Ra(e, n, i = 768) {
893
+ const s = L(i - 1), o = ie(
894
+ () => s.value >= i ? n : e
547
895
  );
548
896
  if (import.meta.client) {
549
- const o = () => {
550
- t.value = window.innerWidth;
897
+ const u = () => {
898
+ s.value = window.innerWidth;
551
899
  };
552
- F(() => {
553
- o(), window.addEventListener("resize", o);
554
- }), Z(() => {
555
- window.removeEventListener("resize", o);
900
+ fe(() => {
901
+ u(), window.addEventListener("resize", u);
902
+ }), Oe(() => {
903
+ window.removeEventListener("resize", u);
556
904
  });
557
905
  }
558
- return { size: n, windowWidth: t };
906
+ return { size: o, windowWidth: s };
559
907
  }
560
- function ye() {
561
- const { locale: e } = y();
562
- function a(i, t = "fr") {
908
+ function Ea() {
909
+ const { locale: e } = V();
910
+ function n(i, s = "fr") {
563
911
  if (!i) return "";
564
- const n = e.value;
565
- return i[n] ?? i[t] ?? "";
912
+ const o = e.value;
913
+ return i[o] ?? i[s] ?? "";
566
914
  }
567
- return a;
915
+ return n;
568
916
  }
569
917
  export {
570
- te as CREATE_PENDING_KEY,
571
- ve as buildUrl,
572
- he as configureHttp,
573
- N as getViewKey,
574
- we as showAndThrowError,
575
- X as useAuthSession,
576
- Ae as useClickOutside,
577
- Ce as useCountriesTranslation,
578
- Me as useGtagConversion,
579
- be as useHttp,
580
- Se as useHubspotContactUrl,
581
- Ie as useImageCacheWatcherCallback,
582
- Ee as useLocaleHelpers,
583
- Re as useParseTranslation,
584
- ke as useResponsiveSize,
585
- Be as useStore,
586
- ye as useTranslate
918
+ ea as MissingItemIdError,
919
+ aa as StoreResetError,
920
+ va as buildUrl,
921
+ ha as configureHttp,
922
+ j as getViewKey,
923
+ ka as showAndThrowError,
924
+ Je as useAuthSession,
925
+ wa as useClickOutside,
926
+ Aa as useCountriesTranslation,
927
+ Ca as useGtagConversion,
928
+ ba as useHttp,
929
+ Sa as useHubspotContactUrl,
930
+ ya as useImageCacheWatcherCallback,
931
+ Ia as useLocaleHelpers,
932
+ Ma as useParseTranslation,
933
+ Ra as useResponsiveSize,
934
+ Ba as useStore,
935
+ Ea as useTranslate
587
936
  };