@choosemycompany/lib 0.9.0 → 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/README.md +30 -5
- package/dist/index.js +223 -209
- package/dist/store/useStore.d.ts +10 -3
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -20,13 +20,12 @@ A single entry point: everything is re-exported from `@choosemycompany/lib`.
|
|
|
20
20
|
|
|
21
21
|
The package expects to be consumed **inside a Nuxt 4 project**, with the following peer deps installed:
|
|
22
22
|
|
|
23
|
-
- `vue`, `vue-i18n`, `
|
|
23
|
+
- `vue`, `vue-i18n`, `pinia`
|
|
24
24
|
- `mande` (HTTP client)
|
|
25
25
|
- `h3` (for `useErrorHandling`)
|
|
26
|
-
- `@nuxtjs/i18n` (`useLocalePath`)
|
|
27
26
|
- `nuxt` (for `useRuntimeConfig`, `useState`, `showError`, imported from `nuxt/app`)
|
|
28
27
|
|
|
29
|
-
Composables using `useRuntimeConfig()
|
|
28
|
+
Composables using `useRuntimeConfig()` or `useI18n()` must be called inside a Nuxt scope (setup, plugin, middleware).
|
|
30
29
|
|
|
31
30
|
## Local development (HMR through the sandbox)
|
|
32
31
|
|
|
@@ -46,15 +45,41 @@ The scenario: sign in, call the protected API, expire the token, call again. The
|
|
|
46
45
|
|
|
47
46
|
Known limitation: production runs a cross-site guard, `RejectCrossSiteCookieAuthenticatedRequest`, which answers `403` to an unsafe request that is authenticated by cookie, carries no `Authorization` header, and comes from another site. The sandbox has no equivalent, so the lib's `403` path cannot be exercised here.
|
|
48
47
|
|
|
49
|
-
## Build
|
|
48
|
+
## Build
|
|
50
49
|
|
|
51
50
|
```bash
|
|
52
51
|
pnpm build # vite build → dist/
|
|
53
52
|
pnpm typecheck
|
|
54
53
|
pnpm test
|
|
55
|
-
pnpm publish # through CircleCI on a push to main
|
|
56
54
|
```
|
|
57
55
|
|
|
56
|
+
## Releasing
|
|
57
|
+
|
|
58
|
+
| Trigger | CI |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| Any branch or pull request | Lint and tests |
|
|
61
|
+
| `vX.Y.Z` tag | Lint, tests, version check, npm publish |
|
|
62
|
+
|
|
63
|
+
There is no preprod: the tag publishes. The tag must match the `version` in `package.json`, and that version must be exactly one patch, minor or major step above the latest version published on npm. A published version can never be republished.
|
|
64
|
+
|
|
65
|
+
Feature and fix pull requests to `develop` touch neither `version` nor `CHANGELOG.md`. Both change only in the release pull request.
|
|
66
|
+
|
|
67
|
+
1. Cut `release_X_Y_Z` from `origin/develop`. If `develop` and `main` have diverged (for example after a squashed release), rebase it on `main` so the commits already shipped drop out. On that branch only, set `version` in `package.json` and add a `## X.Y.Z` section at the top of `CHANGELOG.md`, written in French for the library's users, in the format of cmc-ui's changelog. The number follows from the pull requests shipped: a feature (new composable, option or export) → minor, only fixes → patch, a public API break → major.
|
|
68
|
+
2. Open the release pull request `release_X_Y_Z` → `main`, titled `Release vX.Y.Z`, and merge it with a merge commit, not a squash, so `main` and `develop` keep the same history.
|
|
69
|
+
3. Tag `main` and push the tag:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
git fetch origin
|
|
73
|
+
git tag vX.Y.Z origin/main
|
|
74
|
+
git push origin vX.Y.Z
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
4. Realign `develop` on `main` by rebase, then `git push --force-with-lease` (never merge `main` into `develop`), and delete the release branch.
|
|
78
|
+
|
|
79
|
+
If the version check fails before the publish, nothing is published: delete the tag (`git push origin :refs/tags/vX.Y.Z`), fix, and tag again.
|
|
80
|
+
|
|
81
|
+
A hotfix follows the same steps from `origin/main` instead of `origin/develop`: `hotfix_X_Y_Z` carries the fix, the patch bump and its `CHANGELOG.md` section, then the pull request to `main`, the tag, and the realignment of `develop`.
|
|
82
|
+
|
|
58
83
|
## Notable API changes
|
|
59
84
|
|
|
60
85
|
- `useStore`: unified signature absorbing the `workspace` variant (search, filters, a fourth `FilterItem` generic). Public method: `isPending(key)`. `getViewKey` sorts keys to guarantee a deterministic cache.
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { mande as
|
|
2
|
-
import { ref 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 D(e) {
|
|
|
25
25
|
}
|
|
26
26
|
return i;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
const e =
|
|
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
30
|
let t, n = 0;
|
|
31
|
-
const
|
|
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";
|
|
@@ -77,28 +77,28 @@ const V = "/auth/api/v2/session/tokens", J = "/auth/api/v2/", j = "cmc-auth-sess
|
|
|
77
77
|
isOpen: e,
|
|
78
78
|
isExpired: a,
|
|
79
79
|
expiryReason: i,
|
|
80
|
-
isAuthenticated:
|
|
81
|
-
open:
|
|
82
|
-
expire:
|
|
83
|
-
clear:
|
|
84
|
-
logout:
|
|
85
|
-
refresh:
|
|
80
|
+
isAuthenticated: o,
|
|
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 Q() {
|
|
|
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,151 +126,165 @@ function fe(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 =
|
|
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 l(r,
|
|
155
|
-
n.value[r] =
|
|
156
|
+
async function l(r, d) {
|
|
157
|
+
n.value[r] = d;
|
|
156
158
|
try {
|
|
157
|
-
const
|
|
158
|
-
return delete t.value[r],
|
|
159
|
-
} catch (
|
|
160
|
-
throw t.value[r] =
|
|
159
|
+
const s = await d;
|
|
160
|
+
return delete t.value[r], s;
|
|
161
|
+
} catch (s) {
|
|
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:
|
|
169
|
-
if (a.value[r] && !
|
|
170
|
+
const { force: s = !1 } = d;
|
|
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
|
|
189
|
-
if (
|
|
193
|
+
function m(r) {
|
|
194
|
+
const d = N(r), s = i.value[d];
|
|
195
|
+
if (s)
|
|
190
196
|
return {
|
|
191
|
-
items:
|
|
192
|
-
total:
|
|
193
|
-
hasMore:
|
|
194
|
-
page:
|
|
195
|
-
limit:
|
|
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
|
|
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
|
|
202
|
-
if (i.value[
|
|
203
|
-
return
|
|
204
|
-
const B = n.value[
|
|
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];
|
|
205
211
|
if (B)
|
|
206
|
-
return await B,
|
|
207
|
-
const S = e.fetchPage,
|
|
212
|
+
return await B, m(r);
|
|
213
|
+
const S = e.fetchPage, I = (async () => {
|
|
214
|
+
const E = o.value, R = u;
|
|
208
215
|
try {
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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);
|
|
213
223
|
}
|
|
214
|
-
i.value[
|
|
215
|
-
itemIds:
|
|
216
|
-
total:
|
|
217
|
-
hasMore:
|
|
218
|
-
page:
|
|
219
|
-
limit:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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);
|
|
223
234
|
} finally {
|
|
224
|
-
delete n.value[
|
|
235
|
+
R === u && delete n.value[s];
|
|
225
236
|
}
|
|
226
237
|
})();
|
|
227
|
-
return n.value[
|
|
238
|
+
return n.value[s] = I, await I, m(r);
|
|
228
239
|
}
|
|
229
|
-
async function
|
|
240
|
+
async function C(r, d = te) {
|
|
230
241
|
if (!e.createMutation)
|
|
231
242
|
throw new Error("useStore.create called but createMutation is not defined in store options");
|
|
232
|
-
const
|
|
233
|
-
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;
|
|
234
245
|
}
|
|
235
|
-
async function
|
|
246
|
+
async function v(r, d) {
|
|
236
247
|
if (!e.updateMutation)
|
|
237
248
|
throw new Error("useStore.update called but updateMutation is not defined in store options");
|
|
238
|
-
const
|
|
239
|
-
return a.value[r] = B, 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;
|
|
240
254
|
}
|
|
241
|
-
async function
|
|
255
|
+
async function P(r) {
|
|
242
256
|
if (!e.removeMutation)
|
|
243
257
|
throw new Error("useStore.remove called but removeMutation is not defined in store options");
|
|
244
|
-
const
|
|
245
|
-
await l(r, (async () =>
|
|
246
|
-
for (const
|
|
247
|
-
const
|
|
248
|
-
|
|
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));
|
|
249
263
|
}
|
|
250
264
|
}
|
|
251
|
-
function
|
|
265
|
+
function M() {
|
|
252
266
|
t.value = {};
|
|
253
267
|
}
|
|
254
|
-
function
|
|
255
|
-
a.value = {}, i.value = {}, t.value = {}, n.value = {};
|
|
268
|
+
function U() {
|
|
269
|
+
u += 1, a.value = {}, i.value = {}, t.value = {}, n.value = {};
|
|
256
270
|
}
|
|
257
|
-
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 };
|
|
258
272
|
}
|
|
259
|
-
function
|
|
273
|
+
function Ae(e, a) {
|
|
260
274
|
const i = (t) => {
|
|
261
|
-
const n = e.value,
|
|
262
|
-
!n || !
|
|
275
|
+
const n = e.value, o = t.target;
|
|
276
|
+
!n || !o || n.contains(o) || a();
|
|
263
277
|
};
|
|
264
|
-
|
|
278
|
+
F(() => {
|
|
265
279
|
document.addEventListener("click", i);
|
|
266
|
-
}),
|
|
280
|
+
}), x(() => {
|
|
267
281
|
document.removeEventListener("click", i);
|
|
268
282
|
});
|
|
269
283
|
}
|
|
270
|
-
function
|
|
271
|
-
const { locale: e } =
|
|
284
|
+
function Ce() {
|
|
285
|
+
const { locale: e } = y();
|
|
272
286
|
function a(i, t = null) {
|
|
273
|
-
const n =
|
|
287
|
+
const n = re[i.trim().toUpperCase()];
|
|
274
288
|
if (!n)
|
|
275
289
|
throw new Error(`Unknown country code: ${i}`);
|
|
276
290
|
if (t && n[t])
|
|
@@ -283,7 +297,7 @@ function he() {
|
|
|
283
297
|
}
|
|
284
298
|
return a;
|
|
285
299
|
}
|
|
286
|
-
const
|
|
300
|
+
const re = {
|
|
287
301
|
AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
|
|
288
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" },
|
|
289
303
|
AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
|
|
@@ -421,130 +435,130 @@ const ee = {
|
|
|
421
435
|
ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
|
|
422
436
|
ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
|
|
423
437
|
ZW: { en: "Zimbabwe", fr: "Zimbabwe", es: "Zimbabue", de: "Simbabwe", it: "Zimbabwe", pt: "Zimbábue", da: "Zimbabwe" }
|
|
424
|
-
},
|
|
425
|
-
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({
|
|
426
440
|
statusCode: e,
|
|
427
441
|
statusMessage: t,
|
|
428
442
|
message: t,
|
|
429
443
|
data: i
|
|
430
444
|
});
|
|
431
|
-
throw
|
|
432
|
-
},
|
|
433
|
-
function
|
|
434
|
-
const { gtagId: e } =
|
|
445
|
+
throw j(n), n;
|
|
446
|
+
}, oe = "ilcJCL_lmpwcEJfSkKND";
|
|
447
|
+
function Me() {
|
|
448
|
+
const { gtagId: e } = _().public;
|
|
435
449
|
return { reportConversion: () => {
|
|
436
450
|
if (typeof window > "u" || typeof window.gtag > "u" || !e)
|
|
437
451
|
return;
|
|
438
|
-
const i = `${e}/${
|
|
452
|
+
const i = `${e}/${oe}`;
|
|
439
453
|
window.gtag("event", "conversion", {
|
|
440
454
|
send_to: i
|
|
441
455
|
});
|
|
442
456
|
} };
|
|
443
457
|
}
|
|
444
|
-
const
|
|
445
|
-
function
|
|
446
|
-
const { locale: e } =
|
|
447
|
-
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`) };
|
|
448
462
|
}
|
|
449
|
-
function
|
|
463
|
+
function Ie() {
|
|
450
464
|
async function e(t) {
|
|
451
465
|
await Promise.all(
|
|
452
466
|
t.map(
|
|
453
|
-
(n) => new Promise((
|
|
454
|
-
if (!n) return
|
|
455
|
-
const
|
|
456
|
-
|
|
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;
|
|
457
471
|
})
|
|
458
472
|
)
|
|
459
473
|
);
|
|
460
474
|
}
|
|
461
475
|
function a(t, n) {
|
|
462
|
-
return n.split(".").reduce((
|
|
476
|
+
return n.split(".").reduce((o, u) => o && typeof o == "object" && u in o ? o[u] : "", t) ?? "";
|
|
463
477
|
}
|
|
464
|
-
function i(t, n,
|
|
478
|
+
function i(t, n, o) {
|
|
465
479
|
if (import.meta.server)
|
|
466
|
-
return async (
|
|
480
|
+
return async (f) => {
|
|
467
481
|
t.value = !0;
|
|
468
482
|
};
|
|
469
|
-
const
|
|
483
|
+
const u = $(
|
|
470
484
|
`${n}LoadedImageCache`,
|
|
471
485
|
() => ({})
|
|
472
486
|
);
|
|
473
|
-
return async (
|
|
474
|
-
if (!
|
|
487
|
+
return async (f) => {
|
|
488
|
+
if (!f) {
|
|
475
489
|
t.value = !1;
|
|
476
490
|
return;
|
|
477
491
|
}
|
|
478
|
-
const
|
|
479
|
-
if (
|
|
492
|
+
const g = o.map((m) => a(f, m)), l = `${n}|${g.join("|")}`;
|
|
493
|
+
if (u.value[l]) {
|
|
480
494
|
t.value = !0;
|
|
481
495
|
return;
|
|
482
496
|
}
|
|
483
497
|
t.value = !1;
|
|
484
|
-
const
|
|
485
|
-
await e(
|
|
498
|
+
const b = g.filter(Boolean).map(String);
|
|
499
|
+
await e(b), u.value[l] = !0, t.value = !0;
|
|
486
500
|
};
|
|
487
501
|
}
|
|
488
502
|
return i;
|
|
489
503
|
}
|
|
490
|
-
const
|
|
504
|
+
const se = {
|
|
491
505
|
en: ["US", "UK"]
|
|
492
|
-
},
|
|
493
|
-
function
|
|
506
|
+
}, ue = "FR";
|
|
507
|
+
function de(e) {
|
|
494
508
|
const a = e.trim().replace("_", "-"), [i, t] = a.split("-");
|
|
495
509
|
return {
|
|
496
510
|
language: i?.toLowerCase() ?? "",
|
|
497
511
|
region: t?.toUpperCase() ?? ""
|
|
498
512
|
};
|
|
499
513
|
}
|
|
500
|
-
function
|
|
514
|
+
function K(e) {
|
|
501
515
|
return e.toString().trim().toUpperCase();
|
|
502
516
|
}
|
|
503
|
-
function
|
|
517
|
+
function Ee() {
|
|
504
518
|
function e(a, i) {
|
|
505
519
|
if (!i.length) return;
|
|
506
|
-
const t = i.map(
|
|
507
|
-
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
for (const
|
|
511
|
-
if (n.has(
|
|
512
|
-
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;
|
|
513
527
|
return t[0];
|
|
514
528
|
}
|
|
515
529
|
return { getRegionFromLocale: e };
|
|
516
530
|
}
|
|
517
|
-
function
|
|
518
|
-
const { t: e } =
|
|
531
|
+
function Re() {
|
|
532
|
+
const { t: e } = y();
|
|
519
533
|
function a(i, t) {
|
|
520
|
-
const n = e(i),
|
|
521
|
-
let
|
|
522
|
-
for (;
|
|
523
|
-
const { index:
|
|
524
|
-
|
|
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);
|
|
525
539
|
}
|
|
526
|
-
return
|
|
540
|
+
return b < n.length && o.push({ text: n.slice(b), ...l }), o;
|
|
527
541
|
}
|
|
528
542
|
return { parse: a };
|
|
529
543
|
}
|
|
530
|
-
function
|
|
531
|
-
const t =
|
|
544
|
+
function ke(e, a, i = 768) {
|
|
545
|
+
const t = A(i - 1), n = T(
|
|
532
546
|
() => t.value >= i ? a : e
|
|
533
547
|
);
|
|
534
548
|
if (import.meta.client) {
|
|
535
|
-
const
|
|
549
|
+
const o = () => {
|
|
536
550
|
t.value = window.innerWidth;
|
|
537
551
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}),
|
|
541
|
-
window.removeEventListener("resize",
|
|
552
|
+
F(() => {
|
|
553
|
+
o(), window.addEventListener("resize", o);
|
|
554
|
+
}), Z(() => {
|
|
555
|
+
window.removeEventListener("resize", o);
|
|
542
556
|
});
|
|
543
557
|
}
|
|
544
558
|
return { size: n, windowWidth: t };
|
|
545
559
|
}
|
|
546
|
-
function
|
|
547
|
-
const { locale: e } =
|
|
560
|
+
function ye() {
|
|
561
|
+
const { locale: e } = y();
|
|
548
562
|
function a(i, t = "fr") {
|
|
549
563
|
if (!i) return "";
|
|
550
564
|
const n = e.value;
|
|
@@ -553,21 +567,21 @@ function Se() {
|
|
|
553
567
|
return a;
|
|
554
568
|
}
|
|
555
569
|
export {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
|
573
587
|
};
|
package/dist/store/useStore.d.ts
CHANGED
|
@@ -6,11 +6,16 @@ type ViewKey = string;
|
|
|
6
6
|
* Internal shape of a cached view. Keeps only `itemIds[]` so that `items` remains
|
|
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
|
+
*
|
|
10
|
+
* `revision` is the store's revision when the page was requested: an `update()`
|
|
11
|
+
* or a `markViewsStale()` landing after that request makes the view stale, and
|
|
12
|
+
* the next `list()` on it refetches the page.
|
|
9
13
|
*/
|
|
10
14
|
type StoredView<Id extends IdKey> = ViewKeyParams & {
|
|
11
15
|
itemIds: Id[];
|
|
12
16
|
total: number;
|
|
13
17
|
hasMore: boolean;
|
|
18
|
+
revision: number;
|
|
14
19
|
};
|
|
15
20
|
type StoreItems<Id extends IdKey, Item> = Record<Id, Item>;
|
|
16
21
|
type StoreViews<Id extends IdKey> = Record<ViewKey, StoredView<Id>>;
|
|
@@ -41,7 +46,7 @@ export declare function getViewKey(params: ViewKeyParams): ViewKey;
|
|
|
41
46
|
export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePayload = Item, UpdatePatch = Partial<Item>> = {
|
|
42
47
|
/** Canonical item cache keyed by id. The single source of truth for item data. */
|
|
43
48
|
items: Ref<StoreItems<Id, Item>>;
|
|
44
|
-
/** Cached pages, keyed by `getViewKey(params)`. Each stores `itemIds[]
|
|
49
|
+
/** Cached pages, keyed by `getViewKey(params)`. Each stores `itemIds[]`, pagination meta and the revision it was requested at. */
|
|
45
50
|
views: Ref<StoreViews<Id>>;
|
|
46
51
|
/** Latest error per key (id for retrieve, view key for list, arbitrary for `withPending`). */
|
|
47
52
|
errors: Ref<StoreErrors>;
|
|
@@ -49,7 +54,7 @@ export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePa
|
|
|
49
54
|
isPending: (key: ViewKey | Id) => boolean;
|
|
50
55
|
/** Fetches one item by id (cache-first unless `force: true`). Returns `undefined` on failure. */
|
|
51
56
|
retrieve: (id: Id, retrieveOptions?: RetrieveOptions) => Promise<Item | undefined>;
|
|
52
|
-
/** Fetches one page (cache-first unless `force: true`). Returns the resolved `View<Item>`. */
|
|
57
|
+
/** Fetches one page (cache-first unless `force: true` or the view is stale). Returns the resolved `View<Item>`. */
|
|
53
58
|
list: (params: Params, listOptions?: ListOptions) => Promise<View<Item> | undefined>;
|
|
54
59
|
/** Synchronous lookup: rebuilds a `View<Item>` from the cache without fetching. */
|
|
55
60
|
getView: (params: Params) => View<Item> | undefined;
|
|
@@ -57,8 +62,10 @@ export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePa
|
|
|
57
62
|
withPending: <T>(key: ViewKey | Id, promise: Promise<T>) => Promise<T>;
|
|
58
63
|
/** Calls `createMutation`, inserts the item into `items`, and invalidates all views. */
|
|
59
64
|
create: (payload: CreatePayload, key?: ViewKey | Id) => Promise<Item>;
|
|
60
|
-
/** Calls `updateMutation` (wrapped in `withPending(id)`), replaces `items[id]
|
|
65
|
+
/** Calls `updateMutation` (wrapped in `withPending(id)`), replaces `items[id]`, and marks every view stale. */
|
|
61
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;
|
|
62
69
|
/** Calls `removeMutation` (wrapped in `withPending(id)`), deletes `items[id]`, removes id from every view. */
|
|
63
70
|
remove: (id: Id) => Promise<void>;
|
|
64
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.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"packageManager": "pnpm@10.17.0",
|
|
@@ -29,15 +29,12 @@
|
|
|
29
29
|
"test": "vitest run"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@nuxtjs/i18n": "^10.0.0",
|
|
33
32
|
"h3": "^1.0.0",
|
|
34
33
|
"mande": "^2.0.10",
|
|
35
34
|
"nuxt": "^4.0.0",
|
|
36
35
|
"pinia": "^3.0.0",
|
|
37
|
-
"ufo": "^1.0.0",
|
|
38
36
|
"vue": "^3.5.0",
|
|
39
|
-
"vue-i18n": "^10.0.0"
|
|
40
|
-
"vue-router": "^4.0.0"
|
|
37
|
+
"vue-i18n": "^10.0.0"
|
|
41
38
|
},
|
|
42
39
|
"devDependencies": {
|
|
43
40
|
"@eslint/js": "^9.36.0",
|
|
@@ -53,12 +50,10 @@
|
|
|
53
50
|
"pinia": "^3.0.3",
|
|
54
51
|
"typescript": "^5.9.2",
|
|
55
52
|
"typescript-eslint": "^8.44.1",
|
|
56
|
-
"ufo": "^1.5.4",
|
|
57
53
|
"vite": "^7.1.7",
|
|
58
54
|
"vite-plugin-dts": "^4.5.4",
|
|
59
55
|
"vitest": "^3.2.4",
|
|
60
56
|
"vue": "^3.5.22",
|
|
61
|
-
"vue-i18n": "^10.0.0"
|
|
62
|
-
"vue-router": "^4.5.1"
|
|
57
|
+
"vue-i18n": "^10.0.0"
|
|
63
58
|
}
|
|
64
59
|
}
|