Skip to content

Commit 2ccc5cd

Browse files
committed
fix(kleros-sdk): fix-key-check
1 parent ce41157 commit 2ccc5cd

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
export * from "./populateTemplate";
22
export * from "./retrieveVariables";
33
export * from "./disputeDetailsTypes";
4+
5+
export const isUndefined = (maybeObject: any): maybeObject is undefined | null =>
6+
typeof maybeObject === "undefined" || maybeObject === null;

kleros-sdk/src/dataMappings/utils/replacePlaceholdersWithValues.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import mustache from "mustache";
22
import retrieveVariables from "./retrieveVariables";
33
import { ActionMapping } from "./actionTypes";
44
import { InvalidContextError } from "../../errors";
5+
import { isUndefined } from ".";
56

67
export function replacePlaceholdersWithValues(
78
mapping: ActionMapping,
@@ -35,7 +36,8 @@ const validateContext = (template: string, context: Record<string, unknown>) =>
3536
const variables = retrieveVariables(template);
3637

3738
variables.forEach((variable) => {
38-
if (!context[variable]) throw new InvalidContextError(`Expected key "${variable}" to be provided in context.`);
39+
if (isUndefined(context[variable]))
40+
throw new InvalidContextError(`Expected key "${variable}" to be provided in context.`);
3941
});
4042
return true;
4143
};

0 commit comments

Comments
 (0)