@enfyra/sdk-nuxt 0.3.19 → 0.3.21

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.
Files changed (87) hide show
  1. package/dist/module.cjs +57 -22
  2. package/dist/module.d.ts +4 -7
  3. package/dist/module.d.ts.map +1 -0
  4. package/dist/module.json +4 -1
  5. package/dist/module.mjs +56 -21
  6. package/dist/{composables → runtime/composables}/useEnfyraApi.d.ts +1 -1
  7. package/dist/runtime/composables/useEnfyraApi.d.ts.map +1 -0
  8. package/dist/{composables/useEnfyraApi.mjs → runtime/composables/useEnfyraApi.js} +6 -7
  9. package/dist/{composables → runtime/composables}/useEnfyraAuth.d.ts +1 -1
  10. package/dist/runtime/composables/useEnfyraAuth.d.ts.map +1 -0
  11. package/dist/{composables/useEnfyraAuth.mjs → runtime/composables/useEnfyraAuth.js} +1 -1
  12. package/dist/runtime/constants/auth.d.ts +4 -0
  13. package/dist/runtime/constants/auth.d.ts.map +1 -0
  14. package/dist/runtime/constants/config.d.ts.map +1 -0
  15. package/dist/runtime/plugin/config-error.client.d.ts +3 -0
  16. package/dist/runtime/plugin/config-error.client.d.ts.map +1 -0
  17. package/dist/runtime/server/api/all.d.ts +3 -0
  18. package/dist/runtime/server/api/all.d.ts.map +1 -0
  19. package/dist/runtime/server/api/all.js +1 -1
  20. package/dist/runtime/server/api/login.post.d.ts +5 -0
  21. package/dist/runtime/server/api/login.post.d.ts.map +1 -0
  22. package/dist/runtime/server/api/login.post.js +2 -2
  23. package/dist/runtime/server/api/logout.post.d.ts +3 -0
  24. package/dist/runtime/server/api/logout.post.d.ts.map +1 -0
  25. package/dist/runtime/server/api/logout.post.js +2 -2
  26. package/dist/runtime/server/middleware/auth.d.ts +3 -0
  27. package/dist/runtime/server/middleware/auth.d.ts.map +1 -0
  28. package/dist/runtime/server/middleware/auth.js +2 -2
  29. package/dist/runtime/shims.d.ts +64 -0
  30. package/dist/runtime/utils/http.d.ts.map +1 -0
  31. package/dist/runtime/utils/server/proxy.d.ts +3 -0
  32. package/dist/runtime/utils/server/proxy.d.ts.map +1 -0
  33. package/dist/{utils/server/proxy.mjs → runtime/utils/server/proxy.js} +2 -2
  34. package/dist/runtime/utils/server/refreshToken.d.ts +11 -0
  35. package/dist/runtime/utils/server/refreshToken.d.ts.map +1 -0
  36. package/dist/{utils/server/refreshToken.mjs → runtime/utils/server/refreshToken.js} +2 -2
  37. package/dist/runtime/utils/url.d.ts +4 -0
  38. package/dist/runtime/utils/url.d.ts.map +1 -0
  39. package/dist/types/index.d.ts.map +1 -1
  40. package/module.d.ts +16 -6
  41. package/package.json +12 -14
  42. package/src/module.ts +73 -34
  43. package/src/{composables → runtime/composables}/useEnfyraApi.ts +21 -23
  44. package/src/{composables → runtime/composables}/useEnfyraAuth.ts +2 -2
  45. package/src/runtime/server/api/all.ts +1 -1
  46. package/src/runtime/server/api/login.post.ts +2 -2
  47. package/src/runtime/server/api/logout.post.ts +2 -2
  48. package/src/runtime/server/middleware/auth.ts +2 -2
  49. package/src/runtime/shims.d.ts +64 -0
  50. package/src/{utils → runtime/utils}/server/proxy.ts +1 -1
  51. package/src/{utils → runtime/utils}/server/refreshToken.ts +3 -6
  52. package/src/{utils → runtime/utils}/url.ts +3 -13
  53. package/src/types/index.ts +1 -2
  54. package/dist/composables/useEnfyraApi.d.ts.map +0 -1
  55. package/dist/composables/useEnfyraApi.js +0 -363
  56. package/dist/composables/useEnfyraAuth.d.ts.map +0 -1
  57. package/dist/composables/useEnfyraAuth.js +0 -77
  58. package/dist/constants/auth.d.ts +0 -0
  59. package/dist/constants/config.d.ts.map +0 -1
  60. package/dist/constants/config.mjs +0 -1
  61. package/dist/runtime/plugin/config-error.client.mjs +0 -107
  62. package/dist/runtime/server/api/all.mjs +0 -5
  63. package/dist/runtime/server/api/login.post.mjs +0 -62
  64. package/dist/runtime/server/api/logout.post.mjs +0 -35
  65. package/dist/runtime/server/middleware/auth.mjs +0 -36
  66. package/dist/types/auth.js +0 -1
  67. package/dist/types/index.js +0 -1
  68. package/dist/utils/config.d.ts +0 -0
  69. package/dist/utils/config.mjs +0 -16
  70. package/dist/utils/http.d.ts.map +0 -1
  71. package/dist/utils/http.js +0 -57
  72. package/dist/utils/server/proxy.d.ts +0 -0
  73. package/dist/utils/server/refreshToken.d.ts +0 -0
  74. package/dist/utils/url.d.ts +0 -12
  75. package/dist/utils/url.d.ts.map +0 -1
  76. package/dist/utils/url.js +0 -77
  77. package/src/types/nuxt-imports.d.ts +0 -61
  78. package/src/utils/config.ts +0 -22
  79. /package/dist/{constants/auth.mjs → runtime/constants/auth.js} +0 -0
  80. /package/dist/{constants → runtime/constants}/config.d.ts +0 -0
  81. /package/dist/{constants → runtime/constants}/config.js +0 -0
  82. /package/dist/{utils → runtime/utils}/http.d.ts +0 -0
  83. /package/dist/{utils/http.mjs → runtime/utils/http.js} +0 -0
  84. /package/dist/{utils/url.mjs → runtime/utils/url.js} +0 -0
  85. /package/src/{constants → runtime/constants}/auth.ts +0 -0
  86. /package/src/{constants → runtime/constants}/config.ts +0 -0
  87. /package/src/{utils → runtime/utils}/http.ts +0 -0
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
+ "type": "module",
4
5
  "description": "Nuxt SDK for Enfyra CMS",
5
6
  "repository": {
6
7
  "type": "git",
7
- "url": "https://github.com/dothinh115/enfyra-sdk-nuxt.git"
8
+ "url": "https://github.com/enfyra/sdk-nuxt.git"
8
9
  },
9
10
  "bugs": {
10
- "url": "https://github.com/dothinh115/enfyra-sdk-nuxt/issues"
11
+ "url": "https://github.com/enfyra/sdk-nuxt/issues"
11
12
  },
12
- "homepage": "https://github.com/dothinh115/enfyra-sdk-nuxt#readme",
13
+ "homepage": "https://github.com/enfyra/sdk-nuxt#readme",
13
14
  "main": "./dist/module.mjs",
14
15
  "types": "./dist/types.d.ts",
15
16
  "exports": {
@@ -18,17 +19,13 @@
18
19
  "require": "./dist/module.cjs",
19
20
  "types": "./dist/types.d.ts"
20
21
  },
21
- "./src/composables/useEnfyraApi": {
22
- "types": "./src/composables/useEnfyraApi.ts",
23
- "import": "./src/composables/useEnfyraApi.ts"
24
- },
25
- "./src/composables/useEnfyraAuth": {
26
- "types": "./src/composables/useEnfyraAuth.ts",
27
- "import": "./src/composables/useEnfyraAuth.ts"
22
+ "./runtime/*": {
23
+ "types": "./dist/runtime/*.d.ts",
24
+ "import": "./dist/runtime/*.js"
28
25
  },
29
26
  "./types": {
30
- "types": "./dist/types/index.d.ts",
31
- "import": "./dist/types/index.js"
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
32
29
  }
33
30
  },
34
31
  "files": [
@@ -61,6 +58,7 @@
61
58
  "vue": "^3.0.0"
62
59
  },
63
60
  "dependencies": {
61
+ "defu": "^6.1.4",
64
62
  "h3": "^1.15.4",
65
63
  "ofetch": "^1.3.3"
66
64
  },
@@ -74,4 +72,4 @@
74
72
  "vite-plugin-dts": "^4.3.0",
75
73
  "vitest": "^3.2.4"
76
74
  }
77
- }
75
+ }
package/src/module.ts CHANGED
@@ -2,10 +2,13 @@ import {
2
2
  defineNuxtModule,
3
3
  createResolver,
4
4
  addServerHandler,
5
- addImportsDir,
5
+ addImports,
6
6
  addPlugin,
7
+ addTypeTemplate,
8
+ useLogger,
7
9
  } from "@nuxt/kit";
8
- import { ENFYRA_API_PREFIX } from "./constants/config";
10
+ import { defu } from "defu";
11
+ import { ENFYRA_API_PREFIX } from "./runtime/constants/config";
9
12
 
10
13
  export interface ModuleOptions {
11
14
  apiUrl: string;
@@ -16,12 +19,18 @@ export default defineNuxtModule<ModuleOptions>({
16
19
  meta: {
17
20
  name: "@enfyra/sdk-nuxt",
18
21
  configKey: "enfyraSDK",
22
+ compatibility: {
23
+ nuxt: ">=3.0.0",
24
+ },
19
25
  },
20
26
  defaults: {
21
27
  apiUrl: "",
22
28
  apiPrefix: ENFYRA_API_PREFIX,
23
29
  },
24
30
  setup(options, nuxt) {
31
+ const logger = useLogger("enfyra-sdk");
32
+ const { resolve } = createResolver(import.meta.url);
33
+
25
34
  const normalizedOptions = {
26
35
  ...options,
27
36
  apiUrl:
@@ -30,53 +39,84 @@ export default defineNuxtModule<ModuleOptions>({
30
39
  : options.apiUrl,
31
40
  apiPrefix:
32
41
  typeof options.apiPrefix === "string"
33
- ? (options.apiPrefix.trim()
34
- ? "/" + options.apiPrefix.replace(/^\/+|\/+$/g, "").replace(/\/+/g, "/")
35
- : ENFYRA_API_PREFIX)
42
+ ? options.apiPrefix.trim()
43
+ ? "/" +
44
+ options.apiPrefix
45
+ .replace(/^\/+|\/+$/g, "")
46
+ .replace(/\/+/g, "/")
47
+ : ENFYRA_API_PREFIX
36
48
  : ENFYRA_API_PREFIX,
37
49
  };
38
50
 
39
51
  const apiPrefix = normalizedOptions.apiPrefix;
40
- const { resolve } = createResolver(import.meta.url);
41
52
 
42
53
  if (!normalizedOptions.apiUrl) {
43
- console.warn(
44
- `[Enfyra SDK Nuxt] Missing required configuration:\n` +
45
- `- apiUrl is required\n` +
46
- `Please configure it in your nuxt.config.ts:\n` +
47
- `enfyraSDK: {\n` +
48
- ` apiUrl: 'https://your-api-url'\n` +
49
- `}`
54
+ logger.warn(
55
+ `Missing required configuration:\n` +
56
+ `- apiUrl is required\n` +
57
+ `Please configure it in your nuxt.config.ts:\n` +
58
+ `enfyraSDK: {\n` +
59
+ ` apiUrl: 'https://your-api-url'\n` +
60
+ `}`
61
+ );
62
+
63
+ nuxt.options.runtimeConfig.public.enfyraSDK = defu(
64
+ nuxt.options.runtimeConfig.public.enfyraSDK || {},
65
+ {
66
+ ...normalizedOptions,
67
+ apiPrefix: apiPrefix,
68
+ configError: true,
69
+ configErrorMessage:
70
+ "Enfyra SDK: apiUrl is required. Please configure it in nuxt.config.ts",
71
+ }
50
72
  );
51
-
52
- nuxt.options.runtimeConfig.public.enfyraSDK = {
53
- ...normalizedOptions,
54
- apiPrefix: apiPrefix,
55
- configError: true,
56
- configErrorMessage: 'Enfyra SDK: apiUrl is required. Please configure it in nuxt.config.ts'
57
- };
58
73
  } else {
59
- nuxt.options.runtimeConfig.public.enfyraSDK = {
60
- ...normalizedOptions,
61
- apiPrefix: apiPrefix,
62
- };
74
+ nuxt.options.runtimeConfig.public.enfyraSDK = defu(
75
+ nuxt.options.runtimeConfig.public.enfyraSDK || {},
76
+ {
77
+ ...normalizedOptions,
78
+ apiPrefix: apiPrefix,
79
+ }
80
+ );
63
81
  }
64
82
 
65
-
66
83
  if (!normalizedOptions.apiUrl) {
67
84
  addPlugin({
68
85
  src: resolve("./runtime/plugin/config-error.client"),
69
- mode: 'client'
86
+ mode: "client",
70
87
  });
71
88
  }
72
-
73
- addImportsDir(resolve("./composables"));
74
89
 
75
- nuxt.hook('prepare:types', ({ declarations, references }: any) => {
76
- references.push({
77
- path: resolve('./types/nuxt-imports.d.ts'),
78
- })
79
- })
90
+ addImports([
91
+ {
92
+ name: "useEnfyraApi",
93
+ from: resolve("./runtime/composables/useEnfyraApi"),
94
+ },
95
+ {
96
+ name: "useEnfyraAuth",
97
+ from: resolve("./runtime/composables/useEnfyraAuth"),
98
+ },
99
+ ]);
100
+ addTypeTemplate({
101
+ filename: "types/enfyra-sdk.d.ts",
102
+ getContents: () => `
103
+ import type { ApiOptions, UseEnfyraApiSSRReturn, UseEnfyraApiClientReturn } from '@enfyra/sdk-nuxt/types'
104
+
105
+ declare module '#imports' {
106
+ export function useEnfyraApi<T = any>(
107
+ path: (() => string) | string,
108
+ opts: ApiOptions<T> & { ssr: true }
109
+ ): UseEnfyraApiSSRReturn<T>
110
+
111
+ export function useEnfyraApi<T = any>(
112
+ path: (() => string) | string,
113
+ opts?: ApiOptions<T> & { ssr?: false | undefined }
114
+ ): UseEnfyraApiClientReturn<T>
115
+
116
+ export function useEnfyraAuth(): import('@enfyra/sdk-nuxt/types').UseEnfyraAuthReturn
117
+ }
118
+ `,
119
+ });
80
120
 
81
121
  addServerHandler({
82
122
  handler: resolve("./runtime/server/middleware/auth"),
@@ -95,7 +135,6 @@ export default defineNuxtModule<ModuleOptions>({
95
135
  method: "post",
96
136
  });
97
137
 
98
-
99
138
  addServerHandler({
100
139
  route: "/assets/**",
101
140
  handler: resolve("./runtime/server/api/all"),
@@ -1,4 +1,4 @@
1
- import { ref, unref, toRaw } from "vue";
1
+ import { ref, unref, toRaw, computed } from "vue";
2
2
  import type {
3
3
  ApiOptions,
4
4
  ApiError,
@@ -6,7 +6,7 @@ import type {
6
6
  UseEnfyraApiSSRReturn,
7
7
  UseEnfyraApiClientReturn,
8
8
  BatchProgress,
9
- } from "../types";
9
+ } from "../../types";
10
10
  import { $fetch } from "../utils/http";
11
11
  import { getAppUrl, normalizeUrl } from "../utils/url";
12
12
  import { ENFYRA_API_PREFIX } from "../constants/config";
@@ -68,13 +68,13 @@ export function useEnfyraApi<T = any>(
68
68
  const clientHeaders = process.client
69
69
  ? {}
70
70
  : useRequestHeaders([
71
- "authorization",
72
- "cookie",
73
- "user-agent",
74
- "accept",
75
- "accept-language",
76
- "referer",
77
- ]);
71
+ "authorization",
72
+ "cookie",
73
+ "user-agent",
74
+ "accept",
75
+ "accept-language",
76
+ "referer",
77
+ ]);
78
78
 
79
79
  const serverHeaders = { ...clientHeaders };
80
80
  delete serverHeaders.connection;
@@ -83,7 +83,7 @@ export function useEnfyraApi<T = any>(
83
83
  delete serverHeaders["content-length"];
84
84
 
85
85
  const nuxtApp = useNuxtApp()
86
-
86
+
87
87
  const fetchOptions: any = {
88
88
  method: method as any,
89
89
  body: body,
@@ -94,7 +94,6 @@ export function useEnfyraApi<T = any>(
94
94
  },
95
95
  };
96
96
 
97
- // Pass all useFetch-specific options
98
97
  if (key !== undefined) {
99
98
  fetchOptions.key = key;
100
99
  }
@@ -125,7 +124,6 @@ export function useEnfyraApi<T = any>(
125
124
  if (opts.getCachedData !== undefined) {
126
125
  fetchOptions.getCachedData = opts.getCachedData;
127
126
  } else {
128
- // Auto-add getCachedData to ensure cache is used in SPA navigation
129
127
  fetchOptions.getCachedData = (cacheKey: string) => {
130
128
  return nuxtApp.payload.data[cacheKey] || nuxtApp.static.data[cacheKey]
131
129
  }
@@ -141,13 +139,13 @@ export function useEnfyraApi<T = any>(
141
139
  }
142
140
 
143
141
  const result = useFetch<T>(finalUrl, fetchOptions);
142
+
144
143
 
145
- // Map pending to loading for better naming
146
- // useFetch returns AsyncData with 'pending', but UseEnfyraApiSSRReturn uses 'loading'
144
+ const loading = computed(() => result.status.value === 'pending');
145
+
147
146
  return {
148
147
  ...result,
149
- loading: result.pending,
150
- pending: result.pending, // Keep for backward compatibility
148
+ loading,
151
149
  } as UseEnfyraApiSSRReturn<T>;
152
150
  }
153
151
  const data = ref<T | null>(null);
@@ -207,13 +205,13 @@ export function useEnfyraApi<T = any>(
207
205
 
208
206
  const chunks = effectiveBatchSize
209
207
  ? Array.from(
210
- { length: Math.ceil(items.length / effectiveBatchSize) },
211
- (_, i) =>
212
- items.slice(
213
- i * effectiveBatchSize,
214
- i * effectiveBatchSize + effectiveBatchSize
215
- )
216
- )
208
+ { length: Math.ceil(items.length / effectiveBatchSize) },
209
+ (_, i) =>
210
+ items.slice(
211
+ i * effectiveBatchSize,
212
+ i * effectiveBatchSize + effectiveBatchSize
213
+ )
214
+ )
217
215
  : [items];
218
216
 
219
217
  const totalBatches = chunks.length;
@@ -1,5 +1,5 @@
1
1
  import { ref, computed } from "vue";
2
- import type { LoginPayload, User, UseEnfyraAuthReturn } from "../types/auth";
2
+ import type { LoginPayload, User, UseEnfyraAuthReturn } from "../../types/auth";
3
3
  import { useEnfyraApi } from "./useEnfyraApi";
4
4
 
5
5
  const me = ref<User | null>(null);
@@ -33,7 +33,7 @@ export function useEnfyraAuth() {
33
33
 
34
34
  try {
35
35
  const queryParams: any = {};
36
-
36
+
37
37
  if (options?.fields && options.fields.length > 0) {
38
38
  queryParams.fields = options.fields.join(",");
39
39
  }
@@ -1,5 +1,5 @@
1
1
  import { defineEventHandler } from "h3";
2
- import { proxyToAPI } from "../../../utils/server/proxy";
2
+ import { proxyToAPI } from "../../utils/server/proxy";
3
3
 
4
4
  export default defineEventHandler(async (event) => {
5
5
  return proxyToAPI(event);
@@ -12,8 +12,8 @@ import {
12
12
  ACCESS_TOKEN_KEY,
13
13
  REFRESH_TOKEN_KEY,
14
14
  EXP_TIME_KEY,
15
- } from "../../../constants/auth";
16
- import { normalizeUrl } from "../../../utils/url";
15
+ } from "../../constants/auth";
16
+ import { normalizeUrl } from "../../utils/url";
17
17
 
18
18
  export default defineEventHandler(async (event) => {
19
19
  const config = useRuntimeConfig();
@@ -5,8 +5,8 @@ import {
5
5
  ACCESS_TOKEN_KEY,
6
6
  REFRESH_TOKEN_KEY,
7
7
  EXP_TIME_KEY,
8
- } from "../../../constants/auth";
9
- import { normalizeUrl } from "../../../utils/url";
8
+ } from "../../constants/auth";
9
+ import { normalizeUrl } from "../../utils/url";
10
10
 
11
11
  export default defineEventHandler(async (event) => {
12
12
  const config = useRuntimeConfig();
@@ -3,8 +3,8 @@ import { useRuntimeConfig } from "#imports";
3
3
  import {
4
4
  validateTokens,
5
5
  refreshAccessToken,
6
- } from "../../../utils/server/refreshToken";
7
- import { REFRESH_TOKEN_KEY } from "../../../constants/auth";
6
+ } from "../../utils/server/refreshToken";
7
+ import { REFRESH_TOKEN_KEY } from "../../constants/auth";
8
8
 
9
9
  export default defineEventHandler(async (event) => {
10
10
  if (
@@ -0,0 +1,64 @@
1
+ declare module "#imports" {
2
+ export const useRuntimeConfig: () => {
3
+ public: {
4
+ enfyraSDK?: {
5
+ apiUrl?: string;
6
+ apiPrefix?: string;
7
+ configError?: boolean;
8
+ configErrorMessage?: string;
9
+ };
10
+ };
11
+ [key: string]: any;
12
+ };
13
+
14
+ export const useRequestHeaders: (
15
+ headers?: string[]
16
+ ) => Record<string, string | undefined>;
17
+
18
+ export const useRequestURL: () => URL;
19
+
20
+ export const useFetch: <T = any>(
21
+ url: string | (() => string),
22
+ options?: any
23
+ ) => any;
24
+
25
+ export const useNuxtApp: () => {
26
+ payload: {
27
+ data: Record<string, any>;
28
+ [key: string]: any;
29
+ };
30
+ static: {
31
+ data: Record<string, any>;
32
+ [key: string]: any;
33
+ };
34
+ [key: string]: any;
35
+ };
36
+
37
+ export const defineNuxtPlugin: (plugin: any) => any;
38
+
39
+ export const defineCachedEventHandler: (
40
+ handler: any,
41
+ options?: any
42
+ ) => any;
43
+ export const getCookie: (
44
+ event: any,
45
+ name: string
46
+ ) => string | undefined;
47
+ export const setCookie: (
48
+ event: any,
49
+ name: string,
50
+ value: string,
51
+ options?: any
52
+ ) => void;
53
+ export const deleteCookie: (
54
+ event: any,
55
+ name: string,
56
+ options?: any
57
+ ) => void;
58
+ export const createError: (options: {
59
+ statusCode?: number;
60
+ statusMessage?: string;
61
+ message?: string;
62
+ data?: any;
63
+ }) => Error;
64
+ }
@@ -1,7 +1,7 @@
1
1
  import { H3Event, proxyRequest } from "h3";
2
2
  import { useRuntimeConfig } from "#imports";
3
3
  import { ENFYRA_API_PREFIX } from "../../constants/config";
4
- import { normalizeUrl } from "../../utils/url";
4
+ import { normalizeUrl } from "../url";
5
5
 
6
6
  export function proxyToAPI(event: H3Event, customPath?: string) {
7
7
  const config = useRuntimeConfig();
@@ -5,7 +5,7 @@ import {
5
5
  REFRESH_TOKEN_KEY,
6
6
  EXP_TIME_KEY,
7
7
  } from "../../constants/auth";
8
- import { normalizeUrl } from "../../utils/url";
8
+ import { normalizeUrl } from "../url";
9
9
 
10
10
  interface TokenValidationResult {
11
11
  accessToken: string | null;
@@ -18,8 +18,7 @@ export function decodeJWT(token: string): any {
18
18
  if (parts.length !== 3) {
19
19
  return null;
20
20
  }
21
-
22
- // Decode the payload (second part)
21
+
23
22
  const payload = parts[1];
24
23
  const decodedPayload = Buffer.from(payload, "base64url").toString("utf-8");
25
24
  return JSON.parse(decodedPayload);
@@ -34,8 +33,7 @@ export function isAccessTokenExpired(accessToken: string): boolean {
34
33
  if (!decoded || !decoded.exp) {
35
34
  return true;
36
35
  }
37
-
38
- // JWT exp is in seconds, Date.now() is in milliseconds
36
+
39
37
  const expirationTime = decoded.exp * 1000;
40
38
  return Date.now() >= expirationTime;
41
39
  }
@@ -84,7 +82,6 @@ export async function refreshAccessToken(
84
82
  return newAccessToken;
85
83
  } catch (error) {
86
84
  console.warn("Token refresh failed:", error);
87
- // On refresh failure, clear all auth-related cookies at server side
88
85
  deleteCookie(event, ACCESS_TOKEN_KEY);
89
86
  deleteCookie(event, REFRESH_TOKEN_KEY);
90
87
  deleteCookie(event, EXP_TIME_KEY);
@@ -1,21 +1,14 @@
1
- /**
2
- * Normalizes URL segments to avoid double slashes when concatenating
3
- * Removes trailing slashes from base URL and leading slashes from path segments
4
- * Also normalizes multiple consecutive slashes within segments
5
- */
6
1
  export function normalizeUrl(...segments: (string | undefined | null)[]): string {
7
2
  const validSegments = segments.filter((s): s is string => Boolean(s));
8
3
  if (validSegments.length === 0) return '';
9
4
 
10
- // First segment is the base URL - remove trailing slashes
11
5
  let result = validSegments[0].replace(/\/+$/, '');
12
6
 
13
- // For remaining segments, remove leading and trailing slashes, normalize internal slashes, then join
14
7
  for (let i = 1; i < validSegments.length; i++) {
15
8
  const segment = validSegments[i]
16
- .replace(/^\/+/, '') // Remove leading slashes
17
- .replace(/\/+$/, '') // Remove trailing slashes
18
- .replace(/\/+/g, '/'); // Normalize multiple consecutive slashes to single slash
9
+ .replace(/^\/+/, '')
10
+ .replace(/\/+$/, '')
11
+ .replace(/\/+/g, '/');
19
12
  if (segment) {
20
13
  result += '/' + segment;
21
14
  }
@@ -24,9 +17,6 @@ export function normalizeUrl(...segments: (string | undefined | null)[]): string
24
17
  return result;
25
18
  }
26
19
 
27
- /**
28
- * Joins URL paths safely, avoiding double slashes
29
- */
30
20
  export function joinUrlPath(...paths: (string | undefined | null)[]): string {
31
21
  const validPaths = paths.filter((p): p is string => Boolean(p));
32
22
  if (validPaths.length === 0) return '';
@@ -120,9 +120,8 @@ import type { AsyncData } from 'nuxt/app';
120
120
  export interface UseEnfyraApiSSRReturn<T> extends Omit<AsyncData<T | null, ApiError>, 'pending' | 'error'> {
121
121
  data: Ref<T | null>;
122
122
  loading: Ref<boolean>;
123
- error: Ref<ApiError | null>; // Use null instead of undefined for consistency
123
+ error: Ref<ApiError | null>;
124
124
  refresh: () => Promise<void>;
125
- // Keep pending for backward compatibility, but it's an alias of loading
126
125
  pending?: Ref<boolean>;
127
126
  }
128
127
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEnfyraApi.d.ts","sourceRoot":"","sources":["../../src/composables/useEnfyraApi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EAGV,qBAAqB,EACrB,wBAAwB,EAEzB,MAAM,UAAU,CAAC;AA4BlB,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"}