hydrogen-sanity 4.0.1 → 4.0.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/README.md CHANGED
@@ -422,7 +422,7 @@ export async function loader({context, params}: LoaderArgs) {
422
422
  const {withCache, sanity} = context
423
423
 
424
424
  const homepage = await withCache('home', CacheLong(), () =>
425
- sanity.fetch(`*[_type == "page" && _id == $id][0]`, {id: 'home'})
425
+ sanity.fetch(`*[_type == "page" && _id == $id][0]`, {id: 'home'}),
426
426
  )
427
427
 
428
428
  return json({homepage})
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sanity/client"),t=require("@sanity/react-loader"),n=require("@shopify/hydrogen");function r(e,t){let n=e;return t&&(n+=JSON.stringify(t)),async function(e){const t=await(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}(n)}const i=n.CacheLong(),a=t.createQueryStore({client:!1,ssr:!0});Object.defineProperty(exports,"SanityClient",{enumerable:!0,get:function(){return e.SanityClient}}),Object.defineProperty(exports,"createClient",{enumerable:!0,get:function(){return e.createClient}}),exports.createSanityLoader=function(t){const{withCache:o,preview:c,strategy:l}=t;let s=t.client instanceof e.SanityClient?t.client:e.createClient(t.client);if("1"===s.config().apiVersion&&(s=s.withConfig({apiVersion:"v2022-03-07"})),c&&c.enabled){if(!c.token)throw new Error("Enabling preview mode requires a token.");const e=s.withConfig({useCdn:!1,token:c.token,perspective:"previewDrafts",stega:{enabled:!0,studioUrl:c.studioUrl}});a.setServerClient(e)}else a.setServerClient(s);return{async loadQuery(e,t,s){var u;const d=c&&c.enabled?n.CacheNone():(null==(u=null==s?void 0:s.hydrogen)?void 0:u.cache)||l||i,y=await r(e,t);return await o(y,d,(async({addDebugData:n})=>{var r,i;try{const o=await a.loadQuery(e,t,s);if("development"===process.env.NODE_ENV){n({displayName:(null==(i=null==(r=null==s?void 0:s.hydrogen)?void 0:r.debug)?void 0:i.displayName)||"query Sanity"})}return o}catch(e){throw e}}))},client:s,preview:c}};//# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@sanity/client"),t=require("@sanity/react-loader"),n=require("@shopify/hydrogen");function r(e,t){let n=e;return t&&(n+=JSON.stringify(t)),async function(e){const t=await(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}(n)}const i=n.CacheLong(),a=t.createQueryStore({client:!1,ssr:!0});Object.defineProperty(exports,"SanityClient",{enumerable:!0,get:function(){return e.SanityClient}}),Object.defineProperty(exports,"createClient",{enumerable:!0,get:function(){return e.createClient}}),exports.createSanityLoader=function(t){const{withCache:o,preview:l,strategy:c}=t;let s=t.client instanceof e.SanityClient?t.client:e.createClient(t.client);if("1"===s.config().apiVersion&&(s=s.withConfig({apiVersion:"v2022-03-07"})),l&&l.enabled){if(!l.token)throw new Error("Enabling preview mode requires a token.");const e=s.withConfig({useCdn:!1,token:l.token,perspective:"previewDrafts",stega:{enabled:!0,studioUrl:l.studioUrl}});a.setServerClient(e)}else a.setServerClient(s);return{async loadQuery(e,t,s){var u;const d=l&&l.enabled?n.CacheNone():(null==(u=null==s?void 0:s.hydrogen)?void 0:u.cache)||c||i,y=await r(e,t);return await o(y,d,(async({addDebugData:n})=>{var r,i;if("development"===process.env.NODE_ENV){n({displayName:(null==(i=null==(r=null==s?void 0:s.hydrogen)?void 0:r.debug)?void 0:i.displayName)||"query Sanity"})}return await a.loadQuery(e,t,s)}))},client:s,preview:l}};//# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/loader.ts"],"sourcesContent":["import type {QueryParams, QueryWithoutParams} from './client'\n\n/**\n * Create an SHA-256 hash as a hex string\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string\n */\nexport async function sha256(message: string): Promise<string> {\n // encode as UTF-8\n const messageBuffer = await new TextEncoder().encode(message)\n // hash the message\n const hashBuffer = await crypto.subtle.digest('SHA-256', messageBuffer)\n // convert bytes to hex string\n return Array.from(new Uint8Array(hashBuffer))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n/**\n * Hash query and its parameters for use as cache key\n * NOTE: Oxygen deployment will break if the cache key is long or contains `\\n`\n */\nexport function hashQuery(\n query: string,\n params: QueryParams | QueryWithoutParams\n): Promise<string> {\n let hash = query\n\n if (params) {\n hash += JSON.stringify(params)\n }\n\n return sha256(hash)\n}\n","/* eslint-disable no-return-await */\nimport {createQueryStore, type QueryResponseInitial} from '@sanity/react-loader'\nimport {CacheLong, CacheNone, type HydrogenSession, type WithCache} from '@shopify/hydrogen'\n\nimport {\n type ClientConfig,\n createClient,\n type QueryParams,\n type QueryWithoutParams,\n type ResponseQueryOptions,\n SanityClient,\n} from './client'\nimport type {CachingStrategy} from './types'\nimport {hashQuery} from './utils'\n\nconst DEFAULT_CACHE_STRATEGY = CacheLong()\n\nexport type CreateSanityLoaderOptions = {\n /**\n * Cache control utility from `@shopify/hydrogen`.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching/third-party\n */\n withCache: WithCache\n\n /**\n * Sanity client or configuration to use.\n */\n client: SanityClient | ClientConfig\n\n /**\n * The default caching strategy to use for `loadQuery` subrequests.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n *\n * Defaults to `CacheLong`\n */\n strategy?: CachingStrategy | null\n\n /**\n * Configuration for enabling preview mode.\n */\n preview?: {enabled: boolean; token: string; studioUrl: string}\n}\n\ninterface RequestInit {\n hydrogen?: {\n /**\n * The caching strategy to use for the subrequest.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n */\n cache?: CachingStrategy\n\n /**\n * Optional debugging information to be displayed in the subrequest profiler.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/debugging/subrequest-profiler#how-to-provide-more-debug-information-for-a-request\n */\n debug?: {\n displayName: string\n }\n }\n}\n\ntype HydrogenResponseQueryOptions = Omit<ResponseQueryOptions, 'next' | 'cache'> & {\n hydrogen?: 'hydrogen' extends keyof RequestInit ? RequestInit['hydrogen'] : never\n}\n\ntype LoadQueryOptions = Pick<\n HydrogenResponseQueryOptions,\n 'perspective' | 'hydrogen' | 'useCdn' | 'stega'\n>\n\nexport type SanityLoader = {\n /**\n * Query Sanity using the loader.\n * @see https://www.sanity.io/docs/loaders\n */\n loadQuery<T = any>(\n query: string,\n params?: QueryParams,\n options?: LoadQueryOptions\n ): Promise<QueryResponseInitial<T>>\n\n client: SanityClient\n\n preview?: CreateSanityLoaderOptions['preview']\n}\n\ndeclare module '@shopify/remix-oxygen' {\n /**\n * Declare local additions to the Remix loader context.\n */\n export interface AppLoadContext {\n session: HydrogenSession\n sanity: SanityLoader\n }\n}\n\nconst queryStore = createQueryStore({client: false, ssr: true})\n\n/**\n * @public\n */\nexport function createSanityLoader(options: CreateSanityLoaderOptions): SanityLoader {\n const {withCache, preview, strategy} = options\n let client =\n options.client instanceof SanityClient ? options.client : createClient(options.client)\n\n /**\n * TODO: should this default to the latest API version?\n * Or at least warn if a version that doesn't support perspectivves is used?\n */\n if (client.config().apiVersion === '1') {\n client = client.withConfig({apiVersion: 'v2022-03-07'})\n }\n\n if (preview && preview.enabled) {\n if (!preview.token) {\n throw new Error('Enabling preview mode requires a token.')\n }\n\n const previewClient = client.withConfig({\n useCdn: false,\n token: preview.token,\n perspective: 'previewDrafts' as const,\n stega: {enabled: true, studioUrl: preview.studioUrl},\n })\n\n queryStore.setServerClient(previewClient)\n } else {\n queryStore.setServerClient(client)\n }\n\n const sanity = {\n async loadQuery<T>(\n query: string,\n params: QueryParams | QueryWithoutParams,\n loaderOptions?: LoadQueryOptions\n ): Promise<QueryResponseInitial<T>> {\n // Don't store response if preview is enabled\n const cacheStrategy =\n preview && preview.enabled\n ? CacheNone()\n : loaderOptions?.hydrogen?.cache || strategy || DEFAULT_CACHE_STRATEGY\n\n const queryHash = await hashQuery(query, params)\n\n return await withCache(queryHash, cacheStrategy, async ({addDebugData}) => {\n try {\n const result = await queryStore.loadQuery<T>(query, params, loaderOptions)\n\n // eslint-disable-next-line no-process-env\n if (process.env.NODE_ENV === 'development') {\n // Name displayed in the subrequest profiler\n const displayName = loaderOptions?.hydrogen?.debug?.displayName || 'query Sanity'\n\n addDebugData({\n displayName,\n })\n }\n\n return result\n } catch (error) {\n throw error\n }\n })\n },\n client,\n preview,\n }\n\n return sanity\n}\n"],"names":["hashQuery","query","params","hash","JSON","stringify","async","message","messageBuffer","TextEncoder","encode","hashBuffer","crypto","subtle","digest","Array","from","Uint8Array","map","b","toString","padStart","join","sha256","DEFAULT_CACHE_STRATEGY","CacheLong","queryStore","createQueryStore","client","ssr","Object","defineProperty","exports","enumerable","get","SanityClient","createClient","createSanityLoader","options","withCache","preview","strategy","config","apiVersion","withConfig","enabled","token","Error","previewClient","useCdn","perspective","stega","studioUrl","setServerClient","loadQuery","loaderOptions","_a","cacheStrategy","CacheNone","hydrogen","cache","queryHash","addDebugData","_b","result","process","env","NODE_ENV","displayName","debug","error"],"mappings":"qKAqBgB,SAAAA,EACdC,EACAC,GAEA,IAAIC,EAAOF,EAEX,OAAIC,IACFC,GAAQC,KAAKC,UAAUH,IAtB3BI,eAA6BC,GAE3B,MAAMC,QAAsB,IAAIC,aAAcC,OAAOH,GAE/CI,QAAmBC,OAAOC,OAAOC,OAAO,UAAWN,GAElD,OAAAO,MAAMC,KAAK,IAAIC,WAAWN,IAC9BO,KAAKC,GAAMA,EAAEC,SAAS,IAAIC,SAAS,EAAG,OACtCC,KAAK,GACV,CAgBSC,CAAOpB,EAChB,CCjBA,MAAMqB,EAAyBC,EAAAA,YAiFzBC,EAAaC,EAAAA,iBAAiB,CAACC,QAAQ,EAAOC,KAAK,IA0EzDC,OAAAC,eAAAC,QAAA,eAAA,CAAAC,YAAA,EAAAC,IAAA,WAAA,OAAAN,EAAAO,YAAA,IAAAL,OAAAC,eAAAC,QAAA,eAAA,CAAAC,YAAA,EAAAC,IAAA,WAAA,OAAAN,EAAAQ,YAAA,IAAAJ,QAAAK,mBArEO,SAA4BC,GACjC,MAAMC,UAACA,EAAAC,QAAWA,EAASC,SAAAA,GAAYH,EACnCV,IAAAA,EACFU,EAAQV,kBAAkBO,EAAAA,aAAeG,EAAQV,OAASQ,EAAAA,aAAaE,EAAQV,QAUjF,GAJmC,MAA/BA,EAAOc,SAASC,aAClBf,EAASA,EAAOgB,WAAW,CAACD,WAAY,iBAGtCH,GAAWA,EAAQK,QAAS,CAC9B,IAAKL,EAAQM,MACL,MAAA,IAAIC,MAAM,2CAGZ,MAAAC,EAAgBpB,EAAOgB,WAAW,CACtCK,QAAQ,EACRH,MAAON,EAAQM,MACfI,YAAa,gBACbC,MAAO,CAACN,SAAS,EAAMO,UAAWZ,EAAQY,aAG5C1B,EAAW2B,gBAAgBL,EAC7B,MACEtB,EAAW2B,gBAAgBzB,GAGd,MAAA,CACb,eAAM0B,CACJrD,EACAC,EACAqD,GAvIN,IAAAC,EA0IY,MAAAC,EACJjB,GAAWA,EAAQK,QACfa,EAAAA,aACA,OAAAF,EAAe,MAAAD,OAAA,EAAAA,EAAAI,eAAU,EAAAH,EAAAI,QAASnB,GAAYjB,EAE9CqC,QAAkB7D,EAAUC,EAAOC,GAEzC,aAAaqC,EAAUsB,EAAWJ,GAAenD,OAAQwD,mBAjJ/D,IAAAN,EAAAO,EAkJY,IACF,MAAMC,QAAetC,EAAW4B,UAAarD,EAAOC,EAAQqD,GAGxD,GAAyB,gBAAzBU,QAAQC,IAAIC,SAA4B,CAI7BL,EAAA,CACXM,aAHkB,OAAAL,EAAA,OAAAP,EAAA,MAAAD,OAAA,EAAAA,EAAeI,eAAfH,EAAAA,EAAyBa,YAAzB,EAAAN,EAAgCK,cAAe,gBAKrE,CAEO,OAAAJ,QACAM,GACD,MAAAA,CACR,IAEJ,EAAA1C,OACAA,EACAY,UAIJ"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/loader.ts"],"sourcesContent":["import type {QueryParams, QueryWithoutParams} from './client'\n\n/**\n * Create an SHA-256 hash as a hex string\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string\n */\nexport async function sha256(message: string): Promise<string> {\n // encode as UTF-8\n const messageBuffer = await new TextEncoder().encode(message)\n // hash the message\n const hashBuffer = await crypto.subtle.digest('SHA-256', messageBuffer)\n // convert bytes to hex string\n return Array.from(new Uint8Array(hashBuffer))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n/**\n * Hash query and its parameters for use as cache key\n * NOTE: Oxygen deployment will break if the cache key is long or contains `\\n`\n */\nexport function hashQuery(\n query: string,\n params: QueryParams | QueryWithoutParams,\n): Promise<string> {\n let hash = query\n\n if (params) {\n hash += JSON.stringify(params)\n }\n\n return sha256(hash)\n}\n","/* eslint-disable no-return-await */\nimport {createQueryStore, type QueryResponseInitial} from '@sanity/react-loader'\nimport {CacheLong, CacheNone, type HydrogenSession, type WithCache} from '@shopify/hydrogen'\n\nimport {\n type ClientConfig,\n createClient,\n type QueryParams,\n type QueryWithoutParams,\n type ResponseQueryOptions,\n SanityClient,\n} from './client'\nimport type {CachingStrategy} from './types'\nimport {hashQuery} from './utils'\n\nconst DEFAULT_CACHE_STRATEGY = CacheLong()\n\nexport type CreateSanityLoaderOptions = {\n /**\n * Cache control utility from `@shopify/hydrogen`.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching/third-party\n */\n withCache: WithCache\n\n /**\n * Sanity client or configuration to use.\n */\n client: SanityClient | ClientConfig\n\n /**\n * The default caching strategy to use for `loadQuery` subrequests.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n *\n * Defaults to `CacheLong`\n */\n strategy?: CachingStrategy | null\n\n /**\n * Configuration for enabling preview mode.\n */\n preview?: {enabled: boolean; token: string; studioUrl: string}\n}\n\ninterface RequestInit {\n hydrogen?: {\n /**\n * The caching strategy to use for the subrequest.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n */\n cache?: CachingStrategy\n\n /**\n * Optional debugging information to be displayed in the subrequest profiler.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/debugging/subrequest-profiler#how-to-provide-more-debug-information-for-a-request\n */\n debug?: {\n displayName: string\n }\n }\n}\n\ntype HydrogenResponseQueryOptions = Omit<ResponseQueryOptions, 'next' | 'cache'> & {\n hydrogen?: 'hydrogen' extends keyof RequestInit ? RequestInit['hydrogen'] : never\n}\n\ntype LoadQueryOptions = Pick<\n HydrogenResponseQueryOptions,\n 'perspective' | 'hydrogen' | 'useCdn' | 'stega'\n>\n\nexport type SanityLoader = {\n /**\n * Query Sanity using the loader.\n * @see https://www.sanity.io/docs/loaders\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n loadQuery<T = any>(\n query: string,\n params?: QueryParams,\n options?: LoadQueryOptions,\n ): Promise<QueryResponseInitial<T>>\n\n client: SanityClient\n\n preview?: CreateSanityLoaderOptions['preview']\n}\n\ndeclare module '@shopify/remix-oxygen' {\n /**\n * Declare local additions to the Remix loader context.\n */\n export interface AppLoadContext {\n session: HydrogenSession\n sanity: SanityLoader\n }\n}\n\nconst queryStore = createQueryStore({client: false, ssr: true})\n\n/**\n * @public\n */\nexport function createSanityLoader(options: CreateSanityLoaderOptions): SanityLoader {\n const {withCache, preview, strategy} = options\n let client =\n options.client instanceof SanityClient ? options.client : createClient(options.client)\n\n /**\n * TODO: should this default to the latest API version?\n * Or at least warn if a version that doesn't support perspectivves is used?\n */\n if (client.config().apiVersion === '1') {\n client = client.withConfig({apiVersion: 'v2022-03-07'})\n }\n\n if (preview && preview.enabled) {\n if (!preview.token) {\n throw new Error('Enabling preview mode requires a token.')\n }\n\n const previewClient = client.withConfig({\n useCdn: false,\n token: preview.token,\n perspective: 'previewDrafts' as const,\n stega: {enabled: true, studioUrl: preview.studioUrl},\n })\n\n queryStore.setServerClient(previewClient)\n } else {\n queryStore.setServerClient(client)\n }\n\n const sanity = {\n async loadQuery<T>(\n query: string,\n params: QueryParams | QueryWithoutParams,\n loaderOptions?: LoadQueryOptions,\n ): Promise<QueryResponseInitial<T>> {\n // Don't store response if preview is enabled\n const cacheStrategy =\n preview && preview.enabled\n ? CacheNone()\n : loaderOptions?.hydrogen?.cache || strategy || DEFAULT_CACHE_STRATEGY\n\n const queryHash = await hashQuery(query, params)\n\n return await withCache(queryHash, cacheStrategy, async ({addDebugData}) => {\n // eslint-disable-next-line no-process-env\n if (process.env.NODE_ENV === 'development') {\n // Name displayed in the subrequest profiler\n const displayName = loaderOptions?.hydrogen?.debug?.displayName || 'query Sanity'\n\n addDebugData({\n displayName,\n })\n }\n\n return await queryStore.loadQuery<T>(query, params, loaderOptions)\n })\n },\n client,\n preview,\n }\n\n return sanity\n}\n"],"names":["hashQuery","query","params","hash","JSON","stringify","async","message","messageBuffer","TextEncoder","encode","hashBuffer","crypto","subtle","digest","Array","from","Uint8Array","map","b","toString","padStart","join","sha256","DEFAULT_CACHE_STRATEGY","CacheLong","queryStore","createQueryStore","client","ssr","Object","defineProperty","exports","enumerable","get","SanityClient","createClient","createSanityLoader","options","withCache","preview","strategy","config","apiVersion","withConfig","enabled","token","Error","previewClient","useCdn","perspective","stega","studioUrl","setServerClient","loadQuery","loaderOptions","_a","cacheStrategy","CacheNone","hydrogen","cache","queryHash","addDebugData","_b","process","env","NODE_ENV","displayName","debug"],"mappings":"qKAqBgB,SAAAA,EACdC,EACAC,GAEA,IAAIC,EAAOF,EAEX,OAAIC,IACFC,GAAQC,KAAKC,UAAUH,IAtB3BI,eAA6BC,GAE3B,MAAMC,QAAsB,IAAIC,aAAcC,OAAOH,GAE/CI,QAAmBC,OAAOC,OAAOC,OAAO,UAAWN,GAElD,OAAAO,MAAMC,KAAK,IAAIC,WAAWN,IAC9BO,KAAKC,GAAMA,EAAEC,SAAS,IAAIC,SAAS,EAAG,OACtCC,KAAK,GACV,CAgBSC,CAAOpB,EAChB,CCjBA,MAAMqB,EAAyBC,EAAAA,YAkFzBC,EAAaC,EAAAA,iBAAiB,CAACC,QAAQ,EAAOC,KAAK,IAoEzDC,OAAAC,eAAAC,QAAA,eAAA,CAAAC,YAAA,EAAAC,IAAA,WAAA,OAAAN,EAAAO,YAAA,IAAAL,OAAAC,eAAAC,QAAA,eAAA,CAAAC,YAAA,EAAAC,IAAA,WAAA,OAAAN,EAAAQ,YAAA,IAAAJ,QAAAK,mBA/DO,SAA4BC,GACjC,MAAMC,UAACA,EAAAC,QAAWA,EAASC,SAAAA,GAAYH,EACnCV,IAAAA,EACFU,EAAQV,kBAAkBO,EAAAA,aAAeG,EAAQV,OAASQ,EAAAA,aAAaE,EAAQV,QAUjF,GAJmC,MAA/BA,EAAOc,SAASC,aAClBf,EAASA,EAAOgB,WAAW,CAACD,WAAY,iBAGtCH,GAAWA,EAAQK,QAAS,CAC9B,IAAKL,EAAQM,MACL,MAAA,IAAIC,MAAM,2CAGZ,MAAAC,EAAgBpB,EAAOgB,WAAW,CACtCK,QAAQ,EACRH,MAAON,EAAQM,MACfI,YAAa,gBACbC,MAAO,CAACN,SAAS,EAAMO,UAAWZ,EAAQY,aAG5C1B,EAAW2B,gBAAgBL,EAC7B,MACEtB,EAAW2B,gBAAgBzB,GAGd,MAAA,CACb,eAAM0B,CACJrD,EACAC,EACAqD,GAxIN,IAAAC,EA2IY,MAAAC,EACJjB,GAAWA,EAAQK,QACfa,EAAAA,aACA,OAAAF,EAAe,MAAAD,OAAA,EAAAA,EAAAI,eAAU,EAAAH,EAAAI,QAASnB,GAAYjB,EAE9CqC,QAAkB7D,EAAUC,EAAOC,GAEzC,aAAaqC,EAAUsB,EAAWJ,GAAenD,OAAQwD,mBAlJ/D,IAAAN,EAAAO,EAoJY,GAAyB,gBAAzBC,QAAQC,IAAIC,SAA4B,CAI7BJ,EAAA,CACXK,aAHkB,OAAAJ,EAAA,OAAAP,EAAA,MAAAD,OAAA,EAAAA,EAAeI,eAAfH,EAAAA,EAAyBY,YAAzB,EAAAL,EAAgCI,cAAe,gBAKrE,CAEA,aAAazC,EAAW4B,UAAarD,EAAOC,EAAQqD,EAAa,GAErE,EAAA3B,OACAA,EACAY,UAIJ"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{SanityClient as e,createClient as t}from"@sanity/client";import{SanityClient as n,createClient as i}from"@sanity/client";import{createQueryStore as r}from"@sanity/react-loader";import{CacheLong as a,CacheNone as o}from"@shopify/hydrogen";function s(e,t){let n=e;return t&&(n+=JSON.stringify(t)),async function(e){const t=await(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}(n)}const l=a(),c=r({client:!1,ssr:!0});function d(n){const{withCache:i,preview:r,strategy:a}=n;let d=n.client instanceof e?n.client:t(n.client);if("1"===d.config().apiVersion&&(d=d.withConfig({apiVersion:"v2022-03-07"})),r&&r.enabled){if(!r.token)throw new Error("Enabling preview mode requires a token.");const e=d.withConfig({useCdn:!1,token:r.token,perspective:"previewDrafts",stega:{enabled:!0,studioUrl:r.studioUrl}});c.setServerClient(e)}else c.setServerClient(d);return{async loadQuery(e,t,n){var d;const y=r&&r.enabled?o():(null==(d=null==n?void 0:n.hydrogen)?void 0:d.cache)||a||l,u=await s(e,t);return await i(u,y,(async({addDebugData:i})=>{var r,a;try{const o=await c.loadQuery(e,t,n);if("development"===process.env.NODE_ENV){i({displayName:(null==(a=null==(r=null==n?void 0:n.hydrogen)?void 0:r.debug)?void 0:a.displayName)||"query Sanity"})}return o}catch(e){throw e}}))},client:d,preview:r}}export{n as SanityClient,i as createClient,d as createSanityLoader};//# sourceMappingURL=index.js.map
1
+ import{SanityClient as e,createClient as t}from"@sanity/client";import{SanityClient as n,createClient as i}from"@sanity/client";import{createQueryStore as r}from"@sanity/react-loader";import{CacheLong as a,CacheNone as o}from"@shopify/hydrogen";function l(e,t){let n=e;return t&&(n+=JSON.stringify(t)),async function(e){const t=await(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}(n)}const s=a(),c=r({client:!1,ssr:!0});function d(n){const{withCache:i,preview:r,strategy:a}=n;let d=n.client instanceof e?n.client:t(n.client);if("1"===d.config().apiVersion&&(d=d.withConfig({apiVersion:"v2022-03-07"})),r&&r.enabled){if(!r.token)throw new Error("Enabling preview mode requires a token.");const e=d.withConfig({useCdn:!1,token:r.token,perspective:"previewDrafts",stega:{enabled:!0,studioUrl:r.studioUrl}});c.setServerClient(e)}else c.setServerClient(d);return{async loadQuery(e,t,n){var d;const u=r&&r.enabled?o():(null==(d=null==n?void 0:n.hydrogen)?void 0:d.cache)||a||s,y=await l(e,t);return await i(y,u,(async({addDebugData:i})=>{var r,a;if("development"===process.env.NODE_ENV){i({displayName:(null==(a=null==(r=null==n?void 0:n.hydrogen)?void 0:r.debug)?void 0:a.displayName)||"query Sanity"})}return await c.loadQuery(e,t,n)}))},client:d,preview:r}}export{n as SanityClient,i as createClient,d as createSanityLoader};//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/loader.ts"],"sourcesContent":["import type {QueryParams, QueryWithoutParams} from './client'\n\n/**\n * Create an SHA-256 hash as a hex string\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string\n */\nexport async function sha256(message: string): Promise<string> {\n // encode as UTF-8\n const messageBuffer = await new TextEncoder().encode(message)\n // hash the message\n const hashBuffer = await crypto.subtle.digest('SHA-256', messageBuffer)\n // convert bytes to hex string\n return Array.from(new Uint8Array(hashBuffer))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n/**\n * Hash query and its parameters for use as cache key\n * NOTE: Oxygen deployment will break if the cache key is long or contains `\\n`\n */\nexport function hashQuery(\n query: string,\n params: QueryParams | QueryWithoutParams\n): Promise<string> {\n let hash = query\n\n if (params) {\n hash += JSON.stringify(params)\n }\n\n return sha256(hash)\n}\n","/* eslint-disable no-return-await */\nimport {createQueryStore, type QueryResponseInitial} from '@sanity/react-loader'\nimport {CacheLong, CacheNone, type HydrogenSession, type WithCache} from '@shopify/hydrogen'\n\nimport {\n type ClientConfig,\n createClient,\n type QueryParams,\n type QueryWithoutParams,\n type ResponseQueryOptions,\n SanityClient,\n} from './client'\nimport type {CachingStrategy} from './types'\nimport {hashQuery} from './utils'\n\nconst DEFAULT_CACHE_STRATEGY = CacheLong()\n\nexport type CreateSanityLoaderOptions = {\n /**\n * Cache control utility from `@shopify/hydrogen`.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching/third-party\n */\n withCache: WithCache\n\n /**\n * Sanity client or configuration to use.\n */\n client: SanityClient | ClientConfig\n\n /**\n * The default caching strategy to use for `loadQuery` subrequests.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n *\n * Defaults to `CacheLong`\n */\n strategy?: CachingStrategy | null\n\n /**\n * Configuration for enabling preview mode.\n */\n preview?: {enabled: boolean; token: string; studioUrl: string}\n}\n\ninterface RequestInit {\n hydrogen?: {\n /**\n * The caching strategy to use for the subrequest.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n */\n cache?: CachingStrategy\n\n /**\n * Optional debugging information to be displayed in the subrequest profiler.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/debugging/subrequest-profiler#how-to-provide-more-debug-information-for-a-request\n */\n debug?: {\n displayName: string\n }\n }\n}\n\ntype HydrogenResponseQueryOptions = Omit<ResponseQueryOptions, 'next' | 'cache'> & {\n hydrogen?: 'hydrogen' extends keyof RequestInit ? RequestInit['hydrogen'] : never\n}\n\ntype LoadQueryOptions = Pick<\n HydrogenResponseQueryOptions,\n 'perspective' | 'hydrogen' | 'useCdn' | 'stega'\n>\n\nexport type SanityLoader = {\n /**\n * Query Sanity using the loader.\n * @see https://www.sanity.io/docs/loaders\n */\n loadQuery<T = any>(\n query: string,\n params?: QueryParams,\n options?: LoadQueryOptions\n ): Promise<QueryResponseInitial<T>>\n\n client: SanityClient\n\n preview?: CreateSanityLoaderOptions['preview']\n}\n\ndeclare module '@shopify/remix-oxygen' {\n /**\n * Declare local additions to the Remix loader context.\n */\n export interface AppLoadContext {\n session: HydrogenSession\n sanity: SanityLoader\n }\n}\n\nconst queryStore = createQueryStore({client: false, ssr: true})\n\n/**\n * @public\n */\nexport function createSanityLoader(options: CreateSanityLoaderOptions): SanityLoader {\n const {withCache, preview, strategy} = options\n let client =\n options.client instanceof SanityClient ? options.client : createClient(options.client)\n\n /**\n * TODO: should this default to the latest API version?\n * Or at least warn if a version that doesn't support perspectivves is used?\n */\n if (client.config().apiVersion === '1') {\n client = client.withConfig({apiVersion: 'v2022-03-07'})\n }\n\n if (preview && preview.enabled) {\n if (!preview.token) {\n throw new Error('Enabling preview mode requires a token.')\n }\n\n const previewClient = client.withConfig({\n useCdn: false,\n token: preview.token,\n perspective: 'previewDrafts' as const,\n stega: {enabled: true, studioUrl: preview.studioUrl},\n })\n\n queryStore.setServerClient(previewClient)\n } else {\n queryStore.setServerClient(client)\n }\n\n const sanity = {\n async loadQuery<T>(\n query: string,\n params: QueryParams | QueryWithoutParams,\n loaderOptions?: LoadQueryOptions\n ): Promise<QueryResponseInitial<T>> {\n // Don't store response if preview is enabled\n const cacheStrategy =\n preview && preview.enabled\n ? CacheNone()\n : loaderOptions?.hydrogen?.cache || strategy || DEFAULT_CACHE_STRATEGY\n\n const queryHash = await hashQuery(query, params)\n\n return await withCache(queryHash, cacheStrategy, async ({addDebugData}) => {\n try {\n const result = await queryStore.loadQuery<T>(query, params, loaderOptions)\n\n // eslint-disable-next-line no-process-env\n if (process.env.NODE_ENV === 'development') {\n // Name displayed in the subrequest profiler\n const displayName = loaderOptions?.hydrogen?.debug?.displayName || 'query Sanity'\n\n addDebugData({\n displayName,\n })\n }\n\n return result\n } catch (error) {\n throw error\n }\n })\n },\n client,\n preview,\n }\n\n return sanity\n}\n"],"names":["hashQuery","query","params","hash","JSON","stringify","async","message","messageBuffer","TextEncoder","encode","hashBuffer","crypto","subtle","digest","Array","from","Uint8Array","map","b","toString","padStart","join","sha256","DEFAULT_CACHE_STRATEGY","CacheLong","queryStore","createQueryStore","client","ssr","createSanityLoader","options","withCache","preview","strategy","SanityClient","createClient","config","apiVersion","withConfig","enabled","token","Error","previewClient","useCdn","perspective","stega","studioUrl","setServerClient","loadQuery","loaderOptions","_a","cacheStrategy","CacheNone","hydrogen","cache","queryHash","addDebugData","_b","result","process","env","NODE_ENV","displayName","debug","error"],"mappings":"qPAqBgB,SAAAA,EACdC,EACAC,GAEA,IAAIC,EAAOF,EAEX,OAAIC,IACFC,GAAQC,KAAKC,UAAUH,IAtB3BI,eAA6BC,GAE3B,MAAMC,QAAsB,IAAIC,aAAcC,OAAOH,GAE/CI,QAAmBC,OAAOC,OAAOC,OAAO,UAAWN,GAElD,OAAAO,MAAMC,KAAK,IAAIC,WAAWN,IAC9BO,KAAKC,GAAMA,EAAEC,SAAS,IAAIC,SAAS,EAAG,OACtCC,KAAK,GACV,CAgBSC,CAAOpB,EAChB,CCjBA,MAAMqB,EAAyBC,IAiFzBC,EAAaC,EAAiB,CAACC,QAAQ,EAAOC,KAAK,IAKlD,SAASC,EAAmBC,GACjC,MAAMC,UAACA,EAAAC,QAAWA,EAASC,SAAAA,GAAYH,EACnC,IAAAH,EACFG,EAAQH,kBAAkBO,EAAeJ,EAAQH,OAASQ,EAAaL,EAAQH,QAUjF,GAJmC,MAA/BA,EAAOS,SAASC,aAClBV,EAASA,EAAOW,WAAW,CAACD,WAAY,iBAGtCL,GAAWA,EAAQO,QAAS,CAC9B,IAAKP,EAAQQ,MACL,MAAA,IAAIC,MAAM,2CAGZ,MAAAC,EAAgBf,EAAOW,WAAW,CACtCK,QAAQ,EACRH,MAAOR,EAAQQ,MACfI,YAAa,gBACbC,MAAO,CAACN,SAAS,EAAMO,UAAWd,EAAQc,aAG5CrB,EAAWsB,gBAAgBL,EAC7B,MACEjB,EAAWsB,gBAAgBpB,GAGd,MAAA,CACb,eAAMqB,CACJhD,EACAC,EACAgD,GAvIN,IAAAC,EA0IY,MAAAC,EACJnB,GAAWA,EAAQO,QACfa,KACA,OAAAF,EAAe,MAAAD,OAAA,EAAAA,EAAAI,eAAU,EAAAH,EAAAI,QAASrB,GAAYV,EAE9CgC,QAAkBxD,EAAUC,EAAOC,GAEzC,aAAa8B,EAAUwB,EAAWJ,GAAe9C,OAAQmD,mBAjJ/D,IAAAN,EAAAO,EAkJY,IACF,MAAMC,QAAejC,EAAWuB,UAAahD,EAAOC,EAAQgD,GAGxD,GAAyB,gBAAzBU,QAAQC,IAAIC,SAA4B,CAI7BL,EAAA,CACXM,aAHkB,OAAAL,EAAA,OAAAP,EAAA,MAAAD,OAAA,EAAAA,EAAeI,eAAfH,EAAAA,EAAyBa,YAAzB,EAAAN,EAAgCK,cAAe,gBAKrE,CAEO,OAAAJ,QACAM,GACD,MAAAA,CACR,IAEJ,EACArC,SACAK,UAIJ"}
1
+ {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/loader.ts"],"sourcesContent":["import type {QueryParams, QueryWithoutParams} from './client'\n\n/**\n * Create an SHA-256 hash as a hex string\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#converting_a_digest_to_a_hex_string\n */\nexport async function sha256(message: string): Promise<string> {\n // encode as UTF-8\n const messageBuffer = await new TextEncoder().encode(message)\n // hash the message\n const hashBuffer = await crypto.subtle.digest('SHA-256', messageBuffer)\n // convert bytes to hex string\n return Array.from(new Uint8Array(hashBuffer))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n/**\n * Hash query and its parameters for use as cache key\n * NOTE: Oxygen deployment will break if the cache key is long or contains `\\n`\n */\nexport function hashQuery(\n query: string,\n params: QueryParams | QueryWithoutParams,\n): Promise<string> {\n let hash = query\n\n if (params) {\n hash += JSON.stringify(params)\n }\n\n return sha256(hash)\n}\n","/* eslint-disable no-return-await */\nimport {createQueryStore, type QueryResponseInitial} from '@sanity/react-loader'\nimport {CacheLong, CacheNone, type HydrogenSession, type WithCache} from '@shopify/hydrogen'\n\nimport {\n type ClientConfig,\n createClient,\n type QueryParams,\n type QueryWithoutParams,\n type ResponseQueryOptions,\n SanityClient,\n} from './client'\nimport type {CachingStrategy} from './types'\nimport {hashQuery} from './utils'\n\nconst DEFAULT_CACHE_STRATEGY = CacheLong()\n\nexport type CreateSanityLoaderOptions = {\n /**\n * Cache control utility from `@shopify/hydrogen`.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching/third-party\n */\n withCache: WithCache\n\n /**\n * Sanity client or configuration to use.\n */\n client: SanityClient | ClientConfig\n\n /**\n * The default caching strategy to use for `loadQuery` subrequests.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n *\n * Defaults to `CacheLong`\n */\n strategy?: CachingStrategy | null\n\n /**\n * Configuration for enabling preview mode.\n */\n preview?: {enabled: boolean; token: string; studioUrl: string}\n}\n\ninterface RequestInit {\n hydrogen?: {\n /**\n * The caching strategy to use for the subrequest.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/caching#caching-strategies\n */\n cache?: CachingStrategy\n\n /**\n * Optional debugging information to be displayed in the subrequest profiler.\n * @see https://shopify.dev/docs/custom-storefronts/hydrogen/debugging/subrequest-profiler#how-to-provide-more-debug-information-for-a-request\n */\n debug?: {\n displayName: string\n }\n }\n}\n\ntype HydrogenResponseQueryOptions = Omit<ResponseQueryOptions, 'next' | 'cache'> & {\n hydrogen?: 'hydrogen' extends keyof RequestInit ? RequestInit['hydrogen'] : never\n}\n\ntype LoadQueryOptions = Pick<\n HydrogenResponseQueryOptions,\n 'perspective' | 'hydrogen' | 'useCdn' | 'stega'\n>\n\nexport type SanityLoader = {\n /**\n * Query Sanity using the loader.\n * @see https://www.sanity.io/docs/loaders\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n loadQuery<T = any>(\n query: string,\n params?: QueryParams,\n options?: LoadQueryOptions,\n ): Promise<QueryResponseInitial<T>>\n\n client: SanityClient\n\n preview?: CreateSanityLoaderOptions['preview']\n}\n\ndeclare module '@shopify/remix-oxygen' {\n /**\n * Declare local additions to the Remix loader context.\n */\n export interface AppLoadContext {\n session: HydrogenSession\n sanity: SanityLoader\n }\n}\n\nconst queryStore = createQueryStore({client: false, ssr: true})\n\n/**\n * @public\n */\nexport function createSanityLoader(options: CreateSanityLoaderOptions): SanityLoader {\n const {withCache, preview, strategy} = options\n let client =\n options.client instanceof SanityClient ? options.client : createClient(options.client)\n\n /**\n * TODO: should this default to the latest API version?\n * Or at least warn if a version that doesn't support perspectivves is used?\n */\n if (client.config().apiVersion === '1') {\n client = client.withConfig({apiVersion: 'v2022-03-07'})\n }\n\n if (preview && preview.enabled) {\n if (!preview.token) {\n throw new Error('Enabling preview mode requires a token.')\n }\n\n const previewClient = client.withConfig({\n useCdn: false,\n token: preview.token,\n perspective: 'previewDrafts' as const,\n stega: {enabled: true, studioUrl: preview.studioUrl},\n })\n\n queryStore.setServerClient(previewClient)\n } else {\n queryStore.setServerClient(client)\n }\n\n const sanity = {\n async loadQuery<T>(\n query: string,\n params: QueryParams | QueryWithoutParams,\n loaderOptions?: LoadQueryOptions,\n ): Promise<QueryResponseInitial<T>> {\n // Don't store response if preview is enabled\n const cacheStrategy =\n preview && preview.enabled\n ? CacheNone()\n : loaderOptions?.hydrogen?.cache || strategy || DEFAULT_CACHE_STRATEGY\n\n const queryHash = await hashQuery(query, params)\n\n return await withCache(queryHash, cacheStrategy, async ({addDebugData}) => {\n // eslint-disable-next-line no-process-env\n if (process.env.NODE_ENV === 'development') {\n // Name displayed in the subrequest profiler\n const displayName = loaderOptions?.hydrogen?.debug?.displayName || 'query Sanity'\n\n addDebugData({\n displayName,\n })\n }\n\n return await queryStore.loadQuery<T>(query, params, loaderOptions)\n })\n },\n client,\n preview,\n }\n\n return sanity\n}\n"],"names":["hashQuery","query","params","hash","JSON","stringify","async","message","messageBuffer","TextEncoder","encode","hashBuffer","crypto","subtle","digest","Array","from","Uint8Array","map","b","toString","padStart","join","sha256","DEFAULT_CACHE_STRATEGY","CacheLong","queryStore","createQueryStore","client","ssr","createSanityLoader","options","withCache","preview","strategy","SanityClient","createClient","config","apiVersion","withConfig","enabled","token","Error","previewClient","useCdn","perspective","stega","studioUrl","setServerClient","loadQuery","loaderOptions","_a","cacheStrategy","CacheNone","hydrogen","cache","queryHash","addDebugData","_b","process","env","NODE_ENV","displayName","debug"],"mappings":"qPAqBgB,SAAAA,EACdC,EACAC,GAEA,IAAIC,EAAOF,EAEX,OAAIC,IACFC,GAAQC,KAAKC,UAAUH,IAtB3BI,eAA6BC,GAE3B,MAAMC,QAAsB,IAAIC,aAAcC,OAAOH,GAE/CI,QAAmBC,OAAOC,OAAOC,OAAO,UAAWN,GAElD,OAAAO,MAAMC,KAAK,IAAIC,WAAWN,IAC9BO,KAAKC,GAAMA,EAAEC,SAAS,IAAIC,SAAS,EAAG,OACtCC,KAAK,GACV,CAgBSC,CAAOpB,EAChB,CCjBA,MAAMqB,EAAyBC,IAkFzBC,EAAaC,EAAiB,CAACC,QAAQ,EAAOC,KAAK,IAKlD,SAASC,EAAmBC,GACjC,MAAMC,UAACA,EAAAC,QAAWA,EAASC,SAAAA,GAAYH,EACnC,IAAAH,EACFG,EAAQH,kBAAkBO,EAAeJ,EAAQH,OAASQ,EAAaL,EAAQH,QAUjF,GAJmC,MAA/BA,EAAOS,SAASC,aAClBV,EAASA,EAAOW,WAAW,CAACD,WAAY,iBAGtCL,GAAWA,EAAQO,QAAS,CAC9B,IAAKP,EAAQQ,MACL,MAAA,IAAIC,MAAM,2CAGZ,MAAAC,EAAgBf,EAAOW,WAAW,CACtCK,QAAQ,EACRH,MAAOR,EAAQQ,MACfI,YAAa,gBACbC,MAAO,CAACN,SAAS,EAAMO,UAAWd,EAAQc,aAG5CrB,EAAWsB,gBAAgBL,EAC7B,MACEjB,EAAWsB,gBAAgBpB,GAGd,MAAA,CACb,eAAMqB,CACJhD,EACAC,EACAgD,GAxIN,IAAAC,EA2IY,MAAAC,EACJnB,GAAWA,EAAQO,QACfa,KACA,OAAAF,EAAe,MAAAD,OAAA,EAAAA,EAAAI,eAAU,EAAAH,EAAAI,QAASrB,GAAYV,EAE9CgC,QAAkBxD,EAAUC,EAAOC,GAEzC,aAAa8B,EAAUwB,EAAWJ,GAAe9C,OAAQmD,mBAlJ/D,IAAAN,EAAAO,EAoJY,GAAyB,gBAAzBC,QAAQC,IAAIC,SAA4B,CAI7BJ,EAAA,CACXK,aAHkB,OAAAJ,EAAA,OAAAP,EAAA,MAAAD,OAAA,EAAAA,EAAeI,eAAfH,EAAAA,EAAyBY,YAAzB,EAAAL,EAAgCI,cAAe,gBAKrE,CAEA,aAAapC,EAAWuB,UAAahD,EAAOC,EAAQgD,EAAa,GAErE,EACAtB,SACAK,UAIJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from '@sanity/visual-editing/remix'\nimport {lazy, type ReactElement, Suspense} from 'react'\n\nconst VisualEditingComponent = lazy(() =>\n import('@sanity/visual-editing/remix').then((mod) => ({default: mod.VisualEditing}))\n)\n\n/**\n * Enables visual editing on the front-end\n * @see https://www.sanity.io/docs/introduction-to-visual-editing\n */\nexport function VisualEditing(props: VisualEditingProps): ReactElement {\n return (\n <Suspense fallback={null}>\n <VisualEditingComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["VisualEditingComponent","lazy","import","then","mod","default","VisualEditing","Object","defineProperty","exports","enumerable","get","createDataAttribute","props","Suspense","fallback","children"],"mappings":"yUAGA,MAAMA,EAAyBC,EAAAA,MAAK,IAClCC,OAAO,gCAAgCC,MAAMC,IAAA,CAAUC,QAASD,EAAIE,oBAatEC,OAAAC,eAAAC,QAAA,sBAAA,CAAAC,YAAA,EAAAC,IAAA,WAAA,OAAAC,EAAAA,mBAAA,IAAAH,QAAAH,cANO,SAAuBO,GAE1B,aAACC,EAAAA,UAASC,SAAU,KAClBC,eAAChB,EAAwB,IAAGa,KAGlC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from '@sanity/visual-editing/remix'\nimport {lazy, type ReactElement, Suspense} from 'react'\n\nconst VisualEditingComponent = lazy(() =>\n import('@sanity/visual-editing/remix').then((mod) => ({default: mod.VisualEditing})),\n)\n\n/**\n * Enables visual editing on the front-end\n * @see https://www.sanity.io/docs/introduction-to-visual-editing\n */\nexport function VisualEditing(props: VisualEditingProps): ReactElement {\n return (\n <Suspense fallback={null}>\n <VisualEditingComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["VisualEditingComponent","lazy","import","then","mod","default","VisualEditing","Object","defineProperty","exports","enumerable","get","createDataAttribute","props","Suspense","fallback","children"],"mappings":"yUAGA,MAAMA,EAAyBC,EAAAA,MAAK,IAClCC,OAAO,gCAAgCC,MAAMC,IAAA,CAAUC,QAASD,EAAIE,oBAatEC,OAAAC,eAAAC,QAAA,sBAAA,CAAAC,YAAA,EAAAC,IAAA,WAAA,OAAAC,EAAAA,mBAAA,IAAAH,QAAAH,cANO,SAAuBO,GAE1B,aAACC,EAAAA,UAASC,SAAU,KAClBC,eAAChB,EAAwB,IAAGa,KAGlC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from '@sanity/visual-editing/remix'\nimport {lazy, type ReactElement, Suspense} from 'react'\n\nconst VisualEditingComponent = lazy(() =>\n import('@sanity/visual-editing/remix').then((mod) => ({default: mod.VisualEditing}))\n)\n\n/**\n * Enables visual editing on the front-end\n * @see https://www.sanity.io/docs/introduction-to-visual-editing\n */\nexport function VisualEditing(props: VisualEditingProps): ReactElement {\n return (\n <Suspense fallback={null}>\n <VisualEditingComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["VisualEditingComponent","lazy","import","then","mod","default","VisualEditing","props","jsx","Suspense","fallback","children"],"mappings":"sKAGA,MAAMA,EAAyBC,GAAK,IAClCC,OAAO,gCAAgCC,MAAMC,IAAA,CAAUC,QAASD,EAAIE,oBAO/D,SAASA,EAAcC,GAE1B,OAACC,EAAAC,GAASC,SAAU,KAClBC,SAACH,EAAAR,EAAwB,IAAGO,KAGlC"}
1
+ {"version":3,"file":"index.js","sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from '@sanity/visual-editing/remix'\nimport {lazy, type ReactElement, Suspense} from 'react'\n\nconst VisualEditingComponent = lazy(() =>\n import('@sanity/visual-editing/remix').then((mod) => ({default: mod.VisualEditing})),\n)\n\n/**\n * Enables visual editing on the front-end\n * @see https://www.sanity.io/docs/introduction-to-visual-editing\n */\nexport function VisualEditing(props: VisualEditingProps): ReactElement {\n return (\n <Suspense fallback={null}>\n <VisualEditingComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["VisualEditingComponent","lazy","import","then","mod","default","VisualEditing","props","jsx","Suspense","fallback","children"],"mappings":"sKAGA,MAAMA,EAAyBC,GAAK,IAClCC,OAAO,gCAAgCC,MAAMC,IAAA,CAAUC,QAASD,EAAIE,oBAO/D,SAASA,EAAcC,GAE1B,OAACC,EAAAC,GAASC,SAAU,KAClBC,SAACH,EAAAR,EAAwB,IAAGO,KAGlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hydrogen-sanity",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Sanity.io toolkit for Hydrogen",
5
5
  "keywords": [
6
6
  "sanity",
@@ -82,7 +82,7 @@
82
82
  "watch": "pkg-utils watch --strict"
83
83
  },
84
84
  "dependencies": {
85
- "@sanity/client": "^6.17.2",
85
+ "@sanity/client": "^6.18.0",
86
86
  "@sanity/react-loader": "^1.9.17",
87
87
  "@sanity/visual-editing": "^1.8.18",
88
88
  "groq": "^3.41.0"
@@ -90,24 +90,24 @@
90
90
  "devDependencies": {
91
91
  "@commitlint/cli": "^19.3.0",
92
92
  "@commitlint/config-conventional": "^19.2.2",
93
- "@sanity/pkg-utils": "^6.8.12",
94
- "@sanity/plugin-kit": "^4.0.10",
93
+ "@sanity/pkg-utils": "^6.8.13",
94
+ "@sanity/plugin-kit": "^4.0.11",
95
95
  "@sanity/semantic-release-preset": "^4.1.7",
96
- "@shopify/hydrogen": "~2024.4.0",
96
+ "@shopify/hydrogen": "~2024.4.1",
97
97
  "@shopify/remix-oxygen": "^2.0.4",
98
98
  "@types/react": "^18.3.1",
99
- "@typescript-eslint/eslint-plugin": "^5.62.0",
100
- "@typescript-eslint/parser": "^5.62.0",
99
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
100
+ "@typescript-eslint/parser": "^7.8.0",
101
101
  "eslint": "^8.57.0",
102
- "eslint-config-prettier": "^8.10.0",
103
- "eslint-config-sanity": "^6.0.0",
104
- "eslint-plugin-prettier": "^4.2.1",
102
+ "eslint-config-prettier": "^9.1.0",
103
+ "eslint-config-sanity": "^7.1.2",
104
+ "eslint-plugin-prettier": "^5.1.3",
105
105
  "eslint-plugin-react": "^7.34.1",
106
106
  "eslint-plugin-react-hooks": "^4.6.2",
107
- "eslint-plugin-simple-import-sort": "^10.0.0",
107
+ "eslint-plugin-simple-import-sort": "^12.1.0",
108
108
  "husky": "^9.0.11",
109
109
  "lint-staged": "^15.2.2",
110
- "prettier": "^2.8.8",
110
+ "prettier": "^3.2.5",
111
111
  "prettier-plugin-packagejson": "^2.5.0",
112
112
  "react": "^18.3.1",
113
113
  "react-dom": "^18.3.1",
@@ -116,7 +116,7 @@
116
116
  "vitest-github-actions-reporter": "^0.11.1"
117
117
  },
118
118
  "peerDependencies": {
119
- "@sanity/client": "^6.17.2",
119
+ "@sanity/client": "^6.18.0",
120
120
  "@shopify/hydrogen": "^2023.7.0 || ~2024.1.0 || ~2024.4.0",
121
121
  "@shopify/remix-oxygen": "^1.0.0 || ^2.0.0",
122
122
  "groq": "^3.41.0",
@@ -93,8 +93,8 @@ describe('when configured for preview', () => {
93
93
 
94
94
  it('should throw if a token is not provided', () => {
95
95
  expect(() =>
96
- // @ts-expect-error
97
- createSanityLoader({cache, waitUntil, client, preview: {enabled: true}})
96
+ // @ts-expect-error meant to test invalid configuration
97
+ createSanityLoader({cache, waitUntil, client, preview: {enabled: true}}),
98
98
  ).toThrowErrorMatchingInlineSnapshot(`[Error: Enabling preview mode requires a token.]`)
99
99
  })
100
100
 
package/src/loader.ts CHANGED
@@ -73,10 +73,11 @@ export type SanityLoader = {
73
73
  * Query Sanity using the loader.
74
74
  * @see https://www.sanity.io/docs/loaders
75
75
  */
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
77
  loadQuery<T = any>(
77
78
  query: string,
78
79
  params?: QueryParams,
79
- options?: LoadQueryOptions
80
+ options?: LoadQueryOptions,
80
81
  ): Promise<QueryResponseInitial<T>>
81
82
 
82
83
  client: SanityClient
@@ -133,7 +134,7 @@ export function createSanityLoader(options: CreateSanityLoaderOptions): SanityLo
133
134
  async loadQuery<T>(
134
135
  query: string,
135
136
  params: QueryParams | QueryWithoutParams,
136
- loaderOptions?: LoadQueryOptions
137
+ loaderOptions?: LoadQueryOptions,
137
138
  ): Promise<QueryResponseInitial<T>> {
138
139
  // Don't store response if preview is enabled
139
140
  const cacheStrategy =
@@ -144,23 +145,17 @@ export function createSanityLoader(options: CreateSanityLoaderOptions): SanityLo
144
145
  const queryHash = await hashQuery(query, params)
145
146
 
146
147
  return await withCache(queryHash, cacheStrategy, async ({addDebugData}) => {
147
- try {
148
- const result = await queryStore.loadQuery<T>(query, params, loaderOptions)
149
-
150
- // eslint-disable-next-line no-process-env
151
- if (process.env.NODE_ENV === 'development') {
152
- // Name displayed in the subrequest profiler
153
- const displayName = loaderOptions?.hydrogen?.debug?.displayName || 'query Sanity'
154
-
155
- addDebugData({
156
- displayName,
157
- })
158
- }
159
-
160
- return result
161
- } catch (error) {
162
- throw error
148
+ // eslint-disable-next-line no-process-env
149
+ if (process.env.NODE_ENV === 'development') {
150
+ // Name displayed in the subrequest profiler
151
+ const displayName = loaderOptions?.hydrogen?.debug?.displayName || 'query Sanity'
152
+
153
+ addDebugData({
154
+ displayName,
155
+ })
163
156
  }
157
+
158
+ return await queryStore.loadQuery<T>(query, params, loaderOptions)
164
159
  })
165
160
  },
166
161
  client,
package/src/utils.ts CHANGED
@@ -21,7 +21,7 @@ export async function sha256(message: string): Promise<string> {
21
21
  */
22
22
  export function hashQuery(
23
23
  query: string,
24
- params: QueryParams | QueryWithoutParams
24
+ params: QueryParams | QueryWithoutParams,
25
25
  ): Promise<string> {
26
26
  let hash = query
27
27
 
@@ -2,7 +2,7 @@ import type {VisualEditingProps} from '@sanity/visual-editing/remix'
2
2
  import {lazy, type ReactElement, Suspense} from 'react'
3
3
 
4
4
  const VisualEditingComponent = lazy(() =>
5
- import('@sanity/visual-editing/remix').then((mod) => ({default: mod.VisualEditing}))
5
+ import('@sanity/visual-editing/remix').then((mod) => ({default: mod.VisualEditing})),
6
6
  )
7
7
 
8
8
  /**