@enfyra/sdk-nuxt 0.3.19 → 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.
- package/dist/auth.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/module.cjs +38 -23
- package/dist/module.json +4 -1
- package/dist/module.mjs +37 -22
- package/dist/{composables/useEnfyraApi.mjs → runtime/composables/useEnfyraApi.js} +3 -3
- package/dist/{composables/useEnfyraAuth.mjs → runtime/composables/useEnfyraAuth.js} +1 -1
- package/dist/runtime/server/api/all.js +1 -1
- package/dist/runtime/server/api/login.post.js +2 -2
- package/dist/runtime/server/api/logout.post.js +2 -2
- package/dist/runtime/server/middleware/auth.js +2 -2
- package/dist/runtime/shims.d.ts +72 -0
- package/dist/runtime/utils/http.d.ts +0 -0
- package/dist/runtime/utils/server/proxy.d.ts +0 -0
- package/dist/{utils/server/proxy.mjs → runtime/utils/server/proxy.js} +2 -2
- package/dist/runtime/utils/server/refreshToken.d.ts +0 -0
- package/dist/{utils/server/refreshToken.mjs → runtime/utils/server/refreshToken.js} +2 -2
- package/dist/runtime/utils/url.d.ts +0 -0
- package/module.d.ts +16 -6
- package/package.json +9 -11
- package/src/module.ts +54 -34
- package/src/{composables → runtime/composables}/useEnfyraApi.ts +17 -17
- package/src/{composables → runtime/composables}/useEnfyraAuth.ts +2 -2
- package/src/runtime/server/api/all.ts +1 -1
- package/src/runtime/server/api/login.post.ts +2 -2
- package/src/runtime/server/api/logout.post.ts +2 -2
- package/src/runtime/server/middleware/auth.ts +2 -2
- package/src/runtime/shims.d.ts +72 -0
- package/src/{utils → runtime/utils}/server/proxy.ts +1 -1
- package/src/{utils → runtime/utils}/server/refreshToken.ts +3 -3
- package/dist/composables/useEnfyraApi.d.ts +0 -8
- package/dist/composables/useEnfyraApi.d.ts.map +0 -1
- package/dist/composables/useEnfyraApi.js +0 -363
- package/dist/composables/useEnfyraAuth.d.ts +0 -89
- package/dist/composables/useEnfyraAuth.d.ts.map +0 -1
- package/dist/composables/useEnfyraAuth.js +0 -77
- package/dist/constants/config.d.ts +0 -2
- package/dist/constants/config.d.ts.map +0 -1
- package/dist/constants/config.mjs +0 -1
- package/dist/runtime/plugin/config-error.client.mjs +0 -107
- package/dist/runtime/server/api/all.mjs +0 -5
- package/dist/runtime/server/api/login.post.mjs +0 -62
- package/dist/runtime/server/api/logout.post.mjs +0 -35
- package/dist/runtime/server/middleware/auth.mjs +0 -36
- package/dist/types/auth.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/config.mjs +0 -16
- package/dist/utils/http.d.ts +0 -8
- package/dist/utils/http.d.ts.map +0 -1
- package/dist/utils/http.js +0 -57
- package/dist/utils/url.d.ts +0 -12
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/url.js +0 -77
- package/src/types/nuxt-imports.d.ts +0 -61
- package/src/utils/config.ts +0 -22
- /package/dist/{types/auth.d.ts → auth.d.ts} +0 -0
- /package/dist/{types/auth.js → auth.js} +0 -0
- /package/dist/{types/index.d.ts → index.d.ts} +0 -0
- /package/dist/{types/index.js → index.js} +0 -0
- /package/dist/{constants/auth.d.ts → runtime/composables/useEnfyraApi.d.ts} +0 -0
- /package/dist/{utils/config.d.ts → runtime/composables/useEnfyraAuth.d.ts} +0 -0
- /package/dist/{utils/server/proxy.d.ts → runtime/constants/auth.d.ts} +0 -0
- /package/dist/{constants/auth.mjs → runtime/constants/auth.js} +0 -0
- /package/dist/{utils/server/refreshToken.d.ts → runtime/constants/config.d.ts} +0 -0
- /package/dist/{constants → runtime/constants}/config.js +0 -0
- /package/dist/{utils/http.mjs → runtime/utils/http.js} +0 -0
- /package/dist/{utils/url.mjs → runtime/utils/url.js} +0 -0
- /package/src/{constants → runtime/constants}/auth.ts +0 -0
- /package/src/{constants → runtime/constants}/config.ts +0 -0
- /package/src/{utils → runtime/utils}/http.ts +0 -0
- /package/src/{utils → runtime/utils}/url.ts +0 -0
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { LoginPayload, User } from "../types/auth";
|
|
2
|
-
export declare function useEnfyraAuth(): {
|
|
3
|
-
readonly me: import("vue").Ref<{
|
|
4
|
-
id: string;
|
|
5
|
-
email: string;
|
|
6
|
-
isRootAdmin: boolean;
|
|
7
|
-
isSystem: boolean;
|
|
8
|
-
role?: {
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
routePermissions: {
|
|
12
|
-
id: string;
|
|
13
|
-
isEnabled: boolean;
|
|
14
|
-
allowedUsers?: {
|
|
15
|
-
id: string;
|
|
16
|
-
}[] | undefined;
|
|
17
|
-
methods: {
|
|
18
|
-
id: string;
|
|
19
|
-
method: string;
|
|
20
|
-
}[];
|
|
21
|
-
route: {
|
|
22
|
-
id: string;
|
|
23
|
-
path: string;
|
|
24
|
-
};
|
|
25
|
-
}[];
|
|
26
|
-
} | undefined;
|
|
27
|
-
allowedRoutePermissions?: {
|
|
28
|
-
id: string;
|
|
29
|
-
isEnabled: boolean;
|
|
30
|
-
allowedUsers?: {
|
|
31
|
-
id: string;
|
|
32
|
-
}[] | undefined;
|
|
33
|
-
methods: {
|
|
34
|
-
id: string;
|
|
35
|
-
method: string;
|
|
36
|
-
}[];
|
|
37
|
-
route: {
|
|
38
|
-
id: string;
|
|
39
|
-
path: string;
|
|
40
|
-
};
|
|
41
|
-
}[] | undefined;
|
|
42
|
-
} | null, User | {
|
|
43
|
-
id: string;
|
|
44
|
-
email: string;
|
|
45
|
-
isRootAdmin: boolean;
|
|
46
|
-
isSystem: boolean;
|
|
47
|
-
role?: {
|
|
48
|
-
id: string;
|
|
49
|
-
name: string;
|
|
50
|
-
routePermissions: {
|
|
51
|
-
id: string;
|
|
52
|
-
isEnabled: boolean;
|
|
53
|
-
allowedUsers?: {
|
|
54
|
-
id: string;
|
|
55
|
-
}[] | undefined;
|
|
56
|
-
methods: {
|
|
57
|
-
id: string;
|
|
58
|
-
method: string;
|
|
59
|
-
}[];
|
|
60
|
-
route: {
|
|
61
|
-
id: string;
|
|
62
|
-
path: string;
|
|
63
|
-
};
|
|
64
|
-
}[];
|
|
65
|
-
} | undefined;
|
|
66
|
-
allowedRoutePermissions?: {
|
|
67
|
-
id: string;
|
|
68
|
-
isEnabled: boolean;
|
|
69
|
-
allowedUsers?: {
|
|
70
|
-
id: string;
|
|
71
|
-
}[] | undefined;
|
|
72
|
-
methods: {
|
|
73
|
-
id: string;
|
|
74
|
-
method: string;
|
|
75
|
-
}[];
|
|
76
|
-
route: {
|
|
77
|
-
id: string;
|
|
78
|
-
path: string;
|
|
79
|
-
};
|
|
80
|
-
}[] | undefined;
|
|
81
|
-
} | null>;
|
|
82
|
-
readonly login: (payload: LoginPayload) => Promise<any>;
|
|
83
|
-
readonly logout: () => Promise<void>;
|
|
84
|
-
readonly fetchUser: (options?: {
|
|
85
|
-
fields?: string[];
|
|
86
|
-
}) => Promise<void>;
|
|
87
|
-
readonly isLoggedIn: import("vue").ComputedRef<boolean>;
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=useEnfyraAuth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEnfyraAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useEnfyraAuth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAuB,MAAM,eAAe,CAAC;AAM7E,wBAAgB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAgDG,YAAY;;mCAzBP;QAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;;EAqEzD"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { ref, computed } from "vue";
|
|
2
|
-
import { useEnfyraApi } from "./useEnfyraApi";
|
|
3
|
-
const me = ref(null);
|
|
4
|
-
const isLoading = ref(false);
|
|
5
|
-
export function useEnfyraAuth() {
|
|
6
|
-
const { data: loginData, execute: executeLogin, error: loginError, } = useEnfyraApi("/login", {
|
|
7
|
-
method: "post",
|
|
8
|
-
errorContext: "Login",
|
|
9
|
-
});
|
|
10
|
-
const { execute: executeLogout } = useEnfyraApi("/logout", {
|
|
11
|
-
method: "post",
|
|
12
|
-
errorContext: "Logout",
|
|
13
|
-
});
|
|
14
|
-
const { data: meData, execute: executeFetchUser, error: fetchUserError, } = useEnfyraApi("/me", {
|
|
15
|
-
errorContext: "Fetch User Profile",
|
|
16
|
-
});
|
|
17
|
-
const fetchUser = async (options) => {
|
|
18
|
-
isLoading.value = true;
|
|
19
|
-
try {
|
|
20
|
-
const queryParams = {};
|
|
21
|
-
if (options?.fields && options.fields.length > 0) {
|
|
22
|
-
queryParams.fields = options.fields.join(",");
|
|
23
|
-
}
|
|
24
|
-
await executeFetchUser({
|
|
25
|
-
query: queryParams,
|
|
26
|
-
});
|
|
27
|
-
if (fetchUserError.value) {
|
|
28
|
-
me.value = null;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
me.value = meData.value?.data?.[0];
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
isLoading.value = false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const login = async (payload) => {
|
|
38
|
-
isLoading.value = true;
|
|
39
|
-
try {
|
|
40
|
-
await executeLogin({ body: payload });
|
|
41
|
-
if (loginError.value) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
return loginData.value;
|
|
45
|
-
}
|
|
46
|
-
finally {
|
|
47
|
-
isLoading.value = false;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const logout = async () => {
|
|
51
|
-
isLoading.value = true;
|
|
52
|
-
try {
|
|
53
|
-
await executeLogout();
|
|
54
|
-
me.value = null;
|
|
55
|
-
if (typeof window !== "undefined") {
|
|
56
|
-
window.location.reload();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
me.value = null;
|
|
61
|
-
if (typeof window !== "undefined") {
|
|
62
|
-
window.location.reload();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
finally {
|
|
66
|
-
isLoading.value = false;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const isLoggedIn = computed(() => !!me.value);
|
|
70
|
-
return {
|
|
71
|
-
me,
|
|
72
|
-
login,
|
|
73
|
-
logout,
|
|
74
|
-
fetchUser,
|
|
75
|
-
isLoggedIn,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/constants/config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const ENFYRA_API_PREFIX = "/enfyra/api";
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
|
|
2
|
-
export default defineNuxtPlugin(() => {
|
|
3
|
-
const config = useRuntimeConfig().public?.enfyraSDK;
|
|
4
|
-
if (config?.configError) {
|
|
5
|
-
if (typeof window !== "undefined" && document) {
|
|
6
|
-
let showError = function() {
|
|
7
|
-
const errorDiv = document.createElement("div");
|
|
8
|
-
errorDiv.id = "enfyra-config-error";
|
|
9
|
-
errorDiv.style.cssText = `
|
|
10
|
-
position: fixed;
|
|
11
|
-
top: 0;
|
|
12
|
-
left: 0;
|
|
13
|
-
right: 0;
|
|
14
|
-
bottom: 0;
|
|
15
|
-
background: rgba(0, 0, 0, 0.9);
|
|
16
|
-
display: flex;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-content: center;
|
|
19
|
-
z-index: 999999;
|
|
20
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
21
|
-
`;
|
|
22
|
-
const content = document.createElement("div");
|
|
23
|
-
content.style.cssText = `
|
|
24
|
-
background: white;
|
|
25
|
-
padding: 40px;
|
|
26
|
-
border-radius: 12px;
|
|
27
|
-
max-width: 600px;
|
|
28
|
-
width: 90%;
|
|
29
|
-
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
30
|
-
`;
|
|
31
|
-
content.innerHTML = `
|
|
32
|
-
<div style="display: flex; align-items: center; margin-bottom: 20px;">
|
|
33
|
-
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" style="margin-right: 12px;">
|
|
34
|
-
<circle cx="12" cy="12" r="10" stroke="#ef4444" stroke-width="2"/>
|
|
35
|
-
<path d="M12 8v4M12 16h.01" stroke="#ef4444" stroke-width="2" stroke-linecap="round"/>
|
|
36
|
-
</svg>
|
|
37
|
-
<h1 style="margin: 0; color: #1f2937; font-size: 24px; font-weight: 600;">
|
|
38
|
-
Configuration Error
|
|
39
|
-
</h1>
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
<div style="color: #4b5563; margin-bottom: 24px; line-height: 1.6;">
|
|
43
|
-
<p style="margin: 0 0 16px 0; font-size: 16px;">
|
|
44
|
-
<strong>Enfyra SDK</strong> is not configured properly.
|
|
45
|
-
</p>
|
|
46
|
-
<p style="margin: 0; color: #6b7280; font-size: 14px;">
|
|
47
|
-
${config?.configErrorMessage || "Missing required configuration"}
|
|
48
|
-
</p>
|
|
49
|
-
</div>
|
|
50
|
-
|
|
51
|
-
<div style="background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin-bottom: 24px;">
|
|
52
|
-
<p style="margin: 0 0 12px 0; color: #6b7280; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px;">
|
|
53
|
-
Add to your nuxt.config.ts:
|
|
54
|
-
</p>
|
|
55
|
-
<pre style="margin: 0; background: #1f2937; color: #f3f4f6; padding: 16px; border-radius: 6px; overflow-x: auto; font-size: 14px; line-height: 1.4;"><code>export default defineNuxtConfig({
|
|
56
|
-
modules: ["@enfyra/sdk-nuxt"],
|
|
57
|
-
enfyraSDK: {
|
|
58
|
-
<span style="color: #fbbf24;">apiUrl</span>: <span style="color: #34d399;">"https://your-api-url"</span>
|
|
59
|
-
}
|
|
60
|
-
})</code></pre>
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
<div style="display: flex; gap: 12px;">
|
|
64
|
-
<button onclick="location.reload()" style="
|
|
65
|
-
background: #3b82f6;
|
|
66
|
-
color: white;
|
|
67
|
-
border: none;
|
|
68
|
-
padding: 10px 20px;
|
|
69
|
-
border-radius: 6px;
|
|
70
|
-
font-size: 14px;
|
|
71
|
-
font-weight: 500;
|
|
72
|
-
cursor: pointer;
|
|
73
|
-
transition: background 0.2s;
|
|
74
|
-
" onmouseover="this.style.background='#2563eb'" onmouseout="this.style.background='#3b82f6'">
|
|
75
|
-
Reload Page
|
|
76
|
-
</button>
|
|
77
|
-
<button onclick="document.getElementById('enfyra-config-error').style.display='none'" style="
|
|
78
|
-
background: #f3f4f6;
|
|
79
|
-
color: #4b5563;
|
|
80
|
-
border: 1px solid #e5e7eb;
|
|
81
|
-
padding: 10px 20px;
|
|
82
|
-
border-radius: 6px;
|
|
83
|
-
font-size: 14px;
|
|
84
|
-
font-weight: 500;
|
|
85
|
-
cursor: pointer;
|
|
86
|
-
transition: all 0.2s;
|
|
87
|
-
" onmouseover="this.style.background='#e5e7eb'" onmouseout="this.style.background='#f3f4f6'">
|
|
88
|
-
Dismiss
|
|
89
|
-
</button>
|
|
90
|
-
</div>
|
|
91
|
-
`;
|
|
92
|
-
errorDiv.appendChild(content);
|
|
93
|
-
document.body.appendChild(errorDiv);
|
|
94
|
-
console.error(
|
|
95
|
-
"%c\u26A0\uFE0F Enfyra SDK Configuration Error",
|
|
96
|
-
"color: #ef4444; font-size: 16px; font-weight: bold;",
|
|
97
|
-
"\n\n" + (config?.configErrorMessage || "Missing required configuration") + '\n\nPlease add the following to your nuxt.config.ts:\n\nenfyraSDK: {\n apiUrl: "https://your-api-url"\n}'
|
|
98
|
-
);
|
|
99
|
-
};
|
|
100
|
-
if (document.readyState === "loading") {
|
|
101
|
-
document.addEventListener("DOMContentLoaded", showError);
|
|
102
|
-
} else {
|
|
103
|
-
showError();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEventHandler,
|
|
3
|
-
readBody,
|
|
4
|
-
setCookie,
|
|
5
|
-
createError,
|
|
6
|
-
sendError,
|
|
7
|
-
getHeader
|
|
8
|
-
} from "h3";
|
|
9
|
-
import { useRuntimeConfig } from "#imports";
|
|
10
|
-
import { $fetch } from "ofetch";
|
|
11
|
-
import {
|
|
12
|
-
ACCESS_TOKEN_KEY,
|
|
13
|
-
REFRESH_TOKEN_KEY,
|
|
14
|
-
EXP_TIME_KEY
|
|
15
|
-
} from "../../../constants/auth";
|
|
16
|
-
import { normalizeUrl } from "../../../utils/url";
|
|
17
|
-
export default defineEventHandler(async (event) => {
|
|
18
|
-
const config = useRuntimeConfig();
|
|
19
|
-
const apiUrl = config.public.enfyraSDK?.apiUrl;
|
|
20
|
-
try {
|
|
21
|
-
const body = await readBody(event);
|
|
22
|
-
const response = await $fetch(normalizeUrl(apiUrl, "/auth/login"), {
|
|
23
|
-
method: "POST",
|
|
24
|
-
body,
|
|
25
|
-
headers: {
|
|
26
|
-
cookie: getHeader(event, "cookie") || ""
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
const { accessToken, refreshToken, expTime } = response;
|
|
30
|
-
const cookieOptions = {
|
|
31
|
-
httpOnly: true,
|
|
32
|
-
secure: true,
|
|
33
|
-
sameSite: "lax",
|
|
34
|
-
path: "/"
|
|
35
|
-
};
|
|
36
|
-
setCookie(event, ACCESS_TOKEN_KEY, accessToken, cookieOptions);
|
|
37
|
-
setCookie(event, REFRESH_TOKEN_KEY, refreshToken, cookieOptions);
|
|
38
|
-
setCookie(event, EXP_TIME_KEY, String(expTime), cookieOptions);
|
|
39
|
-
return { accessToken };
|
|
40
|
-
} catch (err) {
|
|
41
|
-
const statusCode = err?.response?.status || err?.statusCode || 401;
|
|
42
|
-
const errorData = err?.response?._data || err?.data;
|
|
43
|
-
let errorMessage = "Authentication failed";
|
|
44
|
-
let errorCode = "AUTHENTICATION_ERROR";
|
|
45
|
-
if (errorData?.error) {
|
|
46
|
-
errorMessage = errorData.error.message || errorData.message || errorMessage;
|
|
47
|
-
errorCode = errorData.error.code || errorCode;
|
|
48
|
-
}
|
|
49
|
-
return sendError(
|
|
50
|
-
event,
|
|
51
|
-
createError({
|
|
52
|
-
statusCode,
|
|
53
|
-
statusMessage: errorMessage,
|
|
54
|
-
data: {
|
|
55
|
-
code: errorCode,
|
|
56
|
-
details: errorData?.error?.details,
|
|
57
|
-
correlationId: errorData?.error?.correlationId
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { defineEventHandler, getHeader, getCookie, deleteCookie } from "h3";
|
|
2
|
-
import { useRuntimeConfig } from "#imports";
|
|
3
|
-
import { $fetch } from "ofetch";
|
|
4
|
-
import {
|
|
5
|
-
ACCESS_TOKEN_KEY,
|
|
6
|
-
REFRESH_TOKEN_KEY,
|
|
7
|
-
EXP_TIME_KEY
|
|
8
|
-
} from "../../../constants/auth";
|
|
9
|
-
import { normalizeUrl } from "../../../utils/url";
|
|
10
|
-
export default defineEventHandler(async (event) => {
|
|
11
|
-
const config = useRuntimeConfig();
|
|
12
|
-
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
13
|
-
const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
|
|
14
|
-
try {
|
|
15
|
-
const result = await $fetch(normalizeUrl(apiUrl, "/auth/logout"), {
|
|
16
|
-
method: "POST",
|
|
17
|
-
headers: {
|
|
18
|
-
cookie: getHeader(event, "cookie") || "",
|
|
19
|
-
authorization: event.context.proxyHeaders?.authorization
|
|
20
|
-
},
|
|
21
|
-
body: {
|
|
22
|
-
refreshToken
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
deleteCookie(event, ACCESS_TOKEN_KEY);
|
|
26
|
-
deleteCookie(event, REFRESH_TOKEN_KEY);
|
|
27
|
-
deleteCookie(event, EXP_TIME_KEY);
|
|
28
|
-
return result;
|
|
29
|
-
} catch (err) {
|
|
30
|
-
deleteCookie(event, ACCESS_TOKEN_KEY);
|
|
31
|
-
deleteCookie(event, REFRESH_TOKEN_KEY);
|
|
32
|
-
deleteCookie(event, EXP_TIME_KEY);
|
|
33
|
-
return { success: false, message: "Logout completed locally" };
|
|
34
|
-
}
|
|
35
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { defineEventHandler, getCookie } from "h3";
|
|
2
|
-
import { useRuntimeConfig } from "#imports";
|
|
3
|
-
import {
|
|
4
|
-
validateTokens,
|
|
5
|
-
refreshAccessToken
|
|
6
|
-
} from "../../../utils/server/refreshToken";
|
|
7
|
-
import { REFRESH_TOKEN_KEY } from "../../../constants/auth";
|
|
8
|
-
export default defineEventHandler(async (event) => {
|
|
9
|
-
if (event.node.req.url === "/api/login" || event.node.req.url === "/api/logout") {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const { accessToken, needsRefresh } = validateTokens(event);
|
|
13
|
-
let currentAccessToken = accessToken;
|
|
14
|
-
if (needsRefresh) {
|
|
15
|
-
const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
|
|
16
|
-
if (refreshToken) {
|
|
17
|
-
try {
|
|
18
|
-
const config = useRuntimeConfig();
|
|
19
|
-
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
20
|
-
if (apiUrl) {
|
|
21
|
-
currentAccessToken = await refreshAccessToken(
|
|
22
|
-
event,
|
|
23
|
-
refreshToken,
|
|
24
|
-
apiUrl
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
} catch (error) {
|
|
28
|
-
currentAccessToken = null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (currentAccessToken) {
|
|
33
|
-
event.context.proxyHeaders = event.context.proxyHeaders || {};
|
|
34
|
-
event.context.proxyHeaders.authorization = `Bearer ${currentAccessToken}`;
|
|
35
|
-
}
|
|
36
|
-
});
|
package/dist/types/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE;QACL,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,gBAAgB,EAAE,eAAe,EAAE,CAAA;KACpC,CAAA;IACD,uBAAuB,CAAC,EAAE,eAAe,EAAE,CAAA;CAC5C;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC/B,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IACzC,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAA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c,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AAEtE,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAC5B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;CACpE;AAGD,cAAc,QAAQ,CAAC"}
|
package/dist/utils/config.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ref } from "vue";
|
|
2
|
-
const config = ref({
|
|
3
|
-
apiUrl: "",
|
|
4
|
-
defaultHeaders: {}
|
|
5
|
-
});
|
|
6
|
-
export function useEnfyraConfig() {
|
|
7
|
-
const setConfig = (newConfig) => {
|
|
8
|
-
config.value = { ...config.value, ...newConfig };
|
|
9
|
-
};
|
|
10
|
-
const getConfig = () => config.value;
|
|
11
|
-
return {
|
|
12
|
-
setConfig,
|
|
13
|
-
getConfig
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export { config };
|
package/dist/utils/http.d.ts
DELETED
package/dist/utils/http.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,wBAAsB,MAAM,CAAC,CAAC,GAAG,GAAG,EAClC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;CACb,GACL,OAAO,CAAC,CAAC,CAAC,CAoEZ"}
|
package/dist/utils/http.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
export async function $fetch(path, options = {}) {
|
|
2
|
-
const { method = "GET", body, headers: optionHeaders = {}, query = {}, baseURL, } = options;
|
|
3
|
-
if (!baseURL) {
|
|
4
|
-
throw new Error('baseURL is required for $fetch');
|
|
5
|
-
}
|
|
6
|
-
const url = new URL(path.startsWith("/") ? path.slice(1) : path, baseURL.endsWith("/") ? baseURL : `${baseURL}/`);
|
|
7
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
8
|
-
if (value !== undefined && value !== null) {
|
|
9
|
-
if (typeof value === 'object') {
|
|
10
|
-
url.searchParams.append(key, JSON.stringify(value));
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
url.searchParams.append(key, String(value));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const headers = {
|
|
18
|
-
"Content-Type": "application/json",
|
|
19
|
-
...optionHeaders,
|
|
20
|
-
};
|
|
21
|
-
const fetchOptions = {
|
|
22
|
-
method: method.toUpperCase(),
|
|
23
|
-
headers,
|
|
24
|
-
};
|
|
25
|
-
if (body && method.toUpperCase() !== "GET") {
|
|
26
|
-
if (body instanceof FormData) {
|
|
27
|
-
delete headers["Content-Type"]; // Let browser set boundary for FormData
|
|
28
|
-
fetchOptions.body = body;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
fetchOptions.body = JSON.stringify(body);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
const response = await fetch(url.toString(), fetchOptions);
|
|
36
|
-
if (!response.ok) {
|
|
37
|
-
let errorData;
|
|
38
|
-
try {
|
|
39
|
-
errorData = await response.json();
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
errorData = { message: response.statusText };
|
|
43
|
-
}
|
|
44
|
-
throw { response: { data: errorData } };
|
|
45
|
-
}
|
|
46
|
-
const contentType = response.headers.get("content-type");
|
|
47
|
-
if (contentType?.includes("application/json")) {
|
|
48
|
-
return await response.json();
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
return (await response.text());
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
package/dist/utils/url.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
export declare function normalizeUrl(...segments: (string | undefined | null)[]): string;
|
|
7
|
-
/**
|
|
8
|
-
* Joins URL paths safely, avoiding double slashes
|
|
9
|
-
*/
|
|
10
|
-
export declare function joinUrlPath(...paths: (string | undefined | null)[]): string;
|
|
11
|
-
export declare function getAppUrl(): string;
|
|
12
|
-
//# sourceMappingURL=url.d.ts.map
|
package/dist/utils/url.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,QAAQ,EAAE,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM,CAmB/E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,EAAE,GAAG,MAAM,CAQ3E;AAED,wBAAgB,SAAS,IAAI,MAAM,CA8ClC"}
|
package/dist/utils/url.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
export function normalizeUrl(...segments) {
|
|
7
|
-
const validSegments = segments.filter((s) => Boolean(s));
|
|
8
|
-
if (validSegments.length === 0)
|
|
9
|
-
return '';
|
|
10
|
-
// First segment is the base URL - remove trailing slashes
|
|
11
|
-
let result = validSegments[0].replace(/\/+$/, '');
|
|
12
|
-
// For remaining segments, remove leading and trailing slashes, normalize internal slashes, then join
|
|
13
|
-
for (let i = 1; i < validSegments.length; i++) {
|
|
14
|
-
const segment = validSegments[i]
|
|
15
|
-
.replace(/^\/+/, '') // Remove leading slashes
|
|
16
|
-
.replace(/\/+$/, '') // Remove trailing slashes
|
|
17
|
-
.replace(/\/+/g, '/'); // Normalize multiple consecutive slashes to single slash
|
|
18
|
-
if (segment) {
|
|
19
|
-
result += '/' + segment;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Joins URL paths safely, avoiding double slashes
|
|
26
|
-
*/
|
|
27
|
-
export function joinUrlPath(...paths) {
|
|
28
|
-
const validPaths = paths.filter((p) => Boolean(p));
|
|
29
|
-
if (validPaths.length === 0)
|
|
30
|
-
return '';
|
|
31
|
-
return validPaths
|
|
32
|
-
.map(path => path.replace(/^\/+/, '').replace(/\/+$/, ''))
|
|
33
|
-
.filter(Boolean)
|
|
34
|
-
.join('/');
|
|
35
|
-
}
|
|
36
|
-
export function getAppUrl() {
|
|
37
|
-
if (process.client && typeof window !== 'undefined') {
|
|
38
|
-
return window.location.origin;
|
|
39
|
-
}
|
|
40
|
-
if (process.server) {
|
|
41
|
-
try {
|
|
42
|
-
let useRequestHeaders;
|
|
43
|
-
let useRequestURL;
|
|
44
|
-
try {
|
|
45
|
-
const imports = eval('require("#imports")');
|
|
46
|
-
useRequestHeaders = imports.useRequestHeaders;
|
|
47
|
-
useRequestURL = imports.useRequestURL;
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
return '';
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
const url = useRequestURL();
|
|
54
|
-
if (url) {
|
|
55
|
-
return `${url.protocol}//${url.host}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
}
|
|
60
|
-
const headers = useRequestHeaders();
|
|
61
|
-
const forwarded = headers['x-forwarded-host'] || headers['x-forwarded-server'];
|
|
62
|
-
const protocol = headers['x-forwarded-proto'] || 'https';
|
|
63
|
-
if (forwarded) {
|
|
64
|
-
return `${protocol}://${forwarded}`;
|
|
65
|
-
}
|
|
66
|
-
const host = headers.host;
|
|
67
|
-
if (host) {
|
|
68
|
-
const isHttps = protocol === 'https' || headers['x-forwarded-ssl'] === 'on';
|
|
69
|
-
return `${isHttps ? 'https' : 'http'}://${host}`;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
console.warn('[Enfyra SDK] Could not auto-detect app URL on server:', e);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return '';
|
|
77
|
-
}
|