@choosemycompany/lib 0.9.1 → 0.10.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/dist/index.js CHANGED
@@ -1,291 +1,303 @@
1
- import { mande as K } from "mande";
2
- import { ref as A, computed as y, onMounted as N, onBeforeUnmount as F, onUnmounted as O } from "vue";
3
- import { defineStore as x } from "pinia";
4
- import { useI18n as E } from "vue-i18n";
5
- import { createError as q } from "h3";
6
- import { showError as Z, useRuntimeConfig as V, useState as J } from "nuxt/app";
7
- let I;
8
- function pe(e) {
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) {
9
9
  if (!e.baseUrl)
10
10
  throw new Error("@choosemycompany/lib: configureHttp() needs a non-empty baseUrl");
11
- I = e;
11
+ k = e;
12
12
  }
13
- function H(e) {
14
- if (!I)
13
+ function O(e) {
14
+ if (!k)
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 I.baseUrl;
19
- const a = I.targets ?? {}, i = Object.hasOwn(a, e) ? a[e] : void 0;
20
- if (typeof i != "string" || !i) {
21
- const t = Object.keys(a), n = t.length > 0 ? t.join(", ") : "none";
18
+ if (e === void 0) return k.baseUrl;
19
+ const a = k.targets ?? {}, t = Object.hasOwn(a, e) ? a[e] : void 0;
20
+ if (typeof t != "string" || !t) {
21
+ const i = Object.keys(a), n = i.length > 0 ? i.join(", ") : "none";
22
22
  throw new Error(
23
23
  `@choosemycompany/lib: no HTTP target named "${e}". Declared targets: ${n}.`
24
24
  );
25
25
  }
26
- return i;
26
+ return t;
27
27
  }
28
- const j = "/auth/api/v2/session/tokens", _ = "/auth/api/v2/", $ = "cmc-auth-session-refresh", W = x("cmc-auth-session", () => {
29
- const e = A(!1), a = A(!1), i = A(void 0);
30
- let t, n = 0;
31
- const o = y(() => e.value && !a.value);
32
- function d() {
33
- e.value = !0, a.value = !1, i.value = void 0;
34
- }
35
- function c() {
36
- n += 1, e.value = !1, a.value = !1, i.value = void 0;
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), t = A(void 0);
30
+ let i, n = 0;
31
+ const o = T(() => e.value && !a.value);
32
+ function u() {
33
+ e.value = !0, a.value = !1, t.value = void 0;
37
34
  }
38
35
  function f() {
39
- n += 1, e.value = !1, a.value = !0, i.value = "logout";
36
+ n += 1, e.value = !1, a.value = !1, t.value = void 0;
37
+ }
38
+ function g() {
39
+ n += 1, e.value = !1, a.value = !0, t.value = "logout";
40
40
  }
41
- function p(h) {
42
- n += 1, e.value = !1, a.value = !0, i.value = h;
41
+ function l(B) {
42
+ n += 1, e.value = !1, a.value = !0, t.value = B;
43
43
  }
44
- async function g() {
44
+ async function b() {
45
45
  if (a.value)
46
46
  throw new Error("Session is expired: no refresh will be attempted");
47
- return t ??= v(m).finally(() => {
48
- t = void 0;
49
- }), t;
47
+ return i ??= m(h).finally(() => {
48
+ i = void 0;
49
+ }), i;
50
50
  }
51
- async function v(h) {
52
- const b = globalThis.navigator?.locks;
53
- if (!b) return h();
54
- await b.request($, h);
51
+ async function m(B) {
52
+ const p = globalThis.navigator?.locks;
53
+ if (!p) return B();
54
+ await p.request(Y, B);
55
55
  }
56
- async function m() {
57
- const h = n, b = () => h !== n, R = new URL(j, H()).href;
58
- let r;
56
+ async function h() {
57
+ const B = n, p = () => B !== n, P = new URL(W, O()).href;
58
+ let M;
59
59
  try {
60
- r = await fetch(R, {
60
+ M = await fetch(P, {
61
61
  method: "POST",
62
62
  credentials: "include"
63
63
  });
64
- } catch (u) {
65
- throw b() || C(), u;
64
+ } catch (U) {
65
+ throw p() || C(), U;
66
66
  }
67
- if (!r.ok)
68
- throw b() || (r.status === 401 ? p(e.value ? "refresh-rejected" : "no-session") : C()), new Error(`Token refresh failed with status ${r.status}`);
69
- if (b())
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())
70
70
  throw new Error("Session was dropped while the refresh was in flight");
71
- d();
71
+ u();
72
72
  }
73
73
  function C() {
74
- i.value = "refresh-unreachable";
74
+ t.value = "refresh-unreachable";
75
75
  }
76
76
  return {
77
77
  isOpen: e,
78
78
  isExpired: a,
79
- expiryReason: i,
79
+ expiryReason: t,
80
80
  isAuthenticated: o,
81
- open: d,
82
- expire: p,
83
- clear: c,
84
- logout: f,
85
- refresh: g
81
+ open: u,
82
+ expire: l,
83
+ clear: f,
84
+ logout: g,
85
+ refresh: b
86
86
  };
87
87
  });
88
- function Q() {
88
+ function ee() {
89
89
  return import.meta.server || typeof document > "u";
90
90
  }
91
- function Y(e) {
92
- return (typeof e == "string" ? e : e instanceof URL ? e.href : e.url).includes(_);
91
+ function ae(e) {
92
+ return (typeof e == "string" ? e : e instanceof URL ? e.href : e.url).includes(Q);
93
93
  }
94
- function X() {
94
+ function ne() {
95
95
  return async (e, a) => {
96
- if (Q()) return fetch(e, a);
97
- const i = await fetch(e, a);
98
- if (i.status !== 401 || Y(e) || new Headers(a?.headers).has("Authorization")) return i;
99
- let t;
96
+ if (ee()) return fetch(e, a);
97
+ const t = await fetch(e, a);
98
+ if (t.status !== 401 || ae(e) || new Headers(a?.headers).has("Authorization")) return t;
99
+ let i;
100
100
  try {
101
- t = W();
101
+ i = X();
102
102
  } catch {
103
- return i;
103
+ return t;
104
104
  }
105
- if (t.isExpired) return i;
105
+ if (i.isExpired) return t;
106
106
  try {
107
- await t.refresh();
107
+ await i.refresh();
108
108
  } catch (n) {
109
- return t.isExpired || console.warn("[cmc-lib] token refresh failed, returning the original 401", n), i;
109
+ return i.isExpired || console.warn("[cmc-lib] token refresh failed, returning the original 401", n), t;
110
110
  }
111
111
  return fetch(e, a);
112
112
  };
113
113
  }
114
- function ge(e) {
115
- const a = K(H(e), {
114
+ function be(e) {
115
+ const a = q(O(e), {
116
116
  headers: {}
117
- }, X());
118
- function i(n) {
117
+ }, ne());
118
+ function t(n) {
119
119
  a.options.headers = {
120
120
  ...a.options.headers ?? {},
121
121
  Authorization: `Bearer ${n}`
122
122
  };
123
123
  }
124
- function t() {
124
+ function i() {
125
125
  a.options.headers && delete a.options.headers.Authorization;
126
126
  }
127
- return { http: a, setToken: i, clearToken: t };
127
+ return { http: a, setToken: t, clearToken: i };
128
128
  }
129
- function me(e, a) {
130
- return e.replace(ee, (i, t) => {
131
- const n = Object.hasOwn(a, t) ? a[t] : void 0;
129
+ function Be(e, a) {
130
+ return e.replace(ie, (t, i) => {
131
+ const n = Object.hasOwn(a, i) ? a[i] : void 0;
132
132
  if (typeof n != "string" && typeof n != "number")
133
- throw new Error(`Missing URL parameter "${t}" for template "${e}"`);
133
+ throw new Error(`Missing URL parameter "${i}" for template "${e}"`);
134
134
  return encodeURIComponent(String(n));
135
135
  });
136
136
  }
137
- const ee = /\{(\w+)\}/g;
138
- function G(e) {
139
- return Object.entries(e).sort(([a], [i]) => a.localeCompare(i)).map(([a, i]) => `${a}=${i}`).join("|");
137
+ const ie = /\{(\w+)\}/g;
138
+ function N(e) {
139
+ return Object.entries(e).sort(([a], [t]) => a.localeCompare(t)).map(([a, t]) => `${a}=${t}`).join("|");
140
140
  }
141
- const ae = "create";
142
- function he(e) {
143
- const a = A({}), i = A({}), t = A({}), n = A({}), o = A(0), d = e.getItemId ?? ((r) => {
144
- const u = r.id;
145
- if (u === void 0)
141
+ const te = "create";
142
+ function ve(e) {
143
+ const a = A({}), t = A({}), i = 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)
146
148
  throw new Error(
147
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."
148
150
  );
149
- return u;
151
+ return d;
150
152
  });
151
- function c(r) {
153
+ function g(r) {
152
154
  return !!n.value[r];
153
155
  }
154
- async function f(r, u) {
155
- n.value[r] = u;
156
+ async function l(r, d) {
157
+ n.value[r] = d;
156
158
  try {
157
- const s = await u;
158
- return delete t.value[r], s;
159
+ const s = await d;
160
+ return delete i.value[r], s;
159
161
  } catch (s) {
160
- throw t.value[r] = s, s;
162
+ throw i.value[r] = s, s;
161
163
  } finally {
162
- n.value[r] === u && delete n.value[r];
164
+ n.value[r] === d && delete n.value[r];
163
165
  }
164
166
  }
165
- async function p(r, u = {}) {
167
+ async function b(r, d = {}) {
166
168
  if (!e.fetchOne)
167
169
  throw new Error("useStore.retrieve called but fetchOne is not defined in store options");
168
- const { force: s = !1 } = u;
170
+ const { force: s = !1 } = d;
169
171
  if (a.value[r] && !s)
170
172
  return a.value[r];
171
- const l = n.value[r];
172
- if (l)
173
- return l;
174
- const B = e.fetchOne, S = (async () => {
173
+ const c = n.value[r];
174
+ if (c)
175
+ return c;
176
+ const v = e.fetchOne, S = (async () => {
177
+ const I = u;
175
178
  try {
176
- const w = await B(r), k = e.enrichItem ? e.enrichItem(w) : w;
177
- return a.value[r] = k, delete t.value[r], a.value[r];
178
- } catch (w) {
179
- t.value[r] = w;
179
+ const E = await v(r);
180
+ if (I !== u)
181
+ return;
182
+ const R = e.enrichItem ? e.enrichItem(E) : E;
183
+ return a.value[r] = R, delete i.value[r], a.value[r];
184
+ } catch (E) {
185
+ I === u && (i.value[r] = E);
180
186
  return;
181
187
  } finally {
182
- delete n.value[r];
188
+ I === u && delete n.value[r];
183
189
  }
184
190
  })();
185
191
  return n.value[r] = S, S;
186
192
  }
187
- function g(r) {
188
- const u = G(r), s = i.value[u];
193
+ function m(r) {
194
+ const d = N(r), s = t.value[d];
189
195
  if (s)
190
196
  return {
191
- items: s.itemIds.map((l) => a.value[l]).filter((l) => l !== void 0),
197
+ items: s.itemIds.map((c) => a.value[c]).filter((c) => c !== void 0),
192
198
  total: s.total,
193
199
  hasMore: s.hasMore,
194
200
  page: s.page,
195
201
  limit: s.limit
196
202
  };
197
203
  }
198
- async function v(r, u = {}) {
204
+ async function h(r, d = {}) {
199
205
  if (!e.fetchPage)
200
206
  throw new Error("useStore.list called but fetchPage is not defined in store options");
201
- const s = G(r), { force: l = !1 } = u;
202
- if (i.value[s]?.revision === o.value && !l)
203
- return g(r);
204
- const B = n.value[s];
205
- if (B)
206
- return await B, g(r);
207
- const S = e.fetchPage, w = (async () => {
208
- const k = o.value;
207
+ const s = N(r), { force: c = !1 } = d;
208
+ if (t.value[s]?.revision === o.value && !c)
209
+ return m(r);
210
+ const v = n.value[s];
211
+ if (v)
212
+ return await v, m(r);
213
+ const S = e.fetchPage, I = (async () => {
214
+ const E = o.value, R = u;
209
215
  try {
210
- const M = await S(r), P = [];
211
- for (const U of M.items) {
212
- const T = e.enrichItem ? e.enrichItem(U) : U, L = d(T);
213
- a.value[L] = T, P.push(L);
216
+ const w = await S(r);
217
+ if (R !== u)
218
+ 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);
214
223
  }
215
- i.value[s] = {
216
- itemIds: P,
217
- total: M.total,
218
- hasMore: M.hasMore,
219
- page: M.page,
220
- limit: M.limit,
221
- revision: k
222
- }, delete t.value[s];
223
- } catch (M) {
224
- t.value[s] = M;
224
+ t.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 i.value[s];
232
+ } catch (w) {
233
+ R === u && (i.value[s] = w);
225
234
  } finally {
226
- delete n.value[s];
235
+ R === u && delete n.value[s];
227
236
  }
228
237
  })();
229
- return n.value[s] = w, await w, g(r);
238
+ return n.value[s] = I, await I, m(r);
230
239
  }
231
- async function m(r, u = ae) {
240
+ async function C(r, d = te) {
232
241
  if (!e.createMutation)
233
242
  throw new Error("useStore.create called but createMutation is not defined in store options");
234
- const s = e.createMutation, l = await f(u, (async () => s(r))()), B = e.enrichItem ? e.enrichItem(l) : l, S = d(B);
235
- return a.value[S] = B, i.value = {}, B;
243
+ const s = e.createMutation, c = await l(d, (async () => s(r))()), v = e.enrichItem ? e.enrichItem(c) : c, S = f(v);
244
+ return a.value[S] = v, p(), v;
236
245
  }
237
- async function C(r, u) {
246
+ async function B(r, d) {
238
247
  if (!e.updateMutation)
239
248
  throw new Error("useStore.update called but updateMutation is not defined in store options");
240
- const s = e.updateMutation, l = await f(r, (async () => s(r, u))()), B = e.enrichItem ? e.enrichItem(l) : l;
241
- return a.value[r] = B, o.value += 1, B;
249
+ const s = e.updateMutation, c = await l(r, (async () => s(r, d))()), v = e.enrichItem ? e.enrichItem(c) : c;
250
+ return a.value[r] = v, p(), v;
251
+ }
252
+ function p() {
253
+ o.value += 1;
242
254
  }
243
- async function h(r) {
255
+ async function P(r) {
244
256
  if (!e.removeMutation)
245
257
  throw new Error("useStore.remove called but removeMutation is not defined in store options");
246
- const u = e.removeMutation;
247
- await f(r, (async () => u(r))()), delete a.value[r];
248
- for (const s of Object.values(i.value)) {
249
- const l = s.itemIds.indexOf(r);
250
- l !== -1 && (s.itemIds.splice(l, 1), s.total = Math.max(0, s.total - 1));
258
+ const d = e.removeMutation;
259
+ await l(r, (async () => d(r))()), delete a.value[r];
260
+ for (const s of Object.values(t.value)) {
261
+ const c = s.itemIds.indexOf(r);
262
+ c !== -1 && (s.itemIds.splice(c, 1), s.total = Math.max(0, s.total - 1));
251
263
  }
252
264
  }
253
- function b() {
254
- t.value = {};
265
+ function M() {
266
+ i.value = {};
255
267
  }
256
- function R() {
257
- a.value = {}, i.value = {}, t.value = {}, n.value = {};
268
+ function U() {
269
+ u += 1, a.value = {}, t.value = {}, i.value = {}, n.value = {};
258
270
  }
259
- return { items: a, views: i, errors: t, isPending: c, list: v, reset: R, retrieve: p, getView: g, withPending: f, create: m, update: C, remove: h, clearErrors: b };
271
+ return { items: a, views: t, errors: i, isPending: g, list: h, reset: U, retrieve: b, getView: m, withPending: l, create: C, update: B, markViewsStale: p, remove: P, clearErrors: M };
260
272
  }
261
- function be(e, a) {
262
- const i = (t) => {
263
- const n = e.value, o = t.target;
273
+ function Ae(e, a) {
274
+ const t = (i) => {
275
+ const n = e.value, o = i.target;
264
276
  !n || !o || n.contains(o) || a();
265
277
  };
266
- N(() => {
267
- document.addEventListener("click", i);
268
- }), F(() => {
269
- document.removeEventListener("click", i);
278
+ F(() => {
279
+ document.addEventListener("click", t);
280
+ }), x(() => {
281
+ document.removeEventListener("click", t);
270
282
  });
271
283
  }
272
- function Be() {
273
- const { locale: e } = E();
274
- function a(i, t = null) {
275
- const n = ne[i.trim().toUpperCase()];
284
+ function Ce() {
285
+ const { locale: e } = y();
286
+ function a(t, i = null) {
287
+ const n = re[t.trim().toUpperCase()];
276
288
  if (!n)
277
- throw new Error(`Unknown country code: ${i}`);
278
- if (t && n[t])
279
- return n[t];
289
+ throw new Error(`Unknown country code: ${t}`);
290
+ if (i && n[i])
291
+ return n[i];
280
292
  if (n[e.value])
281
293
  return n[e.value];
282
294
  if (e.value !== "en" && n.en)
283
295
  return n.en;
284
- throw new Error(`Unknown country code: ${i}`);
296
+ throw new Error(`Unknown country code: ${t}`);
285
297
  }
286
298
  return a;
287
299
  }
288
- const ne = {
300
+ const re = {
289
301
  AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
290
302
  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" },
291
303
  AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
@@ -423,153 +435,153 @@ const ne = {
423
435
  ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
424
436
  ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
425
437
  ZW: { en: "Zimbabwe", fr: "Zimbabwe", es: "Zimbabue", de: "Simbabwe", it: "Zimbabwe", pt: "Zimbábue", da: "Zimbabwe" }
426
- }, ve = ({ code: e, message: a, data: i }) => {
427
- const t = a || "An unexpected error occurred", n = q({
438
+ }, we = ({ code: e, message: a, data: t }) => {
439
+ const i = a || "An unexpected error occurred", n = J({
428
440
  statusCode: e,
429
- statusMessage: t,
430
- message: t,
431
- data: i
441
+ statusMessage: i,
442
+ message: i,
443
+ data: t
432
444
  });
433
- throw Z(n), n;
434
- }, ie = "ilcJCL_lmpwcEJfSkKND";
435
- function Ae() {
436
- const { gtagId: e } = V().public;
445
+ throw j(n), n;
446
+ }, oe = "ilcJCL_lmpwcEJfSkKND";
447
+ function Me() {
448
+ const { gtagId: e } = _().public;
437
449
  return { reportConversion: () => {
438
450
  if (typeof window > "u" || typeof window.gtag > "u" || !e)
439
451
  return;
440
- const i = `${e}/${ie}`;
452
+ const t = `${e}/${oe}`;
441
453
  window.gtag("event", "conversion", {
442
- send_to: i
454
+ send_to: t
443
455
  });
444
456
  } };
445
457
  }
446
- const z = "https://5509641.hs-sites-eu1.com";
447
- function Ce() {
448
- const { locale: e } = E();
449
- return { contactUrl: y(() => e.value === "fr" ? `${z}/contact` : `${z}/${e.value}/contact`) };
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`) };
450
462
  }
451
- function we() {
452
- async function e(t) {
463
+ function Ie() {
464
+ async function e(i) {
453
465
  await Promise.all(
454
- t.map(
466
+ i.map(
455
467
  (n) => new Promise((o) => {
456
468
  if (!n) return o(null);
457
- const d = new Image();
458
- d.onload = () => o(null), d.onerror = () => o(null), d.src = n;
469
+ const u = new Image();
470
+ u.onload = () => o(null), u.onerror = () => o(null), u.src = n;
459
471
  })
460
472
  )
461
473
  );
462
474
  }
463
- function a(t, n) {
464
- return n.split(".").reduce((o, d) => o && typeof o == "object" && d in o ? o[d] : "", t) ?? "";
475
+ function a(i, n) {
476
+ return n.split(".").reduce((o, u) => o && typeof o == "object" && u in o ? o[u] : "", i) ?? "";
465
477
  }
466
- function i(t, n, o) {
478
+ function t(i, n, o) {
467
479
  if (import.meta.server)
468
- return async (c) => {
469
- t.value = !0;
480
+ return async (f) => {
481
+ i.value = !0;
470
482
  };
471
- const d = J(
483
+ const u = $(
472
484
  `${n}LoadedImageCache`,
473
485
  () => ({})
474
486
  );
475
- return async (c) => {
476
- if (!c) {
477
- t.value = !1;
487
+ return async (f) => {
488
+ if (!f) {
489
+ i.value = !1;
478
490
  return;
479
491
  }
480
- const f = o.map((v) => a(c, v)), p = `${n}|${f.join("|")}`;
481
- if (d.value[p]) {
482
- t.value = !0;
492
+ const g = o.map((m) => a(f, m)), l = `${n}|${g.join("|")}`;
493
+ if (u.value[l]) {
494
+ i.value = !0;
483
495
  return;
484
496
  }
485
- t.value = !1;
486
- const g = f.filter(Boolean).map(String);
487
- await e(g), d.value[p] = !0, t.value = !0;
497
+ i.value = !1;
498
+ const b = g.filter(Boolean).map(String);
499
+ await e(b), u.value[l] = !0, i.value = !0;
488
500
  };
489
501
  }
490
- return i;
502
+ return t;
491
503
  }
492
- const te = {
504
+ const se = {
493
505
  en: ["US", "UK"]
494
- }, re = "FR";
495
- function oe(e) {
496
- const a = e.trim().replace("_", "-"), [i, t] = a.split("-");
506
+ }, ue = "FR";
507
+ function de(e) {
508
+ const a = e.trim().replace("_", "-"), [t, i] = a.split("-");
497
509
  return {
498
- language: i?.toLowerCase() ?? "",
499
- region: t?.toUpperCase() ?? ""
510
+ language: t?.toLowerCase() ?? "",
511
+ region: i?.toUpperCase() ?? ""
500
512
  };
501
513
  }
502
- function D(e) {
514
+ function K(e) {
503
515
  return e.toString().trim().toUpperCase();
504
516
  }
505
- function Me() {
506
- function e(a, i) {
507
- if (!i.length) return;
508
- const t = i.map(D), n = new Set(t), { language: o, region: d } = oe(a), c = [];
509
- d && c.push(d);
510
- const f = te[o];
511
- f?.length && c.push(...f.map(D)), o && c.push(o.toUpperCase()), c.push(re);
512
- for (const p of c)
513
- if (n.has(p))
514
- return p;
515
- return t[0];
517
+ function Ee() {
518
+ function e(a, t) {
519
+ if (!t.length) return;
520
+ const i = t.map(K), n = new Set(i), { 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 i[0];
516
528
  }
517
529
  return { getRegionFromLocale: e };
518
530
  }
519
- function Se() {
520
- const { t: e } = E();
521
- function a(i, t) {
522
- const n = e(i), o = [], c = t.map((m) => m.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), f = new RegExp(`\\[(${c})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), p = t.reduce((m, C) => (m[C] = !1, m), {});
523
- let g = 0, v = f.exec(n);
524
- for (; v; ) {
525
- const { index: m, 0: C, 1: h, 2: b } = v;
526
- m > g && o.push({ text: n.slice(g, m), ...p }), b && h && o.push({ text: b, ...p, [h]: !0 }), g = m + C.length, v = f.exec(n);
531
+ function Re() {
532
+ const { t: e } = y();
533
+ function a(t, i) {
534
+ const n = e(t), o = [], f = i.map((h) => h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), g = new RegExp(`\\[(${f})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), l = i.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: B, 2: p } = m;
538
+ h > b && o.push({ text: n.slice(b, h), ...l }), p && B && o.push({ text: p, ...l, [B]: !0 }), b = h + C.length, m = g.exec(n);
527
539
  }
528
- return g < n.length && o.push({ text: n.slice(g), ...p }), o;
540
+ return b < n.length && o.push({ text: n.slice(b), ...l }), o;
529
541
  }
530
542
  return { parse: a };
531
543
  }
532
- function Ie(e, a, i = 768) {
533
- const t = A(i - 1), n = y(
534
- () => t.value >= i ? a : e
544
+ function ke(e, a, t = 768) {
545
+ const i = A(t - 1), n = T(
546
+ () => i.value >= t ? a : e
535
547
  );
536
548
  if (import.meta.client) {
537
549
  const o = () => {
538
- t.value = window.innerWidth;
550
+ i.value = window.innerWidth;
539
551
  };
540
- N(() => {
552
+ F(() => {
541
553
  o(), window.addEventListener("resize", o);
542
- }), O(() => {
554
+ }), Z(() => {
543
555
  window.removeEventListener("resize", o);
544
556
  });
545
557
  }
546
- return { size: n, windowWidth: t };
558
+ return { size: n, windowWidth: i };
547
559
  }
548
- function Ee() {
549
- const { locale: e } = E();
550
- function a(i, t = "fr") {
551
- if (!i) return "";
560
+ function ye() {
561
+ const { locale: e } = y();
562
+ function a(t, i = "fr") {
563
+ if (!t) return "";
552
564
  const n = e.value;
553
- return i[n] ?? i[t] ?? "";
565
+ return t[n] ?? t[i] ?? "";
554
566
  }
555
567
  return a;
556
568
  }
557
569
  export {
558
- ae as CREATE_PENDING_KEY,
559
- me as buildUrl,
560
- pe as configureHttp,
561
- G as getViewKey,
562
- ve as showAndThrowError,
563
- W as useAuthSession,
564
- be as useClickOutside,
565
- Be as useCountriesTranslation,
566
- Ae as useGtagConversion,
567
- ge as useHttp,
568
- Ce as useHubspotContactUrl,
569
- we as useImageCacheWatcherCallback,
570
- Me as useLocaleHelpers,
571
- Se as useParseTranslation,
572
- Ie as useResponsiveSize,
573
- he as useStore,
574
- Ee as useTranslate
570
+ te as CREATE_PENDING_KEY,
571
+ Be 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
+ ve as useStore,
586
+ ye as useTranslate
575
587
  };
@@ -7,9 +7,9 @@ type ViewKey = string;
7
7
  * the single source of truth for item data, avoiding the duplication issue
8
8
  * where a view's `items[]` could drift from `items.value[id]` after a re-fetch.
9
9
  *
10
- * `revision` is the store's revision when the page was requested: an `update()`
11
- * landing after that request makes the view stale, and the next `list()` on it
12
- * refetches the page.
10
+ * `revision` is the store's revision when the page was requested: a `create()`,
11
+ * an `update()` or a `markViewsStale()` landing after that request makes the
12
+ * view stale, and the next `list()` on it refetches the page.
13
13
  */
14
14
  type StoredView<Id extends IdKey> = ViewKeyParams & {
15
15
  itemIds: Id[];
@@ -60,10 +60,12 @@ export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePa
60
60
  getView: (params: Params) => View<Item> | undefined;
61
61
  /** Wraps an arbitrary promise in the store's pending + error lifecycle under `key`. */
62
62
  withPending: <T>(key: ViewKey | Id, promise: Promise<T>) => Promise<T>;
63
- /** Calls `createMutation`, inserts the item into `items`, and invalidates all views. */
63
+ /** Calls `createMutation` (wrapped in `withPending(key)`), inserts the item into `items`, and marks every view stale. */
64
64
  create: (payload: CreatePayload, key?: ViewKey | Id) => Promise<Item>;
65
65
  /** Calls `updateMutation` (wrapped in `withPending(id)`), replaces `items[id]`, and marks every view stale. */
66
66
  update: (id: Id, patch: UpdatePatch) => Promise<Item>;
67
+ /** Marks every cached view stale: `getView()` keeps serving it, the next `list()` on it refetches the page. */
68
+ markViewsStale: () => void;
67
69
  /** Calls `removeMutation` (wrapped in `withPending(id)`), deletes `items[id]`, removes id from every view. */
68
70
  remove: (id: Id) => Promise<void>;
69
71
  /** Clears every entry from `errors`. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@choosemycompany/lib",
3
3
  "description": "Shared composables, stores and types for ChooseMyCompany front apps",
4
- "version": "0.9.1",
4
+ "version": "0.10.1",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "packageManager": "pnpm@10.17.0",