@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,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Newsletter — port contracts (INTERFACES & TYPES ONLY; no adapter logic).
|
|
3
|
+
*
|
|
4
|
+
* Draft ADR-034 (PROPOSED). One seam is declared here; `MailerPort` is imported, not declared:
|
|
5
|
+
*
|
|
6
|
+
* 1. `MailerPort` — imported from the shared `../mail` core primitive (ADR-037). Round-3 audit
|
|
7
|
+
* fold (TM-admin-sweep-001): the shape previously declared locally here predated ADR-037 and
|
|
8
|
+
* didn't match its frozen contract (`originPluginId` vs `sourceContext`, optional `sendBatch`
|
|
9
|
+
* vs the mandatory façade). Newsletter now imports the one shape every mail consumer shares.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT (ADR-024 §3): the Newsletter *plugin* never holds a live `MailerPort` object. The
|
|
12
|
+
* plugin submits send intent as data (through the outbox/command spine); **core** injects and
|
|
13
|
+
* calls the `MailerPort`. The port lives in core's DI graph, not across the plugin ABI.
|
|
14
|
+
*
|
|
15
|
+
* 2. `SubscriberDirectoryPort` — the **Members seam** (Members is designed in parallel; NOT here).
|
|
16
|
+
* Newsletter depends on this read seam to resolve a subscriber's address/consent at audience
|
|
17
|
+
* materialization; Members owns the implementation. Round-3 audit fold: this is a
|
|
18
|
+
* **single-evaluator typed dependency**, not an ADR-006 port — an in-memory test double does
|
|
19
|
+
* not count as Members' "second adapter" (ADR-037 amendment 6 precedent). Promote to a real
|
|
20
|
+
* port only if a second genuine directory adapter (e.g. an external ESP sync) is ever built.
|
|
21
|
+
*
|
|
22
|
+
* Grounding imports (typecheck against real code): `../core/ports`, `../mail`.
|
|
23
|
+
*/
|
|
24
|
+
import type { UUID } from "@jini-ai/core/primitives";
|
|
25
|
+
import type { ListPage } from "@jini-ai/core/list-page";
|
|
26
|
+
import type { AudienceSnapshotRow, CampaignRecord, CampaignRevision, ConfirmationTokenRecord, NewsletterListRow, SendRow, SubscriptionRow } from "./types.js";
|
|
27
|
+
export type { PositionalMailer as MailerPort } from "@jini-ai/core/contracts/mail";
|
|
28
|
+
/** The subset of a Members-owned subscriber that Newsletter needs at send time. */
|
|
29
|
+
export interface SubscriberContact {
|
|
30
|
+
subscriberId: UUID;
|
|
31
|
+
workspaceId: UUID;
|
|
32
|
+
email: string;
|
|
33
|
+
/** Members-owned consent/lifecycle flag; a `false` here suppresses regardless of subscription. */
|
|
34
|
+
emailDeliverable: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Read port into Members. Newsletter NEVER writes subscriber identity/consent through this — it
|
|
38
|
+
* only resolves contact info to freeze into the audience snapshot. Composite `(workspaceId, id)`
|
|
39
|
+
* scoping (ADR-021 §4) is honoured by every method taking `workspaceId` explicitly (ADR-007).
|
|
40
|
+
*
|
|
41
|
+
* Single-evaluator typed dependency, NOT an ADR-006 port (Round-3 audit fold; round-2 re-audit
|
|
42
|
+
* finding Codex-R2-001 caught this same misrepresentation surviving here after the ADR text was
|
|
43
|
+
* fixed). `InMemorySubscriberDirectory` is a test double / interim implementation only — it does
|
|
44
|
+
* NOT count as a second production adapter (ADR-037 amendment 6 precedent). Promote to a real
|
|
45
|
+
* ADR-006 port only if a second genuine directory adapter (e.g. an external ESP sync) is built;
|
|
46
|
+
* until then this stays `MembersSubscriberDirectory` (interim double) — see ADR-034 OPEN-1.
|
|
47
|
+
*/
|
|
48
|
+
export interface SubscriberDirectoryPort {
|
|
49
|
+
getContact(required: {
|
|
50
|
+
workspaceId: UUID;
|
|
51
|
+
subscriberId: UUID;
|
|
52
|
+
}): Promise<SubscriberContact | null>;
|
|
53
|
+
getContacts(required: {
|
|
54
|
+
workspaceId: UUID;
|
|
55
|
+
subscriberIds: readonly UUID[];
|
|
56
|
+
}): Promise<readonly SubscriberContact[]>;
|
|
57
|
+
}
|
|
58
|
+
/** The unit of work the outbox worker claims to drive one batch of a campaign's fan-out. */
|
|
59
|
+
export interface SendBatchJob {
|
|
60
|
+
workspaceId: UUID;
|
|
61
|
+
campaignId: UUID;
|
|
62
|
+
audienceSnapshotId: UUID;
|
|
63
|
+
/** The slice of `p_newsletter__sends` rows (by id) this job attempts. */
|
|
64
|
+
sendIds: readonly UUID[];
|
|
65
|
+
}
|
|
66
|
+
/** The two delivery outcomes `incrementCounter` may bump (explicit union — `CampaignCounters extends JsonObject`, so `keyof` would widen to `string`). */
|
|
67
|
+
export type CampaignOutcomeCounter = "delivered" | "failed";
|
|
68
|
+
/** C-001 — `newsletter_campaigns`/`newsletter_campaign_revisions` (the bespoke Drizzle pair). */
|
|
69
|
+
export interface NewsletterCampaignRepoPort {
|
|
70
|
+
/** Bounded idle-safety probe; missing capability means busy, never a paginated-list fallback. */
|
|
71
|
+
hasSending?(required: {
|
|
72
|
+
workspaceId: UUID;
|
|
73
|
+
}, optional?: {}): Promise<boolean>;
|
|
74
|
+
findById(required: {
|
|
75
|
+
workspaceId: UUID;
|
|
76
|
+
id: UUID;
|
|
77
|
+
}): Promise<CampaignRecord | null>;
|
|
78
|
+
/** Returns campaigns in ID order; pass nextCursor to continue after the last returned ID. */
|
|
79
|
+
list(required: {
|
|
80
|
+
workspaceId: UUID;
|
|
81
|
+
}, optional?: {
|
|
82
|
+
limit?: number;
|
|
83
|
+
cursor?: string | null;
|
|
84
|
+
}): Promise<ListPage<CampaignRecord>>;
|
|
85
|
+
/**
|
|
86
|
+
* Package-private by convention (Code Review file-boundary check) — called from
|
|
87
|
+
* `campaign-write-service.ts` (inside a `transaction()` callback together with `appendRevision`,
|
|
88
|
+
* INV-01: never one without the other in the same tx) and from `send-pipeline.ts`'s status writers
|
|
89
|
+
* (`authorizeSend`, `freezeAudience`, `completeIfDrained`, `transitionAndSave`). Split into two
|
|
90
|
+
* methods (rather than one combined `save`) so a test can force a failure between the two writes at
|
|
91
|
+
* the real SQLite adapter (AC-08) — mirrors `SettingsRepoPort`'s `saveXValue`/`appendRevision` split.
|
|
92
|
+
*
|
|
93
|
+
* Counters are written on INSERT only (2026-09-16): updating an existing campaign keeps its stored
|
|
94
|
+
* `counters`, whatever the passed record holds, so a status write built from a stale read cannot
|
|
95
|
+
* erase a concurrent `incrementCounter`.
|
|
96
|
+
*/
|
|
97
|
+
saveCampaignRow(campaign: CampaignRecord): Promise<void>;
|
|
98
|
+
/** Package-private by convention — call only from `campaign-write-service.ts`. */
|
|
99
|
+
appendRevision(revision: CampaignRevision): Promise<void>;
|
|
100
|
+
listRevisions(required: {
|
|
101
|
+
workspaceId: UUID;
|
|
102
|
+
campaignId: UUID;
|
|
103
|
+
}): Promise<CampaignRevision[]>;
|
|
104
|
+
/** Repo-port-level atomic boundary — mirrors `SettingsRepoPort.transaction`. */
|
|
105
|
+
transaction<T>(required: {
|
|
106
|
+
fn: () => Promise<T>;
|
|
107
|
+
}, optional?: {}): Promise<T>;
|
|
108
|
+
/**
|
|
109
|
+
* Atomically adds 1 to one delivery counter of one campaign and sets its `updatedAt` (2026-09-16). The only writer of
|
|
110
|
+
* `counters` once the row exists; touches no other field (status, version and editorial fields stay as stored). A missing
|
|
111
|
+
* campaign is a no-op. Writes no revision: counters are operational telemetry, narrowing INV-01 the way `redirect_hits`
|
|
112
|
+
* and ADR-027's `asset_renditions` narrow ADR-022 INV-3.
|
|
113
|
+
*/
|
|
114
|
+
incrementCounter(required: {
|
|
115
|
+
workspaceId: UUID;
|
|
116
|
+
id: UUID;
|
|
117
|
+
counter: CampaignOutcomeCounter;
|
|
118
|
+
updatedAt: string;
|
|
119
|
+
}): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
/** C-002 — `p_newsletter__lists`. */
|
|
122
|
+
export interface NewsletterListRepoPort {
|
|
123
|
+
findById(required: {
|
|
124
|
+
workspaceId: UUID;
|
|
125
|
+
id: UUID;
|
|
126
|
+
}): Promise<NewsletterListRow | null>;
|
|
127
|
+
findDefault(required: {
|
|
128
|
+
workspaceId: UUID;
|
|
129
|
+
}): Promise<NewsletterListRow | null>;
|
|
130
|
+
list(required: {
|
|
131
|
+
workspaceId: UUID;
|
|
132
|
+
}): Promise<NewsletterListRow[]>;
|
|
133
|
+
save(row: NewsletterListRow): Promise<void>;
|
|
134
|
+
}
|
|
135
|
+
/** C-003 — `p_newsletter__subscriptions`. */
|
|
136
|
+
export interface NewsletterSubscriptionRepoPort {
|
|
137
|
+
findById(required: {
|
|
138
|
+
workspaceId: UUID;
|
|
139
|
+
id: UUID;
|
|
140
|
+
}): Promise<SubscriptionRow | null>;
|
|
141
|
+
findBySubscriberAndList(required: {
|
|
142
|
+
workspaceId: UUID;
|
|
143
|
+
listId: UUID;
|
|
144
|
+
subscriberId: UUID;
|
|
145
|
+
}): Promise<SubscriptionRow | null>;
|
|
146
|
+
/** Returns subscriptions in ID order, with a cursor when another page exists. */
|
|
147
|
+
list(required: {
|
|
148
|
+
workspaceId: UUID;
|
|
149
|
+
listId: UUID;
|
|
150
|
+
}, optional?: {
|
|
151
|
+
limit?: number;
|
|
152
|
+
cursor?: string | null;
|
|
153
|
+
}): Promise<ListPage<SubscriptionRow>>;
|
|
154
|
+
listSubscribed(required: {
|
|
155
|
+
workspaceId: UUID;
|
|
156
|
+
listId: UUID;
|
|
157
|
+
}): Promise<SubscriptionRow[]>;
|
|
158
|
+
save(row: SubscriptionRow): Promise<void>;
|
|
159
|
+
remove(required: {
|
|
160
|
+
workspaceId: UUID;
|
|
161
|
+
id: UUID;
|
|
162
|
+
}): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
/** C-004 — `p_newsletter__audience_snapshots`. Immutable after creation (INV-06). */
|
|
165
|
+
export interface NewsletterAudienceSnapshotRepoPort {
|
|
166
|
+
findByCampaignId(required: {
|
|
167
|
+
workspaceId: UUID;
|
|
168
|
+
campaignId: UUID;
|
|
169
|
+
}): Promise<AudienceSnapshotRow | null>;
|
|
170
|
+
findById(required: {
|
|
171
|
+
workspaceId: UUID;
|
|
172
|
+
id: UUID;
|
|
173
|
+
}): Promise<AudienceSnapshotRow | null>;
|
|
174
|
+
save(row: AudienceSnapshotRow): Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
/** C-005 — `p_newsletter__sends`. Source of truth for delivery counters. */
|
|
177
|
+
export interface NewsletterSendRepoPort {
|
|
178
|
+
findById(required: {
|
|
179
|
+
workspaceId: UUID;
|
|
180
|
+
id: UUID;
|
|
181
|
+
}): Promise<SendRow | null>;
|
|
182
|
+
findByIdempotencyKey(required: {
|
|
183
|
+
workspaceId: UUID;
|
|
184
|
+
idempotencyKey: string;
|
|
185
|
+
}): Promise<SendRow | null>;
|
|
186
|
+
listByCampaign(required: {
|
|
187
|
+
workspaceId: UUID;
|
|
188
|
+
campaignId: UUID;
|
|
189
|
+
afterId?: UUID;
|
|
190
|
+
limit?: number;
|
|
191
|
+
}): Promise<SendRow[]>;
|
|
192
|
+
listPendingByAudienceSnapshot(required: {
|
|
193
|
+
workspaceId: UUID;
|
|
194
|
+
audienceSnapshotId: UUID;
|
|
195
|
+
limit: number;
|
|
196
|
+
}): Promise<SendRow[]>;
|
|
197
|
+
countPendingByCampaign(required: {
|
|
198
|
+
workspaceId: UUID;
|
|
199
|
+
campaignId: UUID;
|
|
200
|
+
}): Promise<number>;
|
|
201
|
+
save(row: SendRow): Promise<void>;
|
|
202
|
+
saveBatch(required: {
|
|
203
|
+
rows: readonly SendRow[];
|
|
204
|
+
}, optional?: {}): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Atomically takes the dispatch lease on one send row (2026-09-16): succeeds only when the row is `pending` and not
|
|
207
|
+
* under a live lease (`nextAttemptAt` is null or `<= nowIso`), storing `leaseUntilIso` as its `nextAttemptAt`. A leased
|
|
208
|
+
* row stays `pending` (so `countPendingByCampaign` still counts it). Returns the leased row, or `null` when the row is
|
|
209
|
+
* missing, no longer `pending`, or leased by another live dispatch. Timestamps are `toISOString()` strings and compare lexically.
|
|
210
|
+
*/
|
|
211
|
+
claimForDispatch(required: {
|
|
212
|
+
workspaceId: UUID;
|
|
213
|
+
id: UUID;
|
|
214
|
+
nowIso: string;
|
|
215
|
+
leaseUntilIso: string;
|
|
216
|
+
}): Promise<SendRow | null>;
|
|
217
|
+
/**
|
|
218
|
+
* Atomically records a dispatch outcome on one send row (2026-09-16): succeeds only while the row is `pending`, setting
|
|
219
|
+
* `status`, `attempts + 1`, `lastError`, `providerMessageId` (kept as stored when the input is null), `nextAttemptAt`
|
|
220
|
+
* null (releases the `claimForDispatch` lease) and `updatedAt`. Returns the updated row, or `null` when the row is missing
|
|
221
|
+
* or no longer `pending` (another run already recorded it).
|
|
222
|
+
*/
|
|
223
|
+
recordOutcome(required: {
|
|
224
|
+
workspaceId: UUID;
|
|
225
|
+
id: UUID;
|
|
226
|
+
status: "delivered" | "failed";
|
|
227
|
+
providerMessageId: string | null;
|
|
228
|
+
lastError: string | null;
|
|
229
|
+
updatedAt: string;
|
|
230
|
+
}): Promise<SendRow | null>;
|
|
231
|
+
}
|
|
232
|
+
/** C-006 — `p_newsletter__confirmation_tokens`. */
|
|
233
|
+
export interface NewsletterConfirmationTokenRepoPort {
|
|
234
|
+
findById(required: {
|
|
235
|
+
workspaceId: UUID;
|
|
236
|
+
id: UUID;
|
|
237
|
+
}): Promise<ConfirmationTokenRecord | null>;
|
|
238
|
+
findUnconsumedBySubscription(required: {
|
|
239
|
+
workspaceId: UUID;
|
|
240
|
+
subscriptionId: UUID;
|
|
241
|
+
}): Promise<ConfirmationTokenRecord[]>;
|
|
242
|
+
findByTokenHash(required: {
|
|
243
|
+
workspaceId: UUID;
|
|
244
|
+
tokenHash: string;
|
|
245
|
+
}): Promise<ConfirmationTokenRecord | null>;
|
|
246
|
+
save(row: ConfirmationTokenRecord): Promise<void>;
|
|
247
|
+
}
|
|
248
|
+
export interface MembersConsentCapability {
|
|
249
|
+
/** Request consent (double opt-in kickoff) — Newsletter supplies evidence, never asserts the grant itself. */
|
|
250
|
+
request(input: {
|
|
251
|
+
workspaceId: UUID;
|
|
252
|
+
subscriberId: UUID;
|
|
253
|
+
evidence: {
|
|
254
|
+
consentTextRef: string;
|
|
255
|
+
source: string;
|
|
256
|
+
confirmTokenId: UUID;
|
|
257
|
+
};
|
|
258
|
+
}): Promise<{
|
|
259
|
+
requested: true;
|
|
260
|
+
}>;
|
|
261
|
+
/** Confirm a prior request. Returns the resulting consent state — Newsletter flips local status only after `granted`. */
|
|
262
|
+
confirm(input: {
|
|
263
|
+
workspaceId: UUID;
|
|
264
|
+
subscriberId: UUID;
|
|
265
|
+
confirmTokenId: UUID;
|
|
266
|
+
}): Promise<{
|
|
267
|
+
status: "granted" | "denied" | "expired";
|
|
268
|
+
consentRevisionId: string;
|
|
269
|
+
}>;
|
|
270
|
+
/** Revoke consent (unsubscribe). */
|
|
271
|
+
revoke(input: {
|
|
272
|
+
workspaceId: UUID;
|
|
273
|
+
subscriberId: UUID;
|
|
274
|
+
}): Promise<{
|
|
275
|
+
status: "revoked";
|
|
276
|
+
}>;
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { StorageKernel } from "@jini-ai/core/contracts/storage";
|
|
3
|
+
import type { NewsletterAudienceSnapshotRepoPort, NewsletterSendRepoPort } from "./ports.js";
|
|
4
|
+
import { type NewsletterSqlRequired, type NewsletterSqlTables } from "./repo.rows.js";
|
|
5
|
+
import type { AudienceSnapshotRow, SendRow } from "./types.js";
|
|
6
|
+
export declare class SqlNewsletterAudienceSnapshotRepo implements NewsletterAudienceSnapshotRepoPort {
|
|
7
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
8
|
+
protected readonly tables: Pick<NewsletterSqlTables, "audienceSnapshots">;
|
|
9
|
+
constructor(required: NewsletterSqlRequired<"audienceSnapshots">, _optional?: Record<string, never>);
|
|
10
|
+
findByCampaignId(required: {
|
|
11
|
+
workspaceId: string;
|
|
12
|
+
campaignId: string;
|
|
13
|
+
}): Promise<AudienceSnapshotRow | null>;
|
|
14
|
+
findById(required: {
|
|
15
|
+
workspaceId: string;
|
|
16
|
+
id: string;
|
|
17
|
+
}): Promise<AudienceSnapshotRow | null>;
|
|
18
|
+
/** INV-06: immutable after creation. A plain INSERT (no upsert), so a primary-key collision surfaces as a thrown error. */
|
|
19
|
+
save(row: AudienceSnapshotRow): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare class SqlNewsletterSendRepo implements NewsletterSendRepoPort {
|
|
22
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
23
|
+
protected readonly tables: Pick<NewsletterSqlTables, "sends">;
|
|
24
|
+
constructor(required: NewsletterSqlRequired<"sends">, _optional?: Record<string, never>);
|
|
25
|
+
findById(required: {
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
id: string;
|
|
28
|
+
}): Promise<SendRow | null>;
|
|
29
|
+
findByIdempotencyKey(required: {
|
|
30
|
+
workspaceId: string;
|
|
31
|
+
idempotencyKey: string;
|
|
32
|
+
}): Promise<SendRow | null>;
|
|
33
|
+
listByCampaign(required: {
|
|
34
|
+
workspaceId: string;
|
|
35
|
+
campaignId: string;
|
|
36
|
+
afterId?: string;
|
|
37
|
+
limit?: number;
|
|
38
|
+
}): Promise<SendRow[]>;
|
|
39
|
+
listPendingByAudienceSnapshot(required: {
|
|
40
|
+
workspaceId: string;
|
|
41
|
+
audienceSnapshotId: string;
|
|
42
|
+
limit: number;
|
|
43
|
+
}): Promise<SendRow[]>;
|
|
44
|
+
countPendingByCampaign(required: {
|
|
45
|
+
workspaceId: string;
|
|
46
|
+
campaignId: string;
|
|
47
|
+
}): Promise<number>;
|
|
48
|
+
save(row: SendRow): Promise<void>;
|
|
49
|
+
/** All rows land or none do: the batch is one transaction. */
|
|
50
|
+
saveBatch({ rows }: {
|
|
51
|
+
rows: readonly SendRow[];
|
|
52
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Atomically takes the dispatch lease on one send row (2026-09-16, see `ports.ts` doc). One
|
|
55
|
+
* conditional `UPDATE ... RETURNING` makes the claim atomic across processes and hands back the
|
|
56
|
+
* row it claimed, so nothing can change it between the write and the read.
|
|
57
|
+
*
|
|
58
|
+
* @complexity O(1) (indexed lookup by primary key).
|
|
59
|
+
*/
|
|
60
|
+
claimForDispatch(required: {
|
|
61
|
+
workspaceId: string;
|
|
62
|
+
id: string;
|
|
63
|
+
nowIso: string;
|
|
64
|
+
leaseUntilIso: string;
|
|
65
|
+
}): Promise<SendRow | null>;
|
|
66
|
+
/**
|
|
67
|
+
* Atomically records a dispatch outcome (2026-09-16, see `ports.ts` doc). One conditional
|
|
68
|
+
* `UPDATE ... WHERE status = 'pending' RETURNING`: a concurrent second call matches zero rows and
|
|
69
|
+
* returns `null` without touching the row. A null `providerMessageId` keeps the stored one.
|
|
70
|
+
*
|
|
71
|
+
* @complexity O(1) (indexed lookup by primary key).
|
|
72
|
+
*/
|
|
73
|
+
recordOutcome(required: {
|
|
74
|
+
workspaceId: string;
|
|
75
|
+
id: string;
|
|
76
|
+
status: "delivered" | "failed";
|
|
77
|
+
providerMessageId: string | null;
|
|
78
|
+
lastError: string | null;
|
|
79
|
+
updatedAt: string;
|
|
80
|
+
}): Promise<SendRow | null>;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=repo-sends.d.ts.map
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { toAudienceSnapshotRecord, toAudienceSnapshotRow, toSendRecord, toSendRow, updatableSendColumns, } from "./repo.rows.js";
|
|
2
|
+
/**
|
|
3
|
+
* @file The audience-snapshot and send repositories over the host's `p_newsletter__*` dataModule
|
|
4
|
+
* tables: one Kysely query body for every dialect, the table names passed in by the host
|
|
5
|
+
* ({@link NewsletterSqlTables}).
|
|
6
|
+
*/
|
|
7
|
+
import { DEFAULT_LIST_LIMIT } from "./repo-subscribers.js";
|
|
8
|
+
export class SqlNewsletterAudienceSnapshotRepo {
|
|
9
|
+
kernel;
|
|
10
|
+
tables;
|
|
11
|
+
constructor(required, _optional = {}) {
|
|
12
|
+
this.kernel = required.kernel;
|
|
13
|
+
this.tables = required.tables;
|
|
14
|
+
}
|
|
15
|
+
async findByCampaignId(required) {
|
|
16
|
+
const row = await this.kernel.run((db) => db
|
|
17
|
+
.withTables()
|
|
18
|
+
.selectFrom(this.tables.audienceSnapshots)
|
|
19
|
+
.selectAll()
|
|
20
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
21
|
+
.where("campaign_id", "=", required.campaignId)
|
|
22
|
+
.orderBy("id", "asc")
|
|
23
|
+
.limit(1)
|
|
24
|
+
.executeTakeFirst());
|
|
25
|
+
return row ? toAudienceSnapshotRecord(row) : null;
|
|
26
|
+
}
|
|
27
|
+
async findById(required) {
|
|
28
|
+
const row = await this.kernel.run((db) => db
|
|
29
|
+
.withTables()
|
|
30
|
+
.selectFrom(this.tables.audienceSnapshots)
|
|
31
|
+
.selectAll()
|
|
32
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
33
|
+
.where("id", "=", required.id)
|
|
34
|
+
.executeTakeFirst());
|
|
35
|
+
return row ? toAudienceSnapshotRecord(row) : null;
|
|
36
|
+
}
|
|
37
|
+
/** INV-06: immutable after creation. A plain INSERT (no upsert), so a primary-key collision surfaces as a thrown error. */
|
|
38
|
+
async save(row) {
|
|
39
|
+
await this.kernel.run((db) => db.withTables().insertInto(this.tables.audienceSnapshots).values(toAudienceSnapshotRow(row)).execute());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class SqlNewsletterSendRepo {
|
|
43
|
+
kernel;
|
|
44
|
+
tables;
|
|
45
|
+
constructor(required, _optional = {}) {
|
|
46
|
+
this.kernel = required.kernel;
|
|
47
|
+
this.tables = required.tables;
|
|
48
|
+
}
|
|
49
|
+
async findById(required) {
|
|
50
|
+
const row = await this.kernel.run((db) => db
|
|
51
|
+
.withTables()
|
|
52
|
+
.selectFrom(this.tables.sends)
|
|
53
|
+
.selectAll()
|
|
54
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
55
|
+
.where("id", "=", required.id)
|
|
56
|
+
.executeTakeFirst());
|
|
57
|
+
return row ? toSendRecord(row) : null;
|
|
58
|
+
}
|
|
59
|
+
async findByIdempotencyKey(required) {
|
|
60
|
+
const row = await this.kernel.run((db) => db
|
|
61
|
+
.withTables()
|
|
62
|
+
.selectFrom(this.tables.sends)
|
|
63
|
+
.selectAll()
|
|
64
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
65
|
+
.where("idempotency_key", "=", required.idempotencyKey)
|
|
66
|
+
.orderBy("id", "asc")
|
|
67
|
+
.limit(1)
|
|
68
|
+
.executeTakeFirst());
|
|
69
|
+
return row ? toSendRecord(row) : null;
|
|
70
|
+
}
|
|
71
|
+
async listByCampaign(required) {
|
|
72
|
+
const rows = await this.kernel.run((db) => {
|
|
73
|
+
let query = db
|
|
74
|
+
.withTables()
|
|
75
|
+
.selectFrom(this.tables.sends)
|
|
76
|
+
.selectAll()
|
|
77
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
78
|
+
.where("campaign_id", "=", required.campaignId);
|
|
79
|
+
if (required.afterId)
|
|
80
|
+
query = query.where("id", ">", required.afterId);
|
|
81
|
+
return query
|
|
82
|
+
.orderBy("id", "asc")
|
|
83
|
+
.limit(required.limit ?? DEFAULT_LIST_LIMIT)
|
|
84
|
+
.execute();
|
|
85
|
+
});
|
|
86
|
+
return rows.map(toSendRecord);
|
|
87
|
+
}
|
|
88
|
+
async listPendingByAudienceSnapshot(required) {
|
|
89
|
+
const rows = await this.kernel.run((db) => db
|
|
90
|
+
.withTables()
|
|
91
|
+
.selectFrom(this.tables.sends)
|
|
92
|
+
.selectAll()
|
|
93
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
94
|
+
.where("audience_snapshot_id", "=", required.audienceSnapshotId)
|
|
95
|
+
.where("status", "=", "pending")
|
|
96
|
+
.orderBy("id", "asc")
|
|
97
|
+
.limit(required.limit)
|
|
98
|
+
.execute());
|
|
99
|
+
return rows.map(toSendRecord);
|
|
100
|
+
}
|
|
101
|
+
async countPendingByCampaign(required) {
|
|
102
|
+
const row = await this.kernel.run((db) => db
|
|
103
|
+
.withTables()
|
|
104
|
+
.selectFrom(this.tables.sends)
|
|
105
|
+
.select((eb) => eb.fn.countAll().as("n"))
|
|
106
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
107
|
+
.where("campaign_id", "=", required.campaignId)
|
|
108
|
+
.where("status", "=", "pending")
|
|
109
|
+
.executeTakeFirst());
|
|
110
|
+
// Postgres returns a COUNT as a bigint string.
|
|
111
|
+
return Number(row?.n ?? 0);
|
|
112
|
+
}
|
|
113
|
+
async save(row) {
|
|
114
|
+
const values = toSendRow(row);
|
|
115
|
+
await this.kernel.run((db) => db
|
|
116
|
+
.withTables()
|
|
117
|
+
.insertInto(this.tables.sends)
|
|
118
|
+
.values(values)
|
|
119
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(updatableSendColumns(values)))
|
|
120
|
+
.execute());
|
|
121
|
+
}
|
|
122
|
+
/** All rows land or none do: the batch is one transaction. */
|
|
123
|
+
async saveBatch({ rows }, _optional = {}) {
|
|
124
|
+
if (rows.length === 0)
|
|
125
|
+
return;
|
|
126
|
+
await this.kernel.transaction(async () => {
|
|
127
|
+
for (const row of rows)
|
|
128
|
+
await this.save(row);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Atomically takes the dispatch lease on one send row (2026-09-16, see `ports.ts` doc). One
|
|
133
|
+
* conditional `UPDATE ... RETURNING` makes the claim atomic across processes and hands back the
|
|
134
|
+
* row it claimed, so nothing can change it between the write and the read.
|
|
135
|
+
*
|
|
136
|
+
* @complexity O(1) (indexed lookup by primary key).
|
|
137
|
+
*/
|
|
138
|
+
async claimForDispatch(required) {
|
|
139
|
+
const claimed = await this.kernel.run((db) => db
|
|
140
|
+
.withTables()
|
|
141
|
+
.updateTable(this.tables.sends)
|
|
142
|
+
.set({ next_attempt_at: required.leaseUntilIso, updated_at: required.nowIso })
|
|
143
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
144
|
+
.where("id", "=", required.id)
|
|
145
|
+
.where("status", "=", "pending")
|
|
146
|
+
.where((eb) => eb.or([eb("next_attempt_at", "is", null), eb("next_attempt_at", "<=", required.nowIso)]))
|
|
147
|
+
.returningAll()
|
|
148
|
+
.executeTakeFirst());
|
|
149
|
+
return claimed ? toSendRecord(claimed) : null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Atomically records a dispatch outcome (2026-09-16, see `ports.ts` doc). One conditional
|
|
153
|
+
* `UPDATE ... WHERE status = 'pending' RETURNING`: a concurrent second call matches zero rows and
|
|
154
|
+
* returns `null` without touching the row. A null `providerMessageId` keeps the stored one.
|
|
155
|
+
*
|
|
156
|
+
* @complexity O(1) (indexed lookup by primary key).
|
|
157
|
+
*/
|
|
158
|
+
async recordOutcome(required) {
|
|
159
|
+
const recorded = await this.kernel.run((db) => db
|
|
160
|
+
.withTables()
|
|
161
|
+
.updateTable(this.tables.sends)
|
|
162
|
+
.set((eb) => ({
|
|
163
|
+
status: required.status,
|
|
164
|
+
attempts: eb("attempts", "+", 1),
|
|
165
|
+
...(required.providerMessageId === null ? {} : { provider_message_id: required.providerMessageId }),
|
|
166
|
+
last_error: required.lastError,
|
|
167
|
+
next_attempt_at: null,
|
|
168
|
+
updated_at: required.updatedAt,
|
|
169
|
+
}))
|
|
170
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
171
|
+
.where("id", "=", required.id)
|
|
172
|
+
.where("status", "=", "pending")
|
|
173
|
+
.returningAll()
|
|
174
|
+
.executeTakeFirst());
|
|
175
|
+
return recorded ? toSendRecord(recorded) : null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=repo-sends.js.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type ListPage } from "@jini-ai/core/list-page";
|
|
2
|
+
import type { Kysely } from "kysely";
|
|
3
|
+
import type { StorageKernel } from "@jini-ai/core/contracts/storage";
|
|
4
|
+
import type { NewsletterConfirmationTokenRepoPort, NewsletterListRepoPort, NewsletterSubscriptionRepoPort } from "./ports.js";
|
|
5
|
+
import { type NewsletterSqlRequired, type NewsletterSqlTables } from "./repo.rows.js";
|
|
6
|
+
import type { ConfirmationTokenRecord, NewsletterListRow, SubscriptionRow } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* @file The list, subscription and confirmation-token repositories over the host's
|
|
9
|
+
* `p_newsletter__*` dataModule tables: one Kysely query body for every dialect, the table names
|
|
10
|
+
* passed in by the host ({@link NewsletterSqlTables}).
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_LIST_LIMIT = 100;
|
|
13
|
+
export declare class SqlNewsletterListRepo implements NewsletterListRepoPort {
|
|
14
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
15
|
+
protected readonly tables: Pick<NewsletterSqlTables, "lists">;
|
|
16
|
+
constructor(required: NewsletterSqlRequired<"lists">, _optional?: Record<string, never>);
|
|
17
|
+
findById(required: {
|
|
18
|
+
workspaceId: string;
|
|
19
|
+
id: string;
|
|
20
|
+
}): Promise<NewsletterListRow | null>;
|
|
21
|
+
findDefault(required: {
|
|
22
|
+
workspaceId: string;
|
|
23
|
+
}): Promise<NewsletterListRow | null>;
|
|
24
|
+
list(required: {
|
|
25
|
+
workspaceId: string;
|
|
26
|
+
}): Promise<NewsletterListRow[]>;
|
|
27
|
+
save(row: NewsletterListRow): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export declare class SqlNewsletterSubscriptionRepo implements NewsletterSubscriptionRepoPort {
|
|
30
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
31
|
+
protected readonly tables: Pick<NewsletterSqlTables, "subscriptions">;
|
|
32
|
+
constructor(required: NewsletterSqlRequired<"subscriptions">, _optional?: Record<string, never>);
|
|
33
|
+
findById(required: {
|
|
34
|
+
workspaceId: string;
|
|
35
|
+
id: string;
|
|
36
|
+
}): Promise<SubscriptionRow | null>;
|
|
37
|
+
findBySubscriberAndList(required: {
|
|
38
|
+
workspaceId: string;
|
|
39
|
+
listId: string;
|
|
40
|
+
subscriberId: string;
|
|
41
|
+
}): Promise<SubscriptionRow | null>;
|
|
42
|
+
/** Lists one workspace/list's subscriptions by ID using a position-based cursor.
|
|
43
|
+
* @throws {ToolInputError} If the cursor is malformed; storage failures propagate.
|
|
44
|
+
* @complexity O(limit) returned rows in one indexed query.
|
|
45
|
+
*/
|
|
46
|
+
list(required: {
|
|
47
|
+
workspaceId: string;
|
|
48
|
+
listId: string;
|
|
49
|
+
}, optional?: {
|
|
50
|
+
limit?: number;
|
|
51
|
+
cursor?: string | null;
|
|
52
|
+
}): Promise<ListPage<SubscriptionRow>>;
|
|
53
|
+
listSubscribed(required: {
|
|
54
|
+
workspaceId: string;
|
|
55
|
+
listId: string;
|
|
56
|
+
}): Promise<SubscriptionRow[]>;
|
|
57
|
+
save(row: SubscriptionRow): Promise<void>;
|
|
58
|
+
remove(required: {
|
|
59
|
+
workspaceId: string;
|
|
60
|
+
id: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
export declare class SqlNewsletterConfirmationTokenRepo implements NewsletterConfirmationTokenRepoPort {
|
|
64
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
65
|
+
protected readonly tables: Pick<NewsletterSqlTables, "confirmationTokens">;
|
|
66
|
+
constructor(required: NewsletterSqlRequired<"confirmationTokens">, _optional?: Record<string, never>);
|
|
67
|
+
findById(required: {
|
|
68
|
+
workspaceId: string;
|
|
69
|
+
id: string;
|
|
70
|
+
}): Promise<ConfirmationTokenRecord | null>;
|
|
71
|
+
findUnconsumedBySubscription(required: {
|
|
72
|
+
workspaceId: string;
|
|
73
|
+
subscriptionId: string;
|
|
74
|
+
}): Promise<ConfirmationTokenRecord[]>;
|
|
75
|
+
findByTokenHash(required: {
|
|
76
|
+
workspaceId: string;
|
|
77
|
+
tokenHash: string;
|
|
78
|
+
}): Promise<ConfirmationTokenRecord | null>;
|
|
79
|
+
/** Upsert by id; a re-save only ever moves `consumed_at` (the rest of a token is immutable). */
|
|
80
|
+
save(row: ConfirmationTokenRecord): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=repo-subscribers.d.ts.map
|