-
Notifications
You must be signed in to change notification settings - Fork 49
Feat/dynamic context validation in sdk #1703
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
dbb89d2
feat(sdk): dynamic-context-validation
tractorss 85f3668
chore(web): add-graph-api-key-env
tractorss cdbbcf2
feat(subgraph): fetch-dispute-request-event-data-within-subgraph
tractorss c59e102
feat(kleros-sdk): get-dispute-function
tractorss 220ea2f
chore(web): update-dispute-population-flow
tractorss 6974fdb
chore(web): configure-sdk-with-web3-context
tractorss 88963e7
chore(kleros-sdk): make-configuring-sdk-explicit
tractorss 3ad42d5
refactor(kleros-sdk): implement-rabbit-ai-feedback
tractorss d2c8f9c
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
tractorss 25063c7
chore: fixed the SDK tests, minor tweaks
jaybuidl 3abfbc5
fix(kleros-sdk): public-client-null-check
tractorss 9140518
chore(subgraph): redeploy-subgraphs
tractorss e8cd12d
fix(sdk): types and unit tests
jaybuidl d3e4b59
chore(sdk): release configuration for NPM, tsconfig tweaks
jaybuidl 1a11c84
chore(sdk): release @kleros/kleros-sdk@2.1.1
jaybuidl 98c2907
chore(sdk): release @kleros/kleros-sdk@2.1.2
jaybuidl b851f2a
chore(sdk): release @kleros/kleros-sdk@2.1.3
jaybuidl 57711ba
docs(sdk): readme
jaybuidl cbdd6d1
chore: clean up
jaybuidl 77b57e4
chore(kleros-sdk): define-entry-points-for-files
tractorss 71f851b
chore(sdk): release @kleros/kleros-sdk@2.1.4
jaybuidl ecc9edf
refactor(kleros-sdk): remove-path-aliasing
tractorss e698548
refactor(kleros-sdk): update-get-dispute-function-parameter-type
tractorss 93e59a1
fix(web): typing
tractorss 18ae12f
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
tractorss 0a8422f
chore: update-yarn-lock
tractorss 04c80db
chore(kleros-sdk): update-get-dispute-id-spec
tractorss 9b4e9d2
feat(kleros-sdk): better-error-handling-and-optimisations
tractorss 7d5ed21
refactor(kleros-sdk): sonar-cloud-fixes
tractorss 542a8d9
refactor(kleros-sdk): remoev-unused-import
tractorss 3d42edc
refactor(kleros-sdk): address-coderabbit-feedback
tractorss a387e77
refactor(kleros-sdk): refactor-error-classes
tractorss 56853b9
fix: test mocks
jaybuidl 52b31a3
fix(kleros-sdk): replace-graphql-request-library-with-native-fetch
tractorss cab784b
chore(kleros-sdk): use-urql-for-gql-queries
tractorss 0562712
feat(kleros-sdk): gql-client-caching
tractorss 078b233
chore(sdk): release @kleros/kleros-sdk@2.1.6
jaybuidl 128e1e5
chore(sdk): publish script
jaybuidl d2cb260
chore(sdk): release @kleros/kleros-sdk@2.1.7
jaybuidl 7b2ccd3
Merge branch 'dev' into feat/dynamic-context-validation-in-sdk
jaybuidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import mustache from "mustache"; | ||
|
||
/** | ||
* | ||
* @param template | ||
* @returns Variables[] returns the variables in a template string | ||
* @note This is a naive implementation and wil not work for complex tags, only works for {{}} and {{{}}} tags for now. | ||
* Reference : https://github.com/janl/mustache.js/issues/538 | ||
*/ | ||
const retrieveVariables = (template: string) => | ||
mustache | ||
.parse(template) | ||
.filter(function (v) { | ||
return v[0] === "name" || v[0] === "&"; | ||
}) // add more conditions here to include more tags | ||
.map(function (v) { | ||
return v[1]; | ||
}); | ||
|
||
export default retrieveVariables; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { request } from "graphql-request"; | ||
|
||
type DisputeDetailsQueryResponse = { | ||
dispute: { | ||
arbitrated: { | ||
id: string; | ||
}; | ||
arbitrableChainId: number; | ||
externalDisputeId: number; | ||
templateId: number; | ||
}; | ||
}; | ||
|
||
const fetchDisputeDetails = (endpoint: string, id: number) => { | ||
const query = ` | ||
query DisputeDetails { | ||
dispute(id: ${id}) { | ||
arbitrated { | ||
id | ||
} | ||
arbitrableChainId | ||
externalDisputeId | ||
templateId | ||
} | ||
} | ||
`; | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
try { | ||
return request<DisputeDetailsQueryResponse>(endpoint, query) | ||
.then((res) => res) | ||
.catch((err) => { | ||
throw new Error(`Error querying Dispute Details , endpoint : ${endpoint}, message : ${err?.message}`); | ||
}); | ||
} catch (error: any) { | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log(`Query Error : ${error?.message}`); | ||
return undefined; | ||
} | ||
}; | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export default fetchDisputeDetails; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { request } from "graphql-request"; | ||
|
||
type DisputeTemplateQueryResponse = { | ||
disputeTemplate: { | ||
templateData: string; | ||
templateDataMappings: string; | ||
}; | ||
}; | ||
|
||
const fetchDisputeTemplateFromId = (endpoint: string, id: number) => { | ||
const query = ` | ||
query DisputeTemplate { | ||
disputeTemplate(id: ${id}) { | ||
templateData | ||
templateDataMappings | ||
} | ||
} | ||
`; | ||
|
||
try { | ||
return request<DisputeTemplateQueryResponse>(endpoint, query) | ||
.then((res) => res) | ||
.catch((err) => { | ||
throw new Error(`Error querying Dispute Template Registry , endpoint : ${endpoint}, message : ${err?.message}`); | ||
}); | ||
} catch (error: any) { | ||
console.log(`Query Error : ${error?.message}`); | ||
return undefined; | ||
} | ||
}; | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export default fetchDisputeTemplateFromId; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PublicClientConfig } from "viem"; | ||
|
||
export type SdkConfig = { | ||
client: PublicClientConfig; | ||
}; | ||
|
||
type GetDisputeParametersOptions = { | ||
sdkConfig: SdkConfig; | ||
additionalContext: Record<string, any>; | ||
}; | ||
|
||
export type GetDisputeParameters = { | ||
disputeId: number; | ||
coreSubgraph: string; | ||
dtrSubgraph: string; | ||
options: GetDisputeParametersOptions | undefined; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { type GetDisputeParameters } from "src/types"; | ||
import { configureSDK } from "src/sdk"; | ||
import fetchDisputeDetails from "src/requests/fetchDisputeDetails"; | ||
import fetchDisputeTemplateFromId from "src/requests/fetchDisputeTemplateFromId"; | ||
import { executeActions } from "dataMappings/executeActions"; | ||
import { populateTemplate } from "dataMappings/utils/populateTemplate"; | ||
import { DisputeDetails } from "dataMappings/utils/disputeDetailsTypes"; | ||
|
||
/** | ||
* Retrieves dispute parameters based on the provided dispute ID and subgraph endpoints. | ||
* | ||
* @param {GetDisputeParameters} disputeParameters - The parameters required to get the dispute. | ||
* @param {number} disputeParameters.disputeId - A unique numeric identifier of the dispute in the Kleros Core contract. | ||
* @param {string} disputeParameters.coreSubgraph - Endpoint for the Kleros core subgraph to use. | ||
* @param {string} disputeParameters.dtrSubgraph - Endpoint for the Kleros dispute template registry subgraph. | ||
* @param {GetDisputeParametersOptions | undefined} disputeParameters.options - Optional parameters to configure the SDK and provide additional context, if not configured already. | ||
*/ | ||
export const getDispute = async (disputeParameters: GetDisputeParameters): Promise<DisputeDetails | undefined> => { | ||
if (disputeParameters.options?.sdkConfig) { | ||
configureSDK(disputeParameters.options.sdkConfig); | ||
} | ||
const { disputeId, dtrSubgraph, coreSubgraph, options } = disputeParameters; | ||
|
||
const disputeDetails = await fetchDisputeDetails(coreSubgraph, disputeId); | ||
|
||
if (!disputeDetails || !disputeDetails.dispute) return; | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const template = await fetchDisputeTemplateFromId(dtrSubgraph, disputeDetails.dispute.templateId); | ||
|
||
if (!template) return; | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const { templateData, templateDataMappings } = template.disputeTemplate; | ||
|
||
const initialContext = { | ||
arbitrableAddress: disputeDetails.dispute.arbitrated.id, | ||
arbitrableChainID: disputeDetails.dispute.arbitrableChainId, | ||
externalDisputeID: disputeDetails.dispute.externalDisputeId, | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
...options?.additionalContext, | ||
}; | ||
|
||
const data = templateDataMappings ? await executeActions(JSON.parse(templateDataMappings), initialContext) : {}; | ||
alcercu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const populatedTemplate = populateTemplate(templateData, data); | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return populatedTemplate; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.