@antelopejs/dms-mailing 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +162 -0
- package/dist/antelope-modules.d.ts +32 -0
- package/dist/antelope-modules.js +36 -0
- package/dist/antelope-modules.js.map +1 -0
- package/dist/automation/email-event-trigger.d.ts +16 -0
- package/dist/automation/email-event-trigger.js +70 -0
- package/dist/automation/email-event-trigger.js.map +1 -0
- package/dist/automation/index.d.ts +4 -0
- package/dist/automation/index.js +39 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/send-template-action.d.ts +13 -0
- package/dist/automation/send-template-action.js +71 -0
- package/dist/automation/send-template-action.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +28 -0
- package/dist/constants.js +32 -0
- package/dist/constants.js.map +1 -0
- package/dist/crons/index.d.ts +1 -0
- package/dist/crons/index.js +18 -0
- package/dist/crons/index.js.map +1 -0
- package/dist/crons/retention.d.ts +18 -0
- package/dist/crons/retention.js +107 -0
- package/dist/crons/retention.js.map +1 -0
- package/dist/data/body.d.ts +1 -0
- package/dist/data/body.js +18 -0
- package/dist/data/body.js.map +1 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/data/index.js +20 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/sends-table.d.ts +28 -0
- package/dist/data/sends-table.js +161 -0
- package/dist/data/sends-table.js.map +1 -0
- package/dist/data/templates-table.d.ts +31 -0
- package/dist/data/templates-table.js +173 -0
- package/dist/data/templates-table.js.map +1 -0
- package/dist/data-types/categories-type.d.ts +35 -0
- package/dist/data-types/categories-type.js +37 -0
- package/dist/data-types/categories-type.js.map +1 -0
- package/dist/data-types/category-type.d.ts +8 -0
- package/dist/data-types/category-type.js +43 -0
- package/dist/data-types/category-type.js.map +1 -0
- package/dist/data-types/index.d.ts +2 -0
- package/dist/data-types/index.js +19 -0
- package/dist/data-types/index.js.map +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +19 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/models/index.d.ts +4 -0
- package/dist/db/models/index.js +21 -0
- package/dist/db/models/index.js.map +1 -0
- package/dist/db/models/send-events.model.d.ts +27 -0
- package/dist/db/models/send-events.model.js +35 -0
- package/dist/db/models/send-events.model.js.map +1 -0
- package/dist/db/models/sends.model.d.ts +32 -0
- package/dist/db/models/sends.model.js +115 -0
- package/dist/db/models/sends.model.js.map +1 -0
- package/dist/db/models/settings.model.d.ts +23 -0
- package/dist/db/models/settings.model.js +13 -0
- package/dist/db/models/settings.model.js.map +1 -0
- package/dist/db/models/templates.model.d.ts +23 -0
- package/dist/db/models/templates.model.js +13 -0
- package/dist/db/models/templates.model.js.map +1 -0
- package/dist/db/tables/index.d.ts +4 -0
- package/dist/db/tables/index.js +21 -0
- package/dist/db/tables/index.js.map +1 -0
- package/dist/db/tables/send-events.table.d.ts +10 -0
- package/dist/db/tables/send-events.table.js +44 -0
- package/dist/db/tables/send-events.table.js.map +1 -0
- package/dist/db/tables/sends.table.d.ts +26 -0
- package/dist/db/tables/sends.table.js +113 -0
- package/dist/db/tables/sends.table.js.map +1 -0
- package/dist/db/tables/settings.table.d.ts +15 -0
- package/dist/db/tables/settings.table.js +68 -0
- package/dist/db/tables/settings.table.js.map +1 -0
- package/dist/db/tables/templates.table.d.ts +18 -0
- package/dist/db/tables/templates.table.js +81 -0
- package/dist/db/tables/templates.table.js.map +1 -0
- package/dist/engine/conditions.d.ts +2 -0
- package/dist/engine/conditions.js +20 -0
- package/dist/engine/conditions.js.map +1 -0
- package/dist/engine/coverage.d.ts +4 -0
- package/dist/engine/coverage.js +45 -0
- package/dist/engine/coverage.js.map +1 -0
- package/dist/engine/fallback-html.d.ts +4 -0
- package/dist/engine/fallback-html.js +84 -0
- package/dist/engine/fallback-html.js.map +1 -0
- package/dist/engine/index.d.ts +7 -0
- package/dist/engine/index.js +24 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/paths.d.ts +3 -0
- package/dist/engine/paths.js +32 -0
- package/dist/engine/paths.js.map +1 -0
- package/dist/engine/resolve.d.ts +4 -0
- package/dist/engine/resolve.js +139 -0
- package/dist/engine/resolve.js.map +1 -0
- package/dist/engine/tokens.d.ts +7 -0
- package/dist/engine/tokens.js +29 -0
- package/dist/engine/tokens.js.map +1 -0
- package/dist/engine/walk.d.ts +3 -0
- package/dist/engine/walk.js +14 -0
- package/dist/engine/walk.js.map +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +18 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/tenant-export.d.ts +14 -0
- package/dist/hooks/tenant-export.js +84 -0
- package/dist/hooks/tenant-export.js.map +1 -0
- package/dist/implementations/dms-mailing/index.d.ts +2 -0
- package/dist/implementations/dms-mailing/index.js +8 -0
- package/dist/implementations/dms-mailing/index.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/editor.d.ts +9 -0
- package/dist/pages/editor.js +30 -0
- package/dist/pages/editor.js.map +1 -0
- package/dist/pages/index.d.ts +7 -0
- package/dist/pages/index.js +24 -0
- package/dist/pages/index.js.map +1 -0
- package/dist/pages/module.d.ts +1 -0
- package/dist/pages/module.js +12 -0
- package/dist/pages/module.js.map +1 -0
- package/dist/pages/overview.d.ts +14 -0
- package/dist/pages/overview.js +92 -0
- package/dist/pages/overview.js.map +1 -0
- package/dist/pages/sends.d.ts +13 -0
- package/dist/pages/sends.js +125 -0
- package/dist/pages/sends.js.map +1 -0
- package/dist/pages/settings/form.d.ts +1 -0
- package/dist/pages/settings/form.js +68 -0
- package/dist/pages/settings/form.js.map +1 -0
- package/dist/pages/settings/index.d.ts +2 -0
- package/dist/pages/settings/index.js +19 -0
- package/dist/pages/settings/index.js.map +1 -0
- package/dist/pages/settings/page.d.ts +10 -0
- package/dist/pages/settings/page.js +35 -0
- package/dist/pages/settings/page.js.map +1 -0
- package/dist/pages/templates.d.ts +10 -0
- package/dist/pages/templates.js +140 -0
- package/dist/pages/templates.js.map +1 -0
- package/dist/permissions.d.ts +1 -0
- package/dist/permissions.js +37 -0
- package/dist/permissions.js.map +1 -0
- package/dist/quick-actions.d.ts +2 -0
- package/dist/quick-actions.js +18 -0
- package/dist/quick-actions.js.map +1 -0
- package/dist/realtime.d.ts +4 -0
- package/dist/realtime.js +44 -0
- package/dist/realtime.js.map +1 -0
- package/dist/routes/events.d.ts +9 -0
- package/dist/routes/events.js +63 -0
- package/dist/routes/events.js.map +1 -0
- package/dist/routes/index.d.ts +7 -0
- package/dist/routes/index.js +24 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/metrics.d.ts +54 -0
- package/dist/routes/metrics.js +235 -0
- package/dist/routes/metrics.js.map +1 -0
- package/dist/routes/period.d.ts +5 -0
- package/dist/routes/period.js +36 -0
- package/dist/routes/period.js.map +1 -0
- package/dist/routes/provider.d.ts +13 -0
- package/dist/routes/provider.js +41 -0
- package/dist/routes/provider.js.map +1 -0
- package/dist/routes/sends.d.ts +31 -0
- package/dist/routes/sends.js +178 -0
- package/dist/routes/sends.js.map +1 -0
- package/dist/routes/settings.d.ts +14 -0
- package/dist/routes/settings.js +72 -0
- package/dist/routes/settings.js.map +1 -0
- package/dist/routes/templates.d.ts +61 -0
- package/dist/routes/templates.js +230 -0
- package/dist/routes/templates.js.map +1 -0
- package/dist/services/attention.d.ts +23 -0
- package/dist/services/attention.js +104 -0
- package/dist/services/attention.js.map +1 -0
- package/dist/services/categories.d.ts +34 -0
- package/dist/services/categories.js +34 -0
- package/dist/services/categories.js.map +1 -0
- package/dist/services/events.d.ts +10 -0
- package/dist/services/events.js +89 -0
- package/dist/services/events.js.map +1 -0
- package/dist/services/metrics.d.ts +34 -0
- package/dist/services/metrics.js +103 -0
- package/dist/services/metrics.js.map +1 -0
- package/dist/services/notify.d.ts +20 -0
- package/dist/services/notify.js +63 -0
- package/dist/services/notify.js.map +1 -0
- package/dist/services/permissions.d.ts +2 -0
- package/dist/services/permissions.js +15 -0
- package/dist/services/permissions.js.map +1 -0
- package/dist/services/provider.d.ts +6 -0
- package/dist/services/provider.js +25 -0
- package/dist/services/provider.js.map +1 -0
- package/dist/services/render.d.ts +6 -0
- package/dist/services/render.js +21 -0
- package/dist/services/render.js.map +1 -0
- package/dist/services/send.d.ts +49 -0
- package/dist/services/send.js +259 -0
- package/dist/services/send.js.map +1 -0
- package/dist/services/settings.d.ts +4 -0
- package/dist/services/settings.js +61 -0
- package/dist/services/settings.js.map +1 -0
- package/dist/services/status.d.ts +3 -0
- package/dist/services/status.js +16 -0
- package/dist/services/status.js.map +1 -0
- package/dist/services/templates.d.ts +17 -0
- package/dist/services/templates.js +92 -0
- package/dist/services/templates.js.map +1 -0
- package/dist/test/antelope.test.d.ts +2 -0
- package/dist/test/antelope.test.js +179 -0
- package/dist/test/antelope.test.js.map +1 -0
- package/dist/test/helpers/http.d.ts +4 -0
- package/dist/test/helpers/http.js +28 -0
- package/dist/test/helpers/http.js.map +1 -0
- package/dist/test/helpers/owner.d.ts +5 -0
- package/dist/test/helpers/owner.js +30 -0
- package/dist/test/helpers/owner.js.map +1 -0
- package/dist/test/integration/events.test.d.ts +1 -0
- package/dist/test/integration/events.test.js +132 -0
- package/dist/test/integration/events.test.js.map +1 -0
- package/dist/test/integration/retention.test.d.ts +1 -0
- package/dist/test/integration/retention.test.js +291 -0
- package/dist/test/integration/retention.test.js.map +1 -0
- package/dist/test/integration/sends.test.d.ts +1 -0
- package/dist/test/integration/sends.test.js +157 -0
- package/dist/test/integration/sends.test.js.map +1 -0
- package/dist/test/integration/settings.test.d.ts +1 -0
- package/dist/test/integration/settings.test.js +45 -0
- package/dist/test/integration/settings.test.js.map +1 -0
- package/dist/test/integration/setup.test.d.ts +1 -0
- package/dist/test/integration/setup.test.js +32 -0
- package/dist/test/integration/setup.test.js.map +1 -0
- package/dist/test/integration/templates.test.d.ts +1 -0
- package/dist/test/integration/templates.test.js +167 -0
- package/dist/test/integration/templates.test.js.map +1 -0
- package/dist/test/integration/tenant-export.test.d.ts +1 -0
- package/dist/test/integration/tenant-export.test.js +85 -0
- package/dist/test/integration/tenant-export.test.js.map +1 -0
- package/dist/test/unit/attention.test.d.ts +1 -0
- package/dist/test/unit/attention.test.js +109 -0
- package/dist/test/unit/attention.test.js.map +1 -0
- package/dist/test/unit/automation.test.d.ts +1 -0
- package/dist/test/unit/automation.test.js +104 -0
- package/dist/test/unit/automation.test.js.map +1 -0
- package/dist/test/unit/categories.test.d.ts +1 -0
- package/dist/test/unit/categories.test.js +38 -0
- package/dist/test/unit/categories.test.js.map +1 -0
- package/dist/test/unit/engine/conditions.test.d.ts +1 -0
- package/dist/test/unit/engine/conditions.test.js +23 -0
- package/dist/test/unit/engine/conditions.test.js.map +1 -0
- package/dist/test/unit/engine/coverage.test.d.ts +1 -0
- package/dist/test/unit/engine/coverage.test.js +106 -0
- package/dist/test/unit/engine/coverage.test.js.map +1 -0
- package/dist/test/unit/engine/fallback-html.test.d.ts +1 -0
- package/dist/test/unit/engine/fallback-html.test.js +78 -0
- package/dist/test/unit/engine/fallback-html.test.js.map +1 -0
- package/dist/test/unit/engine/paths.test.d.ts +1 -0
- package/dist/test/unit/engine/paths.test.js +33 -0
- package/dist/test/unit/engine/paths.test.js.map +1 -0
- package/dist/test/unit/engine/resolve.test.d.ts +1 -0
- package/dist/test/unit/engine/resolve.test.js +157 -0
- package/dist/test/unit/engine/resolve.test.js.map +1 -0
- package/dist/test/unit/engine/tokens.test.d.ts +1 -0
- package/dist/test/unit/engine/tokens.test.js +26 -0
- package/dist/test/unit/engine/tokens.test.js.map +1 -0
- package/dist/test/unit/events.test.d.ts +1 -0
- package/dist/test/unit/events.test.js +13 -0
- package/dist/test/unit/events.test.js.map +1 -0
- package/dist/test/unit/metrics.test.d.ts +1 -0
- package/dist/test/unit/metrics.test.js +108 -0
- package/dist/test/unit/metrics.test.js.map +1 -0
- package/dist/test/unit/notify.test.d.ts +1 -0
- package/dist/test/unit/notify.test.js +49 -0
- package/dist/test/unit/notify.test.js.map +1 -0
- package/dist/test/unit/period.test.d.ts +1 -0
- package/dist/test/unit/period.test.js +44 -0
- package/dist/test/unit/period.test.js.map +1 -0
- package/dist/test/unit/provider.test.d.ts +1 -0
- package/dist/test/unit/provider.test.js +47 -0
- package/dist/test/unit/provider.test.js.map +1 -0
- package/dist/test/unit/realtime.test.d.ts +1 -0
- package/dist/test/unit/realtime.test.js +13 -0
- package/dist/test/unit/realtime.test.js.map +1 -0
- package/dist/test/unit/render.test.d.ts +1 -0
- package/dist/test/unit/render.test.js +23 -0
- package/dist/test/unit/render.test.js.map +1 -0
- package/dist/test/unit/retention.test.d.ts +1 -0
- package/dist/test/unit/retention.test.js +66 -0
- package/dist/test/unit/retention.test.js.map +1 -0
- package/dist/test/unit/send-batch.test.d.ts +1 -0
- package/dist/test/unit/send-batch.test.js +46 -0
- package/dist/test/unit/send-batch.test.js.map +1 -0
- package/dist/test/unit/send.test.d.ts +1 -0
- package/dist/test/unit/send.test.js +120 -0
- package/dist/test/unit/send.test.js.map +1 -0
- package/dist/test/unit/smoke.test.d.ts +1 -0
- package/dist/test/unit/smoke.test.js +10 -0
- package/dist/test/unit/smoke.test.js.map +1 -0
- package/dist/test/unit/status.test.d.ts +1 -0
- package/dist/test/unit/status.test.js +16 -0
- package/dist/test/unit/status.test.js.map +1 -0
- package/dist/test/unit/templates.test.d.ts +1 -0
- package/dist/test/unit/templates.test.js +48 -0
- package/dist/test/unit/templates.test.js.map +1 -0
- package/dist/test/unit/tenant-export.test.d.ts +1 -0
- package/dist/test/unit/tenant-export.test.js +59 -0
- package/dist/test/unit/tenant-export.test.js.map +1 -0
- package/dist/test/unit/webhook-secret.test.d.ts +1 -0
- package/dist/test/unit/webhook-secret.test.js +42 -0
- package/dist/test/unit/webhook-secret.test.js.map +1 -0
- package/dist/types/blocks.d.ts +2 -0
- package/dist/types/blocks.js +3 -0
- package/dist/types/blocks.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/resolved.d.ts +68 -0
- package/dist/types/resolved.js +3 -0
- package/dist/types/resolved.js.map +1 -0
- package/dist/types/sends.d.ts +14 -0
- package/dist/types/sends.js +19 -0
- package/dist/types/sends.js.map +1 -0
- package/dist/types/settings.d.ts +16 -0
- package/dist/types/settings.js +11 -0
- package/dist/types/settings.js.map +1 -0
- package/dist/validation/settings.schema.d.ts +63 -0
- package/dist/validation/settings.schema.js +29 -0
- package/dist/validation/settings.schema.js.map +1 -0
- package/dist/validation/templates.schema.d.ts +248 -0
- package/dist/validation/templates.schema.js +126 -0
- package/dist/validation/templates.schema.js.map +1 -0
- package/frontend-vue/.editorconfig +12 -0
- package/frontend-vue/.prettierrc +11 -0
- package/frontend-vue/app/components/AttentionCard.vue +78 -0
- package/frontend-vue/app/components/CategoriesInput.vue +126 -0
- package/frontend-vue/app/components/CategoryInput.vue +67 -0
- package/frontend-vue/app/components/Editor.vue +63 -0
- package/frontend-vue/app/components/FunnelCard.vue +66 -0
- package/frontend-vue/app/components/HtmlPreviewModal.vue +20 -0
- package/frontend-vue/app/components/NewTemplateModal.vue +158 -0
- package/frontend-vue/app/components/ProviderChip.vue +39 -0
- package/frontend-vue/app/components/SendDrawer.vue +298 -0
- package/frontend-vue/app/components/TemplateCard.vue +127 -0
- package/frontend-vue/app/components/TemplateDrawer.vue +394 -0
- package/frontend-vue/app/components/TemplateGallery.vue +112 -0
- package/frontend-vue/app/components/TemplatePreviewFrame.vue +103 -0
- package/frontend-vue/app/components/TestSendModal.vue +162 -0
- package/frontend-vue/app/components/TokenText.vue +26 -0
- package/frontend-vue/app/components/blocks/Button.vue +19 -0
- package/frontend-vue/app/components/blocks/Code.vue +17 -0
- package/frontend-vue/app/components/blocks/Divider.vue +3 -0
- package/frontend-vue/app/components/blocks/Footer.vue +22 -0
- package/frontend-vue/app/components/blocks/Heading.vue +18 -0
- package/frontend-vue/app/components/blocks/Hero.vue +32 -0
- package/frontend-vue/app/components/blocks/List.vue +33 -0
- package/frontend-vue/app/components/blocks/Paragraph.vue +18 -0
- package/frontend-vue/app/components/blocks/Total.vue +18 -0
- package/frontend-vue/app/components/editor/EditorBlock.vue +121 -0
- package/frontend-vue/app/components/editor/EditorBlockList.vue +44 -0
- package/frontend-vue/app/components/editor/EditorBlockSettings.vue +186 -0
- package/frontend-vue/app/components/editor/EditorCanvas.vue +91 -0
- package/frontend-vue/app/components/editor/EditorConditionFields.vue +88 -0
- package/frontend-vue/app/components/editor/EditorDataPanel.vue +128 -0
- package/frontend-vue/app/components/editor/EditorDraftBar.vue +35 -0
- package/frontend-vue/app/components/editor/EditorIfBlock.vue +120 -0
- package/frontend-vue/app/components/editor/EditorMissingLocale.vue +62 -0
- package/frontend-vue/app/components/editor/EditorPalette.vue +62 -0
- package/frontend-vue/app/components/editor/EditorRail.vue +58 -0
- package/frontend-vue/app/components/editor/EditorSubjectSettings.vue +37 -0
- package/frontend-vue/app/components/editor/EditorTemplateSettings.vue +87 -0
- package/frontend-vue/app/components/editor/EditorTestSendModal.vue +66 -0
- package/frontend-vue/app/components/editor/EditorToolbar.vue +155 -0
- package/frontend-vue/app/components/editor/EditorVariables.vue +163 -0
- package/frontend-vue/app/components/editor/EditorWorkspace.vue +189 -0
- package/frontend-vue/app/composables/useEditorContext.ts +44 -0
- package/frontend-vue/app/composables/useMailingApi.ts +197 -0
- package/frontend-vue/app/composables/useMailingPeriodData.ts +39 -0
- package/frontend-vue/app/composables/useTemplateDrawer.ts +90 -0
- package/frontend-vue/app/composables/useTemplateEditor.ts +228 -0
- package/frontend-vue/app/emails/EmailMailingTemplate.vue +24 -0
- package/frontend-vue/app/emails/components/MailingBlocks.vue +117 -0
- package/frontend-vue/app/plugins/template-gallery-display.client.ts +14 -0
- package/frontend-vue/app/types/component.ts +29 -0
- package/frontend-vue/app/types/mailing.ts +365 -0
- package/frontend-vue/app/utils/blocks/components.ts +14 -0
- package/frontend-vue/app/utils/blocks/dnd.ts +15 -0
- package/frontend-vue/app/utils/blocks/factory.ts +100 -0
- package/frontend-vue/app/utils/blocks/fields.ts +58 -0
- package/frontend-vue/app/utils/blocks/index.ts +5 -0
- package/frontend-vue/app/utils/blocks/tree.ts +74 -0
- package/frontend-vue/app/utils/categories.ts +54 -0
- package/frontend-vue/app/utils/clone.ts +3 -0
- package/frontend-vue/app/utils/conditions.ts +50 -0
- package/frontend-vue/app/utils/editor-route.ts +18 -0
- package/frontend-vue/app/utils/gallery.ts +41 -0
- package/frontend-vue/app/utils/locales.ts +41 -0
- package/frontend-vue/app/utils/paths.ts +84 -0
- package/frontend-vue/app/utils/period.ts +23 -0
- package/frontend-vue/app/utils/testData.ts +10 -0
- package/frontend-vue/app/utils/timeline.ts +68 -0
- package/frontend-vue/app/utils/tokens.ts +24 -0
- package/frontend-vue/app/utils/variables.ts +48 -0
- package/frontend-vue/dms.email.ts +9 -0
- package/frontend-vue/dms.frontend.ts +29 -0
- package/frontend-vue/eslint.config.mjs +13 -0
- package/frontend-vue/i18n/locales/mailing-en-GB.json +397 -0
- package/frontend-vue/i18n/locales/mailing-fr-FR.json +397 -0
- package/frontend-vue/package.json +32 -0
- package/frontend-vue/pnpm-lock.yaml +6446 -0
- package/frontend-vue/pnpm-workspace.yaml +2 -0
- package/frontend-vue/tests/block-components.test.ts +14 -0
- package/frontend-vue/tests/block-fields.test.ts +23 -0
- package/frontend-vue/tests/blocks-factory.test.ts +28 -0
- package/frontend-vue/tests/blocks-tree.test.ts +49 -0
- package/frontend-vue/tests/categories.test.ts +64 -0
- package/frontend-vue/tests/conditions.test.ts +36 -0
- package/frontend-vue/tests/dnd.test.ts +11 -0
- package/frontend-vue/tests/editor-block-list.test.ts +54 -0
- package/frontend-vue/tests/editor-route.test.ts +23 -0
- package/frontend-vue/tests/email-render-cases.json +77 -0
- package/frontend-vue/tests/gallery.test.ts +39 -0
- package/frontend-vue/tests/i18n-editor.test.ts +21 -0
- package/frontend-vue/tests/i18n.test.ts +83 -0
- package/frontend-vue/tests/locales.test.ts +38 -0
- package/frontend-vue/tests/mailing-api.test.ts +10 -0
- package/frontend-vue/tests/paths.test.ts +128 -0
- package/frontend-vue/tests/period.test.ts +13 -0
- package/frontend-vue/tests/smoke.test.ts +8 -0
- package/frontend-vue/tests/template-editor.test.ts +65 -0
- package/frontend-vue/tests/test-data.test.ts +15 -0
- package/frontend-vue/tests/timeline.test.ts +29 -0
- package/frontend-vue/tests/tokens.test.ts +12 -0
- package/frontend-vue/tests/variables.test.ts +46 -0
- package/frontend-vue/vitest.config.ts +10 -0
- package/package.json +94 -0
- package/src/antelope-modules.ts +48 -0
- package/src/automation/email-event-trigger.ts +112 -0
- package/src/automation/index.ts +33 -0
- package/src/automation/send-template-action.ts +100 -0
- package/src/config.ts +15 -0
- package/src/constants.ts +42 -0
- package/src/crons/index.ts +1 -0
- package/src/crons/retention.ts +126 -0
- package/src/data/body.ts +14 -0
- package/src/data/index.ts +3 -0
- package/src/data/sends-table.ts +154 -0
- package/src/data/templates-table.ts +202 -0
- package/src/data-types/categories-type.ts +29 -0
- package/src/data-types/category-type.ts +44 -0
- package/src/data-types/index.ts +2 -0
- package/src/db/index.ts +2 -0
- package/src/db/models/index.ts +4 -0
- package/src/db/models/send-events.model.ts +46 -0
- package/src/db/models/sends.model.ts +147 -0
- package/src/db/models/settings.model.ts +12 -0
- package/src/db/models/templates.model.ts +12 -0
- package/src/db/tables/index.ts +4 -0
- package/src/db/tables/send-events.table.ts +31 -0
- package/src/db/tables/sends.table.ts +85 -0
- package/src/db/tables/settings.table.ts +49 -0
- package/src/db/tables/templates.table.ts +70 -0
- package/src/engine/conditions.ts +30 -0
- package/src/engine/coverage.ts +67 -0
- package/src/engine/fallback-html.ts +116 -0
- package/src/engine/index.ts +7 -0
- package/src/engine/paths.ts +33 -0
- package/src/engine/resolve.ts +178 -0
- package/src/engine/tokens.ts +35 -0
- package/src/engine/walk.ts +18 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/tenant-export.ts +127 -0
- package/src/implementations/dms-mailing/index.ts +2 -0
- package/src/index.ts +62 -0
- package/src/pages/editor.ts +23 -0
- package/src/pages/index.ts +11 -0
- package/src/pages/module.ts +9 -0
- package/src/pages/overview.ts +175 -0
- package/src/pages/sends.ts +174 -0
- package/src/pages/settings/form.ts +67 -0
- package/src/pages/settings/index.ts +2 -0
- package/src/pages/settings/page.ts +34 -0
- package/src/pages/templates.ts +141 -0
- package/src/permissions.ts +44 -0
- package/src/quick-actions.ts +20 -0
- package/src/realtime.ts +53 -0
- package/src/routes/events.ts +57 -0
- package/src/routes/index.ts +7 -0
- package/src/routes/metrics.ts +243 -0
- package/src/routes/period.ts +46 -0
- package/src/routes/provider.ts +31 -0
- package/src/routes/sends.ts +215 -0
- package/src/routes/settings.ts +66 -0
- package/src/routes/templates.ts +256 -0
- package/src/services/attention.ts +151 -0
- package/src/services/categories.ts +43 -0
- package/src/services/events.ts +121 -0
- package/src/services/metrics.ts +175 -0
- package/src/services/notify.ts +90 -0
- package/src/services/permissions.ts +42 -0
- package/src/services/provider.ts +46 -0
- package/src/services/render.ts +33 -0
- package/src/services/send.ts +409 -0
- package/src/services/settings.ts +74 -0
- package/src/services/status.ts +16 -0
- package/src/services/templates.ts +157 -0
- package/src/test/antelope.test.ts +188 -0
- package/src/test/helpers/http.ts +23 -0
- package/src/test/helpers/owner.ts +37 -0
- package/src/test/integration/events.test.ts +136 -0
- package/src/test/integration/retention.test.ts +363 -0
- package/src/test/integration/sends.test.ts +200 -0
- package/src/test/integration/settings.test.ts +50 -0
- package/src/test/integration/setup.test.ts +35 -0
- package/src/test/integration/templates.test.ts +229 -0
- package/src/test/integration/tenant-export.test.ts +125 -0
- package/src/test/unit/attention.test.ts +129 -0
- package/src/test/unit/automation.test.ts +130 -0
- package/src/test/unit/categories.test.ts +51 -0
- package/src/test/unit/engine/conditions.test.ts +35 -0
- package/src/test/unit/engine/coverage.test.ts +118 -0
- package/src/test/unit/engine/fallback-html.test.ts +86 -0
- package/src/test/unit/engine/paths.test.ts +39 -0
- package/src/test/unit/engine/resolve.test.ts +176 -0
- package/src/test/unit/engine/tokens.test.ts +26 -0
- package/src/test/unit/events.test.ts +19 -0
- package/src/test/unit/metrics.test.ts +170 -0
- package/src/test/unit/notify.test.ts +71 -0
- package/src/test/unit/period.test.ts +64 -0
- package/src/test/unit/provider.test.ts +57 -0
- package/src/test/unit/realtime.test.ts +11 -0
- package/src/test/unit/render.test.ts +23 -0
- package/src/test/unit/retention.test.ts +91 -0
- package/src/test/unit/send-batch.test.ts +72 -0
- package/src/test/unit/send.test.ts +161 -0
- package/src/test/unit/smoke.test.ts +8 -0
- package/src/test/unit/status.test.ts +14 -0
- package/src/test/unit/templates.test.ts +52 -0
- package/src/test/unit/tenant-export.test.ts +88 -0
- package/src/test/unit/webhook-secret.test.ts +50 -0
- package/src/types/blocks.ts +31 -0
- package/src/types/index.ts +4 -0
- package/src/types/resolved.ts +89 -0
- package/src/types/sends.ts +44 -0
- package/src/types/settings.ts +24 -0
- package/src/validation/settings.schema.ts +33 -0
- package/src/validation/templates.schema.ts +145 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Context,
|
|
3
|
+
Controller,
|
|
4
|
+
Get,
|
|
5
|
+
JSONBody,
|
|
6
|
+
Post,
|
|
7
|
+
type RequestContext,
|
|
8
|
+
} from "@antelopejs/interface-api";
|
|
9
|
+
import { assertValidation } from "@antelopejs/interface-api-util";
|
|
10
|
+
import { AuthUserWithPermission } from "@antelopejs/interface-dms/guards";
|
|
11
|
+
import { getRequestTenantId } from "@antelopejs/interface-dms/request-tenant";
|
|
12
|
+
import type { User } from "@antelopejs/interface-dms/auth/db";
|
|
13
|
+
import { TenantScopedModel } from "@antelopejs/interface-dms/tenant-scoped-model";
|
|
14
|
+
import { API_BASE_PATH } from "../constants";
|
|
15
|
+
import { TemplateModel } from "../db";
|
|
16
|
+
import { MailingSettingsPage } from "../pages/settings/page";
|
|
17
|
+
import { reassignRemovedCategories } from "../services/categories";
|
|
18
|
+
import { getSettings, saveSettings } from "../services/settings";
|
|
19
|
+
import type { MailingSettingsValues } from "../types";
|
|
20
|
+
import { settingsSchema } from "../validation/settings.schema";
|
|
21
|
+
|
|
22
|
+
const INVALID_SETTINGS = "$dms_mailing.errors.invalid_settings";
|
|
23
|
+
|
|
24
|
+
export class MailingSettingsController extends Controller(
|
|
25
|
+
`${API_BASE_PATH}/settings`,
|
|
26
|
+
) {
|
|
27
|
+
@Context()
|
|
28
|
+
declare ctx: RequestContext;
|
|
29
|
+
|
|
30
|
+
@AuthUserWithPermission(MailingSettingsPage)
|
|
31
|
+
declare user: User;
|
|
32
|
+
|
|
33
|
+
@TenantScopedModel(TemplateModel)
|
|
34
|
+
declare templates: TemplateModel;
|
|
35
|
+
|
|
36
|
+
@Get("")
|
|
37
|
+
read(): Promise<MailingSettingsValues> {
|
|
38
|
+
return getSettings(getRequestTenantId(this.ctx));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Post("")
|
|
42
|
+
async write(@JSONBody() body: unknown): Promise<MailingSettingsValues> {
|
|
43
|
+
const values = assertValidation(
|
|
44
|
+
body,
|
|
45
|
+
(value) => settingsSchema.parse(value),
|
|
46
|
+
() => INVALID_SETTINGS,
|
|
47
|
+
);
|
|
48
|
+
const saved = await saveSettings(getRequestTenantId(this.ctx), values);
|
|
49
|
+
await this.dropRemovedCategories(values.categories);
|
|
50
|
+
return saved;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A deleted category must not leave templates pointing at nothing: they fall
|
|
55
|
+
* back to no category.
|
|
56
|
+
*/
|
|
57
|
+
private async dropRemovedCategories(
|
|
58
|
+
categories: MailingSettingsValues["categories"],
|
|
59
|
+
): Promise<void> {
|
|
60
|
+
const templates = await this.templates.getAll();
|
|
61
|
+
const orphaned = reassignRemovedCategories(templates, categories);
|
|
62
|
+
for (const id of orphaned) {
|
|
63
|
+
await this.templates.update(id, { category: "" });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Context,
|
|
3
|
+
Controller,
|
|
4
|
+
Get,
|
|
5
|
+
JSONBody,
|
|
6
|
+
Parameter,
|
|
7
|
+
Post,
|
|
8
|
+
type RequestContext,
|
|
9
|
+
} from "@antelopejs/interface-api";
|
|
10
|
+
import { assert, assertValidation } from "@antelopejs/interface-api-util";
|
|
11
|
+
import { AuthUserWithPermission } from "@antelopejs/interface-dms/guards";
|
|
12
|
+
import { getRequestTenantId } from "@antelopejs/interface-dms/request-tenant";
|
|
13
|
+
import { TenantScopedModel } from "@antelopejs/interface-dms/tenant-scoped-model";
|
|
14
|
+
import type { User } from "@antelopejs/interface-dms/auth/db";
|
|
15
|
+
import {
|
|
16
|
+
API_BASE_PATH,
|
|
17
|
+
HTTP_CONFLICT,
|
|
18
|
+
HTTP_NOT_FOUND,
|
|
19
|
+
HTTP_UNPROCESSABLE,
|
|
20
|
+
} from "../constants";
|
|
21
|
+
import { collectContentVariablePaths, resolveEmail } from "../engine";
|
|
22
|
+
import { type MailingTemplate, TemplateModel } from "../db";
|
|
23
|
+
import { TemplatesPageController } from "../pages/templates";
|
|
24
|
+
import { renderEmailHtml } from "../services/render";
|
|
25
|
+
import { getSettings } from "../services/settings";
|
|
26
|
+
import {
|
|
27
|
+
contentFieldsOf,
|
|
28
|
+
displayName,
|
|
29
|
+
localeContentOf,
|
|
30
|
+
parseContent,
|
|
31
|
+
parseTestData,
|
|
32
|
+
parseVariables,
|
|
33
|
+
pickLocale,
|
|
34
|
+
saveContent,
|
|
35
|
+
} from "../services/templates";
|
|
36
|
+
import type {
|
|
37
|
+
MailingSettingsValues,
|
|
38
|
+
TemplateContent,
|
|
39
|
+
TemplateStatus,
|
|
40
|
+
VariableDefinition,
|
|
41
|
+
} from "../types";
|
|
42
|
+
import {
|
|
43
|
+
duplicateSchema,
|
|
44
|
+
previewSchema,
|
|
45
|
+
templateContentSchema,
|
|
46
|
+
testDataSchema,
|
|
47
|
+
variablesSchema,
|
|
48
|
+
} from "../validation/templates.schema";
|
|
49
|
+
|
|
50
|
+
const NOT_FOUND = "$dms_mailing.errors.template_not_found";
|
|
51
|
+
const DUPLICATE_SLUG = "$dms_mailing.errors.duplicate_slug";
|
|
52
|
+
const INVALID_CONTENT = "$dms_mailing.errors.invalid_content";
|
|
53
|
+
|
|
54
|
+
const STATUS_TRANSITIONS: Record<string, TemplateStatus> = {
|
|
55
|
+
publish: "live",
|
|
56
|
+
unpublish: "draft",
|
|
57
|
+
archive: "archived",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export interface CategoriesResponse {
|
|
61
|
+
categories: MailingSettingsValues["categories"];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface TemplateContentResponse {
|
|
65
|
+
template: MailingTemplate;
|
|
66
|
+
content: TemplateContent;
|
|
67
|
+
variables: VariableDefinition[];
|
|
68
|
+
/** Paths the content actually references, across every locale. */
|
|
69
|
+
detectedVariables: string[];
|
|
70
|
+
testData: Record<string, unknown>;
|
|
71
|
+
fallbackLocale: string;
|
|
72
|
+
categories: MailingSettingsValues["categories"];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class TemplatesController extends Controller(
|
|
76
|
+
`${API_BASE_PATH}/templates`,
|
|
77
|
+
) {
|
|
78
|
+
@Context()
|
|
79
|
+
declare ctx: RequestContext;
|
|
80
|
+
|
|
81
|
+
@AuthUserWithPermission(TemplatesPageController)
|
|
82
|
+
declare user: User;
|
|
83
|
+
|
|
84
|
+
@TenantScopedModel(TemplateModel)
|
|
85
|
+
declare templates: TemplateModel;
|
|
86
|
+
|
|
87
|
+
private get tenantId(): string {
|
|
88
|
+
return getRequestTenantId(this.ctx);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private async requireTemplate(id: string): Promise<MailingTemplate> {
|
|
92
|
+
const template = await this.templates.get(id);
|
|
93
|
+
assert(template, HTTP_NOT_FOUND, NOT_FOUND);
|
|
94
|
+
return template;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The tenant's categories for a category picker. Separate from `/settings`,
|
|
99
|
+
* which is guarded by the settings-manage permission a template editor need
|
|
100
|
+
* not hold.
|
|
101
|
+
*/
|
|
102
|
+
@Get("/categories")
|
|
103
|
+
async categories(): Promise<CategoriesResponse> {
|
|
104
|
+
const settings = await getSettings(this.tenantId);
|
|
105
|
+
return { categories: settings.categories };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Get("/:id/content")
|
|
109
|
+
async content(
|
|
110
|
+
@Parameter("id", "param") id: string,
|
|
111
|
+
): Promise<TemplateContentResponse> {
|
|
112
|
+
const template = await this.requireTemplate(id);
|
|
113
|
+
const settings = await getSettings(this.tenantId);
|
|
114
|
+
const content = parseContent(template);
|
|
115
|
+
return {
|
|
116
|
+
template,
|
|
117
|
+
content,
|
|
118
|
+
variables: parseVariables(template),
|
|
119
|
+
detectedVariables: collectContentVariablePaths(content),
|
|
120
|
+
testData: parseTestData(template),
|
|
121
|
+
fallbackLocale: settings.fallbackLocale,
|
|
122
|
+
categories: settings.categories,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Post("/:id/content")
|
|
127
|
+
async replaceContent(
|
|
128
|
+
@Parameter("id", "param") id: string,
|
|
129
|
+
@JSONBody() body: unknown,
|
|
130
|
+
) {
|
|
131
|
+
const content = assertValidation(
|
|
132
|
+
body,
|
|
133
|
+
(value) =>
|
|
134
|
+
templateContentSchema.parse(
|
|
135
|
+
(value as { content: unknown }).content,
|
|
136
|
+
) as TemplateContent,
|
|
137
|
+
() => INVALID_CONTENT,
|
|
138
|
+
);
|
|
139
|
+
await this.requireTemplate(id);
|
|
140
|
+
await saveContent(this.tenantId, id, content, displayName(this.user));
|
|
141
|
+
return {
|
|
142
|
+
saved: true,
|
|
143
|
+
detectedVariables: collectContentVariablePaths(content),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@Post("/:id/publish")
|
|
148
|
+
publish(@Parameter("id", "param") id: string) {
|
|
149
|
+
return this.transition(id, "publish");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@Post("/:id/unpublish")
|
|
153
|
+
unpublish(@Parameter("id", "param") id: string) {
|
|
154
|
+
return this.transition(id, "unpublish");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@Post("/:id/archive")
|
|
158
|
+
archive(@Parameter("id", "param") id: string) {
|
|
159
|
+
return this.transition(id, "archive");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private async transition(id: string, action: string) {
|
|
163
|
+
const template = await this.requireTemplate(id);
|
|
164
|
+
const status = STATUS_TRANSITIONS[action] as TemplateStatus;
|
|
165
|
+
const publishedAt = status === "live" ? new Date() : template.publishedAt;
|
|
166
|
+
await this.templates.update(id, {
|
|
167
|
+
status,
|
|
168
|
+
publishedAt,
|
|
169
|
+
updatedBy: displayName(this.user),
|
|
170
|
+
});
|
|
171
|
+
return { status };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@Post("/:id/variables")
|
|
175
|
+
async variables(
|
|
176
|
+
@Parameter("id", "param") id: string,
|
|
177
|
+
@JSONBody() body: unknown,
|
|
178
|
+
) {
|
|
179
|
+
const { variables } = assertValidation(body, (value) =>
|
|
180
|
+
variablesSchema.parse(value),
|
|
181
|
+
);
|
|
182
|
+
await this.requireTemplate(id);
|
|
183
|
+
await this.templates.update(id, {
|
|
184
|
+
json_variables: JSON.stringify(variables),
|
|
185
|
+
updatedBy: displayName(this.user),
|
|
186
|
+
});
|
|
187
|
+
return { variables };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@Post("/:id/test-data")
|
|
191
|
+
async testData(
|
|
192
|
+
@Parameter("id", "param") id: string,
|
|
193
|
+
@JSONBody() body: unknown,
|
|
194
|
+
) {
|
|
195
|
+
const { data } = assertValidation(body, (value) =>
|
|
196
|
+
testDataSchema.parse(value),
|
|
197
|
+
);
|
|
198
|
+
await this.requireTemplate(id);
|
|
199
|
+
await this.templates.update(id, { json_test_data: JSON.stringify(data) });
|
|
200
|
+
return { data };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Post("/:id/preview")
|
|
204
|
+
async preview(
|
|
205
|
+
@Parameter("id", "param") id: string,
|
|
206
|
+
@JSONBody() body: unknown,
|
|
207
|
+
) {
|
|
208
|
+
const input = assertValidation(
|
|
209
|
+
body,
|
|
210
|
+
(value) => previewSchema.parse(value),
|
|
211
|
+
() => INVALID_CONTENT,
|
|
212
|
+
);
|
|
213
|
+
const template = await this.requireTemplate(id);
|
|
214
|
+
const content =
|
|
215
|
+
(input.content as TemplateContent | undefined) ?? parseContent(template);
|
|
216
|
+
const settings = await getSettings(this.tenantId);
|
|
217
|
+
const locale = pickLocale(content, input.locale, settings.fallbackLocale);
|
|
218
|
+
const localeContent = localeContentOf(content, locale);
|
|
219
|
+
assert(localeContent, HTTP_UNPROCESSABLE, INVALID_CONTENT);
|
|
220
|
+
const email = resolveEmail(
|
|
221
|
+
localeContent,
|
|
222
|
+
input.data ?? parseTestData(template),
|
|
223
|
+
);
|
|
224
|
+
const html = await renderEmailHtml(email, locale);
|
|
225
|
+
return {
|
|
226
|
+
html,
|
|
227
|
+
subject: email.subject,
|
|
228
|
+
locale,
|
|
229
|
+
missing: email.missing,
|
|
230
|
+
hiddenBlockIds: email.hiddenBlockIds,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@Post("/:id/duplicate")
|
|
235
|
+
async duplicate(
|
|
236
|
+
@Parameter("id", "param") id: string,
|
|
237
|
+
@JSONBody() body: unknown,
|
|
238
|
+
) {
|
|
239
|
+
const { slug, name } = assertValidation(body, (value) =>
|
|
240
|
+
duplicateSchema.parse(value),
|
|
241
|
+
);
|
|
242
|
+
const source = await this.requireTemplate(id);
|
|
243
|
+
const clash = await this.templates.getBySlug(slug);
|
|
244
|
+
assert(!clash, HTTP_CONFLICT, DUPLICATE_SLUG);
|
|
245
|
+
const author = displayName(this.user);
|
|
246
|
+
const [copyId] = await this.templates.insert({
|
|
247
|
+
slug,
|
|
248
|
+
name,
|
|
249
|
+
category: source.category,
|
|
250
|
+
status: "draft",
|
|
251
|
+
...contentFieldsOf(source),
|
|
252
|
+
updatedBy: author,
|
|
253
|
+
});
|
|
254
|
+
return { id: copyId };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { MailingSend, MailingTemplate } from "../db";
|
|
2
|
+
import { PROBLEM_STATUSES } from "../types";
|
|
3
|
+
|
|
4
|
+
export type AttentionTone = "error" | "warning" | "neutral";
|
|
5
|
+
|
|
6
|
+
export interface AttentionItem {
|
|
7
|
+
id: string;
|
|
8
|
+
tone: AttentionTone;
|
|
9
|
+
icon: string;
|
|
10
|
+
title: string;
|
|
11
|
+
description: string;
|
|
12
|
+
to: string;
|
|
13
|
+
params?: Record<string, string | number>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const TEMPLATES_PAGE = "/modules/mailing/templates";
|
|
17
|
+
const SENDS_PAGE = "/modules/mailing/sends";
|
|
18
|
+
const SENDS_PROBLEMS_PAGE = `${SENDS_PAGE}?tab=problems`;
|
|
19
|
+
const STALE_DRAFT_DAYS = 7;
|
|
20
|
+
const DAY_MS = 86_400_000;
|
|
21
|
+
|
|
22
|
+
const isStaleDraft = (template: MailingTemplate, now: number): boolean =>
|
|
23
|
+
template.status === "draft" &&
|
|
24
|
+
!template.publishedAt &&
|
|
25
|
+
now - new Date(template.updatedAt).getTime() > STALE_DRAFT_DAYS * DAY_MS;
|
|
26
|
+
|
|
27
|
+
function problemsItem(sends: MailingSend[]): AttentionItem[] {
|
|
28
|
+
const problems = sends.filter((send) =>
|
|
29
|
+
PROBLEM_STATUSES.includes(send.status),
|
|
30
|
+
);
|
|
31
|
+
if (!problems.length) return [];
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
id: "problem-sends",
|
|
35
|
+
tone: "error",
|
|
36
|
+
icon: "i-ph-warning-octagon",
|
|
37
|
+
title: "$dms_mailing.attention.problem_sends.title",
|
|
38
|
+
description: "$dms_mailing.attention.problem_sends.description",
|
|
39
|
+
to: SENDS_PROBLEMS_PAGE,
|
|
40
|
+
params: { count: problems.length },
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function staleDraftsItem(templates: MailingTemplate[]): AttentionItem[] {
|
|
46
|
+
const stale = templates.filter((template) =>
|
|
47
|
+
isStaleDraft(template, Date.now()),
|
|
48
|
+
);
|
|
49
|
+
if (!stale.length) return [];
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
id: "stale-drafts",
|
|
53
|
+
tone: "neutral",
|
|
54
|
+
icon: "i-ph-pencil-simple",
|
|
55
|
+
title: "$dms_mailing.attention.stale_drafts.title",
|
|
56
|
+
description: "$dms_mailing.attention.stale_drafts.description",
|
|
57
|
+
to: TEMPLATES_PAGE,
|
|
58
|
+
params: { count: stale.length },
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function neverSentItem(
|
|
64
|
+
templates: MailingTemplate[],
|
|
65
|
+
sends: MailingSend[],
|
|
66
|
+
): AttentionItem[] {
|
|
67
|
+
const used = new Set(sends.map((send) => send.templateSlug));
|
|
68
|
+
const unused = templates.filter(
|
|
69
|
+
(template) => template.status === "live" && !used.has(template.slug),
|
|
70
|
+
);
|
|
71
|
+
if (!unused.length) return [];
|
|
72
|
+
return [
|
|
73
|
+
{
|
|
74
|
+
id: "unused-live",
|
|
75
|
+
tone: "warning",
|
|
76
|
+
icon: "i-ph-eye-slash",
|
|
77
|
+
title: "$dms_mailing.attention.unused_live.title",
|
|
78
|
+
description: "$dms_mailing.attention.unused_live.description",
|
|
79
|
+
to: TEMPLATES_PAGE,
|
|
80
|
+
params: { count: unused.length },
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Every send the Overview window holds, split the way the business view counts
|
|
87
|
+
* them: `sends` are the ones behind the figures, `excluded` the test sends the
|
|
88
|
+
* business audience drops.
|
|
89
|
+
*/
|
|
90
|
+
export interface AttentionWindow {
|
|
91
|
+
templates: MailingTemplate[];
|
|
92
|
+
sends: MailingSend[];
|
|
93
|
+
excluded: MailingSend[];
|
|
94
|
+
/** What the configured provider can report; `null` when it is unreachable. */
|
|
95
|
+
tracking: ProviderTracking | null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The provider features the Overview's rates depend on. */
|
|
99
|
+
export interface ProviderTracking {
|
|
100
|
+
name: string;
|
|
101
|
+
openTracking: boolean;
|
|
102
|
+
clickTracking: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function testOnlyWindowItem(window: AttentionWindow): AttentionItem[] {
|
|
106
|
+
if (window.sends.length || !window.excluded.length) return [];
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
id: "test-only-window",
|
|
110
|
+
tone: "neutral",
|
|
111
|
+
icon: "i-ph-flask",
|
|
112
|
+
title: "$dms_mailing.attention.test_only_window.title",
|
|
113
|
+
description: "$dms_mailing.attention.test_only_window.description",
|
|
114
|
+
to: SENDS_PAGE,
|
|
115
|
+
params: { count: window.excluded.length },
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Open and click rates can only move if the provider reports those events. An
|
|
122
|
+
* SMTP provider reports neither, so the rates sit at 0 % forever — which reads
|
|
123
|
+
* as "nobody opened it" rather than "nobody can tell". Say so next to the
|
|
124
|
+
* figures, and only while the window actually shows some.
|
|
125
|
+
*/
|
|
126
|
+
function untrackedRatesItem(window: AttentionWindow): AttentionItem[] {
|
|
127
|
+
const { tracking } = window;
|
|
128
|
+
if (!tracking || !window.sends.length) return [];
|
|
129
|
+
if (tracking.openTracking && tracking.clickTracking) return [];
|
|
130
|
+
return [
|
|
131
|
+
{
|
|
132
|
+
id: "untracked-rates",
|
|
133
|
+
tone: "neutral",
|
|
134
|
+
icon: "i-ph-eye-slash",
|
|
135
|
+
title: "$dms_mailing.attention.untracked_rates.title",
|
|
136
|
+
description: "$dms_mailing.attention.untracked_rates.description",
|
|
137
|
+
to: SENDS_PAGE,
|
|
138
|
+
params: { provider: tracking.name },
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function buildAttentionItems(window: AttentionWindow): AttentionItem[] {
|
|
144
|
+
return [
|
|
145
|
+
...problemsItem(window.sends),
|
|
146
|
+
...testOnlyWindowItem(window),
|
|
147
|
+
...untrackedRatesItem(window),
|
|
148
|
+
...neverSentItem(window.templates, window.sends),
|
|
149
|
+
...staleDraftsItem(window.templates),
|
|
150
|
+
];
|
|
151
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { MailingTemplate } from "../db";
|
|
3
|
+
import type { TemplateCategory } from "../types";
|
|
4
|
+
import { categorySchema } from "../validation/settings.schema";
|
|
5
|
+
|
|
6
|
+
/** Direct API callers may send a JSON string; accept both string and array. */
|
|
7
|
+
const categoriesSchema = z
|
|
8
|
+
.union([z.string(), z.array(categorySchema)])
|
|
9
|
+
.transform((value) => {
|
|
10
|
+
if (typeof value !== "string") return value;
|
|
11
|
+
if (value === "") return [];
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(value) as unknown;
|
|
14
|
+
} catch {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.pipe(z.array(categorySchema));
|
|
19
|
+
|
|
20
|
+
export const CATEGORIES_SCHEMA = categoriesSchema;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reads a category list off a form field or an API body. Never throws on shape:
|
|
24
|
+
* this runs while rendering a settings field.
|
|
25
|
+
*/
|
|
26
|
+
export function parseCategories(raw: unknown): TemplateCategory[] {
|
|
27
|
+
const parsed = categoriesSchema.safeParse(raw ?? []);
|
|
28
|
+
return parsed.success ? parsed.data : [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Ids of the templates whose category is not in `categories` any more. Deleting
|
|
33
|
+
* a category must leave them uncategorised, never pointing at nothing.
|
|
34
|
+
*/
|
|
35
|
+
export function reassignRemovedCategories(
|
|
36
|
+
templates: MailingTemplate[],
|
|
37
|
+
categories: TemplateCategory[],
|
|
38
|
+
): string[] {
|
|
39
|
+
const kept = new Set(categories.map((category) => category.id));
|
|
40
|
+
return templates
|
|
41
|
+
.filter((template) => template.category && !kept.has(template.category))
|
|
42
|
+
.map((template) => template._id);
|
|
43
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { GetModel } from "@antelopejs/interface-database-decorators";
|
|
3
|
+
import {
|
|
4
|
+
emitEmailEvent,
|
|
5
|
+
type EmailEventPayload,
|
|
6
|
+
} from "../automation/email-event-trigger";
|
|
7
|
+
import { type MailingSend, SendEventModel, SendModel } from "../db";
|
|
8
|
+
import type { EmailEvent } from "@antelopejs/interface-dms-mailing";
|
|
9
|
+
import { publishSendUpdated } from "../realtime";
|
|
10
|
+
import type { SendEventType, SendStatus } from "../types";
|
|
11
|
+
import { notifyBounce } from "./notify";
|
|
12
|
+
|
|
13
|
+
export interface SendCounters {
|
|
14
|
+
status: SendStatus;
|
|
15
|
+
opens: number;
|
|
16
|
+
clicks: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type CounterKey = keyof Pick<SendCounters, "opens" | "clicks">;
|
|
20
|
+
|
|
21
|
+
const RANK: Record<SendStatus, number> = {
|
|
22
|
+
queued: 0,
|
|
23
|
+
sent: 1,
|
|
24
|
+
delivered: 2,
|
|
25
|
+
opened: 3,
|
|
26
|
+
clicked: 4,
|
|
27
|
+
unsubscribed: 5,
|
|
28
|
+
spam: 6,
|
|
29
|
+
bounced: 7,
|
|
30
|
+
failed: 7,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const COUNTERS: Partial<Record<SendEventType, CounterKey>> = {
|
|
34
|
+
opened: "opens",
|
|
35
|
+
clicked: "clicks",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const MAX_ACTIVITY_ATTEMPTS = 5;
|
|
39
|
+
|
|
40
|
+
export function applyEvent(
|
|
41
|
+
current: SendCounters,
|
|
42
|
+
type: SendEventType,
|
|
43
|
+
): SendCounters {
|
|
44
|
+
const counter = COUNTERS[type];
|
|
45
|
+
const next: SendCounters = { ...current };
|
|
46
|
+
if (counter) next[counter] = current[counter] + 1;
|
|
47
|
+
if (RANK[type] > RANK[current.status]) next.status = type;
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function publishEmailEvent(payload: EmailEventPayload): Promise<void> {
|
|
52
|
+
emitEmailEvent(payload);
|
|
53
|
+
publishSendUpdated(payload.sendId);
|
|
54
|
+
await notifyBounce(payload.tenantId, payload);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function acceptEmailActivity(
|
|
58
|
+
tenantId: string,
|
|
59
|
+
event: EmailEvent,
|
|
60
|
+
): Promise<MailingSend | undefined> {
|
|
61
|
+
const sends = GetModel(SendModel, tenantId);
|
|
62
|
+
for (let attempt = 0; attempt < MAX_ACTIVITY_ATTEMPTS; attempt++) {
|
|
63
|
+
const send = await sends.getByProviderMessageId(event.messageId);
|
|
64
|
+
if (!send || send.isRetiring) return undefined;
|
|
65
|
+
const accepted = await sends.recordActivity(send, {
|
|
66
|
+
...applyEvent(
|
|
67
|
+
{ status: send.status, opens: send.opens, clicks: send.clicks },
|
|
68
|
+
event.type,
|
|
69
|
+
),
|
|
70
|
+
lastEventAt: event.at ?? new Date(),
|
|
71
|
+
provider: event.provider,
|
|
72
|
+
});
|
|
73
|
+
if (accepted) return send;
|
|
74
|
+
}
|
|
75
|
+
throw new Error("Mailing activity conflicted repeatedly; retry the webhook");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function recordEmailEvent(
|
|
79
|
+
tenantId: string,
|
|
80
|
+
event: EmailEvent,
|
|
81
|
+
): Promise<boolean> {
|
|
82
|
+
const send = await acceptEmailActivity(tenantId, event);
|
|
83
|
+
if (!send) return false;
|
|
84
|
+
const at = event.at ?? new Date();
|
|
85
|
+
const recorded = await GetModel(SendEventModel, tenantId).insertForActiveSend(
|
|
86
|
+
{
|
|
87
|
+
sendId: send._id,
|
|
88
|
+
type: event.type,
|
|
89
|
+
at,
|
|
90
|
+
json_details: JSON.stringify(event.details ?? {}),
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
if (!recorded) return false;
|
|
94
|
+
await publishEmailEvent({
|
|
95
|
+
tenantId,
|
|
96
|
+
sendId: send._id,
|
|
97
|
+
templateSlug: send.templateSlug,
|
|
98
|
+
type: event.type,
|
|
99
|
+
recipientEmail: send.recipientEmail,
|
|
100
|
+
});
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether a webhook request carries the tenant's secret.
|
|
106
|
+
*
|
|
107
|
+
* Fails closed on a blank stored secret: the event endpoint is the module's
|
|
108
|
+
* only unauthenticated route, so "no secret configured" must refuse everything
|
|
109
|
+
* rather than accept an empty header. The comparison itself is constant-time;
|
|
110
|
+
* only the length is observable.
|
|
111
|
+
*/
|
|
112
|
+
export function webhookSecretMatches(
|
|
113
|
+
provided: string | undefined,
|
|
114
|
+
stored: string,
|
|
115
|
+
): boolean {
|
|
116
|
+
if (!stored || !provided) return false;
|
|
117
|
+
const left = Buffer.from(provided);
|
|
118
|
+
const right = Buffer.from(stored);
|
|
119
|
+
if (left.length !== right.length) return false;
|
|
120
|
+
return timingSafeEqual(left, right);
|
|
121
|
+
}
|