@satorijs/adapter-lark 3.7.0 → 3.7.2
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/lib/index.cjs +48 -21
- package/lib/index.cjs.map +2 -2
- package/lib/types/api.d.ts +348 -52
- package/lib/types/internal.d.ts +6 -4
- package/package.json +1 -1
- package/src/message.ts +35 -17
- package/src/types/api.ts +349 -53
- package/src/types/internal.ts +18 -6
package/src/types/internal.ts
CHANGED
|
@@ -10,7 +10,10 @@ export interface BaseResponse {
|
|
|
10
10
|
msg: string
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export interface InternalConfig {
|
|
14
|
+
multipart?: boolean
|
|
15
|
+
noExtractData?: boolean
|
|
16
|
+
}
|
|
14
17
|
|
|
15
18
|
export class Internal {
|
|
16
19
|
constructor(private bot: LarkBot) {}
|
|
@@ -23,10 +26,10 @@ export class Internal {
|
|
|
23
26
|
throw error
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
static define(routes: Dict<Partial<Record<Method, string | string[]>>>,
|
|
29
|
+
static define(routes: Dict<Partial<Record<HTTP.Method, string | string[]>>>, options: InternalConfig = {}) {
|
|
27
30
|
for (const path in routes) {
|
|
28
31
|
for (const key in routes[path]) {
|
|
29
|
-
const method = key as Method
|
|
32
|
+
const method = key as HTTP.Method
|
|
30
33
|
for (const name of makeArray(routes[path][method])) {
|
|
31
34
|
Internal.prototype[name] = async function (this: Internal, ...args: any[]) {
|
|
32
35
|
const raw = args.join(', ')
|
|
@@ -42,14 +45,23 @@ export class Internal {
|
|
|
42
45
|
config.data = args[0]
|
|
43
46
|
}
|
|
44
47
|
} else if (args.length === 2 && method !== 'GET' && method !== 'DELETE') {
|
|
45
|
-
|
|
48
|
+
if (options.multipart) {
|
|
49
|
+
const form = new FormData()
|
|
50
|
+
for (const key in args[0]) {
|
|
51
|
+
const value = args[0][key]
|
|
52
|
+
form.append(key, value, value instanceof File ? value.name : undefined)
|
|
53
|
+
}
|
|
54
|
+
config.data = form
|
|
55
|
+
} else {
|
|
56
|
+
config.data = args[0]
|
|
57
|
+
}
|
|
46
58
|
config.params = args[1]
|
|
47
59
|
} else if (args.length > 1) {
|
|
48
60
|
throw new Error(`too many arguments for ${path}, received ${raw}`)
|
|
49
61
|
}
|
|
50
62
|
const response = await this.bot.http(method, url, config)
|
|
51
|
-
this.assertResponse(response
|
|
52
|
-
return
|
|
63
|
+
this.assertResponse(response)
|
|
64
|
+
return options.noExtractData ? response.data : response.data.data
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
67
|
}
|