@cobaltio/cobalt-js 7.0.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,10 +22,10 @@ yarn add @cobaltio/cobalt-js
22
22
  #### Browser
23
23
  ```html
24
24
  <!-- use a specific version -->
25
- <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@7.0.0"></script>
25
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@8.0.0"></script>
26
26
  <!-- use a version range instead of a specific version -->
27
- <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@7"></script>
28
- <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@7.0"></script>
27
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@8"></script>
28
+ <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@8.0"></script>
29
29
  <!-- omit the version completely to use the latest one -->
30
30
  <!-- you should NOT use this in production -->
31
31
  <script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js"></script>
@@ -33,10 +33,7 @@ yarn add @cobaltio/cobalt-js
33
33
 
34
34
  #### Node
35
35
  ```js
36
- // CommonJS
37
- const Cobalt = require("@cobaltio/cobalt-js");
38
- // ESM
39
- import Cobalt from "@cobaltio/cobalt-js";
36
+ import { Cobalt } from "@cobaltio/cobalt-js";
40
37
  ```
41
38
 
42
39
  ### Initialize
@@ -47,247 +44,12 @@ const cobalt = new Cobalt({
47
44
  token: "COBALT_SESSION_TOKEN",
48
45
  });
49
46
 
50
- // initialize without token
47
+ // Or, initialize without token
51
48
  const cobalt = new Cobalt();
52
- // the token you generate for linked accounts using the cobalt backend SDK
49
+ // and you can set the token later.
53
50
  cobalt.token = "COBALT_SESSION_TOKEN";
54
51
  ```
55
52
 
56
- ### SDK
53
+ # Documentation
57
54
 
58
- ## Classes
59
-
60
- <dl>
61
- <dt><a href="#Cobalt">Cobalt</a></dt>
62
- <dd></dd>
63
- </dl>
64
-
65
- ## Typedefs
66
-
67
- <dl>
68
- <dt><a href="#Application">Application</a> : <code>Object</code></dt>
69
- <dd><p>An application in Cobalt.</p>
70
- </dd>
71
- <dt><a href="#InputField">InputField</a> : <code>Object</code></dt>
72
- <dd><p>An Input field to take input from the user.</p>
73
- </dd>
74
- <dt><a href="#ConfigPayload">ConfigPayload</a> : <code>Object</code></dt>
75
- <dd><p>The payload object for config.</p>
76
- </dd>
77
- <dt><a href="#Label">Label</a> : <code>Object</code></dt>
78
- <dd><p>Label Mapping</p>
79
- </dd>
80
- <dt><a href="#UpdateConfigPayload">UpdateConfigPayload</a> : <code>Object</code></dt>
81
- <dd><p>The configuration data for an application.</p>
82
- </dd>
83
- <dt><a href="#WorkflowPayload">WorkflowPayload</a> : <code>Object</code></dt>
84
- <dd><p>The workflow.</p>
85
- </dd>
86
- </dl>
87
-
88
- <a name="Cobalt"></a>
89
-
90
- ## Cobalt
91
- **Kind**: global class
92
-
93
- * [Cobalt](#Cobalt)
94
- * [new Cobalt(options)](#new_Cobalt_new)
95
- * [.getApp([slug])](#Cobalt+getApp) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
96
- * [.connect(slug, [payload])](#Cobalt+connect) ⇒ <code>Promise.&lt;Boolean&gt;</code>
97
- * [.disconnect(slug)](#Cobalt+disconnect) ⇒ <code>Promise.&lt;void&gt;</code>
98
- * [.config(payload)](#Cobalt+config) ⇒ <code>Promise.&lt;Config&gt;</code>
99
- * [.updateConfig(payload)](#Cobalt+updateConfig) ⇒ <code>Promise.&lt;Config&gt;</code>
100
- * [.deleteConfig(slug, [configId])](#Cobalt+deleteConfig) ⇒ <code>Promise.&lt;unknown&gt;</code>
101
- * Additional Methods
102
- * [.getConfig(slug, [configId])](#Cobalt+getConfig) ⇒ <code>Promise.&lt;Config&gt;</code>
103
-
104
- <a name="new_Cobalt_new"></a>
105
-
106
- ### new Cobalt(options)
107
- Cobalt Frontend SDK
108
-
109
-
110
- | Param | Type | Default | Description |
111
- | --- | --- | --- | --- |
112
- | options | <code>Object</code> | | The options to configure the Cobalt SDK. |
113
- | [options.token] | <code>String</code> | | The session token. |
114
- | [options.baseUrl] | <code>String</code> | <code>https://api.gocobalt.io</code> | The base URL of the Cobalt API. |
115
-
116
- <a name="Cobalt+getApp"></a>
117
-
118
- ### cobalt.getApp([slug]) ⇒ [<code>Promise.&lt;Application&gt;</code>](#Application)
119
- Returns the application details for the specified application, provided
120
- the application is enabled in Cobalt. If no application is specified,
121
- it returns all the enabled applications.
122
-
123
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
124
- **Returns**: [<code>Promise.&lt;Application&gt;</code>](#Application) - The application details.
125
-
126
- | Param | Type | Description |
127
- | --- | --- | --- |
128
- | [slug] | <code>String</code> | The application slug. |
129
-
130
- <a name="Cobalt+connect"></a>
131
-
132
- ### cobalt.connect(slug, [payload]) ⇒ <code>Promise.&lt;Boolean&gt;</code>
133
- Connect the specified application, optionally with the auth data that user provides.
134
-
135
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
136
- **Returns**: <code>Promise.&lt;Boolean&gt;</code> - Whether the connection was successful.
137
-
138
- | Param | Type | Default | Description |
139
- | --- | --- | --- | --- |
140
- | slug | <code>String</code> | | The application slug. |
141
- | [payload] | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | <code>{}</code> | The key value pairs of auth data. |
142
-
143
- <a name="Cobalt+disconnect"></a>
144
-
145
- ### cobalt.disconnect(slug) ⇒ <code>Promise.&lt;void&gt;</code>
146
- Disconnect the specified application and remove any associated data from Cobalt.
147
-
148
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
149
-
150
- | Param | Type | Description |
151
- | --- | --- | --- |
152
- | slug | <code>String</code> | The application slug. |
153
-
154
- <a name="Cobalt+config"></a>
155
-
156
- ### cobalt.config(payload) ⇒ <code>Promise.&lt;Config&gt;</code>
157
- Returns the specified config, or creates one if it doesn't exist.
158
-
159
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
160
- **Returns**: <code>Promise.&lt;Config&gt;</code> - The specified config.
161
-
162
- | Param | Type | Description |
163
- | --- | --- | --- |
164
- | payload | [<code>ConfigPayload</code>](#ConfigPayload) | The payload object for config. |
165
-
166
- <a name="Cobalt+getConfig"></a>
167
-
168
- ### cobalt.getConfig(slug, [configId]) ⇒ <code>Promise.&lt;Config&gt;</code>
169
- Returns the specified config.
170
-
171
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
172
- **Returns**: <code>Promise.&lt;Config&gt;</code> - The specified config.
173
-
174
- | Param | Type | Description |
175
- | --- | --- | --- |
176
- | slug | <code>String</code> | The application slug. |
177
- | [configId] | <code>String</code> | The unique ID of the config. |
178
-
179
- <a name="Cobalt+updateConfig"></a>
180
-
181
- ### cobalt.updateConfig(payload) ⇒ <code>Promise.&lt;Config&gt;</code>
182
- Update the specified config.
183
-
184
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
185
- **Returns**: <code>Promise.&lt;Config&gt;</code> - The specified config.
186
-
187
- | Param | Type | Description |
188
- | --- | --- | --- |
189
- | payload | [<code>UpdateConfigPayload</code>](#UpdateConfigPayload) | The update payload. |
190
-
191
- <a name="Cobalt+deleteConfig"></a>
192
-
193
- ### cobalt.deleteConfig(slug, [configId]) ⇒ <code>Promise.&lt;unknown&gt;</code>
194
- Delete the specified config.
195
-
196
- **Kind**: instance method of [<code>Cobalt</code>](#Cobalt)
197
-
198
- | Param | Type | Description |
199
- | --- | --- | --- |
200
- | slug | <code>String</code> | The application slug. |
201
- | [configId] | <code>String</code> | The unique ID of the config. |
202
-
203
- <a name="Application"></a>
204
-
205
- ## Application : <code>Object</code>
206
- An application in Cobalt.
207
-
208
- **Kind**: global typedef
209
- **Properties**
210
-
211
- | Name | Type | Description |
212
- | --- | --- | --- |
213
- | name | <code>String</code> | The application name. |
214
- | description | <code>String</code> | The application description. |
215
- | icon | <code>String</code> | The application icon. |
216
- | type | <code>String</code> | The application slug for native apps. |
217
- | [slug] | <code>String</code> | The application slug for custom apps. |
218
- | auth_type | <code>&quot;oauth2&quot;</code> \| <code>&quot;keybased&quot;</code> | The type of auth used by application. |
219
- | [connected] | <code>Boolean</code> | Whether the user has connected the application. |
220
- | [reauth_required] | <code>Boolean</code> | Whether the connection has expired and re-auth is required. |
221
- | [auth_input_map] | [<code>Array.&lt;InputField&gt;</code>](#InputField) | The fields required from the user to connect the application (for `keybased` auth type). |
222
-
223
- <a name="InputField"></a>
224
-
225
- ## InputField : <code>Object</code>
226
- An Input field to take input from the user.
227
-
228
- **Kind**: global typedef
229
- **Properties**
230
-
231
- | Name | Type | Description |
232
- | --- | --- | --- |
233
- | name | <code>String</code> | Key name of the field. |
234
- | type | <code>String</code> | Input type of the field. |
235
- | required | <code>String</code> | Whether the field is required. |
236
- | placeholder | <code>String</code> | The placeholder of the field. |
237
- | label | <code>String</code> | The label of the field. |
238
-
239
- <a name="ConfigPayload"></a>
240
-
241
- ## ConfigPayload : <code>Object</code>
242
- The payload object for config.
243
-
244
- **Kind**: global typedef
245
- **Properties**
246
-
247
- | Name | Type | Description |
248
- | --- | --- | --- |
249
- | slug | <code>String</code> | The application slug. |
250
- | [config_id] | <code>String</code> | Unique ID for the config. |
251
- | labels | <code>Object.&lt;string, Array.&lt;Label&gt;&gt;</code> | The dynamic label mappings. |
252
-
253
- <a name="Label"></a>
254
-
255
- ## Label : <code>Object</code>
256
- Label Mapping
257
-
258
- **Kind**: global typedef
259
- **Properties**
260
-
261
- | Name | Type | Description |
262
- | --- | --- | --- |
263
- | name | <code>string</code> | The label name. |
264
- | value | <code>string</code> \| <code>number</code> \| <code>boolean</code> | The label value. |
265
-
266
- <a name="UpdateConfigPayload"></a>
267
-
268
- ## UpdateConfigPayload : <code>Object</code>
269
- The configuration data for an application.
270
-
271
- **Kind**: global typedef
272
- **Properties**
273
-
274
- | Name | Type | Description |
275
- | --- | --- | --- |
276
- | slug | <code>String</code> | The application slug. |
277
- | [config_id] | <code>String</code> | Unique ID for the config. |
278
- | fields | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of application fields and their values. |
279
- | workflows | [<code>Array.&lt;WorkflowPayload&gt;</code>](#WorkflowPayload) | Whether the workflow is enabled. |
280
-
281
- <a name="WorkflowPayload"></a>
282
-
283
- ## WorkflowPayload : <code>Object</code>
284
- The workflow.
285
-
286
- **Kind**: global typedef
287
- **Properties**
288
-
289
- | Name | Type | Description |
290
- | --- | --- | --- |
291
- | id | <code>String</code> | The ID of the workflow. |
292
- | enabled | <code>Boolean</code> | Whether the workflow is enabled. |
293
- | fields | <code>Object.&lt;string, (string\|number\|boolean)&gt;</code> | A map of workflow fields and their values. |
55
+ Read the [SDK documentation here](https://gocobalt.github.io/cobalt-js).
package/cobalt.d.ts ADDED
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Cobalt Frontend SDK
3
+ */
4
+ /** An application in Cobalt. */
5
+ export interface Application {
6
+ /**The application name. */
7
+ name: string;
8
+ /**The application description. */
9
+ description: string;
10
+ /**The application icon. */
11
+ icon: string;
12
+ /**The application slug for native apps. */
13
+ type: string;
14
+ /** The application slug for custom apps. */
15
+ slug?: string;
16
+ /**The type of auth used by application. */
17
+ auth_type: "oauth2" | "keybased";
18
+ /** Whether the user has connected the application. */
19
+ connected?: boolean;
20
+ /** Whether the connection has expired and re-auth is required. */
21
+ reauth_required?: boolean;
22
+ /** The fields required from the user to connect the application (for `keybased` auth type). */
23
+ auth_input_map?: InputField[];
24
+ }
25
+ /** An Input field to take input from the user. */
26
+ export interface InputField {
27
+ /** Key name of the field. */
28
+ name: string;
29
+ /** Input type of the field. */
30
+ type: string;
31
+ /** Whether the field is required. */
32
+ required: string;
33
+ /** The placeholder of the field. */
34
+ placeholder: string;
35
+ /** The label of the field. */
36
+ label: string;
37
+ }
38
+ /** The payload object for config. */
39
+ export interface ConfigPayload {
40
+ /** The application slug. */
41
+ slug: string;
42
+ /** Unique ID for the config. */
43
+ config_id?: string;
44
+ /** The dynamic label mappings. */
45
+ labels: Label[];
46
+ }
47
+ /** Label Mapping */
48
+ export interface Label {
49
+ /** The label name. */
50
+ name: string;
51
+ /** The label value. */
52
+ value: string | number | boolean;
53
+ }
54
+ /** The configuration data for an application. */
55
+ export interface UpdateConfigPayload {
56
+ /** The application slug */
57
+ slug: string;
58
+ /** Unique ID for the config. */
59
+ config_id?: string;
60
+ /** A map of application fields and their values. */
61
+ fields: Record<string, string | number | boolean>;
62
+ /** The config workflows data. */
63
+ workflows: WorkflowPayload[];
64
+ }
65
+ /** The workflow. */
66
+ export interface WorkflowPayload {
67
+ /** The ID of the workflow. */
68
+ id: string;
69
+ /** Whether the workflow is enabled. */
70
+ enabled: boolean;
71
+ /** A map of workflow field names and their values. */
72
+ fields: Record<string, string | number | boolean>;
73
+ }
74
+ export interface CobaltOptions {
75
+ /** The base URL of the Cobalt API. You don't need to set this. */
76
+ baseUrl?: string;
77
+ /** The session token. */
78
+ token?: string;
79
+ }
80
+ type Config = any;
81
+ declare class Cobalt {
82
+ private baseUrl;
83
+ token: string;
84
+ /**
85
+ * Cobalt Frontend SDK
86
+ * @param {Object} options The options to configure the Cobalt SDK.
87
+ * @param {String} [options.token] The session token.
88
+ * @param {String} [options.baseUrl=https://api.gocobalt.io] The base URL of the Cobalt API.
89
+ */
90
+ constructor(options?: CobaltOptions);
91
+ /**
92
+ * Returns the org & customer details for the associated token.
93
+ * @private
94
+ * @returns {Promise<unknown>}
95
+ */
96
+ getAccountDetails(): Promise<unknown>;
97
+ /**
98
+ * Returns the application details for the specified application, provided
99
+ * the application is enabled in Cobalt. If no application is specified,
100
+ * it returns all the enabled applications.
101
+ * @param {String} [slug] The application slug.
102
+ * @returns {Promise<Application>} The application details.
103
+ */
104
+ getApp(slug?: string): Promise<Application>;
105
+ /**
106
+ * Returns the auth URL that users can use to authenticate themselves to the
107
+ * specified application.
108
+ * @private
109
+ * @param {String} slug The application slug.
110
+ * @param {Object.<string, string>} [params] The key value pairs of auth data.
111
+ * @returns {Promise<String>} The auth URL where users can authenticate themselves.
112
+ */
113
+ private getOAuthUrl;
114
+ /**
115
+ * Handle OAuth for the specified native application.
116
+ * @private
117
+ * @param {String} slug The application slug.
118
+ * @param {Object.<string, string>} [params] The key value pairs of auth data.
119
+ * @returns {Promise<Boolean>} Whether the user authenticated.
120
+ */
121
+ private oauth;
122
+ /**
123
+ * Connect the specified application, optionally with the auth data that user provides.
124
+ * @param {String} slug The application slug.
125
+ * @param {Object.<string, string>} [payload] The key value pairs of auth data.
126
+ * @returns {Promise<Boolean>} Whether the connection was successful.
127
+ */
128
+ connect(slug: string, payload?: Record<string, string>): Promise<boolean>;
129
+ /**
130
+ * Disconnect the specified application and remove any associated data from Cobalt.
131
+ * @param {String} slug The application slug.
132
+ * @returns {Promise<void>}
133
+ */
134
+ disconnect(slug: string): Promise<void>;
135
+ /**
136
+ * Returns the specified config, or creates one if it doesn't exist.
137
+ * @param {ConfigPayload} payload The payload object for config.
138
+ * @returns {Promise<Config>} The specified config.
139
+ */
140
+ config(payload: ConfigPayload): Promise<Config>;
141
+ /**
142
+ * Returns the specified config.
143
+ * @param {String} slug The application slug.
144
+ * @param {String} [configId] The unique ID of the config.
145
+ * @returns {Promise<Config>} The specified config.
146
+ */
147
+ getConfig(slug: string, configId: string): Promise<Config>;
148
+ /**
149
+ * Update the specified config.
150
+ * @param {UpdateConfigPayload} payload The update payload.
151
+ * @returns {Promise<Config>} The specified config.
152
+ */
153
+ updateConfig(payload: UpdateConfigPayload): Promise<Config>;
154
+ /**
155
+ * Delete the specified config.
156
+ * @param {String} slug The application slug.
157
+ * @param {String} [configId] The unique ID of the config.
158
+ * @returns {Promise<unknown>}
159
+ */
160
+ deleteConfig(slug: string, configId: string): Promise<unknown>;
161
+ }
162
+ export { Cobalt };