@cobaltio/cobalt-js 0.1.0 → 1.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.
Files changed (5) hide show
  1. package/README.md +107 -183
  2. package/cobalt.js +103 -175
  3. package/cobalt.min.js +1 -1
  4. package/docs.md +106 -182
  5. package/package.json +1 -2
package/README.md CHANGED
@@ -21,7 +21,7 @@ yarn add @cobaltio/cobalt-js
21
21
 
22
22
  #### Browser
23
23
  ```js
24
- <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@0"></script>
24
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@1"></script>
25
25
  ```
26
26
 
27
27
  #### Node
@@ -59,17 +59,14 @@ cobalt.token = "COBALT_SESSION_TOKEN";
59
59
  ## Typedefs
60
60
 
61
61
  <dl>
62
- <dt><a href="#Field">Field</a> : <code>object</code></dt>
63
- <dd><p>The Node Field object available for configuration.</p>
62
+ <dt><a href="#AppConfig">AppConfig</a> : <code>object</code></dt>
63
+ <dd><p>The configuration data for an application.</p>
64
64
  </dd>
65
- <dt><a href="#Node">Node</a> : <code>object</code></dt>
66
- <dd><p>The Node object available for configuration.</p>
65
+ <dt><a href="#AppInstance">AppInstance</a> : <code>Object</code></dt>
66
+ <dd><p>An installed application.</p>
67
67
  </dd>
68
- <dt><a href="#Workflow">Workflow</a> : <code>object</code></dt>
69
- <dd><p>The installed workflow.</p>
70
- </dd>
71
- <dt><a href="#AppAuthStatus">AppAuthStatus</a> : <code>object</code></dt>
72
- <dd><p>The auth status of the user for an application.</p>
68
+ <dt><a href="#WorkflowTemplate">WorkflowTemplate</a> : <code>Object</code></dt>
69
+ <dd><p>The workflow template.</p>
73
70
  </dd>
74
71
  </dl>
75
72
 
@@ -79,25 +76,25 @@ cobalt.token = "COBALT_SESSION_TOKEN";
79
76
  Cobalt Frontend SDK
80
77
 
81
78
  **Kind**: global class
79
+ **Properties**
80
+
81
+ | Name | Type | Description |
82
+ | --- | --- | --- |
83
+ | token | <code>String</code> | The session token. |
84
+
82
85
 
83
86
  * [Cobalt](#Cobalt)
84
87
  * [new Cobalt(options)](#new_Cobalt_new)
85
- * [.token](#Cobalt+token) ⇒ <code>string</code>
86
- * [.token](#Cobalt+token) ⇒ <code>string</code>
87
- * [.baseUrl](#Cobalt+baseUrl) ⇒ <code>string</code>
88
- * [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
89
- * [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.&lt;boolean&gt;</code>
90
- * [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.&lt;string&gt;</code>
91
- * [.oauth()](#Cobalt+oauth) ⇒ <code>Promise.&lt;boolean&gt;</code>
92
- * [.setAppAuthData()](#Cobalt+setAppAuthData) ⇒ <code>Promise.&lt;void&gt;</code>
93
- * [.removeAppAuth()](#Cobalt+removeAppAuth) ⇒ <code>Promise.&lt;void&gt;</code>
94
- * [.getNodeConfiguration()](#Cobalt+getNodeConfiguration) ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
95
- * [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
96
- * [.getWorkflowConfiguration()](#Cobalt+getWorkflowConfiguration) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
97
- * [.activateWorkflow()](#Cobalt+activateWorkflow) ⇒ <code>Promise.&lt;void&gt;</code>
98
- * [.activateWorkflows()](#Cobalt+activateWorkflows) ⇒ <code>Promise.&lt;void&gt;</code>
99
- * [.toggleWorkflowStatus()](#Cobalt+toggleWorkflowStatus) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
100
- * [.deleteWorkflow()](#Cobalt+deleteWorkflow) ⇒ <code>Promise.&lt;unknown&gt;</code>
88
+ * [.oauth(application)](#Cobalt+oauth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
89
+ * [.auth(application, payload)](#Cobalt+auth) ⇒ <code>Promise.&lt;unknown&gt;</code>
90
+ * [.authCustom(applicationId, payload)](#Cobalt+authCustom) ⇒ <code>Promise.&lt;unknown&gt;</code>
91
+ * [.checkAuth(application)](#Cobalt+checkAuth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
92
+ * [.removeAuth(application, [applicationId])](#Cobalt+removeAuth) ⇒ <code>Promise.&lt;void&gt;</code>
93
+ * [.getAppConfig(application)](#Cobalt+getAppConfig) ⇒ [<code>Promise.&lt;AppConfig&gt;</code>](#AppConfig)
94
+ * [.install(applicationId, payload)](#Cobalt+install) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
95
+ * [.getInstallation(applicationId, installationId)](#Cobalt+getInstallation) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
96
+ * [.updateInstallation(applicationId, installationId, payload)](#Cobalt+updateInstallation) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
97
+ * [.deleteInstallation(applicationId, installationId)](#Cobalt+deleteInstallation) ⇒ <code>Promise.&lt;unknown&gt;</code>
101
98
 
102
99
  <a name="new_Cobalt_new"></a>
103
100
 
@@ -107,246 +104,173 @@ Cobalt Frontend SDK
107
104
 
108
105
  | Param | Type | Default | Description |
109
106
  | --- | --- | --- | --- |
110
- | options | <code>object</code> | | The options to configure the Cobalt SDK. |
111
- | [options.token] | <code>string</code> | | The session token. |
112
- | [options.baseUrl] | <code>string</code> | <code>&quot;https://api.gocobalt.io&quot;</code> | The base URL of your Cobalt API. |
113
-
114
- <a name="Cobalt+token"></a>
115
-
116
- ### cobalt.token ⇒ <code>string</code>
117
- **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
118
- **Returns**: <code>string</code> - The session token.
119
- <a name="Cobalt+token"></a>
120
-
121
- ### cobalt.token ⇒ <code>string</code>
122
- **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
123
- **Returns**: <code>string</code> - The session token.
124
- <a name="Cobalt+baseUrl"></a>
125
-
126
- ### cobalt.baseUrl ⇒ <code>string</code>
127
- **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
128
- **Returns**: <code>string</code> - The base URL of cobalt API.
129
- <a name="Cobalt+installTemplate"></a>
130
-
131
- ### cobalt.installTemplate() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
132
- Install the given template.
133
-
134
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
135
- **Properties**
136
-
137
- | Name | Type | Description |
138
- | --- | --- | --- |
139
- | templateId | <code>string</code> | The ID of the template you want to install. |
140
- | udf | <code>object</code> | Custom key value pairs you want to store with the installed worklfow. |
141
-
142
- <a name="Cobalt+getAppAuthStatus"></a>
143
-
144
- ### cobalt.getAppAuthStatus() ⇒ <code>Promise.&lt;boolean&gt;</code>
145
- Returns the auth status of the user for the specified application.
146
-
147
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
148
- **Returns**: <code>Promise.&lt;boolean&gt;</code> - The auth status of the user.
149
- **Properties**
150
-
151
- | Name | Type | Description |
152
- | --- | --- | --- |
153
- | application | <code>string</code> | The application type. |
154
-
155
- <a name="Cobalt+getAppAuthUrl"></a>
156
-
157
- ### cobalt.getAppAuthUrl() ⇒ <code>Promise.&lt;string&gt;</code>
158
- Returns the auth URL that users can use to authenticate themselves to the
159
- specified application.
160
-
161
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
162
- **Returns**: <code>Promise.&lt;string&gt;</code> - The auth URL where users can authenticate themselves.
163
- **Properties**
164
-
165
- | Name | Type | Description |
166
- | --- | --- | --- |
167
- | application | <code>string</code> | The application type. |
107
+ | options | <code>Object</code> | | The options to configure the Cobalt SDK. |
108
+ | [options.token] | <code>String</code> | | The session token. |
109
+ | [options.baseUrl] | <code>String</code> | <code>https://api.gocobalt.io</code> | The base URL of the Cobalt API. |
168
110
 
169
111
  <a name="Cobalt+oauth"></a>
170
112
 
171
- ### cobalt.oauth() ⇒ <code>Promise.&lt;boolean&gt;</code>
172
- Handle OAuth for the specified application.
113
+ ### cobalt.oauth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
114
+ Handle OAuth for the specified native application.
173
115
 
174
116
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
175
- **Returns**: <code>Promise.&lt;boolean&gt;</code> - Whether the user authenticated.
176
- **Properties**
117
+ **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the user authenticated.
177
118
 
178
- | Name | Type | Description |
119
+ | Param | Type | Description |
179
120
  | --- | --- | --- |
180
- | application | <code>string</code> | The application type. |
121
+ | application | <code>String</code> | The application type. |
181
122
 
182
- <a name="Cobalt+setAppAuthData"></a>
123
+ <a name="Cobalt+auth"></a>
183
124
 
184
- ### cobalt.setAppAuthData() ⇒ <code>Promise.&lt;void&gt;</code>
125
+ ### cobalt.auth(application, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
185
126
  Save the auth data that user provides to authenticate themselves to the
186
- specified application.
127
+ specified native application.
187
128
 
188
129
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
189
- **Properties**
190
130
 
191
- | Name | Type | Description |
131
+ | Param | Type | Description |
192
132
  | --- | --- | --- |
193
- | application | <code>string</code> | The application type. |
194
- | payload | <code>object</code> | The key value pairs of auth data. |
195
- | appId | <code>object</code> | The application ID in case of custom applications. |
133
+ | application | <code>String</code> | The application type. |
134
+ | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
196
135
 
197
- <a name="Cobalt+removeAppAuth"></a>
136
+ <a name="Cobalt+authCustom"></a>
198
137
 
199
- ### cobalt.removeAppAuth() ⇒ <code>Promise.&lt;void&gt;</code>
200
- Unauthorize the specified application and remove any associated data from Cobalt.
138
+ ### cobalt.authCustom(applicationId, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
139
+ Save the auth data that user provides to authenticate themselves to the
140
+ specified custom application.
201
141
 
202
142
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
203
- **Properties**
204
143
 
205
- | Name | Type | Description |
144
+ | Param | Type | Description |
206
145
  | --- | --- | --- |
207
- | application | <code>string</code> | The application type. |
208
- | appId | <code>string</code> | The application ID in case of custom applications. |
146
+ | applicationId | <code>String</code> | The application ID of the custom application. |
147
+ | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
209
148
 
210
- <a name="Cobalt+getNodeConfiguration"></a>
149
+ <a name="Cobalt+checkAuth"></a>
211
150
 
212
- ### cobalt.getNodeConfiguration() ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
213
- Returns the node configuration data for dynamic fields.
151
+ ### cobalt.checkAuth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
152
+ Returns the auth status of the user for the specified application.
214
153
 
215
154
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
216
- **Properties**
155
+ **Returns**: <code>Promise.&lt;Boolean&gt;</code> - The auth status of the user.
217
156
 
218
- | Name | Type | Description |
157
+ | Param | Type | Description |
219
158
  | --- | --- | --- |
220
- | workflowId | <code>string</code> | The ID of the workflow. |
221
- | nodeId | <code>string</code> | The ID of the node. |
222
- | fieldName | <code>string</code> | The field name for which config data is required. |
223
- | selectedValues | <code>object</code> | The input data already selected for the node. |
159
+ | application | <code>String</code> | The application type. |
224
160
 
225
- <a name="Cobalt+saveNode"></a>
161
+ <a name="Cobalt+removeAuth"></a>
226
162
 
227
- ### cobalt.saveNode() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
228
- Save the input data for the specified node.
163
+ ### cobalt.removeAuth(application, [applicationId]) ⇒ <code>Promise.&lt;void&gt;</code>
164
+ Unauthorize the specified application and remove any associated data from Cobalt.
229
165
 
230
166
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
231
- **Properties**
232
167
 
233
- | Name | Type | Description |
168
+ | Param | Type | Description |
234
169
  | --- | --- | --- |
235
- | workflowId | <code>string</code> | The ID of the workflow. |
236
- | nodeId | <code>string</code> | The ID of the node. |
237
- | inputData | <code>object</code> | The input data for the node. |
170
+ | application | <code>String</code> | The application type. |
171
+ | [applicationId] | <code>String</code> | The application ID in case of custom applications. |
238
172
 
239
- <a name="Cobalt+getWorkflowConfiguration"></a>
173
+ <a name="Cobalt+getAppConfig"></a>
240
174
 
241
- ### cobalt.getWorkflowConfiguration() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
242
- Returns the workflow configuration data.
175
+ ### cobalt.getAppConfig(application) ⇒ [<code>Promise.&lt;AppConfig&gt;</code>](#AppConfig)
176
+ Returns the configuration data for the specified application.
243
177
 
244
178
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
245
- **Properties**
179
+ **Returns**: [<code>Promise.&lt;AppConfig&gt;</code>](#AppConfig) - The specified application's configuration data.
246
180
 
247
- | Name | Type | Description |
181
+ | Param | Type | Description |
248
182
  | --- | --- | --- |
249
- | workflowId | <code>string</code> | The ID of the workflow. |
183
+ | application | <code>String</code> | The application ID. |
250
184
 
251
- <a name="Cobalt+activateWorkflow"></a>
185
+ <a name="Cobalt+install"></a>
252
186
 
253
- ### cobalt.activateWorkflow() ⇒ <code>Promise.&lt;void&gt;</code>
254
- Activate the given installed workflow.
187
+ ### cobalt.install(applicationId, payload) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
188
+ Install the specified application.
255
189
 
256
190
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
257
- **Properties**
191
+ **Returns**: [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance) - The specified application installation.
258
192
 
259
- | Name | Type | Description |
193
+ | Param | Type | Description |
260
194
  | --- | --- | --- |
261
- | workflowId | <code>string</code> | The ID of the workflow you want to activate. |
195
+ | applicationId | <code>String</code> | The application ID. |
196
+ | payload | [<code>AppInstance</code>](#AppInstance) | The install payload. |
262
197
 
263
- <a name="Cobalt+activateWorkflows"></a>
198
+ <a name="Cobalt+getInstallation"></a>
264
199
 
265
- ### cobalt.activateWorkflows() ⇒ <code>Promise.&lt;void&gt;</code>
266
- Activate the given installed workflows.
200
+ ### cobalt.getInstallation(applicationId, installationId) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
201
+ Returns the specified application installation.
267
202
 
268
203
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
269
- **Properties**
204
+ **Returns**: [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance) - The specified application installation.
270
205
 
271
- | Name | Type | Description |
206
+ | Param | Type | Description |
272
207
  | --- | --- | --- |
273
- | workflowIds | <code>string</code> | The list of IDs of the workflows you want to activate. |
208
+ | applicationId | <code>String</code> | The application ID. |
209
+ | installationId | <code>String</code> | The installation ID of the application instance. |
274
210
 
275
- <a name="Cobalt+toggleWorkflowStatus"></a>
211
+ <a name="Cobalt+updateInstallation"></a>
276
212
 
277
- ### cobalt.toggleWorkflowStatus() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
278
- Toggle the status of the specified workflow.
213
+ ### cobalt.updateInstallation(applicationId, installationId, payload) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
214
+ Update the specified application installation.
279
215
 
280
216
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
281
- **Properties**
217
+ **Returns**: [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance) - The specified application installation.
282
218
 
283
- | Name | Type | Description |
219
+ | Param | Type | Description |
284
220
  | --- | --- | --- |
285
- | workflowId | <code>string</code> | The ID of the workflow. |
221
+ | applicationId | <code>String</code> | The application ID. |
222
+ | installationId | <code>String</code> | The installation ID of the application instance. |
223
+ | payload | [<code>AppInstance</code>](#AppInstance) | The update payload. |
286
224
 
287
- <a name="Cobalt+deleteWorkflow"></a>
225
+ <a name="Cobalt+deleteInstallation"></a>
288
226
 
289
- ### cobalt.deleteWorkflow() ⇒ <code>Promise.&lt;unknown&gt;</code>
290
- Delete the specified workflow.
227
+ ### cobalt.deleteInstallation(applicationId, installationId) ⇒ <code>Promise.&lt;unknown&gt;</code>
228
+ Delete the specified installation.
291
229
 
292
230
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
293
- **Properties**
294
-
295
- | Name | Type | Description |
296
- | --- | --- | --- |
297
- | workflowId | <code>string</code> | The ID of the workflow. |
298
-
299
- <a name="Field"></a>
300
-
301
- ## Field : <code>object</code>
302
- The Node Field object available for configuration.
303
231
 
304
- **Kind**: global typedef
305
- **Properties**
306
-
307
- | Name | Type | Description |
232
+ | Param | Type | Description |
308
233
  | --- | --- | --- |
309
- | name | <code>string</code> | The field name. |
310
- | type | <code>string</code> | The input type of the field. |
311
- | placeholder | <code>string</code> | The placeholder text for the field. |
312
- | required | <code>boolean</code> | Whether the field is required. |
234
+ | applicationId | <code>String</code> | The application ID. |
235
+ | installationId | <code>String</code> | The installation ID of the application instance. |
313
236
 
314
- <a name="Node"></a>
237
+ <a name="AppConfig"></a>
315
238
 
316
- ## Node : <code>object</code>
317
- The Node object available for configuration.
239
+ ## AppConfig : <code>object</code>
240
+ The configuration data for an application.
318
241
 
319
242
  **Kind**: global typedef
320
243
  **Properties**
321
244
 
322
245
  | Name | Type | Description |
323
246
  | --- | --- | --- |
324
- | node_id | <code>string</code> | The ID of the installed workflow. |
325
- | node_name | <code>string</code> | The Name of the installed workflow. |
326
- | fields | [<code>Array.&lt;Field&gt;</code>](#Field) | The applications integrated in the workflow. |
247
+ | application_data_slots | <code>Array.&lt;DataSlot&gt;</code> | Array of application data slots. |
248
+ | templates | <code>Array.&lt;Template&gt;</code> | Array of workflow templates. |
327
249
 
328
- <a name="Workflow"></a>
250
+ <a name="AppInstance"></a>
329
251
 
330
- ## Workflow : <code>object</code>
331
- The installed workflow.
252
+ ## AppInstance : <code>Object</code>
253
+ An installed application.
332
254
 
333
255
  **Kind**: global typedef
334
256
  **Properties**
335
257
 
336
258
  | Name | Type | Description |
337
259
  | --- | --- | --- |
338
- | workflow_id | <code>string</code> | The ID of the installed workflow. |
339
- | applications | <code>Array.&lt;unknown&gt;</code> | The applications integrated in the workflow. |
340
- | configure | [<code>Array.&lt;Node&gt;</code>](#Node) | The configuration data for the workflow. |
260
+ | [intallation_id] | <code>String</code> | Unique ID for the installation. |
261
+ | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
262
+ | templates | [<code>Array.&lt;WorkflowTemplate&gt;</code>](#WorkflowTemplate) | Whether the workflow template is enabled. |
341
263
 
342
- <a name="AppAuthStatus"></a>
264
+ <a name="WorkflowTemplate"></a>
343
265
 
344
- ## AppAuthStatus : <code>object</code>
345
- The auth status of the user for an application.
266
+ ## WorkflowTemplate : <code>Object</code>
267
+ The workflow template.
346
268
 
347
269
  **Kind**: global typedef
348
270
  **Properties**
349
271
 
350
272
  | Name | Type | Description |
351
273
  | --- | --- | --- |
352
- | status | <code>boolean</code> | Whether the user has authenticated with this application. |
274
+ | id | <code>String</code> | The ID of the workflow template. |
275
+ | enabled | <code>Boolean</code> | Whether the workflow template is enabled. |
276
+ | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow template's data slots and their values. |
package/cobalt.js CHANGED
@@ -1,116 +1,35 @@
1
1
  /**
2
2
  * Cobalt Frontend SDK
3
+ * @property {String} token The session token.
3
4
  */
4
5
  class Cobalt {
5
6
  /**
6
7
  * Cobalt Frontend SDK
7
- * @param {object} options The options to configure the Cobalt SDK.
8
- * @param {string} [options.token] The session token.
9
- * @param {string} [options.baseUrl=https://api.gocobalt.io] The base URL of your Cobalt API.
8
+ * @param {Object} options The options to configure the Cobalt SDK.
9
+ * @param {String} [options.token] The session token.
10
+ * @param {String} [options.baseUrl=https://api.gocobalt.io] The base URL of the Cobalt API.
10
11
  */
11
12
  constructor(options) {
12
- this.apiBaseUrl = options?.baseUrl || "https://api.gocobalt.io";
13
+ this.baseUrl = options?.baseUrl || "https://api.gocobalt.io";
13
14
  this.token = options?.token;
14
15
  }
15
16
 
16
- /**
17
- * @returns {string} The session token.
18
- */
19
17
  get token() {
20
18
  return this.sessionToken;
21
19
  };
22
20
 
23
- /**
24
- * @returns {string} The session token.
25
- */
26
21
  set token(token) {
27
22
  return this.sessionToken = typeof token === "string" ? token : "";
28
23
  };
29
24
 
30
- /**
31
- * @returns {string} The base URL of cobalt API.
32
- */
33
- get baseUrl() {
34
- return this.apiBaseUrl;
35
- };
36
-
37
- /**
38
- * @typedef {object} Field The Node Field object available for configuration.
39
- * @property {string} name The field name.
40
- * @property {string} type The input type of the field.
41
- * @property {string} placeholder The placeholder text for the field.
42
- * @property {boolean} required Whether the field is required.
43
- */
44
-
45
- /**
46
- * @typedef {object} Node The Node object available for configuration.
47
- * @property {string} node_id The ID of the installed workflow.
48
- * @property {string} node_name The Name of the installed workflow.
49
- * @property {Field[]} fields The applications integrated in the workflow.
50
- */
51
-
52
- /**
53
- * @typedef {object} Workflow The installed workflow.
54
- * @property {string} workflow_id The ID of the installed workflow.
55
- * @property {unknown[]} applications The applications integrated in the workflow.
56
- * @property {Node[]} configure The configuration data for the workflow.
57
- */
58
-
59
- /**
60
- * @typedef {object} AppAuthStatus The auth status of the user for an application.
61
- * @property {boolean} status Whether the user has authenticated with this application.
62
- */
63
-
64
- /**
65
- * Install the given template.
66
- * @property {string} templateId The ID of the template you want to install.
67
- * @property {object} udf Custom key value pairs you want to store with the installed worklfow.
68
- * @returns {Promise<Workflow>}
69
- */
70
- async installTemplate(templateId, udf = {}) {
71
- const res = await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`, {
72
- method: "POST",
73
- headers: {
74
- authorization: `Bearer ${this.token}`,
75
- "content-type": "application/json",
76
- },
77
- body: JSON.stringify({ udf }),
78
- });
79
-
80
- if (res.status >= 400 && res.status < 600) {
81
- throw new Error(res.statusText);
82
- }
83
-
84
- return await res.json();
85
- }
86
-
87
- /**
88
- * Returns the auth status of the user for the specified application.
89
- * @property {string} application The application type.
90
- * @returns {Promise<boolean>} The auth status of the user.
91
- */
92
- async getAppAuthStatus(application) {
93
- const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`, {
94
- headers: {
95
- authorization: `Bearer ${this.token}`,
96
- },
97
- });
98
-
99
- if (res.status >= 400 && res.status < 600) {
100
- throw new Error(res.statusText);
101
- }
102
-
103
- const data = await res.json();
104
- return !!data?.status;
105
- }
106
-
107
25
  /**
108
26
  * Returns the auth URL that users can use to authenticate themselves to the
109
27
  * specified application.
110
- * @property {string} application The application type.
111
- * @returns {Promise<string>} The auth URL where users can authenticate themselves.
28
+ * @private
29
+ * @param {String} application The application type.
30
+ * @returns {Promise<String>} The auth URL where users can authenticate themselves.
112
31
  */
113
- async getAppAuthUrl(application) {
32
+ async getOAuthUrl(application) {
114
33
  const res = await fetch(`${this.baseUrl}/api/v1/${application}/integrate`, {
115
34
  headers: {
116
35
  authorization: `Bearer ${this.token}`,
@@ -126,19 +45,19 @@ class Cobalt {
126
45
  }
127
46
 
128
47
  /**
129
- * Handle OAuth for the specified application.
130
- * @property {string} application The application type.
131
- * @returns {Promise<boolean>} Whether the user authenticated.
48
+ * Handle OAuth for the specified native application.
49
+ * @param {String} application The application type.
50
+ * @returns {Promise<Boolean>} Whether the user authenticated.
132
51
  */
133
52
  async oauth(application) {
134
53
  return new Promise((resolve, reject) => {
135
- this.getAppAuthUrl(application)
54
+ this.getOAuthUrl(application)
136
55
  .then(oauthUrl => {
137
56
  const connectWindow = window.open(oauthUrl);
138
57
 
139
58
  // keep checking connection status
140
59
  const interval = setInterval(() => {
141
- this.getAppAuthStatus(application)
60
+ this.checkAuth(application)
142
61
  .then(connected => {
143
62
  if (connected === true) {
144
63
  // close auth window
@@ -170,14 +89,13 @@ class Cobalt {
170
89
 
171
90
  /**
172
91
  * Save the auth data that user provides to authenticate themselves to the
173
- * specified application.
174
- * @property {string} application The application type.
175
- * @property {object} payload The key value pairs of auth data.
176
- * @property {object} appId The application ID in case of custom applications.
177
- * @returns {Promise<void>}
92
+ * specified native application.
93
+ * @param {String} application The application type.
94
+ * @param {Object.<string, string | number | boolean>} payload The key value pairs of auth data.
95
+ * @returns {Promise<unknown>}
178
96
  */
179
- async setAppAuthData(application, payload, appId) {
180
- const res = await fetch(appId ? `${this.baseUrl}/api/v1/${application}/${appId}/save` : `${this.baseUrl}/api/v1/${application}/save`, {
97
+ async auth(application, payload) {
98
+ const res = await fetch(`${this.baseUrl}/api/v1/${application}/save`, {
181
99
  method: "POST",
182
100
  headers: {
183
101
  authorization: `Bearer ${this.token}`,
@@ -197,93 +115,84 @@ class Cobalt {
197
115
  }
198
116
 
199
117
  /**
200
- * Unauthorize the specified application and remove any associated data from Cobalt.
201
- * @property {string} application The application type.
202
- * @property {string} appId The application ID in case of custom applications.
203
- * @returns {Promise<void>}
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>}
204
123
  */
205
- async removeAppAuth(application, appId) {
206
- const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${appId}`, {
207
- method: "DELETE",
124
+ async authCustom(applicationId, payload) {
125
+ const res = await fetch(`${this.baseUrl}/api/v1/custom/${applicationId}/save`, {
126
+ method: "POST",
208
127
  headers: {
209
128
  authorization: `Bearer ${this.token}`,
129
+ "content-type": "application/json",
210
130
  },
131
+ body: JSON.stringify({
132
+ ...payload,
133
+ }),
211
134
  });
212
135
 
213
136
  if (res.status >= 400 && res.status < 600) {
214
137
  throw new Error(res.statusText);
215
138
  }
139
+
140
+ const data = await res.json();
141
+ return data;
216
142
  }
217
143
 
218
144
  /**
219
- * Returns the node configuration data for dynamic fields.
220
- * @property {string} workflowId The ID of the workflow.
221
- * @property {string} nodeId The ID of the node.
222
- * @property {string} fieldName The field name for which config data is required.
223
- * @property {object} selectedValues The input data already selected for the node.
224
- * @returns {Promise<Field[]>}
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.
225
148
  */
226
- async getNodeConfiguration(workflowId, nodeId, fieldName, selectedValues = {}) {
227
- const res = await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}/node/${nodeId}/configuration`, {
228
- method: "POST",
149
+ async checkAuth(application) {
150
+ const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`, {
229
151
  headers: {
230
152
  authorization: `Bearer ${this.token}`,
231
- "content-type": "application/json",
232
153
  },
233
- body: JSON.stringify({
234
- fieldName,
235
- selectedValues,
236
- }),
237
154
  });
238
155
 
239
156
  if (res.status >= 400 && res.status < 600) {
240
157
  throw new Error(res.statusText);
241
158
  }
242
159
 
243
- return await res.json();
160
+ const data = await res.json();
161
+ return !!data?.status;
244
162
  }
245
163
 
246
164
  /**
247
- * Save the input data for the specified node.
248
- * @property {string} workflowId The ID of the workflow.
249
- * @property {string} nodeId The ID of the node.
250
- * @property {object} inputData The input data for the node.
251
- * @returns {Promise<Workflow>}
165
+ * Unauthorize the specified application and remove any associated data from Cobalt.
166
+ * @param {String} application The application type.
167
+ * @param {String} [applicationId] The application ID in case of custom applications.
168
+ * @returns {Promise<void>}
252
169
  */
253
- async saveNode(workflowId, nodeId, inputData = {}) {
254
- const payload = {};
255
- for (const key in inputData) {
256
- if (Object.hasOwnProperty.call(inputData, key)) {
257
- const value = inputData[key];
258
- payload[key] = { value };
259
- }
260
- }
261
-
262
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`, {
263
- method: "PUT",
170
+ async removeAuth(application, applicationId) {
171
+ const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${applicationId}`, {
172
+ method: "DELETE",
264
173
  headers: {
265
174
  authorization: `Bearer ${this.token}`,
266
- "content-type": "application/json",
267
175
  },
268
- body: JSON.stringify({
269
- input_data: payload,
270
- }),
271
176
  });
272
177
 
273
178
  if (res.status >= 400 && res.status < 600) {
274
179
  throw new Error(res.statusText);
275
180
  }
276
-
277
- return await res.json();
278
181
  }
279
182
 
280
183
  /**
281
- * Returns the workflow configuration data.
282
- * @property {string} workflowId The ID of the workflow.
283
- * @returns {Promise<Workflow>}
184
+ * @typedef {object} AppConfig The configuration data for an application.
185
+ * @property {DataSlot[]} application_data_slots Array of application data slots.
186
+ * @property {Template[]} templates Array of workflow templates.
187
+ */
188
+
189
+ /**
190
+ * Returns the configuration data for the specified application.
191
+ * @param {String} application The application ID.
192
+ * @returns {Promise<AppConfig>} The specified application's configuration data.
284
193
  */
285
- async getWorkflowConfiguration(workflowId) {
286
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/configuration`, {
194
+ async getAppConfig(application) {
195
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${application}/config`, {
287
196
  headers: {
288
197
  authorization: `Bearer ${this.token}`,
289
198
  },
@@ -297,16 +206,33 @@ class Cobalt {
297
206
  }
298
207
 
299
208
  /**
300
- * Activate the given installed workflow.
301
- * @property {string} workflowId The ID of the workflow you want to activate.
302
- * @returns {Promise<void>}
209
+ * @typedef {Object} AppInstance An installed application.
210
+ * @property {String} [intallation_id] Unique ID for the installation.
211
+ * @property {Object.<string, string | number | boolean>} application_data_slots A map of application data slots and their values.
212
+ * @property {WorkflowTemplate[]} templates Whether the workflow template is enabled.
303
213
  */
304
- async activateWorkflow(workflowId) {
305
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/install/success`, {
306
- method: "PUT",
214
+
215
+ /**
216
+ * @typedef {Object} WorkflowTemplate The workflow template.
217
+ * @property {String} id The ID of the workflow template.
218
+ * @property {Boolean} enabled Whether the workflow template is enabled.
219
+ * @property {Object.<string, string | number | boolean>} data_slots A map of workflow template's data slots and their values.
220
+ */
221
+
222
+ /**
223
+ * Install the specified application.
224
+ * @param {String} applicationId The application ID.
225
+ * @param {AppInstance} payload The install payload.
226
+ * @returns {Promise<AppInstance>} The specified application installation.
227
+ */
228
+ async install(applicationId, payload = {}) {
229
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/install`, {
230
+ method: "POST",
307
231
  headers: {
308
232
  authorization: `Bearer ${this.token}`,
233
+ "content-type": "application/json",
309
234
  },
235
+ body: JSON.stringify(payload),
310
236
  });
311
237
 
312
238
  if (res.status >= 400 && res.status < 600) {
@@ -317,19 +243,16 @@ class Cobalt {
317
243
  }
318
244
 
319
245
  /**
320
- * Activate the given installed workflows.
321
- * @property {string} workflowIds The list of IDs of the workflows you want to activate.
322
- * @returns {Promise<void>}
246
+ * Returns the specified application installation.
247
+ * @param {String} applicationId The application ID.
248
+ * @param {String} installationId The installation ID of the application instance.
249
+ * @returns {Promise<AppInstance>} The specified application installation.
323
250
  */
324
- async activateWorkflows(workflowIds = []) {
325
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/install/success`, {
326
- method: "PUT",
251
+ async getInstallation(applicationId, installationId) {
252
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`, {
327
253
  headers: {
328
254
  authorization: `Bearer ${this.token}`,
329
255
  },
330
- body: JSON.stringify({
331
- workflow_ids: workflowIds,
332
- }),
333
256
  });
334
257
 
335
258
  if (res.status >= 400 && res.status < 600) {
@@ -340,16 +263,20 @@ class Cobalt {
340
263
  }
341
264
 
342
265
  /**
343
- * Toggle the status of the specified workflow.
344
- * @property {string} workflowId The ID of the workflow.
345
- * @returns {Promise<Workflow>}
266
+ * Update the specified application installation.
267
+ * @param {String} applicationId The application ID.
268
+ * @param {String} installationId The installation ID of the application instance.
269
+ * @param {AppInstance} payload The update payload.
270
+ * @returns {Promise<AppInstance>} The specified application installation.
346
271
  */
347
- async toggleWorkflowStatus(workflowId) {
348
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/toggle-status`, {
272
+ async updateInstallation(applicationId, installationId, payload = {}) {
273
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`, {
349
274
  method: "PUT",
350
275
  headers: {
351
276
  authorization: `Bearer ${this.token}`,
277
+ "content-type": "application/json",
352
278
  },
279
+ body: JSON.stringify(payload),
353
280
  });
354
281
 
355
282
  if (res.status >= 400 && res.status < 600) {
@@ -360,12 +287,13 @@ class Cobalt {
360
287
  }
361
288
 
362
289
  /**
363
- * Delete the specified workflow.
364
- * @property {string} workflowId The ID of the workflow.
290
+ * Delete the specified installation.
291
+ * @param {String} applicationId The application ID.
292
+ * @param {String} installationId The installation ID of the application instance.
365
293
  * @returns {Promise<unknown>}
366
294
  */
367
- async deleteWorkflow(workflowId) {
368
- const res = await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}`, {
295
+ async deleteInstallation(applicationId, installationId) {
296
+ const res = await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`, {
369
297
  method: "DELETE",
370
298
  headers: {
371
299
  authorization: `Bearer ${this.token}`,
package/cobalt.min.js CHANGED
@@ -1 +1 @@
1
- class Cobalt{constructor(options){this.apiBaseUrl=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:""}get baseUrl(){return this.apiBaseUrl}async installTemplate(templateId,udf={}){const res=await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({udf:udf})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async getAppAuthStatus(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 getAppAuthUrl(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.getAppAuthUrl(application).then(oauthUrl=>{const connectWindow=window.open(oauthUrl);const interval=setInterval(()=>{this.getAppAuthStatus(application).then(connected=>{if(connected===true){connectWindow?.close();clearInterval(interval);resolve(true)}else{if(connectWindow?.closed){clearInterval(interval);resolve(false)}}}).catch(e=>{console.error(e);clearInterval(interval);reject(e)})},3e3)}).catch(reject)})}async setAppAuthData(application,payload,appId){const res=await fetch(appId?`${this.baseUrl}/api/v1/${application}/${appId}/save`:`${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 removeAppAuth(application,appId){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${appId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}}async getNodeConfiguration(workflowId,nodeId,fieldName,selectedValues={}){const res=await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}/node/${nodeId}/configuration`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({fieldName:fieldName,selectedValues:selectedValues})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async saveNode(workflowId,nodeId,inputData={}){const payload={};for(const key in inputData){if(Object.hasOwnProperty.call(inputData,key)){const value=inputData[key];payload[key]={value:value}}}const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({input_data:payload})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async getWorkflowConfiguration(workflowId){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/configuration`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async activateWorkflow(workflowId){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/install/success`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async activateWorkflows(workflowIds=[]){const res=await fetch(`${this.baseUrl}/api/v2/workflow/install/success`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`},body:JSON.stringify({workflow_ids:workflowIds})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async toggleWorkflowStatus(workflowId){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/toggle-status`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async deleteWorkflow(workflowId){const res=await fetch(`${this.baseUrl}/api/v1/workflow/${workflowId}`,{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;
1
+ class Cobalt{constructor(options){this.baseUrl=options?.baseUrl||"https://api.gocobalt.io";this.token=options?.token}get token(){return this.sessionToken}set token(token){return this.sessionToken=typeof token==="string"?token:""}async getOAuthUrl(application){const res=await fetch(`${this.baseUrl}/api/v1/${application}/integrate`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return data?.auth_url}async oauth(application){return new Promise((resolve,reject)=>{this.getOAuthUrl(application).then(oauthUrl=>{const connectWindow=window.open(oauthUrl);const interval=setInterval(()=>{this.checkAuth(application).then(connected=>{if(connected===true){connectWindow?.close();clearInterval(interval);resolve(true)}else{if(connectWindow?.closed){clearInterval(interval);resolve(false)}}}).catch(e=>{console.error(e);clearInterval(interval);reject(e)})},3e3)}).catch(reject)})}async auth(application,payload){const res=await fetch(`${this.baseUrl}/api/v1/${application}/save`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({...payload})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return data}async authCustom(applicationId,payload){const res=await fetch(`${this.baseUrl}/api/v1/custom/${applicationId}/save`,{method:"POST",headers:{authorization:`Bearer ${this.token}`,"content-type":"application/json"},body:JSON.stringify({...payload})});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return data}async checkAuth(application){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/auth?integration_type=${application}`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}const data=await res.json();return!!data?.status}async removeAuth(application,applicationId){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}?app_id=${applicationId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}}async getAppConfig(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 install(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 getInstallation(applicationId,installationId){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`,{headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}async updateInstallation(applicationId,installationId,payload={}){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`,{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 deleteInstallation(applicationId,installationId){const res=await fetch(`${this.baseUrl}/api/v1/application/${applicationId}/installation/${installationId}`,{method:"DELETE",headers:{authorization:`Bearer ${this.token}`}});if(res.status>=400&&res.status<600){throw new Error(res.statusText)}return await res.json()}}module.exports=Cobalt;
package/docs.md CHANGED
@@ -9,17 +9,14 @@
9
9
  ## Typedefs
10
10
 
11
11
  <dl>
12
- <dt><a href="#Field">Field</a> : <code>object</code></dt>
13
- <dd><p>The Node Field object available for configuration.</p>
12
+ <dt><a href="#AppConfig">AppConfig</a> : <code>object</code></dt>
13
+ <dd><p>The configuration data for an application.</p>
14
14
  </dd>
15
- <dt><a href="#Node">Node</a> : <code>object</code></dt>
16
- <dd><p>The Node object available for configuration.</p>
15
+ <dt><a href="#AppInstance">AppInstance</a> : <code>Object</code></dt>
16
+ <dd><p>An installed application.</p>
17
17
  </dd>
18
- <dt><a href="#Workflow">Workflow</a> : <code>object</code></dt>
19
- <dd><p>The installed workflow.</p>
20
- </dd>
21
- <dt><a href="#AppAuthStatus">AppAuthStatus</a> : <code>object</code></dt>
22
- <dd><p>The auth status of the user for an application.</p>
18
+ <dt><a href="#WorkflowTemplate">WorkflowTemplate</a> : <code>Object</code></dt>
19
+ <dd><p>The workflow template.</p>
23
20
  </dd>
24
21
  </dl>
25
22
 
@@ -29,25 +26,25 @@
29
26
  Cobalt Frontend SDK
30
27
 
31
28
  **Kind**: global class
29
+ **Properties**
30
+
31
+ | Name | Type | Description |
32
+ | --- | --- | --- |
33
+ | token | <code>String</code> | The session token. |
34
+
32
35
 
33
36
  * [Cobalt](#Cobalt)
34
37
  * [new Cobalt(options)](#new_Cobalt_new)
35
- * [.token](#Cobalt+token) ⇒ <code>string</code>
36
- * [.token](#Cobalt+token) ⇒ <code>string</code>
37
- * [.baseUrl](#Cobalt+baseUrl) ⇒ <code>string</code>
38
- * [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
39
- * [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.&lt;boolean&gt;</code>
40
- * [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.&lt;string&gt;</code>
41
- * [.oauth()](#Cobalt+oauth) ⇒ <code>Promise.&lt;boolean&gt;</code>
42
- * [.setAppAuthData()](#Cobalt+setAppAuthData) ⇒ <code>Promise.&lt;void&gt;</code>
43
- * [.removeAppAuth()](#Cobalt+removeAppAuth) ⇒ <code>Promise.&lt;void&gt;</code>
44
- * [.getNodeConfiguration()](#Cobalt+getNodeConfiguration) ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
45
- * [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
46
- * [.getWorkflowConfiguration()](#Cobalt+getWorkflowConfiguration) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
47
- * [.activateWorkflow()](#Cobalt+activateWorkflow) ⇒ <code>Promise.&lt;void&gt;</code>
48
- * [.activateWorkflows()](#Cobalt+activateWorkflows) ⇒ <code>Promise.&lt;void&gt;</code>
49
- * [.toggleWorkflowStatus()](#Cobalt+toggleWorkflowStatus) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
50
- * [.deleteWorkflow()](#Cobalt+deleteWorkflow) ⇒ <code>Promise.&lt;unknown&gt;</code>
38
+ * [.oauth(application)](#Cobalt+oauth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
39
+ * [.auth(application, payload)](#Cobalt+auth) ⇒ <code>Promise.&lt;unknown&gt;</code>
40
+ * [.authCustom(applicationId, payload)](#Cobalt+authCustom) ⇒ <code>Promise.&lt;unknown&gt;</code>
41
+ * [.checkAuth(application)](#Cobalt+checkAuth) ⇒ <code>Promise.&lt;Boolean&gt;</code>
42
+ * [.removeAuth(application, [applicationId])](#Cobalt+removeAuth) ⇒ <code>Promise.&lt;void&gt;</code>
43
+ * [.getAppConfig(application)](#Cobalt+getAppConfig) ⇒ [<code>Promise.&lt;AppConfig&gt;</code>](#AppConfig)
44
+ * [.install(applicationId, payload)](#Cobalt+install) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
45
+ * [.getInstallation(applicationId, installationId)](#Cobalt+getInstallation) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
46
+ * [.updateInstallation(applicationId, installationId, payload)](#Cobalt+updateInstallation) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
47
+ * [.deleteInstallation(applicationId, installationId)](#Cobalt+deleteInstallation) ⇒ <code>Promise.&lt;unknown&gt;</code>
51
48
 
52
49
  <a name="new_Cobalt_new"></a>
53
50
 
@@ -57,247 +54,174 @@ Cobalt Frontend SDK
57
54
 
58
55
  | Param | Type | Default | Description |
59
56
  | --- | --- | --- | --- |
60
- | options | <code>object</code> | | The options to configure the Cobalt SDK. |
61
- | [options.token] | <code>string</code> | | The session token. |
62
- | [options.baseUrl] | <code>string</code> | <code>&quot;https://api.gocobalt.io&quot;</code> | The base URL of your Cobalt API. |
63
-
64
- <a name="Cobalt+token"></a>
65
-
66
- ### cobalt.token ⇒ <code>string</code>
67
- **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
68
- **Returns**: <code>string</code> - The session token.
69
- <a name="Cobalt+token"></a>
70
-
71
- ### cobalt.token ⇒ <code>string</code>
72
- **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
73
- **Returns**: <code>string</code> - The session token.
74
- <a name="Cobalt+baseUrl"></a>
75
-
76
- ### cobalt.baseUrl ⇒ <code>string</code>
77
- **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
78
- **Returns**: <code>string</code> - The base URL of cobalt API.
79
- <a name="Cobalt+installTemplate"></a>
80
-
81
- ### cobalt.installTemplate() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
82
- Install the given template.
83
-
84
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
85
- **Properties**
86
-
87
- | Name | Type | Description |
88
- | --- | --- | --- |
89
- | templateId | <code>string</code> | The ID of the template you want to install. |
90
- | udf | <code>object</code> | Custom key value pairs you want to store with the installed worklfow. |
91
-
92
- <a name="Cobalt+getAppAuthStatus"></a>
93
-
94
- ### cobalt.getAppAuthStatus() ⇒ <code>Promise.&lt;boolean&gt;</code>
95
- Returns the auth status of the user for the specified application.
96
-
97
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
98
- **Returns**: <code>Promise.&lt;boolean&gt;</code> - The auth status of the user.
99
- **Properties**
100
-
101
- | Name | Type | Description |
102
- | --- | --- | --- |
103
- | application | <code>string</code> | The application type. |
104
-
105
- <a name="Cobalt+getAppAuthUrl"></a>
106
-
107
- ### cobalt.getAppAuthUrl() ⇒ <code>Promise.&lt;string&gt;</code>
108
- Returns the auth URL that users can use to authenticate themselves to the
109
- specified application.
110
-
111
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
112
- **Returns**: <code>Promise.&lt;string&gt;</code> - The auth URL where users can authenticate themselves.
113
- **Properties**
114
-
115
- | Name | Type | Description |
116
- | --- | --- | --- |
117
- | application | <code>string</code> | The application type. |
57
+ | options | <code>Object</code> | | The options to configure the Cobalt SDK. |
58
+ | [options.token] | <code>String</code> | | The session token. |
59
+ | [options.baseUrl] | <code>String</code> | <code>https://api.gocobalt.io</code> | The base URL of the Cobalt API. |
118
60
 
119
61
  <a name="Cobalt+oauth"></a>
120
62
 
121
- ### cobalt.oauth() ⇒ <code>Promise.&lt;boolean&gt;</code>
122
- Handle OAuth for the specified application.
63
+ ### cobalt.oauth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
64
+ Handle OAuth for the specified native application.
123
65
 
124
66
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
125
- **Returns**: <code>Promise.&lt;boolean&gt;</code> - Whether the user authenticated.
126
- **Properties**
67
+ **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the user authenticated.
127
68
 
128
- | Name | Type | Description |
69
+ | Param | Type | Description |
129
70
  | --- | --- | --- |
130
- | application | <code>string</code> | The application type. |
71
+ | application | <code>String</code> | The application type. |
131
72
 
132
- <a name="Cobalt+setAppAuthData"></a>
73
+ <a name="Cobalt+auth"></a>
133
74
 
134
- ### cobalt.setAppAuthData() ⇒ <code>Promise.&lt;void&gt;</code>
75
+ ### cobalt.auth(application, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
135
76
  Save the auth data that user provides to authenticate themselves to the
136
- specified application.
77
+ specified native application.
137
78
 
138
79
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
139
- **Properties**
140
80
 
141
- | Name | Type | Description |
81
+ | Param | Type | Description |
142
82
  | --- | --- | --- |
143
- | application | <code>string</code> | The application type. |
144
- | payload | <code>object</code> | The key value pairs of auth data. |
145
- | appId | <code>object</code> | The application ID in case of custom applications. |
83
+ | application | <code>String</code> | The application type. |
84
+ | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
146
85
 
147
- <a name="Cobalt+removeAppAuth"></a>
86
+ <a name="Cobalt+authCustom"></a>
148
87
 
149
- ### cobalt.removeAppAuth() ⇒ <code>Promise.&lt;void&gt;</code>
150
- Unauthorize the specified application and remove any associated data from Cobalt.
88
+ ### cobalt.authCustom(applicationId, payload) ⇒ <code>Promise.&lt;unknown&gt;</code>
89
+ Save the auth data that user provides to authenticate themselves to the
90
+ specified custom application.
151
91
 
152
92
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
153
- **Properties**
154
93
 
155
- | Name | Type | Description |
94
+ | Param | Type | Description |
156
95
  | --- | --- | --- |
157
- | application | <code>string</code> | The application type. |
158
- | appId | <code>string</code> | The application ID in case of custom applications. |
96
+ | applicationId | <code>String</code> | The application ID of the custom application. |
97
+ | payload | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | The key value pairs of auth data. |
159
98
 
160
- <a name="Cobalt+getNodeConfiguration"></a>
99
+ <a name="Cobalt+checkAuth"></a>
161
100
 
162
- ### cobalt.getNodeConfiguration() ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
163
- Returns the node configuration data for dynamic fields.
101
+ ### cobalt.checkAuth(application) ⇒ <code>Promise.&lt;Boolean&gt;</code>
102
+ Returns the auth status of the user for the specified application.
164
103
 
165
104
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
166
- **Properties**
105
+ **Returns**: <code>Promise.&lt;Boolean&gt;</code> - The auth status of the user.
167
106
 
168
- | Name | Type | Description |
107
+ | Param | Type | Description |
169
108
  | --- | --- | --- |
170
- | workflowId | <code>string</code> | The ID of the workflow. |
171
- | nodeId | <code>string</code> | The ID of the node. |
172
- | fieldName | <code>string</code> | The field name for which config data is required. |
173
- | selectedValues | <code>object</code> | The input data already selected for the node. |
109
+ | application | <code>String</code> | The application type. |
174
110
 
175
- <a name="Cobalt+saveNode"></a>
111
+ <a name="Cobalt+removeAuth"></a>
176
112
 
177
- ### cobalt.saveNode() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
178
- Save the input data for the specified node.
113
+ ### cobalt.removeAuth(application, [applicationId]) ⇒ <code>Promise.&lt;void&gt;</code>
114
+ Unauthorize the specified application and remove any associated data from Cobalt.
179
115
 
180
116
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
181
- **Properties**
182
117
 
183
- | Name | Type | Description |
118
+ | Param | Type | Description |
184
119
  | --- | --- | --- |
185
- | workflowId | <code>string</code> | The ID of the workflow. |
186
- | nodeId | <code>string</code> | The ID of the node. |
187
- | inputData | <code>object</code> | The input data for the node. |
120
+ | application | <code>String</code> | The application type. |
121
+ | [applicationId] | <code>String</code> | The application ID in case of custom applications. |
188
122
 
189
- <a name="Cobalt+getWorkflowConfiguration"></a>
123
+ <a name="Cobalt+getAppConfig"></a>
190
124
 
191
- ### cobalt.getWorkflowConfiguration() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
192
- Returns the workflow configuration data.
125
+ ### cobalt.getAppConfig(application) ⇒ [<code>Promise.&lt;AppConfig&gt;</code>](#AppConfig)
126
+ Returns the configuration data for the specified application.
193
127
 
194
128
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
195
- **Properties**
129
+ **Returns**: [<code>Promise.&lt;AppConfig&gt;</code>](#AppConfig) - The specified application's configuration data.
196
130
 
197
- | Name | Type | Description |
131
+ | Param | Type | Description |
198
132
  | --- | --- | --- |
199
- | workflowId | <code>string</code> | The ID of the workflow. |
133
+ | application | <code>String</code> | The application ID. |
200
134
 
201
- <a name="Cobalt+activateWorkflow"></a>
135
+ <a name="Cobalt+install"></a>
202
136
 
203
- ### cobalt.activateWorkflow() ⇒ <code>Promise.&lt;void&gt;</code>
204
- Activate the given installed workflow.
137
+ ### cobalt.install(applicationId, payload) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
138
+ Install the specified application.
205
139
 
206
140
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
207
- **Properties**
141
+ **Returns**: [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance) - The specified application installation.
208
142
 
209
- | Name | Type | Description |
143
+ | Param | Type | Description |
210
144
  | --- | --- | --- |
211
- | workflowId | <code>string</code> | The ID of the workflow you want to activate. |
145
+ | applicationId | <code>String</code> | The application ID. |
146
+ | payload | [<code>AppInstance</code>](#AppInstance) | The install payload. |
212
147
 
213
- <a name="Cobalt+activateWorkflows"></a>
148
+ <a name="Cobalt+getInstallation"></a>
214
149
 
215
- ### cobalt.activateWorkflows() ⇒ <code>Promise.&lt;void&gt;</code>
216
- Activate the given installed workflows.
150
+ ### cobalt.getInstallation(applicationId, installationId) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
151
+ Returns the specified application installation.
217
152
 
218
153
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
219
- **Properties**
154
+ **Returns**: [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance) - The specified application installation.
220
155
 
221
- | Name | Type | Description |
156
+ | Param | Type | Description |
222
157
  | --- | --- | --- |
223
- | workflowIds | <code>string</code> | The list of IDs of the workflows you want to activate. |
158
+ | applicationId | <code>String</code> | The application ID. |
159
+ | installationId | <code>String</code> | The installation ID of the application instance. |
224
160
 
225
- <a name="Cobalt+toggleWorkflowStatus"></a>
161
+ <a name="Cobalt+updateInstallation"></a>
226
162
 
227
- ### cobalt.toggleWorkflowStatus() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
228
- Toggle the status of the specified workflow.
163
+ ### cobalt.updateInstallation(applicationId, installationId, payload) ⇒ [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance)
164
+ Update the specified application installation.
229
165
 
230
166
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
231
- **Properties**
167
+ **Returns**: [<code>Promise.&lt;AppInstance&gt;</code>](#AppInstance) - The specified application installation.
232
168
 
233
- | Name | Type | Description |
169
+ | Param | Type | Description |
234
170
  | --- | --- | --- |
235
- | workflowId | <code>string</code> | The ID of the workflow. |
171
+ | applicationId | <code>String</code> | The application ID. |
172
+ | installationId | <code>String</code> | The installation ID of the application instance. |
173
+ | payload | [<code>AppInstance</code>](#AppInstance) | The update payload. |
236
174
 
237
- <a name="Cobalt+deleteWorkflow"></a>
175
+ <a name="Cobalt+deleteInstallation"></a>
238
176
 
239
- ### cobalt.deleteWorkflow() ⇒ <code>Promise.&lt;unknown&gt;</code>
240
- Delete the specified workflow.
177
+ ### cobalt.deleteInstallation(applicationId, installationId) ⇒ <code>Promise.&lt;unknown&gt;</code>
178
+ Delete the specified installation.
241
179
 
242
180
  **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
243
- **Properties**
244
-
245
- | Name | Type | Description |
246
- | --- | --- | --- |
247
- | workflowId | <code>string</code> | The ID of the workflow. |
248
-
249
- <a name="Field"></a>
250
-
251
- ## Field : <code>object</code>
252
- The Node Field object available for configuration.
253
181
 
254
- **Kind**: global typedef
255
- **Properties**
256
-
257
- | Name | Type | Description |
182
+ | Param | Type | Description |
258
183
  | --- | --- | --- |
259
- | name | <code>string</code> | The field name. |
260
- | type | <code>string</code> | The input type of the field. |
261
- | placeholder | <code>string</code> | The placeholder text for the field. |
262
- | required | <code>boolean</code> | Whether the field is required. |
184
+ | applicationId | <code>String</code> | The application ID. |
185
+ | installationId | <code>String</code> | The installation ID of the application instance. |
263
186
 
264
- <a name="Node"></a>
187
+ <a name="AppConfig"></a>
265
188
 
266
- ## Node : <code>object</code>
267
- The Node object available for configuration.
189
+ ## AppConfig : <code>object</code>
190
+ The configuration data for an application.
268
191
 
269
192
  **Kind**: global typedef
270
193
  **Properties**
271
194
 
272
195
  | Name | Type | Description |
273
196
  | --- | --- | --- |
274
- | node_id | <code>string</code> | The ID of the installed workflow. |
275
- | node_name | <code>string</code> | The Name of the installed workflow. |
276
- | fields | [<code>Array.&lt;Field&gt;</code>](#Field) | The applications integrated in the workflow. |
197
+ | application_data_slots | <code>Array.&lt;DataSlot&gt;</code> | Array of application data slots. |
198
+ | templates | <code>Array.&lt;Template&gt;</code> | Array of workflow templates. |
277
199
 
278
- <a name="Workflow"></a>
200
+ <a name="AppInstance"></a>
279
201
 
280
- ## Workflow : <code>object</code>
281
- The installed workflow.
202
+ ## AppInstance : <code>Object</code>
203
+ An installed application.
282
204
 
283
205
  **Kind**: global typedef
284
206
  **Properties**
285
207
 
286
208
  | Name | Type | Description |
287
209
  | --- | --- | --- |
288
- | workflow_id | <code>string</code> | The ID of the installed workflow. |
289
- | applications | <code>Array.&lt;unknown&gt;</code> | The applications integrated in the workflow. |
290
- | configure | [<code>Array.&lt;Node&gt;</code>](#Node) | The configuration data for the workflow. |
210
+ | [intallation_id] | <code>String</code> | Unique ID for the installation. |
211
+ | application_data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application data slots and their values. |
212
+ | templates | [<code>Array.&lt;WorkflowTemplate&gt;</code>](#WorkflowTemplate) | Whether the workflow template is enabled. |
291
213
 
292
- <a name="AppAuthStatus"></a>
214
+ <a name="WorkflowTemplate"></a>
293
215
 
294
- ## AppAuthStatus : <code>object</code>
295
- The auth status of the user for an application.
216
+ ## WorkflowTemplate : <code>Object</code>
217
+ The workflow template.
296
218
 
297
219
  **Kind**: global typedef
298
220
  **Properties**
299
221
 
300
222
  | Name | Type | Description |
301
223
  | --- | --- | --- |
302
- | status | <code>boolean</code> | Whether the user has authenticated with this application. |
224
+ | id | <code>String</code> | The ID of the workflow template. |
225
+ | enabled | <code>Boolean</code> | Whether the workflow template is enabled. |
226
+ | data_slots | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow template's data slots and their values. |
303
227
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {
@@ -29,7 +29,6 @@
29
29
  },
30
30
  "homepage": "https://github.com/Breakout-Embed/cobalt-js#readme",
31
31
  "devDependencies": {
32
- "foodoc": "^0.0.9",
33
32
  "jsdoc": "^4.0.0",
34
33
  "jsdoc-to-markdown": "^8.0.0",
35
34
  "uglify-js": "^3.17.4"