@shop-on/theme-server 0.11.1 → 0.12.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/LICENSE.md CHANGED
@@ -1,9 +1,9 @@
1
- # Shopon Theme Development License
1
+ # ShopOn Theme Development License
2
2
 
3
3
  Copyright (c) 2026 Cody LLC. All rights reserved except as granted below.
4
4
 
5
5
  "The Software" is this package, its source, and its documentation. "The
6
- Platform" is Shopon, the commerce platform operated by Cody LLC.
6
+ Platform" is ShopOn, the commerce platform operated by Cody LLC.
7
7
 
8
8
  ## 1. Grant
9
9
 
@@ -95,6 +95,9 @@ const LITE_ID_PREFIXES = {
95
95
  webhook_delivery: "webhook delivery",
96
96
  invoice: "billing invoice",
97
97
  plan_license: "plan license",
98
+ promo_batch: "promo code batch",
99
+ promo_code: "promo code",
100
+ promo_redemption: "promo code redemption",
98
101
  feedback: "feedback",
99
102
  app: "app",
100
103
  app_install: "app install"
@@ -50,16 +50,42 @@ const IMAGE_WIDTHS = [
50
50
  ];
51
51
  const IMAGE_MAX_DIMENSION = 5760;
52
52
  /**
53
+ * The aspects (height over width) a size with its own height is asked for;
54
+ * any other asked aspect is snapped to the nearest. A height that is no
55
+ * ladder width times one of these is read as `auto`, the image's own.
56
+ */
57
+ const IMAGE_ASPECTS = [
58
+ 1,
59
+ 3 / 4,
60
+ 4 / 3,
61
+ 2 / 3,
62
+ 3 / 2,
63
+ 9 / 16,
64
+ 16 / 9,
65
+ 1 / 2,
66
+ 2,
67
+ 4 / 5,
68
+ 5 / 4
69
+ ];
70
+ /** `width` times the aspect, as the height of a size (1 to 5,760). */
71
+ const aspectHeight = (width, aspect) => Math.min(Math.max(Math.round(width * aspect), 1), IMAGE_MAX_DIMENSION);
72
+ /**
53
73
  * The image's URL at `size`: the width times the scale snapped up the
54
- * ladder (at most 5,760), the height from the asked aspect or the image's
55
- * own, or `url` when the image cannot be resized.
74
+ * ladder (at most 5,760), the height from the image's own aspect or the
75
+ * asked one snapped to `IMAGE_ASPECTS`, or `url` when the image cannot be
76
+ * resized. A size is never larger than the original: past it, the original's
77
+ * pixels come back and the browser scales them.
56
78
  */
57
79
  function imageUrl(image, { width, height, fit = "cover", scale = 1 }) {
58
80
  if (image.sized === null) return image.url;
59
81
  const wanted = Math.min(Math.ceil(width * Math.min(Math.max(scale, 1), 3)), IMAGE_MAX_DIMENSION);
60
82
  const snapped = IMAGE_WIDTHS.find((step) => step >= wanted);
61
- const aspect = height !== void 0 && width > 0 ? height / width : image.height / image.width;
62
- const sizedHeight = Math.min(Math.max(Math.round(snapped * aspect), 1), IMAGE_MAX_DIMENSION);
63
- return image.sized.replace("{width}", String(snapped)).replace("{height}", String(sizedHeight)).replace("{fit}", fit);
83
+ const aspect = height !== void 0 && width > 0 ? nearestAspect(height / width) : image.height / image.width;
84
+ return image.sized.replace("{width}", String(snapped)).replace("{height}", String(aspectHeight(snapped, aspect))).replace("{fit}", fit);
85
+ }
86
+ /** The aspect in `IMAGE_ASPECTS` nearest `asked`, by ratio. */
87
+ function nearestAspect(asked) {
88
+ const distance = (aspect) => Math.abs(Math.log(aspect / asked));
89
+ return IMAGE_ASPECTS.reduce((best, aspect) => distance(aspect) < distance(best) ? aspect : best);
64
90
  }
65
- export { IMAGE_MAX_DIMENSION, IMAGE_WIDTHS, imageSchema, imageUrl };
91
+ export { IMAGE_ASPECTS, IMAGE_MAX_DIMENSION, IMAGE_WIDTHS, imageSchema, imageUrl };
@@ -4699,6 +4699,31 @@ export declare const storefrontContract: {
4699
4699
  gtin: import("zod").ZodNullable<import("zod").ZodString>;
4700
4700
  requiresShipping: import("zod").ZodBoolean;
4701
4701
  mediaFileIds: import("zod").ZodArray<import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`file_${string}`>, "id:file", "inout">>;
4702
+ metafields: import("zod").ZodArray<import("zod").ZodIntersection<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
4703
+ type: import("zod").ZodLiteral<"boolean" | "collection_reference" | "color" | "date" | "date_time" | "decimal" | "file_reference" | "integer" | "json" | "metaobject_reference" | "money" | "multi_line_text" | "page_reference" | "product_reference" | "rich_text" | "single_line_text" | "taxonomy_category_reference" | "taxonomy_value_reference" | "url" | "variant_reference">;
4704
+ list: import("zod").ZodBoolean;
4705
+ value: import("zod").ZodUnion<readonly [import("zod").ZodBoolean | import("zod").ZodISODate | import("zod").ZodISODateTime | import("zod").ZodInt | import("zod").ZodJSONSchema | import("zod").ZodObject<{
4706
+ type: import("zod").ZodLiteral<"root">;
4707
+ children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
4708
+ }, import("zod/v4/core").$strip> | import("zod").ZodString | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`file_${string}`>, "id:file", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`metaobject_${string}`>, "id:metaobject", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`page_${string}`>, "id:page", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`variant_${string}`>, "id:variant", "inout">, import("zod").ZodArray<import("zod").ZodBoolean | import("zod").ZodISODate | import("zod").ZodISODateTime | import("zod").ZodInt | import("zod").ZodJSONSchema | import("zod").ZodObject<{
4709
+ type: import("zod").ZodLiteral<"root">;
4710
+ children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
4711
+ }, import("zod/v4/core").$strip> | import("zod").ZodString | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`file_${string}`>, "id:file", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`metaobject_${string}`>, "id:metaobject", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`page_${string}`>, "id:page", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`variant_${string}`>, "id:variant", "inout">>]>;
4712
+ }, import("zod/v4/core").$strip>, ...import("zod").ZodObject<{
4713
+ type: import("zod").ZodLiteral<"boolean" | "collection_reference" | "color" | "date" | "date_time" | "decimal" | "file_reference" | "integer" | "json" | "metaobject_reference" | "money" | "multi_line_text" | "page_reference" | "product_reference" | "rich_text" | "single_line_text" | "taxonomy_category_reference" | "taxonomy_value_reference" | "url" | "variant_reference">;
4714
+ list: import("zod").ZodBoolean;
4715
+ value: import("zod").ZodUnion<readonly [import("zod").ZodBoolean | import("zod").ZodISODate | import("zod").ZodISODateTime | import("zod").ZodInt | import("zod").ZodJSONSchema | import("zod").ZodObject<{
4716
+ type: import("zod").ZodLiteral<"root">;
4717
+ children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
4718
+ }, import("zod/v4/core").$strip> | import("zod").ZodString | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`file_${string}`>, "id:file", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`metaobject_${string}`>, "id:metaobject", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`page_${string}`>, "id:page", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`variant_${string}`>, "id:variant", "inout">, import("zod").ZodArray<import("zod").ZodBoolean | import("zod").ZodISODate | import("zod").ZodISODateTime | import("zod").ZodInt | import("zod").ZodJSONSchema | import("zod").ZodObject<{
4719
+ type: import("zod").ZodLiteral<"root">;
4720
+ children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
4721
+ }, import("zod/v4/core").$strip> | import("zod").ZodString | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`file_${string}`>, "id:file", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`metaobject_${string}`>, "id:metaobject", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`page_${string}`>, "id:page", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout"> | import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`variant_${string}`>, "id:variant", "inout">>]>;
4722
+ }, import("zod/v4/core").$strip>[]], "type">, import("zod").ZodObject<{
4723
+ definitionId: import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`metafield_definition_${string}`>, "id:metafield_definition", "inout">;
4724
+ namespace: import("zod").ZodString;
4725
+ key: import("zod").ZodString;
4726
+ }, import("zod/v4/core").$strip>>>;
4702
4727
  }, import("zod/v4/core").$strip>>;
4703
4728
  metafields: import("zod").ZodObject<{
4704
4729
  values: import("zod").ZodArray<import("zod").ZodIntersection<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
@@ -20560,6 +20585,7 @@ export declare const storefrontContract: {
20560
20585
  emailLocked: import("zod").ZodBoolean;
20561
20586
  expiresAt: import("zod").ZodISODateTime;
20562
20587
  paysOnline: import("zod").ZodBoolean;
20588
+ verificationCode: import("zod").ZodString;
20563
20589
  lines: import("zod").ZodArray<import("zod").ZodObject<{
20564
20590
  productTitle: import("zod").ZodString;
20565
20591
  variantTitle: import("zod").ZodNullable<import("zod").ZodString>;
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  // ../contract-kit/src/ids.ts
3
- const ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
3
+ /** Crockford base32, lowercase: a TypeID suffix's digits. */
4
+ const CROCKFORD_ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
4
5
  const SUFFIX_PATTERN = /^[0-7][0-9a-hjkmnp-tv-z]{25}$/;
5
6
  const PREFIX_PATTERN = /^(?:[a-z](?:[a-z_]{0,61}[a-z])?)?$/;
6
7
  const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -13,7 +14,7 @@ function encodeTypeId(prefix, uuid) {
13
14
  let bits = BigInt(`0x${uuid.replaceAll("-", "")}`);
14
15
  const suffix = Array.from({ length: 26 });
15
16
  for (let i = 25; i >= 0; i--) {
16
- suffix[i] = ALPHABET[Number(bits & 31n)];
17
+ suffix[i] = CROCKFORD_ALPHABET[Number(bits & 31n)];
17
18
  bits >>= 5n;
18
19
  }
19
20
  return prefix === "" ? suffix.join("") : `${prefix}_${suffix.join("")}`;
@@ -25,7 +26,7 @@ function decodeTypeId(typeId) {
25
26
  const suffix = typeId.slice(split + 1);
26
27
  if (split === 0 || !PREFIX_PATTERN.test(prefix) || !SUFFIX_PATTERN.test(suffix)) throw new TypeError(`Invalid TypeID: ${typeId}`);
27
28
  let bits = 0n;
28
- for (const char of suffix) bits = bits << 5n | BigInt(ALPHABET.indexOf(char));
29
+ for (const char of suffix) bits = bits << 5n | BigInt(CROCKFORD_ALPHABET.indexOf(char));
29
30
  return {
30
31
  prefix,
31
32
  uuid: formatUuid(bits.toString(16).padStart(32, "0"))
@@ -115,4 +116,4 @@ const { idSchema, toId, toUuid, newId } = defineIds(ID_PREFIXES);
115
116
  function formatUuid(hex) {
116
117
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
117
118
  }
118
- export { ID_PREFIXES, decodeTypeId, defineIds, encodeTypeId, newUuid };
119
+ export { CROCKFORD_ALPHABET, ID_PREFIXES, decodeTypeId, defineIds, encodeTypeId, newUuid };
@@ -36,9 +36,10 @@ export type ProcedureAccess<TPermission extends string = string> = {
36
36
  * (server-kit `./http`, `RATE_LIMITS`); a procedure only names its class.
37
37
  * `mount` is the edge's own, never a procedure's: every request to a mount
38
38
  * counts against it before anything else runs. `mcp-write` is the MCP
39
- * mount's own too: each call of a writing tool, per connection.
39
+ * mount's own too: each call of a writing tool, per connection;
40
+ * `app-token-exchange` lite's `/oauth/app_token` mount's, per address.
40
41
  */
41
- export declare const RATE_LIMIT_CLASSES: readonly ["sign-in", "code-send", "code-redeem", "link-write", "provider-callback", "courier-webhook", "provider-push", "promo-guess", "gift-card-guess", "register-gift-card-guess", "gift-card-reveal", "theme-submission", "public-read", "read", "write", "storefront", "storefront-unlock", "driver-sign-in", "storefront-review", "storefront-contact", "storefront-newsletter", "storefront-sitemap", "storefront-analytics", "storefront-cart", "buyer-write", "buyer-email-change", "google-nonce", "expensive", "checkpoint", "editor-presence", "webhook-create", "webhook-update", "webhook-delete", "webhook-test", "webhook-redeliver", "webhook-rotate", "editor-bell", "feedback", "sticker", "mcp-write", "mount"];
42
+ export declare const RATE_LIMIT_CLASSES: readonly ["sign-in", "app-token-exchange", "code-send", "code-redeem", "link-write", "provider-callback", "courier-webhook", "provider-push", "promo-guess", "gift-card-guess", "register-gift-card-guess", "gift-card-reveal", "theme-submission", "public-read", "image-size", "read", "write", "storefront", "storefront-unlock", "driver-sign-in", "storefront-review", "storefront-contact", "storefront-newsletter", "storefront-sitemap", "storefront-analytics", "storefront-cart", "buyer-write", "buyer-email-change", "google-nonce", "expensive", "checkpoint", "editor-presence", "webhook-create", "webhook-update", "webhook-delete", "webhook-test", "webhook-redeliver", "webhook-rotate", "editor-bell", "feedback", "sticker", "mcp-write", "mount"];
42
43
  export type RateLimitClass = (typeof RATE_LIMIT_CLASSES)[number];
43
44
  /**
44
45
  * A procedure's class, or for a class counted per identifier (`sign-in`,
package/dist/files.d.ts CHANGED
@@ -66,8 +66,10 @@ export type StorefrontImage = {
66
66
  /** `image` as every renderer draws it: `url` at `baseWidth`, a srcset of its
67
67
  * 1×, 1.5×, 2× and 3× rungs, and an 80px thumb. A rung past the original's
68
68
  * width is left out and every size is `scale-down`, so an image is never
69
- * enlarged (legacy's `maxWidth`); an image that cannot be resized is its
70
- * original, with no srcset. */
69
+ * enlarged (legacy's `maxWidth`); a URL asks for at most the original's
70
+ * width, so every one is among the sizes the api makes as the image is
71
+ * stored (api-contract's `storefrontSizes`). An image that cannot be resized
72
+ * is its original, with no srcset. */
71
73
  export declare function imageFileInfo(image: StorefrontImage, baseWidth: number): ImageFileInfo;
72
74
  /** A video as the storefront procedures answer it (`@shop-on/api-contract/video`):
73
75
  * only once it is ready, so its MP4, HLS bundle and poster are all there. */
package/dist/files.js CHANGED
@@ -71,11 +71,13 @@ function toFileInfo(node, extra = {}) {
71
71
  /** `image` as every renderer draws it: `url` at `baseWidth`, a srcset of its
72
72
  * 1×, 1.5×, 2× and 3× rungs, and an 80px thumb. A rung past the original's
73
73
  * width is left out and every size is `scale-down`, so an image is never
74
- * enlarged (legacy's `maxWidth`); an image that cannot be resized is its
75
- * original, with no srcset. */
74
+ * enlarged (legacy's `maxWidth`); a URL asks for at most the original's
75
+ * width, so every one is among the sizes the api makes as the image is
76
+ * stored (api-contract's `storefrontSizes`). An image that cannot be resized
77
+ * is its original, with no srcset. */
76
78
  function imageFileInfo(image, baseWidth) {
77
79
  const at = (width) => imageUrl(image, {
78
- width,
80
+ width: Math.min(width, image.width),
79
81
  fit: "scale-down"
80
82
  });
81
83
  const rungs = [
package/dist/liquid.d.ts CHANGED
@@ -116,9 +116,9 @@ export type CustomProduct = Omit<LiquidProduct, "featured_image" | "images"> & {
116
116
  images: CustomImage[];
117
117
  /** Locale-free; a template pipes it through `link_url`. */
118
118
  url: string;
119
- /** `namespace → key → { type, value, values, html }`; `values` is the parsed
120
- * list for a `LIST_*` type, else []; `html` the HTML of a `RICH_TEXT` value,
121
- * else null. `{}` but on the route product. */
119
+ /** `namespace → key → { type, value, values, html }`; `values` the items of a
120
+ * list value, else []; `html` the HTML of a `rich_text` value, else null.
121
+ * `{}` but on the route product. */
122
122
  metafields: Record<string, Record<string, CustomMetafield>>;
123
123
  };
124
124
  /** `metafields: true` for the route product only: a picker-resolved product's
@@ -172,12 +172,24 @@ export declare function customEntry(entry: MetaobjectData): CustomEntry;
172
172
  /** The drops a custom section's Liquid can reach (the validator's
173
173
  * `CUSTOM_LIQUID_ROOTS`). `settings` holds the declared settings' values and
174
174
  * the resolved pickers, built by `renderCustomSections` in
175
- * @shop-on/theme-loader/custom-sections. */
175
+ * @shop-on/theme-loader/custom-sections. `section` is there only for a
176
+ * definition that declares item kinds, as the validator roots it. */
176
177
  export interface CustomLiquidContext {
177
178
  settings: Record<string, unknown>;
178
179
  product: CustomProduct | null;
179
180
  collection: CustomCollection | null;
180
181
  shop: LiquidShop;
182
+ section?: {
183
+ blocks: CustomItem[];
184
+ };
185
+ }
186
+ /** One item of a custom section, as its template reads it: `type` is the
187
+ * item's kind, `blocks` its own items (none below a child kind). */
188
+ export interface CustomItem {
189
+ id: string;
190
+ type: string;
191
+ settings: Record<string, unknown>;
192
+ blocks: CustomItem[];
181
193
  }
182
194
  /** Render a custom section's Liquid. NEVER throws: a parse or render failure,
183
195
  * the render cap included, comes back as `{ html: "", error }`, so partial
@@ -2,7 +2,7 @@
2
2
  export interface MarketingCookies {
3
3
  fbp?: string;
4
4
  fbc?: string;
5
- /** Every allowlisted cookie as `name=value; …`, for Rails to parse. */
5
+ /** Every allowlisted cookie as `name=value; …`, for the api to parse. */
6
6
  cookies?: string;
7
7
  }
8
8
  /**
@@ -1,11 +1,2 @@
1
- /** A value as JSON holds it: what a metafield's value is on the wire, and
2
- * what a server function's answer may carry. */
3
- export type JsonValue = string | number | boolean | null | JsonValue[] | {
4
- [key: string]: JsonValue;
5
- };
6
- /** A resource's storefront metafields keyed `"namespace.key"`, each its
7
- * value type's name and its value (theme-contract's `CustomDataValue`). */
8
- export type MetafieldMap = Record<string, {
9
- type: string;
10
- value: JsonValue;
11
- }>;
1
+ import { JsonValue, MetafieldMap } from "@shop-on/theme-runtime/template-types";
2
+ export type { JsonValue, MetafieldMap };
package/dist/product.js CHANGED
@@ -24,7 +24,8 @@ function toPage(p) {
24
24
  selectedOptions: v.optionValueIds.flatMap((id) => selections.get(id) ?? []),
25
25
  priceV2: toMoney(v.price),
26
26
  compareAtV2: compareAt(v.compareAtPrice),
27
- featuredMedia: v.mediaFileIds[0] ? { id: v.mediaFileIds[0] } : null
27
+ featuredMedia: v.mediaFileIds[0] ? { id: v.mediaFileIds[0] } : null,
28
+ metafields: customDataMap({ values: v.metafields })
28
29
  }));
29
30
  const defaultVariant = variants.find((v) => v.id === p.defaultVariant.id) ?? variants[0];
30
31
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shop-on/theme-server",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "license": "SEE LICENSE IN dist/LICENSE.md",
5
5
  "files": [
6
6
  "dist"
@@ -59,9 +59,9 @@
59
59
  "dependencies": {
60
60
  "@orpc/client": "1.16.2",
61
61
  "@orpc/contract": "1.16.2",
62
- "@shop-on/customer-runtime": "0.11.1",
63
- "@shop-on/theme-contract": "0.11.1",
64
- "@shop-on/theme-runtime": "0.11.1",
62
+ "@shop-on/customer-runtime": "0.12.0",
63
+ "@shop-on/theme-contract": "0.12.0",
64
+ "@shop-on/theme-runtime": "0.12.0",
65
65
  "liquidjs": "10.30.1",
66
66
  "zod": "4.6.7"
67
67
  },