@cobaltio/cobalt-js 2.1.3 → 3.0.0

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.
Files changed (5) hide show
  1. package/README.md +250 -325
  2. package/cobalt.js +96 -160
  3. package/docs.md +59 -134
  4. package/package.json +34 -36
  5. package/cobalt.min.js +0 -1
package/package.json CHANGED
@@ -1,36 +1,34 @@
1
- {
2
- "name": "@cobaltio/cobalt-js",
3
- "version": "2.1.3",
4
- "description": "Cobalt frontend SDK",
5
- "main": "./cobalt.js",
6
- "scripts": {
7
- "build": "uglifyjs cobalt.js -o cobalt.min.js",
8
- "docgen": "jsdoc2md cobalt.js > docs.md",
9
- "test": "echo \"Warn: no test specified\""
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/Breakout-Embed/cobalt.js.git"
14
- },
15
- "publishConfig": {
16
- "access": "public",
17
- "registry": "https://registry.npmjs.org/"
18
- },
19
- "keywords": [
20
- "cobalt embed",
21
- "cobalt sdk",
22
- "frontend sdk",
23
- "sdk"
24
- ],
25
- "author": "Sankarsan Kampa",
26
- "license": "MIT",
27
- "bugs": {
28
- "url": "https://github.com/Breakout-Embed/cobalt-js/issues"
29
- },
30
- "homepage": "https://github.com/Breakout-Embed/cobalt-js#readme",
31
- "devDependencies": {
32
- "jsdoc": "^4.0.0",
33
- "jsdoc-to-markdown": "^8.0.0",
34
- "uglify-js": "^3.17.4"
35
- }
36
- }
1
+ {
2
+ "name": "@cobaltio/cobalt-js",
3
+ "version": "3.0.0",
4
+ "description": "Cobalt frontend SDK",
5
+ "main": "./cobalt.js",
6
+ "scripts": {
7
+ "docgen": "jsdoc2md cobalt.js > docs.md",
8
+ "test": "echo \"Warn: no test specified\""
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Breakout-Embed/cobalt.js.git"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org/"
17
+ },
18
+ "keywords": [
19
+ "cobalt embed",
20
+ "cobalt sdk",
21
+ "frontend sdk",
22
+ "sdk"
23
+ ],
24
+ "author": "Sankarsan Kampa",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/Breakout-Embed/cobalt-js/issues"
28
+ },
29
+ "homepage": "https://github.com/Breakout-Embed/cobalt-js#readme",
30
+ "devDependencies": {
31
+ "jsdoc": "^4.0.2",
32
+ "jsdoc-to-markdown": "^8.0.0"
33
+ }
34
+ }
package/cobalt.min.js DELETED
@@ -1 +0,0 @@
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;