@particle-academy/hubspot-js 0.5.0 → 0.7.0

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/flow.cjs CHANGED
@@ -677,8 +677,44 @@ function propertiesMap2(value) {
677
677
  var CONTACT_CREATE_OPERATION = "contact_create";
678
678
  async function hubspotContactCreate(options) {
679
679
  const config = options.config ?? {};
680
- if (config.email === void 0 || config.email === null || config.email === "") {
681
- throw new Error(`contact_create: "email" is required (Email).`);
680
+ if ((config.email === void 0 || config.email === null || config.email === "") && propertiesMap3(config.properties)["email"] === void 0) {
681
+ throw new Error(`contact_create: "email" is required \u2014 as Email, or as "email" in Properties.`);
682
+ }
683
+ {
684
+ const inMap = propertiesMap3(config.properties)["email"];
685
+ if (config.email !== void 0 && config.email !== null && config.email !== "" && inMap !== void 0 && inMap !== String(config.email).trim()) {
686
+ throw new Error(`contact_create: "email" was given twice with different values \u2014 as Email and as "email" in Properties.`);
687
+ }
688
+ }
689
+ {
690
+ const inMap = propertiesMap3(config.properties)["firstname"];
691
+ if (config.firstName !== void 0 && config.firstName !== null && config.firstName !== "" && inMap !== void 0 && inMap !== String(config.firstName)) {
692
+ throw new Error(`contact_create: "firstName" was given twice with different values \u2014 as First name and as "firstname" in Properties.`);
693
+ }
694
+ }
695
+ {
696
+ const inMap = propertiesMap3(config.properties)["lastname"];
697
+ if (config.lastName !== void 0 && config.lastName !== null && config.lastName !== "" && inMap !== void 0 && inMap !== String(config.lastName)) {
698
+ throw new Error(`contact_create: "lastName" was given twice with different values \u2014 as Last name and as "lastname" in Properties.`);
699
+ }
700
+ }
701
+ {
702
+ const inMap = propertiesMap3(config.properties)["company"];
703
+ if (config.company !== void 0 && config.company !== null && config.company !== "" && inMap !== void 0 && inMap !== String(config.company)) {
704
+ throw new Error(`contact_create: "company" was given twice with different values \u2014 as Company and as "company" in Properties.`);
705
+ }
706
+ }
707
+ {
708
+ const inMap = propertiesMap3(config.properties)["phone"];
709
+ if (config.phone !== void 0 && config.phone !== null && config.phone !== "" && inMap !== void 0 && inMap !== String(config.phone)) {
710
+ throw new Error(`contact_create: "phone" was given twice with different values \u2014 as Phone and as "phone" in Properties.`);
711
+ }
712
+ }
713
+ {
714
+ const inMap = propertiesMap3(config.properties)["lifecyclestage"];
715
+ if (config.lifecycleStage !== void 0 && config.lifecycleStage !== null && config.lifecycleStage !== "" && inMap !== void 0 && inMap !== String(config.lifecycleStage)) {
716
+ throw new Error(`contact_create: "lifecycleStage" was given twice with different values \u2014 as Lifecycle stage and as "lifecyclestage" in Properties.`);
717
+ }
682
718
  }
683
719
  return fancyConnectorCore.callConnector(HUBSPOT, {
684
720
  operation: CONTACT_CREATE_OPERATION,
@@ -692,15 +728,15 @@ async function hubspotContactCreate(options) {
692
728
  request: {
693
729
  method: "POST",
694
730
  path: "/crm/v3/objects/contacts",
695
- json: nestFields({
696
- "properties.email": String(config.email).trim(),
731
+ json: mergeInto(nestFields({
732
+ ...config.email !== void 0 && config.email !== null && config.email !== "" ? { "properties.email": String(config.email).trim() } : {},
697
733
  ...config.firstName !== void 0 && config.firstName !== null && config.firstName !== "" ? { "properties.firstname": String(config.firstName) } : {},
698
734
  ...config.lastName !== void 0 && config.lastName !== null && config.lastName !== "" ? { "properties.lastname": String(config.lastName) } : {},
699
735
  ...config.company !== void 0 && config.company !== null && config.company !== "" ? { "properties.company": String(config.company) } : {},
700
736
  ...config.phone !== void 0 && config.phone !== null && config.phone !== "" ? { "properties.phone": String(config.phone) } : {},
701
737
  ...config.lifecycleStage !== void 0 && config.lifecycleStage !== null && config.lifecycleStage !== "" ? { "properties.lifecyclestage": String(config.lifecycleStage) } : {},
702
738
  "associations": []
703
- })
739
+ }), "properties", propertiesMap3(config.properties))
704
740
  }
705
741
  });
706
742
  }
@@ -719,6 +755,18 @@ function nestFields(flat) {
719
755
  }
720
756
  return out;
721
757
  }
758
+ function mergeInto(body, key, map) {
759
+ const named = body[key];
760
+ return { ...body, [key]: { ...map, ...named !== null && typeof named === "object" ? named : {} } };
761
+ }
762
+ function propertiesMap3(value) {
763
+ if (!value || typeof value !== "object") return {};
764
+ const out = {};
765
+ for (const [key, item] of Object.entries(value)) {
766
+ if (item !== void 0 && item !== null && item !== "") out[key] = String(item);
767
+ }
768
+ return out;
769
+ }
722
770
  var CONTACT_GET_OPERATION = "contact_get";
723
771
  async function hubspotContactGet(options) {
724
772
  const config = options.config ?? {};
@@ -852,12 +900,12 @@ async function hubspotContactUpdate(options) {
852
900
  method: "PATCH",
853
901
  path: `/crm/v3/objects/contacts/${encodeURIComponent(String(config.contactId))}`,
854
902
  json: {
855
- "properties": propertiesMap3(config.properties)
903
+ "properties": propertiesMap4(config.properties)
856
904
  }
857
905
  }
858
906
  });
859
907
  }
860
- function propertiesMap3(value) {
908
+ function propertiesMap4(value) {
861
909
  if (!value || typeof value !== "object") return {};
862
910
  const out = {};
863
911
  for (const [key, item] of Object.entries(value)) {
@@ -884,13 +932,13 @@ async function hubspotDealCreate(options) {
884
932
  method: "POST",
885
933
  path: "/crm/v3/objects/deals",
886
934
  json: {
887
- "properties": propertiesMap4(config.properties),
935
+ "properties": propertiesMap5(config.properties),
888
936
  "associations": []
889
937
  }
890
938
  }
891
939
  });
892
940
  }
893
- function propertiesMap4(value) {
941
+ function propertiesMap5(value) {
894
942
  if (!value || typeof value !== "object") return {};
895
943
  const out = {};
896
944
  for (const [key, item] of Object.entries(value)) {
@@ -1031,12 +1079,12 @@ async function hubspotDealUpdate(options) {
1031
1079
  method: "PATCH",
1032
1080
  path: `/crm/v3/objects/deals/${encodeURIComponent(String(config.dealId))}`,
1033
1081
  json: {
1034
- "properties": propertiesMap5(config.properties)
1082
+ "properties": propertiesMap6(config.properties)
1035
1083
  }
1036
1084
  }
1037
1085
  });
1038
1086
  }
1039
- function propertiesMap5(value) {
1087
+ function propertiesMap6(value) {
1040
1088
  if (!value || typeof value !== "object") return {};
1041
1089
  const out = {};
1042
1090
  for (const [key, item] of Object.entries(value)) {
@@ -1132,7 +1180,7 @@ var HUBSPOT_CRM_EVENT = {
1132
1180
  service: "hubspot",
1133
1181
  operation: "crm_event",
1134
1182
  delivery: "webhook",
1135
- setup: "In the HubSpot app's webhook settings, set the target URL to the route your host mounts for this trigger and subscribe to the deal, contact and company events you want. Deliveries are signed with the app's client secret, already on the connection as `clientSecret`. ONE URL serves every portal that installed the app, so route each event by its portalId, and only after the signature has verified: map portalId to the connection created when that portal installed, and drop an unmapped portalId with a 2xx and a log line, creating nothing.",
1183
+ setup: "In the HubSpot app's webhook settings, set the target URL to the route your host mounts for this trigger and subscribe to the deal, contact and company events you want. Deliveries are signed with the app's client secret, already on the connection as `clientSecret`. ONE URL serves every portal that installed the app, so route each event by its portalId, and only after the signature has verified: map portalId to the connection created when that portal installed, and drop an unmapped portalId with a 2xx and a log line, creating nothing. HubSpot retries a failed delivery, and eventId is not guaranteed to be unique, so never dedupe on eventId alone: a retry is the same event resent, differing only in attemptNumber, so compare every other field. This connector's scope list covers every action, read and write, and is not what your consent URL must ask for: HubSpot requires your app's required scopes in the authorize URL's `scope` parameter and shows an error otherwise, so build it from your own app's configuration. A read-only host asks for its read scopes only.",
1136
1184
  verification: {
1137
1185
  signatureHeader: HUBSPOT_CRM_EVENT_SIGNATURE_HEADER,
1138
1186
  scheme: HUBSPOT_CRM_EVENT_SCHEME,