@cosmicdrift/kumiko-samples 0.414.0 → 0.415.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.
Files changed (84) hide show
  1. package/package.json +1 -1
  2. package/packages/bundled-features/package.json +1 -1
  3. package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +2 -3
  4. package/packages/bundled-features/src/auth-email-password/web/session.tsx +2 -1
  5. package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
  6. package/packages/bundled-features/src/billing-foundation/changes.json +24 -0
  7. package/packages/bundled-features/src/billing-foundation/checkout-core.ts +11 -0
  8. package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +8 -0
  9. package/packages/bundled-features/src/billing-foundation/events.ts +7 -5
  10. package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +2 -0
  11. package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +76 -24
  12. package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +5 -4
  13. package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +2 -0
  14. package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +2 -2
  15. package/packages/bundled-features/src/channel-whatsapp/changes.json +24 -0
  16. package/packages/bundled-features/src/channel-whatsapp/events.ts +4 -3
  17. package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +23 -2
  18. package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +27 -6
  19. package/packages/bundled-features/src/compliance-profiles/changes.json +5 -0
  20. package/packages/bundled-features/src/compliance-profiles/handlers/set-profile.write.ts +2 -0
  21. package/packages/bundled-features/src/data-retention/feature.ts +1 -0
  22. package/packages/bundled-features/src/delivery/changes.json +6 -0
  23. package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +12 -3
  24. package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
  25. package/packages/bundled-features/src/document-ingest-foundation/feature.ts +1 -0
  26. package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +3 -1
  27. package/packages/bundled-features/src/documents/changes.json +6 -0
  28. package/packages/bundled-features/src/documents/feature.ts +10 -5
  29. package/packages/bundled-features/src/form-draft/feature.ts +1 -0
  30. package/packages/bundled-features/src/helpdesk/changes.json +6 -0
  31. package/packages/bundled-features/src/helpdesk/feature.ts +1 -0
  32. package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +3 -3
  33. package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +3 -2
  34. package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +3 -2
  35. package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +3 -1
  36. package/packages/bundled-features/src/helpdesk/lib.ts +9 -4
  37. package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +4 -1
  38. package/packages/bundled-features/src/inbound-mail-foundation/changes.json +6 -0
  39. package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +11 -4
  40. package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +18 -9
  41. package/packages/bundled-features/src/inbound-mail-foundation/events.ts +18 -9
  42. package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +2 -1
  43. package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +6 -0
  44. package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts +18 -5
  45. package/packages/bundled-features/src/inbound-mail-foundation/normalize-inbound-message.ts +22 -8
  46. package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +2 -5
  47. package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +11 -5
  48. package/packages/bundled-features/src/shared/changes.json +6 -0
  49. package/packages/bundled-features/src/shared/hmac-signature.ts +4 -2
  50. package/packages/bundled-features/src/shared/index.ts +2 -1
  51. package/packages/bundled-features/src/shared/normalize-email.ts +3 -0
  52. package/packages/bundled-features/src/shared/send-best-effort.ts +16 -6
  53. package/packages/bundled-features/src/step-dispatcher/changes.json +6 -0
  54. package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +5 -2
  55. package/packages/bundled-features/src/step-dispatcher/feature.ts +14 -0
  56. package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +4 -0
  57. package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +2 -0
  58. package/packages/bundled-features/src/subscription-paddle/changes.json +6 -0
  59. package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +23 -2
  60. package/packages/bundled-features/src/subscription-stripe/changes.json +6 -0
  61. package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +19 -5
  62. package/packages/bundled-features/src/template-resolver/changes.json +12 -0
  63. package/packages/bundled-features/src/template-resolver/seeding.ts +37 -7
  64. package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +7 -1
  65. package/packages/bundled-features/src/tenant-inactivity/changes.json +6 -0
  66. package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +34 -16
  67. package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +6 -0
  68. package/packages/bundled-features/src/tenant-inactivity/state-store.ts +12 -1
  69. package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
  70. package/packages/bundled-features/src/tenant-lifecycle/feature.ts +1 -0
  71. package/packages/bundled-features/src/user/resolve-verified-user-email.ts +3 -3
  72. package/packages/bundled-features/src/user-data-rights/feature.ts +1 -0
  73. package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
  74. package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +2 -2
  75. package/packages/bundled-features/src/waitlist/import.ts +2 -1
  76. package/packages/bundled-features/src/waitlist/lib.ts +1 -5
  77. package/packages/bundled-features/src/waitlist/link-on-signup.ts +2 -2
  78. package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
  79. package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +4 -2
  80. package/samples/apps/admin-console/src/app/shell.tsx +1 -0
  81. package/samples/recipes/crypto-shredding-hr/README.md +11 -0
  82. package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
  83. package/samples/recipes/record-detail-layout/src/feature.ts +36 -5
  84. package/samples/recipes/record-detail-layout/src/order-board.ts +10 -2
@@ -7,9 +7,12 @@ import {
7
7
  type WhatsappStatusKind,
8
8
  } from "./constants.ts";
9
9
  import {
10
+ MIME_TYPE_MAX_CHARS,
11
+ PHONE_NUMBER_ID_MAX_CHARS,
10
12
  RAW_STATUS_MAX_CHARS,
11
13
  type ReceiveMessageInput,
12
14
  type RecordStatusInput,
15
+ WAMID_MAX_CHARS,
13
16
  } from "./events.ts";
14
17
 
15
18
  // Meta adds fields and message types without notice. Every nested object is `.catch(undefined)`,
@@ -46,7 +49,7 @@ const statusSchema = z.object({
46
49
  timestamp: z.string().optional(),
47
50
  recipient_id: z.string().optional(),
48
51
  errors: z
49
- .array(z.object({ code: z.number().optional() }))
52
+ .array(z.object({ code: z.number().int().optional().catch(undefined) }))
50
53
  .optional()
51
54
  .catch(undefined),
52
55
  });
@@ -75,10 +78,14 @@ const webhookSchema = z.object({
75
78
  export type NormalizedWebhook = {
76
79
  readonly messages: readonly ReceiveMessageInput[];
77
80
  readonly statuses: readonly RecordStatusInput[];
78
- // Entries that carried no usable id, sender or phone number id; nothing a redelivery could fix.
81
+ // Entries that carried no usable id, sender or phone number id, or an id longer than the event
82
+ // schema allows; nothing a redelivery could fix.
79
83
  readonly skipped: number;
80
84
  };
81
85
 
86
+ // Temporal.Instant throws beyond 8.64e15 epoch milliseconds.
87
+ const MAX_EPOCH_SECONDS = 8.64e12;
88
+
82
89
  const DIGITS_PATTERN = /^\d{5,20}$/;
83
90
 
84
91
  function toE164(raw: string): string | null {
@@ -88,7 +95,10 @@ function toE164(raw: string): string | null {
88
95
 
89
96
  function toIso(unixSeconds: string | undefined, fallbackIso: string): string {
90
97
  const seconds = Number(unixSeconds);
91
- return unixSeconds !== undefined && Number.isFinite(seconds) && seconds > 0
98
+ return unixSeconds !== undefined &&
99
+ Number.isFinite(seconds) &&
100
+ seconds > 0 &&
101
+ seconds <= MAX_EPOCH_SECONDS
92
102
  ? Temporal.Instant.fromEpochMilliseconds(Math.floor(seconds) * 1000).toString()
93
103
  : fallbackIso;
94
104
  }
@@ -108,6 +118,11 @@ function optionalClip(value: string | undefined, maxChars: number): string | nul
108
118
  return value === undefined ? null : clip(value, maxChars);
109
119
  }
110
120
 
121
+ // A truncated id would point at another object, so an oversized one is dropped, not clipped.
122
+ function optionalId(value: string | undefined): string | null {
123
+ return value === undefined || value.length > WAMID_MAX_CHARS ? null : value;
124
+ }
125
+
111
126
  function buttonContentOf(message: MetaMessage): MessageContent | null {
112
127
  const reply = message.interactive?.button_reply;
113
128
  if (message.type === "interactive" && reply) {
@@ -137,8 +152,8 @@ function mediaContentOf(message: MetaMessage): MessageContent | null {
137
152
  return {
138
153
  ...NO_CONTENT,
139
154
  messageType: message.type,
140
- mediaId: media.id ?? null,
141
- mimeType: media.mime_type ?? null,
155
+ mediaId: optionalId(media.id),
156
+ mimeType: optionalClip(media.mime_type, MIME_TYPE_MAX_CHARS),
142
157
  };
143
158
  }
144
159
 
@@ -163,6 +178,9 @@ function normalizeMessage(
163
178
  const parsed = messageSchema.safeParse(raw);
164
179
  if (!parsed.success) return null;
165
180
  const message = parsed.data;
181
+ if (message.id.length > WAMID_MAX_CHARS || phoneNumberId.length > PHONE_NUMBER_ID_MAX_CHARS) {
182
+ return null;
183
+ }
166
184
  const from = toE164(message.from);
167
185
  if (from === null) return null;
168
186
  return {
@@ -170,7 +188,7 @@ function normalizeMessage(
170
188
  wamid: message.id,
171
189
  from,
172
190
  timestampIso: toIso(message.timestamp, nowIso),
173
- contextWamid: message.context?.id ?? null,
191
+ contextWamid: optionalId(message.context?.id),
174
192
  ...contentOf(message),
175
193
  };
176
194
  }
@@ -187,6 +205,9 @@ function normalizeStatus(
187
205
  const parsed = statusSchema.safeParse(raw);
188
206
  if (!parsed.success) return null;
189
207
  const status: MetaStatus = parsed.data;
208
+ if (status.id.length > WAMID_MAX_CHARS || phoneNumberId.length > PHONE_NUMBER_ID_MAX_CHARS) {
209
+ return null;
210
+ }
190
211
  const recipient = toE164(status.recipient_id ?? "");
191
212
  if (recipient === null) return null;
192
213
  return {
@@ -1,4 +1,9 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "Changing the compliance profile needs a high-risk agent call"
6
+ },
2
7
  {
3
8
  "version": "0.208.2",
4
9
  "type": "improvement",
@@ -46,6 +46,8 @@ export const setProfileWrite = defineWriteHandler({
46
46
  // SystemAdmin can set profiles for customer setup through the platform-
47
47
  // operator path; TenantAdmin can set them only for their own tenant.
48
48
  access: { roles: access.admin },
49
+ // The profile picks the retention preset, so a change can shorten how long data is kept before the purge.
50
+ agent: { risk: "high" },
49
51
  description:
50
52
  "Sets or replaces a tenant's compliance profile key plus an optional JSON override, for onboarding or a later region change; a system admin may target a different tenant through tenantIdOverride.",
51
53
  handler: async (event, ctx) => {
@@ -73,6 +73,7 @@ export function createDataRetentionFeature(): FeatureDefinition {
73
73
  r.job({
74
74
  name: "retention-cleanup",
75
75
  trigger: { maintenance: true },
76
+ irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
76
77
  perTenant: true,
77
78
  includeSystemTenant: true,
78
79
  concurrency: "skip",
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "opted-in-user-ids refuses the wildcard type and resolves former names",
6
+ "detail": "A notificationType of \"*\" is rejected by the schema so wildcard rows never count as opt-in, and a former notification name resolves to the current type instead of returning an empty list."
7
+ },
2
8
  {
3
9
  "version": "0.414.0",
4
10
  "type": "improvement",
@@ -3,13 +3,21 @@ import { defineQueryHandler, SYSTEM_ROLE } from "@cosmicdrift/kumiko-framework/e
3
3
  import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
4
4
  import * as z from "zod";
5
5
  import { tenantMembershipsTable } from "../../tenant/index.ts";
6
- import { notificationTypeNames } from "../notification-type-aliases.ts";
6
+ import { currentNotificationType, notificationTypeNames } from "../notification-type-aliases.ts";
7
7
  import { collapsePreferenceRows } from "../preference-rows.ts";
8
8
  import { notificationPreferencesTable } from "../tables.ts";
9
9
 
10
10
  export const optedInUserIdsQuery = defineQueryHandler({
11
11
  name: "opted-in-user-ids",
12
- schema: z.object({ notificationType: z.string().min(1), channel: z.string().min(1) }).strict(),
12
+ schema: z
13
+ .object({
14
+ notificationType: z
15
+ .string()
16
+ .min(1)
17
+ .refine((type) => type !== "*", { message: "a wildcard is not a notification type" }),
18
+ channel: z.string().min(1),
19
+ })
20
+ .strict(),
13
21
  access: { roles: [SYSTEM_ROLE] },
14
22
  agent: { expose: false },
15
23
  description:
@@ -21,7 +29,8 @@ export const optedInUserIdsQuery = defineQueryHandler({
21
29
  });
22
30
  }
23
31
  const db = ctx.systemDb.assertTenantMatch(query.user.tenantId);
24
- const { notificationType, channel } = query.payload;
32
+ const { channel } = query.payload;
33
+ const notificationType = currentNotificationType(ctx.registry, query.payload.notificationType);
25
34
 
26
35
  const rows = await selectMany(db, notificationPreferencesTable, {
27
36
  tenantId: query.user.tenantId,
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "Parallel ingest progress reports no longer fail after the retry budget",
6
+ "detail": "A version conflict after the last attempt means a newer report already landed, so reportIngestProgress returns instead of throwing into the ingest run."
7
+ },
2
8
  {
3
9
  "version": "0.409.0",
4
10
  "type": "improvement",
@@ -272,6 +272,7 @@ export function createDocumentIngestFoundationFeature() {
272
272
  // extracted text has no reason to survive it either.
273
273
  r.multiStreamProjection({
274
274
  name: "forget-extract-with-file-ref",
275
+ irreversibleWithoutEntryHandler: "rebuildable-derived-data",
275
276
  apply: {
276
277
  [FILE_REF_DELETED]: forgetExtractOnFileRefDeletedHook,
277
278
  [FILE_REF_FORGOTTEN]: forgetExtractOnFileRefForgottenHook,
@@ -55,7 +55,9 @@ export async function reportIngestProgress(
55
55
  // skip: event appended, nothing left to retry
56
56
  return;
57
57
  } catch (e) {
58
- if (!(e instanceof VersionConflictError) || attempt >= MAX_VERSION_CONFLICT_ATTEMPTS) throw e;
58
+ if (!(e instanceof VersionConflictError)) throw e;
59
+ // skip: a conflict after the last attempt means a newer report already landed
60
+ if (attempt >= MAX_VERSION_CONFLICT_ATTEMPTS) return;
59
61
  }
60
62
  }
61
63
  }
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "Split access without write no longer lets members file invisible documents",
6
+ "detail": "With `access: { read, delete }` and no `write`, create fell back to TenantAdmin and TenantMember, so a member could file a document they could never see. Create now stays limited to the admin roles unless a write rule is set."
7
+ },
2
8
  {
3
9
  "version": "0.414.0",
4
10
  "type": "improvement",
@@ -64,8 +64,8 @@ export type DocumentsFeatureOptions = {
64
64
  /**
65
65
  * Who may use the document handlers. One rule applies to read, write and delete; the split form
66
66
  * sets them apart. Default TenantAdmin and TenantMember; a missing delete follows write. Without
67
- * this option, creating a document is limited to the admin roles, since an unlinked document is
68
- * visible to them only.
67
+ * a write rule (no option, or a split form without `write`), creating a document is limited to
68
+ * the admin roles, since an unlinked document is visible to them only.
69
69
  */
70
70
  readonly access?: AccessRule | DocumentsAccess;
71
71
  /** Roles that see every document of their tenant whose file owner they can read, without a link. */
@@ -88,6 +88,10 @@ function isAccessRule(access: AccessRule | DocumentsAccess): access is AccessRul
88
88
  return "roles" in access || "openToAll" in access;
89
89
  }
90
90
 
91
+ function hasNoExplicitWrite(access: AccessRule | DocumentsAccess | undefined): boolean {
92
+ return access === undefined || (!isAccessRule(access) && access.write === undefined);
93
+ }
94
+
91
95
  function resolveAccess(access: AccessRule | DocumentsAccess | undefined): ResolvedDocumentsAccess {
92
96
  if (access === undefined) {
93
97
  return {
@@ -128,9 +132,10 @@ function registerDocuments(
128
132
  });
129
133
  const linkEntity = createDocumentLinkEntity(linkTargets);
130
134
  // A fresh document is invisible until linked, except to the admin roles; with the default access
131
- // a member would file a record they can never see again. An explicit access option stays in charge.
132
- const createAccess: AccessRule =
133
- opts.access === undefined ? { roles: opts.adminRoles ?? DEFAULT_ADMIN_ROLES } : access.write;
135
+ // a member would file a record they can never see again. An explicit write rule stays in charge.
136
+ const createAccess: AccessRule = hasNoExplicitWrite(opts.access)
137
+ ? { roles: opts.adminRoles ?? DEFAULT_ADMIN_ROLES }
138
+ : access.write;
134
139
  const executors = createDocumentExecutors(documentEntity, linkEntity);
135
140
 
136
141
  r.requires({ features: ["files"] });
@@ -44,6 +44,7 @@ function registerFormDraft(r: FeatureRegistrar<typeof FORM_DRAFT_FEATURE_NAME>):
44
44
  r.job({
45
45
  name: "cleanup",
46
46
  trigger: { maintenance: true },
47
+ irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
47
48
  concurrency: "skip",
48
49
  escapeHatch: { reason: CLEANUP_ESCAPE_HATCH_REASON },
49
50
  handler: (payload, ctx) =>
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "Helpdesk forwards requests and replies without ctx.notify",
6
+ "detail": "Forwarding a request, the reply mail dispatch and the in-app note are plain dispatches and now run through runBestEffort instead of the notify-gated sendBestEffort, so they no longer get skipped when the delivery feature is not mounted. The legacy contact subject lookup checks the archive first and decrypts an email only for anonymous requests."
7
+ },
2
8
  {
3
9
  "version": "0.414.0",
4
10
  "type": "fix",
@@ -207,6 +207,7 @@ export function createHelpdeskFeature(opts: HelpdeskOptions): FeatureDefinition
207
207
  r.job({
208
208
  name: "legacy-contact-retention",
209
209
  trigger: { maintenance: true },
210
+ irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
210
211
  concurrency: "skip",
211
212
  handler: async (_payload, ctx) => runLegacyContactRetention(keepFor, ctx),
212
213
  });
@@ -14,7 +14,7 @@ import {
14
14
  platformActor,
15
15
  replyExecutor,
16
16
  requestExecutor,
17
- sendBestEffort,
17
+ runBestEffort,
18
18
  } from "../lib.ts";
19
19
  import { HelpdeskReplySchema } from "../payloads.ts";
20
20
  import {
@@ -50,7 +50,7 @@ async function noteReporterInApp(ctx: HandlerContext, args: InAppNoteArgs): Prom
50
50
  const tenantId = parseTenantId(request.reporterTenantId);
51
51
  // skip: the in-app note needs a signed-in reporter whose tenant id is still valid
52
52
  if (!request.reporterUserId || tenantId === null) return;
53
- await sendBestEffort(ctx, "reply in-app note", async () => {
53
+ await runBestEffort(ctx, "reply in-app note", async () => {
54
54
  const noted = await ctx.dispatch.writeAs(
55
55
  createSystemUser(tenantId),
56
56
  HelpdeskHandlers.notifyReporterInApp,
@@ -173,7 +173,7 @@ export function createReplyHandler() {
173
173
  });
174
174
  if (failed !== null) return failed;
175
175
 
176
- await sendBestEffort(ctx, "reply mail", async () => {
176
+ await runBestEffort(ctx, "reply mail", async () => {
177
177
  const sent = await ctx.dispatch.writeAs(platformActor(), HelpdeskHandlers.sendReplyMail, {
178
178
  replyId,
179
179
  });
@@ -2,16 +2,17 @@ import { requestContext } from "@cosmicdrift/kumiko-framework/api";
2
2
  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
+ import { normalizeEmail } from "../../shared/index.ts";
5
6
  import {
6
7
  forwardHelpdeskRequest,
7
8
  helpdeskDb,
8
9
  loadTenantName,
9
10
  loadTenantPlan,
10
11
  loadUserLabel,
11
- normalizeEmail,
12
12
  phoneProblem,
13
13
  platformActor,
14
14
  requestExecutor,
15
+ runBestEffort,
15
16
  sendBestEffort,
16
17
  } from "../lib.ts";
17
18
  import { helpdeskConfirmationVariables, resolveHelpdeskMailLocale } from "../mail.ts";
@@ -96,7 +97,7 @@ export function createReportHandler(opts: HelpdeskOptions, settings: HelpdeskSet
96
97
  );
97
98
  if (!created.isSuccess) return created;
98
99
 
99
- await sendBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
100
+ await runBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
100
101
 
101
102
  await sendBestEffort(ctx, "confirmation mail", (notify) =>
102
103
  notify(HELPDESK_NOTIFICATION_TYPES.confirmation, {
@@ -14,14 +14,15 @@ import {
14
14
  import { normalizePayloadBucketValue } from "@cosmicdrift/kumiko-framework/pipeline";
15
15
  import { generateId } from "@cosmicdrift/kumiko-framework/utils";
16
16
  import type { PayloadRateLimitOption } from "@cosmicdrift/kumiko-types/handlers";
17
+ import { normalizeEmail } from "../../shared/index.ts";
17
18
  import { consumeChallenge } from "../challenge.ts";
18
19
  import {
19
20
  forwardHelpdeskRequest,
20
21
  helpdeskDb,
21
- normalizeEmail,
22
22
  phoneProblem,
23
23
  platformActor,
24
24
  requestExecutor,
25
+ runBestEffort,
25
26
  sendBestEffort,
26
27
  } from "../lib.ts";
27
28
  import { helpdeskAcknowledgementVariables, resolveHelpdeskMailLocale } from "../mail.ts";
@@ -165,7 +166,7 @@ export function createSubmitHandler(opts: HelpdeskOptions, settings: HelpdeskSet
165
166
  );
166
167
  if (!created.isSuccess) return created;
167
168
 
168
- await sendBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
169
+ await runBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
169
170
 
170
171
  await sendBestEffort(ctx, "confirmation mail", (notify) =>
171
172
  notify(HELPDESK_NOTIFICATION_TYPES.acknowledgement, {
@@ -139,8 +139,8 @@ export async function findLegacyRequestsOfSubject(
139
139
  const runner = systemTenantReadRunner(db);
140
140
  const matches: LegacyAggregate[] = [];
141
141
  for (const [id, raw] of await foldLegacyStreams(runner, LEGACY_CONTACT_REQUEST_ENTITY)) {
142
- if (!(await isSubjectRequest(raw, subject))) continue;
143
142
  if (await isStreamArchived(runner, SYSTEM_TENANT_ID, id)) continue;
143
+ if (!(await isSubjectRequest(raw, subject))) continue;
144
144
  const fields = await readableFields(LEGACY_CONTACT_REQUEST_ENTITY, raw);
145
145
  matches.push({
146
146
  id,
@@ -157,6 +157,8 @@ async function isSubjectRequest(
157
157
  ): Promise<boolean> {
158
158
  if (raw["reporterUserId"] === subject.userId) return true;
159
159
  if (subject.email === undefined) return false;
160
+ // Only anonymous requests can match by email; another signed-in reporter needs no decryption.
161
+ if (typeof raw["reporterUserId"] === "string" && raw["reporterUserId"] !== "") return false;
160
162
  const { email } = await readableFields(LEGACY_CONTACT_REQUEST_ENTITY, { email: raw["email"] }, [
161
163
  "email",
162
164
  ]);
@@ -17,6 +17,7 @@ import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
17
17
  import {
18
18
  acknowledgedSystemDb,
19
19
  decryptStoredPii,
20
+ runBestEffort as runSharedBestEffort,
20
21
  sendBestEffort as sendSharedBestEffort,
21
22
  } from "../shared/index.ts";
22
23
  import { tenantTable } from "../tenant/index.ts";
@@ -89,10 +90,6 @@ export function listRepliesOf(db: TenantDb, requestId: string) {
89
90
  );
90
91
  }
91
92
 
92
- export function normalizeEmail(email: string): string {
93
- return email.toLowerCase();
94
- }
95
-
96
93
  export function helpdeskDb(ctx: Pick<AppContext, "systemDb">): TenantDb {
97
94
  return acknowledgedSystemDb(ctx, "helpdesk", HELPDESK_CROSS_TENANT_REASON);
98
95
  }
@@ -132,6 +129,14 @@ export async function sendBestEffort(
132
129
  return sendSharedBestEffort(ctx, `[helpdesk] ${label} failed`, send);
133
130
  }
134
131
 
132
+ export async function runBestEffort(
133
+ ctx: Pick<HandlerContext, "obs">,
134
+ label: string,
135
+ run: () => Promise<unknown>,
136
+ ): Promise<void> {
137
+ return runSharedBestEffort(ctx, `[helpdesk] ${label} failed`, run);
138
+ }
139
+
135
140
  export async function forwardHelpdeskRequest(
136
141
  ctx: Pick<HandlerContext, "dispatch">,
137
142
  requestId: string,
@@ -1,7 +1,7 @@
1
1
  import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
2
2
  import { selectMany } from "@cosmicdrift/kumiko-framework/db";
3
3
  import type { AccountHealth, PollFailureKind } from "./account-health.ts";
4
- import { refetchSnippetOnlyMessages } from "./content-refetch.ts";
4
+ import { refetchSnippetOnlyMessages, type ScanResumePoints } from "./content-refetch.ts";
5
5
  import { describeError } from "./describe-error.ts";
6
6
  import { seenMessageTable } from "./entities.ts";
7
7
  import {
@@ -63,6 +63,8 @@ export function createAccountPoller(deps: AccountPollerDeps): {
63
63
  log,
64
64
  } = deps;
65
65
 
66
+ const scanResumePoint: ScanResumePoints = new Map();
67
+
66
68
  function unknownMessageIdsFilterFor(account: MailAccountRecord) {
67
69
  return async (providerMessageIds: readonly string[]): Promise<ReadonlySet<string>> => {
68
70
  if (providerMessageIds.length === 0) return new Set();
@@ -111,6 +113,7 @@ export function createAccountPoller(deps: AccountPollerDeps): {
111
113
  const accessToken = await resolveAccessToken(account, plugin);
112
114
  await refetchSnippetOnlyMessages({
113
115
  db: systemDb,
116
+ scanResumePoint,
114
117
  dispatchWrite: deps.dispatchWrite,
115
118
  providerCtx,
116
119
  account,
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.415.0",
4
+ "type": "fix",
5
+ "title": "to/cc lists fit the ciphertext limit, forget-message needs file storage",
6
+ "detail": "normalizeRawInboundMessage drops addresses from the end of to/cc until the serialized list fits INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, and ingestMessageSchema rejects longer lists, so a mail to a large distribution list no longer fails the event append. Entity and event limits derive from shared constants. forget-message fails before archiving when a stored original exists but no file storage is configured. The content-refetch scan marker belongs to one poller instead of the module."
7
+ },
2
8
  {
3
9
  "version": "0.414.0",
4
10
  "type": "fix",
@@ -20,9 +20,9 @@ const SEEN_MAX_PAGES = 4;
20
20
  export const CONTENT_REFETCH_SCAN_ROWS_PER_TICK = SEEN_PAGE_SIZE * SEEN_MAX_PAGES;
21
21
 
22
22
  // Where the previous tick stopped scanning, per account. Without it every tick re-reads the newest
23
- // rows and snippet-only mails further back would never be reached. Lost on restart, which only
24
- // means the scan starts at the newest mail again.
25
- const scanResumePoint = new Map<string, Temporal.Instant>();
23
+ // rows and snippet-only mails further back would never be reached. Owned by one poller, so stacks
24
+ // never share it; lost on restart, which only means the scan starts at the newest mail again.
25
+ export type ScanResumePoints = Map<string, Temporal.Instant>;
26
26
 
27
27
  type SeenRow = { readonly providerMessageId: string; readonly seenAt: Temporal.Instant };
28
28
  type MessageRow = {
@@ -38,6 +38,7 @@ function needsContent(row: MessageRow): boolean {
38
38
 
39
39
  async function findSnippetOnlyMessageIds(
40
40
  db: DbConnection,
41
+ scanResumePoint: ScanResumePoints,
41
42
  account: MailAccountRecord,
42
43
  windowDays: number,
43
44
  ): Promise<string[]> {
@@ -97,6 +98,7 @@ async function findSnippetOnlyMessageIds(
97
98
 
98
99
  export async function refetchSnippetOnlyMessages(args: {
99
100
  readonly db: DbConnection;
101
+ readonly scanResumePoint: ScanResumePoints;
100
102
  readonly dispatchWrite: DispatchWrite;
101
103
  readonly providerCtx: InboundMailContext;
102
104
  readonly account: MailAccountRecord;
@@ -108,7 +110,12 @@ export async function refetchSnippetOnlyMessages(args: {
108
110
  const { account, plugin, dispatchWrite } = args;
109
111
  // skip: the provider cannot reload content.
110
112
  if (!plugin.fetchContent) return;
111
- const ids = await findSnippetOnlyMessageIds(args.db, account, args.windowDays);
113
+ const ids = await findSnippetOnlyMessageIds(
114
+ args.db,
115
+ args.scanResumePoint,
116
+ account,
117
+ args.windowDays,
118
+ );
112
119
  // skip: no snippet-only mail to reload.
113
120
  if (ids.length === 0) return;
114
121
  const result = await plugin.fetchContent(
@@ -19,6 +19,15 @@ import {
19
19
  } from "@cosmicdrift/kumiko-framework/engine";
20
20
  import type { OwnershipMap, OwnershipRule } from "@cosmicdrift/kumiko-types/ownership";
21
21
  import { DEFAULT_INBOUND_MAIL_ADMIN_ROLES, DEFAULT_INBOUND_MAIL_USER_ROLES } from "./mail-roles.ts";
22
+ import {
23
+ INBOUND_ADDRESS_LIST_JSON_MAX_CHARS,
24
+ INBOUND_BODY_HTML_MAX_BYTES,
25
+ INBOUND_BODY_TEXT_MAX_CHARS,
26
+ INBOUND_FROM_MAX_CHARS,
27
+ INBOUND_MAIL_ADDRESS_MAX_CHARS,
28
+ INBOUND_SNIPPET_MAX_CHARS,
29
+ INBOUND_SUBJECT_MAX_CHARS,
30
+ } from "./normalize-inbound-message.ts";
22
31
 
23
32
  // ============================================================================
24
33
  // Read models for the three event-sourced aggregates
@@ -71,7 +80,7 @@ export const mailAccountEntity = createEntity({
71
80
  // Mailbox address — tenant PII.
72
81
  address: createTextField({
73
82
  required: true,
74
- maxLength: piiCiphertextMaxLengthFor(320),
83
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_MAIL_ADDRESS_MAX_CHARS),
75
84
  personal: "tenant",
76
85
  find: "none",
77
86
  }),
@@ -145,28 +154,28 @@ export function createInboundMessageEntity(memberRoles: readonly string[]) {
145
154
  }),
146
155
  from: createTextField({
147
156
  required: true,
148
- maxLength: piiCiphertextMaxLengthFor(2000),
157
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_FROM_MAX_CHARS),
149
158
  personal: "tenant",
150
159
  find: "none",
151
160
  }),
152
161
  // JSON-stringified string[] — als Ganzes encrypted.
153
162
  to: createTextField({
154
- maxLength: piiCiphertextMaxLengthFor(8000),
163
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS),
155
164
  personal: "tenant",
156
165
  find: "none",
157
166
  }),
158
167
  cc: createTextField({
159
- maxLength: piiCiphertextMaxLengthFor(8000),
168
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS),
160
169
  personal: "tenant",
161
170
  find: "none",
162
171
  }),
163
172
  subject: createTextField({
164
- maxLength: piiCiphertextMaxLengthFor(4000),
173
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS),
165
174
  personal: "tenant",
166
175
  find: "none",
167
176
  }),
168
177
  snippet: createTextField({
169
- maxLength: piiCiphertextMaxLengthFor(4000),
178
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SNIPPET_MAX_CHARS),
170
179
  personal: "tenant",
171
180
  find: "none",
172
181
  }),
@@ -176,7 +185,7 @@ export function createInboundMessageEntity(memberRoles: readonly string[]) {
176
185
  // Null on rows from before the column; list-messages never selects it.
177
186
  // Plaintext is clipped to INBOUND_BODY_TEXT_MAX_CHARS (32_000) before encryption.
178
187
  bodyText: createLongTextField({
179
- maxLength: piiCiphertextMaxLengthFor(32_000),
188
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_BODY_TEXT_MAX_CHARS),
180
189
  personal: "tenant",
181
190
  find: "none",
182
191
  }),
@@ -184,7 +193,7 @@ export function createInboundMessageEntity(memberRoles: readonly string[]) {
184
193
  // Sanitized HTML of the mail, null when the mail has none or it was too large: sanitizeInboundHtml
185
194
  // drops anything over 500_000 bytes after sanitizing, before encryption.
186
195
  bodyHtml: createLongTextField({
187
- maxLength: piiCiphertextMaxLengthFor(500_000),
196
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_BODY_HTML_MAX_BYTES),
188
197
  personal: "tenant",
189
198
  find: "none",
190
199
  }),
@@ -239,7 +248,7 @@ export const mailThreadEntity = createEntity({
239
248
  reason: "technical_reference",
240
249
  }),
241
250
  subject: createTextField({
242
- maxLength: piiCiphertextMaxLengthFor(4000),
251
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS),
243
252
  personal: "tenant",
244
253
  find: "none",
245
254
  }),