mobx-lark 2.6.1 → 2.6.3

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.
@@ -16,6 +16,12 @@ export interface TableFormView extends Record<'name' | 'description' | 'shared_u
16
16
  export type LarkFormData = LarkData<{
17
17
  form: TableFormView;
18
18
  }>;
19
+ export interface BiTableSchema {
20
+ tables: BITable[];
21
+ tableIdMap: Record<string, string>;
22
+ forms: Record<string, TableFormView[]>;
23
+ formLinkMap: Record<string, Record<string, string>>;
24
+ }
19
25
  export interface TableCellText {
20
26
  type: 'text';
21
27
  text: string;
@@ -1,7 +1,7 @@
1
1
  import { BaseListModel, RESTClient } from 'mobx-restful';
2
2
  import { LarkDocumentType, UploadTargetType } from '../../type';
3
3
  import { UserIdType } from '../User/type';
4
- import { CopiedFile, DriveFile } from './type';
4
+ import { CopiedFile, DriveFile, DriveFileType, TransferOwner, TransferOption } from './type';
5
5
  export * from './type';
6
6
  export declare abstract class DriveFileModel extends BaseListModel<DriveFile> {
7
7
  baseURI: string;
@@ -29,4 +29,8 @@ export declare abstract class DriveFileModel extends BaseListModel<DriveFile> {
29
29
  * @see {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/copy}
30
30
  */
31
31
  copyOne(type: LarkDocumentType, file_token: string, name?: string, folder_token?: string, user_id_type?: UserIdType): Promise<CopiedFile>;
32
+ /**
33
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-member/transfer_owner}
34
+ */
35
+ transferOwner(type: DriveFileType, token: string, newOwner: TransferOwner, option?: TransferOption): Promise<void>;
32
36
  }
@@ -1,2 +1,14 @@
1
+ import { LarkDocumentType } from '../../type';
1
2
  export type DriveFile = Record<`doc_${'token' | 'type'}` | 'title' | 'owner_id' | 'create_time' | `latest_modify_${'user' | 'time'}` | 'url' | 'sec_label_name', string>;
2
- export type CopiedFile = Record<'token' | 'type' | 'name' | 'parent_token' | 'url', string>;
3
+ export type CopiedFile = Record<'type' | `${'parent_' | ''}token` | 'name' | 'url', string>;
4
+ export type DriveFileType = LarkDocumentType | 'minutes' | 'folder' | 'wiki';
5
+ export interface TransferOwner {
6
+ member_type: 'email' | 'userid' | 'openid';
7
+ member_id: string;
8
+ }
9
+ export interface TransferOption {
10
+ need_notification?: boolean;
11
+ remove_old_owner?: boolean;
12
+ stay_put?: boolean;
13
+ old_owner_perm?: 'view' | 'edit' | 'full_access';
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-lark",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
4
4
  "license": "LGPL-3.0",
5
5
  "author": "shiy2008@gmail.com",
6
6
  "description": "Unofficial TypeScript SDK for FeiShu/Lark API, which is based on MobX-RESTful.",
package/src/Lark.ts CHANGED
@@ -2,9 +2,13 @@ import { Context, HTTPClient } from 'koajax';
2
2
  import { buildURLData, cache, sleep } from 'web-utility';
3
3
 
4
4
  import {
5
+ BiTable,
6
+ BiTableSchema,
7
+ BiTableView,
5
8
  CopiedFile,
6
9
  DocumentModel,
7
10
  DriveFileModel,
11
+ TableFormView,
8
12
  UserIdType,
9
13
  WikiNode,
10
14
  WikiNodeModel
@@ -281,4 +285,29 @@ export class LarkApp implements LarkAppOption {
281
285
 
282
286
  return this.documentStore.getOneContent(doc_token, 'markdown');
283
287
  }
288
+
289
+ async getBiTableSchema(appId: string) {
290
+ const { client } = this;
291
+
292
+ class InternalTableModel extends BiTable() {
293
+ client = client;
294
+ }
295
+ class InternalFormModel extends BiTableView('form') {
296
+ client = client;
297
+ }
298
+ const tables = await new InternalTableModel(appId).getAll(),
299
+ forms: Record<string, TableFormView[]> = {};
300
+
301
+ for (const { name, table_id } of tables)
302
+ forms[name] = await new InternalFormModel(appId, table_id).getAll();
303
+
304
+ const tableIdMap = Object.fromEntries(tables.map(({ name, table_id }) => [name, table_id])),
305
+ formLinkMap = Object.fromEntries(
306
+ Object.entries(forms).map(([name, list]) => [
307
+ name,
308
+ Object.fromEntries(list.map(({ name, shared_url }) => [name, shared_url]))
309
+ ])
310
+ );
311
+ return { tables, tableIdMap, forms, formLinkMap } as BiTableSchema;
312
+ }
284
313
  }
@@ -15,13 +15,21 @@ export interface TableView extends Record<'view_id' | 'view_name', string> {
15
15
  }
16
16
 
17
17
  export interface TableFormView
18
- extends Record<'name' | 'description' | 'shared_url', string>,
18
+ extends
19
+ Record<'name' | 'description' | 'shared_url', string>,
19
20
  Record<'shared' | 'submit_limit_once', boolean> {
20
21
  shared_limit: 'tenant_editable';
21
22
  }
22
23
 
23
24
  export type LarkFormData = LarkData<{ form: TableFormView }>;
24
25
 
26
+ export interface BiTableSchema {
27
+ tables: BITable[];
28
+ tableIdMap: Record<string, string>;
29
+ forms: Record<string, TableFormView[]>;
30
+ formLinkMap: Record<string, Record<string, string>>;
31
+ }
32
+
25
33
  export interface TableCellText {
26
34
  type: 'text';
27
35
  text: string;
@@ -36,14 +44,17 @@ export interface TableCellLink extends Record<'link' | 'text', string> {
36
44
  type: 'url';
37
45
  }
38
46
 
39
- export interface TableCellMedia
40
- extends Record<'file_token' | 'name' | `${'' | 'tmp_'}url`, string> {
47
+ export interface TableCellMedia extends Record<
48
+ 'file_token' | 'name' | `${'' | 'tmp_'}url`,
49
+ string
50
+ > {
41
51
  type: `${string}/${string}`;
42
52
  size: number;
43
53
  }
44
54
 
45
55
  export interface TableCellAttachment
46
- extends Pick<TableCellMedia, 'name' | 'size'>,
56
+ extends
57
+ Pick<TableCellMedia, 'name' | 'size'>,
47
58
  Record<'id' | 'attachmentToken', string>,
48
59
  Record<'height' | 'timeStamp' | 'width', number> {
49
60
  mimeType: TableCellMedia['type'];
@@ -96,8 +107,10 @@ export type TableCellValue =
96
107
 
97
108
  export type TableRecordFields = Record<string, TableCellValue>;
98
109
 
99
- export interface TableRecord<T extends TableRecordFields>
100
- extends Record<'id' | 'record_id', string> {
110
+ export interface TableRecord<T extends TableRecordFields> extends Record<
111
+ 'id' | 'record_id',
112
+ string
113
+ > {
101
114
  created_by: TableCellUser;
102
115
  created_time: number;
103
116
  last_modified_by?: TableCellUser;
@@ -4,7 +4,7 @@ import { buildURLData, splitArray } from 'web-utility';
4
4
 
5
5
  import { LarkData, LarkDocumentPathTypeMap, LarkDocumentType, UploadTargetType } from '../../type';
6
6
  import { UserIdType } from '../User/type';
7
- import { CopiedFile, DriveFile } from './type';
7
+ import { CopiedFile, DriveFile, DriveFileType, TransferOwner, TransferOption } from './type';
8
8
 
9
9
  export * from './type';
10
10
 
@@ -105,4 +105,20 @@ export abstract class DriveFileModel extends BaseListModel<DriveFile> {
105
105
  );
106
106
  return body!.data!.file;
107
107
  }
108
+
109
+ /**
110
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-member/transfer_owner}
111
+ */
112
+ @toggle('uploading')
113
+ async transferOwner(
114
+ type: DriveFileType,
115
+ token: string,
116
+ newOwner: TransferOwner,
117
+ option = {} as TransferOption
118
+ ) {
119
+ await this.client.post<LarkData>(
120
+ `${this.baseURI}/permissions/${token}/members/transfer_owner?${buildURLData({ ...option, type })}`,
121
+ newOwner
122
+ );
123
+ }
108
124
  }
@@ -1,3 +1,5 @@
1
+ import { LarkDocumentType } from '../../type';
2
+
1
3
  export type DriveFile = Record<
2
4
  | `doc_${'token' | 'type'}`
3
5
  | 'title'
@@ -9,4 +11,18 @@ export type DriveFile = Record<
9
11
  string
10
12
  >;
11
13
 
12
- export type CopiedFile = Record<'token' | 'type' | 'name' | 'parent_token' | 'url', string>;
14
+ export type CopiedFile = Record<'type' | `${'parent_' | ''}token` | 'name' | 'url', string>;
15
+
16
+ export type DriveFileType = LarkDocumentType | 'minutes' | 'folder' | 'wiki';
17
+
18
+ export interface TransferOwner {
19
+ member_type: 'email' | 'userid' | 'openid';
20
+ member_id: string;
21
+ }
22
+
23
+ export interface TransferOption {
24
+ need_notification?: boolean;
25
+ remove_old_owner?: boolean;
26
+ stay_put?: boolean;
27
+ old_owner_perm?: 'view' | 'edit' | 'full_access';
28
+ }