@cobaltio/cobalt-js 8.9.1 → 8.9.2-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.
- package/cobalt.d.ts +41 -6
- package/cobalt.js +12 -2
- package/cobalt.ts +46 -8
- package/package.json +1 -1
package/cobalt.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cobalt Frontend SDK
|
|
3
3
|
*/
|
|
4
|
+
export declare enum AuthType {
|
|
5
|
+
OAuth2 = "oauth2",
|
|
6
|
+
KeyBased = "keybased"
|
|
7
|
+
}
|
|
8
|
+
export declare enum AuthStatus {
|
|
9
|
+
Active = "active",
|
|
10
|
+
Expired = "expired"
|
|
11
|
+
}
|
|
4
12
|
/** An application in Cobalt. */
|
|
5
13
|
export interface Application {
|
|
6
14
|
/** Application ID */
|
|
@@ -18,16 +26,43 @@ export interface Application {
|
|
|
18
26
|
type: string | "custom";
|
|
19
27
|
/** The application slug. */
|
|
20
28
|
slug: string;
|
|
21
|
-
/**The
|
|
29
|
+
/** The categories/tags for the application. */
|
|
30
|
+
tags?: string[];
|
|
31
|
+
/** The supported auth types for the application, and the fields required from the user to connect the application. */
|
|
32
|
+
auth_type_options?: {
|
|
33
|
+
[key in AuthType]: InputField[];
|
|
34
|
+
};
|
|
35
|
+
/** The list of connected accounts for this application */
|
|
36
|
+
connected_accounts?: {
|
|
37
|
+
/** The identifier (username, email, etc.) of the connected account. */
|
|
38
|
+
identifier: unknown;
|
|
39
|
+
/** The auth type used to connect the account. */
|
|
40
|
+
auth_type: AuthType;
|
|
41
|
+
/** The timestamp at which the account was connected. */
|
|
42
|
+
connectedAt: string;
|
|
43
|
+
/** The current status of the connection. */
|
|
44
|
+
status?: AuthStatus;
|
|
45
|
+
}[];
|
|
46
|
+
/**
|
|
47
|
+
* The type of auth used by application.
|
|
48
|
+
* @deprecated Check `auth_type_options` and `connected_accounts` for multiple auth types support.
|
|
49
|
+
*/
|
|
22
50
|
auth_type: "oauth2" | "keybased";
|
|
23
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Whether the user has connected the application.
|
|
53
|
+
* @deprecated Check `connected_accounts` for multiple auth types support.
|
|
54
|
+
*/
|
|
24
55
|
connected?: boolean;
|
|
25
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Whether the connection has expired and re-auth is required.
|
|
58
|
+
* @deprecated Check `connected_accounts` for multiple auth types support.
|
|
59
|
+
*/
|
|
26
60
|
reauth_required?: boolean;
|
|
27
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* The fields required from the user to connect the application (for `keybased` auth type).
|
|
63
|
+
* @deprecated Check `auth_type_options` for multiple auth types support.
|
|
64
|
+
*/
|
|
28
65
|
auth_input_map?: InputField[];
|
|
29
|
-
/** The categories/tags for the application. */
|
|
30
|
-
tags?: string[];
|
|
31
66
|
}
|
|
32
67
|
/** An Input field to take input from the user. */
|
|
33
68
|
export interface InputField {
|
package/cobalt.js
CHANGED
|
@@ -12,7 +12,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
});
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Cobalt = void 0;
|
|
15
|
+
exports.Cobalt = exports.AuthStatus = exports.AuthType = void 0;
|
|
16
|
+
var AuthType;
|
|
17
|
+
(function (AuthType) {
|
|
18
|
+
AuthType["OAuth2"] = "oauth2";
|
|
19
|
+
AuthType["KeyBased"] = "keybased";
|
|
20
|
+
})(AuthType || (exports.AuthType = AuthType = {}));
|
|
21
|
+
var AuthStatus;
|
|
22
|
+
(function (AuthStatus) {
|
|
23
|
+
AuthStatus["Active"] = "active";
|
|
24
|
+
AuthStatus["Expired"] = "expired";
|
|
25
|
+
})(AuthStatus || (exports.AuthStatus = AuthStatus = {}));
|
|
16
26
|
class Cobalt {
|
|
17
27
|
/**
|
|
18
28
|
* Cobalt Frontend SDK
|
|
@@ -194,7 +204,7 @@ class Cobalt {
|
|
|
194
204
|
try {
|
|
195
205
|
const app = yield this.getApp(slug);
|
|
196
206
|
// oauth
|
|
197
|
-
if (app && app.auth_type ===
|
|
207
|
+
if (app && app.auth_type === AuthType.OAuth2) {
|
|
198
208
|
const connected = yield this.oauth(slug, payload);
|
|
199
209
|
resolve(connected);
|
|
200
210
|
// key based
|
package/cobalt.ts
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
* Cobalt Frontend SDK
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
export enum AuthType {
|
|
6
|
+
OAuth2 = "oauth2",
|
|
7
|
+
KeyBased = "keybased",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum AuthStatus {
|
|
11
|
+
Active = "active",
|
|
12
|
+
Expired = "expired",
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
/** An application in Cobalt. */
|
|
6
16
|
export interface Application {
|
|
7
17
|
/** Application ID */
|
|
@@ -19,16 +29,44 @@ export interface Application {
|
|
|
19
29
|
type: string | "custom";
|
|
20
30
|
/** The application slug. */
|
|
21
31
|
slug: string;
|
|
22
|
-
/**The
|
|
32
|
+
/** The categories/tags for the application. */
|
|
33
|
+
tags?: string[];
|
|
34
|
+
/** The supported auth types for the application, and the fields required from the user to connect the application. */
|
|
35
|
+
auth_type_options?: {
|
|
36
|
+
/** The fields required from the user to connect the application. */
|
|
37
|
+
[key in AuthType]: InputField[];
|
|
38
|
+
};
|
|
39
|
+
/** The list of connected accounts for this application */
|
|
40
|
+
connected_accounts?: {
|
|
41
|
+
/** The identifier (username, email, etc.) of the connected account. */
|
|
42
|
+
identifier: unknown;
|
|
43
|
+
/** The auth type used to connect the account. */
|
|
44
|
+
auth_type: AuthType;
|
|
45
|
+
/** The timestamp at which the account was connected. */
|
|
46
|
+
connectedAt: string;
|
|
47
|
+
/** The current status of the connection. */
|
|
48
|
+
status?: AuthStatus;
|
|
49
|
+
}[];
|
|
50
|
+
/**
|
|
51
|
+
* The type of auth used by application.
|
|
52
|
+
* @deprecated Check `auth_type_options` and `connected_accounts` for multiple auth types support.
|
|
53
|
+
*/
|
|
23
54
|
auth_type: "oauth2" | "keybased";
|
|
24
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Whether the user has connected the application.
|
|
57
|
+
* @deprecated Check `connected_accounts` for multiple auth types support.
|
|
58
|
+
*/
|
|
25
59
|
connected?: boolean;
|
|
26
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Whether the connection has expired and re-auth is required.
|
|
62
|
+
* @deprecated Check `connected_accounts` for multiple auth types support.
|
|
63
|
+
*/
|
|
27
64
|
reauth_required?: boolean;
|
|
28
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* The fields required from the user to connect the application (for `keybased` auth type).
|
|
67
|
+
* @deprecated Check `auth_type_options` for multiple auth types support.
|
|
68
|
+
*/
|
|
29
69
|
auth_input_map?: InputField[];
|
|
30
|
-
/** The categories/tags for the application. */
|
|
31
|
-
tags?: string[];
|
|
32
70
|
}
|
|
33
71
|
|
|
34
72
|
/** An Input field to take input from the user. */
|
|
@@ -434,7 +472,7 @@ class Cobalt {
|
|
|
434
472
|
const interval = setInterval(() => {
|
|
435
473
|
this.getApp(slug)
|
|
436
474
|
.then(app => {
|
|
437
|
-
if (app && app.
|
|
475
|
+
if (app && app.connected_accounts?.filter(a => a.auth_type === AuthType.OAuth2).some(a => a.status === AuthStatus.Active)) {
|
|
438
476
|
// close auth window
|
|
439
477
|
connectWindow && connectWindow.close();
|
|
440
478
|
// clear interval
|
|
@@ -475,7 +513,7 @@ class Cobalt {
|
|
|
475
513
|
const app = await this.getApp(slug);
|
|
476
514
|
|
|
477
515
|
// oauth
|
|
478
|
-
if (app && app.auth_type ===
|
|
516
|
+
if (app && app.auth_type === AuthType.OAuth2) {
|
|
479
517
|
const connected = await this.oauth(slug, payload);
|
|
480
518
|
resolve(connected);
|
|
481
519
|
// key based
|