pmxtjs 2.20.2 → 2.21.0

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,55 @@
1
+ /**
2
+ * Typed error classes for pmxt.
3
+ *
4
+ * These mirror the error hierarchy in the core TypeScript library,
5
+ * enabling users to catch specific error types.
6
+ */
7
+ export declare class PmxtError extends Error {
8
+ readonly code: string;
9
+ readonly retryable: boolean;
10
+ readonly exchange?: string;
11
+ constructor(message: string, code?: string, retryable?: boolean, exchange?: string);
12
+ }
13
+ export declare class BadRequest extends PmxtError {
14
+ constructor(message: string, exchange?: string);
15
+ }
16
+ export declare class AuthenticationError extends PmxtError {
17
+ constructor(message: string, exchange?: string);
18
+ }
19
+ export declare class PermissionDenied extends PmxtError {
20
+ constructor(message: string, exchange?: string);
21
+ }
22
+ export declare class NotFoundError extends PmxtError {
23
+ constructor(message: string, exchange?: string);
24
+ }
25
+ export declare class OrderNotFound extends NotFoundError {
26
+ constructor(orderId: string, exchange?: string);
27
+ }
28
+ export declare class MarketNotFound extends NotFoundError {
29
+ constructor(marketId: string, exchange?: string);
30
+ }
31
+ export declare class EventNotFound extends NotFoundError {
32
+ constructor(identifier: string, exchange?: string);
33
+ }
34
+ export declare class RateLimitExceeded extends PmxtError {
35
+ readonly retryAfter?: number;
36
+ constructor(message: string, retryAfter?: number, exchange?: string);
37
+ }
38
+ export declare class InvalidOrder extends PmxtError {
39
+ constructor(message: string, exchange?: string);
40
+ }
41
+ export declare class InsufficientFunds extends PmxtError {
42
+ constructor(message: string, exchange?: string);
43
+ }
44
+ export declare class ValidationError extends PmxtError {
45
+ readonly field?: string;
46
+ constructor(message: string, field?: string, exchange?: string);
47
+ }
48
+ export declare class NetworkError extends PmxtError {
49
+ constructor(message: string, exchange?: string);
50
+ }
51
+ export declare class ExchangeNotAvailable extends PmxtError {
52
+ constructor(message: string, exchange?: string);
53
+ }
54
+ /** Convert a server error response object into a typed PmxtError. */
55
+ export declare function fromServerError(errorData: any): PmxtError;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Typed error classes for pmxt.
3
+ *
4
+ * These mirror the error hierarchy in the core TypeScript library,
5
+ * enabling users to catch specific error types.
6
+ */
7
+ export class PmxtError extends Error {
8
+ code;
9
+ retryable;
10
+ exchange;
11
+ constructor(message, code = "UNKNOWN_ERROR", retryable = false, exchange) {
12
+ super(message);
13
+ this.name = this.constructor.name;
14
+ this.code = code;
15
+ this.retryable = retryable;
16
+ this.exchange = exchange;
17
+ if (Error.captureStackTrace) {
18
+ Error.captureStackTrace(this, this.constructor);
19
+ }
20
+ }
21
+ }
22
+ // 4xx Client Errors
23
+ export class BadRequest extends PmxtError {
24
+ constructor(message, exchange) {
25
+ super(message, "BAD_REQUEST", false, exchange);
26
+ }
27
+ }
28
+ export class AuthenticationError extends PmxtError {
29
+ constructor(message, exchange) {
30
+ super(message, "AUTHENTICATION_ERROR", false, exchange);
31
+ }
32
+ }
33
+ export class PermissionDenied extends PmxtError {
34
+ constructor(message, exchange) {
35
+ super(message, "PERMISSION_DENIED", false, exchange);
36
+ }
37
+ }
38
+ export class NotFoundError extends PmxtError {
39
+ constructor(message, exchange) {
40
+ super(message, "NOT_FOUND", false, exchange);
41
+ }
42
+ }
43
+ export class OrderNotFound extends NotFoundError {
44
+ constructor(orderId, exchange) {
45
+ super(`Order not found: ${orderId}`, exchange);
46
+ this.code = "ORDER_NOT_FOUND";
47
+ }
48
+ }
49
+ export class MarketNotFound extends NotFoundError {
50
+ constructor(marketId, exchange) {
51
+ super(`Market not found: ${marketId}`, exchange);
52
+ this.code = "MARKET_NOT_FOUND";
53
+ }
54
+ }
55
+ export class EventNotFound extends NotFoundError {
56
+ constructor(identifier, exchange) {
57
+ super(`Event not found: ${identifier}`, exchange);
58
+ this.code = "EVENT_NOT_FOUND";
59
+ }
60
+ }
61
+ export class RateLimitExceeded extends PmxtError {
62
+ retryAfter;
63
+ constructor(message, retryAfter, exchange) {
64
+ super(message, "RATE_LIMIT_EXCEEDED", true, exchange);
65
+ this.retryAfter = retryAfter;
66
+ }
67
+ }
68
+ export class InvalidOrder extends PmxtError {
69
+ constructor(message, exchange) {
70
+ super(message, "INVALID_ORDER", false, exchange);
71
+ }
72
+ }
73
+ export class InsufficientFunds extends PmxtError {
74
+ constructor(message, exchange) {
75
+ super(message, "INSUFFICIENT_FUNDS", false, exchange);
76
+ }
77
+ }
78
+ export class ValidationError extends PmxtError {
79
+ field;
80
+ constructor(message, field, exchange) {
81
+ super(message, "VALIDATION_ERROR", false, exchange);
82
+ this.field = field;
83
+ }
84
+ }
85
+ // 5xx Server/Network Errors
86
+ export class NetworkError extends PmxtError {
87
+ constructor(message, exchange) {
88
+ super(message, "NETWORK_ERROR", true, exchange);
89
+ }
90
+ }
91
+ export class ExchangeNotAvailable extends PmxtError {
92
+ constructor(message, exchange) {
93
+ super(message, "EXCHANGE_NOT_AVAILABLE", true, exchange);
94
+ }
95
+ }
96
+ // Error code to class mapping
97
+ const ERROR_CODE_MAP = {
98
+ BAD_REQUEST: BadRequest,
99
+ AUTHENTICATION_ERROR: AuthenticationError,
100
+ PERMISSION_DENIED: PermissionDenied,
101
+ NOT_FOUND: NotFoundError,
102
+ ORDER_NOT_FOUND: OrderNotFound,
103
+ MARKET_NOT_FOUND: MarketNotFound,
104
+ EVENT_NOT_FOUND: EventNotFound,
105
+ RATE_LIMIT_EXCEEDED: RateLimitExceeded,
106
+ INVALID_ORDER: InvalidOrder,
107
+ INSUFFICIENT_FUNDS: InsufficientFunds,
108
+ VALIDATION_ERROR: ValidationError,
109
+ NETWORK_ERROR: NetworkError,
110
+ EXCHANGE_NOT_AVAILABLE: ExchangeNotAvailable,
111
+ };
112
+ /** Convert a server error response object into a typed PmxtError. */
113
+ export function fromServerError(errorData) {
114
+ if (typeof errorData === "string") {
115
+ return new PmxtError(errorData);
116
+ }
117
+ const message = errorData.message || "Unknown error";
118
+ const code = errorData.code || "UNKNOWN_ERROR";
119
+ const retryable = errorData.retryable || false;
120
+ const exchange = errorData.exchange;
121
+ const ErrorClass = ERROR_CODE_MAP[code];
122
+ if (ErrorClass === RateLimitExceeded) {
123
+ return new RateLimitExceeded(message, errorData.retryAfter, exchange);
124
+ }
125
+ if (ErrorClass === ValidationError) {
126
+ return new ValidationError(message, errorData.field, exchange);
127
+ }
128
+ if (ErrorClass) {
129
+ return new ErrorClass(message, exchange);
130
+ }
131
+ return new PmxtError(message, code, retryable, exchange);
132
+ }
package/dist/index.d.ts CHANGED
@@ -20,13 +20,30 @@
20
20
  import { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi } from "./pmxt/client.js";
21
21
  import { ServerManager } from "./pmxt/server-manager.js";
22
22
  import * as models from "./pmxt/models.js";
23
+ import * as errors from "./pmxt/errors.js";
23
24
  export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, PolymarketOptions } from "./pmxt/client.js";
24
25
  export { ServerManager } from "./pmxt/server-manager.js";
25
26
  export { MarketList } from "./pmxt/models.js";
26
27
  export type * from "./pmxt/models.js";
28
+ export * from "./pmxt/errors.js";
27
29
  declare function stopServer(): Promise<void>;
28
30
  declare function restartServer(): Promise<void>;
29
31
  declare const pmxt: {
32
+ fromServerError(errorData: any): errors.PmxtError;
33
+ PmxtError: typeof errors.PmxtError;
34
+ BadRequest: typeof errors.BadRequest;
35
+ AuthenticationError: typeof errors.AuthenticationError;
36
+ PermissionDenied: typeof errors.PermissionDenied;
37
+ NotFoundError: typeof errors.NotFoundError;
38
+ OrderNotFound: typeof errors.OrderNotFound;
39
+ MarketNotFound: typeof errors.MarketNotFound;
40
+ EventNotFound: typeof errors.EventNotFound;
41
+ RateLimitExceeded: typeof errors.RateLimitExceeded;
42
+ InvalidOrder: typeof errors.InvalidOrder;
43
+ InsufficientFunds: typeof errors.InsufficientFunds;
44
+ ValidationError: typeof errors.ValidationError;
45
+ NetworkError: typeof errors.NetworkError;
46
+ ExchangeNotAvailable: typeof errors.ExchangeNotAvailable;
30
47
  MarketList: typeof models.MarketList;
31
48
  Exchange: typeof Exchange;
32
49
  Polymarket: typeof Polymarket;
package/dist/index.js CHANGED
@@ -51,11 +51,15 @@ var __importStar = (this && this.__importStar) || (function () {
51
51
  return result;
52
52
  };
53
53
  })();
54
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
55
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
56
+ };
54
57
  Object.defineProperty(exports, "__esModule", { value: true });
55
58
  exports.MarketList = exports.ServerManager = exports.Baozi = exports.Probable = exports.Myriad = exports.Limitless = exports.KalshiDemo = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
56
59
  const client_js_1 = require("./pmxt/client.js");
57
60
  const server_manager_js_1 = require("./pmxt/server-manager.js");
58
61
  const models = __importStar(require("./pmxt/models.js"));
62
+ const errors = __importStar(require("./pmxt/errors.js"));
59
63
  var client_js_2 = require("./pmxt/client.js");
60
64
  Object.defineProperty(exports, "Exchange", { enumerable: true, get: function () { return client_js_2.Exchange; } });
61
65
  Object.defineProperty(exports, "Polymarket", { enumerable: true, get: function () { return client_js_2.Polymarket; } });
@@ -69,6 +73,7 @@ var server_manager_js_2 = require("./pmxt/server-manager.js");
69
73
  Object.defineProperty(exports, "ServerManager", { enumerable: true, get: function () { return server_manager_js_2.ServerManager; } });
70
74
  var models_js_1 = require("./pmxt/models.js");
71
75
  Object.defineProperty(exports, "MarketList", { enumerable: true, get: function () { return models_js_1.MarketList; } });
76
+ __exportStar(require("./pmxt/errors.js"), exports);
72
77
  const defaultManager = new server_manager_js_1.ServerManager();
73
78
  async function stopServer() {
74
79
  await defaultManager.stop();
@@ -88,6 +93,7 @@ const pmxt = {
88
93
  ServerManager: server_manager_js_1.ServerManager,
89
94
  stopServer,
90
95
  restartServer,
91
- ...models
96
+ ...models,
97
+ ...errors
92
98
  };
93
99
  exports.default = pmxt;