@enfyra/sdk-nuxt 0.7.4 → 0.7.5
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.cjs +0 -5
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +0 -5
- package/dist/runtime/server/api/all.d.ts.map +1 -1
- package/dist/runtime/server/api/all.js +24 -4
- package/package.json +1 -1
- package/src/module.ts +0 -6
- package/src/runtime/server/api/all.ts +26 -4
- package/dist/runtime/server/api/auth/callback.get.d.ts +0 -3
- package/dist/runtime/server/api/auth/callback.get.d.ts.map +0 -1
- package/dist/runtime/server/api/auth/callback.get.js +0 -29
- package/src/runtime/server/api/auth/callback.get.ts +0 -36
package/dist/module.cjs
CHANGED
|
@@ -98,11 +98,6 @@ declare module '#imports' {
|
|
|
98
98
|
handler: resolve("./runtime/server/api/logout.post"),
|
|
99
99
|
method: "post"
|
|
100
100
|
});
|
|
101
|
-
kit.addServerHandler({
|
|
102
|
-
route: `${apiPrefix}/auth/callback`,
|
|
103
|
-
handler: resolve("./runtime/server/api/auth/callback.get"),
|
|
104
|
-
method: "get"
|
|
105
|
-
});
|
|
106
101
|
kit.addServerHandler({
|
|
107
102
|
route: "/assets/**",
|
|
108
103
|
handler: resolve("./runtime/server/api/all")
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,wBA6HG"}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -95,11 +95,6 @@ declare module '#imports' {
|
|
|
95
95
|
handler: resolve("./runtime/server/api/logout.post"),
|
|
96
96
|
method: "post"
|
|
97
97
|
});
|
|
98
|
-
addServerHandler({
|
|
99
|
-
route: `${apiPrefix}/auth/callback`,
|
|
100
|
-
handler: resolve("./runtime/server/api/auth/callback.get"),
|
|
101
|
-
method: "get"
|
|
102
|
-
});
|
|
103
98
|
addServerHandler({
|
|
104
99
|
route: "/assets/**",
|
|
105
100
|
handler: resolve("./runtime/server/api/all")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";AAsBA,wBAmDG"}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
setResponseHeaders
|
|
7
7
|
} from "h3";
|
|
8
8
|
import { useRuntimeConfig } from "#imports";
|
|
9
|
+
import { ENFYRA_API_PREFIX } from "../../constants/config.js";
|
|
9
10
|
import { proxyToAPI } from "../../utils/server/proxy.js";
|
|
10
11
|
const CORS_HEADERS = {
|
|
11
12
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -14,13 +15,33 @@ const CORS_HEADERS = {
|
|
|
14
15
|
"Access-Control-Max-Age": "86400"
|
|
15
16
|
};
|
|
16
17
|
const OAUTH_PROVIDERS = ["google", "facebook", "github"];
|
|
17
|
-
const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})
|
|
18
|
+
const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})/?$`);
|
|
19
|
+
const OAUTH_CALLBACK_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})/callback$`);
|
|
18
20
|
export default defineEventHandler(async (event) => {
|
|
19
21
|
setResponseHeaders(event, CORS_HEADERS);
|
|
20
22
|
if (event.method === "OPTIONS") {
|
|
21
23
|
return "";
|
|
22
24
|
}
|
|
23
|
-
const
|
|
25
|
+
const config = useRuntimeConfig();
|
|
26
|
+
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
27
|
+
const fullUrl = event.node?.req?.url || event.path || "";
|
|
28
|
+
const [path, queryString] = fullUrl.split("?");
|
|
29
|
+
const apiPrefix = config.public?.enfyraSDK?.apiPrefix || ENFYRA_API_PREFIX;
|
|
30
|
+
const pathWithoutPrefix = path.replace(new RegExp(`^${apiPrefix}`), "") || "/";
|
|
31
|
+
const oauthCallbackMatch = pathWithoutPrefix.match(OAUTH_CALLBACK_PATTERN);
|
|
32
|
+
if (event.method === "GET" && oauthCallbackMatch) {
|
|
33
|
+
if (!apiUrl) {
|
|
34
|
+
throw createError({ statusCode: 500, message: "API URL not configured" });
|
|
35
|
+
}
|
|
36
|
+
const backendPath = pathWithoutPrefix.startsWith("/") ? pathWithoutPrefix : `/${pathWithoutPrefix}`;
|
|
37
|
+
const backendUrl = `${apiUrl.replace(/\/+$/, "")}${backendPath}${queryString ? `?${queryString}` : ""}`;
|
|
38
|
+
const response = await fetch(backendUrl, { redirect: "manual" });
|
|
39
|
+
const location = response.headers.get("location") || response.headers.get("Location");
|
|
40
|
+
if (location && response.status >= 300 && response.status < 400) {
|
|
41
|
+
return sendRedirect(event, location, response.status);
|
|
42
|
+
}
|
|
43
|
+
throw createError({ statusCode: 502, message: "OAuth callback failed" });
|
|
44
|
+
}
|
|
24
45
|
const oauthMatch = path.match(OAUTH_INIT_PATTERN);
|
|
25
46
|
if (event.method === "GET" && oauthMatch) {
|
|
26
47
|
const provider = oauthMatch[1];
|
|
@@ -29,8 +50,6 @@ export default defineEventHandler(async (event) => {
|
|
|
29
50
|
if (!redirectParam) {
|
|
30
51
|
throw createError({ statusCode: 400, message: "Redirect URL is required" });
|
|
31
52
|
}
|
|
32
|
-
const config = useRuntimeConfig();
|
|
33
|
-
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
34
53
|
if (!apiUrl) {
|
|
35
54
|
throw createError({ statusCode: 500, message: "API URL not configured" });
|
|
36
55
|
}
|
|
@@ -38,6 +57,7 @@ export default defineEventHandler(async (event) => {
|
|
|
38
57
|
const response = await fetch(backendUrl, { redirect: "manual" });
|
|
39
58
|
const location = response.headers.get("location") || response.headers.get("Location");
|
|
40
59
|
if (location && response.status >= 300 && response.status < 400) {
|
|
60
|
+
console.log("[Enfyra OAuth] Redirecting to:", location);
|
|
41
61
|
return sendRedirect(event, location, 302);
|
|
42
62
|
}
|
|
43
63
|
throw createError({ statusCode: 502, message: "Failed to get OAuth URL from backend" });
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -130,12 +130,6 @@ declare module '#imports' {
|
|
|
130
130
|
method: "post",
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
addServerHandler({
|
|
134
|
-
route: `${apiPrefix}/auth/callback`,
|
|
135
|
-
handler: resolve("./runtime/server/api/auth/callback.get"),
|
|
136
|
-
method: "get",
|
|
137
|
-
});
|
|
138
|
-
|
|
139
133
|
addServerHandler({
|
|
140
134
|
route: "/assets/**",
|
|
141
135
|
handler: resolve("./runtime/server/api/all"),
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
setResponseHeaders,
|
|
7
7
|
} from "h3";
|
|
8
8
|
import { useRuntimeConfig } from "#imports";
|
|
9
|
+
import { ENFYRA_API_PREFIX } from "../../constants/config";
|
|
9
10
|
import { proxyToAPI } from "../../utils/server/proxy";
|
|
10
11
|
|
|
11
12
|
const CORS_HEADERS = {
|
|
@@ -16,7 +17,8 @@ const CORS_HEADERS = {
|
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
const OAUTH_PROVIDERS = ["google", "facebook", "github"];
|
|
19
|
-
const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})
|
|
20
|
+
const OAUTH_INIT_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})/?$`);
|
|
21
|
+
const OAUTH_CALLBACK_PATTERN = new RegExp(`/auth/(${OAUTH_PROVIDERS.join("|")})/callback$`);
|
|
20
22
|
|
|
21
23
|
export default defineEventHandler(async (event) => {
|
|
22
24
|
setResponseHeaders(event, CORS_HEADERS);
|
|
@@ -25,7 +27,28 @@ export default defineEventHandler(async (event) => {
|
|
|
25
27
|
return '';
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const
|
|
30
|
+
const config = useRuntimeConfig();
|
|
31
|
+
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
32
|
+
const fullUrl = event.node?.req?.url || event.path || "";
|
|
33
|
+
const [path, queryString] = fullUrl.split("?");
|
|
34
|
+
|
|
35
|
+
const apiPrefix = config.public?.enfyraSDK?.apiPrefix || ENFYRA_API_PREFIX;
|
|
36
|
+
const pathWithoutPrefix = path.replace(new RegExp(`^${apiPrefix}`), "") || "/";
|
|
37
|
+
const oauthCallbackMatch = pathWithoutPrefix.match(OAUTH_CALLBACK_PATTERN);
|
|
38
|
+
if (event.method === "GET" && oauthCallbackMatch) {
|
|
39
|
+
if (!apiUrl) {
|
|
40
|
+
throw createError({ statusCode: 500, message: "API URL not configured" });
|
|
41
|
+
}
|
|
42
|
+
const backendPath = pathWithoutPrefix.startsWith("/") ? pathWithoutPrefix : `/${pathWithoutPrefix}`;
|
|
43
|
+
const backendUrl = `${apiUrl.replace(/\/+$/, "")}${backendPath}${queryString ? `?${queryString}` : ""}`;
|
|
44
|
+
const response = await fetch(backendUrl, { redirect: "manual" });
|
|
45
|
+
const location = response.headers.get("location") || response.headers.get("Location");
|
|
46
|
+
if (location && response.status >= 300 && response.status < 400) {
|
|
47
|
+
return sendRedirect(event, location, response.status as 301 | 302 | 307 | 308);
|
|
48
|
+
}
|
|
49
|
+
throw createError({ statusCode: 502, message: "OAuth callback failed" });
|
|
50
|
+
}
|
|
51
|
+
|
|
29
52
|
const oauthMatch = path.match(OAUTH_INIT_PATTERN);
|
|
30
53
|
if (event.method === "GET" && oauthMatch) {
|
|
31
54
|
const provider = oauthMatch[1];
|
|
@@ -34,8 +57,6 @@ export default defineEventHandler(async (event) => {
|
|
|
34
57
|
if (!redirectParam) {
|
|
35
58
|
throw createError({ statusCode: 400, message: "Redirect URL is required" });
|
|
36
59
|
}
|
|
37
|
-
const config = useRuntimeConfig();
|
|
38
|
-
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
39
60
|
if (!apiUrl) {
|
|
40
61
|
throw createError({ statusCode: 500, message: "API URL not configured" });
|
|
41
62
|
}
|
|
@@ -43,6 +64,7 @@ export default defineEventHandler(async (event) => {
|
|
|
43
64
|
const response = await fetch(backendUrl, { redirect: "manual" });
|
|
44
65
|
const location = response.headers.get("location") || response.headers.get("Location");
|
|
45
66
|
if (location && response.status >= 300 && response.status < 400) {
|
|
67
|
+
console.log("[Enfyra OAuth] Redirecting to:", location);
|
|
46
68
|
return sendRedirect(event, location, 302);
|
|
47
69
|
}
|
|
48
70
|
throw createError({ statusCode: 502, message: "Failed to get OAuth URL from backend" });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callback.get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/callback.get.ts"],"names":[],"mappings":";AAaA,wBAsBG"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEventHandler,
|
|
3
|
-
getQuery,
|
|
4
|
-
setCookie,
|
|
5
|
-
sendRedirect
|
|
6
|
-
} from "h3";
|
|
7
|
-
import {
|
|
8
|
-
ACCESS_TOKEN_KEY,
|
|
9
|
-
REFRESH_TOKEN_KEY,
|
|
10
|
-
EXP_TIME_KEY
|
|
11
|
-
} from "../../../constants/auth.js";
|
|
12
|
-
export default defineEventHandler(async (event) => {
|
|
13
|
-
const query = getQuery(event);
|
|
14
|
-
const { accessToken, refreshToken, expTime, redirect } = query;
|
|
15
|
-
if (!accessToken || !refreshToken || !expTime) {
|
|
16
|
-
return sendRedirect(event, "/login?error=oauth_callback_failed");
|
|
17
|
-
}
|
|
18
|
-
const cookieOptions = {
|
|
19
|
-
httpOnly: true,
|
|
20
|
-
secure: true,
|
|
21
|
-
sameSite: "lax",
|
|
22
|
-
path: "/"
|
|
23
|
-
};
|
|
24
|
-
setCookie(event, ACCESS_TOKEN_KEY, accessToken, cookieOptions);
|
|
25
|
-
setCookie(event, REFRESH_TOKEN_KEY, refreshToken, cookieOptions);
|
|
26
|
-
setCookie(event, EXP_TIME_KEY, expTime, cookieOptions);
|
|
27
|
-
const redirectUrl = redirect || "/";
|
|
28
|
-
return sendRedirect(event, redirectUrl);
|
|
29
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEventHandler,
|
|
3
|
-
getQuery,
|
|
4
|
-
setCookie,
|
|
5
|
-
sendRedirect,
|
|
6
|
-
} from "h3";
|
|
7
|
-
import { useRuntimeConfig } from "#imports";
|
|
8
|
-
import {
|
|
9
|
-
ACCESS_TOKEN_KEY,
|
|
10
|
-
REFRESH_TOKEN_KEY,
|
|
11
|
-
EXP_TIME_KEY,
|
|
12
|
-
} from "../../../constants/auth";
|
|
13
|
-
|
|
14
|
-
export default defineEventHandler(async (event) => {
|
|
15
|
-
const query = getQuery(event);
|
|
16
|
-
|
|
17
|
-
const { accessToken, refreshToken, expTime, redirect } = query;
|
|
18
|
-
|
|
19
|
-
if (!accessToken || !refreshToken || !expTime) {
|
|
20
|
-
return sendRedirect(event, "/login?error=oauth_callback_failed");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const cookieOptions = {
|
|
24
|
-
httpOnly: true,
|
|
25
|
-
secure: true,
|
|
26
|
-
sameSite: "lax" as const,
|
|
27
|
-
path: "/",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
setCookie(event, ACCESS_TOKEN_KEY, accessToken as string, cookieOptions);
|
|
31
|
-
setCookie(event, REFRESH_TOKEN_KEY, refreshToken as string, cookieOptions);
|
|
32
|
-
setCookie(event, EXP_TIME_KEY, expTime as string, cookieOptions);
|
|
33
|
-
|
|
34
|
-
const redirectUrl = (redirect as string) || "/";
|
|
35
|
-
return sendRedirect(event, redirectUrl);
|
|
36
|
-
});
|