@shop-on/theme-runtime 0.5.0 → 0.7.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.
@@ -0,0 +1,18 @@
1
+ //#region src/bytes.d.ts
2
+ /**
3
+ * Binary (1024-step) sizes, one decimal, with a bare `.0` trimmed off.
4
+ *
5
+ * The GB tier is not optional decoration: plan storage ceilings are 5 GiB and
6
+ * 50 GiB, and without it a plan card would advertise "5120.0 MB". The trim
7
+ * matches the API's own copy — `plan_limit_error` formats the same ceilings
8
+ * with `number_to_human_size`, which says "5 GB", so a "5.0 GB" here would
9
+ * contradict the refusal toast the merchant is reading it next to. A real
10
+ * fraction keeps its digit ("1.5 GB").
11
+ *
12
+ * The unit is picked from the ROUNDED value, not the raw one. Deciding the tier
13
+ * first lets any size within half a rounding step of a boundary print a unit
14
+ * that already carried: 1048575 B is under 1 MiB, but at one decimal it is
15
+ * "1024.0 KB" — a KB figure no one writes.
16
+ */
17
+ export declare function formatBytes(bytes: number): string;
18
+ //#endregion
package/dist/bytes.js ADDED
@@ -0,0 +1,33 @@
1
+ //#region src/bytes.ts
2
+ const BYTE_UNITS = [
3
+ "B",
4
+ "KB",
5
+ "MB",
6
+ "GB"
7
+ ];
8
+ /**
9
+ * Binary (1024-step) sizes, one decimal, with a bare `.0` trimmed off.
10
+ *
11
+ * The GB tier is not optional decoration: plan storage ceilings are 5 GiB and
12
+ * 50 GiB, and without it a plan card would advertise "5120.0 MB". The trim
13
+ * matches the API's own copy — `plan_limit_error` formats the same ceilings
14
+ * with `number_to_human_size`, which says "5 GB", so a "5.0 GB" here would
15
+ * contradict the refusal toast the merchant is reading it next to. A real
16
+ * fraction keeps its digit ("1.5 GB").
17
+ *
18
+ * The unit is picked from the ROUNDED value, not the raw one. Deciding the tier
19
+ * first lets any size within half a rounding step of a boundary print a unit
20
+ * that already carried: 1048575 B is under 1 MiB, but at one decimal it is
21
+ * "1024.0 KB" — a KB figure no one writes.
22
+ */
23
+ function formatBytes(bytes) {
24
+ let value = bytes;
25
+ let unit = 0;
26
+ while (unit < BYTE_UNITS.length - 1 && Number(value.toFixed(1)) >= 1024) {
27
+ value /= 1024;
28
+ unit += 1;
29
+ }
30
+ return `${value.toFixed(1).replace(/\.0$/, "")} ${BYTE_UNITS[unit]}`;
31
+ }
32
+ //#endregion
33
+ export { formatBytes };
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ import { isDefaultSingleVariant } from "./product-variants/is-default-single-var
12
12
  import { isVariantSelectable } from "./product-variants/is-variant-selectable.js";
13
13
  import { ResolvedVariant, resolveSelectedVariant } from "./product-variants/resolve-selected-variant.js";
14
14
  import { selectionKey } from "./product-variants/selection-key.js";
15
- import { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, ProductSchemaSource, SectionGroupConfig, TemplateJSON, TemplateSeoSource, WebsiteSchemaSource } from "./template-types.js";
15
+ import { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, OrganizationSchemaSource, ProductSchemaSource, ReturnPolicySchemaSource, SectionGroupConfig, TemplateJSON, TemplateSeoSource, WebsiteSchemaSource } from "./template-types.js";
16
16
  import { staleVariantFlag } from "./product-variants/stale-variant.js";
17
17
  import { SwatchSource, isSwatchOption, swatchSource } from "./product-variants/swatch-source.js";
18
18
  import { VariantPriceRange, variantPriceRange } from "./product-variants/variant-price-range.js";
@@ -22,4 +22,4 @@ import { isOnSale, savePercent } from "./sale.js";
22
22
  import { BuildSeoHeadArgs, SEO_DESCRIPTION_MAX_LENGTH, SeoHead, buildSeoHead, canonicalPath, isNarrowedListing, truncateSeoDescription } from "./seo.js";
23
23
  import { stripPostAuthParams } from "./strip-handoff-url.js";
24
24
  import { thumbhashDataUrl } from "./thumbhash.js";
25
- export { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, BuildSeoHeadArgs, Embed, EmbedKind, type LinkedMetafieldRef, type LinkedMetaobject, type LinkedMetaobjectField, Money, type OptionAvailability, PlayerEmbed, type ProductForVariantState, type ProductOption, type ProductOptionValue, ProductSchemaSource, type ProductVariant, type ResolvedVariant, SEO_DESCRIPTION_MAX_LENGTH, SectionGroupConfig, type SelectedOption, SeoHead, type SwatchSource, type SwatchVariant, TemplateJSON, TemplateSeoSource, type VariantPriceRange, type VariantState, WebsiteSchemaSource, buildAvailabilityIndex, buildSeoHead, buildVariantState, canonicalPath, currencySymbol, defaultPriceMaxBound, embedBackgroundSrc, escapeForScriptTag, findClosestVariant, formatMoney, formatMoneyWithCurrency, initials, isDefaultSingleVariant, isNarrowedListing, isOnSale, isSwatchOption, isVariantSelectable, pageCursor, parseEmbedUrl, productHref, resolveSelectedVariant, savePercent, selectionKey, staleVariantFlag, stripPostAuthParams, swatchSource, thumbhashDataUrl, truncateSeoDescription, variantPriceRange };
25
+ export { ArticleSchemaSource, BlockInstance, BreadcrumbSchemaSource, BuildSeoHeadArgs, Embed, EmbedKind, type LinkedMetafieldRef, type LinkedMetaobject, type LinkedMetaobjectField, Money, type OptionAvailability, OrganizationSchemaSource, PlayerEmbed, type ProductForVariantState, type ProductOption, type ProductOptionValue, ProductSchemaSource, type ProductVariant, type ResolvedVariant, ReturnPolicySchemaSource, SEO_DESCRIPTION_MAX_LENGTH, SectionGroupConfig, type SelectedOption, SeoHead, type SwatchSource, type SwatchVariant, TemplateJSON, TemplateSeoSource, type VariantPriceRange, type VariantState, WebsiteSchemaSource, buildAvailabilityIndex, buildSeoHead, buildVariantState, canonicalPath, currencySymbol, defaultPriceMaxBound, embedBackgroundSrc, escapeForScriptTag, findClosestVariant, formatMoney, formatMoneyWithCurrency, initials, isDefaultSingleVariant, isNarrowedListing, isOnSale, isSwatchOption, isVariantSelectable, pageCursor, parseEmbedUrl, productHref, resolveSelectedVariant, savePercent, selectionKey, staleVariantFlag, stripPostAuthParams, swatchSource, thumbhashDataUrl, truncateSeoDescription, variantPriceRange };
@@ -61,6 +61,9 @@ export interface ProductSchemaSource {
61
61
  description: string;
62
62
  images: string[];
63
63
  sku: string | null;
64
+ /** The default variant's GTIN (EAN/UPC), only when its barcode passes the
65
+ * GS1 check digit. Absent or null emits no `gtin`. */
66
+ gtin?: string | null;
64
67
  vendor: string | null;
65
68
  price: number;
66
69
  currency: string;
@@ -82,6 +85,40 @@ export interface ProductSchemaSource {
82
85
  high: number;
83
86
  offerCount: number;
84
87
  };
88
+ /** The shop's saved return policy, as it applies to THIS product (a
89
+ * final-sale product reads `NotPermitted`). Absent until the merchant saves
90
+ * one under Settings → Returns. */
91
+ returnPolicy?: ReturnPolicySchemaSource;
92
+ }
93
+ /** Schema.org MerchantReturnPolicy source — rides `<ProductJsonLd>`'s offer and
94
+ * `<OrganizationJsonLd>`. Built by `@shop-on/theme-server/structured-data` from
95
+ * the merchant's saved policy; never from the column defaults an unconfigured
96
+ * shop reads back, which are no promise the merchant made. */
97
+ export interface ReturnPolicySchemaSource {
98
+ /** ISO 3166-1 alpha-2 — Google requires `applicableCountry`. */
99
+ country: string;
100
+ category: "FiniteReturnWindow" | "UnlimitedWindow" | "NotPermitted";
101
+ /** Set for `FiniteReturnWindow` only. */
102
+ days?: number;
103
+ /** Who pays to send it back. Absent for `NotPermitted`. */
104
+ fees?: "FreeReturn" | "ReturnFeesCustomerResponsibility" | "ReturnShippingFees";
105
+ /** Set for `ReturnShippingFees` only. */
106
+ shippingFee?: {
107
+ amount: number;
108
+ currency: string;
109
+ };
110
+ /** Percent of the price withheld, when the merchant set one above zero. */
111
+ restockingFeePercent?: number;
112
+ /** Absolute URL of the shop's written refund policy, when it has one. */
113
+ url?: string;
114
+ }
115
+ /** Schema.org Organization source — feeds `<OrganizationJsonLd>` on the
116
+ * homepage: who sells here, their logo, and their return policy. */
117
+ export interface OrganizationSchemaSource {
118
+ name: string;
119
+ url: string;
120
+ logo?: string;
121
+ returnPolicy?: ReturnPolicySchemaSource;
85
122
  }
86
123
  /** Schema.org BreadcrumbList source — feeds `<BreadcrumbJsonLd>`. Items are
87
124
  * ordered root→current and the component assigns the 1-based `position`. URLs
@@ -131,6 +168,8 @@ export interface TemplateJSON {
131
168
  breadcrumbSchema?: BreadcrumbSchemaSource;
132
169
  /** Set by `getHomeTemplate` so the homepage can render `<WebsiteJsonLd>`. */
133
170
  websiteSchema?: WebsiteSchemaSource;
171
+ /** Set by `getHomeTemplate` so the homepage can render `<OrganizationJsonLd>`. */
172
+ organizationSchema?: OrganizationSchemaSource;
134
173
  /** Search-console ownership proofs, set by `getHomeTemplate`. Homepage only:
135
174
  * Google's and Bing's meta-tag verification methods both look at the site
136
175
  * root, so carrying these site-wide would be two dead tags per page. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shop-on/theme-runtime",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "license": "SEE LICENSE IN dist/LICENSE.md",
5
5
  "files": [
6
6
  "dist"
@@ -9,6 +9,7 @@
9
9
  "exports": {
10
10
  ".": "./dist/index.js",
11
11
  "./badge-tags": "./dist/badge-tags.js",
12
+ "./bytes": "./dist/bytes.js",
12
13
  "./cart-discounts": "./dist/cart-discounts.js",
13
14
  "./cart-note": "./dist/cart-note.js",
14
15
  "./color": "./dist/color.js",
@@ -35,7 +36,7 @@
35
36
  },
36
37
  "dependencies": {
37
38
  "thumbhash": "0.1.1",
38
- "@shop-on/theme-contract": "0.5.0"
39
+ "@shop-on/theme-contract": "0.7.0"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@types/node": "26.6.5",