@wocart/theme 2.2.0 → 3.0.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.
@@ -1,23 +1,20 @@
1
1
  /**
2
2
  * An Astro image service for Wocart storefronts: every `<Image>` and
3
- * `getImage()` of a media-domain image is resized by Cloudflare Image Resizing
4
- * on the media domain itself (`https://<media>/cdn-cgi/image/…/<path>`).
3
+ * `getImage()` of a store image is resized by the store's own media delivery
4
+ * — ImageKit or Cloudflare — so a storefront on any host gets the same URLs
5
+ * and no second image bill. Any other image (another host, a file imported
6
+ * into the theme) is served as it is, and so is every image of a `direct`
7
+ * delivery, which does not resize.
5
8
  *
6
- * The media domain is always a Cloudflare zone, wherever the storefront runs,
7
- * so a storefront on Cloudflare and one on Vercel get the same URLs, the same
8
- * edge cache and no second image bill. Any other image — another host, a file
9
- * imported into the theme — is served as it is. Without a media domain (local
10
- * development, a store without one) every image passes through unchanged.
11
- *
12
- * The domain is read per call, not at build: one theme build serves every
13
- * store. Bind it once, in the theme, to wherever the store's media domain
14
- * lives:
9
+ * The delivery is the store config's `media`, read per image, not at build:
10
+ * one theme build serves every store. Bind it once, in the theme, to where
11
+ * the theme keeps the store's config:
15
12
  *
16
13
  * ```ts
17
14
  * // src/image-service.ts
18
- * import { MEDIA_DOMAIN } from "astro:env/server";
19
15
  * import { mediaImageService } from "@wocart/theme/image-service";
20
- * export default mediaImageService(() => MEDIA_DOMAIN);
16
+ * import { storeMedia } from "./store-media";
17
+ * export default mediaImageService(storeMedia);
21
18
  * ```
22
19
  *
23
20
  * ```js
@@ -27,13 +24,13 @@
27
24
  * ```
28
25
  */
29
26
  import type { ExternalImageService, ImageTransform } from "astro";
30
- import { type MediaImageParams } from "@wocart/storefront";
31
- /** The Cloudflare resizing options an Astro image transform asks for. */
27
+ import { type MediaDelivery, type MediaImageParams } from "@wocart/storefront";
28
+ /** The resizing options an Astro image transform asks for. */
32
29
  export declare function mediaImageParams(options: ImageTransform): MediaImageParams;
33
30
  /**
34
- * The image service, bound to the store's media domain.
31
+ * The image service, bound to the store's media delivery.
35
32
  *
36
- * @param mediaDomain - Read on every image (e.g. `() => MEDIA_DOMAIN`): the
37
- * store's media domain, or `undefined` to pass every image through.
33
+ * @param delivery - Read on every image (e.g. `() => config.media`): the
34
+ * store's `MediaDelivery`, or `null` / `undefined` to pass every image through.
38
35
  */
39
- export declare function mediaImageService(mediaDomain: () => string | undefined): ExternalImageService;
36
+ export declare function mediaImageService(delivery: () => MediaDelivery | null | undefined | Promise<MediaDelivery | null | undefined>): ExternalImageService;
@@ -1,23 +1,20 @@
1
1
  /**
2
2
  * An Astro image service for Wocart storefronts: every `<Image>` and
3
- * `getImage()` of a media-domain image is resized by Cloudflare Image Resizing
4
- * on the media domain itself (`https://<media>/cdn-cgi/image/…/<path>`).
3
+ * `getImage()` of a store image is resized by the store's own media delivery
4
+ * — ImageKit or Cloudflare — so a storefront on any host gets the same URLs
5
+ * and no second image bill. Any other image (another host, a file imported
6
+ * into the theme) is served as it is, and so is every image of a `direct`
7
+ * delivery, which does not resize.
5
8
  *
6
- * The media domain is always a Cloudflare zone, wherever the storefront runs,
7
- * so a storefront on Cloudflare and one on Vercel get the same URLs, the same
8
- * edge cache and no second image bill. Any other image — another host, a file
9
- * imported into the theme — is served as it is. Without a media domain (local
10
- * development, a store without one) every image passes through unchanged.
11
- *
12
- * The domain is read per call, not at build: one theme build serves every
13
- * store. Bind it once, in the theme, to wherever the store's media domain
14
- * lives:
9
+ * The delivery is the store config's `media`, read per image, not at build:
10
+ * one theme build serves every store. Bind it once, in the theme, to where
11
+ * the theme keeps the store's config:
15
12
  *
16
13
  * ```ts
17
14
  * // src/image-service.ts
18
- * import { MEDIA_DOMAIN } from "astro:env/server";
19
15
  * import { mediaImageService } from "@wocart/theme/image-service";
20
- * export default mediaImageService(() => MEDIA_DOMAIN);
16
+ * import { storeMedia } from "./store-media";
17
+ * export default mediaImageService(storeMedia);
21
18
  * ```
22
19
  *
23
20
  * ```js
@@ -28,8 +25,8 @@
28
25
  */
29
26
  import { baseService } from "astro/assets";
30
27
  import { mediaImageUrl } from "@wocart/storefront";
31
- /** Astro's `fit` (CSS object-fit) in Cloudflare's words; a value Cloudflare also knows passes as it is. */
32
- const CLOUDFLARE_FIT = {
28
+ /** Astro's `fit` (CSS object-fit) in the words `mediaImageUrl` takes; a value it also knows passes as it is. */
29
+ const FIT = {
33
30
  cover: "cover",
34
31
  contain: "contain",
35
32
  fill: "squeeze",
@@ -38,7 +35,7 @@ const CLOUDFLARE_FIT = {
38
35
  pad: "pad",
39
36
  squeeze: "squeeze",
40
37
  };
41
- /** The Cloudflare resizing options an Astro image transform asks for. */
38
+ /** The resizing options an Astro image transform asks for. */
42
39
  export function mediaImageParams(options) {
43
40
  const params = {};
44
41
  if (options.width)
@@ -49,25 +46,25 @@ export function mediaImageParams(options) {
49
46
  params.format = options.format;
50
47
  if (typeof options.quality === "number")
51
48
  params.quality = options.quality;
52
- const fit = options.fit ? CLOUDFLARE_FIT[options.fit] : undefined;
49
+ const fit = options.fit ? FIT[options.fit] : undefined;
53
50
  if (fit)
54
51
  params.fit = fit;
55
52
  return params;
56
53
  }
57
54
  /**
58
- * The image service, bound to the store's media domain.
55
+ * The image service, bound to the store's media delivery.
59
56
  *
60
- * @param mediaDomain - Read on every image (e.g. `() => MEDIA_DOMAIN`): the
61
- * store's media domain, or `undefined` to pass every image through.
57
+ * @param delivery - Read on every image (e.g. `() => config.media`): the
58
+ * store's `MediaDelivery`, or `null` / `undefined` to pass every image through.
62
59
  */
63
- export function mediaImageService(mediaDomain) {
60
+ export function mediaImageService(delivery) {
64
61
  return {
65
62
  ...baseService,
66
- getURL(options) {
63
+ async getURL(options) {
67
64
  const src = options.src;
68
65
  if (typeof src !== "string")
69
66
  return src.src;
70
- return mediaImageUrl(src, mediaImageParams(options), mediaDomain()) ?? src;
67
+ return mediaImageUrl(src, mediaImageParams(options), await delivery()) ?? src;
71
68
  },
72
69
  };
73
70
  }
@@ -21,8 +21,8 @@ export declare const THEME_MANIFEST_PATH = "/wocart-theme.json";
21
21
  /** Derive the data-only manifest from a theme. `component` and `load` are dropped. */
22
22
  export declare function themeManifest(theme: ThemeDefinition): ThemeManifest;
23
23
  /**
24
- * The manifest's structural shape. Unknown keys are stripped (the forward-compat
25
- * tradeoff documented in the README); absent `fields`/`slots` normalize to `[]`.
24
+ * The manifest's structural shape. Unknown keys are stripped, so a manifest
25
+ * from a newer theme still reads; absent `fields`/`slots` normalize to `[]`.
26
26
  * Rules that span fields are not here — `validateThemeManifest` applies them.
27
27
  */
28
28
  export declare const ThemeManifestSchema: z.ZodObject<{
package/dist/manifest.js CHANGED
@@ -214,8 +214,8 @@ const ComponentSpecSchema = z.object({
214
214
  .default([]),
215
215
  });
216
216
  /**
217
- * The manifest's structural shape. Unknown keys are stripped (the forward-compat
218
- * tradeoff documented in the README); absent `fields`/`slots` normalize to `[]`.
217
+ * The manifest's structural shape. Unknown keys are stripped, so a manifest
218
+ * from a newer theme still reads; absent `fields`/`slots` normalize to `[]`.
219
219
  * Rules that span fields are not here — `validateThemeManifest` applies them.
220
220
  */
221
221
  export const ThemeManifestSchema = z.object({
@@ -17,7 +17,7 @@ export declare const TYPE_KEY_PATTERN: RegExp;
17
17
  */
18
18
  export declare const SURFACE_KEY_PATTERN: RegExp;
19
19
  /** The platform page types a surface can render (`SurfacePageType`), mirrored from the storefront's page types. */
20
- export declare const PAGE_TYPES: readonly ["home", "catalog", "category", "collection", "product", "page", "landing", "checkout", "thankYou"];
20
+ export declare const PAGE_TYPES: readonly ["home", "catalog", "category", "collection", "product", "page", "landing", "checkout", "thankYou", "trackOrder"];
21
21
  /** A `color` field's value: a hex color, `#rgb` or `#rrggbb`. */
22
22
  export declare const COLOR_PATTERN: RegExp;
23
23
  /**
package/dist/patterns.js CHANGED
@@ -27,6 +27,7 @@ export const PAGE_TYPES = [
27
27
  "landing",
28
28
  "checkout",
29
29
  "thankYou",
30
+ "trackOrder",
30
31
  ];
31
32
  /** A `color` field's value: a hex color, `#rgb` or `#rrggbb`. */
32
33
  export const COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
package/dist/types.d.ts CHANGED
@@ -749,7 +749,7 @@ export interface AreaSpec {
749
749
  * The storefront's page types — what a URL means, with the paths the platform
750
750
  * owns. The same names as `StorefrontPageType` in `@wocart/storefront`.
751
751
  */
752
- export type SurfacePageType = "home" | "catalog" | "category" | "collection" | "product" | "page" | "landing" | "checkout" | "thankYou";
752
+ export type SurfacePageType = "home" | "catalog" | "category" | "collection" | "product" | "page" | "landing" | "checkout" | "thankYou" | "trackOrder";
753
753
  /**
754
754
  * One component as data: a `ComponentDefinition` minus its runtime-only
755
755
  * implementation. `component` (the live component reference) and `load` (the
package/dist/version.d.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * reads. Always equal to `package.json`'s version; the package check refuses
5
5
  * a release where they differ.
6
6
  */
7
- export declare const THEME_SDK_VERSION = "2.2.0";
7
+ export declare const THEME_SDK_VERSION = "3.0.0";
package/dist/version.js CHANGED
@@ -4,4 +4,4 @@
4
4
  * reads. Always equal to `package.json`'s version; the package check refuses
5
5
  * a release where they differ.
6
6
  */
7
- export const THEME_SDK_VERSION = "2.2.0";
7
+ export const THEME_SDK_VERSION = "3.0.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocart/theme",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "The Wocart theme contract: code-owned component definitions, JSON page documents, validation and resolution, and a reference Astro renderer.",
5
5
  "keywords": [
6
6
  "wocart",
@@ -82,7 +82,7 @@
82
82
  "zod": "^4.4.3"
83
83
  },
84
84
  "peerDependencies": {
85
- "@wocart/storefront": "^1.20.0",
85
+ "@wocart/storefront": "^2.0.0",
86
86
  "astro": "^7.0.0"
87
87
  },
88
88
  "peerDependenciesMeta": {
@@ -92,7 +92,7 @@
92
92
  },
93
93
  "devDependencies": {
94
94
  "@types/node": "^26.2.0",
95
- "@wocart/storefront": "^1.0.0",
95
+ "@wocart/storefront": "^2.0.0",
96
96
  "astro": "^7.3.2",
97
97
  "fast-check": "^4.6.0",
98
98
  "happy-dom": "^20.11.6",