@shopify/hydrogen 2023.7.1 → 2023.7.2
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/development/index.cjs +8 -2
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +8 -2
- package/dist/development/index.js.map +1 -1
- package/dist/production/index.cjs +1 -1
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +1 -1
- package/dist/production/index.js.map +1 -1
- package/package.json +2 -2
package/dist/production/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { lazy, useMemo, createElement, Suspense, Fragment } from 'react';
|
|
|
5
5
|
import { useMatches, useLocation, useNavigation, Link, useFetcher } from '@remix-run/react';
|
|
6
6
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
|
-
function ge(e){let t=Array.isArray(e)?e:[e],a="";for(let r of t)r!=null&&(typeof r=="object"?!!r.body&&typeof r.body=="string"?a+=r.body:a+=JSON.stringify(r):a+=r);return encodeURIComponent(a)}var k="public",Be="private",_="no-store",me={maxAge:"max-age",staleWhileRevalidate:"stale-while-revalidate",sMaxAge:"s-maxage",staleIfError:"stale-if-error"};function b(e){let t=[];return Object.keys(e).forEach(a=>{a==="mode"?t.push(e[a]):me[a]&&t.push(`${me[a]}=${e[a]}`);}),t.join(", ")}function Q(){return {mode:_}}function Ce(e){if(e?.mode&&e?.mode!==k&&e?.mode!==Be)throw Error("'mode' must be either 'public' or 'private'")}function I(e){return Ce(e),{mode:k,maxAge:1,staleWhileRevalidate:9,...e}}function H(e){return Ce(e),{mode:k,maxAge:3600,staleWhileRevalidate:82800,...e}}function G(e){return e}function U(e){return String(e).includes("__proto__")?JSON.parse(e,We):JSON.parse(e)}function We(e,t){if(e!=="__proto__")return t}function w(e,t){return e&&t?{...e,...t}:e||I()}function V(e){return b(w(e))}async function je(e,t){if(!e)return;let a=await e.match(t);if(!a){return}return a}async function Je(e,t,a,r){if(!e)return;let i=w(r),n=V(w(i,{maxAge:(i.maxAge||0)+(i.staleWhileRevalidate||0)})),o=V(w(i));a.headers.set("cache-control",n),a.headers.set("real-cache-control",o),a.headers.set("cache-put-date",new Date().toUTCString()),await e.put(t,a);}async function Ke(e,t){!e||await e.delete(t);}function Ye(e,t){let a=e.headers.get("real-cache-control"),r=0;if(a){let n=a.match(/max-age=(\d*)/);n&&n.length>1&&(r=parseFloat(n[1]));}return [(new Date().valueOf()-new Date(t).valueOf())/1e3,r]}function ze(e,t){let a=t.headers.get("cache-put-date");if(!a)return !1;let[r,i]=Ye(t,a),n=r>i;return n}var E={get:je,set:Je,delete:Ke,generateDefaultCacheControlHeader:V,isStale:ze};function B(e){return `https://shopify.dev/?${e}`}function Xe(e){return e||I()}async function he(e,t){if(!e)return;let a=B(t),r=new Request(a),i=await E.get(e,r);if(!i)return;let n=await i.text();try{return [U(n),i]}catch{return [n,i]}}async function W(e,t,a,r){if(!e)return;let i=B(t),n=new Request(i),o=new Response(JSON.stringify(a));await E.set(e,n,o,Xe(r));}function Se(e,t){return E.isStale(new Request(B(e)),t)}function Ze(e,t){return [e,{status:t.status,statusText:t.statusText,headers:Array.from(t.headers.entries())}]}function Ie([e,t]){return [e,new Response(e,t)]}var Re=e=>!e?.errors,j=new Set;async function J(e,t,{strategy:a=I(),cacheInstance:r,shouldCacheResult:i=()=>!0,waitUntil:n}){if(!r||!a||a.mode===_)return t();let o=ge([...typeof e=="string"?[e]:e]),s=await he(r,o);if(s){let[c,p]=s;if(!j.has(o)&&Se(o,p)){j.add(o);let d=Promise.resolve().then(async()=>{try{let l=await t();i(l)&&await W(r,o,l,a);}catch(l){l.message&&(l.message="SWR in sub-request failed: "+l.message),console.error(l);}finally{j.delete(o);}});n?.(d);}return c}let u=await t();if(i(u)){let c=W(r,o,u,a);n?.(c);}return u}async function Te(e,t,{cacheInstance:a,cache:r,cacheKey:i=[e,t],shouldCacheResponse:n=()=>!0,waitUntil:o,returnType:s="json"}={}){return !r&&(!t.method||t.method==="GET")&&(r=I()),J(i,async()=>{let u=await fetch(e,t),c;try{c=await u[s]();}catch{c=await u.text();}return Ze(c,u)},{cacheInstance:a,waitUntil:o,strategy:r??null,shouldCacheResult:u=>n(...Ie(u))}).then(Ie)}var xe="Custom-Storefront-Request-Group-ID";function Ae(){return typeof crypto<"u"&&!!crypto.randomUUID?crypto.randomUUID():`weak-${Math.random().toString(16).substring(2)}`}var K="2023.7.
|
|
8
|
+
function ge(e){let t=Array.isArray(e)?e:[e],a="";for(let r of t)r!=null&&(typeof r=="object"?!!r.body&&typeof r.body=="string"?a+=r.body:a+=JSON.stringify(r):a+=r);return encodeURIComponent(a)}var k="public",Be="private",_="no-store",me={maxAge:"max-age",staleWhileRevalidate:"stale-while-revalidate",sMaxAge:"s-maxage",staleIfError:"stale-if-error"};function b(e){let t=[];return Object.keys(e).forEach(a=>{a==="mode"?t.push(e[a]):me[a]&&t.push(`${me[a]}=${e[a]}`);}),t.join(", ")}function Q(){return {mode:_}}function Ce(e){if(e?.mode&&e?.mode!==k&&e?.mode!==Be)throw Error("'mode' must be either 'public' or 'private'")}function I(e){return Ce(e),{mode:k,maxAge:1,staleWhileRevalidate:9,...e}}function H(e){return Ce(e),{mode:k,maxAge:3600,staleWhileRevalidate:82800,...e}}function G(e){return e}function U(e){return String(e).includes("__proto__")?JSON.parse(e,We):JSON.parse(e)}function We(e,t){if(e!=="__proto__")return t}function w(e,t){return e&&t?{...e,...t}:e||I()}function V(e){return b(w(e))}async function je(e,t){if(!e)return;let a=await e.match(t);if(!a){return}return a}async function Je(e,t,a,r){if(!e)return;let i=w(r),n=V(w(i,{maxAge:(i.maxAge||0)+(i.staleWhileRevalidate||0)})),o=V(w(i));a.headers.set("cache-control",n),a.headers.set("real-cache-control",o),a.headers.set("cache-put-date",new Date().toUTCString()),await e.put(t,a);}async function Ke(e,t){!e||await e.delete(t);}function Ye(e,t){let a=e.headers.get("real-cache-control"),r=0;if(a){let n=a.match(/max-age=(\d*)/);n&&n.length>1&&(r=parseFloat(n[1]));}return [(new Date().valueOf()-new Date(t).valueOf())/1e3,r]}function ze(e,t){let a=t.headers.get("cache-put-date");if(!a)return !1;let[r,i]=Ye(t,a),n=r>i;return n}var E={get:je,set:Je,delete:Ke,generateDefaultCacheControlHeader:V,isStale:ze};function B(e){return `https://shopify.dev/?${e}`}function Xe(e){return e||I()}async function he(e,t){if(!e)return;let a=B(t),r=new Request(a),i=await E.get(e,r);if(!i)return;let n=await i.text();try{return [U(n),i]}catch{return [n,i]}}async function W(e,t,a,r){if(!e)return;let i=B(t),n=new Request(i),o=new Response(JSON.stringify(a));await E.set(e,n,o,Xe(r));}function Se(e,t){return E.isStale(new Request(B(e)),t)}function Ze(e,t){return [e,{status:t.status,statusText:t.statusText,headers:Array.from(t.headers.entries())}]}function Ie([e,t]){return [e,new Response(e,t)]}var Re=e=>!e?.errors,j=new Set;async function J(e,t,{strategy:a=I(),cacheInstance:r,shouldCacheResult:i=()=>!0,waitUntil:n}){if(!r||!a||a.mode===_)return t();let o=ge([...typeof e=="string"?[e]:e]),s=await he(r,o);if(s){let[c,p]=s;if(!j.has(o)&&Se(o,p)){j.add(o);let d=Promise.resolve().then(async()=>{try{let l=await t();i(l)&&await W(r,o,l,a);}catch(l){l.message&&(l.message="SWR in sub-request failed: "+l.message),console.error(l);}finally{j.delete(o);}});n?.(d);}return c}let u=await t();if(i(u)){let c=W(r,o,u,a);n?.(c);}return u}async function Te(e,t,{cacheInstance:a,cache:r,cacheKey:i=[e,t],shouldCacheResponse:n=()=>!0,waitUntil:o,returnType:s="json"}={}){return !r&&(!t.method||t.method==="GET")&&(r=I()),J(i,async()=>{let u=await fetch(e,t),c;try{c=await u[s]();}catch{try{c=await u.text();}catch{throw new Error(`Storefront API response code: ${u.status} (Request Id: ${u.headers.get("x-request-id")})`)}}return Ze(c,u)},{cacheInstance:a,waitUntil:o,strategy:r??null,shouldCacheResult:u=>n(...Ie(u))}).then(Ie)}var xe="Custom-Storefront-Request-Group-ID";function Ae(){return typeof crypto<"u"&&!!crypto.randomUUID?crypto.randomUUID():`weak-${Math.random().toString(16).substring(2)}`}var K="2023.7.2";var Me=class extends Error{},ot=e=>e instanceof Me,it=/(^|}\s)query[\s({]/im,st=/(^|}\s)mutation[\s({]/im;function be(e){return e.replace(/\s*#.*$/gm,"").replace(/\s+/gm," ").trim()}var ut={language:"EN",country:"US"};function Pr(e){let {storefrontHeaders:t,cache:a,waitUntil:r,buyerIp:i,i18n:n,requestGroupId:o,storefrontId:s,...u}=e,{getPublicTokenHeaders:p,getPrivateTokenHeaders:d,getStorefrontApiUrl:l,getShopifyDomain:h}=createStorefrontClient(u),m=(u.privateStorefrontToken?d:p)({contentType:"json",buyerIp:t?.buyerIp||i});if(m[xe]=t?.requestGroupId||o||Ae(),s&&(m[SHOPIFY_STOREFRONT_ID_HEADER]=s),(m["user-agent"]=`Hydrogen ${K}`),t&&t.cookie){let y=getShopifyCookies(t.cookie??"");y[SHOPIFY_Y]&&(m[SHOPIFY_STOREFRONT_Y_HEADER]=y[SHOPIFY_Y]),y[SHOPIFY_S]&&(m[SHOPIFY_STOREFRONT_S_HEADER]=y[SHOPIFY_S]);}async function O({query:y,mutation:S,variables:A,cache:ke,headers:P=[],storefrontApiVersion:_e}){let Qe=P instanceof Headers?Object.fromEntries(P.entries()):Array.isArray(P)?Object.fromEntries(P):P;y=y??S;let M={...A};n&&(!A?.country&&/\$country/.test(y)&&(M.country=n.country),!A?.language&&/\$language/.test(y)&&(M.language=n.language));let He=l({storefrontApiVersion:_e}),Ge={method:"POST",headers:{...m,...Qe},body:JSON.stringify({query:y,variables:M})},[$,le]=await Te(He,Ge,{cacheInstance:S?void 0:a,cache:ke||I(),shouldCacheResponse:Re,waitUntil:r}),ye={response:le,type:S?"mutation":"query",query:y,queryVariables:M,errors:void 0};if(!le.ok){let q;try{q=U($);}catch{q=[{message:$}];}De({...ye,errors:q});}let{data:Ve,errors:fe}=$;return fe?.length&&De({...ye,errors:fe,ErrorConstructor:Me}),Ve}return {storefront:{query:(y,S)=>{if(y=be(y),st.test(y))throw new Error("[h2:error:storefront.query] Cannot execute mutations");return O({...S,query:y})},mutate:(y,S)=>{if(y=be(y),it.test(y))throw new Error("[h2:error:storefront.mutate] Cannot execute queries");return O({...S,mutation:y})},cache:a,CacheNone:Q,CacheLong:H,CacheShort:I,CacheCustom:G,generateCacheControlHeader:b,getPublicTokenHeaders:p,getPrivateTokenHeaders:d,getShopifyDomain:h,getApiUrl:l,isApiError:ot,i18n:n??ut}}}function De({response:e,errors:t,type:a,query:r,queryVariables:i,ErrorConstructor:n=Error}){let o=e.headers.get("x-request-id"),s=(typeof t=="string"?t:t?.map?.(u=>u.message).join(`
|
|
9
9
|
`))||`API response error: ${e.status}`;throw new n(`[h2:error:storefront.${a}] `+s+(o?` - Request ID: ${o}`:""),{cause:{errors:t,requestId:o}})}function Ur(e){let{cache:t,waitUntil:a}=e;return function(i,n,o){return J(i,o,{strategy:n,cacheInstance:t,waitUntil:a})}}var Y=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,a){throw new Error("Method not implemented. Use `match` instead.")}async put(t,a){if(t.method!=="GET")throw new TypeError("Cannot cache response to non-GET request.");if(a.status===206)throw new TypeError("Cannot cache response to a range request (206 Partial Content).");if(a.headers.get("vary")?.includes("*"))throw new TypeError("Cannot cache response with 'Vary: *' header.");this.#e.set(t.url,{body:new Uint8Array(await a.arrayBuffer()),status:a.status,headers:[...a.headers],timestamp:Date.now()});}async match(t){if(t.method!=="GET")return;let a=this.#e.get(t.url);if(!a)return;let{body:r,timestamp:i,...n}=a,o=new Headers(n.headers),s=o.get("cache-control")||o.get("real-cache-control")||"",u=parseInt(s.match(/max-age=(\d+)/)?.[1]||"0",10),c=parseInt(s.match(/stale-while-revalidate=(\d+)/)?.[1]||"0",10),p=(Date.now()-i)/1e3;if(p>u+c){this.#e.delete(t.url);return}let l=p>u;return o.set("cache",l?"STALE":"HIT"),o.set("date",new Date(i).toUTCString()),new Response(r,{status:n.status??200,headers:o})}async delete(t){return this.#e.has(t.url)?(this.#e.delete(t.url),!0):!1}keys(t){let a=[];for(let r of this.#e.keys())(!t||t.url===r)&&a.push(new Request(r));return Promise.resolve(a)}};async function pt(e){let{storefront:t,request:a,noAdminRedirect:r,response:i=new Response("Not Found",{status:404})}=e,{pathname:n,search:o}=new URL(a.url),s=n+o;if(n==="/admin"&&!r)return redirect(`${t.getShopifyDomain()}/admin`);try{let{urlRedirects:u}=await t.query(dt,{variables:{query:"path:"+s}}),c=u?.edges?.[0]?.node?.target;if(c)return new Response(null,{status:301,headers:{location:c}});let p=new URLSearchParams(o),d=p.get("return_to")||p.get("redirect");if(d){if(ct(d))return redirect(d);console.warn(`Cross-domain redirects are not supported. Tried to redirect from ${s} to ${d}`);}}catch(u){console.error(`Failed to fetch redirects from Storefront API for route ${s}`,u);}return i}function ct(e){try{new URL(e);}catch{return !0}return !1}var dt=`#graphql
|
|
10
10
|
query redirects($query: String) {
|
|
11
11
|
urlRedirects(first: 1, query: $query) {
|