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 // Post process the data
if (claimData.functions && claimData.functions.postprocess) { const def = claimDefinitions.data[claimData.serviceprovider.name]
if (def.functions && def.functions.postprocess) {
try { try {
({ claimData, proofData } = claimData.functions.postprocess(claimData, proofData)) ({ claimData, proofData } = def.functions.postprocess(claimData, proofData))
} catch (_) {} } catch (_) {}
} }
} else { } else {

View file

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