@tramvai/module-client-hints 2.150.0 → 2.150.1

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.
package/README.md CHANGED
@@ -214,3 +214,15 @@ const App = () => {
214
214
  ### USER_AGENT_TOKEN
215
215
 
216
216
  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.
217
+
218
+ ## Env variables
219
+
220
+ ### TRAMVAI_USER_AGENT_CACHE_MAX
221
+
222
+ Size of User-Agent header parsing cache (in-memory LRU cache), default value is `200`.
223
+
224
+ You can increase it for better cache hit rate and server performance.
225
+
226
+ ## Metrics
227
+
228
+ - `user_agent_cache_gets` counter - User-Agent header parsing count, with labels `hit` and `miss`
@@ -1,2 +1,3 @@
1
1
  import type { UserAgent } from '@tinkoff/user-agent';
2
2
  export declare function loadUserAgent(): UserAgent;
3
+ //# sourceMappingURL=loadUserAgent.d.ts.map
@@ -9,3 +9,4 @@ export declare const matchMediaCommand: ({ context, cookieManager, }: {
9
9
  context: typeof CONTEXT_TOKEN;
10
10
  cookieManager: typeof COOKIE_MANAGER_TOKEN;
11
11
  }) => () => Promise<import("../shared/stores/media").Media>;
12
+ //# sourceMappingURL=matchMedia.d.ts.map
package/lib/browser.d.ts CHANGED
@@ -6,5 +6,6 @@ export * from './shared/stores/userAgent';
6
6
  export { ClientHintsChildAppModule } from './modules/child-app/module';
7
7
  export { ClientHintsCSRModule } from './modules/csr/browser';
8
8
  export declare const ClientHintsModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
9
- [x: string]: (...args: any[]) => import("@tramvai/core").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
9
+ [x: string]: (...args: any[]) => import("@tramvai/core").ModuleType;
10
10
  };
11
+ //# sourceMappingURL=browser.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export declare class ClientHintsChildAppModule {
2
2
  }
3
+ //# sourceMappingURL=module.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export declare const ClientHintsCSRModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
2
- [x: string]: (...args: any[]) => import("@tinkoff/dippy").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
2
+ [x: string]: (...args: any[]) => import("@tinkoff/dippy").ModuleType;
3
3
  };
4
+ //# sourceMappingURL=browser.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export declare const ClientHintsCSRModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
2
- [x: string]: (...args: any[]) => import("@tinkoff/dippy").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
2
+ [x: string]: (...args: any[]) => import("@tinkoff/dippy").ModuleType;
3
3
  };
4
+ //# sourceMappingURL=server.d.ts.map
@@ -4,3 +4,4 @@ export declare const parseUserAgentWithCache: (cache: Cache, userAgent: string,
4
4
  hit: Function;
5
5
  miss: Function;
6
6
  }) => UserAgent;
7
+ //# sourceMappingURL=parseUserAgentWithCache.d.ts.map
@@ -4,3 +4,4 @@ export declare const readMediaCommand: ({ context, cookieManager, }: {
4
4
  context: typeof CONTEXT_TOKEN;
5
5
  cookieManager: typeof COOKIE_MANAGER_TOKEN;
6
6
  }) => () => Promise<import("../shared/stores/media").Media>;
7
+ //# sourceMappingURL=readMedia.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { Provider } from '@tramvai/core';
2
2
  export declare const serverUserAgentProviders: Provider[];
3
+ //# sourceMappingURL=userAgent.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { provide, Scope, commandLineListTokens } from '@tramvai/core';
2
- import { ENV_MANAGER_TOKEN, ENV_USED_TOKEN, CREATE_CACHE_TOKEN, RESPONSE_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, STORE_TOKEN } from '@tramvai/tokens-common';
2
+ import { ENV_USED_TOKEN, CREATE_CACHE_TOKEN, ENV_MANAGER_TOKEN, RESPONSE_MANAGER_TOKEN, REQUEST_MANAGER_TOKEN, STORE_TOKEN } from '@tramvai/tokens-common';
3
3
  import { METRICS_MODULE_TOKEN } from '@tramvai/module-metrics';
4
4
  import { parseClientHints } from '@tinkoff/user-agent';
5
5
  import noop from '@tinkoff/utils/function/noop';
@@ -9,26 +9,12 @@ import { setUserAgent } from '../shared/stores/userAgent.es.js';
9
9
  import { parseUserAgentWithCache } from './parseUserAgentWithCache.es.js';
10
10
 
11
11
  const serverUserAgentProviders = [
12
- provide({
13
- provide: 'userAgentCacheType',
14
- useFactory: ({ envManager }) => envManager.get('TRAMVAI_USER_AGENT_CACHE_TYPE'),
15
- deps: {
16
- envManager: ENV_MANAGER_TOKEN,
17
- },
18
- }),
19
12
  provide({
20
13
  provide: ENV_USED_TOKEN,
21
14
  useValue: [
22
- {
23
- key: 'TRAMVAI_USER_AGENT_CACHE_TYPE',
24
- value: 'memory',
25
- optional: true,
26
- validator: (value) => value === 'memory' || value === 'memory-lfu',
27
- dehydrate: false,
28
- },
29
15
  {
30
16
  key: 'TRAMVAI_USER_AGENT_CACHE_MAX',
31
- value: '50',
17
+ value: '200',
32
18
  optional: true,
33
19
  validator: isNumber,
34
20
  dehydrate: false,
@@ -38,15 +24,14 @@ const serverUserAgentProviders = [
38
24
  provide({
39
25
  provide: 'userAgentMemoryCache',
40
26
  scope: Scope.SINGLETON,
41
- useFactory: ({ createCache, envManager, cacheType }) => {
42
- return createCache(cacheType, {
27
+ useFactory: ({ createCache, envManager }) => {
28
+ return createCache('memory', {
43
29
  max: Number(envManager.get('TRAMVAI_USER_AGENT_CACHE_MAX')),
44
30
  });
45
31
  },
46
32
  deps: {
47
33
  createCache: CREATE_CACHE_TOKEN,
48
34
  envManager: ENV_MANAGER_TOKEN,
49
- cacheType: 'userAgentCacheType',
50
35
  },
51
36
  }),
52
37
  provide({
@@ -17,26 +17,12 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
17
17
  var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
18
18
 
19
19
  const serverUserAgentProviders = [
20
- core.provide({
21
- provide: 'userAgentCacheType',
22
- useFactory: ({ envManager }) => envManager.get('TRAMVAI_USER_AGENT_CACHE_TYPE'),
23
- deps: {
24
- envManager: tokensCommon.ENV_MANAGER_TOKEN,
25
- },
26
- }),
27
20
  core.provide({
28
21
  provide: tokensCommon.ENV_USED_TOKEN,
29
22
  useValue: [
30
- {
31
- key: 'TRAMVAI_USER_AGENT_CACHE_TYPE',
32
- value: 'memory',
33
- optional: true,
34
- validator: (value) => value === 'memory' || value === 'memory-lfu',
35
- dehydrate: false,
36
- },
37
23
  {
38
24
  key: 'TRAMVAI_USER_AGENT_CACHE_MAX',
39
- value: '50',
25
+ value: '200',
40
26
  optional: true,
41
27
  validator: envValidators.isNumber,
42
28
  dehydrate: false,
@@ -46,15 +32,14 @@ const serverUserAgentProviders = [
46
32
  core.provide({
47
33
  provide: 'userAgentMemoryCache',
48
34
  scope: core.Scope.SINGLETON,
49
- useFactory: ({ createCache, envManager, cacheType }) => {
50
- return createCache(cacheType, {
35
+ useFactory: ({ createCache, envManager }) => {
36
+ return createCache('memory', {
51
37
  max: Number(envManager.get('TRAMVAI_USER_AGENT_CACHE_MAX')),
52
38
  });
53
39
  },
54
40
  deps: {
55
41
  createCache: tokensCommon.CREATE_CACHE_TOKEN,
56
42
  envManager: tokensCommon.ENV_MANAGER_TOKEN,
57
- cacheType: 'userAgentCacheType',
58
43
  },
59
44
  }),
60
45
  core.provide({
package/lib/server.d.ts CHANGED
@@ -6,5 +6,6 @@ export * from './shared/stores/userAgent';
6
6
  export { ClientHintsChildAppModule } from './modules/child-app/module';
7
7
  export { ClientHintsCSRModule } from './modules/csr/server';
8
8
  export declare const ClientHintsModule: import("@tinkoff/dippy/lib/modules/module.h").ModuleClass & Partial<import("@tinkoff/dippy/lib/modules/module.h").ModuleSecretParameters> & {
9
- [x: string]: (...args: any[]) => import("@tramvai/core").ModuleType<import("@tinkoff/dippy/lib/modules/module.h").ModuleClass>;
9
+ [x: string]: (...args: any[]) => import("@tramvai/core").ModuleType;
10
10
  };
11
+ //# sourceMappingURL=server.d.ts.map
@@ -1 +1,2 @@
1
1
  export declare const COOKIE_NAME_MEDIA_INFO = "mediaInfo";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -1,3 +1,4 @@
1
1
  export declare const mediaBreakpoints: {
2
2
  retina: string;
3
3
  };
4
+ //# sourceMappingURL=mediaBreakpoints.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { Provider } from '@tinkoff/dippy';
2
2
  export declare const browserProviders: Provider[];
3
+ //# sourceMappingURL=providers.browser.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { Provider } from '@tramvai/core';
2
2
  export declare const commonProviders: Provider[];
3
+ //# sourceMappingURL=providers.d.ts.map
@@ -1,2 +1,3 @@
1
1
  import type { Provider } from '@tinkoff/dippy';
2
2
  export declare const serverProviders: Provider[];
3
+ //# sourceMappingURL=providers.server.d.ts.map
@@ -3,5 +3,6 @@ export interface Media extends MediaInfo {
3
3
  supposed?: boolean;
4
4
  synchronized?: boolean;
5
5
  }
6
- export declare const setMedia: import("@tramvai/types-actions-state-context").EventCreator1<Media, Media>;
6
+ export declare const setMedia: import("@tramvai/types-actions-state-context").EventCreator1<Media>;
7
7
  export declare const MediaStore: import("@tramvai/state").Reducer<Media, "media", never>;
8
+ //# sourceMappingURL=media.d.ts.map
@@ -2,3 +2,4 @@ import type { Media } from './media';
2
2
  export declare function fromClientHints(media: Media): boolean;
3
3
  export declare function isSupposed(media: Media): boolean;
4
4
  export declare function isRetina(media: Media): boolean;
5
+ //# sourceMappingURL=mediaCheckers.d.ts.map
@@ -3,3 +3,4 @@ export declare function useMedia(): Media;
3
3
  export declare function useFromClientHints(): boolean;
4
4
  export declare function useIsSupposed(): boolean;
5
5
  export declare function useIsRetina(): boolean;
6
+ //# sourceMappingURL=mediaSelectors.d.ts.map
@@ -1,3 +1,4 @@
1
1
  import type { UserAgent } from '@tinkoff/user-agent';
2
- export declare const setUserAgent: import("@tramvai/types-actions-state-context").EventCreator1<UserAgent, UserAgent>;
2
+ export declare const setUserAgent: import("@tramvai/types-actions-state-context").EventCreator1<UserAgent>;
3
3
  export declare const UserAgentStore: import("@tramvai/state").Reducer<UserAgent, "userAgent", never>;
4
+ //# sourceMappingURL=userAgent.d.ts.map
package/lib/tokens.d.ts CHANGED
@@ -7,3 +7,4 @@ export declare const PARSER_CLIENT_HINTS_ENABLED: (false & {
7
7
  }) | (true & {
8
8
  __type?: "base token" | undefined;
9
9
  });
10
+ //# sourceMappingURL=tokens.d.ts.map
package/lib/types.d.ts CHANGED
@@ -4,3 +4,4 @@ export interface MediaInfo {
4
4
  isTouch: boolean;
5
5
  retina: boolean;
6
6
  }
7
+ //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-client-hints",
3
- "version": "2.150.0",
3
+ "version": "2.150.1",
4
4
  "description": "",
5
5
  "main": "lib/server.js",
6
6
  "module": "lib/server.es.js",
@@ -19,21 +19,21 @@
19
19
  "watch": "tsc -w"
20
20
  },
21
21
  "dependencies": {
22
- "@tinkoff/user-agent": "0.4.434",
22
+ "@tinkoff/user-agent": "0.4.435",
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.150.0",
27
- "@tramvai/tokens-child-app": "2.150.0",
28
- "@tramvai/tokens-common": "2.150.0",
29
- "@tramvai/tokens-cookie": "2.150.0",
26
+ "@tramvai/module-metrics": "2.150.1",
27
+ "@tramvai/tokens-child-app": "2.150.1",
28
+ "@tramvai/tokens-common": "2.150.1",
29
+ "@tramvai/tokens-cookie": "2.150.1",
30
30
  "user-agent-data-types": "^0.3.1"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@tinkoff/dippy": "0.8.16",
34
34
  "@tinkoff/logger": "0.10.67",
35
- "@tramvai/core": "2.150.0",
36
- "@tramvai/state": "2.150.0",
35
+ "@tramvai/core": "2.150.1",
36
+ "@tramvai/state": "2.150.1",
37
37
  "react": ">=16.14.0",
38
38
  "react-dom": ">=16.14.0",
39
39
  "tslib": "^2.4.0"