Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-2477 IDV Session retrieve and delete device metadata #494

Merged
merged 2 commits into from
Oct 4, 2024
Merged
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
24 changes: 24 additions & 0 deletions src/client/idv.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ 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);
}

/**
* Deletes the tracked devices for given sessionID.
*
* @param {string} sessionId
*
* @returns {Promise<void>}
*/
deleteSessionTrackedDevices(sessionId) {
return this.idvService.deleteSessionTrackedDevices(sessionId);
}
}

module.exports = IDVClient;
52 changes: 52 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 @@ -309,6 +310,8 @@ class IDVService {
* @returns {Promise<SessionConfigurationResponse>}
*/
getSessionConfiguration(sessionId) {
Validation.isString(sessionId, 'sessionId');

const request = new RequestBuilder()
.withPemString(this.pem.toString())
.withBaseUrl(this.apiUrl)
Expand All @@ -323,6 +326,55 @@ class IDVService {
.catch((err) => reject(new IDVError(err)));
});
}

/**
* @param {string} sessionId
*
* @returns {Promise<SessionTrackedDevicesResponse>}
*/
getSessionTrackedDevices(sessionId) {
Validation.isString(sessionId, '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)));
});
}

/**
* Deletes tracked devices for a given session
*
* @param {string} sessionId
*
* @returns {Promise}
*/
deleteSessionTrackedDevices(sessionId) {
Validation.isString(sessionId, 'sessionId');

const request = new RequestBuilder()
.withPemString(this.pem.toString())
.withBaseUrl(this.apiUrl)
.withEndpoint(`/sessions/${sessionId}/tracked-devices`)
.withQueryParam('sdkId', this.sdkId)
.withMethod('DELETE')
.build();

return new Promise((resolve, reject) => {
request.execute(true)
.then(() => resolve())
.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;
Loading