@tramvai/module-server 5.10.0 → 5.14.9

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.
@@ -23,7 +23,7 @@ DependenciesVersionModule = __decorate([
23
23
  provide: SERVER_MODULE_PAPI_PRIVATE_ROUTE,
24
24
  multi: true,
25
25
  useFactory: () => {
26
- const { dependencies = [] } = packageJson !== null && packageJson !== void 0 ? packageJson : {};
26
+ const { dependencies = [] } = packageJson ?? {};
27
27
  return createPapiMethod({
28
28
  path: '/dependenciesVersion',
29
29
  method: 'get',
@@ -27,7 +27,7 @@ exports.DependenciesVersionModule = tslib.__decorate([
27
27
  provide: tokensServer.SERVER_MODULE_PAPI_PRIVATE_ROUTE,
28
28
  multi: true,
29
29
  useFactory: () => {
30
- const { dependencies = [] } = packageJson !== null && packageJson !== void 0 ? packageJson : {};
30
+ const { dependencies = [] } = packageJson ?? {};
31
31
  return papi.createPapiMethod({
32
32
  path: '/dependenciesVersion',
33
33
  method: 'get',
@@ -14,7 +14,6 @@ class EarlyHintsManager {
14
14
  }
15
15
  getHints() {
16
16
  return this.resourcesRegistry.getPageResources().reduce((acc, resource) => {
17
- var _a, _b;
18
17
  let resourceHint = null;
19
18
  let cdnHint = null;
20
19
  if (!resource.payload) {
@@ -28,13 +27,13 @@ class EarlyHintsManager {
28
27
  resourceHint = `Link: <${resource.payload}>; rel=preload;${as}`;
29
28
  cdnHint = this.getCdnHintForResource(resource);
30
29
  }
31
- if (resource.type === 'style' && ((_a = resource.attrs) === null || _a === void 0 ? void 0 : _a['data-critical']) === 'true') {
30
+ if (resource.type === 'style' && resource.attrs?.['data-critical'] === 'true') {
32
31
  resourceHint = `Link: <${resource.payload}>; rel=preload; as=style`;
33
32
  cdnHint = this.getCdnHintForResource(resource);
34
33
  }
35
34
  // prevent scripts preloading because of potential large numbers of JS chunks for every page
36
35
  // still check JS chunks for preconnects
37
- if (resource.type === 'script' && ((_b = resource.attrs) === null || _b === void 0 ? void 0 : _b['data-critical']) === 'true') {
36
+ if (resource.type === 'script' && resource.attrs?.['data-critical'] === 'true') {
38
37
  cdnHint = this.getCdnHintForResource(resource);
39
38
  }
40
39
  if (this.doesHintUniq(cdnHint)) {
@@ -70,8 +69,7 @@ class EarlyHintsManager {
70
69
  return `${result.join(endOfLine)}${endOfLine.repeat(2)}`;
71
70
  }
72
71
  getAsAttribute(resource) {
73
- var _a;
74
- return ((_a = resource.attrs) === null || _a === void 0 ? void 0 : _a.as) !== undefined ? ` as=${resource.attrs.as}` : '';
72
+ return resource.attrs?.as !== undefined ? ` as=${resource.attrs.as}` : '';
75
73
  }
76
74
  getCdnHintForResource(resource) {
77
75
  const match = resource.payload.match(/https:\/\/[^/'"]+/gi);
@@ -18,7 +18,6 @@ class EarlyHintsManager {
18
18
  }
19
19
  getHints() {
20
20
  return this.resourcesRegistry.getPageResources().reduce((acc, resource) => {
21
- var _a, _b;
22
21
  let resourceHint = null;
23
22
  let cdnHint = null;
24
23
  if (!resource.payload) {
@@ -32,13 +31,13 @@ class EarlyHintsManager {
32
31
  resourceHint = `Link: <${resource.payload}>; rel=preload;${as}`;
33
32
  cdnHint = this.getCdnHintForResource(resource);
34
33
  }
35
- if (resource.type === 'style' && ((_a = resource.attrs) === null || _a === void 0 ? void 0 : _a['data-critical']) === 'true') {
34
+ if (resource.type === 'style' && resource.attrs?.['data-critical'] === 'true') {
36
35
  resourceHint = `Link: <${resource.payload}>; rel=preload; as=style`;
37
36
  cdnHint = this.getCdnHintForResource(resource);
38
37
  }
39
38
  // prevent scripts preloading because of potential large numbers of JS chunks for every page
40
39
  // still check JS chunks for preconnects
41
- if (resource.type === 'script' && ((_b = resource.attrs) === null || _b === void 0 ? void 0 : _b['data-critical']) === 'true') {
40
+ if (resource.type === 'script' && resource.attrs?.['data-critical'] === 'true') {
42
41
  cdnHint = this.getCdnHintForResource(resource);
43
42
  }
44
43
  if (this.doesHintUniq(cdnHint)) {
@@ -74,8 +73,7 @@ class EarlyHintsManager {
74
73
  return `${result.join(endOfLine)}${endOfLine.repeat(2)}`;
75
74
  }
76
75
  getAsAttribute(resource) {
77
- var _a;
78
- return ((_a = resource.attrs) === null || _a === void 0 ? void 0 : _a.as) !== undefined ? ` as=${resource.attrs.as}` : '';
76
+ return resource.attrs?.as !== undefined ? ` as=${resource.attrs.as}` : '';
79
77
  }
80
78
  getCdnHintForResource(resource) {
81
79
  const match = resource.payload.match(/https:\/\/[^/'"]+/gi);
@@ -36,12 +36,11 @@ function createApi(rootApp, papiList, { baseUrl, di, logger, papiInitHandlers })
36
36
  app[method](path, {
37
37
  schema,
38
38
  errorHandler: async (error, req, res) => {
39
- var _a;
40
39
  res.status(error.validation ? 400 : 503);
41
40
  childLog.error(error);
42
41
  return {
43
42
  resultCode: 'INTERNAL_ERROR',
44
- errorMessage: (_a = error.message) !== null && _a !== void 0 ? _a : 'internal error',
43
+ errorMessage: error.message ?? 'internal error',
45
44
  };
46
45
  },
47
46
  }, async (req, res) => {
@@ -44,12 +44,11 @@ function createApi(rootApp, papiList, { baseUrl, di, logger, papiInitHandlers })
44
44
  app[method](path, {
45
45
  schema,
46
46
  errorHandler: async (error, req, res) => {
47
- var _a;
48
47
  res.status(error.validation ? 400 : 503);
49
48
  childLog.error(error);
50
49
  return {
51
50
  resultCode: 'INTERNAL_ERROR',
52
- errorMessage: (_a = error.message) !== null && _a !== void 0 ? _a : 'internal error',
51
+ errorMessage: error.message ?? 'internal error',
53
52
  };
54
53
  },
55
54
  }, async (req, res) => {
@@ -7,12 +7,11 @@ const papiExecutorProvider = provide({
7
7
  provide: PAPI_EXECUTOR,
8
8
  scope: Scope.REQUEST,
9
9
  useFactory: ({ di, logger, fastifyRequest, requestManager, responseManager, asyncLocalStorage, }) => {
10
- var _a;
11
10
  const papiLog = logger('papi');
12
11
  const papiOptions = {
13
12
  requestManager,
14
13
  responseManager,
15
- params: (_a = fastifyRequest.params) !== null && _a !== void 0 ? _a : {},
14
+ params: fastifyRequest.params ?? {},
16
15
  cookies: requestManager.getCookies(),
17
16
  headers: requestManager.getHeaders(),
18
17
  body: requestManager.getBody(),
@@ -11,12 +11,11 @@ const papiExecutorProvider = dippy.provide({
11
11
  provide: tokensServerPrivate.PAPI_EXECUTOR,
12
12
  scope: dippy.Scope.REQUEST,
13
13
  useFactory: ({ di, logger, fastifyRequest, requestManager, responseManager, asyncLocalStorage, }) => {
14
- var _a;
15
14
  const papiLog = logger('papi');
16
15
  const papiOptions = {
17
16
  requestManager,
18
17
  responseManager,
19
- params: (_a = fastifyRequest.params) !== null && _a !== void 0 ? _a : {},
18
+ params: fastifyRequest.params ?? {},
20
19
  cookies: requestManager.getCookies(),
21
20
  headers: requestManager.getHeaders(),
22
21
  body: requestManager.getBody(),
@@ -19,14 +19,14 @@ ServerProxyModule = __decorate([
19
19
  useFactory: ({ defaultProxies }) => {
20
20
  return (app) => {
21
21
  const proxyConfig = safeNodeRequire(resolve(process.cwd(), 'proxy.conf'));
22
- const proxies = defaultProxies !== null && defaultProxies !== void 0 ? defaultProxies : [];
22
+ const proxies = defaultProxies ?? [];
23
23
  if (!proxyConfig && proxies.length === 0) {
24
24
  return;
25
25
  }
26
26
  if (isArray(proxyConfig)) {
27
27
  proxies.push(...proxyConfig);
28
28
  }
29
- else if (proxyConfig === null || proxyConfig === void 0 ? void 0 : proxyConfig.target) {
29
+ else if (proxyConfig?.target) {
30
30
  proxies.push(proxyConfig);
31
31
  }
32
32
  else if (isObject(proxyConfig)) {
@@ -29,14 +29,14 @@ exports.ServerProxyModule = tslib.__decorate([
29
29
  useFactory: ({ defaultProxies }) => {
30
30
  return (app) => {
31
31
  const proxyConfig = require$1.safeNodeRequire(path.resolve(process.cwd(), 'proxy.conf'));
32
- const proxies = defaultProxies !== null && defaultProxies !== void 0 ? defaultProxies : [];
32
+ const proxies = defaultProxies ?? [];
33
33
  if (!proxyConfig && proxies.length === 0) {
34
34
  return;
35
35
  }
36
36
  if (isArray__default["default"](proxyConfig)) {
37
37
  proxies.push(...proxyConfig);
38
38
  }
39
- else if (proxyConfig === null || proxyConfig === void 0 ? void 0 : proxyConfig.target) {
39
+ else if (proxyConfig?.target) {
40
40
  proxies.push(proxyConfig);
41
41
  }
42
42
  else if (isObject__default["default"](proxyConfig)) {
@@ -11,7 +11,6 @@ const ServerTimingModule = declareModule({
11
11
  scope: Scope.SINGLETON,
12
12
  multi: true,
13
13
  useValue: (di, type, status, timingInfo) => {
14
- var _a;
15
14
  if (type === 'server' && status === 'customer') {
16
15
  const responseManager = di.get(RESPONSE_MANAGER_TOKEN);
17
16
  const reply = di.get(FASTIFY_RESPONSE);
@@ -19,7 +18,7 @@ const ServerTimingModule = declareModule({
19
18
  if (reply.sent) {
20
19
  return;
21
20
  }
22
- const initialHeader = (_a = responseManager.getHeader('Server-Timing')) !== null && _a !== void 0 ? _a : '';
21
+ const initialHeader = responseManager.getHeader('Server-Timing') ?? '';
23
22
  const entries = [];
24
23
  // index for custom sort
25
24
  let index = 0;
@@ -15,7 +15,6 @@ const ServerTimingModule = core.declareModule({
15
15
  scope: core.Scope.SINGLETON,
16
16
  multi: true,
17
17
  useValue: (di, type, status, timingInfo) => {
18
- var _a;
19
18
  if (type === 'server' && status === 'customer') {
20
19
  const responseManager = di.get(tokensCommon.RESPONSE_MANAGER_TOKEN);
21
20
  const reply = di.get(tokensServerPrivate.FASTIFY_RESPONSE);
@@ -23,7 +22,7 @@ const ServerTimingModule = core.declareModule({
23
22
  if (reply.sent) {
24
23
  return;
25
24
  }
26
- const initialHeader = (_a = responseManager.getHeader('Server-Timing')) !== null && _a !== void 0 ? _a : '';
25
+ const initialHeader = responseManager.getHeader('Server-Timing') ?? '';
27
26
  const entries = [];
28
27
  // index for custom sort
29
28
  let index = 0;
@@ -14,7 +14,7 @@ ServerStaticsModule = __decorate([
14
14
  provide({
15
15
  provide: WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
16
16
  useFactory: ({ options }) => {
17
- const path = (options === null || options === void 0 ? void 0 : options.path) || 'public';
17
+ const path = options?.path || 'public';
18
18
  return (instance) => {
19
19
  instance.register(FastifyStatic, {
20
20
  decorateReply: false,
@@ -22,7 +22,7 @@ exports.ServerStaticsModule = tslib.__decorate([
22
22
  core.provide({
23
23
  provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
24
24
  useFactory: ({ options }) => {
25
- const path$1 = (options === null || options === void 0 ? void 0 : options.path) || 'public';
25
+ const path$1 = options?.path || 'public';
26
26
  return (instance) => {
27
27
  instance.register(FastifyStatic__default["default"], {
28
28
  decorateReply: false,
@@ -14,7 +14,7 @@ const errorHandler = async (app, { log, beforeError, afterError, fetchWebpackSta
14
14
  response: renderErrorBoundaryPageToString({
15
15
  element: RootErrorBoundary,
16
16
  requestUrl: '/5xx.html',
17
- error: staticRootErrorBoundaryError !== null && staticRootErrorBoundaryError !== void 0 ? staticRootErrorBoundaryError : {
17
+ error: staticRootErrorBoundaryError ?? {
18
18
  name: 'STATIC_ROOT_ERROR_BOUNDARY_ERROR',
19
19
  message: 'Default error for root error boundary',
20
20
  },
@@ -22,7 +22,7 @@ const errorHandler = async (app, { log, beforeError, afterError, fetchWebpackSta
22
22
  response: renderErrorBoundaryPageToString.renderErrorBoundaryPageToString({
23
23
  element: RootErrorBoundary,
24
24
  requestUrl: '/5xx.html',
25
- error: staticRootErrorBoundaryError !== null && staticRootErrorBoundaryError !== void 0 ? staticRootErrorBoundaryError : {
25
+ error: staticRootErrorBoundaryError ?? {
26
26
  name: 'STATIC_ROOT_ERROR_BOUNDARY_ERROR',
27
27
  message: 'Default error for root error boundary',
28
28
  },
@@ -3,8 +3,7 @@ import https from 'https';
3
3
  import { readFileSync } from 'fs';
4
4
 
5
5
  const serverFactory = () => {
6
- var _a;
7
- const httpsOptions = JSON.parse((_a = process.env.HTTPS) !== null && _a !== void 0 ? _a : null);
6
+ const httpsOptions = JSON.parse(process.env.HTTPS ?? null);
8
7
  if (httpsOptions && httpsOptions.key && httpsOptions.cert) {
9
8
  return https.createServer({
10
9
  key: readFileSync(httpsOptions.key),
@@ -12,8 +12,7 @@ var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
12
12
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
13
13
 
14
14
  const serverFactory = () => {
15
- var _a;
16
- const httpsOptions = JSON.parse((_a = process.env.HTTPS) !== null && _a !== void 0 ? _a : null);
15
+ const httpsOptions = JSON.parse(process.env.HTTPS ?? null);
17
16
  if (httpsOptions && httpsOptions.key && httpsOptions.cert) {
18
17
  return https__default["default"].createServer({
19
18
  key: fs.readFileSync(httpsOptions.key),
@@ -5,13 +5,12 @@ import os from 'os';
5
5
 
6
6
  const DEFAULT_STATIC_HOST = 'localhost';
7
7
  const staticAppCommand = ({ logger, envManager, appInfo, }) => {
8
- var _a;
9
8
  if (!envManager.get('DEV_STATIC')) {
10
9
  return async function staticAppNoop() { };
11
10
  }
12
11
  const log = logger('server:static');
13
12
  const port = +envManager.get('PORT_STATIC');
14
- const host = ((_a = envManager.get('HOST_STATIC')) !== null && _a !== void 0 ? _a : DEFAULT_STATIC_HOST).replace('localhost', '0.0.0.0');
13
+ const host = (envManager.get('HOST_STATIC') ?? DEFAULT_STATIC_HOST).replace('localhost', '0.0.0.0');
15
14
  const appVersion = envManager.get('APP_VERSION');
16
15
  return async function staticApp() {
17
16
  const appStatic = fastify();
@@ -15,13 +15,12 @@ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
15
15
 
16
16
  const DEFAULT_STATIC_HOST = 'localhost';
17
17
  const staticAppCommand = ({ logger, envManager, appInfo, }) => {
18
- var _a;
19
18
  if (!envManager.get('DEV_STATIC')) {
20
19
  return async function staticAppNoop() { };
21
20
  }
22
21
  const log = logger('server:static');
23
22
  const port = +envManager.get('PORT_STATIC');
24
- const host = ((_a = envManager.get('HOST_STATIC')) !== null && _a !== void 0 ? _a : DEFAULT_STATIC_HOST).replace('localhost', '0.0.0.0');
23
+ const host = (envManager.get('HOST_STATIC') ?? DEFAULT_STATIC_HOST).replace('localhost', '0.0.0.0');
25
24
  const appVersion = envManager.get('APP_VERSION');
26
25
  return async function staticApp() {
27
26
  const appStatic = fastify__default["default"]();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-server",
3
- "version": "5.10.0",
3
+ "version": "5.14.9",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -26,13 +26,13 @@
26
26
  "@tinkoff/monkeypatch": "5.0.2",
27
27
  "@tinkoff/terminus": "0.4.2",
28
28
  "@tinkoff/url": "0.11.2",
29
- "@tramvai/module-cache-warmup": "5.10.0",
30
- "@tramvai/module-metrics": "5.10.0",
31
- "@tramvai/papi": "5.10.0",
32
- "@tramvai/tokens-server": "5.10.0",
33
- "@tramvai/tokens-router": "5.10.0",
34
- "@tramvai/tokens-server-private": "5.10.0",
35
- "@tramvai/safe-strings": "0.8.3",
29
+ "@tramvai/module-cache-warmup": "5.14.9",
30
+ "@tramvai/module-metrics": "5.14.9",
31
+ "@tramvai/papi": "5.14.9",
32
+ "@tramvai/tokens-server": "5.14.9",
33
+ "@tramvai/tokens-router": "5.14.9",
34
+ "@tramvai/tokens-server-private": "5.14.9",
35
+ "@tramvai/safe-strings": "0.8.4",
36
36
  "fastify": "^4.14.1",
37
37
  "@fastify/cookie": "^8.3.0",
38
38
  "@fastify/compress": "^6.2.0",
@@ -44,14 +44,14 @@
44
44
  "peerDependencies": {
45
45
  "@tinkoff/dippy": "0.11.3",
46
46
  "@tinkoff/utils": "^2.1.2",
47
- "@tramvai/cli": "5.10.0",
48
- "@tramvai/core": "5.10.0",
49
- "@tramvai/react": "5.10.0",
50
- "@tramvai/module-common": "5.10.0",
51
- "@tramvai/module-environment": "5.10.0",
52
- "@tramvai/tokens-common": "5.10.0",
53
- "@tramvai/tokens-core-private": "5.10.0",
54
- "@tramvai/tokens-render": "5.10.0",
47
+ "@tramvai/cli": "5.14.9",
48
+ "@tramvai/core": "5.14.9",
49
+ "@tramvai/react": "5.14.9",
50
+ "@tramvai/module-common": "5.14.9",
51
+ "@tramvai/module-environment": "5.14.9",
52
+ "@tramvai/tokens-common": "5.14.9",
53
+ "@tramvai/tokens-core-private": "5.14.9",
54
+ "@tramvai/tokens-render": "5.14.9",
55
55
  "react": ">=16.14.0",
56
56
  "react-dom": ">=16.14.0",
57
57
  "tslib": "^2.4.0"