@lark-apaas/client-toolkit 1.2.54-alpha.6 → 1.2.54-alpha.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.
@@ -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;
@@ -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.54-alpha.6",
3
+ "version": "1.2.54-alpha.8",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -100,9 +100,9 @@
100
100
  "@ant-design/colors": "^7.2.1",
101
101
  "@ant-design/cssinjs": "^1.24.0",
102
102
  "@lark-apaas/aily-web-sdk": "^0.0.11",
103
- "@lark-apaas/auth-sdk": "^0.1.5",
103
+ "@lark-apaas/auth-sdk": "0.1.6-alpha.0",
104
104
  "@lark-apaas/client-capability": "^0.1.7",
105
- "@lark-apaas/dataloom": "0.1.4-alpha.9",
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
- });