-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdevice.ts
More file actions
60 lines (56 loc) · 1.79 KB
/
device.ts
File metadata and controls
60 lines (56 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { isIP } from 'net';
import { ArgumentError } from '../errors';
interface DeviceProps {
/**
* The IP address associated with the device used by the customer in the
* transaction.
*/
ipAddress?: string;
/**
* The HTTP “User-Agent” header of the browser used in the transaction.
*/
userAgent?: string;
/**
* The HTTP “Accept-Language” header of the device used in the transaction.
*/
acceptLanguage?: string;
/**
* The number of seconds between the creation of the user's session and the
* time of the transaction. Note that sessionAge is not the duration of the
* current visit, but the time since the start of the first visit.
*/
sessionAge?: number;
/**
* A string up to 255 characters in length. This is an ID that uniquely
* identifies a visitor's session on the site.
*/
sessionId?: string;
/**
* The tracking token from the Device Tracking Add-on for explicit device
* linking.
*/
trackingToken?: string;
}
/**
* The device information for the transaction being sent to the web service.
*/
export default class Device implements DeviceProps {
/** @inheritDoc DeviceProps.ipAddress */
public ipAddress?: string;
/** @inheritDoc DeviceProps.userAgent */
public userAgent?: string;
/** @inheritDoc DeviceProps.acceptLanguage */
public acceptLanguage?: string;
/** @inheritDoc DeviceProps.sessionAge */
public sessionAge?: number;
/** @inheritDoc DeviceProps.sessionId */
public sessionId?: string;
/** @inheritDoc DeviceProps.trackingToken */
public trackingToken?: string;
public constructor(device: DeviceProps) {
if (device.ipAddress != null && isIP(device.ipAddress) === 0) {
throw new ArgumentError('`device.ipAddress` is an invalid IP address');
}
Object.assign(this, device);
}
}