From 10a32f98a5789ba8f1d2740be4991fbb570263e9 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 12 Apr 2021 14:31:34 +0200 Subject: [PATCH] Update serviceProviders with enums --- src/serviceproviders/devto.js | 10 ++++++---- src/serviceproviders/discourse.js | 10 ++++++---- src/serviceproviders/dns.js | 13 +++++++------ src/serviceproviders/fediverse.js | 10 ++++++---- src/serviceproviders/gitea.js | 10 ++++++---- src/serviceproviders/github.js | 10 ++++++---- src/serviceproviders/gitlab.js | 9 +++++---- src/serviceproviders/hackernews.js | 10 ++++++---- src/serviceproviders/irc.js | 10 ++++++---- src/serviceproviders/liberapay.js | 10 ++++++---- src/serviceproviders/lobsters.js | 10 ++++++---- src/serviceproviders/mastodon.js | 10 ++++++---- src/serviceproviders/matrix.js | 10 ++++++---- src/serviceproviders/owncast.js | 11 +++++------ src/serviceproviders/reddit.js | 10 ++++++---- src/serviceproviders/twitter.js | 10 ++++++---- src/serviceproviders/xmpp.js | 10 ++++++---- 17 files changed, 101 insertions(+), 72 deletions(-) diff --git a/src/serviceproviders/devto.js b/src/serviceproviders/devto.js index 05d1713..4343215 100644 --- a/src/serviceproviders/devto.js +++ b/src/serviceproviders/devto.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/dev\.to\/(.*)\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: `https://dev.to/api/articles/${match[1]}/${match[2]}`, - useProxy: true, - format: 'json', + access: proofAccess.NOCORS, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['body_markdown'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/discourse.js b/src/serviceproviders/discourse.js index c54e41b..c1569e9 100644 --- a/src/serviceproviders/discourse.js +++ b/src/serviceproviders/discourse.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/(.*)\/u\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: `https://${match[1]}/u/${match[2]}.json`, - useProxy: true, - format: 'json', + access: proofAccess.NOCORS, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['user', 'bio_raw'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/dns.js b/src/serviceproviders/dns.js index 50d3322..224b528 100644 --- a/src/serviceproviders/dns.js +++ b/src/serviceproviders/dns.js @@ -13,10 +13,11 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const dns = require('dns') const bent = require('bent') const req = bent('GET') -const utils = require('../utils') + const reURI = /^dns:([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/ const customRequestHandler = async (spData, opts) => { @@ -61,16 +62,16 @@ const processURI = (uri, opts) => { qr: null, }, proof: { - uri: utils.generateProxyURL('dns', match[1], opts), + uri: null, fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.SERVER, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'uri', + format: claimFormat.URI, + relation: claimRelation.CONTAINS, path: ['records', 'txt'], - relation: 'contains', }, customRequestHandler: customRequestHandler, } diff --git a/src/serviceproviders/fediverse.js b/src/serviceproviders/fediverse.js index 5047786..3c14501 100644 --- a/src/serviceproviders/fediverse.js +++ b/src/serviceproviders/fediverse.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/(.*)\/users\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.GENERIC, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'fingerprint', + format: claimFormat.FINGERPRINT, + relation: claimRelation.CONTAINS, path: ['summary'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/gitea.js b/src/serviceproviders/gitea.js index c80cf51..d258f62 100644 --- a/src/serviceproviders/gitea.js +++ b/src/serviceproviders/gitea.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/(.*)\/(.*)\/gitea_proof\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: `https://${match[1]}/api/v1/repos/${match[2]}/gitea_proof`, - useProxy: true, - format: 'json', + access: proofAccess.NOCORS, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.EQUALS, path: ['description'], - relation: 'equals', }, customRequestHandler: null, } diff --git a/src/serviceproviders/github.js b/src/serviceproviders/github.js index c0e843e..726f2bb 100644 --- a/src/serviceproviders/github.js +++ b/src/serviceproviders/github.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/gist\.github\.com\/(.*)\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: `https://api.github.com/gists/${match[2]}`, - useProxy: false, - format: 'json', + access: proofAccess.GENERIC, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['files', 'openpgp.md', 'content'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/gitlab.js b/src/serviceproviders/gitlab.js index f84217f..e987cc1 100644 --- a/src/serviceproviders/gitlab.js +++ b/src/serviceproviders/gitlab.js @@ -13,6 +13,7 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const bent = require('bent') const req = bent('GET') @@ -77,14 +78,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.GENERIC, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.EQUALS, path: ['description'], - relation: 'equals', }, customRequestHandler: customRequestHandler, } diff --git a/src/serviceproviders/hackernews.js b/src/serviceproviders/hackernews.js index 0f324f7..d090160 100644 --- a/src/serviceproviders/hackernews.js +++ b/src/serviceproviders/hackernews.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/news\.ycombinator\.com\/user\?id=(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`, fetch: null, - useProxy: true, - format: 'json', + access: proofAccess.NOCORS, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'uri', + format: claimFormat.URI, + relation: claimRelation.CONTAINS, path: ['about'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/irc.js b/src/serviceproviders/irc.js index 64480e6..2402075 100644 --- a/src/serviceproviders/irc.js +++ b/src/serviceproviders/irc.js @@ -13,7 +13,9 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const utils = require('../utils') + const reURI = /^irc\:\/\/(.*)\/([a-zA-Z0-9]*)/ const processURI = (uri, opts) => { @@ -35,14 +37,14 @@ const processURI = (uri, opts) => { proof: { uri: utils.generateProxyURL('irc', [match[1], match[2]], opts), fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.SERVER, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'uri', + format: claimFormat.URI, + relation: claimRelation.CONTAINS, path: [], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/liberapay.js b/src/serviceproviders/liberapay.js index 89f8c94..8e01f88 100644 --- a/src/serviceproviders/liberapay.js +++ b/src/serviceproviders/liberapay.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/liberapay\.com\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: `https://liberapay.com/${match[1]}/public.json`, - useProxy: false, - format: 'json', + access: proofAccess.GENERIC, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['statements', 'content'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/lobsters.js b/src/serviceproviders/lobsters.js index 3320567..a1e803f 100644 --- a/src/serviceproviders/lobsters.js +++ b/src/serviceproviders/lobsters.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/lobste\.rs\/u\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: `https://lobste.rs/u/${match[1]}.json`, fetch: null, - useProxy: true, - format: 'json', + access: proofAccess.NOCORS, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['about'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/mastodon.js b/src/serviceproviders/mastodon.js index 299107a..e3f7f37 100644 --- a/src/serviceproviders/mastodon.js +++ b/src/serviceproviders/mastodon.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/(.*)\/@(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.GENERIC, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'fingerprint', + format: claimFormat.FINGERPRINT, + relation: claimRelation.CONTAINS, path: ['attachment', 'value'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/matrix.js b/src/serviceproviders/matrix.js index fcf3cc7..e60a59e 100644 --- a/src/serviceproviders/matrix.js +++ b/src/serviceproviders/matrix.js @@ -13,10 +13,12 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const bent = require('bent') const req = bent('GET') const queryString = require('query-string') const utils = require('../utils') + const reURI = /^matrix\:u\/(?:\@)?([^@:]*\:[^?]*)(\?.*)?/ const processURI = (uri, opts) => { @@ -55,14 +57,14 @@ const processURI = (uri, opts) => { proof: { uri: eventUrl, fetch: proofUrl, - useProxy: false, - format: 'json', + access: proofAccess.GRANTED, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['data', 'content', 'body'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/owncast.js b/src/serviceproviders/owncast.js index 53458c4..e38e575 100644 --- a/src/serviceproviders/owncast.js +++ b/src/serviceproviders/owncast.js @@ -13,8 +13,7 @@ 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 bent = require('bent') -const req = bent('GET') +const { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const reURI = /^https:\/\/(.*)/ @@ -37,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: `${uri}/api/config`, fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.GENERIC, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'fingerprint', + format: claimFormat.FINGERPRINT, + relation: claimRelation.CONTAINS, path: ['socialHandles', 'url'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/reddit.js b/src/serviceproviders/reddit.js index 66c1a19..7b8b09f 100644 --- a/src/serviceproviders/reddit.js +++ b/src/serviceproviders/reddit.js @@ -13,6 +13,8 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') + const reURI = /^https:\/\/(?:www\.)?reddit\.com\/user\/(.*)\/comments\/(.*)\/(.*)\/?/ const processURI = (uri, opts) => { @@ -34,14 +36,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: `https://www.reddit.com/user/${match[1]}/comments/${match[2]}.json`, - useProxy: true, - format: 'json', + access: proofAccess.NOCORS, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: ['data', 'children', 'data', 'selftext'], - relation: 'contains', }, customRequestHandler: null, } diff --git a/src/serviceproviders/twitter.js b/src/serviceproviders/twitter.js index 8adc7fa..230dadd 100644 --- a/src/serviceproviders/twitter.js +++ b/src/serviceproviders/twitter.js @@ -13,10 +13,12 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const bent = require('bent') const req = bent('GET') const serviceproviders = require('../serviceproviders') const utils = require('../utils') + const reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/ const customRequestHandler = async (spData, opts) => { @@ -81,14 +83,14 @@ const processURI = (uri, opts) => { proof: { uri: uri, fetch: utils.generateProxyURL('twitter', match[2], opts), - useProxy: false, - format: 'text', + access: proofAccess.GRANTED, + format: proofFormat.TEXT, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: [], - relation: 'contains', }, customRequestHandler: customRequestHandler, } diff --git a/src/serviceproviders/xmpp.js b/src/serviceproviders/xmpp.js index be03bc3..1f333b7 100644 --- a/src/serviceproviders/xmpp.js +++ b/src/serviceproviders/xmpp.js @@ -13,7 +13,9 @@ 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 { proofAccess, proofFormat, claimFormat, claimRelation } = require('../enums') const utils = require('../utils') + const reURI = /^xmpp:([a-zA-Z0-9\.\-\_]*)@([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/ const processURI = (uri, opts) => { @@ -35,14 +37,14 @@ const processURI = (uri, opts) => { proof: { uri: utils.generateProxyURL('xmpp', `${match[1]}@${match[2]}`, opts), fetch: null, - useProxy: false, - format: 'json', + access: proofAccess.SERVER, + format: proofFormat.JSON, }, claim: { fingerprint: null, - format: 'message', + format: claimFormat.MESSAGE, + relation: claimRelation.CONTAINS, path: [], - relation: 'contains', }, customRequestHandler: null, }