@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.
- package/package.json +1 -1
- package/packages/bundled-features/package.json +1 -1
- package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +2 -3
- package/packages/bundled-features/src/auth-email-password/web/session.tsx +2 -1
- package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
- package/packages/bundled-features/src/billing-foundation/changes.json +24 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +11 -0
- package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +8 -0
- package/packages/bundled-features/src/billing-foundation/events.ts +7 -5
- package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +76 -24
- package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +5 -4
- package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +2 -2
- package/packages/bundled-features/src/channel-whatsapp/changes.json +24 -0
- package/packages/bundled-features/src/channel-whatsapp/events.ts +4 -3
- package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +23 -2
- package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +27 -6
- package/packages/bundled-features/src/compliance-profiles/changes.json +5 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/set-profile.write.ts +2 -0
- package/packages/bundled-features/src/data-retention/feature.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +6 -0
- package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +12 -3
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +3 -1
- package/packages/bundled-features/src/documents/changes.json +6 -0
- package/packages/bundled-features/src/documents/feature.ts +10 -5
- package/packages/bundled-features/src/form-draft/feature.ts +1 -0
- package/packages/bundled-features/src/helpdesk/changes.json +6 -0
- package/packages/bundled-features/src/helpdesk/feature.ts +1 -0
- package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +3 -3
- package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +3 -2
- package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +3 -2
- package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +3 -1
- package/packages/bundled-features/src/helpdesk/lib.ts +9 -4
- package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +4 -1
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +11 -4
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +18 -9
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +18 -9
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +2 -1
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts +18 -5
- package/packages/bundled-features/src/inbound-mail-foundation/normalize-inbound-message.ts +22 -8
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +2 -5
- package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +11 -5
- package/packages/bundled-features/src/shared/changes.json +6 -0
- package/packages/bundled-features/src/shared/hmac-signature.ts +4 -2
- package/packages/bundled-features/src/shared/index.ts +2 -1
- package/packages/bundled-features/src/shared/normalize-email.ts +3 -0
- package/packages/bundled-features/src/shared/send-best-effort.ts +16 -6
- package/packages/bundled-features/src/step-dispatcher/changes.json +6 -0
- package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +5 -2
- package/packages/bundled-features/src/step-dispatcher/feature.ts +14 -0
- package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +4 -0
- package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +2 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +6 -0
- package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +23 -2
- package/packages/bundled-features/src/subscription-stripe/changes.json +6 -0
- package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +19 -5
- package/packages/bundled-features/src/template-resolver/changes.json +12 -0
- package/packages/bundled-features/src/template-resolver/seeding.ts +37 -7
- package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +7 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +6 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +34 -16
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +6 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +12 -1
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +1 -0
- package/packages/bundled-features/src/user/resolve-verified-user-email.ts +3 -3
- package/packages/bundled-features/src/user-data-rights/feature.ts +1 -0
- package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +2 -2
- package/packages/bundled-features/src/waitlist/import.ts +2 -1
- package/packages/bundled-features/src/waitlist/lib.ts +1 -5
- package/packages/bundled-features/src/waitlist/link-on-signup.ts +2 -2
- package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
- package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +4 -2
- package/samples/apps/admin-console/src/app/shell.tsx +1 -0
- package/samples/recipes/crypto-shredding-hr/README.md +11 -0
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +36 -5
- package/samples/recipes/record-detail-layout/src/order-board.ts +10 -2
|
@@ -23,6 +23,15 @@
|
|
|
23
23
|
import { piiCiphertextMaxLengthFor } from "@cosmicdrift/kumiko-framework/crypto";
|
|
24
24
|
import * as z from "zod";
|
|
25
25
|
import { INBOUND_MAIL_FOUNDATION_FEATURE, InboundMailAccountStatuses } from "./constants.ts";
|
|
26
|
+
import {
|
|
27
|
+
INBOUND_ADDRESS_LIST_JSON_MAX_CHARS,
|
|
28
|
+
INBOUND_BODY_HTML_MAX_BYTES,
|
|
29
|
+
INBOUND_BODY_TEXT_MAX_CHARS,
|
|
30
|
+
INBOUND_FROM_MAX_CHARS,
|
|
31
|
+
INBOUND_MAIL_ADDRESS_MAX_CHARS,
|
|
32
|
+
INBOUND_SNIPPET_MAX_CHARS,
|
|
33
|
+
INBOUND_SUBJECT_MAX_CHARS,
|
|
34
|
+
} from "./normalize-inbound-message.ts";
|
|
26
35
|
import { senderAuthenticationFieldSchema } from "./sender-auth.ts";
|
|
27
36
|
|
|
28
37
|
// Aggregate types for the event store.
|
|
@@ -75,7 +84,7 @@ export const mailAccountEventPayloadSchema = z.object({
|
|
|
75
84
|
/** null = shared by the tenant; otherwise, this user's personal mailbox. */
|
|
76
85
|
ownerUserId: z.string().max(36).nullable(),
|
|
77
86
|
displayName: z.string().max(200),
|
|
78
|
-
address: z.string().min(1).max(piiCiphertextMaxLengthFor(
|
|
87
|
+
address: z.string().min(1).max(piiCiphertextMaxLengthFor(INBOUND_MAIL_ADDRESS_MAX_CHARS)),
|
|
79
88
|
status: accountStatusEnum,
|
|
80
89
|
/** Provider-agnostic watch state ("idle", "watching", "backoff:3", ...)
|
|
81
90
|
* — an operational signal only, not PII. */
|
|
@@ -115,10 +124,10 @@ export const skippedAttachmentSchema = z.object({
|
|
|
115
124
|
// Shared by inbound-message-received (v2+) and inbound-message-content-fetched.
|
|
116
125
|
// bodyText is ciphertext of at most INBOUND_BODY_TEXT_MAX_CHARS (32_000) characters.
|
|
117
126
|
const inboundMessageContentShape = {
|
|
118
|
-
bodyText: z.string().max(piiCiphertextMaxLengthFor(
|
|
127
|
+
bodyText: z.string().max(piiCiphertextMaxLengthFor(INBOUND_BODY_TEXT_MAX_CHARS)),
|
|
119
128
|
bodyTextTruncated: z.boolean(),
|
|
120
129
|
/** Sanitized HTML body as PII ciphertext. sanitizeInboundHtml drops anything over 500_000 bytes after sanitizing. Null: none or too large. */
|
|
121
|
-
bodyHtml: z.string().max(piiCiphertextMaxLengthFor(
|
|
130
|
+
bodyHtml: z.string().max(piiCiphertextMaxLengthFor(INBOUND_BODY_HTML_MAX_BYTES)).nullable(),
|
|
122
131
|
/** file-foundation FileRef ids (plaintext uuids). Attachments outlive the mail: apps turn them
|
|
123
132
|
* into documents, so the retention sweep never deletes them. */
|
|
124
133
|
attachmentFileIds: z.array(z.uuid()).max(50),
|
|
@@ -148,13 +157,13 @@ export const inboundMessageEventPayloadSchema = z.object({
|
|
|
148
157
|
/** Normalized thread key (References-chain root or provider thread ID,
|
|
149
158
|
* prefixed by the provider). */
|
|
150
159
|
threadKey: z.string().min(1).max(500),
|
|
151
|
-
from: z.string().min(1).max(piiCiphertextMaxLengthFor(
|
|
160
|
+
from: z.string().min(1).max(piiCiphertextMaxLengthFor(INBOUND_FROM_MAX_CHARS)),
|
|
152
161
|
/** JSON-stringified string[], dann PII-encrypted. */
|
|
153
|
-
to: z.string().max(piiCiphertextMaxLengthFor(
|
|
162
|
+
to: z.string().max(piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS)),
|
|
154
163
|
/** JSON-stringified string[], dann PII-encrypted. */
|
|
155
|
-
cc: z.string().max(piiCiphertextMaxLengthFor(
|
|
156
|
-
subject: z.string().max(piiCiphertextMaxLengthFor(
|
|
157
|
-
snippet: z.string().max(piiCiphertextMaxLengthFor(
|
|
164
|
+
cc: z.string().max(piiCiphertextMaxLengthFor(INBOUND_ADDRESS_LIST_JSON_MAX_CHARS)),
|
|
165
|
+
subject: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS)),
|
|
166
|
+
snippet: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SNIPPET_MAX_CHARS)),
|
|
158
167
|
/** ISO instant — receipt time reported by the provider (INTERNALDATE or
|
|
159
168
|
* receivedDateTime), not ingest time. */
|
|
160
169
|
receivedAtIso: z.string().min(1),
|
|
@@ -192,7 +201,7 @@ export type InboundMessageContentFetchedEventPayload = z.infer<
|
|
|
192
201
|
// ============================================================================
|
|
193
202
|
export const mailThreadEventPayloadSchema = z.object({
|
|
194
203
|
threadKey: z.string().min(1).max(500),
|
|
195
|
-
subject: z.string().max(piiCiphertextMaxLengthFor(
|
|
204
|
+
subject: z.string().max(piiCiphertextMaxLengthFor(INBOUND_SUBJECT_MAX_CHARS)),
|
|
196
205
|
lastMessageAtIso: z.string().min(1),
|
|
197
206
|
messageCount: z.number().int().min(1),
|
|
198
207
|
});
|
package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts
CHANGED
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
type MailAccountEventPayload,
|
|
42
42
|
} from "../events.ts";
|
|
43
43
|
import { accessRolesOf, type InboundMailRoles } from "../mail-roles.ts";
|
|
44
|
+
import { INBOUND_MAIL_ADDRESS_MAX_CHARS } from "../normalize-inbound-message.ts";
|
|
44
45
|
import {
|
|
45
46
|
connectConflictOf,
|
|
46
47
|
findMailboxByAddress,
|
|
@@ -62,7 +63,7 @@ export const connectAccountSchema = z
|
|
|
62
63
|
]),
|
|
63
64
|
displayName: z.string().trim().max(200),
|
|
64
65
|
/** Mailbox address in plaintext; it is encrypted here. */
|
|
65
|
-
address: z.string().min(1).max(
|
|
66
|
+
address: z.string().min(1).max(INBOUND_MAIL_ADDRESS_MAX_CHARS),
|
|
66
67
|
/** "shared" = shared across the tenant (info@) · "user" = the caller's
|
|
67
68
|
* personal mailbox (ownerUserId is taken from the session, never from
|
|
68
69
|
* the payload—preventing claims on another user's mailbox). */
|
package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts
CHANGED
|
@@ -42,6 +42,12 @@ export function createForgetMessageHandler({
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const { files } = ctx.services;
|
|
45
|
+
// Without file storage the original could not be deleted, and the row held its only reference.
|
|
46
|
+
if (row.bodyRef && !files) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`forget-message: no file storage to delete the stored original of ${messageId}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
45
51
|
const purged = await purgeInboundMessages({
|
|
46
52
|
db: ctx.db,
|
|
47
53
|
tenantId: event.user.tenantId,
|
package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
INBOUND_ADDRESS_LIST_JSON_MAX_CHARS,
|
|
4
|
+
INBOUND_FROM_MAX_CHARS,
|
|
5
|
+
INBOUND_SNIPPET_MAX_CHARS,
|
|
6
|
+
INBOUND_SUBJECT_MAX_CHARS,
|
|
7
|
+
} from "../normalize-inbound-message.ts";
|
|
2
8
|
import { senderAuthenticationFieldSchema } from "../sender-auth.ts";
|
|
3
9
|
import { inboundContentPayloadShape } from "./message-content.ts";
|
|
4
10
|
|
|
@@ -9,6 +15,13 @@ import { inboundContentPayloadShape } from "./message-content.ts";
|
|
|
9
15
|
// storage here; the event itself stays blob-free (references only).
|
|
10
16
|
// =============================================================================
|
|
11
17
|
|
|
18
|
+
const addressListSchema = z
|
|
19
|
+
.array(z.string().max(2000))
|
|
20
|
+
.max(200)
|
|
21
|
+
.refine((list) => JSON.stringify(list).length <= INBOUND_ADDRESS_LIST_JSON_MAX_CHARS, {
|
|
22
|
+
message: "serialized address list too long",
|
|
23
|
+
});
|
|
24
|
+
|
|
12
25
|
export const ingestMessageSchema = z.object({
|
|
13
26
|
accountId: z.uuid(),
|
|
14
27
|
/** Scope inherited from the account — the supervisor knows the
|
|
@@ -22,11 +35,11 @@ export const ingestMessageSchema = z.object({
|
|
|
22
35
|
providerThreadId: z.string().min(1).max(500).nullable(),
|
|
23
36
|
/** References/In-Reply-To chain, oldest first. */
|
|
24
37
|
references: z.array(z.string().min(1).max(500)).max(200),
|
|
25
|
-
from: z.string().min(1).max(
|
|
26
|
-
to:
|
|
27
|
-
cc:
|
|
28
|
-
subject: z.string().max(
|
|
29
|
-
snippet: z.string().max(
|
|
38
|
+
from: z.string().min(1).max(INBOUND_FROM_MAX_CHARS),
|
|
39
|
+
to: addressListSchema,
|
|
40
|
+
cc: addressListSchema,
|
|
41
|
+
subject: z.string().max(INBOUND_SUBJECT_MAX_CHARS),
|
|
42
|
+
snippet: z.string().max(INBOUND_SNIPPET_MAX_CHARS),
|
|
30
43
|
receivedAtIso: z.string().min(1),
|
|
31
44
|
/** From the app's storeBody hook; empty lets the handler store the original itself. */
|
|
32
45
|
bodyRef: z.string().max(500),
|
|
@@ -6,6 +6,9 @@ import type { RawInboundAttachment, RawInboundMessage, SkippedInboundAttachment
|
|
|
6
6
|
|
|
7
7
|
export const INBOUND_MISSING_SENDER = "(no sender)";
|
|
8
8
|
export const INBOUND_BODY_TEXT_MAX_CHARS = 32_000;
|
|
9
|
+
// Counted in UTF-8 bytes, not characters: the ciphertext grows with the bytes, and a CJK or emoji
|
|
10
|
+
// mail of 500,000 characters would encrypt past the event's bodyHtml maximum.
|
|
11
|
+
export const INBOUND_BODY_HTML_MAX_BYTES = 500_000;
|
|
9
12
|
export const INBOUND_BODY_HTML_MAX_CHARS = 5_000_000;
|
|
10
13
|
export const INBOUND_ATTACHMENT_MAX_BYTES = 25 * 1024 * 1024;
|
|
11
14
|
export const INBOUND_MAIL_ATTACHMENTS_MAX_BYTES = 50 * 1024 * 1024;
|
|
@@ -14,13 +17,16 @@ export const INBOUND_RAW_MIME_MAX_BYTES = INBOUND_MAIL_ATTACHMENTS_MAX_BYTES;
|
|
|
14
17
|
export const INBOUND_ATTACHMENTS_MAX_COUNT = 50;
|
|
15
18
|
export const INBOUND_SKIPPED_ATTACHMENTS_MAX_COUNT = 200;
|
|
16
19
|
|
|
17
|
-
const
|
|
20
|
+
export const INBOUND_FROM_MAX_CHARS = 2000;
|
|
21
|
+
export const INBOUND_SUBJECT_MAX_CHARS = 4000;
|
|
22
|
+
export const INBOUND_SNIPPET_MAX_CHARS = 4000;
|
|
23
|
+
export const INBOUND_MAIL_ADDRESS_MAX_CHARS = 320;
|
|
24
|
+
// Plaintext of one JSON-stringified to/cc list; its ciphertext must fit the event and entity field.
|
|
25
|
+
export const INBOUND_ADDRESS_LIST_JSON_MAX_CHARS = 8000;
|
|
18
26
|
const ADDRESS_MAX = 2000;
|
|
19
27
|
const ADDRESS_LIST_MAX = 200;
|
|
20
28
|
const REFERENCE_MAX = 500;
|
|
21
29
|
const REFERENCES_MAX = 200;
|
|
22
|
-
const SUBJECT_MAX = 4000;
|
|
23
|
-
const SNIPPET_MAX = 4000;
|
|
24
30
|
const MESSAGE_ID_HEADER_MAX = 500;
|
|
25
31
|
|
|
26
32
|
export type NormalizedInboundMessage = Omit<
|
|
@@ -45,6 +51,14 @@ function clip(value: string, max: number): string {
|
|
|
45
51
|
return value.slice(0, cut);
|
|
46
52
|
}
|
|
47
53
|
|
|
54
|
+
function limitAddressList(list: readonly string[]): readonly string[] {
|
|
55
|
+
const kept = list.slice(0, ADDRESS_LIST_MAX).map((a) => clip(a, ADDRESS_MAX));
|
|
56
|
+
while (kept.length > 0 && JSON.stringify(kept).length > INBOUND_ADDRESS_LIST_JSON_MAX_CHARS) {
|
|
57
|
+
kept.pop();
|
|
58
|
+
}
|
|
59
|
+
return kept;
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
function limitReferences(references: readonly string[]): readonly string[] {
|
|
49
63
|
const usable = references.filter((r) => r.length > 0 && r.length <= REFERENCE_MAX);
|
|
50
64
|
if (usable.length <= REFERENCES_MAX) return usable;
|
|
@@ -102,11 +116,11 @@ export function normalizeRawInboundMessage(msg: RawInboundMessage): NormalizedIn
|
|
|
102
116
|
? msg.messageIdHeader
|
|
103
117
|
: null,
|
|
104
118
|
references: limitReferences(msg.references),
|
|
105
|
-
from: from.length === 0 ? INBOUND_MISSING_SENDER : clip(from,
|
|
106
|
-
to: msg.to
|
|
107
|
-
cc: msg.cc
|
|
108
|
-
subject: clip(msg.subject,
|
|
109
|
-
snippet: clip(msg.snippet,
|
|
119
|
+
from: from.length === 0 ? INBOUND_MISSING_SENDER : clip(from, INBOUND_FROM_MAX_CHARS),
|
|
120
|
+
to: limitAddressList(msg.to),
|
|
121
|
+
cc: limitAddressList(msg.cc),
|
|
122
|
+
subject: clip(msg.subject, INBOUND_SUBJECT_MAX_CHARS),
|
|
123
|
+
snippet: clip(msg.snippet, INBOUND_SNIPPET_MAX_CHARS),
|
|
110
124
|
bodyText: clip(fullText, INBOUND_BODY_TEXT_MAX_CHARS),
|
|
111
125
|
bodyTextTruncated: fullText.length > INBOUND_BODY_TEXT_MAX_CHARS,
|
|
112
126
|
bodyHtml: bodyHtml !== null && bodyHtml.length <= INBOUND_BODY_HTML_MAX_CHARS ? bodyHtml : null,
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
// shown by the reader inside a script-free sandboxed iframe; this is the first of the two layers.
|
|
3
3
|
|
|
4
4
|
import sanitizeHtml from "sanitize-html";
|
|
5
|
-
|
|
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 BODY_HTML_MAX_BYTES = 500_000;
|
|
5
|
+
import { INBOUND_BODY_HTML_MAX_BYTES } from "./normalize-inbound-message.ts";
|
|
9
6
|
|
|
10
7
|
const ALLOWED_TAGS = [
|
|
11
8
|
"p",
|
|
@@ -144,7 +141,7 @@ export function sanitizeInboundHtml(html: string): string | null {
|
|
|
144
141
|
// An image whose src was stripped (cid:, data:, other scheme) is only a broken placeholder.
|
|
145
142
|
exclusiveFilter: (frame) => frame.tag === "img" && frame.attribs["src"] === undefined,
|
|
146
143
|
}).trim();
|
|
147
|
-
return clean.length === 0 || Buffer.byteLength(clean, "utf8") >
|
|
144
|
+
return clean.length === 0 || Buffer.byteLength(clean, "utf8") > INBOUND_BODY_HTML_MAX_BYTES
|
|
148
145
|
? null
|
|
149
146
|
: clean;
|
|
150
147
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
useUnsavedInputSource,
|
|
10
10
|
} from "@cosmicdrift/kumiko-renderer";
|
|
11
11
|
import { EditorWorkbench, LoadingState, StatusBadge } from "@cosmicdrift/kumiko-renderer/web";
|
|
12
|
-
import { type ReactNode, useState } from "react";
|
|
12
|
+
import { type ReactNode, useRef, useState } from "react";
|
|
13
13
|
import { DocumentContentEditor } from "../../template-resolver/web/index.ts";
|
|
14
14
|
import {
|
|
15
15
|
PAGE_CREATE_HANDLER,
|
|
@@ -51,8 +51,10 @@ function PageEditor({
|
|
|
51
51
|
}): ReactNode {
|
|
52
52
|
const t = useTranslation();
|
|
53
53
|
const { Banner } = usePrimitives();
|
|
54
|
-
|
|
55
|
-
const
|
|
54
|
+
// Computed once: the editor is remounted per record version, and every keystroke re-renders it.
|
|
55
|
+
const [initial] = useState(() => (record === null ? EMPTY_PAGE_DRAFT : draftOfRecord(record)));
|
|
56
|
+
const [lossyOnOpen] = useState(() => (record === null ? [] : lossyFeaturesOfRecord(record)));
|
|
57
|
+
const savedRef = useRef(false);
|
|
56
58
|
const [draft, setDraft] = useState<PageDraft>(initial);
|
|
57
59
|
const [bodyEdited, setBodyEdited] = useState(false);
|
|
58
60
|
const [resetCount, setResetCount] = useState(0);
|
|
@@ -60,10 +62,13 @@ function PageEditor({
|
|
|
60
62
|
const create = useMutation<{ readonly id?: string }>(PAGE_CREATE_HANDLER);
|
|
61
63
|
const update = useMutation(PAGE_UPDATE_HANDLER);
|
|
62
64
|
const dirty = isDraftDirty(draft, initial);
|
|
63
|
-
|
|
65
|
+
// The leave guard runs synchronously after save, before React re-renders with the saved state.
|
|
66
|
+
useUnsavedInputSource(() => dirty && !savedRef.current);
|
|
64
67
|
|
|
65
|
-
const patch = (changes: Partial<PageDraft>): void =>
|
|
68
|
+
const patch = (changes: Partial<PageDraft>): void => {
|
|
69
|
+
savedRef.current = false;
|
|
66
70
|
setDraft((current) => ({ ...current, ...changes }));
|
|
71
|
+
};
|
|
67
72
|
const canSave = dirty && draft.slug !== "" && draft.title !== "";
|
|
68
73
|
|
|
69
74
|
const save = async (): Promise<void> => {
|
|
@@ -80,6 +85,7 @@ function PageEditor({
|
|
|
80
85
|
setSaveError(dispatcherErrorTextWithFieldIssues(result.error, t));
|
|
81
86
|
return;
|
|
82
87
|
}
|
|
88
|
+
savedRef.current = true;
|
|
83
89
|
onSaved(record === null ? createdIdOf(result.data) : record.id);
|
|
84
90
|
};
|
|
85
91
|
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "One normalizeEmail for helpdesk, waitlist, signup tokens and user-data lookups",
|
|
6
|
+
"detail": "The copies in helpdesk, waitlist, signup-token-store and the inline toLowerCase in resolveVerifiedUserEmail now use shared/normalizeEmail, so a changed normalization cannot make export and erasure miss stored rows."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.414.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -8,8 +8,10 @@ export function hmacSignatureMatches(
|
|
|
8
8
|
expectedBase64Url: string,
|
|
9
9
|
providedBase64Url: string,
|
|
10
10
|
): boolean {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// The text is compared, not the decoded bytes: decoding ignores the unused trailing bits of the
|
|
12
|
+
// last character, so one signature would have several accepted spellings.
|
|
13
|
+
const expectedBuf = Buffer.from(expectedBase64Url);
|
|
14
|
+
const providedBuf = Buffer.from(providedBase64Url);
|
|
13
15
|
// timingSafeEqual throws on a length mismatch, and the throw itself is a timing signal.
|
|
14
16
|
return expectedBuf.length === providedBuf.length && timingSafeEqual(expectedBuf, providedBuf);
|
|
15
17
|
}
|
|
@@ -36,6 +36,7 @@ export {
|
|
|
36
36
|
mailRepeatedRows,
|
|
37
37
|
} from "./mail-template-body.ts";
|
|
38
38
|
export { mapWithConcurrency } from "./map-with-concurrency.ts";
|
|
39
|
+
export { normalizeEmail } from "./normalize-email.ts";
|
|
39
40
|
export {
|
|
40
41
|
denyUnlessJoinRowParentVisible,
|
|
41
42
|
hostRowIsGone,
|
|
@@ -92,7 +93,7 @@ export {
|
|
|
92
93
|
signRowBoundGrant,
|
|
93
94
|
} from "./row-bound-grant.ts";
|
|
94
95
|
export { runInSubTransaction } from "./run-in-sub-transaction.ts";
|
|
95
|
-
export { sendBestEffort } from "./send-best-effort.ts";
|
|
96
|
+
export { runBestEffort, sendBestEffort } from "./send-best-effort.ts";
|
|
96
97
|
export { registrationLocaleFromRequest, sessionLocaleField } from "./session-locale-field.ts";
|
|
97
98
|
export { sessionTimezoneField } from "./session-timezone-field.ts";
|
|
98
99
|
export { assertNotSvg, MAX_INPUT_PIXELS, SHARP_INPUT_OPTIONS } from "./sharp-input-limits.ts";
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import type { HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
|
|
4
|
+
export async function runBestEffort(
|
|
5
|
+
ctx: Pick<HandlerContext, "obs">,
|
|
6
|
+
logMessage: string,
|
|
7
|
+
run: () => Promise<unknown>,
|
|
8
|
+
): Promise<void> {
|
|
9
|
+
try {
|
|
10
|
+
await run();
|
|
11
|
+
} catch (err) {
|
|
12
|
+
ctx.obs.log?.warn(logMessage, {
|
|
13
|
+
error: err instanceof Error ? err.message : String(err),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
export async function sendBestEffort(
|
|
5
19
|
ctx: Pick<HandlerContext, "notify" | "obs">,
|
|
6
20
|
logMessage: string,
|
|
7
21
|
send: (notify: NonNullable<HandlerContext["notify"]>) => Promise<unknown>,
|
|
8
22
|
): Promise<void> {
|
|
9
|
-
|
|
23
|
+
await runBestEffort(ctx, logMessage, async () => {
|
|
10
24
|
if (!ctx.notify) {
|
|
11
25
|
throw new InternalError({ message: "ctx.notify unavailable — mount the delivery feature" });
|
|
12
26
|
}
|
|
13
27
|
await send(ctx.notify);
|
|
14
|
-
}
|
|
15
|
-
ctx.obs.log?.warn(logMessage, {
|
|
16
|
-
error: err instanceof Error ? err.message : String(err),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
28
|
+
});
|
|
19
29
|
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Abandoned-dispatch sweep skips live deliver jobs and cannot overwrite a concurrent outcome",
|
|
6
|
+
"detail": "Before closing a request older than 24 h the sweep asks the job runner whether its deliver job is still waiting, delayed, active, paused or prioritized and skips it until a later run. A runner that cannot report job state makes the sweep skip everything and warn. The failure event is appended with the stream version that was loaded, so a delivery recording its outcome in between causes a version conflict (reported through the close-failure log) and the payload key is not erased. `JobRunner` and `JobRunnerRef` gain an optional `isJobPending(jobName, jobId)`, and `MultiStreamApplyContext.unsafeAppendEvent` accepts an optional `expectedVersion`."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.414.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -141,6 +141,7 @@ function createOutcomeRecorder(
|
|
|
141
141
|
ctx: MultiStreamApplyContext,
|
|
142
142
|
aggregateId: string,
|
|
143
143
|
attempt: number,
|
|
144
|
+
expectedVersion?: number,
|
|
144
145
|
): OutcomeRecorder {
|
|
145
146
|
const record: OutcomeRecorder["record"] = async (type, payload) => {
|
|
146
147
|
await ctx.unsafeAppendEvent({
|
|
@@ -148,6 +149,7 @@ function createOutcomeRecorder(
|
|
|
148
149
|
aggregateType: STEP_DISPATCH_AGGREGATE_TYPE,
|
|
149
150
|
type,
|
|
150
151
|
payload,
|
|
152
|
+
...(expectedVersion !== undefined && { expectedVersion }),
|
|
151
153
|
});
|
|
152
154
|
await eraseDispatchKey(aggregateId);
|
|
153
155
|
};
|
|
@@ -160,7 +162,8 @@ function createOutcomeRecorder(
|
|
|
160
162
|
|
|
161
163
|
// For a deliver job that ended terminally without an outcome (BullMQ stall, lost job): the
|
|
162
164
|
// request is closed as failed and its key erased. A stream that already has an outcome only
|
|
163
|
-
// repeats the erase.
|
|
165
|
+
// repeats the erase. The failure is pinned to the loaded version: a delivery that records its
|
|
166
|
+
// outcome in between makes the append throw VersionConflictError and the key stays.
|
|
164
167
|
export async function closeAbandonedDispatch(
|
|
165
168
|
ctx: MultiStreamApplyContext,
|
|
166
169
|
aggregateId: string,
|
|
@@ -171,7 +174,7 @@ export async function closeAbandonedDispatch(
|
|
|
171
174
|
return "already-closed";
|
|
172
175
|
}
|
|
173
176
|
const requested = stream.find((e) => e.type === STEP_DISPATCH_REQUESTED_TYPE);
|
|
174
|
-
await createOutcomeRecorder(ctx, aggregateId, 0).recordFailure(
|
|
177
|
+
await createOutcomeRecorder(ctx, aggregateId, 0, stream.at(-1)?.version).recordFailure(
|
|
175
178
|
rawStepKindOf(requested?.payload),
|
|
176
179
|
DISPATCH_ABANDONED_ERROR,
|
|
177
180
|
);
|
|
@@ -77,6 +77,7 @@ export function createStepDispatcherFeature(): FeatureDefinition {
|
|
|
77
77
|
"deliver",
|
|
78
78
|
{
|
|
79
79
|
trigger: { manual: true },
|
|
80
|
+
irreversibleWithoutEntryHandler: "per-dispatch-record-key",
|
|
80
81
|
retries: DELIVER_RETRIES,
|
|
81
82
|
backoff: "exponential",
|
|
82
83
|
maxPerTenant: { limit: DELIVER_MAX_PER_TENANT, onLimit: "defer" },
|
|
@@ -110,13 +111,25 @@ export function createStepDispatcherFeature(): FeatureDefinition {
|
|
|
110
111
|
"sweep-abandoned",
|
|
111
112
|
{
|
|
112
113
|
trigger: { cron: "17 3 * * *", wakesSleepingApp: false },
|
|
114
|
+
irreversibleWithoutEntryHandler: "per-dispatch-record-key",
|
|
113
115
|
concurrency: "skip",
|
|
114
116
|
escapeHatch: { reason: SWEEP_ESCAPE_HATCH_REASON },
|
|
115
117
|
},
|
|
116
118
|
async (_payload, ctx) => {
|
|
119
|
+
const runner = ctx.services.jobRunner;
|
|
120
|
+
const isJobPending = runner?.isJobPending?.bind(runner);
|
|
121
|
+
if (!isJobPending) {
|
|
122
|
+
// Fail closed: closing would erase the PII key of a delivery that may still run.
|
|
123
|
+
ctx.obs.log.warn(
|
|
124
|
+
"job runner cannot report job state, abandoned dispatches are not swept",
|
|
125
|
+
);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
117
128
|
await sweepAbandonedDispatches({
|
|
118
129
|
db: ctx.db.unsafeRaw(),
|
|
119
130
|
registry: ctx.registry,
|
|
131
|
+
isDeliverJobPending: (aggregateId) =>
|
|
132
|
+
isJobPending(StepDispatcherJobs.deliver, deliverJobId(aggregateId)),
|
|
120
133
|
startedBeforeIso: ctx.tz
|
|
121
134
|
.now()
|
|
122
135
|
.subtract({ hours: ABANDON_DISPATCH_AFTER_HOURS })
|
|
@@ -129,6 +142,7 @@ export function createStepDispatcherFeature(): FeatureDefinition {
|
|
|
129
142
|
|
|
130
143
|
r.multiStreamProjection({
|
|
131
144
|
name: "step-dispatcher",
|
|
145
|
+
irreversibleWithoutEntryHandler: "per-dispatch-record-key",
|
|
132
146
|
apply: {
|
|
133
147
|
[STEP_DISPATCH_REQUESTED_TYPE]: async (event, _tx, ctx) => {
|
|
134
148
|
const stream = await ctx.loadAggregate(event.aggregateId);
|
|
@@ -16,6 +16,8 @@ export type SweepAbandonedArgs = {
|
|
|
16
16
|
readonly db: DbRunner;
|
|
17
17
|
readonly registry: Registry;
|
|
18
18
|
readonly startedBeforeIso: string;
|
|
19
|
+
// A stream whose deliver job is still queued or running is alive, not abandoned.
|
|
20
|
+
readonly isDeliverJobPending: (aggregateId: string) => Promise<boolean>;
|
|
19
21
|
readonly onCloseFailure: (aggregateId: string, errorName: string) => void;
|
|
20
22
|
readonly batchSize?: number;
|
|
21
23
|
};
|
|
@@ -43,6 +45,8 @@ export async function sweepAbandonedDispatches(args: SweepAbandonedArgs): Promis
|
|
|
43
45
|
callerFeature: STEP_DISPATCHER_FEATURE,
|
|
44
46
|
});
|
|
45
47
|
try {
|
|
48
|
+
// skip: the next run checks the stream again
|
|
49
|
+
if (await args.isDeliverJobPending(aggregateId)) continue;
|
|
46
50
|
await closeAbandonedDispatch(applyContext, aggregateId);
|
|
47
51
|
} catch (err) {
|
|
48
52
|
// One broken stream must not keep the others open; the next run retries it.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// existed: their custom_data still carries the old tenantBinding. Once the
|
|
3
3
|
// first sweep is done the job keeps sweeping for an hour (checkouts opened by
|
|
4
4
|
// the previous release can still be paid), then does nothing.
|
|
5
|
+
// The tenant in custom_data is unverified: the key that signed the binding no longer exists.
|
|
6
|
+
// Only origin "api" and the one hour window bound that; losing a paid checkout would be worse.
|
|
5
7
|
|
|
6
8
|
import {
|
|
7
9
|
parseProviderConsentId,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "unreadable ledger backfill marker no longer causes endless 503",
|
|
6
|
+
"detail": "shouldRedeliverLegacyCheckout answers 200 and logs when the marker dispatch fails, because custom_data.tenantBinding is client-settable."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.414.0",
|
|
4
10
|
"type": "breaking",
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import type { SignatureExtraRouteDeps } from "@cosmicdrift/kumiko-framework/api";
|
|
7
7
|
import { SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
+
import type { FrameworkErrorCode } from "@cosmicdrift/kumiko-framework/errors";
|
|
9
|
+
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
8
10
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
11
|
+
import { isOneOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
9
12
|
import { isTakeoverWindowOver } from "./backfill-checkout-ledger.ts";
|
|
10
13
|
import {
|
|
11
14
|
LEDGER_BACKFILL_MARKER_HANDLER_QN,
|
|
@@ -13,6 +16,15 @@ import {
|
|
|
13
16
|
} from "./ledger-backfill-marker.ts";
|
|
14
17
|
import { hasLegacyTenantBinding } from "./webhook-events.ts";
|
|
15
18
|
|
|
19
|
+
const log = createFallbackLogger("subscription-paddle");
|
|
20
|
+
|
|
21
|
+
// A retry cannot fix these: the marker handler is missing, disabled or not permitted.
|
|
22
|
+
const MARKER_CONFIGURATION_ERROR_CODES = [
|
|
23
|
+
"access_denied",
|
|
24
|
+
"not_found",
|
|
25
|
+
"feature_disabled",
|
|
26
|
+
] as const satisfies readonly FrameworkErrorCode[];
|
|
27
|
+
|
|
16
28
|
type IgnoredEvent = Parameters<typeof hasLegacyTenantBinding>[0];
|
|
17
29
|
|
|
18
30
|
export async function shouldRedeliverLegacyCheckout(args: {
|
|
@@ -28,8 +40,17 @@ export async function shouldRedeliverLegacyCheckout(args: {
|
|
|
28
40
|
roles: [],
|
|
29
41
|
payload: { markCompleted: false },
|
|
30
42
|
});
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
if (!marker.isSuccess) {
|
|
44
|
+
// tenantBinding is client-settable, so a permanent failure must not turn into endless 503s.
|
|
45
|
+
if (isOneOf(MARKER_CONFIGURATION_ERROR_CODES, marker.error.code)) {
|
|
46
|
+
log.warn("ledger backfill marker not readable, not redelivering", {
|
|
47
|
+
errorCode: marker.error.code,
|
|
48
|
+
});
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
// Transient or internal: Paddle redelivers only a bounded number of times, so retrying is safe.
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
33
54
|
const { completedAt } = marker.data as LedgerBackfillMarkerResult; // @cast-boundary engine-payload
|
|
34
55
|
if (completedAt === null) return true;
|
|
35
56
|
return !isTakeoverWindowOver(completedAt, (args.now ?? Temporal.Now.instant)());
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "customer.subscription.created without a linked checkout session is redelivered while young",
|
|
6
|
+
"detail": "An empty checkout session list for a created event younger than ten minutes answers 503 so Stripe redelivers, instead of dropping the subscription as not in the ledger."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.414.0",
|
|
4
10
|
"type": "breaking",
|
|
@@ -167,7 +167,7 @@ export function verifyAndParseStripeWebhook(
|
|
|
167
167
|
// Only the checkout ledger can vouch for a new subscription, so `created` must name its session.
|
|
168
168
|
const providerCheckoutId =
|
|
169
169
|
normalizedType === SubscriptionEventTypes.created
|
|
170
|
-
? await findCheckoutSessionId(stripe, sub.id)
|
|
170
|
+
? await findCheckoutSessionId(stripe, sub.id, event.created)
|
|
171
171
|
: undefined;
|
|
172
172
|
return {
|
|
173
173
|
providerEventId: event.id,
|
|
@@ -183,22 +183,36 @@ export function verifyAndParseStripeWebhook(
|
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
// Stripe may emit `customer.subscription.created` before the session is linked to the subscription.
|
|
187
|
+
const SESSION_LINK_GRACE_SECONDS = 600;
|
|
188
|
+
|
|
189
|
+
// A failing Stripe API call, or an empty list for a young event, is answered with 503 so Stripe
|
|
190
|
+
// redelivers. An empty list for an older event means the subscription has no checkout session: the
|
|
191
|
+
// created event then carries no checkout id and the foundation ignores it as not in the ledger.
|
|
189
192
|
async function findCheckoutSessionId(
|
|
190
193
|
stripe: Stripe,
|
|
191
194
|
subscriptionId: string,
|
|
195
|
+
eventCreatedSeconds: number,
|
|
192
196
|
): Promise<string | undefined> {
|
|
197
|
+
let sessionId: string | undefined;
|
|
193
198
|
try {
|
|
194
199
|
const sessions = await stripe.checkout.sessions.list({
|
|
195
200
|
subscription: subscriptionId,
|
|
196
201
|
limit: 1,
|
|
197
202
|
});
|
|
198
|
-
|
|
203
|
+
sessionId = sessions.data[0]?.id;
|
|
199
204
|
} catch (error) {
|
|
200
205
|
throw transientProviderRejection(error);
|
|
201
206
|
}
|
|
207
|
+
if (sessionId === undefined) {
|
|
208
|
+
const ageSeconds = Temporal.Now.instant().epochMilliseconds / 1000 - eventCreatedSeconds;
|
|
209
|
+
if (ageSeconds < SESSION_LINK_GRACE_SECONDS) {
|
|
210
|
+
throw transientProviderRejection(
|
|
211
|
+
new Error(`no checkout session linked to ${subscriptionId} yet`),
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return sessionId;
|
|
202
216
|
}
|
|
203
217
|
|
|
204
218
|
// =============================================================================
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Orphan cleanup keeps edited system templates of notifications unknown to the booting registry",
|
|
6
|
+
"detail": "A system mail template of a mounted feature whose notification this boot does not register (conditional registration, older pod during a rolling deploy) is deleted only while the system user alone ever wrote it; an edited row is kept and logged with slug and locale. Rows of notifications renamed away through `renamedFrom` are still deleted."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.415.0",
|
|
10
|
+
"type": "fix",
|
|
11
|
+
"title": "Web preview of document bodies fills the example values",
|
|
12
|
+
"detail": "The web preview target sent document bodies with unfilled variable chips. It now fills them with the example values like the snippet preview does."
|
|
13
|
+
},
|
|
2
14
|
{
|
|
3
15
|
"version": "0.414.0",
|
|
4
16
|
"type": "improvement",
|