@tinkoff/user-agent 0.7.204 → 0.8.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +190 -1
  2. package/lib/client-hints/constants.d.ts +7 -0
  3. package/lib/client-hints/constants.es.js +23 -0
  4. package/lib/client-hints/constants.js +32 -0
  5. package/lib/client-hints/parse-client-hints-headers/consts.d.ts +11 -0
  6. package/lib/client-hints/parse-client-hints-headers/consts.es.js +11 -0
  7. package/lib/client-hints/parse-client-hints-headers/consts.js +15 -0
  8. package/lib/client-hints/parse-client-hints-headers/parseClientHintsHeaders.d.ts +18 -0
  9. package/lib/client-hints/parse-client-hints-headers/parseClientHintsHeaders.es.js +54 -0
  10. package/lib/client-hints/parse-client-hints-headers/parseClientHintsHeaders.js +58 -0
  11. package/lib/client-hints/parse-client-hints-user-agent-data/parseClientHintsUserAgentData.d.ts +17 -0
  12. package/lib/client-hints/parse-client-hints-user-agent-data/parseClientHintsUserAgentData.es.js +47 -0
  13. package/lib/client-hints/parse-client-hints-user-agent-data/parseClientHintsUserAgentData.js +51 -0
  14. package/lib/client-hints/utils/getBackwardCompatibleOsName.d.ts +2 -0
  15. package/lib/client-hints/utils/getBackwardCompatibleOsName.es.js +10 -0
  16. package/lib/client-hints/utils/getBackwardCompatibleOsName.js +14 -0
  17. package/lib/client-hints/utils/parseBrowserFromString.d.ts +6 -0
  18. package/lib/client-hints/utils/parseBrowserFromString.es.js +42 -0
  19. package/lib/client-hints/utils/parseBrowserFromString.js +46 -0
  20. package/lib/client-hints/utils/parseBrowserFromUserAgentData.d.ts +6 -0
  21. package/lib/client-hints/utils/parseBrowserFromUserAgentData.es.js +39 -0
  22. package/lib/client-hints/utils/parseBrowserFromUserAgentData.js +43 -0
  23. package/lib/client-hints/utils/parseQuotedString.d.ts +2 -0
  24. package/lib/client-hints/utils/parseQuotedString.es.js +18 -0
  25. package/lib/client-hints/utils/parseQuotedString.js +22 -0
  26. package/lib/constants.d.ts +15 -7
  27. package/lib/constants.es.js +16 -81
  28. package/lib/constants.js +18 -87
  29. package/lib/index.d.ts +7 -5
  30. package/lib/index.es.js +5 -3
  31. package/lib/index.js +12 -8
  32. package/lib/parse-user-agent-header/consts.d.ts +2 -0
  33. package/lib/parse-user-agent-header/consts.es.js +27 -0
  34. package/lib/parse-user-agent-header/consts.js +31 -0
  35. package/lib/{userAgent.d.ts → parse-user-agent-header/parseUserAgentHeader.d.ts} +2 -2
  36. package/lib/{userAgent.es.js → parse-user-agent-header/parseUserAgentHeader.es.js} +7 -9
  37. package/lib/parse-user-agent-header/parseUserAgentHeader.js +35 -0
  38. package/lib/{isSameSiteNoneCompatible.es.js → parse-user-agent-header/utils/is-same-site-none-compatible/isSameSiteNoneCompatible.es.js} +6 -1
  39. package/lib/{isSameSiteNoneCompatible.js → parse-user-agent-header/utils/is-same-site-none-compatible/isSameSiteNoneCompatible.js} +6 -1
  40. package/lib/{utils/merge-extensions.d.ts → parse-user-agent-header/utils/mergeExtensions.d.ts} +2 -2
  41. package/lib/{utils/merge-extensions.es.js → parse-user-agent-header/utils/mergeExtensions.es.js} +1 -1
  42. package/lib/{utils/merge-extensions.js → parse-user-agent-header/utils/mergeExtensions.js} +3 -3
  43. package/lib/parse-user-agent-header/utils/toLowerName.d.ts +2 -0
  44. package/lib/parse-user-agent-header/utils/toLowerName.es.js +14 -0
  45. package/lib/parse-user-agent-header/utils/toLowerName.js +24 -0
  46. package/lib/satisfies/constants.d.ts +16 -0
  47. package/lib/satisfies/constants.es.js +75 -0
  48. package/lib/satisfies/constants.js +82 -0
  49. package/lib/satisfies/is-browser-satisfies-requirements.d.ts +4 -0
  50. package/lib/satisfies/is-browser-satisfies-requirements.es.js +74 -0
  51. package/lib/satisfies/is-browser-satisfies-requirements.js +84 -0
  52. package/lib/satisfies/types.d.ts +6 -0
  53. package/lib/satisfies/utils/normalizeBrowserslist.d.ts +3 -0
  54. package/lib/satisfies/utils/normalizeBrowserslist.es.js +42 -0
  55. package/lib/satisfies/utils/normalizeBrowserslist.js +50 -0
  56. package/lib/types.d.ts +4 -0
  57. package/lib/utils/getBrowserEngine.d.ts +9 -0
  58. package/lib/utils/{get-browser-engine.es.js → getBrowserEngine.es.js} +13 -4
  59. package/lib/utils/{get-browser-engine.js → getBrowserEngine.js} +13 -4
  60. package/lib/utils/getMobileOs.d.ts +9 -0
  61. package/lib/utils/getMobileOs.es.js +24 -0
  62. package/lib/utils/getMobileOs.js +28 -0
  63. package/package.json +3 -3
  64. package/lib/client-hints.d.ts +0 -33
  65. package/lib/client-hints.es.js +0 -178
  66. package/lib/client-hints.js +0 -183
  67. package/lib/satisfies.d.ts +0 -8
  68. package/lib/satisfies.es.js +0 -107
  69. package/lib/satisfies.js +0 -118
  70. package/lib/userAgent.js +0 -43
  71. package/lib/utils/get-browser-engine.d.ts +0 -2
  72. package/lib/utils/get-mobile-os.d.ts +0 -2
  73. package/lib/utils/get-mobile-os.es.js +0 -15
  74. package/lib/utils/get-mobile-os.js +0 -19
  75. /package/lib/{isSameSiteNoneCompatible.d.ts → parse-user-agent-header/utils/is-same-site-none-compatible/isSameSiteNoneCompatible.d.ts} +0 -0
  76. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/bots.txt +0 -0
  77. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/not_supported.txt +0 -0
  78. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/not_supported_modern.txt +0 -0
  79. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/supported.txt +0 -0
  80. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/supported_force.txt +0 -0
  81. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/supported_modern.txt +0 -0
  82. /package/lib/{__tests__ → satisfies/__tests__}/uaDatasets/unknown.txt +0 -0
package/README.md CHANGED
@@ -1,5 +1,194 @@
1
1
  # User agent
2
2
 
3
- Library for parsing and executing checks by:
3
+ A set of methods for parsing userAgent and getting browser data. Library for parsing and executing checks by:
4
+
4
5
  - userAgent string. Based on [ua-parser-js](https://github.com/faisalman/ua-parser-js)
5
6
  - [Client Hints](https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints) headers
7
+
8
+ ## parseClientHintsHeaders
9
+
10
+ Used on the **server** to supplement information from ClientHints headers (`sec-ch-ua`). The parseClientHintsUserAgentData method constructs an object with information based on the headers, enriches it with browser details, fills in additional fields, and ensures backward compatibility in naming. Essentially, it performs data preparation and some data hygiene. For example, when parsing headers with low entropy,
11
+
12
+ ```tsx
13
+ const headers = {
14
+ 'sec-ch-ua': '"Chromium";v="106", "Google Chrome";v="106", "Not;A=Brand";v="99"',
15
+ 'sec-ch-ua-mobile': '?0',
16
+ 'sec-ch-ua-platform': '"Windows"',
17
+ };
18
+ ```
19
+
20
+ We get
21
+
22
+ ```tsx
23
+ const userAgent = {
24
+ browser: {
25
+ browserEngine: 'chrome',
26
+ major: '106',
27
+ name: 'chrome',
28
+ version: '106',
29
+ },
30
+ cpu: {
31
+ architecture: undefined,
32
+ },
33
+ device: {
34
+ model: undefined,
35
+ type: 'desktop',
36
+ vendor: undefined,
37
+ },
38
+ engine: {
39
+ name: 'Blink',
40
+ version: '106',
41
+ },
42
+ mobileOS: undefined,
43
+ os: {
44
+ name: 'Windows',
45
+ version: undefined,
46
+ },
47
+ sameSiteNoneCompatible: true,
48
+ };
49
+ ```
50
+
51
+ When parsing headers with high entropy,
52
+
53
+ ```tsx
54
+ const headers = {
55
+ 'sec-ch-ua-full-version-list':
56
+ '"Not.A/Brand";v="8.0.0.0", "Chromium";v="110.0.5481.100", "Google Chrome";v="110.0.5481.100"',
57
+ 'sec-ch-ua-platform-version': '"10.0.19044.2364"',
58
+ 'sec-ch-ua-arch': '"x86_64"',
59
+ 'sec-ch-ua-model': '"iPhone 13"',
60
+ };
61
+ ```
62
+
63
+ We get
64
+
65
+ ```tsx
66
+ const userAgent = {
67
+ browser: {
68
+ browserEngine: 'chrome',
69
+ major: '110.0.5481.100',
70
+ name: 'chrome',
71
+ version: '110.0.5481.100',
72
+ },
73
+ cpu: {
74
+ architecture: 'x86_64',
75
+ },
76
+ device: {
77
+ model: 'iPhone 13',
78
+ type: 'desktop',
79
+ vendor: undefined,
80
+ },
81
+ engine: {
82
+ name: 'Blink',
83
+ version: '110.0.5481.100',
84
+ },
85
+ mobileOS: undefined,
86
+ os: {
87
+ name: undefined,
88
+ version: '10.0.19044.2364',
89
+ },
90
+ sameSiteNoneCompatible: true,
91
+ };
92
+ ```
93
+
94
+ ## parseClientHintsUserAgentData
95
+
96
+ Used on the **client** to supplement information from navigator.userAgentData.
97
+
98
+ The parseClientHintsUserAgentData method enriches the object with browser information, fills in additional fields, and ensures backward compatibility in naming. Essentially, it performs data preparation and some data hygiene.
99
+
100
+ For example, when parsing:
101
+
102
+ ```tsx
103
+ const userAgentData = {
104
+ brands: [
105
+ {
106
+ brand: 'Not.A/Brand',
107
+ version: '8',
108
+ },
109
+ {
110
+ brand: 'Chromium',
111
+ version: '114',
112
+ },
113
+ {
114
+ brand: 'Google Chrome',
115
+ version: '114',
116
+ },
117
+ ],
118
+ mobile: true,
119
+ platform: 'Android',
120
+ };
121
+ ```
122
+
123
+ We get
124
+
125
+ ```tsx
126
+ const userAgent = {
127
+ browser: {
128
+ browserEngine: 'chrome',
129
+ major: '114',
130
+ name: 'chrome',
131
+ version: '114',
132
+ },
133
+ cpu: {
134
+ architecture: undefined,
135
+ },
136
+ device: {
137
+ model: undefined,
138
+ type: 'mobile',
139
+ vendor: undefined,
140
+ },
141
+ engine: {
142
+ name: 'Blink',
143
+ version: '114',
144
+ },
145
+ mobileOS: 'android',
146
+ os: {
147
+ name: 'Android',
148
+ version: undefined,
149
+ },
150
+ sameSiteNoneCompatible: true,
151
+ };
152
+ ```
153
+
154
+ ## parseUserAgentHeader
155
+
156
+ Used in the following cases:
157
+
158
+ - Headers are unavailable on the **server**.
159
+ - There were errors in obtaining navigator.userAgentData on the **client**.
160
+
161
+ The parseUserAgentHeader method parses the userAgent string and returns an object with browser data. For example, when parsing `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36` We get
162
+
163
+ ```tsx
164
+ const userAgent = {
165
+ browser: {
166
+ browserEngine: 'chrome',
167
+ major: '83',
168
+ name: 'chrome',
169
+ version: '83.0.4103.61',
170
+ },
171
+ cpu: {
172
+ architecture: undefined,
173
+ },
174
+ device: {
175
+ model: undefined,
176
+ type: undefined,
177
+ vendor: undefined,
178
+ },
179
+ engine: {
180
+ name: 'Blink',
181
+ version: '83.0.4103.61',
182
+ },
183
+ mobileOS: undefined,
184
+ os: {
185
+ name: 'Mac OS',
186
+ version: '10.15.4',
187
+ },
188
+ sameSiteNoneCompatible: true,
189
+ };
190
+ ```
191
+
192
+ ## isBrowserSatisfiesRequirements
193
+
194
+ The function isBrowserSatisfiesRequirements checks if a given user agent satisfies the specified browser requirements based on a browserslist configuration. It parses the user agent to determine the browser and its version, normalizes the browserslist configuration, and compares the browser version against the specified requirements. The function returns true if the browser meets the requirements, false if it does not, and null if the browser is not found in the browserslist. It also handles special cases for Chromium-based browsers and allows forcing the use of minimum requested versions for browsers with incomplete statistics.
@@ -0,0 +1,7 @@
1
+ export declare const KNOWN_VENDORS: Set<string>;
2
+ export declare const KNOWN_ENGINES: Set<string>;
3
+ export declare const BACKWARD_COMPATIBILITY_BROWSER_NAME: Record<string, string>;
4
+ export declare const BACKWARD_COMPATIBILITY_ENGINE_NAME: Record<string, string>;
5
+ export declare const BACKWARD_COMPATIBILITY_ARCH: Record<string, string>;
6
+ export declare const BACKWARD_COMPATIBILITY_OS_NAME: Record<string, string>;
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,23 @@
1
+ const KNOWN_VENDORS = new Set([
2
+ 'Opera',
3
+ 'Google Chrome',
4
+ 'Microsoft Edge',
5
+ 'Firefox',
6
+ 'Safari',
7
+ ]);
8
+ const KNOWN_ENGINES = new Set(['Chromium']);
9
+ const BACKWARD_COMPATIBILITY_BROWSER_NAME = {
10
+ 'Google Chrome': 'chrome',
11
+ 'Microsoft Edge': 'edge',
12
+ };
13
+ const BACKWARD_COMPATIBILITY_ENGINE_NAME = {
14
+ Chromium: 'Blink',
15
+ };
16
+ const BACKWARD_COMPATIBILITY_ARCH = {
17
+ x86: 'amd64',
18
+ };
19
+ const BACKWARD_COMPATIBILITY_OS_NAME = {
20
+ macOS: 'Mac OS',
21
+ };
22
+
23
+ export { BACKWARD_COMPATIBILITY_ARCH, BACKWARD_COMPATIBILITY_BROWSER_NAME, BACKWARD_COMPATIBILITY_ENGINE_NAME, BACKWARD_COMPATIBILITY_OS_NAME, KNOWN_ENGINES, KNOWN_VENDORS };
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const KNOWN_VENDORS = new Set([
6
+ 'Opera',
7
+ 'Google Chrome',
8
+ 'Microsoft Edge',
9
+ 'Firefox',
10
+ 'Safari',
11
+ ]);
12
+ const KNOWN_ENGINES = new Set(['Chromium']);
13
+ const BACKWARD_COMPATIBILITY_BROWSER_NAME = {
14
+ 'Google Chrome': 'chrome',
15
+ 'Microsoft Edge': 'edge',
16
+ };
17
+ const BACKWARD_COMPATIBILITY_ENGINE_NAME = {
18
+ Chromium: 'Blink',
19
+ };
20
+ const BACKWARD_COMPATIBILITY_ARCH = {
21
+ x86: 'amd64',
22
+ };
23
+ const BACKWARD_COMPATIBILITY_OS_NAME = {
24
+ macOS: 'Mac OS',
25
+ };
26
+
27
+ exports.BACKWARD_COMPATIBILITY_ARCH = BACKWARD_COMPATIBILITY_ARCH;
28
+ exports.BACKWARD_COMPATIBILITY_BROWSER_NAME = BACKWARD_COMPATIBILITY_BROWSER_NAME;
29
+ exports.BACKWARD_COMPATIBILITY_ENGINE_NAME = BACKWARD_COMPATIBILITY_ENGINE_NAME;
30
+ exports.BACKWARD_COMPATIBILITY_OS_NAME = BACKWARD_COMPATIBILITY_OS_NAME;
31
+ exports.KNOWN_ENGINES = KNOWN_ENGINES;
32
+ exports.KNOWN_VENDORS = KNOWN_VENDORS;
@@ -0,0 +1,11 @@
1
+ export declare const ClientHintsHeaders: {
2
+ readonly BASE: "sec-ch-ua";
3
+ readonly FULL_VERSION_LIST: "sec-ch-ua-full-version-list";
4
+ readonly PLATFORM: "sec-ch-ua-platform";
5
+ readonly PLATFORM_VERSION: "sec-ch-ua-platform-version";
6
+ readonly ARCH: "sec-ch-ua-arch";
7
+ readonly MODEL: "sec-ch-ua-model";
8
+ readonly MOBILE: "sec-ch-ua-mobile";
9
+ };
10
+ export type ClientHintsHeaders = (typeof ClientHintsHeaders)[keyof typeof ClientHintsHeaders];
11
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1,11 @@
1
+ const ClientHintsHeaders = {
2
+ BASE: 'sec-ch-ua',
3
+ FULL_VERSION_LIST: 'sec-ch-ua-full-version-list',
4
+ PLATFORM: 'sec-ch-ua-platform',
5
+ PLATFORM_VERSION: 'sec-ch-ua-platform-version',
6
+ ARCH: 'sec-ch-ua-arch',
7
+ MODEL: 'sec-ch-ua-model',
8
+ MOBILE: 'sec-ch-ua-mobile',
9
+ };
10
+
11
+ export { ClientHintsHeaders };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const ClientHintsHeaders = {
6
+ BASE: 'sec-ch-ua',
7
+ FULL_VERSION_LIST: 'sec-ch-ua-full-version-list',
8
+ PLATFORM: 'sec-ch-ua-platform',
9
+ PLATFORM_VERSION: 'sec-ch-ua-platform-version',
10
+ ARCH: 'sec-ch-ua-arch',
11
+ MODEL: 'sec-ch-ua-model',
12
+ MOBILE: 'sec-ch-ua-mobile',
13
+ };
14
+
15
+ exports.ClientHintsHeaders = ClientHintsHeaders;
@@ -0,0 +1,18 @@
1
+ import { UserAgent } from '../../types';
2
+ /**
3
+ *
4
+ * @description
5
+ *
6
+ * Some of the data are available only when additional headers for client-hints were sent from server:
7
+ * - full browser version (only major version is available by default)
8
+ * - OS version
9
+ * - CPU architecture
10
+ * - device model
11
+ *
12
+ * To be able to use data you should first provide header `Accept-CH` with the list of headers that client should send.
13
+ *
14
+ * @param headers
15
+ * @returns
16
+ */
17
+ export declare const parseClientHintsHeaders: (headers: Record<string, string | string[] | undefined>) => UserAgent;
18
+ //# sourceMappingURL=parseClientHintsHeaders.d.ts.map
@@ -0,0 +1,54 @@
1
+ import { DeviceType } from '../../constants.es.js';
2
+ import { getMobileOs } from '../../utils/getMobileOs.es.js';
3
+ import { BACKWARD_COMPATIBILITY_ARCH } from '../constants.es.js';
4
+ import { getBackwardCompatibleOsName } from '../utils/getBackwardCompatibleOsName.es.js';
5
+ import { parseBrowserFromString } from '../utils/parseBrowserFromString.es.js';
6
+ import { parseQuotedString } from '../utils/parseQuotedString.es.js';
7
+ import { ClientHintsHeaders } from './consts.es.js';
8
+
9
+ /**
10
+ *
11
+ * @description
12
+ *
13
+ * Some of the data are available only when additional headers for client-hints were sent from server:
14
+ * - full browser version (only major version is available by default)
15
+ * - OS version
16
+ * - CPU architecture
17
+ * - device model
18
+ *
19
+ * To be able to use data you should first provide header `Accept-CH` with the list of headers that client should send.
20
+ *
21
+ * @param headers
22
+ * @returns
23
+ */
24
+ const parseClientHintsHeaders = (headers) => {
25
+ const { browser, engine } = parseBrowserFromString(headers[ClientHintsHeaders.FULL_VERSION_LIST] ||
26
+ headers[ClientHintsHeaders.BASE]);
27
+ const osName = parseQuotedString(headers[ClientHintsHeaders.PLATFORM]);
28
+ const mobileOS = getMobileOs(osName);
29
+ const architecture = parseQuotedString(headers[ClientHintsHeaders.ARCH]);
30
+ return {
31
+ browser,
32
+ engine,
33
+ os: {
34
+ name: getBackwardCompatibleOsName(osName),
35
+ version: parseQuotedString(headers[ClientHintsHeaders.PLATFORM_VERSION]),
36
+ },
37
+ cpu: {
38
+ architecture: architecture
39
+ ? (BACKWARD_COMPATIBILITY_ARCH[architecture] ?? architecture)
40
+ : architecture,
41
+ },
42
+ mobileOS,
43
+ device: {
44
+ model: parseQuotedString(headers[ClientHintsHeaders.MODEL]),
45
+ type: headers[ClientHintsHeaders.MOBILE] === '?1' ? DeviceType.mobile : DeviceType.desktop,
46
+ vendor: undefined,
47
+ },
48
+ // basically all the browsers with client-hints support
49
+ // also compatible with SameSite=None
50
+ sameSiteNoneCompatible: true,
51
+ };
52
+ };
53
+
54
+ export { parseClientHintsHeaders };
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants$1 = require('../../constants.js');
6
+ var getMobileOs = require('../../utils/getMobileOs.js');
7
+ var constants = require('../constants.js');
8
+ var getBackwardCompatibleOsName = require('../utils/getBackwardCompatibleOsName.js');
9
+ var parseBrowserFromString = require('../utils/parseBrowserFromString.js');
10
+ var parseQuotedString = require('../utils/parseQuotedString.js');
11
+ var consts = require('./consts.js');
12
+
13
+ /**
14
+ *
15
+ * @description
16
+ *
17
+ * Some of the data are available only when additional headers for client-hints were sent from server:
18
+ * - full browser version (only major version is available by default)
19
+ * - OS version
20
+ * - CPU architecture
21
+ * - device model
22
+ *
23
+ * To be able to use data you should first provide header `Accept-CH` with the list of headers that client should send.
24
+ *
25
+ * @param headers
26
+ * @returns
27
+ */
28
+ const parseClientHintsHeaders = (headers) => {
29
+ const { browser, engine } = parseBrowserFromString.parseBrowserFromString(headers[consts.ClientHintsHeaders.FULL_VERSION_LIST] ||
30
+ headers[consts.ClientHintsHeaders.BASE]);
31
+ const osName = parseQuotedString.parseQuotedString(headers[consts.ClientHintsHeaders.PLATFORM]);
32
+ const mobileOS = getMobileOs.getMobileOs(osName);
33
+ const architecture = parseQuotedString.parseQuotedString(headers[consts.ClientHintsHeaders.ARCH]);
34
+ return {
35
+ browser,
36
+ engine,
37
+ os: {
38
+ name: getBackwardCompatibleOsName.getBackwardCompatibleOsName(osName),
39
+ version: parseQuotedString.parseQuotedString(headers[consts.ClientHintsHeaders.PLATFORM_VERSION]),
40
+ },
41
+ cpu: {
42
+ architecture: architecture
43
+ ? (constants.BACKWARD_COMPATIBILITY_ARCH[architecture] ?? architecture)
44
+ : architecture,
45
+ },
46
+ mobileOS,
47
+ device: {
48
+ model: parseQuotedString.parseQuotedString(headers[consts.ClientHintsHeaders.MODEL]),
49
+ type: headers[consts.ClientHintsHeaders.MOBILE] === '?1' ? constants$1.DeviceType.mobile : constants$1.DeviceType.desktop,
50
+ vendor: undefined,
51
+ },
52
+ // basically all the browsers with client-hints support
53
+ // also compatible with SameSite=None
54
+ sameSiteNoneCompatible: true,
55
+ };
56
+ };
57
+
58
+ exports.parseClientHintsHeaders = parseClientHintsHeaders;
@@ -0,0 +1,17 @@
1
+ import { UserAgent } from '../../types';
2
+ /**
3
+ *
4
+ * @description
5
+ * Some of the data will be available if `UADataValues` were gotten from
6
+ * `getHighEntropyValues` async method, but it's not suitable for all cases.
7
+ *
8
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API
9
+ * @see https://wicg.github.io/ua-client-hints/#http-ua-hints
10
+ *
11
+ * @param payload
12
+ *
13
+ * @example
14
+ * const clientHints = parseClientHintsUserAgentData(window.navigator.userAgentData)
15
+ */
16
+ export declare const parseClientHintsUserAgentData: (payload: UADataValues) => UserAgent;
17
+ //# sourceMappingURL=parseClientHintsUserAgentData.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { DeviceType } from '../../constants.es.js';
2
+ import { getMobileOs } from '../../utils/getMobileOs.es.js';
3
+ import { BACKWARD_COMPATIBILITY_ARCH } from '../constants.es.js';
4
+ import { getBackwardCompatibleOsName } from '../utils/getBackwardCompatibleOsName.es.js';
5
+ import { parseBrowserFromUserAgentData } from '../utils/parseBrowserFromUserAgentData.es.js';
6
+
7
+ /**
8
+ *
9
+ * @description
10
+ * Some of the data will be available if `UADataValues` were gotten from
11
+ * `getHighEntropyValues` async method, but it's not suitable for all cases.
12
+ *
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API
14
+ * @see https://wicg.github.io/ua-client-hints/#http-ua-hints
15
+ *
16
+ * @param payload
17
+ *
18
+ * @example
19
+ * const clientHints = parseClientHintsUserAgentData(window.navigator.userAgentData)
20
+ */
21
+ const parseClientHintsUserAgentData = (payload) => {
22
+ const { browser, engine } = parseBrowserFromUserAgentData(payload.fullVersionList || payload.brands || []);
23
+ return {
24
+ browser,
25
+ engine,
26
+ os: {
27
+ name: getBackwardCompatibleOsName(payload.platform),
28
+ version: payload.platformVersion,
29
+ },
30
+ cpu: {
31
+ architecture: payload.architecture
32
+ ? (BACKWARD_COMPATIBILITY_ARCH[payload.architecture] ?? payload.architecture)
33
+ : payload.architecture,
34
+ },
35
+ mobileOS: getMobileOs(payload.platform),
36
+ device: {
37
+ model: payload.model,
38
+ type: payload.mobile ? DeviceType.mobile : DeviceType.desktop,
39
+ vendor: undefined,
40
+ },
41
+ // basically all the browsers with client-hints support
42
+ // also compatible with SameSite=None
43
+ sameSiteNoneCompatible: true,
44
+ };
45
+ };
46
+
47
+ export { parseClientHintsUserAgentData };
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants$1 = require('../../constants.js');
6
+ var getMobileOs = require('../../utils/getMobileOs.js');
7
+ var constants = require('../constants.js');
8
+ var getBackwardCompatibleOsName = require('../utils/getBackwardCompatibleOsName.js');
9
+ var parseBrowserFromUserAgentData = require('../utils/parseBrowserFromUserAgentData.js');
10
+
11
+ /**
12
+ *
13
+ * @description
14
+ * Some of the data will be available if `UADataValues` were gotten from
15
+ * `getHighEntropyValues` async method, but it's not suitable for all cases.
16
+ *
17
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API
18
+ * @see https://wicg.github.io/ua-client-hints/#http-ua-hints
19
+ *
20
+ * @param payload
21
+ *
22
+ * @example
23
+ * const clientHints = parseClientHintsUserAgentData(window.navigator.userAgentData)
24
+ */
25
+ const parseClientHintsUserAgentData = (payload) => {
26
+ const { browser, engine } = parseBrowserFromUserAgentData.parseBrowserFromUserAgentData(payload.fullVersionList || payload.brands || []);
27
+ return {
28
+ browser,
29
+ engine,
30
+ os: {
31
+ name: getBackwardCompatibleOsName.getBackwardCompatibleOsName(payload.platform),
32
+ version: payload.platformVersion,
33
+ },
34
+ cpu: {
35
+ architecture: payload.architecture
36
+ ? (constants.BACKWARD_COMPATIBILITY_ARCH[payload.architecture] ?? payload.architecture)
37
+ : payload.architecture,
38
+ },
39
+ mobileOS: getMobileOs.getMobileOs(payload.platform),
40
+ device: {
41
+ model: payload.model,
42
+ type: payload.mobile ? constants$1.DeviceType.mobile : constants$1.DeviceType.desktop,
43
+ vendor: undefined,
44
+ },
45
+ // basically all the browsers with client-hints support
46
+ // also compatible with SameSite=None
47
+ sameSiteNoneCompatible: true,
48
+ };
49
+ };
50
+
51
+ exports.parseClientHintsUserAgentData = parseClientHintsUserAgentData;
@@ -0,0 +1,2 @@
1
+ export declare const getBackwardCompatibleOsName: (payload: string | undefined) => string | undefined;
2
+ //# sourceMappingURL=getBackwardCompatibleOsName.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { BACKWARD_COMPATIBILITY_OS_NAME } from '../constants.es.js';
2
+
3
+ const getBackwardCompatibleOsName = (payload) => {
4
+ if (payload === undefined) {
5
+ return undefined;
6
+ }
7
+ return BACKWARD_COMPATIBILITY_OS_NAME[payload] ?? payload;
8
+ };
9
+
10
+ export { getBackwardCompatibleOsName };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants = require('../constants.js');
6
+
7
+ const getBackwardCompatibleOsName = (payload) => {
8
+ if (payload === undefined) {
9
+ return undefined;
10
+ }
11
+ return constants.BACKWARD_COMPATIBILITY_OS_NAME[payload] ?? payload;
12
+ };
13
+
14
+ exports.getBackwardCompatibleOsName = getBackwardCompatibleOsName;
@@ -0,0 +1,6 @@
1
+ import type { Browser, Engine } from '../../types';
2
+ export declare const parseBrowserFromString: (brandsList: string) => {
3
+ browser: Browser;
4
+ engine: Engine;
5
+ };
6
+ //# sourceMappingURL=parseBrowserFromString.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { getBrowserEngine } from '../../utils/getBrowserEngine.es.js';
2
+ import { KNOWN_VENDORS, BACKWARD_COMPATIBILITY_BROWSER_NAME, KNOWN_ENGINES, BACKWARD_COMPATIBILITY_ENGINE_NAME } from '../constants.es.js';
3
+ import { parseQuotedString } from './parseQuotedString.es.js';
4
+
5
+ /*
6
+ The parseBrowserFromString function accepts a brandsList string that contains information
7
+ about the browser and its engine in a format where each entry is separated by a comma,
8
+ and the brand name and version are separated. The function parses this string and returns
9
+ an object containing information about the browser and its engine.
10
+ */
11
+ const parseBrowserFromString = (brandsList) => {
12
+ const browser = {
13
+ name: undefined,
14
+ version: undefined,
15
+ major: undefined,
16
+ browserEngine: '',
17
+ };
18
+ const engine = {
19
+ name: undefined,
20
+ version: undefined,
21
+ };
22
+ brandsList.split(',').forEach((entry) => {
23
+ const [name, version] = entry.split(/;\s*v=/).map(parseQuotedString);
24
+ if (name && KNOWN_VENDORS.has(name)) {
25
+ browser.name = BACKWARD_COMPATIBILITY_BROWSER_NAME[name] ?? name.toLowerCase();
26
+ browser.version = version;
27
+ browser.major = version;
28
+ }
29
+ if (name && KNOWN_ENGINES.has(name)) {
30
+ engine.name = BACKWARD_COMPATIBILITY_ENGINE_NAME[name] ?? name.toLowerCase();
31
+ engine.version = version;
32
+ }
33
+ });
34
+ if (!browser.name && engine.name) {
35
+ browser.name = engine.name;
36
+ browser.version = engine.version;
37
+ }
38
+ browser.browserEngine = getBrowserEngine(browser.name?.toLowerCase(), engine.name?.toLowerCase());
39
+ return { browser, engine };
40
+ };
41
+
42
+ export { parseBrowserFromString };