@hubspot/cms-dev-server 1.0.31 → 1.0.33

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/index.js CHANGED
@@ -1638,7 +1638,7 @@ function trackUsage(action) {
1638
1638
  eventName: EVENT_NAME,
1639
1639
  action,
1640
1640
  nodeVersion: getNodeVersionData(),
1641
- version: "1.0.31",
1641
+ version: "1.0.33",
1642
1642
  os: getPlatform()
1643
1643
  };
1644
1644
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -2912,6 +2912,8 @@ ${result}`;
2912
2912
 
2913
2913
  // src/lib/renderModulePreview.ts
2914
2914
  import { http as hsCliHttp7 } from "@hubspot/local-dev-lib/http";
2915
+ import { getAccountConfig as getAccountConfig2 } from "@hubspot/local-dev-lib/config";
2916
+ import { accessTokenForPersonalAccessKey } from "@hubspot/local-dev-lib/personalAccessKey";
2915
2917
  import jsdom from "jsdom";
2916
2918
  var { JSDOM } = jsdom;
2917
2919
  async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
@@ -2960,14 +2962,18 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
2960
2962
  const cssNeeded = Array.from(dom.window.document.querySelectorAll("style")).map((element) => element.outerHTML).join("");
2961
2963
  return { html: modulePreviewContent, cssNeeded };
2962
2964
  }
2963
- async function signUrl(authedPortalId, unsignedUrl) {
2965
+ async function signUrl(authedPortalId, unsignedUrl, requestBody) {
2966
+ const formData = {
2967
+ module: [JSON.stringify(requestBody)]
2968
+ };
2964
2969
  const request2 = {
2965
2970
  unsignedUrl,
2966
- httpMethod: "POST"
2971
+ httpMethod: "POST",
2972
+ formData
2967
2973
  };
2968
2974
  try {
2969
2975
  const response = await hsCliHttp7.post(authedPortalId, {
2970
- url: "/url-signer-rest/v1/signing",
2976
+ url: "/url-signer-rest/v1/signing/for-form",
2971
2977
  headers: {
2972
2978
  "Content-Type": "application/json",
2973
2979
  Accept: "application/json"
@@ -3037,31 +3043,41 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3037
3043
  };
3038
3044
  const queryParams = new URLSearchParams({
3039
3045
  hsLocalProxy: `${true}`,
3040
- localProxySchemaVersion: "2"
3046
+ localProxySchemaVersion: "2",
3047
+ portalId: `${authedPortalId}`
3041
3048
  });
3042
3049
  const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
3043
3050
  process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
3044
3051
  const previewDomain = `https://${authedPortalId}.hubspotpreview${authedEnv === "qa" ? "qa" : ""}-${authedHublet}.com`;
3045
3052
  const templatePreviewPath = `_hcms/preview/template/multiform`;
3046
- const unsignedUrl = `${previewDomain}/${templatePreviewPath}?portalId=${authedPortalId}`;
3047
- const signedUrl = await signUrl(authedPortalId, unsignedUrl);
3048
- const signedUrlObj = new URL(signedUrl);
3049
- queryParams.forEach((value, key) => {
3050
- signedUrlObj.searchParams.append(key, value);
3051
- });
3052
- signedUrlObj.searchParams.delete("portalId");
3053
- const finalUrl = signedUrlObj.toString();
3054
- const templatePreview = (await hsCliHttp7.post(authedPortalId, {
3055
- url: finalUrl,
3056
- headers: {
3057
- ["content-type"]: "application/x-www-form-urlencoded",
3058
- ["Accept"]: "text/html",
3059
- referer: `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
3060
- cookie: cookieValue,
3061
- "User-Agent": "HubSpot CMS Dev Server"
3062
- },
3063
- data: `module=${encodeURIComponent(JSON.stringify(localModule))}`
3064
- })).data;
3053
+ const unsignedUrl = `${previewDomain}/${templatePreviewPath}?${queryParams}`;
3054
+ const signedUrl = await signUrl(authedPortalId, unsignedUrl, localModule);
3055
+ const postBody = `module=${encodeURIComponent(JSON.stringify(localModule))}`;
3056
+ let templatePreview;
3057
+ try {
3058
+ const authHeaders = {};
3059
+ const accountConfig = getAccountConfig2(authedPortalId);
3060
+ if (accountConfig && accountConfig.authType === "personalaccesskey") {
3061
+ const accessToken = await accessTokenForPersonalAccessKey(authedPortalId);
3062
+ authHeaders["Authorization"] = `Bearer ${accessToken}`;
3063
+ }
3064
+ const response = await fetch(signedUrl, {
3065
+ method: "POST",
3066
+ headers: {
3067
+ "content-type": "application/x-www-form-urlencoded",
3068
+ Accept: "text/html",
3069
+ referer: `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
3070
+ cookie: cookieValue,
3071
+ "User-Agent": "HubSpot CMS Dev Server",
3072
+ ...authHeaders
3073
+ },
3074
+ body: postBody
3075
+ });
3076
+ templatePreview = await response.text();
3077
+ } catch (error) {
3078
+ console.error("Preview request failed:", error);
3079
+ throw error;
3080
+ }
3065
3081
  if (currentHubApiDomainOverride) {
3066
3082
  process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
3067
3083
  } else {
@@ -3866,7 +3882,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
3866
3882
  }
3867
3883
 
3868
3884
  // src/routes/proxyPathPageResourceRedirect.ts
3869
- import fetch from "node-fetch";
3885
+ import fetch2 from "node-fetch";
3870
3886
  var HCMS_PATH2 = "/_hcms/";
3871
3887
  var HS_FS_PATH2 = "/hs-fs/";
3872
3888
  var HUB_FS_PATH2 = "/hubfs/";
@@ -3896,11 +3912,11 @@ function proxyPathPageResourceRedirect(req, res, next) {
3896
3912
  return;
3897
3913
  }
3898
3914
  const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
3899
- fetch(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
3915
+ fetch2(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
3900
3916
  }
3901
3917
 
3902
3918
  // src/routes/proxyServerlessHandler.ts
3903
- import fetch2 from "node-fetch";
3919
+ import fetch3 from "node-fetch";
3904
3920
  var localDomains = ["localhost", "hslocal.net"];
3905
3921
  function proxyServerlessRequest(req, res, next) {
3906
3922
  const { method, headers } = req;
@@ -3953,14 +3969,14 @@ function proxyServerlessRequest(req, res, next) {
3953
3969
  case "POST":
3954
3970
  case "DELETE":
3955
3971
  case "PUT":
3956
- fetch2(urlToProxy, {
3972
+ fetch3(urlToProxy, {
3957
3973
  method,
3958
3974
  body,
3959
3975
  headers: headersToPass
3960
3976
  }).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
3961
3977
  break;
3962
3978
  default:
3963
- fetch2(urlToProxy, {
3979
+ fetch3(urlToProxy, {
3964
3980
  headers: headersToPass
3965
3981
  }).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
3966
3982
  }
@@ -4778,7 +4794,7 @@ async function getJsRenderingGates(portalId, env, personalAccessKey) {
4778
4794
  import {
4779
4795
  getEnv as getEnv3,
4780
4796
  getAccountId as getAccountId4,
4781
- getAccountConfig as getAccountConfig2,
4797
+ getAccountConfig as getAccountConfig3,
4782
4798
  loadConfig,
4783
4799
  validateConfig
4784
4800
  } from "@hubspot/local-dev-lib/config";
@@ -5348,7 +5364,7 @@ async function createDevServer(webRoot, storybook, hubspotCliConfigPathOption, h
5348
5364
  );
5349
5365
  }
5350
5366
  authedEnv = env;
5351
- personalAccessKey = getAccountConfig2(authedPortalId) && getAccountConfig2(authedPortalId).personalAccessKey;
5367
+ personalAccessKey = getAccountConfig3(authedPortalId) && getAccountConfig3(authedPortalId).personalAccessKey;
5352
5368
  if (!authedPortalId && hubspotCliAccountNameOption) {
5353
5369
  console.error(
5354
5370
  `Couldn't find ${hubspotCliAccountNameOption} in your hubspot.config.yaml`
package/dist/run.js CHANGED
@@ -2166,7 +2166,7 @@ function trackUsage(action) {
2166
2166
  eventName: EVENT_NAME,
2167
2167
  action,
2168
2168
  nodeVersion: getNodeVersionData(),
2169
- version: "1.0.31",
2169
+ version: "1.0.33",
2170
2170
  os: getPlatform()
2171
2171
  };
2172
2172
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -3440,6 +3440,8 @@ ${result}`;
3440
3440
 
3441
3441
  // src/lib/renderModulePreview.ts
3442
3442
  import { http as hsCliHttp7 } from "@hubspot/local-dev-lib/http";
3443
+ import { getAccountConfig as getAccountConfig3 } from "@hubspot/local-dev-lib/config";
3444
+ import { accessTokenForPersonalAccessKey } from "@hubspot/local-dev-lib/personalAccessKey";
3443
3445
  import jsdom from "jsdom";
3444
3446
  var { JSDOM } = jsdom;
3445
3447
  async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv, cookieValue) {
@@ -3488,14 +3490,18 @@ async function renderRemoteModulePreview(modulePath, authedPortalId, authedEnv,
3488
3490
  const cssNeeded = Array.from(dom.window.document.querySelectorAll("style")).map((element) => element.outerHTML).join("");
3489
3491
  return { html: modulePreviewContent, cssNeeded };
3490
3492
  }
3491
- async function signUrl(authedPortalId, unsignedUrl) {
3493
+ async function signUrl(authedPortalId, unsignedUrl, requestBody) {
3494
+ const formData = {
3495
+ module: [JSON.stringify(requestBody)]
3496
+ };
3492
3497
  const request2 = {
3493
3498
  unsignedUrl,
3494
- httpMethod: "POST"
3499
+ httpMethod: "POST",
3500
+ formData
3495
3501
  };
3496
3502
  try {
3497
3503
  const response = await hsCliHttp7.post(authedPortalId, {
3498
- url: "/url-signer-rest/v1/signing",
3504
+ url: "/url-signer-rest/v1/signing/for-form",
3499
3505
  headers: {
3500
3506
  "Content-Type": "application/json",
3501
3507
  Accept: "application/json"
@@ -3565,31 +3571,41 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3565
3571
  };
3566
3572
  const queryParams = new URLSearchParams({
3567
3573
  hsLocalProxy: `${true}`,
3568
- localProxySchemaVersion: "2"
3574
+ localProxySchemaVersion: "2",
3575
+ portalId: `${authedPortalId}`
3569
3576
  });
3570
3577
  const currentHubApiDomainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
3571
3578
  process.env.HUBAPI_DOMAIN_OVERRIDE = `api.hubspot`;
3572
3579
  const previewDomain = `https://${authedPortalId}.hubspotpreview${authedEnv === "qa" ? "qa" : ""}-${authedHublet}.com`;
3573
3580
  const templatePreviewPath = `_hcms/preview/template/multiform`;
3574
- const unsignedUrl = `${previewDomain}/${templatePreviewPath}?portalId=${authedPortalId}`;
3575
- const signedUrl = await signUrl(authedPortalId, unsignedUrl);
3576
- const signedUrlObj = new URL(signedUrl);
3577
- queryParams.forEach((value, key) => {
3578
- signedUrlObj.searchParams.append(key, value);
3579
- });
3580
- signedUrlObj.searchParams.delete("portalId");
3581
- const finalUrl = signedUrlObj.toString();
3582
- const templatePreview = (await hsCliHttp7.post(authedPortalId, {
3583
- url: finalUrl,
3584
- headers: {
3585
- ["content-type"]: "application/x-www-form-urlencoded",
3586
- ["Accept"]: "text/html",
3587
- referer: `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
3588
- cookie: cookieValue,
3589
- "User-Agent": "HubSpot CMS Dev Server"
3590
- },
3591
- data: `module=${encodeURIComponent(JSON.stringify(localModule))}`
3592
- })).data;
3581
+ const unsignedUrl = `${previewDomain}/${templatePreviewPath}?${queryParams}`;
3582
+ const signedUrl = await signUrl(authedPortalId, unsignedUrl, localModule);
3583
+ const postBody = `module=${encodeURIComponent(JSON.stringify(localModule))}`;
3584
+ let templatePreview;
3585
+ try {
3586
+ const authHeaders = {};
3587
+ const accountConfig = getAccountConfig3(authedPortalId);
3588
+ if (accountConfig && accountConfig.authType === "personalaccesskey") {
3589
+ const accessToken = await accessTokenForPersonalAccessKey(authedPortalId);
3590
+ authHeaders["Authorization"] = `Bearer ${accessToken}`;
3591
+ }
3592
+ const response = await fetch(signedUrl, {
3593
+ method: "POST",
3594
+ headers: {
3595
+ "content-type": "application/x-www-form-urlencoded",
3596
+ Accept: "text/html",
3597
+ referer: `https://api.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
3598
+ cookie: cookieValue,
3599
+ "User-Agent": "HubSpot CMS Dev Server",
3600
+ ...authHeaders
3601
+ },
3602
+ body: postBody
3603
+ });
3604
+ templatePreview = await response.text();
3605
+ } catch (error) {
3606
+ console.error("Preview request failed:", error);
3607
+ throw error;
3608
+ }
3593
3609
  if (currentHubApiDomainOverride) {
3594
3610
  process.env.HUBAPI_DOMAIN_OVERRIDE = currentHubApiDomainOverride;
3595
3611
  } else {
@@ -4394,7 +4410,7 @@ async function proxyPathPageRouteHandler(request2, response, next) {
4394
4410
  }
4395
4411
 
4396
4412
  // src/routes/proxyPathPageResourceRedirect.ts
4397
- import fetch from "node-fetch";
4413
+ import fetch2 from "node-fetch";
4398
4414
  var HCMS_PATH2 = "/_hcms/";
4399
4415
  var HS_FS_PATH2 = "/hs-fs/";
4400
4416
  var HUB_FS_PATH2 = "/hubfs/";
@@ -4424,11 +4440,11 @@ function proxyPathPageResourceRedirect(req, res, next) {
4424
4440
  return;
4425
4441
  }
4426
4442
  const urlToProxy = `https://${proxyPageUrl.host}${req.url}`;
4427
- fetch(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
4443
+ fetch2(urlToProxy).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
4428
4444
  }
4429
4445
 
4430
4446
  // src/routes/proxyServerlessHandler.ts
4431
- import fetch2 from "node-fetch";
4447
+ import fetch3 from "node-fetch";
4432
4448
  var localDomains = ["localhost", "hslocal.net"];
4433
4449
  function proxyServerlessRequest(req, res, next) {
4434
4450
  const { method, headers } = req;
@@ -4481,14 +4497,14 @@ function proxyServerlessRequest(req, res, next) {
4481
4497
  case "POST":
4482
4498
  case "DELETE":
4483
4499
  case "PUT":
4484
- fetch2(urlToProxy, {
4500
+ fetch3(urlToProxy, {
4485
4501
  method,
4486
4502
  body,
4487
4503
  headers: headersToPass
4488
4504
  }).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
4489
4505
  break;
4490
4506
  default:
4491
- fetch2(urlToProxy, {
4507
+ fetch3(urlToProxy, {
4492
4508
  headers: headersToPass
4493
4509
  }).then((response) => response.body.pipe(res)).catch((err) => console.log(err));
4494
4510
  }
@@ -5518,7 +5534,7 @@ async function getJsRenderingGates(portalId, env2, personalAccessKey) {
5518
5534
  import {
5519
5535
  getEnv as getEnv3,
5520
5536
  getAccountId as getAccountId4,
5521
- getAccountConfig as getAccountConfig3,
5537
+ getAccountConfig as getAccountConfig4,
5522
5538
  loadConfig,
5523
5539
  validateConfig
5524
5540
  } from "@hubspot/local-dev-lib/config";
@@ -6088,7 +6104,7 @@ async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2
6088
6104
  );
6089
6105
  }
6090
6106
  authedEnv = env2;
6091
- personalAccessKey = getAccountConfig3(authedPortalId) && getAccountConfig3(authedPortalId).personalAccessKey;
6107
+ personalAccessKey = getAccountConfig4(authedPortalId) && getAccountConfig4(authedPortalId).personalAccessKey;
6092
6108
  if (!authedPortalId && hubspotCliAccountNameOption2) {
6093
6109
  console.error(
6094
6110
  `Couldn't find ${hubspotCliAccountNameOption2} in your hubspot.config.yaml`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
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.0.31",
32
+ "@hubspot/cms-components": "^1.0.33",
33
33
  "@hubspot/local-dev-lib": "2.0.1",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -132,5 +132,5 @@
132
132
  "publishConfig": {
133
133
  "access": "public"
134
134
  },
135
- "gitHead": "c2e449f3d6c3c845b14c49a45b28aeade035dacb"
135
+ "gitHead": "8d1de5f4c21428c7f8bf053007a30eddff290c7a"
136
136
  }
@@ -0,0 +1,2 @@
1
+ export declare function debugAuthContext(authedPortalId: number, cookieValue: string): Promise<void>;
2
+ export declare function compareUrls(originalUrl: string, signedUrl: string): void;
@@ -2,5 +2,5 @@ export declare function renderRemoteModulePreview(modulePath: string, authedPort
2
2
  html: string;
3
3
  cssNeeded: string;
4
4
  }>;
5
- export declare function signUrl(authedPortalId: number, unsignedUrl: string): Promise<string>;
5
+ export declare function signUrl(authedPortalId: number, unsignedUrl: string, requestBody: any): Promise<string>;
6
6
  export declare function renderLocalProjectModulePreview(moduleName: string, authedPortalId: any, authedEnv: any, authedHublet: any, webRoot: any, viteServer: any, jsRenderingGates: any, projectName: any, projectComponentPath: any, fullOriginalUrl: any, cookieValue: any, fieldOverrides?: {}): Promise<import("./renderComponentWithCSS.js").RenderResult>;