@cobaltio/cobalt-js 2.1.4 → 3.0.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
@@ -62,9 +62,6 @@ cobalt.token = "COBALT_SESSION_TOKEN";
62
62
  ## Typedefs
63
63
 
64
64
  <dl>
65
- <dt><a href="#Config">Config</a> : <code>object</code></dt>
66
- <dd><p>The configuration data for an application.</p>
67
- </dd>
68
65
  <dt><a href="#Label">Label</a> : <code>Object</code></dt>
69
66
  <dd><p>Field Mapping Label</p>
70
67
  </dd>
@@ -74,8 +71,8 @@ cobalt.token = "COBALT_SESSION_TOKEN";
74
71
  <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
75
72
  <dd><p>The dynamic fields payload.</p>
76
73
  </dd>
77
- <dt><a href="#SavedConfig">SavedConfig</a> : <code>Object</code></dt>
78
- <dd><p>An saved config.</p>
74
+ <dt><a href="#Config">Config</a> : <code>Object</code></dt>
75
+ <dd><p>The configuration data for an application.</p>
79
76
  </dd>
80
77
  <dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
81
78
  <dd><p>The workflow.</p>
@@ -88,26 +85,17 @@ cobalt.token = "COBALT_SESSION_TOKEN";
88
85
  Cobalt Frontend SDK
89
86
 
90
87
  **Kind**: global class
91
- **Properties**
92
-
93
- | Name | Type | Description |
94
- | --- | --- | --- |
95
- | token | <code>String</code> | The session token. |
96
-
97
88
 
98
89
  * [Cobalt](#Cobalt)
99
90
  * [new Cobalt(options)](#new_Cobalt_new)
100
- * [.oauth(application)](#Cobalt+oauth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
101
- * [.auth(application, payload)](#Cobalt+auth) ⇒ <code>Promise.&lt;unknown&gt;</code>
102
- * [.authCustom(applicationId, payload)](#Cobalt+authCustom) ⇒ <code>Promise.&lt;unknown&gt;</code>
103
- * [.checkAuth(application)](#Cobalt+checkAuth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
104
- * [.removeAuth(application, [applicationId])](#Cobalt+removeAuth) ⇒ <code>Promise.&lt;void&gt;</code>
105
- * [.config(applicationId, configId, fields)](#Cobalt+config) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
106
- * [.getConfig(application)](#Cobalt+getConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
107
- * [.saveConfig(applicationId, payload)](#Cobalt+saveConfig) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
108
- * [.getSavedConfig(applicationId, configId)](#Cobalt+getSavedConfig) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
109
- * [.updateSavedConfig(applicationId, configId, payload)](#Cobalt+updateSavedConfig) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
110
- * [.deleteSavedConfig(applicationId, configId)](#Cobalt+deleteSavedConfig) ⇒ <code>Promise.&lt;unknown&gt;</code>
91
+ * [.connect(slug, [payload])](#Cobalt+connect) ⇒ <code>Promise.&lt;Boolean&gt;</code>
92
+ * [.disconnect(slug)](#Cobalt+disconnect) ⇒ <code>Promise.&lt;void&gt;</code>
93
+ * [.config(slug, configId, [fields])](#Cobalt+config) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
94
+ * [.updateConfig(slug, configId, payload)](#Cobalt+updateConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
95
+ * [.deleteConfig(slug, configId)](#Cobalt+deleteConfig) ⇒ <code>Promise.&lt;unknown&gt;</code>
96
+ * Additional Methods:
97
+ * [.getApp(slug)](#Cobalt+getApp) ⇒ <code>Promise.&lt;Application&gt;</code>
98
+ * [.getConfig(slug, configId)](#Cobalt+getConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
111
99
 
112
100
  <a name="new_Cobalt_new"></a>
113
101
 
@@ -121,158 +109,95 @@ Cobalt Frontend SDK
121
109
  | [options.token] | <code>String</code> | | The session token. |
122
110
  | [options.baseUrl] | <code>String</code> | <code>https://api.gocobalt.io</code> | The base URL of the Cobalt API. |
123
111
 
124
- <a name="Cobalt+oauth"></a>
125
-
126
- ### cobalt.oauth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
127
- Handle OAuth for the specified native application.
128
-
129
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
130
- **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the user authenticated.
131
-
132
- | Param | Type | Description |
133
- | --- | --- | --- |
134
- | application | <code>String</code> | The application type. |
135
-
136
- <a name="Cobalt+auth"></a>
112
+ <a name="Cobalt+getApp"></a>
137
113
 
138
- ### cobalt.auth(application, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
139
- Save the auth data that user provides to authenticate themselves to the
140
- specified native application.
114
+ ### cobalt.getApp(slug) ⇒ <code>Promise.&lt;Application&gt;</code>
115
+ Returns the application details for the specified application, provided
116
+ the application is enabled in Cobalt.
141
117
 
142
118
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
119
+ **Returns**: <code>Promise.&lt;Application&gt;</code> - The application details.
143
120
 
144
121
  | Param | Type | Description |
145
122
  | --- | --- | --- |
146
- | application | <code>String</code> | The application type. |
147
- | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
123
+ | slug | <code>String</code> | The application slug. |
148
124
 
149
- <a name="Cobalt+authCustom"></a>
125
+ <a name="Cobalt+connect"></a>
150
126
 
151
- ### cobalt.authCustom(applicationId, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
152
- Save the auth data that user provides to authenticate themselves to the
153
- specified custom application.
127
+ ### cobalt.connect(slug, [payload]) ⇒ <code>Promise.&lt;Boolean&gt;</code>
128
+ Connect the specified application, optionally with the auth data that user provides.
154
129
 
155
130
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
131
+ **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the connection was successful.
156
132
 
157
- | Param | Type | Description |
158
- | --- | --- | --- |
159
- | applicationId | <code>String</code> | The application ID of the custom application. |
160
- | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
161
-
162
- <a name="Cobalt+checkAuth"></a>
163
-
164
- ### cobalt.checkAuth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
165
- Returns the auth status of the user for the specified application.
166
-
167
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
168
- **Returns**: <code>Promise.&lt;Boolean&gt;</code> - The auth status of the user.
169
-
170
- | Param | Type | Description |
171
- | --- | --- | --- |
172
- | application | <code>String</code> | The application type. |
133
+ | Param | Type | Default | Description |
134
+ | --- | --- | --- | --- |
135
+ | slug | <code>String</code> | | The application slug. |
136
+ | [payload] | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | <code>{}</code> | The key value pairs of auth data. |
173
137
 
174
- <a name="Cobalt+removeAuth"></a>
138
+ <a name="Cobalt+disconnect"></a>
175
139
 
176
- ### cobalt.removeAuth(application, [applicationId]) ⇒ <code>Promise.&lt;void&gt;</code>
177
- Unauthorize the specified application and remove any associated data from Cobalt.
140
+ ### cobalt.disconnect(slug) ⇒ <code>Promise.&lt;void&gt;</code>
141
+ Disconnect the specified application and remove any associated data from Cobalt.
178
142
 
179
143
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
180
144
 
181
145
  | Param | Type | Description |
182
146
  | --- | --- | --- |
183
- | application | <code>String</code> | The application type. |
184
- | [applicationId] | <code>String</code> | The application ID in case of custom applications. |
147
+ | slug | <code>String</code> | The application slug. |
185
148
 
186
149
  <a name="Cobalt+config"></a>
187
150
 
188
- ### cobalt.config(applicationId, configId, fields) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
189
- Returns the specified saved config, or creates one if it doesn't exist.
151
+ ### cobalt.config(slug, configId, [fields]) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
152
+ Returns the specified config, or creates one if it doesn't exist.
190
153
 
191
154
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
192
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
155
+ **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified config.
193
156
 
194
157
  | Param | Type | Description |
195
158
  | --- | --- | --- |
196
- | applicationId | <code>String</code> | The application ID. |
197
- | configId | <code>String</code> | The config ID of the saved config. |
198
- | fields | [<code>DynamicFields</code>](#DynamicFields) | The dynamic fields payload. |
159
+ | slug | <code>String</code> | The application slug. |
160
+ | configId | <code>String</code> | A unique ID for the config. |
161
+ | [fields] | [<code>DynamicFields</code>](#DynamicFields) | The dynamic fields payload. |
199
162
 
200
163
  <a name="Cobalt+getConfig"></a>
201
164
 
202
- ### cobalt.getConfig(application) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
203
- Returns the configuration data for the specified application.
165
+ ### cobalt.getConfig(slug, configId) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
166
+ Returns the specified config.
204
167
 
205
168
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
206
- **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified application's configuration data.
169
+ **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified config.
207
170
 
208
171
  | Param | Type | Description |
209
172
  | --- | --- | --- |
210
- | application | <code>String</code> | The application ID. |
173
+ | slug | <code>String</code> | The application slug. |
174
+ | configId | <code>String</code> | The unique ID of the config. |
211
175
 
212
- <a name="Cobalt+saveConfig"></a>
176
+ <a name="Cobalt+updateConfig"></a>
213
177
 
214
- ### cobalt.saveConfig(applicationId, payload) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
215
- Save the specified config.
178
+ ### cobalt.updateConfig(slug, configId, payload) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
179
+ Update the specified config.
216
180
 
217
181
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
218
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
182
+ **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified config.
219
183
 
220
184
  | Param | Type | Description |
221
185
  | --- | --- | --- |
222
- | applicationId | <code>String</code> | The application ID. |
223
- | payload | [<code>SavedConfig</code>](#SavedConfig) | The config payload. |
186
+ | slug | <code>String</code> | The application slug. |
187
+ | configId | <code>String</code> | The unique ID of the config. |
188
+ | payload | [<code>Config</code>](#Config) | The update payload. |
224
189
 
225
- <a name="Cobalt+getSavedConfig"></a>
190
+ <a name="Cobalt+deleteConfig"></a>
226
191
 
227
- ### cobalt.getSavedConfig(applicationId, configId) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
228
- Returns the specified saved config.
192
+ ### cobalt.deleteConfig(slug, configId) ⇒ <code>Promise.&lt;unknown&gt;</code>
193
+ Delete the specified config.
229
194
 
230
195
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
231
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
232
196
 
233
197
  | Param | Type | Description |
234
198
  | --- | --- | --- |
235
- | applicationId | <code>String</code> | The application ID. |
236
- | configId | <code>String</code> | The config ID of the saved config. |
237
-
238
- <a name="Cobalt+updateSavedConfig"></a>
239
-
240
- ### cobalt.updateSavedConfig(applicationId, configId, payload) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
241
- Update the specified saved config.
242
-
243
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
244
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
245
-
246
- | Param | Type | Description |
247
- | --- | --- | --- |
248
- | applicationId | <code>String</code> | The application ID. |
249
- | configId | <code>String</code> | The config ID of the saved config. |
250
- | payload | [<code>SavedConfig</code>](#SavedConfig) | The update payload. |
251
-
252
- <a name="Cobalt+deleteSavedConfig"></a>
253
-
254
- ### cobalt.deleteSavedConfig(applicationId, configId) ⇒ <code>Promise.&lt;unknown&gt;</code>
255
- Delete the specified saved config.
256
-
257
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
258
-
259
- | Param | Type | Description |
260
- | --- | --- | --- |
261
- | applicationId | <code>String</code> | The application ID. |
262
- | configId | <code>String</code> | The config ID of the saved config. |
263
-
264
- <a name="Config"></a>
265
-
266
- ## Config : <code>object</code>
267
- The configuration data for an application.
268
-
269
- **Kind**: global typedef
270
- **Properties**
271
-
272
- | Name | Type | Description |
273
- | --- | --- | --- |
274
- | application_data_slots | <code>Array.&lt;DataSlot&gt;</code> | Array of application data slots. |
275
- | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Array of workflows. |
199
+ | slug | <code>String</code> | The application slug. |
200
+ | configId | <code>String</code> | The unique ID of the config. |
276
201
 
277
202
  <a name="Label"></a>
278
203
 
@@ -311,17 +236,17 @@ The dynamic fields payload.
311
236
  | --- | --- | --- |
312
237
  | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
313
238
 
314
- <a name="SavedConfig"></a>
239
+ <a name="Config"></a>
315
240
 
316
- ## SavedConfig : <code>Object</code>
317
- An saved config.
241
+ ## Config : <code>Object</code>
242
+ The configuration data for an application.
318
243
 
319
244
  **Kind**: global typedef
320
245
  **Properties**
321
246
 
322
247
  | Name | Type | Description |
323
248
  | --- | --- | --- |
324
- | [config_id] | <code>String</code> | Unique ID for the saved config. |
249
+ | [config_id] | <code>String</code> | Unique ID for the config. |
325
250
  | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
326
251
  | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Whether the workflow is enabled. |
327
252
 
package/cobalt.js CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Cobalt Frontend SDK
3
- * @property {String} token The session token.
4
3
  */
5
4
  class Cobalt {
6
5
  /**
@@ -22,15 +21,36 @@ class Cobalt {
22
21
  return this.sessionToken = typeof token === "string" ? token : "";
23
22
  };
24
23
 
24
+ /**
25
+ * Returns the application details for the specified application, provided
26
+ * the application is enabled in Cobalt.
27
+ * @param {String} slug The application slug.
28
+ * @returns {Promise<Application>} The application details.
29
+ */
30
+ async getApp(slug) {
31
+ const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/application/${slug}`, {
32
+ headers: {
33
+ authorization: `Bearer ${this.token}`,
34
+ },
35
+ });
36
+
37
+ if (res.status >= 400 && res.status < 600) {
38
+ throw new Error(res.statusText);
39
+ }
40
+
41
+ const data = await res.json();
42
+ return data;
43
+ }
44
+
25
45
  /**
26
46
  * Returns the auth URL that users can use to authenticate themselves to the
27
47
  * specified application.
28
48
  * @private
29
- * @param {String} application The application type.
49
+ * @param {String} slug The application slug.
30
50
  * @returns {Promise<String>} The auth URL where users can authenticate themselves.
31
51
  */
32
- async getOAuthUrl(application) {
33
- const res = await fetch(`${this.baseUrl}/api/v1/${application}/integrate`, {
52
+ async getOAuthUrl(slug) {
53
+ const res = await fetch(`${this.baseUrl}/api/v1/${slug}/integrate`, {
34
54
  headers: {
35
55
  authorization: `Bearer ${this.token}`,
36
56
  },
@@ -46,20 +66,21 @@ class Cobalt {
46
66
 
47
67
  /**
48
68
  * Handle OAuth for the specified native application.
49
- * @param {String} application The application type.
69
+ * @private
70
+ * @param {String} slug The application slug.
50
71
  * @returns {Promise<Boolean>} Whether the user authenticated.
51
72
  */
52
- async oauth(application) {
73
+ async oauth(slug) {
53
74
  return new Promise((resolve, reject) => {
54
- this.getOAuthUrl(application)
75
+ this.getOAuthUrl(slug)
55
76
  .then(oauthUrl => {
56
77
  const connectWindow = window.open(oauthUrl);
57
78
 
58
79
  // keep checking connection status
59
80
  const interval = setInterval(() => {
60
- this.checkAuth(application)
61
- .then(connected => {
62
- if (connected === true) {
81
+ this.getApp(slug)
82
+ .then(app => {
83
+ if (app && app.connected === true) {
63
84
  // close auth window
64
85
  connectWindow && connectWindow.close();
65
86
  // clear interval
@@ -88,87 +109,44 @@ class Cobalt {
88
109
  }
89
110
 
90
111
  /**
91
- * Save the auth data that user provides to authenticate themselves to the
92
- * specified native application.
93
- * @param {String} application The application type.
94
- * @param {Object.<string, string | number | boolean>} payload The key value pairs of auth data.
95
- * @returns {Promise<unknown>}
96
- */
97
- async auth(application, payload) {
98
- const res = await fetch(`${this.baseUrl}/api/v1/${application}/save`, {
99
- method: "POST",
100
- headers: {
101
- authorization: `Bearer ${this.token}`,
102
- "content-type": "application/json",
103
- },
104
- body: JSON.stringify({
105
- ...payload,
106
- }),
107
- });
108
-
109
- if (res.status >= 400 && res.status < 600) {
110
- throw new Error(res.statusText);
111
- }
112
-
113
- const data = await res.json();
114
- return data;
115
- }
116
-
117
- /**
118
- * Save the auth data that user provides to authenticate themselves to the
119
- * specified custom application.
120
- * @param {String} applicationId The application ID of the custom application.
121
- * @param {Object.<string, string | number | boolean>} payload The key value pairs of auth data.
122
- * @returns {Promise<unknown>}
112
+ * Connect the specified application, optionally with the auth data that user provides.
113
+ * @param {String} slug The application slug.
114
+ * @param {Object.<string, string | number | boolean>} [payload={}] The key value pairs of auth data.
115
+ * @returns {Promise<Boolean>} Whether the connection was successful.
123
116
  */
124
- async authCustom(applicationId, payload) {
125
- const res = await fetch(`${this.baseUrl}/api/v1/custom/${applicationId}/save`, {
126
- method: "POST",
127
- headers: {
128
- authorization: `Bearer ${this.token}`,
129
- "content-type": "application/json",
130
- },
131
- body: JSON.stringify({
132
- ...payload,
133
- }),
134
- });
135
-
136
- if (res.status >= 400 && res.status < 600) {
137
- throw new Error(res.statusText);
117
+ async connect(slug, payload) {
118
+ if (payload) {
119
+ // save auth
120
+ const res = await fetch(`${this.baseUrl}/api/v2/app/${slug}/save`, {
121
+ method: "POST",
122
+ headers: {
123
+ authorization: `Bearer ${this.token}`,
124
+ "content-type": "application/json",
125
+ },
126
+ body: JSON.stringify({
127
+ ...payload,
128
+ }),
129
+ });
130
+
131
+ if (res.status >= 400 && res.status < 600) {
132
+ throw new Error(res.statusText);
133
+ }
134
+
135
+ const data = await res.json();
136
+ return data.success;
137
+ } else {
138
+ // oauth
139
+ return this.oauth(slug);
138
140
  }
139
-
140
- const data = await res.json();
141
- return data;
142
141
  }
143
142
 
144
143
  /**
145
- * Returns the auth status of the user for the specified application.
146
- * @param {String} application The application type.
147
- * @returns {Promise<Boolean>} The auth status of the user.
148
- */
149
- async checkAuth(application) {
150
- const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`, {
151
- headers: {
152
- authorization: `Bearer ${this.token}`,
153
- },
154
- });
155
-
156
- if (res.status >= 400 && res.status < 600) {
157
- throw new Error(res.statusText);
158
- }
159
-
160
- const data = await res.json();
161
- return !!data.status;
162
- }
163
-
164
- /**
165
- * Unauthorize the specified application and remove any associated data from Cobalt.
166
- * @param {String} application The application type.
167
- * @param {String} [applicationId] The application ID in case of custom applications.
144
+ * Disconnect the specified application and remove any associated data from Cobalt.
145
+ * @param {String} slug The application slug.
168
146
  * @returns {Promise<void>}
169
147
  */
170
- async removeAuth(application, applicationId) {
171
- const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${applicationId}`, {
148
+ async disconnect(slug) {
149
+ const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${slug}`, {
172
150
  method: "DELETE",
173
151
  headers: {
174
152
  authorization: `Bearer ${this.token}`,
@@ -180,12 +158,6 @@ class Cobalt {
180
158
  }
181
159
  }
182
160
 
183
- /**
184
- * @typedef {object} Config The configuration data for an application.
185
- * @property {DataSlot[]} application_data_slots Array of application data slots.
186
- * @property {Workflow[]} workflows Array of workflows.
187
- */
188
-
189
161
  /**
190
162
  * @typedef {Object} Label Field Mapping Label
191
163
  * @property {string} name The Label name.
@@ -203,14 +175,14 @@ class Cobalt {
203
175
  */
204
176
 
205
177
  /**
206
- * Returns the specified saved config, or creates one if it doesn't exist.
207
- * @param {String} applicationId The application ID.
208
- * @param {String} configId The config ID of the saved config.
209
- * @param {DynamicFields} fields The dynamic fields payload.
210
- * @returns {Promise<SavedConfig>} The specified saved config.
178
+ * Returns the specified config, or creates one if it doesn't exist.
179
+ * @param {String} slug The application slug.
180
+ * @param {String} configId A unique ID for the config.
181
+ * @param {DynamicFields} [fields] The dynamic fields payload.
182
+ * @returns {Promise<Config>} The specified config.
211
183
  */
212
- async config(applicationId, configId, fields = {}) {
213
- const res = await fetch(`${this.baseUrl}/api/v2/application/${applicationId}/installation/${configId}`, {
184
+ async config(slug, configId, fields) {
185
+ const res = await fetch(`${this.baseUrl}/api/v2/application/${slug}/installation/${configId}`, {
214
186
  method: "POST",
215
187
  headers: {
216
188
  authorization: `Bearer ${this.token}`,
@@ -227,27 +199,8 @@ class Cobalt {
227
199
  }
228
200
 
229
201
  /**
230
- * Returns the configuration data for the specified application.
231
- * @param {String} application The application ID.
232
- * @returns {Promise<Config>} The specified application's configuration data.
233
- */
234
- async getConfig(application) {
235
- const res = await fetch(`${this.baseUrl}/api/v1/application/${application}/config`, {
236
- headers: {
237
- authorization: `Bearer ${this.token}`,
238
- },
239
- });
240
-
241
- if (res.status >= 400 && res.status < 600) {
242
- throw new Error(res.statusText);
243
- }
244
-
245
- return await res.json();
246
- }
247
-
248
- /**
249
- * @typedef {Object} SavedConfig An saved config.
250
- * @property {String} [config_id] Unique ID for the saved config.
202
+ * @typedef {Object} Config The configuration data for an application.
203
+ * @property {String} [config_id] Unique ID for the config.
251
204
  * @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
252
205
  * @property {Workflow[]} workflows Whether the workflow is enabled.
253
206
  */
@@ -260,36 +213,13 @@ class Cobalt {
260
213
  */
261
214
 
262
215
  /**
263
- * Save the specified config.
264
- * @param {String} applicationId The application ID.
265
- * @param {SavedConfig} payload The config payload.
266
- * @returns {Promise<SavedConfig>} The specified saved config.
267
- */
268
- async saveConfig(applicationId, payload = {}) {
269
- const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/install`, {
270
- method: "POST",
271
- headers: {
272
- authorization: `Bearer ${this.token}`,
273
- "content-type": "application/json",
274
- },
275
- body: JSON.stringify(payload),
276
- });
277
-
278
- if (res.status >= 400 && res.status < 600) {
279
- throw new Error(res.statusText);
280
- }
281
-
282
- return await res.json();
283
- }
284
-
285
- /**
286
- * Returns the specified saved config.
287
- * @param {String} applicationId The application ID.
288
- * @param {String} configId The config ID of the saved config.
289
- * @returns {Promise<SavedConfig>} The specified saved config.
216
+ * Returns the specified config.
217
+ * @param {String} slug The application slug.
218
+ * @param {String} configId The unique ID of the config.
219
+ * @returns {Promise<Config>} The specified config.
290
220
  */
291
- async getSavedConfig(applicationId, configId) {
292
- const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`, {
221
+ async getConfig(slug, configId) {
222
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${slug}/installation/${configId}`, {
293
223
  headers: {
294
224
  authorization: `Bearer ${this.token}`,
295
225
  },
@@ -303,14 +233,14 @@ class Cobalt {
303
233
  }
304
234
 
305
235
  /**
306
- * Update the specified saved config.
307
- * @param {String} applicationId The application ID.
308
- * @param {String} configId The config ID of the saved config.
309
- * @param {SavedConfig} payload The update payload.
310
- * @returns {Promise<SavedConfig>} The specified saved config.
236
+ * Update the specified config.
237
+ * @param {String} slug The application slug.
238
+ * @param {String} configId The unique ID of the config.
239
+ * @param {Config} payload The update payload.
240
+ * @returns {Promise<Config>} The specified config.
311
241
  */
312
- async updateSavedConfig(applicationId, configId, payload = {}) {
313
- const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`, {
242
+ async updateConfig(slug, configId, payload = {}) {
243
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${slug}/installation/${configId}`, {
314
244
  method: "PUT",
315
245
  headers: {
316
246
  authorization: `Bearer ${this.token}`,
@@ -327,13 +257,13 @@ class Cobalt {
327
257
  }
328
258
 
329
259
  /**
330
- * Delete the specified saved config.
331
- * @param {String} applicationId The application ID.
332
- * @param {String} configId The config ID of the saved config.
260
+ * Delete the specified config.
261
+ * @param {String} slug The application slug.
262
+ * @param {String} configId The unique ID of the config.
333
263
  * @returns {Promise<unknown>}
334
264
  */
335
- async deleteSavedConfig(applicationId, configId) {
336
- const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${configId}`, {
265
+ async deleteConfig(slug, configId) {
266
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${slug}/installation/${configId}`, {
337
267
  method: "DELETE",
338
268
  headers: {
339
269
  authorization: `Bearer ${this.token}`,
package/docs.md CHANGED
@@ -9,9 +9,6 @@
9
9
  ## Typedefs
10
10
 
11
11
  <dl>
12
- <dt><a href="#Config">Config</a> : <code>object</code></dt>
13
- <dd><p>The configuration data for an application.</p>
14
- </dd>
15
12
  <dt><a href="#Label">Label</a> : <code>Object</code></dt>
16
13
  <dd><p>Field Mapping Label</p>
17
14
  </dd>
@@ -21,8 +18,8 @@
21
18
  <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
22
19
  <dd><p>The dynamic fields payload.</p>
23
20
  </dd>
24
- <dt><a href="#SavedConfig">SavedConfig</a> : <code>Object</code></dt>
25
- <dd><p>An saved config.</p>
21
+ <dt><a href="#Config">Config</a> : <code>Object</code></dt>
22
+ <dd><p>The configuration data for an application.</p>
26
23
  </dd>
27
24
  <dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
28
25
  <dd><p>The workflow.</p>
@@ -35,26 +32,16 @@
35
32
  Cobalt Frontend SDK
36
33
 
37
34
  **Kind**: global class
38
- **Properties**
39
-
40
- | Name | Type | Description |
41
- | --- | --- | --- |
42
- | token | <code>String</code> | The session token. |
43
-
44
35
 
45
36
  * [Cobalt](#Cobalt)
46
37
  * [new Cobalt(options)](#new_Cobalt_new)
47
- * [.oauth(application)](#Cobalt+oauth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
48
- * [.auth(application, payload)](#Cobalt+auth) ⇒ <code>Promise.&lt;unknown&gt;</code>
49
- * [.authCustom(applicationId, payload)](#Cobalt+authCustom) ⇒ <code>Promise.&lt;unknown&gt;</code>
50
- * [.checkAuth(application)](#Cobalt+checkAuth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
51
- * [.removeAuth(application, [applicationId])](#Cobalt+removeAuth) ⇒ <code>Promise.&lt;void&gt;</code>
52
- * [.config(applicationId, configId, fields)](#Cobalt+config) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
53
- * [.getConfig(application)](#Cobalt+getConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
54
- * [.saveConfig(applicationId, payload)](#Cobalt+saveConfig) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
55
- * [.getSavedConfig(applicationId, configId)](#Cobalt+getSavedConfig) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
56
- * [.updateSavedConfig(applicationId, configId, payload)](#Cobalt+updateSavedConfig) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
57
- * [.deleteSavedConfig(applicationId, configId)](#Cobalt+deleteSavedConfig) ⇒ <code>Promise.&lt;unknown&gt;</code>
38
+ * [.getApp(slug)](#Cobalt+getApp) ⇒ <code>Promise.&lt;Application&gt;</code>
39
+ * [.connect(slug, [payload])](#Cobalt+connect) ⇒ <code>Promise.&lt;Boolean&gt;</code>
40
+ * [.disconnect(slug)](#Cobalt+disconnect) ⇒ <code>Promise.&lt;void&gt;</code>
41
+ * [.config(slug, configId, [fields])](#Cobalt+config) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
42
+ * [.getConfig(slug, configId)](#Cobalt+getConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
43
+ * [.updateConfig(slug, configId, payload)](#Cobalt+updateConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
44
+ * [.deleteConfig(slug, configId)](#Cobalt+deleteConfig) ⇒ <code>Promise.&lt;unknown&gt;</code>
58
45
 
59
46
  <a name="new_Cobalt_new"></a>
60
47
 
@@ -68,158 +55,95 @@ Cobalt Frontend SDK
68
55
  | [options.token] | <code>String</code> | | The session token. |
69
56
  | [options.baseUrl] | <code>String</code> | <code>https://api.gocobalt.io</code> | The base URL of the Cobalt API. |
70
57
 
71
- <a name="Cobalt+oauth"></a>
72
-
73
- ### cobalt.oauth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
74
- Handle OAuth for the specified native application.
75
-
76
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
77
- **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the user authenticated.
78
-
79
- | Param | Type | Description |
80
- | --- | --- | --- |
81
- | application | <code>String</code> | The application type. |
82
-
83
- <a name="Cobalt+auth"></a>
58
+ <a name="Cobalt+getApp"></a>
84
59
 
85
- ### cobalt.auth(application, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
86
- Save the auth data that user provides to authenticate themselves to the
87
- specified native application.
60
+ ### cobalt.getApp(slug) ⇒ <code>Promise.&lt;Application&gt;</code>
61
+ Returns the application details for the specified application, provided
62
+ the application is enabled in Cobalt.
88
63
 
89
64
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
65
+ **Returns**: <code>Promise.&lt;Application&gt;</code> - The application details.
90
66
 
91
67
  | Param | Type | Description |
92
68
  | --- | --- | --- |
93
- | application | <code>String</code> | The application type. |
94
- | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
69
+ | slug | <code>String</code> | The application slug. |
95
70
 
96
- <a name="Cobalt+authCustom"></a>
71
+ <a name="Cobalt+connect"></a>
97
72
 
98
- ### cobalt.authCustom(applicationId, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
99
- Save the auth data that user provides to authenticate themselves to the
100
- specified custom application.
73
+ ### cobalt.connect(slug, [payload]) ⇒ <code>Promise.&lt;Boolean&gt;</code>
74
+ Connect the specified application, optionally with the auth data that user provides.
101
75
 
102
76
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
77
+ **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the connection was successful.
103
78
 
104
- | Param | Type | Description |
105
- | --- | --- | --- |
106
- | applicationId | <code>String</code> | The application ID of the custom application. |
107
- | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
108
-
109
- <a name="Cobalt+checkAuth"></a>
110
-
111
- ### cobalt.checkAuth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
112
- Returns the auth status of the user for the specified application.
113
-
114
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
115
- **Returns**: <code>Promise.&lt;Boolean&gt;</code> - The auth status of the user.
116
-
117
- | Param | Type | Description |
118
- | --- | --- | --- |
119
- | application | <code>String</code> | The application type. |
79
+ | Param | Type | Default | Description |
80
+ | --- | --- | --- | --- |
81
+ | slug | <code>String</code> | | The application slug. |
82
+ | [payload] | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | <code>{}</code> | The key value pairs of auth data. |
120
83
 
121
- <a name="Cobalt+removeAuth"></a>
84
+ <a name="Cobalt+disconnect"></a>
122
85
 
123
- ### cobalt.removeAuth(application, [applicationId]) ⇒ <code>Promise.&lt;void&gt;</code>
124
- Unauthorize the specified application and remove any associated data from Cobalt.
86
+ ### cobalt.disconnect(slug) ⇒ <code>Promise.&lt;void&gt;</code>
87
+ Disconnect the specified application and remove any associated data from Cobalt.
125
88
 
126
89
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
127
90
 
128
91
  | Param | Type | Description |
129
92
  | --- | --- | --- |
130
- | application | <code>String</code> | The application type. |
131
- | [applicationId] | <code>String</code> | The application ID in case of custom applications. |
93
+ | slug | <code>String</code> | The application slug. |
132
94
 
133
95
  <a name="Cobalt+config"></a>
134
96
 
135
- ### cobalt.config(applicationId, configId, fields) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
136
- Returns the specified saved config, or creates one if it doesn't exist.
97
+ ### cobalt.config(slug, configId, [fields]) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
98
+ Returns the specified config, or creates one if it doesn't exist.
137
99
 
138
100
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
139
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
101
+ **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified config.
140
102
 
141
103
  | Param | Type | Description |
142
104
  | --- | --- | --- |
143
- | applicationId | <code>String</code> | The application ID. |
144
- | configId | <code>String</code> | The config ID of the saved config. |
145
- | fields | [<code>DynamicFields</code>](#DynamicFields) | The dynamic fields payload. |
105
+ | slug | <code>String</code> | The application slug. |
106
+ | configId | <code>String</code> | A unique ID for the config. |
107
+ | [fields] | [<code>DynamicFields</code>](#DynamicFields) | The dynamic fields payload. |
146
108
 
147
109
  <a name="Cobalt+getConfig"></a>
148
110
 
149
- ### cobalt.getConfig(application) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
150
- Returns the configuration data for the specified application.
111
+ ### cobalt.getConfig(slug, configId) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
112
+ Returns the specified config.
151
113
 
152
114
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
153
- **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified application's configuration data.
115
+ **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified config.
154
116
 
155
117
  | Param | Type | Description |
156
118
  | --- | --- | --- |
157
- | application | <code>String</code> | The application ID. |
119
+ | slug | <code>String</code> | The application slug. |
120
+ | configId | <code>String</code> | The unique ID of the config. |
158
121
 
159
- <a name="Cobalt+saveConfig"></a>
122
+ <a name="Cobalt+updateConfig"></a>
160
123
 
161
- ### cobalt.saveConfig(applicationId, payload) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
162
- Save the specified config.
124
+ ### cobalt.updateConfig(slug, configId, payload) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
125
+ Update the specified config.
163
126
 
164
127
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
165
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
128
+ **Returns**: [<code>Promise.&lt;Config&gt;</code>](#Config) - The specified config.
166
129
 
167
130
  | Param | Type | Description |
168
131
  | --- | --- | --- |
169
- | applicationId | <code>String</code> | The application ID. |
170
- | payload | [<code>SavedConfig</code>](#SavedConfig) | The config payload. |
132
+ | slug | <code>String</code> | The application slug. |
133
+ | configId | <code>String</code> | The unique ID of the config. |
134
+ | payload | [<code>Config</code>](#Config) | The update payload. |
171
135
 
172
- <a name="Cobalt+getSavedConfig"></a>
136
+ <a name="Cobalt+deleteConfig"></a>
173
137
 
174
- ### cobalt.getSavedConfig(applicationId, configId) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
175
- Returns the specified saved config.
138
+ ### cobalt.deleteConfig(slug, configId) ⇒ <code>Promise.&lt;unknown&gt;</code>
139
+ Delete the specified config.
176
140
 
177
141
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
178
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
179
142
 
180
143
  | Param | Type | Description |
181
144
  | --- | --- | --- |
182
- | applicationId | <code>String</code> | The application ID. |
183
- | configId | <code>String</code> | The config ID of the saved config. |
184
-
185
- <a name="Cobalt+updateSavedConfig"></a>
186
-
187
- ### cobalt.updateSavedConfig(applicationId, configId, payload) ⇒ [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig)
188
- Update the specified saved config.
189
-
190
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
191
- **Returns**: [<code>Promise.&lt;SavedConfig&gt;</code>](#SavedConfig) - The specified saved config.
192
-
193
- | Param | Type | Description |
194
- | --- | --- | --- |
195
- | applicationId | <code>String</code> | The application ID. |
196
- | configId | <code>String</code> | The config ID of the saved config. |
197
- | payload | [<code>SavedConfig</code>](#SavedConfig) | The update payload. |
198
-
199
- <a name="Cobalt+deleteSavedConfig"></a>
200
-
201
- ### cobalt.deleteSavedConfig(applicationId, configId) ⇒ <code>Promise.&lt;unknown&gt;</code>
202
- Delete the specified saved config.
203
-
204
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
205
-
206
- | Param | Type | Description |
207
- | --- | --- | --- |
208
- | applicationId | <code>String</code> | The application ID. |
209
- | configId | <code>String</code> | The config ID of the saved config. |
210
-
211
- <a name="Config"></a>
212
-
213
- ## Config : <code>object</code>
214
- The configuration data for an application.
215
-
216
- **Kind**: global typedef
217
- **Properties**
218
-
219
- | Name | Type | Description |
220
- | --- | --- | --- |
221
- | application_data_slots | <code>Array.&lt;DataSlot&gt;</code> | Array of application data slots. |
222
- | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Array of workflows. |
145
+ | slug | <code>String</code> | The application slug. |
146
+ | configId | <code>String</code> | The unique ID of the config. |
223
147
 
224
148
  <a name="Label"></a>
225
149
 
@@ -258,17 +182,17 @@ The dynamic fields payload.
258
182
  | --- | --- | --- |
259
183
  | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
260
184
 
261
- <a name="SavedConfig"></a>
185
+ <a name="Config"></a>
262
186
 
263
- ## SavedConfig : <code>Object</code>
264
- An saved config.
187
+ ## Config : <code>Object</code>
188
+ The configuration data for an application.
265
189
 
266
190
  **Kind**: global typedef
267
191
  **Properties**
268
192
 
269
193
  | Name | Type | Description |
270
194
  | --- | --- | --- |
271
- | [config_id] | <code>String</code> | Unique ID for the saved config. |
195
+ | [config_id] | <code>String</code> | Unique ID for the config. |
272
196
  | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
273
197
  | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Whether the workflow is enabled. |
274
198
 
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "2.1.4",
3
+ "version": "3.0.1",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {
7
- "build": "uglifyjs cobalt.js -o cobalt.min.js",
8
7
  "docgen": "jsdoc2md cobalt.js > docs.md",
9
8
  "test": "echo \"Warn: no test specified\""
10
9
  },
@@ -29,8 +28,7 @@
29
28
  },
30
29
  "homepage": "https://github.com/Breakout-Embed/cobalt-js#readme",
31
30
  "devDependencies": {
32
- "jsdoc": "^4.0.0",
33
- "jsdoc-to-markdown": "^8.0.0",
34
- "uglify-js": "^3.17.4"
31
+ "jsdoc": "^4.0.2",
32
+ "jsdoc-to-markdown": "^8.0.0"
35
33
  }
36
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;