@choosemycompany/lib 0.9.1 → 0.10.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 +200 -188
- package/dist/store/useStore.d.ts +4 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { mande as
|
|
2
|
-
import { ref as A, computed as
|
|
3
|
-
import { defineStore as
|
|
4
|
-
import { useI18n as
|
|
5
|
-
import { createError as
|
|
6
|
-
import { showError as
|
|
7
|
-
let
|
|
8
|
-
function
|
|
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
|
-
|
|
11
|
+
k = e;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
if (!
|
|
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
|
|
19
|
-
const a =
|
|
18
|
+
if (e === void 0) return k.baseUrl;
|
|
19
|
+
const a = k.targets ?? {}, i = Object.hasOwn(a, e) ? a[e] : void 0;
|
|
20
20
|
if (typeof i != "string" || !i) {
|
|
21
21
|
const t = Object.keys(a), n = t.length > 0 ? t.join(", ") : "none";
|
|
22
22
|
throw new Error(
|
|
@@ -25,50 +25,50 @@ function H(e) {
|
|
|
25
25
|
}
|
|
26
26
|
return i;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const W = "/auth/api/v2/session/tokens", Q = "/auth/api/v2/", Y = "cmc-auth-session-refresh", X = V("cmc-auth-session", () => {
|
|
29
29
|
const e = A(!1), a = A(!1), i = A(void 0);
|
|
30
30
|
let t, n = 0;
|
|
31
|
-
const o =
|
|
32
|
-
function
|
|
31
|
+
const o = T(() => e.value && !a.value);
|
|
32
|
+
function u() {
|
|
33
33
|
e.value = !0, a.value = !1, i.value = void 0;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function f() {
|
|
36
36
|
n += 1, e.value = !1, a.value = !1, i.value = void 0;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function g() {
|
|
39
39
|
n += 1, e.value = !1, a.value = !0, i.value = "logout";
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
n += 1, e.value = !1, a.value = !0, i.value =
|
|
41
|
+
function l(v) {
|
|
42
|
+
n += 1, e.value = !1, a.value = !0, i.value = v;
|
|
43
43
|
}
|
|
44
|
-
async function
|
|
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 ??=
|
|
47
|
+
return t ??= m(h).finally(() => {
|
|
48
48
|
t = void 0;
|
|
49
49
|
}), t;
|
|
50
50
|
}
|
|
51
|
-
async function v
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
54
|
-
await
|
|
51
|
+
async function m(v) {
|
|
52
|
+
const p = globalThis.navigator?.locks;
|
|
53
|
+
if (!p) return v();
|
|
54
|
+
await p.request(Y, v);
|
|
55
55
|
}
|
|
56
|
-
async function
|
|
57
|
-
const
|
|
58
|
-
let
|
|
56
|
+
async function h() {
|
|
57
|
+
const v = n, p = () => v !== n, P = new URL(W, O()).href;
|
|
58
|
+
let M;
|
|
59
59
|
try {
|
|
60
|
-
|
|
60
|
+
M = await fetch(P, {
|
|
61
61
|
method: "POST",
|
|
62
62
|
credentials: "include"
|
|
63
63
|
});
|
|
64
|
-
} catch (
|
|
65
|
-
throw
|
|
64
|
+
} catch (U) {
|
|
65
|
+
throw p() || C(), U;
|
|
66
66
|
}
|
|
67
|
-
if (!
|
|
68
|
-
throw
|
|
69
|
-
if (
|
|
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
|
-
|
|
71
|
+
u();
|
|
72
72
|
}
|
|
73
73
|
function C() {
|
|
74
74
|
i.value = "refresh-unreachable";
|
|
@@ -78,27 +78,27 @@ const j = "/auth/api/v2/session/tokens", _ = "/auth/api/v2/", $ = "cmc-auth-sess
|
|
|
78
78
|
isExpired: a,
|
|
79
79
|
expiryReason: i,
|
|
80
80
|
isAuthenticated: o,
|
|
81
|
-
open:
|
|
82
|
-
expire:
|
|
83
|
-
clear:
|
|
84
|
-
logout:
|
|
85
|
-
refresh:
|
|
81
|
+
open: u,
|
|
82
|
+
expire: l,
|
|
83
|
+
clear: f,
|
|
84
|
+
logout: g,
|
|
85
|
+
refresh: b
|
|
86
86
|
};
|
|
87
87
|
});
|
|
88
|
-
function
|
|
88
|
+
function ee() {
|
|
89
89
|
return import.meta.server || typeof document > "u";
|
|
90
90
|
}
|
|
91
|
-
function
|
|
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
|
|
94
|
+
function ne() {
|
|
95
95
|
return async (e, a) => {
|
|
96
|
-
if (
|
|
96
|
+
if (ee()) return fetch(e, a);
|
|
97
97
|
const i = await fetch(e, a);
|
|
98
|
-
if (i.status !== 401 ||
|
|
98
|
+
if (i.status !== 401 || ae(e) || new Headers(a?.headers).has("Authorization")) return i;
|
|
99
99
|
let t;
|
|
100
100
|
try {
|
|
101
|
-
t =
|
|
101
|
+
t = X();
|
|
102
102
|
} catch {
|
|
103
103
|
return i;
|
|
104
104
|
}
|
|
@@ -111,10 +111,10 @@ function X() {
|
|
|
111
111
|
return fetch(e, a);
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
const a =
|
|
114
|
+
function be(e) {
|
|
115
|
+
const a = q(O(e), {
|
|
116
116
|
headers: {}
|
|
117
|
-
},
|
|
117
|
+
}, ne());
|
|
118
118
|
function i(n) {
|
|
119
119
|
a.options.headers = {
|
|
120
120
|
...a.options.headers ?? {},
|
|
@@ -126,153 +126,165 @@ function ge(e) {
|
|
|
126
126
|
}
|
|
127
127
|
return { http: a, setToken: i, clearToken: t };
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
return e.replace(
|
|
129
|
+
function ve(e, a) {
|
|
130
|
+
return e.replace(ie, (i, t) => {
|
|
131
131
|
const n = Object.hasOwn(a, t) ? a[t] : void 0;
|
|
132
132
|
if (typeof n != "string" && typeof n != "number")
|
|
133
133
|
throw new Error(`Missing URL parameter "${t}" for template "${e}"`);
|
|
134
134
|
return encodeURIComponent(String(n));
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
function
|
|
137
|
+
const ie = /\{(\w+)\}/g;
|
|
138
|
+
function N(e) {
|
|
139
139
|
return Object.entries(e).sort(([a], [i]) => a.localeCompare(i)).map(([a, i]) => `${a}=${i}`).join("|");
|
|
140
140
|
}
|
|
141
|
-
const
|
|
142
|
-
function
|
|
143
|
-
const a = A({}), i = A({}), t = A({}), n = A({}), o = A(0)
|
|
144
|
-
|
|
145
|
-
|
|
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)
|
|
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
|
|
151
|
+
return d;
|
|
150
152
|
});
|
|
151
|
-
function
|
|
153
|
+
function g(r) {
|
|
152
154
|
return !!n.value[r];
|
|
153
155
|
}
|
|
154
|
-
async function
|
|
155
|
-
n.value[r] =
|
|
156
|
+
async function l(r, d) {
|
|
157
|
+
n.value[r] = d;
|
|
156
158
|
try {
|
|
157
|
-
const s = await
|
|
159
|
+
const s = await d;
|
|
158
160
|
return delete t.value[r], s;
|
|
159
161
|
} catch (s) {
|
|
160
162
|
throw t.value[r] = s, s;
|
|
161
163
|
} finally {
|
|
162
|
-
n.value[r] ===
|
|
164
|
+
n.value[r] === d && delete n.value[r];
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
|
-
async function
|
|
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 } =
|
|
170
|
+
const { force: s = !1 } = d;
|
|
169
171
|
if (a.value[r] && !s)
|
|
170
172
|
return a.value[r];
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
return
|
|
173
|
+
const c = n.value[r];
|
|
174
|
+
if (c)
|
|
175
|
+
return c;
|
|
174
176
|
const B = e.fetchOne, S = (async () => {
|
|
177
|
+
const I = u;
|
|
175
178
|
try {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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);
|
|
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
|
|
188
|
-
const
|
|
193
|
+
function m(r) {
|
|
194
|
+
const d = N(r), s = i.value[d];
|
|
189
195
|
if (s)
|
|
190
196
|
return {
|
|
191
|
-
items: s.itemIds.map((
|
|
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
|
|
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 =
|
|
202
|
-
if (i.value[s]?.revision === o.value && !
|
|
203
|
-
return
|
|
207
|
+
const s = N(r), { force: c = !1 } = d;
|
|
208
|
+
if (i.value[s]?.revision === o.value && !c)
|
|
209
|
+
return m(r);
|
|
204
210
|
const B = n.value[s];
|
|
205
211
|
if (B)
|
|
206
|
-
return await B,
|
|
207
|
-
const S = e.fetchPage,
|
|
208
|
-
const
|
|
212
|
+
return await B, m(r);
|
|
213
|
+
const S = e.fetchPage, I = (async () => {
|
|
214
|
+
const E = o.value, R = u;
|
|
209
215
|
try {
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
224
|
i.value[s] = {
|
|
216
|
-
itemIds:
|
|
217
|
-
total:
|
|
218
|
-
hasMore:
|
|
219
|
-
page:
|
|
220
|
-
limit:
|
|
221
|
-
revision:
|
|
225
|
+
itemIds: L,
|
|
226
|
+
total: w.total,
|
|
227
|
+
hasMore: w.hasMore,
|
|
228
|
+
page: w.page,
|
|
229
|
+
limit: w.limit,
|
|
230
|
+
revision: E
|
|
222
231
|
}, delete t.value[s];
|
|
223
|
-
} catch (
|
|
224
|
-
t.value[s] =
|
|
232
|
+
} catch (w) {
|
|
233
|
+
R === u && (t.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] =
|
|
238
|
+
return n.value[s] = I, await I, m(r);
|
|
230
239
|
}
|
|
231
|
-
async function
|
|
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,
|
|
235
|
-
return a.value[S] = B, i.value = {}, B;
|
|
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;
|
|
236
245
|
}
|
|
237
|
-
async function
|
|
246
|
+
async function v(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,
|
|
241
|
-
return a.value[r] = B,
|
|
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;
|
|
251
|
+
}
|
|
252
|
+
function p() {
|
|
253
|
+
o.value += 1;
|
|
242
254
|
}
|
|
243
|
-
async function
|
|
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
|
|
247
|
-
await
|
|
258
|
+
const d = e.removeMutation;
|
|
259
|
+
await l(r, (async () => d(r))()), delete a.value[r];
|
|
248
260
|
for (const s of Object.values(i.value)) {
|
|
249
|
-
const
|
|
250
|
-
|
|
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
|
|
265
|
+
function M() {
|
|
254
266
|
t.value = {};
|
|
255
267
|
}
|
|
256
|
-
function
|
|
257
|
-
a.value = {}, i.value = {}, t.value = {}, n.value = {};
|
|
268
|
+
function U() {
|
|
269
|
+
u += 1, a.value = {}, i.value = {}, t.value = {}, n.value = {};
|
|
258
270
|
}
|
|
259
|
-
return { items: a, views: i, errors: t, isPending:
|
|
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 };
|
|
260
272
|
}
|
|
261
|
-
function
|
|
273
|
+
function Ae(e, a) {
|
|
262
274
|
const i = (t) => {
|
|
263
275
|
const n = e.value, o = t.target;
|
|
264
276
|
!n || !o || n.contains(o) || a();
|
|
265
277
|
};
|
|
266
|
-
|
|
278
|
+
F(() => {
|
|
267
279
|
document.addEventListener("click", i);
|
|
268
|
-
}),
|
|
280
|
+
}), x(() => {
|
|
269
281
|
document.removeEventListener("click", i);
|
|
270
282
|
});
|
|
271
283
|
}
|
|
272
|
-
function
|
|
273
|
-
const { locale: e } =
|
|
284
|
+
function Ce() {
|
|
285
|
+
const { locale: e } = y();
|
|
274
286
|
function a(i, t = null) {
|
|
275
|
-
const n =
|
|
287
|
+
const n = re[i.trim().toUpperCase()];
|
|
276
288
|
if (!n)
|
|
277
289
|
throw new Error(`Unknown country code: ${i}`);
|
|
278
290
|
if (t && n[t])
|
|
@@ -285,7 +297,7 @@ function Be() {
|
|
|
285
297
|
}
|
|
286
298
|
return a;
|
|
287
299
|
}
|
|
288
|
-
const
|
|
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,130 +435,130 @@ 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
|
-
},
|
|
427
|
-
const t = a || "An unexpected error occurred", n =
|
|
438
|
+
}, we = ({ code: e, message: a, data: i }) => {
|
|
439
|
+
const t = a || "An unexpected error occurred", n = J({
|
|
428
440
|
statusCode: e,
|
|
429
441
|
statusMessage: t,
|
|
430
442
|
message: t,
|
|
431
443
|
data: i
|
|
432
444
|
});
|
|
433
|
-
throw
|
|
434
|
-
},
|
|
435
|
-
function
|
|
436
|
-
const { gtagId: e } =
|
|
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}/${
|
|
452
|
+
const i = `${e}/${oe}`;
|
|
441
453
|
window.gtag("event", "conversion", {
|
|
442
454
|
send_to: i
|
|
443
455
|
});
|
|
444
456
|
} };
|
|
445
457
|
}
|
|
446
|
-
const
|
|
447
|
-
function
|
|
448
|
-
const { locale: e } =
|
|
449
|
-
return { contactUrl:
|
|
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
|
|
463
|
+
function Ie() {
|
|
452
464
|
async function e(t) {
|
|
453
465
|
await Promise.all(
|
|
454
466
|
t.map(
|
|
455
467
|
(n) => new Promise((o) => {
|
|
456
468
|
if (!n) return o(null);
|
|
457
|
-
const
|
|
458
|
-
|
|
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
475
|
function a(t, n) {
|
|
464
|
-
return n.split(".").reduce((o,
|
|
476
|
+
return n.split(".").reduce((o, u) => o && typeof o == "object" && u in o ? o[u] : "", t) ?? "";
|
|
465
477
|
}
|
|
466
478
|
function i(t, n, o) {
|
|
467
479
|
if (import.meta.server)
|
|
468
|
-
return async (
|
|
480
|
+
return async (f) => {
|
|
469
481
|
t.value = !0;
|
|
470
482
|
};
|
|
471
|
-
const
|
|
483
|
+
const u = $(
|
|
472
484
|
`${n}LoadedImageCache`,
|
|
473
485
|
() => ({})
|
|
474
486
|
);
|
|
475
|
-
return async (
|
|
476
|
-
if (!
|
|
487
|
+
return async (f) => {
|
|
488
|
+
if (!f) {
|
|
477
489
|
t.value = !1;
|
|
478
490
|
return;
|
|
479
491
|
}
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
492
|
+
const g = o.map((m) => a(f, m)), l = `${n}|${g.join("|")}`;
|
|
493
|
+
if (u.value[l]) {
|
|
482
494
|
t.value = !0;
|
|
483
495
|
return;
|
|
484
496
|
}
|
|
485
497
|
t.value = !1;
|
|
486
|
-
const
|
|
487
|
-
await e(
|
|
498
|
+
const b = g.filter(Boolean).map(String);
|
|
499
|
+
await e(b), u.value[l] = !0, t.value = !0;
|
|
488
500
|
};
|
|
489
501
|
}
|
|
490
502
|
return i;
|
|
491
503
|
}
|
|
492
|
-
const
|
|
504
|
+
const se = {
|
|
493
505
|
en: ["US", "UK"]
|
|
494
|
-
},
|
|
495
|
-
function
|
|
506
|
+
}, ue = "FR";
|
|
507
|
+
function de(e) {
|
|
496
508
|
const a = e.trim().replace("_", "-"), [i, t] = a.split("-");
|
|
497
509
|
return {
|
|
498
510
|
language: i?.toLowerCase() ?? "",
|
|
499
511
|
region: t?.toUpperCase() ?? ""
|
|
500
512
|
};
|
|
501
513
|
}
|
|
502
|
-
function
|
|
514
|
+
function K(e) {
|
|
503
515
|
return e.toString().trim().toUpperCase();
|
|
504
516
|
}
|
|
505
|
-
function
|
|
517
|
+
function Ee() {
|
|
506
518
|
function e(a, i) {
|
|
507
519
|
if (!i.length) return;
|
|
508
|
-
const t = i.map(
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
for (const
|
|
513
|
-
if (n.has(
|
|
514
|
-
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;
|
|
515
527
|
return t[0];
|
|
516
528
|
}
|
|
517
529
|
return { getRegionFromLocale: e };
|
|
518
530
|
}
|
|
519
|
-
function
|
|
520
|
-
const { t: e } =
|
|
531
|
+
function Re() {
|
|
532
|
+
const { t: e } = y();
|
|
521
533
|
function a(i, t) {
|
|
522
|
-
const n = e(i), o = [],
|
|
523
|
-
let
|
|
524
|
-
for (;
|
|
525
|
-
const { index:
|
|
526
|
-
|
|
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);
|
|
527
539
|
}
|
|
528
|
-
return
|
|
540
|
+
return b < n.length && o.push({ text: n.slice(b), ...l }), o;
|
|
529
541
|
}
|
|
530
542
|
return { parse: a };
|
|
531
543
|
}
|
|
532
|
-
function
|
|
533
|
-
const t = A(i - 1), n =
|
|
544
|
+
function ke(e, a, i = 768) {
|
|
545
|
+
const t = A(i - 1), n = T(
|
|
534
546
|
() => t.value >= i ? a : e
|
|
535
547
|
);
|
|
536
548
|
if (import.meta.client) {
|
|
537
549
|
const o = () => {
|
|
538
550
|
t.value = window.innerWidth;
|
|
539
551
|
};
|
|
540
|
-
|
|
552
|
+
F(() => {
|
|
541
553
|
o(), window.addEventListener("resize", o);
|
|
542
|
-
}),
|
|
554
|
+
}), Z(() => {
|
|
543
555
|
window.removeEventListener("resize", o);
|
|
544
556
|
});
|
|
545
557
|
}
|
|
546
558
|
return { size: n, windowWidth: t };
|
|
547
559
|
}
|
|
548
|
-
function
|
|
549
|
-
const { locale: e } =
|
|
560
|
+
function ye() {
|
|
561
|
+
const { locale: e } = y();
|
|
550
562
|
function a(i, t = "fr") {
|
|
551
563
|
if (!i) return "";
|
|
552
564
|
const n = e.value;
|
|
@@ -555,21 +567,21 @@ function Ee() {
|
|
|
555
567
|
return a;
|
|
556
568
|
}
|
|
557
569
|
export {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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
|
|
575
587
|
};
|
package/dist/store/useStore.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ type ViewKey = string;
|
|
|
8
8
|
* where a view's `items[]` could drift from `items.value[id]` after a re-fetch.
|
|
9
9
|
*
|
|
10
10
|
* `revision` is the store's revision when the page was requested: an `update()`
|
|
11
|
-
* landing after that request makes the view stale, and
|
|
12
|
-
* refetches the page.
|
|
11
|
+
* or a `markViewsStale()` landing after that request makes the view stale, and
|
|
12
|
+
* the next `list()` on it refetches the page.
|
|
13
13
|
*/
|
|
14
14
|
type StoredView<Id extends IdKey> = ViewKeyParams & {
|
|
15
15
|
itemIds: Id[];
|
|
@@ -64,6 +64,8 @@ export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePa
|
|
|
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