@satorijs/adapter-lark 3.11.8 → 3.12.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.
Files changed (68) hide show
  1. package/lib/bot.d.ts +5 -5
  2. package/lib/http.d.ts +6 -3
  3. package/lib/index.cjs +634 -261
  4. package/lib/types/acs.d.ts +4 -1
  5. package/lib/types/aily.d.ts +3 -3
  6. package/lib/types/apaas.d.ts +190 -28
  7. package/lib/types/application.d.ts +20 -4
  8. package/lib/types/approval.d.ts +0 -13
  9. package/lib/types/attendance.d.ts +11 -5
  10. package/lib/types/authen.d.ts +8 -2
  11. package/lib/types/bitable.d.ts +25 -4
  12. package/lib/types/board.d.ts +56 -0
  13. package/lib/types/calendar.d.ts +71 -5
  14. package/lib/types/cardkit.d.ts +2 -2
  15. package/lib/types/compensation.d.ts +400 -0
  16. package/lib/types/contact.d.ts +55 -12
  17. package/lib/types/corehr.d.ts +1287 -79
  18. package/lib/types/directory.d.ts +3 -41
  19. package/lib/types/docx.d.ts +23 -0
  20. package/lib/types/drive.d.ts +107 -90
  21. package/lib/types/ehr.d.ts +11 -2
  22. package/lib/types/helpdesk.d.ts +15 -6
  23. package/lib/types/hire.d.ts +52 -3
  24. package/lib/types/human_authentication.d.ts +1 -1
  25. package/lib/types/im.d.ts +77 -21
  26. package/lib/types/index.d.ts +1670 -105
  27. package/lib/types/mail.d.ts +106 -16
  28. package/lib/types/payroll.d.ts +117 -81
  29. package/lib/types/performance.d.ts +1 -1
  30. package/lib/types/search.d.ts +4 -1
  31. package/lib/types/security_and_compliance.d.ts +254 -1
  32. package/lib/ws.d.ts +30 -0
  33. package/package.json +6 -3
  34. package/src/bot.ts +28 -15
  35. package/src/http.ts +10 -4
  36. package/src/types/acs.ts +4 -1
  37. package/src/types/aily.ts +3 -3
  38. package/src/types/apaas.ts +237 -38
  39. package/src/types/application.ts +20 -4
  40. package/src/types/approval.ts +0 -15
  41. package/src/types/attendance.ts +11 -5
  42. package/src/types/authen.ts +8 -2
  43. package/src/types/bitable.ts +25 -4
  44. package/src/types/board.ts +75 -2
  45. package/src/types/calendar.ts +88 -5
  46. package/src/types/cardkit.ts +2 -2
  47. package/src/types/compensation.ts +485 -0
  48. package/src/types/contact.ts +55 -12
  49. package/src/types/corehr.ts +1480 -123
  50. package/src/types/directory.ts +3 -53
  51. package/src/types/docx.ts +29 -0
  52. package/src/types/drive.ts +129 -112
  53. package/src/types/ehr.ts +11 -2
  54. package/src/types/helpdesk.ts +15 -6
  55. package/src/types/hire.ts +66 -3
  56. package/src/types/human_authentication.ts +1 -1
  57. package/src/types/im.ts +77 -21
  58. package/src/types/index.ts +1751 -107
  59. package/src/types/mail.ts +106 -16
  60. package/src/types/payroll.ts +146 -103
  61. package/src/types/performance.ts +1 -1
  62. package/src/types/search.ts +4 -1
  63. package/src/types/security_and_compliance.ts +292 -1
  64. package/src/ws.ts +183 -0
  65. package/lib/types/api.d.ts +0 -28510
  66. package/lib/types/internal.d.ts +0 -21
  67. package/lib/types/message/content.d.ts +0 -433
  68. package/lib/types/message/index.d.ts +0 -95
@@ -1,5 +1,5 @@
1
1
  import * as Lark from '.'
2
- import { Internal, Paginated } from '../internal'
2
+ import { Internal, Paginated, Pagination } from '../internal'
3
3
 
4
4
  declare module '../internal' {
5
5
  interface Internal {
@@ -9,9 +9,285 @@ declare module '../internal' {
9
9
 
10
10
  export namespace SecurityAndCompliance {
11
11
  export interface Methods {
12
+ deviceRecord: DeviceRecord.Methods
13
+ deviceApplyRecord: DeviceApplyRecord.Methods
12
14
  openapiLog: OpenapiLog.Methods
13
15
  }
14
16
 
17
+ export namespace DeviceRecord {
18
+ export interface Methods {
19
+ /**
20
+ * 获取客户端设备认证信息
21
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/mine
22
+ */
23
+ mine(): Promise<MineResponse>
24
+ /**
25
+ * 新增设备
26
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/create
27
+ */
28
+ create(body: CreateRequest, query?: CreateQuery): Promise<CreateResponse>
29
+ /**
30
+ * 查询设备信息
31
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/list
32
+ */
33
+ list(query?: ListQuery): Paginated<Lark.DeviceRecord>
34
+ /**
35
+ * 获取设备信息
36
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/get
37
+ */
38
+ get(device_record_id: string, query?: GetQuery): Promise<GetResponse>
39
+ /**
40
+ * 更新设备
41
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/update
42
+ */
43
+ update(device_record_id: string, body: UpdateRequest, query?: UpdateQuery): Promise<void>
44
+ /**
45
+ * 删除设备
46
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_record/delete
47
+ */
48
+ delete(device_record_id: string): Promise<void>
49
+ }
50
+
51
+ export const enum MineResponseDeviceOwnership {
52
+ /** 未知设备 */
53
+ Unknown = 0,
54
+ /** 个人设备 */
55
+ Personal = 1,
56
+ /** 企业设备 */
57
+ Company = 2,
58
+ }
59
+
60
+ export const enum MineResponseDeviceStatus {
61
+ /** 未知状态 */
62
+ Unknown = 0,
63
+ /** 信任设备 */
64
+ Trusted = 1,
65
+ /** 非信任设备 */
66
+ Untrusted = 2,
67
+ }
68
+
69
+ export interface MineResponse {
70
+ /** 设备认证编码 */
71
+ device_record_id?: string
72
+ /** 设备归属 */
73
+ device_ownership?: MineResponseDeviceOwnership
74
+ /** 可信状态 */
75
+ device_status?: MineResponseDeviceStatus
76
+ }
77
+
78
+ export const enum CreateRequestDeviceSystem {
79
+ /** Windows */
80
+ Windows = 1,
81
+ /** macOS */
82
+ MacOS = 2,
83
+ /** Linux */
84
+ Linux = 3,
85
+ /** Android */
86
+ Android = 4,
87
+ /** iOS */
88
+ IOS = 5,
89
+ /** OpenHarmony */
90
+ OpenHarmony = 6,
91
+ }
92
+
93
+ export const enum CreateRequestDeviceOwnership {
94
+ /** 未知设备 */
95
+ Unknown = 0,
96
+ /** 个人设备 */
97
+ Personal = 1,
98
+ /** 企业设备 */
99
+ Company = 2,
100
+ }
101
+
102
+ export const enum CreateRequestDeviceStatus {
103
+ /** 未知状态 */
104
+ Unknown = 0,
105
+ /** 信任设备 */
106
+ Trusted = 1,
107
+ /** 非信任设备 */
108
+ Untrusted = 2,
109
+ }
110
+
111
+ export interface CreateRequest {
112
+ /** 操作系统 */
113
+ device_system: CreateRequestDeviceSystem
114
+ /** 生产序列号 */
115
+ serial_number?: string
116
+ /** 硬盘序列号 */
117
+ disk_serial_number?: string
118
+ /** 主板UUID */
119
+ uuid?: string
120
+ /** MAC地址 */
121
+ mac_address?: string
122
+ /** Android标识符 */
123
+ android_id?: string
124
+ /** iOS供应商标识符 */
125
+ idfv?: string
126
+ /** Harmony供应商标识符 */
127
+ aaid?: string
128
+ /** 设备归属 */
129
+ device_ownership: CreateRequestDeviceOwnership
130
+ /** 可信状态 */
131
+ device_status: CreateRequestDeviceStatus
132
+ /** 最近登录用户ID */
133
+ latest_user_id?: string
134
+ /** 设备指纹列表 */
135
+ dids?: string[]
136
+ }
137
+
138
+ export interface CreateQuery {
139
+ /** 此次调用中使用的用户ID的类型 */
140
+ user_id_type?: 'user_id' | 'union_id' | 'open_id'
141
+ }
142
+
143
+ export interface CreateResponse {
144
+ /** 设备认证编码 */
145
+ device_record_id?: string
146
+ }
147
+
148
+ export const enum ListQueryDeviceOwnership {
149
+ /** 未知设备 */
150
+ Unknown = 0,
151
+ /** 个人设备 */
152
+ Personal = 1,
153
+ /** 企业设备 */
154
+ Company = 2,
155
+ }
156
+
157
+ export const enum ListQueryDeviceStatus {
158
+ /** 未知状态 */
159
+ Unknown = 0,
160
+ /** 信任设备 */
161
+ Trusted = 1,
162
+ /** 非信任设备 */
163
+ Untrusted = 2,
164
+ }
165
+
166
+ export const enum ListQueryDeviceTerminalType {
167
+ /** 未知 */
168
+ Unknown = 0,
169
+ /** 移动端 */
170
+ Mobile = 1,
171
+ /** 桌面端 */
172
+ PC = 2,
173
+ }
174
+
175
+ export const enum ListQueryOs {
176
+ /** 未知 */
177
+ Unknown = 0,
178
+ /** Windows */
179
+ Windows = 1,
180
+ /** macOS */
181
+ MacOS = 2,
182
+ /** Linux */
183
+ Linux = 3,
184
+ /** Android */
185
+ Android = 4,
186
+ /** iOS */
187
+ IOS = 5,
188
+ /** 鸿蒙 */
189
+ OpenHarmony = 6,
190
+ }
191
+
192
+ export interface ListQuery extends Pagination {
193
+ /** 设备认证编码 */
194
+ device_record_id?: string
195
+ /** 当前登录用户ID */
196
+ current_user_id?: string
197
+ /** 此次调用中使用的用户ID的类型 */
198
+ user_id_type?: 'open_id' | 'union_id' | 'user_id'
199
+ /** 设备名称 */
200
+ device_name?: string
201
+ /** 生产序列号 */
202
+ serial_number?: string
203
+ /** 硬盘序列号 */
204
+ disk_serial_number?: string
205
+ /** MAC地址 */
206
+ mac_address?: string
207
+ /** Android标识符 */
208
+ android_id?: string
209
+ /** 主板UUID */
210
+ uuid?: string
211
+ /** iOS供应商标识符 */
212
+ idfv?: string
213
+ /** Harmony供应商标识符 */
214
+ aaid?: string
215
+ /** 设备归属 */
216
+ device_ownership?: ListQueryDeviceOwnership
217
+ /** 可信状态 */
218
+ device_status?: ListQueryDeviceStatus
219
+ /** 设备类型 */
220
+ device_terminal_type?: ListQueryDeviceTerminalType
221
+ /** 设备操作系统 */
222
+ os?: ListQueryOs
223
+ /** 最近登录用户ID */
224
+ latest_user_id?: string
225
+ /** 设备指纹 */
226
+ did?: string
227
+ }
228
+
229
+ export interface GetQuery {
230
+ /** 此次调用中使用的用户ID的类型 */
231
+ user_id_type?: 'user_id' | 'union_id' | 'open_id'
232
+ }
233
+
234
+ export interface GetResponse {
235
+ /** 设备记录 */
236
+ device_record?: Lark.DeviceRecord
237
+ }
238
+
239
+ export const enum UpdateRequestDeviceOwnership {
240
+ /** 未知设备 */
241
+ Unknown = 0,
242
+ /** 个人设备 */
243
+ Personal = 1,
244
+ /** 企业设备 */
245
+ Company = 2,
246
+ }
247
+
248
+ export const enum UpdateRequestDeviceStatus {
249
+ /** 未知状态 */
250
+ Unknown = 0,
251
+ /** 信任设备 */
252
+ Trusted = 1,
253
+ /** 非信任设备 */
254
+ Untrusted = 2,
255
+ }
256
+
257
+ export interface UpdateRequest {
258
+ /** 设备归属 */
259
+ device_ownership: UpdateRequestDeviceOwnership
260
+ /** 可信状态 */
261
+ device_status: UpdateRequestDeviceStatus
262
+ /** 最近登录用户ID */
263
+ latest_user_id?: string
264
+ /** 设备指纹列表 */
265
+ dids?: string[]
266
+ }
267
+
268
+ export interface UpdateQuery {
269
+ /** 版本号 */
270
+ version: string
271
+ /** 此次调用中使用的用户ID的类型 */
272
+ user_id_type?: 'user_id' | 'union_id' | 'open_id'
273
+ }
274
+ }
275
+
276
+ export namespace DeviceApplyRecord {
277
+ export interface Methods {
278
+ /**
279
+ * 审批设备申报
280
+ * @see https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/security_and_compliance-v2/device_apply_record/update
281
+ */
282
+ update(device_apply_record_id: string, body: UpdateRequest): Promise<void>
283
+ }
284
+
285
+ export interface UpdateRequest {
286
+ /** 是否审批通过 */
287
+ is_approved: boolean
288
+ }
289
+ }
290
+
15
291
  export namespace OpenapiLog {
16
292
  export interface Methods {
17
293
  /**
@@ -39,6 +315,21 @@ export namespace SecurityAndCompliance {
39
315
  }
40
316
 
41
317
  Internal.define({
318
+ '/security_and_compliance/v2/device_records/mine': {
319
+ GET: 'securityAndCompliance.deviceRecord.mine',
320
+ },
321
+ '/security_and_compliance/v2/device_records': {
322
+ POST: 'securityAndCompliance.deviceRecord.create',
323
+ GET: { name: 'securityAndCompliance.deviceRecord.list', pagination: { argIndex: 0 } },
324
+ },
325
+ '/security_and_compliance/v2/device_records/{device_record_id}': {
326
+ GET: 'securityAndCompliance.deviceRecord.get',
327
+ PUT: 'securityAndCompliance.deviceRecord.update',
328
+ DELETE: 'securityAndCompliance.deviceRecord.delete',
329
+ },
330
+ '/security_and_compliance/v2/device_apply_records/{device_apply_record_id}': {
331
+ PUT: 'securityAndCompliance.deviceApplyRecord.update',
332
+ },
42
333
  '/security_and_compliance/v1/openapi_logs/list_data': {
43
334
  POST: 'securityAndCompliance.openapiLog.listData',
44
335
  },
package/src/ws.ts ADDED
@@ -0,0 +1,183 @@
1
+ import { Adapter, Context, Schema, Universal } from '@satorijs/core'
2
+ import { LarkBot } from './bot'
3
+ import { adaptSession, EventPayload } from './utils'
4
+ import pb from 'protobufjs/light'
5
+
6
+ enum FrameType {
7
+ control = 0,
8
+ data = 1,
9
+ }
10
+
11
+ enum MessageType {
12
+ event = 'event',
13
+ card = 'card',
14
+ ping = 'ping',
15
+ pong = 'pong',
16
+ }
17
+
18
+ interface FrameSegment {
19
+ message_id: string
20
+ sum: number
21
+ seq: number
22
+ data: Uint8Array
23
+ }
24
+
25
+ export class WsClient<C extends Context = Context> extends Adapter.WsClient<C, LarkBot<C, LarkBot.BaseConfig & WsClient.Options>> {
26
+ _deviceId: string
27
+ _serviceId: number
28
+ _pingInterval: number = 90000
29
+ _ping: NodeJS.Timeout
30
+ _cache: Record<string, FrameSegment[]> = {}
31
+ _frame: pb.Type
32
+
33
+ constructor(ctx: C, bot: LarkBot<C, LarkBot.BaseConfig & WsClient.Options>) {
34
+ super(ctx, bot)
35
+ }
36
+
37
+ async prepare() {
38
+ this._frame = pb.Root.fromJSON({
39
+ nested: {
40
+ Header: {
41
+ fields: {
42
+ key: { rule: 'required', type: 'string', id: 1 },
43
+ value: { rule: 'required', type: 'string', id: 2 },
44
+ },
45
+ },
46
+ Frame: {
47
+ fields: {
48
+ SeqID: { rule: 'required', type: 'uint64', id: 1 },
49
+ LogID: { rule: 'required', type: 'uint64', id: 2 },
50
+ service: { rule: 'required', type: 'int32', id: 3 },
51
+ method: { rule: 'required', type: 'int32', id: 4 },
52
+ headers: { rule: 'repeated', type: 'Header', id: 5 },
53
+ payloadEncoding: { type: 'string', id: 6 },
54
+ payloadType: { type: 'string', id: 7 },
55
+ payload: { type: 'bytes', id: 8 },
56
+ LogIDNew: { type: 'string', id: 9 },
57
+ },
58
+ },
59
+ },
60
+ }).lookupType('Frame')
61
+
62
+ const baseUrl = this.bot.config.baseURL ?? new URL(this.bot.config.endpoint).origin
63
+ const { code, data: { URL: url, ClientConfig: config }, msg } = await this.bot.http.post(`${baseUrl}/callback/ws/endpoint`, {
64
+ AppID: this.bot.config.appId,
65
+ AppSecret: this.bot.config.appSecret,
66
+ })
67
+ if (code !== 0) throw new Error(`failed to get gateway url: ${code} ${msg}`)
68
+
69
+ const urlObj = new URL(url)
70
+ this._deviceId = urlObj.searchParams.get('device_id')
71
+ this._serviceId = +urlObj.searchParams.get('service_id')
72
+ this._pingInterval = config.PingInterval * 1000
73
+
74
+ return this.bot.ctx.http.ws(url)
75
+ }
76
+
77
+ ping() {
78
+ if (!this.socket || this.bot.status !== Universal.Status.ONLINE) {
79
+ clearTimeout(this._ping)
80
+ return
81
+ }
82
+ const frame = {
83
+ headers: [{
84
+ key: 'type',
85
+ value: MessageType.ping,
86
+ }],
87
+ service: this._serviceId,
88
+ method: FrameType.control,
89
+ SeqID: 0,
90
+ LogID: 0,
91
+ }
92
+ this.send(frame)
93
+ this._ping = setTimeout(() => this.ping(), this._pingInterval)
94
+ }
95
+
96
+ async accept() {
97
+ await this.bot.initialize()
98
+
99
+ this.socket.addEventListener('message', async ({ data }) => {
100
+ const frame: {
101
+ headers: { key: string; value: string }[]
102
+ method: FrameType
103
+ payload?: Uint8Array
104
+ } = this._frame.decode(new Uint8Array(data as any)) as any
105
+ const headers: {
106
+ message_id: string
107
+ type: MessageType
108
+ sum: string
109
+ seq: string
110
+ } = (frame.headers ?? []).reduce((acc, cur) => {
111
+ acc[cur.key] = cur.value
112
+ return acc
113
+ }, {} as any)
114
+
115
+ if (frame.method === FrameType.control && headers.type === MessageType.pong) {
116
+ this.bot.logger.debug('pong')
117
+ return
118
+ }
119
+
120
+ if (frame.method === FrameType.data) {
121
+ if (headers.type !== MessageType.event) return
122
+
123
+ const data = this.retrieve({
124
+ message_id: headers.message_id,
125
+ sum: +headers.sum,
126
+ seq: +headers.seq,
127
+ data: frame.payload,
128
+ })
129
+ if (!data) return
130
+
131
+ const body: EventPayload = JSON.parse(Buffer.from(data).toString('utf8'))
132
+ if (!body.header) return
133
+ this.bot.logger.info('received event: %o', body)
134
+ body.type = body.header.event_type
135
+ const session = await adaptSession(this.bot, body)
136
+ this.bot.dispatch(session)
137
+
138
+ this.send({
139
+ ...frame,
140
+ headers: [...frame.headers, { key: 'biz_rt', value: '0' }],
141
+ payload: Buffer.from(JSON.stringify({ code: 200 })),
142
+ })
143
+ }
144
+ })
145
+
146
+ this.socket.addEventListener('close', (e) => {
147
+ clearTimeout(this._ping)
148
+ this.bot.offline()
149
+ })
150
+ this.ping()
151
+ }
152
+
153
+ send(frame: any) {
154
+ const encoded = this._frame.encode(frame).finish()
155
+ this.socket.send(encoded as any)
156
+ }
157
+
158
+ retrieve(seg: FrameSegment): Uint8Array | undefined {
159
+ const { message_id, sum } = seg
160
+ if (sum === 1) return seg.data
161
+ if (!this._cache[message_id]) this._cache[message_id] = []
162
+
163
+ this._cache[message_id].push(seg)
164
+ if (this._cache[message_id].length === sum) {
165
+ const data = Buffer.concat(this._cache[message_id].sort((a, b) => a.seq - b.seq).map((item) => item.data))
166
+ delete this._cache[message_id]
167
+ return data
168
+ }
169
+ }
170
+ }
171
+
172
+ export namespace WsClient {
173
+ export interface Options extends Adapter.WsClientConfig {
174
+ protocol: 'ws'
175
+ }
176
+
177
+ export const Options: Schema<Options> = Schema.intersect([
178
+ Schema.object({
179
+ protocol: Schema.const('ws').required(),
180
+ }),
181
+ Adapter.WsClientConfig,
182
+ ])
183
+ }