-
Notifications
You must be signed in to change notification settings - Fork 21
/
PluginAPI.js
66 lines (57 loc) · 1.5 KB
/
PluginAPI.js
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
import http from 'cf-util-http';
import {
v4ResponseOk,
v4Callback
} from '../../utils/CFClientV4API/CFClientV4API';
/*
* This endpoint isn't real but we'll use it to identify REST calls for
* plugin specific functionality like saving a v4 API key/email or toggling
* admin settings. The structure of this API's responses will mimic the client V4 API.
*/
const ENDPOINT = 'https://partners.cloudflare/plugins';
/*
* Indicates api call success
*
* @param {Object} [response]
*
* @returns {Boolean} Successful
*/
export function pluginResponseOk(response) {
return v4ResponseOk(response);
}
export function pluginCallback(callback) {
return v4Callback(callback);
}
export function pluginAccountPost(email, apiKey, callback) {
let opts = {
body: {
email: email.toString().trim(),
apiKey: apiKey.toString().trim()
}
};
return http.post(ENDPOINT + '/account/', opts, pluginCallback(callback));
}
export function pluginSettingListGet(zoneId, callback) {
let opts = {};
return http.get(
ENDPOINT + '/plugin/' + zoneId['zoneId'] + '/settings/',
opts,
pluginCallback(callback)
);
}
export function pluginSettingPatch(zoneId, settingName, value, callback) {
let opts = {
body: {
value: value
}
};
return http.patch(
ENDPOINT + '/plugin/' + zoneId + '/settings/' + settingName,
opts,
pluginCallback(callback)
);
}
export function configGet(callback) {
let opts = {};
return http.get(ENDPOINT + '/config/', opts, pluginCallback(callback));
}