@canton-network/core-rpc-errors 1.12.0 → 1.13.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
@@ -1,6 +1,30 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _metamask_rpc_errors = require("@metamask/rpc-errors");
3
3
  //#region src/index.ts
4
+ /** 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 */
5
+ const CIP103_ERROR_CODES = /* @__PURE__ */ new Set([...Object.values(_metamask_rpc_errors.errorCodes.rpc), ...Object.values(_metamask_rpc_errors.errorCodes.provider)]);
6
+ function isCip103ErrorCode(code) {
7
+ return typeof code === "number" && CIP103_ERROR_CODES.has(code);
8
+ }
9
+ /** `serializeError` only keeps the code of objects without any extra key, so drop everything else first. */
10
+ function pickErrorFields(error) {
11
+ if (typeof error !== "object" || error === null || !("code" in error)) return error;
12
+ const { code, message, data } = error;
13
+ return data === void 0 ? {
14
+ code,
15
+ message
16
+ } : {
17
+ code,
18
+ message,
19
+ data
20
+ };
21
+ }
22
+ /** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */
23
+ function toJsonRpcError(error) {
24
+ if (error instanceof _metamask_rpc_errors.JsonRpcError) return error;
25
+ const { code, message, data } = (0, _metamask_rpc_errors.serializeError)(pickErrorFields(error));
26
+ return new _metamask_rpc_errors.JsonRpcError(code, message || (0, _metamask_rpc_errors.getMessageFromCode)(code), data);
27
+ }
4
28
  const toHttpErrorCode = (rpcCode) => {
5
29
  return {
6
30
  [_metamask_rpc_errors.errorCodes.rpc.parse]: 400,
@@ -19,6 +43,19 @@ Object.defineProperty(exports, "JsonRpcError", {
19
43
  return _metamask_rpc_errors.JsonRpcError;
20
44
  }
21
45
  });
46
+ Object.defineProperty(exports, "errorCodes", {
47
+ enumerable: true,
48
+ get: function() {
49
+ return _metamask_rpc_errors.errorCodes;
50
+ }
51
+ });
52
+ Object.defineProperty(exports, "getMessageFromCode", {
53
+ enumerable: true,
54
+ get: function() {
55
+ return _metamask_rpc_errors.getMessageFromCode;
56
+ }
57
+ });
58
+ exports.isCip103ErrorCode = isCip103ErrorCode;
22
59
  Object.defineProperty(exports, "providerErrors", {
23
60
  enumerable: true,
24
61
  get: function() {
@@ -32,5 +69,6 @@ Object.defineProperty(exports, "rpcErrors", {
32
69
  }
33
70
  });
34
71
  exports.toHttpErrorCode = toHttpErrorCode;
72
+ exports.toJsonRpcError = toJsonRpcError;
35
73
 
36
74
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["errorCodes"],"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 { errorCodes } from '@metamask/rpc-errors'\n\nexport { rpcErrors, providerErrors, JsonRpcError } from '@metamask/rpc-errors'\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":";;;AAOA,MAAa,mBAAmB,YAA4B;CAWxD,OAAO;GATFA,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 }\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"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- export { rpcErrors, providerErrors, JsonRpcError } from '@metamask/rpc-errors';
1
+ import { JsonRpcError, type OptionalDataWithOptionalCause } from '@metamask/rpc-errors';
2
+ export { rpcErrors, providerErrors, JsonRpcError, errorCodes, getMessageFromCode, } from '@metamask/rpc-errors';
3
+ export declare function isCip103ErrorCode(code: unknown): code is number;
4
+ /** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */
5
+ export declare function toJsonRpcError(error: unknown): JsonRpcError<OptionalDataWithOptionalCause>;
2
6
  export declare const toHttpErrorCode: (rpcCode: number) => number;
3
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE9E,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,GAAI,SAAS,MAAM,KAAG,MAYjD,CAAA"}
package/dist/index.js CHANGED
@@ -1,17 +1,41 @@
1
- import { JsonRpcError, errorCodes, providerErrors, rpcErrors } from "@metamask/rpc-errors";
1
+ import { JsonRpcError, JsonRpcError as JsonRpcError$1, errorCodes, errorCodes as errorCodes$1, getMessageFromCode, getMessageFromCode as getMessageFromCode$1, providerErrors, rpcErrors, serializeError } from "@metamask/rpc-errors";
2
2
  //#region src/index.ts
3
+ /** 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 */
4
+ const CIP103_ERROR_CODES = /* @__PURE__ */ new Set([...Object.values(errorCodes$1.rpc), ...Object.values(errorCodes$1.provider)]);
5
+ function isCip103ErrorCode(code) {
6
+ return typeof code === "number" && CIP103_ERROR_CODES.has(code);
7
+ }
8
+ /** `serializeError` only keeps the code of objects without any extra key, so drop everything else first. */
9
+ function pickErrorFields(error) {
10
+ if (typeof error !== "object" || error === null || !("code" in error)) return error;
11
+ const { code, message, data } = error;
12
+ return data === void 0 ? {
13
+ code,
14
+ message
15
+ } : {
16
+ code,
17
+ message,
18
+ data
19
+ };
20
+ }
21
+ /** Converts a JSON-RPC error object or any other thrown value into a `JsonRpcError`, keeping its code. */
22
+ function toJsonRpcError(error) {
23
+ if (error instanceof JsonRpcError$1) return error;
24
+ const { code, message, data } = serializeError(pickErrorFields(error));
25
+ return new JsonRpcError$1(code, message || getMessageFromCode$1(code), data);
26
+ }
3
27
  const toHttpErrorCode = (rpcCode) => {
4
28
  return {
5
- [errorCodes.rpc.parse]: 400,
6
- [errorCodes.rpc.invalidRequest]: 400,
7
- [errorCodes.rpc.methodNotFound]: 404,
8
- [errorCodes.rpc.invalidParams]: 400,
9
- [errorCodes.rpc.invalidInput]: 400,
10
- [errorCodes.provider.unauthorized]: 401,
11
- [errorCodes.rpc.internal]: 500
29
+ [errorCodes$1.rpc.parse]: 400,
30
+ [errorCodes$1.rpc.invalidRequest]: 400,
31
+ [errorCodes$1.rpc.methodNotFound]: 404,
32
+ [errorCodes$1.rpc.invalidParams]: 400,
33
+ [errorCodes$1.rpc.invalidInput]: 400,
34
+ [errorCodes$1.provider.unauthorized]: 401,
35
+ [errorCodes$1.rpc.internal]: 500
12
36
  }[rpcCode] || 500;
13
37
  };
14
38
  //#endregion
15
- export { JsonRpcError, providerErrors, rpcErrors, toHttpErrorCode };
39
+ export { JsonRpcError, errorCodes, getMessageFromCode, isCip103ErrorCode, providerErrors, rpcErrors, toHttpErrorCode, toJsonRpcError };
16
40
 
17
41
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"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 { errorCodes } from '@metamask/rpc-errors'\n\nexport { rpcErrors, providerErrors, JsonRpcError } from '@metamask/rpc-errors'\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":";;AAOA,MAAa,mBAAmB,YAA4B;CAWxD,OAAO;GATF,WAAW,IAAI,QAAQ;GACvB,WAAW,IAAI,iBAAiB;GAChC,WAAW,IAAI,iBAAiB;GAChC,WAAW,IAAI,gBAAgB;GAC/B,WAAW,IAAI,eAAe;GAC9B,WAAW,SAAS,eAAe;GACnC,WAAW,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 }\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"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@canton-network/core-rpc-errors",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "type": "module",
5
5
  "description": "Wrapper for JSON-RPC error objects",
6
6
  "author": "Alex Matson <alex.matson@digitalasset.com>",
7
7
  "license": "Apache-2.0",
8
+ "sideEffects": false,
8
9
  "main": "dist/index.cjs",
9
10
  "module": "dist/index.js",
10
11
  "types": "dist/index.d.ts",
@@ -28,7 +29,7 @@
28
29
  "devDependencies": {
29
30
  "@vitest/coverage-v8": "^5.0.1",
30
31
  "tsdown": "^0.22.9",
31
- "typescript": "^5.9.3",
32
+ "typescript": "^6.0.3",
32
33
  "vitest": "^5.0.1"
33
34
  },
34
35
  "repository": {
@@ -44,8 +45,6 @@
44
45
  "build": "tsdown --onSuccess \"tsc\"",
45
46
  "dev": "tsdown --watch --onSuccess \"tsc\"",
46
47
  "flatpack": "pnpm pack --pack-destination \"$FLATPACK_OUTDIR\"",
47
- "clean": "tsc -b --clean; rm -rf dist",
48
- "test": "vitest run --project node --passWithNoTests",
49
- "test:coverage": "vitest run --project node --coverage --passWithNoTests"
48
+ "clean": "tsc -b --clean; rm -rf dist"
50
49
  }
51
50
  }