@ms-cloudpack/app-server 0.17.67 → 0.17.69
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.
- package/lib/createPageSessionContext.d.ts.map +1 -1
- package/lib/createPageSessionContext.js +1 -0
- package/lib/createPageSessionContext.js.map +1 -1
- package/lib/createRoutes.js +1 -1
- package/lib/createRoutes.js.map +1 -1
- package/lib/renderBootstrapRoute.d.ts.map +1 -1
- package/lib/renderBootstrapRoute.js +2 -2
- package/lib/renderBootstrapRoute.js.map +1 -1
- package/package.json +10 -10
- package/lib/inlineScripts/bootstrap.inline.d.ts +0 -1
- package/lib/inlineScripts/bootstrap.inline.d.ts.map +0 -1
- package/lib/inlineScripts/bootstrap.inline.js +0 -39
- package/lib/inlineScripts/bootstrap.inline.js.map +0 -1
- package/lib/inlineScripts/defineProcess.inline.d.ts +0 -1
- package/lib/inlineScripts/defineProcess.inline.d.ts.map +0 -1
- package/lib/inlineScripts/defineProcess.inline.js +0 -8
- package/lib/inlineScripts/defineProcess.inline.js.map +0 -1
- package/lib/inlineScripts/errorHandler.inline.d.ts +0 -8
- package/lib/inlineScripts/errorHandler.inline.d.ts.map +0 -1
- package/lib/inlineScripts/errorHandler.inline.js +0 -19
- package/lib/inlineScripts/errorHandler.inline.js.map +0 -1
- package/lib/inlineScripts/getBrowserCacheRatio.inline.d.ts +0 -11
- package/lib/inlineScripts/getBrowserCacheRatio.inline.d.ts.map +0 -1
- package/lib/inlineScripts/getBrowserCacheRatio.inline.js +0 -35
- package/lib/inlineScripts/getBrowserCacheRatio.inline.js.map +0 -1
- package/lib/inlineScripts/getInlineScripts.d.ts +0 -10
- package/lib/inlineScripts/getInlineScripts.d.ts.map +0 -1
- package/lib/inlineScripts/getInlineScripts.js +0 -33
- package/lib/inlineScripts/getInlineScripts.js.map +0 -1
- package/lib/inlineScripts/getPageLoadTime.inline.d.ts +0 -2
- package/lib/inlineScripts/getPageLoadTime.inline.d.ts.map +0 -1
- package/lib/inlineScripts/getPageLoadTime.inline.js +0 -98
- package/lib/inlineScripts/getPageLoadTime.inline.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPageSessionContext.d.ts","sourceRoot":"","sources":["../src/createPageSessionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC,EAC7E,WAAW,EAAE,MAAM,GAClB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"createPageSessionContext.d.ts","sourceRoot":"","sources":["../src/createPageSessionContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC,EAC7E,WAAW,EAAE,MAAM,GAClB,kBAAkB,CAUpB"}
|
|
@@ -9,6 +9,7 @@ export function createPageSessionContext(session, requestPath) {
|
|
|
9
9
|
bundleServerUrl: session.urls.bundleServer ?? '',
|
|
10
10
|
requestPath,
|
|
11
11
|
pageLoadTimePerformanceEntry: session.config.telemetry?.pageLoadTimePerformanceEntry,
|
|
12
|
+
define: session.config.define,
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=createPageSessionContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPageSessionContext.js","sourceRoot":"","sources":["../src/createPageSessionContext.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA6E,EAC7E,WAAmB;IAEnB,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,eAAe,EAAE,OAAO,CAAC,QAAQ;QACjC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE;QACpC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE;QAChD,WAAW;QACX,4BAA4B,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"createPageSessionContext.js","sourceRoot":"","sources":["../src/createPageSessionContext.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAA6E,EAC7E,WAAmB;IAEnB,OAAO;QACL,SAAS,EAAE,OAAO,CAAC,EAAE;QACrB,eAAe,EAAE,OAAO,CAAC,QAAQ;QACjC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE;QACpC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE;QAChD,WAAW;QACX,4BAA4B,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,4BAA4B;QACpF,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type { Session } from '@ms-cloudpack/common-types';\nimport type { PageSessionContext } from '@ms-cloudpack/common-types-browser';\n\n/**\n * Create a page session context that needs to be on the page for Cloudpack to work properly.\n */\nexport function createPageSessionContext(\n session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls' | 'config'>,\n requestPath: string,\n): PageSessionContext {\n return {\n sessionId: session.id,\n currentSequence: session.sequence,\n apiUrl: session.urls.apiServer ?? '',\n bundleServerUrl: session.urls.bundleServer ?? '',\n requestPath,\n pageLoadTimePerformanceEntry: session.config.telemetry?.pageLoadTimePerformanceEntry,\n define: session.config.define,\n };\n}\n"]}
|
package/lib/createRoutes.js
CHANGED
|
@@ -3,7 +3,7 @@ import { express } from '@ms-cloudpack/create-express-app';
|
|
|
3
3
|
import { createImportMap } from '@ms-cloudpack/import-map';
|
|
4
4
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import { getInlineScripts } from '
|
|
6
|
+
import { getInlineScripts } from '@ms-cloudpack/inline-scripts';
|
|
7
7
|
import { renderRoute } from './renderRoute/renderRoute.js';
|
|
8
8
|
import { renderBootstrapRoute } from './renderBootstrapRoute.js';
|
|
9
9
|
import { createPageSessionContext } from './createPageSessionContext.js';
|
package/lib/createRoutes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,aAAa,GAMd,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,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAU9D,qFAAqF;AACrF,SAAS,WAAW,CAAC,MAAe;IAClC,OAAO,CAAC,GAAG,EAAE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C,GAAG,CAAC;IAE5G,6DAA6D;IAC7D,MAAM,aAAa,GAAG,CAAC,wBAAwB,EAAE,GAAG,CAAC,MAAM,gBAAgB,EAAE,CAAC,CAAC,CAAC;IAEhF,yDAAyD;IACzD,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IACxC,GAAG,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAE/C,IAAI,QAA6C,CAAC;IAElD,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,QAAQ,GAAG,MAAM,oBAAoB,CAAC;YACpC,OAAO;YACP,SAAS;YACT,aAAa;YACb,aAAa;YACb,YAAY;YACZ,WAAW,EAAE,GAAG,CAAC,IAAI;SACtB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,QAAQ,GAAG,MAAM,WAAW,CAC1B;YACE,GAAG,OAAO;YACV,OAAO;YACP,OAAO,EAAE,GAAG;YACZ,SAAS;YACT,aAAa;YACb,aAAa;YACb,YAAY;SACb,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IAC1F,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,wBAAwB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { EnsurePackageBundledContext } from '@ms-cloudpack/api-server';\nimport {\n isBootstrapRoute,\n isProxyRoute,\n isRedirectRoute,\n isRenderedRoute,\n isStaticRoute,\n type BootstrapRoute,\n type PackageJson,\n type RenderedRoute,\n type ExpandedRenderFunctionResult,\n type RequestHandler,\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 } from './renderRoute/renderRoute.js';\nimport { renderBootstrapRoute } from './renderBootstrapRoute.js';\nimport { createPageSessionContext } from './createPageSessionContext.js';\nimport { parseRouteMatch } from './parseRouteMatch.js';\nimport { createProxyMiddleware } from 'http-proxy-middleware';\n\ninterface CreateRoutesOptions {\n app: Express;\n /** Base app server URL, including the port */\n url: string;\n /** package.json for the app */\n definition: PackageJson;\n}\n\n/** Express middleware that will match the domain to continue the route execution. */\nfunction matchDomain(domain?: RegExp): RequestHandler {\n return (req, _, next) => {\n if (!domain || domain.test(req.hostname)) {\n return next();\n }\n\n // Jump to next route.\n return next('route');\n };\n}\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: EnsurePackageBundledContext): void {\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 if (!routes.length) {\n // If no routes have been defined, register a default (no path) route only.\n // This will render default HTML which includes the app's default path ('.') from the import map.\n routes.push({\n match: '/',\n // sourcePath and requestPath are required by types but unused in this case.\n entry: [{ importPath: '.', sourcePath: '' }],\n });\n }\n\n for (const route of routes) {\n const matches = Array.isArray(route.match) ? route.match : [route.match];\n\n for (const match of matches) {\n const { pathMatch, domainMatch } = parseRouteMatch(match);\n\n if (isStaticRoute(route)) {\n app.use(pathMatch, matchDomain(domainMatch), express.static(path.resolve(appPath, route.staticPath)));\n } else if (isRedirectRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (req, res) => {\n res.redirect(route.redirectTo);\n });\n } else if (isRenderedRoute(route) || isBootstrapRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (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 if (isProxyRoute(route)) {\n app.use(\n pathMatch,\n matchDomain(domainMatch),\n createProxyMiddleware({ target: route.proxyTo, ...route }) as RequestHandler,\n );\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n }\n}\n\nexport async function _handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute | BootstrapRoute;\n },\n context: EnsurePackageBundledContext,\n): Promise<void> {\n const { req, res, definition, route, url } = options;\n const { session } = context;\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({ targetEnvironment: 'browser' }, context));\n\n // For production mode, no overlay script.\n const overlayScript = session.config.mode !== 'production' ? importMap.imports['@ms-cloudpack/overlay'] : undefined;\n\n // Get all entry scripts for the route.\n const entryScripts = route.entry?.map(\n (entry) => importMap.imports[slash(path.join(definition.name, entry.importPath))],\n );\n\n const pageSessionContextScript =\n `window.__cloudpack ??= {};\\n` +\n `window.__cloudpack.pageSessionContext = ${JSON.stringify(createPageSessionContext(session, req.path))};`;\n\n // Add the pageSessionContext to the top of the inlineScripts\n const inlineScripts = [pageSessionContextScript, ...(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: ExpandedRenderFunctionResult | null;\n\n if (isBootstrapRoute(route)) {\n // Render the bootstrap script\n rendered = await renderBootstrapRoute({\n session,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n requestPath: req.path,\n });\n } else {\n // HTML or custom script rendering\n rendered = await renderRoute(\n {\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n },\n context,\n );\n }\n\n if (rendered) {\n res.type(rendered.contentType).status(rendered.statusCode).send(rendered.content).end();\n }\n\n console.debug(`App server: Request: ${req.path}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"createRoutes.js","sourceRoot":"","sources":["../src/createRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,eAAe,EACf,aAAa,GAMd,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,8BAA8B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAU9D,qFAAqF;AACrF,SAAS,WAAW,CAAC,MAAe;IAClC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzC,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,sBAAsB;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B,EAAE,OAAoC;IAC7F,MAAM,EAAE,GAAG,EAAE,GAAG,Y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BAA8B;QAC9B,QAAQ,GAAG,MAAM,oBAAoB,CAAC;YACpC,OAAO;YACP,SAAS;YACT,aAAa;YACb,aAAa;YACb,YAAY;YACZ,WAAW,EAAE,GAAG,CAAC,IAAI;SACtB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,QAAQ,GAAG,MAAM,WAAW,CAC1B;YACE,GAAG,OAAO;YACV,OAAO;YACP,OAAO,EAAE,GAAG;YACZ,SAAS;YACT,aAAa;YACb,aAAa;YACb,YAAY;SACb,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IAC1F,CAAC;IAED,OAAO,CAAC,KAAK,CAAC,wBAAwB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import type { EnsurePackageBundledContext } from '@ms-cloudpack/api-server';\nimport {\n isBootstrapRoute,\n isProxyRoute,\n isRedirectRoute,\n isRenderedRoute,\n isStaticRoute,\n type BootstrapRoute,\n type PackageJson,\n type RenderedRoute,\n type ExpandedRenderFunctionResult,\n type RequestHandler,\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 '@ms-cloudpack/inline-scripts';\nimport { renderRoute } from './renderRoute/renderRoute.js';\nimport { renderBootstrapRoute } from './renderBootstrapRoute.js';\nimport { createPageSessionContext } from './createPageSessionContext.js';\nimport { parseRouteMatch } from './parseRouteMatch.js';\nimport { createProxyMiddleware } from 'http-proxy-middleware';\n\ninterface CreateRoutesOptions {\n app: Express;\n /** Base app server URL, including the port */\n url: string;\n /** package.json for the app */\n definition: PackageJson;\n}\n\n/** Express middleware that will match the domain to continue the route execution. */\nfunction matchDomain(domain?: RegExp): RequestHandler {\n return (req, _, next) => {\n if (!domain || domain.test(req.hostname)) {\n return next();\n }\n\n // Jump to next route.\n return next('route');\n };\n}\n\n/**\n * Creates the routes for the express app based on the config.\n */\nexport function createRoutes(options: CreateRoutesOptions, context: EnsurePackageBundledContext): void {\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 if (!routes.length) {\n // If no routes have been defined, register a default (no path) route only.\n // This will render default HTML which includes the app's default path ('.') from the import map.\n routes.push({\n match: '/',\n // sourcePath and requestPath are required by types but unused in this case.\n entry: [{ importPath: '.', sourcePath: '' }],\n });\n }\n\n for (const route of routes) {\n const matches = Array.isArray(route.match) ? route.match : [route.match];\n\n for (const match of matches) {\n const { pathMatch, domainMatch } = parseRouteMatch(match);\n\n if (isStaticRoute(route)) {\n app.use(pathMatch, matchDomain(domainMatch), express.static(path.resolve(appPath, route.staticPath)));\n } else if (isRedirectRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (req, res) => {\n res.redirect(route.redirectTo);\n });\n } else if (isRenderedRoute(route) || isBootstrapRoute(route)) {\n app.get(pathMatch, matchDomain(domainMatch), (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 if (isProxyRoute(route)) {\n app.use(\n pathMatch,\n matchDomain(domainMatch),\n createProxyMiddleware({ target: route.proxyTo, ...route }) as RequestHandler,\n );\n } else {\n throw new Error(`Unknown route: ${JSON.stringify(route)}`);\n }\n }\n }\n}\n\nexport async function _handleRequest(\n options: Omit<CreateRoutesOptions, 'app'> & {\n req: Request;\n res: Response;\n route: RenderedRoute | BootstrapRoute;\n },\n context: EnsurePackageBundledContext,\n): Promise<void> {\n const { req, res, definition, route, url } = options;\n const { session } = context;\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({ targetEnvironment: 'browser' }, context));\n\n // For production mode, no overlay script.\n const overlayScript = session.config.mode !== 'production' ? importMap.imports['@ms-cloudpack/overlay'] : undefined;\n\n // Get all entry scripts for the route.\n const entryScripts = route.entry?.map(\n (entry) => importMap.imports[slash(path.join(definition.name, entry.importPath))],\n );\n\n const pageSessionContextScript =\n `window.__cloudpack ??= {};\\n` +\n `window.__cloudpack.pageSessionContext = ${JSON.stringify(createPageSessionContext(session, req.path))};`;\n\n // Add the pageSessionContext to the top of the inlineScripts\n const inlineScripts = [pageSessionContextScript, ...(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: ExpandedRenderFunctionResult | null;\n\n if (isBootstrapRoute(route)) {\n // Render the bootstrap script\n rendered = await renderBootstrapRoute({\n session,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n requestPath: req.path,\n });\n } else {\n // HTML or custom script rendering\n rendered = await renderRoute(\n {\n ...options,\n session,\n baseUrl: url,\n importMap,\n overlayScript,\n inlineScripts,\n entryScripts,\n },\n context,\n );\n }\n\n if (rendered) {\n res.type(rendered.contentType).status(rendered.statusCode).send(rendered.content).end();\n }\n\n console.debug(`App server: Request: ${req.path}`);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderBootstrapRoute.d.ts","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderBootstrapRoute.d.ts","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,4BAA4B,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAGxF;;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,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAC1B,OAAO,CAAC,4BAA4B,CAAC,CAmBvC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getInlineScript } from '@ms-cloudpack/inline-scripts';
|
|
2
2
|
/**
|
|
3
3
|
* Render a route with a JS script that will set up and call `window.__cloudpack.bootstrap()`.
|
|
4
4
|
*/
|
|
@@ -6,7 +6,7 @@ export async function renderBootstrapRoute(params) {
|
|
|
6
6
|
const { session, requestPath, ...input } = params;
|
|
7
7
|
// TS adds "export {}" when transpiling bootstrap.inline.ts due to isolatedModules.
|
|
8
8
|
// Remove this since the bootstrap script cannot be ESM.
|
|
9
|
-
const bootstrapInlineScript = (await
|
|
9
|
+
const bootstrapInlineScript = (await getInlineScript('bootstrap')).replace('export {};', '');
|
|
10
10
|
// Inject the boostrap inline script
|
|
11
11
|
// Call the bootstrap function with the input
|
|
12
12
|
const content = `
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderBootstrapRoute.js","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderBootstrapRoute.js","sourceRoot":"","sources":["../src/renderBootstrapRoute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAE2B;IAE3B,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IAElD,mFAAmF;IACnF,wDAAwD;IACxD,MAAM,qBAAqB,GAAG,CAAC,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAE7F,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 { BootstrapInput } from '@ms-cloudpack/common-types-browser';\nimport type { ExpandedRenderFunctionResult, Session } from '@ms-cloudpack/common-types';\nimport { getInlineScript } from '@ms-cloudpack/inline-scripts';\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 } & { requestPath: string },\n): Promise<ExpandedRenderFunctionResult> {\n const { session, requestPath, ...input } = params;\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 getInlineScript('bootstrap')).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.17.
|
|
3
|
+
"version": "0.17.69",
|
|
4
4
|
"description": "An implementation of the App server for Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,22 +14,22 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/api-server": "^0.61.
|
|
18
|
-
"@ms-cloudpack/bundle-server": "^0.6.
|
|
19
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
20
|
-
"@ms-cloudpack/create-express-app": "^1.10.
|
|
17
|
+
"@ms-cloudpack/api-server": "^0.61.17",
|
|
18
|
+
"@ms-cloudpack/bundle-server": "^0.6.78",
|
|
19
|
+
"@ms-cloudpack/common-types": "^0.24.11",
|
|
20
|
+
"@ms-cloudpack/create-express-app": "^1.10.23",
|
|
21
21
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
22
|
-
"@ms-cloudpack/import-map": "^0.10.
|
|
23
|
-
"@ms-cloudpack/
|
|
22
|
+
"@ms-cloudpack/import-map": "^0.10.5",
|
|
23
|
+
"@ms-cloudpack/inline-scripts": "^0.1.2",
|
|
24
24
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
25
|
-
"@ms-cloudpack/path-utilities": "^3.0.
|
|
25
|
+
"@ms-cloudpack/path-utilities": "^3.0.8",
|
|
26
26
|
"@ms-cloudpack/task-reporter": "^0.16.0",
|
|
27
27
|
"happy-dom": "^17.1.1",
|
|
28
28
|
"http-proxy-middleware": "^2.0.6"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@ms-cloudpack/common-types-browser": "^0.5.
|
|
32
|
-
"@ms-cloudpack/config": "^0.33.
|
|
31
|
+
"@ms-cloudpack/common-types-browser": "^0.5.5",
|
|
32
|
+
"@ms-cloudpack/config": "^0.33.23",
|
|
33
33
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
34
34
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
35
35
|
"@ms-cloudpack/test-utilities": "^0.5.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=bootstrap.inline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.inline.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/bootstrap.inline.ts"],"names":[],"mappings":""}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
window.__cloudpack ??= {};
|
|
3
|
-
window.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, entryScripts }) => {
|
|
4
|
-
window.__cloudpack ??= {};
|
|
5
|
-
if (window.__cloudpack.hasBootstrapRun) {
|
|
6
|
-
console.warn('Cloudpack bootstrap has already run, skipping.');
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
window.__cloudpack.hasBootstrapRun = true;
|
|
10
|
-
// Inject the import map
|
|
11
|
-
const importMapScriptTag = document.createElement('script');
|
|
12
|
-
importMapScriptTag.type = 'importmap';
|
|
13
|
-
importMapScriptTag.textContent = JSON.stringify(importMap);
|
|
14
|
-
document.head.appendChild(importMapScriptTag);
|
|
15
|
-
// Inject the inline scripts
|
|
16
|
-
for (const inlineScript of inlineScripts) {
|
|
17
|
-
const inlineTag = document.createElement('script');
|
|
18
|
-
inlineTag.type = 'module';
|
|
19
|
-
inlineTag.textContent = inlineScript;
|
|
20
|
-
document.head.appendChild(inlineTag);
|
|
21
|
-
}
|
|
22
|
-
// Inject the overlay script
|
|
23
|
-
if (overlayScript) {
|
|
24
|
-
const overlayScriptTag = document.createElement('script');
|
|
25
|
-
overlayScriptTag.type = 'module';
|
|
26
|
-
overlayScriptTag.src = overlayScript;
|
|
27
|
-
document.head.appendChild(overlayScriptTag);
|
|
28
|
-
}
|
|
29
|
-
// Inject the main script
|
|
30
|
-
if (entryScripts) {
|
|
31
|
-
for (const entryScript of entryScripts) {
|
|
32
|
-
const entryScriptTag = document.createElement('script');
|
|
33
|
-
entryScriptTag.type = 'module';
|
|
34
|
-
entryScriptTag.src = entryScript;
|
|
35
|
-
document.head.appendChild(entryScriptTag);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=bootstrap.inline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/bootstrap.inline.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,SAAS,GAAG,CAAC,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE;IAC3F,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;IAC1B,IAAI,MAAM,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;QACvC,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC,CAAC;QAC/D,OAAO;IACT,CAAC;IACD,MAAM,CAAC,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC;IAC1C,wBAAwB;IACxB,MAAM,kBAAkB,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC5D,kBAAkB,CAAC,IAAI,GAAG,WAAW,CAAC;IACtC,kBAAkB,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC3D,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IAE9C,4BAA4B;IAC5B,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACnD,SAAS,CAAC,IAAI,GAAG,QAAQ,CAAC;QAC1B,SAAS,CAAC,WAAW,GAAG,YAAY,CAAC;QACrC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,4BAA4B;IAC5B,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC1D,gBAAgB,CAAC,IAAI,GAAG,QAAQ,CAAC;QACjC,gBAAgB,CAAC,GAAG,GAAG,aAAa,CAAC;QACrC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAC9C,CAAC;IAED,yBAAyB;IACzB,IAAI,YAAY,EAAE,CAAC;QACjB,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YACxD,cAAc,CAAC,IAAI,GAAG,QAAQ,CAAC;YAC/B,cAAc,CAAC,GAAG,GAAG,WAAW,CAAC;YACjC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["window.__cloudpack ??= {};\nwindow.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, entryScripts }) => {\n window.__cloudpack ??= {};\n if (window.__cloudpack.hasBootstrapRun) {\n console.warn('Cloudpack bootstrap has already run, skipping.');\n return;\n }\n window.__cloudpack.hasBootstrapRun = true;\n // Inject the import map\n const importMapScriptTag = document.createElement('script');\n importMapScriptTag.type = 'importmap';\n importMapScriptTag.textContent = JSON.stringify(importMap);\n document.head.appendChild(importMapScriptTag);\n\n // Inject the inline scripts\n for (const inlineScript of inlineScripts) {\n const inlineTag = document.createElement('script');\n inlineTag.type = 'module';\n inlineTag.textContent = inlineScript;\n document.head.appendChild(inlineTag);\n }\n\n // Inject the overlay script\n if (overlayScript) {\n const overlayScriptTag = document.createElement('script');\n overlayScriptTag.type = 'module';\n overlayScriptTag.src = overlayScript;\n document.head.appendChild(overlayScriptTag);\n }\n\n // Inject the main script\n if (entryScripts) {\n for (const entryScript of entryScripts) {\n const entryScriptTag = document.createElement('script');\n entryScriptTag.type = 'module';\n entryScriptTag.src = entryScript;\n document.head.appendChild(entryScriptTag);\n }\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=defineProcess.inline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineProcess.inline.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/defineProcess.inline.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file must NOT import other files, because they won't be resolved at runtime.
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
window.process ??= {};
|
|
5
|
-
window.process.env ??= {};
|
|
6
|
-
// Assign true to process.browser for packages like readable-stream
|
|
7
|
-
process.browser = true;
|
|
8
|
-
//# sourceMappingURL=defineProcess.inline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineProcess.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/defineProcess.inline.ts"],"names":[],"mappings":";AAAA,oFAAoF;AAEpF,8DAA8D;AAC9D,MAAM,CAAC,OAAO,KAAK,EAAS,CAAC;AAC7B,MAAM,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,CAAC;AAE1B,mEAAmE;AAClE,OAA2C,CAAC,OAAO,GAAG,IAAI,CAAC","sourcesContent":["// This file must NOT import other files, because they won't be resolved at runtime.\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nwindow.process ??= {} as any;\nwindow.process.env ??= {};\n\n// Assign true to process.browser for packages like readable-stream\n(process as unknown as { browser: boolean }).browser = true;\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
declare const pageErrors: {
|
|
2
|
-
uncaughtErrors: ErrorEvent[];
|
|
3
|
-
uncaughtRejections: PromiseRejectionEvent[];
|
|
4
|
-
unregister: () => void;
|
|
5
|
-
};
|
|
6
|
-
declare function handleError(event: ErrorEvent): void;
|
|
7
|
-
declare function handleRejection(event: PromiseRejectionEvent): void;
|
|
8
|
-
//# sourceMappingURL=errorHandler.inline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.inline.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/errorHandler.inline.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,UAAU;oBACQ,UAAU,EAAE;wBACR,qBAAqB,EAAE;;CAKjD,CAAC;AAEH,iBAAS,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAE5C;AAED,iBAAS,eAAe,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CAE3D"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file must NOT import other files, because they won't be resolved at runtime.
|
|
3
|
-
const pageErrors = (window.__pageErrors = {
|
|
4
|
-
uncaughtErrors: [],
|
|
5
|
-
uncaughtRejections: [],
|
|
6
|
-
unregister: () => {
|
|
7
|
-
window.removeEventListener('error', handleError);
|
|
8
|
-
window.removeEventListener('unhandledrejection', handleRejection);
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
function handleError(event) {
|
|
12
|
-
pageErrors.uncaughtErrors.push(event);
|
|
13
|
-
}
|
|
14
|
-
function handleRejection(event) {
|
|
15
|
-
pageErrors.uncaughtRejections.push(event);
|
|
16
|
-
}
|
|
17
|
-
window.addEventListener('error', handleError);
|
|
18
|
-
window.addEventListener('unhandledrejection', handleRejection);
|
|
19
|
-
//# sourceMappingURL=errorHandler.inline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/errorHandler.inline.ts"],"names":[],"mappings":";AAAA,oFAAoF;AAEpF,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG;IACxC,cAAc,EAAE,EAAkB;IAClC,kBAAkB,EAAE,EAA6B;IACjD,UAAU,EAAE,GAAG,EAAE;QACf,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACjD,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;IACpE,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,WAAW,CAAC,KAAiB;IACpC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,eAAe,CAAC,KAA4B;IACnD,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAC9C,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC","sourcesContent":["// This file must NOT import other files, because they won't be resolved at runtime.\n\nconst pageErrors = (window.__pageErrors = {\n uncaughtErrors: [] as ErrorEvent[],\n uncaughtRejections: [] as PromiseRejectionEvent[],\n unregister: () => {\n window.removeEventListener('error', handleError);\n window.removeEventListener('unhandledrejection', handleRejection);\n },\n});\n\nfunction handleError(event: ErrorEvent): void {\n pageErrors.uncaughtErrors.push(event);\n}\n\nfunction handleRejection(event: PromiseRejectionEvent): void {\n pageErrors.uncaughtRejections.push(event);\n}\n\nwindow.addEventListener('error', handleError);\nwindow.addEventListener('unhandledrejection', handleRejection);\n"]}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare const scriptLoadResults: Record<string, 'cache' | 'network'>;
|
|
2
|
-
declare const bundleServerUrl: string;
|
|
3
|
-
declare function isPerformanceResourceTiming(entry: PerformanceEntry): entry is PerformanceResourceTiming;
|
|
4
|
-
declare function handlePerformanceEntry(item: PerformanceEntry): void;
|
|
5
|
-
declare const perfObserver: PerformanceObserver;
|
|
6
|
-
declare function getBrowserCacheRatio(): {
|
|
7
|
-
ratio: number;
|
|
8
|
-
hit: number;
|
|
9
|
-
total: number;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=getBrowserCacheRatio.inline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBrowserCacheRatio.inline.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/getBrowserCacheRatio.inline.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAM,CAAC;AAMlE,QAAA,MAAM,eAAe,QAAwD,CAAC;AAE9E,iBAAS,2BAA2B,CAAC,KAAK,EAAE,gBAAgB,GAAG,KAAK,IAAI,yBAAyB,CAEhG;AAED,iBAAS,sBAAsB,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAI5D;AAED,QAAA,MAAM,YAAY,qBAIhB,CAAC;AAUH,iBAAS,oBAAoB,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAM7E"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file must NOT import other files (except types), because they won't be resolved at runtime.
|
|
3
|
-
const scriptLoadResults = {};
|
|
4
|
-
if (!window.__cloudpack?.pageSessionContext) {
|
|
5
|
-
throw new Error('window.__cloudpack.pageSessionContext is not defined');
|
|
6
|
-
}
|
|
7
|
-
const bundleServerUrl = window.__cloudpack.pageSessionContext.bundleServerUrl;
|
|
8
|
-
function isPerformanceResourceTiming(entry) {
|
|
9
|
-
return entry.entryType === 'resource';
|
|
10
|
-
}
|
|
11
|
-
function handlePerformanceEntry(item) {
|
|
12
|
-
if (isPerformanceResourceTiming(item) && item.name.startsWith(bundleServerUrl)) {
|
|
13
|
-
scriptLoadResults[item.name] = item.transferSize === 0 ? 'cache' : 'network';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const perfObserver = new PerformanceObserver((list) => {
|
|
17
|
-
for (const item of list.getEntries()) {
|
|
18
|
-
handlePerformanceEntry(item);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
// Get all the resources that were loaded before this script
|
|
22
|
-
for (const entry of performance.getEntriesByType('resource')) {
|
|
23
|
-
handlePerformanceEntry(entry);
|
|
24
|
-
}
|
|
25
|
-
// Observe all resources that are loaded after this script
|
|
26
|
-
perfObserver.observe({ type: 'resource', buffered: true });
|
|
27
|
-
function getBrowserCacheRatio() {
|
|
28
|
-
const cacheCount = Object.values(scriptLoadResults).filter((source) => source == 'cache').length;
|
|
29
|
-
const totalCount = Object.keys(scriptLoadResults).length;
|
|
30
|
-
const ratio = cacheCount / totalCount;
|
|
31
|
-
return { ratio, hit: cacheCount, total: totalCount };
|
|
32
|
-
}
|
|
33
|
-
window.__cloudpack ??= {};
|
|
34
|
-
window.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;
|
|
35
|
-
//# sourceMappingURL=getBrowserCacheRatio.inline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAW,CAAC;AAChE,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): void {\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(): { ratio: number; hit: number; total: number } {\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 } as const;\n}\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.getBrowserCacheRatio = getBrowserCacheRatio;\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads all the inline scripts except bootstrap from the file system and returns them. It caches the result for subsequent calls.
|
|
3
|
-
* @returns The inline scripts excluding bootstrap.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getInlineScripts(): Promise<string[]>;
|
|
6
|
-
/**
|
|
7
|
-
* Reads the bootstrap inline script from the file system and returns it.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getBoostrapInlineScript(): Promise<string>;
|
|
10
|
-
//# sourceMappingURL=getInlineScripts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getInlineScripts.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/getInlineScripts.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAS1D;AAID;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAQ/D"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { globSourceFiles } from '@ms-cloudpack/path-utilities';
|
|
2
|
-
import fsPromises from 'fs/promises';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
async function readInlineScript(fileName) {
|
|
6
|
-
let content = await fsPromises.readFile(fileName, 'utf-8');
|
|
7
|
-
// Remove source maps from inline scripts to avoid warnings in the browser.
|
|
8
|
-
content = content.replace('# sourceMappingURL=', ' ');
|
|
9
|
-
return content;
|
|
10
|
-
}
|
|
11
|
-
let inlineScripts;
|
|
12
|
-
/**
|
|
13
|
-
* Reads all the inline scripts except bootstrap from the file system and returns them. It caches the result for subsequent calls.
|
|
14
|
-
* @returns The inline scripts excluding bootstrap.
|
|
15
|
-
*/
|
|
16
|
-
export async function getInlineScripts() {
|
|
17
|
-
if (!inlineScripts) {
|
|
18
|
-
const inlineScriptFiles = (await globSourceFiles(import.meta.url, '*.inline')).filter((file) => !file.includes('bootstrap.inline'));
|
|
19
|
-
inlineScripts = await Promise.all(inlineScriptFiles.map((filename) => readInlineScript(filename)));
|
|
20
|
-
}
|
|
21
|
-
return inlineScripts;
|
|
22
|
-
}
|
|
23
|
-
let bootstrapInlineScript;
|
|
24
|
-
/**
|
|
25
|
-
* Reads the bootstrap inline script from the file system and returns it.
|
|
26
|
-
*/
|
|
27
|
-
export async function getBoostrapInlineScript() {
|
|
28
|
-
if (!bootstrapInlineScript) {
|
|
29
|
-
bootstrapInlineScript = await readInlineScript(path.join(path.dirname(fileURLToPath(import.meta.url)), 'bootstrap.inline.js'));
|
|
30
|
-
}
|
|
31
|
-
return bootstrapInlineScript;
|
|
32
|
-
}
|
|
33
|
-
//# source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,gBAAgB,CAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAC/E,CAAC;IACJ,CAAC;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC","sourcesContent":["import { globSourceFiles } from '@ms-cloudpack/path-utilities';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nasync function readInlineScript(fileName: string): Promise<string> {\n let content = await fsPromises.readFile(fileName, 'utf-8');\n\n // Remove source maps from inline scripts to avoid warnings in the browser.\n content = content.replace('# sourceMappingURL=', ' ');\n\n return content;\n}\n\nlet inlineScripts: string[] | undefined;\n\n/**\n * Reads all the inline scripts except bootstrap from the file system and returns them. It caches the result for subsequent calls.\n * @returns The inline scripts excluding bootstrap.\n */\nexport async function getInlineScripts(): Promise<string[]> {\n if (!inlineScripts) {\n const inlineScriptFiles = (await globSourceFiles(import.meta.url, '*.inline')).filter(\n (file) => !file.includes('bootstrap.inline'),\n );\n inlineScripts = await Promise.all(inlineScriptFiles.map((filename) => readInlineScript(filename)));\n }\n\n return inlineScripts;\n}\n\nlet bootstrapInlineScript: string | undefined;\n\n/**\n * Reads the bootstrap inline script from the file system and returns it.\n */\nexport async function getBoostrapInlineScript(): Promise<string> {\n if (!bootstrapInlineScript) {\n bootstrapInlineScript = await readInlineScript(\n path.join(path.dirname(fileURLToPath(import.meta.url)), 'bootstrap.inline.js'),\n );\n }\n\n return bootstrapInlineScript;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPageLoadTime.inline.d.ts","sourceRoot":"","sources":["../../src/inlineScripts/getPageLoadTime.inline.ts"],"names":[],"mappings":""}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// This file must NOT import other files (except types), because they won't be resolved at runtime.
|
|
2
|
-
// Typing hack to ensure this ID is correct while working around the limitation on runtime imports
|
|
3
|
-
const overlayRootDivId = 'cloudpack-overlay-root';
|
|
4
|
-
/**
|
|
5
|
-
* Performance mark name for page load time.
|
|
6
|
-
* This makes it easier to see the page load time in the performance tab in dev tools
|
|
7
|
-
*/
|
|
8
|
-
const pageLoadMarker = 'CLOUDPACK_PAGE_LOAD_TIME';
|
|
9
|
-
// The below dom elements will be ignored by mutation observer
|
|
10
|
-
const excludedIds = [overlayRootDivId];
|
|
11
|
-
const defaultPltEntryType = 'mark';
|
|
12
|
-
const defaultPltEntryTimeout = 5 * 60 * 1000; // 5 minutes
|
|
13
|
-
function debounce(func, wait) {
|
|
14
|
-
let timeout;
|
|
15
|
-
return function (...args) {
|
|
16
|
-
if (timeout) {
|
|
17
|
-
clearTimeout(timeout);
|
|
18
|
-
}
|
|
19
|
-
timeout = setTimeout(() => {
|
|
20
|
-
timeout = null;
|
|
21
|
-
func(...args);
|
|
22
|
-
}, wait);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function hasMutationNonExcludedNodes(mutation) {
|
|
26
|
-
return Array.from(mutation.addedNodes).some((node) => {
|
|
27
|
-
const id = node.id;
|
|
28
|
-
if (id) {
|
|
29
|
-
return !excludedIds.includes(id);
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
const waitForPerformancEntry = (pltPerfEntry) => {
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
let timeout = null;
|
|
37
|
-
const observer = new PerformanceObserver((list) => {
|
|
38
|
-
const entries = list.getEntriesByName(pltPerfEntry.name, pltPerfEntry.type);
|
|
39
|
-
if (entries.length > 0) {
|
|
40
|
-
observer.disconnect();
|
|
41
|
-
if (timeout) {
|
|
42
|
-
clearTimeout(timeout);
|
|
43
|
-
timeout = null;
|
|
44
|
-
}
|
|
45
|
-
resolve(entries[entries.length - 1]);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
observer.observe({ entryTypes: [pltPerfEntry.type ?? defaultPltEntryType] });
|
|
49
|
-
// Add a timeout to reject the promise if the entry is not found within a reasonable time
|
|
50
|
-
timeout = setTimeout(() => {
|
|
51
|
-
observer.disconnect();
|
|
52
|
-
reject(new Error('Performance entry not found within the timeout period'));
|
|
53
|
-
}, pltPerfEntry.timeout ?? defaultPltEntryTimeout);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const pageLoadTimePromise = new Promise((resolve, reject) => {
|
|
57
|
-
const pltPerfEntry = window.__cloudpack?.pageSessionContext?.pageLoadTimePerformanceEntry;
|
|
58
|
-
if (pltPerfEntry) {
|
|
59
|
-
// If the pageLoadTimePerformanceMark is set, wait for it and resolve the promise.
|
|
60
|
-
// No need to observe the DOM changes.
|
|
61
|
-
void waitForPerformancEntry(pltPerfEntry)
|
|
62
|
-
.then((entry) => {
|
|
63
|
-
resolve(entry.entryType == 'mark' ? entry.startTime : entry.duration);
|
|
64
|
-
})
|
|
65
|
-
.catch(reject);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const observer = new MutationObserver(domChanged);
|
|
69
|
-
function reportLastAnimationTime(time) {
|
|
70
|
-
// Stop observing the DOM
|
|
71
|
-
observer.disconnect();
|
|
72
|
-
// Resolve the promise with the page load time
|
|
73
|
-
resolve(time);
|
|
74
|
-
}
|
|
75
|
-
const debouncedReportLastAnimationTime = debounce(reportLastAnimationTime, 2000 /* wait ms */);
|
|
76
|
-
function domChanged(mutations) {
|
|
77
|
-
const shouldProcess = mutations.filter(hasMutationNonExcludedNodes).length > 0;
|
|
78
|
-
if (shouldProcess) {
|
|
79
|
-
requestAnimationFrame(() => {
|
|
80
|
-
// Get the current time in ms since the time when navigation has started in window
|
|
81
|
-
const time = performance.now();
|
|
82
|
-
// Clear previous marks
|
|
83
|
-
performance.clearMarks(pageLoadMarker);
|
|
84
|
-
// Mark the page load time
|
|
85
|
-
performance.mark(pageLoadMarker);
|
|
86
|
-
// Report the page load time
|
|
87
|
-
debouncedReportLastAnimationTime(time);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
observer.observe(document.body, {
|
|
92
|
-
childList: true,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
window.__cloudpack ??= {};
|
|
96
|
-
window.__cloudpack.getPageLoadTime = () => pageLoadTimePromise;
|
|
97
|
-
export {};
|
|
98
|
-
//# sourceMappingURL=getPageLoadTime.inline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPageLoadTime.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getPageLoadTime.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;AAKnG,kGAAkG;AAClG,MAAM,gBAAgB,GAAgC,wBAAwB,CAAC;AAE/E;;;GAGG;AACH,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,8DAA8D;AAC9D,MAAM,WAAW,GAAa,CAAC,gBAAgB,CAAC,CAAC;AAIjD,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAE1D,SAAS,QAAQ,CAAsB,IAAqB,EAAE,IAAY;IACxE,IAAI,OAA6C,CAAC;IAElD,OAAO,UAAU,GAAG,IAAO;QACzB,IAAI,OAAO,EAAE,CAAC;YACZ,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAChB,CAAC,EAAE,IAAI,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAAC,QAAwB;IAC3D,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACnD,MAAM,EAAE,GAAI,IAAwB,CAAC,EAAE,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AAC;QACL,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE;QAC9B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC;AAC1B,MAAM,CAAC,WAAW,CAAC,eAAe,GAAG,GAAG,EAAE,CAAC,mBAAmB,CAAC","sourcesContent":["// This file must NOT import other files (except types), because they won't be resolved at runtime.\n\nimport type { PageLoadTimePerformanceEntry } from '@ms-cloudpack/common-types-browser';\nimport type { elementIds } from '@ms-cloudpack/overlay/constants';\n\n// Typing hack to ensure this ID is correct while working around the limitation on runtime imports\nconst overlayRootDivId: (typeof elementIds)['root'] = 'cloudpack-overlay-root';\n\n/**\n * Performance mark name for page load time.\n * This makes it easier to see the page load time in the performance tab in dev tools\n */\nconst pageLoadMarker = 'CLOUDPACK_PAGE_LOAD_TIME';\n\n// The below dom elements will be ignored by mutation observer\nconst excludedIds: string[] = [overlayRootDivId];\n\ntype DebounceFunc<T extends unknown[]> = (...args: T) => void;\n\nconst defaultPltEntryType = 'mark';\nconst defaultPltEntryTimeout = 5 * 60 * 1000; // 5 minutes\n\nfunction debounce<T extends unknown[]>(func: DebounceFunc<T>, wait: number): DebounceFunc<T> {\n let timeout: ReturnType<typeof setTimeout> | null;\n\n return function (...args: T) {\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(() => {\n timeout = null;\n func(...args);\n }, wait);\n };\n}\n\nfunction hasMutationNonExcludedNodes(mutation: MutationRecord): boolean {\n return Array.from(mutation.addedNodes).some((node) => {\n const id = (node as { id?: string }).id;\n\n if (id) {\n return !excludedIds.includes(id);\n }\n\n return true;\n });\n}\n\nconst waitForPerformancEntry = (pltPerfEntry: PageLoadTimePerformanceEntry): Promise<PerformanceEntry> => {\n return new Promise((resolve, reject) => {\n let timeout: ReturnType<typeof setTimeout> | null = null;\n\n const observer = new PerformanceObserver((list) => {\n const entries = list.getEntriesByName(pltPerfEntry.name, pltPerfEntry.type);\n if (entries.length > 0) {\n observer.disconnect();\n if (timeout) {\n clearTimeout(timeout);\n timeout = null;\n }\n\n resolve(entries[entries.length - 1]);\n }\n });\n\n observer.observe({ entryTypes: [pltPerfEntry.type ?? defaultPltEntryType] });\n\n // Add a timeout to reject the promise if the entry is not found within a reasonable time\n timeout = setTimeout(() => {\n observer.disconnect();\n reject(new Error('Performance entry not found within the timeout period'));\n }, pltPerfEntry.timeout ?? defaultPltEntryTimeout);\n });\n};\n\nconst pageLoadTimePromise = new Promise<number>((resolve, reject) => {\n const pltPerfEntry = window.__cloudpack?.pageSessionContext?.pageLoadTimePerformanceEntry;\n if (pltPerfEntry) {\n // If the pageLoadTimePerformanceMark is set, wait for it and resolve the promise.\n // No need to observe the DOM changes.\n void waitForPerformancEntry(pltPerfEntry)\n .then((entry) => {\n resolve(entry.entryType == 'mark' ? entry.startTime : entry.duration);\n })\n .catch(reject);\n return;\n }\n\n const observer = new MutationObserver(domChanged);\n\n function reportLastAnimationTime(time: number) {\n // Stop observing the DOM\n observer.disconnect();\n\n // Resolve the promise with the page load time\n resolve(time);\n }\n\n const debouncedReportLastAnimationTime = debounce(reportLastAnimationTime, 2000 /* wait ms */);\n\n function domChanged(mutations: MutationRecord[]) {\n const shouldProcess = mutations.filter(hasMutationNonExcludedNodes).length > 0;\n\n if (shouldProcess) {\n requestAnimationFrame(() => {\n // Get the current time in ms since the time when navigation has started in window\n const time = performance.now();\n\n // Clear previous marks\n performance.clearMarks(pageLoadMarker);\n\n // Mark the page load time\n performance.mark(pageLoadMarker);\n\n // Report the page load time\n debouncedReportLastAnimationTime(time);\n });\n }\n }\n\n observer.observe(document.body, {\n childList: true,\n });\n});\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.getPageLoadTime = () => pageLoadTimePromise;\n"]}
|