@kleros/kleros-sdk 2.1.3 → 2.1.5

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 (35) hide show
  1. package/README.md +1 -1
  2. package/lib/src/dataMappings/actions/callAction.d.ts +1 -1
  3. package/lib/src/dataMappings/actions/callAction.js +4 -3
  4. package/lib/src/dataMappings/actions/eventAction.d.ts +1 -1
  5. package/lib/src/dataMappings/actions/eventAction.js +4 -3
  6. package/lib/src/dataMappings/actions/fetchIpfsJsonAction.d.ts +1 -1
  7. package/lib/src/dataMappings/actions/fetchIpfsJsonAction.js +7 -6
  8. package/lib/src/dataMappings/actions/jsonAction.js +1 -1
  9. package/lib/src/dataMappings/actions/subgraphAction.js +1 -1
  10. package/lib/src/dataMappings/executeActions.js +4 -3
  11. package/lib/src/dataMappings/index.d.ts +1 -0
  12. package/lib/src/dataMappings/index.js +17 -0
  13. package/lib/src/dataMappings/retrieveRealityData.js +7 -3
  14. package/lib/src/dataMappings/utils/actionTypeValidators.d.ts +2 -2
  15. package/lib/src/dataMappings/utils/actionTypeValidators.js +15 -21
  16. package/lib/src/dataMappings/utils/index.d.ts +3 -0
  17. package/lib/src/dataMappings/utils/index.js +19 -0
  18. package/lib/src/dataMappings/utils/populateTemplate.js +2 -1
  19. package/lib/src/dataMappings/utils/replacePlaceholdersWithValues.js +2 -1
  20. package/lib/src/errors/index.d.ts +26 -0
  21. package/lib/src/errors/index.js +59 -0
  22. package/lib/src/index.d.ts +3 -2
  23. package/lib/src/index.js +3 -2
  24. package/lib/src/requests/fetchDisputeDetails.d.ts +1 -1
  25. package/lib/src/requests/fetchDisputeDetails.js +13 -8
  26. package/lib/src/requests/fetchDisputeTemplateFromId.js +14 -9
  27. package/lib/src/sdk.js +2 -1
  28. package/lib/src/types/index.d.ts +4 -4
  29. package/lib/src/utils/getDispute.d.ts +2 -2
  30. package/lib/src/utils/getDispute.js +11 -10
  31. package/lib/src/utils/index.d.ts +1 -0
  32. package/lib/src/utils/index.js +17 -0
  33. package/package.json +1 -6
  34. package/lib/src/dataMappings/disputeDetails.d.ts +0 -35
  35. package/lib/src/dataMappings/disputeDetails.js +0 -11
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @kleros/kleros-v2-sdk
1
+ # @kleros/kleros-sdk
2
2
 
3
3
  _Archon's successor_
4
4
 
@@ -1,2 +1,2 @@
1
- import { AbiCallMapping } from "src/dataMappings/utils/actionTypes";
1
+ import { AbiCallMapping } from "../utils/actionTypes";
2
2
  export declare const callAction: (mapping: AbiCallMapping) => Promise<Record<string, any>>;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.callAction = void 0;
4
4
  const viem_1 = require("viem");
5
- const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
6
- const sdk_1 = require("src/sdk");
5
+ const createResultObject_1 = require("../utils/createResultObject");
6
+ const sdk_1 = require("../../sdk");
7
+ const errors_1 = require("../../errors");
7
8
  const callAction = async (mapping) => {
8
9
  const publicClient = (0, sdk_1.getPublicClient)();
9
10
  if (!publicClient) {
10
- throw new Error("SDK not configured. Please call `configureSDK` before using.");
11
+ throw new errors_1.SdkNotConfiguredError();
11
12
  }
12
13
  const { abi: source, address, functionName, args, seek, populate } = mapping;
13
14
  const parsedAbi = typeof source === "string" ? (0, viem_1.parseAbiItem)(source) : source;
@@ -1,2 +1,2 @@
1
- import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
1
+ import { AbiEventMapping } from "../utils/actionTypes";
2
2
  export declare const eventAction: (mapping: AbiEventMapping) => Promise<Record<string, any>>;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.eventAction = void 0;
4
4
  const viem_1 = require("viem");
5
- const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
6
- const sdk_1 = require("src/sdk");
5
+ const createResultObject_1 = require("../utils/createResultObject");
6
+ const sdk_1 = require("../../sdk");
7
+ const errors_1 = require("../../errors");
7
8
  const eventAction = async (mapping) => {
8
9
  const publicClient = (0, sdk_1.getPublicClient)();
9
10
  if (!publicClient) {
10
- throw new Error("SDK not configured. Please call `configureSDK` before using.");
11
+ throw new errors_1.SdkNotConfiguredError();
11
12
  }
12
13
  const { abi: source, address, eventFilter, seek, populate } = mapping;
13
14
  const parsedAbi = (0, viem_1.parseAbiItem)(source);
@@ -1,2 +1,2 @@
1
- import { FetchIpfsJsonMapping } from "src/dataMappings/utils/actionTypes";
1
+ import { FetchIpfsJsonMapping } from "../utils/actionTypes";
2
2
  export declare const fetchIpfsJsonAction: (mapping: FetchIpfsJsonMapping) => Promise<Record<string, any>>;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchIpfsJsonAction = void 0;
4
- const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
5
- const consts_1 = require("src/consts");
4
+ const consts_1 = require("../../consts");
5
+ const errors_1 = require("../../errors");
6
+ const createResultObject_1 = require("../utils/createResultObject");
6
7
  const fetchIpfsJsonAction = async (mapping) => {
7
8
  const { ipfsUri, seek, populate } = mapping;
8
9
  let httpUri;
@@ -16,19 +17,19 @@ const fetchIpfsJsonAction = async (mapping) => {
16
17
  httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
17
18
  }
18
19
  else {
19
- throw new Error("Invalid IPFS URI format");
20
+ throw new errors_1.RequestError("Invalid IPFS URI format", httpUri);
20
21
  }
21
22
  const response = await fetch(httpUri, { method: "GET" });
22
23
  if (!response.ok) {
23
- throw new Error("Failed to fetch data from IPFS");
24
+ throw new errors_1.RequestError("Failed to fetch data from IPFS", httpUri);
24
25
  }
25
26
  const contentLength = response.headers.get("content-length");
26
27
  if (contentLength && parseInt(contentLength) > consts_1.MAX_BYTE_SIZE) {
27
- throw new Error("Response size is too large");
28
+ throw new errors_1.RequestError("Response size is too large", httpUri);
28
29
  }
29
30
  const contentType = response.headers.get("content-type");
30
31
  if (!contentType || !contentType.includes("application/json")) {
31
- throw new Error("Fetched data is not JSON");
32
+ throw new errors_1.RequestError("Fetched data is not JSON", httpUri);
32
33
  }
33
34
  const data = await response.json();
34
35
  return (0, createResultObject_1.createResultObject)(data, seek, populate);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonAction = void 0;
4
- const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
4
+ const createResultObject_1 = require("../utils/createResultObject");
5
5
  const jsonAction = (mapping) => {
6
6
  const { value, seek, populate } = mapping;
7
7
  const parsedValue = typeof value === "string" ? JSON.parse(value) : value;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.subgraphAction = void 0;
4
- const createResultObject_1 = require("src/dataMappings/utils/createResultObject");
4
+ const createResultObject_1 = require("../utils/createResultObject");
5
5
  const subgraphAction = async (mapping) => {
6
6
  const { endpoint, query, variables, seek, populate } = mapping;
7
7
  const response = await fetch(endpoint, {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeActions = exports.executeAction = void 0;
4
+ const errors_1 = require("../errors");
4
5
  const callAction_1 = require("./actions/callAction");
5
- const eventAction_js_1 = require("./actions/eventAction.js");
6
+ const eventAction_1 = require("./actions/eventAction");
6
7
  const fetchIpfsJsonAction_1 = require("./actions/fetchIpfsJsonAction");
7
8
  const jsonAction_1 = require("./actions/jsonAction");
8
9
  const subgraphAction_1 = require("./actions/subgraphAction");
@@ -19,14 +20,14 @@ const executeAction = async (mapping, context = {}) => {
19
20
  case "abi/call":
20
21
  return await (0, callAction_1.callAction)((0, actionTypeValidators_1.validateAbiCallMapping)(mapping));
21
22
  case "abi/event":
22
- return await (0, eventAction_js_1.eventAction)((0, actionTypeValidators_1.validateAbiEventMapping)(mapping));
23
+ return await (0, eventAction_1.eventAction)((0, actionTypeValidators_1.validateAbiEventMapping)(mapping));
23
24
  case "fetch/ipfs/json":
24
25
  return await (0, fetchIpfsJsonAction_1.fetchIpfsJsonAction)((0, actionTypeValidators_1.validateFetchIpfsJsonMapping)(mapping));
25
26
  case "reality":
26
27
  mapping = (0, actionTypeValidators_1.validateRealityMapping)(mapping);
27
28
  return await (0, retrieveRealityData_1.retrieveRealityData)(mapping.realityQuestionID, context.arbitrableAddress);
28
29
  default:
29
- throw new Error(`Unsupported action type: ${JSON.stringify(mapping)}`);
30
+ throw new errors_1.UnsupportedActionError(`Unsupported action type: ${JSON.stringify(mapping)}`);
30
31
  }
31
32
  };
32
33
  exports.executeAction = executeAction;
@@ -0,0 +1 @@
1
+ export * from "./executeActions";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./executeActions"), exports);
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.retrieveRealityData = void 0;
4
+ const errors_1 = require("../errors");
4
5
  const executeActions_1 = require("./executeActions");
5
6
  const retrieveRealityData = async (realityQuestionID, arbitrable) => {
6
7
  if (!arbitrable) {
7
- throw new Error("No arbitrable address provided");
8
+ throw new errors_1.InvalidContextError("No arbitrable address provided");
8
9
  }
9
10
  const questionMapping = {
10
11
  type: "abi/event",
@@ -56,8 +57,11 @@ const retrieveRealityData = async (realityQuestionID, arbitrable) => {
56
57
  };
57
58
  const templateData = await (0, executeActions_1.executeAction)(templateMapping);
58
59
  console.log("templateData", templateData);
59
- if (!templateData || !questionData) {
60
- throw new Error("Failed to retrieve template or question data");
60
+ if (!templateData) {
61
+ throw new errors_1.NotFoundError("Template Data", "Failed to retrieve template data");
62
+ }
63
+ if (!questionData) {
64
+ throw new errors_1.NotFoundError("Question Data", "Failed to retrieve question data");
61
65
  }
62
66
  const rc_question = require("@reality.eth/reality-eth-lib/formatters/question.js");
63
67
  const populatedTemplate = rc_question.populatedJSONForTemplate(templateData.questionText, questionData.realityQuestion);
@@ -1,7 +1,7 @@
1
- import { SubgraphMapping, AbiEventMapping, AbiCallMapping, JsonMapping, ActionMapping, FetchIpfsJsonMapping, RealityMapping } from "./actionTypes";
1
+ import { SubgraphMapping, AbiEventMapping, AbiCallMapping, JsonMapping, ActionMapping, FetchIpfsJsonMapping } from "./actionTypes";
2
2
  export declare const validateSubgraphMapping: (mapping: ActionMapping) => SubgraphMapping;
3
3
  export declare const validateAbiEventMapping: (mapping: ActionMapping) => AbiEventMapping;
4
4
  export declare const validateAbiCallMapping: (mapping: ActionMapping) => AbiCallMapping;
5
5
  export declare const validateJsonMapping: (mapping: ActionMapping) => JsonMapping;
6
6
  export declare const validateFetchIpfsJsonMapping: (mapping: ActionMapping) => FetchIpfsJsonMapping;
7
- export declare const validateRealityMapping: (mapping: ActionMapping) => RealityMapping;
7
+ export declare const validateRealityMapping: (mapping: ActionMapping) => import("./actionTypes").RealityMapping;
@@ -1,45 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateRealityMapping = exports.validateFetchIpfsJsonMapping = exports.validateJsonMapping = exports.validateAbiCallMapping = exports.validateAbiEventMapping = exports.validateSubgraphMapping = void 0;
4
+ const errors_1 = require("../../errors");
4
5
  const validateSubgraphMapping = (mapping) => {
5
- if (mapping.endpoint === undefined) {
6
- throw new Error("Invalid mapping for graphql action.");
7
- }
8
- return mapping;
6
+ return validateMapping(mapping, ["endpoint"]);
9
7
  };
10
8
  exports.validateSubgraphMapping = validateSubgraphMapping;
11
9
  const validateAbiEventMapping = (mapping) => {
12
- if (mapping.abi === undefined || mapping.eventFilter === undefined) {
13
- throw new Error("Invalid mapping for abi/event action.");
14
- }
15
- return mapping;
10
+ return validateMapping(mapping, ["abi", "eventFilter"]);
16
11
  };
17
12
  exports.validateAbiEventMapping = validateAbiEventMapping;
18
13
  const validateAbiCallMapping = (mapping) => {
19
- if (mapping.abi === undefined || mapping.functionName === undefined) {
20
- throw new Error("Invalid mapping for abi/call action.");
21
- }
22
- return mapping;
14
+ return validateMapping(mapping, ["abi", "functionName"]);
23
15
  };
24
16
  exports.validateAbiCallMapping = validateAbiCallMapping;
25
17
  const validateJsonMapping = (mapping) => {
26
- if (mapping.value === undefined) {
27
- throw new Error("Invalid mapping for json action.");
28
- }
29
- return mapping;
18
+ return validateMapping(mapping, ["value"]);
30
19
  };
31
20
  exports.validateJsonMapping = validateJsonMapping;
32
21
  const validateFetchIpfsJsonMapping = (mapping) => {
33
- if (mapping.ipfsUri === undefined) {
34
- throw new Error("Invalid mapping for fetch/ipfs/json action.");
35
- }
36
- return mapping;
22
+ return validateMapping(mapping, ["ipfsUri"]);
37
23
  };
38
24
  exports.validateFetchIpfsJsonMapping = validateFetchIpfsJsonMapping;
39
25
  const validateRealityMapping = (mapping) => {
40
26
  if (mapping.type !== "reality" || typeof mapping.realityQuestionID !== "string") {
41
- throw new Error("Invalid mapping for reality action.");
27
+ throw new errors_1.InvalidMappingError("Expected field 'realityQuestionID' to be a string.");
42
28
  }
43
29
  return mapping;
44
30
  };
45
31
  exports.validateRealityMapping = validateRealityMapping;
32
+ const validateMapping = (mapping, requiredFields) => {
33
+ for (const field of requiredFields) {
34
+ if (mapping[field] === undefined) {
35
+ throw new errors_1.InvalidMappingError(`${field.toString()} is required for ${mapping.type}`);
36
+ }
37
+ }
38
+ return mapping;
39
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./populateTemplate";
2
+ export * from "./retrieveVariables";
3
+ export * from "./disputeDetailsTypes";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./populateTemplate"), exports);
18
+ __exportStar(require("./retrieveVariables"), exports);
19
+ __exportStar(require("./disputeDetailsTypes"), exports);
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.populateTemplate = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const disputeDetailsSchema_1 = __importDefault(require("./disputeDetailsSchema"));
9
+ const errors_1 = require("../../errors");
9
10
  const populateTemplate = (mustacheTemplate, data) => {
10
11
  const render = mustache_1.default.render(mustacheTemplate, data);
11
12
  const dispute = JSON.parse(render);
12
13
  const validation = disputeDetailsSchema_1.default.safeParse(dispute);
13
14
  if (!validation.success) {
14
15
  console.error("Validation errors:", validation.error.errors, "\n\nDispute details:", `${JSON.stringify(dispute)}`);
15
- throw new Error("Invalid dispute details format");
16
+ throw new errors_1.InvalidFormatError("Invalid dispute details format");
16
17
  }
17
18
  console.log(dispute);
18
19
  return dispute;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.replacePlaceholdersWithValues = void 0;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const retrieveVariables_1 = __importDefault(require("./retrieveVariables"));
9
+ const errors_1 = require("../../errors");
9
10
  function replacePlaceholdersWithValues(mapping, context) {
10
11
  function replace(obj) {
11
12
  if (typeof obj === "string") {
@@ -29,7 +30,7 @@ const validateContext = (template, context) => {
29
30
  const variables = (0, retrieveVariables_1.default)(template);
30
31
  variables.forEach((variable) => {
31
32
  if (!context[variable])
32
- throw new Error(`Expected key : "${variable}" to be provided in context.`);
33
+ throw new errors_1.InvalidContextError(`Expected key "${variable}" to be provided in context.`);
33
34
  });
34
35
  return true;
35
36
  };
@@ -0,0 +1,26 @@
1
+ export declare class CustomError extends Error {
2
+ constructor(name: string, message: string);
3
+ }
4
+ export declare class InvalidContextError extends CustomError {
5
+ constructor(message: string);
6
+ }
7
+ export declare class InvalidMappingError extends CustomError {
8
+ constructor(message: string);
9
+ }
10
+ export declare class NotFoundError extends CustomError {
11
+ resourceName: string;
12
+ constructor(resourceName: string, message: string);
13
+ }
14
+ export declare class RequestError extends CustomError {
15
+ endpoint: string | undefined;
16
+ constructor(message: string, endpoint?: string);
17
+ }
18
+ export declare class UnsupportedActionError extends CustomError {
19
+ constructor(message: string);
20
+ }
21
+ export declare class InvalidFormatError extends CustomError {
22
+ constructor(message: string);
23
+ }
24
+ export declare class SdkNotConfiguredError extends CustomError {
25
+ constructor();
26
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SdkNotConfiguredError = exports.InvalidFormatError = exports.UnsupportedActionError = exports.RequestError = exports.NotFoundError = exports.InvalidMappingError = exports.InvalidContextError = exports.CustomError = void 0;
4
+ class CustomError extends Error {
5
+ constructor(name, message) {
6
+ super(message);
7
+ this.name = name;
8
+ if (Error.captureStackTrace) {
9
+ Error.captureStackTrace(this, this.constructor);
10
+ }
11
+ }
12
+ }
13
+ exports.CustomError = CustomError;
14
+ class InvalidContextError extends CustomError {
15
+ constructor(message) {
16
+ super("InvalidContextError", message);
17
+ }
18
+ }
19
+ exports.InvalidContextError = InvalidContextError;
20
+ class InvalidMappingError extends CustomError {
21
+ constructor(message) {
22
+ super("InvalidMappingError", message);
23
+ }
24
+ }
25
+ exports.InvalidMappingError = InvalidMappingError;
26
+ class NotFoundError extends CustomError {
27
+ resourceName;
28
+ constructor(resourceName, message) {
29
+ super("NotFoundError", message);
30
+ this.resourceName = resourceName;
31
+ }
32
+ }
33
+ exports.NotFoundError = NotFoundError;
34
+ class RequestError extends CustomError {
35
+ endpoint;
36
+ constructor(message, endpoint) {
37
+ super("RequestError", message);
38
+ this.endpoint = endpoint;
39
+ }
40
+ }
41
+ exports.RequestError = RequestError;
42
+ class UnsupportedActionError extends CustomError {
43
+ constructor(message) {
44
+ super("UnsupportedActionError", message);
45
+ }
46
+ }
47
+ exports.UnsupportedActionError = UnsupportedActionError;
48
+ class InvalidFormatError extends CustomError {
49
+ constructor(message) {
50
+ super("InvalidFormatError", message);
51
+ }
52
+ }
53
+ exports.InvalidFormatError = InvalidFormatError;
54
+ class SdkNotConfiguredError extends CustomError {
55
+ constructor() {
56
+ super("SdkNotConfiguredError", "SDK not configured. Please call `configureSDK` before using.");
57
+ }
58
+ }
59
+ exports.SdkNotConfiguredError = SdkNotConfiguredError;
@@ -1,4 +1,5 @@
1
1
  export * from "./sdk";
2
2
  export * from "./types";
3
- export * from "./utils/getDispute";
4
- export * from "./dataMappings/utils/disputeDetailsTypes";
3
+ export * from "./utils";
4
+ export * from "./dataMappings";
5
+ export * from "./dataMappings/utils";
package/lib/src/index.js CHANGED
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./sdk"), exports);
18
18
  __exportStar(require("./types"), exports);
19
- __exportStar(require("./utils/getDispute"), exports);
20
- __exportStar(require("./dataMappings/utils/disputeDetailsTypes"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ __exportStar(require("./dataMappings"), exports);
21
+ __exportStar(require("./dataMappings/utils"), exports);
@@ -8,5 +8,5 @@ type DisputeDetailsQueryResponse = {
8
8
  templateId: number;
9
9
  };
10
10
  };
11
- declare const fetchDisputeDetails: (endpoint: string, id: number) => Promise<DisputeDetailsQueryResponse>;
11
+ declare const fetchDisputeDetails: (endpoint: string, id: bigint) => Promise<DisputeDetailsQueryResponse>;
12
12
  export default fetchDisputeDetails;
@@ -1,24 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const graphql_request_1 = require("graphql-request");
4
+ const errors_1 = require("../errors");
4
5
  const fetchDisputeDetails = async (endpoint, id) => {
5
- const query = `
6
- query DisputeDetails {
7
- dispute(id: ${id}) {
6
+ const query = (0, graphql_request_1.gql) `
7
+ query DisputeDetails($id: ID!) {
8
+ dispute(id: $id) {
8
9
  arbitrated {
9
- id
10
+ id
10
11
  }
11
12
  arbitrableChainId
12
13
  externalDisputeId
13
14
  templateId
15
+ }
14
16
  }
15
- }
16
- `;
17
+ `;
18
+ const variables = { id: id.toString() };
17
19
  try {
18
- return await (0, graphql_request_1.request)(endpoint, query);
20
+ return await (0, graphql_request_1.request)(endpoint, query, variables);
19
21
  }
20
22
  catch (error) {
21
- throw new Error(`Error querying Dispute Details , endpoint : ${endpoint}, message : ${error?.message}`);
23
+ if (error instanceof Error) {
24
+ throw new errors_1.RequestError(`Error querying Dispute Details: ${error.message}`, endpoint);
25
+ }
26
+ throw new errors_1.RequestError("An unknown error occurred while querying Dispute Details", endpoint);
22
27
  }
23
28
  };
24
29
  exports.default = fetchDisputeDetails;
@@ -1,20 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const graphql_request_1 = require("graphql-request");
4
+ const errors_1 = require("../errors");
4
5
  const fetchDisputeTemplateFromId = async (endpoint, id) => {
5
- const query = `
6
- query DisputeTemplate {
7
- disputeTemplate(id: ${id}) {
8
- templateData
9
- templateDataMappings
10
- }
6
+ const query = (0, graphql_request_1.gql) `
7
+ query DisputeTemplate($id: ID!) {
8
+ disputeTemplate(id: $id) {
9
+ templateData
10
+ templateDataMappings
11
+ }
11
12
  }
12
- `;
13
+ `;
14
+ const variables = { id: id.toString() };
13
15
  try {
14
- return await (0, graphql_request_1.request)(endpoint, query);
16
+ return await (0, graphql_request_1.request)(endpoint, query, variables);
15
17
  }
16
18
  catch (error) {
17
- throw new Error(`Error querying Dispute Template Registry , endpoint : ${endpoint}, message : ${error?.message}`);
19
+ if (error instanceof Error) {
20
+ throw new errors_1.RequestError(`Error querying Dispute Template: ${error.message}`, endpoint);
21
+ }
22
+ throw new errors_1.RequestError("An unknown error occurred while querying Dispute Template", endpoint);
18
23
  }
19
24
  };
20
25
  exports.default = fetchDisputeTemplateFromId;
package/lib/src/sdk.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPublicClient = exports.configureSDK = void 0;
4
4
  const viem_1 = require("viem");
5
+ const errors_1 = require("./errors");
5
6
  let publicClient;
6
7
  const configureSDK = (config) => {
7
8
  if (config.client) {
@@ -11,7 +12,7 @@ const configureSDK = (config) => {
11
12
  exports.configureSDK = configureSDK;
12
13
  const getPublicClient = () => {
13
14
  if (!publicClient) {
14
- throw new Error("SDK not configured. Please call `configureSDK` before using.");
15
+ throw new errors_1.SdkNotConfiguredError();
15
16
  }
16
17
  return publicClient;
17
18
  };
@@ -3,13 +3,13 @@ export type SdkConfig = {
3
3
  client: PublicClientConfig;
4
4
  };
5
5
  type GetDisputeParametersOptions = {
6
- sdkConfig: SdkConfig;
7
- additionalContext: Record<string, any>;
6
+ sdkConfig?: SdkConfig;
7
+ additionalContext?: Record<string, any>;
8
8
  };
9
9
  export type GetDisputeParameters = {
10
- disputeId: number;
10
+ disputeId: bigint;
11
11
  coreSubgraph: string;
12
12
  dtrSubgraph: string;
13
- options: GetDisputeParametersOptions | undefined;
13
+ options?: GetDisputeParametersOptions;
14
14
  };
15
15
  export {};
@@ -1,3 +1,3 @@
1
- import { type GetDisputeParameters } from "src/types";
2
- import { DisputeDetails } from "dataMappings/utils/disputeDetailsTypes";
1
+ import { DisputeDetails } from "../dataMappings/utils";
2
+ import { GetDisputeParameters } from "../types";
3
3
  export declare const getDispute: (disputeParameters: GetDisputeParameters) => Promise<DisputeDetails | undefined>;
@@ -4,11 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getDispute = void 0;
7
- const sdk_1 = require("src/sdk");
8
- const fetchDisputeDetails_1 = __importDefault(require("src/requests/fetchDisputeDetails"));
9
- const fetchDisputeTemplateFromId_1 = __importDefault(require("src/requests/fetchDisputeTemplateFromId"));
10
- const executeActions_1 = require("dataMappings/executeActions");
11
- const populateTemplate_1 = require("dataMappings/utils/populateTemplate");
7
+ const dataMappings_1 = require("../dataMappings");
8
+ const utils_1 = require("../dataMappings/utils");
9
+ const errors_1 = require("../errors");
10
+ const fetchDisputeDetails_1 = __importDefault(require("../requests/fetchDisputeDetails"));
11
+ const fetchDisputeTemplateFromId_1 = __importDefault(require("../requests/fetchDisputeTemplateFromId"));
12
+ const sdk_1 = require("../sdk");
12
13
  const getDispute = async (disputeParameters) => {
13
14
  if (disputeParameters.options?.sdkConfig) {
14
15
  (0, sdk_1.configureSDK)(disputeParameters.options.sdkConfig);
@@ -16,11 +17,11 @@ const getDispute = async (disputeParameters) => {
16
17
  const { disputeId, dtrSubgraph, coreSubgraph, options } = disputeParameters;
17
18
  const disputeDetails = await (0, fetchDisputeDetails_1.default)(coreSubgraph, disputeId);
18
19
  if (!disputeDetails?.dispute) {
19
- throw new Error(`Dispute details not found for disputeId: ${disputeId}`);
20
+ throw new errors_1.NotFoundError("Dispute Details", `Dispute details not found for disputeId: ${disputeId}`);
20
21
  }
21
22
  const template = await (0, fetchDisputeTemplateFromId_1.default)(dtrSubgraph, disputeDetails.dispute.templateId);
22
23
  if (!template) {
23
- throw new Error(`Template not found for template ID: ${disputeDetails.dispute.templateId}`);
24
+ throw new errors_1.NotFoundError("Dispute Template", `Template not found for template ID: ${disputeDetails.dispute.templateId}`);
24
25
  }
25
26
  const { templateData, templateDataMappings } = template.disputeTemplate;
26
27
  const initialContext = {
@@ -32,13 +33,13 @@ const getDispute = async (disputeParameters) => {
32
33
  let data = {};
33
34
  if (templateDataMappings) {
34
35
  try {
35
- data = await (0, executeActions_1.executeActions)(JSON.parse(templateDataMappings), initialContext);
36
+ data = await (0, dataMappings_1.executeActions)(JSON.parse(templateDataMappings), initialContext);
36
37
  }
37
38
  catch (err) {
38
- throw new Error(err);
39
+ throw err;
39
40
  }
40
41
  }
41
- const populatedTemplate = (0, populateTemplate_1.populateTemplate)(templateData, data);
42
+ const populatedTemplate = (0, utils_1.populateTemplate)(templateData, data);
42
43
  return populatedTemplate;
43
44
  };
44
45
  exports.getDispute = getDispute;
@@ -0,0 +1 @@
1
+ export * from "./getDispute";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./getDispute"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kleros/kleros-sdk",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "SDK for Kleros version 2",
5
5
  "repository": "git@github.com:kleros/kleros-v2.git",
6
6
  "author": "Kleros",
@@ -12,10 +12,6 @@
12
12
  "lib/**/*",
13
13
  "!lib/**/test/*"
14
14
  ],
15
- "alias": {
16
- "src": "./src",
17
- "dataMappings": "./src/dataMappings"
18
- },
19
15
  "packageManager": "yarn@4.0.2+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186",
20
16
  "engines": {
21
17
  "node": ">=16.0.0"
@@ -46,7 +42,6 @@
46
42
  "vitest": "^1.1.3"
47
43
  },
48
44
  "dependencies": {
49
- "@kleros/kleros-v2-contracts": "^0.4.1",
50
45
  "@reality.eth/reality-eth-lib": "^3.2.30",
51
46
  "graphql-request": "^7.1.0",
52
47
  "mustache": "^4.2.0",
@@ -1,35 +0,0 @@
1
- export type DisputeDetails = {
2
- title: string;
3
- description: string;
4
- question: string;
5
- type: QuestionType;
6
- answers: Answer[];
7
- policyURI: string;
8
- attachment: Attachment;
9
- frontendUrl: string;
10
- arbitrableChainID: string;
11
- arbitrableAddress: `0x${string}`;
12
- arbitratorChainID: string;
13
- arbitratorAddress: `0x${string}`;
14
- category: string;
15
- lang: string;
16
- specification: string;
17
- version: string;
18
- };
19
- export declare enum QuestionType {
20
- Bool = "bool",
21
- Datetime = "datetime",
22
- MultipleSelect = "multiple-select",
23
- SingleSelect = "single-select",
24
- Uint = "uint"
25
- }
26
- export type Answer = {
27
- title: string;
28
- description: string;
29
- id: `0x${string}`;
30
- reserved: boolean;
31
- };
32
- export type Attachment = {
33
- label: string;
34
- uri: string;
35
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QuestionType = void 0;
4
- var QuestionType;
5
- (function (QuestionType) {
6
- QuestionType["Bool"] = "bool";
7
- QuestionType["Datetime"] = "datetime";
8
- QuestionType["MultipleSelect"] = "multiple-select";
9
- QuestionType["SingleSelect"] = "single-select";
10
- QuestionType["Uint"] = "uint";
11
- })(QuestionType || (exports.QuestionType = QuestionType = {}));