@cosmicdrift/kumiko-bundled-features 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 (95) hide show
  1. package/dist/auth-email-password/signup-token-store.d.ts +2 -2
  2. package/dist/auth-email-password/signup-token-store.js +2 -4
  3. package/dist/auth-email-password/web/session.js +2 -1
  4. package/dist/billing-foundation/checkout-core.d.ts +2 -0
  5. package/dist/billing-foundation/checkout-core.js +9 -0
  6. package/dist/billing-foundation/checkout-ledger.d.ts +7 -0
  7. package/dist/billing-foundation/checkout-ledger.js +6 -0
  8. package/dist/billing-foundation/events.d.ts +1 -0
  9. package/dist/billing-foundation/events.js +6 -5
  10. package/dist/billing-foundation/handlers/create-checkout-session.write.js +2 -1
  11. package/dist/billing-foundation/handlers/process-event.write.d.ts +3 -1
  12. package/dist/billing-foundation/handlers/process-event.write.js +57 -32
  13. package/dist/billing-foundation/handlers/process-payment-event.write.js +5 -5
  14. package/dist/billing-foundation/handlers/start-plan-checkout.write.js +2 -1
  15. package/dist/billing-foundation/webhook-handler.js +2 -2
  16. package/dist/channel-whatsapp/events.d.ts +3 -0
  17. package/dist/channel-whatsapp/events.js +4 -3
  18. package/dist/channel-whatsapp/inbound-handlers.js +24 -3
  19. package/dist/channel-whatsapp/webhook-normalize.js +21 -6
  20. package/dist/compliance-profiles/handlers/set-profile.write.js +2 -0
  21. package/dist/data-retention/feature.js +1 -0
  22. package/dist/delivery/handlers/opted-in-user-ids.query.js +12 -3
  23. package/dist/document-ingest-foundation/feature.js +1 -0
  24. package/dist/document-ingest-foundation/report-ingest-progress.js +4 -1
  25. package/dist/documents/feature.d.ts +2 -2
  26. package/dist/documents/feature.js +7 -2
  27. package/dist/form-draft/feature.js +1 -0
  28. package/dist/helpdesk/feature.js +1 -0
  29. package/dist/helpdesk/handlers/reply.write.js +3 -3
  30. package/dist/helpdesk/handlers/report.write.js +3 -2
  31. package/dist/helpdesk/handlers/submit.write.js +3 -2
  32. package/dist/helpdesk/legacy-contact-streams.js +5 -2
  33. package/dist/helpdesk/lib.d.ts +1 -1
  34. package/dist/helpdesk/lib.js +4 -4
  35. package/dist/inbound-mail-foundation/account-poll.js +2 -0
  36. package/dist/inbound-mail-foundation/content-refetch.d.ts +3 -0
  37. package/dist/inbound-mail-foundation/content-refetch.js +2 -6
  38. package/dist/inbound-mail-foundation/entities.js +10 -9
  39. package/dist/inbound-mail-foundation/events.js +10 -9
  40. package/dist/inbound-mail-foundation/handlers/connect-account.write.js +2 -1
  41. package/dist/inbound-mail-foundation/handlers/forget-message.write.js +4 -0
  42. package/dist/inbound-mail-foundation/handlers/ingest-message-schema.js +12 -5
  43. package/dist/inbound-mail-foundation/normalize-inbound-message.d.ts +6 -0
  44. package/dist/inbound-mail-foundation/normalize-inbound-message.js +21 -8
  45. package/dist/inbound-mail-foundation/sanitize-inbound-html.d.ts +0 -1
  46. package/dist/inbound-mail-foundation/sanitize-inbound-html.js +2 -4
  47. package/dist/managed-pages/web/page-edit-screen.js +12 -5
  48. package/dist/shared/hmac-signature.js +4 -2
  49. package/dist/shared/index.d.ts +2 -1
  50. package/dist/shared/index.js +2 -1
  51. package/dist/shared/normalize-email.d.ts +1 -0
  52. package/dist/shared/normalize-email.js +3 -0
  53. package/dist/shared/send-best-effort.d.ts +1 -0
  54. package/dist/shared/send-best-effort.js +10 -5
  55. package/dist/step-dispatcher/deliver-dispatch-request.js +5 -3
  56. package/dist/step-dispatcher/feature.js +11 -0
  57. package/dist/step-dispatcher/sweep-abandoned.d.ts +1 -0
  58. package/dist/step-dispatcher/sweep-abandoned.js +3 -0
  59. package/dist/subscription-paddle/backfill-checkout-ledger.js +2 -0
  60. package/dist/subscription-paddle/redeliver-legacy-checkout.js +19 -2
  61. package/dist/subscription-stripe/verify-webhook.js +16 -6
  62. package/dist/template-resolver/seeding.js +32 -7
  63. package/dist/template-resolver/web/web-preview-renderer.js +5 -1
  64. package/dist/tenant-inactivity/check-inactive-tenants.js +27 -16
  65. package/dist/tenant-inactivity/handlers/keep-account.write.js +7 -0
  66. package/dist/tenant-inactivity/state-store.d.ts +2 -1
  67. package/dist/tenant-inactivity/state-store.js +7 -0
  68. package/dist/tenant-lifecycle/feature.js +1 -0
  69. package/dist/user/resolve-verified-user-email.js +3 -3
  70. package/dist/user-data-rights/feature.js +1 -0
  71. package/dist/waitlist/handlers/reject.write.js +2 -1
  72. package/dist/waitlist/handlers/submit.write.js +2 -2
  73. package/dist/waitlist/import.js +2 -1
  74. package/dist/waitlist/lib.d.ts +0 -1
  75. package/dist/waitlist/lib.js +1 -4
  76. package/dist/waitlist/link-on-signup.js +2 -2
  77. package/dist/workflow-runner/handlers/resume-run.write.js +4 -3
  78. package/package.json +11 -11
  79. package/src/auth-mfa/changes.json +6 -0
  80. package/src/billing-foundation/changes.json +24 -0
  81. package/src/channel-whatsapp/changes.json +24 -0
  82. package/src/compliance-profiles/changes.json +5 -0
  83. package/src/delivery/changes.json +6 -0
  84. package/src/document-ingest-foundation/changes.json +6 -0
  85. package/src/documents/changes.json +6 -0
  86. package/src/helpdesk/changes.json +6 -0
  87. package/src/inbound-mail-foundation/changes.json +6 -0
  88. package/src/shared/changes.json +6 -0
  89. package/src/step-dispatcher/changes.json +6 -0
  90. package/src/subscription-paddle/changes.json +6 -0
  91. package/src/subscription-stripe/changes.json +6 -0
  92. package/src/template-resolver/changes.json +12 -0
  93. package/src/tenant-inactivity/changes.json +6 -0
  94. package/src/tenant-lifecycle/changes.json +6 -0
  95. package/src/workflow-runner/changes.json +6 -0
@@ -43,6 +43,7 @@ export function createDataRetentionFeature() {
43
43
  r.job({
44
44
  name: "retention-cleanup",
45
45
  trigger: { maintenance: true },
46
+ irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
46
47
  perTenant: true,
47
48
  includeSystemTenant: true,
48
49
  concurrency: "skip",
@@ -3,12 +3,20 @@ 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.js";
6
- import { notificationTypeNames } from "../notification-type-aliases.js";
6
+ import { currentNotificationType, notificationTypeNames } from "../notification-type-aliases.js";
7
7
  import { collapsePreferenceRows } from "../preference-rows.js";
8
8
  import { notificationPreferencesTable } from "../tables.js";
9
9
  export const optedInUserIdsQuery = defineQueryHandler({
10
10
  name: "opted-in-user-ids",
11
- schema: z.object({ notificationType: z.string().min(1), channel: z.string().min(1) }).strict(),
11
+ schema: z
12
+ .object({
13
+ notificationType: z
14
+ .string()
15
+ .min(1)
16
+ .refine((type) => type !== "*", { message: "a wildcard is not a notification type" }),
17
+ channel: z.string().min(1),
18
+ })
19
+ .strict(),
12
20
  access: { roles: [SYSTEM_ROLE] },
13
21
  agent: { expose: false },
14
22
  description: "Job-only: returns the ids of the calling tenant's members who explicitly switched this notification type on for exactly this channel (a preference row with enabled = true), so a job sending an opt-in notification such as a daily digest addresses only the members who ordered it.",
@@ -19,7 +27,8 @@ export const optedInUserIdsQuery = defineQueryHandler({
19
27
  });
20
28
  }
21
29
  const db = ctx.systemDb.assertTenantMatch(query.user.tenantId);
22
- const { notificationType, channel } = query.payload;
30
+ const { channel } = query.payload;
31
+ const notificationType = currentNotificationType(ctx.registry, query.payload.notificationType);
23
32
  const rows = await selectMany(db, notificationPreferencesTable, {
24
33
  tenantId: query.user.tenantId,
25
34
  channel,
@@ -205,6 +205,7 @@ export function createDocumentIngestFoundationFeature() {
205
205
  // extracted text has no reason to survive it either.
206
206
  r.multiStreamProjection({
207
207
  name: "forget-extract-with-file-ref",
208
+ irreversibleWithoutEntryHandler: "rebuildable-derived-data",
208
209
  apply: {
209
210
  [FILE_REF_DELETED]: forgetExtractOnFileRefDeletedHook,
210
211
  [FILE_REF_FORGOTTEN]: forgetExtractOnFileRefForgottenHook,
@@ -29,8 +29,11 @@ export async function reportIngestProgress(deps, input) {
29
29
  return;
30
30
  }
31
31
  catch (e) {
32
- if (!(e instanceof VersionConflictError) || attempt >= MAX_VERSION_CONFLICT_ATTEMPTS)
32
+ if (!(e instanceof VersionConflictError))
33
33
  throw e;
34
+ // skip: a conflict after the last attempt means a newer report already landed
35
+ if (attempt >= MAX_VERSION_CONFLICT_ATTEMPTS)
36
+ return;
34
37
  }
35
38
  }
36
39
  }
@@ -27,8 +27,8 @@ export type DocumentsFeatureOptions = {
27
27
  /**
28
28
  * Who may use the document handlers. One rule applies to read, write and delete; the split form
29
29
  * sets them apart. Default TenantAdmin and TenantMember; a missing delete follows write. Without
30
- * this option, creating a document is limited to the admin roles, since an unlinked document is
31
- * visible to them only.
30
+ * a write rule (no option, or a split form without `write`), creating a document is limited to
31
+ * the admin roles, since an unlinked document is visible to them only.
32
32
  */
33
33
  readonly access?: AccessRule | DocumentsAccess;
34
34
  /** Roles that see every document of their tenant whose file owner they can read, without a link. */
@@ -20,6 +20,9 @@ import { createDocumentWriteGuard } from "./write-guard.js";
20
20
  function isAccessRule(access) {
21
21
  return "roles" in access || "openToAll" in access;
22
22
  }
23
+ function hasNoExplicitWrite(access) {
24
+ return access === undefined || (!isAccessRule(access) && access.write === undefined);
25
+ }
23
26
  function resolveAccess(access) {
24
27
  if (access === undefined) {
25
28
  return {
@@ -51,8 +54,10 @@ function registerDocuments(r, opts) {
51
54
  });
52
55
  const linkEntity = createDocumentLinkEntity(linkTargets);
53
56
  // A fresh document is invisible until linked, except to the admin roles; with the default access
54
- // a member would file a record they can never see again. An explicit access option stays in charge.
55
- const createAccess = opts.access === undefined ? { roles: opts.adminRoles ?? DEFAULT_ADMIN_ROLES } : access.write;
57
+ // a member would file a record they can never see again. An explicit write rule stays in charge.
58
+ const createAccess = hasNoExplicitWrite(opts.access)
59
+ ? { roles: opts.adminRoles ?? DEFAULT_ADMIN_ROLES }
60
+ : access.write;
56
61
  const executors = createDocumentExecutors(documentEntity, linkEntity);
57
62
  r.requires({ features: ["files"] });
58
63
  r.adoptsBundledLists();
@@ -35,6 +35,7 @@ function registerFormDraft(r) {
35
35
  r.job({
36
36
  name: "cleanup",
37
37
  trigger: { maintenance: true },
38
+ irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
38
39
  concurrency: "skip",
39
40
  escapeHatch: { reason: CLEANUP_ESCAPE_HATCH_REASON },
40
41
  handler: (payload, ctx) => cleanupDraftsJob(payload, ctx, ctx.db.unsafeRaw()),
@@ -162,6 +162,7 @@ export function createHelpdeskFeature(opts) {
162
162
  r.job({
163
163
  name: "legacy-contact-retention",
164
164
  trigger: { maintenance: true },
165
+ irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
165
166
  concurrency: "skip",
166
167
  handler: async (_payload, ctx) => runLegacyContactRetention(keepFor, ctx),
167
168
  });
@@ -2,7 +2,7 @@ import { createSystemUser, defineWriteHandler, } from "@cosmicdrift/kumiko-frame
2
2
  import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
3
3
  import { generateId } from "@cosmicdrift/kumiko-framework/utils";
4
4
  import { parseTenantId } from "@cosmicdrift/kumiko-types/identifiers";
5
- import { adminAccess, helpdeskDb, loadUserLabel, pickReplyChannels, platformActor, replyExecutor, requestExecutor, sendBestEffort, } from "../lib.js";
5
+ import { adminAccess, helpdeskDb, loadUserLabel, pickReplyChannels, platformActor, replyExecutor, requestExecutor, runBestEffort, } from "../lib.js";
6
6
  import { HelpdeskReplySchema } from "../payloads.js";
7
7
  import { HELPDESK_REPLY_CHANNELS, HELPDESK_REPLY_ENTITY, HELPDESK_REQUEST_ENTITY, HELPDESK_STATUS, HelpdeskHandlers, HelpdeskScreens, } from "../web/constants.js";
8
8
  import { takeOverUploads } from "./take-over-uploads.js";
@@ -12,7 +12,7 @@ async function noteReporterInApp(ctx, args) {
12
12
  // skip: the in-app note needs a signed-in reporter whose tenant id is still valid
13
13
  if (!request.reporterUserId || tenantId === null)
14
14
  return;
15
- await sendBestEffort(ctx, "reply in-app note", async () => {
15
+ await runBestEffort(ctx, "reply in-app note", async () => {
16
16
  const noted = await ctx.dispatch.writeAs(createSystemUser(tenantId), HelpdeskHandlers.notifyReporterInApp, {
17
17
  replyId: args.replyId,
18
18
  requestId: request.id,
@@ -101,7 +101,7 @@ export function createReplyHandler() {
101
101
  });
102
102
  if (failed !== null)
103
103
  return failed;
104
- await sendBestEffort(ctx, "reply mail", async () => {
104
+ await runBestEffort(ctx, "reply mail", async () => {
105
105
  const sent = await ctx.dispatch.writeAs(platformActor(), HelpdeskHandlers.sendReplyMail, {
106
106
  replyId,
107
107
  });
@@ -2,7 +2,8 @@ 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 { forwardHelpdeskRequest, helpdeskDb, loadTenantName, loadTenantPlan, loadUserLabel, normalizeEmail, phoneProblem, platformActor, requestExecutor, sendBestEffort, } from "../lib.js";
5
+ import { normalizeEmail } from "../../shared/index.js";
6
+ import { forwardHelpdeskRequest, helpdeskDb, loadTenantName, loadTenantPlan, loadUserLabel, phoneProblem, platformActor, requestExecutor, runBestEffort, sendBestEffort, } from "../lib.js";
6
7
  import { helpdeskConfirmationVariables, resolveHelpdeskMailLocale } from "../mail.js";
7
8
  import { REPORT_RATE_LIMIT } from "../options.js";
8
9
  import { HelpdeskReportSchema } from "../payloads.js";
@@ -67,7 +68,7 @@ export function createReportHandler(opts, settings) {
67
68
  }, platformActor(), db);
68
69
  if (!created.isSuccess)
69
70
  return created;
70
- await sendBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
71
+ await runBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
71
72
  await sendBestEffort(ctx, "confirmation mail", (notify) => notify(HELPDESK_NOTIFICATION_TYPES.confirmation, {
72
73
  route: { email },
73
74
  recipientId: requestId,
@@ -3,8 +3,9 @@ import { defineWriteHandler, } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import { InternalError, isKumikoError, UnprocessableError, writeFailure, } from "@cosmicdrift/kumiko-framework/errors";
4
4
  import { normalizePayloadBucketValue } from "@cosmicdrift/kumiko-framework/pipeline";
5
5
  import { generateId } from "@cosmicdrift/kumiko-framework/utils";
6
+ import { normalizeEmail } from "../../shared/index.js";
6
7
  import { consumeChallenge } from "../challenge.js";
7
- import { forwardHelpdeskRequest, helpdeskDb, normalizeEmail, phoneProblem, platformActor, requestExecutor, sendBestEffort, } from "../lib.js";
8
+ import { forwardHelpdeskRequest, helpdeskDb, phoneProblem, platformActor, requestExecutor, runBestEffort, sendBestEffort, } from "../lib.js";
8
9
  import { helpdeskAcknowledgementVariables, resolveHelpdeskMailLocale } from "../mail.js";
9
10
  import { DEFAULT_SUBMIT_EMAIL_RATE_LIMITS, DEFAULT_SUBMIT_RATE_LIMIT, } from "../options.js";
10
11
  import { HelpdeskSubmitSchema } from "../payloads.js";
@@ -114,7 +115,7 @@ export function createSubmitHandler(opts, settings) {
114
115
  }, platformActor(), helpdeskDb(ctx));
115
116
  if (!created.isSuccess)
116
117
  return created;
117
- await sendBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
118
+ await runBestEffort(ctx, "forward request", () => forwardHelpdeskRequest(ctx, requestId));
118
119
  await sendBestEffort(ctx, "confirmation mail", (notify) => notify(HELPDESK_NOTIFICATION_TYPES.acknowledgement, {
119
120
  route: { email },
120
121
  recipientId: requestId,
@@ -84,10 +84,10 @@ export async function findLegacyRequestsOfSubject(db, subject) {
84
84
  const runner = systemTenantReadRunner(db);
85
85
  const matches = [];
86
86
  for (const [id, raw] of await foldLegacyStreams(runner, LEGACY_CONTACT_REQUEST_ENTITY)) {
87
- if (!(await isSubjectRequest(raw, subject)))
88
- continue;
89
87
  if (await isStreamArchived(runner, SYSTEM_TENANT_ID, id))
90
88
  continue;
89
+ if (!(await isSubjectRequest(raw, subject)))
90
+ continue;
91
91
  const fields = await readableFields(LEGACY_CONTACT_REQUEST_ENTITY, raw);
92
92
  matches.push({
93
93
  id,
@@ -102,6 +102,9 @@ async function isSubjectRequest(raw, subject) {
102
102
  return true;
103
103
  if (subject.email === undefined)
104
104
  return false;
105
+ // Only anonymous requests can match by email; another signed-in reporter needs no decryption.
106
+ if (typeof raw["reporterUserId"] === "string" && raw["reporterUserId"] !== "")
107
+ return false;
105
108
  const { email } = await readableFields(LEGACY_CONTACT_REQUEST_ENTITY, { email: raw["email"] }, [
106
109
  "email",
107
110
  ]);
@@ -90,7 +90,6 @@ export declare function listRepliesOf(db: TenantDb, requestId: string): Promise<
90
90
  readonly requestId: string;
91
91
  readonly sentAt: Temporal.Instant;
92
92
  }[]>;
93
- export declare function normalizeEmail(email: string): string;
94
93
  export declare function helpdeskDb(ctx: Pick<AppContext, "systemDb">): TenantDb;
95
94
  export declare function platformActor(): SessionUser;
96
95
  export declare function listSystemAdminIds(db: TenantDb): Promise<readonly string[]>;
@@ -100,6 +99,7 @@ export type UserLabel = {
100
99
  };
101
100
  export declare function loadUserLabel(db: TenantDb, userId: string): Promise<UserLabel | null>;
102
101
  export declare function sendBestEffort(ctx: Pick<HandlerContext, "notify" | "obs">, label: string, send: (notify: NonNullable<HandlerContext["notify"]>) => Promise<unknown>): Promise<void>;
102
+ export declare function runBestEffort(ctx: Pick<HandlerContext, "obs">, label: string, run: () => Promise<unknown>): Promise<void>;
103
103
  export declare function forwardHelpdeskRequest(ctx: Pick<HandlerContext, "dispatch">, requestId: string): Promise<void>;
104
104
  export declare function pickReplyChannels(ctx: Pick<HandlerContext, "hasFeature">, reporterUserId: string | null | undefined): Promise<HelpdeskReplyChannels>;
105
105
  export declare function phoneProblem(mode: HelpdeskPhoneMode, phone: string | undefined): (typeof HelpdeskErrors)[keyof typeof HelpdeskErrors] | null;
@@ -2,7 +2,7 @@ import { ROLES } from "@cosmicdrift/kumiko-framework/auth";
2
2
  import { createEventStoreExecutor, fetchOne, selectMany, } from "@cosmicdrift/kumiko-framework/db";
3
3
  import { access, createSystemUser, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
4
4
  import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
5
- import { acknowledgedSystemDb, decryptStoredPii, sendBestEffort as sendSharedBestEffort, } from "../shared/index.js";
5
+ import { acknowledgedSystemDb, decryptStoredPii, runBestEffort as runSharedBestEffort, sendBestEffort as sendSharedBestEffort, } from "../shared/index.js";
6
6
  import { tenantTable } from "../tenant/index.js";
7
7
  import { TierEngineQueries } from "../tier-engine/index.js";
8
8
  import { USER_STATUS, userTable } from "../user/index.js";
@@ -39,9 +39,6 @@ export function listRepliesOf(db, requestId) {
39
39
  ...page,
40
40
  }, platformActor(), db));
41
41
  }
42
- export function normalizeEmail(email) {
43
- return email.toLowerCase();
44
- }
45
42
  export function helpdeskDb(ctx) {
46
43
  return acknowledgedSystemDb(ctx, "helpdesk", HELPDESK_CROSS_TENANT_REASON);
47
44
  }
@@ -64,6 +61,9 @@ export async function loadUserLabel(db, userId) {
64
61
  export async function sendBestEffort(ctx, label, send) {
65
62
  return sendSharedBestEffort(ctx, `[helpdesk] ${label} failed`, send);
66
63
  }
64
+ export async function runBestEffort(ctx, label, run) {
65
+ return runSharedBestEffort(ctx, `[helpdesk] ${label} failed`, run);
66
+ }
67
67
  export async function forwardHelpdeskRequest(ctx, requestId) {
68
68
  const forwarded = await ctx.dispatch.writeAs(platformActor(), HelpdeskHandlers.forwardRequest, {
69
69
  requestId,
@@ -8,6 +8,7 @@ import { retryQuarantinedMessages } from "./quarantine-retry.js";
8
8
  const SEEN_LOOKUP_CHUNK_SIZE = 1000;
9
9
  export function createAccountPoller(deps) {
10
10
  const { systemDb, cursors, ingester, health, providerCtx, backfillWindowDays, maxMessagesPerPoll, resolveAccessToken, handleSyncError, log, } = deps;
11
+ const scanResumePoint = new Map();
11
12
  function unknownMessageIdsFilterFor(account) {
12
13
  return async (providerMessageIds) => {
13
14
  if (providerMessageIds.length === 0)
@@ -45,6 +46,7 @@ export function createAccountPoller(deps) {
45
46
  const accessToken = await resolveAccessToken(account, plugin);
46
47
  await refetchSnippetOnlyMessages({
47
48
  db: systemDb,
49
+ scanResumePoint,
48
50
  dispatchWrite: deps.dispatchWrite,
49
51
  providerCtx,
50
52
  account,
@@ -1,10 +1,13 @@
1
1
  import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
2
+ import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
2
3
  import type { DispatchWrite } from "./supervisor-ingest.ts";
3
4
  import type { InboundMailContext, InboundMailProviderPlugin, MailAccountRecord } from "./types.ts";
4
5
  export declare const CONTENT_REFETCH_BUDGET_PER_TICK = 50;
5
6
  export declare const CONTENT_REFETCH_SCAN_ROWS_PER_TICK: number;
7
+ export type ScanResumePoints = Map<string, Temporal.Instant>;
6
8
  export declare function refetchSnippetOnlyMessages(args: {
7
9
  readonly db: DbConnection;
10
+ readonly scanResumePoint: ScanResumePoints;
8
11
  readonly dispatchWrite: DispatchWrite;
9
12
  readonly providerCtx: InboundMailContext;
10
13
  readonly account: MailAccountRecord;
@@ -13,15 +13,11 @@ export const CONTENT_REFETCH_BUDGET_PER_TICK = 50;
13
13
  const SEEN_PAGE_SIZE = 250;
14
14
  const SEEN_MAX_PAGES = 4;
15
15
  export const CONTENT_REFETCH_SCAN_ROWS_PER_TICK = SEEN_PAGE_SIZE * SEEN_MAX_PAGES;
16
- // Where the previous tick stopped scanning, per account. Without it every tick re-reads the newest
17
- // rows and snippet-only mails further back would never be reached. Lost on restart, which only
18
- // means the scan starts at the newest mail again.
19
- const scanResumePoint = new Map();
20
16
  function needsContent(row) {
21
17
  const bodyMissing = row.bodyRef === undefined || row.bodyRef === null || row.bodyRef === "";
22
18
  return bodyMissing && (row.contentState == null || row.contentState === "snippet");
23
19
  }
24
- async function findSnippetOnlyMessageIds(db, account, windowDays) {
20
+ async function findSnippetOnlyMessageIds(db, scanResumePoint, account, windowDays) {
25
21
  const cutoff = Temporal.Now.instant().subtract({ hours: windowDays * 24 });
26
22
  const found = [];
27
23
  let before = scanResumePoint.get(account.id);
@@ -68,7 +64,7 @@ export async function refetchSnippetOnlyMessages(args) {
68
64
  // skip: the provider cannot reload content.
69
65
  if (!plugin.fetchContent)
70
66
  return;
71
- const ids = await findSnippetOnlyMessageIds(args.db, account, args.windowDays);
67
+ const ids = await findSnippetOnlyMessageIds(args.db, args.scanResumePoint, account, args.windowDays);
72
68
  // skip: no snippet-only mail to reload.
73
69
  if (ids.length === 0)
74
70
  return;
@@ -2,6 +2,7 @@ import { collectPiiSubjectFields, piiCiphertextMaxLengthFor, } from "@cosmicdrif
2
2
  import { deriveEntityTableMeta, isSchemaTable, physicalColumnName, } from "@cosmicdrift/kumiko-framework/db";
3
3
  import { access, createBooleanField, createEntity, createFilesField, createLongTextField, createNumberField, createTextField, createTimestampField, } from "@cosmicdrift/kumiko-framework/engine";
4
4
  import { DEFAULT_INBOUND_MAIL_ADMIN_ROLES, DEFAULT_INBOUND_MAIL_USER_ROLES } from "./mail-roles.js";
5
+ import { INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, INBOUND_BODY_HTML_MAX_BYTES, INBOUND_BODY_TEXT_MAX_CHARS, INBOUND_FROM_MAX_CHARS, INBOUND_MAIL_ADDRESS_MAX_CHARS, INBOUND_SNIPPET_MAX_CHARS, INBOUND_SUBJECT_MAX_CHARS, } from "./normalize-inbound-message.js";
5
6
  // ============================================================================
6
7
  // Read models for the three event-sourced aggregates
7
8
  // ============================================================================
@@ -52,7 +53,7 @@ export const mailAccountEntity = createEntity({
52
53
  // Mailbox address — tenant PII.
53
54
  address: createTextField({
54
55
  required: true,
55
- maxLength: piiCiphertextMaxLengthFor(320),
56
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_MAIL_ADDRESS_MAX_CHARS),
56
57
  personal: "tenant",
57
58
  find: "none",
58
59
  }),
@@ -124,28 +125,28 @@ export function createInboundMessageEntity(memberRoles) {
124
125
  }),
125
126
  from: createTextField({
126
127
  required: true,
127
- maxLength: piiCiphertextMaxLengthFor(2000),
128
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_FROM_MAX_CHARS),
128
129
  personal: "tenant",
129
130
  find: "none",
130
131
  }),
131
132
  // JSON-stringified string[] — als Ganzes encrypted.
132
133
  to: createTextField({
133
- maxLength: piiCiphertextMaxLengthFor(8000),
134
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS),
134
135
  personal: "tenant",
135
136
  find: "none",
136
137
  }),
137
138
  cc: createTextField({
138
- maxLength: piiCiphertextMaxLengthFor(8000),
139
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS),
139
140
  personal: "tenant",
140
141
  find: "none",
141
142
  }),
142
143
  subject: createTextField({
143
- maxLength: piiCiphertextMaxLengthFor(4000),
144
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS),
144
145
  personal: "tenant",
145
146
  find: "none",
146
147
  }),
147
148
  snippet: createTextField({
148
- maxLength: piiCiphertextMaxLengthFor(4000),
149
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SNIPPET_MAX_CHARS),
149
150
  personal: "tenant",
150
151
  find: "none",
151
152
  }),
@@ -155,7 +156,7 @@ export function createInboundMessageEntity(memberRoles) {
155
156
  // Null on rows from before the column; list-messages never selects it.
156
157
  // Plaintext is clipped to INBOUND_BODY_TEXT_MAX_CHARS (32_000) before encryption.
157
158
  bodyText: createLongTextField({
158
- maxLength: piiCiphertextMaxLengthFor(32_000),
159
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_BODY_TEXT_MAX_CHARS),
159
160
  personal: "tenant",
160
161
  find: "none",
161
162
  }),
@@ -163,7 +164,7 @@ export function createInboundMessageEntity(memberRoles) {
163
164
  // Sanitized HTML of the mail, null when the mail has none or it was too large: sanitizeInboundHtml
164
165
  // drops anything over 500_000 bytes after sanitizing, before encryption.
165
166
  bodyHtml: createLongTextField({
166
- maxLength: piiCiphertextMaxLengthFor(500_000),
167
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_BODY_HTML_MAX_BYTES),
167
168
  personal: "tenant",
168
169
  find: "none",
169
170
  }),
@@ -216,7 +217,7 @@ export const mailThreadEntity = createEntity({
216
217
  reason: "technical_reference",
217
218
  }),
218
219
  subject: createTextField({
219
- maxLength: piiCiphertextMaxLengthFor(4000),
220
+ maxLength: piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS),
220
221
  personal: "tenant",
221
222
  find: "none",
222
223
  }),
@@ -22,6 +22,7 @@
22
22
  import { piiCiphertextMaxLengthFor } from "@cosmicdrift/kumiko-framework/crypto";
23
23
  import * as z from "zod";
24
24
  import { INBOUND_MAIL_FOUNDATION_FEATURE, InboundMailAccountStatuses } from "./constants.js";
25
+ import { INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, INBOUND_BODY_HTML_MAX_BYTES, INBOUND_BODY_TEXT_MAX_CHARS, INBOUND_FROM_MAX_CHARS, INBOUND_MAIL_ADDRESS_MAX_CHARS, INBOUND_SNIPPET_MAX_CHARS, INBOUND_SUBJECT_MAX_CHARS, } from "./normalize-inbound-message.js";
25
26
  import { senderAuthenticationFieldSchema } from "./sender-auth.js";
26
27
  // Aggregate types for the event store.
27
28
  export const MAIL_ACCOUNT_AGGREGATE_TYPE = "mail-account";
@@ -62,7 +63,7 @@ export const mailAccountEventPayloadSchema = z.object({
62
63
  /** null = shared by the tenant; otherwise, this user's personal mailbox. */
63
64
  ownerUserId: z.string().max(36).nullable(),
64
65
  displayName: z.string().max(200),
65
- address: z.string().min(1).max(piiCiphertextMaxLengthFor(320)),
66
+ address: z.string().min(1).max(piiCiphertextMaxLengthFor(INBOUND_MAIL_ADDRESS_MAX_CHARS)),
66
67
  status: accountStatusEnum,
67
68
  /** Provider-agnostic watch state ("idle", "watching", "backoff:3", ...)
68
69
  * — an operational signal only, not PII. */
@@ -95,10 +96,10 @@ export const skippedAttachmentSchema = z.object({
95
96
  // Shared by inbound-message-received (v2+) and inbound-message-content-fetched.
96
97
  // bodyText is ciphertext of at most INBOUND_BODY_TEXT_MAX_CHARS (32_000) characters.
97
98
  const inboundMessageContentShape = {
98
- bodyText: z.string().max(piiCiphertextMaxLengthFor(32_000)),
99
+ bodyText: z.string().max(piiCiphertextMaxLengthFor(INBOUND_BODY_TEXT_MAX_CHARS)),
99
100
  bodyTextTruncated: z.boolean(),
100
101
  /** Sanitized HTML body as PII ciphertext. sanitizeInboundHtml drops anything over 500_000 bytes after sanitizing. Null: none or too large. */
101
- bodyHtml: z.string().max(piiCiphertextMaxLengthFor(500_000)).nullable(),
102
+ bodyHtml: z.string().max(piiCiphertextMaxLengthFor(INBOUND_BODY_HTML_MAX_BYTES)).nullable(),
102
103
  /** file-foundation FileRef ids (plaintext uuids). Attachments outlive the mail: apps turn them
103
104
  * into documents, so the retention sweep never deletes them. */
104
105
  attachmentFileIds: z.array(z.uuid()).max(50),
@@ -127,13 +128,13 @@ export const inboundMessageEventPayloadSchema = z.object({
127
128
  /** Normalized thread key (References-chain root or provider thread ID,
128
129
  * prefixed by the provider). */
129
130
  threadKey: z.string().min(1).max(500),
130
- from: z.string().min(1).max(piiCiphertextMaxLengthFor(2000)),
131
+ from: z.string().min(1).max(piiCiphertextMaxLengthFor(INBOUND_FROM_MAX_CHARS)),
131
132
  /** JSON-stringified string[], dann PII-encrypted. */
132
- to: z.string().max(piiCiphertextMaxLengthFor(8000)),
133
+ to: z.string().max(piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS)),
133
134
  /** JSON-stringified string[], dann PII-encrypted. */
134
- cc: z.string().max(piiCiphertextMaxLengthFor(8000)),
135
- subject: z.string().max(piiCiphertextMaxLengthFor(4000)),
136
- snippet: z.string().max(piiCiphertextMaxLengthFor(4000)),
135
+ cc: z.string().max(piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS)),
136
+ subject: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS)),
137
+ snippet: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SNIPPET_MAX_CHARS)),
137
138
  /** ISO instant — receipt time reported by the provider (INTERNALDATE or
138
139
  * receivedDateTime), not ingest time. */
139
140
  receivedAtIso: z.string().min(1),
@@ -165,7 +166,7 @@ export const inboundMessageContentFetchedEventPayloadSchema = z.object({
165
166
  // ============================================================================
166
167
  export const mailThreadEventPayloadSchema = z.object({
167
168
  threadKey: z.string().min(1).max(500),
168
- subject: z.string().max(piiCiphertextMaxLengthFor(4000)),
169
+ subject: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS)),
169
170
  lastMessageAtIso: z.string().min(1),
170
171
  messageCount: z.number().int().min(1),
171
172
  });
@@ -22,6 +22,7 @@ import { InboundMailAccountStatuses, InboundMailAuthMethods, InboundMailConnectE
22
22
  import { MAIL_ACCOUNT_PII_FIELDS, mailAccountEntity } from "../entities.js";
23
23
  import { MAIL_ACCOUNT_AGGREGATE_TYPE, MAIL_ACCOUNT_CONNECTED_EVENT_QN, } from "../events.js";
24
24
  import { accessRolesOf } from "../mail-roles.js";
25
+ import { INBOUND_MAIL_ADDRESS_MAX_CHARS } from "../normalize-inbound-message.js";
25
26
  import { connectConflictOf, findMailboxByAddress, normalizeMailAddress, } from "./account-address.js";
26
27
  // 'inma': serializes the duplicate-address check and the append per tenant and address (the lock key is tenant-scoped).
27
28
  const CONNECT_ADDRESS_LOCK_NAMESPACE = 0x696e6d61;
@@ -37,7 +38,7 @@ export const connectAccountSchema = z
37
38
  ]),
38
39
  displayName: z.string().trim().max(200),
39
40
  /** Mailbox address in plaintext; it is encrypted here. */
40
- address: z.string().min(1).max(320),
41
+ address: z.string().min(1).max(INBOUND_MAIL_ADDRESS_MAX_CHARS),
41
42
  /** "shared" = shared across the tenant (info@) · "user" = the caller's
42
43
  * personal mailbox (ownerUserId is taken from the session, never from
43
44
  * the payload—preventing claims on another user's mailbox). */
@@ -24,6 +24,10 @@ export function createForgetMessageHandler({ memberRoles, adminRoles, }) {
24
24
  return writeFailure(new AccessDeniedError({ details: { reason: "not_mailbox_owner" } }));
25
25
  }
26
26
  const { files } = ctx.services;
27
+ // Without file storage the original could not be deleted, and the row held its only reference.
28
+ if (row.bodyRef && !files) {
29
+ throw new Error(`forget-message: no file storage to delete the stored original of ${messageId}`);
30
+ }
27
31
  const purged = await purgeInboundMessages({
28
32
  db: ctx.db,
29
33
  tenantId: event.user.tenantId,
@@ -1,4 +1,5 @@
1
1
  import * as z from "zod";
2
+ import { INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, INBOUND_FROM_MAX_CHARS, INBOUND_SNIPPET_MAX_CHARS, INBOUND_SUBJECT_MAX_CHARS, } from "../normalize-inbound-message.js";
2
3
  import { senderAuthenticationFieldSchema } from "../sender-auth.js";
3
4
  import { inboundContentPayloadShape } from "./message-content.js";
4
5
  // =============================================================================
@@ -7,6 +8,12 @@ import { inboundContentPayloadShape } from "./message-content.js";
7
8
  // original and attachments ride in-process as bytes and are persisted to file
8
9
  // storage here; the event itself stays blob-free (references only).
9
10
  // =============================================================================
11
+ const addressListSchema = z
12
+ .array(z.string().max(2000))
13
+ .max(200)
14
+ .refine((list) => JSON.stringify(list).length <= INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, {
15
+ message: "serialized address list too long",
16
+ });
10
17
  export const ingestMessageSchema = z.object({
11
18
  accountId: z.uuid(),
12
19
  /** Scope inherited from the account — the supervisor knows the
@@ -20,11 +27,11 @@ export const ingestMessageSchema = z.object({
20
27
  providerThreadId: z.string().min(1).max(500).nullable(),
21
28
  /** References/In-Reply-To chain, oldest first. */
22
29
  references: z.array(z.string().min(1).max(500)).max(200),
23
- from: z.string().min(1).max(2000),
24
- to: z.array(z.string().max(2000)).max(200),
25
- cc: z.array(z.string().max(2000)).max(200),
26
- subject: z.string().max(4000),
27
- snippet: z.string().max(4000),
30
+ from: z.string().min(1).max(INBOUND_FROM_MAX_CHARS),
31
+ to: addressListSchema,
32
+ cc: addressListSchema,
33
+ subject: z.string().max(INBOUND_SUBJECT_MAX_CHARS),
34
+ snippet: z.string().max(INBOUND_SNIPPET_MAX_CHARS),
28
35
  receivedAtIso: z.string().min(1),
29
36
  /** From the app's storeBody hook; empty lets the handler store the original itself. */
30
37
  bodyRef: z.string().max(500),
@@ -1,12 +1,18 @@
1
1
  import type { RawInboundAttachment, RawInboundMessage, SkippedInboundAttachment } from "./types.ts";
2
2
  export declare const INBOUND_MISSING_SENDER = "(no sender)";
3
3
  export declare const INBOUND_BODY_TEXT_MAX_CHARS = 32000;
4
+ export declare const INBOUND_BODY_HTML_MAX_BYTES = 500000;
4
5
  export declare const INBOUND_BODY_HTML_MAX_CHARS = 5000000;
5
6
  export declare const INBOUND_ATTACHMENT_MAX_BYTES: number;
6
7
  export declare const INBOUND_MAIL_ATTACHMENTS_MAX_BYTES: number;
7
8
  export declare const INBOUND_RAW_MIME_MAX_BYTES: number;
8
9
  export declare const INBOUND_ATTACHMENTS_MAX_COUNT = 50;
9
10
  export declare const INBOUND_SKIPPED_ATTACHMENTS_MAX_COUNT = 200;
11
+ export declare const INBOUND_FROM_MAX_CHARS = 2000;
12
+ export declare const INBOUND_SUBJECT_MAX_CHARS = 4000;
13
+ export declare const INBOUND_SNIPPET_MAX_CHARS = 4000;
14
+ export declare const INBOUND_MAIL_ADDRESS_MAX_CHARS = 320;
15
+ export declare const INBOUND_ADDRESS_LIST_JSON_MAX_CHARS = 8000;
10
16
  export type NormalizedInboundMessage = Omit<RawInboundMessage, "text" | "html" | "attachments" | "skippedAttachments"> & {
11
17
  readonly bodyText: string;
12
18
  readonly bodyTextTruncated: boolean;
@@ -3,6 +3,9 @@
3
3
  // mail would otherwise block the cursor of its mailbox forever.
4
4
  export const INBOUND_MISSING_SENDER = "(no sender)";
5
5
  export const INBOUND_BODY_TEXT_MAX_CHARS = 32_000;
6
+ // Counted in UTF-8 bytes, not characters: the ciphertext grows with the bytes, and a CJK or emoji
7
+ // mail of 500,000 characters would encrypt past the event's bodyHtml maximum.
8
+ export const INBOUND_BODY_HTML_MAX_BYTES = 500_000;
6
9
  export const INBOUND_BODY_HTML_MAX_CHARS = 5_000_000;
7
10
  export const INBOUND_ATTACHMENT_MAX_BYTES = 25 * 1024 * 1024;
8
11
  export const INBOUND_MAIL_ATTACHMENTS_MAX_BYTES = 50 * 1024 * 1024;
@@ -10,13 +13,16 @@ export const INBOUND_MAIL_ATTACHMENTS_MAX_BYTES = 50 * 1024 * 1024;
10
13
  export const INBOUND_RAW_MIME_MAX_BYTES = INBOUND_MAIL_ATTACHMENTS_MAX_BYTES;
11
14
  export const INBOUND_ATTACHMENTS_MAX_COUNT = 50;
12
15
  export const INBOUND_SKIPPED_ATTACHMENTS_MAX_COUNT = 200;
13
- const FROM_MAX = 2000;
16
+ export const INBOUND_FROM_MAX_CHARS = 2000;
17
+ export const INBOUND_SUBJECT_MAX_CHARS = 4000;
18
+ export const INBOUND_SNIPPET_MAX_CHARS = 4000;
19
+ export const INBOUND_MAIL_ADDRESS_MAX_CHARS = 320;
20
+ // Plaintext of one JSON-stringified to/cc list; its ciphertext must fit the event and entity field.
21
+ export const INBOUND_ADDRESS_LIST_JSON_MAX_CHARS = 8000;
14
22
  const ADDRESS_MAX = 2000;
15
23
  const ADDRESS_LIST_MAX = 200;
16
24
  const REFERENCE_MAX = 500;
17
25
  const REFERENCES_MAX = 200;
18
- const SUBJECT_MAX = 4000;
19
- const SNIPPET_MAX = 4000;
20
26
  const MESSAGE_ID_HEADER_MAX = 500;
21
27
  function isHighSurrogate(code) {
22
28
  return code >= 0xd800 && code <= 0xdbff;
@@ -28,6 +34,13 @@ function clip(value, max) {
28
34
  const cut = isHighSurrogate(value.charCodeAt(max - 1)) ? max - 1 : max;
29
35
  return value.slice(0, cut);
30
36
  }
37
+ function limitAddressList(list) {
38
+ const kept = list.slice(0, ADDRESS_LIST_MAX).map((a) => clip(a, ADDRESS_MAX));
39
+ while (kept.length > 0 && JSON.stringify(kept).length > INBOUND_ADDRESS_LIST_JSON_MAX_CHARS) {
40
+ kept.pop();
41
+ }
42
+ return kept;
43
+ }
31
44
  function limitReferences(references) {
32
45
  const usable = references.filter((r) => r.length > 0 && r.length <= REFERENCE_MAX);
33
46
  if (usable.length <= REFERENCES_MAX)
@@ -76,11 +89,11 @@ export function normalizeRawInboundMessage(msg) {
76
89
  ? msg.messageIdHeader
77
90
  : null,
78
91
  references: limitReferences(msg.references),
79
- from: from.length === 0 ? INBOUND_MISSING_SENDER : clip(from, FROM_MAX),
80
- to: msg.to.slice(0, ADDRESS_LIST_MAX).map((a) => clip(a, ADDRESS_MAX)),
81
- cc: msg.cc.slice(0, ADDRESS_LIST_MAX).map((a) => clip(a, ADDRESS_MAX)),
82
- subject: clip(msg.subject, SUBJECT_MAX),
83
- snippet: clip(msg.snippet, SNIPPET_MAX),
92
+ from: from.length === 0 ? INBOUND_MISSING_SENDER : clip(from, INBOUND_FROM_MAX_CHARS),
93
+ to: limitAddressList(msg.to),
94
+ cc: limitAddressList(msg.cc),
95
+ subject: clip(msg.subject, INBOUND_SUBJECT_MAX_CHARS),
96
+ snippet: clip(msg.snippet, INBOUND_SNIPPET_MAX_CHARS),
84
97
  bodyText: clip(fullText, INBOUND_BODY_TEXT_MAX_CHARS),
85
98
  bodyTextTruncated: fullText.length > INBOUND_BODY_TEXT_MAX_CHARS,
86
99
  bodyHtml: bodyHtml !== null && bodyHtml.length <= INBOUND_BODY_HTML_MAX_CHARS ? bodyHtml : null,
@@ -1,2 +1 @@
1
- export declare const BODY_HTML_MAX_BYTES = 500000;
2
1
  export declare function sanitizeInboundHtml(html: string): string | null;
@@ -1,9 +1,7 @@
1
1
  // Allowlist sanitizer for the HTML part of an inbound mail. The result is stored in the event and
2
2
  // shown by the reader inside a script-free sandboxed iframe; this is the first of the two layers.
3
3
  import sanitizeHtml from "sanitize-html";
4
- // Counted in UTF-8 bytes, not characters: the ciphertext grows with the bytes, and a CJK or emoji
5
- // mail of 500,000 characters would encrypt past the event's bodyHtml maximum.
6
- export const BODY_HTML_MAX_BYTES = 500_000;
4
+ import { INBOUND_BODY_HTML_MAX_BYTES } from "./normalize-inbound-message.js";
7
5
  const ALLOWED_TAGS = [
8
6
  "p",
9
7
  "br",
@@ -129,7 +127,7 @@ export function sanitizeInboundHtml(html) {
129
127
  // An image whose src was stripped (cid:, data:, other scheme) is only a broken placeholder.
130
128
  exclusiveFilter: (frame) => frame.tag === "img" && frame.attribs["src"] === undefined,
131
129
  }).trim();
132
- return clean.length === 0 || Buffer.byteLength(clean, "utf8") > BODY_HTML_MAX_BYTES
130
+ return clean.length === 0 || Buffer.byteLength(clean, "utf8") > INBOUND_BODY_HTML_MAX_BYTES
133
131
  ? null
134
132
  : clean;
135
133
  }