@scalar/api-client 2.2.11 → 2.2.12

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,28 +1,28 @@
1
1
  import { ERRORS as v, normalizeError as B } from "../errors.js";
2
- import { normalizeHeaders as q } from "../normalize-headers.js";
2
+ import { normalizeHeaders as $ } from "../normalize-headers.js";
3
3
  import { replaceTemplateVariables as f } from "../string-template.js";
4
- import { canMethodHaveBody as A, isRelativePath as C, concatenateUrlAndPath as F, shouldUseProxy as U } from "@scalar/oas-utils/helpers";
4
+ import { canMethodHaveBody as q, isRelativePath as C, concatenateUrlAndPath as F, shouldUseProxy as U, REGEX as H } from "@scalar/oas-utils/helpers";
5
5
  import g from "js-cookie";
6
6
  import M from "whatwg-mimetype";
7
7
  import { textMediaTypes as z } from "../../views/Request/consts/mediaTypes.js";
8
- function H(n, o) {
8
+ function K(n, o) {
9
9
  const t = new M(o);
10
10
  return z.includes(t.essence) ? new TextDecoder(t.parameters.get("charset")).decode(n) : new Blob([n], { type: t.essence });
11
11
  }
12
- function K(n, o) {
12
+ function W(n, o) {
13
13
  const t = {};
14
14
  return n.parameters.headers.forEach((r) => {
15
15
  const h = r.key.trim().toLowerCase();
16
16
  r.enabled && (h !== "content-type" || r.value !== "multipart/form-data") && (t[h] = f(r.value, o));
17
17
  }), t;
18
18
  }
19
- function W(n, o) {
19
+ function j(n, o) {
20
20
  const t = new URLSearchParams();
21
21
  return n.parameters.query.forEach((r) => {
22
22
  r.enabled && r.value && t.append(r.key, f(r.value, o));
23
23
  }), t;
24
24
  }
25
- function j({
25
+ function N({
26
26
  example: n,
27
27
  env: o,
28
28
  globalCookies: t,
@@ -42,13 +42,13 @@ function j({
42
42
  sameSite: "None",
43
43
  // The Secure attribute must also be set when setting SameSite=None.
44
44
  secure: !0
45
- }, l = g.get();
46
- return Object.keys(l).forEach((a) => g.remove(a)), n.parameters.cookies.forEach((a) => {
45
+ }, y = g.get();
46
+ return Object.keys(y).forEach((a) => g.remove(a)), n.parameters.cookies.forEach((a) => {
47
47
  a.enabled && g.set(a.key, f(a.value, o));
48
48
  }), t.forEach((a) => {
49
- var y;
50
- const { name: c, value: E, ...p } = a;
51
- (p.domain === r || ((y = p.domain) == null ? void 0 : y.startsWith(".")) && r.endsWith(p.domain ?? "")) && g.set(c, E, {
49
+ var l;
50
+ const { name: c, value: k, ...p } = a;
51
+ (p.domain === r || ((l = p.domain) == null ? void 0 : l.startsWith(".")) && r.endsWith(p.domain ?? "")) && g.set(c, k, {
52
52
  /** Override the domain with the proxy value */
53
53
  domain: m,
54
54
  // TODO: path cookies probably don't worth with the proxy
@@ -61,15 +61,15 @@ function j({
61
61
  cookieParams: i
62
62
  };
63
63
  }
64
- function N(n, o, t) {
64
+ function Y(n, o, t) {
65
65
  var r, h, m;
66
- if (!A(n))
66
+ if (!q(n))
67
67
  return { body: void 0, contentType: void 0 };
68
68
  if (o.body.activeBody === "formData" && o.body.formData) {
69
- const i = o.body.formData.encoding === "form-data" ? "multipart/form-data" : "application/x-www-form-urlencoded", l = o.body.formData.encoding === "form-data" ? new FormData() : new URLSearchParams();
69
+ const i = o.body.formData.encoding === "form-data" ? "multipart/form-data" : "application/x-www-form-urlencoded", y = o.body.formData.encoding === "form-data" ? new FormData() : new URLSearchParams();
70
70
  return o.body.formData.value.forEach((a) => {
71
- !a.enabled || !a.key || (a.file && l instanceof FormData ? l.append(a.key, a.file, a.file.name) : a.value !== void 0 && l.append(a.key, f(a.value, t)));
72
- }), { body: l, contentType: i };
71
+ !a.enabled || !a.key || (a.file && y instanceof FormData ? y.append(a.key, a.file, a.file.name) : a.value !== void 0 && y.append(a.key, f(a.value, t)));
72
+ }), { body: y, contentType: i };
73
73
  }
74
74
  return o.body.activeBody === "raw" ? {
75
75
  body: f(((r = o.body.raw) == null ? void 0 : r.value) ?? "", t),
@@ -82,10 +82,10 @@ function N(n, o, t) {
82
82
  contentType: void 0
83
83
  };
84
84
  }
85
- function Y(n) {
86
- return n.startsWith("http://") || n.startsWith("https://") ? n : `http://${n}`;
85
+ function Q(n) {
86
+ return H.PATH.test(n) || n.startsWith("http://") || n.startsWith("https://") ? n : `http://${n}`;
87
87
  }
88
- const T = "YOUR_SECRET_TOKEN", ee = ({
88
+ const T = "YOUR_SECRET_TOKEN", oe = ({
89
89
  request: n,
90
90
  example: o,
91
91
  server: t,
@@ -93,18 +93,20 @@ const T = "YOUR_SECRET_TOKEN", ee = ({
93
93
  selectedSecuritySchemeUids: h = [],
94
94
  proxyUrl: m,
95
95
  status: i,
96
- environment: l,
96
+ environment: y,
97
97
  globalCookies: a
98
98
  }) => {
99
99
  try {
100
- const c = l ?? {}, E = new AbortController(), p = o.parameters.path.reduce((u, e) => (e.enabled && (u[e.key] = f(e.value, c)), u), {}), P = f((t == null ? void 0 : t.url) ?? "", c), y = f(n.path, p);
101
- let d = P || y;
100
+ const c = y ?? {}, k = new AbortController(), p = o.parameters.path.reduce((u, e) => (e.enabled && (u[e.key] = f(e.value, c)), u), {}), P = f((t == null ? void 0 : t.url) ?? "", c), l = f(n.path, p);
101
+ let d = P || l;
102
102
  if (!d) throw v.URL_EMPTY;
103
103
  Object.entries((t == null ? void 0 : t.variables) ?? {}).forEach(([u, e]) => {
104
- d = f(d, { [u]: e.default });
104
+ d = f(d, {
105
+ [u]: p[u] || e.default
106
+ });
105
107
  });
106
- const D = W(o, c), k = K(o, c), { body: O } = N(n.method, o, c);
107
- if (j({
108
+ const D = j(o, c), E = W(o, c), { body: O } = Y(n.method, o, c);
109
+ if (N({
108
110
  example: o,
109
111
  env: c,
110
112
  globalCookies: a,
@@ -116,33 +118,33 @@ const T = "YOUR_SECRET_TOKEN", ee = ({
116
118
  if (e) {
117
119
  if (e.type === "apiKey") {
118
120
  const s = f(e.value, c) || T;
119
- e.in === "header" && (k[e.name] = s), e.in === "query" && D.append(e.name, s), e.in === "cookie" && g.set(e.name, s);
121
+ e.in === "header" && (E[e.name] = s), e.in === "query" && D.append(e.name, s), e.in === "cookie" && g.set(e.name, s);
120
122
  }
121
123
  if (e.type === "http")
122
124
  if (e.scheme === "basic") {
123
125
  const s = f(e.username, c), b = f(e.password, c), R = `${s}:${b}`;
124
- k.Authorization = `Basic ${R === ":" ? "username:password" : btoa(R)}`;
126
+ E.Authorization = `Basic ${R === ":" ? "username:password" : btoa(R)}`;
125
127
  } else {
126
128
  const s = f(e.token, c);
127
- k.Authorization = `Bearer ${s || T}`;
129
+ E.Authorization = `Bearer ${s || T}`;
128
130
  }
129
131
  if (e.type === "oauth2") {
130
132
  const b = (w = Object.values(e.flows).find((R) => R.token)) == null ? void 0 : w.token;
131
- k.Authorization = `Bearer ${b || T}`;
133
+ E.Authorization = `Bearer ${b || T}`;
132
134
  }
133
135
  }
134
136
  }), d && (!C(d) || typeof window < "u")) {
135
- const u = C(d) ? F(window.location.origin, d) : Y(d), e = new URL(u), w = new URL(y, e.origin), s = new URL(e);
136
- t != null && t.url && (e.pathname === "/" ? s.pathname = y : s.pathname = e.pathname + y), s.search = new URLSearchParams([
137
+ const u = C(d) ? F(window.location.origin, d) : Q(d), e = new URL(u), w = new URL(l, e.origin), s = new URL(e);
138
+ t != null && t.url && (e.pathname === "/" ? s.pathname = l : s.pathname = e.pathname + l), s.search = new URLSearchParams([
137
139
  ...e.searchParams,
138
140
  ...w.searchParams,
139
141
  ...D
140
142
  ]).toString(), d = s.toString();
141
143
  }
142
- const S = new URLSearchParams([["scalar_url", d.toString()]]), _ = U(m, d) ? `${m}?${S.toString()}` : d, L = new Request(_, {
144
+ const S = new URLSearchParams([["scalar_url", d.toString()]]), A = U(m, d) ? `${m}?${S.toString()}` : d, L = new Request(A, {
143
145
  method: n.method.toUpperCase(),
144
146
  body: O,
145
- headers: k
147
+ headers: E
146
148
  });
147
149
  return [
148
150
  null,
@@ -153,13 +155,13 @@ const T = "YOUR_SECRET_TOKEN", ee = ({
153
155
  const u = Date.now();
154
156
  try {
155
157
  const e = await fetch(L, {
156
- signal: E.signal
158
+ signal: k.signal
157
159
  });
158
160
  i == null || i.emit("stop");
159
- const w = q(
161
+ const w = $(
160
162
  e.headers,
161
163
  U(m, d)
162
- ), s = e.headers.get("content-type") ?? "text/plain;charset=UTF-8", b = await e.arrayBuffer(), R = H(b, s), $ = "getSetCookie" in e.headers && typeof e.headers.getSetCookie == "function" ? e.headers.getSetCookie() : [];
164
+ ), s = e.headers.get("content-type") ?? "text/plain;charset=UTF-8", b = await e.arrayBuffer(), R = K(b, s), _ = "getSetCookie" in e.headers && typeof e.headers.getSetCookie == "function" ? e.headers.getSetCookie() : [];
163
165
  return [
164
166
  null,
165
167
  {
@@ -168,13 +170,13 @@ const T = "YOUR_SECRET_TOKEN", ee = ({
168
170
  response: {
169
171
  ...e,
170
172
  headers: w,
171
- cookieHeaderKeys: $,
173
+ cookieHeaderKeys: _,
172
174
  data: R,
173
175
  size: b.byteLength,
174
176
  duration: Date.now() - u,
175
177
  method: n.method,
176
178
  status: e.status,
177
- path: y
179
+ path: l
178
180
  }
179
181
  }
180
182
  ];
@@ -182,7 +184,7 @@ const T = "YOUR_SECRET_TOKEN", ee = ({
182
184
  return i == null || i.emit("abort"), [B(e, v.REQUEST_FAILED), null];
183
185
  }
184
186
  },
185
- controller: E
187
+ controller: k
186
188
  }
187
189
  ];
188
190
  } catch (c) {
@@ -190,10 +192,10 @@ const T = "YOUR_SECRET_TOKEN", ee = ({
190
192
  }
191
193
  };
192
194
  export {
193
- N as createFetchBody,
194
- K as createFetchHeaders,
195
- W as createFetchQueryParams,
196
- ee as createRequestOperation,
197
- H as decodeBuffer,
198
- j as setRequestCookies
195
+ Y as createFetchBody,
196
+ W as createFetchHeaders,
197
+ j as createFetchQueryParams,
198
+ oe as createRequestOperation,
199
+ K as decodeBuffer,
200
+ N as setRequestCookies
199
201
  };