@kleros/kleros-sdk 2.1.6 → 2.1.8
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/lib/src/consts.d.ts +1 -0
- package/lib/src/consts.js +4 -0
- package/lib/src/dataMappings/actions/callAction.d.ts +2 -0
- package/lib/src/dataMappings/actions/callAction.js +23 -0
- package/lib/src/dataMappings/actions/eventAction.d.ts +2 -0
- package/lib/src/dataMappings/actions/eventAction.js +26 -0
- package/lib/src/dataMappings/actions/fetchIpfsJsonAction.d.ts +2 -0
- package/lib/src/dataMappings/actions/fetchIpfsJsonAction.js +37 -0
- package/lib/src/dataMappings/actions/jsonAction.d.ts +2 -0
- package/lib/src/dataMappings/actions/jsonAction.js +10 -0
- package/lib/src/dataMappings/actions/subgraphAction.d.ts +2 -0
- package/lib/src/dataMappings/actions/subgraphAction.js +18 -0
- package/lib/src/dataMappings/executeActions.d.ts +5 -0
- package/lib/src/dataMappings/executeActions.js +46 -0
- package/lib/src/dataMappings/index.d.ts +1 -0
- package/lib/src/dataMappings/index.js +17 -0
- package/lib/src/dataMappings/retrieveRealityData.d.ts +15 -0
- package/lib/src/dataMappings/retrieveRealityData.js +104 -0
- package/lib/src/dataMappings/utils/actionTypeValidators.d.ts +7 -0
- package/lib/src/dataMappings/utils/actionTypeValidators.js +39 -0
- package/lib/src/dataMappings/utils/actionTypes.d.ts +40 -0
- package/lib/src/dataMappings/utils/actionTypes.js +2 -0
- package/lib/src/dataMappings/utils/createResultObject.d.ts +1 -0
- package/lib/src/dataMappings/utils/createResultObject.js +23 -0
- package/lib/src/dataMappings/utils/disputeDetailsSchema.d.ts +132 -0
- package/lib/src/dataMappings/utils/disputeDetailsSchema.js +67 -0
- package/lib/src/dataMappings/utils/disputeDetailsTypes.d.ts +7 -0
- package/lib/src/dataMappings/utils/disputeDetailsTypes.js +5 -0
- package/lib/src/dataMappings/utils/index.d.ts +3 -0
- package/lib/src/dataMappings/utils/index.js +19 -0
- package/lib/src/dataMappings/utils/populateTemplate.d.ts +2 -0
- package/lib/src/dataMappings/utils/populateTemplate.js +21 -0
- package/lib/src/dataMappings/utils/replacePlaceholdersWithValues.d.ts +2 -0
- package/lib/src/dataMappings/utils/replacePlaceholdersWithValues.js +36 -0
- package/lib/src/dataMappings/utils/retrieveVariables.d.ts +2 -0
- package/lib/src/dataMappings/utils/retrieveVariables.js +15 -0
- package/lib/src/errors/index.d.ts +26 -0
- package/lib/src/errors/index.js +59 -0
- package/lib/src/index.d.ts +5 -0
- package/lib/src/index.js +21 -0
- package/lib/src/requests/fetchDisputeDetails.d.ts +12 -0
- package/lib/src/requests/fetchDisputeDetails.js +45 -0
- package/lib/src/requests/fetchDisputeTemplateFromId.d.ts +8 -0
- package/lib/src/requests/fetchDisputeTemplateFromId.js +41 -0
- package/lib/src/requests/gqlClient.d.ts +3 -0
- package/lib/src/requests/gqlClient.js +16 -0
- package/lib/src/sdk.d.ts +4 -0
- package/lib/src/sdk.js +19 -0
- package/lib/src/types/index.d.ts +15 -0
- package/lib/src/types/index.js +2 -0
- package/lib/src/utils/getDispute.d.ts +3 -0
- package/lib/src/utils/getDispute.js +45 -0
- package/lib/src/utils/index.d.ts +1 -0
- package/lib/src/utils/index.js +17 -0
- package/package.json +6 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MAX_BYTE_SIZE = 1000000;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callAction = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const createResultObject_1 = require("../utils/createResultObject");
|
|
6
|
+
const sdk_1 = require("../../sdk");
|
|
7
|
+
const errors_1 = require("../../errors");
|
|
8
|
+
const callAction = async (mapping) => {
|
|
9
|
+
const publicClient = (0, sdk_1.getPublicClient)();
|
|
10
|
+
if (!publicClient) {
|
|
11
|
+
throw new errors_1.SdkNotConfiguredError();
|
|
12
|
+
}
|
|
13
|
+
const { abi: source, address, functionName, args, seek, populate } = mapping;
|
|
14
|
+
const parsedAbi = typeof source === "string" ? (0, viem_1.parseAbiItem)(source) : source;
|
|
15
|
+
const data = await publicClient.readContract({
|
|
16
|
+
address,
|
|
17
|
+
abi: [parsedAbi],
|
|
18
|
+
functionName,
|
|
19
|
+
args,
|
|
20
|
+
});
|
|
21
|
+
return (0, createResultObject_1.createResultObject)(data, seek, populate);
|
|
22
|
+
};
|
|
23
|
+
exports.callAction = callAction;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eventAction = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const createResultObject_1 = require("../utils/createResultObject");
|
|
6
|
+
const sdk_1 = require("../../sdk");
|
|
7
|
+
const errors_1 = require("../../errors");
|
|
8
|
+
const eventAction = async (mapping) => {
|
|
9
|
+
const publicClient = (0, sdk_1.getPublicClient)();
|
|
10
|
+
if (!publicClient) {
|
|
11
|
+
throw new errors_1.SdkNotConfiguredError();
|
|
12
|
+
}
|
|
13
|
+
const { abi: source, address, eventFilter, seek, populate } = mapping;
|
|
14
|
+
const parsedAbi = (0, viem_1.parseAbiItem)(source);
|
|
15
|
+
const filter = await publicClient.createEventFilter({
|
|
16
|
+
address,
|
|
17
|
+
event: parsedAbi,
|
|
18
|
+
args: eventFilter.args,
|
|
19
|
+
fromBlock: eventFilter.fromBlock,
|
|
20
|
+
toBlock: eventFilter.toBlock,
|
|
21
|
+
});
|
|
22
|
+
const contractEvent = await publicClient.getFilterLogs({ filter });
|
|
23
|
+
const eventData = contractEvent[0].args;
|
|
24
|
+
return (0, createResultObject_1.createResultObject)(eventData, seek, populate);
|
|
25
|
+
};
|
|
26
|
+
exports.eventAction = eventAction;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchIpfsJsonAction = void 0;
|
|
4
|
+
const consts_1 = require("../../consts");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const createResultObject_1 = require("../utils/createResultObject");
|
|
7
|
+
const fetchIpfsJsonAction = async (mapping) => {
|
|
8
|
+
const { ipfsUri, seek, populate } = mapping;
|
|
9
|
+
let httpUri;
|
|
10
|
+
if (ipfsUri.startsWith("/ipfs/")) {
|
|
11
|
+
httpUri = `https://ipfs.io${ipfsUri}`;
|
|
12
|
+
}
|
|
13
|
+
else if (ipfsUri.startsWith("ipfs://")) {
|
|
14
|
+
httpUri = ipfsUri.replace("ipfs://", "https://ipfs.io/ipfs/");
|
|
15
|
+
}
|
|
16
|
+
else if (!ipfsUri.startsWith("http")) {
|
|
17
|
+
httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
throw new errors_1.RequestError("Invalid IPFS URI format", httpUri);
|
|
21
|
+
}
|
|
22
|
+
const response = await fetch(httpUri, { method: "GET" });
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new errors_1.RequestError("Failed to fetch data from IPFS", httpUri);
|
|
25
|
+
}
|
|
26
|
+
const contentLength = response.headers.get("content-length");
|
|
27
|
+
if (contentLength && parseInt(contentLength) > consts_1.MAX_BYTE_SIZE) {
|
|
28
|
+
throw new errors_1.RequestError("Response size is too large", httpUri);
|
|
29
|
+
}
|
|
30
|
+
const contentType = response.headers.get("content-type");
|
|
31
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
32
|
+
throw new errors_1.RequestError("Fetched data is not JSON", httpUri);
|
|
33
|
+
}
|
|
34
|
+
const data = (await response.json());
|
|
35
|
+
return (0, createResultObject_1.createResultObject)(data, seek, populate);
|
|
36
|
+
};
|
|
37
|
+
exports.fetchIpfsJsonAction = fetchIpfsJsonAction;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsonAction = void 0;
|
|
4
|
+
const createResultObject_1 = require("../utils/createResultObject");
|
|
5
|
+
const jsonAction = (mapping) => {
|
|
6
|
+
const { value, seek, populate } = mapping;
|
|
7
|
+
const parsedValue = typeof value === "string" ? JSON.parse(value) : value;
|
|
8
|
+
return (0, createResultObject_1.createResultObject)(parsedValue, seek, populate);
|
|
9
|
+
};
|
|
10
|
+
exports.jsonAction = jsonAction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subgraphAction = void 0;
|
|
4
|
+
const createResultObject_1 = require("../utils/createResultObject");
|
|
5
|
+
const subgraphAction = async (mapping) => {
|
|
6
|
+
const { endpoint, query, variables, seek, populate } = mapping;
|
|
7
|
+
const response = await fetch(endpoint, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
Accept: "application/json",
|
|
12
|
+
},
|
|
13
|
+
body: JSON.stringify({ query, variables }),
|
|
14
|
+
});
|
|
15
|
+
const { data } = (await response.json());
|
|
16
|
+
return (0, createResultObject_1.createResultObject)(data, seek, populate);
|
|
17
|
+
};
|
|
18
|
+
exports.subgraphAction = subgraphAction;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ActionMapping } from "./utils/actionTypes";
|
|
2
|
+
type ActionResult = Record<string, unknown> | null | undefined;
|
|
3
|
+
export declare const executeAction: (mapping: ActionMapping, context?: Record<string, unknown>) => Promise<ActionResult>;
|
|
4
|
+
export declare const executeActions: (mappings: ActionMapping[], initialContext?: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeActions = exports.executeAction = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const callAction_1 = require("./actions/callAction");
|
|
6
|
+
const eventAction_1 = require("./actions/eventAction");
|
|
7
|
+
const fetchIpfsJsonAction_1 = require("./actions/fetchIpfsJsonAction");
|
|
8
|
+
const jsonAction_1 = require("./actions/jsonAction");
|
|
9
|
+
const subgraphAction_1 = require("./actions/subgraphAction");
|
|
10
|
+
const retrieveRealityData_1 = require("./retrieveRealityData");
|
|
11
|
+
const actionTypeValidators_1 = require("./utils/actionTypeValidators");
|
|
12
|
+
const replacePlaceholdersWithValues_1 = require("./utils/replacePlaceholdersWithValues");
|
|
13
|
+
const executeAction = async (mapping, context = {}) => {
|
|
14
|
+
mapping = (0, replacePlaceholdersWithValues_1.replacePlaceholdersWithValues)(mapping, context);
|
|
15
|
+
switch (mapping.type) {
|
|
16
|
+
case "graphql":
|
|
17
|
+
return await (0, subgraphAction_1.subgraphAction)((0, actionTypeValidators_1.validateSubgraphMapping)(mapping));
|
|
18
|
+
case "json":
|
|
19
|
+
return (0, jsonAction_1.jsonAction)((0, actionTypeValidators_1.validateJsonMapping)(mapping));
|
|
20
|
+
case "abi/call":
|
|
21
|
+
return await (0, callAction_1.callAction)((0, actionTypeValidators_1.validateAbiCallMapping)(mapping));
|
|
22
|
+
case "abi/event":
|
|
23
|
+
return await (0, eventAction_1.eventAction)((0, actionTypeValidators_1.validateAbiEventMapping)(mapping));
|
|
24
|
+
case "fetch/ipfs/json":
|
|
25
|
+
return await (0, fetchIpfsJsonAction_1.fetchIpfsJsonAction)((0, actionTypeValidators_1.validateFetchIpfsJsonMapping)(mapping));
|
|
26
|
+
case "reality":
|
|
27
|
+
mapping = (0, actionTypeValidators_1.validateRealityMapping)(mapping);
|
|
28
|
+
return await (0, retrieveRealityData_1.retrieveRealityData)(mapping.realityQuestionID, context.arbitrableAddress);
|
|
29
|
+
default:
|
|
30
|
+
throw new errors_1.UnsupportedActionError(`Unsupported action type: ${JSON.stringify(mapping)}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.executeAction = executeAction;
|
|
34
|
+
const executeActions = async (mappings, initialContext = {}) => {
|
|
35
|
+
const context = { ...initialContext };
|
|
36
|
+
for (const mapping of mappings) {
|
|
37
|
+
const actionResult = await (0, exports.executeAction)(mapping, context);
|
|
38
|
+
if (actionResult) {
|
|
39
|
+
Object.keys(actionResult).forEach((key) => {
|
|
40
|
+
context[key] = actionResult[key];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return context;
|
|
45
|
+
};
|
|
46
|
+
exports.executeActions = executeActions;
|
|
@@ -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);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type RealityAnswer = {
|
|
2
|
+
title: string;
|
|
3
|
+
description: string;
|
|
4
|
+
id: string;
|
|
5
|
+
reserved: boolean;
|
|
6
|
+
last?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const retrieveRealityData: (realityQuestionID: string, arbitrable?: `0x${string}`) => Promise<{
|
|
9
|
+
question: unknown;
|
|
10
|
+
type: any;
|
|
11
|
+
realityAddress: unknown;
|
|
12
|
+
questionId: unknown;
|
|
13
|
+
realityUser: unknown;
|
|
14
|
+
answers: RealityAnswer[];
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retrieveRealityData = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const executeActions_1 = require("./executeActions");
|
|
6
|
+
const retrieveRealityData = async (realityQuestionID, arbitrable) => {
|
|
7
|
+
if (!arbitrable) {
|
|
8
|
+
throw new errors_1.InvalidContextError("No arbitrable address provided");
|
|
9
|
+
}
|
|
10
|
+
const questionMapping = {
|
|
11
|
+
type: "abi/event",
|
|
12
|
+
abi: "event LogNewQuestion(bytes32 indexed question_id, address indexed user, uint256 template_id, string question, bytes32 indexed content_hash, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 created)",
|
|
13
|
+
address: arbitrable,
|
|
14
|
+
eventFilter: {
|
|
15
|
+
args: [realityQuestionID],
|
|
16
|
+
fromBlock: "earliest",
|
|
17
|
+
toBlock: "latest",
|
|
18
|
+
},
|
|
19
|
+
seek: [
|
|
20
|
+
"question_id",
|
|
21
|
+
"user",
|
|
22
|
+
"template_id",
|
|
23
|
+
"question",
|
|
24
|
+
"content_hash",
|
|
25
|
+
"arbitrator",
|
|
26
|
+
"timeout",
|
|
27
|
+
"opening_ts",
|
|
28
|
+
"nonce",
|
|
29
|
+
"created",
|
|
30
|
+
],
|
|
31
|
+
populate: [
|
|
32
|
+
"realityQuestionID",
|
|
33
|
+
"realityUser",
|
|
34
|
+
"realityTemplateID",
|
|
35
|
+
"realityQuestion",
|
|
36
|
+
"contentHash",
|
|
37
|
+
"arbitrator",
|
|
38
|
+
"timeout",
|
|
39
|
+
"openingTs",
|
|
40
|
+
"nonce",
|
|
41
|
+
"created",
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
const questionData = await (0, executeActions_1.executeAction)(questionMapping);
|
|
45
|
+
console.log("questionData", questionData);
|
|
46
|
+
const templateMapping = {
|
|
47
|
+
type: "abi/event",
|
|
48
|
+
abi: "event LogNewTemplate(uint256 indexed template_id, address indexed user, string question_text)",
|
|
49
|
+
address: arbitrable,
|
|
50
|
+
eventFilter: {
|
|
51
|
+
args: [0],
|
|
52
|
+
fromBlock: "earliest",
|
|
53
|
+
toBlock: "latest",
|
|
54
|
+
},
|
|
55
|
+
seek: ["template_id", "question_text"],
|
|
56
|
+
populate: ["templateID", "questionText"],
|
|
57
|
+
};
|
|
58
|
+
const templateData = await (0, executeActions_1.executeAction)(templateMapping);
|
|
59
|
+
console.log("templateData", templateData);
|
|
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");
|
|
65
|
+
}
|
|
66
|
+
const rc_question = require("@reality.eth/reality-eth-lib/formatters/question.js");
|
|
67
|
+
const populatedTemplate = rc_question.populatedJSONForTemplate(templateData.questionText, questionData.realityQuestion);
|
|
68
|
+
console.log("populatedTemplate", populatedTemplate);
|
|
69
|
+
let answers = [];
|
|
70
|
+
if (populatedTemplate.type === "bool") {
|
|
71
|
+
answers = [
|
|
72
|
+
{
|
|
73
|
+
title: "Yes",
|
|
74
|
+
description: "",
|
|
75
|
+
id: "0x01",
|
|
76
|
+
reserved: false,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
title: "No",
|
|
80
|
+
description: "",
|
|
81
|
+
id: "0x02",
|
|
82
|
+
reserved: false,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
answers.push({
|
|
87
|
+
id: "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
|
|
88
|
+
title: "Answered Too Soon",
|
|
89
|
+
description: "",
|
|
90
|
+
reserved: true,
|
|
91
|
+
});
|
|
92
|
+
for (let i = 0; i < answers.length; i++) {
|
|
93
|
+
answers[i].last = i === answers.length - 1;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
question: questionData.realityQuestion,
|
|
97
|
+
type: populatedTemplate.type,
|
|
98
|
+
realityAddress: questionData.arbitrator,
|
|
99
|
+
questionId: questionData.realityQuestionID,
|
|
100
|
+
realityUser: questionData.realityUser,
|
|
101
|
+
answers,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
exports.retrieveRealityData = retrieveRealityData;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SubgraphMapping, AbiEventMapping, AbiCallMapping, JsonMapping, ActionMapping, FetchIpfsJsonMapping } from "./actionTypes";
|
|
2
|
+
export declare const validateSubgraphMapping: (mapping: ActionMapping) => SubgraphMapping;
|
|
3
|
+
export declare const validateAbiEventMapping: (mapping: ActionMapping) => AbiEventMapping;
|
|
4
|
+
export declare const validateAbiCallMapping: (mapping: ActionMapping) => AbiCallMapping;
|
|
5
|
+
export declare const validateJsonMapping: (mapping: ActionMapping) => JsonMapping;
|
|
6
|
+
export declare const validateFetchIpfsJsonMapping: (mapping: ActionMapping) => FetchIpfsJsonMapping;
|
|
7
|
+
export declare const validateRealityMapping: (mapping: ActionMapping) => import("./actionTypes").RealityMapping;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRealityMapping = exports.validateFetchIpfsJsonMapping = exports.validateJsonMapping = exports.validateAbiCallMapping = exports.validateAbiEventMapping = exports.validateSubgraphMapping = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
|
+
const validateSubgraphMapping = (mapping) => {
|
|
6
|
+
return validateMapping(mapping, ["endpoint"]);
|
|
7
|
+
};
|
|
8
|
+
exports.validateSubgraphMapping = validateSubgraphMapping;
|
|
9
|
+
const validateAbiEventMapping = (mapping) => {
|
|
10
|
+
return validateMapping(mapping, ["abi", "eventFilter"]);
|
|
11
|
+
};
|
|
12
|
+
exports.validateAbiEventMapping = validateAbiEventMapping;
|
|
13
|
+
const validateAbiCallMapping = (mapping) => {
|
|
14
|
+
return validateMapping(mapping, ["abi", "functionName"]);
|
|
15
|
+
};
|
|
16
|
+
exports.validateAbiCallMapping = validateAbiCallMapping;
|
|
17
|
+
const validateJsonMapping = (mapping) => {
|
|
18
|
+
return validateMapping(mapping, ["value"]);
|
|
19
|
+
};
|
|
20
|
+
exports.validateJsonMapping = validateJsonMapping;
|
|
21
|
+
const validateFetchIpfsJsonMapping = (mapping) => {
|
|
22
|
+
return validateMapping(mapping, ["ipfsUri"]);
|
|
23
|
+
};
|
|
24
|
+
exports.validateFetchIpfsJsonMapping = validateFetchIpfsJsonMapping;
|
|
25
|
+
const validateRealityMapping = (mapping) => {
|
|
26
|
+
if (mapping.type !== "reality" || typeof mapping.realityQuestionID !== "string") {
|
|
27
|
+
throw new errors_1.InvalidMappingError("Expected field 'realityQuestionID' to be a string.");
|
|
28
|
+
}
|
|
29
|
+
return mapping;
|
|
30
|
+
};
|
|
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,40 @@
|
|
|
1
|
+
import { type Address, type BlockNumber, type BlockTag } from "viem";
|
|
2
|
+
type MappingType = "graphql" | "abi/call" | "abi/event" | "json" | "fetch/ipfs/json" | "reality";
|
|
3
|
+
type AbstractMapping<T extends MappingType> = {
|
|
4
|
+
type: T;
|
|
5
|
+
seek: string[];
|
|
6
|
+
populate: string[];
|
|
7
|
+
};
|
|
8
|
+
export type JsonMapping = AbstractMapping<"json"> & {
|
|
9
|
+
value: object;
|
|
10
|
+
};
|
|
11
|
+
export type SubgraphMapping = AbstractMapping<"graphql"> & {
|
|
12
|
+
endpoint: string;
|
|
13
|
+
query: string;
|
|
14
|
+
variables: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type AbiCallMapping = AbstractMapping<"abi/call"> & {
|
|
19
|
+
abi: string;
|
|
20
|
+
address: Address;
|
|
21
|
+
functionName: string;
|
|
22
|
+
args: any[];
|
|
23
|
+
};
|
|
24
|
+
export type AbiEventMapping = AbstractMapping<"abi/event"> & {
|
|
25
|
+
abi: string;
|
|
26
|
+
address: Address;
|
|
27
|
+
eventFilter: {
|
|
28
|
+
fromBlock: BlockNumber | BlockTag;
|
|
29
|
+
toBlock: BlockNumber | BlockTag;
|
|
30
|
+
args: any;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type FetchIpfsJsonMapping = AbstractMapping<"fetch/ipfs/json"> & {
|
|
34
|
+
ipfsUri: string;
|
|
35
|
+
};
|
|
36
|
+
export type RealityMapping = AbstractMapping<"reality"> & {
|
|
37
|
+
realityQuestionID: string;
|
|
38
|
+
};
|
|
39
|
+
export type ActionMapping = SubgraphMapping | AbiEventMapping | AbiCallMapping | JsonMapping | FetchIpfsJsonMapping | RealityMapping;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createResultObject: (sourceData: Record<string, any>, seek: string[], populate: string[]) => Record<string, any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createResultObject = void 0;
|
|
4
|
+
const createResultObject = (sourceData, seek, populate) => {
|
|
5
|
+
const result = {};
|
|
6
|
+
const getNestedValue = (obj, path) => {
|
|
7
|
+
return path.split(".").reduce((acc, part) => {
|
|
8
|
+
if (acc && part.includes("[")) {
|
|
9
|
+
const [key, index] = part.replace(/\]/g, "").split("[");
|
|
10
|
+
return acc[key]?.[index];
|
|
11
|
+
}
|
|
12
|
+
return acc ? acc[part] : undefined;
|
|
13
|
+
}, obj);
|
|
14
|
+
};
|
|
15
|
+
seek.forEach((key, idx) => {
|
|
16
|
+
const foundValue = getNestedValue(sourceData, key);
|
|
17
|
+
if (foundValue !== undefined) {
|
|
18
|
+
result[populate[idx]] = foundValue;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
exports.createResultObject = createResultObject;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const isHexAddress: (str: string) => boolean;
|
|
3
|
+
export declare const isHexId: (str: string) => boolean;
|
|
4
|
+
export declare const isMultiaddr: (str: string) => boolean;
|
|
5
|
+
export declare const ethAddressSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
6
|
+
export declare const ensNameSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
7
|
+
export declare const ethAddressOrEnsNameSchema: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>;
|
|
8
|
+
export declare enum QuestionType {
|
|
9
|
+
Bool = "bool",
|
|
10
|
+
Datetime = "datetime",
|
|
11
|
+
MultipleSelect = "multiple-select",
|
|
12
|
+
SingleSelect = "single-select",
|
|
13
|
+
Uint = "uint"
|
|
14
|
+
}
|
|
15
|
+
export declare const QuestionTypeSchema: z.ZodNativeEnum<typeof QuestionType>;
|
|
16
|
+
export declare const AnswerSchema: z.ZodObject<{
|
|
17
|
+
id: z.ZodOptional<z.ZodString>;
|
|
18
|
+
title: z.ZodString;
|
|
19
|
+
description: z.ZodString;
|
|
20
|
+
reserved: z.ZodOptional<z.ZodBoolean>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
description: string;
|
|
23
|
+
title: string;
|
|
24
|
+
id?: string | undefined;
|
|
25
|
+
reserved?: boolean | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
description: string;
|
|
28
|
+
title: string;
|
|
29
|
+
id?: string | undefined;
|
|
30
|
+
reserved?: boolean | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
export declare const AttachmentSchema: z.ZodObject<{
|
|
33
|
+
label: z.ZodString;
|
|
34
|
+
uri: z.ZodString;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
label: string;
|
|
37
|
+
uri: string;
|
|
38
|
+
}, {
|
|
39
|
+
label: string;
|
|
40
|
+
uri: string;
|
|
41
|
+
}>;
|
|
42
|
+
export declare const AliasSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
|
|
43
|
+
declare const DisputeDetailsSchema: z.ZodObject<{
|
|
44
|
+
title: z.ZodString;
|
|
45
|
+
description: z.ZodString;
|
|
46
|
+
question: z.ZodString;
|
|
47
|
+
answers: z.ZodArray<z.ZodObject<{
|
|
48
|
+
id: z.ZodOptional<z.ZodString>;
|
|
49
|
+
title: z.ZodString;
|
|
50
|
+
description: z.ZodString;
|
|
51
|
+
reserved: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
description: string;
|
|
54
|
+
title: string;
|
|
55
|
+
id?: string | undefined;
|
|
56
|
+
reserved?: boolean | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
description: string;
|
|
59
|
+
title: string;
|
|
60
|
+
id?: string | undefined;
|
|
61
|
+
reserved?: boolean | undefined;
|
|
62
|
+
}>, "many">;
|
|
63
|
+
policyURI: z.ZodEffects<z.ZodString, string, string>;
|
|
64
|
+
attachment: z.ZodOptional<z.ZodObject<{
|
|
65
|
+
label: z.ZodString;
|
|
66
|
+
uri: z.ZodString;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
label: string;
|
|
69
|
+
uri: string;
|
|
70
|
+
}, {
|
|
71
|
+
label: string;
|
|
72
|
+
uri: string;
|
|
73
|
+
}>>;
|
|
74
|
+
frontendUrl: z.ZodOptional<z.ZodString>;
|
|
75
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
76
|
+
arbitratorChainID: z.ZodString;
|
|
77
|
+
arbitratorAddress: z.ZodEffects<z.ZodString, string, string>;
|
|
78
|
+
category: z.ZodOptional<z.ZodString>;
|
|
79
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
80
|
+
specification: z.ZodOptional<z.ZodString>;
|
|
81
|
+
aliases: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>>;
|
|
82
|
+
version: z.ZodString;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
description: string;
|
|
85
|
+
question: string;
|
|
86
|
+
answers: {
|
|
87
|
+
description: string;
|
|
88
|
+
title: string;
|
|
89
|
+
id?: string | undefined;
|
|
90
|
+
reserved?: boolean | undefined;
|
|
91
|
+
}[];
|
|
92
|
+
title: string;
|
|
93
|
+
policyURI: string;
|
|
94
|
+
arbitratorChainID: string;
|
|
95
|
+
arbitratorAddress: string;
|
|
96
|
+
version: string;
|
|
97
|
+
attachment?: {
|
|
98
|
+
label: string;
|
|
99
|
+
uri: string;
|
|
100
|
+
} | undefined;
|
|
101
|
+
frontendUrl?: string | undefined;
|
|
102
|
+
metadata?: Record<string, unknown> | undefined;
|
|
103
|
+
category?: string | undefined;
|
|
104
|
+
lang?: string | undefined;
|
|
105
|
+
specification?: string | undefined;
|
|
106
|
+
aliases?: Record<string, string> | undefined;
|
|
107
|
+
}, {
|
|
108
|
+
description: string;
|
|
109
|
+
question: string;
|
|
110
|
+
answers: {
|
|
111
|
+
description: string;
|
|
112
|
+
title: string;
|
|
113
|
+
id?: string | undefined;
|
|
114
|
+
reserved?: boolean | undefined;
|
|
115
|
+
}[];
|
|
116
|
+
title: string;
|
|
117
|
+
policyURI: string;
|
|
118
|
+
arbitratorChainID: string;
|
|
119
|
+
arbitratorAddress: string;
|
|
120
|
+
version: string;
|
|
121
|
+
attachment?: {
|
|
122
|
+
label: string;
|
|
123
|
+
uri: string;
|
|
124
|
+
} | undefined;
|
|
125
|
+
frontendUrl?: string | undefined;
|
|
126
|
+
metadata?: Record<string, unknown> | undefined;
|
|
127
|
+
category?: string | undefined;
|
|
128
|
+
lang?: string | undefined;
|
|
129
|
+
specification?: string | undefined;
|
|
130
|
+
aliases?: Record<string, string> | undefined;
|
|
131
|
+
}>;
|
|
132
|
+
export default DisputeDetailsSchema;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AliasSchema = exports.AttachmentSchema = exports.AnswerSchema = exports.QuestionTypeSchema = exports.QuestionType = exports.ethAddressOrEnsNameSchema = exports.ensNameSchema = exports.ethAddressSchema = exports.isMultiaddr = exports.isHexId = exports.isHexAddress = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const ens_1 = require("viem/ens");
|
|
7
|
+
const isHexAddress = (str) => /^0x[a-fA-F0-9]{40}$/.test(str);
|
|
8
|
+
exports.isHexAddress = isHexAddress;
|
|
9
|
+
const isHexId = (str) => /^0x[a-fA-F0-9]{1,64}$/.test(str);
|
|
10
|
+
exports.isHexId = isHexId;
|
|
11
|
+
const isMultiaddr = (str) => /^\/(?:ip4|ip6|dns4|dns6|dnsaddr|tcp|udp|utp|tls|ws|wss|p2p-circuit|p2p-webrtc-star|p2p-webrtc-direct|p2p-websocket-star|onion|ipfs)(\/[^\s\/]+)+$|^ipfs:\/\/[a-zA-Z0-9]+\/[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)?$/.test(str);
|
|
12
|
+
exports.isMultiaddr = isMultiaddr;
|
|
13
|
+
exports.ethAddressSchema = zod_1.z.string().refine((value) => (0, viem_1.isAddress)(value, { strict: false }), {
|
|
14
|
+
message: "Provided address is invalid.",
|
|
15
|
+
});
|
|
16
|
+
exports.ensNameSchema = zod_1.z
|
|
17
|
+
.string()
|
|
18
|
+
.refine((value) => typeof (0, ens_1.normalize)(value) === "string" && value.endsWith(".eth"), {
|
|
19
|
+
message: "Provided ENS name is invalid.",
|
|
20
|
+
});
|
|
21
|
+
exports.ethAddressOrEnsNameSchema = zod_1.z.union([exports.ethAddressSchema, exports.ensNameSchema], {
|
|
22
|
+
errorMap: () => ({ message: "Provided address or ENS name is invalid." }),
|
|
23
|
+
});
|
|
24
|
+
var QuestionType;
|
|
25
|
+
(function (QuestionType) {
|
|
26
|
+
QuestionType["Bool"] = "bool";
|
|
27
|
+
QuestionType["Datetime"] = "datetime";
|
|
28
|
+
QuestionType["MultipleSelect"] = "multiple-select";
|
|
29
|
+
QuestionType["SingleSelect"] = "single-select";
|
|
30
|
+
QuestionType["Uint"] = "uint";
|
|
31
|
+
})(QuestionType || (exports.QuestionType = QuestionType = {}));
|
|
32
|
+
exports.QuestionTypeSchema = zod_1.z.nativeEnum(QuestionType);
|
|
33
|
+
exports.AnswerSchema = zod_1.z.object({
|
|
34
|
+
id: zod_1.z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(/^0x[0-9a-fA-F]+$/)
|
|
37
|
+
.optional(),
|
|
38
|
+
title: zod_1.z.string(),
|
|
39
|
+
description: zod_1.z.string(),
|
|
40
|
+
reserved: zod_1.z.boolean().optional(),
|
|
41
|
+
});
|
|
42
|
+
exports.AttachmentSchema = zod_1.z.object({
|
|
43
|
+
label: zod_1.z.string(),
|
|
44
|
+
uri: zod_1.z.string(),
|
|
45
|
+
});
|
|
46
|
+
exports.AliasSchema = zod_1.z.record(exports.ethAddressOrEnsNameSchema);
|
|
47
|
+
const MetadataSchema = zod_1.z.record(zod_1.z.unknown());
|
|
48
|
+
const DisputeDetailsSchema = zod_1.z.object({
|
|
49
|
+
title: zod_1.z.string(),
|
|
50
|
+
description: zod_1.z.string(),
|
|
51
|
+
question: zod_1.z.string(),
|
|
52
|
+
answers: zod_1.z.array(exports.AnswerSchema),
|
|
53
|
+
policyURI: zod_1.z.string().refine((value) => (0, exports.isMultiaddr)(value), {
|
|
54
|
+
message: "Provided policy URI is not a valid multiaddr.",
|
|
55
|
+
}),
|
|
56
|
+
attachment: exports.AttachmentSchema.optional(),
|
|
57
|
+
frontendUrl: zod_1.z.string().optional(),
|
|
58
|
+
metadata: MetadataSchema.optional(),
|
|
59
|
+
arbitratorChainID: zod_1.z.string(),
|
|
60
|
+
arbitratorAddress: exports.ethAddressSchema,
|
|
61
|
+
category: zod_1.z.string().optional(),
|
|
62
|
+
lang: zod_1.z.string().optional(),
|
|
63
|
+
specification: zod_1.z.string().optional(),
|
|
64
|
+
aliases: exports.AliasSchema.optional(),
|
|
65
|
+
version: zod_1.z.string(),
|
|
66
|
+
});
|
|
67
|
+
exports.default = DisputeDetailsSchema;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import DisputeDetailsSchema, { AliasSchema, AnswerSchema, AttachmentSchema } from "./disputeDetailsSchema";
|
|
3
|
+
export { QuestionType } from "./disputeDetailsSchema";
|
|
4
|
+
export type DisputeDetails = z.infer<typeof DisputeDetailsSchema>;
|
|
5
|
+
export type Answer = z.infer<typeof AnswerSchema>;
|
|
6
|
+
export type Alias = z.infer<typeof AliasSchema>;
|
|
7
|
+
export type Attachment = z.infer<typeof AttachmentSchema>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuestionType = void 0;
|
|
4
|
+
var disputeDetailsSchema_1 = require("./disputeDetailsSchema");
|
|
5
|
+
Object.defineProperty(exports, "QuestionType", { enumerable: true, get: function () { return disputeDetailsSchema_1.QuestionType; } });
|
|
@@ -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);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.populateTemplate = void 0;
|
|
7
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
+
const disputeDetailsSchema_1 = __importDefault(require("./disputeDetailsSchema"));
|
|
9
|
+
const errors_1 = require("../../errors");
|
|
10
|
+
const populateTemplate = (mustacheTemplate, data) => {
|
|
11
|
+
const render = mustache_1.default.render(mustacheTemplate, data);
|
|
12
|
+
const dispute = JSON.parse(render);
|
|
13
|
+
const validation = disputeDetailsSchema_1.default.safeParse(dispute);
|
|
14
|
+
if (!validation.success) {
|
|
15
|
+
console.error("Validation errors:", validation.error.errors, "\n\nDispute details:", `${JSON.stringify(dispute)}`);
|
|
16
|
+
throw new errors_1.InvalidFormatError("Invalid dispute details format");
|
|
17
|
+
}
|
|
18
|
+
console.log(dispute);
|
|
19
|
+
return dispute;
|
|
20
|
+
};
|
|
21
|
+
exports.populateTemplate = populateTemplate;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.replacePlaceholdersWithValues = void 0;
|
|
7
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
+
const retrieveVariables_1 = __importDefault(require("./retrieveVariables"));
|
|
9
|
+
const errors_1 = require("../../errors");
|
|
10
|
+
function replacePlaceholdersWithValues(mapping, context) {
|
|
11
|
+
function replace(obj) {
|
|
12
|
+
if (typeof obj === "string") {
|
|
13
|
+
validateContext(obj, context);
|
|
14
|
+
return mustache_1.default.render(obj, context);
|
|
15
|
+
}
|
|
16
|
+
else if (Array.isArray(obj)) {
|
|
17
|
+
return obj.map(replace);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof obj === "object" && obj !== null) {
|
|
20
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, replace(value)]));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return replace(mapping);
|
|
27
|
+
}
|
|
28
|
+
exports.replacePlaceholdersWithValues = replacePlaceholdersWithValues;
|
|
29
|
+
const validateContext = (template, context) => {
|
|
30
|
+
const variables = (0, retrieveVariables_1.default)(template);
|
|
31
|
+
variables.forEach((variable) => {
|
|
32
|
+
if (!context[variable])
|
|
33
|
+
throw new errors_1.InvalidContextError(`Expected key "${variable}" to be provided in context.`);
|
|
34
|
+
});
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mustache_1 = __importDefault(require("mustache"));
|
|
7
|
+
const retrieveVariables = (template) => mustache_1.default
|
|
8
|
+
.parse(template)
|
|
9
|
+
.filter(function (v) {
|
|
10
|
+
return v[0] === "name" || v[0] === "&";
|
|
11
|
+
})
|
|
12
|
+
.map(function (v) {
|
|
13
|
+
return v[1];
|
|
14
|
+
});
|
|
15
|
+
exports.default = retrieveVariables;
|
|
@@ -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;
|
package/lib/src/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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("./sdk"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
__exportStar(require("./dataMappings"), exports);
|
|
21
|
+
__exportStar(require("./dataMappings/utils"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type DisputeDetailsQueryResponse = {
|
|
2
|
+
dispute: {
|
|
3
|
+
arbitrated: {
|
|
4
|
+
id: string;
|
|
5
|
+
};
|
|
6
|
+
arbitrableChainId: number;
|
|
7
|
+
externalDisputeId: number;
|
|
8
|
+
templateId: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare const fetchDisputeDetails: (endpoint: string, id: bigint) => Promise<DisputeDetailsQueryResponse | undefined>;
|
|
12
|
+
export default fetchDisputeDetails;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
const core_1 = require("@urql/core");
|
|
8
|
+
const gqlClient_1 = __importDefault(require("./gqlClient"));
|
|
9
|
+
const query = (0, core_1.gql) `
|
|
10
|
+
query DisputeDetails($id: ID!) {
|
|
11
|
+
dispute(id: $id) {
|
|
12
|
+
arbitrated {
|
|
13
|
+
id
|
|
14
|
+
}
|
|
15
|
+
arbitrableChainId
|
|
16
|
+
externalDisputeId
|
|
17
|
+
templateId
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const fetchDisputeDetails = async (endpoint, id) => {
|
|
22
|
+
const variables = { id: id.toString() };
|
|
23
|
+
try {
|
|
24
|
+
const client = (0, gqlClient_1.default)(endpoint);
|
|
25
|
+
return client
|
|
26
|
+
.query(query, variables)
|
|
27
|
+
.toPromise()
|
|
28
|
+
.then((res) => {
|
|
29
|
+
if (res?.error) {
|
|
30
|
+
throw res.error;
|
|
31
|
+
}
|
|
32
|
+
return res?.data;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error instanceof core_1.CombinedError) {
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
else if (error instanceof Error) {
|
|
40
|
+
throw new errors_1.RequestError(`Error querying Dispute Details: ${error.message}`, endpoint);
|
|
41
|
+
}
|
|
42
|
+
throw new errors_1.RequestError("An unknown error occurred while querying Dispute Details", endpoint);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.default = fetchDisputeDetails;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type DisputeTemplateQueryResponse = {
|
|
2
|
+
disputeTemplate: {
|
|
3
|
+
templateData: string;
|
|
4
|
+
templateDataMappings: string;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
declare const fetchDisputeTemplateFromId: (endpoint: string, id: number) => Promise<DisputeTemplateQueryResponse | undefined>;
|
|
8
|
+
export default fetchDisputeTemplateFromId;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_1 = require("@urql/core");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const gqlClient_1 = __importDefault(require("./gqlClient"));
|
|
9
|
+
const query = (0, core_1.gql) `
|
|
10
|
+
query DisputeTemplate($id: ID!) {
|
|
11
|
+
disputeTemplate(id: $id) {
|
|
12
|
+
templateData
|
|
13
|
+
templateDataMappings
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
const fetchDisputeTemplateFromId = async (endpoint, id) => {
|
|
18
|
+
const variables = { id: id.toString() };
|
|
19
|
+
try {
|
|
20
|
+
const client = (0, gqlClient_1.default)(endpoint);
|
|
21
|
+
return client
|
|
22
|
+
.query(query, variables)
|
|
23
|
+
.toPromise()
|
|
24
|
+
.then((res) => {
|
|
25
|
+
if (res?.error) {
|
|
26
|
+
throw res.error;
|
|
27
|
+
}
|
|
28
|
+
return res?.data;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof core_1.CombinedError) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
else if (error instanceof Error) {
|
|
36
|
+
throw new errors_1.RequestError(`Error querying Dispute Template: ${error.message}`, endpoint);
|
|
37
|
+
}
|
|
38
|
+
throw new errors_1.RequestError("An unknown error occurred while querying Dispute Template", endpoint);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.default = fetchDisputeTemplateFromId;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@urql/core");
|
|
4
|
+
const clients = new Map();
|
|
5
|
+
const getClient = (endpoint) => {
|
|
6
|
+
let client = clients.get(endpoint);
|
|
7
|
+
if (!client) {
|
|
8
|
+
client = new core_1.Client({
|
|
9
|
+
url: endpoint,
|
|
10
|
+
exchanges: [core_1.cacheExchange, core_1.fetchExchange],
|
|
11
|
+
});
|
|
12
|
+
clients.set(endpoint, client);
|
|
13
|
+
}
|
|
14
|
+
return client;
|
|
15
|
+
};
|
|
16
|
+
exports.default = getClient;
|
package/lib/src/sdk.d.ts
ADDED
package/lib/src/sdk.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPublicClient = exports.configureSDK = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
let publicClient;
|
|
7
|
+
const configureSDK = (config) => {
|
|
8
|
+
if (config.client) {
|
|
9
|
+
publicClient = (0, viem_1.createPublicClient)(config.client);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.configureSDK = configureSDK;
|
|
13
|
+
const getPublicClient = () => {
|
|
14
|
+
if (!publicClient) {
|
|
15
|
+
throw new errors_1.SdkNotConfiguredError();
|
|
16
|
+
}
|
|
17
|
+
return publicClient;
|
|
18
|
+
};
|
|
19
|
+
exports.getPublicClient = getPublicClient;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PublicClientConfig } from "viem";
|
|
2
|
+
export type SdkConfig = {
|
|
3
|
+
client: PublicClientConfig;
|
|
4
|
+
};
|
|
5
|
+
type GetDisputeParametersOptions = {
|
|
6
|
+
sdkConfig?: SdkConfig;
|
|
7
|
+
additionalContext?: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export type GetDisputeParameters = {
|
|
10
|
+
disputeId: bigint;
|
|
11
|
+
coreSubgraph: string;
|
|
12
|
+
dtrSubgraph: string;
|
|
13
|
+
options?: GetDisputeParametersOptions;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDispute = void 0;
|
|
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");
|
|
13
|
+
const getDispute = async (disputeParameters) => {
|
|
14
|
+
if (disputeParameters.options?.sdkConfig) {
|
|
15
|
+
(0, sdk_1.configureSDK)(disputeParameters.options.sdkConfig);
|
|
16
|
+
}
|
|
17
|
+
const { disputeId, dtrSubgraph, coreSubgraph, options } = disputeParameters;
|
|
18
|
+
const disputeDetails = await (0, fetchDisputeDetails_1.default)(coreSubgraph, disputeId);
|
|
19
|
+
if (!disputeDetails?.dispute) {
|
|
20
|
+
throw new errors_1.NotFoundError("Dispute Details", `Dispute details not found for disputeId: ${disputeId}`);
|
|
21
|
+
}
|
|
22
|
+
const template = await (0, fetchDisputeTemplateFromId_1.default)(dtrSubgraph, disputeDetails.dispute.templateId);
|
|
23
|
+
if (!template) {
|
|
24
|
+
throw new errors_1.NotFoundError("Dispute Template", `Template not found for template ID: ${disputeDetails.dispute.templateId}`);
|
|
25
|
+
}
|
|
26
|
+
const { templateData, templateDataMappings } = template.disputeTemplate;
|
|
27
|
+
const initialContext = {
|
|
28
|
+
arbitrableAddress: disputeDetails.dispute.arbitrated.id,
|
|
29
|
+
arbitrableChainID: disputeDetails.dispute.arbitrableChainId,
|
|
30
|
+
externalDisputeID: disputeDetails.dispute.externalDisputeId,
|
|
31
|
+
...options?.additionalContext,
|
|
32
|
+
};
|
|
33
|
+
let data = {};
|
|
34
|
+
if (templateDataMappings) {
|
|
35
|
+
try {
|
|
36
|
+
data = await (0, dataMappings_1.executeActions)(JSON.parse(templateDataMappings), initialContext);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const populatedTemplate = (0, utils_1.populateTemplate)(templateData, data);
|
|
43
|
+
return populatedTemplate;
|
|
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
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "SDK for Kleros version 2",
|
|
5
5
|
"repository": "git@github.com:kleros/kleros-v2.git",
|
|
6
6
|
"author": "Kleros",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"test": "vitest",
|
|
31
31
|
"test:ui": "vitest --ui",
|
|
32
32
|
"test:run": "vitest run",
|
|
33
|
-
"
|
|
33
|
+
"release:patch": "scripts/publish.sh patch",
|
|
34
|
+
"release:minor": "scripts/publish.sh minor",
|
|
35
|
+
"release:major": "scripts/publish.sh major"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@types/mustache": "^4.2.5",
|
|
@@ -42,10 +44,10 @@
|
|
|
42
44
|
"vitest": "^1.1.3"
|
|
43
45
|
},
|
|
44
46
|
"dependencies": {
|
|
45
|
-
"@reality.eth/reality-eth-lib": "^3.2.
|
|
47
|
+
"@reality.eth/reality-eth-lib": "^3.2.43",
|
|
46
48
|
"@urql/core": "^5.0.8",
|
|
47
49
|
"mustache": "^4.2.0",
|
|
48
|
-
"viem": "^2.21.
|
|
50
|
+
"viem": "^2.21.35",
|
|
49
51
|
"zod": "^3.22.4"
|
|
50
52
|
}
|
|
51
53
|
}
|