@canton-network/core-rpc-errors 1.13.0 → 1.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/dist/index.cjs CHANGED
@@ -33,7 +33,8 @@ const toHttpErrorCode = (rpcCode) => {
33
33
  [_metamask_rpc_errors.errorCodes.rpc.invalidParams]: 400,
34
34
  [_metamask_rpc_errors.errorCodes.rpc.invalidInput]: 400,
35
35
  [_metamask_rpc_errors.errorCodes.provider.unauthorized]: 401,
36
- [_metamask_rpc_errors.errorCodes.rpc.internal]: 500
36
+ [_metamask_rpc_errors.errorCodes.rpc.internal]: 500,
37
+ [_metamask_rpc_errors.errorCodes.rpc.resourceUnavailable]: 503
37
38
  }[rpcCode] || 500;
38
39
  };
39
40
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["errorCodes","JsonRpcError","serializeError","getMessageFromCode"],"sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n errorCodes,\n getMessageFromCode,\n JsonRpcError,\n serializeError,\n type OptionalDataWithOptionalCause,\n} from '@metamask/rpc-errors'\n\nexport {\n rpcErrors,\n providerErrors,\n JsonRpcError,\n errorCodes,\n getMessageFromCode,\n} from '@metamask/rpc-errors'\n\n/** The EIP-1193 and EIP-1474 codes adopted by CIP-103, see https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md */\nconst CIP103_ERROR_CODES: ReadonlySet<number> = new Set([\n ...Object.values(errorCodes.rpc),\n ...Object.values(errorCodes.provider),\n])\n\nexport function isCip103ErrorCode(code: unknown): code is number {\n return typeof code === 'number' && CIP103_ERROR_CODES.has(code)\n}\n\n/** `serializeError` only keeps the code of objects without any extra key, so drop everything else first. */\nfunction pickErrorFields(error: unknown): unknown {\n if (typeof error !== 'object' || error === null || !('code' in error))\n return error\n const { code, message, data } = error as Record<string, unknown>\n return data === undefined ? { code, message } : { code, message, data }\n}\n\n/** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */\nexport function toJsonRpcError(\n error: unknown\n): JsonRpcError<OptionalDataWithOptionalCause> {\n if (error instanceof JsonRpcError) return error\n // Non-JSON-RPC values become an internal error with the original in `data.cause`.\n const { code, message, data } = serializeError(pickErrorFields(error))\n return new JsonRpcError(code, message || getMessageFromCode(code), data)\n}\n\nexport const toHttpErrorCode = (rpcCode: number): number => {\n const errorMap = {\n [errorCodes.rpc.parse]: 400,\n [errorCodes.rpc.invalidRequest]: 400,\n [errorCodes.rpc.methodNotFound]: 404,\n [errorCodes.rpc.invalidParams]: 400,\n [errorCodes.rpc.invalidInput]: 400,\n [errorCodes.provider.unauthorized]: 401,\n [errorCodes.rpc.internal]: 500,\n }\n\n return errorMap[rpcCode] || 500\n}\n"],"mappings":";;;;AAoBA,MAAM,qCAA0C,IAAI,IAAI,CACpD,GAAG,OAAO,OAAOA,qBAAAA,WAAW,GAAG,GAC/B,GAAG,OAAO,OAAOA,qBAAAA,WAAW,QAAQ,CACxC,CAAC;AAED,SAAgB,kBAAkB,MAA+B;CAC7D,OAAO,OAAO,SAAS,YAAY,mBAAmB,IAAI,IAAI;AAClE;;AAGA,SAAS,gBAAgB,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAC3D,OAAO;CACX,MAAM,EAAE,MAAM,SAAS,SAAS;CAChC,OAAO,SAAS,KAAA,IAAY;EAAE;EAAM;CAAQ,IAAI;EAAE;EAAM;EAAS;CAAK;AAC1E;;AAGA,SAAgB,eACZ,OAC2C;CAC3C,IAAI,iBAAiBC,qBAAAA,cAAc,OAAO;CAE1C,MAAM,EAAE,MAAM,SAAS,UAAA,GAASC,qBAAAA,eAAAA,CAAe,gBAAgB,KAAK,CAAC;CACrE,OAAO,IAAID,qBAAAA,aAAa,MAAM,YAAA,GAAWE,qBAAAA,mBAAAA,CAAmB,IAAI,GAAG,IAAI;AAC3E;AAEA,MAAa,mBAAmB,YAA4B;CAWxD,OAAO;GATFH,qBAAAA,WAAW,IAAI,QAAQ;GACvBA,qBAAAA,WAAW,IAAI,iBAAiB;GAChCA,qBAAAA,WAAW,IAAI,iBAAiB;GAChCA,qBAAAA,WAAW,IAAI,gBAAgB;GAC/BA,qBAAAA,WAAW,IAAI,eAAe;GAC9BA,qBAAAA,WAAW,SAAS,eAAe;GACnCA,qBAAAA,WAAW,IAAI,WAAW;CAGjB,EAAE,YAAY;AAChC"}
1
+ {"version":3,"file":"index.cjs","names":["errorCodes","JsonRpcError","serializeError","getMessageFromCode"],"sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n errorCodes,\n getMessageFromCode,\n JsonRpcError,\n serializeError,\n type OptionalDataWithOptionalCause,\n} from '@metamask/rpc-errors'\n\nexport {\n rpcErrors,\n providerErrors,\n JsonRpcError,\n errorCodes,\n getMessageFromCode,\n} from '@metamask/rpc-errors'\n\n/** The EIP-1193 and EIP-1474 codes adopted by CIP-103, see https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md */\nconst CIP103_ERROR_CODES: ReadonlySet<number> = new Set([\n ...Object.values(errorCodes.rpc),\n ...Object.values(errorCodes.provider),\n])\n\nexport function isCip103ErrorCode(code: unknown): code is number {\n return typeof code === 'number' && CIP103_ERROR_CODES.has(code)\n}\n\n/** `serializeError` only keeps the code of objects without any extra key, so drop everything else first. */\nfunction pickErrorFields(error: unknown): unknown {\n if (typeof error !== 'object' || error === null || !('code' in error))\n return error\n const { code, message, data } = error as Record<string, unknown>\n return data === undefined ? { code, message } : { code, message, data }\n}\n\n/** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */\nexport function toJsonRpcError(\n error: unknown\n): JsonRpcError<OptionalDataWithOptionalCause> {\n if (error instanceof JsonRpcError) return error\n // Non-JSON-RPC values become an internal error with the original in `data.cause`.\n const { code, message, data } = serializeError(pickErrorFields(error))\n return new JsonRpcError(code, message || getMessageFromCode(code), data)\n}\n\nexport const toHttpErrorCode = (rpcCode: number): number => {\n const errorMap = {\n [errorCodes.rpc.parse]: 400,\n [errorCodes.rpc.invalidRequest]: 400,\n [errorCodes.rpc.methodNotFound]: 404,\n [errorCodes.rpc.invalidParams]: 400,\n [errorCodes.rpc.invalidInput]: 400,\n [errorCodes.provider.unauthorized]: 401,\n [errorCodes.rpc.internal]: 500,\n [errorCodes.rpc.resourceUnavailable]: 503,\n }\n\n return errorMap[rpcCode] || 500\n}\n"],"mappings":";;;;AAoBA,MAAM,qCAA0C,IAAI,IAAI,CACpD,GAAG,OAAO,OAAOA,qBAAAA,WAAW,GAAG,GAC/B,GAAG,OAAO,OAAOA,qBAAAA,WAAW,QAAQ,CACxC,CAAC;AAED,SAAgB,kBAAkB,MAA+B;CAC7D,OAAO,OAAO,SAAS,YAAY,mBAAmB,IAAI,IAAI;AAClE;;AAGA,SAAS,gBAAgB,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAC3D,OAAO;CACX,MAAM,EAAE,MAAM,SAAS,SAAS;CAChC,OAAO,SAAS,KAAA,IAAY;EAAE;EAAM;CAAQ,IAAI;EAAE;EAAM;EAAS;CAAK;AAC1E;;AAGA,SAAgB,eACZ,OAC2C;CAC3C,IAAI,iBAAiBC,qBAAAA,cAAc,OAAO;CAE1C,MAAM,EAAE,MAAM,SAAS,UAAA,GAASC,qBAAAA,eAAAA,CAAe,gBAAgB,KAAK,CAAC;CACrE,OAAO,IAAID,qBAAAA,aAAa,MAAM,YAAA,GAAWE,qBAAAA,mBAAAA,CAAmB,IAAI,GAAG,IAAI;AAC3E;AAEA,MAAa,mBAAmB,YAA4B;CAYxD,OAAO;GAVFH,qBAAAA,WAAW,IAAI,QAAQ;GACvBA,qBAAAA,WAAW,IAAI,iBAAiB;GAChCA,qBAAAA,WAAW,IAAI,iBAAiB;GAChCA,qBAAAA,WAAW,IAAI,gBAAgB;GAC/BA,qBAAAA,WAAW,IAAI,eAAe;GAC9BA,qBAAAA,WAAW,SAAS,eAAe;GACnCA,qBAAAA,WAAW,IAAI,WAAW;GAC1BA,qBAAAA,WAAW,IAAI,sBAAsB;CAG5B,EAAE,YAAY;AAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAGH,YAAY,EAEZ,KAAK,6BAA6B,EACrC,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACH,SAAS,EACT,cAAc,EACd,YAAY,EACZ,UAAU,EACV,kBAAkB,GACrB,MAAM,sBAAsB,CAAA;AAQ7B,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAE/D;AAUD,0GAA0G;AAC1G,wBAAgB,cAAc,CAC1B,KAAK,EAAE,OAAO,GACf,YAAY,CAAC,6BAA6B,CAAC,CAK7C;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,KAAG,MAYjD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAGH,YAAY,EAEZ,KAAK,6BAA6B,EACrC,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACH,SAAS,EACT,cAAc,EACd,YAAY,EACZ,UAAU,EACV,kBAAkB,GACrB,MAAM,sBAAsB,CAAA;AAQ7B,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAE/D;AAUD,0GAA0G;AAC1G,wBAAgB,cAAc,CAC1B,KAAK,EAAE,OAAO,GACf,YAAY,CAAC,6BAA6B,CAAC,CAK7C;AAED,eAAO,MAAM,eAAe,YAAa,MAAM,KAAG,MAajD,CAAA"}
package/dist/index.js CHANGED
@@ -32,7 +32,8 @@ const toHttpErrorCode = (rpcCode) => {
32
32
  [errorCodes$1.rpc.invalidParams]: 400,
33
33
  [errorCodes$1.rpc.invalidInput]: 400,
34
34
  [errorCodes$1.provider.unauthorized]: 401,
35
- [errorCodes$1.rpc.internal]: 500
35
+ [errorCodes$1.rpc.internal]: 500,
36
+ [errorCodes$1.rpc.resourceUnavailable]: 503
36
37
  }[rpcCode] || 500;
37
38
  };
38
39
  //#endregion
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["errorCodes","JsonRpcError","getMessageFromCode"],"sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n errorCodes,\n getMessageFromCode,\n JsonRpcError,\n serializeError,\n type OptionalDataWithOptionalCause,\n} from '@metamask/rpc-errors'\n\nexport {\n rpcErrors,\n providerErrors,\n JsonRpcError,\n errorCodes,\n getMessageFromCode,\n} from '@metamask/rpc-errors'\n\n/** The EIP-1193 and EIP-1474 codes adopted by CIP-103, see https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md */\nconst CIP103_ERROR_CODES: ReadonlySet<number> = new Set([\n ...Object.values(errorCodes.rpc),\n ...Object.values(errorCodes.provider),\n])\n\nexport function isCip103ErrorCode(code: unknown): code is number {\n return typeof code === 'number' && CIP103_ERROR_CODES.has(code)\n}\n\n/** `serializeError` only keeps the code of objects without any extra key, so drop everything else first. */\nfunction pickErrorFields(error: unknown): unknown {\n if (typeof error !== 'object' || error === null || !('code' in error))\n return error\n const { code, message, data } = error as Record<string, unknown>\n return data === undefined ? { code, message } : { code, message, data }\n}\n\n/** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */\nexport function toJsonRpcError(\n error: unknown\n): JsonRpcError<OptionalDataWithOptionalCause> {\n if (error instanceof JsonRpcError) return error\n // Non-JSON-RPC values become an internal error with the original in `data.cause`.\n const { code, message, data } = serializeError(pickErrorFields(error))\n return new JsonRpcError(code, message || getMessageFromCode(code), data)\n}\n\nexport const toHttpErrorCode = (rpcCode: number): number => {\n const errorMap = {\n [errorCodes.rpc.parse]: 400,\n [errorCodes.rpc.invalidRequest]: 400,\n [errorCodes.rpc.methodNotFound]: 404,\n [errorCodes.rpc.invalidParams]: 400,\n [errorCodes.rpc.invalidInput]: 400,\n [errorCodes.provider.unauthorized]: 401,\n [errorCodes.rpc.internal]: 500,\n }\n\n return errorMap[rpcCode] || 500\n}\n"],"mappings":";;;AAoBA,MAAM,qCAA0C,IAAI,IAAI,CACpD,GAAG,OAAO,OAAOA,aAAW,GAAG,GAC/B,GAAG,OAAO,OAAOA,aAAW,QAAQ,CACxC,CAAC;AAED,SAAgB,kBAAkB,MAA+B;CAC7D,OAAO,OAAO,SAAS,YAAY,mBAAmB,IAAI,IAAI;AAClE;;AAGA,SAAS,gBAAgB,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAC3D,OAAO;CACX,MAAM,EAAE,MAAM,SAAS,SAAS;CAChC,OAAO,SAAS,KAAA,IAAY;EAAE;EAAM;CAAQ,IAAI;EAAE;EAAM;EAAS;CAAK;AAC1E;;AAGA,SAAgB,eACZ,OAC2C;CAC3C,IAAI,iBAAiBC,gBAAc,OAAO;CAE1C,MAAM,EAAE,MAAM,SAAS,SAAS,eAAe,gBAAgB,KAAK,CAAC;CACrE,OAAO,IAAIA,eAAa,MAAM,WAAWC,qBAAmB,IAAI,GAAG,IAAI;AAC3E;AAEA,MAAa,mBAAmB,YAA4B;CAWxD,OAAO;GATFF,aAAW,IAAI,QAAQ;GACvBA,aAAW,IAAI,iBAAiB;GAChCA,aAAW,IAAI,iBAAiB;GAChCA,aAAW,IAAI,gBAAgB;GAC/BA,aAAW,IAAI,eAAe;GAC9BA,aAAW,SAAS,eAAe;GACnCA,aAAW,IAAI,WAAW;CAGjB,EAAE,YAAY;AAChC"}
1
+ {"version":3,"file":"index.js","names":["errorCodes","JsonRpcError","getMessageFromCode"],"sources":["../src/index.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n errorCodes,\n getMessageFromCode,\n JsonRpcError,\n serializeError,\n type OptionalDataWithOptionalCause,\n} from '@metamask/rpc-errors'\n\nexport {\n rpcErrors,\n providerErrors,\n JsonRpcError,\n errorCodes,\n getMessageFromCode,\n} from '@metamask/rpc-errors'\n\n/** The EIP-1193 and EIP-1474 codes adopted by CIP-103, see https://github.com/canton-foundation/cips/blob/main/cip-0103/cip-0103.md */\nconst CIP103_ERROR_CODES: ReadonlySet<number> = new Set([\n ...Object.values(errorCodes.rpc),\n ...Object.values(errorCodes.provider),\n])\n\nexport function isCip103ErrorCode(code: unknown): code is number {\n return typeof code === 'number' && CIP103_ERROR_CODES.has(code)\n}\n\n/** `serializeError` only keeps the code of objects without any extra key, so drop everything else first. */\nfunction pickErrorFields(error: unknown): unknown {\n if (typeof error !== 'object' || error === null || !('code' in error))\n return error\n const { code, message, data } = error as Record<string, unknown>\n return data === undefined ? { code, message } : { code, message, data }\n}\n\n/** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */\nexport function toJsonRpcError(\n error: unknown\n): JsonRpcError<OptionalDataWithOptionalCause> {\n if (error instanceof JsonRpcError) return error\n // Non-JSON-RPC values become an internal error with the original in `data.cause`.\n const { code, message, data } = serializeError(pickErrorFields(error))\n return new JsonRpcError(code, message || getMessageFromCode(code), data)\n}\n\nexport const toHttpErrorCode = (rpcCode: number): number => {\n const errorMap = {\n [errorCodes.rpc.parse]: 400,\n [errorCodes.rpc.invalidRequest]: 400,\n [errorCodes.rpc.methodNotFound]: 404,\n [errorCodes.rpc.invalidParams]: 400,\n [errorCodes.rpc.invalidInput]: 400,\n [errorCodes.provider.unauthorized]: 401,\n [errorCodes.rpc.internal]: 500,\n [errorCodes.rpc.resourceUnavailable]: 503,\n }\n\n return errorMap[rpcCode] || 500\n}\n"],"mappings":";;;AAoBA,MAAM,qCAA0C,IAAI,IAAI,CACpD,GAAG,OAAO,OAAOA,aAAW,GAAG,GAC/B,GAAG,OAAO,OAAOA,aAAW,QAAQ,CACxC,CAAC;AAED,SAAgB,kBAAkB,MAA+B;CAC7D,OAAO,OAAO,SAAS,YAAY,mBAAmB,IAAI,IAAI;AAClE;;AAGA,SAAS,gBAAgB,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,EAAE,UAAU,QAC3D,OAAO;CACX,MAAM,EAAE,MAAM,SAAS,SAAS;CAChC,OAAO,SAAS,KAAA,IAAY;EAAE;EAAM;CAAQ,IAAI;EAAE;EAAM;EAAS;CAAK;AAC1E;;AAGA,SAAgB,eACZ,OAC2C;CAC3C,IAAI,iBAAiBC,gBAAc,OAAO;CAE1C,MAAM,EAAE,MAAM,SAAS,SAAS,eAAe,gBAAgB,KAAK,CAAC;CACrE,OAAO,IAAIA,eAAa,MAAM,WAAWC,qBAAmB,IAAI,GAAG,IAAI;AAC3E;AAEA,MAAa,mBAAmB,YAA4B;CAYxD,OAAO;GAVFF,aAAW,IAAI,QAAQ;GACvBA,aAAW,IAAI,iBAAiB;GAChCA,aAAW,IAAI,iBAAiB;GAChCA,aAAW,IAAI,gBAAgB;GAC/BA,aAAW,IAAI,eAAe;GAC9BA,aAAW,SAAS,eAAe;GACnCA,aAAW,IAAI,WAAW;GAC1BA,aAAW,IAAI,sBAAsB;CAG5B,EAAE,YAAY;AAChC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canton-network/core-rpc-errors",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "type": "module",
5
5
  "description": "Wrapper for JSON-RPC error objects",
6
6
  "author": "Alex Matson <alex.matson@digitalasset.com>",
@@ -27,10 +27,10 @@
27
27
  "@metamask/rpc-errors": "^7.0.3"
28
28
  },
29
29
  "devDependencies": {
30
- "@vitest/coverage-v8": "^5.0.1",
31
- "tsdown": "^0.22.9",
32
- "typescript": "^6.0.3",
33
- "vitest": "^5.0.1"
30
+ "@vitest/coverage-v8": "^5.0.5",
31
+ "tsdown": "^0.23.1",
32
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
33
+ "vitest": "^5.0.5"
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",
@@ -42,9 +42,9 @@
42
42
  "url": "https://github.com/canton-network/wallet/issues"
43
43
  },
44
44
  "scripts": {
45
- "build": "tsdown --onSuccess \"tsc\"",
46
- "dev": "tsdown --watch --onSuccess \"tsc\"",
45
+ "build": "tsdown --onSuccess \"tsc -p tsconfig.lib.json\"",
46
+ "dev": "tsdown --watch --onSuccess \"tsc -p tsconfig.lib.json\"",
47
47
  "flatpack": "pnpm pack --pack-destination \"$FLATPACK_OUTDIR\"",
48
- "clean": "tsc -b --clean; rm -rf dist"
48
+ "clean": "rm -rf dist"
49
49
  }
50
50
  }