@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 +268 -256
- package/dist/store/useStore.d.ts +6 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,291 +1,303 @@
|
|
|
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 =
|
|
20
|
-
if (typeof
|
|
21
|
-
const
|
|
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
|
|
26
|
+
return t;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
const e = A(!1), a = A(!1),
|
|
30
|
-
let
|
|
31
|
-
const o =
|
|
32
|
-
function
|
|
33
|
-
e.value = !0, a.value = !1,
|
|
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 = !
|
|
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
|
|
42
|
-
n += 1, e.value = !1, a.value = !0,
|
|
41
|
+
function l(B) {
|
|
42
|
+
n += 1, e.value = !1, a.value = !0, t.value = B;
|
|
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
|
|
48
|
-
|
|
49
|
-
}),
|
|
47
|
+
return i ??= m(h).finally(() => {
|
|
48
|
+
i = void 0;
|
|
49
|
+
}), i;
|
|
50
50
|
}
|
|
51
|
-
async function
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
54
|
-
await
|
|
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
|
|
57
|
-
const
|
|
58
|
-
let
|
|
56
|
+
async function h() {
|
|
57
|
+
const B = n, p = () => B !== 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
|
+
t.value = "refresh-unreachable";
|
|
75
75
|
}
|
|
76
76
|
return {
|
|
77
77
|
isOpen: e,
|
|
78
78
|
isExpired: a,
|
|
79
|
-
expiryReason:
|
|
79
|
+
expiryReason: t,
|
|
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 (
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
let
|
|
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
|
-
|
|
101
|
+
i = X();
|
|
102
102
|
} catch {
|
|
103
|
-
return
|
|
103
|
+
return t;
|
|
104
104
|
}
|
|
105
|
-
if (
|
|
105
|
+
if (i.isExpired) return t;
|
|
106
106
|
try {
|
|
107
|
-
await
|
|
107
|
+
await i.refresh();
|
|
108
108
|
} catch (n) {
|
|
109
|
-
return
|
|
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
|
|
115
|
-
const a =
|
|
114
|
+
function be(e) {
|
|
115
|
+
const a = q(O(e), {
|
|
116
116
|
headers: {}
|
|
117
|
-
},
|
|
118
|
-
function
|
|
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
|
|
124
|
+
function i() {
|
|
125
125
|
a.options.headers && delete a.options.headers.Authorization;
|
|
126
126
|
}
|
|
127
|
-
return { http: a, setToken:
|
|
127
|
+
return { http: a, setToken: t, clearToken: i };
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
return e.replace(
|
|
131
|
-
const n = Object.hasOwn(a,
|
|
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 "${
|
|
133
|
+
throw new Error(`Missing URL parameter "${i}" for template "${e}"`);
|
|
134
134
|
return encodeURIComponent(String(n));
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
const
|
|
138
|
-
function
|
|
139
|
-
return Object.entries(e).sort(([a], [
|
|
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
|
|
142
|
-
function
|
|
143
|
-
const a = A({}),
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
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
|
|
158
|
-
return delete
|
|
159
|
+
const s = await d;
|
|
160
|
+
return delete i.value[r], s;
|
|
159
161
|
} catch (s) {
|
|
160
|
-
throw
|
|
162
|
+
throw i.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
|
|
174
|
-
const
|
|
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
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
|
188
|
-
const
|
|
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((
|
|
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 (
|
|
203
|
-
return
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
return await
|
|
207
|
-
const S = e.fetchPage,
|
|
208
|
-
const
|
|
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
|
|
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
|
-
|
|
216
|
-
itemIds:
|
|
217
|
-
total:
|
|
218
|
-
hasMore:
|
|
219
|
-
page:
|
|
220
|
-
limit:
|
|
221
|
-
revision:
|
|
222
|
-
}, delete
|
|
223
|
-
} catch (
|
|
224
|
-
|
|
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] =
|
|
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] =
|
|
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
|
|
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,
|
|
241
|
-
return a.value[r] =
|
|
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
|
|
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
|
|
248
|
-
for (const s of Object.values(
|
|
249
|
-
const
|
|
250
|
-
|
|
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
|
|
254
|
-
|
|
265
|
+
function M() {
|
|
266
|
+
i.value = {};
|
|
255
267
|
}
|
|
256
|
-
function
|
|
257
|
-
a.value = {},
|
|
268
|
+
function U() {
|
|
269
|
+
u += 1, a.value = {}, t.value = {}, i.value = {}, n.value = {};
|
|
258
270
|
}
|
|
259
|
-
return { items: a, views:
|
|
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
|
|
262
|
-
const
|
|
263
|
-
const n = e.value, o =
|
|
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
|
-
|
|
267
|
-
document.addEventListener("click",
|
|
268
|
-
}),
|
|
269
|
-
document.removeEventListener("click",
|
|
278
|
+
F(() => {
|
|
279
|
+
document.addEventListener("click", t);
|
|
280
|
+
}), x(() => {
|
|
281
|
+
document.removeEventListener("click", t);
|
|
270
282
|
});
|
|
271
283
|
}
|
|
272
|
-
function
|
|
273
|
-
const { locale: e } =
|
|
274
|
-
function a(
|
|
275
|
-
const n =
|
|
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: ${
|
|
278
|
-
if (
|
|
279
|
-
return n[
|
|
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: ${
|
|
296
|
+
throw new Error(`Unknown country code: ${t}`);
|
|
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,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
|
-
},
|
|
427
|
-
const
|
|
438
|
+
}, we = ({ code: e, message: a, data: t }) => {
|
|
439
|
+
const i = a || "An unexpected error occurred", n = J({
|
|
428
440
|
statusCode: e,
|
|
429
|
-
statusMessage:
|
|
430
|
-
message:
|
|
431
|
-
data:
|
|
441
|
+
statusMessage: i,
|
|
442
|
+
message: i,
|
|
443
|
+
data: t
|
|
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
|
|
452
|
+
const t = `${e}/${oe}`;
|
|
441
453
|
window.gtag("event", "conversion", {
|
|
442
|
-
send_to:
|
|
454
|
+
send_to: t
|
|
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
|
|
452
|
-
async function e(
|
|
463
|
+
function Ie() {
|
|
464
|
+
async function e(i) {
|
|
453
465
|
await Promise.all(
|
|
454
|
-
|
|
466
|
+
i.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
|
-
function a(
|
|
464
|
-
return n.split(".").reduce((o,
|
|
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
|
|
478
|
+
function t(i, n, o) {
|
|
467
479
|
if (import.meta.server)
|
|
468
|
-
return async (
|
|
469
|
-
|
|
480
|
+
return async (f) => {
|
|
481
|
+
i.value = !0;
|
|
470
482
|
};
|
|
471
|
-
const
|
|
483
|
+
const u = $(
|
|
472
484
|
`${n}LoadedImageCache`,
|
|
473
485
|
() => ({})
|
|
474
486
|
);
|
|
475
|
-
return async (
|
|
476
|
-
if (!
|
|
477
|
-
|
|
487
|
+
return async (f) => {
|
|
488
|
+
if (!f) {
|
|
489
|
+
i.value = !1;
|
|
478
490
|
return;
|
|
479
491
|
}
|
|
480
|
-
const
|
|
481
|
-
if (
|
|
482
|
-
|
|
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
|
-
|
|
486
|
-
const
|
|
487
|
-
await e(
|
|
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
|
|
502
|
+
return t;
|
|
491
503
|
}
|
|
492
|
-
const
|
|
504
|
+
const se = {
|
|
493
505
|
en: ["US", "UK"]
|
|
494
|
-
},
|
|
495
|
-
function
|
|
496
|
-
const a = e.trim().replace("_", "-"), [
|
|
506
|
+
}, ue = "FR";
|
|
507
|
+
function de(e) {
|
|
508
|
+
const a = e.trim().replace("_", "-"), [t, i] = a.split("-");
|
|
497
509
|
return {
|
|
498
|
-
language:
|
|
499
|
-
region:
|
|
510
|
+
language: t?.toLowerCase() ?? "",
|
|
511
|
+
region: i?.toUpperCase() ?? ""
|
|
500
512
|
};
|
|
501
513
|
}
|
|
502
|
-
function
|
|
514
|
+
function K(e) {
|
|
503
515
|
return e.toString().trim().toUpperCase();
|
|
504
516
|
}
|
|
505
|
-
function
|
|
506
|
-
function e(a,
|
|
507
|
-
if (!
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
for (const
|
|
513
|
-
if (n.has(
|
|
514
|
-
return
|
|
515
|
-
return
|
|
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
|
|
520
|
-
const { t: e } =
|
|
521
|
-
function a(
|
|
522
|
-
const n = e(
|
|
523
|
-
let
|
|
524
|
-
for (;
|
|
525
|
-
const { index:
|
|
526
|
-
|
|
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
|
|
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
|
|
534
|
-
() =>
|
|
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
|
-
|
|
550
|
+
i.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
|
-
return { size: n, windowWidth:
|
|
558
|
+
return { size: n, windowWidth: i };
|
|
547
559
|
}
|
|
548
|
-
function
|
|
549
|
-
const { locale: e } =
|
|
550
|
-
function a(
|
|
551
|
-
if (!
|
|
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
|
|
565
|
+
return t[n] ?? t[i] ?? "";
|
|
554
566
|
}
|
|
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
|
+
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
|
};
|
package/dist/store/useStore.d.ts
CHANGED
|
@@ -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:
|
|
11
|
-
* landing after that request makes the
|
|
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
|
|
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