@tinkoff/user-agent 0.4.445 → 0.4.447

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.
@@ -22,7 +22,7 @@ export declare const parseClientHintsHeaders: (headers: Record<string, string |
22
22
  * `getHighEntropyValues` async method, but it's not suitable for all cases.
23
23
  *
24
24
  * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API
25
- * @see https://wicg.github.io/ua-client-hints/#user-agent-model
25
+ * @see https://wicg.github.io/ua-client-hints/#http-ua-hints
26
26
  *
27
27
  * @param payload
28
28
  *
@@ -88,6 +88,17 @@ const getBackwardCompatibleOsName = (payload) => {
88
88
  }
89
89
  return (_a = BACKWARD_COMPATIBILITY_OS_NAME[payload]) !== null && _a !== void 0 ? _a : payload;
90
90
  };
91
+ /**
92
+ * Method to convert arch + bitness to `ua-parser-js` compatible format.
93
+ *
94
+ * @see ICPU
95
+ */
96
+ const getArchitecture = (arch, bitness) => {
97
+ if (arch === undefined) {
98
+ return undefined;
99
+ }
100
+ return `${arch}${bitness !== null && bitness !== void 0 ? bitness : ''}`;
101
+ };
91
102
  /**
92
103
  *
93
104
  * @description
@@ -115,7 +126,7 @@ const parseClientHintsHeaders = (headers) => {
115
126
  version: parseQuotedString(headers['sec-ch-ua-platform-version']),
116
127
  },
117
128
  cpu: {
118
- architecture: parseQuotedString(headers['sec-ch-ua-arch']),
129
+ architecture: getArchitecture(parseQuotedString(headers['sec-ch-ua-arch']), parseQuotedString(headers['sec-ch-ua-bitness'])),
119
130
  },
120
131
  mobileOS,
121
132
  device: {
@@ -135,7 +146,7 @@ const parseClientHintsHeaders = (headers) => {
135
146
  * `getHighEntropyValues` async method, but it's not suitable for all cases.
136
147
  *
137
148
  * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API
138
- * @see https://wicg.github.io/ua-client-hints/#user-agent-model
149
+ * @see https://wicg.github.io/ua-client-hints/#http-ua-hints
139
150
  *
140
151
  * @param payload
141
152
  *
@@ -152,7 +163,7 @@ const parseClientHintsUserAgentData = (payload) => {
152
163
  version: payload.platformVersion,
153
164
  },
154
165
  cpu: {
155
- architecture: payload.architecture,
166
+ architecture: getArchitecture(payload.architecture, payload.bitness),
156
167
  },
157
168
  mobileOS: getMobileOs(payload.platform),
158
169
  device: {
@@ -92,6 +92,17 @@ const getBackwardCompatibleOsName = (payload) => {
92
92
  }
93
93
  return (_a = BACKWARD_COMPATIBILITY_OS_NAME[payload]) !== null && _a !== void 0 ? _a : payload;
94
94
  };
95
+ /**
96
+ * Method to convert arch + bitness to `ua-parser-js` compatible format.
97
+ *
98
+ * @see ICPU
99
+ */
100
+ const getArchitecture = (arch, bitness) => {
101
+ if (arch === undefined) {
102
+ return undefined;
103
+ }
104
+ return `${arch}${bitness !== null && bitness !== void 0 ? bitness : ''}`;
105
+ };
95
106
  /**
96
107
  *
97
108
  * @description
@@ -119,7 +130,7 @@ const parseClientHintsHeaders = (headers) => {
119
130
  version: parseQuotedString(headers['sec-ch-ua-platform-version']),
120
131
  },
121
132
  cpu: {
122
- architecture: parseQuotedString(headers['sec-ch-ua-arch']),
133
+ architecture: getArchitecture(parseQuotedString(headers['sec-ch-ua-arch']), parseQuotedString(headers['sec-ch-ua-bitness'])),
123
134
  },
124
135
  mobileOS,
125
136
  device: {
@@ -139,7 +150,7 @@ const parseClientHintsHeaders = (headers) => {
139
150
  * `getHighEntropyValues` async method, but it's not suitable for all cases.
140
151
  *
141
152
  * @see https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API
142
- * @see https://wicg.github.io/ua-client-hints/#user-agent-model
153
+ * @see https://wicg.github.io/ua-client-hints/#http-ua-hints
143
154
  *
144
155
  * @param payload
145
156
  *
@@ -156,7 +167,7 @@ const parseClientHintsUserAgentData = (payload) => {
156
167
  version: payload.platformVersion,
157
168
  },
158
169
  cpu: {
159
- architecture: payload.architecture,
170
+ architecture: getArchitecture(payload.architecture, payload.bitness),
160
171
  },
161
172
  mobileOS: utils.getMobileOs(payload.platform),
162
173
  device: {
package/lib/types.d.ts CHANGED
@@ -15,6 +15,10 @@ export interface Engine {
15
15
  version: string | undefined;
16
16
  }
17
17
  export interface Device {
18
+ /**
19
+ * Device type may be undefined in various cases.
20
+ * @see https://github.com/faisalman/ua-parser-js/issues/182
21
+ */
18
22
  type: string | undefined;
19
23
  model: string | undefined;
20
24
  /**
@@ -27,9 +31,6 @@ export interface OS {
27
31
  version: string | undefined;
28
32
  }
29
33
  export interface Cpu {
30
- /**
31
- * @deprecated This is not provided by default with client-hints
32
- */
33
34
  architecture: string | undefined;
34
35
  }
35
36
  export interface UserAgent {
@@ -37,9 +38,6 @@ export interface UserAgent {
37
38
  engine: Engine;
38
39
  device: Device;
39
40
  os: OS;
40
- /**
41
- * @deprecated This is not provided by default with client-hints
42
- */
43
41
  cpu: Cpu;
44
42
  mobileOS?: string;
45
43
  sameSiteNoneCompatible: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkoff/user-agent",
3
- "version": "0.4.445",
3
+ "version": "0.4.447",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.es.js",
@@ -29,7 +29,7 @@
29
29
  "user-agent-data-types": "^0.3.1"
30
30
  },
31
31
  "peerDependencies": {
32
- "@tramvai/cli": "2.154.0",
32
+ "@tramvai/cli": "2.155.0",
33
33
  "@types/ua-parser-js": "^0.7.33"
34
34
  },
35
35
  "license": "Apache-2.0"