@epam/ai-dial-chat-hooks 1.5.0-dev.33 → 1.5.0-dev.36
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/external-services/useExternalServiceLogin.js +7 -7
- package/external-services.js +3 -3
- package/index.js +247 -247
- package/oauth/batch-channel.d.ts +42 -0
- package/oauth/batch-channel.d.ts.map +1 -0
- package/oauth/batch-channel.js +90 -0
- package/oauth/handshake.d.ts +59 -2
- package/oauth/handshake.d.ts.map +1 -1
- package/oauth/handshake.js +204 -35
- package/oauth/models.d.ts +90 -1
- package/oauth/models.d.ts.map +1 -1
- package/oauth/popup.d.ts +35 -1
- package/oauth/popup.d.ts.map +1 -1
- package/oauth/popup.js +35 -15
- package/oauth/redirect-state.d.ts +12 -0
- package/oauth/redirect-state.d.ts.map +1 -0
- package/oauth/redirect-state.js +20 -0
- package/oauth/types.d.ts +41 -2
- package/oauth/types.d.ts.map +1 -1
- package/oauth/types.js +9 -3
- package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.d.ts +11 -5
- package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.d.ts.map +1 -1
- package/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.js +95 -66
- package/oauth/useToolsetLogin/useToolsetLogin.d.ts +11 -1
- package/oauth/useToolsetLogin/useToolsetLogin.d.ts.map +1 -1
- package/oauth/useToolsetLogin/useToolsetLogin.js +96 -45
- package/oauth.js +10 -10
- package/offline-credentials/useOfflineCredentialsLogin/useOfflineCredentialsLogin.js +5 -5
- package/package.json +17 -17
- package/signin-interrupt/models.d.ts +25 -1
- package/signin-interrupt/models.d.ts.map +1 -1
- package/signin-interrupt/types.d.ts +12 -1
- package/signin-interrupt/types.d.ts.map +1 -1
- package/signin-interrupt/types.js +4 -2
- package/signin-interrupt/useSigninInterrupt/useSigninInterrupt.d.ts +29 -5
- package/signin-interrupt/useSigninInterrupt/useSigninInterrupt.d.ts.map +1 -1
- package/signin-interrupt/useSigninInterrupt/useSigninInterrupt.js +412 -134
package/oauth/popup.js
CHANGED
|
@@ -1,31 +1,51 @@
|
|
|
1
|
-
import { OAuthResourceKind as e,
|
|
1
|
+
import { OAuthResourceKind as e, ToolsetCredentialsLevel as t, ToolsetOAuthCallbackQuery as n, ToolsetOAuthInitiationResultType as r } from "./types.js";
|
|
2
2
|
import { buildToolsetAuthorizeUrl as i, getToolsetRedirectUri as a } from "./authorize-url.js";
|
|
3
|
-
import {
|
|
3
|
+
import { writeToolsetRedirectState as o } from "./redirect-state.js";
|
|
4
|
+
import { generateUUID as s } from "@epam/ai-dial-chat-shared";
|
|
4
5
|
//#region src/oauth/popup.ts
|
|
5
|
-
var c = (e,
|
|
6
|
-
e.setItem(t, o(n));
|
|
7
|
-
}, l = (t, n, i, a, o, s, l = e.Toolset, u) => {
|
|
6
|
+
var c = (t, n, i, a, s, c, l = e.Toolset, u) => {
|
|
8
7
|
let d = {
|
|
9
8
|
toolsetId: a,
|
|
10
|
-
credentialsLevel:
|
|
11
|
-
redirectUri:
|
|
9
|
+
credentialsLevel: s,
|
|
10
|
+
redirectUri: c,
|
|
12
11
|
state: i,
|
|
13
12
|
resourceKind: l,
|
|
14
13
|
offlineUsageConsent: u
|
|
15
14
|
};
|
|
16
|
-
return
|
|
15
|
+
return o(t.sessionStorage, d), t.opener = null, t.location.href = n, {
|
|
17
16
|
type: r.Started,
|
|
18
17
|
popup: t,
|
|
19
18
|
flowId: i
|
|
20
19
|
};
|
|
21
|
-
},
|
|
20
|
+
}, l = () => window.open("", "_blank"), u = (n, o, l, u, d = t.User, f = e.Toolset, p) => {
|
|
22
21
|
let m = a(u), h = s(), g = i(o, m, h);
|
|
23
|
-
return g ?
|
|
24
|
-
},
|
|
25
|
-
let p = a(
|
|
22
|
+
return g ? c(n, g, h, l, d, m, f, p) : (n.close(), { type: r.InvalidConfig });
|
|
23
|
+
}, d = (n, o, u, d = t.User, f) => {
|
|
24
|
+
let p = a(u), m = s(), h = i(n, p, m);
|
|
26
25
|
if (!h) return { type: r.InvalidConfig };
|
|
27
|
-
let g =
|
|
28
|
-
return g ?
|
|
26
|
+
let g = l();
|
|
27
|
+
return g ? c(g, h, m, o, d, p, e.Toolset, f) : { type: r.Blocked };
|
|
28
|
+
}, f = (e, t, r) => {
|
|
29
|
+
let i = new URL(e, window.location.origin);
|
|
30
|
+
return i.searchParams.set(n.BatchRun, t), i.searchParams.set(n.BatchWindow, r), i.toString();
|
|
31
|
+
}, p = (e, t, n) => {
|
|
32
|
+
let r = l();
|
|
33
|
+
return r ? (r.opener = null, r.location.href = f(e, t, n), r) : null;
|
|
34
|
+
}, m = ({ auth: t, toolsetId: n, callbackPath: r, credentialsLevel: o, resourceKind: c = e.Toolset, offlineUsageConsent: l, batch: u }) => {
|
|
35
|
+
let d = a(r), f = s(), p = i(t, d, f);
|
|
36
|
+
return p ? {
|
|
37
|
+
flowId: f,
|
|
38
|
+
url: p,
|
|
39
|
+
redirectState: {
|
|
40
|
+
toolsetId: n,
|
|
41
|
+
credentialsLevel: o,
|
|
42
|
+
redirectUri: d,
|
|
43
|
+
state: f,
|
|
44
|
+
resourceKind: c,
|
|
45
|
+
offlineUsageConsent: l,
|
|
46
|
+
batch: u
|
|
47
|
+
}
|
|
48
|
+
} : null;
|
|
29
49
|
};
|
|
30
50
|
//#endregion
|
|
31
|
-
export { f as
|
|
51
|
+
export { m as buildToolsetOAuthBatchStep, f as getToolsetOAuthBatchWindowUrl, d as initiateOAuthLogin, u as navigateToolsetOAuthPopup, p as openToolsetOAuthBatchWindow, l as openToolsetOAuthPopup };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ToolsetRedirectState } from './models';
|
|
2
|
+
/**
|
|
3
|
+
* Writes the redirect state into the given context's `sessionStorage`,
|
|
4
|
+
* base64-wrapped through `encodeJsonToBase64`. The state carries only
|
|
5
|
+
* flow-correlation ids and paths, never tokens or codes; the wrap's Unicode
|
|
6
|
+
* safety keeps any user-named resource id storable (`btoa` alone throws on
|
|
7
|
+
* characters above `U+00FF`, which would strand the already-open popup).
|
|
8
|
+
*/
|
|
9
|
+
export declare const writeToolsetRedirectState: (storage: Pick<Storage, "setItem">, redirectState: ToolsetRedirectState) => void;
|
|
10
|
+
/** Reads the redirect state from this context's `sessionStorage`, or `null` when absent or malformed. */
|
|
11
|
+
export declare const readToolsetRedirectState: () => ToolsetRedirectState | null;
|
|
12
|
+
//# sourceMappingURL=redirect-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect-state.d.ts","sourceRoot":"","sources":["../../src/oauth/redirect-state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AASrD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACpC,SAAS,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EACjC,eAAe,oBAAoB,KAClC,IAKF,CAAC;AAEF,yGAAyG;AACzG,eAAO,MAAM,wBAAwB,QAAO,oBAAoB,GAAG,IAkBlE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TOOLSET_REDIRECT_STATE_KEY as e } from "./types.js";
|
|
2
|
+
import { decodeJsonFromBase64 as t, encodeJsonToBase64 as n } from "@epam/ai-dial-chat-shared";
|
|
3
|
+
//#region src/oauth/redirect-state.ts
|
|
4
|
+
var r = (t, r) => {
|
|
5
|
+
t.setItem(e, n(r));
|
|
6
|
+
}, i = () => {
|
|
7
|
+
let n = sessionStorage.getItem(e);
|
|
8
|
+
if (!n) return null;
|
|
9
|
+
try {
|
|
10
|
+
return t(n);
|
|
11
|
+
} catch {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(n);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { i as readToolsetRedirectState, r as writeToolsetRedirectState };
|
package/oauth/types.d.ts
CHANGED
|
@@ -74,10 +74,49 @@ export declare enum ToolsetOAuthFailureReason {
|
|
|
74
74
|
export declare enum ToolsetOAuthChannelControlType {
|
|
75
75
|
ResultAcknowledged = "result-acknowledged"
|
|
76
76
|
}
|
|
77
|
-
/** Query parameters
|
|
77
|
+
/** Query parameters of the callback popup URL. */
|
|
78
78
|
export declare enum ToolsetOAuthCallbackQuery {
|
|
79
|
+
/** Written after an OAuth flow completes: its result type. */
|
|
79
80
|
Result = "toolsetOAuthResult",
|
|
80
|
-
|
|
81
|
+
/** Written after a failed OAuth flow: its failure reason. */
|
|
82
|
+
FailureReason = "toolsetOAuthFailureReason",
|
|
83
|
+
/** Bulk sign-in run a waiting window belongs to. */
|
|
84
|
+
BatchRun = "toolsetOAuthBatchRun",
|
|
85
|
+
/** Id of a waiting bulk sign-in window within its run. */
|
|
86
|
+
BatchWindow = "toolsetOAuthBatchWindow"
|
|
87
|
+
}
|
|
88
|
+
/** Messages exchanged on a bulk sign-in run's window channel. */
|
|
89
|
+
export declare enum ToolsetOAuthBatchMessageType {
|
|
90
|
+
/** Window → tab: the window waits for a command after the step it names. */
|
|
91
|
+
Ready = "batch-ready",
|
|
92
|
+
/** Tab → window: run one provider step in this window. */
|
|
93
|
+
Navigate = "batch-navigate",
|
|
94
|
+
/** Window → tab: the window accepted a step and navigates to its provider. */
|
|
95
|
+
Accepted = "batch-accepted",
|
|
96
|
+
/** Tab → window: show the run's upcoming target. */
|
|
97
|
+
Progress = "batch-progress",
|
|
98
|
+
/** Tab → window: close the window. */
|
|
99
|
+
Close = "batch-close",
|
|
100
|
+
/** Window → tab: the window accepts no further commands. */
|
|
101
|
+
Released = "batch-released"
|
|
102
|
+
}
|
|
103
|
+
/** What a bulk sign-in window shows while it is not running a provider step. */
|
|
104
|
+
export declare enum ToolsetOAuthBatchWindowPhase {
|
|
105
|
+
/** Waiting for the run's next command. */
|
|
106
|
+
Waiting = "waiting",
|
|
107
|
+
/** No command arrived in time; the window can be closed. */
|
|
108
|
+
Idle = "idle"
|
|
109
|
+
}
|
|
110
|
+
/** Outcome of one provider step run in a bulk sign-in window. */
|
|
111
|
+
export declare enum ToolsetOAuthBatchStepOutcomeType {
|
|
112
|
+
Success = "success",
|
|
113
|
+
Failure = "failure",
|
|
114
|
+
/** The window was blocked, closed, or stopped answering before the step's result. */
|
|
115
|
+
WindowLost = "window-lost",
|
|
116
|
+
/** The OAuth configuration cannot produce an authorize URL. */
|
|
117
|
+
InvalidConfig = "invalid-config",
|
|
118
|
+
/** The session was closed while the step was running. */
|
|
119
|
+
Stopped = "stopped"
|
|
81
120
|
}
|
|
82
121
|
/** `sessionStorage` key the flow writes its `ToolsetRedirectState` under, in the popup it opens. */
|
|
83
122
|
export declare const TOOLSET_REDIRECT_STATE_KEY = "toolset-redirect-state";
|
package/oauth/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mDAAmD;AACnD,oBAAY,gBAAgB;IAC1B,IAAI,SAAS;IACb,MAAM,YAAY;IAClB,KAAK,UAAU;CAChB;AAED,8EAA8E;AAC9E,oBAAY,iBAAiB;IAC3B,QAAQ,cAAc;IACtB,SAAS,eAAe;IACxB,MAAM,WAAW;CAClB;AAED,2DAA2D;AAC3D,oBAAY,uBAAuB;IACjC,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAED,oGAAoG;AACpG,oBAAY,SAAS;IACnB,SAAS,eAAe;IACxB,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;CAC3B;AAED;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,eAAe,qBAAqB;IACpC;;;;;;;OAOG;IACH,kBAAkB,wBAAwB;CAC3C;AAED,+CAA+C;AAC/C,oBAAY,gCAAgC;IAC1C,0EAA0E;IAC1E,OAAO,YAAY;IACnB,+DAA+D;IAC/D,OAAO,YAAY;IACnB,oEAAoE;IACpE,aAAa,mBAAmB;CACjC;AAED,sEAAsE;AACtE,oBAAY,sBAAsB;IAChC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,oFAAoF;IACpF,SAAS,cAAc;CACxB;AAED,2EAA2E;AAC3E,oBAAY,yBAAyB;IACnC,WAAW,iBAAiB;IAC5B,oBAAoB,2BAA2B;IAC/C,aAAa,mBAAmB;IAChC,kBAAkB,yBAAyB;CAC5C;AAED,mEAAmE;AACnE,oBAAY,8BAA8B;IACxC,kBAAkB,wBAAwB;CAC3C;AAED,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,mDAAmD;AACnD,oBAAY,gBAAgB;IAC1B,IAAI,SAAS;IACb,MAAM,YAAY;IAClB,KAAK,UAAU;CAChB;AAED,8EAA8E;AAC9E,oBAAY,iBAAiB;IAC3B,QAAQ,cAAc;IACtB,SAAS,eAAe;IACxB,MAAM,WAAW;CAClB;AAED,2DAA2D;AAC3D,oBAAY,uBAAuB;IACjC,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,GAAG,QAAQ;CACZ;AAED,oGAAoG;AACpG,oBAAY,SAAS;IACnB,SAAS,eAAe;IACxB,YAAY,kBAAkB;IAC9B,UAAU,gBAAgB;CAC3B;AAED;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,eAAe,qBAAqB;IACpC;;;;;;;OAOG;IACH,kBAAkB,wBAAwB;CAC3C;AAED,+CAA+C;AAC/C,oBAAY,gCAAgC;IAC1C,0EAA0E;IAC1E,OAAO,YAAY;IACnB,+DAA+D;IAC/D,OAAO,YAAY;IACnB,oEAAoE;IACpE,aAAa,mBAAmB;CACjC;AAED,sEAAsE;AACtE,oBAAY,sBAAsB;IAChC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,oFAAoF;IACpF,SAAS,cAAc;CACxB;AAED,2EAA2E;AAC3E,oBAAY,yBAAyB;IACnC,WAAW,iBAAiB;IAC5B,oBAAoB,2BAA2B;IAC/C,aAAa,mBAAmB;IAChC,kBAAkB,yBAAyB;CAC5C;AAED,mEAAmE;AACnE,oBAAY,8BAA8B;IACxC,kBAAkB,wBAAwB;CAC3C;AAED,kDAAkD;AAClD,oBAAY,yBAAyB;IACnC,8DAA8D;IAC9D,MAAM,uBAAuB;IAC7B,6DAA6D;IAC7D,aAAa,8BAA8B;IAC3C,oDAAoD;IACpD,QAAQ,yBAAyB;IACjC,0DAA0D;IAC1D,WAAW,4BAA4B;CACxC;AAED,iEAAiE;AACjE,oBAAY,4BAA4B;IACtC,4EAA4E;IAC5E,KAAK,gBAAgB;IACrB,0DAA0D;IAC1D,QAAQ,mBAAmB;IAC3B,8EAA8E;IAC9E,QAAQ,mBAAmB;IAC3B,oDAAoD;IACpD,QAAQ,mBAAmB;IAC3B,sCAAsC;IACtC,KAAK,gBAAgB;IACrB,4DAA4D;IAC5D,QAAQ,mBAAmB;CAC5B;AAED,gFAAgF;AAChF,oBAAY,4BAA4B;IACtC,0CAA0C;IAC1C,OAAO,YAAY;IACnB,4DAA4D;IAC5D,IAAI,SAAS;CACd;AAED,iEAAiE;AACjE,oBAAY,gCAAgC;IAC1C,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,qFAAqF;IACrF,UAAU,gBAAgB;IAC1B,+DAA+D;IAC/D,aAAa,mBAAmB;IAChC,yDAAyD;IACzD,OAAO,YAAY;CACpB;AAED,oGAAoG;AACpG,eAAO,MAAM,0BAA0B,2BAA2B,CAAC"}
|
package/oauth/types.js
CHANGED
|
@@ -18,7 +18,13 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
18
18
|
}({}), c = /* @__PURE__ */ function(e) {
|
|
19
19
|
return e.ResultAcknowledged = "result-acknowledged", e;
|
|
20
20
|
}({}), l = /* @__PURE__ */ function(e) {
|
|
21
|
-
return e.Result = "toolsetOAuthResult", e.FailureReason = "toolsetOAuthFailureReason", e;
|
|
22
|
-
}({}), u =
|
|
21
|
+
return e.Result = "toolsetOAuthResult", e.FailureReason = "toolsetOAuthFailureReason", e.BatchRun = "toolsetOAuthBatchRun", e.BatchWindow = "toolsetOAuthBatchWindow", e;
|
|
22
|
+
}({}), u = /* @__PURE__ */ function(e) {
|
|
23
|
+
return e.Ready = "batch-ready", e.Navigate = "batch-navigate", e.Accepted = "batch-accepted", e.Progress = "batch-progress", e.Close = "batch-close", e.Released = "batch-released", e;
|
|
24
|
+
}({}), d = /* @__PURE__ */ function(e) {
|
|
25
|
+
return e.Waiting = "waiting", e.Idle = "idle", e;
|
|
26
|
+
}({}), f = /* @__PURE__ */ function(e) {
|
|
27
|
+
return e.Success = "success", e.Failure = "failure", e.WindowLost = "window-lost", e.InvalidConfig = "invalid-config", e.Stopped = "stopped", e;
|
|
28
|
+
}({}), p = "toolset-redirect-state";
|
|
23
29
|
//#endregion
|
|
24
|
-
export { i as OAuthResourceKind,
|
|
30
|
+
export { i as OAuthResourceKind, p as TOOLSET_REDIRECT_STATE_KEY, t as ToolsetAuthStatus, e as ToolsetAuthTypes, n as ToolsetCredentialsLevel, u as ToolsetOAuthBatchMessageType, f as ToolsetOAuthBatchStepOutcomeType, d as ToolsetOAuthBatchWindowPhase, l as ToolsetOAuthCallbackQuery, c as ToolsetOAuthChannelControlType, s as ToolsetOAuthFailureReason, a as ToolsetOAuthInitiationResultType, o as ToolsetOAuthResultType, r as WithLogin };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ToolsetRedirectState } from '../models';
|
|
1
|
+
import { ToolsetOAuthBatchWindowState, ToolsetRedirectState } from '../models';
|
|
2
2
|
import { ToolsetCredentialsLevel, ToolsetOAuthFailureReason } from '../types';
|
|
3
3
|
/** Arguments handed to the host's exchange callback. */
|
|
4
4
|
export interface OAuthExchangeParams {
|
|
@@ -38,6 +38,10 @@ export interface UseOAuthCallbackCompletionResult {
|
|
|
38
38
|
isInProgress: boolean;
|
|
39
39
|
/** Reason the flow failed, or `null` while in progress or on success. */
|
|
40
40
|
failureReason: ToolsetOAuthFailureReason | null;
|
|
41
|
+
/** What this window shows as part of a bulk sign-in run, or `null` outside one. */
|
|
42
|
+
batchWindow: ToolsetOAuthBatchWindowState | null;
|
|
43
|
+
/** Whether this window belongs to a bulk sign-in run; known from the first render, before `batchWindow`. */
|
|
44
|
+
isBatchWindow: boolean;
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* Completes an OAuth authorization-code flow from inside the callback popup:
|
|
@@ -45,10 +49,12 @@ export interface UseOAuthCallbackCompletionResult {
|
|
|
45
49
|
* `sessionStorage`, scrubs the authorization code from the visible URL before
|
|
46
50
|
* any request, validates the returned `state`, performs the exchange through
|
|
47
51
|
* the injected callback, then reports the outcome into the popup URL and over
|
|
48
|
-
* the flow channel until acknowledged, closing the popup afterwards.
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
+
* the flow channel until acknowledged, closing the popup afterwards. A window
|
|
53
|
+
* of a bulk sign-in run instead waits for the run's next command after the
|
|
54
|
+
* acknowledgement, and a window opened for a run without a code waits from the
|
|
55
|
+
* start. Runs its effect once per mount even under StrictMode
|
|
56
|
+
* double-invocation. Renders nothing and produces no user-visible text — the
|
|
57
|
+
* host page presents and announces the returned state in its own language.
|
|
52
58
|
*/
|
|
53
59
|
export declare const useOAuthCallbackCompletion: ({ searchParams, callbackPath, exchange, }: UseOAuthCallbackCompletionParams) => UseOAuthCallbackCompletionResult;
|
|
54
60
|
//# sourceMappingURL=useOAuthCallbackCompletion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOAuthCallbackCompletion.d.ts","sourceRoot":"","sources":["../../../src/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOAuthCallbackCompletion.d.ts","sourceRoot":"","sources":["../../../src/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,4BAA4B,EAG5B,oBAAoB,EACrB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAEL,uBAAuB,EAIvB,yBAAyB,EAE1B,MAAM,UAAU,CAAC;AAIlB,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,kFAAkF;IAClF,WAAW,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,iFAAiF;IACjF,aAAa,EAAE,oBAAoB,CAAC;CACrC;AAED,yDAAyD;AACzD,MAAM,WAAW,gCAAgC;IAC/C;;;OAGG;IACH,YAAY,EAAE,eAAe,CAAC;IAC9B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,EAAE,CACR,MAAM,EAAE,mBAAmB,KACxB,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAC;CAChD;AAED,oFAAoF;AACpF,MAAM,WAAW,gCAAgC;IAC/C,mDAAmD;IACnD,YAAY,EAAE,OAAO,CAAC;IACtB,yEAAyE;IACzE,aAAa,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAChD,mFAAmF;IACnF,WAAW,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACjD,4GAA4G;IAC5G,aAAa,EAAE,OAAO,CAAC;CACxB;AAkFD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,GAAI,2CAIxC,gCAAgC,KAAG,gCA6KrC,CAAC"}
|
|
@@ -1,93 +1,122 @@
|
|
|
1
|
-
import { TOOLSET_REDIRECT_STATE_KEY as e, ToolsetCredentialsLevel as t,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { TOOLSET_REDIRECT_STATE_KEY as e, ToolsetCredentialsLevel as t, ToolsetOAuthBatchWindowPhase as n, ToolsetOAuthCallbackQuery as r, ToolsetOAuthChannelControlType as i, ToolsetOAuthFailureReason as a, ToolsetOAuthResultType as o } from "../types.js";
|
|
2
|
+
import { readToolsetRedirectState as s } from "../redirect-state.js";
|
|
3
|
+
import { BATCH_WINDOW_IDLE_TIMEOUT_MS as c, readBatchWindowIdentity as l, startBatchWindowWaiting as u } from "../batch-channel.js";
|
|
4
|
+
import { getToolsetOAuthBatchWindowUrl as d } from "../popup.js";
|
|
5
|
+
import { getToolsetOAuthChannelName as f } from "../handshake.js";
|
|
6
|
+
import { useEffect as p, useRef as m, useState as h } from "react";
|
|
5
7
|
//#region src/oauth/useOAuthCallbackCompletion/useOAuthCallbackCompletion.ts
|
|
6
|
-
var
|
|
7
|
-
let t = sessionStorage.getItem(e);
|
|
8
|
-
if (!t) return null;
|
|
9
|
-
try {
|
|
10
|
-
return s(t);
|
|
11
|
-
} catch {
|
|
12
|
-
try {
|
|
13
|
-
return JSON.parse(t);
|
|
14
|
-
} catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}, m = (e) => {
|
|
8
|
+
var g = 500, _ = (e) => typeof e == "object" && !!e && "type" in e && e.type === i.ResultAcknowledged, v = (e) => {
|
|
19
9
|
try {
|
|
20
10
|
window.history.replaceState({}, document.title, `${e.pathname}${e.search}`);
|
|
21
11
|
} catch {}
|
|
22
|
-
},
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let r =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
}, y = (e, t, n = () => window.close()) => {
|
|
13
|
+
let i = new URL(window.location.pathname, window.location.origin);
|
|
14
|
+
i.searchParams.set(r.Result, t.type), t.type === o.Failure && i.searchParams.set(r.FailureReason, t.reason), v(i);
|
|
15
|
+
let a = () => void 0;
|
|
16
|
+
if (!e) return window.close(), a;
|
|
17
|
+
try {
|
|
18
|
+
let r = new BroadcastChannel(f(e));
|
|
19
|
+
r.postMessage(t);
|
|
20
|
+
let i = setInterval(() => {
|
|
21
|
+
r.postMessage(t);
|
|
22
|
+
}, g), a = () => {
|
|
23
|
+
clearInterval(i), r.close();
|
|
33
24
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
return r.onmessage = (e) => {
|
|
26
|
+
_(e.data) && (a(), n());
|
|
27
|
+
}, a;
|
|
28
|
+
} catch {
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
}, b = (e) => e != null && typeof e.runId == "string" && typeof e.windowId == "string" && typeof e.stepId == "number", x = ({ searchParams: r, callbackPath: i, exchange: f }) => {
|
|
32
|
+
let [g, _] = h(!0), [x, S] = h(null), [C, w] = h(null), [T] = h(() => l(r) != null || b(s()?.batch)), E = m(!1), D = m(f);
|
|
33
|
+
D.current = f;
|
|
34
|
+
let O = m(i);
|
|
35
|
+
return O.current = i, p(() => {
|
|
36
|
+
if (E.current) return;
|
|
37
|
+
E.current = !0;
|
|
38
|
+
let i = (e, t) => {
|
|
39
|
+
v(new URL(d(window.location.pathname, e.runId, e.windowId))), _(!1), w({ phase: n.Waiting }), u({
|
|
40
|
+
...e,
|
|
41
|
+
lastStepId: t,
|
|
42
|
+
onProgress: (e) => w({
|
|
43
|
+
phase: n.Waiting,
|
|
44
|
+
progress: e
|
|
45
|
+
}),
|
|
46
|
+
onIdle: () => w((e) => ({
|
|
47
|
+
phase: n.Idle,
|
|
48
|
+
progress: e?.progress
|
|
49
|
+
}))
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
(async () => {
|
|
53
|
+
let u = r.get("code"), d = r.get("state"), f = s();
|
|
42
54
|
sessionStorage.removeItem(e);
|
|
43
|
-
let
|
|
44
|
-
|
|
55
|
+
let p = f?.state ?? d ?? void 0, m = b(f?.batch) ? f.batch : void 0, h = l(r);
|
|
56
|
+
if (h != null && !u) {
|
|
57
|
+
i(h, 0);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let g = (e, t) => {
|
|
61
|
+
if (S(t.type === o.Failure ? t.reason : null), m == null || e == null) {
|
|
62
|
+
y(e, t), _(!1);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
_(!1), w({ phase: n.Waiting });
|
|
66
|
+
let r = {}, a = y(e, t, () => {
|
|
67
|
+
clearTimeout(r.idle), i(m, m.stepId);
|
|
68
|
+
});
|
|
69
|
+
r.idle = setTimeout(() => {
|
|
70
|
+
a(), w({ phase: n.Idle });
|
|
71
|
+
}, c);
|
|
45
72
|
};
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
type:
|
|
49
|
-
reason:
|
|
73
|
+
if (v(new URL(window.location.pathname, window.location.origin)), !u || !f?.toolsetId) {
|
|
74
|
+
g(p, {
|
|
75
|
+
type: o.Failure,
|
|
76
|
+
reason: f?.toolsetId ? a.MissingCode : a.MissingRedirectState
|
|
50
77
|
});
|
|
51
78
|
return;
|
|
52
79
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
type:
|
|
56
|
-
reason:
|
|
80
|
+
if (f.state != null && f.state !== d) {
|
|
81
|
+
g(p, {
|
|
82
|
+
type: o.Failure,
|
|
83
|
+
reason: a.StateMismatch
|
|
57
84
|
});
|
|
58
85
|
return;
|
|
59
86
|
}
|
|
60
|
-
let
|
|
87
|
+
let x = f.credentialsLevel ?? t.User, C = f.redirectUri ?? `${window.location.origin}${O.current}`;
|
|
61
88
|
try {
|
|
62
|
-
let e = await
|
|
63
|
-
code:
|
|
64
|
-
redirectUri:
|
|
65
|
-
credentialsLevel:
|
|
66
|
-
redirectState:
|
|
89
|
+
let e = await D.current({
|
|
90
|
+
code: u,
|
|
91
|
+
redirectUri: C,
|
|
92
|
+
credentialsLevel: x,
|
|
93
|
+
redirectState: f
|
|
67
94
|
});
|
|
68
95
|
if (e != null) {
|
|
69
|
-
|
|
70
|
-
type:
|
|
96
|
+
g(p, {
|
|
97
|
+
type: o.Failure,
|
|
71
98
|
reason: e
|
|
72
99
|
});
|
|
73
100
|
return;
|
|
74
101
|
}
|
|
75
|
-
|
|
76
|
-
type:
|
|
77
|
-
toolsetId:
|
|
78
|
-
credentialsLevel:
|
|
102
|
+
g(p, {
|
|
103
|
+
type: o.Success,
|
|
104
|
+
toolsetId: f.toolsetId,
|
|
105
|
+
credentialsLevel: x
|
|
79
106
|
});
|
|
80
107
|
} catch {
|
|
81
|
-
|
|
82
|
-
type:
|
|
83
|
-
reason:
|
|
108
|
+
g(p, {
|
|
109
|
+
type: o.Failure,
|
|
110
|
+
reason: a.LoginRequestFailed
|
|
84
111
|
});
|
|
85
112
|
}
|
|
86
|
-
})()
|
|
87
|
-
}, [
|
|
88
|
-
isInProgress:
|
|
89
|
-
failureReason:
|
|
113
|
+
})();
|
|
114
|
+
}, [r]), {
|
|
115
|
+
isInProgress: g,
|
|
116
|
+
failureReason: x,
|
|
117
|
+
batchWindow: C,
|
|
118
|
+
isBatchWindow: T
|
|
90
119
|
};
|
|
91
120
|
};
|
|
92
121
|
//#endregion
|
|
93
|
-
export {
|
|
122
|
+
export { x as useOAuthCallbackCompletion };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DialToolsetDto, ToolsetLoginBodyDto, ToolsetLogoutBodyDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
import { CreateToolsetOAuthBatchSessionOptions, ToolsetOAuthBatchSession } from '../handshake';
|
|
2
3
|
import { ToolsetOAuthSettings } from '../models';
|
|
3
4
|
import { ToolsetAuthTypes, ToolsetCredentialsLevel } from '../types';
|
|
4
5
|
/** Terminal outcome kinds `login` can resolve. */
|
|
@@ -6,7 +7,9 @@ export declare enum ToolsetLoginOutcomeType {
|
|
|
6
7
|
Success = "success",
|
|
7
8
|
Failure = "failure",
|
|
8
9
|
PopupBlocked = "popup-blocked",
|
|
9
|
-
Cancelled = "cancelled"
|
|
10
|
+
Cancelled = "cancelled",
|
|
11
|
+
/** A bulk sign-in window was lost before the step's result, and the toolset is not signed in. */
|
|
12
|
+
WindowLost = "window-lost"
|
|
10
13
|
}
|
|
11
14
|
/** Discriminated outcome of one login attempt. */
|
|
12
15
|
export interface ToolsetLoginOutcome {
|
|
@@ -46,6 +49,11 @@ export interface ToolsetLoginParams {
|
|
|
46
49
|
* `consent-required` in the background. Absent means not granted.
|
|
47
50
|
*/
|
|
48
51
|
offlineUsageConsent?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Bulk sign-in run to run an OAuth login in, instead of opening a popup of
|
|
54
|
+
* its own. Ignored for API key logins.
|
|
55
|
+
*/
|
|
56
|
+
batchSession?: ToolsetOAuthBatchSession;
|
|
49
57
|
}
|
|
50
58
|
/** Parameters for {@link useToolsetLogin}. */
|
|
51
59
|
export interface UseToolsetLoginParams {
|
|
@@ -72,6 +80,8 @@ export interface UseToolsetLoginParams {
|
|
|
72
80
|
export interface UseToolsetLoginResult {
|
|
73
81
|
/** Runs one API-key or OAuth login attempt and resolves its outcome. */
|
|
74
82
|
login: (params: ToolsetLoginParams) => Promise<ToolsetLoginOutcome>;
|
|
83
|
+
/** Creates a bulk sign-in run on this host's callback route, for `ToolsetLoginParams.batchSession`. */
|
|
84
|
+
createBatchSession: (options?: Omit<CreateToolsetOAuthBatchSessionOptions, 'callbackPath'>) => ToolsetOAuthBatchSession;
|
|
75
85
|
}
|
|
76
86
|
/**
|
|
77
87
|
* Shared toolset API-key/OAuth login orchestration, so no two surfaces fork
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToolsetLogin.d.ts","sourceRoot":"","sources":["../../../src/oauth/useToolsetLogin/useToolsetLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"useToolsetLogin.d.ts","sourceRoot":"","sources":["../../../src/oauth/useToolsetLogin/useToolsetLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EACL,KAAK,qCAAqC,EAE1C,KAAK,wBAAwB,EAE9B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAOtD,OAAO,EAGL,gBAAgB,EAChB,uBAAuB,EAIxB,MAAM,UAAU,CAAC;AAElB,kDAAkD;AAClD,oBAAY,uBAAuB;IACjC,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,YAAY,kBAAkB;IAC9B,SAAS,cAAc;IACvB,iGAAiG;IACjG,UAAU,gBAAgB;CAC3B;AAED,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,IAAI,EAAE,uBAAuB,CAAC;CAC/B;AAED,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,qDAAqD;IACrD,kBAAkB,EAAE,gBAAgB,CAAC;IACrC,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,wBAAwB,CAAC;CACzC;AAED,8CAA8C;AAC9C,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,YAAY,EAAE,CACZ,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,mBAAmB,KACtB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,0EAA0E;IAC1E,aAAa,EAAE,CACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,oBAAoB,KACvB,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,wFAAwF;IACxF,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC3D;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,KAAK,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACpE,uGAAuG;IACvG,kBAAkB,EAAE,CAClB,OAAO,CAAC,EAAE,IAAI,CAAC,qCAAqC,EAAE,cAAc,CAAC,KAClE,wBAAwB,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,sFAM7B,qBAAqB,KAAG,qBA4R1B,CAAC"}
|