@cobaltio/cobalt-js 0.0.17 → 0.0.19
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/cobalt.js +50 -5
- package/cobalt.min.js +1 -1
- package/docs.md +16 -0
- package/package.json +4 -4
package/cobalt.js
CHANGED
|
@@ -125,15 +125,59 @@ 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.
|
|
131
174
|
* @property {string} application The application type.
|
|
132
175
|
* @property {object} payload The key value pairs of auth data.
|
|
176
|
+
* @property {object} appId The application ID in case of custom applications.
|
|
133
177
|
* @returns {Promise<void>}
|
|
134
178
|
*/
|
|
135
|
-
async setAppAuthData(application, payload) {
|
|
136
|
-
const res = await fetch(`${this.baseUrl}/api/v1/${application}/save`, {
|
|
179
|
+
async setAppAuthData(application, payload, appId) {
|
|
180
|
+
const res = await fetch(appId ? `${this.baseUrl}/api/v1/${application}/${appId}/save` : `${this.baseUrl}/api/v1/${application}/save`, {
|
|
137
181
|
method: "POST",
|
|
138
182
|
headers: {
|
|
139
183
|
authorization: `Bearer ${this.token}`,
|
|
@@ -155,10 +199,11 @@ class Cobalt {
|
|
|
155
199
|
/**
|
|
156
200
|
* Unauthorize the specified application and remove any associated data from Cobalt.
|
|
157
201
|
* @property {string} application The application type.
|
|
202
|
+
* @property {string} appId The application ID in case of custom applications.
|
|
158
203
|
* @returns {Promise<void>}
|
|
159
204
|
*/
|
|
160
|
-
async removeAppAuth(application) {
|
|
161
|
-
const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}`, {
|
|
205
|
+
async removeAppAuth(application, appId) {
|
|
206
|
+
const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${appId}`, {
|
|
162
207
|
method: "DELETE",
|
|
163
208
|
headers: {
|
|
164
209
|
authorization: `Bearer ${this.token}`,
|
|
@@ -248,7 +293,7 @@ class Cobalt {
|
|
|
248
293
|
* @property {string} workflowId The ID of the workflow you want to activate.
|
|
249
294
|
* @returns {Promise<void>}
|
|
250
295
|
*/
|
|
251
|
-
|
|
296
|
+
async activateWorkflow(workflowId) {
|
|
252
297
|
const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/install/success`, {
|
|
253
298
|
method: "PUT",
|
|
254
299
|
headers: {
|
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)});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){const res=await fetch(
|
|
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;
|
package/docs.md
CHANGED
|
@@ -38,6 +38,7 @@ 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>
|
|
@@ -114,6 +115,19 @@ specified application.
|
|
|
114
115
|
| --- | --- | --- |
|
|
115
116
|
| application | <code>string</code> | The application type. |
|
|
116
117
|
|
|
118
|
+
<a name="Cobalt+oauth"></a>
|
|
119
|
+
|
|
120
|
+
### cobalt.oauth() ⇒ <code>Promise.<boolean></code>
|
|
121
|
+
Handle OAuth for the specified application.
|
|
122
|
+
|
|
123
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
124
|
+
**Returns**: <code>Promise.<boolean></code> - Whether the user authenticated.
|
|
125
|
+
**Properties**
|
|
126
|
+
|
|
127
|
+
| Name | Type | Description |
|
|
128
|
+
| --- | --- | --- |
|
|
129
|
+
| application | <code>string</code> | The application type. |
|
|
130
|
+
|
|
117
131
|
<a name="Cobalt+setAppAuthData"></a>
|
|
118
132
|
|
|
119
133
|
### cobalt.setAppAuthData() ⇒ <code>Promise.<void></code>
|
|
@@ -127,6 +141,7 @@ specified application.
|
|
|
127
141
|
| --- | --- | --- |
|
|
128
142
|
| application | <code>string</code> | The application type. |
|
|
129
143
|
| payload | <code>object</code> | The key value pairs of auth data. |
|
|
144
|
+
| appId | <code>object</code> | The application ID in case of custom applications. |
|
|
130
145
|
|
|
131
146
|
<a name="Cobalt+removeAppAuth"></a>
|
|
132
147
|
|
|
@@ -139,6 +154,7 @@ Unauthorize the specified application and remove any associated data from Cobalt
|
|
|
139
154
|
| Name | Type | Description |
|
|
140
155
|
| --- | --- | --- |
|
|
141
156
|
| application | <code>string</code> | The application type. |
|
|
157
|
+
| appId | <code>string</code> | The application ID in case of custom applications. |
|
|
142
158
|
|
|
143
159
|
<a name="Cobalt+getNodeConfiguration"></a>
|
|
144
160
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobaltio/cobalt-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
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
|
}
|