@enfyra/sdk-nuxt 0.3.22 → 0.3.23

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.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.3.22",
7
+ "version": "0.3.23",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
@@ -1,7 +1,7 @@
1
1
  import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from "../../types";
2
2
  export declare function useEnfyraApi<T = any>(path: (() => string) | string, opts: ApiOptions<T> & {
3
3
  ssr: true;
4
- }): UseEnfyraApiSSRReturn<T>;
4
+ }): UseEnfyraApiSSRReturn<T> | Promise<UseEnfyraApiSSRReturn<T>>;
5
5
  export declare function useEnfyraApi<T = any>(path: (() => string) | string, opts?: ApiOptions<T> & {
6
6
  ssr?: false | undefined;
7
7
  }): UseEnfyraApiClientReturn<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"useEnfyraApi.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAGV,qBAAqB,EACrB,wBAAwB,EAEzB,MAAM,aAAa,CAAC;AA4BrB,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAClC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAE5B,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,GACjD,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"useEnfyraApi.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useEnfyraApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAGV,qBAAqB,EACrB,wBAAwB,EAEzB,MAAM,aAAa,CAAC;AA4BrB,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAClC,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhE,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EAC7B,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,GACjD,wBAAwB,CAAC,CAAC,CAAC,CAAC"}
@@ -101,10 +101,14 @@ export function useEnfyraApi(path, opts = {}) {
101
101
  }
102
102
  const result = useFetch(finalUrl, fetchOptions);
103
103
  const loading = computed(() => result.status.value === "pending");
104
- return {
104
+ const returnValue = {
105
105
  ...result,
106
106
  loading
107
107
  };
108
+ if (process.server) {
109
+ return Promise.resolve(returnValue);
110
+ }
111
+ return returnValue;
108
112
  }
109
113
  const data = ref(null);
110
114
  const error = ref(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "type": "module",
5
5
  "description": "Nuxt SDK for Enfyra CMS",
6
6
  "repository": {
@@ -37,7 +37,7 @@ function handleError(
37
37
  export function useEnfyraApi<T = any>(
38
38
  path: (() => string) | string,
39
39
  opts: ApiOptions<T> & { ssr: true }
40
- ): UseEnfyraApiSSRReturn<T>;
40
+ ): UseEnfyraApiSSRReturn<T> | Promise<UseEnfyraApiSSRReturn<T>>;
41
41
 
42
42
  export function useEnfyraApi<T = any>(
43
43
  path: (() => string) | string,
@@ -47,7 +47,7 @@ export function useEnfyraApi<T = any>(
47
47
  export function useEnfyraApi<T = any>(
48
48
  path: (() => string) | string,
49
49
  opts: ApiOptions<T> = {}
50
- ): UseEnfyraApiSSRReturn<T> | UseEnfyraApiClientReturn<T> {
50
+ ): UseEnfyraApiSSRReturn<T> | UseEnfyraApiClientReturn<T> | Promise<UseEnfyraApiSSRReturn<T>> {
51
51
  const { method = "get", body, query, errorContext, onError, ssr, key } = opts;
52
52
  const batchOptions = opts as any;
53
53
  const { batchSize, concurrent, onProgress } = batchOptions;
@@ -143,13 +143,19 @@ export function useEnfyraApi<T = any>(
143
143
 
144
144
  const result = useFetch<T>(finalUrl, fetchOptions);
145
145
 
146
-
147
146
  const loading = computed(() => result.status.value === 'pending');
148
147
 
149
- return {
148
+ const returnValue = {
150
149
  ...result,
151
150
  loading,
152
151
  } as UseEnfyraApiSSRReturn<T>;
152
+
153
+ // Ở server, return Promise để có thể await (hoặc không)
154
+ if (process.server) {
155
+ return Promise.resolve(returnValue) as Promise<UseEnfyraApiSSRReturn<T>>;
156
+ }
157
+
158
+ return returnValue;
153
159
  }
154
160
  const data = ref<T | null>(null);
155
161
  const error = ref<ApiError | null>(null);