Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"jest": {
"verbose": true,
"collectCoverage": true,
"collectCoverage": false,
"collectCoverageFrom": [
"./*.js",
"./src/**/*.js",
Expand Down
22 changes: 22 additions & 0 deletions src/idv_service/session/create/filters/allowed.provider.builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const Validation = require('../../../../yoti_common/validation');
const AllowedProvider = require('./allowed.provider');

class AllowedProviderBuilder {
withName(provider) {
Validation.isString(provider, 'provider');
this.name = provider;
}

/**
* @returns {AllowedProvider}
*/
build() {
return new AllowedProvider(
this.name
);
}
}

module.exports = AllowedProviderBuilder;
22 changes: 22 additions & 0 deletions src/idv_service/session/create/filters/allowed.provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const Validation = require('../../../../yoti_common/validation');

class AllowedProvider {
/**
* @param {string} name
*/
constructor(name) {
Validation.isString(name, 'name');
/** @private */
this.name = name;
}

toJSON() {
return {
name: this.name,
};
}
}

module.exports = AllowedProvider;
61 changes: 60 additions & 1 deletion src/idv_service/session/create/filters/document.filter.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,78 @@
'use strict';

const Validation = require('../../../../yoti_common/validation');
const AllowedProvider = require('./allowed.provider');

class DocumentFilter {
/**
* @param {string} type
* @param {boolean} allowExpiredDocuments
* @param {boolean} allowNonLatinDocuments
* @param {boolean} allowDigitalIds
* @param {AllowedProvider[]} allowedProviders
*/
constructor(type) {
constructor(type, allowExpiredDocuments, allowNonLatinDocuments, allowDigitalIds, allowedProviders) {
if (new.target === DocumentFilter) {
throw TypeError('DocumentFilter cannot be instantiated');
}

Validation.isString(type, 'type');
/** @private */
this.type = type;

Validation.isBoolean(allowExpiredDocuments, 'allowExpiredDocuments', true);
/** @private */
this.allowExpiredDocuments = allowExpiredDocuments;

Validation.isBoolean(allowNonLatinDocuments, 'allowNonLatinDocuments', true);
/** @private */
this.allowNonLatinDocuments = allowNonLatinDocuments;

Validation.isBoolean(allowDigitalIds, 'allowDigitalIds', true);
/** @private */
this.allowDigitalIds = allowDigitalIds;

if (allowedProviders) {
Validation.isArrayOfType(allowedProviders, AllowedProvider, 'allowedProviders');
/** @private */
this.allowedProviders = allowedProviders;
}
}

/**
* Whether to allow non latin documents
*
* @return {boolean} flag
*/
getAllowNonLatinDocuments() {
return this.allowNonLatinDocuments;
}

/**
* Whether to allow non expired documents
*
* @return {boolean} flag
*/
getAllowExpiredDocuments() {
return this.allowExpiredDocuments;
}

/**
* Whether to allow digital IDs to satisfy the filter
*
* @return boolean flag
*/
getAllowDigitalIds() {
return this.allowDigitalIds;
}

/**
* The list of digital ID providers that are allowed to satisfy the filter
*
* @return AllowedProvider[] the allowed providers
*/
getAllowedProviders() {
return this.allowedProviders;
}

toJSON() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const DocumentRestriction = require('./document.restriction');
const Validation = require('../../../../../yoti_common/validation');
const IDVConstants = require('../../../../idv.constants');

/**
* @typedef {import('./../allowed.provider')} AllowedProvider
*/

class DocumentRestrictionsFilterBuilder {
constructor() {
/** @private */
Expand Down Expand Up @@ -59,6 +63,26 @@ class DocumentRestrictionsFilterBuilder {
return this;
}

/**
* @param {Boolean} allowDigitalIds
*
* @returns {this}
*/
withAllowDigitalIds(allowDigitalIds) {
this.allowDigitalIds = allowDigitalIds;
return this;
}

/**
* @param {AllowedProvider[]} allowedProviders
*
* @returns {this}
*/
withAllowedProviders(allowedProviders) {
this.allowedProviders = allowedProviders;
return this;
}

/**
* @returns {DocumentRestrictionsFilter}
*/
Expand All @@ -67,7 +91,9 @@ class DocumentRestrictionsFilterBuilder {
this.inclusion,
this.documents,
this.allowExpiredDocuments,
this.allowNonLatinDocuments
this.allowNonLatinDocuments,
this.allowDigitalIds,
this.allowedProviders
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ const DocumentFilter = require('../document.filter');
const DocumentRestriction = require('./document.restriction');
const IDVConstants = require('../../../../idv.constants');

/**
* @typedef {import('./../allowed.provider')} AllowedProvider
*/

class DocumentRestrictionsFilter extends DocumentFilter {
/**
* @param {string} inclusion
* @param {DocumentRestriction[]} documents
* @param {Boolean} allowExpiredDocuments
* @param {Boolean} allowNonLatinDocuments
* @param {boolean} allowDigitalIds
* @param {AllowedProvider[]} allowedProviders
*/
constructor(inclusion, documents, allowExpiredDocuments, allowNonLatinDocuments) {
super(IDVConstants.DOCUMENT_RESTRICTIONS);
constructor(inclusion, documents, allowExpiredDocuments, allowNonLatinDocuments, allowDigitalIds, allowedProviders) {
super(IDVConstants.DOCUMENT_RESTRICTIONS, allowExpiredDocuments, allowNonLatinDocuments, allowDigitalIds, allowedProviders);

Validation.isString(inclusion, 'inclusion');
/** @private */
Expand All @@ -22,23 +28,17 @@ class DocumentRestrictionsFilter extends DocumentFilter {
Validation.isArrayOfType(documents, DocumentRestriction, 'documents');
/** @private */
this.documents = documents;

Validation.isBoolean(allowExpiredDocuments, 'allowExpiredDocuments', true);
/** @private */
this.allowExpiredDocuments = allowExpiredDocuments;

Validation.isBoolean(allowNonLatinDocuments, 'allowNonLatinDocuments', true);
/** @private */
this.allowNonLatinDocuments = allowNonLatinDocuments;
}

toJSON() {
const json = super.toJSON();

json.inclusion = this.inclusion;
json.documents = this.documents;
json.allow_expired_documents = this.allowExpiredDocuments;
json.allow_non_latin_documents = this.allowNonLatinDocuments;
json.allow_expired_documents = this.getAllowExpiredDocuments();
json.allow_non_latin_documents = this.getAllowNonLatinDocuments();
json.allow_digital_ids = this.getAllowDigitalIds();
json.allowed_providers = this.getAllowedProviders();

return json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const TypeRestriction = require('./type.restriction');
const CountryRestriction = require('./country.restriction');
const IDVConstants = require('../../../../idv.constants');

/**
* @typedef {import('./../allowed.provider')} AllowedProvider
*/

class OrthogonalRestrictionsFilterBuilder {
/**
* @param {string[]} countryCodes
Expand Down Expand Up @@ -78,6 +82,26 @@ class OrthogonalRestrictionsFilterBuilder {
return this;
}

/**
* @param {Boolean} allowDigitalIds
*
* @returns {this}
*/
withAllowDigitalIds(allowDigitalIds) {
this.allowDigitalIds = allowDigitalIds;
return this;
}

/**
* @param {AllowedProvider[]} allowedProviders
*
* @returns {this}
*/
withAllowedProviders(allowedProviders) {
this.allowedProviders = allowedProviders;
return this;
}

/**
* @returns {OrthogonalRestrictionsFilter}
*/
Expand All @@ -86,7 +110,9 @@ class OrthogonalRestrictionsFilterBuilder {
this.countryRestriction,
this.typeRestriction,
this.allowExpiredDocuments,
this.allowNonLatinDocuments
this.allowNonLatinDocuments,
this.allowDigitalIds,
this.allowedProviders
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ const IDVConstants = require('../../../../idv.constants');
const TypeRestriction = require('./type.restriction');
const CountryRestriction = require('./country.restriction');

/**
* @typedef {import('./../allowed.provider')} AllowedProvider
*/

class OrthogonalRestrictionsFilter extends DocumentFilter {
/**
* @param {CountryRestriction} countryRestriction
* @param {TypeRestriction} typeRestriction
* @param {Boolean} allowExpiredDocuments
* @param {Boolean} allowNonLatinDocuments
* @param {boolean} allowDigitalIds
* @param {AllowedProvider[]} allowedProviders
*/
constructor(countryRestriction, typeRestriction, allowExpiredDocuments, allowNonLatinDocuments) {
super(IDVConstants.ORTHOGONAL_RESTRICTIONS);
constructor(countryRestriction, typeRestriction, allowExpiredDocuments, allowNonLatinDocuments, allowDigitalIds, allowedProviders) {
super(IDVConstants.ORTHOGONAL_RESTRICTIONS, allowExpiredDocuments, allowNonLatinDocuments, allowDigitalIds, allowedProviders);

if (countryRestriction) {
Validation.instanceOf(countryRestriction, CountryRestriction, 'countryRestriction');
Expand All @@ -27,23 +33,17 @@ class OrthogonalRestrictionsFilter extends DocumentFilter {
/** @private */
this.typeRestriction = typeRestriction;
}

Validation.isBoolean(allowExpiredDocuments, 'allowExpiredDocuments', true);
/** @private */
this.allowExpiredDocuments = allowExpiredDocuments;

Validation.isBoolean(allowNonLatinDocuments, 'allowNonLatinDocuments', true);
/** @private */
this.allowNonLatinDocuments = allowNonLatinDocuments;
}

toJSON() {
const json = super.toJSON();

json.country_restriction = this.countryRestriction;
json.type_restriction = this.typeRestriction;
json.allow_expired_documents = this.allowExpiredDocuments;
json.allow_non_latin_documents = this.allowNonLatinDocuments;
json.allow_expired_documents = this.getAllowExpiredDocuments();
json.allow_non_latin_documents = this.getAllowNonLatinDocuments();
json.allow_digital_ids = this.getAllowDigitalIds();
json.allowed_providers = this.getAllowedProviders();

return json;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class SupportedDocumentResponse {
Validation.isString(supportedDocument.type, 'type');
/** @private */
this.type = supportedDocument.type;

if (supportedDocument.providers) {
Validation.isArrayOfStrings(supportedDocument.providers, 'providers');
/** @private */
this.providers = supportedDocument.providers;
}
}

/**
Expand All @@ -20,6 +26,15 @@ class SupportedDocumentResponse {
getType() {
return this.type;
}

/**
* Returns the digital ID providers supported for this document type.
*
* @return {string[] | null}
*/
getProviders() {
return this.providers;
}
}

module.exports = SupportedDocumentResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const Validation = require('../../../yoti_common/validation');

class DigitalIdShareErrorResponse {
constructor(errorResponse) {
Validation.isString(errorResponse.code, 'code', true);
/** @private */
this.code = errorResponse.code;

Validation.isString(errorResponse.description, 'description', true);
/** @private */
this.description = errorResponse.description;
}

getCode() {
return this.code;
}

getDescription() {
return this.description;
}
}

module.exports = DigitalIdShareErrorResponse;
Loading
Loading