@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.
- package/dist/module.cjs +57 -22
- package/dist/module.d.ts +4 -7
- package/dist/module.d.ts.map +1 -0
- package/dist/module.json +4 -1
- package/dist/module.mjs +56 -21
- package/dist/{composables → runtime/composables}/useEnfyraApi.d.ts +1 -1
- package/dist/runtime/composables/useEnfyraApi.d.ts.map +1 -0
- package/dist/{composables/useEnfyraApi.mjs → runtime/composables/useEnfyraApi.js} +6 -7
- package/dist/{composables → runtime/composables}/useEnfyraAuth.d.ts +1 -1
- package/dist/runtime/composables/useEnfyraAuth.d.ts.map +1 -0
- package/dist/{composables/useEnfyraAuth.mjs → runtime/composables/useEnfyraAuth.js} +1 -1
- package/dist/runtime/constants/auth.d.ts +4 -0
- package/dist/runtime/constants/auth.d.ts.map +1 -0
- package/dist/runtime/constants/config.d.ts.map +1 -0
- package/dist/runtime/plugin/config-error.client.d.ts +3 -0
- package/dist/runtime/plugin/config-error.client.d.ts.map +1 -0
- package/dist/runtime/server/api/all.d.ts +3 -0
- package/dist/runtime/server/api/all.d.ts.map +1 -0
- package/dist/runtime/server/api/all.js +1 -1
- package/dist/runtime/server/api/login.post.d.ts +5 -0
- package/dist/runtime/server/api/login.post.d.ts.map +1 -0
- package/dist/runtime/server/api/login.post.js +2 -2
- package/dist/runtime/server/api/logout.post.d.ts +3 -0
- package/dist/runtime/server/api/logout.post.d.ts.map +1 -0
- package/dist/runtime/server/api/logout.post.js +2 -2
- package/dist/runtime/server/middleware/auth.d.ts +3 -0
- package/dist/runtime/server/middleware/auth.d.ts.map +1 -0
- package/dist/runtime/server/middleware/auth.js +2 -2
- package/dist/runtime/shims.d.ts +64 -0
- package/dist/runtime/utils/http.d.ts.map +1 -0
- package/dist/runtime/utils/server/proxy.d.ts +3 -0
- package/dist/runtime/utils/server/proxy.d.ts.map +1 -0
- package/dist/{utils/server/proxy.mjs → runtime/utils/server/proxy.js} +2 -2
- package/dist/runtime/utils/server/refreshToken.d.ts +11 -0
- package/dist/runtime/utils/server/refreshToken.d.ts.map +1 -0
- package/dist/{utils/server/refreshToken.mjs → runtime/utils/server/refreshToken.js} +2 -2
- package/dist/runtime/utils/url.d.ts +4 -0
- package/dist/runtime/utils/url.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/module.d.ts +16 -6
- package/package.json +12 -14
- package/src/module.ts +73 -34
- package/src/{composables → runtime/composables}/useEnfyraApi.ts +21 -23
- 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 +64 -0
- package/src/{utils → runtime/utils}/server/proxy.ts +1 -1
- package/src/{utils → runtime/utils}/server/refreshToken.ts +3 -6
- package/src/{utils → runtime/utils}/url.ts +3 -13
- package/src/types/index.ts +1 -2
- package/dist/composables/useEnfyraApi.d.ts.map +0 -1
- package/dist/composables/useEnfyraApi.js +0 -363
- package/dist/composables/useEnfyraAuth.d.ts.map +0 -1
- package/dist/composables/useEnfyraAuth.js +0 -77
- package/dist/constants/auth.d.ts +0 -0
- 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.js +0 -1
- package/dist/types/index.js +0 -1
- package/dist/utils/config.d.ts +0 -0
- package/dist/utils/config.mjs +0 -16
- package/dist/utils/http.d.ts.map +0 -1
- package/dist/utils/http.js +0 -57
- package/dist/utils/server/proxy.d.ts +0 -0
- package/dist/utils/server/refreshToken.d.ts +0 -0
- 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/{constants/auth.mjs → runtime/constants/auth.js} +0 -0
- /package/dist/{constants → runtime/constants}/config.d.ts +0 -0
- /package/dist/{constants → runtime/constants}/config.js +0 -0
- /package/dist/{utils → runtime/utils}/http.d.ts +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
|
@@ -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.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './auth';
|
package/dist/utils/config.d.ts
DELETED
|
File without changes
|
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.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
|
-
}
|
|
File without changes
|
|
File without changes
|
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
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type declarations for Nuxt auto-imports
|
|
3
|
-
* These are provided at runtime by Nuxt but need declarations for TypeScript
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
declare global {
|
|
7
|
-
const useEnfyraApi: typeof import('../composables/useEnfyraApi').useEnfyraApi
|
|
8
|
-
const useEnfyraAuth: typeof import('../composables/useEnfyraAuth').useEnfyraAuth
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare module '#imports' {
|
|
12
|
-
export const useRuntimeConfig: () => {
|
|
13
|
-
public: {
|
|
14
|
-
enfyraSDK?: {
|
|
15
|
-
apiUrl?: string;
|
|
16
|
-
apiPrefix?: string;
|
|
17
|
-
configError?: boolean;
|
|
18
|
-
configErrorMessage?: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const useRequestHeaders: (headers?: string[]) => Record<string, string | undefined>;
|
|
25
|
-
|
|
26
|
-
export const useRequestURL: () => URL;
|
|
27
|
-
|
|
28
|
-
export const useFetch: <T = any>(
|
|
29
|
-
url: string | (() => string),
|
|
30
|
-
options?: any
|
|
31
|
-
) => any;
|
|
32
|
-
|
|
33
|
-
export const useNuxtApp: () => {
|
|
34
|
-
payload: {
|
|
35
|
-
data: Record<string, any>;
|
|
36
|
-
[key: string]: any;
|
|
37
|
-
};
|
|
38
|
-
static: {
|
|
39
|
-
data: Record<string, any>;
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
};
|
|
42
|
-
[key: string]: any;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const defineNuxtPlugin: (plugin: any) => any;
|
|
46
|
-
|
|
47
|
-
export const defineCachedEventHandler: (handler: any, options?: any) => any;
|
|
48
|
-
|
|
49
|
-
export const getCookie: (event: any, name: string) => string | undefined;
|
|
50
|
-
|
|
51
|
-
export const setCookie: (event: any, name: string, value: string, options?: any) => void;
|
|
52
|
-
|
|
53
|
-
export const deleteCookie: (event: any, name: string, options?: any) => void;
|
|
54
|
-
|
|
55
|
-
export const createError: (options: {
|
|
56
|
-
statusCode?: number;
|
|
57
|
-
statusMessage?: string;
|
|
58
|
-
message?: string;
|
|
59
|
-
data?: any;
|
|
60
|
-
}) => Error;
|
|
61
|
-
}
|
package/src/utils/config.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ref } from 'vue';
|
|
2
|
-
import type { EnfyraConfig } from '../types';
|
|
3
|
-
|
|
4
|
-
const config = ref<EnfyraConfig>({
|
|
5
|
-
apiUrl: '',
|
|
6
|
-
defaultHeaders: {}
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export function useEnfyraConfig() {
|
|
10
|
-
const setConfig = (newConfig: Partial<EnfyraConfig>) => {
|
|
11
|
-
config.value = { ...config.value, ...newConfig };
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const getConfig = () => config.value;
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
setConfig,
|
|
18
|
-
getConfig
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { config };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|