@cosmicdrift/kumiko-samples 0.387.0 → 0.388.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 +8 -1
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-dispatch.ts +9 -9
- package/packages/bundled-features/src/audit/changes.json +12 -0
- package/packages/bundled-features/src/audit/handlers/audit-events.ts +1 -1
- package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +2 -2
- package/packages/bundled-features/src/auth-mfa/feature.ts +6 -0
- package/packages/bundled-features/src/auth-mfa/web/i18n.ts +6 -1
- package/packages/bundled-features/src/auth-mfa/web/mfa-code-or-recovery-field.tsx +68 -0
- package/packages/bundled-features/src/auth-mfa/web/mfa-disable-dialog.tsx +23 -13
- package/packages/bundled-features/src/auth-mfa/web/mfa-regenerate-recovery-dialog.tsx +23 -13
- package/packages/bundled-features/src/auth-mfa/web/mfa-setup-preauth-screen.tsx +15 -6
- package/packages/bundled-features/src/auth-mfa/web/mfa-verify-screen.tsx +65 -18
- package/packages/bundled-features/src/billing-foundation/changes.json +55 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +32 -42
- package/packages/bundled-features/src/billing-foundation/consumer-protection/confirmation-mail.ts +8 -2
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/issue-confirmation.ts +14 -3
- package/packages/bundled-features/src/billing-foundation/consumer-protection/mail-notifications.ts +3 -4
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-receipt-limit.ts +12 -6
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts +35 -19
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-request.ts +12 -8
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts +14 -8
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-texts.ts +5 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/withdrawal-period.ts +8 -10
- package/packages/bundled-features/src/billing-foundation/events.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/feature.ts +3 -1
- package/packages/bundled-features/src/billing-foundation/handlers/billing-plans.query.ts +71 -6
- package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/handlers/plan-switch-preview.query.ts +65 -0
- package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +9 -2
- package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +44 -8
- package/packages/bundled-features/src/billing-foundation/handlers/switch-plan.write.ts +72 -82
- package/packages/bundled-features/src/billing-foundation/handlers/sync-subscription.write.ts +14 -1
- package/packages/bundled-features/src/billing-foundation/i18n.ts +22 -0
- package/packages/bundled-features/src/billing-foundation/index.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/plan-catalog.ts +62 -27
- package/packages/bundled-features/src/billing-foundation/plan-switch.ts +84 -0
- package/packages/bundled-features/src/billing-foundation/types.ts +80 -1
- package/packages/bundled-features/src/billing-foundation/validate-options.ts +19 -0
- package/packages/bundled-features/src/billing-foundation/web/billing-plans-panel.tsx +119 -47
- package/packages/bundled-features/src/billing-foundation/web/checkout-consent-dialog.tsx +89 -42
- package/packages/bundled-features/src/billing-foundation/web/constants.ts +4 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +55 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-switch-confirm-dialog.tsx +224 -0
- package/packages/bundled-features/src/cap-counter/cap-reservation.ts +5 -1
- package/packages/bundled-features/src/cap-counter/changes.json +18 -0
- package/packages/bundled-features/src/cap-counter/enforce-cap.ts +2 -1
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +8 -1
- package/packages/bundled-features/src/channel-email/changes.json +6 -0
- package/packages/bundled-features/src/channel-email/feature.ts +1 -1
- package/packages/bundled-features/src/config/changes.json +12 -0
- package/packages/bundled-features/src/config/handlers/cascade.query.ts +4 -2
- package/packages/bundled-features/src/config/handlers/values.query.ts +4 -2
- package/packages/bundled-features/src/config/write-helpers.ts +27 -8
- package/packages/bundled-features/src/crypto-shredding/changes.json +6 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +10 -9
- package/packages/bundled-features/src/delivery/changes.json +30 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +9 -3
- package/packages/bundled-features/src/delivery/db/queries/preferences.ts +2 -2
- package/packages/bundled-features/src/delivery/delivery-service.ts +35 -5
- package/packages/bundled-features/src/delivery/handlers/preferences.query.ts +20 -1
- package/packages/bundled-features/src/delivery/handlers/unsubscribe-page-chrome.query.ts +1 -1
- package/packages/bundled-features/src/delivery/unsubscribe-link.ts +3 -1
- package/packages/bundled-features/src/delivery/unsubscribe-page-strings.ts +1 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +6 -0
- package/packages/bundled-features/src/delivery/unsubscribe.ts +36 -15
- package/packages/bundled-features/src/file-foundation/index.ts +1 -0
- package/packages/bundled-features/src/file-foundation/read-file-ref-content.ts +7 -1
- package/packages/bundled-features/src/file-provider-s3/env-named-feature.ts +0 -2
- package/packages/bundled-features/src/files/README.md +1 -1
- package/packages/bundled-features/src/form-draft/changes.json +6 -0
- package/packages/bundled-features/src/form-draft/db/queries/cleanup.ts +2 -2
- package/packages/bundled-features/src/form-draft/decrypt-draft.ts +4 -1
- package/packages/bundled-features/src/host-routing/README.md +1 -1
- package/packages/bundled-features/src/host-routing/changes.json +6 -0
- package/packages/bundled-features/src/host-routing/dispatch.ts +16 -17
- package/packages/bundled-features/src/host-routing/options.ts +2 -1
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +18 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/update-account.write.ts +17 -5
- package/packages/bundled-features/src/inbound-mail-foundation/i18n.ts +0 -1
- package/packages/bundled-features/src/inbound-mail-foundation/screens.ts +0 -3
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +4 -3
- package/packages/bundled-features/src/inbound-mail-foundation/watch-supervisor.ts +32 -16
- package/packages/bundled-features/src/jobs/changes.json +13 -0
- package/packages/bundled-features/src/jobs/feature.ts +14 -4
- package/packages/bundled-features/src/jobs/handlers/tenant-failures.query.ts +45 -40
- package/packages/bundled-features/src/jobs/handlers/tenant-runs.query.ts +63 -59
- package/packages/bundled-features/src/jobs/job-run-logger.ts +5 -4
- package/packages/bundled-features/src/legal-pages/README.md +1 -1
- package/packages/bundled-features/src/mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/mail-foundation/feature.ts +5 -3
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +4 -1
- package/packages/bundled-features/src/renderer-pdf/changes.json +6 -0
- package/packages/bundled-features/src/renderer-pdf/render-table-pdf.ts +27 -10
- package/packages/bundled-features/src/sessions/feature.ts +7 -2
- package/packages/bundled-features/src/shared/decrypt-stored-pii.ts +10 -0
- package/packages/bundled-features/src/shared/index.ts +1 -1
- package/packages/bundled-features/src/shared/mail-template-body.ts +10 -3
- package/packages/bundled-features/src/step-dispatcher/changes.json +6 -0
- package/packages/bundled-features/src/step-dispatcher/feature.ts +1 -0
- package/packages/bundled-features/src/subscription-dodo/changes.json +14 -0
- package/packages/bundled-features/src/subscription-dodo/client.ts +45 -0
- package/packages/bundled-features/src/subscription-dodo/constants.ts +24 -0
- package/packages/bundled-features/src/subscription-dodo/feature.ts +207 -0
- package/packages/bundled-features/src/subscription-dodo/index.ts +16 -0
- package/packages/bundled-features/src/subscription-dodo/plugin-methods.ts +345 -0
- package/packages/bundled-features/src/subscription-dodo/runtime.ts +126 -0
- package/packages/bundled-features/src/subscription-dodo/verify-webhook.ts +262 -0
- package/packages/bundled-features/src/subscription-stripe/changes.json +12 -0
- package/packages/bundled-features/src/subscription-stripe/feature.ts +1 -0
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +7 -6
- package/packages/bundled-features/src/template-resolver/api.ts +31 -4
- package/packages/bundled-features/src/template-resolver/changes.json +48 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +1 -0
- package/packages/bundled-features/src/template-resolver/feature.ts +2 -2
- package/packages/bundled-features/src/template-resolver/handlers/bundle-import.ts +3 -2
- package/packages/bundled-features/src/template-resolver/handlers/copy-locale.write.ts +27 -5
- package/packages/bundled-features/src/template-resolver/handlers/diff-to-system.query.ts +3 -2
- package/packages/bundled-features/src/template-resolver/handlers/document-base.ts +3 -2
- package/packages/bundled-features/src/template-resolver/handlers/find-by-id.query.ts +3 -2
- package/packages/bundled-features/src/template-resolver/handlers/list.query.ts +18 -19
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +15 -5
- package/packages/bundled-features/src/template-resolver/handlers/tenant-override-counts.query.ts +9 -5
- package/packages/bundled-features/src/template-resolver/handlers/tenant-override-selection.ts +8 -6
- package/packages/bundled-features/src/template-resolver/handlers/tenant-overrides.query.ts +44 -5
- package/packages/bundled-features/src/template-resolver/handlers/usage.query.ts +37 -26
- package/packages/bundled-features/src/template-resolver/handlers/validate.query.ts +7 -2
- package/packages/bundled-features/src/template-resolver/seeding.ts +32 -14
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +22 -4
- package/packages/bundled-features/src/template-resolver/template-delivery-policy.ts +0 -11
- package/packages/bundled-features/src/template-resolver/template-meta.ts +12 -4
- package/packages/bundled-features/src/template-resolver/template-preview.ts +11 -3
- package/packages/bundled-features/src/template-resolver/web/constants.ts +7 -5
- package/packages/bundled-features/src/template-resolver/web/index.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/mail-layout-constants.ts +8 -0
- package/packages/bundled-features/src/tenant/changes.json +6 -0
- package/packages/bundled-features/src/tenant/handlers/member-directory.query.ts +9 -3
- package/packages/bundled-features/src/tenant/handlers/tenant-directory.query.ts +7 -4
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +5 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +5 -1
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/handlers/set-tenant-tier.write.ts +4 -1
- package/packages/bundled-features/src/tier-engine/web/constants.ts +3 -3
- package/packages/bundled-features/src/user-data-rights/run-export-jobs.ts +3 -4
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -1
- package/packages/bundled-features/src/waitlist/changes.json +18 -0
- package/packages/bundled-features/src/waitlist/handlers/export-purge.write.ts +2 -1
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +5 -5
- package/packages/bundled-features/src/waitlist/import.ts +5 -0
- package/packages/bundled-features/src/waitlist/legacy-migrate.ts +22 -3
- package/packages/bundled-features/src/waitlist/link-on-signup.ts +20 -10
- package/packages/bundled-features/src/waitlist/options.ts +3 -0
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +11 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +24 -0
- package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-constants.ts +5 -0
- package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-features.ts +90 -15
- package/samples/apps/use-all-bundled/e2e-billing-gallery/server.ts +16 -6
- package/samples/apps/use-all-bundled/feature-manifest.json +120 -3
- package/samples/apps/use-all-bundled/src/run-config.ts +9 -3
- package/samples/recipes/auth-mfa/README.md +5 -0
- package/samples/recipes/auth-mfa/package.json +5 -2
- package/samples/recipes/auth-mfa/src/web/confirmation-code-step.tsx +49 -0
- package/samples/recipes/auth-mfa/tsconfig.json +8 -0
- package/samples/recipes/env-composition/README.md +3 -1
- package/samples/recipes/env-composition/src/env.ts +2 -0
- package/samples/recipes/legal-pages/README.md +1 -1
- package/samples/recipes/rate-limiting/README.md +18 -0
- package/samples/recipes/rate-limiting/src/feature.ts +12 -0
- package/packages/bundled-features/src/billing-foundation/consumer-protection/stored-user-email.ts +0 -12
|
@@ -7,10 +7,13 @@ import type { PdfPageFormat } from "../template-resolver/index.ts";
|
|
|
7
7
|
const PDF_TABLE_MAX_ROWS = 10_000;
|
|
8
8
|
const PDF_TABLE_MAX_COLUMNS = 30;
|
|
9
9
|
const PDF_TABLE_MAX_CELL_LENGTH = 5_000;
|
|
10
|
+
const PDF_TABLE_MAX_META_ENTRIES = 500;
|
|
11
|
+
const PDF_TABLE_MAX_TEXT_LENGTH = 20_000;
|
|
12
|
+
const PDF_TABLE_MAX_PAGE_LABEL_LENGTH = 100;
|
|
10
13
|
|
|
11
14
|
const pdfTableColumnSchema = z
|
|
12
15
|
.object({
|
|
13
|
-
header: z.string(),
|
|
16
|
+
header: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH),
|
|
14
17
|
weight: z.number().positive().optional(),
|
|
15
18
|
align: z.enum(["left", "right"]).optional(),
|
|
16
19
|
})
|
|
@@ -18,10 +21,18 @@ const pdfTableColumnSchema = z
|
|
|
18
21
|
|
|
19
22
|
export const pdfTableDocumentSchema = z
|
|
20
23
|
.object({
|
|
21
|
-
title: z.string(),
|
|
22
|
-
subtitle: z.string().optional(),
|
|
24
|
+
title: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH),
|
|
25
|
+
subtitle: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH).optional(),
|
|
23
26
|
meta: z
|
|
24
|
-
.array(
|
|
27
|
+
.array(
|
|
28
|
+
z
|
|
29
|
+
.object({
|
|
30
|
+
label: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH),
|
|
31
|
+
value: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH),
|
|
32
|
+
})
|
|
33
|
+
.readonly(),
|
|
34
|
+
)
|
|
35
|
+
.max(PDF_TABLE_MAX_META_ENTRIES)
|
|
25
36
|
.readonly()
|
|
26
37
|
.optional(),
|
|
27
38
|
columns: z.array(pdfTableColumnSchema).min(1).max(PDF_TABLE_MAX_COLUMNS).readonly(),
|
|
@@ -29,10 +40,10 @@ export const pdfTableDocumentSchema = z
|
|
|
29
40
|
.array(z.array(z.string().max(PDF_TABLE_MAX_CELL_LENGTH)).readonly())
|
|
30
41
|
.max(PDF_TABLE_MAX_ROWS)
|
|
31
42
|
.readonly(),
|
|
32
|
-
emptyText: z.string().optional(),
|
|
33
|
-
footerText: z.string().optional(),
|
|
43
|
+
emptyText: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH).optional(),
|
|
44
|
+
footerText: z.string().max(PDF_TABLE_MAX_TEXT_LENGTH).optional(),
|
|
34
45
|
// Template with `{page}` and `{pages}`; default `"{page} / {pages}"`.
|
|
35
|
-
pageLabel: z.string().optional(),
|
|
46
|
+
pageLabel: z.string().max(PDF_TABLE_MAX_PAGE_LABEL_LENGTH).optional(),
|
|
36
47
|
})
|
|
37
48
|
.readonly();
|
|
38
49
|
|
|
@@ -235,12 +246,18 @@ function resolveTableLayout(
|
|
|
235
246
|
}
|
|
236
247
|
|
|
237
248
|
export async function renderTablePdf(
|
|
238
|
-
|
|
249
|
+
untrustedDoc: PdfTableDocument,
|
|
239
250
|
options?: PdfTableOptions,
|
|
240
251
|
): Promise<PdfTableResult> {
|
|
241
|
-
|
|
242
|
-
|
|
252
|
+
// Direct callers bypass renderTablePdfRequest, so the size caps are enforced here too.
|
|
253
|
+
const parsed = pdfTableDocumentSchema.safeParse(untrustedDoc);
|
|
254
|
+
if (!parsed.success) {
|
|
255
|
+
throw new RendererError(
|
|
256
|
+
`table document is invalid: ${parsed.error.message}`,
|
|
257
|
+
"invalid_payload",
|
|
258
|
+
);
|
|
243
259
|
}
|
|
260
|
+
const doc = parsed.data;
|
|
244
261
|
assertRowShape(doc);
|
|
245
262
|
|
|
246
263
|
const pdf = await PDFDocument.create({ updateMetadata: false });
|
|
@@ -59,8 +59,10 @@ export type SessionsFeatureOptions = {
|
|
|
59
59
|
readonly adminAccess?: "admin" | "systemAdmin";
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// The returned unbind only clears the binding while it is still this revoker, so a stack that
|
|
63
|
+
// stops later cannot unbind a newer stack sharing the same feature instance.
|
|
64
|
+
export type BindAutoRevokeOnPasswordChange = (revoker: SessionMassRevoker) => () => void;
|
|
65
|
+
export type BindRevokeAllOtherSessions = (revoker: SessionAllOthersRevoker) => () => void;
|
|
64
66
|
|
|
65
67
|
// Reads the late-bind setter off a mounted sessions feature's exports.
|
|
66
68
|
// run{Prod,Dev}App call it once the DB connection is concrete — the feature
|
|
@@ -236,6 +238,9 @@ export function createSessionsFeature(options?: SessionsFeatureOptions): Feature
|
|
|
236
238
|
|
|
237
239
|
const bindAutoRevokeOnPasswordChange: BindAutoRevokeOnPasswordChange = (revoker) => {
|
|
238
240
|
boundAutoRevoke = revoker;
|
|
241
|
+
return () => {
|
|
242
|
+
if (boundAutoRevoke === revoker) boundAutoRevoke = undefined;
|
|
243
|
+
};
|
|
239
244
|
};
|
|
240
245
|
|
|
241
246
|
r.translations({ keys: SESSIONS_I18N });
|
|
@@ -2,6 +2,7 @@ import { requestContext } from "@cosmicdrift/kumiko-framework/api";
|
|
|
2
2
|
import {
|
|
3
3
|
configuredPiiSubjectKms,
|
|
4
4
|
decryptPiiFieldValues,
|
|
5
|
+
PII_ERASED_SENTINEL,
|
|
5
6
|
} from "@cosmicdrift/kumiko-framework/crypto";
|
|
6
7
|
|
|
7
8
|
// Raw reads (fetchOne/selectMany) return the stored column value — with an
|
|
@@ -24,3 +25,12 @@ export async function decryptStoredPii(
|
|
|
24
25
|
const decrypted = out[field];
|
|
25
26
|
return typeof decrypted === "string" ? decrypted : value;
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
// Null for an erased subject: the sentinel must never be mailed or shown as an address.
|
|
30
|
+
export async function decryptStoredUserEmail(
|
|
31
|
+
stored: string,
|
|
32
|
+
fallbackRequestId: string,
|
|
33
|
+
): Promise<string | null> {
|
|
34
|
+
const email = await decryptStoredPii(stored, "email", fallbackRequestId);
|
|
35
|
+
return email === PII_ERASED_SENTINEL ? null : email;
|
|
36
|
+
}
|
|
@@ -15,7 +15,7 @@ export {
|
|
|
15
15
|
classifyStoredEnvelope,
|
|
16
16
|
type StoredEnvelopeClassification,
|
|
17
17
|
} from "./classify-stored-envelope.ts";
|
|
18
|
-
export { decryptStoredPii } from "./decrypt-stored-pii.ts";
|
|
18
|
+
export { decryptStoredPii, decryptStoredUserEmail } from "./decrypt-stored-pii.ts";
|
|
19
19
|
export { encryptForDirectWrite } from "./encrypt-for-direct-write.ts";
|
|
20
20
|
export { entitiesOf } from "./entities-of.ts";
|
|
21
21
|
export { isWithinGracePeriod } from "./grace-period.ts";
|
|
@@ -11,8 +11,14 @@ export function mailTextWithSlotsHtml(text: string): string {
|
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type MailParagraphOptions = { readonly showIf?: string };
|
|
15
|
+
|
|
16
|
+
function paragraphOpenTag(options: MailParagraphOptions | undefined): string {
|
|
17
|
+
return options?.showIf === undefined ? "<p>" : `<p data-if="${escapeHtmlAttr(options.showIf)}">`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function mailParagraph(text: string, options?: MailParagraphOptions): string {
|
|
21
|
+
return `${paragraphOpenTag(options)}${mailTextWithSlotsHtml(text)}</p>`;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export function mailHeading(text: string): string {
|
|
@@ -27,8 +33,9 @@ export function mailParagraphWithLink(
|
|
|
27
33
|
text: string,
|
|
28
34
|
linkLabel: string,
|
|
29
35
|
linkVariable: string,
|
|
36
|
+
options?: MailParagraphOptions,
|
|
30
37
|
): string {
|
|
31
|
-
return
|
|
38
|
+
return `${paragraphOpenTag(options)}${mailTextWithSlotsHtml(text)} <a href="{{${escapeHtmlAttr(linkVariable)}}}">${escapeHtml(linkLabel)}</a></p>`;
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
// One table row per list entry; the cell shows the entry's `field`.
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.388.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Deliver job validates its payload at the trigger",
|
|
6
|
+
"detail": "The deliver job now declares its payload schema, so a manual trigger with an invalid payload is rejected up front instead of throwing inside the handler and consuming all retries."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.365.1",
|
|
4
10
|
"type": "fix",
|
|
@@ -75,6 +75,7 @@ export function createStepDispatcherFeature(): FeatureDefinition {
|
|
|
75
75
|
retries: DELIVER_RETRIES,
|
|
76
76
|
backoff: "exponential",
|
|
77
77
|
maxPerTenant: { limit: DELIVER_MAX_PER_TENANT, onLimit: "defer" },
|
|
78
|
+
schema: deliverJobPayloadSchema,
|
|
78
79
|
escapeHatch: { reason: DELIVER_ESCAPE_HATCH_REASON },
|
|
79
80
|
},
|
|
80
81
|
async (payload, ctx) => {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.388.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "New subscription provider for Dodo Payments",
|
|
6
|
+
"detail": "createSubscriptionDodoFeature() registers the \"dodo\" subscription provider (Merchant of Record). It verifies Standard Webhooks signatures, maps Dodo events to the foundation events, creates hosted checkouts and portal sessions, and switches plans in the app through previewPlanSwitch and applyPlanSwitch. Config keys are api-key, webhook-secret, billing-live and environment. Plan switches need a Product Collection in Dodo."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.388.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "dodoEnvSchema declares the Dodo product id slots",
|
|
12
|
+
"detail": "dodoEnvSchema({ prices: [\"PRO\"] }) adds one optional DODO_PRODUCT_PRO slot per plan next to the API key and webhook key, and checks the pdt_ prefix. It is the counterpart to stripeEnvSchema."
|
|
13
|
+
}
|
|
14
|
+
]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Thin JSON-over-fetch client for the Dodo Payments REST API. All traffic goes
|
|
2
|
+
// through the injected `send`, which defaults to the SSRF-safe egress in
|
|
3
|
+
// feature.ts and is replaced by a mock in tests.
|
|
4
|
+
|
|
5
|
+
import { parseJsonOrThrow } from "@cosmicdrift/kumiko-framework/utils";
|
|
6
|
+
|
|
7
|
+
export type DodoSend = (url: string, init?: RequestInit) => Promise<Response>;
|
|
8
|
+
|
|
9
|
+
export type DodoRequest = {
|
|
10
|
+
readonly method: "GET" | "POST" | "PATCH";
|
|
11
|
+
/** Path segments interpolated into it must already be encodeURIComponent'ed. */
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly query?: Readonly<Record<string, string>>;
|
|
14
|
+
readonly body?: unknown;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type DodoTarget = { readonly baseUrl: string; readonly apiKey: string };
|
|
18
|
+
|
|
19
|
+
// Never carries the response body or the key: both can hold customer data or secrets.
|
|
20
|
+
export class DodoHttpError extends Error {
|
|
21
|
+
readonly status: number;
|
|
22
|
+
constructor(request: DodoRequest, status: number) {
|
|
23
|
+
super(`subscription-dodo: ${request.method} ${request.path} failed with status ${status}`);
|
|
24
|
+
this.name = "DodoHttpError";
|
|
25
|
+
this.status = status;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createDodoHttp(send: DodoSend) {
|
|
30
|
+
return async (target: DodoTarget, request: DodoRequest): Promise<unknown> => {
|
|
31
|
+
const query = request.query ? `?${new URLSearchParams(request.query).toString()}` : "";
|
|
32
|
+
const response = await send(`${target.baseUrl}${request.path}${query}`, {
|
|
33
|
+
method: request.method,
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: `Bearer ${target.apiKey}`,
|
|
36
|
+
Accept: "application/json",
|
|
37
|
+
...(request.body !== undefined && { "Content-Type": "application/json" }),
|
|
38
|
+
},
|
|
39
|
+
...(request.body !== undefined && { body: JSON.stringify(request.body) }),
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) throw new DodoHttpError(request, response.status);
|
|
42
|
+
const text = await response.text();
|
|
43
|
+
return text.length === 0 ? null : parseJsonOrThrow<unknown>(text, "subscription-dodo response");
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const SUBSCRIPTION_DODO_FEATURE = "subscription-dodo" as const;
|
|
2
|
+
|
|
3
|
+
// Must match the path segment in the webhook URL `/api/subscription/webhook/dodo`.
|
|
4
|
+
export const DODO_PROVIDER_NAME = "dodo" as const;
|
|
5
|
+
|
|
6
|
+
// Config-key short-names, qualified to `subscription-dodo:config:<name>` at
|
|
7
|
+
// registry-build. api-key + webhook-secret are backing:"secrets".
|
|
8
|
+
export const DODO_API_KEY_CONFIG = "api-key" as const;
|
|
9
|
+
export const DODO_WEBHOOK_SECRET_CONFIG = "webhook-secret" as const;
|
|
10
|
+
export const DODO_BILLING_LIVE_CONFIG = "billingLive" as const;
|
|
11
|
+
export const DODO_ENVIRONMENT_CONFIG = "environment" as const;
|
|
12
|
+
|
|
13
|
+
// Separate from billingLive on purpose: staging runs Dodo's test API with
|
|
14
|
+
// billingLive on, production flips both.
|
|
15
|
+
export const DodoEnvironments = {
|
|
16
|
+
test: "test",
|
|
17
|
+
live: "live",
|
|
18
|
+
} as const;
|
|
19
|
+
export type DodoEnvironment = (typeof DodoEnvironments)[keyof typeof DodoEnvironments];
|
|
20
|
+
|
|
21
|
+
export const DODO_BASE_URLS: Readonly<Record<DodoEnvironment, string>> = {
|
|
22
|
+
test: "https://test.dodopayments.com",
|
|
23
|
+
live: "https://live.dodopayments.com",
|
|
24
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// kumiko-feature-version: 1
|
|
2
|
+
//
|
|
3
|
+
// subscription-dodo — Dodo Payments (merchant of record) plugin for the
|
|
4
|
+
// billing-foundation plugin API. Credentials, the billing-live master switch and
|
|
5
|
+
// the API environment (test | live) are config keys resolved at call time, like
|
|
6
|
+
// subscription-stripe. `apiKey` / `webhookSecret` options are env→secrets bridge
|
|
7
|
+
// fallbacks.
|
|
8
|
+
|
|
9
|
+
import type { SubscriptionProviderPlugin } from "@cosmicdrift/kumiko-bundled-features/billing-foundation";
|
|
10
|
+
import {
|
|
11
|
+
access,
|
|
12
|
+
createSystemConfig,
|
|
13
|
+
defineFeature,
|
|
14
|
+
type FeatureDefinition,
|
|
15
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
16
|
+
import { type FeatureWithEnvSchema, featureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
|
|
17
|
+
import { egress } from "@cosmicdrift/kumiko-framework/http";
|
|
18
|
+
import * as z from "zod";
|
|
19
|
+
import type { DodoSend } from "./client.ts";
|
|
20
|
+
import {
|
|
21
|
+
DODO_API_KEY_CONFIG,
|
|
22
|
+
DODO_BILLING_LIVE_CONFIG,
|
|
23
|
+
DODO_ENVIRONMENT_CONFIG,
|
|
24
|
+
DODO_PROVIDER_NAME,
|
|
25
|
+
DODO_WEBHOOK_SECRET_CONFIG,
|
|
26
|
+
DodoEnvironments,
|
|
27
|
+
SUBSCRIPTION_DODO_FEATURE,
|
|
28
|
+
} from "./constants.ts";
|
|
29
|
+
import {
|
|
30
|
+
createDodoApplyPlanSwitch,
|
|
31
|
+
createDodoCancelSubscription,
|
|
32
|
+
createDodoCheckoutSession,
|
|
33
|
+
createDodoPortalSession,
|
|
34
|
+
createDodoPreviewPlanSwitch,
|
|
35
|
+
createDodoPriceCache,
|
|
36
|
+
createDodoResumeSubscription,
|
|
37
|
+
createDodoRetrievePrices,
|
|
38
|
+
createDodoRetrieveSubscription,
|
|
39
|
+
} from "./plugin-methods.ts";
|
|
40
|
+
import { createDodoRuntimes } from "./runtime.ts";
|
|
41
|
+
import { verifyAndParseDodoWebhook } from "./verify-webhook.ts";
|
|
42
|
+
|
|
43
|
+
/** Bridge contract: both fields are optional fallbacks for the secrets store. */
|
|
44
|
+
export const subscriptionDodoEnvSchema = z.object({
|
|
45
|
+
DODO_PAYMENTS_API_KEY: z
|
|
46
|
+
.string()
|
|
47
|
+
.min(1)
|
|
48
|
+
.describe("Dodo Payments API key. Bridge-fallback — prefer the secret.")
|
|
49
|
+
.meta({ kumiko: { pulumi: { secret: true } } })
|
|
50
|
+
.optional(),
|
|
51
|
+
DODO_PAYMENTS_WEBHOOK_KEY: z
|
|
52
|
+
.string()
|
|
53
|
+
.min(1)
|
|
54
|
+
.describe(
|
|
55
|
+
"Dodo Payments webhook signing key (`whsec_...`). Bridge-fallback — prefer the secret.",
|
|
56
|
+
)
|
|
57
|
+
.meta({ kumiko: { pulumi: { secret: true } } })
|
|
58
|
+
.optional(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
type DodoProductEnvShape<TPrice extends string> = {
|
|
62
|
+
[Key in `DODO_PRODUCT_${TPrice}`]: z.ZodOptional<z.ZodString>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Dodo env block plus one `DODO_PRODUCT_<NAME>` slot per plan product the app
|
|
66
|
+
* maps to a tier, e.g. `dodoEnvSchema({ prices: ["PRO", "TEAM"] })`.
|
|
67
|
+
* Shares its bridge fields with `subscriptionDodoEnvSchema`, so spreading
|
|
68
|
+
* it into `composeEnvSchema({ extend })` next to the mounted feature is no
|
|
69
|
+
* key clash. */
|
|
70
|
+
export function dodoEnvSchema<const TPrice extends string>(options: {
|
|
71
|
+
readonly prices: readonly TPrice[];
|
|
72
|
+
}) {
|
|
73
|
+
const productShape = Object.fromEntries(
|
|
74
|
+
options.prices.map((price) => [
|
|
75
|
+
`DODO_PRODUCT_${price}`,
|
|
76
|
+
z
|
|
77
|
+
.string()
|
|
78
|
+
.regex(/^pdt_/, `DODO_PRODUCT_${price} must start with 'pdt_'`)
|
|
79
|
+
.optional()
|
|
80
|
+
.describe(`Dodo Payments product id (\`pdt_...\`) of the ${price} plan.`),
|
|
81
|
+
]),
|
|
82
|
+
// @cast-boundary schema-walk — Object.fromEntries widens to an index signature; the entries are exactly one optional string per listed price.
|
|
83
|
+
) as DodoProductEnvShape<TPrice>;
|
|
84
|
+
return z.object({ ...subscriptionDodoEnvSchema.shape, ...productShape });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type SubscriptionDodoOptions = {
|
|
88
|
+
/** Bridge-fallback API key; the `api-key` config key wins when set. */
|
|
89
|
+
readonly apiKey?: string;
|
|
90
|
+
/** Bridge-fallback webhook secret; the `webhook-secret` config key wins when set. */
|
|
91
|
+
readonly webhookSecret?: string;
|
|
92
|
+
/** Dodo product id → app tier name. Products absent here drop the event. */
|
|
93
|
+
readonly priceToTier?: Readonly<Record<string, string>>;
|
|
94
|
+
/** Product ids a mode:"payment" checkout may target; empty = one-off checkouts closed. */
|
|
95
|
+
readonly oneOffPriceIds?: readonly string[];
|
|
96
|
+
/** HTTP transport; defaults to the SSRF-safe external egress. Test seam. */
|
|
97
|
+
readonly send?: DodoSend;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// Validated once at feature-build time so a typo fails app startup instead of
|
|
101
|
+
// silently widening or narrowing the one-off allowlist at request time.
|
|
102
|
+
function validateOneOffPriceIds(priceIds: readonly string[]): void {
|
|
103
|
+
const seen = new Set<string>();
|
|
104
|
+
for (const priceId of priceIds) {
|
|
105
|
+
if (priceId.length === 0) {
|
|
106
|
+
throw new Error("subscription-dodo: oneOffPriceIds must not contain an empty string");
|
|
107
|
+
}
|
|
108
|
+
if (seen.has(priceId)) {
|
|
109
|
+
throw new Error(`subscription-dodo: duplicate oneOffPriceIds entry "${priceId}"`);
|
|
110
|
+
}
|
|
111
|
+
seen.add(priceId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function createSubscriptionDodoFeature(
|
|
116
|
+
options: SubscriptionDodoOptions = {},
|
|
117
|
+
): FeatureWithEnvSchema<FeatureDefinition, typeof subscriptionDodoEnvSchema.shape> {
|
|
118
|
+
validateOneOffPriceIds(options.oneOffPriceIds ?? []);
|
|
119
|
+
const feature: FeatureDefinition = defineFeature(SUBSCRIPTION_DODO_FEATURE, (r) => {
|
|
120
|
+
r.describe(
|
|
121
|
+
'Dodo Payments provider plugin for `billing-foundation`. Dodo acts as merchant of record: it sells to the customer and issues invoice and VAT, so the consumer-protection texts for this provider come from `consumerProtection.providerTexts`. Reads its API key and webhook secret from system config keys with `backing:"secrets"` (envelope-encrypted in the secrets store under the system tenant), plus a `billingLive` master switch and an `environment` key (test | live). `environment` is its own key because Dodo serves test and live mode from different API hosts and a live key must never hit the test host or the other way round; `billingLive` only decides whether checkouts are offered at all. All four are runtime config, so keys rotate and prod goes live without a redeploy, and the `mask` on each derives the sysadmin settings screen and nav. Mount via `createSubscriptionDodoFeature({ priceToTier })`; the optional `apiKey`/`webhookSecret` options are env to secrets bridge fallbacks (`DODO_PAYMENTS_API_KEY`, `DODO_PAYMENTS_WEBHOOK_KEY`). The plugin always mounts; `createCheckoutSession` throws `feature_disabled` unless `billingLive` is true. Webhooks arrive at `/api/subscription/webhook/dodo` and are verified per the Standard Webhooks spec (HMAC-SHA256 over id, timestamp and the raw body, 5 minute tolerance); events for products outside `priceToTier` or without tenant metadata are dropped. Implements hosted checkout, customer portal, cancel and resume, `retrievePrices` (10-minute TTL cache), `retrieveSubscription` for the sync job, and an in-app plan switch: `previewPlanSwitch` shows the proration before the customer confirms, `applyPlanSwitch` changes the plan without a hosted page and waits for the `plan_changed` webhook to move the tier. A plan switch in Dodo requires all plan products to belong to one Product Collection.',
|
|
122
|
+
);
|
|
123
|
+
r.uiHints({
|
|
124
|
+
displayLabel: "Billing · Dodo Payments",
|
|
125
|
+
category: "billing",
|
|
126
|
+
recommended: false,
|
|
127
|
+
});
|
|
128
|
+
r.requires({ features: ["billing-foundation"] });
|
|
129
|
+
r.requires({ features: ["config"] });
|
|
130
|
+
r.requires({ features: ["secrets"] });
|
|
131
|
+
r.envSchema(subscriptionDodoEnvSchema);
|
|
132
|
+
|
|
133
|
+
const configKeys = r.config({
|
|
134
|
+
keys: {
|
|
135
|
+
[DODO_API_KEY_CONFIG]: createSystemConfig("text", {
|
|
136
|
+
backing: "secrets",
|
|
137
|
+
write: access.systemAdmin,
|
|
138
|
+
read: access.admin,
|
|
139
|
+
mask: { title: "subscription-dodo.api-key", icon: "key", order: 1 },
|
|
140
|
+
}),
|
|
141
|
+
[DODO_WEBHOOK_SECRET_CONFIG]: createSystemConfig("text", {
|
|
142
|
+
backing: "secrets",
|
|
143
|
+
write: access.systemAdmin,
|
|
144
|
+
read: access.admin,
|
|
145
|
+
mask: { title: "subscription-dodo.webhook-secret", icon: "shield", order: 2 },
|
|
146
|
+
}),
|
|
147
|
+
[DODO_ENVIRONMENT_CONFIG]: createSystemConfig("select", {
|
|
148
|
+
default: DodoEnvironments.test,
|
|
149
|
+
options: [DodoEnvironments.test, DodoEnvironments.live],
|
|
150
|
+
write: access.systemAdmin,
|
|
151
|
+
read: access.admin,
|
|
152
|
+
mask: { title: "subscription-dodo.environment", icon: "server", order: 3 },
|
|
153
|
+
}),
|
|
154
|
+
[DODO_BILLING_LIVE_CONFIG]: createSystemConfig("boolean", {
|
|
155
|
+
default: false,
|
|
156
|
+
write: access.privileged,
|
|
157
|
+
read: access.admin,
|
|
158
|
+
mask: { title: "subscription-dodo.billing-live", icon: "rocket", order: 4 },
|
|
159
|
+
}),
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
r.translations({
|
|
164
|
+
keys: {
|
|
165
|
+
"subscription-dodo.api-key": { en: "Dodo Payments API key" },
|
|
166
|
+
"subscription-dodo.webhook-secret": { en: "Dodo Payments webhook secret" },
|
|
167
|
+
"subscription-dodo.environment": { en: "Dodo Payments environment" },
|
|
168
|
+
"subscription-dodo.billing-live": { en: "Live billing" },
|
|
169
|
+
"subscription-dodo.settings": { en: "Dodo Payments" },
|
|
170
|
+
"screen:subscription-dodo-system.title": { en: "Dodo Payments" },
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const priceToTier = options.priceToTier ?? {};
|
|
175
|
+
const runtimes = createDodoRuntimes({
|
|
176
|
+
apiKeyHandle: configKeys[DODO_API_KEY_CONFIG],
|
|
177
|
+
webhookSecretHandle: configKeys[DODO_WEBHOOK_SECRET_CONFIG],
|
|
178
|
+
billingLiveHandle: configKeys[DODO_BILLING_LIVE_CONFIG],
|
|
179
|
+
environmentHandle: configKeys[DODO_ENVIRONMENT_CONFIG],
|
|
180
|
+
send: options.send ?? egress({ kind: "external" }),
|
|
181
|
+
fallback: {
|
|
182
|
+
...(options.apiKey !== undefined && { apiKey: options.apiKey }),
|
|
183
|
+
...(options.webhookSecret !== undefined && { webhookSecret: options.webhookSecret }),
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const plugin: SubscriptionProviderPlugin = {
|
|
188
|
+
displayName: "Dodo Payments",
|
|
189
|
+
verifyAndParseWebhook: verifyAndParseDodoWebhook(runtimes.webhook, { priceToTier }),
|
|
190
|
+
createCheckoutSession: createDodoCheckoutSession(runtimes.ctx),
|
|
191
|
+
createPortalSession: createDodoPortalSession(runtimes.ctx),
|
|
192
|
+
cancelSubscription: createDodoCancelSubscription(runtimes.ctx),
|
|
193
|
+
resumeSubscription: createDodoResumeSubscription(runtimes.ctx),
|
|
194
|
+
priceToTier,
|
|
195
|
+
oneOffPriceIds: options.oneOffPriceIds ?? [],
|
|
196
|
+
isBillingEnabled: runtimes.ctx.isBillingEnabled,
|
|
197
|
+
retrievePrices: createDodoRetrievePrices(runtimes.ctx, createDodoPriceCache()),
|
|
198
|
+
retrieveSubscription: createDodoRetrieveSubscription(runtimes.ctx, { priceToTier }),
|
|
199
|
+
previewPlanSwitch: createDodoPreviewPlanSwitch(runtimes.ctx),
|
|
200
|
+
applyPlanSwitch: createDodoApplyPlanSwitch(runtimes.ctx),
|
|
201
|
+
};
|
|
202
|
+
r.useExtension("subscriptionProvider", DODO_PROVIDER_NAME, plugin);
|
|
203
|
+
|
|
204
|
+
return { configKeys };
|
|
205
|
+
});
|
|
206
|
+
return featureWithEnvSchema(feature, subscriptionDodoEnvSchema);
|
|
207
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Public API of the subscription-dodo bundled feature. The webhook verifier,
|
|
2
|
+
// client and plugin methods are internal to feature.ts.
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
DODO_BASE_URLS,
|
|
6
|
+
DODO_PROVIDER_NAME,
|
|
7
|
+
type DodoEnvironment,
|
|
8
|
+
DodoEnvironments,
|
|
9
|
+
SUBSCRIPTION_DODO_FEATURE,
|
|
10
|
+
} from "./constants.ts";
|
|
11
|
+
export {
|
|
12
|
+
createSubscriptionDodoFeature,
|
|
13
|
+
dodoEnvSchema,
|
|
14
|
+
type SubscriptionDodoOptions,
|
|
15
|
+
subscriptionDodoEnvSchema,
|
|
16
|
+
} from "./feature.ts";
|