@cobaltio/cobalt-js 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ yarn add @cobaltio/cobalt-js
15
15
 
16
16
  ## Usage
17
17
 
18
- Check the SDK [documentation](docs.md) for detailed information.
18
+ <!-- Check the SDK [documentation](docs.md) for detailed information. -->
19
19
 
20
20
  ### Include
21
21
 
@@ -45,3 +45,264 @@ const cobalt = new Cobalt();
45
45
  // the token you generate for linked accounts using the cobalt backend SDK
46
46
  cobalt.token = "COBALT_SESSION_TOKEN";
47
47
  ```
48
+
49
+ ### SDK
50
+
51
+ ## Classes
52
+
53
+ <dl>
54
+ <dt><a href="#Cobalt">Cobalt</a></dt>
55
+ <dd><p>Cobalt Frontend SDK</p>
56
+ </dd>
57
+ </dl>
58
+
59
+ ## Typedefs
60
+
61
+ <dl>
62
+ <dt><a href="#Field">Field</a> : <code>object</code></dt>
63
+ <dd><p>The Node Field object available for configuration.</p>
64
+ </dd>
65
+ <dt><a href="#Node">Node</a> : <code>object</code></dt>
66
+ <dd><p>The Node object available for configuration.</p>
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>
73
+ </dd>
74
+ </dl>
75
+
76
+ <a name="Cobalt"></a>
77
+
78
+ ## Cobalt
79
+ Cobalt Frontend SDK
80
+
81
+ **Kind**: global class
82
+
83
+ * [Cobalt](#Cobalt)
84
+ * [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
+ * [.removeAppAuth()](#Cobalt+removeAppAuth) ⇒ <code>Promise.&lt;void&gt;</code>
92
+ * [.getNodeConfiguration()](#Cobalt+getNodeConfiguration) ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
93
+ * [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
94
+ * [.getWorkflowConfiguration()](#Cobalt+getWorkflowConfiguration) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
95
+ * [.activateWorkflow()](#Cobalt+activateWorkflow) ⇒ <code>Promise.&lt;void&gt;</code>
96
+ * [.toggleWorkflowStatus()](#Cobalt+toggleWorkflowStatus) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
97
+ * [.deleteWorkflow()](#Cobalt+deleteWorkflow) ⇒ <code>Promise.&lt;unknown&gt;</code>
98
+
99
+ <a name="new_Cobalt_new"></a>
100
+
101
+ ### new Cobalt(options)
102
+ Cobalt Frontend SDK
103
+
104
+
105
+ | Param | Type | Default | Description |
106
+ | --- | --- | --- | --- |
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>&quot;https://api.gocobalt.io&quot;</code> | The base URL of your Cobalt API. |
110
+
111
+ <a name="Cobalt+token"></a>
112
+
113
+ ### cobalt.token ⇒ <code>string</code>
114
+ **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
115
+ **Returns**: <code>string</code> - The session token.
116
+ <a name="Cobalt+token"></a>
117
+
118
+ ### cobalt.token ⇒ <code>string</code>
119
+ **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
120
+ **Returns**: <code>string</code> - The session token.
121
+ <a name="Cobalt+baseUrl"></a>
122
+
123
+ ### cobalt.baseUrl ⇒ <code>string</code>
124
+ **Kind**: instance property of [<code>Cobalt</code>](#Cobalt)
125
+ **Returns**: <code>string</code> - The base URL of cobalt API.
126
+ <a name="Cobalt+installTemplate"></a>
127
+
128
+ ### cobalt.installTemplate() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
129
+ Install the given template.
130
+
131
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
132
+ **Properties**
133
+
134
+ | Name | Type | Description |
135
+ | --- | --- | --- |
136
+ | templateId | <code>string</code> | The ID of the template you want to install. |
137
+ | udf | <code>object</code> | Custom key value pairs you want to store with the installed worklfow. |
138
+
139
+ <a name="Cobalt+getAppAuthStatus"></a>
140
+
141
+ ### cobalt.getAppAuthStatus() ⇒ <code>Promise.&lt;boolean&gt;</code>
142
+ Returns the auth status of the user for the specified application.
143
+
144
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
145
+ **Returns**: <code>Promise.&lt;boolean&gt;</code> - The auth status of the user.
146
+ **Properties**
147
+
148
+ | Name | Type | Description |
149
+ | --- | --- | --- |
150
+ | application | <code>string</code> | The application type. |
151
+
152
+ <a name="Cobalt+getAppAuthUrl"></a>
153
+
154
+ ### cobalt.getAppAuthUrl() ⇒ <code>Promise.&lt;string&gt;</code>
155
+ Returns the auth URL that users can use to authenticate themselves to the
156
+ specified application.
157
+
158
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
159
+ **Returns**: <code>Promise.&lt;string&gt;</code> - The auth URL where users can authenticate themselves.
160
+ **Properties**
161
+
162
+ | Name | Type | Description |
163
+ | --- | --- | --- |
164
+ | application | <code>string</code> | The application type. |
165
+
166
+ <a name="Cobalt+removeAppAuth"></a>
167
+
168
+ ### cobalt.removeAppAuth() ⇒ <code>Promise.&lt;void&gt;</code>
169
+ Unauthorize the specified application and remove any associated data from Cobalt.
170
+
171
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
172
+ **Properties**
173
+
174
+ | Name | Type | Description |
175
+ | --- | --- | --- |
176
+ | application | <code>string</code> | The application type. |
177
+
178
+ <a name="Cobalt+getNodeConfiguration"></a>
179
+
180
+ ### cobalt.getNodeConfiguration() ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
181
+ Returns the node configuration data for dynamic fields.
182
+
183
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
184
+ **Properties**
185
+
186
+ | Name | Type | Description |
187
+ | --- | --- | --- |
188
+ | workflowId | <code>string</code> | The ID of the workflow. |
189
+ | nodeId | <code>string</code> | The ID of the node. |
190
+ | fieldName | <code>string</code> | The field name for which config data is required. |
191
+ | selectedValues | <code>object</code> | The input data already selected for the node. |
192
+
193
+ <a name="Cobalt+saveNode"></a>
194
+
195
+ ### cobalt.saveNode() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
196
+ Save the input data for the specified node.
197
+
198
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
199
+ **Properties**
200
+
201
+ | Name | Type | Description |
202
+ | --- | --- | --- |
203
+ | workflowId | <code>string</code> | The ID of the workflow. |
204
+ | nodeId | <code>string</code> | The ID of the node. |
205
+ | inputData | <code>object</code> | The input data for the node. |
206
+
207
+ <a name="Cobalt+getWorkflowConfiguration"></a>
208
+
209
+ ### cobalt.getWorkflowConfiguration() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
210
+ Returns the workflow configuration data.
211
+
212
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
213
+ **Properties**
214
+
215
+ | Name | Type | Description |
216
+ | --- | --- | --- |
217
+ | workflowId | <code>string</code> | The ID of the workflow. |
218
+
219
+ <a name="Cobalt+activateWorkflow"></a>
220
+
221
+ ### cobalt.activateWorkflow() ⇒ <code>Promise.&lt;void&gt;</code>
222
+ Activate the given installed workflow.
223
+
224
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
225
+ **Properties**
226
+
227
+ | Name | Type | Description |
228
+ | --- | --- | --- |
229
+ | workflowId | <code>string</code> | The ID of the workflow you want to activate. |
230
+
231
+ <a name="Cobalt+toggleWorkflowStatus"></a>
232
+
233
+ ### cobalt.toggleWorkflowStatus() ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
234
+ Toggle the status of the specified workflow.
235
+
236
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
237
+ **Properties**
238
+
239
+ | Name | Type | Description |
240
+ | --- | --- | --- |
241
+ | workflowId | <code>string</code> | The ID of the workflow. |
242
+
243
+ <a name="Cobalt+deleteWorkflow"></a>
244
+
245
+ ### cobalt.deleteWorkflow() ⇒ <code>Promise.&lt;unknown&gt;</code>
246
+ Delete the specified workflow.
247
+
248
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
249
+ **Properties**
250
+
251
+ | Name | Type | Description |
252
+ | --- | --- | --- |
253
+ | workflowId | <code>string</code> | The ID of the workflow. |
254
+
255
+ <a name="Field"></a>
256
+
257
+ ## Field : <code>object</code>
258
+ The Node Field object available for configuration.
259
+
260
+ **Kind**: global typedef
261
+ **Properties**
262
+
263
+ | Name | Type | Description |
264
+ | --- | --- | --- |
265
+ | name | <code>string</code> | The field name. |
266
+ | type | <code>string</code> | The input type of the field. |
267
+ | placeholder | <code>string</code> | The placeholder text for the field. |
268
+ | required | <code>boolean</code> | Whether the field is required. |
269
+
270
+ <a name="Node"></a>
271
+
272
+ ## Node : <code>object</code>
273
+ The Node object available for configuration.
274
+
275
+ **Kind**: global typedef
276
+ **Properties**
277
+
278
+ | Name | Type | Description |
279
+ | --- | --- | --- |
280
+ | node_id | <code>string</code> | The ID of the installed workflow. |
281
+ | node_name | <code>string</code> | The Name of the installed workflow. |
282
+ | fields | [<code>Array.&lt;Field&gt;</code>](#Field) | The applications integrated in the workflow. |
283
+
284
+ <a name="Workflow"></a>
285
+
286
+ ## Workflow : <code>object</code>
287
+ The installed workflow.
288
+
289
+ **Kind**: global typedef
290
+ **Properties**
291
+
292
+ | Name | Type | Description |
293
+ | --- | --- | --- |
294
+ | workflow_id | <code>string</code> | The ID of the installed workflow. |
295
+ | applications | <code>Array.&lt;unknown&gt;</code> | The applications integrated in the workflow. |
296
+ | configure | [<code>Array.&lt;Node&gt;</code>](#Node) | The configuration data for the workflow. |
297
+
298
+ <a name="AppAuthStatus"></a>
299
+
300
+ ## AppAuthStatus : <code>object</code>
301
+ The auth status of the user for an application.
302
+
303
+ **Kind**: global typedef
304
+ **Properties**
305
+
306
+ | Name | Type | Description |
307
+ | --- | --- | --- |
308
+ | status | <code>boolean</code> | Whether the user has authenticated with this application. |
package/cobalt.js CHANGED
@@ -125,6 +125,33 @@ class Cobalt {
125
125
  return data?.auth_url;
126
126
  }
127
127
 
128
+ /**
129
+ * Save the auth data that user provides to authenticate themselves to the
130
+ * specified application.
131
+ * @property {string} application The application type.
132
+ * @property {object} payload The key value pairs of auth data.
133
+ * @returns {Promise<void>}
134
+ */
135
+ async setAppAuthData(application, payload) {
136
+ const res = await fetch(`${this.baseUrl}/api/v1/${application}/save`, {
137
+ method: "POST",
138
+ headers: {
139
+ authorization: `Bearer ${this.token}`,
140
+ "content-type": "application/json",
141
+ },
142
+ body: JSON.stringify({
143
+ ...payload,
144
+ }),
145
+ });
146
+
147
+ if (res.status >= 400 && res.status < 600) {
148
+ throw new Error(res.statusText);
149
+ }
150
+
151
+ const data = await res.json();
152
+ return data;
153
+ }
154
+
128
155
  /**
129
156
  * Unauthorize the specified application and remove any associated data from Cobalt.
130
157
  * @property {string} application The application type.
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)});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 removeAppAuth(application){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}`,{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 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:inputData})});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 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.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)});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 setAppAuthData(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 removeAppAuth(application){const res=await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${application}`,{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 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:inputData})});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 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;
package/docs.md CHANGED
@@ -38,6 +38,7 @@ Cobalt Frontend SDK
38
38
  * [.installTemplate()](#Cobalt+installTemplate) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
39
39
  * [.getAppAuthStatus()](#Cobalt+getAppAuthStatus) ⇒ <code>Promise.&lt;boolean&gt;</code>
40
40
  * [.getAppAuthUrl()](#Cobalt+getAppAuthUrl) ⇒ <code>Promise.&lt;string&gt;</code>
41
+ * [.setAppAuthData()](#Cobalt+setAppAuthData) ⇒ <code>Promise.&lt;void&gt;</code>
41
42
  * [.removeAppAuth()](#Cobalt+removeAppAuth) ⇒ <code>Promise.&lt;void&gt;</code>
42
43
  * [.getNodeConfiguration()](#Cobalt+getNodeConfiguration) ⇒ <code>Promise.&lt;Array.&lt;Field&gt;&gt;</code>
43
44
  * [.saveNode()](#Cobalt+saveNode) ⇒ [<code>Promise.&lt;Workflow&gt;</code>](#Workflow)
@@ -113,6 +114,20 @@ specified application.
113
114
  | --- | --- | --- |
114
115
  | application | <code>string</code> | The application type. |
115
116
 
117
+ <a name="Cobalt+setAppAuthData"></a>
118
+
119
+ ### cobalt.setAppAuthData() ⇒ <code>Promise.&lt;void&gt;</code>
120
+ Save the auth data that user provides to authenticate themselves to the
121
+ specified application.
122
+
123
+ **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
124
+ **Properties**
125
+
126
+ | Name | Type | Description |
127
+ | --- | --- | --- |
128
+ | application | <code>string</code> | The application type. |
129
+ | payload | <code>object</code> | The key value pairs of auth data. |
130
+
116
131
  <a name="Cobalt+removeAppAuth"></a>
117
132
 
118
133
  ### cobalt.removeAppAuth() ⇒ <code>Promise.&lt;void&gt;</code>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {