@scalar/api-client 2.31.2 → 2.32.0

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,44 +1,49 @@
1
- import { isRelativePath as E } from "@scalar/helpers/url/is-relative-path";
2
- import { makeUrlAbsolute as b } from "@scalar/helpers/url/make-url-absolute";
3
- import { shouldUseProxy as S } from "@scalar/helpers/url/redirect-to-proxy";
4
- import { encode as z, fromUint8Array as C } from "js-base64";
5
- const A = (t) => {
6
- const e = t?.url;
7
- return e ? E(e) ? typeof window > "u" ? {} : { basePath: e } : { baseUrl: e } : {};
8
- }, F = () => {
1
+ import { isRelativePath as z } from "@scalar/helpers/url/is-relative-path";
2
+ import { makeUrlAbsolute as S } from "@scalar/helpers/url/make-url-absolute";
3
+ import { shouldUseProxy as F } from "@scalar/helpers/url/redirect-to-proxy";
4
+ import { encode as R, fromUint8Array as A } from "js-base64";
5
+ import { getServerUrl as E } from "../../operation-block/helpers/get-server-url.js";
6
+ const b = (t, e = {}) => {
7
+ const i = E(t, e);
8
+ return i ? z(i) ? typeof window > "u" ? {} : { basePath: i } : { baseUrl: i } : {};
9
+ }, $ = () => {
9
10
  const t = new Uint8Array(32);
10
- return crypto.getRandomValues(t), C(t, !0);
11
- }, R = async (t, e) => {
11
+ return crypto.getRandomValues(t), A(t, !0);
12
+ }, L = async (t, e) => {
12
13
  if (e === "plain")
13
14
  return t;
14
15
  if (typeof crypto?.subtle?.digest != "function")
15
16
  return console.warn("SHA-256 is only supported when using https, using a plain text code challenge instead."), t;
16
- const l = new TextEncoder().encode(t), f = await crypto.subtle.digest("SHA-256", l);
17
- return C(new Uint8Array(f), !0);
18
- }, W = async (t, e, g, l, f) => {
19
- const d = t[e];
17
+ const d = new TextEncoder().encode(t), m = await crypto.subtle.digest("SHA-256", d);
18
+ return A(new Uint8Array(m), !0);
19
+ }, q = async (t, e, i, d, m, g = {}) => {
20
+ const h = t[e];
20
21
  try {
21
- if (!d)
22
+ if (!h)
22
23
  return [new Error("Flow not found"), null];
23
- const m = g.join(" ");
24
+ const p = i.join(" ");
24
25
  if (e === "clientCredentials" || e === "password")
25
- return U(
26
+ return C(
26
27
  t,
27
28
  e,
28
- m,
29
+ p,
29
30
  {
30
- proxyUrl: f
31
+ proxyUrl: m
31
32
  },
32
- l
33
+ d,
34
+ g
33
35
  );
34
- const r = (Math.random() + 1).toString(36).substring(2, 10), a = b(t[e].authorizationUrl, A(l)), n = new URL(a);
36
+ const r = (Math.random() + 1).toString(36).substring(2, 10), a = S(
37
+ t[e].authorizationUrl,
38
+ b(d, g)
39
+ ), n = new URL(a);
35
40
  let c = null;
36
41
  if (e === "implicit")
37
42
  n.searchParams.set("response_type", "token");
38
43
  else if (e === "authorizationCode") {
39
44
  const s = t[e];
40
45
  if (n.searchParams.set("response_type", "code"), s["x-usePkce"] !== "no") {
41
- const o = F(), u = await R(o, s["x-usePkce"]);
46
+ const o = $(), u = await L(o, s["x-usePkce"]);
42
47
  c = {
43
48
  codeVerifier: o,
44
49
  codeChallenge: u,
@@ -46,76 +51,77 @@ const A = (t) => {
46
51
  }, n.searchParams.set("code_challenge", u), n.searchParams.set("code_challenge_method", c.codeChallengeMethod);
47
52
  }
48
53
  }
49
- const i = t[e];
50
- if (i["x-scalar-secret-redirect-uri"].startsWith("/")) {
51
- const s = l?.url || window.location.origin + window.location.pathname, o = new URL(i["x-scalar-secret-redirect-uri"], s).toString();
54
+ const l = t[e];
55
+ if (l["x-scalar-secret-redirect-uri"].startsWith("/")) {
56
+ const s = E(d, g) || window.location.origin + window.location.pathname, o = new URL(l["x-scalar-secret-redirect-uri"], s).toString();
52
57
  n.searchParams.set("redirect_uri", o);
53
58
  } else
54
- n.searchParams.set("redirect_uri", i["x-scalar-secret-redirect-uri"]);
55
- d["x-scalar-security-query"] && Object.keys(d["x-scalar-security-query"]).forEach((s) => {
56
- const o = d["x-scalar-security-query"]?.[s];
59
+ n.searchParams.set("redirect_uri", l["x-scalar-secret-redirect-uri"]);
60
+ h["x-scalar-security-query"] && Object.keys(h["x-scalar-security-query"]).forEach((s) => {
61
+ const o = h["x-scalar-security-query"]?.[s];
57
62
  o && n.searchParams.set(s, o);
58
- }), n.searchParams.set("client_id", d["x-scalar-secret-client-id"]), n.searchParams.set("state", r), m && n.searchParams.set("scope", m);
59
- const h = window.open(n, "openAuth2Window", "left=100,top=100,width=800,height=600");
60
- return h ? new Promise((s) => {
63
+ }), n.searchParams.set("client_id", h["x-scalar-secret-client-id"]), n.searchParams.set("state", r), p && n.searchParams.set("scope", p);
64
+ const w = window.open(n, "openAuth2Window", "left=100,top=100,width=800,height=600");
65
+ return w ? new Promise((s) => {
61
66
  const o = setInterval(() => {
62
- let u = null, p = null, x = null, _ = null;
67
+ let u = null, x = null, _ = null, P = null;
63
68
  try {
64
- const w = new URL(h.location.href).searchParams, k = d["x-tokenName"] || "access_token";
65
- u = w.get(k), p = w.get("code"), x = w.get("error"), _ = w.get("error_description");
66
- const P = new URLSearchParams(h.location.href.split("#")[1]);
67
- u ||= P.get(k), p ||= P.get("code"), x ||= P.get("error"), _ ||= P.get("error_description");
69
+ const f = new URL(w.location.href).searchParams, U = h["x-tokenName"] || "access_token";
70
+ u = f.get(U), x = f.get("code"), _ = f.get("error"), P = f.get("error_description");
71
+ const y = new URLSearchParams(w.location.href.split("#")[1]);
72
+ u ||= y.get(U), x ||= y.get("code"), _ ||= y.get("error"), P ||= y.get("error_description");
68
73
  } catch {
69
74
  }
70
- if (h.closed || u || p || x)
71
- if (clearInterval(o), h.close(), x)
72
- s([new Error(`OAuth error: ${x}${_ ? ` (${_})` : ""}`), null]);
75
+ if (w.closed || u || x || _)
76
+ if (clearInterval(o), w.close(), _)
77
+ s([new Error(`OAuth error: ${_}${P ? ` (${P})` : ""}`), null]);
73
78
  else if (u) {
74
- const w = h.location.href.match(/state=([^&]*)/)?.[1];
75
- s(w === r ? [null, u] : [new Error("State mismatch"), null]);
76
- } else p && e === "authorizationCode" ? new URL(h.location.href).searchParams.get("state") === r ? U(
79
+ const f = w.location.href.match(/state=([^&]*)/)?.[1];
80
+ s(f === r ? [null, u] : [new Error("State mismatch"), null]);
81
+ } else x && e === "authorizationCode" ? new URL(w.location.href).searchParams.get("state") === r ? C(
77
82
  t,
78
83
  e,
79
- m,
84
+ p,
80
85
  {
81
- code: p,
86
+ code: x,
82
87
  pkce: c,
83
- proxyUrl: f
88
+ proxyUrl: m
84
89
  },
85
- l
90
+ d,
91
+ g
86
92
  ).then(s) : s([new Error("State mismatch"), null]) : (clearInterval(o), s([new Error("Window was closed without granting authorization"), null]));
87
93
  }, 200);
88
94
  }) : [new Error("Failed to open auth window"), null];
89
95
  } catch {
90
96
  return [new Error("Failed to authorize oauth2 flow"), null];
91
97
  }
92
- }, U = async (t, e, g, {
93
- code: l,
94
- pkce: f,
95
- proxyUrl: d
96
- } = {}, m) => {
98
+ }, C = async (t, e, i, {
99
+ code: d,
100
+ pkce: m,
101
+ proxyUrl: g
102
+ } = {}, h, p = {}) => {
97
103
  const r = t[e];
98
104
  if (!r)
99
105
  return [new Error("OAuth2 flow was not defined"), null];
100
106
  const a = new URLSearchParams();
101
- g && (e === "clientCredentials" || e === "password") && a.set("scope", g);
107
+ i && (e === "clientCredentials" || e === "password") && a.set("scope", i);
102
108
  const n = r["x-scalar-credentials-location"] === "body";
103
- if (n && (a.set("client_id", r["x-scalar-secret-client-id"]), a.set("client_secret", r["x-scalar-secret-client-secret"])), "x-scalar-secret-redirect-uri" in r && r["x-scalar-secret-redirect-uri"] && a.set("redirect_uri", r["x-scalar-secret-redirect-uri"]), l)
104
- a.set("code", l), a.set("grant_type", "authorization_code"), f && a.set("code_verifier", f.codeVerifier);
109
+ if (n && (a.set("client_id", r["x-scalar-secret-client-id"]), a.set("client_secret", r["x-scalar-secret-client-secret"])), "x-scalar-secret-redirect-uri" in r && r["x-scalar-secret-redirect-uri"] && a.set("redirect_uri", r["x-scalar-secret-redirect-uri"]), d)
110
+ a.set("code", d), a.set("grant_type", "authorization_code"), m && a.set("code_verifier", m.codeVerifier);
105
111
  else if (e === "password") {
106
112
  const c = t[e];
107
113
  a.set("grant_type", "password"), a.set("username", c["x-scalar-secret-username"]), a.set("password", c["x-scalar-secret-password"]);
108
114
  } else
109
115
  a.set("grant_type", "client_credentials");
110
- r["x-scalar-security-body"] && Object.entries(r["x-scalar-security-body"]).forEach(([c, i]) => {
111
- i && a.set(c, i);
116
+ r["x-scalar-security-body"] && Object.entries(r["x-scalar-security-body"]).forEach(([c, l]) => {
117
+ l && a.set(c, l);
112
118
  });
113
119
  try {
114
120
  const c = {
115
121
  "Content-Type": "application/x-www-form-urlencoded"
116
122
  };
117
- n || (c.Authorization = `Basic ${z(`${r["x-scalar-secret-client-id"]}:${r["x-scalar-secret-client-secret"]}`)}`);
118
- const i = b(r.tokenUrl, A(m)), y = S(d, i) ? `${d}?${new URLSearchParams([["scalar_url", i]]).toString()}` : i, s = await (await fetch(y, {
123
+ n || (c.Authorization = `Basic ${R(`${r["x-scalar-secret-client-id"]}:${r["x-scalar-secret-client-secret"]}`)}`);
124
+ const l = S(r.tokenUrl, b(h, p)), k = F(g, l) ? `${g}?${new URLSearchParams([["scalar_url", l]]).toString()}` : l, s = await (await fetch(k, {
119
125
  method: "POST",
120
126
  headers: c,
121
127
  body: a
@@ -126,5 +132,5 @@ const A = (t) => {
126
132
  }
127
133
  };
128
134
  export {
129
- W as authorizeOauth2
135
+ q as authorizeOauth2
130
136
  };
@@ -81,7 +81,7 @@ const P = {
81
81
  )
82
82
  )), x = t(
83
83
  () => b(a(e.options)?.hiddenClients)
84
- ), g = "2.31.2";
84
+ ), g = "2.32.0";
85
85
  return (n, o) => e.path && e.method && e.exampleName && r.value ? (m(), C(c(V), {
86
86
  key: 0,
87
87
  activeEnvironment: e.workspaceStore.workspace["x-scalar-active-environment"],
@@ -33,7 +33,7 @@ const W = { class: "flex-center relative flex flex-1 flex-col gap-6 p-2 capitali
33
33
  }));
34
34
  }, f = (u) => {
35
35
  u?.createNew && g.name === "request" && p();
36
- }, v = "2.31.2";
36
+ }, v = "2.32.0";
37
37
  return q(() => a.hotKeys.on(f)), R(() => a.hotKeys.off(f)), (u, e) => (l(), n("div", W, [
38
38
  s("div", {
39
39
  class: y(["flex h-[calc(100%_-_50px)] flex-col items-center justify-center", {
@@ -9,6 +9,13 @@ type PKCEState = {
9
9
  codeChallenge: string;
10
10
  codeChallengeMethod: string;
11
11
  };
12
+ /**
13
+ * Interpolates server URL template variables (e.g. `https://{env}.example.com`)
14
+ * using the user-set `value` when available, falling back to the OpenAPI `default`.
15
+ * This is needed so OAuth flows that use the server URL as a base resolve correctly
16
+ * when the spec defines server variables.
17
+ */
18
+ export declare const getInterpolatedServerUrl: (activeServer?: Server) => string | undefined;
12
19
  /**
13
20
  * Creates a code challenge from the code verifier
14
21
  */
@@ -1 +1 @@
1
- {"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../../../../src/views/Request/libs/oauth2.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,qDAAqD;AACrD,KAAK,eAAe,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAA;AAEhE,KAAK,SAAS,GAAG;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,EAAE,MAAM,CAAA;CAC5B,CAAA;AA8BD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAU,UAAU,MAAM,EAAE,UAAU,SAAS,GAAG,OAAO,KAAG,OAAO,CAAC,MAAM,CAkB3G,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,UAAU;AAChB,wEAAwE;AACxE,cAAc,MAAM;AACpB,kCAAkC;AAClC,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CA0K/B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,eAAe,EACrB,QAAQ,MAAM,EACd,2BAIG;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,YAAK,EACN,cAAc,MAAM,GAAG,SAAS,KAC/B,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CA2F/B,CAAA"}
1
+ {"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../../../../src/views/Request/libs/oauth2.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AAGzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,qDAAqD;AACrD,KAAK,eAAe,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAA;AAEhE,KAAK,SAAS,GAAG;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,mBAAmB,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,eAAe,MAAM,KAAG,MAAM,GAAG,SAczE,CAAA;AA8BD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAU,UAAU,MAAM,EAAE,UAAU,SAAS,GAAG,OAAO,KAAG,OAAO,CAAC,MAAM,CAkB3G,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,UAAU;AAChB,wEAAwE;AACxE,cAAc,MAAM;AACpB,kCAAkC;AAClC,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CA0K/B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,eAAe,EACrB,QAAQ,MAAM,EACd,2BAIG;IACD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B,YAAK,EACN,cAAc,MAAM,GAAG,SAAS,KAC/B,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CA2F/B,CAAA"}
@@ -1,115 +1,127 @@
1
- import { isRelativePath as U } from "@scalar/helpers/url/is-relative-path";
1
+ import { replaceVariables as U } from "@scalar/helpers/regex/replace-variables";
2
+ import { isRelativePath as b } from "@scalar/helpers/url/is-relative-path";
2
3
  import { makeUrlAbsolute as x } from "@scalar/helpers/url/make-url-absolute";
3
- import { shouldUseProxy as f } from "@scalar/helpers/url/redirect-to-proxy";
4
- import { encode as A, fromUint8Array as k } from "js-base64";
5
- const w = (e) => {
6
- const a = e?.url;
7
- return a ? U(a) ? typeof window > "u" ? {} : { basePath: a } : { baseUrl: a } : {};
8
- }, b = () => {
4
+ import { shouldUseProxy as A } from "@scalar/helpers/url/redirect-to-proxy";
5
+ import { encode as E, fromUint8Array as k } from "js-base64";
6
+ const S = (e) => {
7
+ if (!e?.url) return;
8
+ const s = Object.entries(e.variables ?? {}).reduce(
9
+ (i, [a, c]) => {
10
+ const h = c.value || c.default;
11
+ return h && (i[a] = h), i;
12
+ },
13
+ {}
14
+ );
15
+ return U(e.url, s);
16
+ }, w = (e) => {
17
+ const s = S(e);
18
+ return s ? b(s) ? typeof window > "u" ? {} : { basePath: s } : { baseUrl: s } : {};
19
+ }, C = () => {
9
20
  const e = new Uint8Array(32);
10
21
  return crypto.getRandomValues(e), k(e, !0);
11
- }, E = async (e, a) => {
12
- if (a === "plain")
22
+ }, T = async (e, s) => {
23
+ if (s === "plain")
13
24
  return e;
14
25
  if (typeof crypto?.subtle?.digest != "function")
15
26
  return console.warn("SHA-256 is only supported when using https, using a plain text code challenge instead."), e;
16
- const c = new TextEncoder().encode(e), o = await crypto.subtle.digest("SHA-256", c);
17
- return k(new Uint8Array(o), !0);
18
- }, $ = async (e, a, u) => {
27
+ const a = new TextEncoder().encode(e), c = await crypto.subtle.digest("SHA-256", a);
28
+ return k(new Uint8Array(c), !0);
29
+ }, L = async (e, s, i) => {
19
30
  try {
20
31
  if (!e)
21
32
  return [new Error("Flow not found"), null];
22
- const c = e.selectedScopes.join(" ");
33
+ const a = e.selectedScopes.join(" ");
23
34
  if (e.type === "clientCredentials" || e.type === "password")
24
- return S(
35
+ return f(
25
36
  e,
26
- c,
37
+ a,
27
38
  {
28
- proxyUrl: u
39
+ proxyUrl: i
29
40
  },
30
- a
41
+ s
31
42
  );
32
- const o = (Math.random() + 1).toString(36).substring(2, 10), _ = x(e.authorizationUrl, w(a)), t = new URL(_);
33
- let y = null;
43
+ const c = (Math.random() + 1).toString(36).substring(2, 10), h = x(e.authorizationUrl, w(s)), t = new URL(h);
44
+ let g = null;
34
45
  if (e.type === "implicit")
35
46
  t.searchParams.set("response_type", "token");
36
47
  else if (e.type === "authorizationCode" && (t.searchParams.set("response_type", "code"), e["x-usePkce"] !== "no")) {
37
- const r = b(), s = await E(r, e["x-usePkce"]);
38
- y = {
48
+ const r = C(), n = await T(r, e["x-usePkce"]);
49
+ g = {
39
50
  codeVerifier: r,
40
- codeChallenge: s,
51
+ codeChallenge: n,
41
52
  codeChallengeMethod: e["x-usePkce"] === "SHA-256" ? "S256" : "plain"
42
- }, t.searchParams.set("code_challenge", s), t.searchParams.set("code_challenge_method", y.codeChallengeMethod);
53
+ }, t.searchParams.set("code_challenge", n), t.searchParams.set("code_challenge_method", g.codeChallengeMethod);
43
54
  }
44
55
  if (e["x-scalar-redirect-uri"].startsWith("/")) {
45
- const r = a?.url || window.location.origin + window.location.pathname, s = x(e["x-scalar-redirect-uri"], { baseUrl: r });
46
- t.searchParams.set("redirect_uri", s);
56
+ const r = S(s) || window.location.origin + window.location.pathname, n = x(e["x-scalar-redirect-uri"], { baseUrl: r });
57
+ t.searchParams.set("redirect_uri", n);
47
58
  } else
48
59
  t.searchParams.set("redirect_uri", e["x-scalar-redirect-uri"]);
49
60
  e["x-scalar-security-query"] && Object.keys(e["x-scalar-security-query"]).forEach((r) => {
50
- const s = e["x-scalar-security-query"]?.[r];
51
- s && t.searchParams.set(r, s);
52
- }), t.searchParams.set("client_id", e["x-scalar-client-id"]), t.searchParams.set("state", o), c && t.searchParams.set("scope", c);
53
- const n = window.open(t, "openAuth2Window", "left=100,top=100,width=800,height=600");
54
- return n ? new Promise((r) => {
55
- const s = setInterval(() => {
56
- let h = null, d = null, l = null, m = null;
61
+ const n = e["x-scalar-security-query"]?.[r];
62
+ n && t.searchParams.set(r, n);
63
+ }), t.searchParams.set("client_id", e["x-scalar-client-id"]), t.searchParams.set("state", c), a && t.searchParams.set("scope", a);
64
+ const o = window.open(t, "openAuth2Window", "left=100,top=100,width=800,height=600");
65
+ return o ? new Promise((r) => {
66
+ const n = setInterval(() => {
67
+ let p = null, d = null, u = null, y = null;
57
68
  try {
58
- const i = new URL(n.location.href).searchParams, P = e["x-tokenName"] || "access_token";
59
- h = i.get(P), d = i.get("code"), l = i.get("error"), m = i.get("error_description");
60
- const g = new URLSearchParams(n.location.href.split("#")[1]);
61
- h ||= g.get(P), d ||= g.get("code"), l ||= g.get("error"), m ||= g.get("error_description");
69
+ const l = new URL(o.location.href).searchParams, P = e["x-tokenName"] || "access_token";
70
+ p = l.get(P), d = l.get("code"), u = l.get("error"), y = l.get("error_description");
71
+ const _ = new URLSearchParams(o.location.href.split("#")[1]);
72
+ p ||= _.get(P), d ||= _.get("code"), u ||= _.get("error"), y ||= _.get("error_description");
62
73
  } catch {
63
74
  }
64
- if (n.closed || h || d || l)
65
- if (clearInterval(s), n.close(), l)
66
- r([new Error(`OAuth error: ${l}${m ? ` (${m})` : ""}`), null]);
67
- else if (h) {
68
- const i = n.location.href.match(/state=([^&]*)/)?.[1];
69
- r(i === o ? [null, h] : [new Error("State mismatch"), null]);
70
- } else d ? new URL(n.location.href).searchParams.get("state") === o ? S(
75
+ if (o.closed || p || d || u)
76
+ if (clearInterval(n), o.close(), u)
77
+ r([new Error(`OAuth error: ${u}${y ? ` (${y})` : ""}`), null]);
78
+ else if (p) {
79
+ const l = o.location.href.match(/state=([^&]*)/)?.[1];
80
+ r(l === c ? [null, p] : [new Error("State mismatch"), null]);
81
+ } else d ? new URL(o.location.href).searchParams.get("state") === c ? f(
71
82
  e,
72
- c,
83
+ a,
73
84
  {
74
85
  code: d,
75
- pkce: y,
76
- proxyUrl: u
86
+ pkce: g,
87
+ proxyUrl: i
77
88
  },
78
- a
79
- ).then(r) : r([new Error("State mismatch"), null]) : (clearInterval(s), r([new Error("Window was closed without granting authorization"), null]));
89
+ s
90
+ ).then(r) : r([new Error("State mismatch"), null]) : (clearInterval(n), r([new Error("Window was closed without granting authorization"), null]));
80
91
  }, 200);
81
92
  }) : [new Error("Failed to open auth window"), null];
82
93
  } catch {
83
94
  return [new Error("Failed to authorize oauth2 flow"), null];
84
95
  }
85
- }, S = async (e, a, {
86
- code: u,
87
- pkce: c,
88
- proxyUrl: o
89
- } = {}, _) => {
96
+ }, f = async (e, s, {
97
+ code: i,
98
+ pkce: a,
99
+ proxyUrl: c
100
+ } = {}, h) => {
90
101
  if (!e)
91
102
  return [new Error("OAuth2 flow was not defined"), null];
92
103
  const t = new URLSearchParams();
93
- t.set("client_id", e["x-scalar-client-id"]), a && (e.type === "clientCredentials" || e.type === "password") && t.set("scope", a), e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "body") && t.set("client_secret", e.clientSecret), "x-scalar-redirect-uri" in e && e["x-scalar-redirect-uri"] && t.set("redirect_uri", e["x-scalar-redirect-uri"]), u ? (t.set("code", u), t.set("grant_type", "authorization_code"), c && t.set("code_verifier", c.codeVerifier)) : e.type === "password" ? (t.set("grant_type", "password"), t.set("username", e.username), t.set("password", e.password)) : t.set("grant_type", "client_credentials"), e["x-scalar-security-body"] && Object.entries(e["x-scalar-security-body"]).forEach(([p, n]) => {
94
- n && t.set(p, n);
104
+ t.set("client_id", e["x-scalar-client-id"]), s && (e.type === "clientCredentials" || e.type === "password") && t.set("scope", s), e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "body") && t.set("client_secret", e.clientSecret), "x-scalar-redirect-uri" in e && e["x-scalar-redirect-uri"] && t.set("redirect_uri", e["x-scalar-redirect-uri"]), i ? (t.set("code", i), t.set("grant_type", "authorization_code"), a && t.set("code_verifier", a.codeVerifier)) : e.type === "password" ? (t.set("grant_type", "password"), t.set("username", e.username), t.set("password", e.password)) : t.set("grant_type", "client_credentials"), e["x-scalar-security-body"] && Object.entries(e["x-scalar-security-body"]).forEach(([m, o]) => {
105
+ o && t.set(m, o);
95
106
  });
96
107
  try {
97
- const p = {
108
+ const m = {
98
109
  "Content-Type": "application/x-www-form-urlencoded"
99
110
  };
100
- e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "header") && (p.Authorization = `Basic ${A(`${e["x-scalar-client-id"]}:${e.clientSecret}`)}`);
101
- const r = x(e.tokenUrl, w(_)), s = f(o, r) ? `${o}?${new URLSearchParams([["scalar_url", r]]).toString()}` : r, d = await (await fetch(s, {
111
+ e.clientSecret && (!e["x-scalar-credentials-location"] || e["x-scalar-credentials-location"] === "header") && (m.Authorization = `Basic ${E(`${e["x-scalar-client-id"]}:${e.clientSecret}`)}`);
112
+ const r = x(e.tokenUrl, w(h)), n = A(c, r) ? `${c}?${new URLSearchParams([["scalar_url", r]]).toString()}` : r, d = await (await fetch(n, {
102
113
  method: "POST",
103
- headers: p,
114
+ headers: m,
104
115
  body: t
105
- })).json(), l = e["x-tokenName"] || "access_token";
106
- return [null, d[l]];
116
+ })).json(), u = e["x-tokenName"] || "access_token";
117
+ return [null, d[u]];
107
118
  } catch {
108
119
  return [new Error("Failed to get an access token. Please check your credentials."), null];
109
120
  }
110
121
  };
111
122
  export {
112
- $ as authorizeOauth2,
113
- S as authorizeServers,
114
- E as generateCodeChallenge
123
+ L as authorizeOauth2,
124
+ f as authorizeServers,
125
+ T as generateCodeChallenge,
126
+ S as getInterpolatedServerUrl
115
127
  };
package/package.json CHANGED
@@ -18,9 +18,9 @@
18
18
  "rest",
19
19
  "testing"
20
20
  ],
21
- "version": "2.31.2",
21
+ "version": "2.32.0",
22
22
  "engines": {
23
- "node": ">=20"
23
+ "node": ">=22"
24
24
  },
25
25
  "type": "module",
26
26
  "main": "dist/index.js",
@@ -327,26 +327,26 @@
327
327
  "whatwg-mimetype": "4.0.0",
328
328
  "yaml": "^2.8.0",
329
329
  "zod": "^4.3.5",
330
- "@scalar/analytics-client": "1.0.1",
331
- "@scalar/components": "0.19.14",
332
- "@scalar/draggable": "0.3.0",
333
- "@scalar/helpers": "0.2.17",
334
- "@scalar/icons": "0.5.3",
335
- "@scalar/import": "0.4.54",
336
- "@scalar/oas-utils": "0.8.2",
337
- "@scalar/json-magic": "0.11.6",
338
- "@scalar/object-utils": "1.2.31",
339
- "@scalar/openapi-types": "0.5.3",
340
- "@scalar/openapi-parser": "0.24.16",
341
- "@scalar/postman-to-openapi": "0.4.9",
342
- "@scalar/sidebar": "0.7.45",
343
- "@scalar/snippetz": "0.6.18",
344
- "@scalar/types": "0.6.9",
345
- "@scalar/themes": "0.14.3",
346
- "@scalar/use-toasts": "0.9.1",
347
- "@scalar/use-hooks": "0.3.7",
348
- "@scalar/use-codemirror": "0.13.49",
349
- "@scalar/workspace-store": "0.35.2"
330
+ "@scalar/components": "0.20.0",
331
+ "@scalar/draggable": "0.4.0",
332
+ "@scalar/helpers": "0.3.0",
333
+ "@scalar/analytics-client": "1.1.0",
334
+ "@scalar/icons": "0.6.0",
335
+ "@scalar/import": "0.5.0",
336
+ "@scalar/json-magic": "0.12.0",
337
+ "@scalar/object-utils": "1.3.0",
338
+ "@scalar/openapi-parser": "0.25.0",
339
+ "@scalar/oas-utils": "0.9.0",
340
+ "@scalar/openapi-types": "0.6.0",
341
+ "@scalar/postman-to-openapi": "0.5.0",
342
+ "@scalar/sidebar": "0.8.0",
343
+ "@scalar/snippetz": "0.7.0",
344
+ "@scalar/themes": "0.15.0",
345
+ "@scalar/types": "0.7.0",
346
+ "@scalar/use-hooks": "0.4.0",
347
+ "@scalar/use-codemirror": "0.14.0",
348
+ "@scalar/workspace-store": "0.36.0",
349
+ "@scalar/use-toasts": "0.10.0"
350
350
  },
351
351
  "devDependencies": {
352
352
  "@tailwindcss/vite": "^4.1.18",
@@ -361,9 +361,9 @@
361
361
  "vite": "^7.3.1",
362
362
  "vite-svg-loader": "5.1.0",
363
363
  "vitest": "4.0.16",
364
- "@scalar/build-tooling": "0.4.1",
365
- "@scalar/galaxy": "0.5.16",
366
- "@scalar/pre-post-request-scripts": "0.2.8"
364
+ "@scalar/build-tooling": "0.5.0",
365
+ "@scalar/galaxy": "0.6.0",
366
+ "@scalar/pre-post-request-scripts": "0.3.0"
367
367
  },
368
368
  "scripts": {
369
369
  "build": "scalar-build-vite",