@enfyra/sdk-nuxt 0.3.18 → 0.3.19
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/composables/useEnfyraApi.d.ts +8 -0
- package/dist/composables/useEnfyraApi.d.ts.map +1 -0
- package/dist/composables/useEnfyraApi.js +363 -0
- package/dist/composables/useEnfyraApi.mjs +345 -0
- package/dist/composables/useEnfyraAuth.d.ts +89 -0
- package/dist/composables/useEnfyraAuth.d.ts.map +1 -0
- package/dist/composables/useEnfyraAuth.js +77 -0
- package/dist/composables/useEnfyraAuth.mjs +81 -0
- package/dist/constants/auth.d.ts +0 -0
- package/dist/constants/auth.mjs +3 -0
- package/dist/constants/config.d.ts +2 -0
- package/dist/constants/config.d.ts.map +1 -0
- package/dist/constants/config.js +1 -0
- package/dist/constants/config.mjs +1 -0
- package/dist/module.cjs +82 -0
- package/dist/module.d.cts +10 -0
- package/dist/module.d.mts +10 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +79 -0
- package/dist/types/auth.d.ts +43 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +1 -0
- package/dist/types/index.d.ts +141 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types.d.mts +7 -0
- package/dist/types.d.ts +7 -0
- package/dist/utils/config.d.ts +0 -0
- package/dist/utils/config.mjs +16 -0
- package/dist/utils/http.d.ts +8 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +57 -0
- package/dist/utils/http.mjs +61 -0
- package/dist/utils/server/proxy.d.ts +0 -0
- package/dist/utils/server/proxy.mjs +14 -0
- package/dist/utils/server/refreshToken.d.ts +0 -0
- package/dist/utils/server/refreshToken.mjs +69 -0
- package/dist/utils/url.d.ts +12 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +77 -0
- package/dist/utils/url.mjs +56 -0
- package/index.ts +1 -1
- package/module.d.ts +2 -2
- package/package.json +24 -24
- package/src/composables/useEnfyraAuth.ts +1 -1
- package/{module.ts → src/module.ts} +9 -10
- package/src/utils/url.ts +11 -4
|
@@ -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
|
+
}
|
package/index.ts
CHANGED
package/module.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ModuleOptions } from './module'
|
|
1
|
+
import type { ModuleOptions } from './src/module'
|
|
2
2
|
|
|
3
3
|
declare module '@nuxt/schema' {
|
|
4
4
|
interface NuxtConfig {
|
|
@@ -9,6 +9,6 @@ declare module '@nuxt/schema' {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export type { ModuleOptions } from './module'
|
|
12
|
+
export type { ModuleOptions } from './src/module'
|
|
13
13
|
export type * from './src/types'
|
|
14
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enfyra/sdk-nuxt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"description": "Nuxt SDK for Enfyra CMS",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
"url": "https://github.com/dothinh115/enfyra-sdk-nuxt/issues"
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/dothinh115/enfyra-sdk-nuxt#readme",
|
|
13
|
-
"main": "./module.
|
|
14
|
-
"types": "./
|
|
13
|
+
"main": "./dist/module.mjs",
|
|
14
|
+
"types": "./dist/types.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"import": "./dist/module.mjs",
|
|
18
|
+
"require": "./dist/module.cjs",
|
|
19
|
+
"types": "./dist/types.d.ts"
|
|
19
20
|
},
|
|
20
21
|
"./src/composables/useEnfyraApi": {
|
|
21
22
|
"types": "./src/composables/useEnfyraApi.ts",
|
|
@@ -25,25 +26,16 @@
|
|
|
25
26
|
"types": "./src/composables/useEnfyraAuth.ts",
|
|
26
27
|
"import": "./src/composables/useEnfyraAuth.ts"
|
|
27
28
|
},
|
|
28
|
-
"./
|
|
29
|
-
"types": "./
|
|
30
|
-
"import": "./
|
|
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"
|
|
29
|
+
"./types": {
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"import": "./dist/types/index.js"
|
|
32
|
+
}
|
|
40
33
|
},
|
|
41
34
|
"files": [
|
|
42
|
-
"
|
|
35
|
+
"dist/",
|
|
36
|
+
"src/",
|
|
43
37
|
"module.d.ts",
|
|
44
|
-
"index.ts"
|
|
45
|
-
"src/**/*",
|
|
46
|
-
"dist/runtime/**/*"
|
|
38
|
+
"index.ts"
|
|
47
39
|
],
|
|
48
40
|
"keywords": [
|
|
49
41
|
"nuxt",
|
|
@@ -57,8 +49,12 @@
|
|
|
57
49
|
"access": "public"
|
|
58
50
|
},
|
|
59
51
|
"scripts": {
|
|
60
|
-
"
|
|
61
|
-
"
|
|
52
|
+
"dev": "nuxi dev playground",
|
|
53
|
+
"build": "nuxt-module-build build && npx tsc -p tsconfig.build.json",
|
|
54
|
+
"prepack": "nuxt-module-build build && npx tsc -p tsconfig.build.json",
|
|
55
|
+
"test": "vitest",
|
|
56
|
+
"test:ui": "vitest --ui",
|
|
57
|
+
"test:run": "vitest run"
|
|
62
58
|
},
|
|
63
59
|
"peerDependencies": {
|
|
64
60
|
"@nuxt/kit": "^3.18.1",
|
|
@@ -69,9 +65,13 @@
|
|
|
69
65
|
"ofetch": "^1.3.3"
|
|
70
66
|
},
|
|
71
67
|
"devDependencies": {
|
|
68
|
+
"@nuxt/module-builder": "^0.8.4",
|
|
72
69
|
"@types/node": "^24.10.1",
|
|
70
|
+
"@vitest/ui": "^3.2.4",
|
|
73
71
|
"nuxt": "^3.18.1",
|
|
74
72
|
"typescript": "^5.0.0",
|
|
75
|
-
"
|
|
73
|
+
"vite": "^6.0.7",
|
|
74
|
+
"vite-plugin-dts": "^4.3.0",
|
|
75
|
+
"vitest": "^3.2.4"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
addImportsDir,
|
|
6
6
|
addPlugin,
|
|
7
7
|
} from "@nuxt/kit";
|
|
8
|
-
import { ENFYRA_API_PREFIX } from "./
|
|
8
|
+
import { ENFYRA_API_PREFIX } from "./constants/config";
|
|
9
9
|
|
|
10
10
|
export interface ModuleOptions {
|
|
11
11
|
apiUrl: string;
|
|
@@ -65,46 +65,45 @@ export default defineNuxtModule<ModuleOptions>({
|
|
|
65
65
|
|
|
66
66
|
if (!normalizedOptions.apiUrl) {
|
|
67
67
|
addPlugin({
|
|
68
|
-
src: resolve("./
|
|
68
|
+
src: resolve("./runtime/plugin/config-error.client"),
|
|
69
69
|
mode: 'client'
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
addImportsDir(resolve("./
|
|
73
|
+
addImportsDir(resolve("./composables"));
|
|
74
74
|
|
|
75
75
|
nuxt.hook('prepare:types', ({ declarations, references }: any) => {
|
|
76
76
|
references.push({
|
|
77
|
-
path: resolve('./
|
|
77
|
+
path: resolve('./types/nuxt-imports.d.ts'),
|
|
78
78
|
})
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
addServerHandler({
|
|
82
|
-
handler: resolve(
|
|
82
|
+
handler: resolve("./runtime/server/middleware/auth"),
|
|
83
83
|
middleware: true,
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
addServerHandler({
|
|
87
87
|
route: `${apiPrefix}/login`,
|
|
88
|
-
handler: resolve(
|
|
88
|
+
handler: resolve("./runtime/server/api/login.post"),
|
|
89
89
|
method: "post",
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
addServerHandler({
|
|
93
93
|
route: `${apiPrefix}/logout`,
|
|
94
|
-
handler: resolve(
|
|
94
|
+
handler: resolve("./runtime/server/api/logout.post"),
|
|
95
95
|
method: "post",
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
addServerHandler({
|
|
100
100
|
route: "/assets/**",
|
|
101
|
-
handler: resolve(
|
|
101
|
+
handler: resolve("./runtime/server/api/all"),
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
addServerHandler({
|
|
105
105
|
route: `${apiPrefix}/**`,
|
|
106
|
-
handler: resolve(
|
|
106
|
+
handler: resolve("./runtime/server/api/all"),
|
|
107
107
|
});
|
|
108
108
|
},
|
|
109
109
|
});
|
|
110
|
-
|
package/src/utils/url.ts
CHANGED
|
@@ -37,9 +37,6 @@ export function joinUrlPath(...paths: (string | undefined | null)[]): string {
|
|
|
37
37
|
.join('/');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
// Import from #imports at top level
|
|
41
|
-
import { useRequestHeaders, useRequestURL } from '#imports';
|
|
42
|
-
|
|
43
40
|
export function getAppUrl(): string {
|
|
44
41
|
if (process.client && typeof window !== 'undefined') {
|
|
45
42
|
return window.location.origin;
|
|
@@ -47,13 +44,23 @@ export function getAppUrl(): string {
|
|
|
47
44
|
|
|
48
45
|
if (process.server) {
|
|
49
46
|
try {
|
|
47
|
+
let useRequestHeaders: any;
|
|
48
|
+
let useRequestURL: any;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const imports = eval('require("#imports")');
|
|
52
|
+
useRequestHeaders = imports.useRequestHeaders;
|
|
53
|
+
useRequestURL = imports.useRequestURL;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
try {
|
|
51
59
|
const url = useRequestURL();
|
|
52
60
|
if (url) {
|
|
53
61
|
return `${url.protocol}//${url.host}`;
|
|
54
62
|
}
|
|
55
63
|
} catch (e) {
|
|
56
|
-
// useRequestURL might not be available in all contexts
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
const headers = useRequestHeaders();
|