@lwrjs/lwc-ssr 0.24.2 → 0.24.4

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.
@@ -1,16 +1,28 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
5
  var __export = (target, all) => {
4
6
  for (var name in all)
5
- __defProp(target, name, {get: all[name], enumerable: true});
7
+ __defProp(target, name, { get: all[name], enumerable: true });
6
8
  };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
7
18
 
8
19
  // packages/@lwrjs/lwc-ssr/src/__mocks__/renderer.ts
9
- __markAsModule(exports);
10
- __export(exports, {
20
+ var renderer_exports = {};
21
+ __export(renderer_exports, {
11
22
  Renderer: () => Renderer,
12
23
  getRenderer: () => getRenderer
13
24
  });
25
+ module.exports = __toCommonJS(renderer_exports);
14
26
  var mockComponents = {};
15
27
  function getRenderer() {
16
28
  return new Renderer();
@@ -37,6 +49,6 @@ var Renderer = class {
37
49
  throw new Error(mockOutput.error);
38
50
  }
39
51
  }
40
- return {results, warnings, bundles: new Set([2, 3, 4])};
52
+ return { results, warnings, bundles: /* @__PURE__ */ new Set([2, 3, 4]) };
41
53
  }
42
54
  };
@@ -1,30 +1,43 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
5
  var __export = (target, all) => {
4
6
  for (var name in all)
5
- __defProp(target, name, {get: all[name], enumerable: true});
7
+ __defProp(target, name, { get: all[name], enumerable: true });
6
8
  };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
7
18
 
8
19
  // packages/@lwrjs/lwc-ssr/src/__mocks__/undici.ts
9
- __markAsModule(exports);
10
- __export(exports, {
20
+ var undici_exports = {};
21
+ __export(undici_exports, {
11
22
  Pool: () => Pool
12
23
  });
24
+ module.exports = __toCommonJS(undici_exports);
13
25
  var Pool = class {
26
+ origin = "";
27
+ // passed to the Pool constructor
14
28
  constructor(origin) {
15
- this.origin = "";
16
29
  this.origin = origin;
17
30
  }
18
31
  async request(options) {
19
- const {path} = options;
20
- if (path.endsWith("bad"))
21
- throw new Error("fail");
22
- const ret = {origin: this.origin, req: options};
32
+ const { path } = options;
33
+ if (path.endsWith("bad")) throw new Error("fail");
34
+ const ret = { origin: this.origin, req: options };
23
35
  const retStr = JSON.stringify(ret);
24
36
  return Promise.resolve({
25
37
  statusCode: path.endsWith("fail") ? 500 : path.endsWith("empty") ? 204 : path.endsWith("reset") ? 205 : 200,
26
- headers: {"cache-control": "no-cache", "X-something": void 0, "set-cookie": ["a", "b", "c"]},
38
+ headers: { "cache-control": "no-cache", "X-something": void 0, "set-cookie": ["a", "b", "c"] },
27
39
  body: {
40
+ // return options passed to new Pool() and client.request()
28
41
  arrayBuffer: () => Promise.resolve(Uint8Array.from(retStr.split("").map((letter) => letter.charCodeAt(0)))),
29
42
  text: () => Promise.resolve(retStr),
30
43
  json: () => Promise.resolve(ret)
@@ -1,82 +1,88 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
5
  var __export = (target, all) => {
9
6
  for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
7
+ __defProp(target, name, { get: all[name], enumerable: true });
11
8
  };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
14
  }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
15
+ return to;
22
16
  };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
18
 
24
19
  // packages/@lwrjs/lwc-ssr/src/dataViewTransformer/index.ts
25
- __markAsModule(exports);
26
- __export(exports, {
20
+ var dataViewTransformer_exports = {};
21
+ __export(dataViewTransformer_exports, {
27
22
  default: () => preloadDataViewTransformer
28
23
  });
29
- var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
30
- var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
31
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
- var import_utils = __toModule(require("../utils.cjs"));
33
- var import_renderer = __toModule(require("../renderer.cjs"));
24
+ module.exports = __toCommonJS(dataViewTransformer_exports);
25
+ var import_diagnostics = require("@lwrjs/diagnostics");
26
+ var import_instrumentation = require("@lwrjs/instrumentation");
27
+ var import_shared_utils = require("@lwrjs/shared-utils");
28
+ var import_utils = require("../utils.cjs");
29
+ var import_renderer = require("../renderer.cjs");
34
30
  var NAME = "preload-data-transformer";
35
- function preloadDataViewTransformer(_options, {config, moduleBundler, resourceRegistry}) {
31
+ function preloadDataViewTransformer(_options, { config, moduleBundler, resourceRegistry }) {
36
32
  const routes = [...config.routes, ...config.errorRoutes];
37
33
  return {
38
34
  name: NAME,
39
35
  async link(stringBuilder, viewContext, metadata) {
40
- const allBundles = new Set([...metadata.serverBundles ?? []]);
41
- const {rootComponent} = viewContext.view;
36
+ const allBundles = /* @__PURE__ */ new Set([...metadata.serverBundles ?? []]);
37
+ const { rootComponent } = viewContext.view;
42
38
  if (!rootComponent || !viewContext.view.bootstrap?.preloadData || viewContext.view.bootstrap?.ssr) {
43
39
  return {};
44
40
  }
45
- import_diagnostics.logger.debug({label: NAME, message: `Preload data for root component "${rootComponent}"`});
41
+ import_diagnostics.logger.debug({ label: NAME, message: `Preload data for root component "${rootComponent}"` });
46
42
  const {
47
43
  results = {},
48
44
  warnings,
49
45
  bundles
50
- } = await (0, import_instrumentation.getTracer)().trace({
51
- name: import_instrumentation.ViewSpan.PreloadData,
52
- attributes: {rootComponent}
53
- }, async () => {
54
- const route = routes.find((r) => r.id === viewContext.view.id);
55
- if (!route) {
56
- throw new Error(`Unable to resolve configuration for view: ${viewContext.view.id}`);
57
- }
58
- try {
59
- return await (0, import_renderer.getRenderer)(config, moduleBundler, resourceRegistry).render({[rootComponent]: {specifier: rootComponent, props: {}}}, route, viewContext.runtimeEnvironment, viewContext.runtimeParams);
60
- } catch (e) {
61
- if (e instanceof import_diagnostics.LwrStatusError)
62
- throw e;
63
- const message = import_diagnostics.descriptions.APPLICATION.PRELOAD_DATA_ERROR(rootComponent, (0, import_diagnostics.stringifyError)(e));
64
- import_diagnostics.logger.warn({label: "preloadDataViewTransformer", message});
65
- return {warnings: [message]};
46
+ } = await (0, import_instrumentation.getTracer)().trace(
47
+ {
48
+ name: import_instrumentation.ViewSpan.PreloadData,
49
+ attributes: { rootComponent }
50
+ },
51
+ async () => {
52
+ const route = routes.find((r) => r.id === viewContext.view.id);
53
+ if (!route) {
54
+ throw new Error(`Unable to resolve configuration for view: ${viewContext.view.id}`);
55
+ }
56
+ try {
57
+ return await (0, import_renderer.getRenderer)(config, moduleBundler, resourceRegistry).render(
58
+ { [rootComponent]: { specifier: rootComponent, props: {} } },
59
+ route,
60
+ viewContext.runtimeEnvironment,
61
+ viewContext.runtimeParams
62
+ );
63
+ } catch (e) {
64
+ if (e instanceof import_diagnostics.LwrStatusError) throw e;
65
+ const message = import_diagnostics.descriptions.APPLICATION.PRELOAD_DATA_ERROR(
66
+ rootComponent,
67
+ (0, import_diagnostics.stringifyError)(e)
68
+ );
69
+ import_diagnostics.logger.warn({ label: "preloadDataViewTransformer", message });
70
+ return { warnings: [message] };
71
+ }
66
72
  }
67
- });
73
+ );
68
74
  (0, import_utils.mergeWarnings)(metadata, warnings);
69
75
  const result = results[rootComponent];
70
76
  if (!result) {
71
77
  return {};
72
78
  }
73
- const {props, markup, cache: {ttl} = {ttl: void 0}} = result || {};
74
- import_diagnostics.logger.verbose({label: NAME, message: "response", additionalInfo: props});
79
+ const { props, markup, cache: { ttl } = { ttl: void 0 } } = result || {};
80
+ import_diagnostics.logger.verbose({ label: NAME, message: "response", additionalInfo: props });
75
81
  markup && (0, import_shared_utils.addHeadMarkup)([result.markup], stringBuilder);
76
82
  metadata.serverData = metadata.serverData || {};
77
83
  Object.assign(metadata.serverData, props);
78
- metadata.serverBundles = bundles ? new Set([...allBundles, ...bundles]) : allBundles;
79
- return {cache: {ttl}};
84
+ metadata.serverBundles = bundles ? /* @__PURE__ */ new Set([...allBundles, ...bundles]) : allBundles;
85
+ return { cache: { ttl } };
80
86
  }
81
87
  };
82
88
  }
@@ -1,40 +1,36 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
5
  var __export = (target, all) => {
9
6
  for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
7
+ __defProp(target, name, { get: all[name], enumerable: true });
11
8
  };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
14
  }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
15
+ return to;
22
16
  };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
18
 
24
19
  // packages/@lwrjs/lwc-ssr/src/directFetch.ts
25
- __markAsModule(exports);
26
- __export(exports, {
20
+ var directFetch_exports = {};
21
+ __export(directFetch_exports, {
27
22
  ROUTE_CORE_HEADER: () => ROUTE_CORE_HEADER,
28
23
  fetchWithAgent: () => fetchWithAgent
29
24
  });
30
- var import_undici = __toModule(require("undici"));
31
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
- var import_utils = __toModule(require("./utils.cjs"));
33
- var CORE_CLIENTS = new Map();
25
+ module.exports = __toCommonJS(directFetch_exports);
26
+ var import_undici = require("undici");
27
+ var import_shared_utils = require("@lwrjs/shared-utils");
28
+ var import_utils = require("./utils.cjs");
29
+ var CORE_CLIENTS = /* @__PURE__ */ new Map();
34
30
  var ROUTE_CORE_HEADER = "x-sfdc-route-core";
35
31
  async function fetchWithAgent(request, init, forwardedOrigin, coreProxy, span) {
36
- let {origin, servername} = coreProxy;
37
- const {finalUrl} = (0, import_utils.getFinalRequest)(request, origin.startsWith("http") ? origin : forwardedOrigin);
32
+ let { origin, servername } = coreProxy;
33
+ const { finalUrl } = (0, import_utils.getFinalRequest)(request, origin.startsWith("http") ? origin : forwardedOrigin);
38
34
  const forwardedHostname = (0, import_shared_utils.toHostname)(forwardedOrigin);
39
35
  const hostHeader = coreProxy.host ?? forwardedHostname;
40
36
  const ENHANCED_DOMAIN_TLD = ".site.com";
@@ -68,20 +64,23 @@ async function fetchWithAgent(request, init, forwardedOrigin, coreProxy, span) {
68
64
  }
69
65
  const res = await client.request({
70
66
  ...init,
67
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
68
+ // @ts-ignore - HttpMethod not available for typecasting :|
71
69
  method: init.method || "GET",
72
70
  path,
73
- headers: {...init?.headers, Host: hostHeader},
71
+ headers: { ...init?.headers, Host: hostHeader },
72
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
73
+ // @ts-ignore - not properly typed >:|
74
74
  servername
75
75
  });
76
- span.setAttributes({coreStatusCode: res.statusCode});
76
+ span.setAttributes({ coreStatusCode: res.statusCode });
77
77
  const bodyBuffer = await res.body.arrayBuffer();
78
78
  const body = res.statusCode === 204 || res.statusCode === 205 ? null : bodyBuffer;
79
79
  const headers = new Headers();
80
80
  for (const [key, value] of Object.entries(res.headers)) {
81
- if (!value)
82
- continue;
81
+ if (!value) continue;
83
82
  const values = Array.isArray(value) ? value : [value];
84
83
  values.forEach((v) => headers.append(key, v));
85
84
  }
86
- return new Response(body, {status: res.statusCode, headers});
85
+ return new Response(body, { status: res.statusCode, headers });
87
86
  }
@@ -1,93 +1,105 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
5
  var __export = (target, all) => {
9
6
  for (var name in all)
10
- __defProp(target, name, {get: all[name], enumerable: true});
7
+ __defProp(target, name, { get: all[name], enumerable: true });
11
8
  };
12
- var __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
14
  }
18
- return target;
19
- };
20
- var __toModule = (module2) => {
21
- return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
15
+ return to;
22
16
  };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
18
 
24
19
  // packages/@lwrjs/lwc-ssr/src/fetchController.ts
25
- __markAsModule(exports);
26
- __export(exports, {
20
+ var fetchController_exports = {};
21
+ __export(fetchController_exports, {
27
22
  FetchController: () => FetchController
28
23
  });
29
- var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
30
- var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
31
- var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
- var import_directFetch = __toModule(require("./directFetch.cjs"));
33
- var import_utils = __toModule(require("./utils.cjs"));
24
+ module.exports = __toCommonJS(fetchController_exports);
25
+ var import_diagnostics = require("@lwrjs/diagnostics");
26
+ var import_instrumentation = require("@lwrjs/instrumentation");
27
+ var import_shared_utils = require("@lwrjs/shared-utils");
28
+ var import_directFetch = require("./directFetch.cjs");
29
+ var import_utils = require("./utils.cjs");
34
30
  var FetchController = class {
31
+ killSwitchActivated = false;
32
+ noOpActivated = false;
33
+ abortController;
34
+ headers;
35
+ host;
36
+ coreProxy;
37
+ fetchEndowment;
35
38
  constructor(context, coreProxy) {
36
- this.killSwitchActivated = false;
37
- this.noOpActivated = false;
38
- this.controlledFetch = (request, init) => {
39
- if (this.killSwitchActivated) {
40
- return this.handleAbortError(request, "Kill switch was already enabled");
41
- }
42
- if (!this.abortController) {
43
- this.abortController = new AbortController();
44
- }
45
- const signal = this.abortController?.signal;
46
- const updatedInit = {
47
- ...init,
48
- headers: {...init?.headers, ...this.headers},
49
- signal
50
- };
51
- const fetchFunction = this.noOpActivated ? this.fetchNoOp(request, updatedInit) : this.fetchEndowment(request, updatedInit);
52
- const fetchPromise = fetchFunction.catch((error) => {
53
- const errorMsg = error.message || error;
54
- if (error && (errorMsg.startsWith("AbortError") || error?.stack.startsWith("AbortError"))) {
55
- return this.handleAbortError(request, error);
56
- } else {
57
- throw error;
58
- }
59
- });
60
- return fetchPromise;
61
- };
62
- this.activateKillSwitch = () => {
63
- this.killSwitchActivated = true;
64
- this.abortController?.abort("AbortError: Kill switch enabled");
65
- this.abortController = void 0;
66
- };
67
- this.deactivateKillSwitch = () => {
68
- this.killSwitchActivated = false;
69
- };
70
- this.activateNoOp = () => {
71
- this.noOpActivated = true;
72
- };
73
- this.deactivateNoOp = () => {
74
- this.noOpActivated = false;
75
- };
76
- this.setFetchRequestContext = (context) => {
77
- const {abortController, host, headers} = context;
78
- this.host = host;
79
- this.headers = headers;
80
- this.abortController = abortController;
81
- };
82
39
  this.coreProxy = coreProxy;
83
40
  this.setFetchRequestContext(context);
84
41
  this.fetchEndowment = this.createFetchEndowment();
85
42
  }
43
+ controlledFetch = (request, init) => {
44
+ if (this.killSwitchActivated) {
45
+ return this.handleAbortError(request, "Kill switch was already enabled");
46
+ }
47
+ if (!this.abortController) {
48
+ this.abortController = new AbortController();
49
+ }
50
+ const signal = this.abortController?.signal;
51
+ const updatedInit = {
52
+ ...init,
53
+ headers: { ...init?.headers, ...this.headers },
54
+ signal
55
+ };
56
+ const fetchFunction = this.noOpActivated ? this.fetchNoOp(request, updatedInit) : this.fetchEndowment(request, updatedInit);
57
+ const fetchPromise = fetchFunction.catch((error) => {
58
+ const errorMsg = error.message || error;
59
+ if (error && (errorMsg.startsWith("AbortError") || error?.stack.startsWith("AbortError"))) {
60
+ return this.handleAbortError(request, error);
61
+ } else {
62
+ throw error;
63
+ }
64
+ });
65
+ return fetchPromise;
66
+ };
67
+ /**
68
+ * After SSR is complete the kill switch will abort any pending fetch requests.
69
+ */
70
+ activateKillSwitch = () => {
71
+ this.killSwitchActivated = true;
72
+ this.abortController?.abort("AbortError: Kill switch enabled");
73
+ this.abortController = void 0;
74
+ };
75
+ deactivateKillSwitch = () => {
76
+ this.killSwitchActivated = false;
77
+ };
78
+ /**
79
+ * During SSR renderComponent (which is synchronous) Do not even call any fetch requests
80
+ * since they would not complete before SSR is done.
81
+ */
82
+ activateNoOp = () => {
83
+ this.noOpActivated = true;
84
+ };
85
+ deactivateNoOp = () => {
86
+ this.noOpActivated = false;
87
+ };
88
+ setFetchRequestContext = (context) => {
89
+ const { abortController, host, headers } = context;
90
+ this.host = host;
91
+ this.headers = headers;
92
+ this.abortController = abortController;
93
+ };
86
94
  handleAbortError(request, error) {
87
95
  const message = `${String(request)} request was killed. Either the request timed out or it was dispatched during SSR. Async processes are not supported during SSR. For more information, see: https://developer.salesforce.com/docs/platform/lwr/guide/lwr-configure-component-ssr.html.`;
88
- import_diagnostics.logger.warn({label: `Server-side Rendering`, message}, error);
89
- return Promise.resolve(new Response(message, {status: 500}));
96
+ import_diagnostics.logger.warn({ label: `Server-side Rendering`, message }, error);
97
+ return Promise.resolve(new Response(message, { status: 500 }));
90
98
  }
99
+ /**
100
+ * Create a fetch API that never calls a request.
101
+ * This is not expected to be called without an AbortController setup.
102
+ */
91
103
  fetchNoOp(request, init) {
92
104
  return new Promise((resolve) => {
93
105
  if (!init?.signal) {
@@ -97,7 +109,12 @@ var FetchController = class {
97
109
  } else {
98
110
  const abortHandler = (err) => {
99
111
  init?.signal?.removeEventListener("abort", abortHandler);
100
- resolve(this.handleAbortError(request, new Error("Not allowed: Request was dispatched during SSR", {cause: err})));
112
+ resolve(
113
+ this.handleAbortError(
114
+ request,
115
+ new Error("Not allowed: Request was dispatched during SSR", { cause: err })
116
+ )
117
+ );
101
118
  };
102
119
  init.signal.addEventListener("abort", abortHandler);
103
120
  }
@@ -105,8 +122,8 @@ var FetchController = class {
105
122
  }
106
123
  createFetchEndowment() {
107
124
  return (request, init = {}) => {
108
- const {host: forwardedOrigin = "", coreProxy} = this;
109
- const {finalRequest, finalUrl} = (0, import_utils.getFinalRequest)(request, forwardedOrigin);
125
+ const { host: forwardedOrigin = "", coreProxy } = this;
126
+ const { finalRequest, finalUrl } = (0, import_utils.getFinalRequest)(request, forwardedOrigin);
110
127
  if (coreProxy || forwardedOrigin && finalUrl.startsWith(forwardedOrigin)) {
111
128
  init.headers[import_directFetch.ROUTE_CORE_HEADER] = "true";
112
129
  }
@@ -115,31 +132,36 @@ var FetchController = class {
115
132
  label: `pre ${import_instrumentation.ViewSpan.Fetch}`,
116
133
  message: `finalUrl: ${finalUrl}, hasCookies: ${hasCookies}`
117
134
  });
118
- return (0, import_instrumentation.getTracer)().trace({
119
- name: import_instrumentation.ViewSpan.Fetch,
120
- attributes: {
121
- url: finalUrl,
122
- fetchType: "cdn",
123
- forwardedOrigin,
124
- hasCookies
135
+ return (0, import_instrumentation.getTracer)().trace(
136
+ // fetchType is one of ['cdn' (default), 'direct']
137
+ // Default URL to final URL if successful addInfoToSpan will replace with response.url
138
+ {
139
+ name: import_instrumentation.ViewSpan.Fetch,
140
+ attributes: {
141
+ url: finalUrl,
142
+ fetchType: "cdn",
143
+ forwardedOrigin,
144
+ hasCookies
145
+ }
146
+ },
147
+ (span) => {
148
+ const withTracing = (fetchPromise) => {
149
+ return fetchPromise.then((res) => {
150
+ res.url && span.setAttributes({ url: res.url });
151
+ span.setAttributes({ statusCode: res.status });
152
+ return res;
153
+ }).catch((e) => {
154
+ span.setAttributes({ error: (0, import_diagnostics.stringifyError)(e) });
155
+ throw e;
156
+ });
157
+ };
158
+ init.headers = { ...init.headers, ...(0, import_shared_utils.getTraceHeaders)({}, span) };
159
+ if (coreProxy) {
160
+ return withTracing((0, import_directFetch.fetchWithAgent)(request, init, forwardedOrigin, coreProxy, span));
161
+ }
162
+ return withTracing(fetch(finalRequest, init));
125
163
  }
126
- }, (span) => {
127
- const withTracing = (fetchPromise) => {
128
- return fetchPromise.then((res) => {
129
- res.url && span.setAttributes({url: res.url});
130
- span.setAttributes({statusCode: res.status});
131
- return res;
132
- }).catch((e) => {
133
- span.setAttributes({error: (0, import_diagnostics.stringifyError)(e)});
134
- throw e;
135
- });
136
- };
137
- init.headers = {...init.headers, ...(0, import_shared_utils.getTraceHeaders)({}, span)};
138
- if (coreProxy) {
139
- return withTracing((0, import_directFetch.fetchWithAgent)(request, init, forwardedOrigin, coreProxy, span));
140
- }
141
- return withTracing(fetch(finalRequest, init));
142
- });
164
+ );
143
165
  };
144
166
  }
145
167
  };