gomtm 0.0.332 → 0.0.334
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/esm/components/site/SiteInfo.d.ts +2 -0
- package/dist/esm/components/site/SiteInfo.js +15 -0
- package/dist/esm/consts.d.ts +2 -2
- package/dist/esm/consts.js +4 -4
- package/dist/esm/curd/listview/list-store.d.ts +0 -1
- package/dist/esm/curd/listview/list-store.js +16 -37
- package/dist/esm/gomtmQuery.js +8 -20
- package/dist/esm/ly/LayoutBase.js +26 -18
- package/dist/esm/ly/UserAvatorMenus.js +5 -3
- package/dist/esm/ly/front-layout/headerv2.d.ts +0 -0
- package/dist/esm/ly/front-layout/headerv2.js +0 -0
- package/dist/esm/mtmFetcher.d.ts +3 -1
- package/dist/esm/mtmFetcher.js +23 -8
- package/dist/esm/providers/AuthProvider.d.ts +1 -0
- package/dist/esm/providers/AuthProvider.js +13 -3
- package/dist/esm/providers/GomtmAppSS.js +4 -2
- package/dist/esm/store/mtapp-store.d.ts +3 -1
- package/dist/esm/store/mtapp-store.js +10 -6
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from "mtxuilib/lib/utils";
|
|
4
|
+
import { useGomtmSuspenseQuery } from "../../gomtmQuery";
|
|
5
|
+
import { siteGet } from "../../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
|
|
6
|
+
const SiteInfo = (props) => {
|
|
7
|
+
const query = useGomtmSuspenseQuery(siteGet.service.typeName, siteGet.name, {});
|
|
8
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("bg-blue-100 "), children: [
|
|
9
|
+
/* @__PURE__ */ jsx("h1", { children: "site info" }),
|
|
10
|
+
/* @__PURE__ */ jsx("pre", { children: JSON.stringify(query.data, null, 2) })
|
|
11
|
+
] });
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
SiteInfo
|
|
15
|
+
};
|
package/dist/esm/consts.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const COOKIE_MTM_SITE_ID = "mtm-site-id";
|
|
2
2
|
export declare const MTM_SITE_HOSTNAME = "mtm-site-hostname";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const CONST_COOKIE_MtM_TOKEN_NAME = "mtmToken";
|
|
4
4
|
export declare const fetchMaxRetry = 3;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const CONST_HeaderMtmHost = "Mtm-Host";
|
|
6
6
|
export declare const HeaderMtmApi = "Mtm-Api";
|
|
7
7
|
export declare const Cookie_Site_Host = "site-host";
|
|
8
8
|
export declare const MTM_SERVER_COOKIE_ACTIVATE_URL = "mtm:serverUrl";
|
package/dist/esm/consts.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const COOKIE_MTM_SITE_ID = "mtm-site-id";
|
|
2
2
|
const MTM_SITE_HOSTNAME = "mtm-site-hostname";
|
|
3
|
-
const
|
|
3
|
+
const CONST_COOKIE_MtM_TOKEN_NAME = "mtmToken";
|
|
4
4
|
const fetchMaxRetry = 3;
|
|
5
|
-
const
|
|
5
|
+
const CONST_HeaderMtmHost = "Mtm-Host";
|
|
6
6
|
const HeaderMtmApi = "Mtm-Api";
|
|
7
7
|
const Cookie_Site_Host = "site-host";
|
|
8
8
|
const MTM_SERVER_COOKIE_ACTIVATE_URL = "mtm:serverUrl";
|
|
@@ -40,6 +40,8 @@ export {
|
|
|
40
40
|
ActionEdit,
|
|
41
41
|
ActionFetchNextPage,
|
|
42
42
|
ActionRefetch,
|
|
43
|
+
CONST_COOKIE_MtM_TOKEN_NAME,
|
|
44
|
+
CONST_HeaderMtmHost,
|
|
43
45
|
CONST_cookieListViewLayout,
|
|
44
46
|
CONST_debounce_INPUT,
|
|
45
47
|
COOKIE_MTM_SITE_ID,
|
|
@@ -53,7 +55,6 @@ export {
|
|
|
53
55
|
HOTKEY_Listview_Switchlayout,
|
|
54
56
|
HOTKEY_Switchlayout,
|
|
55
57
|
HeaderMtmApi,
|
|
56
|
-
HeaderMtmHost,
|
|
57
58
|
ImageNoExist,
|
|
58
59
|
IsDebugCookie,
|
|
59
60
|
ItemAction_list_new_item,
|
|
@@ -65,7 +66,6 @@ export {
|
|
|
65
66
|
MTM_SERVER_COOKIE_ACTIVATE_SELFBACKEND_URL,
|
|
66
67
|
MTM_SERVER_COOKIE_ACTIVATE_URL,
|
|
67
68
|
MTM_SITE_HOSTNAME,
|
|
68
|
-
MtM_TOKEN_NAME,
|
|
69
69
|
TRPC_API_PREFIX,
|
|
70
70
|
cookieBackendUrl,
|
|
71
71
|
fetchMaxRetry
|
|
@@ -27,7 +27,6 @@ export interface ListViewState extends ListViewStateProps {
|
|
|
27
27
|
setOpenEdit: (openEdit: boolean) => void;
|
|
28
28
|
setLayout: (layout: string) => void;
|
|
29
29
|
setActivateItem: (activateItem: any) => void;
|
|
30
|
-
loadListData: () => Promise<any>;
|
|
31
30
|
nextPage: () => void;
|
|
32
31
|
setEditRender: (a: Renderable<any>) => void;
|
|
33
32
|
setDetailData: (detailData: any) => void;
|
|
@@ -30,33 +30,12 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
}
|
|
31
31
|
return target;
|
|
32
32
|
};
|
|
33
|
-
var __async = (__this, __arguments, generator) => {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
var fulfilled = (value) => {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.next(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
var rejected = (value) => {
|
|
43
|
-
try {
|
|
44
|
-
step(generator.throw(value));
|
|
45
|
-
} catch (e) {
|
|
46
|
-
reject(e);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
33
|
import { jsx } from "react/jsx-runtime";
|
|
54
34
|
import { setCookie } from "mtxlib/clientlib";
|
|
55
35
|
import { createContext, useContext, useRef } from "react";
|
|
56
36
|
import { useStore } from "zustand";
|
|
57
37
|
import { createStore } from "zustand/vanilla";
|
|
58
|
-
import { CONST_cookieListViewLayout
|
|
59
|
-
import { goMtmQueryFn } from "../../mtmFetcher";
|
|
38
|
+
import { CONST_cookieListViewLayout } from "../../consts";
|
|
60
39
|
import { useGomtm } from "../../store/mtapp-store";
|
|
61
40
|
const createListviewStore = (initProps) => {
|
|
62
41
|
const DEFAULT_PROPS = {
|
|
@@ -80,21 +59,21 @@ const createListviewStore = (initProps) => {
|
|
|
80
59
|
setCookie(CONST_cookieListViewLayout, layout);
|
|
81
60
|
return set((state) => ({ layout }));
|
|
82
61
|
},
|
|
83
|
-
loadListData: () =>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
62
|
+
// loadListData: async () => {
|
|
63
|
+
// const baseUrl = get().backendUrl || ""
|
|
64
|
+
// const apiUrl = (new URL(MTM_API_PREFIX, baseUrl)).toString()
|
|
65
|
+
// console.log("loadListData, apiUrl:", apiUrl)
|
|
66
|
+
// const data = await goMtmQueryFn({
|
|
67
|
+
// svc: get().svc,
|
|
68
|
+
// method: get().methodList,
|
|
69
|
+
// input: get().paramsList,
|
|
70
|
+
// options: {
|
|
71
|
+
// url: apiUrl
|
|
72
|
+
// }
|
|
73
|
+
// })
|
|
74
|
+
// set({ data })
|
|
75
|
+
// return data
|
|
76
|
+
// },
|
|
98
77
|
nextPage: () => {
|
|
99
78
|
},
|
|
100
79
|
setEditRender: (editRender) => set({ editRender }),
|
package/dist/esm/gomtmQuery.js
CHANGED
|
@@ -7,6 +7,7 @@ const useGmtmQjeryFn = () => {
|
|
|
7
7
|
const backendUrl = useGomtm((x) => x.backendUrl);
|
|
8
8
|
const cookieStr = useGomtm((x) => x.cookieStr);
|
|
9
9
|
const token = useGomtm((x) => x.token);
|
|
10
|
+
const gomtmHost = useGomtm((x) => x.gomtmHost);
|
|
10
11
|
return (svc, method, input) => {
|
|
11
12
|
return goMtmQueryFn({
|
|
12
13
|
svc,
|
|
@@ -15,41 +16,29 @@ const useGmtmQjeryFn = () => {
|
|
|
15
16
|
options: {
|
|
16
17
|
url: new URL(MTM_API_PREFIX, backendUrl).toString(),
|
|
17
18
|
token,
|
|
18
|
-
cookieStr
|
|
19
|
+
cookieStr,
|
|
20
|
+
gomtmHost
|
|
19
21
|
}
|
|
20
22
|
});
|
|
21
23
|
};
|
|
22
24
|
};
|
|
23
25
|
const useGomtmQuery = (svc, method, input) => {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const token = useGomtm((x) => x.token);
|
|
27
|
-
const query = useQuery({
|
|
26
|
+
const fn = useGmtmQjeryFn();
|
|
27
|
+
return useQuery({
|
|
28
28
|
queryKey: createQueryKey(svc, method, input),
|
|
29
|
-
queryFn: (k) =>
|
|
30
|
-
svc,
|
|
31
|
-
method,
|
|
32
|
-
input,
|
|
33
|
-
options: {
|
|
34
|
-
url: new URL(MTM_API_PREFIX, backendUrl).toString(),
|
|
35
|
-
token,
|
|
36
|
-
cookieStr
|
|
37
|
-
}
|
|
38
|
-
})
|
|
29
|
+
queryFn: (k) => fn(svc, method, input)
|
|
39
30
|
});
|
|
40
|
-
return query;
|
|
41
31
|
};
|
|
42
32
|
const useGomtmSuspenseQuery = (svc, method, input) => {
|
|
43
33
|
const fn = useGmtmQjeryFn();
|
|
44
|
-
|
|
34
|
+
return useSuspenseQuery({
|
|
45
35
|
queryKey: createQueryKey(svc, method, input),
|
|
46
36
|
queryFn: (k) => fn(svc, method, input)
|
|
47
37
|
});
|
|
48
|
-
return query;
|
|
49
38
|
};
|
|
50
39
|
function useGomtmSuspenseInfiniteQuery(svc, method, input) {
|
|
51
40
|
const fn = useGmtmQjeryFn();
|
|
52
|
-
|
|
41
|
+
return useSuspenseInfiniteQuery({
|
|
53
42
|
queryKey: createInfiniteQueryKey(svc, method, input),
|
|
54
43
|
queryFn: (k) => fn(svc, method, input),
|
|
55
44
|
initialPageParam: input,
|
|
@@ -58,7 +47,6 @@ function useGomtmSuspenseInfiniteQuery(svc, method, input) {
|
|
|
58
47
|
return lastPage;
|
|
59
48
|
}
|
|
60
49
|
});
|
|
61
|
-
return query;
|
|
62
50
|
}
|
|
63
51
|
const useGomtmMutation = (svc, method) => {
|
|
64
52
|
const fn = useGmtmQjeryFn();
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
|
4
4
|
import { TailwindIndicator } from "mtxuilib/common/tailwind-indicator";
|
|
5
|
-
import { AppMetaRender } from "mtxuilib/store/AppMetaRender";
|
|
6
5
|
import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
|
|
7
6
|
import { TooltipProvider } from "mtxuilib/ui/tooltip";
|
|
8
7
|
import { MtButton } from "mtxuilib/ui/ui-mt/Button";
|
|
9
8
|
import { AppProgressBar as ProgressBar } from "next-nprogress-bar";
|
|
9
|
+
import { ThemeProvider } from "next-themes";
|
|
10
10
|
import { Suspense, lazy, useMemo, useState } from "react";
|
|
11
11
|
import { useHotkeys } from "react-hotkeys-hook";
|
|
12
12
|
import { Toaster } from "sonner";
|
|
@@ -38,23 +38,31 @@ const LayoutBase = (props) => {
|
|
|
38
38
|
return LzFrontLayout;
|
|
39
39
|
}
|
|
40
40
|
}, [layout]);
|
|
41
|
-
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
42
|
+
ThemeProvider,
|
|
43
|
+
{
|
|
44
|
+
attribute: "class",
|
|
45
|
+
defaultTheme: "system",
|
|
46
|
+
enableSystem: true,
|
|
47
|
+
disableTransitionOnChange: true,
|
|
48
|
+
children: /* @__PURE__ */ jsxs(TooltipProvider, { delayDuration: 0, children: [
|
|
49
|
+
/* @__PURE__ */ jsx(LayoutComponent, { children }),
|
|
50
|
+
/* @__PURE__ */ jsx(
|
|
51
|
+
ProgressBar,
|
|
52
|
+
{
|
|
53
|
+
height: "4px",
|
|
54
|
+
color: "#4934eb",
|
|
55
|
+
options: { showSpinner: false },
|
|
56
|
+
shallowRouting: true
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
/* @__PURE__ */ jsx(ReactQueryDevtools, {}),
|
|
60
|
+
/* @__PURE__ */ jsx(Toaster, {}),
|
|
61
|
+
/* @__PURE__ */ jsx(TailwindIndicator, {}),
|
|
62
|
+
/* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(LayoutSwitchDlg, {}) })
|
|
63
|
+
] })
|
|
64
|
+
}
|
|
65
|
+
) });
|
|
58
66
|
};
|
|
59
67
|
const LayoutSwitchDlg = () => {
|
|
60
68
|
const layout = useGomtm((x) => x.layout);
|
|
@@ -6,11 +6,11 @@ import { Avatar, AvatarFallback, AvatarImage } from "mtxuilib/ui/avatar";
|
|
|
6
6
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
|
|
7
7
|
import { DropdownMenuItemLink } from "mtxuilib/ui/ui-mt/DropdownMenuItemLink";
|
|
8
8
|
import { usePathname } from "next/navigation";
|
|
9
|
-
import { useAuth } from "../providers/AuthProvider";
|
|
9
|
+
import { useAuth, useLogout } from "../providers/AuthProvider";
|
|
10
10
|
function UserAvatorMenus() {
|
|
11
11
|
const pathName = usePathname();
|
|
12
12
|
const auth = useAuth();
|
|
13
|
-
|
|
13
|
+
const logout = useLogout();
|
|
14
14
|
return /* @__PURE__ */ jsx(Fragment, { children: !auth.userId ? /* @__PURE__ */ jsx(MtLink, { variant: "ghost", href: `/login?next=${pathName}`, children: " login" }) : /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
15
15
|
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Avatar, { children: [
|
|
16
16
|
/* @__PURE__ */ jsx(AvatarImage, { src: "/mtm_images/placeholder-user.jpg", alt: "@siteCook" }),
|
|
@@ -50,7 +50,9 @@ function UserAvatorMenus() {
|
|
|
50
50
|
] }) }) }),
|
|
51
51
|
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
52
52
|
/* @__PURE__ */ jsx(DropdownMenuGroupDevelop, {}),
|
|
53
|
-
/* @__PURE__ */ jsx(
|
|
53
|
+
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => {
|
|
54
|
+
logout();
|
|
55
|
+
}, children: " Log out " }),
|
|
54
56
|
/* @__PURE__ */ jsx(DropdownMenuItemLink, { href: "/", children: "\u9996\u9875" })
|
|
55
57
|
] })
|
|
56
58
|
] }) });
|
|
File without changes
|
|
File without changes
|
package/dist/esm/mtmFetcher.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface goMtmQueryFnProps {
|
|
|
9
9
|
url?: string;
|
|
10
10
|
token?: string;
|
|
11
11
|
cookieStr?: string;
|
|
12
|
+
gomtmHost: string;
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
export declare const goMtmQueryFn: (props: goMtmQueryFnProps) => Promise<any>;
|
|
@@ -16,12 +17,13 @@ export declare const ssrGetBackendUrl: () => string;
|
|
|
16
17
|
export declare const gomtmApiUrl: () => string;
|
|
17
18
|
export declare function createMtmServiceClient<T extends ServiceType>(service: T, url?: string): import("@connectrpc/connect").PromiseClient<T>;
|
|
18
19
|
export declare function createTransport(): import("@connectrpc/connect").Transport;
|
|
19
|
-
export declare function createMtmServiceClientByName<T extends ServiceType>(svcName: string, url?: string, token?: string): import("@connectrpc/connect").PromiseClient<ServiceType>;
|
|
20
|
+
export declare function createMtmServiceClientByName<T extends ServiceType>(svcName: string, url?: string, token?: string, gomtmHost?: string): import("@connectrpc/connect").PromiseClient<ServiceType>;
|
|
20
21
|
type CustomRequestInit = RequestInit & {
|
|
21
22
|
cookieStr?: string;
|
|
22
23
|
token?: string;
|
|
23
24
|
enableCache?: boolean;
|
|
24
25
|
enableLog?: boolean;
|
|
26
|
+
gomtmHost?: string;
|
|
25
27
|
};
|
|
26
28
|
export declare const gomtmFetcher: (initGlobal?: CustomRequestInit) => (input: string | URL | globalThis.Request, init?: CustomRequestInit) => Promise<Response>;
|
|
27
29
|
export {};
|
package/dist/esm/mtmFetcher.js
CHANGED
|
@@ -39,8 +39,9 @@ import { createPromiseClient } from "@connectrpc/connect";
|
|
|
39
39
|
import { createConnectTransport } from "@connectrpc/connect-web";
|
|
40
40
|
import { camelCase, merge } from "lodash";
|
|
41
41
|
import { fetchMiddleWithCache } from "mtxlib/http/fetchMiddleWithCache";
|
|
42
|
-
import { MTM_API_PREFIX } from "./consts";
|
|
42
|
+
import { CONST_HeaderMtmHost, MTM_API_PREFIX } from "./consts";
|
|
43
43
|
import { MtmService } from "./gomtmpb/mtm/sppb/mtm_connect";
|
|
44
|
+
import { MtmError } from "./gomtmpb/mtm/sppb/mtm_pb";
|
|
44
45
|
const allServices = [MtmService];
|
|
45
46
|
const createQueryKey = (svc, method, input) => {
|
|
46
47
|
return [svc, method, input || {}];
|
|
@@ -49,8 +50,13 @@ const createInfiniteQueryKey = (svc, method, input) => {
|
|
|
49
50
|
return [...createQueryKey(svc, method, input), "infinite"];
|
|
50
51
|
};
|
|
51
52
|
const goMtmQueryFn = (props) => __async(void 0, null, function* () {
|
|
52
|
-
var _a, _b;
|
|
53
|
-
const client = createMtmServiceClientByName(
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
const client = createMtmServiceClientByName(
|
|
55
|
+
props.svc,
|
|
56
|
+
(_a = props.options) == null ? void 0 : _a.url,
|
|
57
|
+
(_b = props.options) == null ? void 0 : _b.token,
|
|
58
|
+
(_c = props.options) == null ? void 0 : _c.gomtmHost
|
|
59
|
+
);
|
|
54
60
|
if (!client) {
|
|
55
61
|
throw new Error(`missing mtmclient:"${props.svc}"`);
|
|
56
62
|
}
|
|
@@ -63,7 +69,11 @@ const goMtmQueryFn = (props) => __async(void 0, null, function* () {
|
|
|
63
69
|
const data = yield methodFn(props.input);
|
|
64
70
|
return toPlainMessage(data);
|
|
65
71
|
} catch (e) {
|
|
66
|
-
console.log("goMtmQueryFn
|
|
72
|
+
console.log("[goMtmQueryFn]\u51FA\u9519", e);
|
|
73
|
+
return toPlainMessage(new MtmError({
|
|
74
|
+
errCode: "error call gomtm client",
|
|
75
|
+
errMessage: e.toString()
|
|
76
|
+
}));
|
|
67
77
|
}
|
|
68
78
|
});
|
|
69
79
|
const ssrGetBackendUrl = () => {
|
|
@@ -97,7 +107,7 @@ function createTransport() {
|
|
|
97
107
|
useHttpGet: true
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
|
-
function createMtmServiceClientByName(svcName, url, token) {
|
|
110
|
+
function createMtmServiceClientByName(svcName, url, token, gomtmHost) {
|
|
101
111
|
let svcType = void 0;
|
|
102
112
|
for (const a of allServices) {
|
|
103
113
|
if (a.typeName == svcName) {
|
|
@@ -114,7 +124,8 @@ function createMtmServiceClientByName(svcName, url, token) {
|
|
|
114
124
|
baseUrl,
|
|
115
125
|
fetch: gomtmFetcher({
|
|
116
126
|
cookieStr: token,
|
|
117
|
-
token
|
|
127
|
+
token,
|
|
128
|
+
gomtmHost
|
|
118
129
|
})
|
|
119
130
|
})
|
|
120
131
|
);
|
|
@@ -140,11 +151,15 @@ const gomtmFetcher = (initGlobal) => {
|
|
|
140
151
|
if (typeof window == "undefined") {
|
|
141
152
|
cookieStr1 = (yield import("next/headers")).headers().get("cookie") || "";
|
|
142
153
|
}
|
|
154
|
+
let gomtmHost = initGlobal == null ? void 0 : initGlobal.gomtmHost;
|
|
155
|
+
if (!gomtmHost && typeof window == "undefined") {
|
|
156
|
+
gomtmHost = (yield import("next/headers")).headers().get("host") || "";
|
|
157
|
+
}
|
|
143
158
|
init = __spreadValues(__spreadValues({}, init), {
|
|
144
|
-
headers: __spreadValues(__spreadValues({
|
|
159
|
+
headers: __spreadValues(__spreadValues(__spreadValues({
|
|
145
160
|
// ...init.headers,
|
|
146
161
|
"Content-Type": "application/json"
|
|
147
|
-
}, cookieStr1 && { "Cookie": cookieStr1 }), token && { "Authorization": "Bearer " + token })
|
|
162
|
+
}, cookieStr1 && { "Cookie": cookieStr1 }), token && { "Authorization": "Bearer " + token }), gomtmHost && { [CONST_HeaderMtmHost]: gomtmHost })
|
|
148
163
|
});
|
|
149
164
|
let fetcher = fetch;
|
|
150
165
|
req.enableCache = true;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { deleteCookie } from "mtxlib/clientlib";
|
|
3
|
+
import { useMtRouter } from "mtxuilib/hooks/use-router";
|
|
4
|
+
import { useCallback, useMemo } from "react";
|
|
5
|
+
import { CONST_COOKIE_MtM_TOKEN_NAME } from "../consts";
|
|
3
6
|
import { useGomtmSuspenseQuery } from "../gomtmQuery";
|
|
4
7
|
import { userinfo } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
|
|
5
8
|
import { useGomtm } from "../store/mtapp-store";
|
|
@@ -21,7 +24,6 @@ function isRoleMatch(currentRoles, allowRoles) {
|
|
|
21
24
|
function useAuth() {
|
|
22
25
|
const cookieStr = useGomtm((x) => x.cookieStr);
|
|
23
26
|
const token = useGomtm((x) => x.token);
|
|
24
|
-
console.log("\uFF08useAuth\uFF09cookieStr-----------", { token, cookieStr });
|
|
25
27
|
const userInfoQuery = useGomtmSuspenseQuery(userinfo.service.typeName, userinfo.name);
|
|
26
28
|
const userId = useMemo(() => {
|
|
27
29
|
var _a;
|
|
@@ -33,7 +35,15 @@ function useAuth() {
|
|
|
33
35
|
// isAdmin
|
|
34
36
|
};
|
|
35
37
|
}
|
|
38
|
+
function useLogout() {
|
|
39
|
+
const router = useMtRouter();
|
|
40
|
+
return useCallback(() => {
|
|
41
|
+
deleteCookie(CONST_COOKIE_MtM_TOKEN_NAME);
|
|
42
|
+
router.push("/");
|
|
43
|
+
}, [router]);
|
|
44
|
+
}
|
|
36
45
|
export {
|
|
37
46
|
isRoleMatch,
|
|
38
|
-
useAuth
|
|
47
|
+
useAuth,
|
|
48
|
+
useLogout
|
|
39
49
|
};
|
|
@@ -39,7 +39,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
};
|
|
40
40
|
import { jsx } from "react/jsx-runtime";
|
|
41
41
|
import { cookies, headers } from "next/headers";
|
|
42
|
-
import {
|
|
42
|
+
import { CONST_COOKIE_MtM_TOKEN_NAME, CookieConfigState } from "../consts";
|
|
43
43
|
import { ssrGetBackendUrl } from "../mtmFetcher";
|
|
44
44
|
import { GoMtmAppProvider } from "../store/mtapp-store";
|
|
45
45
|
function GomtmAppSS(props) {
|
|
@@ -50,13 +50,15 @@ function GomtmAppSS(props) {
|
|
|
50
50
|
const cookiesStr = headers().get("Cookie");
|
|
51
51
|
const configState = JSON.parse(((_a = cookies().get(CookieConfigState)) == null ? void 0 : _a.value) || "{}");
|
|
52
52
|
const cState = configState["state"];
|
|
53
|
-
const token = (_b = cookies().get(
|
|
53
|
+
const token = (_b = cookies().get(CONST_COOKIE_MtM_TOKEN_NAME)) == null ? void 0 : _b.value;
|
|
54
|
+
const gomtmHost = headers().get("host");
|
|
54
55
|
return /* @__PURE__ */ jsx(
|
|
55
56
|
GoMtmAppProvider,
|
|
56
57
|
__spreadProps(__spreadValues({}, cState), {
|
|
57
58
|
cookieStr: cookiesStr || "",
|
|
58
59
|
token,
|
|
59
60
|
backendUrl: (cState == null ? void 0 : cState.backendUrl) || backend,
|
|
61
|
+
gomtmHost,
|
|
60
62
|
children
|
|
61
63
|
})
|
|
62
64
|
);
|
|
@@ -14,6 +14,7 @@ interface GomtmAppProps {
|
|
|
14
14
|
params?: any;
|
|
15
15
|
cookieStr?: string;
|
|
16
16
|
token?: string;
|
|
17
|
+
gomtmHost?: string;
|
|
17
18
|
globalSearchParams?: any;
|
|
18
19
|
openDebug?: boolean;
|
|
19
20
|
}
|
|
@@ -26,8 +27,9 @@ interface GomtmAppState extends GomtmAppProps {
|
|
|
26
27
|
setGlobalSearchParams: (globalSearchParams: any) => void;
|
|
27
28
|
setOpenDebug: (openDebug: boolean) => void;
|
|
28
29
|
setCacheEnabled: (cacheEnabled: boolean) => void;
|
|
30
|
+
logout: () => void;
|
|
29
31
|
}
|
|
30
|
-
export declare const
|
|
32
|
+
export declare const gomtmContext: import("react").Context<(Omit<import("zustand").StoreApi<GomtmAppState>, "persist"> & {
|
|
31
33
|
persist: {
|
|
32
34
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<GomtmAppState, unknown>>) => void;
|
|
33
35
|
clearStorage: () => void;
|
|
@@ -40,11 +40,12 @@ import { createJSONStorage, persist } from "zustand/middleware";
|
|
|
40
40
|
import { createStore } from "zustand/vanilla";
|
|
41
41
|
import { GoMtmDebug } from "../components/devtools/GoMtmDebug";
|
|
42
42
|
import { TransportProvider } from "../connectquery";
|
|
43
|
-
import { CookieConfigState, HOTKEY_Debug, MTM_API_PREFIX } from "../consts";
|
|
43
|
+
import { CONST_COOKIE_MtM_TOKEN_NAME, CookieConfigState, HOTKEY_Debug, MTM_API_PREFIX } from "../consts";
|
|
44
44
|
import { anypbTypeReg } from "../messageTypeRegistry";
|
|
45
45
|
import { gomtmFetcher } from "../mtmFetcher";
|
|
46
46
|
import { MtReactQueryProvider } from "../providers/ReactQueryProvider";
|
|
47
47
|
import { customCookieStorage } from "./customStorage";
|
|
48
|
+
import { deleteCookie } from "mtxlib/clientlib";
|
|
48
49
|
const createGomtmAppStore = (initProps) => {
|
|
49
50
|
const DEFAULT_PROPS = {
|
|
50
51
|
debug: false,
|
|
@@ -61,7 +62,10 @@ const createGomtmAppStore = (initProps) => {
|
|
|
61
62
|
setCounter: (counter) => set({ counter }),
|
|
62
63
|
setGlobalSearchParams: (globalSearchParams) => set({ globalSearchParams }),
|
|
63
64
|
openDebug: false,
|
|
64
|
-
setOpenDebug: (openDebug) => set({ openDebug })
|
|
65
|
+
setOpenDebug: (openDebug) => set({ openDebug }),
|
|
66
|
+
logout: () => {
|
|
67
|
+
deleteCookie(CONST_COOKIE_MtM_TOKEN_NAME);
|
|
68
|
+
}
|
|
65
69
|
}),
|
|
66
70
|
{
|
|
67
71
|
name: CookieConfigState,
|
|
@@ -80,14 +84,14 @@ const createGomtmAppStore = (initProps) => {
|
|
|
80
84
|
)
|
|
81
85
|
);
|
|
82
86
|
};
|
|
83
|
-
const
|
|
87
|
+
const gomtmContext = createContext(null);
|
|
84
88
|
const GoMtmAppProvider = (props) => {
|
|
85
89
|
const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
|
|
86
90
|
const storeRef = useRef();
|
|
87
91
|
if (!storeRef.current) {
|
|
88
92
|
storeRef.current = createGomtmAppStore(props);
|
|
89
93
|
}
|
|
90
|
-
return /* @__PURE__ */ jsx(
|
|
94
|
+
return /* @__PURE__ */ jsx(gomtmContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsxs(MtConnectProvider, { children: [
|
|
91
95
|
/* @__PURE__ */ jsxs(MtReactQueryProvider, { children: [
|
|
92
96
|
/* @__PURE__ */ jsx(GoMtmDebug, {}),
|
|
93
97
|
children
|
|
@@ -96,7 +100,7 @@ const GoMtmAppProvider = (props) => {
|
|
|
96
100
|
] }) });
|
|
97
101
|
};
|
|
98
102
|
function useGomtm(selector) {
|
|
99
|
-
const store = useContext(
|
|
103
|
+
const store = useContext(gomtmContext);
|
|
100
104
|
if (!store)
|
|
101
105
|
throw new Error("userGomtm Missing GoMtmAppProvider in the tree");
|
|
102
106
|
return useStore(store, selector);
|
|
@@ -144,9 +148,9 @@ const DebugCounter = () => {
|
|
|
144
148
|
] }) });
|
|
145
149
|
};
|
|
146
150
|
export {
|
|
147
|
-
BearContext,
|
|
148
151
|
DebugCounter,
|
|
149
152
|
GoMtmAppProvider,
|
|
150
153
|
MtConnectProvider,
|
|
154
|
+
gomtmContext,
|
|
151
155
|
useGomtm
|
|
152
156
|
};
|