@inzombieland/nuxt-common 1.18.7 → 1.18.8
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.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/api/index.d.ts +6 -0
- package/dist/runtime/api/user-actions.d.ts +0 -6
- package/dist/runtime/api/user-actions.mjs +2 -26
- package/dist/runtime/packages/core/index.d.ts +18 -0
- package/dist/runtime/packages/core/init-application.mjs +3 -1
- package/dist/runtime/packages/core/package.json +1 -1
- package/dist/runtime/packages/core/user-actions.d.ts +6 -0
- package/dist/runtime/packages/core/user-actions.mjs +15 -1
- package/dist/runtime/plugin.mjs +11 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addPlugin, addComponent } from '@nuxt/kit';
|
|
3
3
|
|
|
4
4
|
const name = "@inzombieland/nuxt-common";
|
|
5
|
-
const version = "1.18.
|
|
5
|
+
const version = "1.18.8";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -28,5 +28,11 @@ declare const fetch: Fetch, getUser: () => Promise<import("src/runtime/packages/
|
|
|
28
28
|
fetchActiveSessions: () => Promise<{
|
|
29
29
|
sessions: import("src/runtime/packages/core/types").ActiveSession[];
|
|
30
30
|
}>;
|
|
31
|
+
changeTheme: (body: {
|
|
32
|
+
theme: "light" | "dark";
|
|
33
|
+
}) => Promise<void>;
|
|
34
|
+
changeLocale: (body: {
|
|
35
|
+
locale: string;
|
|
36
|
+
}) => Promise<void>;
|
|
31
37
|
};
|
|
32
38
|
export { fetch, getUser, useApiFetch, userActions };
|
|
@@ -87,12 +87,6 @@ export declare const changePhone: (body: {
|
|
|
87
87
|
phone: string;
|
|
88
88
|
password: string;
|
|
89
89
|
}) => Promise<void>;
|
|
90
|
-
export declare const changeTheme: (body: {
|
|
91
|
-
theme: "light" | "dark";
|
|
92
|
-
}) => Promise<void>;
|
|
93
|
-
export declare const changeLocale: (body: {
|
|
94
|
-
locale: string;
|
|
95
|
-
}) => Promise<void>;
|
|
96
90
|
export declare const changeAvatar: (body: FormData) => Promise<void>;
|
|
97
91
|
export declare const deleteAvatar: () => Promise<void>;
|
|
98
92
|
export declare const fetchActiveSessions: () => Promise<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useRequestHeaders } from "#imports";
|
|
2
|
+
import { useUser } from "../packages/core/index.mjs";
|
|
3
3
|
import { flush, setToken, updateUser } from "../packages/core/api-client.mjs";
|
|
4
4
|
import { fetch, getUser, userActions } from "./index.mjs";
|
|
5
5
|
export const signIn = userActions.signIn;
|
|
@@ -114,30 +114,6 @@ export const changePhone = async (body) => {
|
|
|
114
114
|
await fetch("/account/1/change/phone", { body, method: "POST" });
|
|
115
115
|
updateUser({ phone: body.phone });
|
|
116
116
|
};
|
|
117
|
-
export const changeTheme = async (body) => {
|
|
118
|
-
const user = useUser();
|
|
119
|
-
if (user.value) {
|
|
120
|
-
await fetch("/account/1/change/theme", { body, method: "POST" });
|
|
121
|
-
updateUser(body);
|
|
122
|
-
}
|
|
123
|
-
if (typeof window !== "undefined") {
|
|
124
|
-
const theme = useThemeMode();
|
|
125
|
-
theme.value = { value: body.theme };
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
export const changeLocale = async (body) => {
|
|
129
|
-
const user = useUser();
|
|
130
|
-
if (user.value) {
|
|
131
|
-
await fetch("/account/1/change/locale", { body, method: "POST" });
|
|
132
|
-
updateUser(body);
|
|
133
|
-
}
|
|
134
|
-
if (typeof window !== "undefined") {
|
|
135
|
-
const localeCookie = useCookie("locale", { maxAge: 60 * 60 * 24 * 365 });
|
|
136
|
-
localeCookie.value = body.locale;
|
|
137
|
-
const locale = useAppLocale();
|
|
138
|
-
locale.value = { value: body.locale };
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
117
|
export const changeAvatar = async (body) => {
|
|
142
118
|
const { avatar } = await fetch("/account/1/upload/avatar", { body, method: "POST" });
|
|
143
119
|
updateUser({ avatar });
|
|
@@ -20,6 +20,12 @@ export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
|
|
|
20
20
|
fetchActiveSessions: () => Promise<{
|
|
21
21
|
sessions: import("./types").ActiveSession[];
|
|
22
22
|
}>;
|
|
23
|
+
changeTheme: (body: {
|
|
24
|
+
theme: "light" | "dark";
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
changeLocale: (body: {
|
|
27
|
+
locale: string;
|
|
28
|
+
}) => Promise<void>;
|
|
23
29
|
};
|
|
24
30
|
};
|
|
25
31
|
export declare const useUserActions: () => Ref<{
|
|
@@ -34,6 +40,12 @@ export declare const useUserActions: () => Ref<{
|
|
|
34
40
|
fetchActiveSessions: () => Promise<{
|
|
35
41
|
sessions: import("./types").ActiveSession[];
|
|
36
42
|
}>;
|
|
43
|
+
changeTheme: (body: {
|
|
44
|
+
theme: "light" | "dark";
|
|
45
|
+
}) => Promise<void>;
|
|
46
|
+
changeLocale: (body: {
|
|
47
|
+
locale: string;
|
|
48
|
+
}) => Promise<void>;
|
|
37
49
|
}, {
|
|
38
50
|
signIn: (body: {
|
|
39
51
|
username: string;
|
|
@@ -46,4 +58,10 @@ export declare const useUserActions: () => Ref<{
|
|
|
46
58
|
fetchActiveSessions: () => Promise<{
|
|
47
59
|
sessions: import("./types").ActiveSession[];
|
|
48
60
|
}>;
|
|
61
|
+
changeTheme: (body: {
|
|
62
|
+
theme: "light" | "dark";
|
|
63
|
+
}) => Promise<void>;
|
|
64
|
+
changeLocale: (body: {
|
|
65
|
+
locale: string;
|
|
66
|
+
}) => Promise<void>;
|
|
49
67
|
}> | undefined;
|
|
@@ -14,6 +14,7 @@ function initApplication() {
|
|
|
14
14
|
const theme = useThemeMode();
|
|
15
15
|
const locale = useAppLocale();
|
|
16
16
|
const i18n = useI18n();
|
|
17
|
+
const userActions = useUserActions();
|
|
17
18
|
watch(user, (user2) => {
|
|
18
19
|
if (user2 && user2.theme !== theme.value?.value) {
|
|
19
20
|
theme.value = { value: user2.theme };
|
|
@@ -34,6 +35,7 @@ function initApplication() {
|
|
|
34
35
|
document.documentElement.classList.add("light", "van-theme-light");
|
|
35
36
|
StyleProvider(null);
|
|
36
37
|
}
|
|
38
|
+
userActions?.value.changeTheme({ theme: theme2?.value });
|
|
37
39
|
},
|
|
38
40
|
{ immediate: true }
|
|
39
41
|
);
|
|
@@ -51,6 +53,7 @@ function initApplication() {
|
|
|
51
53
|
VantLocale.use(locale2, ruRU);
|
|
52
54
|
VarletLocale.add("en-US", VarletLocale.enUS);
|
|
53
55
|
}
|
|
56
|
+
userActions?.value.changeLocale({ locale: locale2?.value });
|
|
54
57
|
},
|
|
55
58
|
{ immediate: true }
|
|
56
59
|
);
|
|
@@ -73,7 +76,6 @@ function initApplication() {
|
|
|
73
76
|
}
|
|
74
77
|
const visitor = useVisitor();
|
|
75
78
|
if (session?.status === "SignedOut" && session?.visitorId === visitor.value?.id) {
|
|
76
|
-
const userActions = useUserActions();
|
|
77
79
|
const data = await userActions?.value.fetchActiveSessions();
|
|
78
80
|
const isCurrentSession = data?.sessions.some((s) => s.isCurrentSession && s.id === session?.sessionId);
|
|
79
81
|
if (isCurrentSession) {
|
|
@@ -12,4 +12,10 @@ export declare const createApiUserActions: (fetch: Fetch, config: FetchConfig, g
|
|
|
12
12
|
fetchActiveSessions: () => Promise<{
|
|
13
13
|
sessions: ActiveSession[];
|
|
14
14
|
}>;
|
|
15
|
+
changeTheme: (body: {
|
|
16
|
+
theme: "light" | "dark";
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
changeLocale: (body: {
|
|
19
|
+
locale: string;
|
|
20
|
+
}) => Promise<void>;
|
|
15
21
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { flush, setToken } from "./api-client.mjs";
|
|
1
|
+
import { flush, setToken, updateUser } from "./api-client.mjs";
|
|
2
2
|
import { useUser } from "./composables/index.mjs";
|
|
3
3
|
import { once } from "./helpers/index.mjs";
|
|
4
4
|
export const createApiUserActions = once(
|
|
@@ -32,6 +32,20 @@ export const createApiUserActions = once(
|
|
|
32
32
|
},
|
|
33
33
|
fetchActiveSessions: async () => {
|
|
34
34
|
return await fetch("/account/1/sessions");
|
|
35
|
+
},
|
|
36
|
+
changeTheme: async (body) => {
|
|
37
|
+
const user = useUser();
|
|
38
|
+
if (user.value) {
|
|
39
|
+
await fetch("/account/1/change/theme", { body, method: "POST" });
|
|
40
|
+
updateUser(body);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
changeLocale: async (body) => {
|
|
44
|
+
const user = useUser();
|
|
45
|
+
if (user.value) {
|
|
46
|
+
await fetch("/account/1/change/locale", { body, method: "POST" });
|
|
47
|
+
updateUser(body);
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
50
|
};
|
|
37
51
|
}
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { addRouteMiddleware, defineNuxtPlugin } from "#app";
|
|
2
|
-
import { useNuxtApp, useRequestHeaders, useRuntimeConfig, useState } from "#imports";
|
|
2
|
+
import { useCookie, useNuxtApp, useRequestHeaders, useRuntimeConfig, useState } from "#imports";
|
|
3
3
|
import { watch } from "vue";
|
|
4
4
|
import { fetch, getUser } from "./api/index.mjs";
|
|
5
5
|
import { authMiddleware, guestMiddleware, localeMiddleware } from "./middleware/index.mjs";
|
|
6
|
-
import { defineVuePlugins, useThemeMode } from "./packages/core/index.mjs";
|
|
6
|
+
import { defineVuePlugins, useAppLocale, useThemeMode } from "./packages/core/index.mjs";
|
|
7
7
|
import { flush, setToken, setUser } from "./packages/core/api-client.mjs";
|
|
8
8
|
const useAuth = () => {
|
|
9
9
|
return useState("auth", () => null);
|
|
@@ -14,6 +14,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
14
14
|
const runtimeConfig = useRuntimeConfig();
|
|
15
15
|
const { $mobileApp } = useNuxtApp();
|
|
16
16
|
const theme = useThemeMode();
|
|
17
|
+
const locale = useAppLocale();
|
|
17
18
|
if (runtimeConfig.public.ssr && import.meta.server || !runtimeConfig.public.ssr) {
|
|
18
19
|
flush();
|
|
19
20
|
if (import.meta.server) {
|
|
@@ -40,6 +41,14 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
40
41
|
},
|
|
41
42
|
{ immediate: true }
|
|
42
43
|
);
|
|
44
|
+
watch(
|
|
45
|
+
locale,
|
|
46
|
+
(locale2) => {
|
|
47
|
+
const localeCookie = useCookie("locale", { maxAge: 60 * 60 * 24 * 365 });
|
|
48
|
+
localeCookie.value = locale2?.value;
|
|
49
|
+
},
|
|
50
|
+
{ immediate: true }
|
|
51
|
+
);
|
|
43
52
|
});
|
|
44
53
|
addRouteMiddleware("auth", authMiddleware, { global: false });
|
|
45
54
|
addRouteMiddleware("guest", guestMiddleware, { global: false });
|