@choosemycompany/lib 0.8.1 → 0.9.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/README.md +31 -6
- package/dist/auth/useAuthSession.d.ts +1 -1
- package/dist/index.js +181 -179
- package/dist/store/useStore.d.ts +8 -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
|
|
|
@@ -40,21 +39,47 @@ The sandbox uses a Vite alias `@choosemycompany/lib` → `../src/index.ts`, so e
|
|
|
40
39
|
|
|
41
40
|
### The `/auth` page
|
|
42
41
|
|
|
43
|
-
It exercises `useAuthSession` against a mocked auth backend: `POST /auth/api/v2/login`, `POST /auth/api/v2/
|
|
42
|
+
It exercises `useAuthSession` against a mocked auth backend: `POST /auth/api/v2/login`, `POST /auth/api/v2/session/tokens` and `POST /auth/api/v2/logout` served at the **origin** like the real auth-api, a protected resource under `/api/session/protected`, and `POST /api/session/simulate` to age the session without waiting 4 h.
|
|
44
43
|
|
|
45
44
|
The scenario: sign in, call the protected API, expire the token, call again. The app writes a single `http.get` and the trace shows three calls — the `401`, the renewal, the replay.
|
|
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.
|
|
@@ -4,7 +4,7 @@ import { SessionExpiryReason } from './types';
|
|
|
4
4
|
* declared base URL, never appended to it: that base URL may carry a path
|
|
5
5
|
* prefix, while the auth API always sits at this path on the origin. Internal.
|
|
6
6
|
*/
|
|
7
|
-
export declare const REFRESH_URI = "/auth/api/v2/
|
|
7
|
+
export declare const REFRESH_URI = "/auth/api/v2/session/tokens";
|
|
8
8
|
/**
|
|
9
9
|
* Path prefix of the auth API. A call to it is never renewed and replayed: it
|
|
10
10
|
* speaks *about* the session rather than relying on it, so a `401` from `login`
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { mande as
|
|
2
|
-
import { ref as
|
|
3
|
-
import { defineStore as
|
|
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
4
|
import { useI18n as E } from "vue-i18n";
|
|
5
|
-
import { createError as
|
|
6
|
-
import { showError as
|
|
5
|
+
import { createError as q } from "h3";
|
|
6
|
+
import { showError as Z, useRuntimeConfig as V, useState as J } from "nuxt/app";
|
|
7
7
|
let I;
|
|
8
|
-
function
|
|
8
|
+
function pe(e) {
|
|
9
9
|
if (!e.baseUrl)
|
|
10
10
|
throw new Error("@choosemycompany/lib: configureHttp() needs a non-empty baseUrl");
|
|
11
11
|
I = e;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function H(e) {
|
|
14
14
|
if (!I)
|
|
15
15
|
throw new Error(
|
|
16
16
|
"@choosemycompany/lib: useHttp() was called before configureHttp(). Declare the base URLs from an app plugin."
|
|
@@ -25,47 +25,47 @@ function D(e) {
|
|
|
25
25
|
}
|
|
26
26
|
return i;
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
const e =
|
|
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
30
|
let t, n = 0;
|
|
31
|
-
const
|
|
31
|
+
const o = y(() => e.value && !a.value);
|
|
32
32
|
function d() {
|
|
33
33
|
e.value = !0, a.value = !1, i.value = void 0;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function c() {
|
|
36
36
|
n += 1, e.value = !1, a.value = !1, i.value = void 0;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function f() {
|
|
39
39
|
n += 1, e.value = !1, a.value = !0, i.value = "logout";
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function p(h) {
|
|
42
42
|
n += 1, e.value = !1, a.value = !0, i.value = h;
|
|
43
43
|
}
|
|
44
|
-
async function
|
|
44
|
+
async function g() {
|
|
45
45
|
if (a.value)
|
|
46
46
|
throw new Error("Session is expired: no refresh will be attempted");
|
|
47
|
-
return t ??= v(
|
|
47
|
+
return t ??= v(m).finally(() => {
|
|
48
48
|
t = void 0;
|
|
49
49
|
}), t;
|
|
50
50
|
}
|
|
51
51
|
async function v(h) {
|
|
52
52
|
const b = globalThis.navigator?.locks;
|
|
53
53
|
if (!b) return h();
|
|
54
|
-
await b.request(
|
|
54
|
+
await b.request($, h);
|
|
55
55
|
}
|
|
56
|
-
async function
|
|
57
|
-
const h = n, b = () => h !== n,
|
|
58
|
-
let
|
|
56
|
+
async function m() {
|
|
57
|
+
const h = n, b = () => h !== n, R = new URL(j, H()).href;
|
|
58
|
+
let r;
|
|
59
59
|
try {
|
|
60
|
-
|
|
60
|
+
r = await fetch(R, {
|
|
61
61
|
method: "POST",
|
|
62
62
|
credentials: "include"
|
|
63
63
|
});
|
|
64
|
-
} catch (
|
|
65
|
-
throw b() || C(),
|
|
64
|
+
} catch (u) {
|
|
65
|
+
throw b() || C(), u;
|
|
66
66
|
}
|
|
67
|
-
if (!
|
|
68
|
-
throw b() || (
|
|
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
69
|
if (b())
|
|
70
70
|
throw new Error("Session was dropped while the refresh was in flight");
|
|
71
71
|
d();
|
|
@@ -77,28 +77,28 @@ const V = "/auth/api/v2/login/token/refresh", J = "/auth/api/v2/", j = "cmc-auth
|
|
|
77
77
|
isOpen: e,
|
|
78
78
|
isExpired: a,
|
|
79
79
|
expiryReason: i,
|
|
80
|
-
isAuthenticated:
|
|
80
|
+
isAuthenticated: o,
|
|
81
81
|
open: d,
|
|
82
|
-
expire:
|
|
83
|
-
clear:
|
|
84
|
-
logout:
|
|
85
|
-
refresh:
|
|
82
|
+
expire: p,
|
|
83
|
+
clear: c,
|
|
84
|
+
logout: f,
|
|
85
|
+
refresh: g
|
|
86
86
|
};
|
|
87
87
|
});
|
|
88
|
-
function
|
|
88
|
+
function Q() {
|
|
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 Y(e) {
|
|
92
|
+
return (typeof e == "string" ? e : e instanceof URL ? e.href : e.url).includes(_);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function X() {
|
|
95
95
|
return async (e, a) => {
|
|
96
|
-
if (
|
|
96
|
+
if (Q()) return fetch(e, a);
|
|
97
97
|
const i = await fetch(e, a);
|
|
98
|
-
if (i.status !== 401 ||
|
|
98
|
+
if (i.status !== 401 || Y(e) || new Headers(a?.headers).has("Authorization")) return i;
|
|
99
99
|
let t;
|
|
100
100
|
try {
|
|
101
|
-
t =
|
|
101
|
+
t = W();
|
|
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 ge(e) {
|
|
115
|
+
const a = K(H(e), {
|
|
116
116
|
headers: {}
|
|
117
|
-
},
|
|
117
|
+
}, X());
|
|
118
118
|
function i(n) {
|
|
119
119
|
a.options.headers = {
|
|
120
120
|
...a.options.headers ?? {},
|
|
@@ -126,21 +126,21 @@ function fe(e) {
|
|
|
126
126
|
}
|
|
127
127
|
return { http: a, setToken: i, clearToken: t };
|
|
128
128
|
}
|
|
129
|
-
function
|
|
130
|
-
return e.replace(
|
|
129
|
+
function me(e, a) {
|
|
130
|
+
return e.replace(ee, (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 ee = /\{(\w+)\}/g;
|
|
138
|
+
function G(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 =
|
|
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
144
|
const u = r.id;
|
|
145
145
|
if (u === void 0)
|
|
146
146
|
throw new Error(
|
|
@@ -148,16 +148,16 @@ function ge(e) {
|
|
|
148
148
|
);
|
|
149
149
|
return u;
|
|
150
150
|
});
|
|
151
|
-
function
|
|
151
|
+
function c(r) {
|
|
152
152
|
return !!n.value[r];
|
|
153
153
|
}
|
|
154
|
-
async function
|
|
154
|
+
async function f(r, u) {
|
|
155
155
|
n.value[r] = u;
|
|
156
156
|
try {
|
|
157
|
-
const
|
|
158
|
-
return delete t.value[r],
|
|
159
|
-
} catch (
|
|
160
|
-
throw t.value[r] =
|
|
157
|
+
const s = await u;
|
|
158
|
+
return delete t.value[r], s;
|
|
159
|
+
} catch (s) {
|
|
160
|
+
throw t.value[r] = s, s;
|
|
161
161
|
} finally {
|
|
162
162
|
n.value[r] === u && delete n.value[r];
|
|
163
163
|
}
|
|
@@ -165,18 +165,18 @@ function ge(e) {
|
|
|
165
165
|
async function p(r, u = {}) {
|
|
166
166
|
if (!e.fetchOne)
|
|
167
167
|
throw new Error("useStore.retrieve called but fetchOne is not defined in store options");
|
|
168
|
-
const { force:
|
|
169
|
-
if (a.value[r] && !
|
|
168
|
+
const { force: s = !1 } = u;
|
|
169
|
+
if (a.value[r] && !s)
|
|
170
170
|
return a.value[r];
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
return
|
|
171
|
+
const l = n.value[r];
|
|
172
|
+
if (l)
|
|
173
|
+
return l;
|
|
174
174
|
const B = e.fetchOne, S = (async () => {
|
|
175
175
|
try {
|
|
176
|
-
const
|
|
177
|
-
return a.value[r] =
|
|
178
|
-
} catch (
|
|
179
|
-
t.value[r] =
|
|
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;
|
|
180
180
|
return;
|
|
181
181
|
} finally {
|
|
182
182
|
delete n.value[r];
|
|
@@ -184,93 +184,95 @@ function ge(e) {
|
|
|
184
184
|
})();
|
|
185
185
|
return n.value[r] = S, S;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
188
|
-
const u =
|
|
189
|
-
if (
|
|
187
|
+
function g(r) {
|
|
188
|
+
const u = G(r), s = i.value[u];
|
|
189
|
+
if (s)
|
|
190
190
|
return {
|
|
191
|
-
items:
|
|
192
|
-
total:
|
|
193
|
-
hasMore:
|
|
194
|
-
page:
|
|
195
|
-
limit:
|
|
191
|
+
items: s.itemIds.map((l) => a.value[l]).filter((l) => l !== void 0),
|
|
192
|
+
total: s.total,
|
|
193
|
+
hasMore: s.hasMore,
|
|
194
|
+
page: s.page,
|
|
195
|
+
limit: s.limit
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
async function
|
|
198
|
+
async function v(r, u = {}) {
|
|
199
199
|
if (!e.fetchPage)
|
|
200
200
|
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[
|
|
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
205
|
if (B)
|
|
206
|
-
return await B,
|
|
207
|
-
const S = e.fetchPage,
|
|
206
|
+
return await B, g(r);
|
|
207
|
+
const S = e.fetchPage, w = (async () => {
|
|
208
|
+
const k = o.value;
|
|
208
209
|
try {
|
|
209
|
-
const
|
|
210
|
-
for (const
|
|
211
|
-
const
|
|
212
|
-
a.value[
|
|
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);
|
|
213
214
|
}
|
|
214
|
-
i.value[
|
|
215
|
-
itemIds:
|
|
216
|
-
total:
|
|
217
|
-
hasMore:
|
|
218
|
-
page:
|
|
219
|
-
limit:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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;
|
|
223
225
|
} finally {
|
|
224
|
-
delete n.value[
|
|
226
|
+
delete n.value[s];
|
|
225
227
|
}
|
|
226
228
|
})();
|
|
227
|
-
return n.value[
|
|
229
|
+
return n.value[s] = w, await w, g(r);
|
|
228
230
|
}
|
|
229
|
-
async function
|
|
231
|
+
async function m(r, u = ae) {
|
|
230
232
|
if (!e.createMutation)
|
|
231
233
|
throw new Error("useStore.create called but createMutation is not defined in store options");
|
|
232
|
-
const
|
|
234
|
+
const s = e.createMutation, l = await f(u, (async () => s(r))()), B = e.enrichItem ? e.enrichItem(l) : l, S = d(B);
|
|
233
235
|
return a.value[S] = B, i.value = {}, B;
|
|
234
236
|
}
|
|
235
|
-
async function
|
|
237
|
+
async function C(r, u) {
|
|
236
238
|
if (!e.updateMutation)
|
|
237
239
|
throw new Error("useStore.update called but updateMutation is not defined in store options");
|
|
238
|
-
const
|
|
239
|
-
return a.value[r] = B, B;
|
|
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;
|
|
240
242
|
}
|
|
241
|
-
async function
|
|
243
|
+
async function h(r) {
|
|
242
244
|
if (!e.removeMutation)
|
|
243
245
|
throw new Error("useStore.remove called but removeMutation is not defined in store options");
|
|
244
246
|
const u = e.removeMutation;
|
|
245
|
-
await
|
|
246
|
-
for (const
|
|
247
|
-
const
|
|
248
|
-
|
|
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));
|
|
249
251
|
}
|
|
250
252
|
}
|
|
251
|
-
function
|
|
253
|
+
function b() {
|
|
252
254
|
t.value = {};
|
|
253
255
|
}
|
|
254
|
-
function
|
|
256
|
+
function R() {
|
|
255
257
|
a.value = {}, i.value = {}, t.value = {}, n.value = {};
|
|
256
258
|
}
|
|
257
|
-
return { items: a, views: i, errors: t, isPending:
|
|
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 };
|
|
258
260
|
}
|
|
259
|
-
function
|
|
261
|
+
function be(e, a) {
|
|
260
262
|
const i = (t) => {
|
|
261
|
-
const n = e.value,
|
|
262
|
-
!n || !
|
|
263
|
+
const n = e.value, o = t.target;
|
|
264
|
+
!n || !o || n.contains(o) || a();
|
|
263
265
|
};
|
|
264
|
-
|
|
266
|
+
N(() => {
|
|
265
267
|
document.addEventListener("click", i);
|
|
266
|
-
}),
|
|
268
|
+
}), F(() => {
|
|
267
269
|
document.removeEventListener("click", i);
|
|
268
270
|
});
|
|
269
271
|
}
|
|
270
|
-
function
|
|
272
|
+
function Be() {
|
|
271
273
|
const { locale: e } = E();
|
|
272
274
|
function a(i, t = null) {
|
|
273
|
-
const n =
|
|
275
|
+
const n = ne[i.trim().toUpperCase()];
|
|
274
276
|
if (!n)
|
|
275
277
|
throw new Error(`Unknown country code: ${i}`);
|
|
276
278
|
if (t && n[t])
|
|
@@ -283,7 +285,7 @@ function he() {
|
|
|
283
285
|
}
|
|
284
286
|
return a;
|
|
285
287
|
}
|
|
286
|
-
const
|
|
288
|
+
const ne = {
|
|
287
289
|
AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
|
|
288
290
|
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
291
|
AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
|
|
@@ -421,129 +423,129 @@ const ee = {
|
|
|
421
423
|
ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
|
|
422
424
|
ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
|
|
423
425
|
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 =
|
|
426
|
+
}, ve = ({ code: e, message: a, data: i }) => {
|
|
427
|
+
const t = a || "An unexpected error occurred", n = q({
|
|
426
428
|
statusCode: e,
|
|
427
429
|
statusMessage: t,
|
|
428
430
|
message: t,
|
|
429
431
|
data: i
|
|
430
432
|
});
|
|
431
|
-
throw
|
|
432
|
-
},
|
|
433
|
-
function
|
|
434
|
-
const { gtagId: e } =
|
|
433
|
+
throw Z(n), n;
|
|
434
|
+
}, ie = "ilcJCL_lmpwcEJfSkKND";
|
|
435
|
+
function Ae() {
|
|
436
|
+
const { gtagId: e } = V().public;
|
|
435
437
|
return { reportConversion: () => {
|
|
436
438
|
if (typeof window > "u" || typeof window.gtag > "u" || !e)
|
|
437
439
|
return;
|
|
438
|
-
const i = `${e}/${
|
|
440
|
+
const i = `${e}/${ie}`;
|
|
439
441
|
window.gtag("event", "conversion", {
|
|
440
442
|
send_to: i
|
|
441
443
|
});
|
|
442
444
|
} };
|
|
443
445
|
}
|
|
444
|
-
const
|
|
445
|
-
function
|
|
446
|
+
const z = "https://5509641.hs-sites-eu1.com";
|
|
447
|
+
function Ce() {
|
|
446
448
|
const { locale: e } = E();
|
|
447
|
-
return { contactUrl:
|
|
449
|
+
return { contactUrl: y(() => e.value === "fr" ? `${z}/contact` : `${z}/${e.value}/contact`) };
|
|
448
450
|
}
|
|
449
|
-
function
|
|
451
|
+
function we() {
|
|
450
452
|
async function e(t) {
|
|
451
453
|
await Promise.all(
|
|
452
454
|
t.map(
|
|
453
|
-
(n) => new Promise((
|
|
454
|
-
if (!n) return
|
|
455
|
+
(n) => new Promise((o) => {
|
|
456
|
+
if (!n) return o(null);
|
|
455
457
|
const d = new Image();
|
|
456
|
-
d.onload = () =>
|
|
458
|
+
d.onload = () => o(null), d.onerror = () => o(null), d.src = n;
|
|
457
459
|
})
|
|
458
460
|
)
|
|
459
461
|
);
|
|
460
462
|
}
|
|
461
463
|
function a(t, n) {
|
|
462
|
-
return n.split(".").reduce((
|
|
464
|
+
return n.split(".").reduce((o, d) => o && typeof o == "object" && d in o ? o[d] : "", t) ?? "";
|
|
463
465
|
}
|
|
464
|
-
function i(t, n,
|
|
466
|
+
function i(t, n, o) {
|
|
465
467
|
if (import.meta.server)
|
|
466
|
-
return async (
|
|
468
|
+
return async (c) => {
|
|
467
469
|
t.value = !0;
|
|
468
470
|
};
|
|
469
|
-
const d =
|
|
471
|
+
const d = J(
|
|
470
472
|
`${n}LoadedImageCache`,
|
|
471
473
|
() => ({})
|
|
472
474
|
);
|
|
473
|
-
return async (
|
|
474
|
-
if (!
|
|
475
|
+
return async (c) => {
|
|
476
|
+
if (!c) {
|
|
475
477
|
t.value = !1;
|
|
476
478
|
return;
|
|
477
479
|
}
|
|
478
|
-
const
|
|
479
|
-
if (d.value[
|
|
480
|
+
const f = o.map((v) => a(c, v)), p = `${n}|${f.join("|")}`;
|
|
481
|
+
if (d.value[p]) {
|
|
480
482
|
t.value = !0;
|
|
481
483
|
return;
|
|
482
484
|
}
|
|
483
485
|
t.value = !1;
|
|
484
|
-
const
|
|
485
|
-
await e(
|
|
486
|
+
const g = f.filter(Boolean).map(String);
|
|
487
|
+
await e(g), d.value[p] = !0, t.value = !0;
|
|
486
488
|
};
|
|
487
489
|
}
|
|
488
490
|
return i;
|
|
489
491
|
}
|
|
490
|
-
const
|
|
492
|
+
const te = {
|
|
491
493
|
en: ["US", "UK"]
|
|
492
|
-
},
|
|
493
|
-
function
|
|
494
|
+
}, re = "FR";
|
|
495
|
+
function oe(e) {
|
|
494
496
|
const a = e.trim().replace("_", "-"), [i, t] = a.split("-");
|
|
495
497
|
return {
|
|
496
498
|
language: i?.toLowerCase() ?? "",
|
|
497
499
|
region: t?.toUpperCase() ?? ""
|
|
498
500
|
};
|
|
499
501
|
}
|
|
500
|
-
function
|
|
502
|
+
function D(e) {
|
|
501
503
|
return e.toString().trim().toUpperCase();
|
|
502
504
|
}
|
|
503
|
-
function
|
|
505
|
+
function Me() {
|
|
504
506
|
function e(a, i) {
|
|
505
507
|
if (!i.length) return;
|
|
506
|
-
const t = i.map(
|
|
507
|
-
d &&
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
for (const
|
|
511
|
-
if (n.has(
|
|
512
|
-
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;
|
|
513
515
|
return t[0];
|
|
514
516
|
}
|
|
515
517
|
return { getRegionFromLocale: e };
|
|
516
518
|
}
|
|
517
|
-
function
|
|
519
|
+
function Se() {
|
|
518
520
|
const { t: e } = E();
|
|
519
521
|
function a(i, t) {
|
|
520
|
-
const n = e(i),
|
|
521
|
-
let
|
|
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);
|
|
522
524
|
for (; v; ) {
|
|
523
|
-
const { index:
|
|
524
|
-
|
|
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);
|
|
525
527
|
}
|
|
526
|
-
return
|
|
528
|
+
return g < n.length && o.push({ text: n.slice(g), ...p }), o;
|
|
527
529
|
}
|
|
528
530
|
return { parse: a };
|
|
529
531
|
}
|
|
530
|
-
function
|
|
531
|
-
const t =
|
|
532
|
+
function Ie(e, a, i = 768) {
|
|
533
|
+
const t = A(i - 1), n = y(
|
|
532
534
|
() => t.value >= i ? a : e
|
|
533
535
|
);
|
|
534
536
|
if (import.meta.client) {
|
|
535
|
-
const
|
|
537
|
+
const o = () => {
|
|
536
538
|
t.value = window.innerWidth;
|
|
537
539
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}),
|
|
541
|
-
window.removeEventListener("resize",
|
|
540
|
+
N(() => {
|
|
541
|
+
o(), window.addEventListener("resize", o);
|
|
542
|
+
}), O(() => {
|
|
543
|
+
window.removeEventListener("resize", o);
|
|
542
544
|
});
|
|
543
545
|
}
|
|
544
546
|
return { size: n, windowWidth: t };
|
|
545
547
|
}
|
|
546
|
-
function
|
|
548
|
+
function Ee() {
|
|
547
549
|
const { locale: e } = E();
|
|
548
550
|
function a(i, t = "fr") {
|
|
549
551
|
if (!i) return "";
|
|
@@ -553,21 +555,21 @@ function Se() {
|
|
|
553
555
|
return a;
|
|
554
556
|
}
|
|
555
557
|
export {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
|
573
575
|
};
|
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
|
+
* landing after that request makes the view stale, and the next `list()` on it
|
|
12
|
+
* 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,7 +62,7 @@ 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>;
|
|
62
67
|
/** Calls `removeMutation` (wrapped in `withPending(id)`), deletes `items[id]`, removes id from every view. */
|
|
63
68
|
remove: (id: Id) => Promise<void>;
|
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.9.1",
|
|
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
|
}
|