@cobaltio/cobalt-js 3.0.1 → 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 +84 -41
  2. package/cobalt.js +56 -33
  3. package/docs.md +76 -37
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -21,10 +21,14 @@ yarn add @cobaltio/cobalt-js
21
21
 
22
22
  #### Browser
23
23
  ```html
24
- <!-- import the latest version -->
24
+ <!-- use a specific version -->
25
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@3.0.1"></script>
26
+ <!-- use a version range instead of a specific version -->
27
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@3"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@3.0"></script>
29
+ <!-- omit the version completely to use the latest one -->
30
+ <!-- you should NOT use this in production -->
25
31
  <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js"></script>
26
- <!-- import a specific version -->
27
- <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@2"></script>
28
32
  ```
29
33
 
30
34
  #### Node
@@ -55,21 +59,17 @@ cobalt.token = "COBALT_SESSION_TOKEN";
55
59
 
56
60
  <dl>
57
61
  <dt><a href="#Cobalt">Cobalt</a></dt>
58
- <dd><p>Cobalt Frontend SDK</p>
59
- </dd>
62
+ <dd></dd>
60
63
  </dl>
61
64
 
62
65
  ## Typedefs
63
66
 
64
67
  <dl>
65
- <dt><a href="#Label">Label</a> : <code>Object</code></dt>
66
- <dd><p>Field Mapping Label</p>
67
- </dd>
68
- <dt><a href="#DynamicField">DynamicField</a> : <code>Object</code></dt>
69
- <dd><p>Field Mapping Label</p>
68
+ <dt><a href="#Application">Application</a> : <code>Object</code></dt>
69
+ <dd><p>An application in Cobalt.</p>
70
70
  </dd>
71
- <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
72
- <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>
73
73
  </dd>
74
74
  <dt><a href="#Config">Config</a> : <code>Object</code></dt>
75
75
  <dd><p>The configuration data for an application.</p>
@@ -77,13 +77,20 @@ cobalt.token = "COBALT_SESSION_TOKEN";
77
77
  <dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
78
78
  <dd><p>The workflow.</p>
79
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>
80
89
  </dl>
81
90
 
82
91
  <a name="Cobalt"></a>
83
92
 
84
93
  ## Cobalt
85
- Cobalt Frontend SDK
86
-
87
94
  **Kind**: global class
88
95
 
89
96
  * [Cobalt](#Cobalt)
@@ -93,8 +100,8 @@ Cobalt Frontend SDK
93
100
  * [.config(slug, configId, [fields])](#Cobalt+config) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
94
101
  * [.updateConfig(slug, configId, payload)](#Cobalt+updateConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
95
102
  * [.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>
103
+ Additional Methods:
104
+ * [.getApp([slug])](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
98
105
  * [.getConfig(slug, configId)](#Cobalt+getConfig) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
99
106
 
100
107
  <a name="new_Cobalt_new"></a>
@@ -111,16 +118,17 @@ Cobalt Frontend SDK
111
118
 
112
119
  <a name="Cobalt+getApp"></a>
113
120
 
114
- ### cobalt.getApp(slug) ⇒ <code>Promise.&lt;Application&gt;</code>
121
+ ### cobalt.getApp([slug]) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
115
122
  Returns the application details for the specified application, provided
116
- 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.
117
125
 
118
126
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
119
- **Returns**: <code>Promise.&lt;Application&gt;</code> - The application details.
127
+ **Returns**: [<code>Promise.&lt;Application&gt;</code>](#Application) - The application details.
120
128
 
121
129
  | Param | Type | Description |
122
130
  | --- | --- | --- |
123
- | slug | <code>String</code> | The application slug. |
131
+ | [slug] | <code>String</code> | The application slug. |
124
132
 
125
133
  <a name="Cobalt+connect"></a>
126
134
 
@@ -199,42 +207,40 @@ Delete the specified config.
199
207
  | slug | <code>String</code> | The application slug. |
200
208
  | configId | <code>String</code> | The unique ID of the config. |
201
209
 
202
- <a name="Label"></a>
210
+ <a name="Application"></a>
203
211
 
204
- ## Label : <code>Object</code>
205
- Field Mapping Label
212
+ ## Application : <code>Object</code>
213
+ An application in Cobalt.
206
214
 
207
215
  **Kind**: global typedef
208
216
  **Properties**
209
217
 
210
218
  | Name | Type | Description |
211
219
  | --- | --- | --- |
212
- | name | <code>string</code> | The Label name. |
213
- | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
220
+ | name | <code>String</code> | The application name. |
221
+ | description | <code>String</code> | The application description. |
222
+ | icon | <code>String</code> | The application icon. |
223
+ | type | <code>String</code> | The application slug for native apps. |
224
+ | [slug] | <code>String</code> | The application slug for custom apps. |
225
+ | auth_type | <code>&quot;oauth2&quot;</code> \| <code>&quot;keybased&quot;</code> | The type of auth used by application. |
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). |
214
228
 
215
- <a name="DynamicField"></a>
229
+ <a name="InputField"></a>
216
230
 
217
- ## DynamicField : <code>Object</code>
218
- Field Mapping Label
219
-
220
- **Kind**: global typedef
221
- **Properties**
222
-
223
- | Name | Type | Description |
224
- | --- | --- | --- |
225
- | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
226
-
227
- <a name="DynamicFields"></a>
228
-
229
- ## DynamicFields : <code>Object</code>
230
- The dynamic fields payload.
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
- | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
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. |
238
244
 
239
245
  <a name="Config"></a>
240
246
 
@@ -263,3 +269,40 @@ The workflow.
263
269
  | id | <code>String</code> | The ID of the workflow. |
264
270
  | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
265
271
  | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow's data slots and their values. |
272
+
273
+ <a name="DynamicFields"></a>
274
+
275
+ ## DynamicFields : <code>Object</code>
276
+ The dynamic fields payload.
277
+
278
+ **Kind**: global typedef
279
+ **Properties**
280
+
281
+ | Name | Type | Description |
282
+ | --- | --- | --- |
283
+ | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
284
+
285
+ <a name="DynamicField"></a>
286
+
287
+ ## DynamicField : <code>Object</code>
288
+ Field Mapping Label
289
+
290
+ **Kind**: global typedef
291
+ **Properties**
292
+
293
+ | Name | Type | Description |
294
+ | --- | --- | --- |
295
+ | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
296
+
297
+ <a name="Label"></a>
298
+
299
+ ## Label : <code>Object</code>
300
+ Field Mapping Label
301
+
302
+ **Kind**: global typedef
303
+ **Properties**
304
+
305
+ | Name | Type | Description |
306
+ | --- | --- | --- |
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
@@ -23,12 +75,13 @@ class Cobalt {
23
75
 
24
76
  /**
25
77
  * Returns the application details for the specified application, provided
26
- * the application is enabled in Cobalt.
27
- * @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.
28
81
  * @returns {Promise<Application>} The application details.
29
82
  */
30
83
  async getApp(slug) {
31
- 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}` : ""), {
32
85
  headers: {
33
86
  authorization: `Bearer ${this.token}`,
34
87
  },
@@ -158,22 +211,6 @@ class Cobalt {
158
211
  }
159
212
  }
160
213
 
161
- /**
162
- * @typedef {Object} Label Field Mapping Label
163
- * @property {string} name The Label name.
164
- * @property {string | number | boolean} value The Label value.
165
- */
166
-
167
- /**
168
- * @typedef {Object} DynamicField Field Mapping Label
169
- * @property {Label[]} fields The Label name.
170
- */
171
-
172
- /**
173
- * @typedef {Object} DynamicFields The dynamic fields payload.
174
- * @property {Object.<string, DynamicField>} map_fields_object desc.
175
- */
176
-
177
214
  /**
178
215
  * Returns the specified config, or creates one if it doesn't exist.
179
216
  * @param {String} slug The application slug.
@@ -198,20 +235,6 @@ class Cobalt {
198
235
  return await res.json();
199
236
  }
200
237
 
201
- /**
202
- * @typedef {Object} Config The configuration data for an application.
203
- * @property {String} [config_id] Unique ID for the config.
204
- * @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
205
- * @property {Workflow[]} workflows Whether the workflow is enabled.
206
- */
207
-
208
- /**
209
- * @typedef {Object} Workflow The workflow.
210
- * @property {String} id The ID of the workflow.
211
- * @property {Boolean} enabled Whether the workflow is enabled.
212
- * @property {Object.<string, string | number | boolean>} data_slots A map of workflow's data slots and their values.
213
- */
214
-
215
238
  /**
216
239
  * Returns the specified config.
217
240
  * @param {String} slug The application slug.
package/docs.md CHANGED
@@ -2,21 +2,17 @@
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
10
9
 
11
10
  <dl>
12
- <dt><a href="#Label">Label</a> : <code>Object</code></dt>
13
- <dd><p>Field Mapping Label</p>
14
- </dd>
15
- <dt><a href="#DynamicField">DynamicField</a> : <code>Object</code></dt>
16
- <dd><p>Field Mapping Label</p>
11
+ <dt><a href="#Application">Application</a> : <code>Object</code></dt>
12
+ <dd><p>An application in Cobalt.</p>
17
13
  </dd>
18
- <dt><a href="#DynamicFields">DynamicFields</a> : <code>Object</code></dt>
19
- <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>
20
16
  </dd>
21
17
  <dt><a href="#Config">Config</a> : <code>Object</code></dt>
22
18
  <dd><p>The configuration data for an application.</p>
@@ -24,18 +20,25 @@
24
20
  <dt><a href="#Workflow">Workflow</a> : <code>Object</code></dt>
25
21
  <dd><p>The workflow.</p>
26
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>
27
32
  </dl>
28
33
 
29
34
  <a name="Cobalt"></a>
30
35
 
31
36
  ## Cobalt
32
- Cobalt Frontend SDK
33
-
34
37
  **Kind**: global class
35
38
 
36
39
  * [Cobalt](#Cobalt)
37
40
  * [new Cobalt(options)](#new_Cobalt_new)
38
- * [.getApp(slug)](#Cobalt+getApp) ⇒ <code>Promise.&lt;Application&gt;</code>
41
+ * [.getApp([slug])](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
39
42
  * [.connect(slug, [payload])](#Cobalt+connect) ⇒ <code>Promise.&lt;Boolean&gt;</code>
40
43
  * [.disconnect(slug)](#Cobalt+disconnect) ⇒ <code>Promise.&lt;void&gt;</code>
41
44
  * [.config(slug, configId, [fields])](#Cobalt+config) ⇒ [<code>Promise.&lt;Config&gt;</code>](#Config)
@@ -57,16 +60,17 @@ Cobalt Frontend SDK
57
60
 
58
61
  <a name="Cobalt+getApp"></a>
59
62
 
60
- ### cobalt.getApp(slug) ⇒ <code>Promise.&lt;Application&gt;</code>
63
+ ### cobalt.getApp([slug]) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
61
64
  Returns the application details for the specified application, provided
62
- 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.
63
67
 
64
68
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
65
- **Returns**: <code>Promise.&lt;Application&gt;</code> - The application details.
69
+ **Returns**: [<code>Promise.&lt;Application&gt;</code>](#Application) - The application details.
66
70
 
67
71
  | Param | Type | Description |
68
72
  | --- | --- | --- |
69
- | slug | <code>String</code> | The application slug. |
73
+ | [slug] | <code>String</code> | The application slug. |
70
74
 
71
75
  <a name="Cobalt+connect"></a>
72
76
 
@@ -145,42 +149,40 @@ Delete the specified config.
145
149
  | slug | <code>String</code> | The application slug. |
146
150
  | configId | <code>String</code> | The unique ID of the config. |
147
151
 
148
- <a name="Label"></a>
152
+ <a name="Application"></a>
149
153
 
150
- ## Label : <code>Object</code>
151
- Field Mapping Label
154
+ ## Application : <code>Object</code>
155
+ An application in Cobalt.
152
156
 
153
157
  **Kind**: global typedef
154
158
  **Properties**
155
159
 
156
160
  | Name | Type | Description |
157
161
  | --- | --- | --- |
158
- | name | <code>string</code> | The Label name. |
159
- | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
162
+ | name | <code>String</code> | The application name. |
163
+ | description | <code>String</code> | The application description. |
164
+ | icon | <code>String</code> | The application icon. |
165
+ | type | <code>String</code> | The application slug for native apps. |
166
+ | [slug] | <code>String</code> | The application slug for custom apps. |
167
+ | auth_type | <code>&quot;oauth2&quot;</code> \| <code>&quot;keybased&quot;</code> | The type of auth used by application. |
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). |
160
170
 
161
- <a name="DynamicField"></a>
171
+ <a name="InputField"></a>
162
172
 
163
- ## DynamicField : <code>Object</code>
164
- Field Mapping Label
165
-
166
- **Kind**: global typedef
167
- **Properties**
168
-
169
- | Name | Type | Description |
170
- | --- | --- | --- |
171
- | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
172
-
173
- <a name="DynamicFields"></a>
174
-
175
- ## DynamicFields : <code>Object</code>
176
- The dynamic fields payload.
173
+ ## InputField : <code>Object</code>
174
+ An Input field to take input from the user.
177
175
 
178
176
  **Kind**: global typedef
179
177
  **Properties**
180
178
 
181
179
  | Name | Type | Description |
182
180
  | --- | --- | --- |
183
- | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
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. |
184
186
 
185
187
  <a name="Config"></a>
186
188
 
@@ -210,3 +212,40 @@ The workflow.
210
212
  | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
211
213
  | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow's data slots and their values. |
212
214
 
215
+ <a name="DynamicFields"></a>
216
+
217
+ ## DynamicFields : <code>Object</code>
218
+ The dynamic fields payload.
219
+
220
+ **Kind**: global typedef
221
+ **Properties**
222
+
223
+ | Name | Type | Description |
224
+ | --- | --- | --- |
225
+ | map_fields_object | <code>Object.&lt;string, DynamicField&gt;</code> | desc. |
226
+
227
+ <a name="DynamicField"></a>
228
+
229
+ ## DynamicField : <code>Object</code>
230
+ Field Mapping Label
231
+
232
+ **Kind**: global typedef
233
+ **Properties**
234
+
235
+ | Name | Type | Description |
236
+ | --- | --- | --- |
237
+ | fields | [<code>Array.&lt;Label&gt;</code>](#Label) | The Label name. |
238
+
239
+ <a name="Label"></a>
240
+
241
+ ## Label : <code>Object</code>
242
+ Field Mapping Label
243
+
244
+ **Kind**: global typedef
245
+ **Properties**
246
+
247
+ | Name | Type | Description |
248
+ | --- | --- | --- |
249
+ | name | <code>string</code> | The Label name. |
250
+ | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The Label value. |
251
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {