@argent/x-shared 1.53.2 → 1.54.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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("lodash-es"),a=require("./HttpError.cjs"),d=require("./IHttpService.cjs");class w{constructor(o,t="json"){this.requestInit=o,this.responseType=t}async get(o,t){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"GET",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(o,r).catch(()=>{throw new a.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_FETCH_URL,0)});if(this.responseType==="json"){if(!e.ok)throw new a.HttpError(e.statusText,e.status);return await e.json()}return e}async post(o,t,s){const r=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,e={...r,...t,method:"POST",headers:{...r==null?void 0:r.headers,...t==null?void 0:t.headers}},n=await fetch(o,e).catch(()=>{throw new a.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_POST_URL,0)});if(!n.ok)throw new a.HttpError(n.statusText,n.status,await n.json());if(n.status===204)return{};const c=await n.json();if(s)try{return s.parse(c)}catch(i){throw new a.HttpError(i.message,0)}return c}async put(o,t){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"PUT",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(o,r).catch(()=>{throw new a.HttpError("Failed to put url",0)});if(!e.ok)throw new a.HttpError(e.statusText,e.status);return await e.json()}async delete(o,t){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"DELETE",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(o,r).catch(()=>{throw new a.HttpError("Failed to delete url",0)});if(!e.ok)throw new a.HttpError(e.statusText,e.status)}}exports.HTTPService=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es"),n=require("./HttpError.cjs"),d=require("./IHttpService.cjs");class w{constructor(a,t="json"){this.requestInit=a,this.responseType=t}async get(a,t){const s=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"GET",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(a,r).catch(async o=>{let c;throw o instanceof Response&&(c=await o.json().catch(()=>{})),new n.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_FETCH_URL,0,c)});if(this.responseType==="json"){if(!e.ok)throw new n.HttpError(e.statusText,e.status,await e.json().catch(()=>{}));return await e.json()}return e}async post(a,t,s){const r=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,e={...r,...t,method:"POST",headers:{...r==null?void 0:r.headers,...t==null?void 0:t.headers}},o=await fetch(a,e).catch(()=>{throw new n.HttpError(d.HTTP_ERROR_MESSAGE.FAILED_TO_POST_URL,0)});if(!o.ok)throw new n.HttpError(o.statusText,o.status,await o.json());if(o.status===204)return{};const c=await o.json();if(s)try{return s.parse(c)}catch(h){throw new n.HttpError(h.message,0)}return c}async put(a,t){const s=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"PUT",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(a,r).catch(()=>{throw new n.HttpError("Failed to put url",0)});if(!e.ok)throw new n.HttpError(e.statusText,e.status);return await e.json()}async delete(a,t){const s=i.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...s,...t,method:"DELETE",headers:{...s==null?void 0:s.headers,...t==null?void 0:t.headers}},e=await fetch(a,r).catch(()=>{throw new n.HttpError("Failed to delete url",0)});if(!e.ok)throw new n.HttpError(e.statusText,e.status)}}exports.HTTPService=w;
@@ -1,12 +1,12 @@
1
- import { isFunction as n } from "lodash-es";
2
- import { HttpError as r } from "./HttpError.js";
1
+ import { isFunction as c } from "lodash-es";
2
+ import { HttpError as h } from "./HttpError.js";
3
3
  import { HTTP_ERROR_MESSAGE as w } from "./IHttpService.js";
4
4
  class m {
5
- constructor(o, t = "json") {
6
- this.requestInit = o, this.responseType = t;
5
+ constructor(r, t = "json") {
6
+ this.requestInit = r, this.responseType = t;
7
7
  }
8
- async get(o, t) {
9
- const s = n(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
8
+ async get(r, t) {
9
+ const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
10
10
  ...s,
11
11
  ...t,
12
12
  method: "GET",
@@ -15,18 +15,21 @@ class m {
15
15
  ...s == null ? void 0 : s.headers,
16
16
  ...t == null ? void 0 : t.headers
17
17
  }
18
- }, e = await fetch(o, a).catch(() => {
19
- throw new r(w.FAILED_TO_FETCH_URL, 0);
18
+ }, e = await fetch(r, a).catch(async (o) => {
19
+ let n;
20
+ throw o instanceof Response && (n = await o.json().catch(() => {
21
+ })), new h(w.FAILED_TO_FETCH_URL, 0, n);
20
22
  });
21
23
  if (this.responseType === "json") {
22
24
  if (!e.ok)
23
- throw new r(e.statusText, e.status);
25
+ throw new h(e.statusText, e.status, await e.json().catch(() => {
26
+ }));
24
27
  return await e.json();
25
28
  }
26
29
  return e;
27
30
  }
28
- async post(o, t, s) {
29
- const a = n(this.requestInit) ? await this.requestInit() : this.requestInit, e = {
31
+ async post(r, t, s) {
32
+ const a = c(this.requestInit) ? await this.requestInit() : this.requestInit, e = {
30
33
  ...a,
31
34
  ...t,
32
35
  method: "POST",
@@ -35,24 +38,24 @@ class m {
35
38
  ...a == null ? void 0 : a.headers,
36
39
  ...t == null ? void 0 : t.headers
37
40
  }
38
- }, h = await fetch(o, e).catch(() => {
39
- throw new r(w.FAILED_TO_POST_URL, 0);
41
+ }, o = await fetch(r, e).catch(() => {
42
+ throw new h(w.FAILED_TO_POST_URL, 0);
40
43
  });
41
- if (!h.ok)
42
- throw new r(h.statusText, h.status, await h.json());
43
- if (h.status === 204)
44
+ if (!o.ok)
45
+ throw new h(o.statusText, o.status, await o.json());
46
+ if (o.status === 204)
44
47
  return {};
45
- const c = await h.json();
48
+ const n = await o.json();
46
49
  if (s)
47
50
  try {
48
- return s.parse(c);
51
+ return s.parse(n);
49
52
  } catch (i) {
50
- throw new r(i.message, 0);
53
+ throw new h(i.message, 0);
51
54
  }
52
- return c;
55
+ return n;
53
56
  }
54
- async put(o, t) {
55
- const s = n(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
57
+ async put(r, t) {
58
+ const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
56
59
  ...s,
57
60
  ...t,
58
61
  method: "PUT",
@@ -61,15 +64,15 @@ class m {
61
64
  ...s == null ? void 0 : s.headers,
62
65
  ...t == null ? void 0 : t.headers
63
66
  }
64
- }, e = await fetch(o, a).catch(() => {
65
- throw new r("Failed to put url", 0);
67
+ }, e = await fetch(r, a).catch(() => {
68
+ throw new h("Failed to put url", 0);
66
69
  });
67
70
  if (!e.ok)
68
- throw new r(e.statusText, e.status);
71
+ throw new h(e.statusText, e.status);
69
72
  return await e.json();
70
73
  }
71
- async delete(o, t) {
72
- const s = n(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
74
+ async delete(r, t) {
75
+ const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
73
76
  ...s,
74
77
  ...t,
75
78
  method: "DELETE",
@@ -78,11 +81,11 @@ class m {
78
81
  ...s == null ? void 0 : s.headers,
79
82
  ...t == null ? void 0 : t.headers
80
83
  }
81
- }, e = await fetch(o, a).catch(() => {
82
- throw new r("Failed to delete url", 0);
84
+ }, e = await fetch(r, a).catch(() => {
85
+ throw new h("Failed to delete url", 0);
83
86
  });
84
87
  if (!e.ok)
85
- throw new r(e.statusText, e.status);
88
+ throw new h(e.statusText, e.status);
86
89
  }
87
90
  }
88
91
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.53.2",
3
+ "version": "1.54.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"
@@ -44,26 +44,26 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@amplitude/analytics-types": "2.8.4",
47
- "@commitlint/cli": "19.6.0",
47
+ "@commitlint/cli": "19.6.1",
48
48
  "@commitlint/config-conventional": "19.6.0",
49
- "@rollup/plugin-typescript": "12.1.1",
49
+ "@rollup/plugin-typescript": "12.1.2",
50
50
  "@semantic-release/git": "10.0.1",
51
51
  "@types/async-retry": "1.4.9",
52
52
  "@types/lodash-es": "4.17.12",
53
53
  "@types/ua-parser-js": "0.7.39",
54
- "@typescript-eslint/eslint-plugin": "8.16.0",
55
- "@typescript-eslint/parser": "8.16.0",
54
+ "@typescript-eslint/eslint-plugin": "8.18.0",
55
+ "@typescript-eslint/parser": "8.18.0",
56
56
  "eslint": "8.57.1",
57
57
  "eslint-config-prettier": "9.1.0",
58
58
  "eslint-plugin-import": "2.31.0",
59
59
  "husky": "9.1.7",
60
- "lint-staged": "15.2.10",
61
- "msw": "2.6.6",
62
- "prettier": "3.4.1",
60
+ "lint-staged": "15.2.11",
61
+ "msw": "2.6.8",
62
+ "prettier": "3.4.2",
63
63
  "semantic-release": "24.2.0",
64
64
  "ts-to-zod": "3.15.0",
65
65
  "typescript": "5.7.2",
66
- "vite": "6.0.2",
66
+ "vite": "6.0.3",
67
67
  "vite-plugin-dts": "4.3.0",
68
68
  "vitest": "2.1.8"
69
69
  },