-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.d.ts
More file actions
82 lines (82 loc) · 2.06 KB
/
Copy pathmain.d.ts
File metadata and controls
82 lines (82 loc) · 2.06 KB
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
export type CCWResult = {
body: any;
code: string;
msg: string | null;
status: number;
};
export type CCWFetchResponse = Omit<Response, 'json'> & {
json(): Promise<CCWResult>;
};
/**
* @typedef {{
* body: any,
* code: string,
* msg: string | null,
* status: number,
* }} CCWResult
*
* @typedef {Omit<Response, 'json'> & {
* json(): Promise<CCWResult>
* }} CCWFetchResponse
*/
declare class CCWFetch {
/**
* 强制使用指定token。
*/
token: string;
/**
* 是否允许使用 guest-id。
* 如果该值为 false,则在未登录时不会尝试使用 guest-id。
* 仅在 token 属性为空时有效。
*/
allowGuestId: boolean;
/**
* [内部]
* 签名密钥。
* 使用 healthCheck 以更新签名密钥。
*/
_hmacKey: string;
/**
* [内部]
* 是否使用guest-id。
*/
_usingGuestId: boolean;
/**
* [内部]
* guest-id。
* 使用 healthCheck 以生成 guest-id。
*/
_guestId: string;
/**
* 更新签名密钥。
* 失败会抛出错误。
*/
healthCheck(url?: string): Promise<void>;
/**
* 请求 CCW API 。
* 如果有 body 但还没获取 hmacKey,会自动调用 healthCheck 函数。
*
* @param {string} method
* @param {string | URL} url
* @param {string | {[key: string]: any} | null} [body]
* @param {RequestInit} [init]
* @returns {Promise<CCWFetchResponse>}
*/
fetch(method: string, url: string | URL, body?: string | {
[key: string]: any;
} | null, init?: RequestInit): Promise<CCWFetchResponse>;
/**
* @param {string} url
* @param {string | {[key: string]: any} | null} [body]
* @param {RequestInit} [init]
*/
POST(url: string, body?: string | {
[key: string]: any;
} | null, init?: RequestInit): Promise<CCWFetchResponse>;
/**
* @param {string} url
* @param {RequestInit} [init]
*/
GET(url: string, init?: RequestInit): Promise<CCWFetchResponse>;
}
export default CCWFetch;