@cobaltio/cobalt-js 0.1.1 → 1.0.1
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/README.md +105 -210
- package/cobalt.js +103 -200
- package/cobalt.min.js +1 -1
- package/docs.md +104 -209
- package/package.json +1 -2
package/cobalt.js
CHANGED
|
@@ -1,141 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cobalt Frontend SDK
|
|
3
|
+
* @property {String} token The session token.
|
|
3
4
|
*/
|
|
4
5
|
class Cobalt {
|
|
5
6
|
/**
|
|
6
7
|
* Cobalt Frontend SDK
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
8
|
+
* @param {Object} options The options to configure the Cobalt SDK.
|
|
9
|
+
* @param {String} [options.token] The session token.
|
|
10
|
+
* @param {String} [options.baseUrl=https://api.gocobalt.io] The base URL of the Cobalt API.
|
|
10
11
|
*/
|
|
11
12
|
constructor(options) {
|
|
12
|
-
this.
|
|
13
|
+
this.baseUrl = options?.baseUrl || "https://api.gocobalt.io";
|
|
13
14
|
this.token = options?.token;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
/**
|
|
17
|
-
* @returns {string} The session token.
|
|
18
|
-
*/
|
|
19
17
|
get token() {
|
|
20
18
|
return this.sessionToken;
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
/**
|
|
24
|
-
* @returns {string} The session token.
|
|
25
|
-
*/
|
|
26
21
|
set token(token) {
|
|
27
22
|
return this.sessionToken = typeof token === "string" ? token : "";
|
|
28
23
|
};
|
|
29
24
|
|
|
30
|
-
/**
|
|
31
|
-
* @returns {string} The base URL of cobalt API.
|
|
32
|
-
*/
|
|
33
|
-
get baseUrl() {
|
|
34
|
-
return this.apiBaseUrl;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @typedef {object} Field The Node Field object available for configuration.
|
|
39
|
-
* @property {string} name The field name.
|
|
40
|
-
* @property {string} type The input type of the field.
|
|
41
|
-
* @property {string} placeholder The placeholder text for the field.
|
|
42
|
-
* @property {boolean} required Whether the field is required.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @typedef {object} Node The Node object available for configuration.
|
|
47
|
-
* @property {string} node_id The ID of the installed workflow.
|
|
48
|
-
* @property {string} node_name The Name of the installed workflow.
|
|
49
|
-
* @property {Field[]} fields The applications integrated in the workflow.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @typedef {object} Workflow The installed workflow.
|
|
54
|
-
* @property {string} workflow_id The ID of the installed workflow.
|
|
55
|
-
* @property {unknown[]} applications The applications integrated in the workflow.
|
|
56
|
-
* @property {Node[]} configure The configuration data for the workflow.
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @typedef {object} AppAuthStatus The auth status of the user for an application.
|
|
61
|
-
* @property {boolean} status Whether the user has authenticated with this application.
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @typedef {object} AppConfig The configuration data for an application.
|
|
66
|
-
* @property {DataSlot[]} application_data_slots Array of application data slots.
|
|
67
|
-
* @property {Template[]} templates Array of workflow templates.
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Install the given template.
|
|
72
|
-
* @property {string} templateId The ID of the template you want to install.
|
|
73
|
-
* @property {object} udf Custom key value pairs you want to store with the installed worklfow.
|
|
74
|
-
* @returns {Promise<Workflow>}
|
|
75
|
-
*/
|
|
76
|
-
async installTemplate(templateId, udf = {}) {
|
|
77
|
-
const res = await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`, {
|
|
78
|
-
method: "POST",
|
|
79
|
-
headers: {
|
|
80
|
-
authorization: `Bearer ${this.token}`,
|
|
81
|
-
"content-type": "application/json",
|
|
82
|
-
},
|
|
83
|
-
body: JSON.stringify({ udf }),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
if (res.status >= 400 && res.status < 600) {
|
|
87
|
-
throw new Error(res.statusText);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return await res.json();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Returns the configuration data for the specified application.
|
|
95
|
-
* @param {string} application The application ID.
|
|
96
|
-
* @returns {Promise<AppConfig>} The specified application's configuration data.
|
|
97
|
-
*/
|
|
98
|
-
async getAppConfig(application) {
|
|
99
|
-
const res = await fetch(`${this.baseUrl}/api/v1/application/${application}/config`, {
|
|
100
|
-
headers: {
|
|
101
|
-
authorization: `Bearer ${this.token}`,
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (res.status >= 400 && res.status < 600) {
|
|
106
|
-
throw new Error(res.statusText);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return await res.json();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Returns the auth status of the user for the specified application.
|
|
114
|
-
* @property {string} application The application type.
|
|
115
|
-
* @returns {Promise<boolean>} The auth status of the user.
|
|
116
|
-
*/
|
|
117
|
-
async getAppAuthStatus(application) {
|
|
118
|
-
const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`, {
|
|
119
|
-
headers: {
|
|
120
|
-
authorization: `Bearer ${this.token}`,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (res.status >= 400 && res.status < 600) {
|
|
125
|
-
throw new Error(res.statusText);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const data = await res.json();
|
|
129
|
-
return !!data?.status;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
25
|
/**
|
|
133
26
|
* Returns the auth URL that users can use to authenticate themselves to the
|
|
134
27
|
* specified application.
|
|
135
|
-
* @
|
|
136
|
-
* @
|
|
28
|
+
* @private
|
|
29
|
+
* @param {String} application The application type.
|
|
30
|
+
* @returns {Promise<String>} The auth URL where users can authenticate themselves.
|
|
137
31
|
*/
|
|
138
|
-
async
|
|
32
|
+
async getOAuthUrl(application) {
|
|
139
33
|
const res = await fetch(`${this.baseUrl}/api/v1/${application}/integrate`, {
|
|
140
34
|
headers: {
|
|
141
35
|
authorization: `Bearer ${this.token}`,
|
|
@@ -151,19 +45,19 @@ class Cobalt {
|
|
|
151
45
|
}
|
|
152
46
|
|
|
153
47
|
/**
|
|
154
|
-
* Handle OAuth for the specified application.
|
|
155
|
-
* @
|
|
156
|
-
* @returns {Promise<
|
|
48
|
+
* Handle OAuth for the specified native application.
|
|
49
|
+
* @param {String} application The application type.
|
|
50
|
+
* @returns {Promise<Boolean>} Whether the user authenticated.
|
|
157
51
|
*/
|
|
158
52
|
async oauth(application) {
|
|
159
53
|
return new Promise((resolve, reject) => {
|
|
160
|
-
this.
|
|
54
|
+
this.getOAuthUrl(application)
|
|
161
55
|
.then(oauthUrl => {
|
|
162
56
|
const connectWindow = window.open(oauthUrl);
|
|
163
57
|
|
|
164
58
|
// keep checking connection status
|
|
165
59
|
const interval = setInterval(() => {
|
|
166
|
-
this.
|
|
60
|
+
this.checkAuth(application)
|
|
167
61
|
.then(connected => {
|
|
168
62
|
if (connected === true) {
|
|
169
63
|
// close auth window
|
|
@@ -195,14 +89,13 @@ class Cobalt {
|
|
|
195
89
|
|
|
196
90
|
/**
|
|
197
91
|
* Save the auth data that user provides to authenticate themselves to the
|
|
198
|
-
* specified application.
|
|
199
|
-
* @
|
|
200
|
-
* @
|
|
201
|
-
* @
|
|
202
|
-
* @returns {Promise<void>}
|
|
92
|
+
* specified native application.
|
|
93
|
+
* @param {String} application The application type.
|
|
94
|
+
* @param {Object.<string, string | number | boolean>} payload The key value pairs of auth data.
|
|
95
|
+
* @returns {Promise<unknown>}
|
|
203
96
|
*/
|
|
204
|
-
async
|
|
205
|
-
const res = await fetch(
|
|
97
|
+
async auth(application, payload) {
|
|
98
|
+
const res = await fetch(`${this.baseUrl}/api/v1/${application}/save`, {
|
|
206
99
|
method: "POST",
|
|
207
100
|
headers: {
|
|
208
101
|
authorization: `Bearer ${this.token}`,
|
|
@@ -222,93 +115,84 @@ class Cobalt {
|
|
|
222
115
|
}
|
|
223
116
|
|
|
224
117
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* @
|
|
228
|
-
* @
|
|
118
|
+
* Save the auth data that user provides to authenticate themselves to the
|
|
119
|
+
* specified custom application.
|
|
120
|
+
* @param {String} applicationId The application ID of the custom application.
|
|
121
|
+
* @param {Object.<string, string | number | boolean>} payload The key value pairs of auth data.
|
|
122
|
+
* @returns {Promise<unknown>}
|
|
229
123
|
*/
|
|
230
|
-
async
|
|
231
|
-
const res = await fetch(`${this.baseUrl}/api/v1/
|
|
232
|
-
method: "
|
|
124
|
+
async authCustom(applicationId, payload) {
|
|
125
|
+
const res = await fetch(`${this.baseUrl}/api/v1/custom/${applicationId}/save`, {
|
|
126
|
+
method: "POST",
|
|
233
127
|
headers: {
|
|
234
128
|
authorization: `Bearer ${this.token}`,
|
|
129
|
+
"content-type": "application/json",
|
|
235
130
|
},
|
|
131
|
+
body: JSON.stringify({
|
|
132
|
+
...payload,
|
|
133
|
+
}),
|
|
236
134
|
});
|
|
237
135
|
|
|
238
136
|
if (res.status >= 400 && res.status < 600) {
|
|
239
137
|
throw new Error(res.statusText);
|
|
240
138
|
}
|
|
139
|
+
|
|
140
|
+
const data = await res.json();
|
|
141
|
+
return data;
|
|
241
142
|
}
|
|
242
143
|
|
|
243
144
|
/**
|
|
244
|
-
* Returns the
|
|
245
|
-
* @
|
|
246
|
-
* @
|
|
247
|
-
* @property {string} fieldName The field name for which config data is required.
|
|
248
|
-
* @property {object} selectedValues The input data already selected for the node.
|
|
249
|
-
* @returns {Promise<Field[]>}
|
|
145
|
+
* Returns the auth status of the user for the specified application.
|
|
146
|
+
* @param {String} application The application type.
|
|
147
|
+
* @returns {Promise<Boolean>} The auth status of the user.
|
|
250
148
|
*/
|
|
251
|
-
async
|
|
252
|
-
const res = await fetch(`${this.baseUrl}/api/v1/
|
|
253
|
-
method: "POST",
|
|
149
|
+
async checkAuth(application) {
|
|
150
|
+
const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`, {
|
|
254
151
|
headers: {
|
|
255
152
|
authorization: `Bearer ${this.token}`,
|
|
256
|
-
"content-type": "application/json",
|
|
257
153
|
},
|
|
258
|
-
body: JSON.stringify({
|
|
259
|
-
fieldName,
|
|
260
|
-
selectedValues,
|
|
261
|
-
}),
|
|
262
154
|
});
|
|
263
155
|
|
|
264
156
|
if (res.status >= 400 && res.status < 600) {
|
|
265
157
|
throw new Error(res.statusText);
|
|
266
158
|
}
|
|
267
159
|
|
|
268
|
-
|
|
160
|
+
const data = await res.json();
|
|
161
|
+
return !!data?.status;
|
|
269
162
|
}
|
|
270
163
|
|
|
271
164
|
/**
|
|
272
|
-
*
|
|
273
|
-
* @
|
|
274
|
-
* @
|
|
275
|
-
* @
|
|
276
|
-
* @returns {Promise<Workflow>}
|
|
165
|
+
* Unauthorize the specified application and remove any associated data from Cobalt.
|
|
166
|
+
* @param {String} application The application type.
|
|
167
|
+
* @param {String} [applicationId] The application ID in case of custom applications.
|
|
168
|
+
* @returns {Promise<void>}
|
|
277
169
|
*/
|
|
278
|
-
async
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
if (Object.hasOwnProperty.call(inputData, key)) {
|
|
282
|
-
const value = inputData[key];
|
|
283
|
-
payload[key] = { value };
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`, {
|
|
288
|
-
method: "PUT",
|
|
170
|
+
async removeAuth(application, applicationId) {
|
|
171
|
+
const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${applicationId}`, {
|
|
172
|
+
method: "DELETE",
|
|
289
173
|
headers: {
|
|
290
174
|
authorization: `Bearer ${this.token}`,
|
|
291
|
-
"content-type": "application/json",
|
|
292
175
|
},
|
|
293
|
-
body: JSON.stringify({
|
|
294
|
-
input_data: payload,
|
|
295
|
-
}),
|
|
296
176
|
});
|
|
297
177
|
|
|
298
178
|
if (res.status >= 400 && res.status < 600) {
|
|
299
179
|
throw new Error(res.statusText);
|
|
300
180
|
}
|
|
301
|
-
|
|
302
|
-
return await res.json();
|
|
303
181
|
}
|
|
304
182
|
|
|
305
183
|
/**
|
|
306
|
-
*
|
|
307
|
-
* @property {
|
|
308
|
-
* @
|
|
184
|
+
* @typedef {object} AppConfig The configuration data for an application.
|
|
185
|
+
* @property {DataSlot[]} application_data_slots Array of application data slots.
|
|
186
|
+
* @property {Workflow[]} workflows Array of workflows.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Returns the configuration data for the specified application.
|
|
191
|
+
* @param {String} application The application ID.
|
|
192
|
+
* @returns {Promise<AppConfig>} The specified application's configuration data.
|
|
309
193
|
*/
|
|
310
|
-
async
|
|
311
|
-
const res = await fetch(`${this.baseUrl}/api/
|
|
194
|
+
async getAppConfig(application) {
|
|
195
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${application}/config`, {
|
|
312
196
|
headers: {
|
|
313
197
|
authorization: `Bearer ${this.token}`,
|
|
314
198
|
},
|
|
@@ -322,16 +206,33 @@ class Cobalt {
|
|
|
322
206
|
}
|
|
323
207
|
|
|
324
208
|
/**
|
|
325
|
-
*
|
|
326
|
-
* @property {
|
|
327
|
-
* @
|
|
209
|
+
* @typedef {Object} AppInstance An installed application.
|
|
210
|
+
* @property {String} [installation_id] Unique ID for the installation.
|
|
211
|
+
* @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
|
|
212
|
+
* @property {Workflow[]} workflows Whether the workflow is enabled.
|
|
328
213
|
*/
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @typedef {Object} Workflow The workflow.
|
|
217
|
+
* @property {String} id The ID of the workflow.
|
|
218
|
+
* @property {Boolean} enabled Whether the workflow is enabled.
|
|
219
|
+
* @property {Object.<string, string | number | boolean>} data_slots A map of workflow's data slots and their values.
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Install the specified application.
|
|
224
|
+
* @param {String} applicationId The application ID.
|
|
225
|
+
* @param {AppInstance} payload The install payload.
|
|
226
|
+
* @returns {Promise<AppInstance>} The specified application installation.
|
|
227
|
+
*/
|
|
228
|
+
async install(applicationId, payload = {}) {
|
|
229
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/install`, {
|
|
230
|
+
method: "POST",
|
|
332
231
|
headers: {
|
|
333
232
|
authorization: `Bearer ${this.token}`,
|
|
233
|
+
"content-type": "application/json",
|
|
334
234
|
},
|
|
235
|
+
body: JSON.stringify(payload),
|
|
335
236
|
});
|
|
336
237
|
|
|
337
238
|
if (res.status >= 400 && res.status < 600) {
|
|
@@ -342,19 +243,16 @@ class Cobalt {
|
|
|
342
243
|
}
|
|
343
244
|
|
|
344
245
|
/**
|
|
345
|
-
*
|
|
346
|
-
* @
|
|
347
|
-
* @
|
|
246
|
+
* Returns the specified application installation.
|
|
247
|
+
* @param {String} applicationId The application ID.
|
|
248
|
+
* @param {String} installationId The installation ID of the application instance.
|
|
249
|
+
* @returns {Promise<AppInstance>} The specified application installation.
|
|
348
250
|
*/
|
|
349
|
-
async
|
|
350
|
-
const res = await fetch(`${this.baseUrl}/api/
|
|
351
|
-
method: "PUT",
|
|
251
|
+
async getInstallation(applicationId, installationId) {
|
|
252
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`, {
|
|
352
253
|
headers: {
|
|
353
254
|
authorization: `Bearer ${this.token}`,
|
|
354
255
|
},
|
|
355
|
-
body: JSON.stringify({
|
|
356
|
-
workflow_ids: workflowIds,
|
|
357
|
-
}),
|
|
358
256
|
});
|
|
359
257
|
|
|
360
258
|
if (res.status >= 400 && res.status < 600) {
|
|
@@ -365,16 +263,20 @@ class Cobalt {
|
|
|
365
263
|
}
|
|
366
264
|
|
|
367
265
|
/**
|
|
368
|
-
*
|
|
369
|
-
* @
|
|
370
|
-
* @
|
|
266
|
+
* Update the specified application installation.
|
|
267
|
+
* @param {String} applicationId The application ID.
|
|
268
|
+
* @param {String} installationId The installation ID of the application instance.
|
|
269
|
+
* @param {AppInstance} payload The update payload.
|
|
270
|
+
* @returns {Promise<AppInstance>} The specified application installation.
|
|
371
271
|
*/
|
|
372
|
-
async
|
|
373
|
-
const res = await fetch(`${this.baseUrl}/api/
|
|
272
|
+
async updateInstallation(applicationId, installationId, payload = {}) {
|
|
273
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`, {
|
|
374
274
|
method: "PUT",
|
|
375
275
|
headers: {
|
|
376
276
|
authorization: `Bearer ${this.token}`,
|
|
277
|
+
"content-type": "application/json",
|
|
377
278
|
},
|
|
279
|
+
body: JSON.stringify(payload),
|
|
378
280
|
});
|
|
379
281
|
|
|
380
282
|
if (res.status >= 400 && res.status < 600) {
|
|
@@ -385,12 +287,13 @@ class Cobalt {
|
|
|
385
287
|
}
|
|
386
288
|
|
|
387
289
|
/**
|
|
388
|
-
* Delete the specified
|
|
389
|
-
* @
|
|
290
|
+
* Delete the specified installation.
|
|
291
|
+
* @param {String} applicationId The application ID.
|
|
292
|
+
* @param {String} installationId The installation ID of the application instance.
|
|
390
293
|
* @returns {Promise<unknown>}
|
|
391
294
|
*/
|
|
392
|
-
async
|
|
393
|
-
const res = await fetch(`${this.baseUrl}/api/v1/
|
|
295
|
+
async deleteInstallation(applicationId, installationId) {
|
|
296
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`, {
|
|
394
297
|
method: "DELETE",
|
|
395
298
|
headers: {
|
|
396
299
|
authorization: `Bearer ${this.token}`,
|
package/cobalt.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Cobalt{constructor(options){this.
|
|
1
|
+
class Cobalt{constructor(options){this.baseUrl=options?.baseUrl||"https://api.gocobalt.io";this.token=options?.token}get token(){return this.sessionToken}set token(token){return this.sessionToken=typeof token==="string"?token:""}async getOAuthUrl(application){const res=await fetch(`${this.baseUrl}/api/v1/${application}/integrate`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return data?.auth_url}async oauth(application){return new Promise((resolve,reject)=>{this.getOAuthUrl(application).then(oauthUrl=>{const connectWindow=window.open(oauthUrl);const interval=setInterval(()=>{this.checkAuth(application).then(connected=>{if(connected===true){connectWindow?.close();clearInterval(interval);resolve(true)}else{if(connectWindow?.closed){clearInterval(interval);resolve(false)}}}).catch(e=>{console.error(e);clearInterval(interval);reject(e)})},3e3)}).catch(reject)})}async auth(application,payload){const res=await fetch(`${this.baseUrl}/api/v1/${application}/save`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({...payload})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return data}async authCustom(applicationId,payload){const res=await fetch(`${this.baseUrl}/api/v1/custom/${applicationId}/save`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({...payload})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return data}async checkAuth(application){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return!!data?.status}async removeAuth(application,applicationId){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${applicationId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}}async getAppConfig(application){const res=await fetch(`${this.baseUrl}/api/v1/application/${application}/config`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async install(applicationId,payload={}){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/install`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify(payload)});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async getInstallation(applicationId,installationId){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async updateInstallation(applicationId,installationId,payload={}){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify(payload)});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async deleteInstallation(applicationId,installationId){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}}module.exports=Cobalt;
|