@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.
- package/LICENSE +73 -0
- package/README.md +31 -0
- package/lib/module/auth.js +182 -0
- package/lib/module/auth.js.map +1 -0
- package/lib/module/client.js +99 -0
- package/lib/module/client.js.map +1 -0
- package/lib/module/config.js +72 -0
- package/lib/module/config.js.map +1 -0
- package/lib/module/converters.js +31 -0
- package/lib/module/converters.js.map +1 -0
- package/lib/module/create-config.js +36 -0
- package/lib/module/create-config.js.map +1 -0
- package/lib/module/endpoints.js +89 -0
- package/lib/module/endpoints.js.map +1 -0
- package/lib/module/errors.js +76 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/i18n.js +84 -0
- package/lib/module/i18n.js.map +1 -0
- package/lib/module/index.js +18 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/media.js +182 -0
- package/lib/module/media.js.map +1 -0
- package/lib/module/models.js +2 -0
- package/lib/module/models.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/provider.js +182 -0
- package/lib/module/provider.js.map +1 -0
- package/lib/module/runtime.js +43 -0
- package/lib/module/runtime.js.map +1 -0
- package/lib/module/single-flight.js +23 -0
- package/lib/module/single-flight.js.map +1 -0
- package/lib/module/site-context.js +74 -0
- package/lib/module/site-context.js.map +1 -0
- package/lib/module/stores.js +66 -0
- package/lib/module/stores.js.map +1 -0
- package/lib/module/translations.js +42 -0
- package/lib/module/translations.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/auth.d.ts +31 -0
- package/lib/typescript/src/auth.d.ts.map +1 -0
- package/lib/typescript/src/client.d.ts +31 -0
- package/lib/typescript/src/client.d.ts.map +1 -0
- package/lib/typescript/src/config.d.ts +150 -0
- package/lib/typescript/src/config.d.ts.map +1 -0
- package/lib/typescript/src/converters.d.ts +17 -0
- package/lib/typescript/src/converters.d.ts.map +1 -0
- package/lib/typescript/src/create-config.d.ts +11 -0
- package/lib/typescript/src/create-config.d.ts.map +1 -0
- package/lib/typescript/src/endpoints.d.ts +36 -0
- package/lib/typescript/src/endpoints.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +43 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/i18n.d.ts +20 -0
- package/lib/typescript/src/i18n.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +17 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/media.d.ts +81 -0
- package/lib/typescript/src/media.d.ts.map +1 -0
- package/lib/typescript/src/models.d.ts +327 -0
- package/lib/typescript/src/models.d.ts.map +1 -0
- package/lib/typescript/src/provider.d.ts +37 -0
- package/lib/typescript/src/provider.d.ts.map +1 -0
- package/lib/typescript/src/runtime.d.ts +26 -0
- package/lib/typescript/src/runtime.d.ts.map +1 -0
- package/lib/typescript/src/single-flight.d.ts +7 -0
- package/lib/typescript/src/single-flight.d.ts.map +1 -0
- package/lib/typescript/src/site-context.d.ts +28 -0
- package/lib/typescript/src/site-context.d.ts.map +1 -0
- package/lib/typescript/src/stores.d.ts +54 -0
- package/lib/typescript/src/stores.d.ts.map +1 -0
- package/lib/typescript/src/translations.d.ts +40 -0
- package/lib/typescript/src/translations.d.ts.map +1 -0
- package/package.json +77 -0
- package/src/auth.ts +223 -0
- package/src/client.ts +133 -0
- package/src/config.ts +191 -0
- package/src/converters.ts +47 -0
- package/src/create-config.ts +29 -0
- package/src/endpoints.ts +133 -0
- package/src/errors.ts +104 -0
- package/src/i18n.ts +108 -0
- package/src/index.ts +123 -0
- package/src/media.ts +209 -0
- package/src/models.ts +384 -0
- package/src/provider.tsx +229 -0
- package/src/runtime.ts +57 -0
- package/src/single-flight.ts +23 -0
- package/src/site-context.ts +77 -0
- package/src/stores.ts +94 -0
- package/src/translations.ts +40 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
import type { SiteContextAdapter } from './site-context.js';
|
|
4
|
+
/**
|
|
5
|
+
* An endpoint value is a URL template, optionally split into named scopes.
|
|
6
|
+
* Values carry their own query string (`fields=…`); the builder merges caller params into it.
|
|
7
|
+
*/
|
|
8
|
+
export type EndpointValue = string | Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Endpoint keys. Feature packages add their own by declaration merging:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* declare module '@laconius/core' {
|
|
14
|
+
* interface LaconiusEndpoints { productSearch: string | Record<'default' | 'carousel', string> }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface LaconiusEndpoints {
|
|
19
|
+
baseSites: string;
|
|
20
|
+
languages: string;
|
|
21
|
+
currencies: string;
|
|
22
|
+
countries: string;
|
|
23
|
+
regions: string;
|
|
24
|
+
}
|
|
25
|
+
/** Converter keys, extended by declaration merging exactly like endpoint keys. */
|
|
26
|
+
export interface LaconiusConverters {
|
|
27
|
+
baseSite: unknown;
|
|
28
|
+
language: unknown;
|
|
29
|
+
currency: unknown;
|
|
30
|
+
country: unknown;
|
|
31
|
+
region: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** Adapter slots, extended by declaration merging. Replacing one is the route to a non-OCC backend. */
|
|
34
|
+
export interface LaconiusAdapters {
|
|
35
|
+
siteContext: SiteContextAdapter;
|
|
36
|
+
}
|
|
37
|
+
export type TranslationTree = {
|
|
38
|
+
[key: string]: string | TranslationTree;
|
|
39
|
+
};
|
|
40
|
+
/** Extended by `@laconius/ui` with themes, components and colour scheme. */
|
|
41
|
+
export interface LaconiusUiConfig {
|
|
42
|
+
media?: {
|
|
43
|
+
/** Format code to width in pixels. Widths, not device classes. */
|
|
44
|
+
formats?: Record<string, number>;
|
|
45
|
+
/** Role to the largest format code that role may use. */
|
|
46
|
+
roles?: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Extended by `@laconius/cms` with the component registry and layout config. */
|
|
50
|
+
export interface LaconiusCmsConfig {
|
|
51
|
+
htmlRenderer?: ComponentType<{
|
|
52
|
+
html: string;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
55
|
+
export interface LaconiusAuthConfig {
|
|
56
|
+
clientId: string;
|
|
57
|
+
redirectUri: string;
|
|
58
|
+
authServerUrl: string;
|
|
59
|
+
/** Passed to `expo-secure-store` as `requireAuthentication`. Off by default. */
|
|
60
|
+
requireBiometricUnlock?: boolean;
|
|
61
|
+
/** Identity-provider slot. Laconius stores and refreshes whatever it is handed. */
|
|
62
|
+
tokenProvider?: () => Promise<{
|
|
63
|
+
access_token: string;
|
|
64
|
+
refresh_token?: string;
|
|
65
|
+
expires_in: number;
|
|
66
|
+
}>;
|
|
67
|
+
/** Multisite isolation hook, replacing Spartacus' `AuthMultisiteIsolationService`. */
|
|
68
|
+
decorateUserId?: (userId: string, baseSite: string) => string;
|
|
69
|
+
/** Called when the session dies. Core never navigates. */
|
|
70
|
+
onAuthExpired?: () => void;
|
|
71
|
+
}
|
|
72
|
+
export interface LaconiusConfig {
|
|
73
|
+
backend: {
|
|
74
|
+
occ: {
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
baseSite: string;
|
|
77
|
+
/** Defaults to `/occ/v2`. */
|
|
78
|
+
prefix?: string;
|
|
79
|
+
endpoints?: Partial<LaconiusEndpoints>;
|
|
80
|
+
};
|
|
81
|
+
media?: {
|
|
82
|
+
baseUrl?: string;
|
|
83
|
+
};
|
|
84
|
+
adapters?: Partial<LaconiusAdapters>;
|
|
85
|
+
};
|
|
86
|
+
auth: LaconiusAuthConfig;
|
|
87
|
+
context: {
|
|
88
|
+
languages: string[];
|
|
89
|
+
currencies: string[];
|
|
90
|
+
defaultLanguage?: string;
|
|
91
|
+
defaultCurrency?: string;
|
|
92
|
+
};
|
|
93
|
+
/** The three known version-gated endpoints. Defaults are the 221121.x baseline. */
|
|
94
|
+
capabilities?: {
|
|
95
|
+
jsonVouchers?: boolean;
|
|
96
|
+
productAvailabilities?: boolean;
|
|
97
|
+
userScopedCms?: boolean;
|
|
98
|
+
};
|
|
99
|
+
converters?: Partial<Record<keyof LaconiusConverters, unknown[]>>;
|
|
100
|
+
cms?: LaconiusCmsConfig;
|
|
101
|
+
ui?: LaconiusUiConfig;
|
|
102
|
+
i18n?: {
|
|
103
|
+
fallbackLanguage?: string;
|
|
104
|
+
translations?: Record<string, TranslationTree>;
|
|
105
|
+
/** Set this and Laconius resolves nothing itself. */
|
|
106
|
+
translate?: (key: string, params?: Record<string, unknown>) => string;
|
|
107
|
+
};
|
|
108
|
+
query?: {
|
|
109
|
+
queryClient?: QueryClient;
|
|
110
|
+
wireOnlineManager?: boolean;
|
|
111
|
+
wireFocusManager?: boolean;
|
|
112
|
+
};
|
|
113
|
+
/** Observation only: it does not render. */
|
|
114
|
+
onError?: (error: unknown, ctx: {
|
|
115
|
+
url?: string;
|
|
116
|
+
}) => void;
|
|
117
|
+
}
|
|
118
|
+
type Primitive = string | number | boolean | symbol | bigint | null | undefined;
|
|
119
|
+
export type DeepPartial<T> = T extends Primitive ? T : T extends (...args: never[]) => unknown ? T : T extends readonly (infer _U)[] ? T : {
|
|
120
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
121
|
+
};
|
|
122
|
+
/** What a feature package exports as `defaultProductConfig` and friends. */
|
|
123
|
+
export type LaconiusConfigChunk = DeepPartial<LaconiusConfig>;
|
|
124
|
+
/** The app's own chunk. `backend.occ` and `auth` are what the provider refuses to start without. */
|
|
125
|
+
export type LaconiusAppConfig = LaconiusConfigChunk & {
|
|
126
|
+
backend: DeepPartial<LaconiusConfig['backend']> & {
|
|
127
|
+
occ: {
|
|
128
|
+
baseUrl: string;
|
|
129
|
+
baseSite: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
auth: LaconiusAuthConfig;
|
|
133
|
+
};
|
|
134
|
+
export declare const DEFAULT_OCC_PREFIX = "/occ/v2";
|
|
135
|
+
export declare const defaultCapabilities: {
|
|
136
|
+
jsonVouchers: boolean;
|
|
137
|
+
productAvailabilities: boolean;
|
|
138
|
+
userScopedCms: boolean;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Objects deep-merge, arrays are replaced, `undefined` is ignored.
|
|
142
|
+
*
|
|
143
|
+
* Arrays are never concatenated: a default you cannot remove is a bug. Everything that would
|
|
144
|
+
* want concatenation exports a `default*` array the app spreads explicitly.
|
|
145
|
+
*/
|
|
146
|
+
export declare function deepMerge<T>(base: T, override: unknown): T;
|
|
147
|
+
/** @internal Use `createLaconiusConfig`, which seeds core's own defaults first. */
|
|
148
|
+
export declare function createLaconiusConfigInternal(app: LaconiusAppConfig, chunks: LaconiusConfigChunk[]): LaconiusConfig;
|
|
149
|
+
export {};
|
|
150
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAgB,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,kFAAkF;AAClF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,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AiB,EACtB,MAAM,EAAE,mBAAmB,EAAE,GAC5B,cAAc,CAOhB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LaconiusConfig, LaconiusConverters } from './config.js';
|
|
2
|
+
/** Spartacus' populator pattern with dependency injection removed. */
|
|
3
|
+
export type Converter<S, T> = (source: S, target?: T) => T;
|
|
4
|
+
/**
|
|
5
|
+
* Reduces a converter stack so each converter enriches the previous one's partial target.
|
|
6
|
+
*
|
|
7
|
+
* The seed is explicit because it is easy to re-derive wrong: an empty stack returns the source
|
|
8
|
+
* unchanged, and otherwise the first converter is called with `target === undefined`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyConverters<S, T>(source: S, converters: readonly Converter<S, T>[] | undefined): T;
|
|
11
|
+
export type ConverterRegistry = {
|
|
12
|
+
convert<S, T>(source: S, key: keyof LaconiusConverters): T;
|
|
13
|
+
convertAll<S, T>(sources: S[] | undefined, key: keyof LaconiusConverters): T[];
|
|
14
|
+
};
|
|
15
|
+
/** Converters are registered by explicit spread of a feature's exported defaults. */
|
|
16
|
+
export declare function createConverterRegistry(config: LaconiusConfig): ConverterRegistry;
|
|
17
|
+
//# sourceMappingURL=converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/converters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAU,CAAC;AAEnE,sEAAsE;AACtE,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAClC,MAAM,EAAE,CAAC,EACT,UAAU,EAAE,SAAS,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,GACjD,CAAC,CAQH;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,kBAAkB,GAAG,CAAC,CAAC;IAC3D,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,kBAAkB,GAAG,CAAC,EAAE,CAAC;CAChF,CAAC;AAEF,qFAAqF;AACrF,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,cAAc,GACrB,iBAAiB,CAcnB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LaconiusAppConfig, type LaconiusConfig, type LaconiusConfigChunk } from './config.js';
|
|
2
|
+
/** What core contributes before any feature chunk: its endpoints, media table and strings. */
|
|
3
|
+
export declare const coreDefaults: LaconiusConfigChunk;
|
|
4
|
+
/**
|
|
5
|
+
* Deep-merges core's defaults, then the feature chunks in order, then the app chunk last, so an
|
|
6
|
+
* override is written where the reader expects it.
|
|
7
|
+
*
|
|
8
|
+
* Objects deep-merge, arrays are replaced, `undefined` is ignored.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createLaconiusConfig(app: LaconiusAppConfig, featureChunks?: LaconiusConfigChunk[]): LaconiusConfig;
|
|
11
|
+
//# sourceMappingURL=create-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-config.d.ts","sourceRoot":"","sources":["../../../src/create-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACzB,MAAM,aAAU,CAAC;AAKlB,8FAA8F;AAC9F,eAAO,MAAM,YAAY,EAAE,mBAI1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,iBAAiB,EACtB,aAAa,GAAE,mBAAmB,EAAO,GACxC,cAAc,CAEhB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type EndpointValue, type LaconiusConfig, type LaconiusEndpoints } from './config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Core's own endpoints: site context. Every value is a URL with its query string, never a bare
|
|
4
|
+
* path, so field selection lives in the template rather than at the call site.
|
|
5
|
+
*
|
|
6
|
+
* `baseSites` is the one endpoint built without the base-site segment.
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultCoreEndpoints: Pick<LaconiusEndpoints, 'baseSites' | 'languages' | 'currencies' | 'countries' | 'regions'>;
|
|
9
|
+
export type EndpointParams = {
|
|
10
|
+
/** Values for `${placeholder}` segments in the template. URI-encoded on interpolation. */
|
|
11
|
+
urlParams?: Record<string, string | number>;
|
|
12
|
+
/** Merged into the query string the template already carries. Caller params win. */
|
|
13
|
+
queryParams?: Record<string, string | number | boolean | undefined>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Named scope -> `default` scope -> plain string -> `undefined`.
|
|
17
|
+
*
|
|
18
|
+
* Spartacus' final fallback — using the endpoint key itself as the path — is deliberately
|
|
19
|
+
* dropped: it turns a configuration mistake into a mysterious 404.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveEndpointValue(endpoints: Partial<Record<string, EndpointValue>>, key: string, scope?: string): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Merges `queryParams` into the query string the template already carries, caller wins.
|
|
24
|
+
*
|
|
25
|
+
* Template values are kept verbatim — an OCC `fields` expression is already in the shape the
|
|
26
|
+
* backend wants, and re-encoding its parentheses breaks it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mergeQueryString(template: string, queryParams?: Record<string, string | number | boolean | undefined>): string;
|
|
29
|
+
export type EndpointResolver = {
|
|
30
|
+
/** Full URL for an endpoint key. Throws an error naming the key when it is not configured. */
|
|
31
|
+
getEndpoint(key: string, params?: EndpointParams, scope?: string): string;
|
|
32
|
+
/** Lets an adapter branch on presence instead of crashing. */
|
|
33
|
+
isConfigured(key: string, scope?: string): boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare function createEndpointResolver(config: LaconiusConfig): EndpointResolver;
|
|
36
|
+
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../../src/endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,aAAU,CAAC;AAElB;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,IAAI,CACrC,iBAAiB,EACjB,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAOnE,CAAC;AAKF,MAAM,MAAM,cAAc,GAAG;IAC3B,0FAA0F;IAC1F,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC5C,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,EACjD,GAAG,EAAE,MAAM,EACX,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,GAAG,SAAS,CAMpB;AAiBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAM,GACtE,MAAM,CAqBR;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,8FAA8F;IAC9F,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1E,8DAA8D;IAC9D,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpD,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB,CA0B/E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** One entry of OCC's `errors[]` envelope. `type` is open-ended and customer-extensible. */
|
|
2
|
+
export type OccError = {
|
|
3
|
+
type?: string;
|
|
4
|
+
reason?: string;
|
|
5
|
+
subject?: string;
|
|
6
|
+
subjectType?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The one error type Laconius throws for a failed request.
|
|
11
|
+
*
|
|
12
|
+
* An OCC business error is data, not a status code: `InsufficientStockError` and a network
|
|
13
|
+
* timeout are the same `status` to a shopper who needs to be told different things.
|
|
14
|
+
*/
|
|
15
|
+
export declare class LaconiusHttpError extends Error {
|
|
16
|
+
/** 0 when the request never reached the server. */
|
|
17
|
+
readonly status: number;
|
|
18
|
+
readonly url: string;
|
|
19
|
+
/** Parsed `errors[]`, empty when the payload carried none. */
|
|
20
|
+
readonly occErrors: OccError[];
|
|
21
|
+
/** Raw payload, for the app's telemetry. */
|
|
22
|
+
readonly body?: unknown;
|
|
23
|
+
constructor(init: {
|
|
24
|
+
status: number;
|
|
25
|
+
url: string;
|
|
26
|
+
occErrors?: OccError[];
|
|
27
|
+
body?: unknown;
|
|
28
|
+
message?: string;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Parses OCC's `errors[]` envelope out of an arbitrary payload. */
|
|
32
|
+
export declare function parseOccErrors(body: unknown): OccError[];
|
|
33
|
+
/** `getOccError(error)` for the first one, `getOccError(error, 'InsufficientStockError')` to match. */
|
|
34
|
+
export declare function getOccError(error: unknown, type?: string): OccError | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* A translated sentence for a shopper:
|
|
37
|
+
* OCC `type`/`reason` -> OCC `type` -> status class -> unknown.
|
|
38
|
+
*
|
|
39
|
+
* Never falls through to a raw backend string: that leaks internals and is untranslated by
|
|
40
|
+
* definition.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getErrorMessage(error: unknown, t: (key: string, params?: Record<string, unknown>) => string): string;
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAC;IAC/B,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEZ,IAAI,EAAE;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;QACvB,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;CAaF;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,EAAE,CAOxD;AAED,uGAAuG;AACvG,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,QAAQ,GAAG,SAAS,CAItB;AAUD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAC3D,MAAM,CAoBR"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TranslationTree } from './config.js';
|
|
2
|
+
/** Dotted lookup into a nested translation chunk. */
|
|
3
|
+
export declare function lookupKey(tree: TranslationTree | undefined, key: string): string | undefined;
|
|
4
|
+
export declare function interpolate(template: string, params?: Record<string, unknown>): string;
|
|
5
|
+
export type Translator = (key: string, params?: Record<string, unknown>) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Key lookup, `{{param}}` interpolation and `Intl.PluralRules` — the three things Laconius
|
|
8
|
+
* needs from an i18n runtime, in place of taking one as a peer dependency.
|
|
9
|
+
*
|
|
10
|
+
* A missing key returns the key itself: warned once in development, silent in production.
|
|
11
|
+
* A blank label is invisible; a printed key is a bug report.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createTranslator(options: {
|
|
14
|
+
translations?: Record<string, TranslationTree>;
|
|
15
|
+
language: string;
|
|
16
|
+
fallbackLanguage?: string;
|
|
17
|
+
/** An app that already runs an i18n runtime sets this, and Laconius resolves nothing itself. */
|
|
18
|
+
translate?: Translator;
|
|
19
|
+
}): Translator;
|
|
20
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../../src/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAU,CAAC;AAsBhD,qDAAqD;AACrD,wBAAgB,SAAS,CACvB,IAAI,EAAE,eAAe,GAAG,SAAS,EACjC,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAQpB;AAaD,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,MAAM,CAKR;AAED,MAAM,MAAM,UAAU,GAAG,CACvB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,MAAM,CAAC;AAEZ;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gGAAgG;IAChG,SAAS,CAAC,EAAE,UAAU,CAAC;CACxB,GAAG,UAAU,CAgCb"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { DEFAULT_OCC_PREFIX, deepMerge, defaultCapabilities, type DeepPartial, type EndpointValue, type LaconiusAdapters, type LaconiusAppConfig, type LaconiusAuthConfig, type LaconiusCmsConfig, type LaconiusConfig, type LaconiusConfigChunk, type LaconiusConverters, type LaconiusEndpoints, type LaconiusUiConfig, type TranslationTree, } from './config.js';
|
|
2
|
+
export { coreDefaults, createLaconiusConfig } from './create-config.js';
|
|
3
|
+
export { createEndpointResolver, defaultCoreEndpoints, mergeQueryString, resolveEndpointValue, type EndpointParams, type EndpointResolver, } from './endpoints.js';
|
|
4
|
+
export { createHttpClient, type LaconiusHttpClient, type LaconiusRequest, } from './client.js';
|
|
5
|
+
export { LaconiusHttpError, getErrorMessage, getOccError, parseOccErrors, type OccError, } from './errors.js';
|
|
6
|
+
export { SecureStorageError, createAuthClient, createDiscovery, type AuthClient, type TokenSet, } from './auth.js';
|
|
7
|
+
export { singleFlight } from './single-flight.js';
|
|
8
|
+
export { resolveCurrency, resolveLanguage, selectUserId, useSessionStore, useSiteContextStore, type SessionState, type SiteContextState, } from './stores.js';
|
|
9
|
+
export { applyConverters, createConverterRegistry, type Converter, type ConverterRegistry, } from './converters.js';
|
|
10
|
+
export { absolutizeMedia, defaultMediaFormats, defaultMediaRoles, getFormatsUpToMaxFormat, getGalleryImages, getMediaBaseUrl, getPrimaryImage, normalizeImages, resolveMediaCandidates, resolveMediaUrl, sortFormats, type MediaContainer, type MediaSource, } from './media.js';
|
|
11
|
+
export { createTranslator, interpolate, lookupKey, type Translator, } from './i18n.js';
|
|
12
|
+
export { defaultCoreTranslations } from './translations.js';
|
|
13
|
+
export { getRuntime, laconiusQueryKey, setActiveRuntime, type LaconiusRuntime, } from './runtime.js';
|
|
14
|
+
export { defaultSiteContextAdapter, siteContextQueries, useBaseSites, useCurrencies, useLanguages, type SiteContextAdapter, } from './site-context.js';
|
|
15
|
+
export { LaconiusProvider, createDefaultQueryClient, useIsLoggedIn, useIsOnline, useLaconius, useLaconiusConfig, useLogout, useSiteContext, useTranslation, type LaconiusProviderProps, } from './provider.js';
|
|
16
|
+
export type * from './models.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,aAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAiB,CAAC;AAErE,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,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gB,EAChB,wBAAwB,EACxB,aAAa,EACb,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,eAAY,CAAC;AAEpB,mBAAmB,aAAU,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { LaconiusConfig } from './config.js';
|
|
2
|
+
import type { Image, ImageGroup, Images } from './models.js';
|
|
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 declare const defaultMediaFormats: Record<string, number>;
|
|
11
|
+
/** A role caps the candidate set; it does not select a single asset. No role means no cap. */
|
|
12
|
+
export declare const defaultMediaRoles: Record<string, string>;
|
|
13
|
+
/** What `expo-image` accepts as one entry of an `ImageSource[]`. */
|
|
14
|
+
export type MediaSource = {
|
|
15
|
+
uri: string;
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
};
|
|
19
|
+
export type MediaContainer = ImageGroup | Image | undefined;
|
|
20
|
+
export declare function getMediaBaseUrl(config: LaconiusConfig): string;
|
|
21
|
+
/**
|
|
22
|
+
* Absolutises an OCC media path. Absolute URLs, protocol-relative URLs and `data:` URIs are
|
|
23
|
+
* returned untouched — Spartacus absolutises `data:` URIs in one of its two paths and breaks
|
|
24
|
+
* them there.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveMediaUrl(media: Image | undefined, baseUrl: string): string | undefined;
|
|
27
|
+
/** Format codes ascending by width, unknown widths last in declaration order. */
|
|
28
|
+
export declare function sortFormats(formats: Record<string, number>): {
|
|
29
|
+
code: string;
|
|
30
|
+
width: number;
|
|
31
|
+
}[];
|
|
32
|
+
/**
|
|
33
|
+
* Formats up to and including `maxFormat`. An unknown `maxFormat` caps nothing, which is
|
|
34
|
+
* Spartacus' behaviour and the safe one: a typo shows a big image, not no image.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getFormatsUpToMaxFormat<T extends {
|
|
37
|
+
code: string;
|
|
38
|
+
}>(formats: T[], maxFormat?: string): T[];
|
|
39
|
+
/**
|
|
40
|
+
* The candidate set for one media container, widths attached.
|
|
41
|
+
*
|
|
42
|
+
* `expo-image` picks the source that best fits the measured container at the screen scale, so
|
|
43
|
+
* the caller never decides "which format" and never passes the container size.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveMediaCandidates(media: MediaContainer, options: {
|
|
46
|
+
baseUrl: string;
|
|
47
|
+
role?: string;
|
|
48
|
+
/** Explicit cap, overriding the one the role implies. */
|
|
49
|
+
maxFormat?: string;
|
|
50
|
+
formats?: Record<string, number>;
|
|
51
|
+
roles?: Record<string, string>;
|
|
52
|
+
}): MediaSource[];
|
|
53
|
+
/**
|
|
54
|
+
* Absolutises every media URL inside a payload, on the way in.
|
|
55
|
+
*
|
|
56
|
+
* One mechanism for CMS media and product images alike ([chapter 08](../../../docs/spec/08-media.md)),
|
|
57
|
+
* where Spartacus has two unrelated ones. The walk is shape-agnostic because media reaches the
|
|
58
|
+
* client as an `Image`, as a group keyed by format code, and as arrays of either.
|
|
59
|
+
*/
|
|
60
|
+
export declare function absolutizeMedia<T>(value: T, baseUrl: string): T;
|
|
61
|
+
/**
|
|
62
|
+
* The `PRIMARY` group of a normalized `Images`, which is what a card, a thumbnail and a gallery's
|
|
63
|
+
* first slide all want. OCC only ever sends one primary image, so an array here is a payload
|
|
64
|
+
* oddity rather than a case to support.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getPrimaryImage(images: Images | undefined): ImageGroup | undefined;
|
|
67
|
+
/** The `GALLERY` groups in `galleryIndex` order, with the primary image first when there is one. */
|
|
68
|
+
export declare function getGalleryImages(images: Images | undefined): ImageGroup[];
|
|
69
|
+
/**
|
|
70
|
+
* Reshapes OCC's flat `Image[]` into `images.PRIMARY.zoom` / `images.GALLERY[i].thumbnail`,
|
|
71
|
+
* ported from `core-libs/core/src/occ/adapters/product/converters/product-image-normalizer.ts:36-100`.
|
|
72
|
+
*
|
|
73
|
+
* Lives in core because product payloads and cart entry products carry the same flat list —
|
|
74
|
+
* one mechanism ([chapter 08](../../../docs/spec/08-media.md)), and no `cart -> product` edge
|
|
75
|
+
* exists to borrow it over ([chapter 01](../../../docs/spec/01-packages.md)).
|
|
76
|
+
*
|
|
77
|
+
* URLs are **not** absolutised here: a converter is a pure function with no access to config, so
|
|
78
|
+
* adapters absolutise the whole payload afterwards through `absolutizeMedia`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function normalizeImages(source: Image[] | undefined): Images;
|
|
81
|
+
//# sourceMappingURL=media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../../src/media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAU,CAAC;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAStD,CAAC;AAEF,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAIpD,CAAC;AAEF,oEAAoE;AACpE,MAAM,MAAM,WAAW,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,CAAC;AAE5D,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CA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