@cobaltio/cobalt-js 1.0.1 → 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 +83 -37
- package/cobalt.js +61 -27
- package/cobalt.min.js +1 -1
- package/docs.md +83 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,11 +59,17 @@ cobalt.token = "COBALT_SESSION_TOKEN";
|
|
|
59
59
|
## Typedefs
|
|
60
60
|
|
|
61
61
|
<dl>
|
|
62
|
-
<dt><a href="#
|
|
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="#
|
|
66
|
-
<dd><p>
|
|
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>
|
|
71
|
+
<dt><a href="#SavedConfig">SavedConfig</a> : <code>Object</code></dt>
|
|
72
|
+
<dd><p>An saved config.</p>
|
|
67
73
|
</dd>
|
|
68
74
|
<dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
|
|
69
75
|
<dd><p>The workflow.</p>
|
|
@@ -90,11 +96,12 @@ 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>
|
|
93
|
-
* [.
|
|
94
|
-
* [.
|
|
95
|
-
* [.
|
|
96
|
-
* [.
|
|
97
|
-
* [.
|
|
99
|
+
* [.config(applicationId, configId, fields)](#Cobalt+config) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
100
|
+
* [.getConfig(application)](#Cobalt+getConfig) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
101
|
+
* [.saveConfig(applicationId, payload)](#Cobalt+saveConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
102
|
+
* [.getSavedConfig(applicationId, configId)](#Cobalt+getSavedConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
103
|
+
* [.updateSavedConfig(applicationId, configId, payload)](#Cobalt+updateSavedConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
104
|
+
* [.deleteSavedConfig(applicationId, configId)](#Cobalt+deleteSavedConfig) ⇒ <code>Promise.<unknown></code>
|
|
98
105
|
|
|
99
106
|
<a name="new_Cobalt_new"></a>
|
|
100
107
|
|
|
@@ -170,73 +177,87 @@ 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
|
|
|
173
|
-
<a name="Cobalt+
|
|
180
|
+
<a name="Cobalt+config"></a>
|
|
174
181
|
|
|
175
|
-
### cobalt.
|
|
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
|
+
|
|
194
|
+
<a name="Cobalt+getConfig"></a>
|
|
195
|
+
|
|
196
|
+
### cobalt.getConfig(application) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
176
197
|
Returns the configuration data for the specified application.
|
|
177
198
|
|
|
178
199
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
179
|
-
**Returns**: [<code>Promise.<
|
|
200
|
+
**Returns**: [<code>Promise.<Config></code>](#Config) - The specified application's configuration data.
|
|
180
201
|
|
|
181
202
|
| Param | Type | Description |
|
|
182
203
|
| --- | --- | --- |
|
|
183
204
|
| application | <code>String</code> | The application ID. |
|
|
184
205
|
|
|
185
|
-
<a name="Cobalt+
|
|
206
|
+
<a name="Cobalt+saveConfig"></a>
|
|
186
207
|
|
|
187
|
-
### cobalt.
|
|
188
|
-
|
|
208
|
+
### cobalt.saveConfig(applicationId, payload) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
209
|
+
Save the specified config.
|
|
189
210
|
|
|
190
211
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
191
|
-
**Returns**: [<code>Promise.<
|
|
212
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
192
213
|
|
|
193
214
|
| Param | Type | Description |
|
|
194
215
|
| --- | --- | --- |
|
|
195
216
|
| applicationId | <code>String</code> | The application ID. |
|
|
196
|
-
| payload | [<code>
|
|
217
|
+
| payload | [<code>SavedConfig</code>](#SavedConfig) | The config payload. |
|
|
197
218
|
|
|
198
|
-
<a name="Cobalt+
|
|
219
|
+
<a name="Cobalt+getSavedConfig"></a>
|
|
199
220
|
|
|
200
|
-
### cobalt.
|
|
201
|
-
Returns the specified
|
|
221
|
+
### cobalt.getSavedConfig(applicationId, configId) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
222
|
+
Returns the specified saved config.
|
|
202
223
|
|
|
203
224
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
204
|
-
**Returns**: [<code>Promise.<
|
|
225
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
205
226
|
|
|
206
227
|
| Param | Type | Description |
|
|
207
228
|
| --- | --- | --- |
|
|
208
229
|
| applicationId | <code>String</code> | The application ID. |
|
|
209
|
-
|
|
|
230
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
210
231
|
|
|
211
|
-
<a name="Cobalt+
|
|
232
|
+
<a name="Cobalt+updateSavedConfig"></a>
|
|
212
233
|
|
|
213
|
-
### cobalt.
|
|
214
|
-
Update the specified
|
|
234
|
+
### cobalt.updateSavedConfig(applicationId, configId, payload) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
235
|
+
Update the specified saved config.
|
|
215
236
|
|
|
216
237
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
217
|
-
**Returns**: [<code>Promise.<
|
|
238
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
218
239
|
|
|
219
240
|
| Param | Type | Description |
|
|
220
241
|
| --- | --- | --- |
|
|
221
242
|
| applicationId | <code>String</code> | The application ID. |
|
|
222
|
-
|
|
|
223
|
-
| payload | [<code>
|
|
243
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
244
|
+
| payload | [<code>SavedConfig</code>](#SavedConfig) | The update payload. |
|
|
224
245
|
|
|
225
|
-
<a name="Cobalt+
|
|
246
|
+
<a name="Cobalt+deleteSavedConfig"></a>
|
|
226
247
|
|
|
227
|
-
### cobalt.
|
|
228
|
-
Delete the specified
|
|
248
|
+
### cobalt.deleteSavedConfig(applicationId, configId) ⇒ <code>Promise.<unknown></code>
|
|
249
|
+
Delete the specified saved config.
|
|
229
250
|
|
|
230
251
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
231
252
|
|
|
232
253
|
| Param | Type | Description |
|
|
233
254
|
| --- | --- | --- |
|
|
234
255
|
| applicationId | <code>String</code> | The application ID. |
|
|
235
|
-
|
|
|
256
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
236
257
|
|
|
237
|
-
<a name="
|
|
258
|
+
<a name="Config"></a>
|
|
238
259
|
|
|
239
|
-
##
|
|
260
|
+
## Config : <code>object</code>
|
|
240
261
|
The configuration data for an application.
|
|
241
262
|
|
|
242
263
|
**Kind**: global typedef
|
|
@@ -247,17 +268,42 @@ 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
|
|
|
250
|
-
<a name="
|
|
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
|
+
|
|
296
|
+
<a name="SavedConfig"></a>
|
|
251
297
|
|
|
252
|
-
##
|
|
253
|
-
An
|
|
298
|
+
## SavedConfig : <code>Object</code>
|
|
299
|
+
An saved config.
|
|
254
300
|
|
|
255
301
|
**Kind**: global typedef
|
|
256
302
|
**Properties**
|
|
257
303
|
|
|
258
304
|
| Name | Type | Description |
|
|
259
305
|
| --- | --- | --- |
|
|
260
|
-
| [
|
|
306
|
+
| [config_id] | <code>String</code> | Unique ID for the saved config. |
|
|
261
307
|
| application_data_slots | <code>Object.<string, (string\|number\|boolean)></code> | A map of application data slots and their values. |
|
|
262
308
|
| workflows | [<code>Array.<Workflow></code>](#Workflow) | Whether the workflow is enabled. |
|
|
263
309
|
|
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() {
|
|
@@ -181,17 +181,51 @@ class Cobalt {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
* @typedef {object}
|
|
184
|
+
* @typedef {object} Config The configuration data for an application.
|
|
185
185
|
* @property {DataSlot[]} application_data_slots Array of application data slots.
|
|
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.
|
|
192
|
-
* @returns {Promise<
|
|
226
|
+
* @returns {Promise<Config>} The specified application's configuration data.
|
|
193
227
|
*/
|
|
194
|
-
async
|
|
228
|
+
async getConfig(application) {
|
|
195
229
|
const res = await fetch(`${this.baseUrl}/api/v1/application/${application}/config`, {
|
|
196
230
|
headers: {
|
|
197
231
|
authorization: `Bearer ${this.token}`,
|
|
@@ -206,8 +240,8 @@ class Cobalt {
|
|
|
206
240
|
}
|
|
207
241
|
|
|
208
242
|
/**
|
|
209
|
-
* @typedef {Object}
|
|
210
|
-
* @property {String} [
|
|
243
|
+
* @typedef {Object} SavedConfig An saved config.
|
|
244
|
+
* @property {String} [config_id] Unique ID for the saved config.
|
|
211
245
|
* @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
|
|
212
246
|
* @property {Workflow[]} workflows Whether the workflow is enabled.
|
|
213
247
|
*/
|
|
@@ -220,12 +254,12 @@ class Cobalt {
|
|
|
220
254
|
*/
|
|
221
255
|
|
|
222
256
|
/**
|
|
223
|
-
*
|
|
257
|
+
* Save the specified config.
|
|
224
258
|
* @param {String} applicationId The application ID.
|
|
225
|
-
* @param {
|
|
226
|
-
* @returns {Promise<
|
|
259
|
+
* @param {SavedConfig} payload The config payload.
|
|
260
|
+
* @returns {Promise<SavedConfig>} The specified saved config.
|
|
227
261
|
*/
|
|
228
|
-
async
|
|
262
|
+
async saveConfig(applicationId, payload = {}) {
|
|
229
263
|
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/install`, {
|
|
230
264
|
method: "POST",
|
|
231
265
|
headers: {
|
|
@@ -243,13 +277,13 @@ class Cobalt {
|
|
|
243
277
|
}
|
|
244
278
|
|
|
245
279
|
/**
|
|
246
|
-
* Returns the specified
|
|
280
|
+
* Returns the specified saved config.
|
|
247
281
|
* @param {String} applicationId The application ID.
|
|
248
|
-
* @param {String}
|
|
249
|
-
* @returns {Promise<
|
|
282
|
+
* @param {String} configId The config ID of the saved config.
|
|
283
|
+
* @returns {Promise<SavedConfig>} The specified saved config.
|
|
250
284
|
*/
|
|
251
|
-
async
|
|
252
|
-
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${
|
|
285
|
+
async getSavedConfig(applicationId, configId) {
|
|
286
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`, {
|
|
253
287
|
headers: {
|
|
254
288
|
authorization: `Bearer ${this.token}`,
|
|
255
289
|
},
|
|
@@ -263,14 +297,14 @@ class Cobalt {
|
|
|
263
297
|
}
|
|
264
298
|
|
|
265
299
|
/**
|
|
266
|
-
* Update the specified
|
|
300
|
+
* Update the specified saved config.
|
|
267
301
|
* @param {String} applicationId The application ID.
|
|
268
|
-
* @param {String}
|
|
269
|
-
* @param {
|
|
270
|
-
* @returns {Promise<
|
|
302
|
+
* @param {String} configId The config ID of the saved config.
|
|
303
|
+
* @param {SavedConfig} payload The update payload.
|
|
304
|
+
* @returns {Promise<SavedConfig>} The specified saved config.
|
|
271
305
|
*/
|
|
272
|
-
async
|
|
273
|
-
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${
|
|
306
|
+
async updateSavedConfig(applicationId, configId, payload = {}) {
|
|
307
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`, {
|
|
274
308
|
method: "PUT",
|
|
275
309
|
headers: {
|
|
276
310
|
authorization: `Bearer ${this.token}`,
|
|
@@ -287,13 +321,13 @@ class Cobalt {
|
|
|
287
321
|
}
|
|
288
322
|
|
|
289
323
|
/**
|
|
290
|
-
* Delete the specified
|
|
324
|
+
* Delete the specified saved config.
|
|
291
325
|
* @param {String} applicationId The application ID.
|
|
292
|
-
* @param {String}
|
|
326
|
+
* @param {String} configId The config ID of the saved config.
|
|
293
327
|
* @returns {Promise<unknown>}
|
|
294
328
|
*/
|
|
295
|
-
async
|
|
296
|
-
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${
|
|
329
|
+
async deleteSavedConfig(applicationId, configId) {
|
|
330
|
+
const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`, {
|
|
297
331
|
method: "DELETE",
|
|
298
332
|
headers: {
|
|
299
333
|
authorization: `Bearer ${this.token}`,
|
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
|
@@ -9,11 +9,17 @@
|
|
|
9
9
|
## Typedefs
|
|
10
10
|
|
|
11
11
|
<dl>
|
|
12
|
-
<dt><a href="#
|
|
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="#
|
|
16
|
-
<dd><p>
|
|
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>
|
|
21
|
+
<dt><a href="#SavedConfig">SavedConfig</a> : <code>Object</code></dt>
|
|
22
|
+
<dd><p>An saved config.</p>
|
|
17
23
|
</dd>
|
|
18
24
|
<dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
|
|
19
25
|
<dd><p>The workflow.</p>
|
|
@@ -40,11 +46,12 @@ 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>
|
|
43
|
-
* [.
|
|
44
|
-
* [.
|
|
45
|
-
* [.
|
|
46
|
-
* [.
|
|
47
|
-
* [.
|
|
49
|
+
* [.config(applicationId, configId, fields)](#Cobalt+config) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
50
|
+
* [.getConfig(application)](#Cobalt+getConfig) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
51
|
+
* [.saveConfig(applicationId, payload)](#Cobalt+saveConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
52
|
+
* [.getSavedConfig(applicationId, configId)](#Cobalt+getSavedConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
53
|
+
* [.updateSavedConfig(applicationId, configId, payload)](#Cobalt+updateSavedConfig) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
54
|
+
* [.deleteSavedConfig(applicationId, configId)](#Cobalt+deleteSavedConfig) ⇒ <code>Promise.<unknown></code>
|
|
48
55
|
|
|
49
56
|
<a name="new_Cobalt_new"></a>
|
|
50
57
|
|
|
@@ -120,73 +127,87 @@ 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
|
|
|
123
|
-
<a name="Cobalt+
|
|
130
|
+
<a name="Cobalt+config"></a>
|
|
124
131
|
|
|
125
|
-
### cobalt.
|
|
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
|
+
|
|
144
|
+
<a name="Cobalt+getConfig"></a>
|
|
145
|
+
|
|
146
|
+
### cobalt.getConfig(application) ⇒ [<code>Promise.<Config></code>](#Config)
|
|
126
147
|
Returns the configuration data for the specified application.
|
|
127
148
|
|
|
128
149
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
129
|
-
**Returns**: [<code>Promise.<
|
|
150
|
+
**Returns**: [<code>Promise.<Config></code>](#Config) - The specified application's configuration data.
|
|
130
151
|
|
|
131
152
|
| Param | Type | Description |
|
|
132
153
|
| --- | --- | --- |
|
|
133
154
|
| application | <code>String</code> | The application ID. |
|
|
134
155
|
|
|
135
|
-
<a name="Cobalt+
|
|
156
|
+
<a name="Cobalt+saveConfig"></a>
|
|
136
157
|
|
|
137
|
-
### cobalt.
|
|
138
|
-
|
|
158
|
+
### cobalt.saveConfig(applicationId, payload) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
159
|
+
Save the specified config.
|
|
139
160
|
|
|
140
161
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
141
|
-
**Returns**: [<code>Promise.<
|
|
162
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
142
163
|
|
|
143
164
|
| Param | Type | Description |
|
|
144
165
|
| --- | --- | --- |
|
|
145
166
|
| applicationId | <code>String</code> | The application ID. |
|
|
146
|
-
| payload | [<code>
|
|
167
|
+
| payload | [<code>SavedConfig</code>](#SavedConfig) | The config payload. |
|
|
147
168
|
|
|
148
|
-
<a name="Cobalt+
|
|
169
|
+
<a name="Cobalt+getSavedConfig"></a>
|
|
149
170
|
|
|
150
|
-
### cobalt.
|
|
151
|
-
Returns the specified
|
|
171
|
+
### cobalt.getSavedConfig(applicationId, configId) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
172
|
+
Returns the specified saved config.
|
|
152
173
|
|
|
153
174
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
154
|
-
**Returns**: [<code>Promise.<
|
|
175
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
155
176
|
|
|
156
177
|
| Param | Type | Description |
|
|
157
178
|
| --- | --- | --- |
|
|
158
179
|
| applicationId | <code>String</code> | The application ID. |
|
|
159
|
-
|
|
|
180
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
160
181
|
|
|
161
|
-
<a name="Cobalt+
|
|
182
|
+
<a name="Cobalt+updateSavedConfig"></a>
|
|
162
183
|
|
|
163
|
-
### cobalt.
|
|
164
|
-
Update the specified
|
|
184
|
+
### cobalt.updateSavedConfig(applicationId, configId, payload) ⇒ [<code>Promise.<SavedConfig></code>](#SavedConfig)
|
|
185
|
+
Update the specified saved config.
|
|
165
186
|
|
|
166
187
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
167
|
-
**Returns**: [<code>Promise.<
|
|
188
|
+
**Returns**: [<code>Promise.<SavedConfig></code>](#SavedConfig) - The specified saved config.
|
|
168
189
|
|
|
169
190
|
| Param | Type | Description |
|
|
170
191
|
| --- | --- | --- |
|
|
171
192
|
| applicationId | <code>String</code> | The application ID. |
|
|
172
|
-
|
|
|
173
|
-
| payload | [<code>
|
|
193
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
194
|
+
| payload | [<code>SavedConfig</code>](#SavedConfig) | The update payload. |
|
|
174
195
|
|
|
175
|
-
<a name="Cobalt+
|
|
196
|
+
<a name="Cobalt+deleteSavedConfig"></a>
|
|
176
197
|
|
|
177
|
-
### cobalt.
|
|
178
|
-
Delete the specified
|
|
198
|
+
### cobalt.deleteSavedConfig(applicationId, configId) ⇒ <code>Promise.<unknown></code>
|
|
199
|
+
Delete the specified saved config.
|
|
179
200
|
|
|
180
201
|
**Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
|
|
181
202
|
|
|
182
203
|
| Param | Type | Description |
|
|
183
204
|
| --- | --- | --- |
|
|
184
205
|
| applicationId | <code>String</code> | The application ID. |
|
|
185
|
-
|
|
|
206
|
+
| configId | <code>String</code> | The config ID of the saved config. |
|
|
186
207
|
|
|
187
|
-
<a name="
|
|
208
|
+
<a name="Config"></a>
|
|
188
209
|
|
|
189
|
-
##
|
|
210
|
+
## Config : <code>object</code>
|
|
190
211
|
The configuration data for an application.
|
|
191
212
|
|
|
192
213
|
**Kind**: global typedef
|
|
@@ -197,17 +218,42 @@ 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
|
|
|
200
|
-
<a name="
|
|
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
|
+
|
|
246
|
+
<a name="SavedConfig"></a>
|
|
201
247
|
|
|
202
|
-
##
|
|
203
|
-
An
|
|
248
|
+
## SavedConfig : <code>Object</code>
|
|
249
|
+
An saved config.
|
|
204
250
|
|
|
205
251
|
**Kind**: global typedef
|
|
206
252
|
**Properties**
|
|
207
253
|
|
|
208
254
|
| Name | Type | Description |
|
|
209
255
|
| --- | --- | --- |
|
|
210
|
-
| [
|
|
256
|
+
| [config_id] | <code>String</code> | Unique ID for the saved config. |
|
|
211
257
|
| application_data_slots | <code>Object.<string, (string\|number\|boolean)></code> | A map of application data slots and their values. |
|
|
212
258
|
| workflows | [<code>Array.<Workflow></code>](#Workflow) | Whether the workflow is enabled. |
|
|
213
259
|
|