@cobaltio/cobalt-js 2.1.0 → 2.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 CHANGED
@@ -291,7 +291,7 @@ The dynamic fields payload.
291
291
 
292
292
  | Name | Type | Description |
293
293
  | --- | --- | --- |
294
- | map_field_object | <code>Object.&lt;string, Array.&lt;Label&gt;&gt;</code> | desc. |
294
+ | map_fields_object | <code>Object.&lt;string, Array.&lt;Label&gt;&gt;</code> | desc. |
295
295
 
296
296
  <a name="SavedConfig"></a>
297
297
 
package/cobalt.js CHANGED
@@ -194,7 +194,7 @@ class Cobalt {
194
194
 
195
195
  /**
196
196
  * @typedef {Object} DynamicFields The dynamic fields payload.
197
- * @property {Object.<string, Label[]>} map_field_object desc.
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?.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?.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 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}`},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;
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?.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 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
- | map_field_object | <code>Object.&lt;string, Array.&lt;Label&gt;&gt;</code> | desc. |
244
+ | map_fields_object | <code>Object.&lt;string, Array.&lt;Label&gt;&gt;</code> | desc. |
245
245
 
246
246
  <a name="SavedConfig"></a>
247
247
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {