@eldrajs/theme-core 0.3.5 → 0.3.6

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
+ - **`defaultCurrencyOf(commerce)` (WS-1399).** The currency pages are built in: `defaultCurrency` (contract 6.22.0), else the first of a `currencies` list without the store's own currency, else `currency`. `resolveVisitorCurrency` and `offeredCurrencies` take that default as `base`.
8
9
  - **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)`.
9
10
  - **`getTypeScriptDefinitions({ sdkAugmentation })` (WS-434, contract 6.1.0).** `true` sends
10
11
  `sdkAugmentation=true`, asking the gateway to append the `declare module '@eldrajs/sdk'` block that
package/dist/index.d.ts CHANGED
@@ -837,7 +837,7 @@ type SellingCurrency = (typeof SELLING_CURRENCIES)[number];
837
837
  /** The selling currency a country pays in (ISO 3166-1 alpha-2, as `countryFromHeader` answers it), or `null`. */
838
838
  export declare function currencyForCountry(country: string | null | undefined): SellingCurrency | null;
839
839
  export interface VisitorCurrencyInput {
840
- /** The shop's own currency, what every page is built in. */
840
+ /** The shop's default currency (`defaultCurrencyOf`): what every page is built in. */
841
841
  base: string;
842
842
  /** The currencies the shop shows, `base` first. */
843
843
  offered: readonly string[];
@@ -846,9 +846,15 @@ export interface VisitorCurrencyInput {
846
846
  /** The visitor's country, as the edge reports it. */
847
847
  country?: string | null;
848
848
  }
849
- /** Remembered choice, then the visitor's country, then the shop's own currency: each only if offered. */
849
+ /** Remembered choice, then the visitor's country, then the shop's default: each only if offered. */
850
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]`. */
851
+ /** What pages are built in: `defaultCurrency`, else (before contract 6.22.0) the first of a `currencies` without `currency`, else `currency`. */
852
+ export declare function defaultCurrencyOf(commerce: {
853
+ currency: string;
854
+ currencies?: readonly unknown[] | null;
855
+ defaultCurrency?: unknown;
856
+ }): string;
857
+ /** Selling currencies only, no repeats, `base` (the default) first; a list without `base` is not trusted and answers `[base]`. */
852
858
  export declare function offeredCurrencies(base: string, listed: readonly unknown[] | null | undefined): string[];
853
859
  /** The site's own route that answers `{ country }` from the edge's `CF-IPCountry` header. */
854
860
  export declare const VISITOR_COUNTRY_PATH = "/_eldra/visitor";
package/dist/index.js CHANGED
@@ -1836,7 +1836,7 @@ const COUNTRY_CURRENCY = {
1836
1836
  function currencyForCountry(country) {
1837
1837
  return country ? COUNTRY_CURRENCY[country] ?? null : null;
1838
1838
  }
1839
- /** Remembered choice, then the visitor's country, then the shop's own currency: each only if offered. */
1839
+ /** Remembered choice, then the visitor's country, then the shop's default: each only if offered. */
1840
1840
  function resolveVisitorCurrency(input) {
1841
1841
  const offered = new Set(input.offered);
1842
1842
  if (input.remembered && offered.has(input.remembered)) return input.remembered;
@@ -1844,7 +1844,17 @@ function resolveVisitorCurrency(input) {
1844
1844
  if (fromCountry !== null && offered.has(fromCountry)) return fromCountry;
1845
1845
  return input.base;
1846
1846
  }
1847
- /** Selling currencies only, no repeats, `base` first; a list without `base` is not trusted and answers `[base]`. */
1847
+ /** What pages are built in: `defaultCurrency`, else (before contract 6.22.0) the first of a `currencies` without `currency`, else `currency`. */
1848
+ function defaultCurrencyOf(commerce) {
1849
+ const listed = Array.isArray(commerce.currencies) ? commerce.currencies : [];
1850
+ const candidate = listed.includes(commerce.currency) ? void 0 : listed[0];
1851
+ for (const code of [commerce.defaultCurrency, candidate]) if (isSellingCurrency(code)) return code;
1852
+ return commerce.currency;
1853
+ }
1854
+ function isSellingCurrency(code) {
1855
+ return SELLING_CURRENCIES.includes(code);
1856
+ }
1857
+ /** Selling currencies only, no repeats, `base` (the default) first; a list without `base` is not trusted and answers `[base]`. */
1848
1858
  function offeredCurrencies(base, listed) {
1849
1859
  if (!Array.isArray(listed) || !listed.includes(base)) return [base];
1850
1860
  return [base, ...SELLING_CURRENCIES.filter((code) => code !== base && listed.includes(code))];
@@ -1856,4 +1866,4 @@ function countryFromHeader(value) {
1856
1866
  const code = (value ?? "").trim().toUpperCase();
1857
1867
  return /^[A-Z]{2}$/.test(code) && code !== "XX" ? code : null;
1858
1868
  }
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 };
1869
+ 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, defaultCurrencyOf, 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.5",
3
+ "version": "0.3.6",
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",