Skip to content

Commit

Permalink
idv: added getSessionTrackedDevices to retrieve the devices (includes…
Browse files Browse the repository at this point in the history
… responses) in service and exposed them in client
  • Loading branch information
laurent-yoti committed Sep 20, 2024
1 parent f834631 commit 818144a
Show file tree
Hide file tree
Showing 15 changed files with 810 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/client/idv.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ class IDVClient {
getSessionConfiguration(sessionId) {
return this.idvService.getSessionConfiguration(sessionId);
}

/**
* Fetches the tracked devices for the given sessionID.
*
* @param {string} sessionId
*
* @typedef {import('../idv_service/session/retrieve/devices/session.tracked.devices.response')} SessionTrackedDevicesResponse
*
* @returns {Promise<SessionTrackedDevicesResponse>}
*/
getSessionTrackedDevices(sessionId) {
return this.idvService.getSessionTrackedDevices(sessionId);
}
}

module.exports = IDVClient;
23 changes: 23 additions & 0 deletions src/idv_service/idv.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CreateFaceCaptureResourceResponse = require('./session/retrieve/create.fac
const CreateFaceCaptureResourcePayload = require('./session/create/face_capture/create.face.capture.resource.payload');
const UploadFaceCaptureImagePayload = require('./session/create/face_capture/upload.face.capture.image.payload');
const SessionConfigurationResponse = require('./session/retrieve/configuration/session.configuration.response');
const SessionTrackedDevicesResponse = require('./session/retrieve/devices/session.tracked.devices.response');

const DEFAULT_API_URL = config.yoti.idvApi;

Expand Down Expand Up @@ -323,6 +324,28 @@ class IDVService {
.catch((err) => reject(new IDVError(err)));
});
}

/**
* @param {string} sessionId
*
* @returns {Promise<SessionTrackedDevicesResponse>}
*/
getSessionTrackedDevices(sessionId) {
const request = new RequestBuilder()
.withPemString(this.pem.toString())
.withBaseUrl(this.apiUrl)
.withEndpoint(`/sessions/${sessionId}/tracked-devices`)
.withQueryParam('sdkId', this.sdkId)
.withGet()
.build();

return new Promise((resolve, reject) => {
request.execute()
// eslint-disable-next-line max-len
.then((response) => resolve(new SessionTrackedDevicesResponse(response.getParsedResponse())))
.catch((err) => reject(new IDVError(err)));
});
}
}

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

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

class DeviceDescriptionResponse {
constructor(payload) {
Validation.isString(payload.ip_address, 'ip_address', true);
/** @private */
this.ipAddress = payload.ip_address;

Validation.isString(payload.ip_iso_country_code, 'ip_iso_country_code', true);
/** @private */
this.ipISOCountryCode = payload.ip_iso_country_code;

Validation.isString(payload.manufacture_name, 'manufacture_name', true);
/** @private */
this.manufactureName = payload.manufacture_name;

Validation.isString(payload.model_name, 'model_name', true);
/** @private */
this.modelName = payload.model_name;

Validation.isString(payload.os_name, 'os_name', true);
/** @private */
this.osName = payload.os_name;

Validation.isString(payload.os_version, 'os_version', true);
/** @private */
this.osVersion = payload.os_version;

Validation.isString(payload.browser_name, 'browser_name', true);
/** @private */
this.browserName = payload.browser_name;

Validation.isString(payload.browser_version, 'browser_version', true);
/** @private */
this.browserVersion = payload.browser_version;

Validation.isString(payload.locale, 'locale', true);
/** @private */
this.locale = payload.locale;

Validation.isString(payload.client_version, 'client_version');
/** @private */
this.clientVersion = payload.client_version;
}

/**
* Returns the device ip address.
*
* @returns {string | undefined}
*/
getIpAddress() {
return this.ipAddress;
}

/**
* Returns the device ip ISO country code.
*
* @returns {string | undefined}
*/
getIpISOCountryCode() {
return this.ipISOCountryCode;
}

/**
* Returns the device manufacture name.
*
* @returns {string | undefined}
*/
getManufactureName() {
return this.manufactureName;
}

/**
* Returns the device model name.
*
* @returns {string | undefined}
*/
getModelName() {
return this.modelName;
}

/**
* Returns the device OS name.
*
* @returns {string | undefined}
*/
getOSName() {
return this.osName;
}

/**
* Returns the device OS version.
*
* @returns {string | undefined}
*/
getOSVersion() {
return this.osVersion;
}

/**
* Returns the device browser name.
*
* @returns {string | undefined}
*/
getBrowserName() {
return this.browserName;
}

/**
* Returns the device browser version.
*
* @returns {string | undefined}
*/
getBrowserVersion() {
return this.browserVersion;
}

/**
* Returns the device locale.
*
* @returns {string | undefined}
*/
getLocale() {
return this.locale;
}

/**
* Returns the client version.
*
* @returns {string}
*/
getClientVersion() {
return this.clientVersion;
}
}

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

const Validation = require('../../../../yoti_common/validation');
const TrackedDeviceEventResponse = require('./tracked.device.event.response');

class TrackedDevicesResponse {
/**
* @param {{}[]} response
*/
constructor(response) {
Validation.isArray(response, 'tracked devices');
/** @private */
this.deviceEvents = response.map((item) => new TrackedDeviceEventResponse(item));
}

/**
* Returns the list of tracked device events.
*
* @returns {TrackedDeviceEventResponse[]}
*/
getDeviceEvents() {
return this.deviceEvents;
}
}

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

const Validation = require('../../../../yoti_common/validation');
const DeviceDescriptionResponse = require('./device.description.response');

class TrackedDeviceEventResponse {
constructor(payload) {
Validation.isString(payload.event, 'event');
/** @private */
this.event = payload.event;

Validation.isStringDate(payload.created, 'created');
/** @private */
this.created = new Date(payload.created);

Validation.isPlainObject(payload.device, 'device');
/** @private */
this.device = new DeviceDescriptionResponse(payload.device);
}

/**
* Returns the event.
*
* @returns {string}
*/
getEvent() {
return this.event;
}

/**
* Returns the created date.
*
* @returns {Date}
*/
getCreated() {
return this.created;
}

/**
* Returns the device description.
*
* @returns {DeviceDescriptionResponse}
*/
getDevice() {
return this.device;
}
}

module.exports = TrackedDeviceEventResponse;
48 changes: 48 additions & 0 deletions tests/client/idv.client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const GetSessionResult = require('../../src/idv_service/session/retrieve/get.ses
const Media = require('../../src/data_type/media');
const SupportedDocumentResponse = require('../../src/idv_service/support/supported.documents.response');
const SessionConfigurationResponse = require('../../src/idv_service/session/retrieve/configuration/session.configuration.response');
const SessionTrackedDevicesResponse = require('../../src/idv_service/session/retrieve/devices/session.tracked.devices.response');
const CaptureResponse = require('../../src/idv_service/session/retrieve/configuration/capture/capture.response');
const CreateFaceCaptureResourceResponse = require('../../src/idv_service/session/retrieve/create.face.capture.resource.response');

Expand Down Expand Up @@ -51,6 +52,7 @@ describe.each([
const sessionMediaUriRegExp = new RegExp(`${apiUrlPath}/sessions/${SESSION_ID}/media/${MEDIA_ID}/content\\?sdkId=${APP_ID}`);
const supportedDocumentsUriRegExp = new RegExp(`${apiUrlPath}/supported-documents`);
const sessionConfigUriRegExp = new RegExp(`/sessions/${SESSION_ID}/configuration`);
const sessionTrackedDevicesUriRegExp = new RegExp(`/sessions/${SESSION_ID}/tracked-devices`);
const faceCaptureCreateUri = new RegExp(`^/idverify/v1/sessions/${SESSION_ID}/resources/face-capture`);
const uploadFaceCaptureImageUri = new RegExp(`^/idverify/v1/sessions/${SESSION_ID}/resources/face-capture/${RESOURCE_ID}/image`);

Expand Down Expand Up @@ -265,6 +267,52 @@ describe.each([
});
});

describe('#getSessionTrackedDevices', () => {
const setupResponse = (responseBody, responseStatusCode = 200) => {
nock(apiUrlDomain)
.get(sessionTrackedDevicesUriRegExp)
.reply(responseStatusCode, responseBody);
};

beforeEach(() => {
setupResponse(JSON.stringify([
{
event: 'CONFIG_FIRST_LOADED',
created: '2021-06-11T11:39:24Z',
device: {
client_version: '2.12.0',
},
},
{
event: 'RESOURCE_CREATED',
resource_id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
created: '2021-06-11T11:39:24Z',
device: {
client_version: '2.12.0',
},
},
{
event: 'CLIENT_SESSION_TOKEN_DELETED',
created: '2021-06-11T11:39:24Z',
device: {
client_version: '2.12.0',
},
},
]));
});

it('should return an IDV session tracked devices', (done) => {
idvClient
.getSessionTrackedDevices(SESSION_ID)
.then((result) => {
expect(result).toBeInstanceOf(SessionTrackedDevicesResponse);
expect(result.getDeviceEvents()).toHaveLength(3);
done();
})
.catch(done);
});
});

describe('#createFaceCaptureResource', () => {
const createFaceCaptureResourcePayload = new CreateFaceCaptureResourcePayloadBuilder().withRequirementId('abc').build();

Expand Down
Loading

0 comments on commit 818144a

Please sign in to comment.