@polymarket/client 0.13.0 → 0.14.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.
- package/README.md +177 -0
- package/dist/actions/index.d.ts +10 -10
- package/dist/actions/index.js +1 -1
- package/dist/chunk-IRLMIGOU.js +3 -0
- package/dist/chunk-IRLMIGOU.js.map +1 -0
- package/dist/chunk-U54M5MQK.js +2 -0
- package/dist/chunk-U54M5MQK.js.map +1 -0
- package/dist/chunk-XUX2UYIW.js +6 -0
- package/dist/chunk-XUX2UYIW.js.map +1 -0
- package/dist/ethers-v5.d.ts +1 -1
- package/dist/ethers-v5.js +1 -1
- package/dist/ethers-v5.js.map +1 -1
- package/dist/index.d.ts +51 -10
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/node.js +1 -1
- package/dist/privy.js +1 -1
- package/dist/{sports-DxgyI41A.d.ts → sports-CW4y_VKL.d.ts} +7 -7
- package/dist/{types-BGxCI8uu.d.ts → types-CprSC_sB.d.ts} +1029 -383
- package/dist/viem.d.ts +1 -1
- package/dist/viem.js +1 -1
- package/dist/viem.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-6GBGW5CG.js +0 -2
- package/dist/chunk-6GBGW5CG.js.map +0 -1
- package/dist/chunk-MY66WYAN.js +0 -3
- package/dist/chunk-MY66WYAN.js.map +0 -1
- package/dist/chunk-VLNLVY4C.js +0 -6
- package/dist/chunk-VLNLVY4C.js.map +0 -1
package/dist/chunk-VLNLVY4C.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export{RealtimeKnownErrorCode as s}from'@polymarket/bindings/subscriptions';import {PolymarketError}from'@polymarket/types';var Z=/^[$A-Z_a-z][$\w]*$/;function i(t){let r=c(t.issues);return r.length===0?"It was not possible to determine a more specific reason.":["Fix the following issues:",p(r)].join(`
|
|
2
|
-
`)}function u(t,r){let e=c(t.issues);return e.length===0?["Received an incompatible API response.",`Endpoint: ${r.endpoint}`,"This usually means the API response shape changed in a breaking way or the SDK is outdated.","It was not possible to determine a more specific reason."].join(`
|
|
3
|
-
`):["Received an incompatible API response.",`Endpoint: ${r.endpoint}`,"This usually means the API response shape changed in a breaking way or the SDK is outdated.","Fix the following issues:",p(e)].join(`
|
|
4
|
-
`)}function p(t){return t.map(e=>e.path===null?`- ${e.message}`:`- ${e.path}: ${e.message}`).join(`
|
|
5
|
-
`)}function c(t){return d(t).slice(0,99)}function d(t,r=[]){let e=t.flatMap(o=>{let a=[...r,...o.path];return o.code==="invalid_union"?o.errors.flatMap(U=>d(U,a)):[{code:o.code,message:o.message,path:a.length===0?null:j(a)}]});return T(e)}function T(t){let r=new Set,e=[];for(let o of t){let a=`${o.code}:${o.path??""}:${o.message}`;r.has(a)||(r.add(a),e.push(o));}return e.sort(L)}function L(t,r){return t.path===null&&r.path!==null?-1:t.path!==null&&r.path===null?1:(t.path??"").localeCompare(r.path??"")}function j(t){return t.reduce((r,e)=>typeof e=="number"?`${r}[${e.toString()}]`:typeof e!="string"?r:e.includes('"')?`${r}["${e.replaceAll('"','\\"')}"]`:Z.test(e)?r.length===0?e:`${r}.${e}`:`${r}["${e}"]`,"")}var l=class t extends PolymarketError{name="UserInputError";constructor(r,e={}){super(r,e);}static fromZodError(r){return new t(i(r),{cause:r})}},m=class extends PolymarketError{name="PaginationLimitError";constructor(r,e={}){super(r,e);}},f=class t extends PolymarketError{name="UnexpectedResponseError";constructor(r,e={}){super(r,e);}static fromZodError(r,e){return new t(u(r,e),{cause:r})}},y=class t extends PolymarketError{name="TransportError";constructor(r,e={}){super(r,e);}static fromError(r){return new t(r instanceof Error?r.message:"Request failed",{cause:r})}},M=(s=>(s[s.NormalClosure=1e3]="NormalClosure",s[s.GoingAway=1001]="GoingAway",s[s.ProtocolError=1002]="ProtocolError",s[s.UnsupportedData=1003]="UnsupportedData",s[s.NoStatusReceived=1005]="NoStatusReceived",s[s.AbnormalClosure=1006]="AbnormalClosure",s[s.InvalidFramePayload=1007]="InvalidFramePayload",s[s.PolicyViolation=1008]="PolicyViolation",s[s.MessageTooBig=1009]="MessageTooBig",s[s.InternalError=1011]="InternalError",s[s.ServiceRestart=1012]="ServiceRestart",s[s.TryAgainLater=1013]="TryAgainLater",s))(M||{}),g=class extends PolymarketError{name="ConnectionLostError";code;reason;constructor(r,e){super(r,e),this.code=e.code,this.reason=e.reason;}},V=(e=>(e.RESTARTING="restarting",e.POST_ONLY="post_only",e))(V||{}),E=class extends PolymarketError{name="RequestRejectedError";status;code;retryAfter;restriction;constructor(r,e){super(r,e),this.status=e.status,this.code=e.code,this.retryAfter=e.retryAfter,this.restriction=e.restriction;}},x=class extends PolymarketError{name="RateLimitError";retryAfter;rateLimit;constructor(r,e={}){super(r,e),this.retryAfter=e.retryAfter,this.rateLimit=e.rateLimit;}},I=class extends PolymarketError{name="TimeoutError";constructor(r,e={}){super(r,e);}},h=class t extends PolymarketError{name="OperationAbortedError";constructor(r,e={}){super(r,e);}static fromReason(r){return new t("Operation was aborted.",{cause:r})}},R=class extends PolymarketError{name="TransactionFailedError";constructor(r,e={}){super(r,e);}},O=class t extends PolymarketError{name="CancelledSigningError";constructor(r,e={}){super(r,e);}static fromError(r){return new t(r.message,{cause:r})}},v=class extends PolymarketError{name="InsufficientLiquidityError";constructor(r,e={}){super(r,e);}},$=class extends PolymarketError{name="AutoCancelDailyLimitError";constructor(r,e={}){super(r,e);}},A=class extends PolymarketError{name="PerpsCancelRetryError";results;pendingIndexes;constructor(r,e){super(r,e),this.results=[...e.results],this.pendingIndexes=[...e.pendingIndexes];}},P=class t extends PolymarketError{name="SigningError";constructor(r,e={}){super(r,e);}static fromError(r,e){let o=e??(r instanceof Error?r.message:"Signing failed");return new t(o,{cause:r})}};function z(...t){return {isError(r){return t.some(e=>r instanceof e)}}}export{l as a,m as b,f as c,y as d,M as e,g as f,V as g,E as h,x as i,I as j,h as k,R as l,O as m,v as n,$ as o,A as p,P as q,z as r};//# sourceMappingURL=chunk-VLNLVY4C.js.map
|
|
6
|
-
//# sourceMappingURL=chunk-VLNLVY4C.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/validation.ts","../src/errors.ts"],"names":["identifierRegex","formatInputZodError","error","issues","flattenIssues","formatIssues","formatResponseZodError","context","issue","flattenIssueBranches","pathPrefix","flattened","path","branch","formatPath","dedupeIssues","seen","deduped","key","compareIssues","left","right","result","segment","UserInputError","_UserInputError","PolymarketError","message","options","PaginationLimitError","UnexpectedResponseError","_UnexpectedResponseError","TransportError","_TransportError","WebSocketKnownCloseCode","ConnectionLostError","TradingRestriction","RequestRejectedError","RateLimitError","TimeoutError","OperationAbortedError","_OperationAbortedError","reason","TransactionFailedError","CancelledSigningError","_CancelledSigningError","InsufficientLiquidityError","AutoCancelDailyLimitError","PerpsCancelRetryError","SigningError","_SigningError","msg","makeErrorGuard","classes","c"],"mappings":"4HAGA,IAAMA,CAAAA,CAAkB,oBAAA,CAejB,SAASC,CAAAA,CAAoBC,EAAyB,CAC3D,IAAMC,CAAAA,CAASC,CAAAA,CAAcF,CAAAA,CAAM,MAAM,CAAA,CAEzC,OAAIC,EAAO,MAAA,GAAW,CAAA,CACb,0DAAA,CAGF,CAAC,2BAAA,CAA6BE,CAAAA,CAAaF,CAAM,CAAC,EAAE,IAAA,CAAK;AAAA,CAAI,CACtE,CAKO,SAASG,CAAAA,CACdJ,CAAAA,CACAK,CAAAA,CACQ,CACR,IAAMJ,CAAAA,CAASC,CAAAA,CAAcF,CAAAA,CAAM,MAAM,CAAA,CAEzC,OAAIC,CAAAA,CAAO,MAAA,GAAW,CAAA,CACb,CACL,wCAAA,CACA,CAAA,UAAA,EAAaI,CAAAA,CAAQ,QAAQ,CAAA,CAAA,CAC7B,6FAAA,CACA,0DACF,CAAA,CAAE,IAAA,CAAK;AAAA,CAAI,CAAA,CAGN,CACL,wCAAA,CACA,CAAA,UAAA,EAAaA,CAAAA,CAAQ,QAAQ,CAAA,CAAA,CAC7B,6FAAA,CACA,2BAAA,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ASkD,KAIXC,CAAAA,CACmE,CACtE,OAAO,CACL,OAAA,CAAQnD,EAAyD,CAC/D,OAAOmD,EAAQ,IAAA,CAAMC,CAAAA,EAAMpD,aAAiBoD,CAAC,CAC/C,CACF,CACF","file":"chunk-VLNLVY4C.js","sourcesContent":["import type { core, ZodError } from 'zod';\n\nconst maxIssuesInMessage = 99;\nconst identifierRegex = /^[$A-Z_a-z][$\\w]*$/;\n\ntype UserInputIssue = {\n code: string;\n message: string;\n path: string | null;\n};\n\nexport type ResponseValidationContext = {\n endpoint: string;\n};\n\n/**\n * Formats a `ZodError` into an SDK-oriented input validation message.\n */\nexport function formatInputZodError(error: ZodError): string {\n const issues = flattenIssues(error.issues);\n\n if (issues.length === 0) {\n return 'It was not possible to determine a more specific reason.';\n }\n\n return ['Fix the following issues:', formatIssues(issues)].join('\\n');\n}\n\n/**\n * Formats a `ZodError` into an SDK-oriented response validation message.\n */\nexport function formatResponseZodError(\n error: ZodError,\n context: ResponseValidationContext,\n): string {\n const issues = flattenIssues(error.issues);\n\n if (issues.length === 0) {\n return [\n 'Received an incompatible API response.',\n `Endpoint: ${context.endpoint}`,\n 'This usually means the API response shape changed in a breaking way or the SDK is outdated.',\n 'It was not possible to determine a more specific reason.',\n ].join('\\n');\n }\n\n return [\n 'Received an incompatible API response.',\n `Endpoint: ${context.endpoint}`,\n 'This usually means the API response shape changed in a breaking way or the SDK is outdated.',\n 'Fix the following issues:',\n formatIssues(issues),\n ].join('\\n');\n}\n\nfunction formatIssues(issues: readonly UserInputIssue[]): string {\n const lines = issues.map((issue) => {\n if (issue.path === null) {\n return `- ${issue.message}`;\n }\n\n return `- ${issue.path}: ${issue.message}`;\n });\n\n return lines.join('\\n');\n}\n\nfunction flattenIssues(issues: readonly core.$ZodIssue[]): UserInputIssue[] {\n return flattenIssueBranches(issues).slice(0, maxIssuesInMessage);\n}\n\nfunction flattenIssueBranches(\n issues: readonly core.$ZodIssue[],\n pathPrefix: readonly PropertyKey[] = [],\n): UserInputIssue[] {\n const flattened = issues.flatMap((issue) => {\n const path = [...pathPrefix, ...issue.path];\n\n if (issue.code === 'invalid_union') {\n return issue.errors.flatMap((branch) =>\n flattenIssueBranches(branch, path),\n );\n }\n\n return [\n {\n code: issue.code,\n message: issue.message,\n path: path.length === 0 ? null : formatPath(path),\n } satisfies UserInputIssue,\n ];\n });\n\n return dedupeIssues(flattened);\n}\n\nfunction dedupeIssues(issues: readonly UserInputIssue[]): UserInputIssue[] {\n const seen = new Set<string>();\n const deduped: UserInputIssue[] = [];\n\n for (const issue of issues) {\n const key = `${issue.code}:${issue.path ?? ''}:${issue.message}`;\n\n if (seen.has(key)) {\n continue;\n }\n\n seen.add(key);\n deduped.push(issue);\n }\n\n return deduped.sort(compareIssues);\n}\n\nfunction compareIssues(left: UserInputIssue, right: UserInputIssue): number {\n if (left.path === null && right.path !== null) {\n return -1;\n }\n\n if (left.path !== null && right.path === null) {\n return 1;\n }\n\n return (left.path ?? '').localeCompare(right.path ?? '');\n}\n\nfunction formatPath(path: readonly PropertyKey[]): string {\n return path.reduce<string>((result, segment) => {\n if (typeof segment === 'number') {\n return `${result}[${segment.toString()}]`;\n }\n\n if (typeof segment !== 'string') {\n return result;\n }\n\n if (segment.includes('\"')) {\n return `${result}[\"${segment.replaceAll('\"', '\\\\\"')}\"]`;\n }\n\n if (!identifierRegex.test(segment)) {\n return `${result}[\"${segment}\"]`;\n }\n\n if (result.length === 0) {\n return segment;\n }\n\n return `${result}.${segment}`;\n }, '');\n}\n","import type { PerpsCancelOrderResult } from '@polymarket/bindings/perps';\n\nexport {\n type RealtimeErrorCode,\n RealtimeKnownErrorCode,\n} from '@polymarket/bindings/subscriptions';\n\nimport { PolymarketError } from '@polymarket/types';\nimport type { ZodError } from 'zod';\nimport type { RateLimitUpdate } from './rate-limit';\nimport {\n formatInputZodError,\n formatResponseZodError,\n type ResponseValidationContext,\n} from './validation';\n\n/**\n * Error thrown when an action input fails SDK validation before a request is\n * sent.\n */\nexport class UserInputError extends PolymarketError {\n override name = 'UserInputError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n\n static fromZodError(error: ZodError): UserInputError {\n return new UserInputError(formatInputZodError(error), {\n cause: error,\n });\n }\n}\n\n/**\n * Error thrown when pagination would pass the deepest page the service serves\n * for a list.\n *\n * Some list endpoints cap how far an offset-paginated read may go and reject\n * requests past the cap. The SDK throws this before sending such a request;\n * the pages already returned stay valid, but whether more items exist past\n * the cap cannot be established. Automatic iteration stops normally on a page\n * with `limitReached: true`; explicitly resuming past the cap still throws.\n */\nexport class PaginationLimitError extends PolymarketError {\n override name = 'PaginationLimitError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n}\n\n/**\n * Error thrown when a service response does not match the action's expected\n * response shape.\n */\nexport class UnexpectedResponseError extends PolymarketError {\n override name = 'UnexpectedResponseError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n\n static fromZodError(\n error: ZodError,\n context: ResponseValidationContext,\n ): UnexpectedResponseError {\n return new UnexpectedResponseError(formatResponseZodError(error, context), {\n cause: error,\n });\n }\n}\n\n/**\n * Error thrown when the SDK cannot complete a request because of a network or\n * runtime transport failure.\n */\nexport class TransportError extends PolymarketError {\n override name = 'TransportError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n\n static fromError(error: unknown): TransportError {\n return new TransportError(\n error instanceof Error ? error.message : 'Request failed',\n {\n cause: error,\n },\n );\n }\n}\n\n/**\n * WebSocket close codes defined by RFC 6455 and the IANA WebSocket Close Code\n * Number registry. Codes 4000-4999 are reserved for application use and are\n * intentionally not modeled here.\n */\nexport enum WebSocketKnownCloseCode {\n NormalClosure = 1000,\n GoingAway = 1001,\n ProtocolError = 1002,\n UnsupportedData = 1003,\n /** Synthesized locally when the peer closed without a status code. */\n NoStatusReceived = 1005,\n /** Synthesized locally when the connection dropped without a close frame. */\n AbnormalClosure = 1006,\n InvalidFramePayload = 1007,\n PolicyViolation = 1008,\n MessageTooBig = 1009,\n InternalError = 1011,\n ServiceRestart = 1012,\n TryAgainLater = 1013,\n}\n\n/**\n * A WebSocket close code. Codes enumerated in\n * {@link WebSocketKnownCloseCode} are defined by RFC 6455; other values, such\n * as application-defined 4000-4999 codes, flow through as plain numbers.\n */\nexport type WebSocketCloseCode = WebSocketKnownCloseCode | (number & {});\n\nexport type ConnectionLostErrorOptions = {\n /** WebSocket close code reported for the lost connection. */\n code: WebSocketCloseCode;\n /** Close reason provided by the peer. Empty when none was sent. */\n reason: string;\n};\n\n/**\n * Error thrown when a live connection ends without the SDK requesting it.\n */\nexport class ConnectionLostError extends PolymarketError {\n override name = 'ConnectionLostError' as const;\n\n readonly code: WebSocketCloseCode;\n readonly reason: string;\n\n constructor(\n message: string,\n options: ErrorOptions & ConnectionLostErrorOptions,\n ) {\n super(message, options);\n this.code = options.code;\n this.reason = options.reason;\n }\n}\n\n/**\n * Trading restriction reported by the venue while orders cannot be placed\n * normally. The SDK does not retry automatically; callers decide how to\n * react, honoring {@link RequestRejectedError.retryAfter} when provided.\n */\nexport enum TradingRestriction {\n /** The matching engine is restarting and rejects order requests until it is back. */\n RESTARTING = 'restarting',\n /** Cancels and post-only orders are accepted; other orders are rejected. */\n POST_ONLY = 'post_only',\n}\n\nexport type RequestRejectedErrorOptions = {\n status: number;\n /**\n * Machine-readable error code from the response body, when the service\n * provided one.\n */\n code?: string;\n /**\n * Server-requested delay in seconds before retrying, when the response\n * provided one.\n */\n retryAfter?: number;\n /**\n * Trading restriction that caused the rejection, when the response\n * identified one.\n */\n restriction?: TradingRestriction;\n};\n\n/**\n * Error thrown when a service responds with a non-success status other than\n * rate limiting.\n */\nexport class RequestRejectedError extends PolymarketError {\n override name = 'RequestRejectedError' as const;\n\n readonly status: number;\n /**\n * Machine-readable error code from the response body, when the service\n * provided one.\n */\n readonly code?: string;\n /**\n * Server-requested delay in seconds before retrying, when the response\n * provided one.\n */\n readonly retryAfter?: number;\n /**\n * Trading restriction that caused the rejection, when the response\n * identified one.\n */\n readonly restriction?: TradingRestriction;\n\n constructor(\n message: string,\n options: ErrorOptions & RequestRejectedErrorOptions,\n ) {\n super(message, options);\n this.status = options.status;\n this.code = options.code;\n this.retryAfter = options.retryAfter;\n this.restriction = options.restriction;\n }\n}\n\nexport type RateLimitErrorOptions = {\n /**\n * Server-requested delay in seconds before retrying, when the response\n * provided one.\n */\n retryAfter?: number;\n /**\n * Rate-limit state reported with the rejection, when the response provided\n * it.\n */\n rateLimit?: RateLimitUpdate;\n};\n\n/**\n * Error thrown when the service rejects a request because the rate limit has\n * been exceeded.\n */\nexport class RateLimitError extends PolymarketError {\n override name = 'RateLimitError' as const;\n\n /**\n * Server-requested delay in seconds before retrying, when the response\n * provided one.\n */\n readonly retryAfter?: number;\n /**\n * Rate-limit state reported with the rejection, when the response provided\n * it.\n */\n readonly rateLimit?: RateLimitUpdate;\n\n constructor(\n message: string,\n options: ErrorOptions & RateLimitErrorOptions = {},\n ) {\n super(message, options);\n this.retryAfter = options.retryAfter;\n this.rateLimit = options.rateLimit;\n }\n}\n\n/**\n * Error thrown when an async wait operation exceeds its allotted polling time.\n */\nexport class TimeoutError extends PolymarketError {\n override name = 'TimeoutError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n}\n\n/**\n * Error thrown when an operation is interrupted through an abort signal.\n */\nexport class OperationAbortedError extends PolymarketError {\n override name = 'OperationAbortedError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n\n static fromReason(reason: unknown): OperationAbortedError {\n return new OperationAbortedError('Operation was aborted.', {\n cause: reason,\n });\n }\n}\n\n/**\n * Error thrown when a submitted transaction reaches a terminal failure state.\n */\nexport class TransactionFailedError extends PolymarketError {\n override name = 'TransactionFailedError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n}\n\n/**\n * Error thrown when the user cancels a required wallet signing action.\n */\nexport class CancelledSigningError extends PolymarketError {\n override name = 'CancelledSigningError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n\n static fromError(error: Error): CancelledSigningError {\n return new CancelledSigningError(error.message, {\n cause: error,\n });\n }\n}\n\n/**\n * Error thrown when there is not enough resting market liquidity to satisfy the\n * requested execution semantics.\n */\nexport class InsufficientLiquidityError extends PolymarketError {\n override name = 'InsufficientLiquidityError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n}\n\n/**\n * Error thrown when arming auto-cancel is rejected because the account has\n * reached its daily auto-cancel trigger limit. Arming is rejected until the\n * daily counter resets at the next UTC midnight; clearing an existing\n * schedule is always allowed.\n *\n * @experimental This API may change in a breaking way in any release, including patch releases.\n */\nexport class AutoCancelDailyLimitError extends PolymarketError {\n override name = 'AutoCancelDailyLimitError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n}\n\n/**\n * Details retained when a Perps cancellation retry fails.\n *\n * @experimental This API may change in a breaking way in any release, including patch releases.\n */\nexport type PerpsCancelRetryErrorOptions = {\n /** Last received per-order outcomes, in the original request order. */\n results: readonly PerpsCancelOrderResult[];\n /** Zero-based original request positions retried in the failed attempt. */\n pendingIndexes: readonly number[];\n};\n\n/**\n * Error thrown when a Perps cancellation retry fails after per-order results\n * have already been received. The original failure is available as `cause`.\n *\n * @experimental This API may change in a breaking way in any release, including patch releases.\n */\nexport class PerpsCancelRetryError extends PolymarketError {\n override name = 'PerpsCancelRetryError' as const;\n\n /** Last received per-order outcomes, in the original request order. */\n readonly results: readonly PerpsCancelOrderResult[];\n /**\n * Zero-based original request positions retried in the failed attempt.\n * Their retained rejections are historical: a transport failure can conceal\n * completion, so these results do not establish the current order state.\n */\n readonly pendingIndexes: readonly number[];\n\n constructor(\n message: string,\n options: ErrorOptions & PerpsCancelRetryErrorOptions,\n ) {\n super(message, options);\n this.results = [...options.results];\n this.pendingIndexes = [...options.pendingIndexes];\n }\n}\n\n/**\n * Error thrown when the SDK cannot produce a required signature or\n * authentication payload.\n */\nexport class SigningError extends PolymarketError {\n override name = 'SigningError' as const;\n\n constructor(message: string, options: ErrorOptions = {}) {\n super(message, options);\n }\n\n static fromError(error: unknown, message?: string): SigningError {\n const msg =\n message ?? (error instanceof Error ? error.message : 'Signing failed');\n return new SigningError(msg, { cause: error });\n }\n}\n\nexport function makeErrorGuard<\n // biome-ignore lint/suspicious/noExplicitAny: constructor rest args require any[]\n TClasses extends ReadonlyArray<new (...args: any[]) => unknown>,\n>(\n ...classes: TClasses\n): { isError(error: unknown): error is InstanceType<TClasses[number]> } {\n return {\n isError(error: unknown): error is InstanceType<TClasses[number]> {\n return classes.some((c) => error instanceof c);\n },\n };\n}\n"]}
|