@choosemycompany/lib 0.5.0 → 0.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @choosemycompany/lib
2
2
 
3
- Composables, stores et types partagés entre les apps front ChooseMyCompany (`commercial`, `workspace`).
3
+ Composables, stores and types shared between the ChooseMyCompany front-end apps (`commercial`, `workspace`).
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,36 +8,41 @@ Composables, stores et types partagés entre les apps front ChooseMyCompany (`co
8
8
  pnpm add @choosemycompany/lib
9
9
  ```
10
10
 
11
- ## Utilisation
11
+ ## Usage
12
12
 
13
13
  ```ts
14
14
  import { useHttp, useStore, type Store, type View } from '@choosemycompany/lib'
15
15
  ```
16
16
 
17
- Un seul entry point, tout est ré-exporté depuis `@choosemycompany/lib`.
17
+ A single entry point: everything is re-exported from `@choosemycompany/lib`.
18
18
 
19
- ## Dépendances
19
+ ## Dependencies
20
20
 
21
- Le package s'attend à être consommé **dans un projet Nuxt 4** avec les peer deps suivantes installées :
21
+ The package expects to be consumed **inside a Nuxt 4 project**, with the following peer deps installed:
22
22
 
23
23
  - `vue`, `vue-i18n`, `vue-router`, `pinia`
24
- - `mande` (client HTTP)
25
- - `h3` (pour `useErrorHandling`)
24
+ - `mande` (HTTP client)
25
+ - `h3` (for `useErrorHandling`)
26
26
  - `@nuxtjs/i18n` (`useLocalePath`)
27
- - `nuxt` (pour `useRuntimeConfig`, `useState`, `showError` importés depuis `nuxt/app`)
27
+ - `nuxt` (for `useRuntimeConfig`, `useState`, `showError`, imported from `nuxt/app`)
28
28
 
29
- Les composables utilisant `useRuntimeConfig()`, `useRoute()`, `useI18n()` doivent être appelés dans un scope Nuxt (setup, plugin, middleware).
29
+ Composables using `useRuntimeConfig()`, `useRoute()` or `useI18n()` must be called inside a Nuxt scope (setup, plugin, middleware).
30
30
 
31
- ## Développement local (HMR via sandbox)
31
+ ## Local development (HMR through the sandbox)
32
32
 
33
33
  ```bash
34
- pnpm install
35
- pnpm --filter sandbox dev # n'existe pas : sandbox est indépendant
36
- # ou
37
34
  cd sandbox && pnpm install && pnpm dev
38
35
  ```
39
36
 
40
- La sandbox utilise un alias Vite `@choosemycompany/lib` → `../src/index.ts`, donc chaque modif des sources de la lib déclenche du HMR immédiat.
37
+ Then <http://localhost:3000>. The sandbox has its own `package.json` and its own lockfile: it is not part of a pnpm workspace, hence the `cd`.
38
+
39
+ The sandbox uses a Vite alias `@choosemycompany/lib` → `../src/index.ts`, so every change to the lib's sources triggers immediate HMR. A mock API is served by Nitro: `/api/philosophers` for `useHttp` + `useStore`, and an authentication backend for the `/auth` page.
40
+
41
+ ### The `/auth` page
42
+
43
+ It reproduces a session that expires, against a mocked auth backend: `POST /auth/api/v2/login`, `POST /auth/api/v2/login/token/refresh` 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
+
45
+ The scenario: sign in, call the protected API, expire the token, call again. The network trace shows what the lib does — or does not do — between the app's call and the response.
41
46
 
42
47
  ## Build & publish
43
48
 
@@ -45,10 +50,10 @@ La sandbox utilise un alias Vite `@choosemycompany/lib` → `../src/index.ts`, d
45
50
  pnpm build # vite build → dist/
46
51
  pnpm typecheck
47
52
  pnpm test
48
- pnpm publish # via CI CircleCI sur push main
53
+ pnpm publish # through CircleCI on a push to main
49
54
  ```
50
55
 
51
- ## Changements d'API notables
56
+ ## Notable API changes
52
57
 
53
- - `useStore` : signature unifiée qui absorbe la variante `workspace` (search, filters, 4ᵉ générique `FilterItem`). Méthode publique : `isPending(key)`. `getViewKey` trie les clés pour garantir un cache déterministe.
54
- - `usePrimaryTypeTranslation(primaryTypes)` : reçoit désormais la liste des primaryTypes en argument au lieu de l'importer depuis `@/entities/form` de commercial.
58
+ - `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.
59
+ - `usePrimaryTypeTranslation(primaryTypes)`: now receives the list of primary types as an argument instead of importing it from commercial's `@/entities/form`.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Base URLs the application declares to the library.
3
+ *
4
+ * `baseUrl` is what {@link useHttp} uses when the caller names no target.
5
+ * `targets` holds the other origins the app talks to, addressed by name.
6
+ */
7
+ export interface HttpConfig {
8
+ /** Base URL used by `useHttp()`. May carry a path prefix. */
9
+ baseUrl: string;
10
+ /** Extra origins, addressed by name: `useHttp('happy')`. */
11
+ targets?: Record<string, string>;
12
+ }
13
+ /**
14
+ * Declares the base URLs the library must use.
15
+ *
16
+ * The app owns its configuration. It reads its own keys — from
17
+ * `runtimeConfig`, from the environment, from anywhere — and it hands the
18
+ * result to the library. The library never reads the configuration of the app,
19
+ * so it imposes no key name and it needs no knowledge of the host framework.
20
+ *
21
+ * Call this once, as early as the app can: a Nuxt plugin, or the entry point of
22
+ * a non-Nuxt host.
23
+ *
24
+ * The key names below belong to the app, and to the app alone. This library
25
+ * names none of them, which is the whole point of the arrangement.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // app/plugins/00.http.ts
30
+ * const config = useRuntimeConfig()
31
+ *
32
+ * configureHttp({
33
+ * baseUrl: config.public.apiBaseUrl as string,
34
+ * targets: { reporting: config.public.reportingApiUrl as string },
35
+ * })
36
+ * ```
37
+ */
38
+ export declare function configureHttp(config: HttpConfig): void;
39
+ /**
40
+ * Returns the base URL for a target, or the default base URL when `target` is
41
+ * absent.
42
+ *
43
+ * Throws instead of returning `undefined`. A base URL that is missing builds
44
+ * request URLs such as `"undefined/api/v2/…"`, which fail far from their cause
45
+ * and read as a network problem once they do.
46
+ *
47
+ * Internal: the public surface is {@link configureHttp} and {@link useHttp}.
48
+ */
49
+ export declare function resolveBaseUrl(target?: string): string;
50
+ /**
51
+ * Test seam: drops the declaration so a suite can declare again between cases.
52
+ * Not part of the public API.
53
+ */
54
+ export declare function resetHttpConfig(): void;
@@ -1,11 +1,17 @@
1
1
  import { MandeInstance } from 'mande';
2
2
  /**
3
- * Returns a `mande` instance pre-configured against the CMC API base URL,
4
- * along with two helpers to attach/detach the `Authorization` bearer token.
3
+ * Returns a `mande` instance bound to one of the base URLs the app declared
4
+ * through `configureHttp`, along with two helpers to attach/detach the
5
+ * `Authorization` bearer token.
5
6
  *
6
7
  * The returned `http` instance exposes the standard `mande` verbs
7
- * (`get`, `post`, `put`, `patch`, `delete`) and is meant to be the only
8
- * way the lib (and downstream apps) talk to the CMC backend.
8
+ * (`get`, `post`, `put`, `patch`, `delete`) and is meant to be the only way the
9
+ * lib (and downstream apps) talk to an HTTP backend.
10
+ *
11
+ * @param target - Name of a declared target. Omit it for the default base URL,
12
+ * which is what almost every caller wants. Name one to reach
13
+ * another origin the app declared — the call site then holds no
14
+ * URL of its own, and no second HTTP client has to exist.
9
15
  *
10
16
  * @example
11
17
  * ```ts
@@ -15,8 +21,13 @@ import { MandeInstance } from 'mande';
15
21
  * const { item } = await http.get<RetrieveResponse<User>>('/me')
16
22
  * clearToken() // on logout
17
23
  * ```
24
+ *
25
+ * @example Another declared origin
26
+ * ```ts
27
+ * const { http } = useHttp('happy')
28
+ * ```
18
29
  */
19
- export declare function useHttp(): {
30
+ export declare function useHttp(target?: string): {
20
31
  http: MandeInstance;
21
32
  setToken: (token: string) => void;
22
33
  clearToken: () => void;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * re-exported here is considered internal and may change without notice.
6
6
  *
7
7
  * Grouped by concern:
8
- * - **HTTP** — {@link useHttp}: thin `mande` wrapper bound to the CMC API base URL.
8
+ * - **HTTP** — {@link configureHttp}: the app declares its base URLs;
9
+ * {@link useHttp}: thin `mande` wrapper bound to one of them.
9
10
  * - **Store** — {@link useStore}, {@link getViewKey}: typed cache for `retrieve` /
10
11
  * `list` workflows with single-flight, per-key errors, and CRUD mutations.
11
12
  * - **i18n** — locale-aware translators for plain strings, country names,
@@ -18,7 +19,8 @@
18
19
  * @packageDocumentation
19
20
  */
20
21
  export { useHttp } from './http/useHttp';
21
- export { useStore, getViewKey, type Store } from './store/useStore';
22
+ export { configureHttp, type HttpConfig } from './http/config';
23
+ export { useStore, getViewKey, CREATE_PENDING_KEY, type Store } from './store/useStore';
22
24
  export { useClickOutside } from './ui/useClickOutside';
23
25
  export { useCountriesTranslation, type CountryCodes } from './i18n/useCountriesTranslation';
24
26
  export { showAndThrowError } from './errors/useErrorHandling';
package/dist/index.js CHANGED
@@ -1,14 +1,31 @@
1
1
  import { mande as D } from "mande";
2
- import { useRuntimeConfig as L, showError as K, useState as H } from "nuxt/app";
3
- import { ref as v, onMounted as z, onBeforeUnmount as F, computed as N, onUnmounted as O } from "vue";
2
+ import { ref as M, onMounted as L, onBeforeUnmount as N, computed as z, onUnmounted as K } from "vue";
4
3
  import { useI18n as k } from "vue-i18n";
5
- import { createError as q } from "h3";
4
+ import { createError as H } from "h3";
5
+ import { showError as F, useRuntimeConfig as O, useState as q } from "nuxt/app";
6
6
  let w;
7
- function Z() {
8
- return w || (w = L().public.cmcApiUrl, w);
7
+ function ea(a) {
8
+ if (!a.baseUrl)
9
+ throw new Error("@choosemycompany/lib: configureHttp() needs a non-empty baseUrl");
10
+ w = a;
11
+ }
12
+ function Z(a) {
13
+ if (!w)
14
+ throw new Error(
15
+ "@choosemycompany/lib: useHttp() was called before configureHttp(). Declare the base URLs from an app plugin."
16
+ );
17
+ if (a === void 0) return w.baseUrl;
18
+ const i = w.targets ?? {}, t = Object.hasOwn(i, a) ? i[a] : void 0;
19
+ if (typeof t != "string" || !t) {
20
+ const n = Object.keys(i), e = n.length > 0 ? n.join(", ") : "none";
21
+ throw new Error(
22
+ `@choosemycompany/lib: no HTTP target named "${a}". Declared targets: ${e}.`
23
+ );
24
+ }
25
+ return t;
9
26
  }
10
- function aa() {
11
- const a = Z(), i = D(a, {
27
+ function na(a) {
28
+ const i = D(Z(a), {
12
29
  headers: {}
13
30
  });
14
31
  function t(e) {
@@ -25,8 +42,9 @@ function aa() {
25
42
  function T(a) {
26
43
  return Object.entries(a).sort(([i], [t]) => i.localeCompare(t)).map(([i, t]) => `${i}=${t}`).join("|");
27
44
  }
28
- function ea(a) {
29
- const i = v({}), t = v({}), n = v({}), e = v({}), s = a.getItemId ?? ((r) => {
45
+ const x = "create";
46
+ function ia(a) {
47
+ const i = M({}), t = M({}), n = M({}), e = M({}), s = a.getItemId ?? ((r) => {
30
48
  const d = r.id;
31
49
  if (d === void 0)
32
50
  throw new Error(
@@ -34,10 +52,10 @@ function ea(a) {
34
52
  );
35
53
  return d;
36
54
  });
37
- function l(r) {
55
+ function c(r) {
38
56
  return !!e.value[r];
39
57
  }
40
- async function c(r, d) {
58
+ async function l(r, d) {
41
59
  e.value[r] = d;
42
60
  try {
43
61
  const o = await d;
@@ -45,10 +63,10 @@ function ea(a) {
45
63
  } catch (o) {
46
64
  throw n.value[r] = o, o;
47
65
  } finally {
48
- delete e.value[r];
66
+ e.value[r] === d && delete e.value[r];
49
67
  }
50
68
  }
51
- async function f(r, d = {}) {
69
+ async function g(r, d = {}) {
52
70
  if (!a.fetchOne)
53
71
  throw new Error("useStore.retrieve called but fetchOne is not defined in store options");
54
72
  const { force: o = !1 } = d;
@@ -57,18 +75,18 @@ function ea(a) {
57
75
  const u = e.value[r];
58
76
  if (u)
59
77
  return u;
60
- const B = a.fetchOne, S = (async () => {
78
+ const f = a.fetchOne, A = (async () => {
61
79
  try {
62
- const A = await B(r), b = a.enrichItem ? a.enrichItem(A) : A;
63
- return i.value[r] = b, delete n.value[r], i.value[r];
64
- } catch (A) {
65
- n.value[r] = A;
80
+ const C = await f(r), h = a.enrichItem ? a.enrichItem(C) : C;
81
+ return i.value[r] = h, delete n.value[r], i.value[r];
82
+ } catch (C) {
83
+ n.value[r] = C;
66
84
  return;
67
85
  } finally {
68
86
  delete e.value[r];
69
87
  }
70
88
  })();
71
- return e.value[r] = S, S;
89
+ return e.value[r] = A, A;
72
90
  }
73
91
  function p(r) {
74
92
  const d = T(r), o = t.value[d];
@@ -81,82 +99,82 @@ function ea(a) {
81
99
  limit: o.limit
82
100
  };
83
101
  }
84
- async function m(r, d = {}) {
102
+ async function b(r, d = {}) {
85
103
  if (!a.fetchPage)
86
104
  throw new Error("useStore.list called but fetchPage is not defined in store options");
87
105
  const o = T(r), { force: u = !1 } = d;
88
106
  if (t.value[o] && !u)
89
107
  return p(r);
90
- const B = e.value[o];
91
- if (B)
92
- return await B, p(r);
93
- const S = a.fetchPage, A = (async () => {
108
+ const f = e.value[o];
109
+ if (f)
110
+ return await f, p(r);
111
+ const A = a.fetchPage, C = (async () => {
94
112
  try {
95
- const b = await S(r), R = [];
96
- for (const E of b.items) {
97
- const y = a.enrichItem ? a.enrichItem(E) : E, P = s(y);
98
- i.value[P] = y, R.push(P);
113
+ const h = await A(r), E = [];
114
+ for (const R of h.items) {
115
+ const y = a.enrichItem ? a.enrichItem(R) : R, P = s(y);
116
+ i.value[P] = y, E.push(P);
99
117
  }
100
118
  t.value[o] = {
101
- itemIds: R,
102
- total: b.total,
103
- hasMore: b.hasMore,
104
- page: b.page,
105
- limit: b.limit
119
+ itemIds: E,
120
+ total: h.total,
121
+ hasMore: h.hasMore,
122
+ page: h.page,
123
+ limit: h.limit
106
124
  }, delete n.value[o];
107
- } catch (b) {
108
- n.value[o] = b;
125
+ } catch (h) {
126
+ n.value[o] = h;
109
127
  } finally {
110
128
  delete e.value[o];
111
129
  }
112
130
  })();
113
- return e.value[o] = A, await A, p(r);
131
+ return e.value[o] = C, await C, p(r);
114
132
  }
115
- async function h(r) {
133
+ async function B(r, d = x) {
116
134
  if (!a.createMutation)
117
135
  throw new Error("useStore.create called but createMutation is not defined in store options");
118
- const d = await a.createMutation(r), o = a.enrichItem ? a.enrichItem(d) : d, u = s(o);
119
- return i.value[u] = o, t.value = {}, o;
136
+ const o = a.createMutation, u = await l(d, (async () => o(r))()), f = a.enrichItem ? a.enrichItem(u) : u, A = s(f);
137
+ return i.value[A] = f, t.value = {}, f;
120
138
  }
121
- async function g(r, d) {
139
+ async function m(r, d) {
122
140
  if (!a.updateMutation)
123
141
  throw new Error("useStore.update called but updateMutation is not defined in store options");
124
- const o = a.updateMutation, u = await c(r, (async () => o(r, d))()), B = a.enrichItem ? a.enrichItem(u) : u;
125
- return i.value[r] = B, B;
142
+ const o = a.updateMutation, u = await l(r, (async () => o(r, d))()), f = a.enrichItem ? a.enrichItem(u) : u;
143
+ return i.value[r] = f, f;
126
144
  }
127
- async function C(r) {
145
+ async function v(r) {
128
146
  if (!a.removeMutation)
129
147
  throw new Error("useStore.remove called but removeMutation is not defined in store options");
130
148
  const d = a.removeMutation;
131
- await c(r, (async () => d(r))()), delete i.value[r];
149
+ await l(r, (async () => d(r))()), delete i.value[r];
132
150
  for (const o of Object.values(t.value)) {
133
151
  const u = o.itemIds.indexOf(r);
134
152
  u !== -1 && (o.itemIds.splice(u, 1), o.total = Math.max(0, o.total - 1));
135
153
  }
136
154
  }
137
- function M() {
155
+ function I() {
138
156
  n.value = {};
139
157
  }
140
- function I() {
158
+ function S() {
141
159
  i.value = {}, t.value = {}, n.value = {}, e.value = {};
142
160
  }
143
- return { items: i, views: t, errors: n, isPending: l, list: m, reset: I, retrieve: f, getView: p, withPending: c, create: h, update: g, remove: C, clearErrors: M };
161
+ return { items: i, views: t, errors: n, isPending: c, list: b, reset: S, retrieve: g, getView: p, withPending: l, create: B, update: m, remove: v, clearErrors: I };
144
162
  }
145
- function na(a, i) {
163
+ function ta(a, i) {
146
164
  const t = (n) => {
147
165
  const e = a.value, s = n.target;
148
166
  !e || !s || e.contains(s) || i();
149
167
  };
150
- z(() => {
168
+ L(() => {
151
169
  document.addEventListener("click", t);
152
- }), F(() => {
170
+ }), N(() => {
153
171
  document.removeEventListener("click", t);
154
172
  });
155
173
  }
156
- function ia() {
174
+ function ra() {
157
175
  const { locale: a } = k();
158
176
  function i(t, n = null) {
159
- const e = x[t.trim().toUpperCase()];
177
+ const e = V[t.trim().toUpperCase()];
160
178
  if (!e)
161
179
  throw new Error(`Unknown country code: ${t}`);
162
180
  if (n && e[n])
@@ -169,7 +187,7 @@ function ia() {
169
187
  }
170
188
  return i;
171
189
  }
172
- const x = {
190
+ const V = {
173
191
  AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
174
192
  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" },
175
193
  AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
@@ -307,76 +325,76 @@ const x = {
307
325
  ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
308
326
  ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
309
327
  ZW: { en: "Zimbabwe", fr: "Zimbabwe", es: "Zimbabue", de: "Simbabwe", it: "Zimbabwe", pt: "Zimbábue", da: "Zimbabwe" }
310
- }, ta = ({ code: a, message: i, data: t }) => {
311
- const n = i || "An unexpected error occurred", e = q({
328
+ }, oa = ({ code: a, message: i, data: t }) => {
329
+ const n = i || "An unexpected error occurred", e = H({
312
330
  statusCode: a,
313
331
  statusMessage: n,
314
332
  message: n,
315
333
  data: t
316
334
  });
317
- throw K(e), e;
318
- }, V = "ilcJCL_lmpwcEJfSkKND";
319
- function ra() {
320
- const { gtagId: a } = L().public;
335
+ throw F(e), e;
336
+ }, J = "ilcJCL_lmpwcEJfSkKND";
337
+ function sa() {
338
+ const { gtagId: a } = O().public;
321
339
  return { reportConversion: () => {
322
340
  if (typeof window > "u" || typeof window.gtag > "u" || !a)
323
341
  return;
324
- const t = `${a}/${V}`;
342
+ const t = `${a}/${J}`;
325
343
  window.gtag("event", "conversion", {
326
344
  send_to: t
327
345
  });
328
346
  } };
329
347
  }
330
348
  const U = "https://5509641.hs-sites-eu1.com";
331
- function oa() {
349
+ function da() {
332
350
  const { locale: a } = k();
333
- return { contactUrl: N(() => a.value === "fr" ? `${U}/contact` : `${U}/${a.value}/contact`) };
351
+ return { contactUrl: z(() => a.value === "fr" ? `${U}/contact` : `${U}/${a.value}/contact`) };
334
352
  }
335
- function sa() {
353
+ function ua() {
336
354
  async function a(n) {
337
355
  await Promise.all(
338
356
  n.map(
339
357
  (e) => new Promise((s) => {
340
358
  if (!e) return s(null);
341
- const l = new Image();
342
- l.onload = () => s(null), l.onerror = () => s(null), l.src = e;
359
+ const c = new Image();
360
+ c.onload = () => s(null), c.onerror = () => s(null), c.src = e;
343
361
  })
344
362
  )
345
363
  );
346
364
  }
347
365
  function i(n, e) {
348
- return e.split(".").reduce((s, l) => s && typeof s == "object" && l in s ? s[l] : "", n) ?? "";
366
+ return e.split(".").reduce((s, c) => s && typeof s == "object" && c in s ? s[c] : "", n) ?? "";
349
367
  }
350
368
  function t(n, e, s) {
351
369
  if (import.meta.server)
352
- return async (c) => {
370
+ return async (l) => {
353
371
  n.value = !0;
354
372
  };
355
- const l = H(
373
+ const c = q(
356
374
  `${e}LoadedImageCache`,
357
375
  () => ({})
358
376
  );
359
- return async (c) => {
360
- if (!c) {
377
+ return async (l) => {
378
+ if (!l) {
361
379
  n.value = !1;
362
380
  return;
363
381
  }
364
- const f = s.map((h) => i(c, h)), p = `${e}|${f.join("|")}`;
365
- if (l.value[p]) {
382
+ const g = s.map((B) => i(l, B)), p = `${e}|${g.join("|")}`;
383
+ if (c.value[p]) {
366
384
  n.value = !0;
367
385
  return;
368
386
  }
369
387
  n.value = !1;
370
- const m = f.filter(Boolean).map(String);
371
- await a(m), l.value[p] = !0, n.value = !0;
388
+ const b = g.filter(Boolean).map(String);
389
+ await a(b), c.value[p] = !0, n.value = !0;
372
390
  };
373
391
  }
374
392
  return t;
375
393
  }
376
- const J = {
394
+ const j = {
377
395
  en: ["US", "UK"]
378
- }, j = "FR";
379
- function $(a) {
396
+ }, $ = "FR";
397
+ function _(a) {
380
398
  const i = a.trim().replace("_", "-"), [t, n] = i.split("-");
381
399
  return {
382
400
  language: t?.toLowerCase() ?? "",
@@ -386,50 +404,50 @@ function $(a) {
386
404
  function G(a) {
387
405
  return a.toString().trim().toUpperCase();
388
406
  }
389
- function da() {
407
+ function la() {
390
408
  function a(i, t) {
391
409
  if (!t.length) return;
392
- const n = t.map(G), e = new Set(n), { language: s, region: l } = $(i), c = [];
393
- l && c.push(l);
394
- const f = J[s];
395
- f?.length && c.push(...f.map(G)), s && c.push(s.toUpperCase()), c.push(j);
396
- for (const p of c)
410
+ const n = t.map(G), e = new Set(n), { language: s, region: c } = _(i), l = [];
411
+ c && l.push(c);
412
+ const g = j[s];
413
+ g?.length && l.push(...g.map(G)), s && l.push(s.toUpperCase()), l.push($);
414
+ for (const p of l)
397
415
  if (e.has(p))
398
416
  return p;
399
417
  return n[0];
400
418
  }
401
419
  return { getRegionFromLocale: a };
402
420
  }
403
- function ua() {
421
+ function ca() {
404
422
  const { t: a } = k();
405
423
  function i(t, n) {
406
- const e = a(t), s = [], c = n.map((g) => g.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), f = new RegExp(`\\[(${c})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), p = n.reduce((g, C) => (g[C] = !1, g), {});
407
- let m = 0, h = f.exec(e);
408
- for (; h; ) {
409
- const { index: g, 0: C, 1: M, 2: I } = h;
410
- g > m && s.push({ text: e.slice(m, g), ...p }), I && M && s.push({ text: I, ...p, [M]: !0 }), m = g + C.length, h = f.exec(e);
424
+ const e = a(t), s = [], l = n.map((m) => m.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), g = new RegExp(`\\[(${l})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), p = n.reduce((m, v) => (m[v] = !1, m), {});
425
+ let b = 0, B = g.exec(e);
426
+ for (; B; ) {
427
+ const { index: m, 0: v, 1: I, 2: S } = B;
428
+ m > b && s.push({ text: e.slice(b, m), ...p }), S && I && s.push({ text: S, ...p, [I]: !0 }), b = m + v.length, B = g.exec(e);
411
429
  }
412
- return m < e.length && s.push({ text: e.slice(m), ...p }), s;
430
+ return b < e.length && s.push({ text: e.slice(b), ...p }), s;
413
431
  }
414
432
  return { parse: i };
415
433
  }
416
- function la(a, i, t = 768) {
417
- const n = v(t - 1), e = N(
434
+ function pa(a, i, t = 768) {
435
+ const n = M(t - 1), e = z(
418
436
  () => n.value >= t ? i : a
419
437
  );
420
438
  if (import.meta.client) {
421
439
  const s = () => {
422
440
  n.value = window.innerWidth;
423
441
  };
424
- z(() => {
442
+ L(() => {
425
443
  s(), window.addEventListener("resize", s);
426
- }), O(() => {
444
+ }), K(() => {
427
445
  window.removeEventListener("resize", s);
428
446
  });
429
447
  }
430
448
  return { size: e, windowWidth: n };
431
449
  }
432
- function ca() {
450
+ function fa() {
433
451
  const { locale: a } = k();
434
452
  function i(t, n = "fr") {
435
453
  if (!t) return "";
@@ -439,17 +457,19 @@ function ca() {
439
457
  return i;
440
458
  }
441
459
  export {
460
+ x as CREATE_PENDING_KEY,
461
+ ea as configureHttp,
442
462
  T as getViewKey,
443
- ta as showAndThrowError,
444
- na as useClickOutside,
445
- ia as useCountriesTranslation,
446
- ra as useGtagConversion,
447
- aa as useHttp,
448
- oa as useHubspotContactUrl,
449
- sa as useImageCacheWatcherCallback,
450
- da as useLocaleHelpers,
451
- ua as useParseTranslation,
452
- la as useResponsiveSize,
453
- ea as useStore,
454
- ca as useTranslate
463
+ oa as showAndThrowError,
464
+ ta as useClickOutside,
465
+ ra as useCountriesTranslation,
466
+ sa as useGtagConversion,
467
+ na as useHttp,
468
+ da as useHubspotContactUrl,
469
+ ua as useImageCacheWatcherCallback,
470
+ la as useLocaleHelpers,
471
+ ca as useParseTranslation,
472
+ pa as useResponsiveSize,
473
+ ia as useStore,
474
+ fa as useTranslate
455
475
  };
@@ -56,7 +56,7 @@ export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePa
56
56
  /** Wraps an arbitrary promise in the store's pending + error lifecycle under `key`. */
57
57
  withPending: <T>(key: ViewKey | Id, promise: Promise<T>) => Promise<T>;
58
58
  /** Calls `createMutation`, inserts the item into `items`, and invalidates all views. */
59
- create: (payload: CreatePayload) => Promise<Item>;
59
+ create: (payload: CreatePayload, key?: ViewKey | Id) => Promise<Item>;
60
60
  /** Calls `updateMutation` (wrapped in `withPending(id)`), replaces `items[id]`. */
61
61
  update: (id: Id, patch: UpdatePatch) => Promise<Item>;
62
62
  /** Calls `removeMutation` (wrapped in `withPending(id)`), deletes `items[id]`, removes id from every view. */
@@ -85,5 +85,6 @@ export type Store<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePa
85
85
  * await store.update('org-42', { name: 'Acme Inc.' })
86
86
  * ```
87
87
  */
88
+ export declare const CREATE_PENDING_KEY = "create";
88
89
  export declare function useStore<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePayload = Item, UpdatePatch = Partial<Item>>(options: StoreOptions<Id, Item, Params, CreatePayload, UpdatePatch>): Store<Id, Item, Params, CreatePayload, UpdatePatch>;
89
90
  export {};
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.5.0",
4
+ "version": "0.7.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "packageManager": "pnpm@10.17.0",