@scalar/api-client 2.1.13 → 2.1.15

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.
@@ -4,31 +4,31 @@ import { replaceTemplateVariables as u } from "./string-template.js";
4
4
  import { isRelativePath as E, shouldUseProxy as B, canMethodHaveBody as z } from "@scalar/oas-utils/helpers";
5
5
  import k from "js-cookie";
6
6
  import H from "whatwg-mimetype";
7
- import { requestStatusBus as v } from "./event-busses/request-status-bus.js";
7
+ import { requestStatusBus as S } from "./event-busses/request-status-bus.js";
8
8
  import { textMediaTypes as q } from "../views/Request/consts/mediaTypes.js";
9
- function K(s, n) {
9
+ function K(r, n) {
10
10
  const o = new H(n);
11
11
  if (q.includes(o.essence)) {
12
- const c = new TextDecoder(o.parameters.get("charset")).decode(s);
12
+ const c = new TextDecoder(o.parameters.get("charset")).decode(r);
13
13
  return o.subtype === "json" ? JSON.parse(c) : c;
14
14
  }
15
- return new Blob([s], { type: o.essence });
15
+ return new Blob([r], { type: o.essence });
16
16
  }
17
- function _(s, n) {
17
+ function _(r, n) {
18
18
  const o = {};
19
- return s.parameters.headers.forEach((t) => {
19
+ return r.parameters.headers.forEach((t) => {
20
20
  const c = t.key.trim().toLowerCase();
21
21
  t.enabled && (c !== "content-type" || t.value !== "multipart/form-data") && (o[c] = u(t.value, n));
22
22
  }), o;
23
23
  }
24
- function j(s, n) {
24
+ function j(r, n) {
25
25
  const o = new URLSearchParams();
26
- return s.parameters.query.forEach((t) => {
26
+ return r.parameters.query.forEach((t) => {
27
27
  t.enabled && t.value && o.append(t.key, u(t.value, n));
28
28
  }), o;
29
29
  }
30
30
  function N({
31
- example: s,
31
+ example: r,
32
32
  env: n,
33
33
  globalCookies: o,
34
34
  domain: t,
@@ -48,12 +48,12 @@ function N({
48
48
  // The Secure attribute must also be set when setting SameSite=None.
49
49
  secure: !0
50
50
  }, f = k.get();
51
- return Object.keys(f).forEach((e) => k.remove(e)), s.parameters.cookies.forEach((e) => {
51
+ return Object.keys(f).forEach((e) => k.remove(e)), r.parameters.cookies.forEach((e) => {
52
52
  e.enabled && k.set(e.key, u(e.value, n));
53
53
  }), o.forEach((e) => {
54
54
  var i;
55
- const { name: R, value: U, ...m } = e;
56
- (m.domain === t || ((i = m.domain) == null ? void 0 : i.startsWith(".")) && t.endsWith(m.domain ?? "")) && k.set(R, U, {
55
+ const { name: R, value: v, ...m } = e;
56
+ (m.domain === t || ((i = m.domain) == null ? void 0 : i.startsWith(".")) && t.endsWith(m.domain ?? "")) && k.set(R, v, {
57
57
  /** Override the domain with the proxy value */
58
58
  domain: d,
59
59
  // TODO: path cookies probably don't worth with the proxy
@@ -66,9 +66,9 @@ function N({
66
66
  cookieParams: l
67
67
  };
68
68
  }
69
- function Q(s, n, o) {
69
+ function Q(r, n, o) {
70
70
  var t, c, d;
71
- if (!z(s))
71
+ if (!z(r))
72
72
  return { body: void 0, contentType: void 0 };
73
73
  if (n.body.activeBody === "formData" && n.body.formData) {
74
74
  const l = n.body.formData.encoding === "form-data" ? "multipart/form-data" : "application/x-www-form-urlencoded", f = n.body.formData.encoding === "form-data" ? new FormData() : new URLSearchParams();
@@ -88,7 +88,7 @@ function Q(s, n, o) {
88
88
  };
89
89
  }
90
90
  const te = ({
91
- request: s,
91
+ request: r,
92
92
  auth: n,
93
93
  example: o,
94
94
  server: t,
@@ -98,30 +98,30 @@ const te = ({
98
98
  globalCookies: f
99
99
  }) => {
100
100
  try {
101
- const e = l ?? {}, R = new AbortController(), U = o.parameters.path.reduce((p, a) => (a.enabled && (p[a.key] = u(a.value, e)), p), {}), m = u((t == null ? void 0 : t.url) ?? "", e), y = u(s.path, U);
101
+ const e = l ?? {}, R = new AbortController(), v = o.parameters.path.reduce((p, a) => (a.enabled && (p[a.key] = u(a.value, e)), p), {}), m = u((t == null ? void 0 : t.url) ?? "", e), y = u(r.path, v);
102
102
  let i = m || y;
103
103
  if (!i) throw T.URL_EMPTY;
104
- const P = j(o, e), w = _(o, e), { body: C } = Q(s.method, o, e), { cookieParams: V } = N({
104
+ const P = j(o, e), w = _(o, e), { body: C } = Q(r.method, o, e), { cookieParams: V } = N({
105
105
  example: o,
106
106
  env: e,
107
107
  globalCookies: f,
108
108
  domain: i,
109
109
  proxy: d
110
110
  });
111
- return s.selectedSecuritySchemeUids.forEach((p) => {
111
+ return r.selectedSecuritySchemeUids.forEach((p) => {
112
112
  const a = n[p], h = c[p];
113
113
  if (!(!a || !h)) {
114
114
  if (h.type === "apiKey" && a.type === "apiKey") {
115
- const r = u(a.value, e);
116
- h.in === "header" && (w[a.name] = r), h.in === "query" && P.append(a.name, r), h.in === "cookie" && k.set(a.name, r);
115
+ const s = u(a.value, e);
116
+ h.in === "header" && (w[a.name] = s), h.in === "query" && P.append(a.name, s), h.in === "cookie" && k.set(a.name, s);
117
117
  }
118
118
  if (h.type === "http" && a.type === "http")
119
119
  if (h.scheme === "basic") {
120
- const r = u(a.username, e), g = u(a.password, e), D = g ? `${r}:${g}` : r;
120
+ const s = u(a.username, e), U = u(a.password, e), D = `${s}:${U}`;
121
121
  w.Authorization = `Basic ${btoa(D)}`;
122
122
  } else {
123
- const r = u(a.token, e);
124
- w.Authorization = `Bearer ${r}`;
123
+ const s = u(a.token, e);
124
+ w.Authorization = `Bearer ${s}`;
125
125
  }
126
126
  h.type === "oauth2" && a.type.includes("oauth") && "token" in a && (a.token || console.error("OAuth token was not created"), w.Authorization = `Bearer ${a.token}`);
127
127
  }
@@ -129,57 +129,57 @@ const te = ({
129
129
  null,
130
130
  {
131
131
  sendRequest: async () => {
132
- v.emit("start");
132
+ S.emit("start");
133
133
  const p = Date.now();
134
134
  try {
135
135
  if (i && (!E(i) || typeof window < "u")) {
136
- const O = E(i) ? window.location.origin + i : i, b = new URL(O), $ = new URL(y, b.origin), S = new URL(b);
137
- t != null && t.url && (b.pathname === "/" ? S.pathname = y : S.pathname = b.pathname + y), S.search = new URLSearchParams([
136
+ const O = E(i) ? window.location.origin + i : i, b = new URL(O), $ = new URL(y, b.origin), g = new URL(b);
137
+ t != null && t.url && (b.pathname === "/" ? g.pathname = y : g.pathname = b.pathname + y), g.search = new URLSearchParams([
138
138
  ...b.searchParams,
139
139
  ...$.searchParams,
140
140
  ...P
141
- ]).toString(), i = S.toString();
141
+ ]).toString(), i = g.toString();
142
142
  }
143
- const a = new URLSearchParams([["scalar_url", i.toString()]]), h = B(d, i) ? `${d}?${a.toString()}` : i, r = await fetch(h, {
143
+ const a = new URLSearchParams([["scalar_url", i.toString()]]), h = B(d, i) ? `${d}?${a.toString()}` : i, s = await fetch(h, {
144
144
  signal: R.signal,
145
- method: s.method.toUpperCase(),
145
+ method: r.method.toUpperCase(),
146
146
  body: C,
147
147
  headers: w
148
148
  });
149
- v.emit("stop");
150
- const g = M(
151
- r.headers,
149
+ S.emit("stop");
150
+ const U = M(
151
+ s.headers,
152
152
  B(d, i)
153
- ), D = r.headers.get("content-type") ?? "text/plain;charset=UTF-8", A = K(
154
- await r.arrayBuffer(),
153
+ ), D = s.headers.get("content-type") ?? "text/plain;charset=UTF-8", A = K(
154
+ await s.arrayBuffer(),
155
155
  D
156
- ), F = "getSetCookie" in r.headers && typeof r.headers.getSetCookie == "function" ? r.headers.getSetCookie() : [];
156
+ ), F = "getSetCookie" in s.headers && typeof s.headers.getSetCookie == "function" ? s.headers.getSetCookie() : [];
157
157
  return [
158
158
  null,
159
159
  {
160
160
  timestamp: Date.now(),
161
161
  request: o,
162
162
  response: {
163
- ...r,
164
- headers: g,
163
+ ...s,
164
+ headers: U,
165
165
  cookieHeaderKeys: F,
166
166
  data: A,
167
167
  duration: Date.now() - p,
168
- method: s.method,
169
- status: r.status,
168
+ method: r.method,
169
+ status: s.status,
170
170
  path: y
171
171
  }
172
172
  }
173
173
  ];
174
174
  } catch (a) {
175
- return v.emit("abort"), [L(a, T.REQUEST_FAILED), null];
175
+ return S.emit("abort"), [L(a, T.REQUEST_FAILED), null];
176
176
  }
177
177
  },
178
178
  controller: R
179
179
  }
180
180
  ];
181
181
  } catch (e) {
182
- return v.emit("abort"), [L(e), null];
182
+ return S.emit("abort"), [L(e), null];
183
183
  }
184
184
  };
185
185
  export {