@cobaltio/cobalt-js 2.0.0 → 2.1.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.
- package/README.md +46 -0
- package/cobalt.js +37 -3
- package/cobalt.min.js +1 -1
- package/docs.md +46 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,12 @@ cobalt.token = "COBALT_SESSION_TOKEN";
|
|
|
62
62
|
<dt><a href="#Config">Config</a> : <code>object</code></dt>
|
|
63
63
|
<dd><p>The configuration data for an application.</p>
|
|
64
64
|
</dd>
|
|
65
|
+
<dt><a href="#Label">Label</a> : <code>Object</code></dt>
|
|
66
|
+
<dd><p>Field Mapping Label</p>
|
|
67
|
+
</dd>
|
|
68
|
+
<dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
|
|
69
|
+
<dd><p>The dynamic fields payload.</p>
|
|
70
|
+
</dd>
|
|
65
71
|
<dt><a href="#SavedConfig">SavedConfig</a> : <code>Object</code></dt>
|
|
66
72
|
<dd><p>An saved config.</p>
|
|
67
73
|
</dd>
|
|
@@ -90,6 +96,7 @@ Cobalt Frontend SDK
|
|
|
90
96
|
* [.authCustom(applicationId, payload)](#Cobalt+authCustom) ⇒ <code>Promise.<unknown></code>
|
|
91
97
|
* [.checkAuth(application)](#Cobalt+checkAuth) ⇒ <code>Promise.<Boolean></code>
|
|
92
98
|
* [.removeAuth(application, [applicationId])](#Cobalt+removeAuth) ⇒ <code>Promise.<void></code>
|
|
99
|
+
* [.config(applicationId, configId, fields)](#Cobalt+config) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
93
100
|
* [.getConfig(application)](#Cobalt+getConfig) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
94
101
|
* [.saveConfig(applicationId, payload)](#Cobalt+saveConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
95
102
|
* [.getSavedConfig(applicationId, configId)](#Cobalt+getSavedConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
@@ -170,6 +177,20 @@ Unauthorize the specified application and remove any associated data from Cobalt
|
|
|
170
177
|
| application | <code>String</code> | The application type. |
|
|
171
178
|
| [applicationId] | <code>String</code> | The application ID in case of custom applications. |
|
|
172
179
|
|
|
180
|
+
<a name="Cobalt+config"></a>
|
|
181
|
+
|
|
182
|
+
### cobalt.config(applicationId, configId, fields) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
183
|
+
Returns the specified saved config, or creates one if it doesn't exist.
|
|
184
|
+
|
|
185
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
186
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
187
|
+
|
|
188
|
+
| Param | Type | Description |
|
|
189
|
+
| --- | --- | --- |
|
|
190
|
+
| applicationId | <code>String</code> | The application ID. |
|
|
191
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
192
|
+
| fields | [<code>DynamicFields</code>](#DynamicFields) | The dynamic fields payload. |
|
|
193
|
+
|
|
173
194
|
<a name="Cobalt+getConfig"></a>
|
|
174
195
|
|
|
175
196
|
### cobalt.getConfig(application) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
@@ -247,6 +268,31 @@ The configuration data for an application.
|
|
|
247
268
|
| application_data_slots | <code>Array.<DataSlot></code> | Array of application data slots. |
|
|
248
269
|
| workflows | [<code>Array.<Workflow></code>](#Workflow) | Array of workflows. |
|
|
249
270
|
|
|
271
|
+
<a name="Label"></a>
|
|
272
|
+
|
|
273
|
+
## Label : <code>Object</code>
|
|
274
|
+
Field Mapping Label
|
|
275
|
+
|
|
276
|
+
**Kind**: global typedef
|
|
277
|
+
**Properties**
|
|
278
|
+
|
|
279
|
+
| Name | Type | Description |
|
|
280
|
+
| --- | --- | --- |
|
|
281
|
+
| name | <code>string</code> | The Label name. |
|
|
282
|
+
| value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
|
|
283
|
+
|
|
284
|
+
<a name="DynamicFields"></a>
|
|
285
|
+
|
|
286
|
+
## DynamicFields : <code>Object</code>
|
|
287
|
+
The dynamic fields payload.
|
|
288
|
+
|
|
289
|
+
**Kind**: global typedef
|
|
290
|
+
**Properties**
|
|
291
|
+
|
|
292
|
+
| Name | Type | Description |
|
|
293
|
+
| --- | --- | --- |
|
|
294
|
+
| map_field_object | <code>Object.<string, Array.<Label>></code> | desc. |
|
|
295
|
+
|
|
250
296
|
<a name="SavedConfig"></a>
|
|
251
297
|
|
|
252
298
|
## SavedConfig : <code>Object</code>
|
package/cobalt.js
CHANGED
|
@@ -9,9 +9,9 @@ class Cobalt {
|
|
|
9
9
|
* @param {String} [options.token] The session token.
|
|
10
10
|
* @param {String} [options.baseUrl=https://api.gocobalt.io] The base URL of the Cobalt API.
|
|
11
11
|
*/
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.baseUrl = options
|
|
14
|
-
this.token = options
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.baseUrl = options.baseUrl || "https://api.gocobalt.io";
|
|
14
|
+
this.token = options.token;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
get token() {
|
|
@@ -186,6 +186,40 @@ class Cobalt {
|
|
|
186
186
|
* @property {Workflow[]} workflows Array of workflows.
|
|
187
187
|
*/
|
|
188
188
|
|
|
189
|
+
/**
|
|
190
|
+
* @typedef {Object} Label Field Mapping Label
|
|
191
|
+
* @property {string} name The Label name.
|
|
192
|
+
* @property {string | number | boolean} value The Label value.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @typedef {Object} DynamicFields The dynamic fields payload.
|
|
197
|
+
* @property {Object.<string, Label[]>} map_field_object desc.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns the specified saved config, or creates one if it doesn't exist.
|
|
202
|
+
* @param {String} applicationId The application ID.
|
|
203
|
+
* @param {String} configId The config ID of the saved config.
|
|
204
|
+
* @param {DynamicFields} fields The dynamic fields payload.
|
|
205
|
+
* @returns {Promise<SavedConfig>} The specified saved config.
|
|
206
|
+
*/
|
|
207
|
+
async config(applicationId, configId, fields = {}) {
|
|
208
|
+
const res = await fetch(`${this.baseUrl}/api/v2/application/${applicationId}/installation/${configId}`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: {
|
|
211
|
+
authorization: `Bearer ${this.token}`,
|
|
212
|
+
},
|
|
213
|
+
body: JSON.stringify(fields),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
if (res.status >= 400 && res.status < 600) {
|
|
217
|
+
throw new Error(res.statusText);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return await res.json();
|
|
221
|
+
}
|
|
222
|
+
|
|
189
223
|
/**
|
|
190
224
|
* Returns the configuration data for the specified application.
|
|
191
225
|
* @param {String} application The application ID.
|
package/cobalt.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Cobalt{constructor(options){this.baseUrl=options
|
|
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;
|
package/docs.md
CHANGED
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
<dt><a href="#Config">Config</a> : <code>object</code></dt>
|
|
13
13
|
<dd><p>The configuration data for an application.</p>
|
|
14
14
|
</dd>
|
|
15
|
+
<dt><a href="#Label">Label</a> : <code>Object</code></dt>
|
|
16
|
+
<dd><p>Field Mapping Label</p>
|
|
17
|
+
</dd>
|
|
18
|
+
<dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
|
|
19
|
+
<dd><p>The dynamic fields payload.</p>
|
|
20
|
+
</dd>
|
|
15
21
|
<dt><a href="#SavedConfig">SavedConfig</a> : <code>Object</code></dt>
|
|
16
22
|
<dd><p>An saved config.</p>
|
|
17
23
|
</dd>
|
|
@@ -40,6 +46,7 @@ Cobalt Frontend SDK
|
|
|
40
46
|
* [.authCustom(applicationId, payload)](#Cobalt+authCustom) ⇒ <code>Promise.<unknown></code>
|
|
41
47
|
* [.checkAuth(application)](#Cobalt+checkAuth) ⇒ <code>Promise.<Boolean></code>
|
|
42
48
|
* [.removeAuth(application, [applicationId])](#Cobalt+removeAuth) ⇒ <code>Promise.<void></code>
|
|
49
|
+
* [.config(applicationId, configId, fields)](#Cobalt+config) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
43
50
|
* [.getConfig(application)](#Cobalt+getConfig) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
44
51
|
* [.saveConfig(applicationId, payload)](#Cobalt+saveConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
45
52
|
* [.getSavedConfig(applicationId, configId)](#Cobalt+getSavedConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
@@ -120,6 +127,20 @@ Unauthorize the specified application and remove any associated data from Cobalt
|
|
|
120
127
|
| application | <code>String</code> | The application type. |
|
|
121
128
|
| [applicationId] | <code>String</code> | The application ID in case of custom applications. |
|
|
122
129
|
|
|
130
|
+
<a name="Cobalt+config"></a>
|
|
131
|
+
|
|
132
|
+
### cobalt.config(applicationId, configId, fields) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
133
|
+
Returns the specified saved config, or creates one if it doesn't exist.
|
|
134
|
+
|
|
135
|
+
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
136
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
137
|
+
|
|
138
|
+
| Param | Type | Description |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| applicationId | <code>String</code> | The application ID. |
|
|
141
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
142
|
+
| fields | [<code>DynamicFields</code>](#DynamicFields) | The dynamic fields payload. |
|
|
143
|
+
|
|
123
144
|
<a name="Cobalt+getConfig"></a>
|
|
124
145
|
|
|
125
146
|
### cobalt.getConfig(application) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
@@ -197,6 +218,31 @@ The configuration data for an application.
|
|
|
197
218
|
| application_data_slots | <code>Array.<DataSlot></code> | Array of application data slots. |
|
|
198
219
|
| workflows | [<code>Array.<Workflow></code>](#Workflow) | Array of workflows. |
|
|
199
220
|
|
|
221
|
+
<a name="Label"></a>
|
|
222
|
+
|
|
223
|
+
## Label : <code>Object</code>
|
|
224
|
+
Field Mapping Label
|
|
225
|
+
|
|
226
|
+
**Kind**: global typedef
|
|
227
|
+
**Properties**
|
|
228
|
+
|
|
229
|
+
| Name | Type | Description |
|
|
230
|
+
| --- | --- | --- |
|
|
231
|
+
| name | <code>string</code> | The Label name. |
|
|
232
|
+
| value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
|
|
233
|
+
|
|
234
|
+
<a name="DynamicFields"></a>
|
|
235
|
+
|
|
236
|
+
## DynamicFields : <code>Object</code>
|
|
237
|
+
The dynamic fields payload.
|
|
238
|
+
|
|
239
|
+
**Kind**: global typedef
|
|
240
|
+
**Properties**
|
|
241
|
+
|
|
242
|
+
| Name | Type | Description |
|
|
243
|
+
| --- | --- | --- |
|
|
244
|
+
| map_field_object | <code>Object.<string, Array.<Label>></code> | desc. |
|
|
245
|
+
|
|
200
246
|
<a name="SavedConfig"></a>
|
|
201
247
|
|
|
202
248
|
## SavedConfig : <code>Object</code>
|