@ms-cloudpack/app-server 0.17.43 → 0.17.45
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 +1 -1
- package/lib/createPageSessionContext.d.ts.map +1 -1
- package/lib/createPageSessionContext.js +1 -0
- package/lib/createPageSessionContext.js.map +1 -1
- package/lib/inlineScripts/getPageLoadTime.inline.js +36 -1
- package/lib/inlineScripts/getPageLoadTime.inline.js.map +1 -1
- package/package.json +9 -9
|
@@ -3,5 +3,5 @@ import type { PageSessionContext } from '@ms-cloudpack/common-types-browser';
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a page session context that needs to be on the page for Cloudpack to work properly.
|
|
5
5
|
*/
|
|
6
|
-
export declare function createPageSessionContext(session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls'>, requestPath: string): PageSessionContext;
|
|
6
|
+
export declare function createPageSessionContext(session: Pick<Session, 'id' | 'sequence' | 'projectName' | 'urls' | 'config'>, requestPath: string): PageSessionContext;
|
|
7
7
|
//# sourceMappingURL=createPageSessionContext.d.ts.map
|
|
@@ -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,CAAC,
|
|
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,CASpB"}
|
|
@@ -8,6 +8,7 @@ export function createPageSessionContext(session, requestPath) {
|
|
|
8
8
|
apiUrl: session.urls.apiServer ?? '',
|
|
9
9
|
bundleServerUrl: session.urls.bundleServer ?? '',
|
|
10
10
|
requestPath,
|
|
11
|
+
pageLoadTimePerformanceEntry: session.config.telemetry?.pageLoadTimePerformanceEntry,
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
//# 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,
|
|
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;KACrF,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 };\n}\n"]}
|
|
@@ -8,6 +8,8 @@ const overlayRootDivId = 'cloudpack-overlay-root';
|
|
|
8
8
|
const pageLoadMarker = 'CLOUDPACK_PAGE_LOAD_TIME';
|
|
9
9
|
// The below dom elements will be ignored by mutation observer
|
|
10
10
|
const excludedIds = [overlayRootDivId];
|
|
11
|
+
const defaultPltEntryType = 'mark';
|
|
12
|
+
const defaultPltEntryTimeout = 5 * 60 * 1000; // 5 minutes
|
|
11
13
|
function debounce(func, wait) {
|
|
12
14
|
let timeout;
|
|
13
15
|
return function (...args) {
|
|
@@ -29,7 +31,40 @@ function hasMutationNonExcludedNodes(mutation) {
|
|
|
29
31
|
return true;
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
|
-
const
|
|
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
|
+
}
|
|
33
68
|
const observer = new MutationObserver(domChanged);
|
|
34
69
|
function reportLastAnimationTime(time) {
|
|
35
70
|
// Stop observing the DOM
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPageLoadTime.inline.js","sourceRoot":"","sources":["../../src/inlineScripts/getPageLoadTime.inline.ts"],"names":[],"mappings":"AAAA,mGAAmG;
|
|
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;I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,CAAC,SAA2B;QAC7C,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAE/E,IAAI,aAAa,EAAE,CAAC;YAClB,qBAAqB,CAAC,GAAG,EAAE;gBACzB,kFAAkF;gBAClF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;gBAE/B,uBAAuB;gBACvB,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;gBAEvC,0BAA0B;gBAC1B,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAEjC,4BAA4B;gBAC5B,gCAAgC,CAAC,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;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 [...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"]}
|
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.45",
|
|
4
4
|
"description": "An implementation of the App server for Cloudpack.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/api-server": "^0.58.
|
|
18
|
-
"@ms-cloudpack/bundle-server": "^0.6.
|
|
19
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
20
|
-
"@ms-cloudpack/create-express-app": "^1.10.
|
|
21
|
-
"@ms-cloudpack/import-map": "^0.8.
|
|
22
|
-
"@ms-cloudpack/overlay": "^0.17.
|
|
17
|
+
"@ms-cloudpack/api-server": "^0.58.15",
|
|
18
|
+
"@ms-cloudpack/bundle-server": "^0.6.54",
|
|
19
|
+
"@ms-cloudpack/common-types": "^0.24.6",
|
|
20
|
+
"@ms-cloudpack/create-express-app": "^1.10.18",
|
|
21
|
+
"@ms-cloudpack/import-map": "^0.8.28",
|
|
22
|
+
"@ms-cloudpack/overlay": "^0.17.126",
|
|
23
23
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
24
|
-
"@ms-cloudpack/path-utilities": "^3.0.
|
|
24
|
+
"@ms-cloudpack/path-utilities": "^3.0.3",
|
|
25
25
|
"@ms-cloudpack/task-reporter": "^0.15.0",
|
|
26
26
|
"http-proxy-middleware": "^2.0.6",
|
|
27
27
|
"jsdom": "^26.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@ms-cloudpack/common-types-browser": "^0.5.
|
|
30
|
+
"@ms-cloudpack/common-types-browser": "^0.5.4",
|
|
31
31
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
32
32
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
33
33
|
"@ms-cloudpack/test-utilities": "^0.5.0",
|