@tramvai/module-client-hints 5.49.1 → 6.59.0

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 (2) hide show
  1. package/README.md +36 -1
  2. package/package.json +13 -13
package/README.md CHANGED
@@ -223,7 +223,42 @@ const App = () => {
223
223
 
224
224
  ### USER_AGENT_TOKEN
225
225
 
226
- Object as a result of parsing user-agent string with [@tinkoff/user-agent](../libs/user-agent.md). Parsing happens only on server-side and parsed info is reused on client-side.
226
+ Object as a result of parsing user-agent headers or string with [@tinkoff/user-agent](../libs/user-agent.md). Parsing happens only on server-side and parsed info is reused on client-side. If header info is unavailable then takes user-agent and parse it with ua-parser-js lib.
227
+
228
+ ### Example of usage
229
+
230
+ Here userAgent is used to determine the mobile device.
231
+
232
+ ```tsx
233
+ import { provide, Scope, Module, createToken } from '@tramvai/core';
234
+ import { ClientHintsModule, USER_AGENT_TOKEN } from '@tramvai/module-client-hints';
235
+
236
+ export const IS_MOBILE_BANNER = createToken<boolean>('IS_MOBILE_BANNER');
237
+
238
+ @Module({
239
+ imports: [ClientHintsModule],
240
+ providers: [
241
+ provide({
242
+ provide: IS_MOBILE_BANNER,
243
+ deps: {
244
+ userAgent: USER_AGENT_TOKEN,
245
+ },
246
+ useFactory({ userAgent }) {
247
+ const deviceType = userAgent?.device?.type ?? 'desktop';
248
+
249
+ return (
250
+ {
251
+ mobile: true,
252
+ wearable: true,
253
+ }[deviceType] || false
254
+ );
255
+ },
256
+ scope: Scope.REQUEST,
257
+ }),
258
+ ],
259
+ })
260
+ export class BannerModule {}
261
+ ```
227
262
 
228
263
  ## Env variables
229
264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-client-hints",
3
- "version": "5.49.1",
3
+ "version": "6.59.0",
4
4
  "description": "",
5
5
  "main": "lib/server.js",
6
6
  "module": "lib/server.es.js",
@@ -19,22 +19,22 @@
19
19
  "watch": "tsc -w"
20
20
  },
21
21
  "dependencies": {
22
- "@tinkoff/user-agent": "0.7.115",
22
+ "@tinkoff/env-validators": "0.5.0",
23
+ "@tinkoff/user-agent": "0.8.102",
23
24
  "@tinkoff/utils": "^2.1.2",
24
- "@tinkoff/env-validators": "0.4.2",
25
- "@tramvai/safe-strings": "0.8.4",
26
- "@tramvai/module-metrics": "5.49.1",
27
- "@tramvai/tokens-child-app": "5.49.1",
28
- "@tramvai/tokens-common": "5.49.1",
29
- "@tramvai/tokens-cookie": "5.49.1",
30
- "@tramvai/tokens-render": "5.49.1",
25
+ "@tramvai/module-metrics": "6.59.0",
26
+ "@tramvai/safe-strings": "0.9.0",
27
+ "@tramvai/tokens-child-app": "6.59.0",
28
+ "@tramvai/tokens-common": "6.59.0",
29
+ "@tramvai/tokens-cookie": "6.59.0",
30
+ "@tramvai/tokens-render": "6.59.0",
31
31
  "user-agent-data-types": "^0.3.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "@tinkoff/dippy": "0.11.4",
35
- "@tinkoff/logger": "0.10.507",
36
- "@tramvai/core": "5.49.1",
37
- "@tramvai/state": "5.49.1",
34
+ "@tinkoff/dippy": "0.12.3",
35
+ "@tinkoff/logger": "^0.10.507",
36
+ "@tramvai/core": "6.59.0",
37
+ "@tramvai/state": "6.59.0",
38
38
  "react": ">=16.14.0",
39
39
  "react-dom": ">=16.14.0",
40
40
  "tslib": "^2.4.0"