@satorijs/adapter-lark 3.6.0 → 3.6.1

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,6 +1,31 @@
1
+ declare global {
2
+ namespace JSX {
3
+ interface IntrinsicElements {
4
+ 'lark:share-chat': {
5
+ 'chat-id': string;
6
+ };
7
+ 'lark:share-user': {
8
+ 'user-id': string;
9
+ };
10
+ 'lark:system': {
11
+ 'need-rollup'?: boolean;
12
+ };
13
+ }
14
+ }
15
+ }
16
+ export interface MessageContent {
17
+ text: MessageContent.Text;
18
+ post: MessageContent.RichText;
19
+ image: MessageContent.Image;
20
+ file: MessageContent.File;
21
+ audio: MessageContent.Audio;
22
+ media: MessageContent.Media;
23
+ sticker: MessageContent.Sticker;
24
+ share_chat: MessageContent.ShareChat;
25
+ share_user: MessageContent.ShareUser;
26
+ system: MessageContent.System;
27
+ }
1
28
  export declare namespace MessageContent {
2
- type Contents = Text | Image | ShareChat | ShareUser | Audio | Media | File | Sticker | RichText;
3
- type MediaContents = Image | Audio | Media | File;
4
29
  interface Text {
5
30
  text: string;
6
31
  }
@@ -18,7 +43,7 @@ export declare namespace MessageContent {
18
43
  }
19
44
  interface Media {
20
45
  file_key: string;
21
- image_key: string;
46
+ image_key?: string;
22
47
  }
23
48
  interface File {
24
49
  file_key: string;
@@ -26,44 +51,198 @@ export declare namespace MessageContent {
26
51
  interface Sticker {
27
52
  file_key: string;
28
53
  }
54
+ interface System {
55
+ type: 'divider';
56
+ params: {
57
+ divider_text: {
58
+ text: string;
59
+ i18n_text?: Record<string, string>;
60
+ };
61
+ };
62
+ options?: {
63
+ need_rollup?: boolean;
64
+ };
65
+ }
29
66
  interface RichText {
30
67
  [locale: string]: {
31
- title: string;
68
+ title?: string;
32
69
  content: RichText.Paragraph[];
33
70
  };
34
71
  }
35
72
  namespace RichText {
36
- interface Paragraph extends Array<RichText.Content> {
37
- }
38
- interface BaseContent {
39
- tag: string;
73
+ type Style = 'bold' | 'italic' | 'underline' | 'lineThrough';
74
+ interface BaseElement<T extends string = string> {
75
+ tag: T;
40
76
  }
41
- interface TextContent extends BaseContent {
42
- tag: 'text';
77
+ interface TextElement extends BaseElement<'text'> {
43
78
  text: string;
44
79
  un_escape?: boolean;
80
+ style?: Style[];
45
81
  }
46
- interface LinkContent extends BaseContent {
47
- tag: 'a';
82
+ interface LinkElement extends BaseElement<'a'> {
48
83
  text: string;
49
84
  href: string;
85
+ style?: Style[];
50
86
  }
51
- interface AtContent extends BaseContent {
52
- tag: 'at';
87
+ interface AtElement extends BaseElement<'at'> {
53
88
  user_id: string;
54
- user_name?: string;
89
+ style?: Style[];
55
90
  }
56
- interface ImageContent extends BaseContent {
57
- tag: 'img';
91
+ interface ImageElement extends BaseElement<'img'> {
58
92
  image_key: string;
59
- height?: number;
60
- width?: number;
61
93
  }
62
- interface MediaContent extends BaseContent {
63
- tag: 'media';
94
+ interface MediaElement extends BaseElement<'media'> {
64
95
  file_key: string;
65
96
  image_key?: string;
66
97
  }
67
- type Content = RichText.TextContent | RichText.LinkContent | RichText.AtContent | RichText.ImageContent | RichText.MediaContent;
98
+ interface EmotionElement extends BaseElement<'emoji'> {
99
+ emoji_type: string;
100
+ }
101
+ interface CodeBlockElement extends BaseElement<'code_block'> {
102
+ language?: string;
103
+ text: string;
104
+ }
105
+ interface HRElement extends BaseElement<'hr'> {
106
+ }
107
+ interface MarkdownElement extends BaseElement<'md'> {
108
+ text: string;
109
+ }
110
+ type InlineElement = TextElement | LinkElement | AtElement | EmotionElement | MarkdownElement;
111
+ type BlockElement = ImageElement | MediaElement | CodeBlockElement | HRElement;
112
+ type Paragraph = InlineElement[] | [BlockElement];
113
+ }
114
+ interface Card {
115
+ config: Card.Config;
116
+ card_link?: Card.URLs;
117
+ elements?: Card.Element[];
118
+ }
119
+ namespace Card {
120
+ /** @see https://open.larksuite.com/document/common-capabilities/message-card/getting-started/card-structure/card-configuration */
121
+ interface Config {
122
+ enable_forward?: boolean;
123
+ update_multi?: boolean;
124
+ }
125
+ interface URLs {
126
+ url: string;
127
+ pc_url?: string;
128
+ ios_url?: string;
129
+ android_url?: string;
130
+ }
131
+ /** @see https://open.larksuite.com/document/common-capabilities/message-card/message-cards-content/card-header */
132
+ interface Header {
133
+ title: I18nPlainTextElement;
134
+ subtitle?: I18nPlainTextElement;
135
+ template?: Header.Template;
136
+ icon?: CustomIconElement;
137
+ ud_icon?: StandardIconElement;
138
+ text_tag_list?: TextTagElement[];
139
+ i18n_text_tag_list?: Record<string, TextTagElement[]>;
140
+ }
141
+ namespace Header {
142
+ type Template = 'blue' | 'wathet' | 'turquoise' | 'green' | 'yellow' | 'orange' | 'red' | 'carmine' | 'violet' | 'purple' | 'indigo' | 'grey' | 'default';
143
+ }
144
+ interface BaseElement<T extends string = string> {
145
+ tag: T;
146
+ }
147
+ type TextSize = 'heading-0' | 'heading-1' | 'heading-2' | 'heading-3' | 'heading-4' | 'heading' | 'normal' | 'notation' | 'xxxx-large' | 'xxx-large' | 'xx-large' | 'x-large' | 'large' | 'medium' | 'small' | 'x-small';
148
+ type TextAlign = 'left' | 'center' | 'right';
149
+ interface PlainTextElement extends BaseElement<'plain_text'> {
150
+ content: string;
151
+ }
152
+ interface I18nPlainTextElement extends PlainTextElement {
153
+ i18n?: Record<string, string>;
154
+ }
155
+ interface DivPlainTextElement extends PlainTextElement {
156
+ text_size?: TextSize;
157
+ text_color?: string;
158
+ text_align?: TextAlign;
159
+ lines?: number;
160
+ icon?: IconElement;
161
+ }
162
+ type IconElement = StandardIconElement | CustomIconElement;
163
+ interface CustomIconElement extends BaseElement<'custom_icon'> {
164
+ img_key: string;
165
+ }
166
+ interface StandardIconElement extends BaseElement<'standard_icon'> {
167
+ token: string;
168
+ color?: string;
169
+ }
170
+ interface TextTagElement extends BaseElement<'text_tag'> {
171
+ text: PlainTextElement;
172
+ color: TextTagElement.Color;
173
+ }
174
+ namespace TextTagElement {
175
+ type Color = 'neutral' | 'blue' | 'torqoise' | 'lime' | 'orange' | 'violet' | 'indigo' | 'wathet' | 'green' | 'yellow' | 'red' | 'purple' | 'carmine';
176
+ }
177
+ interface ImageElement extends BaseElement<'image'> {
178
+ img_key: string;
179
+ alt?: PlainTextElement;
180
+ title?: PlainTextElement;
181
+ custom_width?: number;
182
+ compact_width?: boolean;
183
+ mode?: 'crop_center' | 'fit_horizontal' | 'large' | 'medium' | 'small' | 'tiny';
184
+ preview?: boolean;
185
+ }
186
+ interface HorizontalRuleElement extends BaseElement<'hr'> {
187
+ }
188
+ interface DivElement extends BaseElement<'div'> {
189
+ text?: DivPlainTextElement;
190
+ }
191
+ interface MarkdownElement extends BaseElement<'markdown'> {
192
+ content: string;
193
+ text_size?: TextSize;
194
+ text_align?: TextAlign;
195
+ href?: Record<string, URLs>;
196
+ }
197
+ interface HorizontalRuleElement extends BaseElement<'hr'> {
198
+ }
199
+ interface ActionModule extends BaseElement<'action'> {
200
+ actions: ActionElement[];
201
+ layout?: 'bisected' | 'trisection' | 'flow';
202
+ }
203
+ type ActionElement = ButtonElement;
204
+ type ActionBehavior = OpenURLBehavior | CallbackBehavior;
205
+ interface OpenURLBehavior {
206
+ type: 'open_url';
207
+ default_url: string;
208
+ pc_url?: string;
209
+ ios_url?: string;
210
+ android_url?: string;
211
+ }
212
+ interface CallbackBehavior {
213
+ type: 'callback';
214
+ value: Record<string, string>;
215
+ }
216
+ interface ButtonElement extends BaseElement<'button'> {
217
+ text: PlainTextElement;
218
+ type?: ButtonElement.Type;
219
+ size?: ButtonElement.Size;
220
+ width?: ButtonElement.Width;
221
+ icon?: IconElement;
222
+ hover_tips?: PlainTextElement;
223
+ disabled?: boolean;
224
+ disabled_tips?: PlainTextElement;
225
+ confirm?: {
226
+ title: PlainTextElement;
227
+ text: PlainTextElement;
228
+ };
229
+ behaviors?: ActionBehavior[];
230
+ name?: string;
231
+ required?: boolean;
232
+ action_type?: 'link' | 'request' | 'multi' | 'form_submit' | 'form_reset';
233
+ }
234
+ namespace ButtonElement {
235
+ type Size = 'tiny' | 'small' | 'medium' | 'large';
236
+ type Width = 'default' | 'fill' | string;
237
+ type Type = 'default' | 'primary' | 'danger' | 'text' | 'primary_text' | 'danger_text' | 'primary_filled' | 'danger_filled' | 'laser';
238
+ }
239
+ type Element = DivElement | MarkdownElement | HorizontalRuleElement | ActionModule;
240
+ }
241
+ interface Template {
242
+ type: 'template';
243
+ data: {
244
+ template_id: string;
245
+ template_variable: object;
246
+ };
68
247
  }
69
248
  }
@@ -1,19 +1,5 @@
1
- import { Lark } from '..';
2
- import { MessageContent } from './content';
1
+ import { Lark, MessageContent } from '..';
3
2
  export * from './content';
4
- export type MessageType = 'text' | 'post' | 'image' | 'file' | 'audio' | 'media' | 'sticker' | 'interactive' | 'share_chat' | 'share_user';
5
- export interface MessageContentMap {
6
- 'text': MessageContent.Text;
7
- 'post': MessageContent.RichText;
8
- 'image': MessageContent.Image;
9
- 'file': MessageContent.File;
10
- 'audio': MessageContent.Audio;
11
- 'media': MessageContent.Media;
12
- 'sticker': MessageContent.Sticker;
13
- 'share_chat': MessageContent.ShareChat;
14
- 'share_user': MessageContent.ShareUser;
15
- }
16
- export type MessageContentType<T extends MessageType> = T extends keyof MessageContentMap ? MessageContentMap[T] : any;
17
3
  declare module '../event' {
18
4
  interface Events {
19
5
  /**
@@ -33,7 +19,7 @@ declare module '../event' {
33
19
  create_time: string;
34
20
  chat_id: string;
35
21
  chat_type: string;
36
- message_type: MessageType;
22
+ message_type: keyof MessageContent;
37
23
  content: string;
38
24
  mentions: {
39
25
  key: string;
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context, Session, Universal } from '@satorijs/core';
2
- import { FeishuBot, LarkBot } from './bot';
2
+ import { LarkBot } from './bot';
3
3
  import { EventPayload, Events, GetImChatResponse, Lark } from './types';
4
4
  export type Sender = {
5
5
  sender_id: Lark.UserIds;
@@ -10,8 +10,8 @@ export type Sender = {
10
10
  tenant_key: string;
11
11
  });
12
12
  export declare function adaptSender(sender: Sender, session: Session): Session;
13
- export declare function adaptMessage(bot: FeishuBot, data: Events['im.message.receive_v1'], session: Session, details?: boolean): Promise<Session>;
14
- export declare function adaptSession<C extends Context>(bot: FeishuBot<C>, body: EventPayload): Promise<C[typeof import("cordis").Context.session]>;
13
+ export declare function adaptMessage(bot: LarkBot, data: Events['im.message.receive_v1'], session: Session, details?: boolean): Promise<Session>;
14
+ export declare function adaptSession<C extends Context>(bot: LarkBot<C>, body: EventPayload): Promise<C[typeof import("cordis").Context.session]>;
15
15
  export declare function decodeMessage(bot: LarkBot, body: Lark.Message, details?: boolean): Promise<Universal.Message>;
16
16
  /**
17
17
  * Get ID type from id string
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.0",
4
+ "version": "3.6.1",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "types": "lib/index.d.ts",
package/src/http.ts CHANGED
@@ -3,29 +3,29 @@ import { ReadableStream } from 'node:stream/web'
3
3
  import { Adapter, Context, Logger, Schema } from '@satorijs/core'
4
4
  import {} from '@cordisjs/plugin-server'
5
5
 
6
- import { FeishuBot } from './bot'
6
+ import { LarkBot } from './bot'
7
7
  import { EventPayload } from './types'
8
8
  import { adaptSession, Cipher } from './utils'
9
9
 
10
- export class HttpServer<C extends Context = Context> extends Adapter<C, FeishuBot<C>> {
10
+ export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<C>> {
11
11
  static inject = ['server']
12
12
 
13
13
  private logger: Logger
14
14
  private ciphers: Record<string, Cipher> = {}
15
15
 
16
- constructor(ctx: C, bot: FeishuBot<C>) {
16
+ constructor(ctx: C, bot: LarkBot<C>) {
17
17
  super(ctx)
18
18
  this.logger = ctx.logger('lark')
19
19
  }
20
20
 
21
- fork(ctx: C, bot: FeishuBot<C>) {
21
+ fork(ctx: C, bot: LarkBot<C>) {
22
22
  super.fork(ctx, bot)
23
23
 
24
24
  this._refreshCipher()
25
25
  return bot.initialize()
26
26
  }
27
27
 
28
- async connect(bot: FeishuBot) {
28
+ async connect(bot: LarkBot) {
29
29
  const { path } = bot.config
30
30
  bot.ctx.server.post(path, (ctx) => {
31
31
  this._refreshCipher()
@@ -72,10 +72,10 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, FeishuBo
72
72
 
73
73
  // dispatch message
74
74
  bot.logger.debug('received decryped event: %o', body)
75
- // @TODO: need await?
76
75
  this.dispatchSession(body)
77
76
 
78
77
  // Lark requires 200 OK response to make sure event is received
78
+ ctx.body = {}
79
79
  return ctx.status = 200
80
80
  })
81
81