@cosmicdrift/kumiko-samples 0.411.0 → 0.413.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 +13 -13
- package/packages/bundled-features/src/admin-shell/feature.ts +1 -1
- package/packages/bundled-features/src/agent-tools/agent-doc-lint.ts +64 -3
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +13 -130
- package/packages/bundled-features/src/agent-tools/api-docs/anchors.ts +60 -0
- package/packages/bundled-features/src/agent-tools/api-docs/check.ts +25 -0
- package/packages/bundled-features/src/agent-tools/api-docs/collect-events.ts +140 -0
- package/packages/bundled-features/src/agent-tools/api-docs/collect.ts +175 -0
- package/packages/bundled-features/src/agent-tools/api-docs/curl.ts +28 -0
- package/packages/bundled-features/src/agent-tools/api-docs/error-table.ts +45 -0
- package/packages/bundled-features/src/agent-tools/api-docs/examples.ts +43 -0
- package/packages/bundled-features/src/agent-tools/api-docs/generate.ts +179 -0
- package/packages/bundled-features/src/agent-tools/api-docs/index-json.ts +29 -0
- package/packages/bundled-features/src/agent-tools/api-docs/index.ts +21 -0
- package/packages/bundled-features/src/agent-tools/api-docs/list-parameters.ts +38 -0
- package/packages/bundled-features/src/agent-tools/api-docs/markdown.ts +70 -0
- package/packages/bundled-features/src/agent-tools/api-docs/menu-path.ts +82 -0
- package/packages/bundled-features/src/agent-tools/api-docs/model.ts +83 -0
- package/packages/bundled-features/src/agent-tools/api-docs/problems.ts +58 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-events.ts +76 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-openapi.ts +216 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-overview.ts +86 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-reference.ts +79 -0
- package/packages/bundled-features/src/agent-tools/api-docs/render-tokens.ts +136 -0
- package/packages/bundled-features/src/agent-tools/api-docs/schema-fields.ts +167 -0
- package/packages/bundled-features/src/agent-tools/api-docs/section-ids.ts +28 -0
- package/packages/bundled-features/src/agent-tools/api-docs/system-only.ts +11 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/de.ts +166 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/en.ts +159 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/es.ts +162 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/fr.ts +169 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/index.ts +67 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/it.ts +165 -0
- package/packages/bundled-features/src/agent-tools/api-docs/texts/types.ts +130 -0
- package/packages/bundled-features/src/agent-tools/api-docs/ui-writes.ts +81 -0
- package/packages/bundled-features/src/agent-tools/changes.json +24 -0
- package/packages/bundled-features/src/agent-tools/handler-schema.ts +45 -0
- package/packages/bundled-features/src/agent-tools/index.ts +24 -0
- package/packages/bundled-features/src/agent-tools/labels.ts +181 -0
- package/packages/bundled-features/src/auth-email-password/boot-rules.ts +9 -0
- package/packages/bundled-features/src/auth-email-password/feature.ts +6 -19
- package/packages/bundled-features/src/auth-email-password/validate-options.ts +20 -0
- package/packages/bundled-features/src/billing-foundation/boot-rules.ts +26 -0
- package/packages/bundled-features/src/billing-foundation/validate-options.ts +59 -46
- package/packages/bundled-features/src/cap-overview/boot-rules.ts +14 -0
- package/packages/bundled-features/src/cap-overview/feature.ts +12 -5
- package/packages/bundled-features/src/documents/boot-rules.ts +14 -0
- package/packages/bundled-features/src/documents/feature.ts +8 -4
- package/packages/bundled-features/src/file-derivatives/boot-rules.ts +9 -0
- package/packages/bundled-features/src/file-derivatives/feature.ts +6 -3
- package/packages/bundled-features/src/folders/boot-rules.ts +9 -0
- package/packages/bundled-features/src/folders/feature.ts +6 -3
- package/packages/bundled-features/src/helpdesk/boot-rules.ts +9 -0
- package/packages/bundled-features/src/{contact → helpdesk}/challenge.ts +2 -2
- package/packages/bundled-features/src/{contact → helpdesk}/changes.json +6 -0
- package/packages/bundled-features/src/{contact/client/contact-client-source.ts → helpdesk/client/helpdesk-client-source.ts} +4 -4
- package/packages/bundled-features/src/helpdesk/client/helpdesk-website-client.ts +29 -0
- package/packages/bundled-features/src/helpdesk/client/index.ts +9 -0
- package/packages/bundled-features/src/{contact → helpdesk}/entity.ts +35 -31
- package/packages/bundled-features/src/{contact → helpdesk}/feature.ts +56 -52
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/attempts.ts +3 -3
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/challenge.query.ts +10 -10
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/forward-request.write.ts +25 -23
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/mark-done.write.ts +11 -11
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/notify-reporter-in-app.write.ts +14 -14
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/open-count.query.ts +4 -4
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/open-count.ts +2 -2
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/replies.query.ts +6 -6
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/reply.write.ts +30 -30
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/report.write.ts +29 -29
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/request-delivery.query.ts +40 -40
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/request-detail.query.ts +15 -15
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/request-list.query.ts +2 -2
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/send-reply-mail.write.ts +24 -24
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/send-test.write.ts +18 -14
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/submit.write.ts +32 -31
- package/packages/bundled-features/src/{contact → helpdesk}/handlers/take-over-uploads.ts +5 -5
- package/packages/bundled-features/src/{contact → helpdesk}/i18n.ts +78 -75
- package/packages/bundled-features/src/helpdesk/index.ts +29 -0
- package/packages/bundled-features/src/{contact → helpdesk}/lib.ts +32 -28
- package/packages/bundled-features/src/{contact → helpdesk}/mail.ts +56 -56
- package/packages/bundled-features/src/{contact → helpdesk}/options.ts +18 -16
- package/packages/bundled-features/src/helpdesk/panels.ts +28 -0
- package/packages/bundled-features/src/{contact → helpdesk}/payloads.ts +33 -33
- package/packages/bundled-features/src/{contact → helpdesk}/screens.ts +104 -104
- package/packages/bundled-features/src/{contact → helpdesk}/subject.ts +3 -3
- package/packages/bundled-features/src/{contact → helpdesk}/user-data-hooks.ts +17 -17
- package/packages/bundled-features/src/helpdesk/web/constants.ts +160 -0
- package/packages/bundled-features/src/helpdesk/web/index.ts +29 -0
- package/packages/bundled-features/src/host-routing/boot-rules.ts +27 -0
- package/packages/bundled-features/src/host-routing/validate-options.ts +36 -27
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +99 -71
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +2 -2
- package/packages/bundled-features/src/jobs/boot-rules.ts +9 -0
- package/packages/bundled-features/src/jobs/feature.ts +9 -4
- package/packages/bundled-features/src/legal-pages/boot-rules.ts +19 -0
- package/packages/bundled-features/src/legal-pages/feature.ts +6 -3
- package/packages/bundled-features/src/legal-pages/lib/validate-routes.ts +11 -5
- package/packages/bundled-features/src/metrics/boot-rules.ts +15 -0
- package/packages/bundled-features/src/metrics/validate.ts +8 -2
- package/packages/bundled-features/src/notes-history/boot-rules.ts +9 -0
- package/packages/bundled-features/src/notes-history/feature.ts +6 -3
- package/packages/bundled-features/src/personal-access-tokens/boot-rules.ts +9 -0
- package/packages/bundled-features/src/personal-access-tokens/changes.json +6 -0
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +5 -2
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +7 -2
- package/packages/bundled-features/src/personal-access-tokens/i18n.ts +6 -1
- package/packages/bundled-features/src/personal-access-tokens/index.ts +37 -2
- package/packages/bundled-features/src/personal-access-tokens/scope-events-check.ts +31 -0
- package/packages/bundled-features/src/personal-access-tokens/screens.ts +9 -1
- package/packages/bundled-features/src/personal-access-tokens/web/constants.ts +1 -0
- package/packages/bundled-features/src/personal-access-tokens/web/scopes.ts +14 -0
- package/packages/bundled-features/src/presence/boot-rules.ts +9 -0
- package/packages/bundled-features/src/presence/options.ts +5 -1
- package/packages/bundled-features/src/readiness/boot-rules.ts +14 -0
- package/packages/bundled-features/src/readiness/probe-boot-check.ts +8 -6
- package/packages/bundled-features/src/shared/assert-no-where-rule-in-ownership-write.ts +6 -4
- package/packages/bundled-features/src/shared/boot-rules.ts +9 -0
- package/packages/bundled-features/src/subscription-mollie/boot-rules.ts +19 -0
- package/packages/bundled-features/src/subscription-mollie/feature.ts +18 -10
- package/packages/bundled-features/src/tags/boot-rules.ts +9 -0
- package/packages/bundled-features/src/tags/feature.ts +6 -3
- package/packages/bundled-features/src/template-resolver/boot-rules.ts +19 -0
- package/packages/bundled-features/src/template-resolver/feature.ts +14 -10
- package/packages/bundled-features/src/tenant/boot-rules.ts +9 -0
- package/packages/bundled-features/src/tenant/feature.ts +5 -3
- package/samples/apps/marketing-demo/README.md +1 -1
- package/samples/apps/marketing-demo/playwright.config.ts +1 -1
- package/samples/apps/marketing-demo/src/app/client.tsx +3 -3
- package/samples/apps/marketing-demo/src/app/seed-data.ts +1 -1
- package/samples/apps/marketing-demo/src/app/seed.ts +4 -4
- package/samples/apps/marketing-demo/src/app/server.ts +3 -3
- package/samples/apps/marketing-demo/src/features/{helpdesk → ticketing}/feature.ts +15 -12
- package/samples/apps/marketing-demo/src/features/ticketing/i18n.ts +100 -0
- package/samples/apps/marketing-demo/src/features/{helpdesk → ticketing}/schema/ticket.ts +4 -4
- package/samples/apps/marketing-demo/src/features/ticketing/web/index.ts +7 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +67 -67
- package/samples/apps/use-all-bundled/kumiko/migrations/0064_helpdesk-rename.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -1
- package/samples/apps/use-all-bundled/src/app/client.tsx +1 -1
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +10 -10
- package/samples/apps/use-all-bundled/src/run-config.ts +6 -6
- package/samples/recipes/api-docs/README.md +52 -0
- package/samples/recipes/api-docs/api-docs/de/events.md +62 -0
- package/samples/recipes/api-docs/api-docs/de/overview.md +100 -0
- package/samples/recipes/api-docs/api-docs/de/reference/tickets.md +305 -0
- package/samples/recipes/api-docs/api-docs/de/tokens.md +66 -0
- package/samples/recipes/api-docs/api-docs/en/events.md +62 -0
- package/samples/recipes/api-docs/api-docs/en/overview.md +100 -0
- package/samples/recipes/api-docs/api-docs/en/reference/tickets.md +305 -0
- package/samples/recipes/api-docs/api-docs/en/tokens.md +66 -0
- package/samples/recipes/api-docs/api-docs/index.json +371 -0
- package/samples/recipes/api-docs/api-docs/openapi.json +982 -0
- package/samples/recipes/api-docs/api-examples/ticket-close.json +21 -0
- package/samples/recipes/api-docs/api-examples/ticket-create.json +42 -0
- package/samples/recipes/api-docs/api-examples/ticket-detail.json +28 -0
- package/samples/recipes/api-docs/api-examples/ticket-list.json +31 -0
- package/samples/recipes/api-docs/api-examples/ticket-update.json +54 -0
- package/samples/recipes/api-docs/api-examples/webhooks/ticket-closed.json +8 -0
- package/samples/recipes/api-docs/api-examples/webhooks/ticket-created.json +10 -0
- package/samples/recipes/api-docs/kumiko.config.ts +33 -0
- package/samples/recipes/api-docs/package.json +14 -0
- package/samples/recipes/api-docs/src/feature.ts +218 -0
- package/samples/recipes/api-docs/tsconfig.json +22 -0
- package/samples/recipes/golden-path/src/feature.ts +1 -1
- package/samples/recipes/{contact → helpdesk}/README.md +16 -16
- package/samples/recipes/{contact → helpdesk}/package.json +2 -2
- package/samples/recipes/{contact → helpdesk}/src/feature.ts +6 -6
- package/packages/bundled-features/src/contact/client/contact-website-client.ts +0 -29
- package/packages/bundled-features/src/contact/client/index.ts +0 -9
- package/packages/bundled-features/src/contact/index.ts +0 -29
- package/packages/bundled-features/src/contact/panels.ts +0 -28
- package/packages/bundled-features/src/contact/web/constants.ts +0 -160
- package/packages/bundled-features/src/contact/web/index.ts +0 -29
- package/samples/apps/marketing-demo/src/features/helpdesk/i18n.ts +0 -100
- package/samples/apps/marketing-demo/src/features/helpdesk/web/index.ts +0 -7
- /package/packages/bundled-features/src/{contact → helpdesk}/handlers/access.ts +0 -0
- /package/packages/bundled-features/src/{contact → helpdesk}/pow.ts +0 -0
- /package/packages/bundled-features/src/{contact → helpdesk}/user-agent.ts +0 -0
- /package/samples/apps/marketing-demo/src/features/{helpdesk → ticketing}/schema/index.ts +0 -0
|
@@ -2,34 +2,34 @@ import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
|
2
2
|
import { NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
import {
|
|
4
4
|
adminAccess,
|
|
5
|
-
|
|
5
|
+
helpdeskDb,
|
|
6
6
|
loadUserLabel,
|
|
7
7
|
pickReplyChannels,
|
|
8
8
|
platformActor,
|
|
9
9
|
requestExecutor,
|
|
10
10
|
} from "../lib.ts";
|
|
11
|
-
import type {
|
|
12
|
-
import {
|
|
11
|
+
import type { HelpdeskOptions } from "../options.ts";
|
|
12
|
+
import { HelpdeskIdSchema } from "../payloads.ts";
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
HELPDESK_ORIGIN,
|
|
15
|
+
HELPDESK_REQUEST_ENTITY,
|
|
16
|
+
HELPDESK_SOURCE,
|
|
17
|
+
HelpdeskConfigKeys,
|
|
18
18
|
} from "../web/constants.ts";
|
|
19
19
|
|
|
20
|
-
export function createRequestDetailQuery(opts:
|
|
20
|
+
export function createRequestDetailQuery(opts: HelpdeskOptions) {
|
|
21
21
|
return defineQueryHandler({
|
|
22
22
|
name: "request-detail",
|
|
23
|
-
schema:
|
|
23
|
+
schema: HelpdeskIdSchema,
|
|
24
24
|
access: adminAccess,
|
|
25
25
|
description:
|
|
26
26
|
"Returns one contact request with its origin fields plus what the detail screen shows around it: the Reply-To address a reply goes out with (the caller's own email while none is configured), the channels a reply reaches the reporter on, the app version label and whether the request came from the website or the admin.",
|
|
27
27
|
handler: async (event, ctx) => {
|
|
28
|
-
const db =
|
|
28
|
+
const db = helpdeskDb(ctx);
|
|
29
29
|
const request = await requestExecutor.detail({ id: event.payload.id }, platformActor(), db);
|
|
30
|
-
if (!request) throw new NotFoundError(
|
|
30
|
+
if (!request) throw new NotFoundError(HELPDESK_REQUEST_ENTITY, event.payload.id);
|
|
31
31
|
|
|
32
|
-
const configuredReplyTo = await ctx.config?.(
|
|
32
|
+
const configuredReplyTo = await ctx.config?.(HelpdeskConfigKeys.replyTo);
|
|
33
33
|
const replyTo =
|
|
34
34
|
typeof configuredReplyTo === "string" && configuredReplyTo !== ""
|
|
35
35
|
? configuredReplyTo
|
|
@@ -41,9 +41,9 @@ export function createRequestDetailQuery(opts: ContactOptions) {
|
|
|
41
41
|
replyChannels: await pickReplyChannels(ctx, request.reporterUserId),
|
|
42
42
|
versionLabel: opts.appVersion !== undefined ? `${opts.appName} ${opts.appVersion}` : null,
|
|
43
43
|
origin:
|
|
44
|
-
request.source ===
|
|
45
|
-
?
|
|
46
|
-
:
|
|
44
|
+
request.source === HELPDESK_SOURCE.Admin
|
|
45
|
+
? HELPDESK_ORIGIN.AdminReport
|
|
46
|
+
: HELPDESK_ORIGIN.Website,
|
|
47
47
|
};
|
|
48
48
|
},
|
|
49
49
|
});
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
type EntityDefinition,
|
|
4
4
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
5
5
|
import { adminAccess } from "../lib.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { HELPDESK_REQUEST_ENTITY } from "../web/constants.ts";
|
|
7
7
|
|
|
8
8
|
export function createRequestListQuery(requestEntity: EntityDefinition) {
|
|
9
|
-
return defineEntityListHandler(
|
|
9
|
+
return defineEntityListHandler(HELPDESK_REQUEST_ENTITY, requestEntity, {
|
|
10
10
|
access: adminAccess,
|
|
11
11
|
description:
|
|
12
12
|
"Lists contact requests for the SystemAdmin inbox: searchable, filterable by status, kind and source, newest first; the open named filter backs the dashboard tile.",
|
package/packages/bundled-features/src/{contact → helpdesk}/handlers/send-reply-mail.write.ts
RENAMED
|
@@ -9,7 +9,7 @@ import { fileRefsTable } from "@cosmicdrift/kumiko-framework/files";
|
|
|
9
9
|
import type { FileAttachmentRef } from "../../delivery/index.ts";
|
|
10
10
|
import { decryptStoredPii } from "../../shared/index.ts";
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
helpdeskDb,
|
|
13
13
|
internalAccess,
|
|
14
14
|
loadUserLabel,
|
|
15
15
|
platformActor,
|
|
@@ -17,20 +17,20 @@ import {
|
|
|
17
17
|
requestExecutor,
|
|
18
18
|
sendBestEffort,
|
|
19
19
|
} from "../lib.ts";
|
|
20
|
-
import {
|
|
21
|
-
import type {
|
|
22
|
-
import {
|
|
20
|
+
import { helpdeskReplyVariables, resolveHelpdeskMailLocale } from "../mail.ts";
|
|
21
|
+
import type { HelpdeskOptions } from "../options.ts";
|
|
22
|
+
import { HelpdeskSendReplyMailSchema } from "../payloads.ts";
|
|
23
23
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
HELPDESK_NOTIFICATION_TYPES,
|
|
25
|
+
HELPDESK_REPLY_ENTITY,
|
|
26
|
+
HELPDESK_REQUEST_ENTITY,
|
|
27
|
+
HelpdeskConfigKeys,
|
|
28
|
+
helpdeskIdempotencyKeys,
|
|
29
29
|
} from "../web/constants.ts";
|
|
30
30
|
|
|
31
|
-
const ATTACHMENT_LOOKUP_REASON = "
|
|
31
|
+
const ATTACHMENT_LOOKUP_REASON = "helpdesk:reply-attachment";
|
|
32
32
|
|
|
33
|
-
export type
|
|
33
|
+
export type HelpdeskSendReplyMailData = { readonly kind: "sent"; readonly attachmentCount: number };
|
|
34
34
|
|
|
35
35
|
type FileRefNameRow = { readonly fileName: string };
|
|
36
36
|
|
|
@@ -38,7 +38,7 @@ async function resolveAttachments(
|
|
|
38
38
|
ctx: HandlerContext,
|
|
39
39
|
fileIds: readonly string[],
|
|
40
40
|
): Promise<readonly FileAttachmentRef[]> {
|
|
41
|
-
const db =
|
|
41
|
+
const db = helpdeskDb(ctx);
|
|
42
42
|
const attachments: FileAttachmentRef[] = [];
|
|
43
43
|
for (const fileRefId of fileIds) {
|
|
44
44
|
const row = await fetchOne<FileRefNameRow>(db, fileRefsTable, {
|
|
@@ -57,7 +57,7 @@ async function resolveReplyTo(
|
|
|
57
57
|
ctx: HandlerContext,
|
|
58
58
|
authorEmail: string | undefined,
|
|
59
59
|
): Promise<string | undefined> {
|
|
60
|
-
const configured = await ctx.config?.(
|
|
60
|
+
const configured = await ctx.config?.(HelpdeskConfigKeys.replyTo);
|
|
61
61
|
return typeof configured === "string" && configured.trim() !== ""
|
|
62
62
|
? configured.trim()
|
|
63
63
|
: authorEmail;
|
|
@@ -65,26 +65,26 @@ async function resolveReplyTo(
|
|
|
65
65
|
|
|
66
66
|
// Runs as the platform identity: the delivery channel reads attachments of the sending tenant,
|
|
67
67
|
// and the reply files live in the system tenant, whichever tenant the answering admin is in.
|
|
68
|
-
export function createSendReplyMailHandler(opts:
|
|
68
|
+
export function createSendReplyMailHandler(opts: HelpdeskOptions) {
|
|
69
69
|
return defineWriteHandler<
|
|
70
70
|
"send-reply-mail",
|
|
71
|
-
typeof
|
|
72
|
-
|
|
71
|
+
typeof HelpdeskSendReplyMailSchema,
|
|
72
|
+
HelpdeskSendReplyMailData
|
|
73
73
|
>({
|
|
74
74
|
name: "send-reply-mail",
|
|
75
|
-
schema:
|
|
75
|
+
schema: HelpdeskSendReplyMailSchema,
|
|
76
76
|
access: internalAccess,
|
|
77
77
|
agent: { expose: false },
|
|
78
78
|
description:
|
|
79
79
|
"Internal: mails a stored reply to the reporter with Reply-To, the quoted request and the reply files attached. Only the platform identity can call it.",
|
|
80
80
|
handler: async (event, ctx) => {
|
|
81
|
-
const db =
|
|
81
|
+
const db = helpdeskDb(ctx);
|
|
82
82
|
const { replyId } = event.payload;
|
|
83
83
|
const reply = await replyExecutor.detail({ id: replyId }, platformActor(), db);
|
|
84
|
-
if (!reply) return writeFailure(new NotFoundError(
|
|
84
|
+
if (!reply) return writeFailure(new NotFoundError(HELPDESK_REPLY_ENTITY, replyId));
|
|
85
85
|
const request = await requestExecutor.detail({ id: reply.requestId }, platformActor(), db);
|
|
86
86
|
if (!request) {
|
|
87
|
-
return writeFailure(new NotFoundError(
|
|
87
|
+
return writeFailure(new NotFoundError(HELPDESK_REQUEST_ENTITY, reply.requestId));
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const author = await loadUserLabel(db, reply.authorUserId);
|
|
@@ -96,11 +96,11 @@ export function createSendReplyMailHandler(opts: ContactOptions) {
|
|
|
96
96
|
const locale = request.locale ?? undefined;
|
|
97
97
|
|
|
98
98
|
await sendBestEffort(ctx, "reply mail", (notify) =>
|
|
99
|
-
notify(
|
|
99
|
+
notify(HELPDESK_NOTIFICATION_TYPES.reply, {
|
|
100
100
|
route: { email: recipientEmail },
|
|
101
101
|
recipientId: request.id,
|
|
102
102
|
data: {
|
|
103
|
-
...
|
|
103
|
+
...helpdeskReplyVariables({
|
|
104
104
|
requestSubject: request.subject,
|
|
105
105
|
requestMessage: request.message,
|
|
106
106
|
requestSubmittedAt: Number(request.submittedAt.epochMilliseconds),
|
|
@@ -112,9 +112,9 @@ export function createSendReplyMailHandler(opts: ContactOptions) {
|
|
|
112
112
|
...(replyTo !== undefined && { replyTo }),
|
|
113
113
|
...(attachments.length > 0 && { attachments }),
|
|
114
114
|
},
|
|
115
|
-
idempotencyKey:
|
|
115
|
+
idempotencyKey: helpdeskIdempotencyKeys.reply(replyId),
|
|
116
116
|
priority: "normal",
|
|
117
|
-
locale:
|
|
117
|
+
locale: resolveHelpdeskMailLocale(locale),
|
|
118
118
|
}),
|
|
119
119
|
);
|
|
120
120
|
|
|
@@ -5,39 +5,43 @@ import {
|
|
|
5
5
|
writeFailure,
|
|
6
6
|
} from "@cosmicdrift/kumiko-framework/errors";
|
|
7
7
|
import { adminAccess } from "../lib.ts";
|
|
8
|
-
import {
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { helpdeskTestVariables, resolveHelpdeskMailLocale } from "../mail.ts";
|
|
9
|
+
import type { HelpdeskOptions } from "../options.ts";
|
|
10
|
+
import { HelpdeskEmptySchema } from "../payloads.ts";
|
|
11
|
+
import {
|
|
12
|
+
HELPDESK_NOTIFICATION_TYPES,
|
|
13
|
+
HelpdeskConfigKeys,
|
|
14
|
+
HelpdeskErrors,
|
|
15
|
+
} from "../web/constants.ts";
|
|
12
16
|
|
|
13
|
-
export type
|
|
17
|
+
export type HelpdeskSendTestData = { readonly kind: "sent" };
|
|
14
18
|
|
|
15
|
-
export function createSendTestHandler(opts:
|
|
16
|
-
return defineWriteHandler<"send-test", typeof
|
|
19
|
+
export function createSendTestHandler(opts: HelpdeskOptions) {
|
|
20
|
+
return defineWriteHandler<"send-test", typeof HelpdeskEmptySchema, HelpdeskSendTestData>({
|
|
17
21
|
name: "send-test",
|
|
18
|
-
schema:
|
|
22
|
+
schema: HelpdeskEmptySchema,
|
|
19
23
|
access: adminAccess,
|
|
20
24
|
agent: { expose: false },
|
|
21
25
|
description:
|
|
22
26
|
"Sends a test message to the configured Telegram chat; fails with a typed error when no chat is configured or the provider does not accept the message, so a SystemAdmin can verify bot token and chat id.",
|
|
23
27
|
handler: async (event, ctx) => {
|
|
24
|
-
const chatId = await ctx.config?.(
|
|
28
|
+
const chatId = await ctx.config?.(HelpdeskConfigKeys.telegramChat);
|
|
25
29
|
if (typeof chatId !== "string" || chatId.trim() === "") {
|
|
26
|
-
return writeFailure(new UnprocessableError(
|
|
30
|
+
return writeFailure(new UnprocessableError(HelpdeskErrors.telegramChatMissing));
|
|
27
31
|
}
|
|
28
32
|
if (!ctx.notify) {
|
|
29
33
|
throw new InternalError({ message: "ctx.notify unavailable — mount the delivery feature" });
|
|
30
34
|
}
|
|
31
35
|
const locale = opts.adminLocale ?? "en";
|
|
32
|
-
const result = await ctx.notify(
|
|
36
|
+
const result = await ctx.notify(HELPDESK_NOTIFICATION_TYPES.test, {
|
|
33
37
|
route: { telegram: chatId.trim() },
|
|
34
38
|
recipientId: event.user.id,
|
|
35
|
-
data:
|
|
39
|
+
data: helpdeskTestVariables({ appName: opts.appName, locale }),
|
|
36
40
|
immediate: true,
|
|
37
|
-
locale:
|
|
41
|
+
locale: resolveHelpdeskMailLocale(locale),
|
|
38
42
|
});
|
|
39
43
|
if (result.deliveries.some((d) => d.status === "failed")) {
|
|
40
|
-
return writeFailure(new UnprocessableError(
|
|
44
|
+
return writeFailure(new UnprocessableError(HelpdeskErrors.telegramTestFailed));
|
|
41
45
|
}
|
|
42
46
|
return { isSuccess: true, data: { kind: "sent" } };
|
|
43
47
|
},
|
|
@@ -16,37 +16,37 @@ import { generateId } from "@cosmicdrift/kumiko-framework/utils";
|
|
|
16
16
|
import type { PayloadRateLimitOption } from "@cosmicdrift/kumiko-types/handlers";
|
|
17
17
|
import { consumeChallenge } from "../challenge.ts";
|
|
18
18
|
import {
|
|
19
|
-
|
|
19
|
+
helpdeskDb,
|
|
20
20
|
normalizeEmail,
|
|
21
21
|
phoneProblem,
|
|
22
22
|
platformActor,
|
|
23
23
|
requestExecutor,
|
|
24
24
|
sendBestEffort,
|
|
25
25
|
} from "../lib.ts";
|
|
26
|
-
import {
|
|
26
|
+
import { helpdeskAcknowledgementVariables, resolveHelpdeskMailLocale } from "../mail.ts";
|
|
27
27
|
import {
|
|
28
|
-
type ContactOptions,
|
|
29
|
-
type ContactSettings,
|
|
30
28
|
DEFAULT_SUBMIT_EMAIL_RATE_LIMITS,
|
|
31
29
|
DEFAULT_SUBMIT_RATE_LIMIT,
|
|
30
|
+
type HelpdeskOptions,
|
|
31
|
+
type HelpdeskSettings,
|
|
32
32
|
} from "../options.ts";
|
|
33
|
-
import { type
|
|
33
|
+
import { type HelpdeskSubmitInput, HelpdeskSubmitSchema } from "../payloads.ts";
|
|
34
34
|
import { verifyProofOfWork } from "../pow.ts";
|
|
35
35
|
import { deriveSubjectFromMessage } from "../subject.ts";
|
|
36
36
|
import { summarizeUserAgent } from "../user-agent.ts";
|
|
37
37
|
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
HELPDESK_NOTIFICATION_TYPES,
|
|
39
|
+
HELPDESK_SOURCE,
|
|
40
|
+
HELPDESK_STATUS,
|
|
41
|
+
HelpdeskHandlers,
|
|
42
|
+
helpdeskIdempotencyKeys,
|
|
43
43
|
} from "../web/constants.ts";
|
|
44
44
|
import { SUBMIT_ROLES } from "./access.ts";
|
|
45
45
|
|
|
46
|
-
export type
|
|
46
|
+
export type HelpdeskSubmitData = { readonly kind: "submitted" };
|
|
47
47
|
|
|
48
48
|
// Identical body for stored and silently dropped submits, so a bot learns nothing from it.
|
|
49
|
-
const SUBMITTED: WriteResult<
|
|
49
|
+
const SUBMITTED: WriteResult<HelpdeskSubmitData> = {
|
|
50
50
|
isSuccess: true,
|
|
51
51
|
data: { kind: "submitted" },
|
|
52
52
|
};
|
|
@@ -54,7 +54,7 @@ const SUBMITTED: WriteResult<ContactSubmitData> = {
|
|
|
54
54
|
type DropReason = "honeypot" | "challenge" | "too_fast" | "proof_of_work";
|
|
55
55
|
|
|
56
56
|
// An explicitly bound `undefined` is an error for the postgres driver; a missing key is not.
|
|
57
|
-
function presentOptionalFields(payload:
|
|
57
|
+
function presentOptionalFields(payload: HelpdeskSubmitInput) {
|
|
58
58
|
return {
|
|
59
59
|
...(payload.phone !== undefined && payload.phone !== "" && { phone: payload.phone }),
|
|
60
60
|
...(payload.page !== undefined && payload.page !== "" && { page: payload.page }),
|
|
@@ -62,15 +62,15 @@ function presentOptionalFields(payload: ContactSubmitInput) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
async function findDropReason(
|
|
65
|
-
payload:
|
|
65
|
+
payload: HelpdeskSubmitInput,
|
|
66
66
|
ctx: HandlerContext,
|
|
67
|
-
settings:
|
|
67
|
+
settings: HelpdeskSettings,
|
|
68
68
|
): Promise<DropReason | null> {
|
|
69
69
|
if (payload.website !== undefined && payload.website.trim() !== "") return "honeypot";
|
|
70
70
|
const redis = ctx.services.redis;
|
|
71
71
|
if (!redis) {
|
|
72
72
|
throw new InternalError({
|
|
73
|
-
message: "
|
|
73
|
+
message: "helpdesk:submit requires ctx.services.redis for the challenge store",
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
const issued = await consumeChallenge(redis, payload.challenge);
|
|
@@ -89,18 +89,19 @@ async function findDropReason(
|
|
|
89
89
|
// real owner out. Only submits that passed the spam checks count. An empty list disables the limit.
|
|
90
90
|
async function enforceEmailLimits(
|
|
91
91
|
ctx: HandlerContext,
|
|
92
|
-
payload:
|
|
92
|
+
payload: HelpdeskSubmitInput,
|
|
93
93
|
limits: readonly PayloadRateLimitOption[],
|
|
94
94
|
): Promise<WriteFailure | null> {
|
|
95
95
|
if (limits.length === 0) return null;
|
|
96
96
|
const { rateLimit } = ctx.services;
|
|
97
97
|
if (!rateLimit || !ctx.rateLimitDigest) {
|
|
98
98
|
throw new InternalError({
|
|
99
|
-
message:
|
|
99
|
+
message:
|
|
100
|
+
"helpdesk:submit declares an email rate limit but no rate limiter or digest is wired",
|
|
100
101
|
});
|
|
101
102
|
}
|
|
102
103
|
const requests = limits.map(({ per, limit, windowSeconds, cost, normalize }) => ({
|
|
103
|
-
bucket: `
|
|
104
|
+
bucket: `helpdesk-submit:${per.payloadField}:${ctx.rateLimitDigest?.(
|
|
104
105
|
normalizePayloadBucketValue(payload.email, normalize),
|
|
105
106
|
)}`,
|
|
106
107
|
config: { limit, windowSeconds, ...(cost !== undefined && { cost }) },
|
|
@@ -114,11 +115,11 @@ async function enforceEmailLimits(
|
|
|
114
115
|
return null;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
export function createSubmitHandler(opts:
|
|
118
|
+
export function createSubmitHandler(opts: HelpdeskOptions, settings: HelpdeskSettings) {
|
|
118
119
|
const emailRateLimits = opts.emailRateLimits ?? DEFAULT_SUBMIT_EMAIL_RATE_LIMITS;
|
|
119
|
-
return defineWriteHandler<"submit", typeof
|
|
120
|
+
return defineWriteHandler<"submit", typeof HelpdeskSubmitSchema, HelpdeskSubmitData>({
|
|
120
121
|
name: "submit",
|
|
121
|
-
schema:
|
|
122
|
+
schema: HelpdeskSubmitSchema,
|
|
122
123
|
access: { roles: SUBMIT_ROLES, personalData: "public-intake", anySignedIn: true },
|
|
123
124
|
rateLimit: opts.rateLimit ?? DEFAULT_SUBMIT_RATE_LIMIT,
|
|
124
125
|
agent: { expose: false },
|
|
@@ -128,7 +129,7 @@ export function createSubmitHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
128
129
|
const payload = event.payload;
|
|
129
130
|
const dropReason = await findDropReason(payload, ctx, settings);
|
|
130
131
|
if (dropReason !== null) {
|
|
131
|
-
ctx.obs.log?.info("[
|
|
132
|
+
ctx.obs.log?.info("[helpdesk:submit] dropped", { reason: dropReason });
|
|
132
133
|
return SUBMITTED;
|
|
133
134
|
}
|
|
134
135
|
|
|
@@ -146,8 +147,8 @@ export function createSubmitHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
146
147
|
{
|
|
147
148
|
id: requestId,
|
|
148
149
|
kind: payload.kind,
|
|
149
|
-
status:
|
|
150
|
-
source:
|
|
150
|
+
status: HELPDESK_STATUS.Open,
|
|
151
|
+
source: HELPDESK_SOURCE.Website,
|
|
151
152
|
subject: deriveSubjectFromMessage(payload.message),
|
|
152
153
|
message: payload.message,
|
|
153
154
|
name: payload.name,
|
|
@@ -161,30 +162,30 @@ export function createSubmitHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
161
162
|
replyCount: 0,
|
|
162
163
|
},
|
|
163
164
|
platformActor(),
|
|
164
|
-
|
|
165
|
+
helpdeskDb(ctx),
|
|
165
166
|
);
|
|
166
167
|
if (!created.isSuccess) return created;
|
|
167
168
|
|
|
168
169
|
await sendBestEffort(ctx, "forward request", async () => {
|
|
169
170
|
const forwarded = await ctx.dispatch.writeAs(
|
|
170
171
|
platformActor(),
|
|
171
|
-
|
|
172
|
+
HelpdeskHandlers.forwardRequest,
|
|
172
173
|
{ requestId },
|
|
173
174
|
);
|
|
174
175
|
if (!forwarded.isSuccess) throw new Error(forwarded.error.message);
|
|
175
176
|
});
|
|
176
177
|
|
|
177
178
|
await sendBestEffort(ctx, "confirmation mail", (notify) =>
|
|
178
|
-
notify(
|
|
179
|
+
notify(HELPDESK_NOTIFICATION_TYPES.acknowledgement, {
|
|
179
180
|
route: { email },
|
|
180
181
|
recipientId: requestId,
|
|
181
|
-
data:
|
|
182
|
+
data: helpdeskAcknowledgementVariables({
|
|
182
183
|
appName: opts.appName,
|
|
183
184
|
locale: payload.locale,
|
|
184
185
|
}),
|
|
185
|
-
idempotencyKey:
|
|
186
|
+
idempotencyKey: helpdeskIdempotencyKeys.confirmation(requestId),
|
|
186
187
|
priority: "normal",
|
|
187
|
-
locale:
|
|
188
|
+
locale: resolveHelpdeskMailLocale(payload.locale),
|
|
188
189
|
}),
|
|
189
190
|
);
|
|
190
191
|
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
import { copyPendingFileRefsToTenant } from "@cosmicdrift/kumiko-framework/files";
|
|
7
7
|
import type { WriteResult } from "@cosmicdrift/kumiko-types/handlers";
|
|
8
8
|
import { fileContextForTenant } from "../../file-foundation/index.ts";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { helpdeskDb, platformActor } from "../lib.ts";
|
|
10
|
+
import { HELPDESK_UPLOAD_FIELD } from "../web/constants.ts";
|
|
11
11
|
|
|
12
12
|
// The form uploads into the submitter's tenant; the request or reply lives in the system tenant.
|
|
13
13
|
export async function takeOverUploads(
|
|
@@ -21,7 +21,7 @@ export async function takeOverUploads(
|
|
|
21
21
|
},
|
|
22
22
|
): Promise<WriteResult<readonly string[]>> {
|
|
23
23
|
if (args.fileIds.length === 0) return { isSuccess: true, data: [] };
|
|
24
|
-
const db =
|
|
24
|
+
const db = helpdeskDb(ctx);
|
|
25
25
|
const submitterTenantId = args.user.tenantId;
|
|
26
26
|
return copyPendingFileRefsToTenant({
|
|
27
27
|
source: {
|
|
@@ -29,7 +29,7 @@ export async function takeOverUploads(
|
|
|
29
29
|
user: args.user,
|
|
30
30
|
files: fileContextForTenant(ctx, submitterTenantId, submitterTenantId),
|
|
31
31
|
entityType: args.screen,
|
|
32
|
-
fieldName:
|
|
32
|
+
fieldName: HELPDESK_UPLOAD_FIELD,
|
|
33
33
|
},
|
|
34
34
|
target: {
|
|
35
35
|
db,
|
|
@@ -38,7 +38,7 @@ export async function takeOverUploads(
|
|
|
38
38
|
files: fileContextForTenant(ctx, submitterTenantId, SYSTEM_TENANT_ID),
|
|
39
39
|
attachTo: {
|
|
40
40
|
entityType: args.entityType,
|
|
41
|
-
fieldName:
|
|
41
|
+
fieldName: HELPDESK_UPLOAD_FIELD,
|
|
42
42
|
entityId: args.entityId,
|
|
43
43
|
},
|
|
44
44
|
},
|