@inzombieland/nuxt-common 1.18.13 → 1.18.15
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/packages/core/AppProvider.vue +10 -4
- package/dist/runtime/packages/core/api-client.d.ts +0 -2
- package/dist/runtime/packages/core/api-client.mjs +5 -5
- package/dist/runtime/packages/core/comet-client.mjs +6 -3
- package/dist/runtime/packages/core/composables/index.d.ts +2 -0
- package/dist/runtime/packages/core/composables/index.mjs +2 -0
- package/dist/runtime/packages/core/composables/use-api-actions.d.ts +13 -0
- package/dist/runtime/packages/core/composables/use-api-actions.mjs +5 -0
- package/dist/runtime/packages/core/composables/use-cookies.d.ts +27 -0
- package/dist/runtime/packages/core/composables/use-cookies.mjs +152 -0
- package/dist/runtime/packages/core/composables/use-subscribe.d.ts +1 -1
- package/dist/runtime/packages/core/composables/use-subscribe.mjs +2 -1
- package/dist/runtime/packages/core/get-user.mjs +3 -4
- package/dist/runtime/packages/core/index.d.ts +1 -6
- package/dist/runtime/packages/core/index.mjs +13 -8
- package/dist/runtime/packages/core/init-application.mjs +3 -1
- package/dist/runtime/packages/core/package.json +5 -1
- package/dist/runtime/plugin.mjs +2 -11
- 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.15";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { onMounted, ref } from "vue"
|
|
3
|
-
import
|
|
2
|
+
import { onBeforeMount, onMounted, ref } from "vue"
|
|
3
|
+
import bus from "./bus"
|
|
4
4
|
import { useThemeMode, useUser } from "./index"
|
|
5
5
|
import type { ConfigProviderTheme } from "vant"
|
|
6
6
|
import "@vant/touch-emulator"
|
|
@@ -9,12 +9,18 @@ const theme = useThemeMode()
|
|
|
9
9
|
const user = useUser()
|
|
10
10
|
const appLoading = ref(Boolean(user.value))
|
|
11
11
|
|
|
12
|
+
onBeforeMount(() => {
|
|
13
|
+
bus.publish("app:beforeMount", true)
|
|
14
|
+
})
|
|
15
|
+
|
|
12
16
|
onMounted(() => {
|
|
13
17
|
appLoading.value = false
|
|
14
18
|
})
|
|
19
|
+
</script>
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
export const useBus = () => {
|
|
23
|
+
return bus
|
|
18
24
|
}
|
|
19
25
|
</script>
|
|
20
26
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import bus from "./bus";
|
|
2
1
|
import type { Fetch, FetchConfig, FetchExtraOptions as FetchOptions, User } from "./types";
|
|
3
|
-
export { bus };
|
|
4
2
|
export declare const setUser: (newUser?: User | null) => void;
|
|
5
3
|
export declare const updateUser: (newUser: Partial<User>) => void;
|
|
6
4
|
export declare const getToken: () => string | null | undefined;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useUser, useVisitor } from "./composables/index.mjs";
|
|
1
|
+
import { useApiActions, useUser, useVisitor } from "./composables/index.mjs";
|
|
3
2
|
import { apiHelper, once } from "./helpers/index.mjs";
|
|
4
|
-
import {
|
|
5
|
-
export { bus };
|
|
3
|
+
import { useBus } from "./index.mjs";
|
|
6
4
|
let token = null;
|
|
7
5
|
export const setUser = (newUser) => {
|
|
8
6
|
const user = useUser();
|
|
9
7
|
user.value = newUser;
|
|
8
|
+
const bus = useBus();
|
|
10
9
|
bus.publish("user:onUpdated", user.value);
|
|
11
10
|
};
|
|
12
11
|
export const updateUser = (newUser) => {
|
|
@@ -27,6 +26,7 @@ export const flush = () => {
|
|
|
27
26
|
};
|
|
28
27
|
const eventHandler = (requestID, eventName) => {
|
|
29
28
|
return new Promise((resolve, reject) => {
|
|
29
|
+
const bus = useBus();
|
|
30
30
|
const subscription = bus.subscribe(eventName, (data) => {
|
|
31
31
|
if (requestID !== data?.requestID) {
|
|
32
32
|
return;
|
|
@@ -117,7 +117,7 @@ const fetchRequest = (url, options = {}, fetch, config) => {
|
|
|
117
117
|
const { status } = error?.response ?? { status: 500 };
|
|
118
118
|
if (status === 401 && url !== "/account/1/offline") {
|
|
119
119
|
const apiActions = useApiActions();
|
|
120
|
-
await apiActions
|
|
120
|
+
await apiActions.value?.refreshToken?.();
|
|
121
121
|
return request();
|
|
122
122
|
}
|
|
123
123
|
throw errorHandler(error);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Centrifuge } from "centrifuge";
|
|
2
|
-
import {
|
|
2
|
+
import { getToken } from "./api-client.mjs";
|
|
3
|
+
import { useApiActions } from "./composables/index.mjs";
|
|
3
4
|
import { apiHelper } from "./helpers/index.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { useBus } from "./index.mjs";
|
|
5
6
|
if (typeof window !== "undefined" && import.meta.env.MODE !== "production") {
|
|
6
7
|
window.wsPublish = (eventName, data) => {
|
|
8
|
+
const bus = useBus();
|
|
7
9
|
setTimeout(() => bus.publish(`WS.${eventName}`, data), 0);
|
|
8
10
|
};
|
|
9
11
|
}
|
|
@@ -27,10 +29,11 @@ export function newCometClient(user, cometServerURL) {
|
|
|
27
29
|
debug: import.meta.env.MODE !== "production",
|
|
28
30
|
getToken: async () => {
|
|
29
31
|
const apiActions = useApiActions();
|
|
30
|
-
return await apiActions
|
|
32
|
+
return await apiActions.value?.refreshToken?.() ?? "";
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
35
|
const publish = (eventName, data) => () => {
|
|
36
|
+
const bus = useBus();
|
|
34
37
|
bus.publish(`WS.${eventName}`, apiHelper.convertToClient(data));
|
|
35
38
|
};
|
|
36
39
|
let userSubscription;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "../helpers/composables";
|
|
2
2
|
export { useActiveSessions } from "./use-active-sessions";
|
|
3
|
+
export { useApiActions } from "./use-api-actions";
|
|
3
4
|
export { useAppLocale } from "./use-app-locale";
|
|
5
|
+
export { useCookies } from "./use-cookies";
|
|
4
6
|
export { useSubscribe } from "./use-subscribe";
|
|
5
7
|
export { useThemeMode } from "./use-theme-mode";
|
|
6
8
|
export { useUser } from "./use-user";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "../helpers/composables.mjs";
|
|
2
2
|
export { useActiveSessions } from "./use-active-sessions.mjs";
|
|
3
|
+
export { useApiActions } from "./use-api-actions.mjs";
|
|
3
4
|
export { useAppLocale } from "./use-app-locale.mjs";
|
|
5
|
+
export { useCookies } from "./use-cookies.mjs";
|
|
4
6
|
export { useSubscribe } from "./use-subscribe.mjs";
|
|
5
7
|
export { useThemeMode } from "./use-theme-mode.mjs";
|
|
6
8
|
export { useUser } from "./use-user.mjs";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const useApiActions: () => import("vue").Ref<{
|
|
2
|
+
initialized: boolean;
|
|
3
|
+
getVisitorIdentifier?: (() => Promise<void>) | undefined;
|
|
4
|
+
refreshToken?: (() => Promise<string>) | undefined;
|
|
5
|
+
}, {
|
|
6
|
+
initialized: boolean;
|
|
7
|
+
getVisitorIdentifier?: () => Promise<void>;
|
|
8
|
+
refreshToken?: () => Promise<string>;
|
|
9
|
+
} | {
|
|
10
|
+
initialized: boolean;
|
|
11
|
+
getVisitorIdentifier?: (() => Promise<void>) | undefined;
|
|
12
|
+
refreshToken?: (() => Promise<string>) | undefined;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CookieParseOptions, type CookieSerializeOptions } from "cookie-es";
|
|
2
|
+
import { type Ref } from "vue";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
cookieStore?: {
|
|
6
|
+
addEventListener: (type: "change", listener: (event: any) => void) => void;
|
|
7
|
+
removeEventListener: (type: "change", listener: (event: any) => void) => void;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
type _CookieOptions = Omit<CookieSerializeOptions & CookieParseOptions, "decode" | "encode">;
|
|
12
|
+
export interface CookieOptions<T = any> extends _CookieOptions {
|
|
13
|
+
decode?: (value: string) => T;
|
|
14
|
+
encode?: (value: T) => string;
|
|
15
|
+
default?: () => T | Ref<T>;
|
|
16
|
+
watch?: boolean | "shallow";
|
|
17
|
+
readonly?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface CookieRef<T> extends Ref<T> {
|
|
20
|
+
}
|
|
21
|
+
export declare function useCookies<T = string | null | undefined>(name: string, _opts?: CookieOptions<T> & {
|
|
22
|
+
readonly?: false;
|
|
23
|
+
}): CookieRef<T>;
|
|
24
|
+
export declare function useCookies<T = string | null | undefined>(name: string, _opts: CookieOptions<T> & {
|
|
25
|
+
readonly: true;
|
|
26
|
+
}): Readonly<CookieRef<T>>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { parse, serialize } from "cookie-es";
|
|
2
|
+
import destr from "destr";
|
|
3
|
+
import { klona } from "klona";
|
|
4
|
+
import { isEqual } from "ohash";
|
|
5
|
+
import { customRef, getCurrentScope, nextTick, onScopeDispose, ref, watch } from "vue";
|
|
6
|
+
const CookieDefaults = {
|
|
7
|
+
path: "/",
|
|
8
|
+
watch: true,
|
|
9
|
+
decode: (val) => destr(decodeURIComponent(val)),
|
|
10
|
+
encode: (val) => encodeURIComponent(typeof val === "string" ? val : JSON.stringify(val))
|
|
11
|
+
};
|
|
12
|
+
const store = typeof window !== "undefined" ? window.cookieStore : void 0;
|
|
13
|
+
export function useCookies(name, _opts) {
|
|
14
|
+
const opts = { ...CookieDefaults, ..._opts };
|
|
15
|
+
opts.filter ??= (key) => key === name;
|
|
16
|
+
const cookies = readRawCookies(opts) || {};
|
|
17
|
+
let delay;
|
|
18
|
+
if (opts.maxAge !== void 0) {
|
|
19
|
+
delay = opts.maxAge * 1e3;
|
|
20
|
+
} else if (opts.expires) {
|
|
21
|
+
delay = opts.expires.getTime() - Date.now();
|
|
22
|
+
}
|
|
23
|
+
const hasExpired = delay !== void 0 && delay <= 0;
|
|
24
|
+
const shouldSetInitialClientCookie = hasExpired || cookies[name] === void 0 || cookies[name] === null;
|
|
25
|
+
const cookieValue = klona(hasExpired ? void 0 : cookies[name] ?? opts.default?.());
|
|
26
|
+
const cookie = delay && !hasExpired ? cookieRef(cookieValue, delay, opts.watch && opts.watch !== "shallow") : ref(cookieValue);
|
|
27
|
+
if (import.meta.env.MODE !== "production" && hasExpired) {
|
|
28
|
+
console.warn(`not setting cookie \`${name}\` as it has already expired.`);
|
|
29
|
+
}
|
|
30
|
+
let channel = null;
|
|
31
|
+
try {
|
|
32
|
+
if (!store && typeof BroadcastChannel !== "undefined") {
|
|
33
|
+
channel = new BroadcastChannel(`app:cookies:${name}`);
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
const callback = (force = false) => {
|
|
38
|
+
if (!force && (opts.readonly || isEqual(cookie.value, cookies[name]))) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
writeClientCookie(name, cookie.value, opts);
|
|
42
|
+
cookies[name] = klona(cookie.value);
|
|
43
|
+
channel?.postMessage({ value: opts.encode(cookie.value) });
|
|
44
|
+
};
|
|
45
|
+
const handleChange = (data) => {
|
|
46
|
+
const value = data.refresh ? readRawCookies(opts)?.[name] : opts.decode(data.value);
|
|
47
|
+
watchPaused = true;
|
|
48
|
+
cookie.value = value;
|
|
49
|
+
cookies[name] = klona(value);
|
|
50
|
+
nextTick(() => {
|
|
51
|
+
watchPaused = false;
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
let watchPaused = false;
|
|
55
|
+
const hasScope = !!getCurrentScope();
|
|
56
|
+
if (hasScope) {
|
|
57
|
+
onScopeDispose(() => {
|
|
58
|
+
watchPaused = true;
|
|
59
|
+
callback();
|
|
60
|
+
channel?.close();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (store) {
|
|
64
|
+
const changeHandler = (event) => {
|
|
65
|
+
const changedCookie = event.changed.find((c) => c.name === name);
|
|
66
|
+
const removedCookie = event.deleted.find((c) => c.name === name);
|
|
67
|
+
if (changedCookie) {
|
|
68
|
+
handleChange({ value: changedCookie.value });
|
|
69
|
+
}
|
|
70
|
+
if (removedCookie) {
|
|
71
|
+
handleChange({ value: null });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
store.addEventListener("change", changeHandler);
|
|
75
|
+
if (hasScope) {
|
|
76
|
+
onScopeDispose(() => store.removeEventListener("change", changeHandler));
|
|
77
|
+
}
|
|
78
|
+
} else if (channel) {
|
|
79
|
+
channel.onmessage = ({ data }) => handleChange(data);
|
|
80
|
+
}
|
|
81
|
+
if (opts.watch) {
|
|
82
|
+
watch(
|
|
83
|
+
cookie,
|
|
84
|
+
() => {
|
|
85
|
+
if (watchPaused) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
callback();
|
|
89
|
+
},
|
|
90
|
+
{ deep: opts.watch !== "shallow" }
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
if (shouldSetInitialClientCookie) {
|
|
94
|
+
callback(shouldSetInitialClientCookie);
|
|
95
|
+
}
|
|
96
|
+
return cookie;
|
|
97
|
+
}
|
|
98
|
+
function readRawCookies(opts = {}) {
|
|
99
|
+
return parse(document.cookie, opts);
|
|
100
|
+
}
|
|
101
|
+
function serializeCookie(name, value, opts = {}) {
|
|
102
|
+
if (value === null || value === void 0) {
|
|
103
|
+
return serialize(name, value, { ...opts, maxAge: -1 });
|
|
104
|
+
}
|
|
105
|
+
return serialize(name, value, opts);
|
|
106
|
+
}
|
|
107
|
+
function writeClientCookie(name, value, opts = {}) {
|
|
108
|
+
document.cookie = serializeCookie(name, value, opts);
|
|
109
|
+
}
|
|
110
|
+
const MAX_TIMEOUT_DELAY = 2147483647;
|
|
111
|
+
function cookieRef(value, delay, shouldWatch) {
|
|
112
|
+
let timeout;
|
|
113
|
+
let unsubscribe;
|
|
114
|
+
let elapsed = 0;
|
|
115
|
+
const internalRef = shouldWatch ? ref(value) : { value };
|
|
116
|
+
if (getCurrentScope()) {
|
|
117
|
+
onScopeDispose(() => {
|
|
118
|
+
unsubscribe?.();
|
|
119
|
+
clearTimeout(timeout);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return customRef((track, trigger) => {
|
|
123
|
+
if (shouldWatch) {
|
|
124
|
+
unsubscribe = watch(internalRef, trigger);
|
|
125
|
+
}
|
|
126
|
+
function createExpirationTimeout() {
|
|
127
|
+
elapsed = 0;
|
|
128
|
+
clearTimeout(timeout);
|
|
129
|
+
const timeRemaining = delay - elapsed;
|
|
130
|
+
const timeoutLength = Math.min(timeRemaining, MAX_TIMEOUT_DELAY);
|
|
131
|
+
timeout = setTimeout(() => {
|
|
132
|
+
elapsed += timeoutLength;
|
|
133
|
+
if (elapsed < delay) {
|
|
134
|
+
return createExpirationTimeout();
|
|
135
|
+
}
|
|
136
|
+
internalRef.value = void 0;
|
|
137
|
+
trigger();
|
|
138
|
+
}, timeoutLength);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
get() {
|
|
142
|
+
track();
|
|
143
|
+
return internalRef.value;
|
|
144
|
+
},
|
|
145
|
+
set(newValue) {
|
|
146
|
+
createExpirationTimeout();
|
|
147
|
+
internalRef.value = newValue;
|
|
148
|
+
trigger();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { onMounted, onUnmounted } from "vue";
|
|
2
|
-
import
|
|
2
|
+
import { useBus } from "../index.mjs";
|
|
3
3
|
export const useSubscribe = (eventName, func, options = { once: false, unsubscribeOnUnmount: true }) => {
|
|
4
|
+
const bus = useBus();
|
|
4
5
|
let subscription;
|
|
5
6
|
onMounted(() => {
|
|
6
7
|
subscription = bus.subscribe(eventName, (data) => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useLocalStorage } from "@vueuse/core";
|
|
2
2
|
import { flush, getToken, setUser } from "./api-client.mjs";
|
|
3
|
-
import { useUser } from "./composables/index.mjs";
|
|
3
|
+
import { useApiActions, useUser } from "./composables/index.mjs";
|
|
4
4
|
import { createSingletonAsync, once } from "./helpers/index.mjs";
|
|
5
|
-
import { useApiActions } from "./index.mjs";
|
|
6
5
|
async function getUserRequest(fetch, config) {
|
|
7
6
|
const token = getToken();
|
|
8
7
|
const user = useUser();
|
|
@@ -17,8 +16,8 @@ async function getUserRequest(fetch, config) {
|
|
|
17
16
|
}
|
|
18
17
|
try {
|
|
19
18
|
const apiActions = useApiActions();
|
|
20
|
-
await apiActions
|
|
21
|
-
await apiActions
|
|
19
|
+
await apiActions.value?.getVisitorIdentifier?.();
|
|
20
|
+
await apiActions.value?.refreshToken?.();
|
|
22
21
|
} catch {
|
|
23
22
|
flush();
|
|
24
23
|
return { token: null, user: null };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { type Ref } from "vue";
|
|
2
2
|
import type { Fetch, FetchConfig } from "./types";
|
|
3
3
|
export { defineVuePlugins } from "./define-vue-plugins";
|
|
4
|
-
export { default as AppProvider } from "./AppProvider.vue";
|
|
4
|
+
export { default as AppProvider, useBus } from "./AppProvider.vue";
|
|
5
5
|
export * from "./composables";
|
|
6
6
|
export * from "./types";
|
|
7
|
-
type ApiActions = {
|
|
8
|
-
getVisitorIdentifier?: () => Promise<void>;
|
|
9
|
-
refreshToken?: () => Promise<string>;
|
|
10
|
-
};
|
|
11
7
|
export declare function initApiFetch($fetch: Fetch, config: FetchConfig): {
|
|
12
8
|
fetch: Fetch;
|
|
13
9
|
getUser: () => Promise<import("./types").GetUserResponse>;
|
|
@@ -69,4 +65,3 @@ export declare const useUserActions: () => Ref<{
|
|
|
69
65
|
locale: string;
|
|
70
66
|
}) => Promise<void>;
|
|
71
67
|
}> | undefined;
|
|
72
|
-
export declare const useApiActions: () => Ref<ApiActions, ApiActions> | undefined;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { useLocalStorage } from "@vueuse/core";
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
-
import {
|
|
3
|
+
import { createApiFetch } from "./api-client.mjs";
|
|
4
|
+
import { useBus } from "./AppProvider.vue";
|
|
4
5
|
import { newCometClient } from "./comet-client.mjs";
|
|
6
|
+
import { useApiActions } from "./composables/index.mjs";
|
|
5
7
|
import { createApiGetUser } from "./get-user.mjs";
|
|
6
8
|
import { createApiGetVisitorIdentifier } from "./get-visitor.mjs";
|
|
7
9
|
import { createInitApplication } from "./init-application.mjs";
|
|
8
10
|
import { createApiRefreshToken } from "./refresh-token.mjs";
|
|
9
11
|
import { createApiUserActions } from "./user-actions.mjs";
|
|
10
12
|
export { defineVuePlugins } from "./define-vue-plugins.mjs";
|
|
11
|
-
export { default as AppProvider } from "./AppProvider.vue";
|
|
13
|
+
export { default as AppProvider, useBus } from "./AppProvider.vue";
|
|
12
14
|
export * from "./composables/index.mjs";
|
|
13
15
|
export * from "./types.mjs";
|
|
16
|
+
const apiActions = useApiActions();
|
|
14
17
|
let userActions;
|
|
15
|
-
let apiActions;
|
|
16
18
|
export function initApiFetch($fetch, config) {
|
|
17
19
|
const fetch = createApiFetch($fetch, config);
|
|
18
20
|
const getUser = createApiGetUser(fetch, config);
|
|
@@ -20,11 +22,16 @@ export function initApiFetch($fetch, config) {
|
|
|
20
22
|
const initApplication = createInitApplication();
|
|
21
23
|
const refreshToken = createApiRefreshToken(fetch, config);
|
|
22
24
|
userActions = ref(createApiUserActions(fetch, config, getUser));
|
|
23
|
-
apiActions =
|
|
25
|
+
apiActions.value = {
|
|
26
|
+
initialized: true,
|
|
27
|
+
getVisitorIdentifier,
|
|
28
|
+
refreshToken
|
|
29
|
+
};
|
|
24
30
|
if (typeof window !== "undefined") {
|
|
25
31
|
const loggedIn = useLocalStorage("lin", "no");
|
|
26
32
|
const cometServerURL = config.cometServerURL;
|
|
27
33
|
let cometClient;
|
|
34
|
+
const bus = useBus();
|
|
28
35
|
bus.subscribe("user:onUpdated", (user) => {
|
|
29
36
|
if (user) {
|
|
30
37
|
cometClient || (cometClient = newCometClient(user, cometServerURL));
|
|
@@ -38,7 +45,8 @@ export function initApiFetch($fetch, config) {
|
|
|
38
45
|
}
|
|
39
46
|
loggedIn.value = user ? "yes" : "no";
|
|
40
47
|
});
|
|
41
|
-
bus.subscribe("app:
|
|
48
|
+
bus.subscribe("app:beforeMount", () => {
|
|
49
|
+
console.log("Service started in mode", import.meta.env.MODE);
|
|
42
50
|
getVisitorIdentifier();
|
|
43
51
|
initApplication();
|
|
44
52
|
});
|
|
@@ -49,6 +57,3 @@ export function initApiFetch($fetch, config) {
|
|
|
49
57
|
export const useUserActions = () => {
|
|
50
58
|
return userActions;
|
|
51
59
|
};
|
|
52
|
-
export const useApiActions = () => {
|
|
53
|
-
return apiActions;
|
|
54
|
-
};
|
|
@@ -5,7 +5,7 @@ import ruRU from "vant/es/locale/lang/ru-RU";
|
|
|
5
5
|
import { watch } from "vue";
|
|
6
6
|
import { useI18n } from "vue-i18n";
|
|
7
7
|
import { useRouter } from "vue-router";
|
|
8
|
-
import { useActiveSessions, useSubscribe, useUser } from "./composables/index.mjs";
|
|
8
|
+
import { useActiveSessions, useCookies, useSubscribe, useUser } from "./composables/index.mjs";
|
|
9
9
|
import { once } from "./helpers/index.mjs";
|
|
10
10
|
import { useAppLocale, useThemeMode, useUserActions, useVisitor } from "./index.mjs";
|
|
11
11
|
function initApplication() {
|
|
@@ -62,6 +62,8 @@ function initApplication() {
|
|
|
62
62
|
VantLocale.use(locale2, ruRU);
|
|
63
63
|
VarletLocale.add("en-US", VarletLocale.enUS);
|
|
64
64
|
}
|
|
65
|
+
const localeCookie = useCookies("locale", { maxAge: 60 * 60 * 24 * 365 });
|
|
66
|
+
localeCookie.value = locale2?.value;
|
|
65
67
|
},
|
|
66
68
|
{ immediate: true }
|
|
67
69
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inzombieland/core",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"main": "./index.mjs",
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
"@varlet/ui": "^3.10.5",
|
|
15
15
|
"@vueuse/core": "^12.8.2",
|
|
16
16
|
"centrifuge": "^5.3.4",
|
|
17
|
+
"cookie-es": "^2.0.0",
|
|
18
|
+
"destr": "^2.0.5",
|
|
19
|
+
"klona": "^2.0.6",
|
|
17
20
|
"ofetch": "^1.4.1",
|
|
21
|
+
"ohash": "^2.0.11",
|
|
18
22
|
"rxjs": "^7.8.2",
|
|
19
23
|
"vant": "^4.9.19",
|
|
20
24
|
"zod": "^3.24.2"
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { addRouteMiddleware, defineNuxtPlugin } from "#app";
|
|
2
|
-
import {
|
|
2
|
+
import { 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,
|
|
6
|
+
import { defineVuePlugins, 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,7 +14,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
14
14
|
const runtimeConfig = useRuntimeConfig();
|
|
15
15
|
const { $mobileApp } = useNuxtApp();
|
|
16
16
|
const theme = useThemeMode();
|
|
17
|
-
const locale = useAppLocale();
|
|
18
17
|
if (runtimeConfig.public.ssr && import.meta.server || !runtimeConfig.public.ssr) {
|
|
19
18
|
flush();
|
|
20
19
|
if (import.meta.server) {
|
|
@@ -41,14 +40,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
41
40
|
},
|
|
42
41
|
{ immediate: true }
|
|
43
42
|
);
|
|
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
|
-
);
|
|
52
43
|
});
|
|
53
44
|
addRouteMiddleware("auth", authMiddleware, { global: false });
|
|
54
45
|
addRouteMiddleware("guest", guestMiddleware, { global: false });
|