@segment/action-destinations 3.301.1-staging-c2af298f5 → 3.302.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/destinations/actions-pardot/pa-operations.d.ts +1 -1
- package/dist/destinations/adjust/functions.d.ts +1 -1
- package/dist/destinations/adobe-target/adobeTarget_operations.d.ts +1 -1
- package/dist/destinations/airship/utilities.d.ts +7 -7
- package/dist/destinations/amazon-amc/index.js +10 -2
- package/dist/destinations/amazon-amc/index.js.map +1 -1
- package/dist/destinations/blackbaud-raisers-edge-nxt/utils/index.d.ts +1 -1
- package/dist/destinations/braze/utils.d.ts +6 -6
- package/dist/destinations/contentstack/customAttributesSync/utils.d.ts +1 -1
- package/dist/destinations/cordial/cordial-client.d.ts +8 -8
- package/dist/destinations/dawn/dawn-types.d.ts +13 -0
- package/dist/destinations/{engage/twilio/utils/types.js → dawn/dawn-types.js} +1 -1
- package/dist/destinations/dawn/dawn-types.js.map +1 -0
- package/dist/destinations/dawn/generated-types.d.ts +3 -0
- package/dist/destinations/dawn/generated-types.js.map +1 -0
- package/dist/destinations/dawn/identifyUser/generated-types.d.ts +7 -0
- package/dist/destinations/dawn/identifyUser/generated-types.js.map +1 -0
- package/dist/destinations/dawn/identifyUser/index.js +58 -0
- package/dist/destinations/dawn/identifyUser/index.js.map +1 -0
- package/dist/destinations/{engage/twilio/destinationDefinition.d.ts → dawn/index.d.ts} +2 -1
- package/dist/destinations/dawn/index.js +39 -0
- package/dist/destinations/dawn/index.js.map +1 -0
- package/dist/destinations/dawn/track/generated-types.d.ts +8 -0
- package/dist/destinations/dawn/track/generated-types.js.map +1 -0
- package/dist/destinations/dawn/track/index.js +69 -0
- package/dist/destinations/dawn/track/index.js.map +1 -0
- package/dist/destinations/engage-messaging-sendgrid/sendEmail/SendEmailPerformer.d.ts +1 -1
- package/dist/destinations/engage-messaging-twilio/sendMobilePush/PushSender.d.ts +1 -1
- package/dist/destinations/engage-messaging-twilio/utils/PhoneMessageSender.d.ts +1 -1
- package/dist/destinations/facebook-conversions-api/constants.d.ts +1 -1
- package/dist/destinations/facebook-conversions-api/constants.js +1 -1
- package/dist/destinations/facebook-custom-audiences/fbca-operations.d.ts +2 -2
- package/dist/destinations/first-party-dv360/generated-types.d.ts +0 -7
- package/dist/destinations/first-party-dv360/index.d.ts +3 -3
- package/dist/destinations/first-party-dv360/index.js +5 -119
- package/dist/destinations/first-party-dv360/index.js.map +1 -1
- package/dist/destinations/gameball/util.d.ts +1 -1
- package/dist/destinations/google-analytics-4/ga4-functions.d.ts +1 -1
- package/dist/destinations/google-sheets/index.js +1 -3
- package/dist/destinations/google-sheets/index.js.map +1 -1
- package/dist/destinations/google-sheets/postSheet/operations.d.ts +1 -1
- package/dist/destinations/hubspot/customEvent/common-fields.d.ts +2 -0
- package/dist/destinations/hubspot/customEvent/common-fields.js +74 -0
- package/dist/destinations/hubspot/customEvent/common-fields.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/constants.d.ts +4 -0
- package/dist/destinations/hubspot/customEvent/constants.js +10 -0
- package/dist/destinations/hubspot/customEvent/constants.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/dynamic-fields.d.ts +32 -0
- package/dist/destinations/hubspot/customEvent/dynamic-fields.js +104 -0
- package/dist/destinations/hubspot/customEvent/dynamic-fields.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/generated-types.d.ts +13 -0
- package/dist/destinations/hubspot/customEvent/generated-types.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/hubspot-api.d.ts +62 -0
- package/dist/destinations/hubspot/customEvent/hubspot-api.js +310 -0
- package/dist/destinations/hubspot/customEvent/hubspot-api.js.map +1 -0
- package/dist/destinations/hubspot/customEvent/index.js +57 -0
- package/dist/destinations/hubspot/customEvent/index.js.map +1 -0
- package/dist/destinations/hubspot/index.js +3 -1
- package/dist/destinations/hubspot/index.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/common-fields.js +8 -32
- package/dist/destinations/hubspot/upsertObject/common-fields.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/generated-types.d.ts +8 -11
- package/dist/destinations/hubspot/upsertObject/hubspot-api.d.ts +169 -53
- package/dist/destinations/hubspot/upsertObject/hubspot-api.js +449 -336
- package/dist/destinations/hubspot/upsertObject/hubspot-api.js.map +1 -1
- package/dist/destinations/hubspot/upsertObject/index.d.ts +1 -1
- package/dist/destinations/hubspot/upsertObject/index.js +52 -28
- package/dist/destinations/hubspot/upsertObject/index.js.map +1 -1
- package/dist/destinations/index.js +2 -0
- package/dist/destinations/index.js.map +1 -1
- package/dist/destinations/klaviyo/addProfileToList/generated-types.d.ts +1 -0
- package/dist/destinations/klaviyo/addProfileToList/index.js +14 -5
- package/dist/destinations/klaviyo/addProfileToList/index.js.map +1 -1
- package/dist/destinations/klaviyo/functions.d.ts +7 -6
- package/dist/destinations/klaviyo/functions.js +23 -7
- package/dist/destinations/klaviyo/functions.js.map +1 -1
- package/dist/destinations/klaviyo/orderCompleted/generated-types.d.ts +1 -0
- package/dist/destinations/klaviyo/orderCompleted/index.js +11 -2
- package/dist/destinations/klaviyo/orderCompleted/index.js.map +1 -1
- package/dist/destinations/klaviyo/properties.d.ts +1 -0
- package/dist/destinations/klaviyo/properties.js +7 -1
- package/dist/destinations/klaviyo/properties.js.map +1 -1
- package/dist/destinations/klaviyo/removeProfile/generated-types.d.ts +1 -0
- package/dist/destinations/klaviyo/removeProfile/index.js +24 -7
- package/dist/destinations/klaviyo/removeProfile/index.js.map +1 -1
- package/dist/destinations/klaviyo/removeProfileFromList/generated-types.d.ts +1 -0
- package/dist/destinations/klaviyo/removeProfileFromList/index.js +18 -6
- package/dist/destinations/klaviyo/removeProfileFromList/index.js.map +1 -1
- package/dist/destinations/launchdarkly-audiences/syncAudience/custom-audience-operations.d.ts +1 -1
- package/dist/destinations/salesforce/index.js +1 -13
- package/dist/destinations/salesforce/index.js.map +1 -1
- package/dist/destinations/salesforce/sf-operations.d.ts +0 -1
- package/dist/destinations/salesforce/sf-operations.js +0 -20
- package/dist/destinations/salesforce/sf-operations.js.map +1 -1
- package/dist/destinations/salesforce/sf-properties.d.ts +0 -1
- package/dist/destinations/salesforce/sf-properties.js +6 -29
- package/dist/destinations/salesforce/sf-properties.js.map +1 -1
- package/dist/destinations/schematic/identifyUser/generated-types.d.ts +1 -1
- package/dist/destinations/schematic/identifyUser/index.js +6 -3
- package/dist/destinations/schematic/identifyUser/index.js.map +1 -1
- package/dist/destinations/schematic/trackEvent/generated-types.d.ts +1 -1
- package/dist/destinations/schematic/trackEvent/index.js +2 -2
- package/dist/destinations/schematic/trackEvent/index.js.map +1 -1
- package/dist/destinations/topsort/click/generated-types.d.ts +6 -0
- package/dist/destinations/topsort/click/generated-types.js.map +1 -0
- package/dist/destinations/topsort/click/index.js +54 -0
- package/dist/destinations/topsort/click/index.js.map +1 -0
- package/dist/destinations/topsort/client.d.ts +10 -0
- package/dist/destinations/topsort/client.js +26 -0
- package/dist/destinations/topsort/client.js.map +1 -0
- package/dist/destinations/topsort/generated-types.d.ts +3 -0
- package/dist/destinations/topsort/generated-types.js.map +1 -0
- package/dist/destinations/topsort/impression/generated-types.d.ts +6 -0
- package/dist/destinations/topsort/impression/generated-types.js.map +1 -0
- package/dist/destinations/topsort/impression/index.js +54 -0
- package/dist/destinations/topsort/impression/index.js.map +1 -0
- package/dist/destinations/{engage/sendgrid/destinationDefinition.d.ts → topsort/index.d.ts} +2 -1
- package/dist/destinations/topsort/index.js +56 -0
- package/dist/destinations/topsort/index.js.map +1 -0
- package/dist/destinations/topsort/purchase/generated-types.d.ts +10 -0
- package/dist/destinations/topsort/purchase/generated-types.js.map +1 -0
- package/dist/destinations/topsort/purchase/index.d.ts +5 -0
- package/dist/destinations/topsort/purchase/index.js +82 -0
- package/dist/destinations/topsort/purchase/index.js.map +1 -0
- package/dist/lib/test-data.js +2 -0
- package/dist/lib/test-data.js.map +1 -1
- package/package.json +4 -4
- package/dist/destinations/amazon-ads/generated-types.d.ts +0 -12
- package/dist/destinations/amazon-ads/generated-types.js.map +0 -1
- package/dist/destinations/amazon-ads/index.d.ts +0 -4
- package/dist/destinations/amazon-ads/index.js +0 -237
- package/dist/destinations/amazon-ads/index.js.map +0 -1
- package/dist/destinations/amazon-ads/syncAudiences/generated-types.d.ts +0 -15
- package/dist/destinations/amazon-ads/syncAudiences/generated-types.js.map +0 -1
- package/dist/destinations/amazon-ads/syncAudiences/index.js +0 -182
- package/dist/destinations/amazon-ads/syncAudiences/index.js.map +0 -1
- package/dist/destinations/amazon-ads/types.d.ts +0 -47
- package/dist/destinations/amazon-ads/types.js +0 -11
- package/dist/destinations/amazon-ads/types.js.map +0 -1
- package/dist/destinations/amazon-ads/utils.d.ts +0 -37
- package/dist/destinations/amazon-ads/utils.js +0 -25
- package/dist/destinations/amazon-ads/utils.js.map +0 -1
- package/dist/destinations/contentstack/constants.d.ts +0 -3
- package/dist/destinations/contentstack/constants.js +0 -7
- package/dist/destinations/contentstack/constants.js.map +0 -1
- package/dist/destinations/engage/sendgrid/destinationDefinition.js +0 -70
- package/dist/destinations/engage/sendgrid/destinationDefinition.js.map +0 -1
- package/dist/destinations/engage/sendgrid/generated-types.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/generated-types.js +0 -14
- package/dist/destinations/engage/sendgrid/generated-types.js.map +0 -1
- package/dist/destinations/engage/sendgrid/index.d.ts +0 -2
- package/dist/destinations/engage/sendgrid/index.js +0 -5
- package/dist/destinations/engage/sendgrid/index.js.map +0 -1
- package/dist/destinations/engage/sendgrid/previewApiLookup/actionDefinition.d.ts +0 -4
- package/dist/destinations/engage/sendgrid/previewApiLookup/actionDefinition.js +0 -28
- package/dist/destinations/engage/sendgrid/previewApiLookup/actionDefinition.js.map +0 -1
- package/dist/destinations/engage/sendgrid/previewApiLookup/generated-types.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/previewApiLookup/generated-types.js +0 -14
- package/dist/destinations/engage/sendgrid/previewApiLookup/generated-types.js.map +0 -1
- package/dist/destinations/engage/sendgrid/previewApiLookup/index.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/previewApiLookup/index.js +0 -14
- package/dist/destinations/engage/sendgrid/previewApiLookup/index.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/SendEmailPerformer.d.ts +0 -44
- package/dist/destinations/engage/sendgrid/sendEmail/SendEmailPerformer.js +0 -419
- package/dist/destinations/engage/sendgrid/sendEmail/SendEmailPerformer.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/UnlayerResponse.d.ts +0 -12
- package/dist/destinations/engage/sendgrid/sendEmail/UnlayerResponse.js +0 -3
- package/dist/destinations/engage/sendgrid/sendEmail/UnlayerResponse.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/actionDefinition.d.ts +0 -4
- package/dist/destinations/engage/sendgrid/sendEmail/actionDefinition.js +0 -257
- package/dist/destinations/engage/sendgrid/sendEmail/actionDefinition.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/generated-types.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/generated-types.js +0 -14
- package/dist/destinations/engage/sendgrid/sendEmail/generated-types.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/index.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/index.js +0 -14
- package/dist/destinations/engage/sendgrid/sendEmail/index.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/insertEmailPreviewText.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/insertEmailPreviewText.js +0 -23
- package/dist/destinations/engage/sendgrid/sendEmail/insertEmailPreviewText.js.map +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/isRestrictedDomain.d.ts +0 -1
- package/dist/destinations/engage/sendgrid/sendEmail/isRestrictedDomain.js +0 -14
- package/dist/destinations/engage/sendgrid/sendEmail/isRestrictedDomain.js.map +0 -1
- package/dist/destinations/engage/twilio/destinationDefinition.js +0 -172
- package/dist/destinations/engage/twilio/destinationDefinition.js.map +0 -1
- package/dist/destinations/engage/twilio/generated-types.d.ts +0 -1
- package/dist/destinations/engage/twilio/generated-types.js +0 -14
- package/dist/destinations/engage/twilio/generated-types.js.map +0 -1
- package/dist/destinations/engage/twilio/index.d.ts +0 -2
- package/dist/destinations/engage/twilio/index.js +0 -5
- package/dist/destinations/engage/twilio/index.js.map +0 -1
- package/dist/destinations/engage/twilio/sendMobilePush/PushSender.d.ts +0 -28
- package/dist/destinations/engage/twilio/sendMobilePush/PushSender.js +0 -151
- package/dist/destinations/engage/twilio/sendMobilePush/PushSender.js.map +0 -1
- package/dist/destinations/engage/twilio/sendMobilePush/actionDefinition.d.ts +0 -4
- package/dist/destinations/engage/twilio/sendMobilePush/actionDefinition.js +0 -250
- package/dist/destinations/engage/twilio/sendMobilePush/actionDefinition.js.map +0 -1
- package/dist/destinations/engage/twilio/sendMobilePush/generated-types.d.ts +0 -1
- package/dist/destinations/engage/twilio/sendMobilePush/generated-types.js +0 -14
- package/dist/destinations/engage/twilio/sendMobilePush/generated-types.js.map +0 -1
- package/dist/destinations/engage/twilio/sendMobilePush/index.d.ts +0 -1
- package/dist/destinations/engage/twilio/sendMobilePush/index.js +0 -14
- package/dist/destinations/engage/twilio/sendMobilePush/index.js.map +0 -1
- package/dist/destinations/engage/twilio/sendSms/SmsMessageSender.d.ts +0 -9
- package/dist/destinations/engage/twilio/sendSms/SmsMessageSender.js +0 -72
- package/dist/destinations/engage/twilio/sendSms/SmsMessageSender.js.map +0 -1
- package/dist/destinations/engage/twilio/sendSms/actionDefinition.d.ts +0 -4
- package/dist/destinations/engage/twilio/sendSms/actionDefinition.js +0 -162
- package/dist/destinations/engage/twilio/sendSms/actionDefinition.js.map +0 -1
- package/dist/destinations/engage/twilio/sendSms/generated-types.d.ts +0 -1
- package/dist/destinations/engage/twilio/sendSms/generated-types.js +0 -14
- package/dist/destinations/engage/twilio/sendSms/generated-types.js.map +0 -1
- package/dist/destinations/engage/twilio/sendSms/index.d.ts +0 -1
- package/dist/destinations/engage/twilio/sendSms/index.js +0 -14
- package/dist/destinations/engage/twilio/sendSms/index.js.map +0 -1
- package/dist/destinations/engage/twilio/sendWhatsApp/WhatsAppMessageSender.d.ts +0 -9
- package/dist/destinations/engage/twilio/sendWhatsApp/WhatsAppMessageSender.js +0 -89
- package/dist/destinations/engage/twilio/sendWhatsApp/WhatsAppMessageSender.js.map +0 -1
- package/dist/destinations/engage/twilio/sendWhatsApp/actionDefinition.d.ts +0 -4
- package/dist/destinations/engage/twilio/sendWhatsApp/actionDefinition.js +0 -136
- package/dist/destinations/engage/twilio/sendWhatsApp/actionDefinition.js.map +0 -1
- package/dist/destinations/engage/twilio/sendWhatsApp/generated-types.d.ts +0 -1
- package/dist/destinations/engage/twilio/sendWhatsApp/generated-types.js +0 -14
- package/dist/destinations/engage/twilio/sendWhatsApp/generated-types.js.map +0 -1
- package/dist/destinations/engage/twilio/sendWhatsApp/index.d.ts +0 -1
- package/dist/destinations/engage/twilio/sendWhatsApp/index.js +0 -14
- package/dist/destinations/engage/twilio/sendWhatsApp/index.js.map +0 -1
- package/dist/destinations/engage/twilio/utils/PhoneMessageSender.d.ts +0 -16
- package/dist/destinations/engage/twilio/utils/PhoneMessageSender.js +0 -71
- package/dist/destinations/engage/twilio/utils/PhoneMessageSender.js.map +0 -1
- package/dist/destinations/engage/twilio/utils/TwilioMessageSender.d.ts +0 -16
- package/dist/destinations/engage/twilio/utils/TwilioMessageSender.js +0 -115
- package/dist/destinations/engage/twilio/utils/TwilioMessageSender.js.map +0 -1
- package/dist/destinations/engage/twilio/utils/index.d.ts +0 -2
- package/dist/destinations/engage/twilio/utils/index.js +0 -15
- package/dist/destinations/engage/twilio/utils/index.js.map +0 -1
- package/dist/destinations/engage/twilio/utils/types.d.ts +0 -23
- package/dist/destinations/engage/twilio/utils/types.js.map +0 -1
- package/dist/destinations/engage/utils/AggregateError.d.ts +0 -14
- package/dist/destinations/engage/utils/AggregateError.js +0 -26
- package/dist/destinations/engage/utils/AggregateError.js.map +0 -1
- package/dist/destinations/engage/utils/EngageActionPerformer.d.ts +0 -42
- package/dist/destinations/engage/utils/EngageActionPerformer.js +0 -148
- package/dist/destinations/engage/utils/EngageActionPerformer.js.map +0 -1
- package/dist/destinations/engage/utils/EngageLogger.d.ts +0 -18
- package/dist/destinations/engage/utils/EngageLogger.js +0 -52
- package/dist/destinations/engage/utils/EngageLogger.js.map +0 -1
- package/dist/destinations/engage/utils/EngageStats.d.ts +0 -18
- package/dist/destinations/engage/utils/EngageStats.js +0 -95
- package/dist/destinations/engage/utils/EngageStats.js.map +0 -1
- package/dist/destinations/engage/utils/IntegrationErrorWrapper.d.ts +0 -12
- package/dist/destinations/engage/utils/IntegrationErrorWrapper.js +0 -31
- package/dist/destinations/engage/utils/IntegrationErrorWrapper.js.map +0 -1
- package/dist/destinations/engage/utils/MessageSendPerformer.d.ts +0 -65
- package/dist/destinations/engage/utils/MessageSendPerformer.js +0 -211
- package/dist/destinations/engage/utils/MessageSendPerformer.js.map +0 -1
- package/dist/destinations/engage/utils/Profile.d.ts +0 -6
- package/dist/destinations/engage/utils/Profile.js +0 -3
- package/dist/destinations/engage/utils/Profile.js.map +0 -1
- package/dist/destinations/engage/utils/ResponseError.d.ts +0 -25
- package/dist/destinations/engage/utils/ResponseError.js +0 -22
- package/dist/destinations/engage/utils/ResponseError.js.map +0 -1
- package/dist/destinations/engage/utils/apiLookups.d.ts +0 -22
- package/dist/destinations/engage/utils/apiLookups.js +0 -189
- package/dist/destinations/engage/utils/apiLookups.js.map +0 -1
- package/dist/destinations/engage/utils/getProfileApiEndpoint.d.ts +0 -2
- package/dist/destinations/engage/utils/getProfileApiEndpoint.js +0 -10
- package/dist/destinations/engage/utils/getProfileApiEndpoint.js.map +0 -1
- package/dist/destinations/engage/utils/index.d.ts +0 -9
- package/dist/destinations/engage/utils/index.js +0 -22
- package/dist/destinations/engage/utils/index.js.map +0 -1
- package/dist/destinations/engage/utils/isDestinationActionService.d.ts +0 -1
- package/dist/destinations/engage/utils/isDestinationActionService.js +0 -8
- package/dist/destinations/engage/utils/isDestinationActionService.js.map +0 -1
- package/dist/destinations/engage/utils/isRetryableError.d.ts +0 -2
- package/dist/destinations/engage/utils/isRetryableError.js +0 -33
- package/dist/destinations/engage/utils/isRetryableError.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/GenericMethodDecorator.d.ts +0 -1
- package/dist/destinations/engage/utils/operationTracking/GenericMethodDecorator.js +0 -3
- package/dist/destinations/engage/utils/operationTracking/GenericMethodDecorator.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationDecorator.d.ts +0 -46
- package/dist/destinations/engage/utils/operationTracking/OperationDecorator.js +0 -46
- package/dist/destinations/engage/utils/operationTracking/OperationDecorator.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationDuration.d.ts +0 -12
- package/dist/destinations/engage/utils/operationTracking/OperationDuration.js +0 -23
- package/dist/destinations/engage/utils/operationTracking/OperationDuration.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationErrorHandler.d.ts +0 -12
- package/dist/destinations/engage/utils/operationTracking/OperationErrorHandler.js +0 -35
- package/dist/destinations/engage/utils/operationTracking/OperationErrorHandler.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationFinallyHooks.d.ts +0 -14
- package/dist/destinations/engage/utils/operationTracking/OperationFinallyHooks.js +0 -31
- package/dist/destinations/engage/utils/operationTracking/OperationFinallyHooks.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationLogger.d.ts +0 -31
- package/dist/destinations/engage/utils/operationTracking/OperationLogger.js +0 -104
- package/dist/destinations/engage/utils/operationTracking/OperationLogger.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationStats.d.ts +0 -39
- package/dist/destinations/engage/utils/operationTracking/OperationStats.js +0 -130
- package/dist/destinations/engage/utils/operationTracking/OperationStats.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationTracker.test.d.ts +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationTracker.test.js +0 -377
- package/dist/destinations/engage/utils/operationTracking/OperationTracker.test.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/OperationTree.d.ts +0 -23
- package/dist/destinations/engage/utils/operationTracking/OperationTree.js +0 -49
- package/dist/destinations/engage/utils/operationTracking/OperationTree.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/TrackedError.d.ts +0 -6
- package/dist/destinations/engage/utils/operationTracking/TrackedError.js +0 -3
- package/dist/destinations/engage/utils/operationTracking/TrackedError.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/index.d.ts +0 -10
- package/dist/destinations/engage/utils/operationTracking/index.js +0 -23
- package/dist/destinations/engage/utils/operationTracking/index.js.map +0 -1
- package/dist/destinations/engage/utils/operationTracking/wrapTryCatchFinallyPromisable.d.ts +0 -21
- package/dist/destinations/engage/utils/operationTracking/wrapTryCatchFinallyPromisable.js +0 -99
- package/dist/destinations/engage/utils/operationTracking/wrapTryCatchFinallyPromisable.js.map +0 -1
- package/dist/destinations/engage/utils/testUtils.d.ts +0 -6
- package/dist/destinations/engage/utils/testUtils.js +0 -26
- package/dist/destinations/engage/utils/testUtils.js.map +0 -1
- package/dist/destinations/engage/utils/track.d.ts +0 -52
- package/dist/destinations/engage/utils/track.js +0 -9
- package/dist/destinations/engage/utils/track.js.map +0 -1
- package/dist/destinations/engage-messaging-sendgrid/previewApiLookup.types.d.ts +0 -16
- package/dist/destinations/engage-messaging-sendgrid/previewApiLookup.types.js +0 -3
- package/dist/destinations/engage-messaging-sendgrid/previewApiLookup.types.js.map +0 -1
- package/dist/destinations/engage-messaging-sendgrid/sendEmail.types.d.ts +0 -56
- package/dist/destinations/engage-messaging-sendgrid/sendEmail.types.js +0 -3
- package/dist/destinations/engage-messaging-sendgrid/sendEmail.types.js.map +0 -1
- package/dist/destinations/engage-messaging-twilio/sendMobilePush.types.d.ts +0 -39
- package/dist/destinations/engage-messaging-twilio/sendMobilePush.types.js +0 -3
- package/dist/destinations/engage-messaging-twilio/sendMobilePush.types.js.map +0 -1
- package/dist/destinations/engage-messaging-twilio/sendSms.types.d.ts +0 -27
- package/dist/destinations/engage-messaging-twilio/sendSms.types.js +0 -3
- package/dist/destinations/engage-messaging-twilio/sendSms.types.js.map +0 -1
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp.types.d.ts +0 -25
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp.types.js +0 -3
- package/dist/destinations/engage-messaging-twilio/sendWhatsApp.types.js.map +0 -1
- package/dist/destinations/facebook-custom-audiences/add/generated-types.d.ts +0 -2
- package/dist/destinations/facebook-custom-audiences/add/generated-types.js.map +0 -1
- package/dist/destinations/facebook-custom-audiences/add/index.js +0 -11
- package/dist/destinations/facebook-custom-audiences/add/index.js.map +0 -1
- package/dist/destinations/facebook-custom-audiences/remove/generated-types.d.ts +0 -2
- package/dist/destinations/facebook-custom-audiences/remove/generated-types.js.map +0 -1
- package/dist/destinations/facebook-custom-audiences/remove/index.js +0 -11
- package/dist/destinations/facebook-custom-audiences/remove/index.js.map +0 -1
- package/dist/destinations/first-party-dv360/functions.d.ts +0 -17
- package/dist/destinations/first-party-dv360/functions.js +0 -38
- package/dist/destinations/first-party-dv360/functions.js.map +0 -1
- package/dist/destinations/google-sheets/postSheet2/generated-types.d.ts +0 -10
- package/dist/destinations/google-sheets/postSheet2/generated-types.js.map +0 -1
- package/dist/destinations/google-sheets/postSheet2/index.js +0 -98
- package/dist/destinations/google-sheets/postSheet2/index.js.map +0 -1
- package/dist/destinations/google-sheets/postSheet2/operations2.d.ts +0 -10
- package/dist/destinations/google-sheets/postSheet2/operations2.js +0 -96
- package/dist/destinations/google-sheets/postSheet2/operations2.js.map +0 -1
- package/dist/destinations/salesforce/account2/generated-types.d.ts +0 -32
- package/dist/destinations/salesforce/account2/generated-types.js.map +0 -1
- package/dist/destinations/salesforce/account2/index.d.ts +0 -5
- package/dist/destinations/salesforce/account2/index.js +0 -248
- package/dist/destinations/salesforce/account2/index.js.map +0 -1
- package/dist/destinations/salesforce/cases2/generated-types.d.ts +0 -17
- package/dist/destinations/salesforce/cases2/generated-types.js.map +0 -1
- package/dist/destinations/salesforce/cases2/index.js +0 -76
- package/dist/destinations/salesforce/cases2/index.js.map +0 -1
- package/dist/destinations/salesforce/contact2/generated-types.d.ts +0 -25
- package/dist/destinations/salesforce/contact2/generated-types.js.map +0 -1
- package/dist/destinations/salesforce/contact2/index.d.ts +0 -5
- package/dist/destinations/salesforce/contact2/index.js +0 -192
- package/dist/destinations/salesforce/contact2/index.js.map +0 -1
- package/dist/destinations/salesforce/customObject2/generated-types.d.ts +0 -17
- package/dist/destinations/salesforce/customObject2/generated-types.js +0 -3
- package/dist/destinations/salesforce/customObject2/generated-types.js.map +0 -1
- package/dist/destinations/salesforce/customObject2/index.d.ts +0 -5
- package/dist/destinations/salesforce/customObject2/index.js +0 -97
- package/dist/destinations/salesforce/customObject2/index.js.map +0 -1
- package/dist/destinations/salesforce/lead2/generated-types.d.ts +0 -25
- package/dist/destinations/salesforce/lead2/generated-types.js +0 -3
- package/dist/destinations/salesforce/lead2/generated-types.js.map +0 -1
- package/dist/destinations/salesforce/lead2/index.d.ts +0 -5
- package/dist/destinations/salesforce/lead2/index.js +0 -200
- package/dist/destinations/salesforce/lead2/index.js.map +0 -1
- package/dist/destinations/salesforce/opportunity2/generated-types.d.ts +0 -21
- package/dist/destinations/salesforce/opportunity2/generated-types.js +0 -3
- package/dist/destinations/salesforce/opportunity2/generated-types.js.map +0 -1
- package/dist/destinations/salesforce/opportunity2/index.d.ts +0 -5
- package/dist/destinations/salesforce/opportunity2/index.js +0 -112
- package/dist/destinations/salesforce/opportunity2/index.js.map +0 -1
- /package/dist/destinations/{amazon-ads → dawn}/generated-types.js +0 -0
- /package/dist/destinations/{amazon-ads/syncAudiences → dawn/identifyUser}/generated-types.js +0 -0
- /package/dist/destinations/{amazon-ads/syncAudiences → dawn/identifyUser}/index.d.ts +0 -0
- /package/dist/destinations/{facebook-custom-audiences/add → dawn/track}/generated-types.js +0 -0
- /package/dist/destinations/{facebook-custom-audiences/add → dawn/track}/index.d.ts +0 -0
- /package/dist/destinations/{facebook-custom-audiences/remove → hubspot/customEvent}/generated-types.js +0 -0
- /package/dist/destinations/{google-sheets/postSheet2 → hubspot/customEvent}/index.d.ts +0 -0
- /package/dist/destinations/{google-sheets/postSheet2 → topsort/click}/generated-types.js +0 -0
- /package/dist/destinations/{facebook-custom-audiences/remove → topsort/click}/index.d.ts +0 -0
- /package/dist/destinations/{salesforce/account2 → topsort}/generated-types.js +0 -0
- /package/dist/destinations/{salesforce/cases2 → topsort/impression}/generated-types.js +0 -0
- /package/dist/destinations/{salesforce/cases2 → topsort/impression}/index.d.ts +0 -0
- /package/dist/destinations/{salesforce/contact2 → topsort/purchase}/generated-types.js +0 -0
|
@@ -1,9 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HubspotClient = void 0;
|
|
3
|
+
exports.HubspotClient = exports.SchemaMatch = exports.AssociationSyncMode = exports.SyncMode = void 0;
|
|
4
4
|
const actions_core_1 = require("@segment/actions-core");
|
|
5
5
|
const properties_1 = require("../properties");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
|
+
const OBJECT_NOT_FOUND_ERROR_RESPONSE = 'Unable to infer object type';
|
|
8
|
+
exports.SyncMode = {
|
|
9
|
+
Upsert: 'upsert',
|
|
10
|
+
Add: 'add',
|
|
11
|
+
Update: 'update'
|
|
12
|
+
};
|
|
13
|
+
exports.AssociationSyncMode = {
|
|
14
|
+
Upsert: 'upsert',
|
|
15
|
+
Read: 'read'
|
|
16
|
+
};
|
|
17
|
+
const BatchRequestType = {
|
|
18
|
+
Upsert: 'upsert',
|
|
19
|
+
Create: 'create',
|
|
20
|
+
Update: 'update',
|
|
21
|
+
Read: 'read'
|
|
22
|
+
};
|
|
23
|
+
const HSPropTypeFieldType = {
|
|
24
|
+
StringText: 'string:text',
|
|
25
|
+
NumberNumber: 'number:number',
|
|
26
|
+
DateTimeDate: 'datetime:date',
|
|
27
|
+
DateDate: 'date:date',
|
|
28
|
+
EnumerationBooleanCheckbox: 'enumeration:booleancheckbox'
|
|
29
|
+
};
|
|
30
|
+
const HSPropType = {
|
|
31
|
+
Date: 'date',
|
|
32
|
+
String: 'string',
|
|
33
|
+
DateTime: 'datetime',
|
|
34
|
+
Number: 'number',
|
|
35
|
+
Enumeration: 'enumeration'
|
|
36
|
+
};
|
|
37
|
+
const HSPropFieldType = {
|
|
38
|
+
Text: 'text',
|
|
39
|
+
Number: 'number',
|
|
40
|
+
Date: 'date',
|
|
41
|
+
BooleanCheckbox: 'booleancheckbox'
|
|
42
|
+
};
|
|
43
|
+
exports.SchemaMatch = {
|
|
44
|
+
FullMatch: 'full_match',
|
|
45
|
+
PropertiesMissing: 'properties_missing',
|
|
46
|
+
NoMatch: 'no_match',
|
|
47
|
+
Mismatch: 'mismatch'
|
|
48
|
+
};
|
|
49
|
+
const ReadType = {
|
|
50
|
+
ReturnRecordsWithIds: 'return_records_with_ids',
|
|
51
|
+
ReturnRecordsWithoutIds: 'return_records_without_ids'
|
|
52
|
+
};
|
|
7
53
|
var AssociationCategory;
|
|
8
54
|
(function (AssociationCategory) {
|
|
9
55
|
AssociationCategory["HUBSPOT_DEFINED"] = "HUBSPOT_DEFINED";
|
|
@@ -11,200 +57,254 @@ var AssociationCategory;
|
|
|
11
57
|
AssociationCategory["INTEGRATOR_DEFINED"] = "INTEGRATOR_DEFINED";
|
|
12
58
|
})(AssociationCategory || (AssociationCategory = {}));
|
|
13
59
|
class HubspotClient {
|
|
14
|
-
constructor(request,
|
|
60
|
+
constructor(request, objectType, syncMode, associationSyncMode, propertyGroup) {
|
|
15
61
|
this.request = request;
|
|
62
|
+
this.objectType = objectType;
|
|
63
|
+
this.syncMode = syncMode;
|
|
16
64
|
this.associationSyncMode = associationSyncMode;
|
|
17
|
-
this.
|
|
18
|
-
this.fromIdFieldName = fromIdFieldName;
|
|
19
|
-
this.hubspotSyncMode = this.mapHubspotSyncMode(syncMode);
|
|
20
|
-
this.fromPropertyGroup = fromPropertyGroup;
|
|
65
|
+
this.propertyGroup = propertyGroup;
|
|
21
66
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
case 'add':
|
|
27
|
-
return 'create';
|
|
28
|
-
case 'update':
|
|
29
|
-
return 'update';
|
|
30
|
-
default:
|
|
31
|
-
throw new Error('Invalid sync mode');
|
|
67
|
+
cleanProp(str) {
|
|
68
|
+
str = str.toLowerCase().replace(/[^a-z0-9_]/g, '_');
|
|
69
|
+
if (!/^[a-z]/.test(str)) {
|
|
70
|
+
throw new actions_core_1.PayloadValidationError(`Property ${str} in event has an invalid name. Property names must start with a letter.`);
|
|
32
71
|
}
|
|
72
|
+
return str;
|
|
33
73
|
}
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
method: 'GET',
|
|
39
|
-
skipResponseCloning: true
|
|
40
|
-
}));
|
|
74
|
+
cleanObj(obj) {
|
|
75
|
+
const cleanObj = {};
|
|
76
|
+
if (obj === undefined) {
|
|
77
|
+
return undefined;
|
|
41
78
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
Object.keys(obj).forEach((key) => {
|
|
80
|
+
const value = obj[key];
|
|
81
|
+
const cleanKey = this.cleanProp(key);
|
|
82
|
+
cleanObj[cleanKey] =
|
|
83
|
+
typeof value === 'object' && value !== null ? JSON.stringify(value) : value;
|
|
84
|
+
});
|
|
85
|
+
return cleanObj;
|
|
86
|
+
}
|
|
87
|
+
cleanProps(payloads) {
|
|
88
|
+
const copy = JSON.parse(JSON.stringify(payloads));
|
|
89
|
+
copy.forEach((payload) => {
|
|
90
|
+
payload.properties = this.cleanObj(payload.properties);
|
|
91
|
+
payload.sensitive_properties = this.cleanObj(payload.sensitive_properties);
|
|
92
|
+
});
|
|
93
|
+
return copy;
|
|
94
|
+
}
|
|
95
|
+
format(value) {
|
|
96
|
+
switch (typeof value) {
|
|
97
|
+
case 'object':
|
|
98
|
+
return { type: HSPropType.String, fieldType: HSPropFieldType.Text };
|
|
99
|
+
case 'number':
|
|
100
|
+
return { type: HSPropType.Number, fieldType: HSPropFieldType.Number };
|
|
101
|
+
case 'boolean':
|
|
102
|
+
return { type: HSPropType.Enumeration, fieldType: HSPropFieldType.BooleanCheckbox };
|
|
103
|
+
case 'string': {
|
|
104
|
+
const date = new Date(value);
|
|
105
|
+
if (isNaN(date.getTime())) {
|
|
106
|
+
return { type: HSPropType.String, fieldType: HSPropFieldType.Text };
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const year = date.getUTCFullYear();
|
|
110
|
+
const month = date.getUTCMonth();
|
|
111
|
+
const day = date.getUTCDate();
|
|
112
|
+
const hours = date.getUTCHours();
|
|
113
|
+
const minutes = date.getUTCMinutes();
|
|
114
|
+
const seconds = date.getUTCSeconds();
|
|
115
|
+
const milliseconds = date.getUTCMilliseconds();
|
|
116
|
+
if (hours === 0 && minutes === 0 && seconds === 0 && milliseconds === 0) {
|
|
117
|
+
const reconstructedDate = new Date(Date.UTC(year, month, day));
|
|
118
|
+
if (reconstructedDate.getTime() === date.getTime()) {
|
|
119
|
+
return { type: HSPropType.Date, fieldType: HSPropFieldType.Date };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { type: HSPropType.DateTime, fieldType: HSPropFieldType.Date };
|
|
123
|
+
}
|
|
73
124
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
throw new actions_core_1.IntegrationError(`readProperties() failed: ${err?.response?.data?.message ?? 'Unknown error: readProperties() failed'}`, 'HUBSPOT_READ_PROPERTIES_FAILED', 400);
|
|
125
|
+
case undefined:
|
|
126
|
+
default:
|
|
127
|
+
throw new actions_core_1.IntegrationError('Property must be an object, boolean, string or number', 'HUBSPOT_PROPERTY_VALUE_UNDEFINED', 400);
|
|
78
128
|
}
|
|
79
129
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return 'string';
|
|
130
|
+
formatHS(type, fieldType) {
|
|
131
|
+
if (type === 'date' && fieldType === 'date') {
|
|
132
|
+
return HSPropTypeFieldType.DateDate;
|
|
84
133
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const day = date.getUTCDate();
|
|
88
|
-
const hours = date.getUTCHours();
|
|
89
|
-
const minutes = date.getUTCMinutes();
|
|
90
|
-
const seconds = date.getUTCSeconds();
|
|
91
|
-
const milliseconds = date.getUTCMilliseconds();
|
|
92
|
-
if (hours === 0 && minutes === 0 && seconds === 0 && milliseconds === 0) {
|
|
93
|
-
const reconstructedDate = new Date(Date.UTC(year, month, day));
|
|
94
|
-
if (reconstructedDate.getTime() === date.getTime()) {
|
|
95
|
-
return 'date';
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
return 'datetime';
|
|
99
|
-
}
|
|
134
|
+
else if (type === 'string' && fieldType === 'text') {
|
|
135
|
+
return HSPropTypeFieldType.StringText;
|
|
100
136
|
}
|
|
101
|
-
|
|
137
|
+
else if (type === 'number' && fieldType === 'number') {
|
|
138
|
+
return HSPropTypeFieldType.NumberNumber;
|
|
139
|
+
}
|
|
140
|
+
else if (type === 'datetime' && fieldType === 'date') {
|
|
141
|
+
return HSPropTypeFieldType.DateTimeDate;
|
|
142
|
+
}
|
|
143
|
+
else if (type === 'enumeration' && fieldType === 'booleancheckbox') {
|
|
144
|
+
return HSPropTypeFieldType.EnumerationBooleanCheckbox;
|
|
145
|
+
}
|
|
146
|
+
throw new actions_core_1.IntegrationError('Property type not supported', 'HUBSPOT_PROPERTY_TYPE_NOT_SUPPORTED', 400);
|
|
102
147
|
}
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
const format = type === 'string' ? this.hubspotStringType(value) : 'string';
|
|
111
|
-
acc[propName] = {
|
|
112
|
-
name: propName,
|
|
113
|
-
type,
|
|
114
|
-
format
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
return acc;
|
|
120
|
-
}, {}));
|
|
121
|
-
const uniqueSensitiveProperties = Object.values(payloads.reduce((acc, payload) => {
|
|
122
|
-
if (payload.sensitiveProperties) {
|
|
123
|
-
Object.keys(payload.sensitiveProperties).forEach((propName) => {
|
|
124
|
-
if (payload.sensitiveProperties) {
|
|
125
|
-
const value = payload.sensitiveProperties[propName];
|
|
126
|
-
const type = typeof payload.sensitiveProperties[propName];
|
|
127
|
-
const format = type === 'string' ? this.hubspotStringType(value) : 'string';
|
|
148
|
+
schema(payloads) {
|
|
149
|
+
const extractProperties = (propertyType) => {
|
|
150
|
+
return Object.values(payloads.reduce((acc, payload) => {
|
|
151
|
+
const properties = payload[propertyType];
|
|
152
|
+
if (properties) {
|
|
153
|
+
Object.entries(properties).forEach(([propName, value]) => {
|
|
154
|
+
const typeData = this.format(value);
|
|
128
155
|
acc[propName] = {
|
|
129
156
|
name: propName,
|
|
130
|
-
type,
|
|
131
|
-
|
|
157
|
+
type: typeData.type,
|
|
158
|
+
fieldType: typeData.fieldType,
|
|
159
|
+
typeFieldType: this.formatHS(typeData.type, typeData.fieldType)
|
|
132
160
|
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return acc;
|
|
164
|
+
}, {}));
|
|
165
|
+
};
|
|
166
|
+
const properties = extractProperties('properties');
|
|
167
|
+
const sensitiveProperties = extractProperties('sensitive_properties');
|
|
138
168
|
return {
|
|
139
|
-
|
|
140
|
-
|
|
169
|
+
object_details: {
|
|
170
|
+
object_type: this.objectType,
|
|
171
|
+
id_field_name: payloads[0].object_details.id_field_name
|
|
172
|
+
},
|
|
173
|
+
properties,
|
|
174
|
+
sensitiveProperties
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
async schemaDiffCache(schema) {
|
|
178
|
+
let data = JSON.stringify(`${schema}`);
|
|
179
|
+
data = data.replace(data, '');
|
|
180
|
+
console.log(`${data}`);
|
|
181
|
+
const schemaDiff = {
|
|
182
|
+
match: 'no_match',
|
|
183
|
+
object_details: {
|
|
184
|
+
object_type: schema.object_details.object_type,
|
|
185
|
+
id_field_name: schema.object_details.id_field_name
|
|
186
|
+
},
|
|
187
|
+
missingProperties: [],
|
|
188
|
+
missingSensitiveProperties: []
|
|
141
189
|
};
|
|
190
|
+
return Promise.resolve(schemaDiff);
|
|
142
191
|
}
|
|
143
|
-
|
|
144
|
-
|
|
192
|
+
async saveSchemaToCache(schema) {
|
|
193
|
+
let data = JSON.stringify(`${schema}`);
|
|
194
|
+
data = data.replace(data, '');
|
|
195
|
+
console.log(`${data}`);
|
|
145
196
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
197
|
+
determineMissingPropsAndMatchType(response, properties) {
|
|
198
|
+
switch (response.status) {
|
|
199
|
+
case 'fulfilled': {
|
|
200
|
+
const results = response.value?.data.results ?? [];
|
|
201
|
+
const missingProps = [];
|
|
202
|
+
properties.forEach((prop) => {
|
|
203
|
+
const match = results.find((item) => {
|
|
204
|
+
return item.name === prop.name;
|
|
205
|
+
});
|
|
206
|
+
if (match && (match.fieldType !== prop.fieldType || match.type !== prop.type)) {
|
|
207
|
+
throw new actions_core_1.IntegrationError(`Payload property with name ${prop.name} has a different type to the property in HubSpot. Expected: type = ${prop.type} fieldType = ${prop.fieldType}. Received: type = ${match.type} fieldType = ${match.fieldType}`, 'HUBSPOT_PROPERTY_TYPE_MISMATCH', 400);
|
|
154
208
|
}
|
|
155
|
-
|
|
156
|
-
|
|
209
|
+
if (!match) {
|
|
210
|
+
missingProps.push({
|
|
211
|
+
name: prop.name,
|
|
212
|
+
type: prop.type,
|
|
213
|
+
fieldType: prop.fieldType,
|
|
214
|
+
typeFieldType: prop.typeFieldType
|
|
215
|
+
});
|
|
157
216
|
}
|
|
158
|
-
|
|
159
|
-
|
|
217
|
+
});
|
|
218
|
+
return {
|
|
219
|
+
missingProps,
|
|
220
|
+
match: missingProps.length === 0 ? exports.SchemaMatch.FullMatch : exports.SchemaMatch.PropertiesMissing
|
|
221
|
+
};
|
|
160
222
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
acc[lowerCasedProp] = payload.sensitiveProperties ? payload.sensitiveProperties[prop] : undefined;
|
|
169
|
-
}
|
|
170
|
-
return acc;
|
|
171
|
-
}, {});
|
|
223
|
+
case 'rejected': {
|
|
224
|
+
if (response.reason?.message.startsWith(OBJECT_NOT_FOUND_ERROR_RESPONSE)) {
|
|
225
|
+
return { missingProps: [], match: exports.SchemaMatch.NoMatch };
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
throw new actions_core_1.IntegrationError(`Error fetching Hubspot property data: ${response.reason?.message}`, 'HUBSPOT_PROPERTY_FETCH_ERROR', 400);
|
|
229
|
+
}
|
|
172
230
|
}
|
|
173
|
-
}
|
|
174
|
-
return deepCopy;
|
|
231
|
+
}
|
|
175
232
|
}
|
|
176
|
-
async
|
|
177
|
-
|
|
233
|
+
async schemaDiffHubspot(schema) {
|
|
234
|
+
const requests = [];
|
|
235
|
+
const hasProps = schema.properties.length;
|
|
236
|
+
const hasSensitiveProps = schema.sensitiveProperties.length;
|
|
237
|
+
if (hasProps) {
|
|
238
|
+
requests.push(this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/properties/${this.objectType}`, {
|
|
239
|
+
method: 'GET',
|
|
240
|
+
skipResponseCloning: true
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
if (hasSensitiveProps) {
|
|
244
|
+
requests.push(this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/properties/${this.objectType}?dataSensitivity=sensitive`, {
|
|
245
|
+
method: 'GET',
|
|
246
|
+
skipResponseCloning: true
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
const responses = await Promise.allSettled(requests);
|
|
250
|
+
const schemaDiff = {
|
|
251
|
+
object_details: {
|
|
252
|
+
object_type: schema.object_details.object_type,
|
|
253
|
+
id_field_name: schema.object_details.id_field_name
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
if (hasProps && requests.length > 0) {
|
|
257
|
+
const response = responses.shift();
|
|
258
|
+
const { missingProps, match } = this.determineMissingPropsAndMatchType(response, schema.properties);
|
|
259
|
+
schemaDiff.missingProperties = missingProps;
|
|
260
|
+
schemaDiff.match = match;
|
|
261
|
+
}
|
|
262
|
+
if (hasSensitiveProps && requests.length > 0) {
|
|
263
|
+
const response = responses.shift();
|
|
264
|
+
const { missingProps, match } = this.determineMissingPropsAndMatchType(response, schema.sensitiveProperties);
|
|
265
|
+
schemaDiff.missingSensitiveProperties = missingProps;
|
|
266
|
+
if (schemaDiff.match === exports.SchemaMatch.NoMatch && schemaDiff.match !== exports.SchemaMatch.NoMatch) {
|
|
267
|
+
throw new actions_core_1.IntegrationError('Unable to fetch property data from Hubspot', 'HUBSPOT_PROPERTIES_ERROR', 400);
|
|
268
|
+
}
|
|
269
|
+
if (schemaDiff.match === exports.SchemaMatch.FullMatch) {
|
|
270
|
+
schemaDiff.match = match;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return schemaDiff;
|
|
274
|
+
}
|
|
275
|
+
async createProperties(schemaDiff) {
|
|
276
|
+
if (!this.propertyGroup) {
|
|
178
277
|
throw new actions_core_1.PayloadValidationError('"Property Group" is a required field when creating properties on an Object Schema in Hubspot');
|
|
179
278
|
}
|
|
180
|
-
if (
|
|
279
|
+
if (schemaDiff.missingProperties.length === 0 || schemaDiff.missingSensitiveProperties.length === 0) {
|
|
181
280
|
return;
|
|
182
281
|
}
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
282
|
+
const { missingProperties: props, missingSensitiveProperties: sensitiveProps } = schemaDiff;
|
|
283
|
+
const input = (prop, sensitive) => {
|
|
284
|
+
switch (prop.typeFieldType) {
|
|
285
|
+
case HSPropTypeFieldType.NumberNumber:
|
|
186
286
|
return {
|
|
187
287
|
name: prop.name,
|
|
188
288
|
label: prop.name,
|
|
189
|
-
groupName: this.
|
|
289
|
+
groupName: this.propertyGroup,
|
|
190
290
|
type: 'number',
|
|
191
291
|
dataSensitivity: sensitive === true ? 'sensitive' : undefined,
|
|
192
292
|
fieldType: 'number'
|
|
193
293
|
};
|
|
194
|
-
case
|
|
294
|
+
case HSPropTypeFieldType.StringText:
|
|
195
295
|
return {
|
|
196
296
|
name: prop.name,
|
|
197
297
|
label: prop.name,
|
|
198
|
-
groupName: this.
|
|
298
|
+
groupName: this.propertyGroup,
|
|
199
299
|
type: 'string',
|
|
200
300
|
dataSensitivity: sensitive === true ? 'sensitive' : undefined,
|
|
201
301
|
fieldType: 'text'
|
|
202
302
|
};
|
|
203
|
-
case
|
|
303
|
+
case HSPropTypeFieldType.EnumerationBooleanCheckbox:
|
|
204
304
|
return {
|
|
205
305
|
name: prop.name,
|
|
206
306
|
label: prop.name,
|
|
207
|
-
groupName: this.
|
|
307
|
+
groupName: this.propertyGroup,
|
|
208
308
|
type: 'enumeration',
|
|
209
309
|
dataSensitivity: sensitive === true ? 'sensitive' : undefined,
|
|
210
310
|
fieldType: 'booleancheckbox',
|
|
@@ -225,232 +325,245 @@ class HubspotClient {
|
|
|
225
325
|
}
|
|
226
326
|
]
|
|
227
327
|
};
|
|
228
|
-
case
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
fieldType: 'date'
|
|
247
|
-
};
|
|
248
|
-
case 'datetime':
|
|
249
|
-
return {
|
|
250
|
-
name: prop.name,
|
|
251
|
-
label: prop.name,
|
|
252
|
-
groupName: this.fromPropertyGroup,
|
|
253
|
-
type: 'datetime',
|
|
254
|
-
dataSensitivity: sensitive === true ? 'sensitive' : undefined,
|
|
255
|
-
fieldType: 'date'
|
|
256
|
-
};
|
|
257
|
-
}
|
|
328
|
+
case HSPropTypeFieldType.DateTimeDate:
|
|
329
|
+
return {
|
|
330
|
+
name: prop.name,
|
|
331
|
+
label: prop.name,
|
|
332
|
+
groupName: this.propertyGroup,
|
|
333
|
+
type: 'datetime',
|
|
334
|
+
dataSensitivity: sensitive === true ? 'sensitive' : undefined,
|
|
335
|
+
fieldType: 'date'
|
|
336
|
+
};
|
|
337
|
+
case HSPropTypeFieldType.DateDate:
|
|
338
|
+
return {
|
|
339
|
+
name: prop.name,
|
|
340
|
+
label: prop.name,
|
|
341
|
+
groupName: this.propertyGroup,
|
|
342
|
+
type: 'date',
|
|
343
|
+
dataSensitivity: sensitive === true ? 'sensitive' : undefined,
|
|
344
|
+
fieldType: 'date'
|
|
345
|
+
};
|
|
258
346
|
}
|
|
259
|
-
throw new actions_core_1.PayloadValidationError('Invalid property type');
|
|
260
347
|
};
|
|
261
348
|
const json = {
|
|
262
|
-
inputs: [
|
|
263
|
-
...properties.map((prop) => generateInputMapping(prop, false)),
|
|
264
|
-
...sensitiveProperties.map((prop) => generateInputMapping(prop, true))
|
|
265
|
-
]
|
|
349
|
+
inputs: [...props.map((p) => input(p, false)), ...sensitiveProps.map((p) => input(p, true))]
|
|
266
350
|
};
|
|
267
|
-
await this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/properties/${this.
|
|
351
|
+
await this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/properties/${this.objectType}/batch/create`, {
|
|
268
352
|
method: 'POST',
|
|
269
353
|
skipResponseCloning: true,
|
|
270
354
|
json
|
|
271
355
|
});
|
|
272
356
|
}
|
|
273
|
-
groupAssociations(associations, groupBy) {
|
|
274
|
-
const groupedAssociations = [];
|
|
275
|
-
const groups = associations.reduce((acc, association) => {
|
|
276
|
-
const key = groupBy.map((prop) => association[prop]).join('_');
|
|
277
|
-
if (!acc[key]) {
|
|
278
|
-
acc[key] = [];
|
|
279
|
-
}
|
|
280
|
-
acc[key].push(association);
|
|
281
|
-
return acc;
|
|
282
|
-
}, {});
|
|
283
|
-
for (const key in groups) {
|
|
284
|
-
const items = groups[key];
|
|
285
|
-
for (let i = 0; i < items.length; i += constants_1.MAX_HUBSPOT_BATCH_SIZE) {
|
|
286
|
-
groupedAssociations.push(items.slice(i, i + constants_1.MAX_HUBSPOT_BATCH_SIZE));
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return groupedAssociations;
|
|
290
|
-
}
|
|
291
|
-
getAssociationsFromPayloads(payloads) {
|
|
292
|
-
const payloadsDeepCopy = JSON.parse(JSON.stringify(payloads));
|
|
293
|
-
const allAssociations = [];
|
|
294
|
-
payloadsDeepCopy.forEach((payload) => {
|
|
295
|
-
const associations = payload.associations ?? [];
|
|
296
|
-
associations.forEach((association) => {
|
|
297
|
-
association.from_record_id = payload.object_details.from_record_id;
|
|
298
|
-
allAssociations.push(association);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
return allAssociations;
|
|
302
|
-
}
|
|
303
357
|
async batchObjectRequest(action, objectType, data) {
|
|
304
358
|
return this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v3/objects/${objectType}/batch/${action}`, {
|
|
305
359
|
method: 'POST',
|
|
306
360
|
json: data
|
|
307
361
|
});
|
|
308
362
|
}
|
|
309
|
-
async
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
switch (this.associationSyncMode) {
|
|
314
|
-
case 'upsert': {
|
|
315
|
-
groupedAssociations = this.groupAssociations(associationsDeepCopy, ['to_object_type']);
|
|
316
|
-
requests = groupedAssociations.map(async (associations) => {
|
|
317
|
-
const { to_object_type: toObjectType } = associations[0];
|
|
318
|
-
return await this.batchObjectRequest(this.associationSyncMode, toObjectType, {
|
|
319
|
-
inputs: associations.map((association) => {
|
|
320
|
-
return {
|
|
321
|
-
idProperty: association.to_id_field_name,
|
|
322
|
-
id: association.to_id_field_value,
|
|
323
|
-
properties: {
|
|
324
|
-
[association.to_id_field_name]: association.to_id_field_value
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
})
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
break;
|
|
363
|
+
async sendFromRecords(payloads) {
|
|
364
|
+
switch (this.syncMode) {
|
|
365
|
+
case exports.SyncMode.Upsert: {
|
|
366
|
+
return await this.upsertRecords(payloads, this.objectType);
|
|
331
367
|
}
|
|
332
|
-
case
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
idProperty: toIdFieldName,
|
|
338
|
-
properties: [toIdFieldName],
|
|
339
|
-
inputs: associations.map((association) => {
|
|
340
|
-
return {
|
|
341
|
-
id: association.to_id_field_value
|
|
342
|
-
};
|
|
343
|
-
})
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
break;
|
|
368
|
+
case exports.SyncMode.Update: {
|
|
369
|
+
return await this.updateRecords(payloads, this.objectType);
|
|
370
|
+
}
|
|
371
|
+
case exports.SyncMode.Add: {
|
|
372
|
+
return await this.addRecords(payloads, this.objectType);
|
|
347
373
|
}
|
|
348
374
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
375
|
+
}
|
|
376
|
+
async readRecords(payloads, objectType, readType) {
|
|
377
|
+
const idFieldName = payloads[0].object_details.id_field_name;
|
|
378
|
+
const readResponse = await this.batchObjectRequest(BatchRequestType.Read, objectType, {
|
|
379
|
+
properties: [idFieldName],
|
|
380
|
+
idProperty: idFieldName,
|
|
381
|
+
inputs: payloads.map((payload) => {
|
|
382
|
+
return { id: payload.object_details.id_field_value };
|
|
383
|
+
})
|
|
357
384
|
});
|
|
358
|
-
switch (
|
|
359
|
-
case
|
|
360
|
-
return
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return groupedAssociations.flat();
|
|
364
|
-
}
|
|
385
|
+
switch (readType) {
|
|
386
|
+
case ReadType.ReturnRecordsWithIds:
|
|
387
|
+
return this.returnRecordsWithIds(payloads, readResponse);
|
|
388
|
+
case ReadType.ReturnRecordsWithoutIds:
|
|
389
|
+
return this.returnRecordsWithoutIds(payloads, readResponse);
|
|
365
390
|
}
|
|
366
391
|
}
|
|
367
|
-
|
|
368
|
-
const
|
|
392
|
+
async upsertRecords(payloads, objectType) {
|
|
393
|
+
const response = await this.batchObjectRequest(BatchRequestType.Upsert, objectType, {
|
|
394
|
+
inputs: payloads.map(({ object_details: { id_field_value }, properties, sensitive_properties }) => {
|
|
395
|
+
const idFieldName = payloads[0].object_details.id_field_name;
|
|
396
|
+
return {
|
|
397
|
+
idProperty: idFieldName,
|
|
398
|
+
id: id_field_value,
|
|
399
|
+
properties: { ...properties, ...sensitive_properties, [idFieldName]: id_field_value }
|
|
400
|
+
};
|
|
401
|
+
})
|
|
402
|
+
});
|
|
403
|
+
return this.returnRecordsWithIds(payloads, response);
|
|
404
|
+
}
|
|
405
|
+
async updateRecords(payloads, objectType) {
|
|
406
|
+
const existingRecords = (await this.readRecords(payloads, objectType, ReadType.ReturnRecordsWithIds));
|
|
407
|
+
const response = await this.batchObjectRequest(BatchRequestType.Update, this.objectType, {
|
|
408
|
+
inputs: existingRecords.map(({ object_details: { id_field_value }, properties, sensitive_properties }) => {
|
|
409
|
+
const idFieldName = payloads[0].object_details.id_field_name;
|
|
410
|
+
return {
|
|
411
|
+
idProperty: idFieldName,
|
|
412
|
+
id: id_field_value,
|
|
413
|
+
properties: { ...properties, ...sensitive_properties }
|
|
414
|
+
};
|
|
415
|
+
})
|
|
416
|
+
});
|
|
417
|
+
return this.returnRecordsWithIds(existingRecords, response);
|
|
418
|
+
}
|
|
419
|
+
async addRecords(payloads, objectType) {
|
|
420
|
+
const recordsToCreate = (await this.readRecords(payloads, objectType, ReadType.ReturnRecordsWithoutIds));
|
|
421
|
+
const response = await this.batchObjectRequest(BatchRequestType.Create, this.objectType, {
|
|
422
|
+
inputs: recordsToCreate.map(({ object_details: { id_field_value: fromIdFieldValue }, properties, sensitive_properties }) => {
|
|
423
|
+
const idFieldName = payloads[0].object_details.id_field_name;
|
|
424
|
+
return {
|
|
425
|
+
idProperty: idFieldName,
|
|
426
|
+
properties: { ...properties, ...sensitive_properties, [idFieldName]: fromIdFieldValue }
|
|
427
|
+
};
|
|
428
|
+
})
|
|
429
|
+
});
|
|
430
|
+
return this.returnRecordsWithIds(recordsToCreate, response);
|
|
431
|
+
}
|
|
432
|
+
returnRecordsWithIds(payloads, response) {
|
|
369
433
|
response?.data?.results.forEach((result) => {
|
|
370
|
-
|
|
434
|
+
payloads
|
|
371
435
|
.filter((p) => {
|
|
372
|
-
return
|
|
436
|
+
return p.object_details.id_field_value == result.properties[p.object_details.id_field_name];
|
|
373
437
|
})
|
|
374
438
|
.forEach((p) => {
|
|
375
|
-
|
|
439
|
+
const pw = { ...p, object_details: { ...p.object_details, record_id: result.id } };
|
|
440
|
+
if (pw.associations) {
|
|
441
|
+
pw.associations.forEach((association) => {
|
|
442
|
+
association.from_record_id = result.id;
|
|
443
|
+
});
|
|
444
|
+
}
|
|
376
445
|
});
|
|
377
446
|
});
|
|
378
|
-
return
|
|
447
|
+
return payloads;
|
|
379
448
|
}
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
449
|
+
returnRecordsWithoutIds(payloads, response) {
|
|
450
|
+
const missingRecords = payloads.filter((payload) => {
|
|
451
|
+
return !response.data.results.some((result) => {
|
|
452
|
+
return result.properties[payload.object_details.id_field_name] === payload.object_details.id_field_value;
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
return missingRecords;
|
|
456
|
+
}
|
|
457
|
+
createAssociationPayloads(payloads) {
|
|
458
|
+
const associationPayloads = payloads.flatMap((payload) => Array.isArray(payload.associations)
|
|
459
|
+
? payload.associations.map((association) => ({
|
|
460
|
+
object_details: {
|
|
461
|
+
object_type: association.object_type,
|
|
462
|
+
id_field_name: association.id_field_name,
|
|
463
|
+
id_field_value: association.id_field_value,
|
|
464
|
+
from_record_id: association.from_record_id
|
|
465
|
+
},
|
|
466
|
+
association_details: {
|
|
467
|
+
association_label: association.association_label
|
|
468
|
+
}
|
|
469
|
+
}))
|
|
470
|
+
: []);
|
|
471
|
+
return this.groupPayloads(associationPayloads, ['object_type', 'id_field_name']);
|
|
472
|
+
}
|
|
473
|
+
groupPayloads(associations, groupBy) {
|
|
474
|
+
const groupedPayloads = [];
|
|
475
|
+
const groups = associations.reduce((acc, payload) => {
|
|
476
|
+
const key = groupBy.map((prop) => payload.object_details[prop]).join('_');
|
|
477
|
+
if (!acc[key]) {
|
|
478
|
+
acc[key] = [];
|
|
395
479
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
});
|
|
404
|
-
const existingRecords = this.insertRecordIds(payloadsDeepCopy, readResponse).filter((payload) => payload.object_details.from_record_id);
|
|
405
|
-
response = await this.batchObjectRequest(this.hubspotSyncMode, this.fromObjectType, {
|
|
406
|
-
inputs: existingRecords.map(({ object_details: { from_id_field_value }, properties, sensitiveProperties }) => {
|
|
407
|
-
return {
|
|
408
|
-
idProperty: this.fromIdFieldName,
|
|
409
|
-
id: from_id_field_value,
|
|
410
|
-
properties: { ...properties, ...sensitiveProperties }
|
|
411
|
-
};
|
|
412
|
-
})
|
|
413
|
-
});
|
|
414
|
-
return this.insertRecordIds(existingRecords, response).filter((payload) => payload.object_details.from_id_field_value);
|
|
480
|
+
acc[key].push(payload);
|
|
481
|
+
return acc;
|
|
482
|
+
}, {});
|
|
483
|
+
for (const key in groups) {
|
|
484
|
+
const items = groups[key];
|
|
485
|
+
for (let i = 0; i < items.length; i += constants_1.MAX_HUBSPOT_BATCH_SIZE) {
|
|
486
|
+
groupedPayloads.push(items.slice(i, i + constants_1.MAX_HUBSPOT_BATCH_SIZE));
|
|
415
487
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
inputs: nonExistingRecords.map(({ object_details: { from_id_field_value: fromIdFieldValue }, properties, sensitiveProperties }) => {
|
|
427
|
-
return {
|
|
428
|
-
idProperty: this.fromIdFieldName,
|
|
429
|
-
properties: { ...properties, ...sensitiveProperties, [this.fromIdFieldName]: fromIdFieldValue }
|
|
430
|
-
};
|
|
431
|
-
})
|
|
432
|
-
});
|
|
433
|
-
return this.insertRecordIds(nonExistingRecords, response).filter((payload) => payload.object_details.from_id_field_value);
|
|
488
|
+
}
|
|
489
|
+
return groupedPayloads;
|
|
490
|
+
}
|
|
491
|
+
async sendAssociatedRecords(payloads) {
|
|
492
|
+
switch (this.associationSyncMode) {
|
|
493
|
+
case exports.AssociationSyncMode.Upsert: {
|
|
494
|
+
return await this.upsertAssociatedRecords(payloads);
|
|
495
|
+
}
|
|
496
|
+
case exports.AssociationSyncMode.Read: {
|
|
497
|
+
return await this.readAssociatedRecords(payloads);
|
|
434
498
|
}
|
|
435
499
|
}
|
|
436
500
|
}
|
|
501
|
+
async readAssociatedRecords(groupedPayloads) {
|
|
502
|
+
const requests = groupedPayloads.map(async (payloads) => {
|
|
503
|
+
const { object_type: objectType } = payloads[0].object_details;
|
|
504
|
+
return await this.batchObjectRequest(exports.AssociationSyncMode.Read, objectType, {
|
|
505
|
+
idProperty: payloads[0].object_details.id_field_name,
|
|
506
|
+
properties: [payloads[0].object_details.id_field_name],
|
|
507
|
+
inputs: payloads.map((payload) => {
|
|
508
|
+
return {
|
|
509
|
+
id: payload.object_details.id_field_value
|
|
510
|
+
};
|
|
511
|
+
})
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
const responses = await Promise.all(requests);
|
|
515
|
+
return this.returnAssociatedRecordsWithIds(groupedPayloads, responses);
|
|
516
|
+
}
|
|
517
|
+
async upsertAssociatedRecords(groupedPayloads) {
|
|
518
|
+
const requests = groupedPayloads.map(async (payloads) => {
|
|
519
|
+
const { object_type: objectType } = payloads[0].object_details;
|
|
520
|
+
return await this.batchObjectRequest(exports.AssociationSyncMode.Upsert, objectType, {
|
|
521
|
+
inputs: payloads.map((payload) => {
|
|
522
|
+
return {
|
|
523
|
+
idProperty: payload.object_details.id_field_name,
|
|
524
|
+
id: payload.object_details.id_field_value,
|
|
525
|
+
properties: {
|
|
526
|
+
[payload.object_details.id_field_name]: payload.object_details.id_field_value
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
})
|
|
530
|
+
});
|
|
531
|
+
});
|
|
532
|
+
const responses = await Promise.all(requests);
|
|
533
|
+
return this.returnAssociatedRecordsWithIds(groupedPayloads, responses);
|
|
534
|
+
}
|
|
535
|
+
returnAssociatedRecordsWithIds(groupedPayloads, responses) {
|
|
536
|
+
responses.forEach((response, index) => {
|
|
537
|
+
const payloads = groupedPayloads[index];
|
|
538
|
+
response?.data?.results.forEach((result) => {
|
|
539
|
+
payloads
|
|
540
|
+
.filter((payload) => payload.object_details.id_field_value ==
|
|
541
|
+
result.properties[payload.object_details.id_field_name])
|
|
542
|
+
.forEach((payload) => (payload.object_details.record_id = result.id));
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
return groupedPayloads
|
|
546
|
+
.flat()
|
|
547
|
+
.filter((payload) => payload.object_details.record_id);
|
|
548
|
+
}
|
|
437
549
|
async batchAssociationsRequest(body, toObjectType) {
|
|
438
|
-
return this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v4/associations/${this.
|
|
550
|
+
return this.request(`${properties_1.HUBSPOT_BASE_URL}/crm/v4/associations/${this.objectType}/${toObjectType}/batch/create`, {
|
|
439
551
|
method: 'POST',
|
|
440
552
|
json: body
|
|
441
553
|
});
|
|
442
554
|
}
|
|
443
|
-
async
|
|
444
|
-
const
|
|
445
|
-
|
|
555
|
+
async sendAssociations(payloads) {
|
|
556
|
+
const groupedPayloads = this.groupPayloads(payloads, [
|
|
557
|
+
'object_type'
|
|
558
|
+
]);
|
|
446
559
|
function getAssociationType(associationLabel) {
|
|
447
560
|
const [associationCategory, associationTypeId] = associationLabel.split(':');
|
|
448
561
|
return { associationCategory, associationTypeId };
|
|
449
562
|
}
|
|
450
|
-
const requests =
|
|
451
|
-
const toObjectType =
|
|
452
|
-
const inputs =
|
|
453
|
-
const { associationCategory, associationTypeId } = getAssociationType(
|
|
563
|
+
const requests = groupedPayloads.map(async (payloads) => {
|
|
564
|
+
const toObjectType = payloads[0].object_details.object_type;
|
|
565
|
+
const inputs = payloads.map((payload) => {
|
|
566
|
+
const { associationCategory, associationTypeId } = getAssociationType(payload.association_details.association_label);
|
|
454
567
|
const input = {
|
|
455
568
|
types: [
|
|
456
569
|
{
|
|
@@ -459,10 +572,10 @@ class HubspotClient {
|
|
|
459
572
|
}
|
|
460
573
|
],
|
|
461
574
|
from: {
|
|
462
|
-
id:
|
|
575
|
+
id: payload.object_details.from_record_id
|
|
463
576
|
},
|
|
464
577
|
to: {
|
|
465
|
-
id:
|
|
578
|
+
id: payload.object_details.record_id
|
|
466
579
|
}
|
|
467
580
|
};
|
|
468
581
|
return input;
|