@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.
Files changed (758) hide show
  1. package/LICENSE.md +672 -0
  2. package/core-modules/dist/erxes-api-shared-core-modules.cjs.d.ts +2 -0
  3. package/core-modules/dist/erxes-api-shared-core-modules.cjs.dev.js +6685 -0
  4. package/core-modules/dist/erxes-api-shared-core-modules.cjs.js +7 -0
  5. package/core-modules/dist/erxes-api-shared-core-modules.cjs.prod.js +6685 -0
  6. package/core-modules/dist/erxes-api-shared-core-modules.esm.js +6298 -0
  7. package/core-modules/package.json +5 -0
  8. package/core-types/dist/erxes-api-shared-core-types.cjs.d.ts +2 -0
  9. package/core-types/dist/erxes-api-shared-core-types.cjs.dev.js +12 -0
  10. package/core-types/dist/erxes-api-shared-core-types.cjs.js +7 -0
  11. package/core-types/dist/erxes-api-shared-core-types.cjs.prod.js +12 -0
  12. package/core-types/dist/erxes-api-shared-core-types.esm.js +8 -0
  13. package/core-types/package.json +5 -0
  14. package/dist/declarations/src/core-modules/approval/approvalChangeTypes.d.ts +15 -0
  15. package/dist/declarations/src/core-modules/approval/approvalChangeTypes.d.ts.map +1 -0
  16. package/dist/declarations/src/core-modules/approval/checkApprovalLock.d.ts +7 -0
  17. package/dist/declarations/src/core-modules/approval/checkApprovalLock.d.ts.map +1 -0
  18. package/dist/declarations/src/core-modules/approval/constants.d.ts +37 -0
  19. package/dist/declarations/src/core-modules/approval/constants.d.ts.map +1 -0
  20. package/dist/declarations/src/core-modules/approval/index.d.ts +7 -0
  21. package/dist/declarations/src/core-modules/approval/index.d.ts.map +1 -0
  22. package/dist/declarations/src/core-modules/approval/initApproval.d.ts +9 -0
  23. package/dist/declarations/src/core-modules/approval/initApproval.d.ts.map +1 -0
  24. package/dist/declarations/src/core-modules/approval/types.d.ts +164 -0
  25. package/dist/declarations/src/core-modules/approval/types.d.ts.map +1 -0
  26. package/dist/declarations/src/core-modules/approval/zodSchemas.d.ts +125 -0
  27. package/dist/declarations/src/core-modules/approval/zodSchemas.d.ts.map +1 -0
  28. package/dist/declarations/src/core-modules/apps/@types/app.d.ts +15 -0
  29. package/dist/declarations/src/core-modules/apps/@types/app.d.ts.map +1 -0
  30. package/dist/declarations/src/core-modules/apps/db/definitions/apps.d.ts +13 -0
  31. package/dist/declarations/src/core-modules/apps/db/definitions/apps.d.ts.map +1 -0
  32. package/dist/declarations/src/core-modules/apps/index.d.ts +3 -0
  33. package/dist/declarations/src/core-modules/apps/index.d.ts.map +1 -0
  34. package/dist/declarations/src/core-modules/automations/actionErrorPolicy.d.ts +68 -0
  35. package/dist/declarations/src/core-modules/automations/actionErrorPolicy.d.ts.map +1 -0
  36. package/dist/declarations/src/core-modules/automations/actionOutcome.d.ts +51 -0
  37. package/dist/declarations/src/core-modules/automations/actionOutcome.d.ts.map +1 -0
  38. package/dist/declarations/src/core-modules/automations/constants.d.ts +101 -0
  39. package/dist/declarations/src/core-modules/automations/constants.d.ts.map +1 -0
  40. package/dist/declarations/src/core-modules/automations/definitions/aiAgents.d.ts +141 -0
  41. package/dist/declarations/src/core-modules/automations/definitions/aiAgents.d.ts.map +1 -0
  42. package/dist/declarations/src/core-modules/automations/definitions/automations.d.ts +868 -0
  43. package/dist/declarations/src/core-modules/automations/definitions/automations.d.ts.map +1 -0
  44. package/dist/declarations/src/core-modules/automations/definitions/executions.d.ts +316 -0
  45. package/dist/declarations/src/core-modules/automations/definitions/executions.d.ts.map +1 -0
  46. package/dist/declarations/src/core-modules/automations/definitions/index.d.ts +4 -0
  47. package/dist/declarations/src/core-modules/automations/definitions/index.d.ts.map +1 -0
  48. package/dist/declarations/src/core-modules/automations/index.d.ts +14 -0
  49. package/dist/declarations/src/core-modules/automations/index.d.ts.map +1 -0
  50. package/dist/declarations/src/core-modules/automations/outputResolvers.d.ts +67 -0
  51. package/dist/declarations/src/core-modules/automations/outputResolvers.d.ts.map +1 -0
  52. package/dist/declarations/src/core-modules/automations/reEnrollment.d.ts +23 -0
  53. package/dist/declarations/src/core-modules/automations/reEnrollment.d.ts.map +1 -0
  54. package/dist/declarations/src/core-modules/automations/segmentMembership.d.ts +19 -0
  55. package/dist/declarations/src/core-modules/automations/segmentMembership.d.ts.map +1 -0
  56. package/dist/declarations/src/core-modules/automations/sendAutomationMessage.d.ts +51 -0
  57. package/dist/declarations/src/core-modules/automations/sendAutomationMessage.d.ts.map +1 -0
  58. package/dist/declarations/src/core-modules/automations/setupAutomationProducers.d.ts +4 -0
  59. package/dist/declarations/src/core-modules/automations/setupAutomationProducers.d.ts.map +1 -0
  60. package/dist/declarations/src/core-modules/automations/typeUtils.d.ts +2 -0
  61. package/dist/declarations/src/core-modules/automations/typeUtils.d.ts.map +1 -0
  62. package/dist/declarations/src/core-modules/automations/types.d.ts +474 -0
  63. package/dist/declarations/src/core-modules/automations/types.d.ts.map +1 -0
  64. package/dist/declarations/src/core-modules/automations/utils.d.ts +38 -0
  65. package/dist/declarations/src/core-modules/automations/utils.d.ts.map +1 -0
  66. package/dist/declarations/src/core-modules/automations/workflowValidation.d.ts +3 -0
  67. package/dist/declarations/src/core-modules/automations/workflowValidation.d.ts.map +1 -0
  68. package/dist/declarations/src/core-modules/automations/zodTypes.d.ts +2366 -0
  69. package/dist/declarations/src/core-modules/automations/zodTypes.d.ts.map +1 -0
  70. package/dist/declarations/src/core-modules/client-portals/definitions/clientPortal.d.ts +375 -0
  71. package/dist/declarations/src/core-modules/client-portals/definitions/clientPortal.d.ts.map +1 -0
  72. package/dist/declarations/src/core-modules/client-portals/definitions/comment.d.ts +53 -0
  73. package/dist/declarations/src/core-modules/client-portals/definitions/comment.d.ts.map +1 -0
  74. package/dist/declarations/src/core-modules/client-portals/definitions/cpNotification.d.ts +110 -0
  75. package/dist/declarations/src/core-modules/client-portals/definitions/cpNotification.d.ts.map +1 -0
  76. package/dist/declarations/src/core-modules/client-portals/definitions/cpUser.d.ts +828 -0
  77. package/dist/declarations/src/core-modules/client-portals/definitions/cpUser.d.ts.map +1 -0
  78. package/dist/declarations/src/core-modules/client-portals/index.d.ts +5 -0
  79. package/dist/declarations/src/core-modules/client-portals/index.d.ts.map +1 -0
  80. package/dist/declarations/src/core-modules/common/db/definitions/common.d.ts +77 -0
  81. package/dist/declarations/src/core-modules/common/db/definitions/common.d.ts.map +1 -0
  82. package/dist/declarations/src/core-modules/common/eventHandlers/createEventHandlers.d.ts +8 -0
  83. package/dist/declarations/src/core-modules/common/eventHandlers/createEventHandlers.d.ts.map +1 -0
  84. package/dist/declarations/src/core-modules/common/eventHandlers/generateEventHandlers.d.ts +4 -0
  85. package/dist/declarations/src/core-modules/common/eventHandlers/generateEventHandlers.d.ts.map +1 -0
  86. package/dist/declarations/src/core-modules/common/eventHandlers/index.d.ts +5 -0
  87. package/dist/declarations/src/core-modules/common/eventHandlers/index.d.ts.map +1 -0
  88. package/dist/declarations/src/core-modules/common/eventHandlers/runtimeContext.d.ts +9 -0
  89. package/dist/declarations/src/core-modules/common/eventHandlers/runtimeContext.d.ts.map +1 -0
  90. package/dist/declarations/src/core-modules/common/eventHandlers/schemas.d.ts +82 -0
  91. package/dist/declarations/src/core-modules/common/eventHandlers/schemas.d.ts.map +1 -0
  92. package/dist/declarations/src/core-modules/common/eventHandlers/types.d.ts +87 -0
  93. package/dist/declarations/src/core-modules/common/eventHandlers/types.d.ts.map +1 -0
  94. package/dist/declarations/src/core-modules/common/index.d.ts +5 -0
  95. package/dist/declarations/src/core-modules/common/index.d.ts.map +1 -0
  96. package/dist/declarations/src/core-modules/common/references/getRecordReferenceFields.d.ts +57 -0
  97. package/dist/declarations/src/core-modules/common/references/getRecordReferenceFields.d.ts.map +1 -0
  98. package/dist/declarations/src/core-modules/common/references/index.d.ts +6 -0
  99. package/dist/declarations/src/core-modules/common/references/index.d.ts.map +1 -0
  100. package/dist/declarations/src/core-modules/common/references/initRecordReferences.d.ts +4 -0
  101. package/dist/declarations/src/core-modules/common/references/initRecordReferences.d.ts.map +1 -0
  102. package/dist/declarations/src/core-modules/common/references/resolveRecordReferencePlaceholders.d.ts +12 -0
  103. package/dist/declarations/src/core-modules/common/references/resolveRecordReferencePlaceholders.d.ts.map +1 -0
  104. package/dist/declarations/src/core-modules/common/references/resolveRecordReferenceValue.d.ts +6 -0
  105. package/dist/declarations/src/core-modules/common/references/resolveRecordReferenceValue.d.ts.map +1 -0
  106. package/dist/declarations/src/core-modules/common/references/types.d.ts +63 -0
  107. package/dist/declarations/src/core-modules/common/references/types.d.ts.map +1 -0
  108. package/dist/declarations/src/core-modules/common/routeToModuleProducer.d.ts +55 -0
  109. package/dist/declarations/src/core-modules/common/routeToModuleProducer.d.ts.map +1 -0
  110. package/dist/declarations/src/core-modules/email-content/blocksToHtml.d.ts +72 -0
  111. package/dist/declarations/src/core-modules/email-content/blocksToHtml.d.ts.map +1 -0
  112. package/dist/declarations/src/core-modules/email-content/constants.d.ts +5 -0
  113. package/dist/declarations/src/core-modules/email-content/constants.d.ts.map +1 -0
  114. package/dist/declarations/src/core-modules/email-content/emailFooter.d.ts +5 -0
  115. package/dist/declarations/src/core-modules/email-content/emailFooter.d.ts.map +1 -0
  116. package/dist/declarations/src/core-modules/email-content/expandRepeatRows.d.ts +9 -0
  117. package/dist/declarations/src/core-modules/email-content/expandRepeatRows.d.ts.map +1 -0
  118. package/dist/declarations/src/core-modules/email-content/index.d.ts +9 -0
  119. package/dist/declarations/src/core-modules/email-content/index.d.ts.map +1 -0
  120. package/dist/declarations/src/core-modules/email-content/renderEmailContent.d.ts +19 -0
  121. package/dist/declarations/src/core-modules/email-content/renderEmailContent.d.ts.map +1 -0
  122. package/dist/declarations/src/core-modules/email-content/replacePlaceholders.d.ts +36 -0
  123. package/dist/declarations/src/core-modules/email-content/replacePlaceholders.d.ts.map +1 -0
  124. package/dist/declarations/src/core-modules/email-content/types.d.ts +48 -0
  125. package/dist/declarations/src/core-modules/email-content/types.d.ts.map +1 -0
  126. package/dist/declarations/src/core-modules/email-content/unresolvedPlaceholders.d.ts +4 -0
  127. package/dist/declarations/src/core-modules/email-content/unresolvedPlaceholders.d.ts.map +1 -0
  128. package/dist/declarations/src/core-modules/forms/index.d.ts +3 -0
  129. package/dist/declarations/src/core-modules/forms/index.d.ts.map +1 -0
  130. package/dist/declarations/src/core-modules/forms/types.d.ts +55 -0
  131. package/dist/declarations/src/core-modules/forms/types.d.ts.map +1 -0
  132. package/dist/declarations/src/core-modules/forms/utils.d.ts +4 -0
  133. package/dist/declarations/src/core-modules/forms/utils.d.ts.map +1 -0
  134. package/dist/declarations/src/core-modules/import-export/index.d.ts +8 -0
  135. package/dist/declarations/src/core-modules/import-export/index.d.ts.map +1 -0
  136. package/dist/declarations/src/core-modules/import-export/types.d.ts +181 -0
  137. package/dist/declarations/src/core-modules/import-export/types.d.ts.map +1 -0
  138. package/dist/declarations/src/core-modules/import-export/utils/exportCursor.d.ts +14 -0
  139. package/dist/declarations/src/core-modules/import-export/utils/exportCursor.d.ts.map +1 -0
  140. package/dist/declarations/src/core-modules/import-export/utils/headerMatcher.d.ts +32 -0
  141. package/dist/declarations/src/core-modules/import-export/utils/headerMatcher.d.ts.map +1 -0
  142. package/dist/declarations/src/core-modules/import-export/utils/importExportRuntime.d.ts +32 -0
  143. package/dist/declarations/src/core-modules/import-export/utils/importExportRuntime.d.ts.map +1 -0
  144. package/dist/declarations/src/core-modules/import-export/utils/importUtils.d.ts +25 -0
  145. package/dist/declarations/src/core-modules/import-export/utils/importUtils.d.ts.map +1 -0
  146. package/dist/declarations/src/core-modules/import-export/worker.d.ts +8 -0
  147. package/dist/declarations/src/core-modules/import-export/worker.d.ts.map +1 -0
  148. package/dist/declarations/src/core-modules/import-export/zodSchemas.d.ts +111 -0
  149. package/dist/declarations/src/core-modules/import-export/zodSchemas.d.ts.map +1 -0
  150. package/dist/declarations/src/core-modules/index.d.ts +16 -0
  151. package/dist/declarations/src/core-modules/index.d.ts.map +1 -0
  152. package/dist/declarations/src/core-modules/logs/activityLog/builder.d.ts +3 -0
  153. package/dist/declarations/src/core-modules/logs/activityLog/builder.d.ts.map +1 -0
  154. package/dist/declarations/src/core-modules/logs/activityLog/index.d.ts +5 -0
  155. package/dist/declarations/src/core-modules/logs/activityLog/index.d.ts.map +1 -0
  156. package/dist/declarations/src/core-modules/logs/activityLog/sharedBuilders.d.ts +18 -0
  157. package/dist/declarations/src/core-modules/logs/activityLog/sharedBuilders.d.ts.map +1 -0
  158. package/dist/declarations/src/core-modules/logs/activityLog/types.d.ts +21 -0
  159. package/dist/declarations/src/core-modules/logs/activityLog/types.d.ts.map +1 -0
  160. package/dist/declarations/src/core-modules/logs/activityLog/utils.d.ts +10 -0
  161. package/dist/declarations/src/core-modules/logs/activityLog/utils.d.ts.map +1 -0
  162. package/dist/declarations/src/core-modules/logs/activityLogUtils.d.ts +72 -0
  163. package/dist/declarations/src/core-modules/logs/activityLogUtils.d.ts.map +1 -0
  164. package/dist/declarations/src/core-modules/logs/definitions/activityLog.d.ts +84 -0
  165. package/dist/declarations/src/core-modules/logs/definitions/activityLog.d.ts.map +1 -0
  166. package/dist/declarations/src/core-modules/logs/definitions/logs.d.ts +39 -0
  167. package/dist/declarations/src/core-modules/logs/definitions/logs.d.ts.map +1 -0
  168. package/dist/declarations/src/core-modules/logs/index.d.ts +6 -0
  169. package/dist/declarations/src/core-modules/logs/index.d.ts.map +1 -0
  170. package/dist/declarations/src/core-modules/logs/types.d.ts +15 -0
  171. package/dist/declarations/src/core-modules/logs/types.d.ts.map +1 -0
  172. package/dist/declarations/src/core-modules/notifications/definitions/emailAddresses.d.ts +73 -0
  173. package/dist/declarations/src/core-modules/notifications/definitions/emailAddresses.d.ts.map +1 -0
  174. package/dist/declarations/src/core-modules/notifications/definitions/emailDeliveries.d.ts +115 -0
  175. package/dist/declarations/src/core-modules/notifications/definitions/emailDeliveries.d.ts.map +1 -0
  176. package/dist/declarations/src/core-modules/notifications/definitions/emailRamp.d.ts +65 -0
  177. package/dist/declarations/src/core-modules/notifications/definitions/emailRamp.d.ts.map +1 -0
  178. package/dist/declarations/src/core-modules/notifications/definitions/emailSenders.d.ts +58 -0
  179. package/dist/declarations/src/core-modules/notifications/definitions/emailSenders.d.ts.map +1 -0
  180. package/dist/declarations/src/core-modules/notifications/definitions/notificationSettings.d.ts +66 -0
  181. package/dist/declarations/src/core-modules/notifications/definitions/notificationSettings.d.ts.map +1 -0
  182. package/dist/declarations/src/core-modules/notifications/definitions/notifications.d.ts +89 -0
  183. package/dist/declarations/src/core-modules/notifications/definitions/notifications.d.ts.map +1 -0
  184. package/dist/declarations/src/core-modules/notifications/index.d.ts +8 -0
  185. package/dist/declarations/src/core-modules/notifications/index.d.ts.map +1 -0
  186. package/dist/declarations/src/core-modules/notifications/utils.d.ts +85 -0
  187. package/dist/declarations/src/core-modules/notifications/utils.d.ts.map +1 -0
  188. package/dist/declarations/src/core-modules/permissions/db/definitions/permissions.d.ts +60 -0
  189. package/dist/declarations/src/core-modules/permissions/db/definitions/permissions.d.ts.map +1 -0
  190. package/dist/declarations/src/core-modules/permissions/index.d.ts +4 -0
  191. package/dist/declarations/src/core-modules/permissions/index.d.ts.map +1 -0
  192. package/dist/declarations/src/core-modules/permissions/user-actions-map.d.ts +4 -0
  193. package/dist/declarations/src/core-modules/permissions/user-actions-map.d.ts.map +1 -0
  194. package/dist/declarations/src/core-modules/permissions/utils.d.ts +22 -0
  195. package/dist/declarations/src/core-modules/permissions/utils.d.ts.map +1 -0
  196. package/dist/declarations/src/core-modules/properties/filter.d.ts +5 -0
  197. package/dist/declarations/src/core-modules/properties/filter.d.ts.map +1 -0
  198. package/dist/declarations/src/core-modules/properties/importExport.d.ts +18 -0
  199. package/dist/declarations/src/core-modules/properties/importExport.d.ts.map +1 -0
  200. package/dist/declarations/src/core-modules/properties/index.d.ts +10 -0
  201. package/dist/declarations/src/core-modules/properties/index.d.ts.map +1 -0
  202. package/dist/declarations/src/core-modules/properties/keys.d.ts +46 -0
  203. package/dist/declarations/src/core-modules/properties/keys.d.ts.map +1 -0
  204. package/dist/declarations/src/core-modules/properties/mergeRows.d.ts +8 -0
  205. package/dist/declarations/src/core-modules/properties/mergeRows.d.ts.map +1 -0
  206. package/dist/declarations/src/core-modules/properties/operators.d.ts +6 -0
  207. package/dist/declarations/src/core-modules/properties/operators.d.ts.map +1 -0
  208. package/dist/declarations/src/core-modules/properties/options.d.ts +10 -0
  209. package/dist/declarations/src/core-modules/properties/options.d.ts.map +1 -0
  210. package/dist/declarations/src/core-modules/properties/setupPropertyProducers.d.ts +4 -0
  211. package/dist/declarations/src/core-modules/properties/setupPropertyProducers.d.ts.map +1 -0
  212. package/dist/declarations/src/core-modules/properties/types.d.ts +14 -0
  213. package/dist/declarations/src/core-modules/properties/types.d.ts.map +1 -0
  214. package/dist/declarations/src/core-modules/properties/valueUsage.d.ts +56 -0
  215. package/dist/declarations/src/core-modules/properties/valueUsage.d.ts.map +1 -0
  216. package/dist/declarations/src/core-modules/segments/dependencies.d.ts +6 -0
  217. package/dist/declarations/src/core-modules/segments/dependencies.d.ts.map +1 -0
  218. package/dist/declarations/src/core-modules/segments/evaluate.d.ts +11 -0
  219. package/dist/declarations/src/core-modules/segments/evaluate.d.ts.map +1 -0
  220. package/dist/declarations/src/core-modules/segments/evaluateBatch.d.ts +42 -0
  221. package/dist/declarations/src/core-modules/segments/evaluateBatch.d.ts.map +1 -0
  222. package/dist/declarations/src/core-modules/segments/evaluateFieldsRouter.d.ts +29 -0
  223. package/dist/declarations/src/core-modules/segments/evaluateFieldsRouter.d.ts.map +1 -0
  224. package/dist/declarations/src/core-modules/segments/evaluateOwned.d.ts +27 -0
  225. package/dist/declarations/src/core-modules/segments/evaluateOwned.d.ts.map +1 -0
  226. package/dist/declarations/src/core-modules/segments/events.d.ts +45 -0
  227. package/dist/declarations/src/core-modules/segments/events.d.ts.map +1 -0
  228. package/dist/declarations/src/core-modules/segments/fieldBuilders.d.ts +35 -0
  229. package/dist/declarations/src/core-modules/segments/fieldBuilders.d.ts.map +1 -0
  230. package/dist/declarations/src/core-modules/segments/fieldMeta.d.ts +62 -0
  231. package/dist/declarations/src/core-modules/segments/fieldMeta.d.ts.map +1 -0
  232. package/dist/declarations/src/core-modules/segments/fieldRequests.d.ts +33 -0
  233. package/dist/declarations/src/core-modules/segments/fieldRequests.d.ts.map +1 -0
  234. package/dist/declarations/src/core-modules/segments/fingerprint.d.ts +6 -0
  235. package/dist/declarations/src/core-modules/segments/fingerprint.d.ts.map +1 -0
  236. package/dist/declarations/src/core-modules/segments/index.d.ts +31 -0
  237. package/dist/declarations/src/core-modules/segments/index.d.ts.map +1 -0
  238. package/dist/declarations/src/core-modules/segments/joinChanges.d.ts +11 -0
  239. package/dist/declarations/src/core-modules/segments/joinChanges.d.ts.map +1 -0
  240. package/dist/declarations/src/core-modules/segments/materialized.d.ts +9 -0
  241. package/dist/declarations/src/core-modules/segments/materialized.d.ts.map +1 -0
  242. package/dist/declarations/src/core-modules/segments/measureRelations.d.ts +18 -0
  243. package/dist/declarations/src/core-modules/segments/measureRelations.d.ts.map +1 -0
  244. package/dist/declarations/src/core-modules/segments/memberQuery.d.ts +13 -0
  245. package/dist/declarations/src/core-modules/segments/memberQuery.d.ts.map +1 -0
  246. package/dist/declarations/src/core-modules/segments/membership.d.ts +24 -0
  247. package/dist/declarations/src/core-modules/segments/membership.d.ts.map +1 -0
  248. package/dist/declarations/src/core-modules/segments/mongoFilter.d.ts +15 -0
  249. package/dist/declarations/src/core-modules/segments/mongoFilter.d.ts.map +1 -0
  250. package/dist/declarations/src/core-modules/segments/nodeRefs.d.ts +5 -0
  251. package/dist/declarations/src/core-modules/segments/nodeRefs.d.ts.map +1 -0
  252. package/dist/declarations/src/core-modules/segments/nodes.d.ts +42 -0
  253. package/dist/declarations/src/core-modules/segments/nodes.d.ts.map +1 -0
  254. package/dist/declarations/src/core-modules/segments/operators.d.ts +46 -0
  255. package/dist/declarations/src/core-modules/segments/operators.d.ts.map +1 -0
  256. package/dist/declarations/src/core-modules/segments/ownedSource.d.ts +7 -0
  257. package/dist/declarations/src/core-modules/segments/ownedSource.d.ts.map +1 -0
  258. package/dist/declarations/src/core-modules/segments/plan.d.ts +35 -0
  259. package/dist/declarations/src/core-modules/segments/plan.d.ts.map +1 -0
  260. package/dist/declarations/src/core-modules/segments/relationRegistry.d.ts +33 -0
  261. package/dist/declarations/src/core-modules/segments/relationRegistry.d.ts.map +1 -0
  262. package/dist/declarations/src/core-modules/segments/setupSegmentProducers.d.ts +4 -0
  263. package/dist/declarations/src/core-modules/segments/setupSegmentProducers.d.ts.map +1 -0
  264. package/dist/declarations/src/core-modules/segments/subjectsReachedBy.d.ts +11 -0
  265. package/dist/declarations/src/core-modules/segments/subjectsReachedBy.d.ts.map +1 -0
  266. package/dist/declarations/src/core-modules/segments/timeZone.d.ts +2 -0
  267. package/dist/declarations/src/core-modules/segments/timeZone.d.ts.map +1 -0
  268. package/dist/declarations/src/core-modules/segments/types.d.ts +67 -0
  269. package/dist/declarations/src/core-modules/segments/types.d.ts.map +1 -0
  270. package/dist/declarations/src/core-modules/segments/utils.d.ts +4 -0
  271. package/dist/declarations/src/core-modules/segments/utils.d.ts.map +1 -0
  272. package/dist/declarations/src/core-modules/segments/walkNodes.d.ts +9 -0
  273. package/dist/declarations/src/core-modules/segments/walkNodes.d.ts.map +1 -0
  274. package/dist/declarations/src/core-modules/segments/zodSchemas.d.ts +532 -0
  275. package/dist/declarations/src/core-modules/segments/zodSchemas.d.ts.map +1 -0
  276. package/dist/declarations/src/core-modules/segments/zonedTime.d.ts +25 -0
  277. package/dist/declarations/src/core-modules/segments/zonedTime.d.ts.map +1 -0
  278. package/dist/declarations/src/core-modules/templates/index.d.ts +2 -0
  279. package/dist/declarations/src/core-modules/templates/index.d.ts.map +1 -0
  280. package/dist/declarations/src/core-modules/templates/utils.d.ts +11 -0
  281. package/dist/declarations/src/core-modules/templates/utils.d.ts.map +1 -0
  282. package/dist/declarations/src/core-modules/users/constants.d.ts +114 -0
  283. package/dist/declarations/src/core-modules/users/constants.d.ts.map +1 -0
  284. package/dist/declarations/src/core-modules/users/db/definitions/users.d.ts +24 -0
  285. package/dist/declarations/src/core-modules/users/db/definitions/users.d.ts.map +1 -0
  286. package/dist/declarations/src/core-modules/users/index.d.ts +3 -0
  287. package/dist/declarations/src/core-modules/users/index.d.ts.map +1 -0
  288. package/dist/declarations/src/core-types/common.d.ts +149 -0
  289. package/dist/declarations/src/core-types/common.d.ts.map +1 -0
  290. package/dist/declarations/src/core-types/index.d.ts +20 -0
  291. package/dist/declarations/src/core-types/index.d.ts.map +1 -0
  292. package/dist/declarations/src/core-types/modules/app/app.d.ts +12 -0
  293. package/dist/declarations/src/core-types/modules/app/app.d.ts.map +1 -0
  294. package/dist/declarations/src/core-types/modules/automations/automations.d.ts +19 -0
  295. package/dist/declarations/src/core-types/modules/automations/automations.d.ts.map +1 -0
  296. package/dist/declarations/src/core-types/modules/contacts/company.d.ts +53 -0
  297. package/dist/declarations/src/core-types/modules/contacts/company.d.ts.map +1 -0
  298. package/dist/declarations/src/core-types/modules/contacts/contacts-common.d.ts +32 -0
  299. package/dist/declarations/src/core-types/modules/contacts/contacts-common.d.ts.map +1 -0
  300. package/dist/declarations/src/core-types/modules/contacts/customer.d.ts +74 -0
  301. package/dist/declarations/src/core-types/modules/contacts/customer.d.ts.map +1 -0
  302. package/dist/declarations/src/core-types/modules/emailTemplates/emailTemplate.d.ts +18 -0
  303. package/dist/declarations/src/core-types/modules/emailTemplates/emailTemplate.d.ts.map +1 -0
  304. package/dist/declarations/src/core-types/modules/logs/logs.d.ts +28 -0
  305. package/dist/declarations/src/core-types/modules/logs/logs.d.ts.map +1 -0
  306. package/dist/declarations/src/core-types/modules/permissions/permission.d.ts +56 -0
  307. package/dist/declarations/src/core-types/modules/permissions/permission.d.ts.map +1 -0
  308. package/dist/declarations/src/core-types/modules/permissions/role.d.ts +21 -0
  309. package/dist/declarations/src/core-types/modules/permissions/role.d.ts.map +1 -0
  310. package/dist/declarations/src/core-types/modules/products/product.d.ts +76 -0
  311. package/dist/declarations/src/core-types/modules/products/product.d.ts.map +1 -0
  312. package/dist/declarations/src/core-types/modules/products/productCategory.d.ts +26 -0
  313. package/dist/declarations/src/core-types/modules/products/productCategory.d.ts.map +1 -0
  314. package/dist/declarations/src/core-types/modules/products/productConfig.d.ts +9 -0
  315. package/dist/declarations/src/core-types/modules/products/productConfig.d.ts.map +1 -0
  316. package/dist/declarations/src/core-types/modules/products/uom.d.ts +11 -0
  317. package/dist/declarations/src/core-types/modules/products/uom.d.ts.map +1 -0
  318. package/dist/declarations/src/core-types/modules/relations/relations.d.ts +13 -0
  319. package/dist/declarations/src/core-types/modules/relations/relations.d.ts.map +1 -0
  320. package/dist/declarations/src/core-types/modules/saas/organization.d.ts +8 -0
  321. package/dist/declarations/src/core-types/modules/saas/organization.d.ts.map +1 -0
  322. package/dist/declarations/src/core-types/modules/tags/tag.d.ts +16 -0
  323. package/dist/declarations/src/core-types/modules/tags/tag.d.ts.map +1 -0
  324. package/dist/declarations/src/core-types/modules/team-member/structure.d.ts +19 -0
  325. package/dist/declarations/src/core-types/modules/team-member/structure.d.ts.map +1 -0
  326. package/dist/declarations/src/core-types/modules/team-member/user.d.ts +90 -0
  327. package/dist/declarations/src/core-types/modules/team-member/user.d.ts.map +1 -0
  328. package/dist/declarations/src/index.d.ts +3 -0
  329. package/dist/declarations/src/index.d.ts.map +1 -0
  330. package/dist/declarations/src/utils/agent-tools/auth.d.ts +18 -0
  331. package/dist/declarations/src/utils/agent-tools/auth.d.ts.map +1 -0
  332. package/dist/declarations/src/utils/agent-tools/endpoints.d.ts +16 -0
  333. package/dist/declarations/src/utils/agent-tools/endpoints.d.ts.map +1 -0
  334. package/dist/declarations/src/utils/agent-tools/index.d.ts +6 -0
  335. package/dist/declarations/src/utils/agent-tools/index.d.ts.map +1 -0
  336. package/dist/declarations/src/utils/agent-tools/manifest.d.ts +11 -0
  337. package/dist/declarations/src/utils/agent-tools/manifest.d.ts.map +1 -0
  338. package/dist/declarations/src/utils/agent-tools/responseLimit.d.ts +26 -0
  339. package/dist/declarations/src/utils/agent-tools/responseLimit.d.ts.map +1 -0
  340. package/dist/declarations/src/utils/agent-tools/types.d.ts +48 -0
  341. package/dist/declarations/src/utils/agent-tools/types.d.ts.map +1 -0
  342. package/dist/declarations/src/utils/apollo/beforeResolvers.d.ts +41 -0
  343. package/dist/declarations/src/utils/apollo/beforeResolvers.d.ts.map +1 -0
  344. package/dist/declarations/src/utils/apollo/commonTypeDefs.d.ts +7 -0
  345. package/dist/declarations/src/utils/apollo/commonTypeDefs.d.ts.map +1 -0
  346. package/dist/declarations/src/utils/apollo/constants.d.ts +3 -0
  347. package/dist/declarations/src/utils/apollo/constants.d.ts.map +1 -0
  348. package/dist/declarations/src/utils/apollo/customScalars.d.ts +6 -0
  349. package/dist/declarations/src/utils/apollo/customScalars.d.ts.map +1 -0
  350. package/dist/declarations/src/utils/apollo/expectedErrorPlugin.d.ts +11 -0
  351. package/dist/declarations/src/utils/apollo/expectedErrorPlugin.d.ts.map +1 -0
  352. package/dist/declarations/src/utils/apollo/index.d.ts +10 -0
  353. package/dist/declarations/src/utils/apollo/index.d.ts.map +1 -0
  354. package/dist/declarations/src/utils/apollo/runBeforeResolvers.d.ts +27 -0
  355. package/dist/declarations/src/utils/apollo/runBeforeResolvers.d.ts.map +1 -0
  356. package/dist/declarations/src/utils/apollo/utils.d.ts +5 -0
  357. package/dist/declarations/src/utils/apollo/utils.d.ts.map +1 -0
  358. package/dist/declarations/src/utils/apollo/wrapperMutations.d.ts +8 -0
  359. package/dist/declarations/src/utils/apollo/wrapperMutations.d.ts.map +1 -0
  360. package/dist/declarations/src/utils/apollo/wrapperResolvers.d.ts +8 -0
  361. package/dist/declarations/src/utils/apollo/wrapperResolvers.d.ts.map +1 -0
  362. package/dist/declarations/src/utils/bulkUtils.d.ts +7 -0
  363. package/dist/declarations/src/utils/bulkUtils.d.ts.map +1 -0
  364. package/dist/declarations/src/utils/constants.d.ts +40 -0
  365. package/dist/declarations/src/utils/constants.d.ts.map +1 -0
  366. package/dist/declarations/src/utils/editor.d.ts +45 -0
  367. package/dist/declarations/src/utils/editor.d.ts.map +1 -0
  368. package/dist/declarations/src/utils/email/address.d.ts +10 -0
  369. package/dist/declarations/src/utils/email/address.d.ts.map +1 -0
  370. package/dist/declarations/src/utils/email/attachments.d.ts +12 -0
  371. package/dist/declarations/src/utils/email/attachments.d.ts.map +1 -0
  372. package/dist/declarations/src/utils/email/config.d.ts +10 -0
  373. package/dist/declarations/src/utils/email/config.d.ts.map +1 -0
  374. package/dist/declarations/src/utils/email/constants.d.ts +6 -0
  375. package/dist/declarations/src/utils/email/constants.d.ts.map +1 -0
  376. package/dist/declarations/src/utils/email/index.d.ts +12 -0
  377. package/dist/declarations/src/utils/email/index.d.ts.map +1 -0
  378. package/dist/declarations/src/utils/email/providers/sendgrid.d.ts +17 -0
  379. package/dist/declarations/src/utils/email/providers/sendgrid.d.ts.map +1 -0
  380. package/dist/declarations/src/utils/email/providers/sendgridEvents.d.ts +18 -0
  381. package/dist/declarations/src/utils/email/providers/sendgridEvents.d.ts.map +1 -0
  382. package/dist/declarations/src/utils/email/providers/ses.d.ts +19 -0
  383. package/dist/declarations/src/utils/email/providers/ses.d.ts.map +1 -0
  384. package/dist/declarations/src/utils/email/providers/smtp.d.ts +14 -0
  385. package/dist/declarations/src/utils/email/providers/smtp.d.ts.map +1 -0
  386. package/dist/declarations/src/utils/email/resolveProvider.d.ts +6 -0
  387. package/dist/declarations/src/utils/email/resolveProvider.d.ts.map +1 -0
  388. package/dist/declarations/src/utils/email/service.d.ts +50 -0
  389. package/dist/declarations/src/utils/email/service.d.ts.map +1 -0
  390. package/dist/declarations/src/utils/email/types.d.ts +87 -0
  391. package/dist/declarations/src/utils/email/types.d.ts.map +1 -0
  392. package/dist/declarations/src/utils/errorClassifier.d.ts +56 -0
  393. package/dist/declarations/src/utils/errorClassifier.d.ts.map +1 -0
  394. package/dist/declarations/src/utils/file/read.d.ts +14 -0
  395. package/dist/declarations/src/utils/file/read.d.ts.map +1 -0
  396. package/dist/declarations/src/utils/file/upload.d.ts +10 -0
  397. package/dist/declarations/src/utils/file/upload.d.ts.map +1 -0
  398. package/dist/declarations/src/utils/graphqlPubSub.d.ts +3 -0
  399. package/dist/declarations/src/utils/graphqlPubSub.d.ts.map +1 -0
  400. package/dist/declarations/src/utils/headers/get-hostname.d.ts +5 -0
  401. package/dist/declarations/src/utils/headers/get-hostname.d.ts.map +1 -0
  402. package/dist/declarations/src/utils/headers/index.d.ts +5 -0
  403. package/dist/declarations/src/utils/headers/index.d.ts.map +1 -0
  404. package/dist/declarations/src/utils/headers/sanitize.d.ts +3 -0
  405. package/dist/declarations/src/utils/headers/sanitize.d.ts.map +1 -0
  406. package/dist/declarations/src/utils/headers/subdomain.d.ts +4 -0
  407. package/dist/declarations/src/utils/headers/subdomain.d.ts.map +1 -0
  408. package/dist/declarations/src/utils/headers/user.d.ts +14 -0
  409. package/dist/declarations/src/utils/headers/user.d.ts.map +1 -0
  410. package/dist/declarations/src/utils/index.d.ts +28 -0
  411. package/dist/declarations/src/utils/index.d.ts.map +1 -0
  412. package/dist/declarations/src/utils/knowledge.d.ts +50 -0
  413. package/dist/declarations/src/utils/knowledge.d.ts.map +1 -0
  414. package/dist/declarations/src/utils/logs/index.d.ts +103 -0
  415. package/dist/declarations/src/utils/logs/index.d.ts.map +1 -0
  416. package/dist/declarations/src/utils/mongo/cursor-util.d.ts +41 -0
  417. package/dist/declarations/src/utils/mongo/cursor-util.d.ts.map +1 -0
  418. package/dist/declarations/src/utils/mongo/generate-models.d.ts +4 -0
  419. package/dist/declarations/src/utils/mongo/generate-models.d.ts.map +1 -0
  420. package/dist/declarations/src/utils/mongo/index.d.ts +6 -0
  421. package/dist/declarations/src/utils/mongo/index.d.ts.map +1 -0
  422. package/dist/declarations/src/utils/mongo/mongo-connection.d.ts +5 -0
  423. package/dist/declarations/src/utils/mongo/mongo-connection.d.ts.map +1 -0
  424. package/dist/declarations/src/utils/mongo/mongoose-types.d.ts +22 -0
  425. package/dist/declarations/src/utils/mongo/mongoose-types.d.ts.map +1 -0
  426. package/dist/declarations/src/utils/mongo/mongoose-utils.d.ts +30 -0
  427. package/dist/declarations/src/utils/mongo/mongoose-utils.d.ts.map +1 -0
  428. package/dist/declarations/src/utils/mongo/search-tokens.d.ts +21 -0
  429. package/dist/declarations/src/utils/mongo/search-tokens.d.ts.map +1 -0
  430. package/dist/declarations/src/utils/mq-worker.d.ts +19 -0
  431. package/dist/declarations/src/utils/mq-worker.d.ts.map +1 -0
  432. package/dist/declarations/src/utils/random.d.ts +3 -0
  433. package/dist/declarations/src/utils/random.d.ts.map +1 -0
  434. package/dist/declarations/src/utils/redis.d.ts +4 -0
  435. package/dist/declarations/src/utils/redis.d.ts.map +1 -0
  436. package/dist/declarations/src/utils/saas/index.d.ts +3 -0
  437. package/dist/declarations/src/utils/saas/index.d.ts.map +1 -0
  438. package/dist/declarations/src/utils/saas/saas-mongo-connection.d.ts +59 -0
  439. package/dist/declarations/src/utils/saas/saas-mongo-connection.d.ts.map +1 -0
  440. package/dist/declarations/src/utils/saas/types.d.ts +96 -0
  441. package/dist/declarations/src/utils/saas/types.d.ts.map +1 -0
  442. package/dist/declarations/src/utils/sanitize.d.ts +3 -0
  443. package/dist/declarations/src/utils/sanitize.d.ts.map +1 -0
  444. package/dist/declarations/src/utils/sentry-init.d.ts +15 -0
  445. package/dist/declarations/src/utils/sentry-init.d.ts.map +1 -0
  446. package/dist/declarations/src/utils/sentry-instrument.d.ts +2 -0
  447. package/dist/declarations/src/utils/sentry-instrument.d.ts.map +1 -0
  448. package/dist/declarations/src/utils/serializablePayload.d.ts +11 -0
  449. package/dist/declarations/src/utils/serializablePayload.d.ts.map +1 -0
  450. package/dist/declarations/src/utils/service-discovery.d.ts +25 -0
  451. package/dist/declarations/src/utils/service-discovery.d.ts.map +1 -0
  452. package/dist/declarations/src/utils/start-plugin.d.ts +85 -0
  453. package/dist/declarations/src/utils/start-plugin.d.ts.map +1 -0
  454. package/dist/declarations/src/utils/string.d.ts +82 -0
  455. package/dist/declarations/src/utils/string.d.ts.map +1 -0
  456. package/dist/declarations/src/utils/trpc/index.d.ts +79 -0
  457. package/dist/declarations/src/utils/trpc/index.d.ts.map +1 -0
  458. package/dist/declarations/src/utils/trpc/sendCoreModuleProducer.d.ts +53 -0
  459. package/dist/declarations/src/utils/trpc/sendCoreModuleProducer.d.ts.map +1 -0
  460. package/dist/declarations/src/utils/utils.d.ts +69 -0
  461. package/dist/declarations/src/utils/utils.d.ts.map +1 -0
  462. package/dist/erxes-api-shared.cjs.d.ts +3 -0
  463. package/dist/erxes-api-shared.cjs.dev.js +7 -0
  464. package/dist/erxes-api-shared.cjs.js +7 -0
  465. package/dist/erxes-api-shared.cjs.prod.js +7 -0
  466. package/dist/erxes-api-shared.esm.js +3 -0
  467. package/dist/start-plugin-576e707d.cjs.prod.js +23223 -0
  468. package/dist/start-plugin-6e76556c.esm.js +22742 -0
  469. package/dist/start-plugin-89fa2bd2.cjs.dev.js +23225 -0
  470. package/package.json +105 -4
  471. package/src/common-modules/payment/worker.ts +53 -0
  472. package/src/core-modules/approval/approvalChangeTypes.ts +31 -0
  473. package/src/core-modules/approval/checkApprovalLock.ts +85 -0
  474. package/src/core-modules/approval/constants.ts +45 -0
  475. package/src/core-modules/approval/index.ts +6 -0
  476. package/src/core-modules/approval/initApproval.ts +59 -0
  477. package/src/core-modules/approval/types.ts +206 -0
  478. package/src/core-modules/approval/zodSchemas.ts +55 -0
  479. package/src/core-modules/apps/@types/app.ts +15 -0
  480. package/src/core-modules/apps/db/definitions/apps.ts +30 -0
  481. package/src/core-modules/apps/index.ts +2 -0
  482. package/src/core-modules/automations/actionErrorPolicy.test.ts +125 -0
  483. package/src/core-modules/automations/actionErrorPolicy.ts +162 -0
  484. package/src/core-modules/automations/actionInputs.test.ts +70 -0
  485. package/src/core-modules/automations/actionOutcome.test.ts +87 -0
  486. package/src/core-modules/automations/actionOutcome.ts +128 -0
  487. package/src/core-modules/automations/constants.ts +181 -0
  488. package/src/core-modules/automations/definitions/aiAgents.ts +343 -0
  489. package/src/core-modules/automations/definitions/automations.ts +207 -0
  490. package/src/core-modules/automations/definitions/executions.ts +190 -0
  491. package/src/core-modules/automations/definitions/index.ts +3 -0
  492. package/src/core-modules/automations/getValueByPath.test.ts +49 -0
  493. package/src/core-modules/automations/index.ts +13 -0
  494. package/src/core-modules/automations/outputResolvers.test.ts +97 -0
  495. package/src/core-modules/automations/outputResolvers.ts +1238 -0
  496. package/src/core-modules/automations/reEnrollment.ts +34 -0
  497. package/src/core-modules/automations/segmentMembership.ts +34 -0
  498. package/src/core-modules/automations/sendAutomationMessage.ts +219 -0
  499. package/src/core-modules/automations/setPropertyOutcome.test.ts +105 -0
  500. package/src/core-modules/automations/setPropertyRows.test.ts +61 -0
  501. package/src/core-modules/automations/setupAutomationProducers.ts +187 -0
  502. package/src/core-modules/automations/typeUtils.ts +3 -0
  503. package/src/core-modules/automations/types.ts +577 -0
  504. package/src/core-modules/automations/utils.ts +1128 -0
  505. package/src/core-modules/automations/workflowValidation.ts +32 -0
  506. package/src/core-modules/automations/zodTypes.ts +221 -0
  507. package/src/core-modules/client-portals/definitions/clientPortal.ts +230 -0
  508. package/src/core-modules/client-portals/definitions/comment.ts +26 -0
  509. package/src/core-modules/client-portals/definitions/cpNotification.ts +112 -0
  510. package/src/core-modules/client-portals/definitions/cpUser.ts +236 -0
  511. package/src/core-modules/client-portals/index.ts +4 -0
  512. package/src/core-modules/common/db/definitions/common.ts +43 -0
  513. package/src/core-modules/common/eventHandlers/createEventHandlers.ts +236 -0
  514. package/src/core-modules/common/eventHandlers/generateEventHandlers.ts +37 -0
  515. package/src/core-modules/common/eventHandlers/index.ts +11 -0
  516. package/src/core-modules/common/eventHandlers/runtimeContext.ts +36 -0
  517. package/src/core-modules/common/eventHandlers/schemas.ts +53 -0
  518. package/src/core-modules/common/eventHandlers/types.ts +97 -0
  519. package/src/core-modules/common/eventHandlers/utils.ts +113 -0
  520. package/src/core-modules/common/index.ts +4 -0
  521. package/src/core-modules/common/references/fetchRecordReferenceTargets.ts +43 -0
  522. package/src/core-modules/common/references/getRecordReferenceFields.ts +243 -0
  523. package/src/core-modules/common/references/index.ts +9 -0
  524. package/src/core-modules/common/references/initRecordReferences.ts +84 -0
  525. package/src/core-modules/common/references/normalizeRecordReferenceConfig.ts +59 -0
  526. package/src/core-modules/common/references/resolveRecordReferencePath.ts +473 -0
  527. package/src/core-modules/common/references/resolveRecordReferencePlaceholders.ts +173 -0
  528. package/src/core-modules/common/references/resolveRecordReferenceValue.ts +41 -0
  529. package/src/core-modules/common/references/resolveRecordRelationIds.ts +57 -0
  530. package/src/core-modules/common/references/types.ts +78 -0
  531. package/src/core-modules/common/references/utils.ts +60 -0
  532. package/src/core-modules/common/references/zodInputs.ts +13 -0
  533. package/src/core-modules/common/routeToModuleProducer.ts +118 -0
  534. package/src/core-modules/email-content/blocksToHtml.ts +551 -0
  535. package/src/core-modules/email-content/constants.ts +4 -0
  536. package/src/core-modules/email-content/emailFooter.ts +17 -0
  537. package/src/core-modules/email-content/expandRepeatRows.test.ts +36 -0
  538. package/src/core-modules/email-content/expandRepeatRows.ts +59 -0
  539. package/src/core-modules/email-content/index.ts +8 -0
  540. package/src/core-modules/email-content/renderEmailContent.ts +88 -0
  541. package/src/core-modules/email-content/replacePlaceholders.ts +143 -0
  542. package/src/core-modules/email-content/types.ts +49 -0
  543. package/src/core-modules/email-content/unresolvedPlaceholders.ts +27 -0
  544. package/src/core-modules/forms/index.ts +2 -0
  545. package/src/core-modules/forms/types.ts +86 -0
  546. package/src/core-modules/forms/utils.ts +34 -0
  547. package/src/core-modules/import-export/index.ts +7 -0
  548. package/src/core-modules/import-export/types.ts +204 -0
  549. package/src/core-modules/import-export/utils/createCoreImportClient.ts +131 -0
  550. package/src/core-modules/import-export/utils/exportBatchProcess.ts +560 -0
  551. package/src/core-modules/import-export/utils/exportCursor.ts +47 -0
  552. package/src/core-modules/import-export/utils/headerMatcher.test.ts +90 -0
  553. package/src/core-modules/import-export/utils/headerMatcher.ts +229 -0
  554. package/src/core-modules/import-export/utils/importBatchProcess.ts +780 -0
  555. package/src/core-modules/import-export/utils/importExportError.ts +71 -0
  556. package/src/core-modules/import-export/utils/importExportRuntime.ts +96 -0
  557. package/src/core-modules/import-export/utils/importUtils.ts +59 -0
  558. package/src/core-modules/import-export/utils/progressUpdate.ts +25 -0
  559. package/src/core-modules/import-export/utils/tempWorkspace.ts +34 -0
  560. package/src/core-modules/import-export/worker.ts +215 -0
  561. package/src/core-modules/import-export/zodSchemas.ts +63 -0
  562. package/src/core-modules/index.ts +15 -0
  563. package/src/core-modules/logs/activityLog/builder.ts +232 -0
  564. package/src/core-modules/logs/activityLog/index.ts +4 -0
  565. package/src/core-modules/logs/activityLog/sharedBuilders.ts +95 -0
  566. package/src/core-modules/logs/activityLog/types.ts +26 -0
  567. package/src/core-modules/logs/activityLog/utils.ts +61 -0
  568. package/src/core-modules/logs/activityLogUtils.ts +677 -0
  569. package/src/core-modules/logs/definitions/activityLog.ts +71 -0
  570. package/src/core-modules/logs/definitions/logs.ts +49 -0
  571. package/src/core-modules/logs/index.ts +5 -0
  572. package/src/core-modules/logs/types.ts +16 -0
  573. package/src/core-modules/notifications/definitions/emailAddresses.ts +105 -0
  574. package/src/core-modules/notifications/definitions/emailDeliveries.ts +188 -0
  575. package/src/core-modules/notifications/definitions/emailRamp.ts +83 -0
  576. package/src/core-modules/notifications/definitions/emailSenders.ts +84 -0
  577. package/src/core-modules/notifications/definitions/notificationConfigs.ts +110 -0
  578. package/src/core-modules/notifications/definitions/notificationSettings.ts +67 -0
  579. package/src/core-modules/notifications/definitions/notifications.ts +130 -0
  580. package/src/core-modules/notifications/emailUtils.ts +88 -0
  581. package/src/core-modules/notifications/index.ts +7 -0
  582. package/src/core-modules/notifications/utils.ts +143 -0
  583. package/src/core-modules/permissions/db/definitions/permissions.ts +82 -0
  584. package/src/core-modules/permissions/index.ts +3 -0
  585. package/src/core-modules/permissions/oauth-scopes.test.ts +102 -0
  586. package/src/core-modules/permissions/user-actions-map.ts +170 -0
  587. package/src/core-modules/permissions/utils.ts +317 -0
  588. package/src/core-modules/properties/README.md +161 -0
  589. package/src/core-modules/properties/filter.test.ts +74 -0
  590. package/src/core-modules/properties/filter.ts +156 -0
  591. package/src/core-modules/properties/importExport.ts +159 -0
  592. package/src/core-modules/properties/index.ts +9 -0
  593. package/src/core-modules/properties/keys.test.ts +71 -0
  594. package/src/core-modules/properties/keys.ts +128 -0
  595. package/src/core-modules/properties/mergePropertyData.test.ts +65 -0
  596. package/src/core-modules/properties/mergeRows.ts +93 -0
  597. package/src/core-modules/properties/operators.ts +91 -0
  598. package/src/core-modules/properties/options.test.ts +119 -0
  599. package/src/core-modules/properties/options.ts +55 -0
  600. package/src/core-modules/properties/setupPropertyProducers.ts +32 -0
  601. package/src/core-modules/properties/types.ts +31 -0
  602. package/src/core-modules/properties/valueUsage.test.ts +158 -0
  603. package/src/core-modules/properties/valueUsage.ts +153 -0
  604. package/src/core-modules/segments/anniversary.test.ts +122 -0
  605. package/src/core-modules/segments/dependencies.test.ts +173 -0
  606. package/src/core-modules/segments/dependencies.ts +70 -0
  607. package/src/core-modules/segments/evaluate.test.ts +339 -0
  608. package/src/core-modules/segments/evaluate.ts +388 -0
  609. package/src/core-modules/segments/evaluateBatch.test.ts +233 -0
  610. package/src/core-modules/segments/evaluateBatch.ts +263 -0
  611. package/src/core-modules/segments/evaluateFieldsRouter.test.ts +148 -0
  612. package/src/core-modules/segments/evaluateFieldsRouter.ts +94 -0
  613. package/src/core-modules/segments/evaluateOwned.ts +162 -0
  614. package/src/core-modules/segments/events.ts +142 -0
  615. package/src/core-modules/segments/fieldBuilders.ts +152 -0
  616. package/src/core-modules/segments/fieldMeta.ts +96 -0
  617. package/src/core-modules/segments/fieldRequests.test.ts +302 -0
  618. package/src/core-modules/segments/fieldRequests.ts +172 -0
  619. package/src/core-modules/segments/fieldSources.test.ts +99 -0
  620. package/src/core-modules/segments/fingerprint.test.ts +111 -0
  621. package/src/core-modules/segments/fingerprint.ts +70 -0
  622. package/src/core-modules/segments/index.ts +30 -0
  623. package/src/core-modules/segments/joinChanges.test.ts +96 -0
  624. package/src/core-modules/segments/joinChanges.ts +67 -0
  625. package/src/core-modules/segments/materialized.ts +23 -0
  626. package/src/core-modules/segments/measureRelations.test.ts +222 -0
  627. package/src/core-modules/segments/measureRelations.ts +322 -0
  628. package/src/core-modules/segments/memberQuery.test.ts +60 -0
  629. package/src/core-modules/segments/memberQuery.ts +45 -0
  630. package/src/core-modules/segments/membership.ts +170 -0
  631. package/src/core-modules/segments/mongoFilter.test.ts +326 -0
  632. package/src/core-modules/segments/mongoFilter.ts +355 -0
  633. package/src/core-modules/segments/nodeRefs.ts +29 -0
  634. package/src/core-modules/segments/nodes.ts +48 -0
  635. package/src/core-modules/segments/operators.ts +243 -0
  636. package/src/core-modules/segments/ownedSource.ts +16 -0
  637. package/src/core-modules/segments/plan.test.ts +172 -0
  638. package/src/core-modules/segments/plan.ts +155 -0
  639. package/src/core-modules/segments/relationRegistry.test.ts +64 -0
  640. package/src/core-modules/segments/relationRegistry.ts +198 -0
  641. package/src/core-modules/segments/segmentReference.test.ts +142 -0
  642. package/src/core-modules/segments/setupSegmentProducers.ts +77 -0
  643. package/src/core-modules/segments/subjectsReachedBy.ts +70 -0
  644. package/src/core-modules/segments/timeZone.ts +56 -0
  645. package/src/core-modules/segments/types.ts +97 -0
  646. package/src/core-modules/segments/utils.ts +122 -0
  647. package/src/core-modules/segments/walkNodes.ts +76 -0
  648. package/src/core-modules/segments/zodSchemas.ts +130 -0
  649. package/src/core-modules/segments/zonedTime.test.ts +163 -0
  650. package/src/core-modules/segments/zonedTime.ts +198 -0
  651. package/src/core-modules/templates/index.ts +1 -0
  652. package/src/core-modules/templates/utils.ts +91 -0
  653. package/src/core-modules/users/constants.ts +318 -0
  654. package/src/core-modules/users/db/definitions/users.ts +226 -0
  655. package/src/core-modules/users/index.ts +2 -0
  656. package/src/core-types/common.ts +183 -0
  657. package/src/core-types/index.ts +19 -0
  658. package/src/core-types/modules/app/app.ts +13 -0
  659. package/src/core-types/modules/automations/automations.ts +23 -0
  660. package/src/core-types/modules/contacts/company.ts +70 -0
  661. package/src/core-types/modules/contacts/contacts-common.ts +32 -0
  662. package/src/core-types/modules/contacts/customer.ts +94 -0
  663. package/src/core-types/modules/emailTemplates/emailTemplate.ts +19 -0
  664. package/src/core-types/modules/emailTemplates/index.ts +1 -0
  665. package/src/core-types/modules/logs/logs.ts +30 -0
  666. package/src/core-types/modules/permissions/permission.ts +63 -0
  667. package/src/core-types/modules/permissions/role.ts +24 -0
  668. package/src/core-types/modules/products/product.ts +100 -0
  669. package/src/core-types/modules/products/productCategory.ts +27 -0
  670. package/src/core-types/modules/products/productConfig.ts +10 -0
  671. package/src/core-types/modules/products/uom.ts +12 -0
  672. package/src/core-types/modules/relations/relations.ts +14 -0
  673. package/src/core-types/modules/saas/organization.ts +7 -0
  674. package/src/core-types/modules/structure/structure.ts +29 -0
  675. package/src/core-types/modules/tags/tag.ts +17 -0
  676. package/src/core-types/modules/team-member/structure.ts +23 -0
  677. package/src/core-types/modules/team-member/user.ts +93 -0
  678. package/src/index.ts +1 -0
  679. package/src/utils/agent-tools/auth.ts +129 -0
  680. package/src/utils/agent-tools/endpoints.ts +274 -0
  681. package/src/utils/agent-tools/index.ts +5 -0
  682. package/src/utils/agent-tools/manifest.ts +152 -0
  683. package/src/utils/agent-tools/responseLimit.test.ts +99 -0
  684. package/src/utils/agent-tools/responseLimit.ts +66 -0
  685. package/src/utils/agent-tools/types.ts +52 -0
  686. package/src/utils/apollo/beforeResolvers.ts +117 -0
  687. package/src/utils/apollo/commonTypeDefs.ts +78 -0
  688. package/src/utils/apollo/constants.ts +16 -0
  689. package/src/utils/apollo/customScalars.ts +69 -0
  690. package/src/utils/apollo/expectedErrorPlugin.ts +83 -0
  691. package/src/utils/apollo/index.ts +10 -0
  692. package/src/utils/apollo/runBeforeResolvers.ts +214 -0
  693. package/src/utils/apollo/utils.ts +80 -0
  694. package/src/utils/apollo/wrapperMutations.ts +75 -0
  695. package/src/utils/apollo/wrapperResolvers.ts +182 -0
  696. package/src/utils/bulkUtils.ts +62 -0
  697. package/src/utils/constants.ts +99 -0
  698. package/src/utils/editor.ts +412 -0
  699. package/src/utils/email/address.ts +42 -0
  700. package/src/utils/email/attachments.ts +74 -0
  701. package/src/utils/email/config.ts +46 -0
  702. package/src/utils/email/constants.ts +25 -0
  703. package/src/utils/email/index.ts +11 -0
  704. package/src/utils/email/providers/sendgrid.ts +280 -0
  705. package/src/utils/email/providers/sendgridEvents.ts +48 -0
  706. package/src/utils/email/providers/ses.ts +250 -0
  707. package/src/utils/email/providers/smtp.ts +99 -0
  708. package/src/utils/email/resolveProvider.ts +75 -0
  709. package/src/utils/email/service.ts +192 -0
  710. package/src/utils/email/types.ts +127 -0
  711. package/src/utils/errorClassifier.test.ts +231 -0
  712. package/src/utils/errorClassifier.ts +458 -0
  713. package/src/utils/file/read.ts +464 -0
  714. package/src/utils/file/upload.ts +531 -0
  715. package/src/utils/graphqlPubSub.ts +28 -0
  716. package/src/utils/headers/get-hostname.ts +18 -0
  717. package/src/utils/headers/index.ts +4 -0
  718. package/src/utils/headers/sanitize.ts +9 -0
  719. package/src/utils/headers/subdomain.ts +13 -0
  720. package/src/utils/headers/user.test.ts +76 -0
  721. package/src/utils/headers/user.ts +113 -0
  722. package/src/utils/index.ts +27 -0
  723. package/src/utils/knowledge.ts +107 -0
  724. package/src/utils/logs/index.ts +247 -0
  725. package/src/utils/mongo/cursor-util.ts +153 -0
  726. package/src/utils/mongo/generate-models.ts +97 -0
  727. package/src/utils/mongo/index.ts +5 -0
  728. package/src/utils/mongo/mongo-connection.ts +42 -0
  729. package/src/utils/mongo/mongoose-types.ts +26 -0
  730. package/src/utils/mongo/mongoose-utils.ts +329 -0
  731. package/src/utils/mongo/search-tokens.ts +193 -0
  732. package/src/utils/mq-worker.ts +150 -0
  733. package/src/utils/random.ts +6 -0
  734. package/src/utils/redis.ts +23 -0
  735. package/src/utils/saas/constants.ts +32 -0
  736. package/src/utils/saas/definition.ts +318 -0
  737. package/src/utils/saas/index.ts +2 -0
  738. package/src/utils/saas/saas-mongo-connection.ts +595 -0
  739. package/src/utils/saas/types.ts +107 -0
  740. package/src/utils/sanitize.ts +73 -0
  741. package/src/utils/sentry-init.ts +128 -0
  742. package/src/utils/sentry-instrument.ts +5 -0
  743. package/src/utils/serializablePayload.test.ts +65 -0
  744. package/src/utils/serializablePayload.ts +44 -0
  745. package/src/utils/service-discovery.ts +256 -0
  746. package/src/utils/start-plugin.ts +482 -0
  747. package/src/utils/string.ts +159 -0
  748. package/src/utils/trpc/index.ts +278 -0
  749. package/src/utils/trpc/sendCoreModuleProducer.ts +146 -0
  750. package/src/utils/trpc/trpc-setup.ts +91 -0
  751. package/src/utils/utils.ts +669 -0
  752. package/utils/dist/erxes-api-shared-utils.cjs.d.ts +2 -0
  753. package/utils/dist/erxes-api-shared-utils.cjs.dev.js +3066 -0
  754. package/utils/dist/erxes-api-shared-utils.cjs.js +7 -0
  755. package/utils/dist/erxes-api-shared-utils.cjs.prod.js +3066 -0
  756. package/utils/dist/erxes-api-shared-utils.esm.js +2776 -0
  757. package/utils/package.json +5 -0
  758. package/README.md +0 -3
@@ -0,0 +1,2776 @@
1
+ import { u as userHeaderName, g as getEnv, c as connect, _ as _asyncToGenerator, a as _regeneratorRuntime, b as coreModelOrganizations, d as getSubdomain, e as getSaasCoreConnection, f as createScopedEventHandlers, h as _slicedToArray, l as logHandler, r as runBeforeResolvers, s as sendWorkerQueue, i as _objectSpread2, j as chunkArray, k as _createForOfIteratorHelper, m as _createClass, n as _classCallCheck, o as isValidURL, p as sendTRPCMessage, q as _inherits, t as _wrapNativeSuper, v as _callSuper, w as _defineProperty, x as _toConsumableArray } from '../../dist/start-plugin-6e76556c.esm.js';
2
+ export { K as AGENT_TOOL_DEFAULT_MAX_RESPONSE_BYTES, ak as DEFAULT_JOB_OPTIONS, bY as EXPECTED_ERROR_NAME, bZ as ExpectedError, W as HEADER_SIZE_WARN_BYTES, b7 as MAX_HEADER_BYTES, aA as ORGANIZATION_ID_MAPPING, T as TBeforeResolversProducers, V as USER_HEADER_OMITTED_FIELDS, N as agentToolResponseTooLargeError, F as agentToolsAuthHeaderName, y as apolloCustomScalars, bi as applyTrustProxy, bk as authCookieOptions, I as buildAgentToolManifest, bR as buildCursorQuery, ag as buildSearchTokenFilter, D as checkBeforeResolvers, aa as checkCollectionCodeDuplication, bH as checkServiceRunning, bt as checkUserIds, j as chunkArray, b$ as classifyError, bW as cleanHtml, b0 as clearServiceDiscoveryCache, P as clientPortalHeaderName, ad as closeMongooose, X as compactUserForHeader, ah as configureSchemaSearchTokens, c as connect, bj as connectionOptions, ar as coreModelAddons, as as coreModelBundles, av as coreModelEndpoints, ay as coreModelExperiences, at as coreModelInstallations, az as coreModelOrganizationPlanHistories, b as coreModelOrganizations, ax as coreModelPlugins, aw as coreModelPromoCodes, au as coreModelUsers, Q as cpUserHeaderName, b_ as createExpectedError, bG as createHealthRoute, al as createMQWorkerWithListeners, bc as createPluginTRPCContext, bd as createTRPCContext, a8 as cursorPaginate, a9 as cursorPaginateAggregation, bC as dateToShortStr, H as decodeAgentToolsAuthHeader, bQ as decodeCursor, bb as decodeTRPCContextHeader, a7 as defaultPaginate, G as encodeAgentToolsAuthHeader, bP as encodeCursor, ba as encodeTRPCContextHeader, bf as err, bp as escapeRegExp, E as expectedErrorPlugin, S as extractCPUserFromHeader, U as extractClientPortalFromHeader, c1 as extractMessage, R as extractUserFromHeader, bs as fixDate, bB as fixNum, bK as flattenObject, z as generateApolloContext, af as generateConfiguredSearchTokens, bI as generateRequestProcess, a_ as getActivePlugins, L as getAgentToolMaxResponseBytes, a$ as getAvailablePlugins, bo as getCoreDomain, bv as getDate, bJ as getDiffObjects, g as getEnv, bx as getFullDate, bA as getNextMonth, b1 as getPlugin, b5 as getPluginAddress, aY as getPlugins, by as getPureDate, e as getSaasCoreConnection, aT as getSaasOrgPromoCodes, aO as getSaasOrganizationActiveAddons, aH as getSaasOrganizationByHelpCenterDomain, aM as getSaasOrganizationDetail, aI as getSaasOrganizationHelpCenterDomains, aB as getSaasOrganizationIdBySubdomain, aN as getSaasOrganizationPlanHistories, aD as getSaasOrganizations, aE as getSaasOrganizationsByFilter, aJ as getSaasOrganizationsWithPendingHelpCenterDomain, aC as getSaasOrgsCache, aR as getSaasPlugin, aQ as getSaasPlugins, aS as getSaasPromoCodes, ai as getSchemaSearchTokenConfig, d as getSubdomain, bw as getToday, bz as getTomorrow, bh as getTrustProxySetting, bu as getUniqueValue, O as graphqlPubsub, aG as helpCenterDomainsOf, c3 as initErxesSentry, b6 as initializePluginConfig, aW as isDev, b4 as isEnabled, c0 as isExpectedError, bE as isImage, o as isValidURL, bF as isVideo, b2 as joinErxesGateway, aX as keyForConfig, b3 as leaveErxesGateway, l as logHandler, B as markResolvers, a3 as mongoStringRequired, ac as mongooseConnectionOptions, a5 as mongooseField, a2 as mongooseStringNonBlank, a1 as mongooseStringRandomId, a4 as mongooseStringRequiredNonBlank, J as mountAgentTools, be as ok, M as oversizedAgentToolResultBytes, bl as paginate, br as pluralFormation, bX as random, an as randomAlphanumeric, ao as randomLowercase, bM as readFileFromStorage, bN as readFileStreamFromStorage, bL as readFileUrl, ap as redis, bn as regexSearchText, bU as removeExtraSpaces, bT as removeLastTrailingSlash, aP as removeOrgsCache, aL as removeSaasOrganizationHelpCenterDomain, aq as resetConfigsCache, r as runBeforeResolvers, aU as sanitizeFilename, aV as sanitizeKey, aK as saveSaasOrganizationHelpCenterDomain, ab as schemaWrapper, bg as sendCoreModuleProducer, p as sendTRPCMessage, am as sendWorkerMessage, s as sendWorkerQueue, c2 as sentryExpectedErrorFilter, aZ as setActivePlugins, Z as setCPUserHeader, $ as setClientPortalHeader, Y as setUserHeader, bD as shortStrToDate, ae as splitSearchWords, bV as splitStr, a0 as startAfterProcess, C as startBeforeResolvers, b8 as startPlugin, bS as stripAnsi, aj as toSerializablePayload, b9 as trpcContextHeaderName, a6 as updateMongoDocumentOrder, bq as updateOrder, aF as updateSaasOrganization, bO as uploadFileToStorage, u as userHeaderName, bm as validSearchText, A as wrapApolloResolvers } from '../../dist/start-plugin-6e76556c.esm.js';
3
+ import mongoose from 'mongoose';
4
+ import { Transform } from 'stream';
5
+ import { keyBy } from 'lodash';
6
+ import fetch from 'node-fetch';
7
+ import * as crypto from 'crypto';
8
+ import * as AWS from 'aws-sdk';
9
+ import * as nodemailer from 'nodemailer';
10
+ import '@sentry/node';
11
+ import 'node:fs';
12
+ import 'node:path';
13
+ import '@apollo/server';
14
+ import '@apollo/server/express4';
15
+ import '@apollo/server/plugin/drainHttpServer';
16
+ import '@apollo/subgraph';
17
+ import '@trpc/server/adapters/express';
18
+ import 'cookie-parser';
19
+ import 'cors';
20
+ import 'dotenv';
21
+ import 'express';
22
+ import 'http';
23
+ import 'path';
24
+ import 'express-rate-limit';
25
+ import 'graphql';
26
+ import 'graphql/language';
27
+ import 'dayjs';
28
+ import 'nanoid';
29
+ import 'ioredis';
30
+ import 'bullmq';
31
+ import '@trpc/client';
32
+ import 'async_hooks';
33
+ import 'zod';
34
+ import '@trpc/server';
35
+ import 'node:crypto';
36
+ import 'graphql-redis-subscriptions';
37
+ import '@azure/storage-blob';
38
+ import '@google-cloud/storage';
39
+ import 'fs';
40
+ import 'form-data';
41
+ import 'os';
42
+ import 'csv-parse';
43
+
44
+ var graphqlAttachmentType = "\n type Attachment {\n url: String!\n name: String\n type: String\n size: Float\n duration: Float\n }\n";
45
+ var graphqlAttachmentInput = "\n input AttachmentInput {\n url: String!\n name: String!\n type: String\n size: Float\n duration: Float\n }\n";
46
+ var graphqlPdfAttachmentType = "\n type PdfAttachment {\n pdf: Attachment\n pages: [Attachment]\n }\n";
47
+ var graphqlPdfAttachmentInput = "\n input PdfAttachmentInput {\n pdf: AttachmentInput\n pages: [AttachmentInput]\n }\n";
48
+ var graphqlPaginationInfo = "\n type PageInfo {\n hasNextPage: Boolean,\n hasPreviousPage: Boolean,\n startCursor: String,\n endCursor: String,\n }\n";
49
+ var apolloCommonTypes = "\n scalar Date\n scalar JSON\n\n enum CURSOR_DIRECTION {\n forward,\n backward\n }\n\n enum CURSOR_MODE {\n inclusive,\n exclusive\n }\n\n enum CONTACT_STATUS {\n active,\n deleted\n }\n\n type Coordinate {\n longitude: String\n latitude: String\n }\n\n input CoordinateInput {\n longitude: String\n latitude: String\n }\n\n ".concat(graphqlAttachmentType, "\n ").concat(graphqlAttachmentInput, "\n ").concat(graphqlPdfAttachmentType, "\n ").concat(graphqlPdfAttachmentInput, "\n ").concat(graphqlPaginationInfo, "\n");
50
+
51
+ var GQL_CURSOR_PARAM_DEFS = "\n limit: Int\n cursor: String\n cursorMode: CURSOR_MODE\n direction: CURSOR_DIRECTION\n orderBy: JSON\n sortMode: String\n aggregationPipeline: [JSON]\n";
52
+ var GQL_OFFSET_PARAM_DEFS = "\n page: Int\n perPage: Int\n sortField: String\n sortDirection: String\n";
53
+
54
+ var erxesSubdomainHeaderName = 'erxes-subdomain';
55
+ var getSubomdainHeader = function getSubomdainHeader(req) {
56
+ var subdomainHeader = req.headers[erxesSubdomainHeaderName];
57
+ if (Array.isArray(subdomainHeader)) {
58
+ throw new Error("Multiple ".concat(erxesSubdomainHeaderName, " headers!"));
59
+ }
60
+ return subdomainHeader;
61
+ };
62
+
63
+ function sanitizeHeaders(headers) {
64
+ delete headers[erxesSubdomainHeaderName];
65
+ delete headers[userHeaderName];
66
+ delete headers['userid'];
67
+ }
68
+
69
+ // trimmed version of getHostname, since we don't enable trust
70
+ var getHostnameZeroTrust = function getHostnameZeroTrust(req) {
71
+ var host = req.headers.host;
72
+ if (!host) return;
73
+
74
+ // IPv6 literal support
75
+ var offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
76
+ var index = host.indexOf(':', offset);
77
+ return index !== -1 ? host.substring(0, index) : host;
78
+ };
79
+
80
+ var returnGeneratedModels = /*#__PURE__*/function () {
81
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(connection, loadClasses, subdomain, context) {
82
+ var eventHandlers;
83
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
84
+ while (1) switch (_context.prev = _context.next) {
85
+ case 0:
86
+ eventHandlers = createScopedEventHandlers(subdomain, context);
87
+ _context.next = 3;
88
+ return loadClasses(connection, subdomain, eventHandlers);
89
+ case 3:
90
+ return _context.abrupt("return", _context.sent);
91
+ case 4:
92
+ case "end":
93
+ return _context.stop();
94
+ }
95
+ }, _callee);
96
+ }));
97
+ return function returnGeneratedModels(_x, _x2, _x3, _x4) {
98
+ return _ref.apply(this, arguments);
99
+ };
100
+ }();
101
+ var createGenerateModels = function createGenerateModels(loadClasses) {
102
+ var VERSION = getEnv({
103
+ name: 'VERSION',
104
+ defaultValue: 'os'
105
+ });
106
+ connect();
107
+ if (VERSION && VERSION !== 'saas') {
108
+ return /*#__PURE__*/function () {
109
+ var _genereteModels = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(hostnameOrSubdomain, context) {
110
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
111
+ while (1) switch (_context2.prev = _context2.next) {
112
+ case 0:
113
+ _context2.next = 2;
114
+ return returnGeneratedModels(mongoose.connection, loadClasses, hostnameOrSubdomain, context);
115
+ case 2:
116
+ return _context2.abrupt("return", _context2.sent);
117
+ case 3:
118
+ case "end":
119
+ return _context2.stop();
120
+ }
121
+ }, _callee2);
122
+ }));
123
+ function genereteModels(_x5, _x6) {
124
+ return _genereteModels.apply(this, arguments);
125
+ }
126
+ return genereteModels;
127
+ }();
128
+ } else {
129
+ return /*#__PURE__*/function () {
130
+ var _genereteModels2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
131
+ var _subdomain;
132
+ var hostnameOrSubdomain,
133
+ context,
134
+ subdomain,
135
+ organization,
136
+ DB_NAME,
137
+ GE_MONGO_URL,
138
+ tenantCon,
139
+ _args3 = arguments;
140
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
141
+ while (1) switch (_context3.prev = _context3.next) {
142
+ case 0:
143
+ hostnameOrSubdomain = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : '';
144
+ context = _args3.length > 1 ? _args3[1] : undefined;
145
+ subdomain = hostnameOrSubdomain;
146
+ if (subdomain) {
147
+ _context3.next = 5;
148
+ break;
149
+ }
150
+ throw new Error("Subdomain is `".concat(subdomain, "`"));
151
+ case 5:
152
+ // means hostname
153
+ if ((_subdomain = subdomain) !== null && _subdomain !== void 0 && _subdomain.includes('.')) {
154
+ subdomain = getSubdomain(hostnameOrSubdomain);
155
+ }
156
+ _context3.next = 8;
157
+ return getSaasCoreConnection();
158
+ case 8:
159
+ _context3.next = 10;
160
+ return coreModelOrganizations.findOne({
161
+ subdomain: subdomain
162
+ });
163
+ case 10:
164
+ organization = _context3.sent;
165
+ if (organization) {
166
+ _context3.next = 13;
167
+ break;
168
+ }
169
+ throw new Error("Organization with subdomain = ".concat(subdomain, " is not found"));
170
+ case 13:
171
+ DB_NAME = getEnv({
172
+ name: 'DB_NAME'
173
+ });
174
+ GE_MONGO_URL = (DB_NAME || 'erxes_<organizationId>').replace('<organizationId>', organization._id);
175
+ tenantCon = mongoose.connection.useDb(GE_MONGO_URL, {
176
+ // so that conn.model method can use cached connection
177
+ useCache: true,
178
+ noListener: true
179
+ });
180
+ _context3.next = 18;
181
+ return returnGeneratedModels(tenantCon, loadClasses, subdomain, context);
182
+ case 18:
183
+ return _context3.abrupt("return", _context3.sent);
184
+ case 19:
185
+ case "end":
186
+ return _context3.stop();
187
+ }
188
+ }, _callee3);
189
+ }));
190
+ function genereteModels() {
191
+ return _genereteModels2.apply(this, arguments);
192
+ }
193
+ return genereteModels;
194
+ }();
195
+ }
196
+ };
197
+
198
+ var withLogging = function withLogging(resolver) {
199
+ return /*#__PURE__*/function () {
200
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(root, args, context, info) {
201
+ var user, req, processId, subdomain, requestData;
202
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
203
+ while (1) switch (_context2.prev = _context2.next) {
204
+ case 0:
205
+ user = context.user, req = context.req, processId = context.processId, subdomain = context.subdomain;
206
+ requestData = req.headers;
207
+ _context2.next = 4;
208
+ return logHandler(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
209
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
210
+ while (1) switch (_context.prev = _context.next) {
211
+ case 0:
212
+ _context.next = 2;
213
+ return resolver(root, args, context, info);
214
+ case 2:
215
+ return _context.abrupt("return", _context.sent);
216
+ case 3:
217
+ case "end":
218
+ return _context.stop();
219
+ }
220
+ }, _callee);
221
+ })), {
222
+ subdomain: subdomain,
223
+ source: 'graphql',
224
+ action: 'mutation',
225
+ payload: {
226
+ mutationName: info.fieldName,
227
+ requestData: requestData,
228
+ args: args
229
+ },
230
+ processId: processId,
231
+ userId: user === null || user === void 0 ? void 0 : user._id
232
+ });
233
+ case 4:
234
+ return _context2.abrupt("return", _context2.sent);
235
+ case 5:
236
+ case "end":
237
+ return _context2.stop();
238
+ }
239
+ }, _callee2);
240
+ }));
241
+ return function (_x, _x2, _x3, _x4) {
242
+ return _ref.apply(this, arguments);
243
+ };
244
+ }();
245
+ };
246
+ var withBefore = function withBefore(resolver, resolverKey) {
247
+ return /*#__PURE__*/function () {
248
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(root, args, context, info) {
249
+ var _requestInfo, _req;
250
+ var subdomain, user, headers, result;
251
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
252
+ while (1) switch (_context3.prev = _context3.next) {
253
+ case 0:
254
+ subdomain = context.subdomain, user = context.user;
255
+ headers = ((_requestInfo = context.requestInfo) === null || _requestInfo === void 0 ? void 0 : _requestInfo.headers) || ((_req = context.req) === null || _req === void 0 ? void 0 : _req.headers);
256
+ _context3.next = 4;
257
+ return runBeforeResolvers(resolverKey, args, {
258
+ subdomain: subdomain,
259
+ user: user,
260
+ headers: headers
261
+ });
262
+ case 4:
263
+ result = _context3.sent;
264
+ if (!result.resolved) {
265
+ _context3.next = 7;
266
+ break;
267
+ }
268
+ return _context3.abrupt("return", result.data);
269
+ case 7:
270
+ return _context3.abrupt("return", resolver(root, result.args, context, info));
271
+ case 8:
272
+ case "end":
273
+ return _context3.stop();
274
+ }
275
+ }, _callee3);
276
+ }));
277
+ return function (_x5, _x6, _x7, _x8) {
278
+ return _ref3.apply(this, arguments);
279
+ };
280
+ }();
281
+ };
282
+
283
+ // Apply middleware to all mutations in an object
284
+ var wrapApolloMutations = function wrapApolloMutations(mutations, muataionsForSkip) {
285
+ var wrappedMutations = {};
286
+ for (var _i = 0, _Object$entries = Object.entries(mutations); _i < _Object$entries.length; _i++) {
287
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
288
+ key = _Object$entries$_i[0],
289
+ resolver = _Object$entries$_i[1];
290
+ if (muataionsForSkip !== null && muataionsForSkip !== void 0 && muataionsForSkip.includes(key)) {
291
+ wrappedMutations[key] = resolver;
292
+ } else {
293
+ wrappedMutations[key] = withLogging(withBefore(resolver, key));
294
+ }
295
+ }
296
+ return wrappedMutations;
297
+ };
298
+
299
+ var STATUSES = [{
300
+ label: 'Active',
301
+ value: 'Active'
302
+ }, {
303
+ label: 'Deleted',
304
+ value: 'Deleted'
305
+ }];
306
+ var DEFAULT_SOCIAL_LINKS = [{
307
+ label: 'Facebook',
308
+ value: 'facebook'
309
+ }, {
310
+ label: 'whatsapp',
311
+ value: 'whatsapp'
312
+ }, {
313
+ label: 'Twitter',
314
+ value: 'twitter'
315
+ }, {
316
+ label: 'Youtube',
317
+ value: 'youtube'
318
+ }, {
319
+ label: 'Website',
320
+ value: 'website'
321
+ }];
322
+ var SOCIAL_LINKS = [].concat(DEFAULT_SOCIAL_LINKS, [{
323
+ label: 'Academia.edu',
324
+ value: 'academia.edu'
325
+ }, {
326
+ label: 'Chess.com',
327
+ value: 'chess.com'
328
+ }, {
329
+ label: 'Crunchyroll',
330
+ value: 'crunchyroll'
331
+ }, {
332
+ label: 'DeviantArt',
333
+ value: 'deviantArt'
334
+ }, {
335
+ label: 'Discord',
336
+ value: 'discord'
337
+ }, {
338
+ label: 'Douban',
339
+ value: 'douban'
340
+ }, {
341
+ label: 'eToro',
342
+ value: 'eToro'
343
+ }, {
344
+ label: 'Flickr',
345
+ value: 'flickr'
346
+ }, {
347
+ label: 'Gapo',
348
+ value: 'gapo'
349
+ }, {
350
+ label: 'Goodreads',
351
+ value: 'goodreads'
352
+ }, {
353
+ label: 'GitHub',
354
+ value: 'gitHub'
355
+ }, {
356
+ label: 'Instagram',
357
+ value: 'instagram'
358
+ }, {
359
+ label: 'KakaoStory',
360
+ value: 'kakaoStory'
361
+ }, {
362
+ label: 'KizlarSoruyor',
363
+ value: 'kizlarSoruyor'
364
+ }, {
365
+ label: 'Last.fm',
366
+ value: 'last.fm'
367
+ }, {
368
+ label: 'LinkedIn',
369
+ value: 'linkedIn'
370
+ }, {
371
+ label: 'LiveJournal',
372
+ value: 'liveJournal'
373
+ }, {
374
+ label: 'Pinterest',
375
+ value: 'pinterest'
376
+ }, {
377
+ label: 'Pixnet',
378
+ value: 'pixnet'
379
+ }, {
380
+ label: 'Plurk',
381
+ value: 'plurk'
382
+ }, {
383
+ label: 'Quora',
384
+ value: 'quora'
385
+ }, {
386
+ label: 'Reddit',
387
+ value: 'reddit'
388
+ }, {
389
+ label: 'Renren',
390
+ value: 'renren'
391
+ }, {
392
+ label: 'Sina Weibo',
393
+ value: 'sinaWeibo'
394
+ }, {
395
+ label: 'SoundCloud',
396
+ value: 'soundCloud'
397
+ }, {
398
+ label: 'Spotify',
399
+ value: 'spotify'
400
+ }, {
401
+ label: 'Steam',
402
+ value: 'steam'
403
+ }, {
404
+ label: 'Tagged',
405
+ value: 'tagged'
406
+ }, {
407
+ label: 'Taringa',
408
+ value: 'taringa'
409
+ }, {
410
+ label: 'Tumblr',
411
+ value: 'tumblr'
412
+ }, {
413
+ label: 'VK',
414
+ value: 'vk'
415
+ }, {
416
+ label: 'Voat',
417
+ value: 'voat'
418
+ }, {
419
+ label: 'Wattpad',
420
+ value: 'wattpad'
421
+ }, {
422
+ label: 'XING',
423
+ value: 'xing'
424
+ }, {
425
+ label: 'Yammer',
426
+ value: 'yammer'
427
+ }, {
428
+ label: 'Yelp',
429
+ value: 'yelp'
430
+ }]);
431
+ var DEFAULT_SEX_CHOICES = [{
432
+ label: 'Not known',
433
+ value: 0
434
+ }, {
435
+ label: 'Male',
436
+ value: 1
437
+ }, {
438
+ label: 'Female',
439
+ value: 2
440
+ }, {
441
+ label: 'Not applicable',
442
+ value: 9
443
+ }];
444
+ var SEX_OPTIONS = [].concat(DEFAULT_SEX_CHOICES, [{
445
+ label: 'co/co',
446
+ value: 10
447
+ }, {
448
+ label: 'en/en',
449
+ value: 11
450
+ }, {
451
+ label: 'ey/em',
452
+ value: 12
453
+ }, {
454
+ label: 'he/him',
455
+ value: 13
456
+ }, {
457
+ label: 'he/them',
458
+ value: 14
459
+ }, {
460
+ label: 'she/her',
461
+ value: 15
462
+ }, {
463
+ label: 'she/them',
464
+ value: 16
465
+ }, {
466
+ label: 'they/them',
467
+ value: 17
468
+ }, {
469
+ label: 'xie/hir',
470
+ value: 18
471
+ }, {
472
+ label: 'yo/yo',
473
+ value: 19
474
+ }, {
475
+ label: 'ze/zir',
476
+ value: 20
477
+ }, {
478
+ label: 've/vis',
479
+ value: 21
480
+ }, {
481
+ label: 'xe/xem',
482
+ value: 22
483
+ }]);
484
+ var USER_ROLES = {
485
+ SYSTEM: 'system',
486
+ USER: 'user',
487
+ ALL: ['system', 'user']
488
+ };
489
+ var LOG_STATUSES = {
490
+ FAILED: 'failed',
491
+ SUCCESS: 'success'
492
+ };
493
+ var CONFORMITY_TYPE = {
494
+ customers: 'customer',
495
+ companies: 'company'
496
+ };
497
+ var PERMISSION_ROLES = {
498
+ OWNER: 'owner',
499
+ ADMIN: 'admin',
500
+ MEMBER: 'member',
501
+ ALL: ['owner', 'admin', 'member']
502
+ };
503
+
504
+ var buildKnowledgeSourceType = function buildKnowledgeSourceType(_ref) {
505
+ var pluginName = _ref.pluginName,
506
+ moduleName = _ref.moduleName,
507
+ key = _ref.key;
508
+ return "".concat(pluginName, ":").concat(moduleName, ":").concat(key);
509
+ };
510
+ var enqueueKnowledgeIndexJob = /*#__PURE__*/function () {
511
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
512
+ var subdomain, job, jobOptions, source, queue;
513
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
514
+ while (1) switch (_context.prev = _context.next) {
515
+ case 0:
516
+ subdomain = _ref2.subdomain, job = _ref2.job, jobOptions = _ref2.jobOptions;
517
+ source = job.operation === 'upsert' ? job.document.source : job.source;
518
+ queue = sendWorkerQueue('automations', 'aiAgent');
519
+ return _context.abrupt("return", queue.add('indexKnowledgeDocument', {
520
+ subdomain: subdomain,
521
+ data: job
522
+ }, _objectSpread2({
523
+ attempts: 2,
524
+ jobId: "knowledge:".concat(source.type, ":").concat(source.id, ":").concat(job.operation, ":").concat(source.version, ":").concat(source.updatedAt),
525
+ removeOnComplete: true,
526
+ removeOnFail: true
527
+ }, jobOptions)));
528
+ case 4:
529
+ case "end":
530
+ return _context.stop();
531
+ }
532
+ }, _callee);
533
+ }));
534
+ return function enqueueKnowledgeIndexJob(_x) {
535
+ return _ref3.apply(this, arguments);
536
+ };
537
+ }();
538
+ var enqueueAiKnowledgeSourceRefreshJob = /*#__PURE__*/function () {
539
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
540
+ var subdomain, source, jobOptions, queue;
541
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
542
+ while (1) switch (_context2.prev = _context2.next) {
543
+ case 0:
544
+ subdomain = _ref4.subdomain, source = _ref4.source, jobOptions = _ref4.jobOptions;
545
+ queue = sendWorkerQueue('automations', 'aiAgent');
546
+ return _context2.abrupt("return", queue.add('refreshAiKnowledgeSource', {
547
+ subdomain: subdomain,
548
+ data: {
549
+ source: source
550
+ }
551
+ }, _objectSpread2({
552
+ attempts: 2,
553
+ jobId: "knowledge-source:".concat(source.pluginName, ":").concat(source.moduleName, ":").concat(source.key, ":").concat(source.sourceId, ":").concat(source.updatedAt),
554
+ removeOnComplete: true,
555
+ removeOnFail: true
556
+ }, jobOptions)));
557
+ case 3:
558
+ case "end":
559
+ return _context2.stop();
560
+ }
561
+ }, _callee2);
562
+ }));
563
+ return function enqueueAiKnowledgeSourceRefreshJob(_x2) {
564
+ return _ref5.apply(this, arguments);
565
+ };
566
+ }();
567
+
568
+ var stream = /*#__PURE__*/function () {
569
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(executeChunk, transformCallback, generateChildStream, chunkSize) {
570
+ var variables, onFinishPiping, parentTransformerStream, childCursor;
571
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
572
+ while (1) switch (_context3.prev = _context3.next) {
573
+ case 0:
574
+ variables = {}; // Function to handle remaining items after streaming
575
+ onFinishPiping = /*#__PURE__*/function () {
576
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
577
+ var chunks, _iterator, _step, chunk;
578
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
579
+ while (1) switch (_context.prev = _context.next) {
580
+ case 0:
581
+ if (!(variables.parentIds && variables.parentIds.length > 0)) {
582
+ _context.next = 19;
583
+ break;
584
+ }
585
+ chunks = chunkArray(variables.parentIds, chunkSize);
586
+ _iterator = _createForOfIteratorHelper(chunks);
587
+ _context.prev = 3;
588
+ _iterator.s();
589
+ case 5:
590
+ if ((_step = _iterator.n()).done) {
591
+ _context.next = 11;
592
+ break;
593
+ }
594
+ chunk = _step.value;
595
+ _context.next = 9;
596
+ return executeChunk(chunk);
597
+ case 9:
598
+ _context.next = 5;
599
+ break;
600
+ case 11:
601
+ _context.next = 16;
602
+ break;
603
+ case 13:
604
+ _context.prev = 13;
605
+ _context.t0 = _context["catch"](3);
606
+ _iterator.e(_context.t0);
607
+ case 16:
608
+ _context.prev = 16;
609
+ _iterator.f();
610
+ return _context.finish(16);
611
+ case 19:
612
+ case "end":
613
+ return _context.stop();
614
+ }
615
+ }, _callee, null, [[3, 13, 16, 19]]);
616
+ }));
617
+ return function onFinishPiping() {
618
+ return _ref2.apply(this, arguments);
619
+ };
620
+ }(); // Transformer stream to process each item
621
+ parentTransformerStream = new Transform({
622
+ objectMode: true,
623
+ transform: function transform(root, _encoding, callback) {
624
+ try {
625
+ transformCallback(variables, root);
626
+ callback();
627
+ } catch (err) {
628
+ callback(err);
629
+ }
630
+ }
631
+ });
632
+ childCursor = generateChildStream().cursor();
633
+ _context3.prev = 4;
634
+ _context3.next = 7;
635
+ return new Promise(function (resolve, reject) {
636
+ childCursor.pipe(parentTransformerStream);
637
+ parentTransformerStream.on('finish', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
638
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
639
+ while (1) switch (_context2.prev = _context2.next) {
640
+ case 0:
641
+ _context2.prev = 0;
642
+ _context2.next = 3;
643
+ return onFinishPiping();
644
+ case 3:
645
+ resolve();
646
+ _context2.next = 9;
647
+ break;
648
+ case 6:
649
+ _context2.prev = 6;
650
+ _context2.t0 = _context2["catch"](0);
651
+ reject(_context2.t0);
652
+ case 9:
653
+ case "end":
654
+ return _context2.stop();
655
+ }
656
+ }, _callee2, null, [[0, 6]]);
657
+ })));
658
+ parentTransformerStream.on('error', reject);
659
+ });
660
+ case 7:
661
+ return _context3.abrupt("return", 'done');
662
+ case 10:
663
+ _context3.prev = 10;
664
+ _context3.t0 = _context3["catch"](4);
665
+ parentTransformerStream.destroy();
666
+ throw _context3.t0;
667
+ case 14:
668
+ _context3.prev = 14;
669
+ if (typeof childCursor.destroy === 'function') {
670
+ childCursor.destroy();
671
+ }
672
+ return _context3.finish(14);
673
+ case 17:
674
+ case "end":
675
+ return _context3.stop();
676
+ }
677
+ }, _callee3, null, [[4, 10, 14, 17]]);
678
+ }));
679
+ return function stream(_x, _x2, _x3, _x4) {
680
+ return _ref.apply(this, arguments);
681
+ };
682
+ }();
683
+
684
+ var getCustomerName = function getCustomerName(customer) {
685
+ if (customer.firstName || customer.lastName) {
686
+ return (customer.firstName || '') + ' ' + (customer.lastName || '');
687
+ }
688
+ if (customer.primaryEmail || customer.primaryPhone) {
689
+ return customer.primaryEmail || customer.primaryPhone;
690
+ }
691
+ var visitorContactInfo = customer.visitorContactInfo;
692
+ if (visitorContactInfo) {
693
+ return visitorContactInfo.phone || visitorContactInfo.email;
694
+ }
695
+ return 'Unknown';
696
+ };
697
+ function runReplacersOn(content) {
698
+ var replacers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
699
+ var replacedContent = content;
700
+ var _iterator = _createForOfIteratorHelper(replacers),
701
+ _step;
702
+ try {
703
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
704
+ var replacer = _step.value;
705
+ var regex = new RegExp(replacer.key, 'gi');
706
+ replacedContent = replacedContent.replace(regex, replacer.value);
707
+ }
708
+ } catch (err) {
709
+ _iterator.e(err);
710
+ } finally {
711
+ _iterator.f();
712
+ }
713
+ return replacedContent;
714
+ }
715
+ var EditorAttributeUtil = /*#__PURE__*/function () {
716
+ function EditorAttributeUtil(API_DOMAIN, availableServices, subdomain) {
717
+ _classCallCheck(this, EditorAttributeUtil);
718
+ this.API_DOMAIN = API_DOMAIN;
719
+ this.availableServices = new Set(availableServices);
720
+ this.subdomain = subdomain || 'os';
721
+ }
722
+ return _createClass(EditorAttributeUtil, [{
723
+ key: "fileToFileLink",
724
+ value: function () {
725
+ var _fileToFileLink = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, name) {
726
+ var href, key, uriName;
727
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
728
+ while (1) switch (_context.prev = _context.next) {
729
+ case 0:
730
+ if (url) {
731
+ _context.next = 2;
732
+ break;
733
+ }
734
+ return _context.abrupt("return", '');
735
+ case 2:
736
+ if (isValidURL(url) || url.includes('/')) {
737
+ href = url;
738
+ } else {
739
+ key = url;
740
+ uriName = name ? encodeURIComponent(name) : url;
741
+ href = "".concat(this.API_DOMAIN, "/read-file?key=").concat(key, "&name=").concat(uriName);
742
+ }
743
+ return _context.abrupt("return", "<a target=\"_blank\" download href=\"".concat(href, "\">").concat(name || url, "</a>"));
744
+ case 4:
745
+ case "end":
746
+ return _context.stop();
747
+ }
748
+ }, _callee, this);
749
+ }));
750
+ function fileToFileLink(_x, _x2) {
751
+ return _fileToFileLink.apply(this, arguments);
752
+ }
753
+ return fileToFileLink;
754
+ }()
755
+ }, {
756
+ key: "customFieldsDataItemToFileLink",
757
+ value: function () {
758
+ var _customFieldsDataItemToFileLink = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(customFieldDataItem) {
759
+ var _this = this;
760
+ var value, links;
761
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
762
+ while (1) switch (_context2.prev = _context2.next) {
763
+ case 0:
764
+ value = customFieldDataItem.value;
765
+ if (!Array.isArray(value)) {
766
+ _context2.next = 6;
767
+ break;
768
+ }
769
+ _context2.next = 4;
770
+ return Promise.all(value.map(function (v) {
771
+ return _this.fileToFileLink(v.url, v.name);
772
+ }));
773
+ case 4:
774
+ links = _context2.sent;
775
+ return _context2.abrupt("return", links.join(' | '));
776
+ case 6:
777
+ return _context2.abrupt("return", this.fileToFileLink(value.url, value.name));
778
+ case 7:
779
+ case "end":
780
+ return _context2.stop();
781
+ }
782
+ }, _callee2, this);
783
+ }));
784
+ function customFieldsDataItemToFileLink(_x3) {
785
+ return _customFieldsDataItemToFileLink.apply(this, arguments);
786
+ }
787
+ return customFieldsDataItemToFileLink;
788
+ }()
789
+ }, {
790
+ key: "getPossibleCustomerFields",
791
+ value: function () {
792
+ var _getPossibleCustomerFields = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
793
+ var _this$_possibleCustom;
794
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
795
+ while (1) switch (_context3.prev = _context3.next) {
796
+ case 0:
797
+ if (!((_this$_possibleCustom = this._possibleCustomerFields) !== null && _this$_possibleCustom !== void 0)) {
798
+ _context3.next = 4;
799
+ break;
800
+ }
801
+ _context3.next = 7;
802
+ break;
803
+ case 4:
804
+ _context3.next = 6;
805
+ return sendTRPCMessage({
806
+ subdomain: this.subdomain,
807
+ pluginName: 'core',
808
+ method: 'query',
809
+ module: 'fields',
810
+ action: 'fieldsCombinedByContentType',
811
+ input: {
812
+ contentType: 'core:customer'
813
+ }
814
+ });
815
+ case 6:
816
+ this._possibleCustomerFields = _context3.sent;
817
+ case 7:
818
+ if (this._possibleCustomerFields) {
819
+ _context3.next = 9;
820
+ break;
821
+ }
822
+ throw new Error('Cannot acquire possibleCustomerFields');
823
+ case 9:
824
+ return _context3.abrupt("return", this._possibleCustomerFields || []);
825
+ case 10:
826
+ case "end":
827
+ return _context3.stop();
828
+ }
829
+ }, _callee3, this);
830
+ }));
831
+ function getPossibleCustomerFields() {
832
+ return _getPossibleCustomerFields.apply(this, arguments);
833
+ }
834
+ return getPossibleCustomerFields;
835
+ }()
836
+ }, {
837
+ key: "getCustomerFields",
838
+ value: function () {
839
+ var _getCustomerFields = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(content) {
840
+ var customerFields, possibleCustomerFields, _iterator2, _step2, field;
841
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
842
+ while (1) switch (_context4.prev = _context4.next) {
843
+ case 0:
844
+ customerFields = ['firstName', 'lastName', 'middleName'];
845
+ _context4.next = 3;
846
+ return this.getPossibleCustomerFields();
847
+ case 3:
848
+ possibleCustomerFields = _context4.sent;
849
+ _iterator2 = _createForOfIteratorHelper(possibleCustomerFields);
850
+ _context4.prev = 5;
851
+ _iterator2.s();
852
+ case 7:
853
+ if ((_step2 = _iterator2.n()).done) {
854
+ _context4.next = 20;
855
+ break;
856
+ }
857
+ field = _step2.value;
858
+ if (content.includes("{{ customer.".concat(field.name, " }}"))) {
859
+ _context4.next = 11;
860
+ break;
861
+ }
862
+ return _context4.abrupt("continue", 18);
863
+ case 11:
864
+ if (!field.name.includes('trackedData')) {
865
+ _context4.next = 14;
866
+ break;
867
+ }
868
+ customerFields.push('trackedData');
869
+ return _context4.abrupt("continue", 18);
870
+ case 14:
871
+ if (!field.name.includes('customFieldsData')) {
872
+ _context4.next = 17;
873
+ break;
874
+ }
875
+ customerFields.push('customFieldsData');
876
+ return _context4.abrupt("continue", 18);
877
+ case 17:
878
+ customerFields.push(field.name);
879
+ case 18:
880
+ _context4.next = 7;
881
+ break;
882
+ case 20:
883
+ _context4.next = 25;
884
+ break;
885
+ case 22:
886
+ _context4.prev = 22;
887
+ _context4.t0 = _context4["catch"](5);
888
+ _iterator2.e(_context4.t0);
889
+ case 25:
890
+ _context4.prev = 25;
891
+ _iterator2.f();
892
+ return _context4.finish(25);
893
+ case 28:
894
+ return _context4.abrupt("return", customerFields);
895
+ case 29:
896
+ case "end":
897
+ return _context4.stop();
898
+ }
899
+ }, _callee4, this, [[5, 22, 25, 28]]);
900
+ }));
901
+ function getCustomerFields(_x4) {
902
+ return _getCustomerFields.apply(this, arguments);
903
+ }
904
+ return getCustomerFields;
905
+ }()
906
+ }, {
907
+ key: "fillMissingCustomFieldsDataItemOfCustomer",
908
+ value: function () {
909
+ var _fillMissingCustomFieldsDataItemOfCustomer = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(content, customer) {
910
+ var existingItemsByFieldId, possibleCustomerFields, _iterator3, _step3, field, fieldId;
911
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
912
+ while (1) switch (_context5.prev = _context5.next) {
913
+ case 0:
914
+ if (!customer.customFieldsData) {
915
+ customer.customFieldsData = [];
916
+ }
917
+ existingItemsByFieldId = keyBy(customer.customFieldsData, 'field');
918
+ _context5.next = 4;
919
+ return this.getPossibleCustomerFields();
920
+ case 4:
921
+ possibleCustomerFields = _context5.sent;
922
+ _iterator3 = _createForOfIteratorHelper(possibleCustomerFields);
923
+ _context5.prev = 6;
924
+ _iterator3.s();
925
+ case 8:
926
+ if ((_step3 = _iterator3.n()).done) {
927
+ _context5.next = 15;
928
+ break;
929
+ }
930
+ field = _step3.value;
931
+ if (content.includes("{{ customer.".concat(field.name, " }}"))) {
932
+ _context5.next = 12;
933
+ break;
934
+ }
935
+ return _context5.abrupt("continue", 13);
936
+ case 12:
937
+ if (field.name.includes('customFieldsData')) {
938
+ fieldId = field.name.split('.').pop(); // if content has attribute that doesn't have fieldId, fill with dummy item
939
+ // if content has field attribute that doesn't exist on the customer.customFieldsData, fill with dummy item
940
+ if (!fieldId || !existingItemsByFieldId[fieldId]) {
941
+ customer.customFieldsData.push({
942
+ field: fieldId || '',
943
+ stringValue: '',
944
+ value: ''
945
+ });
946
+ }
947
+ }
948
+ case 13:
949
+ _context5.next = 8;
950
+ break;
951
+ case 15:
952
+ _context5.next = 20;
953
+ break;
954
+ case 17:
955
+ _context5.prev = 17;
956
+ _context5.t0 = _context5["catch"](6);
957
+ _iterator3.e(_context5.t0);
958
+ case 20:
959
+ _context5.prev = 20;
960
+ _iterator3.f();
961
+ return _context5.finish(20);
962
+ case 23:
963
+ case "end":
964
+ return _context5.stop();
965
+ }
966
+ }, _callee5, this, [[6, 17, 20, 23]]);
967
+ }));
968
+ function fillMissingCustomFieldsDataItemOfCustomer(_x5, _x6) {
969
+ return _fillMissingCustomFieldsDataItemOfCustomer.apply(this, arguments);
970
+ }
971
+ return fillMissingCustomFieldsDataItemOfCustomer;
972
+ }()
973
+ }, {
974
+ key: "generateAmounts",
975
+ value: function () {
976
+ var _generateAmounts = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(productsData) {
977
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
978
+ while (1) switch (_context6.prev = _context6.next) {
979
+ case 0:
980
+ if (this.availableServices.has('sales')) {
981
+ _context6.next = 2;
982
+ break;
983
+ }
984
+ throw new Error('Sales service is not running.');
985
+ case 2:
986
+ return _context6.abrupt("return", sendTRPCMessage({
987
+ subdomain: this.subdomain,
988
+ pluginName: 'sales',
989
+ method: 'query',
990
+ module: 'deal',
991
+ action: 'generateAmounts',
992
+ input: productsData
993
+ }));
994
+ case 3:
995
+ case "end":
996
+ return _context6.stop();
997
+ }
998
+ }, _callee6, this);
999
+ }));
1000
+ function generateAmounts(_x7) {
1001
+ return _generateAmounts.apply(this, arguments);
1002
+ }
1003
+ return generateAmounts;
1004
+ }()
1005
+ }, {
1006
+ key: "generateProducts",
1007
+ value: function () {
1008
+ var _generateProducts = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(productsData) {
1009
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1010
+ while (1) switch (_context7.prev = _context7.next) {
1011
+ case 0:
1012
+ if (this.availableServices.has('sales')) {
1013
+ _context7.next = 2;
1014
+ break;
1015
+ }
1016
+ throw new Error('Sales service is not running.');
1017
+ case 2:
1018
+ return _context7.abrupt("return", sendTRPCMessage({
1019
+ subdomain: this.subdomain,
1020
+ pluginName: 'sales',
1021
+ method: 'query',
1022
+ module: 'deal',
1023
+ action: 'generateProducts',
1024
+ input: productsData
1025
+ }));
1026
+ case 3:
1027
+ case "end":
1028
+ return _context7.stop();
1029
+ }
1030
+ }, _callee7, this);
1031
+ }));
1032
+ function generateProducts(_x8) {
1033
+ return _generateProducts.apply(this, arguments);
1034
+ }
1035
+ return generateProducts;
1036
+ }()
1037
+ }, {
1038
+ key: "generateReplacers",
1039
+ value: function () {
1040
+ var _generateReplacers = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(args) {
1041
+ var _this2 = this;
1042
+ var content, user, brand, item, replacers, customer, customerFields, fields, customerFileFieldsById, _iterator4, _step4, field, dbFieldName, _iterator5, _step5, customFieldsDataItem, replaceValue, products, amounts, fieldMetaDatas, _iterator6, _step6, _loop;
1043
+ return _regeneratorRuntime().wrap(function _callee8$(_context9) {
1044
+ while (1) switch (_context9.prev = _context9.next) {
1045
+ case 0:
1046
+ content = args.content, user = args.user, brand = args.brand, item = args.item;
1047
+ replacers = []; // replace customer fields
1048
+ if (!args.customer) {
1049
+ _context9.next = 59;
1050
+ break;
1051
+ }
1052
+ customer = args.customer;
1053
+ customerFields = args.customerFields;
1054
+ if (!(!customerFields || customerFields.length === 0)) {
1055
+ _context9.next = 9;
1056
+ break;
1057
+ }
1058
+ _context9.next = 8;
1059
+ return this.getCustomerFields(content);
1060
+ case 8:
1061
+ customerFields = _context9.sent;
1062
+ case 9:
1063
+ _context9.next = 11;
1064
+ return this.fillMissingCustomFieldsDataItemOfCustomer(content, customer);
1065
+ case 11:
1066
+ replacers.push({
1067
+ key: '{{ customer.name }}',
1068
+ value: getCustomerName(customer) || 'Unknown'
1069
+ });
1070
+ _context9.next = 14;
1071
+ return sendTRPCMessage({
1072
+ subdomain: this.subdomain,
1073
+ pluginName: 'core',
1074
+ method: 'query',
1075
+ module: 'fields',
1076
+ action: 'find',
1077
+ input: {
1078
+ query: {
1079
+ type: 'file',
1080
+ contentType: 'core:customer'
1081
+ }
1082
+ }
1083
+ });
1084
+ case 14:
1085
+ fields = _context9.sent;
1086
+ customerFileFieldsById = keyBy(fields, '_id');
1087
+ _iterator4 = _createForOfIteratorHelper(customerFields);
1088
+ _context9.prev = 17;
1089
+ _iterator4.s();
1090
+ case 19:
1091
+ if ((_step4 = _iterator4.n()).done) {
1092
+ _context9.next = 51;
1093
+ break;
1094
+ }
1095
+ field = _step4.value;
1096
+ if (!(field.includes('trackedData') || field.includes('customFieldsData'))) {
1097
+ _context9.next = 48;
1098
+ break;
1099
+ }
1100
+ dbFieldName = field.includes('trackedData') ? 'trackedData' : 'customFieldsData';
1101
+ _iterator5 = _createForOfIteratorHelper(customer[dbFieldName] || []);
1102
+ _context9.prev = 24;
1103
+ _iterator5.s();
1104
+ case 26:
1105
+ if ((_step5 = _iterator5.n()).done) {
1106
+ _context9.next = 39;
1107
+ break;
1108
+ }
1109
+ customFieldsDataItem = _step5.value;
1110
+ if (!customerFileFieldsById[customFieldsDataItem.field]) {
1111
+ _context9.next = 34;
1112
+ break;
1113
+ }
1114
+ _context9.next = 31;
1115
+ return this.customFieldsDataItemToFileLink(customFieldsDataItem);
1116
+ case 31:
1117
+ _context9.t0 = _context9.sent;
1118
+ _context9.next = 35;
1119
+ break;
1120
+ case 34:
1121
+ _context9.t0 = customFieldsDataItem.stringValue || customFieldsDataItem.value || '';
1122
+ case 35:
1123
+ replaceValue = _context9.t0;
1124
+ replacers.push({
1125
+ key: "{{ customer.".concat(dbFieldName, ".").concat(customFieldsDataItem.field, " }}"),
1126
+ value: replaceValue
1127
+ });
1128
+ case 37:
1129
+ _context9.next = 26;
1130
+ break;
1131
+ case 39:
1132
+ _context9.next = 44;
1133
+ break;
1134
+ case 41:
1135
+ _context9.prev = 41;
1136
+ _context9.t1 = _context9["catch"](24);
1137
+ _iterator5.e(_context9.t1);
1138
+ case 44:
1139
+ _context9.prev = 44;
1140
+ _iterator5.f();
1141
+ return _context9.finish(44);
1142
+ case 47:
1143
+ return _context9.abrupt("continue", 49);
1144
+ case 48:
1145
+ replacers.push({
1146
+ key: "{{ customer.".concat(field, " }}"),
1147
+ value: customer[field] || ''
1148
+ });
1149
+ case 49:
1150
+ _context9.next = 19;
1151
+ break;
1152
+ case 51:
1153
+ _context9.next = 56;
1154
+ break;
1155
+ case 53:
1156
+ _context9.prev = 53;
1157
+ _context9.t2 = _context9["catch"](17);
1158
+ _iterator4.e(_context9.t2);
1159
+ case 56:
1160
+ _context9.prev = 56;
1161
+ _iterator4.f();
1162
+ return _context9.finish(56);
1163
+ case 59:
1164
+ // replace user fields
1165
+ if (user) {
1166
+ replacers.push({
1167
+ key: '{{ user.email }}',
1168
+ value: user.email || ''
1169
+ });
1170
+ if (user.details) {
1171
+ replacers.push({
1172
+ key: '{{ user.fullName }}',
1173
+ value: user.details.fullName || ''
1174
+ }, {
1175
+ key: '{{ user.position }}',
1176
+ value: user.details.position || ''
1177
+ });
1178
+ }
1179
+ }
1180
+
1181
+ // replace brand fields
1182
+ if (brand) {
1183
+ replacers.push({
1184
+ key: '{{ brandName }}',
1185
+ value: brand.name || ''
1186
+ });
1187
+ }
1188
+
1189
+ // deal, ticket, task mapping
1190
+ if (!item) {
1191
+ _context9.next = 91;
1192
+ break;
1193
+ }
1194
+ replacers.push({
1195
+ key: '{{ itemName }}',
1196
+ value: item.name || ''
1197
+ }, {
1198
+ key: '{{ itemDescription }}',
1199
+ value: item.description || ''
1200
+ }, {
1201
+ key: '{{ itemCloseDate }}',
1202
+ value: item.closeDate ? new Date(item.closeDate).toLocaleDateString() : ''
1203
+ }, {
1204
+ key: '{{ itemCreatedAt }}',
1205
+ value: item.createdAt ? new Date(item.createdAt).toLocaleDateString() : ''
1206
+ }, {
1207
+ key: '{{ itemModifiedAt }}',
1208
+ value: item.modifiedAt ? new Date(item.modifiedAt).toLocaleDateString() : ''
1209
+ });
1210
+ _context9.next = 65;
1211
+ return this.generateProducts(item.productsData);
1212
+ case 65:
1213
+ products = _context9.sent;
1214
+ _context9.next = 68;
1215
+ return this.generateAmounts(item.productsData);
1216
+ case 68:
1217
+ amounts = _context9.sent;
1218
+ replacers.push({
1219
+ key: '{{ dealProducts }}',
1220
+ value: products.map(function (p) {
1221
+ return p.product.name;
1222
+ }).join(',')
1223
+ }, {
1224
+ key: '{{ dealAmounts }}',
1225
+ value: Object.keys(amounts).map(function (key) {
1226
+ return "".concat(amounts[key]).concat(key);
1227
+ }).join(',')
1228
+ });
1229
+ _context9.next = 72;
1230
+ return sendTRPCMessage({
1231
+ subdomain: this.subdomain,
1232
+ pluginName: 'core',
1233
+ method: 'query',
1234
+ module: 'fields',
1235
+ action: 'find',
1236
+ input: {
1237
+ query: {
1238
+ contentType: item.contentType,
1239
+ isDefinedByErxes: false
1240
+ }
1241
+ }
1242
+ });
1243
+ case 72:
1244
+ fieldMetaDatas = _context9.sent;
1245
+ _iterator6 = _createForOfIteratorHelper(fieldMetaDatas);
1246
+ _context9.prev = 74;
1247
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1248
+ var fieldMetaData, customFieldsData, customFieldsDataItem, key, replaceValue;
1249
+ return _regeneratorRuntime().wrap(function _loop$(_context8) {
1250
+ while (1) switch (_context8.prev = _context8.next) {
1251
+ case 0:
1252
+ fieldMetaData = _step6.value;
1253
+ customFieldsData = item.customFieldsData || [];
1254
+ customFieldsDataItem = customFieldsData.find(function (c) {
1255
+ return c.field === fieldMetaData._id;
1256
+ });
1257
+ key = "{{ itemCustomField.".concat(fieldMetaData._id, " }}");
1258
+ if (customFieldsDataItem) {
1259
+ _context8.next = 7;
1260
+ break;
1261
+ }
1262
+ if (content.includes(key)) {
1263
+ replacers.push({
1264
+ key: key,
1265
+ value: ''
1266
+ });
1267
+ }
1268
+ return _context8.abrupt("return", 1);
1269
+ case 7:
1270
+ if (!(fieldMetaData.type === 'file')) {
1271
+ _context8.next = 13;
1272
+ break;
1273
+ }
1274
+ _context8.next = 10;
1275
+ return _this2.customFieldsDataItemToFileLink(customFieldsDataItem);
1276
+ case 10:
1277
+ _context8.t0 = _context8.sent;
1278
+ _context8.next = 14;
1279
+ break;
1280
+ case 13:
1281
+ _context8.t0 = customFieldsDataItem.stringValue || customFieldsDataItem.value || '';
1282
+ case 14:
1283
+ replaceValue = _context8.t0;
1284
+ replacers.push({
1285
+ key: key,
1286
+ value: replaceValue
1287
+ });
1288
+ case 16:
1289
+ case "end":
1290
+ return _context8.stop();
1291
+ }
1292
+ }, _loop);
1293
+ });
1294
+ _iterator6.s();
1295
+ case 77:
1296
+ if ((_step6 = _iterator6.n()).done) {
1297
+ _context9.next = 83;
1298
+ break;
1299
+ }
1300
+ return _context9.delegateYield(_loop(), "t3", 79);
1301
+ case 79:
1302
+ if (!_context9.t3) {
1303
+ _context9.next = 81;
1304
+ break;
1305
+ }
1306
+ return _context9.abrupt("continue", 81);
1307
+ case 81:
1308
+ _context9.next = 77;
1309
+ break;
1310
+ case 83:
1311
+ _context9.next = 88;
1312
+ break;
1313
+ case 85:
1314
+ _context9.prev = 85;
1315
+ _context9.t4 = _context9["catch"](74);
1316
+ _iterator6.e(_context9.t4);
1317
+ case 88:
1318
+ _context9.prev = 88;
1319
+ _iterator6.f();
1320
+ return _context9.finish(88);
1321
+ case 91:
1322
+ return _context9.abrupt("return", replacers);
1323
+ case 92:
1324
+ case "end":
1325
+ return _context9.stop();
1326
+ }
1327
+ }, _callee8, this, [[17, 53, 56, 59], [24, 41, 44, 47], [74, 85, 88, 91]]);
1328
+ }));
1329
+ function generateReplacers(_x9) {
1330
+ return _generateReplacers.apply(this, arguments);
1331
+ }
1332
+ return generateReplacers;
1333
+ }()
1334
+ }, {
1335
+ key: "replaceAttributes",
1336
+ value: function () {
1337
+ var _replaceAttributes = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(args) {
1338
+ var replacers, replacedContent;
1339
+ return _regeneratorRuntime().wrap(function _callee9$(_context0) {
1340
+ while (1) switch (_context0.prev = _context0.next) {
1341
+ case 0:
1342
+ _context0.next = 2;
1343
+ return this.generateReplacers(args);
1344
+ case 2:
1345
+ replacers = _context0.sent;
1346
+ replacedContent = runReplacersOn(args.content, replacers);
1347
+ return _context0.abrupt("return", replacedContent);
1348
+ case 5:
1349
+ case "end":
1350
+ return _context0.stop();
1351
+ }
1352
+ }, _callee9, this);
1353
+ }));
1354
+ function replaceAttributes(_x0) {
1355
+ return _replaceAttributes.apply(this, arguments);
1356
+ }
1357
+ return replaceAttributes;
1358
+ }()
1359
+ }]);
1360
+ }();
1361
+
1362
+ var normalizeEmail = function normalizeEmail(email) {
1363
+ return email.trim().toLowerCase();
1364
+ };
1365
+ var parseAddress = function parseAddress(value) {
1366
+ var match = /^\s*(.*?)\s*<([^>]+)>\s*$/.exec(value || '');
1367
+ return match ? {
1368
+ name: match[1].replace(/^"|"$/g, ''),
1369
+ address: match[2].trim()
1370
+ } : {
1371
+ name: '',
1372
+ address: (value || '').trim()
1373
+ };
1374
+ };
1375
+ var SPECIALS = /[()<>@,;:\\".[\]]/;
1376
+ var quoteName = function quoteName(name) {
1377
+ var clean = name.replace(/[\r\n]/g, ' ').trim();
1378
+ if (!clean) {
1379
+ return '';
1380
+ }
1381
+ return SPECIALS.test(clean) ? "\"".concat(clean.replace(/(["\\])/g, '\\$1'), "\"") : clean;
1382
+ };
1383
+ var alignSender = function alignSender(requested, replyTo, alignedFrom) {
1384
+ var reply = (replyTo === null || replyTo === void 0 ? void 0 : replyTo.trim()) || undefined;
1385
+ if (!alignedFrom) {
1386
+ return {
1387
+ from: requested,
1388
+ replyTo: reply
1389
+ };
1390
+ }
1391
+ var _parseAddress = parseAddress(requested),
1392
+ name = _parseAddress.name,
1393
+ address = _parseAddress.address;
1394
+ return {
1395
+ from: "".concat(quoteName(name) || address, " <").concat(alignedFrom, ">"),
1396
+ replyTo: reply || (address === alignedFrom ? undefined : address)
1397
+ };
1398
+ };
1399
+
1400
+ var DOWNLOAD_TIMEOUT_MS = 15000;
1401
+ var MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024;
1402
+ var toBase64Attachment = /*#__PURE__*/function () {
1403
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(attachment) {
1404
+ var controller, timer, response, declaredSize, buffer;
1405
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1406
+ while (1) switch (_context.prev = _context.next) {
1407
+ case 0:
1408
+ if (!attachment.content) {
1409
+ _context.next = 2;
1410
+ break;
1411
+ }
1412
+ return _context.abrupt("return", {
1413
+ filename: attachment.filename,
1414
+ content: attachment.content,
1415
+ type: attachment.contentType
1416
+ });
1417
+ case 2:
1418
+ if (attachment.path) {
1419
+ _context.next = 4;
1420
+ break;
1421
+ }
1422
+ throw new Error("Attachment \"".concat(attachment.filename, "\" has neither \"content\" nor \"path\""));
1423
+ case 4:
1424
+ controller = new AbortController();
1425
+ timer = setTimeout(function () {
1426
+ return controller.abort();
1427
+ }, DOWNLOAD_TIMEOUT_MS);
1428
+ _context.prev = 6;
1429
+ _context.next = 9;
1430
+ return fetch(attachment.path, {
1431
+ signal: controller.signal
1432
+ });
1433
+ case 9:
1434
+ response = _context.sent;
1435
+ case 10:
1436
+ _context.prev = 10;
1437
+ clearTimeout(timer);
1438
+ return _context.finish(10);
1439
+ case 13:
1440
+ if (response.ok) {
1441
+ _context.next = 15;
1442
+ break;
1443
+ }
1444
+ throw new Error("Failed to download attachment \"".concat(attachment.filename, "\" from ").concat(attachment.path, ": ").concat(response.status));
1445
+ case 15:
1446
+ declaredSize = Number(response.headers.get('content-length'));
1447
+ if (!(declaredSize && declaredSize > MAX_ATTACHMENT_BYTES)) {
1448
+ _context.next = 18;
1449
+ break;
1450
+ }
1451
+ throw new Error("Attachment \"".concat(attachment.filename, "\" exceeds the ").concat(MAX_ATTACHMENT_BYTES / (1024 * 1024), "MB limit"));
1452
+ case 18:
1453
+ _context.next = 20;
1454
+ return response.buffer();
1455
+ case 20:
1456
+ buffer = _context.sent;
1457
+ if (!(buffer.byteLength > MAX_ATTACHMENT_BYTES)) {
1458
+ _context.next = 23;
1459
+ break;
1460
+ }
1461
+ throw new Error("Attachment \"".concat(attachment.filename, "\" exceeds the ").concat(MAX_ATTACHMENT_BYTES / (1024 * 1024), "MB limit"));
1462
+ case 23:
1463
+ return _context.abrupt("return", {
1464
+ filename: attachment.filename,
1465
+ content: buffer.toString('base64'),
1466
+ type: attachment.contentType || response.headers.get('content-type') || undefined
1467
+ });
1468
+ case 24:
1469
+ case "end":
1470
+ return _context.stop();
1471
+ }
1472
+ }, _callee, null, [[6,, 10, 13]]);
1473
+ }));
1474
+ return function toBase64Attachment(_x) {
1475
+ return _ref.apply(this, arguments);
1476
+ };
1477
+ }();
1478
+ var toBase64Attachments = /*#__PURE__*/function () {
1479
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1480
+ var attachments,
1481
+ _args2 = arguments;
1482
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1483
+ while (1) switch (_context2.prev = _context2.next) {
1484
+ case 0:
1485
+ attachments = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : [];
1486
+ return _context2.abrupt("return", Promise.all(attachments.map(toBase64Attachment)));
1487
+ case 2:
1488
+ case "end":
1489
+ return _context2.stop();
1490
+ }
1491
+ }, _callee2);
1492
+ }));
1493
+ return function toBase64Attachments() {
1494
+ return _ref2.apply(this, arguments);
1495
+ };
1496
+ }();
1497
+
1498
+ var EMAIL_PROVIDER_CONFIG_CODES = ['DEFAULT_EMAIL_SERVICE', 'AWS_SES_ACCESS_KEY_ID', 'AWS_SES_SECRET_ACCESS_KEY', 'AWS_REGION', 'AWS_SES_CONFIG_SET', 'SENDGRID_API_KEY', 'SENDGRID_SUBUSER', 'MAIL_SERVICE', 'MAIL_HOST', 'MAIL_PORT', 'MAIL_USER', 'MAIL_PASS'];
1499
+ var DEFAULT_EMAIL_PROVIDER = 'SES';
1500
+ var SENDGRID_API_BASE_URL = 'https://api.sendgrid.com/v3';
1501
+ var SES_DKIM_CNAME_SUFFIX = 'dkim.amazonses.com';
1502
+
1503
+ var loadEmailProviderConfig = /*#__PURE__*/function () {
1504
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(read) {
1505
+ var values;
1506
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1507
+ while (1) switch (_context.prev = _context.next) {
1508
+ case 0:
1509
+ _context.next = 2;
1510
+ return Promise.all(EMAIL_PROVIDER_CONFIG_CODES.map(function (code) {
1511
+ return read(code, '');
1512
+ }));
1513
+ case 2:
1514
+ values = _context.sent;
1515
+ return _context.abrupt("return", EMAIL_PROVIDER_CONFIG_CODES.reduce(function (config, code, index) {
1516
+ var value = values[index];
1517
+ if (value) {
1518
+ config[code] = value;
1519
+ }
1520
+ return config;
1521
+ }, {}));
1522
+ case 4:
1523
+ case "end":
1524
+ return _context.stop();
1525
+ }
1526
+ }, _callee);
1527
+ }));
1528
+ return function loadEmailProviderConfig(_x) {
1529
+ return _ref.apply(this, arguments);
1530
+ };
1531
+ }();
1532
+ var resolveDefaultSenderEmail = function resolveDefaultSenderEmail(_ref2) {
1533
+ var isSaas = _ref2.isSaas,
1534
+ companyEmailFrom = _ref2.companyEmailFrom,
1535
+ fallbackEmail = _ref2.fallbackEmail;
1536
+ return (isSaas ? fallbackEmail : companyEmailFrom || fallbackEmail) || '';
1537
+ };
1538
+ var getEmailProviderConfigFingerprint = function getEmailProviderConfigFingerprint(config) {
1539
+ return EMAIL_PROVIDER_CONFIG_CODES.map(function (code) {
1540
+ var _config$code;
1541
+ return "".concat(code, "=").concat((_config$code = config[code]) !== null && _config$code !== void 0 ? _config$code : '');
1542
+ }).join('|');
1543
+ };
1544
+
1545
+ var EmailProviderNotSupportedError = /*#__PURE__*/function (_Error) {
1546
+ function EmailProviderNotSupportedError(provider, operation) {
1547
+ var _this;
1548
+ _classCallCheck(this, EmailProviderNotSupportedError);
1549
+ _this = _callSuper(this, EmailProviderNotSupportedError, ["\"".concat(operation, "\" is not supported by the \"").concat(provider, "\" email provider")]);
1550
+ _this.name = 'EmailProviderNotSupportedError';
1551
+ return _this;
1552
+ }
1553
+ _inherits(EmailProviderNotSupportedError, _Error);
1554
+ return _createClass(EmailProviderNotSupportedError);
1555
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1556
+ var EmailProviderConfigError = /*#__PURE__*/function (_Error2) {
1557
+ function EmailProviderConfigError(provider, missing) {
1558
+ var _this2;
1559
+ _classCallCheck(this, EmailProviderConfigError);
1560
+ _this2 = _callSuper(this, EmailProviderConfigError, ["\"".concat(provider, "\" email provider is missing configuration: ").concat(missing.join(', '))]);
1561
+ _this2.name = 'EmailProviderConfigError';
1562
+ return _this2;
1563
+ }
1564
+ _inherits(EmailProviderConfigError, _Error2);
1565
+ return _createClass(EmailProviderConfigError);
1566
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1567
+ var EmailProviderRequestError = /*#__PURE__*/function (_Error3) {
1568
+ function EmailProviderRequestError(provider, status, body) {
1569
+ var _this3;
1570
+ _classCallCheck(this, EmailProviderRequestError);
1571
+ _this3 = _callSuper(this, EmailProviderRequestError, ["\"".concat(provider, "\" API request failed with status ").concat(status, ": ").concat(body)]);
1572
+ _this3.name = 'EmailProviderRequestError';
1573
+ _this3.status = status;
1574
+ _this3.body = body;
1575
+ return _this3;
1576
+ }
1577
+ _inherits(EmailProviderRequestError, _Error3);
1578
+ return _createClass(EmailProviderRequestError);
1579
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
1580
+
1581
+ var REQUEST_TIMEOUT_MS = 15000;
1582
+ var toDnsRecords = function toDnsRecords(dns) {
1583
+ return Object.values(dns || {}).map(function (entry) {
1584
+ return {
1585
+ type: entry.type.toUpperCase(),
1586
+ host: entry.host,
1587
+ data: entry.data,
1588
+ valid: entry.valid
1589
+ };
1590
+ });
1591
+ };
1592
+ var toSingleSender = function toSingleSender(sender) {
1593
+ return {
1594
+ id: String(sender.id),
1595
+ type: 'single',
1596
+ value: sender.from_email,
1597
+ name: sender.from_name || sender.nickname,
1598
+ status: sender.verified ? 'verified' : 'pending'
1599
+ };
1600
+ };
1601
+ var toDomainSender = function toDomainSender(domain) {
1602
+ return {
1603
+ id: String(domain.id),
1604
+ type: 'domain',
1605
+ value: domain.domain,
1606
+ status: domain.valid ? 'verified' : 'pending',
1607
+ dnsRecords: toDnsRecords(domain.dns)
1608
+ };
1609
+ };
1610
+ var toSendError = function toSendError(error) {
1611
+ var response = error === null || error === void 0 ? void 0 : error.response;
1612
+ if (!response) {
1613
+ return error;
1614
+ }
1615
+ return new EmailProviderRequestError('sendgrid', response.statusCode || 0, typeof response.body === 'string' ? response.body : JSON.stringify(response.body));
1616
+ };
1617
+ var SendgridEmailProvider = /*#__PURE__*/function () {
1618
+ function SendgridEmailProvider(config) {
1619
+ _classCallCheck(this, SendgridEmailProvider);
1620
+ _defineProperty(this, "name", 'sendgrid');
1621
+ if (!config.SENDGRID_API_KEY) {
1622
+ throw new EmailProviderConfigError('sendgrid', ['SENDGRID_API_KEY']);
1623
+ }
1624
+ this.apiKey = config.SENDGRID_API_KEY;
1625
+ this.subuser = config.SENDGRID_SUBUSER;
1626
+ var _require = require('@sendgrid/mail'),
1627
+ MailService = _require.MailService;
1628
+ var mailer = new MailService();
1629
+ mailer.setApiKey(this.apiKey);
1630
+ this.mailer = mailer;
1631
+ }
1632
+ return _createClass(SendgridEmailProvider, [{
1633
+ key: "send",
1634
+ value: function () {
1635
+ var _send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(message) {
1636
+ var _message$attachments, _message$cc, _message$bcc, _response, _response2;
1637
+ var attachments, payload, response, _yield$this$mailer$se, _yield$this$mailer$se2, messageId;
1638
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1639
+ while (1) switch (_context.prev = _context.next) {
1640
+ case 0:
1641
+ if (!((_message$attachments = message.attachments) !== null && _message$attachments !== void 0 && _message$attachments.length)) {
1642
+ _context.next = 6;
1643
+ break;
1644
+ }
1645
+ _context.next = 3;
1646
+ return toBase64Attachments(message.attachments);
1647
+ case 3:
1648
+ _context.t0 = _context.sent;
1649
+ _context.next = 7;
1650
+ break;
1651
+ case 6:
1652
+ _context.t0 = undefined;
1653
+ case 7:
1654
+ attachments = _context.t0;
1655
+ payload = {
1656
+ from: message.from,
1657
+ to: message.to,
1658
+ cc: (_message$cc = message.cc) !== null && _message$cc !== void 0 && _message$cc.length ? message.cc : undefined,
1659
+ bcc: (_message$bcc = message.bcc) !== null && _message$bcc !== void 0 && _message$bcc.length ? message.bcc : undefined,
1660
+ replyTo: message.replyTo,
1661
+ subject: message.subject,
1662
+ html: message.html,
1663
+ text: message.text,
1664
+ attachments: attachments,
1665
+ headers: message.headers,
1666
+ customArgs: message.customArgs
1667
+ };
1668
+ _context.prev = 9;
1669
+ _context.next = 12;
1670
+ return this.mailer.send(payload);
1671
+ case 12:
1672
+ _yield$this$mailer$se = _context.sent;
1673
+ _yield$this$mailer$se2 = _slicedToArray(_yield$this$mailer$se, 1);
1674
+ response = _yield$this$mailer$se2[0];
1675
+ _context.next = 20;
1676
+ break;
1677
+ case 17:
1678
+ _context.prev = 17;
1679
+ _context.t1 = _context["catch"](9);
1680
+ throw toSendError(_context.t1);
1681
+ case 20:
1682
+ messageId = ((_response = response) === null || _response === void 0 || (_response = _response.headers) === null || _response === void 0 ? void 0 : _response['x-message-id']) || ((_response2 = response) === null || _response2 === void 0 || (_response2 = _response2.headers) === null || _response2 === void 0 ? void 0 : _response2['X-Message-Id']) || '';
1683
+ return _context.abrupt("return", {
1684
+ messageId: String(messageId),
1685
+ provider: this.name,
1686
+ accepted: message.to,
1687
+ rejected: []
1688
+ });
1689
+ case 22:
1690
+ case "end":
1691
+ return _context.stop();
1692
+ }
1693
+ }, _callee, this, [[9, 17]]);
1694
+ }));
1695
+ function send(_x) {
1696
+ return _send.apply(this, arguments);
1697
+ }
1698
+ return send;
1699
+ }()
1700
+ }, {
1701
+ key: "listSingleSenders",
1702
+ value: function () {
1703
+ var _listSingleSenders = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ids) {
1704
+ var _this = this;
1705
+ var paths, pages;
1706
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1707
+ while (1) switch (_context2.prev = _context2.next) {
1708
+ case 0:
1709
+ paths = ids !== null && ids !== void 0 && ids.length ? ids.map(function (id) {
1710
+ return "/verified_senders?id=".concat(encodeURIComponent(id));
1711
+ }) : ['/verified_senders'];
1712
+ _context2.next = 3;
1713
+ return Promise.all(paths.map(function (path) {
1714
+ return _this.request('GET', path);
1715
+ }));
1716
+ case 3:
1717
+ pages = _context2.sent;
1718
+ return _context2.abrupt("return", pages.flatMap(function (page) {
1719
+ return ((page === null || page === void 0 ? void 0 : page.results) || []).map(toSingleSender);
1720
+ }));
1721
+ case 5:
1722
+ case "end":
1723
+ return _context2.stop();
1724
+ }
1725
+ }, _callee2);
1726
+ }));
1727
+ function listSingleSenders(_x2) {
1728
+ return _listSingleSenders.apply(this, arguments);
1729
+ }
1730
+ return listSingleSenders;
1731
+ }()
1732
+ }, {
1733
+ key: "listAuthenticatedDomains",
1734
+ value: function () {
1735
+ var _listAuthenticatedDomains = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(domains) {
1736
+ var _this2 = this;
1737
+ var paths, pages;
1738
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1739
+ while (1) switch (_context3.prev = _context3.next) {
1740
+ case 0:
1741
+ paths = domains !== null && domains !== void 0 && domains.length ? domains.map(function (domain) {
1742
+ return "/whitelabel/domains?domain=".concat(encodeURIComponent(domain));
1743
+ }) : ['/whitelabel/domains'];
1744
+ _context3.next = 3;
1745
+ return Promise.all(paths.map(function (path) {
1746
+ return _this2.request('GET', path);
1747
+ }));
1748
+ case 3:
1749
+ pages = _context3.sent;
1750
+ return _context3.abrupt("return", pages.flatMap(function (page) {
1751
+ return (page || []).map(toDomainSender);
1752
+ }));
1753
+ case 5:
1754
+ case "end":
1755
+ return _context3.stop();
1756
+ }
1757
+ }, _callee3);
1758
+ }));
1759
+ function listAuthenticatedDomains(_x3) {
1760
+ return _listAuthenticatedDomains.apply(this, arguments);
1761
+ }
1762
+ return listAuthenticatedDomains;
1763
+ }()
1764
+ }, {
1765
+ key: "verifySingleSender",
1766
+ value: function () {
1767
+ var _verifySingleSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(input) {
1768
+ var created;
1769
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1770
+ while (1) switch (_context4.prev = _context4.next) {
1771
+ case 0:
1772
+ _context4.next = 2;
1773
+ return this.request('POST', '/verified_senders', {
1774
+ nickname: input.name || input.email,
1775
+ from_email: input.email,
1776
+ from_name: input.name || input.email,
1777
+ reply_to: input.replyTo || input.email,
1778
+ address: input.address || '',
1779
+ city: input.city || '',
1780
+ country: input.country || ''
1781
+ });
1782
+ case 2:
1783
+ created = _context4.sent;
1784
+ return _context4.abrupt("return", {
1785
+ id: String(created.id),
1786
+ type: 'single',
1787
+ value: created.from_email,
1788
+ name: created.from_name,
1789
+ status: created.verified ? 'verified' : 'pending'
1790
+ });
1791
+ case 4:
1792
+ case "end":
1793
+ return _context4.stop();
1794
+ }
1795
+ }, _callee4, this);
1796
+ }));
1797
+ function verifySingleSender(_x4) {
1798
+ return _verifySingleSender.apply(this, arguments);
1799
+ }
1800
+ return verifySingleSender;
1801
+ }()
1802
+ }, {
1803
+ key: "removeSender",
1804
+ value: function () {
1805
+ var _removeSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
1806
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1807
+ while (1) switch (_context5.prev = _context5.next) {
1808
+ case 0:
1809
+ _context5.next = 2;
1810
+ return this.request('DELETE', "/verified_senders/".concat(encodeURIComponent(id)));
1811
+ case 2:
1812
+ case "end":
1813
+ return _context5.stop();
1814
+ }
1815
+ }, _callee5, this);
1816
+ }));
1817
+ function removeSender(_x5) {
1818
+ return _removeSender.apply(this, arguments);
1819
+ }
1820
+ return removeSender;
1821
+ }()
1822
+ }, {
1823
+ key: "authenticateDomain",
1824
+ value: function () {
1825
+ var _authenticateDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(domain) {
1826
+ var created;
1827
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1828
+ while (1) switch (_context6.prev = _context6.next) {
1829
+ case 0:
1830
+ _context6.next = 2;
1831
+ return this.request('POST', '/whitelabel/domains', {
1832
+ domain: domain,
1833
+ automatic_security: true
1834
+ });
1835
+ case 2:
1836
+ created = _context6.sent;
1837
+ return _context6.abrupt("return", toDomainSender(created));
1838
+ case 4:
1839
+ case "end":
1840
+ return _context6.stop();
1841
+ }
1842
+ }, _callee6, this);
1843
+ }));
1844
+ function authenticateDomain(_x6) {
1845
+ return _authenticateDomain.apply(this, arguments);
1846
+ }
1847
+ return authenticateDomain;
1848
+ }()
1849
+ }, {
1850
+ key: "validateDomain",
1851
+ value: function () {
1852
+ var _validateDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
1853
+ var encodedId, domain;
1854
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1855
+ while (1) switch (_context7.prev = _context7.next) {
1856
+ case 0:
1857
+ encodedId = encodeURIComponent(id);
1858
+ _context7.next = 3;
1859
+ return this.request('POST', "/whitelabel/domains/".concat(encodedId, "/validate"));
1860
+ case 3:
1861
+ _context7.next = 5;
1862
+ return this.request('GET', "/whitelabel/domains/".concat(encodedId));
1863
+ case 5:
1864
+ domain = _context7.sent;
1865
+ return _context7.abrupt("return", toDomainSender(domain));
1866
+ case 7:
1867
+ case "end":
1868
+ return _context7.stop();
1869
+ }
1870
+ }, _callee7, this);
1871
+ }));
1872
+ function validateDomain(_x7) {
1873
+ return _validateDomain.apply(this, arguments);
1874
+ }
1875
+ return validateDomain;
1876
+ }()
1877
+ }, {
1878
+ key: "request",
1879
+ value: function () {
1880
+ var _request = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(method, path, body) {
1881
+ var headers, controller, timer, response, text;
1882
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1883
+ while (1) switch (_context8.prev = _context8.next) {
1884
+ case 0:
1885
+ headers = {
1886
+ Authorization: "Bearer ".concat(this.apiKey),
1887
+ 'Content-Type': 'application/json'
1888
+ };
1889
+ if (this.subuser) {
1890
+ headers['on-behalf-of'] = this.subuser;
1891
+ }
1892
+ controller = new AbortController();
1893
+ timer = setTimeout(function () {
1894
+ return controller.abort();
1895
+ }, REQUEST_TIMEOUT_MS);
1896
+ _context8.prev = 4;
1897
+ _context8.next = 7;
1898
+ return fetch("".concat(SENDGRID_API_BASE_URL).concat(path), {
1899
+ method: method,
1900
+ headers: headers,
1901
+ body: body === undefined ? undefined : JSON.stringify(body),
1902
+ signal: controller.signal
1903
+ });
1904
+ case 7:
1905
+ response = _context8.sent;
1906
+ case 8:
1907
+ _context8.prev = 8;
1908
+ clearTimeout(timer);
1909
+ return _context8.finish(8);
1910
+ case 11:
1911
+ if (response.ok) {
1912
+ _context8.next = 18;
1913
+ break;
1914
+ }
1915
+ _context8.t0 = EmailProviderRequestError;
1916
+ _context8.t1 = response.status;
1917
+ _context8.next = 16;
1918
+ return response.text();
1919
+ case 16:
1920
+ _context8.t2 = _context8.sent;
1921
+ throw new _context8.t0('sendgrid', _context8.t1, _context8.t2);
1922
+ case 18:
1923
+ if (!(response.status === 204)) {
1924
+ _context8.next = 20;
1925
+ break;
1926
+ }
1927
+ return _context8.abrupt("return", undefined);
1928
+ case 20:
1929
+ _context8.next = 22;
1930
+ return response.text();
1931
+ case 22:
1932
+ text = _context8.sent;
1933
+ if (text) {
1934
+ _context8.next = 25;
1935
+ break;
1936
+ }
1937
+ return _context8.abrupt("return", undefined);
1938
+ case 25:
1939
+ return _context8.abrupt("return", JSON.parse(text));
1940
+ case 26:
1941
+ case "end":
1942
+ return _context8.stop();
1943
+ }
1944
+ }, _callee8, this, [[4,, 8, 11]]);
1945
+ }));
1946
+ function request(_x8, _x9, _x0) {
1947
+ return _request.apply(this, arguments);
1948
+ }
1949
+ return request;
1950
+ }()
1951
+ }]);
1952
+ }();
1953
+
1954
+ var SENDGRID_SIGNATURE_HEADER = 'x-twilio-email-event-webhook-signature';
1955
+ var SENDGRID_TIMESTAMP_HEADER = 'x-twilio-email-event-webhook-timestamp';
1956
+ var verifySendgridSignature = function verifySendgridSignature(_ref) {
1957
+ var publicKey = _ref.publicKey,
1958
+ signature = _ref.signature,
1959
+ timestamp = _ref.timestamp,
1960
+ payload = _ref.payload;
1961
+ if (!publicKey || !signature || !timestamp) {
1962
+ return false;
1963
+ }
1964
+ try {
1965
+ var key = crypto.createPublicKey({
1966
+ key: Buffer.from(publicKey, 'base64'),
1967
+ format: 'der',
1968
+ type: 'spki'
1969
+ });
1970
+ return crypto.createVerify('sha256').update(timestamp).update(payload).verify(key, signature, 'base64');
1971
+ } catch (_unused) {
1972
+ return false;
1973
+ }
1974
+ };
1975
+
1976
+ var toSenderStatus = function toSenderStatus(verificationStatus) {
1977
+ if (verificationStatus === 'Success') {
1978
+ return 'verified';
1979
+ }
1980
+ if (verificationStatus === 'Failed' || verificationStatus === 'TemporaryFailure') {
1981
+ return 'failed';
1982
+ }
1983
+ return 'pending';
1984
+ };
1985
+ var SesEmailProvider = /*#__PURE__*/function () {
1986
+ function SesEmailProvider(config) {
1987
+ _classCallCheck(this, SesEmailProvider);
1988
+ _defineProperty(this, "name", 'SES');
1989
+ var missing = [];
1990
+ if (!config.AWS_SES_ACCESS_KEY_ID) {
1991
+ missing.push('AWS_SES_ACCESS_KEY_ID');
1992
+ }
1993
+ if (!config.AWS_SES_SECRET_ACCESS_KEY) {
1994
+ missing.push('AWS_SES_SECRET_ACCESS_KEY');
1995
+ }
1996
+ if (!config.AWS_REGION) {
1997
+ missing.push('AWS_REGION');
1998
+ }
1999
+ if (missing.length) {
2000
+ throw new EmailProviderConfigError('SES', missing);
2001
+ }
2002
+ this.configSet = config.AWS_SES_CONFIG_SET;
2003
+ this.client = new AWS.SES({
2004
+ apiVersion: '2010-12-01',
2005
+ region: config.AWS_REGION,
2006
+ accessKeyId: config.AWS_SES_ACCESS_KEY_ID,
2007
+ secretAccessKey: config.AWS_SES_SECRET_ACCESS_KEY
2008
+ });
2009
+ this.transporter = nodemailer.createTransport({
2010
+ SES: this.client
2011
+ });
2012
+ }
2013
+ return _createClass(SesEmailProvider, [{
2014
+ key: "send",
2015
+ value: function () {
2016
+ var _send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(message) {
2017
+ var _message$cc, _message$bcc, _message$attachments;
2018
+ var headers, _i, _Object$entries, _Object$entries$_i, key, value, info;
2019
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2020
+ while (1) switch (_context.prev = _context.next) {
2021
+ case 0:
2022
+ headers = _objectSpread2(_objectSpread2({}, this.configSet ? {
2023
+ 'X-SES-CONFIGURATION-SET': this.configSet
2024
+ } : {}), message.headers || {});
2025
+ for (_i = 0, _Object$entries = Object.entries(message.customArgs || {}); _i < _Object$entries.length; _i++) {
2026
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1];
2027
+ headers[key] = value;
2028
+ }
2029
+ _context.next = 4;
2030
+ return this.transporter.sendMail({
2031
+ from: message.from,
2032
+ to: message.to.join(', '),
2033
+ cc: (_message$cc = message.cc) !== null && _message$cc !== void 0 && _message$cc.length ? message.cc.join(', ') : undefined,
2034
+ bcc: (_message$bcc = message.bcc) !== null && _message$bcc !== void 0 && _message$bcc.length ? message.bcc.join(', ') : undefined,
2035
+ replyTo: message.replyTo,
2036
+ subject: message.subject,
2037
+ html: message.html,
2038
+ text: message.text,
2039
+ attachments: (_message$attachments = message.attachments) === null || _message$attachments === void 0 ? void 0 : _message$attachments.map(function (attachment) {
2040
+ return {
2041
+ filename: attachment.filename,
2042
+ path: attachment.path,
2043
+ content: attachment.content ? Buffer.from(attachment.content, 'base64') : undefined,
2044
+ contentType: attachment.contentType
2045
+ };
2046
+ }),
2047
+ headers: headers
2048
+ });
2049
+ case 4:
2050
+ info = _context.sent;
2051
+ return _context.abrupt("return", {
2052
+ messageId: info.messageId,
2053
+ provider: this.name,
2054
+ accepted: (info.accepted || []).map(String),
2055
+ rejected: (info.rejected || []).map(String)
2056
+ });
2057
+ case 6:
2058
+ case "end":
2059
+ return _context.stop();
2060
+ }
2061
+ }, _callee, this);
2062
+ }));
2063
+ function send(_x) {
2064
+ return _send.apply(this, arguments);
2065
+ }
2066
+ return send;
2067
+ }()
2068
+ }, {
2069
+ key: "listSingleSenders",
2070
+ value: function () {
2071
+ var _listSingleSenders = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(ids) {
2072
+ var emails, statuses;
2073
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2074
+ while (1) switch (_context2.prev = _context2.next) {
2075
+ case 0:
2076
+ if (!(ids !== null && ids !== void 0)) {
2077
+ _context2.next = 4;
2078
+ break;
2079
+ }
2080
+ _context2.t0 = ids;
2081
+ _context2.next = 7;
2082
+ break;
2083
+ case 4:
2084
+ _context2.next = 6;
2085
+ return this.listAllIdentities('EmailAddress');
2086
+ case 6:
2087
+ _context2.t0 = _context2.sent;
2088
+ case 7:
2089
+ emails = _context2.t0;
2090
+ if (emails.length) {
2091
+ _context2.next = 10;
2092
+ break;
2093
+ }
2094
+ return _context2.abrupt("return", []);
2095
+ case 10:
2096
+ _context2.next = 12;
2097
+ return this.getVerificationStatuses(emails);
2098
+ case 12:
2099
+ statuses = _context2.sent;
2100
+ return _context2.abrupt("return", emails.map(function (email) {
2101
+ return {
2102
+ id: email,
2103
+ type: 'single',
2104
+ value: email,
2105
+ status: toSenderStatus(statuses[email])
2106
+ };
2107
+ }));
2108
+ case 14:
2109
+ case "end":
2110
+ return _context2.stop();
2111
+ }
2112
+ }, _callee2, this);
2113
+ }));
2114
+ function listSingleSenders(_x2) {
2115
+ return _listSingleSenders.apply(this, arguments);
2116
+ }
2117
+ return listSingleSenders;
2118
+ }()
2119
+ }, {
2120
+ key: "listAuthenticatedDomains",
2121
+ value: function () {
2122
+ var _listAuthenticatedDomains = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(domains) {
2123
+ var _this = this;
2124
+ var names;
2125
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2126
+ while (1) switch (_context3.prev = _context3.next) {
2127
+ case 0:
2128
+ if (!(domains !== null && domains !== void 0)) {
2129
+ _context3.next = 4;
2130
+ break;
2131
+ }
2132
+ _context3.t0 = domains;
2133
+ _context3.next = 7;
2134
+ break;
2135
+ case 4:
2136
+ _context3.next = 6;
2137
+ return this.listAllIdentities('Domain');
2138
+ case 6:
2139
+ _context3.t0 = _context3.sent;
2140
+ case 7:
2141
+ names = _context3.t0;
2142
+ return _context3.abrupt("return", Promise.all(names.map(function (domain) {
2143
+ return _this.getDomainSender(domain);
2144
+ })));
2145
+ case 9:
2146
+ case "end":
2147
+ return _context3.stop();
2148
+ }
2149
+ }, _callee3, this);
2150
+ }));
2151
+ function listAuthenticatedDomains(_x3) {
2152
+ return _listAuthenticatedDomains.apply(this, arguments);
2153
+ }
2154
+ return listAuthenticatedDomains;
2155
+ }()
2156
+ }, {
2157
+ key: "listAllIdentities",
2158
+ value: function () {
2159
+ var _listAllIdentities = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(identityType) {
2160
+ var identities, nextToken, _page$Identities, page;
2161
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2162
+ while (1) switch (_context4.prev = _context4.next) {
2163
+ case 0:
2164
+ identities = [];
2165
+ case 1:
2166
+ _context4.next = 3;
2167
+ return this.client.listIdentities({
2168
+ IdentityType: identityType,
2169
+ MaxItems: 100,
2170
+ NextToken: nextToken
2171
+ }).promise();
2172
+ case 3:
2173
+ page = _context4.sent;
2174
+ identities.push.apply(identities, _toConsumableArray((_page$Identities = page.Identities) !== null && _page$Identities !== void 0 ? _page$Identities : []));
2175
+ nextToken = page.NextToken;
2176
+ case 6:
2177
+ if (nextToken) {
2178
+ _context4.next = 1;
2179
+ break;
2180
+ }
2181
+ case 7:
2182
+ return _context4.abrupt("return", identities);
2183
+ case 8:
2184
+ case "end":
2185
+ return _context4.stop();
2186
+ }
2187
+ }, _callee4, this);
2188
+ }));
2189
+ function listAllIdentities(_x4) {
2190
+ return _listAllIdentities.apply(this, arguments);
2191
+ }
2192
+ return listAllIdentities;
2193
+ }()
2194
+ }, {
2195
+ key: "getVerificationStatuses",
2196
+ value: function () {
2197
+ var _getVerificationStatuses = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(identities) {
2198
+ var statuses, i, attributes, _i2, _Object$entries2, _attributes$Verificat, _Object$entries2$_i, identity, attribute;
2199
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2200
+ while (1) switch (_context5.prev = _context5.next) {
2201
+ case 0:
2202
+ statuses = {};
2203
+ i = 0;
2204
+ case 2:
2205
+ if (!(i < identities.length)) {
2206
+ _context5.next = 10;
2207
+ break;
2208
+ }
2209
+ _context5.next = 5;
2210
+ return this.client.getIdentityVerificationAttributes({
2211
+ Identities: identities.slice(i, i + 100)
2212
+ }).promise();
2213
+ case 5:
2214
+ attributes = _context5.sent;
2215
+ for (_i2 = 0, _Object$entries2 = Object.entries((_attributes$Verificat = attributes.VerificationAttributes) !== null && _attributes$Verificat !== void 0 ? _attributes$Verificat : {}); _i2 < _Object$entries2.length; _i2++) {
2216
+ _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), identity = _Object$entries2$_i[0], attribute = _Object$entries2$_i[1];
2217
+ statuses[identity] = attribute.VerificationStatus;
2218
+ }
2219
+ case 7:
2220
+ i += 100;
2221
+ _context5.next = 2;
2222
+ break;
2223
+ case 10:
2224
+ return _context5.abrupt("return", statuses);
2225
+ case 11:
2226
+ case "end":
2227
+ return _context5.stop();
2228
+ }
2229
+ }, _callee5, this);
2230
+ }));
2231
+ function getVerificationStatuses(_x5) {
2232
+ return _getVerificationStatuses.apply(this, arguments);
2233
+ }
2234
+ return getVerificationStatuses;
2235
+ }()
2236
+ }, {
2237
+ key: "verifySingleSender",
2238
+ value: function () {
2239
+ var _verifySingleSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(input) {
2240
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
2241
+ while (1) switch (_context6.prev = _context6.next) {
2242
+ case 0:
2243
+ _context6.next = 2;
2244
+ return this.client.verifyEmailAddress({
2245
+ EmailAddress: input.email
2246
+ }).promise();
2247
+ case 2:
2248
+ return _context6.abrupt("return", {
2249
+ id: input.email,
2250
+ type: 'single',
2251
+ value: input.email,
2252
+ name: input.name,
2253
+ status: 'pending'
2254
+ });
2255
+ case 3:
2256
+ case "end":
2257
+ return _context6.stop();
2258
+ }
2259
+ }, _callee6, this);
2260
+ }));
2261
+ function verifySingleSender(_x6) {
2262
+ return _verifySingleSender.apply(this, arguments);
2263
+ }
2264
+ return verifySingleSender;
2265
+ }()
2266
+ }, {
2267
+ key: "removeSender",
2268
+ value: function () {
2269
+ var _removeSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
2270
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
2271
+ while (1) switch (_context7.prev = _context7.next) {
2272
+ case 0:
2273
+ _context7.next = 2;
2274
+ return this.client.deleteIdentity({
2275
+ Identity: id
2276
+ }).promise();
2277
+ case 2:
2278
+ case "end":
2279
+ return _context7.stop();
2280
+ }
2281
+ }, _callee7, this);
2282
+ }));
2283
+ function removeSender(_x7) {
2284
+ return _removeSender.apply(this, arguments);
2285
+ }
2286
+ return removeSender;
2287
+ }()
2288
+ }, {
2289
+ key: "authenticateDomain",
2290
+ value: function () {
2291
+ var _authenticateDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(domain) {
2292
+ var dkim, dnsRecords;
2293
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
2294
+ while (1) switch (_context8.prev = _context8.next) {
2295
+ case 0:
2296
+ _context8.next = 2;
2297
+ return this.client.verifyDomainIdentity({
2298
+ Domain: domain
2299
+ }).promise();
2300
+ case 2:
2301
+ _context8.next = 4;
2302
+ return this.client.verifyDomainDkim({
2303
+ Domain: domain
2304
+ }).promise();
2305
+ case 4:
2306
+ dkim = _context8.sent;
2307
+ dnsRecords = (dkim.DkimTokens || []).map(function (token) {
2308
+ return {
2309
+ type: 'CNAME',
2310
+ host: "".concat(token, "._domainkey.").concat(domain),
2311
+ data: "".concat(token, ".").concat(SES_DKIM_CNAME_SUFFIX),
2312
+ valid: false
2313
+ };
2314
+ });
2315
+ return _context8.abrupt("return", {
2316
+ id: domain,
2317
+ type: 'domain',
2318
+ value: domain,
2319
+ status: 'pending',
2320
+ dnsRecords: dnsRecords
2321
+ });
2322
+ case 7:
2323
+ case "end":
2324
+ return _context8.stop();
2325
+ }
2326
+ }, _callee8, this);
2327
+ }));
2328
+ function authenticateDomain(_x8) {
2329
+ return _authenticateDomain.apply(this, arguments);
2330
+ }
2331
+ return authenticateDomain;
2332
+ }()
2333
+ }, {
2334
+ key: "validateDomain",
2335
+ value: function () {
2336
+ var _validateDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(id) {
2337
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
2338
+ while (1) switch (_context9.prev = _context9.next) {
2339
+ case 0:
2340
+ return _context9.abrupt("return", this.getDomainSender(id));
2341
+ case 1:
2342
+ case "end":
2343
+ return _context9.stop();
2344
+ }
2345
+ }, _callee9, this);
2346
+ }));
2347
+ function validateDomain(_x9) {
2348
+ return _validateDomain.apply(this, arguments);
2349
+ }
2350
+ return validateDomain;
2351
+ }()
2352
+ }, {
2353
+ key: "getDomainSender",
2354
+ value: function () {
2355
+ var _getDomainSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee0(domain) {
2356
+ var _dkim$DkimAttributes;
2357
+ var dkim, attributes, dnsRecords;
2358
+ return _regeneratorRuntime().wrap(function _callee0$(_context0) {
2359
+ while (1) switch (_context0.prev = _context0.next) {
2360
+ case 0:
2361
+ _context0.next = 2;
2362
+ return this.client.getIdentityDkimAttributes({
2363
+ Identities: [domain]
2364
+ }).promise();
2365
+ case 2:
2366
+ dkim = _context0.sent;
2367
+ attributes = (_dkim$DkimAttributes = dkim.DkimAttributes) === null || _dkim$DkimAttributes === void 0 ? void 0 : _dkim$DkimAttributes[domain];
2368
+ dnsRecords = ((attributes === null || attributes === void 0 ? void 0 : attributes.DkimTokens) || []).map(function (token) {
2369
+ return {
2370
+ type: 'CNAME',
2371
+ host: "".concat(token, "._domainkey.").concat(domain),
2372
+ data: "".concat(token, ".").concat(SES_DKIM_CNAME_SUFFIX),
2373
+ valid: (attributes === null || attributes === void 0 ? void 0 : attributes.DkimVerificationStatus) === 'Success'
2374
+ };
2375
+ });
2376
+ return _context0.abrupt("return", {
2377
+ id: domain,
2378
+ type: 'domain',
2379
+ value: domain,
2380
+ status: toSenderStatus(attributes === null || attributes === void 0 ? void 0 : attributes.DkimVerificationStatus),
2381
+ dnsRecords: dnsRecords
2382
+ });
2383
+ case 6:
2384
+ case "end":
2385
+ return _context0.stop();
2386
+ }
2387
+ }, _callee0, this);
2388
+ }));
2389
+ function getDomainSender(_x0) {
2390
+ return _getDomainSender.apply(this, arguments);
2391
+ }
2392
+ return getDomainSender;
2393
+ }()
2394
+ }]);
2395
+ }();
2396
+
2397
+ var CONNECTION_TIMEOUT_MS = 15000;
2398
+ var GREETING_TIMEOUT_MS = 15000;
2399
+ var SOCKET_TIMEOUT_MS = 30000;
2400
+ var SmtpEmailProvider = /*#__PURE__*/function () {
2401
+ function SmtpEmailProvider(config) {
2402
+ _classCallCheck(this, SmtpEmailProvider);
2403
+ _defineProperty(this, "name", 'custom');
2404
+ var auth = config.MAIL_USER && config.MAIL_PASS ? {
2405
+ user: config.MAIL_USER,
2406
+ pass: config.MAIL_PASS
2407
+ } : undefined;
2408
+ var port = config.MAIL_PORT ? Number(config.MAIL_PORT) : undefined;
2409
+ this.transporter = nodemailer.createTransport(_objectSpread2(_objectSpread2({
2410
+ service: config.MAIL_SERVICE,
2411
+ host: config.MAIL_HOST,
2412
+ port: port,
2413
+ auth: auth
2414
+ }, auth && port !== 465 ? {
2415
+ requireTLS: true
2416
+ } : {}), {}, {
2417
+ connectionTimeout: CONNECTION_TIMEOUT_MS,
2418
+ greetingTimeout: GREETING_TIMEOUT_MS,
2419
+ socketTimeout: SOCKET_TIMEOUT_MS
2420
+ }));
2421
+ }
2422
+ return _createClass(SmtpEmailProvider, [{
2423
+ key: "send",
2424
+ value: function () {
2425
+ var _send = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(message) {
2426
+ var _message$cc, _message$bcc, _message$attachments;
2427
+ var info;
2428
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2429
+ while (1) switch (_context.prev = _context.next) {
2430
+ case 0:
2431
+ _context.next = 2;
2432
+ return this.transporter.sendMail({
2433
+ from: message.from,
2434
+ to: message.to.join(', '),
2435
+ cc: (_message$cc = message.cc) !== null && _message$cc !== void 0 && _message$cc.length ? message.cc.join(', ') : undefined,
2436
+ bcc: (_message$bcc = message.bcc) !== null && _message$bcc !== void 0 && _message$bcc.length ? message.bcc.join(', ') : undefined,
2437
+ replyTo: message.replyTo,
2438
+ subject: message.subject,
2439
+ html: message.html,
2440
+ text: message.text,
2441
+ attachments: (_message$attachments = message.attachments) === null || _message$attachments === void 0 ? void 0 : _message$attachments.map(function (attachment) {
2442
+ return {
2443
+ filename: attachment.filename,
2444
+ path: attachment.path,
2445
+ content: attachment.content ? Buffer.from(attachment.content, 'base64') : undefined,
2446
+ contentType: attachment.contentType
2447
+ };
2448
+ }),
2449
+ headers: _objectSpread2(_objectSpread2({}, message.headers || {}), message.customArgs || {})
2450
+ });
2451
+ case 2:
2452
+ info = _context.sent;
2453
+ return _context.abrupt("return", {
2454
+ messageId: info.messageId,
2455
+ provider: this.name,
2456
+ accepted: (info.accepted || []).map(String),
2457
+ rejected: (info.rejected || []).map(String)
2458
+ });
2459
+ case 4:
2460
+ case "end":
2461
+ return _context.stop();
2462
+ }
2463
+ }, _callee, this);
2464
+ }));
2465
+ function send(_x) {
2466
+ return _send.apply(this, arguments);
2467
+ }
2468
+ return send;
2469
+ }()
2470
+ }, {
2471
+ key: "listSingleSenders",
2472
+ value: function () {
2473
+ var _listSingleSenders = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
2474
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2475
+ while (1) switch (_context2.prev = _context2.next) {
2476
+ case 0:
2477
+ throw new EmailProviderNotSupportedError('custom', 'listSingleSenders');
2478
+ case 1:
2479
+ case "end":
2480
+ return _context2.stop();
2481
+ }
2482
+ }, _callee2);
2483
+ }));
2484
+ function listSingleSenders() {
2485
+ return _listSingleSenders.apply(this, arguments);
2486
+ }
2487
+ return listSingleSenders;
2488
+ }()
2489
+ }, {
2490
+ key: "listAuthenticatedDomains",
2491
+ value: function () {
2492
+ var _listAuthenticatedDomains = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
2493
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
2494
+ while (1) switch (_context3.prev = _context3.next) {
2495
+ case 0:
2496
+ throw new EmailProviderNotSupportedError('custom', 'listAuthenticatedDomains');
2497
+ case 1:
2498
+ case "end":
2499
+ return _context3.stop();
2500
+ }
2501
+ }, _callee3);
2502
+ }));
2503
+ function listAuthenticatedDomains() {
2504
+ return _listAuthenticatedDomains.apply(this, arguments);
2505
+ }
2506
+ return listAuthenticatedDomains;
2507
+ }()
2508
+ }, {
2509
+ key: "verifySingleSender",
2510
+ value: function () {
2511
+ var _verifySingleSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_input) {
2512
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
2513
+ while (1) switch (_context4.prev = _context4.next) {
2514
+ case 0:
2515
+ throw new EmailProviderNotSupportedError('custom', 'verifySingleSender');
2516
+ case 1:
2517
+ case "end":
2518
+ return _context4.stop();
2519
+ }
2520
+ }, _callee4);
2521
+ }));
2522
+ function verifySingleSender(_x2) {
2523
+ return _verifySingleSender.apply(this, arguments);
2524
+ }
2525
+ return verifySingleSender;
2526
+ }()
2527
+ }, {
2528
+ key: "removeSender",
2529
+ value: function () {
2530
+ var _removeSender = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_id) {
2531
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
2532
+ while (1) switch (_context5.prev = _context5.next) {
2533
+ case 0:
2534
+ throw new EmailProviderNotSupportedError('custom', 'removeSender');
2535
+ case 1:
2536
+ case "end":
2537
+ return _context5.stop();
2538
+ }
2539
+ }, _callee5);
2540
+ }));
2541
+ function removeSender(_x3) {
2542
+ return _removeSender.apply(this, arguments);
2543
+ }
2544
+ return removeSender;
2545
+ }()
2546
+ }, {
2547
+ key: "authenticateDomain",
2548
+ value: function () {
2549
+ var _authenticateDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_domain) {
2550
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
2551
+ while (1) switch (_context6.prev = _context6.next) {
2552
+ case 0:
2553
+ throw new EmailProviderNotSupportedError('custom', 'authenticateDomain');
2554
+ case 1:
2555
+ case "end":
2556
+ return _context6.stop();
2557
+ }
2558
+ }, _callee6);
2559
+ }));
2560
+ function authenticateDomain(_x4) {
2561
+ return _authenticateDomain.apply(this, arguments);
2562
+ }
2563
+ return authenticateDomain;
2564
+ }()
2565
+ }, {
2566
+ key: "validateDomain",
2567
+ value: function () {
2568
+ var _validateDomain = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_id) {
2569
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
2570
+ while (1) switch (_context7.prev = _context7.next) {
2571
+ case 0:
2572
+ throw new EmailProviderNotSupportedError('custom', 'validateDomain');
2573
+ case 1:
2574
+ case "end":
2575
+ return _context7.stop();
2576
+ }
2577
+ }, _callee7);
2578
+ }));
2579
+ function validateDomain(_x5) {
2580
+ return _validateDomain.apply(this, arguments);
2581
+ }
2582
+ return validateDomain;
2583
+ }()
2584
+ }]);
2585
+ }();
2586
+
2587
+ var resolveEmailProviderName = function resolveEmailProviderName(config) {
2588
+ var value = (config.DEFAULT_EMAIL_SERVICE || '').trim();
2589
+ if (value.toLowerCase() === 'sendgrid') {
2590
+ return 'sendgrid';
2591
+ }
2592
+ if (value.toLowerCase() === 'custom') {
2593
+ return 'custom';
2594
+ }
2595
+ if (value.toUpperCase() === 'SES') {
2596
+ return 'SES';
2597
+ }
2598
+ return DEFAULT_EMAIL_PROVIDER;
2599
+ };
2600
+ var createEmailProvider = function createEmailProvider(config) {
2601
+ switch (resolveEmailProviderName(config)) {
2602
+ case 'sendgrid':
2603
+ return new SendgridEmailProvider(config);
2604
+ case 'custom':
2605
+ return new SmtpEmailProvider(config);
2606
+ default:
2607
+ return new SesEmailProvider(config);
2608
+ }
2609
+ };
2610
+ var providerCache = new Map();
2611
+ var getEmailProvider = function getEmailProvider(cacheKey, config) {
2612
+ var fingerprint = getEmailProviderConfigFingerprint(config);
2613
+ var cached = providerCache.get(cacheKey);
2614
+ if (cached && cached.fingerprint === fingerprint) {
2615
+ return cached.provider;
2616
+ }
2617
+ var provider = createEmailProvider(config);
2618
+ providerCache.set(cacheKey, {
2619
+ fingerprint: fingerprint,
2620
+ provider: provider
2621
+ });
2622
+ return provider;
2623
+ };
2624
+ var clearEmailProviderCache = function clearEmailProviderCache(cacheKey) {
2625
+ if (cacheKey) {
2626
+ providerCache["delete"](cacheKey);
2627
+ return;
2628
+ }
2629
+ providerCache.clear();
2630
+ };
2631
+
2632
+ var EMAIL_DELIVERY_ID_KEY = 'EmailDeliveryId';
2633
+ var EMAIL_SUBDOMAIN_KEY = 'Subdomain';
2634
+ var toDeliveryLogProvider = function toDeliveryLogProvider(name) {
2635
+ if (name === 'sendgrid') {
2636
+ return 'sendgrid';
2637
+ }
2638
+ if (name === 'SES') {
2639
+ return 'ses';
2640
+ }
2641
+ return 'smtp';
2642
+ };
2643
+ var toErrorMessage = function toErrorMessage(error) {
2644
+ return error instanceof Error ? error.message : String(error);
2645
+ };
2646
+ var deliverEmail = /*#__PURE__*/function () {
2647
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
2648
+ var cacheKey, config, message, log, suppression, meta, provider, recipients, suppressed, closed, to, deliveryId, tracking, outbound, result;
2649
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2650
+ while (1) switch (_context.prev = _context.next) {
2651
+ case 0:
2652
+ cacheKey = _ref.cacheKey, config = _ref.config, message = _ref.message, log = _ref.log, suppression = _ref.suppression, meta = _ref.meta;
2653
+ provider = getEmailProvider(cacheKey, config);
2654
+ recipients = message;
2655
+ suppressed = [];
2656
+ if (!suppression) {
2657
+ _context.next = 14;
2658
+ break;
2659
+ }
2660
+ _context.next = 7;
2661
+ return suppression.blocked([].concat(_toConsumableArray(message.to), _toConsumableArray(message.cc || []), _toConsumableArray(message.bcc || [])), meta === null || meta === void 0 ? void 0 : meta.source);
2662
+ case 7:
2663
+ suppressed = _context.sent;
2664
+ if (!suppressed.length) {
2665
+ _context.next = 14;
2666
+ break;
2667
+ }
2668
+ closed = new Set(suppressed);
2669
+ to = message.to.filter(function (email) {
2670
+ return !closed.has(email);
2671
+ });
2672
+ if (to.length) {
2673
+ _context.next = 13;
2674
+ break;
2675
+ }
2676
+ return _context.abrupt("return", {
2677
+ messageId: '',
2678
+ provider: provider.name,
2679
+ accepted: [],
2680
+ rejected: [],
2681
+ skipped: true,
2682
+ suppressed: suppressed
2683
+ });
2684
+ case 13:
2685
+ recipients = _objectSpread2(_objectSpread2({}, message), {}, {
2686
+ to: to,
2687
+ cc: (message.cc || []).filter(function (email) {
2688
+ return !closed.has(email);
2689
+ }),
2690
+ bcc: (message.bcc || []).filter(function (email) {
2691
+ return !closed.has(email);
2692
+ })
2693
+ });
2694
+ case 14:
2695
+ if (!log) {
2696
+ _context.next = 24;
2697
+ break;
2698
+ }
2699
+ _context.prev = 15;
2700
+ _context.next = 18;
2701
+ return log.create({
2702
+ toEmails: recipients.to,
2703
+ ccEmails: recipients.cc,
2704
+ from: recipients.from,
2705
+ subject: recipients.subject,
2706
+ provider: provider.name,
2707
+ source: meta === null || meta === void 0 ? void 0 : meta.source,
2708
+ sourceId: meta === null || meta === void 0 ? void 0 : meta.sourceId,
2709
+ userId: meta === null || meta === void 0 ? void 0 : meta.userId,
2710
+ notificationId: meta === null || meta === void 0 ? void 0 : meta.notificationId
2711
+ });
2712
+ case 18:
2713
+ deliveryId = _context.sent;
2714
+ _context.next = 24;
2715
+ break;
2716
+ case 21:
2717
+ _context.prev = 21;
2718
+ _context.t0 = _context["catch"](15);
2719
+ console.error("Failed to record email delivery: ".concat(toErrorMessage(_context.t0)));
2720
+ case 24:
2721
+ tracking = _objectSpread2(_objectSpread2({}, deliveryId ? _defineProperty({}, EMAIL_DELIVERY_ID_KEY, deliveryId) : {}), meta !== null && meta !== void 0 && meta.subdomain ? _defineProperty({}, EMAIL_SUBDOMAIN_KEY, meta.subdomain) : {});
2722
+ outbound = Object.keys(tracking).length ? _objectSpread2(_objectSpread2({}, recipients), {}, {
2723
+ customArgs: _objectSpread2(_objectSpread2({}, recipients.customArgs || {}), tracking)
2724
+ }) : recipients;
2725
+ _context.prev = 26;
2726
+ _context.next = 29;
2727
+ return provider.send(outbound);
2728
+ case 29:
2729
+ result = _context.sent;
2730
+ if (!(log && deliveryId)) {
2731
+ _context.next = 33;
2732
+ break;
2733
+ }
2734
+ _context.next = 33;
2735
+ return log.update(deliveryId, {
2736
+ status: 'sent',
2737
+ sentAt: new Date(),
2738
+ messageId: result.messageId,
2739
+ rejected: result.rejected
2740
+ })["catch"](function (error) {
2741
+ console.error("Failed to update email delivery: ".concat(toErrorMessage(error)));
2742
+ });
2743
+ case 33:
2744
+ return _context.abrupt("return", _objectSpread2(_objectSpread2({}, result), {}, {
2745
+ deliveryId: deliveryId,
2746
+ suppressed: suppressed.length ? suppressed : undefined
2747
+ }));
2748
+ case 36:
2749
+ _context.prev = 36;
2750
+ _context.t1 = _context["catch"](26);
2751
+ if (!(log && deliveryId)) {
2752
+ _context.next = 41;
2753
+ break;
2754
+ }
2755
+ _context.next = 41;
2756
+ return log.update(deliveryId, {
2757
+ status: 'failed',
2758
+ sentAt: new Date(),
2759
+ error: toErrorMessage(_context.t1)
2760
+ })["catch"](function () {
2761
+ return undefined;
2762
+ });
2763
+ case 41:
2764
+ throw _context.t1;
2765
+ case 42:
2766
+ case "end":
2767
+ return _context.stop();
2768
+ }
2769
+ }, _callee, null, [[15, 21], [26, 36]]);
2770
+ }));
2771
+ return function deliverEmail(_x) {
2772
+ return _ref2.apply(this, arguments);
2773
+ };
2774
+ }();
2775
+
2776
+ export { CONFORMITY_TYPE, DEFAULT_EMAIL_PROVIDER, DEFAULT_SEX_CHOICES, DEFAULT_SOCIAL_LINKS, EMAIL_DELIVERY_ID_KEY, EMAIL_PROVIDER_CONFIG_CODES, EMAIL_SUBDOMAIN_KEY, EditorAttributeUtil, EmailProviderConfigError, EmailProviderNotSupportedError, EmailProviderRequestError, GQL_CURSOR_PARAM_DEFS, GQL_OFFSET_PARAM_DEFS, LOG_STATUSES, PERMISSION_ROLES, SENDGRID_API_BASE_URL, SENDGRID_SIGNATURE_HEADER, SENDGRID_TIMESTAMP_HEADER, SES_DKIM_CNAME_SUFFIX, SEX_OPTIONS, SOCIAL_LINKS, STATUSES, SendgridEmailProvider, SesEmailProvider, SmtpEmailProvider, USER_ROLES, alignSender, apolloCommonTypes, buildKnowledgeSourceType, clearEmailProviderCache, createEmailProvider, createGenerateModels, deliverEmail, enqueueAiKnowledgeSourceRefreshJob, enqueueKnowledgeIndexJob, erxesSubdomainHeaderName, getCustomerName, getEmailProvider, getEmailProviderConfigFingerprint, getHostnameZeroTrust, getSubomdainHeader, graphqlAttachmentInput, graphqlAttachmentType, graphqlPaginationInfo, graphqlPdfAttachmentInput, graphqlPdfAttachmentType, loadEmailProviderConfig, normalizeEmail, parseAddress, resolveDefaultSenderEmail, resolveEmailProviderName, runReplacersOn, sanitizeHeaders, stream, toBase64Attachment, toBase64Attachments, toDeliveryLogProvider, verifySendgridSignature, wrapApolloMutations };