@cobaltio/cobalt-js 0.0.18 → 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 +67 -1
- package/cobalt.min.js +1 -1
- package/docs.md +27 -0
- package/package.json +4 -4
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
|
@@ -125,6 +125,49 @@ class Cobalt {
|
|
|
125
125
|
return data?.auth_url;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Handle OAuth for the specified application.
|
|
130
|
+
* @property {string} application The application type.
|
|
131
|
+
* @returns {Promise<boolean>} Whether the user authenticated.
|
|
132
|
+
*/
|
|
133
|
+
async oauth(application) {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
this.getAppAuthUrl(application)
|
|
136
|
+
.then(oauthUrl => {
|
|
137
|
+
const connectWindow = window.open(oauthUrl);
|
|
138
|
+
|
|
139
|
+
// keep checking connection status
|
|
140
|
+
const interval = setInterval(() => {
|
|
141
|
+
this.getAppAuthStatus(application)
|
|
142
|
+
.then(connected => {
|
|
143
|
+
if (connected === true) {
|
|
144
|
+
// close auth window
|
|
145
|
+
connectWindow?.close();
|
|
146
|
+
// clear interval
|
|
147
|
+
clearInterval(interval);
|
|
148
|
+
// resovle status
|
|
149
|
+
resolve(true);
|
|
150
|
+
} else {
|
|
151
|
+
// user closed oauth window without authenticating
|
|
152
|
+
if (connectWindow?.closed) {
|
|
153
|
+
// clear interval
|
|
154
|
+
clearInterval(interval);
|
|
155
|
+
// resolve status
|
|
156
|
+
resolve(false);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.catch(e => {
|
|
161
|
+
console.error(e);
|
|
162
|
+
clearInterval(interval);
|
|
163
|
+
reject(e);
|
|
164
|
+
});
|
|
165
|
+
}, 3e3);
|
|
166
|
+
})
|
|
167
|
+
.catch(reject);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
128
171
|
/**
|
|
129
172
|
* Save the auth data that user provides to authenticate themselves to the
|
|
130
173
|
* specified application.
|
|
@@ -250,7 +293,7 @@ class Cobalt {
|
|
|
250
293
|
* @property {string} workflowId The ID of the workflow you want to activate.
|
|
251
294
|
* @returns {Promise<void>}
|
|
252
295
|
*/
|
|
253
|
-
|
|
296
|
+
async activateWorkflow(workflowId) {
|
|
254
297
|
const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/install/success`, {
|
|
255
298
|
method: "PUT",
|
|
256
299
|
headers: {
|
|
@@ -265,6 +308,29 @@ class Cobalt {
|
|
|
265
308
|
return await res.json();
|
|
266
309
|
}
|
|
267
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
|
+
|
|
268
334
|
/**
|
|
269
335
|
* Toggle the status of the specified workflow.
|
|
270
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 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
|
@@ -38,12 +38,14 @@ Cobalt Frontend SDK
|
|
|
38
38
|
* [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
39
39
|
* [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.<boolean></code>
|
|
40
40
|
* [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.<string></code>
|
|
41
|
+
* [.oauth()](#Cobalt+oauth) ⇒ <code>Promise.<boolean></code>
|
|
41
42
|
* [.setAppAuthData()](#Cobalt+setAppAuthData) ⇒ <code>Promise.<void></code>
|
|
42
43
|
* [.removeAppAuth()](#Cobalt+removeAppAuth) ⇒ <code>Promise.<void></code>
|
|
43
44
|
* [.getNodeConfiguration()](#Cobalt+getNodeConfiguration) ⇒ <code>Promise.<Array.<Field>></code>
|
|
44
45
|
* [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
45
46
|
* [.getWorkflowConfiguration()](#Cobalt+getWorkflowConfiguration) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
46
47
|
* [.activateWorkflow()](#Cobalt+activateWorkflow) ⇒ <code>Promise.<void></code>
|
|
48
|
+
* [.activateWorkflows()](#Cobalt+activateWorkflows) ⇒ <code>Promise.<void></code>
|
|
47
49
|
* [.toggleWorkflowStatus()](#Cobalt+toggleWorkflowStatus) ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
|
48
50
|
* [.deleteWorkflow()](#Cobalt+deleteWorkflow) ⇒ <code>Promise.<unknown></code>
|
|
49
51
|
|
|
@@ -114,6 +116,19 @@ specified application.
|
|
|
114
116
|
| --- | --- | --- |
|
|
115
117
|
| application | <code>string</code> | The application type. |
|
|
116
118
|
|
|
119
|
+
<a name="Cobalt+oauth"></a>
|
|
120
|
+
|
|
121
|
+
### cobalt.oauth() ⇒ <code>Promise.<boolean></code>
|
|
122
|
+
Handle OAuth for the specified application.
|
|
123
|
+
|
|
124
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
125
|
+
**Returns**: <code>Promise.<boolean></code> - Whether the user authenticated.
|
|
126
|
+
**Properties**
|
|
127
|
+
|
|
128
|
+
| Name | Type | Description |
|
|
129
|
+
| --- | --- | --- |
|
|
130
|
+
| application | <code>string</code> | The application type. |
|
|
131
|
+
|
|
117
132
|
<a name="Cobalt+setAppAuthData"></a>
|
|
118
133
|
|
|
119
134
|
### cobalt.setAppAuthData() ⇒ <code>Promise.<void></code>
|
|
@@ -195,6 +210,18 @@ Activate the given installed workflow.
|
|
|
195
210
|
| --- | --- | --- |
|
|
196
211
|
| workflowId | <code>string</code> | The ID of the workflow you want to activate. |
|
|
197
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
|
+
|
|
198
225
|
<a name="Cobalt+toggleWorkflowStatus"></a>
|
|
199
226
|
|
|
200
227
|
### cobalt.toggleWorkflowStatus() ⇒ [<code>Promise.<Workflow></code>](#Workflow)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobaltio/cobalt-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Cobalt frontend SDK",
|
|
5
5
|
"main": "./cobalt.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"homepage": "https://github.com/Breakout-Embed/cobalt-js#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"foodoc": "^0.0.9",
|
|
33
|
-
"jsdoc": "^
|
|
34
|
-
"jsdoc-to-markdown": "^
|
|
35
|
-
"uglify-js": "^3.17.
|
|
33
|
+
"jsdoc": "^4.0.0",
|
|
34
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
35
|
+
"uglify-js": "^3.17.4"
|
|
36
36
|
}
|
|
37
37
|
}
|