@amboras-dev/storefront-core 2026.11.9-rc.1 → 2026.11.10

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
@@ -2,6 +2,73 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2026.11.10
6
+
7
+ ### Fixed
8
+
9
+ - `metafieldHtml` shows a `value` that is not a rich-text tree as escaped text, never as markup; a rich-text link to `/\host` (read by browsers as `//host`) keeps only its text.
10
+ - `getMetaobjectPage`: only a 404 or 410 is "not found". Any other 4xx (429, 401/403, 400) or a body that is not JSON throws `StoreMetaobjectPageUnavailableError`, so it never renders or caches a 404 for a live page.
11
+ - `amboras-check redirect-boundaries` also guards `app/pages` and `app/pages/[handle]` (metaobject entry web pages).
12
+
13
+ ### Added
14
+
15
+ - Blog comments on the storefront (Shopify's article comments; the blog's Comments setting: disabled, allowed pending
16
+ moderation, or allowed and automatically published):
17
+ - `lib/store-blog`: `getArticleComments(blog, article, { limit, offset })` reads
18
+ `GET /store/content/blogs/:blog/articles/:handle/comments` (published comments only, newest first as on Shopify, no emails, with the blog's
19
+ `commentable` setting; `null` for a missing post; strict like the other reads, an outage throws
20
+ `StoreBlogUnavailableError`). `postArticleComment(blog, article, { author, email, body, website })` posts one
21
+ and never throws: `posted` (`status` `published` or `pending`), `invalid` (a message per field),
22
+ `comments_disabled`, `rate_limited`, `not_found` or `unavailable`. `website` is the honeypot. Types
23
+ `ArticleComment`, `ArticleCommentsResponse`, `ArticleCommentInput`, `BlogCommentable`,
24
+ `PostArticleCommentResult`; `MAX_COMMENTS_PAGE`.
25
+ - `client/use-store-blog`: `usePostArticleComment(blog, article)` (the comment form's mutation).
26
+ - No new shims: the existing `lib/store-blog.ts` and `hooks/use-store-blog.ts` re-export everything.
27
+ - Metaobjects on the storefront (content module step 3, "shopper render path for metaobjects"):
28
+ - `lib/store-metaobjects`: `getMetaobjects(type, { limit, offset, revalidate })` and `getMetaobject(type, handle)`
29
+ read `GET /store/metaobjects/:type` (active entries of a definition with storefront access, storefront-visible
30
+ fields only), cached by Next (`revalidate` 60 by default); `metaobjectText(entry, key)` renders a value.
31
+ - `client/use-store-metaobjects`: `useMetaobjects(type)` and `useMetaobject(type, handle)`, the browser twins.
32
+ - `lib/store-metafields`: `getProductMetafields(productId, ['custom.designer'])` reads a product's metafields in the
33
+ order asked (`?metafields=` with `fields=id`); `findMetafield`, `metaobjectOf` and `metaobjectsOf` read the
34
+ entry a metaobject-reference metafield points at, which the store API now embeds (display name + visible
35
+ values; Medusa content step 3).
36
+ - All fail-soft: an older store API, an unknown type or a hidden definition gives an empty list / `null`.
37
+ - Needs new shims `hooks/use-store-metaobjects.ts`, `lib/store-metafields.ts` and `lib/store-metaobjects.ts` (added to
38
+ `core-manifest.json`).
39
+ - Metafield formats (content module step 4, Shopify's): `lib/store-metafields` adds `fileOf(metafield)` (a file
40
+ metafield's file: `url`, `alt`, `width`, `height`, `mime_type`, `size` — the store API now stores the
41
+ Files-library file, not a bare URL), `metafieldHtml(metafield)` (render a rich-text metafield: the store API's new
42
+ `html`, else the tree in `value`, else an older HTML value) and `richTextToHtml(tree)` (a metaobject's rich-text
43
+ field). Types `StoreFile` and `RichTextNode`; `StoreMetafield.html`.
44
+ - Metaobject web pages (content module step 6B, Shopify's "Publish entries as web pages"): `lib/store-metaobjects`
45
+ adds `getMetaobjectPage(type, handle)` (`/store/metaobjects/:type/:handle`: an active entry of a definition with
46
+ storefront access and web pages on, its title and description from the definition's page fields) and
47
+ `metaobjectPagePath(type, handle)` (`/pages/<type>/<handle>`). Strict: a missing entry is `null`, a failed read
48
+ throws `StoreMetaobjectPageUnavailableError` (never a 404 during an outage). Type `StoreMetaobjectPage`.
49
+ - The blog in core (content module step 5; "Blog = core Content, as on Shopify"), for stores whose blog pages are the
50
+ starter template's (`app/blogs/**` reading `@/lib/store-blog`). Same store routes and response shapes as the
51
+ `@amboras-dev/blog` plugin:
52
+ - `lib/store-blog`: `getBlogs()`, `getBlogArticles(blog, { limit, offset })`, `getAllArticles({ perBlog })` (every
53
+ post across blogs, newest first, each with its blog) and `getArticle(blog, article)`, cached by Next
54
+ (`revalidate` 60) and bounded by `STORE_FETCH_TIMEOUT_MS`; `blogPath` / `articlePath` build Shopify's
55
+ `/blogs/<blog>[/<article>]`. A missing blog or post (404/410) is `null`; any other failure throws
56
+ `StoreBlogUnavailableError` (never a 404 during an outage).
57
+ - Moved posts and blogs: the store API answers an old path with the post or blog it moved to (Medusa
58
+ `url_redirect`), carrying the current handles; `articleRedirectPath(blog, article, data)` and
59
+ `blogRedirectPath(blog, data)` return the path to answer 308 to (a renamed post, a post moved to another blog,
60
+ a renamed or archived blog, a URL in another case), or `null`.
61
+ - `client/use-store-blog`: `useBlogs()`, `useBlogArticles(blog, { page, perPage })` and
62
+ `useArticle(blog, article)`, the browser twins (fail-soft).
63
+ - New shims `hooks/use-store-blog.ts` and `lib/store-blog.ts` (in `core-manifest.json`). Inert unless imported:
64
+ no route, no side effect, and the paths never collide with the plugin's (`components/plugins/blog/*`,
65
+ `app/blogs/**`), so a store on the Blog plugin is unchanged by the raise. Named `store-blog`, not `blog`, so a
66
+ raise never overwrites a store's own `lib/blog.ts`.
67
+ - `amboras-check redirect-boundaries` guards `app/blogs` and `app/blogs/[blog]` when the store's blog pages are
68
+ core's (they import `@/lib/store-blog`). A store on the Blog plugin is not checked there, as before.
69
+
70
+ ## 2026.11.9
71
+
5
72
  ### Fixed
6
73
 
7
74
  - A server-side store-API read (GET/HEAD) that fails on a dead pooled connection (`ECONNRESET`, `EPIPE`, undici socket closed) is
@@ -23,6 +90,8 @@
23
90
  `sms_marketing_opt_in` / `whatsapp_marketing_opt_in` (`ChannelOptInSettings`: `enabled`, `countries` ISO-2 lower case with empty meaning
24
91
  every country, `disabled_reason?`) and `require_verified_account`. All optional, so an older Medusa's answer still type-checks; absent
25
92
  means off. `DEFAULT_CHECKOUT_SETTINGS` gains them, off.
93
+ - `intervalLabel` (`lib/subscription-cart`) labels the 45-day Subscribe & Save frequency Medusa now offers (`every_45_days`) as
94
+ "Every 45 days" on the cart badge and the account subscription list, instead of the raw-value fallback "Every_45_days".
26
95
 
27
96
  ## 2026.11.8
28
97
 
@@ -22,17 +22,34 @@
22
22
  * Usage: `node scripts/check-redirect-boundaries.mjs [storefrontRoot]`.
23
23
  * Exit 1 with the offending paths, exit 0 otherwise.
24
24
  */
25
- import { existsSync } from 'node:fs'
25
+ import { existsSync, readFileSync } from 'node:fs'
26
26
  import { join, resolve } from 'node:path'
27
27
  import { fileURLToPath } from 'node:url'
28
28
 
29
- export const GUARDED_DIRS = ['app/products', 'app/collections', 'app/[...slug]']
29
+ // app/pages: a metaobject entry's web page (app/pages/[handle]/[entry]) 308s to a merchant URL redirect when
30
+ // the entry is gone, so a loading.tsx in either parent would turn that into a 200 (content module).
31
+ export const GUARDED_DIRS = ['app/products', 'app/collections', 'app/[...slug]', 'app/pages', 'app/pages/[handle]']
32
+ // app/blogs: core's blog pages 308 a moved post or blog, so a loading.tsx in either parent would turn that into a
33
+ // 200. Guarded only when the blog pages are core's (they import `@/lib/store-blog`): a store on the Blog plugin
34
+ // owns its app/blogs files and is checked exactly as before.
35
+ export const CORE_BLOG_DIRS = ['app/blogs', 'app/blogs/[blog]']
36
+ const CORE_BLOG_MARKER = '@/lib/store-blog'
30
37
  const LOADING_FILES = ['loading.tsx', 'loading.ts', 'loading.jsx', 'loading.js']
31
38
 
39
+ function hasCoreBlogPages(root) {
40
+ return ['app/blogs/[blog]/page.tsx', 'app/blogs/[blog]/[article]/page.tsx'].some((file) => {
41
+ try {
42
+ return readFileSync(join(root, file), 'utf8').includes(CORE_BLOG_MARKER)
43
+ } catch {
44
+ return false
45
+ }
46
+ })
47
+ }
48
+
32
49
  /** Offending files (relative paths) under `root`. */
33
50
  export function findRedirectBoundaryViolations(root) {
34
51
  const found = []
35
- for (const dir of GUARDED_DIRS) {
52
+ for (const dir of hasCoreBlogPages(root) ? [...GUARDED_DIRS, ...CORE_BLOG_DIRS] : GUARDED_DIRS) {
36
53
  for (const file of LOADING_FILES) {
37
54
  if (existsSync(join(root, dir, file))) found.push(`${dir}/${file}`)
38
55
  }
@@ -67,5 +84,5 @@ if (isMain) {
67
84
  )
68
85
  process.exit(1)
69
86
  }
70
- console.log('[check-redirect-boundaries] OK: no loading boundary above a redirecting segment (products, collections, [...slug]).')
87
+ console.log('[check-redirect-boundaries] OK: no loading boundary above a redirecting segment (products, collections, [...slug], pages, core blog pages).')
71
88
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$comment": "Generated by scripts/build-manifest.mjs. Paths are relative to the storefront app root.",
3
3
  "package": "@amboras-dev/storefront-core",
4
- "version": "2026.11.9-rc.1",
4
+ "version": "2026.11.10",
5
5
  "shims": [
6
6
  {
7
7
  "path": "hooks/use-auth.ts",
@@ -178,6 +178,11 @@
178
178
  "import": "@amboras-dev/storefront-core/client/use-shipping-countries",
179
179
  "kind": "reexport"
180
180
  },
181
+ {
182
+ "path": "hooks/use-store-blog.ts",
183
+ "import": "@amboras-dev/storefront-core/client/use-store-blog",
184
+ "kind": "reexport"
185
+ },
181
186
  {
182
187
  "path": "hooks/use-store-config.ts",
183
188
  "import": "@amboras-dev/storefront-core/client/use-store-config",
@@ -188,6 +193,11 @@
188
193
  "import": "@amboras-dev/storefront-core/client/use-store-credit",
189
194
  "kind": "reexport"
190
195
  },
196
+ {
197
+ "path": "hooks/use-store-metaobjects.ts",
198
+ "import": "@amboras-dev/storefront-core/client/use-store-metaobjects",
199
+ "kind": "reexport"
200
+ },
191
201
  {
192
202
  "path": "hooks/use-store-search.ts",
193
203
  "import": "@amboras-dev/storefront-core/client/use-store-search",
@@ -478,11 +488,26 @@
478
488
  "import": "@amboras-dev/storefront-core/lib/store-api",
479
489
  "kind": "reexport"
480
490
  },
491
+ {
492
+ "path": "lib/store-blog.ts",
493
+ "import": "@amboras-dev/storefront-core/lib/store-blog",
494
+ "kind": "reexport"
495
+ },
481
496
  {
482
497
  "path": "lib/store-config.ts",
483
498
  "import": "@amboras-dev/storefront-core/lib/store-config",
484
499
  "kind": "reexport"
485
500
  },
501
+ {
502
+ "path": "lib/store-metafields.ts",
503
+ "import": "@amboras-dev/storefront-core/lib/store-metafields",
504
+ "kind": "reexport"
505
+ },
506
+ {
507
+ "path": "lib/store-metaobjects.ts",
508
+ "import": "@amboras-dev/storefront-core/lib/store-metaobjects",
509
+ "kind": "reexport"
510
+ },
486
511
  {
487
512
  "path": "lib/stripe/appearance.ts",
488
513
  "import": "@amboras-dev/storefront-core/lib/stripe/appearance",
@@ -0,0 +1,53 @@
1
+ import type { ArticleCommentInput, ArticleResponse, PostArticleCommentResult } from '../lib/store-blog.js';
2
+ /**
3
+ * The blog in the browser — the client twin of `lib/store-blog` (`getBlogs`,
4
+ * `getBlogArticles`, `getArticle`, for server components). For interactive
5
+ * islands (pagination, a "latest posts" strip). Same routes, same rules, and
6
+ * FAIL-SOFT: a missing blog or post, or any failure, gives an empty list /
7
+ * null, never an error state the page has to handle. `usePostArticleComment` posts a
8
+ * shopper's comment (the article page's comment form).
9
+ */
10
+ export declare const blogKeys: {
11
+ all: readonly ["blog"];
12
+ blogs: () => readonly ["blog", "blogs"];
13
+ articles: (blogHandle: string, page: number, perPage: number) => readonly ["blog", "articles", string, number, number];
14
+ article: (blogHandle: string, articleHandle: string) => readonly ["blog", "article", string, string];
15
+ };
16
+ /** The store's active blogs. */
17
+ export declare function useBlogs(options?: {
18
+ enabled?: boolean;
19
+ }): {
20
+ blogs: import("../lib/store-blog.js").Blog[];
21
+ count: number;
22
+ isLoading: boolean;
23
+ };
24
+ /** A page of a blog's published posts (`page` from 1). `blog` is null when there is no such blog. */
25
+ export declare function useBlogArticles(blogHandle: string, options?: {
26
+ page?: number;
27
+ perPage?: number;
28
+ enabled?: boolean;
29
+ }): {
30
+ blog: import("../lib/store-blog.js").Blog | null;
31
+ articles: import("../lib/store-blog.js").Article[];
32
+ count: number;
33
+ isLoading: boolean;
34
+ };
35
+ /** One published post; `data` is null when there is none. */
36
+ export declare function useArticle(blogHandle: string, articleHandle: string, options?: {
37
+ enabled?: boolean;
38
+ }): {
39
+ data: ArticleResponse | null;
40
+ isLoading: boolean;
41
+ };
42
+ /**
43
+ * Post a comment on a published post (the article page's comment form). `mutateAsync` resolves a
44
+ * `PostArticleCommentResult` and never rejects: `posted` (`status` `published` or `pending`), `invalid` (field
45
+ * messages), `comments_disabled`, `rate_limited`, `not_found` or `unavailable`. `result` is the last outcome.
46
+ */
47
+ export declare function usePostArticleComment(blogHandle: string, articleHandle: string): {
48
+ postComment: import("@tanstack/react-query").UseMutateAsyncFunction<PostArticleCommentResult, never, ArticleCommentInput, unknown>;
49
+ result: PostArticleCommentResult | null;
50
+ isPosting: boolean;
51
+ reset: () => void;
52
+ };
53
+ //# sourceMappingURL=use-store-blog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store-blog.d.ts","sourceRoot":"","sources":["../../src/hooks/use-store-blog.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAuC,wBAAwB,EAAE,MAAM,sBAAsB,CAAA;AAE/I;;;;;;;GAOG;AAEH,eAAO,MAAM,QAAQ;;;2BAGI,MAAM,QAAQ,MAAM,WAAW,MAAM;0BACtC,MAAM,iBAAiB,MAAM;CACpD,CAAA;AAYD,gCAAgC;AAChC,wBAAgB,QAAQ,CAAC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;;EAQ3D;AAED,qGAAqG;AACrG,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;EAYvH;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;EASxG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;;;;;EAU9E"}
@@ -0,0 +1,77 @@
1
+ 'use client';
2
+ import { useMutation, useQuery } from '@tanstack/react-query';
3
+ import { medusaBackendUrl, storeHeaders } from '../lib/store-api.js';
4
+ import { postArticleComment } from '../lib/store-blog.js';
5
+ /**
6
+ * The blog in the browser — the client twin of `lib/store-blog` (`getBlogs`,
7
+ * `getBlogArticles`, `getArticle`, for server components). For interactive
8
+ * islands (pagination, a "latest posts" strip). Same routes, same rules, and
9
+ * FAIL-SOFT: a missing blog or post, or any failure, gives an empty list /
10
+ * null, never an error state the page has to handle. `usePostArticleComment` posts a
11
+ * shopper's comment (the article page's comment form).
12
+ */
13
+ export const blogKeys = {
14
+ all: ['blog'],
15
+ blogs: () => [...blogKeys.all, 'blogs'],
16
+ articles: (blogHandle, page, perPage) => [...blogKeys.all, 'articles', blogHandle, page, perPage],
17
+ article: (blogHandle, articleHandle) => [...blogKeys.all, 'article', blogHandle, articleHandle],
18
+ };
19
+ async function getJson(path) {
20
+ try {
21
+ const res = await fetch(`${medusaBackendUrl()}${path}`, { headers: storeHeaders({ contentType: false }) });
22
+ if (!res.ok)
23
+ return null;
24
+ return (await res.json());
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ /** The store's active blogs. */
31
+ export function useBlogs(options = {}) {
32
+ const { data, isLoading } = useQuery({
33
+ queryKey: blogKeys.blogs(),
34
+ queryFn: () => getJson('/store/content/blogs'),
35
+ enabled: options.enabled ?? true,
36
+ staleTime: 60_000,
37
+ });
38
+ return { blogs: data?.blogs ?? [], count: data?.count ?? 0, isLoading };
39
+ }
40
+ /** A page of a blog's published posts (`page` from 1). `blog` is null when there is no such blog. */
41
+ export function useBlogArticles(blogHandle, options = {}) {
42
+ const { page = 1, perPage = 20, enabled = true } = options;
43
+ const { data, isLoading } = useQuery({
44
+ queryKey: blogKeys.articles(blogHandle, page, perPage),
45
+ queryFn: () => getJson(`/store/content/blogs/${encodeURIComponent(blogHandle)}/articles?limit=${perPage}&offset=${(Math.max(page, 1) - 1) * perPage}`),
46
+ enabled: enabled && !!blogHandle,
47
+ staleTime: 60_000,
48
+ });
49
+ return { blog: data?.blog ?? null, articles: data?.articles ?? [], count: data?.count ?? 0, isLoading };
50
+ }
51
+ /** One published post; `data` is null when there is none. */
52
+ export function useArticle(blogHandle, articleHandle, options = {}) {
53
+ const { data, isLoading } = useQuery({
54
+ queryKey: blogKeys.article(blogHandle, articleHandle),
55
+ queryFn: () => getJson(`/store/content/blogs/${encodeURIComponent(blogHandle)}/articles/${encodeURIComponent(articleHandle)}`),
56
+ enabled: (options.enabled ?? true) && !!blogHandle && !!articleHandle,
57
+ staleTime: 60_000,
58
+ });
59
+ return { data: data ?? null, isLoading };
60
+ }
61
+ /**
62
+ * Post a comment on a published post (the article page's comment form). `mutateAsync` resolves a
63
+ * `PostArticleCommentResult` and never rejects: `posted` (`status` `published` or `pending`), `invalid` (field
64
+ * messages), `comments_disabled`, `rate_limited`, `not_found` or `unavailable`. `result` is the last outcome.
65
+ */
66
+ export function usePostArticleComment(blogHandle, articleHandle) {
67
+ const mutation = useMutation({
68
+ mutationFn: (input) => postArticleComment(blogHandle, articleHandle, input),
69
+ });
70
+ return {
71
+ postComment: mutation.mutateAsync,
72
+ result: mutation.data ?? null,
73
+ isPosting: mutation.isPending,
74
+ reset: mutation.reset,
75
+ };
76
+ }
77
+ //# sourceMappingURL=use-store-blog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store-blog.js","sourceRoot":"","sources":["../../src/hooks/use-store-blog.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE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aAAa,CAAC;QACrD,OAAO,EAAE,GAAG,EAAE,CACZ,OAAO,CAAkB,wBAAwB,kBAAkB,CAAC,UAAU,CAAC,aAAa,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC;QAClI,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,aAAa;QACrE,SAAS,EAAE,MAAM;KAClB,CAAC,CAAA;IACF,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,SAAS,EAAE,CAAA;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAAkB,EAAE,aAAqB;IAC7E,MAAM,QAAQ,GAAG,WAAW,CAAuD;QACjF,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,aAAa,EAAE,KAAK,CAAC;KAC5E,CAAC,CAAA;IACF,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,MAAM,EAAE,QAAQ,CAAC,IAAI,IAAI,IAAI;QAC7B,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,KAAK,EAAE,QAAQ,CAAC,KAAK;KACtB,CAAA;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { StoreMetaobjectEntry } from '../lib/store-metaobjects.js';
2
+ /**
3
+ * Metaobjects in the browser — the client twin of `lib/store-metaobjects`
4
+ * (`getMetaobjects` / `getMetaobject`, for server components). Same route
5
+ * (`GET /store/metaobjects/:type`), same rules: active entries of a definition
6
+ * with storefront access, storefront-visible fields only, and FAIL-SOFT — a
7
+ * missing route, an unknown type or a hidden definition gives an empty list /
8
+ * null, never an error state the page has to handle.
9
+ */
10
+ export declare const metaobjectKeys: {
11
+ all: readonly ["metaobjects"];
12
+ list: (type: string, params: {
13
+ limit?: number;
14
+ offset?: number;
15
+ }) => readonly ["metaobjects", "list", string, {
16
+ limit?: number;
17
+ offset?: number;
18
+ }];
19
+ entry: (type: string, handle: string) => readonly ["metaobjects", "entry", string, string];
20
+ };
21
+ /** Active entries of one metaobject type, e.g. `useMetaobjects('faq')`. */
22
+ export declare function useMetaobjects(type: string, options?: {
23
+ limit?: number;
24
+ offset?: number;
25
+ enabled?: boolean;
26
+ }): {
27
+ entries: StoreMetaobjectEntry[];
28
+ count: number;
29
+ isLoading: boolean;
30
+ };
31
+ /** One entry by handle, e.g. `useMetaobject('designer', 'stella-mccartney')`; `entry` is null when there is none. */
32
+ export declare function useMetaobject(type: string, handle: string | null | undefined, options?: {
33
+ enabled?: boolean;
34
+ }): {
35
+ entry: StoreMetaobjectEntry | null;
36
+ isLoading: boolean;
37
+ };
38
+ //# sourceMappingURL=use-store-metaobjects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store-metaobjects.d.ts","sourceRoot":"","sources":["../../src/hooks/use-store-metaobjects.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAuB,MAAM,6BAA6B,CAAA;AAE5F;;;;;;;GAOG;AAEH,eAAO,MAAM,cAAc;;iBAEZ,MAAM,UAAU;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;gBAAzB,MAAM;iBAAW,MAAM;;kBAChD,MAAM,UAAU,MAAM;CACrC,CAAA;AAkBD,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;;EAShH;AAED,qHAAqH;AACrH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;EAYjH"}
@@ -0,0 +1,61 @@
1
+ 'use client';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { medusaBackendUrl, storeHeaders } from '../lib/store-api.js';
4
+ /**
5
+ * Metaobjects in the browser — the client twin of `lib/store-metaobjects`
6
+ * (`getMetaobjects` / `getMetaobject`, for server components). Same route
7
+ * (`GET /store/metaobjects/:type`), same rules: active entries of a definition
8
+ * with storefront access, storefront-visible fields only, and FAIL-SOFT — a
9
+ * missing route, an unknown type or a hidden definition gives an empty list /
10
+ * null, never an error state the page has to handle.
11
+ */
12
+ export const metaobjectKeys = {
13
+ all: ['metaobjects'],
14
+ list: (type, params) => [...metaobjectKeys.all, 'list', type, params],
15
+ entry: (type, handle) => [...metaobjectKeys.all, 'entry', type, handle],
16
+ };
17
+ async function fetchEntries(type, params) {
18
+ const query = new URLSearchParams();
19
+ for (const [key, value] of Object.entries(params))
20
+ if (value !== undefined && value !== '')
21
+ query.set(key, String(value));
22
+ const qs = query.toString();
23
+ try {
24
+ const res = await fetch(`${medusaBackendUrl()}/store/metaobjects/${encodeURIComponent(type)}${qs ? `?${qs}` : ''}`, {
25
+ headers: storeHeaders({ contentType: false }),
26
+ });
27
+ if (!res.ok)
28
+ return { entries: [], count: 0 };
29
+ const data = (await res.json());
30
+ return { entries: data.entries ?? [], count: data.count ?? 0 };
31
+ }
32
+ catch {
33
+ return { entries: [], count: 0 };
34
+ }
35
+ }
36
+ /** Active entries of one metaobject type, e.g. `useMetaobjects('faq')`. */
37
+ export function useMetaobjects(type, options = {}) {
38
+ const { limit, offset, enabled = true } = options;
39
+ const { data, isLoading } = useQuery({
40
+ queryKey: metaobjectKeys.list(type, { limit, offset }),
41
+ queryFn: () => fetchEntries(type, { limit, offset }),
42
+ enabled: enabled && !!type,
43
+ staleTime: 60_000,
44
+ });
45
+ return { entries: data?.entries ?? [], count: data?.count ?? 0, isLoading };
46
+ }
47
+ /** One entry by handle, e.g. `useMetaobject('designer', 'stella-mccartney')`; `entry` is null when there is none. */
48
+ export function useMetaobject(type, handle, options = {}) {
49
+ const { enabled = true } = options;
50
+ const { data, isLoading } = useQuery({
51
+ queryKey: metaobjectKeys.entry(type, handle ?? ''),
52
+ queryFn: async () => {
53
+ const list = await fetchEntries(type, { handle: handle ?? undefined });
54
+ return list.entries.find((entry) => entry.handle === handle) ?? null;
55
+ },
56
+ enabled: enabled && !!type && !!handle,
57
+ staleTime: 60_000,
58
+ });
59
+ return { entry: data ?? null, isLoading };
60
+ }
61
+ //# sourceMappingURL=use-store-metaobjects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-store-metaobjects.js","sourceRoot":"","sources":["../../src/hooks/use-store-metaobjects.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGpE;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,GAAG,EAAE,CAAC,aAAa,CAAU;IAC7B,IAAI,EAAE,CAAC,IAAY,EAAE,MAA2C,EAAE,EAAE,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAU;IAC3H,KAAK,EAAE,CAAC,IAAY,EAAE,MAAc,EAAE,EAAE,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAU;CACjG,CAAA;AAED,KAAK,UAAU,YAAY,CAAC,IAAY,EAAE,MAAmD;IAC3F,MAAM,KAAK,GAAG,IAAI,eAAe,EAAE,CAAA;IACnC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;YAAE,KAAK,CAAC,GAAG,CAAC,GAAG,EAA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