@satorijs/adapter-lark 3.6.2 → 3.7.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.
@@ -12,7 +12,7 @@ type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
12
12
  export declare class Internal {
13
13
  private bot;
14
14
  constructor(bot: LarkBot);
15
- private processReponse;
16
- static define(routes: Dict<Partial<Record<Method, string | string[]>>>): void;
15
+ private assertResponse;
16
+ static define(routes: Dict<Partial<Record<Method, string | string[]>>>, extractData?: boolean): void;
17
17
  }
18
18
  export {};
package/lib/utils.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare function decodeMessage(bot: LarkBot, body: Lark.Message, details?
18
18
  * @see https://open.larksuite.com/document/home/user-identity-introduction/introduction
19
19
  */
20
20
  export declare function extractIdType(id: string): Lark.ReceiveIdType;
21
- export declare function decodeChannel(channelId: string, guild: GetImChatResponse['data']): Universal.Channel;
21
+ export declare function decodeChannel(channelId: string, guild: GetImChatResponse): Universal.Channel;
22
22
  export declare function decodeGuild(guild: Lark.ListChat): Universal.Guild;
23
23
  export declare function decodeUser(user: Lark.User): Universal.User;
24
24
  export declare class Cipher {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@satorijs/adapter-lark",
3
3
  "description": "Lark (飞书) Adapter for Satorijs",
4
- "version": "3.6.2",
4
+ "version": "3.7.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "types": "lib/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "@cordisjs/plugin-server": "^0.2.4",
38
- "@satorijs/core": "^4.2.10",
38
+ "@satorijs/core": "^4.2.11",
39
39
  "cordis": "^3.18.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "@satorijs/core": "^4.2.10"
42
+ "@satorijs/core": "^4.2.11"
43
43
  }
44
- }
44
+ }
package/src/bot.ts CHANGED
@@ -89,26 +89,26 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
89
89
 
90
90
  async getMessage(channelId: string, messageId: string, recursive = true) {
91
91
  const data = await this.internal.getImMessage(messageId)
92
- const message = await Utils.decodeMessage(this, data.data.items[0], recursive)
92
+ const message = await Utils.decodeMessage(this, data.items[0], recursive)
93
93
  const im = await this.internal.getImChat(channelId)
94
- message.channel.type = im.data.chat_mode === 'p2p' ? Universal.Channel.Type.DIRECT : Universal.Channel.Type.TEXT
94
+ message.channel.type = im.chat_mode === 'p2p' ? Universal.Channel.Type.DIRECT : Universal.Channel.Type.TEXT
95
95
  return message
96
96
  }
97
97
 
98
98
  async getMessageList(channelId: string, before?: string) {
99
- const { data: messages } = await this.internal.listImMessage({ container_id_type: 'chat', container_id: channelId, page_token: before })
99
+ const messages = await this.internal.listImMessage({ container_id_type: 'chat', container_id: channelId, page_token: before })
100
100
  const data = await Promise.all(messages.items.reverse().map(data => Utils.decodeMessage(this, data)))
101
101
  return { data, next: data[0]?.id }
102
102
  }
103
103
 
104
104
  async getUser(userId: string, guildId?: string) {
105
105
  const data = await this.internal.getContactUser(userId)
106
- return Utils.decodeUser(data.data.user)
106
+ return Utils.decodeUser(data.user)
107
107
  }
108
108
 
109
109
  async getChannel(channelId: string) {
110
- const { data } = await this.internal.getImChat(channelId)
111
- return Utils.decodeChannel(channelId, data)
110
+ const chat = await this.internal.getImChat(channelId)
111
+ return Utils.decodeChannel(channelId, chat)
112
112
  }
113
113
 
114
114
  async getChannelList(guildId: string) {
@@ -116,19 +116,19 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
116
116
  }
117
117
 
118
118
  async getGuild(guildId: string) {
119
- const { data } = await this.internal.getImChat(guildId)
120
- return Utils.decodeGuild(data)
119
+ const chat = await this.internal.getImChat(guildId)
120
+ return Utils.decodeGuild(chat)
121
121
  }
122
122
 
123
123
  async getGuildList(after?: string) {
124
- const { data: guilds } = await this.internal.listImChat({ page_token: after })
125
- return { data: guilds.items.map(Utils.decodeGuild), next: guilds.page_token }
124
+ const chats = await this.internal.listImChat({ page_token: after })
125
+ return { data: chats.items.map(Utils.decodeGuild), next: chats.page_token }
126
126
  }
127
127
 
128
128
  async getGuildMemberList(guildId: string, after?: string) {
129
- const { data: users } = await this.internal.getImChatMembers(guildId, { page_token: after })
130
- const data = users.items.map(v => ({ user: { id: v.member_id, name: v.name }, name: v.name }))
131
- return { data, next: users.page_token }
129
+ const members = await this.internal.getImChatMembers(guildId, { page_token: after })
130
+ const data = members.items.map(v => ({ user: { id: v.member_id, name: v.name }, name: v.name }))
131
+ return { data, next: members.page_token }
132
132
  }
133
133
  }
134
134
 
package/src/message.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, Dict, h, MessageEncoder } from '@satorijs/core'
2
2
  import { LarkBot } from './bot'
3
- import { BaseResponse, Lark, MessageContent } from './types'
3
+ import { Lark, MessageContent } from './types'
4
4
  import { extractIdType } from './utils'
5
5
 
6
6
  export class LarkMessageEncoder<C extends Context = Context> extends MessageEncoder<C, LarkBot<C>> {
@@ -13,7 +13,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
13
13
 
14
14
  async post(data?: any) {
15
15
  try {
16
- let resp: BaseResponse & { data?: Lark.Message }
16
+ let resp: Lark.Message
17
17
  if (this.quote?.id) {
18
18
  resp = await this.bot.internal.replyImMessage(this.quote.id, {
19
19
  ...data,
@@ -26,9 +26,9 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
26
26
  })
27
27
  }
28
28
  const session = this.bot.session()
29
- session.messageId = resp.data.message_id
30
- session.timestamp = Number(resp.data.create_time) * 1000
31
- session.userId = resp.data.sender.id
29
+ session.messageId = resp.message_id
30
+ session.timestamp = Number(resp.create_time) * 1000
31
+ session.userId = resp.sender.id
32
32
  session.channelId = this.channelId
33
33
  session.guildId = this.guildId
34
34
  session.app.emit(session, 'send', session)
@@ -96,7 +96,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
96
96
  const payload = new FormData()
97
97
  payload.append('image', new Blob([data], { type }), filename)
98
98
  payload.append('image_type', 'message')
99
- const { data: { image_key } } = await this.bot.internal.createImImage(payload)
99
+ const { image_key } = await this.bot.internal.createImImage(payload)
100
100
  return image_key
101
101
  }
102
102
 
@@ -126,7 +126,7 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
126
126
  }
127
127
  }
128
128
 
129
- const { data: { file_key } } = await this.bot.internal.createImFile(payload)
129
+ const { file_key } = await this.bot.internal.createImFile(payload)
130
130
  await this.post({
131
131
  msg_type: _type === 'video' ? 'media' : _type,
132
132
  content: JSON.stringify({ file_key }),