@liberfi.io/ui-predict 0.1.70 → 0.1.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
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-DgC5flVr.js';
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
2
 
3
3
  /** Default page size for list queries */
4
4
  declare const DEFAULT_PAGE_SIZE = 48;
@@ -1,4 +1,4 @@
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-DgC5flVr.mjs';
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
2
 
3
3
  /** Default page size for list queries */
4
4
  declare const DEFAULT_PAGE_SIZE = 48;
package/dist/server.d.mts CHANGED
@@ -1,2 +1,2 @@
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-Cb45Eqd0.mjs';
2
- export { P as PredictClientV2, b as V2Event, V as V2EventSortField, d as V2EventStatus, f as V2ListEventsParams, c as V2Market, h as V2MarketResult, i as V2MarketStatus, j as V2Outcome, e as V2Page, k as V2ProviderMeta, a as V2ProviderSource, l as V2SettlementSource, m as V2Tag, g as createPredictClientV2 } from './client-DgC5flVr.mjs';
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 CHANGED
@@ -1,2 +1,2 @@
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-CUXRrxGG.js';
2
- export { P as PredictClientV2, b as V2Event, V as V2EventSortField, d as V2EventStatus, f as V2ListEventsParams, c as V2Market, h as V2MarketResult, i as V2MarketStatus, j as V2Outcome, e as V2Page, k as V2ProviderMeta, a as V2ProviderSource, l as V2SettlementSource, m as V2Tag, g as createPredictClientV2 } from './client-DgC5flVr.js';
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 CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var utils=require('@liberfi.io/utils');var c=48;function _(e){if(e)return e.tagSlug??e.categorySlug??void 0}function g(e={}){let{tagSlugSelection:t,limit:r=48,status:o="open",with_markets:s=true,source:p,sort_by:v,sort_asc:l}=e,P=_(t);return {limit:r,status:o,with_markets:s,...p?{source:p}:{},...P?{tag_slug:P}:{},...v?{sort_by:v}:{},...l!==void 0?{sort_asc:l}:{}}}function R(e){return ["predict-v2","events-infinite",e]}async function S(e,t){return e.listEvents(t)}function y(e,t){return ["predict-v2","event",e,t]}async function m(e,t,r){return e.getEvent(t,r)}function V(e){let t=new URLSearchParams;for(let[o,s]of Object.entries(e))s!=null&&t.set(o,String(s));let r=t.toString();return r?`?${r}`:""}var a=class{constructor(t){this.endpoint=t;}async listEvents(t){let r=V(t??{}),o=`${this.endpoint}/api/v1/events${r}`;return await utils.httpGet(o)}async getEvent(t,r){let o=r?V({source:r}):"",s=`${this.endpoint}/api/v1/events/${encodeURIComponent(t)}${o}`;return await utils.httpGet(s)}async getMarket(t,r){let o=r?V({source:r}):"",s=`${this.endpoint}/api/v1/markets/${encodeURIComponent(t)}${o}`;return await utils.httpGet(s)}};function d(e){return new a(e)}exports.DEFAULT_PAGE_SIZE=c;exports.PredictClientV2=a;exports.createPredictClientV2=d;exports.eventV2QueryKey=y;exports.eventsV2InfiniteQueryKey=R;exports.fetchEventV2=m;exports.fetchEventsV2Page=S;exports.resolveEventsV2Params=g;exports.resolveTagSlug=_;//# sourceMappingURL=server.js.map
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
2
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
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","createPredictClientV2"],"mappings":"oDACO,IAAMA,CAAAA,CAAoB,GCgC1B,SAASC,CAAAA,CACdC,CAAAA,CACoB,CACpB,GAAKA,EACL,OAAOA,CAAAA,CAAU,OAAA,EAAWA,CAAAA,CAAU,YAAA,EAAgB,MACxD,CAsBO,SAASC,CAAAA,CACdC,EAAoC,EAAC,CACjB,CACpB,GAAM,CACJ,gBAAA,CAAAC,CAAAA,CACA,KAAA,CAAAC,CAAAA,CAAQ,GACR,MAAA,CAAAC,CAAAA,CAAS,MAAA,CACT,YAAA,CAAAC,CAAAA,CAAe,IAAA,CACf,OAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CACF,CAAA,CAAIP,EACEQ,CAAAA,CAAWX,CAAAA,CAAeI,CAAgB,CAAA,CAChD,OAAO,CACL,MAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,GAAIC,EAAS,CAAE,MAAA,CAAAA,CAAO,CAAA,CAAI,EAAC,CAC3B,GAAIG,CAAA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Dc,CAAAA,CAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,cAAA,EAAiBD,CAAK,CAAA,CAAA,CAClD,OAAO,MAAME,aAAAA,CAAyBD,CAAG,CAC3C,CAaA,MAAM,QAAA,CAASV,CAAAA,CAAcT,CAAAA,CAA6C,CACxE,IAAMkB,EAAQlB,CAAAA,CAASW,CAAAA,CAAa,CAAE,MAAA,CAAAX,CAAO,CAAC,EAAI,EAAA,CAC5CmB,CAAAA,CAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,eAAA,EAAkB,mBAAmBV,CAAI,CAAC,GAAGS,CAAK,CAAA,CAAA,CAC9E,OAAO,MAAME,aAAAA,CAAiBD,CAAG,CACnC,CAYA,MAAM,UAAUV,CAAAA,CAAcT,CAAAA,CAA8C,CAC1E,IAAMkB,CAAAA,CAAQlB,CAAAA,CAASW,EAAa,CAAE,MAAA,CAAAX,CAAO,CAAC,CAAA,CAAI,EAAA,CAC5CmB,EAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,gBAAA,EAAmB,kBAAA,CAAmBV,CAAI,CAAC,CAAA,EAAGS,CAAK,CAAA,CAAA,CAC/E,OAAO,MAAME,aAAAA,CAAkBD,CAAG,CACpC,CACF,EAOO,SAASE,CAAAA,CAAsBJ,CAAAA,CAAmC,CACvE,OAAO,IAAID,CAAAA,CAAgBC,CAAQ,CACrC","file":"server.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 } from \"@liberfi.io/utils\";\nimport type {\n V2Event,\n V2ListEventsParams,\n V2Market,\n V2Page,\n V2ProviderSource,\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/**\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"]}
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,CA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G,IAAA,CAAK,QAAQ,CAAA,2BAAA,CAAA,CAC5B,OAAO,MAAMO,cAAAA,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,cAAyBD,CAAG,CAC3C,CACF,EAOO,SAASQ,EAAsBV,CAAAA,CAAmC,CACvE,OAAO,IAAID,CAAAA,CAAgBC,CAAQ,CACrC","file":"server.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 CHANGED
@@ -1,2 +1,2 @@
1
- import {httpGet}from'@liberfi.io/utils';var c=48;function _(e){if(e)return e.tagSlug??e.categorySlug??void 0}function g(e={}){let{tagSlugSelection:t,limit:r=48,status:o="open",with_markets:s=true,source:p,sort_by:v,sort_asc:l}=e,P=_(t);return {limit:r,status:o,with_markets:s,...p?{source:p}:{},...P?{tag_slug:P}:{},...v?{sort_by:v}:{},...l!==void 0?{sort_asc:l}:{}}}function R(e){return ["predict-v2","events-infinite",e]}async function S(e,t){return e.listEvents(t)}function y(e,t){return ["predict-v2","event",e,t]}async function m(e,t,r){return e.getEvent(t,r)}function V(e){let t=new URLSearchParams;for(let[o,s]of Object.entries(e))s!=null&&t.set(o,String(s));let r=t.toString();return r?`?${r}`:""}var a=class{constructor(t){this.endpoint=t;}async listEvents(t){let r=V(t??{}),o=`${this.endpoint}/api/v1/events${r}`;return await httpGet(o)}async getEvent(t,r){let o=r?V({source:r}):"",s=`${this.endpoint}/api/v1/events/${encodeURIComponent(t)}${o}`;return await httpGet(s)}async getMarket(t,r){let o=r?V({source:r}):"",s=`${this.endpoint}/api/v1/markets/${encodeURIComponent(t)}${o}`;return await httpGet(s)}};function d(e){return new a(e)}export{c as DEFAULT_PAGE_SIZE,a as PredictClientV2,d as createPredictClientV2,y as eventV2QueryKey,R as eventsV2InfiniteQueryKey,m as fetchEventV2,S as fetchEventsV2Page,g as resolveEventsV2Params,_ as resolveTagSlug};//# sourceMappingURL=server.mjs.map
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
2
  //# sourceMappingURL=server.mjs.map
@@ -1 +1 @@
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","createPredictClientV2"],"mappings":"wCACO,IAAMA,CAAAA,CAAoB,GCgC1B,SAASC,CAAAA,CACdC,CAAAA,CACoB,CACpB,GAAKA,EACL,OAAOA,CAAAA,CAAU,OAAA,EAAWA,CAAAA,CAAU,YAAA,EAAgB,MACxD,CAsBO,SAASC,CAAAA,CACdC,EAAoC,EAAC,CACjB,CACpB,GAAM,CACJ,gBAAA,CAAAC,CAAAA,CACA,KAAA,CAAAC,CAAAA,CAAQ,GACR,MAAA,CAAAC,CAAAA,CAAS,MAAA,CACT,YAAA,CAAAC,CAAAA,CAAe,IAAA,CACf,OAAAC,CAAAA,CACA,OAAA,CAAAC,CAAAA,CACA,QAAA,CAAAC,CACF,CAAA,CAAIP,EACEQ,CAAAA,CAAWX,CAAAA,CAAeI,CAAgB,CAAA,CAChD,OAAO,CACL,MAAAC,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,YAAA,CAAAC,CAAAA,CACA,GAAIC,EAAS,CAAE,MAAA,CAAAA,CAAO,CAAA,CAAI,EAAC,CAC3B,GAAIG,CAAAA,CAAW,CAAE,QAAA,CAAAA,CAAS,CAAA,CAAI,GAC9B,GAAIF,CAAAA,CAAU,CAAE,OAAA,CAAAA,CAAQ,EAAI,EAAC,CAC7B,GAAIC,CAAAA,GAAa,MAAA,CAAY,CAAE,SAAAA,CAAS,CAAA,CAAI,EAC9C,CACF,CAGO,SAASE,CAAAA,CACdC,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,CACd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OAAO,MAAME,OAAAA,CAAiBD,CAAG,CACnC,CAYA,MAAM,UAAUV,CAAAA,CAAcT,CAAAA,CAA8C,CAC1E,IAAMkB,CAAAA,CAAQlB,CAAAA,CAASW,EAAa,CAAE,MAAA,CAAAX,CAAO,CAAC,CAAA,CAAI,EAAA,CAC5CmB,EAAM,CAAA,EAAG,IAAA,CAAK,QAAQ,CAAA,gBAAA,EAAmB,kBAAA,CAAmBV,CAAI,CAAC,CAAA,EAAGS,CAAK,CAAA,CAAA,CAC/E,OAAO,MAAME,OAAAA,CAAkBD,CAAG,CACpC,CACF,EAOO,SAASE,CAAAA,CAAsBJ,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 } from \"@liberfi.io/utils\";\nimport type {\n V2Event,\n V2ListEventsParams,\n V2Market,\n V2Page,\n V2ProviderSource,\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/**\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"]}
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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esContent":["/** 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liberfi.io/ui-predict",
3
- "version": "0.1.70",
3
+ "version": "0.1.71",
4
4
  "description": "Predict Components for Liberfi React SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -35,13 +35,13 @@
35
35
  "react-window": "^2.2.3",
36
36
  "react-window-infinite-loader": "^2.0.0",
37
37
  "recharts": "^3.5.1",
38
- "@liberfi.io/hooks": "0.1.80",
39
- "@liberfi.io/i18n": "0.1.85",
40
- "@liberfi.io/react": "0.1.60",
41
- "@liberfi.io/types": "0.1.83",
42
- "@liberfi.io/ui": "0.1.83",
43
- "@liberfi.io/utils": "0.1.80",
44
- "@liberfi.io/wallet-connector": "0.1.74"
38
+ "@liberfi.io/hooks": "0.1.81",
39
+ "@liberfi.io/i18n": "0.1.86",
40
+ "@liberfi.io/react": "0.1.61",
41
+ "@liberfi.io/types": "0.1.84",
42
+ "@liberfi.io/ui": "0.1.84",
43
+ "@liberfi.io/utils": "0.1.81",
44
+ "@liberfi.io/wallet-connector": "0.1.75"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@tanstack/react-query": "^5.90.2",
@@ -54,15 +54,15 @@
54
54
  "react-dom": "^19.1.1",
55
55
  "tsup": "^8.5.0",
56
56
  "typescript": "^5.9.2",
57
- "@liberfi.io/ui-scaffold": "0.1.82",
58
- "tsconfig": "0.1.71"
57
+ "@liberfi.io/ui-scaffold": "0.1.83",
58
+ "tsconfig": "0.1.72"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@tanstack/react-query": "^5.90.2",
62
62
  "jotai": ">=2.15.1",
63
63
  "react": ">=18",
64
64
  "react-dom": ">=18",
65
- "@liberfi.io/ui-scaffold": "0.1.82"
65
+ "@liberfi.io/ui-scaffold": "0.1.83"
66
66
  },
67
67
  "scripts": {
68
68
  "dev": "tsup --watch",
@@ -1,201 +0,0 @@
1
- /**
2
- * V2 types for the prediction-server REST API (/api/v1/events).
3
- *
4
- * These types are intentionally isolated from the legacy client types so that
5
- * the v1 (DFlow) and v2 (prediction-server) clients can coexist and be migrated
6
- * incrementally.
7
- *
8
- * Mirrors: github.com/liberfi-io/prediction-server/internal/domain
9
- */
10
- /** Upstream data provider that produced a domain object. */
11
- type V2ProviderSource = "dflow" | "polymarket";
12
- /**
13
- * Provider-specific metadata attached to every domain aggregate.
14
- * Keys are namespaced field paths, e.g. "polymarket.conditionId" or "dflow.yesMint".
15
- * Values are raw JSON-decoded values.
16
- */
17
- type V2ProviderMeta = Record<string, unknown>;
18
- /** Provider-sourced label attached to an Event. */
19
- interface V2Tag {
20
- slug: string;
21
- label: string;
22
- source: V2ProviderSource;
23
- provider_meta?: V2ProviderMeta;
24
- }
25
- /** Lifecycle status of a prediction event (normalised across all providers). */
26
- type V2EventStatus = "pending" | "open" | "closed" | "voided";
27
- /** Settlement / resolution data source for an event. */
28
- interface V2SettlementSource {
29
- url: string;
30
- name?: string;
31
- }
32
- /** Root aggregate for a prediction event from the prediction-server API. */
33
- interface V2Event {
34
- /** Internal database surrogate key (absent when not yet persisted). */
35
- id?: number;
36
- /**
37
- * Canonical business key shared across all providers.
38
- * - DFlow: ticker (e.g. "KXBTCD-25FEB-T68000")
39
- * - Polymarket: slug (e.g. "will-trump-win-2024")
40
- */
41
- slug: string;
42
- title: string;
43
- subtitle?: string;
44
- description?: string;
45
- image_url?: string;
46
- status: V2EventStatus;
47
- /** ISO 8601 timestamp; absent if the provider does not supply it. */
48
- start_at?: string;
49
- end_at?: string;
50
- created_at?: string;
51
- updated_at?: string;
52
- /** Provider-sourced labels for display only. */
53
- tags?: V2Tag[];
54
- /** All values are USD amounts. */
55
- volume?: number;
56
- volume_24h?: number;
57
- liquidity?: number;
58
- open_interest?: number;
59
- settlement_sources?: V2SettlementSource[];
60
- /** Nested markets; omitted when the request used `with_markets=false`. */
61
- markets?: V2Market[];
62
- source: V2ProviderSource;
63
- provider_meta?: V2ProviderMeta;
64
- }
65
- /** Lifecycle status of a prediction market (normalised across all providers). */
66
- type V2MarketStatus = "pending" | "open" | "closed" | "voided";
67
- /** Final resolution of a closed market. Empty string means unresolved. */
68
- type V2MarketResult = "yes" | "no" | "voided" | "";
69
- /** One possible outcome in a binary (or multi-outcome) prediction market. */
70
- interface V2Outcome {
71
- /** Display name, e.g. "Yes" or "No". */
72
- label: string;
73
- /** Current implied probability [0, 1]. */
74
- price?: number;
75
- best_bid?: number;
76
- best_ask?: number;
77
- }
78
- /** Tradeable prediction outcome within an Event. */
79
- interface V2Market {
80
- id?: number;
81
- event_id?: number;
82
- slug: string;
83
- event_slug: string;
84
- question: string;
85
- description?: string;
86
- /** Resolution/settlement rules in order. */
87
- rules?: string[];
88
- status: V2MarketStatus;
89
- result?: V2MarketResult;
90
- start_at?: string;
91
- end_at?: string;
92
- expires_at?: string;
93
- created_at?: string;
94
- updated_at?: string;
95
- /** Always present; binary markets have exactly 2 outcomes (YES at [0], NO at [1]). */
96
- outcomes: V2Outcome[];
97
- volume?: number;
98
- volume_24h?: number;
99
- liquidity?: number;
100
- open_interest?: number;
101
- source: V2ProviderSource;
102
- provider_meta?: V2ProviderMeta;
103
- }
104
- /** Generic paginated result set returned by the prediction-server list endpoints. */
105
- interface V2Page<T> {
106
- items: T[];
107
- next_cursor?: string;
108
- has_more?: boolean;
109
- limit?: number;
110
- /** Not all backends support total count. */
111
- total?: number;
112
- }
113
- /** Valid sort fields accepted by `GET /api/v1/events`. */
114
- type V2EventSortField = "volume" | "volume_24h" | "liquidity" | "open_interest" | "end_at" | "start_at" | "created_at";
115
- /** Query parameters for `listEvents`. All fields are optional. */
116
- interface V2ListEventsParams {
117
- /** Page size. Server default: 20. */
118
- limit?: number;
119
- /** Opaque pagination cursor returned by the previous page's `next_cursor`. */
120
- cursor?: string;
121
- /** Filter by event lifecycle status. */
122
- status?: V2EventStatus;
123
- /** Filter by upstream provider. */
124
- source?: V2ProviderSource;
125
- /** Unified navigation tag slug (e.g. "politics", "sports"). */
126
- tag_slug?: string;
127
- /** Full-text search query. */
128
- search?: string;
129
- /** Field to sort by. */
130
- sort_by?: V2EventSortField;
131
- /** When `true`, sort ascending. Defaults to descending. */
132
- sort_asc?: boolean;
133
- /**
134
- * When `false`, markets are omitted from each event for lighter payloads.
135
- * Defaults to `true` on the server.
136
- */
137
- with_markets?: boolean;
138
- }
139
-
140
- /**
141
- * HTTP client for the prediction-server REST API (v2 / prediction-server backend).
142
- *
143
- * Covers `GET /api/v1/events` (listEvents), `GET /api/v1/events/:slug` (getEvent),
144
- * and `GET /api/v1/markets/:slug` (getMarket).
145
- *
146
- * This client is intentionally decoupled from the legacy `DflowPredictClient` so
147
- * that both can be used in parallel during the incremental migration from the old
148
- * DFlow-direct integration to the unified prediction-server backend.
149
- *
150
- * @example
151
- * ```ts
152
- * const client = new PredictClientV2("https://api.example.com");
153
- * const page = await client.listEvents({ status: "open", limit: 20 });
154
- * const event = await client.getEvent("will-trump-win-2024");
155
- * const market = await client.getMarket("will-trump-win-2024-yes");
156
- * ```
157
- */
158
- declare class PredictClientV2 {
159
- private readonly endpoint;
160
- constructor(endpoint: string);
161
- /**
162
- * List prediction events with optional filtering, sorting, and pagination.
163
- *
164
- * Maps to `GET /api/v1/events`.
165
- *
166
- * @param params - Optional query parameters (filter, sort, pagination).
167
- * @returns A paginated page of events.
168
- */
169
- listEvents(params?: V2ListEventsParams): Promise<V2Page<V2Event>>;
170
- /**
171
- * Fetch a single prediction event by its slug.
172
- *
173
- * Maps to `GET /api/v1/events/:slug?source=...`.
174
- *
175
- * @param slug - Canonical event slug (e.g. "will-trump-win-2024" for Polymarket
176
- * or "KXBTCD-25FEB-T68000" for DFlow).
177
- * @param source - Upstream provider (`"dflow"` or `"polymarket"`).
178
- * @returns The matching event.
179
- * @throws When the server responds with 404 or any other non-2xx status.
180
- */
181
- getEvent(slug: string, source?: V2ProviderSource): Promise<V2Event>;
182
- /**
183
- * Fetch a single prediction market by its slug.
184
- *
185
- * Maps to `GET /api/v1/markets/:slug?source=...`.
186
- *
187
- * @param slug - Canonical market slug.
188
- * @param source - Upstream provider (`"dflow"` or `"polymarket"`).
189
- * @returns The matching market.
190
- * @throws When the server responds with 404 or any other non-2xx status.
191
- */
192
- getMarket(slug: string, source?: V2ProviderSource): Promise<V2Market>;
193
- }
194
- /**
195
- * Factory function for `PredictClientV2`.
196
- *
197
- * @param endpoint - Base URL of the prediction-server, without a trailing slash.
198
- */
199
- declare function createPredictClientV2(endpoint: string): PredictClientV2;
200
-
201
- export { PredictClientV2 as P, type V2EventSortField as V, type V2ProviderSource as a, type V2Event as b, type V2Market as c, type V2EventStatus as d, type V2Page as e, type V2ListEventsParams as f, createPredictClientV2 as g, type V2MarketResult as h, type V2MarketStatus as i, type V2Outcome as j, type V2ProviderMeta as k, type V2SettlementSource as l, type V2Tag as m };