@cosmicdrift/kumiko-samples 0.342.0 → 0.344.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/audit/changes.json +6 -0
- package/packages/bundled-features/src/audit/constants.ts +5 -1
- package/packages/bundled-features/src/audit/escape-hatch-audit-sink.ts +1 -0
- package/packages/bundled-features/src/audit/run-escape-hatch-retention.ts +99 -8
- package/packages/bundled-features/src/auth-email-password/changes.json +7 -0
- package/packages/bundled-features/src/auth-email-password/email-templates.ts +76 -16
- package/packages/bundled-features/src/auth-email-password/handlers/invite-create.write.ts +4 -1
- package/packages/bundled-features/src/auth-email-password/handlers/signup-request.write.ts +4 -1
- package/packages/bundled-features/src/auth-email-password/handlers/token-request-handler.ts +3 -0
- package/packages/bundled-features/src/auth-email-password/magic-link-mail.ts +4 -0
- package/packages/bundled-features/src/billing-foundation/changes.json +7 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +35 -7
- package/packages/bundled-features/src/billing-foundation/consumer-protection/confirmation-mail.ts +36 -22
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +12 -2
- package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-locale.ts +1 -1
- package/packages/bundled-features/src/billing-foundation/consumer-protection/issue-confirmation.ts +34 -1
- package/packages/bundled-features/src/billing-foundation/events.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/handlers/billing-plans.query.ts +14 -5
- package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +61 -36
- package/packages/bundled-features/src/billing-foundation/index.ts +11 -0
- package/packages/bundled-features/src/billing-foundation/types.ts +25 -7
- package/packages/bundled-features/src/billing-foundation/validate-options.ts +36 -3
- package/packages/bundled-features/src/billing-foundation/web/billing-plans-panel.tsx +1 -1
- package/packages/bundled-features/src/billing-foundation/web/cancel-contract-dialog.tsx +1 -2
- package/packages/bundled-features/src/billing-foundation/web/checkout-consent-dialog.tsx +16 -6
- package/packages/bundled-features/src/billing-foundation/web/index.ts +12 -0
- package/packages/bundled-features/src/channel-discord/feature.ts +1 -0
- package/packages/bundled-features/src/channel-email/feature.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +1 -0
- package/packages/bundled-features/src/channel-push/feature.ts +1 -0
- package/packages/bundled-features/src/channel-slack/feature.ts +1 -0
- package/packages/bundled-features/src/channel-teams/changes.json +8 -0
- package/packages/bundled-features/src/channel-teams/feature.ts +1 -0
- package/packages/bundled-features/src/channel-teams/teams-channel.ts +16 -0
- package/packages/bundled-features/src/channel-telegram/feature.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +32 -0
- package/packages/bundled-features/src/delivery/chat-webhook-channel.ts +7 -2
- package/packages/bundled-features/src/delivery/chat-webhook-sender.ts +60 -14
- package/packages/bundled-features/src/delivery/constants.ts +4 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +70 -5
- package/packages/bundled-features/src/delivery/events.ts +15 -1
- package/packages/bundled-features/src/delivery/feature.ts +32 -4
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +65 -20
- package/packages/bundled-features/src/delivery/i18n.ts +55 -0
- package/packages/bundled-features/src/delivery/index.ts +2 -0
- package/packages/bundled-features/src/delivery/jobs.ts +43 -20
- package/packages/bundled-features/src/delivery/notify-factory.ts +19 -0
- package/packages/bundled-features/src/delivery/public-names.ts +4 -0
- package/packages/bundled-features/src/delivery/tables.ts +3 -0
- package/packages/bundled-features/src/delivery/testing.ts +5 -9
- package/packages/bundled-features/src/delivery/types.ts +6 -2
- package/packages/bundled-features/src/delivery/web/client-plugin.tsx +16 -1
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +13 -0
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +17 -0
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +10 -3
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +8 -0
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +20 -0
- package/packages/bundled-features/src/jobs/changes.json +6 -0
- package/packages/bundled-features/src/legal-pages/changes.json +6 -0
- package/packages/bundled-features/src/legal-pages/constants.ts +2 -0
- package/packages/bundled-features/src/legal-pages/feature.ts +8 -3
- package/packages/bundled-features/src/renderer-simple/changes.json +6 -0
- package/packages/bundled-features/src/renderer-simple/simple-renderer.ts +10 -0
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/constants.ts +10 -0
- package/packages/bundled-features/src/secrets/feature.ts +4 -0
- package/packages/bundled-features/src/secrets/i18n.ts +5 -3
- package/packages/bundled-features/src/secrets/index.ts +8 -1
- package/packages/bundled-features/src/secrets/write-gate.ts +17 -5
- package/packages/bundled-features/src/shared/index.ts +6 -0
- package/packages/bundled-features/src/shared/redact.ts +27 -0
- package/packages/bundled-features/src/step-dispatcher/feature.ts +2 -6
- package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +0 -6
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +12 -2
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +23 -8
- package/packages/bundled-features/src/user/index.ts +1 -0
- package/packages/bundled-features/src/user/resolve-display-names.ts +35 -0
- package/samples/apps/use-all-bundled/e2e-billing-gallery/gallery-features.ts +10 -11
- package/samples/apps/use-all-bundled/e2e-billing-gallery/server.ts +2 -2
- /package/packages/bundled-features/src/{tenant → shared}/web/translate-or-raw.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-samples",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.344.0",
|
|
4
4
|
"description": "Source trees of the Kumiko sample recipes, sample apps and bundled features in repo layout, for tooling such as few-shot corpus builds.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-bundled-features",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.344.0",
|
|
4
4
|
"description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.343.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "escape-hatch retention follows the tenant compliance profile",
|
|
6
|
+
"detail": "The audit job `escape-hatch-retention` now deletes `escapeHatchUse` events after the `auditLog.retention` of the tenant's compliance profile. A tenant override can only lengthen that period, never go below the base retention of the selected profile. Cross-tenant audits (with `targetTenantId`, e.g. `identity-switch`) additionally follow the profile of the target tenant. The config key `audit:config:escape-hatch-retention-days` is only the fallback when compliance-profiles is not mounted.\n`pruneEvents` gains the optional `aggregateIds` option to restrict the prune to specific aggregates. `@cosmicdrift/kumiko-framework/compliance` exports `subtractRetentionSpec` and the `RetentionSpec` type for calendar-aware cutoffs (months and years)."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.313.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -25,7 +25,11 @@ export const AUDIT_LOG_SCREEN_ID = "audit-log" as const;
|
|
|
25
25
|
/** Single-event detail screen, breadcrumb-linked to the audit-log list. */
|
|
26
26
|
export const AUDIT_LOG_DETAIL_SCREEN_ID = "audit-log-detail" as const;
|
|
27
27
|
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Config key (system scope) for how long `escapeHatchUse` audit events are kept. Only a fallback
|
|
30
|
+
* for apps without compliance-profiles; with it mounted, the tenant profile's `auditLog.retention`
|
|
31
|
+
* applies (a tenant override can only lengthen it).
|
|
32
|
+
*/
|
|
29
33
|
export const ESCAPE_HATCH_RETENTION_DAYS_KEY = "audit:config:escape-hatch-retention-days" as const;
|
|
30
34
|
|
|
31
35
|
export const DEFAULT_ESCAPE_HATCH_RETENTION_DAYS = 90;
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
import { selectMany } from "@cosmicdrift/kumiko-framework/bun-db";
|
|
2
|
+
import {
|
|
3
|
+
COMPLIANCE_PROFILES,
|
|
4
|
+
subtractRetentionSpec,
|
|
5
|
+
} from "@cosmicdrift/kumiko-framework/compliance";
|
|
1
6
|
import type { DbConnection, DbRunner } from "@cosmicdrift/kumiko-framework/db";
|
|
2
7
|
import {
|
|
3
8
|
type ConfigResolver,
|
|
9
|
+
parseTenantId,
|
|
4
10
|
type Registry,
|
|
5
11
|
SYSTEM_TENANT_ID,
|
|
12
|
+
type TenantId,
|
|
6
13
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
7
|
-
import {
|
|
14
|
+
import { eventsTable } from "@cosmicdrift/kumiko-framework/event-store";
|
|
15
|
+
import { pruneEvents } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
16
|
+
import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
|
|
17
|
+
import { resolveProfileForTenant } from "../compliance-profiles/index.js";
|
|
8
18
|
import { createConfigAccessor } from "../config/index.js";
|
|
9
19
|
import {
|
|
10
20
|
DEFAULT_ESCAPE_HATCH_RETENTION_DAYS,
|
|
11
21
|
ESCAPE_HATCH_RETENTION_DAYS_KEY,
|
|
12
22
|
} from "./constants.js";
|
|
13
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
ESCAPE_HATCH_USE_AGGREGATE_TYPE,
|
|
25
|
+
escapeHatchUsedSchema,
|
|
26
|
+
} from "./escape-hatch-audit-sink.js";
|
|
14
27
|
|
|
15
28
|
// pruneEvents opens its own transaction, so a runner that cannot begin one (a tx handle) is rejected instead of nested.
|
|
16
29
|
export function isDbConnection(runner: DbRunner): runner is DbConnection {
|
|
@@ -35,19 +48,97 @@ async function resolveRetentionDays(args: {
|
|
|
35
48
|
return typeof raw === "number" && raw >= 1 ? raw : DEFAULT_ESCAPE_HATCH_RETENTION_DAYS;
|
|
36
49
|
}
|
|
37
50
|
|
|
51
|
+
// Soft dependency: audit must stay mountable without compliance-profiles, so we probe its entity.
|
|
52
|
+
const COMPLIANCE_PROFILE_ENTITY = "tenant-compliance-profile";
|
|
53
|
+
const PRUNE_CHUNK_SIZE = 1000;
|
|
54
|
+
|
|
55
|
+
type AuditEventRow = {
|
|
56
|
+
readonly aggregateId: string;
|
|
57
|
+
readonly tenantId: TenantId;
|
|
58
|
+
readonly createdAt: Temporal.Instant;
|
|
59
|
+
readonly payload: unknown;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Overrides may only lengthen retention: the earlier cutoff (same `now`) is the longer period.
|
|
63
|
+
function earlierInstant(a: Temporal.Instant, b: Temporal.Instant): Temporal.Instant {
|
|
64
|
+
return Temporal.Instant.compare(a, b) <= 0 ? a : b;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function resolveTenantCutoff(
|
|
68
|
+
db: DbConnection,
|
|
69
|
+
tenantId: TenantId,
|
|
70
|
+
now: Temporal.Instant,
|
|
71
|
+
): Promise<Temporal.Instant> {
|
|
72
|
+
const { profile } = await resolveProfileForTenant({ db, tenantId });
|
|
73
|
+
const effective = subtractRetentionSpec(now, profile.auditLog.retention);
|
|
74
|
+
const base = subtractRetentionSpec(now, COMPLIANCE_PROFILES[profile.key].auditLog.retention);
|
|
75
|
+
return earlierInstant(effective, base);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// A cross-tenant audit (e.g. identity-switch) lives under the actor's tenant but must also
|
|
79
|
+
// satisfy the target tenant's retention. A malformed payload falls back to the storing tenant.
|
|
80
|
+
function targetTenantOf(payload: unknown): TenantId | null {
|
|
81
|
+
const parsed = escapeHatchUsedSchema.safeParse(payload);
|
|
82
|
+
return parsed.success ? parseTenantId(parsed.data.targetTenantId) : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function pruneByTenantProfiles(db: DbConnection): Promise<number> {
|
|
86
|
+
const rows = await selectMany<AuditEventRow>(db, eventsTable, {
|
|
87
|
+
aggregateType: ESCAPE_HATCH_USE_AGGREGATE_TYPE,
|
|
88
|
+
});
|
|
89
|
+
const now = getTemporal().Now.instant();
|
|
90
|
+
const cutoffByTenant = new Map<TenantId, Temporal.Instant>();
|
|
91
|
+
const cutoffOf = async (tenantId: TenantId): Promise<Temporal.Instant> => {
|
|
92
|
+
const cached = cutoffByTenant.get(tenantId);
|
|
93
|
+
if (cached) return cached;
|
|
94
|
+
const cutoff = await resolveTenantCutoff(db, tenantId, now);
|
|
95
|
+
cutoffByTenant.set(tenantId, cutoff);
|
|
96
|
+
return cutoff;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const expiredAggregateIds: string[] = [];
|
|
100
|
+
for (const row of rows) {
|
|
101
|
+
const targetTenantId = targetTenantOf(row.payload);
|
|
102
|
+
const storeCutoff = await cutoffOf(row.tenantId);
|
|
103
|
+
const cutoff = targetTenantId
|
|
104
|
+
? earlierInstant(storeCutoff, await cutoffOf(targetTenantId))
|
|
105
|
+
: storeCutoff;
|
|
106
|
+
if (Temporal.Instant.compare(row.createdAt, cutoff) < 0) {
|
|
107
|
+
expiredAggregateIds.push(row.aggregateId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let deletedCount = 0;
|
|
112
|
+
for (let i = 0; i < expiredAggregateIds.length; i += PRUNE_CHUNK_SIZE) {
|
|
113
|
+
const result = await pruneEvents(db, {
|
|
114
|
+
aggregateTypes: [ESCAPE_HATCH_USE_AGGREGATE_TYPE],
|
|
115
|
+
aggregateIds: expiredAggregateIds.slice(i, i + PRUNE_CHUNK_SIZE),
|
|
116
|
+
olderThan: now,
|
|
117
|
+
});
|
|
118
|
+
deletedCount += result.deletedCount;
|
|
119
|
+
}
|
|
120
|
+
return deletedCount;
|
|
121
|
+
}
|
|
122
|
+
|
|
38
123
|
export async function runEscapeHatchRetention(args: {
|
|
39
124
|
readonly db: DbRunner;
|
|
40
125
|
readonly registry: Registry;
|
|
41
126
|
readonly configResolver: ConfigResolver | undefined;
|
|
42
127
|
readonly userId: string;
|
|
43
|
-
}): Promise<
|
|
128
|
+
}): Promise<{ readonly deletedCount: number }> {
|
|
44
129
|
const { db } = args;
|
|
45
130
|
if (!isDbConnection(db)) {
|
|
46
131
|
throw new Error("audit escape-hatch retention: a transaction-free DbConnection is required");
|
|
47
132
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
133
|
+
|
|
134
|
+
if (!args.registry.getEntity(COMPLIANCE_PROFILE_ENTITY)) {
|
|
135
|
+
const olderThanDays = await resolveRetentionDays({ ...args, db });
|
|
136
|
+
const { deletedCount } = await pruneEvents(db, {
|
|
137
|
+
aggregateTypes: [ESCAPE_HATCH_USE_AGGREGATE_TYPE],
|
|
138
|
+
olderThanDays,
|
|
139
|
+
});
|
|
140
|
+
return { deletedCount };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { deletedCount: await pruneByTenantProfiles(db) };
|
|
53
144
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.343.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Mail expiry shows duration and local time with time zone",
|
|
6
|
+
"detail": "Auth mails state the link validity as a duration and in the user's time zone\nThe five token mail renderers replace the UTC timestamp with `{duration}` (for example \"1 day\") and `{when}` (medium date and short time with zone abbreviation, in the recipient's locale). `RenderTokenContentArgs` gains `issuedAt` (default now) and `timeZone` (default UTC; an invalid zone falls back to UTC); the handlers pass the token issue time and `ctx.tz.user`. German strings use \"Konto\" instead of \"Account\".",
|
|
7
|
+
"migration": "Custom `auth.mail.*.expiry` translations should use the new `{duration}` and `{when}` placeholders; `{when}` now includes the time and zone abbreviation instead of a UTC timestamp."
|
|
8
|
+
},
|
|
2
9
|
{
|
|
3
10
|
"version": "0.342.0",
|
|
4
11
|
"type": "improvement",
|
|
@@ -20,21 +20,21 @@ export const AUTH_MAIL_EN: Readonly<Record<string, string>> = {
|
|
|
20
20
|
"auth.mail.reset.intro":
|
|
21
21
|
"you requested a password reset for {app}. Click the link below to set a new password:",
|
|
22
22
|
"auth.mail.reset.button": "Reset password",
|
|
23
|
-
"auth.mail.reset.expiry": "The link
|
|
23
|
+
"auth.mail.reset.expiry": "The link is valid for {duration} (until {when}).",
|
|
24
24
|
"auth.mail.reset.ignore":
|
|
25
25
|
"If you didn't request a reset, you can safely ignore this email — your password won't change.",
|
|
26
26
|
"auth.mail.verify.subject": "{app} — Verify your email",
|
|
27
27
|
"auth.mail.verify.greeting": "Welcome,",
|
|
28
28
|
"auth.mail.verify.intro": "please verify your email address for {app} to activate your account:",
|
|
29
29
|
"auth.mail.verify.button": "Verify email",
|
|
30
|
-
"auth.mail.verify.expiry": "The link
|
|
30
|
+
"auth.mail.verify.expiry": "The link is valid for {duration} (until {when}).",
|
|
31
31
|
"auth.mail.verify.ignore": "If you didn't create this account, you can ignore this email.",
|
|
32
32
|
"auth.mail.activation.subject": "{app} — Activate your account",
|
|
33
33
|
"auth.mail.activation.greeting": "Welcome,",
|
|
34
34
|
"auth.mail.activation.intro":
|
|
35
35
|
"click the link below to activate your {app} account. The next step is choosing your password:",
|
|
36
36
|
"auth.mail.activation.button": "Activate account",
|
|
37
|
-
"auth.mail.activation.expiry": "The link
|
|
37
|
+
"auth.mail.activation.expiry": "The link is valid for {duration} (until {when}).",
|
|
38
38
|
"auth.mail.activation.ignore":
|
|
39
39
|
"If you didn't sign up, you can ignore this email — no account is created until you open the link.",
|
|
40
40
|
"auth.mail.invite.subject": "{app} — Workspace invitation",
|
|
@@ -42,14 +42,14 @@ export const AUTH_MAIL_EN: Readonly<Record<string, string>> = {
|
|
|
42
42
|
"auth.mail.invite.intro":
|
|
43
43
|
"you've been invited to a {app} workspace as {role}. Click the link below to accept:",
|
|
44
44
|
"auth.mail.invite.button": "Accept invitation",
|
|
45
|
-
"auth.mail.invite.expiry": "The link
|
|
45
|
+
"auth.mail.invite.expiry": "The link is valid for {duration} (until {when}).",
|
|
46
46
|
"auth.mail.invite.ignore": "If you weren't expecting this invitation, you can ignore this email.",
|
|
47
47
|
"auth.mail.unlock.subject": "{app} — Unlock your account",
|
|
48
48
|
"auth.mail.unlock.greeting": "Hi,",
|
|
49
49
|
"auth.mail.unlock.intro":
|
|
50
50
|
"your {app} account was temporarily locked after several failed sign-in attempts. Click the link below to unlock it immediately:",
|
|
51
51
|
"auth.mail.unlock.button": "Unlock account",
|
|
52
|
-
"auth.mail.unlock.expiry": "The link
|
|
52
|
+
"auth.mail.unlock.expiry": "The link is valid for {duration} (until {when}).",
|
|
53
53
|
"auth.mail.unlock.ignore":
|
|
54
54
|
"If you didn't trigger this lock, you can ignore this email — the lock expires on its own.",
|
|
55
55
|
};
|
|
@@ -62,6 +62,10 @@ export type RenderTokenContentArgs = {
|
|
|
62
62
|
readonly locale?: AuthMailLocale;
|
|
63
63
|
/** Optional app name for subject + intro. Default from auth.mail.appNameDefault. */
|
|
64
64
|
readonly appName?: string;
|
|
65
|
+
/** ISO instant the token was issued; the validity duration is measured from it. Default: now. */
|
|
66
|
+
readonly issuedAt?: string;
|
|
67
|
+
/** IANA zone the expiry time is shown in. Default "UTC"; an invalid zone falls back to "UTC". */
|
|
68
|
+
readonly timeZone?: string;
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
export type RenderInviteEmailArgs = RenderTokenContentArgs & { readonly role: string };
|
|
@@ -119,7 +123,7 @@ export function renderResetPasswordEmail(args: RenderTokenContentArgs): AuthMail
|
|
|
119
123
|
intro: t(locale, "auth.mail.reset.intro", { app }),
|
|
120
124
|
buttonLabel: t(locale, "auth.mail.reset.button"),
|
|
121
125
|
buttonUrl: args.url,
|
|
122
|
-
expiry: t(locale, "auth.mail.reset.expiry",
|
|
126
|
+
expiry: t(locale, "auth.mail.reset.expiry", expiryParams(args, locale)),
|
|
123
127
|
ignore: t(locale, "auth.mail.reset.ignore"),
|
|
124
128
|
});
|
|
125
129
|
}
|
|
@@ -134,7 +138,7 @@ export function renderUnlockAccountEmail(args: RenderTokenContentArgs): AuthMail
|
|
|
134
138
|
intro: t(locale, "auth.mail.unlock.intro", { app }),
|
|
135
139
|
buttonLabel: t(locale, "auth.mail.unlock.button"),
|
|
136
140
|
buttonUrl: args.url,
|
|
137
|
-
expiry: t(locale, "auth.mail.unlock.expiry",
|
|
141
|
+
expiry: t(locale, "auth.mail.unlock.expiry", expiryParams(args, locale)),
|
|
138
142
|
ignore: t(locale, "auth.mail.unlock.ignore"),
|
|
139
143
|
});
|
|
140
144
|
}
|
|
@@ -149,7 +153,7 @@ export function renderVerifyEmail(args: RenderTokenContentArgs): AuthMailContent
|
|
|
149
153
|
intro: t(locale, "auth.mail.verify.intro", { app }),
|
|
150
154
|
buttonLabel: t(locale, "auth.mail.verify.button"),
|
|
151
155
|
buttonUrl: args.url,
|
|
152
|
-
expiry: t(locale, "auth.mail.verify.expiry",
|
|
156
|
+
expiry: t(locale, "auth.mail.verify.expiry", expiryParams(args, locale)),
|
|
153
157
|
ignore: t(locale, "auth.mail.verify.ignore"),
|
|
154
158
|
});
|
|
155
159
|
}
|
|
@@ -164,7 +168,7 @@ export function renderActivationEmail(args: RenderTokenContentArgs): AuthMailCon
|
|
|
164
168
|
intro: t(locale, "auth.mail.activation.intro", { app }),
|
|
165
169
|
buttonLabel: t(locale, "auth.mail.activation.button"),
|
|
166
170
|
buttonUrl: args.url,
|
|
167
|
-
expiry: t(locale, "auth.mail.activation.expiry",
|
|
171
|
+
expiry: t(locale, "auth.mail.activation.expiry", expiryParams(args, locale)),
|
|
168
172
|
ignore: t(locale, "auth.mail.activation.ignore"),
|
|
169
173
|
});
|
|
170
174
|
}
|
|
@@ -179,20 +183,76 @@ export function renderInviteEmail(args: RenderInviteEmailArgs): AuthMailContent
|
|
|
179
183
|
intro: t(locale, "auth.mail.invite.intro", { app, role: args.role }),
|
|
180
184
|
buttonLabel: t(locale, "auth.mail.invite.button"),
|
|
181
185
|
buttonUrl: args.url,
|
|
182
|
-
expiry: t(locale, "auth.mail.invite.expiry",
|
|
186
|
+
expiry: t(locale, "auth.mail.invite.expiry", expiryParams(args, locale)),
|
|
183
187
|
ignore: t(locale, "auth.mail.invite.ignore"),
|
|
184
188
|
});
|
|
185
189
|
}
|
|
186
190
|
|
|
187
|
-
|
|
191
|
+
const MS_PER_MINUTE = 60_000;
|
|
192
|
+
const MS_PER_HOUR = 60 * MS_PER_MINUTE;
|
|
193
|
+
const MS_PER_DAY = 24 * MS_PER_HOUR;
|
|
194
|
+
|
|
195
|
+
type DurationUnit = "day" | "hour" | "minute";
|
|
196
|
+
|
|
197
|
+
// Rounds to whole minutes first so a few ms between issuing and signing still
|
|
198
|
+
// read as "1 day"; a larger unit is only used when it divides the span exactly.
|
|
199
|
+
function durationParts(ms: number): { readonly amount: number; readonly unit: DurationUnit } {
|
|
200
|
+
const minutes = Math.max(1, Math.round(ms / MS_PER_MINUTE));
|
|
201
|
+
const minutesPerHour = MS_PER_HOUR / MS_PER_MINUTE;
|
|
202
|
+
const minutesPerDay = MS_PER_DAY / MS_PER_MINUTE;
|
|
203
|
+
if (minutes % minutesPerDay === 0) return { amount: minutes / minutesPerDay, unit: "day" };
|
|
204
|
+
if (minutes % minutesPerHour === 0) return { amount: minutes / minutesPerHour, unit: "hour" };
|
|
205
|
+
return { amount: minutes, unit: "minute" };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function formatDuration(ms: number, locale: string): string {
|
|
209
|
+
const { amount, unit } = durationParts(ms);
|
|
210
|
+
const options: Intl.NumberFormatOptions = { style: "unit", unit, unitDisplay: "long" };
|
|
188
211
|
try {
|
|
189
|
-
|
|
190
|
-
return `${z.year}-${pad2(z.month)}-${pad2(z.day)} ${pad2(z.hour)}:${pad2(z.minute)} UTC`;
|
|
212
|
+
return new Intl.NumberFormat(locale, options).format(amount);
|
|
191
213
|
} catch {
|
|
192
|
-
return
|
|
214
|
+
return new Intl.NumberFormat("en", options).format(amount);
|
|
193
215
|
}
|
|
194
216
|
}
|
|
195
217
|
|
|
196
|
-
|
|
197
|
-
|
|
218
|
+
// Intl rejects timeZoneName together with dateStyle/timeStyle, so the zone
|
|
219
|
+
// abbreviation is read from a second formatter and appended.
|
|
220
|
+
function formatWhen(expiresAt: Temporal.Instant, locale: string, timeZone: string): string {
|
|
221
|
+
const build = (tag: string, zone: string): string => {
|
|
222
|
+
const at = expiresAt.epochMilliseconds;
|
|
223
|
+
const dateTime = new Intl.DateTimeFormat(tag, {
|
|
224
|
+
dateStyle: "medium",
|
|
225
|
+
timeStyle: "short",
|
|
226
|
+
timeZone: zone,
|
|
227
|
+
}).format(at);
|
|
228
|
+
const zoneName = new Intl.DateTimeFormat(tag, { timeZone: zone, timeZoneName: "short" })
|
|
229
|
+
.formatToParts(at)
|
|
230
|
+
.find((part) => part.type === "timeZoneName")?.value;
|
|
231
|
+
return zoneName ? `${dateTime} ${zoneName}` : dateTime;
|
|
232
|
+
};
|
|
233
|
+
try {
|
|
234
|
+
return build(locale, timeZone);
|
|
235
|
+
} catch {
|
|
236
|
+
try {
|
|
237
|
+
return build(locale, "UTC");
|
|
238
|
+
} catch {
|
|
239
|
+
return build("en", "UTC");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function expiryParams(
|
|
245
|
+
args: RenderTokenContentArgs,
|
|
246
|
+
locale: string,
|
|
247
|
+
): { readonly duration: string; readonly when: string } {
|
|
248
|
+
try {
|
|
249
|
+
const expiresAt = Temporal.Instant.from(args.expiresAt);
|
|
250
|
+
const issuedAt = args.issuedAt ? Temporal.Instant.from(args.issuedAt) : Temporal.Now.instant();
|
|
251
|
+
return {
|
|
252
|
+
duration: formatDuration(expiresAt.epochMilliseconds - issuedAt.epochMilliseconds, locale),
|
|
253
|
+
when: formatWhen(expiresAt, locale, args.timeZone ?? "UTC"),
|
|
254
|
+
};
|
|
255
|
+
} catch {
|
|
256
|
+
return { duration: args.expiresAt, when: args.expiresAt };
|
|
257
|
+
}
|
|
198
258
|
}
|
|
@@ -160,7 +160,8 @@ async function issueInvitation(
|
|
|
160
160
|
|
|
161
161
|
const email = request.email.toLowerCase();
|
|
162
162
|
const tenantId = inviter.tenantId;
|
|
163
|
-
const
|
|
163
|
+
const issuedAt = Temporal.Now.instant();
|
|
164
|
+
const expiresAt = issuedAt.add({ seconds: ttlSeconds });
|
|
164
165
|
|
|
165
166
|
// The unique index allows one row per (tenantId, email). Whatever its
|
|
166
167
|
// status, a re-invite resets it to pending with a fresh token.
|
|
@@ -233,6 +234,8 @@ async function issueInvitation(
|
|
|
233
234
|
appUrl: opts.appUrl,
|
|
234
235
|
token,
|
|
235
236
|
expiresAt: expiresAt.toString(),
|
|
237
|
+
issuedAt: issuedAt.toString(),
|
|
238
|
+
timeZone: ctx.tz.user,
|
|
236
239
|
...(opts.appName !== undefined && { appName: opts.appName }),
|
|
237
240
|
locale,
|
|
238
241
|
},
|
|
@@ -150,7 +150,8 @@ export function createSignupRequestHandler(opts: SignupRequestOptions) {
|
|
|
150
150
|
// session tokens.
|
|
151
151
|
const token = generateToken();
|
|
152
152
|
|
|
153
|
-
const
|
|
153
|
+
const issuedAt = Temporal.Now.instant();
|
|
154
|
+
const expiresAt = issuedAt.add({ seconds: ttlSeconds });
|
|
154
155
|
const expiresAtIso = expiresAt.toString();
|
|
155
156
|
|
|
156
157
|
await storeSignupToken(ctx.redis, { email, token, ttlSeconds });
|
|
@@ -211,6 +212,8 @@ export function createSignupRequestHandler(opts: SignupRequestOptions) {
|
|
|
211
212
|
appUrl: opts.appUrl,
|
|
212
213
|
token,
|
|
213
214
|
expiresAt: expiresAtIso,
|
|
215
|
+
issuedAt: issuedAt.toString(),
|
|
216
|
+
timeZone: ctx.tz.user,
|
|
214
217
|
...(opts.appName !== undefined && { appName: opts.appName }),
|
|
215
218
|
locale,
|
|
216
219
|
},
|
|
@@ -137,6 +137,7 @@ export function createTokenRequestHandler<TName extends string, TSuccessKind ext
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
const { token, expiresAt } = spec.sign(user.id, ttl, opts.hmacSecret);
|
|
140
|
+
const issuedAt = expiresAt.subtract({ minutes: ttl }).toString();
|
|
140
141
|
|
|
141
142
|
const locale = resolveHandlerMailLocale(ctx, opts.locale);
|
|
142
143
|
|
|
@@ -154,6 +155,8 @@ export function createTokenRequestHandler<TName extends string, TSuccessKind ext
|
|
|
154
155
|
appUrl: opts.appUrl,
|
|
155
156
|
token,
|
|
156
157
|
expiresAt: expiresAt.toString(),
|
|
158
|
+
issuedAt,
|
|
159
|
+
timeZone: ctx.tz.user,
|
|
157
160
|
...(opts.appName !== undefined && { appName: opts.appName }),
|
|
158
161
|
locale,
|
|
159
162
|
},
|
|
@@ -34,6 +34,8 @@ export type MagicLinkMailParams = {
|
|
|
34
34
|
readonly expiresAt: string;
|
|
35
35
|
readonly appName?: string;
|
|
36
36
|
readonly locale?: AuthMailLocale;
|
|
37
|
+
readonly issuedAt?: string;
|
|
38
|
+
readonly timeZone?: string;
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
function resolveAppUrl(appUrl: string | ((locale: string) => string), locale: string): string {
|
|
@@ -78,6 +80,8 @@ export async function dispatchMagicLinkMail(
|
|
|
78
80
|
expiresAt: params.expiresAt,
|
|
79
81
|
...(params.locale !== undefined && { locale: params.locale }),
|
|
80
82
|
...(params.appName !== undefined && { appName: params.appName }),
|
|
83
|
+
...(params.issuedAt !== undefined && { issuedAt: params.issuedAt }),
|
|
84
|
+
...(params.timeZone !== undefined && { timeZone: params.timeZone }),
|
|
81
85
|
});
|
|
82
86
|
await notify(spec.notificationType, {
|
|
83
87
|
route: { email: params.email },
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.344.0",
|
|
4
|
+
"type": "breaking",
|
|
5
|
+
"title": "Consumer-protection gaps - per-locale legal links, gate order, confirmation mail, exports",
|
|
6
|
+
"detail": "All changes below apply only when `createBillingFoundationFeature` gets `consumerProtection`. Apps without it behave as before.\n`ConsumerProtectionOptions.legalLinks` takes either one `LegalLinkSet` or one set per consent locale (`{ de, en }`, both required). `BillingPlansResult.consumerProtection.legalLinks` is now always `Record<\"de\" | \"en\", LegalLinkSet>`; a single set is returned for both locales. Code that reads `legalLinks.terms` from the billing-plans result must read `legalLinks[locale].terms`. `CheckoutConsentDialog` picks the set for the consent locale.\n`FALLBACK_CONSENT_LOCALE` is now `\"en\"` (was `\"de\"`). A locale other than de/en, or none, resolves to English in `resolveConsentLocale`, the consent gate, the confirmation mail's VAT note and the termination record.\n`create-checkout-session` with consumer protection now checks in this order: provider, billing enabled, redirect origins, price and subscription gates, then the live price (new `UnprocessableError` `price_unavailable` when the provider cannot return it), then the consent, then the provider call. A missing consent no longer hides a disabled provider, an existing subscription or an unknown price. Its payload schema is strict, so unknown fields are rejected. `assertCheckoutAllowed` and `startProviderCheckout` split `openCheckout` in checkout-core.\nNew option `ConsumerProtectionOptions.oneOffItemLabel(ctx, priceId)`: the server resolves the label of a one-off item (for example a credit pack). It is stored on the consent event as `itemLabelKey` / `itemLabelParams` and shown in the confirmation mail as \"Leistung\" / \"Item\". The client cannot set it.\nThe terms text block is read from the system tenant, not from the buyer's tenant, in the consent gate and the confirmation mail. A tenant-owned block with the same slug no longer changes `termsHash` or the mailed text.\nThe confirmation mail shows dates in the recipient's time zone (user zone, else tenant zone, else UTC) with the zone name, renders the terms as Markdown with real headings and shows the translated plan name (`catalog.tierLabelKey`, looked up through the registry i18n, so the key must be qualified with the registering feature; untranslated keys fall back to the raw tier). Its opening sentence starts with a capital letter.\nNew exports: `consentPayloadSchema`, `ConsentPayload`, `OrderItem`, `CONSENT_LOCALES`, `ConsentLocale`, `resolveConsentLocale`, `LegalLinkSet`. The `/web` entry adds `CheckoutConsentDialog`, `CheckoutConsentDialogProps`, `CheckoutConsentPayload`, `CONSENT_TEXT_OUTDATED_CODE`, `resolveConsentLocale`, `ConsentLocale` and `LegalLinkSet`. `CheckoutConsentDialog` `price.count` is optional, and the \"cancel at any time\" note only shows for a recurring price (`price.renewalKey` set).\nThe checkout and cancel dialogs no longer repeat the modal title as a heading, and the cancel-contract button is hidden once a cancellation is scheduled.",
|
|
7
|
+
"migration": "Only apps that pass consumerProtection are affected. BillingPlansResult.consumerProtection.legalLinks is now keyed by locale (legalLinks.de / legalLinks.en). FALLBACK_CONSENT_LOCALE changed from de to en. create-checkout-session rejects unknown payload fields when consumer protection is on."
|
|
8
|
+
},
|
|
2
9
|
{
|
|
3
10
|
"version": "0.341.0",
|
|
4
11
|
"type": "improvement",
|
|
@@ -329,17 +329,27 @@ function assertOneOffPriceAllowed(
|
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
type CheckoutCapableProvider = SubscriptionProviderPlugin & {
|
|
333
|
+
readonly createCheckoutSession: NonNullable<SubscriptionProviderPlugin["createCheckoutSession"]>;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
function canCreateCheckoutSession(
|
|
337
|
+
plugin: SubscriptionProviderPlugin,
|
|
338
|
+
): plugin is CheckoutCapableProvider {
|
|
339
|
+
return plugin.createCheckoutSession !== undefined;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** All gates that run before a provider checkout call: provider, billing
|
|
343
|
+
* enabled, redirect origins, mode gates, foreign provider customer.
|
|
344
|
+
* `mode: "payment"` (one-off top-ups etc.) skips the price/subscription
|
|
345
|
+
* gates — those apply to recurring subscriptions only. */
|
|
346
|
+
export async function assertCheckoutAllowed(
|
|
337
347
|
ctx: HandlerContext,
|
|
338
348
|
options: OpenCheckoutOptions,
|
|
339
349
|
input: OpenCheckoutInput,
|
|
340
|
-
): Promise<
|
|
350
|
+
): Promise<CheckoutCapableProvider> {
|
|
341
351
|
const { plugin } = resolveProviderPlugin(ctx, input.providerName);
|
|
342
|
-
if (!plugin
|
|
352
|
+
if (!canCreateCheckoutSession(plugin)) {
|
|
343
353
|
throw new Error(
|
|
344
354
|
`subscription-foundation: provider "${input.providerName}" has no createCheckoutSession-method (e.g. Apple-IAP-only providers). Use the provider's native checkout flow.`,
|
|
345
355
|
);
|
|
@@ -376,7 +386,14 @@ export async function openCheckout(
|
|
|
376
386
|
});
|
|
377
387
|
}
|
|
378
388
|
}
|
|
389
|
+
return plugin;
|
|
390
|
+
}
|
|
379
391
|
|
|
392
|
+
export async function startProviderCheckout(
|
|
393
|
+
ctx: HandlerContext,
|
|
394
|
+
plugin: CheckoutCapableProvider,
|
|
395
|
+
input: OpenCheckoutInput,
|
|
396
|
+
): Promise<{ readonly url: string; readonly providerName: string }> {
|
|
380
397
|
const result = await plugin.createCheckoutSession(ctx, {
|
|
381
398
|
priceId: input.priceId,
|
|
382
399
|
tenantId: ctx.user.tenantId,
|
|
@@ -393,3 +410,14 @@ export async function openCheckout(
|
|
|
393
410
|
});
|
|
394
411
|
return { url: result.url, providerName: input.providerName };
|
|
395
412
|
}
|
|
413
|
+
|
|
414
|
+
/** The one checkout entry-point start-plan-checkout, switch-plan and the
|
|
415
|
+
* non-consumer-protection create-checkout-session funnel through. */
|
|
416
|
+
export async function openCheckout(
|
|
417
|
+
ctx: HandlerContext,
|
|
418
|
+
options: OpenCheckoutOptions,
|
|
419
|
+
input: OpenCheckoutInput,
|
|
420
|
+
): Promise<{ readonly url: string; readonly providerName: string }> {
|
|
421
|
+
const plugin = await assertCheckoutAllowed(ctx, options, input);
|
|
422
|
+
return startProviderCheckout(ctx, plugin, input);
|
|
423
|
+
}
|