@lark-apaas/client-toolkit 1.2.56-alpha.0 → 1.2.56-beta.0

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.
@@ -1,10 +1,11 @@
1
1
  import { IUserProfile } from '../apis/udt-types';
2
2
  /**
3
3
  * useCurrentUserProfile 的返回类型。
4
- * client-toolkit-lite 完全一致:所有字段保证非 undefined(未加载时为空字符串),
5
- * 使用 `if (!userInfo.user_id)` 判断是否已加载完成。
4
+ * 初始状态为空对象 `{}`(所有字段均为 undefined),异步获取用户信息后字段才会被填充。
5
+ * 使用时必须通过可选链或空值合并进行安全访问,如 `userInfo?.user_id`。
6
+ * 判断是否已加载完成应使用 `if (!userInfo?.user_id)` 而非 `if (!userInfo)`(因为空对象是 truthy)。
6
7
  */
7
- export interface ICompatibilityUserProfile extends IUserProfile {
8
+ export type ICompatibilityUserProfile = Partial<IUserProfile & {
8
9
  /**
9
10
  * @deprecated please use `name`
10
11
  */
@@ -13,5 +14,14 @@ export interface ICompatibilityUserProfile extends IUserProfile {
13
14
  * @deprecated please use `avatar`
14
15
  */
15
16
  userAvatar: string;
16
- }
17
- 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
+ }>;
@@ -25,14 +25,9 @@ function fetchLarkUserId() {
25
25
  function getCompatibilityUserProfile() {
26
26
  const userInfo = getCurrentUserProfile();
27
27
  return {
28
- user_id: userInfo.user_id ?? '',
29
- email: userInfo.email ?? '',
30
- name: userInfo.name ?? '',
31
- avatar: userInfo.avatar ?? '',
32
- status: userInfo.status,
33
- lark_user_id: userInfo.lark_user_id,
34
- userName: userInfo.name ?? '',
35
- userAvatar: userInfo.avatar ?? ''
28
+ ...userInfo,
29
+ userName: userInfo.name,
30
+ userAvatar: userInfo.avatar
36
31
  };
37
32
  }
38
33
  const useCurrentUserProfile = ()=>{
@@ -43,15 +38,14 @@ const useCurrentUserProfile = ()=>{
43
38
  const result = await authClient.session.getUserInfo();
44
39
  if (cancelled) return;
45
40
  const info = result?.data?.user_info;
46
- const userName = getNameFromArray(info?.name) ?? '';
47
- const avatar = info?.avatar?.image?.large ?? '';
41
+ const userName = getNameFromArray(info?.name);
48
42
  const newUserInfo = {
49
- user_id: info?.user_id?.toString() ?? '',
50
- email: info?.email ?? '',
43
+ user_id: info?.user_id?.toString(),
44
+ email: info?.email,
51
45
  name: userName,
52
- avatar,
46
+ avatar: info?.avatar?.image?.large,
53
47
  userName,
54
- userAvatar: avatar
48
+ userAvatar: info?.avatar?.image?.large
55
49
  };
56
50
  const larkUserId = await fetchLarkUserId();
57
51
  if (larkUserId) newUserInfo.lark_user_id = larkUserId;
@@ -1,4 +1,4 @@
1
- declare const createDataLoomClient: () => import("@lark-apaas/dataloom").DataloomClient;
1
+ declare const createDataLoomClient: (url?: string, pat?: string) => import("@lark-apaas/dataloom").DataloomClient;
2
2
  /** 获取dataloom实例 */
3
3
  export declare function getDataloom(): Promise<ReturnType<typeof createDataLoomClient>>;
4
4
  export {};
@@ -1,10 +1,14 @@
1
+ import { splitWorkspaceUrl } from "../utils/url.js";
1
2
  import { createClient } from "@lark-apaas/dataloom";
2
3
  import { authClient } from "@lark-apaas/auth-sdk";
3
4
  import { getAppId } from "../utils/getAppId.js";
4
- import { getInitialInfo } from "../utils/getInitialInfo.js";
5
- const createDataLoomClient = ()=>{
5
+ import { getAppPublished } from "../utils/getInitialInfo.js";
6
+ const createDataLoomClient = (url, pat)=>{
7
+ const { baseUrl } = url ? splitWorkspaceUrl(url) : {
8
+ baseUrl: ''
9
+ };
6
10
  const appId = getAppId();
7
- return createClient({
11
+ return createClient(baseUrl, pat, {
8
12
  global: {
9
13
  enableDataloomLog: 'production' !== process.env.NODE_ENV,
10
14
  requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
@@ -22,8 +26,10 @@ let pendingPromise = null;
22
26
  function getDataloom() {
23
27
  if (dataloom) return Promise.resolve(dataloom);
24
28
  if (pendingPromise) return pendingPromise;
25
- pendingPromise = getInitialInfo().then(()=>{
26
- dataloom = createDataLoomClient();
29
+ pendingPromise = getAppPublished().then((info)=>{
30
+ const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
31
+ const DATALOOM_PAT = info?.app_runtime_extra?.token;
32
+ dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
27
33
  return dataloom;
28
34
  }).finally(()=>{
29
35
  pendingPromise = null;
@@ -1,10 +1,11 @@
1
1
  import { IUserProfile } from '../apis/udt-types';
2
2
  /**
3
3
  * 获取当前用户信息。
4
- * client-toolkit-lite 一致返回 IUserProfile(非 Partial);
5
- * 调用方需自行处理 window._userInfo 未就绪时空对象的情况。
4
+ * 返回 Partial<IUserProfile>,因为初始值来自 window._userInfo,
5
+ * 该值在运行时始终为空对象 {},所有字段均为 undefined。
6
+ * 异步获取用户信息后才会被填充为完整的 IUserProfile。
6
7
  */
7
- export declare function getCurrentUserProfile(): IUserProfile;
8
+ export declare function getCurrentUserProfile(): Partial<IUserProfile>;
8
9
  /**
9
10
  * @deprecated 请使用 getCurrentUserProfile 代替
10
11
  */
@@ -6,6 +6,15 @@ export type I18nText = {
6
6
  export type DepartmentBasic = {
7
7
  departmentID: string;
8
8
  name: I18nText;
9
+ /** 飞书部门 open id(od- 开头),调飞书部门能力时使用 */
10
+ openDepartmentID?: string;
11
+ };
12
+ /** 直属上级 / 虚线上级,仅在 needFullFields 时返回 */
13
+ export type LeaderUser = {
14
+ /** 飞书企业内 user_id */
15
+ employeeID?: string;
16
+ /** 妙搭用户全局唯一 ID */
17
+ miaodaUserID?: string;
9
18
  };
10
19
  export type UserInfo = {
11
20
  userID: string;
@@ -16,11 +25,32 @@ export type UserInfo = {
16
25
  department: DepartmentBasic;
17
26
  email?: string;
18
27
  tenantName?: string;
28
+ /** 妙搭用户全局唯一 ID(来源同 userID,向前兼容别名) */
29
+ miaodaUserID?: string;
30
+ /** 飞书企业内 user_id,仅内部飞书用户;调飞书开放平台能力时使用 */
31
+ employeeID?: string;
32
+ /** 飞书用户全局唯一 ID(来源同 larkUserID 别名) */
33
+ larkID?: string;
34
+ nickname?: string;
35
+ mobile?: string;
36
+ gender?: number;
37
+ country?: string;
38
+ workStation?: string;
39
+ employeeNo?: string;
40
+ city?: string;
41
+ jobTitle?: string;
42
+ employeeType?: number;
43
+ /** 直属上级 */
44
+ leader?: LeaderUser;
45
+ /** 虚线上级 */
46
+ dottedLineLeaders?: LeaderUser[];
19
47
  };
20
48
  export type DepartmentInfo = {
21
49
  departmentID: string;
22
50
  larkDepartmentID: string;
23
51
  name: I18nText;
52
+ /** 飞书部门 open id(od- 开头) */
53
+ openDepartmentID?: string;
24
54
  };
25
55
  export type AccountType = 'apaas' | 'lark';
26
56
  export type SearchAvatar = {
@@ -35,6 +65,8 @@ export type SearchUsersParams = {
35
65
  offset?: number;
36
66
  pageSize?: number;
37
67
  searchExternalContact?: boolean;
68
+ /** 是否返回 full 字段(手机号/职位/上级等),默认 false */
69
+ needFullFields?: boolean;
38
70
  };
39
71
  export type SearchUsersResponse = {
40
72
  data: {
@@ -75,6 +107,8 @@ export type SearchDepartmentsResponse = {
75
107
  export type ChatInfo = {
76
108
  /** 群组 ID */
77
109
  chatID: string;
110
+ /** 飞书群组 open id(oc_ 开头),调飞书群组能力时使用 */
111
+ openChatID?: string;
78
112
  /** 群组名称(国际化文本) */
79
113
  name: I18nText;
80
114
  /** 头像:URL 或 16 进制 RGB 颜色 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.56-alpha.0",
3
+ "version": "1.2.56-beta.0",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -102,7 +102,7 @@
102
102
  "@lark-apaas/aily-web-sdk": "^0.0.11",
103
103
  "@lark-apaas/auth-sdk": "^0.1.5",
104
104
  "@lark-apaas/client-capability": "^0.1.7",
105
- "@lark-apaas/dataloom": "0.1.4-alpha.10",
105
+ "@lark-apaas/dataloom": "^0.1.3",
106
106
  "@lark-apaas/internal-slardar": "^0.0.3",
107
107
  "@lark-apaas/miaoda-inspector": "^1.0.23",
108
108
  "@lark-apaas/observable-web": "^1.0.6",
@@ -1 +0,0 @@
1
- export {};
@@ -1,83 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
- import { getDataloom } from "../dataloom.js";
3
- const { getInitialInfoMock, getAppPublishedMock, getAppIdMock, createClientMock, authUserMock, authSessionMock } = vi.hoisted(()=>({
4
- getInitialInfoMock: vi.fn(),
5
- getAppPublishedMock: vi.fn(),
6
- getAppIdMock: vi.fn(),
7
- createClientMock: vi.fn(),
8
- authUserMock: {},
9
- authSessionMock: {}
10
- }));
11
- vi.mock('../../utils/getInitialInfo', ()=>({
12
- getInitialInfo: getInitialInfoMock,
13
- getAppPublished: getAppPublishedMock
14
- }));
15
- vi.mock('../../utils/getAppId', ()=>({
16
- getAppId: getAppIdMock
17
- }));
18
- vi.mock('@lark-apaas/dataloom', ()=>({
19
- createClient: createClientMock
20
- }));
21
- vi.mock('@lark-apaas/auth-sdk', ()=>({
22
- authClient: {
23
- user: authUserMock,
24
- session: authSessionMock
25
- }
26
- }));
27
- beforeEach(()=>{
28
- getInitialInfoMock.mockReset();
29
- getAppPublishedMock.mockReset();
30
- getAppIdMock.mockReset();
31
- createClientMock.mockReset();
32
- });
33
- afterEach(()=>{
34
- vi.restoreAllMocks();
35
- });
36
- describe('getDataloom', ()=>{
37
- it('返回-createClient实例-改用getInitialInfo-新签名不取token/url-appId注入-并发去重-缓存复用', async ()=>{
38
- getAppIdMock.mockReturnValue('app-1');
39
- getInitialInfoMock.mockResolvedValue({
40
- app_runtime_extra: {
41
- token: 'pat',
42
- url: 'https://x'
43
- }
44
- });
45
- const client = {
46
- __id: 'client-1'
47
- };
48
- createClientMock.mockReturnValue(client);
49
- const p1 = getDataloom();
50
- const p2 = getDataloom();
51
- expect(p1).toBe(p2);
52
- const [c1, c2] = await Promise.all([
53
- p1,
54
- p2
55
- ]);
56
- expect(c1).toBe(client);
57
- expect(c2).toBe(client);
58
- expect(getInitialInfoMock).toHaveBeenCalledTimes(1);
59
- expect(getAppPublishedMock).not.toHaveBeenCalled();
60
- expect(createClientMock).toHaveBeenCalledTimes(1);
61
- const args = createClientMock.mock.calls[0];
62
- expect(args).toHaveLength(1);
63
- const options = args[0];
64
- expect(typeof options).toBe('object');
65
- expect(options).not.toBe('https://x');
66
- expect(options).not.toBe('pat');
67
- expect(options.global).toBeDefined();
68
- expect(options.global).not.toHaveProperty('url');
69
- expect(options.global).not.toHaveProperty('key');
70
- expect(options.global?.appId).toBe('app-1');
71
- expect(options.global?.accountServices).toEqual({
72
- user: authUserMock,
73
- session: authSessionMock
74
- });
75
- const cached1 = await getDataloom();
76
- const cached2 = await getDataloom();
77
- expect(cached1).toBe(client);
78
- expect(cached2).toBe(client);
79
- expect(cached1).toBe(cached2);
80
- expect(getInitialInfoMock).toHaveBeenCalledTimes(1);
81
- expect(createClientMock).toHaveBeenCalledTimes(1);
82
- });
83
- });