@argent/x-shared 1.78.5 → 1.78.6

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"),u=require("./IHttpService.cjs");class w{constructor(o,e="json"){this.requestInit=o,this.responseType=e}async get(o,e,s){const n=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...n,...e,method:"GET",headers:{...n?.headers,...e?.headers}},t=await fetch(o,r).catch(async i=>{let c;throw i instanceof Response&&(c=await i.json().catch(()=>{})),new a.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_FETCH_URL,0,c)});if(this.responseType==="json"){if(!t.ok)throw new a.HttpError(t.statusText,t.status,await t.json().catch(()=>{}));const i=await t.json();if(s)try{return s.parse(i)}catch(c){throw new a.HttpError(c.message,0)}return i}return t}async post(o,e,s){const n=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...n,...e,method:"POST",headers:{...n?.headers,...e?.headers}},t=await fetch(o,r).catch(()=>{throw new a.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_POST_URL,0)});if(!t.ok)throw new a.HttpError(t.statusText,t.status,await t.json());if(t.status===204)return{};const i=await t.json();if(s)try{return s.parse(i)}catch(c){throw new a.HttpError(c.message,0)}return i}async put(o,e,s){const n=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,r={...n,...e,method:"PUT",headers:{...n?.headers,...e?.headers}},t=await fetch(o,r).catch(()=>{throw new a.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_PUT_URL,0)});if(!t.ok)throw new a.HttpError(t.statusText,t.status,await t.json().catch(()=>{}));if(t.status===204)return{};const i=await t.json();if(s)try{return s.parse(i)}catch(c){throw new a.HttpError(c.message,0)}return i}async delete(o,e){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,n={...s,...e,method:"DELETE",headers:{...s?.headers,...e?.headers}},r=await fetch(o,n).catch(()=>{throw new a.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_DELETE_URL,0)});if(!r.ok)throw new a.HttpError(r.statusText,r.status)}async patch(o,e){const s=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,n={...s,...e,method:"PATCH",headers:{...s?.headers,...e?.headers}},r=await fetch(o,n).catch(()=>{throw new a.HttpError("Failed to patch url",0)});if(!r.ok)throw new a.HttpError(r.statusText,r.status);return await r.json()}}exports.HTTPService=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("lodash-es"),n=require("./HttpError.cjs"),u=require("./IHttpService.cjs");class d{constructor(c,e="json"){this.requestInit=c,this.responseType=e}async get(c,e,r){const i=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,s={...i,...e,method:"GET",headers:{...i?.headers,...e?.headers}},t=await fetch(c,s).catch(async a=>{let o;throw a instanceof Response&&(o=await a.json().catch(()=>{})),new n.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_FETCH_URL,0,o)});if(this.responseType==="json"){if(!t.ok)throw new n.HttpError(t.statusText,t.status,await t.json().catch(()=>{}));const a=await t.json();if(r)try{return r.parse(a)}catch(o){throw new n.HttpError(o.message,0)}return a}return t}async post(c,e,r){const i=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,s={...i,...e,method:"POST",headers:{...i?.headers,...e?.headers}},t=await fetch(c,s).catch(()=>{throw new n.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_POST_URL,0)});if(!t.ok){const o=await t.json().catch(()=>{});throw new n.HttpError(t.statusText,t.status,o)}if(t.status===204)return{};const a=await t.json();if(r)try{return r.parse(a)}catch(o){throw new n.HttpError(o.message,0)}return a}async put(c,e,r){const i=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,s={...i,...e,method:"PUT",headers:{...i?.headers,...e?.headers}},t=await fetch(c,s).catch(()=>{throw new n.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_PUT_URL,0)});if(!t.ok)throw new n.HttpError(t.statusText,t.status,await t.json().catch(()=>{}));if(t.status===204)return{};const a=await t.json();if(r)try{return r.parse(a)}catch(o){throw new n.HttpError(o.message,0)}return a}async delete(c,e){const r=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,i={...r,...e,method:"DELETE",headers:{...r?.headers,...e?.headers}},s=await fetch(c,i).catch(()=>{throw new n.HttpError(u.HTTP_ERROR_MESSAGE.FAILED_TO_DELETE_URL,0)});if(!s.ok){const t=await s.json().catch(()=>{});throw new n.HttpError(s.statusText,s.status,t)}}async patch(c,e){const r=h.isFunction(this.requestInit)?await this.requestInit():this.requestInit,i={...r,...e,method:"PATCH",headers:{...r?.headers,...e?.headers}},s=await fetch(c,i).catch(()=>{throw new n.HttpError("Failed to patch url",0)});if(!s.ok){const a=await s.json().catch(()=>{});throw new n.HttpError(s.statusText,s.status,a)}return await s.json()}}exports.HTTPService=d;
@@ -1,124 +1,133 @@
1
- import { isFunction as c } from "lodash-es";
2
- import { HttpError as n } from "./HttpError.js";
1
+ import { isFunction as h } from "lodash-es";
2
+ import { HttpError as o } from "./HttpError.js";
3
3
  import { HTTP_ERROR_MESSAGE as u } from "./IHttpService.js";
4
4
  class p {
5
- constructor(o, e = "json") {
6
- this.requestInit = o, this.responseType = e;
5
+ constructor(c, e = "json") {
6
+ this.requestInit = c, this.responseType = e;
7
7
  }
8
- async get(o, e, s) {
9
- const r = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
10
- ...r,
8
+ async get(c, e, a) {
9
+ const i = h(this.requestInit) ? await this.requestInit() : this.requestInit, s = {
10
+ ...i,
11
11
  ...e,
12
12
  method: "GET",
13
13
  // merge headers
14
14
  headers: {
15
- ...r?.headers,
15
+ ...i?.headers,
16
16
  ...e?.headers
17
17
  }
18
- }, t = await fetch(o, a).catch(async (i) => {
19
- let h;
20
- throw i instanceof Response && (h = await i.json().catch(() => {
21
- })), new n(u.FAILED_TO_FETCH_URL, 0, h);
18
+ }, t = await fetch(c, s).catch(async (n) => {
19
+ let r;
20
+ throw n instanceof Response && (r = await n.json().catch(() => {
21
+ })), new o(u.FAILED_TO_FETCH_URL, 0, r);
22
22
  });
23
23
  if (this.responseType === "json") {
24
24
  if (!t.ok)
25
- throw new n(t.statusText, t.status, await t.json().catch(() => {
25
+ throw new o(t.statusText, t.status, await t.json().catch(() => {
26
26
  }));
27
- const i = await t.json();
28
- if (s)
27
+ const n = await t.json();
28
+ if (a)
29
29
  try {
30
- return s.parse(i);
31
- } catch (h) {
32
- throw new n(h.message, 0);
30
+ return a.parse(n);
31
+ } catch (r) {
32
+ throw new o(r.message, 0);
33
33
  }
34
- return i;
34
+ return n;
35
35
  }
36
36
  return t;
37
37
  }
38
- async post(o, e, s) {
39
- const r = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
40
- ...r,
38
+ async post(c, e, a) {
39
+ const i = h(this.requestInit) ? await this.requestInit() : this.requestInit, s = {
40
+ ...i,
41
41
  ...e,
42
42
  method: "POST",
43
43
  // merge headers
44
44
  headers: {
45
- ...r?.headers,
45
+ ...i?.headers,
46
46
  ...e?.headers
47
47
  }
48
- }, t = await fetch(o, a).catch(() => {
49
- throw new n(u.FAILED_TO_POST_URL, 0);
48
+ }, t = await fetch(c, s).catch(() => {
49
+ throw new o(u.FAILED_TO_POST_URL, 0);
50
50
  });
51
- if (!t.ok)
52
- throw new n(t.statusText, t.status, await t.json());
51
+ if (!t.ok) {
52
+ const r = await t.json().catch(() => {
53
+ });
54
+ throw new o(t.statusText, t.status, r);
55
+ }
53
56
  if (t.status === 204)
54
57
  return {};
55
- const i = await t.json();
56
- if (s)
58
+ const n = await t.json();
59
+ if (a)
57
60
  try {
58
- return s.parse(i);
59
- } catch (h) {
60
- throw new n(h.message, 0);
61
+ return a.parse(n);
62
+ } catch (r) {
63
+ throw new o(r.message, 0);
61
64
  }
62
- return i;
65
+ return n;
63
66
  }
64
- async put(o, e, s) {
65
- const r = c(this.requestInit) ? await this.requestInit() : this.requestInit, a = {
66
- ...r,
67
+ async put(c, e, a) {
68
+ const i = h(this.requestInit) ? await this.requestInit() : this.requestInit, s = {
69
+ ...i,
67
70
  ...e,
68
71
  method: "PUT",
69
72
  // merge headers
70
73
  headers: {
71
- ...r?.headers,
74
+ ...i?.headers,
72
75
  ...e?.headers
73
76
  }
74
- }, t = await fetch(o, a).catch(() => {
75
- throw new n(u.FAILED_TO_PUT_URL, 0);
77
+ }, t = await fetch(c, s).catch(() => {
78
+ throw new o(u.FAILED_TO_PUT_URL, 0);
76
79
  });
77
80
  if (!t.ok)
78
- throw new n(t.statusText, t.status, await t.json().catch(() => {
81
+ throw new o(t.statusText, t.status, await t.json().catch(() => {
79
82
  }));
80
83
  if (t.status === 204)
81
84
  return {};
82
- const i = await t.json();
83
- if (s)
85
+ const n = await t.json();
86
+ if (a)
84
87
  try {
85
- return s.parse(i);
86
- } catch (h) {
87
- throw new n(h.message, 0);
88
+ return a.parse(n);
89
+ } catch (r) {
90
+ throw new o(r.message, 0);
88
91
  }
89
- return i;
92
+ return n;
90
93
  }
91
- async delete(o, e) {
92
- const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, r = {
93
- ...s,
94
+ async delete(c, e) {
95
+ const a = h(this.requestInit) ? await this.requestInit() : this.requestInit, i = {
96
+ ...a,
94
97
  ...e,
95
98
  method: "DELETE",
96
99
  // merge headers
97
100
  headers: {
98
- ...s?.headers,
101
+ ...a?.headers,
99
102
  ...e?.headers
100
103
  }
101
- }, a = await fetch(o, r).catch(() => {
102
- throw new n(u.FAILED_TO_DELETE_URL, 0);
104
+ }, s = await fetch(c, i).catch(() => {
105
+ throw new o(u.FAILED_TO_DELETE_URL, 0);
103
106
  });
104
- if (!a.ok)
105
- throw new n(a.statusText, a.status);
107
+ if (!s.ok) {
108
+ const t = await s.json().catch(() => {
109
+ });
110
+ throw new o(s.statusText, s.status, t);
111
+ }
106
112
  }
107
- async patch(o, e) {
108
- const s = c(this.requestInit) ? await this.requestInit() : this.requestInit, r = {
109
- ...s,
113
+ async patch(c, e) {
114
+ const a = h(this.requestInit) ? await this.requestInit() : this.requestInit, i = {
115
+ ...a,
110
116
  ...e,
111
117
  method: "PATCH",
112
118
  headers: {
113
- ...s?.headers,
119
+ ...a?.headers,
114
120
  ...e?.headers
115
121
  }
116
- }, a = await fetch(o, r).catch(() => {
117
- throw new n("Failed to patch url", 0);
122
+ }, s = await fetch(c, i).catch(() => {
123
+ throw new o("Failed to patch url", 0);
118
124
  });
119
- if (!a.ok)
120
- throw new n(a.statusText, a.status);
121
- return await a.json();
125
+ if (!s.ok) {
126
+ const n = await s.json().catch(() => {
127
+ });
128
+ throw new o(s.statusText, s.status, n);
129
+ }
130
+ return await s.json();
122
131
  }
123
132
  }
124
133
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.78.5",
3
+ "version": "1.78.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"