@lwrjs/core 0.17.2-alpha.10 → 0.17.2-alpha.11

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.
@@ -28,8 +28,6 @@ __export(exports, {
28
28
  });
29
29
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
30
30
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
- var MRT_REQUEST_CLASS = "x-mobify-request-class";
32
- var TRUE_CLIENT_IP = "true-client-ip";
33
31
  function requestProcessorMiddleware(app, context) {
34
32
  const {basePath} = context.runtimeEnvironment;
35
33
  app.use(async (req, res, next) => {
@@ -44,9 +42,10 @@ function requestProcessorMiddleware(app, context) {
44
42
  });
45
43
  }
46
44
  }
47
- requestClass = req.headers[MRT_REQUEST_CLASS];
45
+ requestClass = req.headers[import_shared_utils.MRT_REQUEST_CLASS];
48
46
  requestDepth = (0, import_shared_utils.parseRequestDepth)(req.headers, req.query);
49
- const trueClientIP = req.headers[TRUE_CLIENT_IP];
47
+ const trueClientIP = req.headers[import_shared_utils.TRUE_CLIENT_IP];
48
+ const correlationID = req.headers[import_shared_utils.CORRELATION_ID];
50
49
  const forwarded = req.headers["forwarded"];
51
50
  const host = req.headers["host"];
52
51
  const forwardedProto = req.headers["x-forwarded-proto"];
@@ -54,7 +53,7 @@ function requestProcessorMiddleware(app, context) {
54
53
  if ((0, import_shared_utils.isLambdaEnv)()) {
55
54
  import_diagnostics.logger.info({
56
55
  label: `request-processor-middleware`,
57
- message: `Original Url: ${req.originalUrl}, Forwarded: ${forwarded}, X-Forwarded-Proto: ${forwardedProto}, Host: ${host}, Protocol: ${protocol}, ${MRT_REQUEST_CLASS}: ${requestClass}, ${TRUE_CLIENT_IP}: ${trueClientIP}, ${import_shared_utils.REQUEST_DEPTH_HEADER}: ${requestDepth}`
56
+ message: `Original Url: ${req.originalUrl}, Forwarded: ${forwarded}, X-Forwarded-Proto: ${forwardedProto}, Host: ${host}, Protocol: ${protocol}, ${import_shared_utils.MRT_REQUEST_CLASS}: ${requestClass}, ${import_shared_utils.TRUE_CLIENT_IP}: ${trueClientIP}, ${import_shared_utils.CORRELATION_ID}: ${correlationID}, ${import_shared_utils.REQUEST_DEPTH_HEADER}: ${requestDepth}`
58
57
  });
59
58
  }
60
59
  }
@@ -90,7 +89,7 @@ function requestProcessorMiddleware(app, context) {
90
89
  } else {
91
90
  import_diagnostics.logger.debug({
92
91
  label: `request-processor-middleware`,
93
- message: `${MRT_REQUEST_CLASS} ignored ${req.headers ? req.headers[MRT_REQUEST_CLASS] : "no-headers"}`
92
+ message: `${import_shared_utils.MRT_REQUEST_CLASS} ignored ${req.headers ? req.headers[import_shared_utils.MRT_REQUEST_CLASS] : "no-headers"}`
94
93
  });
95
94
  req.basePath = basePath;
96
95
  }
@@ -32,7 +32,7 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
32
  function addRedirectQueryParam(redirectUrl, depth) {
33
33
  const fakeOrigin = "http://parse.com";
34
34
  const url = (0, import_shared_utils.isURL)(redirectUrl) ? new URL(redirectUrl) : new URL(`${fakeOrigin}${redirectUrl}`);
35
- url.searchParams.set(import_shared_utils.REQUEST_DEPTH_KEY, String(depth + 1));
35
+ url.searchParams.set(import_shared_utils.REQUEST_DEPTH_HEADER, String(depth + 1));
36
36
  return url.toString().replace(fakeOrigin, "");
37
37
  }
38
38
  function createReturnStatus(error, req, debug) {
@@ -63,13 +63,15 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
63
63
  query: req.query,
64
64
  requestPath: req.path
65
65
  };
66
+ const correlationID = req.headers && req.headers[import_shared_utils.CORRELATION_ID];
66
67
  const runtimeParams = {
67
68
  ...defaultRuntimeParams,
69
+ correlationID,
68
70
  url: viewRequest.url,
69
71
  params: viewRequest.params,
70
72
  query: viewRequest.query,
71
73
  cookie: req.headers?.cookie,
72
- trueClientIP: req.headers && req.headers["true-client-ip"],
74
+ trueClientIP: req.headers && req.headers[import_shared_utils.TRUE_CLIENT_IP],
73
75
  coreProxy: req.getCoreProxy(appConfig.coreProxy ?? void 0, route.bootstrap?.proxyForSSR)
74
76
  };
75
77
  const resolve = req.isJsonRequest() ? viewHandler.getViewJson : viewHandler.getViewContent;
@@ -88,6 +90,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
88
90
  }
89
91
  }, async (span) => {
90
92
  traceId = span.traceId;
93
+ runtimeParams.b3TraceID = traceId;
91
94
  const res2 = await resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
92
95
  span.setAttributes({
93
96
  size: byteSize(res2.body)
@@ -111,8 +114,11 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
111
114
  });
112
115
  resolvedRoute = errorRoute;
113
116
  } finally {
117
+ if (correlationID?.length) {
118
+ res.setHeader(import_shared_utils.CORRELATION_ID, correlationID);
119
+ }
114
120
  if (traceId?.length) {
115
- res.setHeader("x-trace-id", traceId);
121
+ res.setHeader(import_shared_utils.B3_TRACE_ID, traceId);
116
122
  res.set({
117
123
  "Server-Timing": (0, import_instrumentation2.getTraceCollector)().getSpansInTrace(traceId)
118
124
  });
@@ -1,15 +1,5 @@
1
- /**
2
- * Parse passed to us via the X-Mobify-Request-Class.
3
- *
4
- * basePath: The dynamic base path
5
- * '' or undefined -> LWR basePath ''
6
- * token or /token -> LWR basePath '/token'
7
- *
8
- */
9
1
  import { logger } from '@lwrjs/diagnostics';
10
- import { REQUEST_DEPTH_HEADER, isLambdaEnv, parseRequestDepth } from '@lwrjs/shared-utils';
11
- const MRT_REQUEST_CLASS = 'x-mobify-request-class';
12
- const TRUE_CLIENT_IP = 'true-client-ip';
2
+ import { CORRELATION_ID, MRT_REQUEST_CLASS, REQUEST_DEPTH_HEADER, TRUE_CLIENT_IP, isLambdaEnv, parseRequestDepth, } from '@lwrjs/shared-utils';
13
3
  export function requestProcessorMiddleware(app, context) {
14
4
  const { basePath } = context.runtimeEnvironment;
15
5
  app.use(async (req, res, next) => {
@@ -29,6 +19,7 @@ export function requestProcessorMiddleware(app, context) {
29
19
  requestClass = req.headers[MRT_REQUEST_CLASS];
30
20
  requestDepth = parseRequestDepth(req.headers, req.query);
31
21
  const trueClientIP = req.headers[TRUE_CLIENT_IP];
22
+ const correlationID = req.headers[CORRELATION_ID];
32
23
  const forwarded = req.headers['forwarded'];
33
24
  const host = req.headers['host'];
34
25
  const forwardedProto = req.headers['x-forwarded-proto'];
@@ -37,7 +28,7 @@ export function requestProcessorMiddleware(app, context) {
37
28
  if (isLambdaEnv()) {
38
29
  logger.info({
39
30
  label: `request-processor-middleware`,
40
- message: `Original Url: ${req.originalUrl}, Forwarded: ${forwarded}, X-Forwarded-Proto: ${forwardedProto}, Host: ${host}, Protocol: ${protocol}, ${MRT_REQUEST_CLASS}: ${requestClass}, ${TRUE_CLIENT_IP}: ${trueClientIP}, ${REQUEST_DEPTH_HEADER}: ${requestDepth}`,
31
+ message: `Original Url: ${req.originalUrl}, Forwarded: ${forwarded}, X-Forwarded-Proto: ${forwardedProto}, Host: ${host}, Protocol: ${protocol}, ${MRT_REQUEST_CLASS}: ${requestClass}, ${TRUE_CLIENT_IP}: ${trueClientIP}, ${CORRELATION_ID}: ${correlationID}, ${REQUEST_DEPTH_HEADER}: ${requestDepth}`,
41
32
  });
42
33
  }
43
34
  }
@@ -90,12 +81,21 @@ export function requestProcessorMiddleware(app, context) {
90
81
  await next();
91
82
  });
92
83
  }
84
+ /**
85
+ * Parse the basePath passed via the X-Mobify-Request-Class header.
86
+ * Example: basePath=/token
87
+ *
88
+ * basePath: The dynamic base path
89
+ * '' or undefined -> LWR basePath ''
90
+ * token or /token -> LWR basePath '/token'
91
+ *
92
+ */
93
93
  function parseRequestClass(requestClass) {
94
94
  // If there is no requestClass do not bother parsing
95
95
  if (!requestClass) {
96
96
  return {};
97
97
  }
98
- // Split the Forwarded header into individual key-value pairs
98
+ // Split the header into individual key-value pairs
99
99
  const keyValuePairs = requestClass.split(';');
100
100
  // Create an object to store the parsed values
101
101
  const parsed = {};
@@ -1,12 +1,12 @@
1
1
  import { descriptions, DiagnosticsError, LwrError, LwrInvalidError, LwrStatusError, LwrUnresolvableError, } from '@lwrjs/diagnostics';
2
2
  import { logger } from '@lwrjs/diagnostics';
3
- import { isURL, parseRequestDepth, REQUEST_DEPTH_KEY } from '@lwrjs/shared-utils';
3
+ import { isURL, parseRequestDepth, REQUEST_DEPTH_HEADER } from '@lwrjs/shared-utils';
4
4
  function addRedirectQueryParam(redirectUrl, depth) {
5
5
  // add a request depth query param to the URL
6
6
  // the depth header cannot be used since headers cannot be added to a redirect
7
7
  const fakeOrigin = 'http://parse.com';
8
8
  const url = isURL(redirectUrl) ? new URL(redirectUrl) : new URL(`${fakeOrigin}${redirectUrl}`);
9
- url.searchParams.set(REQUEST_DEPTH_KEY, String(depth + 1));
9
+ url.searchParams.set(REQUEST_DEPTH_HEADER, String(depth + 1));
10
10
  return url.toString().replace(fakeOrigin, '');
11
11
  }
12
12
  function createReturnStatus(error, req, debug) {
@@ -2,7 +2,7 @@ import { TextEncoder } from 'util';
2
2
  import { URLSearchParams } from 'url';
3
3
  import { descriptions, logger } from '@lwrjs/diagnostics';
4
4
  import { getClientRoutes } from '@lwrjs/router';
5
- import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isLocalDev, shortestTtl, isLambdaEnv, } from '@lwrjs/shared-utils';
5
+ import { B3_TRACE_ID, CORRELATION_ID, TRUE_CLIENT_IP, decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, isLambdaEnv, isLocalDev, shortestTtl, } from '@lwrjs/shared-utils';
6
6
  import { RequestHandlerSpan, getTracer } from '@lwrjs/instrumentation';
7
7
  import { handleErrors } from './utils/error-handling.js';
8
8
  import { LwrViewHandler } from '@lwrjs/view-registry';
@@ -37,13 +37,15 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
37
37
  requestPath: req.path,
38
38
  };
39
39
  // Augment runtime params with viewRequest info
40
+ const correlationID = req.headers && req.headers[CORRELATION_ID];
40
41
  const runtimeParams = {
41
42
  ...defaultRuntimeParams,
43
+ correlationID,
42
44
  url: viewRequest.url,
43
45
  params: viewRequest.params,
44
46
  query: viewRequest.query,
45
47
  cookie: req.headers?.cookie,
46
- trueClientIP: req.headers && req.headers['true-client-ip'],
48
+ trueClientIP: req.headers && req.headers[TRUE_CLIENT_IP],
47
49
  coreProxy: req.getCoreProxy(appConfig.coreProxy ?? undefined, route.bootstrap?.proxyForSSR),
48
50
  };
49
51
  const resolve = req.isJsonRequest() ? viewHandler.getViewJson : viewHandler.getViewContent;
@@ -62,6 +64,7 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
62
64
  },
63
65
  }, async (span) => {
64
66
  traceId = span.traceId;
67
+ runtimeParams.b3TraceID = traceId;
65
68
  const res = await resolve.call(viewHandler, viewRequest, route, runtimeEnvironment, runtimeParams);
66
69
  // Add the view size metric
67
70
  span.setAttributes({
@@ -91,8 +94,11 @@ function createViewMiddleware(route, errorRoutes, context, viewHandler) {
91
94
  resolvedRoute = errorRoute;
92
95
  }
93
96
  finally {
97
+ if (correlationID?.length) {
98
+ res.setHeader(CORRELATION_ID, correlationID);
99
+ }
94
100
  if (traceId?.length) {
95
- res.setHeader('x-trace-id', traceId);
101
+ res.setHeader(B3_TRACE_ID, traceId);
96
102
  res.set({
97
103
  'Server-Timing': getTraceCollector().getSpansInTrace(traceId),
98
104
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.10",
7
+ "version": "0.17.2-alpha.11",
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.10",
47
- "@lwrjs/asset-registry": "0.17.2-alpha.10",
48
- "@lwrjs/asset-transformer": "0.17.2-alpha.10",
49
- "@lwrjs/base-view-provider": "0.17.2-alpha.10",
50
- "@lwrjs/base-view-transformer": "0.17.2-alpha.10",
51
- "@lwrjs/client-modules": "0.17.2-alpha.10",
52
- "@lwrjs/config": "0.17.2-alpha.10",
53
- "@lwrjs/diagnostics": "0.17.2-alpha.10",
54
- "@lwrjs/esbuild": "0.17.2-alpha.10",
55
- "@lwrjs/fs-asset-provider": "0.17.2-alpha.10",
56
- "@lwrjs/fs-watch": "0.17.2-alpha.10",
57
- "@lwrjs/html-view-provider": "0.17.2-alpha.10",
58
- "@lwrjs/instrumentation": "0.17.2-alpha.10",
59
- "@lwrjs/loader": "0.17.2-alpha.10",
60
- "@lwrjs/lwc-module-provider": "0.17.2-alpha.10",
61
- "@lwrjs/lwc-ssr": "0.17.2-alpha.10",
62
- "@lwrjs/markdown-view-provider": "0.17.2-alpha.10",
63
- "@lwrjs/module-bundler": "0.17.2-alpha.10",
64
- "@lwrjs/module-registry": "0.17.2-alpha.10",
65
- "@lwrjs/npm-module-provider": "0.17.2-alpha.10",
66
- "@lwrjs/nunjucks-view-provider": "0.17.2-alpha.10",
67
- "@lwrjs/o11y": "0.17.2-alpha.10",
68
- "@lwrjs/resource-registry": "0.17.2-alpha.10",
69
- "@lwrjs/router": "0.17.2-alpha.10",
70
- "@lwrjs/server": "0.17.2-alpha.10",
71
- "@lwrjs/shared-utils": "0.17.2-alpha.10",
72
- "@lwrjs/static": "0.17.2-alpha.10",
73
- "@lwrjs/view-registry": "0.17.2-alpha.10",
46
+ "@lwrjs/app-service": "0.17.2-alpha.11",
47
+ "@lwrjs/asset-registry": "0.17.2-alpha.11",
48
+ "@lwrjs/asset-transformer": "0.17.2-alpha.11",
49
+ "@lwrjs/base-view-provider": "0.17.2-alpha.11",
50
+ "@lwrjs/base-view-transformer": "0.17.2-alpha.11",
51
+ "@lwrjs/client-modules": "0.17.2-alpha.11",
52
+ "@lwrjs/config": "0.17.2-alpha.11",
53
+ "@lwrjs/diagnostics": "0.17.2-alpha.11",
54
+ "@lwrjs/esbuild": "0.17.2-alpha.11",
55
+ "@lwrjs/fs-asset-provider": "0.17.2-alpha.11",
56
+ "@lwrjs/fs-watch": "0.17.2-alpha.11",
57
+ "@lwrjs/html-view-provider": "0.17.2-alpha.11",
58
+ "@lwrjs/instrumentation": "0.17.2-alpha.11",
59
+ "@lwrjs/loader": "0.17.2-alpha.11",
60
+ "@lwrjs/lwc-module-provider": "0.17.2-alpha.11",
61
+ "@lwrjs/lwc-ssr": "0.17.2-alpha.11",
62
+ "@lwrjs/markdown-view-provider": "0.17.2-alpha.11",
63
+ "@lwrjs/module-bundler": "0.17.2-alpha.11",
64
+ "@lwrjs/module-registry": "0.17.2-alpha.11",
65
+ "@lwrjs/npm-module-provider": "0.17.2-alpha.11",
66
+ "@lwrjs/nunjucks-view-provider": "0.17.2-alpha.11",
67
+ "@lwrjs/o11y": "0.17.2-alpha.11",
68
+ "@lwrjs/resource-registry": "0.17.2-alpha.11",
69
+ "@lwrjs/router": "0.17.2-alpha.11",
70
+ "@lwrjs/server": "0.17.2-alpha.11",
71
+ "@lwrjs/shared-utils": "0.17.2-alpha.11",
72
+ "@lwrjs/static": "0.17.2-alpha.11",
73
+ "@lwrjs/view-registry": "0.17.2-alpha.11",
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.10",
83
+ "@lwrjs/types": "0.17.2-alpha.11",
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": "3938f97f31973d7953bb61cff8388c71980c22c7"
96
+ "gitHead": "72217912e6c17e617413044743892582be5599a0"
97
97
  }