-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
92 lines (76 loc) · 2.08 KB
/
api.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
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
'use strict';
const Cache = require('./cache');
const now = require('./requests').now;
let API = {
/**
* @param {String} deployId
* @param {String} alias
* @return {Promise<Object, Object>}
*/
alias: (deployId, alias) => now(`deployments/${deployId}/aliases`, {
method: 'POST',
body: JSON.stringify({alias: alias})
}),
/** @return {Promise<Array, Object>} */
aliases: () => now('aliases').then(data => data && data.aliases || []),
/**
* @param {String} aliasId
* @return {Promise<Object, Object>}
*/
deleteAlias: aliasId => now(`aliases/${aliasId}`, {method: 'DELETE'}),
/**
* @param {Object} contents
* @return {Promise<Object, Object>}
*/
deploy: contents => now('deployments', {
method: 'POST',
body: JSON.stringify(contents)
}),
/** @return {Promise<Array, Object>} */
deployments: () => now('deployments').then(data => data && data.deployments || []),
/**
* @param {String} deployId
* @return {Promise<Object, Object>}
*/
deployment: deployId => now(`deployments/${deployId}`),
/**
* @param {String} deployId
* @return {Promise<Object, Object>}
*/
deleteDeployment: deployId => now(`deployments/${deployId}`, {method: 'DELETE'}),
/**
* @param {String} deployId
* @param {String} fileId
* @return {Promise<Object, Object>}
*/
file: (deployId, fileId) => now(`deployments/${deployId}/files/${fileId}`),
/**
* @param {String} deployId
* @return {Promise<Array, Object>}
*/
files: deployId => now(`deployments/${deployId}/files`),
/** @return {Promise<Boolean, Object>} */
ok: () => now('aliases').then(() => true),
/**
* @param {String} token
* @return {Object} the API itself
*/
setToken: token => {
// Guarantee that the token is set before moving on.
(function* setToken() {
yield Cache.set(Cache.TOKEN, token);
})().next();
return API;
}
}
API.RESPONSE_STATUS = {
SUCCESS: 'SUCCESS'
};
API.DEPLOY_STATUS = {
BOOTED: 'BOOTED',
BOOTING: 'BOOTING',
DELETED: 'DELETED',
READY: 'READY',
FROZEN: 'FROZEN'
};
module.exports = API;