feat: Add OpenCollective service provider

This commit is contained in:
Yarmo Mackenbach 2023-03-19 09:52:35 +01:00
parent 7d65a21c1d
commit 15bbad0e6b
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 77 additions and 1 deletions

View file

@ -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)

View file

@ -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