codeforlife 2.11.0 → 2.11.2

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.
@@ -9,7 +9,7 @@ import df from "events";
9
9
  import uh from "util";
10
10
  import { c as xh } from "../client-BK9NlSVR.js";
11
11
  import Ms from "react-dom";
12
- import { A as ch } from "../App-3VkR-ZEZ.js";
12
+ import ch from "./App.es.js";
13
13
  var zs = { exports: {} }, Ef;
14
14
  function Eh() {
15
15
  return Ef || (Ef = 1, (function(se, K) {
@@ -0,0 +1,6 @@
1
+ "use strict";var u=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var w=(r,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let a of v(s))!k.call(r,a)&&a!==e&&c(r,a,{get:()=>s[a],enumerable:!(t=m(s,a))||t.enumerable});return r};var o=(r,s,e)=>(e=r!=null?u(C(r)):{},w(s||!r||!r.__esModule?c(e,"default",{value:r,enumerable:!0}):e,r));const y=require("memory-cache"),S=require("node:crypto"),f=require("express"),l=require("node:fs/promises"),I=require("node:http");class P{envIsProduction;templateHtml;hostname;mode;port;base;app;server;cache;healthCheckCacheKey;healthCheckCacheTimeout;healthCheckStatusCodes;devtoolsWorkspaceUUID;constructor({mode:s,port:e,base:t}={}){this.envIsProduction=process.env.NODE_ENV==="production",this.templateHtml="",this.hostname=this.envIsProduction?"0.0.0.0":"127.0.0.1",this.mode=s||process.env.MODE||"development",this.port=e||(process.env.PORT?Number(process.env.PORT):this.envIsProduction?8080:5173),this.base=t||process.env.BASE||"",this.app=f(),this.server=I.createServer(this.app),this.cache=new y.Cache,this.healthCheckCacheKey="health-check",this.healthCheckCacheTimeout=3e4,this.healthCheckStatusCodes={healthy:200,startingUp:503,shuttingDown:503,unhealthy:503,unknown:503},this.devtoolsWorkspaceUUID=S.randomUUID()}getHealthCheck(s){return{healthStatus:"healthy",additionalInfo:"All healthy."}}handleHealthCheck(s,e){let t=this.cache.get(this.healthCheckCacheKey);if(t===null){const a=this.getHealthCheck(s);a.healthStatus!=="healthy"&&console.warn(`health check: ${JSON.stringify(a)}`),t={appId:process.env.APP_ID||"REPLACE_ME",healthStatus:a.healthStatus,lastCheckedTimestamp:new Date().toISOString(),additionalInformation:a.additionalInfo,startupTimestamp:new Date().toISOString(),appVersion:process.env.APP_VERSION||"REPLACE_ME",details:a.details||[]},this.cache.put(this.healthCheckCacheKey,t,this.healthCheckCacheTimeout)}e.status(this.healthCheckStatusCodes[t.healthStatus]).json(t)}async handleServeHtml(s,e,{getRenderAndTemplate:t,onServeError:a}){try{const h=s.originalUrl.replace(this.base,""),[n,p]=await t(h),i=await n(h),d=p.replace("<!--app-head-->",i.head??"").replace("<!--app-html-->",i.html??"");e.status(200).set({"Content-Type":"text/html"}).send(d)}catch(h){if(h instanceof Error){console.error(h.stack);const n=a(h);e.status(500).end(n)}}}handleChromeDevTools(s,e){if(this.envIsProduction)e.status(404).json({});else{const t=process.env.LOCAL_WORKSPACE_PATH;let a,h;t?(a=200,h={workspace:{uuid:this.devtoolsWorkspaceUUID,root:t}}):(a=404,h={error:"Local workspace path not configured."}),e.status(a).json(h)}}async setUpProduction(){const s=(await import("compression")).default,e=(await import("sirv")).default;return this.templateHtml=await l.readFile("./dist/client/index.html","utf-8"),this.app.use(s()),this.app.use(this.base,e("./dist/client",{extensions:[]})),{getRenderAndTemplate:async()=>{const t=(await import("../../../dist/server/entry-server.js")).render,a=this.templateHtml;return[t,a]},onServeError:()=>{}}}async setUpDevelopment(){const{createServer:s}=await import("vite"),e=await s({configFile:"/workspace/frontend/vite.config.ts",server:{middlewareMode:!0,hmr:{server:this.server}},appType:"custom",base:this.base,mode:this.mode});return this.app.use(e.middlewares),{getRenderAndTemplate:async t=>{const a=(await e.ssrLoadModule("/src/entry-server.tsx")).render;let h=await l.readFile("./index.html","utf-8");return h=await e.transformIndexHtml(t,h),[a,h]},onServeError:t=>(e.ssrFixStacktrace(t),t.stack)}}async run(){const s=this.envIsProduction?await this.setUpProduction():await this.setUpDevelopment();this.app.get("/health-check",(e,t)=>{this.handleHealthCheck(e,t)}),this.app.get("/.well-known/appspecific/com.chrome.devtools.json",(e,t)=>{this.handleChromeDevTools(e,t)}),this.app.get("*",async(e,t)=>{await this.handleServeHtml(e,t,s)}),this.server.listen(this.port,this.hostname,()=>{let e=`Server started.
2
+ url: http://${this.hostname}:${this.port}
3
+ environment: ${process.env.NODE_ENV}
4
+ `;this.envIsProduction||(e+=`mode: ${this.mode}
5
+ `),console.log(e)})}}module.exports=P;
6
+ //# sourceMappingURL=server.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.cjs.js","sources":["../../src/server/server.ts"],"sourcesContent":["/**\n * © Ocado Group\n * Created on 13/12/2024 at 12:15:05(+00:00).\n *\n * A server for an app in a live environment.\n * Based off: https://github.com/bluwy/create-vite-extra/blob/master/template-ssr-react-ts/server.js\n */\n\nimport { Cache, type CacheClass } from \"memory-cache\"\nimport { type UUID, randomUUID } from \"node:crypto\"\nimport express, { type Express, type Request, type Response } from \"express\"\nimport fs from \"node:fs/promises\"\nimport http from \"node:http\"\n\ntype Mode = \"development\" | \"staging\" | \"production\"\ntype Options = Partial<{\n mode: Mode\n port: number\n base: string\n}>\n\ntype HealthStatus =\n | \"healthy\"\n | \"startingUp\"\n | \"shuttingDown\"\n | \"unhealthy\"\n | \"unknown\"\ntype HealthCheck = {\n healthStatus: HealthStatus\n additionalInfo: string\n details?: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\ntype HealthCheckResponse = {\n appId: string\n healthStatus: HealthStatus\n lastCheckedTimestamp: string\n additionalInformation: string\n startupTimestamp: string\n appVersion: string\n details: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\n\ntype Render = (path: string) => Promise<{ head?: string; html?: string }>\ntype EntryModule = { render: Render }\ntype RenderAndTemplate = [Render, string]\ntype GetRenderAndTemplate = (path: string) => Promise<RenderAndTemplate>\ntype OnServeError = (error: Error) => string | undefined\n\ntype Setup = {\n getRenderAndTemplate: GetRenderAndTemplate\n onServeError: OnServeError\n}\n\nexport default class Server {\n envIsProduction: boolean\n templateHtml: string\n hostname: string\n mode: Mode\n port: number\n base: string\n app: Express\n server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>\n cache: CacheClass<string, any>\n healthCheckCacheKey: string\n healthCheckCacheTimeout: number\n healthCheckStatusCodes: Record<HealthStatus, number>\n devtoolsWorkspaceUUID: UUID\n\n constructor({ mode, port, base }: Options = {}) {\n this.envIsProduction = process.env.NODE_ENV === \"production\"\n this.templateHtml = \"\"\n this.hostname = this.envIsProduction ? \"0.0.0.0\" : \"127.0.0.1\"\n\n this.mode = mode || (process.env.MODE as Mode) || \"development\"\n this.port =\n port ||\n (process.env.PORT\n ? Number(process.env.PORT)\n : this.envIsProduction\n ? 8080\n : 5173)\n this.base = base || process.env.BASE || \"\"\n\n this.app = express()\n this.server = http.createServer(this.app)\n this.cache = new Cache()\n\n this.healthCheckCacheKey = \"health-check\"\n this.healthCheckCacheTimeout = 30000\n this.healthCheckStatusCodes = {\n // The app is running normally.\n healthy: 200,\n // The app is performing app-specific initialisation which must\n // complete before it will serve normal application requests\n // (perhaps the app is warming a cache or something similar). You\n // only need to use this status if your app will be in a start-up\n // mode for a prolonged period of time.\n startingUp: 503,\n // The app is shutting down. As with startingUp, you only need to\n // use this status if your app takes a prolonged amount of time\n // to shutdown, perhaps because it waits for a long-running\n // process to complete before shutting down.\n shuttingDown: 503,\n // The app is not running normally.\n unhealthy: 503,\n // The app is not able to report its own state.\n unknown: 503,\n }\n\n this.devtoolsWorkspaceUUID = randomUUID()\n }\n\n // @ts-expect-error unused var\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getHealthCheck(request: Request): HealthCheck {\n return {\n healthStatus: \"healthy\",\n additionalInfo: \"All healthy.\",\n }\n }\n\n handleHealthCheck(request: Request, response: Response): void {\n let value: HealthCheckResponse = this.cache.get(\n this.healthCheckCacheKey,\n ) as HealthCheckResponse\n if (value === null) {\n const healthCheck = this.getHealthCheck(request)\n\n if (healthCheck.healthStatus !== \"healthy\") {\n console.warn(`health check: ${JSON.stringify(healthCheck)}`)\n }\n\n value = {\n appId: process.env.APP_ID || \"REPLACE_ME\",\n healthStatus: healthCheck.healthStatus,\n lastCheckedTimestamp: new Date().toISOString(),\n additionalInformation: healthCheck.additionalInfo,\n startupTimestamp: new Date().toISOString(),\n appVersion: process.env.APP_VERSION || \"REPLACE_ME\",\n details: healthCheck.details || [],\n }\n\n this.cache.put(\n this.healthCheckCacheKey,\n value,\n this.healthCheckCacheTimeout,\n )\n }\n\n response.status(this.healthCheckStatusCodes[value.healthStatus]).json(value)\n }\n\n async handleServeHtml(\n request: Request,\n response: Response,\n { getRenderAndTemplate, onServeError }: Setup,\n ): Promise<void> {\n try {\n const path = request.originalUrl.replace(this.base, \"\")\n\n const [render, template] = await getRenderAndTemplate(path)\n\n const rendered = await render(path)\n\n const html = template\n .replace(`<!--app-head-->`, rendered.head ?? \"\")\n .replace(`<!--app-html-->`, rendered.html ?? \"\")\n\n response.status(200).set({ \"Content-Type\": \"text/html\" }).send(html)\n } catch (error) {\n if (error instanceof Error) {\n console.error(error.stack)\n const body = onServeError(error)\n response.status(500).end(body)\n }\n }\n }\n\n // @ts-expect-error unused var\n handleChromeDevTools(request: Request, response: Response) {\n if (this.envIsProduction) {\n response.status(404).json({})\n } else {\n const localWorkspacePath = process.env.LOCAL_WORKSPACE_PATH\n\n let code: number\n let body: object\n if (localWorkspacePath) {\n code = 200\n body = {\n workspace: {\n uuid: this.devtoolsWorkspaceUUID,\n root: localWorkspacePath,\n },\n }\n } else {\n code = 404\n body = { error: \"Local workspace path not configured.\" }\n }\n\n response.status(code).json(body)\n }\n }\n\n async setUpProduction(): Promise<Setup> {\n const compression = (await import(\"compression\")).default\n const sirv = (await import(\"sirv\")).default\n\n this.templateHtml = await fs.readFile(\"./dist/client/index.html\", \"utf-8\")\n\n this.app.use(compression())\n this.app.use(this.base, sirv(\"./dist/client\", { extensions: [] }))\n\n return {\n getRenderAndTemplate: async () => {\n const render = (\n (await import(\n // @ts-expect-error only present after building installing app.\n \"../../../dist/server/entry-server.js\"\n )) as EntryModule\n ).render\n\n // Use cached template.\n const template = this.templateHtml\n\n return [render, template]\n },\n onServeError: () => undefined,\n }\n }\n\n async setUpDevelopment(): Promise<Setup> {\n const { createServer } = await import(\"vite\")\n\n const vite = await createServer({\n configFile: \"/workspace/frontend/vite.config.ts\",\n server: {\n middlewareMode: true,\n hmr: { server: this.server },\n },\n appType: \"custom\",\n base: this.base,\n mode: this.mode,\n })\n\n this.app.use(vite.middlewares)\n\n return {\n getRenderAndTemplate: async path => {\n const render = (\n (await vite.ssrLoadModule(\"/src/entry-server.tsx\")) as EntryModule\n ).render\n\n // Always read fresh template.\n let template = await fs.readFile(\"./index.html\", \"utf-8\")\n template = await vite.transformIndexHtml(path, template)\n\n return [render, template]\n },\n onServeError: error => {\n vite.ssrFixStacktrace(error)\n return error.stack\n },\n }\n }\n\n async run() {\n const setup = this.envIsProduction\n ? await this.setUpProduction()\n : await this.setUpDevelopment()\n\n this.app.get(\"/health-check\", (request, response) => {\n this.handleHealthCheck(request, response)\n })\n\n this.app.get(\n \"/.well-known/appspecific/com.chrome.devtools.json\",\n (request, response) => {\n this.handleChromeDevTools(request, response)\n },\n )\n\n this.app.get(\"*\", async (request, response) => {\n await this.handleServeHtml(request, response, setup)\n })\n\n this.server.listen(this.port, this.hostname, () => {\n let startMessage =\n \"Server started.\\n\" +\n `url: http://${this.hostname}:${this.port}\\n` +\n `environment: ${process.env.NODE_ENV}\\n`\n\n if (!this.envIsProduction) startMessage += `mode: ${this.mode}\\n`\n\n console.log(startMessage)\n })\n }\n}\n"],"names":["Server","mode","port","base","express","http","Cache","randomUUID","request","response","value","healthCheck","getRenderAndTemplate","onServeError","path","render","template","rendered","html","error","body","localWorkspacePath","code","compression","sirv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C,MAAM,KAAK,gBAAgBD,EAASC,EAAUmB,CAAK,CACrD,CAAC,EAED,KAAK,OAAO,OAAO,KAAK,KAAM,KAAK,SAAU,IAAM,CACjD,IAAIC,EACF;AAAA,cACe,KAAK,QAAQ,IAAI,KAAK,IAAI;AAAA,eACzB,QAAQ,IAAI,QAAQ;AAAA,EAEjC,KAAK,kBAAiBA,GAAgB,SAAS,KAAK,IAAI;AAAA,GAE7D,QAAQ,IAAIA,CAAY,CAC1B,CAAC,CACH,CACF"}
@@ -3,7 +3,6 @@ import { randomUUID as p } from "node:crypto";
3
3
  import d from "express";
4
4
  import i from "node:fs/promises";
5
5
  import m from "node:http";
6
- import { A as P } from "../App-3VkR-ZEZ.js";
7
6
  class S {
8
7
  envIsProduction;
9
8
  templateHtml;
@@ -18,8 +17,8 @@ class S {
18
17
  healthCheckCacheTimeout;
19
18
  healthCheckStatusCodes;
20
19
  devtoolsWorkspaceUUID;
21
- constructor({ mode: o, port: e, base: t } = {}) {
22
- this.envIsProduction = process.env.NODE_ENV === "production", this.templateHtml = "", this.hostname = this.envIsProduction ? "0.0.0.0" : "127.0.0.1", this.mode = o || process.env.MODE || "development", this.port = e || (process.env.PORT ? Number(process.env.PORT) : this.envIsProduction ? 8080 : 5173), this.base = t || process.env.BASE || "", this.app = d(), this.server = m.createServer(this.app), this.cache = new l(), this.healthCheckCacheKey = "health-check", this.healthCheckCacheTimeout = 3e4, this.healthCheckStatusCodes = {
20
+ constructor({ mode: h, port: e, base: t } = {}) {
21
+ this.envIsProduction = process.env.NODE_ENV === "production", this.templateHtml = "", this.hostname = this.envIsProduction ? "0.0.0.0" : "127.0.0.1", this.mode = h || process.env.MODE || "development", this.port = e || (process.env.PORT ? Number(process.env.PORT) : this.envIsProduction ? 8080 : 5173), this.base = t || process.env.BASE || "", this.app = d(), this.server = m.createServer(this.app), this.cache = new l(), this.healthCheckCacheKey = "health-check", this.healthCheckCacheTimeout = 3e4, this.healthCheckStatusCodes = {
23
22
  // The app is running normally.
24
23
  healthy: 200,
25
24
  // The app is performing app-specific initialisation which must
@@ -41,18 +40,18 @@ class S {
41
40
  }
42
41
  // @ts-expect-error unused var
43
42
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
- getHealthCheck(o) {
43
+ getHealthCheck(h) {
45
44
  return {
46
45
  healthStatus: "healthy",
47
46
  additionalInfo: "All healthy."
48
47
  };
49
48
  }
50
- handleHealthCheck(o, e) {
49
+ handleHealthCheck(h, e) {
51
50
  let t = this.cache.get(
52
51
  this.healthCheckCacheKey
53
52
  );
54
53
  if (t === null) {
55
- const s = this.getHealthCheck(o);
54
+ const s = this.getHealthCheck(h);
56
55
  s.healthStatus !== "healthy" && console.warn(`health check: ${JSON.stringify(s)}`), t = {
57
56
  appId: process.env.APP_ID || "REPLACE_ME",
58
57
  healthStatus: s.healthStatus,
@@ -69,20 +68,20 @@ class S {
69
68
  }
70
69
  e.status(this.healthCheckStatusCodes[t.healthStatus]).json(t);
71
70
  }
72
- async handleServeHtml(o, e, { getRenderAndTemplate: t, onServeError: s }) {
71
+ async handleServeHtml(h, e, { getRenderAndTemplate: t, onServeError: s }) {
73
72
  try {
74
- const a = o.originalUrl.replace(this.base, ""), [h, n] = await t(a), r = await h(a), c = n.replace("<!--app-head-->", r.head ?? "").replace("<!--app-html-->", r.html ?? "");
73
+ const a = h.originalUrl.replace(this.base, ""), [o, n] = await t(a), r = await o(a), c = n.replace("<!--app-head-->", r.head ?? "").replace("<!--app-html-->", r.html ?? "");
75
74
  e.status(200).set({ "Content-Type": "text/html" }).send(c);
76
75
  } catch (a) {
77
76
  if (a instanceof Error) {
78
77
  console.error(a.stack);
79
- const h = s(a);
80
- e.status(500).end(h);
78
+ const o = s(a);
79
+ e.status(500).end(o);
81
80
  }
82
81
  }
83
82
  }
84
83
  // @ts-expect-error unused var
85
- handleChromeDevTools(o, e) {
84
+ handleChromeDevTools(h, e) {
86
85
  if (this.envIsProduction)
87
86
  e.status(404).json({});
88
87
  else {
@@ -97,8 +96,8 @@ class S {
97
96
  }
98
97
  }
99
98
  async setUpProduction() {
100
- const o = (await import("compression")).default, e = (await import("sirv")).default;
101
- return this.templateHtml = await i.readFile("./dist/client/index.html", "utf-8"), this.app.use(o()), this.app.use(this.base, e("./dist/client", { extensions: [] })), {
99
+ const h = (await import("compression")).default, e = (await import("sirv")).default;
100
+ return this.templateHtml = await i.readFile("./dist/client/index.html", "utf-8"), this.app.use(h()), this.app.use(this.base, e("./dist/client", { extensions: [] })), {
102
101
  getRenderAndTemplate: async () => {
103
102
  const t = (await import(
104
103
  // @ts-expect-error only present after building installing app.
@@ -111,7 +110,7 @@ class S {
111
110
  };
112
111
  }
113
112
  async setUpDevelopment() {
114
- const { createServer: o } = await import("vite"), e = await o({
113
+ const { createServer: h } = await import("vite"), e = await h({
115
114
  configFile: "/workspace/frontend/vite.config.ts",
116
115
  server: {
117
116
  middlewareMode: !0,
@@ -131,7 +130,7 @@ class S {
131
130
  };
132
131
  }
133
132
  async run() {
134
- const o = this.envIsProduction ? await this.setUpProduction() : await this.setUpDevelopment();
133
+ const h = this.envIsProduction ? await this.setUpProduction() : await this.setUpDevelopment();
135
134
  this.app.get("/health-check", (e, t) => {
136
135
  this.handleHealthCheck(e, t);
137
136
  }), this.app.get(
@@ -140,7 +139,7 @@ class S {
140
139
  this.handleChromeDevTools(e, t);
141
140
  }
142
141
  ), this.app.get("*", async (e, t) => {
143
- await this.handleServeHtml(e, t, o);
142
+ await this.handleServeHtml(e, t, h);
144
143
  }), this.server.listen(this.port, this.hostname, () => {
145
144
  let e = `Server started.
146
145
  url: http://${this.hostname}:${this.port}
@@ -152,7 +151,6 @@ environment: ${process.env.NODE_ENV}
152
151
  }
153
152
  }
154
153
  export {
155
- P as App,
156
- S as Server
154
+ S as default
157
155
  };
158
- //# sourceMappingURL=index.es.js.map
156
+ //# sourceMappingURL=server.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../src/server/server.ts"],"sourcesContent":["/**\n * © Ocado Group\n * Created on 13/12/2024 at 12:15:05(+00:00).\n *\n * A server for an app in a live environment.\n * Based off: https://github.com/bluwy/create-vite-extra/blob/master/template-ssr-react-ts/server.js\n */\n\nimport { Cache, type CacheClass } from \"memory-cache\"\nimport { type UUID, randomUUID } from \"node:crypto\"\nimport express, { type Express, type Request, type Response } from \"express\"\nimport fs from \"node:fs/promises\"\nimport http from \"node:http\"\n\ntype Mode = \"development\" | \"staging\" | \"production\"\ntype Options = Partial<{\n mode: Mode\n port: number\n base: string\n}>\n\ntype HealthStatus =\n | \"healthy\"\n | \"startingUp\"\n | \"shuttingDown\"\n | \"unhealthy\"\n | \"unknown\"\ntype HealthCheck = {\n healthStatus: HealthStatus\n additionalInfo: string\n details?: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\ntype HealthCheckResponse = {\n appId: string\n healthStatus: HealthStatus\n lastCheckedTimestamp: string\n additionalInformation: string\n startupTimestamp: string\n appVersion: string\n details: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\n\ntype Render = (path: string) => Promise<{ head?: string; html?: string }>\ntype EntryModule = { render: Render }\ntype RenderAndTemplate = [Render, string]\ntype GetRenderAndTemplate = (path: string) => Promise<RenderAndTemplate>\ntype OnServeError = (error: Error) => string | undefined\n\ntype Setup = {\n getRenderAndTemplate: GetRenderAndTemplate\n onServeError: OnServeError\n}\n\nexport default class Server {\n envIsProduction: boolean\n templateHtml: string\n hostname: string\n mode: Mode\n port: number\n base: string\n app: Express\n server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>\n cache: CacheClass<string, any>\n healthCheckCacheKey: string\n healthCheckCacheTimeout: number\n healthCheckStatusCodes: Record<HealthStatus, number>\n devtoolsWorkspaceUUID: UUID\n\n constructor({ mode, port, base }: Options = {}) {\n this.envIsProduction = process.env.NODE_ENV === \"production\"\n this.templateHtml = \"\"\n this.hostname = this.envIsProduction ? \"0.0.0.0\" : \"127.0.0.1\"\n\n this.mode = mode || (process.env.MODE as Mode) || \"development\"\n this.port =\n port ||\n (process.env.PORT\n ? Number(process.env.PORT)\n : this.envIsProduction\n ? 8080\n : 5173)\n this.base = base || process.env.BASE || \"\"\n\n this.app = express()\n this.server = http.createServer(this.app)\n this.cache = new Cache()\n\n this.healthCheckCacheKey = \"health-check\"\n this.healthCheckCacheTimeout = 30000\n this.healthCheckStatusCodes = {\n // The app is running normally.\n healthy: 200,\n // The app is performing app-specific initialisation which must\n // complete before it will serve normal application requests\n // (perhaps the app is warming a cache or something similar). You\n // only need to use this status if your app will be in a start-up\n // mode for a prolonged period of time.\n startingUp: 503,\n // The app is shutting down. As with startingUp, you only need to\n // use this status if your app takes a prolonged amount of time\n // to shutdown, perhaps because it waits for a long-running\n // process to complete before shutting down.\n shuttingDown: 503,\n // The app is not running normally.\n unhealthy: 503,\n // The app is not able to report its own state.\n unknown: 503,\n }\n\n this.devtoolsWorkspaceUUID = randomUUID()\n }\n\n // @ts-expect-error unused var\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getHealthCheck(request: Request): HealthCheck {\n return {\n healthStatus: \"healthy\",\n additionalInfo: \"All healthy.\",\n }\n }\n\n handleHealthCheck(request: Request, response: Response): void {\n let value: HealthCheckResponse = this.cache.get(\n this.healthCheckCacheKey,\n ) as HealthCheckResponse\n if (value === null) {\n const healthCheck = this.getHealthCheck(request)\n\n if (healthCheck.healthStatus !== \"healthy\") {\n console.warn(`health check: ${JSON.stringify(healthCheck)}`)\n }\n\n value = {\n appId: process.env.APP_ID || \"REPLACE_ME\",\n healthStatus: healthCheck.healthStatus,\n lastCheckedTimestamp: new Date().toISOString(),\n additionalInformation: healthCheck.additionalInfo,\n startupTimestamp: new Date().toISOString(),\n appVersion: process.env.APP_VERSION || \"REPLACE_ME\",\n details: healthCheck.details || [],\n }\n\n this.cache.put(\n this.healthCheckCacheKey,\n value,\n this.healthCheckCacheTimeout,\n )\n }\n\n response.status(this.healthCheckStatusCodes[value.healthStatus]).json(value)\n }\n\n async handleServeHtml(\n request: Request,\n response: Response,\n { getRenderAndTemplate, onServeError }: Setup,\n ): Promise<void> {\n try {\n const path = request.originalUrl.replace(this.base, \"\")\n\n const [render, template] = await getRenderAndTemplate(path)\n\n const rendered = await render(path)\n\n const html = template\n .replace(`<!--app-head-->`, rendered.head ?? \"\")\n .replace(`<!--app-html-->`, rendered.html ?? \"\")\n\n response.status(200).set({ \"Content-Type\": \"text/html\" }).send(html)\n } catch (error) {\n if (error instanceof Error) {\n console.error(error.stack)\n const body = onServeError(error)\n response.status(500).end(body)\n }\n }\n }\n\n // @ts-expect-error unused var\n handleChromeDevTools(request: Request, response: Response) {\n if (this.envIsProduction) {\n response.status(404).json({})\n } else {\n const localWorkspacePath = process.env.LOCAL_WORKSPACE_PATH\n\n let code: number\n let body: object\n if (localWorkspacePath) {\n code = 200\n body = {\n workspace: {\n uuid: this.devtoolsWorkspaceUUID,\n root: localWorkspacePath,\n },\n }\n } else {\n code = 404\n body = { error: \"Local workspace path not configured.\" }\n }\n\n response.status(code).json(body)\n }\n }\n\n async setUpProduction(): Promise<Setup> {\n const compression = (await import(\"compression\")).default\n const sirv = (await import(\"sirv\")).default\n\n this.templateHtml = await fs.readFile(\"./dist/client/index.html\", \"utf-8\")\n\n this.app.use(compression())\n this.app.use(this.base, sirv(\"./dist/client\", { extensions: [] }))\n\n return {\n getRenderAndTemplate: async () => {\n const render = (\n (await import(\n // @ts-expect-error only present after building installing app.\n \"../../../dist/server/entry-server.js\"\n )) as EntryModule\n ).render\n\n // Use cached template.\n const template = this.templateHtml\n\n return [render, template]\n },\n onServeError: () => undefined,\n }\n }\n\n async setUpDevelopment(): Promise<Setup> {\n const { createServer } = await import(\"vite\")\n\n const vite = await createServer({\n configFile: \"/workspace/frontend/vite.config.ts\",\n server: {\n middlewareMode: true,\n hmr: { server: this.server },\n },\n appType: \"custom\",\n base: this.base,\n mode: this.mode,\n })\n\n this.app.use(vite.middlewares)\n\n return {\n getRenderAndTemplate: async path => {\n const render = (\n (await vite.ssrLoadModule(\"/src/entry-server.tsx\")) as EntryModule\n ).render\n\n // Always read fresh template.\n let template = await fs.readFile(\"./index.html\", \"utf-8\")\n template = await vite.transformIndexHtml(path, template)\n\n return [render, template]\n },\n onServeError: error => {\n vite.ssrFixStacktrace(error)\n return error.stack\n },\n }\n }\n\n async run() {\n const setup = this.envIsProduction\n ? await this.setUpProduction()\n : await this.setUpDevelopment()\n\n this.app.get(\"/health-check\", (request, response) => {\n this.handleHealthCheck(request, response)\n })\n\n this.app.get(\n \"/.well-known/appspecific/com.chrome.devtools.json\",\n (request, response) => {\n this.handleChromeDevTools(request, response)\n },\n )\n\n this.app.get(\"*\", async (request, response) => {\n await this.handleServeHtml(request, response, setup)\n })\n\n this.server.listen(this.port, this.hostname, () => {\n let startMessage =\n \"Server started.\\n\" +\n `url: http://${this.hostname}:${this.port}\\n` +\n `environment: ${process.env.NODE_ENV}\\n`\n\n if (!this.envIsProduction) startMessage += `mode: ${this.mode}\\n`\n\n console.log(startMessage)\n })\n }\n}\n"],"names":["Server","mode","port","base","express","http","Cache","randomUUID","request","response","value","healthCheck","getRenderAndTemplate","onServeError","path","render","template","rendered","html","error","body","localWorkspacePath","code","compression","sirv","fs","createServer","vite","setup","startMessage"],"mappings":"+rBA6DA,MAAqBA,CAAO,CAC1B,gBACA,aACA,SACA,KACA,KACA,KACA,IACA,OACA,MACA,oBACA,wBACA,uBACA,sBAEA,YAAY,CAAE,KAAAC,EAAM,KAAAC,EAAM,KAAAC,CAAA,EAAkB,CAAA,EAAI,CAC9C,KAAK,gBAAkB,QAAQ,IAAI,WAAa,aAChD,KAAK,aAAe,GACpB,KAAK,SAAW,KAAK,gBAAkB,UAAY,YAEnD,KAAK,KAAOF,GAAS,QAAQ,IAAI,MAAiB,cAClD,KAAK,KACHC,IACC,QAAQ,IAAI,KACT,OAAO,QAAQ,IAAI,IAAI,EACvB,KAAK,gBACH,KACA,MACR,KAAK,KAAOC,GAAQ,QAAQ,IAAI,MAAQ,GAExC,KAAK,IAAMC,EAAA,EAC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AAS,SACT,KAAM,KAAK,KACX,KAAM,KAAK,IAAA,CACZ,EAED,YAAK,IAAI,IAAIC,EAAK,WAAW,EAEtB,CACL,qBAAsB,MAAMb,GAAQ,CAClC,MAAMC,GACH,MAAMY,EAAK,cAAc,uBAAuB,GACjD,OAGF,IAAIX,EAAW,MAAMS,EAAG,SAAS,eAAgB,OAAO,EACxD,OAAAT,EAAW,MAAMW,EAAK,mBAAmBb,EAAME,CAAQ,EAEhD,CAACD,EAAQC,CAAQ,CAC1B,EACA,aAAcG,IACZQ,EAAK,iBAAiBR,CAAK,EACpBA,EAAM,MACf,CAEJ,CAEA,MAAM,KAAM,CACV,MAAMS,EAAQ,KAAK,gBACf,MAAM,KAAK,gBAAA,EACX,MAAM,KAAK,iBAAA,EAEf,KAAK,IAAI,IAAI,gBAAiB,CAACpB,EAASC,IAAa,CACnD,KAAK,kBAAkBD,EAASC,CAAQ,CAC1C,CAAC,EAED,KAAK,IAAI,IACP,oDACA,CAACD,EAASC,IAAa,CACrB,KAAK,qBAAqBD,EAASC,CAAQ,CAC7C,CAAA,EAGF,KAAK,IAAI,IAAI,IAAK,MAAOD,EAASC,IAAa,CAC7C,MAAM,KAAK,gBAAgBD,EAASC,EAAUmB,CAAK,CACrD,CAAC,EAED,KAAK,OAAO,OAAO,KAAK,KAAM,KAAK,SAAU,IAAM,CACjD,IAAIC,EACF;AAAA,cACe,KAAK,QAAQ,IAAI,KAAK,IAAI;AAAA,eACzB,QAAQ,IAAI,QAAQ;AAAA,EAEjC,KAAK,kBAAiBA,GAAgB,SAAS,KAAK,IAAI;AAAA,GAE7D,QAAQ,IAAIA,CAAY,CAC1B,CAAC,CACH,CACF"}
1
+ {"version":3,"file":"server.es.js","sources":["../../src/server/server.ts"],"sourcesContent":["/**\n * © Ocado Group\n * Created on 13/12/2024 at 12:15:05(+00:00).\n *\n * A server for an app in a live environment.\n * Based off: https://github.com/bluwy/create-vite-extra/blob/master/template-ssr-react-ts/server.js\n */\n\nimport { Cache, type CacheClass } from \"memory-cache\"\nimport { type UUID, randomUUID } from \"node:crypto\"\nimport express, { type Express, type Request, type Response } from \"express\"\nimport fs from \"node:fs/promises\"\nimport http from \"node:http\"\n\ntype Mode = \"development\" | \"staging\" | \"production\"\ntype Options = Partial<{\n mode: Mode\n port: number\n base: string\n}>\n\ntype HealthStatus =\n | \"healthy\"\n | \"startingUp\"\n | \"shuttingDown\"\n | \"unhealthy\"\n | \"unknown\"\ntype HealthCheck = {\n healthStatus: HealthStatus\n additionalInfo: string\n details?: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\ntype HealthCheckResponse = {\n appId: string\n healthStatus: HealthStatus\n lastCheckedTimestamp: string\n additionalInformation: string\n startupTimestamp: string\n appVersion: string\n details: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\n\ntype Render = (path: string) => Promise<{ head?: string; html?: string }>\ntype EntryModule = { render: Render }\ntype RenderAndTemplate = [Render, string]\ntype GetRenderAndTemplate = (path: string) => Promise<RenderAndTemplate>\ntype OnServeError = (error: Error) => string | undefined\n\ntype Setup = {\n getRenderAndTemplate: GetRenderAndTemplate\n onServeError: OnServeError\n}\n\nexport default class Server {\n envIsProduction: boolean\n templateHtml: string\n hostname: string\n mode: Mode\n port: number\n base: string\n app: Express\n server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>\n cache: CacheClass<string, any>\n healthCheckCacheKey: string\n healthCheckCacheTimeout: number\n healthCheckStatusCodes: Record<HealthStatus, number>\n devtoolsWorkspaceUUID: UUID\n\n constructor({ mode, port, base }: Options = {}) {\n this.envIsProduction = process.env.NODE_ENV === \"production\"\n this.templateHtml = \"\"\n this.hostname = this.envIsProduction ? \"0.0.0.0\" : \"127.0.0.1\"\n\n this.mode = mode || (process.env.MODE as Mode) || \"development\"\n this.port =\n port ||\n (process.env.PORT\n ? Number(process.env.PORT)\n : this.envIsProduction\n ? 8080\n : 5173)\n this.base = base || process.env.BASE || \"\"\n\n this.app = express()\n this.server = http.createServer(this.app)\n this.cache = new Cache()\n\n this.healthCheckCacheKey = \"health-check\"\n this.healthCheckCacheTimeout = 30000\n this.healthCheckStatusCodes = {\n // The app is running normally.\n healthy: 200,\n // The app is performing app-specific initialisation which must\n // complete before it will serve normal application requests\n // (perhaps the app is warming a cache or something similar). You\n // only need to use this status if your app will be in a start-up\n // mode for a prolonged period of time.\n startingUp: 503,\n // The app is shutting down. As with startingUp, you only need to\n // use this status if your app takes a prolonged amount of time\n // to shutdown, perhaps because it waits for a long-running\n // process to complete before shutting down.\n shuttingDown: 503,\n // The app is not running normally.\n unhealthy: 503,\n // The app is not able to report its own state.\n unknown: 503,\n }\n\n this.devtoolsWorkspaceUUID = randomUUID()\n }\n\n // @ts-expect-error unused var\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getHealthCheck(request: Request): HealthCheck {\n return {\n healthStatus: \"healthy\",\n additionalInfo: \"All healthy.\",\n }\n }\n\n handleHealthCheck(request: Request, response: Response): void {\n let value: HealthCheckResponse = this.cache.get(\n this.healthCheckCacheKey,\n ) as HealthCheckResponse\n if (value === null) {\n const healthCheck = this.getHealthCheck(request)\n\n if (healthCheck.healthStatus !== \"healthy\") {\n console.warn(`health check: ${JSON.stringify(healthCheck)}`)\n }\n\n value = {\n appId: process.env.APP_ID || \"REPLACE_ME\",\n healthStatus: healthCheck.healthStatus,\n lastCheckedTimestamp: new Date().toISOString(),\n additionalInformation: healthCheck.additionalInfo,\n startupTimestamp: new Date().toISOString(),\n appVersion: process.env.APP_VERSION || \"REPLACE_ME\",\n details: healthCheck.details || [],\n }\n\n this.cache.put(\n this.healthCheckCacheKey,\n value,\n this.healthCheckCacheTimeout,\n )\n }\n\n response.status(this.healthCheckStatusCodes[value.healthStatus]).json(value)\n }\n\n async handleServeHtml(\n request: Request,\n response: Response,\n { getRenderAndTemplate, onServeError }: Setup,\n ): Promise<void> {\n try {\n const path = request.originalUrl.replace(this.base, \"\")\n\n const [render, template] = await getRenderAndTemplate(path)\n\n const rendered = await render(path)\n\n const html = template\n .replace(`<!--app-head-->`, rendered.head ?? \"\")\n .replace(`<!--app-html-->`, rendered.html ?? \"\")\n\n response.status(200).set({ \"Content-Type\": \"text/html\" }).send(html)\n } catch (error) {\n if (error instanceof Error) {\n console.error(error.stack)\n const body = onServeError(error)\n response.status(500).end(body)\n }\n }\n }\n\n // @ts-expect-error unused var\n handleChromeDevTools(request: Request, response: Response) {\n if (this.envIsProduction) {\n response.status(404).json({})\n } else {\n const localWorkspacePath = process.env.LOCAL_WORKSPACE_PATH\n\n let code: number\n let body: object\n if (localWorkspacePath) {\n code = 200\n body = {\n workspace: {\n uuid: this.devtoolsWorkspaceUUID,\n root: localWorkspacePath,\n },\n }\n } else {\n code = 404\n body = { error: \"Local workspace path not configured.\" }\n }\n\n response.status(code).json(body)\n }\n }\n\n async setUpProduction(): Promise<Setup> {\n const compression = (await import(\"compression\")).default\n const sirv = (await import(\"sirv\")).default\n\n this.templateHtml = await fs.readFile(\"./dist/client/index.html\", \"utf-8\")\n\n this.app.use(compression())\n this.app.use(this.base, sirv(\"./dist/client\", { extensions: [] }))\n\n return {\n getRenderAndTemplate: async () => {\n const render = (\n (await import(\n // @ts-expect-error only present after building installing app.\n \"../../../dist/server/entry-server.js\"\n )) as EntryModule\n ).render\n\n // Use cached template.\n const template = this.templateHtml\n\n return [render, template]\n },\n onServeError: () => undefined,\n }\n }\n\n async setUpDevelopment(): Promise<Setup> {\n const { createServer } = await import(\"vite\")\n\n const vite = await createServer({\n configFile: \"/workspace/frontend/vite.config.ts\",\n server: {\n middlewareMode: true,\n hmr: { server: this.server },\n },\n appType: \"custom\",\n base: this.base,\n mode: this.mode,\n })\n\n this.app.use(vite.middlewares)\n\n return {\n getRenderAndTemplate: async path => {\n const render = (\n (await vite.ssrLoadModule(\"/src/entry-server.tsx\")) as EntryModule\n ).render\n\n // Always read fresh template.\n let template = await fs.readFile(\"./index.html\", \"utf-8\")\n template = await vite.transformIndexHtml(path, template)\n\n return [render, template]\n },\n onServeError: error => {\n vite.ssrFixStacktrace(error)\n return error.stack\n },\n }\n }\n\n async run() {\n const setup = this.envIsProduction\n ? await this.setUpProduction()\n : await this.setUpDevelopment()\n\n this.app.get(\"/health-check\", (request, response) => {\n this.handleHealthCheck(request, response)\n })\n\n this.app.get(\n \"/.well-known/appspecific/com.chrome.devtools.json\",\n (request, response) => {\n this.handleChromeDevTools(request, response)\n },\n )\n\n this.app.get(\"*\", async (request, response) => {\n await this.handleServeHtml(request, response, setup)\n })\n\n this.server.listen(this.port, this.hostname, () => {\n let startMessage =\n \"Server started.\\n\" +\n `url: http://${this.hostname}:${this.port}\\n` +\n `environment: ${process.env.NODE_ENV}\\n`\n\n if (!this.envIsProduction) startMessage += `mode: ${this.mode}\\n`\n\n console.log(startMessage)\n })\n }\n}\n"],"names":["Server","mode","port","base","express","http","Cache","randomUUID","request","response","value","healthCheck","getRenderAndTemplate","onServeError","path","render","template","rendered","html","error","body","localWorkspacePath","code","compression","sirv","fs","createServer","vite","setup","startMessage"],"mappings":";;;;;AA6DA,MAAqBA,EAAO;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,EAAE,MAAAC,GAAM,MAAAC,GAAM,MAAAC,EAAA,IAAkB,CAAA,GAAI;AAC9C,SAAK,kBAAkB,QAAQ,IAAI,aAAa,cAChD,KAAK,eAAe,IACpB,KAAK,WAAW,KAAK,kBAAkB,YAAY,aAEnD,KAAK,OAAOF,KAAS,QAAQ,IAAI,QAAiB,eAClD,KAAK,OACHC,MACC,QAAQ,IAAI,OACT,OAAO,QAAQ,IAAI,IAAI,IACvB,KAAK,kBACH,OACA,OACR,KAAK,OAAOC,KAAQ,QAAQ,IAAI,QAAQ,IAExC,KAAK,MAAMC,EAAA,GACX,KAAK,SAASC,EAAK,aAAa,KAAK,GAAG,GACxC,KAAK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AK,OAAOD,GAASC,MAAa;AAC7C,YAAM,KAAK,gBAAgBD,GAASC,GAAUmB,CAAK;AAAA,IACrD,CAAC,GAED,KAAK,OAAO,OAAO,KAAK,MAAM,KAAK,UAAU,MAAM;AACjD,UAAIC,IACF;AAAA,cACe,KAAK,QAAQ,IAAI,KAAK,IAAI;AAAA,eACzB,QAAQ,IAAI,QAAQ;AAAA;AAEtC,MAAK,KAAK,oBAAiBA,KAAgB,SAAS,KAAK,IAAI;AAAA,IAE7D,QAAQ,IAAIA,CAAY;AAAA,IAC1B,CAAC;AAAA,EACH;AACF;"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "codeforlife",
3
3
  "description": "Common frontend code",
4
4
  "private": false,
5
- "version": "2.11.0",
5
+ "version": "2.11.2",
6
6
  "type": "module",
7
7
  "types": "dist/index.d.ts",
8
8
  "module": "dist/index.es.js",
@@ -64,9 +64,14 @@
64
64
  "require": "./dist/middlewares/index.cjs.js"
65
65
  },
66
66
  "./server": {
67
- "types": "./dist/server/index.d.ts",
68
- "import": "./dist/server/index.es.js",
69
- "require": "./dist/server/index.cjs.js"
67
+ "types": "./dist/server/server.d.ts",
68
+ "import": "./dist/server/server.es.js",
69
+ "require": "./dist/server/server.cjs.js"
70
+ },
71
+ "./server/App": {
72
+ "types": "./dist/server/App.d.ts",
73
+ "import": "./dist/server/App.es.js",
74
+ "require": "./dist/server/App.cjs.js"
70
75
  },
71
76
  "./server/entry": {
72
77
  "types": "./dist/server/entry.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"file":"App-3VkR-ZEZ.js","sources":["../src/server/App.tsx"],"sourcesContent":["import { CssBaseline, ThemeProvider } from \"@mui/material\"\nimport {\n type EmotionCache,\n CacheProvider as EmotionCacheProvider,\n} from \"@emotion/react\"\nimport { type JSX, type ReactNode } from \"react\"\nimport {\n Provider as StoreProvider,\n type ProviderProps as StoreProviderProps,\n} from \"react-redux\"\nimport { type Action } from \"redux\"\nimport { type ThemeProviderProps } from \"@mui/material\"\n\nimport \"./App.css\"\n// import { InactiveDialog, ScreenTimeDialog } from \"../features\"\n// import { useCountdown, useEventListener } from \"../hooks\"\n// import \"../scripts\"\n// import {\n// configureFreshworksWidget,\n// toggleOneTrustInfoDisplay,\n// } from \"../utils/window\"\n\nexport interface AppProps<A extends Action = Action, S = unknown> {\n children: ReactNode\n emotionCache: EmotionCache\n theme: ThemeProviderProps[\"theme\"]\n store: StoreProviderProps<A, S>[\"store\"]\n maxIdleSeconds?: number\n maxTotalSeconds?: number\n}\n\nconst App = <A extends Action = Action, S = unknown>({\n children,\n emotionCache,\n theme,\n store,\n // @ts-expect-error TODO\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n maxIdleSeconds = 60 * 60,\n // @ts-expect-error TODO\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n maxTotalSeconds = 60 * 60,\n}: AppProps<A, S>): JSX.Element => {\n // TODO: cannot use document during SSR\n // const root = document.getElementById(\"root\") as HTMLElement\n\n // const [idleSeconds, setIdleSeconds] = useCountdown(maxIdleSeconds)\n // const [totalSeconds, setTotalSeconds] = useCountdown(maxTotalSeconds)\n // const resetIdleSeconds = useCallback(() => {\n // setIdleSeconds(maxIdleSeconds)\n // }, [setIdleSeconds, maxIdleSeconds])\n\n // const isIdle = idleSeconds === 0\n // const tooMuchScreenTime = totalSeconds === 0\n\n // useEventListener(root, \"mousemove\", resetIdleSeconds)\n // useEventListener(root, \"keypress\", resetIdleSeconds)\n\n // React.useEffect(() => {\n // configureFreshworksWidget(\"hide\")\n // }, [])\n\n // if (import.meta.env.PROD) {\n // toggleOneTrustInfoDisplay()\n // }\n\n return (\n // https://mui.com/material-ui/guides/server-rendering/\n <EmotionCacheProvider value={emotionCache}>\n <ThemeProvider theme={theme}>\n <CssBaseline />\n <StoreProvider store={store}>\n {/* <InactiveDialog open={isIdle} onClose={resetIdleSeconds} />\n <ScreenTimeDialog\n open={!isIdle && tooMuchScreenTime}\n onClose={() => {\n setTotalSeconds(maxTotalSeconds)\n }}\n /> */}\n {children}\n </StoreProvider>\n </ThemeProvider>\n </EmotionCacheProvider>\n )\n}\n\nexport default App\n\n// TODO: figure out what to do with this\n// function useOneTrustScripts(): void {\n// const oneTrustEventTypes = [\n// useExternalScript({\n// props: {\n// src: \"https://cdn-ukwest.onetrust.com/consent/5da42396-cb12-4493-8d04-5179033cfbad/OtAutoBlock.js\",\n// type: \"text/javascript\",\n// },\n// eventTypes: [\"load\", \"error\"],\n// }),\n// useExternalScript({\n// props: {\n// src: \"https://cdn-ukwest.onetrust.com/scripttemplates/otSDKStub.js\",\n// type: \"text/javascript\",\n// charset: \"UTF-8\",\n// },\n// attrs: {\n// \"data-domain-script\": \"5da42396-cb12-4493-8d04-5179033cfbad\",\n// },\n// eventTypes: [\"load\", \"error\"],\n// }),\n// useExternalScript({\n// props: {\n// src: \"https://cdn-ukwest.onetrust.com/scripttemplates/202302.1.0/otBannerSdk.js\",\n// async: true,\n// type: \"text/javascript\",\n// },\n// eventTypes: [\"load\", \"error\"],\n// }),\n// ]\n// if (oneTrustEventTypes.some(t => t === \"error\")) {\n// alert(\"OneTrust failed to load!\")\n// }\n// }\n"],"names":["App","children","emotionCache","theme","store","maxIdleSeconds","maxTotalSeconds","EmotionCacheProvider","jsxs","ThemeProvider","jsx","CssBaseline","StoreProvider"],"mappings":";;;;;AA+BA,MAAMA,IAAM,CAAyC;AAAA,EACnD,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,OAAAC;AAAA,EACA,OAAAC;AAAA;AAAA;AAAA,EAGA,gBAAAC,IAAiB;AAAA;AAAA;AAAA,EAGjB,iBAAAC,IAAkB;AACpB;AAAA;AAAA,wBA0BKC,GAAA,EAAqB,OAAOL,GAC3B,UAAAM,gBAAAA,EAAAA,KAACC,KAAc,OAAAN,GACb,UAAA;AAAA,IAAAO,gBAAAA,EAAAA,IAACC,GAAA,EAAY;AAAA,IACbD,gBAAAA,EAAAA,IAACE,GAAA,EAAc,OAAAR,GAQZ,UAAAH,EAAA,CACH;AAAA,EAAA,EAAA,CACF,EAAA,CACF;AAAA;"}
@@ -1,2 +0,0 @@
1
- "use strict";const e=require("./jsx-runtime-B2pbW5Fp.cjs"),r=require("@mui/material"),x=require("@emotion/react");require("react");const o=require("react-redux"),u=({children:s,emotionCache:t,theme:i,store:n,maxIdleSeconds:c=3600,maxTotalSeconds:a=3600})=>e.jsxRuntimeExports.jsx(x.CacheProvider,{value:t,children:e.jsxRuntimeExports.jsxs(r.ThemeProvider,{theme:i,children:[e.jsxRuntimeExports.jsx(r.CssBaseline,{}),e.jsxRuntimeExports.jsx(o.Provider,{store:n,children:s})]})});exports.App=u;
2
- //# sourceMappingURL=App-UfeajXtp.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"App-UfeajXtp.cjs","sources":["../src/server/App.tsx"],"sourcesContent":["import { CssBaseline, ThemeProvider } from \"@mui/material\"\nimport {\n type EmotionCache,\n CacheProvider as EmotionCacheProvider,\n} from \"@emotion/react\"\nimport { type JSX, type ReactNode } from \"react\"\nimport {\n Provider as StoreProvider,\n type ProviderProps as StoreProviderProps,\n} from \"react-redux\"\nimport { type Action } from \"redux\"\nimport { type ThemeProviderProps } from \"@mui/material\"\n\nimport \"./App.css\"\n// import { InactiveDialog, ScreenTimeDialog } from \"../features\"\n// import { useCountdown, useEventListener } from \"../hooks\"\n// import \"../scripts\"\n// import {\n// configureFreshworksWidget,\n// toggleOneTrustInfoDisplay,\n// } from \"../utils/window\"\n\nexport interface AppProps<A extends Action = Action, S = unknown> {\n children: ReactNode\n emotionCache: EmotionCache\n theme: ThemeProviderProps[\"theme\"]\n store: StoreProviderProps<A, S>[\"store\"]\n maxIdleSeconds?: number\n maxTotalSeconds?: number\n}\n\nconst App = <A extends Action = Action, S = unknown>({\n children,\n emotionCache,\n theme,\n store,\n // @ts-expect-error TODO\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n maxIdleSeconds = 60 * 60,\n // @ts-expect-error TODO\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n maxTotalSeconds = 60 * 60,\n}: AppProps<A, S>): JSX.Element => {\n // TODO: cannot use document during SSR\n // const root = document.getElementById(\"root\") as HTMLElement\n\n // const [idleSeconds, setIdleSeconds] = useCountdown(maxIdleSeconds)\n // const [totalSeconds, setTotalSeconds] = useCountdown(maxTotalSeconds)\n // const resetIdleSeconds = useCallback(() => {\n // setIdleSeconds(maxIdleSeconds)\n // }, [setIdleSeconds, maxIdleSeconds])\n\n // const isIdle = idleSeconds === 0\n // const tooMuchScreenTime = totalSeconds === 0\n\n // useEventListener(root, \"mousemove\", resetIdleSeconds)\n // useEventListener(root, \"keypress\", resetIdleSeconds)\n\n // React.useEffect(() => {\n // configureFreshworksWidget(\"hide\")\n // }, [])\n\n // if (import.meta.env.PROD) {\n // toggleOneTrustInfoDisplay()\n // }\n\n return (\n // https://mui.com/material-ui/guides/server-rendering/\n <EmotionCacheProvider value={emotionCache}>\n <ThemeProvider theme={theme}>\n <CssBaseline />\n <StoreProvider store={store}>\n {/* <InactiveDialog open={isIdle} onClose={resetIdleSeconds} />\n <ScreenTimeDialog\n open={!isIdle && tooMuchScreenTime}\n onClose={() => {\n setTotalSeconds(maxTotalSeconds)\n }}\n /> */}\n {children}\n </StoreProvider>\n </ThemeProvider>\n </EmotionCacheProvider>\n )\n}\n\nexport default App\n\n// TODO: figure out what to do with this\n// function useOneTrustScripts(): void {\n// const oneTrustEventTypes = [\n// useExternalScript({\n// props: {\n// src: \"https://cdn-ukwest.onetrust.com/consent/5da42396-cb12-4493-8d04-5179033cfbad/OtAutoBlock.js\",\n// type: \"text/javascript\",\n// },\n// eventTypes: [\"load\", \"error\"],\n// }),\n// useExternalScript({\n// props: {\n// src: \"https://cdn-ukwest.onetrust.com/scripttemplates/otSDKStub.js\",\n// type: \"text/javascript\",\n// charset: \"UTF-8\",\n// },\n// attrs: {\n// \"data-domain-script\": \"5da42396-cb12-4493-8d04-5179033cfbad\",\n// },\n// eventTypes: [\"load\", \"error\"],\n// }),\n// useExternalScript({\n// props: {\n// src: \"https://cdn-ukwest.onetrust.com/scripttemplates/202302.1.0/otBannerSdk.js\",\n// async: true,\n// type: \"text/javascript\",\n// },\n// eventTypes: [\"load\", \"error\"],\n// }),\n// ]\n// if (oneTrustEventTypes.some(t => t === \"error\")) {\n// alert(\"OneTrust failed to load!\")\n// }\n// }\n"],"names":["App","children","emotionCache","theme","store","maxIdleSeconds","maxTotalSeconds","EmotionCacheProvider","jsxs","ThemeProvider","jsx","CssBaseline","StoreProvider"],"mappings":"kKA+BMA,EAAM,CAAyC,CACnD,SAAAC,EACA,aAAAC,EACA,MAAAC,EACA,MAAAC,EAGA,eAAAC,EAAiB,KAGjB,gBAAAC,EAAkB,IACpB,4BA0BKC,EAAAA,cAAA,CAAqB,MAAOL,EAC3B,SAAAM,EAAAA,kBAAAA,KAACC,EAAAA,eAAc,MAAAN,EACb,SAAA,CAAAO,EAAAA,kBAAAA,IAACC,EAAAA,YAAA,EAAY,EACbD,EAAAA,kBAAAA,IAACE,EAAAA,SAAA,CAAc,MAAAR,EAQZ,SAAAH,CAAA,CACH,CAAA,CAAA,CACF,CAAA,CACF"}
@@ -1,6 +0,0 @@
1
- "use strict";var u=Object.create;var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var S=(h,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let a of v(s))!k.call(h,a)&&a!==e&&c(h,a,{get:()=>s[a],enumerable:!(t=m(s,a))||t.enumerable});return h};var o=(h,s,e)=>(e=h!=null?u(C(h)):{},S(s||!h||!h.__esModule?c(e,"default",{value:h,enumerable:!0}):e,h));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("memory-cache"),y=require("node:crypto"),f=require("express"),l=require("node:fs/promises"),g=require("node:http"),P=require("../App-UfeajXtp.cjs");class I{envIsProduction;templateHtml;hostname;mode;port;base;app;server;cache;healthCheckCacheKey;healthCheckCacheTimeout;healthCheckStatusCodes;devtoolsWorkspaceUUID;constructor({mode:s,port:e,base:t}={}){this.envIsProduction=process.env.NODE_ENV==="production",this.templateHtml="",this.hostname=this.envIsProduction?"0.0.0.0":"127.0.0.1",this.mode=s||process.env.MODE||"development",this.port=e||(process.env.PORT?Number(process.env.PORT):this.envIsProduction?8080:5173),this.base=t||process.env.BASE||"",this.app=f(),this.server=g.createServer(this.app),this.cache=new w.Cache,this.healthCheckCacheKey="health-check",this.healthCheckCacheTimeout=3e4,this.healthCheckStatusCodes={healthy:200,startingUp:503,shuttingDown:503,unhealthy:503,unknown:503},this.devtoolsWorkspaceUUID=y.randomUUID()}getHealthCheck(s){return{healthStatus:"healthy",additionalInfo:"All healthy."}}handleHealthCheck(s,e){let t=this.cache.get(this.healthCheckCacheKey);if(t===null){const a=this.getHealthCheck(s);a.healthStatus!=="healthy"&&console.warn(`health check: ${JSON.stringify(a)}`),t={appId:process.env.APP_ID||"REPLACE_ME",healthStatus:a.healthStatus,lastCheckedTimestamp:new Date().toISOString(),additionalInformation:a.additionalInfo,startupTimestamp:new Date().toISOString(),appVersion:process.env.APP_VERSION||"REPLACE_ME",details:a.details||[]},this.cache.put(this.healthCheckCacheKey,t,this.healthCheckCacheTimeout)}e.status(this.healthCheckStatusCodes[t.healthStatus]).json(t)}async handleServeHtml(s,e,{getRenderAndTemplate:t,onServeError:a}){try{const r=s.originalUrl.replace(this.base,""),[n,p]=await t(r),i=await n(r),d=p.replace("<!--app-head-->",i.head??"").replace("<!--app-html-->",i.html??"");e.status(200).set({"Content-Type":"text/html"}).send(d)}catch(r){if(r instanceof Error){console.error(r.stack);const n=a(r);e.status(500).end(n)}}}handleChromeDevTools(s,e){if(this.envIsProduction)e.status(404).json({});else{const t=process.env.LOCAL_WORKSPACE_PATH;let a,r;t?(a=200,r={workspace:{uuid:this.devtoolsWorkspaceUUID,root:t}}):(a=404,r={error:"Local workspace path not configured."}),e.status(a).json(r)}}async setUpProduction(){const s=(await import("compression")).default,e=(await import("sirv")).default;return this.templateHtml=await l.readFile("./dist/client/index.html","utf-8"),this.app.use(s()),this.app.use(this.base,e("./dist/client",{extensions:[]})),{getRenderAndTemplate:async()=>{const t=(await import("../../../dist/server/entry-server.js")).render,a=this.templateHtml;return[t,a]},onServeError:()=>{}}}async setUpDevelopment(){const{createServer:s}=await import("vite"),e=await s({configFile:"/workspace/frontend/vite.config.ts",server:{middlewareMode:!0,hmr:{server:this.server}},appType:"custom",base:this.base,mode:this.mode});return this.app.use(e.middlewares),{getRenderAndTemplate:async t=>{const a=(await e.ssrLoadModule("/src/entry-server.tsx")).render;let r=await l.readFile("./index.html","utf-8");return r=await e.transformIndexHtml(t,r),[a,r]},onServeError:t=>(e.ssrFixStacktrace(t),t.stack)}}async run(){const s=this.envIsProduction?await this.setUpProduction():await this.setUpDevelopment();this.app.get("/health-check",(e,t)=>{this.handleHealthCheck(e,t)}),this.app.get("/.well-known/appspecific/com.chrome.devtools.json",(e,t)=>{this.handleChromeDevTools(e,t)}),this.app.get("*",async(e,t)=>{await this.handleServeHtml(e,t,s)}),this.server.listen(this.port,this.hostname,()=>{let e=`Server started.
2
- url: http://${this.hostname}:${this.port}
3
- environment: ${process.env.NODE_ENV}
4
- `;this.envIsProduction||(e+=`mode: ${this.mode}
5
- `),console.log(e)})}}exports.App=P.App;exports.Server=I;
6
- //# sourceMappingURL=index.cjs.js.map
@@ -1,6 +0,0 @@
1
- /**
2
- * © Ocado Group
3
- * Created on 20/10/2025 at 15:27:12(+01:00).
4
- */
5
- export { default as Server } from './server';
6
- export { default as App, type AppProps } from './App';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.es.js","sources":["../../src/server/server.ts"],"sourcesContent":["/**\n * © Ocado Group\n * Created on 13/12/2024 at 12:15:05(+00:00).\n *\n * A server for an app in a live environment.\n * Based off: https://github.com/bluwy/create-vite-extra/blob/master/template-ssr-react-ts/server.js\n */\n\nimport { Cache, type CacheClass } from \"memory-cache\"\nimport { type UUID, randomUUID } from \"node:crypto\"\nimport express, { type Express, type Request, type Response } from \"express\"\nimport fs from \"node:fs/promises\"\nimport http from \"node:http\"\n\ntype Mode = \"development\" | \"staging\" | \"production\"\ntype Options = Partial<{\n mode: Mode\n port: number\n base: string\n}>\n\ntype HealthStatus =\n | \"healthy\"\n | \"startingUp\"\n | \"shuttingDown\"\n | \"unhealthy\"\n | \"unknown\"\ntype HealthCheck = {\n healthStatus: HealthStatus\n additionalInfo: string\n details?: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\ntype HealthCheckResponse = {\n appId: string\n healthStatus: HealthStatus\n lastCheckedTimestamp: string\n additionalInformation: string\n startupTimestamp: string\n appVersion: string\n details: Array<{\n name: string\n description: string\n health: HealthStatus\n }>\n}\n\ntype Render = (path: string) => Promise<{ head?: string; html?: string }>\ntype EntryModule = { render: Render }\ntype RenderAndTemplate = [Render, string]\ntype GetRenderAndTemplate = (path: string) => Promise<RenderAndTemplate>\ntype OnServeError = (error: Error) => string | undefined\n\ntype Setup = {\n getRenderAndTemplate: GetRenderAndTemplate\n onServeError: OnServeError\n}\n\nexport default class Server {\n envIsProduction: boolean\n templateHtml: string\n hostname: string\n mode: Mode\n port: number\n base: string\n app: Express\n server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>\n cache: CacheClass<string, any>\n healthCheckCacheKey: string\n healthCheckCacheTimeout: number\n healthCheckStatusCodes: Record<HealthStatus, number>\n devtoolsWorkspaceUUID: UUID\n\n constructor({ mode, port, base }: Options = {}) {\n this.envIsProduction = process.env.NODE_ENV === \"production\"\n this.templateHtml = \"\"\n this.hostname = this.envIsProduction ? \"0.0.0.0\" : \"127.0.0.1\"\n\n this.mode = mode || (process.env.MODE as Mode) || \"development\"\n this.port =\n port ||\n (process.env.PORT\n ? Number(process.env.PORT)\n : this.envIsProduction\n ? 8080\n : 5173)\n this.base = base || process.env.BASE || \"\"\n\n this.app = express()\n this.server = http.createServer(this.app)\n this.cache = new Cache()\n\n this.healthCheckCacheKey = \"health-check\"\n this.healthCheckCacheTimeout = 30000\n this.healthCheckStatusCodes = {\n // The app is running normally.\n healthy: 200,\n // The app is performing app-specific initialisation which must\n // complete before it will serve normal application requests\n // (perhaps the app is warming a cache or something similar). You\n // only need to use this status if your app will be in a start-up\n // mode for a prolonged period of time.\n startingUp: 503,\n // The app is shutting down. As with startingUp, you only need to\n // use this status if your app takes a prolonged amount of time\n // to shutdown, perhaps because it waits for a long-running\n // process to complete before shutting down.\n shuttingDown: 503,\n // The app is not running normally.\n unhealthy: 503,\n // The app is not able to report its own state.\n unknown: 503,\n }\n\n this.devtoolsWorkspaceUUID = randomUUID()\n }\n\n // @ts-expect-error unused var\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getHealthCheck(request: Request): HealthCheck {\n return {\n healthStatus: \"healthy\",\n additionalInfo: \"All healthy.\",\n }\n }\n\n handleHealthCheck(request: Request, response: Response): void {\n let value: HealthCheckResponse = this.cache.get(\n this.healthCheckCacheKey,\n ) as HealthCheckResponse\n if (value === null) {\n const healthCheck = this.getHealthCheck(request)\n\n if (healthCheck.healthStatus !== \"healthy\") {\n console.warn(`health check: ${JSON.stringify(healthCheck)}`)\n }\n\n value = {\n appId: process.env.APP_ID || \"REPLACE_ME\",\n healthStatus: healthCheck.healthStatus,\n lastCheckedTimestamp: new Date().toISOString(),\n additionalInformation: healthCheck.additionalInfo,\n startupTimestamp: new Date().toISOString(),\n appVersion: process.env.APP_VERSION || \"REPLACE_ME\",\n details: healthCheck.details || [],\n }\n\n this.cache.put(\n this.healthCheckCacheKey,\n value,\n this.healthCheckCacheTimeout,\n )\n }\n\n response.status(this.healthCheckStatusCodes[value.healthStatus]).json(value)\n }\n\n async handleServeHtml(\n request: Request,\n response: Response,\n { getRenderAndTemplate, onServeError }: Setup,\n ): Promise<void> {\n try {\n const path = request.originalUrl.replace(this.base, \"\")\n\n const [render, template] = await getRenderAndTemplate(path)\n\n const rendered = await render(path)\n\n const html = template\n .replace(`<!--app-head-->`, rendered.head ?? \"\")\n .replace(`<!--app-html-->`, rendered.html ?? \"\")\n\n response.status(200).set({ \"Content-Type\": \"text/html\" }).send(html)\n } catch (error) {\n if (error instanceof Error) {\n console.error(error.stack)\n const body = onServeError(error)\n response.status(500).end(body)\n }\n }\n }\n\n // @ts-expect-error unused var\n handleChromeDevTools(request: Request, response: Response) {\n if (this.envIsProduction) {\n response.status(404).json({})\n } else {\n const localWorkspacePath = process.env.LOCAL_WORKSPACE_PATH\n\n let code: number\n let body: object\n if (localWorkspacePath) {\n code = 200\n body = {\n workspace: {\n uuid: this.devtoolsWorkspaceUUID,\n root: localWorkspacePath,\n },\n }\n } else {\n code = 404\n body = { error: \"Local workspace path not configured.\" }\n }\n\n response.status(code).json(body)\n }\n }\n\n async setUpProduction(): Promise<Setup> {\n const compression = (await import(\"compression\")).default\n const sirv = (await import(\"sirv\")).default\n\n this.templateHtml = await fs.readFile(\"./dist/client/index.html\", \"utf-8\")\n\n this.app.use(compression())\n this.app.use(this.base, sirv(\"./dist/client\", { extensions: [] }))\n\n return {\n getRenderAndTemplate: async () => {\n const render = (\n (await import(\n // @ts-expect-error only present after building installing app.\n \"../../../dist/server/entry-server.js\"\n )) as EntryModule\n ).render\n\n // Use cached template.\n const template = this.templateHtml\n\n return [render, template]\n },\n onServeError: () => undefined,\n }\n }\n\n async setUpDevelopment(): Promise<Setup> {\n const { createServer } = await import(\"vite\")\n\n const vite = await createServer({\n configFile: \"/workspace/frontend/vite.config.ts\",\n server: {\n middlewareMode: true,\n hmr: { server: this.server },\n },\n appType: \"custom\",\n base: this.base,\n mode: this.mode,\n })\n\n this.app.use(vite.middlewares)\n\n return {\n getRenderAndTemplate: async path => {\n const render = (\n (await vite.ssrLoadModule(\"/src/entry-server.tsx\")) as EntryModule\n ).render\n\n // Always read fresh template.\n let template = await fs.readFile(\"./index.html\", \"utf-8\")\n template = await vite.transformIndexHtml(path, template)\n\n return [render, template]\n },\n onServeError: error => {\n vite.ssrFixStacktrace(error)\n return error.stack\n },\n }\n }\n\n async run() {\n const setup = this.envIsProduction\n ? await this.setUpProduction()\n : await this.setUpDevelopment()\n\n this.app.get(\"/health-check\", (request, response) => {\n this.handleHealthCheck(request, response)\n })\n\n this.app.get(\n \"/.well-known/appspecific/com.chrome.devtools.json\",\n (request, response) => {\n this.handleChromeDevTools(request, response)\n },\n )\n\n this.app.get(\"*\", async (request, response) => {\n await this.handleServeHtml(request, response, setup)\n })\n\n this.server.listen(this.port, this.hostname, () => {\n let startMessage =\n \"Server started.\\n\" +\n `url: http://${this.hostname}:${this.port}\\n` +\n `environment: ${process.env.NODE_ENV}\\n`\n\n if (!this.envIsProduction) startMessage += `mode: ${this.mode}\\n`\n\n console.log(startMessage)\n })\n }\n}\n"],"names":["Server","mode","port","base","express","http","Cache","randomUUID","request","response","value","healthCheck","getRenderAndTemplate","onServeError","path","render","template","rendered","html","error","body","localWorkspacePath","code","compression","sirv","fs","createServer","vite","setup","startMessage"],"mappings":";;;;;;AA6DA,MAAqBA,EAAO;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,EAAE,MAAAC,GAAM,MAAAC,GAAM,MAAAC,EAAA,IAAkB,CAAA,GAAI;AAC9C,SAAK,kBAAkB,QAAQ,IAAI,aAAa,cAChD,KAAK,eAAe,IACpB,KAAK,WAAW,KAAK,kBAAkB,YAAY,aAEnD,KAAK,OAAOF,KAAS,QAAQ,IAAI,QAAiB,eAClD,KAAK,OACHC,MACC,QAAQ,IAAI,OACT,OAAO,QAAQ,IAAI,IAAI,IACvB,KAAK,kBACH,OACA,OACR,KAAK,OAAOC,KAAQ,QAAQ,IAAI,QAAQ,IAExC,KAAK,MAAMC,EAAA,GACX,KAAK,SAASC,EAAK,aAAa,KAAK,GAAG,GACxC,KAAK,QAAQ,IAAIC,EAAA,GAE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