@cosmicdrift/kumiko-bundled-features 0.404.1 → 0.405.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/auth-email-password/mail-notifications.d.ts +3 -3
  2. package/dist/auth-email-password/mail-notifications.js +10 -34
  3. package/dist/auth-email-password/web/default-topbar-actions.d.ts +6 -1
  4. package/dist/auth-email-password/web/default-topbar-actions.js +2 -2
  5. package/dist/auth-email-password/web/index.d.ts +2 -0
  6. package/dist/auth-email-password/web/index.js +1 -0
  7. package/dist/auth-email-password/web/invite-accept-screen.js +6 -41
  8. package/dist/auth-email-password/web/tenant-label.d.ts +2 -0
  9. package/dist/auth-email-password/web/tenant-label.js +10 -0
  10. package/dist/auth-email-password/web/tenant-menu-items.js +2 -7
  11. package/dist/auth-email-password/web/tenant-switcher.js +5 -12
  12. package/dist/auth-email-password/web/use-redirect-authed-from-login.d.ts +7 -0
  13. package/dist/auth-email-password/web/use-redirect-authed-from-login.js +30 -0
  14. package/dist/auth-foundation/feature.js +8 -21
  15. package/dist/auth-mfa/handlers/reencrypt.job.js +7 -15
  16. package/dist/auth-mfa/hmac-token-codec.d.ts +6 -1
  17. package/dist/auth-mfa/hmac-token-codec.js +8 -10
  18. package/dist/auth-mfa/mfa-challenge-token.js +2 -8
  19. package/dist/auth-mfa/mfa-preauth-setup-token.js +2 -8
  20. package/dist/auth-mfa/mfa-setup-token.d.ts +2 -8
  21. package/dist/auth-mfa/mfa-setup-token.js +8 -45
  22. package/dist/billing-foundation/consumer-protection/termination-revoke.js +3 -11
  23. package/dist/billing-foundation/feature.js +1 -5
  24. package/dist/billing-foundation/handlers/process-event.write.js +2 -6
  25. package/dist/billing-foundation/handlers/process-payment-event.write.js +2 -6
  26. package/dist/billing-foundation/index.d.ts +2 -0
  27. package/dist/billing-foundation/index.js +2 -0
  28. package/dist/billing-foundation/projection.js +12 -21
  29. package/dist/billing-foundation/provider-event-seen.d.ts +5 -0
  30. package/dist/billing-foundation/provider-event-seen.js +7 -0
  31. package/dist/billing-foundation/provider-shared.d.ts +11 -0
  32. package/dist/billing-foundation/provider-shared.js +44 -0
  33. package/dist/billing-foundation/tenant-destroy-hook.js +5 -4
  34. package/dist/channel-email/feature.js +1 -1
  35. package/dist/config/handlers/reencrypt.job.js +7 -15
  36. package/dist/delivery/delivery-service.js +2 -8
  37. package/dist/file-derivatives/feature.js +9 -21
  38. package/dist/file-foundation/feature.js +2 -6
  39. package/dist/files-tenant-data/hooks.js +1 -6
  40. package/dist/folders/feature.js +2 -9
  41. package/dist/folders/web/folder-manager.js +7 -26
  42. package/dist/folders/web/folder-section.js +5 -24
  43. package/dist/form-draft/handlers/save.write.d.ts +9 -0
  44. package/dist/form-draft/handlers/save.write.js +3 -7
  45. package/dist/inbound-mail-foundation/feature.js +2 -6
  46. package/dist/inbound-mail-foundation/oauth-state.js +5 -13
  47. package/dist/inbound-mail-foundation/tenant-destroy-hook.d.ts +1 -1
  48. package/dist/inbound-mail-foundation/tenant-destroy-hook.js +3 -18
  49. package/dist/jobs/handlers/tenant-failures.query.js +1 -15
  50. package/dist/jobs/handlers/tenant-runs.query.js +1 -14
  51. package/dist/jobs/job-run-logger.js +19 -23
  52. package/dist/jobs/parse-subject.d.ts +1 -0
  53. package/dist/jobs/parse-subject.js +15 -0
  54. package/dist/ledger/feature.js +2 -8
  55. package/dist/mail-foundation/feature.js +3 -7
  56. package/dist/managed-pages/render-page-body.js +4 -12
  57. package/dist/notes-history/feature.js +2 -9
  58. package/dist/personal-access-tokens/handlers/list.query.js +1 -9
  59. package/dist/personal-access-tokens/hash.js +2 -2
  60. package/dist/personal-access-tokens/parse-scope-names.d.ts +1 -0
  61. package/dist/personal-access-tokens/parse-scope-names.js +10 -0
  62. package/dist/personal-access-tokens/resolver.js +1 -9
  63. package/dist/renderer-foundation/feature.js +3 -14
  64. package/dist/secrets/handlers/rotate.job.js +7 -18
  65. package/dist/shared/collect-extension-options.d.ts +4 -0
  66. package/dist/shared/collect-extension-options.js +8 -0
  67. package/dist/shared/hmac-signature.d.ts +2 -0
  68. package/dist/shared/hmac-signature.js +10 -0
  69. package/dist/shared/index.d.ts +6 -0
  70. package/dist/shared/index.js +6 -0
  71. package/dist/shared/is-unique-constraint-failure.d.ts +2 -0
  72. package/dist/shared/is-unique-constraint-failure.js +7 -0
  73. package/dist/shared/mail-locale-templates.d.ts +12 -0
  74. package/dist/shared/mail-locale-templates.js +36 -0
  75. package/dist/shared/resolve-feature-access.d.ts +7 -0
  76. package/dist/shared/resolve-feature-access.js +8 -0
  77. package/dist/shared/signed-token.js +4 -14
  78. package/dist/shared/single-use-token-store.js +2 -2
  79. package/dist/shared/stream-tenant-derived-state.js +1 -5
  80. package/dist/shared/tenant-db-cache.d.ts +3 -0
  81. package/dist/shared/tenant-db-cache.js +14 -0
  82. package/dist/shared/web/status-banner.d.ts +15 -0
  83. package/dist/shared/web/status-banner.js +13 -0
  84. package/dist/shared/web/use-dispatched-writes.d.ts +8 -0
  85. package/dist/shared/web/use-dispatched-writes.js +29 -0
  86. package/dist/subscription-paddle/feature.js +2 -15
  87. package/dist/subscription-paddle/price-methods.d.ts +2 -5
  88. package/dist/subscription-paddle/price-methods.js +5 -26
  89. package/dist/subscription-paddle/runtime.d.ts +1 -1
  90. package/dist/subscription-paddle/runtime.js +3 -16
  91. package/dist/subscription-stripe/feature.js +2 -17
  92. package/dist/subscription-stripe/plugin-methods.d.ts +2 -5
  93. package/dist/subscription-stripe/plugin-methods.js +3 -18
  94. package/dist/subscription-stripe/runtime.js +3 -19
  95. package/dist/tags/feature.js +2 -9
  96. package/dist/tags/web/tag-manager.js +5 -24
  97. package/dist/tags/web/tag-section.js +3 -12
  98. package/dist/template-resolver/handlers/tenant-overrides.query.js +3 -9
  99. package/dist/tenant/handlers/decrypt-member-users.d.ts +10 -0
  100. package/dist/tenant/handlers/decrypt-member-users.js +17 -0
  101. package/dist/tenant/handlers/members.query.js +2 -17
  102. package/dist/tenant/handlers/team-list.query.js +4 -17
  103. package/dist/tenant-lifecycle/archive-and-delete-tenant-rows.d.ts +5 -0
  104. package/dist/tenant-lifecycle/archive-and-delete-tenant-rows.js +20 -0
  105. package/dist/tenant-lifecycle/index.d.ts +1 -0
  106. package/dist/tenant-lifecycle/index.js +1 -0
  107. package/dist/tier-engine/feature.js +1 -1
  108. package/dist/user-data-rights/build-hook-db.d.ts +11 -0
  109. package/dist/user-data-rights/build-hook-db.js +22 -0
  110. package/dist/user-data-rights/handlers/request-export.write.js +2 -12
  111. package/dist/user-data-rights/mail-notifications.d.ts +3 -3
  112. package/dist/user-data-rights/mail-notifications.js +10 -34
  113. package/dist/user-data-rights/run-forget-cleanup.d.ts +1 -1
  114. package/dist/user-data-rights/run-forget-cleanup.js +2 -21
  115. package/dist/user-data-rights/run-user-export.d.ts +1 -1
  116. package/dist/user-data-rights/run-user-export.js +2 -21
  117. package/dist/user-data-rights/token-helpers.js +2 -14
  118. package/dist/user-data-rights/web/privacy-center-screen.js +1 -11
  119. package/dist/user-profile/web/profile-screen.js +1 -11
  120. package/package.json +20 -20
  121. package/src/auth-email-password/changes.json +6 -0
  122. package/src/auth-mfa/changes.json +6 -0
  123. package/src/billing-foundation/changes.json +6 -0
  124. package/src/shared/changes.json +6 -0
  125. package/src/tenant-lifecycle/changes.json +6 -0
@@ -0,0 +1,10 @@
1
+ export type MemberUserRow = {
2
+ readonly id: unknown;
3
+ readonly email?: unknown;
4
+ readonly displayName?: unknown;
5
+ };
6
+ export declare const KMS_POOL_CONCURRENCY = 4;
7
+ export declare function decryptMemberUsers(users: readonly MemberUserRow[], reason: string): Promise<Map<string, {
8
+ readonly email: string | null;
9
+ readonly displayName: string | null;
10
+ }>>;
@@ -0,0 +1,17 @@
1
+ import { decryptStoredPii, mapWithConcurrency } from "../../shared/index.js";
2
+ // Bounded, not Promise.all/sequential: each decrypt hits the KMS adapter's
3
+ // own small dedicated pool (PgKmsAdapter default max: 4). Promise.all fires
4
+ // one call per user unbounded and exhausts the pool once membership counts
5
+ // exceed a handful, surfacing as "the connection was closed"; a strict
6
+ // sequential loop caps concurrency at 1 and leaves 3 pool slots idle.
7
+ export const KMS_POOL_CONCURRENCY = 4;
8
+ export async function decryptMemberUsers(users, reason) {
9
+ const decrypted = await mapWithConcurrency(users, KMS_POOL_CONCURRENCY, async (user) => {
10
+ const email = typeof user.email === "string" ? await decryptStoredPii(user.email, "email", reason) : null;
11
+ const displayName = typeof user.displayName === "string"
12
+ ? await decryptStoredPii(user.displayName, "displayName", reason)
13
+ : null;
14
+ return { userId: String(user.id), email, displayName };
15
+ });
16
+ return new Map(decrypted.map((d) => [d.userId, d]));
17
+ }
@@ -3,15 +3,9 @@ import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine
3
3
  import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
4
4
  import { parseRoles } from "@cosmicdrift/kumiko-framework/utils";
5
5
  import * as z from "zod";
6
- import { decryptStoredPii, mapWithConcurrency } from "../../shared/index.js";
7
6
  import { userTable } from "../../user/index.js";
8
7
  import { tenantMembershipsTable } from "../membership-table.js";
9
- // Bounded, not Promise.all/sequential: each decrypt hits the KMS adapter's
10
- // own small dedicated pool (PgKmsAdapter default max: 4). Promise.all fires
11
- // one call per user unbounded and exhausts the pool once membership counts
12
- // exceed a handful, surfacing as "the connection was closed"; a strict
13
- // sequential loop caps concurrency at 1 and leaves 3 pool slots idle.
14
- const KMS_POOL_CONCURRENCY = 4;
8
+ import { decryptMemberUsers } from "./decrypt-member-users.js";
15
9
  export const membersQuery = defineQueryHandler({
16
10
  name: "members",
17
11
  schema: z.object({
@@ -37,16 +31,7 @@ export const membersQuery = defineQueryHandler({
37
31
  const userIds = [...new Set(rows.map((row) => row["userId"]))];
38
32
  const users = userIds.length > 0 ? await selectMany(db, userTable, { id: userIds }) : [];
39
33
  const userById = new Map(users.map((u) => [String(u.id), u]));
40
- const decrypted = await mapWithConcurrency(users, KMS_POOL_CONCURRENCY, async (user) => {
41
- const email = typeof user.email === "string"
42
- ? await decryptStoredPii(user.email, "email", "tenant:members")
43
- : null;
44
- const displayName = typeof user.displayName === "string"
45
- ? await decryptStoredPii(user.displayName, "displayName", "tenant:members")
46
- : null;
47
- return { userId: String(user.id), email, displayName };
48
- });
49
- const decryptedByUserId = new Map(decrypted.map((d) => [d.userId, d]));
34
+ const decryptedByUserId = await decryptMemberUsers(users, "tenant:members");
50
35
  return rows.map((row) => {
51
36
  const user = userById.get(String(row["userId"]));
52
37
  const decrypted = user ? decryptedByUserId.get(String(user.id)) : undefined;
@@ -10,7 +10,7 @@ import { decryptStoredPii, mapWithConcurrency } from "../../shared/index.js";
10
10
  import { userTable } from "../../user/index.js";
11
11
  import { INVITATION_STATUS, tenantInvitationsTable } from "../invitation-table.js";
12
12
  import { tenantMembershipsTable } from "../membership-table.js";
13
- const KMS_POOL_CONCURRENCY = 4;
13
+ import { decryptMemberUsers, KMS_POOL_CONCURRENCY, } from "./decrypt-member-users.js";
14
14
  // The /members screen exposes one column per field above under the SAME
15
15
  // name — unlike delivery-log there is no display-alias to map, `sort` on
16
16
  // the wire already names a TeamRow field directly.
@@ -86,11 +86,7 @@ export const teamListQuery = definePagedQueryHandler({
86
86
  const tenantId = query.user.tenantId;
87
87
  const membershipRows = await selectMany(db, tenantMembershipsTable, { tenantId });
88
88
  const userIds = [...new Set(membershipRows.map((row) => String(row["userId"])))];
89
- const users = userIds.length > 0
90
- ? await selectMany(db, userTable, {
91
- id: userIds,
92
- })
93
- : [];
89
+ const users = userIds.length > 0 ? await selectMany(db, userTable, { id: userIds }) : [];
94
90
  const lastSeenByUserId = new Map();
95
91
  if (userIds.length > 0) {
96
92
  try {
@@ -115,19 +111,10 @@ export const teamListQuery = definePagedQueryHandler({
115
111
  }
116
112
  }
117
113
  // Bounded, not Promise.all/sequential-per-item: shares the KMS
118
- // adapter's small dedicated pool (max 4, see members.query.ts) with the
114
+ // adapter's small dedicated pool (max 4, see decrypt-member-users.ts) with the
119
115
  // invitations decrypt below — the two passes run one after the other
120
116
  // (await, not Promise.all), so combined concurrency never exceeds 4.
121
- const decryptedUsers = await mapWithConcurrency(users, KMS_POOL_CONCURRENCY, async (user) => {
122
- const email = typeof user.email === "string"
123
- ? await decryptStoredPii(user.email, "email", "tenant:team-list")
124
- : null;
125
- const displayName = typeof user.displayName === "string"
126
- ? await decryptStoredPii(user.displayName, "displayName", "tenant:team-list")
127
- : null;
128
- return { userId: String(user.id), email, displayName };
129
- });
130
- const decryptedByUserId = new Map(decryptedUsers.map((d) => [d.userId, d]));
117
+ const decryptedByUserId = await decryptMemberUsers(users, "tenant:team-list");
131
118
  const memberRows = membershipRows.map((row) => {
132
119
  const userId = String(row["userId"]);
133
120
  const decrypted = decryptedByUserId.get(userId);
@@ -0,0 +1,5 @@
1
+ import type { EntityTableMeta } from "@cosmicdrift/kumiko-framework/db";
2
+ import { type TenantDataHookCtx } from "@cosmicdrift/kumiko-framework/engine";
3
+ export declare const TENANT_DESTROY_ARCHIVED_BY = "tenant-lifecycle:destroy";
4
+ export declare const TENANT_DESTROY_ARCHIVE_REASON = "tenant_destroy";
5
+ export declare function archiveAndDeleteTenantRows(ctx: TenantDataHookCtx, table: EntityTableMeta, aggregateType: string, escapeHatchReason: string): Promise<readonly string[]>;
@@ -0,0 +1,20 @@
1
+ import { declareEscapeHatch } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { archiveStream } from "@cosmicdrift/kumiko-framework/event-store";
3
+ export const TENANT_DESTROY_ARCHIVED_BY = "tenant-lifecycle:destroy";
4
+ export const TENANT_DESTROY_ARCHIVE_REASON = "tenant_destroy";
5
+ // Archiving first means a later projection rebuild cannot resurrect the deleted rows.
6
+ export async function archiveAndDeleteTenantRows(ctx, table, aggregateType, escapeHatchReason) {
7
+ declareEscapeHatch({ reason: escapeHatchReason });
8
+ const rows = await ctx.db.selectMany(table, { tenantId: ctx.tenantId });
9
+ for (const row of rows) {
10
+ await archiveStream(ctx.db.unsafeRaw(), {
11
+ tenantId: ctx.tenantId,
12
+ aggregateId: row.id,
13
+ aggregateType,
14
+ archivedBy: TENANT_DESTROY_ARCHIVED_BY,
15
+ reason: TENANT_DESTROY_ARCHIVE_REASON,
16
+ });
17
+ }
18
+ await ctx.db.deleteMany(table, { tenantId: ctx.tenantId });
19
+ return rows.map((row) => row.id);
20
+ }
@@ -1,3 +1,4 @@
1
+ export { archiveAndDeleteTenantRows, TENANT_DESTROY_ARCHIVE_REASON, TENANT_DESTROY_ARCHIVED_BY, } from "./archive-and-delete-tenant-rows.ts";
1
2
  export { TENANT_DESTRUCTION_STAGES, TENANT_LIFECYCLE_FEATURE, TenantLifecycleHandlers, } from "./constants.ts";
2
3
  export { createTenantLifecycleFeature } from "./feature.ts";
3
4
  export { resolveTenantLifecycleGate } from "./run-tenant-destroy.ts";
@@ -1,3 +1,4 @@
1
+ export { archiveAndDeleteTenantRows, TENANT_DESTROY_ARCHIVE_REASON, TENANT_DESTROY_ARCHIVED_BY, } from "./archive-and-delete-tenant-rows.js";
1
2
  export { TENANT_DESTRUCTION_STAGES, TENANT_LIFECYCLE_FEATURE, TenantLifecycleHandlers, } from "./constants.js";
2
3
  export { createTenantLifecycleFeature } from "./feature.js";
3
4
  export { resolveTenantLifecycleGate } from "./run-tenant-destroy.js";
@@ -380,7 +380,7 @@ export function createTierEngineFeature(opts = {}) {
380
380
  // point AND registers itself as the default plugin. Other features could
381
381
  // register there later (e.g. a future toggle-only resolver), but only one
382
382
  // plugin wins — see the "single-plugin" comment on findTierResolverUsage.
383
- r.extendsRegistrar(TENANT_TIER_RESOLVER_EXT, { onRegister: () => { } });
383
+ r.extendsRegistrar(TENANT_TIER_RESOLVER_EXT, {});
384
384
  // Plugin-registration: framework's runDevApp/runProdApp picks this up
385
385
  // post-stack-setup, calls build(deps), wires effectiveFeatures.
386
386
  const plugin = {
@@ -0,0 +1,11 @@
1
+ import { type DbRunner } from "@cosmicdrift/kumiko-framework/db";
2
+ import { type EscapeHatchAuditSink, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { type Logger } from "@cosmicdrift/kumiko-framework/logging";
4
+ export declare function buildHookDb(db: DbRunner, tenantId: TenantId, entry: {
5
+ readonly entityName: string;
6
+ readonly escapeHatchReason: string | undefined;
7
+ }, args: {
8
+ readonly escapeHatchAuditSink?: EscapeHatchAuditSink;
9
+ readonly escapeHatchAuditLog?: Logger;
10
+ readonly actor?: string;
11
+ }): import("@cosmicdrift/kumiko-types/tenant-db-types").TenantDb;
@@ -0,0 +1,22 @@
1
+ import { createTenantDb } from "@cosmicdrift/kumiko-framework/db";
2
+ import { EXT_USER_DATA, } from "@cosmicdrift/kumiko-framework/engine";
3
+ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
4
+ import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
5
+ export function buildHookDb(db, tenantId, entry, args) {
6
+ const report = createEscapeHatchReporter({
7
+ handler: `${EXT_USER_DATA}:${entry.entityName}`,
8
+ tenantId,
9
+ actor: args.actor ?? UNATTRIBUTED_ACTOR,
10
+ sink: args.escapeHatchAuditSink,
11
+ log: args.escapeHatchAuditLog ?? createFallbackLogger("user-data-rights"),
12
+ });
13
+ return createTenantDb({
14
+ db,
15
+ tenantId,
16
+ mode: "tenant",
17
+ grants: {
18
+ unsafeRaw: entry.escapeHatchReason !== undefined ? { reason: entry.escapeHatchReason } : undefined,
19
+ report,
20
+ },
21
+ });
22
+ }
@@ -24,22 +24,12 @@ import { createEventStoreExecutor, fetchOne } from "@cosmicdrift/kumiko-framewor
24
24
  import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
25
25
  import { getTemporal } from "@cosmicdrift/kumiko-framework/time";
26
26
  import * as z from "zod";
27
+ import { isUniqueConstraintFailure } from "../../shared/index.js";
27
28
  import { ACTIVE_JOB_CONSTRAINT, EXPORT_JOB_STATUS, exportJobEntity, exportJobsTable, } from "../schema/export-job.js";
28
29
  const crud = createEventStoreExecutor(exportJobsTable, exportJobEntity, {
29
30
  entityName: "export-job",
30
31
  });
31
32
  const REQUEST_EXPORT_REASON = "export jobs are keyed by userId across all of the user's tenant memberships, not the caller's current tenant";
32
- /**
33
- * `createEventStoreExecutor.create` catches 23505 internally and returns
34
- * `WriteFailure(UniqueViolationError)` rather than throwing. Check the
35
- * failure code and constraintName to distinguish the app-side and race
36
- * paths; propagate other failures (validation, version conflicts, ...)
37
- * unchanged.
38
- */
39
- function isActiveJobConflict(failure) {
40
- const error = failure.error; // @cast-boundary error-details
41
- return (error.code === "unique_violation" && error.details?.constraintName === ACTIVE_JOB_CONSTRAINT);
42
- }
43
33
  export const requestExportWrite = defineWriteHandler({
44
34
  name: "request-export",
45
35
  schema: z.object({}),
@@ -89,7 +79,7 @@ export const requestExportWrite = defineWriteHandler({
89
79
  // crud.create, causing UniqueViolationError for our constraint. Re-fetch
90
80
  // and return the existing job with isExisting=true. Propagate other
91
81
  // failures (validation, version conflicts, ...) unchanged.
92
- if (isActiveJobConflict(result)) {
82
+ if (isUniqueConstraintFailure(result, ACTIVE_JOB_CONSTRAINT)) {
93
83
  const winner = await findActiveJob(exportJobRunner, userId);
94
84
  if (!winner) {
95
85
  // This should be impossible: a constraint violation without an existing
@@ -1,4 +1,4 @@
1
- import { type FeatureRegistrar, type NotificationLocalizedTemplate, type TemplateVariables } from "@cosmicdrift/kumiko-framework/engine";
1
+ import { type FeatureRegistrar, type TemplateVariables } from "@cosmicdrift/kumiko-framework/engine";
2
2
  declare const ALL_GDPR_MAIL_KINDS: readonly ["exportReady", "exportFailed", "deletionRequested", "deletionExecuted"];
3
3
  export type GdprMailKind = (typeof ALL_GDPR_MAIL_KINDS)[number];
4
4
  export declare const GDPR_MAIL_KINDS: Readonly<Record<GdprMailKind, {
@@ -6,8 +6,8 @@ export declare const GDPR_MAIL_KINDS: Readonly<Record<GdprMailKind, {
6
6
  readonly translationKey: string;
7
7
  }>>;
8
8
  export declare const GdprMailNotificationTypes: Readonly<Record<GdprMailKind, string>>;
9
- export declare function gdprMailTemplateLocale(notificationType: string, requestedLocale: string): string;
9
+ export declare const gdprMailTemplateLocale: (notificationType: string, requestedLocale: string) => string;
10
10
  export declare const GDPR_MAIL_VARIABLES: Readonly<Record<GdprMailKind, TemplateVariables>>;
11
- export declare function gdprMailLocalizedTemplate(kind: GdprMailKind): () => NotificationLocalizedTemplate;
11
+ export declare const gdprMailLocalizedTemplate: (kind: "deletionExecuted" | "deletionRequested" | "exportFailed" | "exportReady") => () => import("@cosmicdrift/kumiko-types/config").NotificationLocalizedTemplate;
12
12
  export declare function registerGdprMails(r: FeatureRegistrar): void;
13
13
  export {};
@@ -1,7 +1,7 @@
1
1
  import { QnTypes, qn, templateVariable, } from "@cosmicdrift/kumiko-framework/engine";
2
- import { hasMailTranslationKey, listMailLocales, mailT, resolveMailLocale, } from "@cosmicdrift/kumiko-framework/i18n";
2
+ import { mailT } from "@cosmicdrift/kumiko-framework/i18n";
3
3
  import { escapeHtml } from "@cosmicdrift/kumiko-renderer/headless";
4
- import { mailParagraph } from "../shared/index.js";
4
+ import { createMailLocaleTemplates, mailParagraph } from "../shared/index.js";
5
5
  import { USER_DATA_RIGHTS_FEATURE } from "./web/constants.js";
6
6
  const ALL_GDPR_MAIL_KINDS = [
7
7
  "exportReady",
@@ -27,15 +27,13 @@ function gdprMailType(kind) {
27
27
  function subjectKey(kind) {
28
28
  return `gdpr.mail.${GDPR_MAIL_KINDS[kind].translationKey}.subject`;
29
29
  }
30
- const SUBJECT_KEY_BY_TYPE = new Map(ALL_GDPR_MAIL_KINDS.map((kind) => [GdprMailNotificationTypes[kind], subjectKey(kind)]));
31
- // A registered locale whose bundle lacks the subject key has no template (see
32
- // gdprMailLocalizedTemplate); the renderer has no locale fallback, so the
33
- // sender must pick a locale that has one or the mail would not go out at all.
34
- export function gdprMailTemplateLocale(notificationType, requestedLocale) {
35
- const locale = resolveMailLocale(requestedLocale);
36
- const key = SUBJECT_KEY_BY_TYPE.get(notificationType);
37
- return key !== undefined && hasMailTranslationKey(locale, key) ? locale : "en";
38
- }
30
+ const mailLocaleTemplates = createMailLocaleTemplates({
31
+ kinds: ALL_GDPR_MAIL_KINDS,
32
+ notificationTypes: GdprMailNotificationTypes,
33
+ subjectKey,
34
+ bodyFor: (kind, locale) => mailBody(kind, locale),
35
+ });
36
+ export const gdprMailTemplateLocale = mailLocaleTemplates.templateLocale;
39
37
  const appName = () => templateVariable.text({ required: true });
40
38
  export const GDPR_MAIL_VARIABLES = {
41
39
  exportReady: {
@@ -85,29 +83,7 @@ function mailBody(kind, locale) {
85
83
  return [greeting(locale), paragraph(kind, locale, "intro")].join("");
86
84
  }
87
85
  }
88
- // Evaluated when the registry is built, after every locale feature has
89
- // registered its mail translations. English always ships; another locale only
90
- // gets a template when it has its own subject, so a missing translation never
91
- // silently becomes an English mail in that locale's slot.
92
- export function gdprMailLocalizedTemplate(kind) {
93
- const kindSubjectKey = subjectKey(kind);
94
- return () => {
95
- const locales = [
96
- "en",
97
- ...listMailLocales().filter((locale) => locale !== "en" && hasMailTranslationKey(locale, kindSubjectKey)),
98
- ];
99
- return Object.fromEntries(locales.map((locale) => [
100
- locale,
101
- {
102
- body: mailBody(kind, locale),
103
- meta: {
104
- subject: mailT(locale, kindSubjectKey, { app: "{{appName}}" }),
105
- category: "transactional",
106
- },
107
- },
108
- ]));
109
- };
110
- }
86
+ export const gdprMailLocalizedTemplate = mailLocaleTemplates.localizedTemplate;
111
87
  export function registerGdprMails(r) {
112
88
  for (const kind of ALL_GDPR_MAIL_KINDS) {
113
89
  r.notification(GDPR_MAIL_KINDS[kind].name, {
@@ -1,4 +1,4 @@
1
- import { type Logger } from "@cosmicdrift/kumiko-framework/logging";
1
+ import type { Logger } from "@cosmicdrift/kumiko-framework/logging";
2
2
  import { type KmsAdapter } from "@cosmicdrift/kumiko-framework/crypto";
3
3
  import { type DbRunner } from "@cosmicdrift/kumiko-framework/db";
4
4
  import { type EscapeHatchAuditSink, type Registry, type TenantId, type TenantUserModel, type UserDataDeleteStrategy, type UserDataStorageProvider } from "@cosmicdrift/kumiko-framework/engine";
@@ -1,4 +1,3 @@
1
- import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
2
1
  // Forget-cleanup runner — pure-function pipeline.
3
2
  //
4
3
  // After the grace period, this runner processes users in DeletionRequested
@@ -28,36 +27,18 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
28
27
  // collected and returned for operator visibility, while a user with failed
29
28
  // hooks remains in DeletionRequested for automatic retry.
30
29
  import { configuredPiiSubjectKms, subjectIdToKey, } from "@cosmicdrift/kumiko-framework/crypto";
31
- import { createTenantDb, entityEventName, executeRawQuery, fetchOne, nullBlindIndexesForSubject, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
30
+ import { entityEventName, executeRawQuery, fetchOne, nullBlindIndexesForSubject, selectMany, WritePurposes, } from "@cosmicdrift/kumiko-framework/db";
32
31
  import { deleteStoredFileAndDerivatives } from "@cosmicdrift/kumiko-framework/derivatives";
33
32
  import { EXT_USER_DATA, EXT_USER_DATA_ORDER, extensionUsageEscapeHatchReason, } from "@cosmicdrift/kumiko-framework/engine";
34
33
  import { runInSystemRowLevelSecurityScope } from "@cosmicdrift/kumiko-framework/internal/row-level-security";
35
- import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
36
34
  import { purgeSearchDocumentsForSubject, } from "@cosmicdrift/kumiko-framework/search";
37
35
  import { resolveRetentionPolicyForTenant, resolveTenantRetentionPreset, } from "../data-retention/index.js";
38
36
  import { decryptStoredPii, purgeFilesReachingSubject, runInSubTransaction, } from "../shared/index.js";
39
37
  import { tenantMembershipsTable } from "../tenant/index.js";
40
38
  import { USER_STATUS, userTable } from "../user/index.js";
39
+ import { buildHookDb } from "./build-hook-db.js";
41
40
  import { selectUsersDueForForgetCleanup } from "./db/queries/forget-cleanup.js";
42
41
  import { updateUserLifecycle } from "./lib/update-user-lifecycle.js";
43
- function buildHookDb(db, tenantId, entry, args) {
44
- const report = createEscapeHatchReporter({
45
- handler: `${EXT_USER_DATA}:${entry.entityName}`,
46
- tenantId,
47
- actor: args.actor ?? UNATTRIBUTED_ACTOR,
48
- sink: args.escapeHatchAuditSink,
49
- log: args.escapeHatchAuditLog ?? createFallbackLogger("user-data-rights"),
50
- });
51
- return createTenantDb({
52
- db,
53
- tenantId,
54
- mode: "tenant",
55
- grants: {
56
- unsafeRaw: entry.escapeHatchReason !== undefined ? { reason: entry.escapeHatchReason } : undefined,
57
- report,
58
- },
59
- });
60
- }
61
42
  // EXT_USER_DATA delete-hooks default here; a hook that redacts data keyed on an
62
43
  // owner column it doesn't own must register a lower order so it runs BEFORE any
63
44
  // hook that nulls that column. See custom-fields wire-user-data-rights.ts.
@@ -1,4 +1,4 @@
1
- import { type Logger } from "@cosmicdrift/kumiko-framework/logging";
1
+ import type { Logger } from "@cosmicdrift/kumiko-framework/logging";
2
2
  import type { DbRunner } from "@cosmicdrift/kumiko-framework/db";
3
3
  import { type EscapeHatchAuditSink, type Registry, type TenantId, type UserDataExportSnippet } from "@cosmicdrift/kumiko-framework/engine";
4
4
  import type { getTemporal } from "@cosmicdrift/kumiko-framework/time";
@@ -1,4 +1,3 @@
1
- import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
2
1
  // User data export pipeline — GDPR Art. 15 (access) +
3
2
  // Art. 20 (data portability).
4
3
  //
@@ -20,30 +19,12 @@ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
20
19
  // user-data-rights-defaults/hooks/user.userdata-hook explicitly exposes
21
20
  // neither passwordHash nor roles (privileged columns).
22
21
  import { configuredPiiSubjectKms, decryptPiiFieldValues, isPiiCiphertext, } from "@cosmicdrift/kumiko-framework/crypto";
23
- import { collectEncryptedFieldNames, configuredEntityFieldEncryption, createTenantDb, decryptEntityFieldValues, selectMany, } from "@cosmicdrift/kumiko-framework/db";
22
+ import { collectEncryptedFieldNames, configuredEntityFieldEncryption, decryptEntityFieldValues, selectMany, } from "@cosmicdrift/kumiko-framework/db";
24
23
  import { EXT_USER_DATA, extensionUsageEscapeHatchReason, maskWriteOnlyFields, } from "@cosmicdrift/kumiko-framework/engine";
25
24
  import { runInSystemRowLevelSecurityScope } from "@cosmicdrift/kumiko-framework/internal/row-level-security";
26
- import { createEscapeHatchReporter, UNATTRIBUTED_ACTOR, } from "@cosmicdrift/kumiko-framework/pipeline";
27
25
  import { tenantMembershipsTable } from "../tenant/index.js";
26
+ import { buildHookDb } from "./build-hook-db.js";
28
27
  import { buildFileRefZipPath } from "./zip-path.js";
29
- function buildHookDb(db, tenantId, entry, args) {
30
- const report = createEscapeHatchReporter({
31
- handler: `${EXT_USER_DATA}:${entry.entityName}`,
32
- tenantId,
33
- actor: args.actor ?? UNATTRIBUTED_ACTOR,
34
- sink: args.escapeHatchAuditSink,
35
- log: args.escapeHatchAuditLog ?? createFallbackLogger("user-data-rights"),
36
- });
37
- return createTenantDb({
38
- db,
39
- tenantId,
40
- mode: "tenant",
41
- grants: {
42
- unsafeRaw: entry.escapeHatchReason !== undefined ? { reason: entry.escapeHatchReason } : undefined,
43
- report,
44
- },
45
- });
46
- }
47
28
  /**
48
29
  * Pure function: invokes all EXT_USER_DATA hooks for each tenant
49
30
  * membership and collects snippets into a UserExportBundle.
@@ -13,10 +13,7 @@
13
13
  // **Multi-use within TTL:** The token is NOT "consumed" on download, so the user
14
14
  // can download repeatedly until expiresAt. This matches Google-Takeout (7d) and
15
15
  // Facebook-Data-Download (4d).
16
- //
17
- // **Universal Web-Crypto API:** crypto.getRandomValues + crypto.subtle.digest
18
- // runs identically in Bun, Node 19+, and browsers, avoiding platform-specific
19
- // imports.
16
+ import { hashOpaqueToken } from "@cosmicdrift/kumiko-framework/crypto";
20
17
  /**
21
18
  * Generates a new download token. The plain token is sent to the user by email;
22
19
  * the hash is stored in the token database row.
@@ -36,9 +33,7 @@ export async function generateDownloadToken() {
36
33
  * database (no constant-time comparison, see the header comment).
37
34
  */
38
35
  export async function hashDownloadToken(plain) {
39
- const encoded = new TextEncoder().encode(plain);
40
- const digest = await crypto.subtle.digest("SHA-256", encoded);
41
- return uint8ArrayToHex(new Uint8Array(digest));
36
+ return hashOpaqueToken(plain);
42
37
  }
43
38
  function uint8ArrayToBase64Url(bytes) {
44
39
  // btoa expects a binary string. atob/btoa are universal in Bun, Node, and browsers.
@@ -48,10 +43,3 @@ function uint8ArrayToBase64Url(bytes) {
48
43
  }
49
44
  return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
50
45
  }
51
- function uint8ArrayToHex(bytes) {
52
- let out = "";
53
- for (let i = 0; i < bytes.length; i++) {
54
- out += bytes[i].toString(16).padStart(2, "0"); // @cast-boundary dynamic-key
55
- }
56
- return out;
57
- }
@@ -14,6 +14,7 @@ import { useDispatcher, usePrimitives, useQuery, useTranslation, } from "@cosmic
14
14
  import { postWithDownload } from "@cosmicdrift/kumiko-renderer/web";
15
15
  import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
16
16
  import { useEffect, useState } from "react";
17
+ import { StatusBanner } from "../../shared/web/status-banner.js";
17
18
  import { EXPORT_JOB_STATUS, UserDataRightsHandlers, UserDataRightsQueries, } from "./constants.js";
18
19
  // The export job runs asynchronously (worker-Lane-Cron, ~1 Min). While it is
19
20
  // pending/running, the screen polls its status so the download appears without
@@ -34,17 +35,6 @@ export function formatDate(iso) {
34
35
  const tIndex = iso.indexOf("T");
35
36
  return tIndex > 0 ? iso.slice(0, tIndex) : iso;
36
37
  }
37
- function StatusBanner({ status }) {
38
- const t = useTranslation();
39
- const { Banner } = usePrimitives();
40
- if (status.kind === "success") {
41
- return _jsx(Banner, { variant: "info", children: t(status.messageKey) });
42
- }
43
- if (status.kind === "error") {
44
- return _jsx(Banner, { variant: "error", children: t(status.messageKey) });
45
- }
46
- return null;
47
- }
48
38
  // Mounted by the renderer's ExtensionSectionMount (already wrapped in
49
39
  // <Section title={...} testId="section-extension-...">) — takes no props of
50
40
  // its own, ExtensionSectionProps (entityName/entityId/...) are unused since
@@ -11,6 +11,7 @@ import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
11
11
  import { useState } from "react";
12
12
  import { AuthHandlers } from "../../auth-email-password/web/constants.js";
13
13
  import { requestEmailVerification } from "../../auth-email-password/web/index.js";
14
+ import { StatusBanner } from "../../shared/web/status-banner.js";
14
15
  import { UserProfileHandlers } from "./constants.js";
15
16
  // Dispatcher failures carry an i18nKey only when the handler sets one —
16
17
  // boundary read with a generic fallback.
@@ -18,17 +19,6 @@ function failureKey(error) {
18
19
  const key = propertyOf(error, "i18nKey");
19
20
  return typeof key === "string" ? key : "profile.errors.generic";
20
21
  }
21
- function StatusBanner({ status }) {
22
- const t = useTranslation();
23
- const { Banner } = usePrimitives();
24
- if (status.kind === "success") {
25
- return _jsx(Banner, { variant: "info", children: t(status.messageKey) });
26
- }
27
- if (status.kind === "error") {
28
- return _jsx(Banner, { variant: "error", children: t(status.messageKey) });
29
- }
30
- return null;
31
- }
32
22
  // Mounted by the renderer's ExtensionSectionMount (already wrapped in
33
23
  // <Section title={...} testId="section-extension-...">) — takes no props of
34
24
  // its own. Deliberately NOT a <Form>: RenderEdit already renders a host
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-bundled-features",
3
- "version": "0.404.1",
3
+ "version": "0.405.0",
4
4
  "description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
5
5
  "license": "MIT",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -570,20 +570,20 @@
570
570
  }
571
571
  },
572
572
  "dependencies": {
573
- "@cosmicdrift/kumiko-framework": "0.404.1",
574
- "@cosmicdrift/kumiko-renderer": "0.404.1",
575
- "@cosmicdrift/kumiko-types": "0.404.1",
573
+ "@cosmicdrift/kumiko-framework": "0.405.0",
574
+ "@cosmicdrift/kumiko-renderer": "0.405.0",
575
+ "@cosmicdrift/kumiko-types": "0.405.0",
576
576
  "@mollie/api-client": "^4.6.0",
577
577
  "@node-rs/argon2": "^2.2.2",
578
- "@tiptap/core": "^3.32.1",
579
- "@tiptap/extension-link": "^3.32.1",
580
- "@tiptap/extension-list": "^3.32.1",
581
- "@tiptap/extension-table": "^3.32.1",
582
- "@tiptap/html": "^3.32.1",
583
- "@tiptap/extensions": "^3.32.1",
584
- "@tiptap/pm": "^3.32.1",
585
- "@tiptap/react": "^3.32.1",
586
- "@tiptap/starter-kit": "^3.32.1",
578
+ "@tiptap/core": "^3.32.2",
579
+ "@tiptap/extension-link": "^3.32.2",
580
+ "@tiptap/extension-list": "^3.32.2",
581
+ "@tiptap/extension-table": "^3.32.2",
582
+ "@tiptap/html": "^3.32.2",
583
+ "@tiptap/extensions": "^3.32.2",
584
+ "@tiptap/pm": "^3.32.2",
585
+ "@tiptap/react": "^3.32.2",
586
+ "@tiptap/starter-kit": "^3.32.2",
587
587
  "@types/mailparser": "^3.9.0",
588
588
  "@types/qrcode": "^1.5.6",
589
589
  "clsx": "^2.1.1",
@@ -1166,17 +1166,17 @@
1166
1166
  ],
1167
1167
  "devDependencies": {
1168
1168
  "@testing-library/user-event": "^14.6.8",
1169
- "@cosmicdrift/kumiko-locale-de": "0.404.1",
1170
- "@cosmicdrift/kumiko-locale-es": "0.404.1",
1171
- "@cosmicdrift/kumiko-locale-fr": "0.404.1",
1172
- "@cosmicdrift/kumiko-locale-it": "0.404.1",
1173
- "@cosmicdrift/kumiko-renderer-mail-html": "0.404.1",
1169
+ "@cosmicdrift/kumiko-locale-de": "0.405.0",
1170
+ "@cosmicdrift/kumiko-locale-es": "0.405.0",
1171
+ "@cosmicdrift/kumiko-locale-fr": "0.405.0",
1172
+ "@cosmicdrift/kumiko-locale-it": "0.405.0",
1173
+ "@cosmicdrift/kumiko-renderer-mail-html": "0.405.0",
1174
1174
  "jsqr": "^1.4.0",
1175
1175
  "unpdf": "^1.9.1",
1176
- "@cosmicdrift/kumiko-testing": "0.404.1"
1176
+ "@cosmicdrift/kumiko-testing": "0.405.0"
1177
1177
  },
1178
1178
  "peerDependencies": {
1179
- "@cosmicdrift/kumiko-testing": "0.404.1"
1179
+ "@cosmicdrift/kumiko-testing": "0.405.0"
1180
1180
  },
1181
1181
  "peerDependenciesMeta": {
1182
1182
  "@cosmicdrift/kumiko-testing": {
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.405.0",
4
+ "type": "improvement",
5
+ "title": "Login-path redirect hook and topbar without UserMenu",
6
+ "detail": "auth-email-password/web exports useRedirectAuthedFromLogin({ loginPath, target }), which replaces the URL with target while a signed-in user sits on the login path, also after Browser-Back, and isAuthedOnLoginPath. DefaultTopbarActions takes userMenu (default true) to hide the UserMenu and themeToggleTestId for the ThemeToggle button."
7
+ },
2
8
  {
3
9
  "version": "0.394.0",
4
10
  "type": "improvement",
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.405.0",
4
+ "type": "improvement",
5
+ "title": "MFA setup token uses the shared HMAC token codec",
6
+ "detail": "signMfaSetupToken and verifyMfaSetupToken run on createHmacTokenCodec with the domain mfa-setup. Tokens issued before the change still verify, and new tokens are byte-identical for the same input. The challenge and preauth-setup tokens share one payload guard, and signed-token and the inbound-mail OAuth state use the same HMAC signature helper."
7
+ },
2
8
  {
3
9
  "version": "0.391.0",
4
10
  "type": "fix",
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.405.0",
4
+ "type": "improvement",
5
+ "title": "Provider helpers shared through billing-foundation",
6
+ "detail": "billing-foundation exports validateOneOffPriceIds, parseStoredSecret, createTtlPriceCache and hasSeenProviderEvent. subscription-stripe and subscription-paddle use them instead of their own copies, with the same error texts as before. The subscription projection reuses one apply body for created/updated and one for canceled/invoice-paid; the exported apply names stay."
7
+ },
2
8
  {
3
9
  "version": "0.399.0",
4
10
  "type": "improvement",
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.405.0",
4
+ "type": "improvement",
5
+ "title": "Bundled features share internal helpers",
6
+ "detail": "Access resolution for folders, ledger, notes-history and tags, the folders/tags write hook, the system-mode TenantDb cache of the re-encryption and rotation jobs, the mail locale templates of auth-email-password and user-data-rights, extension option collection for delivery and renderers, PAT scope parsing, user-data-rights hook DBs, unique-constraint failure checks, tenant member PII decryption, the status banner, the invite-accept request, the tenant label and the jobs subject parser each live in one internal module now. Empty onRegister callbacks are dropped. No behavior change."
7
+ },
2
8
  {
3
9
  "version": "0.364.0",
4
10
  "type": "improvement",
@@ -1,4 +1,10 @@
1
1
  [
2
+ {
3
+ "version": "0.405.0",
4
+ "type": "improvement",
5
+ "title": "archiveAndDeleteTenantRows for tenant-destroy hooks",
6
+ "detail": "@cosmicdrift/kumiko-bundled-features/tenant-lifecycle exports archiveAndDeleteTenantRows(ctx, table, aggregateType, escapeHatchReason), which archives each row's event stream and then deletes the tenant's rows, plus the TENANT_DESTROY_ARCHIVED_BY and TENANT_DESTROY_ARCHIVE_REASON constants. inbound-mail-foundation uses the helper, billing-foundation the constants."
7
+ },
2
8
  {
3
9
  "version": "0.389.0",
4
10
  "type": "fix",