Fix implementation of postprocess function

This commit is contained in:
Yarmo Mackenbach 2022-11-14 23:49:40 +01:00
parent e6b824bcf8
commit 13e20fe6fb
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 12 additions and 9 deletions

View file

@ -250,9 +250,10 @@ class Claim {
}
// Post process the data
if (claimData.functions && claimData.functions.postprocess) {
const def = claimDefinitions.data[claimData.serviceprovider.name]
if (def.functions && def.functions.postprocess) {
try {
({ claimData, proofData } = claimData.functions.postprocess(claimData, proofData))
({ claimData, proofData } = def.functions.postprocess(claimData, proofData))
} catch (_) {}
}
} else {

View file

@ -54,13 +54,14 @@ const processURI = (uri) => {
relation: E.ClaimRelation.CONTAINS,
path: ['attachment', 'value']
}
],
functions: {
postprocess: (claimData, proofData) => {
claimData.profile.display = `${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}`
return { claimData, proofData }
}
}
]
}
}
const functions = {
postprocess: (claimData, proofData) => {
claimData.profile.display = `${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}`
return { claimData, proofData }
}
}
@ -93,4 +94,5 @@ const tests = [
exports.reURI = reURI
exports.processURI = processURI
exports.functions = functions
exports.tests = tests