@cobaltio/cobalt-js 3.0.2 → 3.0.3

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 (4) hide show
  1. package/README.md +56 -38
  2. package/cobalt.js +56 -44
  3. package/docs.md +55 -37
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -59,8 +59,7 @@ cobalt.token = "COBALT_SESSION_TOKEN";
59
59
 
60
60
  <dl>
61
61
  <dt><a href="#Cobalt">Cobalt</a></dt>
62
- <dd><p>Cobalt Frontend SDK</p>
63
- </dd>
62
+ <dd></dd>
64
63
  </dl>
65
64
 
66
65
  ## Typedefs
@@ -69,14 +68,8 @@ cobalt.token = "COBALT_SESSION_TOKEN";
69
68
  <dt><a href="#Application">Application</a> : <code>Object</code></dt>
70
69
  <dd><p>An application in Cobalt.</p>
71
70
  </dd>
72
- <dt><a href="#Label">Label</a> : <code>Object</code></dt>
73
- <dd><p>Field Mapping Label</p>
74
- </dd>
75
- <dt><a href="#DynamicField">DynamicField</a> : <code>Object</code></dt>
76
- <dd><p>Field Mapping Label</p>
77
- </dd>
78
- <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
79
- <dd><p>The dynamic fields payload.</p>
71
+ <dt><a href="#InputField">InputField</a> : <code>Object</code></dt>
72
+ <dd><p>An Input field to take input from the user.</p>
80
73
  </dd>
81
74
  <dt><a href="#Config">Config</a> : <code>Object</code></dt>
82
75
  <dd><p>The configuration data for an application.</p>
@@ -84,13 +77,20 @@ cobalt.token = "COBALT_SESSION_TOKEN";
84
77
  <dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
85
78
  <dd><p>The workflow.</p>
86
79
  </dd>
80
+ <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
81
+ <dd><p>The dynamic fields payload.</p>
82
+ </dd>
83
+ <dt><a href="#DynamicField">DynamicField</a> : <code>Object</code></dt>
84
+ <dd><p>Field Mapping Label</p>
85
+ </dd>
86
+ <dt><a href="#Label">Label</a> : <code>Object</code></dt>
87
+ <dd><p>Field Mapping Label</p>
88
+ </dd>
87
89
  </dl>
88
90
 
89
91
  <a name="Cobalt"></a>
90
92
 
91
93
  ## Cobalt
92
- Cobalt Frontend SDK
93
-
94
94
  **Kind**: global class
95
95
 
96
96
  * [Cobalt](#Cobalt)
@@ -100,8 +100,8 @@ Cobalt Frontend SDK
100
100
  * [.config(slug, configId, [fields])](#Cobalt+config) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
101
101
  * [.updateConfig(slug, configId, payload)](#Cobalt+updateConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
102
102
  * [.deleteConfig(slug, configId)](#Cobalt+deleteConfig) ⇒ <code>Promise.&lt;unknown&gt;</code>
103
- * Additional Methods:
104
- * [.getApp(slug)](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
103
+ Additional Methods:
104
+ * [.getApp([slug])](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
105
105
  * [.getConfig(slug, configId)](#Cobalt+getConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
106
106
 
107
107
  <a name="new_Cobalt_new"></a>
@@ -118,16 +118,17 @@ Cobalt Frontend SDK
118
118
 
119
119
  <a name="Cobalt+getApp"></a>
120
120
 
121
- ### cobalt.getApp(slug) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
121
+ ### cobalt.getApp([slug]) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
122
122
  Returns the application details for the specified application, provided
123
- the application is enabled in Cobalt.
123
+ the application is enabled in Cobalt. If no application is specified,
124
+ it returns all the enabled applications.
124
125
 
125
126
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
126
127
  **Returns**: [<code>Promise.&lt;Application&gt;</code>](#Application) - The application details.
127
128
 
128
129
  | Param | Type | Description |
129
130
  | --- | --- | --- |
130
- | slug | <code>String</code> | The application slug. |
131
+ | [slug] | <code>String</code> | The application slug. |
131
132
 
132
133
  <a name="Cobalt+connect"></a>
133
134
 
@@ -223,31 +224,51 @@ An application in Cobalt.
223
224
  | [slug] | <code>String</code> | The application slug for custom apps. |
224
225
  | auth_type | <code>&quot;oauth2&quot;</code> \| <code>&quot;keybased&quot;</code> | The type of auth used by application. |
225
226
  | [connected] | <code>Boolean</code> | Whether the user has connected the application. |
227
+ | [auth_input_map] | [<code>Array.&lt;InputField&gt;</code>](#InputField) | The fields required from the user to connect the application (for `keybased` auth type). |
226
228
 
227
- <a name="Label"></a>
229
+ <a name="InputField"></a>
228
230
 
229
- ## Label : <code>Object</code>
230
- Field Mapping Label
231
+ ## InputField : <code>Object</code>
232
+ An Input field to take input from the user.
231
233
 
232
234
  **Kind**: global typedef
233
235
  **Properties**
234
236
 
235
237
  | Name | Type | Description |
236
238
  | --- | --- | --- |
237
- | name | <code>string</code> | The Label name. |
238
- | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
239
+ | name | <code>String</code> | Key name of the field. |
240
+ | type | <code>String</code> | Input type of the field. |
241
+ | required | <code>String</code> | Whether the field is required. |
242
+ | placeholder | <code>String</code> | The placeholder of the field. |
243
+ | label | <code>String</code> | The label of the field. |
239
244
 
240
- <a name="DynamicField"></a>
245
+ <a name="Config"></a>
241
246
 
242
- ## DynamicField : <code>Object</code>
243
- Field Mapping Label
247
+ ## Config : <code>Object</code>
248
+ The configuration data for an application.
244
249
 
245
250
  **Kind**: global typedef
246
251
  **Properties**
247
252
 
248
253
  | Name | Type | Description |
249
254
  | --- | --- | --- |
250
- | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
255
+ | [config_id] | <code>String</code> | Unique ID for the config. |
256
+ | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
257
+ | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Whether the workflow is enabled. |
258
+
259
+ <a name="Workflow"></a>
260
+
261
+ ## Workflow : <code>Object</code>
262
+ The workflow.
263
+
264
+ **Kind**: global typedef
265
+ **Properties**
266
+
267
+ | Name | Type | Description |
268
+ | --- | --- | --- |
269
+ | id | <code>String</code> | The ID of the workflow. |
270
+ | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
271
+ | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow's data slots and their values. |
251
272
 
252
273
  <a name="DynamicFields"></a>
253
274
 
@@ -261,30 +282,27 @@ The dynamic fields payload.
261
282
  | --- | --- | --- |
262
283
  | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
263
284
 
264
- <a name="Config"></a>
285
+ <a name="DynamicField"></a>
265
286
 
266
- ## Config : <code>Object</code>
267
- The configuration data for an application.
287
+ ## DynamicField : <code>Object</code>
288
+ Field Mapping Label
268
289
 
269
290
  **Kind**: global typedef
270
291
  **Properties**
271
292
 
272
293
  | Name | Type | Description |
273
294
  | --- | --- | --- |
274
- | [config_id] | <code>String</code> | Unique ID for the config. |
275
- | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
276
- | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Whether the workflow is enabled. |
295
+ | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
277
296
 
278
- <a name="Workflow"></a>
297
+ <a name="Label"></a>
279
298
 
280
- ## Workflow : <code>Object</code>
281
- The workflow.
299
+ ## Label : <code>Object</code>
300
+ Field Mapping Label
282
301
 
283
302
  **Kind**: global typedef
284
303
  **Properties**
285
304
 
286
305
  | Name | Type | Description |
287
306
  | --- | --- | --- |
288
- | id | <code>String</code> | The ID of the workflow. |
289
- | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
290
- | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow's data slots and their values. |
307
+ | name | <code>string</code> | The Label name. |
308
+ | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
package/cobalt.js CHANGED
@@ -1,6 +1,58 @@
1
1
  /**
2
2
  * Cobalt Frontend SDK
3
3
  */
4
+
5
+ /**
6
+ * @typedef {Object} Application An application in Cobalt.
7
+ * @property {String} name The application name.
8
+ * @property {String} description The application description.
9
+ * @property {String} icon The application icon.
10
+ * @property {String} type The application slug for native apps.
11
+ * @property {String} [slug] The application slug for custom apps.
12
+ * @property {"oauth2"|"keybased"} auth_type The type of auth used by application.
13
+ * @property {Boolean} [connected] Whether the user has connected the application.
14
+ * @property {InputField[]} [auth_input_map] The fields required from the user to connect the application (for `keybased` auth type).
15
+ */
16
+
17
+ /**
18
+ * @typedef {Object} InputField An Input field to take input from the user.
19
+ * @property {String} name Key name of the field.
20
+ * @property {String} type Input type of the field.
21
+ * @property {String} required Whether the field is required.
22
+ * @property {String} placeholder The placeholder of the field.
23
+ * @property {String} label The label of the field.
24
+ */
25
+
26
+ /**
27
+ * @typedef {Object} Config The configuration data for an application.
28
+ * @property {String} [config_id] Unique ID for the config.
29
+ * @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
30
+ * @property {Workflow[]} workflows Whether the workflow is enabled.
31
+ */
32
+
33
+ /**
34
+ * @typedef {Object} Workflow The workflow.
35
+ * @property {String} id The ID of the workflow.
36
+ * @property {Boolean} enabled Whether the workflow is enabled.
37
+ * @property {Object.<string, string | number | boolean>} data_slots A map of workflow's data slots and their values.
38
+ */
39
+
40
+ /**
41
+ * @typedef {Object} DynamicFields The dynamic fields payload.
42
+ * @property {Object.<string, DynamicField>} map_fields_object desc.
43
+ */
44
+
45
+ /**
46
+ * @typedef {Object} DynamicField Field Mapping Label
47
+ * @property {Label[]} fields The Label name.
48
+ */
49
+
50
+ /**
51
+ * @typedef {Object} Label Field Mapping Label
52
+ * @property {string} name The Label name.
53
+ * @property {string | number | boolean} value The Label value.
54
+ */
55
+
4
56
  class Cobalt {
5
57
  /**
6
58
  * Cobalt Frontend SDK
@@ -21,25 +73,15 @@ class Cobalt {
21
73
  return this.sessionToken = typeof token === "string" ? token : "";
22
74
  };
23
75
 
24
- /**
25
- * @typedef {Object} Application An application in Cobalt.
26
- * @property {String} name The application name.
27
- * @property {String} description The application description.
28
- * @property {String} icon The application icon.
29
- * @property {String} type The application slug for native apps.
30
- * @property {String} [slug] The application slug for custom apps.
31
- * @property {"oauth2"|"keybased"} auth_type The type of auth used by application.
32
- * @property {Boolean} [connected] Whether the user has connected the application.
33
- */
34
-
35
76
  /**
36
77
  * Returns the application details for the specified application, provided
37
- * the application is enabled in Cobalt.
38
- * @param {String} slug The application slug.
78
+ * the application is enabled in Cobalt. If no application is specified,
79
+ * it returns all the enabled applications.
80
+ * @param {String} [slug] The application slug.
39
81
  * @returns {Promise<Application>} The application details.
40
82
  */
41
83
  async getApp(slug) {
42
- const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/application/${slug}`, {
84
+ const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/application` + (slug ? `/${slug}` : ""), {
43
85
  headers: {
44
86
  authorization: `Bearer ${this.token}`,
45
87
  },
@@ -169,22 +211,6 @@ class Cobalt {
169
211
  }
170
212
  }
171
213
 
172
- /**
173
- * @typedef {Object} Label Field Mapping Label
174
- * @property {string} name The Label name.
175
- * @property {string | number | boolean} value The Label value.
176
- */
177
-
178
- /**
179
- * @typedef {Object} DynamicField Field Mapping Label
180
- * @property {Label[]} fields The Label name.
181
- */
182
-
183
- /**
184
- * @typedef {Object} DynamicFields The dynamic fields payload.
185
- * @property {Object.<string, DynamicField>} map_fields_object desc.
186
- */
187
-
188
214
  /**
189
215
  * Returns the specified config, or creates one if it doesn't exist.
190
216
  * @param {String} slug The application slug.
@@ -209,20 +235,6 @@ class Cobalt {
209
235
  return await res.json();
210
236
  }
211
237
 
212
- /**
213
- * @typedef {Object} Config The configuration data for an application.
214
- * @property {String} [config_id] Unique ID for the config.
215
- * @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
216
- * @property {Workflow[]} workflows Whether the workflow is enabled.
217
- */
218
-
219
- /**
220
- * @typedef {Object} Workflow The workflow.
221
- * @property {String} id The ID of the workflow.
222
- * @property {Boolean} enabled Whether the workflow is enabled.
223
- * @property {Object.<string, string | number | boolean>} data_slots A map of workflow's data slots and their values.
224
- */
225
-
226
238
  /**
227
239
  * Returns the specified config.
228
240
  * @param {String} slug The application slug.
package/docs.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  <dl>
4
4
  <dt><a href="#Cobalt">Cobalt</a></dt>
5
- <dd><p>Cobalt Frontend SDK</p>
6
- </dd>
5
+ <dd></dd>
7
6
  </dl>
8
7
 
9
8
  ## Typedefs
@@ -12,14 +11,8 @@
12
11
  <dt><a href="#Application">Application</a> : <code>Object</code></dt>
13
12
  <dd><p>An application in Cobalt.</p>
14
13
  </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="#DynamicField">DynamicField</a> : <code>Object</code></dt>
19
- <dd><p>Field Mapping Label</p>
20
- </dd>
21
- <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
22
- <dd><p>The dynamic fields payload.</p>
14
+ <dt><a href="#InputField">InputField</a> : <code>Object</code></dt>
15
+ <dd><p>An Input field to take input from the user.</p>
23
16
  </dd>
24
17
  <dt><a href="#Config">Config</a> : <code>Object</code></dt>
25
18
  <dd><p>The configuration data for an application.</p>
@@ -27,18 +20,25 @@
27
20
  <dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
28
21
  <dd><p>The workflow.</p>
29
22
  </dd>
23
+ <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
24
+ <dd><p>The dynamic fields payload.</p>
25
+ </dd>
26
+ <dt><a href="#DynamicField">DynamicField</a> : <code>Object</code></dt>
27
+ <dd><p>Field Mapping Label</p>
28
+ </dd>
29
+ <dt><a href="#Label">Label</a> : <code>Object</code></dt>
30
+ <dd><p>Field Mapping Label</p>
31
+ </dd>
30
32
  </dl>
31
33
 
32
34
  <a name="Cobalt"></a>
33
35
 
34
36
  ## Cobalt
35
- Cobalt Frontend SDK
36
-
37
37
  **Kind**: global class
38
38
 
39
39
  * [Cobalt](#Cobalt)
40
40
  * [new Cobalt(options)](#new_Cobalt_new)
41
- * [.getApp(slug)](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
41
+ * [.getApp([slug])](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
42
42
  * [.connect(slug, [payload])](#Cobalt+connect) ⇒ <code>Promise.&lt;Boolean&gt;</code>
43
43
  * [.disconnect(slug)](#Cobalt+disconnect) ⇒ <code>Promise.&lt;void&gt;</code>
44
44
  * [.config(slug, configId, [fields])](#Cobalt+config) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
@@ -60,16 +60,17 @@ Cobalt Frontend SDK
60
60
 
61
61
  <a name="Cobalt+getApp"></a>
62
62
 
63
- ### cobalt.getApp(slug) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
63
+ ### cobalt.getApp([slug]) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
64
64
  Returns the application details for the specified application, provided
65
- the application is enabled in Cobalt.
65
+ the application is enabled in Cobalt. If no application is specified,
66
+ it returns all the enabled applications.
66
67
 
67
68
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
68
69
  **Returns**: [<code>Promise.&lt;Application&gt;</code>](#Application) - The application details.
69
70
 
70
71
  | Param | Type | Description |
71
72
  | --- | --- | --- |
72
- | slug | <code>String</code> | The application slug. |
73
+ | [slug] | <code>String</code> | The application slug. |
73
74
 
74
75
  <a name="Cobalt+connect"></a>
75
76
 
@@ -165,31 +166,51 @@ An application in Cobalt.
165
166
  | [slug] | <code>String</code> | The application slug for custom apps. |
166
167
  | auth_type | <code>&quot;oauth2&quot;</code> \| <code>&quot;keybased&quot;</code> | The type of auth used by application. |
167
168
  | [connected] | <code>Boolean</code> | Whether the user has connected the application. |
169
+ | [auth_input_map] | [<code>Array.&lt;InputField&gt;</code>](#InputField) | The fields required from the user to connect the application (for `keybased` auth type). |
168
170
 
169
- <a name="Label"></a>
171
+ <a name="InputField"></a>
170
172
 
171
- ## Label : <code>Object</code>
172
- Field Mapping Label
173
+ ## InputField : <code>Object</code>
174
+ An Input field to take input from the user.
173
175
 
174
176
  **Kind**: global typedef
175
177
  **Properties**
176
178
 
177
179
  | Name | Type | Description |
178
180
  | --- | --- | --- |
179
- | name | <code>string</code> | The Label name. |
180
- | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
181
+ | name | <code>String</code> | Key name of the field. |
182
+ | type | <code>String</code> | Input type of the field. |
183
+ | required | <code>String</code> | Whether the field is required. |
184
+ | placeholder | <code>String</code> | The placeholder of the field. |
185
+ | label | <code>String</code> | The label of the field. |
181
186
 
182
- <a name="DynamicField"></a>
187
+ <a name="Config"></a>
183
188
 
184
- ## DynamicField : <code>Object</code>
185
- Field Mapping Label
189
+ ## Config : <code>Object</code>
190
+ The configuration data for an application.
186
191
 
187
192
  **Kind**: global typedef
188
193
  **Properties**
189
194
 
190
195
  | Name | Type | Description |
191
196
  | --- | --- | --- |
192
- | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
197
+ | [config_id] | <code>String</code> | Unique ID for the config. |
198
+ | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
199
+ | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Whether the workflow is enabled. |
200
+
201
+ <a name="Workflow"></a>
202
+
203
+ ## Workflow : <code>Object</code>
204
+ The workflow.
205
+
206
+ **Kind**: global typedef
207
+ **Properties**
208
+
209
+ | Name | Type | Description |
210
+ | --- | --- | --- |
211
+ | id | <code>String</code> | The ID of the workflow. |
212
+ | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
213
+ | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow's data slots and their values. |
193
214
 
194
215
  <a name="DynamicFields"></a>
195
216
 
@@ -203,31 +224,28 @@ The dynamic fields payload.
203
224
  | --- | --- | --- |
204
225
  | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
205
226
 
206
- <a name="Config"></a>
227
+ <a name="DynamicField"></a>
207
228
 
208
- ## Config : <code>Object</code>
209
- The configuration data for an application.
229
+ ## DynamicField : <code>Object</code>
230
+ Field Mapping Label
210
231
 
211
232
  **Kind**: global typedef
212
233
  **Properties**
213
234
 
214
235
  | Name | Type | Description |
215
236
  | --- | --- | --- |
216
- | [config_id] | <code>String</code> | Unique ID for the config. |
217
- | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
218
- | workflows | [<code>Array.&lt;Workflow&gt;</code>](#Workflow) | Whether the workflow is enabled. |
237
+ | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
219
238
 
220
- <a name="Workflow"></a>
239
+ <a name="Label"></a>
221
240
 
222
- ## Workflow : <code>Object</code>
223
- The workflow.
241
+ ## Label : <code>Object</code>
242
+ Field Mapping Label
224
243
 
225
244
  **Kind**: global typedef
226
245
  **Properties**
227
246
 
228
247
  | Name | Type | Description |
229
248
  | --- | --- | --- |
230
- | id | <code>String</code> | The ID of the workflow. |
231
- | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
232
- | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow's data slots and their values. |
249
+ | name | <code>string</code> | The Label name. |
250
+ | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
233
251
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {