Skip to content

Commit

Permalink
Merge pull request #278 from getyoti/release/3.16.0
Browse files Browse the repository at this point in the history
Release 3.16.0
  • Loading branch information
laurent-yoti authored Jun 30, 2021
2 parents 0807f0e + c79adf2 commit 5ec2f7e
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:

- run: npm audit --production

- run: set -o pipefail && npm audit --audit-level=high --parseable | awk -F $'\t' 'NF {print $2,"("$3") - "$4" - "$5" - "$6}' | awk '!visited[$0]++'

- run: npm test

- name: Fix code coverage paths
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The Yoti SDK can be used for the following products, follow the links for more i

## Support

For any questions or support please email [sdksupport@yoti.com](mailto:sdksupport@yoti.com).
For any questions or support please email [clientsupport@yoti.com](mailto:clientsupport@yoti.com).
Please provide the following to get you up and working as quickly as possible:

* Computer type
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yoti",
"version": "3.15.0",
"version": "3.16.0",
"description": "Yoti NodeJS SDK for back-end integration",
"author": "Yoti LTD <[email protected]> (https://www.yoti.com/developers)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.organization = getyoti

sonar.projectKey = getyoti:node
sonar.projectName = Node SDK
sonar.projectVersion = 3.15.0
sonar.projectVersion = 3.16.0
sonar.exclusions=tests/**,examples/**,node_modules/**,coverage/**
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.verbose = true
Expand Down
2 changes: 2 additions & 0 deletions src/doc_scan_service/doc.scan.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ module.exports = Object.freeze({
DESIRED: 'DESIRED',
IGNORE: 'IGNORE',
PROOF_OF_ADDRESS: 'PROOF_OF_ADDRESS',
BASIC: 'BASIC',
BEARER: 'BEARER',
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ class NotificationConfigBuilder {
return this;
}

/**
* Sets the authorization type as BASIC
*
* @returns {this}
*/
withAuthTypeBasic() {
this.authType = DocScanConstants.BASIC;
return this;
}

/**
* Sets the authorization type as BEARER
*
* @returns {this}
*/
withAuthTypeBearer() {
this.authType = DocScanConstants.BEARER;
return this;
}

/**
* Sets the endpoint that notifications should be sent to
*
Expand Down Expand Up @@ -101,7 +121,8 @@ class NotificationConfigBuilder {
return new NotificationConfig(
this.authToken,
this.endpoint,
this.topics
this.topics,
this.authType
);
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/doc_scan_service/session/create/notification.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use strict';

const DocScanConstants = require('../../doc.scan.constants');
const Validation = require('../../../yoti_common/validation');

const acceptedAuthTypes = [DocScanConstants.BASIC, DocScanConstants.BEARER];

/**
* Configures call-back Notifications to some backend endpoint provided
* by the Relying Business.
*
* Notifications can be configured to notified a client backend of certain
* events, avoiding the neeed to poll for the state of the Session.
* events, avoiding the need to poll for the state of the Session.
*
* @class NotificationConfig
*/
Expand All @@ -19,8 +22,10 @@ class NotificationConfig {
* The endpoint that notifications should be sent to
* @param {string[]} topics
* The list of topics that should trigger notifications
* @param {string} authType
* The authorization type to used in call-back messages, accepts BASIC, BEARER
*/
constructor(authToken, endpoint, topics) {
constructor(authToken, endpoint, topics, authType) {
Validation.isString(authToken, 'authToken', true);
this.authToken = authToken;

Expand All @@ -31,6 +36,12 @@ class NotificationConfig {
Validation.isArrayOfStrings(topics, 'topics');
this.topics = topics.filter((elem, pos) => topics.indexOf(elem) === pos);
}

Validation.isString(authType, 'authType', true);
if (authType) {
Validation.oneOf(authType, acceptedAuthTypes, 'authType');
this.authType = authType;
}
}

/**
Expand All @@ -39,6 +50,7 @@ class NotificationConfig {
toJSON() {
return {
auth_token: this.authToken,
auth_type: this.authType,
endpoint: this.endpoint,
topics: this.topics,
};
Expand Down
14 changes: 14 additions & 0 deletions src/yoti_common/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,18 @@ module.exports = class Validation {
throw TypeError(`${name} cannot be null or empty`);
}
}

/**
* @param {*} value
* @param {array} acceptedValues
* @param {string} name
*
* @throws {TypeError}
*/
static oneOf(value, acceptedValues, name) {
this.isArray(acceptedValues, 'acceptedValues');
if (!acceptedValues.includes(value)) {
throw Error(`${name} is not an accepted value`);
}
}
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
const {
NotificationConfigBuilder,
} = require('../../../../src/doc_scan_service');
const DocScanConstants = require('../../../../src/doc_scan_service/doc.scan.constants');

describe('NotificationConfigBuilder', () => {
it('should build NotificationConfig', () => {
const notificationConfig = new NotificationConfigBuilder()
.withEndpoint('some-endpoint')
.withAuthToken('some-auth-token')
.withAuthTypeBearer()
.withTopic('some-topic')
.withTopic('some-other-topic')
.build();

const expectedJson = JSON.stringify({
auth_token: 'some-auth-token',
auth_type: DocScanConstants.BEARER,
endpoint: 'some-endpoint',
topics: [
'some-topic',
Expand Down Expand Up @@ -103,4 +106,30 @@ describe('NotificationConfigBuilder', () => {

expect(JSON.stringify(notificationConfig)).toBe(expectedJson);
});

it('should build NotificationConfig with authType BEARER', () => {
const notificationConfig = new NotificationConfigBuilder()
.withAuthTypeBearer()
.build();

const expectedJson = JSON.stringify({
auth_type: DocScanConstants.BEARER,
topics: [],
});

expect(JSON.stringify(notificationConfig)).toBe(expectedJson);
});

it('should build NotificationConfig with authType BASIC', () => {
const notificationConfig = new NotificationConfigBuilder()
.withAuthTypeBasic()
.build();

const expectedJson = JSON.stringify({
auth_type: DocScanConstants.BASIC,
topics: [],
});

expect(JSON.stringify(notificationConfig)).toBe(expectedJson);
});
});
25 changes: 23 additions & 2 deletions tests/doc_scan_service/session/create/notification.config.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const DocScanConstants = require('../../../../src/doc_scan_service/doc.scan.constants');
const NotificationConfig = require('../../../../src/doc_scan_service/session/create/notification.config');

const SOME_AUTH_TOKEN = 'some-auth-token';
const SOME_ENDPOINT = 'some-endpoint';

describe('NotificationConfig', () => {
it('should serialize without topics', () => {
const notificationConfig = new NotificationConfig(SOME_AUTH_TOKEN, SOME_ENDPOINT);
it('should serialize without topics and no auth_type', () => {
const notificationConfig = new NotificationConfig(
SOME_AUTH_TOKEN,
SOME_ENDPOINT
);

const expectedJson = JSON.stringify({
auth_token: SOME_AUTH_TOKEN,
Expand All @@ -14,4 +18,21 @@ describe('NotificationConfig', () => {

expect(JSON.stringify(notificationConfig)).toBe(expectedJson);
});

it('should serialize with auth_type when provided', () => {
const notificationConfig = new NotificationConfig(
SOME_AUTH_TOKEN,
SOME_ENDPOINT,
undefined,
DocScanConstants.BEARER
);

const expectedJson = JSON.stringify({
auth_token: SOME_AUTH_TOKEN,
auth_type: DocScanConstants.BEARER,
endpoint: SOME_ENDPOINT,
});

expect(JSON.stringify(notificationConfig)).toBe(expectedJson);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
SdkConfigBuilder,
RequiredIdDocumentBuilder,
DocumentRestrictionsFilterBuilder,
} = require('../../../../');
} = require('../../../..');

describe('SessionSpecificationBuilder', () => {
it('should build SessionSpecification', () => {
Expand All @@ -20,6 +20,7 @@ describe('SessionSpecificationBuilder', () => {

const notificationConfig = new NotificationConfigBuilder()
.withEndpoint('some-endpoint')
.withAuthTypeBearer()
.build();

const textExtractionTask = new RequestedTextExtractionTaskBuilder()
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('SessionSpecificationBuilder', () => {
resources_ttl: 10,
user_tracking_id: 'some-tracking-id',
notifications: {
auth_type: 'BEARER',
endpoint: 'some-endpoint',
topics: [],
},
Expand Down
26 changes: 26 additions & 0 deletions tests/yoti_common/validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,30 @@ describe('Validation', () => {
.toThrow(new TypeError('name cannot be null or empty'));
});
});

describe('#oneOf', () => {
const acceptedValues = ['abc', 'def', 123];
describe('valid cases', () => {
test.each([
['abc'],
['def'],
[123],
])('should not throw error as value is an accepted one', (value) => {
expect(() => Validation.oneOf(value, acceptedValues, 'name'))
.not.toThrow();
});
});
describe('invalid cases', () => {
test.each([
[''],
[null],
['ab'],
[12],
['123'],
])('should throw error as value is not an accepted one', (value) => {
expect(() => Validation.oneOf(value, acceptedValues, 'name'))
.toThrow(new Error('name is not an accepted value'));
});
});
});
});

0 comments on commit 5ec2f7e

Please sign in to comment.