@shopify/hydrogen 2023.4.3 → 2023.4.4

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.
@@ -114,23 +114,23 @@ type Storefront<TI18n extends I18nBase = I18nBase> = {
114
114
  mutate: <OverrideReturnType = any, RawGqlString extends string = string>(mutation: RawGqlString, ...options: RawGqlString extends keyof StorefrontMutations ? IsOptionalVariables<StorefrontMutations[RawGqlString]> extends true ? [StorefrontMutateSecondParam<RawGqlString>?] : [StorefrontMutateSecondParam<RawGqlString>] : [StorefrontMutateSecondParam?]) => Promise<RawGqlString extends keyof StorefrontMutations ? StorefrontMutations[RawGqlString]['return'] : OverrideReturnType>;
115
115
  /** The cache instance passed in from the `createStorefrontClient` argument. */
116
116
  cache?: Cache;
117
- /** Re-export of [`CacheNone`](/docs/api/hydrogen/utilities/cachenone). */
117
+ /** Re-export of [`CacheNone`](/docs/api/hydrogen/2023-04/utilities/cachenone). */
118
118
  CacheNone: typeof CacheNone;
119
- /** Re-export of [`CacheLong`](/docs/api/hydrogen/utilities/cachelong). */
119
+ /** Re-export of [`CacheLong`](/docs/api/hydrogen/2023-04/utilities/cachelong). */
120
120
  CacheLong: typeof CacheLong;
121
- /** Re-export of [`CacheShort`](/docs/api/hydrogen/utilities/cacheshort). */
121
+ /** Re-export of [`CacheShort`](/docs/api/hydrogen/2023-04/utilities/cacheshort). */
122
122
  CacheShort: typeof CacheShort;
123
- /** Re-export of [`CacheCustom`](/docs/api/hydrogen/utilities/cachecustom). */
123
+ /** Re-export of [`CacheCustom`](/docs/api/hydrogen/2023-04/utilities/cachecustom). */
124
124
  CacheCustom: typeof CacheCustom;
125
- /** Re-export of [`generateCacheControlHeader`](/docs/api/hydrogen/utilities/generatecachecontrolheader). */
125
+ /** Re-export of [`generateCacheControlHeader`](/docs/api/hydrogen/2023-04/utilities/generatecachecontrolheader). */
126
126
  generateCacheControlHeader: typeof generateCacheControlHeader;
127
- /** Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint. See [`getPublicTokenHeaders` in Hydrogen React](/docs/api/hydrogen-react/utilities/createstorefrontclient#:~:text=%27graphql%27.-,getPublicTokenHeaders,-(props%3F%3A) for more details. */
127
+ /** Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint. See [`getPublicTokenHeaders` in Hydrogen React](/docs/api/hydrogen-react/2023-04/utilities/createstorefrontclient#:~:text=%27graphql%27.-,getPublicTokenHeaders,-(props%3F%3A) for more details. */
128
128
  getPublicTokenHeaders: ReturnType<typeof createStorefrontClient$1>['getPublicTokenHeaders'];
129
- /** Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint for API calls made from a server. See [`getPrivateTokenHeaders` in Hydrogen React](/docs/api/hydrogen-react/utilities/createstorefrontclient#:~:text=storefrontApiVersion-,getPrivateTokenHeaders,-(props%3F%3A) for more details.*/
129
+ /** Returns an object that contains headers that are needed for each query to Storefront API GraphQL endpoint for API calls made from a server. See [`getPrivateTokenHeaders` in Hydrogen React](/docs/api/hydrogen-react/2023-04/utilities/createstorefrontclient#:~:text=storefrontApiVersion-,getPrivateTokenHeaders,-(props%3F%3A) for more details.*/
130
130
  getPrivateTokenHeaders: ReturnType<typeof createStorefrontClient$1>['getPrivateTokenHeaders'];
131
- /** Creates the fully-qualified URL to your myshopify.com domain. See [`getShopifyDomain` in Hydrogen React](/docs/api/hydrogen-react/utilities/createstorefrontclient#:~:text=StorefrontClientReturn-,getShopifyDomain,-(props%3F%3A) for more details. */
131
+ /** Creates the fully-qualified URL to your myshopify.com domain. See [`getShopifyDomain` in Hydrogen React](/docs/api/hydrogen-react/2023-04/utilities/createstorefrontclient#:~:text=StorefrontClientReturn-,getShopifyDomain,-(props%3F%3A) for more details. */
132
132
  getShopifyDomain: ReturnType<typeof createStorefrontClient$1>['getShopifyDomain'];
133
- /** Creates the fully-qualified URL to your store's GraphQL endpoint. See [`getStorefrontApiUrl` in Hydrogen React](/docs/api/hydrogen-react/utilities/createstorefrontclient#:~:text=storeDomain-,getStorefrontApiUrl,-(props%3F%3A) for more details.*/
133
+ /** Creates the fully-qualified URL to your store's GraphQL endpoint. See [`getStorefrontApiUrl` in Hydrogen React](/docs/api/hydrogen-react/2023-04/utilities/createstorefrontclient#:~:text=storeDomain-,getStorefrontApiUrl,-(props%3F%3A) for more details.*/
134
134
  getApiUrl: ReturnType<typeof createStorefrontClient$1>['getStorefrontApiUrl'];
135
135
  /** Determines if the error is resulted from a Storefront API call. */
136
136
  isApiError: (error: any) => boolean;
@@ -164,7 +164,7 @@ type StorefrontHeaders = {
164
164
  };
165
165
  declare const isStorefrontApiError: (error: any) => boolean;
166
166
  /**
167
- * This function extends `createStorefrontClient` from [Hydrogen React](/docs/api/hydrogen-react/latest/utilities/createstorefrontclient). The additional arguments enable internationalization (i18n), caching, and other features particular to Remix and Oxygen.
167
+ * This function extends `createStorefrontClient` from [Hydrogen React](/docs/api/hydrogen-react/2023-04/utilities/createstorefrontclient). The additional arguments enable internationalization (i18n), caching, and other features particular to Remix and Oxygen.
168
168
  *
169
169
  * Learn more about [data fetching in Hydrogen](/docs/custom-storefronts/hydrogen/data-fetching/fetch-data).
170
170
  */
@@ -216,9 +216,14 @@ declare class InMemoryCache implements Cache {
216
216
  }
217
217
 
218
218
  type StorefrontRedirect = {
219
+ /** The [Storefront client](/docs/api/hydrogen/2023-04/utilities/createstorefrontclient) instance */
219
220
  storefront: Storefront<I18nBase>;
221
+ /** The [MDN Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object that was passed to the `server.ts` request handler. */
220
222
  request: Request;
223
+ /** The [MDN Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object created by `handleRequest` */
221
224
  response?: Response;
225
+ /** By default the `/admin` route is redirected to the Shopify Admin page for the current storefront. Disable this redirect by passing `true`. */
226
+ noAdminRedirect?: boolean;
222
227
  };
223
228
  /**
224
229
  * Queries the Storefront API to see if there is any redirect
@@ -518,9 +523,9 @@ type Connection<NodesType> = {
518
523
  nodes: Array<NodesType>;
519
524
  pageInfo: PageInfo;
520
525
  } | {
521
- edges: {
522
- node: Array<NodesType>;
523
- };
526
+ edges: Array<{
527
+ node: NodesType;
528
+ }>;
524
529
  pageInfo: PageInfo;
525
530
  };
526
531
  interface PaginationInfo<NodesType> {
@@ -4,8 +4,8 @@ import { redirect } from '@remix-run/server-runtime';
4
4
  import { lazy, useMemo, createElement, Suspense, Fragment } from 'react';
5
5
  import { useMatches, useLocation, useNavigation, Link } from '@remix-run/react';
6
6
 
7
- function z(e){let t=Array.isArray(e)?e:[e],n="";for(let r of t)r!=null&&(typeof r=="object"?!!r.body&&typeof r.body=="string"?n+=r.body:n+=JSON.stringify(r):n+=r);return n}var U="public",Pe="private",Re="no-store",Z={maxAge:"max-age",staleWhileRevalidate:"stale-while-revalidate",sMaxAge:"s-maxage",staleIfError:"stale-if-error"};function w(e){let t=[];return Object.keys(e).forEach(n=>{n==="mode"?t.push(e[n]):Z[n]&&t.push(`${Z[n]}=${e[n]}`);}),t.join(", ")}function H(){return {mode:Re}}function ee(e){if(e?.mode&&e?.mode!==U&&e?.mode!==Pe)throw Error("'mode' must be either 'public' or 'private'")}function y(e){return ee(e),{mode:U,maxAge:1,staleWhileRevalidate:9,...e}}function G(e){return ee(e),{mode:U,maxAge:3600,staleWhileRevalidate:82800,...e}}function j(e){return e}function R(e){return String(e).includes("__proto__")?JSON.parse(e,Ie):JSON.parse(e)}function Ie(e,t){if(e!=="__proto__")return t}function I(e,t){return e&&t?{...e,...t}:e||y()}function _(e){return w(I(e))}async function ke(e,t){if(!e)return;let n=await e.match(t);if(!n){t.url;return}return t.url,n}async function Ee(e,t,n,r){if(!e)return;let a=I(r);t.headers.set("cache-control",_(I(a,{maxAge:(a.maxAge||0)+(a.staleWhileRevalidate||0)})));let o=_(I(a));n.headers.set("cache-control",o),n.headers.set("real-cache-control",o),n.headers.set("cache-put-date",new Date().toUTCString()),t.url,await e.put(t,n);}async function Ae(e,t){!e||(t.url,await e.delete(t));}function Oe(e,t){let n=t.headers.get("cache-put-date"),r=t.headers.get("real-cache-control"),a=0;if(r){let c=r.match(/max-age=(\d*)/);c&&c.length>1&&(a=parseFloat(c[1]));}if(!n)return !1;let i=(new Date().valueOf()-new Date(n).valueOf())/1e3>a;return i&&(e.url,void 0),i}var k={get:ke,set:Ee,delete:Ae,generateDefaultCacheControlHeader:_,isStale:Oe};function V(e){return `https://shopify.dev/?${e}`}function Le(e){return e||y()}async function te(e,t){if(!e)return;let n=V(t),r=new Request(n),a=await k.get(e,r);if(!a)return;let o=await a.text();try{return [R(o),a]}catch{return [o,a]}}async function D(e,t,n,r){if(!e)return;let a=V(t),o=new Request(a),s=new Response(JSON.stringify(n));await k.set(e,o,s,Le(r));}function re(e,t){return k.isStale(new Request(V(e)),t)}function ve(e,t){return [e,{status:t.status,statusText:t.statusText,headers:Array.from(t.headers.entries())}]}function ne([e,t]){return [e,new Response(e,t)]}var oe=e=>!e?.errors,F=new Set;async function Q(e,t,{strategy:n=y(),cacheInstance:r,shouldCacheResult:a=()=>!0,waitUntil:o}){if(!r||!n)return t();let s=z([...typeof e=="string"?[e]:e]),i=await te(r,s);if(i){let[p,u]=i;if(!F.has(s)&&re(s,u)){F.add(s);let g=Promise.resolve().then(async()=>{try{let f=await t();a(f)&&await D(r,s,f,n);}catch(f){f.message&&(f.message="SWR in sub-request failed: "+f.message),console.error(f);}finally{F.delete(s);}});o?.(g);}return p}let c=await t();if(a(c)){let p=D(r,s,c,n);o?.(p);}return c}async function ae(e,t,{cacheInstance:n,cache:r,cacheKey:a=[e,t],shouldCacheResponse:o=()=>!0,waitUntil:s,returnType:i="json"}={}){return !r&&(!t.method||t.method==="GET")&&(r=y()),Q(a,async()=>{let c=await fetch(e,t),p;try{p=await c[i]();}catch{p=await c.text();}return ve(p,c)},{cacheInstance:n,waitUntil:s,strategy:r??null,shouldCacheResult:c=>o(...ne(c))}).then(ne)}var se="Custom-Storefront-Request-Group-ID";function ie(){return typeof crypto<"u"&&!!crypto.randomUUID?crypto.randomUUID():`weak-${Math.random().toString(16).substring(2)}`}var ce=new Set,$=e=>{ce.has(e)||(console.warn(e),ce.add(e));};var W="2023.4.3";var ge=class extends Error{},Ge=e=>e instanceof ge,je=/(^|}\s)query[\s({]/im,_e=/(^|}\s)mutation[\s({]/im;function le(e){return e.replace(/\s*#.*$/gm,"").replace(/\s+/gm," ").trim()}var Ve={language:"EN",country:"US"};function qt(e){let{storefrontHeaders:t,cache:n,waitUntil:r,buyerIp:a,i18n:o,requestGroupId:s,storefrontId:i,...c}=e;n||$("Storefront API client created without a cache instance. This may slow down your sub-requests.");let{getPublicTokenHeaders:p,getPrivateTokenHeaders:u,getStorefrontApiUrl:g,getShopifyDomain:f}=createStorefrontClient(c),h=(c.privateStorefrontToken?u:p)({contentType:"json",buyerIp:t?.buyerIp||a});if(h[se]=t?.requestGroupId||s||ie(),i&&(h[SHOPIFY_STOREFRONT_ID_HEADER]=i),(h["user-agent"]=`Hydrogen ${W}`),t&&t.cookie){let l=getShopifyCookies(t.cookie??"");l[SHOPIFY_Y]&&(h[SHOPIFY_STOREFRONT_Y_HEADER]=l[SHOPIFY_Y]),l[SHOPIFY_S]&&(h[SHOPIFY_STOREFRONT_S_HEADER]=l[SHOPIFY_S]);}t||$('"requestGroupId" and "buyerIp" will be deprecated in the next calendar release. Please use "getStorefrontHeaders"');async function m({query:l,mutation:x,variables:L,cache:Se,headers:b=[],storefrontApiVersion:Ce}){let Te=b instanceof Headers?Object.fromEntries(b.entries()):Array.isArray(b)?Object.fromEntries(b):b;l=l??x;let v={...L};o&&(!L?.country&&/\$country/.test(l)&&(v.country=o.country),!L?.language&&/\$language/.test(l)&&(v.language=o.language));let xe=g({storefrontApiVersion:Ce}),be={method:"POST",headers:{...h,...Te},body:JSON.stringify({query:l,variables:v})},[M,q]=await ae(xe,be,{cacheInstance:x?void 0:n,cache:Se||y(),shouldCacheResponse:oe,waitUntil:r});if(!q.ok){let N;try{N=R(M);}catch{N=[{message:M}];}fe(q,N);}let{data:we,errors:X}=M;return X?.length&&fe(q,X,ge),we}return {storefront:{query:(l,x)=>{if(l=le(l),_e.test(l))throw new Error("storefront.query cannot execute mutations");return m({...x,query:l})},mutate:(l,x)=>{if(l=le(l),je.test(l))throw new Error("storefront.mutate cannot execute queries");return m({...x,mutation:l})},cache:n,CacheNone:H,CacheLong:G,CacheShort:y,CacheCustom:j,generateCacheControlHeader:w,getPublicTokenHeaders:p,getPrivateTokenHeaders:u,getShopifyDomain:f,getApiUrl:g,isApiError:Ge,i18n:o??Ve}}}function fe(e,t,n=Error){let r=e.headers.get("x-request-id"),a=r?` - Request ID: ${r}`:"";if(t){let o=typeof t=="string"?t:t.map(s=>s.message).join(`
8
- `);throw new n(o+a)}throw new n(`API response error: ${e.status}`+a)}function Gt(e){let{cache:t,waitUntil:n}=e;return function(a,o,s){return Q(a,s,{strategy:o,cacheInstance:t,waitUntil:n})}}var B=class{#e;constructor(){this.#e=new Map;}add(t){throw new Error("Method not implemented. Use `put` instead.")}addAll(t){throw new Error("Method not implemented. Use `put` instead.")}matchAll(t,n){throw new Error("Method not implemented. Use `match` instead.")}async put(t,n){if(t.method!=="GET")throw new TypeError("Cannot cache response to non-GET request.");if(n.status===206)throw new TypeError("Cannot cache response to a range request (206 Partial Content).");if(n.headers.get("vary")?.includes("*"))throw new TypeError("Cannot cache response with 'Vary: *' header.");this.#e.set(t.url,{body:new Uint8Array(await n.arrayBuffer()),status:n.status,headers:[...n.headers],timestamp:Date.now()});}async match(t){if(t.method!=="GET")return;let n=this.#e.get(t.url);if(!n)return;let{body:r,timestamp:a,...o}=n,s=new Headers(o.headers),i=s.get("cache-control")||s.get("real-cache-control")||"",c=parseInt(i.match(/max-age=(\d+)/)?.[1]||"0",10),p=parseInt(i.match(/stale-while-revalidate=(\d+)/)?.[1]||"0",10),u=(Date.now()-a)/1e3;if(u>c+p){this.#e.delete(t.url);return}let f=u>c;return s.set("cache",f?"STALE":"HIT"),s.set("date",new Date(a).toUTCString()),new Response(r,{status:o.status??200,headers:s})}async delete(t){return this.#e.has(t.url)?(this.#e.delete(t.url),!0):!1}keys(t){let n=[];for(let r of this.#e.keys())(!t||t.url===r)&&n.push(new Request(r));return Promise.resolve(n)}};async function Fe(e){let{storefront:t,request:n,response:r=new Response("Not Found",{status:404})}=e,{pathname:a,search:o}=new URL(n.url),s=a+o;try{let{urlRedirects:i}=await t.query($e,{variables:{query:"path:"+s}}),c=i?.edges?.[0]?.node?.target;if(c)return new Response(null,{status:302,headers:{location:c}});let p=new URLSearchParams(o),u=p.get("return_to")||p.get("redirect");if(u){if(Qe(u))return redirect(u);console.warn(`Cross-domain redirects are not supported. Tried to redirect from ${s} to ${u}`);}}catch(i){console.error(`Failed to fetch redirects from Storefront API for route ${s}`,i);}return r}function Qe(e){try{new URL(e);}catch{return !0}return !1}var $e=`#graphql
7
+ function Z(e){let t=Array.isArray(e)?e:[e],n="";for(let r of t)r!=null&&(typeof r=="object"?!!r.body&&typeof r.body=="string"?n+=r.body:n+=JSON.stringify(r):n+=r);return n}var U="public",Ie="private",H="no-store",ee={maxAge:"max-age",staleWhileRevalidate:"stale-while-revalidate",sMaxAge:"s-maxage",staleIfError:"stale-if-error"};function w(e){let t=[];return Object.keys(e).forEach(n=>{n==="mode"?t.push(e[n]):ee[n]&&t.push(`${ee[n]}=${e[n]}`);}),t.join(", ")}function G(){return {mode:H}}function te(e){if(e?.mode&&e?.mode!==U&&e?.mode!==Ie)throw Error("'mode' must be either 'public' or 'private'")}function y(e){return te(e),{mode:U,maxAge:1,staleWhileRevalidate:9,...e}}function j(e){return te(e),{mode:U,maxAge:3600,staleWhileRevalidate:82800,...e}}function _(e){return e}function P(e){return String(e).includes("__proto__")?JSON.parse(e,ke):JSON.parse(e)}function ke(e,t){if(e!=="__proto__")return t}function I(e,t){return e&&t?{...e,...t}:e||y()}function D(e){return w(I(e))}async function Ee(e,t){if(!e)return;let n=await e.match(t);if(!n){t.url;return}return t.url,n}async function Ae(e,t,n,r){if(!e)return;let a=I(r);t.headers.set("cache-control",D(I(a,{maxAge:(a.maxAge||0)+(a.staleWhileRevalidate||0)})));let o=D(I(a));n.headers.set("cache-control",o),n.headers.set("real-cache-control",o),n.headers.set("cache-put-date",new Date().toUTCString()),t.url,await e.put(t,n);}async function Oe(e,t){!e||(t.url,await e.delete(t));}function Le(e,t){let n=t.headers.get("cache-put-date"),r=t.headers.get("real-cache-control"),a=0;if(r){let c=r.match(/max-age=(\d*)/);c&&c.length>1&&(a=parseFloat(c[1]));}if(!n)return !1;let i=(new Date().valueOf()-new Date(n).valueOf())/1e3>a;return i&&(e.url,void 0),i}var k={get:Ee,set:Ae,delete:Oe,generateDefaultCacheControlHeader:D,isStale:Le};function V(e){return `https://shopify.dev/?${e}`}function ve(e){return e||y()}async function re(e,t){if(!e)return;let n=V(t),r=new Request(n),a=await k.get(e,r);if(!a)return;let o=await a.text();try{return [P(o),a]}catch{return [o,a]}}async function F(e,t,n,r){if(!e)return;let a=V(t),o=new Request(a),s=new Response(JSON.stringify(n));await k.set(e,o,s,ve(r));}function ne(e,t){return k.isStale(new Request(V(e)),t)}function Me(e,t){return [e,{status:t.status,statusText:t.statusText,headers:Array.from(t.headers.entries())}]}function oe([e,t]){return [e,new Response(e,t)]}var ae=e=>!e?.errors,$=new Set;async function Q(e,t,{strategy:n=y(),cacheInstance:r,shouldCacheResult:a=()=>!0,waitUntil:o}){if(!r||!n||n.mode===H)return t();let s=Z([...typeof e=="string"?[e]:e]),i=await re(r,s);if(i){let[p,u]=i;if(!$.has(s)&&ne(s,u)){$.add(s);let l=Promise.resolve().then(async()=>{try{let g=await t();a(g)&&await F(r,s,g,n);}catch(g){g.message&&(g.message="SWR in sub-request failed: "+g.message),console.error(g);}finally{$.delete(s);}});o?.(l);}return p}let c=await t();if(a(c)){let p=F(r,s,c,n);o?.(p);}return c}async function se(e,t,{cacheInstance:n,cache:r,cacheKey:a=[e,t],shouldCacheResponse:o=()=>!0,waitUntil:s,returnType:i="json"}={}){return !r&&(!t.method||t.method==="GET")&&(r=y()),Q(a,async()=>{let c=await fetch(e,t),p;try{p=await c[i]();}catch{p=await c.text();}return Me(p,c)},{cacheInstance:n,waitUntil:s,strategy:r??null,shouldCacheResult:c=>o(...oe(c))}).then(oe)}var ie="Custom-Storefront-Request-Group-ID";function ce(){return typeof crypto<"u"&&!!crypto.randomUUID?crypto.randomUUID():`weak-${Math.random().toString(16).substring(2)}`}var pe=new Set,W=e=>{pe.has(e)||(console.warn(e),pe.add(e));};var B="2023.4.4";var de=class extends Error{},je=e=>e instanceof de,_e=/(^|}\s)query[\s({]/im,De=/(^|}\s)mutation[\s({]/im;function fe(e){return e.replace(/\s*#.*$/gm,"").replace(/\s+/gm," ").trim()}var Ve={language:"EN",country:"US"};function qt(e){let{storefrontHeaders:t,cache:n,waitUntil:r,buyerIp:a,i18n:o,requestGroupId:s,storefrontId:i,...c}=e;n||W("Storefront API client created without a cache instance. This may slow down your sub-requests.");let{getPublicTokenHeaders:p,getPrivateTokenHeaders:u,getStorefrontApiUrl:l,getShopifyDomain:g}=createStorefrontClient(c),h=(c.privateStorefrontToken?u:p)({contentType:"json",buyerIp:t?.buyerIp||a});if(h[ie]=t?.requestGroupId||s||ce(),i&&(h[SHOPIFY_STOREFRONT_ID_HEADER]=i),(h["user-agent"]=`Hydrogen ${B}`),t&&t.cookie){let f=getShopifyCookies(t.cookie??"");f[SHOPIFY_Y]&&(h[SHOPIFY_STOREFRONT_Y_HEADER]=f[SHOPIFY_Y]),f[SHOPIFY_S]&&(h[SHOPIFY_STOREFRONT_S_HEADER]=f[SHOPIFY_S]);}t||W('"requestGroupId" and "buyerIp" will be deprecated in the next calendar release. Please use "getStorefrontHeaders"');async function m({query:f,mutation:b,variables:L,cache:Te,headers:x=[],storefrontApiVersion:be}){let xe=x instanceof Headers?Object.fromEntries(x.entries()):Array.isArray(x)?Object.fromEntries(x):x;f=f??b;let v={...L};o&&(!L?.country&&/\$country/.test(f)&&(v.country=o.country),!L?.language&&/\$language/.test(f)&&(v.language=o.language));let we=l({storefrontApiVersion:be}),Re={method:"POST",headers:{...h,...xe},body:JSON.stringify({query:f,variables:v})},[M,q]=await se(we,Re,{cacheInstance:b?void 0:n,cache:Te||y(),shouldCacheResponse:ae,waitUntil:r});if(!q.ok){let N;try{N=P(M);}catch{N=[{message:M}];}ge(q,N);}let{data:Pe,errors:z}=M;return z?.length&&ge(q,z,de),Pe}return {storefront:{query:(f,b)=>{if(f=fe(f),De.test(f))throw new Error("storefront.query cannot execute mutations");return m({...b,query:f})},mutate:(f,b)=>{if(f=fe(f),_e.test(f))throw new Error("storefront.mutate cannot execute queries");return m({...b,mutation:f})},cache:n,CacheNone:G,CacheLong:j,CacheShort:y,CacheCustom:_,generateCacheControlHeader:w,getPublicTokenHeaders:p,getPrivateTokenHeaders:u,getShopifyDomain:g,getApiUrl:l,isApiError:je,i18n:o??Ve}}}function ge(e,t,n=Error){let r=e.headers.get("x-request-id"),a=r?` - Request ID: ${r}`:"";if(t){let o=typeof t=="string"?t:t.map(s=>s.message).join(`
8
+ `);throw new n(o+a)}throw new n(`API response error: ${e.status}`+a)}function Gt(e){let{cache:t,waitUntil:n}=e;return function(a,o,s){return Q(a,s,{strategy:o,cacheInstance:t,waitUntil:n})}}var K=class{#e;constructor(){this.#e=new Map;}add(t){throw new Error("Method not implemented. Use `put` instead.")}addAll(t){throw new Error("Method not implemented. Use `put` instead.")}matchAll(t,n){throw new Error("Method not implemented. Use `match` instead.")}async put(t,n){if(t.method!=="GET")throw new TypeError("Cannot cache response to non-GET request.");if(n.status===206)throw new TypeError("Cannot cache response to a range request (206 Partial Content).");if(n.headers.get("vary")?.includes("*"))throw new TypeError("Cannot cache response with 'Vary: *' header.");this.#e.set(t.url,{body:new Uint8Array(await n.arrayBuffer()),status:n.status,headers:[...n.headers],timestamp:Date.now()});}async match(t){if(t.method!=="GET")return;let n=this.#e.get(t.url);if(!n)return;let{body:r,timestamp:a,...o}=n,s=new Headers(o.headers),i=s.get("cache-control")||s.get("real-cache-control")||"",c=parseInt(i.match(/max-age=(\d+)/)?.[1]||"0",10),p=parseInt(i.match(/stale-while-revalidate=(\d+)/)?.[1]||"0",10),u=(Date.now()-a)/1e3;if(u>c+p){this.#e.delete(t.url);return}let g=u>c;return s.set("cache",g?"STALE":"HIT"),s.set("date",new Date(a).toUTCString()),new Response(r,{status:o.status??200,headers:s})}async delete(t){return this.#e.has(t.url)?(this.#e.delete(t.url),!0):!1}keys(t){let n=[];for(let r of this.#e.keys())(!t||t.url===r)&&n.push(new Request(r));return Promise.resolve(n)}};async function Fe(e){let{storefront:t,request:n,noAdminRedirect:r,response:a=new Response("Not Found",{status:404})}=e,{pathname:o,search:s}=new URL(n.url),i=o+s;if(o==="/admin"&&!r)return redirect(`${t.getShopifyDomain()}/admin`);try{let{urlRedirects:c}=await t.query(Qe,{variables:{query:"path:"+i}}),p=c?.edges?.[0]?.node?.target;if(p)return new Response(null,{status:301,headers:{location:p}});let u=new URLSearchParams(s),l=u.get("return_to")||u.get("redirect");if(l){if($e(l))return redirect(l);console.warn(`Cross-domain redirects are not supported. Tried to redirect from ${i} to ${l}`);}}catch(c){console.error(`Failed to fetch redirects from Storefront API for route ${i}`,c);}return a}function $e(e){try{new URL(e);}catch{return !0}return !1}var Qe=`#graphql
9
9
  query redirects($query: String) {
10
10
  urlRedirects(first: 1, query: $query) {
11
11
  edges {
@@ -69,8 +69,8 @@ function z(e){let t=Array.isArray(e)?e:[e],n="";for(let r of t)r!=null&&(typeof
69
69
  <\/script>
70
70
  </body>
71
71
  </html>
72
- `,{status:200,headers:{"content-type":"text/html"}})};var S="Error in SEO input: ",E={title:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`title` should be a string"));if(typeof e=="string"&&e.length>120)throw new Error(S.concat("`title` should not be longer than 120 characters"));return e}},description:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`description` should be a string"));if(typeof e=="string"&&e.length>155)throw new Error(S.concat("`description` should not be longer than 155 characters"));return e}},url:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`url` should be a string"));if(typeof e=="string"&&!e.startsWith("http"))throw new Error(S.concat("`url` should be a valid URL"));return e}},handle:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`handle` should be a string"));if(typeof e=="string"&&!e.startsWith("@"))throw new Error(S.concat("`handle` should start with `@`"));return e}}};function de(e){let t=[];for(let n of Object.keys(e))switch(n){case"title":{let r=A(E.title,e.title),a=Be(e?.titleTemplate,r);if(!a)break;t.push(d("title",{title:a}),d("meta",{property:"og:title",content:a}),d("meta",{name:"twitter:title",content:a}));break}case"description":{let r=A(E.description,e.description);if(!r)break;t.push(d("meta",{name:"description",content:r}),d("meta",{property:"og:description",content:r}),d("meta",{name:"twitter:description",content:r}));break}case"url":{let r=A(E.url,e.url);if(!r)break;t.push(d("link",{rel:"canonical",href:r}),d("meta",{property:"og:url",content:r}));break}case"handle":{let r=A(E.handle,e.handle);if(!r)break;t.push(d("meta",{name:"twitter:site",content:r}),d("meta",{name:"twitter:creator",content:r}));break}case"media":{let r,a=J(e.media);for(let o of a)if(typeof o=="string"&&t.push(d("meta",{name:"og:image",content:o})),o&&typeof o=="object"){let s=o.type||"image",i=o?{url:o?.url,secure_url:o?.url,type:Ke(o.url),width:o?.width,height:o?.height,alt:o?.altText}:{};for(let c of Object.keys(i))i[c]&&(r=i[c],t.push(d("meta",{property:`og:${s}:${c}`,content:r},i.url)));}break}case"jsonLd":{let r=J(e.jsonLd),a=0;for(let o of r){if(typeof o!="object")continue;let s=d("script",{type:"application/ld+json",children:JSON.stringify(o)},`json-ld-${o?.["@type"]||o?.name||a++}`);t.push(s);}break}case"alternates":{let r=J(e.alternates);for(let a of r){if(!a)continue;let{language:o,url:s,default:i}=a,c=o?`${o}${i?"-default":""}`:void 0;t.push(d("link",{rel:"alternate",hrefLang:c,href:s}));}break}case"robots":{if(!e.robots)break;let{maxImagePreview:r,maxSnippet:a,maxVideoPreview:o,noArchive:s,noFollow:i,noImageIndex:c,noIndex:p,noSnippet:u,noTranslate:g,unavailableAfter:f}=e.robots,T=[s&&"noarchive",c&&"noimageindex",u&&"nosnippet",g&&"notranslate",r&&`max-image-preview:${r}`,a&&`max-snippet:${a}`,o&&`max-video-preview:${o}`,f&&`unavailable_after:${f}`],h=(p?"noindex":"index")+","+(i?"nofollow":"follow");for(let m of T)m&&(h+=`,${m}`);t.push(d("meta",{name:"robots",content:h}));break}}return t.flat().sort((n,r)=>n.key.localeCompare(r.key))}function d(e,t,n){let r={tag:e,props:{},key:""};return e==="title"?(r.children=t.title,r.key=K(r),r):e==="script"?(r.children=typeof t.children=="string"?t.children:"",r.key=K(r,n),delete t.children,r.props=t,r):(r.props=t,Object.keys(r.props).forEach(a=>!r.props[a]&&delete r.props[a]),r.key=K(r,n),r)}function K(e,t){let{tag:n,props:r}=e;if(n==="title")return "0-title";if(n==="meta"){let a=r.content===t&&typeof r.property=="string"&&!r.property.endsWith("secure_url")&&"0";return [n,...[t,a],r.property||r.name].filter(s=>s).join("-")}return n==="link"?[n,r.rel,r.hrefLang||r.media].filter(o=>o).join("-").replace(/\s+/g,"-"):n==="script"?`${n}-${t}`:`${n}-${r.type}`}function Be(e,t){if(!!t)return e?typeof e=="function"?e(t):e.replace("%s",t??""):t}function Ke(e){switch(e&&e.split(".").pop()){case"svg":return "image/svg+xml";case"png":return "image/png";case"gif":return "image/gif";case"swf":return "application/x-shockwave-flash";case"mp3":return "audio/mpeg";case"jpg":case"jpeg":default:return "image/jpeg"}}function J(e){return Array.isArray(e)?e:[e]}function A(e,t){try{return e.validate(t)}catch(n){return console.warn(n.message),t}}var et=lazy(()=>import('./log-seo-tags-N7J66FN6.js'));function tt({debug:e}){let t=useMatches(),n=useLocation(),r=useMemo(()=>t.flatMap(s=>{let{handle:i,...c}=s,p={...c,...n},u=i?.seo,g=c?.data?.seo;return !u&&!g?[]:u?O(i.seo,p):[g]}).reduce((s,i)=>{Object.keys(i).forEach(p=>!i[p]&&delete i[p]);let{jsonLd:c}=i;return c?s?.jsonLd?Array.isArray(c)?{...s,...i,jsonLd:[...s.jsonLd,...c]}:{...s,...i,jsonLd:[...s.jsonLd,c]}:{...s,...i,jsonLd:[c]}:{...s,...i}},{}),[t,n]),{html:a,loggerMarkup:o}=useMemo(()=>{let s=de(r),i=s.map(p=>p.tag==="script"?createElement(p.tag,{...p.props,key:p.key,dangerouslySetInnerHTML:{__html:p.children}}):createElement(p.tag,{...p.props,key:p.key},p.children)),c=createElement(Suspense,{fallback:null},createElement(et,{headTags:s}));return {html:i,loggerMarkup:c}},[r]);return createElement(Fragment,null,a,e&&o)}function O(e,...t){if(e instanceof Function)return O(e(...t),...t);let n={};return Array.isArray(e)?(n=e.reduce((r,a)=>[...r,O(a)],[]),n):e instanceof Object?(Object.entries(e).forEach(([a,o])=>{n[a]=O(o,...t);}),n):e}function ot({connection:e,children:t=()=>(console.warn("<Pagination> requires children to work properly"),null)}){let r=useNavigation().state==="loading",{endCursor:a,hasNextPage:o,hasPreviousPage:s,nextPageUrl:i,nodes:c,previousPageUrl:p,startCursor:u}=at(e),g=useMemo(()=>({pageInfo:{endCursor:a,hasPreviousPage:s,startCursor:u},nodes:c}),[a,s,u,c]),f=useMemo(()=>function(m){return o?createElement(Link,{preventScrollReset:!0,...m,to:i,state:g,replace:!0}):null},[o,i]),T=useMemo(()=>function(m){return s?createElement(Link,{preventScrollReset:!0,...m,to:p,state:g,replace:!0}):null},[s,p]);return t({state:g,hasNextPage:o,hasPreviousPage:s,isLoading:r,nextPageUrl:i,nodes:c,previousPageUrl:p,NextLink:f,PreviousLink:T})}function at(e){let{state:t,search:n}=useLocation(),o=new URLSearchParams(n).get("direction")==="previous",s=useMemo(()=>!t||!t?.nodes?flattenConnection(e):o?[...flattenConnection(e),...t.nodes]:[...t.nodes,...flattenConnection(e)],[t,e]),i=useMemo(()=>{let u=t?.pageInfo?.startCursor===void 0?e.pageInfo.startCursor:t.pageInfo.startCursor,g=t?.pageInfo?.endCursor===void 0?e.pageInfo.endCursor:t.pageInfo.endCursor;t?.nodes&&(o?u=e.pageInfo.startCursor:g=e.pageInfo.endCursor);let f=t?.pageInfo?.hasPreviousPage===void 0?e.pageInfo.hasPreviousPage:t.pageInfo.hasPreviousPage,T=t?.pageInfo?.hasNextPage===void 0?e.pageInfo.hasNextPage:t.pageInfo.hasNextPage;return {startCursor:u,endCursor:g,hasPreviousPage:f,hasNextPage:T}},[o,t,e.pageInfo.hasNextPage,e.pageInfo.hasPreviousPage,e.pageInfo.startCursor,e.pageInfo.endCursor]),c=useMemo(()=>{let u=new URLSearchParams(n);return u.set("direction","previous"),i.startCursor&&u.set("cursor",i.startCursor),`?${u.toString()}`},[n,i.startCursor]),p=useMemo(()=>{let u=new URLSearchParams(n);return u.set("direction","next"),i.endCursor&&u.set("cursor",i.endCursor),`?${u.toString()}`},[n,i.endCursor]);return {...i,previousPageUrl:c,nextPageUrl:p,nodes:s}}function st(e,t={pageBy:20}){if(!(e instanceof Request))throw new Error("getPaginationVariables must be called with the Request object passed to your loader function");let{pageBy:n}=t,r=new URLSearchParams(new URL(e.url).search),a=r.get("cursor")??void 0;return (r.get("direction")==="previous"?"previous":"next")==="previous"?{last:n,startCursor:a??null}:{first:n,endCursor:a??null}}
72
+ `,{status:200,headers:{"content-type":"text/html"}})};var S="Error in SEO input: ",E={title:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`title` should be a string"));if(typeof e=="string"&&e.length>120)throw new Error(S.concat("`title` should not be longer than 120 characters"));return e}},description:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`description` should be a string"));if(typeof e=="string"&&e.length>155)throw new Error(S.concat("`description` should not be longer than 155 characters"));return e}},url:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`url` should be a string"));if(typeof e=="string"&&!e.startsWith("http"))throw new Error(S.concat("`url` should be a valid URL"));return e}},handle:{validate:e=>{if(typeof e!="string")throw new Error(S.concat("`handle` should be a string"));if(typeof e=="string"&&!e.startsWith("@"))throw new Error(S.concat("`handle` should start with `@`"));return e}}};function ye(e){let t=[];for(let n of Object.keys(e))switch(n){case"title":{let r=A(E.title,e.title),a=Be(e?.titleTemplate,r);if(!a)break;t.push(d("title",{title:a}),d("meta",{property:"og:title",content:a}),d("meta",{name:"twitter:title",content:a}));break}case"description":{let r=A(E.description,e.description);if(!r)break;t.push(d("meta",{name:"description",content:r}),d("meta",{property:"og:description",content:r}),d("meta",{name:"twitter:description",content:r}));break}case"url":{let r=A(E.url,e.url);if(!r)break;t.push(d("link",{rel:"canonical",href:r}),d("meta",{property:"og:url",content:r}));break}case"handle":{let r=A(E.handle,e.handle);if(!r)break;t.push(d("meta",{name:"twitter:site",content:r}),d("meta",{name:"twitter:creator",content:r}));break}case"media":{let r,a=Y(e.media);for(let o of a)if(typeof o=="string"&&t.push(d("meta",{name:"og:image",content:o})),o&&typeof o=="object"){let s=o.type||"image",i=o?{url:o?.url,secure_url:o?.url,type:Ke(o.url),width:o?.width,height:o?.height,alt:o?.altText}:{};for(let c of Object.keys(i))i[c]&&(r=i[c],t.push(d("meta",{property:`og:${s}:${c}`,content:r},i.url)));}break}case"jsonLd":{let r=Y(e.jsonLd),a=0;for(let o of r){if(typeof o!="object")continue;let s=d("script",{type:"application/ld+json",children:JSON.stringify(o)},`json-ld-${o?.["@type"]||o?.name||a++}`);t.push(s);}break}case"alternates":{let r=Y(e.alternates);for(let a of r){if(!a)continue;let{language:o,url:s,default:i}=a,c=o?`${o}${i?"-default":""}`:void 0;t.push(d("link",{rel:"alternate",hrefLang:c,href:s}));}break}case"robots":{if(!e.robots)break;let{maxImagePreview:r,maxSnippet:a,maxVideoPreview:o,noArchive:s,noFollow:i,noImageIndex:c,noIndex:p,noSnippet:u,noTranslate:l,unavailableAfter:g}=e.robots,T=[s&&"noarchive",c&&"noimageindex",u&&"nosnippet",l&&"notranslate",r&&`max-image-preview:${r}`,a&&`max-snippet:${a}`,o&&`max-video-preview:${o}`,g&&`unavailable_after:${g}`],h=(p?"noindex":"index")+","+(i?"nofollow":"follow");for(let m of T)m&&(h+=`,${m}`);t.push(d("meta",{name:"robots",content:h}));break}}return t.flat().sort((n,r)=>n.key.localeCompare(r.key))}function d(e,t,n){let r={tag:e,props:{},key:""};return e==="title"?(r.children=t.title,r.key=J(r),r):e==="script"?(r.children=typeof t.children=="string"?t.children:"",r.key=J(r,n),delete t.children,r.props=t,r):(r.props=t,Object.keys(r.props).forEach(a=>!r.props[a]&&delete r.props[a]),r.key=J(r,n),r)}function J(e,t){let{tag:n,props:r}=e;if(n==="title")return "0-title";if(n==="meta"){let a=r.content===t&&typeof r.property=="string"&&!r.property.endsWith("secure_url")&&"0";return [n,...[t,a],r.property||r.name].filter(s=>s).join("-")}return n==="link"?[n,r.rel,r.hrefLang||r.media].filter(o=>o).join("-").replace(/\s+/g,"-"):n==="script"?`${n}-${t}`:`${n}-${r.type}`}function Be(e,t){if(!!t)return e?typeof e=="function"?e(t):e.replace("%s",t??""):t}function Ke(e){switch(e&&e.split(".").pop()){case"svg":return "image/svg+xml";case"png":return "image/png";case"gif":return "image/gif";case"swf":return "application/x-shockwave-flash";case"mp3":return "audio/mpeg";case"jpg":case"jpeg":default:return "image/jpeg"}}function Y(e){return Array.isArray(e)?e:[e]}function A(e,t){try{return e.validate(t)}catch(n){return console.warn(n.message),t}}var et=lazy(()=>import('./log-seo-tags-N7J66FN6.js'));function tt({debug:e}){let t=useMatches(),n=useLocation(),r=useMemo(()=>t.flatMap(s=>{let{handle:i,...c}=s,p={...c,...n},u=i?.seo,l=c?.data?.seo;return !u&&!l?[]:u?O(i.seo,p):[l]}).reduce((s,i)=>{Object.keys(i).forEach(p=>!i[p]&&delete i[p]);let{jsonLd:c}=i;return c?s?.jsonLd?Array.isArray(c)?{...s,...i,jsonLd:[...s.jsonLd,...c]}:{...s,...i,jsonLd:[...s.jsonLd,c]}:{...s,...i,jsonLd:[c]}:{...s,...i}},{}),[t,n]),{html:a,loggerMarkup:o}=useMemo(()=>{let s=ye(r),i=s.map(p=>p.tag==="script"?createElement(p.tag,{...p.props,key:p.key,dangerouslySetInnerHTML:{__html:p.children}}):createElement(p.tag,{...p.props,key:p.key},p.children)),c=createElement(Suspense,{fallback:null},createElement(et,{headTags:s}));return {html:i,loggerMarkup:c}},[r]);return createElement(Fragment,null,a,e&&o)}function O(e,...t){if(e instanceof Function)return O(e(...t),...t);let n={};return Array.isArray(e)?(n=e.reduce((r,a)=>[...r,O(a)],[]),n):e instanceof Object?(Object.entries(e).forEach(([a,o])=>{n[a]=O(o,...t);}),n):e}function ot({connection:e,children:t=()=>(console.warn("<Pagination> requires children to work properly"),null)}){let r=useNavigation().state==="loading",{endCursor:a,hasNextPage:o,hasPreviousPage:s,nextPageUrl:i,nodes:c,previousPageUrl:p,startCursor:u}=at(e),l=useMemo(()=>({pageInfo:{endCursor:a,hasPreviousPage:s,startCursor:u},nodes:c}),[a,s,u,c]),g=useMemo(()=>function(m){return o?createElement(Link,{preventScrollReset:!0,...m,to:i,state:l,replace:!0}):null},[o,i]),T=useMemo(()=>function(m){return s?createElement(Link,{preventScrollReset:!0,...m,to:p,state:l,replace:!0}):null},[s,p]);return t({state:l,hasNextPage:o,hasPreviousPage:s,isLoading:r,nextPageUrl:i,nodes:c,previousPageUrl:p,NextLink:g,PreviousLink:T})}function at(e){let{state:t,search:n}=useLocation(),o=new URLSearchParams(n).get("direction")==="previous",s=useMemo(()=>!t||!t?.nodes?flattenConnection(e):o?[...flattenConnection(e),...t.nodes]:[...t.nodes,...flattenConnection(e)],[t,e]),i=useMemo(()=>{let u=t?.pageInfo?.startCursor===void 0?e.pageInfo.startCursor:t.pageInfo.startCursor,l=t?.pageInfo?.endCursor===void 0?e.pageInfo.endCursor:t.pageInfo.endCursor;t?.nodes&&(o?u=e.pageInfo.startCursor:l=e.pageInfo.endCursor);let g=t?.pageInfo?.hasPreviousPage===void 0?e.pageInfo.hasPreviousPage:t.pageInfo.hasPreviousPage,T=t?.pageInfo?.hasNextPage===void 0?e.pageInfo.hasNextPage:t.pageInfo.hasNextPage;return {startCursor:u,endCursor:l,hasPreviousPage:g,hasNextPage:T}},[o,t,e.pageInfo.hasNextPage,e.pageInfo.hasPreviousPage,e.pageInfo.startCursor,e.pageInfo.endCursor]),c=useMemo(()=>{let u=new URLSearchParams(n);return u.set("direction","previous"),i.startCursor&&u.set("cursor",i.startCursor),`?${u.toString()}`},[n,i.startCursor]),p=useMemo(()=>{let u=new URLSearchParams(n);return u.set("direction","next"),i.endCursor&&u.set("cursor",i.endCursor),`?${u.toString()}`},[n,i.endCursor]);return {...i,previousPageUrl:c,nextPageUrl:p,nodes:s}}function st(e,t={pageBy:20}){if(!(e instanceof Request))throw new Error("getPaginationVariables must be called with the Request object passed to your loader function");let{pageBy:n}=t,r=new URLSearchParams(new URL(e.url).search),a=r.get("cursor")??void 0;return (r.get("direction")==="previous"?"previous":"next")==="previous"?{last:n,startCursor:a??null}:{first:n,endCursor:a??null}}
73
73
 
74
- export { j as CacheCustom, G as CacheLong, H as CacheNone, y as CacheShort, B as InMemoryCache, ot as Pagination__unstable, tt as Seo, qt as createStorefrontClient, Gt as createWithCache_unstable, w as generateCacheControlHeader, st as getPaginationVariables__unstable, We as graphiqlLoader, Ge as isStorefrontApiError, Fe as storefrontRedirect };
74
+ export { _ as CacheCustom, j as CacheLong, G as CacheNone, y as CacheShort, K as InMemoryCache, ot as Pagination__unstable, tt as Seo, qt as createStorefrontClient, Gt as createWithCache_unstable, w as generateCacheControlHeader, st as getPaginationVariables__unstable, We as graphiqlLoader, je as isStorefrontApiError, Fe as storefrontRedirect };
75
75
  //# sourceMappingURL=out.js.map
76
76
  //# sourceMappingURL=index.js.map