@tramvai/module-cache-warmup 7.5.3 → 7.7.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.
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Request } from '@tinkoff/request-core';
2
2
  import { ExtractDependencyType } from '@tramvai/core';
3
+ import type { PrerenderRequest } from '@tramvai/tokens-router';
3
4
  import { CACHE_WARMUP_HOOKS_TOKEN } from './tokens';
4
5
  type QueueReuestsOptions<T> = {
5
6
  requestsOptions: T[];
@@ -16,7 +17,7 @@ export declare function queueRequests<T>(options: QueueReuestsOptions<T>): Promi
16
17
  result: "resolved" | "rejected" | "skipped";
17
18
  }[]>;
18
19
  export declare function createRequestsOptions(options: {
19
- urls: string[];
20
+ urls: Array<string | PrerenderRequest>;
20
21
  port: string;
21
22
  userAgents: string[];
22
23
  }): Request[];
package/lib/utils.es.js CHANGED
@@ -33,18 +33,38 @@ function createRequestsOptions(options) {
33
33
  const { urls, port } = options;
34
34
  return urls.reduce((requestOptions, url) => {
35
35
  const ip = generateRandomIPv4Adress();
36
- requestOptions.push(...options.userAgents.map((userAgent) => ({
37
- url: format({
38
- hostname: 'localhost',
39
- port,
40
- path: url,
41
- }),
42
- headers: {
43
- 'User-Agent': userAgent,
44
- 'X-Real-IP': ip,
45
- 'x-tramvai-service-name': 'CACHE_WARMUP',
46
- },
47
- })));
36
+ const prerenderRequest = typeof url === 'string' ? { pathname: url } : url;
37
+ const { pathname, headers, query } = prerenderRequest;
38
+ requestOptions.push(...(typeof url === 'string'
39
+ ? options.userAgents.map((userAgent) => ({
40
+ url: format({
41
+ hostname: 'localhost',
42
+ port,
43
+ path: pathname,
44
+ query,
45
+ }),
46
+ headers: {
47
+ 'User-Agent': userAgent,
48
+ 'X-Real-IP': ip,
49
+ ...headers,
50
+ 'x-tramvai-service-name': 'CACHE_WARMUP',
51
+ },
52
+ }))
53
+ : [
54
+ {
55
+ url: format({
56
+ hostname: 'localhost',
57
+ port,
58
+ path: pathname,
59
+ query,
60
+ }),
61
+ headers: {
62
+ 'X-Real-IP': ip,
63
+ ...headers,
64
+ 'x-tramvai-service-name': 'CACHE_WARMUP',
65
+ },
66
+ },
67
+ ]));
48
68
  return requestOptions;
49
69
  }, []);
50
70
  }
package/lib/utils.js CHANGED
@@ -42,18 +42,38 @@ function createRequestsOptions(options) {
42
42
  const { urls, port } = options;
43
43
  return urls.reduce((requestOptions, url$1) => {
44
44
  const ip = generateRandomIPv4Adress();
45
- requestOptions.push(...options.userAgents.map((userAgent) => ({
46
- url: url.format({
47
- hostname: 'localhost',
48
- port,
49
- path: url$1,
50
- }),
51
- headers: {
52
- 'User-Agent': userAgent,
53
- 'X-Real-IP': ip,
54
- 'x-tramvai-service-name': 'CACHE_WARMUP',
55
- },
56
- })));
45
+ const prerenderRequest = typeof url$1 === 'string' ? { pathname: url$1 } : url$1;
46
+ const { pathname, headers, query } = prerenderRequest;
47
+ requestOptions.push(...(typeof url$1 === 'string'
48
+ ? options.userAgents.map((userAgent) => ({
49
+ url: url.format({
50
+ hostname: 'localhost',
51
+ port,
52
+ path: pathname,
53
+ query,
54
+ }),
55
+ headers: {
56
+ 'User-Agent': userAgent,
57
+ 'X-Real-IP': ip,
58
+ ...headers,
59
+ 'x-tramvai-service-name': 'CACHE_WARMUP',
60
+ },
61
+ }))
62
+ : [
63
+ {
64
+ url: url.format({
65
+ hostname: 'localhost',
66
+ port,
67
+ path: pathname,
68
+ query,
69
+ }),
70
+ headers: {
71
+ 'X-Real-IP': ip,
72
+ ...headers,
73
+ 'x-tramvai-service-name': 'CACHE_WARMUP',
74
+ },
75
+ },
76
+ ]));
57
77
  return requestOptions;
58
78
  }, []);
59
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-cache-warmup",
3
- "version": "7.5.3",
3
+ "version": "7.7.0",
4
4
  "description": "tramvai cache warmup module",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -22,13 +22,14 @@
22
22
  "@tinkoff/request-core": "^0.10.0",
23
23
  "@tinkoff/request-plugin-protocol-http": "0.16.0",
24
24
  "@tinkoff/url": "0.13.1",
25
+ "@tramvai/tokens-router": "7.7.0",
25
26
  "undici": "^7.18.2"
26
27
  },
27
28
  "peerDependencies": {
28
- "@tramvai/core": "7.5.3",
29
- "@tramvai/module-common": "7.5.3",
30
- "@tramvai/state": "7.5.3",
31
- "@tramvai/tokens-http-client": "7.5.3",
29
+ "@tramvai/core": "7.7.0",
30
+ "@tramvai/module-common": "7.7.0",
31
+ "@tramvai/state": "7.7.0",
32
+ "@tramvai/tokens-http-client": "7.7.0",
32
33
  "tslib": "^2.4.0"
33
34
  },
34
35
  "module": "lib/server.es.js",