diff --git a/package.json b/package.json index 2e35c44..d3a4f57 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "@rollup/plugin-node-resolve": "^15.1.0", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", - "chai-match-pattern": "^1.2.0", "clean-jsdoc-theme": "^3.2.4", "eslint": "^8.39.0", "eslint-config-standard": "^17.0.0", diff --git a/src/claimDefinitions/activitypub.js b/src/serviceProviders/activitypub.js similarity index 61% rename from src/claimDefinitions/activitypub.js rename to src/serviceProviders/activitypub.js index 311b588..ab18166 100644 --- a/src/claimDefinitions/activitypub.js +++ b/src/serviceProviders/activitypub.js @@ -14,60 +14,65 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/?/ /** * @function * @param {string} uri + * @returns {ServiceProvider} */ export function processURI (uri) { - return { - serviceprovider: { - type: 'web', - name: 'activitypub' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'activitypub', + name: 'ActivityPub', + homepage: 'https://activitypub.rocks' }, profile: { display: uri, uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString().toString(), + uriIsAmbiguous: true + }, proof: { - uri, request: { - fetcher: E.Fetcher.ACTIVITYPUB, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.ACTIVITYPUB, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: uri } - } - }, - claim: [ - { - format: E.ClaimFormat.FINGERPRINT, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['summary'] }, - { - format: E.ClaimFormat.FINGERPRINT, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['attachment', 'value'] + response: { + format: E.ProofFormat.JSON }, - { - format: E.ClaimFormat.FINGERPRINT, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['content'] - } - ] - } + target: [ + { + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['summary'] + }, + { + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['attachment', 'value'] + }, + { + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['content'] + } + ] + } + }) } export const functions = { diff --git a/src/claimDefinitions/discourse.js b/src/serviceProviders/discourse.js similarity index 64% rename from src/claimDefinitions/discourse.js rename to src/serviceProviders/discourse.js index c1ca992..ed60b89 100644 --- a/src/claimDefinitions/discourse.js +++ b/src/serviceProviders/discourse.js @@ -14,49 +14,54 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/u\/(.*)\/?/ /** * @function * @param {string} uri + * @returns {ServiceProvider} */ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'discourse' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'discourse', + name: 'Discourse', + homepage: 'https://www.discourse.org' }, profile: { display: `${match[2]}@${match[1]}`, uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString().toString(), + uriIsAmbiguous: true + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://${match[1]}/u/${match[2]}.json`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['user', 'bio_raw'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['user', 'bio_raw'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/dns.js b/src/serviceProviders/dns.js similarity index 66% rename from src/claimDefinitions/dns.js rename to src/serviceProviders/dns.js index a6f4a5d..e5135c5 100644 --- a/src/claimDefinitions/dns.js +++ b/src/serviceProviders/dns.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^dns:([a-zA-Z0-9.\-_]*)(?:\?(.*))?/ @@ -24,38 +25,40 @@ export const reURI = /^dns:([a-zA-Z0-9.\-_]*)(?:\?(.*))?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'dns' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'dns', + name: 'DNS' }, profile: { display: match[1], uri: `https://${match[1]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: null, request: { - fetcher: E.Fetcher.DNS, - access: E.ProofAccess.SERVER, - format: E.ProofFormat.JSON, + uri: null, + protocol: E.Fetcher.DNS, + accessRestriction: E.ProofAccessRestriction.SERVER, data: { domain: match[1] } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['records', 'txt'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['records', 'txt'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/forem.js b/src/serviceProviders/forem.js similarity index 66% rename from src/claimDefinitions/forem.js rename to src/serviceProviders/forem.js index 97e3088..e9fb420 100644 --- a/src/claimDefinitions/forem.js +++ b/src/serviceProviders/forem.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/(.*)\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/(.*)\/(.*)\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'forem' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'forem', + name: 'Forem', + homepage: 'https://www.forem.com' }, profile: { display: `${match[2]}@${match[1]}`, uri: `https://${match[1]}/${match[2]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString().toString(), + uriIsAmbiguous: true + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://${match[1]}/api/articles/${match[2]}/${match[3]}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['body_markdown'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['body_markdown'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/forgejo.js b/src/serviceProviders/forgejo.js similarity index 68% rename from src/claimDefinitions/forgejo.js rename to src/serviceProviders/forgejo.js index 7f25bf7..7fb7c07 100644 --- a/src/claimDefinitions/forgejo.js +++ b/src/serviceProviders/forgejo.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/(.*)\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/(.*)\/(.*)\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'forgejo' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'forgejo', + name: 'Forgejo', + homepage: 'https://forgejo.org' }, profile: { display: `${match[2]}@${match[1]}`, uri: `https://${match[1]}/${match[2]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: true + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://${match[1]}/api/v1/repos/${match[2]}/${match[3]}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.EQUALS, - path: ['description'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.EQUALS, + path: ['description'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/gitea.js b/src/serviceProviders/gitea.js similarity index 68% rename from src/claimDefinitions/gitea.js rename to src/serviceProviders/gitea.js index 1c593ca..10fb641 100644 --- a/src/claimDefinitions/gitea.js +++ b/src/serviceProviders/gitea.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/(.*)\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/(.*)\/(.*)\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'gitea' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'gitea', + name: 'Gitea', + homepage: 'https://about.gitea.com' }, profile: { display: `${match[2]}@${match[1]}`, uri: `https://${match[1]}/${match[2]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: true + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://${match[1]}/api/v1/repos/${match[2]}/${match[3]}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.EQUALS, - path: ['description'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.EQUALS, + path: ['description'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/github.js b/src/serviceProviders/github.js similarity index 66% rename from src/claimDefinitions/github.js rename to src/serviceProviders/github.js index d3c964a..312b5c5 100644 --- a/src/claimDefinitions/github.js +++ b/src/serviceProviders/github.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/gist\.github\.com\/(.*)\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/gist\.github\.com\/(.*)\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'github' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'github', + name: 'GitHub', + homepage: 'https://github.com' }, profile: { display: match[1], uri: `https://github.com/${match[1]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: `https://api.github.com/gists/${match[2]}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['files', 'openpgp.md', 'content'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['files', 'openpgp.md', 'content'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/gitlab.js b/src/serviceProviders/gitlab.js similarity index 68% rename from src/claimDefinitions/gitlab.js rename to src/serviceProviders/gitlab.js index 9825593..a390732 100644 --- a/src/claimDefinitions/gitlab.js +++ b/src/serviceProviders/gitlab.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)\/(.*)\/gitlab_proof\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/(.*)\/(.*)\/gitlab_proof\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'gitlab' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'gitlab', + name: 'GitLab', + homepage: 'https://about.gitlab.com' }, profile: { display: `${match[2]}@${match[1]}`, uri: `https://${match[1]}/${match[2]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: true + }, proof: { uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: `https://${match[1]}/api/v4/projects/${match[2]}%2Fgitlab_proof`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.EQUALS, - path: ['description'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.EQUALS, + path: ['description'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/hackernews.js b/src/serviceProviders/hackernews.js similarity index 64% rename from src/claimDefinitions/hackernews.js rename to src/serviceProviders/hackernews.js index 8088e55..dcbc030 100644 --- a/src/claimDefinitions/hackernews.js +++ b/src/serviceProviders/hackernews.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/news\.ycombinator\.com\/user\?id=(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/news\.ycombinator\.com\/user\?id=(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'hackernews' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'hackernews', + name: 'Hacker News', + homepage: 'https://news.ycombinator.com' }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.HTML, - relation: E.ClaimRelation.CONTAINS, - path: ['about'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.HTML, + relation: E.ClaimRelation.CONTAINS, + path: ['about'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/index.js b/src/serviceProviders/index.js similarity index 100% rename from src/claimDefinitions/index.js rename to src/serviceProviders/index.js diff --git a/src/claimDefinitions/irc.js b/src/serviceProviders/irc.js similarity index 69% rename from src/claimDefinitions/irc.js rename to src/serviceProviders/irc.js index f54dcf1..7db6c13 100644 --- a/src/claimDefinitions/irc.js +++ b/src/serviceProviders/irc.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^irc:\/\/(.*)\/([a-zA-Z0-9\-[\]\\`_^{|}]*)/ @@ -24,39 +25,41 @@ export const reURI = /^irc:\/\/(.*)\/([a-zA-Z0-9\-[\]\\`_^{|}]*)/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'communication', - name: 'irc' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'irc', + name: 'IRC' }, profile: { display: `irc://${match[1]}/${match[2]}`, uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: null, request: { - fetcher: E.Fetcher.IRC, - access: E.ProofAccess.SERVER, - format: E.ProofFormat.JSON, + uri: null, + protocol: E.Fetcher.IRC, + accessRestriction: E.ProofAccessRestriction.SERVER, data: { domain: match[1], nick: match[2] } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: [] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: [] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/keybase.js b/src/serviceProviders/keybase.js similarity index 64% rename from src/claimDefinitions/keybase.js rename to src/serviceProviders/keybase.js index a8b237f..8814edf 100644 --- a/src/claimDefinitions/keybase.js +++ b/src/serviceProviders/keybase.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/keybase.io\/(.*)\/?/ @@ -24,39 +25,41 @@ export const reURI = /^https:\/\/keybase.io\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', + return new ServiceProvider({ + about: { + id: 'web', name: 'keybase' }, - match: { - regularExpression: reURI, - isAmbiguous: false - }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: `https://keybase.io/_/api/1.0/user/lookup.json?username=${match[1]}`, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri: `https://keybase.io/_/api/1.0/user/lookup.json?username=${match[1]}`, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://keybase.io/_/api/1.0/user/lookup.json?username=${match[1]}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.FINGERPRINT, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['them', 'public_keys', 'primary', 'key_fingerprint'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.FINGERPRINT, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['them', 'public_keys', 'primary', 'key_fingerprint'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/liberapay.js b/src/serviceProviders/liberapay.js similarity index 65% rename from src/claimDefinitions/liberapay.js rename to src/serviceProviders/liberapay.js index eb4a799..222a2ac 100644 --- a/src/claimDefinitions/liberapay.js +++ b/src/serviceProviders/liberapay.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/liberapay\.com\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/liberapay\.com\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'liberapay' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'liberapay', + name: 'Liberapay', + homepage: 'https://liberapay.com' }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: `https://liberapay.com/${match[1]}/public.json`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['statements', 'content'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['statements', 'content'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/lichess.js b/src/serviceProviders/lichess.js similarity index 66% rename from src/claimDefinitions/lichess.js rename to src/serviceProviders/lichess.js index cc53c84..fb665d5 100644 --- a/src/claimDefinitions/lichess.js +++ b/src/serviceProviders/lichess.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/lichess\.org\/@\/(.*)\/?/ @@ -24,39 +25,41 @@ export const reURI = /^https:\/\/lichess\.org\/@\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', + return new ServiceProvider({ + about: { + id: 'web', name: 'lichess' }, - match: { - regularExpression: reURI, - isAmbiguous: false - }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: `https://lichess.org/api/user/${match[1]}`, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + uri: `https://lichess.org/api/user/${match[1]}`, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: `https://lichess.org/api/user/${match[1]}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.FINGERPRINT, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['profile', 'links'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.FINGERPRINT, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['profile', 'links'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/lobsters.js b/src/serviceProviders/lobsters.js similarity index 64% rename from src/claimDefinitions/lobsters.js rename to src/serviceProviders/lobsters.js index dd9b297..ed730f9 100644 --- a/src/claimDefinitions/lobsters.js +++ b/src/serviceProviders/lobsters.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/lobste\.rs\/u\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/lobste\.rs\/u\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'lobsters' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'lobsters', + name: 'Lobsters', + homepage: 'https://lobste.rs' }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: `https://lobste.rs/u/${match[1]}.json`, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri: `https://lobste.rs/u/${match[1]}.json`, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://lobste.rs/u/${match[1]}.json`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['about'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['about'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/matrix.js b/src/serviceProviders/matrix.js similarity index 75% rename from src/claimDefinitions/matrix.js rename to src/serviceProviders/matrix.js index 0a74d7f..a57ab38 100644 --- a/src/claimDefinitions/matrix.js +++ b/src/serviceProviders/matrix.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^matrix:u\/(?:@)?([^@:]*:[^?]*)(\?.*)?/ @@ -40,39 +41,42 @@ export function processURI (uri) { const profileUrl = `https://matrix.to/#/@${match[1]}` const eventUrl = `https://matrix.to/#/${paramRoomId}/${paramEventId}` - return { - serviceprovider: { - type: 'communication', - name: 'matrix' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'matrix', + name: 'Matrix', + homepage: 'https://matrix.org' }, profile: { display: `@${match[1]}`, uri: profileUrl, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: eventUrl, request: { - fetcher: E.Fetcher.MATRIX, - access: E.ProofAccess.GRANTED, - format: E.ProofFormat.JSON, + uri: eventUrl, + protocol: E.Fetcher.MATRIX, + accessRestriction: E.ProofAccessRestriction.GRANTED, data: { eventId: paramEventId, roomId: paramRoomId } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['content', 'body'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['content', 'body'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/opencollective.js b/src/serviceProviders/opencollective.js similarity index 65% rename from src/claimDefinitions/opencollective.js rename to src/serviceProviders/opencollective.js index de593d0..2b64aec 100644 --- a/src/claimDefinitions/opencollective.js +++ b/src/serviceProviders/opencollective.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/opencollective\.com\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/opencollective\.com\/(.*)\/?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'opencollective' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'opencollective', + name: 'Open Collective', + homepage: 'https://opencollective.com' }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri, request: { - fetcher: E.Fetcher.GRAPHQL, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.GRAPHQL, + accessRestriction: E.ProofAccessRestriction.NOCORS, 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'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['data', 'collective', 'longDescription'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/owncast.js b/src/serviceProviders/owncast.js similarity index 64% rename from src/claimDefinitions/owncast.js rename to src/serviceProviders/owncast.js index dff3f4e..77b1f76 100644 --- a/src/claimDefinitions/owncast.js +++ b/src/serviceProviders/owncast.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*)/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/(.*)/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'owncast' - }, - match: { - regularExpression: reURI, - isAmbiguous: true + return new ServiceProvider({ + about: { + id: 'owncast', + name: 'Owncast', + homepage: 'https://owncast.online' }, profile: { display: match[1], uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: true + }, proof: { - uri: `${uri}/api/config`, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + uri: `${uri}/api/config`, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: `${uri}/api/config`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.FINGERPRINT, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['socialHandles', 'url'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.FINGERPRINT, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['socialHandles', 'url'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/reddit.js b/src/serviceProviders/reddit.js similarity index 70% rename from src/claimDefinitions/reddit.js rename to src/serviceProviders/reddit.js index 09705b5..89e9814 100644 --- a/src/claimDefinitions/reddit.js +++ b/src/serviceProviders/reddit.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(?:www\.)?reddit\.com\/user\/(.*)\/comments\/(.*)\/(.*)\/?/ @@ -24,39 +25,42 @@ export const reURI = /^https:\/\/(?:www\.)?reddit\.com\/user\/(.*)\/comments\/(. export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'web', - name: 'reddit' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'reddit', + name: 'Reddit', + homepage: 'https://reddit.com' }, profile: { display: match[1], uri: `https://www.reddit.com/user/${match[1]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { url: `https://www.reddit.com/user/${match[1]}/comments/${match[2]}.json`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['data', 'children', 'data', 'selftext'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['data', 'children', 'data', 'selftext'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/stackexchange.js b/src/serviceProviders/stackexchange.js similarity index 76% rename from src/claimDefinitions/stackexchange.js rename to src/serviceProviders/stackexchange.js index 0b8ca9c..ec1ee15 100644 --- a/src/claimDefinitions/stackexchange.js +++ b/src/serviceProviders/stackexchange.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/(.*(?:askubuntu|mathoverflow|serverfault|stackapps|stackoverflow|superuser)|.+\.stackexchange)\.com\/users\/(\d+)/ const reStackExchange = /\.stackexchange$/ @@ -26,39 +27,42 @@ export function processURI (uri) { const [, domain, id] = uri.match(reURI) const site = domain.replace(reStackExchange, '') - return { - serviceprovider: { - type: 'web', - name: 'stackexchange' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'stackexchange', + name: 'Stack Exchange', + homepage: 'https://stackexchange.com' }, profile: { display: `${id}@${site}`, uri, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: `https://${domain}.com/users/${id}?tab=profile`, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.GENERIC, - format: E.ProofFormat.JSON, + uri: `https://${domain}.com/users/${id}?tab=profile`, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NONE, data: { url: `https://api.stackexchange.com/2.3/users/${id}?site=${site}&filter=!AH)b5JqVyImf`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['items', 'about_me'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['items', 'about_me'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/telegram.js b/src/serviceProviders/telegram.js similarity index 68% rename from src/claimDefinitions/telegram.js rename to src/serviceProviders/telegram.js index 0b22b34..048b200 100644 --- a/src/claimDefinitions/telegram.js +++ b/src/serviceProviders/telegram.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /https:\/\/t.me\/([A-Za-z0-9_]{5,32})\?proof=([A-Za-z0-9_]{5,32})/ @@ -24,39 +25,42 @@ export const reURI = /https:\/\/t.me\/([A-Za-z0-9_]{5,32})\?proof=([A-Za-z0-9_]{ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'communication', - name: 'telegram' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'telegram', + name: 'Telegram', + homepage: 'https://telegram.org' }, profile: { display: `@${match[1]}`, uri: `https://t.me/${match[1]}`, qr: `https://t.me/${match[1]}` }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: `https://t.me/${match[2]}`, request: { - fetcher: E.Fetcher.TELEGRAM, - access: E.ProofAccess.GRANTED, - format: E.ProofFormat.JSON, + uri: `https://t.me/${match[2]}`, + protocol: E.Fetcher.TELEGRAM, + accessRestriction: E.ProofAccessRestriction.GRANTED, data: { user: match[1], chat: match[2] } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.EQUALS, - path: ['text'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.EQUALS, + path: ['text'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/twitter.js b/src/serviceProviders/twitter.js similarity index 71% rename from src/claimDefinitions/twitter.js rename to src/serviceProviders/twitter.js index f7f804e..fe0de0f 100644 --- a/src/claimDefinitions/twitter.js +++ b/src/serviceProviders/twitter.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/ @@ -28,40 +29,43 @@ export function processURI (uri) { urlsp.set('url', match[0]) urlsp.set('omit_script', '1') - return { - serviceprovider: { - type: 'web', - name: 'twitter' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'twitter', + name: 'Twitter', + homepage: 'https://twitter.com' }, profile: { display: `@${match[1]}`, uri: `https://twitter.com/${match[1]}`, qr: null }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri, request: { - fetcher: E.Fetcher.HTTP, - access: E.ProofAccess.NOCORS, - format: E.ProofFormat.JSON, + uri, + protocol: E.Fetcher.HTTP, + accessRestriction: E.ProofAccessRestriction.NOCORS, data: { // Returns an oembed json object with the tweet content in html form url: `https://publish.twitter.com/oembed?${urlsp}`, format: E.ProofFormat.JSON } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: ['html'] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: ['html'] + }] + } + }) } export const tests = [ diff --git a/src/claimDefinitions/xmpp.js b/src/serviceProviders/xmpp.js similarity index 66% rename from src/claimDefinitions/xmpp.js rename to src/serviceProviders/xmpp.js index cae36ca..0043495 100644 --- a/src/claimDefinitions/xmpp.js +++ b/src/serviceProviders/xmpp.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ import * as E from '../enums.js' +import { ServiceProvider } from '../serviceProvider.js' export const reURI = /^xmpp:([a-zA-Z0-9.\-_]*)@([a-zA-Z0-9.\-_]*)(?:\?(.*))?/ @@ -24,38 +25,41 @@ export const reURI = /^xmpp:([a-zA-Z0-9.\-_]*)@([a-zA-Z0-9.\-_]*)(?:\?(.*))?/ export function processURI (uri) { const match = uri.match(reURI) - return { - serviceprovider: { - type: 'communication', - name: 'xmpp' - }, - match: { - regularExpression: reURI, - isAmbiguous: false + return new ServiceProvider({ + about: { + id: 'xmpp', + name: 'XMPP', + homepage: 'https://xmpp.org' }, profile: { display: `${match[1]}@${match[2]}`, uri, qr: uri }, + claim: { + uriRegularExpression: reURI.toString(), + uriIsAmbiguous: false + }, proof: { - uri: null, request: { - fetcher: E.Fetcher.XMPP, - access: E.ProofAccess.SERVER, - format: E.ProofFormat.JSON, + uri: null, + protocol: E.Fetcher.XMPP, + accessRestriction: E.ProofAccessRestriction.SERVER, data: { id: `${match[1]}@${match[2]}` } - } - }, - claim: [{ - format: E.ClaimFormat.URI, - encoding: E.EntityEncodingFormat.PLAIN, - relation: E.ClaimRelation.CONTAINS, - path: [] - }] - } + }, + response: { + format: E.ProofFormat.JSON + }, + target: [{ + format: E.ClaimFormat.URI, + encoding: E.EntityEncodingFormat.PLAIN, + relation: E.ClaimRelation.CONTAINS, + path: [] + }] + } + }) } export const tests = [ diff --git a/test/claimDefinitions.test.js b/test/claimDefinitions.test.js deleted file mode 100644 index 41577bd..0000000 --- a/test/claimDefinitions.test.js +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2021 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. -*/ -import { expect, use } from 'chai' -import chaiAsPromised from 'chai-as-promised' -import chaiMatchPattern from 'chai-match-pattern' -use(chaiAsPromised) -use(chaiMatchPattern) - -const _ = chaiMatchPattern.getLodashModule() - -import { claimDefinitions } from '../src/index.js' - -const pattern = { - serviceprovider: { - type: _.isString, - name: _.isString, - }, - match: { - regularExpression: _.isRegExp, - isAmbiguous: _.isBoolean, - }, - profile: { - display: _.isString, - uri: _.isString, - qr: (x) => { - return _.isString(x) || _.isNull(x) - }, - }, - proof: { - uri: (x) => { - return _.isString(x) || _.isNull(x) - }, - request: { - fetcher: _.isString, - access: _.isString, - format: _.isString, - data: _.isObject, - }, - }, - claim: _.isArray -} - -claimDefinitions.list.forEach((claimDefName, i) => { - const claimDef = claimDefinitions.data[claimDefName] - - describe(`claimDefinitions.${claimDefName}`, () => { - it('should be an object', () => { - expect(typeof claimDef).to.equal('object') - }) - it('should have a RegExp instance named "reURI"', () => { - expect(claimDef.reURI).to.be.instanceof(RegExp) - }) - it('should have a function named "processURI" (1 argument)', () => { - expect(claimDef.processURI).to.be.a('function') - expect(claimDef.processURI).to.have.length(1) - }) - it('should have an array named "tests"', () => { - expect(claimDef.tests).to.be.instanceof(Array) - }) - - claimDef.tests.forEach((test, j) => { - if (test.shouldMatch) { - it(`should match "${test.uri}"`, () => { - expect(claimDef.reURI.test(test.uri)).to.be.true - }) - it(`should return a valid object for "${test.uri}"`, async () => { - const obj = claimDef.processURI(claimDef.tests[0].uri) - expect(obj).to.be.a('object') - expect(obj).to.matchPattern(pattern) - }) - } else { - it(`should not match "${test.uri}"`, () => { - expect(claimDef.reURI.test(test.uri)).to.be.false - }) - } - }) - }) -}) diff --git a/test/serviceProviderDefinitions.test.js b/test/serviceProviderDefinitions.test.js new file mode 100644 index 0000000..3fcd1a7 --- /dev/null +++ b/test/serviceProviderDefinitions.test.js @@ -0,0 +1,56 @@ +/* +Copyright 2021 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. +*/ +import { expect, use } from 'chai' +import chaiAsPromised from 'chai-as-promised' +use(chaiAsPromised) + +import { ServiceProviderDefinitions, ServiceProvider } from '../src/index.js' + +ServiceProviderDefinitions.list.forEach((spDefName, i) => { + const spDef = ServiceProviderDefinitions.data[spDefName] + + describe(`ServiceProviderDefinitions.${spDefName}`, () => { + it('should be an object', () => { + expect(typeof spDef).to.equal('object') + }) + it('should have a RegExp instance named "reURI"', () => { + expect(spDef.reURI).to.be.instanceof(RegExp) + }) + it('should have a function named "processURI" (1 argument)', () => { + expect(spDef.processURI).to.be.a('function') + expect(spDef.processURI).to.have.length(1) + }) + it('should have an array named "tests"', () => { + expect(spDef.tests).to.be.instanceof(Array) + }) + + spDef.tests.forEach((test, j) => { + if (test.shouldMatch) { + it(`should match "${test.uri}"`, () => { + expect(spDef.reURI.test(test.uri)).to.be.true + }) + it(`should return a valid object for "${test.uri}"`, async () => { + const obj = spDef.processURI(spDef.tests[0].uri) + expect(obj).to.be.instanceOf(ServiceProvider) + }) + } else { + it(`should not match "${test.uri}"`, () => { + expect(spDef.reURI.test(test.uri)).to.be.false + }) + } + }) + }) +})