@pear-protocol/core-sdk 1.17.0 → 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,28 @@
1
1
  import { searchKalshiTriggers, fetchKalshiMarketNames } from './kalshi';
2
2
  import { searchPolymarketTriggers, fetchPolymarketMarketNames } from './polymarket';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  class External {
7
+ static {
8
+ __name(this, "External");
9
+ }
5
10
  triggers = {
6
11
  kalshi: {
7
- marketNames: async (tickers) => {
12
+ marketNames: /* @__PURE__ */ __name(async (tickers) => {
8
13
  return fetchKalshiMarketNames(tickers);
9
- },
10
- search: async (params = {}) => {
14
+ }, "marketNames"),
15
+ search: /* @__PURE__ */ __name(async (params = {}) => {
11
16
  return searchKalshiTriggers(params);
12
- }
17
+ }, "search")
13
18
  },
14
19
  polymarket: {
15
- marketNames: async (ids) => {
20
+ marketNames: /* @__PURE__ */ __name(async (ids) => {
16
21
  return fetchPolymarketMarketNames(ids);
17
- },
18
- search: async (params = {}) => {
22
+ }, "marketNames"),
23
+ search: /* @__PURE__ */ __name(async (params = {}) => {
19
24
  return searchPolymarketTriggers(params);
20
- }
25
+ }, "search")
21
26
  }
22
27
  };
23
28
  }
@@ -1,5 +1,7 @@
1
1
  import { proxyFetch } from '@pear-protocol/utils';
2
2
 
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
5
  const BASE_URL = "https://api.elections.kalshi.com";
4
6
  const BATCH_SIZE = 100;
5
7
  async function fetchKalshiMarketNames(tickers) {
@@ -9,13 +11,19 @@ async function fetchKalshiMarketNames(tickers) {
9
11
  const url = new URL(`${BASE_URL}/trade-api/v2/markets`);
10
12
  url.searchParams.set("tickers", batch.join(","));
11
13
  url.searchParams.set("limit", String(BATCH_SIZE));
12
- const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
14
+ const response = await proxyFetch(url, {
15
+ method: "GET",
16
+ headers: {
17
+ accept: "application/json"
18
+ }
19
+ });
13
20
  if (!response.ok) throw new Error(`Kalshi API error: ${response.status} ${response.statusText}`);
14
21
  const data = await response.json();
15
22
  for (const m of data.markets ?? []) result.set(m.ticker, m.title);
16
23
  }
17
24
  return result;
18
25
  }
26
+ __name(fetchKalshiMarketNames, "fetchKalshiMarketNames");
19
27
  async function searchKalshiTriggers(params = {}) {
20
28
  const url = new URL(`${BASE_URL}/v1/search/series`);
21
29
  url.searchParams.set("order_by", "trending");
@@ -24,14 +32,23 @@ async function searchKalshiTriggers(params = {}) {
24
32
  if (params.category) url.searchParams.set("category", params.category);
25
33
  if (params.search) url.searchParams.set("query", params.search);
26
34
  if (params.cursor) url.searchParams.set("cursor", params.cursor);
27
- const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
28
- if (!response.ok) return { triggers: [], nextCursor: null };
35
+ const response = await proxyFetch(url, {
36
+ method: "GET",
37
+ headers: {
38
+ accept: "application/json"
39
+ }
40
+ });
41
+ if (!response.ok) return {
42
+ triggers: [],
43
+ nextCursor: null
44
+ };
29
45
  const data = await response.json();
30
46
  return {
31
47
  triggers: (data.current_page ?? []).map(mapEventToTrigger),
32
48
  nextCursor: data.next_cursor || null
33
49
  };
34
50
  }
51
+ __name(searchKalshiTriggers, "searchKalshiTriggers");
35
52
  function mapEventToTrigger(event) {
36
53
  const imageUrl = `https://kalshi-public-docs.s3.amazonaws.com/series-images-webp/${event.event_ticker.split("-")[0]}.webp`;
37
54
  if (event.markets.length > 1) {
@@ -60,6 +77,7 @@ function mapEventToTrigger(event) {
60
77
  imageUrl
61
78
  };
62
79
  }
80
+ __name(mapEventToTrigger, "mapEventToTrigger");
63
81
  function mapMarketToOutcome(market) {
64
82
  return {
65
83
  id: market.ticker,
@@ -67,5 +85,6 @@ function mapMarketToOutcome(market) {
67
85
  oracle: market.last_price
68
86
  };
69
87
  }
88
+ __name(mapMarketToOutcome, "mapMarketToOutcome");
70
89
 
71
90
  export { fetchKalshiMarketNames, searchKalshiTriggers };
@@ -1,5 +1,7 @@
1
1
  import { proxyFetch } from '@pear-protocol/utils';
2
2
 
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
5
  const BASE_URL = "https://gamma-api.polymarket.com";
4
6
  const BATCH_SIZE = 100;
5
7
  async function fetchPolymarketMarketNames(ids) {
@@ -9,13 +11,19 @@ async function fetchPolymarketMarketNames(ids) {
9
11
  const url = new URL(`${BASE_URL}/markets`);
10
12
  for (const id of batch) url.searchParams.append("id", id);
11
13
  url.searchParams.set("limit", String(BATCH_SIZE));
12
- const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
14
+ const response = await proxyFetch(url, {
15
+ method: "GET",
16
+ headers: {
17
+ accept: "application/json"
18
+ }
19
+ });
13
20
  if (!response.ok) throw new Error(`Polymarket API error: ${response.status} ${response.statusText}`);
14
21
  const data = await response.json();
15
22
  for (const m of data) result.set(m.id, m.question ?? m.groupItemTitle ?? "");
16
23
  }
17
24
  return result;
18
25
  }
26
+ __name(fetchPolymarketMarketNames, "fetchPolymarketMarketNames");
19
27
  async function searchPolymarketTriggers(params = {}) {
20
28
  const url = new URL(`${BASE_URL}/events/keyset`);
21
29
  url.searchParams.set("closed", "false");
@@ -25,8 +33,16 @@ async function searchPolymarketTriggers(params = {}) {
25
33
  if (params.search) url.searchParams.set("title_search", params.search);
26
34
  if (params.category) url.searchParams.set("tag_slug", params.category);
27
35
  if (params.cursor) url.searchParams.set("after_cursor", params.cursor);
28
- const response = await proxyFetch(url, { method: "GET", headers: { accept: "application/json" } });
29
- if (!response.ok) return { triggers: [], nextCursor: null };
36
+ const response = await proxyFetch(url, {
37
+ method: "GET",
38
+ headers: {
39
+ accept: "application/json"
40
+ }
41
+ });
42
+ if (!response.ok) return {
43
+ triggers: [],
44
+ nextCursor: null
45
+ };
30
46
  const data = await response.json();
31
47
  const events = data.events ?? [];
32
48
  return {
@@ -34,6 +50,7 @@ async function searchPolymarketTriggers(params = {}) {
34
50
  nextCursor: data.next_cursor ?? null
35
51
  };
36
52
  }
53
+ __name(searchPolymarketTriggers, "searchPolymarketTriggers");
37
54
  function mapEventToTrigger(event) {
38
55
  const markets = (event.markets ?? []).filter((m) => m.active !== false && m.closed !== true);
39
56
  const [first] = markets;
@@ -63,6 +80,7 @@ function mapEventToTrigger(event) {
63
80
  imageUrl: event.image ?? event.icon ?? first.image ?? first.icon ?? null
64
81
  };
65
82
  }
83
+ __name(mapEventToTrigger, "mapEventToTrigger");
66
84
  function mapMarketToOutcome(market) {
67
85
  return {
68
86
  id: market.id,
@@ -70,6 +88,7 @@ function mapMarketToOutcome(market) {
70
88
  oracle: parseYesCents(market)
71
89
  };
72
90
  }
91
+ __name(mapMarketToOutcome, "mapMarketToOutcome");
73
92
  function parseYesCents(market) {
74
93
  const outcomes = parseStringArray(market.outcomes);
75
94
  const prices = parseStringArray(market.outcomePrices);
@@ -79,6 +98,7 @@ function parseYesCents(market) {
79
98
  if (!Number.isFinite(price)) return null;
80
99
  return Math.round(price * 1e4) / 100;
81
100
  }
101
+ __name(parseYesCents, "parseYesCents");
82
102
  function parseStringArray(value) {
83
103
  if (Array.isArray(value)) return value.map(String);
84
104
  if (!value) return [];
@@ -89,5 +109,6 @@ function parseStringArray(value) {
89
109
  return [];
90
110
  }
91
111
  }
112
+ __name(parseStringArray, "parseStringArray");
92
113
 
93
114
  export { fetchPolymarketMarketNames, searchPolymarketTriggers };
package/dist/http.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import { stringify } from 'qs';
2
2
  import { getBaseUrl, normalizeRequest, normalizeResponseData } from './utils';
3
3
 
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
6
  class HttpClient {
7
+ static {
8
+ __name(this, "HttpClient");
9
+ }
5
10
  baseUrl;
6
11
  logger;
7
12
  authMode;
@@ -23,17 +28,17 @@ class HttpClient {
23
28
  };
24
29
  }
25
30
  /**
26
- * Add a request middleware that runs before the request is sent.
27
- * Middlewares are executed in order.
28
- */
31
+ * Add a request middleware that runs before the request is sent.
32
+ * Middlewares are executed in order.
33
+ */
29
34
  useRequest(middleware) {
30
35
  this.requestMiddlewares.push(middleware);
31
36
  }
32
37
  /**
33
- * Add a response middleware that runs after the response is received.
34
- * Middlewares are executed in order.
35
- * The retry function allows retrying the request.
36
- */
38
+ * Add a response middleware that runs after the response is received.
39
+ * Middlewares are executed in order.
40
+ * The retry function allows retrying the request.
41
+ */
37
42
  useResponse(middleware) {
38
43
  this.responseMiddlewares.push(middleware);
39
44
  }
@@ -43,9 +48,9 @@ class HttpClient {
43
48
  const normalizedInput = this.normalizeInput(input, init);
44
49
  this.logRequest(normalizedInput, headers);
45
50
  const request = new Request(normalizedInput, normalizeRequest(init, headers, this.authMode));
46
- const executeRequest = async () => {
51
+ const executeRequest = /* @__PURE__ */ __name(async () => {
47
52
  let currentIndex = 0;
48
- const next = async () => {
53
+ const next = /* @__PURE__ */ __name(async () => {
49
54
  if (currentIndex < this.requestMiddlewares.length) {
50
55
  const middleware = this.requestMiddlewares[currentIndex++];
51
56
  if (middleware) {
@@ -53,30 +58,26 @@ class HttpClient {
53
58
  }
54
59
  }
55
60
  return await fetch(request);
56
- };
61
+ }, "next");
57
62
  return next();
58
- };
63
+ }, "executeRequest");
59
64
  let response = await executeRequest();
60
- const executeResponse = async (resp) => {
65
+ const executeResponse = /* @__PURE__ */ __name(async (resp) => {
61
66
  let currentIndex = 0;
62
- const processMiddlewares = async () => {
67
+ const processMiddlewares = /* @__PURE__ */ __name(async () => {
63
68
  if (currentIndex < this.responseMiddlewares.length) {
64
69
  const middleware = this.responseMiddlewares[currentIndex++];
65
70
  if (middleware) {
66
- return middleware(
67
- resp,
68
- async () => {
69
- const newResponse = await executeRequest();
70
- return executeResponse(newResponse);
71
- },
72
- request
73
- );
71
+ return middleware(resp, async () => {
72
+ const newResponse = await executeRequest();
73
+ return executeResponse(newResponse);
74
+ }, request);
74
75
  }
75
76
  }
76
77
  return resp;
77
- };
78
+ }, "processMiddlewares");
78
79
  return processMiddlewares();
79
- };
80
+ }, "executeResponse");
80
81
  response = await executeResponse(response);
81
82
  this.logger.debug(`Received response with status ${response.status}
82
83
  `);
@@ -110,7 +111,13 @@ class HttpClient {
110
111
  normalizedInput = new URL(fullPath, baseUrl.origin);
111
112
  if (init?.query) {
112
113
  const params = Object.fromEntries(normalizedInput.searchParams.entries());
113
- const stringifiedQuery = stringify({ ...params, ...init.query }, { skipNulls: true, arrayFormat: "repeat" });
114
+ const stringifiedQuery = stringify({
115
+ ...params,
116
+ ...init.query
117
+ }, {
118
+ skipNulls: true,
119
+ arrayFormat: "repeat"
120
+ });
114
121
  normalizedInput.search = stringifiedQuery;
115
122
  }
116
123
  }
@@ -121,13 +128,9 @@ class HttpClient {
121
128
  headers.forEach((value, key) => {
122
129
  headersObj[key] = value;
123
130
  });
124
- this.logger.debug(
125
- "Performing request to:\n",
126
- `URL: ${normalizedInput.toString()}
127
- `,
128
- `Headers: ${JSON.stringify(headersObj, null, 2)}
129
- `
130
- );
131
+ this.logger.debug("Performing request to:\n", `URL: ${normalizedInput.toString()}
132
+ `, `Headers: ${JSON.stringify(headersObj, null, 2)}
133
+ `);
131
134
  }
132
135
  }
133
136
 
package/dist/index.js CHANGED
@@ -8,7 +8,12 @@ import { HttpClient } from './http';
8
8
  import { FetchError } from './utils';
9
9
  export { FetchError } from './utils';
10
10
 
11
+ var __defProp = Object.defineProperty;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
13
  class PearSDK {
14
+ static {
15
+ __name(this, "PearSDK");
16
+ }
12
17
  auth;
13
18
  core;
14
19
  external;
@@ -28,7 +33,7 @@ class PearSDK {
28
33
  this.external = new External();
29
34
  if (authMode === "session") {
30
35
  let refreshInFlight = null;
31
- const refreshSession = async () => {
36
+ const refreshSession = /* @__PURE__ */ __name(async () => {
32
37
  if (!refreshInFlight) {
33
38
  logger.info("[session-refresh] Refreshing session...");
34
39
  refreshInFlight = this.auth.refreshSession().then((session) => {
@@ -48,8 +53,8 @@ class PearSDK {
48
53
  logger.debug("[session-refresh] Refresh already in flight, waiting...");
49
54
  }
50
55
  return refreshInFlight;
51
- };
52
- const sessionRefreshMiddleware = async (response, retry, request) => {
56
+ }, "refreshSession");
57
+ const sessionRefreshMiddleware = /* @__PURE__ */ __name(async (response, retry, request) => {
53
58
  if (response.status !== 401) return response;
54
59
  logger.warn(`[session-refresh] 401 received for ${request.method} ${request.url}`);
55
60
  try {
@@ -61,7 +66,7 @@ class PearSDK {
61
66
  config.onSessionExpired?.();
62
67
  throw new FetchError("Session expired. Please log in again.", "Unauthorized", 401);
63
68
  }
64
- };
69
+ }, "sessionRefreshMiddleware");
65
70
  client.useResponse(sessionRefreshMiddleware);
66
71
  }
67
72
  if (authMode === "bearer" && config.auth?.token) {
package/dist/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  function getBaseUrl(passedBaseUrl) {
2
4
  if (typeof window === "undefined") {
3
5
  return passedBaseUrl;
@@ -7,6 +9,7 @@ function getBaseUrl(passedBaseUrl) {
7
9
  }
8
10
  return passedBaseUrl;
9
11
  }
12
+ __name(getBaseUrl, "getBaseUrl");
10
13
  function normalizeRequest(init, headers, authMode) {
11
14
  let body = init?.body;
12
15
  if (body && headers.get("content-type")?.includes("application/json")) {
@@ -15,12 +18,17 @@ function normalizeRequest(init, headers, authMode) {
15
18
  return {
16
19
  ...init,
17
20
  headers,
18
- ...body ? { body } : {},
21
+ ...body ? {
22
+ body
23
+ } : {},
19
24
  // In session mode, include cookies with every request
20
25
  // WHY: httpOnly cookies are sent automatically — no JS token management needed
21
- ...authMode === "session" ? { credentials: "include" } : {}
26
+ ...authMode === "session" ? {
27
+ credentials: "include"
28
+ } : {}
22
29
  };
23
30
  }
31
+ __name(normalizeRequest, "normalizeRequest");
24
32
  async function normalizeResponseData(resp, reqHeaders) {
25
33
  if (resp.status === 304) {
26
34
  return null;
@@ -42,7 +50,11 @@ async function normalizeResponseData(resp, reqHeaders) {
42
50
  }
43
51
  return JSON.parse(responseText);
44
52
  }
53
+ __name(normalizeResponseData, "normalizeResponseData");
45
54
  class FetchError extends Error {
55
+ static {
56
+ __name(this, "FetchError");
57
+ }
46
58
  status;
47
59
  statusText;
48
60
  // Machine-readable contract code from the server's error envelope (e.g. SYNC_CREATE_FILLS_TOO_RECENT).
@@ -55,8 +67,11 @@ class FetchError extends Error {
55
67
  }
56
68
  }
57
69
  async function gzipJson(value) {
58
- const stream = new Blob([JSON.stringify(value)]).stream().pipeThrough(new CompressionStream("gzip"));
70
+ const stream = new Blob([
71
+ JSON.stringify(value)
72
+ ]).stream().pipeThrough(new CompressionStream("gzip"));
59
73
  return await new Response(stream).blob();
60
74
  }
75
+ __name(gzipJson, "gzipJson");
61
76
 
62
77
  export { FetchError, getBaseUrl, gzipJson, normalizeRequest, normalizeResponseData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/core-sdk",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "Pear Protocol Core SDK",
5
5
  "private": false,
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "typecheck": "tsc --noEmit"
27
27
  },
28
28
  "dependencies": {
29
- "@pear-protocol/types": "^1.24.0",
30
- "@pear-protocol/utils": "^0.5.1",
29
+ "@pear-protocol/types": "^1.24.1",
30
+ "@pear-protocol/utils": "^0.5.2",
31
31
  "qs": "^6.14.0"
32
32
  },
33
33
  "devDependencies": {