@cobaltio/cobalt-js 0.1.0 → 0.1.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 +29 -0
- package/cobalt.js +25 -0
- package/cobalt.min.js +1 -1
- package/docs.md +29 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,9 @@ cobalt.token = "COBALT_SESSION_TOKEN";
|
|
|
71
71
|
<dt><a href="#AppAuthStatus">AppAuthStatus</a> : <code>object</code></dt>
|
|
72
72
|
<dd><p>The auth status of the user for an application.</p>
|
|
73
73
|
</dd>
|
|
74
|
+
<dt><a href="#AppConfig">AppConfig</a> : <code>object</code></dt>
|
|
75
|
+
<dd><p>The configuration data for an application.</p>
|
|
76
|
+
</dd>
|
|
74
77
|
</dl>
|
|
75
78
|
|
|
76
79
|
<a name="Cobalt"></a>
|
|
@@ -86,6 +89,7 @@ Cobalt Frontend SDK
|
|
|
86
89
|
* [.token](#Cobalt+token) ⇒ <code>string</code>
|
|
87
90
|
* [.baseUrl](#Cobalt+baseUrl) ⇒ <code>string</code>
|
|
88
91
|
* [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
92
|
+
* [.getAppConfig(application)](#Cobalt+getAppConfig) ⇒ [<code>Promise.<AppConfig></code>](#AppConfig)
|
|
89
93
|
* [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.<boolean></code>
|
|
90
94
|
* [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.<string></code>
|
|
91
95
|
* [.oauth()](#Cobalt+oauth) ⇒ <code>Promise.<boolean></code>
|
|
@@ -139,6 +143,18 @@ Install the given template.
|
|
|
139
143
|
| templateId | <code>string</code> | The ID of the template you want to install. |
|
|
140
144
|
| udf | <code>object</code> | Custom key value pairs you want to store with the installed worklfow. |
|
|
141
145
|
|
|
146
|
+
<a name="Cobalt+getAppConfig"></a>
|
|
147
|
+
|
|
148
|
+
### cobalt.getAppConfig(application) ⇒ [<code>Promise.<AppConfig></code>](#AppConfig)
|
|
149
|
+
Returns the configuration data for the specified application.
|
|
150
|
+
|
|
151
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
152
|
+
**Returns**: [<code>Promise.<AppConfig></code>](#AppConfig) - The specified application's configuration data.
|
|
153
|
+
|
|
154
|
+
| Param | Type | Description |
|
|
155
|
+
| --- | --- | --- |
|
|
156
|
+
| application | <code>string</code> | The application ID. |
|
|
157
|
+
|
|
142
158
|
<a name="Cobalt+getAppAuthStatus"></a>
|
|
143
159
|
|
|
144
160
|
### cobalt.getAppAuthStatus() ⇒ <code>Promise.<boolean></code>
|
|
@@ -350,3 +366,16 @@ The auth status of the user for an application.
|
|
|
350
366
|
| Name | Type | Description |
|
|
351
367
|
| --- | --- | --- |
|
|
352
368
|
| status | <code>boolean</code> | Whether the user has authenticated with this application. |
|
|
369
|
+
|
|
370
|
+
<a name="AppConfig"></a>
|
|
371
|
+
|
|
372
|
+
## AppConfig : <code>object</code>
|
|
373
|
+
The configuration data for an application.
|
|
374
|
+
|
|
375
|
+
**Kind**: global typedef
|
|
376
|
+
**Properties**
|
|
377
|
+
|
|
378
|
+
| Name | Type | Description |
|
|
379
|
+
| --- | --- | --- |
|
|
380
|
+
| application_data_slots | <code>Array.<DataSlot></code> | Array of application data slots. |
|
|
381
|
+
| templates | <code>Array.<Template></code> | Array of workflow templates. |
|
package/cobalt.js
CHANGED
|
@@ -61,6 +61,12 @@ class Cobalt {
|
|
|
61
61
|
* @property {boolean} status Whether the user has authenticated with this application.
|
|
62
62
|
*/
|
|
63
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
|
+
|
|
64
70
|
/**
|
|
65
71
|
* Install the given template.
|
|
66
72
|
* @property {string} templateId The ID of the template you want to install.
|
|
@@ -84,6 +90,25 @@ class Cobalt {
|
|
|
84
90
|
return await res.json();
|
|
85
91
|
}
|
|
86
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
|
+
|
|
87
112
|
/**
|
|
88
113
|
* Returns the auth status of the user for the specified application.
|
|
89
114
|
* @property {string} application The application type.
|
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 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.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;
|
package/docs.md
CHANGED
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
<dt><a href="#AppAuthStatus">AppAuthStatus</a> : <code>object</code></dt>
|
|
22
22
|
<dd><p>The auth status of the user for an application.</p>
|
|
23
23
|
</dd>
|
|
24
|
+
<dt><a href="#AppConfig">AppConfig</a> : <code>object</code></dt>
|
|
25
|
+
<dd><p>The configuration data for an application.</p>
|
|
26
|
+
</dd>
|
|
24
27
|
</dl>
|
|
25
28
|
|
|
26
29
|
<a name="Cobalt"></a>
|
|
@@ -36,6 +39,7 @@ Cobalt Frontend SDK
|
|
|
36
39
|
* [.token](#Cobalt+token) ⇒ <code>string</code>
|
|
37
40
|
* [.baseUrl](#Cobalt+baseUrl) ⇒ <code>string</code>
|
|
38
41
|
* [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
42
|
+
* [.getAppConfig(application)](#Cobalt+getAppConfig) ⇒ [<code>Promise.<AppConfig></code>](#AppConfig)
|
|
39
43
|
* [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.<boolean></code>
|
|
40
44
|
* [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.<string></code>
|
|
41
45
|
* [.oauth()](#Cobalt+oauth) ⇒ <code>Promise.<boolean></code>
|
|
@@ -89,6 +93,18 @@ Install the given template.
|
|
|
89
93
|
| templateId | <code>string</code> | The ID of the template you want to install. |
|
|
90
94
|
| udf | <code>object</code> | Custom key value pairs you want to store with the installed worklfow. |
|
|
91
95
|
|
|
96
|
+
<a name="Cobalt+getAppConfig"></a>
|
|
97
|
+
|
|
98
|
+
### cobalt.getAppConfig(application) ⇒ [<code>Promise.<AppConfig></code>](#AppConfig)
|
|
99
|
+
Returns the configuration data for the specified application.
|
|
100
|
+
|
|
101
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
102
|
+
**Returns**: [<code>Promise.<AppConfig></code>](#AppConfig) - The specified application's configuration data.
|
|
103
|
+
|
|
104
|
+
| Param | Type | Description |
|
|
105
|
+
| --- | --- | --- |
|
|
106
|
+
| application | <code>string</code> | The application ID. |
|
|
107
|
+
|
|
92
108
|
<a name="Cobalt+getAppAuthStatus"></a>
|
|
93
109
|
|
|
94
110
|
### cobalt.getAppAuthStatus() ⇒ <code>Promise.<boolean></code>
|
|
@@ -301,3 +317,16 @@ The auth status of the user for an application.
|
|
|
301
317
|
| --- | --- | --- |
|
|
302
318
|
| status | <code>boolean</code> | Whether the user has authenticated with this application. |
|
|
303
319
|
|
|
320
|
+
<a name="AppConfig"></a>
|
|
321
|
+
|
|
322
|
+
## AppConfig : <code>object</code>
|
|
323
|
+
The configuration data for an application.
|
|
324
|
+
|
|
325
|
+
**Kind**: global typedef
|
|
326
|
+
**Properties**
|
|
327
|
+
|
|
328
|
+
| Name | Type | Description |
|
|
329
|
+
| --- | --- | --- |
|
|
330
|
+
| application_data_slots | <code>Array.<DataSlot></code> | Array of application data slots. |
|
|
331
|
+
| templates | <code>Array.<Template></code> | Array of workflow templates. |
|
|
332
|
+
|