@shop-on/theme-server 0.11.1 → 0.13.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 +2 -2
- package/dist/api-contract/src/areas.js +12 -3
- package/dist/api-contract/src/ids.js +7 -0
- package/dist/api-contract/src/image.js +32 -6
- package/dist/api-contract/src/storefront/index.d.ts +27 -0
- package/dist/api-contract/src/storefront/shop.js +2 -0
- package/dist/contract-kit/src/ids.js +5 -4
- package/dist/contract-kit/src/procedure.d.ts +3 -2
- package/dist/files.d.ts +4 -2
- package/dist/files.js +5 -3
- package/dist/liquid.d.ts +16 -4
- package/dist/marketing-cookies.d.ts +1 -1
- package/dist/metafields.d.ts +2 -11
- package/dist/product.js +2 -1
- package/dist/server-fn-csrf.d.ts +24 -0
- package/dist/server-fn-csrf.js +33 -0
- package/package.json +5 -4
package/dist/LICENSE.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#
|
|
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
|
|
6
|
+
Platform" is ShopOn, the commerce platform operated by Cody LLC.
|
|
7
7
|
|
|
8
8
|
## 1. Grant
|
|
9
9
|
|
|
@@ -19,13 +19,15 @@ const areaRef = z.object({
|
|
|
19
19
|
kind: z.enum(AREA_KINDS),
|
|
20
20
|
name: areaName
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
/** An area's outline's box in WGS 84 degrees: what a map frames to show the area. */
|
|
23
|
+
const areaBounds = z.object({
|
|
23
24
|
south: z.number(),
|
|
24
25
|
west: z.number(),
|
|
25
26
|
north: z.number(),
|
|
26
27
|
east: z.number()
|
|
27
28
|
});
|
|
28
|
-
|
|
29
|
+
/** One area of a level, as the address pickers read it (`areas.list`, merchant and storefront). */
|
|
30
|
+
const areaNode = areaRef.extend({
|
|
29
31
|
/** Whether the area has live children: whether the picker goes a level deeper. */
|
|
30
32
|
hasChildren: z.boolean(),
|
|
31
33
|
/**
|
|
@@ -46,4 +48,11 @@ areaRef.extend({
|
|
|
46
48
|
postalCodeRequired: z.boolean()
|
|
47
49
|
}).nullable()
|
|
48
50
|
});
|
|
49
|
-
|
|
51
|
+
/** An area of a level with its box, so choosing it moves an address form's map there (null: its outline is not known). */
|
|
52
|
+
const boundedArea = areaNode.extend({ bounds: areaBounds.nullable() });
|
|
53
|
+
boundedArea.extend({ children: z.array(boundedArea) });
|
|
54
|
+
z.object({
|
|
55
|
+
latitude: z.number().min(-90).max(90),
|
|
56
|
+
longitude: z.number().min(-180).max(180)
|
|
57
|
+
});
|
|
58
|
+
export { AREA_KINDS, areaBounds, areaName, areaNode, areaRef, boundedArea };
|
|
@@ -95,6 +95,13 @@ 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",
|
|
101
|
+
wallet_charge: "wallet charge",
|
|
102
|
+
wallet_movement: "wallet movement",
|
|
103
|
+
wallet_adjustment: "wallet adjustment",
|
|
104
|
+
wallet_funding: "wallet funding",
|
|
98
105
|
feedback: "feedback",
|
|
99
106
|
app: "app",
|
|
100
107
|
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
|
|
55
|
-
*
|
|
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
|
-
|
|
63
|
-
|
|
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 };
|
|
@@ -3066,6 +3066,7 @@ export declare const storefrontContract: {
|
|
|
3066
3066
|
primaryDomain: import("zod").ZodNullable<import("zod").ZodObject<{
|
|
3067
3067
|
hostname: import("zod").ZodString;
|
|
3068
3068
|
}, import("zod/v4/core").$strip>>;
|
|
3069
|
+
hostnames: import("zod").ZodArray<import("zod").ZodString>;
|
|
3069
3070
|
storefrontUrl: import("zod").ZodURL;
|
|
3070
3071
|
passwordProtection: import("zod").ZodObject<{
|
|
3071
3072
|
enabled: import("zod").ZodBoolean;
|
|
@@ -4699,6 +4700,31 @@ export declare const storefrontContract: {
|
|
|
4699
4700
|
gtin: import("zod").ZodNullable<import("zod").ZodString>;
|
|
4700
4701
|
requiresShipping: import("zod").ZodBoolean;
|
|
4701
4702
|
mediaFileIds: import("zod").ZodArray<import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`file_${string}`>, "id:file", "inout">>;
|
|
4703
|
+
metafields: import("zod").ZodArray<import("zod").ZodIntersection<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
4704
|
+
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">;
|
|
4705
|
+
list: import("zod").ZodBoolean;
|
|
4706
|
+
value: import("zod").ZodUnion<readonly [import("zod").ZodBoolean | import("zod").ZodISODate | import("zod").ZodISODateTime | import("zod").ZodInt | import("zod").ZodJSONSchema | import("zod").ZodObject<{
|
|
4707
|
+
type: import("zod").ZodLiteral<"root">;
|
|
4708
|
+
children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
|
|
4709
|
+
}, 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<{
|
|
4710
|
+
type: import("zod").ZodLiteral<"root">;
|
|
4711
|
+
children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
|
|
4712
|
+
}, 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">>]>;
|
|
4713
|
+
}, import("zod/v4/core").$strip>, ...import("zod").ZodObject<{
|
|
4714
|
+
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">;
|
|
4715
|
+
list: import("zod").ZodBoolean;
|
|
4716
|
+
value: import("zod").ZodUnion<readonly [import("zod").ZodBoolean | import("zod").ZodISODate | import("zod").ZodISODateTime | import("zod").ZodInt | import("zod").ZodJSONSchema | import("zod").ZodObject<{
|
|
4717
|
+
type: import("zod").ZodLiteral<"root">;
|
|
4718
|
+
children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
|
|
4719
|
+
}, 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<{
|
|
4720
|
+
type: import("zod").ZodLiteral<"root">;
|
|
4721
|
+
children: import("zod").ZodArray<import("zod").ZodType<RichTextNode, unknown, import("zod/v4/core").$ZodTypeInternals<RichTextNode, unknown>>>;
|
|
4722
|
+
}, 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">>]>;
|
|
4723
|
+
}, import("zod/v4/core").$strip>[]], "type">, import("zod").ZodObject<{
|
|
4724
|
+
definitionId: import("zod/v4/core").$ZodBranded<import("zod").ZodTemplateLiteral<`metafield_definition_${string}`>, "id:metafield_definition", "inout">;
|
|
4725
|
+
namespace: import("zod").ZodString;
|
|
4726
|
+
key: import("zod").ZodString;
|
|
4727
|
+
}, import("zod/v4/core").$strip>>>;
|
|
4702
4728
|
}, import("zod/v4/core").$strip>>;
|
|
4703
4729
|
metafields: import("zod").ZodObject<{
|
|
4704
4730
|
values: import("zod").ZodArray<import("zod").ZodIntersection<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
@@ -20560,6 +20586,7 @@ export declare const storefrontContract: {
|
|
|
20560
20586
|
emailLocked: import("zod").ZodBoolean;
|
|
20561
20587
|
expiresAt: import("zod").ZodISODateTime;
|
|
20562
20588
|
paysOnline: import("zod").ZodBoolean;
|
|
20589
|
+
verificationCode: import("zod").ZodString;
|
|
20563
20590
|
lines: import("zod").ZodArray<import("zod").ZodObject<{
|
|
20564
20591
|
productTitle: import("zod").ZodString;
|
|
20565
20592
|
variantTitle: import("zod").ZodNullable<import("zod").ZodString>;
|
|
@@ -22,6 +22,8 @@ const storefrontShop = z.object({
|
|
|
22
22
|
})),
|
|
23
23
|
/** The canonical host every other host redirects to: an active custom domain or platform alias; null: `{handle}.{storefront base}`. */
|
|
24
24
|
primaryDomain: z.object({ hostname: z.string() }).nullable(),
|
|
25
|
+
/** Every host the storefront is served on besides `{handle}.{storefront base}`: its active custom domains and unreleased platform aliases, the primary first, then oldest first. Public, as their DNS is: the buyer apps take a hand-off from any of them. */
|
|
26
|
+
hostnames: z.array(z.string()),
|
|
25
27
|
/** The shop's canonical storefront address (legacy `Shop#storefront_url`): its primary domain's, else `{handle}.{storefront base}`; `http` on a platform host of a localhost base, else `https`. */
|
|
26
28
|
storefrontUrl: z.url(),
|
|
27
29
|
/** The coming-soon gate, which the storefront keeps: while `enabled`, a buyer without an unlock of this `version` sees the password page. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
// ../contract-kit/src/ids.ts
|
|
3
|
-
|
|
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] =
|
|
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(
|
|
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", "billing-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", "register-pin", "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`);
|
|
70
|
-
*
|
|
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`);
|
|
75
|
-
*
|
|
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`
|
|
120
|
-
* list
|
|
121
|
-
*
|
|
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
|
package/dist/metafields.d.ts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createCsrfMiddleware } from "@tanstack/react-start";
|
|
2
|
+
/**
|
|
3
|
+
* The origin the buyer's browser is on. A storefront request reaches the
|
|
4
|
+
* theme through the shard's proxy, so its URL is the shard-internal one;
|
|
5
|
+
* the public host and scheme ride `x-forwarded-host` / `x-forwarded-proto`
|
|
6
|
+
* (the first value of each), as `account.ts` and `seo-context.ts` read them.
|
|
7
|
+
*/
|
|
8
|
+
export declare function publicOrigin(request: Request): string;
|
|
9
|
+
/**
|
|
10
|
+
* Server functions take same-origin calls only. A browser sending
|
|
11
|
+
* `Sec-Fetch-Site` is judged on it alone, so another shop's storefront on a
|
|
12
|
+
* sibling host (`same-site`, which carries the buyer's Lax cookies) is
|
|
13
|
+
* refused. One that doesn't (Safari < 16.4) is judged by `Origin` against
|
|
14
|
+
* the public origin: against the request URL, the default, every call would
|
|
15
|
+
* be refused behind the proxy. Page loads are not checked: a link from
|
|
16
|
+
* another site arrives `Sec-Fetch-Site: cross-site`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const storefrontCsrfOptions: Parameters<typeof createCsrfMiddleware>[0];
|
|
19
|
+
/**
|
|
20
|
+
* Request middleware: every theme registers it in `src/start.ts`. A
|
|
21
|
+
* `start.ts` with its own `requestMiddleware` drops the check Start applies
|
|
22
|
+
* without one, so it has to be listed.
|
|
23
|
+
*/
|
|
24
|
+
export declare const storefrontCsrfMiddleware: import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createCsrfMiddleware } from "@tanstack/react-start";
|
|
2
|
+
// src/server-fn-csrf.ts
|
|
3
|
+
/**
|
|
4
|
+
* The origin the buyer's browser is on. A storefront request reaches the
|
|
5
|
+
* theme through the shard's proxy, so its URL is the shard-internal one;
|
|
6
|
+
* the public host and scheme ride `x-forwarded-host` / `x-forwarded-proto`
|
|
7
|
+
* (the first value of each), as `account.ts` and `seo-context.ts` read them.
|
|
8
|
+
*/
|
|
9
|
+
function publicOrigin(request) {
|
|
10
|
+
const url = new URL(request.url);
|
|
11
|
+
const first = (name) => request.headers.get(name)?.split(",")[0]?.trim() || null;
|
|
12
|
+
return `${first("x-forwarded-proto") ?? url.protocol.replace(/:$/, "")}://${first("x-forwarded-host") ?? url.host}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Server functions take same-origin calls only. A browser sending
|
|
16
|
+
* `Sec-Fetch-Site` is judged on it alone, so another shop's storefront on a
|
|
17
|
+
* sibling host (`same-site`, which carries the buyer's Lax cookies) is
|
|
18
|
+
* refused. One that doesn't (Safari < 16.4) is judged by `Origin` against
|
|
19
|
+
* the public origin: against the request URL, the default, every call would
|
|
20
|
+
* be refused behind the proxy. Page loads are not checked: a link from
|
|
21
|
+
* another site arrives `Sec-Fetch-Site: cross-site`.
|
|
22
|
+
*/
|
|
23
|
+
const storefrontCsrfOptions = {
|
|
24
|
+
filter: (ctx) => ctx.handlerType === "serverFn",
|
|
25
|
+
origin: (origin, { request }) => origin === publicOrigin(request)
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Request middleware: every theme registers it in `src/start.ts`. A
|
|
29
|
+
* `start.ts` with its own `requestMiddleware` drops the check Start applies
|
|
30
|
+
* without one, so it has to be listed.
|
|
31
|
+
*/
|
|
32
|
+
const storefrontCsrfMiddleware = createCsrfMiddleware(storefrontCsrfOptions);
|
|
33
|
+
export { publicOrigin, storefrontCsrfMiddleware, storefrontCsrfOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shop-on/theme-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"license": "SEE LICENSE IN dist/LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"./search": "./dist/search.js",
|
|
50
50
|
"./seo-context": "./dist/seo-context.js",
|
|
51
51
|
"./seo-documents": "./dist/seo-documents.js",
|
|
52
|
+
"./server-fn-csrf": "./dist/server-fn-csrf.js",
|
|
52
53
|
"./shop": "./dist/shop.js",
|
|
53
54
|
"./shop-seo": "./dist/shop-seo.js",
|
|
54
55
|
"./store-availability": "./dist/store-availability.js",
|
|
@@ -59,9 +60,9 @@
|
|
|
59
60
|
"dependencies": {
|
|
60
61
|
"@orpc/client": "1.16.2",
|
|
61
62
|
"@orpc/contract": "1.16.2",
|
|
62
|
-
"@shop-on/customer-runtime": "0.
|
|
63
|
-
"@shop-on/theme-contract": "0.
|
|
64
|
-
"@shop-on/theme-runtime": "0.
|
|
63
|
+
"@shop-on/customer-runtime": "0.13.0",
|
|
64
|
+
"@shop-on/theme-contract": "0.13.0",
|
|
65
|
+
"@shop-on/theme-runtime": "0.13.0",
|
|
65
66
|
"liquidjs": "10.30.1",
|
|
66
67
|
"zod": "4.6.7"
|
|
67
68
|
},
|