From 15bbad0e6b1f2b0e2a603d63f02b8f2b1c333e40 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sun, 19 Mar 2023 09:52:35 +0100 Subject: [PATCH] feat: Add OpenCollective service provider --- src/claimDefinitions/index.js | 3 +- src/claimDefinitions/opencollective.js | 75 ++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/claimDefinitions/opencollective.js diff --git a/src/claimDefinitions/index.js b/src/claimDefinitions/index.js index 479c7e6..4e11d8c 100644 --- a/src/claimDefinitions/index.js +++ b/src/claimDefinitions/index.js @@ -35,7 +35,8 @@ const data = { discourse: require('./discourse'), owncast: require('./owncast'), stackexchange: require('./stackexchange'), - keybase: require('./keybase') + keybase: require('./keybase'), + opencollective: require('./opencollective') } exports.list = Object.keys(data) diff --git a/src/claimDefinitions/opencollective.js b/src/claimDefinitions/opencollective.js new file mode 100644 index 0000000..737e330 --- /dev/null +++ b/src/claimDefinitions/opencollective.js @@ -0,0 +1,75 @@ +/* +Copyright 2023 Yarmo Mackenbach + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +const E = require('../enums') + +const reURI = /^https:\/\/opencollective\.com\/(.*)\/?/ + +const processURI = (uri) => { + const match = uri.match(reURI) + + return { + serviceprovider: { + type: 'web', + name: 'opencollective' + }, + match: { + regularExpression: reURI, + isAmbiguous: false + }, + profile: { + display: match[1], + uri: uri, + qr: null + }, + proof: { + uri: uri, + request: { + fetcher: E.Fetcher.GRAPHQL, + access: E.ProofAccess.NOCORS, + format: E.ProofFormat.JSON, + data: { + url: 'https://api.opencollective.com/graphql/v2', + query: `{ "query": "query { collective(slug: \\"${match[1]}\\") { longDescription } }" }` + } + } + }, + claim: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['data', 'collective', 'longDescription'] + }] + } +} + +const tests = [ + { + uri: 'https://opencollective.com/Alice', + shouldMatch: true + }, + { + uri: 'https://opencollective.com/Alice/', + shouldMatch: true + }, + { + uri: 'https://domain.org/Alice', + shouldMatch: false + } +] + +exports.reURI = reURI +exports.processURI = processURI +exports.tests = tests