@laconius/core 0.1.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 (90) hide show
  1. package/LICENSE +73 -0
  2. package/README.md +31 -0
  3. package/lib/module/auth.js +182 -0
  4. package/lib/module/auth.js.map +1 -0
  5. package/lib/module/client.js +99 -0
  6. package/lib/module/client.js.map +1 -0
  7. package/lib/module/config.js +72 -0
  8. package/lib/module/config.js.map +1 -0
  9. package/lib/module/converters.js +31 -0
  10. package/lib/module/converters.js.map +1 -0
  11. package/lib/module/create-config.js +36 -0
  12. package/lib/module/create-config.js.map +1 -0
  13. package/lib/module/endpoints.js +89 -0
  14. package/lib/module/endpoints.js.map +1 -0
  15. package/lib/module/errors.js +76 -0
  16. package/lib/module/errors.js.map +1 -0
  17. package/lib/module/i18n.js +84 -0
  18. package/lib/module/i18n.js.map +1 -0
  19. package/lib/module/index.js +18 -0
  20. package/lib/module/index.js.map +1 -0
  21. package/lib/module/media.js +182 -0
  22. package/lib/module/media.js.map +1 -0
  23. package/lib/module/models.js +2 -0
  24. package/lib/module/models.js.map +1 -0
  25. package/lib/module/package.json +1 -0
  26. package/lib/module/provider.js +182 -0
  27. package/lib/module/provider.js.map +1 -0
  28. package/lib/module/runtime.js +43 -0
  29. package/lib/module/runtime.js.map +1 -0
  30. package/lib/module/single-flight.js +23 -0
  31. package/lib/module/single-flight.js.map +1 -0
  32. package/lib/module/site-context.js +74 -0
  33. package/lib/module/site-context.js.map +1 -0
  34. package/lib/module/stores.js +66 -0
  35. package/lib/module/stores.js.map +1 -0
  36. package/lib/module/translations.js +42 -0
  37. package/lib/module/translations.js.map +1 -0
  38. package/lib/typescript/package.json +1 -0
  39. package/lib/typescript/src/auth.d.ts +31 -0
  40. package/lib/typescript/src/auth.d.ts.map +1 -0
  41. package/lib/typescript/src/client.d.ts +31 -0
  42. package/lib/typescript/src/client.d.ts.map +1 -0
  43. package/lib/typescript/src/config.d.ts +150 -0
  44. package/lib/typescript/src/config.d.ts.map +1 -0
  45. package/lib/typescript/src/converters.d.ts +17 -0
  46. package/lib/typescript/src/converters.d.ts.map +1 -0
  47. package/lib/typescript/src/create-config.d.ts +11 -0
  48. package/lib/typescript/src/create-config.d.ts.map +1 -0
  49. package/lib/typescript/src/endpoints.d.ts +36 -0
  50. package/lib/typescript/src/endpoints.d.ts.map +1 -0
  51. package/lib/typescript/src/errors.d.ts +43 -0
  52. package/lib/typescript/src/errors.d.ts.map +1 -0
  53. package/lib/typescript/src/i18n.d.ts +20 -0
  54. package/lib/typescript/src/i18n.d.ts.map +1 -0
  55. package/lib/typescript/src/index.d.ts +17 -0
  56. package/lib/typescript/src/index.d.ts.map +1 -0
  57. package/lib/typescript/src/media.d.ts +81 -0
  58. package/lib/typescript/src/media.d.ts.map +1 -0
  59. package/lib/typescript/src/models.d.ts +327 -0
  60. package/lib/typescript/src/models.d.ts.map +1 -0
  61. package/lib/typescript/src/provider.d.ts +37 -0
  62. package/lib/typescript/src/provider.d.ts.map +1 -0
  63. package/lib/typescript/src/runtime.d.ts +26 -0
  64. package/lib/typescript/src/runtime.d.ts.map +1 -0
  65. package/lib/typescript/src/single-flight.d.ts +7 -0
  66. package/lib/typescript/src/single-flight.d.ts.map +1 -0
  67. package/lib/typescript/src/site-context.d.ts +28 -0
  68. package/lib/typescript/src/site-context.d.ts.map +1 -0
  69. package/lib/typescript/src/stores.d.ts +54 -0
  70. package/lib/typescript/src/stores.d.ts.map +1 -0
  71. package/lib/typescript/src/translations.d.ts +40 -0
  72. package/lib/typescript/src/translations.d.ts.map +1 -0
  73. package/package.json +77 -0
  74. package/src/auth.ts +223 -0
  75. package/src/client.ts +133 -0
  76. package/src/config.ts +191 -0
  77. package/src/converters.ts +47 -0
  78. package/src/create-config.ts +29 -0
  79. package/src/endpoints.ts +133 -0
  80. package/src/errors.ts +104 -0
  81. package/src/i18n.ts +108 -0
  82. package/src/index.ts +123 -0
  83. package/src/media.ts +209 -0
  84. package/src/models.ts +384 -0
  85. package/src/provider.tsx +229 -0
  86. package/src/runtime.ts +57 -0
  87. package/src/single-flight.ts +23 -0
  88. package/src/site-context.ts +77 -0
  89. package/src/stores.ts +94 -0
  90. package/src/translations.ts +40 -0
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ import { DEFAULT_OCC_PREFIX } from "./config.js";
4
+
5
+ /**
6
+ * Core's own endpoints: site context. Every value is a URL with its query string, never a bare
7
+ * path, so field selection lives in the template rather than at the call site.
8
+ *
9
+ * `baseSites` is the one endpoint built without the base-site segment.
10
+ */
11
+ export const defaultCoreEndpoints = {
12
+ baseSites: 'basesites?fields=FULL',
13
+ languages: 'languages',
14
+ currencies: 'currencies',
15
+ countries: 'countries',
16
+ regions: 'countries/${isoCode}/regions?fields=regions(name,isocode,isocodeShort)'
17
+ };
18
+
19
+ /** Endpoints that are addressed outside the base-site segment. */
20
+ const SITE_LESS_ENDPOINTS = new Set(['baseSites']);
21
+ /**
22
+ * Named scope -> `default` scope -> plain string -> `undefined`.
23
+ *
24
+ * Spartacus' final fallback — using the endpoint key itself as the path — is deliberately
25
+ * dropped: it turns a configuration mistake into a mysterious 404.
26
+ */
27
+ export function resolveEndpointValue(endpoints, key, scope) {
28
+ const value = endpoints[key];
29
+ if (value === undefined) return undefined;
30
+ if (typeof value === 'string') return value;
31
+ if (scope && value[scope] !== undefined) return value[scope];
32
+ return value['default'];
33
+ }
34
+ function interpolate(template, urlParams = {}) {
35
+ return template.replace(/\$\{(\w+)\}/g, (_match, name) => {
36
+ const value = urlParams[name];
37
+ if (value === undefined) {
38
+ throw new Error(`[laconius] Missing url parameter "${name}" for endpoint template "${template}".`);
39
+ }
40
+ return encodeURIComponent(String(value));
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Merges `queryParams` into the query string the template already carries, caller wins.
46
+ *
47
+ * Template values are kept verbatim — an OCC `fields` expression is already in the shape the
48
+ * backend wants, and re-encoding its parentheses breaks it.
49
+ */
50
+ export function mergeQueryString(template, queryParams = {}) {
51
+ const separator = template.indexOf('?');
52
+ const path = separator === -1 ? template : template.slice(0, separator);
53
+ const existing = separator === -1 ? '' : template.slice(separator + 1);
54
+ const params = new Map();
55
+ for (const pair of existing.split('&')) {
56
+ if (!pair) continue;
57
+ const equals = pair.indexOf('=');
58
+ if (equals === -1) params.set(pair, '');else params.set(pair.slice(0, equals), pair.slice(equals + 1));
59
+ }
60
+ for (const [key, value] of Object.entries(queryParams)) {
61
+ if (value === undefined) continue;
62
+ params.set(encodeURIComponent(key), encodeURIComponent(String(value)));
63
+ }
64
+ const query = [...params].map(([key, value]) => value === '' ? key : `${key}=${value}`).join('&');
65
+ return query ? `${path}?${query}` : path;
66
+ }
67
+ export function createEndpointResolver(config) {
68
+ const endpoints = config.backend.occ.endpoints ?? {};
69
+ const {
70
+ baseUrl,
71
+ baseSite
72
+ } = config.backend.occ;
73
+ const prefix = config.backend.occ.prefix ?? DEFAULT_OCC_PREFIX;
74
+ return {
75
+ isConfigured(key, scope) {
76
+ return resolveEndpointValue(endpoints, key, scope) !== undefined;
77
+ },
78
+ getEndpoint(key, params = {}, scope) {
79
+ const template = resolveEndpointValue(endpoints, key, scope);
80
+ if (template === undefined) {
81
+ throw new Error(`[laconius] No endpoint configured for "${key}"${scope ? ` (scope "${scope}")` : ''}. Add it to backend.occ.endpoints.`);
82
+ }
83
+ const resolved = mergeQueryString(interpolate(template, params.urlParams), params.queryParams);
84
+ const site = SITE_LESS_ENDPOINTS.has(key) ? '' : `/${baseSite}`;
85
+ return `${baseUrl.replace(/\/$/, '')}${prefix}${site}/${resolved}`;
86
+ }
87
+ };
88
+ }
89
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_OCC_PREFIX","defaultCoreEndpoints","baseSites","languages","currencies","countries","regions","SITE_LESS_ENDPOINTS","Set","resolveEndpointValue","endpoints","key","scope","value","undefined","interpolate","template","urlParams","replace","_match","name","Error","encodeURIComponent","String","mergeQueryString","queryParams","separator","indexOf","path","slice","existing","params","Map","pair","split","equals","set","Object","entries","query","map","join","createEndpointResolver","config","backend","occ","baseUrl","baseSite","prefix","isConfigured","getEndpoint","resolved","site","has"],"sourceRoot":"../../src","sources":["endpoints.ts"],"mappings":";;AAAA,SACEA,kBAAkB,QAIb,aAAU;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAGZ,GAAG;EACFC,SAAS,EAAE,uBAAuB;EAClCC,SAAS,EAAE,WAAW;EACtBC,UAAU,EAAE,YAAY;EACxBC,SAAS,EAAE,WAAW;EACtBC,OAAO,EAAE;AACX,CAAC;;AAED;AACA,MAAMC,mBAAmB,GAAG,IAAIC,GAAG,CAAS,CAAC,WAAW,CAAC,CAAC;AAS1D;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAClCC,SAAiD,EACjDC,GAAW,EACXC,KAAc,EACM;EACpB,MAAMC,KAAK,GAAGH,SAAS,CAACC,GAAG,CAAC;EAC5B,IAAIE,KAAK,KAAKC,SAAS,EAAE,OAAOA,SAAS;EACzC,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE,OAAOA,KAAK;EAC3C,IAAID,KAAK,IAAIC,KAAK,CAACD,KAAK,CAAC,KAAKE,SAAS,EAAE,OAAOD,KAAK,CAACD,KAAK,CAAC;EAC5D,OAAOC,KAAK,CAAC,SAAS,CAAC;AACzB;AAEA,SAASE,WAAWA,CAClBC,QAAgB,EAChBC,SAA0C,GAAG,CAAC,CAAC,EACvC;EACR,OAAOD,QAAQ,CAACE,OAAO,CAAC,cAAc,EAAE,CAACC,MAAM,EAAEC,IAAY,KAAK;IAChE,MAAMP,KAAK,GAAGI,SAAS,CAACG,IAAI,CAAC;IAC7B,IAAIP,KAAK,KAAKC,SAAS,EAAE;MACvB,MAAM,IAAIO,KAAK,CACb,qCAAqCD,IAAI,4BAA4BJ,QAAQ,IAC/E,CAAC;IACH;IACA,OAAOM,kBAAkB,CAACC,MAAM,CAACV,K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GAAG,CAAC,GAAG,EAAE,GAAG,IAAIoC,QAAQ,EAAE;MAC/D,OAAO,GAAGD,OAAO,CAAC5B,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG8B,MAAM,GAAGI,IAAI,IAAID,QAAQ,EAAE;IACpE;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ /** One entry of OCC's `errors[]` envelope. `type` is open-ended and customer-extensible. */
4
+
5
+ /**
6
+ * The one error type Laconius throws for a failed request.
7
+ *
8
+ * An OCC business error is data, not a status code: `InsufficientStockError` and a network
9
+ * timeout are the same `status` to a shopper who needs to be told different things.
10
+ */
11
+ export class LaconiusHttpError extends Error {
12
+ /** 0 when the request never reached the server. */
13
+
14
+ /** Parsed `errors[]`, empty when the payload carried none. */
15
+
16
+ /** Raw payload, for the app's telemetry. */
17
+
18
+ constructor(init) {
19
+ const occErrors = init.occErrors ?? [];
20
+ super(init.message ?? occErrors[0]?.message ?? `Request to ${init.url} failed with status ${init.status}`);
21
+ this.name = 'LaconiusHttpError';
22
+ this.status = init.status;
23
+ this.url = init.url;
24
+ this.occErrors = occErrors;
25
+ this.body = init.body;
26
+ }
27
+ }
28
+
29
+ /** Parses OCC's `errors[]` envelope out of an arbitrary payload. */
30
+ export function parseOccErrors(body) {
31
+ if (typeof body !== 'object' || body === null) return [];
32
+ const errors = body.errors;
33
+ if (!Array.isArray(errors)) return [];
34
+ return errors.filter(entry => typeof entry === 'object' && entry !== null);
35
+ }
36
+
37
+ /** `getOccError(error)` for the first one, `getOccError(error, 'InsufficientStockError')` to match. */
38
+ export function getOccError(error, type) {
39
+ if (!(error instanceof LaconiusHttpError)) return undefined;
40
+ if (type === undefined) return error.occErrors[0];
41
+ return error.occErrors.find(occError => occError.type === type);
42
+ }
43
+ const STATUS_KEYS = {
44
+ 400: 'badRequest',
45
+ 401: 'unauthorized',
46
+ 403: 'forbidden',
47
+ 404: 'notFound',
48
+ 409: 'conflict'
49
+ };
50
+
51
+ /**
52
+ * A translated sentence for a shopper:
53
+ * OCC `type`/`reason` -> OCC `type` -> status class -> unknown.
54
+ *
55
+ * Never falls through to a raw backend string: that leaks internals and is untranslated by
56
+ * definition.
57
+ */
58
+ export function getErrorMessage(error, t) {
59
+ const unknown = 'errors.http.unknown';
60
+ if (!(error instanceof LaconiusHttpError)) return t(unknown);
61
+ const occError = error.occErrors[0];
62
+ if (occError?.type) {
63
+ if (occError.reason) {
64
+ const key = `errors.occ.${occError.type}.${occError.reason}`;
65
+ const message = t(key);
66
+ if (message !== key) return message;
67
+ }
68
+ const key = `errors.occ.${occError.type}`;
69
+ const message = t(key);
70
+ if (message !== key) return message;
71
+ }
72
+ if (error.status === 0) return t('errors.http.offline');
73
+ const statusKey = STATUS_KEYS[error.status] ?? (error.status >= 500 ? 'serverError' : undefined);
74
+ return statusKey ? t(`errors.http.${statusKey}`) : t(unknown);
75
+ }
76
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["LaconiusHttpError","Error","constructor","init","occErrors","message","url","status","name","body","parseOccErrors","errors","Array","isArray","filter","entry","getOccError","error","type","undefined","find","occError","STATUS_KEYS","getErrorMessage","t","unknown","reason","key","statusKey"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;AAAA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,iBAAiB,SAASC,KAAK,CAAC;EAC3C;;EAGA;;EAEA;;EAGAC,WAAWA,CAACC,IAMX,EAAE;IACD,MAAMC,SAAS,GAAGD,IAAI,CAACC,SAAS,IAAI,EAAE;IACtC,KAAK,CACHD,IAAI,CAACE,OAAO,IACVD,SAAS,CAAC,CAAC,CAAC,EAAEC,OAAO,IACrB,cAAcF,IAAI,CAACG,GAAG,uBAAuBH,IAAI,CAACI,MAAM,EAC5D,CAAC;IACD,IAAI,CAACC,IAAI,GAAG,mBAAmB;IAC/B,IAAI,CAACD,MAAM,GAAGJ,IAAI,CAACI,MAA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K,CAACb,SAAS,CAAC,CAAC,CAAC;EACnC,IAAIiB,QAAQ,EAAEH,IAAI,EAAE;IAClB,IAAIG,QAAQ,CAACK,MAAM,EAAE;MACnB,MAAMC,GAAG,GAAG,cAAcN,QAAQ,CAACH,IAAI,IAAIG,QAAQ,CAACK,MAAM,EAAE;MAC5D,MAAMrB,OAAO,GAAGmB,CAAC,CAACG,GAAG,CAAC;MACtB,IAAItB,OAAO,KAAKsB,GAAG,EAAE,OAAOtB,OAAO;IACrC;IACA,MAAMsB,GAAG,GAAG,cAAcN,QAAQ,CAACH,IAAI,EAAE;IACzC,MAAMb,OAAO,GAAGmB,CAAC,CAACG,GAAG,CAAC;IACtB,IAAItB,OAAO,KAAKsB,GAAG,EAAE,OAAOtB,OAAO;EACrC;EAEA,IAAIY,KAAK,CAACV,MAAM,KAAK,CAAC,EAAE,OAAOiB,CAAC,CAAC,qBAAqB,CAAC;EACvD,MAAMI,SAAS,GACbN,WAAW,CAACL,KAAK,CAACV,MAAM,CAAC,KAAKU,KAAK,CAACV,MAAM,IAAI,GAAG,GAAG,aAAa,GAAGY,SAAS,CAAC;EAChF,OAAOS,SAAS,GAAGJ,CAAC,CAAC,eAAeI,SAAS,EAAE,CAAC,GAAGJ,CAAC,CAACC,OAAO,CAAC;AAC/D","ignoreList":[]}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ const warned = new Set();
4
+
5
+ /**
6
+ * Hermes ships `Intl` on Android only, so on iOS `Intl.PluralRules` is undefined and constructing
7
+ * it throws — the one place where "the platform already does it" was not true.
8
+ *
9
+ * ponytail: English one/other fallback. The translations Laconius ships are English, and an app
10
+ * with a language whose plural rules are richer either sets `i18n.translate` or polyfills
11
+ * `Intl.PluralRules` (`@formatjs/intl-pluralrules`), which this picks up on its own.
12
+ */
13
+ function pluralCategory(count, language) {
14
+ const PluralRules = globalThis.Intl?.PluralRules;
15
+ if (!PluralRules) return count === 1 ? 'one' : 'other';
16
+ return new PluralRules(language.replace('_', '-')).select(count);
17
+ }
18
+ function isDev() {
19
+ return process.env.NODE_ENV !== 'production';
20
+ }
21
+
22
+ /** Dotted lookup into a nested translation chunk. */
23
+ export function lookupKey(tree, key) {
24
+ if (!tree) return undefined;
25
+ let node = tree;
26
+ for (const segment of key.split('.')) {
27
+ if (typeof node !== 'object' || node === null) return undefined;
28
+ node = node[segment];
29
+ }
30
+ return typeof node === 'string' ? node : undefined;
31
+ }
32
+
33
+ /** `pt_BR` and `pt-BR` both fall back to `pt`, matching OCC's isoCode shapes. */
34
+ function languageChain(language, fallbackLanguage) {
35
+ const chain = [language];
36
+ const base = language.split(/[-_]/)[0];
37
+ if (base && base !== language) chain.push(base);
38
+ if (fallbackLanguage && !chain.includes(fallbackLanguage)) {
39
+ chain.push(fallbackLanguage);
40
+ }
41
+ return chain;
42
+ }
43
+ export function interpolate(template, params = {}) {
44
+ return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (match, name) => {
45
+ const value = params[name];
46
+ return value === undefined ? match : String(value);
47
+ });
48
+ }
49
+ /**
50
+ * Key lookup, `{{param}}` interpolation and `Intl.PluralRules` — the three things Laconius
51
+ * needs from an i18n runtime, in place of taking one as a peer dependency.
52
+ *
53
+ * A missing key returns the key itself: warned once in development, silent in production.
54
+ * A blank label is invisible; a printed key is a bug report.
55
+ */
56
+ export function createTranslator(options) {
57
+ if (options.translate) return options.translate;
58
+ const chain = languageChain(options.language, options.fallbackLanguage);
59
+ const resolve = key => {
60
+ for (const language of chain) {
61
+ const value = lookupKey(options.translations?.[language], key);
62
+ if (value !== undefined) return value;
63
+ }
64
+ return undefined;
65
+ };
66
+ return (key, params) => {
67
+ let template;
68
+ const count = params?.['count'];
69
+ if (typeof count === 'number') {
70
+ const category = pluralCategory(count, options.language);
71
+ template = resolve(`${key}_${category}`) ?? resolve(`${key}_other`);
72
+ }
73
+ template ??= resolve(key);
74
+ if (template === undefined) {
75
+ if (isDev() && !warned.has(key)) {
76
+ warned.add(key);
77
+ console.warn(`[laconius] Missing translation key "${key}".`);
78
+ }
79
+ return key;
80
+ }
81
+ return interpolate(template, params);
82
+ };
83
+ }
84
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["warned","Set","pluralCategory","count","language","PluralRules","globalThis","Intl","replace","select","isDev","process","env","NODE_ENV","lookupKey","tree","key","undefined","node","segment","split","languageChain","fallbackLanguage","chain","base","push","includes","interpolate","template","params","match","name","value","String","createTranslator","options","translate","resolve","translations","category","has","add","console","warn"],"sourceRoot":"../../src","sources":["i18n.ts"],"mappings":";;AAEA,MAAMA,MAAM,GAAG,IAAIC,GAAG,CAAS,CAAC;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAACC,KAAa,EAAEC,QAAgB,EAAU;EAC/D,MAAMC,WAAW,GAAGC,UAAU,CAACC,IAAI,EAAEF,WAAW;EAChD,IAAI,CAACA,WAAW,EAAE,OAAOF,KAAK,KAAK,CAAC,GAAG,KAAK,GAAG,OAAO;EACtD,OAAO,IAAIE,WAAW,CAACD,QAAQ,CAACI,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAACC,MAAM,CAACN,KAAK,CAAC;AAClE;AAEA,SAASO,KAAKA,CAAA,EAAY;EACxB,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY;AAC9C;;AAEA;AACA,OAAO,SAASC,SAASA,CACvBC,IAAiC,EACjCC,GAAW,EACS;EACpB,IAAI,CAACD,IAAI,EAAE,OAAOE,SAAS;EAC3B,IAAIC,IAA0C,GAAGH,IAAI;EACrD,KAAK,MAAMI,OAAO,IAAIH,GAAG,CAACI,KAAK,CAAC,GAAG,CAAC,EAAE;IACpC,IAAI,OAAOF,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,IAAI,EAAE,OAAOD,SAAS;IAC/DC,IAAI,GAAGA,IAAI,CAACC,OAAO,CAAC;EACtB;EACA,OAAO,OAAOD,IAAI,KAAK,QAAQ,G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IgB,KAAK,KAAKf,SAAS,EAAE,OAAOe,KAAK;IACvC;IACA,OAAOf,SAAS;EAClB,CAAC;EAED,OAAO,CAACD,GAAG,EAAEa,MAAM,KAAK;IACtB,IAAID,QAA4B;IAEhC,MAAMzB,KAAK,GAAG0B,MAAM,GAAG,OAAO,CAAC;IAC/B,IAAI,OAAO1B,KAAK,KAAK,QAAQ,EAAE;MAC7B,MAAMoC,QAAQ,GAAGrC,cAAc,CAACC,KAAK,EAAEgC,OAAO,CAAC/B,QAAQ,CAAC;MACxDwB,QAAQ,GAAGS,OAAO,CAAC,GAAGrB,GAAG,IAAIuB,QAAQ,EAAE,CAAC,IAAIF,OAAO,CAAC,GAAGrB,GAAG,QAAQ,CAAC;IACrE;IACAY,QAAQ,KAAKS,OAAO,CAACrB,GAAG,CAAC;IAEzB,IAAIY,QAAQ,KAAKX,SAAS,EAAE;MAC1B,IAAIP,KAAK,CAAC,CAAC,IAAI,CAACV,MAAM,CAACwC,GAAG,CAACxB,GAAG,CAAC,EAAE;QAC/BhB,MAAM,CAACyC,GAAG,CAACzB,GAAG,CAAC;QACf0B,OAAO,CAACC,IAAI,CAAC,uCAAuC3B,GAAG,IAAI,CAAC;MAC9D;MACA,OAAOA,GAAG;IACZ;IACA,OAAOW,WAAW,CAACC,QAAQ,EAAEC,MAAM,CAAC;EACtC,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ export { DEFAULT_OCC_PREFIX, deepMerge, defaultCapabilities } from "./config.js";
4
+ export { coreDefaults, createLaconiusConfig } from "./create-config.js";
5
+ export { createEndpointResolver, defaultCoreEndpoints, mergeQueryString, resolveEndpointValue } from "./endpoints.js";
6
+ export { createHttpClient } from "./client.js";
7
+ export { LaconiusHttpError, getErrorMessage, getOccError, parseOccErrors } from "./errors.js";
8
+ export { SecureStorageError, createAuthClient, createDiscovery } from "./auth.js";
9
+ export { singleFlight } from "./single-flight.js";
10
+ export { resolveCurrency, resolveLanguage, selectUserId, useSessionStore, useSiteContextStore } from "./stores.js";
11
+ export { applyConverters, createConverterRegistry } from "./converters.js";
12
+ export { absolutizeMedia, defaultMediaFormats, defaultMediaRoles, getFormatsUpToMaxFormat, getGalleryImages, getMediaBaseUrl, getPrimaryImage, normalizeImages, resolveMediaCandidates, resolveMediaUrl, sortFormats } from "./media.js";
13
+ export { createTranslator, interpolate, lookupKey } from "./i18n.js";
14
+ export { defaultCoreTranslations } from "./translations.js";
15
+ export { getRuntime, laconiusQueryKey, setActiveRuntime } from "./runtime.js";
16
+ export { defaultSiteContextAdapter, siteContextQueries, useBaseSites, useCurrencies, useLanguages } from "./site-context.js";
17
+ export { LaconiusProvider, createDefaultQueryClient, useIsLoggedIn, useIsOnline, useLaconius, useLaconiusConfig, useLogout, useSiteContext, useTranslation } from "./provider.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEFAULT_OCC_PREFIX","deepMerge","defaultCapabilities","coreDefaults","createLaconiusConfig","createEndpointResolver","defaultCoreEndpoints","mergeQueryString","resolveEndpointValue","createHttpClient","LaconiusHttpError","getErrorMessage","getOccError","parseOccErrors","SecureStorageError","createAuthClient","createDiscovery","singleFlight","resolveCurrency","resolveLanguage","selectUserId","useSessionStore","useSiteContextStore","applyConverters","createConverterRegistry","absolutizeMedia","defaultMediaFormats","defaultMediaRoles","getFormatsUpToMaxFormat","getGalleryImages","getMediaBaseUrl","getPrimaryImage","normalizeImages","resolveMediaCandidates","resolveMediaUrl","sortFormats","createTranslator","interpolate","lookupKey","defaultCoreTranslations","getRuntime","laconiusQueryKey","setActiveRuntime","defaultSiteContextAdapter","siteContextQueries","useBaseSites","useCurrencies","useLanguages","LaconiusProvider","createDefaultQueryClient","useIsLoggedIn","useIsOnline","useLaconius","useLaconiusConfig","useLogout","useSiteContext","useTranslation"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SACEA,kBAAkB,EAClBC,SAAS,EACTC,mBAAmB,QAad,aAAU;AACjB,SAASC,YAAY,EAAEC,oBAAoB,QAAQ,oBAAiB;AAEpE,SACEC,sBAAsB,EACtBC,oBAAoB,EACpBC,gBAAgB,EAChBC,oBAAoB,QAGf,gBAAa;AAEpB,SACEC,gBAAgB,QAGX,aAAU;AAEjB,SACEC,iBAAiB,EACjBC,eAAe,EACfC,WAAW,EACXC,cAAc,QAET,aAAU;AAEjB,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,QAGV,WAAQ;AAEf,SAASC,YAAY,QAAQ,oBAAiB;AAE9C,SACEC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,eAAe,EACfC,mBAAmB,QAGd,aAAU;AAEjB,SACEC,eAAe,EACfC,uBAAuB,QAGlB,iBAAc;AAErB,SACEC,eAAe,EACfC,mBAAmB,EACnBC,iBAAiB,EACjBC,uBAAuB,EACvBC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,sBAAsB,EACtBC,eAAe,EACfC,WAAW,QAGN,YAAS;AAEhB,SACEC,gBAAgB,EAChBC,WAAW,EACXC,SAAS,QAEJ,WAAQ;AACf,SAASC,uBAAuB,QAAQ,mBAAgB;AAExD,SACEC,UAAU,EACVC,gBAAgB,EAChBC,gBAAgB,QAEX,cAAW;AAElB,SACEC,yBAAyB,EACzBC,kBAAkB,EAClBC,YAAY,EACZC,aAAa,EACbC,YAAY,QAEP,mBAAgB;AAEvB,SACEC,gBAAgB,EAChBC,wBAAwB,EACxBC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,iBAAiB,EACjBC,SAAS,EACTC,cAAc,EACdC,cAAc,QAET,eAAY","ignoreList":[]}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Format code to width in pixels, ported from Spartacus'
5
+ * `core-libs/storefront/recipes/config/default-media.config.ts`.
6
+ *
7
+ * The codes are widths, not device classes. Mapping a phone to `mobile` (400px) would upscale a
8
+ * hero 3x on a @3x screen, so nothing here maps device to format.
9
+ */
10
+ export const defaultMediaFormats = {
11
+ cartIcon: 65,
12
+ thumbnail: 96,
13
+ product: 284,
14
+ mobile: 400,
15
+ zoom: 515,
16
+ tablet: 770,
17
+ desktop: 1140,
18
+ widescreen: 1400
19
+ };
20
+
21
+ /** A role caps the candidate set; it does not select a single asset. No role means no cap. */
22
+ export const defaultMediaRoles = {
23
+ cartIcon: 'cartIcon',
24
+ thumbnail: 'thumbnail',
25
+ product: 'product'
26
+ };
27
+
28
+ /** What `expo-image` accepts as one entry of an `ImageSource[]`. */
29
+
30
+ export function getMediaBaseUrl(config) {
31
+ return config.backend.media?.baseUrl ?? config.backend.occ.baseUrl;
32
+ }
33
+
34
+ /**
35
+ * Absolutises an OCC media path. Absolute URLs, protocol-relative URLs and `data:` URIs are
36
+ * returned untouched — Spartacus absolutises `data:` URIs in one of its two paths and breaks
37
+ * them there.
38
+ */
39
+ export function resolveMediaUrl(media, baseUrl) {
40
+ const url = media?.url;
41
+ if (!url) return undefined;
42
+ if (/^(https?:)?\/\//.test(url) || url.startsWith('data:')) return url;
43
+ return `${baseUrl.replace(/\/$/, '')}${url.startsWith('/') ? '' : '/'}${url}`;
44
+ }
45
+
46
+ /** Format codes ascending by width, unknown widths last in declaration order. */
47
+ export function sortFormats(formats) {
48
+ return Object.entries(formats).map(([code, width]) => ({
49
+ code,
50
+ width
51
+ })).sort((a, b) => a.width - b.width);
52
+ }
53
+
54
+ /**
55
+ * Formats up to and including `maxFormat`. An unknown `maxFormat` caps nothing, which is
56
+ * Spartacus' behaviour and the safe one: a typo shows a big image, not no image.
57
+ */
58
+ export function getFormatsUpToMaxFormat(formats, maxFormat) {
59
+ const maxIndex = formats.findIndex(format => format.code === maxFormat);
60
+ return maxIndex === -1 ? formats : formats.slice(0, maxIndex + 1);
61
+ }
62
+
63
+ /**
64
+ * The candidate set for one media container, widths attached.
65
+ *
66
+ * `expo-image` picks the source that best fits the measured container at the screen scale, so
67
+ * the caller never decides "which format" and never passes the container size.
68
+ */
69
+ export function resolveMediaCandidates(media, options) {
70
+ if (!media) return [];
71
+ const formats = options.formats ?? defaultMediaFormats;
72
+ const roles = options.roles ?? defaultMediaRoles;
73
+ const cap = options.maxFormat ?? (options.role ? roles[options.role] : undefined);
74
+ const container = media;
75
+ const known = getFormatsUpToMaxFormat(sortFormats(formats), cap).filter(format => isImage(container[format.code]));
76
+ if (known.length > 0) {
77
+ return known.flatMap(({
78
+ code,
79
+ width
80
+ }) => {
81
+ const uri = resolveMediaUrl(container[code], options.baseUrl);
82
+ return uri ? [{
83
+ uri,
84
+ width
85
+ }] : [];
86
+ });
87
+ }
88
+
89
+ // A bare `Image` (CMS media often is one), or a container whose format codes are unknown.
90
+ const single = isImage(media) ? media : firstImage(container);
91
+ const uri = resolveMediaUrl(single, options.baseUrl);
92
+ return uri ? [{
93
+ uri
94
+ }] : [];
95
+ }
96
+ function isImage(value) {
97
+ return typeof value === 'object' && value !== null && typeof value.url === 'string';
98
+ }
99
+ function firstImage(container) {
100
+ for (const value of Object.values(container)) {
101
+ if (isImage(value)) return value;
102
+ }
103
+ return undefined;
104
+ }
105
+
106
+ /**
107
+ * Absolutises every media URL inside a payload, on the way in.
108
+ *
109
+ * One mechanism for CMS media and product images alike ([chapter 08](../../../docs/spec/08-media.md)),
110
+ * where Spartacus has two unrelated ones. The walk is shape-agnostic because media reaches the
111
+ * client as an `Image`, as a group keyed by format code, and as arrays of either.
112
+ */
113
+ export function absolutizeMedia(value, baseUrl) {
114
+ if (Array.isArray(value)) {
115
+ return value.map(item => absolutizeMedia(item, baseUrl));
116
+ }
117
+ if (typeof value !== 'object' || value === null) return value;
118
+ const entries = Object.entries(value).map(([key, item]) => isImage(item) ? [key, {
119
+ ...item,
120
+ url: resolveMediaUrl(item, baseUrl)
121
+ }] : [key, absolutizeMedia(item, baseUrl)]);
122
+ return Object.fromEntries(entries);
123
+ }
124
+
125
+ /**
126
+ * The `PRIMARY` group of a normalized `Images`, which is what a card, a thumbnail and a gallery's
127
+ * first slide all want. OCC only ever sends one primary image, so an array here is a payload
128
+ * oddity rather than a case to support.
129
+ */
130
+ export function getPrimaryImage(images) {
131
+ const primary = images?.['PRIMARY'];
132
+ return Array.isArray(primary) ? primary[0] : primary;
133
+ }
134
+
135
+ /** The `GALLERY` groups in `galleryIndex` order, with the primary image first when there is one. */
136
+ export function getGalleryImages(images) {
137
+ const gallery = images?.['GALLERY'];
138
+ const groups = Array.isArray(gallery) ? gallery.filter(Boolean) : gallery ? [gallery] : [];
139
+ if (groups.length > 0) return groups;
140
+ const primary = getPrimaryImage(images);
141
+ return primary ? [primary] : [];
142
+ }
143
+
144
+ /**
145
+ * Reshapes OCC's flat `Image[]` into `images.PRIMARY.zoom` / `images.GALLERY[i].thumbnail`,
146
+ * ported from `core-libs/core/src/occ/adapters/product/converters/product-image-normalizer.ts:36-100`.
147
+ *
148
+ * Lives in core because product payloads and cart entry products carry the same flat list —
149
+ * one mechanism ([chapter 08](../../../docs/spec/08-media.md)), and no `cart -> product` edge
150
+ * exists to borrow it over ([chapter 01](../../../docs/spec/01-packages.md)).
151
+ *
152
+ * URLs are **not** absolutised here: a converter is a pure function with no access to config, so
153
+ * adapters absolutise the whole payload afterwards through `absolutizeMedia`.
154
+ */
155
+ export function normalizeImages(source) {
156
+ const images = {};
157
+ for (const image of source ?? []) {
158
+ if (!image.imageType || !image.format) continue;
159
+ const group = groupFor(images, image);
160
+ group[image.format] = image;
161
+ }
162
+ return images;
163
+ }
164
+
165
+ /** `galleryIndex` is what makes an image type a list, not the type code. */
166
+ function groupFor(images, image) {
167
+ const type = image.imageType;
168
+ if (image.galleryIndex === undefined) {
169
+ const existing = images[type];
170
+ if (existing && !Array.isArray(existing)) return existing;
171
+ const group = {};
172
+ images[type] = group;
173
+ return group;
174
+ }
175
+ const existing = images[type];
176
+ const groups = Array.isArray(existing) ? existing : [];
177
+ images[type] = groups;
178
+ const group = groups[image.galleryIndex] ?? {};
179
+ groups[image.galleryIndex] = group;
180
+ return group;
181
+ }
182
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defaultMediaFormats","cartIcon","thumbnail","product","mobile","zoom","tablet","desktop","widescreen","defaultMediaRoles","getMediaBaseUrl","config","backend","media","baseUrl","occ","resolveMediaUrl","url","undefined","test","startsWith","replace","sortFormats","formats","Object","entries","map","code","width","sort","a","b","getFormatsUpToMaxFormat","maxFormat","maxIndex","findIndex","format","slice","resolveMediaCandidates","options","roles","cap","role","container","known","filter","isImage","length","flatMap","uri","single","firstImage","value","values","absolutizeMedia","Array","isArray","item","key","fromEntries","getPrimaryImage","images","primary","getGalleryImages","gallery","groups","Boolean","normalizeImages","source","image","imageType","group","groupFor","type","galleryIndex","existing"],"sourceRoot":"../../src","sources":["media.ts"],"mappings":";;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,mBAA2C,GAAG;EACzDC,QAAQ,EAAE,EAAE;EACZC,SAAS,EAAE,EAAE;EACbC,OAAO,EAAE,GAAG;EACZC,MAAM,EAAE,GAAG;EACXC,IAAI,EAAE,GAAG;EACTC,MAAM,EAAE,GAAG;EACXC,OAAO,EAAE,IAAI;EACbC,UAAU,EAAE;AACd,CAAC;;AAED;AACA,OAAO,MAAMC,iBAAyC,GAAG;EACvDR,QAAQ,EAAE,UAAU;EACpBC,SAAS,EAAE,WAAW;EACtBC,OAAO,EAAE;AACX,CAAC;;AAED;;AAKA,OAAO,SAASO,eAAeA,CAACC,MAAsB,EAAU;EAC9D,OAAOA,MAAM,CAACC,OAAO,CAACC,KAAK,EAAEC,OAAO,IAAIH,MAAM,CAACC,OAAO,CAACG,GAAG,CAACD,OAAO;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,eAAeA,CAC7BH,KAAwB,EACxBC,OAAe,EACK;EACpB,MAAMG,GAAG,GAAGJ,KAAK,EAAEI,GAAG;EACtB,IAAI,CAACA,GAAG,EAAE,OAAOC,SAAS;EAC1B,IAAI,iBAAiB,CAACC,IA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AACI,KAAK,CAACK,YAAY,CAAC,IAAI,CAAC,CAAC;EAC9CT,MAAM,CAACI,KAAK,CAACK,YAAY,CAAC,GAAGH,KAAK;EAClC,OAAOA,KAAK;AACd","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["models.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}