mobx-lark 2.9.0 → 2.10.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,5 +1,5 @@
1
1
  import { BaseModel, RESTClient } from 'mobx-restful';
2
- import { BankCardEntity, Contract, Resume, TaxiInvoice, TrainInvoice, VatInvoice, VehicleInvoice } from './type';
2
+ import { BankCardEntity, BusinessCard, BusinessLicense, Contract, IDCard, Resume, TaxiInvoice, TrainInvoice, VatInvoice, VehicleInvoice } from './type';
3
3
  export * from './type';
4
4
  export declare abstract class DocumentAIModel extends BaseModel {
5
5
  baseURI: string;
@@ -36,6 +36,18 @@ export declare abstract class DocumentAIModel extends BaseModel {
36
36
  * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/bank_card/recognize}
37
37
  */
38
38
  recognizeBankCard(file: File): Promise<BankCardEntity[]>;
39
+ /**
40
+ * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/id_card/recognize}
41
+ */
42
+ recognizeIDCard(file: File): Promise<IDCard>;
43
+ /**
44
+ * @see {@link https://open.feishu.cn/document/server-docs/ai/document_ai-v1/business_card/recognize}
45
+ */
46
+ recognizeBusinessCard(file: File): Promise<BusinessCard[]>;
47
+ /**
48
+ * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/business_license/recognize}
49
+ */
50
+ recognizeBusinessLicense(file: File): Promise<BusinessLicense>;
39
51
  /**
40
52
  * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/resume/parse}
41
53
  */
@@ -22,6 +22,33 @@ export interface BankCardEntity {
22
22
  type: 'card_number' | 'date_of_expiry';
23
23
  value: string;
24
24
  }
25
+ export interface IDCardEntity {
26
+ type: `identity_${'code' | 'name'}` | 'birth' | 'gender' | 'race' | 'address' | 'issued_by' | `valid_date_${'start' | 'end'}`;
27
+ value: string;
28
+ }
29
+ export declare enum IDCardSide {
30
+ Cover = 0,
31
+ Profile = 1
32
+ }
33
+ export interface IDCard {
34
+ entities: IDCardEntity[];
35
+ side: IDCardSide;
36
+ corners: number[];
37
+ }
38
+ export interface BusinessCardEntity {
39
+ type: `${'contact' | 'company'}_names` | 'departments' | 'job_titles' | 'emails' | 'websites' | 'addresses' | `${'mobile' | 'work' | 'other'}_phones` | 'faxes';
40
+ value: string;
41
+ }
42
+ export interface BusinessCard {
43
+ entities: BusinessCardEntity[];
44
+ }
45
+ export interface BusinessLicenseEntity {
46
+ type: 'certificate_type' | 'unified_social_credit_code' | `company_${'name' | 'type'}` | 'domicile' | 'legal_representative' | 'registered_capital' | `established_${'time' | 'date'}` | 'business_scope' | 'approval_date' | 'website';
47
+ value: string;
48
+ }
49
+ export interface BusinessLicense {
50
+ entities: BusinessLicenseEntity[];
51
+ }
25
52
  export type ResumePeriod = Record<`${'start' | 'end'}_${'date' | 'time'}`, string>;
26
53
  export declare enum EducationQualification {
27
54
  PrimarySchool = 1,
@@ -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, DriveFileType, TransferOwner, TransferOption } from './type';
4
+ import { CopiedFile, DriveFile, DriveFileType, PublicFileType, PublicPermission, PublicPermissionPatch, TransferOption, TransferOwner } from './type';
5
5
  export * from './type';
6
6
  export declare abstract class DriveFileModel extends BaseListModel<DriveFile> {
7
7
  baseURI: string;
@@ -29,6 +29,14 @@ 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-public/patch-2}
34
+ */
35
+ updatePublicPermission(type: PublicFileType, token: string, permission: PublicPermissionPatch): Promise<PublicPermission>;
36
+ /**
37
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/permission-public-password/create}
38
+ */
39
+ createPublicPassword(type: PublicFileType, token: string): Promise<string>;
32
40
  /**
33
41
  * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-member/transfer_owner}
34
42
  */
@@ -2,6 +2,31 @@ import { LarkDocumentType } from '../../type';
2
2
  export type DriveFile = Record<`doc_${'token' | 'type'}` | 'title' | 'owner_id' | 'create_time' | `latest_modify_${'user' | 'time'}` | 'url' | 'sec_label_name', string>;
3
3
  export type CopiedFile = Record<'type' | `${'parent_' | ''}token` | 'name' | 'url', string>;
4
4
  export type DriveFileType = LarkDocumentType | 'minutes' | 'folder' | 'wiki';
5
+ export type PublicFileType = Exclude<DriveFileType, 'folder'>;
6
+ type PublicEditableLevel = 'view' | 'edit';
7
+ type PublicLinkAccessLevel = 'readable' | 'editable';
8
+ type PublicLinkShareScope = `${'' | 'partner_'}tenant` | 'anyone';
9
+ export type PublicCommentEntity = `anyone_can_${PublicEditableLevel}`;
10
+ export type PublicPermissionLevel = PublicCommentEntity | 'only_full_access';
11
+ export type PublicShareEntity = 'anyone' | 'same_tenant';
12
+ export type PublicCollaboratorEntity = `collaborator_can_${PublicEditableLevel}` | 'collaborator_full_access';
13
+ export type PublicExternalAccessEntity = 'open' | 'closed' | 'allow_share_partner_tenant';
14
+ export type PublicLinkShareEntity = `${PublicLinkShareScope}_${PublicLinkAccessLevel}` | 'closed';
15
+ export interface PublicPermission {
16
+ external_access_entity: PublicExternalAccessEntity;
17
+ security_entity: PublicPermissionLevel;
18
+ comment_entity: PublicCommentEntity;
19
+ share_entity: PublicShareEntity;
20
+ manage_collaborator_entity: PublicCollaboratorEntity;
21
+ link_share_entity: PublicLinkShareEntity;
22
+ copy_entity: PublicPermissionLevel;
23
+ lock_switch: boolean;
24
+ }
25
+ export type PublicPermissionPatch = Partial<Omit<PublicPermission, 'lock_switch'>>;
26
+ export interface PublishedFile {
27
+ permission: PublicPermission;
28
+ password?: string;
29
+ }
5
30
  export interface TransferOwner {
6
31
  member_type: 'email' | 'userid' | 'openid';
7
32
  member_id: string;
@@ -12,3 +37,4 @@ export interface TransferOption {
12
37
  stay_put?: boolean;
13
38
  old_owner_perm?: 'view' | 'edit' | 'full_access';
14
39
  }
40
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mobx-lark",
3
- "version": "2.9.0",
3
+ "version": "2.10.0",
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.",
@@ -48,7 +48,7 @@
48
48
  "dotenv": "^17.4.2",
49
49
  "fs-extra": "^11.3.5",
50
50
  "husky": "^9.1.7",
51
- "lint-staged": "^17.0.7",
51
+ "lint-staged": "^17.0.8",
52
52
  "parcel": "~2.16.4",
53
53
  "prettier": "^3.8.4",
54
54
  "react": "^19.2.7",
package/src/Lark.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  DocumentAIModel,
10
10
  DocumentModel,
11
11
  DriveFileModel,
12
+ PublicFileType,
13
+ PublishedFile,
12
14
  TableFormView,
13
15
  UserIdType,
14
16
  WikiNode,
@@ -291,6 +293,31 @@ export class LarkApp implements LarkAppOption {
291
293
  return this.documentStore.getOneContent(doc_token, 'markdown');
292
294
  }
293
295
 
296
+ /**
297
+ * @see {@link DriveFileModel#updatePublicPermission}
298
+ * @see {@link DriveFileModel#createPublicPassword}
299
+ */
300
+ async publishFile(URI: string, enablePassword = false, editable = false) {
301
+ await this.getAccessToken();
302
+
303
+ const [[pathType, token]] = DriveFileModel.parseURI(URI);
304
+ const type: PublicFileType =
305
+ pathType === 'wiki' ? pathType : getLarkDocumentType(pathType as LarkDocumentPathType);
306
+
307
+ const permission = await this.driveFileStore.updatePublicPermission(type, token, {
308
+ external_access_entity: 'open',
309
+ link_share_entity: editable ? 'anyone_editable' : 'anyone_readable',
310
+ copy_entity: 'anyone_can_view',
311
+ security_entity: 'anyone_can_view',
312
+ comment_entity: 'anyone_can_view'
313
+ }),
314
+ password = enablePassword
315
+ ? await this.driveFileStore.createPublicPassword(type, token)
316
+ : undefined;
317
+
318
+ return { permission, password } as PublishedFile;
319
+ }
320
+
294
321
  async getBiTableSchema(appId: string): Promise<BiTableSchema> {
295
322
  const { client } = this;
296
323
 
@@ -4,7 +4,10 @@ import { BaseModel, RESTClient, toggle } from 'mobx-restful';
4
4
  import { LarkData } from '../../type';
5
5
  import {
6
6
  BankCardEntity,
7
+ BusinessCard,
8
+ BusinessLicense,
7
9
  Contract,
10
+ IDCard,
8
11
  Resume,
9
12
  TaxiInvoice,
10
13
  TrainInvoice,
@@ -95,6 +98,46 @@ export abstract class DocumentAIModel extends BaseModel {
95
98
  return body!.data!.bank_card.entities;
96
99
  }
97
100
 
101
+ /**
102
+ * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/id_card/recognize}
103
+ */
104
+ @toggle('uploading')
105
+ async recognizeIDCard(file: File) {
106
+ type IDCardTypo = Omit<IDCard, 'corners'> & { conners: number[] };
107
+
108
+ const { body } = await this.client.post<LarkData<{ id_card: IDCardTypo }>>(
109
+ `${this.baseURI}/id_card/recognize`,
110
+ makeFormData({ file })
111
+ );
112
+ const { conners: corners, ...idCard } = body!.data!.id_card;
113
+
114
+ return { ...idCard, corners } as IDCard;
115
+ }
116
+
117
+ /**
118
+ * @see {@link https://open.feishu.cn/document/server-docs/ai/document_ai-v1/business_card/recognize}
119
+ */
120
+ @toggle('uploading')
121
+ async recognizeBusinessCard(file: File) {
122
+ const { body } = await this.client.post<LarkData<{ business_cards: BusinessCard[] }>>(
123
+ `${this.baseURI}/business_card/recognize`,
124
+ makeFormData({ file })
125
+ );
126
+ return body!.data!.business_cards;
127
+ }
128
+
129
+ /**
130
+ * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/business_license/recognize}
131
+ */
132
+ @toggle('uploading')
133
+ async recognizeBusinessLicense(file: File) {
134
+ const { body } = await this.client.post<LarkData<{ business_license: BusinessLicense }>>(
135
+ `${this.baseURI}/business_license/recognize`,
136
+ makeFormData({ file })
137
+ );
138
+ return body!.data!.business_license;
139
+ }
140
+
98
141
  /**
99
142
  * @see {@link https://open.feishu.cn/document/ai/document_ai-v1/resume/parse}
100
143
  */
@@ -75,6 +75,65 @@ export interface BankCardEntity {
75
75
  value: string;
76
76
  }
77
77
 
78
+ export interface IDCardEntity {
79
+ type:
80
+ | `identity_${'code' | 'name'}`
81
+ | 'birth'
82
+ | 'gender'
83
+ | 'race'
84
+ | 'address'
85
+ | 'issued_by'
86
+ | `valid_date_${'start' | 'end'}`;
87
+ value: string;
88
+ }
89
+
90
+ export enum IDCardSide {
91
+ Cover = 0,
92
+ Profile = 1
93
+ }
94
+
95
+ export interface IDCard {
96
+ entities: IDCardEntity[];
97
+ side: IDCardSide;
98
+ corners: number[];
99
+ }
100
+
101
+ export interface BusinessCardEntity {
102
+ type:
103
+ | `${'contact' | 'company'}_names`
104
+ | 'departments'
105
+ | 'job_titles'
106
+ | 'emails'
107
+ | 'websites'
108
+ | 'addresses'
109
+ | `${'mobile' | 'work' | 'other'}_phones`
110
+ | 'faxes';
111
+ value: string;
112
+ }
113
+
114
+ export interface BusinessCard {
115
+ entities: BusinessCardEntity[];
116
+ }
117
+
118
+ export interface BusinessLicenseEntity {
119
+ type:
120
+ | 'certificate_type'
121
+ | 'unified_social_credit_code'
122
+ | `company_${'name' | 'type'}`
123
+ | 'domicile'
124
+ | 'legal_representative'
125
+ | 'registered_capital'
126
+ | `established_${'time' | 'date'}` // 成立日期、营业期限
127
+ | 'business_scope'
128
+ | 'approval_date'
129
+ | 'website';
130
+ value: string;
131
+ }
132
+
133
+ export interface BusinessLicense {
134
+ entities: BusinessLicenseEntity[];
135
+ }
136
+
78
137
  export type ResumePeriod = Record<`${'start' | 'end'}_${'date' | 'time'}`, string>;
79
138
 
80
139
  export enum EducationQualification {
@@ -4,7 +4,16 @@ 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, DriveFileType, TransferOwner, TransferOption } from './type';
7
+ import {
8
+ CopiedFile,
9
+ DriveFile,
10
+ DriveFileType,
11
+ PublicFileType,
12
+ PublicPermission,
13
+ PublicPermissionPatch,
14
+ TransferOption,
15
+ TransferOwner
16
+ } from './type';
8
17
 
9
18
  export * from './type';
10
19
 
@@ -106,6 +115,33 @@ export abstract class DriveFileModel extends BaseListModel<DriveFile> {
106
115
  return body!.data!.file;
107
116
  }
108
117
 
118
+ /**
119
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/patch-2}
120
+ */
121
+ @toggle('uploading')
122
+ async updatePublicPermission(
123
+ type: PublicFileType,
124
+ token: string,
125
+ permission: PublicPermissionPatch
126
+ ) {
127
+ const { body } = await this.client.patch<LarkData<{ permission_public: PublicPermission }>>(
128
+ `${this.baseURI}/../v2/permissions/${token}/public?${buildURLData({ type })}`,
129
+ permission
130
+ );
131
+ return body!.data!.permission_public;
132
+ }
133
+
134
+ /**
135
+ * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-public/permission-public-password/create}
136
+ */
137
+ @toggle('uploading')
138
+ async createPublicPassword(type: PublicFileType, token: string) {
139
+ const { body } = await this.client.post<LarkData<{ password: string }>>(
140
+ `${this.baseURI}/permissions/${token}/public/password?${buildURLData({ type })}`
141
+ );
142
+ return body!.data!.password;
143
+ }
144
+
109
145
  /**
110
146
  * @see {@link https://open.feishu.cn/document/server-docs/docs/permission/permission-member/transfer_owner}
111
147
  */
@@ -14,6 +14,38 @@ export type DriveFile = Record<
14
14
  export type CopiedFile = Record<'type' | `${'parent_' | ''}token` | 'name' | 'url', string>;
15
15
 
16
16
  export type DriveFileType = LarkDocumentType | 'minutes' | 'folder' | 'wiki';
17
+ export type PublicFileType = Exclude<DriveFileType, 'folder'>;
18
+
19
+ type PublicEditableLevel = 'view' | 'edit';
20
+ type PublicLinkAccessLevel = 'readable' | 'editable';
21
+ type PublicLinkShareScope = `${'' | 'partner_'}tenant` | 'anyone';
22
+
23
+ export type PublicCommentEntity = `anyone_can_${PublicEditableLevel}`;
24
+ export type PublicPermissionLevel = PublicCommentEntity | 'only_full_access';
25
+ export type PublicShareEntity = 'anyone' | 'same_tenant';
26
+ export type PublicCollaboratorEntity =
27
+ | `collaborator_can_${PublicEditableLevel}`
28
+ | 'collaborator_full_access';
29
+ export type PublicExternalAccessEntity = 'open' | 'closed' | 'allow_share_partner_tenant';
30
+ export type PublicLinkShareEntity = `${PublicLinkShareScope}_${PublicLinkAccessLevel}` | 'closed';
31
+
32
+ export interface PublicPermission {
33
+ external_access_entity: PublicExternalAccessEntity;
34
+ security_entity: PublicPermissionLevel;
35
+ comment_entity: PublicCommentEntity;
36
+ share_entity: PublicShareEntity;
37
+ manage_collaborator_entity: PublicCollaboratorEntity;
38
+ link_share_entity: PublicLinkShareEntity;
39
+ copy_entity: PublicPermissionLevel;
40
+ lock_switch: boolean;
41
+ }
42
+
43
+ export type PublicPermissionPatch = Partial<Omit<PublicPermission, 'lock_switch'>>;
44
+
45
+ export interface PublishedFile {
46
+ permission: PublicPermission;
47
+ password?: string;
48
+ }
17
49
 
18
50
  export interface TransferOwner {
19
51
  member_type: 'email' | 'userid' | 'openid';