pmxt-core 2.43.20 → 2.43.24

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.
Files changed (67) hide show
  1. package/dist/exchanges/baozi/errors.d.ts +1 -1
  2. package/dist/exchanges/baozi/errors.js +1 -1
  3. package/dist/exchanges/gemini-titan/errors.d.ts +3 -3
  4. package/dist/exchanges/gemini-titan/errors.js +1 -1
  5. package/dist/exchanges/gemini-titan/index.js +1 -1
  6. package/dist/exchanges/gemini-titan/normalizer.js +2 -2
  7. package/dist/exchanges/hyperliquid/errors.d.ts +3 -3
  8. package/dist/exchanges/hyperliquid/errors.js +1 -1
  9. package/dist/exchanges/hyperliquid/index.js +1 -1
  10. package/dist/exchanges/kalshi/api.d.ts +1 -1
  11. package/dist/exchanges/kalshi/api.js +1 -1
  12. package/dist/exchanges/kalshi/auth.js +3 -0
  13. package/dist/exchanges/kalshi/errors.d.ts +2 -2
  14. package/dist/exchanges/kalshi/fetcher.d.ts +1 -0
  15. package/dist/exchanges/kalshi/index.js +1 -1
  16. package/dist/exchanges/kalshi/normalizer.d.ts +1 -1
  17. package/dist/exchanges/kalshi/normalizer.js +4 -4
  18. package/dist/exchanges/limitless/api.d.ts +1 -1
  19. package/dist/exchanges/limitless/api.js +1 -1
  20. package/dist/exchanges/limitless/auth.js +3 -0
  21. package/dist/exchanges/limitless/errors.d.ts +2 -2
  22. package/dist/exchanges/limitless/index.js +1 -1
  23. package/dist/exchanges/metaculus/cancelOrder.d.ts +1 -1
  24. package/dist/exchanges/metaculus/cancelOrder.js +3 -3
  25. package/dist/exchanges/metaculus/errors.d.ts +3 -3
  26. package/dist/exchanges/mock/index.js +32 -15
  27. package/dist/exchanges/myriad/api.d.ts +1 -1
  28. package/dist/exchanges/myriad/api.js +1 -1
  29. package/dist/exchanges/myriad/errors.d.ts +2 -2
  30. package/dist/exchanges/opinion/api.d.ts +1 -1
  31. package/dist/exchanges/opinion/api.js +1 -1
  32. package/dist/exchanges/opinion/errors.d.ts +2 -2
  33. package/dist/exchanges/opinion/errors.js +4 -3
  34. package/dist/exchanges/opinion/index.js +1 -1
  35. package/dist/exchanges/opinion/utils.d.ts +1 -1
  36. package/dist/exchanges/opinion/utils.js +2 -2
  37. package/dist/exchanges/polymarket/api-clob.d.ts +1 -1
  38. package/dist/exchanges/polymarket/api-clob.js +1 -1
  39. package/dist/exchanges/polymarket/api-data.d.ts +1 -1
  40. package/dist/exchanges/polymarket/api-data.js +1 -1
  41. package/dist/exchanges/polymarket/api-gamma.d.ts +1 -1
  42. package/dist/exchanges/polymarket/api-gamma.js +1 -1
  43. package/dist/exchanges/polymarket/auth.js +22 -3
  44. package/dist/exchanges/polymarket/errors.d.ts +3 -3
  45. package/dist/exchanges/polymarket/fetcher.js +3 -0
  46. package/dist/exchanges/polymarket/index.js +1 -1
  47. package/dist/exchanges/polymarket_us/normalizer.js +3 -3
  48. package/dist/exchanges/probable/api.d.ts +1 -1
  49. package/dist/exchanges/probable/api.js +1 -1
  50. package/dist/exchanges/probable/errors.d.ts +2 -2
  51. package/dist/exchanges/probable/errors.js +1 -1
  52. package/dist/exchanges/probable/index.js +2 -2
  53. package/dist/exchanges/smarkets/auth.js +6 -0
  54. package/dist/exchanges/smarkets/errors.d.ts +3 -3
  55. package/dist/exchanges/smarkets/errors.js +7 -2
  56. package/dist/feeds/binance/binance-feed.js +11 -2
  57. package/dist/feeds/chainlink/chainlink-feed.js +9 -3
  58. package/dist/router/Router.js +1 -3
  59. package/dist/router/client.d.ts +16 -8
  60. package/dist/router/client.js +7 -3
  61. package/dist/server/openapi.yaml +1 -1
  62. package/dist/subscriber/external/goldsky.d.ts +2 -1
  63. package/dist/subscriber/external/goldsky.js +33 -14
  64. package/dist/types.d.ts +1 -1
  65. package/dist/utils/error-mapper.d.ts +7 -7
  66. package/dist/utils/error-mapper.js +54 -47
  67. package/package.json +3 -3
@@ -6,6 +6,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ErrorMapper = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const errors_1 = require("../errors");
9
+ /** Type guard for plain error objects with numeric status codes. */
10
+ function isPlainErrorObject(value) {
11
+ return (typeof value === 'object' &&
12
+ value !== null &&
13
+ !Array.isArray(value) &&
14
+ !(value instanceof Error) &&
15
+ 'status' in value &&
16
+ typeof value.status === 'number');
17
+ }
18
+ /** Type guard for Node.js-style errors with a `code` property. */
19
+ function isNodeError(value) {
20
+ return value instanceof Error && 'code' in value;
21
+ }
9
22
  /**
10
23
  * Maps raw errors to PMXT unified error classes
11
24
  *
@@ -33,15 +46,15 @@ class ErrorMapper {
33
46
  return this.mapAxiosError(error);
34
47
  }
35
48
  // Handle plain objects with status/data (e.g., Polymarket clob-client)
36
- if (error && typeof error === 'object' && !Array.isArray(error) && !(error instanceof Error)) {
37
- if (error.status && typeof error.status === 'number') {
38
- const message = this.extractErrorMessage(error);
39
- return this.mapByStatusCode(error.status, message, error.data, error);
40
- }
49
+ if (isPlainErrorObject(error)) {
50
+ const message = this.extractErrorMessage(error);
51
+ return this.mapByStatusCode(error.status, message, error.data, error);
41
52
  }
42
53
  // Handle network errors
43
- if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.code === 'ETIMEDOUT') {
44
- return new errors_1.NetworkError(`Network error: ${error.message}`, this.exchangeName);
54
+ if (isNodeError(error)) {
55
+ if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.code === 'ETIMEDOUT') {
56
+ return new errors_1.NetworkError(`Network error: ${error.message}`, this.exchangeName);
57
+ }
45
58
  }
46
59
  // Handle Error instances with attached HTTP metadata (common in third-party SDKs)
47
60
  if (error instanceof Error) {
@@ -153,7 +166,10 @@ class ErrorMapper {
153
166
  */
154
167
  mapRateLimitError(message, response) {
155
168
  // Try to extract retry-after from headers
156
- const retryAfter = response?.headers?.['retry-after'];
169
+ const headers = (typeof response === 'object' && response !== null && 'headers' in response
170
+ ? response.headers
171
+ : undefined);
172
+ const retryAfter = headers?.['retry-after'];
157
173
  const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : undefined;
158
174
  return new errors_1.RateLimitExceeded(message, retryAfterSeconds, this.exchangeName);
159
175
  }
@@ -168,44 +184,34 @@ class ErrorMapper {
168
184
  if (typeof data === 'string') {
169
185
  return data;
170
186
  }
171
- if (data.error) {
172
- if (typeof data.error === 'string') {
173
- return data.error;
187
+ if (typeof data === 'object' && data !== null) {
188
+ const obj = data;
189
+ if (obj.error) {
190
+ if (typeof obj.error === 'string') {
191
+ return obj.error;
192
+ }
193
+ if (typeof obj.error === 'object' && obj.error !== null && 'message' in obj.error) {
194
+ return String(obj.error.message);
195
+ }
174
196
  }
175
- if (data.error.message) {
176
- return data.error.message;
197
+ if (typeof obj.message === 'string') {
198
+ return obj.message;
199
+ }
200
+ if (typeof obj.errorMsg === 'string') {
201
+ return obj.errorMsg;
177
202
  }
178
- }
179
- if (data.message) {
180
- return data.message;
181
- }
182
- if (data.errorMsg) {
183
- return data.errorMsg;
184
203
  }
185
204
  // Fallback to stringified data
186
205
  return JSON.stringify(data);
187
206
  }
188
207
  // Plain object with status and data (e.g., Polymarket clob-client errors)
189
208
  // These aren't AxiosError instances but have similar structure
190
- if (error && typeof error === 'object' && !Array.isArray(error) && !(error instanceof Error)) {
209
+ if (isPlainErrorObject(error)) {
191
210
  const data = error.data;
192
211
  if (data) {
193
- if (typeof data === 'string') {
194
- return data;
195
- }
196
- if (data.error) {
197
- if (typeof data.error === 'string') {
198
- return data.error;
199
- }
200
- if (data.error.message) {
201
- return data.error.message;
202
- }
203
- }
204
- if (data.message) {
205
- return data.message;
206
- }
207
- if (data.errorMsg) {
208
- return data.errorMsg;
212
+ const extracted = this.extractFromData(data);
213
+ if (extracted) {
214
+ return extracted;
209
215
  }
210
216
  }
211
217
  // Check for message at top level
@@ -237,7 +243,7 @@ class ErrorMapper {
237
243
  try {
238
244
  return JSON.stringify(error, Object.getOwnPropertyNames(error));
239
245
  }
240
- catch (e) {
246
+ catch {
241
247
  return String(error);
242
248
  }
243
249
  }
@@ -250,20 +256,21 @@ class ErrorMapper {
250
256
  if (typeof data === 'string') {
251
257
  return data;
252
258
  }
253
- if (data && typeof data === 'object') {
254
- if (data.error) {
255
- if (typeof data.error === 'string') {
256
- return data.error;
259
+ if (typeof data === 'object' && data !== null) {
260
+ const obj = data;
261
+ if (obj.error) {
262
+ if (typeof obj.error === 'string') {
263
+ return obj.error;
257
264
  }
258
- if (data.error.message) {
259
- return data.error.message;
265
+ if (typeof obj.error === 'object' && obj.error !== null && 'message' in obj.error) {
266
+ return String(obj.error.message);
260
267
  }
261
268
  }
262
- if (data.message) {
263
- return data.message;
269
+ if (typeof obj.message === 'string') {
270
+ return obj.message;
264
271
  }
265
- if (data.errorMsg) {
266
- return data.errorMsg;
272
+ if (typeof obj.errorMsg === 'string') {
273
+ return obj.errorMsg;
267
274
  }
268
275
  try {
269
276
  return JSON.stringify(data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.43.20",
3
+ "version": "2.43.24",
4
4
  "description": "pmxt is a unified prediction market data API. The ccxt for prediction markets.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,8 +29,8 @@
29
29
  "test": "jest -c jest.config.js",
30
30
  "server": "tsx watch src/server/index.ts",
31
31
  "server:prod": "node dist/server/index.js",
32
- "generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.43.20,library=urllib3",
33
- "generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.43.20,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
32
+ "generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.43.24,library=urllib3",
33
+ "generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.43.24,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
34
34
  "fetch:openapi": "node scripts/fetch-openapi-specs.js",
35
35
  "extract:jsdoc": "node ../scripts/extract-jsdoc.js",
36
36
  "generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",