@lark-apaas/client-toolkit 1.2.28-alpha.67 → 1.2.28-alpha.68

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/lib/auth.d.ts CHANGED
@@ -1 +1 @@
1
- export { CanRole, AbilityContext, ROLE_SUBJECT } from '@lark-apaas/auth-sdk';
1
+ export { CanRole, AbilityContext, ROLE_SUBJECT, useAuth, } from '@lark-apaas/auth-sdk';
package/lib/auth.js CHANGED
@@ -1,2 +1,2 @@
1
- import { AbilityContext, CanRole, ROLE_SUBJECT } from "@lark-apaas/auth-sdk";
2
- export { AbilityContext, CanRole, ROLE_SUBJECT };
1
+ import { AbilityContext, CanRole, ROLE_SUBJECT, useAuth } from "@lark-apaas/auth-sdk";
2
+ export { AbilityContext, CanRole, ROLE_SUBJECT, useAuth };
@@ -9,6 +9,7 @@ import { PageHoc } from "./PageHoc.js";
9
9
  import { reportTeaEvent } from "./utils/tea.js";
10
10
  import { useAppInfo } from "../../hooks/index.js";
11
11
  import { TrackKey } from "../../types/tea.js";
12
+ import { slardar } from "@lark-apaas/internal-slardar";
12
13
  import safety from "./safety.js";
13
14
  import { getAppId } from "../../utils/getAppId.js";
14
15
  import { isNewPathEnabled } from "../../utils/apiPath.js";
@@ -38,14 +39,33 @@ const App = (props)=>{
38
39
  });
39
40
  }, []);
40
41
  useEffect(()=>{
41
- if ('production' === process.env.NODE_ENV) reportTeaEvent({
42
- trackKey: TrackKey.VIEW,
43
- trackParams: {
44
- artifact_uid: getAppId(),
45
- agent_id: 'agent_miaoda',
46
- url: window.location.href
47
- }
48
- });
42
+ if ('production' === process.env.NODE_ENV) {
43
+ reportTeaEvent({
44
+ trackKey: TrackKey.VIEW,
45
+ trackParams: {
46
+ artifact_uid: getAppId(),
47
+ agent_id: 'agent_miaoda',
48
+ url: window.location.href
49
+ }
50
+ });
51
+ const appId = getAppId();
52
+ const firstRenderTime = Math.round(performance.now());
53
+ const navEntry = performance.getEntriesByType('navigation')[0];
54
+ const pageLoadTime = navEntry && navEntry.loadEventEnd > 0 ? Math.round(navEntry.loadEventEnd - navEntry.startTime) : void 0;
55
+ slardar.sendEvent({
56
+ name: 'app-first-render',
57
+ metrics: {
58
+ firstRenderTime,
59
+ ...null != pageLoadTime ? {
60
+ pageLoadTime
61
+ } : {}
62
+ },
63
+ categories: {
64
+ appId: appId ?? 'unknown',
65
+ mode: isMiaodaPreview ? 'preview' : 'runtime'
66
+ }
67
+ });
68
+ }
49
69
  }, []);
50
70
  const appId = getAppId();
51
71
  const permissionApiUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/permissions/roles` : `/spark/app/${appId}/runtime/api/v1/permissions/roles`;
@@ -14,17 +14,31 @@ const Component = ()=>{
14
14
  const isMobile = useIsMobile();
15
15
  const [userinfo, setUserinfo] = useState(null);
16
16
  const [isInternetVisible, setIsInternetVisible] = useState(false);
17
+ const [showBadge, setShowBadge] = useState(true);
18
+ const [badgeLoaded, setBadgeLoaded] = useState(false);
17
19
  const timeoutRef = useRef(null);
18
20
  useEffect(()=>{
19
21
  const appId = getAppId();
22
+ const csrfHeaders = {
23
+ 'X-Suda-Csrf-Token': getCsrfToken()
24
+ };
20
25
  const tenantInfoUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/tenant_info` : `/spark/b/${appId}/tenant_info`;
21
26
  fetch(tenantInfoUrl, {
22
- headers: {
23
- 'X-Suda-Csrf-Token': getCsrfToken()
24
- }
27
+ headers: csrfHeaders
25
28
  }).then((res)=>res.json()).then((data)=>{
26
29
  setUserinfo(data?.data?.tenant_info);
27
30
  setIsInternetVisible(data?.data?.is_internet_visible);
31
+ }).catch(()=>{});
32
+ const getPublishedUrl = isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/studio/get_published` : `/spark/b/${appId}/get_published`;
33
+ fetch(getPublishedUrl, {
34
+ headers: csrfHeaders
35
+ }).then((res)=>res.json()).then((data)=>{
36
+ const badge = data?.data?.app_info?.show_badge;
37
+ setShowBadge(false !== badge);
38
+ }).catch(()=>{
39
+ setShowBadge(true);
40
+ }).finally(()=>{
41
+ setBadgeLoaded(true);
28
42
  });
29
43
  }, []);
30
44
  useEffect(()=>{
@@ -39,6 +53,8 @@ const Component = ()=>{
39
53
  isMobile
40
54
  ]);
41
55
  if ('production' !== process.env.NODE_ENV) return null;
56
+ if (!badgeLoaded) return null;
57
+ if (!showBadge) return null;
42
58
  if (!visible) return null;
43
59
  if (isMobile) return /*#__PURE__*/ jsxs(Sheet, {
44
60
  open: open,
@@ -47,7 +63,7 @@ const Component = ()=>{
47
63
  /*#__PURE__*/ jsx(SheetTrigger, {
48
64
  asChild: true,
49
65
  children: /*#__PURE__*/ jsxs("div", {
50
- className: "fixed right-[12px] bottom-[80px] inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-[10px] py-[6px] bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-md text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000]",
66
+ className: "fixed right-[12px] bottom-[80px] inline-flex items-center gap-x-1 border-solid border-[#ffffff1a] border px-[10px] py-[6px] bg-[#1f2329e5] backdrop-blur-[5px] shadow-[0px_6px_12px_0px_#41444a0a,0px_8px_24px_8px_#41444a0a] rounded-[6px] text-[#ebebeb)] font-['PingFang_SC'] text-xs leading-[20px] tracking-[0px] z-[10000000]",
51
67
  onClick: ()=>{
52
68
  setOpen(true);
53
69
  },
@@ -242,7 +258,7 @@ const Component = ()=>{
242
258
  className: "w-full self-stretch shrink-0 flex items-start gap-x-[8px]",
243
259
  children: [
244
260
  /*#__PURE__*/ jsx("div", {
245
- className: "flex-1 flex rounded-lg items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
261
+ className: "flex-1 flex rounded-[8px] items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
246
262
  "data-custom-element": "safety-close",
247
263
  onClick: (e)=>{
248
264
  e.stopPropagation();
@@ -253,7 +269,7 @@ const Component = ()=>{
253
269
  children: "不再展示"
254
270
  }),
255
271
  /*#__PURE__*/ jsx("div", {
256
- className: "flex-1 flex rounded-lg items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
272
+ className: "flex-1 flex rounded-[8px] items-center justify-center h-[34px] border-[0.5px] border-solid border-[#ffffff1c] hover:border-[#ffffff33] bg-[#ffffff08] hover:bg-[#ffffff14] cursor-pointer text-[#ebebeb]",
257
273
  "data-custom-element": "safety-more",
258
274
  onClick: ()=>{
259
275
  window.open('https://miaoda.feishu.cn/landing', '_blank');
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const badgeVariants: (props?: {
4
- variant?: "default" | "destructive" | "secondary" | "outline";
4
+ variant?: "default" | "destructive" | "outline" | "secondary";
5
5
  } & import("class-variance-authority/dist/types").ClassProp) => string;
6
6
  declare function Badge({ className, variant, asChild, ...props }: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
7
7
  asChild?: boolean;
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
2
  import { type VariantProps } from "class-variance-authority";
3
3
  declare const buttonVariants: (props?: {
4
- variant?: "default" | "link" | "destructive" | "secondary" | "outline" | "ghost";
5
- size?: "default" | "icon" | "sm" | "lg" | "icon-sm" | "icon-lg";
4
+ variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost";
5
+ size?: "default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg";
6
6
  } & import("class-variance-authority/dist/types").ClassProp) => string;
7
7
  declare function Button({ className, variant, size, asChild, ...props }: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
8
8
  asChild?: boolean;
@@ -8,7 +8,7 @@ const buttonVariants = cva("inline-flex items-center justify-center gap-2 whites
8
8
  variant: {
9
9
  default: "bg-primary text-primary-foreground not-disabled:hover:bg-primary/90",
10
10
  destructive: "bg-destructive text-white not-disabled:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
11
- outline: "border bg-background not-disabled:hover:bg-accent not-disabled:hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:not-disabled:hover:bg-input/50",
11
+ outline: "border border-input bg-transparent text-foreground not-disabled:hover:bg-accent not-disabled:hover:text-accent-foreground",
12
12
  secondary: "bg-secondary text-secondary-foreground not-disabled:hover:bg-secondary/80",
13
13
  ghost: "not-disabled:hover:bg-accent not-disabled:hover:text-accent-foreground dark:not-disabled:hover:bg-accent/50",
14
14
  link: "text-primary underline-offset-4 not-disabled:hover:underline"
@@ -0,0 +1,28 @@
1
+ export interface ConfirmOptions {
2
+ /** 标题,默认 "提示" */
3
+ title?: string;
4
+ /** 内容描述 */
5
+ message: string;
6
+ /** 确认按钮文案,默认 "确认" */
7
+ confirmText?: string;
8
+ /** 取消按钮文案,默认 "取消" */
9
+ cancelText?: string;
10
+ /** 确认按钮样式变体 */
11
+ variant?: 'default' | 'destructive';
12
+ }
13
+ /**
14
+ * 函数式确认弹窗,作为 window.confirm 的直接平替。
15
+ *
16
+ * @example
17
+ * // 简单用法(兼容 window.confirm 传参)
18
+ * const ok = await showConfirm('确定删除吗?');
19
+ *
20
+ * // 完整用法
21
+ * const ok = await showConfirm({
22
+ * title: '确认删除',
23
+ * message: '删除后不可恢复',
24
+ * confirmText: '删除',
25
+ * variant: 'destructive',
26
+ * });
27
+ */
28
+ export declare function showConfirm(options: string | ConfirmOptions): Promise<boolean>;
@@ -0,0 +1,83 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { Content, Description, Overlay, Portal, Root, Title } from "@radix-ui/react-dialog";
5
+ import { Button } from "./button.js";
6
+ import { clsxWithTw } from "../../utils/utils.js";
7
+ function showConfirm(options) {
8
+ const opts = 'string' == typeof options ? {
9
+ message: options
10
+ } : options;
11
+ const { title = '提示', message, confirmText = '确认', cancelText = '取消', variant = 'default' } = opts;
12
+ return new Promise((resolve)=>{
13
+ const container = document.createElement('div');
14
+ document.body.appendChild(container);
15
+ const root = createRoot(container);
16
+ function cleanup() {
17
+ root.unmount();
18
+ container.remove();
19
+ }
20
+ function handleConfirm() {
21
+ cleanup();
22
+ resolve(true);
23
+ }
24
+ function handleCancel() {
25
+ cleanup();
26
+ resolve(false);
27
+ }
28
+ root.render(/*#__PURE__*/ jsx(ConfirmDialog, {
29
+ title: title,
30
+ message: message,
31
+ confirmText: confirmText,
32
+ cancelText: cancelText,
33
+ variant: variant,
34
+ onConfirm: handleConfirm,
35
+ onCancel: handleCancel
36
+ }));
37
+ });
38
+ }
39
+ function ConfirmDialog({ title, message, confirmText, cancelText, variant, onConfirm, onCancel }) {
40
+ return /*#__PURE__*/ jsx(Root, {
41
+ defaultOpen: true,
42
+ onOpenChange: (open)=>{
43
+ if (!open) onCancel();
44
+ },
45
+ children: /*#__PURE__*/ jsxs(Portal, {
46
+ children: [
47
+ /*#__PURE__*/ jsx(Overlay, {
48
+ className: clsxWithTw('fixed inset-0 z-[99999] bg-black/40', 'data-[state=open]:animate-in data-[state=open]:fade-in-0', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0')
49
+ }),
50
+ /*#__PURE__*/ jsxs(Content, {
51
+ className: clsxWithTw('fixed left-1/2 top-1/2 z-[99999] -translate-x-1/2 -translate-y-1/2', 'w-[90vw] max-w-[400px] rounded-lg', 'bg-[var(--popover,var(--color-neutral-00,#fff))] text-[var(--popover-foreground,var(--color-neutral-950,#1f2329))]', 'border border-[var(--border,var(--color-neutral-300,#dee0e3))]', 'shadow-lg p-6', 'data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95', 'data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95'),
52
+ children: [
53
+ /*#__PURE__*/ jsx(Title, {
54
+ className: clsxWithTw('text-base font-medium leading-6', 'text-[var(--foreground,var(--color-neutral-950,#1f2329))]'),
55
+ children: title
56
+ }),
57
+ /*#__PURE__*/ jsx(Description, {
58
+ className: clsxWithTw('mt-2 text-sm leading-5', 'text-[var(--muted-foreground,var(--color-neutral-700,#646a73))]'),
59
+ children: message
60
+ }),
61
+ /*#__PURE__*/ jsxs("div", {
62
+ className: clsxWithTw('mt-6 flex justify-end gap-2'),
63
+ children: [
64
+ /*#__PURE__*/ jsx(Button, {
65
+ variant: "outline",
66
+ className: "!bg-transparent !text-inherit",
67
+ onClick: onCancel,
68
+ children: cancelText
69
+ }),
70
+ /*#__PURE__*/ jsx(Button, {
71
+ variant: variant,
72
+ onClick: onConfirm,
73
+ children: confirmText
74
+ })
75
+ ]
76
+ })
77
+ ]
78
+ })
79
+ ]
80
+ })
81
+ });
82
+ }
83
+ export { showConfirm };
@@ -1,5 +1,11 @@
1
1
  import { IUserProfile } from '../apis/udt-types';
2
- export interface ICompatibilityUserProfile extends IUserProfile {
2
+ /**
3
+ * useCurrentUserProfile 的返回类型。
4
+ * 初始状态为空对象 `{}`(所有字段均为 undefined),异步获取用户信息后字段才会被填充。
5
+ * 使用时必须通过可选链或空值合并进行安全访问,如 `userInfo?.user_id`。
6
+ * 判断是否已加载完成应使用 `if (!userInfo?.user_id)` 而非 `if (!userInfo)`(因为空对象是 truthy)。
7
+ */
8
+ export type ICompatibilityUserProfile = Partial<IUserProfile & {
3
9
  /**
4
10
  * @deprecated please use `name`
5
11
  */
@@ -8,5 +14,14 @@ export interface ICompatibilityUserProfile extends IUserProfile {
8
14
  * @deprecated please use `avatar`
9
15
  */
10
16
  userAvatar: string;
11
- }
12
- export declare const useCurrentUserProfile: () => ICompatibilityUserProfile;
17
+ }>;
18
+ export declare const useCurrentUserProfile: () => Partial<IUserProfile & {
19
+ /**
20
+ * @deprecated please use `name`
21
+ */
22
+ userName: string;
23
+ /**
24
+ * @deprecated please use `avatar`
25
+ */
26
+ userAvatar: string;
27
+ }>;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export declare const capabilityClient: import("@lark-apaas/client-capability").CapabilityClient;
2
+ export { showConfirm } from './components/ui/confirm';
3
+ export type { ConfirmOptions } from './components/ui/confirm';
2
4
  declare const _default: {
3
5
  version: string;
4
6
  };
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ import { isNewPathEnabled } from "./utils/apiPath.js";
5
5
  import { logger } from "./logger/index.js";
6
6
  import { showToast } from "./components/ui/toast.js";
7
7
  import { version } from "../package.json";
8
+ import { showConfirm } from "./components/ui/confirm.js";
8
9
  const _appId = getAppId();
9
10
  const _acquireUploadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_upload_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_upload_url";
10
11
  const _acquireDownloadUrl = isNewPathEnabled() ? `/app/${_appId}/__runtime__/api/v1/studio/plugins/tmp_files/acquire_download_url` : "/af/api/v1/studio/plugins/tmp_files/acquire_download_url";
@@ -25,4 +26,4 @@ const capabilityClient = createClient({
25
26
  const src = {
26
27
  version: version
27
28
  };
28
- export { capabilityClient, src as default };
29
+ export { capabilityClient, src as default, showConfirm };
@@ -1,5 +1,11 @@
1
1
  import { IUserProfile } from '../apis/udt-types';
2
- export declare function getCurrentUserProfile(): IUserProfile;
2
+ /**
3
+ * 获取当前用户信息。
4
+ * 返回 Partial<IUserProfile>,因为初始值来自 window._userInfo,
5
+ * 该值在运行时始终为空对象 {},所有字段均为 undefined。
6
+ * 异步获取用户信息后才会被填充为完整的 IUserProfile。
7
+ */
8
+ export declare function getCurrentUserProfile(): Partial<IUserProfile>;
3
9
  /**
4
10
  * @deprecated 请使用 getCurrentUserProfile 代替
5
11
  */
@@ -0,0 +1,12 @@
1
+ import type { BatchGetChatsResponse, SearchChatsParams, SearchChatsResponse } from './types';
2
+ export type ChatServiceConfig = {
3
+ getAppId?: () => string | null | undefined;
4
+ searchChatsUrl?: (appId: string) => string;
5
+ listChatsUrl?: (appId: string) => string;
6
+ };
7
+ export declare class ChatService {
8
+ private config;
9
+ constructor(config?: ChatServiceConfig);
10
+ searchChats(params: SearchChatsParams): Promise<SearchChatsResponse>;
11
+ listChatsByIds(chatIds: string[]): Promise<BatchGetChatsResponse>;
12
+ }
@@ -0,0 +1,67 @@
1
+ import { getAppId } from "../../utils/getAppId.js";
2
+ const DEFAULT_CONFIG = {
3
+ getAppId: ()=>getAppId(),
4
+ searchChatsUrl: (appId)=>`/app/${appId}/__runtime__/api/v1/account/search`,
5
+ listChatsUrl: (appId)=>`/app/${appId}/__runtime__/api/v1/account/chat/list_chats`
6
+ };
7
+ class ChatService {
8
+ config;
9
+ constructor(config = {}){
10
+ this.config = {
11
+ ...DEFAULT_CONFIG,
12
+ ...config
13
+ };
14
+ }
15
+ async searchChats(params) {
16
+ const appId = this.config.getAppId();
17
+ if (!appId) throw new Error('Failed to get appId');
18
+ const response = await fetch(this.config.searchChatsUrl(appId), {
19
+ method: 'POST',
20
+ headers: {
21
+ 'Content-Type': 'application/json'
22
+ },
23
+ body: JSON.stringify({
24
+ query: params.query,
25
+ filters: {
26
+ userParam: {
27
+ commonParam: {
28
+ searchable: false
29
+ }
30
+ },
31
+ departmentParam: {
32
+ commonParam: {
33
+ searchable: false
34
+ }
35
+ },
36
+ chatParam: {
37
+ commonParam: {
38
+ searchable: true,
39
+ pageSize: params.pageSize ?? 100,
40
+ offset: params.offset ?? 0
41
+ }
42
+ }
43
+ }
44
+ }),
45
+ credentials: 'include'
46
+ });
47
+ if (!response.ok) throw new Error('Failed to search chats');
48
+ return response.json();
49
+ }
50
+ async listChatsByIds(chatIds) {
51
+ const appId = this.config.getAppId();
52
+ if (!appId) throw new Error('Failed to get appId');
53
+ const response = await fetch(this.config.listChatsUrl(appId), {
54
+ method: 'POST',
55
+ headers: {
56
+ 'Content-Type': 'application/json'
57
+ },
58
+ body: JSON.stringify({
59
+ chatIDList: chatIds
60
+ }),
61
+ credentials: 'include'
62
+ });
63
+ if (!response.ok) throw new Error('Failed to fetch chats by ids');
64
+ return response.json();
65
+ }
66
+ }
67
+ export { ChatService };
@@ -1,12 +1,14 @@
1
- import type { BatchGetUsersResponse, SearchUsersParams, SearchUsersResponse } from './types';
1
+ import type { BatchGetUsersResponse, ConvertExternalContactResponse, SearchUsersParams, SearchUsersResponse } from './types';
2
2
  export type UserServiceConfig = {
3
3
  getAppId?: () => string | null | undefined;
4
4
  searchUserUrl?: (appId: string) => string;
5
5
  listUsersUrl?: (appId: string) => string;
6
+ convertExternalContactUrl?: (appId: string) => string;
6
7
  };
7
8
  export declare class UserService {
8
9
  private config;
9
10
  constructor(config?: UserServiceConfig);
10
11
  searchUsers(params: SearchUsersParams): Promise<SearchUsersResponse>;
11
12
  listUsersByIds(userIds: string[]): Promise<BatchGetUsersResponse>;
13
+ convertExternalContact(larkUserID: string): Promise<ConvertExternalContactResponse>;
12
14
  }
@@ -3,7 +3,8 @@ import { isNewPathEnabled } from "../../utils/apiPath.js";
3
3
  const DEFAULT_CONFIG = {
4
4
  getAppId: ()=>getAppId(),
5
5
  searchUserUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/search_user` : `/af/app/${appId}/runtime/api/v1/account/search_user`,
6
- listUsersUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/list_users` : `/af/app/${appId}/runtime/api/v1/account/list_users`
6
+ listUsersUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/list_users` : `/af/app/${appId}/runtime/api/v1/account/list_users`,
7
+ convertExternalContactUrl: (appId)=>isNewPathEnabled() ? `/app/${appId}/__runtime__/api/v1/account/convert_lark_user` : `/af/app/${appId}/runtime/api/v1/account/convert_lark_user`
7
8
  };
8
9
  class UserService {
9
10
  config;
@@ -43,5 +44,23 @@ class UserService {
43
44
  if (!response.ok) throw new Error('Failed to fetch users by ids');
44
45
  return response.json();
45
46
  }
47
+ async convertExternalContact(larkUserID) {
48
+ const appId = this.config.getAppId();
49
+ if (!appId) throw new Error('Failed to get appId');
50
+ const response = await fetch(this.config.convertExternalContactUrl(appId), {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json'
54
+ },
55
+ body: JSON.stringify({
56
+ larkUserID
57
+ }),
58
+ credentials: 'include'
59
+ });
60
+ if (!response.ok) throw new Error('Failed to convert external contact');
61
+ const data = await response.json();
62
+ if (!data?.data?.userInfo?.userID) throw new Error('Invalid response from convert external contact');
63
+ return data;
64
+ }
46
65
  }
47
66
  export { UserService };
@@ -1,4 +1,5 @@
1
1
  export * from './types';
2
2
  export * from './UserService';
3
3
  export * from './DepartmentService';
4
+ export * from './ChatService';
4
5
  export * from './UserProfileService';
@@ -1,4 +1,5 @@
1
1
  export * from "./types.js";
2
2
  export * from "./UserService.js";
3
3
  export * from "./DepartmentService.js";
4
+ export * from "./ChatService.js";
4
5
  export * from "./UserProfileService.js";
@@ -15,6 +15,7 @@ export type UserInfo = {
15
15
  userType: '_employee' | '_externalUser' | '_anonymousUser';
16
16
  department: DepartmentBasic;
17
17
  email?: string;
18
+ tenantName?: string;
18
19
  };
19
20
  export type DepartmentInfo = {
20
21
  departmentID: string;
@@ -33,6 +34,7 @@ export type SearchUsersParams = {
33
34
  query?: string;
34
35
  offset?: number;
35
36
  pageSize?: number;
37
+ searchExternalContact?: boolean;
36
38
  };
37
39
  export type SearchUsersResponse = {
38
40
  data: {
@@ -41,6 +43,14 @@ export type SearchUsersResponse = {
41
43
  };
42
44
  status_code: string;
43
45
  };
46
+ export type ConvertExternalContactResponse = {
47
+ data: {
48
+ userInfo: {
49
+ tenantID: number;
50
+ userID: number;
51
+ };
52
+ };
53
+ };
44
54
  export type BatchGetUsersResponse = {
45
55
  data: {
46
56
  userInfoMap: Record<string, UserInfo & SearchAvatar>;
@@ -62,6 +72,40 @@ export type SearchDepartmentsResponse = {
62
72
  };
63
73
  status_code: string;
64
74
  };
75
+ export type ChatInfo = {
76
+ /** 群组 ID */
77
+ chatID: string;
78
+ /** 群组名称(国际化文本) */
79
+ name: I18nText;
80
+ /** 头像:URL 或 16 进制 RGB 颜色 */
81
+ avatar: string;
82
+ /** 是否是外部群 */
83
+ isExternal?: boolean;
84
+ /** 群成员数量(不包括机器人),搜索接口返回,批量查询接口不返回 */
85
+ userCount?: number;
86
+ };
87
+ export type SearchChatsParams = {
88
+ query?: string;
89
+ offset?: number;
90
+ pageSize?: number;
91
+ };
92
+ export type SearchChatsResponse = {
93
+ data: {
94
+ result: {
95
+ chatResult?: {
96
+ total: number;
97
+ items: ChatInfo[];
98
+ };
99
+ };
100
+ };
101
+ status_code: string;
102
+ };
103
+ export type BatchGetChatsResponse = {
104
+ data: {
105
+ chatInfoMap: Record<string, ChatInfo>;
106
+ };
107
+ status_code: string;
108
+ };
65
109
  export type UserProfileAccountStatus = 0 | 1 | 2 | 3 | 4;
66
110
  export type SimpleUserProfileInfo = {
67
111
  name?: string;
@@ -4,6 +4,92 @@ import { logger } from "../apis/logger.js";
4
4
  import { getStacktrace } from "../logger/selected-logs.js";
5
5
  import { safeStringify } from "./safeStringify.js";
6
6
  import { slardar } from "@lark-apaas/internal-slardar";
7
+ import { normalizeBasePath } from "./utils.js";
8
+ const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
9
+ function stripBasePath(urlPath) {
10
+ const base = normalizeBasePath(process.env.CLIENT_BASE_PATH);
11
+ if (base && urlPath.startsWith(base)) return urlPath.slice(base.length) || '/';
12
+ return urlPath;
13
+ }
14
+ let _pageRoutes = null;
15
+ function getPageRouteDefinitions() {
16
+ if (_pageRoutes) return _pageRoutes;
17
+ try {
18
+ const raw = process.env.__PAGE_ROUTE_DEFINITIONS__;
19
+ if (raw) {
20
+ const parsed = JSON.parse(raw);
21
+ if (Array.isArray(parsed)) {
22
+ _pageRoutes = parsed;
23
+ return _pageRoutes;
24
+ }
25
+ }
26
+ } catch {}
27
+ _pageRoutes = [];
28
+ return _pageRoutes;
29
+ }
30
+ let _apiRoutes = null;
31
+ function getApiRouteDefinitions() {
32
+ if (_apiRoutes) return _apiRoutes;
33
+ try {
34
+ const raw = process.env.__API_ROUTE_DEFINITIONS__;
35
+ if (raw) {
36
+ const parsed = JSON.parse(raw);
37
+ if (Array.isArray(parsed)) {
38
+ _apiRoutes = parsed;
39
+ return _apiRoutes;
40
+ }
41
+ }
42
+ } catch {}
43
+ _apiRoutes = [];
44
+ return _apiRoutes;
45
+ }
46
+ function matchRoute(concretePath, routes) {
47
+ const segments = concretePath.split('/').filter(Boolean);
48
+ for (const route of routes){
49
+ const routeSegments = route.path.split('/').filter(Boolean);
50
+ if (routeSegments.length !== segments.length) continue;
51
+ let match = true;
52
+ for(let i = 0; i < routeSegments.length; i++)if (!routeSegments[i].startsWith(':')) {
53
+ if (routeSegments[i] !== segments[i]) {
54
+ match = false;
55
+ break;
56
+ }
57
+ }
58
+ if (match) return route.path;
59
+ }
60
+ return null;
61
+ }
62
+ function matchApiRoute(method, concretePath) {
63
+ const routes = getApiRouteDefinitions();
64
+ const segments = concretePath.split('/').filter(Boolean);
65
+ for (const route of routes){
66
+ if ('*' !== route.method && route.method !== method) continue;
67
+ const routeSegments = route.path.split('/').filter(Boolean);
68
+ if (routeSegments.length !== segments.length) continue;
69
+ let match = true;
70
+ for(let i = 0; i < routeSegments.length; i++)if (!routeSegments[i].startsWith(':')) {
71
+ if (routeSegments[i] !== segments[i]) {
72
+ match = false;
73
+ break;
74
+ }
75
+ }
76
+ if (match) return route.path;
77
+ }
78
+ return null;
79
+ }
80
+ function getRefererPath() {
81
+ try {
82
+ if ('undefined' == typeof window || !window.location?.pathname) return '/';
83
+ const rawPath = stripBasePath(window.location.pathname);
84
+ return matchRoute(rawPath, getPageRouteDefinitions()) || rawPath;
85
+ } catch {
86
+ return '/';
87
+ }
88
+ }
89
+ function getApiField(method, path) {
90
+ const matched = matchApiRoute(method, path);
91
+ return `${method} ${matched || path}`;
92
+ }
7
93
  const isValidResponse = (resp)=>null != resp && 'object' == typeof resp && 'config' in resp && null !== resp.config && void 0 !== resp.config && 'object' == typeof resp.config && 'status' in resp && 'number' == typeof resp.status && 'data' in resp;
8
94
  async function logResponse(ok, responseOrError) {
9
95
  if (isValidResponse(responseOrError)) {
@@ -139,13 +225,20 @@ function handleSpanEnd(cfg, response, error) {
139
225
  const errorMessage = error?.message || '未知错误';
140
226
  const url = response?.request?.responseURL || errorResponse?.request?.responseURL || cfg.url || "";
141
227
  const method = (cfg.method || 'GET').toUpperCase();
142
- const path = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
228
+ const rawPath = url.split('?')[0].replace(/^https?:\/\/[^/]+/, '') || '/';
229
+ const path = stripBasePath(rawPath);
230
+ const durationMs = startTime ? Date.now() - startTime : void 0;
231
+ const referer_path = getRefererPath();
232
+ const api = getApiField(method, path);
233
+ const type = APP_CLIENT_API_LOG_TYPE;
143
234
  const logData = {
144
235
  method,
145
236
  path,
146
237
  url,
147
- duration_ms: startTime ? Date.now() - startTime : void 0,
148
- status: response ? response.status : errorResponse.status || 0
238
+ duration_ms: durationMs,
239
+ status: response ? response.status : errorResponse.status || 0,
240
+ referer_path,
241
+ type
149
242
  };
150
243
  if (error) logData.error_message = errorMessage;
151
244
  if ('undefined' != typeof navigator) logData.user_agent = navigator.userAgent;
@@ -158,7 +251,19 @@ function handleSpanEnd(cfg, response, error) {
158
251
  const responseData = response?.data || errorResponse?.data;
159
252
  if (responseData) logData.response = responseData;
160
253
  const level = error ? 'ERROR' : 'INFO';
161
- observable.log(level, safeStringify(logData), {}, currentSpan);
254
+ observable.log(level, safeStringify(logData), {
255
+ referer_path,
256
+ api,
257
+ type,
258
+ duration_ms: durationMs
259
+ }, currentSpan);
260
+ if ('function' == typeof currentSpan.setAttributes) currentSpan.setAttributes({
261
+ referer_path,
262
+ api,
263
+ duration_ms: durationMs,
264
+ module: 'app_web',
265
+ source_type: 'platform'
266
+ });
162
267
  'function' == typeof currentSpan.end && currentSpan.end();
163
268
  } catch (e) {
164
269
  console.error('[AxiosTrace] Log span failed:', e);
@@ -240,6 +345,11 @@ function initAxiosConfig(axiosInstance) {
240
345
  const csrfToken = window.csrfToken;
241
346
  if (csrfToken) config.headers['X-Suda-Csrf-Token'] = csrfToken;
242
347
  if ('undefined' != typeof window && window.location?.pathname) config.headers['X-Page-Route'] = window.location.pathname;
348
+ const refererPath = getRefererPath();
349
+ config.headers['Rpc-Persist-Apaas-Observability-Referer-Path'] = refererPath;
350
+ const reqMethod = (config.method || 'GET').toUpperCase();
351
+ const requestPath = stripBasePath((config.url || '').split('?')[0]);
352
+ config.headers['Rpc-Persist-Apaas-Observability-Api'] = getApiField(reqMethod, requestPath);
243
353
  return config;
244
354
  }, (error)=>Promise.reject(error));
245
355
  instance.interceptors.response.use((response)=>response, (error)=>{
@@ -262,7 +372,18 @@ function initAxiosConfig(axiosInstance) {
262
372
  name: 'toolkit_axios_403_downgrade',
263
373
  categories: {
264
374
  url: String(error.config?.url || ''),
265
- method: String(error.config?.method || '')
375
+ method: String(error.config?.method || ''),
376
+ ...'production' !== process.env.NODE_ENV && {
377
+ responseData: (()=>{
378
+ try {
379
+ const data = error.response?.data;
380
+ if (!data) return '';
381
+ return 'string' == typeof data ? data.slice(0, 512) : JSON.stringify(data).slice(0, 512);
382
+ } catch {
383
+ return '';
384
+ }
385
+ })()
386
+ }
266
387
  }
267
388
  });
268
389
  return error.response;
@@ -273,7 +394,19 @@ function initAxiosConfig(axiosInstance) {
273
394
  categories: {
274
395
  url: String(error.config?.url || ''),
275
396
  method: String(error.config?.method || ''),
276
- status: String(error.response?.status || '')
397
+ status: String(error.response?.status || ''),
398
+ ...'production' !== process.env.NODE_ENV && {
399
+ errorMessage: String(error.message || ''),
400
+ responseData: (()=>{
401
+ try {
402
+ const data = error.response?.data;
403
+ if (!data) return '';
404
+ return 'string' == typeof data ? data.slice(0, 512) : JSON.stringify(data).slice(0, 512);
405
+ } catch {
406
+ return '';
407
+ }
408
+ })()
409
+ }
277
410
  }
278
411
  });
279
412
  return Promise.reject(error);
@@ -9,6 +9,12 @@
9
9
  * @see docs/RFC_HMR_API.md
10
10
  */
11
11
  export interface HmrApi {
12
+ /**
13
+ * 注册 HMR 更新前回调(模块替换之前触发)
14
+ * @param callback 回调函数
15
+ * @returns cleanup 函数,用于取消注册
16
+ */
17
+ onBeforeApply?(callback: () => void): () => void;
12
18
  /**
13
19
  * 注册 HMR 成功回调
14
20
  * @param callback 成功回调函数
@@ -24,7 +30,7 @@ export interface HmrApi {
24
30
  }
25
31
  declare global {
26
32
  interface Window {
27
- __VITE_HMR__?: HmrApi;
33
+ __VITE_HMR__?: Required<HmrApi>;
28
34
  }
29
35
  }
30
36
  /**
@@ -12,6 +12,11 @@ function safeStringify(obj) {
12
12
  if (value instanceof Set) return Array.from(value);
13
13
  if (void 0 === value) return 'undefined';
14
14
  if ('symbol' == typeof value) return value.toString();
15
+ if (value instanceof Error) return {
16
+ name: value.name,
17
+ message: value.message,
18
+ stack: value.stack
19
+ };
15
20
  return value;
16
21
  });
17
22
  } catch {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,125 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { mapLogLevel, processLogParams, safeStringify } from "./safeStringify.js";
3
+ describe('safeStringify', ()=>{
4
+ it('should serialize a plain string', ()=>{
5
+ expect(safeStringify('hello')).toBe('"hello"');
6
+ });
7
+ it('should serialize a plain object', ()=>{
8
+ expect(safeStringify({
9
+ a: 1
10
+ })).toBe('{"a":1}');
11
+ });
12
+ it('should handle circular references', ()=>{
13
+ const obj = {
14
+ a: 1
15
+ };
16
+ obj.self = obj;
17
+ expect(safeStringify(obj)).toBe('{"a":1,"self":"[Circular]"}');
18
+ });
19
+ it('should serialize BigInt as string', ()=>{
20
+ expect(safeStringify(BigInt(123))).toBe('"123"');
21
+ });
22
+ it('should serialize Date as ISO string', ()=>{
23
+ const date = new Date('2024-01-01T00:00:00.000Z');
24
+ expect(safeStringify(date)).toBe('"2024-01-01T00:00:00.000Z"');
25
+ });
26
+ it('should serialize Map as object', ()=>{
27
+ const map = new Map([
28
+ [
29
+ 'key',
30
+ 'value'
31
+ ]
32
+ ]);
33
+ expect(safeStringify(map)).toBe('{"key":"value"}');
34
+ });
35
+ it('should serialize Set as array', ()=>{
36
+ const set = new Set([
37
+ 1,
38
+ 2,
39
+ 3
40
+ ]);
41
+ expect(safeStringify(set)).toBe('[1,2,3]');
42
+ });
43
+ it('should serialize undefined as string', ()=>{
44
+ expect(safeStringify({
45
+ a: void 0
46
+ })).toBe('{"a":"undefined"}');
47
+ });
48
+ it('should serialize Symbol as string', ()=>{
49
+ expect(safeStringify({
50
+ s: Symbol('test')
51
+ })).toBe('{"s":"Symbol(test)"}');
52
+ });
53
+ it('should serialize Error with name, message and stack', ()=>{
54
+ const err = new Error('something went wrong');
55
+ const result = JSON.parse(safeStringify(err));
56
+ expect(result.name).toBe('Error');
57
+ expect(result.message).toBe('something went wrong');
58
+ expect(result.stack).toContain('something went wrong');
59
+ });
60
+ it('should serialize Error subclass with correct name', ()=>{
61
+ const err = new TypeError('bad type');
62
+ const result = JSON.parse(safeStringify(err));
63
+ expect(result.name).toBe('TypeError');
64
+ expect(result.message).toBe('bad type');
65
+ });
66
+ it('should serialize Error nested in object', ()=>{
67
+ const err = new Error('inner error');
68
+ const result = JSON.parse(safeStringify({
69
+ err
70
+ }));
71
+ expect(result.err.name).toBe('Error');
72
+ expect(result.err.message).toBe('inner error');
73
+ });
74
+ it('should return empty string on unexpected failure', ()=>{
75
+ const bad = {
76
+ toJSON () {
77
+ throw new Error('fail');
78
+ }
79
+ };
80
+ expect(safeStringify(bad)).toBe('');
81
+ });
82
+ });
83
+ describe('processLogParams', ()=>{
84
+ it('should serialize single argument directly', ()=>{
85
+ expect(processLogParams([
86
+ 'hello'
87
+ ])).toBe('"hello"');
88
+ });
89
+ it('should serialize single object argument', ()=>{
90
+ expect(processLogParams([
91
+ {
92
+ a: 1
93
+ }
94
+ ])).toBe('{"a":1}');
95
+ });
96
+ it('should serialize multiple arguments as indexed object', ()=>{
97
+ const result = JSON.parse(processLogParams([
98
+ 'msg',
99
+ {
100
+ key: 'val'
101
+ }
102
+ ]));
103
+ expect(result['0']).toBe('msg');
104
+ expect(result['1']).toEqual({
105
+ key: 'val'
106
+ });
107
+ });
108
+ });
109
+ describe('mapLogLevel', ()=>{
110
+ it('should map error to ERROR', ()=>{
111
+ expect(mapLogLevel('error')).toBe('ERROR');
112
+ });
113
+ it('should map info to INFO', ()=>{
114
+ expect(mapLogLevel('info')).toBe('INFO');
115
+ });
116
+ it('should map success to INFO', ()=>{
117
+ expect(mapLogLevel('success')).toBe('INFO');
118
+ });
119
+ it('should map warn to WARN', ()=>{
120
+ expect(mapLogLevel('warn')).toBe('WARN');
121
+ });
122
+ it('should default unknown level to INFO', ()=>{
123
+ expect(mapLogLevel('debug')).toBe('INFO');
124
+ });
125
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.28-alpha.67",
3
+ "version": "1.2.28-alpha.68",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -98,13 +98,13 @@
98
98
  "dependencies": {
99
99
  "@ant-design/colors": "^7.2.1",
100
100
  "@ant-design/cssinjs": "^1.24.0",
101
- "@data-loom/js": "0.4.9",
102
- "@lark-apaas/aily-web-sdk": "0.0.2-alpha.18",
103
- "@lark-apaas/auth-sdk": "^0.1.2",
101
+ "@data-loom/js": "0.4.13",
102
+ "@lark-apaas/aily-web-sdk": "^0.0.8",
103
+ "@lark-apaas/auth-sdk": "^0.1.3",
104
104
  "@lark-apaas/client-capability": "^0.1.6",
105
105
  "@lark-apaas/internal-slardar": "^0.0.3",
106
- "@lark-apaas/miaoda-inspector": "^1.0.20",
107
- "@lark-apaas/observable-web": "^1.0.4",
106
+ "@lark-apaas/miaoda-inspector": "^1.0.23",
107
+ "@lark-apaas/observable-web": "1.0.2-alpha.11",
108
108
  "@radix-ui/react-avatar": "^1.1.10",
109
109
  "@radix-ui/react-popover": "^1.1.15",
110
110
  "@radix-ui/react-slot": "^1.2.3",