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