@cobaltio/cobalt-js 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,45 @@
1
1
  # cobalt.js
2
2
  Cobalt frontend SDK.
3
3
 
4
- # Install
4
+ ## Install
5
+
6
+ #### npm
5
7
  ```bash
8
+ npm install @cobaltio/cobalt-js
6
9
  ```
7
10
 
8
- # Usage
11
+ #### yarn
9
12
  ```bash
13
+ yarn add @cobaltio/cobalt-js
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Include
19
+
20
+ #### Browser
21
+ ```js
22
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@0"></script>
23
+ ```
24
+
25
+ #### Node
26
+ ```js
27
+ // CommonJS
28
+ const Cobalt = require("@cobaltio/cobalt-js");
29
+ // ESM
30
+ import Cobalt from "@cobaltio/cobalt-js";
31
+ ```
32
+
33
+ ### Initialize
34
+ ```js
35
+ // initialize with token
36
+ const cobalt = new Cobalt({
37
+ // the token you generate for linked accounts using the cobalt backend SDK
38
+ token: "COBALT_SESSION_TOKEN",
39
+ });
40
+
41
+ // initialize without token
42
+ const cobalt = new Cobalt();
43
+ // the token you generate for linked accounts using the cobalt backend SDK
44
+ cobalt.token("COBALT_SESSION_TOKEN");
10
45
  ```
package/cobalt.js CHANGED
@@ -5,25 +5,26 @@ class Cobalt {
5
5
  /**
6
6
  * Cobalt Frontend SDK
7
7
  * @param {object} options The options to configure the Cobalt SDK.
8
+ * @param {string} [options.token] The session token.
8
9
  * @param {string} [options.baseUrl=https://api.gocobalt.io] The base URL of your Cobalt API.
9
10
  */
10
11
  constructor(options) {
11
12
  this.apiBaseUrl = options?.baseUrl || "https://api.gocobalt.io";
12
- this.template = {};
13
+ this.token(options?.token);
13
14
  }
14
15
 
15
16
  /**
16
- * @returns {string} The token to install a template.
17
+ * @returns {string} The session token.
17
18
  */
18
19
  get token() {
19
- return this.templateToken;
20
+ return this.sessionToken;
20
21
  };
21
22
 
22
23
  /**
23
- * @returns {string} The token to install a template.
24
+ * @returns {string} The session token.
24
25
  */
25
26
  set token(token) {
26
- return this.templateToken = typeof token === "string" ? token : "";
27
+ return this.sessionToken = typeof token === "string" ? token : "";
27
28
  };
28
29
 
29
30
  /**
@@ -57,25 +58,28 @@ class Cobalt {
57
58
 
58
59
  /**
59
60
  * Install the given template.
61
+ * @property {string} templateId The ID of the template you want to install.
60
62
  * @returns {Promise<Workflow>}
61
63
  */
62
- async installTemplate() {
63
- const res = await fetch(`${this.baseUrl}/api/v1/template/install`, {
64
+ async installTemplate(templateId) {
65
+ const res = await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`, {
64
66
  method: "POST",
65
67
  headers: {
66
68
  authorization: `Bearer ${this.token}`,
67
69
  },
68
70
  });
69
- this.template = await res.json();
70
- return this.template;
71
+ return await res.json();
71
72
  }
72
73
 
73
74
  /**
74
- * Install the given template.
75
+ * Save the input data for the specified node.
76
+ * @property {string} workflowId The ID of the workflow.
77
+ * @property {string} nodeId The ID of the node.
78
+ * @property {object} inputData The input data for the node.
75
79
  * @returns {Promise<Workflow>}
76
80
  */
77
- async saveNode(nodeId, inputData = {}) {
78
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${this.template?.workflow_id}/node/${nodeId}`, {
81
+ async saveNode(workflowId, nodeId, inputData = {}) {
82
+ const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`, {
79
83
  method: "PUT",
80
84
  headers: {
81
85
  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.template={}}get token(){return this.templateToken}set token(token){return this.templateToken=typeof token==="string"?token:""}get baseUrl(){return this.apiBaseUrl}async installTemplate(){const res=await fetch(`${this.baseUrl}/api/v1/template/install`,{method:"POST",headers:{authorization:`Bearer ${this.token}`}});this.template=await res.json();return this.template}async saveNode(nodeId,inputData={}){const res=await fetch(`${this.baseUrl}/api/v2/workflow/${this.template?.workflow_id}/node/${nodeId}`,{method:"PUT",headers:{authorization:`Bearer ${this.token}`},body:JSON.stringify({input_data:inputData})});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){const res=await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`,{method:"POST",headers:{authorization:`Bearer ${this.token}`}});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}`},body:JSON.stringify({input_data:inputData})});return await res.json()}}module.exports=Cobalt;
package/docs/Cobalt.html CHANGED
@@ -133,6 +133,43 @@
133
133
  <tbody>
134
134
 
135
135
 
136
+ <tr>
137
+
138
+ <td class="name"><code>token</code></td>
139
+
140
+
141
+ <td class="type">
142
+
143
+
144
+ <span class="param-type">string</span>
145
+
146
+
147
+
148
+ </td>
149
+
150
+
151
+ <td class="attributes">
152
+
153
+ &lt;optional><br>
154
+
155
+
156
+
157
+
158
+
159
+ </td>
160
+
161
+
162
+
163
+ <td class="default">
164
+
165
+ </td>
166
+
167
+
168
+ <td class="description last">The session token.</td>
169
+ </tr>
170
+
171
+
172
+
136
173
  <tr>
137
174
 
138
175
  <td class="name"><code>baseUrl</code></td>
@@ -305,7 +342,7 @@
305
342
 
306
343
  <dt class="tag-source">Source:</dt>
307
344
  <dd class="tag-source"><ul class="dummy"><li>
308
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line32">line 32</a>
345
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line33">line 33</a>
309
346
  </li></ul></dd>
310
347
 
311
348
 
@@ -363,7 +400,7 @@
363
400
 
364
401
  <dt class="tag-source">Source:</dt>
365
402
  <dd class="tag-source"><ul class="dummy"><li>
366
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line18">line 18</a>
403
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line19">line 19</a>
367
404
  </li></ul></dd>
368
405
 
369
406
 
@@ -421,7 +458,7 @@
421
458
 
422
459
  <dt class="tag-source">Source:</dt>
423
460
  <dd class="tag-source"><ul class="dummy"><li>
424
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line25">line 25</a>
461
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line26">line 26</a>
425
462
  </li></ul></dd>
426
463
 
427
464
 
@@ -472,6 +509,58 @@
472
509
 
473
510
 
474
511
 
512
+ <h5 class="subsection-title">Properties:</h5>
513
+
514
+
515
+
516
+ <table class="props">
517
+ <thead>
518
+ <tr>
519
+
520
+ <th>Name</th>
521
+
522
+
523
+ <th>Type</th>
524
+
525
+
526
+
527
+
528
+
529
+ <th class="last">Description</th>
530
+ </tr>
531
+ </thead>
532
+
533
+ <tbody>
534
+
535
+
536
+ <tr>
537
+
538
+ <td class="name"><code>templateId</code></td>
539
+
540
+
541
+ <td class="type">
542
+
543
+
544
+ <span class="param-type">string</span>
545
+
546
+
547
+
548
+ </td>
549
+
550
+
551
+
552
+
553
+
554
+ <td class="description last">The ID of the template you want to install.</td>
555
+ </tr>
556
+
557
+
558
+ </tbody>
559
+ </table>
560
+
561
+
562
+
563
+
475
564
  <dl class="details">
476
565
 
477
566
 
@@ -501,7 +590,7 @@
501
590
 
502
591
  <dt class="tag-source">Source:</dt>
503
592
  <dd class="tag-source"><ul class="dummy"><li>
504
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line62">line 62</a>
593
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line64">line 64</a>
505
594
  </li></ul></dd>
506
595
 
507
596
 
@@ -563,7 +652,7 @@
563
652
 
564
653
 
565
654
  <div class="description">
566
- Install the given template.
655
+ Save the input data for the specified node.
567
656
  </div>
568
657
 
569
658
 
@@ -578,6 +667,104 @@
578
667
 
579
668
 
580
669
 
670
+ <h5 class="subsection-title">Properties:</h5>
671
+
672
+
673
+
674
+ <table class="props">
675
+ <thead>
676
+ <tr>
677
+
678
+ <th>Name</th>
679
+
680
+
681
+ <th>Type</th>
682
+
683
+
684
+
685
+
686
+
687
+ <th class="last">Description</th>
688
+ </tr>
689
+ </thead>
690
+
691
+ <tbody>
692
+
693
+
694
+ <tr>
695
+
696
+ <td class="name"><code>workflowId</code></td>
697
+
698
+
699
+ <td class="type">
700
+
701
+
702
+ <span class="param-type">string</span>
703
+
704
+
705
+
706
+ </td>
707
+
708
+
709
+
710
+
711
+
712
+ <td class="description last">The ID of the workflow.</td>
713
+ </tr>
714
+
715
+
716
+
717
+ <tr>
718
+
719
+ <td class="name"><code>nodeId</code></td>
720
+
721
+
722
+ <td class="type">
723
+
724
+
725
+ <span class="param-type">string</span>
726
+
727
+
728
+
729
+ </td>
730
+
731
+
732
+
733
+
734
+
735
+ <td class="description last">The ID of the node.</td>
736
+ </tr>
737
+
738
+
739
+
740
+ <tr>
741
+
742
+ <td class="name"><code>inputData</code></td>
743
+
744
+
745
+ <td class="type">
746
+
747
+
748
+ <span class="param-type">object</span>
749
+
750
+
751
+
752
+ </td>
753
+
754
+
755
+
756
+
757
+
758
+ <td class="description last">The input data for the node.</td>
759
+ </tr>
760
+
761
+
762
+ </tbody>
763
+ </table>
764
+
765
+
766
+
767
+
581
768
  <dl class="details">
582
769
 
583
770
 
@@ -607,7 +794,7 @@
607
794
 
608
795
  <dt class="tag-source">Source:</dt>
609
796
  <dd class="tag-source"><ul class="dummy"><li>
610
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line77">line 77</a>
797
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line81">line 81</a>
611
798
  </li></ul></dd>
612
799
 
613
800
 
@@ -677,7 +864,7 @@
677
864
  <br class="clear">
678
865
 
679
866
  <footer>
680
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Sep 05 2022 15:43:26 GMT+0530 (India Standard Time)
867
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Wed Sep 07 2022 12:11:23 GMT+0530 (India Standard Time)
681
868
  </footer>
682
869
 
683
870
  <script> prettyPrint(); </script>
@@ -33,25 +33,26 @@ class Cobalt {
33
33
  /**
34
34
  * Cobalt Frontend SDK
35
35
  * @param {object} options The options to configure the Cobalt SDK.
36
+ * @param {string} [options.token] The session token.
36
37
  * @param {string} [options.baseUrl=https://api.gocobalt.io] The base URL of your Cobalt API.
37
38
  */
38
39
  constructor(options) {
39
40
  this.apiBaseUrl = options?.baseUrl || "https://api.gocobalt.io";
40
- this.template = {};
41
+ this.token(options?.token);
41
42
  }
42
43
 
43
44
  /**
44
- * @returns {string} The token to install a template.
45
+ * @returns {string} The session token.
45
46
  */
46
47
  get token() {
47
- return this.templateToken;
48
+ return this.sessionToken;
48
49
  };
49
50
 
50
51
  /**
51
- * @returns {string} The token to install a template.
52
+ * @returns {string} The session token.
52
53
  */
53
54
  set token(token) {
54
- return this.templateToken = typeof token === "string" ? token : "";
55
+ return this.sessionToken = typeof token === "string" ? token : "";
55
56
  };
56
57
 
57
58
  /**
@@ -85,25 +86,28 @@ class Cobalt {
85
86
 
86
87
  /**
87
88
  * Install the given template.
89
+ * @property {string} templateId The ID of the template you want to install.
88
90
  * @returns {Promise&lt;Workflow>}
89
91
  */
90
- async installTemplate() {
91
- const res = await fetch(`${this.baseUrl}/api/v1/template/install`, {
92
+ async installTemplate(templateId) {
93
+ const res = await fetch(`${this.baseUrl}/api/v1/template/install/${templateId}`, {
92
94
  method: "POST",
93
95
  headers: {
94
96
  authorization: `Bearer ${this.token}`,
95
97
  },
96
98
  });
97
- this.template = await res.json();
98
- return this.template;
99
+ return await res.json();
99
100
  }
100
101
 
101
102
  /**
102
- * Install the given template.
103
+ * Save the input data for the specified node.
104
+ * @property {string} workflowId The ID of the workflow.
105
+ * @property {string} nodeId The ID of the node.
106
+ * @property {object} inputData The input data for the node.
103
107
  * @returns {Promise&lt;Workflow>}
104
108
  */
105
- async saveNode(nodeId, inputData = {}) {
106
- const res = await fetch(`${this.baseUrl}/api/v2/workflow/${this.template?.workflow_id}/node/${nodeId}`, {
109
+ async saveNode(workflowId, nodeId, inputData = {}) {
110
+ const res = await fetch(`${this.baseUrl}/api/v2/workflow/${workflowId}/node/${nodeId}`, {
107
111
  method: "PUT",
108
112
  headers: {
109
113
  authorization: `Bearer ${this.token}`,
@@ -116,7 +120,7 @@ class Cobalt {
116
120
  }
117
121
  }
118
122
 
119
- export default Cobalt;
123
+ module.exports = Cobalt;
120
124
  </code></pre>
121
125
  </article>
122
126
  </section>
@@ -133,7 +137,7 @@ export default Cobalt;
133
137
  <br class="clear">
134
138
 
135
139
  <footer>
136
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Sep 05 2022 15:43:26 GMT+0530 (India Standard Time)
140
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Wed Sep 07 2022 12:11:23 GMT+0530 (India Standard Time)
137
141
  </footer>
138
142
 
139
143
  <script> prettyPrint(); </script>
package/docs/global.html CHANGED
@@ -277,7 +277,7 @@
277
277
 
278
278
  <dt class="tag-source">Source:</dt>
279
279
  <dd class="tag-source"><ul class="dummy"><li>
280
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line36">line 36</a>
280
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line37">line 37</a>
281
281
  </li></ul></dd>
282
282
 
283
283
 
@@ -447,7 +447,7 @@
447
447
 
448
448
  <dt class="tag-source">Source:</dt>
449
449
  <dd class="tag-source"><ul class="dummy"><li>
450
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line44">line 44</a>
450
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line45">line 45</a>
451
451
  </li></ul></dd>
452
452
 
453
453
 
@@ -617,7 +617,7 @@
617
617
 
618
618
  <dt class="tag-source">Source:</dt>
619
619
  <dd class="tag-source"><ul class="dummy"><li>
620
- <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line51">line 51</a>
620
+ <a href="cobalt.js.html">cobalt.js</a>, <a href="cobalt.js.html#line52">line 52</a>
621
621
  </li></ul></dd>
622
622
 
623
623
 
@@ -653,7 +653,7 @@
653
653
  <br class="clear">
654
654
 
655
655
  <footer>
656
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Sep 05 2022 15:43:26 GMT+0530 (India Standard Time)
656
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Wed Sep 07 2022 12:11:23 GMT+0530 (India Standard Time)
657
657
  </footer>
658
658
 
659
659
  <script> prettyPrint(); </script>
package/docs/index.html CHANGED
@@ -45,10 +45,36 @@
45
45
  <section>
46
46
  <article><h1>cobalt.js</h1>
47
47
  <p>Cobalt frontend SDK.</p>
48
- <h1>Install</h1>
49
- <pre class="prettyprint source lang-bash"><code></code></pre>
50
- <h1>Usage</h1>
51
- <pre class="prettyprint source lang-bash"><code></code></pre></article>
48
+ <h2>Install</h2>
49
+ <h4>npm</h4>
50
+ <pre class="prettyprint source lang-bash"><code>npm install @cobaltio/cobalt-js
51
+ </code></pre>
52
+ <h4>yarn</h4>
53
+ <pre class="prettyprint source lang-bash"><code>yarn add @cobaltio/cobalt-js
54
+ </code></pre>
55
+ <h2>Usage</h2>
56
+ <h3>Include</h3>
57
+ <h4>Browser</h4>
58
+ <pre class="prettyprint source lang-js"><code>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@0&quot;>&lt;/script>
59
+ </code></pre>
60
+ <h4>Node</h4>
61
+ <pre class="prettyprint source lang-js"><code>// CommonJS
62
+ const Cobalt = require(&quot;@cobaltio/cobalt-js&quot;);
63
+ // ESM
64
+ import Cobalt from &quot;@cobaltio/cobalt-js&quot;;
65
+ </code></pre>
66
+ <h3>Initialize</h3>
67
+ <pre class="prettyprint source lang-js"><code>// initialize with token
68
+ const cobalt = new Cobalt({
69
+ // the token you generate for linked accounts using the cobalt backend SDK
70
+ token: &quot;COBALT_SESSION_TOKEN&quot;,
71
+ });
72
+
73
+ // initialize without token
74
+ const cobalt = new Cobalt();
75
+ // the token you generate for linked accounts using the cobalt backend SDK
76
+ cobalt.token(&quot;COBALT_SESSION_TOKEN&quot;);
77
+ </code></pre></article>
52
78
  </section>
53
79
 
54
80
 
@@ -65,7 +91,7 @@
65
91
  <br class="clear">
66
92
 
67
93
  <footer>
68
- Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Mon Sep 05 2022 15:43:26 GMT+0530 (India Standard Time)
94
+ Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Wed Sep 07 2022 12:11:23 GMT+0530 (India Standard Time)
69
95
  </footer>
70
96
 
71
97
  <script> prettyPrint(); </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "scripts": {