@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.
Files changed (5) hide show
  1. package/README.md +105 -210
  2. package/cobalt.js +103 -200
  3. package/cobalt.min.js +1 -1
  4. package/docs.md +104 -209
  5. 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 {object} options The options to configure the Cobalt SDK.
8
- * @param {string} [options.token] The session token.
9
- * @param {string} [options.baseUrl=https://api.gocobalt.io] The base URL of your Cobalt API.
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.apiBaseUrl = options?.baseUrl || "https://api.gocobalt.io";
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
- * @property {string} application The application type.
136
- * @returns {Promise<string>} The auth URL where users can authenticate themselves.
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 getAppAuthUrl(application) {
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
- * @property {string} application The application type.
156
- * @returns {Promise<boolean>} Whether the user authenticated.
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.getAppAuthUrl(application)
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.getAppAuthStatus(application)
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
- * @property {string} application The application type.
200
- * @property {object} payload The key value pairs of auth data.
201
- * @property {object} appId The application ID in case of custom applications.
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 setAppAuthData(application, payload, appId) {
205
- const res = await fetch(appId ? `${this.baseUrl}/api/v1/${application}/${appId}/save` : `${this.baseUrl}/api/v1/${application}/save`, {
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
- * Unauthorize the specified application and remove any associated data from Cobalt.
226
- * @property {string} application The application type.
227
- * @property {string} appId The application ID in case of custom applications.
228
- * @returns {Promise<void>}
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 removeAppAuth(application, appId) {
231
- const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${appId}`, {
232
- method: "DELETE",
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 node configuration data for dynamic fields.
245
- * @property {string} workflowId The ID of the workflow.
246
- * @property {string} nodeId The ID of the node.
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 getNodeConfiguration(workflowId, nodeId, fieldName, selectedValues = {}) {
252
- const res = await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}/node/${nodeId}/configuration`, {
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
- return await res.json();
160
+ const data = await res.json();
161
+ return !!data?.status;
269
162
  }
270
163
 
271
164
  /**
272
- * Save the input data for the specified node.
273
- * @property {string} workflowId The ID of the workflow.
274
- * @property {string} nodeId The ID of the node.
275
- * @property {object} inputData The input data for the node.
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 saveNode(workflowId, nodeId, inputData = {}) {
279
- const payload = {};
280
- for (const key in inputData) {
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
- * Returns the workflow configuration data.
307
- * @property {string} workflowId The ID of the workflow.
308
- * @returns {Promise<Workflow>}
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 getWorkflowConfiguration(workflowId) {
311
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/configuration`, {
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
- * Activate the given installed workflow.
326
- * @property {string} workflowId The ID of the workflow you want to activate.
327
- * @returns {Promise<void>}
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
- async activateWorkflow(workflowId) {
330
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/install/success`, {
331
- method: "PUT",
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
- * Activate the given installed workflows.
346
- * @property {string} workflowIds The list of IDs of the workflows you want to activate.
347
- * @returns {Promise<void>}
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 activateWorkflows(workflowIds = []) {
350
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/install/success`, {
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
- * Toggle the status of the specified workflow.
369
- * @property {string} workflowId The ID of the workflow.
370
- * @returns {Promise<Workflow>}
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 toggleWorkflowStatus(workflowId) {
373
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/toggle-status`, {
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 workflow.
389
- * @property {string} workflowId The ID of the workflow.
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 deleteWorkflow(workflowId) {
393
- const res = await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}`, {
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.apiBaseUrl=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:""}get baseUrl(){return this.apiBaseUrl}async installTemplate(templateId,udf={}){const res=await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({udf:udf})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}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 getAppAuthStatus(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 getAppAuthUrl(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.getAppAuthUrl(application).then(oauthUrl=>{const connectWindow=window.open(oauthUrl);const interval=setInterval(()=>{this.getAppAuthStatus(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 setAppAuthData(application,payload,appId){const res=await fetch(appId?`${this.baseUrl}/api/v1/${application}/${appId}/save`:`${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 removeAppAuth(application,appId){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${appId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}}async getNodeConfiguration(workflowId,nodeId,fieldName,selectedValues={}){const res=await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}/node/${nodeId}/configuration`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({fieldName:fieldName,selectedValues:selectedValues})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async saveNode(workflowId,nodeId,inputData={}){const payload={};for(const key in inputData){if(Object.hasOwnProperty.call(inputData,key)){const value=inputData[key];payload[key]={value:value}}}const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({input_data:payload})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async getWorkflowConfiguration(workflowId){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/configuration`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async activateWorkflow(workflowId){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/install/success`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async activateWorkflows(workflowIds=[]){const res=await fetch(`${this.baseUrl}/api/v2/workflow/install/success`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`},body:JSON.stringify({workflow_ids:workflowIds})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async toggleWorkflowStatus(workflowId){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/toggle-status`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async deleteWorkflow(workflowId){const res=await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}`,{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;
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;