@cored-im/openapi-sdk 0.28.102
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.
- package/LICENSE +201 -0
- package/README.md +114 -0
- package/dist/index.cjs +1493 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +387 -0
- package/dist/index.d.ts +387 -0
- package/dist/index.js +1463 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
- package/src/client.ts +85 -0
- package/src/core/api_client.ts +344 -0
- package/src/core/config.ts +25 -0
- package/src/core/consts.ts +8 -0
- package/src/core/crypto.ts +212 -0
- package/src/core/http_client.ts +25 -0
- package/src/core/logger.ts +37 -0
- package/src/core/time_manager.ts +28 -0
- package/src/core/types.ts +72 -0
- package/src/core/version.ts +5 -0
- package/src/core/ws_client.ts +423 -0
- package/src/index.ts +19 -0
- package/src/internal/transport.ts +507 -0
- package/src/service/im/index.ts +11 -0
- package/src/service/im/v1/chat.ts +41 -0
- package/src/service/im/v1/chat_model.ts +19 -0
- package/src/service/im/v1/index.ts +9 -0
- package/src/service/im/v1/message.ts +59 -0
- package/src/service/im/v1/message_enum.ts +20 -0
- package/src/service/im/v1/message_event.ts +40 -0
- package/src/service/im/v1/message_model.ts +259 -0
- package/src/service/im/v1/v1.ts +14 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/** 64-bit integer represented as string to avoid precision loss */
|
|
2
|
+
type Int64 = string;
|
|
3
|
+
interface ApiRequest {
|
|
4
|
+
method: string;
|
|
5
|
+
path: string;
|
|
6
|
+
pathParams?: Record<string, string>;
|
|
7
|
+
queryParams?: Record<string, string>;
|
|
8
|
+
headerParams?: Record<string, string>;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
stream?: ReadableStream<Uint8Array> | null;
|
|
11
|
+
withAppAccessToken?: boolean;
|
|
12
|
+
withWebSocket?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface ApiResponse {
|
|
15
|
+
json(): Promise<unknown>;
|
|
16
|
+
body(): Promise<Uint8Array>;
|
|
17
|
+
}
|
|
18
|
+
interface ApiError {
|
|
19
|
+
code: number;
|
|
20
|
+
msg: string;
|
|
21
|
+
log_id: string;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
}
|
|
24
|
+
interface ApiClient {
|
|
25
|
+
preheat(): Promise<void>;
|
|
26
|
+
request(req: ApiRequest): Promise<ApiResponse>;
|
|
27
|
+
onEvent(eventType: string, handler: WrappedEventHandler): void;
|
|
28
|
+
offEvent(eventType: string, handler: WrappedEventHandler): void;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
interface EventHeader {
|
|
32
|
+
event_id: string;
|
|
33
|
+
event_type: string;
|
|
34
|
+
event_created_at: Int64;
|
|
35
|
+
}
|
|
36
|
+
type WrappedEventHandler = (header: EventHeader, body: Uint8Array | string) => void;
|
|
37
|
+
type Marshaller = (v: unknown) => string;
|
|
38
|
+
type Unmarshaller = (data: string) => unknown;
|
|
39
|
+
interface HttpClient {
|
|
40
|
+
fetch(url: string, init: RequestInit): Promise<Response>;
|
|
41
|
+
}
|
|
42
|
+
interface Logger {
|
|
43
|
+
debug(msg: string, ...args: unknown[]): void;
|
|
44
|
+
info(msg: string, ...args: unknown[]): void;
|
|
45
|
+
warn(msg: string, ...args: unknown[]): void;
|
|
46
|
+
error(msg: string, ...args: unknown[]): void;
|
|
47
|
+
}
|
|
48
|
+
declare enum LoggerLevel {
|
|
49
|
+
Debug = 0,
|
|
50
|
+
Info = 1,
|
|
51
|
+
Warn = 2,
|
|
52
|
+
Error = 3
|
|
53
|
+
}
|
|
54
|
+
interface TimeManager {
|
|
55
|
+
getSystemTimestamp(): number;
|
|
56
|
+
getServerTimestamp(): number;
|
|
57
|
+
syncServerTimestamp(timestamp: number): void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface Config {
|
|
61
|
+
appId: string;
|
|
62
|
+
appSecret: string;
|
|
63
|
+
backendUrl: string;
|
|
64
|
+
httpClient: HttpClient;
|
|
65
|
+
apiClient: ApiClient;
|
|
66
|
+
enableEncryption: boolean;
|
|
67
|
+
requestTimeout: number;
|
|
68
|
+
timeManager: TimeManager;
|
|
69
|
+
logger: Logger;
|
|
70
|
+
jsonMarshal: Marshaller;
|
|
71
|
+
jsonUnmarshal: Unmarshaller;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Set typing status (Request) */
|
|
75
|
+
interface CreateTypingReq {
|
|
76
|
+
chat_id?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Set typing status (Response) */
|
|
79
|
+
interface CreateTypingResp {
|
|
80
|
+
}
|
|
81
|
+
/** Clear typing status (Request) */
|
|
82
|
+
interface DeleteTypingReq {
|
|
83
|
+
chat_id?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Clear typing status (Response) */
|
|
86
|
+
interface DeleteTypingResp {
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare class Chat {
|
|
90
|
+
private readonly config;
|
|
91
|
+
constructor(config: Config);
|
|
92
|
+
/**
|
|
93
|
+
* Set typing status
|
|
94
|
+
*
|
|
95
|
+
* Set the typing status, lasts only 5 seconds, direct messages only
|
|
96
|
+
*/
|
|
97
|
+
createTyping(req: CreateTypingReq): Promise<CreateTypingResp>;
|
|
98
|
+
/**
|
|
99
|
+
* Clear typing status
|
|
100
|
+
*
|
|
101
|
+
* Direct messages only
|
|
102
|
+
*/
|
|
103
|
+
deleteTyping(req: DeleteTypingReq): Promise<DeleteTypingResp>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Send a message (Request) */
|
|
107
|
+
interface SendMessageReq {
|
|
108
|
+
message_type?: string;
|
|
109
|
+
message_content?: MessageContent;
|
|
110
|
+
chat_id?: string;
|
|
111
|
+
reply_message_id?: string;
|
|
112
|
+
}
|
|
113
|
+
/** Send a message (Response) */
|
|
114
|
+
interface SendMessageResp {
|
|
115
|
+
message_id?: string;
|
|
116
|
+
}
|
|
117
|
+
/** Get a message (Request) */
|
|
118
|
+
interface GetMessageReq {
|
|
119
|
+
message_id?: string;
|
|
120
|
+
}
|
|
121
|
+
/** Get a message (Response) */
|
|
122
|
+
interface GetMessageResp {
|
|
123
|
+
message?: Message$1;
|
|
124
|
+
}
|
|
125
|
+
/** Recall a message (Request) */
|
|
126
|
+
interface RecallMessageReq {
|
|
127
|
+
message_id?: string;
|
|
128
|
+
}
|
|
129
|
+
/** Recall a message (Response) */
|
|
130
|
+
interface RecallMessageResp {
|
|
131
|
+
}
|
|
132
|
+
/** Mark message as read (Request) */
|
|
133
|
+
interface ReadMessageReq {
|
|
134
|
+
message_id?: string;
|
|
135
|
+
}
|
|
136
|
+
/** Mark message as read (Response) */
|
|
137
|
+
interface ReadMessageResp {
|
|
138
|
+
}
|
|
139
|
+
/** Message content */
|
|
140
|
+
interface MessageContent {
|
|
141
|
+
text?: MessageText;
|
|
142
|
+
image?: MessageImage;
|
|
143
|
+
sticker?: MessageSticker;
|
|
144
|
+
video?: MessageVideo;
|
|
145
|
+
audio?: MessageAudio;
|
|
146
|
+
file?: MessageFile;
|
|
147
|
+
user_card?: MessageUserCard;
|
|
148
|
+
group_card?: MessageGroupCard;
|
|
149
|
+
group_announcement?: MessageGroupAnnouncement;
|
|
150
|
+
card?: MessageCard;
|
|
151
|
+
}
|
|
152
|
+
/** Text message */
|
|
153
|
+
interface MessageText {
|
|
154
|
+
content?: string;
|
|
155
|
+
attachment_list?: MessageTextAttachment[];
|
|
156
|
+
mention_user_list?: MessageTextMentionUser[];
|
|
157
|
+
emoji_list?: MessageTextEmoji[];
|
|
158
|
+
}
|
|
159
|
+
/** Attachment */
|
|
160
|
+
interface MessageTextAttachment {
|
|
161
|
+
attachment_id?: string;
|
|
162
|
+
attachment_type?: string;
|
|
163
|
+
attachment_content?: MessageTextAttachmentContent;
|
|
164
|
+
}
|
|
165
|
+
/** Attachment content */
|
|
166
|
+
interface MessageTextAttachmentContent {
|
|
167
|
+
image?: FileImage;
|
|
168
|
+
}
|
|
169
|
+
/** Image file */
|
|
170
|
+
interface FileImage {
|
|
171
|
+
image?: File;
|
|
172
|
+
image_width?: Int64;
|
|
173
|
+
image_height?: Int64;
|
|
174
|
+
image_origin?: File;
|
|
175
|
+
image_origin_width?: Int64;
|
|
176
|
+
image_origin_height?: Int64;
|
|
177
|
+
image_thumb_bytes?: Uint8Array;
|
|
178
|
+
image_thumb_mime?: string;
|
|
179
|
+
image_dominant_color?: string;
|
|
180
|
+
}
|
|
181
|
+
/** File */
|
|
182
|
+
interface File {
|
|
183
|
+
file_id?: string;
|
|
184
|
+
file_mime?: string;
|
|
185
|
+
file_size?: Int64;
|
|
186
|
+
file_encryption?: Encryption;
|
|
187
|
+
}
|
|
188
|
+
/** Encryption */
|
|
189
|
+
interface Encryption {
|
|
190
|
+
encryption_algorithm?: string;
|
|
191
|
+
encryption_key?: Uint8Array;
|
|
192
|
+
encrypted_size?: Int64;
|
|
193
|
+
}
|
|
194
|
+
/** Mentioned user */
|
|
195
|
+
interface MessageTextMentionUser {
|
|
196
|
+
user_id?: UserId;
|
|
197
|
+
user_name?: string;
|
|
198
|
+
is_in_chat?: boolean;
|
|
199
|
+
}
|
|
200
|
+
/** User ID */
|
|
201
|
+
interface UserId {
|
|
202
|
+
user_id?: string;
|
|
203
|
+
union_user_id?: string;
|
|
204
|
+
open_user_id?: string;
|
|
205
|
+
}
|
|
206
|
+
interface MessageTextEmoji {
|
|
207
|
+
emoji_id?: string;
|
|
208
|
+
emoji_name?: string;
|
|
209
|
+
}
|
|
210
|
+
/** Image message */
|
|
211
|
+
interface MessageImage {
|
|
212
|
+
image?: FileImage;
|
|
213
|
+
}
|
|
214
|
+
/** Sticker message */
|
|
215
|
+
interface MessageSticker {
|
|
216
|
+
sticker?: Sticker;
|
|
217
|
+
}
|
|
218
|
+
/** Sticker */
|
|
219
|
+
interface Sticker {
|
|
220
|
+
sticker_id?: string;
|
|
221
|
+
sticker_name?: string;
|
|
222
|
+
sticker_name_i18n?: Record<string, string>;
|
|
223
|
+
sticker_image?: FileImage;
|
|
224
|
+
}
|
|
225
|
+
/** Video message */
|
|
226
|
+
interface MessageVideo {
|
|
227
|
+
video?: FileVideo;
|
|
228
|
+
}
|
|
229
|
+
/** Video file */
|
|
230
|
+
interface FileVideo {
|
|
231
|
+
video?: File;
|
|
232
|
+
video_width?: Int64;
|
|
233
|
+
video_height?: Int64;
|
|
234
|
+
video_duration?: number;
|
|
235
|
+
video_preview?: FileImage;
|
|
236
|
+
}
|
|
237
|
+
/** Audio message */
|
|
238
|
+
interface MessageAudio {
|
|
239
|
+
audio?: FileAudio;
|
|
240
|
+
}
|
|
241
|
+
/** Audio file */
|
|
242
|
+
interface FileAudio {
|
|
243
|
+
audio?: File;
|
|
244
|
+
audio_duration?: number;
|
|
245
|
+
}
|
|
246
|
+
/** File message */
|
|
247
|
+
interface MessageFile {
|
|
248
|
+
file?: File;
|
|
249
|
+
filename?: string;
|
|
250
|
+
}
|
|
251
|
+
/** User card message */
|
|
252
|
+
interface MessageUserCard {
|
|
253
|
+
user_id?: UserId;
|
|
254
|
+
}
|
|
255
|
+
/** Group card message */
|
|
256
|
+
interface MessageGroupCard {
|
|
257
|
+
chat_id?: string;
|
|
258
|
+
}
|
|
259
|
+
/** Group announcement */
|
|
260
|
+
interface MessageGroupAnnouncement {
|
|
261
|
+
message_text?: MessageText;
|
|
262
|
+
}
|
|
263
|
+
/** Card message */
|
|
264
|
+
interface MessageCard {
|
|
265
|
+
schema?: string;
|
|
266
|
+
v1?: MessageCardV1;
|
|
267
|
+
}
|
|
268
|
+
/** V1 */
|
|
269
|
+
interface MessageCardV1 {
|
|
270
|
+
header?: MessageCardV1Header;
|
|
271
|
+
body?: MessageCardV1Body;
|
|
272
|
+
footer?: MessageCardV1Footer;
|
|
273
|
+
}
|
|
274
|
+
/** Card header */
|
|
275
|
+
interface MessageCardV1Header {
|
|
276
|
+
title?: string;
|
|
277
|
+
title_i18n?: Record<string, string>;
|
|
278
|
+
template?: string;
|
|
279
|
+
}
|
|
280
|
+
/** Card body */
|
|
281
|
+
interface MessageCardV1Body {
|
|
282
|
+
message_text?: MessageText;
|
|
283
|
+
message_text_i18n?: Record<string, MessageText>;
|
|
284
|
+
}
|
|
285
|
+
/** Card footer */
|
|
286
|
+
interface MessageCardV1Footer {
|
|
287
|
+
button_list?: MessageCardV1Button[];
|
|
288
|
+
button_align?: string;
|
|
289
|
+
}
|
|
290
|
+
/** Card button */
|
|
291
|
+
interface MessageCardV1Button {
|
|
292
|
+
button_text?: string;
|
|
293
|
+
button_text_i18n?: Record<string, string>;
|
|
294
|
+
template?: string;
|
|
295
|
+
link?: MessageCardV1ButtonLink;
|
|
296
|
+
}
|
|
297
|
+
/** Link */
|
|
298
|
+
interface MessageCardV1ButtonLink {
|
|
299
|
+
url?: string;
|
|
300
|
+
android_url?: string;
|
|
301
|
+
ios_url?: string;
|
|
302
|
+
pc_url?: string;
|
|
303
|
+
}
|
|
304
|
+
/** Message */
|
|
305
|
+
interface Message$1 {
|
|
306
|
+
message_id?: string;
|
|
307
|
+
message_type?: string;
|
|
308
|
+
message_status?: string;
|
|
309
|
+
message_content?: MessageContent;
|
|
310
|
+
message_created_at?: Int64;
|
|
311
|
+
chat_id?: string;
|
|
312
|
+
chat_seq_id?: Int64;
|
|
313
|
+
sender_id?: UserId;
|
|
314
|
+
reply?: MessagePropReply;
|
|
315
|
+
}
|
|
316
|
+
/** Message reply properties */
|
|
317
|
+
interface MessagePropReply {
|
|
318
|
+
reply_message_id?: string;
|
|
319
|
+
}
|
|
320
|
+
/** Message received */
|
|
321
|
+
interface EventMessageReceiveBody {
|
|
322
|
+
message?: Message$1;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Message received */
|
|
326
|
+
interface EventMessageReceive {
|
|
327
|
+
header: EventHeader;
|
|
328
|
+
body: EventMessageReceiveBody;
|
|
329
|
+
}
|
|
330
|
+
declare class MessageEvent {
|
|
331
|
+
private readonly config;
|
|
332
|
+
private readonly handlerMap;
|
|
333
|
+
constructor(config: Config);
|
|
334
|
+
/** Message received */
|
|
335
|
+
onMessageReceive(handler: (event: EventMessageReceive) => void): void;
|
|
336
|
+
offMessageReceive(handler: (event: EventMessageReceive) => void): void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class Message {
|
|
340
|
+
private readonly config;
|
|
341
|
+
readonly Event: MessageEvent;
|
|
342
|
+
constructor(config: Config);
|
|
343
|
+
/** Send a message */
|
|
344
|
+
sendMessage(req: SendMessageReq): Promise<SendMessageResp>;
|
|
345
|
+
/** Get a message */
|
|
346
|
+
getMessage(req: GetMessageReq): Promise<GetMessageResp>;
|
|
347
|
+
/** Recall a message */
|
|
348
|
+
recallMessage(req: RecallMessageReq): Promise<RecallMessageResp>;
|
|
349
|
+
/** Mark message as read */
|
|
350
|
+
readMessage(req: ReadMessageReq): Promise<ReadMessageResp>;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
declare class V1 {
|
|
354
|
+
readonly Chat: Chat;
|
|
355
|
+
readonly Message: Message;
|
|
356
|
+
constructor(config: Config);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
declare class Service {
|
|
360
|
+
readonly v1: V1;
|
|
361
|
+
constructor(config: Config);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
interface CoredClientOptions {
|
|
365
|
+
httpClient?: HttpClient;
|
|
366
|
+
requestTimeout?: number;
|
|
367
|
+
enableEncryption?: boolean;
|
|
368
|
+
logLevel?: LoggerLevel;
|
|
369
|
+
logger?: Logger;
|
|
370
|
+
timeManager?: TimeManager;
|
|
371
|
+
jsonMarshal?: Marshaller;
|
|
372
|
+
jsonUnmarshal?: Unmarshaller;
|
|
373
|
+
}
|
|
374
|
+
declare class CoredClient {
|
|
375
|
+
readonly config: Config;
|
|
376
|
+
readonly apiClient: ApiClient;
|
|
377
|
+
readonly Im: Service;
|
|
378
|
+
private constructor();
|
|
379
|
+
static create(backendUrl: string, appId: string, appSecret: string, options?: CoredClientOptions): Promise<CoredClient>;
|
|
380
|
+
preheat(): Promise<void>;
|
|
381
|
+
close(): Promise<void>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
declare const VERSION = "0.28.102";
|
|
385
|
+
declare const USER_AGENT = "cored-openapi-sdk-js/0.28.102";
|
|
386
|
+
|
|
387
|
+
export { type ApiClient, type ApiError, type ApiRequest, type ApiResponse, type Config, CoredClient, type CoredClientOptions, type EventHeader, type HttpClient, type Int64, type Logger, LoggerLevel, type TimeManager, USER_AGENT, VERSION };
|