@scalar/api-client 2.1.51 → 2.1.52

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/components/CommandPalette/CommandPaletteCollection.vue.js +1 -1
  3. package/dist/components/IconSelector.vue.js +2 -2
  4. package/dist/components/Sidebar/Sidebar.vue.d.ts.map +1 -1
  5. package/dist/components/Sidebar/Sidebar.vue.js +2 -2
  6. package/dist/components/Sidebar/Sidebar.vue2.js +37 -39
  7. package/dist/layouts/App/create-api-client-app.d.ts +1 -0
  8. package/dist/layouts/App/create-api-client-app.d.ts.map +1 -1
  9. package/dist/layouts/Modal/create-api-client-modal.d.ts +2 -0
  10. package/dist/layouts/Modal/create-api-client-modal.d.ts.map +1 -1
  11. package/dist/layouts/Web/create-api-client-web.d.ts +1 -0
  12. package/dist/layouts/Web/create-api-client-web.d.ts.map +1 -1
  13. package/dist/libs/create-client.d.ts +2 -0
  14. package/dist/libs/create-client.d.ts.map +1 -1
  15. package/dist/libs/create-client.js +102 -86
  16. package/dist/libs/send-request.d.ts +1 -4
  17. package/dist/libs/send-request.d.ts.map +1 -1
  18. package/dist/libs/send-request.js +107 -104
  19. package/dist/libs/string-template.d.ts.map +1 -1
  20. package/dist/libs/string-template.js +23 -22
  21. package/dist/style.css +1 -1
  22. package/dist/views/Request/Request.vue.js +1 -1
  23. package/dist/views/Request/Request.vue2.js +26 -26
  24. package/dist/views/Request/RequestSection/RequestTableTooltip.vue.d.ts.map +1 -1
  25. package/dist/views/Request/RequestSection/RequestTableTooltip.vue.js +27 -27
  26. package/dist/views/Request/RequestSidebar.vue.d.ts.map +1 -1
  27. package/dist/views/Request/RequestSidebar.vue.js +1 -1
  28. package/dist/views/Request/RequestSidebar.vue2.js +2 -2
  29. package/dist/views/Request/ResponseSection/ResponseBodyRaw.vue.d.ts.map +1 -1
  30. package/dist/views/Request/ResponseSection/ResponseBodyRaw.vue.js +2 -2
  31. package/dist/views/Request/ResponseSection/ResponseBodyRaw.vue2.js +35 -15
  32. package/dist/views/Request/ResponseSection/ResponseEmpty.vue2.js +1 -1
  33. package/package.json +9 -9
@@ -1,190 +1,193 @@
1
1
  import { ERRORS as B, normalizeError as C } from "./errors.js";
2
2
  import { normalizeHeaders as H } from "./normalize-headers.js";
3
- import { replaceTemplateVariables as f } from "./string-template.js";
4
- import { canMethodHaveBody as q, isRelativePath as S, shouldUseProxy as A } from "@scalar/oas-utils/helpers";
3
+ import { replaceTemplateVariables as h } from "./string-template.js";
4
+ import { canMethodHaveBody as q, isRelativePath as A, concatenateUrlAndPath as K, shouldUseProxy as S } from "@scalar/oas-utils/helpers";
5
5
  import g from "js-cookie";
6
- import K from "whatwg-mimetype";
6
+ import W from "whatwg-mimetype";
7
7
  import { textMediaTypes as _ } from "../views/Request/consts/mediaTypes.js";
8
- function j(c, t) {
9
- const n = new K(t);
10
- return _.includes(n.essence) ? new TextDecoder(n.parameters.get("charset")).decode(c) : new Blob([c], { type: n.essence });
8
+ function j(a, o) {
9
+ const n = new W(o);
10
+ return _.includes(n.essence) ? new TextDecoder(n.parameters.get("charset")).decode(a) : new Blob([a], { type: n.essence });
11
11
  }
12
- function Q(c, t) {
12
+ function Q(a, o) {
13
13
  const n = {};
14
- return c.parameters.headers.forEach((e) => {
15
- const p = e.key.trim().toLowerCase();
16
- e.enabled && (p !== "content-type" || e.value !== "multipart/form-data") && (n[p] = f(e.value, t));
14
+ return a.parameters.headers.forEach((e) => {
15
+ const m = e.key.trim().toLowerCase();
16
+ e.enabled && (m !== "content-type" || e.value !== "multipart/form-data") && (n[m] = h(e.value, o));
17
17
  }), n;
18
18
  }
19
- function V(c, t) {
19
+ function V(a, o) {
20
20
  const n = new URLSearchParams();
21
- return c.parameters.query.forEach((e) => {
22
- e.enabled && e.value && n.append(e.key, f(e.value, t));
21
+ return a.parameters.query.forEach((e) => {
22
+ e.enabled && e.value && n.append(e.key, h(e.value, o));
23
23
  }), n;
24
24
  }
25
- function W({
26
- example: c,
27
- env: t,
25
+ function I({
26
+ example: a,
27
+ env: o,
28
28
  globalCookies: n,
29
29
  domain: e,
30
- proxy: p
30
+ proxy: m
31
31
  }) {
32
- let h;
32
+ let f;
33
33
  try {
34
- h = new URL(p || e).host;
34
+ f = new URL(m || e).host;
35
35
  } catch {
36
- typeof window < "u" && (h = window.location.host);
36
+ typeof window < "u" && (f = window.location.host);
37
37
  }
38
- const u = {
38
+ const l = {
39
39
  // Must point all cookies to the proxy and let it sort them out
40
- domain: h,
40
+ domain: f,
41
41
  // Means that the browser sends the cookie with both cross-site and same-site requests.
42
42
  sameSite: "None",
43
43
  // The Secure attribute must also be set when setting SameSite=None.
44
44
  secure: !0
45
- }, r = g.get();
46
- return Object.keys(r).forEach((a) => g.remove(a)), c.parameters.cookies.forEach((a) => {
47
- a.enabled && g.set(a.key, f(a.value, t));
48
- }), n.forEach((a) => {
45
+ }, i = g.get();
46
+ return Object.keys(i).forEach((r) => g.remove(r)), a.parameters.cookies.forEach((r) => {
47
+ r.enabled && g.set(r.key, h(r.value, o));
48
+ }), n.forEach((r) => {
49
49
  var R;
50
- const { name: v, value: s, ...m } = a;
51
- (m.domain === e || ((R = m.domain) == null ? void 0 : R.startsWith(".")) && e.endsWith(m.domain ?? "")) && g.set(v, s, {
50
+ const { name: P, value: s, ...p } = r;
51
+ (p.domain === e || ((R = p.domain) == null ? void 0 : R.startsWith(".")) && e.endsWith(p.domain ?? "")) && g.set(P, s, {
52
52
  /** Override the domain with the proxy value */
53
- domain: h,
53
+ domain: f,
54
54
  // TODO: path cookies probably don't worth with the proxy
55
- path: m.path,
56
- expires: m.expires ? new Date(m.expires) : void 0,
57
- httpOnly: m.httpOnly,
58
- secure: m.secure
55
+ path: p.path,
56
+ expires: p.expires ? new Date(p.expires) : void 0,
57
+ httpOnly: p.httpOnly,
58
+ secure: p.secure
59
59
  });
60
60
  }), {
61
- cookieParams: u
61
+ cookieParams: l
62
62
  };
63
63
  }
64
- function I(c, t, n) {
65
- var e, p, h;
66
- if (!q(c))
64
+ function N(a, o, n) {
65
+ var e, m, f;
66
+ if (!q(a))
67
67
  return { body: void 0, contentType: void 0 };
68
- if (t.body.activeBody === "formData" && t.body.formData) {
69
- const u = t.body.formData.encoding === "form-data" ? "multipart/form-data" : "application/x-www-form-urlencoded", r = t.body.formData.encoding === "form-data" ? new FormData() : new URLSearchParams();
70
- return t.body.formData.value.forEach((a) => {
71
- !a.enabled || !a.key || (a.file && r instanceof FormData ? r.append(a.key, a.file, a.file.name) : a.value !== void 0 && r.append(a.key, f(a.value, n)));
72
- }), { body: r, contentType: u };
68
+ if (o.body.activeBody === "formData" && o.body.formData) {
69
+ const l = o.body.formData.encoding === "form-data" ? "multipart/form-data" : "application/x-www-form-urlencoded", i = o.body.formData.encoding === "form-data" ? new FormData() : new URLSearchParams();
70
+ return o.body.formData.value.forEach((r) => {
71
+ !r.enabled || !r.key || (r.file && i instanceof FormData ? i.append(r.key, r.file, r.file.name) : r.value !== void 0 && i.append(r.key, h(r.value, n)));
72
+ }), { body: i, contentType: l };
73
73
  }
74
- return t.body.activeBody === "raw" ? {
75
- body: f(((e = t.body.raw) == null ? void 0 : e.value) ?? "", n),
76
- contentType: (p = t.body.raw) == null ? void 0 : p.encoding
77
- } : t.body.activeBody === "binary" ? {
78
- body: t.body.binary,
79
- contentType: (h = t.body.binary) == null ? void 0 : h.type
74
+ return o.body.activeBody === "raw" ? {
75
+ body: h(((e = o.body.raw) == null ? void 0 : e.value) ?? "", n),
76
+ contentType: (m = o.body.raw) == null ? void 0 : m.encoding
77
+ } : o.body.activeBody === "binary" ? {
78
+ body: o.body.binary,
79
+ contentType: (f = o.body.binary) == null ? void 0 : f.type
80
80
  } : {
81
81
  body: void 0,
82
82
  contentType: void 0
83
83
  };
84
84
  }
85
- const oe = ({
86
- request: c,
87
- auth: t,
85
+ function Y(a) {
86
+ return a.startsWith("http://") || a.startsWith("https://") ? a : `http://${a}`;
87
+ }
88
+ const ne = ({
89
+ request: a,
90
+ auth: o,
88
91
  example: n,
89
92
  server: e,
90
- securitySchemes: p,
91
- selectedSecuritySchemeUids: h = [],
92
- proxy: u,
93
- status: r,
94
- environment: a,
95
- globalCookies: v
93
+ securitySchemes: m,
94
+ selectedSecuritySchemeUids: f = [],
95
+ proxy: l,
96
+ status: i,
97
+ environment: r,
98
+ globalCookies: P
96
99
  }) => {
97
100
  try {
98
- const s = a ?? {}, m = new AbortController(), E = n.parameters.path.reduce((l, o) => (o.enabled && (l[o.key] = f(o.value, s)), l), {}), R = f((e == null ? void 0 : e.url) ?? "", s), w = f(c.path, E);
101
+ const s = r ?? {}, p = new AbortController(), T = n.parameters.path.reduce((u, t) => (t.enabled && (u[t.key] = h(t.value, s)), u), {}), R = h((e == null ? void 0 : e.url) ?? "", s), w = h(a.path, T);
99
102
  let d = R || w;
100
103
  if (!d) throw B.URL_EMPTY;
101
- Object.entries((e == null ? void 0 : e.variables) ?? {}).forEach(([l, o]) => {
102
- d = f(d, { [l]: o.default });
104
+ Object.entries((e == null ? void 0 : e.variables) ?? {}).forEach(([u, t]) => {
105
+ d = h(d, { [u]: t.default });
103
106
  });
104
- const P = V(n, s), b = Q(n, s), { body: F } = I(c.method, n, s);
105
- return W({
107
+ const E = V(n, s), b = Q(n, s), { body: $ } = N(a.method, n, s);
108
+ return I({
106
109
  example: n,
107
110
  env: s,
108
- globalCookies: v,
111
+ globalCookies: P,
109
112
  domain: d,
110
- proxy: u
111
- }), h == null || h.forEach((l) => {
112
- const o = t[l], y = p[l];
113
- if (!(!o || !y)) {
114
- if (y.type === "apiKey" && o.type === "apiKey") {
115
- const i = f(o.value, s);
116
- y.in === "header" && (b[o.name] = i), y.in === "query" && P.append(o.name, i), y.in === "cookie" && g.set(o.name, i);
113
+ proxy: l
114
+ }), f == null || f.forEach((u) => {
115
+ const t = o[u], y = m[u];
116
+ if (!(!t || !y)) {
117
+ if (y.type === "apiKey" && t.type === "apiKey") {
118
+ const c = h(t.value, s);
119
+ y.in === "header" && (b[t.name] = c), y.in === "query" && E.append(t.name, c), y.in === "cookie" && g.set(t.name, c);
117
120
  }
118
- if (y.type === "http" && o.type === "http")
121
+ if (y.type === "http" && t.type === "http")
119
122
  if (y.scheme === "basic") {
120
- const i = f(o.username, s), L = f(o.password, s), T = `${i}:${L}`;
121
- b.Authorization = `Basic ${btoa(T)}`;
123
+ const c = h(t.username, s), v = h(t.password, s), L = `${c}:${v}`;
124
+ b.Authorization = `Basic ${btoa(L)}`;
122
125
  } else {
123
- const i = f(o.token, s);
124
- b.Authorization = `Bearer ${i}`;
126
+ const c = h(t.token, s);
127
+ b.Authorization = `Bearer ${c}`;
125
128
  }
126
- y.type === "oauth2" && o.type.includes("oauth") && "token" in o && (o.token || console.error("OAuth token was not created"), b.Authorization = `Bearer ${o.token}`);
129
+ y.type === "oauth2" && t.type.includes("oauth") && "token" in t && (t.token || console.error("OAuth token was not created"), b.Authorization = `Bearer ${t.token}`);
127
130
  }
128
131
  }), [
129
132
  null,
130
133
  {
131
134
  sendRequest: async () => {
132
- r == null || r.emit("start");
133
- const l = Date.now();
135
+ i == null || i.emit("start");
136
+ const u = Date.now();
134
137
  try {
135
- if (d && (!S(d) || typeof window < "u")) {
136
- const z = S(d) ? window.location.origin + d : d, k = new URL(z), M = new URL(w, k.origin), D = new URL(k);
138
+ if (d && (!A(d) || typeof window < "u")) {
139
+ const z = A(d) ? K(window.location.origin, d) : Y(d), k = new URL(z), M = new URL(w, k.origin), D = new URL(k);
137
140
  e != null && e.url && (k.pathname === "/" ? D.pathname = w : D.pathname = k.pathname + w), D.search = new URLSearchParams([
138
141
  ...k.searchParams,
139
142
  ...M.searchParams,
140
- ...P
143
+ ...E
141
144
  ]).toString(), d = D.toString();
142
145
  }
143
- const o = new URLSearchParams([["scalar_url", d.toString()]]), y = A(u, d) ? `${u}?${o.toString()}` : d, i = await fetch(y, {
144
- signal: m.signal,
145
- method: c.method.toUpperCase(),
146
- body: F,
146
+ const t = new URLSearchParams([["scalar_url", d.toString()]]), y = S(l, d) ? `${l}?${t.toString()}` : d, c = await fetch(y, {
147
+ signal: p.signal,
148
+ method: a.method.toUpperCase(),
149
+ body: $,
147
150
  headers: b
148
151
  });
149
- r == null || r.emit("stop");
150
- const L = H(
151
- i.headers,
152
- A(u, d)
153
- ), T = i.headers.get("content-type") ?? "text/plain;charset=UTF-8", U = await i.arrayBuffer(), O = j(U, T), $ = "getSetCookie" in i.headers && typeof i.headers.getSetCookie == "function" ? i.headers.getSetCookie() : [];
152
+ i == null || i.emit("stop");
153
+ const v = H(
154
+ c.headers,
155
+ S(l, d)
156
+ ), L = c.headers.get("content-type") ?? "text/plain;charset=UTF-8", U = await c.arrayBuffer(), F = j(U, L), O = "getSetCookie" in c.headers && typeof c.headers.getSetCookie == "function" ? c.headers.getSetCookie() : [];
154
157
  return [
155
158
  null,
156
159
  {
157
160
  timestamp: Date.now(),
158
161
  request: n,
159
162
  response: {
160
- ...i,
161
- headers: L,
162
- cookieHeaderKeys: $,
163
- data: O,
163
+ ...c,
164
+ headers: v,
165
+ cookieHeaderKeys: O,
166
+ data: F,
164
167
  size: U.byteLength,
165
- duration: Date.now() - l,
166
- method: c.method,
167
- status: i.status,
168
+ duration: Date.now() - u,
169
+ method: a.method,
170
+ status: c.status,
168
171
  path: w
169
172
  }
170
173
  }
171
174
  ];
172
- } catch (o) {
173
- return r == null || r.emit("abort"), [C(o, B.REQUEST_FAILED), null];
175
+ } catch (t) {
176
+ return i == null || i.emit("abort"), [C(t, B.REQUEST_FAILED), null];
174
177
  }
175
178
  },
176
- controller: m
179
+ controller: p
177
180
  }
178
181
  ];
179
182
  } catch (s) {
180
- return r == null || r.emit("abort"), [C(s), null];
183
+ return i == null || i.emit("abort"), [C(s), null];
181
184
  }
182
185
  };
183
186
  export {
184
- I as createFetchBody,
187
+ N as createFetchBody,
185
188
  Q as createFetchHeaders,
186
189
  V as createFetchQueryParams,
187
- oe as createRequestOperation,
190
+ ne as createRequestOperation,
188
191
  j as decodeBuffer,
189
- W as setRequestCookies
192
+ I as setRequestCookies
190
193
  };
@@ -1 +1 @@
1
- {"version":3,"file":"string-template.d.ts","sourceRoot":"","sources":["../../src/libs/string-template.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAQ5D;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,UAkBhB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,sBAoBjD"}
1
+ {"version":3,"file":"string-template.d.ts","sourceRoot":"","sources":["../../src/libs/string-template.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAQ5D;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,UAehB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,sBAoBjD"}
@@ -1,30 +1,31 @@
1
- function l(n, a) {
2
- const s = n.split(".").reduce(
3
- (e, t) => e == null ? void 0 : e[t],
4
- a
1
+ import { REGEX as u } from "@scalar/oas-utils/helpers";
2
+ function l(n, o) {
3
+ const t = n.split(".").reduce(
4
+ (e, c) => e == null ? void 0 : e[c],
5
+ o
5
6
  );
6
- return typeof s == "string" ? s : JSON.stringify(s);
7
+ return typeof t == "string" ? t : JSON.stringify(t);
7
8
  }
8
- function u(n, a) {
9
- const c = /{{\s*([^}\s]+?)\s*}}|{\s*([^}\s]+?)\s*}|:\b[\w.]+\b/g, s = n.match(c) ?? [];
10
- let e = n;
11
- return s.forEach((t) => {
12
- const r = t.startsWith(":") ? t.slice(1) : t.replace(/[{}]/g, "").trim(), o = l(r, a);
13
- o != null && (e = e.replaceAll(t, o));
14
- }), e;
9
+ function f(n, o) {
10
+ const r = n.match(u.TEMPLATE_VARIABLE) ?? [];
11
+ let t = n;
12
+ return r.forEach((e) => {
13
+ const c = e.startsWith(":") ? e.slice(1) : e.replace(/[{}]/g, "").trim(), s = l(c, o);
14
+ s != null && (t = t.replaceAll(e, s));
15
+ }), t;
15
16
  }
16
- function i(n) {
17
- function a(c, s) {
18
- const e = Object.keys(c), t = [];
19
- return e.forEach((r) => {
20
- const o = s ? `${s}.${r}` : r;
21
- typeof c[r] == "object" ? t.push(...a(c[r], o)) : t.push([o, String(c[r])]);
22
- }), t;
17
+ function p(n) {
18
+ function o(r, t) {
19
+ const e = Object.keys(r), c = [];
20
+ return e.forEach((s) => {
21
+ const a = t ? `${t}.${s}` : s;
22
+ typeof r[s] == "object" ? c.push(...o(r[s], a)) : c.push([a, String(r[s])]);
23
+ }), c;
23
24
  }
24
- return a(n);
25
+ return o(n);
25
26
  }
26
27
  export {
27
- i as flattenEnvVars,
28
+ p as flattenEnvVars,
28
29
  l as getDotPathValue,
29
- u as replaceTemplateVariables
30
+ f as replaceTemplateVariables
30
31
  };