@tramvai/module-page-render-mode 2.90.0 → 2.91.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/lib/browser.js +1 -1
- package/lib/server.es.js +1 -1
- package/lib/server.js +0 -1
- package/lib/staticPages/staticPagesService.d.ts +3 -6
- package/lib/staticPages/staticPagesService.es.js +36 -23
- package/lib/staticPages/staticPagesService.js +36 -23
- package/lib/staticPages.d.ts +0 -6
- package/lib/staticPages.es.js +3 -21
- package/lib/staticPages.js +2 -24
- package/lib/tokens.browser.js +1 -2
- package/lib/tokens.d.ts +0 -3
- package/lib/tokens.es.js +1 -2
- package/lib/tokens.js +0 -2
- package/package.json +13 -13
package/lib/browser.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { declareModule } from '@tramvai/core';
|
|
2
2
|
import { ForceCSRModule } from './ForceCSRModule.browser.js';
|
|
3
3
|
import { sharedProviders } from './shared.browser.js';
|
|
4
|
-
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN,
|
|
4
|
+
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN, STATIC_PAGES_SHOULD_USE_CACHE } from './tokens.browser.js';
|
|
5
5
|
|
|
6
6
|
// @todo: перенести в @tramvai/module-render
|
|
7
7
|
const PageRenderModeModule = declareModule({
|
package/lib/server.es.js
CHANGED
|
@@ -2,7 +2,7 @@ import { declareModule } from '@tramvai/core';
|
|
|
2
2
|
import { ForceCSRModule } from './ForceCSRModule.es.js';
|
|
3
3
|
import { sharedProviders } from './shared.es.js';
|
|
4
4
|
import { staticPagesProviders } from './staticPages.es.js';
|
|
5
|
-
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN,
|
|
5
|
+
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN, STATIC_PAGES_SHOULD_USE_CACHE } from './tokens.es.js';
|
|
6
6
|
|
|
7
7
|
// @todo: перенести в @tramvai/module-render
|
|
8
8
|
const PageRenderModeModule = declareModule({
|
package/lib/server.js
CHANGED
|
@@ -25,6 +25,5 @@ exports.STATIC_PAGES_CACHE_TOKEN = tokens.STATIC_PAGES_CACHE_TOKEN;
|
|
|
25
25
|
exports.STATIC_PAGES_COMMAND_LINE = tokens.STATIC_PAGES_COMMAND_LINE;
|
|
26
26
|
exports.STATIC_PAGES_MODIFY_CACHE = tokens.STATIC_PAGES_MODIFY_CACHE;
|
|
27
27
|
exports.STATIC_PAGES_OPTIONS_TOKEN = tokens.STATIC_PAGES_OPTIONS_TOKEN;
|
|
28
|
-
exports.STATIC_PAGES_SHOULD_SET_TO_CACHE = tokens.STATIC_PAGES_SHOULD_SET_TO_CACHE;
|
|
29
28
|
exports.STATIC_PAGES_SHOULD_USE_CACHE = tokens.STATIC_PAGES_SHOULD_USE_CACHE;
|
|
30
29
|
exports.PageRenderModeModule = PageRenderModeModule;
|
|
@@ -4,12 +4,11 @@ import type { ENV_MANAGER_TOKEN, LOGGER_TOKEN, REQUEST_MANAGER_TOKEN, RESPONSE_M
|
|
|
4
4
|
import type { FASTIFY_RESPONSE } from '@tramvai/tokens-server-private';
|
|
5
5
|
import type { MODERN_SATISFIES_TOKEN } from '@tramvai/tokens-render';
|
|
6
6
|
import type { STATIC_PAGES_BACKGROUND_FETCH_SERVICE, STATIC_PAGES_GET_CACHE_KEY_TOKEN } from '../staticPages';
|
|
7
|
-
import type { STATIC_PAGES_SHOULD_USE_CACHE,
|
|
7
|
+
import type { STATIC_PAGES_SHOULD_USE_CACHE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN, STATIC_PAGES_CACHE_5xx_RESPONSE } from '../tokens';
|
|
8
8
|
type ResponseManager = ExtractDependencyType<typeof RESPONSE_MANAGER_TOKEN>;
|
|
9
9
|
type Response = ExtractDependencyType<typeof FASTIFY_RESPONSE>;
|
|
10
10
|
type Logger = ExtractDependencyType<typeof LOGGER_TOKEN>;
|
|
11
11
|
type ShouldUseCache = ExtractDependencyType<typeof STATIC_PAGES_SHOULD_USE_CACHE>;
|
|
12
|
-
type ShouldSetToCache = ExtractDependencyType<typeof STATIC_PAGES_SHOULD_SET_TO_CACHE>;
|
|
13
12
|
type BackgroundFetchService = ExtractDependencyType<typeof STATIC_PAGES_BACKGROUND_FETCH_SERVICE>;
|
|
14
13
|
type Cache = ExtractDependencyType<typeof STATIC_PAGES_CACHE_TOKEN>;
|
|
15
14
|
type ModifyCache = ExtractDependencyType<typeof STATIC_PAGES_MODIFY_CACHE> | null;
|
|
@@ -30,8 +29,7 @@ export declare class StaticPagesService {
|
|
|
30
29
|
private options;
|
|
31
30
|
private cache5xxResponse;
|
|
32
31
|
shouldUseCache: () => boolean;
|
|
33
|
-
|
|
34
|
-
constructor({ getCacheKey, requestManager, response, responseManager, environmentManager, userAgent, modern, logger, cache, modifyCache, shouldUseCache, shouldSetToCache, backgroundFetchService, options, cache5xxResponse, }: {
|
|
32
|
+
constructor({ getCacheKey, requestManager, response, responseManager, environmentManager, userAgent, modern, logger, cache, modifyCache, shouldUseCache, backgroundFetchService, options, cache5xxResponse, }: {
|
|
35
33
|
getCacheKey: ExtractDependencyType<typeof STATIC_PAGES_GET_CACHE_KEY_TOKEN>;
|
|
36
34
|
requestManager: ExtractDependencyType<typeof REQUEST_MANAGER_TOKEN>;
|
|
37
35
|
responseManager: ResponseManager;
|
|
@@ -43,16 +41,15 @@ export declare class StaticPagesService {
|
|
|
43
41
|
cache: Cache;
|
|
44
42
|
modifyCache: ModifyCache;
|
|
45
43
|
shouldUseCache: ShouldUseCache;
|
|
46
|
-
shouldSetToCache: ShouldSetToCache;
|
|
47
44
|
backgroundFetchService: BackgroundFetchService;
|
|
48
45
|
options: Options;
|
|
49
46
|
cache5xxResponse: Cache5xxResponse;
|
|
50
47
|
});
|
|
51
48
|
respond(onSuccess: () => void): void;
|
|
52
|
-
saveResponse(): void;
|
|
53
49
|
revalidate(): Promise<void>;
|
|
54
50
|
private hasCache;
|
|
55
51
|
private getCache;
|
|
56
52
|
private setCache;
|
|
53
|
+
private cacheOutdated;
|
|
57
54
|
}
|
|
58
55
|
export {};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
// It is critical to ignore cached Set-Cookie header and use fresh one from current request
|
|
2
|
+
// COMMAND_LINE_EXECUTION_END_TOKEN with fresh server timings will not works for responses from cache
|
|
3
|
+
const HEADERS_BLACKLIST = ['Set-Cookie', 'server-timing'];
|
|
1
4
|
class StaticPagesService {
|
|
2
|
-
constructor({ getCacheKey, requestManager, response, responseManager, environmentManager, userAgent, modern, logger, cache, modifyCache, shouldUseCache,
|
|
5
|
+
constructor({ getCacheKey, requestManager, response, responseManager, environmentManager, userAgent, modern, logger, cache, modifyCache, shouldUseCache, backgroundFetchService, options, cache5xxResponse, }) {
|
|
3
6
|
this.key = getCacheKey();
|
|
4
7
|
this.path = requestManager.getParsedUrl().pathname;
|
|
5
8
|
this.port = environmentManager.get('PORT');
|
|
@@ -11,7 +14,6 @@ class StaticPagesService {
|
|
|
11
14
|
this.cache = cache;
|
|
12
15
|
this.modifyCache = modifyCache;
|
|
13
16
|
this.shouldUseCache = () => shouldUseCache.every((fn) => fn());
|
|
14
|
-
this.shouldSetToCache = () => shouldSetToCache.every((fn) => fn());
|
|
15
17
|
this.backgroundFetchService = backgroundFetchService;
|
|
16
18
|
this.options = options;
|
|
17
19
|
this.cache5xxResponse = cache5xxResponse;
|
|
@@ -24,20 +26,28 @@ class StaticPagesService {
|
|
|
24
26
|
});
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
|
-
const { ttl } = this.options;
|
|
28
29
|
let cacheEntry = this.getCache();
|
|
29
30
|
if (Array.isArray(this.modifyCache)) {
|
|
30
31
|
cacheEntry = this.modifyCache.reduce((result, modifier) => {
|
|
31
32
|
return modifier(result);
|
|
32
33
|
}, cacheEntry);
|
|
33
34
|
}
|
|
34
|
-
const {
|
|
35
|
-
const isOutdated =
|
|
35
|
+
const { status, headers, body } = cacheEntry;
|
|
36
|
+
const isOutdated = this.cacheOutdated(cacheEntry);
|
|
37
|
+
const currentHeaders = this.responseManager.getHeaders();
|
|
36
38
|
if (!isOutdated) {
|
|
37
39
|
this.log.debug({
|
|
38
40
|
event: 'cache-hit',
|
|
39
41
|
key: this.key,
|
|
40
42
|
});
|
|
43
|
+
HEADERS_BLACKLIST.forEach((header) => {
|
|
44
|
+
if (headers[header]) {
|
|
45
|
+
delete headers[header];
|
|
46
|
+
}
|
|
47
|
+
if (currentHeaders[header]) {
|
|
48
|
+
headers[header] = currentHeaders[header];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
41
51
|
this.response
|
|
42
52
|
.header('content-type', 'text/html')
|
|
43
53
|
.header('X-Tramvai-Static-Page-From-Cache', 'true')
|
|
@@ -53,28 +63,17 @@ class StaticPagesService {
|
|
|
53
63
|
});
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
|
-
saveResponse() {
|
|
57
|
-
if (!this.cache5xxResponse() && this.responseManager.getStatus() >= 500) {
|
|
58
|
-
this.log.debug({
|
|
59
|
-
event: 'cache-set-5xx',
|
|
60
|
-
key: this.key,
|
|
61
|
-
});
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this.log.debug({
|
|
65
|
-
event: 'cache-set',
|
|
66
|
-
key: this.key,
|
|
67
|
-
});
|
|
68
|
-
this.setCache({
|
|
69
|
-
status: this.responseManager.getStatus(),
|
|
70
|
-
headers: this.responseManager.getHeaders(),
|
|
71
|
-
body: this.responseManager.getBody(),
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
66
|
async revalidate() {
|
|
75
67
|
if (!this.backgroundFetchService.enabled()) {
|
|
76
68
|
return;
|
|
77
69
|
}
|
|
70
|
+
if (this.hasCache()) {
|
|
71
|
+
const cacheEntry = this.getCache();
|
|
72
|
+
const isOutdated = this.cacheOutdated(cacheEntry);
|
|
73
|
+
if (!isOutdated) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
78
77
|
await this.backgroundFetchService
|
|
79
78
|
.revalidate({
|
|
80
79
|
key: this.key,
|
|
@@ -88,6 +87,10 @@ class StaticPagesService {
|
|
|
88
87
|
return;
|
|
89
88
|
}
|
|
90
89
|
if (!this.cache5xxResponse() && response.status >= 500) {
|
|
90
|
+
this.log.debug({
|
|
91
|
+
event: 'cache-set-5xx',
|
|
92
|
+
key: this.key,
|
|
93
|
+
});
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
96
|
this.setCache(response);
|
|
@@ -100,6 +103,10 @@ class StaticPagesService {
|
|
|
100
103
|
return this.cache.get(this.path).get(this.key);
|
|
101
104
|
}
|
|
102
105
|
setCache(cacheEntry) {
|
|
106
|
+
this.log.debug({
|
|
107
|
+
event: 'cache-set',
|
|
108
|
+
key: this.key,
|
|
109
|
+
});
|
|
103
110
|
if (!this.cache.has(this.path)) {
|
|
104
111
|
this.cache.set(this.path, new Map());
|
|
105
112
|
}
|
|
@@ -108,6 +115,12 @@ class StaticPagesService {
|
|
|
108
115
|
updatedAt: Date.now(),
|
|
109
116
|
});
|
|
110
117
|
}
|
|
118
|
+
cacheOutdated(cacheEntry) {
|
|
119
|
+
const { ttl } = this.options;
|
|
120
|
+
const { updatedAt } = cacheEntry;
|
|
121
|
+
const isOutdated = updatedAt + ttl <= Date.now();
|
|
122
|
+
return isOutdated;
|
|
123
|
+
}
|
|
111
124
|
}
|
|
112
125
|
|
|
113
126
|
export { StaticPagesService };
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
// It is critical to ignore cached Set-Cookie header and use fresh one from current request
|
|
6
|
+
// COMMAND_LINE_EXECUTION_END_TOKEN with fresh server timings will not works for responses from cache
|
|
7
|
+
const HEADERS_BLACKLIST = ['Set-Cookie', 'server-timing'];
|
|
5
8
|
class StaticPagesService {
|
|
6
|
-
constructor({ getCacheKey, requestManager, response, responseManager, environmentManager, userAgent, modern, logger, cache, modifyCache, shouldUseCache,
|
|
9
|
+
constructor({ getCacheKey, requestManager, response, responseManager, environmentManager, userAgent, modern, logger, cache, modifyCache, shouldUseCache, backgroundFetchService, options, cache5xxResponse, }) {
|
|
7
10
|
this.key = getCacheKey();
|
|
8
11
|
this.path = requestManager.getParsedUrl().pathname;
|
|
9
12
|
this.port = environmentManager.get('PORT');
|
|
@@ -15,7 +18,6 @@ class StaticPagesService {
|
|
|
15
18
|
this.cache = cache;
|
|
16
19
|
this.modifyCache = modifyCache;
|
|
17
20
|
this.shouldUseCache = () => shouldUseCache.every((fn) => fn());
|
|
18
|
-
this.shouldSetToCache = () => shouldSetToCache.every((fn) => fn());
|
|
19
21
|
this.backgroundFetchService = backgroundFetchService;
|
|
20
22
|
this.options = options;
|
|
21
23
|
this.cache5xxResponse = cache5xxResponse;
|
|
@@ -28,20 +30,28 @@ class StaticPagesService {
|
|
|
28
30
|
});
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
|
-
const { ttl } = this.options;
|
|
32
33
|
let cacheEntry = this.getCache();
|
|
33
34
|
if (Array.isArray(this.modifyCache)) {
|
|
34
35
|
cacheEntry = this.modifyCache.reduce((result, modifier) => {
|
|
35
36
|
return modifier(result);
|
|
36
37
|
}, cacheEntry);
|
|
37
38
|
}
|
|
38
|
-
const {
|
|
39
|
-
const isOutdated =
|
|
39
|
+
const { status, headers, body } = cacheEntry;
|
|
40
|
+
const isOutdated = this.cacheOutdated(cacheEntry);
|
|
41
|
+
const currentHeaders = this.responseManager.getHeaders();
|
|
40
42
|
if (!isOutdated) {
|
|
41
43
|
this.log.debug({
|
|
42
44
|
event: 'cache-hit',
|
|
43
45
|
key: this.key,
|
|
44
46
|
});
|
|
47
|
+
HEADERS_BLACKLIST.forEach((header) => {
|
|
48
|
+
if (headers[header]) {
|
|
49
|
+
delete headers[header];
|
|
50
|
+
}
|
|
51
|
+
if (currentHeaders[header]) {
|
|
52
|
+
headers[header] = currentHeaders[header];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
45
55
|
this.response
|
|
46
56
|
.header('content-type', 'text/html')
|
|
47
57
|
.header('X-Tramvai-Static-Page-From-Cache', 'true')
|
|
@@ -57,28 +67,17 @@ class StaticPagesService {
|
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
|
-
saveResponse() {
|
|
61
|
-
if (!this.cache5xxResponse() && this.responseManager.getStatus() >= 500) {
|
|
62
|
-
this.log.debug({
|
|
63
|
-
event: 'cache-set-5xx',
|
|
64
|
-
key: this.key,
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
this.log.debug({
|
|
69
|
-
event: 'cache-set',
|
|
70
|
-
key: this.key,
|
|
71
|
-
});
|
|
72
|
-
this.setCache({
|
|
73
|
-
status: this.responseManager.getStatus(),
|
|
74
|
-
headers: this.responseManager.getHeaders(),
|
|
75
|
-
body: this.responseManager.getBody(),
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
70
|
async revalidate() {
|
|
79
71
|
if (!this.backgroundFetchService.enabled()) {
|
|
80
72
|
return;
|
|
81
73
|
}
|
|
74
|
+
if (this.hasCache()) {
|
|
75
|
+
const cacheEntry = this.getCache();
|
|
76
|
+
const isOutdated = this.cacheOutdated(cacheEntry);
|
|
77
|
+
if (!isOutdated) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
82
81
|
await this.backgroundFetchService
|
|
83
82
|
.revalidate({
|
|
84
83
|
key: this.key,
|
|
@@ -92,6 +91,10 @@ class StaticPagesService {
|
|
|
92
91
|
return;
|
|
93
92
|
}
|
|
94
93
|
if (!this.cache5xxResponse() && response.status >= 500) {
|
|
94
|
+
this.log.debug({
|
|
95
|
+
event: 'cache-set-5xx',
|
|
96
|
+
key: this.key,
|
|
97
|
+
});
|
|
95
98
|
return;
|
|
96
99
|
}
|
|
97
100
|
this.setCache(response);
|
|
@@ -104,6 +107,10 @@ class StaticPagesService {
|
|
|
104
107
|
return this.cache.get(this.path).get(this.key);
|
|
105
108
|
}
|
|
106
109
|
setCache(cacheEntry) {
|
|
110
|
+
this.log.debug({
|
|
111
|
+
event: 'cache-set',
|
|
112
|
+
key: this.key,
|
|
113
|
+
});
|
|
107
114
|
if (!this.cache.has(this.path)) {
|
|
108
115
|
this.cache.set(this.path, new Map());
|
|
109
116
|
}
|
|
@@ -112,6 +119,12 @@ class StaticPagesService {
|
|
|
112
119
|
updatedAt: Date.now(),
|
|
113
120
|
});
|
|
114
121
|
}
|
|
122
|
+
cacheOutdated(cacheEntry) {
|
|
123
|
+
const { ttl } = this.options;
|
|
124
|
+
const { updatedAt } = cacheEntry;
|
|
125
|
+
const isOutdated = updatedAt + ttl <= Date.now();
|
|
126
|
+
return isOutdated;
|
|
127
|
+
}
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
exports.StaticPagesService = StaticPagesService;
|
package/lib/staticPages.d.ts
CHANGED
|
@@ -139,9 +139,6 @@ export declare const staticPagesProviders: (import("@tinkoff/dippy/lib/Provider"
|
|
|
139
139
|
shouldUseCache: (() => boolean) & {
|
|
140
140
|
__type?: "multi token";
|
|
141
141
|
};
|
|
142
|
-
shouldSetToCache: (() => boolean) & {
|
|
143
|
-
__type?: "multi token";
|
|
144
|
-
};
|
|
145
142
|
backgroundFetchService: BackgroundFetchService & {
|
|
146
143
|
__type?: "base token";
|
|
147
144
|
};
|
|
@@ -193,9 +190,6 @@ export declare const staticPagesProviders: (import("@tinkoff/dippy/lib/Provider"
|
|
|
193
190
|
shouldUseCache: (() => boolean) & {
|
|
194
191
|
__type?: "multi token";
|
|
195
192
|
};
|
|
196
|
-
shouldSetToCache: (() => boolean) & {
|
|
197
|
-
__type?: "multi token";
|
|
198
|
-
};
|
|
199
193
|
backgroundFetchService: BackgroundFetchService & {
|
|
200
194
|
__type?: "base token";
|
|
201
195
|
};
|
package/lib/staticPages.es.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import isEmpty from '@tinkoff/utils/is/empty';
|
|
2
1
|
import { createToken, provide, Scope, commandLineListTokens, DI_TOKEN } from '@tramvai/core';
|
|
3
2
|
import { CREATE_CACHE_TOKEN, REQUEST_MANAGER_TOKEN, LOGGER_TOKEN, RESPONSE_MANAGER_TOKEN, ENV_MANAGER_TOKEN } from '@tramvai/tokens-common';
|
|
4
3
|
import { FASTIFY_RESPONSE } from '@tramvai/tokens-server-private';
|
|
@@ -9,7 +8,7 @@ import { SERVER_MODULE_PAPI_PRIVATE_ROUTE } from '@tramvai/tokens-server';
|
|
|
9
8
|
import { METRICS_MODULE_TOKEN } from '@tramvai/tokens-metrics';
|
|
10
9
|
import { createPapiMethod } from '@tramvai/papi';
|
|
11
10
|
import { StopCommandLineRunnerError } from './error.es.js';
|
|
12
|
-
import { STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_OPTIONS_TOKEN,
|
|
11
|
+
import { STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_OPTIONS_TOKEN, STATIC_PAGES_SHOULD_USE_CACHE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_COMMAND_LINE, PAGE_RENDER_DEFAULT_MODE } from './tokens.es.js';
|
|
13
12
|
import { getPageRenderMode } from './utils/getPageRenderMode.es.js';
|
|
14
13
|
import { getCacheKey } from './utils/cacheKey.es.js';
|
|
15
14
|
import { BackgroundFetchService } from './staticPages/backgroundFetchService.es.js';
|
|
@@ -76,17 +75,6 @@ const staticPagesProviders = [
|
|
|
76
75
|
modern: MODERN_SATISFIES_TOKEN,
|
|
77
76
|
},
|
|
78
77
|
}),
|
|
79
|
-
provide({
|
|
80
|
-
provide: STATIC_PAGES_SHOULD_SET_TO_CACHE,
|
|
81
|
-
useFactory: ({ requestManager }) => {
|
|
82
|
-
return () => {
|
|
83
|
-
return isEmpty(requestManager.getCookies());
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
deps: {
|
|
87
|
-
requestManager: REQUEST_MANAGER_TOKEN,
|
|
88
|
-
},
|
|
89
|
-
}),
|
|
90
78
|
provide({
|
|
91
79
|
provide: STATIC_PAGES_SHOULD_USE_CACHE,
|
|
92
80
|
useFactory: ({ requestManager }) => {
|
|
@@ -112,7 +100,7 @@ const staticPagesProviders = [
|
|
|
112
100
|
}),
|
|
113
101
|
provide({
|
|
114
102
|
provide: STATIC_PAGES_BACKGROUND_FETCH_SERVICE,
|
|
115
|
-
scope: Scope.
|
|
103
|
+
scope: Scope.SINGLETON,
|
|
116
104
|
useClass: BackgroundFetchService,
|
|
117
105
|
deps: {
|
|
118
106
|
logger: LOGGER_TOKEN,
|
|
@@ -135,7 +123,6 @@ const staticPagesProviders = [
|
|
|
135
123
|
cache: STATIC_PAGES_CACHE_TOKEN,
|
|
136
124
|
modifyCache: { token: STATIC_PAGES_MODIFY_CACHE, optional: true },
|
|
137
125
|
shouldUseCache: STATIC_PAGES_SHOULD_USE_CACHE,
|
|
138
|
-
shouldSetToCache: STATIC_PAGES_SHOULD_SET_TO_CACHE,
|
|
139
126
|
backgroundFetchService: STATIC_PAGES_BACKGROUND_FETCH_SERVICE,
|
|
140
127
|
options: STATIC_PAGES_OPTIONS_TOKEN,
|
|
141
128
|
cache5xxResponse: STATIC_PAGES_CACHE_5xx_RESPONSE,
|
|
@@ -184,12 +171,7 @@ const staticPagesProviders = [
|
|
|
184
171
|
if (!isStaticPage) {
|
|
185
172
|
return;
|
|
186
173
|
}
|
|
187
|
-
|
|
188
|
-
staticPagesService.saveResponse();
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
staticPagesService.revalidate();
|
|
192
|
-
}
|
|
174
|
+
staticPagesService.revalidate();
|
|
193
175
|
};
|
|
194
176
|
},
|
|
195
177
|
deps: {
|
package/lib/staticPages.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var isEmpty = require('@tinkoff/utils/is/empty');
|
|
6
5
|
var core = require('@tramvai/core');
|
|
7
6
|
var tokensCommon = require('@tramvai/tokens-common');
|
|
8
7
|
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
@@ -19,10 +18,6 @@ var cacheKey = require('./utils/cacheKey.js');
|
|
|
19
18
|
var backgroundFetchService = require('./staticPages/backgroundFetchService.js');
|
|
20
19
|
var staticPagesService = require('./staticPages/staticPagesService.js');
|
|
21
20
|
|
|
22
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
|
-
|
|
24
|
-
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
25
|
-
|
|
26
21
|
const STATIC_PAGES_BACKGROUND_FETCH_SERVICE = core.createToken();
|
|
27
22
|
const STATIC_PAGES_GET_CACHE_KEY_TOKEN = core.createToken();
|
|
28
23
|
const STATIC_PAGES_CACHE_HIT_METRIC_TOKEN = core.createToken();
|
|
@@ -84,17 +79,6 @@ const staticPagesProviders = [
|
|
|
84
79
|
modern: tokensRender.MODERN_SATISFIES_TOKEN,
|
|
85
80
|
},
|
|
86
81
|
}),
|
|
87
|
-
core.provide({
|
|
88
|
-
provide: tokens.STATIC_PAGES_SHOULD_SET_TO_CACHE,
|
|
89
|
-
useFactory: ({ requestManager }) => {
|
|
90
|
-
return () => {
|
|
91
|
-
return isEmpty__default["default"](requestManager.getCookies());
|
|
92
|
-
};
|
|
93
|
-
},
|
|
94
|
-
deps: {
|
|
95
|
-
requestManager: tokensCommon.REQUEST_MANAGER_TOKEN,
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
82
|
core.provide({
|
|
99
83
|
provide: tokens.STATIC_PAGES_SHOULD_USE_CACHE,
|
|
100
84
|
useFactory: ({ requestManager }) => {
|
|
@@ -120,7 +104,7 @@ const staticPagesProviders = [
|
|
|
120
104
|
}),
|
|
121
105
|
core.provide({
|
|
122
106
|
provide: STATIC_PAGES_BACKGROUND_FETCH_SERVICE,
|
|
123
|
-
scope: core.Scope.
|
|
107
|
+
scope: core.Scope.SINGLETON,
|
|
124
108
|
useClass: backgroundFetchService.BackgroundFetchService,
|
|
125
109
|
deps: {
|
|
126
110
|
logger: tokensCommon.LOGGER_TOKEN,
|
|
@@ -143,7 +127,6 @@ const staticPagesProviders = [
|
|
|
143
127
|
cache: tokens.STATIC_PAGES_CACHE_TOKEN,
|
|
144
128
|
modifyCache: { token: tokens.STATIC_PAGES_MODIFY_CACHE, optional: true },
|
|
145
129
|
shouldUseCache: tokens.STATIC_PAGES_SHOULD_USE_CACHE,
|
|
146
|
-
shouldSetToCache: tokens.STATIC_PAGES_SHOULD_SET_TO_CACHE,
|
|
147
130
|
backgroundFetchService: STATIC_PAGES_BACKGROUND_FETCH_SERVICE,
|
|
148
131
|
options: tokens.STATIC_PAGES_OPTIONS_TOKEN,
|
|
149
132
|
cache5xxResponse: tokens.STATIC_PAGES_CACHE_5xx_RESPONSE,
|
|
@@ -192,12 +175,7 @@ const staticPagesProviders = [
|
|
|
192
175
|
if (!isStaticPage) {
|
|
193
176
|
return;
|
|
194
177
|
}
|
|
195
|
-
|
|
196
|
-
staticPagesService.saveResponse();
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
staticPagesService.revalidate();
|
|
200
|
-
}
|
|
178
|
+
staticPagesService.revalidate();
|
|
201
179
|
};
|
|
202
180
|
},
|
|
203
181
|
deps: {
|
package/lib/tokens.browser.js
CHANGED
|
@@ -9,11 +9,10 @@ const PAGE_RENDER_WRAPPER_TYPE = createToken('pageRenderWrapperType');
|
|
|
9
9
|
const PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT = createToken('pageRenderDefaultFallbackComponent');
|
|
10
10
|
const STATIC_PAGES_CACHE_TOKEN = createToken('static pages cache');
|
|
11
11
|
const STATIC_PAGES_SHOULD_USE_CACHE = createToken('static pages should use cache', { multi: true });
|
|
12
|
-
const STATIC_PAGES_SHOULD_SET_TO_CACHE = createToken('static pages should set to cache', { multi: true });
|
|
13
12
|
const STATIC_PAGES_BACKGROUND_FETCH_ENABLED = createToken('static pages can fetch page');
|
|
14
13
|
const STATIC_PAGES_OPTIONS_TOKEN = createToken('static pages options');
|
|
15
14
|
const STATIC_PAGES_COMMAND_LINE = createToken('static pages command line');
|
|
16
15
|
const STATIC_PAGES_MODIFY_CACHE = createToken('static pages modify cache', { multi: true });
|
|
17
16
|
const STATIC_PAGES_CACHE_5xx_RESPONSE = createToken('static pages cache 5xx response');
|
|
18
17
|
|
|
19
|
-
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN,
|
|
18
|
+
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN, STATIC_PAGES_SHOULD_USE_CACHE };
|
package/lib/tokens.d.ts
CHANGED
|
@@ -48,9 +48,6 @@ export declare const STATIC_PAGES_CACHE_TOKEN: Cache<Map<string, StaticPagesCach
|
|
|
48
48
|
export declare const STATIC_PAGES_SHOULD_USE_CACHE: (() => boolean) & {
|
|
49
49
|
__type?: "multi token";
|
|
50
50
|
};
|
|
51
|
-
export declare const STATIC_PAGES_SHOULD_SET_TO_CACHE: (() => boolean) & {
|
|
52
|
-
__type?: "multi token";
|
|
53
|
-
};
|
|
54
51
|
export declare const STATIC_PAGES_BACKGROUND_FETCH_ENABLED: (() => boolean) & {
|
|
55
52
|
__type?: "base token";
|
|
56
53
|
};
|
package/lib/tokens.es.js
CHANGED
|
@@ -9,11 +9,10 @@ const PAGE_RENDER_WRAPPER_TYPE = createToken('pageRenderWrapperType');
|
|
|
9
9
|
const PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT = createToken('pageRenderDefaultFallbackComponent');
|
|
10
10
|
const STATIC_PAGES_CACHE_TOKEN = createToken('static pages cache');
|
|
11
11
|
const STATIC_PAGES_SHOULD_USE_CACHE = createToken('static pages should use cache', { multi: true });
|
|
12
|
-
const STATIC_PAGES_SHOULD_SET_TO_CACHE = createToken('static pages should set to cache', { multi: true });
|
|
13
12
|
const STATIC_PAGES_BACKGROUND_FETCH_ENABLED = createToken('static pages can fetch page');
|
|
14
13
|
const STATIC_PAGES_OPTIONS_TOKEN = createToken('static pages options');
|
|
15
14
|
const STATIC_PAGES_COMMAND_LINE = createToken('static pages command line');
|
|
16
15
|
const STATIC_PAGES_MODIFY_CACHE = createToken('static pages modify cache', { multi: true });
|
|
17
16
|
const STATIC_PAGES_CACHE_5xx_RESPONSE = createToken('static pages cache 5xx response');
|
|
18
17
|
|
|
19
|
-
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN,
|
|
18
|
+
export { PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT, PAGE_RENDER_DEFAULT_MODE, PAGE_RENDER_FALLBACK_COMPONENT_PREFIX, PAGE_RENDER_WRAPPER_TYPE, STATIC_PAGES_BACKGROUND_FETCH_ENABLED, STATIC_PAGES_CACHE_5xx_RESPONSE, STATIC_PAGES_CACHE_TOKEN, STATIC_PAGES_COMMAND_LINE, STATIC_PAGES_MODIFY_CACHE, STATIC_PAGES_OPTIONS_TOKEN, STATIC_PAGES_SHOULD_USE_CACHE };
|
package/lib/tokens.js
CHANGED
|
@@ -13,7 +13,6 @@ const PAGE_RENDER_WRAPPER_TYPE = dippy.createToken('pageRenderWrapperType');
|
|
|
13
13
|
const PAGE_RENDER_DEFAULT_FALLBACK_COMPONENT = dippy.createToken('pageRenderDefaultFallbackComponent');
|
|
14
14
|
const STATIC_PAGES_CACHE_TOKEN = dippy.createToken('static pages cache');
|
|
15
15
|
const STATIC_PAGES_SHOULD_USE_CACHE = dippy.createToken('static pages should use cache', { multi: true });
|
|
16
|
-
const STATIC_PAGES_SHOULD_SET_TO_CACHE = dippy.createToken('static pages should set to cache', { multi: true });
|
|
17
16
|
const STATIC_PAGES_BACKGROUND_FETCH_ENABLED = dippy.createToken('static pages can fetch page');
|
|
18
17
|
const STATIC_PAGES_OPTIONS_TOKEN = dippy.createToken('static pages options');
|
|
19
18
|
const STATIC_PAGES_COMMAND_LINE = dippy.createToken('static pages command line');
|
|
@@ -30,5 +29,4 @@ exports.STATIC_PAGES_CACHE_TOKEN = STATIC_PAGES_CACHE_TOKEN;
|
|
|
30
29
|
exports.STATIC_PAGES_COMMAND_LINE = STATIC_PAGES_COMMAND_LINE;
|
|
31
30
|
exports.STATIC_PAGES_MODIFY_CACHE = STATIC_PAGES_MODIFY_CACHE;
|
|
32
31
|
exports.STATIC_PAGES_OPTIONS_TOKEN = STATIC_PAGES_OPTIONS_TOKEN;
|
|
33
|
-
exports.STATIC_PAGES_SHOULD_SET_TO_CACHE = STATIC_PAGES_SHOULD_SET_TO_CACHE;
|
|
34
32
|
exports.STATIC_PAGES_SHOULD_USE_CACHE = STATIC_PAGES_SHOULD_USE_CACHE;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-page-render-mode",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.91.1",
|
|
4
4
|
"description": "Enable different rendering modes for pages",
|
|
5
5
|
"main": "./lib/server.js",
|
|
6
6
|
"module": "./lib/server.es.js",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@tinkoff/utils": "^2.1.2",
|
|
32
32
|
"@tinkoff/dippy": "0.8.15",
|
|
33
|
-
"@tramvai/core": "2.
|
|
34
|
-
"@tramvai/react": "2.
|
|
35
|
-
"@tramvai/papi": "2.
|
|
36
|
-
"@tramvai/module-router": "2.
|
|
37
|
-
"@tramvai/module-client-hints": "2.
|
|
38
|
-
"@tramvai/tokens-common": "2.
|
|
39
|
-
"@tramvai/tokens-core": "2.
|
|
40
|
-
"@tramvai/tokens-render": "2.
|
|
41
|
-
"@tramvai/tokens-router": "2.
|
|
42
|
-
"@tramvai/tokens-server": "2.
|
|
43
|
-
"@tramvai/tokens-server-private": "2.
|
|
44
|
-
"@tramvai/tokens-metrics": "2.
|
|
33
|
+
"@tramvai/core": "2.91.1",
|
|
34
|
+
"@tramvai/react": "2.91.1",
|
|
35
|
+
"@tramvai/papi": "2.91.1",
|
|
36
|
+
"@tramvai/module-router": "2.91.1",
|
|
37
|
+
"@tramvai/module-client-hints": "2.91.1",
|
|
38
|
+
"@tramvai/tokens-common": "2.91.1",
|
|
39
|
+
"@tramvai/tokens-core": "2.91.1",
|
|
40
|
+
"@tramvai/tokens-render": "2.91.1",
|
|
41
|
+
"@tramvai/tokens-router": "2.91.1",
|
|
42
|
+
"@tramvai/tokens-server": "2.91.1",
|
|
43
|
+
"@tramvai/tokens-server-private": "2.91.1",
|
|
44
|
+
"@tramvai/tokens-metrics": "2.91.1",
|
|
45
45
|
"prom-client": "^12.0.0",
|
|
46
46
|
"react": ">=16.14.0",
|
|
47
47
|
"tslib": "^2.4.0"
|