@pellux/goodvibes-sdk 0.18.49 → 0.18.51
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/dist/_internal/errors/index.d.ts +27 -2
- package/dist/_internal/errors/index.d.ts.map +1 -1
- package/dist/_internal/errors/index.js +44 -2
- package/dist/_internal/platform/auth/index.d.ts +4 -0
- package/dist/_internal/platform/auth/index.d.ts.map +1 -0
- package/dist/_internal/platform/auth/index.js +7 -0
- package/dist/_internal/platform/auth/oauth-client.d.ts +45 -0
- package/dist/_internal/platform/auth/oauth-client.d.ts.map +1 -0
- package/dist/_internal/platform/auth/oauth-client.js +45 -0
- package/dist/_internal/platform/auth/oauth-types.d.ts +21 -0
- package/dist/_internal/platform/auth/oauth-types.d.ts.map +1 -0
- package/dist/_internal/platform/auth/oauth-types.js +8 -0
- package/dist/_internal/platform/auth/permission-resolver.d.ts +35 -0
- package/dist/_internal/platform/auth/permission-resolver.d.ts.map +1 -0
- package/dist/_internal/platform/auth/permission-resolver.js +57 -0
- package/dist/_internal/platform/auth/session-manager.d.ts +31 -0
- package/dist/_internal/platform/auth/session-manager.d.ts.map +1 -0
- package/dist/_internal/platform/auth/session-manager.js +44 -0
- package/dist/_internal/platform/auth/token-store.d.ts +23 -0
- package/dist/_internal/platform/auth/token-store.d.ts.map +1 -0
- package/dist/_internal/platform/auth/token-store.js +34 -0
- package/dist/_internal/platform/config/openai-codex-auth.d.ts +1 -1
- package/dist/_internal/platform/config/openai-codex-auth.d.ts.map +1 -1
- package/dist/_internal/platform/config/openai-codex-auth.js +2 -2
- package/dist/_internal/platform/config/subscriptions.d.ts +2 -2
- package/dist/_internal/platform/config/subscriptions.d.ts.map +1 -1
- package/dist/_internal/platform/config/subscriptions.js +2 -2
- package/dist/_internal/platform/core/orchestrator.d.ts +75 -11
- package/dist/_internal/platform/core/orchestrator.d.ts.map +1 -1
- package/dist/_internal/platform/core/orchestrator.js +29 -8
- package/dist/_internal/platform/runtime/auth/crypto-adapter.d.ts +22 -0
- package/dist/_internal/platform/runtime/auth/crypto-adapter.d.ts.map +1 -0
- package/dist/_internal/platform/runtime/auth/crypto-adapter.js +40 -0
- package/dist/_internal/platform/runtime/auth/oauth-core.d.ts +4 -15
- package/dist/_internal/platform/runtime/auth/oauth-core.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/auth/oauth-core.js +13 -8
- package/dist/_internal/platform/version.js +1 -1
- package/dist/_internal/transport-realtime/domain-events.d.ts +26 -0
- package/dist/_internal/transport-realtime/domain-events.d.ts.map +1 -1
- package/dist/_internal/transport-realtime/domain-events.js +63 -0
- package/dist/_internal/transport-realtime/index.d.ts +2 -2
- package/dist/_internal/transport-realtime/index.d.ts.map +1 -1
- package/dist/_internal/transport-realtime/index.js +2 -2
- package/dist/_internal/transport-realtime/runtime-events.d.ts +27 -1
- package/dist/_internal/transport-realtime/runtime-events.d.ts.map +1 -1
- package/dist/_internal/transport-realtime/runtime-events.js +27 -0
- package/dist/auth.d.ts +28 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +6 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +1 -0
- package/dist/client.d.ts +50 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/expo.d.ts +1 -0
- package/dist/expo.d.ts.map +1 -1
- package/dist/expo.js +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/oauth.d.ts +26 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +24 -0
- package/dist/react-native.d.ts +1 -0
- package/dist/react-native.d.ts.map +1 -1
- package/dist/react-native.js +1 -0
- package/dist/web.d.ts +1 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +1 -0
- package/package.json +8 -1
|
@@ -2,6 +2,20 @@ import type { DaemonErrorCategory, DaemonErrorSource, StructuredDaemonErrorBody
|
|
|
2
2
|
export type { DaemonErrorCategory, DaemonErrorSource, StructuredDaemonErrorBody, } from './daemon-error-contract.js';
|
|
3
3
|
export type ErrorCategory = DaemonErrorCategory | 'contract';
|
|
4
4
|
export type ErrorSource = DaemonErrorSource | 'contract';
|
|
5
|
+
/**
|
|
6
|
+
* Tagged union discriminant for all SDK errors. Use this for exhaustive
|
|
7
|
+
* switch/if-else handling instead of `instanceof` chains.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* if (error instanceof GoodVibesSdkError) {
|
|
11
|
+
* if (error.kind === 'rate-limit') {
|
|
12
|
+
* await delay(error.retryAfterMs ?? 1000);
|
|
13
|
+
* } else if (error.kind === 'auth') {
|
|
14
|
+
* // refresh credentials
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export type SDKErrorKind = 'auth' | 'config' | 'contract' | 'network' | 'not-found' | 'rate-limit' | 'server' | 'validation' | 'unknown';
|
|
5
19
|
export interface GoodVibesSdkErrorOptions {
|
|
6
20
|
readonly code?: string;
|
|
7
21
|
readonly category?: ErrorCategory;
|
|
@@ -45,6 +59,7 @@ export declare const RETRYABLE_STATUS_CODES: readonly number[];
|
|
|
45
59
|
* ```
|
|
46
60
|
*/
|
|
47
61
|
export declare class GoodVibesSdkError extends Error {
|
|
62
|
+
readonly kind: SDKErrorKind;
|
|
48
63
|
readonly code?: string;
|
|
49
64
|
readonly category: ErrorCategory;
|
|
50
65
|
readonly source: ErrorSource;
|
|
@@ -68,7 +83,10 @@ export declare class GoodVibesSdkError extends Error {
|
|
|
68
83
|
* implementation available, or calling a mutation on a read-only auth resolver).
|
|
69
84
|
*
|
|
70
85
|
* Always non-recoverable (`recoverable: false`).
|
|
71
|
-
* Category: `'config'`.
|
|
86
|
+
* Category: `'config'`. Kind: `'config'`.
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Use `error.kind === 'config'` instead of `instanceof ConfigurationError`.
|
|
89
|
+
* This class is preserved for backward compatibility and still throws normally.
|
|
72
90
|
*
|
|
73
91
|
* @example
|
|
74
92
|
* import { ConfigurationError } from '@pellux/goodvibes-sdk';
|
|
@@ -89,7 +107,10 @@ export declare class ConfigurationError extends GoodVibesSdkError {
|
|
|
89
107
|
* (unexpected shape, missing required fields, etc.).
|
|
90
108
|
*
|
|
91
109
|
* Always non-recoverable (`recoverable: false`).
|
|
92
|
-
* Category: `'contract'`.
|
|
110
|
+
* Category: `'contract'`. Kind: `'contract'`.
|
|
111
|
+
*
|
|
112
|
+
* @deprecated Use `error.kind === 'contract'` instead of `instanceof ContractError`.
|
|
113
|
+
* This class is preserved for backward compatibility and still throws normally.
|
|
93
114
|
*
|
|
94
115
|
* @example
|
|
95
116
|
* import { ContractError } from '@pellux/goodvibes-sdk';
|
|
@@ -117,6 +138,10 @@ export declare class ContractError extends GoodVibesSdkError {
|
|
|
117
138
|
* Use `recoverable` to decide whether to retry, and `retryAfterMs` for
|
|
118
139
|
* the backoff hint on rate-limit responses.
|
|
119
140
|
*
|
|
141
|
+
* @deprecated Use `error.kind` instead of `instanceof HttpStatusError`.
|
|
142
|
+
* For example: `error.kind === 'rate-limit'`, `error.kind === 'auth'`, `error.kind === 'server'`.
|
|
143
|
+
* This class is preserved for backward compatibility and still throws normally.
|
|
144
|
+
*
|
|
120
145
|
* @example
|
|
121
146
|
* import { HttpStatusError } from '@pellux/goodvibes-sdk';
|
|
122
147
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_internal/errors/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,WAAW,GA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,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,KAAK,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CAqBpE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB;gBAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CASpE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,aAAc,SAAQ,iBAAiB;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CASpE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,eAAgB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CAOpE;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,yBAAyB,CAE9F;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ,eAAe,CAgCjB"}
|
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
function inferKind(category) {
|
|
2
|
+
switch (category) {
|
|
3
|
+
case 'authentication':
|
|
4
|
+
case 'authorization':
|
|
5
|
+
case 'billing':
|
|
6
|
+
case 'permission':
|
|
7
|
+
return 'auth';
|
|
8
|
+
case 'config':
|
|
9
|
+
return 'config';
|
|
10
|
+
case 'contract':
|
|
11
|
+
return 'contract';
|
|
12
|
+
case 'network':
|
|
13
|
+
case 'timeout':
|
|
14
|
+
return 'network';
|
|
15
|
+
case 'not_found':
|
|
16
|
+
return 'not-found';
|
|
17
|
+
case 'rate_limit':
|
|
18
|
+
return 'rate-limit';
|
|
19
|
+
case 'protocol':
|
|
20
|
+
case 'service':
|
|
21
|
+
case 'internal':
|
|
22
|
+
return 'server';
|
|
23
|
+
case 'bad_request':
|
|
24
|
+
return 'validation';
|
|
25
|
+
case 'tool':
|
|
26
|
+
case 'unknown':
|
|
27
|
+
default:
|
|
28
|
+
return 'unknown';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
1
31
|
export const RETRYABLE_STATUS_CODES = [408, 429, 500, 502, 503, 504];
|
|
2
32
|
function inferCategory(status) {
|
|
3
33
|
if (status === 400)
|
|
@@ -42,6 +72,7 @@ function inferCategory(status) {
|
|
|
42
72
|
* ```
|
|
43
73
|
*/
|
|
44
74
|
export class GoodVibesSdkError extends Error {
|
|
75
|
+
kind;
|
|
45
76
|
code;
|
|
46
77
|
category;
|
|
47
78
|
source;
|
|
@@ -63,6 +94,7 @@ export class GoodVibesSdkError extends Error {
|
|
|
63
94
|
this.name = this.constructor.name;
|
|
64
95
|
this.code = options.code;
|
|
65
96
|
this.category = options.category ?? inferCategory(options.status);
|
|
97
|
+
this.kind = inferKind(this.category);
|
|
66
98
|
this.source = options.source ?? 'unknown';
|
|
67
99
|
this.recoverable = options.recoverable ?? (options.status !== undefined && RETRYABLE_STATUS_CODES.includes(options.status));
|
|
68
100
|
this.status = options.status;
|
|
@@ -84,7 +116,10 @@ export class GoodVibesSdkError extends Error {
|
|
|
84
116
|
* implementation available, or calling a mutation on a read-only auth resolver).
|
|
85
117
|
*
|
|
86
118
|
* Always non-recoverable (`recoverable: false`).
|
|
87
|
-
* Category: `'config'`.
|
|
119
|
+
* Category: `'config'`. Kind: `'config'`.
|
|
120
|
+
*
|
|
121
|
+
* @deprecated Use `error.kind === 'config'` instead of `instanceof ConfigurationError`.
|
|
122
|
+
* This class is preserved for backward compatibility and still throws normally.
|
|
88
123
|
*
|
|
89
124
|
* @example
|
|
90
125
|
* import { ConfigurationError } from '@pellux/goodvibes-sdk';
|
|
@@ -113,7 +148,10 @@ export class ConfigurationError extends GoodVibesSdkError {
|
|
|
113
148
|
* (unexpected shape, missing required fields, etc.).
|
|
114
149
|
*
|
|
115
150
|
* Always non-recoverable (`recoverable: false`).
|
|
116
|
-
* Category: `'contract'`.
|
|
151
|
+
* Category: `'contract'`. Kind: `'contract'`.
|
|
152
|
+
*
|
|
153
|
+
* @deprecated Use `error.kind === 'contract'` instead of `instanceof ContractError`.
|
|
154
|
+
* This class is preserved for backward compatibility and still throws normally.
|
|
117
155
|
*
|
|
118
156
|
* @example
|
|
119
157
|
* import { ContractError } from '@pellux/goodvibes-sdk';
|
|
@@ -149,6 +187,10 @@ export class ContractError extends GoodVibesSdkError {
|
|
|
149
187
|
* Use `recoverable` to decide whether to retry, and `retryAfterMs` for
|
|
150
188
|
* the backoff hint on rate-limit responses.
|
|
151
189
|
*
|
|
190
|
+
* @deprecated Use `error.kind` instead of `instanceof HttpStatusError`.
|
|
191
|
+
* For example: `error.kind === 'rate-limit'`, `error.kind === 'auth'`, `error.kind === 'server'`.
|
|
192
|
+
* This class is preserved for backward compatibility and still throws normally.
|
|
193
|
+
*
|
|
152
194
|
* @example
|
|
153
195
|
* import { HttpStatusError } from '@pellux/goodvibes-sdk';
|
|
154
196
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/auth/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// OAuthClient is intentionally NOT re-exported from this barrel.
|
|
2
|
+
// It depends on node:crypto (via oauth-core.ts) and must not enter the
|
|
3
|
+
// React Native / browser module graph.
|
|
4
|
+
// Consumers: import OAuthClient from @pellux/goodvibes-sdk/oauth (Node only).
|
|
5
|
+
export { PermissionResolver } from './permission-resolver.js';
|
|
6
|
+
export { SessionManager } from './session-manager.js';
|
|
7
|
+
export { TokenStore } from './token-store.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuthClient — Focused responsibility: OAuth 2.0 / PKCE flows.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the pure functions in `oauth-core.ts` behind a class boundary so
|
|
5
|
+
* callers can inject config once and call methods, rather than threading
|
|
6
|
+
* `OAuthProviderConfig` through every call.
|
|
7
|
+
*/
|
|
8
|
+
import type { OAuthProviderConfig } from '../config/subscriptions.js';
|
|
9
|
+
export type { OAuthStartState, OAuthTokenPayload } from './oauth-types.js';
|
|
10
|
+
import type { OAuthStartState, OAuthTokenPayload } from './oauth-types.js';
|
|
11
|
+
export declare class OAuthClient {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(config: OAuthProviderConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Build the authorization URL and PKCE state needed to start an OAuth flow.
|
|
16
|
+
* Redirect the user's browser to `result.authorizationUrl`.
|
|
17
|
+
*/
|
|
18
|
+
beginAuthorization(input?: {
|
|
19
|
+
readonly state?: string;
|
|
20
|
+
readonly verifier?: string;
|
|
21
|
+
readonly redirectUri?: string;
|
|
22
|
+
}): Promise<OAuthStartState>;
|
|
23
|
+
/**
|
|
24
|
+
* Exchange an authorization code (returned via the redirect) for tokens.
|
|
25
|
+
* Use the `state` and `verifier` from the matching `beginAuthorization` call.
|
|
26
|
+
*/
|
|
27
|
+
exchangeCode(input: {
|
|
28
|
+
readonly code: string;
|
|
29
|
+
readonly verifier: string;
|
|
30
|
+
readonly redirectUri: string;
|
|
31
|
+
readonly state?: string;
|
|
32
|
+
}): Promise<OAuthTokenPayload>;
|
|
33
|
+
/**
|
|
34
|
+
* Use a refresh token to obtain a new access token without user interaction.
|
|
35
|
+
*/
|
|
36
|
+
refreshToken(refreshToken: string): Promise<OAuthTokenPayload>;
|
|
37
|
+
/**
|
|
38
|
+
* Decode a JWT access token's payload without verification.
|
|
39
|
+
* Returns null when the token is malformed.
|
|
40
|
+
*/
|
|
41
|
+
decodeJwtPayload(token: string): Record<string, unknown> | null;
|
|
42
|
+
/** Expose the provider config this client was built from. */
|
|
43
|
+
get config(): OAuthProviderConfig;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=oauth-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-client.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/auth/oauth-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAOtE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,qBAAa,WAAW;;gBAGV,MAAM,EAAE,mBAAmB;IAIvC;;;OAGG;IACG,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;KAC/B,GAAG,OAAO,CAAC,eAAe,CAAC;IAI5B;;;OAGG;IACG,YAAY,CAAC,KAAK,EAAE;QACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;QAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI9B;;OAEG;IACG,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIpE;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI/D,6DAA6D;IAC7D,IAAI,MAAM,IAAI,mBAAmB,CAEhC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuthClient — Focused responsibility: OAuth 2.0 / PKCE flows.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the pure functions in `oauth-core.ts` behind a class boundary so
|
|
5
|
+
* callers can inject config once and call methods, rather than threading
|
|
6
|
+
* `OAuthProviderConfig` through every call.
|
|
7
|
+
*/
|
|
8
|
+
import { buildOAuthAuthorizationStart, decodeJwtPayload, exchangeOAuthAuthorizationCode, refreshOAuthAccessToken, } from '../runtime/auth/oauth-core.js';
|
|
9
|
+
export class OAuthClient {
|
|
10
|
+
#config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.#config = config;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Build the authorization URL and PKCE state needed to start an OAuth flow.
|
|
16
|
+
* Redirect the user's browser to `result.authorizationUrl`.
|
|
17
|
+
*/
|
|
18
|
+
async beginAuthorization(input) {
|
|
19
|
+
return buildOAuthAuthorizationStart(this.#config, input);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Exchange an authorization code (returned via the redirect) for tokens.
|
|
23
|
+
* Use the `state` and `verifier` from the matching `beginAuthorization` call.
|
|
24
|
+
*/
|
|
25
|
+
async exchangeCode(input) {
|
|
26
|
+
return exchangeOAuthAuthorizationCode(this.#config, input);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Use a refresh token to obtain a new access token without user interaction.
|
|
30
|
+
*/
|
|
31
|
+
async refreshToken(refreshToken) {
|
|
32
|
+
return refreshOAuthAccessToken(this.#config, refreshToken);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decode a JWT access token's payload without verification.
|
|
36
|
+
* Returns null when the token is malformed.
|
|
37
|
+
*/
|
|
38
|
+
decodeJwtPayload(token) {
|
|
39
|
+
return decodeJwtPayload(token);
|
|
40
|
+
}
|
|
41
|
+
/** Expose the provider config this client was built from. */
|
|
42
|
+
get config() {
|
|
43
|
+
return this.#config;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared OAuth type definitions.
|
|
3
|
+
*
|
|
4
|
+
* Isolated from oauth-core.ts so that these types can be re-exported from
|
|
5
|
+
* runtime-neutral entry points (auth.ts, react-native.ts, browser.ts, etc.)
|
|
6
|
+
* without pulling in node:crypto.
|
|
7
|
+
*/
|
|
8
|
+
export interface OAuthStartState {
|
|
9
|
+
readonly authorizationUrl: string;
|
|
10
|
+
readonly state: string;
|
|
11
|
+
readonly verifier: string;
|
|
12
|
+
readonly redirectUri: string;
|
|
13
|
+
}
|
|
14
|
+
export interface OAuthTokenPayload {
|
|
15
|
+
readonly accessToken: string;
|
|
16
|
+
readonly refreshToken?: string;
|
|
17
|
+
readonly tokenType: string;
|
|
18
|
+
readonly expiresAt?: number;
|
|
19
|
+
readonly scopes?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=oauth-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-types.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/auth/oauth-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PermissionResolver — Focused responsibility: role and scope checks.
|
|
3
|
+
*
|
|
4
|
+
* Inspects a `ControlPlaneAuthSnapshot` to answer permission questions.
|
|
5
|
+
* Callers that only need access control checks can use this directly
|
|
6
|
+
* rather than traversing the full auth snapshot themselves.
|
|
7
|
+
*/
|
|
8
|
+
import type { ControlPlaneAuthSnapshot } from '../control-plane/auth-snapshot.js';
|
|
9
|
+
export declare class PermissionResolver {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(snapshot: ControlPlaneAuthSnapshot);
|
|
12
|
+
/** Whether the current principal is authenticated. */
|
|
13
|
+
get authenticated(): boolean;
|
|
14
|
+
/** Whether the current principal has admin privileges. */
|
|
15
|
+
get isAdmin(): boolean;
|
|
16
|
+
/** The principal identifier (user/bot/service id), or null when anonymous. */
|
|
17
|
+
get principalId(): string | null;
|
|
18
|
+
/** The kind of the current principal. */
|
|
19
|
+
get principalKind(): ControlPlaneAuthSnapshot['principalKind'];
|
|
20
|
+
/** Return true when the principal holds the given role. */
|
|
21
|
+
hasRole(role: string): boolean;
|
|
22
|
+
/** Return true when the principal holds ALL of the given roles. */
|
|
23
|
+
hasAllRoles(roles: readonly string[]): boolean;
|
|
24
|
+
/** Return true when the principal holds ANY of the given roles. */
|
|
25
|
+
hasAnyRole(roles: readonly string[]): boolean;
|
|
26
|
+
/** Return true when the principal holds the given scope. */
|
|
27
|
+
hasScope(scope: string): boolean;
|
|
28
|
+
/** Return true when the principal holds ALL of the given scopes. */
|
|
29
|
+
hasAllScopes(scopes: readonly string[]): boolean;
|
|
30
|
+
/** Return true when the principal holds ANY of the given scopes. */
|
|
31
|
+
hasAnyScope(scopes: readonly string[]): boolean;
|
|
32
|
+
/** Expose the raw snapshot for direct inspection. */
|
|
33
|
+
get snapshot(): ControlPlaneAuthSnapshot;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=permission-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission-resolver.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/auth/permission-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAElF,qBAAa,kBAAkB;;gBAGjB,QAAQ,EAAE,wBAAwB;IAI9C,sDAAsD;IACtD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,0DAA0D;IAC1D,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,8EAA8E;IAC9E,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED,yCAAyC;IACzC,IAAI,aAAa,IAAI,wBAAwB,CAAC,eAAe,CAAC,CAE7D;IAED,2DAA2D;IAC3D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,mEAAmE;IACnE,WAAW,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAI9C,mEAAmE;IACnE,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAI7C,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIhC,oEAAoE;IACpE,YAAY,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAIhD,oEAAoE;IACpE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO;IAI/C,qDAAqD;IACrD,IAAI,QAAQ,IAAI,wBAAwB,CAEvC;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PermissionResolver — Focused responsibility: role and scope checks.
|
|
3
|
+
*
|
|
4
|
+
* Inspects a `ControlPlaneAuthSnapshot` to answer permission questions.
|
|
5
|
+
* Callers that only need access control checks can use this directly
|
|
6
|
+
* rather than traversing the full auth snapshot themselves.
|
|
7
|
+
*/
|
|
8
|
+
export class PermissionResolver {
|
|
9
|
+
#snapshot;
|
|
10
|
+
constructor(snapshot) {
|
|
11
|
+
this.#snapshot = snapshot;
|
|
12
|
+
}
|
|
13
|
+
/** Whether the current principal is authenticated. */
|
|
14
|
+
get authenticated() {
|
|
15
|
+
return this.#snapshot.authenticated;
|
|
16
|
+
}
|
|
17
|
+
/** Whether the current principal has admin privileges. */
|
|
18
|
+
get isAdmin() {
|
|
19
|
+
return this.#snapshot.admin;
|
|
20
|
+
}
|
|
21
|
+
/** The principal identifier (user/bot/service id), or null when anonymous. */
|
|
22
|
+
get principalId() {
|
|
23
|
+
return this.#snapshot.principalId;
|
|
24
|
+
}
|
|
25
|
+
/** The kind of the current principal. */
|
|
26
|
+
get principalKind() {
|
|
27
|
+
return this.#snapshot.principalKind;
|
|
28
|
+
}
|
|
29
|
+
/** Return true when the principal holds the given role. */
|
|
30
|
+
hasRole(role) {
|
|
31
|
+
return this.#snapshot.roles.includes(role);
|
|
32
|
+
}
|
|
33
|
+
/** Return true when the principal holds ALL of the given roles. */
|
|
34
|
+
hasAllRoles(roles) {
|
|
35
|
+
return roles.every((role) => this.#snapshot.roles.includes(role));
|
|
36
|
+
}
|
|
37
|
+
/** Return true when the principal holds ANY of the given roles. */
|
|
38
|
+
hasAnyRole(roles) {
|
|
39
|
+
return roles.some((role) => this.#snapshot.roles.includes(role));
|
|
40
|
+
}
|
|
41
|
+
/** Return true when the principal holds the given scope. */
|
|
42
|
+
hasScope(scope) {
|
|
43
|
+
return this.#snapshot.scopes.includes(scope);
|
|
44
|
+
}
|
|
45
|
+
/** Return true when the principal holds ALL of the given scopes. */
|
|
46
|
+
hasAllScopes(scopes) {
|
|
47
|
+
return scopes.every((scope) => this.#snapshot.scopes.includes(scope));
|
|
48
|
+
}
|
|
49
|
+
/** Return true when the principal holds ANY of the given scopes. */
|
|
50
|
+
hasAnyScope(scopes) {
|
|
51
|
+
return scopes.some((scope) => this.#snapshot.scopes.includes(scope));
|
|
52
|
+
}
|
|
53
|
+
/** Expose the raw snapshot for direct inspection. */
|
|
54
|
+
get snapshot() {
|
|
55
|
+
return this.#snapshot;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionManager — Focused responsibility: session lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Manages the login/logout lifecycle and ties token persistence to login
|
|
5
|
+
* results. Decoupled from transport and token storage implementations.
|
|
6
|
+
*/
|
|
7
|
+
import type { OperatorSdk } from '../../operator/index.js';
|
|
8
|
+
import type { GoodVibesAuthLoginOptions, GoodVibesCurrentAuth, GoodVibesLoginInput, GoodVibesLoginOutput } from '../../../auth.js';
|
|
9
|
+
import { TokenStore } from './token-store.js';
|
|
10
|
+
export declare class SessionManager {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(operator: OperatorSdk, tokenStore: TokenStore | null);
|
|
13
|
+
/**
|
|
14
|
+
* Return the current auth state from the daemon control plane.
|
|
15
|
+
* Does not require a writable token store.
|
|
16
|
+
*/
|
|
17
|
+
current(): Promise<GoodVibesCurrentAuth>;
|
|
18
|
+
/**
|
|
19
|
+
* Perform a login and, when `persistToken` is not false, automatically
|
|
20
|
+
* persist the returned token into the configured token store.
|
|
21
|
+
*/
|
|
22
|
+
login(input: GoodVibesLoginInput, options?: GoodVibesAuthLoginOptions): Promise<GoodVibesLoginOutput>;
|
|
23
|
+
/**
|
|
24
|
+
* Whether this session manager has a writable token store.
|
|
25
|
+
* Read-only instances (using a raw `getAuthToken` resolver) return false.
|
|
26
|
+
*/
|
|
27
|
+
get writable(): boolean;
|
|
28
|
+
/** Access the underlying TokenStore (null when using a read-only resolver). */
|
|
29
|
+
get tokenStore(): TokenStore | null;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=session-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/auth/session-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qBAAa,cAAc;;gBAIb,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI;IAKhE;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAI9C;;;OAGG;IACG,KAAK,CACT,KAAK,EAAE,mBAAmB,EAC1B,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,oBAAoB,CAAC;IAQhC;;;OAGG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,+EAA+E;IAC/E,IAAI,UAAU,IAAI,UAAU,GAAG,IAAI,CAElC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionManager — Focused responsibility: session lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* Manages the login/logout lifecycle and ties token persistence to login
|
|
5
|
+
* results. Decoupled from transport and token storage implementations.
|
|
6
|
+
*/
|
|
7
|
+
import { TokenStore } from './token-store.js';
|
|
8
|
+
export class SessionManager {
|
|
9
|
+
#operator;
|
|
10
|
+
#tokenStore;
|
|
11
|
+
constructor(operator, tokenStore) {
|
|
12
|
+
this.#operator = operator;
|
|
13
|
+
this.#tokenStore = tokenStore;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Return the current auth state from the daemon control plane.
|
|
17
|
+
* Does not require a writable token store.
|
|
18
|
+
*/
|
|
19
|
+
async current() {
|
|
20
|
+
return this.#operator.control.auth.current();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Perform a login and, when `persistToken` is not false, automatically
|
|
24
|
+
* persist the returned token into the configured token store.
|
|
25
|
+
*/
|
|
26
|
+
async login(input, options = {}) {
|
|
27
|
+
const result = await this.#operator.control.auth.login(input);
|
|
28
|
+
if ((options.persistToken ?? true) && this.#tokenStore) {
|
|
29
|
+
await this.#tokenStore.setToken(result.token);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether this session manager has a writable token store.
|
|
35
|
+
* Read-only instances (using a raw `getAuthToken` resolver) return false.
|
|
36
|
+
*/
|
|
37
|
+
get writable() {
|
|
38
|
+
return this.#tokenStore !== null;
|
|
39
|
+
}
|
|
40
|
+
/** Access the underlying TokenStore (null when using a read-only resolver). */
|
|
41
|
+
get tokenStore() {
|
|
42
|
+
return this.#tokenStore;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TokenStore — Focused responsibility: token persistence.
|
|
3
|
+
*
|
|
4
|
+
* Owns all read/write/clear operations on a `GoodVibesTokenStore`. Consumers
|
|
5
|
+
* that only need token storage can interact with this class directly rather
|
|
6
|
+
* than going through the full auth client.
|
|
7
|
+
*/
|
|
8
|
+
import type { GoodVibesTokenStore } from '../../../auth.js';
|
|
9
|
+
export declare class TokenStore {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(store: GoodVibesTokenStore);
|
|
12
|
+
/** Return the current token, or null if none is stored. */
|
|
13
|
+
getToken(): Promise<string | null>;
|
|
14
|
+
/** Persist a new token, or clear storage when null. */
|
|
15
|
+
setToken(token: string | null): Promise<void>;
|
|
16
|
+
/** Clear the stored token. */
|
|
17
|
+
clearToken(): Promise<void>;
|
|
18
|
+
/** Return true when a non-empty token is currently stored. */
|
|
19
|
+
hasToken(): Promise<boolean>;
|
|
20
|
+
/** Expose the underlying store for interop with existing consumers. */
|
|
21
|
+
get store(): GoodVibesTokenStore;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=token-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-store.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/auth/token-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,qBAAa,UAAU;;gBAGT,KAAK,EAAE,mBAAmB;IAItC,2DAA2D;IACrD,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIxC,uDAAuD;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,8BAA8B;IACxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC,8DAA8D;IACxD,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAKlC,uEAAuE;IACvE,IAAI,KAAK,IAAI,mBAAmB,CAE/B;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TokenStore — Focused responsibility: token persistence.
|
|
3
|
+
*
|
|
4
|
+
* Owns all read/write/clear operations on a `GoodVibesTokenStore`. Consumers
|
|
5
|
+
* that only need token storage can interact with this class directly rather
|
|
6
|
+
* than going through the full auth client.
|
|
7
|
+
*/
|
|
8
|
+
export class TokenStore {
|
|
9
|
+
#store;
|
|
10
|
+
constructor(store) {
|
|
11
|
+
this.#store = store;
|
|
12
|
+
}
|
|
13
|
+
/** Return the current token, or null if none is stored. */
|
|
14
|
+
async getToken() {
|
|
15
|
+
return this.#store.getToken();
|
|
16
|
+
}
|
|
17
|
+
/** Persist a new token, or clear storage when null. */
|
|
18
|
+
async setToken(token) {
|
|
19
|
+
return this.#store.setToken(token);
|
|
20
|
+
}
|
|
21
|
+
/** Clear the stored token. */
|
|
22
|
+
async clearToken() {
|
|
23
|
+
return this.#store.clearToken();
|
|
24
|
+
}
|
|
25
|
+
/** Return true when a non-empty token is currently stored. */
|
|
26
|
+
async hasToken() {
|
|
27
|
+
const token = await this.#store.getToken();
|
|
28
|
+
return typeof token === 'string' && token.length > 0;
|
|
29
|
+
}
|
|
30
|
+
/** Expose the underlying store for interop with existing consumers. */
|
|
31
|
+
get store() {
|
|
32
|
+
return this.#store;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -15,7 +15,7 @@ export interface OpenAICodexTokenResult {
|
|
|
15
15
|
readonly expiresAt: number;
|
|
16
16
|
readonly scopes?: readonly string[];
|
|
17
17
|
}
|
|
18
|
-
export declare function beginOpenAICodexLogin(): OpenAICodexLoginStart
|
|
18
|
+
export declare function beginOpenAICodexLogin(): Promise<OpenAICodexLoginStart>;
|
|
19
19
|
export declare function exchangeOpenAICodexCode(code: string, verifier: string): Promise<OpenAICodexTokenResult>;
|
|
20
20
|
export declare function refreshOpenAICodexToken(refreshToken: string): Promise<OpenAICodexTokenResult>;
|
|
21
21
|
//# sourceMappingURL=openai-codex-auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-codex-auth.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/config/openai-codex-auth.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AACrE,eAAO,MAAM,0BAA0B,4CAA4C,CAAC;AACpF,eAAO,MAAM,sBAAsB,wCAAwC,CAAC;AAC5E,eAAO,MAAM,yBAAyB,wCAAwC,CAAC;AAG/E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ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,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAyB7G;AAED,wBAAsB,uBAAuB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAqBnG"}
|
|
@@ -4,8 +4,8 @@ export const OPENAI_CODEX_AUTHORIZE_URL = 'https://auth.openai.com/oauth/authori
|
|
|
4
4
|
export const OPENAI_CODEX_TOKEN_URL = 'https://auth.openai.com/oauth/token';
|
|
5
5
|
export const OPENAI_CODEX_REDIRECT_URI = 'http://localhost:1455/auth/callback';
|
|
6
6
|
const OPENAI_CODEX_SCOPE = 'openid profile email offline_access';
|
|
7
|
-
export function beginOpenAICodexLogin() {
|
|
8
|
-
const started = buildOAuthAuthorizationStart({
|
|
7
|
+
export async function beginOpenAICodexLogin() {
|
|
8
|
+
const started = await buildOAuthAuthorizationStart({
|
|
9
9
|
authUrl: OPENAI_CODEX_AUTHORIZE_URL,
|
|
10
10
|
tokenUrl: OPENAI_CODEX_TOKEN_URL,
|
|
11
11
|
clientId: OPENAI_CODEX_CLIENT_ID,
|
|
@@ -51,10 +51,10 @@ export declare class SubscriptionManager {
|
|
|
51
51
|
get(provider: string): ProviderSubscription | null;
|
|
52
52
|
getAccessToken(provider: string): string | null;
|
|
53
53
|
resolveAccessToken(provider: string, config: OAuthProviderConfig): Promise<string | null>;
|
|
54
|
-
beginOAuthLogin(provider: string, config: OAuthProviderConfig): {
|
|
54
|
+
beginOAuthLogin(provider: string, config: OAuthProviderConfig): Promise<{
|
|
55
55
|
authorizationUrl: string;
|
|
56
56
|
pending: PendingSubscriptionLogin;
|
|
57
|
-
}
|
|
57
|
+
}>;
|
|
58
58
|
completeOAuthLogin(provider: string, config: OAuthProviderConfig, code: string): Promise<ProviderSubscription>;
|
|
59
59
|
refreshOAuthToken(provider: string, config: OAuthProviderConfig): Promise<ProviderSubscription>;
|
|
60
60
|
logout(provider: string): boolean;
|
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CAAC,IAAI;IAaZ,OAAO,CAAC,KAAK;IAKN,IAAI,IAAI,oBAAoB,EAAE;IAI9B,WAAW,IAAI,wBAAwB,EAAE;IAIzC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI;IAIlD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAMzC,kBAAkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASZ,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,wBAAwB,CAAA;KAAE,CAAC;IAqBxI,kBAAkB,CAC7B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,mBAAmB,EAC3B,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,oBAAoB,CAAC;IAoCnB,iBAAiB,CAC5B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,oBAAoB,CAAC;IAkCzB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IASjC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,GAAG,IAAI;IAI7D,WAAW,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAMpD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMpC,gBAAgB,CAAC,YAAY,EAAE,oBAAoB,GAAG,oBAAoB;CAOlF"}
|
|
@@ -52,7 +52,7 @@ export class SubscriptionManager {
|
|
|
52
52
|
: subscription;
|
|
53
53
|
return active.accessToken;
|
|
54
54
|
}
|
|
55
|
-
beginOAuthLogin(provider, config) {
|
|
55
|
+
async beginOAuthLogin(provider, config) {
|
|
56
56
|
const store = this.read();
|
|
57
57
|
const state = createOAuthState();
|
|
58
58
|
const verifier = createPkceVerifier();
|
|
@@ -64,7 +64,7 @@ export class SubscriptionManager {
|
|
|
64
64
|
redirectUri,
|
|
65
65
|
createdAt: Date.now(),
|
|
66
66
|
};
|
|
67
|
-
const started = buildOAuthAuthorizationStart(config, { state, verifier, redirectUri });
|
|
67
|
+
const started = await buildOAuthAuthorizationStart(config, { state, verifier, redirectUri });
|
|
68
68
|
store.pending[provider] = pending;
|
|
69
69
|
this.write(store);
|
|
70
70
|
return {
|