@cobaltio/cobalt-js 0.0.19 → 0.0.20
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 +23 -0
- 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
|
@@ -308,6 +308,29 @@ class Cobalt {
|
|
|
308
308
|
return await res.json();
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Activate the given installed workflows.
|
|
313
|
+
* @property {string} workflowIds The list of IDs of the workflows you want to activate.
|
|
314
|
+
* @returns {Promise<void>}
|
|
315
|
+
*/
|
|
316
|
+
async activateWorkflows(workflowIds = []) {
|
|
317
|
+
const res = await fetch(`${this.baseUrl}/api/v2/workflow/install/success`, {
|
|
318
|
+
method: "PUT",
|
|
319
|
+
headers: {
|
|
320
|
+
authorization: `Bearer ${this.token}`,
|
|
321
|
+
},
|
|
322
|
+
body: JSON.stringify({
|
|
323
|
+
workflow_ids: workflowIds,
|
|
324
|
+
}),
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
if (res.status >= 400 && res.status < 600) {
|
|
328
|
+
throw new Error(res.statusText);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return await res.json();
|
|
332
|
+
}
|
|
333
|
+
|
|
311
334
|
/**
|
|
312
335
|
* Toggle the status of the specified workflow.
|
|
313
336
|
* @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:inputData})});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 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.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:inputData})});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)
|