pmxtjs 2.43.19 → 2.43.20

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.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Structured logger for pmxt TypeScript SDK.
3
+ *
4
+ * Thin abstraction over console that:
5
+ * - Attaches a `[pmxt]` prefix for easy filtering
6
+ * - Supports log levels (debug, info, warn, error)
7
+ * - Respects a configurable level threshold via PMXT_LOG_LEVEL
8
+ * - Can be swapped for a real transport later
9
+ */
10
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
11
+ export declare const logger: {
12
+ debug(message: string, context?: Record<string, unknown>): void;
13
+ info(message: string, context?: Record<string, unknown>): void;
14
+ warn(message: string, context?: Record<string, unknown>): void;
15
+ error(message: string, context?: Record<string, unknown>): void;
16
+ setLevel(level: LogLevel): void;
17
+ getLevel(): LogLevel;
18
+ };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Structured logger for pmxt TypeScript SDK.
3
+ *
4
+ * Thin abstraction over console that:
5
+ * - Attaches a `[pmxt]` prefix for easy filtering
6
+ * - Supports log levels (debug, info, warn, error)
7
+ * - Respects a configurable level threshold via PMXT_LOG_LEVEL
8
+ * - Can be swapped for a real transport later
9
+ */
10
+ const LEVEL_PRIORITY = {
11
+ debug: 0,
12
+ info: 1,
13
+ warn: 2,
14
+ error: 3,
15
+ silent: 4,
16
+ };
17
+ function getDefaultLevel() {
18
+ if (typeof process !== 'undefined' && process.env?.PMXT_LOG_LEVEL) {
19
+ return process.env.PMXT_LOG_LEVEL;
20
+ }
21
+ return 'info';
22
+ }
23
+ let currentLevel = getDefaultLevel();
24
+ function shouldLog(level) {
25
+ return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[currentLevel];
26
+ }
27
+ export const logger = {
28
+ debug(message, context) {
29
+ if (!shouldLog('debug'))
30
+ return;
31
+ if (context) {
32
+ console.debug(`[pmxt] ${message}`, context);
33
+ }
34
+ else {
35
+ console.debug(`[pmxt] ${message}`);
36
+ }
37
+ },
38
+ info(message, context) {
39
+ if (!shouldLog('info'))
40
+ return;
41
+ if (context) {
42
+ console.info(`[pmxt] ${message}`, context);
43
+ }
44
+ else {
45
+ console.info(`[pmxt] ${message}`);
46
+ }
47
+ },
48
+ warn(message, context) {
49
+ if (!shouldLog('warn'))
50
+ return;
51
+ if (context) {
52
+ console.warn(`[pmxt] ${message}`, context);
53
+ }
54
+ else {
55
+ console.warn(`[pmxt] ${message}`);
56
+ }
57
+ },
58
+ error(message, context) {
59
+ if (!shouldLog('error'))
60
+ return;
61
+ if (context) {
62
+ console.error(`[pmxt] ${message}`, context);
63
+ }
64
+ else {
65
+ console.error(`[pmxt] ${message}`);
66
+ }
67
+ },
68
+ setLevel(level) {
69
+ currentLevel = level;
70
+ },
71
+ getLevel() {
72
+ return currentLevel;
73
+ },
74
+ };
@@ -5,6 +5,7 @@
5
5
  * every venue PMXT supports. Only requires a PMXT API key.
6
6
  */
7
7
  import { Exchange } from "./client.js";
8
+ import { logger } from "./logger.js";
8
9
  function convertMarket(raw) {
9
10
  const outcomes = (raw.outcomes || []).map((o) => ({
10
11
  outcomeId: o.outcomeId,
@@ -131,7 +132,7 @@ export class Router extends Exchange {
131
132
  }
132
133
  }
133
134
  async fetchMatches(marketOrParams = {}) {
134
- console.warn('[pmxt] fetchMatches is deprecated, use fetchMarketMatches instead');
135
+ logger.warn('fetchMatches is deprecated, use fetchMarketMatches instead');
135
136
  return this.fetchMarketMatches(marketOrParams);
136
137
  }
137
138
  async fetchEventMatches(eventOrParams = {}) {
@@ -188,6 +189,7 @@ export class Router extends Exchange {
188
189
  method: 'POST',
189
190
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
190
191
  body: JSON.stringify({ args: [query], credentials: this.getCredentials() }),
192
+ signal: AbortSignal.timeout(30_000),
191
193
  });
192
194
  if (!response.ok) {
193
195
  const body = await response.json().catch(() => ({}));
@@ -188,6 +188,9 @@ export class SidecarWsClient {
188
188
  if (credentials) {
189
189
  message.credentials = credentials;
190
190
  }
191
+ if (!this.ws) {
192
+ throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
193
+ }
191
194
  this.ws.send(JSON.stringify(message));
192
195
  return this.waitForData(requestId, timeoutMs);
193
196
  }
@@ -213,6 +216,9 @@ export class SidecarWsClient {
213
216
  if (credentials) {
214
217
  message.credentials = credentials;
215
218
  }
219
+ if (!this.ws) {
220
+ throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
221
+ }
216
222
  this.ws.send(JSON.stringify(message));
217
223
  // Wait for first data event
218
224
  await this.waitForData(requestId, timeoutMs);
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Structured logger for pmxt TypeScript SDK.
3
+ *
4
+ * Thin abstraction over console that:
5
+ * - Attaches a `[pmxt]` prefix for easy filtering
6
+ * - Supports log levels (debug, info, warn, error)
7
+ * - Respects a configurable level threshold via PMXT_LOG_LEVEL
8
+ * - Can be swapped for a real transport later
9
+ */
10
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
11
+ export declare const logger: {
12
+ debug(message: string, context?: Record<string, unknown>): void;
13
+ info(message: string, context?: Record<string, unknown>): void;
14
+ warn(message: string, context?: Record<string, unknown>): void;
15
+ error(message: string, context?: Record<string, unknown>): void;
16
+ setLevel(level: LogLevel): void;
17
+ getLevel(): LogLevel;
18
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /**
3
+ * Structured logger for pmxt TypeScript SDK.
4
+ *
5
+ * Thin abstraction over console that:
6
+ * - Attaches a `[pmxt]` prefix for easy filtering
7
+ * - Supports log levels (debug, info, warn, error)
8
+ * - Respects a configurable level threshold via PMXT_LOG_LEVEL
9
+ * - Can be swapped for a real transport later
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.logger = void 0;
13
+ const LEVEL_PRIORITY = {
14
+ debug: 0,
15
+ info: 1,
16
+ warn: 2,
17
+ error: 3,
18
+ silent: 4,
19
+ };
20
+ function getDefaultLevel() {
21
+ if (typeof process !== 'undefined' && process.env?.PMXT_LOG_LEVEL) {
22
+ return process.env.PMXT_LOG_LEVEL;
23
+ }
24
+ return 'info';
25
+ }
26
+ let currentLevel = getDefaultLevel();
27
+ function shouldLog(level) {
28
+ return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[currentLevel];
29
+ }
30
+ exports.logger = {
31
+ debug(message, context) {
32
+ if (!shouldLog('debug'))
33
+ return;
34
+ if (context) {
35
+ console.debug(`[pmxt] ${message}`, context);
36
+ }
37
+ else {
38
+ console.debug(`[pmxt] ${message}`);
39
+ }
40
+ },
41
+ info(message, context) {
42
+ if (!shouldLog('info'))
43
+ return;
44
+ if (context) {
45
+ console.info(`[pmxt] ${message}`, context);
46
+ }
47
+ else {
48
+ console.info(`[pmxt] ${message}`);
49
+ }
50
+ },
51
+ warn(message, context) {
52
+ if (!shouldLog('warn'))
53
+ return;
54
+ if (context) {
55
+ console.warn(`[pmxt] ${message}`, context);
56
+ }
57
+ else {
58
+ console.warn(`[pmxt] ${message}`);
59
+ }
60
+ },
61
+ error(message, context) {
62
+ if (!shouldLog('error'))
63
+ return;
64
+ if (context) {
65
+ console.error(`[pmxt] ${message}`, context);
66
+ }
67
+ else {
68
+ console.error(`[pmxt] ${message}`);
69
+ }
70
+ },
71
+ setLevel(level) {
72
+ currentLevel = level;
73
+ },
74
+ getLevel() {
75
+ return currentLevel;
76
+ },
77
+ };
@@ -41,6 +41,7 @@ var __importStar = (this && this.__importStar) || (function () {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.Router = void 0;
43
43
  const client_js_1 = require("./client.js");
44
+ const logger_js_1 = require("./logger.js");
44
45
  function convertMarket(raw) {
45
46
  const outcomes = (raw.outcomes || []).map((o) => ({
46
47
  outcomeId: o.outcomeId,
@@ -167,7 +168,7 @@ class Router extends client_js_1.Exchange {
167
168
  }
168
169
  }
169
170
  async fetchMatches(marketOrParams = {}) {
170
- console.warn('[pmxt] fetchMatches is deprecated, use fetchMarketMatches instead');
171
+ logger_js_1.logger.warn('fetchMatches is deprecated, use fetchMarketMatches instead');
171
172
  return this.fetchMarketMatches(marketOrParams);
172
173
  }
173
174
  async fetchEventMatches(eventOrParams = {}) {
@@ -224,6 +225,7 @@ class Router extends client_js_1.Exchange {
224
225
  method: 'POST',
225
226
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
226
227
  body: JSON.stringify({ args: [query], credentials: this.getCredentials() }),
228
+ signal: AbortSignal.timeout(30_000),
227
229
  });
228
230
  if (!response.ok) {
229
231
  const body = await response.json().catch(() => ({}));
@@ -191,6 +191,9 @@ class SidecarWsClient {
191
191
  if (credentials) {
192
192
  message.credentials = credentials;
193
193
  }
194
+ if (!this.ws) {
195
+ throw new errors_js_1.PmxtError('[ws-client] Cannot send: WebSocket not connected');
196
+ }
194
197
  this.ws.send(JSON.stringify(message));
195
198
  return this.waitForData(requestId, timeoutMs);
196
199
  }
@@ -216,6 +219,9 @@ class SidecarWsClient {
216
219
  if (credentials) {
217
220
  message.credentials = credentials;
218
221
  }
222
+ if (!this.ws) {
223
+ throw new errors_js_1.PmxtError('[ws-client] Cannot send: WebSocket not connected');
224
+ }
219
225
  this.ws.send(JSON.stringify(message));
220
226
  // Wait for first data event
221
227
  await this.waitForData(requestId, timeoutMs);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.43.19",
3
+ "version": "2.43.20",
4
4
  "description": "OpenAPI client for pmxtjs",
5
5
  "author": "OpenAPI-Generator",
6
6
  "repository": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxtjs",
3
- "version": "2.43.19",
3
+ "version": "2.43.20",
4
4
  "description": "Unified prediction market data API - The ccxt for prediction markets",
5
5
  "author": "PMXT Contributors",
6
6
  "repository": {
@@ -43,7 +43,7 @@
43
43
  "unified"
44
44
  ],
45
45
  "dependencies": {
46
- "pmxt-core": "2.43.19",
46
+ "pmxt-core": "2.43.20",
47
47
  "ws": "^8.18.0"
48
48
  },
49
49
  "devDependencies": {
package/pmxt/logger.ts ADDED
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Structured logger for pmxt TypeScript SDK.
3
+ *
4
+ * Thin abstraction over console that:
5
+ * - Attaches a `[pmxt]` prefix for easy filtering
6
+ * - Supports log levels (debug, info, warn, error)
7
+ * - Respects a configurable level threshold via PMXT_LOG_LEVEL
8
+ * - Can be swapped for a real transport later
9
+ */
10
+
11
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
12
+
13
+ const LEVEL_PRIORITY: Record<LogLevel, number> = {
14
+ debug: 0,
15
+ info: 1,
16
+ warn: 2,
17
+ error: 3,
18
+ silent: 4,
19
+ };
20
+
21
+ function getDefaultLevel(): LogLevel {
22
+ if (typeof process !== 'undefined' && process.env?.PMXT_LOG_LEVEL) {
23
+ return process.env.PMXT_LOG_LEVEL as LogLevel;
24
+ }
25
+ return 'info';
26
+ }
27
+
28
+ let currentLevel: LogLevel = getDefaultLevel();
29
+
30
+ function shouldLog(level: LogLevel): boolean {
31
+ return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[currentLevel];
32
+ }
33
+
34
+ export const logger = {
35
+ debug(message: string, context?: Record<string, unknown>): void {
36
+ if (!shouldLog('debug')) return;
37
+ if (context) {
38
+ console.debug(`[pmxt] ${message}`, context);
39
+ } else {
40
+ console.debug(`[pmxt] ${message}`);
41
+ }
42
+ },
43
+
44
+ info(message: string, context?: Record<string, unknown>): void {
45
+ if (!shouldLog('info')) return;
46
+ if (context) {
47
+ console.info(`[pmxt] ${message}`, context);
48
+ } else {
49
+ console.info(`[pmxt] ${message}`);
50
+ }
51
+ },
52
+
53
+ warn(message: string, context?: Record<string, unknown>): void {
54
+ if (!shouldLog('warn')) return;
55
+ if (context) {
56
+ console.warn(`[pmxt] ${message}`, context);
57
+ } else {
58
+ console.warn(`[pmxt] ${message}`);
59
+ }
60
+ },
61
+
62
+ error(message: string, context?: Record<string, unknown>): void {
63
+ if (!shouldLog('error')) return;
64
+ if (context) {
65
+ console.error(`[pmxt] ${message}`, context);
66
+ } else {
67
+ console.error(`[pmxt] ${message}`);
68
+ }
69
+ },
70
+
71
+ setLevel(level: LogLevel): void {
72
+ currentLevel = level;
73
+ },
74
+
75
+ getLevel(): LogLevel {
76
+ return currentLevel;
77
+ },
78
+ };
package/pmxt/router.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
 
8
8
  import { Exchange, ExchangeOptions } from "./client.js";
9
+ import { logger } from "./logger.js";
9
10
  import {
10
11
  MatchResult,
11
12
  MatchRelation,
@@ -204,7 +205,7 @@ export class Router extends Exchange {
204
205
  limit?: number;
205
206
  includePrices?: boolean;
206
207
  } = {}): Promise<MatchResult[]> {
207
- console.warn('[pmxt] fetchMatches is deprecated, use fetchMarketMatches instead');
208
+ logger.warn('fetchMatches is deprecated, use fetchMarketMatches instead');
208
209
  return this.fetchMarketMatches(marketOrParams as any);
209
210
  }
210
211
 
@@ -297,6 +298,7 @@ export class Router extends Exchange {
297
298
  method: 'POST',
298
299
  headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
299
300
  body: JSON.stringify({ args: [query], credentials: this.getCredentials() }),
301
+ signal: AbortSignal.timeout(30_000),
300
302
  });
301
303
  if (!response.ok) {
302
304
  const body = await response.json().catch(() => ({}));
package/pmxt/ws-client.ts CHANGED
@@ -240,7 +240,10 @@ export class SidecarWsClient {
240
240
  message.credentials = credentials;
241
241
  }
242
242
 
243
- this.ws!.send(JSON.stringify(message));
243
+ if (!this.ws) {
244
+ throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
245
+ }
246
+ this.ws.send(JSON.stringify(message));
244
247
 
245
248
  return this.waitForData(requestId, timeoutMs);
246
249
  }
@@ -278,7 +281,10 @@ export class SidecarWsClient {
278
281
  message.credentials = credentials;
279
282
  }
280
283
 
281
- this.ws!.send(JSON.stringify(message));
284
+ if (!this.ws) {
285
+ throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
286
+ }
287
+ this.ws.send(JSON.stringify(message));
282
288
 
283
289
  // Wait for first data event
284
290
  await this.waitForData(requestId, timeoutMs);