@choosemycompany/lib 0.1.0 → 0.2.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.
Files changed (42) hide show
  1. package/README.md +2 -3
  2. package/dist/analytics/useGtagConversion.d.ts +36 -0
  3. package/dist/analytics/useHubspotContactUrl.d.ts +25 -0
  4. package/dist/errors/useErrorHandling.d.ts +36 -0
  5. package/dist/http/types.d.ts +113 -0
  6. package/dist/http/useHttp.d.ts +23 -0
  7. package/dist/i18n/types.d.ts +37 -0
  8. package/dist/i18n/useCountriesTranslation.d.ts +46 -0
  9. package/dist/{useLocaleHelpers.d.ts → i18n/useLocaleHelpers.d.ts} +5 -0
  10. package/dist/i18n/useParseTranslation.d.ts +45 -0
  11. package/dist/i18n/usePrimaryTypeTranslation.d.ts +34 -0
  12. package/dist/i18n/useTranslate.d.ts +32 -0
  13. package/dist/index.d.ts +35 -15
  14. package/dist/index.js +225 -191
  15. package/dist/store/types.d.ts +94 -0
  16. package/dist/store/useStore.d.ts +94 -0
  17. package/dist/ui/useClickOutside.d.ts +39 -0
  18. package/dist/ui/useImageCacheWatcherCallback.d.ts +34 -0
  19. package/dist/ui/useResponsiveSize.d.ts +33 -0
  20. package/package.json +13 -11
  21. package/dist/types/errors.d.ts +0 -15
  22. package/dist/types/index.d.ts +0 -8
  23. package/dist/types/language.d.ts +0 -2
  24. package/dist/types/pagination.d.ts +0 -12
  25. package/dist/types/request.d.ts +0 -7
  26. package/dist/types/response.d.ts +0 -8
  27. package/dist/types/routes.d.ts +0 -6
  28. package/dist/types/store.d.ts +0 -15
  29. package/dist/types/view.d.ts +0 -12
  30. package/dist/useClickOutside.d.ts +0 -2
  31. package/dist/useCountriesTranslation.d.ts +0 -6
  32. package/dist/useErrorHandling.d.ts +0 -5
  33. package/dist/useGtagConversion.d.ts +0 -8
  34. package/dist/useHttp.d.ts +0 -6
  35. package/dist/useHubspotContactUrl.d.ts +0 -3
  36. package/dist/useImageCacheWatcherCallback.d.ts +0 -2
  37. package/dist/useParseTranslation.d.ts +0 -6
  38. package/dist/usePrimaryTypeTranslation.d.ts +0 -3
  39. package/dist/useResponsiveSize.d.ts +0 -4
  40. package/dist/useStore.d.ts +0 -20
  41. package/dist/useTranslate.d.ts +0 -4
  42. package/dist/useUrlHelpers.d.ts +0 -8
package/dist/index.js CHANGED
@@ -1,113 +1,175 @@
1
- import { mande as P } from "mande";
2
- import { useRuntimeConfig as S, showError as w, useState as T, useLocalePath as E } from "#imports";
3
- import { ref as h, onMounted as I, onBeforeUnmount as y, computed as R, onUnmounted as L } from "vue";
4
- import { useI18n as C } from "vue-i18n";
5
- import { createError as z } from "h3";
6
- import { useRoute as G } from "vue-router";
7
- import { withBase as D } from "ufo";
8
- let A;
9
- function N() {
10
- return A || (A = S().public.cmcApiUrl, A);
1
+ import { mande as H } from "mande";
2
+ import { useRuntimeConfig as G, showError as F, useState as O } from "nuxt/app";
3
+ import { ref as A, onMounted as z, onBeforeUnmount as q, computed as N, onUnmounted as Z } from "vue";
4
+ import { useI18n as M } from "vue-i18n";
5
+ import { createError as x } from "h3";
6
+ let w;
7
+ function V() {
8
+ return w || (w = G().public.cmcApiUrl, w);
11
9
  }
12
- function Q() {
13
- const a = N(), e = P(a, {
10
+ function na() {
11
+ const a = V(), n = H(a, {
14
12
  headers: {}
15
13
  });
16
- function t(n) {
17
- e.options.headers = {
18
- ...e.options.headers ?? {},
19
- Authorization: `Bearer ${n}`
14
+ function t(e) {
15
+ n.options.headers = {
16
+ ...n.options.headers ?? {},
17
+ Authorization: `Bearer ${e}`
20
18
  };
21
19
  }
22
20
  function i() {
23
- e.options.headers && delete e.options.headers.Authorization;
21
+ n.options.headers && delete n.options.headers.Authorization;
24
22
  }
25
- return { http: e, setToken: t, clearToken: i };
23
+ return { http: n, setToken: t, clearToken: i };
26
24
  }
27
- function K(a) {
28
- return Object.entries(a).sort(([e], [t]) => e.localeCompare(t)).map(([e, t]) => `${e}=${t}`).join("|");
25
+ function P(a) {
26
+ return Object.entries(a).sort(([n], [t]) => n.localeCompare(t)).map(([n, t]) => `${n}=${t}`).join("|");
29
27
  }
30
- function Y(a) {
31
- const e = h({}), t = h({}), i = h([]), n = h({}), r = h(""), d = h([]);
32
- function s(c) {
33
- return !!n.value[c];
28
+ function ia(a) {
29
+ const n = A({}), t = A({}), i = A({}), e = A({}), o = A(""), d = A([]), l = a.getItemId ?? ((r) => {
30
+ const u = r.id;
31
+ if (u === void 0)
32
+ throw new Error(
33
+ "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."
34
+ );
35
+ return u;
36
+ });
37
+ function f(r) {
38
+ return !!e.value[r];
34
39
  }
35
- async function l(c, f = {}) {
36
- const u = c, { force: b = !1 } = f;
37
- if (e.value[u] && !b)
38
- return e.value[u];
39
- if (!a.fetchOne || s(u))
40
- return e.value[u] ?? void 0;
41
- n.value[u] = !0;
40
+ async function p(r, u) {
41
+ e.value[r] = u;
42
42
  try {
43
- const o = await a.fetchOne(c), B = a.enrichItem ? a.enrichItem(o) : o;
44
- return e.value[u] = B, e.value[u];
45
- } catch (o) {
46
- i.value.push(o);
47
- return;
43
+ const s = await u;
44
+ return delete i.value[r], s;
45
+ } catch (s) {
46
+ throw i.value[r] = s, s;
48
47
  } finally {
49
- n.value[u] = !1;
48
+ delete e.value[r];
50
49
  }
51
50
  }
52
- async function p(c, f = {}) {
53
- const u = K(c), { force: b = !1 } = f;
54
- if (!(t.value[u] && !b) && !(!a.fetchPage || s(u))) {
55
- n.value[u] = !0;
51
+ async function b(r, u = {}) {
52
+ if (!a.fetchOne)
53
+ throw new Error("useStore.retrieve called but fetchOne is not defined in store options");
54
+ const { force: s = !1 } = u;
55
+ if (n.value[r] && !s)
56
+ return n.value[r];
57
+ const c = e.value[r];
58
+ if (c)
59
+ return c;
60
+ const B = a.fetchOne, k = (async () => {
56
61
  try {
57
- const o = await a.fetchPage(c), B = o.items.map(
58
- (m) => a.enrichItem ? a.enrichItem(m) : m
59
- );
60
- for (const m of B) {
61
- const M = a.getItemId(m);
62
- e.value[M] = m;
62
+ const C = await B(r), h = a.enrichItem ? a.enrichItem(C) : C;
63
+ return n.value[r] = h, delete i.value[r], n.value[r];
64
+ } catch (C) {
65
+ i.value[r] = C;
66
+ return;
67
+ } finally {
68
+ delete e.value[r];
69
+ }
70
+ })();
71
+ return e.value[r] = k, k;
72
+ }
73
+ function g(r) {
74
+ const u = P(r), s = t.value[u];
75
+ if (s)
76
+ return {
77
+ items: s.itemIds.map((c) => n.value[c]).filter((c) => c !== void 0),
78
+ total: s.total,
79
+ hasMore: s.hasMore,
80
+ page: s.page,
81
+ limit: s.limit
82
+ };
83
+ }
84
+ async function m(r, u = {}) {
85
+ if (!a.fetchPage)
86
+ throw new Error("useStore.list called but fetchPage is not defined in store options");
87
+ const s = P(r), { force: c = !1 } = u;
88
+ if (t.value[s] && !c)
89
+ return g(r);
90
+ const B = e.value[s];
91
+ if (B)
92
+ return await B, g(r);
93
+ const k = a.fetchPage, C = (async () => {
94
+ try {
95
+ const h = await k(r), R = [];
96
+ for (const E of h.items) {
97
+ const y = a.enrichItem ? a.enrichItem(E) : E, T = l(y);
98
+ n.value[T] = y, R.push(T);
63
99
  }
64
- t.value[u] = {
65
- items: B,
66
- total: o.total,
67
- hasMore: o.hasMore,
68
- page: o.page,
69
- limit: o.limit
70
- };
71
- } catch (o) {
72
- i.value.push(o);
100
+ t.value[s] = {
101
+ itemIds: R,
102
+ total: h.total,
103
+ hasMore: h.hasMore,
104
+ page: h.page,
105
+ limit: h.limit
106
+ }, delete i.value[s];
107
+ } catch (h) {
108
+ i.value[s] = h;
73
109
  } finally {
74
- n.value[u] = !1;
110
+ delete e.value[s];
75
111
  }
112
+ })();
113
+ return e.value[s] = C, await C, g(r);
114
+ }
115
+ async function v(r) {
116
+ if (!a.createMutation)
117
+ throw new Error("useStore.create called but createMutation is not defined in store options");
118
+ const u = await a.createMutation(r), s = a.enrichItem ? a.enrichItem(u) : u, c = l(s);
119
+ return n.value[c] = s, t.value = {}, s;
120
+ }
121
+ async function I(r, u) {
122
+ if (!a.updateMutation)
123
+ throw new Error("useStore.update called but updateMutation is not defined in store options");
124
+ const s = a.updateMutation, c = await p(r, (async () => s(r, u))()), B = a.enrichItem ? a.enrichItem(c) : c;
125
+ return n.value[r] = B, B;
126
+ }
127
+ async function S(r) {
128
+ if (!a.removeMutation)
129
+ throw new Error("useStore.remove called but removeMutation is not defined in store options");
130
+ const u = a.removeMutation;
131
+ await p(r, (async () => u(r))()), delete n.value[r];
132
+ for (const s of Object.values(t.value)) {
133
+ const c = s.itemIds.indexOf(r);
134
+ c !== -1 && (s.itemIds.splice(c, 1), s.total = Math.max(0, s.total - 1));
76
135
  }
77
136
  }
78
- function g() {
79
- e.value = {}, t.value = {}, i.value = [], n.value = {}, r.value = "", d.value = [];
137
+ function D() {
138
+ i.value = {};
139
+ }
140
+ function K() {
141
+ n.value = {}, t.value = {}, i.value = {}, e.value = {}, o.value = "", d.value = [];
80
142
  }
81
- return { items: e, views: t, errors: i, search: r, filters: d, isPending: s, list: p, reset: g, retrieve: l };
143
+ return { items: n, views: t, errors: i, search: o, filters: d, isPending: f, list: m, reset: K, retrieve: b, getView: g, track: p, create: v, update: I, remove: S, clearErrors: D };
82
144
  }
83
- function X(a, e) {
145
+ function ta(a, n) {
84
146
  const t = (i) => {
85
- const n = a.value, r = i.target;
86
- !n || !r || n.contains(r) || e();
147
+ const e = a.value, o = i.target;
148
+ !e || !o || e.contains(o) || n();
87
149
  };
88
- I(() => {
150
+ z(() => {
89
151
  document.addEventListener("click", t);
90
- }), y(() => {
152
+ }), q(() => {
91
153
  document.removeEventListener("click", t);
92
154
  });
93
155
  }
94
- function aa() {
95
- const { locale: a } = C();
96
- function e(t, i = null) {
97
- const n = H[t.trim().toUpperCase()];
98
- if (!n)
156
+ function ra() {
157
+ const { locale: a } = M();
158
+ function n(t, i = null) {
159
+ const e = J[t.trim().toUpperCase()];
160
+ if (!e)
99
161
  throw new Error(`Unknown country code: ${t}`);
100
- if (i && n[i])
101
- return n[i];
102
- if (n[a.value])
103
- return n[a.value];
104
- if (a.value !== "en" && n.en)
105
- return n.en;
162
+ if (i && e[i])
163
+ return e[i];
164
+ if (e[a.value])
165
+ return e[a.value];
166
+ if (a.value !== "en" && e.en)
167
+ return e.en;
106
168
  throw new Error(`Unknown country code: ${t}`);
107
169
  }
108
- return e;
170
+ return n;
109
171
  }
110
- const H = {
172
+ const J = {
111
173
  AD: { en: "Andorra", fr: "Andorre", es: "Andorra", de: "Andorra", it: "Andorra", pt: "Andorra", da: "Andorra" },
112
174
  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" },
113
175
  AF: { en: "Afghanistan", fr: "Afghanistan", es: "Afganistán", de: "Afghanistan", it: "Afghanistan", pt: "Afeganistão", da: "Afghanistan" },
@@ -245,188 +307,160 @@ const H = {
245
307
  ZA: { en: "South Africa", fr: "Afrique Du Sud", es: "Sudáfrica", de: "Südafrika", it: "Sudafrica", pt: "África Do Sul", da: "Sydafrika" },
246
308
  ZM: { en: "Zambia", fr: "Zambie", es: "Zambia", de: "Sambia", it: "Zambia", pt: "Zâmbia", da: "Zambia" },
247
309
  ZW: { en: "Zimbabwe", fr: "Zimbabwe", es: "Zimbabue", de: "Simbabwe", it: "Zimbabwe", pt: "Zimbábue", da: "Zimbabwe" }
248
- }, ea = ({ code: a, message: e, data: t }) => {
249
- const i = e || "An unexpected error occurred", n = z({
310
+ }, oa = ({ code: a, message: n, data: t }) => {
311
+ const i = n || "An unexpected error occurred", e = x({
250
312
  statusCode: a,
251
313
  statusMessage: i,
252
314
  message: i,
253
315
  data: t
254
316
  });
255
- throw w(n), n;
256
- }, F = "ilcJCL_lmpwcEJfSkKND";
257
- function na() {
258
- const { gtagId: a } = S().public;
317
+ throw F(e), e;
318
+ }, $ = "ilcJCL_lmpwcEJfSkKND";
319
+ function sa() {
320
+ const { gtagId: a } = G().public;
259
321
  return { reportConversion: () => {
260
322
  if (typeof window > "u" || typeof window.gtag > "u" || !a)
261
323
  return;
262
- const t = `${a}/${F}`;
324
+ const t = `${a}/${$}`;
263
325
  window.gtag("event", "conversion", {
264
326
  send_to: t
265
327
  });
266
328
  } };
267
329
  }
268
- const v = "https://5509641.hs-sites-eu1.com";
269
- function ia() {
270
- const { locale: a } = C();
271
- return { contactUrl: R(() => a.value === "fr" ? `${v}/contact` : `${v}/${a.value}/contact`) };
330
+ const U = "https://5509641.hs-sites-eu1.com";
331
+ function da() {
332
+ const { locale: a } = M();
333
+ return { contactUrl: N(() => a.value === "fr" ? `${U}/contact` : `${U}/${a.value}/contact`) };
272
334
  }
273
- function ta() {
335
+ function ua() {
274
336
  async function a(i) {
275
337
  await Promise.all(
276
338
  i.map(
277
- (n) => new Promise((r) => {
278
- if (!n) return r(null);
339
+ (e) => new Promise((o) => {
340
+ if (!e) return o(null);
279
341
  const d = new Image();
280
- d.onload = () => r(null), d.onerror = () => r(null), d.src = n;
342
+ d.onload = () => o(null), d.onerror = () => o(null), d.src = e;
281
343
  })
282
344
  )
283
345
  );
284
346
  }
285
- function e(i, n) {
286
- return n.split(".").reduce((r, d) => r && typeof r == "object" && d in r ? r[d] : "", i) ?? "";
347
+ function n(i, e) {
348
+ return e.split(".").reduce((o, d) => o && typeof o == "object" && d in o ? o[d] : "", i) ?? "";
287
349
  }
288
- function t(i, n, r) {
350
+ function t(i, e, o) {
289
351
  if (import.meta.server)
290
- return async (s) => {
352
+ return async (l) => {
291
353
  i.value = !0;
292
354
  };
293
- const d = T(
294
- `${n}LoadedImageCache`,
355
+ const d = O(
356
+ `${e}LoadedImageCache`,
295
357
  () => ({})
296
358
  );
297
- return async (s) => {
298
- if (!s) {
359
+ return async (l) => {
360
+ if (!l) {
299
361
  i.value = !1;
300
362
  return;
301
363
  }
302
- const l = r.map((c) => e(s, c)), p = `${n}|${l.join("|")}`;
364
+ const f = o.map((g) => n(l, g)), p = `${e}|${f.join("|")}`;
303
365
  if (d.value[p]) {
304
366
  i.value = !0;
305
367
  return;
306
368
  }
307
369
  i.value = !1;
308
- const g = l.filter(Boolean).map(String);
309
- await a(g), d.value[p] = !0, i.value = !0;
370
+ const b = f.filter(Boolean).map(String);
371
+ await a(b), d.value[p] = !0, i.value = !0;
310
372
  };
311
373
  }
312
374
  return t;
313
375
  }
314
- const q = {
376
+ const j = {
315
377
  en: ["US", "UK"]
316
- }, Z = "FR";
317
- function $(a) {
318
- const e = a.trim().replace("_", "-"), [t, i] = e.split("-");
378
+ }, _ = "FR";
379
+ function W(a) {
380
+ const n = a.trim().replace("_", "-"), [t, i] = n.split("-");
319
381
  return {
320
382
  language: t?.toLowerCase() ?? "",
321
383
  region: i?.toUpperCase() ?? ""
322
384
  };
323
385
  }
324
- function k(a) {
386
+ function L(a) {
325
387
  return a.toString().trim().toUpperCase();
326
388
  }
327
- function ra() {
328
- function a(e, t) {
389
+ function la() {
390
+ function a(n, t) {
329
391
  if (!t.length) return;
330
- const i = t.map(k), n = new Set(i), { language: r, region: d } = $(e), s = [];
331
- d && s.push(d);
332
- const l = q[r];
333
- l?.length && s.push(...l.map(k)), r && s.push(r.toUpperCase()), s.push(Z);
334
- for (const p of s)
335
- if (n.has(p))
392
+ const i = t.map(L), e = new Set(i), { language: o, region: d } = W(n), l = [];
393
+ d && l.push(d);
394
+ const f = j[o];
395
+ f?.length && l.push(...f.map(L)), o && l.push(o.toUpperCase()), l.push(_);
396
+ for (const p of l)
397
+ if (e.has(p))
336
398
  return p;
337
399
  return i[0];
338
400
  }
339
401
  return { getRegionFromLocale: a };
340
402
  }
341
- function oa() {
342
- const { t: a } = C();
343
- function e(t, i) {
344
- const n = a(t), r = [], s = i.map((f) => f.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), l = new RegExp(`\\[(${s})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), p = i.reduce((f, u) => (f[u] = !1, f), {});
345
- let g = 0, c = l.exec(n);
346
- for (; c; ) {
347
- const { index: f, 0: u, 1: b, 2: o } = c;
348
- f > g && r.push({ text: n.slice(g, f), ...p }), o && b && r.push({ text: o, ...p, [b]: !0 }), g = f + u.length, c = l.exec(n);
403
+ function ca() {
404
+ const { t: a } = M();
405
+ function n(t, i) {
406
+ const e = a(t), o = [], l = i.map((m) => m.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), f = new RegExp(`\\[(${l})\\]([\\s\\S]*?)\\[\\/\\1\\]`, "g"), p = i.reduce((m, v) => (m[v] = !1, m), {});
407
+ let b = 0, g = f.exec(e);
408
+ for (; g; ) {
409
+ const { index: m, 0: v, 1: I, 2: S } = g;
410
+ m > b && o.push({ text: e.slice(b, m), ...p }), S && I && o.push({ text: S, ...p, [I]: !0 }), b = m + v.length, g = f.exec(e);
349
411
  }
350
- return g < n.length && r.push({ text: n.slice(g), ...p }), r;
412
+ return b < e.length && o.push({ text: e.slice(b), ...p }), o;
351
413
  }
352
- return { parse: e };
414
+ return { parse: n };
353
415
  }
354
- function sa(a) {
355
- const { t: e, te: t, tm: i } = C();
356
- function n(r, d) {
357
- const s = `${r}.${d}`, l = `${r}.${a[0]}`;
358
- return t(s) ? e(s) : t(l) ? e(l) : typeof i(r) == "string" ? e(r, {
359
- primaryType: e(`common.primary-type.${d}`).toLowerCase()
416
+ function pa(a) {
417
+ const { t: n, te: t, tm: i } = M();
418
+ function e(o, d) {
419
+ const l = `${o}.${d}`, f = `${o}.${a[0]}`;
420
+ return t(l) ? n(l) : t(f) ? n(f) : typeof i(o) == "string" ? n(o, {
421
+ primaryType: n(`common.primary-type.${d}`).toLowerCase()
360
422
  }) : "";
361
423
  }
362
- return { getPrimaryTypeTranslation: n };
424
+ return { getPrimaryTypeTranslation: e };
363
425
  }
364
- function da(a, e, t = 768) {
365
- const i = h(t - 1), n = R(
366
- () => i.value >= t ? e : a
426
+ function fa(a, n, t = 768) {
427
+ const i = A(t - 1), e = N(
428
+ () => i.value >= t ? n : a
367
429
  );
368
430
  if (import.meta.client) {
369
- const r = () => {
431
+ const o = () => {
370
432
  i.value = window.innerWidth;
371
433
  };
372
- I(() => {
373
- r(), window.addEventListener("resize", r);
374
- }), L(() => {
375
- window.removeEventListener("resize", r);
434
+ z(() => {
435
+ o(), window.addEventListener("resize", o);
436
+ }), Z(() => {
437
+ window.removeEventListener("resize", o);
376
438
  });
377
439
  }
378
- return { size: n, windowWidth: i };
440
+ return { size: e, windowWidth: i };
379
441
  }
380
- function ua() {
381
- const { locale: a } = C();
382
- function e(t, i = "fr") {
442
+ function ga() {
443
+ const { locale: a } = M();
444
+ function n(t, i = "fr") {
383
445
  if (!t) return "";
384
- const n = a.value;
385
- return t[n] ?? t[i] ?? "";
386
- }
387
- return e;
388
- }
389
- function la() {
390
- const a = S(), { locale: e } = C(), t = G(), i = E(), n = a.public.cmcAssetsUrl, r = a.public.cmcCorporateWebsiteUrl, d = a.public.siteUrl;
391
- function s(o) {
392
- return `${n}${o}`;
393
- }
394
- const l = s("/img/public-site/default-banner.png"), p = s("/img/public-site/default-logo.png");
395
- function g(o) {
396
- return o || l;
397
- }
398
- function c(o) {
399
- return o || p;
400
- }
401
- function f(o) {
402
- return `${r}${o}`;
403
- }
404
- function u(o) {
405
- return `${d}/${e.value}/${o}`;
406
- }
407
- function b(o = "home") {
408
- const B = String(t.name || "");
409
- if (B === o || B.startsWith(`${o}__`) || B.startsWith(`${o}___`))
410
- return;
411
- const m = i(o), M = `/${e.value}`, U = !m || m === "/" || m.startsWith("/_") ? M : m;
412
- return D(U, a.app.baseURL);
446
+ const e = a.value;
447
+ return t[e] ?? t[i] ?? "";
413
448
  }
414
- return { getCoverUrl: g, getLogoUrl: c, getCorporateUrl: f, getAssetsUrl: s, getSiteUrl: u, getHomeUrl: b };
449
+ return n;
415
450
  }
416
451
  export {
417
- K as getViewKey,
418
- ea as showAndThrowError,
419
- X as useClickOutside,
420
- aa as useCountriesTranslation,
421
- na as useGtagConversion,
422
- Q as useHttp,
423
- ia as useHubspotContactUrl,
424
- ta as useImageCacheWatcherCallback,
425
- ra as useLocaleHelpers,
426
- oa as useParseTranslation,
427
- sa as usePrimaryTypeTranslation,
428
- da as useResponsiveSize,
429
- Y as useStore,
430
- ua as useTranslate,
431
- la as useUrlHelpers
452
+ P as getViewKey,
453
+ oa as showAndThrowError,
454
+ ta as useClickOutside,
455
+ ra as useCountriesTranslation,
456
+ sa as useGtagConversion,
457
+ na as useHttp,
458
+ da as useHubspotContactUrl,
459
+ ua as useImageCacheWatcherCallback,
460
+ la as useLocaleHelpers,
461
+ ca as useParseTranslation,
462
+ pa as usePrimaryTypeTranslation,
463
+ fa as useResponsiveSize,
464
+ ia as useStore,
465
+ ga as useTranslate
432
466
  };
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Shared types for {@link useStore}. Kept in their own module so consumers can
3
+ * `import type` without dragging in the runtime composable.
4
+ */
5
+ /**
6
+ * Required shape every paginated query must satisfy. Acts as a constraint on
7
+ * the `Params` generic of {@link useStore} so the store can deterministically
8
+ * key a view from arbitrary user-defined query objects.
9
+ */
10
+ export type ViewKeyParams = {
11
+ page: number;
12
+ limit: number;
13
+ };
14
+ /**
15
+ * Resolved view exposed by `list()` and `getView()`. Combines the original
16
+ * `{ page, limit }` query with the materialized items and pagination meta.
17
+ *
18
+ * @typeParam Item - Shape of an individual list item.
19
+ */
20
+ export type View<Item> = ViewKeyParams & {
21
+ /** Items belonging to this page, in API-returned order. */
22
+ items: Item[];
23
+ /** Total number of items across all pages. */
24
+ total: number;
25
+ /** `true` if more pages exist after the current one. */
26
+ hasMore: boolean;
27
+ };
28
+ /**
29
+ * Reserved for future "infinite scroll vs. paginated" switching. Currently
30
+ * unused by the implementation — declared here to lock the public surface.
31
+ */
32
+ export type ViewOptions = {
33
+ infinite?: boolean;
34
+ };
35
+ /**
36
+ * Permitted shape for an item identifier. Restricting to `string | number`
37
+ * keeps `Record<Id, Item>` indexing tractable on TypeScript ≥ 5 strict mode.
38
+ */
39
+ export type IdKey = string | number;
40
+ /**
41
+ * Configuration passed to {@link useStore}. Every field is optional — fetchers
42
+ * and mutations only need to be supplied for the corresponding `retrieve` /
43
+ * `list` / `create` / `update` / `remove` methods to work.
44
+ *
45
+ * @typeParam Id - Item identifier type (string or number).
46
+ * @typeParam Item - Item shape stored in the cache.
47
+ * @typeParam Params - User-defined paginated query shape (must extend {@link ViewKeyParams}).
48
+ * @typeParam CreatePayload - Shape passed to `createMutation` (defaults to `Item`).
49
+ * @typeParam UpdatePatch - Shape passed to `updateMutation` (defaults to `Partial<Item>`).
50
+ */
51
+ export type StoreOptions<Id extends IdKey, Item, Params extends ViewKeyParams, CreatePayload = Item, UpdatePatch = Partial<Item>> = {
52
+ /** Default query parameters. Held for reference, never read by the store itself. */
53
+ params?: Params;
54
+ /**
55
+ * Computes the cache key for an item. Defaults to `(item) => item.id` and
56
+ * throws if `id` is missing on an item, so always provide this when items
57
+ * use a non-standard identifier (`uuid`, `slug`, composite key, …).
58
+ */
59
+ getItemId?: (item: Item) => Id;
60
+ /** Fetches a single item by id. Required to call `retrieve()`. */
61
+ fetchOne?: (id: Id) => Promise<Item>;
62
+ /** Fetches one page. Required to call `list()`. */
63
+ fetchPage?: (params: Params) => Promise<View<Item>>;
64
+ /**
65
+ * Transformation applied to every item before it lands in `items`. Also runs
66
+ * on items returned by `createMutation` and `updateMutation`. Identity by default.
67
+ */
68
+ enrichItem?: (item: Item) => Item;
69
+ /** Persists a new item server-side. Required to call `create()`. */
70
+ createMutation?: (payload: CreatePayload) => Promise<Item>;
71
+ /** Patches an existing item server-side. Required to call `update()`. */
72
+ updateMutation?: (id: Id, patch: UpdatePatch) => Promise<Item>;
73
+ /** Deletes an item server-side. Required to call `remove()`. */
74
+ removeMutation?: (id: Id) => Promise<void>;
75
+ /**
76
+ * Cache time-to-live in milliseconds. Reserved for future use — currently
77
+ * **not implemented**; cached entries live until `reset()` is called.
78
+ */
79
+ ttlMs?: number;
80
+ };
81
+ /**
82
+ * Options accepted by `retrieve()`.
83
+ */
84
+ export type RetrieveOptions = {
85
+ /** When `true`, bypass the cache and fetch even if the item is already known. */
86
+ force?: boolean;
87
+ };
88
+ /**
89
+ * Options accepted by `list()`.
90
+ */
91
+ export type ListOptions = {
92
+ /** When `true`, bypass the cache and fetch even if the view is already known. */
93
+ force?: boolean;
94
+ };