@devite/nuxt-sanity 2.4.2 → 2.4.3

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/module.d.mts CHANGED
@@ -10,7 +10,16 @@ type ModuleOptions = ClientConfig & {
10
10
  /** @default { cachingEnabled: true, cacheBaseUrl: "http://localhost:3000", assetEndpoint: "/_sanity/cache/asset", queryEndpoint: "/_sanity/cache/query", webhookEndpoint: "/_sanity/cache/invalidate" } */
11
11
  minimalClient?: boolean | {
12
12
  cachingEnabled?: boolean;
13
- cacheBaseUrl?: string;
13
+ /**
14
+ * This is the base url for fetching data after hydration
15
+ * @default 'http://localhost:3000'
16
+ */
17
+ cacheClientBaseUrl?: string;
18
+ /**
19
+ * This is the base url for fetching data during SSR
20
+ * @default 'http://localhost:3000'
21
+ */
22
+ cacheServerBaseUrl?: string;
14
23
  assetEndpoint?: string;
15
24
  queryEndpoint?: string;
16
25
  webhookEndpoint?: string;
package/dist/module.d.ts CHANGED
@@ -10,7 +10,16 @@ type ModuleOptions = ClientConfig & {
10
10
  /** @default { cachingEnabled: true, cacheBaseUrl: "http://localhost:3000", assetEndpoint: "/_sanity/cache/asset", queryEndpoint: "/_sanity/cache/query", webhookEndpoint: "/_sanity/cache/invalidate" } */
11
11
  minimalClient?: boolean | {
12
12
  cachingEnabled?: boolean;
13
- cacheBaseUrl?: string;
13
+ /**
14
+ * This is the base url for fetching data after hydration
15
+ * @default 'http://localhost:3000'
16
+ */
17
+ cacheClientBaseUrl?: string;
18
+ /**
19
+ * This is the base url for fetching data during SSR
20
+ * @default 'http://localhost:3000'
21
+ */
22
+ cacheServerBaseUrl?: string;
14
23
  assetEndpoint?: string;
15
24
  queryEndpoint?: string;
16
25
  webhookEndpoint?: string;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "configKey": "sanity",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addImpor
3
3
  import defu from 'defu';
4
4
 
5
5
  const name = "@devite/nuxt-sanity";
6
- const version = "2.4.2";
6
+ const version = "2.4.3";
7
7
 
8
8
  const CONFIG_KEY = "sanity";
9
9
  const module = defineNuxtModule({
@@ -21,7 +21,8 @@ const module = defineNuxtModule({
21
21
  dataset: options.dataset || "production",
22
22
  minimalClient: options.minimalClient !== false ? defu(options.minimalClient, {
23
23
  cachingEnabled: true,
24
- cacheBaseUrl: "http://localhost:3000",
24
+ cacheClientBaseUrl: "http://localhost:3000",
25
+ cacheServerBaseUrl: "http://localhost:3000",
25
26
  assetEndpoint: "/_sanity/cache/asset",
26
27
  queryEndpoint: "/_sanity/cache/query",
27
28
  webhookEndpoint: "/_sanity/cache/invalidate"
@@ -39,7 +39,8 @@ class MinimalSanityClient extends SanityClient {
39
39
  const isEligibleForGetRequest = byteLength <= 9e3;
40
40
  const minimalClientConfig = typeof this.config.minimalClient === "object" ? this.config.minimalClient : {};
41
41
  const useCache = minimalClientConfig.cachingEnabled && isEligibleForGetRequest;
42
- const requestUrl = useCache && minimalClientConfig.cacheBaseUrl ? minimalClientConfig.cacheBaseUrl + minimalClientConfig.queryEndpoint : `https://${this.config.projectId}.${this.config.useCdn && isEligibleForGetRequest ? API_CDN_HOST : API_HOST}${this.queryPath}`;
42
+ const cacheBaseUrl = import.meta.client ? minimalClientConfig.cacheClientBaseUrl : minimalClientConfig.cacheServerBaseUrl;
43
+ const requestUrl = useCache && cacheBaseUrl ? cacheBaseUrl + minimalClientConfig.queryEndpoint : `https://${this.config.projectId}.${this.config.useCdn && isEligibleForGetRequest ? API_CDN_HOST : API_HOST}${this.queryPath}`;
43
44
  return (await $fetch(requestUrl + queryString, {
44
45
  ...this.fetchOptions,
45
46
  method: isEligibleForGetRequest ? "GET" : "POST",
@@ -6,11 +6,11 @@ export const getImage = (src, { modifiers = {} } = {}, ctx) => {
6
6
  const sanityConfig = useRuntimeConfig().public.sanity;
7
7
  const minimalClientConfig = sanityConfig.minimalClient;
8
8
  const useCaching = typeof minimalClientConfig === "object" && minimalClientConfig.cachingEnabled;
9
- if (useCaching && minimalClientConfig.cacheBaseUrl && !useSanityVisualEditingState().enabled) {
9
+ if (useCaching && minimalClientConfig.cacheClientBaseUrl && !useSanityVisualEditingState().enabled) {
10
10
  const params = new URLSearchParams();
11
11
  params.set("src", src);
12
12
  params.set("modifiers", JSON.stringify(modifiers));
13
- return { url: joinURL(minimalClientConfig.cacheBaseUrl, minimalClientConfig.assetEndpoint + `?${params.toString()}`) };
13
+ return { url: joinURL(minimalClientConfig.cacheClientBaseUrl, minimalClientConfig.assetEndpoint + `?${params.toString()}`) };
14
14
  }
15
15
  return getSanityImage(src, { modifiers, projectId: sanityConfig.projectId, dataset: sanityConfig.dataset }, ctx);
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",