-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
310 lines (285 loc) · 9.07 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/* eslint-disable */
interface Window {
/**
* APIs available for Rulia plugins.
*/
Rulia: {
/**
* Write a log message.
* This function is available from 0.18.0.
*/
log: (level: string, message: string) => void
/**
* End execution of current plugin context without returning any data.
*/
end: () => void
/**
* End execution of current plugin context with some data returned.
*
* @param payload Data passed to Rulia.
*/
endWithResult: (payload: any) => void
/**
* End execution of current plugin context with raising an exception.
*
* @param errorMsg Error message.
*/
endWithException: (errorMsg: string) => void
/**
* Make an app toast.
* You can use this function to tell user something if you need to.
*
* @param message Toast message.
*/
appToast: (message: string) => void
/**
* Make a http request.
*
* @example
* // 1. Make a get request.
* // ===========================================
* const payload = new URLSearchParams()
* payload.append('region', 'japan')
* payload.append('keyword', 'school')
*
* const rawResponse = await window.Rulia.httpRequest({
* url: 'https://example.com/v1/comic-list',
* method: 'GET',
* payload: payload.toString() // 'region=japan&keyword=school'
* })
*
* // If the response is JSON.
* const response = JSON.parse(rawResponse)
*
* @example
* // 1.5 Make a get request and get both headers and response.
* // ===========================================
* const payload = new URLSearchParams()
* payload.append('region', 'japan')
* payload.append('keyword', 'school')
*
* const rawResponse = await window.Rulia.httpRequest({
* url: 'https://example.com/v1/comic-list',
* method: 'GET',
* payload: payload.toString(), // 'region=japan&keyword=school'
* responseWithHeaders: true // Be aware of this.
* })
*
* const { data, headers } = JSON.parse(rawResponse)
* console.log(headers) // { 'content-type': 'application/json', ... }
*
* // If the response is JSON.
* const response = JSON.parse(data)
*
* @example
* // 2. Make a post request in the form of the "application/json".
* // ===========================================
* const payload = {
* name: 'John Smith',
* age: 100
* }
* const rawResponse = await window.Rulia.httpRequest({
* url: 'https://example.com/v1/add-user',
* method: 'POST',
* payload: JSON.stringify(payload),
* contentType: 'application/json'
* })
*
* // If your response is some kind of customized string, just use it.
* const response = rawResponse
*
* @example
* // 3. Make a post request in the form of the "application/x-www-form-urlencoded".
* // ===========================================
* const payload = new URLSearchParams()
* payload.append('name', 'John Smith')
* payload.append('age', 100)
*
* const rawResposne = await window.Rulia.httpRequest({
* url: 'https://example.com/v1/add-user',
* method: 'POST',
* payload: payload.toString(),
* contentType: 'application/x-www-form-urlencoded'
* })
*
* @example
* // 4. Make a post request with your custom type.
* // ===========================================
* const rawResponse = await window.Rulia.httpRequest({
* url: 'https://example.com/some/api/requires/xml',
* method: 'POST',
* payload: '<user><name>John Smith</name><age>100</age></user>', // Let's say the server requires a piece of XML.
* contentType: 'application/must-be-written-in-this-way' // The required content type by the server.
* })
*
* // For an example, the sever responses a YAML string.
* const myYAML = parseYAML(rawResponse)
*/
httpRequest: (params: {
/**
* Request URL.
*/
url: string
/**
* Http method.
*/
method: string
/**
* Requested data.
* It only accepts string, thus you have to serialize it into string by yourself.
* Check the example above to see how to do this.
*/
payload?: string
/**
* Content type of the request.
* It should be somthing that the server asks for.
*/
contentType?: string
/**
* Timeout for the request. Milliseconds.
* No default setting.
* This parameter is available from 0.15.0.
*/
timeout?: number
/**
* Custom headers.
* This option is available from 0.17.0.
*/
headers?: Record<string, string>
/**
* Whether to response with headers.
* If this option is set to true, the response will be a JSON string with two fields: "headers" and "data".
* If this option is set to false, the response will be the data itself.
*
* This option is available from 0.18.0.
*
* @example If the server responses a JSON { name: 'Doge' }.
*
* const rawResponse = await window.Rulia.httpRequest({ ... })
* const data = JSON.parse(rawResponse) // { name: 'Doge' }
*
* const rawResponse = await window.Rulia.httpRequest({ ..., responseWithHeaders: true })
* const response = JSON.parse(rawResponse) // { data: '{ "nane": "Doge" }', headers: { 'content-type': 'application/json', ... }
* const data = JSON.parse(response.data) // { name: 'Doge' }
* const headers = response.headers // { 'content-type': 'application/json', ... }
*
* @example If the server responses a piece of XML: '<user><name>Doge</name></user>'
*
* const data = await window.Rulia.httpRequest({ ... }) // '<user><name>Doge</name></user>'
*
* const rawResponse = await window.Rulia.httpRequest({ ..., responseWithHeaders: true })
* const response = JSON.parse(rawResponse) // { data: '<user><name>Doge</name></user>', headers: { 'content-type': 'application/xml', ... }
* const data = response.data // '<user><name>Doge</name></user>'
* const headers = response.headers // { 'content-type': 'application/xml', ... }
*/
responseWithHeaders?: boolean
}) => Promise<string>
/**
* Get app version. Maybe you need it.
*
* @returns {string} Version string.
*/
getAppVersion: () => string
/**
* Get user config of the plugin.
* User config fields are defined in the section "userConfig" in the package.json.
*/
getUserConfig: () => Record<string, string>
/**
* This local storage API just acts exactly as the same as the one in browsers.
* The data will be persisted in Rulia.
* Available from 0.15.0.
*/
localStorage: {
getItem: (key: string) => string | undefined
setItem: (key: string, value: string) => void
},
/**
* This session storage API just acts exactly the same as the one in browser.
* Your data will be lost after users close the Rulia.
* Available from 0.15.0.
*/
sessionStorage: {
getItem: (key: string) => string | undefined
setItem: (key: string, value: string) => void
},
/**
* Get all cookies from Rulia.
* These cookies are available after the user logs in through WebView.
* This function is available from 0.18.0.
*/
getCookies: () => Promise<{
Name: string
Path: string
Domain: string
Value: string
Expires: string
HttpOnly: boolean
Secure: boolean
}[]>
}
}
/**
* This is the data type that you need to pass to Rulia
* in function "getMangaList".
*/
interface IGetMangaListResult {
list: {
title: string
url: string
coverUrl: string
}[]
}
/**
* This is the data type that you need to pass to Rulia
* in function "getMangaData".
*/
interface IGetMangaDataResult {
title: string
description: string
coverUrl: string
/**
* Chapter list.
* If you need to make a pagination, assign "chapterListTotalPage" and
* leave "chapterList" an empty array.
*/
chapterList: {
title: string
url: string
}[]
/**
* If this field is provided, the app will make a pagination
* for the chapter list.
* You only need to provide either "chapterListTotalPage" or "chapterList".
*
* Available from 0.22.0.
*/
chapterListTotalPage?: number
/**
* There will be a continue button if you provide this information.
*/
lastReadChapter?: {
title: string
url: string
}
}
/**
* This is the image data for each single image.
*/
interface IRuliaChapterImage {
url: string
width: number
height: number
}
/**
* This is the type of filter options in manga list page.
*/
interface IRuliaMangaListFilterOption {
label: string
name: string | number
options: Array<{ label: string, value: string }>
}
/**
* This is the data type that should be returned in function "setMangaListFilterOptions".
*/
type IRuliaMangaListFilterOptions = IRuliaMangaListFilterOption[]