@gardenfi/orderbook 2.2.1-beta.1 → 2.2.1

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.
package/dist/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),l=require("./index6.cjs");class h{constructor(n){this.Url=n}async createOrder(n,o){const e=await o.getAuthHeaders();if(e.error)return r.Err(e.error);try{const t=await r.Fetcher.post(this.Url.endpoint("/relayer").endpoint("create-order"),{body:JSON.stringify(n),headers:{...e.val,"Content-Type":"application/json"}});return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("CreateOrder: Unexpected error, result is undefined")}catch(t){return r.Err("CreateOrder Err:",String(t))}}async getOrder(n,o){const e=o?`/id/${n}/matched`:`/id/${n}/unmatched`,t=this.Url.endpoint("orders").endpoint(e);try{const s=await r.Fetcher.get(t);return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(s){return r.Err("GetOrder:",String(s))}}async getMatchedOrders(n,o,e){const t=l.ConstructUrl(this.Url.endpoint("orders"),`/user/${n}/matched`,{...e,status:o});try{const s=await r.Fetcher.get(t);return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(s){return r.Err("GetMatchedOrders:",String(s))}}async getUnMatchedOrders(n,o){const e=l.ConstructUrl(this.Url.endpoint("orders"),`/user/${n}/unmatched`,o);try{const t=await r.Fetcher.get(e);return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(t){return r.Err("GetUnMatchedOrders:",String(t))}}async getOrders(n,o,e,t,s,u){const a=n?"/matched":"/unmatched",d={};o&&(d.page=o.page,d.per_page=o.per_page),e&&(d.address=e),t&&(d.tx_hash=t),s&&(d.from_chain=s),u&&(d.to_chain=u);const i=l.ConstructUrl(this.Url.endpoint("orders"),a,d);try{const c=await r.Fetcher.get(i);return c.error?r.Err(c.error):c.result?r.Ok(c.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(c){return r.Err("GetAllOrders:",String(c))}}async subscribeOrders(n,o,e,t,s="all",u){let a=!1;const d=async()=>{if(!a){a=!0;try{const c=o?await this.getMatchedOrders(n,s,u):await this.getUnMatchedOrders(n,u);c.ok?await t(c.val):console.error("Error fetching orders:",c.error)}catch(c){console.error("Error fetching orders:",c)}finally{a=!1}}};await d();const i=setInterval(d,e);return()=>{clearInterval(i)}}async getOrdersCount(n){const o=this.Url.endpoint("orders").endpoint(`/user/${n}/count`);try{const e=await r.Fetcher.get(o);return e.error?r.Err(e.error):e.status===r.ApiStatus.Ok&&e.result!==void 0?r.Ok(e.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrdersCount:",String(e))}}}exports.Orderbook=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index6.cjs"),h=require("@gardenfi/utils"),l=require("./index7.cjs");class O{constructor(n){this.Url=n}async createOrder(n,o){const e=await o.getAuthHeaders();if(e.error)return r.Err(e.error);try{const t=await r.Fetcher.post(this.Url.endpoint("/relayer").endpoint("create-order"),{body:JSON.stringify(n),headers:{...e.val,"Content-Type":"application/json"}});return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("CreateOrder: Unexpected error, result is undefined")}catch(t){return r.Err("CreateOrder Err:",String(t))}}async getOrder(n,o){const e=o?`/id/${n}/matched`:`/id/${n}/unmatched`,t=this.Url.endpoint("orders").endpoint(e);try{const s=await r.Fetcher.get(t);return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(s){return r.Err("GetOrder:",String(s))}}async getMatchedOrders(n,o,e){const t=l.ConstructUrl(this.Url.endpoint("orders"),`/user/${n}/matched`,{...e,status:o});try{const s=await r.Fetcher.get(t);return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(s){return r.Err("GetMatchedOrders:",String(s))}}async getUnMatchedOrders(n,o){const e=l.ConstructUrl(this.Url.endpoint("orders"),`/user/${n}/unmatched`,o);try{const t=await r.Fetcher.get(e);return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(t){return r.Err("GetUnMatchedOrders:",String(t))}}async getOrders(n,o,e,t,s,i){const u=n?"/matched":"/unmatched",d={};o&&(d.page=o.page,d.per_page=o.per_page),e&&(d.address=e),t&&(d.tx_hash=t),s&&(d.from_chain=s),i&&(d.to_chain=i);const a=l.ConstructUrl(this.Url.endpoint("orders"),u,d);try{const c=await r.Fetcher.get(a);return c.error?r.Err(c.error):c.result?r.Ok(c.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(c){return r.Err("GetAllOrders:",String(c))}}async subscribeOrders(n,o,e,t,s="all",i){let u=!1;const d=async()=>{if(!u){u=!0;try{const c=o?await this.getMatchedOrders(n,s,i):await this.getUnMatchedOrders(n,i);c.ok?await t(c.val):console.error("Error fetching orders:",c.error)}catch(c){console.error("Error fetching orders:",c)}finally{u=!1}}};await d();const a=setInterval(d,e);return()=>{clearInterval(a)}}async getOrdersCount(n){const o=this.Url.endpoint("orders").endpoint(`/user/${n}/count`);try{const e=await r.Fetcher.get(o);return e.error?r.Err(e.error):e.status===h.ApiStatus.Ok&&e.result!==void 0?r.Ok(e.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrdersCount:",String(e))}}}exports.Orderbook=O;
package/dist/index2.js CHANGED
@@ -1,6 +1,7 @@
1
- import { Err as t, Fetcher as a, Ok as i, ApiStatus as f } from "@gardenfi/utils";
2
- import { ConstructUrl as p } from "./index6.js";
3
- class U {
1
+ import { Err as t, Fetcher as a, Ok as i } from "./index6.js";
2
+ import { ApiStatus as f } from "@gardenfi/utils";
3
+ import { ConstructUrl as p } from "./index7.js";
4
+ class m {
4
5
  constructor(n) {
5
6
  this.Url = n;
6
7
  }
@@ -117,5 +118,5 @@ class U {
117
118
  }
118
119
  }
119
120
  export {
120
- U as Orderbook
121
+ m as Orderbook
121
122
  };
package/dist/index4.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),d=require("./index6.cjs");class h{constructor(s){this.url=new r.Url("/orders",s)}async getOrder(s,c){const t=c?`/id/matched/${s}`:`/id/unmatched/${s}`,n=this.url.endpoint(t);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrder:",String(e))}}async getMatchedOrders(s,c,t){const n=d.ConstructUrl(this.url,`/user/matched/${s}`,{...t,pending:c});try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetMatchedOrders:",String(e))}}async getUnMatchedOrders(s,c){const t=d.ConstructUrl(this.url,`/user/unmatched/${s}`,c);try{const n=await r.Fetcher.get(t);return n.error?r.Err(n.error):n.result?r.Ok(n.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(n){return r.Err("GetUnMatchedOrders:",String(n))}}async getOrders(s,c){const t=s?"/matched":"/unmatched",n=d.ConstructUrl(this.url,t,c);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetAllOrders:",String(e))}}async subscribeOrders(s,c,t,n,e=!1,i){let o=!1;const a=async()=>{if(!o){o=!0;try{const u=c?await this.getMatchedOrders(s,e,i):await this.getUnMatchedOrders(s,i);u.ok?await n(u.val):console.error("Error fetching orders:",u.error)}catch(u){console.error("Error fetching orders:",u)}finally{o=!1}}};await a();const l=setInterval(a,t);return()=>{clearInterval(l)}}async getOrdersCount(s){const c=this.url.endpoint(`/user/count/${s}`);try{const t=await r.Fetcher.get(c);return t.error?r.Err(t.error):t.status===r.ApiStatus.Ok&&t.result!==void 0?r.Ok(t.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(t){return r.Err("GetOrdersCount:",String(t))}}}exports.OrdersProvider=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index6.cjs"),l=require("@gardenfi/utils"),d=require("./index7.cjs");class O{constructor(s){this.url=new l.Url("/orders",s)}async getOrder(s,c){const t=c?`/id/matched/${s}`:`/id/unmatched/${s}`,n=this.url.endpoint(t);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrder:",String(e))}}async getMatchedOrders(s,c,t){const n=d.ConstructUrl(this.url,`/user/matched/${s}`,{...t,pending:c});try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetMatchedOrders:",String(e))}}async getUnMatchedOrders(s,c){const t=d.ConstructUrl(this.url,`/user/unmatched/${s}`,c);try{const n=await r.Fetcher.get(t);return n.error?r.Err(n.error):n.result?r.Ok(n.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(n){return r.Err("GetUnMatchedOrders:",String(n))}}async getOrders(s,c){const t=s?"/matched":"/unmatched",n=d.ConstructUrl(this.url,t,c);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetAllOrders:",String(e))}}async subscribeOrders(s,c,t,n,e=!1,i){let o=!1;const a=async()=>{if(!o){o=!0;try{const u=c?await this.getMatchedOrders(s,e,i):await this.getUnMatchedOrders(s,i);u.ok?await n(u.val):console.error("Error fetching orders:",u.error)}catch(u){console.error("Error fetching orders:",u)}finally{o=!1}}};await a();const h=setInterval(a,t);return()=>{clearInterval(h)}}async getOrdersCount(s){const c=this.url.endpoint(`/user/count/${s}`);try{const t=await r.Fetcher.get(c);return t.error?r.Err(t.error):t.status===l.ApiStatus.Ok&&t.result!==void 0?r.Ok(t.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(t){return r.Err("GetOrdersCount:",String(t))}}}exports.OrdersProvider=O;
package/dist/index4.js CHANGED
@@ -1,11 +1,12 @@
1
- import { Url as f, Fetcher as u, Err as s, Ok as d, ApiStatus as g } from "@gardenfi/utils";
2
- import { ConstructUrl as i } from "./index6.js";
3
- class m {
1
+ import { Fetcher as u, Err as s, Ok as d } from "./index6.js";
2
+ import { Url as f, ApiStatus as g } from "@gardenfi/utils";
3
+ import { ConstructUrl as i } from "./index7.js";
4
+ class w {
4
5
  constructor(t) {
5
6
  this.url = new f("/orders", t);
6
7
  }
7
- async getOrder(t, c) {
8
- const e = c ? `/id/matched/${t}` : `/id/unmatched/${t}`, n = this.url.endpoint(e);
8
+ async getOrder(t, o) {
9
+ const e = o ? `/id/matched/${t}` : `/id/unmatched/${t}`, n = this.url.endpoint(e);
9
10
  try {
10
11
  const r = await u.get(n);
11
12
  return r.error ? s(r.error) : r.result ? d(r.result) : s("GetOrder: Unexpected error, result is undefined");
@@ -13,10 +14,10 @@ class m {
13
14
  return s("GetOrder:", String(r));
14
15
  }
15
16
  }
16
- async getMatchedOrders(t, c, e) {
17
+ async getMatchedOrders(t, o, e) {
17
18
  const n = i(this.url, `/user/matched/${t}`, {
18
19
  ...e,
19
- pending: c
20
+ pending: o
20
21
  });
21
22
  try {
22
23
  const r = await u.get(
@@ -27,11 +28,11 @@ class m {
27
28
  return s("GetMatchedOrders:", String(r));
28
29
  }
29
30
  }
30
- async getUnMatchedOrders(t, c) {
31
+ async getUnMatchedOrders(t, o) {
31
32
  const e = i(
32
33
  this.url,
33
34
  `/user/unmatched/${t}`,
34
- c
35
+ o
35
36
  );
36
37
  try {
37
38
  const n = await u.get(
@@ -42,8 +43,8 @@ class m {
42
43
  return s("GetUnMatchedOrders:", String(n));
43
44
  }
44
45
  }
45
- async getOrders(t, c) {
46
- const e = t ? "/matched" : "/unmatched", n = i(this.url, e, c);
46
+ async getOrders(t, o) {
47
+ const e = t ? "/matched" : "/unmatched", n = i(this.url, e, o);
47
48
  try {
48
49
  const r = await u.get(n);
49
50
  return r.error ? s(r.error) : r.result ? d(r.result) : s("GetAllOrders: Unexpected error, result is undefined");
@@ -51,18 +52,18 @@ class m {
51
52
  return s("GetAllOrders:", String(r));
52
53
  }
53
54
  }
54
- async subscribeOrders(t, c, e, n, r = !1, l) {
55
+ async subscribeOrders(t, o, e, n, r = !1, l) {
55
56
  let a = !1;
56
57
  const h = async () => {
57
58
  if (!a) {
58
59
  a = !0;
59
60
  try {
60
- const o = c ? await this.getMatchedOrders(t, r, l) : await this.getUnMatchedOrders(t, l);
61
- o.ok ? await n(
62
- o.val
63
- ) : console.error("Error fetching orders:", o.error);
64
- } catch (o) {
65
- console.error("Error fetching orders:", o);
61
+ const c = o ? await this.getMatchedOrders(t, r, l) : await this.getUnMatchedOrders(t, l);
62
+ c.ok ? await n(
63
+ c.val
64
+ ) : console.error("Error fetching orders:", c.error);
65
+ } catch (c) {
66
+ console.error("Error fetching orders:", c);
66
67
  } finally {
67
68
  a = !1;
68
69
  }
@@ -75,9 +76,9 @@ class m {
75
76
  };
76
77
  }
77
78
  async getOrdersCount(t) {
78
- const c = this.url.endpoint(`/user/count/${t}`);
79
+ const o = this.url.endpoint(`/user/count/${t}`);
79
80
  try {
80
- const e = await u.get(c);
81
+ const e = await u.get(o);
81
82
  return e.error ? s(e.error) : e.status === g.Ok && e.result !== void 0 ? d(e.result) : s("GetOrdersCount: Unexpected error, result is undefined");
82
83
  } catch (e) {
83
84
  return s("GetOrdersCount:", String(e));
@@ -85,5 +86,5 @@ class m {
85
86
  }
86
87
  }
87
88
  export {
88
- m as OrdersProvider
89
+ w as OrdersProvider
89
90
  };
package/dist/index6.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=(n,o,t)=>{const r=n.endpoint(o);return t&&Object.entries(t).forEach(([c,e])=>{e!==void 0&&r.searchParams.append(c,e.toString())}),r};exports.ConstructUrl=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var p=(a,t,e)=>{if(!t.has(a))throw TypeError("Cannot "+e)},u=(a,t,e)=>(p(a,t,"read from private field"),e?e.call(a):t.get(a)),w=(a,t,e)=>{if(t.has(a))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(a):t.set(a,e)},f=(a,t,e,r)=>(p(a,t,"write to private field"),t.set(a,e),e);const d=a=>new Promise(t=>setTimeout(t,a));class g{constructor(t,e){this.maxRetries=Math.max(t,0),this.delay=e}async retry(t){let e=0,r;for(;e<this.maxRetries+1;)try{return await t()}catch(i){e++,r=i,await d(this.delay*e)}throw r}}const v=a=>{try{return JSON.parse(a)}catch{return a}};class m{static async _postWithFallback(t,e){let r="";for(const i of t)try{const s=await fetch(i,{method:"POST",...e});if(s.status>=500){r=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){r=y(s);continue}throw new Error(r||"All APIs failed")}static async postWithFallback(t,e){return await n(e).retry(()=>this._postWithFallback(t,e))}static async _getWithFallback(t,e){let r="";for(const i of t)try{const s=await fetch(i,e);if(s.status>=500){r=await(s.text()||s.json());continue}return await this.parse(s)}catch(s){r=y(s);continue}throw new Error(r||"All APIs failed")}static async getWithFallback(t,e){return await n(e).retry(()=>this._getWithFallback(t,e))}static async _get(t,e){return await this.parse(await fetch(t,e))}static async get(t,e){return await n(e).retry(()=>this._get(t,e))}static async _post(t,e){return await this.parse(await fetch(t,{method:"POST",...e}))}static async post(t,e){return await n(e).retry(()=>this._post(t,e))}static async parse(t){const e=await t.text();if(t.status>=200&&t.status<300)return v(e);throw new Error(e)}}function y(a){return(a==null?void 0:a.message)||(a==null?void 0:a.toString())||"unknown error"}const n=a=>new g((a==null?void 0:a.retryCount)??2,(a==null?void 0:a.retryDelay)??1e3);var o,c,l;class h{constructor(t,e,r=void 0){w(this,o,void 0),w(this,c,void 0),w(this,l,void 0),f(this,o,t),f(this,l,r),f(this,c,e)}get ok(){return u(this,o)}get error(){return u(this,l)}get val(){return u(this,c)}}o=new WeakMap,c=new WeakMap,l=new WeakMap;const k=a=>new h(!0,a),W=(a,...t)=>{if(typeof a=="string"&&t&&t.length>0){let e=[a,...t].map(r=>{if(r){if(r instanceof Error)return r.message;if(typeof r=="string")return r;if(r!=null&&r.toString)return r.toString()}});return new h(!1,null,e.filter(r=>r!==void 0).join(" "))}return new h(!1,null,a)};exports.Err=W;exports.Fetcher=m;exports.Ok=k;exports.Result=h;exports.Retry=g;exports.safeParseJson=v;exports.sleep=d;
package/dist/index6.js CHANGED
@@ -1,9 +1,190 @@
1
- const i = (o, e, t) => {
2
- const r = o.endpoint(e);
3
- return t && Object.entries(t).forEach(([c, n]) => {
4
- n !== void 0 && r.searchParams.append(c, n.toString());
5
- }), r;
1
+ var p = (e, t, a) => {
2
+ if (!t.has(e))
3
+ throw TypeError("Cannot " + a);
4
+ }, h = (e, t, a) => (p(e, t, "read from private field"), a ? a.call(e) : t.get(e)), u = (e, t, a) => {
5
+ if (t.has(e))
6
+ throw TypeError("Cannot add the same private member more than once");
7
+ t instanceof WeakSet ? t.add(e) : t.set(e, a);
8
+ }, w = (e, t, a, r) => (p(e, t, "write to private field"), t.set(e, a), a);
9
+ const d = (e) => new Promise((t) => setTimeout(t, e));
10
+ class g {
11
+ /**
12
+ * @param {number} maxRetries - The maximum number of retries, if less < 0 then it is set to 0
13
+ * @param {number} delay - The delay between retries
14
+ */
15
+ constructor(t, a) {
16
+ this.maxRetries = Math.max(t, 0), this.delay = a;
17
+ }
18
+ /**
19
+ * Retries a function until it succeeds or the max number of retries is reached
20
+ *
21
+ * @param {() => Promise<T>} fn - The function to retry
22
+ * @return {Promise<T>} a Promise that resolves to the result of the function
23
+ */
24
+ async retry(t) {
25
+ let a = 0, r;
26
+ for (; a < this.maxRetries + 1; )
27
+ try {
28
+ return await t();
29
+ } catch (i) {
30
+ a++, r = i, await d(this.delay * a);
31
+ }
32
+ throw r;
33
+ }
34
+ }
35
+ const v = (e) => {
36
+ try {
37
+ return JSON.parse(e);
38
+ } catch {
39
+ return e;
40
+ }
41
+ };
42
+ class m {
43
+ static async _postWithFallback(t, a) {
44
+ let r = "";
45
+ for (const i of t)
46
+ try {
47
+ const s = await fetch(i, {
48
+ method: "POST",
49
+ ...a
50
+ });
51
+ if (s.status >= 500) {
52
+ r = await (s.text() || s.json());
53
+ continue;
54
+ }
55
+ return await this.parse(s);
56
+ } catch (s) {
57
+ r = y(s);
58
+ continue;
59
+ }
60
+ throw new Error(r || "All APIs failed");
61
+ }
62
+ /**
63
+ * Asynchronously sends a POST request to multiple URLs with fallback logic.
64
+ *
65
+ * @param {string[]} input - array of URLs to send the POST request to
66
+ * @param {RequestInit} [init] - optional request initialization options
67
+ * @return {Promise<T>} a Promise that resolves to the parsed response data
68
+ */
69
+ static async postWithFallback(t, a) {
70
+ return await n(a).retry(
71
+ () => this._postWithFallback(t, a)
72
+ );
73
+ }
74
+ static async _getWithFallback(t, a) {
75
+ let r = "";
76
+ for (const i of t)
77
+ try {
78
+ const s = await fetch(i, a);
79
+ if (s.status >= 500) {
80
+ r = await (s.text() || s.json());
81
+ continue;
82
+ }
83
+ return await this.parse(s);
84
+ } catch (s) {
85
+ r = y(s);
86
+ continue;
87
+ }
88
+ throw new Error(r || "All APIs failed");
89
+ }
90
+ /**
91
+ * Asynchronously sends a POST request to multiple URLs with fallback mechanism.
92
+ *
93
+ * @param {string[]} input - An array of URLs to retrieve data from.
94
+ * @param {RequestInit} [init] - Optional request options.
95
+ * @return {Promise<T>} A promise that resolves to the retrieved data.
96
+ */
97
+ static async getWithFallback(t, a) {
98
+ return await n(a).retry(
99
+ () => this._getWithFallback(t, a)
100
+ );
101
+ }
102
+ static async _get(t, a) {
103
+ return await this.parse(await fetch(t, a));
104
+ }
105
+ /**
106
+ * Asynchronously retrieves data of type T from the specified URL or RequestInfo, with optional initialization options.
107
+ *
108
+ * @param {RequestInfo | URL} input - The URL or RequestInfo to fetch data from
109
+ * @param {RequestInit} init - Optional initialization options for the fetch request
110
+ * @return {Promise<T>} The retrieved data of type T
111
+ */
112
+ static async get(t, a) {
113
+ return await n(a).retry(() => this._get(t, a));
114
+ }
115
+ static async _post(t, a) {
116
+ return await this.parse(
117
+ await fetch(t, {
118
+ method: "POST",
119
+ ...a
120
+ })
121
+ );
122
+ }
123
+ /**
124
+ * Asynchronously sends a POST request to the specified URL or RequestInfo, with optional initialization options.
125
+ */
126
+ static async post(t, a) {
127
+ return await n(a).retry(() => this._post(t, a));
128
+ }
129
+ /**
130
+ * Parses the response and returns the result as the specified type.
131
+ *
132
+ * @param {Response} res - the response object to be parsed
133
+ * @return {Promise<T>} the parsed result of type T
134
+ */
135
+ static async parse(t) {
136
+ const a = await t.text();
137
+ if (t.status >= 200 && t.status < 300)
138
+ return v(a);
139
+ throw new Error(a);
140
+ }
141
+ }
142
+ function y(e) {
143
+ return (e == null ? void 0 : e.message) || (e == null ? void 0 : e.toString()) || "unknown error";
144
+ }
145
+ const n = (e) => new g((e == null ? void 0 : e.retryCount) ?? 2, (e == null ? void 0 : e.retryDelay) ?? 1e3);
146
+ var o, c, l;
147
+ class f {
148
+ constructor(t, a, r = void 0) {
149
+ u(this, o, void 0), u(this, c, void 0), u(this, l, void 0), w(this, o, t), w(this, l, r), w(this, c, a);
150
+ }
151
+ get ok() {
152
+ return h(this, o);
153
+ }
154
+ get error() {
155
+ return h(this, l);
156
+ }
157
+ get val() {
158
+ return h(this, c);
159
+ }
160
+ }
161
+ o = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap();
162
+ const k = (e) => new f(!0, e), W = (e, ...t) => {
163
+ if (typeof e == "string" && t && t.length > 0) {
164
+ let a = [e, ...t].map((r) => {
165
+ if (r) {
166
+ if (r instanceof Error)
167
+ return r.message;
168
+ if (typeof r == "string")
169
+ return r;
170
+ if (r != null && r.toString)
171
+ return r.toString();
172
+ }
173
+ });
174
+ return new f(
175
+ !1,
176
+ null,
177
+ a.filter((r) => r !== void 0).join(" ")
178
+ );
179
+ }
180
+ return new f(!1, null, e);
6
181
  };
7
182
  export {
8
- i as ConstructUrl
183
+ W as Err,
184
+ m as Fetcher,
185
+ k as Ok,
186
+ f as Result,
187
+ g as Retry,
188
+ v as safeParseJson,
189
+ d as sleep
9
190
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=(n,o,t)=>{const r=n.endpoint(o);return t&&Object.entries(t).forEach(([c,e])=>{e!==void 0&&r.searchParams.append(c,e.toString())}),r};exports.ConstructUrl=i;
package/dist/index7.js ADDED
@@ -0,0 +1,9 @@
1
+ const i = (o, e, t) => {
2
+ const r = o.endpoint(e);
3
+ return t && Object.entries(t).forEach(([c, n]) => {
4
+ n !== void 0 && r.searchParams.append(c, n.toString());
5
+ }), r;
6
+ };
7
+ export {
8
+ i as ConstructUrl
9
+ };
@@ -1,5 +1,6 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
1
2
  import { CreateOrder, CreateOrderRequestWithAdditionalData, IOrderbook, MatchedOrder, PaginatedData, PaginationConfig, Status } from './orderbook.types';
2
- import { AsyncResult, IAuth, Url } from '@gardenfi/utils';
3
+ import { IAuth, Url } from '@gardenfi/utils';
3
4
  import { Chain } from '../asset';
4
5
 
5
6
  /**
@@ -1,4 +1,5 @@
1
- import { APIResponse, AsyncResult, IAuth, IStore } from '@gardenfi/utils';
1
+ import { AsyncResult } from '@catalogfi/utils';
2
+ import { APIResponse, IAuth, IStore } from '@gardenfi/utils';
2
3
  import { Asset, Chain } from '../asset';
3
4
 
4
5
  /**
@@ -1,4 +1,4 @@
1
- import { AsyncResult } from '@gardenfi/utils';
1
+ import { AsyncResult } from '@catalogfi/utils';
2
2
  import { CreateOrder, MatchedOrder, PaginatedData, PaginationConfig } from '../orderbook/orderbook.types';
3
3
 
4
4
  export interface IOrderProvider {
@@ -1,6 +1,7 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
1
2
  import { IOrderProvider } from './orders.types';
2
3
  import { CreateOrder, MatchedOrder, PaginatedData, PaginationConfig } from '../orderbook/orderbook.types';
3
- import { AsyncResult, Url } from '@gardenfi/utils';
4
+ import { Url } from '@gardenfi/utils';
4
5
 
5
6
  export declare class OrdersProvider implements IOrderProvider {
6
7
  private url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "2.2.1-beta.1",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@coral-xyz/anchor": "^0.30.1",
30
- "@gardenfi/utils": "2.2.1-beta.1",
30
+ "@gardenfi/utils": "2.2.1",
31
31
  "bufferutil": "^4.0.8",
32
32
  "siwe": "^2.1.4",
33
33
  "utf-8-validate": "^6.0.3",