@cobaltio/cobalt-js 2.1.0 → 2.1.2
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 +1 -1
- package/cobalt.js +6 -5
- package/cobalt.min.js +1 -1
- package/docs.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -291,7 +291,7 @@ The dynamic fields payload.
|
|
|
291
291
|
|
|
292
292
|
| Name | Type | Description |
|
|
293
293
|
| --- | --- | --- |
|
|
294
|
-
|
|
|
294
|
+
| map_fields_object | <code>Object.<string, Array.<Label>></code> | desc. |
|
|
295
295
|
|
|
296
296
|
<a name="SavedConfig"></a>
|
|
297
297
|
|
package/cobalt.js
CHANGED
|
@@ -41,7 +41,7 @@ class Cobalt {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const data = await res.json();
|
|
44
|
-
return data
|
|
44
|
+
return data.auth_url;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -61,14 +61,14 @@ class Cobalt {
|
|
|
61
61
|
.then(connected => {
|
|
62
62
|
if (connected === true) {
|
|
63
63
|
// close auth window
|
|
64
|
-
connectWindow
|
|
64
|
+
connectWindow && connectWindow.close();
|
|
65
65
|
// clear interval
|
|
66
66
|
clearInterval(interval);
|
|
67
67
|
// resovle status
|
|
68
68
|
resolve(true);
|
|
69
69
|
} else {
|
|
70
70
|
// user closed oauth window without authenticating
|
|
71
|
-
if (connectWindow
|
|
71
|
+
if (connectWindow && connectWindow.closed) {
|
|
72
72
|
// clear interval
|
|
73
73
|
clearInterval(interval);
|
|
74
74
|
// resolve status
|
|
@@ -158,7 +158,7 @@ class Cobalt {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
const data = await res.json();
|
|
161
|
-
return !!data
|
|
161
|
+
return !!data.status;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
@@ -194,7 +194,7 @@ class Cobalt {
|
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
196
|
* @typedef {Object} DynamicFields The dynamic fields payload.
|
|
197
|
-
* @property {Object.<string, Label[]>}
|
|
197
|
+
* @property {Object.<string, Label[]>} map_fields_object desc.
|
|
198
198
|
*/
|
|
199
199
|
|
|
200
200
|
/**
|
|
@@ -209,6 +209,7 @@ class Cobalt {
|
|
|
209
209
|
method: "POST",
|
|
210
210
|
headers: {
|
|
211
211
|
authorization: `Bearer ${this.token}`,
|
|
212
|
+
"content-type": "application/json",
|
|
212
213
|
},
|
|
213
214
|
body: JSON.stringify(fields),
|
|
214
215
|
});
|
package/cobalt.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Cobalt{constructor(options={}){this.baseUrl=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:""}async getOAuthUrl(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
|
|
1
|
+
class Cobalt{constructor(options={}){this.baseUrl=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:""}async getOAuthUrl(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.getOAuthUrl(application).then(oauthUrl=>{const connectWindow=window.open(oauthUrl);const interval=setInterval(()=>{this.checkAuth(application).then(connected=>{if(connected===true){connectWindow&&connectWindow.close();clearInterval(interval);resolve(true)}else{if(connectWindow&&connectWindow.closed){clearInterval(interval);resolve(false)}}}).catch(e=>{console.error(e);clearInterval(interval);reject(e)})},3e3)}).catch(reject)})}async auth(application,payload){const res=await fetch(`${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 authCustom(applicationId,payload){const res=await fetch(`${this.baseUrl}/api/v1/custom/${applicationId}/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 checkAuth(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 removeAuth(application,applicationId){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${applicationId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}}async config(applicationId,configId,fields={}){const res=await fetch(`${this.baseUrl}/api/v2/application/${applicationId}/installation/${configId}`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify(fields)});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async getConfig(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 saveConfig(applicationId,payload={}){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/install`,{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)}return await res.json()}async getSavedConfig(applicationId,configId){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async updateSavedConfig(applicationId,configId,payload={}){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`,{method:"PUT",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)}return await res.json()}async deleteSavedConfig(applicationId,configId){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`,{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
|
@@ -241,7 +241,7 @@ The dynamic fields payload.
|
|
|
241
241
|
|
|
242
242
|
| Name | Type | Description |
|
|
243
243
|
| --- | --- | --- |
|
|
244
|
-
|
|
|
244
|
+
| map_fields_object | <code>Object.<string, Array.<Label>></code> | desc. |
|
|
245
245
|
|
|
246
246
|
<a name="SavedConfig"></a>
|
|
247
247
|
|