@enfyra/sdk-nuxt 0.3.18 → 0.3.20

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 (59) hide show
  1. package/dist/auth.d.ts +43 -0
  2. package/dist/auth.d.ts.map +1 -0
  3. package/dist/auth.js +1 -0
  4. package/dist/index.d.ts +141 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/module.cjs +97 -0
  8. package/dist/module.d.cts +10 -0
  9. package/dist/module.d.mts +10 -0
  10. package/dist/module.json +12 -0
  11. package/dist/module.mjs +94 -0
  12. package/dist/runtime/composables/useEnfyraApi.d.ts +0 -0
  13. package/dist/runtime/composables/useEnfyraApi.js +345 -0
  14. package/dist/runtime/composables/useEnfyraAuth.d.ts +0 -0
  15. package/dist/runtime/composables/useEnfyraAuth.js +81 -0
  16. package/dist/runtime/constants/auth.d.ts +0 -0
  17. package/dist/runtime/constants/auth.js +3 -0
  18. package/dist/runtime/constants/config.d.ts +0 -0
  19. package/dist/runtime/constants/config.js +1 -0
  20. package/dist/runtime/server/api/all.js +1 -1
  21. package/dist/runtime/server/api/login.post.js +2 -2
  22. package/dist/runtime/server/api/logout.post.js +2 -2
  23. package/dist/runtime/server/middleware/auth.js +2 -2
  24. package/dist/runtime/shims.d.ts +72 -0
  25. package/dist/runtime/utils/http.d.ts +0 -0
  26. package/dist/runtime/utils/http.js +61 -0
  27. package/dist/runtime/utils/server/proxy.d.ts +0 -0
  28. package/dist/runtime/utils/server/proxy.js +14 -0
  29. package/dist/runtime/utils/server/refreshToken.d.ts +0 -0
  30. package/dist/runtime/utils/server/refreshToken.js +69 -0
  31. package/dist/runtime/utils/url.d.ts +0 -0
  32. package/dist/runtime/utils/url.js +56 -0
  33. package/dist/types.d.mts +7 -0
  34. package/dist/types.d.ts +7 -0
  35. package/index.ts +1 -1
  36. package/module.d.ts +16 -6
  37. package/package.json +30 -32
  38. package/src/module.ts +129 -0
  39. package/src/{composables → runtime/composables}/useEnfyraApi.ts +17 -17
  40. package/src/{composables → runtime/composables}/useEnfyraAuth.ts +2 -2
  41. package/src/runtime/server/api/all.ts +1 -1
  42. package/src/runtime/server/api/login.post.ts +2 -2
  43. package/src/runtime/server/api/logout.post.ts +2 -2
  44. package/src/runtime/server/middleware/auth.ts +2 -2
  45. package/src/runtime/shims.d.ts +72 -0
  46. package/src/{utils → runtime/utils}/server/proxy.ts +1 -1
  47. package/src/{utils → runtime/utils}/server/refreshToken.ts +3 -3
  48. package/src/{utils → runtime/utils}/url.ts +11 -4
  49. package/dist/runtime/plugin/config-error.client.mjs +0 -107
  50. package/dist/runtime/server/api/all.mjs +0 -5
  51. package/dist/runtime/server/api/login.post.mjs +0 -62
  52. package/dist/runtime/server/api/logout.post.mjs +0 -35
  53. package/dist/runtime/server/middleware/auth.mjs +0 -36
  54. package/module.ts +0 -110
  55. package/src/types/nuxt-imports.d.ts +0 -61
  56. package/src/utils/config.ts +0 -22
  57. /package/src/{constants → runtime/constants}/auth.ts +0 -0
  58. /package/src/{constants → runtime/constants}/config.ts +0 -0
  59. /package/src/{utils → runtime/utils}/http.ts +0 -0
@@ -0,0 +1,69 @@
1
+ import { setCookie, getCookie, deleteCookie } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ import {
4
+ ACCESS_TOKEN_KEY,
5
+ REFRESH_TOKEN_KEY,
6
+ EXP_TIME_KEY
7
+ } from "../../constants/auth.js";
8
+ import { normalizeUrl } from "../url.js";
9
+ export function decodeJWT(token) {
10
+ try {
11
+ const parts = token.split(".");
12
+ if (parts.length !== 3) {
13
+ return null;
14
+ }
15
+ const payload = parts[1];
16
+ const decodedPayload = Buffer.from(payload, "base64url").toString("utf-8");
17
+ return JSON.parse(decodedPayload);
18
+ } catch (error) {
19
+ console.warn("Failed to decode JWT:", error);
20
+ return null;
21
+ }
22
+ }
23
+ export function isAccessTokenExpired(accessToken) {
24
+ const decoded = decodeJWT(accessToken);
25
+ if (!decoded || !decoded.exp) {
26
+ return true;
27
+ }
28
+ const expirationTime = decoded.exp * 1e3;
29
+ return Date.now() >= expirationTime;
30
+ }
31
+ export function validateTokens(event) {
32
+ const accessToken = getCookie(event, ACCESS_TOKEN_KEY);
33
+ const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
34
+ if (accessToken && !isAccessTokenExpired(accessToken)) {
35
+ return { accessToken, needsRefresh: false };
36
+ } else if (refreshToken && (!accessToken || isAccessTokenExpired(accessToken))) {
37
+ return { accessToken: null, needsRefresh: true };
38
+ }
39
+ return { accessToken: null, needsRefresh: false };
40
+ }
41
+ export async function refreshAccessToken(event, refreshToken, apiUrl) {
42
+ try {
43
+ const response = await $fetch(normalizeUrl(apiUrl, "/auth/refresh-token"), {
44
+ method: "POST",
45
+ body: { refreshToken }
46
+ });
47
+ const {
48
+ accessToken: newAccessToken,
49
+ refreshToken: newRefreshToken,
50
+ expTime: newExpTime
51
+ } = response;
52
+ const cookieOptions = {
53
+ httpOnly: true,
54
+ secure: true,
55
+ sameSite: "lax",
56
+ path: "/"
57
+ };
58
+ setCookie(event, ACCESS_TOKEN_KEY, newAccessToken, cookieOptions);
59
+ setCookie(event, REFRESH_TOKEN_KEY, newRefreshToken, cookieOptions);
60
+ setCookie(event, EXP_TIME_KEY, String(newExpTime), cookieOptions);
61
+ return newAccessToken;
62
+ } catch (error) {
63
+ console.warn("Token refresh failed:", error);
64
+ deleteCookie(event, ACCESS_TOKEN_KEY);
65
+ deleteCookie(event, REFRESH_TOKEN_KEY);
66
+ deleteCookie(event, EXP_TIME_KEY);
67
+ throw error;
68
+ }
69
+ }
File without changes
@@ -0,0 +1,56 @@
1
+ export function normalizeUrl(...segments) {
2
+ const validSegments = segments.filter((s) => Boolean(s));
3
+ if (validSegments.length === 0) return "";
4
+ let result = validSegments[0].replace(/\/+$/, "");
5
+ for (let i = 1; i < validSegments.length; i++) {
6
+ const segment = validSegments[i].replace(/^\/+/, "").replace(/\/+$/, "").replace(/\/+/g, "/");
7
+ if (segment) {
8
+ result += "/" + segment;
9
+ }
10
+ }
11
+ return result;
12
+ }
13
+ export function joinUrlPath(...paths) {
14
+ const validPaths = paths.filter((p) => Boolean(p));
15
+ if (validPaths.length === 0) return "";
16
+ return validPaths.map((path) => path.replace(/^\/+/, "").replace(/\/+$/, "")).filter(Boolean).join("/");
17
+ }
18
+ export function getAppUrl() {
19
+ if (process.client && typeof window !== "undefined") {
20
+ return window.location.origin;
21
+ }
22
+ if (process.server) {
23
+ try {
24
+ let useRequestHeaders;
25
+ let useRequestURL;
26
+ try {
27
+ const imports = eval('require("#imports")');
28
+ useRequestHeaders = imports.useRequestHeaders;
29
+ useRequestURL = imports.useRequestURL;
30
+ } catch (e) {
31
+ return "";
32
+ }
33
+ try {
34
+ const url = useRequestURL();
35
+ if (url) {
36
+ return `${url.protocol}//${url.host}`;
37
+ }
38
+ } catch (e) {
39
+ }
40
+ const headers = useRequestHeaders();
41
+ const forwarded = headers["x-forwarded-host"] || headers["x-forwarded-server"];
42
+ const protocol = headers["x-forwarded-proto"] || "https";
43
+ if (forwarded) {
44
+ return `${protocol}://${forwarded}`;
45
+ }
46
+ const host = headers.host;
47
+ if (host) {
48
+ const isHttps = protocol === "https" || headers["x-forwarded-ssl"] === "on";
49
+ return `${isHttps ? "https" : "http"}://${host}`;
50
+ }
51
+ } catch (e) {
52
+ console.warn("[Enfyra SDK] Could not auto-detect app URL on server:", e);
53
+ }
54
+ }
55
+ return "";
56
+ }
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.js'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.js'
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module'
package/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './module'
1
+ export * from './src/module'
2
2
  export * from './src/types'
3
3
 
package/module.d.ts CHANGED
@@ -1,14 +1,24 @@
1
- import type { ModuleOptions } from './module'
1
+ import type { ModuleOptions } from "./src/module";
2
2
 
3
- declare module '@nuxt/schema' {
3
+ declare module "@nuxt/schema" {
4
4
  interface NuxtConfig {
5
- enfyraSDK?: ModuleOptions
5
+ enfyraSDK?: ModuleOptions;
6
6
  }
7
7
  interface NuxtOptions {
8
- enfyraSDK?: ModuleOptions
8
+ enfyraSDK?: ModuleOptions;
9
+ }
10
+ interface PublicRuntimeConfig {
11
+ enfyraSDK?: ModuleOptions & {
12
+ configError?: boolean;
13
+ configErrorMessage?: string;
14
+ };
9
15
  }
10
16
  }
11
17
 
12
- export type { ModuleOptions } from './module'
13
- export type * from './src/types'
18
+ declare module "#imports" {
19
+ export const useEnfyraApi: typeof import("./src/runtime/composables/useEnfyraApi").useEnfyraApi;
20
+ export const useEnfyraAuth: typeof import("./src/runtime/composables/useEnfyraAuth").useEnfyraAuth;
21
+ }
14
22
 
23
+ export type { ModuleOptions } from "./src/module";
24
+ export type * from "./src/types";
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@enfyra/sdk-nuxt",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
+ "type": "module",
4
5
  "description": "Nuxt SDK for Enfyra CMS",
5
6
  "repository": {
6
7
  "type": "git",
@@ -10,40 +11,28 @@
10
11
  "url": "https://github.com/dothinh115/enfyra-sdk-nuxt/issues"
11
12
  },
12
13
  "homepage": "https://github.com/dothinh115/enfyra-sdk-nuxt#readme",
13
- "main": "./module.ts",
14
- "types": "./module.d.ts",
14
+ "main": "./dist/module.mjs",
15
+ "types": "./dist/types.d.ts",
15
16
  "exports": {
16
17
  ".": {
17
- "types": "./module.d.ts",
18
- "import": "./module.ts"
18
+ "import": "./dist/module.mjs",
19
+ "require": "./dist/module.cjs",
20
+ "types": "./dist/types.d.ts"
19
21
  },
20
- "./src/composables/useEnfyraApi": {
21
- "types": "./src/composables/useEnfyraApi.ts",
22
- "import": "./src/composables/useEnfyraApi.ts"
22
+ "./runtime/*": {
23
+ "types": "./dist/runtime/*.d.ts",
24
+ "import": "./dist/runtime/*.js"
23
25
  },
24
- "./src/composables/useEnfyraAuth": {
25
- "types": "./src/composables/useEnfyraAuth.ts",
26
- "import": "./src/composables/useEnfyraAuth.ts"
27
- },
28
- "./src/types": {
29
- "types": "./src/types/index.ts",
30
- "import": "./src/types/index.ts"
31
- },
32
- "./src/runtime/server/api/all": "./src/runtime/server/api/all.ts",
33
- "./src/runtime/server/api/all.ts": "./src/runtime/server/api/all.ts",
34
- "./src/runtime/server/api/login.post": "./src/runtime/server/api/login.post.ts",
35
- "./src/runtime/server/api/login.post.ts": "./src/runtime/server/api/login.post.ts",
36
- "./src/runtime/server/api/logout.post": "./src/runtime/server/api/logout.post.ts",
37
- "./src/runtime/server/api/logout.post.ts": "./src/runtime/server/api/logout.post.ts",
38
- "./src/runtime/server/middleware/auth": "./src/runtime/server/middleware/auth.ts",
39
- "./src/runtime/server/middleware/auth.ts": "./src/runtime/server/middleware/auth.ts"
26
+ "./types": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
40
30
  },
41
31
  "files": [
42
- "module.ts",
32
+ "dist/",
33
+ "src/",
43
34
  "module.d.ts",
44
- "index.ts",
45
- "src/**/*",
46
- "dist/runtime/**/*"
35
+ "index.ts"
47
36
  ],
48
37
  "keywords": [
49
38
  "nuxt",
@@ -57,21 +46,30 @@
57
46
  "access": "public"
58
47
  },
59
48
  "scripts": {
60
- "build": "unbuild && npx tsc --noEmit --skipLibCheck",
61
- "prepublishOnly": "unbuild"
49
+ "dev": "nuxi dev playground",
50
+ "build": "nuxt-module-build build && npx tsc -p tsconfig.build.json",
51
+ "prepack": "nuxt-module-build build && npx tsc -p tsconfig.build.json",
52
+ "test": "vitest",
53
+ "test:ui": "vitest --ui",
54
+ "test:run": "vitest run"
62
55
  },
63
56
  "peerDependencies": {
64
57
  "@nuxt/kit": "^3.18.1",
65
58
  "vue": "^3.0.0"
66
59
  },
67
60
  "dependencies": {
61
+ "defu": "^6.1.4",
68
62
  "h3": "^1.15.4",
69
63
  "ofetch": "^1.3.3"
70
64
  },
71
65
  "devDependencies": {
66
+ "@nuxt/module-builder": "^0.8.4",
72
67
  "@types/node": "^24.10.1",
68
+ "@vitest/ui": "^3.2.4",
73
69
  "nuxt": "^3.18.1",
74
70
  "typescript": "^5.0.0",
75
- "unbuild": "^2.0.0"
71
+ "vite": "^6.0.7",
72
+ "vite-plugin-dts": "^4.3.0",
73
+ "vitest": "^3.2.4"
76
74
  }
77
- }
75
+ }
package/src/module.ts ADDED
@@ -0,0 +1,129 @@
1
+ import {
2
+ defineNuxtModule,
3
+ createResolver,
4
+ addServerHandler,
5
+ addImports,
6
+ addPlugin,
7
+ useLogger,
8
+ } from "@nuxt/kit";
9
+ import { defu } from "defu";
10
+ import { ENFYRA_API_PREFIX } from "./runtime/constants/config";
11
+
12
+ export interface ModuleOptions {
13
+ apiUrl: string;
14
+ apiPrefix?: string;
15
+ }
16
+
17
+ export default defineNuxtModule<ModuleOptions>({
18
+ meta: {
19
+ name: "@enfyra/sdk-nuxt",
20
+ configKey: "enfyraSDK",
21
+ compatibility: {
22
+ nuxt: ">=3.0.0",
23
+ },
24
+ },
25
+ defaults: {
26
+ apiUrl: "",
27
+ apiPrefix: ENFYRA_API_PREFIX,
28
+ },
29
+ setup(options, nuxt) {
30
+ const logger = useLogger("enfyra-sdk");
31
+ const { resolve } = createResolver(import.meta.url);
32
+
33
+ const normalizedOptions = {
34
+ ...options,
35
+ apiUrl:
36
+ typeof options.apiUrl === "string"
37
+ ? options.apiUrl.replace(/\/+$/, "")
38
+ : options.apiUrl,
39
+ apiPrefix:
40
+ typeof options.apiPrefix === "string"
41
+ ? options.apiPrefix.trim()
42
+ ? "/" +
43
+ options.apiPrefix
44
+ .replace(/^\/+|\/+$/g, "")
45
+ .replace(/\/+/g, "/")
46
+ : ENFYRA_API_PREFIX
47
+ : ENFYRA_API_PREFIX,
48
+ };
49
+
50
+ const apiPrefix = normalizedOptions.apiPrefix;
51
+
52
+ if (!normalizedOptions.apiUrl) {
53
+ logger.warn(
54
+ `Missing required configuration:\n` +
55
+ `- apiUrl is required\n` +
56
+ `Please configure it in your nuxt.config.ts:\n` +
57
+ `enfyraSDK: {\n` +
58
+ ` apiUrl: 'https://your-api-url'\n` +
59
+ `}`
60
+ );
61
+
62
+ nuxt.options.runtimeConfig.public.enfyraSDK = defu(
63
+ nuxt.options.runtimeConfig.public.enfyraSDK || {},
64
+ {
65
+ ...normalizedOptions,
66
+ apiPrefix: apiPrefix,
67
+ configError: true,
68
+ configErrorMessage:
69
+ "Enfyra SDK: apiUrl is required. Please configure it in nuxt.config.ts",
70
+ }
71
+ );
72
+ } else {
73
+ nuxt.options.runtimeConfig.public.enfyraSDK = defu(
74
+ nuxt.options.runtimeConfig.public.enfyraSDK || {},
75
+ {
76
+ ...normalizedOptions,
77
+ apiPrefix: apiPrefix,
78
+ }
79
+ );
80
+ }
81
+
82
+ if (!normalizedOptions.apiUrl) {
83
+ addPlugin({
84
+ src: resolve("./runtime/plugin/config-error.client"),
85
+ mode: "client",
86
+ });
87
+ }
88
+
89
+ // Register composables for auto-import with explicit declarations
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
+
101
+ // Server handlers
102
+ addServerHandler({
103
+ handler: resolve("./runtime/server/middleware/auth"),
104
+ middleware: true,
105
+ });
106
+
107
+ addServerHandler({
108
+ route: `${apiPrefix}/login`,
109
+ handler: resolve("./runtime/server/api/login.post"),
110
+ method: "post",
111
+ });
112
+
113
+ addServerHandler({
114
+ route: `${apiPrefix}/logout`,
115
+ handler: resolve("./runtime/server/api/logout.post"),
116
+ method: "post",
117
+ });
118
+
119
+ addServerHandler({
120
+ route: "/assets/**",
121
+ handler: resolve("./runtime/server/api/all"),
122
+ });
123
+
124
+ addServerHandler({
125
+ route: `${apiPrefix}/**`,
126
+ handler: resolve("./runtime/server/api/all"),
127
+ });
128
+ },
129
+ });
@@ -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,
@@ -141,7 +141,7 @@ export function useEnfyraApi<T = any>(
141
141
  }
142
142
 
143
143
  const result = useFetch<T>(finalUrl, fetchOptions);
144
-
144
+
145
145
  // Map pending to loading for better naming
146
146
  // useFetch returns AsyncData with 'pending', but UseEnfyraApiSSRReturn uses 'loading'
147
147
  return {
@@ -207,13 +207,13 @@ export function useEnfyraApi<T = any>(
207
207
 
208
208
  const chunks = effectiveBatchSize
209
209
  ? Array.from(
210
- { length: Math.ceil(items.length / effectiveBatchSize) },
211
- (_, i) =>
212
- items.slice(
213
- i * effectiveBatchSize,
214
- i * effectiveBatchSize + effectiveBatchSize
215
- )
216
- )
210
+ { length: Math.ceil(items.length / effectiveBatchSize) },
211
+ (_, i) =>
212
+ items.slice(
213
+ i * effectiveBatchSize,
214
+ i * effectiveBatchSize + effectiveBatchSize
215
+ )
216
+ )
217
217
  : [items];
218
218
 
219
219
  const totalBatches = chunks.length;
@@ -1,5 +1,5 @@
1
1
  import { ref, computed } from "vue";
2
- import type { LoginPayload, User } 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,72 @@
1
+ /**
2
+ * Type shims for Nuxt auto-imports used in module runtime.
3
+ * These types are provided by Nuxt at runtime but need declarations for TypeScript.
4
+ */
5
+
6
+ declare module "#imports" {
7
+ // Nuxt composables
8
+ export const useRuntimeConfig: () => {
9
+ public: {
10
+ enfyraSDK?: {
11
+ apiUrl?: string;
12
+ apiPrefix?: string;
13
+ configError?: boolean;
14
+ configErrorMessage?: string;
15
+ };
16
+ };
17
+ [key: string]: any;
18
+ };
19
+
20
+ export const useRequestHeaders: (
21
+ headers?: string[]
22
+ ) => Record<string, string | undefined>;
23
+
24
+ export const useRequestURL: () => URL;
25
+
26
+ export const useFetch: <T = any>(
27
+ url: string | (() => string),
28
+ options?: any
29
+ ) => any;
30
+
31
+ export const useNuxtApp: () => {
32
+ payload: {
33
+ data: Record<string, any>;
34
+ [key: string]: any;
35
+ };
36
+ static: {
37
+ data: Record<string, any>;
38
+ [key: string]: any;
39
+ };
40
+ [key: string]: any;
41
+ };
42
+
43
+ // Nuxt plugin
44
+ export const defineNuxtPlugin: (plugin: any) => any;
45
+
46
+ // Server utilities (from nitro)
47
+ export const defineCachedEventHandler: (
48
+ handler: any,
49
+ options?: any
50
+ ) => any;
51
+ export const getCookie: (
52
+ event: any,
53
+ name: string
54
+ ) => string | undefined;
55
+ export const setCookie: (
56
+ event: any,
57
+ name: string,
58
+ value: string,
59
+ options?: any
60
+ ) => void;
61
+ export const deleteCookie: (
62
+ event: any,
63
+ name: string,
64
+ options?: any
65
+ ) => void;
66
+ export const createError: (options: {
67
+ statusCode?: number;
68
+ statusMessage?: string;
69
+ message?: string;
70
+ data?: any;
71
+ }) => Error;
72
+ }
@@ -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,7 +18,7 @@ export function decodeJWT(token: string): any {
18
18
  if (parts.length !== 3) {
19
19
  return null;
20
20
  }
21
-
21
+
22
22
  // Decode the payload (second part)
23
23
  const payload = parts[1];
24
24
  const decodedPayload = Buffer.from(payload, "base64url").toString("utf-8");
@@ -34,7 +34,7 @@ export function isAccessTokenExpired(accessToken: string): boolean {
34
34
  if (!decoded || !decoded.exp) {
35
35
  return true;
36
36
  }
37
-
37
+
38
38
  // JWT exp is in seconds, Date.now() is in milliseconds
39
39
  const expirationTime = decoded.exp * 1000;
40
40
  return Date.now() >= expirationTime;