@epam/ai-dial-chat-hooks 1.3.0-dev.296 → 1.3.0-dev.304

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.
@@ -1,88 +1,79 @@
1
- import { OAuthResourceKind as e, ToolsetAuthTypes as t, ToolsetCredentialsLevel as n, ToolsetOAuthInitiationResultType as r, ToolsetOAuthResultType as i, WithLogin as a } from "../oauth/types.js";
2
- import { waitForToolsetOAuthResult as o } from "../oauth/handshake.js";
3
- import { navigateToolsetOAuthPopup as s, openToolsetOAuthPopup as c } from "../oauth/popup.js";
4
- import { OfflineCredentialsLoginOutcomeType as l } from "../offline-credentials/useOfflineCredentialsLogin/useOfflineCredentialsLogin.js";
5
- import { buildExternalServiceScopeId as u } from "../shared/external-services.js";
6
- import { useCallback as d } from "react";
1
+ import { OAuthResourceKind as e, ToolsetCredentialsLevel as t, ToolsetOAuthInitiationResultType as n, ToolsetOAuthResultType as r } from "../oauth/types.js";
2
+ import { waitForToolsetOAuthResult as i } from "../oauth/handshake.js";
3
+ import { navigateToolsetOAuthPopup as a, openToolsetOAuthPopup as o } from "../oauth/popup.js";
4
+ import { OfflineCredentialsLoginOutcomeType as s } from "../offline-credentials/useOfflineCredentialsLogin/useOfflineCredentialsLogin.js";
5
+ import { buildExternalServiceScopeId as c } from "../shared/external-services.js";
6
+ import { useCallback as l } from "react";
7
7
  //#region src/external-services/useExternalServiceLogin.ts
8
- var f = /* @__PURE__ */ function(e) {
8
+ var u = /* @__PURE__ */ function(e) {
9
9
  return e.None = "NONE", e.ApiKey = "API_KEY", e.OAuth = "OAUTH", e.DialNative = "DIAL_NATIVE", e;
10
- }({}), p = /* @__PURE__ */ function(e) {
10
+ }({}), d = /* @__PURE__ */ function(e) {
11
11
  return e.SignedIn = "SIGNED_IN", e.SignedOut = "SIGNED_OUT", e.Failed = "FAILED", e;
12
- }({}), m = /* @__PURE__ */ function(e) {
12
+ }({}), f = /* @__PURE__ */ function(e) {
13
13
  return e.Global = "GLOBAL", e.Application = "APPLICATION", e.User = "USER", e;
14
- }({}), h = /* @__PURE__ */ function(e) {
14
+ }({}), p = /* @__PURE__ */ function(e) {
15
15
  return e.Success = "success", e.Failure = "failure", e.PopupBlocked = "popup-blocked", e.Cancelled = "cancelled", e.AdminConsentRequired = "admin-consent-required", e.OfflineUnavailable = "offline-unavailable", e;
16
- }({}), g = (e) => e === "GLOBAL" ? n.Global : n.User, _ = ({ callbackPath: n, getExternalService: f, signInExternalService: p, signOutExternalService: m, getOfflineCredentials: h, loginOfflineCredentials: _ }) => {
17
- let v = d(async ({ appId: e, serviceId: t, popup: n }) => {
18
- let r = n ?? c();
16
+ }({}), m = (e) => e === "GLOBAL" ? t.Global : t.User, h = ({ callbackPath: t, getExternalService: u, signInExternalService: d, signOutExternalService: f, getOfflineCredentials: p, loginOfflineCredentials: h }) => {
17
+ let g = l(async ({ appId: e, serviceId: t, popup: n }) => {
18
+ let r = n ?? o();
19
19
  if (!r) return { type: "popup-blocked" };
20
20
  try {
21
- let n = await f(e, t);
21
+ let n = await u(e, t);
22
22
  if (n.appLevelAuthStatus !== "SIGNED_IN") return r.close(), { type: n.appLevelAuthStatus === "SIGNED_OUT" ? "admin-consent-required" : "failure" };
23
- let i = await h();
23
+ let i = await p();
24
24
  if (i.connected) return r.close(), { type: "success" };
25
25
  if (!i.available || !i.connect) return r.close(), { type: "offline-unavailable" };
26
- let a = await _(i.connect, h, r);
27
- if (a.type === l.Success) {
28
- let n = await f(e, t);
26
+ let a = await h(i.connect, p, r);
27
+ if (a.type === s.Success) {
28
+ let n = await u(e, t);
29
29
  return { type: n.appLevelAuthStatus === "SIGNED_IN" ? "success" : n.appLevelAuthStatus === "SIGNED_OUT" ? "admin-consent-required" : "failure" };
30
30
  }
31
- return a.type === l.Cancelled ? { type: "cancelled" } : { type: "failure" };
31
+ return a.type === s.Cancelled ? { type: "cancelled" } : { type: "failure" };
32
32
  } catch {
33
33
  return r.close(), { type: "failure" };
34
34
  }
35
35
  }, [
36
- _,
37
- f,
38
- h
39
- ]), y = d(async (e, t, n, r) => {
36
+ h,
37
+ u,
38
+ p
39
+ ]), _ = l(async (e, t, n, r) => {
40
40
  try {
41
- await m(e, t, {
41
+ await f(e, t, {
42
42
  credentialsLevel: n,
43
43
  authenticationType: r
44
44
  });
45
45
  } catch {}
46
- }, [m]), b = d(async (l) => {
47
- let { appId: d, serviceId: p, credentialsLevel: m, oauthSettings: h, forceStale: _, offlineUsageConsent: v, popup: b } = l, x = u(d, p), S = g(m), C = {
48
- authenticationType: t.OAuth,
49
- withLogin: a.WithConfig,
50
- isLoggedIn: !1,
51
- clientId: h?.clientId,
52
- authorizationEndpoint: h?.authorizationEndpoint,
53
- scopes: h?.scopes,
54
- codeChallenge: h?.codeChallenge,
55
- codeChallengeMethod: h?.codeChallengeMethod
56
- }, w = b ?? c();
57
- if (!w) return { type: "popup-blocked" };
58
- _ && await y(d, p, m, "OAUTH");
46
+ }, [f]), v = l(async (s) => {
47
+ let { appId: l, serviceId: d, credentialsLevel: f, oauthSettings: p, forceStale: h, offlineUsageConsent: g, popup: v } = s, y = c(l, d), b = m(f), x = v ?? o();
48
+ if (!x) return { type: "popup-blocked" };
49
+ h && await _(l, d, f, "OAUTH");
59
50
  try {
60
- let t = s(w, C, x, n, S, e.ExternalService, v);
61
- if (t.type !== r.Started) return { type: "failure" };
62
- let a = await o(t.popup, t.flowId, {
63
- toolsetId: x,
64
- credentialsLevel: S,
65
- callbackPath: n
51
+ let o = a(x, p ?? {}, y, t, b, e.ExternalService, g);
52
+ if (o.type !== n.Started) return { type: "failure" };
53
+ let s = await i(o.popup, o.flowId, {
54
+ toolsetId: y,
55
+ credentialsLevel: b,
56
+ callbackPath: t
66
57
  });
67
- if (a.type === i.Success) return { type: "success" };
68
- if (a.type === i.Failure) return { type: "failure" };
58
+ if (s.type === r.Success) return { type: "success" };
59
+ if (s.type === r.Failure) return { type: "failure" };
69
60
  try {
70
- let e = await f(d, p);
71
- if ((m === "USER" ? e.userLevelAuthStatus : e.globalAuthStatus) === "SIGNED_IN") return { type: "success" };
61
+ let e = await u(l, d);
62
+ if ((f === "USER" ? e.userLevelAuthStatus : e.globalAuthStatus) === "SIGNED_IN") return { type: "success" };
72
63
  } catch {}
73
64
  return { type: "cancelled" };
74
65
  } catch {
75
- return w.close(), { type: "failure" };
66
+ return x.close(), { type: "failure" };
76
67
  }
77
68
  }, [
78
- y,
79
- n,
80
- f
81
- ]), x = d(async (e) => {
69
+ _,
70
+ t,
71
+ u
72
+ ]), y = l(async (e) => {
82
73
  let { appId: t, serviceId: n, credentialsLevel: r, authenticationType: i, apiKey: a, forceStale: o, offlineUsageConsent: s } = e;
83
74
  if (i === "DIAL_NATIVE") return { type: "failure" };
84
75
  try {
85
- return o && await y(t, n, r, i), await p(t, n, {
76
+ return o && await _(t, n, r, i), await d(t, n, {
86
77
  credentialsLevel: r,
87
78
  authenticationType: i,
88
79
  apiKey: a?.trim(),
@@ -91,12 +82,12 @@ var f = /* @__PURE__ */ function(e) {
91
82
  } catch {
92
83
  return { type: "failure" };
93
84
  }
94
- }, [y, p]);
95
- return { login: d((e) => e.authenticationType === "DIAL_NATIVE" ? v(e) : e.authenticationType === "OAUTH" ? b(e) : x(e), [
85
+ }, [_, d]);
86
+ return { login: l((e) => e.authenticationType === "DIAL_NATIVE" ? g(e) : e.authenticationType === "OAUTH" ? v(e) : y(e), [
87
+ g,
96
88
  v,
97
- b,
98
- x
89
+ y
99
90
  ]) };
100
91
  };
101
92
  //#endregion
102
- export { p as ExternalServiceAuthStatus, f as ExternalServiceAuthType, m as ExternalServiceCredentialsLevel, h as ExternalServiceLoginOutcomeType, _ as useExternalServiceLogin };
93
+ export { d as ExternalServiceAuthStatus, u as ExternalServiceAuthType, f as ExternalServiceCredentialsLevel, p as ExternalServiceLoginOutcomeType, h as useExternalServiceLogin };