@gardenfi/orderbook 2.0.9-beta.16 → 2.0.9-beta.18

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("./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,pending: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=!1,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;
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
@@ -45,7 +45,7 @@ class m {
45
45
  `/user/${n}/matched`,
46
46
  {
47
47
  ...e,
48
- pending: o
48
+ status: o
49
49
  }
50
50
  );
51
51
  try {
@@ -85,7 +85,7 @@ class m {
85
85
  return s("GetAllOrders:", String(r));
86
86
  }
87
87
  }
88
- async subscribeOrders(n, o, e, t, r = !1, l) {
88
+ async subscribeOrders(n, o, e, t, r = "all", l) {
89
89
  let i = !1;
90
90
  const h = async () => {
91
91
  if (!i) {
@@ -1,5 +1,5 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
- import { CreateOrder, CreateOrderRequestWithAdditionalData, IOrderbook, MatchedOrder, PaginatedData, PaginationConfig } from './orderbook.types';
2
+ import { CreateOrder, CreateOrderRequestWithAdditionalData, IOrderbook, MatchedOrder, PaginatedData, PaginationConfig, Status } from './orderbook.types';
3
3
  import { IAuth, Url } from '@gardenfi/utils';
4
4
 
5
5
  /**
@@ -18,9 +18,9 @@ export declare class Orderbook implements IOrderbook {
18
18
  */
19
19
  createOrder(order: CreateOrderRequestWithAdditionalData, auth: IAuth): AsyncResult<string, string>;
20
20
  getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
21
- getMatchedOrders(address: string, pending: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
21
+ getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
22
22
  getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<CreateOrder>, string>;
23
23
  getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
24
- subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, pending?: boolean, paginationConfig?: PaginationConfig): Promise<() => void>;
24
+ subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig): Promise<() => void>;
25
25
  getOrdersCount(address: string): AsyncResult<number, string>;
26
26
  }
@@ -1,7 +1,6 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
2
  import { APIResponse, IAuth, IStore } from '@gardenfi/utils';
3
3
  import { Asset, Chain } from '../asset';
4
- import { IOrderProvider } from '../orders/orders.types';
5
4
 
6
5
  /**
7
6
  * Configuration for creating an order
@@ -84,7 +83,7 @@ export type OrderConfig = {
84
83
  per_page?: number;
85
84
  };
86
85
  };
87
- export interface IOrderbook extends IOrderProvider {
86
+ export interface IOrderbook {
88
87
  /**
89
88
  * Creates an order
90
89
  * @param {CreateOrderConfig} orderConfig - The configuration for the creating the order.
@@ -105,7 +104,7 @@ export interface IOrderbook extends IOrderProvider {
105
104
  * @param paginationConfig - The configuration for the pagination.
106
105
  * @returns {AsyncResult<PaginatedData<MatchedOrder>, string>} A promise that resolves to the orders.
107
106
  */
108
- getMatchedOrders(address: string, pending: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
107
+ getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
109
108
  /**
110
109
  * Get all unmatched orders from the orderbook associated with the `address`.
111
110
  * @param address The address to get the orders for.
@@ -139,7 +138,7 @@ export interface IOrderbook extends IOrderProvider {
139
138
  * }, 20000);
140
139
  * ```
141
140
  */
142
- subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, pending?: boolean, paginationConfig?: PaginationConfig): Promise<() => void>;
141
+ subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig): Promise<() => void>;
143
142
  /**
144
143
  * Returns the current orders count associated with the provided address. Used to calculate nonce for secret generation.
145
144
  * @param address The address to get the orders count for.
@@ -240,3 +239,4 @@ export type PaginationConfig = {
240
239
  page?: number;
241
240
  per_page?: number;
242
241
  };
242
+ export type Status = 'all' | 'pending' | 'fulfilled';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "2.0.9-beta.16",
3
+ "version": "2.0.9-beta.18",
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.0.6-beta.13",
29
+ "@gardenfi/utils": "2.0.6-beta.15",
30
30
  "bufferutil": "^4.0.8",
31
31
  "siwe": "^2.1.4",
32
32
  "utf-8-validate": "^6.0.3",