@jini-ai/user-management 0.7.3-next.2 → 0.7.3-next.3
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/README.md +55 -2
- package/dist/admin/adapters/memory.js +4 -4
- package/dist/admin-http/auth/auth-request.d.ts +112 -0
- package/dist/admin-http/auth/auth-request.js +32 -0
- package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
- package/dist/admin-http/auth/boot-redemption.js +17 -0
- package/dist/admin-http/auth/boot-session.d.ts +30 -0
- package/dist/admin-http/auth/boot-session.js +40 -0
- package/dist/admin-http/auth/current-user.d.ts +28 -0
- package/dist/admin-http/auth/current-user.js +34 -0
- package/dist/admin-http/auth/index.d.ts +17 -0
- package/dist/admin-http/auth/index.js +9 -0
- package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
- package/dist/admin-http/auth/local-boot-session.js +30 -0
- package/dist/admin-http/auth/logout.d.ts +10 -0
- package/dist/admin-http/auth/logout.js +17 -0
- package/dist/admin-http/auth/mfa-login.d.ts +30 -0
- package/dist/admin-http/auth/mfa-login.js +43 -0
- package/dist/admin-http/auth/password-login.d.ts +35 -0
- package/dist/admin-http/auth/password-login.js +52 -0
- package/dist/admin-http/auth/password-status.d.ts +34 -0
- package/dist/admin-http/auth/password-status.js +42 -0
- package/dist/admin-http/http/api-keys.d.ts +45 -0
- package/dist/admin-http/http/api-keys.js +28 -0
- package/dist/admin-http/http/users.d.ts +71 -0
- package/dist/admin-http/http/users.js +42 -0
- package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
- package/dist/admin-http/owner/mfa-deps.js +26 -0
- package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
- package/dist/admin-http/owner/mfa-routes.js +105 -0
- package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
- package/dist/admin-http/owner/passkey-admission.js +23 -0
- package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
- package/dist/admin-http/owner/passkey-route-deps.js +33 -0
- package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
- package/dist/admin-http/owner/passkey-routes.js +98 -0
- package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
- package/dist/admin-http/owner/recovery-routes.js +112 -0
- package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
- package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
- package/dist/admin-http/routes/api-keys/issue.js +38 -0
- package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/revoke.js +31 -0
- package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
- package/dist/admin-http/routes/api-keys/shared.js +38 -0
- package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
- package/dist/admin-http/routes/users/access-shared.js +85 -0
- package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
- package/dist/admin-http/routes/users/assign-role.js +30 -0
- package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/attach-policy.js +31 -0
- package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
- package/dist/admin-http/routes/users/create-policy.js +28 -0
- package/dist/admin-http/routes/users/create-role.d.ts +15 -0
- package/dist/admin-http/routes/users/create-role.js +21 -0
- package/dist/admin-http/routes/users/create.d.ts +32 -0
- package/dist/admin-http/routes/users/create.js +67 -0
- package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-policy.js +24 -0
- package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-role.js +24 -0
- package/dist/admin-http/routes/users/delete.d.ts +35 -0
- package/dist/admin-http/routes/users/delete.js +35 -0
- package/dist/admin-http/routes/users/disable.d.ts +31 -0
- package/dist/admin-http/routes/users/disable.js +38 -0
- package/dist/admin-http/routes/users/enable.d.ts +32 -0
- package/dist/admin-http/routes/users/enable.js +45 -0
- package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
- package/dist/admin-http/routes/users/list-policies.js +20 -0
- package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
- package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
- package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
- package/dist/admin-http/routes/users/list-roles.js +20 -0
- package/dist/admin-http/routes/users/list.d.ts +40 -0
- package/dist/admin-http/routes/users/list.js +82 -0
- package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
- package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
- package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
- package/dist/admin-http/routes/users/reset-password.js +52 -0
- package/dist/admin-http/routes/users/shared.d.ts +124 -0
- package/dist/admin-http/routes/users/shared.js +93 -0
- package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/update-policy.js +30 -0
- package/dist/admin-http/routes/users/update-role.d.ts +23 -0
- package/dist/admin-http/routes/users/update-role.js +29 -0
- package/dist/admin-http/routes/users/update.d.ts +35 -0
- package/dist/admin-http/routes/users/update.js +78 -0
- package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
- package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
- package/dist/core/ports.d.ts +22 -3
- package/dist/core/types.d.ts +17 -5
- package/dist/core/types.js +12 -0
- package/dist/identity/api-key-secret.d.ts +68 -0
- package/dist/identity/api-key-secret.js +229 -0
- package/dist/identity/api-key-service.d.ts +144 -0
- package/dist/identity/api-key-service.js +389 -0
- package/dist/identity/api-key-types.d.ts +79 -0
- package/dist/identity/api-key-types.js +2 -0
- package/dist/identity/boot-session-token.d.ts +18 -0
- package/dist/identity/boot-session-token.js +92 -0
- package/dist/identity/builtin-role-grants.d.ts +120 -0
- package/dist/identity/builtin-role-grants.js +88 -0
- package/dist/identity/delete-user-service.d.ts +195 -0
- package/dist/identity/delete-user-service.js +275 -0
- package/dist/identity/owner-reset-env.d.ts +37 -0
- package/dist/identity/owner-reset-env.js +38 -0
- package/dist/identity/permission-grants.d.ts +31 -0
- package/dist/identity/permission-grants.js +12 -0
- package/dist/identity/permission-list-tool.d.ts +35 -0
- package/dist/identity/permission-list-tool.js +47 -0
- package/dist/identity/repo.authentication.d.ts +57 -0
- package/dist/identity/repo.authentication.js +153 -0
- package/dist/identity/repo.authorization.d.ts +82 -0
- package/dist/identity/repo.authorization.js +203 -0
- package/dist/identity/repo.d.ts +87 -0
- package/dist/identity/repo.js +167 -0
- package/dist/identity/repo.memory.d.ts +31 -0
- package/dist/identity/repo.memory.js +37 -0
- package/dist/identity/role-manage-permission.d.ts +34 -0
- package/dist/identity/role-manage-permission.js +39 -0
- package/dist/identity/site-key-permission.d.ts +66 -0
- package/dist/identity/site-key-permission.js +92 -0
- package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
- package/dist/identity/sql/kernel-user-purge.js +34 -0
- package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
- package/dist/identity/sql/kernel-user-trash-store.js +41 -0
- package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
- package/dist/identity/sql/user-trash-adapter.js +124 -0
- package/dist/identity/tool-registrations.d.ts +100 -0
- package/dist/identity/tool-registrations.js +257 -0
- package/dist/identity/user-manage-permission.d.ts +8 -0
- package/dist/identity/user-manage-permission.js +8 -0
- package/dist/identity/user-purge-types.d.ts +85 -0
- package/dist/identity/user-purge-types.js +17 -0
- package/dist/identity/user-purge.d.ts +69 -0
- package/dist/identity/user-purge.js +46 -0
- package/dist/identity/username-change-ports.d.ts +15 -0
- package/dist/identity/username-change-ports.js +22 -0
- package/dist/mail/site/capture-clear.d.ts +58 -0
- package/dist/mail/site/capture-clear.js +21 -0
- package/dist/mail/status/agent-tools.d.ts +65 -0
- package/dist/mail/status/agent-tools.js +22 -0
- package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
- package/dist/mail/status/delivery-agent-tools.js +63 -0
- package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
- package/dist/mail/status/delivery-tool-registrations.js +110 -0
- package/dist/mail/status/domain-deps.d.ts +25 -0
- package/dist/mail/status/domain-deps.js +23 -0
- package/dist/mail/status/permissions.d.ts +43 -0
- package/dist/mail/status/permissions.js +45 -0
- package/dist/mail/status/provider-agent-tools.d.ts +38 -0
- package/dist/mail/status/provider-agent-tools.js +17 -0
- package/dist/mail/status/provider-operations.d.ts +166 -0
- package/dist/mail/status/provider-operations.js +121 -0
- package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
- package/dist/mail/status/provider-tool-registrations.js +106 -0
- package/dist/mail/status/tool-registrations.d.ts +152 -0
- package/dist/mail/status/tool-registrations.js +112 -0
- package/dist/member-login/credentials.d.ts +40 -0
- package/dist/member-login/credentials.js +26 -0
- package/dist/member-login/link-service.d.ts +66 -0
- package/dist/member-login/link-service.js +141 -0
- package/dist/member-login/oidc-login.d.ts +132 -0
- package/dist/member-login/oidc-login.js +206 -0
- package/dist/member-login/oidc-request.d.ts +80 -0
- package/dist/member-login/oidc-request.js +86 -0
- package/dist/member-login/providers.d.ts +79 -0
- package/dist/member-login/providers.js +41 -0
- package/dist/member-login/ready-providers.d.ts +17 -0
- package/dist/member-login/ready-providers.js +11 -0
- package/dist/member-login/unlink-identity.d.ts +26 -0
- package/dist/member-login/unlink-identity.js +59 -0
- package/dist/members/access-resolver.d.ts +107 -0
- package/dist/members/access-resolver.js +231 -0
- package/dist/members/agent-tools.d.ts +14 -0
- package/dist/members/agent-tools.js +139 -0
- package/dist/members/auth-mail.d.ts +27 -0
- package/dist/members/auth-mail.js +21 -0
- package/dist/members/capability-card.d.ts +18 -0
- package/dist/members/capability-card.js +27 -0
- package/dist/members/consent-service.d.ts +115 -0
- package/dist/members/consent-service.js +179 -0
- package/dist/members/member-admin-writes.d.ts +73 -0
- package/dist/members/member-admin-writes.js +149 -0
- package/dist/members/member-challenge-request.d.ts +59 -0
- package/dist/members/member-challenge-request.js +145 -0
- package/dist/members/member-challenge.d.ts +37 -0
- package/dist/members/member-challenge.js +84 -0
- package/dist/members/member-credentials.d.ts +35 -0
- package/dist/members/member-credentials.js +57 -0
- package/dist/members/member-sign-in.d.ts +44 -0
- package/dist/members/member-sign-in.js +130 -0
- package/dist/members/member-validation.d.ts +5 -0
- package/dist/members/member-validation.js +13 -0
- package/dist/members/password-auth.d.ts +55 -0
- package/dist/members/password-auth.js +177 -0
- package/dist/members/ports.d.ts +455 -0
- package/dist/members/ports.js +21 -0
- package/dist/members/public-member-auth-response.d.ts +68 -0
- package/dist/members/public-member-auth-response.js +45 -0
- package/dist/members/public-member-response.d.ts +25 -0
- package/dist/members/public-member-response.js +15 -0
- package/dist/members/repo.d.ts +199 -0
- package/dist/members/repo.js +324 -0
- package/dist/members/repo.memory.d.ts +276 -0
- package/dist/members/repo.memory.js +395 -0
- package/dist/members/repo.rows.d.ts +153 -0
- package/dist/members/repo.rows.js +250 -0
- package/dist/members/repo.sessions.d.ts +80 -0
- package/dist/members/repo.sessions.js +166 -0
- package/dist/members/repo.sql.d.ts +9 -0
- package/dist/members/repo.sql.js +11 -0
- package/dist/members/subscriber-directory.d.ts +85 -0
- package/dist/members/subscriber-directory.js +70 -0
- package/dist/members/tool-registrations.d.ts +143 -0
- package/dist/members/tool-registrations.js +247 -0
- package/dist/members/trash-member.d.ts +24 -0
- package/dist/members/trash-member.js +24 -0
- package/dist/members/types.d.ts +321 -0
- package/dist/members/types.js +34 -0
- package/dist/members/write-service.d.ts +17 -0
- package/dist/members/write-service.js +15 -0
- package/dist/newsletter/agent-tools.d.ts +20 -0
- package/dist/newsletter/agent-tools.js +236 -0
- package/dist/newsletter/campaign-write-service.d.ts +92 -0
- package/dist/newsletter/campaign-write-service.js +190 -0
- package/dist/newsletter/campaign.d.ts +53 -0
- package/dist/newsletter/campaign.js +95 -0
- package/dist/newsletter/confirmation.d.ts +75 -0
- package/dist/newsletter/confirmation.js +142 -0
- package/dist/newsletter/data-module-manifest.d.ts +68 -0
- package/dist/newsletter/data-module-manifest.js +126 -0
- package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
- package/dist/newsletter/delivery/tool-registrations.js +229 -0
- package/dist/newsletter/errors.d.ts +93 -0
- package/dist/newsletter/errors.js +93 -0
- package/dist/newsletter/hooks.d.ts +59 -0
- package/dist/newsletter/hooks.js +49 -0
- package/dist/newsletter/http-error-responses.d.ts +17 -0
- package/dist/newsletter/http-error-responses.js +96 -0
- package/dist/newsletter/launch-gate.d.ts +62 -0
- package/dist/newsletter/launch-gate.js +29 -0
- package/dist/newsletter/lists.d.ts +60 -0
- package/dist/newsletter/lists.js +83 -0
- package/dist/newsletter/ports.d.ts +278 -0
- package/dist/newsletter/ports.js +2 -0
- package/dist/newsletter/repo-sends.d.ts +82 -0
- package/dist/newsletter/repo-sends.js +178 -0
- package/dist/newsletter/repo-subscribers.d.ts +82 -0
- package/dist/newsletter/repo-subscribers.js +193 -0
- package/dist/newsletter/repo.d.ts +61 -0
- package/dist/newsletter/repo.js +147 -0
- package/dist/newsletter/repo.memory.d.ts +201 -0
- package/dist/newsletter/repo.memory.js +250 -0
- package/dist/newsletter/repo.rows.d.ts +221 -0
- package/dist/newsletter/repo.rows.js +260 -0
- package/dist/newsletter/send-pipeline.d.ts +236 -0
- package/dist/newsletter/send-pipeline.js +514 -0
- package/dist/newsletter/subscriptions.d.ts +87 -0
- package/dist/newsletter/subscriptions.js +119 -0
- package/dist/newsletter/tool-registrations.d.ts +89 -0
- package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
- package/dist/newsletter/tool-registrations.deps.js +9 -0
- package/dist/newsletter/tool-registrations.js +133 -0
- package/dist/newsletter/tool-registrations.read.d.ts +76 -0
- package/dist/newsletter/tool-registrations.read.js +140 -0
- package/dist/newsletter/tool-registrations.write.d.ts +54 -0
- package/dist/newsletter/tool-registrations.write.js +229 -0
- package/dist/newsletter/types.d.ts +279 -0
- package/dist/newsletter/types.js +23 -0
- package/dist/newsletter/unsubscribe.d.ts +41 -0
- package/dist/newsletter/unsubscribe.js +100 -0
- package/dist/project-keys/attached-vault.d.ts +23 -0
- package/dist/project-keys/attached-vault.js +65 -0
- package/dist/project-keys/create-vault.d.ts +17 -0
- package/dist/project-keys/create-vault.js +29 -0
- package/dist/project-keys/service.d.ts +133 -0
- package/dist/project-keys/service.js +128 -0
- package/dist/project-keys/site-references.d.ts +30 -0
- package/dist/project-keys/site-references.js +63 -0
- package/dist/project-keys/site-sealer.d.ts +28 -0
- package/dist/project-keys/site-sealer.js +64 -0
- package/dist/project-keys/sql/attachments.d.ts +33 -0
- package/dist/project-keys/sql/attachments.js +55 -0
- package/dist/project-keys/tools.d.ts +86 -0
- package/dist/project-keys/tools.js +66 -0
- package/dist/public-http/routes/mail/feedback.d.ts +44 -0
- package/dist/public-http/routes/mail/feedback.js +17 -0
- package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
- package/dist/public-http/routes/newsletter/confirm.js +33 -0
- package/dist/public-http/routes/newsletter/page.d.ts +29 -0
- package/dist/public-http/routes/newsletter/page.js +34 -0
- package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
- package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
- package/dist/react/auth/Passkeys.d.ts +2 -34
- package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
- package/dist/react/auth/RecoveryCodesCard.js +56 -0
- package/dist/react/auth/TotpSettings.d.ts +2 -23
- package/dist/react/auth/local-owner-signin.d.ts +40 -0
- package/dist/react/auth/local-owner-signin.js +25 -0
- package/dist/react/auth/owner-mfa-api.d.ts +10 -0
- package/dist/react/auth/owner-mfa-api.js +17 -0
- package/dist/react/auth/owner-passkey-api.d.ts +11 -0
- package/dist/react/auth/owner-passkey-api.js +17 -0
- package/dist/react/auth/owner-recovery-api.d.ts +51 -0
- package/dist/react/auth/owner-recovery-api.js +29 -0
- package/dist/react/auth/owner-request.d.ts +7 -0
- package/dist/react/auth/owner-request.js +2 -0
- package/dist/react/index.d.ts +10 -0
- package/dist/react/index.js +6 -0
- package/dist/react/mail/Email.d.ts +20 -0
- package/dist/react/mail/Email.js +143 -0
- package/dist/react/mail/EmailProviderTab.d.ts +34 -0
- package/dist/react/mail/EmailProviderTab.js +132 -0
- package/dist/react/mail/EmailSegments.d.ts +24 -0
- package/dist/react/mail/EmailSegments.js +15 -0
- package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
- package/dist/react/mail/EmailTemplateEditor.js +116 -0
- package/dist/react/mail/email-view.types.d.ts +236 -0
- package/dist/react/mail/email-view.types.js +2 -0
- package/dist/react/members/Members.d.ts +5 -3
- package/dist/react/members/Members.js +3 -3
- package/dist/react/members/api/members-api.d.ts +37 -0
- package/dist/react/members/api/members-api.js +16 -0
- package/dist/react/members/hooks/use-members.hooks.js +2 -1
- package/dist/react/members/members-i18n.d.ts +23 -0
- package/dist/react/members/members-i18n.js +25 -0
- package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-a.js +294 -0
- package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-b.js +265 -0
- package/dist/react/models.d.ts +1 -49
- package/dist/react/ports.d.ts +3 -143
- package/dist/react/roles/api/roles-api.d.ts +74 -0
- package/dist/react/roles/api/roles-api.js +22 -0
- package/dist/react/testing.js +18 -9
- package/dist/react/users/UsersPanel.d.ts +30 -0
- package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
- package/dist/react/users/UsersPanel.hooks.js +9 -0
- package/dist/react/users/UsersPanel.js +9 -0
- package/dist/react/users/api/users-api.d.ts +65 -0
- package/dist/react/users/api/users-api.js +46 -0
- package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
- package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
- package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
- package/dist/react/users/password-reset-notice.d.ts +8 -0
- package/dist/react/users/password-reset-notice.js +36 -0
- package/dist/server/admin-crud-service.d.ts +4 -10
- package/dist/server/admin-crud-service.js +20 -6
- package/dist/server/agent-tool-registrations.js +20 -5
- package/dist/server/agent-tools.js +16 -3
- package/dist/server/auth-challenge.d.ts +1 -1
- package/dist/server/auth-service.js +2 -1
- package/dist/server/grant-service.d.ts +1 -0
- package/dist/server/grant-service.js +7 -4
- package/dist/server/mfa/passkey-service.d.ts +2 -2
- package/dist/server/mfa/passkey-service.js +1 -1
- package/dist/server/mfa/service.js +6 -4
- package/dist/server/repo.memory.d.ts +30 -2
- package/dist/server/repo.memory.js +58 -4
- package/dist/server/seed.js +3 -3
- package/dist/server/sql/assignments.d.ts +90 -0
- package/dist/server/sql/assignments.js +128 -0
- package/dist/server/sql/index.d.ts +6 -0
- package/dist/server/sql/index.js +5 -0
- package/dist/server/sql/kernel.d.ts +9 -0
- package/dist/server/sql/kernel.js +2 -0
- package/dist/server/sql/mfa.d.ts +36 -0
- package/dist/server/sql/mfa.js +51 -0
- package/dist/server/sql/passkeys.d.ts +25 -0
- package/dist/server/sql/passkeys.js +33 -0
- package/dist/server/sql/recovery-codes.d.ts +22 -0
- package/dist/server/sql/recovery-codes.js +32 -0
- package/package.json +909 -11
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { describeErrorForLog } from "@jini-ai/core/model-facing-tool-errors";
|
|
2
|
+
/**
|
|
3
|
+
* @file Newsletter's half of ADR-049 Decision 4 (ADR-PIPE-011/SPEC-011): maps `agent-tools.ts`'s
|
|
4
|
+
* catalog entries onto existing campaign/list/subscription services as ToolRegistrations.
|
|
5
|
+
* Delivery operations are contributed separately from delivery/tool-registrations.ts; bulk import is absent.
|
|
6
|
+
*
|
|
7
|
+
* Authorization shape: `@jini-ai/user-management/newsletter/http-error-responses`'s consumers (the admin route specs in Jini's
|
|
8
|
+
* `@jini-ai/cms/admin-http/routes/newsletter/*`) record that "none of Newsletter's domain functions call authorize() ...
|
|
9
|
+
* every admin route therefore asks for its own permission as its first step". Every handler here does the same via
|
|
10
|
+
* the kit's `requireToolPermission` — ADR-021 §2's single evaluation, located where the real route
|
|
11
|
+
* locates it.
|
|
12
|
+
*/
|
|
13
|
+
import { requireInputRecord, requireString } from "@jini-ai/core";
|
|
14
|
+
import { adaptLegacyAuthorize, requireToolPermission } from "@jini-ai/core";
|
|
15
|
+
import { cancelCampaign, saveCampaign } from "@jini-ai/user-management/newsletter/campaign-write-service";
|
|
16
|
+
import { issueConfirmationToken } from "@jini-ai/user-management/newsletter/confirmation";
|
|
17
|
+
import { NewsletterCampaignNotFoundError, NewsletterSubscriptionNotFoundError } from "@jini-ai/user-management/newsletter/errors";
|
|
18
|
+
import { archiveList, saveList } from "@jini-ai/user-management/newsletter/lists";
|
|
19
|
+
import { pauseCampaign } from "@jini-ai/user-management/newsletter/send-pipeline";
|
|
20
|
+
import { saveSubscription, unsubscribeSubscription } from "@jini-ai/user-management/newsletter/subscriptions";
|
|
21
|
+
import { toNewsletterSendPipelineDeps } from "./tool-registrations.deps.js";
|
|
22
|
+
import { toCampaignToolView, toListToolView, toSubscriptionToolView } from "./tool-registrations.read.js";
|
|
23
|
+
/**
|
|
24
|
+
* Assembles `campaign-write-service.ts`'s deps bundle from {@link NewsletterToolDeps} — a local
|
|
25
|
+
* duplicate of `host src/server/inbound/admin-http/routes/newsletter/deps.ts`'s `toCampaignWriteServiceDeps` rather than
|
|
26
|
+
* an import of it, for the same reason `features/settings/tool-registrations.ts`'s header gives for
|
|
27
|
+
* duplicating `toWriteServiceDeps`: importing from the HTTP admin layer would invert this codebase's
|
|
28
|
+
* ports/adapters direction. Each `to*Deps` mapper below carries the identical rationale.
|
|
29
|
+
*/
|
|
30
|
+
export function toCampaignWriteServiceDeps(deps) {
|
|
31
|
+
return {
|
|
32
|
+
campaignRepo: deps.newsletterCampaignRepo,
|
|
33
|
+
listRepo: deps.newsletterListRepo,
|
|
34
|
+
clock: deps.clock,
|
|
35
|
+
ids: deps.idGen,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Assembles `lists.ts`'s deps bundle — the local twin of `toCampaignWriteServiceDeps` above. */
|
|
39
|
+
export function toListsDeps(deps) {
|
|
40
|
+
return { listRepo: deps.newsletterListRepo, clock: deps.clock, ids: deps.idGen };
|
|
41
|
+
}
|
|
42
|
+
/** Assembles `subscriptions.ts`'s `unsubscribeSubscription` deps bundle — the local twin of
|
|
43
|
+
* `toCampaignWriteServiceDeps` above. */
|
|
44
|
+
export function toUnsubscribeSubscriptionDeps(deps) {
|
|
45
|
+
return {
|
|
46
|
+
subscriptionRepo: deps.newsletterSubscriptionRepo,
|
|
47
|
+
consentCapability: deps.membersConsentCapability,
|
|
48
|
+
clock: deps.clock,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export async function resendPendingSubscriptionConfirmation({ deps, subscriptionId, signal }, _options = {}) {
|
|
52
|
+
try {
|
|
53
|
+
const subscription = await deps.newsletterSubscriptionRepo.findById({ workspaceId: deps.workspaceId, id: subscriptionId });
|
|
54
|
+
// Constant acknowledgement for missing subscriptions, missing contacts and non-pending records.
|
|
55
|
+
if (!subscription || subscription.status !== "pending")
|
|
56
|
+
return { delivered: true, mailDeliveryAvailable: true };
|
|
57
|
+
const contact = await deps.newsletterSubscriberDirectory.getContact({ workspaceId: deps.workspaceId, subscriberId: subscription.subscriberId });
|
|
58
|
+
if (signal.aborted)
|
|
59
|
+
return { confirmed: false, reason: "abandoned", delivered: false, mailDeliveryAvailable: true };
|
|
60
|
+
if (contact) {
|
|
61
|
+
await issueConfirmationToken({
|
|
62
|
+
deps: deps.buildConfirmationDeps({ deps }),
|
|
63
|
+
input: { workspaceId: deps.workspaceId, subscriptionId: subscription.id, recipientEmail: contact.email },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
let errorDiagnostic = "[diagnostic unavailable]";
|
|
69
|
+
try {
|
|
70
|
+
errorDiagnostic = describeErrorForLog({ err: error });
|
|
71
|
+
}
|
|
72
|
+
catch { /* Keep the original failure path if diagnostics fail. */ }
|
|
73
|
+
// A contact-specific failure must not turn this acknowledgement into an enumeration oracle.
|
|
74
|
+
// Keep diagnostics free of addresses, tokens and provider endpoints.
|
|
75
|
+
console.error("[newsletter] confirmation request could not be processed; inspect mail configuration", errorDiagnostic);
|
|
76
|
+
}
|
|
77
|
+
return { delivered: true, mailDeliveryAvailable: true };
|
|
78
|
+
}
|
|
79
|
+
export function createNewsletterCreateCampaignHandler(deps) {
|
|
80
|
+
return async (ctx) => {
|
|
81
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
82
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.campaign.compose" }, { entityType: "newsletter_campaign" });
|
|
83
|
+
await deps.newsletterReady;
|
|
84
|
+
ctx.signal.throwIfAborted();
|
|
85
|
+
const { campaign } = await saveCampaign({
|
|
86
|
+
deps: toCampaignWriteServiceDeps(deps),
|
|
87
|
+
input: {
|
|
88
|
+
workspaceId: deps.workspaceId,
|
|
89
|
+
actorId: ctx.principal.id,
|
|
90
|
+
// Recorded at write time so the agent-pause hold can tell this campaign from an owner-made one.
|
|
91
|
+
creatorKind: "agent",
|
|
92
|
+
fields: {
|
|
93
|
+
subject: requireString({ input, key: "subject" }),
|
|
94
|
+
preheader: typeof input.preheader === "string" ? input.preheader : null,
|
|
95
|
+
fromName: requireString({ input, key: "fromName" }),
|
|
96
|
+
fromEmail: requireString({ input, key: "fromEmail" }),
|
|
97
|
+
replyTo: requireString({ input, key: "replyTo" }),
|
|
98
|
+
listId: requireString({ input, key: "listId" }),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
return { campaign: toCampaignToolView(campaign) };
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function createNewsletterUpdateCampaignHandler(deps) {
|
|
106
|
+
return async (ctx) => {
|
|
107
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
108
|
+
const campaignId = requireString({ input, key: "campaignId" });
|
|
109
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.campaign.compose" }, { entityType: "newsletter_campaign" });
|
|
110
|
+
await deps.newsletterReady;
|
|
111
|
+
const existing = await deps.newsletterCampaignRepo.findById({ workspaceId: deps.workspaceId, id: campaignId });
|
|
112
|
+
if (!existing)
|
|
113
|
+
throw new NewsletterCampaignNotFoundError(`campaign ${campaignId} was not found`);
|
|
114
|
+
ctx.signal.throwIfAborted();
|
|
115
|
+
const { campaign } = await saveCampaign({
|
|
116
|
+
deps: toCampaignWriteServiceDeps(deps),
|
|
117
|
+
input: {
|
|
118
|
+
workspaceId: deps.workspaceId,
|
|
119
|
+
id: campaignId,
|
|
120
|
+
actorId: ctx.principal.id,
|
|
121
|
+
fields: {
|
|
122
|
+
subject: typeof input.subject === "string" ? input.subject : existing.subject,
|
|
123
|
+
preheader: input.preheader === null || typeof input.preheader === "string" ? input.preheader : existing.preheader,
|
|
124
|
+
fromName: typeof input.fromName === "string" ? input.fromName : existing.fromName,
|
|
125
|
+
fromEmail: typeof input.fromEmail === "string" ? input.fromEmail : existing.fromEmail,
|
|
126
|
+
replyTo: typeof input.replyTo === "string" ? input.replyTo : existing.replyTo,
|
|
127
|
+
listId: typeof input.listId === "string" ? input.listId : existing.listId,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
return { campaign: toCampaignToolView(campaign) };
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export function createNewsletterCancelCampaignHandler(deps) {
|
|
135
|
+
return async (ctx) => {
|
|
136
|
+
const campaignId = requireString({ input: requireInputRecord({ input: ctx.input }), key: "campaignId" });
|
|
137
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.campaign.compose" }, { entityType: "newsletter_campaign" });
|
|
138
|
+
await deps.newsletterReady;
|
|
139
|
+
ctx.signal.throwIfAborted();
|
|
140
|
+
const { campaign } = await cancelCampaign({
|
|
141
|
+
deps: toCampaignWriteServiceDeps(deps),
|
|
142
|
+
input: { workspaceId: deps.workspaceId, id: campaignId, actorId: ctx.principal.id },
|
|
143
|
+
});
|
|
144
|
+
return { campaign: toCampaignToolView(campaign) };
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export function createNewsletterPauseCampaignHandler(deps) {
|
|
148
|
+
return async (ctx) => {
|
|
149
|
+
const campaignId = requireString({ input: requireInputRecord({ input: ctx.input }), key: "campaignId" });
|
|
150
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.campaign.send" }, { entityType: "newsletter_campaign" });
|
|
151
|
+
await deps.newsletterReady;
|
|
152
|
+
const { campaign } = await pauseCampaign({ deps: toNewsletterSendPipelineDeps(deps), input: { workspaceId: deps.workspaceId, campaignId } });
|
|
153
|
+
return { campaign: toCampaignToolView(campaign) };
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export function createNewsletterCreateListHandler(deps) {
|
|
157
|
+
return async (ctx) => {
|
|
158
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
159
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.list.manage" }, { entityType: "newsletter_list" });
|
|
160
|
+
await deps.newsletterReady;
|
|
161
|
+
ctx.signal.throwIfAborted();
|
|
162
|
+
const { list } = await saveList({
|
|
163
|
+
deps: toListsDeps(deps),
|
|
164
|
+
input: { workspaceId: deps.workspaceId, name: requireString({ input, key: "name" }), slug: requireString({ input, key: "slug" }) },
|
|
165
|
+
});
|
|
166
|
+
return { list: toListToolView(list) };
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
export function createNewsletterArchiveListHandler(deps) {
|
|
170
|
+
return async (ctx) => {
|
|
171
|
+
const listId = requireString({ input: requireInputRecord({ input: ctx.input }), key: "listId" });
|
|
172
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.list.manage" }, { entityType: "newsletter_list" });
|
|
173
|
+
await deps.newsletterReady;
|
|
174
|
+
ctx.signal.throwIfAborted();
|
|
175
|
+
const { list } = await archiveList({ deps: toListsDeps(deps), input: { workspaceId: deps.workspaceId, id: listId } });
|
|
176
|
+
return { list: toListToolView(list) };
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export function createNewsletterCreateSubscriptionHandler(deps) {
|
|
180
|
+
return async (ctx) => {
|
|
181
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
182
|
+
const listId = requireString({ input, key: "listId" });
|
|
183
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.subscriber.manage" }, { entityType: "newsletter_subscription" });
|
|
184
|
+
await deps.newsletterReady;
|
|
185
|
+
const source = typeof input.source === "string" ? input.source : "admin";
|
|
186
|
+
ctx.signal.throwIfAborted();
|
|
187
|
+
const { subscription } = await saveSubscription({
|
|
188
|
+
deps: deps.buildSubscriptionsDeps({ deps }),
|
|
189
|
+
input: { workspaceId: deps.workspaceId, listId, subscriberId: requireString({ input, key: "subscriberId" }), source },
|
|
190
|
+
});
|
|
191
|
+
return { subscription: toSubscriptionToolView(subscription) };
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export function createNewsletterRemoveSubscriptionHandler(deps) {
|
|
195
|
+
return async (ctx) => {
|
|
196
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
197
|
+
const listId = requireString({ input, key: "listId" });
|
|
198
|
+
const subscriptionId = requireString({ input, key: "subscriptionId" });
|
|
199
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.subscriber.manage" }, { entityType: "newsletter_subscription" });
|
|
200
|
+
await deps.newsletterReady;
|
|
201
|
+
const existing = await deps.newsletterSubscriptionRepo.findById({ workspaceId: deps.workspaceId, id: subscriptionId });
|
|
202
|
+
if (!existing || existing.listId !== listId) {
|
|
203
|
+
throw new NewsletterSubscriptionNotFoundError(`subscription ${subscriptionId} was not found`);
|
|
204
|
+
}
|
|
205
|
+
const { subscription } = await unsubscribeSubscription({
|
|
206
|
+
deps: toUnsubscribeSubscriptionDeps(deps),
|
|
207
|
+
input: { workspaceId: deps.workspaceId, id: subscriptionId },
|
|
208
|
+
});
|
|
209
|
+
return { subscription: toSubscriptionToolView(subscription) };
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
export function createNewsletterResendConfirmationHandler(deps) {
|
|
213
|
+
return async (ctx) => {
|
|
214
|
+
const subscriptionId = requireString({ input: requireInputRecord({ input: ctx.input }), key: "subscriptionId" });
|
|
215
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: "admin.newsletter.subscriber.manage" }, { entityType: "newsletter_subscription" });
|
|
216
|
+
await deps.newsletterReady;
|
|
217
|
+
const mailOff = { delivered: false, mailDeliveryAvailable: false, note: "Email sending is not configured. Configure an SMTP credential or a mail adapter in Agent Plugins to send real email." };
|
|
218
|
+
const driver = deps.mailer.capabilities().driver;
|
|
219
|
+
if (driver === "console" || driver === "memory")
|
|
220
|
+
return mailOff;
|
|
221
|
+
if (ctx.signal.aborted)
|
|
222
|
+
return { confirmed: false, reason: "abandoned", delivered: false, mailDeliveryAvailable: true };
|
|
223
|
+
const currentDriver = deps.mailer.capabilities().driver;
|
|
224
|
+
if (currentDriver === "console" || currentDriver === "memory")
|
|
225
|
+
return mailOff;
|
|
226
|
+
return resendPendingSubscriptionConfirmation({ deps, subscriptionId, signal: ctx.signal });
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=tool-registrations.write.js.map
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Newsletter — core domain types (INTERFACES & TYPES ONLY; no feature logic).
|
|
3
|
+
*
|
|
4
|
+
* Draft ADR-034 (PROPOSED). These types encode the Newsletter design's data model,
|
|
5
|
+
* permission catalog, event/hook vocabulary, and own-table row shapes so the design is
|
|
6
|
+
* compile-checked against the real repo primitives before any implementation exists.
|
|
7
|
+
*
|
|
8
|
+
* Placement (the host v2 design doc §3.5): Newsletter is a **Tier-3 bundled plugin**
|
|
9
|
+
* (`plugins/newsletter`) resting on the **Tier-2 `MailerPort` core primitive** (see
|
|
10
|
+
* `./ports.ts`). Campaigns reuse the ADR-022 `entries` editorial substrate; the relational,
|
|
11
|
+
* high-volume audience/delivery state lives in core-mediated own-tables (ADR-023 `dataModule`,
|
|
12
|
+
* namespace `p_newsletter__*`).
|
|
13
|
+
*
|
|
14
|
+
* Grounding imports (typecheck against real code):
|
|
15
|
+
* - `../core/ports` — UUID/ISODateTime/JsonObject/DomainEvent (ADR-007/009 spine).
|
|
16
|
+
* - `../features/plugins` — the ADR-023 declared-schema shape core executes.
|
|
17
|
+
*/
|
|
18
|
+
import type { CreatorKind, ISODateTime, JsonObject, UUID } from "@jini-ai/core/primitives";
|
|
19
|
+
import type { DomainEvent } from "@jini-ai/core/contracts/events";
|
|
20
|
+
import type { DataModuleDecl } from "@jini-ai/core/contracts/site/db-data-modules";
|
|
21
|
+
/** The registered content-type slug for a campaign entry (ADR-022 registry-as-data). */
|
|
22
|
+
export declare const NEWSLETTER_CAMPAIGN_TYPE: "newsletter_campaign";
|
|
23
|
+
export type NewsletterCampaignType = typeof NEWSLETTER_CAMPAIGN_TYPE;
|
|
24
|
+
/**
|
|
25
|
+
* Campaign lifecycle status. Registry-declared statuses on the campaign content-type.
|
|
26
|
+
* `sending`/`sent`/`paused`/`canceled`/`failed` are terminal-ish states the send pipeline drives;
|
|
27
|
+
* editors only move draft↔scheduled. Once `sending` begins the audience is frozen (§audience snapshot).
|
|
28
|
+
*/
|
|
29
|
+
export type CampaignStatus = "draft" | "scheduled" | "sending" | "sent" | "paused" | "canceled" | "failed";
|
|
30
|
+
/**
|
|
31
|
+
* Newsletter-specific fields carried under `entries.fields.ext.newsletter.*` (ADR-022 §2),
|
|
32
|
+
* validated on write by the content-type registry. Counters are derived/rebuildable from the
|
|
33
|
+
* `p_newsletter__sends` ledger — stored here only as a denormalized read cache, updated through
|
|
34
|
+
* the ADR-026 atomic multi-write envelope, never authored by the plugin directly.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* ADR-PIPE-011 Decision §2 supersedes this file's original ADR-034-draft framing above: the
|
|
38
|
+
* campaign row is a BESPOKE Drizzle table pair (`newsletter_campaigns`/`newsletter_campaign_revisions`,
|
|
39
|
+
* `src/platform/db/schema.sqlite.ts`), not an `entries` content-type — no generalized `entries` substrate
|
|
40
|
+
* exists in this repo (ADR-PIPE-011 Rationale). `CampaignFields`/`NEWSLETTER_CAMPAIGN_TYPE` below are
|
|
41
|
+
* kept in place (additive-only extension per this task's directive) but are NOT the shape the real
|
|
42
|
+
* write chokepoint (`campaign-write-service.ts`) persists — `CampaignRecord`/`CampaignRevision`
|
|
43
|
+
* (state.spec.md §1) are the real row shapes; see those types further down this file.
|
|
44
|
+
*/
|
|
45
|
+
export interface CampaignFields extends JsonObject {
|
|
46
|
+
/** Email subject line. */
|
|
47
|
+
subject: string;
|
|
48
|
+
/** Inbox-preview / preheader text (optional in practice; required-shape here). */
|
|
49
|
+
preheader: string;
|
|
50
|
+
/** Envelope From display name. */
|
|
51
|
+
fromName: string;
|
|
52
|
+
/** Envelope From address (must pass the workspace's verified-sender check at send time). */
|
|
53
|
+
fromEmail: string;
|
|
54
|
+
/** Reply-To address. */
|
|
55
|
+
replyTo: string;
|
|
56
|
+
/** Target audience — a `p_newsletter__lists.id` (composite-scoped to the workspace). */
|
|
57
|
+
listId: UUID;
|
|
58
|
+
/** When `scheduled`: the intended send time (ISO). Absent for immediate/draft. */
|
|
59
|
+
scheduledAt: ISODateTime | null;
|
|
60
|
+
/** Stamped when the send pipeline begins materializing recipients (audience freeze point). */
|
|
61
|
+
sendStartedAt: ISODateTime | null;
|
|
62
|
+
/** The frozen audience batch id (`p_newsletter__audience_snapshots.id`) once sending starts. */
|
|
63
|
+
audienceSnapshotId: UUID | null;
|
|
64
|
+
/** Denormalized delivery counters (source of truth = the sends ledger). */
|
|
65
|
+
counters: CampaignCounters;
|
|
66
|
+
}
|
|
67
|
+
/** Denormalized per-campaign delivery counters (rebuildable from `p_newsletter__sends`). */
|
|
68
|
+
export interface CampaignCounters extends JsonObject {
|
|
69
|
+
recipients: number;
|
|
70
|
+
delivered: number;
|
|
71
|
+
failed: number;
|
|
72
|
+
bounced: number;
|
|
73
|
+
complained: number;
|
|
74
|
+
unsubscribed: number;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The REAL campaign row (state.spec.md §1) — the bespoke Drizzle table pair's shape
|
|
78
|
+
* (ADR-PIPE-011 Decision §2). This is what `campaign-write-service.ts`'s chokepoint persists;
|
|
79
|
+
* `CampaignFields` above is the superseded ADR-034-draft shape, kept only for compile-compat.
|
|
80
|
+
*/
|
|
81
|
+
export interface CampaignRecord {
|
|
82
|
+
id: UUID;
|
|
83
|
+
workspaceId: UUID;
|
|
84
|
+
status: CampaignStatus;
|
|
85
|
+
subject: string;
|
|
86
|
+
/** Editorial document persisted in the same-transaction revision JSON; absent on legacy drafts. */
|
|
87
|
+
bodyJson?: Record<string, unknown>;
|
|
88
|
+
preheader: string | null;
|
|
89
|
+
fromName: string;
|
|
90
|
+
fromEmail: string;
|
|
91
|
+
replyTo: string;
|
|
92
|
+
listId: UUID;
|
|
93
|
+
scheduledAt: ISODateTime | null;
|
|
94
|
+
sendStartedAt: ISODateTime | null;
|
|
95
|
+
audienceSnapshotId: UUID | null;
|
|
96
|
+
counters: CampaignCounters;
|
|
97
|
+
/** Optimistic-concurrency version (EC-06: a stale `expectedVersion` write is rejected). */
|
|
98
|
+
version: number;
|
|
99
|
+
createdByPrincipal: UUID;
|
|
100
|
+
/** `"agent"` when created through an agent's tools, `"person"` otherwise (H4, 2026-11-24; the
|
|
101
|
+
* `created_by_kind` column). Recorded once at creation and never changed; absent reads as
|
|
102
|
+
* `"person"`, so an owner-made campaign is never paused by the agent switch by mistake. */
|
|
103
|
+
createdByKind?: CreatorKind;
|
|
104
|
+
createdAt: ISODateTime;
|
|
105
|
+
updatedAt: ISODateTime;
|
|
106
|
+
}
|
|
107
|
+
/** Append-only revision row (INV-01) — one per `saveCampaign`/`cancelCampaign`/`scheduleCampaign` write. */
|
|
108
|
+
export interface CampaignRevision {
|
|
109
|
+
campaignId: UUID;
|
|
110
|
+
workspaceId: UUID;
|
|
111
|
+
seq: number;
|
|
112
|
+
state: CampaignRecord;
|
|
113
|
+
actorId: UUID;
|
|
114
|
+
recordedAt: ISODateTime;
|
|
115
|
+
}
|
|
116
|
+
/** A named send audience. Small parent table; subscriptions FK to it. */
|
|
117
|
+
export interface NewsletterListRow {
|
|
118
|
+
id: UUID;
|
|
119
|
+
workspaceId: UUID;
|
|
120
|
+
name: string;
|
|
121
|
+
slug: string;
|
|
122
|
+
/** True for the default "all subscribers" list seeded per workspace. */
|
|
123
|
+
isDefault: boolean;
|
|
124
|
+
/** REQ-08/09: the default list can never be archived (`NEWSLETTER_DEFAULT_LIST_PROTECTED`). */
|
|
125
|
+
status: "active" | "archived";
|
|
126
|
+
createdAt: ISODateTime;
|
|
127
|
+
updatedAt: ISODateTime;
|
|
128
|
+
}
|
|
129
|
+
/** Per-subscriber-per-list subscription state. This is the newsletter-owned half of the edge. */
|
|
130
|
+
export type SubscriptionStatus = "pending" | "subscribed" | "unsubscribed" | "bounced" | "complained";
|
|
131
|
+
/**
|
|
132
|
+
* A subscription row. `subscriberId` references a **Members-owned** subscriber principal
|
|
133
|
+
* (composite `(workspace_id, subscriberId)`); Newsletter never owns the identity/email/consent —
|
|
134
|
+
* see `SubscriberDirectoryPort` in `./ports.ts` and OPEN-1 (Members seam) in ADR-034.
|
|
135
|
+
*/
|
|
136
|
+
export interface SubscriptionRow {
|
|
137
|
+
id: UUID;
|
|
138
|
+
workspaceId: UUID;
|
|
139
|
+
listId: UUID;
|
|
140
|
+
/** FK into the Members-owned subscriber directory (seam — NOT designed here). */
|
|
141
|
+
subscriberId: UUID;
|
|
142
|
+
status: SubscriptionStatus;
|
|
143
|
+
/** Source of the subscription for audit/consent provenance. */
|
|
144
|
+
source: "import" | "signup_form" | "admin" | "api";
|
|
145
|
+
/**
|
|
146
|
+
* Snapshot of the Members consent-revision id in effect when this subscription last entered
|
|
147
|
+
* `subscribed` (state.spec.md §5, REQ-14) — set ONLY by `confirmation.ts`'s
|
|
148
|
+
* `consumeConfirmationToken`, never client-supplied. The unsubscribe-token derivation binds to
|
|
149
|
+
* this value (INV-04): a token minted against a stale revision (e.g. before a re-subscribe under
|
|
150
|
+
* a new consent grant) must fail closed, never silently unsubscribe the current grant.
|
|
151
|
+
*/
|
|
152
|
+
consentRevisionIdAtSubscribe: string | null;
|
|
153
|
+
subscribedAt: ISODateTime | null;
|
|
154
|
+
unsubscribedAt: ISODateTime | null;
|
|
155
|
+
createdAt: ISODateTime;
|
|
156
|
+
updatedAt: ISODateTime;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Confirmation-token lifecycle row (OQ-03, mirrors `MagicLinkTokenRecord`'s shape) — REQ-11/12/13.
|
|
160
|
+
* `consumedAt` once set is never cleared (state invariant, mirrors `member_magic_tokens`).
|
|
161
|
+
*/
|
|
162
|
+
export interface ConfirmationTokenRecord {
|
|
163
|
+
id: UUID;
|
|
164
|
+
workspaceId: UUID;
|
|
165
|
+
subscriptionId: UUID;
|
|
166
|
+
/** SHA-256 of the raw token; the raw token itself is never persisted. */
|
|
167
|
+
tokenHash: string;
|
|
168
|
+
purpose: "newsletter_subscription_confirm";
|
|
169
|
+
createdAt: ISODateTime;
|
|
170
|
+
expiresAt: ISODateTime;
|
|
171
|
+
consumedAt: ISODateTime | null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* A frozen recipient set captured when a campaign begins sending, so mid-send subscription
|
|
175
|
+
* churn never double-sends or skips (audience freeze). One snapshot per send attempt.
|
|
176
|
+
*/
|
|
177
|
+
export interface AudienceSnapshotRow {
|
|
178
|
+
id: UUID;
|
|
179
|
+
workspaceId: UUID;
|
|
180
|
+
campaignId: UUID;
|
|
181
|
+
listId: UUID;
|
|
182
|
+
recipientCount: number;
|
|
183
|
+
createdAt: ISODateTime;
|
|
184
|
+
}
|
|
185
|
+
/** Per-recipient delivery lifecycle. */
|
|
186
|
+
export type SendStatus = "pending" | "sent" | "delivered" | "failed" | "bounced" | "complained";
|
|
187
|
+
/**
|
|
188
|
+
* One row per (campaign, subscriber) delivery attempt — the outbox-driven send ledger and the
|
|
189
|
+
* source of truth for counters. `idempotencyKey` makes outbox retries safe (ADR-009 idempotent
|
|
190
|
+
* handlers): a redelivery re-uses the same key so the MailerPort/provider never double-sends.
|
|
191
|
+
*/
|
|
192
|
+
export interface SendRow {
|
|
193
|
+
id: UUID;
|
|
194
|
+
workspaceId: UUID;
|
|
195
|
+
campaignId: UUID;
|
|
196
|
+
audienceSnapshotId: UUID;
|
|
197
|
+
subscriberId: UUID;
|
|
198
|
+
/** Frozen at snapshot time from the Members directory — the address actually sent to. */
|
|
199
|
+
recipientEmail: string;
|
|
200
|
+
status: SendStatus;
|
|
201
|
+
attempts: number;
|
|
202
|
+
/** Stable per-recipient idempotency token, also forwarded to the provider adapter. */
|
|
203
|
+
idempotencyKey: string;
|
|
204
|
+
/** Provider message id once accepted (for bounce/complaint correlation). */
|
|
205
|
+
providerMessageId: string | null;
|
|
206
|
+
lastError: string | null;
|
|
207
|
+
nextAttemptAt: ISODateTime | null;
|
|
208
|
+
createdAt: ISODateTime;
|
|
209
|
+
updatedAt: ISODateTime;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The ADR-023 declared-schema manifest for the newsletter own-tables. Shape-only reference so the
|
|
213
|
+
* design compiles against the real `DataModuleDecl` core executes (v1 = seam; engine built later).
|
|
214
|
+
*/
|
|
215
|
+
export type NewsletterDataModule = DataModuleDecl;
|
|
216
|
+
/**
|
|
217
|
+
* REQ-25 Agent Directive (ADR-PIPE-011 Migration Safety): renamed from the stale unprefixed
|
|
218
|
+
* `newsletter.*` strings to `admin.newsletter.*` — confirmed additive, zero existing call sites
|
|
219
|
+
* referenced the old strings anywhere in `src/` (same pattern SPEC-009 used for
|
|
220
|
+
* `admin.redirects.manage`; api.spec.md §2's per-endpoint auth profiles use these exact 8 strings).
|
|
221
|
+
*/
|
|
222
|
+
export type NewsletterPermission = "admin.newsletter.read" | "admin.newsletter.campaign.compose" | "admin.newsletter.campaign.schedule" | "admin.newsletter.campaign.send" | "admin.newsletter.campaign.send_test" | "admin.newsletter.list.manage" | "admin.newsletter.subscriber.read" | "admin.newsletter.subscriber.manage" | "admin.newsletter.settings.manage" | "admin.newsletter.manage";
|
|
223
|
+
/** Registered catalog (declaration, not logic) — enumerable via the host CLI's `permissions list` (ADR-021). */
|
|
224
|
+
export declare const NEWSLETTER_PERMISSIONS: readonly NewsletterPermission[];
|
|
225
|
+
export type NewsletterEventName = "newsletter.campaign.scheduled" | "newsletter.campaign.send_started" | "newsletter.send.enqueued" | "newsletter.send.delivered" | "newsletter.send.failed" | "newsletter.send.bounced" | "newsletter.send.complained" | "newsletter.campaign.sent" | "newsletter.subscriber.unsubscribed";
|
|
226
|
+
export interface CampaignScheduledPayload {
|
|
227
|
+
campaignId: UUID;
|
|
228
|
+
listId: UUID;
|
|
229
|
+
scheduledAt: ISODateTime;
|
|
230
|
+
}
|
|
231
|
+
export interface SendStartedPayload {
|
|
232
|
+
campaignId: UUID;
|
|
233
|
+
audienceSnapshotId: UUID;
|
|
234
|
+
recipientCount: number;
|
|
235
|
+
}
|
|
236
|
+
export interface SendResultPayload {
|
|
237
|
+
campaignId: UUID;
|
|
238
|
+
sendId: UUID;
|
|
239
|
+
subscriberId: UUID;
|
|
240
|
+
providerMessageId: string | null;
|
|
241
|
+
}
|
|
242
|
+
export interface UnsubscribedPayload {
|
|
243
|
+
subscriberId: UUID;
|
|
244
|
+
listId: UUID;
|
|
245
|
+
/** Present when the unsubscribe originated from a specific campaign's footer link. */
|
|
246
|
+
campaignId: UUID | null;
|
|
247
|
+
}
|
|
248
|
+
/** Concrete DomainEvent aliases (ADR-007: every event is workspace-scoped, enforced by the type). */
|
|
249
|
+
export type CampaignScheduledEvent = DomainEvent<CampaignScheduledPayload>;
|
|
250
|
+
export type SendStartedEvent = DomainEvent<SendStartedPayload>;
|
|
251
|
+
export type SendResultEvent = DomainEvent<SendResultPayload>;
|
|
252
|
+
export type UnsubscribedEvent = DomainEvent<UnsubscribedPayload>;
|
|
253
|
+
export type NewsletterHookName = "newsletter.email.beforeSend" | "newsletter.recipient.filter";
|
|
254
|
+
/** Passed to `newsletter.email.beforeSend` — returns a possibly-transformed message. */
|
|
255
|
+
export interface BeforeSendHookContext {
|
|
256
|
+
workspaceId: UUID;
|
|
257
|
+
campaignId: UUID;
|
|
258
|
+
sendId: UUID;
|
|
259
|
+
subscriberId: UUID;
|
|
260
|
+
}
|
|
261
|
+
/** Passed to `newsletter.recipient.filter` — returns `true` to keep the recipient. */
|
|
262
|
+
export interface RecipientFilterContext {
|
|
263
|
+
workspaceId: UUID;
|
|
264
|
+
campaignId: UUID;
|
|
265
|
+
listId: UUID;
|
|
266
|
+
subscriberId: UUID;
|
|
267
|
+
recipientEmail: string;
|
|
268
|
+
status: SubscriptionStatus;
|
|
269
|
+
}
|
|
270
|
+
/** The claims an unsubscribe link carries; core signs (HMAC) and verifies. Never a session cookie. */
|
|
271
|
+
export interface UnsubscribeTokenClaims {
|
|
272
|
+
workspaceId: UUID;
|
|
273
|
+
subscriberId: UUID;
|
|
274
|
+
listId: UUID;
|
|
275
|
+
campaignId: UUID | null;
|
|
276
|
+
/** Short expiry is optional for unsubscribe (links live in old inboxes); default = non-expiring. */
|
|
277
|
+
expiresAt: ISODateTime | null;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* ------------------------------------------------------------------------------------------------
|
|
2
|
+
* 1. Campaign editorial state — reuses ADR-022 `entries` (content-type `newsletter_campaign`)
|
|
3
|
+
* ------------------------------------------------------------------------------------------------
|
|
4
|
+
* A campaign IS a seeded/registered content-type entry (like `media` in ADR-027): it gets the
|
|
5
|
+
* write chokepoint, append-only revisions, status transitions, and `bodyJson` (TipTap doc) for
|
|
6
|
+
* free. Newsletter-specific fields live under the validated namespaced bag `fields.ext.newsletter.*`.
|
|
7
|
+
*/
|
|
8
|
+
/** The registered content-type slug for a campaign entry (ADR-022 registry-as-data). */
|
|
9
|
+
export const NEWSLETTER_CAMPAIGN_TYPE = "newsletter_campaign";
|
|
10
|
+
/** Registered catalog (declaration, not logic) — enumerable via the host CLI's `permissions list` (ADR-021). */
|
|
11
|
+
export const NEWSLETTER_PERMISSIONS = [
|
|
12
|
+
"admin.newsletter.read",
|
|
13
|
+
"admin.newsletter.campaign.compose",
|
|
14
|
+
"admin.newsletter.campaign.schedule",
|
|
15
|
+
"admin.newsletter.campaign.send",
|
|
16
|
+
"admin.newsletter.campaign.send_test",
|
|
17
|
+
"admin.newsletter.list.manage",
|
|
18
|
+
"admin.newsletter.subscriber.read",
|
|
19
|
+
"admin.newsletter.subscriber.manage",
|
|
20
|
+
"admin.newsletter.settings.manage",
|
|
21
|
+
"admin.newsletter.manage",
|
|
22
|
+
];
|
|
23
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { UUID } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { KeyringPort } from "@jini-ai/core/contracts/vault";
|
|
3
|
+
import type { OriginRegistryPort } from "@jini-ai/core/contracts/server/verified-origin";
|
|
4
|
+
import type { MembersConsentCapability, NewsletterSubscriptionRepoPort } from "./ports.js";
|
|
5
|
+
export interface UnsubscribeTokenClaims {
|
|
6
|
+
workspaceId: UUID;
|
|
7
|
+
subscriberId: UUID;
|
|
8
|
+
listId: UUID;
|
|
9
|
+
campaignId: UUID | null;
|
|
10
|
+
/** The consent-revision id the token was minted against — compared to the subscription's CURRENT value (INV-04).
|
|
11
|
+
* `null` when the subscription recorded none (no consent capability bound); it must stay `null`
|
|
12
|
+
* rather than be coerced, or the comparison would reject the subscriber's own token. */
|
|
13
|
+
consentRevisionId: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface UnsubscribeDeps {
|
|
16
|
+
subscriptionRepo: NewsletterSubscriptionRepoPort;
|
|
17
|
+
keyring: KeyringPort;
|
|
18
|
+
originRegistry: OriginRegistryPort;
|
|
19
|
+
consentCapability: MembersConsentCapability | null;
|
|
20
|
+
clock: {
|
|
21
|
+
nowIso(): string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Build a signed, origin-anchored unsubscribe link (REQ-30/INV-09 — never a raw `Host` header). */
|
|
25
|
+
export declare function buildUnsubscribeLink(required: {
|
|
26
|
+
deps: UnsubscribeDeps;
|
|
27
|
+
claims: UnsubscribeTokenClaims;
|
|
28
|
+
}, _optional?: Record<string, never>): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* @complexity O(1).
|
|
31
|
+
* @overallScore 100
|
|
32
|
+
*/
|
|
33
|
+
export declare function processUnsubscribe(required: {
|
|
34
|
+
deps: UnsubscribeDeps;
|
|
35
|
+
input: {
|
|
36
|
+
rawToken: string;
|
|
37
|
+
};
|
|
38
|
+
}, _optional?: Record<string, never>): Promise<{
|
|
39
|
+
outcome: "unsubscribed" | "already-unsubscribed";
|
|
40
|
+
}>;
|
|
41
|
+
//# sourceMappingURL=unsubscribe.d.ts.map
|