@hubspot/cms-dev-server 1.2.46 → 1.2.49
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/README.md +13 -1
- package/dist/.DS_Store +0 -0
- package/dist/generateJsonFromJsx.js +2 -1
- package/dist/index.js +98 -21
- package/dist/run.js +98 -21
- package/dist/validateFieldsCli.js +1324 -0
- package/package.json +6 -4
- 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/renderModule.d.ts +14 -0
- package/types/lib/viteAssetHandler.d.ts +15 -0
- package/types/lib/watchFieldsUpdates.d.ts +1 -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/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
# cms-dev-server
|
|
2
2
|
|
|
3
|
-
Local
|
|
3
|
+
Local development server for JS rendering, published as `@hubspot/cms-dev-server` and invoked via the HubSpot CLI. Handles proxying pages, serving/hot-reloading a customer's JS project, module/HubL routing, and a Storybook mode.
|
|
4
|
+
|
|
5
|
+
See [Set up local development](../docs/local-dev-setup.md) for how this is normally run from the monorepo root (`bend yarn start`/`bend yarn watch`), and [Utility Scripts](../docs/utility-scripts.md) for the full command reference.
|
|
6
|
+
|
|
7
|
+
## Scripts
|
|
8
|
+
|
|
9
|
+
- `dev` / `dev-inspect` — run the dev server directly (with `--inspect` for the latter)
|
|
10
|
+
- `start` / `start-inspect` — same, via the built output
|
|
11
|
+
- `build` / `build:watch` / `build-types` — build the package and its type declarations
|
|
12
|
+
- `es-watch` — watch mode for the ES build
|
|
13
|
+
- `runBuild` — used by `bend yarn run-at-resources`/`run-at-resources-unified` to point the dev server at a fixture project
|
|
14
|
+
- `test` / `test:watch` — vitest
|
|
15
|
+
- `publint` — validates the published package shape before release
|
package/dist/.DS_Store
ADDED
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -1202,7 +1202,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
1202
1202
|
origin,
|
|
1203
1203
|
hmr: {
|
|
1204
1204
|
protocol: sslEnabled ? "wss" : void 0
|
|
1205
|
-
}
|
|
1205
|
+
},
|
|
1206
|
+
allowedHosts: ["localhost", "hslocal.net", ...additionalMkcertHosts]
|
|
1206
1207
|
},
|
|
1207
1208
|
root: webRoot,
|
|
1208
1209
|
...ssrAndOptimizeDep,
|
|
@@ -1649,7 +1650,7 @@ function trackUsage(action) {
|
|
|
1649
1650
|
eventName: EVENT_NAME,
|
|
1650
1651
|
action,
|
|
1651
1652
|
nodeVersion: getNodeVersionData(),
|
|
1652
|
-
version: "1.2.
|
|
1653
|
+
version: "1.2.49",
|
|
1653
1654
|
os: getPlatform()
|
|
1654
1655
|
};
|
|
1655
1656
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -2412,11 +2413,81 @@ var buildHTMLResponse = (content) => {
|
|
|
2412
2413
|
`;
|
|
2413
2414
|
};
|
|
2414
2415
|
var insertAtEndOfBody = (html, script) => {
|
|
2415
|
-
const insertAt = (baseStr, index, insertStr) => {
|
|
2416
|
-
return `${baseStr.slice(0, index)}${insertStr}${baseStr.slice(index)}`;
|
|
2417
|
-
};
|
|
2418
2416
|
const endOfBodyIndex = html.lastIndexOf("</body>");
|
|
2419
|
-
|
|
2417
|
+
if (endOfBodyIndex === -1) {
|
|
2418
|
+
return html + script;
|
|
2419
|
+
}
|
|
2420
|
+
return html.slice(0, endOfBodyIndex) + script + html.slice(endOfBodyIndex);
|
|
2421
|
+
};
|
|
2422
|
+
var SAFE_URL_PARAM_RE = /^[a-zA-Z0-9@/\-_.]+$/;
|
|
2423
|
+
function escapeHtml(s) {
|
|
2424
|
+
return s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
2425
|
+
}
|
|
2426
|
+
function isSafeUrlParam(value) {
|
|
2427
|
+
return typeof value === "string" && value.length > 0 && SAFE_URL_PARAM_RE.test(value);
|
|
2428
|
+
}
|
|
2429
|
+
function resolveDomain(isLocal, branch) {
|
|
2430
|
+
if (isLocal)
|
|
2431
|
+
return "local.hubspotqa.com";
|
|
2432
|
+
if (branch)
|
|
2433
|
+
return `b-${branch}.dynamic.hsappstatic.net`;
|
|
2434
|
+
return "static.hsappstatic.net";
|
|
2435
|
+
}
|
|
2436
|
+
function resolveProtocol(isLocal) {
|
|
2437
|
+
return isLocal ? "//" : "https://";
|
|
2438
|
+
}
|
|
2439
|
+
function resolveVersion(isLocal, version) {
|
|
2440
|
+
return isLocal ? "static" : version;
|
|
2441
|
+
}
|
|
2442
|
+
function buildStaticAssetUrl(pkg, filePath, isLocal, version, branch) {
|
|
2443
|
+
const protocol = resolveProtocol(isLocal);
|
|
2444
|
+
const resolvedVersion = resolveVersion(isLocal, version);
|
|
2445
|
+
const domain = resolveDomain(isLocal, branch);
|
|
2446
|
+
return `${protocol}${domain}/${pkg}/${resolvedVersion}/${filePath}`;
|
|
2447
|
+
}
|
|
2448
|
+
function normalizeToArray(value) {
|
|
2449
|
+
if (Array.isArray(value))
|
|
2450
|
+
return value;
|
|
2451
|
+
if (value)
|
|
2452
|
+
return [value];
|
|
2453
|
+
return [];
|
|
2454
|
+
}
|
|
2455
|
+
function parseCsvToScriptProperties(csv, branch) {
|
|
2456
|
+
const fields = csv.split(",");
|
|
2457
|
+
if (fields.length !== 4)
|
|
2458
|
+
return null;
|
|
2459
|
+
const [pkg, scriptPath, isLocalStr, version] = fields;
|
|
2460
|
+
return { pkg, scriptPath, version: version || null, isLocal: isLocalStr === "true", branch };
|
|
2461
|
+
}
|
|
2462
|
+
function buildValidatedScriptUrl(props) {
|
|
2463
|
+
const { pkg, scriptPath, version, isLocal, branch } = props;
|
|
2464
|
+
const hasSafePkg = isSafeUrlParam(pkg);
|
|
2465
|
+
const hasSafeScriptPath = isSafeUrlParam(scriptPath);
|
|
2466
|
+
const hasVersionOrIsLocal = isLocal || isSafeUrlParam(version);
|
|
2467
|
+
const hasSafeBranch = branch === null || isSafeUrlParam(branch);
|
|
2468
|
+
if (!hasSafePkg || !hasSafeScriptPath || !hasVersionOrIsLocal || !hasSafeBranch) {
|
|
2469
|
+
return null;
|
|
2470
|
+
}
|
|
2471
|
+
return buildStaticAssetUrl(pkg, scriptPath, isLocal, version, branch);
|
|
2472
|
+
}
|
|
2473
|
+
var addScriptInjectionBootstrapper = (html, query) => {
|
|
2474
|
+
const branchPreviewBuild = query.branchPreviewBuild || null;
|
|
2475
|
+
const topLevelProps = {
|
|
2476
|
+
pkg: query.benderPackage,
|
|
2477
|
+
scriptPath: query.scriptPath,
|
|
2478
|
+
version: query.staticVersion || null,
|
|
2479
|
+
isLocal: query.localAssets === "true",
|
|
2480
|
+
branch: branchPreviewBuild
|
|
2481
|
+
};
|
|
2482
|
+
const injectedProps = normalizeToArray(query.injectedScripts).map((csv) => parseCsvToScriptProperties(csv, branchPreviewBuild)).filter((props) => props !== null);
|
|
2483
|
+
const scriptUrls = [topLevelProps, ...injectedProps].map(buildValidatedScriptUrl).filter((url3) => url3 !== null);
|
|
2484
|
+
if (scriptUrls.length === 0) {
|
|
2485
|
+
return html;
|
|
2486
|
+
}
|
|
2487
|
+
const scriptTags = scriptUrls.map((url3) => `<script data-hs-injected-script src="${escapeHtml(url3)}"></script>`).join("\n ");
|
|
2488
|
+
return insertAtEndOfBody(html, `
|
|
2489
|
+
${scriptTags}
|
|
2490
|
+
`);
|
|
2420
2491
|
};
|
|
2421
2492
|
var addRefreshScript = (html) => {
|
|
2422
2493
|
const refreshScript = `
|
|
@@ -3517,13 +3588,16 @@ var moduleRouteHandler = async (request, response) => {
|
|
|
3517
3588
|
viteServer,
|
|
3518
3589
|
jsRenderingGates
|
|
3519
3590
|
);
|
|
3520
|
-
const html =
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3591
|
+
const html = addScriptInjectionBootstrapper(
|
|
3592
|
+
htmlShell.replace(
|
|
3593
|
+
"<!--headend-->",
|
|
3594
|
+
[
|
|
3595
|
+
cssNeeded,
|
|
3596
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
3597
|
+
].join("\n")
|
|
3598
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml),
|
|
3599
|
+
request.query
|
|
3600
|
+
);
|
|
3527
3601
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
3528
3602
|
} catch (e) {
|
|
3529
3603
|
console.error(e);
|
|
@@ -4152,14 +4226,17 @@ async function modulePreviewRouteHandler(request, response) {
|
|
|
4152
4226
|
jsRenderingGates
|
|
4153
4227
|
);
|
|
4154
4228
|
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
|
-
|
|
4229
|
+
const html = addScriptInjectionBootstrapper(
|
|
4230
|
+
htmlShell.replace(
|
|
4231
|
+
"<!--headend-->",
|
|
4232
|
+
[
|
|
4233
|
+
fullHeightCss,
|
|
4234
|
+
cssNeeded,
|
|
4235
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
4236
|
+
].join("\n")
|
|
4237
|
+
).replace(`<!--ssr-outlet-->`, renderedHtml),
|
|
4238
|
+
request.query
|
|
4239
|
+
);
|
|
4163
4240
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
4164
4241
|
} catch (e) {
|
|
4165
4242
|
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.49",
|
|
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);
|
|
@@ -5191,7 +5267,8 @@ Custom origin: ${process.env.VITE_ORIGIN}
|
|
|
5191
5267
|
origin,
|
|
5192
5268
|
hmr: {
|
|
5193
5269
|
protocol: sslEnabled ? "wss" : void 0
|
|
5194
|
-
}
|
|
5270
|
+
},
|
|
5271
|
+
allowedHosts: ["localhost", "hslocal.net", ...additionalMkcertHosts]
|
|
5195
5272
|
},
|
|
5196
5273
|
root: webRoot2,
|
|
5197
5274
|
...ssrAndOptimizeDep,
|