@cosmicdrift/kumiko-samples 0.406.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 +18 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +24 -1
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +4 -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 +58 -5
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +31 -2
- 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/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,106 @@
|
|
|
1
|
+
import { canonicalizeLocaleTag, isValidLocaleTag } from "@cosmicdrift/kumiko-framework/i18n";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
import {
|
|
4
|
+
CONTACT_ADMIN_KINDS,
|
|
5
|
+
CONTACT_FIELD_LIMITS,
|
|
6
|
+
CONTACT_MAX_FILES,
|
|
7
|
+
CONTACT_WEBSITE_KINDS,
|
|
8
|
+
} from "./web/constants.ts";
|
|
9
|
+
|
|
10
|
+
// Submitted text lands in mail subjects; CR/LF there would allow header injection.
|
|
11
|
+
const NO_CONTROL_CHARS = /^\P{Cc}*$/u;
|
|
12
|
+
const NO_CONTROL_CHARS_EXCEPT_WHITESPACE = /^(?:[^\p{Cc}]|[\n\r\t])*$/u;
|
|
13
|
+
const noControlChars = (value: string) => NO_CONTROL_CHARS.test(value);
|
|
14
|
+
const CONTROL_CHARS_MESSAGE = "control characters not allowed";
|
|
15
|
+
|
|
16
|
+
const singleLine = (max: number) =>
|
|
17
|
+
z.string().trim().min(1).max(max).refine(noControlChars, CONTROL_CHARS_MESSAGE);
|
|
18
|
+
|
|
19
|
+
const multiLine = (max: number) =>
|
|
20
|
+
z
|
|
21
|
+
.string()
|
|
22
|
+
.trim()
|
|
23
|
+
.min(1)
|
|
24
|
+
.max(max)
|
|
25
|
+
.refine((value) => NO_CONTROL_CHARS_EXCEPT_WHITESPACE.test(value), CONTROL_CHARS_MESSAGE);
|
|
26
|
+
|
|
27
|
+
// An empty phone field of a form counts as absent.
|
|
28
|
+
const phone = z
|
|
29
|
+
.string()
|
|
30
|
+
.trim()
|
|
31
|
+
.max(CONTACT_FIELD_LIMITS.phone)
|
|
32
|
+
.refine(noControlChars, CONTROL_CHARS_MESSAGE)
|
|
33
|
+
.optional();
|
|
34
|
+
|
|
35
|
+
const pagePath = z
|
|
36
|
+
.string()
|
|
37
|
+
.trim()
|
|
38
|
+
.max(CONTACT_FIELD_LIMITS.page)
|
|
39
|
+
.refine(noControlChars, CONTROL_CHARS_MESSAGE)
|
|
40
|
+
// Query strings and fragments carry tokens and ids (reset links, session hints) that must not
|
|
41
|
+
// end up in an inbox that is kept for a year.
|
|
42
|
+
.transform((value) => value.split(/[?#]/, 1)[0] ?? "")
|
|
43
|
+
.optional();
|
|
44
|
+
|
|
45
|
+
const locale = z
|
|
46
|
+
.string()
|
|
47
|
+
.max(CONTACT_FIELD_LIMITS.locale)
|
|
48
|
+
.refine(isValidLocaleTag, "invalid locale tag")
|
|
49
|
+
.transform(canonicalizeLocaleTag);
|
|
50
|
+
|
|
51
|
+
export const ContactSubmitSchema = z
|
|
52
|
+
.object({
|
|
53
|
+
kind: z.enum(CONTACT_WEBSITE_KINDS),
|
|
54
|
+
name: singleLine(CONTACT_FIELD_LIMITS.name),
|
|
55
|
+
email: z.email().max(CONTACT_FIELD_LIMITS.email),
|
|
56
|
+
phone,
|
|
57
|
+
message: multiLine(CONTACT_FIELD_LIMITS.message),
|
|
58
|
+
locale,
|
|
59
|
+
// Honeypot: bots fill it, humans leave it empty.
|
|
60
|
+
website: z.string().max(CONTACT_FIELD_LIMITS.honeypot).optional(),
|
|
61
|
+
challenge: z.string().max(CONTACT_FIELD_LIMITS.challenge),
|
|
62
|
+
nonce: z.string().max(CONTACT_FIELD_LIMITS.nonce),
|
|
63
|
+
page: pagePath,
|
|
64
|
+
})
|
|
65
|
+
.strict();
|
|
66
|
+
export type ContactSubmitInput = z.infer<typeof ContactSubmitSchema>;
|
|
67
|
+
|
|
68
|
+
export const ContactReportSchema = z
|
|
69
|
+
.object({
|
|
70
|
+
kind: z.enum(CONTACT_ADMIN_KINDS),
|
|
71
|
+
subject: singleLine(CONTACT_FIELD_LIMITS.subject),
|
|
72
|
+
message: multiLine(CONTACT_FIELD_LIMITS.message),
|
|
73
|
+
phone,
|
|
74
|
+
fileIds: z.array(z.uuid()).max(CONTACT_MAX_FILES).optional(),
|
|
75
|
+
})
|
|
76
|
+
.strict();
|
|
77
|
+
export type ContactReportInput = z.infer<typeof ContactReportSchema>;
|
|
78
|
+
|
|
79
|
+
export const ContactIdSchema = z.object({ id: z.uuid() }).strict();
|
|
80
|
+
|
|
81
|
+
export const ContactReplySchema = z
|
|
82
|
+
.object({
|
|
83
|
+
requestId: z.uuid(),
|
|
84
|
+
message: multiLine(CONTACT_FIELD_LIMITS.message),
|
|
85
|
+
fileIds: z.array(z.uuid()).max(CONTACT_MAX_FILES).optional(),
|
|
86
|
+
markDone: z.boolean().default(false),
|
|
87
|
+
})
|
|
88
|
+
.strict();
|
|
89
|
+
|
|
90
|
+
export const ContactMarkDoneSchema = ContactIdSchema;
|
|
91
|
+
|
|
92
|
+
export const ContactForwardRequestSchema = z.object({ requestId: z.uuid() }).strict();
|
|
93
|
+
|
|
94
|
+
export const ContactSendReplyMailSchema = z.object({ replyId: z.uuid() }).strict();
|
|
95
|
+
|
|
96
|
+
export const ContactNotifyReporterInAppSchema = z
|
|
97
|
+
.object({
|
|
98
|
+
replyId: z.uuid(),
|
|
99
|
+
requestId: z.uuid(),
|
|
100
|
+
userId: z.uuid(),
|
|
101
|
+
authorName: z.string().max(CONTACT_FIELD_LIMITS.name),
|
|
102
|
+
locale: z.string().max(CONTACT_FIELD_LIMITS.locale).optional(),
|
|
103
|
+
})
|
|
104
|
+
.strict();
|
|
105
|
+
|
|
106
|
+
export const ContactEmptySchema = z.object({}).strict();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
export function hasLeadingZeroBits(hash: Uint8Array, bits: number): boolean {
|
|
4
|
+
const fullBytes = Math.floor(bits / 8);
|
|
5
|
+
for (let index = 0; index < fullBytes; index++) {
|
|
6
|
+
if (hash[index] !== 0) return false;
|
|
7
|
+
}
|
|
8
|
+
const remainingBits = bits % 8;
|
|
9
|
+
if (remainingBits === 0) return true;
|
|
10
|
+
const next = hash[fullBytes];
|
|
11
|
+
if (next === undefined) return false;
|
|
12
|
+
return next >> (8 - remainingBits) === 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function verifyProofOfWork(args: {
|
|
16
|
+
readonly challenge: string;
|
|
17
|
+
readonly nonce: string;
|
|
18
|
+
readonly bits: number;
|
|
19
|
+
}): boolean {
|
|
20
|
+
const hash = createHash("sha256").update(`${args.challenge}:${args.nonce}`).digest();
|
|
21
|
+
return hasLeadingZeroBits(hash, args.bits);
|
|
22
|
+
}
|
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { access, createFilesField, createTextField } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import type {
|
|
3
|
+
ActionFormScreenDefinition,
|
|
4
|
+
ConfigEditScreenDefinition,
|
|
5
|
+
EntityListScreenDefinition,
|
|
6
|
+
ProjectionDetailScreenDefinition,
|
|
7
|
+
ScreenDefinition,
|
|
8
|
+
} from "@cosmicdrift/kumiko-framework/ui-types";
|
|
9
|
+
import { DELIVERY_LOG_SCREEN_ID } from "../delivery/index.ts";
|
|
10
|
+
import { REPORT_ACCESS } from "./handlers/access.ts";
|
|
11
|
+
import type { ContactOptions, ContactSettings } from "./options.ts";
|
|
12
|
+
import {
|
|
13
|
+
CONTACT_ADMIN_KINDS,
|
|
14
|
+
CONTACT_DELIVERY_STATUS,
|
|
15
|
+
CONTACT_FEATURE,
|
|
16
|
+
CONTACT_MAX_FILES,
|
|
17
|
+
CONTACT_ORIGIN,
|
|
18
|
+
CONTACT_REPLY_CHANNELS,
|
|
19
|
+
CONTACT_STATUS,
|
|
20
|
+
CONTACT_UPLOAD_FIELD,
|
|
21
|
+
ContactConfigKeys,
|
|
22
|
+
ContactHandlers,
|
|
23
|
+
ContactQueries,
|
|
24
|
+
} from "./web/constants.ts";
|
|
25
|
+
|
|
26
|
+
const MAX_FILE_SIZE = "10MB";
|
|
27
|
+
const REQUEST_FIELD = `${CONTACT_FEATURE}:entity:contact-request:field`;
|
|
28
|
+
const DELIVERY_FIELD = `${CONTACT_FEATURE}:entity:contact-delivery:field`;
|
|
29
|
+
const TELEGRAM_BOT_TOKEN_SECRET = "channel-telegram:secret:bot-token";
|
|
30
|
+
|
|
31
|
+
export const REPORT_FIELD_LABEL = `${CONTACT_FEATURE}:report.field`;
|
|
32
|
+
export const REPLY_FIELD_LABEL = `${CONTACT_FEATURE}:reply.field`;
|
|
33
|
+
|
|
34
|
+
function attachmentsField() {
|
|
35
|
+
return createFilesField({
|
|
36
|
+
personal: false,
|
|
37
|
+
reason: "is_business_data",
|
|
38
|
+
maxCount: CONTACT_MAX_FILES,
|
|
39
|
+
maxSize: MAX_FILE_SIZE,
|
|
40
|
+
display: "dropzone",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The files the form uploads stay pending under this screen's QN until the handler takes them
|
|
45
|
+
// over (copyPendingFileRefsToTenant).
|
|
46
|
+
function createReportScreen(
|
|
47
|
+
opts: ContactOptions,
|
|
48
|
+
settings: ContactSettings,
|
|
49
|
+
): ActionFormScreenDefinition {
|
|
50
|
+
const withPhone = settings.phone !== "off";
|
|
51
|
+
return {
|
|
52
|
+
id: "report",
|
|
53
|
+
type: "actionForm",
|
|
54
|
+
dormant: true,
|
|
55
|
+
handler: ContactHandlers.report,
|
|
56
|
+
summary: {
|
|
57
|
+
title: `${CONTACT_FEATURE}:report.hint`,
|
|
58
|
+
subtitle: `${CONTACT_FEATURE}:report.summary`,
|
|
59
|
+
},
|
|
60
|
+
fields: {
|
|
61
|
+
kind: { type: "select", options: CONTACT_ADMIN_KINDS, required: true, display: "radio" },
|
|
62
|
+
...(withPhone && {
|
|
63
|
+
phone: { type: "text", format: "phone", required: settings.phone === "required" },
|
|
64
|
+
}),
|
|
65
|
+
subject: { type: "text", required: true },
|
|
66
|
+
message: { type: "longText", required: true },
|
|
67
|
+
[CONTACT_UPLOAD_FIELD]: attachmentsField(),
|
|
68
|
+
},
|
|
69
|
+
layout: {
|
|
70
|
+
sections: [
|
|
71
|
+
{
|
|
72
|
+
title: `${CONTACT_FEATURE}:report.section`,
|
|
73
|
+
description: `${CONTACT_FEATURE}:report.section.description`,
|
|
74
|
+
fields: [
|
|
75
|
+
"kind",
|
|
76
|
+
...(withPhone ? ["phone"] : []),
|
|
77
|
+
{ field: "subject", span: 2 },
|
|
78
|
+
"message",
|
|
79
|
+
CONTACT_UPLOAD_FIELD,
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
fieldLabels: {
|
|
85
|
+
kind: `${REPORT_FIELD_LABEL}.kind`,
|
|
86
|
+
phone: `${REPORT_FIELD_LABEL}.phone`,
|
|
87
|
+
subject: `${REPORT_FIELD_LABEL}.subject`,
|
|
88
|
+
message: `${REPORT_FIELD_LABEL}.message`,
|
|
89
|
+
[CONTACT_UPLOAD_FIELD]: `${REPORT_FIELD_LABEL}.files`,
|
|
90
|
+
},
|
|
91
|
+
submitLabel: `${CONTACT_FEATURE}:report.submit`,
|
|
92
|
+
...(opts.reportCancelTarget !== undefined && { cancelTarget: opts.reportCancelTarget }),
|
|
93
|
+
successMessage: `${CONTACT_FEATURE}:report.success`,
|
|
94
|
+
access: REPORT_ACCESS,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The two reply screens differ only in the summary text: the screen QN is also the entityType the
|
|
99
|
+
// pending uploads hang under, so reply.write picks the variant by the reporter's reply channels.
|
|
100
|
+
function createReplyScreen(id: string, summarySubtitle: string): ActionFormScreenDefinition {
|
|
101
|
+
return {
|
|
102
|
+
id,
|
|
103
|
+
type: "actionForm",
|
|
104
|
+
dormant: true,
|
|
105
|
+
handler: ContactHandlers.reply,
|
|
106
|
+
summary: { title: `${CONTACT_FEATURE}:reply.title`, subtitle: summarySubtitle },
|
|
107
|
+
fields: {
|
|
108
|
+
requestId: { type: "text", required: true },
|
|
109
|
+
message: { type: "longText", required: true },
|
|
110
|
+
[CONTACT_UPLOAD_FIELD]: attachmentsField(),
|
|
111
|
+
markDone: { type: "boolean" },
|
|
112
|
+
name: { type: "text" },
|
|
113
|
+
email: { type: "text" },
|
|
114
|
+
replyTo: { type: "text" },
|
|
115
|
+
},
|
|
116
|
+
layout: {
|
|
117
|
+
sections: [
|
|
118
|
+
{
|
|
119
|
+
title: `${CONTACT_FEATURE}:reply.section`,
|
|
120
|
+
description: `${CONTACT_FEATURE}:reply.section.description`,
|
|
121
|
+
fields: [
|
|
122
|
+
{ field: "requestId", visible: false },
|
|
123
|
+
{ field: "name", visible: false },
|
|
124
|
+
{ field: "email", visible: false },
|
|
125
|
+
{ field: "replyTo", visible: false },
|
|
126
|
+
"message",
|
|
127
|
+
CONTACT_UPLOAD_FIELD,
|
|
128
|
+
"markDone",
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
fieldLabels: {
|
|
134
|
+
message: `${REPLY_FIELD_LABEL}.message`,
|
|
135
|
+
[CONTACT_UPLOAD_FIELD]: `${REPLY_FIELD_LABEL}.files`,
|
|
136
|
+
markDone: `${REPLY_FIELD_LABEL}.mark-done`,
|
|
137
|
+
},
|
|
138
|
+
submitLabel: `${CONTACT_FEATURE}:reply.submit`,
|
|
139
|
+
access: { roles: access.systemAdmin },
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const requestListScreen: EntityListScreenDefinition = {
|
|
144
|
+
id: "request-list",
|
|
145
|
+
type: "entityList",
|
|
146
|
+
entity: "contact-request",
|
|
147
|
+
dormant: true,
|
|
148
|
+
allowCreate: false,
|
|
149
|
+
searchable: true,
|
|
150
|
+
columns: [
|
|
151
|
+
{ field: "submittedAt", display: "datetime" },
|
|
152
|
+
"kind",
|
|
153
|
+
{ field: "name", label: `${CONTACT_FEATURE}:list.from` },
|
|
154
|
+
{ field: "reporterTenantName", label: `${REQUEST_FIELD}:reporterTenantName` },
|
|
155
|
+
{ field: "subject", hideOnNarrow: true },
|
|
156
|
+
{
|
|
157
|
+
field: "source",
|
|
158
|
+
hideOnNarrow: true,
|
|
159
|
+
renderer: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:source:option:` },
|
|
160
|
+
},
|
|
161
|
+
{ field: "fileCount", label: `${REQUEST_FIELD}:fileCount`, hideOnNarrow: true },
|
|
162
|
+
"status",
|
|
163
|
+
],
|
|
164
|
+
facets: {
|
|
165
|
+
status: {
|
|
166
|
+
display: "chips",
|
|
167
|
+
showCounts: true,
|
|
168
|
+
extraOptions: [
|
|
169
|
+
{ id: "all", label: `${CONTACT_FEATURE}:filter.all`, values: [], position: "start" },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
kind: { display: "select" },
|
|
173
|
+
source: { display: "select" },
|
|
174
|
+
},
|
|
175
|
+
defaultFilters: { status: [CONTACT_STATUS.Open] },
|
|
176
|
+
defaultSort: { field: "submittedAt", dir: "desc" },
|
|
177
|
+
rowActions: [
|
|
178
|
+
{
|
|
179
|
+
kind: "navigate",
|
|
180
|
+
id: "open",
|
|
181
|
+
label: `${CONTACT_FEATURE}:action.open`,
|
|
182
|
+
screen: "request-detail",
|
|
183
|
+
entityId: "id",
|
|
184
|
+
rowClick: true,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
kind: "writeHandler",
|
|
188
|
+
id: "mark-done",
|
|
189
|
+
label: `${CONTACT_FEATURE}:action.mark-done`,
|
|
190
|
+
handler: ContactHandlers.markDone,
|
|
191
|
+
payload: { pick: ["id"] },
|
|
192
|
+
visible: { field: "status", ne: CONTACT_STATUS.Done },
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
bulkActions: [{ id: "mark-done", rowAction: "mark-done" }],
|
|
196
|
+
access: { roles: access.systemAdmin },
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const deliveryStatusTones = {
|
|
200
|
+
[CONTACT_DELIVERY_STATUS.Pending]: "warn",
|
|
201
|
+
[CONTACT_DELIVERY_STATUS.Delivered]: "ok",
|
|
202
|
+
[CONTACT_DELIVERY_STATUS.Failed]: "bad",
|
|
203
|
+
[CONTACT_DELIVERY_STATUS.Skipped]: "neutral",
|
|
204
|
+
[CONTACT_DELIVERY_STATUS.Read]: "accent",
|
|
205
|
+
} as const;
|
|
206
|
+
|
|
207
|
+
function detailLinkTarget(
|
|
208
|
+
link: string | false | undefined,
|
|
209
|
+
defaultScreen: string,
|
|
210
|
+
): string | undefined {
|
|
211
|
+
if (link === false) return undefined;
|
|
212
|
+
return link ?? defaultScreen;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function createRequestDetailScreen(
|
|
216
|
+
opts: ContactOptions,
|
|
217
|
+
settings: ContactSettings,
|
|
218
|
+
): ProjectionDetailScreenDefinition {
|
|
219
|
+
const userScreen = detailLinkTarget(opts.detailLinks?.user, "user-edit");
|
|
220
|
+
const tenantScreen = detailLinkTarget(opts.detailLinks?.tenant, "tenant-edit");
|
|
221
|
+
return {
|
|
222
|
+
id: "request-detail",
|
|
223
|
+
type: "projectionDetail",
|
|
224
|
+
dormant: true,
|
|
225
|
+
query: ContactQueries.requestDetail,
|
|
226
|
+
listScreenId: "request-list",
|
|
227
|
+
header: {
|
|
228
|
+
title: "subject",
|
|
229
|
+
subtitle: [
|
|
230
|
+
{
|
|
231
|
+
field: "kind",
|
|
232
|
+
format: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:kind:option:` },
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
field: "name",
|
|
236
|
+
...(userScreen !== undefined && {
|
|
237
|
+
navigate: { screen: userScreen, entityId: "reporterUserId" },
|
|
238
|
+
}),
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
field: "reporterTenantName",
|
|
242
|
+
...(tenantScreen !== undefined && {
|
|
243
|
+
navigate: { screen: tenantScreen, entityId: "reporterTenantId" },
|
|
244
|
+
}),
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
field: "submittedAt",
|
|
248
|
+
format: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
status: "status",
|
|
252
|
+
statusFormat: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:status:option:` },
|
|
253
|
+
statusTones: {
|
|
254
|
+
[CONTACT_STATUS.Open]: "warn",
|
|
255
|
+
[CONTACT_STATUS.Answered]: "accent",
|
|
256
|
+
[CONTACT_STATUS.Done]: "ok",
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
actions: [
|
|
260
|
+
{
|
|
261
|
+
kind: "writeHandler",
|
|
262
|
+
id: "mark-done",
|
|
263
|
+
label: `${CONTACT_FEATURE}:action.mark-done`,
|
|
264
|
+
handler: ContactHandlers.markDone,
|
|
265
|
+
icon: "check-circle",
|
|
266
|
+
style: "secondary",
|
|
267
|
+
payload: { pick: ["id"] },
|
|
268
|
+
visible: { field: "status", ne: CONTACT_STATUS.Done },
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
kind: "drawer",
|
|
272
|
+
id: "reply",
|
|
273
|
+
icon: "mail",
|
|
274
|
+
style: "primary",
|
|
275
|
+
label: `${CONTACT_FEATURE}:action.reply`,
|
|
276
|
+
screen: "reply",
|
|
277
|
+
params: { map: { requestId: "id", name: "name", email: "email", replyTo: "replyTo" } },
|
|
278
|
+
title: "screen:reply.title",
|
|
279
|
+
visible: { field: "replyChannels", eq: CONTACT_REPLY_CHANNELS.EmailAndInApp },
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
kind: "drawer",
|
|
283
|
+
id: "reply-mail",
|
|
284
|
+
icon: "mail",
|
|
285
|
+
style: "primary",
|
|
286
|
+
label: `${CONTACT_FEATURE}:action.reply`,
|
|
287
|
+
screen: "reply-mail",
|
|
288
|
+
params: { map: { requestId: "id", name: "name", email: "email", replyTo: "replyTo" } },
|
|
289
|
+
title: "screen:reply-mail.title",
|
|
290
|
+
visible: { field: "replyChannels", eq: CONTACT_REPLY_CHANNELS.Email },
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
primaryAction: "reply",
|
|
294
|
+
inlineActions: ["mark-done"],
|
|
295
|
+
fieldLabels: {
|
|
296
|
+
message: `${REQUEST_FIELD}:message`,
|
|
297
|
+
fileIds: `${CONTACT_FEATURE}:detail.attachments`,
|
|
298
|
+
name: `${REQUEST_FIELD}:name`,
|
|
299
|
+
email: `${REQUEST_FIELD}:email`,
|
|
300
|
+
phone: `${REQUEST_FIELD}:phone`,
|
|
301
|
+
reporterTenantPlan: `${REQUEST_FIELD}:reporterTenantPlan`,
|
|
302
|
+
origin: `${REQUEST_FIELD}:origin`,
|
|
303
|
+
page: `${REQUEST_FIELD}:page`,
|
|
304
|
+
versionLabel: `${REQUEST_FIELD}:versionLabel`,
|
|
305
|
+
browser: `${REQUEST_FIELD}:browser`,
|
|
306
|
+
},
|
|
307
|
+
layout: {
|
|
308
|
+
sections: [
|
|
309
|
+
{ title: `${CONTACT_FEATURE}:detail.section.message`, fields: ["message"] },
|
|
310
|
+
{
|
|
311
|
+
kind: "relatedList",
|
|
312
|
+
readOnly: true,
|
|
313
|
+
title: `${CONTACT_FEATURE}:detail.section.replies`,
|
|
314
|
+
query: ContactQueries.replies,
|
|
315
|
+
columns: [
|
|
316
|
+
{
|
|
317
|
+
field: "sentAt",
|
|
318
|
+
renderer: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
|
|
319
|
+
label: `${CONTACT_FEATURE}:entity:contact-reply:field:sentAt`,
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
field: "authorName",
|
|
323
|
+
label: `${CONTACT_FEATURE}:entity:contact-reply:field:authorName`,
|
|
324
|
+
},
|
|
325
|
+
{ field: "message", label: `${CONTACT_FEATURE}:entity:contact-reply:field:message` },
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
title: `${CONTACT_FEATURE}:detail.section.files`,
|
|
330
|
+
fields: [
|
|
331
|
+
{
|
|
332
|
+
field: CONTACT_UPLOAD_FIELD,
|
|
333
|
+
renderer: { format: "file" },
|
|
334
|
+
visible: { field: "fileCount", ne: 0 },
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
title: `${CONTACT_FEATURE}:detail.section.sender`,
|
|
340
|
+
fields: [
|
|
341
|
+
"name",
|
|
342
|
+
{ field: "email", format: "email" },
|
|
343
|
+
...(settings.phone !== "off"
|
|
344
|
+
? [
|
|
345
|
+
{
|
|
346
|
+
field: "phone",
|
|
347
|
+
format: "phone" as const,
|
|
348
|
+
visible: { field: "phone", notIn: [null, ""] },
|
|
349
|
+
},
|
|
350
|
+
]
|
|
351
|
+
: []),
|
|
352
|
+
"reporterTenantPlan",
|
|
353
|
+
],
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
title: `${CONTACT_FEATURE}:detail.section.origin`,
|
|
357
|
+
fields: [
|
|
358
|
+
{
|
|
359
|
+
field: "origin",
|
|
360
|
+
renderer: { format: "enumOption", keyPrefix: `${REQUEST_FIELD}:origin:option:` },
|
|
361
|
+
},
|
|
362
|
+
{ field: "page", visible: { field: "origin", eq: CONTACT_ORIGIN.Website } },
|
|
363
|
+
"versionLabel",
|
|
364
|
+
"browser",
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
kind: "relatedList",
|
|
369
|
+
readOnly: true,
|
|
370
|
+
title: `${CONTACT_FEATURE}:detail.section.delivery`,
|
|
371
|
+
query: ContactQueries.requestDelivery,
|
|
372
|
+
toolbarActions: [
|
|
373
|
+
{
|
|
374
|
+
kind: "navigate",
|
|
375
|
+
id: "delivery-log",
|
|
376
|
+
label: `${CONTACT_FEATURE}:detail.delivery-log`,
|
|
377
|
+
screen: DELIVERY_LOG_SCREEN_ID,
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
columns: [
|
|
381
|
+
{
|
|
382
|
+
field: "channel",
|
|
383
|
+
label: `${DELIVERY_FIELD}:channel`,
|
|
384
|
+
renderer: { format: "enumOption", keyPrefix: `${DELIVERY_FIELD}:channel:option:` },
|
|
385
|
+
},
|
|
386
|
+
{ field: "recipient", label: `${DELIVERY_FIELD}:recipient` },
|
|
387
|
+
{
|
|
388
|
+
field: "at",
|
|
389
|
+
renderer: { format: "timestamp", dateStyle: "medium", timeStyle: "short" },
|
|
390
|
+
label: `${DELIVERY_FIELD}:at`,
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
field: "status",
|
|
394
|
+
label: `${DELIVERY_FIELD}:status`,
|
|
395
|
+
renderer: {
|
|
396
|
+
format: "enumOption",
|
|
397
|
+
keyPrefix: `${DELIVERY_FIELD}:status:option:`,
|
|
398
|
+
tones: deliveryStatusTones,
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
],
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
kind: "extension",
|
|
405
|
+
title: `${CONTACT_FEATURE}:detail.section.notes`,
|
|
406
|
+
component: { react: { __component: "NotesSection" } },
|
|
407
|
+
entityName: "contact-request",
|
|
408
|
+
},
|
|
409
|
+
],
|
|
410
|
+
},
|
|
411
|
+
access: { roles: access.systemAdmin },
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function createForwardingScreen(telegram: boolean): ConfigEditScreenDefinition {
|
|
416
|
+
return {
|
|
417
|
+
id: "forwarding",
|
|
418
|
+
type: "configEdit",
|
|
419
|
+
dormant: true,
|
|
420
|
+
scope: "system",
|
|
421
|
+
configKeys: {
|
|
422
|
+
replyTo: ContactConfigKeys.replyTo,
|
|
423
|
+
...(telegram && { telegramChat: ContactConfigKeys.telegramChat }),
|
|
424
|
+
},
|
|
425
|
+
...(telegram && { secretKeys: { botToken: TELEGRAM_BOT_TOKEN_SECRET } }),
|
|
426
|
+
fields: {
|
|
427
|
+
replyTo: createTextField({
|
|
428
|
+
format: "email",
|
|
429
|
+
maxLength: 254,
|
|
430
|
+
personal: false,
|
|
431
|
+
reason: "is_business_data",
|
|
432
|
+
}),
|
|
433
|
+
...(telegram && {
|
|
434
|
+
telegramChat: createTextField({
|
|
435
|
+
maxLength: 64,
|
|
436
|
+
personal: false,
|
|
437
|
+
reason: "is_business_data",
|
|
438
|
+
}),
|
|
439
|
+
botToken: createTextField({
|
|
440
|
+
writeOnly: true,
|
|
441
|
+
maxLength: 200,
|
|
442
|
+
personal: false,
|
|
443
|
+
reason: "is_business_data",
|
|
444
|
+
}),
|
|
445
|
+
}),
|
|
446
|
+
},
|
|
447
|
+
layout: {
|
|
448
|
+
variant: "settings-list",
|
|
449
|
+
sections: [
|
|
450
|
+
{
|
|
451
|
+
title: `${CONTACT_FEATURE}:forwarding.email`,
|
|
452
|
+
description: `${CONTACT_FEATURE}:forwarding.email.description`,
|
|
453
|
+
fields: ["replyTo"],
|
|
454
|
+
},
|
|
455
|
+
...(telegram
|
|
456
|
+
? [
|
|
457
|
+
{
|
|
458
|
+
title: `${CONTACT_FEATURE}:forwarding.telegram`,
|
|
459
|
+
description: `${CONTACT_FEATURE}:forwarding.telegram.description`,
|
|
460
|
+
fields: ["telegramChat", "botToken"],
|
|
461
|
+
},
|
|
462
|
+
]
|
|
463
|
+
: []),
|
|
464
|
+
],
|
|
465
|
+
},
|
|
466
|
+
fieldLabels: {
|
|
467
|
+
replyTo: `${CONTACT_FEATURE}:config.reply-to.label`,
|
|
468
|
+
telegramChat: `${CONTACT_FEATURE}:config.telegram-chat.label`,
|
|
469
|
+
botToken: `${CONTACT_FEATURE}:config.bot-token.label`,
|
|
470
|
+
},
|
|
471
|
+
fieldDescriptions: {
|
|
472
|
+
replyTo: `${CONTACT_FEATURE}:config.reply-to.description`,
|
|
473
|
+
telegramChat: `${CONTACT_FEATURE}:config.telegram-chat.description`,
|
|
474
|
+
botToken: `${CONTACT_FEATURE}:config.bot-token.description`,
|
|
475
|
+
},
|
|
476
|
+
submitLabel: `${CONTACT_FEATURE}:forwarding.submit`,
|
|
477
|
+
...(telegram && {
|
|
478
|
+
actions: [
|
|
479
|
+
{
|
|
480
|
+
id: "send-test",
|
|
481
|
+
handler: ContactHandlers.sendTest,
|
|
482
|
+
label: `${CONTACT_FEATURE}:config.send-test.label`,
|
|
483
|
+
description: `${CONTACT_FEATURE}:config.send-test.description`,
|
|
484
|
+
buttonLabel: `${CONTACT_FEATURE}:config.send-test.button`,
|
|
485
|
+
afterField: "botToken",
|
|
486
|
+
successMessage: `${CONTACT_FEATURE}:config.send-test.success`,
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
}),
|
|
490
|
+
access: { roles: access.systemAdmin },
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export function createContactScreens(
|
|
495
|
+
opts: ContactOptions,
|
|
496
|
+
settings: ContactSettings,
|
|
497
|
+
): readonly ScreenDefinition[] {
|
|
498
|
+
return [
|
|
499
|
+
createReportScreen(opts, settings),
|
|
500
|
+
requestListScreen,
|
|
501
|
+
createRequestDetailScreen(opts, settings),
|
|
502
|
+
createReplyScreen("reply", `${CONTACT_FEATURE}:reply.summary.in-app`),
|
|
503
|
+
createReplyScreen("reply-mail", `${CONTACT_FEATURE}:reply.summary.mail`),
|
|
504
|
+
createForwardingScreen(opts.telegram === true),
|
|
505
|
+
];
|
|
506
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CONTACT_SUBJECT_MAX_CHARS } from "./web/constants.ts";
|
|
2
|
+
|
|
3
|
+
// The website form has no subject field; the first non-empty line of the message stands in for it.
|
|
4
|
+
export function deriveSubjectFromMessage(message: string): string {
|
|
5
|
+
const firstLine = message.split(/[\r\n]/).find((line) => line.trim() !== "") ?? "";
|
|
6
|
+
const trimmed = firstLine.trim();
|
|
7
|
+
const chars = [...trimmed];
|
|
8
|
+
if (chars.length <= CONTACT_SUBJECT_MAX_CHARS) return trimmed;
|
|
9
|
+
return `${chars
|
|
10
|
+
.slice(0, CONTACT_SUBJECT_MAX_CHARS - 1)
|
|
11
|
+
.join("")
|
|
12
|
+
.trimEnd()}…`;
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type BrowserName = "Edge" | "Opera" | "Firefox" | "Chrome" | "Safari";
|
|
2
|
+
type OsName = "Windows" | "macOS" | "iOS" | "Android" | "Linux";
|
|
3
|
+
|
|
4
|
+
// Order matters: Edge and Opera also say "Chrome", Chrome also says "Safari".
|
|
5
|
+
const BROWSER_PATTERNS: readonly (readonly [BrowserName, RegExp])[] = [
|
|
6
|
+
["Edge", /\bEdg(?:e|A|iOS)?\/(\d+)/],
|
|
7
|
+
["Opera", /\b(?:OPR|Opera)\/(\d+)/],
|
|
8
|
+
["Firefox", /\b(?:Firefox|FxiOS)\/(\d+)/],
|
|
9
|
+
["Chrome", /\b(?:Chrome|CriOS)\/(\d+)/],
|
|
10
|
+
["Safari", /\bVersion\/(\d+)[\s\S]*\bSafari\//],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
// iOS and Android UAs also contain "Mac OS X" / "Linux", so they are tested first.
|
|
14
|
+
const OS_PATTERNS: readonly (readonly [OsName, RegExp])[] = [
|
|
15
|
+
["iOS", /\b(?:iPhone|iPad|iPod)\b/],
|
|
16
|
+
["Android", /\bAndroid\b/],
|
|
17
|
+
["Windows", /\bWindows\b/],
|
|
18
|
+
["macOS", /\bMac OS X\b|\bMacintosh\b/],
|
|
19
|
+
["Linux", /\b(?:Linux|X11)\b/],
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const CONNECTOR_BY_LANGUAGE: Readonly<Record<string, string>> = { de: "auf", en: "on" };
|
|
23
|
+
|
|
24
|
+
function languageOf(locale: string): string {
|
|
25
|
+
return locale.split("-")[0]?.toLowerCase() ?? "en";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Null when the UA names no known browser; the browser column is a hint for operators, not an identity.
|
|
29
|
+
export function summarizeUserAgent(userAgent: string | undefined, locale: string): string | null {
|
|
30
|
+
if (userAgent === undefined) return null;
|
|
31
|
+
const browser = BROWSER_PATTERNS.map(([name, pattern]) => {
|
|
32
|
+
const version = pattern.exec(userAgent)?.[1];
|
|
33
|
+
return version === undefined ? undefined : `${name} ${version}`;
|
|
34
|
+
}).find((summary) => summary !== undefined);
|
|
35
|
+
if (browser === undefined) return null;
|
|
36
|
+
const os = OS_PATTERNS.find(([, pattern]) => pattern.test(userAgent))?.[0];
|
|
37
|
+
if (os === undefined) return browser;
|
|
38
|
+
return `${browser} ${CONNECTOR_BY_LANGUAGE[languageOf(locale)] ?? "on"} ${os}`;
|
|
39
|
+
}
|