@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
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
type AccessRule,
|
|
20
|
+
bootRuleError,
|
|
20
21
|
defineEntityCreateHandler,
|
|
21
22
|
defineEntityDetailHandler,
|
|
22
23
|
defineEntityListHandler,
|
|
@@ -26,6 +27,7 @@ import {
|
|
|
26
27
|
type FeatureRegistrar,
|
|
27
28
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
28
29
|
import { assertNoWhereRuleInOwnershipWrite, resolveFeatureAccess } from "../shared/index.ts";
|
|
30
|
+
import { FOLDERS_BOOT_RULES } from "./boot-rules.ts";
|
|
29
31
|
import { createFolderAssignmentEntity, folderEntity } from "./entity.ts";
|
|
30
32
|
import { createClearFolderHandler } from "./handlers/clear-folder.write.ts";
|
|
31
33
|
import { createDeleteFolderHandler } from "./handlers/delete-folder.write.ts";
|
|
@@ -164,12 +166,13 @@ export function createFoldersFeature(
|
|
|
164
166
|
}
|
|
165
167
|
assertNoWhereRuleInOwnershipWrite("createFoldersFeature", opts.ownership?.write);
|
|
166
168
|
if (opts.parents !== undefined && opts.parents.length === 0) {
|
|
167
|
-
throw
|
|
168
|
-
|
|
169
|
+
throw bootRuleError(FOLDERS_BOOT_RULES.emptyParentsAllowlist, {
|
|
170
|
+
message:
|
|
171
|
+
"createFoldersFeature({ parents }): parents must not be an empty array — " +
|
|
169
172
|
"an empty allowlist rejects every set-folder call and hides every " +
|
|
170
173
|
"assignment row. Omit `parents` to keep every registered entity " +
|
|
171
174
|
"admissible as a host instead.",
|
|
172
|
-
);
|
|
175
|
+
});
|
|
173
176
|
}
|
|
174
177
|
const access = resolveFeatureAccess(opts, DEFAULT_FOLDER_ACCESS);
|
|
175
178
|
return defineFeature(FOLDERS_FEATURE_NAME, (r) =>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BootRuleTable } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
|
|
3
|
+
export const HELPDESK_BOOT_RULES = {
|
|
4
|
+
invalidProofOfWorkBits: {
|
|
5
|
+
id: "helpdesk/invalid-proof-of-work-bits",
|
|
6
|
+
summary: "spamProtection.proofOfWorkBits is an integer within the allowed range.",
|
|
7
|
+
fix: "Use an integer inside the documented bounds.",
|
|
8
|
+
},
|
|
9
|
+
} as const satisfies BootRuleTable;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import * as z from "zod";
|
|
4
|
-
import {
|
|
4
|
+
import { HELPDESK_CHALLENGE_REDIS_PREFIX } from "./web/constants.ts";
|
|
5
5
|
|
|
6
6
|
const CHALLENGE_BYTES = 16;
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ const StoredChallengeSchema = z.object({
|
|
|
11
11
|
});
|
|
12
12
|
export type StoredChallenge = z.infer<typeof StoredChallengeSchema>;
|
|
13
13
|
|
|
14
|
-
const challengeKey = (challenge: string) => `${
|
|
14
|
+
const challengeKey = (challenge: string) => `${HELPDESK_CHALLENGE_REDIS_PREFIX}${challenge}`;
|
|
15
15
|
|
|
16
16
|
export async function issueChallenge(
|
|
17
17
|
redis: Redis,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.413.0",
|
|
4
|
+
"type": "breaking",
|
|
5
|
+
"title": "contact feature renamed to helpdesk",
|
|
6
|
+
"migration": "The bundled feature contact is renamed to helpdesk; nothing keeps the old names. Imports: @cosmicdrift/kumiko-bundled-features/contact, /contact/web and /contact/client become /helpdesk, /helpdesk/web and /helpdesk/client; createContactFeature, contactOpenRequestsPanels, ContactOptions and the other Contact*/CONTACT_* exports become Helpdesk*/HELPDESK_* (createHelpdeskFeature, helpdeskOpenRequestsPanels, HelpdeskOptions). The feature name, handler, screen, config and i18n keys move from contact: to helpdesk:, the entities from contact-request/contact-reply to helpdesk-request/helpdesk-reply with the tables read_helpdesk_requests/read_helpdesk_replies, and error codes from contact_* to helpdesk_*. The browser client is served at GET /helpdesk/client.js and registers window.KumikoHelpdesk; update script tags, same-origin ingress paths and nav/legal references to the feature name. Notification preferences and opt-outs stored under contact:notify: are not carried over; the six notifications start with their defaults. Run kumiko schema generate and commit the migration. Data stored under the old names is not carried over: requests, replies and their events stay inert under contact-request/contact-reply, and the config values contact:config:reply-to and contact:config:telegram-chat are not read any more. Close open requests before upgrading and set reply-to and the Telegram chat again on the forwarding screen."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.410.0",
|
|
4
10
|
"type": "improvement",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// The browser client ships as a string so it survives the tsc-only dist build, which copies no
|
|
2
2
|
// loose .js assets. Keep it free of backslashes, backticks and template placeholders.
|
|
3
|
-
export const
|
|
3
|
+
export const HELPDESK_CLIENT_SOURCE = `(function () {
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
6
|
var QUERY_PATH = "/api/query";
|
|
7
7
|
var WRITE_PATH = "/api/write";
|
|
8
|
-
var CHALLENGE_QUERY = "
|
|
9
|
-
var SUBMIT_WRITE = "
|
|
8
|
+
var CHALLENGE_QUERY = "helpdesk:query:challenge";
|
|
9
|
+
var SUBMIT_WRITE = "helpdesk:write:submit";
|
|
10
10
|
var CSRF_COOKIE_NAME = "kumiko_csrf";
|
|
11
11
|
var CSRF_HEADER_NAME = "X-CSRF-Token";
|
|
12
12
|
var LOCALE_HEADER_NAME = "X-Locale";
|
|
@@ -198,6 +198,6 @@ export const CONTACT_CLIENT_SOURCE = `(function () {
|
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
window.
|
|
201
|
+
window.KumikoHelpdesk = { load: load, submit: submit };
|
|
202
202
|
})();
|
|
203
203
|
`;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as z from "zod";
|
|
2
|
+
import type { HelpdeskSubmitSchema } from "../payloads.ts";
|
|
3
|
+
import type { HELPDESK_WEBSITE_KINDS, HelpdeskPhoneMode } from "../web/constants.ts";
|
|
4
|
+
|
|
5
|
+
export type HelpdeskWebsiteKind = (typeof HELPDESK_WEBSITE_KINDS)[number];
|
|
6
|
+
|
|
7
|
+
export type HelpdeskWebsiteFormOptions = {
|
|
8
|
+
readonly phone: HelpdeskPhoneMode;
|
|
9
|
+
readonly kinds: readonly HelpdeskWebsiteKind[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// The client adds challenge and nonce itself and falls back to the page language for locale.
|
|
13
|
+
export type HelpdeskWebsiteSubmitFields = Omit<
|
|
14
|
+
z.input<typeof HelpdeskSubmitSchema>,
|
|
15
|
+
"challenge" | "nonce" | "locale"
|
|
16
|
+
> & { readonly locale?: z.input<typeof HelpdeskSubmitSchema>["locale"] };
|
|
17
|
+
|
|
18
|
+
export type HelpdeskWebsiteSubmitResult =
|
|
19
|
+
| { readonly kind: "sent" }
|
|
20
|
+
| { readonly kind: "rate-limited"; readonly retryAfterSeconds?: number }
|
|
21
|
+
| { readonly kind: "failed" };
|
|
22
|
+
|
|
23
|
+
export type HelpdeskWebsiteClient = {
|
|
24
|
+
load(): Promise<HelpdeskWebsiteFormOptions>;
|
|
25
|
+
submit(fields: HelpdeskWebsiteSubmitFields): Promise<HelpdeskWebsiteSubmitResult>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Registered by HELPDESK_CLIENT_SOURCE as window.KumikoHelpdesk.
|
|
29
|
+
export type HelpdeskWebsiteWindow = { readonly KumikoHelpdesk?: HelpdeskWebsiteClient };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { HELPDESK_CLIENT_SOURCE } from "./helpdesk-client-source.ts";
|
|
2
|
+
export type {
|
|
3
|
+
HelpdeskWebsiteClient,
|
|
4
|
+
HelpdeskWebsiteFormOptions,
|
|
5
|
+
HelpdeskWebsiteKind,
|
|
6
|
+
HelpdeskWebsiteSubmitFields,
|
|
7
|
+
HelpdeskWebsiteSubmitResult,
|
|
8
|
+
HelpdeskWebsiteWindow,
|
|
9
|
+
} from "./helpdesk-website-client.ts";
|
|
@@ -11,24 +11,28 @@ import {
|
|
|
11
11
|
import type { PersonalSubject } from "@cosmicdrift/kumiko-types/fields";
|
|
12
12
|
import { DEFAULT_RETENTION_KEEP_FOR } from "./options.ts";
|
|
13
13
|
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
HELPDESK_KIND,
|
|
15
|
+
HELPDESK_MAX_FILES,
|
|
16
|
+
HELPDESK_REPLY_CHANNELS,
|
|
17
|
+
HELPDESK_SOURCE,
|
|
18
|
+
HELPDESK_STATUS,
|
|
19
19
|
} from "./web/constants.ts";
|
|
20
20
|
|
|
21
21
|
const KIND_OPTIONS = [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
HELPDESK_KIND.Question,
|
|
23
|
+
HELPDESK_KIND.Contact,
|
|
24
|
+
HELPDESK_KIND.Bug,
|
|
25
|
+
HELPDESK_KIND.Wish,
|
|
26
26
|
] as const;
|
|
27
|
-
const STATUS_OPTIONS = [
|
|
28
|
-
|
|
27
|
+
const STATUS_OPTIONS = [
|
|
28
|
+
HELPDESK_STATUS.Open,
|
|
29
|
+
HELPDESK_STATUS.Answered,
|
|
30
|
+
HELPDESK_STATUS.Done,
|
|
31
|
+
] as const;
|
|
32
|
+
const SOURCE_OPTIONS = [HELPDESK_SOURCE.Website, HELPDESK_SOURCE.Admin] as const;
|
|
29
33
|
const REPLY_CHANNEL_OPTIONS = [
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
HELPDESK_REPLY_CHANNELS.Email,
|
|
35
|
+
HELPDESK_REPLY_CHANNELS.EmailAndInApp,
|
|
32
36
|
] as const;
|
|
33
37
|
|
|
34
38
|
// A signed-in reporter is the data subject; an anonymous reporter has no user id, so the row
|
|
@@ -37,9 +41,9 @@ const REPORTER_SUBJECT: PersonalSubject = { of: "reporterUserId", whenAbsent: "s
|
|
|
37
41
|
|
|
38
42
|
const MAX_FILE_SIZE = "10MB";
|
|
39
43
|
|
|
40
|
-
export function
|
|
44
|
+
export function createHelpdeskRequestEntity(retentionKeepFor: string = DEFAULT_RETENTION_KEEP_FOR) {
|
|
41
45
|
return createEntity({
|
|
42
|
-
table: "
|
|
46
|
+
table: "read_helpdesk_requests",
|
|
43
47
|
description:
|
|
44
48
|
"A message from a website visitor or a signed-in user to the platform operators (question, contact request, bug report or wish), tracked through open, answered and done as SystemAdmins process it; name, email, phone, subject and message are the reporter's personal data.",
|
|
45
49
|
systemStream: true,
|
|
@@ -52,22 +56,22 @@ export function createContactRequestEntity(retentionKeepFor: string = DEFAULT_RE
|
|
|
52
56
|
filterable: true,
|
|
53
57
|
sortable: true,
|
|
54
58
|
optionTones: {
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
+
[HELPDESK_KIND.Bug]: "bad",
|
|
60
|
+
[HELPDESK_KIND.Question]: "accent",
|
|
61
|
+
[HELPDESK_KIND.Contact]: "accent",
|
|
62
|
+
[HELPDESK_KIND.Wish]: "neutral",
|
|
59
63
|
},
|
|
60
64
|
}),
|
|
61
65
|
status: createSelectField({
|
|
62
66
|
options: STATUS_OPTIONS,
|
|
63
67
|
required: true,
|
|
64
|
-
default:
|
|
68
|
+
default: HELPDESK_STATUS.Open,
|
|
65
69
|
filterable: true,
|
|
66
70
|
sortable: true,
|
|
67
71
|
optionTones: {
|
|
68
|
-
[
|
|
69
|
-
[
|
|
70
|
-
[
|
|
72
|
+
[HELPDESK_STATUS.Open]: "warn",
|
|
73
|
+
[HELPDESK_STATUS.Answered]: "accent",
|
|
74
|
+
[HELPDESK_STATUS.Done]: "ok",
|
|
71
75
|
},
|
|
72
76
|
}),
|
|
73
77
|
source: createSelectField({
|
|
@@ -105,7 +109,7 @@ export function createContactRequestEntity(retentionKeepFor: string = DEFAULT_RE
|
|
|
105
109
|
browser: createTextField({ personal: false, reason: "is_browser_summary" }),
|
|
106
110
|
locale: createTextField({ personal: false, reason: "is_ui_language_preference" }),
|
|
107
111
|
fileIds: createFilesField({
|
|
108
|
-
maxCount:
|
|
112
|
+
maxCount: HELPDESK_MAX_FILES,
|
|
109
113
|
maxSize: MAX_FILE_SIZE,
|
|
110
114
|
personal: REPORTER_SUBJECT,
|
|
111
115
|
}),
|
|
@@ -123,9 +127,9 @@ export function createContactRequestEntity(retentionKeepFor: string = DEFAULT_RE
|
|
|
123
127
|
});
|
|
124
128
|
}
|
|
125
129
|
|
|
126
|
-
export function
|
|
130
|
+
export function createHelpdeskReplyEntity(retentionKeepFor: string = DEFAULT_RETENTION_KEEP_FOR) {
|
|
127
131
|
return createEntity({
|
|
128
|
-
table: "
|
|
132
|
+
table: "read_helpdesk_replies",
|
|
129
133
|
description:
|
|
130
134
|
"A SystemAdmin's answer to a contact request, with the channels it went out on; the message is the reporter's personal data because it quotes and addresses them.",
|
|
131
135
|
systemStream: true,
|
|
@@ -146,7 +150,7 @@ export function createContactReplyEntity(retentionKeepFor: string = DEFAULT_RETE
|
|
|
146
150
|
}),
|
|
147
151
|
authorName: createTextField({ required: true, personal: false, reason: "is_admin_label" }),
|
|
148
152
|
fileIds: createFilesField({
|
|
149
|
-
maxCount:
|
|
153
|
+
maxCount: HELPDESK_MAX_FILES,
|
|
150
154
|
maxSize: MAX_FILE_SIZE,
|
|
151
155
|
personal: false,
|
|
152
156
|
reason: "is_business_data",
|
|
@@ -162,7 +166,7 @@ export function createContactReplyEntity(retentionKeepFor: string = DEFAULT_RETE
|
|
|
162
166
|
});
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
export const
|
|
166
|
-
export const
|
|
167
|
-
export const
|
|
168
|
-
export const
|
|
169
|
+
export const helpdeskRequestEntity = createHelpdeskRequestEntity();
|
|
170
|
+
export const helpdeskReplyEntity = createHelpdeskReplyEntity();
|
|
171
|
+
export const helpdeskRequestTable = buildEntityTable("helpdesk-request", helpdeskRequestEntity);
|
|
172
|
+
export const helpdeskReplyTable = buildEntityTable("helpdesk-reply", helpdeskReplyEntity);
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
EXT_USER_DATA,
|
|
6
6
|
type FeatureDefinition,
|
|
7
7
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
-
import {
|
|
8
|
+
import { HELPDESK_CLIENT_SOURCE } from "./client/helpdesk-client-source.ts";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
createHelpdeskReplyEntity,
|
|
11
|
+
createHelpdeskRequestEntity,
|
|
12
|
+
helpdeskReplyEntity,
|
|
13
|
+
helpdeskRequestEntity,
|
|
14
14
|
} from "./entity.ts";
|
|
15
15
|
import { createChallengeQuery } from "./handlers/challenge.query.ts";
|
|
16
16
|
import { createForwardRequestHandler } from "./handlers/forward-request.write.ts";
|
|
@@ -26,49 +26,51 @@ import { createRequestListQuery } from "./handlers/request-list.query.ts";
|
|
|
26
26
|
import { createSendReplyMailHandler } from "./handlers/send-reply-mail.write.ts";
|
|
27
27
|
import { createSendTestHandler } from "./handlers/send-test.write.ts";
|
|
28
28
|
import { createSubmitHandler } from "./handlers/submit.write.ts";
|
|
29
|
-
import {
|
|
29
|
+
import { createHelpdeskI18n } from "./i18n.ts";
|
|
30
30
|
import { TELEGRAM_FEATURE } from "./lib.ts";
|
|
31
31
|
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
HELPDESK_ACKNOWLEDGEMENT_VARIABLES,
|
|
33
|
+
HELPDESK_CONFIRMATION_VARIABLES,
|
|
34
|
+
HELPDESK_NEW_REQUEST_VARIABLES,
|
|
35
|
+
HELPDESK_REPLY_VARIABLES,
|
|
36
|
+
HELPDESK_TEST_VARIABLES,
|
|
37
|
+
helpdeskAcknowledgementTemplate,
|
|
38
|
+
helpdeskConfirmationTemplate,
|
|
39
|
+
helpdeskNewRequestTemplate,
|
|
40
|
+
helpdeskReplyTemplate,
|
|
41
|
+
helpdeskTestTemplate,
|
|
42
42
|
inAppTemplate,
|
|
43
43
|
telegramTemplate,
|
|
44
44
|
} from "./mail.ts";
|
|
45
45
|
import {
|
|
46
|
-
type ContactOptions,
|
|
47
46
|
DEFAULT_RETENTION_KEEP_FOR,
|
|
48
|
-
|
|
47
|
+
type HelpdeskOptions,
|
|
48
|
+
resolveHelpdeskSettings,
|
|
49
49
|
} from "./options.ts";
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
50
|
+
import { createHelpdeskScreens } from "./screens.ts";
|
|
51
|
+
import { helpdeskDeleteHook, helpdeskExportHook } from "./user-data-hooks.ts";
|
|
52
|
+
import { HELPDESK_FEATURE } from "./web/constants.ts";
|
|
53
53
|
|
|
54
54
|
const REPLY_CONTEXT_FIELDS = ["name", "email", "replyTo"];
|
|
55
55
|
|
|
56
|
-
export function
|
|
57
|
-
const settings =
|
|
56
|
+
export function createHelpdeskFeature(opts: HelpdeskOptions): FeatureDefinition {
|
|
57
|
+
const settings = resolveHelpdeskSettings(opts);
|
|
58
58
|
const telegram = opts.telegram === true;
|
|
59
59
|
const keepFor = opts.retentionKeepFor ?? DEFAULT_RETENTION_KEEP_FOR;
|
|
60
60
|
const requestEntity =
|
|
61
61
|
keepFor === DEFAULT_RETENTION_KEEP_FOR
|
|
62
|
-
?
|
|
63
|
-
:
|
|
62
|
+
? helpdeskRequestEntity
|
|
63
|
+
: createHelpdeskRequestEntity(keepFor);
|
|
64
64
|
const replyEntity =
|
|
65
|
-
keepFor === DEFAULT_RETENTION_KEEP_FOR
|
|
65
|
+
keepFor === DEFAULT_RETENTION_KEEP_FOR
|
|
66
|
+
? helpdeskReplyEntity
|
|
67
|
+
: createHelpdeskReplyEntity(keepFor);
|
|
66
68
|
|
|
67
|
-
return defineFeature(
|
|
69
|
+
return defineFeature(HELPDESK_FEATURE, (r) => {
|
|
68
70
|
r.describe(
|
|
69
|
-
"
|
|
71
|
+
"Helpdesk inbox: an anonymous browser client (GET /helpdesk/client.js) submits questions, contact requests, bug reports and wishes behind a honeypot, a minimum submit time and a single-use proof-of-work challenge; signed-in users file reports from the admin. Every request is stored platform-wide and every SystemAdmin is notified by mail, optionally also in a Telegram chat (option `telegram`, off by default); the notification names only the kind, the app and a link, never name, address, phone, subject or message, because mail and Telegram cannot be shredded. SystemAdmins reply by mail (Reply-To set, attachments, quoting the original) and mark requests done; a website sender gets a fixed acknowledgement, a signed-in reporter a copy and an in-app note. Personal data is crypto-shredding-ready and the EXT_USER_DATA hooks export and erase a user's requests.",
|
|
70
72
|
);
|
|
71
|
-
r.uiHints({ displayLabel: "
|
|
73
|
+
r.uiHints({ displayLabel: "Helpdesk", category: "communication", recommended: false });
|
|
72
74
|
r.systemScope();
|
|
73
75
|
r.requires({ features: ["config", "delivery", "user-data-rights", "files", "notes-history"] });
|
|
74
76
|
// The feature manifest and reference are built from one mounted instance, so the off
|
|
@@ -76,7 +78,7 @@ export function createContactFeature(opts: ContactOptions): FeatureDefinition {
|
|
|
76
78
|
if (telegram) r.requires({ features: [TELEGRAM_FEATURE] });
|
|
77
79
|
else r.optionalRequires(TELEGRAM_FEATURE);
|
|
78
80
|
r.adoptsBundledLists();
|
|
79
|
-
r.translations({ keys:
|
|
81
|
+
r.translations({ keys: createHelpdeskI18n() });
|
|
80
82
|
|
|
81
83
|
r.config({
|
|
82
84
|
keys: {
|
|
@@ -102,33 +104,35 @@ export function createContactFeature(opts: ContactOptions): FeatureDefinition {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
r.notification("new-request", {
|
|
105
|
-
variables:
|
|
106
|
-
localizedTemplate:
|
|
107
|
+
variables: HELPDESK_NEW_REQUEST_VARIABLES,
|
|
108
|
+
localizedTemplate: helpdeskNewRequestTemplate,
|
|
107
109
|
...(telegram && { templates: { telegram: telegramTemplate } }),
|
|
108
110
|
});
|
|
109
111
|
r.notification("confirmation", {
|
|
110
|
-
variables:
|
|
111
|
-
localizedTemplate:
|
|
112
|
+
variables: HELPDESK_CONFIRMATION_VARIABLES,
|
|
113
|
+
localizedTemplate: helpdeskConfirmationTemplate,
|
|
112
114
|
});
|
|
113
115
|
r.notification("acknowledgement", {
|
|
114
|
-
variables:
|
|
115
|
-
localizedTemplate:
|
|
116
|
+
variables: HELPDESK_ACKNOWLEDGEMENT_VARIABLES,
|
|
117
|
+
localizedTemplate: helpdeskAcknowledgementTemplate,
|
|
116
118
|
});
|
|
117
119
|
r.notification("reply", {
|
|
118
|
-
variables:
|
|
119
|
-
localizedTemplate:
|
|
120
|
+
variables: HELPDESK_REPLY_VARIABLES,
|
|
121
|
+
localizedTemplate: helpdeskReplyTemplate,
|
|
122
|
+
});
|
|
123
|
+
r.notification("reply-in-app", {
|
|
124
|
+
templates: { inApp: inAppTemplate },
|
|
120
125
|
});
|
|
121
|
-
r.notification("reply-in-app", { templates: { inApp: inAppTemplate } });
|
|
122
126
|
if (telegram) {
|
|
123
127
|
r.notification("test", {
|
|
124
|
-
variables:
|
|
125
|
-
localizedTemplate:
|
|
128
|
+
variables: HELPDESK_TEST_VARIABLES,
|
|
129
|
+
localizedTemplate: helpdeskTestTemplate,
|
|
126
130
|
templates: { telegram: telegramTemplate },
|
|
127
131
|
});
|
|
128
132
|
}
|
|
129
133
|
|
|
130
|
-
r.entity({ name: "
|
|
131
|
-
r.entity({ name: "
|
|
134
|
+
r.entity({ name: "helpdesk-request", ...requestEntity });
|
|
135
|
+
r.entity({ name: "helpdesk-reply", ...replyEntity });
|
|
132
136
|
|
|
133
137
|
r.writeHandler(createSubmitHandler(opts, settings));
|
|
134
138
|
r.writeHandler(createReportHandler(opts, settings));
|
|
@@ -147,26 +151,26 @@ export function createContactFeature(opts: ContactOptions): FeatureDefinition {
|
|
|
147
151
|
r.queryHandler(repliesQuery);
|
|
148
152
|
r.queryHandler(createRequestDeliveryQuery(opts));
|
|
149
153
|
|
|
150
|
-
for (const screen of
|
|
154
|
+
for (const screen of createHelpdeskScreens(opts, settings)) r.screen(screen);
|
|
151
155
|
|
|
152
156
|
r.httpRoute({
|
|
153
157
|
method: "GET",
|
|
154
|
-
// A literal, not
|
|
155
|
-
path: "/
|
|
158
|
+
// A literal, not HELPDESK_CLIENT_PATH: the feature-AST extractor only reads string literals.
|
|
159
|
+
path: "/helpdesk/client.js",
|
|
156
160
|
anonymous: true,
|
|
157
161
|
handler: async (c) =>
|
|
158
|
-
c.body(
|
|
162
|
+
c.body(HELPDESK_CLIENT_SOURCE, 200, {
|
|
159
163
|
"content-type": "application/javascript; charset=utf-8",
|
|
160
164
|
"cache-control": "public, max-age=300",
|
|
161
165
|
}),
|
|
162
166
|
});
|
|
163
167
|
|
|
164
|
-
r.useExtension(EXT_USER_DATA, "
|
|
165
|
-
export:
|
|
166
|
-
delete:
|
|
168
|
+
r.useExtension(EXT_USER_DATA, "helpdesk-request", {
|
|
169
|
+
export: helpdeskExportHook,
|
|
170
|
+
delete: helpdeskDeleteHook,
|
|
167
171
|
});
|
|
168
|
-
// Replies are exported nested under their request and erased with it (
|
|
169
|
-
r.useExtension(EXT_USER_DATA, "
|
|
172
|
+
// Replies are exported nested under their request and erased with it (helpdeskDeleteHook).
|
|
173
|
+
r.useExtension(EXT_USER_DATA, "helpdesk-reply", {
|
|
170
174
|
export: async () => null,
|
|
171
175
|
delete: async () => {},
|
|
172
176
|
});
|
|
@@ -28,7 +28,7 @@ const readStateResultSchema = z.object({
|
|
|
28
28
|
rows: z.array(z.object({ key: z.string(), readAt: instant.nullable() })),
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
export type
|
|
31
|
+
export type HelpdeskAttempt = z.infer<typeof attemptSchema>;
|
|
32
32
|
|
|
33
33
|
function chunked(keys: readonly string[]): readonly (readonly string[])[] {
|
|
34
34
|
const chunks: string[][] = [];
|
|
@@ -42,8 +42,8 @@ export async function loadAttemptsByKey(
|
|
|
42
42
|
ctx: Pick<HandlerContext, "dispatch">,
|
|
43
43
|
user: SessionUser,
|
|
44
44
|
keys: readonly string[],
|
|
45
|
-
): Promise<readonly
|
|
46
|
-
const rows:
|
|
45
|
+
): Promise<readonly HelpdeskAttempt[]> {
|
|
46
|
+
const rows: HelpdeskAttempt[] = [];
|
|
47
47
|
for (const chunk of chunked(keys)) {
|
|
48
48
|
const result = await ctx.dispatch.queryAs(user, DeliveryQueries.attemptsByKeys, {
|
|
49
49
|
keys: chunk,
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
import { issueChallenge } from "../challenge.ts";
|
|
4
|
-
import { CHALLENGE_RATE_LIMIT, type
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { CHALLENGE_RATE_LIMIT, type HelpdeskSettings } from "../options.ts";
|
|
5
|
+
import { HelpdeskEmptySchema } from "../payloads.ts";
|
|
6
|
+
import { HELPDESK_WEBSITE_KINDS, type HelpdeskPhoneMode } from "../web/constants.ts";
|
|
7
7
|
import { SUBMIT_ROLES } from "./access.ts";
|
|
8
8
|
|
|
9
|
-
export type
|
|
9
|
+
export type HelpdeskChallengeData = {
|
|
10
10
|
readonly challenge: string;
|
|
11
11
|
readonly bits: number;
|
|
12
|
-
readonly phone:
|
|
12
|
+
readonly phone: HelpdeskPhoneMode;
|
|
13
13
|
readonly kinds: readonly string[];
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export function createChallengeQuery(settings:
|
|
16
|
+
export function createChallengeQuery(settings: HelpdeskSettings) {
|
|
17
17
|
return defineQueryHandler({
|
|
18
18
|
name: "challenge",
|
|
19
|
-
schema:
|
|
19
|
+
schema: HelpdeskEmptySchema,
|
|
20
20
|
access: { roles: SUBMIT_ROLES, personalData: "public-intake", anySignedIn: true },
|
|
21
21
|
rateLimit: CHALLENGE_RATE_LIMIT,
|
|
22
22
|
agent: { expose: false },
|
|
23
23
|
description:
|
|
24
24
|
"Public contact form bootstrap: issues a single-use proof-of-work challenge and reports which fields the form shows (phone mode, request kinds).",
|
|
25
|
-
handler: async (_event, ctx): Promise<
|
|
25
|
+
handler: async (_event, ctx): Promise<HelpdeskChallengeData> => {
|
|
26
26
|
if (!ctx.services.redis) {
|
|
27
27
|
throw new InternalError({
|
|
28
|
-
message: "
|
|
28
|
+
message: "helpdesk:challenge requires ctx.services.redis for the challenge store",
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
const challenge = await issueChallenge(ctx.services.redis, {
|
|
@@ -37,7 +37,7 @@ export function createChallengeQuery(settings: ContactSettings) {
|
|
|
37
37
|
challenge,
|
|
38
38
|
bits: settings.proofOfWorkBits,
|
|
39
39
|
phone: settings.phone,
|
|
40
|
-
kinds:
|
|
40
|
+
kinds: HELPDESK_WEBSITE_KINDS,
|
|
41
41
|
};
|
|
42
42
|
},
|
|
43
43
|
});
|
package/packages/bundled-features/src/{contact → helpdesk}/handlers/forward-request.write.ts
RENAMED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
helpdeskDb,
|
|
5
5
|
internalAccess,
|
|
6
6
|
listSystemAdminIds,
|
|
7
7
|
platformActor,
|
|
8
8
|
requestExecutor,
|
|
9
9
|
sendBestEffort,
|
|
10
10
|
} from "../lib.ts";
|
|
11
|
-
import {
|
|
12
|
-
import type {
|
|
13
|
-
import {
|
|
11
|
+
import { helpdeskNewRequestVariables, resolveHelpdeskMailLocale } from "../mail.ts";
|
|
12
|
+
import type { HelpdeskOptions } from "../options.ts";
|
|
13
|
+
import { HelpdeskForwardRequestSchema } from "../payloads.ts";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
HELPDESK_NOTIFICATION_TYPES,
|
|
16
|
+
HELPDESK_REQUEST_ENTITY,
|
|
17
|
+
HelpdeskConfigKeys,
|
|
18
|
+
helpdeskIdempotencyKeys,
|
|
19
19
|
} from "../web/constants.ts";
|
|
20
20
|
|
|
21
21
|
const EMAIL_CHANNEL = "email";
|
|
22
22
|
|
|
23
|
-
export type
|
|
23
|
+
export type HelpdeskForwardData = {
|
|
24
24
|
readonly kind: "forwarded";
|
|
25
25
|
readonly adminCount: number;
|
|
26
26
|
readonly telegram: boolean;
|
|
@@ -28,32 +28,32 @@ export type ContactForwardData = {
|
|
|
28
28
|
|
|
29
29
|
// Runs as the platform identity so the notification, the config and the bot token secret are
|
|
30
30
|
// read in the system tenant, whoever filed the request.
|
|
31
|
-
export function createForwardRequestHandler(opts:
|
|
31
|
+
export function createForwardRequestHandler(opts: HelpdeskOptions) {
|
|
32
32
|
return defineWriteHandler<
|
|
33
33
|
"forward-request",
|
|
34
|
-
typeof
|
|
35
|
-
|
|
34
|
+
typeof HelpdeskForwardRequestSchema,
|
|
35
|
+
HelpdeskForwardData
|
|
36
36
|
>({
|
|
37
37
|
name: "forward-request",
|
|
38
|
-
schema:
|
|
38
|
+
schema: HelpdeskForwardRequestSchema,
|
|
39
39
|
access: internalAccess,
|
|
40
40
|
agent: { expose: false },
|
|
41
41
|
description:
|
|
42
42
|
"Internal: forwards a stored contact request to every SystemAdmin by mail and, when a Telegram chat is configured, to that chat. Only the platform identity can call it.",
|
|
43
43
|
handler: async (event, ctx) => {
|
|
44
|
-
const db =
|
|
44
|
+
const db = helpdeskDb(ctx);
|
|
45
45
|
const request = await requestExecutor.detail(
|
|
46
46
|
{ id: event.payload.requestId },
|
|
47
47
|
platformActor(),
|
|
48
48
|
db,
|
|
49
49
|
);
|
|
50
50
|
if (!request) {
|
|
51
|
-
return writeFailure(new NotFoundError(
|
|
51
|
+
return writeFailure(new NotFoundError(HELPDESK_REQUEST_ENTITY, event.payload.requestId));
|
|
52
52
|
}
|
|
53
53
|
const requestId = event.payload.requestId;
|
|
54
54
|
const adminLocale = opts.adminLocale;
|
|
55
55
|
const link = opts.requestLink?.(requestId);
|
|
56
|
-
const data =
|
|
56
|
+
const data = helpdeskNewRequestVariables({
|
|
57
57
|
kind: request.kind,
|
|
58
58
|
appName: opts.appName,
|
|
59
59
|
link,
|
|
@@ -63,28 +63,30 @@ export function createForwardRequestHandler(opts: ContactOptions) {
|
|
|
63
63
|
const adminIds = await listSystemAdminIds(db);
|
|
64
64
|
if (adminIds.length > 0) {
|
|
65
65
|
await sendBestEffort(ctx, "admin mail", (notify) =>
|
|
66
|
-
notify(
|
|
66
|
+
notify(HELPDESK_NOTIFICATION_TYPES.newRequest, {
|
|
67
67
|
to: adminIds,
|
|
68
68
|
channels: [EMAIL_CHANNEL],
|
|
69
69
|
data,
|
|
70
|
-
idempotencyKey:
|
|
70
|
+
idempotencyKey: helpdeskIdempotencyKeys.admins(requestId),
|
|
71
71
|
priority: "normal",
|
|
72
|
-
locale:
|
|
72
|
+
locale: resolveHelpdeskMailLocale(adminLocale),
|
|
73
73
|
}),
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const chatId = opts.telegram
|
|
77
|
+
const chatId = opts.telegram
|
|
78
|
+
? await ctx.config?.(HelpdeskConfigKeys.telegramChat)
|
|
79
|
+
: undefined;
|
|
78
80
|
const telegram = opts.telegram === true && typeof chatId === "string" && chatId.trim() !== "";
|
|
79
81
|
if (telegram) {
|
|
80
82
|
await sendBestEffort(ctx, "telegram", (notify) =>
|
|
81
|
-
notify(
|
|
83
|
+
notify(HELPDESK_NOTIFICATION_TYPES.newRequest, {
|
|
82
84
|
route: { telegram: chatId.trim() },
|
|
83
85
|
recipientId: requestId,
|
|
84
86
|
data,
|
|
85
|
-
idempotencyKey:
|
|
87
|
+
idempotencyKey: helpdeskIdempotencyKeys.telegram(requestId),
|
|
86
88
|
priority: "normal",
|
|
87
|
-
locale:
|
|
89
|
+
locale: resolveHelpdeskMailLocale(adminLocale),
|
|
88
90
|
}),
|
|
89
91
|
);
|
|
90
92
|
}
|