@inzombieland/core 1.18.13 → 1.18.14
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/AppProvider.vue +10 -4
- package/api-client.d.ts +0 -2
- package/api-client.mjs +5 -5
- package/comet-client.mjs +6 -3
- package/composables/index.d.ts +1 -0
- package/composables/index.mjs +1 -0
- package/composables/use-api-actions.d.ts +13 -0
- package/composables/use-api-actions.mjs +5 -0
- package/composables/use-subscribe.d.ts +1 -1
- package/composables/use-subscribe.mjs +2 -1
- package/get-user.mjs +3 -4
- package/index.d.ts +1 -6
- package/index.mjs +13 -8
- package/package.json +1 -1
package/AppProvider.vue
CHANGED
|
@@ -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
|
|
package/api-client.d.ts
CHANGED
|
@@ -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;
|
package/api-client.mjs
CHANGED
|
@@ -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);
|
package/comet-client.mjs
CHANGED
|
@@ -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;
|
package/composables/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
4
5
|
export { useSubscribe } from "./use-subscribe";
|
|
5
6
|
export { useThemeMode } from "./use-theme-mode";
|
package/composables/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
4
5
|
export { useSubscribe } from "./use-subscribe.mjs";
|
|
5
6
|
export { useThemeMode } from "./use-theme-mode.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
|
+
}>;
|
|
@@ -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) => {
|
package/get-user.mjs
CHANGED
|
@@ -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 };
|
package/index.d.ts
CHANGED
|
@@ -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;
|
package/index.mjs
CHANGED
|
@@ -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
|
-
};
|