@gardenfi/orderbook 2.1.9-beta.1 → 2.1.9
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 +1 -1
- package/dist/index2.js +39 -38
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +22 -21
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +187 -6
- package/dist/index7.cjs +1 -0
- package/dist/index7.js +9 -0
- package/dist/src/lib/orderbook/orderbook.d.ts +2 -1
- package/dist/src/lib/orderbook/orderbook.types.d.ts +2 -1
- package/dist/src/lib/orders/orders.types.d.ts +1 -1
- package/dist/src/lib/orders/ordersProvider.d.ts +2 -1
- package/package.json +2 -2
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),i=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index6.cjs"),h=require("@gardenfi/utils"),i=require("./index7.cjs");class O{constructor(n){this.Url=n}async createOrder(n,o){const t=await o.getAuthHeaders();if(t.error)return r.Err(t.error);try{const s=await r.Fetcher.post(this.Url.endpoint("/relayer").endpoint("create-order"),{body:JSON.stringify(n),headers:{...t.val,"Content-Type":"application/json"}});return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("CreateOrder: Unexpected error, result is undefined")}catch(s){return r.Err("CreateOrder:",String(s))}}async getOrder(n,o){const t=o?`/id/${n}/matched`:`/id/${n}/unmatched`,s=this.Url.endpoint("orders").endpoint(t);try{const e=await r.Fetcher.get(s);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(n,o,t){const s=i.ConstructUrl(this.Url.endpoint("orders"),`/user/${n}/matched`,{...t,status:o});try{const e=await r.Fetcher.get(s);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(n,o){const t=i.ConstructUrl(this.Url.endpoint("orders"),`/user/${n}/unmatched`,o);try{const s=await r.Fetcher.get(t);return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(s){return r.Err("GetUnMatchedOrders:",String(s))}}async getOrders(n,o){const t=n?"/matched":"/unmatched",s=i.ConstructUrl(this.Url.endpoint("orders"),t,o);try{const e=await r.Fetcher.get(s);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(n,o,t,s,e="all",u){let d=!1;const a=async()=>{if(!d){d=!0;try{const c=o?await this.getMatchedOrders(n,e,u):await this.getUnMatchedOrders(n,u);c.ok?await s(c.val):console.error("Error fetching orders:",c.error)}catch(c){console.error("Error fetching orders:",c)}finally{d=!1}}};await a();const l=setInterval(a,t);return()=>{clearInterval(l)}}async getOrdersCount(n){const o=this.Url.endpoint("orders").endpoint(`/user/${n}/count`);try{const t=await r.Fetcher.get(o);return t.error?r.Err(t.error):t.status===h.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.Orderbook=O;
|
package/dist/index2.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Err as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Err as s, Fetcher as d, Ok as a } from "./index6.js";
|
|
2
|
+
import { ApiStatus as f } from "@gardenfi/utils";
|
|
3
|
+
import { ConstructUrl as u } from "./index7.js";
|
|
4
|
+
class m {
|
|
5
|
+
constructor(n) {
|
|
6
|
+
this.Url = n;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Creates an order
|
|
@@ -10,38 +11,38 @@ class U {
|
|
|
10
11
|
* @param {IAuth} auth - The auth object.
|
|
11
12
|
* @returns {string} The create order ID.
|
|
12
13
|
*/
|
|
13
|
-
async createOrder(
|
|
14
|
+
async createOrder(n, o) {
|
|
14
15
|
const e = await o.getAuthHeaders();
|
|
15
|
-
if (e.error) return
|
|
16
|
+
if (e.error) return s(e.error);
|
|
16
17
|
try {
|
|
17
18
|
const t = await d.post(
|
|
18
19
|
this.Url.endpoint("/relayer").endpoint("create-order"),
|
|
19
20
|
{
|
|
20
|
-
body: JSON.stringify(
|
|
21
|
+
body: JSON.stringify(n),
|
|
21
22
|
headers: {
|
|
22
23
|
...e.val,
|
|
23
24
|
"Content-Type": "application/json"
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
);
|
|
27
|
-
return t.error ?
|
|
28
|
+
return t.error ? s(t.error) : t.result ? a(t.result) : s("CreateOrder: Unexpected error, result is undefined");
|
|
28
29
|
} catch (t) {
|
|
29
|
-
return
|
|
30
|
+
return s("CreateOrder:", String(t));
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
async getOrder(
|
|
33
|
-
const e = o ? `/id/${
|
|
33
|
+
async getOrder(n, o) {
|
|
34
|
+
const e = o ? `/id/${n}/matched` : `/id/${n}/unmatched`, t = this.Url.endpoint("orders").endpoint(e);
|
|
34
35
|
try {
|
|
35
36
|
const r = await d.get(t);
|
|
36
|
-
return r.error ?
|
|
37
|
+
return r.error ? s(r.error) : r.result ? a(r.result) : s("GetOrder: Unexpected error, result is undefined");
|
|
37
38
|
} catch (r) {
|
|
38
|
-
return
|
|
39
|
+
return s("GetOrder:", String(r));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
|
-
async getMatchedOrders(
|
|
42
|
+
async getMatchedOrders(n, o, e) {
|
|
42
43
|
const t = u(
|
|
43
44
|
this.Url.endpoint("orders"),
|
|
44
|
-
`/user/${
|
|
45
|
+
`/user/${n}/matched`,
|
|
45
46
|
{
|
|
46
47
|
...e,
|
|
47
48
|
status: o
|
|
@@ -51,51 +52,51 @@ class U {
|
|
|
51
52
|
const r = await d.get(
|
|
52
53
|
t
|
|
53
54
|
);
|
|
54
|
-
return r.error ?
|
|
55
|
+
return r.error ? s(r.error) : r.result ? a(r.result) : s("GetMatchedOrders: Unexpected error, result is undefined");
|
|
55
56
|
} catch (r) {
|
|
56
|
-
return
|
|
57
|
+
return s("GetMatchedOrders:", String(r));
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
async getUnMatchedOrders(
|
|
60
|
+
async getUnMatchedOrders(n, o) {
|
|
60
61
|
const e = u(
|
|
61
62
|
this.Url.endpoint("orders"),
|
|
62
|
-
`/user/${
|
|
63
|
+
`/user/${n}/unmatched`,
|
|
63
64
|
o
|
|
64
65
|
);
|
|
65
66
|
try {
|
|
66
67
|
const t = await d.get(
|
|
67
68
|
e
|
|
68
69
|
);
|
|
69
|
-
return t.error ?
|
|
70
|
+
return t.error ? s(t.error) : t.result ? a(t.result) : s("GetUnMatchedOrders: Unexpected error, result is undefined");
|
|
70
71
|
} catch (t) {
|
|
71
|
-
return
|
|
72
|
+
return s("GetUnMatchedOrders:", String(t));
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
async getOrders(
|
|
75
|
-
const e =
|
|
75
|
+
async getOrders(n, o) {
|
|
76
|
+
const e = n ? "/matched" : "/unmatched", t = u(
|
|
76
77
|
this.Url.endpoint("orders"),
|
|
77
78
|
e,
|
|
78
79
|
o
|
|
79
80
|
);
|
|
80
81
|
try {
|
|
81
82
|
const r = await d.get(t);
|
|
82
|
-
return r.error ?
|
|
83
|
+
return r.error ? s(r.error) : r.result ? a(r.result) : s("GetAllOrders: Unexpected error, result is undefined");
|
|
83
84
|
} catch (r) {
|
|
84
|
-
return
|
|
85
|
+
return s("GetAllOrders:", String(r));
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
async subscribeOrders(
|
|
88
|
+
async subscribeOrders(n, o, e, t, r = "all", l) {
|
|
88
89
|
let i = !1;
|
|
89
90
|
const h = async () => {
|
|
90
91
|
if (!i) {
|
|
91
92
|
i = !0;
|
|
92
93
|
try {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
) : console.error("Error fetching orders:",
|
|
97
|
-
} catch (
|
|
98
|
-
console.error("Error fetching orders:",
|
|
94
|
+
const c = o ? await this.getMatchedOrders(n, r, l) : await this.getUnMatchedOrders(n, l);
|
|
95
|
+
c.ok ? await t(
|
|
96
|
+
c.val
|
|
97
|
+
) : console.error("Error fetching orders:", c.error);
|
|
98
|
+
} catch (c) {
|
|
99
|
+
console.error("Error fetching orders:", c);
|
|
99
100
|
} finally {
|
|
100
101
|
i = !1;
|
|
101
102
|
}
|
|
@@ -107,16 +108,16 @@ class U {
|
|
|
107
108
|
clearInterval(O);
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
|
-
async getOrdersCount(
|
|
111
|
-
const o = this.Url.endpoint("orders").endpoint(`/user/${
|
|
111
|
+
async getOrdersCount(n) {
|
|
112
|
+
const o = this.Url.endpoint("orders").endpoint(`/user/${n}/count`);
|
|
112
113
|
try {
|
|
113
114
|
const e = await d.get(o);
|
|
114
|
-
return e.error ?
|
|
115
|
+
return e.error ? s(e.error) : e.status === f.Ok && e.result !== void 0 ? a(e.result) : s("GetOrdersCount: Unexpected error, result is undefined");
|
|
115
116
|
} catch (e) {
|
|
116
|
-
return
|
|
117
|
+
return s("GetOrdersCount:", String(e));
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
export {
|
|
121
|
-
|
|
122
|
+
m as Orderbook
|
|
122
123
|
};
|
package/dist/index4.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),d=require("./
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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,
|
|
8
|
-
const 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,
|
|
17
|
+
async getMatchedOrders(t, o, e) {
|
|
17
18
|
const n = i(this.url, `/user/matched/${t}`, {
|
|
18
19
|
...e,
|
|
19
|
-
pending:
|
|
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,
|
|
31
|
+
async getUnMatchedOrders(t, o) {
|
|
31
32
|
const e = i(
|
|
32
33
|
this.url,
|
|
33
34
|
`/user/unmatched/${t}`,
|
|
34
|
-
|
|
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,
|
|
46
|
-
const e = t ? "/matched" : "/unmatched", n = i(this.url, e,
|
|
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,
|
|
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
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
) : console.error("Error fetching orders:",
|
|
64
|
-
} catch (
|
|
65
|
-
console.error("Error fetching orders:",
|
|
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
|
|
79
|
+
const o = this.url.endpoint(`/user/count/${t}`);
|
|
79
80
|
try {
|
|
80
|
-
const e = await u.get(
|
|
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
|
-
|
|
89
|
+
w as OrdersProvider
|
|
89
90
|
};
|
package/dist/index6.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
};
|
package/dist/index7.cjs
ADDED
|
@@ -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
|
@@ -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 {
|
|
3
|
+
import { IAuth, Url } from '@gardenfi/utils';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A class that allows you to create and manage orders with the orderbook url.
|
|
@@ -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 {
|
|
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.1.9
|
|
3
|
+
"version": "2.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@gardenfi/utils": "2.1.3
|
|
29
|
+
"@gardenfi/utils": "2.1.3",
|
|
30
30
|
"bufferutil": "^4.0.8",
|
|
31
31
|
"siwe": "^2.1.4",
|
|
32
32
|
"utf-8-validate": "^6.0.3",
|