@endora-commerce/contracts 0.108.0 → 0.110.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/dist/actor.d.ts +16 -0
- package/dist/actor.d.ts.map +1 -1
- package/dist/addresses.d.ts +35 -0
- package/dist/addresses.d.ts.map +1 -1
- package/dist/addresses.js +8 -1
- package/dist/addresses.js.map +1 -1
- package/dist/admin-actions.d.ts +12 -3
- package/dist/admin-actions.d.ts.map +1 -1
- package/dist/admin-actions.js +34 -3
- package/dist/admin-actions.js.map +1 -1
- package/dist/admin-contributions.d.ts +94 -10
- package/dist/admin-contributions.d.ts.map +1 -1
- package/dist/admin-contributions.js +65 -0
- package/dist/admin-contributions.js.map +1 -1
- package/dist/admin-notifications.d.ts +17 -1
- package/dist/admin-notifications.d.ts.map +1 -1
- package/dist/admin-preferences.d.ts +108 -0
- package/dist/admin-preferences.d.ts.map +1 -0
- package/dist/admin-preferences.js +133 -0
- package/dist/admin-preferences.js.map +1 -0
- package/dist/admin-roles.d.ts +8 -2
- package/dist/admin-roles.d.ts.map +1 -1
- package/dist/admin-roles.js.map +1 -1
- package/dist/admin-users.d.ts +9 -0
- package/dist/admin-users.d.ts.map +1 -1
- package/dist/admin.d.ts +92 -5
- package/dist/admin.d.ts.map +1 -1
- package/dist/admin.js +86 -3
- package/dist/admin.js.map +1 -1
- package/dist/assets-library.d.ts +123 -3
- package/dist/assets-library.d.ts.map +1 -1
- package/dist/assets-library.js +11 -3
- package/dist/assets-library.js.map +1 -1
- package/dist/audit-logs.d.ts +12 -0
- package/dist/audit-logs.d.ts.map +1 -1
- package/dist/audit-logs.js +12 -0
- package/dist/audit-logs.js.map +1 -1
- package/dist/blog.d.ts +431 -14
- package/dist/blog.d.ts.map +1 -1
- package/dist/blog.js +251 -7
- package/dist/blog.js.map +1 -1
- package/dist/carts.d.ts +507 -92
- package/dist/carts.d.ts.map +1 -1
- package/dist/carts.js +197 -21
- package/dist/carts.js.map +1 -1
- package/dist/catalog.d.ts +515 -144
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +356 -68
- package/dist/catalog.js.map +1 -1
- package/dist/cms-brand.d.ts +2233 -0
- package/dist/cms-brand.d.ts.map +1 -0
- package/dist/cms-brand.js +311 -0
- package/dist/cms-brand.js.map +1 -0
- package/dist/cms-contact-form.d.ts +55 -0
- package/dist/cms-contact-form.d.ts.map +1 -0
- package/dist/cms-contact-form.js +100 -0
- package/dist/cms-contact-form.js.map +1 -0
- package/dist/cms.d.ts +576 -17
- package/dist/cms.d.ts.map +1 -1
- package/dist/cms.js +251 -0
- package/dist/cms.js.map +1 -1
- package/dist/common.d.ts +23 -6
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +25 -2
- package/dist/common.js.map +1 -1
- package/dist/comparisons.d.ts +28 -21
- package/dist/comparisons.d.ts.map +1 -1
- package/dist/comparisons.js +2 -1
- package/dist/comparisons.js.map +1 -1
- package/dist/credit-limits.d.ts +1 -0
- package/dist/credit-limits.d.ts.map +1 -1
- package/dist/credit-limits.js +14 -0
- package/dist/credit-limits.js.map +1 -1
- package/dist/crm-rich-text.d.ts +10 -61
- package/dist/crm-rich-text.d.ts.map +1 -1
- package/dist/crm-rich-text.js +10 -300
- package/dist/crm-rich-text.js.map +1 -1
- package/dist/crm.d.ts +173 -115
- package/dist/crm.d.ts.map +1 -1
- package/dist/crm.js +35 -88
- package/dist/crm.js.map +1 -1
- package/dist/custom-fields.d.ts +54 -22
- package/dist/custom-fields.d.ts.map +1 -1
- package/dist/custom-fields.js +21 -1
- package/dist/custom-fields.js.map +1 -1
- package/dist/customer-accounts.d.ts +216 -22
- package/dist/customer-accounts.d.ts.map +1 -1
- package/dist/customer-accounts.js +70 -0
- package/dist/customer-accounts.js.map +1 -1
- package/dist/customers.d.ts +40 -73
- package/dist/customers.d.ts.map +1 -1
- package/dist/customers.js +45 -10
- package/dist/customers.js.map +1 -1
- package/dist/document-templates.d.ts +35 -23
- package/dist/document-templates.d.ts.map +1 -1
- package/dist/document-values.d.ts +8 -0
- package/dist/document-values.d.ts.map +1 -1
- package/dist/document-values.js +24 -6
- package/dist/document-values.js.map +1 -1
- package/dist/email.d.ts +5 -0
- package/dist/email.d.ts.map +1 -1
- package/dist/errors.d.ts +224 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +269 -1
- package/dist/errors.js.map +1 -1
- package/dist/forms-logic.d.ts +79 -0
- package/dist/forms-logic.d.ts.map +1 -0
- package/dist/forms-logic.fixtures.d.ts +52 -0
- package/dist/forms-logic.fixtures.d.ts.map +1 -0
- package/dist/forms-logic.fixtures.js +610 -0
- package/dist/forms-logic.fixtures.js.map +1 -0
- package/dist/forms-logic.js +699 -0
- package/dist/forms-logic.js.map +1 -0
- package/dist/forms.d.ts +9833 -0
- package/dist/forms.d.ts.map +1 -0
- package/dist/forms.js +827 -0
- package/dist/forms.js.map +1 -0
- package/dist/import-export.d.ts +180 -0
- package/dist/import-export.d.ts.map +1 -1
- package/dist/import-export.js +60 -0
- package/dist/import-export.js.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -1
- package/dist/index.js.map +1 -1
- package/dist/inventory.d.ts +6 -6
- package/dist/invoice-ledger.d.ts +7 -7
- package/dist/invoices.d.ts +6 -2
- package/dist/invoices.d.ts.map +1 -1
- package/dist/invoices.js +7 -0
- package/dist/invoices.js.map +1 -1
- package/dist/megamenu.d.ts +674 -0
- package/dist/megamenu.d.ts.map +1 -1
- package/dist/megamenu.js +96 -3
- package/dist/megamenu.js.map +1 -1
- package/dist/mfa.d.ts +125 -4
- package/dist/mfa.d.ts.map +1 -1
- package/dist/mfa.js +54 -2
- package/dist/mfa.js.map +1 -1
- package/dist/modules.d.ts +44 -5
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +73 -0
- package/dist/modules.js.map +1 -1
- package/dist/money-decimal.d.ts +54 -0
- package/dist/money-decimal.d.ts.map +1 -1
- package/dist/money-decimal.js +95 -0
- package/dist/money-decimal.js.map +1 -1
- package/dist/newsletter.d.ts +7 -7
- package/dist/orders.d.ts +128 -10
- package/dist/orders.d.ts.map +1 -1
- package/dist/orders.js +74 -4
- package/dist/orders.js.map +1 -1
- package/dist/organization-registry-lookup.d.ts +362 -0
- package/dist/organization-registry-lookup.d.ts.map +1 -0
- package/dist/organization-registry-lookup.js +196 -0
- package/dist/organization-registry-lookup.js.map +1 -0
- package/dist/organization-roles.d.ts +340 -0
- package/dist/organization-roles.d.ts.map +1 -0
- package/dist/organization-roles.js +211 -0
- package/dist/organization-roles.js.map +1 -0
- package/dist/organizations.d.ts +123 -89
- package/dist/organizations.d.ts.map +1 -1
- package/dist/organizations.js +68 -24
- package/dist/organizations.js.map +1 -1
- package/dist/page-builder-props.d.ts +1401 -0
- package/dist/page-builder-props.d.ts.map +1 -0
- package/dist/page-builder-props.js +266 -0
- package/dist/page-builder-props.js.map +1 -0
- package/dist/page-builder-values.d.ts +95 -0
- package/dist/page-builder-values.d.ts.map +1 -0
- package/dist/page-builder-values.js +164 -0
- package/dist/page-builder-values.js.map +1 -0
- package/dist/pim-connector.d.ts +6 -2
- package/dist/pim-connector.d.ts.map +1 -1
- package/dist/pim-connector.js +6 -2
- package/dist/pim-connector.js.map +1 -1
- package/dist/pim-field-path.d.ts +5 -1
- package/dist/pim-field-path.d.ts.map +1 -1
- package/dist/pim-field-path.js +37 -81
- package/dist/pim-field-path.js.map +1 -1
- package/dist/pim-locale-mapping.d.ts +131 -0
- package/dist/pim-locale-mapping.d.ts.map +1 -0
- package/dist/pim-locale-mapping.js +193 -0
- package/dist/pim-locale-mapping.js.map +1 -0
- package/dist/platform-language.d.ts +9 -0
- package/dist/platform-language.d.ts.map +1 -1
- package/dist/platform-language.js +14 -0
- package/dist/platform-language.js.map +1 -1
- package/dist/price-books.d.ts +47 -43
- package/dist/price-books.d.ts.map +1 -1
- package/dist/price-books.js +6 -2
- package/dist/price-books.js.map +1 -1
- package/dist/price-lists.d.ts +48 -14
- package/dist/price-lists.d.ts.map +1 -1
- package/dist/price-lists.js +24 -1
- package/dist/price-lists.js.map +1 -1
- package/dist/product-feeds.d.ts +144 -84
- package/dist/product-feeds.d.ts.map +1 -1
- package/dist/product-feeds.js +23 -0
- package/dist/product-feeds.js.map +1 -1
- package/dist/product-scope-model.d.ts +161 -0
- package/dist/product-scope-model.d.ts.map +1 -0
- package/dist/product-scope-model.js +161 -0
- package/dist/product-scope-model.js.map +1 -0
- package/dist/product-scope-overrides.d.ts +0 -103
- package/dist/product-scope-overrides.d.ts.map +1 -1
- package/dist/product-scope-overrides.js +0 -54
- package/dist/product-scope-overrides.js.map +1 -1
- package/dist/product-scoped-values.d.ts +2610 -0
- package/dist/product-scoped-values.d.ts.map +1 -0
- package/dist/product-scoped-values.js +425 -0
- package/dist/product-scoped-values.js.map +1 -0
- package/dist/product-scopes.d.ts +746 -0
- package/dist/product-scopes.d.ts.map +1 -0
- package/dist/product-scopes.js +436 -0
- package/dist/product-scopes.js.map +1 -0
- package/dist/product-summary-text.d.ts +23 -0
- package/dist/product-summary-text.d.ts.map +1 -0
- package/dist/product-summary-text.js +64 -0
- package/dist/product-summary-text.js.map +1 -0
- package/dist/product-tax-rates.d.ts +38 -0
- package/dist/product-tax-rates.d.ts.map +1 -0
- package/dist/product-tax-rates.js +45 -0
- package/dist/product-tax-rates.js.map +1 -0
- package/dist/product-url-keys.d.ts +210 -0
- package/dist/product-url-keys.d.ts.map +1 -0
- package/dist/product-url-keys.js +200 -0
- package/dist/product-url-keys.js.map +1 -0
- package/dist/product-value-resolver.d.ts +37 -60
- package/dist/product-value-resolver.d.ts.map +1 -1
- package/dist/product-value-resolver.js +36 -96
- package/dist/product-value-resolver.js.map +1 -1
- package/dist/projects.d.ts +2370 -0
- package/dist/projects.d.ts.map +1 -0
- package/dist/projects.js +843 -0
- package/dist/projects.js.map +1 -0
- package/dist/promotions.d.ts +10 -10
- package/dist/prompt-actions.d.ts +19 -1
- package/dist/prompt-actions.d.ts.map +1 -1
- package/dist/prompt-actions.js +31 -2
- package/dist/prompt-actions.js.map +1 -1
- package/dist/pwa.d.ts +2 -2
- package/dist/quick-order.d.ts +150 -7
- package/dist/quick-order.d.ts.map +1 -1
- package/dist/quick-order.js +76 -2
- package/dist/quick-order.js.map +1 -1
- package/dist/quote-requests.d.ts +99 -13
- package/dist/quote-requests.d.ts.map +1 -1
- package/dist/quote-requests.js +66 -1
- package/dist/quote-requests.js.map +1 -1
- package/dist/record-references.d.ts +252 -0
- package/dist/record-references.d.ts.map +1 -0
- package/dist/record-references.js +178 -0
- package/dist/record-references.js.map +1 -0
- package/dist/record-rich-text.d.ts +66 -0
- package/dist/record-rich-text.d.ts.map +1 -0
- package/dist/record-rich-text.js +304 -0
- package/dist/record-rich-text.js.map +1 -0
- package/dist/returns.d.ts +234 -52
- package/dist/returns.d.ts.map +1 -1
- package/dist/returns.js +139 -26
- package/dist/returns.js.map +1 -1
- package/dist/sales-channels.d.ts +51 -7
- package/dist/sales-channels.d.ts.map +1 -1
- package/dist/sales-channels.js +38 -4
- package/dist/sales-channels.js.map +1 -1
- package/dist/saved-list-views.d.ts +56 -0
- package/dist/saved-list-views.d.ts.map +1 -1
- package/dist/saved-list-views.js +27 -1
- package/dist/saved-list-views.js.map +1 -1
- package/dist/scoped-write-encoding.d.ts +100 -0
- package/dist/scoped-write-encoding.d.ts.map +1 -0
- package/dist/scoped-write-encoding.js +135 -0
- package/dist/scoped-write-encoding.js.map +1 -0
- package/dist/search.d.ts +25 -15
- package/dist/search.d.ts.map +1 -1
- package/dist/seo.d.ts +127 -15
- package/dist/seo.d.ts.map +1 -1
- package/dist/seo.js +38 -4
- package/dist/seo.js.map +1 -1
- package/dist/settings.d.ts +161 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +73 -3
- package/dist/settings.js.map +1 -1
- package/dist/shopping-lists.d.ts +24 -3
- package/dist/shopping-lists.d.ts.map +1 -1
- package/dist/shopping-lists.js +20 -0
- package/dist/shopping-lists.js.map +1 -1
- package/dist/storefront-cache-tags.d.ts +41 -0
- package/dist/storefront-cache-tags.d.ts.map +1 -1
- package/dist/storefront-cache-tags.js +36 -0
- package/dist/storefront-cache-tags.js.map +1 -1
- package/dist/storefront-language-path.d.ts +77 -0
- package/dist/storefront-language-path.d.ts.map +1 -0
- package/dist/storefront-language-path.js +123 -0
- package/dist/storefront-language-path.js.map +1 -0
- package/dist/storefront-value-overrides.d.ts +18 -56
- package/dist/storefront-value-overrides.d.ts.map +1 -1
- package/dist/storefront-value-overrides.js +11 -86
- package/dist/storefront-value-overrides.js.map +1 -1
- package/dist/tasks.d.ts +2842 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +901 -0
- package/dist/tasks.js.map +1 -0
- package/dist/transactional-emails.d.ts +14 -11
- package/dist/transactional-emails.d.ts.map +1 -1
- package/dist/transactional-emails.js +13 -0
- package/dist/transactional-emails.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Feature 167 (`specs/167-storefront-locale-path/`, issue #396) — the language of a
|
|
4
|
+
* storefront page is the first segment of its path (`/pl/p/wiertarka`, `/en/p/drill`).
|
|
5
|
+
*
|
|
6
|
+
* This module is the **one** derivation of a channel's URL language prefixes
|
|
7
|
+
* (`contracts/url-shape.md` §2) and the one composer of a storefront page path in a
|
|
8
|
+
* language. The backend answers the derived prefixes on the public channel read, so the
|
|
9
|
+
* storefront never re-derives them; every backend emitter composes its storefront URLs
|
|
10
|
+
* through {@link storefrontPagePath}. Nothing is stored: a prefix is a function of the
|
|
11
|
+
* channel's languages and its *prefix the default language* setting, so it cannot drift
|
|
12
|
+
* from them.
|
|
13
|
+
*
|
|
14
|
+
* A leaf: imports only `zod`.
|
|
15
|
+
*/
|
|
16
|
+
/** What a URL composer needs to know about a channel. `CachedChannel` and `PublicSalesChannel` satisfy it. */
|
|
17
|
+
export interface ChannelUrlFacts {
|
|
18
|
+
readonly languages: readonly string[];
|
|
19
|
+
readonly defaultLanguage: string;
|
|
20
|
+
readonly prefixDefaultLanguage: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** The prefix grammar of `url-shape.md` §1: a lower-case primary subtag, optionally the full lower-case tag. */
|
|
23
|
+
export declare const URL_LANGUAGE_PREFIX_PATTERN: RegExp;
|
|
24
|
+
export declare const channelUrlLanguageSchema: z.ZodObject<{
|
|
25
|
+
languageCode: z.ZodString;
|
|
26
|
+
prefix: z.ZodString;
|
|
27
|
+
prefixed: z.ZodBoolean;
|
|
28
|
+
isDefault: z.ZodBoolean;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type ChannelUrlLanguage = z.infer<typeof channelUrlLanguageSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* A primary subtag shared by several channel languages (`en` for `en-US` and `en-GB`).
|
|
33
|
+
* It is no language's prefix, but a request under it is answered 307 to one of its
|
|
34
|
+
* languages (FR-015), so links taken before the channel gained the second variant keep
|
|
35
|
+
* working.
|
|
36
|
+
*/
|
|
37
|
+
export declare const channelUrlLanguageAliasSchema: z.ZodObject<{
|
|
38
|
+
alias: z.ZodString;
|
|
39
|
+
languageCodes: z.ZodArray<z.ZodString>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export type ChannelUrlLanguageAlias = z.infer<typeof channelUrlLanguageAliasSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* The URL language of every channel language (`url-shape.md` §2): the lower-case primary
|
|
44
|
+
* subtag when it is the only channel language with that subtag, else the full lower-case
|
|
45
|
+
* tag. Channel order, the default language included. Throws on a case-insensitive
|
|
46
|
+
* duplicate code, which the channel validator already refuses.
|
|
47
|
+
*/
|
|
48
|
+
export declare function channelUrlLanguages(channel: ChannelUrlFacts): ChannelUrlLanguage[];
|
|
49
|
+
/** The split aliases of a channel (FR-015): each primary subtag shared by two or more channel languages. */
|
|
50
|
+
export declare function channelUrlLanguageAliases(channel: ChannelUrlFacts): ChannelUrlLanguageAlias[];
|
|
51
|
+
/**
|
|
52
|
+
* The storefront path of a page in a language. `path` is a **logical** path — today's
|
|
53
|
+
* route (`/`, `/c/x`, `/p/k?variant=A`); the answer is `/<prefix>` + path when the
|
|
54
|
+
* language is prefixed (`/<prefix>` alone for `/`), else `path`. The query and fragment
|
|
55
|
+
* are kept verbatim. Throws on a language the channel does not have: an emitter asking
|
|
56
|
+
* for one has a bug.
|
|
57
|
+
*/
|
|
58
|
+
export declare function storefrontPagePath(input: {
|
|
59
|
+
path: string;
|
|
60
|
+
languageCode: string;
|
|
61
|
+
channel: ChannelUrlFacts;
|
|
62
|
+
}): string;
|
|
63
|
+
/** The unprefixed URL of a logical path — the `x-default` target in both setting states (`url-shape.md` §8). */
|
|
64
|
+
export declare function storefrontDefaultPath(path: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* The storefront path of a page for a **message** (an e-mail link, a redirect a
|
|
67
|
+
* backend route answers) — feature 167, FR-034. The language is the one the message
|
|
68
|
+
* is rendered in when the channel serves it (exact tag, then primary subtag), else
|
|
69
|
+
* the channel's default language. With no channel known the logical path is answered
|
|
70
|
+
* unchanged: the storefront's redirects then choose the language.
|
|
71
|
+
*/
|
|
72
|
+
export declare function storefrontPagePathFor(input: {
|
|
73
|
+
path: string;
|
|
74
|
+
channel: ChannelUrlFacts | null | undefined;
|
|
75
|
+
requestedLanguage?: string | null | undefined;
|
|
76
|
+
}): string;
|
|
77
|
+
//# sourceMappingURL=storefront-language-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storefront-language-path.d.ts","sourceRoot":"","sources":["../src/storefront-language-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;GAaG;AAEH,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC;CACzC;AAED,gHAAgH;AAChH,eAAO,MAAM,2BAA2B,QAAkC,CAAC;AAE3E,eAAO,MAAM,wBAAwB;;;;;iBAMnC,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B;;;iBAGxC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAoBpF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,EAAE,CAkBlF;AAED,4GAA4G;AAC5G,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,eAAe,GAAG,uBAAuB,EAAE,CAS7F;AAQD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,eAAe,CAAC;CAC1B,GAAG,MAAM,CAUT;AAED,gHAAgH;AAChH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC/C,GAAG,MAAM,CAWT"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The prefix grammar of `url-shape.md` §1: a lower-case primary subtag, optionally the full lower-case tag. */
|
|
3
|
+
export const URL_LANGUAGE_PREFIX_PATTERN = /^[a-z]{2,3}(-[a-z0-9]{1,8})*$/;
|
|
4
|
+
export const channelUrlLanguageSchema = z.object({
|
|
5
|
+
languageCode: z.string().min(1).max(16),
|
|
6
|
+
prefix: z.string().regex(URL_LANGUAGE_PREFIX_PATTERN),
|
|
7
|
+
/** `false` only for the default language with `prefixDefaultLanguage` off. */
|
|
8
|
+
prefixed: z.boolean(),
|
|
9
|
+
isDefault: z.boolean(),
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* A primary subtag shared by several channel languages (`en` for `en-US` and `en-GB`).
|
|
13
|
+
* It is no language's prefix, but a request under it is answered 307 to one of its
|
|
14
|
+
* languages (FR-015), so links taken before the channel gained the second variant keep
|
|
15
|
+
* working.
|
|
16
|
+
*/
|
|
17
|
+
export const channelUrlLanguageAliasSchema = z.object({
|
|
18
|
+
alias: z.string().regex(/^[a-z]{2,3}$/),
|
|
19
|
+
languageCodes: z.array(z.string()).min(2),
|
|
20
|
+
});
|
|
21
|
+
function primarySubtag(code) {
|
|
22
|
+
return code.split('-')[0].toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
/** The channel's languages in channel order, the default language included (first when absent). */
|
|
25
|
+
function orderedLanguages(channel) {
|
|
26
|
+
const list = [...channel.languages];
|
|
27
|
+
const hasDefault = list.some((code) => code.toLowerCase() === channel.defaultLanguage.toLowerCase());
|
|
28
|
+
if (!hasDefault)
|
|
29
|
+
list.unshift(channel.defaultLanguage);
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
for (const code of list) {
|
|
32
|
+
const key = code.toLowerCase();
|
|
33
|
+
if (seen.has(key))
|
|
34
|
+
throw new Error(`channelUrlLanguages: duplicate language code "${code}"`);
|
|
35
|
+
seen.add(key);
|
|
36
|
+
}
|
|
37
|
+
return list;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The URL language of every channel language (`url-shape.md` §2): the lower-case primary
|
|
41
|
+
* subtag when it is the only channel language with that subtag, else the full lower-case
|
|
42
|
+
* tag. Channel order, the default language included. Throws on a case-insensitive
|
|
43
|
+
* duplicate code, which the channel validator already refuses.
|
|
44
|
+
*/
|
|
45
|
+
export function channelUrlLanguages(channel) {
|
|
46
|
+
const languages = orderedLanguages(channel);
|
|
47
|
+
const perPrimary = new Map();
|
|
48
|
+
for (const code of languages) {
|
|
49
|
+
const primary = primarySubtag(code);
|
|
50
|
+
perPrimary.set(primary, (perPrimary.get(primary) ?? 0) + 1);
|
|
51
|
+
}
|
|
52
|
+
const defaultKey = channel.defaultLanguage.toLowerCase();
|
|
53
|
+
return languages.map((code) => {
|
|
54
|
+
const primary = primarySubtag(code);
|
|
55
|
+
const isDefault = code.toLowerCase() === defaultKey;
|
|
56
|
+
return {
|
|
57
|
+
languageCode: code,
|
|
58
|
+
prefix: perPrimary.get(primary) === 1 ? primary : code.toLowerCase(),
|
|
59
|
+
prefixed: !(isDefault && !channel.prefixDefaultLanguage),
|
|
60
|
+
isDefault,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** The split aliases of a channel (FR-015): each primary subtag shared by two or more channel languages. */
|
|
65
|
+
export function channelUrlLanguageAliases(channel) {
|
|
66
|
+
const groups = new Map();
|
|
67
|
+
for (const code of orderedLanguages(channel)) {
|
|
68
|
+
const primary = primarySubtag(code);
|
|
69
|
+
groups.set(primary, [...(groups.get(primary) ?? []), code]);
|
|
70
|
+
}
|
|
71
|
+
return [...groups.entries()]
|
|
72
|
+
.filter(([, codes]) => codes.length >= 2)
|
|
73
|
+
.map(([alias, languageCodes]) => ({ alias, languageCodes }));
|
|
74
|
+
}
|
|
75
|
+
function assertLogicalPath(path) {
|
|
76
|
+
if (!path.startsWith('/') || path.startsWith('//')) {
|
|
77
|
+
throw new Error(`storefrontPagePath: "${path}" is not a root-relative storefront path`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The storefront path of a page in a language. `path` is a **logical** path — today's
|
|
82
|
+
* route (`/`, `/c/x`, `/p/k?variant=A`); the answer is `/<prefix>` + path when the
|
|
83
|
+
* language is prefixed (`/<prefix>` alone for `/`), else `path`. The query and fragment
|
|
84
|
+
* are kept verbatim. Throws on a language the channel does not have: an emitter asking
|
|
85
|
+
* for one has a bug.
|
|
86
|
+
*/
|
|
87
|
+
export function storefrontPagePath(input) {
|
|
88
|
+
assertLogicalPath(input.path);
|
|
89
|
+
const wanted = input.languageCode.toLowerCase();
|
|
90
|
+
const language = channelUrlLanguages(input.channel).find((l) => l.languageCode.toLowerCase() === wanted);
|
|
91
|
+
if (language === undefined) {
|
|
92
|
+
throw new Error(`storefrontPagePath: language "${input.languageCode}" is not a language of the channel`);
|
|
93
|
+
}
|
|
94
|
+
if (!language.prefixed)
|
|
95
|
+
return input.path;
|
|
96
|
+
const rest = /^\/(?=[?#]|$)/.test(input.path) ? input.path.slice(1) : input.path;
|
|
97
|
+
return `/${language.prefix}${rest}`;
|
|
98
|
+
}
|
|
99
|
+
/** The unprefixed URL of a logical path — the `x-default` target in both setting states (`url-shape.md` §8). */
|
|
100
|
+
export function storefrontDefaultPath(path) {
|
|
101
|
+
assertLogicalPath(path);
|
|
102
|
+
return path;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The storefront path of a page for a **message** (an e-mail link, a redirect a
|
|
106
|
+
* backend route answers) — feature 167, FR-034. The language is the one the message
|
|
107
|
+
* is rendered in when the channel serves it (exact tag, then primary subtag), else
|
|
108
|
+
* the channel's default language. With no channel known the logical path is answered
|
|
109
|
+
* unchanged: the storefront's redirects then choose the language.
|
|
110
|
+
*/
|
|
111
|
+
export function storefrontPagePathFor(input) {
|
|
112
|
+
assertLogicalPath(input.path);
|
|
113
|
+
if (!input.channel)
|
|
114
|
+
return input.path;
|
|
115
|
+
const languages = channelUrlLanguages(input.channel);
|
|
116
|
+
const wanted = input.requestedLanguage?.trim().toLowerCase() ?? '';
|
|
117
|
+
const primary = wanted.split('-')[0];
|
|
118
|
+
const match = (wanted === '' ? undefined : languages.find((l) => l.languageCode.toLowerCase() === wanted)) ??
|
|
119
|
+
(wanted === '' ? undefined : languages.find((l) => l.languageCode.split('-')[0].toLowerCase() === primary)) ??
|
|
120
|
+
languages.find((l) => l.isDefault);
|
|
121
|
+
return storefrontPagePath({ path: input.path, languageCode: match.languageCode, channel: input.channel });
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=storefront-language-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storefront-language-path.js","sourceRoot":"","sources":["../src/storefront-language-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwBxB,gHAAgH;AAChH,MAAM,CAAC,MAAM,2BAA2B,GAAG,+BAA+B,CAAC;AAE3E,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,2BAA2B,CAAC;IACrD,8EAA8E;IAC9E,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;CACvB,CAAC,CAAC;AAGH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC,MAAM,CAAC;IACpD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC;IACvC,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC1C,CAAC,CAAC;AAGH,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC;AAC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ACtC,MAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,KAAK,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC;IACnE,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,KAAK,GACT,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC;QAC5F,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,CAAC;QAC5G,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAE,CAAC;IACtC,OAAO,kBAAkB,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AAC5G,CAAC"}
|
|
@@ -1,67 +1,29 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ScopeLevel } from './product-scope-model.js';
|
|
2
|
+
import { type OverrideRow } from './product-value-resolver.js';
|
|
2
3
|
/**
|
|
3
|
-
* Issue #384
|
|
4
|
-
* a storefront read shows
|
|
4
|
+
* Issue #384, rewritten by feature 174 (research R1) — the effective Name, Description or
|
|
5
|
+
* attribute a storefront read shows at the request's (channel, language), given the override
|
|
6
|
+
* rows it already holds.
|
|
5
7
|
*
|
|
6
|
-
* Shared by every storefront read that shows a product's
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* **Only the override slots are taken from the resolver.** The fallback chain
|
|
11
|
-
* is {@link resolveAttribute}, and this file adds no second implementation of
|
|
12
|
-
* it. What it deliberately does *not* take from the resolver is the baseline
|
|
13
|
-
* leg: the storefront reads have always walked their own language fallback
|
|
14
|
-
* over the baseline JSONB (`preferred` → the channel's default language →
|
|
15
|
-
* `en-US` → `en` → first key), which differs from the resolver's
|
|
16
|
-
* (`languageCode` → primary language → first sorted key) in its edges.
|
|
17
|
-
* Replacing it would change what every product *without* an override shows,
|
|
18
|
-
* so an override answers here only when the resolver says a channel slot
|
|
19
|
-
* produced the value, and the caller's existing baseline pick answers
|
|
20
|
-
* otherwise. The baseline is still read for one thing — where that pick
|
|
21
|
-
* stops — so an override never answers for a later language than the one
|
|
22
|
-
* whose baseline text the page would show.
|
|
8
|
+
* Shared by every storefront read that shows a product's text — `catalog`'s product page and
|
|
9
|
+
* listing cards, and `search`'s result cards — so one product cannot show two names depending on
|
|
10
|
+
* which module answered. The chain is {@link resolveAttribute}'s (C×L → C → G); there is no
|
|
11
|
+
* per-language baseline walk any more: the Global value is one string (FR-014).
|
|
23
12
|
*/
|
|
24
|
-
/** The request's resolution context
|
|
13
|
+
/** The request's resolution context: the resolved channel and its content language. */
|
|
25
14
|
export interface StorefrontOverrideContext {
|
|
26
15
|
channelId: string;
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
* {@link overrideLanguages}. A (channel, language) override is looked up at
|
|
30
|
-
* each leg until the baseline has a value for one; the pick's first-key tail
|
|
31
|
-
* is derived from the baseline itself. Empty when nothing is known: only the
|
|
32
|
-
* baseline's first key and the channel-only slot can answer.
|
|
33
|
-
*/
|
|
34
|
-
languages: readonly string[];
|
|
16
|
+
/** Already resolved against the channel; `null` = the channel scope only. */
|
|
17
|
+
languageCode: string | null;
|
|
35
18
|
}
|
|
36
19
|
/**
|
|
37
|
-
* The
|
|
38
|
-
*
|
|
39
|
-
* `en`. A caller whose pick has no channel-default leg passes `undefined` for
|
|
40
|
-
* it, so the override walk mirrors exactly the pick it sits on.
|
|
41
|
-
*/
|
|
42
|
-
export declare function overrideLanguages(preferredLanguage: string | undefined, channelDefaultLanguage: string | undefined): string[];
|
|
43
|
-
/**
|
|
44
|
-
* The override value for one attribute in this context, or `undefined` when no
|
|
45
|
-
* channel slot applies and the caller's baseline should stand.
|
|
46
|
-
*
|
|
47
|
-
* The walk is the baseline pick's own, with the override slot looked at first
|
|
48
|
-
* at every leg: for each language L of `ctx.languages`, a (channel, L)
|
|
49
|
-
* override answers; else, if the baseline has a value for L, the walk stops
|
|
50
|
-
* there. When no leg stopped it and the baseline is a per-language record, its
|
|
51
|
-
* first key — the pick's tail — is the last leg. So an override for a later
|
|
52
|
-
* language never beats a baseline value for an earlier one. Whatever the walk
|
|
53
|
-
* stopped on, the channel-only slot is asked last, exactly as it always was.
|
|
54
|
-
*
|
|
55
|
-
* `baseline` is the raw value the caller's pick reads: `products.name` /
|
|
56
|
-
* `products.description` for the system text, `attributeValues[key]` for a
|
|
57
|
-
* user attribute.
|
|
20
|
+
* The effective value of one field at `ctx`: the C×L row, else the C row, else `global`; an
|
|
21
|
+
* empty override answers `null`.
|
|
58
22
|
*/
|
|
59
|
-
export declare function
|
|
23
|
+
export declare function effectiveScopedValue(overrides: readonly OverrideRow[] | undefined, attributeKey: string, levels: readonly ScopeLevel[], ctx: StorefrontOverrideContext, global: unknown): unknown;
|
|
60
24
|
/**
|
|
61
|
-
* The effective Name or Description
|
|
62
|
-
*
|
|
63
|
-
* language pick over `baseline`, the JSONB it picked from. The pick is kept
|
|
64
|
-
* the caller's so a product without overrides shows byte-identical text.
|
|
25
|
+
* The effective Name or Description at `ctx`: `null` when the answer is an empty override (a
|
|
26
|
+
* description deliberately left empty) or there is no value at all.
|
|
65
27
|
*/
|
|
66
|
-
export declare function effectiveSystemText(overrides: readonly OverrideRow[] | undefined, attributeKey: 'name' | 'description', ctx: StorefrontOverrideContext,
|
|
28
|
+
export declare function effectiveSystemText(overrides: readonly OverrideRow[] | undefined, attributeKey: 'name' | 'description', ctx: StorefrontOverrideContext, global: string | null): string | null;
|
|
67
29
|
//# sourceMappingURL=storefront-value-overrides.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storefront-value-overrides.d.ts","sourceRoot":"","sources":["../src/storefront-value-overrides.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storefront-value-overrides.d.ts","sourceRoot":"","sources":["../src/storefront-value-overrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAEjF;;;;;;;;;GASG;AAEH,uFAAuF;AACvF,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAID;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,WAAW,EAAE,GAAG,SAAS,EAC7C,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,GAAG,EAAE,yBAAyB,EAC9B,MAAM,EAAE,OAAO,GACd,OAAO,CAET;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,SAAS,WAAW,EAAE,GAAG,SAAS,EAC7C,YAAY,EAAE,MAAM,GAAG,aAAa,EACpC,GAAG,EAAE,yBAAyB,EAC9B,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,GAAG,IAAI,CAGf"}
|
|
@@ -1,93 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { resolveAttribute } from './product-value-resolver.js';
|
|
2
|
+
const TEXT_LEVELS = ['G', 'C', 'CL'];
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
* `en`. A caller whose pick has no channel-default leg passes `undefined` for
|
|
7
|
-
* it, so the override walk mirrors exactly the pick it sits on.
|
|
4
|
+
* The effective value of one field at `ctx`: the C×L row, else the C row, else `global`; an
|
|
5
|
+
* empty override answers `null`.
|
|
8
6
|
*/
|
|
9
|
-
export function
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
function isPlainRecord(v) {
|
|
13
|
-
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Whether the baseline answers at `language` — where the caller's pick stops.
|
|
17
|
-
* A per-language record answers where it holds a value (an empty string does
|
|
18
|
-
* not stop the pick, as in the callers' `if (hit)`); a language-agnostic scalar
|
|
19
|
-
* answers at every leg; an absent baseline answers at none.
|
|
20
|
-
*/
|
|
21
|
-
function baselineAnswersAt(baseline, language) {
|
|
22
|
-
if (isPlainRecord(baseline))
|
|
23
|
-
return isNonEmpty(baseline[language]);
|
|
24
|
-
return isNonEmpty(baseline);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* The override value for one attribute in this context, or `undefined` when no
|
|
28
|
-
* channel slot applies and the caller's baseline should stand.
|
|
29
|
-
*
|
|
30
|
-
* The walk is the baseline pick's own, with the override slot looked at first
|
|
31
|
-
* at every leg: for each language L of `ctx.languages`, a (channel, L)
|
|
32
|
-
* override answers; else, if the baseline has a value for L, the walk stops
|
|
33
|
-
* there. When no leg stopped it and the baseline is a per-language record, its
|
|
34
|
-
* first key — the pick's tail — is the last leg. So an override for a later
|
|
35
|
-
* language never beats a baseline value for an earlier one. Whatever the walk
|
|
36
|
-
* stopped on, the channel-only slot is asked last, exactly as it always was.
|
|
37
|
-
*
|
|
38
|
-
* `baseline` is the raw value the caller's pick reads: `products.name` /
|
|
39
|
-
* `products.description` for the system text, `attributeValues[key]` for a
|
|
40
|
-
* user attribute.
|
|
41
|
-
*/
|
|
42
|
-
export function channelOverrideFor(overrides, attributeKey, scope, ctx, baseline) {
|
|
43
|
-
if (!overrides || overrides.length === 0)
|
|
44
|
-
return undefined;
|
|
45
|
-
const resolve = (languageCode) => resolveAttribute({
|
|
46
|
-
attributeKey,
|
|
47
|
-
// No baseline: the baseline leg is the caller's (see the file comment).
|
|
48
|
-
baseline: undefined,
|
|
49
|
-
overrides,
|
|
50
|
-
scope,
|
|
51
|
-
ctx: {
|
|
52
|
-
channelId: ctx.channelId,
|
|
53
|
-
languageCode,
|
|
54
|
-
// Unused: with no baseline, the resolver's primary-language leg cannot answer.
|
|
55
|
-
primaryLanguage: languageCode ?? '',
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
const languageSlot = (languageCode) => {
|
|
59
|
-
const resolved = resolve(languageCode);
|
|
60
|
-
return resolved.source === 'channel+language' ? resolved.value : undefined;
|
|
61
|
-
};
|
|
62
|
-
let stopped = false;
|
|
63
|
-
for (const languageCode of ctx.languages) {
|
|
64
|
-
const v = languageSlot(languageCode);
|
|
65
|
-
if (v !== undefined)
|
|
66
|
-
return v;
|
|
67
|
-
if (baselineAnswersAt(baseline, languageCode)) {
|
|
68
|
-
stopped = true;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (!stopped && isPlainRecord(baseline)) {
|
|
73
|
-
const firstKey = Object.keys(baseline)[0];
|
|
74
|
-
if (firstKey !== undefined) {
|
|
75
|
-
const v = languageSlot(firstKey);
|
|
76
|
-
if (v !== undefined)
|
|
77
|
-
return v;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const channelOnly = resolve(null);
|
|
81
|
-
return channelOnly.source === 'channel' ? channelOnly.value : undefined;
|
|
7
|
+
export function effectiveScopedValue(overrides, attributeKey, levels, ctx, global) {
|
|
8
|
+
return resolveAttribute({ attributeKey, baseline: global, overrides: overrides ?? [], levels, ctx }).value;
|
|
82
9
|
}
|
|
83
10
|
/**
|
|
84
|
-
* The effective Name or Description
|
|
85
|
-
*
|
|
86
|
-
* language pick over `baseline`, the JSONB it picked from. The pick is kept
|
|
87
|
-
* the caller's so a product without overrides shows byte-identical text.
|
|
11
|
+
* The effective Name or Description at `ctx`: `null` when the answer is an empty override (a
|
|
12
|
+
* description deliberately left empty) or there is no value at all.
|
|
88
13
|
*/
|
|
89
|
-
export function effectiveSystemText(overrides, attributeKey, ctx,
|
|
90
|
-
const
|
|
91
|
-
return typeof
|
|
14
|
+
export function effectiveSystemText(overrides, attributeKey, ctx, global) {
|
|
15
|
+
const value = effectiveScopedValue(overrides, attributeKey, TEXT_LEVELS, ctx, global);
|
|
16
|
+
return typeof value === 'string' ? value : null;
|
|
92
17
|
}
|
|
93
18
|
//# sourceMappingURL=storefront-value-overrides.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storefront-value-overrides.js","sourceRoot":"","sources":["../src/storefront-value-overrides.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storefront-value-overrides.js","sourceRoot":"","sources":["../src/storefront-value-overrides.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAoB,MAAM,6BAA6B,CAAC;AAoBjF,MAAM,WAAW,GAA0B,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAA6C,EAC7C,YAAoB,EACpB,MAA6B,EAC7B,GAA8B,EAC9B,MAAe;IAEf,OAAO,gBAAgB,CAAC,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC;AAC7G,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAA6C,EAC7C,YAAoC,EACpC,GAA8B,EAC9B,MAAqB;IAErB,MAAM,KAAK,GAAG,oBAAoB,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACtF,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC"}
|