@prosopo/api 3.5.18 → 3.5.20

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,11 +1,11 @@
1
1
  import { HttpClientBase } from "./HttpClientBase.js";
2
- class ApiClient extends HttpClientBase {
3
- constructor(baseUrl, account) {
4
- const baseUrlWithProtocol = !baseUrl.startsWith("http") ? `https://${baseUrl}` : baseUrl;
5
- super(baseUrlWithProtocol);
6
- this.account = account;
7
- }
8
- }
9
- export {
10
- ApiClient
2
+ //#region src/api/apiClient.ts
3
+ var ApiClient = class extends HttpClientBase {
4
+ constructor(baseUrl, account) {
5
+ const baseUrlWithProtocol = !baseUrl.startsWith("http") ? `https://${baseUrl}` : baseUrl;
6
+ super(baseUrlWithProtocol);
7
+ this.account = account;
8
+ }
11
9
  };
10
+ //#endregion
11
+ export { ApiClient };
package/dist/api/index.js CHANGED
@@ -1,11 +1,5 @@
1
- import { HttpClientBase } from "./HttpClientBase.js";
2
1
  import { HttpError } from "./HttpError.js";
3
- import { default as default2, VERIFY_FORWARDED_HEADER } from "./ProviderApi.js";
2
+ import { HttpClientBase } from "./HttpClientBase.js";
4
3
  import { ApiClient } from "./apiClient.js";
5
- export {
6
- ApiClient,
7
- HttpClientBase,
8
- HttpError,
9
- default2 as ProviderApi,
10
- VERIFY_FORWARDED_HEADER
11
- };
4
+ import ProviderApi, { VERIFY_FORWARDED_HEADER } from "./ProviderApi.js";
5
+ export { ApiClient, HttpClientBase, HttpError, ProviderApi, VERIFY_FORWARDED_HEADER };
@@ -1,83 +1,71 @@
1
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const HttpError = require("./HttpError.cjs");
4
- class HttpClientBase {
5
- constructor(baseURL, prefix = "") {
6
- this.baseURL = baseURL + prefix;
7
- }
8
- async fetch(input, init) {
9
- try {
10
- const response = await fetch(this.baseURL + input, init);
11
- if (!response.ok && // Only throw an error if the response is not JSON and not a 400 error
12
- response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) {
13
- throw new HttpError.HttpError(response.status, response.statusText, response.url);
14
- }
15
- return this.responseHandler(response);
16
- } catch (error) {
17
- return this.errorHandler(error);
18
- }
19
- }
20
- async post(input, body, init) {
21
- const headers = {
22
- "Content-Type": "application/json",
23
- ...init?.headers || {}
24
- };
25
- try {
26
- const response = await fetch(this.baseURL + input, {
27
- method: "POST",
28
- body: JSON.stringify(body),
29
- ...init,
30
- headers
31
- });
32
- if (!response.ok && // Only throw an error if the response is not JSON and not a 400 error
33
- response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) {
34
- throw new HttpError.HttpError(response.status, response.statusText, response.url);
35
- }
36
- return this.responseHandler(response);
37
- } catch (error) {
38
- return this.errorHandler(error);
39
- }
40
- }
41
- // Like `post`, but also surfaces the response Headers so callers can read
42
- // values delivered out-of-band (e.g. the honeypot meta header). The body
43
- // is still parsed as JSON.
44
- async postWithHeaders(input, body, init) {
45
- const headers = {
46
- "Content-Type": "application/json",
47
- ...init?.headers || {}
48
- };
49
- try {
50
- const response = await fetch(this.baseURL + input, {
51
- method: "POST",
52
- body: JSON.stringify(body),
53
- ...init,
54
- headers
55
- });
56
- if (!response.ok && response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) {
57
- throw new HttpError.HttpError(response.status, response.statusText, response.url);
58
- }
59
- const data = await this.responseHandler(response);
60
- return { data, headers: response.headers };
61
- } catch (error) {
62
- return this.errorHandler(error);
63
- }
64
- }
65
- async responseHandler(response) {
66
- try {
67
- return await response.json();
68
- } catch (error) {
69
- console.error("Error parsing JSON:", error);
70
- throw error;
71
- }
72
- }
73
- errorHandler(error) {
74
- if (error instanceof HttpError.HttpError) {
75
- console.error("HTTP error:", error);
76
- } else {
77
- console.error("API request error:", error);
78
- }
79
- return Promise.reject(error);
80
- }
81
- }
1
+ const require_HttpError = require("./HttpError.cjs");
2
+ //#region src/api/HttpClientBase.ts
3
+ var HttpClientBase = class {
4
+ constructor(baseURL, prefix = "") {
5
+ this.baseURL = baseURL + prefix;
6
+ }
7
+ async fetch(input, init) {
8
+ try {
9
+ const response = await fetch(this.baseURL + input, init);
10
+ if (!response.ok && response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) throw new require_HttpError.HttpError(response.status, response.statusText, response.url);
11
+ return this.responseHandler(response);
12
+ } catch (error) {
13
+ return this.errorHandler(error);
14
+ }
15
+ }
16
+ async post(input, body, init) {
17
+ const headers = {
18
+ "Content-Type": "application/json",
19
+ ...init?.headers || {}
20
+ };
21
+ try {
22
+ const response = await fetch(this.baseURL + input, {
23
+ method: "POST",
24
+ body: JSON.stringify(body),
25
+ ...init,
26
+ headers
27
+ });
28
+ if (!response.ok && response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) throw new require_HttpError.HttpError(response.status, response.statusText, response.url);
29
+ return this.responseHandler(response);
30
+ } catch (error) {
31
+ return this.errorHandler(error);
32
+ }
33
+ }
34
+ async postWithHeaders(input, body, init) {
35
+ const headers = {
36
+ "Content-Type": "application/json",
37
+ ...init?.headers || {}
38
+ };
39
+ try {
40
+ const response = await fetch(this.baseURL + input, {
41
+ method: "POST",
42
+ body: JSON.stringify(body),
43
+ ...init,
44
+ headers
45
+ });
46
+ if (!response.ok && response.status !== 400 && !response.headers.get("content-type")?.includes("application/json")) throw new require_HttpError.HttpError(response.status, response.statusText, response.url);
47
+ return {
48
+ data: await this.responseHandler(response),
49
+ headers: response.headers
50
+ };
51
+ } catch (error) {
52
+ return this.errorHandler(error);
53
+ }
54
+ }
55
+ async responseHandler(response) {
56
+ try {
57
+ return await response.json();
58
+ } catch (error) {
59
+ console.error("Error parsing JSON:", error);
60
+ throw error;
61
+ }
62
+ }
63
+ errorHandler(error) {
64
+ if (error instanceof require_HttpError.HttpError) console.error("HTTP error:", error);
65
+ else console.error("API request error:", error);
66
+ return Promise.reject(error);
67
+ }
68
+ };
69
+ //#endregion
82
70
  exports.HttpClientBase = HttpClientBase;
83
71
  exports.default = HttpClientBase;
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- class HttpError extends Error {
4
- constructor(status, statusText, url) {
5
- super(`HTTP error! status: ${status} (${statusText}) for URL: ${url}`);
6
- this.status = status;
7
- this.statusText = statusText;
8
- this.url = url;
9
- this.name = "HttpError";
10
- }
11
- }
1
+ //#region src/api/HttpError.ts
2
+ var HttpError = class extends Error {
3
+ constructor(status, statusText, url) {
4
+ super(`HTTP error! status: ${status} (${statusText}) for URL: ${url}`);
5
+ this.status = status;
6
+ this.statusText = statusText;
7
+ this.url = url;
8
+ this.name = "HttpError";
9
+ }
10
+ };
11
+ //#endregion
12
12
  exports.HttpError = HttpError;