@tramvai/module-client-hints 2.153.3 → 2.155.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.
@@ -0,0 +1,2 @@
1
+ export declare function loadHighEntropyClientHints(): void;
2
+ //# sourceMappingURL=loadHighEntropyClientHints.inline.d.ts.map
@@ -0,0 +1,18 @@
1
+ function loadHighEntropyClientHints() {
2
+ if (window.navigator.userAgentData !== undefined) {
3
+ window.navigator.userAgentData
4
+ .getHighEntropyValues([
5
+ 'architecture',
6
+ 'bitness',
7
+ 'model',
8
+ 'platformVersion',
9
+ 'fullVersionList',
10
+ ])
11
+ .then((result) => {
12
+ window.__TRAMVAI_USER_AGENT_DATA = result;
13
+ })
14
+ .catch(() => { });
15
+ }
16
+ }
17
+
18
+ export { loadHighEntropyClientHints };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function loadHighEntropyClientHints() {
6
+ if (window.navigator.userAgentData !== undefined) {
7
+ window.navigator.userAgentData
8
+ .getHighEntropyValues([
9
+ 'architecture',
10
+ 'bitness',
11
+ 'model',
12
+ 'platformVersion',
13
+ 'fullVersionList',
14
+ ])
15
+ .then((result) => {
16
+ window.__TRAMVAI_USER_AGENT_DATA = result;
17
+ })
18
+ .catch(() => { });
19
+ }
20
+ }
21
+
22
+ exports.loadHighEntropyClientHints = loadHighEntropyClientHints;
@@ -1,16 +1,19 @@
1
1
  import { parse, parseClientHintsUserAgentData } from '@tinkoff/user-agent';
2
2
 
3
3
  const getFromUserAgentData = () => {
4
+ var _a;
4
5
  try {
5
- // @ts-expect-error. We are handling error here, that's why we can force TS
6
- const { brands, mobile, platform } = window.navigator.userAgentData;
6
+ const values = (_a = window.__TRAMVAI_USER_AGENT_DATA) !== null && _a !== void 0 ? _a : window.navigator.userAgentData;
7
+ if (values === undefined) {
8
+ return null;
9
+ }
7
10
  // chrome User-Agent emulation doesn't sync with `navigator.userAgentData`,
8
11
  // and `navigator.userAgentData` return incorrect object for Safari User-Agents instead of `undefined`
9
12
  // example of this problem with Playwright tests - https://github.com/microsoft/playwright/issues/14361
10
- if (brands && brands.length === 0 && platform === '') {
13
+ if (values.brands && values.brands.length === 0 && values.platform === '') {
11
14
  return null;
12
15
  }
13
- return parseClientHintsUserAgentData({ brands, mobile, platform });
16
+ return parseClientHintsUserAgentData(values);
14
17
  }
15
18
  catch (error) {
16
19
  return null;
@@ -1,3 +1,9 @@
1
+ /// <reference types="user-agent-data-types" />
2
+ declare global {
3
+ interface Window {
4
+ __TRAMVAI_USER_AGENT_DATA?: UADataValues;
5
+ }
6
+ }
1
7
  export declare const ClientHintsCSRModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
2
8
  [x: string]: (...args: any[]) => import("@tinkoff/dippy").ModuleType;
3
9
  };
@@ -1,9 +1,21 @@
1
- import { declareModule } from '@tinkoff/dippy';
1
+ import { declareModule, provide } from '@tinkoff/dippy';
2
+ import { RENDER_SLOTS, ResourceType, ResourceSlot } from '@tramvai/tokens-render';
2
3
  import { serverProviders } from '../../shared/providers.server.es.js';
4
+ import { loadHighEntropyClientHints } from '../../browser/loadHighEntropyClientHints.inline.es.js';
3
5
 
4
6
  const ClientHintsCSRModule = /* @__PURE__ */ declareModule({
5
7
  name: 'ClientHintsCSRModule',
6
- providers: serverProviders,
8
+ providers: [
9
+ ...serverProviders,
10
+ provide({
11
+ provide: RENDER_SLOTS,
12
+ useValue: {
13
+ type: ResourceType.inlineScript,
14
+ slot: ResourceSlot.HEAD_PERFORMANCE,
15
+ payload: `(${loadHighEntropyClientHints.toString()})()`,
16
+ },
17
+ }),
18
+ ],
7
19
  });
8
20
 
9
21
  export { ClientHintsCSRModule };
@@ -3,11 +3,23 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var dippy = require('@tinkoff/dippy');
6
+ var tokensRender = require('@tramvai/tokens-render');
6
7
  var providers_server = require('../../shared/providers.server.js');
8
+ var loadHighEntropyClientHints_inline = require('../../browser/loadHighEntropyClientHints.inline.js');
7
9
 
8
10
  const ClientHintsCSRModule = /* @__PURE__ */ dippy.declareModule({
9
11
  name: 'ClientHintsCSRModule',
10
- providers: providers_server.serverProviders,
12
+ providers: [
13
+ ...providers_server.serverProviders,
14
+ dippy.provide({
15
+ provide: tokensRender.RENDER_SLOTS,
16
+ useValue: {
17
+ type: tokensRender.ResourceType.inlineScript,
18
+ slot: tokensRender.ResourceSlot.HEAD_PERFORMANCE,
19
+ payload: `(${loadHighEntropyClientHints_inline.loadHighEntropyClientHints.toString()})()`,
20
+ },
21
+ }),
22
+ ],
11
23
  });
12
24
 
13
25
  exports.ClientHintsCSRModule = ClientHintsCSRModule;
@@ -1,5 +1,5 @@
1
1
  import { provide } from '@tramvai/core';
2
- import { COMBINE_REDUCERS } from '@tramvai/tokens-common';
2
+ import { COMBINE_REDUCERS, ENV_USED_TOKEN } from '@tramvai/tokens-common';
3
3
  import { UserAgentStore } from './stores/userAgent.browser.js';
4
4
  import { MediaStore } from './stores/media.browser.js';
5
5
 
@@ -9,6 +9,15 @@ const commonProviders = [
9
9
  multi: true,
10
10
  useValue: [UserAgentStore, MediaStore],
11
11
  }),
12
+ provide({
13
+ provide: ENV_USED_TOKEN,
14
+ useValue: [
15
+ {
16
+ key: 'TRAMVAI_FORCE_CLIENT_SIDE_RENDERING',
17
+ optional: true,
18
+ },
19
+ ],
20
+ }),
12
21
  ];
13
22
 
14
23
  export { commonProviders };
@@ -1,5 +1,5 @@
1
1
  import { provide } from '@tramvai/core';
2
- import { COMBINE_REDUCERS } from '@tramvai/tokens-common';
2
+ import { COMBINE_REDUCERS, ENV_USED_TOKEN } from '@tramvai/tokens-common';
3
3
  import { UserAgentStore } from './stores/userAgent.es.js';
4
4
  import { MediaStore } from './stores/media.es.js';
5
5
 
@@ -9,6 +9,15 @@ const commonProviders = [
9
9
  multi: true,
10
10
  useValue: [UserAgentStore, MediaStore],
11
11
  }),
12
+ provide({
13
+ provide: ENV_USED_TOKEN,
14
+ useValue: [
15
+ {
16
+ key: 'TRAMVAI_FORCE_CLIENT_SIDE_RENDERING',
17
+ optional: true,
18
+ },
19
+ ],
20
+ }),
12
21
  ];
13
22
 
14
23
  export { commonProviders };
@@ -13,6 +13,15 @@ const commonProviders = [
13
13
  multi: true,
14
14
  useValue: [userAgent.UserAgentStore, media.MediaStore],
15
15
  }),
16
+ core.provide({
17
+ provide: tokensCommon.ENV_USED_TOKEN,
18
+ useValue: [
19
+ {
20
+ key: 'TRAMVAI_FORCE_CLIENT_SIDE_RENDERING',
21
+ optional: true,
22
+ },
23
+ ],
24
+ }),
16
25
  ];
17
26
 
18
27
  exports.commonProviders = commonProviders;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-client-hints",
3
- "version": "2.153.3",
3
+ "version": "2.155.0",
4
4
  "description": "",
5
5
  "main": "lib/server.js",
6
6
  "module": "lib/server.es.js",
@@ -19,21 +19,22 @@
19
19
  "watch": "tsc -w"
20
20
  },
21
21
  "dependencies": {
22
- "@tinkoff/user-agent": "0.4.444",
22
+ "@tinkoff/user-agent": "0.4.447",
23
23
  "@tinkoff/utils": "^2.1.2",
24
24
  "@tinkoff/env-validators": "0.1.6",
25
25
  "@tramvai/safe-strings": "0.5.12",
26
- "@tramvai/module-metrics": "2.153.3",
27
- "@tramvai/tokens-child-app": "2.153.3",
28
- "@tramvai/tokens-common": "2.153.3",
29
- "@tramvai/tokens-cookie": "2.153.3",
26
+ "@tramvai/module-metrics": "2.155.0",
27
+ "@tramvai/tokens-child-app": "2.155.0",
28
+ "@tramvai/tokens-common": "2.155.0",
29
+ "@tramvai/tokens-cookie": "2.155.0",
30
+ "@tramvai/tokens-render": "2.155.0",
30
31
  "user-agent-data-types": "^0.3.1"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "@tinkoff/dippy": "0.8.16",
34
35
  "@tinkoff/logger": "0.10.67",
35
- "@tramvai/core": "2.153.3",
36
- "@tramvai/state": "2.153.3",
36
+ "@tramvai/core": "2.155.0",
37
+ "@tramvai/state": "2.155.0",
37
38
  "react": ">=16.14.0",
38
39
  "react-dom": ">=16.14.0",
39
40
  "tslib": "^2.4.0"