@inzombieland/nuxt-common 0.0.3 → 0.0.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/LICENSE +8 -0
- package/assets/css/layer.css +305 -0
- package/module.cjs +5 -0
- package/module.d.mts +7 -0
- package/module.d.ts +7 -0
- package/module.json +9 -0
- package/module.mjs +70 -0
- package/package.json +5 -3
- package/runtime/AppProvider.vue +129 -0
- package/runtime/SidebarProvider.vue +138 -0
- package/runtime/api/account/account.get.d.ts +2 -0
- package/runtime/api/account/account.get.mjs +19 -0
- package/runtime/api/account/authcheck.get.d.ts +8 -0
- package/runtime/api/account/authcheck.get.mjs +28 -0
- package/runtime/api/account/default-handler.d.ts +2 -0
- package/runtime/api/account/default-handler.mjs +37 -0
- package/runtime/api/account/middleware.d.ts +2 -0
- package/runtime/api/account/middleware.mjs +18 -0
- package/runtime/api/account/token.get.d.ts +2 -0
- package/runtime/api/account/token.get.mjs +31 -0
- package/runtime/api/index.d.ts +37 -0
- package/runtime/api/index.mjs +26 -0
- package/runtime/api/user-actions.d.ts +118 -0
- package/runtime/api/user-actions.mjs +165 -0
- package/runtime/composables/use-active-sessions.d.ts +5 -0
- package/runtime/composables/use-active-sessions.mjs +15 -0
- package/runtime/composables/use-api-fetch.d.ts +3 -0
- package/runtime/composables/use-api-fetch.mjs +3 -0
- package/runtime/composables/use-helpers.d.ts +16 -0
- package/runtime/composables/use-helpers.mjs +10 -0
- package/runtime/composables/use-layer-manager.d.ts +3 -0
- package/runtime/composables/use-layer-manager.mjs +3 -0
- package/runtime/composables/use-subscribe.d.ts +10 -0
- package/runtime/composables/use-subscribe.mjs +22 -0
- package/runtime/composables/use-toggle-sidebar.d.ts +3 -0
- package/runtime/composables/use-toggle-sidebar.mjs +8 -0
- package/runtime/composables/use-user-actions.d.ts +2 -0
- package/runtime/composables/use-user-actions.mjs +4 -0
- package/runtime/composables/use-user.d.ts +3 -0
- package/runtime/composables/use-user.mjs +3 -0
- package/runtime/composables/use-validators.d.ts +8 -0
- package/runtime/composables/use-validators.mjs +17 -0
- package/runtime/middleware/auth.d.ts +2 -0
- package/runtime/middleware/auth.mjs +10 -0
- package/runtime/middleware/guest.d.ts +2 -0
- package/runtime/middleware/guest.mjs +12 -0
- package/runtime/middleware/index.d.ts +4 -0
- package/runtime/middleware/index.mjs +4 -0
- package/runtime/middleware/locale.global.d.ts +2 -0
- package/runtime/middleware/locale.global.mjs +13 -0
- package/runtime/packages/api/api-client.d.ts +8 -0
- package/runtime/packages/api/api-client.mjs +150 -0
- package/runtime/packages/api/bus.d.ts +7 -0
- package/runtime/packages/api/bus.mjs +22 -0
- package/runtime/packages/api/comet-client.d.ts +11 -0
- package/runtime/packages/api/comet-client.mjs +73 -0
- package/runtime/packages/api/get-user.d.ts +8 -0
- package/runtime/packages/api/get-user.mjs +54 -0
- package/runtime/packages/api/get-visitor.d.ts +11 -0
- package/runtime/packages/api/get-visitor.mjs +32 -0
- package/runtime/packages/api/helpers/api-helper.d.ts +6 -0
- package/runtime/packages/api/helpers/api-helper.mjs +99 -0
- package/runtime/packages/api/helpers/current-device.d.ts +67 -0
- package/runtime/packages/api/helpers/current-device.mjs +368 -0
- package/runtime/packages/api/helpers/date-helper.d.ts +15 -0
- package/runtime/packages/api/helpers/date-helper.mjs +231 -0
- package/runtime/packages/api/helpers/index.d.ts +4 -0
- package/runtime/packages/api/helpers/index.mjs +15 -0
- package/runtime/packages/api/index.d.ts +26 -0
- package/runtime/packages/api/index.mjs +50 -0
- package/runtime/packages/api/package.json +20 -0
- package/runtime/packages/api/refresh-token.d.ts +2 -0
- package/runtime/packages/api/refresh-token.mjs +39 -0
- package/runtime/packages/api/types.d.ts +51 -0
- package/runtime/packages/api/types.mjs +0 -0
- package/runtime/packages/api/use-api-actions.d.ts +13 -0
- package/runtime/packages/api/use-api-actions.mjs +5 -0
- package/runtime/packages/api/use-user.d.ts +47 -0
- package/runtime/packages/api/use-user.mjs +5 -0
- package/runtime/packages/helpers/index.d.ts +3 -0
- package/runtime/packages/helpers/index.mjs +14 -0
- package/runtime/packages/helpers/package.json +11 -0
- package/runtime/packages/helpers/phone-helper.d.ts +13 -0
- package/runtime/packages/helpers/phone-helper.mjs +58 -0
- package/runtime/packages/helpers/string-helper.d.ts +4 -0
- package/runtime/packages/helpers/string-helper.mjs +8 -0
- package/runtime/packages/layer-manager/LayerComponent.vue +54 -0
- package/runtime/packages/layer-manager/LayersProvider.vue +171 -0
- package/runtime/packages/layer-manager/index.d.ts +2 -0
- package/runtime/packages/layer-manager/index.mjs +2 -0
- package/runtime/packages/layer-manager/package.json +11 -0
- package/runtime/packages/layer-manager/types.d.ts +8 -0
- package/runtime/packages/layer-manager/types.mjs +0 -0
- package/runtime/packages/layer-manager/use-layer-actions.d.ts +23 -0
- package/runtime/packages/layer-manager/use-layer-actions.mjs +5 -0
- package/runtime/plugin.d.ts +2 -0
- package/runtime/plugin.mjs +42 -0
- package/runtime/plugins/device.d.ts +136 -0
- package/runtime/plugins/device.mjs +29 -0
- package/runtime/plugins/otp-input.d.ts +2 -0
- package/runtime/plugins/otp-input.mjs +5 -0
- package/runtime/plugins/sanitize-html.d.ts +2 -0
- package/runtime/plugins/sanitize-html.mjs +90 -0
- package/runtime/plugins/sanitize-url.d.ts +2 -0
- package/runtime/plugins/sanitize-url.mjs +9 -0
- package/runtime/server/middleware/basic-auth.d.ts +2 -0
- package/runtime/server/middleware/basic-auth.mjs +34 -0
- package/runtime/thirdparty/helpers/index.d.mts +5 -0
- package/runtime/thirdparty/helpers/index.d.ts +7 -0
- package/runtime/thirdparty/helpers/index.mjs +69 -0
- package/runtime/thirdparty/helpers/index.mjs.map +1 -0
- package/runtime/thirdparty/sanitize-url/index.d.mts +2 -0
- package/runtime/thirdparty/sanitize-url/index.d.ts +1 -0
- package/runtime/thirdparty/sanitize-url/index.mjs +98 -0
- package/runtime/thirdparty/sanitize-url/index.mjs.map +1 -0
- package/runtime/ui/varlet.d.ts +7 -0
- package/runtime/ui/varlet.mjs +13 -0
- package/types.d.mts +16 -0
- package/types.d.ts +16 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useSwipe, type UseSwipeDirection } from "@vueuse/core"
|
|
3
|
+
import { onMounted, ref, watch } from "vue"
|
|
4
|
+
import { useNuxtApp } from "#imports"
|
|
5
|
+
import { useToggleSidebar } from "./composables/use-toggle-sidebar"
|
|
6
|
+
|
|
7
|
+
const sidebarRef = ref<HTMLElement | null>(null)
|
|
8
|
+
const contentRef = ref<HTMLElement | null>(null)
|
|
9
|
+
const sidebarBackdropRef = ref<HTMLElement | null>(null)
|
|
10
|
+
|
|
11
|
+
const sidebar = ref("hidden")
|
|
12
|
+
const toggleSidebar = useToggleSidebar()
|
|
13
|
+
const { $device } = useNuxtApp()
|
|
14
|
+
const sidebarClass = ref({
|
|
15
|
+
sidebar: true,
|
|
16
|
+
"sidebar-open": sidebar.value === "open",
|
|
17
|
+
"sidebar-hidden": sidebar.value === "hidden",
|
|
18
|
+
})
|
|
19
|
+
const contentClass = ref({
|
|
20
|
+
content: true,
|
|
21
|
+
"sidebar-open": sidebar.value === "open",
|
|
22
|
+
"sidebar-hidden": sidebar.value === "hidden",
|
|
23
|
+
})
|
|
24
|
+
const sidebarBackdropClass = ref({
|
|
25
|
+
sidebarBackdrop: true,
|
|
26
|
+
"sidebar-open": sidebar.value === "open",
|
|
27
|
+
"sidebar-hidden": sidebar.value === "hidden",
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
watch(sidebar, value => {
|
|
31
|
+
sidebarClass.value["sidebar-open"] = value === "open"
|
|
32
|
+
sidebarClass.value["sidebar-hidden"] = value === "hidden"
|
|
33
|
+
contentClass.value["sidebar-open"] = value === "open"
|
|
34
|
+
contentClass.value["sidebar-hidden"] = value === "hidden"
|
|
35
|
+
sidebarBackdropClass.value["sidebar-open"] = value === "open"
|
|
36
|
+
sidebarBackdropClass.value["sidebar-hidden"] = value === "hidden"
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
onMounted(() => {
|
|
40
|
+
toggleSidebar.value = () => {
|
|
41
|
+
if (localStorage.sidebar === "hidden" || sidebarRef.value?.clientWidth === 0) {
|
|
42
|
+
localStorage.sidebar = "open"
|
|
43
|
+
sidebar.value = "open"
|
|
44
|
+
} else {
|
|
45
|
+
localStorage.sidebar = "hidden"
|
|
46
|
+
sidebar.value = "hidden"
|
|
47
|
+
}
|
|
48
|
+
return sidebar.value
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
useSwipe(sidebarRef, {
|
|
52
|
+
onSwipeEnd(e: TouchEvent, direction: UseSwipeDirection) {
|
|
53
|
+
if (direction === "left") {
|
|
54
|
+
localStorage.sidebar = "hidden"
|
|
55
|
+
sidebar.value = "hidden"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
sidebarBackdropRef.value?.addEventListener(
|
|
61
|
+
"click",
|
|
62
|
+
() => {
|
|
63
|
+
sidebar.value = "hidden"
|
|
64
|
+
},
|
|
65
|
+
false
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if ($device.desktop()) {
|
|
69
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
70
|
+
|
|
71
|
+
sidebarRef.value?.addEventListener(
|
|
72
|
+
"mouseover",
|
|
73
|
+
() => {
|
|
74
|
+
if (localStorage.sidebar === "hidden") {
|
|
75
|
+
clearTimeout(timer)
|
|
76
|
+
timer = setTimeout(function () {
|
|
77
|
+
sidebar.value = "open"
|
|
78
|
+
}, 200)
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
false
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
sidebarRef.value?.addEventListener(
|
|
85
|
+
"mouseleave",
|
|
86
|
+
() => {
|
|
87
|
+
if (localStorage.sidebar === "hidden") {
|
|
88
|
+
clearTimeout(timer)
|
|
89
|
+
timer = setTimeout(function () {
|
|
90
|
+
sidebar.value = "hidden"
|
|
91
|
+
}, 100)
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
false
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (sidebarRef.value) {
|
|
99
|
+
sidebarRef.value.style.transition = "width 0.25s ease"
|
|
100
|
+
}
|
|
101
|
+
if (contentRef.value) {
|
|
102
|
+
contentRef.value.style.transition = "left 0.25s ease"
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
if (typeof window !== "undefined" && $device.desktop()) {
|
|
107
|
+
sidebar.value = localStorage.sidebar === "hidden" ? "hidden" : "open"
|
|
108
|
+
}
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<template>
|
|
112
|
+
<div>
|
|
113
|
+
<aside
|
|
114
|
+
ref="sidebarRef"
|
|
115
|
+
:class="sidebarClass"
|
|
116
|
+
>
|
|
117
|
+
<div>
|
|
118
|
+
<slot name="sidebar" />
|
|
119
|
+
</div>
|
|
120
|
+
</aside>
|
|
121
|
+
<div
|
|
122
|
+
ref="contentRef"
|
|
123
|
+
:class="contentClass"
|
|
124
|
+
>
|
|
125
|
+
<div>
|
|
126
|
+
<slot name="content" />
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
<div
|
|
130
|
+
ref="sidebarBackdropRef"
|
|
131
|
+
:class="sidebarBackdropClass"
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
</template>
|
|
135
|
+
|
|
136
|
+
<style scoped>
|
|
137
|
+
.sidebar{height:100%;left:0;padding-top:48px;pointer-events:auto;position:fixed;top:0;transform:translateX(0);will-change:transform;z-index:20}.sidebar,.sidebar.sidebar-open{width:20rem}.sidebar.sidebar-hidden{transition:width .15s ease!important;width:0}.sidebar>div{background:var(--color-surface-container-low);box-shadow:inset -1px 0 0 var(--app-bar-border-color);height:100%;overflow-x:hidden;overflow-y:auto}.sidebar>div::-webkit-scrollbar-thumb{background-color:transparent}.sidebar>div:hover::-webkit-scrollbar-thumb{background-color:rgba(53,65,76,.4)}.sidebar>div:hover::-webkit-scrollbar-thumb:hover{background-color:rgba(53,65,76,.5)}.dark .sidebar>div:hover::-webkit-scrollbar-thumb{background-color:hsla(0,0%,100%,.4)}.dark .sidebar>div:hover::-webkit-scrollbar-thumb:hover{background-color:hsla(0,0%,100%,.5)}.content{bottom:0;pointer-events:auto;position:absolute;right:0;top:0;transform:translateX(0);will-change:transform;z-index:10}.content,.content.sidebar-open{left:20rem}.content.sidebar-hidden{left:0;transition:left .15s ease!important}.content>div{bottom:0;left:0;overflow-y:auto;position:absolute;right:0;top:0;-webkit-overflow-scrolling:auto}.sidebarBackdrop{background-color:#37415180;bottom:0;display:none;left:0;position:fixed;right:0;top:0;z-index:10}.dark .sidebarBackdrop{background-color:#21273070}@media (max-width:767px){.sidebar{width:0}.sidebar.sidebar-open{width:20rem}.sidebar.sidebar-hidden{width:0}.content,.content.sidebar-hidden,.content.sidebar-open{left:0}.sidebarBackdrop.sidebar-open{display:block}.sidebarBackdrop.sidebar-hidden{display:none}}
|
|
138
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineEventHandler, getRequestHeader, parseCookies } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const cookies = parseCookies(event);
|
|
5
|
+
if (cookies.lin !== "yes") {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const config = useRuntimeConfig();
|
|
9
|
+
const request = String(config.public.apiBaseURL) + String(event.node.req.url);
|
|
10
|
+
const authorization = getRequestHeader(event, "authorization") ?? "";
|
|
11
|
+
try {
|
|
12
|
+
const response = await $fetch.raw(request, {
|
|
13
|
+
headers: { ...event.context.headers, authorization }
|
|
14
|
+
});
|
|
15
|
+
return response._data;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineEventHandler, parseCookies } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const cookies = parseCookies(event);
|
|
5
|
+
if (cookies.lin !== "yes") {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const config = useRuntimeConfig();
|
|
9
|
+
const request = String(config.public.apiBaseURL) + String(event.node.req.url);
|
|
10
|
+
try {
|
|
11
|
+
const response = await $fetch(request, {
|
|
12
|
+
headers: event.context.headers
|
|
13
|
+
});
|
|
14
|
+
const { AccessToken: token } = response || {};
|
|
15
|
+
if (!token) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const user = await $fetch(`${config.public.apiBaseURL}/account`, {
|
|
19
|
+
headers: { ...event.context.headers, authorization: `JWT ${token}` }
|
|
20
|
+
});
|
|
21
|
+
if (!user) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
return { token, user };
|
|
25
|
+
} catch {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { cookieHelper } from "@asvate/nuxt-common/helpers";
|
|
2
|
+
import { appendHeader, defineEventHandler, readBody } from "h3";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const config = useRuntimeConfig();
|
|
6
|
+
const request = String(config.public.apiBaseURL) + String(event.node.req.url);
|
|
7
|
+
try {
|
|
8
|
+
const body = await readBody(event);
|
|
9
|
+
const response = await $fetch.raw(request, {
|
|
10
|
+
body,
|
|
11
|
+
method: event.node.req.method,
|
|
12
|
+
headers: event.context.headers
|
|
13
|
+
});
|
|
14
|
+
appendResponseHeaders(response.headers);
|
|
15
|
+
return response._data;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
appendResponseHeaders(error?.response?.headers);
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
function appendResponseHeaders(headers) {
|
|
21
|
+
if (typeof headers?.get !== "function") {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const cookies = cookieHelper.splitCookiesString(headers.get("set-cookie") ?? "");
|
|
25
|
+
for (const cookie of cookies) {
|
|
26
|
+
appendHeader(event, "set-cookie", cookie);
|
|
27
|
+
}
|
|
28
|
+
const requestID = headers.get("x-request-id");
|
|
29
|
+
if (requestID) {
|
|
30
|
+
appendHeader(event, "x-request-id", requestID);
|
|
31
|
+
}
|
|
32
|
+
const traceID = headers.get("x-trace-id");
|
|
33
|
+
if (traceID) {
|
|
34
|
+
appendHeader(event, "x-trace-id", traceID);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineEventHandler, getRequestHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
export default defineEventHandler((event) => {
|
|
4
|
+
const config = useRuntimeConfig();
|
|
5
|
+
let authorization = "";
|
|
6
|
+
if (import.meta.server && String(config.appClientID) && String(config.appClientSecret)) {
|
|
7
|
+
const credentials = btoa(`${config.appClientID}:${config.appClientSecret}`);
|
|
8
|
+
authorization = `Basic ${credentials}`;
|
|
9
|
+
}
|
|
10
|
+
event.context.headers = {
|
|
11
|
+
...authorization && { authorization },
|
|
12
|
+
cookie: getRequestHeader(event, "cookie") ?? "",
|
|
13
|
+
platform: getRequestHeader(event, "platform") ?? "",
|
|
14
|
+
visitor: getRequestHeader(event, "visitor") ?? "",
|
|
15
|
+
"x-hostname": getRequestHeader(event, "x-hostname") ?? "",
|
|
16
|
+
"user-agent": getRequestHeader(event, "user-agent") ?? ""
|
|
17
|
+
};
|
|
18
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { cookieHelper } from "@asvate/nuxt-common/helpers";
|
|
2
|
+
import { appendHeader, defineEventHandler, parseCookies } from "h3";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const cookies = parseCookies(event);
|
|
6
|
+
if (cookies.lin !== "yes") {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
const config = useRuntimeConfig();
|
|
10
|
+
const request = String(config.public.apiBaseURL) + String(event.node.req.url);
|
|
11
|
+
try {
|
|
12
|
+
const response = await $fetch.raw(request, {
|
|
13
|
+
headers: event.context.headers
|
|
14
|
+
});
|
|
15
|
+
const cookies2 = cookieHelper.splitCookiesString(response.headers.get("set-cookie") ?? "");
|
|
16
|
+
for (const cookie of cookies2) {
|
|
17
|
+
appendHeader(event, "set-cookie", cookie);
|
|
18
|
+
}
|
|
19
|
+
const requestID = response.headers.get("x-request-id");
|
|
20
|
+
if (requestID) {
|
|
21
|
+
appendHeader(event, "x-request-id", requestID);
|
|
22
|
+
}
|
|
23
|
+
const traceID = response.headers.get("x-trace-id");
|
|
24
|
+
if (traceID) {
|
|
25
|
+
appendHeader(event, "x-trace-id", traceID);
|
|
26
|
+
}
|
|
27
|
+
return response._data;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return error;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Fetch } from "../packages/api";
|
|
2
|
+
export { type ActiveSession, type Fetch, type User, type Visitor } from "../packages/api";
|
|
3
|
+
export { getVisitor, getVisitorId, useUser } from "../packages/api";
|
|
4
|
+
export declare const config: {
|
|
5
|
+
apiBaseURL: string;
|
|
6
|
+
cometServerURL: string;
|
|
7
|
+
appClientID: string;
|
|
8
|
+
appClientSecret: string;
|
|
9
|
+
isMobileApp: boolean;
|
|
10
|
+
isDesktopApp: boolean;
|
|
11
|
+
appName: string;
|
|
12
|
+
getHostname: () => string;
|
|
13
|
+
getDevice: () => Promise<any>;
|
|
14
|
+
useRequestHeaders: (include?: string[]) => {
|
|
15
|
+
baseURL: string;
|
|
16
|
+
headers: {
|
|
17
|
+
[x: Lowercase<string>]: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
declare const fetch: Fetch, getUser: () => Promise<{
|
|
22
|
+
token?: string | null;
|
|
23
|
+
user?: import("src/runtime/packages/api/use-user").User | null;
|
|
24
|
+
}>, getVisitorIdentifier: () => Promise<void>, useApiFetch: () => Fetch, userActions: {
|
|
25
|
+
signIn: (body: {
|
|
26
|
+
username: string;
|
|
27
|
+
password: string;
|
|
28
|
+
rememberMe: boolean;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
token?: string | null;
|
|
31
|
+
user?: import("src/runtime/packages/api/use-user").User | null;
|
|
32
|
+
} | {
|
|
33
|
+
key: string;
|
|
34
|
+
}>;
|
|
35
|
+
logout: () => Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
export { fetch, getUser, getVisitorIdentifier, useApiFetch, userActions };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useNuxtApp, useRequestHeaders, useRequestURL } from "#imports";
|
|
2
|
+
import { initApiFetch } from "../packages/api/index.mjs";
|
|
3
|
+
export { getVisitor, getVisitorId, useUser } from "../packages/api/index.mjs";
|
|
4
|
+
const getBoolean = (value) => value === "true";
|
|
5
|
+
export const config = {
|
|
6
|
+
apiBaseURL: String(import.meta.env.VITE_API_BASE_URL),
|
|
7
|
+
cometServerURL: String(import.meta.env.VITE_COMET_SERVER_URL),
|
|
8
|
+
appClientID: String(import.meta.env.VITE_APP_CLIENT_ID),
|
|
9
|
+
appClientSecret: String(import.meta.env.VITE_APP_CLIENT_SECRET),
|
|
10
|
+
isMobileApp: getBoolean(import.meta.env.VITE_IS_MOBILE_APP),
|
|
11
|
+
isDesktopApp: getBoolean(import.meta.env.VITE_IS_DESKTOP_APP),
|
|
12
|
+
appName: String(import.meta.env.VITE_APP_NAME),
|
|
13
|
+
getHostname: () => useRequestURL().hostname,
|
|
14
|
+
getDevice: async () => {
|
|
15
|
+
const { $device } = useNuxtApp();
|
|
16
|
+
return await $device.getInfo();
|
|
17
|
+
},
|
|
18
|
+
useRequestHeaders: (include = []) => {
|
|
19
|
+
return {
|
|
20
|
+
baseURL: "/",
|
|
21
|
+
headers: useRequestHeaders(include)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const { fetch, getUser, getVisitorIdentifier, useApiFetch, userActions } = initApiFetch($fetch, config);
|
|
26
|
+
export { fetch, getUser, getVisitorIdentifier, useApiFetch, userActions };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type ActiveSession } from "./index";
|
|
2
|
+
export declare const signIn: (body: {
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
rememberMe: boolean;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
token?: string | null;
|
|
8
|
+
user?: import("src/runtime/packages/api").User | null;
|
|
9
|
+
} | {
|
|
10
|
+
key: string;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const logout: () => Promise<void>;
|
|
13
|
+
export declare const signInByCodeSendCode: (body: {
|
|
14
|
+
username: string;
|
|
15
|
+
}) => Promise<{
|
|
16
|
+
key: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const signInByCodeVerifyCode: (body: {
|
|
19
|
+
key: string;
|
|
20
|
+
code: string;
|
|
21
|
+
rememberMe?: boolean;
|
|
22
|
+
}) => Promise<{
|
|
23
|
+
token?: string | null;
|
|
24
|
+
user?: import("src/runtime/packages/api").User | null;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const signUp: (body: {
|
|
27
|
+
email: string;
|
|
28
|
+
password: string;
|
|
29
|
+
passwordConfirm: string;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
key: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const confirmEmail: (body: {
|
|
34
|
+
key: string;
|
|
35
|
+
code: string;
|
|
36
|
+
}) => Promise<{}>;
|
|
37
|
+
export declare const resendActivationEmail: (body: {
|
|
38
|
+
email: string;
|
|
39
|
+
}) => Promise<{
|
|
40
|
+
key: string;
|
|
41
|
+
}>;
|
|
42
|
+
export declare const recovery: (body: {
|
|
43
|
+
email: string;
|
|
44
|
+
}) => Promise<{
|
|
45
|
+
key: string;
|
|
46
|
+
}>;
|
|
47
|
+
export declare const confirmRecovery: (body: {
|
|
48
|
+
key: string;
|
|
49
|
+
code: string;
|
|
50
|
+
}) => Promise<{
|
|
51
|
+
key: string;
|
|
52
|
+
}>;
|
|
53
|
+
export declare const resetPassword: (body: {
|
|
54
|
+
key: string;
|
|
55
|
+
password: string;
|
|
56
|
+
}) => Promise<{}>;
|
|
57
|
+
export declare const changeName: (body: {
|
|
58
|
+
firstName: string;
|
|
59
|
+
lastName: string;
|
|
60
|
+
middleName: string;
|
|
61
|
+
}) => Promise<void>;
|
|
62
|
+
export declare const changeBirthday: (body: {
|
|
63
|
+
day?: number;
|
|
64
|
+
month?: number;
|
|
65
|
+
year?: number;
|
|
66
|
+
}) => Promise<void>;
|
|
67
|
+
export declare const changeGender: (body: {
|
|
68
|
+
gender: "" | "male" | "female";
|
|
69
|
+
}) => Promise<void>;
|
|
70
|
+
export declare const changePassword: (body: {
|
|
71
|
+
password: string;
|
|
72
|
+
newPassword: string;
|
|
73
|
+
}) => Promise<{
|
|
74
|
+
key: string;
|
|
75
|
+
}>;
|
|
76
|
+
export declare const confirmPasswordChange: (body: {
|
|
77
|
+
key: string;
|
|
78
|
+
code: string;
|
|
79
|
+
newPassword?: string;
|
|
80
|
+
}) => Promise<void>;
|
|
81
|
+
export declare const changeEmail: (body: {
|
|
82
|
+
email: string;
|
|
83
|
+
password: string;
|
|
84
|
+
}) => Promise<{
|
|
85
|
+
key: string;
|
|
86
|
+
}>;
|
|
87
|
+
export declare const confirmEmailChange: (body: {
|
|
88
|
+
key: string;
|
|
89
|
+
code: string;
|
|
90
|
+
email?: string;
|
|
91
|
+
}) => Promise<void>;
|
|
92
|
+
export declare const changePhone: (body: {
|
|
93
|
+
phone: string;
|
|
94
|
+
password: string;
|
|
95
|
+
}) => Promise<void>;
|
|
96
|
+
export declare const changeTheme: (body: {
|
|
97
|
+
theme: "light" | "dark";
|
|
98
|
+
}) => Promise<void>;
|
|
99
|
+
export declare const changeLocale: (body: {
|
|
100
|
+
locale: string;
|
|
101
|
+
}) => Promise<void>;
|
|
102
|
+
export declare const changeAvatar: (body: FormData) => Promise<void>;
|
|
103
|
+
export declare const deleteAvatar: () => Promise<void>;
|
|
104
|
+
export declare const fetchActiveSessions: () => Promise<{
|
|
105
|
+
sessions: ActiveSession[];
|
|
106
|
+
}>;
|
|
107
|
+
export declare const logoutActiveSession: (body: {
|
|
108
|
+
sessionId: string;
|
|
109
|
+
visitorId: string;
|
|
110
|
+
}) => Promise<any>;
|
|
111
|
+
export declare const logoutFromAllActiveSessions: () => Promise<any>;
|
|
112
|
+
export declare const deleteAccount: () => Promise<{
|
|
113
|
+
key: string;
|
|
114
|
+
}>;
|
|
115
|
+
export declare const confirmDeleteAccount: (body: {
|
|
116
|
+
key: string;
|
|
117
|
+
code: string;
|
|
118
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { useLocalStorage } from "@vueuse/core";
|
|
2
|
+
import { useCookie, useRequestHeaders } from "#imports";
|
|
3
|
+
import { flush, setToken, updateUser } from "../packages/api/api-client.mjs";
|
|
4
|
+
import { fetch, getUser, userActions, useUser } from "./index.mjs";
|
|
5
|
+
export const signIn = userActions.signIn;
|
|
6
|
+
export const logout = userActions.logout;
|
|
7
|
+
export const signInByCodeSendCode = async (body) => {
|
|
8
|
+
return await fetch("/account/0/signinbycode/sendcode", {
|
|
9
|
+
body,
|
|
10
|
+
method: "POST",
|
|
11
|
+
baseURL: "/",
|
|
12
|
+
headers: useRequestHeaders(["cookie"])
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export const signInByCodeVerifyCode = async (body) => {
|
|
16
|
+
const response = await fetch("/account/0/signinbycode/verifycode", {
|
|
17
|
+
body,
|
|
18
|
+
method: "POST",
|
|
19
|
+
baseURL: "/",
|
|
20
|
+
headers: useRequestHeaders(["cookie"])
|
|
21
|
+
});
|
|
22
|
+
const { accessToken, ...rest } = response;
|
|
23
|
+
if (!accessToken) {
|
|
24
|
+
throw rest;
|
|
25
|
+
}
|
|
26
|
+
setToken(accessToken);
|
|
27
|
+
return await getUser();
|
|
28
|
+
};
|
|
29
|
+
export const signUp = async (body) => {
|
|
30
|
+
return await fetch("/account/0/signup", {
|
|
31
|
+
body,
|
|
32
|
+
method: "POST",
|
|
33
|
+
baseURL: "/",
|
|
34
|
+
headers: useRequestHeaders(["cookie"])
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export const confirmEmail = async (body) => {
|
|
38
|
+
return await fetch("/account/0/signup", {
|
|
39
|
+
body,
|
|
40
|
+
method: "PUT",
|
|
41
|
+
baseURL: "/",
|
|
42
|
+
headers: useRequestHeaders(["cookie"])
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export const resendActivationEmail = async (body) => {
|
|
46
|
+
return await fetch("/account/0/signup", {
|
|
47
|
+
body,
|
|
48
|
+
method: "PATCH",
|
|
49
|
+
baseURL: "/",
|
|
50
|
+
headers: useRequestHeaders(["cookie"])
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
export const recovery = async (body) => {
|
|
54
|
+
return await fetch("/account/0/recovery", {
|
|
55
|
+
body,
|
|
56
|
+
method: "POST",
|
|
57
|
+
baseURL: "/",
|
|
58
|
+
headers: useRequestHeaders(["cookie"])
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export const confirmRecovery = async (body) => {
|
|
62
|
+
return await fetch("/account/0/recovery", {
|
|
63
|
+
body,
|
|
64
|
+
method: "PATCH",
|
|
65
|
+
baseURL: "/",
|
|
66
|
+
headers: useRequestHeaders(["cookie"])
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
export const resetPassword = async (body) => {
|
|
70
|
+
return await fetch("/account/0/recovery", {
|
|
71
|
+
body,
|
|
72
|
+
method: "PUT",
|
|
73
|
+
baseURL: "/",
|
|
74
|
+
headers: useRequestHeaders(["cookie"])
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export const changeName = async (body) => {
|
|
78
|
+
await fetch("/account/1/change/name", {
|
|
79
|
+
body,
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { event: "WS.ChangeNameResult" }
|
|
82
|
+
});
|
|
83
|
+
updateUser(body);
|
|
84
|
+
};
|
|
85
|
+
export const changeBirthday = async (body) => {
|
|
86
|
+
await fetch("/account/1/change/birthday", { body, method: "POST" });
|
|
87
|
+
const { year, month, day } = body;
|
|
88
|
+
if (year && month && day) {
|
|
89
|
+
const birthday = /* @__PURE__ */ new Date();
|
|
90
|
+
birthday.setUTCFullYear(year, month - 1, day);
|
|
91
|
+
birthday.setUTCHours(0, 0, 0, 0);
|
|
92
|
+
updateUser({ birthday });
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
export const changeGender = async (body) => {
|
|
96
|
+
await fetch("/account/1/change/gender", { body, method: "POST" });
|
|
97
|
+
updateUser(body);
|
|
98
|
+
};
|
|
99
|
+
export const changePassword = async (body) => {
|
|
100
|
+
return await fetch("/account/1/change/password", { body, method: "POST" });
|
|
101
|
+
};
|
|
102
|
+
export const confirmPasswordChange = async (body) => {
|
|
103
|
+
await fetch("/account/1/change/password", { body, method: "PUT" });
|
|
104
|
+
updateUser({ passwordLastSet: /* @__PURE__ */ new Date() });
|
|
105
|
+
};
|
|
106
|
+
export const changeEmail = async (body) => {
|
|
107
|
+
return await fetch("/account/1/change/email", { body, method: "POST" });
|
|
108
|
+
};
|
|
109
|
+
export const confirmEmailChange = async (body) => {
|
|
110
|
+
await fetch("/account/1/change/email", { body, method: "PUT" });
|
|
111
|
+
updateUser({ email: body.email });
|
|
112
|
+
};
|
|
113
|
+
export const changePhone = async (body) => {
|
|
114
|
+
await fetch("/account/1/change/phone", { body, method: "POST" });
|
|
115
|
+
updateUser({ phone: body.phone });
|
|
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 = useLocalStorage("theme", "light");
|
|
125
|
+
theme.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 = useLocalStorage("locale", "en");
|
|
138
|
+
locale.value = body.locale;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
export const changeAvatar = async (body) => {
|
|
142
|
+
const { avatar } = await fetch("/account/1/upload/avatar", { body, method: "POST" });
|
|
143
|
+
updateUser({ avatar });
|
|
144
|
+
};
|
|
145
|
+
export const deleteAvatar = async () => {
|
|
146
|
+
const user = useUser();
|
|
147
|
+
await fetch("/account/1/delete/avatar", { body: { avatar: user.value?.avatar }, method: "DELETE" });
|
|
148
|
+
updateUser({ avatar: "" });
|
|
149
|
+
};
|
|
150
|
+
export const fetchActiveSessions = async () => {
|
|
151
|
+
return await fetch("/account/1/sessions");
|
|
152
|
+
};
|
|
153
|
+
export const logoutActiveSession = async (body) => {
|
|
154
|
+
return await fetch("/account/1/logout/session", { body, method: "POST" });
|
|
155
|
+
};
|
|
156
|
+
export const logoutFromAllActiveSessions = async () => {
|
|
157
|
+
return await fetch("/account/1/logout/sessions", { method: "POST" });
|
|
158
|
+
};
|
|
159
|
+
export const deleteAccount = async () => {
|
|
160
|
+
return await fetch("/account/1/delete", { method: "POST" });
|
|
161
|
+
};
|
|
162
|
+
export const confirmDeleteAccount = async (body) => {
|
|
163
|
+
await fetch("/account/1/delete", { body, method: "PUT" });
|
|
164
|
+
flush();
|
|
165
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { onMounted } from "vue";
|
|
2
|
+
import { useState } from "#imports";
|
|
3
|
+
import { useUserActions } from "./use-user-actions.mjs";
|
|
4
|
+
export const useActiveSessions = () => useState("activeSessions", () => []);
|
|
5
|
+
export default () => {
|
|
6
|
+
const { fetchActiveSessions } = useUserActions();
|
|
7
|
+
const activeSessions = useActiveSessions();
|
|
8
|
+
onMounted(async () => {
|
|
9
|
+
if (activeSessions.value.length === 0) {
|
|
10
|
+
const data = await fetchActiveSessions();
|
|
11
|
+
activeSessions.value = data?.sessions ?? [];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return activeSessions;
|
|
15
|
+
};
|