@merkaly/nuxt 0.4.5 → 0.6.0
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.d.mts +8 -3
- package/dist/module.json +2 -2
- package/dist/module.mjs +152 -67
- package/dist/runtime/adapters/create.auth.session.d.ts +9 -0
- package/dist/runtime/adapters/create.auth.session.js +14 -0
- package/dist/runtime/adapters/delete.auth.session.d.ts +1 -0
- package/dist/runtime/adapters/delete.auth.session.js +6 -0
- package/dist/runtime/adapters/read.auth.session.d.ts +9 -0
- package/dist/runtime/adapters/read.auth.session.js +8 -0
- package/dist/runtime/components/app.d.vue.ts +3 -3
- package/dist/runtime/components/app.vue +10 -9
- package/dist/runtime/components/app.vue.d.ts +3 -3
- package/dist/runtime/components/input/InputMoney.d.vue.ts +1 -1
- package/dist/runtime/components/input/InputMoney.vue.d.ts +1 -1
- package/dist/runtime/plugins/api.global.d.ts +1 -1
- package/dist/runtime/plugins/api.global.js +4 -4
- package/dist/runtime/plugins/auth0.client.js +11 -11
- package/dist/runtime/plugins/sentry.global.d.ts +2 -0
- package/dist/runtime/plugins/sentry.global.js +11 -0
- package/dist/runtime/server/middleware/proxy.d.ts +2 -0
- package/dist/runtime/server/middleware/proxy.js +34 -0
- package/package.json +4 -3
package/dist/module.d.mts
CHANGED
|
@@ -4,6 +4,10 @@ export { AdapterArgs, AdapterOptions } from '../dist/runtime/utils/withAdapter.j
|
|
|
4
4
|
export { ApiOptions, HooksOptions, ParamsOptions, RefOptions } from '../dist/runtime/plugins/api.global.js';
|
|
5
5
|
|
|
6
6
|
interface MerkalyModuleOptions {
|
|
7
|
+
api: {
|
|
8
|
+
url: string;
|
|
9
|
+
prefix?: string;
|
|
10
|
+
};
|
|
7
11
|
auth0: {
|
|
8
12
|
audience: string;
|
|
9
13
|
callbackUrl: string;
|
|
@@ -17,9 +21,10 @@ interface MerkalyModuleOptions {
|
|
|
17
21
|
domain: string;
|
|
18
22
|
localhost: string;
|
|
19
23
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
sentry: {
|
|
25
|
+
dsn: string;
|
|
26
|
+
project: string;
|
|
27
|
+
token: string;
|
|
23
28
|
};
|
|
24
29
|
}
|
|
25
30
|
declare const _default: _nuxt_schema.NuxtModule<MerkalyModuleOptions, MerkalyModuleOptions, false>;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,82 +1,167 @@
|
|
|
1
|
-
import { defineNuxtModule,
|
|
2
|
-
import { createJiti } from 'jiti';
|
|
1
|
+
import { defineNuxtModule, useLogger, createResolver, addPlugin, addServerHandler, addRouteMiddleware, addImportsDir, addComponentsDir, addTypeTemplate } from '@nuxt/kit';
|
|
3
2
|
import { defu } from 'defu';
|
|
3
|
+
import { createJiti } from 'jiti';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import svgLoader from 'vite-svg-loader';
|
|
6
6
|
import 'reflect-metadata';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
callbackUrl: "/auth",
|
|
13
|
-
client: "",
|
|
14
|
-
domain: "",
|
|
15
|
-
logoutUrl: "/",
|
|
16
|
-
params: {},
|
|
17
|
-
requiresAuth: false
|
|
18
|
-
},
|
|
19
|
-
plausible: {
|
|
20
|
-
domain: "",
|
|
21
|
-
localhost: ""
|
|
22
|
-
},
|
|
23
|
-
api: {
|
|
24
|
-
url: "/",
|
|
25
|
-
prefix: "/"
|
|
26
|
-
}
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
api: {
|
|
10
|
+
url: "/",
|
|
11
|
+
prefix: "/"
|
|
27
12
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
if (nuxt.options.merkaly?.plausible) {
|
|
38
|
-
dependencies["@nuxtjs/plausible"] = {};
|
|
39
|
-
}
|
|
40
|
-
return dependencies;
|
|
13
|
+
auth0: {
|
|
14
|
+
audience: "",
|
|
15
|
+
callbackUrl: "/auth",
|
|
16
|
+
client: "",
|
|
17
|
+
domain: "",
|
|
18
|
+
logoutUrl: "/",
|
|
19
|
+
params: {},
|
|
20
|
+
requiresAuth: false
|
|
41
21
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
22
|
+
plausible: {
|
|
23
|
+
domain: "",
|
|
24
|
+
localhost: ""
|
|
25
|
+
},
|
|
26
|
+
sentry: {
|
|
27
|
+
dsn: "",
|
|
28
|
+
project: "",
|
|
29
|
+
token: ""
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function hasPlausibleConfig(options) {
|
|
33
|
+
return Boolean(options.plausible?.domain);
|
|
34
|
+
}
|
|
35
|
+
function buildModuleDependencies(options) {
|
|
36
|
+
const dependencies = {
|
|
37
|
+
"@bootstrap-vue-next/nuxt": {},
|
|
38
|
+
"@nuxt/eslint": {},
|
|
39
|
+
"@nuxt/fonts": {},
|
|
40
|
+
"@nuxt/image": {},
|
|
41
|
+
"@sentry/nuxt/module": {},
|
|
42
|
+
"@vueuse/nuxt": {}
|
|
43
|
+
};
|
|
44
|
+
if (hasPlausibleConfig(options)) {
|
|
45
|
+
dependencies["@nuxtjs/plausible"] = {};
|
|
46
|
+
}
|
|
47
|
+
const logger = useLogger("@merkaly/nuxt");
|
|
48
|
+
Object.keys(dependencies).forEach((it) => logger.info(`Loaded ${it} module`));
|
|
49
|
+
return dependencies;
|
|
50
|
+
}
|
|
51
|
+
function configureRuntimeConfig(nuxt, options) {
|
|
52
|
+
nuxt.options.runtimeConfig.public.merkaly = defu(
|
|
53
|
+
options,
|
|
54
|
+
nuxt.options.runtimeConfig.public.merkaly || {}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function configurePlausible(nuxt, options) {
|
|
58
|
+
nuxt.options.plausible = defu(
|
|
59
|
+
{
|
|
47
60
|
apiHost: "https://analytics.merkaly.io",
|
|
48
61
|
domain: options.plausible?.domain,
|
|
49
62
|
enableAutoOutboundTracking: true,
|
|
50
63
|
enableAutoPageviews: true,
|
|
51
|
-
enabled: process.env.NODE_ENV === "production",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
enabled: process.env.NODE_ENV === "production" && hasPlausibleConfig(options),
|
|
65
|
+
ignoredHostnames: ["localhost", options.plausible?.localhost].filter(Boolean)
|
|
66
|
+
},
|
|
67
|
+
nuxt.options.plausible || {}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function configureSentry(nuxt, options) {
|
|
71
|
+
nuxt.options.sentry = defu({
|
|
72
|
+
authToken: options.sentry.token,
|
|
73
|
+
org: "merkaly",
|
|
74
|
+
project: options.sentry.project
|
|
75
|
+
});
|
|
76
|
+
nuxt.options.sourcemap = { client: "hidden", server: true };
|
|
77
|
+
}
|
|
78
|
+
async function loadBootstrapConfig(nuxt) {
|
|
79
|
+
const rootDirResolver = createResolver(nuxt.options.rootDir);
|
|
80
|
+
const bootstrapConfigPath = rootDirResolver.resolve("bootstrap.config.ts");
|
|
81
|
+
if (!existsSync(bootstrapConfigPath)) {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
const jiti = createJiti(import.meta.url);
|
|
85
|
+
const imported = await jiti.import(bootstrapConfigPath).catch(() => ({}));
|
|
86
|
+
return imported.default || {};
|
|
87
|
+
}
|
|
88
|
+
function configureBootstrapVueNext(nuxt, components) {
|
|
89
|
+
nuxt.options.bootstrapVueNext = defu(
|
|
90
|
+
nuxt.options.bootstrapVueNext || {},
|
|
91
|
+
{
|
|
92
|
+
plugin: {
|
|
93
|
+
components
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
function configureAppHead(nuxt) {
|
|
99
|
+
nuxt.options.app?.head?.script?.push({
|
|
100
|
+
crossorigin: "anonymous",
|
|
101
|
+
src: "https://kit.fontawesome.com/55a4b2f4e1.js"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function registerRuntimeFeatures(nuxt, options, resolver) {
|
|
105
|
+
addPlugin({ src: resolver.resolve("./runtime/plugins/api.global") });
|
|
106
|
+
addPlugin({ src: resolver.resolve("./runtime/plugins/auth0.client") });
|
|
107
|
+
addPlugin({ src: resolver.resolve("./runtime/plugins/sentry.global") });
|
|
108
|
+
addServerHandler({
|
|
109
|
+
handler: resolver.resolve("./runtime/server/middleware/proxy"),
|
|
110
|
+
middleware: true
|
|
111
|
+
});
|
|
112
|
+
addRouteMiddleware({
|
|
113
|
+
global: options.auth0.requiresAuth,
|
|
114
|
+
name: "auth",
|
|
115
|
+
path: resolver.resolve("./runtime/middleware/auth")
|
|
116
|
+
});
|
|
117
|
+
addImportsDir(resolver.resolve("./runtime/adapters"));
|
|
118
|
+
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
119
|
+
addImportsDir(resolver.resolve("./runtime/utils"));
|
|
120
|
+
addComponentsDir({
|
|
121
|
+
path: resolver.resolve("./runtime/components"),
|
|
122
|
+
prefix: "MK"
|
|
123
|
+
});
|
|
124
|
+
addTypeTemplate({
|
|
125
|
+
filename: "types/merkaly.d.ts",
|
|
126
|
+
src: resolver.resolve("./runtime/types/nuxt.d.ts")
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function configureVite(nuxt) {
|
|
130
|
+
nuxt.options.vite = defu(
|
|
131
|
+
nuxt.options.vite || {},
|
|
132
|
+
{
|
|
133
|
+
plugins: [svgLoader()]
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const module = defineNuxtModule({
|
|
138
|
+
defaults: defaultOptions,
|
|
139
|
+
meta: {
|
|
140
|
+
name: "@merkaly/nuxt",
|
|
141
|
+
configKey: "merkaly",
|
|
142
|
+
compatibility: { nuxt: ">=3.14.0" }
|
|
143
|
+
},
|
|
144
|
+
moduleDependencies(nuxt) {
|
|
145
|
+
const options = defu(
|
|
146
|
+
nuxt.options.merkaly || {},
|
|
147
|
+
defaultOptions
|
|
148
|
+
);
|
|
149
|
+
return buildModuleDependencies(options);
|
|
150
|
+
},
|
|
151
|
+
async setup(options, nuxt) {
|
|
55
152
|
const logger = useLogger("@merkaly/nuxt");
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
addImportsDir(moduleResolver.resolve("./runtime/composables"));
|
|
70
|
-
addImportsDir(moduleResolver.resolve("./runtime/utils"));
|
|
71
|
-
addComponentsDir({
|
|
72
|
-
path: moduleResolver.resolve("./runtime/components"),
|
|
73
|
-
prefix: "MK"
|
|
74
|
-
});
|
|
75
|
-
nuxt.options["vite"] = defu(nuxt.options["vite"] || {}, { plugins: [svgLoader()] });
|
|
76
|
-
addTypeTemplate({
|
|
77
|
-
filename: "types/merkaly.d.ts",
|
|
78
|
-
src: moduleResolver.resolve("./runtime/types/nuxt.d.ts")
|
|
79
|
-
});
|
|
153
|
+
const resolver = createResolver(import.meta.url);
|
|
154
|
+
configureRuntimeConfig(nuxt, options);
|
|
155
|
+
configurePlausible(nuxt, options);
|
|
156
|
+
configureSentry(nuxt, options);
|
|
157
|
+
const bootstrapComponentsConfig = await loadBootstrapConfig(nuxt);
|
|
158
|
+
if (Object.keys(bootstrapComponentsConfig).length > 0) {
|
|
159
|
+
logger.info("Loading bootstrap.config.ts");
|
|
160
|
+
}
|
|
161
|
+
configureBootstrapVueNext(nuxt, bootstrapComponentsConfig);
|
|
162
|
+
configureAppHead(nuxt);
|
|
163
|
+
registerRuntimeFeatures(nuxt, options, resolver);
|
|
164
|
+
configureVite(nuxt);
|
|
80
165
|
}
|
|
81
166
|
});
|
|
82
167
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface AuthSessionData {
|
|
2
|
+
expiresAt: string | Date;
|
|
3
|
+
issuedAt: string | Date;
|
|
4
|
+
orgId?: string;
|
|
5
|
+
role: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const createAuthSession: (args?: ((args: object) => import("#imports").AdapterArgs<AuthSessionData, Record<string, unknown>, object>) | undefined) => import("#imports").UseApiReturn<AuthSessionData, Record<string, unknown>, object>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useAuth } from "#imports";
|
|
2
|
+
import { withAdapter } from "../utils/withAdapter.js";
|
|
3
|
+
export const createAuthSession = withAdapter(() => {
|
|
4
|
+
const { token } = useAuth();
|
|
5
|
+
return {
|
|
6
|
+
default: () => ({}),
|
|
7
|
+
global: true,
|
|
8
|
+
headers: {
|
|
9
|
+
authorization: token.value ? `Bearer ${token.value}` : ""
|
|
10
|
+
},
|
|
11
|
+
method: "POST",
|
|
12
|
+
uri: "/session"
|
|
13
|
+
};
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deleteAuthSession: (args?: ((args: object) => import("../utils/withAdapter.js").AdapterArgs<undefined, Record<string, unknown>, object>) | undefined) => import("../composables/useApi.js").UseApiReturn<undefined, Record<string, unknown>, object>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface AuthSessionData {
|
|
2
|
+
expiresAt: string | Date;
|
|
3
|
+
issuedAt: string | Date;
|
|
4
|
+
orgId?: string;
|
|
5
|
+
role: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const readAuthSession: (args?: ((args: object) => import("../utils/withAdapter.js").AdapterArgs<AuthSessionData, Record<string, unknown>, object>) | undefined) => import("../composables/useApi.js").UseApiReturn<AuthSessionData, Record<string, unknown>, object>;
|
|
9
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare var
|
|
1
|
+
declare var __VLS_7: {}, __VLS_9: {};
|
|
2
2
|
type __VLS_Slots = {} & {
|
|
3
|
-
loading?: (props: typeof
|
|
3
|
+
loading?: (props: typeof __VLS_7) => any;
|
|
4
4
|
} & {
|
|
5
|
-
default?: (props: typeof
|
|
5
|
+
default?: (props: typeof __VLS_9) => any;
|
|
6
6
|
};
|
|
7
7
|
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
8
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -3,9 +3,11 @@ import { useRoute } from "#app";
|
|
|
3
3
|
import { useAuth, watchOnce, addRouteMiddleware, useNuxtApp } from "#imports";
|
|
4
4
|
import AuthMiddleware from "../middleware/auth";
|
|
5
5
|
import { useNavigation } from "../composables/useNavigation";
|
|
6
|
+
import { useColorMode } from "@vueuse/core";
|
|
6
7
|
const $route = useRoute();
|
|
7
8
|
const { isLoading } = useAuth();
|
|
8
9
|
const { hook } = useNuxtApp();
|
|
10
|
+
useColorMode({ attribute: "data-bs-theme" });
|
|
9
11
|
watchOnce(isLoading, () => AuthMiddleware($route, $route));
|
|
10
12
|
const { defer, regenerate } = useNavigation();
|
|
11
13
|
addRouteMiddleware("navigation", (to) => defer(to), { global: true });
|
|
@@ -14,15 +16,14 @@ hook("page:finish", () => regenerate());
|
|
|
14
16
|
|
|
15
17
|
<template>
|
|
16
18
|
<main>
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
+
<BApp>
|
|
20
|
+
<!-- Mostramos spinner mientras auth se carga -->
|
|
21
|
+
<slot v-if="isLoading" name="loading" />
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<NuxtPage />
|
|
26
|
-
</slot>
|
|
23
|
+
<!-- Renderizamos páginas solo cuando isLoading = false -->
|
|
24
|
+
<slot v-else>
|
|
25
|
+
<NuxtPage />
|
|
26
|
+
</slot>
|
|
27
|
+
</BApp>
|
|
27
28
|
</main>
|
|
28
29
|
</template>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare var
|
|
1
|
+
declare var __VLS_7: {}, __VLS_9: {};
|
|
2
2
|
type __VLS_Slots = {} & {
|
|
3
|
-
loading?: (props: typeof
|
|
3
|
+
loading?: (props: typeof __VLS_7) => any;
|
|
4
4
|
} & {
|
|
5
|
-
default?: (props: typeof
|
|
5
|
+
default?: (props: typeof __VLS_9) => any;
|
|
6
6
|
};
|
|
7
7
|
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
8
8
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -77,9 +77,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
77
77
|
decimal: string;
|
|
78
78
|
min: number;
|
|
79
79
|
max: number;
|
|
80
|
-
prefix: string;
|
|
81
80
|
placeholder: string;
|
|
82
81
|
precision: number;
|
|
82
|
+
prefix: string;
|
|
83
83
|
suffix: string;
|
|
84
84
|
thousands: string;
|
|
85
85
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -77,9 +77,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
77
77
|
decimal: string;
|
|
78
78
|
min: number;
|
|
79
79
|
max: number;
|
|
80
|
-
prefix: string;
|
|
81
80
|
placeholder: string;
|
|
82
81
|
precision: number;
|
|
82
|
+
prefix: string;
|
|
83
83
|
suffix: string;
|
|
84
84
|
thousands: string;
|
|
85
85
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -37,9 +37,9 @@ export interface ParamsOptions {
|
|
|
37
37
|
body?: FetchOptions['body'];
|
|
38
38
|
controller?: AbortController;
|
|
39
39
|
default?: () => unknown;
|
|
40
|
+
global?: boolean;
|
|
40
41
|
headers?: FetchOptions['headers'];
|
|
41
42
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
42
|
-
prefix?: string;
|
|
43
43
|
query?: FetchOptions['query'];
|
|
44
44
|
timeout?: FetchOptions['timeout'];
|
|
45
45
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { defineNuxtPlugin
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
2
|
import { useAuth } from "#imports";
|
|
3
|
+
const GLOBAL_API_HEADER = "x-merkaly-global";
|
|
3
4
|
export default defineNuxtPlugin(({ provide }) => provide("api", async (url, options = {}) => {
|
|
4
|
-
const { public: $config } = useRuntimeConfig();
|
|
5
5
|
const { tenant, token } = useAuth();
|
|
6
6
|
await $fetch(url, {
|
|
7
|
-
|
|
8
|
-
baseURL: new URL(options.prefix || $config.merkaly.api.prefix || "/", $config.merkaly.api.url).href,
|
|
7
|
+
baseURL: "/api",
|
|
9
8
|
body: options?.body,
|
|
10
9
|
headers: {
|
|
11
10
|
authorization: token.value ? `Bearer ${token.value}` : "",
|
|
12
11
|
identity: tenant.value,
|
|
12
|
+
[GLOBAL_API_HEADER]: options.global ? "true" : "",
|
|
13
13
|
...options?.headers
|
|
14
14
|
},
|
|
15
15
|
method: options?.method,
|
|
@@ -40,17 +40,17 @@ export default defineNuxtPlugin(async ({ callHook, hook }) => {
|
|
|
40
40
|
redirect_uri: redirectUri
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
auth0.linkWithConnection = (connection) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
43
|
+
auth0.linkWithConnection = async (connection) => {
|
|
44
|
+
await linkingClient.loginWithPopup({ authorizationParams: { connection } });
|
|
45
|
+
const claims = await linkingClient.getIdTokenClaims();
|
|
46
|
+
if (!claims?.sub) {
|
|
47
|
+
throw new Error("Failed to get ID token for linking");
|
|
48
|
+
}
|
|
49
|
+
const [provider, ...userIdParts] = claims.sub.split("|");
|
|
50
|
+
const userId = userIdParts.join("|");
|
|
51
|
+
const body = { provider, userId };
|
|
52
|
+
const { $api } = useNuxtApp();
|
|
53
|
+
return await $api("/identities", { body, global: true, method: "POST" });
|
|
54
54
|
};
|
|
55
55
|
const isAuthCallback = window.location.pathname === callbackPath;
|
|
56
56
|
if (!isAuthCallback) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
import { setUser } from "@sentry/nuxt";
|
|
3
|
+
export default defineNuxtPlugin(async ({ hook }) => {
|
|
4
|
+
hook("merkaly:auth", (user) => {
|
|
5
|
+
return setUser(user ? {
|
|
6
|
+
id: user.sub,
|
|
7
|
+
email: user.email,
|
|
8
|
+
username: user.name
|
|
9
|
+
} : null);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineEventHandler, getRequestURL, proxyRequest } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
const GLOBAL_API_HEADER = "x-merkaly-global";
|
|
4
|
+
const API_PREFIX_PATTERN = /^\/api\/?/;
|
|
5
|
+
const API_ROUTE_PATTERN = /^\/api(?:\/|$)/;
|
|
6
|
+
const EDGE_SLASH_PATTERN = /^\/|\/$/g;
|
|
7
|
+
function normalizeSegment(value) {
|
|
8
|
+
return value.replace(EDGE_SLASH_PATTERN, "");
|
|
9
|
+
}
|
|
10
|
+
function resolveProxyPath(prefix, pathname, search) {
|
|
11
|
+
const normalizedPathname = pathname.replace(API_PREFIX_PATTERN, "");
|
|
12
|
+
return `/${[prefix, normalizedPathname].map(normalizeSegment).filter(Boolean).join("/")}${search}`;
|
|
13
|
+
}
|
|
14
|
+
function isGlobalRequest(value) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return value.includes("true");
|
|
17
|
+
}
|
|
18
|
+
return value === "true";
|
|
19
|
+
}
|
|
20
|
+
export default defineEventHandler((event) => {
|
|
21
|
+
if (!API_ROUTE_PATTERN.test(event.path)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const { public: $config } = useRuntimeConfig();
|
|
25
|
+
const targetOrigin = new URL($config.merkaly.api.url);
|
|
26
|
+
const url = getRequestURL(event);
|
|
27
|
+
const prefix = isGlobalRequest(event.node.req.headers[GLOBAL_API_HEADER]) ? "" : $config.merkaly.api.prefix;
|
|
28
|
+
const path = resolveProxyPath(prefix, url.pathname, url.search);
|
|
29
|
+
event.node.req.headers["x-forwarded-host"] = url.host;
|
|
30
|
+
if (import.meta.dev && targetOrigin.hostname.endsWith(".test")) {
|
|
31
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
32
|
+
}
|
|
33
|
+
return proxyRequest(event, new URL(path, targetOrigin).toString());
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkaly/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/merkaly-io/nuxt.git"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@auth0/auth0-spa-js": "^2.17.0",
|
|
46
|
-
"@bootstrap-vue-next/nuxt": "^0.
|
|
46
|
+
"@bootstrap-vue-next/nuxt": "^0.44.1",
|
|
47
47
|
"@nuxt/devtools": "^3.2.1",
|
|
48
48
|
"@nuxt/eslint": "1.15.1",
|
|
49
49
|
"@nuxt/eslint-config": "^1.15.1",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@nuxt/image": "^2.0.0",
|
|
52
52
|
"@nuxt/kit": "^4.4.2",
|
|
53
53
|
"@nuxtjs/plausible": "^3.0.1",
|
|
54
|
+
"@sentry/nuxt": "^10.47.0",
|
|
54
55
|
"@types/node": "latest",
|
|
55
56
|
"@types/vue-select": "^3.16.8",
|
|
56
57
|
"@vueuse/components": "^14.2.0",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"@vueuse/integrations": "^14.2.0",
|
|
59
60
|
"@vueuse/nuxt": "^14.2.0",
|
|
60
61
|
"bootstrap": "^5.3.8",
|
|
61
|
-
"bootstrap-vue-next": "^0.
|
|
62
|
+
"bootstrap-vue-next": "^0.44.1",
|
|
62
63
|
"change-case": "^5",
|
|
63
64
|
"class-transformer": "^0.5.1",
|
|
64
65
|
"class-validator": "^0.15.1",
|