@ms-cloudpack/app-server 0.10.4 → 0.10.6

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 +1 @@
1
- {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAKL,KAAK,WAAW,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,kCAAkC,CAAC;AAUnF,UAAU,mBAAmB;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,WAAW,CAAC;CACzB;AAED,KAAK,mBAAmB,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,oBAAoB,GAAG,eAAe,GAAG,SAAS,CAAC,CAAC;AAE1G;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,QAoDtF"}
1
+ {"version":3,"file":"createRoutes.d.ts","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAML,KAAK,WAAW,EAEjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,kCAAkC,CAAC;AAUnF,UAAU,mBAAmB;IAC3B,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,WAAW,CAAC;CACzB;AAED,KAAK,mBAAmB,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,oBAAoB,GAAG,eAAe,GAAG,SAAS,CAAC,CAAC;AAE1G;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,mBAAmB,QAyCtF"}
@@ -5,8 +5,7 @@ import { slash } from '@ms-cloudpack/path-string-parsing';
5
5
  import path from 'path';
6
6
  import { getInlineScripts } from './inlineScripts/getInlineScripts.js';
7
7
  import { renderRoute } from './renderRoute/renderRoute.js';
8
- import { setHeaders } from './setHeaders.js';
9
- import { createBootstrapRouteHandler } from './createBootstrapRouteHandler.js';
8
+ import { renderBootstrapRoute } from './renderBootstrapRoute.js';
10
9
  /**
11
10
  * Creates the routes for the express app based on the config.
12
11
  */
@@ -39,13 +38,7 @@ export function createRoutes(options, context) {
39
38
  res.redirect(route.redirectTo);
40
39
  });
41
40
  }
42
- else if (isBootstrapRoute(route)) {
43
- app.get(route.match, createBootstrapRouteHandler({
44
- exportEntry: route.exportEntry,
45
- definitionName: options.definition.name,
46
- }, context));
47
- }
48
- else if (isRenderedRoute(route)) {
41
+ else if (isRenderedRoute(route) || isBootstrapRoute(route)) {
49
42
  app.get(route.match, (req, res) => {
50
43
  handleRequest({ ...otherOptions, route, req, res }, context).catch((err) => {
51
44
  console.error(err?.stack || err);
@@ -69,25 +62,37 @@ async function handleRequest(options, context) {
69
62
  // Build the import map if it hasn't been built yet for this session version.
70
63
  // (TS can't infer that urls.bundleServer is set on session from a check above.)
71
64
  const importMap = (session.importMap ??= await createImportMap({ ...context, ...session, urls: { bundleServer } }));
72
- // Parse the request path, extension, grab the overlay script path.
73
- const requestPath = slash(req.path.substring(1));
74
- const requestExt = path.extname(requestPath);
75
65
  const overlayScript = importMap.imports['@ms-cloudpack/overlay'];
76
66
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
77
67
  const entryScript = route.exportEntry && importMap.imports[slash(path.join(definition.name, route.exportEntry))];
78
- // Set the appropriate Cloudpack headers in the response.
79
- setHeaders({ res });
80
68
  const inlineScripts = await getInlineScripts();
81
- const { content, statusCode, contentType } = await renderRoute({
82
- ...options,
83
- session,
84
- baseUrl: url,
85
- importMap,
86
- overlayScript,
87
- entryScript,
88
- inlineScripts,
89
- });
90
- res.type(contentType).status(statusCode).send(content).end();
91
- console.debug(`App server: Request: ${requestPath}, ext: ${requestExt}`);
69
+ // Set the appropriate Cloudpack headers in the response.
70
+ res.header('Cache-Control', 'no-cache');
71
+ res.header('Access-Control-Allow-Origin', '*');
72
+ let rendered;
73
+ if (isBootstrapRoute(route)) {
74
+ // Render the bootstrap script
75
+ rendered = await renderBootstrapRoute({
76
+ session,
77
+ importMap,
78
+ overlayScript,
79
+ inlineScripts,
80
+ entryScript,
81
+ });
82
+ }
83
+ else {
84
+ // HTML or custom script rendering
85
+ rendered = await renderRoute({
86
+ ...options,
87
+ session,
88
+ baseUrl: url,
89
+ importMap,
90
+ overlayScript,
91
+ entryScript,
92
+ inlineScripts,
93
+ });
94
+ }
95
+ res.type(rendered.contentType).status(rendered.statusCode).send(rendered.content).end();
96
+ console.debug(`App server: Request: ${req.path}`);
92
97
  }
93
98
  //# sourceMappingURL=createRoutes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,GAGd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAsB,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAU/E;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B,EAAE,OAA4B;I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irectRoute,\n isRenderedRoute,\n isStaticRoute,\n type PackageJson,\n type RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport type { Express, Request, Response } from '@ms-cloudpack/create-express-app';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { createImportMap } from '@ms-cloudpack/import-map';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { renderRoute, type RouteInternal } from './renderRoute/renderRoute.js';\nimport { setHeaders } from './setHeaders.js';\nimport { createBootstrapRouteHandler } from './createBootstrapRouteHandler.js';\n\ninterface CreateRoutesOptions {\n app: Express;\n url: string;\n definition: PackageJson;\n}\n\ntype CreateRoutesContext = Pick<Context, 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'>;\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: CreateRoutesContext) {\n const { app, ...otherOptions } = options;\n const { session } = context;\n const { config } = session;\n const { appPath } = config;\n const routes = [...(session.config.routes || [])];\n\n if (!options.definition.name) {\n throw new Error('Name field is required in the package.json file.');\n }\n\n // Only as a basic fallback if no routes are specified, add a default catch-all route.\n // Adding this automatically has the risk of hiding errors, like if an unexpected path\n // being requested, or a JS file somehow being loaded from the app server unexpectedly.\n if (!routes.length) {\n const fallbackRoute: RouteInternal = {\n match: '*',\n exportEntry: '.',\n isDefaultFallback: true, // this internal property is read by renderRoute\n };\n routes.push(fallbackRoute);\n }\n\n for (const route of routes) {\n if (isStaticRoute(route)) {\n app.use(route.match, express.static(path.resolve(appPath, route.staticPath)));\n } else if (isRedirectRoute(route)) {\n app.get(route.match, (req, res) => {\n res.redirect(route.redirectTo);\n });\n } else if (isBootstrapRoute(route)) {\n app.get(\n route.match,\n createBootstrapRouteHandler(\n {\n exportEntry: route.exportEntry,\n definitionName: options.definition.name,\n },\n context,\n ),\n );\n } else if (isRenderedRoute(route)) {\n app.get(route.match, (req, res) => {\n handleRequest({ ...otherOptions, route, req, res }, context).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n}\n\nasync function handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute;\n },\n context: CreateRoutesContext,\n) {\n const { req, res, definition, route, url } = options;\n const { session } = context;\n const { bundleServer } = session.urls;\n if (!bundleServer) {\n // Sanity check...\n throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');\n }\n\n // Build the import map if it hasn't been built yet for this session version.\n // (TS can't infer that urls.bundleServer is set on session from a check above.)\n const importMap = (session.importMap ??= await createImportMap({ ...context, ...session, urls: { bundleServer } }));\n\n // Parse the request path, extension, grab the overlay script path.\n const requestPath = slash(req.path.substring(1));\n const requestExt = path.extname(requestPath);\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const entryScript = route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\n\n // Set the appropriate Cloudpack headers in the response.\n setHeaders({ res });\n\n const inlineScripts = await getInlineScripts();\n const { content, statusCode, contentType } = await renderRoute({\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n inlineScripts,\n });\n\n res.type(contentType).status(statusCode).send(content).end();\n\n console.debug(`App server: Request: ${requestPath}, ext: ${requestExt}`);\n}\n"]}
1
+ {"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,GAId,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CA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Q,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IAExF,OAAO,CAAC,KAAK,CAAC,wBAAwB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { Context } from '@ms-cloudpack/api-server';\nimport {\n isBootstrapRoute,\n isRedirectRoute,\n isRenderedRoute,\n isStaticRoute,\n type BootstrapRoute,\n type PackageJson,\n type RenderedRoute,\n} from '@ms-cloudpack/common-types';\nimport type { Express, Request, Response } from '@ms-cloudpack/create-express-app';\nimport { express } from '@ms-cloudpack/create-express-app';\nimport { createImportMap } from '@ms-cloudpack/import-map';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport { getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { renderRoute, type RouteInternal } from './renderRoute/renderRoute.js';\nimport { renderBootstrapRoute } from './renderBootstrapRoute.js';\nimport type { CompleteRenderRouteResult } from './types/RenderRouteResult.js';\n\ninterface CreateRoutesOptions {\n app: Express;\n url: string;\n definition: PackageJson;\n}\n\ntype CreateRoutesContext = Pick<Context, 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'>;\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: CreateRoutesContext) {\n const { app, ...otherOptions } = options;\n const { session } = context;\n const { config } = session;\n const { appPath } = config;\n const routes = [...(session.config.routes || [])];\n\n if (!options.definition.name) {\n throw new Error('Name field is required in the package.json file.');\n }\n\n // Only as a basic fallback if no routes are specified, add a default catch-all route.\n // Adding this automatically has the risk of hiding errors, like if an unexpected path\n // being requested, or a JS file somehow being loaded from the app server unexpectedly.\n if (!routes.length) {\n const fallbackRoute: RouteInternal = {\n match: '*',\n exportEntry: '.',\n isDefaultFallback: true, // this internal property is read by renderRoute\n };\n routes.push(fallbackRoute);\n }\n\n for (const route of routes) {\n if (isStaticRoute(route)) {\n app.use(route.match, express.static(path.resolve(appPath, route.staticPath)));\n } else if (isRedirectRoute(route)) {\n app.get(route.match, (req, res) => {\n res.redirect(route.redirectTo);\n });\n } else if (isRenderedRoute(route) || isBootstrapRoute(route)) {\n app.get(route.match, (req, res) => {\n handleRequest({ ...otherOptions, route, req, res }, context).catch((err) => {\n console.error((err as Error)?.stack || err);\n res.status(500).send(`Error loading app: ${err}`);\n });\n });\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n}\n\nasync function handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute | BootstrapRoute;\n },\n context: CreateRoutesContext,\n) {\n const { req, res, definition, route, url } = options;\n const { session } = context;\n const { bundleServer } = session.urls;\n if (!bundleServer) {\n // Sanity check...\n throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');\n }\n\n // Build the import map if it hasn't been built yet for this session version.\n // (TS can't infer that urls.bundleServer is set on session from a check above.)\n const importMap = (session.importMap ??= await createImportMap({ ...context, ...session, urls: { bundleServer } }));\n\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const entryScript = route.exportEntry && importMap.imports[slash(path.join(definition.name!, route.exportEntry))];\n const inlineScripts = await getInlineScripts();\n\n // Set the appropriate Cloudpack headers in the response.\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n\n let rendered: CompleteRenderRouteResult;\n\n if (isBootstrapRoute(route)) {\n // Render the bootstrap script\n rendered = await renderBootstrapRoute({\n session,\n importMap,\n overlayScript,\n inlineScripts,\n entryScript,\n });\n } else {\n // HTML or custom script rendering\n rendered = await renderRoute({\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n entryScript,\n inlineScripts,\n });\n }\n\n res.type(rendered.contentType).status(rendered.statusCode).send(rendered.content).end();\n\n console.debug(`App server: Request: ${req.path}`);\n}\n"]}
@@ -25,8 +25,9 @@ for (const entry of performance.getEntriesByType('resource')) {
25
25
  perfObserver.observe({ type: 'resource', buffered: true });
26
26
  function getBrowserCacheRatio() {
27
27
  const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;
28
- const ratio = cacheCount / Object.keys(scriptLoadResults).length;
29
- return ratio;
28
+ const totalCount = Object.keys(scriptLoadResults).length;
29
+ const ratio = cacheCount / totalCount;
30
+ return { ratio, hit: cacheCount, total: totalCount };
30
31
  }
31
32
  window.__cloudpack ??= {};
32
33
  window.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;
@@ -1 +1 @@
1
- {"version":3,"file":"getBrowserCacheRatio.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getBrowserCacheRatio.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAEnG,MAAM,iBAAiB,GAAwC,EAAE,CAAC;AAElE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAC5C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,eAAe,CAAC;AAE9E,SAAS,2BAA2B,CAAC,KAAuB;IAC1D,OAAO,KAAK,CAAC,SAAS,KAAK,UAAU,CAAC;AACxC,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAsB;IACpD,IAAI,2BAA2B,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QAC/E,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;IACpD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;QACrC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,4DAA4D;AAC5D,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;IAC7D,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,0DAA0D;AAC1D,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3D,SAAS,oBAAoB;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC;IACjG,MAAM,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC;IAEjE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,oBAAoB,GAAG,oBAAoB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nconst scriptLoadResults: Record<string, 'cache' | 'network'> = {};\n\nif (!window.__cloudpack?.pageSessionContext) {\n throw new Error('window.__cloudpack.pageSessionContext is not defined');\n}\n\nconst bundleServerUrl = window.__cloudpack.pageSessionContext.bundleServerUrl;\n\nfunction isPerformanceResourceTiming(entry: PerformanceEntry): entry is PerformanceResourceTiming {\n return entry.entryType === 'resource';\n}\n\nfunction handlePerformanceEntry(item: PerformanceEntry) {\n if (isPerformanceResourceTiming(item) && item.name.startsWith(bundleServerUrl)) {\n scriptLoadResults[item.name] = item.transferSize === 0 ? 'cache' : 'network';\n }\n}\n\nconst perfObserver = new PerformanceObserver((list) => {\n for (const item of list.getEntries()) {\n handlePerformanceEntry(item);\n }\n});\n\n// Get all the resources that were loaded before this script\nfor (const entry of performance.getEntriesByType('resource')) {\n handlePerformanceEntry(entry);\n}\n\n// Observe all resources that are loaded after this script\nperfObserver.observe({ type: 'resource', buffered: true });\n\nfunction getBrowserCacheRatio() {\n const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;\n const ratio = cacheCount / Object.keys(scriptLoadResults).length;\n\n return ratio;\n}\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;\n"]}
1
+ {"version":3,"file":"getBrowserCacheRatio.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getBrowserCacheRatio.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAEnG,MAAM,iBAAiB,GAAwC,EAAE,CAAC;AAElE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAC5C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,eAAe,CAAC;AAE9E,SAAS,2BAA2B,CAAC,KAAuB;IAC1D,OAAO,KAAK,CAAC,SAAS,KAAK,UAAU,CAAC;AACxC,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAsB;IACpD,IAAI,2BAA2B,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QAC/E,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,CAAC,IAAI,EAAE,EAAE;IACpD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;QACrC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,4DAA4D;AAC5D,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;IAC7D,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,0DAA0D;AAC1D,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAE3D,SAAS,oBAAoB;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,MAAM,CAAC;IACjG,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAAC;IACzD,MAAM,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;IAEtC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AACvD,CAAC;AAED,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,oBAAoB,GAAG,oBAAoB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nconst scriptLoadResults: Record<string, 'cache' | 'network'> = {};\n\nif (!window.__cloudpack?.pageSessionContext) {\n throw new Error('window.__cloudpack.pageSessionContext is not defined');\n}\n\nconst bundleServerUrl = window.__cloudpack.pageSessionContext.bundleServerUrl;\n\nfunction isPerformanceResourceTiming(entry: PerformanceEntry): entry is PerformanceResourceTiming {\n return entry.entryType === 'resource';\n}\n\nfunction handlePerformanceEntry(item: PerformanceEntry) {\n if (isPerformanceResourceTiming(item) && item.name.startsWith(bundleServerUrl)) {\n scriptLoadResults[item.name] = item.transferSize === 0 ? 'cache' : 'network';\n }\n}\n\nconst perfObserver = new PerformanceObserver((list) => {\n for (const item of list.getEntries()) {\n handlePerformanceEntry(item);\n }\n});\n\n// Get all the resources that were loaded before this script\nfor (const entry of performance.getEntriesByType('resource')) {\n handlePerformanceEntry(entry);\n}\n\n// Observe all resources that are loaded after this script\nperfObserver.observe({ type: 'resource', buffered: true });\n\nfunction getBrowserCacheRatio() {\n const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;\n const totalCount = Object.keys(scriptLoadResults).length;\n const ratio = cacheCount / totalCount;\n\n return { ratio, hit: cacheCount, total: totalCount };\n}\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Session } from '@ms-cloudpack/api-server';
2
+ import type { BootstrapInput } from '@ms-cloudpack/common-types-browser';
3
+ import type { CompleteRenderRouteResult } from './types/RenderRouteResult.js';
4
+ /**
5
+ * Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.
6
+ */
7
+ export declare function renderBootstrapRoute(params: Omit<BootstrapInput, 'pageSessionContext'> & {
8
+ session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls'>;
9
+ }): Promise<CompleteRenderRouteResult>;
10
+ //# sourceMappingURL=renderBootstrapRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderBootstrapRoute.d.ts","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAG9E;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,oBAAoB,CAAC,GAAG;IACnD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,MAAM,CAAC,CAAC;CACpE,GACA,OAAO,CAAC,yBAAyB,CAAC,CAwBpC"}
@@ -0,0 +1,27 @@
1
+ import { getBoostrapInlineScript } from './inlineScripts/getInlineScripts.js';
2
+ import { createPageSessionContext } from './createPageSessionContext.js';
3
+ /**
4
+ * Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.
5
+ */
6
+ export async function renderBootstrapRoute(params) {
7
+ const { session, ...partialInput } = params;
8
+ const input = {
9
+ ...partialInput,
10
+ pageSessionContext: createPageSessionContext(session),
11
+ };
12
+ // TS adds "export {}" when transpiling bootstrap.inline.ts due to isolatedModules.
13
+ // Remove this since the bootstrap script cannot be ESM.
14
+ const bootstrapInlineScript = (await getBoostrapInlineScript()).replace('export {};', '');
15
+ // Inject the boostrap inline script
16
+ // Call the bootstrap function with the input
17
+ const content = `
18
+ ${bootstrapInlineScript}
19
+ window.__cloudpack.bootstrap(${JSON.stringify(input)});
20
+ `;
21
+ return {
22
+ content,
23
+ contentType: 'application/javascript',
24
+ statusCode: 200,
25
+ };
26
+ }
27
+ //# sourceMappingURL=renderBootstrapRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderBootstrapRoute.js","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAG9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAEC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAE5C,MAAM,KAAK,GAAmB;QAC5B,GAAG,YAAY;QACf,kBAAkB,EAAE,wBAAwB,CAAC,OAAO,CAAC;KACtD,CAAC;IAEF,mFAAmF;IACnF,wDAAwD;IACxD,MAAM,qBAAqB,GAAG,CAAC,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAE1F,oCAAoC;IACpC,6CAA6C;IAC7C,MAAM,OAAO,GAAG;MACZ,qBAAqB;mCACQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;GACrD,CAAC;IAEF,OAAO;QACL,OAAO;QACP,WAAW,EAAE,wBAAwB;QACrC,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type { Session } from '@ms-cloudpack/api-server';\nimport { getBoostrapInlineScript } from './inlineScripts/getInlineScripts.js';\nimport type { BootstrapInput } from '@ms-cloudpack/common-types-browser';\nimport type { CompleteRenderRouteResult } from './types/RenderRouteResult.js';\nimport { createPageSessionContext } from './createPageSessionContext.js';\n\n/**\n * Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.\n */\nexport async function renderBootstrapRoute(\n params: Omit<BootstrapInput, 'pageSessionContext'> & {\n session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls'>;\n },\n): Promise<CompleteRenderRouteResult> {\n const { session, ...partialInput } = params;\n\n const input: BootstrapInput = {\n ...partialInput,\n pageSessionContext: createPageSessionContext(session),\n };\n\n // TS adds \"export {}\" when transpiling bootstrap.inline.ts due to isolatedModules.\n // Remove this since the bootstrap script cannot be ESM.\n const bootstrapInlineScript = (await getBoostrapInlineScript()).replace('export {};', '');\n\n // Inject the boostrap inline script\n // Call the bootstrap function with the input\n const content = `\n ${bootstrapInlineScript}\n window.__cloudpack.bootstrap(${JSON.stringify(input)});\n `;\n\n return {\n content,\n contentType: 'application/javascript',\n statusCode: 200,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/app-server",
3
- "version": "0.10.4",
3
+ "version": "0.10.6",
4
4
  "description": "An implementation of the App server for Cloudpack.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,19 +14,19 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/api-server": "^0.47.0",
18
- "@ms-cloudpack/bundle-server": "^0.4.33",
19
- "@ms-cloudpack/common-types": "^0.12.0",
20
- "@ms-cloudpack/create-express-app": "^1.6.27",
21
- "@ms-cloudpack/import-map": "^0.5.21",
22
- "@ms-cloudpack/overlay": "^0.17.31",
17
+ "@ms-cloudpack/api-server": "^0.47.2",
18
+ "@ms-cloudpack/bundle-server": "^0.4.35",
19
+ "@ms-cloudpack/common-types": "^0.13.0",
20
+ "@ms-cloudpack/create-express-app": "^1.6.28",
21
+ "@ms-cloudpack/import-map": "^0.5.22",
22
+ "@ms-cloudpack/overlay": "^0.17.33",
23
23
  "@ms-cloudpack/path-string-parsing": "^1.2.3",
24
- "@ms-cloudpack/path-utilities": "^2.7.24",
24
+ "@ms-cloudpack/path-utilities": "^2.7.25",
25
25
  "@ms-cloudpack/task-reporter": "^0.14.1",
26
26
  "jsdom": "^24.0.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@ms-cloudpack/common-types-browser": "^0.2.0",
29
+ "@ms-cloudpack/common-types-browser": "^0.3.0",
30
30
  "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
31
31
  "@ms-cloudpack/scripts": "^0.0.1",
32
32
  "@ms-cloudpack/test-utilities": "^0.5.0",
@@ -1,9 +0,0 @@
1
- import type { Context } from '@ms-cloudpack/api-server';
2
- import type { Request, Response } from '@ms-cloudpack/create-express-app';
3
- type CreateBootstrapRouteHandlerContext = Pick<Context, 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'>;
4
- export declare function createBootstrapRouteHandler(options: {
5
- definitionName: string;
6
- exportEntry?: string;
7
- }, context: CreateBootstrapRouteHandlerContext): (_req: Request, res: Response) => void;
8
- export {};
9
- //# sourceMappingURL=createBootstrapRouteHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBootstrapRouteHandler.d.ts","sourceRoot":"","sources":["../src/createBootstrapRouteHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAKxD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAkB1E,KAAK,kCAAkC,GAAG,IAAI,CAC5C,OAAO,EACP,UAAU,GAAG,oBAAoB,GAAG,eAAe,GAAG,SAAS,CAChE,CAAC;AAEF,wBAAgB,2BAA2B,CACzC,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,EACD,OAAO,EAAE,kCAAkC,UAE7B,OAAO,OAAO,QAAQ,UAqCrC"}
@@ -1,50 +0,0 @@
1
- import { createImportMap } from '@ms-cloudpack/import-map';
2
- import { join } from 'path';
3
- import { getBoostrapInlineScript, getInlineScripts } from './inlineScripts/getInlineScripts.js';
4
- import { slash } from '@ms-cloudpack/path-string-parsing';
5
- import { createPageSessionContext } from './createPageSessionContext.js';
6
- const getBootstrapScript = async (input) => {
7
- let bootstrapInlineScript = await getBoostrapInlineScript();
8
- // Remove the export statement from the inline script, the bootstrap can not be an esm.
9
- bootstrapInlineScript = bootstrapInlineScript.replace('export {};', '');
10
- // Inject the boostrap inline script
11
- // Call the bootstrap function with the input
12
- return `
13
- ${bootstrapInlineScript}
14
- window.__cloudpack.bootstrap(${JSON.stringify(input)});
15
- `;
16
- };
17
- export function createBootstrapRouteHandler(options, context) {
18
- return (_req, res) => {
19
- (async () => {
20
- const { definitionName, exportEntry } = options;
21
- const { session } = context;
22
- const { bundleServer: bundleServerUrl } = session.urls;
23
- if (!bundleServerUrl) {
24
- // Sanity check...
25
- throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');
26
- }
27
- const importMap = (session.importMap ??= await createImportMap({
28
- ...context,
29
- ...session,
30
- urls: { bundleServer: bundleServerUrl },
31
- }));
32
- const inlineScripts = await getInlineScripts();
33
- const pageSessionContext = createPageSessionContext(session);
34
- const entryScript = exportEntry && importMap.imports[slash(join(definitionName, exportEntry))];
35
- const overlayScript = importMap.imports['@ms-cloudpack/overlay'];
36
- const renderedContent = await getBootstrapScript({
37
- importMap,
38
- pageSessionContext,
39
- overlayScript,
40
- inlineScripts,
41
- entryScript,
42
- });
43
- return res.type('application/javascript').send(renderedContent).end();
44
- })().catch((err) => {
45
- console.error(err?.stack || err);
46
- return res.status(500).send(`Error loading app: ${err}`);
47
- });
48
- };
49
- }
50
- //# sourceMappingURL=createBootstrapRouteHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBootstrapRouteHandler.js","sourceRoot":"","sources":["../src/createBootstrapRouteHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAChG,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAG1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,MAAM,kBAAkB,GAAG,KAAK,EAAE,KAAqB,EAAE,EAAE;IACzD,IAAI,qBAAqB,GAAG,MAAM,uBAAuB,EAAE,CAAC;IAE5D,uFAAuF;IACvF,qBAAqB,GAAG,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAExE,oCAAoC;IACpC,6CAA6C;IAC7C,OAAO;MACH,qBAAqB;mCACQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;GACrD,CAAC;AACJ,CAAC,CAAC;AAOF,MAAM,UAAU,2BAA2B,CACzC,OAGC,EACD,OAA2C;IAE3C,OAAO,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;QACtC,CAAC,KAAK,IAAI,EAAE;YACV,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YAEhD,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;YA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udpack/api-server';\nimport { createImportMap } from '@ms-cloudpack/import-map';\nimport { join } from 'path';\nimport { getBoostrapInlineScript, getInlineScripts } from './inlineScripts/getInlineScripts.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { Request, Response } from '@ms-cloudpack/create-express-app';\nimport type { BootstrapInput } from '@ms-cloudpack/common-types-browser';\nimport { createPageSessionContext } from './createPageSessionContext.js';\n\nconst getBootstrapScript = async (input: BootstrapInput) => {\n let bootstrapInlineScript = await getBoostrapInlineScript();\n\n // Remove the export statement from the inline script, the bootstrap can not be an esm.\n bootstrapInlineScript = bootstrapInlineScript.replace('export {};', '');\n\n // Inject the boostrap inline script\n // Call the bootstrap function with the input\n return `\n ${bootstrapInlineScript}\n window.__cloudpack.bootstrap(${JSON.stringify(input)});\n `;\n};\n\ntype CreateBootstrapRouteHandlerContext = Pick<\n Context,\n 'packages' | 'packageImportPaths' | 'packageHashes' | 'session'\n>;\n\nexport function createBootstrapRouteHandler(\n options: {\n definitionName: string;\n exportEntry?: string;\n },\n context: CreateBootstrapRouteHandlerContext,\n) {\n return (_req: Request, res: Response) => {\n (async () => {\n const { definitionName, exportEntry } = options;\n\n const { session } = context;\n const { bundleServer: bundleServerUrl } = session.urls;\n\n if (!bundleServerUrl) {\n // Sanity check...\n throw new Error('The bundle server URL is not yet set in the session (this is a Cloudpack bug).');\n }\n\n const importMap = (session.importMap ??= await createImportMap({\n ...context,\n ...session,\n urls: { bundleServer: bundleServerUrl },\n }));\n\n const inlineScripts = await getInlineScripts();\n const pageSessionContext = createPageSessionContext(session);\n const entryScript = exportEntry && importMap.imports[slash(join(definitionName, exportEntry))];\n const overlayScript = importMap.imports['@ms-cloudpack/overlay'];\n\n const renderedContent = await getBootstrapScript({\n importMap,\n pageSessionContext,\n overlayScript,\n inlineScripts,\n entryScript,\n });\n\n return res.type('application/javascript').send(renderedContent).end();\n })().catch((err) => {\n console.error((err as Error)?.stack || err);\n return res.status(500).send(`Error loading app: ${err}`);\n });\n };\n}\n"]}
@@ -1,8 +0,0 @@
1
- import type { Response } from '@ms-cloudpack/create-express-app';
2
- /**
3
- * Set the Cloudpack headers in the response.
4
- */
5
- export declare function setHeaders(params: {
6
- res: Response;
7
- }): void;
8
- //# sourceMappingURL=setHeaders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setHeaders.d.ts","sourceRoot":"","sources":["../src/setHeaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAEjE;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,QAAQ,CAAA;CAAE,QAKnD"}
package/lib/setHeaders.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * Set the Cloudpack headers in the response.
3
- */
4
- export function setHeaders(params) {
5
- const { res } = params;
6
- res.header('Cache-Control', 'no-cache');
7
- res.header('Access-Control-Allow-Origin', '*');
8
- }
9
- //# sourceMappingURL=setHeaders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setHeaders.js","sourceRoot":"","sources":["../src/setHeaders.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAyB;IAClD,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAEvB,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type { Response } from '@ms-cloudpack/create-express-app';\n\n/**\n * Set the Cloudpack headers in the response.\n */\nexport function setHeaders(params: { res: Response }) {\n const { res } = params;\n\n res.header('Cache-Control', 'no-cache');\n res.header('Access-Control-Allow-Origin', '*');\n}\n"]}