@liberfi.io/ui-predict 0.1.75 → 0.1.77
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/README.md +46 -41
- package/dist/index.d.mts +277 -1417
- package/dist/index.d.ts +277 -1417
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -21
- package/dist/client/index.d.mts +0 -2
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.js +0 -2
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs +0 -2
- package/dist/client/index.mjs.map +0 -1
- package/dist/client-Doli88ls.d.mts +0 -420
- package/dist/client-Doli88ls.d.ts +0 -420
- package/dist/index-BphwuECY.d.mts +0 -1420
- package/dist/index-NXmKF-C9.d.ts +0 -1420
- package/dist/server-CeHdJzO-.d.ts +0 -120
- package/dist/server-f1B7ItWZ.d.mts +0 -120
- package/dist/server.d.mts +0 -2
- package/dist/server.d.ts +0 -2
- package/dist/server.js +0 -2
- package/dist/server.js.map +0 -1
- package/dist/server.mjs +0 -2
- package/dist/server.mjs.map +0 -1
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { a as V2ProviderSource, P as PredictClientV2, b as V2Event, d as V2EventStatus, V as V2EventSortField, f as V2ListEventsParams, e as V2Page } from './client-Doli88ls.js';
|
|
2
|
-
|
|
3
|
-
/** Default page size for list queries */
|
|
4
|
-
declare const DEFAULT_PAGE_SIZE = 48;
|
|
5
|
-
/** Maximum number of markets to display in price history chart */
|
|
6
|
-
declare const MAX_PRICE_HISTORY_MARKETS = 4;
|
|
7
|
-
/**
|
|
8
|
-
* Candlestick period intervals in minutes (granularity for API queries)
|
|
9
|
-
*/
|
|
10
|
-
declare const CandlestickPeriod: {
|
|
11
|
-
/** 1 minute */
|
|
12
|
-
readonly ONE_MINUTE: 1;
|
|
13
|
-
/** 1 hour (60 minutes) */
|
|
14
|
-
readonly ONE_HOUR: 60;
|
|
15
|
-
/** 1 day (1440 minutes) */
|
|
16
|
-
readonly ONE_DAY: 1440;
|
|
17
|
-
};
|
|
18
|
-
type CandlestickPeriodType = (typeof CandlestickPeriod)[keyof typeof CandlestickPeriod];
|
|
19
|
-
/**
|
|
20
|
-
* Chart range options (the user-facing time range selector)
|
|
21
|
-
*/
|
|
22
|
-
declare const ChartRange: {
|
|
23
|
-
/** 1 day */
|
|
24
|
-
readonly ONE_DAY: "1d";
|
|
25
|
-
/** 1 week */
|
|
26
|
-
readonly ONE_WEEK: "1w";
|
|
27
|
-
/** 1 month */
|
|
28
|
-
readonly ONE_MONTH: "1m";
|
|
29
|
-
/** All time */
|
|
30
|
-
readonly ALL: "all";
|
|
31
|
-
};
|
|
32
|
-
type ChartRangeType = (typeof ChartRange)[keyof typeof ChartRange];
|
|
33
|
-
/** Default chart range */
|
|
34
|
-
declare const DEFAULT_CHART_RANGE: "all";
|
|
35
|
-
/** Candlestick granularity derived from chart range (1D → minute, 1W/1M → hourly, ALL → daily) */
|
|
36
|
-
declare const CHART_RANGE_PERIOD: Record<ChartRangeType, CandlestickPeriodType>;
|
|
37
|
-
/** Chart sampling interval in seconds (used to downsample candlestick data for display) */
|
|
38
|
-
declare const CHART_RANGE_SAMPLE_INTERVAL: Record<ChartRangeType, number>;
|
|
39
|
-
/** Duration in seconds for each chart range (null = all time) */
|
|
40
|
-
declare const CHART_RANGE_DURATION: Record<ChartRangeType, number | null>;
|
|
41
|
-
/** Minimum order quantity (contracts) */
|
|
42
|
-
declare const ORDER_MIN_QUANTITY = 1;
|
|
43
|
-
/** Price step size in cents */
|
|
44
|
-
declare const ORDER_PRICE_STEP = 1;
|
|
45
|
-
/** Minimum price in cents */
|
|
46
|
-
declare const ORDER_MIN_PRICE = 1;
|
|
47
|
-
/** Maximum price in cents */
|
|
48
|
-
declare const ORDER_MAX_PRICE = 99;
|
|
49
|
-
/** @deprecated Use ChartRange instead */
|
|
50
|
-
declare const PriceHistoryInterval: {
|
|
51
|
-
readonly ONE_HOUR: "1h";
|
|
52
|
-
readonly SIX_HOURS: "6h";
|
|
53
|
-
readonly ONE_DAY: "1d";
|
|
54
|
-
readonly ONE_WEEK: "1w";
|
|
55
|
-
readonly MAX: "max";
|
|
56
|
-
};
|
|
57
|
-
/** @deprecated Use ChartRangeType instead */
|
|
58
|
-
type PriceHistoryIntervalType = (typeof PriceHistoryInterval)[keyof typeof PriceHistoryInterval];
|
|
59
|
-
/** @deprecated Use DEFAULT_CHART_RANGE instead */
|
|
60
|
-
declare const DEFAULT_PRICE_HISTORY_INTERVAL: "1w";
|
|
61
|
-
/** @deprecated */
|
|
62
|
-
declare const PRICE_HISTORY_SAMPLE_INTERVAL: Record<PriceHistoryIntervalType, number>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Server-safe pure functions for v2 events query parameters.
|
|
66
|
-
*
|
|
67
|
-
* This module contains NO React imports and can be used in Server Components,
|
|
68
|
-
* route handlers, or any non-browser context.
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Selection emitted by CategoriesWidgetV2.
|
|
73
|
-
*
|
|
74
|
-
* Duplicated from categories.v2.script to avoid pulling in the component
|
|
75
|
-
* barrel (which has React dependencies) into server-only bundles.
|
|
76
|
-
*/
|
|
77
|
-
interface TagSlugSelection {
|
|
78
|
-
categorySlug: string | null;
|
|
79
|
-
tagSlug: string | null;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Resolve a `TagSlugSelection` to a single `tag_slug` string for the v2 API.
|
|
83
|
-
*/
|
|
84
|
-
declare function resolveTagSlug(selection: TagSlugSelection | null | undefined): string | undefined;
|
|
85
|
-
/**
|
|
86
|
-
* Input accepted by {@link resolveEventsV2Params}. All fields optional;
|
|
87
|
-
* defaults match the client-side `useEventsV2` hook's initial state.
|
|
88
|
-
*/
|
|
89
|
-
interface ResolveEventsV2ParamsInput {
|
|
90
|
-
tagSlugSelection?: TagSlugSelection | null;
|
|
91
|
-
limit?: number;
|
|
92
|
-
status?: V2EventStatus;
|
|
93
|
-
sort_by?: V2EventSortField;
|
|
94
|
-
sort_asc?: boolean;
|
|
95
|
-
source?: V2ProviderSource;
|
|
96
|
-
with_markets?: boolean;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Build a clean `V2ListEventsParams` from loose user inputs.
|
|
100
|
-
*
|
|
101
|
-
* Server-side `prefetchInfiniteQuery` and client-side `useEventsV2` must both
|
|
102
|
-
* use this function to guarantee identical query keys.
|
|
103
|
-
*/
|
|
104
|
-
declare function resolveEventsV2Params(input?: ResolveEventsV2ParamsInput): V2ListEventsParams;
|
|
105
|
-
/** Stable TanStack Query key for the v2 events infinite query. */
|
|
106
|
-
declare function eventsV2InfiniteQueryKey(params: V2ListEventsParams): unknown[];
|
|
107
|
-
/**
|
|
108
|
-
* Fetch a single page of v2 events. Can be used outside of React
|
|
109
|
-
* (e.g. in Server Components, loaders, or tests).
|
|
110
|
-
*/
|
|
111
|
-
declare function fetchEventsV2Page(client: PredictClientV2, params: V2ListEventsParams): Promise<V2Page<V2Event>>;
|
|
112
|
-
/** Stable TanStack Query key for a single v2 event. */
|
|
113
|
-
declare function eventV2QueryKey(slug: string, source?: V2ProviderSource): unknown[];
|
|
114
|
-
/**
|
|
115
|
-
* Fetch a single v2 event. Can be used outside of React
|
|
116
|
-
* (e.g. in Server Components, loaders, or tests).
|
|
117
|
-
*/
|
|
118
|
-
declare function fetchEventV2(client: PredictClientV2, slug: string, source?: V2ProviderSource): Promise<V2Event>;
|
|
119
|
-
|
|
120
|
-
export { type ChartRangeType as C, DEFAULT_PAGE_SIZE as D, MAX_PRICE_HISTORY_MARKETS as M, ORDER_MIN_QUANTITY as O, PriceHistoryInterval as P, type ResolveEventsV2ParamsInput as R, type TagSlugSelection as T, type CandlestickPeriodType as a, ChartRange as b, CandlestickPeriod as c, DEFAULT_CHART_RANGE as d, CHART_RANGE_PERIOD as e, CHART_RANGE_SAMPLE_INTERVAL as f, CHART_RANGE_DURATION as g, ORDER_PRICE_STEP as h, ORDER_MIN_PRICE as i, ORDER_MAX_PRICE as j, type PriceHistoryIntervalType as k, DEFAULT_PRICE_HISTORY_INTERVAL as l, PRICE_HISTORY_SAMPLE_INTERVAL as m, eventV2QueryKey as n, fetchEventV2 as o, resolveEventsV2Params as p, eventsV2InfiniteQueryKey as q, resolveTagSlug as r, fetchEventsV2Page as s };
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { a as V2ProviderSource, P as PredictClientV2, b as V2Event, d as V2EventStatus, V as V2EventSortField, f as V2ListEventsParams, e as V2Page } from './client-Doli88ls.mjs';
|
|
2
|
-
|
|
3
|
-
/** Default page size for list queries */
|
|
4
|
-
declare const DEFAULT_PAGE_SIZE = 48;
|
|
5
|
-
/** Maximum number of markets to display in price history chart */
|
|
6
|
-
declare const MAX_PRICE_HISTORY_MARKETS = 4;
|
|
7
|
-
/**
|
|
8
|
-
* Candlestick period intervals in minutes (granularity for API queries)
|
|
9
|
-
*/
|
|
10
|
-
declare const CandlestickPeriod: {
|
|
11
|
-
/** 1 minute */
|
|
12
|
-
readonly ONE_MINUTE: 1;
|
|
13
|
-
/** 1 hour (60 minutes) */
|
|
14
|
-
readonly ONE_HOUR: 60;
|
|
15
|
-
/** 1 day (1440 minutes) */
|
|
16
|
-
readonly ONE_DAY: 1440;
|
|
17
|
-
};
|
|
18
|
-
type CandlestickPeriodType = (typeof CandlestickPeriod)[keyof typeof CandlestickPeriod];
|
|
19
|
-
/**
|
|
20
|
-
* Chart range options (the user-facing time range selector)
|
|
21
|
-
*/
|
|
22
|
-
declare const ChartRange: {
|
|
23
|
-
/** 1 day */
|
|
24
|
-
readonly ONE_DAY: "1d";
|
|
25
|
-
/** 1 week */
|
|
26
|
-
readonly ONE_WEEK: "1w";
|
|
27
|
-
/** 1 month */
|
|
28
|
-
readonly ONE_MONTH: "1m";
|
|
29
|
-
/** All time */
|
|
30
|
-
readonly ALL: "all";
|
|
31
|
-
};
|
|
32
|
-
type ChartRangeType = (typeof ChartRange)[keyof typeof ChartRange];
|
|
33
|
-
/** Default chart range */
|
|
34
|
-
declare const DEFAULT_CHART_RANGE: "all";
|
|
35
|
-
/** Candlestick granularity derived from chart range (1D → minute, 1W/1M → hourly, ALL → daily) */
|
|
36
|
-
declare const CHART_RANGE_PERIOD: Record<ChartRangeType, CandlestickPeriodType>;
|
|
37
|
-
/** Chart sampling interval in seconds (used to downsample candlestick data for display) */
|
|
38
|
-
declare const CHART_RANGE_SAMPLE_INTERVAL: Record<ChartRangeType, number>;
|
|
39
|
-
/** Duration in seconds for each chart range (null = all time) */
|
|
40
|
-
declare const CHART_RANGE_DURATION: Record<ChartRangeType, number | null>;
|
|
41
|
-
/** Minimum order quantity (contracts) */
|
|
42
|
-
declare const ORDER_MIN_QUANTITY = 1;
|
|
43
|
-
/** Price step size in cents */
|
|
44
|
-
declare const ORDER_PRICE_STEP = 1;
|
|
45
|
-
/** Minimum price in cents */
|
|
46
|
-
declare const ORDER_MIN_PRICE = 1;
|
|
47
|
-
/** Maximum price in cents */
|
|
48
|
-
declare const ORDER_MAX_PRICE = 99;
|
|
49
|
-
/** @deprecated Use ChartRange instead */
|
|
50
|
-
declare const PriceHistoryInterval: {
|
|
51
|
-
readonly ONE_HOUR: "1h";
|
|
52
|
-
readonly SIX_HOURS: "6h";
|
|
53
|
-
readonly ONE_DAY: "1d";
|
|
54
|
-
readonly ONE_WEEK: "1w";
|
|
55
|
-
readonly MAX: "max";
|
|
56
|
-
};
|
|
57
|
-
/** @deprecated Use ChartRangeType instead */
|
|
58
|
-
type PriceHistoryIntervalType = (typeof PriceHistoryInterval)[keyof typeof PriceHistoryInterval];
|
|
59
|
-
/** @deprecated Use DEFAULT_CHART_RANGE instead */
|
|
60
|
-
declare const DEFAULT_PRICE_HISTORY_INTERVAL: "1w";
|
|
61
|
-
/** @deprecated */
|
|
62
|
-
declare const PRICE_HISTORY_SAMPLE_INTERVAL: Record<PriceHistoryIntervalType, number>;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Server-safe pure functions for v2 events query parameters.
|
|
66
|
-
*
|
|
67
|
-
* This module contains NO React imports and can be used in Server Components,
|
|
68
|
-
* route handlers, or any non-browser context.
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Selection emitted by CategoriesWidgetV2.
|
|
73
|
-
*
|
|
74
|
-
* Duplicated from categories.v2.script to avoid pulling in the component
|
|
75
|
-
* barrel (which has React dependencies) into server-only bundles.
|
|
76
|
-
*/
|
|
77
|
-
interface TagSlugSelection {
|
|
78
|
-
categorySlug: string | null;
|
|
79
|
-
tagSlug: string | null;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Resolve a `TagSlugSelection` to a single `tag_slug` string for the v2 API.
|
|
83
|
-
*/
|
|
84
|
-
declare function resolveTagSlug(selection: TagSlugSelection | null | undefined): string | undefined;
|
|
85
|
-
/**
|
|
86
|
-
* Input accepted by {@link resolveEventsV2Params}. All fields optional;
|
|
87
|
-
* defaults match the client-side `useEventsV2` hook's initial state.
|
|
88
|
-
*/
|
|
89
|
-
interface ResolveEventsV2ParamsInput {
|
|
90
|
-
tagSlugSelection?: TagSlugSelection | null;
|
|
91
|
-
limit?: number;
|
|
92
|
-
status?: V2EventStatus;
|
|
93
|
-
sort_by?: V2EventSortField;
|
|
94
|
-
sort_asc?: boolean;
|
|
95
|
-
source?: V2ProviderSource;
|
|
96
|
-
with_markets?: boolean;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Build a clean `V2ListEventsParams` from loose user inputs.
|
|
100
|
-
*
|
|
101
|
-
* Server-side `prefetchInfiniteQuery` and client-side `useEventsV2` must both
|
|
102
|
-
* use this function to guarantee identical query keys.
|
|
103
|
-
*/
|
|
104
|
-
declare function resolveEventsV2Params(input?: ResolveEventsV2ParamsInput): V2ListEventsParams;
|
|
105
|
-
/** Stable TanStack Query key for the v2 events infinite query. */
|
|
106
|
-
declare function eventsV2InfiniteQueryKey(params: V2ListEventsParams): unknown[];
|
|
107
|
-
/**
|
|
108
|
-
* Fetch a single page of v2 events. Can be used outside of React
|
|
109
|
-
* (e.g. in Server Components, loaders, or tests).
|
|
110
|
-
*/
|
|
111
|
-
declare function fetchEventsV2Page(client: PredictClientV2, params: V2ListEventsParams): Promise<V2Page<V2Event>>;
|
|
112
|
-
/** Stable TanStack Query key for a single v2 event. */
|
|
113
|
-
declare function eventV2QueryKey(slug: string, source?: V2ProviderSource): unknown[];
|
|
114
|
-
/**
|
|
115
|
-
* Fetch a single v2 event. Can be used outside of React
|
|
116
|
-
* (e.g. in Server Components, loaders, or tests).
|
|
117
|
-
*/
|
|
118
|
-
declare function fetchEventV2(client: PredictClientV2, slug: string, source?: V2ProviderSource): Promise<V2Event>;
|
|
119
|
-
|
|
120
|
-
export { type ChartRangeType as C, DEFAULT_PAGE_SIZE as D, MAX_PRICE_HISTORY_MARKETS as M, ORDER_MIN_QUANTITY as O, PriceHistoryInterval as P, type ResolveEventsV2ParamsInput as R, type TagSlugSelection as T, type CandlestickPeriodType as a, ChartRange as b, CandlestickPeriod as c, DEFAULT_CHART_RANGE as d, CHART_RANGE_PERIOD as e, CHART_RANGE_SAMPLE_INTERVAL as f, CHART_RANGE_DURATION as g, ORDER_PRICE_STEP as h, ORDER_MIN_PRICE as i, ORDER_MAX_PRICE as j, type PriceHistoryIntervalType as k, DEFAULT_PRICE_HISTORY_INTERVAL as l, PRICE_HISTORY_SAMPLE_INTERVAL as m, eventV2QueryKey as n, fetchEventV2 as o, resolveEventsV2Params as p, eventsV2InfiniteQueryKey as q, resolveTagSlug as r, fetchEventsV2Page as s };
|
package/dist/server.d.mts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { D as DEFAULT_PAGE_SIZE, R as ResolveEventsV2ParamsInput, T as TagSlugSelection, n as eventV2QueryKey, q as eventsV2InfiniteQueryKey, o as fetchEventV2, s as fetchEventsV2Page, p as resolveEventsV2Params, r as resolveTagSlug } from './server-f1B7ItWZ.mjs';
|
|
2
|
-
export { P as PredictClientV2, b as V2Event, V as V2EventSortField, d as V2EventStatus, f as V2ListEventsParams, c as V2Market, y as V2MarketResult, z as V2MarketStatus, A as V2Outcome, e as V2Page, B as V2ProviderMeta, a as V2ProviderSource, C as V2SettlementSource, D as V2Tag, x as createPredictClientV2 } from './client-Doli88ls.mjs';
|
package/dist/server.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { D as DEFAULT_PAGE_SIZE, R as ResolveEventsV2ParamsInput, T as TagSlugSelection, n as eventV2QueryKey, q as eventsV2InfiniteQueryKey, o as fetchEventV2, s as fetchEventsV2Page, p as resolveEventsV2Params, r as resolveTagSlug } from './server-CeHdJzO-.js';
|
|
2
|
-
export { P as PredictClientV2, b as V2Event, V as V2EventSortField, d as V2EventStatus, f as V2ListEventsParams, c as V2Market, y as V2MarketResult, z as V2MarketStatus, A as V2Outcome, e as V2Page, B as V2ProviderMeta, a as V2ProviderSource, C as V2SettlementSource, D as V2Tag, x as createPredictClientV2 } from './client-Doli88ls.js';
|
package/dist/server.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var utils=require('@liberfi.io/utils');var l=48;function m(s){if(s)return s.tagSlug??s.categorySlug??void 0}function y(s={}){let{tagSlugSelection:e,limit:t=48,status:r="open",with_markets:n=true,source:c,sort_by:p,sort_asc:P}=s,E=m(e);return {limit:t,status:r,with_markets:n,...c?{source:c}:{},...E?{tag_slug:E}:{},...p?{sort_by:p}:{},...P!==void 0?{sort_asc:P}:{}}}function g(s){return ["predict-v2","events-infinite",s]}async function S(s,e){return s.listEvents(e)}function O(s,e){return ["predict-v2","event",s,e]}async function _(s,e,t){return s.getEvent(e,t)}function i(s){let e=new URLSearchParams;for(let[r,n]of Object.entries(s))n!=null&&e.set(r,String(n));let t=e.toString();return t?`?${t}`:""}var u=class{constructor(e){this.endpoint=e;}async listEvents(e){let t=i(e??{}),r=`${this.endpoint}/api/v1/events${t}`;return await utils.httpGet(r)}async getEvent(e,t){let r=t?i({source:t}):"",n=`${this.endpoint}/api/v1/events/${encodeURIComponent(e)}${r}`;return await utils.httpGet(n)}async getMarket(e,t){let r=t?i({source:t}):"",n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}${r}`;return await utils.httpGet(n)}async getOrderbook(e,t){let r=i({source:t}),n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/orderbook${r}`;return await utils.httpGet(n)}async listMarketTrades(e,t){let r=i(t),n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/trades${r}`;return await utils.httpGet(n)}async getPriceHistory(e,t,r){let n=i({source:t,range:r}),c=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/price-history${n}`;return await utils.httpGet(c)}async listCandlesticks(e,t){let r=i(t??{}),n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/candlesticks${r}`;return await utils.httpGet(n)}async getSimilarEvents(e,t,r){let n=i({source:t,...r}),c=`${this.endpoint}/api/v1/events/${encodeURIComponent(e)}/similar${n}`;return await utils.httpGet(c)}async getPositions(e,t){let r=i({source:e,user:t}),n=`${this.endpoint}/api/v1/positions${r}`;return await utils.httpGet(n)}async listOrders(e){let t=i(e),r=`${this.endpoint}/api/v1/orders${t}`;return await utils.httpGet(r)}async getOrder(e,t){let r=i({source:t}),n=`${this.endpoint}/api/v1/orders/${encodeURIComponent(e)}${r}`;return await utils.httpGet(n)}async cancelOrder(e,t){let r=i({source:t}),n=`${this.endpoint}/api/v1/orders/${encodeURIComponent(e)}${r}`;return await utils.httpDelete(n)}async createDFlowQuote(e){let t=`${this.endpoint}/api/v1/orders/dflow/quote`;return await utils.httpPost(t,e)}async submitDFlowTransaction(e){let t=`${this.endpoint}/api/v1/orders/dflow/submit`;return await utils.httpPost(t,e)}async listTradesByWallet(e){let t=i(e),r=`${this.endpoint}/api/v1/trades${t}`;return await utils.httpGet(r)}};function R(s){return new u(s)}exports.DEFAULT_PAGE_SIZE=l;exports.PredictClientV2=u;exports.createPredictClientV2=R;exports.eventV2QueryKey=O;exports.eventsV2InfiniteQueryKey=g;exports.fetchEventV2=_;exports.fetchEventsV2Page=S;exports.resolveEventsV2Params=y;exports.resolveTagSlug=m;//# sourceMappingURL=server.js.map
|
|
2
|
-
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/consts/index.ts","../src/hooks/v2/eventsV2.params.ts","../src/client/v2/client.ts"],"names":["DEFAULT_PAGE_SIZE","resolveTagSlug","selection","resolveEventsV2Params","input","tagSlugSelection","limit","status","with_markets","source","sort_by","sort_asc","tag_slug","eventsV2InfiniteQueryKey","params","fetchEventsV2Page","client","eventV2QueryKey","slug","fetchEventV2","buildV2Query","qs","key","value","str","PredictClientV2","endpoint","query","url","httpGet","range","user","id","httpDelete","body","httpPost","createPredictClientV2"],"mappings":"oDACO,IAAMA,EAAoB,GCgC1B,SAASC,CAAAA,CACdC,EACoB,CACpB,GAAKA,EACL,OAAOA,CAAAA,CAAU,SAAWA,CAAAA,CAAU,YAAA,EAAgB,MACxD,CAsBO,SAASC,EACdC,CAAAA,CAAoC,GAChB,CACpB,GAAM,CACJ,gBAAA,CAAAC,CAAAA,CACA,MAAAC,CAAAA,CAAQ,EAAA,CACR,OAAAC,CAAAA,CAAS,MAAA,CACT,aAAAC,CAAAA,CAAe,IAAA,CACf,OAAAC,CAAAA,CACA,OAAA,CAAAC,EACA,QAAA,CAAAC,CACF,CAAA,CAAIP,CAAAA,CACEQ,EAAWX,CAAAA,CAAeI,CAAgB,EAChD,OAAO,CACL,MAAAC,CAAAA,CACA,MAAA,CAAAC,EACA,YAAA,CAAAC,CAAAA,CACA,GAAIC,CAAAA,CAAS,CAAE,OAAAA,CAAO,CAAA,CAAI,EAAC,CAC3B,GAAIG,EAAW,CAAE,QAAA,CAAAA,CAAS,CAAA,CAAI,GAC9B,GAAIF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js","sourcesContent":["/** Default page size for list queries */\nexport const DEFAULT_PAGE_SIZE = 48;\n\n/** Maximum number of markets to display in price history chart */\nexport const MAX_PRICE_HISTORY_MARKETS = 4;\n\n/**\n * Candlestick period intervals in minutes (granularity for API queries)\n */\nexport const CandlestickPeriod = {\n /** 1 minute */\n ONE_MINUTE: 1,\n /** 1 hour (60 minutes) */\n ONE_HOUR: 60,\n /** 1 day (1440 minutes) */\n ONE_DAY: 1440,\n} as const;\n\nexport type CandlestickPeriodType =\n (typeof CandlestickPeriod)[keyof typeof CandlestickPeriod];\n\n/**\n * Chart range options (the user-facing time range selector)\n */\nexport const ChartRange = {\n /** 1 day */\n ONE_DAY: \"1d\",\n /** 1 week */\n ONE_WEEK: \"1w\",\n /** 1 month */\n ONE_MONTH: \"1m\",\n /** All time */\n ALL: \"all\",\n} as const;\n\nexport type ChartRangeType = (typeof ChartRange)[keyof typeof ChartRange];\n\n/** Default chart range */\nexport const DEFAULT_CHART_RANGE = ChartRange.ALL;\n\n/** Candlestick granularity derived from chart range (1D → minute, 1W/1M → hourly, ALL → daily) */\nexport const CHART_RANGE_PERIOD: Record<ChartRangeType, CandlestickPeriodType> =\n {\n [ChartRange.ONE_DAY]: CandlestickPeriod.ONE_MINUTE,\n [ChartRange.ONE_WEEK]: CandlestickPeriod.ONE_HOUR,\n [ChartRange.ONE_MONTH]: CandlestickPeriod.ONE_HOUR,\n [ChartRange.ALL]: CandlestickPeriod.ONE_DAY,\n };\n\n/** Chart sampling interval in seconds (used to downsample candlestick data for display) */\nexport const CHART_RANGE_SAMPLE_INTERVAL: Record<ChartRangeType, number> = {\n [ChartRange.ONE_DAY]: 5 * 60, // 5 minutes\n [ChartRange.ONE_WEEK]: 60 * 60, // 1 hour\n [ChartRange.ONE_MONTH]: 3 * 60 * 60, // 3 hours\n [ChartRange.ALL]: 24 * 60 * 60, // 1 day\n};\n\n/** Duration in seconds for each chart range (null = all time) */\nexport const CHART_RANGE_DURATION: Record<ChartRangeType, number | null> = {\n [ChartRange.ONE_DAY]: 24 * 60 * 60,\n [ChartRange.ONE_WEEK]: 7 * 24 * 60 * 60,\n [ChartRange.ONE_MONTH]: 30 * 24 * 60 * 60,\n [ChartRange.ALL]: null,\n};\n\n// -- Order-related constants -------------------------------------------------\n\n/** Minimum order quantity (contracts) */\nexport const ORDER_MIN_QUANTITY = 1;\n\n/** Price step size in cents */\nexport const ORDER_PRICE_STEP = 1;\n\n/** Minimum price in cents */\nexport const ORDER_MIN_PRICE = 1;\n\n/** Maximum price in cents */\nexport const ORDER_MAX_PRICE = 99;\n\n// -- Legacy aliases for backward compatibility -------------------------------\n\n/** @deprecated Use ChartRange instead */\nexport const PriceHistoryInterval = {\n ONE_HOUR: \"1h\",\n SIX_HOURS: \"6h\",\n ONE_DAY: \"1d\",\n ONE_WEEK: \"1w\",\n MAX: \"max\",\n} as const;\n\n/** @deprecated Use ChartRangeType instead */\nexport type PriceHistoryIntervalType =\n (typeof PriceHistoryInterval)[keyof typeof PriceHistoryInterval];\n\n/** @deprecated Use DEFAULT_CHART_RANGE instead */\nexport const DEFAULT_PRICE_HISTORY_INTERVAL = PriceHistoryInterval.ONE_WEEK;\n\n/** @deprecated */\nexport const PRICE_HISTORY_SAMPLE_INTERVAL: Record<\n PriceHistoryIntervalType,\n number\n> = {\n [PriceHistoryInterval.ONE_HOUR]: 60,\n [PriceHistoryInterval.SIX_HOURS]: 60,\n [PriceHistoryInterval.ONE_DAY]: 300,\n [PriceHistoryInterval.ONE_WEEK]: 1800,\n [PriceHistoryInterval.MAX]: 1800,\n};\n","/**\n * Server-safe pure functions for v2 events query parameters.\n *\n * This module contains NO React imports and can be used in Server Components,\n * route handlers, or any non-browser context.\n */\nimport type {\n V2Event,\n V2EventSortField,\n V2EventStatus,\n V2ListEventsParams,\n V2Page,\n V2ProviderSource,\n} from \"../../client/v2\";\nimport type { PredictClientV2 } from \"../../client/v2\";\nimport { DEFAULT_PAGE_SIZE } from \"../../consts\";\n\nexport type { V2ProviderSource };\n\n/**\n * Selection emitted by CategoriesWidgetV2.\n *\n * Duplicated from categories.v2.script to avoid pulling in the component\n * barrel (which has React dependencies) into server-only bundles.\n */\nexport interface TagSlugSelection {\n categorySlug: string | null;\n tagSlug: string | null;\n}\n\n/**\n * Resolve a `TagSlugSelection` to a single `tag_slug` string for the v2 API.\n */\nexport function resolveTagSlug(\n selection: TagSlugSelection | null | undefined,\n): string | undefined {\n if (!selection) return undefined;\n return selection.tagSlug ?? selection.categorySlug ?? undefined;\n}\n\n/**\n * Input accepted by {@link resolveEventsV2Params}. All fields optional;\n * defaults match the client-side `useEventsV2` hook's initial state.\n */\nexport interface ResolveEventsV2ParamsInput {\n tagSlugSelection?: TagSlugSelection | null;\n limit?: number;\n status?: V2EventStatus;\n sort_by?: V2EventSortField;\n sort_asc?: boolean;\n source?: V2ProviderSource;\n with_markets?: boolean;\n}\n\n/**\n * Build a clean `V2ListEventsParams` from loose user inputs.\n *\n * Server-side `prefetchInfiniteQuery` and client-side `useEventsV2` must both\n * use this function to guarantee identical query keys.\n */\nexport function resolveEventsV2Params(\n input: ResolveEventsV2ParamsInput = {},\n): V2ListEventsParams {\n const {\n tagSlugSelection,\n limit = DEFAULT_PAGE_SIZE,\n status = \"open\",\n with_markets = true,\n source,\n sort_by,\n sort_asc,\n } = input;\n const tag_slug = resolveTagSlug(tagSlugSelection);\n return {\n limit,\n status,\n with_markets,\n ...(source ? { source } : {}),\n ...(tag_slug ? { tag_slug } : {}),\n ...(sort_by ? { sort_by } : {}),\n ...(sort_asc !== undefined ? { sort_asc } : {}),\n };\n}\n\n/** Stable TanStack Query key for the v2 events infinite query. */\nexport function eventsV2InfiniteQueryKey(\n params: V2ListEventsParams,\n): unknown[] {\n return [\"predict-v2\", \"events-infinite\", params];\n}\n\n/**\n * Fetch a single page of v2 events. Can be used outside of React\n * (e.g. in Server Components, loaders, or tests).\n */\nexport async function fetchEventsV2Page(\n client: PredictClientV2,\n params: V2ListEventsParams,\n): Promise<V2Page<V2Event>> {\n return client.listEvents(params);\n}\n\n// ---------------------------------------------------------------------------\n// Single-event helpers (also server-safe)\n// ---------------------------------------------------------------------------\n\n/** Stable TanStack Query key for a single v2 event. */\nexport function eventV2QueryKey(\n slug: string,\n source?: V2ProviderSource,\n): unknown[] {\n return [\"predict-v2\", \"event\", slug, source];\n}\n\n/**\n * Fetch a single v2 event. Can be used outside of React\n * (e.g. in Server Components, loaders, or tests).\n */\nexport async function fetchEventV2(\n client: PredictClientV2,\n slug: string,\n source?: V2ProviderSource,\n): Promise<V2Event> {\n return client.getEvent(slug, source);\n}\n\nexport type { V2Event, V2ListEventsParams, V2Page };\n","import { httpGet, httpPost, httpDelete } from \"@liberfi.io/utils\";\nimport type {\n V2CancelOrderResult,\n V2Candlestick,\n V2DFlowQuoteRequest,\n V2DFlowQuoteResponse,\n V2DFlowSubmitRequest,\n V2DFlowSubmitResponse,\n V2Event,\n V2ListCandlesticksParams,\n V2ListEventsParams,\n V2ListMarketTradesParams,\n V2ListOrdersParams,\n V2ListTradesByWalletParams,\n V2Market,\n V2Orderbook,\n V2Page,\n V2PositionsResponse,\n V2PriceHistoryRange,\n V2PriceHistoryResponse,\n V2ProviderSource,\n V2SimilarEventsParams,\n V2Trade,\n V2UserOrder,\n} from \"./types\";\n\n/**\n * Build a URL query string from a params object.\n * `undefined` and `null` values are omitted.\n * Boolean values are serialised as \"true\" / \"false\" strings.\n */\nfunction buildV2Query(params: Record<string, unknown>): string {\n const qs = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n qs.set(key, String(value));\n }\n }\n const str = qs.toString();\n return str ? `?${str}` : \"\";\n}\n\n/**\n * HTTP client for the prediction-server REST API (v2 / prediction-server backend).\n *\n * Covers `GET /api/v1/events` (listEvents), `GET /api/v1/events/:slug` (getEvent),\n * and `GET /api/v1/markets/:slug` (getMarket).\n *\n * This client is intentionally decoupled from the legacy `DflowPredictClient` so\n * that both can be used in parallel during the incremental migration from the old\n * DFlow-direct integration to the unified prediction-server backend.\n *\n * @example\n * ```ts\n * const client = new PredictClientV2(\"https://api.example.com\");\n * const page = await client.listEvents({ status: \"open\", limit: 20 });\n * const event = await client.getEvent(\"will-trump-win-2024\");\n * const market = await client.getMarket(\"will-trump-win-2024-yes\");\n * ```\n */\nexport class PredictClientV2 {\n constructor(private readonly endpoint: string) {}\n\n /**\n * List prediction events with optional filtering, sorting, and pagination.\n *\n * Maps to `GET /api/v1/events`.\n *\n * @param params - Optional query parameters (filter, sort, pagination).\n * @returns A paginated page of events.\n */\n async listEvents(params?: V2ListEventsParams): Promise<V2Page<V2Event>> {\n const query = buildV2Query((params ?? {}) as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/events${query}`;\n return await httpGet<V2Page<V2Event>>(url);\n }\n\n /**\n * Fetch a single prediction event by its slug.\n *\n * Maps to `GET /api/v1/events/:slug?source=...`.\n *\n * @param slug - Canonical event slug (e.g. \"will-trump-win-2024\" for Polymarket\n * or \"KXBTCD-25FEB-T68000\" for DFlow).\n * @param source - Upstream provider (`\"dflow\"` or `\"polymarket\"`).\n * @returns The matching event.\n * @throws When the server responds with 404 or any other non-2xx status.\n */\n async getEvent(slug: string, source?: V2ProviderSource): Promise<V2Event> {\n const query = source ? buildV2Query({ source }) : \"\";\n const url = `${this.endpoint}/api/v1/events/${encodeURIComponent(slug)}${query}`;\n return await httpGet<V2Event>(url);\n }\n\n /**\n * Fetch a single prediction market by its slug.\n *\n * Maps to `GET /api/v1/markets/:slug?source=...`.\n *\n * @param slug - Canonical market slug.\n * @param source - Upstream provider (`\"dflow\"` or `\"polymarket\"`).\n * @returns The matching market.\n * @throws When the server responds with 404 or any other non-2xx status.\n */\n async getMarket(slug: string, source?: V2ProviderSource): Promise<V2Market> {\n const query = source ? buildV2Query({ source }) : \"\";\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}${query}`;\n return await httpGet<V2Market>(url);\n }\n\n // -------------------------------------------------------------------------\n // Market sub-resources\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/markets/:slug/orderbook?source=...`. */\n async getOrderbook(\n slug: string,\n source: V2ProviderSource,\n ): Promise<V2Orderbook> {\n const query = buildV2Query({ source });\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/orderbook${query}`;\n return await httpGet<V2Orderbook>(url);\n }\n\n /** Maps to `GET /api/v1/markets/:slug/trades?source=...`. */\n async listMarketTrades(\n slug: string,\n params: V2ListMarketTradesParams,\n ): Promise<V2Page<V2Trade>> {\n const query = buildV2Query(params as unknown as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/trades${query}`;\n return await httpGet<V2Page<V2Trade>>(url);\n }\n\n /** Maps to `GET /api/v1/markets/:slug/price-history?source=...&range=...`. */\n async getPriceHistory(\n slug: string,\n source: V2ProviderSource,\n range?: V2PriceHistoryRange,\n ): Promise<V2PriceHistoryResponse> {\n const query = buildV2Query({ source, range });\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/price-history${query}`;\n return await httpGet<V2PriceHistoryResponse>(url);\n }\n\n /** Maps to `GET /api/v1/markets/:slug/candlesticks?interval=...&limit=...`. */\n async listCandlesticks(\n slug: string,\n params?: V2ListCandlesticksParams,\n ): Promise<V2Candlestick[]> {\n const query = buildV2Query((params ?? {}) as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/candlesticks${query}`;\n return await httpGet<V2Candlestick[]>(url);\n }\n\n // -------------------------------------------------------------------------\n // Event sub-resources\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/events/:slug/similar?source=...`. */\n async getSimilarEvents(\n slug: string,\n source: V2ProviderSource,\n params?: V2SimilarEventsParams,\n ): Promise<V2Event[]> {\n const query = buildV2Query({ source, ...params });\n const url = `${this.endpoint}/api/v1/events/${encodeURIComponent(slug)}/similar${query}`;\n return await httpGet<V2Event[]>(url);\n }\n\n // -------------------------------------------------------------------------\n // Positions\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/positions?source=...&user=...`. */\n async getPositions(\n source: V2ProviderSource,\n user: string,\n ): Promise<V2PositionsResponse> {\n const query = buildV2Query({ source, user });\n const url = `${this.endpoint}/api/v1/positions${query}`;\n return await httpGet<V2PositionsResponse>(url);\n }\n\n // -------------------------------------------------------------------------\n // Orders\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/orders?source=...&wallet_address=...`. */\n async listOrders(params: V2ListOrdersParams): Promise<V2Page<V2UserOrder>> {\n const query = buildV2Query(params as unknown as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/orders${query}`;\n return await httpGet<V2Page<V2UserOrder>>(url);\n }\n\n /** Maps to `GET /api/v1/orders/:id?source=...`. */\n async getOrder(id: string, source: V2ProviderSource): Promise<V2UserOrder> {\n const query = buildV2Query({ source });\n const url = `${this.endpoint}/api/v1/orders/${encodeURIComponent(id)}${query}`;\n return await httpGet<V2UserOrder>(url);\n }\n\n /** Maps to `DELETE /api/v1/orders/:id?source=...`. */\n async cancelOrder(\n id: string,\n source: V2ProviderSource,\n ): Promise<V2CancelOrderResult> {\n const query = buildV2Query({ source });\n const url = `${this.endpoint}/api/v1/orders/${encodeURIComponent(id)}${query}`;\n return await httpDelete<V2CancelOrderResult>(url);\n }\n\n // -------------------------------------------------------------------------\n // DFlow trading\n // -------------------------------------------------------------------------\n\n /** Maps to `POST /api/v1/orders/dflow/quote`. */\n async createDFlowQuote(\n body: V2DFlowQuoteRequest,\n ): Promise<V2DFlowQuoteResponse> {\n const url = `${this.endpoint}/api/v1/orders/dflow/quote`;\n return await httpPost<V2DFlowQuoteResponse>(url, body);\n }\n\n /** Maps to `POST /api/v1/orders/dflow/submit`. */\n async submitDFlowTransaction(\n body: V2DFlowSubmitRequest,\n ): Promise<V2DFlowSubmitResponse> {\n const url = `${this.endpoint}/api/v1/orders/dflow/submit`;\n return await httpPost<V2DFlowSubmitResponse>(url, body);\n }\n\n // -------------------------------------------------------------------------\n // Trades by wallet\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/trades?source=...&wallet=...`. */\n async listTradesByWallet(\n params: V2ListTradesByWalletParams,\n ): Promise<V2Page<V2Trade>> {\n const query = buildV2Query(params as unknown as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/trades${query}`;\n return await httpGet<V2Page<V2Trade>>(url);\n }\n}\n\n/**\n * Factory function for `PredictClientV2`.\n *\n * @param endpoint - Base URL of the prediction-server, without a trailing slash.\n */\nexport function createPredictClientV2(endpoint: string): PredictClientV2 {\n return new PredictClientV2(endpoint);\n}\n"]}
|
package/dist/server.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {httpGet,httpDelete,httpPost}from'@liberfi.io/utils';var l=48;function m(s){if(s)return s.tagSlug??s.categorySlug??void 0}function y(s={}){let{tagSlugSelection:e,limit:t=48,status:r="open",with_markets:n=true,source:c,sort_by:p,sort_asc:P}=s,E=m(e);return {limit:t,status:r,with_markets:n,...c?{source:c}:{},...E?{tag_slug:E}:{},...p?{sort_by:p}:{},...P!==void 0?{sort_asc:P}:{}}}function g(s){return ["predict-v2","events-infinite",s]}async function S(s,e){return s.listEvents(e)}function O(s,e){return ["predict-v2","event",s,e]}async function _(s,e,t){return s.getEvent(e,t)}function i(s){let e=new URLSearchParams;for(let[r,n]of Object.entries(s))n!=null&&e.set(r,String(n));let t=e.toString();return t?`?${t}`:""}var u=class{constructor(e){this.endpoint=e;}async listEvents(e){let t=i(e??{}),r=`${this.endpoint}/api/v1/events${t}`;return await httpGet(r)}async getEvent(e,t){let r=t?i({source:t}):"",n=`${this.endpoint}/api/v1/events/${encodeURIComponent(e)}${r}`;return await httpGet(n)}async getMarket(e,t){let r=t?i({source:t}):"",n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}${r}`;return await httpGet(n)}async getOrderbook(e,t){let r=i({source:t}),n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/orderbook${r}`;return await httpGet(n)}async listMarketTrades(e,t){let r=i(t),n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/trades${r}`;return await httpGet(n)}async getPriceHistory(e,t,r){let n=i({source:t,range:r}),c=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/price-history${n}`;return await httpGet(c)}async listCandlesticks(e,t){let r=i(t??{}),n=`${this.endpoint}/api/v1/markets/${encodeURIComponent(e)}/candlesticks${r}`;return await httpGet(n)}async getSimilarEvents(e,t,r){let n=i({source:t,...r}),c=`${this.endpoint}/api/v1/events/${encodeURIComponent(e)}/similar${n}`;return await httpGet(c)}async getPositions(e,t){let r=i({source:e,user:t}),n=`${this.endpoint}/api/v1/positions${r}`;return await httpGet(n)}async listOrders(e){let t=i(e),r=`${this.endpoint}/api/v1/orders${t}`;return await httpGet(r)}async getOrder(e,t){let r=i({source:t}),n=`${this.endpoint}/api/v1/orders/${encodeURIComponent(e)}${r}`;return await httpGet(n)}async cancelOrder(e,t){let r=i({source:t}),n=`${this.endpoint}/api/v1/orders/${encodeURIComponent(e)}${r}`;return await httpDelete(n)}async createDFlowQuote(e){let t=`${this.endpoint}/api/v1/orders/dflow/quote`;return await httpPost(t,e)}async submitDFlowTransaction(e){let t=`${this.endpoint}/api/v1/orders/dflow/submit`;return await httpPost(t,e)}async listTradesByWallet(e){let t=i(e),r=`${this.endpoint}/api/v1/trades${t}`;return await httpGet(r)}};function R(s){return new u(s)}export{l as DEFAULT_PAGE_SIZE,u as PredictClientV2,R as createPredictClientV2,O as eventV2QueryKey,g as eventsV2InfiniteQueryKey,_ as fetchEventV2,S as fetchEventsV2Page,y as resolveEventsV2Params,m as resolveTagSlug};//# sourceMappingURL=server.mjs.map
|
|
2
|
-
//# sourceMappingURL=server.mjs.map
|
package/dist/server.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/consts/index.ts","../src/hooks/v2/eventsV2.params.ts","../src/client/v2/client.ts"],"names":["DEFAULT_PAGE_SIZE","resolveTagSlug","selection","resolveEventsV2Params","input","tagSlugSelection","limit","status","with_markets","source","sort_by","sort_asc","tag_slug","eventsV2InfiniteQueryKey","params","fetchEventsV2Page","client","eventV2QueryKey","slug","fetchEventV2","buildV2Query","qs","key","value","str","PredictClientV2","endpoint","query","url","httpGet","range","user","id","httpDelete","body","httpPost","createPredictClientV2"],"mappings":"4DACO,IAAMA,EAAoB,GCgC1B,SAASC,CAAAA,CACdC,EACoB,CACpB,GAAKA,EACL,OAAOA,CAAAA,CAAU,SAAWA,CAAAA,CAAU,YAAA,EAAgB,MACxD,CAsBO,SAASC,EACdC,CAAAA,CAAoC,GAChB,CACpB,GAAM,CACJ,gBAAA,CAAAC,CAAAA,CACA,MAAAC,CAAAA,CAAQ,EAAA,CACR,OAAAC,CAAAA,CAAS,MAAA,CACT,aAAAC,CAAAA,CAAe,IAAA,CACf,OAAAC,CAAAA,CACA,OAAA,CAAAC,EACA,QAAA,CAAAC,CACF,CAAA,CAAIP,CAAAA,CACEQ,EAAWX,CAAAA,CAAeI,CAAgB,EAChD,OAAO,CACL,MAAAC,CAAAA,CACA,MAAA,CAAAC,EACA,YAAA,CAAAC,CAAAA,CACA,GAAIC,CAAAA,CAAS,CAAE,OAAAA,CAAO,CAAA,CAAI,EAAC,CAC3B,GAAIG,EAAW,CAAE,QAAA,CAAAA,CAAS,CAAA,CAAI,GAC9B,GAAIF,CAAAA,CAAU,CAAE,OAAA,CAAAA,CAAQ,EAAI,EAAC,CAC7B,GAAIC,CAAAA,GAAa,MAAA,CAAY,CAAE,QAAA,CAAAA,CAAS,EAAI,EAC9C,CACF,CAGO,SAASE,EACdC,CAAAA,CACW,CACX,OAAO,CAAC,YAAA,CAAc,kBAAmBA,CAAM,CACjD,CAMA,eAAsBC,CAAAA,CACpBC,EACAF,CAAAA,CAC0B,CAC1B,OAAOE,CAAAA,CAAO,UAAA,CAAWF,CAAM,CACjC,CAOO,SAASG,CAAAA,CACdC,CAAAA,CACAT,EACW,CACX,OAAO,CAAC,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,CAAAA,CAAQP,EAAa,CAAE,MAAA,CAAAX,CAAO,CAAC,CAAA,CAC/BmB,EAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,eAAA,EAAkB,kBAAA,CAAmBI,CAAE,CAAC,CAAA,EAAGL,CAAK,CAAA,CAAA,CAC5E,OAAO,MAAMM,UAAAA,CAAgCL,CAAG,CAClD,CAOA,MAAM,iBACJM,CAAAA,CAC+B,CAC/B,IAAMN,CAAAA,CAAM,CAAA,EAAG,KAAK,QAAQ,CAAA,0BAAA,CAAA,CAC5B,OAAO,MAAMO,QAAAA,CAA+BP,EAAKM,CAAI,CACvD,CAGA,MAAM,sBAAA,CACJA,EACgC,CAChC,IAAMN,EAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,2BAAA,CAAA,CAC5B,OAAO,MAAMO,QAAAA,CAAgCP,CAAAA,CAAKM,CAAI,CACxD,CAOA,MAAM,kBAAA,CACJpB,CAAAA,CAC0B,CAC1B,IAAMa,CAAAA,CAAQP,EAAaN,CAA4C,CAAA,CACjEc,EAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,cAAA,EAAiBD,CAAK,GAClD,OAAO,MAAME,QAAyBD,CAAG,CAC3C,CACF,EAOO,SAASQ,EAAsBV,CAAAA,CAAmC,CACvE,OAAO,IAAID,CAAAA,CAAgBC,CAAQ,CACrC","file":"server.mjs","sourcesContent":["/** Default page size for list queries */\nexport const DEFAULT_PAGE_SIZE = 48;\n\n/** Maximum number of markets to display in price history chart */\nexport const MAX_PRICE_HISTORY_MARKETS = 4;\n\n/**\n * Candlestick period intervals in minutes (granularity for API queries)\n */\nexport const CandlestickPeriod = {\n /** 1 minute */\n ONE_MINUTE: 1,\n /** 1 hour (60 minutes) */\n ONE_HOUR: 60,\n /** 1 day (1440 minutes) */\n ONE_DAY: 1440,\n} as const;\n\nexport type CandlestickPeriodType =\n (typeof CandlestickPeriod)[keyof typeof CandlestickPeriod];\n\n/**\n * Chart range options (the user-facing time range selector)\n */\nexport const ChartRange = {\n /** 1 day */\n ONE_DAY: \"1d\",\n /** 1 week */\n ONE_WEEK: \"1w\",\n /** 1 month */\n ONE_MONTH: \"1m\",\n /** All time */\n ALL: \"all\",\n} as const;\n\nexport type ChartRangeType = (typeof ChartRange)[keyof typeof ChartRange];\n\n/** Default chart range */\nexport const DEFAULT_CHART_RANGE = ChartRange.ALL;\n\n/** Candlestick granularity derived from chart range (1D → minute, 1W/1M → hourly, ALL → daily) */\nexport const CHART_RANGE_PERIOD: Record<ChartRangeType, CandlestickPeriodType> =\n {\n [ChartRange.ONE_DAY]: CandlestickPeriod.ONE_MINUTE,\n [ChartRange.ONE_WEEK]: CandlestickPeriod.ONE_HOUR,\n [ChartRange.ONE_MONTH]: CandlestickPeriod.ONE_HOUR,\n [ChartRange.ALL]: CandlestickPeriod.ONE_DAY,\n };\n\n/** Chart sampling interval in seconds (used to downsample candlestick data for display) */\nexport const CHART_RANGE_SAMPLE_INTERVAL: Record<ChartRangeType, number> = {\n [ChartRange.ONE_DAY]: 5 * 60, // 5 minutes\n [ChartRange.ONE_WEEK]: 60 * 60, // 1 hour\n [ChartRange.ONE_MONTH]: 3 * 60 * 60, // 3 hours\n [ChartRange.ALL]: 24 * 60 * 60, // 1 day\n};\n\n/** Duration in seconds for each chart range (null = all time) */\nexport const CHART_RANGE_DURATION: Record<ChartRangeType, number | null> = {\n [ChartRange.ONE_DAY]: 24 * 60 * 60,\n [ChartRange.ONE_WEEK]: 7 * 24 * 60 * 60,\n [ChartRange.ONE_MONTH]: 30 * 24 * 60 * 60,\n [ChartRange.ALL]: null,\n};\n\n// -- Order-related constants -------------------------------------------------\n\n/** Minimum order quantity (contracts) */\nexport const ORDER_MIN_QUANTITY = 1;\n\n/** Price step size in cents */\nexport const ORDER_PRICE_STEP = 1;\n\n/** Minimum price in cents */\nexport const ORDER_MIN_PRICE = 1;\n\n/** Maximum price in cents */\nexport const ORDER_MAX_PRICE = 99;\n\n// -- Legacy aliases for backward compatibility -------------------------------\n\n/** @deprecated Use ChartRange instead */\nexport const PriceHistoryInterval = {\n ONE_HOUR: \"1h\",\n SIX_HOURS: \"6h\",\n ONE_DAY: \"1d\",\n ONE_WEEK: \"1w\",\n MAX: \"max\",\n} as const;\n\n/** @deprecated Use ChartRangeType instead */\nexport type PriceHistoryIntervalType =\n (typeof PriceHistoryInterval)[keyof typeof PriceHistoryInterval];\n\n/** @deprecated Use DEFAULT_CHART_RANGE instead */\nexport const DEFAULT_PRICE_HISTORY_INTERVAL = PriceHistoryInterval.ONE_WEEK;\n\n/** @deprecated */\nexport const PRICE_HISTORY_SAMPLE_INTERVAL: Record<\n PriceHistoryIntervalType,\n number\n> = {\n [PriceHistoryInterval.ONE_HOUR]: 60,\n [PriceHistoryInterval.SIX_HOURS]: 60,\n [PriceHistoryInterval.ONE_DAY]: 300,\n [PriceHistoryInterval.ONE_WEEK]: 1800,\n [PriceHistoryInterval.MAX]: 1800,\n};\n","/**\n * Server-safe pure functions for v2 events query parameters.\n *\n * This module contains NO React imports and can be used in Server Components,\n * route handlers, or any non-browser context.\n */\nimport type {\n V2Event,\n V2EventSortField,\n V2EventStatus,\n V2ListEventsParams,\n V2Page,\n V2ProviderSource,\n} from \"../../client/v2\";\nimport type { PredictClientV2 } from \"../../client/v2\";\nimport { DEFAULT_PAGE_SIZE } from \"../../consts\";\n\nexport type { V2ProviderSource };\n\n/**\n * Selection emitted by CategoriesWidgetV2.\n *\n * Duplicated from categories.v2.script to avoid pulling in the component\n * barrel (which has React dependencies) into server-only bundles.\n */\nexport interface TagSlugSelection {\n categorySlug: string | null;\n tagSlug: string | null;\n}\n\n/**\n * Resolve a `TagSlugSelection` to a single `tag_slug` string for the v2 API.\n */\nexport function resolveTagSlug(\n selection: TagSlugSelection | null | undefined,\n): string | undefined {\n if (!selection) return undefined;\n return selection.tagSlug ?? selection.categorySlug ?? undefined;\n}\n\n/**\n * Input accepted by {@link resolveEventsV2Params}. All fields optional;\n * defaults match the client-side `useEventsV2` hook's initial state.\n */\nexport interface ResolveEventsV2ParamsInput {\n tagSlugSelection?: TagSlugSelection | null;\n limit?: number;\n status?: V2EventStatus;\n sort_by?: V2EventSortField;\n sort_asc?: boolean;\n source?: V2ProviderSource;\n with_markets?: boolean;\n}\n\n/**\n * Build a clean `V2ListEventsParams` from loose user inputs.\n *\n * Server-side `prefetchInfiniteQuery` and client-side `useEventsV2` must both\n * use this function to guarantee identical query keys.\n */\nexport function resolveEventsV2Params(\n input: ResolveEventsV2ParamsInput = {},\n): V2ListEventsParams {\n const {\n tagSlugSelection,\n limit = DEFAULT_PAGE_SIZE,\n status = \"open\",\n with_markets = true,\n source,\n sort_by,\n sort_asc,\n } = input;\n const tag_slug = resolveTagSlug(tagSlugSelection);\n return {\n limit,\n status,\n with_markets,\n ...(source ? { source } : {}),\n ...(tag_slug ? { tag_slug } : {}),\n ...(sort_by ? { sort_by } : {}),\n ...(sort_asc !== undefined ? { sort_asc } : {}),\n };\n}\n\n/** Stable TanStack Query key for the v2 events infinite query. */\nexport function eventsV2InfiniteQueryKey(\n params: V2ListEventsParams,\n): unknown[] {\n return [\"predict-v2\", \"events-infinite\", params];\n}\n\n/**\n * Fetch a single page of v2 events. Can be used outside of React\n * (e.g. in Server Components, loaders, or tests).\n */\nexport async function fetchEventsV2Page(\n client: PredictClientV2,\n params: V2ListEventsParams,\n): Promise<V2Page<V2Event>> {\n return client.listEvents(params);\n}\n\n// ---------------------------------------------------------------------------\n// Single-event helpers (also server-safe)\n// ---------------------------------------------------------------------------\n\n/** Stable TanStack Query key for a single v2 event. */\nexport function eventV2QueryKey(\n slug: string,\n source?: V2ProviderSource,\n): unknown[] {\n return [\"predict-v2\", \"event\", slug, source];\n}\n\n/**\n * Fetch a single v2 event. Can be used outside of React\n * (e.g. in Server Components, loaders, or tests).\n */\nexport async function fetchEventV2(\n client: PredictClientV2,\n slug: string,\n source?: V2ProviderSource,\n): Promise<V2Event> {\n return client.getEvent(slug, source);\n}\n\nexport type { V2Event, V2ListEventsParams, V2Page };\n","import { httpGet, httpPost, httpDelete } from \"@liberfi.io/utils\";\nimport type {\n V2CancelOrderResult,\n V2Candlestick,\n V2DFlowQuoteRequest,\n V2DFlowQuoteResponse,\n V2DFlowSubmitRequest,\n V2DFlowSubmitResponse,\n V2Event,\n V2ListCandlesticksParams,\n V2ListEventsParams,\n V2ListMarketTradesParams,\n V2ListOrdersParams,\n V2ListTradesByWalletParams,\n V2Market,\n V2Orderbook,\n V2Page,\n V2PositionsResponse,\n V2PriceHistoryRange,\n V2PriceHistoryResponse,\n V2ProviderSource,\n V2SimilarEventsParams,\n V2Trade,\n V2UserOrder,\n} from \"./types\";\n\n/**\n * Build a URL query string from a params object.\n * `undefined` and `null` values are omitted.\n * Boolean values are serialised as \"true\" / \"false\" strings.\n */\nfunction buildV2Query(params: Record<string, unknown>): string {\n const qs = new URLSearchParams();\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n qs.set(key, String(value));\n }\n }\n const str = qs.toString();\n return str ? `?${str}` : \"\";\n}\n\n/**\n * HTTP client for the prediction-server REST API (v2 / prediction-server backend).\n *\n * Covers `GET /api/v1/events` (listEvents), `GET /api/v1/events/:slug` (getEvent),\n * and `GET /api/v1/markets/:slug` (getMarket).\n *\n * This client is intentionally decoupled from the legacy `DflowPredictClient` so\n * that both can be used in parallel during the incremental migration from the old\n * DFlow-direct integration to the unified prediction-server backend.\n *\n * @example\n * ```ts\n * const client = new PredictClientV2(\"https://api.example.com\");\n * const page = await client.listEvents({ status: \"open\", limit: 20 });\n * const event = await client.getEvent(\"will-trump-win-2024\");\n * const market = await client.getMarket(\"will-trump-win-2024-yes\");\n * ```\n */\nexport class PredictClientV2 {\n constructor(private readonly endpoint: string) {}\n\n /**\n * List prediction events with optional filtering, sorting, and pagination.\n *\n * Maps to `GET /api/v1/events`.\n *\n * @param params - Optional query parameters (filter, sort, pagination).\n * @returns A paginated page of events.\n */\n async listEvents(params?: V2ListEventsParams): Promise<V2Page<V2Event>> {\n const query = buildV2Query((params ?? {}) as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/events${query}`;\n return await httpGet<V2Page<V2Event>>(url);\n }\n\n /**\n * Fetch a single prediction event by its slug.\n *\n * Maps to `GET /api/v1/events/:slug?source=...`.\n *\n * @param slug - Canonical event slug (e.g. \"will-trump-win-2024\" for Polymarket\n * or \"KXBTCD-25FEB-T68000\" for DFlow).\n * @param source - Upstream provider (`\"dflow\"` or `\"polymarket\"`).\n * @returns The matching event.\n * @throws When the server responds with 404 or any other non-2xx status.\n */\n async getEvent(slug: string, source?: V2ProviderSource): Promise<V2Event> {\n const query = source ? buildV2Query({ source }) : \"\";\n const url = `${this.endpoint}/api/v1/events/${encodeURIComponent(slug)}${query}`;\n return await httpGet<V2Event>(url);\n }\n\n /**\n * Fetch a single prediction market by its slug.\n *\n * Maps to `GET /api/v1/markets/:slug?source=...`.\n *\n * @param slug - Canonical market slug.\n * @param source - Upstream provider (`\"dflow\"` or `\"polymarket\"`).\n * @returns The matching market.\n * @throws When the server responds with 404 or any other non-2xx status.\n */\n async getMarket(slug: string, source?: V2ProviderSource): Promise<V2Market> {\n const query = source ? buildV2Query({ source }) : \"\";\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}${query}`;\n return await httpGet<V2Market>(url);\n }\n\n // -------------------------------------------------------------------------\n // Market sub-resources\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/markets/:slug/orderbook?source=...`. */\n async getOrderbook(\n slug: string,\n source: V2ProviderSource,\n ): Promise<V2Orderbook> {\n const query = buildV2Query({ source });\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/orderbook${query}`;\n return await httpGet<V2Orderbook>(url);\n }\n\n /** Maps to `GET /api/v1/markets/:slug/trades?source=...`. */\n async listMarketTrades(\n slug: string,\n params: V2ListMarketTradesParams,\n ): Promise<V2Page<V2Trade>> {\n const query = buildV2Query(params as unknown as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/trades${query}`;\n return await httpGet<V2Page<V2Trade>>(url);\n }\n\n /** Maps to `GET /api/v1/markets/:slug/price-history?source=...&range=...`. */\n async getPriceHistory(\n slug: string,\n source: V2ProviderSource,\n range?: V2PriceHistoryRange,\n ): Promise<V2PriceHistoryResponse> {\n const query = buildV2Query({ source, range });\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/price-history${query}`;\n return await httpGet<V2PriceHistoryResponse>(url);\n }\n\n /** Maps to `GET /api/v1/markets/:slug/candlesticks?interval=...&limit=...`. */\n async listCandlesticks(\n slug: string,\n params?: V2ListCandlesticksParams,\n ): Promise<V2Candlestick[]> {\n const query = buildV2Query((params ?? {}) as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/markets/${encodeURIComponent(slug)}/candlesticks${query}`;\n return await httpGet<V2Candlestick[]>(url);\n }\n\n // -------------------------------------------------------------------------\n // Event sub-resources\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/events/:slug/similar?source=...`. */\n async getSimilarEvents(\n slug: string,\n source: V2ProviderSource,\n params?: V2SimilarEventsParams,\n ): Promise<V2Event[]> {\n const query = buildV2Query({ source, ...params });\n const url = `${this.endpoint}/api/v1/events/${encodeURIComponent(slug)}/similar${query}`;\n return await httpGet<V2Event[]>(url);\n }\n\n // -------------------------------------------------------------------------\n // Positions\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/positions?source=...&user=...`. */\n async getPositions(\n source: V2ProviderSource,\n user: string,\n ): Promise<V2PositionsResponse> {\n const query = buildV2Query({ source, user });\n const url = `${this.endpoint}/api/v1/positions${query}`;\n return await httpGet<V2PositionsResponse>(url);\n }\n\n // -------------------------------------------------------------------------\n // Orders\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/orders?source=...&wallet_address=...`. */\n async listOrders(params: V2ListOrdersParams): Promise<V2Page<V2UserOrder>> {\n const query = buildV2Query(params as unknown as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/orders${query}`;\n return await httpGet<V2Page<V2UserOrder>>(url);\n }\n\n /** Maps to `GET /api/v1/orders/:id?source=...`. */\n async getOrder(id: string, source: V2ProviderSource): Promise<V2UserOrder> {\n const query = buildV2Query({ source });\n const url = `${this.endpoint}/api/v1/orders/${encodeURIComponent(id)}${query}`;\n return await httpGet<V2UserOrder>(url);\n }\n\n /** Maps to `DELETE /api/v1/orders/:id?source=...`. */\n async cancelOrder(\n id: string,\n source: V2ProviderSource,\n ): Promise<V2CancelOrderResult> {\n const query = buildV2Query({ source });\n const url = `${this.endpoint}/api/v1/orders/${encodeURIComponent(id)}${query}`;\n return await httpDelete<V2CancelOrderResult>(url);\n }\n\n // -------------------------------------------------------------------------\n // DFlow trading\n // -------------------------------------------------------------------------\n\n /** Maps to `POST /api/v1/orders/dflow/quote`. */\n async createDFlowQuote(\n body: V2DFlowQuoteRequest,\n ): Promise<V2DFlowQuoteResponse> {\n const url = `${this.endpoint}/api/v1/orders/dflow/quote`;\n return await httpPost<V2DFlowQuoteResponse>(url, body);\n }\n\n /** Maps to `POST /api/v1/orders/dflow/submit`. */\n async submitDFlowTransaction(\n body: V2DFlowSubmitRequest,\n ): Promise<V2DFlowSubmitResponse> {\n const url = `${this.endpoint}/api/v1/orders/dflow/submit`;\n return await httpPost<V2DFlowSubmitResponse>(url, body);\n }\n\n // -------------------------------------------------------------------------\n // Trades by wallet\n // -------------------------------------------------------------------------\n\n /** Maps to `GET /api/v1/trades?source=...&wallet=...`. */\n async listTradesByWallet(\n params: V2ListTradesByWalletParams,\n ): Promise<V2Page<V2Trade>> {\n const query = buildV2Query(params as unknown as Record<string, unknown>);\n const url = `${this.endpoint}/api/v1/trades${query}`;\n return await httpGet<V2Page<V2Trade>>(url);\n }\n}\n\n/**\n * Factory function for `PredictClientV2`.\n *\n * @param endpoint - Base URL of the prediction-server, without a trailing slash.\n */\nexport function createPredictClientV2(endpoint: string): PredictClientV2 {\n return new PredictClientV2(endpoint);\n}\n"]}
|