@lwrjs/core 0.17.2-alpha.14 → 0.17.2-alpha.16

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.
@@ -60,6 +60,7 @@ function createReturnStatus(error, req, debug) {
60
60
  }
61
61
  if (debug) {
62
62
  body = `<div style="font-family:sans-serif;margin:50px;"><h1>${status}: Document generation failed</h1><p>${body.replace(/</g, "&lt;").replace(/>/g, "&gt;")}</p></div>`;
63
+ status = 200;
63
64
  }
64
65
  return {status, body, headers: Object.keys(headers).length > 0 ? headers : void 0};
65
66
  }
@@ -77,8 +78,7 @@ function handleErrors(middleware, isBaseDoc = false) {
77
78
  }
78
79
  const {status, body, headers} = createReturnStatus(err, req, req.query.debug !== void 0 && isBaseDoc);
79
80
  headers && res.set(headers);
80
- res.status(status);
81
- res.send(body);
81
+ res.status(status).send(body);
82
82
  }
83
83
  };
84
84
  }
@@ -26,17 +26,16 @@ __markAsModule(exports);
26
26
  __export(exports, {
27
27
  viewMiddleware: () => viewMiddleware
28
28
  });
29
- var import_util = __toModule(require("util"));
30
29
  var import_url = __toModule(require("url"));
30
+ var import_util = __toModule(require("util"));
31
+ var import_zlib = __toModule(require("zlib"));
31
32
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
33
+ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
32
34
  var import_router = __toModule(require("@lwrjs/router"));
33
35
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
34
- var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
35
- var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
36
36
  var import_view_registry = __toModule(require("@lwrjs/view-registry"));
37
- var import_instrumentation2 = __toModule(require("@lwrjs/instrumentation"));
38
- var import_zlib = __toModule(require("zlib"));
39
37
  var import_compression = __toModule(require("./utils/compression.cjs"));
38
+ var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
40
39
  function createViewMiddleware(route, errorRoutes, context, viewHandler) {
41
40
  const errorRoute = errorRoutes.find((route2) => route2.status === 500);
42
41
  const appConfig = context.appConfig;
@@ -63,21 +62,21 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
63
62
  query: req.query,
64
63
  requestPath: req.path
65
64
  };
66
- const correlationID = req.headers && req.headers[import_shared_utils.CORRELATION_ID];
67
65
  const runtimeParams = {
68
66
  ...defaultRuntimeParams,
69
- correlationID,
70
67
  url: viewRequest.url,
71
68
  params: viewRequest.params,
72
69
  query: viewRequest.query,
73
70
  cookie: req.headers?.cookie,
74
- trueClientIP: req.headers && req.headers[import_shared_utils.TRUE_CLIENT_IP],
71
+ trueClientIP: req.headers?.[import_shared_utils.TRUE_CLIENT_IP],
72
+ correlationID: req.headers?.[import_shared_utils.CORRELATION_ID],
75
73
  coreProxy: req.getCoreProxy(appConfig.coreProxy ?? void 0, route.bootstrap?.proxyForSSR)
76
74
  };
77
75
  const resolve = req.isJsonRequest() ? viewHandler.getViewJson : viewHandler.getViewContent;
78
76
  let viewResponse;
79
77
  let resolvedRoute;
80
78
  let traceId;
79
+ let headers = {};
81
80
  try {
82
81
  viewResponse = await (0, import_instrumentation.getTracer)().trace({
83
82
  name: import_instrumentation.RequestHandlerSpan.GetView,
@@ -89,8 +88,9 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
89
88
  locale: runtimeParams.locale
90
89
  }
91
90
  }, async (span) => {
91
+ runtimeParams.viewSpanID = span.spanId;
92
92
  traceId = span.traceId;
93
- runtimeParams.b3TraceID = traceId;
93
+ headers = (0, import_shared_utils.getTraceHeaders)(runtimeParams, span);
94
94
  const res2 = await resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
95
95
  span.setAttributes({
96
96
  size: byteSize(res2.body)
@@ -114,15 +114,13 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
114
114
  });
115
115
  resolvedRoute = errorRoute;
116
116
  } finally {
117
- if (correlationID?.length) {
118
- res.setHeader(import_shared_utils.CORRELATION_ID, correlationID);
119
- }
117
+ if (Object.keys(headers).length)
118
+ res.set(headers);
120
119
  if (traceId?.length) {
121
- res.setHeader(import_shared_utils.B3_TRACE_ID, traceId);
122
120
  res.set({
123
- "Server-Timing": (0, import_instrumentation2.getTraceCollector)().getSpansInTrace(traceId)
121
+ "Server-Timing": (0, import_instrumentation.getTraceCollector)().getSpansInTrace(traceId)
124
122
  });
125
- (0, import_instrumentation2.getTraceCollector)().dropTrace(traceId);
123
+ (0, import_instrumentation.getTraceCollector)().dropTrace(traceId);
126
124
  }
127
125
  }
128
126
  if (req.isSiteGeneration()) {
@@ -42,8 +42,9 @@ function createReturnStatus(error, req, debug) {
42
42
  : `${descriptions.SERVER.SERVER_ERROR(req.originalUrl)}: ${body}`;
43
43
  }
44
44
  if (debug) {
45
- // return a debug base doc if debug mode is on
45
+ // return a debug base doc and a 200 response code if debug mode is on
46
46
  body = `<div style="font-family:sans-serif;margin:50px;"><h1>${status}: Document generation failed</h1><p>${body.replace(/</g, '&lt;').replace(/>/g, '&gt;')}</p></div>`;
47
+ status = 200;
47
48
  }
48
49
  return { status, body, headers: Object.keys(headers).length > 0 ? headers : undefined };
49
50
  }
@@ -65,8 +66,7 @@ export function handleErrors(middleware, isBaseDoc = false) {
65
66
  // only return HTML error screen for base doc requests in debug mode
66
67
  req.query.debug !== undefined && isBaseDoc);
67
68
  headers && res.set(headers);
68
- res.status(status);
69
- res.send(body);
69
+ res.status(status).send(body);
70
70
  }
71
71
  };
72
72
  }
@@ -1,14 +1,13 @@
1
- import { TextEncoder } from 'util';
2
1
  import { URLSearchParams } from 'url';
2
+ import { TextEncoder } from 'util';
3
+ import { brotliCompressSync, gzipSync } from 'zlib';
3
4
  import { descriptions, logger } from '@lwrjs/diagnostics';
5
+ import { RequestHandlerSpan, getTraceCollector, getTracer } from '@lwrjs/instrumentation';
4
6
  import { getClientRoutes } from '@lwrjs/router';
5
- import { B3_TRACE_ID, CORRELATION_ID, TRUE_CLIENT_IP, decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isLambdaEnv, isLocalDev, shortestTtl, } from '@lwrjs/shared-utils';
6
- import { RequestHandlerSpan, getTracer } from '@lwrjs/instrumentation';
7
- import { handleErrors } from './utils/error-handling.js';
7
+ import { CORRELATION_ID, TRUE_CLIENT_IP, decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, getTraceHeaders, isLambdaEnv, isLocalDev, shortestTtl, } from '@lwrjs/shared-utils';
8
8
  import { LwrViewHandler } from '@lwrjs/view-registry';
9
- import { getTraceCollector } from '@lwrjs/instrumentation';
10
- import { brotliCompressSync, gzipSync } from 'zlib';
11
9
  import { getMrtCompressionThreshold } from './utils/compression.js';
10
+ import { handleErrors } from './utils/error-handling.js';
12
11
  function createViewMiddleware(route, errorRoutes, context, viewHandler) {
13
12
  const errorRoute = errorRoutes.find((route) => route.status === 500);
14
13
  const appConfig = context.appConfig;
@@ -37,21 +36,21 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
37
36
  requestPath: req.path,
38
37
  };
39
38
  // Augment runtime params with viewRequest info
40
- const correlationID = req.headers && req.headers[CORRELATION_ID];
41
39
  const runtimeParams = {
42
40
  ...defaultRuntimeParams,
43
- correlationID,
44
41
  url: viewRequest.url,
45
42
  params: viewRequest.params,
46
43
  query: viewRequest.query,
47
44
  cookie: req.headers?.cookie,
48
- trueClientIP: req.headers && req.headers[TRUE_CLIENT_IP],
45
+ trueClientIP: req.headers?.[TRUE_CLIENT_IP],
46
+ correlationID: req.headers?.[CORRELATION_ID],
49
47
  coreProxy: req.getCoreProxy(appConfig.coreProxy ?? undefined, route.bootstrap?.proxyForSSR),
50
48
  };
51
49
  const resolve = req.isJsonRequest() ? viewHandler.getViewJson : viewHandler.getViewContent;
52
50
  let viewResponse;
53
51
  let resolvedRoute;
54
52
  let traceId;
53
+ let headers = {};
55
54
  try {
56
55
  viewResponse = await getTracer().trace({
57
56
  name: RequestHandlerSpan.GetView,
@@ -63,8 +62,9 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
63
62
  locale: runtimeParams.locale,
64
63
  },
65
64
  }, async (span) => {
65
+ runtimeParams.viewSpanID = span.spanId;
66
66
  traceId = span.traceId;
67
- runtimeParams.b3TraceID = traceId;
67
+ headers = getTraceHeaders(runtimeParams, span);
68
68
  const res = await resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
69
69
  // Add the view size metric
70
70
  span.setAttributes({
@@ -94,11 +94,9 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
94
94
  resolvedRoute = errorRoute;
95
95
  }
96
96
  finally {
97
- if (correlationID?.length) {
98
- res.setHeader(CORRELATION_ID, correlationID);
99
- }
97
+ if (Object.keys(headers).length)
98
+ res.set(headers);
100
99
  if (traceId?.length) {
101
- res.setHeader(B3_TRACE_ID, traceId);
102
100
  res.set({
103
101
  'Server-Timing': getTraceCollector().getSpansInTrace(traceId),
104
102
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.14",
7
+ "version": "0.17.2-alpha.16",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -43,34 +43,34 @@
43
43
  "build": "tsc -b"
44
44
  },
45
45
  "dependencies": {
46
- "@lwrjs/app-service": "0.17.2-alpha.14",
47
- "@lwrjs/asset-registry": "0.17.2-alpha.14",
48
- "@lwrjs/asset-transformer": "0.17.2-alpha.14",
49
- "@lwrjs/base-view-provider": "0.17.2-alpha.14",
50
- "@lwrjs/base-view-transformer": "0.17.2-alpha.14",
51
- "@lwrjs/client-modules": "0.17.2-alpha.14",
52
- "@lwrjs/config": "0.17.2-alpha.14",
53
- "@lwrjs/diagnostics": "0.17.2-alpha.14",
54
- "@lwrjs/esbuild": "0.17.2-alpha.14",
55
- "@lwrjs/fs-asset-provider": "0.17.2-alpha.14",
56
- "@lwrjs/fs-watch": "0.17.2-alpha.14",
57
- "@lwrjs/html-view-provider": "0.17.2-alpha.14",
58
- "@lwrjs/instrumentation": "0.17.2-alpha.14",
59
- "@lwrjs/loader": "0.17.2-alpha.14",
60
- "@lwrjs/lwc-module-provider": "0.17.2-alpha.14",
61
- "@lwrjs/lwc-ssr": "0.17.2-alpha.14",
62
- "@lwrjs/markdown-view-provider": "0.17.2-alpha.14",
63
- "@lwrjs/module-bundler": "0.17.2-alpha.14",
64
- "@lwrjs/module-registry": "0.17.2-alpha.14",
65
- "@lwrjs/npm-module-provider": "0.17.2-alpha.14",
66
- "@lwrjs/nunjucks-view-provider": "0.17.2-alpha.14",
67
- "@lwrjs/o11y": "0.17.2-alpha.14",
68
- "@lwrjs/resource-registry": "0.17.2-alpha.14",
69
- "@lwrjs/router": "0.17.2-alpha.14",
70
- "@lwrjs/server": "0.17.2-alpha.14",
71
- "@lwrjs/shared-utils": "0.17.2-alpha.14",
72
- "@lwrjs/static": "0.17.2-alpha.14",
73
- "@lwrjs/view-registry": "0.17.2-alpha.14",
46
+ "@lwrjs/app-service": "0.17.2-alpha.16",
47
+ "@lwrjs/asset-registry": "0.17.2-alpha.16",
48
+ "@lwrjs/asset-transformer": "0.17.2-alpha.16",
49
+ "@lwrjs/base-view-provider": "0.17.2-alpha.16",
50
+ "@lwrjs/base-view-transformer": "0.17.2-alpha.16",
51
+ "@lwrjs/client-modules": "0.17.2-alpha.16",
52
+ "@lwrjs/config": "0.17.2-alpha.16",
53
+ "@lwrjs/diagnostics": "0.17.2-alpha.16",
54
+ "@lwrjs/esbuild": "0.17.2-alpha.16",
55
+ "@lwrjs/fs-asset-provider": "0.17.2-alpha.16",
56
+ "@lwrjs/fs-watch": "0.17.2-alpha.16",
57
+ "@lwrjs/html-view-provider": "0.17.2-alpha.16",
58
+ "@lwrjs/instrumentation": "0.17.2-alpha.16",
59
+ "@lwrjs/loader": "0.17.2-alpha.16",
60
+ "@lwrjs/lwc-module-provider": "0.17.2-alpha.16",
61
+ "@lwrjs/lwc-ssr": "0.17.2-alpha.16",
62
+ "@lwrjs/markdown-view-provider": "0.17.2-alpha.16",
63
+ "@lwrjs/module-bundler": "0.17.2-alpha.16",
64
+ "@lwrjs/module-registry": "0.17.2-alpha.16",
65
+ "@lwrjs/npm-module-provider": "0.17.2-alpha.16",
66
+ "@lwrjs/nunjucks-view-provider": "0.17.2-alpha.16",
67
+ "@lwrjs/o11y": "0.17.2-alpha.16",
68
+ "@lwrjs/resource-registry": "0.17.2-alpha.16",
69
+ "@lwrjs/router": "0.17.2-alpha.16",
70
+ "@lwrjs/server": "0.17.2-alpha.16",
71
+ "@lwrjs/shared-utils": "0.17.2-alpha.16",
72
+ "@lwrjs/static": "0.17.2-alpha.16",
73
+ "@lwrjs/view-registry": "0.17.2-alpha.16",
74
74
  "chokidar": "^3.6.0",
75
75
  "esbuild": "^0.9.7",
76
76
  "fs-extra": "^11.2.0",
@@ -80,7 +80,7 @@
80
80
  "ws": "^8.18.0"
81
81
  },
82
82
  "devDependencies": {
83
- "@lwrjs/types": "0.17.2-alpha.14",
83
+ "@lwrjs/types": "0.17.2-alpha.16",
84
84
  "@types/ws": "^8.5.12",
85
85
  "memfs": "^4.13.0"
86
86
  },
@@ -93,5 +93,5 @@
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
95
95
  },
96
- "gitHead": "a7d6d67f5453787a8b2428bd11546c334af3f77b"
96
+ "gitHead": "5a6b24c265145652f9dda60d1d2cb405148c71f3"
97
97
  }