@kleros/kleros-sdk 2.1.12 → 2.3.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.
@@ -14,21 +14,27 @@ export declare enum QuestionType {
14
14
  }
15
15
  export declare const QuestionTypeSchema: z.ZodNativeEnum<typeof QuestionType>;
16
16
  export declare const AnswerSchema: z.ZodObject<{
17
- id: z.ZodOptional<z.ZodString>;
17
+ id: z.ZodString;
18
18
  title: z.ZodString;
19
19
  description: z.ZodString;
20
20
  reserved: z.ZodOptional<z.ZodBoolean>;
21
21
  }, "strip", z.ZodTypeAny, {
22
+ id: string;
22
23
  description: string;
23
24
  title: string;
24
- id?: string | undefined;
25
25
  reserved?: boolean | undefined;
26
26
  }, {
27
+ id: string;
27
28
  description: string;
28
29
  title: string;
29
- id?: string | undefined;
30
30
  reserved?: boolean | undefined;
31
31
  }>;
32
+ export declare const RefuseToArbitrateAnswer: {
33
+ id: string;
34
+ title: string;
35
+ description: string;
36
+ reserved: boolean;
37
+ };
32
38
  export declare const AttachmentSchema: z.ZodObject<{
33
39
  label: z.ZodString;
34
40
  uri: z.ZodString;
@@ -45,19 +51,19 @@ declare const DisputeDetailsSchema: z.ZodObject<{
45
51
  description: z.ZodString;
46
52
  question: z.ZodString;
47
53
  answers: z.ZodArray<z.ZodObject<{
48
- id: z.ZodOptional<z.ZodString>;
54
+ id: z.ZodString;
49
55
  title: z.ZodString;
50
56
  description: z.ZodString;
51
57
  reserved: z.ZodOptional<z.ZodBoolean>;
52
58
  }, "strip", z.ZodTypeAny, {
59
+ id: string;
53
60
  description: string;
54
61
  title: string;
55
- id?: string | undefined;
56
62
  reserved?: boolean | undefined;
57
63
  }, {
64
+ id: string;
58
65
  description: string;
59
66
  title: string;
60
- id?: string | undefined;
61
67
  reserved?: boolean | undefined;
62
68
  }>, "many">;
63
69
  policyURI: z.ZodEffects<z.ZodString, string, string>;
@@ -83,13 +89,13 @@ declare const DisputeDetailsSchema: z.ZodObject<{
83
89
  }, "strip", z.ZodTypeAny, {
84
90
  description: string;
85
91
  question: string;
92
+ title: string;
86
93
  answers: {
94
+ id: string;
87
95
  description: string;
88
96
  title: string;
89
- id?: string | undefined;
90
97
  reserved?: boolean | undefined;
91
98
  }[];
92
- title: string;
93
99
  policyURI: string;
94
100
  arbitratorChainID: string;
95
101
  arbitratorAddress: `0x${string}`;
@@ -107,13 +113,13 @@ declare const DisputeDetailsSchema: z.ZodObject<{
107
113
  }, {
108
114
  description: string;
109
115
  question: string;
116
+ title: string;
110
117
  answers: {
118
+ id: string;
111
119
  description: string;
112
120
  title: string;
113
- id?: string | undefined;
114
121
  reserved?: boolean | undefined;
115
122
  }[];
116
- title: string;
117
123
  policyURI: string;
118
124
  arbitratorChainID: string;
119
125
  arbitratorAddress: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
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;
3
+ exports.AliasSchema = exports.AttachmentSchema = exports.RefuseToArbitrateAnswer = exports.AnswerSchema = exports.QuestionTypeSchema = exports.QuestionType = exports.ethAddressOrEnsNameSchema = exports.ensNameSchema = exports.ethAddressSchema = exports.isMultiaddr = exports.isHexId = exports.isHexAddress = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const viem_1 = require("viem");
6
6
  const ens_1 = require("viem/ens");
@@ -31,14 +31,17 @@ var QuestionType;
31
31
  })(QuestionType || (exports.QuestionType = QuestionType = {}));
32
32
  exports.QuestionTypeSchema = zod_1.z.nativeEnum(QuestionType);
33
33
  exports.AnswerSchema = zod_1.z.object({
34
- id: zod_1.z
35
- .string()
36
- .regex(/^0x[0-9a-fA-F]+$/)
37
- .optional(),
34
+ id: zod_1.z.string().regex(/^0x[0-9a-fA-F]+$/),
38
35
  title: zod_1.z.string(),
39
36
  description: zod_1.z.string(),
40
37
  reserved: zod_1.z.boolean().optional(),
41
38
  });
39
+ exports.RefuseToArbitrateAnswer = {
40
+ id: "0x0",
41
+ title: "Refuse to Arbitrate / Invalid",
42
+ description: "Refuse to Arbitrate / Invalid",
43
+ reserved: true,
44
+ };
42
45
  exports.AttachmentSchema = zod_1.z.object({
43
46
  label: zod_1.z.string(),
44
47
  uri: zod_1.z.string(),
@@ -1,3 +1,4 @@
1
1
  export * from "./populateTemplate";
2
2
  export * from "./retrieveVariables";
3
3
  export * from "./disputeDetailsTypes";
4
+ export declare const isUndefined: (maybeObject: any) => maybeObject is undefined | null;
@@ -14,6 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.isUndefined = void 0;
17
18
  __exportStar(require("./populateTemplate"), exports);
18
19
  __exportStar(require("./retrieveVariables"), exports);
19
20
  __exportStar(require("./disputeDetailsTypes"), exports);
21
+ const isUndefined = (maybeObject) => typeof maybeObject === "undefined" || maybeObject === null;
22
+ exports.isUndefined = isUndefined;
@@ -1,11 +1,34 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.populateTemplate = void 0;
7
30
  const mustache_1 = __importDefault(require("mustache"));
8
- const disputeDetailsSchema_1 = __importDefault(require("./disputeDetailsSchema"));
31
+ const disputeDetailsSchema_1 = __importStar(require("./disputeDetailsSchema"));
9
32
  const populateTemplate = (mustacheTemplate, data) => {
10
33
  const render = mustache_1.default.render(mustacheTemplate, data);
11
34
  const dispute = JSON.parse(render);
@@ -13,6 +36,19 @@ const populateTemplate = (mustacheTemplate, data) => {
13
36
  if (!validation.success) {
14
37
  throw validation.error;
15
38
  }
16
- return dispute;
39
+ return findAndUpdateRTA(dispute);
17
40
  };
18
41
  exports.populateTemplate = populateTemplate;
42
+ const findAndUpdateRTA = (dispute) => {
43
+ const templateRTAIndex = dispute.answers.findIndex((answer) => answer.id && BigInt(answer.id) === BigInt(0));
44
+ if (templateRTAIndex !== -1) {
45
+ dispute.answers[templateRTAIndex] = {
46
+ ...disputeDetailsSchema_1.RefuseToArbitrateAnswer,
47
+ description: dispute.answers[templateRTAIndex].description ?? disputeDetailsSchema_1.RefuseToArbitrateAnswer.description,
48
+ };
49
+ }
50
+ else {
51
+ dispute.answers = [disputeDetailsSchema_1.RefuseToArbitrateAnswer, ...dispute.answers];
52
+ }
53
+ return dispute;
54
+ };
@@ -7,6 +7,7 @@ exports.replacePlaceholdersWithValues = replacePlaceholdersWithValues;
7
7
  const mustache_1 = __importDefault(require("mustache"));
8
8
  const retrieveVariables_1 = __importDefault(require("./retrieveVariables"));
9
9
  const errors_1 = require("../../errors");
10
+ const _1 = require(".");
10
11
  function replacePlaceholdersWithValues(mapping, context) {
11
12
  function replace(obj) {
12
13
  if (typeof obj === "string") {
@@ -28,7 +29,7 @@ function replacePlaceholdersWithValues(mapping, context) {
28
29
  const validateContext = (template, context) => {
29
30
  const variables = (0, retrieveVariables_1.default)(template);
30
31
  variables.forEach((variable) => {
31
- if (!context[variable])
32
+ if ((0, _1.isUndefined)(context[variable]))
32
33
  throw new errors_1.InvalidContextError(`Expected key "${variable}" to be provided in context.`);
33
34
  });
34
35
  return true;
@@ -40,15 +40,6 @@ const getDispute = async (disputeParameters) => {
40
40
  }
41
41
  }
42
42
  const populatedTemplate = (0, utils_1.populateTemplate)(templateData, data);
43
- populatedTemplate.answers = [
44
- {
45
- id: "0x0",
46
- title: "Refuse to Arbitrate / Invalid",
47
- description: "Refuse to Arbitrate / Invalid",
48
- reserved: true,
49
- },
50
- ...(populatedTemplate.answers?.filter((answer) => answer.id && Number(answer.id) !== 0) || []),
51
- ];
52
43
  return populatedTemplate;
53
44
  };
54
45
  exports.getDispute = getDispute;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kleros/kleros-sdk",
3
- "version": "2.1.12",
3
+ "version": "2.3.0",
4
4
  "description": "SDK for Kleros version 2",
5
5
  "repository": "git@github.com:kleros/kleros-v2.git",
6
6
  "homepage": "https://github.com/kleros/kleros-v2/tree/master/kleros-sdk#readme",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "type": "commonjs",
17
17
  "volta": {
18
- "node": "20.11.0"
18
+ "node": "20.18.2"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public",
@@ -43,7 +43,7 @@
43
43
  "vitest": "^1.6.0"
44
44
  },
45
45
  "dependencies": {
46
- "@reality.eth/reality-eth-lib": "^3.2.44",
46
+ "@reality.eth/reality-eth-lib": "^3.2.60",
47
47
  "@urql/core": "^5.0.8",
48
48
  "mustache": "^4.2.0",
49
49
  "zod": "^3.23.8"