From 13e20fe6fb16610ade1c583e3aa29b182d5e3fa7 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 14 Nov 2022 23:49:40 +0100 Subject: [PATCH] Fix implementation of postprocess function --- src/claim.js | 5 +++-- src/claimDefinitions/activitypub.js | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/claim.js b/src/claim.js index eff8343..9b28e32 100644 --- a/src/claim.js +++ b/src/claim.js @@ -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 { diff --git a/src/claimDefinitions/activitypub.js b/src/claimDefinitions/activitypub.js index b3a80f9..e779e07 100644 --- a/src/claimDefinitions/activitypub.js +++ b/src/claimDefinitions/activitypub.js @@ -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