@cobaltio/cobalt-js 8.9.2-beta.1 → 9.0.0-beta.1

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 (4) hide show
  1. package/cobalt.d.ts +24 -4
  2. package/cobalt.js +39 -34
  3. package/cobalt.ts +58 -41
  4. package/package.json +1 -1
package/cobalt.d.ts CHANGED
@@ -283,6 +283,18 @@ export interface Execution {
283
283
  associated_event_id: string;
284
284
  custom_trigger_id?: string;
285
285
  custom_application_id?: string;
286
+ completion_percentage?: number;
287
+ nodes?: {
288
+ node_id: string;
289
+ node_name: string;
290
+ node_type: string;
291
+ node_status: "Success" | "Ready" | "Errored" | "Waiting" | "Stopped" | "Rejected" | "Errored_and_Skipped" | "Timed_Out";
292
+ is_batch?: boolean;
293
+ attempts_made: number;
294
+ maximum_attempts: number;
295
+ input_data: unknown;
296
+ latest_output: unknown;
297
+ }[];
286
298
  createdAt: string;
287
299
  }
288
300
  declare class Cobalt {
@@ -334,26 +346,34 @@ declare class Cobalt {
334
346
  */
335
347
  private getOAuthUrl;
336
348
  /**
337
- * Handle OAuth for the specified native application.
349
+ * Handle OAuth for the specified application.
338
350
  * @private
339
351
  * @param {String} slug The application slug.
340
352
  * @param {Object.<string, string>} [params] The key value pairs of auth data.
341
353
  * @returns {Promise<Boolean>} Whether the user authenticated.
342
354
  */
343
355
  private oauth;
356
+ /**
357
+ * Save auth data for the specified keybased application.
358
+ * @param {String} slug The application slug.
359
+ * @param {Object.<string, string>} [payload] The key value pairs of auth data.
360
+ * @returns {Promise<Boolean>} Whether the auth data was saved successfully.
361
+ */
362
+ private keybased;
344
363
  /**
345
364
  * Connect the specified application, optionally with the auth data that user provides.
346
365
  * @param {String} slug The application slug.
366
+ * @param {AuthType} authType The auth type to use.
347
367
  * @param {Object.<string, string>} [payload] The key value pairs of auth data.
348
368
  * @returns {Promise<Boolean>} Whether the connection was successful.
349
369
  */
350
- connect(slug: string, payload?: Record<string, string>): Promise<boolean>;
370
+ connect(slug: string, authType: AuthType, payload?: Record<string, string>): Promise<boolean>;
351
371
  /**
352
372
  * Disconnect the specified application and remove any associated data from Cobalt.
353
373
  * @param {String} slug The application slug.
354
- * @returns {Promise<void>}
374
+ * @returns {Promise<unknown>}
355
375
  */
356
- disconnect(slug: string): Promise<void>;
376
+ disconnect(slug: string): Promise<unknown>;
357
377
  /**
358
378
  * Returns the specified config, or creates one if it doesn't exist.
359
379
  * @param {ConfigPayload} payload The payload object for config.
package/cobalt.js CHANGED
@@ -146,7 +146,7 @@ class Cobalt {
146
146
  });
147
147
  }
148
148
  /**
149
- * Handle OAuth for the specified native application.
149
+ * Handle OAuth for the specified application.
150
150
  * @private
151
151
  * @param {String} slug The application slug.
152
152
  * @param {Object.<string, string>} [params] The key value pairs of auth data.
@@ -162,7 +162,8 @@ class Cobalt {
162
162
  const interval = setInterval(() => {
163
163
  this.getApp(slug)
164
164
  .then(app => {
165
- if (app && app.connected === true && !app.reauth_required) {
165
+ var _a;
166
+ if (app && ((_a = app.connected_accounts) === null || _a === void 0 ? void 0 : _a.filter(a => a.auth_type === AuthType.OAuth2).some(a => a.status === AuthStatus.Active))) {
166
167
  // close auth window
167
168
  connectWindow && connectWindow.close();
168
169
  // clear interval
@@ -192,50 +193,53 @@ class Cobalt {
192
193
  });
193
194
  });
194
195
  }
196
+ /**
197
+ * Save auth data for the specified keybased application.
198
+ * @param {String} slug The application slug.
199
+ * @param {Object.<string, string>} [payload] The key value pairs of auth data.
200
+ * @returns {Promise<Boolean>} Whether the auth data was saved successfully.
201
+ */
202
+ keybased(slug, payload) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ const res = yield fetch(`${this.baseUrl}/api/v2/app/${slug}/save`, {
205
+ method: "POST",
206
+ headers: {
207
+ authorization: `Bearer ${this.token}`,
208
+ "content-type": "application/json",
209
+ },
210
+ body: JSON.stringify(Object.assign({}, payload)),
211
+ });
212
+ if (res.status >= 400 && res.status < 600) {
213
+ const error = yield res.json();
214
+ throw error;
215
+ }
216
+ const data = yield res.json();
217
+ return data.success;
218
+ });
219
+ }
195
220
  /**
196
221
  * Connect the specified application, optionally with the auth data that user provides.
197
222
  * @param {String} slug The application slug.
223
+ * @param {AuthType} authType The auth type to use.
198
224
  * @param {Object.<string, string>} [payload] The key value pairs of auth data.
199
225
  * @returns {Promise<Boolean>} Whether the connection was successful.
200
226
  */
201
- connect(slug, payload) {
227
+ connect(slug, authType, payload) {
202
228
  return __awaiter(this, void 0, void 0, function* () {
203
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
204
- try {
205
- const app = yield this.getApp(slug);
206
- // oauth
207
- if (app && app.auth_type === AuthType.OAuth2) {
208
- const connected = yield this.oauth(slug, payload);
209
- resolve(connected);
210
- // key based
211
- }
212
- else {
213
- const res = yield fetch(`${this.baseUrl}/api/v2/app/${slug}/save`, {
214
- method: "POST",
215
- headers: {
216
- authorization: `Bearer ${this.token}`,
217
- "content-type": "application/json",
218
- },
219
- body: JSON.stringify(Object.assign({}, payload)),
220
- });
221
- if (res.status >= 400 && res.status < 600) {
222
- const error = yield res.json();
223
- reject(error);
224
- }
225
- const data = yield res.json();
226
- resolve(data.success);
227
- }
228
- }
229
- catch (error) {
230
- reject(error);
231
- }
232
- }));
229
+ switch (authType) {
230
+ case AuthType.OAuth2:
231
+ return this.oauth(slug, payload);
232
+ case AuthType.KeyBased:
233
+ return this.keybased(slug, payload);
234
+ default:
235
+ throw new Error(`Invalid auth type: ${authType}`);
236
+ }
233
237
  });
234
238
  }
235
239
  /**
236
240
  * Disconnect the specified application and remove any associated data from Cobalt.
237
241
  * @param {String} slug The application slug.
238
- * @returns {Promise<void>}
242
+ * @returns {Promise<unknown>}
239
243
  */
240
244
  disconnect(slug) {
241
245
  return __awaiter(this, void 0, void 0, function* () {
@@ -249,6 +253,7 @@ class Cobalt {
249
253
  const error = yield res.json();
250
254
  throw error;
251
255
  }
256
+ return yield res.json();
252
257
  });
253
258
  }
254
259
  /**
package/cobalt.ts CHANGED
@@ -282,12 +282,12 @@ export interface Execution {
282
282
  _id: string;
283
283
  name: string;
284
284
  icon?: string;
285
- },
286
- status: "COMPLETED" | "RUNNING" | "ERRORED" | "STOPPED" | "STOPPING" | "TIMED_OUT",
285
+ };
286
+ status: "COMPLETED" | "RUNNING" | "ERRORED" | "STOPPED" | "STOPPING" | "TIMED_OUT";
287
287
  associated_workflow: {
288
288
  _id: string;
289
289
  name: string;
290
- },
290
+ };
291
291
  associated_trigger_application: {
292
292
  _id: string;
293
293
  name: string;
@@ -297,7 +297,7 @@ export interface Execution {
297
297
  _id: string;
298
298
  name: string;
299
299
  }
300
- },
300
+ };
301
301
  trigger_application_event?: string;
302
302
  linked_account_id: string;
303
303
  environment: "test" | "production";
@@ -305,6 +305,18 @@ export interface Execution {
305
305
  associated_event_id: string;
306
306
  custom_trigger_id?: string;
307
307
  custom_application_id?: string;
308
+ completion_percentage?: number;
309
+ nodes?: {
310
+ node_id: string;
311
+ node_name: string;
312
+ node_type: string;
313
+ node_status: "Success" | "Ready" | "Errored" | "Waiting" | "Stopped" | "Rejected"| "Errored_and_Skipped" | "Timed_Out";
314
+ is_batch?: boolean;
315
+ attempts_made: number;
316
+ maximum_attempts: number;
317
+ input_data: unknown;
318
+ latest_output: unknown;
319
+ }[];
308
320
  createdAt: string;
309
321
  }
310
322
 
@@ -456,7 +468,7 @@ class Cobalt {
456
468
  }
457
469
 
458
470
  /**
459
- * Handle OAuth for the specified native application.
471
+ * Handle OAuth for the specified application.
460
472
  * @private
461
473
  * @param {String} slug The application slug.
462
474
  * @param {Object.<string, string>} [params] The key value pairs of auth data.
@@ -501,54 +513,57 @@ class Cobalt {
501
513
  });
502
514
  }
503
515
 
516
+ /**
517
+ * Save auth data for the specified keybased application.
518
+ * @param {String} slug The application slug.
519
+ * @param {Object.<string, string>} [payload] The key value pairs of auth data.
520
+ * @returns {Promise<Boolean>} Whether the auth data was saved successfully.
521
+ */
522
+ private async keybased(slug: string, payload?: Record<string, string>): Promise<boolean> {
523
+ const res = await fetch(`${this.baseUrl}/api/v2/app/${slug}/save`, {
524
+ method: "POST",
525
+ headers: {
526
+ authorization: `Bearer ${this.token}`,
527
+ "content-type": "application/json",
528
+ },
529
+ body: JSON.stringify({
530
+ ...payload,
531
+ }),
532
+ });
533
+
534
+ if (res.status >= 400 && res.status < 600) {
535
+ const error = await res.json();
536
+ throw error;
537
+ }
538
+
539
+ const data = await res.json();
540
+ return data.success;
541
+ }
542
+
504
543
  /**
505
544
  * Connect the specified application, optionally with the auth data that user provides.
506
545
  * @param {String} slug The application slug.
546
+ * @param {AuthType} authType The auth type to use.
507
547
  * @param {Object.<string, string>} [payload] The key value pairs of auth data.
508
548
  * @returns {Promise<Boolean>} Whether the connection was successful.
509
549
  */
510
- public async connect(slug: string, payload?: Record<string, string>): Promise<boolean> {
511
- return new Promise(async (resolve, reject) => {
512
- try {
513
- const app = await this.getApp(slug);
514
-
515
- // oauth
516
- if (app && app.auth_type === AuthType.OAuth2) {
517
- const connected = await this.oauth(slug, payload);
518
- resolve(connected);
519
- // key based
520
- } else {
521
- const res = await fetch(`${this.baseUrl}/api/v2/app/${slug}/save`, {
522
- method: "POST",
523
- headers: {
524
- authorization: `Bearer ${this.token}`,
525
- "content-type": "application/json",
526
- },
527
- body: JSON.stringify({
528
- ...payload,
529
- }),
530
- });
531
-
532
- if (res.status >= 400 && res.status < 600) {
533
- const error = await res.json();
534
- reject(error);
535
- }
536
-
537
- const data = await res.json();
538
- resolve(data.success);
539
- }
540
- } catch (error) {
541
- reject(error);
542
- }
543
- });
550
+ public async connect(slug: string, authType: AuthType, payload?: Record<string, string>): Promise<boolean> {
551
+ switch (authType) {
552
+ case AuthType.OAuth2:
553
+ return this.oauth(slug, payload);
554
+ case AuthType.KeyBased:
555
+ return this.keybased(slug, payload);
556
+ default:
557
+ throw new Error(`Invalid auth type: ${authType}`);
558
+ }
544
559
  }
545
560
 
546
561
  /**
547
562
  * Disconnect the specified application and remove any associated data from Cobalt.
548
563
  * @param {String} slug The application slug.
549
- * @returns {Promise<void>}
564
+ * @returns {Promise<unknown>}
550
565
  */
551
- public async disconnect(slug: string): Promise<void> {
566
+ public async disconnect(slug: string): Promise<unknown> {
552
567
  const res = await fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${slug}`, {
553
568
  method: "DELETE",
554
569
  headers: {
@@ -560,6 +575,8 @@ class Cobalt {
560
575
  const error = await res.json();
561
576
  throw error;
562
577
  }
578
+
579
+ return await res.json();
563
580
  }
564
581
 
565
582
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobaltio/cobalt-js",
3
- "version": "8.9.2-beta.1",
3
+ "version": "9.0.0-beta.1",
4
4
  "description": "Cobalt frontend SDK",
5
5
  "main": "./cobalt.js",
6
6
  "typings": "./cobalt.d.ts",