@cosmicdrift/kumiko-samples 0.405.0 → 0.409.0
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/package.json +1 -1
- package/packages/bundled-features/package.json +26 -4
- package/packages/bundled-features/src/account-security/feature.ts +9 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
- package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
- package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
- package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
- package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
- package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
- package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
- package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
- package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
- package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
- package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
- package/packages/bundled-features/src/contact/challenge.ts +41 -0
- package/packages/bundled-features/src/contact/changes.json +27 -0
- package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
- package/packages/bundled-features/src/contact/entity.ts +168 -0
- package/packages/bundled-features/src/contact/feature.ts +171 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
- package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
- package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
- package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
- package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
- package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
- package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
- package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
- package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
- package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
- package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
- package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
- package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
- package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
- package/packages/bundled-features/src/contact/i18n.ts +189 -0
- package/packages/bundled-features/src/contact/index.ts +29 -0
- package/packages/bundled-features/src/contact/lib.ts +176 -0
- package/packages/bundled-features/src/contact/mail.ts +401 -0
- package/packages/bundled-features/src/contact/options.ts +95 -0
- package/packages/bundled-features/src/contact/panels.ts +28 -0
- package/packages/bundled-features/src/contact/payloads.ts +106 -0
- package/packages/bundled-features/src/contact/pow.ts +22 -0
- package/packages/bundled-features/src/contact/screens.ts +506 -0
- package/packages/bundled-features/src/contact/subject.ts +13 -0
- package/packages/bundled-features/src/contact/user-agent.ts +39 -0
- package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
- package/packages/bundled-features/src/contact/web/constants.ts +160 -0
- package/packages/bundled-features/src/contact/web/index.ts +29 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
- package/packages/bundled-features/src/data-retention/changes.json +6 -0
- package/packages/bundled-features/src/data-retention/feature.ts +16 -2
- package/packages/bundled-features/src/data-retention/index.ts +5 -0
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
- package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +7 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
- package/packages/bundled-features/src/delivery/events.ts +2 -0
- package/packages/bundled-features/src/delivery/feature.ts +3 -2
- package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
- package/packages/bundled-features/src/delivery/jobs.ts +5 -0
- package/packages/bundled-features/src/delivery/tables.ts +13 -2
- package/packages/bundled-features/src/delivery/types.ts +3 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
- package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
- package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
- package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
- package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
- package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
- package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
- package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
- package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
- package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
- package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
- package/packages/bundled-features/src/ledger/recurring.ts +1 -0
- package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
- package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
- package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
- package/packages/bundled-features/src/sessions/changes.json +6 -0
- package/packages/bundled-features/src/sessions/feature.ts +21 -18
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
- package/packages/bundled-features/src/sessions/screens.ts +1 -0
- package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
- package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
- package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
- package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
- package/packages/bundled-features/src/shared/index.ts +16 -0
- package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
- package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
- package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
- package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
- package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
- package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
- package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
- package/packages/bundled-features/src/shared/web/index.ts +3 -0
- package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
- package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
- package/packages/bundled-features/src/tags/entity.ts +1 -0
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
- package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
- package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
- package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +11 -8
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
- package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
- package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
- package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
- package/packages/bundled-features/src/tenant/i18n.ts +3 -0
- package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
- package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
- package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +56 -0
- package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
- package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
- package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
- package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
- package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
- package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
- package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
- package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +30 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/events.ts +2 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +25 -2
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
- package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +131 -11
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +39 -4
- package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
- package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
- package/packages/bundled-features/src/tier-engine/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
- package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
- package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
- package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +134 -2
- package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -0
- package/samples/apps/use-all-bundled/playwright.config.ts +2 -0
- package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +38 -4
- package/samples/recipes/contact/README.md +46 -0
- package/samples/recipes/contact/package.json +12 -0
- package/samples/recipes/contact/src/feature.ts +27 -0
- package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
- package/samples/recipes/lane-routing/README.md +1 -0
- package/samples/recipes/lane-routing/src/feature.ts +8 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
- package/samples/recipes/search/README.md +2 -0
- package/samples/recipes/search/src/feature.ts +27 -2
- package/samples/recipes/secrets-demo/README.md +1 -0
- package/samples/recipes/secrets-demo/src/feature.ts +56 -0
- package/samples/recipes/tenant-inactivity/README.md +21 -0
- package/samples/recipes/tenant-inactivity/package.json +12 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import {
|
|
2
|
+
access,
|
|
3
|
+
createSystemConfig,
|
|
4
|
+
defineFeature,
|
|
5
|
+
EXT_USER_DATA,
|
|
6
|
+
type FeatureDefinition,
|
|
7
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
+
import { CONTACT_CLIENT_SOURCE } from "./client/contact-client-source.ts";
|
|
9
|
+
import {
|
|
10
|
+
contactReplyEntity,
|
|
11
|
+
contactRequestEntity,
|
|
12
|
+
createContactReplyEntity,
|
|
13
|
+
createContactRequestEntity,
|
|
14
|
+
} from "./entity.ts";
|
|
15
|
+
import { createChallengeQuery } from "./handlers/challenge.query.ts";
|
|
16
|
+
import { createForwardRequestHandler } from "./handlers/forward-request.write.ts";
|
|
17
|
+
import { markDoneHandler } from "./handlers/mark-done.write.ts";
|
|
18
|
+
import { notifyReporterInAppHandler } from "./handlers/notify-reporter-in-app.write.ts";
|
|
19
|
+
import { openCountQuery } from "./handlers/open-count.query.ts";
|
|
20
|
+
import { repliesQuery } from "./handlers/replies.query.ts";
|
|
21
|
+
import { createReplyHandler } from "./handlers/reply.write.ts";
|
|
22
|
+
import { createReportHandler } from "./handlers/report.write.ts";
|
|
23
|
+
import { createRequestDeliveryQuery } from "./handlers/request-delivery.query.ts";
|
|
24
|
+
import { createRequestDetailQuery } from "./handlers/request-detail.query.ts";
|
|
25
|
+
import { createRequestListQuery } from "./handlers/request-list.query.ts";
|
|
26
|
+
import { createSendReplyMailHandler } from "./handlers/send-reply-mail.write.ts";
|
|
27
|
+
import { createSendTestHandler } from "./handlers/send-test.write.ts";
|
|
28
|
+
import { createSubmitHandler } from "./handlers/submit.write.ts";
|
|
29
|
+
import { createContactI18n } from "./i18n.ts";
|
|
30
|
+
import { TELEGRAM_FEATURE } from "./lib.ts";
|
|
31
|
+
import {
|
|
32
|
+
CONTACT_ACKNOWLEDGEMENT_VARIABLES,
|
|
33
|
+
CONTACT_CONFIRMATION_VARIABLES,
|
|
34
|
+
CONTACT_NEW_REQUEST_VARIABLES,
|
|
35
|
+
CONTACT_REPLY_VARIABLES,
|
|
36
|
+
CONTACT_TEST_VARIABLES,
|
|
37
|
+
contactAcknowledgementTemplate,
|
|
38
|
+
contactConfirmationTemplate,
|
|
39
|
+
contactNewRequestTemplate,
|
|
40
|
+
contactReplyTemplate,
|
|
41
|
+
contactTestTemplate,
|
|
42
|
+
inAppTemplate,
|
|
43
|
+
telegramTemplate,
|
|
44
|
+
} from "./mail.ts";
|
|
45
|
+
import {
|
|
46
|
+
type ContactOptions,
|
|
47
|
+
DEFAULT_RETENTION_KEEP_FOR,
|
|
48
|
+
resolveContactSettings,
|
|
49
|
+
} from "./options.ts";
|
|
50
|
+
import { createContactScreens } from "./screens.ts";
|
|
51
|
+
import { contactDeleteHook, contactExportHook } from "./user-data-hooks.ts";
|
|
52
|
+
import { CONTACT_FEATURE } from "./web/constants.ts";
|
|
53
|
+
|
|
54
|
+
const REPLY_CONTEXT_FIELDS = ["name", "email", "replyTo"];
|
|
55
|
+
|
|
56
|
+
export function createContactFeature(opts: ContactOptions): FeatureDefinition {
|
|
57
|
+
const settings = resolveContactSettings(opts);
|
|
58
|
+
const telegram = opts.telegram === true;
|
|
59
|
+
const keepFor = opts.retentionKeepFor ?? DEFAULT_RETENTION_KEEP_FOR;
|
|
60
|
+
const requestEntity =
|
|
61
|
+
keepFor === DEFAULT_RETENTION_KEEP_FOR
|
|
62
|
+
? contactRequestEntity
|
|
63
|
+
: createContactRequestEntity(keepFor);
|
|
64
|
+
const replyEntity =
|
|
65
|
+
keepFor === DEFAULT_RETENTION_KEEP_FOR ? contactReplyEntity : createContactReplyEntity(keepFor);
|
|
66
|
+
|
|
67
|
+
return defineFeature(CONTACT_FEATURE, (r) => {
|
|
68
|
+
r.describe(
|
|
69
|
+
"Contact inbox: an anonymous browser client (GET /contact/client.js) submits questions, contact requests, bug reports and wishes behind a honeypot, a minimum submit time and a single-use proof-of-work challenge; signed-in users file reports from the admin. Every request is stored platform-wide and every SystemAdmin is notified by mail, optionally also in a Telegram chat (option `telegram`, off by default); the notification names only the kind, the app and a link, never name, address, phone, subject or message, because mail and Telegram cannot be shredded. SystemAdmins reply by mail (Reply-To set, attachments, quoting the original) and mark requests done; a website sender gets a fixed acknowledgement, a signed-in reporter a copy and an in-app note. Personal data is crypto-shredding-ready and the EXT_USER_DATA hooks export and erase a user's requests.",
|
|
70
|
+
);
|
|
71
|
+
r.uiHints({ displayLabel: "Contact", category: "communication", recommended: false });
|
|
72
|
+
r.systemScope();
|
|
73
|
+
r.requires({ features: ["config", "delivery", "user-data-rights", "files", "notes-history"] });
|
|
74
|
+
if (telegram) r.requires({ features: [TELEGRAM_FEATURE] });
|
|
75
|
+
r.adoptsBundledLists();
|
|
76
|
+
r.translations({ keys: createContactI18n() });
|
|
77
|
+
|
|
78
|
+
r.config({
|
|
79
|
+
keys: {
|
|
80
|
+
replyTo: createSystemConfig("text", {
|
|
81
|
+
default: "",
|
|
82
|
+
write: access.systemAdmin,
|
|
83
|
+
read: access.systemAdmin,
|
|
84
|
+
pattern: { regex: "^$|^[^\\s@<>]{1,64}@[^\\s@<>]{1,200}\\.[^\\s@<>]{2,24}$" },
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
if (telegram) {
|
|
89
|
+
r.config({
|
|
90
|
+
keys: {
|
|
91
|
+
telegramChat: createSystemConfig("text", {
|
|
92
|
+
default: "",
|
|
93
|
+
write: access.systemAdmin,
|
|
94
|
+
read: access.systemAdmin,
|
|
95
|
+
pattern: { regex: "^$|^(-?[0-9]{1,20}|@[A-Za-z0-9_]{5,32})$" },
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
r.notification("new-request", {
|
|
102
|
+
variables: CONTACT_NEW_REQUEST_VARIABLES,
|
|
103
|
+
localizedTemplate: contactNewRequestTemplate,
|
|
104
|
+
...(telegram && { templates: { telegram: telegramTemplate } }),
|
|
105
|
+
});
|
|
106
|
+
r.notification("confirmation", {
|
|
107
|
+
variables: CONTACT_CONFIRMATION_VARIABLES,
|
|
108
|
+
localizedTemplate: contactConfirmationTemplate,
|
|
109
|
+
});
|
|
110
|
+
r.notification("acknowledgement", {
|
|
111
|
+
variables: CONTACT_ACKNOWLEDGEMENT_VARIABLES,
|
|
112
|
+
localizedTemplate: contactAcknowledgementTemplate,
|
|
113
|
+
});
|
|
114
|
+
r.notification("reply", {
|
|
115
|
+
variables: CONTACT_REPLY_VARIABLES,
|
|
116
|
+
localizedTemplate: contactReplyTemplate,
|
|
117
|
+
});
|
|
118
|
+
r.notification("reply-in-app", { templates: { inApp: inAppTemplate } });
|
|
119
|
+
if (telegram) {
|
|
120
|
+
r.notification("test", {
|
|
121
|
+
variables: CONTACT_TEST_VARIABLES,
|
|
122
|
+
localizedTemplate: contactTestTemplate,
|
|
123
|
+
templates: { telegram: telegramTemplate },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
r.entity({ name: "contact-request", ...requestEntity });
|
|
128
|
+
r.entity({ name: "contact-reply", ...replyEntity });
|
|
129
|
+
|
|
130
|
+
r.writeHandler(createSubmitHandler(opts, settings));
|
|
131
|
+
r.writeHandler(createReportHandler(opts, settings));
|
|
132
|
+
r.writeHandler(createForwardRequestHandler(opts));
|
|
133
|
+
// The detail drawer prefills these for the form summary only; the form never sends them.
|
|
134
|
+
r.writeHandler({ ...createReplyHandler(), excludedFields: REPLY_CONTEXT_FIELDS });
|
|
135
|
+
r.writeHandler(createSendReplyMailHandler(opts));
|
|
136
|
+
r.writeHandler(notifyReporterInAppHandler);
|
|
137
|
+
r.writeHandler(markDoneHandler);
|
|
138
|
+
if (telegram) r.writeHandler(createSendTestHandler(opts));
|
|
139
|
+
|
|
140
|
+
r.queryHandler(createChallengeQuery(settings));
|
|
141
|
+
r.queryHandler(openCountQuery);
|
|
142
|
+
r.queryHandler(createRequestListQuery(requestEntity));
|
|
143
|
+
r.queryHandler(createRequestDetailQuery(opts));
|
|
144
|
+
r.queryHandler(repliesQuery);
|
|
145
|
+
r.queryHandler(createRequestDeliveryQuery(opts));
|
|
146
|
+
|
|
147
|
+
for (const screen of createContactScreens(opts, settings)) r.screen(screen);
|
|
148
|
+
|
|
149
|
+
r.httpRoute({
|
|
150
|
+
method: "GET",
|
|
151
|
+
// A literal, not CONTACT_CLIENT_PATH: the feature-AST extractor only reads string literals.
|
|
152
|
+
path: "/contact/client.js",
|
|
153
|
+
anonymous: true,
|
|
154
|
+
handler: async (c) =>
|
|
155
|
+
c.body(CONTACT_CLIENT_SOURCE, 200, {
|
|
156
|
+
"content-type": "application/javascript; charset=utf-8",
|
|
157
|
+
"cache-control": "public, max-age=300",
|
|
158
|
+
}),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
r.useExtension(EXT_USER_DATA, "contact-request", {
|
|
162
|
+
export: contactExportHook,
|
|
163
|
+
delete: contactDeleteHook,
|
|
164
|
+
});
|
|
165
|
+
// Replies are exported nested under their request and erased with it (contactDeleteHook).
|
|
166
|
+
r.useExtension(EXT_USER_DATA, "contact-reply", {
|
|
167
|
+
export: async () => null,
|
|
168
|
+
delete: async () => {},
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { access } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
|
|
3
|
+
// The website client sends without a session (credentials: "omit"), so it always arrives as anonymous; the signed-in roles only cover other callers.
|
|
4
|
+
export const SUBMIT_ROLES = access.roles(
|
|
5
|
+
...access.anonymous,
|
|
6
|
+
...access.authenticated,
|
|
7
|
+
"Member",
|
|
8
|
+
"TenantAdmin",
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const REPORT_ACCESS = {
|
|
12
|
+
openToAll: {
|
|
13
|
+
reason:
|
|
14
|
+
"every signed-in user may report a problem; name, email and tenant come from the session and the request is bound to the caller's own userId",
|
|
15
|
+
personalData: "tenant-members",
|
|
16
|
+
},
|
|
17
|
+
} as const;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSystemUser,
|
|
3
|
+
type HandlerContext,
|
|
4
|
+
type SessionUser,
|
|
5
|
+
type TenantId,
|
|
6
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
7
|
+
import { IN_APP_NOTIFICATION_QUERIES } from "@cosmicdrift/kumiko-types/in-app-notification-types";
|
|
8
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
9
|
+
import * as z from "zod";
|
|
10
|
+
import { DeliveryQueries } from "../../delivery/index.ts";
|
|
11
|
+
import { SYSTEM_ADMIN_ROLE } from "../lib.ts";
|
|
12
|
+
|
|
13
|
+
// Both queries accept at most this many keys per call.
|
|
14
|
+
const MAX_KEYS_PER_QUERY = 50;
|
|
15
|
+
|
|
16
|
+
const instant = z.custom<Temporal.Instant>((value) => value instanceof Temporal.Instant);
|
|
17
|
+
|
|
18
|
+
const attemptSchema = z.object({
|
|
19
|
+
key: z.string(),
|
|
20
|
+
channel: z.string(),
|
|
21
|
+
recipientId: z.string().nullable(),
|
|
22
|
+
status: z.string(),
|
|
23
|
+
createdAt: instant,
|
|
24
|
+
});
|
|
25
|
+
const attemptsResultSchema = z.object({ rows: z.array(attemptSchema) });
|
|
26
|
+
|
|
27
|
+
const readStateResultSchema = z.object({
|
|
28
|
+
rows: z.array(z.object({ key: z.string(), readAt: instant.nullable() })),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type ContactAttempt = z.infer<typeof attemptSchema>;
|
|
32
|
+
|
|
33
|
+
function chunked(keys: readonly string[]): readonly (readonly string[])[] {
|
|
34
|
+
const chunks: string[][] = [];
|
|
35
|
+
for (let start = 0; start < keys.length; start += MAX_KEYS_PER_QUERY) {
|
|
36
|
+
chunks.push(keys.slice(start, start + MAX_KEYS_PER_QUERY));
|
|
37
|
+
}
|
|
38
|
+
return chunks;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function loadAttemptsByKey(
|
|
42
|
+
ctx: Pick<HandlerContext, "dispatch">,
|
|
43
|
+
user: SessionUser,
|
|
44
|
+
keys: readonly string[],
|
|
45
|
+
): Promise<readonly ContactAttempt[]> {
|
|
46
|
+
const rows: ContactAttempt[] = [];
|
|
47
|
+
for (const chunk of chunked(keys)) {
|
|
48
|
+
const result = await ctx.dispatch.queryAs(user, DeliveryQueries.attemptsByKeys, {
|
|
49
|
+
keys: chunk,
|
|
50
|
+
});
|
|
51
|
+
rows.push(...attemptsResultSchema.parse(result).rows);
|
|
52
|
+
}
|
|
53
|
+
return rows;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The in-app notes of a request live in the reporter's tenant, so the read state is asked there.
|
|
57
|
+
// Empty when channel-in-app is not mounted: nothing can have been read then.
|
|
58
|
+
export async function loadReadAtByKey(
|
|
59
|
+
ctx: Pick<HandlerContext, "dispatch" | "registry">,
|
|
60
|
+
reporterTenantId: TenantId,
|
|
61
|
+
keys: readonly string[],
|
|
62
|
+
): Promise<ReadonlyMap<string, Temporal.Instant | null>> {
|
|
63
|
+
const readAtByKey = new Map<string, Temporal.Instant | null>();
|
|
64
|
+
if (ctx.registry.getQueryHandler(IN_APP_NOTIFICATION_QUERIES.readStateByKeys) === undefined) {
|
|
65
|
+
return readAtByKey;
|
|
66
|
+
}
|
|
67
|
+
const user = createSystemUser(reporterTenantId, [SYSTEM_ADMIN_ROLE]);
|
|
68
|
+
for (const chunk of chunked(keys)) {
|
|
69
|
+
const result = await ctx.dispatch.queryAs(user, IN_APP_NOTIFICATION_QUERIES.readStateByKeys, {
|
|
70
|
+
keys: chunk,
|
|
71
|
+
});
|
|
72
|
+
for (const row of readStateResultSchema.parse(result).rows)
|
|
73
|
+
readAtByKey.set(row.key, row.readAt);
|
|
74
|
+
}
|
|
75
|
+
return readAtByKey;
|
|
76
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import { issueChallenge } from "../challenge.ts";
|
|
4
|
+
import { CHALLENGE_RATE_LIMIT, type ContactSettings } from "../options.ts";
|
|
5
|
+
import { ContactEmptySchema } from "../payloads.ts";
|
|
6
|
+
import { CONTACT_WEBSITE_KINDS, type ContactPhoneMode } from "../web/constants.ts";
|
|
7
|
+
import { SUBMIT_ROLES } from "./access.ts";
|
|
8
|
+
|
|
9
|
+
export type ContactChallengeData = {
|
|
10
|
+
readonly challenge: string;
|
|
11
|
+
readonly bits: number;
|
|
12
|
+
readonly phone: ContactPhoneMode;
|
|
13
|
+
readonly kinds: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function createChallengeQuery(settings: ContactSettings) {
|
|
17
|
+
return defineQueryHandler({
|
|
18
|
+
name: "challenge",
|
|
19
|
+
schema: ContactEmptySchema,
|
|
20
|
+
access: { roles: SUBMIT_ROLES, personalData: "public-intake" },
|
|
21
|
+
rateLimit: CHALLENGE_RATE_LIMIT,
|
|
22
|
+
agent: { expose: false },
|
|
23
|
+
description:
|
|
24
|
+
"Public contact form bootstrap: issues a single-use proof-of-work challenge and reports which fields the form shows (phone mode, request kinds).",
|
|
25
|
+
handler: async (_event, ctx): Promise<ContactChallengeData> => {
|
|
26
|
+
if (!ctx.services.redis) {
|
|
27
|
+
throw new InternalError({
|
|
28
|
+
message: "contact:challenge requires ctx.services.redis for the challenge store",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const challenge = await issueChallenge(ctx.services.redis, {
|
|
32
|
+
bits: settings.proofOfWorkBits,
|
|
33
|
+
ttlSeconds: settings.challengeTtlSeconds,
|
|
34
|
+
nowMs: ctx.tz.now().epochMilliseconds,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
challenge,
|
|
38
|
+
bits: settings.proofOfWorkBits,
|
|
39
|
+
phone: settings.phone,
|
|
40
|
+
kinds: CONTACT_WEBSITE_KINDS,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import {
|
|
4
|
+
contactDb,
|
|
5
|
+
internalAccess,
|
|
6
|
+
listSystemAdminIds,
|
|
7
|
+
platformActor,
|
|
8
|
+
requestExecutor,
|
|
9
|
+
sendBestEffort,
|
|
10
|
+
} from "../lib.ts";
|
|
11
|
+
import { contactNewRequestVariables, resolveContactMailLocale } from "../mail.ts";
|
|
12
|
+
import type { ContactOptions } from "../options.ts";
|
|
13
|
+
import { ContactForwardRequestSchema } from "../payloads.ts";
|
|
14
|
+
import {
|
|
15
|
+
CONTACT_NOTIFICATION_TYPES,
|
|
16
|
+
CONTACT_REQUEST_ENTITY,
|
|
17
|
+
ContactConfigKeys,
|
|
18
|
+
contactIdempotencyKeys,
|
|
19
|
+
} from "../web/constants.ts";
|
|
20
|
+
|
|
21
|
+
const EMAIL_CHANNEL = "email";
|
|
22
|
+
|
|
23
|
+
export type ContactForwardData = {
|
|
24
|
+
readonly kind: "forwarded";
|
|
25
|
+
readonly adminCount: number;
|
|
26
|
+
readonly telegram: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Runs as the platform identity so the notification, the config and the bot token secret are
|
|
30
|
+
// read in the system tenant, whoever filed the request.
|
|
31
|
+
export function createForwardRequestHandler(opts: ContactOptions) {
|
|
32
|
+
return defineWriteHandler<
|
|
33
|
+
"forward-request",
|
|
34
|
+
typeof ContactForwardRequestSchema,
|
|
35
|
+
ContactForwardData
|
|
36
|
+
>({
|
|
37
|
+
name: "forward-request",
|
|
38
|
+
schema: ContactForwardRequestSchema,
|
|
39
|
+
access: internalAccess,
|
|
40
|
+
agent: { expose: false },
|
|
41
|
+
description:
|
|
42
|
+
"Internal: forwards a stored contact request to every SystemAdmin by mail and, when a Telegram chat is configured, to that chat. Only the platform identity can call it.",
|
|
43
|
+
handler: async (event, ctx) => {
|
|
44
|
+
const db = contactDb(ctx);
|
|
45
|
+
const request = await requestExecutor.detail(
|
|
46
|
+
{ id: event.payload.requestId },
|
|
47
|
+
platformActor(),
|
|
48
|
+
db,
|
|
49
|
+
);
|
|
50
|
+
if (!request) {
|
|
51
|
+
return writeFailure(new NotFoundError(CONTACT_REQUEST_ENTITY, event.payload.requestId));
|
|
52
|
+
}
|
|
53
|
+
const requestId = event.payload.requestId;
|
|
54
|
+
const adminLocale = opts.adminLocale;
|
|
55
|
+
const link = opts.requestLink?.(requestId);
|
|
56
|
+
const data = contactNewRequestVariables({
|
|
57
|
+
kind: request.kind,
|
|
58
|
+
appName: opts.appName,
|
|
59
|
+
link,
|
|
60
|
+
locale: adminLocale,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const adminIds = await listSystemAdminIds(db);
|
|
64
|
+
if (adminIds.length > 0) {
|
|
65
|
+
await sendBestEffort(ctx, "admin mail", (notify) =>
|
|
66
|
+
notify(CONTACT_NOTIFICATION_TYPES.newRequest, {
|
|
67
|
+
to: adminIds,
|
|
68
|
+
channels: [EMAIL_CHANNEL],
|
|
69
|
+
data,
|
|
70
|
+
idempotencyKey: contactIdempotencyKeys.admins(requestId),
|
|
71
|
+
priority: "normal",
|
|
72
|
+
locale: resolveContactMailLocale(adminLocale),
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const chatId = opts.telegram ? await ctx.config?.(ContactConfigKeys.telegramChat) : undefined;
|
|
78
|
+
const telegram = opts.telegram === true && typeof chatId === "string" && chatId.trim() !== "";
|
|
79
|
+
if (telegram) {
|
|
80
|
+
await sendBestEffort(ctx, "telegram", (notify) =>
|
|
81
|
+
notify(CONTACT_NOTIFICATION_TYPES.newRequest, {
|
|
82
|
+
route: { telegram: chatId.trim() },
|
|
83
|
+
recipientId: requestId,
|
|
84
|
+
data,
|
|
85
|
+
idempotencyKey: contactIdempotencyKeys.telegram(requestId),
|
|
86
|
+
priority: "normal",
|
|
87
|
+
locale: resolveContactMailLocale(adminLocale),
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
isSuccess: true,
|
|
94
|
+
data: { kind: "forwarded", adminCount: adminIds.length, telegram },
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import { adminAccess, contactDb, platformActor, requestExecutor } from "../lib.ts";
|
|
4
|
+
import { ContactMarkDoneSchema } from "../payloads.ts";
|
|
5
|
+
import { CONTACT_REQUEST_ENTITY, CONTACT_STATUS } from "../web/constants.ts";
|
|
6
|
+
|
|
7
|
+
export type ContactMarkDoneData = { readonly kind: "marked"; readonly changed: number };
|
|
8
|
+
|
|
9
|
+
export const markDoneHandler = defineWriteHandler<
|
|
10
|
+
"mark-done",
|
|
11
|
+
typeof ContactMarkDoneSchema,
|
|
12
|
+
ContactMarkDoneData
|
|
13
|
+
>({
|
|
14
|
+
name: "mark-done",
|
|
15
|
+
schema: ContactMarkDoneSchema,
|
|
16
|
+
access: adminAccess,
|
|
17
|
+
agent: { expose: false },
|
|
18
|
+
description:
|
|
19
|
+
"Marks one contact request as done without sending a reply; a finished request is left as it is.",
|
|
20
|
+
handler: async (event, ctx) => {
|
|
21
|
+
const db = contactDb(ctx);
|
|
22
|
+
const { id } = event.payload;
|
|
23
|
+
const request = await requestExecutor.detail({ id }, platformActor(), db);
|
|
24
|
+
if (!request) return writeFailure(new NotFoundError(CONTACT_REQUEST_ENTITY, id));
|
|
25
|
+
if (request.status === CONTACT_STATUS.Done) {
|
|
26
|
+
return { isSuccess: true, data: { kind: "marked", changed: 0 } };
|
|
27
|
+
}
|
|
28
|
+
const updated = await requestExecutor.update(
|
|
29
|
+
{
|
|
30
|
+
id,
|
|
31
|
+
version: request.version,
|
|
32
|
+
changes: { status: CONTACT_STATUS.Done, closedAt: ctx.tz.now() },
|
|
33
|
+
},
|
|
34
|
+
platformActor(),
|
|
35
|
+
db,
|
|
36
|
+
);
|
|
37
|
+
if (!updated.isSuccess) return updated;
|
|
38
|
+
return { isSuccess: true, data: { kind: "marked", changed: 1 } };
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { tenantMembershipsTable } from "../../tenant/index.ts";
|
|
4
|
+
import { contactDb, IN_APP_FEATURE, internalAccess, sendBestEffort } from "../lib.ts";
|
|
5
|
+
import { contactReplyInAppData, resolveContactMailLocale } from "../mail.ts";
|
|
6
|
+
import { ContactNotifyReporterInAppSchema } from "../payloads.ts";
|
|
7
|
+
import { CONTACT_NOTIFICATION_TYPES, contactIdempotencyKeys } from "../web/constants.ts";
|
|
8
|
+
|
|
9
|
+
export type ContactNotifyReporterData = {
|
|
10
|
+
readonly kind: "notified" | "skipped";
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Runs as the platform identity of the reporter's tenant, so the in-app note lands in that
|
|
14
|
+
// tenant's inbox. The note names the author only; the answer itself goes by mail.
|
|
15
|
+
export const notifyReporterInAppHandler = defineWriteHandler<
|
|
16
|
+
"notify-reporter-in-app",
|
|
17
|
+
typeof ContactNotifyReporterInAppSchema,
|
|
18
|
+
ContactNotifyReporterData
|
|
19
|
+
>({
|
|
20
|
+
name: "notify-reporter-in-app",
|
|
21
|
+
schema: ContactNotifyReporterInAppSchema,
|
|
22
|
+
access: internalAccess,
|
|
23
|
+
agent: { expose: false },
|
|
24
|
+
description:
|
|
25
|
+
"Internal: adds an in-app note about a contact reply to a signed-in reporter in the reporter's own tenant; skipped when the reporter is no longer a member or in-app delivery is not mounted.",
|
|
26
|
+
handler: async (event, ctx) => {
|
|
27
|
+
const { userId, replyId, authorName, locale } = event.payload;
|
|
28
|
+
if (!(await ctx.hasFeature(IN_APP_FEATURE)))
|
|
29
|
+
return { isSuccess: true, data: { kind: "skipped" } };
|
|
30
|
+
const membership = await fetchOne(contactDb(ctx), tenantMembershipsTable, {
|
|
31
|
+
userId,
|
|
32
|
+
tenantId: event.user.tenantId,
|
|
33
|
+
});
|
|
34
|
+
if (!membership) return { isSuccess: true, data: { kind: "skipped" } };
|
|
35
|
+
|
|
36
|
+
await sendBestEffort(ctx, "reply in-app note", (notify) =>
|
|
37
|
+
notify(CONTACT_NOTIFICATION_TYPES.replyInApp, {
|
|
38
|
+
route: { inApp: userId },
|
|
39
|
+
recipientId: userId,
|
|
40
|
+
data: contactReplyInAppData({ authorName, locale }),
|
|
41
|
+
idempotencyKey: contactIdempotencyKeys.replyInApp(replyId),
|
|
42
|
+
priority: "normal",
|
|
43
|
+
locale: resolveContactMailLocale(locale),
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
return { isSuccess: true, data: { kind: "notified" } };
|
|
47
|
+
},
|
|
48
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { adminAccess, contactDb } from "../lib.ts";
|
|
3
|
+
import { ContactEmptySchema } from "../payloads.ts";
|
|
4
|
+
import { countOpenRequests } from "./open-count.ts";
|
|
5
|
+
|
|
6
|
+
export const openCountQuery = defineQueryHandler({
|
|
7
|
+
name: "open-count",
|
|
8
|
+
schema: ContactEmptySchema,
|
|
9
|
+
access: adminAccess,
|
|
10
|
+
description:
|
|
11
|
+
"Counts the contact requests that still wait for a first answer, for the dashboard tile.",
|
|
12
|
+
handler: async (_event, ctx) => {
|
|
13
|
+
return { count: await countOpenRequests(contactDb(ctx)) };
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { platformActor, requestExecutor } from "../lib.ts";
|
|
3
|
+
import { CONTACT_STATUS } from "../web/constants.ts";
|
|
4
|
+
|
|
5
|
+
// Open means no answer yet; an answered request counts as handled even before it is marked done.
|
|
6
|
+
export async function countOpenRequests(db: TenantDb): Promise<number> {
|
|
7
|
+
const found = await requestExecutor.list(
|
|
8
|
+
{
|
|
9
|
+
filter: { field: "status", op: "eq", value: CONTACT_STATUS.Open },
|
|
10
|
+
limit: 1,
|
|
11
|
+
totalCount: true,
|
|
12
|
+
},
|
|
13
|
+
platformActor(),
|
|
14
|
+
db,
|
|
15
|
+
);
|
|
16
|
+
return found.total ?? 0;
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import { adminAccess, contactDb, listRepliesOf, platformActor, requestExecutor } from "../lib.ts";
|
|
4
|
+
import { ContactIdSchema } from "../payloads.ts";
|
|
5
|
+
import { CONTACT_REQUEST_ENTITY } from "../web/constants.ts";
|
|
6
|
+
|
|
7
|
+
export const repliesQuery = defineQueryHandler({
|
|
8
|
+
name: "replies",
|
|
9
|
+
schema: ContactIdSchema,
|
|
10
|
+
access: adminAccess,
|
|
11
|
+
description:
|
|
12
|
+
"Returns the answers SystemAdmins sent to one contact request (id, sent time, author name, message), oldest first, as flat rows for a related list; the request itself is not part of it.",
|
|
13
|
+
handler: async (event, ctx) => {
|
|
14
|
+
const db = contactDb(ctx);
|
|
15
|
+
const { id } = event.payload;
|
|
16
|
+
const request = await requestExecutor.detail({ id }, platformActor(), db);
|
|
17
|
+
if (!request) throw new NotFoundError(CONTACT_REQUEST_ENTITY, id);
|
|
18
|
+
const replies = await listRepliesOf(db, id);
|
|
19
|
+
return {
|
|
20
|
+
rows: replies.map((reply) => ({
|
|
21
|
+
id: reply.id,
|
|
22
|
+
sentAt: reply.sentAt.toString(),
|
|
23
|
+
authorName: reply.authorName,
|
|
24
|
+
message: reply.message,
|
|
25
|
+
})),
|
|
26
|
+
nextCursor: null,
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|