@shopify/hydrogen 2023.4.1 → 2023.4.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 +145 -1
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +146 -4
- package/dist/development/index.js.map +1 -1
- package/dist/production/index.cjs +17 -15
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.d.ts +118 -37
- package/dist/production/index.js +8 -8
- package/dist/production/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -4,8 +4,9 @@ import { ExecutionArgs } from 'graphql';
|
|
|
4
4
|
import { LanguageCode, CountryCode, Maybe } from '@shopify/hydrogen-react/storefront-api-types';
|
|
5
5
|
import { LoaderArgs, LoaderFunction, SerializeFrom, AppData } from '@remix-run/server-runtime';
|
|
6
6
|
import * as react from 'react';
|
|
7
|
-
import { Params, Location } from '@remix-run/react';
|
|
7
|
+
import { Params, Location, LinkProps } from '@remix-run/react';
|
|
8
8
|
import { Thing, WithContext } from 'schema-dts';
|
|
9
|
+
import { PageInfo, Maybe as Maybe$1 } from '@shopify/hydrogen/storefront-api-types';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Override options for a cache strategy.
|
|
@@ -66,40 +67,70 @@ type I18nBase = {
|
|
|
66
67
|
country: CountryCode;
|
|
67
68
|
};
|
|
68
69
|
/**
|
|
69
|
-
*
|
|
70
|
+
* Wraps all the returned utilities from `createStorefrontClient`.
|
|
70
71
|
*/
|
|
71
72
|
type StorefrontClient<TI18n extends I18nBase> = {
|
|
72
73
|
storefront: Storefront<TI18n>;
|
|
73
74
|
};
|
|
74
75
|
/**
|
|
75
|
-
*
|
|
76
|
+
* Maps all the queries found in the project to variables and return types.
|
|
77
|
+
*/
|
|
78
|
+
interface StorefrontQueries {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Maps all the mutations found in the project to variables and return types.
|
|
82
|
+
*/
|
|
83
|
+
interface StorefrontMutations {
|
|
84
|
+
}
|
|
85
|
+
type GenericVariables = ExecutionArgs['variableValues'];
|
|
86
|
+
type EmptyVariables = {
|
|
87
|
+
[key: string]: never;
|
|
88
|
+
};
|
|
89
|
+
type AutoAddedVariableNames = 'country' | 'language';
|
|
90
|
+
type IsOptionalVariables<OperationTypeValue extends {
|
|
91
|
+
variables: any;
|
|
92
|
+
}> = Omit<OperationTypeValue['variables'], AutoAddedVariableNames> extends EmptyVariables ? true : GenericVariables extends OperationTypeValue['variables'] ? true : false;
|
|
93
|
+
type StorefrontCommonOptions<Variables extends GenericVariables> = {
|
|
94
|
+
headers?: HeadersInit;
|
|
95
|
+
storefrontApiVersion?: string;
|
|
96
|
+
} & (IsOptionalVariables<{
|
|
97
|
+
variables: Variables;
|
|
98
|
+
}> extends true ? {
|
|
99
|
+
variables?: Variables;
|
|
100
|
+
} : {
|
|
101
|
+
variables: Variables;
|
|
102
|
+
});
|
|
103
|
+
type StorefrontQuerySecondParam<RawGqlString extends keyof StorefrontQueries | string = string> = (RawGqlString extends keyof StorefrontQueries ? StorefrontCommonOptions<StorefrontQueries[RawGqlString]['variables']> : StorefrontCommonOptions<GenericVariables>) & {
|
|
104
|
+
cache?: CachingStrategy;
|
|
105
|
+
};
|
|
106
|
+
type StorefrontMutateSecondParam<RawGqlString extends keyof StorefrontMutations | string = string> = RawGqlString extends keyof StorefrontMutations ? StorefrontCommonOptions<StorefrontMutations[RawGqlString]['variables']> : StorefrontCommonOptions<GenericVariables>;
|
|
107
|
+
/**
|
|
108
|
+
* Interface to interact with the Storefront API.
|
|
76
109
|
*/
|
|
77
110
|
type Storefront<TI18n extends I18nBase = I18nBase> = {
|
|
78
|
-
/** The function to run a query on
|
|
79
|
-
query: <
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/** The function to run a mutation on storefront api. */
|
|
83
|
-
mutate: <T>(mutation: string, payload?: StorefrontCommonOptions) => Promise<T>;
|
|
111
|
+
/** The function to run a query on Storefront API. */
|
|
112
|
+
query: <OverrideReturnType = any, RawGqlString extends string = string>(query: RawGqlString, ...options: RawGqlString extends keyof StorefrontQueries ? IsOptionalVariables<StorefrontQueries[RawGqlString]> extends true ? [StorefrontQuerySecondParam<RawGqlString>?] : [StorefrontQuerySecondParam<RawGqlString>] : [StorefrontQuerySecondParam?]) => Promise<RawGqlString extends keyof StorefrontQueries ? StorefrontQueries[RawGqlString]['return'] : OverrideReturnType>;
|
|
113
|
+
/** The function to run a mutation on Storefront API. */
|
|
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>;
|
|
84
115
|
/** The cache instance passed in from the `createStorefrontClient` argument. */
|
|
85
116
|
cache?: Cache;
|
|
86
|
-
/** Re-export of [`CacheNone`](/docs/api/hydrogen/
|
|
117
|
+
/** Re-export of [`CacheNone`](/docs/api/hydrogen/utilities/cachenone). */
|
|
87
118
|
CacheNone: typeof CacheNone;
|
|
88
|
-
/** Re-export of [`CacheLong`](/docs/api/hydrogen/
|
|
119
|
+
/** Re-export of [`CacheLong`](/docs/api/hydrogen/utilities/cachelong). */
|
|
89
120
|
CacheLong: typeof CacheLong;
|
|
90
|
-
/** Re-export of [`CacheShort`](/docs/api/hydrogen/
|
|
121
|
+
/** Re-export of [`CacheShort`](/docs/api/hydrogen/utilities/cacheshort). */
|
|
91
122
|
CacheShort: typeof CacheShort;
|
|
92
|
-
/** Re-export of [`CacheCustom`](/docs/api/hydrogen/
|
|
123
|
+
/** Re-export of [`CacheCustom`](/docs/api/hydrogen/utilities/cachecustom). */
|
|
93
124
|
CacheCustom: typeof CacheCustom;
|
|
94
|
-
/** Re-export of [`generateCacheControlHeader`](/docs/api/hydrogen/
|
|
125
|
+
/** Re-export of [`generateCacheControlHeader`](/docs/api/hydrogen/utilities/generatecachecontrolheader). */
|
|
95
126
|
generateCacheControlHeader: typeof generateCacheControlHeader;
|
|
96
|
-
/** 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/
|
|
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. */
|
|
97
128
|
getPublicTokenHeaders: ReturnType<typeof createStorefrontClient$1>['getPublicTokenHeaders'];
|
|
98
|
-
/** 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/
|
|
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.*/
|
|
99
130
|
getPrivateTokenHeaders: ReturnType<typeof createStorefrontClient$1>['getPrivateTokenHeaders'];
|
|
100
|
-
/** Creates the fully-qualified URL to your myshopify.com domain. See [`getShopifyDomain` in Hydrogen React](/docs/api/hydrogen-react/
|
|
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. */
|
|
101
132
|
getShopifyDomain: ReturnType<typeof createStorefrontClient$1>['getShopifyDomain'];
|
|
102
|
-
/** Creates the fully-qualified URL to your store's GraphQL endpoint. See [`getStorefrontApiUrl` in Hydrogen React](/docs/api/hydrogen-react/
|
|
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.*/
|
|
103
134
|
getApiUrl: ReturnType<typeof createStorefrontClient$1>['getStorefrontApiUrl'];
|
|
104
135
|
/** Determines if the error is resulted from a Storefront API call. */
|
|
105
136
|
isApiError: (error: any) => boolean;
|
|
@@ -131,24 +162,6 @@ type StorefrontHeaders = {
|
|
|
131
162
|
/** The cookie header from the client */
|
|
132
163
|
cookie: string | null;
|
|
133
164
|
};
|
|
134
|
-
type StorefrontCommonOptions = {
|
|
135
|
-
variables?: ExecutionArgs['variableValues'] & {
|
|
136
|
-
country?: CountryCode;
|
|
137
|
-
language?: LanguageCode;
|
|
138
|
-
};
|
|
139
|
-
headers?: HeadersInit;
|
|
140
|
-
storefrontApiVersion?: string;
|
|
141
|
-
};
|
|
142
|
-
type StorefrontQueryOptions = StorefrontCommonOptions & {
|
|
143
|
-
query: string;
|
|
144
|
-
mutation?: never;
|
|
145
|
-
cache?: CachingStrategy;
|
|
146
|
-
};
|
|
147
|
-
type StorefrontMutationOptions = StorefrontCommonOptions & {
|
|
148
|
-
query?: never;
|
|
149
|
-
mutation: string;
|
|
150
|
-
cache?: never;
|
|
151
|
-
};
|
|
152
165
|
declare const isStorefrontApiError: (error: any) => boolean;
|
|
153
166
|
/**
|
|
154
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.
|
|
@@ -501,4 +514,72 @@ declare function Seo({ debug }: SeoProps): react.FunctionComponentElement<{
|
|
|
501
514
|
children?: react.ReactNode;
|
|
502
515
|
}>;
|
|
503
516
|
|
|
504
|
-
|
|
517
|
+
type Connection<NodesType> = {
|
|
518
|
+
nodes: Array<NodesType>;
|
|
519
|
+
pageInfo: PageInfo;
|
|
520
|
+
} | {
|
|
521
|
+
edges: {
|
|
522
|
+
node: Array<NodesType>;
|
|
523
|
+
};
|
|
524
|
+
pageInfo: PageInfo;
|
|
525
|
+
};
|
|
526
|
+
interface PaginationInfo<NodesType> {
|
|
527
|
+
/** The paginated array of nodes. You should map over and render this array. */
|
|
528
|
+
nodes: Array<NodesType>;
|
|
529
|
+
/** The `<NextLink>` is a helper component that makes it easy to navigate to the next page of paginated data. Alternatively you can build your own `<Link>` component: `<Link to={nextPageUrl} state={state} preventScrollReset />` */
|
|
530
|
+
NextLink: (props: Omit<LinkProps, 'to'>) => JSX.Element | null;
|
|
531
|
+
/** The `<PreviousLink>` is a helper component that makes it easy to navigate to the previous page of paginated data. Alternatively you can build your own `<Link>` component: `<Link to={previousPageUrl} state={state} preventScrollReset />` */
|
|
532
|
+
PreviousLink: (props: Omit<LinkProps, 'to'>) => JSX.Element | null;
|
|
533
|
+
/** The URL to the previous page of paginated data. Use this prop to build your own `<Link>` component. */
|
|
534
|
+
previousPageUrl: string;
|
|
535
|
+
/** The URL to the next page of paginated data. Use this prop to build your own `<Link>` component. */
|
|
536
|
+
nextPageUrl: string;
|
|
537
|
+
/** True if the cursor has next paginated data */
|
|
538
|
+
hasNextPage: boolean;
|
|
539
|
+
/** True if the cursor has previous paginated data */
|
|
540
|
+
hasPreviousPage: boolean;
|
|
541
|
+
/** True if we are in the process of fetching another page of data */
|
|
542
|
+
isLoading: boolean;
|
|
543
|
+
/** The `state` property is important to use when building your own `<Link>` component if you want paginated data to continuously append to the page. This means that every time the user clicks "Next page", the next page of data will be apppended inline with the previous page. If you want the whole page to re-render with only the next page results, do not pass the `state` prop to the Remix `<Link>` component. */
|
|
544
|
+
state: {
|
|
545
|
+
nodes: Array<NodesType>;
|
|
546
|
+
pageInfo: {
|
|
547
|
+
endCursor: Maybe$1<string> | undefined;
|
|
548
|
+
startCursor: Maybe$1<string> | undefined;
|
|
549
|
+
hasPreviousPage: boolean;
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
type PaginationProps<NodesType> = {
|
|
554
|
+
/** The response from `storefront.query` for a paginated request. Make sure the query is passed pagination variables and that the query has `pageInfo` with `hasPreviousPage`, `hasNextpage`, `startCursor`, and `endCursor` defined. */
|
|
555
|
+
connection: Connection<NodesType>;
|
|
556
|
+
/** A render prop that includes pagination data and helpers. */
|
|
557
|
+
children: PaginationRenderProp<NodesType>;
|
|
558
|
+
};
|
|
559
|
+
type PaginationRenderProp<NodesType> = (props: PaginationInfo<NodesType>) => JSX.Element | null;
|
|
560
|
+
/**
|
|
561
|
+
*
|
|
562
|
+
* The [Storefront API uses cursors](https://shopify.dev/docs/api/usage/pagination-graphql) to paginate through lists of data
|
|
563
|
+
* and the \`<Pagination />\` component makes it easy to paginate data from the Storefront API.
|
|
564
|
+
*
|
|
565
|
+
* @prop connection The response from `storefront.query` for a paginated request. Make sure the query is passed pagination variables and that the query has `pageInfo` with `hasPreviousPage`, `hasNextpage`, `startCursor`, and `endCursor` defined.
|
|
566
|
+
* @prop children A render prop that includes pagination data and helpers.
|
|
567
|
+
*/
|
|
568
|
+
declare function Pagination<NodesType>({ connection, children, }: PaginationProps<NodesType>): JSX.Element | null;
|
|
569
|
+
/**
|
|
570
|
+
* @param request The request object passed to your Remix loader function.
|
|
571
|
+
* @param options Options for how to configure the pagination variables. Includes the ability to change how many nodes are within each page.
|
|
572
|
+
*
|
|
573
|
+
* @returns Variables to be used with the `storefront.query` function
|
|
574
|
+
*/
|
|
575
|
+
declare function getPaginationVariables(request: Request, options?: {
|
|
576
|
+
pageBy: number;
|
|
577
|
+
}): {
|
|
578
|
+
last: number;
|
|
579
|
+
startCursor: string | null;
|
|
580
|
+
} | {
|
|
581
|
+
first: number;
|
|
582
|
+
endCursor: string | null;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
export { CacheCustom, CacheLong, CacheNone, CacheShort, CreateStorefrontClientOptions, I18nBase, InMemoryCache, Pagination as Pagination__unstable, Seo, SeoConfig, SeoHandleFunction, Storefront, StorefrontClient, StorefrontMutations, StorefrontQueries, WithCache, createStorefrontClient, createWithCache_unstable, generateCacheControlHeader, getPaginationVariables as getPaginationVariables__unstable, graphiqlLoader, isStorefrontApiError, storefrontRedirect };
|
package/dist/production/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createStorefrontClient, SHOPIFY_STOREFRONT_ID_HEADER, getShopifyCookies, SHOPIFY_Y, SHOPIFY_STOREFRONT_Y_HEADER, SHOPIFY_S, SHOPIFY_STOREFRONT_S_HEADER } from '@shopify/hydrogen-react';
|
|
1
|
+
import { createStorefrontClient, SHOPIFY_STOREFRONT_ID_HEADER, getShopifyCookies, SHOPIFY_Y, SHOPIFY_STOREFRONT_Y_HEADER, SHOPIFY_S, SHOPIFY_STOREFRONT_S_HEADER, flattenConnection } from '@shopify/hydrogen-react';
|
|
2
2
|
export { AnalyticsEventName, AnalyticsPageType, ExternalVideo, IMAGE_FRAGMENT, Image, MediaFile, ModelViewer, Money, ShopPayButton, ShopifySalesChannel, Video, flattenConnection, getClientBrowserParameters, getShopifyCookies, parseGid, parseMetafield, sendShopifyAnalytics, storefrontApiCustomScalars, useMoney, useShopifyCookies } from '@shopify/hydrogen-react';
|
|
3
3
|
import { redirect } from '@remix-run/server-runtime';
|
|
4
4
|
import { lazy, useMemo, createElement, Suspense, Fragment } from 'react';
|
|
5
|
-
import { useMatches, useLocation } from '@remix-run/react';
|
|
5
|
+
import { useMatches, useLocation, useNavigation, Link } from '@remix-run/react';
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
`);throw new n(a
|
|
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.2";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
|
|
9
9
|
query redirects($query: String) {
|
|
10
10
|
urlRedirects(first: 1, query: $query) {
|
|
11
11
|
edges {
|
|
@@ -15,7 +15,7 @@ function J(e){let t=Array.isArray(e)?e:[e],n="";for(let r of t)r!=null&&(typeof
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
`;var We=async function({context:t}){let n=t?.storefront;if(!n)throw new Error("GraphiQL: Hydrogen's storefront client must be injected in the loader context.");let r=n.getApiUrl(),
|
|
18
|
+
`;var We=async function({context:t}){let n=t?.storefront;if(!n)throw new Error("GraphiQL: Hydrogen's storefront client must be injected in the loader context.");let r=n.getApiUrl(),a=n.getPublicTokenHeaders()["X-Shopify-Storefront-Access-Token"];return new Response(`
|
|
19
19
|
<!DOCTYPE html>
|
|
20
20
|
<html lang="en">
|
|
21
21
|
<head>
|
|
@@ -58,7 +58,7 @@ function J(e){let t=Array.isArray(e)?e:[e],n="";for(let r of t)r!=null&&(typeof
|
|
|
58
58
|
fetcher: GraphiQL.createFetcher({
|
|
59
59
|
url: '${r}',
|
|
60
60
|
headers: {
|
|
61
|
-
'X-Shopify-Storefront-Access-Token': '${
|
|
61
|
+
'X-Shopify-Storefront-Access-Token': '${a}',
|
|
62
62
|
}
|
|
63
63
|
}),
|
|
64
64
|
defaultEditorToolsVisibility: true,
|
|
@@ -69,8 +69,8 @@ function J(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
|
|
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}}
|
|
73
73
|
|
|
74
|
-
export {
|
|
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 };
|
|
75
75
|
//# sourceMappingURL=out.js.map
|
|
76
76
|
//# sourceMappingURL=index.js.map
|