@enfyra/sdk-nuxt 0.3.14 → 0.3.15
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.
|
@@ -2,7 +2,7 @@ import { ref, unref, toRaw } from "vue";
|
|
|
2
2
|
import { $fetch } from "../utils/http";
|
|
3
3
|
import { getAppUrl, normalizeUrl } from "../utils/url";
|
|
4
4
|
import { ENFYRA_API_PREFIX } from "../constants/config";
|
|
5
|
-
import { useRuntimeConfig, useFetch, useRequestHeaders } from "#imports";
|
|
5
|
+
import { useRuntimeConfig, useFetch, useRequestHeaders, useNuxtApp } from "#imports";
|
|
6
6
|
function handleError(error, context, customHandler) {
|
|
7
7
|
const apiError = {
|
|
8
8
|
message: error?.message || error?.data?.message || "Request failed",
|
|
@@ -43,6 +43,7 @@ export function useEnfyraApi(path, opts = {}) {
|
|
|
43
43
|
delete serverHeaders["keep-alive"];
|
|
44
44
|
delete serverHeaders.host;
|
|
45
45
|
delete serverHeaders["content-length"];
|
|
46
|
+
const nuxtApp = useNuxtApp();
|
|
46
47
|
const fetchOptions = {
|
|
47
48
|
method,
|
|
48
49
|
body,
|
|
@@ -81,6 +82,10 @@ export function useEnfyraApi(path, opts = {}) {
|
|
|
81
82
|
}
|
|
82
83
|
if (opts.getCachedData !== void 0) {
|
|
83
84
|
fetchOptions.getCachedData = opts.getCachedData;
|
|
85
|
+
} else {
|
|
86
|
+
fetchOptions.getCachedData = (cacheKey) => {
|
|
87
|
+
return nuxtApp.payload.data[cacheKey] || nuxtApp.static.data[cacheKey];
|
|
88
|
+
};
|
|
84
89
|
}
|
|
85
90
|
if (opts.refresh !== void 0) {
|
|
86
91
|
fetchOptions.refresh = opts.refresh;
|
package/dist/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enfyra/sdk-nuxt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "Nuxt SDK for Enfyra CMS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@nuxt/module-builder": "^0.8.4",
|
|
55
|
+
"@types/node": "^24.10.1",
|
|
55
56
|
"@vitest/ui": "^3.2.4",
|
|
56
57
|
"nuxt": "^3.18.1",
|
|
57
58
|
"typescript": "^5.0.0",
|
|
@@ -11,7 +11,7 @@ import { $fetch } from "../utils/http";
|
|
|
11
11
|
import { getAppUrl, normalizeUrl } from "../utils/url";
|
|
12
12
|
import { ENFYRA_API_PREFIX } from "../constants/config";
|
|
13
13
|
|
|
14
|
-
import { useRuntimeConfig, useFetch, useRequestHeaders } from "#imports";
|
|
14
|
+
import { useRuntimeConfig, useFetch, useRequestHeaders, useNuxtApp } from "#imports";
|
|
15
15
|
|
|
16
16
|
function handleError(
|
|
17
17
|
error: any,
|
|
@@ -82,6 +82,8 @@ export function useEnfyraApi<T = any>(
|
|
|
82
82
|
delete serverHeaders.host;
|
|
83
83
|
delete serverHeaders["content-length"];
|
|
84
84
|
|
|
85
|
+
const nuxtApp = useNuxtApp()
|
|
86
|
+
|
|
85
87
|
const fetchOptions: any = {
|
|
86
88
|
method: method as any,
|
|
87
89
|
body: body,
|
|
@@ -122,6 +124,11 @@ export function useEnfyraApi<T = any>(
|
|
|
122
124
|
}
|
|
123
125
|
if (opts.getCachedData !== undefined) {
|
|
124
126
|
fetchOptions.getCachedData = opts.getCachedData;
|
|
127
|
+
} else {
|
|
128
|
+
// Auto-add getCachedData to ensure cache is used in SPA navigation
|
|
129
|
+
fetchOptions.getCachedData = (cacheKey: string) => {
|
|
130
|
+
return nuxtApp.payload.data[cacheKey] || nuxtApp.static.data[cacheKey]
|
|
131
|
+
}
|
|
125
132
|
}
|
|
126
133
|
if (opts.refresh !== undefined) {
|
|
127
134
|
fetchOptions.refresh = opts.refresh;
|
|
@@ -25,6 +25,18 @@ declare module '#imports' {
|
|
|
25
25
|
options?: any
|
|
26
26
|
) => any;
|
|
27
27
|
|
|
28
|
+
export const useNuxtApp: () => {
|
|
29
|
+
payload: {
|
|
30
|
+
data: Record<string, any>;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
static: {
|
|
34
|
+
data: Record<string, any>;
|
|
35
|
+
[key: string]: any;
|
|
36
|
+
};
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
};
|
|
39
|
+
|
|
28
40
|
export const defineNuxtPlugin: (plugin: any) => any;
|
|
29
41
|
|
|
30
42
|
export const defineCachedEventHandler: (handler: any, options?: any) => any;
|