@erxes/api-shared 0.0.0-stage → 3.2.19-2
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/LICENSE.md +672 -0
- package/core-modules/dist/erxes-api-shared-core-modules.cjs.d.ts +2 -0
- package/core-modules/dist/erxes-api-shared-core-modules.cjs.dev.js +6685 -0
- package/core-modules/dist/erxes-api-shared-core-modules.cjs.js +7 -0
- package/core-modules/dist/erxes-api-shared-core-modules.cjs.prod.js +6685 -0
- package/core-modules/dist/erxes-api-shared-core-modules.esm.js +6298 -0
- package/core-modules/package.json +5 -0
- package/core-types/dist/erxes-api-shared-core-types.cjs.d.ts +2 -0
- package/core-types/dist/erxes-api-shared-core-types.cjs.dev.js +12 -0
- package/core-types/dist/erxes-api-shared-core-types.cjs.js +7 -0
- package/core-types/dist/erxes-api-shared-core-types.cjs.prod.js +12 -0
- package/core-types/dist/erxes-api-shared-core-types.esm.js +8 -0
- package/core-types/package.json +5 -0
- package/dist/declarations/src/core-modules/approval/approvalChangeTypes.d.ts +15 -0
- package/dist/declarations/src/core-modules/approval/approvalChangeTypes.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/approval/checkApprovalLock.d.ts +7 -0
- package/dist/declarations/src/core-modules/approval/checkApprovalLock.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/approval/constants.d.ts +37 -0
- package/dist/declarations/src/core-modules/approval/constants.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/approval/index.d.ts +7 -0
- package/dist/declarations/src/core-modules/approval/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/approval/initApproval.d.ts +9 -0
- package/dist/declarations/src/core-modules/approval/initApproval.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/approval/types.d.ts +164 -0
- package/dist/declarations/src/core-modules/approval/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/approval/zodSchemas.d.ts +125 -0
- package/dist/declarations/src/core-modules/approval/zodSchemas.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/apps/@types/app.d.ts +15 -0
- package/dist/declarations/src/core-modules/apps/@types/app.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/apps/db/definitions/apps.d.ts +13 -0
- package/dist/declarations/src/core-modules/apps/db/definitions/apps.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/apps/index.d.ts +3 -0
- package/dist/declarations/src/core-modules/apps/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/actionErrorPolicy.d.ts +68 -0
- package/dist/declarations/src/core-modules/automations/actionErrorPolicy.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/actionOutcome.d.ts +51 -0
- package/dist/declarations/src/core-modules/automations/actionOutcome.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/constants.d.ts +101 -0
- package/dist/declarations/src/core-modules/automations/constants.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/definitions/aiAgents.d.ts +141 -0
- package/dist/declarations/src/core-modules/automations/definitions/aiAgents.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/definitions/automations.d.ts +868 -0
- package/dist/declarations/src/core-modules/automations/definitions/automations.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/definitions/executions.d.ts +316 -0
- package/dist/declarations/src/core-modules/automations/definitions/executions.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/definitions/index.d.ts +4 -0
- package/dist/declarations/src/core-modules/automations/definitions/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/index.d.ts +14 -0
- package/dist/declarations/src/core-modules/automations/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/outputResolvers.d.ts +67 -0
- package/dist/declarations/src/core-modules/automations/outputResolvers.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/reEnrollment.d.ts +23 -0
- package/dist/declarations/src/core-modules/automations/reEnrollment.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/segmentMembership.d.ts +19 -0
- package/dist/declarations/src/core-modules/automations/segmentMembership.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/sendAutomationMessage.d.ts +51 -0
- package/dist/declarations/src/core-modules/automations/sendAutomationMessage.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/setupAutomationProducers.d.ts +4 -0
- package/dist/declarations/src/core-modules/automations/setupAutomationProducers.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/typeUtils.d.ts +2 -0
- package/dist/declarations/src/core-modules/automations/typeUtils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/types.d.ts +474 -0
- package/dist/declarations/src/core-modules/automations/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/utils.d.ts +38 -0
- package/dist/declarations/src/core-modules/automations/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/workflowValidation.d.ts +3 -0
- package/dist/declarations/src/core-modules/automations/workflowValidation.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/automations/zodTypes.d.ts +2366 -0
- package/dist/declarations/src/core-modules/automations/zodTypes.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/clientPortal.d.ts +375 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/clientPortal.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/comment.d.ts +53 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/comment.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/cpNotification.d.ts +110 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/cpNotification.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/cpUser.d.ts +828 -0
- package/dist/declarations/src/core-modules/client-portals/definitions/cpUser.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/client-portals/index.d.ts +5 -0
- package/dist/declarations/src/core-modules/client-portals/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/db/definitions/common.d.ts +77 -0
- package/dist/declarations/src/core-modules/common/db/definitions/common.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/createEventHandlers.d.ts +8 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/createEventHandlers.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/generateEventHandlers.d.ts +4 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/generateEventHandlers.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/index.d.ts +5 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/runtimeContext.d.ts +9 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/runtimeContext.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/schemas.d.ts +82 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/schemas.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/types.d.ts +87 -0
- package/dist/declarations/src/core-modules/common/eventHandlers/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/index.d.ts +5 -0
- package/dist/declarations/src/core-modules/common/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/references/getRecordReferenceFields.d.ts +57 -0
- package/dist/declarations/src/core-modules/common/references/getRecordReferenceFields.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/references/index.d.ts +6 -0
- package/dist/declarations/src/core-modules/common/references/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/references/initRecordReferences.d.ts +4 -0
- package/dist/declarations/src/core-modules/common/references/initRecordReferences.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/references/resolveRecordReferencePlaceholders.d.ts +12 -0
- package/dist/declarations/src/core-modules/common/references/resolveRecordReferencePlaceholders.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/references/resolveRecordReferenceValue.d.ts +6 -0
- package/dist/declarations/src/core-modules/common/references/resolveRecordReferenceValue.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/references/types.d.ts +63 -0
- package/dist/declarations/src/core-modules/common/references/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/common/routeToModuleProducer.d.ts +55 -0
- package/dist/declarations/src/core-modules/common/routeToModuleProducer.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/blocksToHtml.d.ts +72 -0
- package/dist/declarations/src/core-modules/email-content/blocksToHtml.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/constants.d.ts +5 -0
- package/dist/declarations/src/core-modules/email-content/constants.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/emailFooter.d.ts +5 -0
- package/dist/declarations/src/core-modules/email-content/emailFooter.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/expandRepeatRows.d.ts +9 -0
- package/dist/declarations/src/core-modules/email-content/expandRepeatRows.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/index.d.ts +9 -0
- package/dist/declarations/src/core-modules/email-content/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/renderEmailContent.d.ts +19 -0
- package/dist/declarations/src/core-modules/email-content/renderEmailContent.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/replacePlaceholders.d.ts +36 -0
- package/dist/declarations/src/core-modules/email-content/replacePlaceholders.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/types.d.ts +48 -0
- package/dist/declarations/src/core-modules/email-content/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/email-content/unresolvedPlaceholders.d.ts +4 -0
- package/dist/declarations/src/core-modules/email-content/unresolvedPlaceholders.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/forms/index.d.ts +3 -0
- package/dist/declarations/src/core-modules/forms/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/forms/types.d.ts +55 -0
- package/dist/declarations/src/core-modules/forms/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/forms/utils.d.ts +4 -0
- package/dist/declarations/src/core-modules/forms/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/index.d.ts +8 -0
- package/dist/declarations/src/core-modules/import-export/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/types.d.ts +181 -0
- package/dist/declarations/src/core-modules/import-export/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/utils/exportCursor.d.ts +14 -0
- package/dist/declarations/src/core-modules/import-export/utils/exportCursor.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/utils/headerMatcher.d.ts +32 -0
- package/dist/declarations/src/core-modules/import-export/utils/headerMatcher.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/utils/importExportRuntime.d.ts +32 -0
- package/dist/declarations/src/core-modules/import-export/utils/importExportRuntime.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/utils/importUtils.d.ts +25 -0
- package/dist/declarations/src/core-modules/import-export/utils/importUtils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/worker.d.ts +8 -0
- package/dist/declarations/src/core-modules/import-export/worker.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/import-export/zodSchemas.d.ts +111 -0
- package/dist/declarations/src/core-modules/import-export/zodSchemas.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/index.d.ts +16 -0
- package/dist/declarations/src/core-modules/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/activityLog/builder.d.ts +3 -0
- package/dist/declarations/src/core-modules/logs/activityLog/builder.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/activityLog/index.d.ts +5 -0
- package/dist/declarations/src/core-modules/logs/activityLog/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/activityLog/sharedBuilders.d.ts +18 -0
- package/dist/declarations/src/core-modules/logs/activityLog/sharedBuilders.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/activityLog/types.d.ts +21 -0
- package/dist/declarations/src/core-modules/logs/activityLog/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/activityLog/utils.d.ts +10 -0
- package/dist/declarations/src/core-modules/logs/activityLog/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/activityLogUtils.d.ts +72 -0
- package/dist/declarations/src/core-modules/logs/activityLogUtils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/definitions/activityLog.d.ts +84 -0
- package/dist/declarations/src/core-modules/logs/definitions/activityLog.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/definitions/logs.d.ts +39 -0
- package/dist/declarations/src/core-modules/logs/definitions/logs.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/index.d.ts +6 -0
- package/dist/declarations/src/core-modules/logs/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/logs/types.d.ts +15 -0
- package/dist/declarations/src/core-modules/logs/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailAddresses.d.ts +73 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailAddresses.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailDeliveries.d.ts +115 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailDeliveries.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailRamp.d.ts +65 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailRamp.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailSenders.d.ts +58 -0
- package/dist/declarations/src/core-modules/notifications/definitions/emailSenders.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/definitions/notificationSettings.d.ts +66 -0
- package/dist/declarations/src/core-modules/notifications/definitions/notificationSettings.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/definitions/notifications.d.ts +89 -0
- package/dist/declarations/src/core-modules/notifications/definitions/notifications.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/index.d.ts +8 -0
- package/dist/declarations/src/core-modules/notifications/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/notifications/utils.d.ts +85 -0
- package/dist/declarations/src/core-modules/notifications/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/permissions/db/definitions/permissions.d.ts +60 -0
- package/dist/declarations/src/core-modules/permissions/db/definitions/permissions.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/permissions/index.d.ts +4 -0
- package/dist/declarations/src/core-modules/permissions/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/permissions/user-actions-map.d.ts +4 -0
- package/dist/declarations/src/core-modules/permissions/user-actions-map.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/permissions/utils.d.ts +22 -0
- package/dist/declarations/src/core-modules/permissions/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/filter.d.ts +5 -0
- package/dist/declarations/src/core-modules/properties/filter.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/importExport.d.ts +18 -0
- package/dist/declarations/src/core-modules/properties/importExport.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/index.d.ts +10 -0
- package/dist/declarations/src/core-modules/properties/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/keys.d.ts +46 -0
- package/dist/declarations/src/core-modules/properties/keys.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/mergeRows.d.ts +8 -0
- package/dist/declarations/src/core-modules/properties/mergeRows.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/operators.d.ts +6 -0
- package/dist/declarations/src/core-modules/properties/operators.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/options.d.ts +10 -0
- package/dist/declarations/src/core-modules/properties/options.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/setupPropertyProducers.d.ts +4 -0
- package/dist/declarations/src/core-modules/properties/setupPropertyProducers.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/types.d.ts +14 -0
- package/dist/declarations/src/core-modules/properties/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/properties/valueUsage.d.ts +56 -0
- package/dist/declarations/src/core-modules/properties/valueUsage.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/dependencies.d.ts +6 -0
- package/dist/declarations/src/core-modules/segments/dependencies.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/evaluate.d.ts +11 -0
- package/dist/declarations/src/core-modules/segments/evaluate.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/evaluateBatch.d.ts +42 -0
- package/dist/declarations/src/core-modules/segments/evaluateBatch.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/evaluateFieldsRouter.d.ts +29 -0
- package/dist/declarations/src/core-modules/segments/evaluateFieldsRouter.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/evaluateOwned.d.ts +27 -0
- package/dist/declarations/src/core-modules/segments/evaluateOwned.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/events.d.ts +45 -0
- package/dist/declarations/src/core-modules/segments/events.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/fieldBuilders.d.ts +35 -0
- package/dist/declarations/src/core-modules/segments/fieldBuilders.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/fieldMeta.d.ts +62 -0
- package/dist/declarations/src/core-modules/segments/fieldMeta.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/fieldRequests.d.ts +33 -0
- package/dist/declarations/src/core-modules/segments/fieldRequests.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/fingerprint.d.ts +6 -0
- package/dist/declarations/src/core-modules/segments/fingerprint.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/index.d.ts +31 -0
- package/dist/declarations/src/core-modules/segments/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/joinChanges.d.ts +11 -0
- package/dist/declarations/src/core-modules/segments/joinChanges.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/materialized.d.ts +9 -0
- package/dist/declarations/src/core-modules/segments/materialized.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/measureRelations.d.ts +18 -0
- package/dist/declarations/src/core-modules/segments/measureRelations.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/memberQuery.d.ts +13 -0
- package/dist/declarations/src/core-modules/segments/memberQuery.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/membership.d.ts +24 -0
- package/dist/declarations/src/core-modules/segments/membership.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/mongoFilter.d.ts +15 -0
- package/dist/declarations/src/core-modules/segments/mongoFilter.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/nodeRefs.d.ts +5 -0
- package/dist/declarations/src/core-modules/segments/nodeRefs.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/nodes.d.ts +42 -0
- package/dist/declarations/src/core-modules/segments/nodes.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/operators.d.ts +46 -0
- package/dist/declarations/src/core-modules/segments/operators.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/ownedSource.d.ts +7 -0
- package/dist/declarations/src/core-modules/segments/ownedSource.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/plan.d.ts +35 -0
- package/dist/declarations/src/core-modules/segments/plan.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/relationRegistry.d.ts +33 -0
- package/dist/declarations/src/core-modules/segments/relationRegistry.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/setupSegmentProducers.d.ts +4 -0
- package/dist/declarations/src/core-modules/segments/setupSegmentProducers.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/subjectsReachedBy.d.ts +11 -0
- package/dist/declarations/src/core-modules/segments/subjectsReachedBy.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/timeZone.d.ts +2 -0
- package/dist/declarations/src/core-modules/segments/timeZone.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/types.d.ts +67 -0
- package/dist/declarations/src/core-modules/segments/types.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/utils.d.ts +4 -0
- package/dist/declarations/src/core-modules/segments/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/walkNodes.d.ts +9 -0
- package/dist/declarations/src/core-modules/segments/walkNodes.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/zodSchemas.d.ts +532 -0
- package/dist/declarations/src/core-modules/segments/zodSchemas.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/segments/zonedTime.d.ts +25 -0
- package/dist/declarations/src/core-modules/segments/zonedTime.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/templates/index.d.ts +2 -0
- package/dist/declarations/src/core-modules/templates/index.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/templates/utils.d.ts +11 -0
- package/dist/declarations/src/core-modules/templates/utils.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/users/constants.d.ts +114 -0
- package/dist/declarations/src/core-modules/users/constants.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/users/db/definitions/users.d.ts +24 -0
- package/dist/declarations/src/core-modules/users/db/definitions/users.d.ts.map +1 -0
- package/dist/declarations/src/core-modules/users/index.d.ts +3 -0
- package/dist/declarations/src/core-modules/users/index.d.ts.map +1 -0
- package/dist/declarations/src/core-types/common.d.ts +149 -0
- package/dist/declarations/src/core-types/common.d.ts.map +1 -0
- package/dist/declarations/src/core-types/index.d.ts +20 -0
- package/dist/declarations/src/core-types/index.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/app/app.d.ts +12 -0
- package/dist/declarations/src/core-types/modules/app/app.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/automations/automations.d.ts +19 -0
- package/dist/declarations/src/core-types/modules/automations/automations.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/contacts/company.d.ts +53 -0
- package/dist/declarations/src/core-types/modules/contacts/company.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/contacts/contacts-common.d.ts +32 -0
- package/dist/declarations/src/core-types/modules/contacts/contacts-common.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/contacts/customer.d.ts +74 -0
- package/dist/declarations/src/core-types/modules/contacts/customer.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/emailTemplates/emailTemplate.d.ts +18 -0
- package/dist/declarations/src/core-types/modules/emailTemplates/emailTemplate.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/logs/logs.d.ts +28 -0
- package/dist/declarations/src/core-types/modules/logs/logs.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/permissions/permission.d.ts +56 -0
- package/dist/declarations/src/core-types/modules/permissions/permission.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/permissions/role.d.ts +21 -0
- package/dist/declarations/src/core-types/modules/permissions/role.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/products/product.d.ts +76 -0
- package/dist/declarations/src/core-types/modules/products/product.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/products/productCategory.d.ts +26 -0
- package/dist/declarations/src/core-types/modules/products/productCategory.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/products/productConfig.d.ts +9 -0
- package/dist/declarations/src/core-types/modules/products/productConfig.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/products/uom.d.ts +11 -0
- package/dist/declarations/src/core-types/modules/products/uom.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/relations/relations.d.ts +13 -0
- package/dist/declarations/src/core-types/modules/relations/relations.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/saas/organization.d.ts +8 -0
- package/dist/declarations/src/core-types/modules/saas/organization.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/tags/tag.d.ts +16 -0
- package/dist/declarations/src/core-types/modules/tags/tag.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/team-member/structure.d.ts +19 -0
- package/dist/declarations/src/core-types/modules/team-member/structure.d.ts.map +1 -0
- package/dist/declarations/src/core-types/modules/team-member/user.d.ts +90 -0
- package/dist/declarations/src/core-types/modules/team-member/user.d.ts.map +1 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/agent-tools/auth.d.ts +18 -0
- package/dist/declarations/src/utils/agent-tools/auth.d.ts.map +1 -0
- package/dist/declarations/src/utils/agent-tools/endpoints.d.ts +16 -0
- package/dist/declarations/src/utils/agent-tools/endpoints.d.ts.map +1 -0
- package/dist/declarations/src/utils/agent-tools/index.d.ts +6 -0
- package/dist/declarations/src/utils/agent-tools/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/agent-tools/manifest.d.ts +11 -0
- package/dist/declarations/src/utils/agent-tools/manifest.d.ts.map +1 -0
- package/dist/declarations/src/utils/agent-tools/responseLimit.d.ts +26 -0
- package/dist/declarations/src/utils/agent-tools/responseLimit.d.ts.map +1 -0
- package/dist/declarations/src/utils/agent-tools/types.d.ts +48 -0
- package/dist/declarations/src/utils/agent-tools/types.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/beforeResolvers.d.ts +41 -0
- package/dist/declarations/src/utils/apollo/beforeResolvers.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/commonTypeDefs.d.ts +7 -0
- package/dist/declarations/src/utils/apollo/commonTypeDefs.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/constants.d.ts +3 -0
- package/dist/declarations/src/utils/apollo/constants.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/customScalars.d.ts +6 -0
- package/dist/declarations/src/utils/apollo/customScalars.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/expectedErrorPlugin.d.ts +11 -0
- package/dist/declarations/src/utils/apollo/expectedErrorPlugin.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/index.d.ts +10 -0
- package/dist/declarations/src/utils/apollo/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/runBeforeResolvers.d.ts +27 -0
- package/dist/declarations/src/utils/apollo/runBeforeResolvers.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/utils.d.ts +5 -0
- package/dist/declarations/src/utils/apollo/utils.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/wrapperMutations.d.ts +8 -0
- package/dist/declarations/src/utils/apollo/wrapperMutations.d.ts.map +1 -0
- package/dist/declarations/src/utils/apollo/wrapperResolvers.d.ts +8 -0
- package/dist/declarations/src/utils/apollo/wrapperResolvers.d.ts.map +1 -0
- package/dist/declarations/src/utils/bulkUtils.d.ts +7 -0
- package/dist/declarations/src/utils/bulkUtils.d.ts.map +1 -0
- package/dist/declarations/src/utils/constants.d.ts +40 -0
- package/dist/declarations/src/utils/constants.d.ts.map +1 -0
- package/dist/declarations/src/utils/editor.d.ts +45 -0
- package/dist/declarations/src/utils/editor.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/address.d.ts +10 -0
- package/dist/declarations/src/utils/email/address.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/attachments.d.ts +12 -0
- package/dist/declarations/src/utils/email/attachments.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/config.d.ts +10 -0
- package/dist/declarations/src/utils/email/config.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/constants.d.ts +6 -0
- package/dist/declarations/src/utils/email/constants.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/index.d.ts +12 -0
- package/dist/declarations/src/utils/email/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/providers/sendgrid.d.ts +17 -0
- package/dist/declarations/src/utils/email/providers/sendgrid.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/providers/sendgridEvents.d.ts +18 -0
- package/dist/declarations/src/utils/email/providers/sendgridEvents.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/providers/ses.d.ts +19 -0
- package/dist/declarations/src/utils/email/providers/ses.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/providers/smtp.d.ts +14 -0
- package/dist/declarations/src/utils/email/providers/smtp.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/resolveProvider.d.ts +6 -0
- package/dist/declarations/src/utils/email/resolveProvider.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/service.d.ts +50 -0
- package/dist/declarations/src/utils/email/service.d.ts.map +1 -0
- package/dist/declarations/src/utils/email/types.d.ts +87 -0
- package/dist/declarations/src/utils/email/types.d.ts.map +1 -0
- package/dist/declarations/src/utils/errorClassifier.d.ts +56 -0
- package/dist/declarations/src/utils/errorClassifier.d.ts.map +1 -0
- package/dist/declarations/src/utils/file/read.d.ts +14 -0
- package/dist/declarations/src/utils/file/read.d.ts.map +1 -0
- package/dist/declarations/src/utils/file/upload.d.ts +10 -0
- package/dist/declarations/src/utils/file/upload.d.ts.map +1 -0
- package/dist/declarations/src/utils/graphqlPubSub.d.ts +3 -0
- package/dist/declarations/src/utils/graphqlPubSub.d.ts.map +1 -0
- package/dist/declarations/src/utils/headers/get-hostname.d.ts +5 -0
- package/dist/declarations/src/utils/headers/get-hostname.d.ts.map +1 -0
- package/dist/declarations/src/utils/headers/index.d.ts +5 -0
- package/dist/declarations/src/utils/headers/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/headers/sanitize.d.ts +3 -0
- package/dist/declarations/src/utils/headers/sanitize.d.ts.map +1 -0
- package/dist/declarations/src/utils/headers/subdomain.d.ts +4 -0
- package/dist/declarations/src/utils/headers/subdomain.d.ts.map +1 -0
- package/dist/declarations/src/utils/headers/user.d.ts +14 -0
- package/dist/declarations/src/utils/headers/user.d.ts.map +1 -0
- package/dist/declarations/src/utils/index.d.ts +28 -0
- package/dist/declarations/src/utils/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/knowledge.d.ts +50 -0
- package/dist/declarations/src/utils/knowledge.d.ts.map +1 -0
- package/dist/declarations/src/utils/logs/index.d.ts +103 -0
- package/dist/declarations/src/utils/logs/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/cursor-util.d.ts +41 -0
- package/dist/declarations/src/utils/mongo/cursor-util.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/generate-models.d.ts +4 -0
- package/dist/declarations/src/utils/mongo/generate-models.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/index.d.ts +6 -0
- package/dist/declarations/src/utils/mongo/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/mongo-connection.d.ts +5 -0
- package/dist/declarations/src/utils/mongo/mongo-connection.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/mongoose-types.d.ts +22 -0
- package/dist/declarations/src/utils/mongo/mongoose-types.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/mongoose-utils.d.ts +30 -0
- package/dist/declarations/src/utils/mongo/mongoose-utils.d.ts.map +1 -0
- package/dist/declarations/src/utils/mongo/search-tokens.d.ts +21 -0
- package/dist/declarations/src/utils/mongo/search-tokens.d.ts.map +1 -0
- package/dist/declarations/src/utils/mq-worker.d.ts +19 -0
- package/dist/declarations/src/utils/mq-worker.d.ts.map +1 -0
- package/dist/declarations/src/utils/random.d.ts +3 -0
- package/dist/declarations/src/utils/random.d.ts.map +1 -0
- package/dist/declarations/src/utils/redis.d.ts +4 -0
- package/dist/declarations/src/utils/redis.d.ts.map +1 -0
- package/dist/declarations/src/utils/saas/index.d.ts +3 -0
- package/dist/declarations/src/utils/saas/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/saas/saas-mongo-connection.d.ts +59 -0
- package/dist/declarations/src/utils/saas/saas-mongo-connection.d.ts.map +1 -0
- package/dist/declarations/src/utils/saas/types.d.ts +96 -0
- package/dist/declarations/src/utils/saas/types.d.ts.map +1 -0
- package/dist/declarations/src/utils/sanitize.d.ts +3 -0
- package/dist/declarations/src/utils/sanitize.d.ts.map +1 -0
- package/dist/declarations/src/utils/sentry-init.d.ts +15 -0
- package/dist/declarations/src/utils/sentry-init.d.ts.map +1 -0
- package/dist/declarations/src/utils/sentry-instrument.d.ts +2 -0
- package/dist/declarations/src/utils/sentry-instrument.d.ts.map +1 -0
- package/dist/declarations/src/utils/serializablePayload.d.ts +11 -0
- package/dist/declarations/src/utils/serializablePayload.d.ts.map +1 -0
- package/dist/declarations/src/utils/service-discovery.d.ts +25 -0
- package/dist/declarations/src/utils/service-discovery.d.ts.map +1 -0
- package/dist/declarations/src/utils/start-plugin.d.ts +85 -0
- package/dist/declarations/src/utils/start-plugin.d.ts.map +1 -0
- package/dist/declarations/src/utils/string.d.ts +82 -0
- package/dist/declarations/src/utils/string.d.ts.map +1 -0
- package/dist/declarations/src/utils/trpc/index.d.ts +79 -0
- package/dist/declarations/src/utils/trpc/index.d.ts.map +1 -0
- package/dist/declarations/src/utils/trpc/sendCoreModuleProducer.d.ts +53 -0
- package/dist/declarations/src/utils/trpc/sendCoreModuleProducer.d.ts.map +1 -0
- package/dist/declarations/src/utils/utils.d.ts +69 -0
- package/dist/declarations/src/utils/utils.d.ts.map +1 -0
- package/dist/erxes-api-shared.cjs.d.ts +3 -0
- package/dist/erxes-api-shared.cjs.dev.js +7 -0
- package/dist/erxes-api-shared.cjs.js +7 -0
- package/dist/erxes-api-shared.cjs.prod.js +7 -0
- package/dist/erxes-api-shared.esm.js +3 -0
- package/dist/start-plugin-576e707d.cjs.prod.js +23223 -0
- package/dist/start-plugin-6e76556c.esm.js +22742 -0
- package/dist/start-plugin-89fa2bd2.cjs.dev.js +23225 -0
- package/package.json +105 -4
- package/src/common-modules/payment/worker.ts +53 -0
- package/src/core-modules/approval/approvalChangeTypes.ts +31 -0
- package/src/core-modules/approval/checkApprovalLock.ts +85 -0
- package/src/core-modules/approval/constants.ts +45 -0
- package/src/core-modules/approval/index.ts +6 -0
- package/src/core-modules/approval/initApproval.ts +59 -0
- package/src/core-modules/approval/types.ts +206 -0
- package/src/core-modules/approval/zodSchemas.ts +55 -0
- package/src/core-modules/apps/@types/app.ts +15 -0
- package/src/core-modules/apps/db/definitions/apps.ts +30 -0
- package/src/core-modules/apps/index.ts +2 -0
- package/src/core-modules/automations/actionErrorPolicy.test.ts +125 -0
- package/src/core-modules/automations/actionErrorPolicy.ts +162 -0
- package/src/core-modules/automations/actionInputs.test.ts +70 -0
- package/src/core-modules/automations/actionOutcome.test.ts +87 -0
- package/src/core-modules/automations/actionOutcome.ts +128 -0
- package/src/core-modules/automations/constants.ts +181 -0
- package/src/core-modules/automations/definitions/aiAgents.ts +343 -0
- package/src/core-modules/automations/definitions/automations.ts +207 -0
- package/src/core-modules/automations/definitions/executions.ts +190 -0
- package/src/core-modules/automations/definitions/index.ts +3 -0
- package/src/core-modules/automations/getValueByPath.test.ts +49 -0
- package/src/core-modules/automations/index.ts +13 -0
- package/src/core-modules/automations/outputResolvers.test.ts +97 -0
- package/src/core-modules/automations/outputResolvers.ts +1238 -0
- package/src/core-modules/automations/reEnrollment.ts +34 -0
- package/src/core-modules/automations/segmentMembership.ts +34 -0
- package/src/core-modules/automations/sendAutomationMessage.ts +219 -0
- package/src/core-modules/automations/setPropertyOutcome.test.ts +105 -0
- package/src/core-modules/automations/setPropertyRows.test.ts +61 -0
- package/src/core-modules/automations/setupAutomationProducers.ts +187 -0
- package/src/core-modules/automations/typeUtils.ts +3 -0
- package/src/core-modules/automations/types.ts +577 -0
- package/src/core-modules/automations/utils.ts +1128 -0
- package/src/core-modules/automations/workflowValidation.ts +32 -0
- package/src/core-modules/automations/zodTypes.ts +221 -0
- package/src/core-modules/client-portals/definitions/clientPortal.ts +230 -0
- package/src/core-modules/client-portals/definitions/comment.ts +26 -0
- package/src/core-modules/client-portals/definitions/cpNotification.ts +112 -0
- package/src/core-modules/client-portals/definitions/cpUser.ts +236 -0
- package/src/core-modules/client-portals/index.ts +4 -0
- package/src/core-modules/common/db/definitions/common.ts +43 -0
- package/src/core-modules/common/eventHandlers/createEventHandlers.ts +236 -0
- package/src/core-modules/common/eventHandlers/generateEventHandlers.ts +37 -0
- package/src/core-modules/common/eventHandlers/index.ts +11 -0
- package/src/core-modules/common/eventHandlers/runtimeContext.ts +36 -0
- package/src/core-modules/common/eventHandlers/schemas.ts +53 -0
- package/src/core-modules/common/eventHandlers/types.ts +97 -0
- package/src/core-modules/common/eventHandlers/utils.ts +113 -0
- package/src/core-modules/common/index.ts +4 -0
- package/src/core-modules/common/references/fetchRecordReferenceTargets.ts +43 -0
- package/src/core-modules/common/references/getRecordReferenceFields.ts +243 -0
- package/src/core-modules/common/references/index.ts +9 -0
- package/src/core-modules/common/references/initRecordReferences.ts +84 -0
- package/src/core-modules/common/references/normalizeRecordReferenceConfig.ts +59 -0
- package/src/core-modules/common/references/resolveRecordReferencePath.ts +473 -0
- package/src/core-modules/common/references/resolveRecordReferencePlaceholders.ts +173 -0
- package/src/core-modules/common/references/resolveRecordReferenceValue.ts +41 -0
- package/src/core-modules/common/references/resolveRecordRelationIds.ts +57 -0
- package/src/core-modules/common/references/types.ts +78 -0
- package/src/core-modules/common/references/utils.ts +60 -0
- package/src/core-modules/common/references/zodInputs.ts +13 -0
- package/src/core-modules/common/routeToModuleProducer.ts +118 -0
- package/src/core-modules/email-content/blocksToHtml.ts +551 -0
- package/src/core-modules/email-content/constants.ts +4 -0
- package/src/core-modules/email-content/emailFooter.ts +17 -0
- package/src/core-modules/email-content/expandRepeatRows.test.ts +36 -0
- package/src/core-modules/email-content/expandRepeatRows.ts +59 -0
- package/src/core-modules/email-content/index.ts +8 -0
- package/src/core-modules/email-content/renderEmailContent.ts +88 -0
- package/src/core-modules/email-content/replacePlaceholders.ts +143 -0
- package/src/core-modules/email-content/types.ts +49 -0
- package/src/core-modules/email-content/unresolvedPlaceholders.ts +27 -0
- package/src/core-modules/forms/index.ts +2 -0
- package/src/core-modules/forms/types.ts +86 -0
- package/src/core-modules/forms/utils.ts +34 -0
- package/src/core-modules/import-export/index.ts +7 -0
- package/src/core-modules/import-export/types.ts +204 -0
- package/src/core-modules/import-export/utils/createCoreImportClient.ts +131 -0
- package/src/core-modules/import-export/utils/exportBatchProcess.ts +560 -0
- package/src/core-modules/import-export/utils/exportCursor.ts +47 -0
- package/src/core-modules/import-export/utils/headerMatcher.test.ts +90 -0
- package/src/core-modules/import-export/utils/headerMatcher.ts +229 -0
- package/src/core-modules/import-export/utils/importBatchProcess.ts +780 -0
- package/src/core-modules/import-export/utils/importExportError.ts +71 -0
- package/src/core-modules/import-export/utils/importExportRuntime.ts +96 -0
- package/src/core-modules/import-export/utils/importUtils.ts +59 -0
- package/src/core-modules/import-export/utils/progressUpdate.ts +25 -0
- package/src/core-modules/import-export/utils/tempWorkspace.ts +34 -0
- package/src/core-modules/import-export/worker.ts +215 -0
- package/src/core-modules/import-export/zodSchemas.ts +63 -0
- package/src/core-modules/index.ts +15 -0
- package/src/core-modules/logs/activityLog/builder.ts +232 -0
- package/src/core-modules/logs/activityLog/index.ts +4 -0
- package/src/core-modules/logs/activityLog/sharedBuilders.ts +95 -0
- package/src/core-modules/logs/activityLog/types.ts +26 -0
- package/src/core-modules/logs/activityLog/utils.ts +61 -0
- package/src/core-modules/logs/activityLogUtils.ts +677 -0
- package/src/core-modules/logs/definitions/activityLog.ts +71 -0
- package/src/core-modules/logs/definitions/logs.ts +49 -0
- package/src/core-modules/logs/index.ts +5 -0
- package/src/core-modules/logs/types.ts +16 -0
- package/src/core-modules/notifications/definitions/emailAddresses.ts +105 -0
- package/src/core-modules/notifications/definitions/emailDeliveries.ts +188 -0
- package/src/core-modules/notifications/definitions/emailRamp.ts +83 -0
- package/src/core-modules/notifications/definitions/emailSenders.ts +84 -0
- package/src/core-modules/notifications/definitions/notificationConfigs.ts +110 -0
- package/src/core-modules/notifications/definitions/notificationSettings.ts +67 -0
- package/src/core-modules/notifications/definitions/notifications.ts +130 -0
- package/src/core-modules/notifications/emailUtils.ts +88 -0
- package/src/core-modules/notifications/index.ts +7 -0
- package/src/core-modules/notifications/utils.ts +143 -0
- package/src/core-modules/permissions/db/definitions/permissions.ts +82 -0
- package/src/core-modules/permissions/index.ts +3 -0
- package/src/core-modules/permissions/oauth-scopes.test.ts +102 -0
- package/src/core-modules/permissions/user-actions-map.ts +170 -0
- package/src/core-modules/permissions/utils.ts +317 -0
- package/src/core-modules/properties/README.md +161 -0
- package/src/core-modules/properties/filter.test.ts +74 -0
- package/src/core-modules/properties/filter.ts +156 -0
- package/src/core-modules/properties/importExport.ts +159 -0
- package/src/core-modules/properties/index.ts +9 -0
- package/src/core-modules/properties/keys.test.ts +71 -0
- package/src/core-modules/properties/keys.ts +128 -0
- package/src/core-modules/properties/mergePropertyData.test.ts +65 -0
- package/src/core-modules/properties/mergeRows.ts +93 -0
- package/src/core-modules/properties/operators.ts +91 -0
- package/src/core-modules/properties/options.test.ts +119 -0
- package/src/core-modules/properties/options.ts +55 -0
- package/src/core-modules/properties/setupPropertyProducers.ts +32 -0
- package/src/core-modules/properties/types.ts +31 -0
- package/src/core-modules/properties/valueUsage.test.ts +158 -0
- package/src/core-modules/properties/valueUsage.ts +153 -0
- package/src/core-modules/segments/anniversary.test.ts +122 -0
- package/src/core-modules/segments/dependencies.test.ts +173 -0
- package/src/core-modules/segments/dependencies.ts +70 -0
- package/src/core-modules/segments/evaluate.test.ts +339 -0
- package/src/core-modules/segments/evaluate.ts +388 -0
- package/src/core-modules/segments/evaluateBatch.test.ts +233 -0
- package/src/core-modules/segments/evaluateBatch.ts +263 -0
- package/src/core-modules/segments/evaluateFieldsRouter.test.ts +148 -0
- package/src/core-modules/segments/evaluateFieldsRouter.ts +94 -0
- package/src/core-modules/segments/evaluateOwned.ts +162 -0
- package/src/core-modules/segments/events.ts +142 -0
- package/src/core-modules/segments/fieldBuilders.ts +152 -0
- package/src/core-modules/segments/fieldMeta.ts +96 -0
- package/src/core-modules/segments/fieldRequests.test.ts +302 -0
- package/src/core-modules/segments/fieldRequests.ts +172 -0
- package/src/core-modules/segments/fieldSources.test.ts +99 -0
- package/src/core-modules/segments/fingerprint.test.ts +111 -0
- package/src/core-modules/segments/fingerprint.ts +70 -0
- package/src/core-modules/segments/index.ts +30 -0
- package/src/core-modules/segments/joinChanges.test.ts +96 -0
- package/src/core-modules/segments/joinChanges.ts +67 -0
- package/src/core-modules/segments/materialized.ts +23 -0
- package/src/core-modules/segments/measureRelations.test.ts +222 -0
- package/src/core-modules/segments/measureRelations.ts +322 -0
- package/src/core-modules/segments/memberQuery.test.ts +60 -0
- package/src/core-modules/segments/memberQuery.ts +45 -0
- package/src/core-modules/segments/membership.ts +170 -0
- package/src/core-modules/segments/mongoFilter.test.ts +326 -0
- package/src/core-modules/segments/mongoFilter.ts +355 -0
- package/src/core-modules/segments/nodeRefs.ts +29 -0
- package/src/core-modules/segments/nodes.ts +48 -0
- package/src/core-modules/segments/operators.ts +243 -0
- package/src/core-modules/segments/ownedSource.ts +16 -0
- package/src/core-modules/segments/plan.test.ts +172 -0
- package/src/core-modules/segments/plan.ts +155 -0
- package/src/core-modules/segments/relationRegistry.test.ts +64 -0
- package/src/core-modules/segments/relationRegistry.ts +198 -0
- package/src/core-modules/segments/segmentReference.test.ts +142 -0
- package/src/core-modules/segments/setupSegmentProducers.ts +77 -0
- package/src/core-modules/segments/subjectsReachedBy.ts +70 -0
- package/src/core-modules/segments/timeZone.ts +56 -0
- package/src/core-modules/segments/types.ts +97 -0
- package/src/core-modules/segments/utils.ts +122 -0
- package/src/core-modules/segments/walkNodes.ts +76 -0
- package/src/core-modules/segments/zodSchemas.ts +130 -0
- package/src/core-modules/segments/zonedTime.test.ts +163 -0
- package/src/core-modules/segments/zonedTime.ts +198 -0
- package/src/core-modules/templates/index.ts +1 -0
- package/src/core-modules/templates/utils.ts +91 -0
- package/src/core-modules/users/constants.ts +318 -0
- package/src/core-modules/users/db/definitions/users.ts +226 -0
- package/src/core-modules/users/index.ts +2 -0
- package/src/core-types/common.ts +183 -0
- package/src/core-types/index.ts +19 -0
- package/src/core-types/modules/app/app.ts +13 -0
- package/src/core-types/modules/automations/automations.ts +23 -0
- package/src/core-types/modules/contacts/company.ts +70 -0
- package/src/core-types/modules/contacts/contacts-common.ts +32 -0
- package/src/core-types/modules/contacts/customer.ts +94 -0
- package/src/core-types/modules/emailTemplates/emailTemplate.ts +19 -0
- package/src/core-types/modules/emailTemplates/index.ts +1 -0
- package/src/core-types/modules/logs/logs.ts +30 -0
- package/src/core-types/modules/permissions/permission.ts +63 -0
- package/src/core-types/modules/permissions/role.ts +24 -0
- package/src/core-types/modules/products/product.ts +100 -0
- package/src/core-types/modules/products/productCategory.ts +27 -0
- package/src/core-types/modules/products/productConfig.ts +10 -0
- package/src/core-types/modules/products/uom.ts +12 -0
- package/src/core-types/modules/relations/relations.ts +14 -0
- package/src/core-types/modules/saas/organization.ts +7 -0
- package/src/core-types/modules/structure/structure.ts +29 -0
- package/src/core-types/modules/tags/tag.ts +17 -0
- package/src/core-types/modules/team-member/structure.ts +23 -0
- package/src/core-types/modules/team-member/user.ts +93 -0
- package/src/index.ts +1 -0
- package/src/utils/agent-tools/auth.ts +129 -0
- package/src/utils/agent-tools/endpoints.ts +274 -0
- package/src/utils/agent-tools/index.ts +5 -0
- package/src/utils/agent-tools/manifest.ts +152 -0
- package/src/utils/agent-tools/responseLimit.test.ts +99 -0
- package/src/utils/agent-tools/responseLimit.ts +66 -0
- package/src/utils/agent-tools/types.ts +52 -0
- package/src/utils/apollo/beforeResolvers.ts +117 -0
- package/src/utils/apollo/commonTypeDefs.ts +78 -0
- package/src/utils/apollo/constants.ts +16 -0
- package/src/utils/apollo/customScalars.ts +69 -0
- package/src/utils/apollo/expectedErrorPlugin.ts +83 -0
- package/src/utils/apollo/index.ts +10 -0
- package/src/utils/apollo/runBeforeResolvers.ts +214 -0
- package/src/utils/apollo/utils.ts +80 -0
- package/src/utils/apollo/wrapperMutations.ts +75 -0
- package/src/utils/apollo/wrapperResolvers.ts +182 -0
- package/src/utils/bulkUtils.ts +62 -0
- package/src/utils/constants.ts +99 -0
- package/src/utils/editor.ts +412 -0
- package/src/utils/email/address.ts +42 -0
- package/src/utils/email/attachments.ts +74 -0
- package/src/utils/email/config.ts +46 -0
- package/src/utils/email/constants.ts +25 -0
- package/src/utils/email/index.ts +11 -0
- package/src/utils/email/providers/sendgrid.ts +280 -0
- package/src/utils/email/providers/sendgridEvents.ts +48 -0
- package/src/utils/email/providers/ses.ts +250 -0
- package/src/utils/email/providers/smtp.ts +99 -0
- package/src/utils/email/resolveProvider.ts +75 -0
- package/src/utils/email/service.ts +192 -0
- package/src/utils/email/types.ts +127 -0
- package/src/utils/errorClassifier.test.ts +231 -0
- package/src/utils/errorClassifier.ts +458 -0
- package/src/utils/file/read.ts +464 -0
- package/src/utils/file/upload.ts +531 -0
- package/src/utils/graphqlPubSub.ts +28 -0
- package/src/utils/headers/get-hostname.ts +18 -0
- package/src/utils/headers/index.ts +4 -0
- package/src/utils/headers/sanitize.ts +9 -0
- package/src/utils/headers/subdomain.ts +13 -0
- package/src/utils/headers/user.test.ts +76 -0
- package/src/utils/headers/user.ts +113 -0
- package/src/utils/index.ts +27 -0
- package/src/utils/knowledge.ts +107 -0
- package/src/utils/logs/index.ts +247 -0
- package/src/utils/mongo/cursor-util.ts +153 -0
- package/src/utils/mongo/generate-models.ts +97 -0
- package/src/utils/mongo/index.ts +5 -0
- package/src/utils/mongo/mongo-connection.ts +42 -0
- package/src/utils/mongo/mongoose-types.ts +26 -0
- package/src/utils/mongo/mongoose-utils.ts +329 -0
- package/src/utils/mongo/search-tokens.ts +193 -0
- package/src/utils/mq-worker.ts +150 -0
- package/src/utils/random.ts +6 -0
- package/src/utils/redis.ts +23 -0
- package/src/utils/saas/constants.ts +32 -0
- package/src/utils/saas/definition.ts +318 -0
- package/src/utils/saas/index.ts +2 -0
- package/src/utils/saas/saas-mongo-connection.ts +595 -0
- package/src/utils/saas/types.ts +107 -0
- package/src/utils/sanitize.ts +73 -0
- package/src/utils/sentry-init.ts +128 -0
- package/src/utils/sentry-instrument.ts +5 -0
- package/src/utils/serializablePayload.test.ts +65 -0
- package/src/utils/serializablePayload.ts +44 -0
- package/src/utils/service-discovery.ts +256 -0
- package/src/utils/start-plugin.ts +482 -0
- package/src/utils/string.ts +159 -0
- package/src/utils/trpc/index.ts +278 -0
- package/src/utils/trpc/sendCoreModuleProducer.ts +146 -0
- package/src/utils/trpc/trpc-setup.ts +91 -0
- package/src/utils/utils.ts +669 -0
- package/utils/dist/erxes-api-shared-utils.cjs.d.ts +2 -0
- package/utils/dist/erxes-api-shared-utils.cjs.dev.js +3066 -0
- package/utils/dist/erxes-api-shared-utils.cjs.js +7 -0
- package/utils/dist/erxes-api-shared-utils.cjs.prod.js +3066 -0
- package/utils/dist/erxes-api-shared-utils.esm.js +2776 -0
- package/utils/package.json +5 -0
- package/README.md +0 -3
|
@@ -0,0 +1,1128 @@
|
|
|
1
|
+
import { pluralFormation } from '../../utils';
|
|
2
|
+
import {
|
|
3
|
+
parsePropertyDataKey,
|
|
4
|
+
propertyDataPath,
|
|
5
|
+
toPropertyGroupKey,
|
|
6
|
+
} from '../properties/keys';
|
|
7
|
+
import { nanoid } from 'nanoid';
|
|
8
|
+
import { sendTRPCMessage } from '../../utils/trpc';
|
|
9
|
+
import { AUTOMATION_PROPERTY_OPERATORS } from './constants';
|
|
10
|
+
import {
|
|
11
|
+
IPropertyProps,
|
|
12
|
+
TAutomationSetPropertyChange,
|
|
13
|
+
TAutomationSetPropertyModifier,
|
|
14
|
+
TAutomationSetPropertyRule,
|
|
15
|
+
TAutomationSetPropertyUpdateArgs,
|
|
16
|
+
} from './types';
|
|
17
|
+
import { getValueByPath, replaceOutputPlaceholders } from './outputResolvers';
|
|
18
|
+
import { splitType } from './typeUtils';
|
|
19
|
+
|
|
20
|
+
export { splitType } from './typeUtils';
|
|
21
|
+
|
|
22
|
+
type TSetPropertyRecord = Record<string, unknown>;
|
|
23
|
+
type TModifierKey = keyof TAutomationSetPropertyModifier;
|
|
24
|
+
type TSetPropertyRuleBuildResult = {
|
|
25
|
+
modifier: TAutomationSetPropertyModifier;
|
|
26
|
+
change?: TAutomationSetPropertyChange;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const PROPERTY_DATA_PREFIX = 'propertiesData.';
|
|
30
|
+
|
|
31
|
+
const CURRENT_VALUE_OPERATORS = new Set<string>([
|
|
32
|
+
AUTOMATION_PROPERTY_OPERATORS.ADD,
|
|
33
|
+
AUTOMATION_PROPERTY_OPERATORS.SUBTRACT,
|
|
34
|
+
AUTOMATION_PROPERTY_OPERATORS.MULTIPLY,
|
|
35
|
+
AUTOMATION_PROPERTY_OPERATORS.DIVIDE,
|
|
36
|
+
AUTOMATION_PROPERTY_OPERATORS.PERCENT,
|
|
37
|
+
AUTOMATION_PROPERTY_OPERATORS.CONCAT,
|
|
38
|
+
AUTOMATION_PROPERTY_OPERATORS.ADD_DAY,
|
|
39
|
+
AUTOMATION_PROPERTY_OPERATORS.SUBTRACT_DAY,
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const NUMERIC_OPERATORS = new Set<string>([
|
|
43
|
+
AUTOMATION_PROPERTY_OPERATORS.ADD,
|
|
44
|
+
AUTOMATION_PROPERTY_OPERATORS.SUBTRACT,
|
|
45
|
+
AUTOMATION_PROPERTY_OPERATORS.MULTIPLY,
|
|
46
|
+
AUTOMATION_PROPERTY_OPERATORS.DIVIDE,
|
|
47
|
+
AUTOMATION_PROPERTY_OPERATORS.PERCENT,
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
const DATE_OPERATORS = new Set<string>([
|
|
51
|
+
AUTOMATION_PROPERTY_OPERATORS.ADD_DAY,
|
|
52
|
+
AUTOMATION_PROPERTY_OPERATORS.SUBTRACT_DAY,
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
const safeArithmeticEval = (expr: string): number => {
|
|
56
|
+
const tokens = expr.match(/(\d+\.?\d*|[+\-*/()])/g) || [];
|
|
57
|
+
let pos = 0;
|
|
58
|
+
|
|
59
|
+
const parseNumber = (): number => {
|
|
60
|
+
if (tokens[pos] === '(') {
|
|
61
|
+
pos++;
|
|
62
|
+
const result = parseAddSub();
|
|
63
|
+
pos++;
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
if (tokens[pos] === '-') {
|
|
67
|
+
pos++;
|
|
68
|
+
return -parseNumber();
|
|
69
|
+
}
|
|
70
|
+
if (tokens[pos] === '+') {
|
|
71
|
+
pos++;
|
|
72
|
+
return parseNumber();
|
|
73
|
+
}
|
|
74
|
+
return parseFloat(tokens[pos++]) || 0;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const parseMulDiv = (): number => {
|
|
78
|
+
let result = parseNumber();
|
|
79
|
+
while (tokens[pos] === '*' || tokens[pos] === '/') {
|
|
80
|
+
const op = tokens[pos++];
|
|
81
|
+
const right = parseNumber();
|
|
82
|
+
result = op === '*' ? result * right : result / right;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const parseAddSub = (): number => {
|
|
88
|
+
let result = parseMulDiv();
|
|
89
|
+
while (tokens[pos] === '+' || tokens[pos] === '-') {
|
|
90
|
+
const op = tokens[pos++];
|
|
91
|
+
const right = parseMulDiv();
|
|
92
|
+
result = op === '+' ? result + right : result - right;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return parseAddSub();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const parseRepeatingGroupField = (fieldPath?: string) => {
|
|
101
|
+
if (!fieldPath?.startsWith(PROPERTY_DATA_PREFIX)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const key = parsePropertyDataKey(
|
|
106
|
+
fieldPath.slice(PROPERTY_DATA_PREFIX.length),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
return key.kind === 'row' ? key : null;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const getPropertiesDataKey = (fieldPath: string) => {
|
|
113
|
+
if (!fieldPath.startsWith(PROPERTY_DATA_PREFIX)) {
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const key = fieldPath.slice(PROPERTY_DATA_PREFIX.length);
|
|
118
|
+
|
|
119
|
+
return key.includes('.') ? '' : key;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const toPlainRecord = (item?: Record<string, unknown>) => {
|
|
123
|
+
if (!item) {
|
|
124
|
+
return {};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const toObject = item.toObject;
|
|
128
|
+
|
|
129
|
+
if (typeof toObject === 'function') {
|
|
130
|
+
return toObject.call(item) as TSetPropertyRecord;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return item;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const getCurrentValue = (
|
|
137
|
+
relatedItem: Record<string, unknown>,
|
|
138
|
+
fieldPath: string,
|
|
139
|
+
) => {
|
|
140
|
+
const item = toPlainRecord(relatedItem);
|
|
141
|
+
const direct = getValueByPath(item, fieldPath);
|
|
142
|
+
|
|
143
|
+
if (direct.found) {
|
|
144
|
+
return direct.value;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const getter = relatedItem.get;
|
|
148
|
+
|
|
149
|
+
if (typeof getter === 'function') {
|
|
150
|
+
return getter.call(relatedItem, fieldPath);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return undefined;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const toNumber = (value: unknown) => {
|
|
157
|
+
const numberValue = Number.parseFloat(String(value ?? 0));
|
|
158
|
+
|
|
159
|
+
return Number.isNaN(numberValue) ? 0 : numberValue;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const evaluateArithmeticValue = (value: unknown) => {
|
|
163
|
+
const stringValue = String(value ?? '');
|
|
164
|
+
|
|
165
|
+
if (!stringValue.match(/^[0-9+\-*/\s().]+$/)) {
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
return safeArithmeticEval(stringValue);
|
|
171
|
+
} catch {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const toArrayValue = (value: unknown) => {
|
|
177
|
+
if (Array.isArray(value)) {
|
|
178
|
+
return value.filter((item) => item !== undefined && item !== null);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return String(value ?? '')
|
|
182
|
+
.trim()
|
|
183
|
+
.replace(/, /g, ',')
|
|
184
|
+
.split(',')
|
|
185
|
+
.map((item) => item.trim())
|
|
186
|
+
.filter(Boolean);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const toUniqueArrayValue = (value: unknown) =>
|
|
190
|
+
Array.from(new Set(toArrayValue(value)));
|
|
191
|
+
|
|
192
|
+
const resolveRuleValue = async ({
|
|
193
|
+
subdomain,
|
|
194
|
+
execution,
|
|
195
|
+
rule,
|
|
196
|
+
fieldPath,
|
|
197
|
+
}: {
|
|
198
|
+
subdomain: string;
|
|
199
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
200
|
+
rule: TAutomationSetPropertyRule;
|
|
201
|
+
fieldPath: string;
|
|
202
|
+
}) => {
|
|
203
|
+
const replacedValues = await replaceOutputPlaceholders({
|
|
204
|
+
subdomain,
|
|
205
|
+
execution,
|
|
206
|
+
values: { value: rule.value },
|
|
207
|
+
keepUnresolvedPlaceholders: false,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
let updatedValue = evaluateArithmeticValue(replacedValues.value);
|
|
211
|
+
|
|
212
|
+
if (rule.operator === AUTOMATION_PROPERTY_OPERATORS.SPLIT) {
|
|
213
|
+
return toArrayValue(updatedValue);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (fieldPath.endsWith('Ids')) {
|
|
217
|
+
updatedValue = toUniqueArrayValue(updatedValue);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return updatedValue;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const isEmptyRuleValue = (value: unknown): boolean =>
|
|
224
|
+
value === null ||
|
|
225
|
+
value === undefined ||
|
|
226
|
+
(typeof value === 'string' && !value.trim()) ||
|
|
227
|
+
(Array.isArray(value) && !value.length);
|
|
228
|
+
|
|
229
|
+
const resolveRuleValueWithFallback = async ({
|
|
230
|
+
subdomain,
|
|
231
|
+
execution,
|
|
232
|
+
rule,
|
|
233
|
+
fieldPath,
|
|
234
|
+
}: {
|
|
235
|
+
subdomain: string;
|
|
236
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
237
|
+
rule: TAutomationSetPropertyRule;
|
|
238
|
+
fieldPath: string;
|
|
239
|
+
}) => {
|
|
240
|
+
const resolvedValue = await resolveRuleValue({
|
|
241
|
+
subdomain,
|
|
242
|
+
execution,
|
|
243
|
+
rule,
|
|
244
|
+
fieldPath,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
if (!isEmptyRuleValue(resolvedValue)) {
|
|
248
|
+
return resolvedValue;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (isEmptyRuleValue(rule.fallbackValue)) {
|
|
252
|
+
return resolvedValue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return await resolveRuleValue({
|
|
256
|
+
subdomain,
|
|
257
|
+
execution,
|
|
258
|
+
rule: { ...rule, value: rule.fallbackValue },
|
|
259
|
+
fieldPath,
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const getPerValue = async ({
|
|
264
|
+
subdomain,
|
|
265
|
+
relatedItem,
|
|
266
|
+
rule,
|
|
267
|
+
execution,
|
|
268
|
+
resolvedValue,
|
|
269
|
+
}: {
|
|
270
|
+
subdomain: string;
|
|
271
|
+
relatedItem: Record<string, unknown>;
|
|
272
|
+
rule: TAutomationSetPropertyRule;
|
|
273
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
274
|
+
resolvedValue?: unknown;
|
|
275
|
+
}) => {
|
|
276
|
+
const fieldPath = rule.field || '';
|
|
277
|
+
const operator = rule.operator || AUTOMATION_PROPERTY_OPERATORS.SET;
|
|
278
|
+
const op1 = getCurrentValue(relatedItem, fieldPath);
|
|
279
|
+
|
|
280
|
+
let updatedValue =
|
|
281
|
+
resolvedValue !== undefined
|
|
282
|
+
? resolvedValue
|
|
283
|
+
: await resolveRuleValue({
|
|
284
|
+
subdomain,
|
|
285
|
+
execution,
|
|
286
|
+
rule,
|
|
287
|
+
fieldPath,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (NUMERIC_OPERATORS.has(operator)) {
|
|
291
|
+
const currentValue = toNumber(op1);
|
|
292
|
+
const numberValue = toNumber(updatedValue);
|
|
293
|
+
|
|
294
|
+
switch (operator) {
|
|
295
|
+
case AUTOMATION_PROPERTY_OPERATORS.ADD:
|
|
296
|
+
updatedValue = currentValue + numberValue;
|
|
297
|
+
break;
|
|
298
|
+
case AUTOMATION_PROPERTY_OPERATORS.SUBTRACT:
|
|
299
|
+
updatedValue = currentValue - numberValue;
|
|
300
|
+
break;
|
|
301
|
+
case AUTOMATION_PROPERTY_OPERATORS.MULTIPLY:
|
|
302
|
+
updatedValue = currentValue * numberValue;
|
|
303
|
+
break;
|
|
304
|
+
case AUTOMATION_PROPERTY_OPERATORS.DIVIDE:
|
|
305
|
+
updatedValue = currentValue / numberValue || 1;
|
|
306
|
+
break;
|
|
307
|
+
case AUTOMATION_PROPERTY_OPERATORS.PERCENT:
|
|
308
|
+
updatedValue = (currentValue / 100) * numberValue;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (operator === AUTOMATION_PROPERTY_OPERATORS.CONCAT) {
|
|
314
|
+
updatedValue = String(op1 || '').concat(String(updatedValue ?? ''));
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (DATE_OPERATORS.has(operator)) {
|
|
318
|
+
const currentDate = new Date(String(op1 || new Date()));
|
|
319
|
+
const dateValue = Number.parseFloat(String(updatedValue));
|
|
320
|
+
const dayOffset =
|
|
321
|
+
operator === AUTOMATION_PROPERTY_OPERATORS.ADD_DAY
|
|
322
|
+
? dateValue
|
|
323
|
+
: -1 * dateValue;
|
|
324
|
+
|
|
325
|
+
updatedValue = new Date(
|
|
326
|
+
currentDate.setDate(currentDate.getDate() + dayOffset),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return updatedValue;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const mergeModifier = (
|
|
334
|
+
base: TAutomationSetPropertyModifier,
|
|
335
|
+
next: TAutomationSetPropertyModifier,
|
|
336
|
+
) => {
|
|
337
|
+
for (const key of Object.keys(next) as TModifierKey[]) {
|
|
338
|
+
base[key] = {
|
|
339
|
+
...(base[key] || {}),
|
|
340
|
+
...(next[key] || {}),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return base;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const buildArrayAddModifierValue = (value: unknown) =>
|
|
348
|
+
Array.isArray(value) ? { $each: value } : value;
|
|
349
|
+
|
|
350
|
+
const buildArrayPullModifierValue = (value: unknown) =>
|
|
351
|
+
Array.isArray(value) ? { $in: value } : value;
|
|
352
|
+
|
|
353
|
+
const getRulePlaceholder = (value: unknown) => {
|
|
354
|
+
if (typeof value !== 'string' || !value.includes('{{')) {
|
|
355
|
+
return undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return value;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const buildSetPropertyChange = ({
|
|
362
|
+
rule,
|
|
363
|
+
value,
|
|
364
|
+
status,
|
|
365
|
+
}: {
|
|
366
|
+
rule: TAutomationSetPropertyRule;
|
|
367
|
+
value?: unknown;
|
|
368
|
+
status: TAutomationSetPropertyChange['status'];
|
|
369
|
+
}): TAutomationSetPropertyChange => ({
|
|
370
|
+
field: rule.field,
|
|
371
|
+
fieldLabel: rule.fieldLabel || rule.field,
|
|
372
|
+
operator: rule.operator || AUTOMATION_PROPERTY_OPERATORS.SET,
|
|
373
|
+
placeholder: getRulePlaceholder(rule.value),
|
|
374
|
+
value: status === 'cleared' || status === 'skipped' ? undefined : value,
|
|
375
|
+
status,
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
const buildRuleUpdate = async ({
|
|
379
|
+
subdomain,
|
|
380
|
+
relatedItem,
|
|
381
|
+
rule,
|
|
382
|
+
execution,
|
|
383
|
+
}: {
|
|
384
|
+
subdomain: string;
|
|
385
|
+
relatedItem: Record<string, unknown>;
|
|
386
|
+
rule: TAutomationSetPropertyRule;
|
|
387
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
388
|
+
}): Promise<TSetPropertyRuleBuildResult> => {
|
|
389
|
+
const fieldPath = rule.field || '';
|
|
390
|
+
const operator = rule.operator || AUTOMATION_PROPERTY_OPERATORS.SET;
|
|
391
|
+
|
|
392
|
+
if (!fieldPath) {
|
|
393
|
+
return { modifier: {} };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (operator === AUTOMATION_PROPERTY_OPERATORS.CLEAR) {
|
|
397
|
+
return {
|
|
398
|
+
modifier: { $unset: { [fieldPath]: '' } },
|
|
399
|
+
change: buildSetPropertyChange({
|
|
400
|
+
rule,
|
|
401
|
+
status: 'cleared',
|
|
402
|
+
}),
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const resolvedValue = await resolveRuleValueWithFallback({
|
|
407
|
+
subdomain,
|
|
408
|
+
execution,
|
|
409
|
+
rule,
|
|
410
|
+
fieldPath,
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// An empty resolved value would wipe the field (or push '' into arrays);
|
|
414
|
+
// intentional clearing goes through the CLEAR operator instead.
|
|
415
|
+
if (isEmptyRuleValue(resolvedValue)) {
|
|
416
|
+
return {
|
|
417
|
+
modifier: {},
|
|
418
|
+
change: buildSetPropertyChange({
|
|
419
|
+
rule,
|
|
420
|
+
status: 'skipped',
|
|
421
|
+
}),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const value = await getPerValue({
|
|
426
|
+
subdomain,
|
|
427
|
+
relatedItem,
|
|
428
|
+
rule,
|
|
429
|
+
execution,
|
|
430
|
+
resolvedValue,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
let modifier: TAutomationSetPropertyModifier = {};
|
|
434
|
+
|
|
435
|
+
switch (operator) {
|
|
436
|
+
case AUTOMATION_PROPERTY_OPERATORS.PUSH:
|
|
437
|
+
modifier = { $push: { [fieldPath]: buildArrayAddModifierValue(value) } };
|
|
438
|
+
break;
|
|
439
|
+
case AUTOMATION_PROPERTY_OPERATORS.ADD_TO_SET:
|
|
440
|
+
modifier = {
|
|
441
|
+
$addToSet: { [fieldPath]: buildArrayAddModifierValue(value) },
|
|
442
|
+
};
|
|
443
|
+
break;
|
|
444
|
+
case AUTOMATION_PROPERTY_OPERATORS.PULL:
|
|
445
|
+
modifier = { $pull: { [fieldPath]: buildArrayPullModifierValue(value) } };
|
|
446
|
+
break;
|
|
447
|
+
default:
|
|
448
|
+
modifier = { $set: { [fieldPath]: value } };
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return {
|
|
452
|
+
modifier,
|
|
453
|
+
change: buildSetPropertyChange({
|
|
454
|
+
rule,
|
|
455
|
+
value,
|
|
456
|
+
status: 'updated',
|
|
457
|
+
}),
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const validatePropertiesDataInModifier = async ({
|
|
462
|
+
subdomain,
|
|
463
|
+
modifier,
|
|
464
|
+
}: {
|
|
465
|
+
subdomain: string;
|
|
466
|
+
modifier: TAutomationSetPropertyModifier;
|
|
467
|
+
}) => {
|
|
468
|
+
if (!modifier.$set) {
|
|
469
|
+
return modifier;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const propertiesData: Record<string, unknown> = {};
|
|
473
|
+
|
|
474
|
+
for (const [fieldPath, value] of Object.entries(modifier.$set)) {
|
|
475
|
+
const fieldId = getPropertiesDataKey(fieldPath);
|
|
476
|
+
|
|
477
|
+
if (fieldId) {
|
|
478
|
+
propertiesData[fieldId] = value;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (!Object.keys(propertiesData).length) {
|
|
483
|
+
return modifier;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const validatedPropertiesData = await sendTRPCMessage({
|
|
487
|
+
subdomain,
|
|
488
|
+
pluginName: 'core',
|
|
489
|
+
method: 'mutation',
|
|
490
|
+
module: 'fields',
|
|
491
|
+
action: 'validateFieldValues',
|
|
492
|
+
input: { data: propertiesData },
|
|
493
|
+
defaultValue: propertiesData,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
for (const fieldId of Object.keys(propertiesData)) {
|
|
497
|
+
const fieldPath = `${PROPERTY_DATA_PREFIX}${fieldId}`;
|
|
498
|
+
|
|
499
|
+
if (
|
|
500
|
+
Object.prototype.hasOwnProperty.call(validatedPropertiesData, fieldId)
|
|
501
|
+
) {
|
|
502
|
+
modifier.$set[fieldPath] = validatedPropertiesData[fieldId];
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return modifier;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
export const buildSetPropertyModifier = async ({
|
|
510
|
+
subdomain,
|
|
511
|
+
rules,
|
|
512
|
+
execution,
|
|
513
|
+
relatedItem = {},
|
|
514
|
+
}: {
|
|
515
|
+
subdomain: string;
|
|
516
|
+
rules: TAutomationSetPropertyRule[];
|
|
517
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
518
|
+
relatedItem?: Record<string, unknown>;
|
|
519
|
+
}) => {
|
|
520
|
+
return (
|
|
521
|
+
await buildSetPropertyUpdatePayload({
|
|
522
|
+
subdomain,
|
|
523
|
+
rules,
|
|
524
|
+
execution,
|
|
525
|
+
relatedItem,
|
|
526
|
+
})
|
|
527
|
+
).modifier;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
const syncSetChangeValues = (
|
|
531
|
+
changes: TAutomationSetPropertyChange[],
|
|
532
|
+
modifier: TAutomationSetPropertyModifier,
|
|
533
|
+
) =>
|
|
534
|
+
changes.map((change) => {
|
|
535
|
+
if (
|
|
536
|
+
change.status !== 'updated' ||
|
|
537
|
+
!modifier.$set ||
|
|
538
|
+
!Object.prototype.hasOwnProperty.call(modifier.$set, change.field)
|
|
539
|
+
) {
|
|
540
|
+
return change;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return {
|
|
544
|
+
...change,
|
|
545
|
+
value: modifier.$set[change.field],
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
const buildRepeatingGroupRowUpdate = async ({
|
|
550
|
+
subdomain,
|
|
551
|
+
groupId,
|
|
552
|
+
rules,
|
|
553
|
+
execution,
|
|
554
|
+
}: {
|
|
555
|
+
subdomain: string;
|
|
556
|
+
groupId: string;
|
|
557
|
+
rules: TAutomationSetPropertyRule[];
|
|
558
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
559
|
+
}): Promise<{
|
|
560
|
+
modifier: TAutomationSetPropertyModifier;
|
|
561
|
+
changes: TAutomationSetPropertyChange[];
|
|
562
|
+
}> => {
|
|
563
|
+
const row: TSetPropertyRecord = {};
|
|
564
|
+
const changes: TAutomationSetPropertyChange[] = [];
|
|
565
|
+
|
|
566
|
+
for (const rule of rules) {
|
|
567
|
+
const leafFieldId = parseRepeatingGroupField(rule.field)?.fieldId || '';
|
|
568
|
+
|
|
569
|
+
const value = await resolveRuleValueWithFallback({
|
|
570
|
+
subdomain,
|
|
571
|
+
execution,
|
|
572
|
+
rule,
|
|
573
|
+
fieldPath: rule.field,
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
if (!leafFieldId || isEmptyRuleValue(value)) {
|
|
577
|
+
changes.push(
|
|
578
|
+
buildSetPropertyChange({ rule, value: undefined, status: 'skipped' }),
|
|
579
|
+
);
|
|
580
|
+
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
row[leafFieldId] = value;
|
|
585
|
+
changes.push(buildSetPropertyChange({ rule, value, status: 'updated' }));
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (!Object.keys(row).length) {
|
|
589
|
+
return { modifier: {}, changes };
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const validatedRow = await sendTRPCMessage({
|
|
593
|
+
subdomain,
|
|
594
|
+
pluginName: 'core',
|
|
595
|
+
method: 'mutation',
|
|
596
|
+
module: 'fields',
|
|
597
|
+
action: 'validateFieldValues',
|
|
598
|
+
input: { data: row },
|
|
599
|
+
defaultValue: row,
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
modifier: {
|
|
604
|
+
$push: {
|
|
605
|
+
[propertyDataPath(toPropertyGroupKey(groupId))]: {
|
|
606
|
+
...validatedRow,
|
|
607
|
+
_id: nanoid(),
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
changes,
|
|
612
|
+
};
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
const buildSetPropertyUpdatePayload = async ({
|
|
616
|
+
subdomain,
|
|
617
|
+
rules,
|
|
618
|
+
execution,
|
|
619
|
+
relatedItem = {},
|
|
620
|
+
}: {
|
|
621
|
+
subdomain: string;
|
|
622
|
+
rules: TAutomationSetPropertyRule[];
|
|
623
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
624
|
+
relatedItem?: Record<string, unknown>;
|
|
625
|
+
}) => {
|
|
626
|
+
let modifier: TAutomationSetPropertyModifier = {};
|
|
627
|
+
const changes: TAutomationSetPropertyChange[] = [];
|
|
628
|
+
|
|
629
|
+
// one appended entry per group, so `school` and `year` land in the same row
|
|
630
|
+
const rulesByGroup = new Map<string, TAutomationSetPropertyRule[]>();
|
|
631
|
+
|
|
632
|
+
for (const rule of rules || []) {
|
|
633
|
+
const groupId = parseRepeatingGroupField(rule.field)?.groupId;
|
|
634
|
+
|
|
635
|
+
if (groupId) {
|
|
636
|
+
rulesByGroup.set(groupId, [...(rulesByGroup.get(groupId) || []), rule]);
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const ruleUpdate = await buildRuleUpdate({
|
|
641
|
+
subdomain,
|
|
642
|
+
relatedItem,
|
|
643
|
+
rule,
|
|
644
|
+
execution,
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
modifier = mergeModifier(modifier, ruleUpdate.modifier);
|
|
648
|
+
|
|
649
|
+
if (ruleUpdate.change) {
|
|
650
|
+
changes.push(ruleUpdate.change);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
for (const [groupId, groupRules] of rulesByGroup) {
|
|
655
|
+
const rowUpdate = await buildRepeatingGroupRowUpdate({
|
|
656
|
+
subdomain,
|
|
657
|
+
groupId,
|
|
658
|
+
rules: groupRules,
|
|
659
|
+
execution,
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
modifier = mergeModifier(modifier, rowUpdate.modifier);
|
|
663
|
+
changes.push(...rowUpdate.changes);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const validatedModifier = await validatePropertiesDataInModifier({
|
|
667
|
+
subdomain,
|
|
668
|
+
modifier,
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
return {
|
|
672
|
+
modifier: validatedModifier,
|
|
673
|
+
changes: syncSetChangeValues(changes, validatedModifier),
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
const hasCurrentValueOperators = (rules: TAutomationSetPropertyRule[]) =>
|
|
678
|
+
(rules || []).some((rule) => CURRENT_VALUE_OPERATORS.has(rule.operator));
|
|
679
|
+
|
|
680
|
+
const hasModifierOperations = (modifier: TAutomationSetPropertyModifier) =>
|
|
681
|
+
Object.values(modifier).some((operation) => {
|
|
682
|
+
return operation && Object.keys(operation).length > 0;
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
const getIdsSelectorFromItems = (items: Record<string, unknown>[]) => {
|
|
686
|
+
const ids = items.map((item) => item._id).filter(Boolean);
|
|
687
|
+
|
|
688
|
+
return ids.length ? { _id: { $in: ids } } : {};
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
const getItemSelector = (
|
|
692
|
+
baseSelector: Record<string, unknown>,
|
|
693
|
+
item: Record<string, unknown>,
|
|
694
|
+
) => ({
|
|
695
|
+
...baseSelector,
|
|
696
|
+
...(item._id ? { _id: item._id } : {}),
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
const getFallbackTRPCModuleName = (module: string) => {
|
|
700
|
+
const [, moduleName, contentType] = splitType(module);
|
|
701
|
+
const collectionType = contentType || moduleName || '';
|
|
702
|
+
|
|
703
|
+
if (!collectionType) {
|
|
704
|
+
return '';
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return collectionType.endsWith('s')
|
|
708
|
+
? collectionType
|
|
709
|
+
: pluralFormation(collectionType);
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
const updateSetPropertyByTRPC = async ({
|
|
713
|
+
subdomain,
|
|
714
|
+
module,
|
|
715
|
+
selector,
|
|
716
|
+
modifier,
|
|
717
|
+
}: {
|
|
718
|
+
subdomain: string;
|
|
719
|
+
module: string;
|
|
720
|
+
selector: Record<string, unknown>;
|
|
721
|
+
modifier: TAutomationSetPropertyModifier;
|
|
722
|
+
}) => {
|
|
723
|
+
const [serviceName] = splitType(module);
|
|
724
|
+
const moduleName = getFallbackTRPCModuleName(module);
|
|
725
|
+
|
|
726
|
+
if (!serviceName || !moduleName) {
|
|
727
|
+
throw new Error(`Invalid set property module: ${module}`);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
return await sendTRPCMessage({
|
|
731
|
+
subdomain,
|
|
732
|
+
method: 'mutation',
|
|
733
|
+
pluginName: serviceName,
|
|
734
|
+
module: moduleName,
|
|
735
|
+
action: 'updateMany',
|
|
736
|
+
input: {
|
|
737
|
+
selector,
|
|
738
|
+
modifier,
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
const getUpdateResultCount = (updateResult: unknown, fallback = 0) => {
|
|
744
|
+
if (!updateResult || typeof updateResult !== 'object') {
|
|
745
|
+
return fallback;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const result = updateResult as Record<string, unknown>;
|
|
749
|
+
|
|
750
|
+
for (const key of ['matchedCount', 'modifiedCount', 'n', 'nModified']) {
|
|
751
|
+
const value = result[key];
|
|
752
|
+
|
|
753
|
+
if (typeof value === 'number') {
|
|
754
|
+
return value;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return fallback;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
const getSetPropertyUpdate = ({
|
|
762
|
+
subdomain,
|
|
763
|
+
module,
|
|
764
|
+
update,
|
|
765
|
+
}: {
|
|
766
|
+
subdomain: string;
|
|
767
|
+
module: string;
|
|
768
|
+
update?: (args: TAutomationSetPropertyUpdateArgs) => Promise<unknown>;
|
|
769
|
+
}) =>
|
|
770
|
+
update ||
|
|
771
|
+
((args: TAutomationSetPropertyUpdateArgs) =>
|
|
772
|
+
updateSetPropertyByTRPC({
|
|
773
|
+
subdomain,
|
|
774
|
+
module,
|
|
775
|
+
selector: args.selector,
|
|
776
|
+
modifier: args.modifier,
|
|
777
|
+
}));
|
|
778
|
+
|
|
779
|
+
const getSelectorCountFallback = (selector: Record<string, unknown>) => {
|
|
780
|
+
const idSelector = selector._id;
|
|
781
|
+
|
|
782
|
+
if (typeof idSelector === 'string') {
|
|
783
|
+
return 1;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
if (
|
|
787
|
+
idSelector &&
|
|
788
|
+
typeof idSelector === 'object' &&
|
|
789
|
+
'$in' in idSelector &&
|
|
790
|
+
Array.isArray((idSelector as Record<string, unknown>).$in)
|
|
791
|
+
) {
|
|
792
|
+
return ((idSelector as Record<string, unknown>).$in as unknown[]).length;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return 0;
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
const markChangesStatus = (
|
|
799
|
+
changes: TAutomationSetPropertyChange[],
|
|
800
|
+
status: TAutomationSetPropertyChange['status'],
|
|
801
|
+
) =>
|
|
802
|
+
changes.map((change) => ({
|
|
803
|
+
...change,
|
|
804
|
+
status,
|
|
805
|
+
value:
|
|
806
|
+
status === 'cleared' || status === 'skipped' ? undefined : change.value,
|
|
807
|
+
}));
|
|
808
|
+
|
|
809
|
+
const formatChangeValue = (value: unknown) => {
|
|
810
|
+
if (value === undefined || value === null || value === '') {
|
|
811
|
+
return 'empty';
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
if (Array.isArray(value)) {
|
|
815
|
+
return value.join(', ');
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (value instanceof Date) {
|
|
819
|
+
return value.toISOString();
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
if (typeof value === 'object') {
|
|
823
|
+
return JSON.stringify(value);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
return String(value);
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
const formatChangeText = (change: TAutomationSetPropertyChange) => {
|
|
830
|
+
if (change.status === 'failed') {
|
|
831
|
+
return `${change.fieldLabel} failed`;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
if (change.status === 'skipped') {
|
|
835
|
+
return `${change.fieldLabel} skipped`;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (change.status === 'cleared') {
|
|
839
|
+
return `${change.fieldLabel} cleared`;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const value = formatChangeValue(change.value);
|
|
843
|
+
|
|
844
|
+
switch (change.operator) {
|
|
845
|
+
case AUTOMATION_PROPERTY_OPERATORS.PUSH:
|
|
846
|
+
case AUTOMATION_PROPERTY_OPERATORS.ADD_TO_SET:
|
|
847
|
+
return `${change.fieldLabel} added ${value}`;
|
|
848
|
+
case AUTOMATION_PROPERTY_OPERATORS.PULL:
|
|
849
|
+
return `${change.fieldLabel} removed ${value}`;
|
|
850
|
+
case AUTOMATION_PROPERTY_OPERATORS.ADD:
|
|
851
|
+
return `${change.fieldLabel} increased to ${value}`;
|
|
852
|
+
case AUTOMATION_PROPERTY_OPERATORS.SUBTRACT:
|
|
853
|
+
return `${change.fieldLabel} decreased to ${value}`;
|
|
854
|
+
default:
|
|
855
|
+
return `${change.fieldLabel} set to ${value}`;
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
const buildSetPropertyTarget = ({
|
|
860
|
+
module,
|
|
861
|
+
count,
|
|
862
|
+
setPropertyTarget,
|
|
863
|
+
}: {
|
|
864
|
+
module: string;
|
|
865
|
+
count: number;
|
|
866
|
+
setPropertyTarget?: IPropertyProps<unknown>['setPropertyTarget'];
|
|
867
|
+
}) => ({
|
|
868
|
+
label: setPropertyTarget?.label || setPropertyTarget?.description || module,
|
|
869
|
+
type: module,
|
|
870
|
+
count,
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
const buildSetPropertySummary = ({
|
|
874
|
+
target,
|
|
875
|
+
changes,
|
|
876
|
+
}: {
|
|
877
|
+
target: ReturnType<typeof buildSetPropertyTarget>;
|
|
878
|
+
changes: TAutomationSetPropertyChange[];
|
|
879
|
+
}) => {
|
|
880
|
+
if (!changes.length) {
|
|
881
|
+
return `Updated ${target.count} ${target.label}`;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
return `Updated ${target.count} ${target.label}: ${changes
|
|
885
|
+
.map(formatChangeText)
|
|
886
|
+
.join(', ')}`;
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
const buildSetPropertyResult = ({
|
|
890
|
+
module,
|
|
891
|
+
setPropertyTarget,
|
|
892
|
+
count,
|
|
893
|
+
changes,
|
|
894
|
+
}: {
|
|
895
|
+
module: string;
|
|
896
|
+
setPropertyTarget?: IPropertyProps<unknown>['setPropertyTarget'];
|
|
897
|
+
count: number;
|
|
898
|
+
changes: TAutomationSetPropertyChange[];
|
|
899
|
+
}) => {
|
|
900
|
+
const target = buildSetPropertyTarget({
|
|
901
|
+
module,
|
|
902
|
+
count,
|
|
903
|
+
setPropertyTarget,
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
return {
|
|
907
|
+
target,
|
|
908
|
+
changes,
|
|
909
|
+
summary: buildSetPropertySummary({ target, changes }),
|
|
910
|
+
};
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
const getAutomationBaseType = (type: string) => {
|
|
914
|
+
const [pluginName, moduleName, collectionName] = splitType(type || '');
|
|
915
|
+
|
|
916
|
+
if (!pluginName || !moduleName) {
|
|
917
|
+
return type || '';
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
const normalizedCollectionName =
|
|
921
|
+
collectionName && collectionName.endsWith('s')
|
|
922
|
+
? collectionName
|
|
923
|
+
: pluralFormation(collectionName || '');
|
|
924
|
+
|
|
925
|
+
return collectionName
|
|
926
|
+
? `${pluginName}:${moduleName}.${normalizedCollectionName}`
|
|
927
|
+
: `${pluginName}:${moduleName}`;
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
export const getSetPropertySelector = async ({
|
|
931
|
+
subdomain,
|
|
932
|
+
module,
|
|
933
|
+
execution,
|
|
934
|
+
targetType,
|
|
935
|
+
relation,
|
|
936
|
+
targetPath,
|
|
937
|
+
}: {
|
|
938
|
+
subdomain: string;
|
|
939
|
+
module: string;
|
|
940
|
+
execution: IPropertyProps<unknown>['execution'];
|
|
941
|
+
targetType: string;
|
|
942
|
+
relation?: {
|
|
943
|
+
contentType: string;
|
|
944
|
+
relatedContentType: string;
|
|
945
|
+
};
|
|
946
|
+
targetPath?: string;
|
|
947
|
+
}) => {
|
|
948
|
+
const target = execution.target || {};
|
|
949
|
+
const targetId = String(execution.targetId || target._id || '');
|
|
950
|
+
|
|
951
|
+
if (targetPath) {
|
|
952
|
+
const { found, value } = getValueByPath(target, targetPath);
|
|
953
|
+
const rawValue = found ? value : undefined;
|
|
954
|
+
const ids = (Array.isArray(rawValue) ? rawValue : [rawValue])
|
|
955
|
+
.map((id) => (id == null ? '' : String(id)))
|
|
956
|
+
.filter(Boolean);
|
|
957
|
+
|
|
958
|
+
return { _id: { $in: Array.from(new Set(ids)) } };
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
if (!targetId) {
|
|
962
|
+
return { _id: { $in: [] } };
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
if (
|
|
966
|
+
!relation &&
|
|
967
|
+
getAutomationBaseType(module) === getAutomationBaseType(targetType)
|
|
968
|
+
) {
|
|
969
|
+
return { _id: targetId };
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const { contentType, relatedContentType } = relation || {};
|
|
973
|
+
|
|
974
|
+
if (!contentType || !relatedContentType) {
|
|
975
|
+
return { _id: { $in: [] } };
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
const relationIds = await sendTRPCMessage({
|
|
979
|
+
subdomain,
|
|
980
|
+
pluginName: 'core',
|
|
981
|
+
module: 'relation',
|
|
982
|
+
action: 'getRelationIds',
|
|
983
|
+
input: {
|
|
984
|
+
contentType,
|
|
985
|
+
contentId: targetId,
|
|
986
|
+
relatedContentType,
|
|
987
|
+
},
|
|
988
|
+
defaultValue: [],
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
return {
|
|
992
|
+
_id: {
|
|
993
|
+
$in: Array.from(new Set((relationIds || []).filter(Boolean))),
|
|
994
|
+
},
|
|
995
|
+
};
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
export const setProperty = async <TModels>({
|
|
999
|
+
subdomain,
|
|
1000
|
+
module,
|
|
1001
|
+
rules,
|
|
1002
|
+
execution,
|
|
1003
|
+
setPropertyTarget,
|
|
1004
|
+
relatedItems = [],
|
|
1005
|
+
selector,
|
|
1006
|
+
fetchItems,
|
|
1007
|
+
update,
|
|
1008
|
+
}: IPropertyProps<TModels>) => {
|
|
1009
|
+
const updateRecord = getSetPropertyUpdate({ subdomain, module, update });
|
|
1010
|
+
const needsCurrentValue = hasCurrentValueOperators(rules);
|
|
1011
|
+
const baseSelector =
|
|
1012
|
+
selector ||
|
|
1013
|
+
(relatedItems.length ? getIdsSelectorFromItems(relatedItems) : {});
|
|
1014
|
+
|
|
1015
|
+
if (!needsCurrentValue) {
|
|
1016
|
+
const { modifier, changes } = await buildSetPropertyUpdatePayload({
|
|
1017
|
+
subdomain,
|
|
1018
|
+
rules,
|
|
1019
|
+
execution,
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
if (!Object.keys(baseSelector).length || !hasModifierOperations(modifier)) {
|
|
1023
|
+
return buildSetPropertyResult({
|
|
1024
|
+
module,
|
|
1025
|
+
setPropertyTarget,
|
|
1026
|
+
count: 0,
|
|
1027
|
+
changes: markChangesStatus(changes, 'skipped'),
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
try {
|
|
1032
|
+
const updateResult = await updateRecord({
|
|
1033
|
+
selector: baseSelector,
|
|
1034
|
+
modifier,
|
|
1035
|
+
});
|
|
1036
|
+
const count = getUpdateResultCount(
|
|
1037
|
+
updateResult,
|
|
1038
|
+
getSelectorCountFallback(baseSelector),
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
return buildSetPropertyResult({
|
|
1042
|
+
module,
|
|
1043
|
+
setPropertyTarget,
|
|
1044
|
+
count,
|
|
1045
|
+
// Nothing matched, so nothing was set; "updated" would hide a lost target.
|
|
1046
|
+
changes: count ? changes : markChangesStatus(changes, 'skipped'),
|
|
1047
|
+
});
|
|
1048
|
+
} catch {
|
|
1049
|
+
return buildSetPropertyResult({
|
|
1050
|
+
module,
|
|
1051
|
+
setPropertyTarget,
|
|
1052
|
+
count: 0,
|
|
1053
|
+
changes: markChangesStatus(changes, 'failed'),
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const items =
|
|
1059
|
+
relatedItems.length || !fetchItems
|
|
1060
|
+
? relatedItems
|
|
1061
|
+
: await fetchItems(baseSelector);
|
|
1062
|
+
|
|
1063
|
+
// No record to set means every rule was skipped, not that none were asked.
|
|
1064
|
+
if (!items.length) {
|
|
1065
|
+
const { changes } = await buildSetPropertyUpdatePayload({
|
|
1066
|
+
subdomain,
|
|
1067
|
+
rules,
|
|
1068
|
+
execution,
|
|
1069
|
+
});
|
|
1070
|
+
|
|
1071
|
+
return buildSetPropertyResult({
|
|
1072
|
+
module,
|
|
1073
|
+
setPropertyTarget,
|
|
1074
|
+
count: 0,
|
|
1075
|
+
changes: markChangesStatus(changes, 'skipped'),
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
let updatedCount = 0;
|
|
1080
|
+
const changes: TAutomationSetPropertyChange[] = [];
|
|
1081
|
+
|
|
1082
|
+
for (const relatedItem of items) {
|
|
1083
|
+
const ruleUpdate = await buildSetPropertyUpdatePayload({
|
|
1084
|
+
subdomain,
|
|
1085
|
+
rules,
|
|
1086
|
+
execution,
|
|
1087
|
+
relatedItem,
|
|
1088
|
+
});
|
|
1089
|
+
const { modifier } = ruleUpdate;
|
|
1090
|
+
|
|
1091
|
+
if (!hasModifierOperations(modifier)) {
|
|
1092
|
+
changes.push(...markChangesStatus(ruleUpdate.changes, 'skipped'));
|
|
1093
|
+
continue;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
const itemSelector = getItemSelector(baseSelector, relatedItem);
|
|
1097
|
+
|
|
1098
|
+
try {
|
|
1099
|
+
const updateResult = await updateRecord({
|
|
1100
|
+
selector: itemSelector,
|
|
1101
|
+
modifier,
|
|
1102
|
+
item: relatedItem,
|
|
1103
|
+
});
|
|
1104
|
+
const itemCount = getUpdateResultCount(updateResult, 1);
|
|
1105
|
+
|
|
1106
|
+
updatedCount += itemCount;
|
|
1107
|
+
changes.push(
|
|
1108
|
+
...(itemCount
|
|
1109
|
+
? ruleUpdate.changes
|
|
1110
|
+
: markChangesStatus(ruleUpdate.changes, 'skipped')),
|
|
1111
|
+
);
|
|
1112
|
+
} catch {
|
|
1113
|
+
changes.push(...markChangesStatus(ruleUpdate.changes, 'failed'));
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
return buildSetPropertyResult({
|
|
1119
|
+
module,
|
|
1120
|
+
setPropertyTarget,
|
|
1121
|
+
count: updatedCount,
|
|
1122
|
+
changes,
|
|
1123
|
+
});
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
export const getContentType = (type: string) => splitType(type)[2];
|
|
1127
|
+
export const getModuleName = (type: string) => splitType(type)[1];
|
|
1128
|
+
export const getPluginName = (type: string) => splitType(type)[0];
|