@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
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
-
import { adminAccess,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { adminAccess, helpdeskDb, platformActor, requestExecutor } from "../lib.ts";
|
|
4
|
+
import { HelpdeskMarkDoneSchema } from "../payloads.ts";
|
|
5
|
+
import { HELPDESK_REQUEST_ENTITY, HELPDESK_STATUS } from "../web/constants.ts";
|
|
6
6
|
|
|
7
|
-
export type
|
|
7
|
+
export type HelpdeskMarkDoneData = { readonly kind: "marked"; readonly changed: number };
|
|
8
8
|
|
|
9
9
|
export const markDoneHandler = defineWriteHandler<
|
|
10
10
|
"mark-done",
|
|
11
|
-
typeof
|
|
12
|
-
|
|
11
|
+
typeof HelpdeskMarkDoneSchema,
|
|
12
|
+
HelpdeskMarkDoneData
|
|
13
13
|
>({
|
|
14
14
|
name: "mark-done",
|
|
15
|
-
schema:
|
|
15
|
+
schema: HelpdeskMarkDoneSchema,
|
|
16
16
|
access: adminAccess,
|
|
17
17
|
agent: { expose: false },
|
|
18
18
|
description:
|
|
19
19
|
"Marks one contact request as done without sending a reply; a finished request is left as it is.",
|
|
20
20
|
handler: async (event, ctx) => {
|
|
21
|
-
const db =
|
|
21
|
+
const db = helpdeskDb(ctx);
|
|
22
22
|
const { id } = event.payload;
|
|
23
23
|
const request = await requestExecutor.detail({ id }, platformActor(), db);
|
|
24
|
-
if (!request) return writeFailure(new NotFoundError(
|
|
25
|
-
if (request.status ===
|
|
24
|
+
if (!request) return writeFailure(new NotFoundError(HELPDESK_REQUEST_ENTITY, id));
|
|
25
|
+
if (request.status === HELPDESK_STATUS.Done) {
|
|
26
26
|
return { isSuccess: true, data: { kind: "marked", changed: 0 } };
|
|
27
27
|
}
|
|
28
28
|
const updated = await requestExecutor.update(
|
|
29
29
|
{
|
|
30
30
|
id,
|
|
31
31
|
version: request.version,
|
|
32
|
-
changes: { status:
|
|
32
|
+
changes: { status: HELPDESK_STATUS.Done, closedAt: ctx.tz.now() },
|
|
33
33
|
},
|
|
34
34
|
platformActor(),
|
|
35
35
|
db,
|
package/packages/bundled-features/src/{contact → helpdesk}/handlers/notify-reporter-in-app.write.ts
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { tenantMembershipsTable } from "../../tenant/index.ts";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { helpdeskDb, IN_APP_FEATURE, internalAccess, sendBestEffort } from "../lib.ts";
|
|
5
|
+
import { helpdeskReplyInAppData, resolveHelpdeskMailLocale } from "../mail.ts";
|
|
6
|
+
import { HelpdeskNotifyReporterInAppSchema } from "../payloads.ts";
|
|
7
|
+
import { HELPDESK_NOTIFICATION_TYPES, helpdeskIdempotencyKeys } from "../web/constants.ts";
|
|
8
8
|
|
|
9
|
-
export type
|
|
9
|
+
export type HelpdeskNotifyReporterData = {
|
|
10
10
|
readonly kind: "notified" | "skipped";
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -14,33 +14,33 @@ export type ContactNotifyReporterData = {
|
|
|
14
14
|
// tenant's inbox. The note names the author only; the answer itself goes by mail.
|
|
15
15
|
export const notifyReporterInAppHandler = defineWriteHandler<
|
|
16
16
|
"notify-reporter-in-app",
|
|
17
|
-
typeof
|
|
18
|
-
|
|
17
|
+
typeof HelpdeskNotifyReporterInAppSchema,
|
|
18
|
+
HelpdeskNotifyReporterData
|
|
19
19
|
>({
|
|
20
20
|
name: "notify-reporter-in-app",
|
|
21
|
-
schema:
|
|
21
|
+
schema: HelpdeskNotifyReporterInAppSchema,
|
|
22
22
|
access: internalAccess,
|
|
23
23
|
agent: { expose: false },
|
|
24
24
|
description:
|
|
25
|
-
"Internal: adds an in-app note about a
|
|
25
|
+
"Internal: adds an in-app note about a helpdesk 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
26
|
handler: async (event, ctx) => {
|
|
27
27
|
const { userId, replyId, authorName, locale } = event.payload;
|
|
28
28
|
if (!(await ctx.hasFeature(IN_APP_FEATURE)))
|
|
29
29
|
return { isSuccess: true, data: { kind: "skipped" } };
|
|
30
|
-
const membership = await fetchOne(
|
|
30
|
+
const membership = await fetchOne(helpdeskDb(ctx), tenantMembershipsTable, {
|
|
31
31
|
userId,
|
|
32
32
|
tenantId: event.user.tenantId,
|
|
33
33
|
});
|
|
34
34
|
if (!membership) return { isSuccess: true, data: { kind: "skipped" } };
|
|
35
35
|
|
|
36
36
|
await sendBestEffort(ctx, "reply in-app note", (notify) =>
|
|
37
|
-
notify(
|
|
37
|
+
notify(HELPDESK_NOTIFICATION_TYPES.replyInApp, {
|
|
38
38
|
route: { inApp: userId },
|
|
39
39
|
recipientId: userId,
|
|
40
|
-
data:
|
|
41
|
-
idempotencyKey:
|
|
40
|
+
data: helpdeskReplyInAppData({ authorName, locale }),
|
|
41
|
+
idempotencyKey: helpdeskIdempotencyKeys.replyInApp(replyId),
|
|
42
42
|
priority: "normal",
|
|
43
|
-
locale:
|
|
43
|
+
locale: resolveHelpdeskMailLocale(locale),
|
|
44
44
|
}),
|
|
45
45
|
);
|
|
46
46
|
return { isSuccess: true, data: { kind: "notified" } };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import { adminAccess,
|
|
3
|
-
import {
|
|
2
|
+
import { adminAccess, helpdeskDb } from "../lib.ts";
|
|
3
|
+
import { HelpdeskEmptySchema } from "../payloads.ts";
|
|
4
4
|
import { countOpenRequests } from "./open-count.ts";
|
|
5
5
|
|
|
6
6
|
export const openCountQuery = defineQueryHandler({
|
|
7
7
|
name: "open-count",
|
|
8
|
-
schema:
|
|
8
|
+
schema: HelpdeskEmptySchema,
|
|
9
9
|
access: adminAccess,
|
|
10
10
|
description:
|
|
11
11
|
"Counts the contact requests that still wait for a first answer, for the dashboard tile.",
|
|
12
12
|
handler: async (_event, ctx) => {
|
|
13
|
-
return { count: await countOpenRequests(
|
|
13
|
+
return { count: await countOpenRequests(helpdeskDb(ctx)) };
|
|
14
14
|
},
|
|
15
15
|
});
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { platformActor, requestExecutor } from "../lib.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { HELPDESK_STATUS } from "../web/constants.ts";
|
|
4
4
|
|
|
5
5
|
// Open means no answer yet; an answered request counts as handled even before it is marked done.
|
|
6
6
|
export async function countOpenRequests(db: TenantDb): Promise<number> {
|
|
7
7
|
const found = await requestExecutor.list(
|
|
8
8
|
{
|
|
9
|
-
filter: { field: "status", op: "eq", value:
|
|
9
|
+
filter: { field: "status", op: "eq", value: HELPDESK_STATUS.Open },
|
|
10
10
|
limit: 1,
|
|
11
11
|
totalCount: true,
|
|
12
12
|
},
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { NotFoundError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
-
import { adminAccess,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { adminAccess, helpdeskDb, listRepliesOf, platformActor, requestExecutor } from "../lib.ts";
|
|
4
|
+
import { HelpdeskIdSchema } from "../payloads.ts";
|
|
5
|
+
import { HELPDESK_REQUEST_ENTITY } from "../web/constants.ts";
|
|
6
6
|
|
|
7
7
|
export const repliesQuery = defineQueryHandler({
|
|
8
8
|
name: "replies",
|
|
9
|
-
schema:
|
|
9
|
+
schema: HelpdeskIdSchema,
|
|
10
10
|
access: adminAccess,
|
|
11
11
|
description:
|
|
12
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
13
|
handler: async (event, ctx) => {
|
|
14
|
-
const db =
|
|
14
|
+
const db = helpdeskDb(ctx);
|
|
15
15
|
const { id } = event.payload;
|
|
16
16
|
const request = await requestExecutor.detail({ id }, platformActor(), db);
|
|
17
|
-
if (!request) throw new NotFoundError(
|
|
17
|
+
if (!request) throw new NotFoundError(HELPDESK_REQUEST_ENTITY, id);
|
|
18
18
|
const replies = await listRepliesOf(db, id);
|
|
19
19
|
return {
|
|
20
20
|
rows: replies.map((reply) => ({
|
|
@@ -12,7 +12,7 @@ import { generateId } from "@cosmicdrift/kumiko-framework/utils";
|
|
|
12
12
|
import { parseTenantId } from "@cosmicdrift/kumiko-types/identifiers";
|
|
13
13
|
import {
|
|
14
14
|
adminAccess,
|
|
15
|
-
|
|
15
|
+
helpdeskDb,
|
|
16
16
|
loadUserLabel,
|
|
17
17
|
pickReplyChannels,
|
|
18
18
|
platformActor,
|
|
@@ -20,23 +20,23 @@ import {
|
|
|
20
20
|
requestExecutor,
|
|
21
21
|
sendBestEffort,
|
|
22
22
|
} from "../lib.ts";
|
|
23
|
-
import {
|
|
23
|
+
import { HelpdeskReplySchema } from "../payloads.ts";
|
|
24
24
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type
|
|
32
|
-
|
|
25
|
+
HELPDESK_REPLY_CHANNELS,
|
|
26
|
+
HELPDESK_REPLY_ENTITY,
|
|
27
|
+
HELPDESK_REQUEST_ENTITY,
|
|
28
|
+
HELPDESK_STATUS,
|
|
29
|
+
HelpdeskErrors,
|
|
30
|
+
HelpdeskHandlers,
|
|
31
|
+
type HelpdeskReplyChannels,
|
|
32
|
+
HelpdeskScreens,
|
|
33
33
|
} from "../web/constants.ts";
|
|
34
34
|
import { takeOverUploads } from "./take-over-uploads.ts";
|
|
35
35
|
|
|
36
|
-
export type
|
|
36
|
+
export type HelpdeskReplyData = {
|
|
37
37
|
readonly kind: "replied";
|
|
38
38
|
readonly id: string;
|
|
39
|
-
readonly status: typeof
|
|
39
|
+
readonly status: typeof HELPDESK_STATUS.Answered | typeof HELPDESK_STATUS.Done;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
type InAppNoteArgs = {
|
|
@@ -58,7 +58,7 @@ async function noteReporterInApp(ctx: HandlerContext, args: InAppNoteArgs): Prom
|
|
|
58
58
|
await sendBestEffort(ctx, "reply in-app note", async () => {
|
|
59
59
|
const noted = await ctx.dispatch.writeAs(
|
|
60
60
|
createSystemUser(tenantId),
|
|
61
|
-
|
|
61
|
+
HelpdeskHandlers.notifyReporterInApp,
|
|
62
62
|
{
|
|
63
63
|
replyId: args.replyId,
|
|
64
64
|
requestId: request.id,
|
|
@@ -83,14 +83,14 @@ type PersistReplyArgs = {
|
|
|
83
83
|
readonly authorUserId: string;
|
|
84
84
|
readonly authorName: string;
|
|
85
85
|
readonly fileIds: readonly string[];
|
|
86
|
-
readonly channels:
|
|
87
|
-
readonly status:
|
|
86
|
+
readonly channels: HelpdeskReplyChannels;
|
|
87
|
+
readonly status: HelpdeskReplyData["status"];
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
// Returns the failing write result, or null when reply and request update both succeeded.
|
|
91
91
|
async function persistReply(
|
|
92
92
|
ctx: HandlerContext,
|
|
93
|
-
db: ReturnType<typeof
|
|
93
|
+
db: ReturnType<typeof helpdeskDb>,
|
|
94
94
|
args: PersistReplyArgs,
|
|
95
95
|
) {
|
|
96
96
|
const { request } = args;
|
|
@@ -118,7 +118,7 @@ async function persistReply(
|
|
|
118
118
|
changes: {
|
|
119
119
|
status: args.status,
|
|
120
120
|
answeredAt: sentAt,
|
|
121
|
-
...(args.status ===
|
|
121
|
+
...(args.status === HELPDESK_STATUS.Done && { closedAt: sentAt }),
|
|
122
122
|
replyCount: (request.replyCount ?? 0) + 1,
|
|
123
123
|
},
|
|
124
124
|
},
|
|
@@ -129,16 +129,16 @@ async function persistReply(
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
// The drawer variant the admin used is chosen by the reply channels, and pending uploads hang under that screen.
|
|
132
|
-
function replyScreenFor(channels:
|
|
133
|
-
return channels ===
|
|
134
|
-
?
|
|
135
|
-
:
|
|
132
|
+
function replyScreenFor(channels: HelpdeskReplyChannels): string {
|
|
133
|
+
return channels === HELPDESK_REPLY_CHANNELS.EmailAndInApp
|
|
134
|
+
? HelpdeskScreens.reply
|
|
135
|
+
: HelpdeskScreens.replyMail;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
export function createReplyHandler() {
|
|
139
|
-
return defineWriteHandler<"reply", typeof
|
|
139
|
+
return defineWriteHandler<"reply", typeof HelpdeskReplySchema, HelpdeskReplyData>({
|
|
140
140
|
name: "reply",
|
|
141
|
-
schema:
|
|
141
|
+
schema: HelpdeskReplySchema,
|
|
142
142
|
access: adminAccess,
|
|
143
143
|
description:
|
|
144
144
|
"A SystemAdmin answers a contact request: stores the reply (uploaded files are taken over into the system tenant), mails it to the reporter (Reply-To set, optional attachments, quoting the original request) and, for a signed-in reporter, adds an in-app note in the reporter's tenant. Marks the request answered, or done when markDone is set.",
|
|
@@ -146,9 +146,9 @@ export function createReplyHandler() {
|
|
|
146
146
|
agent: { expose: false },
|
|
147
147
|
handler: async (event, ctx) => {
|
|
148
148
|
const { requestId, message, markDone } = event.payload;
|
|
149
|
-
const db =
|
|
149
|
+
const db = helpdeskDb(ctx);
|
|
150
150
|
const request = await requestExecutor.detail({ id: requestId }, platformActor(), db);
|
|
151
|
-
if (!request) return writeFailure(new NotFoundError(
|
|
151
|
+
if (!request) return writeFailure(new NotFoundError(HELPDESK_REQUEST_ENTITY, requestId));
|
|
152
152
|
|
|
153
153
|
const replyId = generateId();
|
|
154
154
|
const reporterUserId = request.reporterUserId ?? undefined;
|
|
@@ -156,18 +156,18 @@ export function createReplyHandler() {
|
|
|
156
156
|
const uploaded = await takeOverUploads(ctx, {
|
|
157
157
|
user: event.user,
|
|
158
158
|
screen: replyScreenFor(channels),
|
|
159
|
-
entityType:
|
|
159
|
+
entityType: HELPDESK_REPLY_ENTITY,
|
|
160
160
|
entityId: replyId,
|
|
161
161
|
fileIds: event.payload.fileIds ?? [],
|
|
162
162
|
});
|
|
163
163
|
if (!uploaded.isSuccess) {
|
|
164
|
-
return writeFailure(new UnprocessableError(
|
|
164
|
+
return writeFailure(new UnprocessableError(HelpdeskErrors.attachmentNotFound));
|
|
165
165
|
}
|
|
166
166
|
const fileIds = uploaded.data;
|
|
167
167
|
const author = await loadUserLabel(db, event.user.id);
|
|
168
168
|
const authorName = author?.name ?? event.user.id;
|
|
169
169
|
|
|
170
|
-
const status = markDone ?
|
|
170
|
+
const status = markDone ? HELPDESK_STATUS.Done : HELPDESK_STATUS.Answered;
|
|
171
171
|
const failed = await persistReply(ctx, db, {
|
|
172
172
|
replyId,
|
|
173
173
|
request,
|
|
@@ -181,13 +181,13 @@ export function createReplyHandler() {
|
|
|
181
181
|
if (failed !== null) return failed;
|
|
182
182
|
|
|
183
183
|
await sendBestEffort(ctx, "reply mail", async () => {
|
|
184
|
-
const sent = await ctx.dispatch.writeAs(platformActor(),
|
|
184
|
+
const sent = await ctx.dispatch.writeAs(platformActor(), HelpdeskHandlers.sendReplyMail, {
|
|
185
185
|
replyId,
|
|
186
186
|
});
|
|
187
187
|
if (!sent.isSuccess) throw new Error(sent.error.message);
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
if (channels ===
|
|
190
|
+
if (channels === HELPDESK_REPLY_CHANNELS.EmailAndInApp) {
|
|
191
191
|
await noteReporterInApp(ctx, { replyId, request, authorName });
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -3,7 +3,7 @@ import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
|
3
3
|
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import { generateId } from "@cosmicdrift/kumiko-framework/utils";
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
helpdeskDb,
|
|
7
7
|
loadTenantName,
|
|
8
8
|
loadTenantPlan,
|
|
9
9
|
loadUserLabel,
|
|
@@ -13,30 +13,30 @@ import {
|
|
|
13
13
|
requestExecutor,
|
|
14
14
|
sendBestEffort,
|
|
15
15
|
} from "../lib.ts";
|
|
16
|
-
import {
|
|
17
|
-
import { type
|
|
18
|
-
import {
|
|
16
|
+
import { helpdeskConfirmationVariables, resolveHelpdeskMailLocale } from "../mail.ts";
|
|
17
|
+
import { type HelpdeskOptions, type HelpdeskSettings, REPORT_RATE_LIMIT } from "../options.ts";
|
|
18
|
+
import { HelpdeskReportSchema } from "../payloads.ts";
|
|
19
19
|
import { summarizeUserAgent } from "../user-agent.ts";
|
|
20
20
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
HELPDESK_NOTIFICATION_TYPES,
|
|
22
|
+
HELPDESK_REQUEST_ENTITY,
|
|
23
|
+
HELPDESK_SOURCE,
|
|
24
|
+
HELPDESK_STATUS,
|
|
25
|
+
HELPDESK_UPLOAD_FIELD,
|
|
26
|
+
HelpdeskErrors,
|
|
27
|
+
HelpdeskHandlers,
|
|
28
|
+
HelpdeskScreens,
|
|
29
|
+
helpdeskIdempotencyKeys,
|
|
30
30
|
} from "../web/constants.ts";
|
|
31
31
|
import { REPORT_ACCESS } from "./access.ts";
|
|
32
32
|
import { takeOverUploads } from "./take-over-uploads.ts";
|
|
33
33
|
|
|
34
|
-
export type
|
|
34
|
+
export type HelpdeskReportData = { readonly kind: "reported"; readonly id: string };
|
|
35
35
|
|
|
36
|
-
export function createReportHandler(opts:
|
|
37
|
-
return defineWriteHandler<"report", typeof
|
|
36
|
+
export function createReportHandler(opts: HelpdeskOptions, settings: HelpdeskSettings) {
|
|
37
|
+
return defineWriteHandler<"report", typeof HelpdeskReportSchema, HelpdeskReportData>({
|
|
38
38
|
name: "report",
|
|
39
|
-
schema:
|
|
39
|
+
schema: HelpdeskReportSchema,
|
|
40
40
|
access: REPORT_ACCESS,
|
|
41
41
|
rateLimit: REPORT_RATE_LIMIT,
|
|
42
42
|
agent: { expose: false },
|
|
@@ -47,10 +47,10 @@ export function createReportHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
47
47
|
const phoneIssue = phoneProblem(settings.phone, payload.phone);
|
|
48
48
|
if (phoneIssue !== null) return writeFailure(new UnprocessableError(phoneIssue));
|
|
49
49
|
|
|
50
|
-
const db =
|
|
50
|
+
const db = helpdeskDb(ctx);
|
|
51
51
|
const reporter = await loadUserLabel(db, event.user.id);
|
|
52
52
|
if (!reporter?.email) {
|
|
53
|
-
return writeFailure(new UnprocessableError(
|
|
53
|
+
return writeFailure(new UnprocessableError(HelpdeskErrors.reporterEmailMissing));
|
|
54
54
|
}
|
|
55
55
|
const tenantName = await loadTenantName(db, event.user.tenantId);
|
|
56
56
|
const email = normalizeEmail(reporter.email);
|
|
@@ -61,8 +61,8 @@ export function createReportHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
61
61
|
const requestId = generateId();
|
|
62
62
|
const uploaded = await takeOverUploads(ctx, {
|
|
63
63
|
user: event.user,
|
|
64
|
-
screen:
|
|
65
|
-
entityType:
|
|
64
|
+
screen: HelpdeskScreens.report,
|
|
65
|
+
entityType: HELPDESK_REQUEST_ENTITY,
|
|
66
66
|
entityId: requestId,
|
|
67
67
|
fileIds: payload.fileIds ?? [],
|
|
68
68
|
});
|
|
@@ -72,8 +72,8 @@ export function createReportHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
72
72
|
{
|
|
73
73
|
id: requestId,
|
|
74
74
|
kind: payload.kind,
|
|
75
|
-
status:
|
|
76
|
-
source:
|
|
75
|
+
status: HELPDESK_STATUS.Open,
|
|
76
|
+
source: HELPDESK_SOURCE.Admin,
|
|
77
77
|
subject: payload.subject,
|
|
78
78
|
message: payload.message,
|
|
79
79
|
name: reporter.name,
|
|
@@ -87,7 +87,7 @@ export function createReportHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
87
87
|
...(opts.appVersion !== undefined && { appVersion: opts.appVersion }),
|
|
88
88
|
...(browser !== null && { browser }),
|
|
89
89
|
submittedAt: ctx.tz.now(),
|
|
90
|
-
...(fileIds.length > 0 && { [
|
|
90
|
+
...(fileIds.length > 0 && { [HELPDESK_UPLOAD_FIELD]: fileIds }),
|
|
91
91
|
fileCount: fileIds.length,
|
|
92
92
|
replyCount: 0,
|
|
93
93
|
},
|
|
@@ -99,24 +99,24 @@ export function createReportHandler(opts: ContactOptions, settings: ContactSetti
|
|
|
99
99
|
await sendBestEffort(ctx, "forward request", async () => {
|
|
100
100
|
const forwarded = await ctx.dispatch.writeAs(
|
|
101
101
|
platformActor(),
|
|
102
|
-
|
|
102
|
+
HelpdeskHandlers.forwardRequest,
|
|
103
103
|
{ requestId },
|
|
104
104
|
);
|
|
105
105
|
if (!forwarded.isSuccess) throw new Error(forwarded.error.message);
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
await sendBestEffort(ctx, "confirmation mail", (notify) =>
|
|
109
|
-
notify(
|
|
109
|
+
notify(HELPDESK_NOTIFICATION_TYPES.confirmation, {
|
|
110
110
|
route: { email },
|
|
111
111
|
recipientId: requestId,
|
|
112
|
-
data:
|
|
112
|
+
data: helpdeskConfirmationVariables({
|
|
113
113
|
appName: opts.appName,
|
|
114
114
|
message: payload.message,
|
|
115
115
|
locale: ctx.locale,
|
|
116
116
|
}),
|
|
117
|
-
idempotencyKey:
|
|
117
|
+
idempotencyKey: helpdeskIdempotencyKeys.confirmation(requestId),
|
|
118
118
|
priority: "normal",
|
|
119
|
-
locale:
|
|
119
|
+
locale: resolveHelpdeskMailLocale(ctx.locale),
|
|
120
120
|
}),
|
|
121
121
|
);
|
|
122
122
|
|
package/packages/bundled-features/src/{contact → helpdesk}/handlers/request-delivery.query.ts
RENAMED
|
@@ -5,53 +5,53 @@ import { parseTenantId } from "@cosmicdrift/kumiko-types/identifiers";
|
|
|
5
5
|
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
6
6
|
import {
|
|
7
7
|
adminAccess,
|
|
8
|
-
|
|
8
|
+
helpdeskDb,
|
|
9
9
|
listRepliesOf,
|
|
10
10
|
loadUserLabel,
|
|
11
11
|
platformActor,
|
|
12
12
|
requestExecutor,
|
|
13
13
|
} from "../lib.ts";
|
|
14
|
-
import type {
|
|
15
|
-
import {
|
|
14
|
+
import type { HelpdeskOptions } from "../options.ts";
|
|
15
|
+
import { HelpdeskIdSchema } from "../payloads.ts";
|
|
16
16
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
|
|
17
|
+
HELPDESK_DELIVERY_CHANNEL,
|
|
18
|
+
HELPDESK_DELIVERY_STATUS,
|
|
19
|
+
HELPDESK_REQUEST_ENTITY,
|
|
20
|
+
HelpdeskConfigKeys,
|
|
21
|
+
type HelpdeskDeliveryChannel,
|
|
22
|
+
type HelpdeskDeliveryStatus,
|
|
23
|
+
helpdeskIdempotencyKeys,
|
|
24
24
|
} from "../web/constants.ts";
|
|
25
|
-
import { type
|
|
25
|
+
import { type HelpdeskAttempt, loadAttemptsByKey, loadReadAtByKey } from "./attempts.ts";
|
|
26
26
|
|
|
27
27
|
type DeliveryRow = {
|
|
28
28
|
readonly id: string;
|
|
29
|
-
readonly channel:
|
|
29
|
+
readonly channel: HelpdeskDeliveryChannel;
|
|
30
30
|
readonly recipient: string;
|
|
31
31
|
readonly at: string;
|
|
32
|
-
readonly status:
|
|
32
|
+
readonly status: HelpdeskDeliveryStatus;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
function displayStatus(attemptStatus: string):
|
|
35
|
+
function displayStatus(attemptStatus: string): HelpdeskDeliveryStatus {
|
|
36
36
|
switch (attemptStatus) {
|
|
37
37
|
case "sent":
|
|
38
|
-
return
|
|
38
|
+
return HELPDESK_DELIVERY_STATUS.Delivered;
|
|
39
39
|
case "failed":
|
|
40
|
-
return
|
|
40
|
+
return HELPDESK_DELIVERY_STATUS.Failed;
|
|
41
41
|
case "skipped":
|
|
42
|
-
return
|
|
42
|
+
return HELPDESK_DELIVERY_STATUS.Skipped;
|
|
43
43
|
default:
|
|
44
|
-
return
|
|
44
|
+
return HELPDESK_DELIVERY_STATUS.Pending;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function attemptsOf(attempts: readonly
|
|
48
|
+
function attemptsOf(attempts: readonly HelpdeskAttempt[], key: string): readonly HelpdeskAttempt[] {
|
|
49
49
|
return attempts.filter((attempt) => attempt.key === key);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function rowOf(
|
|
53
|
-
attempt:
|
|
54
|
-
channel:
|
|
53
|
+
attempt: HelpdeskAttempt,
|
|
54
|
+
channel: HelpdeskDeliveryChannel,
|
|
55
55
|
recipient: string,
|
|
56
56
|
readAt: Temporal.Instant | null | undefined,
|
|
57
57
|
): DeliveryRow {
|
|
@@ -61,43 +61,43 @@ function rowOf(
|
|
|
61
61
|
channel,
|
|
62
62
|
recipient,
|
|
63
63
|
at: (read ? readAt : attempt.createdAt).toString(),
|
|
64
|
-
status: read ?
|
|
64
|
+
status: read ? HELPDESK_DELIVERY_STATUS.Read : displayStatus(attempt.status),
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
async function adminRows(
|
|
69
69
|
db: TenantDb,
|
|
70
|
-
attempts: readonly
|
|
70
|
+
attempts: readonly HelpdeskAttempt[],
|
|
71
71
|
requestId: string,
|
|
72
72
|
): Promise<readonly DeliveryRow[]> {
|
|
73
73
|
const rows: DeliveryRow[] = [];
|
|
74
|
-
for (const attempt of attemptsOf(attempts,
|
|
74
|
+
for (const attempt of attemptsOf(attempts, helpdeskIdempotencyKeys.admins(requestId))) {
|
|
75
75
|
const admin = attempt.recipientId ? await loadUserLabel(db, attempt.recipientId) : null;
|
|
76
76
|
rows.push(
|
|
77
|
-
rowOf(attempt,
|
|
77
|
+
rowOf(attempt, HELPDESK_DELIVERY_CHANNEL.Email, `${admin?.name ?? "?"} (SystemAdmin)`, null),
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
return rows;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
export function createRequestDeliveryQuery(opts:
|
|
83
|
+
export function createRequestDeliveryQuery(opts: HelpdeskOptions) {
|
|
84
84
|
return defineQueryHandler({
|
|
85
85
|
name: "request-delivery",
|
|
86
|
-
schema:
|
|
86
|
+
schema: HelpdeskIdSchema,
|
|
87
87
|
access: adminAccess,
|
|
88
88
|
description:
|
|
89
89
|
"Returns where one contact request went and how: the admin mails, the Telegram message and each answer as mail and in-app note, each with channel, recipient, time and delivery status (an in-app note shows as read with the time it was opened), as flat rows for a related list.",
|
|
90
90
|
handler: async (event, ctx) => {
|
|
91
|
-
const db =
|
|
91
|
+
const db = helpdeskDb(ctx);
|
|
92
92
|
const { id } = event.payload;
|
|
93
93
|
const request = await requestExecutor.detail({ id }, platformActor(), db);
|
|
94
|
-
if (!request) throw new NotFoundError(
|
|
94
|
+
if (!request) throw new NotFoundError(HELPDESK_REQUEST_ENTITY, id);
|
|
95
95
|
const replies = await listRepliesOf(db, id);
|
|
96
|
-
const replyInAppKeys = replies.map((reply) =>
|
|
96
|
+
const replyInAppKeys = replies.map((reply) => helpdeskIdempotencyKeys.replyInApp(reply.id));
|
|
97
97
|
const attempts = await loadAttemptsByKey(ctx, event.user, [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
...replies.map((reply) =>
|
|
98
|
+
helpdeskIdempotencyKeys.admins(id),
|
|
99
|
+
helpdeskIdempotencyKeys.telegram(id),
|
|
100
|
+
...replies.map((reply) => helpdeskIdempotencyKeys.reply(reply.id)),
|
|
101
101
|
...replyInAppKeys,
|
|
102
102
|
]);
|
|
103
103
|
const reporterTenantId = parseTenantId(request.reporterTenantId);
|
|
@@ -108,12 +108,12 @@ export function createRequestDeliveryQuery(opts: ContactOptions) {
|
|
|
108
108
|
|
|
109
109
|
const rows: DeliveryRow[] = [...(await adminRows(db, attempts, id))];
|
|
110
110
|
if (opts.telegram) {
|
|
111
|
-
const chat = await ctx.config?.(
|
|
112
|
-
for (const attempt of attemptsOf(attempts,
|
|
111
|
+
const chat = await ctx.config?.(HelpdeskConfigKeys.telegramChat);
|
|
112
|
+
for (const attempt of attemptsOf(attempts, helpdeskIdempotencyKeys.telegram(id))) {
|
|
113
113
|
rows.push(
|
|
114
114
|
rowOf(
|
|
115
115
|
attempt,
|
|
116
|
-
|
|
116
|
+
HELPDESK_DELIVERY_CHANNEL.Telegram,
|
|
117
117
|
typeof chat === "string" ? chat : "",
|
|
118
118
|
null,
|
|
119
119
|
),
|
|
@@ -121,16 +121,16 @@ export function createRequestDeliveryQuery(opts: ContactOptions) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
for (const reply of replies) {
|
|
124
|
-
const mailKey =
|
|
124
|
+
const mailKey = helpdeskIdempotencyKeys.reply(reply.id);
|
|
125
125
|
for (const attempt of attemptsOf(attempts, mailKey)) {
|
|
126
|
-
rows.push(rowOf(attempt,
|
|
126
|
+
rows.push(rowOf(attempt, HELPDESK_DELIVERY_CHANNEL.ReplyEmail, request.name, null));
|
|
127
127
|
}
|
|
128
|
-
const inAppKey =
|
|
128
|
+
const inAppKey = helpdeskIdempotencyKeys.replyInApp(reply.id);
|
|
129
129
|
for (const attempt of attemptsOf(attempts, inAppKey)) {
|
|
130
130
|
rows.push(
|
|
131
131
|
rowOf(
|
|
132
132
|
attempt,
|
|
133
|
-
|
|
133
|
+
HELPDESK_DELIVERY_CHANNEL.ReplyInApp,
|
|
134
134
|
request.name,
|
|
135
135
|
readAtByKey.get(inAppKey),
|
|
136
136
|
),
|