Skip to content

Commit c43189e

Browse files
authored
SDK-2477 IDV Session retrieve and delete device metadata (#494)
* IDV: added getSessionTrackedDevices to retrieve the devices (includes responses) in service and exposed them in client * IDV: added deleteSessionTrackedDevices in both client and service
1 parent f834631 commit c43189e

15 files changed

+936
-0
lines changed

src/client/idv.client.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,30 @@ class IDVClient {
155155
getSessionConfiguration(sessionId) {
156156
return this.idvService.getSessionConfiguration(sessionId);
157157
}
158+
159+
/**
160+
* Fetches the tracked devices for the given sessionID.
161+
*
162+
* @param {string} sessionId
163+
*
164+
* @typedef {import('../idv_service/session/retrieve/devices/session.tracked.devices.response')} SessionTrackedDevicesResponse
165+
*
166+
* @returns {Promise<SessionTrackedDevicesResponse>}
167+
*/
168+
getSessionTrackedDevices(sessionId) {
169+
return this.idvService.getSessionTrackedDevices(sessionId);
170+
}
171+
172+
/**
173+
* Deletes the tracked devices for given sessionID.
174+
*
175+
* @param {string} sessionId
176+
*
177+
* @returns {Promise<void>}
178+
*/
179+
deleteSessionTrackedDevices(sessionId) {
180+
return this.idvService.deleteSessionTrackedDevices(sessionId);
181+
}
158182
}
159183

160184
module.exports = IDVClient;

src/idv_service/idv.service.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const CreateFaceCaptureResourceResponse = require('./session/retrieve/create.fac
1515
const CreateFaceCaptureResourcePayload = require('./session/create/face_capture/create.face.capture.resource.payload');
1616
const UploadFaceCaptureImagePayload = require('./session/create/face_capture/upload.face.capture.image.payload');
1717
const SessionConfigurationResponse = require('./session/retrieve/configuration/session.configuration.response');
18+
const SessionTrackedDevicesResponse = require('./session/retrieve/devices/session.tracked.devices.response');
1819

1920
const DEFAULT_API_URL = config.yoti.idvApi;
2021

@@ -309,6 +310,8 @@ class IDVService {
309310
* @returns {Promise<SessionConfigurationResponse>}
310311
*/
311312
getSessionConfiguration(sessionId) {
313+
Validation.isString(sessionId, 'sessionId');
314+
312315
const request = new RequestBuilder()
313316
.withPemString(this.pem.toString())
314317
.withBaseUrl(this.apiUrl)
@@ -323,6 +326,55 @@ class IDVService {
323326
.catch((err) => reject(new IDVError(err)));
324327
});
325328
}
329+
330+
/**
331+
* @param {string} sessionId
332+
*
333+
* @returns {Promise<SessionTrackedDevicesResponse>}
334+
*/
335+
getSessionTrackedDevices(sessionId) {
336+
Validation.isString(sessionId, 'sessionId');
337+
338+
const request = new RequestBuilder()
339+
.withPemString(this.pem.toString())
340+
.withBaseUrl(this.apiUrl)
341+
.withEndpoint(`/sessions/${sessionId}/tracked-devices`)
342+
.withQueryParam('sdkId', this.sdkId)
343+
.withGet()
344+
.build();
345+
346+
return new Promise((resolve, reject) => {
347+
request.execute()
348+
// eslint-disable-next-line max-len
349+
.then((response) => resolve(new SessionTrackedDevicesResponse(response.getParsedResponse())))
350+
.catch((err) => reject(new IDVError(err)));
351+
});
352+
}
353+
354+
/**
355+
* Deletes tracked devices for a given session
356+
*
357+
* @param {string} sessionId
358+
*
359+
* @returns {Promise}
360+
*/
361+
deleteSessionTrackedDevices(sessionId) {
362+
Validation.isString(sessionId, 'sessionId');
363+
364+
const request = new RequestBuilder()
365+
.withPemString(this.pem.toString())
366+
.withBaseUrl(this.apiUrl)
367+
.withEndpoint(`/sessions/${sessionId}/tracked-devices`)
368+
.withQueryParam('sdkId', this.sdkId)
369+
.withMethod('DELETE')
370+
.build();
371+
372+
return new Promise((resolve, reject) => {
373+
request.execute(true)
374+
.then(() => resolve())
375+
.catch((err) => reject(new IDVError(err)));
376+
});
377+
}
326378
}
327379

328380
module.exports = IDVService;
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
'use strict';
2+
3+
const Validation = require('../../../../yoti_common/validation');
4+
5+
class DeviceDescriptionResponse {
6+
constructor(payload) {
7+
Validation.isString(payload.ip_address, 'ip_address', true);
8+
/** @private */
9+
this.ipAddress = payload.ip_address;
10+
11+
Validation.isString(payload.ip_iso_country_code, 'ip_iso_country_code', true);
12+
/** @private */
13+
this.ipISOCountryCode = payload.ip_iso_country_code;
14+
15+
Validation.isString(payload.manufacture_name, 'manufacture_name', true);
16+
/** @private */
17+
this.manufactureName = payload.manufacture_name;
18+
19+
Validation.isString(payload.model_name, 'model_name', true);
20+
/** @private */
21+
this.modelName = payload.model_name;
22+
23+
Validation.isString(payload.os_name, 'os_name', true);
24+
/** @private */
25+
this.osName = payload.os_name;
26+
27+
Validation.isString(payload.os_version, 'os_version', true);
28+
/** @private */
29+
this.osVersion = payload.os_version;
30+
31+
Validation.isString(payload.browser_name, 'browser_name', true);
32+
/** @private */
33+
this.browserName = payload.browser_name;
34+
35+
Validation.isString(payload.browser_version, 'browser_version', true);
36+
/** @private */
37+
this.browserVersion = payload.browser_version;
38+
39+
Validation.isString(payload.locale, 'locale', true);
40+
/** @private */
41+
this.locale = payload.locale;
42+
43+
Validation.isString(payload.client_version, 'client_version');
44+
/** @private */
45+
this.clientVersion = payload.client_version;
46+
}
47+
48+
/**
49+
* Returns the device ip address.
50+
*
51+
* @returns {string | undefined}
52+
*/
53+
getIpAddress() {
54+
return this.ipAddress;
55+
}
56+
57+
/**
58+
* Returns the device ip ISO country code.
59+
*
60+
* @returns {string | undefined}
61+
*/
62+
getIpISOCountryCode() {
63+
return this.ipISOCountryCode;
64+
}
65+
66+
/**
67+
* Returns the device manufacture name.
68+
*
69+
* @returns {string | undefined}
70+
*/
71+
getManufactureName() {
72+
return this.manufactureName;
73+
}
74+
75+
/**
76+
* Returns the device model name.
77+
*
78+
* @returns {string | undefined}
79+
*/
80+
getModelName() {
81+
return this.modelName;
82+
}
83+
84+
/**
85+
* Returns the device OS name.
86+
*
87+
* @returns {string | undefined}
88+
*/
89+
getOSName() {
90+
return this.osName;
91+
}
92+
93+
/**
94+
* Returns the device OS version.
95+
*
96+
* @returns {string | undefined}
97+
*/
98+
getOSVersion() {
99+
return this.osVersion;
100+
}
101+
102+
/**
103+
* Returns the device browser name.
104+
*
105+
* @returns {string | undefined}
106+
*/
107+
getBrowserName() {
108+
return this.browserName;
109+
}
110+
111+
/**
112+
* Returns the device browser version.
113+
*
114+
* @returns {string | undefined}
115+
*/
116+
getBrowserVersion() {
117+
return this.browserVersion;
118+
}
119+
120+
/**
121+
* Returns the device locale.
122+
*
123+
* @returns {string | undefined}
124+
*/
125+
getLocale() {
126+
return this.locale;
127+
}
128+
129+
/**
130+
* Returns the client version.
131+
*
132+
* @returns {string}
133+
*/
134+
getClientVersion() {
135+
return this.clientVersion;
136+
}
137+
}
138+
139+
module.exports = DeviceDescriptionResponse;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const Validation = require('../../../../yoti_common/validation');
4+
const TrackedDeviceEventResponse = require('./tracked.device.event.response');
5+
6+
class TrackedDevicesResponse {
7+
/**
8+
* @param {{}[]} response
9+
*/
10+
constructor(response) {
11+
Validation.isArray(response, 'tracked devices');
12+
/** @private */
13+
this.deviceEvents = response.map((item) => new TrackedDeviceEventResponse(item));
14+
}
15+
16+
/**
17+
* Returns the list of tracked device events.
18+
*
19+
* @returns {TrackedDeviceEventResponse[]}
20+
*/
21+
getDeviceEvents() {
22+
return this.deviceEvents;
23+
}
24+
}
25+
26+
module.exports = TrackedDevicesResponse;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
const Validation = require('../../../../yoti_common/validation');
4+
const DeviceDescriptionResponse = require('./device.description.response');
5+
6+
class TrackedDeviceEventResponse {
7+
constructor(payload) {
8+
Validation.isString(payload.event, 'event');
9+
/** @private */
10+
this.event = payload.event;
11+
12+
Validation.isStringDate(payload.created, 'created');
13+
/** @private */
14+
this.created = new Date(payload.created);
15+
16+
Validation.isPlainObject(payload.device, 'device');
17+
/** @private */
18+
this.device = new DeviceDescriptionResponse(payload.device);
19+
}
20+
21+
/**
22+
* Returns the event.
23+
*
24+
* @returns {string}
25+
*/
26+
getEvent() {
27+
return this.event;
28+
}
29+
30+
/**
31+
* Returns the created date.
32+
*
33+
* @returns {Date}
34+
*/
35+
getCreated() {
36+
return this.created;
37+
}
38+
39+
/**
40+
* Returns the device description.
41+
*
42+
* @returns {DeviceDescriptionResponse}
43+
*/
44+
getDevice() {
45+
return this.device;
46+
}
47+
}
48+
49+
module.exports = TrackedDeviceEventResponse;

0 commit comments

Comments
 (0)