@hubspot/cms-dev-server 1.2.46 → 1.2.47
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/dist/.DS_Store +0 -0
- package/dist/index.js +96 -20
- package/dist/run.js +96 -20
- package/package.json +4 -3
- package/types/lib/debugAuth.d.ts +2 -0
- package/types/lib/localComponentsLoader.d.ts +2 -0
- package/types/lib/previewUtils.d.ts +9 -0
- package/types/lib/viteAssetHandler.d.ts +15 -0
- package/types/plugins/hubspotStaticAssetPlugin.d.ts +2 -0
- package/types/plugins/remoteAssetsPlugin.d.ts +7 -0
- package/types/plugins/requestSigningPlugin.d.ts +6 -0
- package/types/routes/createAppServerRoutes.d.ts +5 -0
- package/types/routes/meta.d.ts +0 -2
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1649,7 +1649,7 @@ function trackUsage(action) {
|
|
|
1649
1649
|
eventName: EVENT_NAME,
|
|
1650
1650
|
action,
|
|
1651
1651
|
nodeVersion: getNodeVersionData(),
|
|
1652
|
-
version: "1.2.
|
|
1652
|
+
version: "1.2.47",
|
|
1653
1653
|
os: getPlatform()
|
|
1654
1654
|
};
|
|
1655
1655
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -2412,11 +2412,81 @@ var buildHTMLResponse = (content) => {
|
|
|
2412
2412
|
`;
|
|
2413
2413
|
};
|
|
2414
2414
|
var insertAtEndOfBody = (html, script) => {
|
|
2415
|
-
const insertAt = (baseStr, index, insertStr) => {
|
|
2416
|
-
return `${baseStr.slice(0, index)}${insertStr}${baseStr.slice(index)}`;
|
|
2417
|
-
};
|
|
2418
2415
|
const endOfBodyIndex = html.lastIndexOf("</body>");
|
|
2419
|
-
|
|
2416
|
+
if (endOfBodyIndex === -1) {
|
|
2417
|
+
return html + script;
|
|
2418
|
+
}
|
|
2419
|
+
return html.slice(0, endOfBodyIndex) + script + html.slice(endOfBodyIndex);
|
|
2420
|
+
};
|
|
2421
|
+
var SAFE_URL_PARAM_RE = /^[a-zA-Z0-9@/\-_.]+$/;
|
|
2422
|
+
function escapeHtml(s) {
|
|
2423
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
2424
|
+
}
|
|
2425
|
+
function isSafeUrlParam(value) {
|
|
2426
|
+
return typeof value === "string" && value.length > 0 && SAFE_URL_PARAM_RE.test(value);
|
|
2427
|
+
}
|
|
2428
|
+
function resolveDomain(isLocal, branch) {
|
|
2429
|
+
if (isLocal)
|
|
2430
|
+
return "local.hubspotqa.com";
|
|
2431
|
+
if (branch)
|
|
2432
|
+
return `b-${branch}.dynamic.hsappstatic.net`;
|
|
2433
|
+
return "static.hsappstatic.net";
|
|
2434
|
+
}
|
|
2435
|
+
function resolveProtocol(isLocal) {
|
|
2436
|
+
return isLocal ? "//" : "https://";
|
|
2437
|
+
}
|
|
2438
|
+
function resolveVersion(isLocal, version) {
|
|
2439
|
+
return isLocal ? "static" : version;
|
|
2440
|
+
}
|
|
2441
|
+
function buildStaticAssetUrl(pkg, filePath, isLocal, version, branch) {
|
|
2442
|
+
const protocol = resolveProtocol(isLocal);
|
|
2443
|
+
const resolvedVersion = resolveVersion(isLocal, version);
|
|
2444
|
+
const domain = resolveDomain(isLocal, branch);
|
|
2445
|
+
return `${protocol}${domain}/${pkg}/${resolvedVersion}/${filePath}`;
|
|
2446
|
+
}
|
|
2447
|
+
function normalizeToArray(value) {
|
|
2448
|
+
if (Array.isArray(value))
|
|
2449
|
+
return value;
|
|
2450
|
+
if (value)
|
|
2451
|
+
return [value];
|
|
2452
|
+
return [];
|
|
2453
|
+
}
|
|
2454
|
+
function parseCsvToScriptProperties(csv, branch) {
|
|
2455
|
+
const fields = csv.split(",");
|
|
2456
|
+
if (fields.length !== 4)
|
|
2457
|
+
return null;
|
|
2458
|
+
const [pkg, scriptPath, isLocalStr, version] = fields;
|
|
2459
|
+
return { pkg, scriptPath, version: version || null, isLocal: isLocalStr === "true", branch };
|
|
2460
|
+
}
|
|
2461
|
+
function buildValidatedScriptUrl(props) {
|
|
2462
|
+
const { pkg, scriptPath, version, isLocal, branch } = props;
|
|
2463
|
+
const hasSafePkg = isSafeUrlParam(pkg);
|
|
2464
|
+
const hasSafeScriptPath = isSafeUrlParam(scriptPath);
|
|
2465
|
+
const hasVersionOrIsLocal = isLocal || isSafeUrlParam(version);
|
|
2466
|
+
const hasSafeBranch = branch === null || isSafeUrlParam(branch);
|
|
2467
|
+
if (!hasSafePkg || !hasSafeScriptPath || !hasVersionOrIsLocal || !hasSafeBranch) {
|
|
2468
|
+
return null;
|
|
2469
|
+
}
|
|
2470
|
+
return buildStaticAssetUrl(pkg, scriptPath, isLocal, version, branch);
|
|
2471
|
+
}
|
|
2472
|
+
var addScriptInjectionBootstrapper = (html, query) => {
|
|
2473
|
+
const branchPreviewBuild = query.branchPreviewBuild || null;
|
|
2474
|
+
const topLevelProps = {
|
|
2475
|
+
pkg: query.benderPackage,
|
|
2476
|
+
scriptPath: query.scriptPath,
|
|
2477
|
+
version: query.staticVersion || null,
|
|
2478
|
+
isLocal: query.localAssets === "true",
|
|
2479
|
+
branch: branchPreviewBuild
|
|
2480
|
+
};
|
|
2481
|
+
const injectedProps = normalizeToArray(query.injectedScripts).map((csv) => parseCsvToScriptProperties(csv, branchPreviewBuild)).filter((props) => props !== null);
|
|
2482
|
+
const scriptUrls = [topLevelProps, ...injectedProps].map(buildValidatedScriptUrl).filter((url3) => url3 !== null);
|
|
2483
|
+
if (scriptUrls.length === 0) {
|
|
2484
|
+
return html;
|
|
2485
|
+
}
|
|
2486
|
+
const scriptTags = scriptUrls.map((url3) => `<script data-hs-injected-script src="${escapeHtml(url3)}"></script>`).join("\n ");
|
|
2487
|
+
return insertAtEndOfBody(html, `
|
|
2488
|
+
${scriptTags}
|
|
2489
|
+
`);
|
|
2420
2490
|
};
|
|
2421
2491
|
var addRefreshScript = (html) => {
|
|
2422
2492
|
const refreshScript = `
|
|
@@ -3517,13 +3587,16 @@ var moduleRouteHandler = async (request, response) => {
|
|
|
3517
3587
|
viteServer,
|
|
3518
3588
|
jsRenderingGates
|
|
3519
3589
|
);
|
|
3520
|
-
const html =
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3590
|
+
const html = addScriptInjectionBootstrapper(
|
|
3591
|
+
htmlShell.replace(
|
|
3592
|
+
"<!--headend-->",
|
|
3593
|
+
[
|
|
3594
|
+
cssNeeded,
|
|
3595
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
3596
|
+
].join("\n")
|
|
3597
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml),
|
|
3598
|
+
request.query
|
|
3599
|
+
);
|
|
3527
3600
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
3528
3601
|
} catch (e) {
|
|
3529
3602
|
console.error(e);
|
|
@@ -4152,14 +4225,17 @@ async function modulePreviewRouteHandler(request, response) {
|
|
|
4152
4225
|
jsRenderingGates
|
|
4153
4226
|
);
|
|
4154
4227
|
const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
|
|
4155
|
-
const html =
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4228
|
+
const html = addScriptInjectionBootstrapper(
|
|
4229
|
+
htmlShell.replace(
|
|
4230
|
+
"<!--headend-->",
|
|
4231
|
+
[
|
|
4232
|
+
fullHeightCss,
|
|
4233
|
+
cssNeeded,
|
|
4234
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4235
|
+
].join("\n")
|
|
4236
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml),
|
|
4237
|
+
request.query
|
|
4238
|
+
);
|
|
4163
4239
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4164
4240
|
} catch (e) {
|
|
4165
4241
|
console.error(e);
|
package/dist/run.js
CHANGED
|
@@ -2256,7 +2256,7 @@ function trackUsage(action) {
|
|
|
2256
2256
|
eventName: EVENT_NAME,
|
|
2257
2257
|
action,
|
|
2258
2258
|
nodeVersion: getNodeVersionData(),
|
|
2259
|
-
version: "1.2.
|
|
2259
|
+
version: "1.2.47",
|
|
2260
2260
|
os: getPlatform()
|
|
2261
2261
|
};
|
|
2262
2262
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -3019,11 +3019,81 @@ var buildHTMLResponse = (content) => {
|
|
|
3019
3019
|
`;
|
|
3020
3020
|
};
|
|
3021
3021
|
var insertAtEndOfBody = (html, script) => {
|
|
3022
|
-
const insertAt = (baseStr, index, insertStr) => {
|
|
3023
|
-
return `${baseStr.slice(0, index)}${insertStr}${baseStr.slice(index)}`;
|
|
3024
|
-
};
|
|
3025
3022
|
const endOfBodyIndex = html.lastIndexOf("</body>");
|
|
3026
|
-
|
|
3023
|
+
if (endOfBodyIndex === -1) {
|
|
3024
|
+
return html + script;
|
|
3025
|
+
}
|
|
3026
|
+
return html.slice(0, endOfBodyIndex) + script + html.slice(endOfBodyIndex);
|
|
3027
|
+
};
|
|
3028
|
+
var SAFE_URL_PARAM_RE = /^[a-zA-Z0-9@/\-_.]+$/;
|
|
3029
|
+
function escapeHtml(s) {
|
|
3030
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
3031
|
+
}
|
|
3032
|
+
function isSafeUrlParam(value) {
|
|
3033
|
+
return typeof value === "string" && value.length > 0 && SAFE_URL_PARAM_RE.test(value);
|
|
3034
|
+
}
|
|
3035
|
+
function resolveDomain(isLocal, branch) {
|
|
3036
|
+
if (isLocal)
|
|
3037
|
+
return "local.hubspotqa.com";
|
|
3038
|
+
if (branch)
|
|
3039
|
+
return `b-${branch}.dynamic.hsappstatic.net`;
|
|
3040
|
+
return "static.hsappstatic.net";
|
|
3041
|
+
}
|
|
3042
|
+
function resolveProtocol(isLocal) {
|
|
3043
|
+
return isLocal ? "//" : "https://";
|
|
3044
|
+
}
|
|
3045
|
+
function resolveVersion(isLocal, version) {
|
|
3046
|
+
return isLocal ? "static" : version;
|
|
3047
|
+
}
|
|
3048
|
+
function buildStaticAssetUrl(pkg, filePath, isLocal, version, branch) {
|
|
3049
|
+
const protocol = resolveProtocol(isLocal);
|
|
3050
|
+
const resolvedVersion = resolveVersion(isLocal, version);
|
|
3051
|
+
const domain2 = resolveDomain(isLocal, branch);
|
|
3052
|
+
return `${protocol}${domain2}/${pkg}/${resolvedVersion}/${filePath}`;
|
|
3053
|
+
}
|
|
3054
|
+
function normalizeToArray(value) {
|
|
3055
|
+
if (Array.isArray(value))
|
|
3056
|
+
return value;
|
|
3057
|
+
if (value)
|
|
3058
|
+
return [value];
|
|
3059
|
+
return [];
|
|
3060
|
+
}
|
|
3061
|
+
function parseCsvToScriptProperties(csv, branch) {
|
|
3062
|
+
const fields = csv.split(",");
|
|
3063
|
+
if (fields.length !== 4)
|
|
3064
|
+
return null;
|
|
3065
|
+
const [pkg, scriptPath, isLocalStr, version] = fields;
|
|
3066
|
+
return { pkg, scriptPath, version: version || null, isLocal: isLocalStr === "true", branch };
|
|
3067
|
+
}
|
|
3068
|
+
function buildValidatedScriptUrl(props) {
|
|
3069
|
+
const { pkg, scriptPath, version, isLocal, branch } = props;
|
|
3070
|
+
const hasSafePkg = isSafeUrlParam(pkg);
|
|
3071
|
+
const hasSafeScriptPath = isSafeUrlParam(scriptPath);
|
|
3072
|
+
const hasVersionOrIsLocal = isLocal || isSafeUrlParam(version);
|
|
3073
|
+
const hasSafeBranch = branch === null || isSafeUrlParam(branch);
|
|
3074
|
+
if (!hasSafePkg || !hasSafeScriptPath || !hasVersionOrIsLocal || !hasSafeBranch) {
|
|
3075
|
+
return null;
|
|
3076
|
+
}
|
|
3077
|
+
return buildStaticAssetUrl(pkg, scriptPath, isLocal, version, branch);
|
|
3078
|
+
}
|
|
3079
|
+
var addScriptInjectionBootstrapper = (html, query) => {
|
|
3080
|
+
const branchPreviewBuild = query.branchPreviewBuild || null;
|
|
3081
|
+
const topLevelProps = {
|
|
3082
|
+
pkg: query.benderPackage,
|
|
3083
|
+
scriptPath: query.scriptPath,
|
|
3084
|
+
version: query.staticVersion || null,
|
|
3085
|
+
isLocal: query.localAssets === "true",
|
|
3086
|
+
branch: branchPreviewBuild
|
|
3087
|
+
};
|
|
3088
|
+
const injectedProps = normalizeToArray(query.injectedScripts).map((csv) => parseCsvToScriptProperties(csv, branchPreviewBuild)).filter((props) => props !== null);
|
|
3089
|
+
const scriptUrls = [topLevelProps, ...injectedProps].map(buildValidatedScriptUrl).filter((url3) => url3 !== null);
|
|
3090
|
+
if (scriptUrls.length === 0) {
|
|
3091
|
+
return html;
|
|
3092
|
+
}
|
|
3093
|
+
const scriptTags = scriptUrls.map((url3) => `<script data-hs-injected-script src="${escapeHtml(url3)}"></script>`).join("\n ");
|
|
3094
|
+
return insertAtEndOfBody(html, `
|
|
3095
|
+
${scriptTags}
|
|
3096
|
+
`);
|
|
3027
3097
|
};
|
|
3028
3098
|
var addRefreshScript = (html) => {
|
|
3029
3099
|
const refreshScript = `
|
|
@@ -4124,13 +4194,16 @@ var moduleRouteHandler = async (request, response) => {
|
|
|
4124
4194
|
viteServer,
|
|
4125
4195
|
jsRenderingGates
|
|
4126
4196
|
);
|
|
4127
|
-
const html =
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4197
|
+
const html = addScriptInjectionBootstrapper(
|
|
4198
|
+
htmlShell.replace(
|
|
4199
|
+
"<!--headend-->",
|
|
4200
|
+
[
|
|
4201
|
+
cssNeeded,
|
|
4202
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4203
|
+
].join("\n")
|
|
4204
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml),
|
|
4205
|
+
request.query
|
|
4206
|
+
);
|
|
4134
4207
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4135
4208
|
} catch (e) {
|
|
4136
4209
|
console.error(e);
|
|
@@ -4759,14 +4832,17 @@ async function modulePreviewRouteHandler(request, response) {
|
|
|
4759
4832
|
jsRenderingGates
|
|
4760
4833
|
);
|
|
4761
4834
|
const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
|
|
4762
|
-
const html =
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4835
|
+
const html = addScriptInjectionBootstrapper(
|
|
4836
|
+
htmlShell.replace(
|
|
4837
|
+
"<!--headend-->",
|
|
4838
|
+
[
|
|
4839
|
+
fullHeightCss,
|
|
4840
|
+
cssNeeded,
|
|
4841
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4842
|
+
].join("\n")
|
|
4843
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml),
|
|
4844
|
+
request.query
|
|
4845
|
+
);
|
|
4770
4846
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4771
4847
|
} catch (e) {
|
|
4772
4848
|
console.error(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.47",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@babel/parser": "^7.25.3",
|
|
30
30
|
"@babel/traverse": "^7.25.3",
|
|
31
31
|
"@babel/types": "^7.25.2",
|
|
32
|
-
"@hubspot/cms-components": "^1.2.
|
|
32
|
+
"@hubspot/cms-components": "^1.2.47",
|
|
33
33
|
"@hubspot/local-dev-lib": "5.8.2",
|
|
34
34
|
"@inquirer/select": "^2.0.0",
|
|
35
35
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"copyfiles": "^2.4.1",
|
|
87
87
|
"esbuild": "^0.16.17",
|
|
88
88
|
"fs-extra": "^11.2.0",
|
|
89
|
+
"msw": "2.13.3",
|
|
89
90
|
"nodemon": "^2.0.15",
|
|
90
91
|
"postcss": "^8.4.47",
|
|
91
92
|
"publint": "^0.2.7",
|
|
@@ -133,5 +134,5 @@
|
|
|
133
134
|
"publishConfig": {
|
|
134
135
|
"access": "public"
|
|
135
136
|
},
|
|
136
|
-
"gitHead": "
|
|
137
|
+
"gitHead": "da7fa942c738e49e04bca8dd01b96691eb1c70a3"
|
|
137
138
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export declare const removePreviewPrefix: (t: string) => string;
|
|
2
2
|
export declare const getPreviewUrl: (request: any, queryParams: any) => string;
|
|
3
3
|
export declare const buildHTMLResponse: (content: any) => string;
|
|
4
|
+
/**
|
|
5
|
+
* HTML-encodes characters that could allow a URL to break out of an attribute value and inject
|
|
6
|
+
* markup into the response. Applied to every URL placed in a `src` attribute so that even if
|
|
7
|
+
* `isSafeUrlParam` validation is bypassed or a URL is constructed from a future code path that
|
|
8
|
+
* skips it, the injected script tag cannot introduce XSS.
|
|
9
|
+
*/
|
|
10
|
+
export declare function escapeHtml(s: string): string;
|
|
11
|
+
export declare function buildStaticAssetUrl(pkg: string, filePath: string, isLocal: boolean, version: string | null, branch: string | null): string;
|
|
12
|
+
export declare const addScriptInjectionBootstrapper: (html: string, query: Record<string, any>) => string;
|
|
4
13
|
export declare const addRefreshScript: (html: string) => string;
|
|
5
14
|
export declare function buildDevFileHashTable(src: string, dest: string, filePaths: string[]): {};
|
|
6
15
|
export declare type ThemePreviewOptions = {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViteDevServer } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Processes HTML to find remote assets and replace with Vite-managed URLs
|
|
4
|
+
*/
|
|
5
|
+
export declare function processRemoteAssets(html: string, viteServer: ViteDevServer): Promise<string>;
|
|
6
|
+
/**
|
|
7
|
+
* Vite plugin to handle remote assets
|
|
8
|
+
*/
|
|
9
|
+
export declare function remoteAssetsPlugin(): {
|
|
10
|
+
name: string;
|
|
11
|
+
apply: "serve";
|
|
12
|
+
configResolved(config: any): void;
|
|
13
|
+
resolveId(id: string): string;
|
|
14
|
+
load(id: string): Promise<string>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
export declare function handleGetModulePages(req: Request, res: Response, next: NextFunction): Promise<Response<any, Record<string, any>>>;
|
|
3
|
+
export declare function handleOpenFile(req: Request, res: Response, next: NextFunction): Response<any, Record<string, any>>;
|
|
4
|
+
export declare function createAppServerRoutes(): import("express-serve-static-core").Router;
|
|
5
|
+
export default createAppServerRoutes;
|
package/types/routes/meta.d.ts
DELETED