Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dynamic context validation in sdk #1703

Merged
merged 40 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dbb89d2
feat(sdk): dynamic-context-validation
Harman-singh-waraich Oct 8, 2024
85f3668
chore(web): add-graph-api-key-env
Harman-singh-waraich Oct 8, 2024
cdbbcf2
feat(subgraph): fetch-dispute-request-event-data-within-subgraph
Harman-singh-waraich Oct 11, 2024
c59e102
feat(kleros-sdk): get-dispute-function
Harman-singh-waraich Oct 14, 2024
220ea2f
chore(web): update-dispute-population-flow
Harman-singh-waraich Oct 14, 2024
6974fdb
chore(web): configure-sdk-with-web3-context
Harman-singh-waraich Oct 14, 2024
88963e7
chore(kleros-sdk): make-configuring-sdk-explicit
Harman-singh-waraich Oct 14, 2024
3ad42d5
refactor(kleros-sdk): implement-rabbit-ai-feedback
Harman-singh-waraich Oct 14, 2024
d2c8f9c
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
Harman-singh-waraich Oct 15, 2024
25063c7
chore: fixed the SDK tests, minor tweaks
jaybuidl Oct 15, 2024
3abfbc5
fix(kleros-sdk): public-client-null-check
Harman-singh-waraich Oct 15, 2024
9140518
chore(subgraph): redeploy-subgraphs
Harman-singh-waraich Oct 15, 2024
e8cd12d
fix(sdk): types and unit tests
jaybuidl Oct 15, 2024
d3e4b59
chore(sdk): release configuration for NPM, tsconfig tweaks
jaybuidl Oct 16, 2024
1a11c84
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
98c2907
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
b851f2a
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
57711ba
docs(sdk): readme
jaybuidl Oct 16, 2024
cbdd6d1
chore: clean up
jaybuidl Oct 16, 2024
77b57e4
chore(kleros-sdk): define-entry-points-for-files
Harman-singh-waraich Oct 16, 2024
71f851b
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 16, 2024
ecc9edf
refactor(kleros-sdk): remove-path-aliasing
Harman-singh-waraich Oct 18, 2024
e698548
refactor(kleros-sdk): update-get-dispute-function-parameter-type
Harman-singh-waraich Oct 21, 2024
93e59a1
fix(web): typing
Harman-singh-waraich Oct 21, 2024
18ae12f
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
Harman-singh-waraich Oct 21, 2024
0a8422f
chore: update-yarn-lock
Harman-singh-waraich Oct 21, 2024
04c80db
chore(kleros-sdk): update-get-dispute-id-spec
Harman-singh-waraich Oct 21, 2024
9b4e9d2
feat(kleros-sdk): better-error-handling-and-optimisations
Harman-singh-waraich Oct 22, 2024
7d5ed21
refactor(kleros-sdk): sonar-cloud-fixes
Harman-singh-waraich Oct 22, 2024
542a8d9
refactor(kleros-sdk): remoev-unused-import
Harman-singh-waraich Oct 22, 2024
3d42edc
refactor(kleros-sdk): address-coderabbit-feedback
Harman-singh-waraich Oct 22, 2024
a387e77
refactor(kleros-sdk): refactor-error-classes
Harman-singh-waraich Oct 22, 2024
56853b9
fix: test mocks
jaybuidl Oct 23, 2024
52b31a3
fix(kleros-sdk): replace-graphql-request-library-with-native-fetch
Harman-singh-waraich Oct 23, 2024
cab784b
chore(kleros-sdk): use-urql-for-gql-queries
Harman-singh-waraich Oct 24, 2024
0562712
feat(kleros-sdk): gql-client-caching
Harman-singh-waraich Oct 24, 2024
078b233
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 25, 2024
128e1e5
chore(sdk): publish script
jaybuidl Oct 25, 2024
d2cb260
chore(sdk): release @kleros/[email protected]
jaybuidl Oct 25, 2024
7b2ccd3
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
jaybuidl Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@kleros/vea-contracts": "^0.4.0"
"@kleros/vea-contracts": "^0.4.0",
"viem": "^2.21.26"
}
}
2 changes: 1 addition & 1 deletion contracts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@kleros/kleros-v2-tsconfig/base.json",
"extends": "@kleros/kleros-v2-tsconfig/base18.json",
"include": [
"./src",
"./scripts",
Expand Down
24 changes: 24 additions & 0 deletions kleros-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules

# vite
development
build
dist
lib

# misc
.eslintcache
.DS_Store
.env
.env.test
.env.testnet
.env.devnet
.env.local
.env.development.local
.env.test.local
.env.production.local

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
2 changes: 1 addition & 1 deletion kleros-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @kleros/kleros-v2-sdk
# @kleros/kleros-sdk

_Archon's successor_

Expand Down
30 changes: 21 additions & 9 deletions kleros-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "@kleros/kleros-sdk",
"version": "0.1.0",
"version": "2.1.7",
"description": "SDK for Kleros version 2",
"main": "index.ts",
"repository": "[email protected]:kleros/kleros-v2.git",
"author": "Kleros",
"license": "MIT",
"alias": {
"src": "./src",
"dataMappings": "./src/dataMappings"
},
"main": "./lib/src/index.js",
"types": "./lib/src/index.d.ts",
"module": "./lib/src/index.js",
"files": [
"lib/**/*",
"!lib/**/test/*"
],
"packageManager": "[email protected]+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186",
"engines": {
"node": ">=16.0.0"
Expand All @@ -18,24 +20,34 @@
"volta": {
"node": "20.11.0"
},
"publishConfig": {
"access": "public",
"tag": "latest"
},
"scripts": {
"build": "your-build-script",
"clean": "rimraf lib",
"build": "yarn clean && tsc",
"test": "vitest",
"test:ui": "vitest --ui",
"test:run": "vitest run"
"test:run": "vitest run",
"release:patch": "scripts/publish.sh patch",
"release:minor": "scripts/publish.sh minor",
"release:major": "scripts/publish.sh major"
},
"devDependencies": {
"@types/mustache": "^4.2.5",
"@vitest/ui": "^1.1.3",
"mocha": "^10.2.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vitest": "^1.1.3"
},
"dependencies": {
"@kleros/kleros-v2-contracts": "workspace:^",
"@reality.eth/reality-eth-lib": "^3.2.30",
"@urql/core": "^5.0.8",
"mustache": "^4.2.0",
"viem": "^2.21.26",
"zod": "^3.22.4"
}
}
42 changes: 42 additions & 0 deletions kleros-sdk/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider enhancing script directory handling.

The script directory resolution is good but could be more robust.

-SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+readonly SCRIPT_DIR="$( cd "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" >/dev/null 2>&1 && pwd )"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
#!/bin/bash
readonly SCRIPT_DIR="$( cd "$( dirname "$(readlink -f "${BASH_SOURCE[0]}")" )" >/dev/null 2>&1 && pwd )"


#--------------------------------------
# Error handling
#--------------------------------------

set -Ee
function _catch {
# Don't propagate to outer shell
exit 0
}
function _finally {
# TODO: rollback version bump
rm -rf $SCRIPT_DIR/../dist
}
trap _catch ERR
trap _finally EXIT

#--------------------------------------

# Check if any tracked files are currently changed, ignoring untracked files
if [ -n "$(git status --porcelain -uno)" ]; then
echo "Error: There are uncommitted changes in tracked files. Please commit or stash them before publishing."
exit 1
fi

yarn version $1

version=$(cat package.json | jq -r .version)
echo "Publishing version $version"

git add package.json
git commit -m "chore(sdk): release @kleros/kleros-sdk@$version"
git tag "@kleros/kleros-sdk@$version" -m "@kleros/kleros-sdk@$version"
git push
git push --tags

yarn clean
yarn build
yarn npm publish
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add verification steps for build and publish process.

The build and publish steps need additional checks to ensure reliability.

+# Verify npm authentication
+if ! yarn npm whoami >/dev/null 2>&1; then
+    echo "Error: Not authenticated to npm. Please run 'yarn npm login' first."
+    exit 1
+fi
+
 yarn clean
-yarn build
+yarn build || { echo "Build failed"; exit 1; }
+
+# Verify dist directory exists and contains files
+if [ ! -d "dist" ] || [ -z "$(ls -A dist)" ]; then
+    echo "Error: dist directory is missing or empty"
+    exit 1
+fi
+
 yarn npm publish
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
yarn clean
yarn build
yarn npm publish
# Verify npm authentication
if ! yarn npm whoami >/dev/null 2>&1; then
echo "Error: Not authenticated to npm. Please run 'yarn npm login' first."
exit 1
fi
yarn clean
yarn build || { echo "Build failed"; exit 1; }
# Verify dist directory exists and contains files
if [ ! -d "dist" ] || [ -z "$(ls -A dist)" ]; then
echo "Error: dist directory is missing or empty"
exit 1
fi
yarn npm publish

18 changes: 11 additions & 7 deletions kleros-sdk/src/dataMappings/actions/callAction.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { parseAbiItem } from "viem";
import { AbiCallMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { configureSDK, getPublicClient } from "src/sdk";
import { AbiCallMapping } from "../utils/actionTypes";
import { createResultObject } from "../utils/createResultObject";
import { getPublicClient } from "../../sdk";
import { SdkNotConfiguredError } from "../../errors";

export const callAction = async (mapping: AbiCallMapping, alchemyApiKey: string) => {
configureSDK({ apiKey: alchemyApiKey });
export const callAction = async (mapping: AbiCallMapping) => {
const publicClient = getPublicClient();

const { abi: source, address, args, seek, populate } = mapping;
if (!publicClient) {
throw new SdkNotConfiguredError();
}

const { abi: source, address, functionName, args, seek, populate } = mapping;
const parsedAbi = typeof source === "string" ? parseAbiItem(source) : source;

const data = await publicClient.readContract({
address,
abi: [parsedAbi],
functionName: "TODO: FIX ME",
functionName,
args,
});

Expand Down
21 changes: 12 additions & 9 deletions kleros-sdk/src/dataMappings/actions/eventAction.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { parseAbiItem } from "viem";
import { type AbiEvent } from "abitype";
import { AbiEventMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { configureSDK, getPublicClient } from "src/sdk";
import { parseAbiItem, type AbiEvent } from "viem";
import { AbiEventMapping } from "../utils/actionTypes";
import { createResultObject } from "../utils/createResultObject";
import { getPublicClient } from "../../sdk";
import { SdkNotConfiguredError } from "../../errors";

export const eventAction = async (mapping: AbiEventMapping, alchemyApiKey: string) => {
configureSDK({ apiKey: alchemyApiKey });
export const eventAction = async (mapping: AbiEventMapping) => {
const publicClient = getPublicClient();

if (!publicClient) {
throw new SdkNotConfiguredError();
}

const { abi: source, address, eventFilter, seek, populate } = mapping;
const parsedAbi = parseAbiItem(source) as AbiEvent;

const filter = await publicClient.createEventFilter({
address,
event: parsedAbi,
args: eventFilter.args,
fromBlock: eventFilter.fromBlock ? BigInt(eventFilter.fromBlock.toString()) : undefined,
toBlock: eventFilter.toBlock ? BigInt(eventFilter.toBlock.toString()) : undefined,
fromBlock: eventFilter.fromBlock,
toBlock: eventFilter.toBlock,
});

const contractEvent = await publicClient.getFilterLogs({ filter });
Expand Down
17 changes: 9 additions & 8 deletions kleros-sdk/src/dataMappings/actions/fetchIpfsJsonAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FetchIpfsJsonMapping } from "src/dataMappings/utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { MAX_BYTE_SIZE } from "src/consts";
import { MAX_BYTE_SIZE } from "../../consts";
import { RequestError } from "../../errors";
import { FetchIpfsJsonMapping } from "../utils/actionTypes";
import { createResultObject } from "../utils/createResultObject";

export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
const { ipfsUri, seek, populate } = mapping;
Expand All @@ -13,26 +14,26 @@ export const fetchIpfsJsonAction = async (mapping: FetchIpfsJsonMapping) => {
} else if (!ipfsUri.startsWith("http")) {
httpUri = `https://ipfs.io/ipfs/${ipfsUri}`;
} else {
throw new Error("Invalid IPFS URI format");
throw new RequestError("Invalid IPFS URI format", httpUri);
}

const response = await fetch(httpUri, { method: "GET" });

if (!response.ok) {
throw new Error("Failed to fetch data from IPFS");
throw new RequestError("Failed to fetch data from IPFS", httpUri);
}

const contentLength = response.headers.get("content-length");
if (contentLength && parseInt(contentLength) > MAX_BYTE_SIZE) {
throw new Error("Response size is too large");
throw new RequestError("Response size is too large", httpUri);
}

const contentType = response.headers.get("content-type");
if (!contentType || !contentType.includes("application/json")) {
throw new Error("Fetched data is not JSON");
throw new RequestError("Fetched data is not JSON", httpUri);
}

const data = await response.json();
const data = (await response.json()) as any;

return createResultObject(data, seek, populate);
};
2 changes: 1 addition & 1 deletion kleros-sdk/src/dataMappings/actions/jsonAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonMapping } from "../utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { createResultObject } from "../utils/createResultObject";

export const jsonAction = (mapping: JsonMapping) => {
const { value, seek, populate } = mapping;
Expand Down
4 changes: 2 additions & 2 deletions kleros-sdk/src/dataMappings/actions/subgraphAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SubgraphMapping } from "../utils/actionTypes";
import { createResultObject } from "src/dataMappings/utils/createResultObject";
import { createResultObject } from "../utils/createResultObject";

export const subgraphAction = async (mapping: SubgraphMapping) => {
const { endpoint, query, variables, seek, populate } = mapping;
Expand All @@ -13,7 +13,7 @@ export const subgraphAction = async (mapping: SubgraphMapping) => {
body: JSON.stringify({ query, variables }),
});

const { data } = await response.json();
const { data } = (await response.json()) as any;

return createResultObject(data, seek, populate);
};
75 changes: 0 additions & 75 deletions kleros-sdk/src/dataMappings/dataMapping.json

This file was deleted.

Loading
Loading