@eldrajs/theme-core 0.3.4 → 0.3.5

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/CHANGELOG.md CHANGED
@@ -5,6 +5,7 @@ Release-please writes the generated notes from commit messages and does not repl
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ - **Currencies (WS-1391).** `SELLING_CURRENCIES`, `currencyForCountry(country)` (one table, country code to selling currency), `countryFromHeader(value)`, `VISITOR_COUNTRY_PATH`, `resolveVisitorCurrency({ base, offered, remembered, country })` (the remembered choice, then the visitor's country, then the store's own currency, each only when offered) and `offeredCurrencies(base, listed)`.
8
9
  - **`getTypeScriptDefinitions({ sdkAugmentation })` (WS-434, contract 6.1.0).** `true` sends
9
10
  `sdkAugmentation=true`, asking the gateway to append the `declare module '@eldrajs/sdk'` block that
10
11
  fills `EldraProductExtensions`, so product extensions are typed. Off by default: without it the
package/dist/index.d.ts CHANGED
@@ -831,4 +831,27 @@ export interface StructuredDataContext {
831
831
  }
832
832
  /** Applies the theme's opt-out and extender to the nodes a page built. Pure. */
833
833
  export declare function applyStructuredDataPolicy(entries: readonly StructuredDataEntry[], policy: StructuredDataPolicy, context: StructuredDataContext): JsonLd[];
834
+ /** The currencies a shop can sell in, in the platform's own order (WS-1383). */
835
+ export declare const SELLING_CURRENCIES: readonly ["ISK", "EUR", "USD", "GBP", "CAD", "DKK", "NOK", "SEK"];
836
+ type SellingCurrency = (typeof SELLING_CURRENCIES)[number];
837
+ /** The selling currency a country pays in (ISO 3166-1 alpha-2, as `countryFromHeader` answers it), or `null`. */
838
+ export declare function currencyForCountry(country: string | null | undefined): SellingCurrency | null;
839
+ export interface VisitorCurrencyInput {
840
+ /** The shop's own currency, what every page is built in. */
841
+ base: string;
842
+ /** The currencies the shop shows, `base` first. */
843
+ offered: readonly string[];
844
+ /** The visitor's earlier choice, if any. */
845
+ remembered?: string | null;
846
+ /** The visitor's country, as the edge reports it. */
847
+ country?: string | null;
848
+ }
849
+ /** Remembered choice, then the visitor's country, then the shop's own currency: each only if offered. */
850
+ export declare function resolveVisitorCurrency(input: VisitorCurrencyInput): string;
851
+ /** Selling currencies only, no repeats, `base` first; a list without `base` is not trusted and answers `[base]`. */
852
+ export declare function offeredCurrencies(base: string, listed: readonly unknown[] | null | undefined): string[];
853
+ /** The site's own route that answers `{ country }` from the edge's `CF-IPCountry` header. */
854
+ export declare const VISITOR_COUNTRY_PATH = "/_eldra/visitor";
855
+ /** A two-letter country from `CF-IPCountry`, or `null` for none, unknown (`XX`) or Tor (`T1`). */
856
+ export declare function countryFromHeader(value: string | null | undefined): string | null;
834
857
  export { type BeforeInputClassification, type BlockFieldDefinition, type BlockFieldsMap, BlockSlotDefinition, type BuildRichTextTreeOptions, CatalogDoc, CatalogList, CatalogQuery, ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssLength, CssTokenLength, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, DynamicRouteResolution, EDIT_MODE_HIDDEN_OPACITY, EldraCatalogReader, EldraClient, EldraClientError, EldraClientOptions, EldraRetryOptions, EntryDoc, EntryList, EntryQuery, FrameRect, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, ImageFraming, LAYOUT_BREAKPOINTS, LayoutBlockNode, LayoutBreakpoint, LayoutBreakpoints, LayoutContainerNode, LayoutDocument, LayoutNode, LayoutRenderBlockNode, LayoutRenderModel, LayoutRenderNode, LayoutStyle, LayoutValidationCode, LayoutValidationError, LayoutValidationIssue, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, type NegotiatedEditorCapabilities, NormalizedLayoutResult, type OverlayRuntime, type OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, PageLayoutDocument, PageLayoutNode, type PageLike, PageMeta, ParsedDynamicRoutePattern, type PreviewMessageRouter, type PreviewRouterMessageType, ResolveEntryListBody, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutStyle, Responsive, ResponsiveTokenValue, type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, type ReusableRenderIdentity, type RichTextDomPoint, type RichTextFieldIdentity, type RichTextMark, type RichTextNode, type RichTextPositionNode, type RichTextPositions, type RichTextRenderChild, type RichTextRenderNode, type RichTextRenderStateChange, type RichTextSelectionContext, type RichTextToolbarControl, RouteTemplateLike, SiteDesignTokenOverrides, SizingLength, SlotValidationContext, Spacing, type StegaMeta, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, ThemeColorToken, ThemeDesignTokens, WidthLength, activeLayoutBreakpoint, applyDesignTokenOverrides, buildDynamicRoutePath, buildTemplateBlockRenames, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, designTokenRevisionHash, encodeStega, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, layoutNodeClass, layoutRenderNodeId, matchDynamicRoutePattern, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, resolveColorSelection, resolveDesignTokenCatalog, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, responsiveValue, stripStega, unscaledFrameRect, validateLayoutDocument };
package/dist/index.js CHANGED
@@ -1761,4 +1761,99 @@ function applyStructuredDataPolicy(entries, policy, context) {
1761
1761
  }
1762
1762
  return out;
1763
1763
  }
1764
- export { ANALYTICS_MAX_KEY_BYTES, ANALYTICS_MAX_NAME_BYTES, ANALYTICS_MAX_PROPS, ANALYTICS_MAX_VALUE_BYTES, ANALYTICS_QUEUE_LIMIT, DEFAULT_HOME_TITLE_PATTERN, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DEFAULT_TITLE_PATTERN, DesignTokenValidationError, EDIT_MODE_HIDDEN_OPACITY, EldraClientError, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, LAYOUT_BREAKPOINTS, LD_DESCRIPTION_MAX, LayoutValidationError, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, PREVIEW_ROUTER_MESSAGE_TYPES, RESERVED_THEME_IDS, RICH_TEXT_LEAF_TYPES, RICH_TEXT_MARK_ELEMENTS, RICH_TEXT_PAD_ATTR, RICH_TEXT_TOOLBAR_CONTROLS, ReusableComponentSnapshotCache, SEO_SYNTAX, SITEMAP_MAX_BYTES, SITEMAP_MAX_URLS, STRUCTURED_DATA_TYPES, THEME_ID_PATTERN, activeLayoutBreakpoint, applyDesignTokenOverrides, applyStructuredDataPolicy, blockApiIdOf, buildAlternates, buildBreadcrumbLd, buildDynamicRoutePath, buildItemListLd, buildOrganizationLd, buildProductLd, buildRichTextTree, buildRobots, buildSitemap, buildTemplateBlockRenames, buildWebSiteLd, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, computeRichTextPositions, createAnalytics, createEldraClient, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, describeSelectionContext, designTokenRevisionHash, domRangeToPositions, encodeEntryDataStega, encodeStega, escapeXml, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, getRegisteredThemeId, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, isBlockFieldLocalized, layoutIdentityOf, layoutNodeClass, layoutRenderNodeId, ldPlainText, ldPrice, matchDynamicRoutePattern, normalizeAnalyticsProps, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, pickSeoLocale, projectEntryDataLocale, registerBlockFields, registerThemeId, renderSeoTitle, resolveColorSelection, resolveDesignTokenCatalog, resolveDomPoint, resolveDomPosition, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, resolveSeo, responsiveValue, restampRichTextPositions, richTextMarkNameOf, richTextNodeSize, richTextText, safeHref, serializeLd, siteOrigin, sitemapLastmod, stripStega, substituteSeoPattern, themeSchemaApiId, tidySeoTitle, truncateUtf8, unscaledFrameRect, validGtin, validateLayoutDocument };
1764
+ // src/currency.ts
1765
+ /** The currencies a shop can sell in, in the platform's own order (WS-1383). */
1766
+ const SELLING_CURRENCIES = [
1767
+ "ISK",
1768
+ "EUR",
1769
+ "USD",
1770
+ "GBP",
1771
+ "CAD",
1772
+ "DKK",
1773
+ "NOK",
1774
+ "SEK"
1775
+ ];
1776
+ const COUNTRY_CURRENCY = {
1777
+ ...Object.fromEntries([
1778
+ "AD",
1779
+ "AT",
1780
+ "AX",
1781
+ "BE",
1782
+ "BG",
1783
+ "BL",
1784
+ "CY",
1785
+ "DE",
1786
+ "EE",
1787
+ "ES",
1788
+ "FI",
1789
+ "FR",
1790
+ "GF",
1791
+ "GP",
1792
+ "GR",
1793
+ "HR",
1794
+ "IE",
1795
+ "IT",
1796
+ "LT",
1797
+ "LU",
1798
+ "LV",
1799
+ "MC",
1800
+ "ME",
1801
+ "MF",
1802
+ "MQ",
1803
+ "MT",
1804
+ "NL",
1805
+ "PM",
1806
+ "PT",
1807
+ "RE",
1808
+ "SI",
1809
+ "SK",
1810
+ "SM",
1811
+ "VA",
1812
+ "XK",
1813
+ "YT"
1814
+ ].map((country) => [country, "EUR"])),
1815
+ IS: "ISK",
1816
+ US: "USD",
1817
+ AS: "USD",
1818
+ GU: "USD",
1819
+ MP: "USD",
1820
+ PR: "USD",
1821
+ UM: "USD",
1822
+ VI: "USD",
1823
+ GB: "GBP",
1824
+ GG: "GBP",
1825
+ IM: "GBP",
1826
+ JE: "GBP",
1827
+ CA: "CAD",
1828
+ DK: "DKK",
1829
+ FO: "DKK",
1830
+ GL: "DKK",
1831
+ NO: "NOK",
1832
+ SJ: "NOK",
1833
+ SE: "SEK"
1834
+ };
1835
+ /** The selling currency a country pays in (ISO 3166-1 alpha-2, as `countryFromHeader` answers it), or `null`. */
1836
+ function currencyForCountry(country) {
1837
+ return country ? COUNTRY_CURRENCY[country] ?? null : null;
1838
+ }
1839
+ /** Remembered choice, then the visitor's country, then the shop's own currency: each only if offered. */
1840
+ function resolveVisitorCurrency(input) {
1841
+ const offered = new Set(input.offered);
1842
+ if (input.remembered && offered.has(input.remembered)) return input.remembered;
1843
+ const fromCountry = currencyForCountry(input.country);
1844
+ if (fromCountry !== null && offered.has(fromCountry)) return fromCountry;
1845
+ return input.base;
1846
+ }
1847
+ /** Selling currencies only, no repeats, `base` first; a list without `base` is not trusted and answers `[base]`. */
1848
+ function offeredCurrencies(base, listed) {
1849
+ if (!Array.isArray(listed) || !listed.includes(base)) return [base];
1850
+ return [base, ...SELLING_CURRENCIES.filter((code) => code !== base && listed.includes(code))];
1851
+ }
1852
+ /** The site's own route that answers `{ country }` from the edge's `CF-IPCountry` header. */
1853
+ const VISITOR_COUNTRY_PATH = "/_eldra/visitor";
1854
+ /** A two-letter country from `CF-IPCountry`, or `null` for none, unknown (`XX`) or Tor (`T1`). */
1855
+ function countryFromHeader(value) {
1856
+ const code = (value ?? "").trim().toUpperCase();
1857
+ return /^[A-Z]{2}$/.test(code) && code !== "XX" ? code : null;
1858
+ }
1859
+ export { ANALYTICS_MAX_KEY_BYTES, ANALYTICS_MAX_NAME_BYTES, ANALYTICS_MAX_PROPS, ANALYTICS_MAX_VALUE_BYTES, ANALYTICS_QUEUE_LIMIT, DEFAULT_HOME_TITLE_PATTERN, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DEFAULT_TITLE_PATTERN, DesignTokenValidationError, EDIT_MODE_HIDDEN_OPACITY, EldraClientError, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, LAYOUT_BREAKPOINTS, LD_DESCRIPTION_MAX, LayoutValidationError, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, PREVIEW_ROUTER_MESSAGE_TYPES, RESERVED_THEME_IDS, RICH_TEXT_LEAF_TYPES, RICH_TEXT_MARK_ELEMENTS, RICH_TEXT_PAD_ATTR, RICH_TEXT_TOOLBAR_CONTROLS, ReusableComponentSnapshotCache, SELLING_CURRENCIES, SEO_SYNTAX, SITEMAP_MAX_BYTES, SITEMAP_MAX_URLS, STRUCTURED_DATA_TYPES, THEME_ID_PATTERN, VISITOR_COUNTRY_PATH, activeLayoutBreakpoint, applyDesignTokenOverrides, applyStructuredDataPolicy, blockApiIdOf, buildAlternates, buildBreadcrumbLd, buildDynamicRoutePath, buildItemListLd, buildOrganizationLd, buildProductLd, buildRichTextTree, buildRobots, buildSitemap, buildTemplateBlockRenames, buildWebSiteLd, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, computeRichTextPositions, countryFromHeader, createAnalytics, createEldraClient, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, currencyForCountry, decodeStega, describeSelectionContext, designTokenRevisionHash, domRangeToPositions, encodeEntryDataStega, encodeStega, escapeXml, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, getRegisteredThemeId, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, isBlockFieldLocalized, layoutIdentityOf, layoutNodeClass, layoutRenderNodeId, ldPlainText, ldPrice, matchDynamicRoutePattern, normalizeAnalyticsProps, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, offeredCurrencies, parseDynamicRoutePattern, parseImageFramingValueAttr, pickSeoLocale, projectEntryDataLocale, registerBlockFields, registerThemeId, renderSeoTitle, resolveColorSelection, resolveDesignTokenCatalog, resolveDomPoint, resolveDomPosition, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, resolveSeo, resolveVisitorCurrency, responsiveValue, restampRichTextPositions, richTextMarkNameOf, richTextNodeSize, richTextText, safeHref, serializeLd, siteOrigin, sitemapLastmod, stripStega, substituteSeoPattern, themeSchemaApiId, tidySeoTitle, truncateUtf8, unscaledFrameRect, validGtin, validateLayoutDocument };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-core",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Framework-free core of the Eldra theme SDK: the Studio preview bridge, stega encoding, the overlay runtime, layout CSS, rich-text positions, design tokens and image framing.",
5
5
  "keywords": [
6
6
  "cms",