@cobaltio/cobalt-js 0.0.19 → 0.1.0
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 +29 -0
- package/cobalt.js +33 -2
- package/cobalt.min.js +1 -1
- package/docs.md +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,12 +88,14 @@ Cobalt Frontend SDK
|
|
|
88
88
|
* [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
89
89
|
* [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.<boolean></code>
|
|
90
90
|
* [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.<string></code>
|
|
91
|
+
* [.oauth()](#Cobalt+oauth) ⇒ <code>Promise.<boolean></code>
|
|
91
92
|
* [.setAppAuthData()](#Cobalt+setAppAuthData) ⇒ <code>Promise.<void></code>
|
|
92
93
|
* [.removeAppAuth()](#Cobalt+removeAppAuth) ⇒ <code>Promise.<void></code>
|
|
93
94
|
* [.getNodeConfiguration()](#Cobalt+getNodeConfiguration) ⇒ <code>Promise.<Array.<Field>></code>
|
|
94
95
|
* [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
95
96
|
* [.getWorkflowConfiguration()](#Cobalt+getWorkflowConfiguration) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
96
97
|
* [.activateWorkflow()](#Cobalt+activateWorkflow) ⇒ <code>Promise.<void></code>
|
|
98
|
+
* [.activateWorkflows()](#Cobalt+activateWorkflows) ⇒ <code>Promise.<void></code>
|
|
97
99
|
* [.toggleWorkflowStatus()](#Cobalt+toggleWorkflowStatus) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
98
100
|
* [.deleteWorkflow()](#Cobalt+deleteWorkflow) ⇒ <code>Promise.<unknown></code>
|
|
99
101
|
|
|
@@ -164,6 +166,19 @@ specified application.
|
|
|
164
166
|
| --- | --- | --- |
|
|
165
167
|
| application | <code>string</code> | The application type. |
|
|
166
168
|
|
|
169
|
+
<a name="Cobalt+oauth"></a>
|
|
170
|
+
|
|
171
|
+
### cobalt.oauth() ⇒ <code>Promise.<boolean></code>
|
|
172
|
+
Handle OAuth for the specified application.
|
|
173
|
+
|
|
174
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
175
|
+
**Returns**: <code>Promise.<boolean></code> - Whether the user authenticated.
|
|
176
|
+
**Properties**
|
|
177
|
+
|
|
178
|
+
| Name | Type | Description |
|
|
179
|
+
| --- | --- | --- |
|
|
180
|
+
| application | <code>string</code> | The application type. |
|
|
181
|
+
|
|
167
182
|
<a name="Cobalt+setAppAuthData"></a>
|
|
168
183
|
|
|
169
184
|
### cobalt.setAppAuthData() ⇒ <code>Promise.<void></code>
|
|
@@ -177,6 +192,7 @@ specified application.
|
|
|
177
192
|
| --- | --- | --- |
|
|
178
193
|
| application | <code>string</code> | The application type. |
|
|
179
194
|
| payload | <code>object</code> | The key value pairs of auth data. |
|
|
195
|
+
| appId | <code>object</code> | The application ID in case of custom applications. |
|
|
180
196
|
|
|
181
197
|
<a name="Cobalt+removeAppAuth"></a>
|
|
182
198
|
|
|
@@ -189,6 +205,7 @@ Unauthorize the specified application and remove any associated data from Cobalt
|
|
|
189
205
|
| Name | Type | Description |
|
|
190
206
|
| --- | --- | --- |
|
|
191
207
|
| application | <code>string</code> | The application type. |
|
|
208
|
+
| appId | <code>string</code> | The application ID in case of custom applications. |
|
|
192
209
|
|
|
193
210
|
<a name="Cobalt+getNodeConfiguration"></a>
|
|
194
211
|
|
|
@@ -243,6 +260,18 @@ Activate the given installed workflow.
|
|
|
243
260
|
| --- | --- | --- |
|
|
244
261
|
| workflowId | <code>string</code> | The ID of the workflow you want to activate. |
|
|
245
262
|
|
|
263
|
+
<a name="Cobalt+activateWorkflows"></a>
|
|
264
|
+
|
|
265
|
+
### cobalt.activateWorkflows() ⇒ <code>Promise.<void></code>
|
|
266
|
+
Activate the given installed workflows.
|
|
267
|
+
|
|
268
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
269
|
+
**Properties**
|
|
270
|
+
|
|
271
|
+
| Name | Type | Description |
|
|
272
|
+
| --- | --- | --- |
|
|
273
|
+
| workflowIds | <code>string</code> | The list of IDs of the workflows you want to activate. |
|
|
274
|
+
|
|
246
275
|
<a name="Cobalt+toggleWorkflowStatus"></a>
|
|
247
276
|
|
|
248
277
|
### cobalt.toggleWorkflowStatus() ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
package/cobalt.js
CHANGED
|
@@ -223,7 +223,7 @@ class Cobalt {
|
|
|
223
223
|
* @property {object} selectedValues The input data already selected for the node.
|
|
224
224
|
* @returns {Promise<Field[]>}
|
|
225
225
|
*/
|
|
226
|
-
|
|
226
|
+
async getNodeConfiguration(workflowId, nodeId, fieldName, selectedValues = {}) {
|
|
227
227
|
const res = await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}/node/${nodeId}/configuration`, {
|
|
228
228
|
method: "POST",
|
|
229
229
|
headers: {
|
|
@@ -251,6 +251,14 @@ class Cobalt {
|
|
|
251
251
|
* @returns {Promise<Workflow>}
|
|
252
252
|
*/
|
|
253
253
|
async saveNode(workflowId, nodeId, inputData = {}) {
|
|
254
|
+
const payload = {};
|
|
255
|
+
for (const key in inputData) {
|
|
256
|
+
if (Object.hasOwnProperty.call(inputData, key)) {
|
|
257
|
+
const value = inputData[key];
|
|
258
|
+
payload[key] = { value };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
254
262
|
const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`, {
|
|
255
263
|
method: "PUT",
|
|
256
264
|
headers: {
|
|
@@ -258,7 +266,7 @@ class Cobalt {
|
|
|
258
266
|
"content-type": "application/json",
|
|
259
267
|
},
|
|
260
268
|
body: JSON.stringify({
|
|
261
|
-
input_data:
|
|
269
|
+
input_data: payload,
|
|
262
270
|
}),
|
|
263
271
|
});
|
|
264
272
|
|
|
@@ -308,6 +316,29 @@ class Cobalt {
|
|
|
308
316
|
return await res.json();
|
|
309
317
|
}
|
|
310
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Activate the given installed workflows.
|
|
321
|
+
* @property {string} workflowIds The list of IDs of the workflows you want to activate.
|
|
322
|
+
* @returns {Promise<void>}
|
|
323
|
+
*/
|
|
324
|
+
async activateWorkflows(workflowIds = []) {
|
|
325
|
+
const res = await fetch(`${this.baseUrl}/api/v2/workflow/install/success`, {
|
|
326
|
+
method: "PUT",
|
|
327
|
+
headers: {
|
|
328
|
+
authorization: `Bearer ${this.token}`,
|
|
329
|
+
},
|
|
330
|
+
body: JSON.stringify({
|
|
331
|
+
workflow_ids: workflowIds,
|
|
332
|
+
}),
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
if (res.status >= 400 && res.status < 600) {
|
|
336
|
+
throw new Error(res.statusText);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return await res.json();
|
|
340
|
+
}
|
|
341
|
+
|
|
311
342
|
/**
|
|
312
343
|
* Toggle the status of the specified workflow.
|
|
313
344
|
* @property {string} workflowId The ID of the workflow.
|
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 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 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:
|
|
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 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;
|
package/docs.md
CHANGED
|
@@ -45,6 +45,7 @@ Cobalt Frontend SDK
|
|
|
45
45
|
* [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
46
46
|
* [.getWorkflowConfiguration()](#Cobalt+getWorkflowConfiguration) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
47
47
|
* [.activateWorkflow()](#Cobalt+activateWorkflow) ⇒ <code>Promise.<void></code>
|
|
48
|
+
* [.activateWorkflows()](#Cobalt+activateWorkflows) ⇒ <code>Promise.<void></code>
|
|
48
49
|
* [.toggleWorkflowStatus()](#Cobalt+toggleWorkflowStatus) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
49
50
|
* [.deleteWorkflow()](#Cobalt+deleteWorkflow) ⇒ <code>Promise.<unknown></code>
|
|
50
51
|
|
|
@@ -209,6 +210,18 @@ Activate the given installed workflow.
|
|
|
209
210
|
| --- | --- | --- |
|
|
210
211
|
| workflowId | <code>string</code> | The ID of the workflow you want to activate. |
|
|
211
212
|
|
|
213
|
+
<a name="Cobalt+activateWorkflows"></a>
|
|
214
|
+
|
|
215
|
+
### cobalt.activateWorkflows() ⇒ <code>Promise.<void></code>
|
|
216
|
+
Activate the given installed workflows.
|
|
217
|
+
|
|
218
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
219
|
+
**Properties**
|
|
220
|
+
|
|
221
|
+
| Name | Type | Description |
|
|
222
|
+
| --- | --- | --- |
|
|
223
|
+
| workflowIds | <code>string</code> | The list of IDs of the workflows you want to activate. |
|
|
224
|
+
|
|
212
225
|
<a name="Cobalt+toggleWorkflowStatus"></a>
|
|
213
226
|
|
|
214
227
|
### cobalt.toggleWorkflowStatus() ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|