@cosmicdrift/kumiko-bundled-features 0.398.0 → 0.400.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 (94) hide show
  1. package/dist/auth-mfa/schema/user-mfa.d.ts +4 -4
  2. package/dist/billing-foundation/consumer-protection/consent-text.js +4 -4
  3. package/dist/billing-foundation/entities.d.ts +2 -2
  4. package/dist/billing-foundation/projection.d.ts +2 -2
  5. package/dist/cap-counter/entity.d.ts +3 -3
  6. package/dist/channel-in-app/constants.js +4 -9
  7. package/dist/channel-in-app/feature.js +1 -1
  8. package/dist/channel-in-app/handlers/inbox.query.d.ts +4 -1
  9. package/dist/channel-in-app/handlers/inbox.query.js +23 -8
  10. package/dist/channel-in-app/handlers/unread-count.query.js +2 -9
  11. package/dist/channel-in-app/in-app-channel.js +23 -11
  12. package/dist/channel-in-app/in-app-target.d.ts +5 -0
  13. package/dist/channel-in-app/in-app-target.js +34 -0
  14. package/dist/channel-in-app/index.d.ts +1 -0
  15. package/dist/channel-in-app/index.js +1 -0
  16. package/dist/compliance-profiles/schema/profile-selection.d.ts +2 -2
  17. package/dist/custom-fields/entity.d.ts +23 -3
  18. package/dist/delivery/tables.d.ts +11 -1
  19. package/dist/documents/aggregate-id.d.ts +2 -0
  20. package/dist/documents/aggregate-id.js +12 -0
  21. package/dist/documents/capture.d.ts +14 -0
  22. package/dist/documents/capture.js +65 -0
  23. package/dist/documents/constants.d.ts +23 -0
  24. package/dist/documents/constants.js +21 -0
  25. package/dist/documents/ensure-link.d.ts +17 -0
  26. package/dist/documents/ensure-link.js +20 -0
  27. package/dist/documents/entity.d.ts +76 -0
  28. package/dist/documents/entity.js +84 -0
  29. package/dist/documents/executor.d.ts +6 -0
  30. package/dist/documents/executor.js +8 -0
  31. package/dist/documents/expiry.d.ts +9 -0
  32. package/dist/documents/expiry.js +20 -0
  33. package/dist/documents/feature.d.ts +33 -0
  34. package/dist/documents/feature.js +111 -0
  35. package/dist/documents/handlers/import.write.d.ts +23 -0
  36. package/dist/documents/handlers/import.write.js +104 -0
  37. package/dist/documents/handlers/link.write.d.ts +18 -0
  38. package/dist/documents/handlers/link.write.js +61 -0
  39. package/dist/documents/i18n.d.ts +6 -0
  40. package/dist/documents/i18n.js +33 -0
  41. package/dist/documents/index.d.ts +7 -0
  42. package/dist/documents/index.js +6 -0
  43. package/dist/documents/pending-file-guard.d.ts +2 -0
  44. package/dist/documents/pending-file-guard.js +29 -0
  45. package/dist/documents/queries/expiry-overview.query.d.ts +10 -0
  46. package/dist/documents/queries/expiry-overview.query.js +41 -0
  47. package/dist/documents/queries/for-record.query.d.ts +90 -0
  48. package/dist/documents/queries/for-record.query.js +54 -0
  49. package/dist/documents/queries/list-page.d.ts +19 -0
  50. package/dist/documents/queries/list-page.js +36 -0
  51. package/dist/documents/queries/overview.query.d.ts +32 -0
  52. package/dist/documents/queries/overview.query.js +41 -0
  53. package/dist/documents/schemas.d.ts +93 -0
  54. package/dist/documents/schemas.js +51 -0
  55. package/dist/documents/screens.d.ts +3 -0
  56. package/dist/documents/screens.js +76 -0
  57. package/dist/documents/tab.d.ts +4 -0
  58. package/dist/documents/tab.js +42 -0
  59. package/dist/documents/target-write-check.d.ts +3 -0
  60. package/dist/documents/target-write-check.js +25 -0
  61. package/dist/documents/write-guard.d.ts +6 -0
  62. package/dist/documents/write-guard.js +46 -0
  63. package/dist/inbound-mail-foundation/entities.d.ts +17 -7
  64. package/dist/inbound-mail-foundation/ingest-failures.d.ts +3 -3
  65. package/dist/inbound-mail-foundation/projection.d.ts +15 -5
  66. package/dist/inbound-mail-foundation/quarantine-entities.d.ts +3 -3
  67. package/dist/jobs/job-run-table.d.ts +4 -4
  68. package/dist/ledger/entity.d.ts +8 -8
  69. package/dist/managed-pages/table.d.ts +24 -4
  70. package/dist/metrics/compute.d.ts +3 -0
  71. package/dist/metrics/compute.js +10 -3
  72. package/dist/metrics/feature.js +6 -2
  73. package/dist/metrics/types.d.ts +5 -1
  74. package/dist/metrics/validate.js +3 -0
  75. package/dist/personal-access-tokens/schema/api-token.d.ts +3 -3
  76. package/dist/readiness/schema/probe-run.d.ts +60 -20
  77. package/dist/secrets/table.d.ts +1 -1
  78. package/dist/sessions/schema/user-session.d.ts +4 -4
  79. package/dist/shared/purge-row-file-refs.js +5 -4
  80. package/dist/template-resolver/table.d.ts +12 -12
  81. package/dist/template-resolver/user-content-table.d.ts +4 -4
  82. package/dist/tenant/invitation-table.d.ts +6 -6
  83. package/dist/tenant/schema/tenant.d.ts +32 -12
  84. package/dist/tier-engine/entity.d.ts +1 -1
  85. package/dist/tier-engine/tier-resolver.d.ts +1 -1
  86. package/dist/user/schema/user.d.ts +28 -8
  87. package/dist/user-data-rights/schema/download-attempt.d.ts +2 -2
  88. package/dist/user-data-rights/schema/download-token.d.ts +8 -8
  89. package/dist/user-data-rights/schema/export-job.d.ts +12 -12
  90. package/dist/waitlist/entity.d.ts +8 -8
  91. package/package.json +19 -11
  92. package/src/billing-foundation/changes.json +6 -0
  93. package/src/channel-in-app/changes.json +6 -0
  94. package/src/metrics/changes.json +6 -0
@@ -21,7 +21,7 @@ export declare const userMfaEntity: import("@cosmicdrift/kumiko-types/fields").E
21
21
  readonly min?: string;
22
22
  readonly max?: string;
23
23
  readonly locale?: string;
24
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
24
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
25
25
  required: true;
26
26
  };
27
27
  readonly lastUsedAt: {
@@ -37,7 +37,7 @@ export declare const userMfaEntity: import("@cosmicdrift/kumiko-types/fields").E
37
37
  readonly min?: string;
38
38
  readonly max?: string;
39
39
  readonly locale?: string;
40
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
40
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
41
41
  required: false;
42
42
  };
43
43
  }, "tenant">;
@@ -64,7 +64,7 @@ export declare const userMfaTable: import("@cosmicdrift/kumiko-framework/db").En
64
64
  readonly min?: string;
65
65
  readonly max?: string;
66
66
  readonly locale?: string;
67
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
67
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
68
68
  required: true;
69
69
  };
70
70
  readonly lastUsedAt: {
@@ -80,7 +80,7 @@ export declare const userMfaTable: import("@cosmicdrift/kumiko-framework/db").En
80
80
  readonly min?: string;
81
81
  readonly max?: string;
82
82
  readonly locale?: string;
83
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
83
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
84
84
  required: false;
85
85
  };
86
86
  }, "tenant">>;
@@ -17,12 +17,12 @@ export const CONSENT_TEXTS = {
17
17
  };
18
18
  const DOCUMENTS_ACKNOWLEDGEMENT_TEXTS = {
19
19
  de: {
20
- withRefund: "Ich habe die AGB, die Erstattungsrichtlinie und die Datenschutzerklärung gelesen. Mit den AGB und der Erstattungsrichtlinie bin ich einverstanden.",
21
- withoutRefund: "Ich habe die AGB und die Datenschutzerklärung gelesen. Mit den AGB bin ich einverstanden.",
20
+ withRefund: "Ich habe die AGB und die Erstattungsrichtlinie gelesen und bin mit ihnen einverstanden.",
21
+ withoutRefund: "Ich habe die AGB gelesen und bin mit ihnen einverstanden.",
22
22
  },
23
23
  en: {
24
- withRefund: "I have read the Terms, the Refund Policy and the Privacy Policy, and I agree to the Terms and the Refund Policy.",
25
- withoutRefund: "I have read the Terms and the Privacy Policy, and I agree to the Terms.",
24
+ withRefund: "I have read and agree to the Terms and the Refund Policy.",
25
+ withoutRefund: "I have read and agree to the Terms.",
26
26
  },
27
27
  };
28
28
  export function legalLinksPerLocale(legalLinks) {
@@ -27,7 +27,7 @@ export declare const subscriptionEntity: import("@cosmicdrift/kumiko-types/field
27
27
  readonly min?: string;
28
28
  readonly max?: string;
29
29
  readonly locale?: string;
30
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
30
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
31
31
  required: true;
32
32
  };
33
33
  readonly cancelAt: {
@@ -43,7 +43,7 @@ export declare const subscriptionEntity: import("@cosmicdrift/kumiko-types/field
43
43
  readonly min?: string;
44
44
  readonly max?: string;
45
45
  readonly locale?: string;
46
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
46
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
47
47
  required: false;
48
48
  };
49
49
  }, "tenant">;
@@ -28,7 +28,7 @@ export declare const subscriptionsProjectionTable: import("@cosmicdrift/kumiko-f
28
28
  readonly min?: string;
29
29
  readonly max?: string;
30
30
  readonly locale?: string;
31
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
31
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
32
32
  required: true;
33
33
  };
34
34
  readonly cancelAt: {
@@ -44,7 +44,7 @@ export declare const subscriptionsProjectionTable: import("@cosmicdrift/kumiko-f
44
44
  readonly min?: string;
45
45
  readonly max?: string;
46
46
  readonly locale?: string;
47
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
47
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
48
48
  required: false;
49
49
  };
50
50
  }, "tenant">>;
@@ -12,7 +12,7 @@ export declare const capCounterEntity: import("@cosmicdrift/kumiko-types/fields"
12
12
  readonly sensitive?: boolean;
13
13
  readonly default?: number;
14
14
  readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
15
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
15
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
16
16
  required: true;
17
17
  };
18
18
  readonly periodStart: {
@@ -28,7 +28,7 @@ export declare const capCounterEntity: import("@cosmicdrift/kumiko-types/fields"
28
28
  readonly min?: string;
29
29
  readonly max?: string;
30
30
  readonly locale?: string;
31
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
31
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
32
32
  required: true;
33
33
  };
34
34
  readonly lastSoftWarnedAt: {
@@ -44,7 +44,7 @@ export declare const capCounterEntity: import("@cosmicdrift/kumiko-types/fields"
44
44
  readonly min?: string;
45
45
  readonly max?: string;
46
46
  readonly locale?: string;
47
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
47
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
48
48
  required: false;
49
49
  };
50
50
  }, "tenant">;
@@ -1,9 +1,4 @@
1
- export const CHANNEL_IN_APP_FEATURE = "channel-in-app";
2
- export const InAppHandlers = {
3
- markRead: "channel-in-app:write:mark-read",
4
- markAllRead: "channel-in-app:write:mark-all-read",
5
- };
6
- export const InAppQueries = {
7
- inbox: "channel-in-app:query:inbox",
8
- unreadCount: "channel-in-app:query:unread-count",
9
- };
1
+ import { IN_APP_NOTIFICATION_FEATURE, IN_APP_NOTIFICATION_QUERIES, IN_APP_NOTIFICATION_WRITES, } from "@cosmicdrift/kumiko-types/in-app-notification-types";
2
+ export const CHANNEL_IN_APP_FEATURE = IN_APP_NOTIFICATION_FEATURE;
3
+ export const InAppHandlers = IN_APP_NOTIFICATION_WRITES;
4
+ export const InAppQueries = IN_APP_NOTIFICATION_QUERIES;
@@ -8,7 +8,7 @@ import { inAppChannel } from "./in-app-channel.js";
8
8
  import { inAppMessagesTableMeta } from "./tables.js";
9
9
  export function createChannelInAppFeature() {
10
10
  return defineFeature("channel-in-app", (r) => {
11
- r.describe("Persists notifications to an in-app inbox table so users can retrieve them via `handlers.inbox` and track unread state with `handlers.markRead` / `handlers.markAllRead` and `queries.unreadCount`. Requires `delivery`; no external service needed \u2014 messages are stored in the app's own database.");
11
+ r.describe("Persists notifications to an in-app inbox table so users can page through them via `queries.inbox` (cursor, total, parsed `target`) and track unread state with `handlers.markRead` / `handlers.markAllRead` and `queries.unreadCount`. A notification links to a screen when `data.target` is set with `inAppTarget(screenId, entityId?)`. The renderer shell shows a bell with a live unread badge whenever this feature is mounted. Requires `delivery`; no external service needed \u2014 messages are stored in the app's own database.");
12
12
  r.uiHints({
13
13
  displayLabel: "In-App Inbox",
14
14
  category: "notifications",
@@ -2,6 +2,9 @@ import * as z from "zod";
2
2
  export declare const inboxQuery: import("@cosmicdrift/kumiko-types/define-handler").QueryHandlerDefinition<"inbox", z.ZodObject<{
3
3
  limit: z.ZodDefault<z.ZodNumber>;
4
4
  unreadOnly: z.ZodDefault<z.ZodBoolean>;
5
+ cursor: z.ZodOptional<z.ZodString>;
5
6
  }, z.core.$strip>, {
6
- rows: readonly any[];
7
+ rows: any[];
8
+ nextCursor: string | null;
9
+ total: number;
7
10
  }, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
@@ -1,12 +1,15 @@
1
1
  import { selectMany } from "@cosmicdrift/kumiko-framework/db";
2
2
  import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
3
3
  import * as z from "zod";
4
+ import { parseStoredNotificationData, targetOfNotificationData } from "../in-app-target.js";
4
5
  import { inAppMessagesTable } from "../tables.js";
6
+ const SERIAL_ID_PATTERN = /^\d{1,15}$/;
5
7
  export const inboxQuery = defineQueryHandler({
6
8
  name: "inbox",
7
9
  schema: z.object({
8
10
  limit: z.number().min(1).max(100).default(50),
9
11
  unreadOnly: z.boolean().default(false),
12
+ cursor: z.string().regex(SERIAL_ID_PATTERN).optional(),
10
13
  }),
11
14
  access: {
12
15
  openToAll: {
@@ -14,15 +17,27 @@ export const inboxQuery = defineQueryHandler({
14
17
  "inAppMessagesTable by the caller's own id",
15
18
  },
16
19
  },
17
- description: "Lists the calling user's own in-app notification messages newest-first, optionally only the unread ones; use it to show or inspect a user's notification inbox.",
20
+ description: "Lists the calling user's own in-app notification messages newest-first with a parsed navigation target, optionally only the unread ones. Pass the returned nextCursor as cursor for the next page; total counts all matching messages, not just the page. Use it to show or inspect a user's notification inbox.",
18
21
  handler: async (query, ctx) => {
19
- const where = { userId: query.user.id };
20
- if (query.payload.unreadOnly)
21
- where["isRead"] = false;
22
- const rows = await selectMany(ctx.db, inAppMessagesTable, where, {
23
- limit: query.payload.limit,
24
- orderBy: { col: "createdAt", direction: "desc" },
22
+ const { limit, unreadOnly, cursor } = query.payload;
23
+ const ownMessages = { userId: query.user.id };
24
+ if (unreadOnly)
25
+ ownMessages["isRead"] = false;
26
+ const pageWhere = cursor === undefined ? ownMessages : { ...ownMessages, id: { lt: Number(cursor) } };
27
+ // One extra row tells whether another page exists without a second query.
28
+ const fetched = await selectMany(ctx.db, inAppMessagesTable, pageWhere, {
29
+ limit: limit + 1,
30
+ orderBy: { col: "id", direction: "desc" },
25
31
  });
26
- return { rows };
32
+ const page = fetched.slice(0, limit);
33
+ const lastRow = page[page.length - 1];
34
+ const nextCursor = fetched.length > limit && lastRow ? String(lastRow["id"]) : null;
35
+ const [totalRow] = await ctx.db.aggregate(inAppMessagesTable, { measure: { fn: "count" } }, ownMessages);
36
+ const rows = page.map((row) => {
37
+ const storedData = row["data"];
38
+ const data = parseStoredNotificationData(typeof storedData === "string" ? storedData : null);
39
+ return { ...row, target: targetOfNotificationData(data) };
40
+ });
41
+ return { rows, nextCursor, total: totalRow?.value ?? 0 };
27
42
  },
28
43
  });
@@ -1,4 +1,3 @@
1
- import { selectMany } from "@cosmicdrift/kumiko-framework/db";
2
1
  import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
3
2
  import * as z from "zod";
4
3
  import { inAppMessagesTable } from "../tables.js";
@@ -13,13 +12,7 @@ export const unreadCountQuery = defineQueryHandler({
13
12
  },
14
13
  description: "Counts the calling user's unread in-app notification messages; use it for an inbox badge or to check whether a user has pending notifications.",
15
14
  handler: async (query, ctx) => {
16
- // The query helpers in db/query.ts have no aggregate helper, so selectMany returns all matching
17
- // rows and count() runs in JS. This is acceptable because unread counts are low-cardinality and
18
- // user-scoped, with at most a few hundred rows; use raw .unsafe() with COUNT(*) if that grows.
19
- const rows = await selectMany(ctx.db, inAppMessagesTable, {
20
- userId: query.user.id,
21
- isRead: false,
22
- });
23
- return { count: rows.length };
15
+ const [countRow] = await ctx.db.aggregate(inAppMessagesTable, { measure: { fn: "count" } }, { userId: query.user.id, isRead: false });
16
+ return { count: countRow?.value ?? 0 };
24
17
  },
25
18
  });
@@ -1,5 +1,9 @@
1
1
  import { tenantChannel } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
3
+ import { IN_APP_NOTIFICATION_DELIVERED_EVENT } from "@cosmicdrift/kumiko-types/in-app-notification-types";
4
+ import { targetOfNotificationData } from "./in-app-target.js";
2
5
  import { inAppMessagesTable } from "./tables.js";
6
+ const log = createFallbackLogger("channel-in-app");
3
7
  export const inAppChannel = {
4
8
  name: "inApp",
5
9
  mode: "inline",
@@ -10,24 +14,32 @@ export const inAppChannel = {
10
14
  async send(address, message, ctx) {
11
15
  // address is the user-id string after the ES migration — keep it as-is.
12
16
  const userId = address;
17
+ // A malformed target drops only the link, never the notification.
18
+ const target = targetOfNotificationData(message.data);
19
+ const storedData = message.data === undefined
20
+ ? null
21
+ : JSON.stringify({ ...message.data, target: target ?? undefined });
13
22
  const row = await ctx.db.insertOne(inAppMessagesTable, {
14
23
  userId,
15
24
  notificationType: message.notificationType,
16
25
  title: message.title,
17
26
  body: message.body ?? null,
18
- data: message.data ? JSON.stringify(message.data) : null,
27
+ data: storedData,
19
28
  });
20
29
  if (ctx.sseBroker) {
21
- await ctx.sseBroker.pushToChannel(tenantChannel(ctx.tenantId), {
22
- type: "channel-in-app:event:delivered",
23
- data: {
24
- id: row?.id,
25
- userId,
26
- notificationType: message.notificationType,
27
- title: message.title,
28
- body: message.body,
29
- },
30
- });
30
+ // The row is stored, so a failing push (e.g. Redis down) must not turn the delivery into
31
+ // a failure that gets retried and stored twice. Clients fetch the inbox on reconnect.
32
+ try {
33
+ await ctx.sseBroker.pushToChannel(tenantChannel(ctx.tenantId), {
34
+ type: IN_APP_NOTIFICATION_DELIVERED_EVENT,
35
+ data: { id: row?.id, userId, notificationType: message.notificationType },
36
+ });
37
+ }
38
+ catch (error) {
39
+ log.warn("in-app SSE push failed; the notification is stored", {
40
+ error: error instanceof Error ? error.message : String(error),
41
+ });
42
+ }
31
43
  }
32
44
  return { status: "sent", address };
33
45
  },
@@ -0,0 +1,5 @@
1
+ import type { InAppNotificationTarget } from "@cosmicdrift/kumiko-types/in-app-notification-types";
2
+ export declare function inAppTarget(screenId: string, entityId?: string): InAppNotificationTarget;
3
+ export declare function parseInAppTarget(value: unknown): InAppNotificationTarget | null;
4
+ export declare function targetOfNotificationData(data: unknown): InAppNotificationTarget | null;
5
+ export declare function parseStoredNotificationData(stored: string | null): unknown;
@@ -0,0 +1,34 @@
1
+ import * as z from "zod";
2
+ const SCREEN_ID_PATTERN = /^[^\s:]+:screen:[^\s:]+$/;
3
+ const targetSchema = z.object({
4
+ screenId: z.string().regex(SCREEN_ID_PATTERN),
5
+ entityId: z.string().min(1).optional(),
6
+ });
7
+ export function inAppTarget(screenId, entityId) {
8
+ return entityId === undefined ? { screenId } : { screenId, entityId };
9
+ }
10
+ // Returns null for anything that is not a well-formed target, so a malformed `data.target`
11
+ // drops only the link and never the notification.
12
+ export function parseInAppTarget(value) {
13
+ const parsed = targetSchema.safeParse(value);
14
+ if (!parsed.success)
15
+ return null;
16
+ const { screenId, entityId } = parsed.data;
17
+ return inAppTarget(screenId, entityId);
18
+ }
19
+ // Reads `target` out of the stored notification data (a JSON string) or out of a raw data object.
20
+ export function targetOfNotificationData(data) {
21
+ if (typeof data !== "object" || data === null || !("target" in data))
22
+ return null;
23
+ return parseInAppTarget(data.target);
24
+ }
25
+ export function parseStoredNotificationData(stored) {
26
+ if (stored === null)
27
+ return null;
28
+ try {
29
+ return JSON.parse(stored);
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
@@ -1,4 +1,5 @@
1
1
  export { CHANNEL_IN_APP_FEATURE, InAppHandlers, InAppQueries } from "./constants.ts";
2
2
  export { createChannelInAppFeature } from "./feature.ts";
3
3
  export { inAppChannel } from "./in-app-channel.ts";
4
+ export { inAppTarget } from "./in-app-target.ts";
4
5
  export { inAppMessagesTable } from "./tables.ts";
@@ -1,4 +1,5 @@
1
1
  export { CHANNEL_IN_APP_FEATURE, InAppHandlers, InAppQueries } from "./constants.js";
2
2
  export { createChannelInAppFeature } from "./feature.js";
3
3
  export { inAppChannel } from "./in-app-channel.js";
4
+ export { inAppTarget } from "./in-app-target.js";
4
5
  export { inAppMessagesTable } from "./tables.js";
@@ -21,7 +21,7 @@ export declare const tenantComplianceProfileEntity: import("@cosmicdrift/kumiko-
21
21
  readonly optionsQueryPayload?: import("@cosmicdrift/kumiko-types/fields").OptionsQueryPayload;
22
22
  readonly optionsAvailabilityQuery?: string;
23
23
  readonly conditionalOptions?: readonly import("@cosmicdrift/kumiko-types/fields").SelectConditionalOptions<"de-hr-dsgvo-hgb" | "eu-dsgvo" | "minimal-no-region" | "swiss-dsg">[] | undefined;
24
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
24
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
25
25
  required: true;
26
26
  };
27
27
  readonly override: import("@cosmicdrift/kumiko-types/fields").EntityLongTextFieldDef & {
@@ -51,7 +51,7 @@ export declare const tenantComplianceProfileTable: import("@cosmicdrift/kumiko-f
51
51
  readonly optionsQueryPayload?: import("@cosmicdrift/kumiko-types/fields").OptionsQueryPayload;
52
52
  readonly optionsAvailabilityQuery?: string;
53
53
  readonly conditionalOptions?: readonly import("@cosmicdrift/kumiko-types/fields").SelectConditionalOptions<"de-hr-dsgvo-hgb" | "eu-dsgvo" | "minimal-no-region" | "swiss-dsg">[] | undefined;
54
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
54
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
55
55
  required: true;
56
56
  };
57
57
  readonly override: import("@cosmicdrift/kumiko-types/fields").EntityLongTextFieldDef & {
@@ -8,11 +8,31 @@ export declare const fieldDefinitionEntity: import("@cosmicdrift/kumiko-types/fi
8
8
  readonly type: import("@cosmicdrift/kumiko-types/fields").EntityTextFieldDef & {
9
9
  required: true;
10
10
  };
11
- readonly required: import("@cosmicdrift/kumiko-types/fields").BooleanFieldDef & {
11
+ readonly required: {
12
+ readonly type: "boolean";
13
+ readonly description?: string;
14
+ readonly required?: boolean;
15
+ readonly sortable?: boolean;
16
+ readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
17
+ readonly filterable?: boolean;
18
+ readonly sensitive?: boolean;
19
+ readonly default?: boolean;
20
+ readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
21
+ } & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
12
22
  required: true;
13
23
  default: boolean;
14
24
  };
15
- readonly searchable: import("@cosmicdrift/kumiko-types/fields").BooleanFieldDef & {
25
+ readonly searchable: {
26
+ readonly type: "boolean";
27
+ readonly description?: string;
28
+ readonly required?: boolean;
29
+ readonly sortable?: boolean;
30
+ readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
31
+ readonly filterable?: boolean;
32
+ readonly sensitive?: boolean;
33
+ readonly default?: boolean;
34
+ readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
35
+ } & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
16
36
  required: true;
17
37
  default: boolean;
18
38
  };
@@ -33,7 +53,7 @@ export declare const fieldDefinitionEntity: import("@cosmicdrift/kumiko-types/fi
33
53
  readonly field: string;
34
54
  };
35
55
  readonly grouping?: boolean;
36
- } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & {
56
+ } & import("@cosmicdrift/kumiko-types/fields").ResolvedPiiFlags & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
37
57
  required: true;
38
58
  };
39
59
  readonly serializedField: import("@cosmicdrift/kumiko-types/fields").EntityTextFieldDef & {
@@ -11,7 +11,17 @@ export declare const notificationPreferenceEntity: import("@cosmicdrift/kumiko-t
11
11
  readonly channel: import("@cosmicdrift/kumiko-types/fields").EntityTextFieldDef & {
12
12
  required: true;
13
13
  };
14
- readonly enabled: import("@cosmicdrift/kumiko-types/fields").BooleanFieldDef & {
14
+ readonly enabled: {
15
+ readonly type: "boolean";
16
+ readonly description?: string;
17
+ readonly required?: boolean;
18
+ readonly sortable?: boolean;
19
+ readonly sortNulls?: import("@cosmicdrift/kumiko-types/fields").SortNulls;
20
+ readonly filterable?: boolean;
21
+ readonly sensitive?: boolean;
22
+ readonly default?: boolean;
23
+ readonly access?: import("@cosmicdrift/kumiko-types/fields").FieldAccess;
24
+ } & import("@cosmicdrift/kumiko-types/fields").FieldStateConditions & {
15
25
  required: false;
16
26
  default: boolean;
17
27
  };
@@ -0,0 +1,2 @@
1
+ export declare function documentIdForFile(tenantId: string, fileRefId: string): string;
2
+ export declare function documentLinkAggregateId(tenantId: string, documentId: string, entityType: string, entityId: string): string;
@@ -0,0 +1,12 @@
1
+ import { v5 as uuidv5 } from "uuid";
2
+ // Frozen: changing a namespace re-keys every derived stream and breaks replay.
3
+ const DOCUMENT_FOR_FILE_NAMESPACE = "6d2f7e41-3c58-4b0a-9e17-5a4c8d1b2f93";
4
+ const DOCUMENT_LINK_NAMESPACE = "b83a1c6e-9f20-4d57-a1e4-7c0d52f68b19";
5
+ // @wrapper-known uuid-domain
6
+ export function documentIdForFile(tenantId, fileRefId) {
7
+ return uuidv5(`${tenantId}|${fileRefId}`, DOCUMENT_FOR_FILE_NAMESPACE);
8
+ }
9
+ // @wrapper-known uuid-domain
10
+ export function documentLinkAggregateId(tenantId, documentId, entityType, entityId) {
11
+ return uuidv5(`${tenantId}|${documentId}|${entityType}|${entityId}`, DOCUMENT_LINK_NAMESPACE);
12
+ }
@@ -0,0 +1,14 @@
1
+ import { type FeatureRegistrar } from "@cosmicdrift/kumiko-framework/engine";
2
+ import type { BootCheckContext } from "@cosmicdrift/kumiko-types/feature";
3
+ import type { DOCUMENTS_FEATURE_NAME } from "./constants.ts";
4
+ import { type LinkTarget } from "./ensure-link.ts";
5
+ import type { DocumentExecutors } from "./executor.ts";
6
+ export type DocumentCaptureRule = {
7
+ readonly entity: string;
8
+ readonly field: string;
9
+ readonly category: string;
10
+ readonly title?: (row: Readonly<Record<string, unknown>>) => string;
11
+ readonly links?: (row: Readonly<Record<string, unknown>>) => readonly LinkTarget[];
12
+ };
13
+ export declare function registerCapture(r: FeatureRegistrar<typeof DOCUMENTS_FEATURE_NAME>, executors: DocumentExecutors, rules: readonly DocumentCaptureRule[], linkTargets: readonly string[]): void;
14
+ export declare function validateCaptureRules({ features }: BootCheckContext, rules: readonly DocumentCaptureRule[], categories: readonly string[], linkTargets: readonly string[]): void;
@@ -0,0 +1,65 @@
1
+ import { createSystemUser, } from "@cosmicdrift/kumiko-framework/engine";
2
+ import { documentIdForFile } from "./aggregate-id.js";
3
+ import { ensureDocumentLink } from "./ensure-link.js";
4
+ const MAX_TITLE_LENGTH = 200;
5
+ async function captureFile(executors, rule, linkTargets, saved, fileRefId, user, db) {
6
+ const id = documentIdForFile(user.tenantId, fileRefId);
7
+ // The title never defaults to the file name, which can carry personal data.
8
+ const title = (rule.title?.(saved.data) ?? rule.category).slice(0, MAX_TITLE_LENGTH);
9
+ const created = await executors.document.create({ id, title, category: rule.category, file: fileRefId }, user, db);
10
+ // version_conflict: the stream exists already, so the file was captured before (and a document
11
+ // deleted since stays deleted).
12
+ if (!created.isSuccess && created.error.code !== "version_conflict") {
13
+ throw new Error(`documents capture failed for ${rule.entity}.${rule.field}: ${created.error.code}`);
14
+ }
15
+ // The gate hides rows from a caller without the registry; existence is the system user's question.
16
+ const live = await executors.document.detail({ id }, createSystemUser(user.tenantId), db);
17
+ // skip: the document was deleted after an earlier capture and stays deleted
18
+ if (live === null)
19
+ return;
20
+ const targets = [
21
+ { entityType: rule.entity, entityId: saved.id },
22
+ // Trusted: derived from the saved row, see DocumentCaptureRule.links.
23
+ ...(rule.links?.(saved.data) ?? []),
24
+ ].filter((target) => linkTargets.includes(target.entityType));
25
+ for (const target of targets) {
26
+ const linked = await ensureDocumentLink(executors, user, db, id, target);
27
+ if (!linked.isSuccess) {
28
+ throw new Error(`documents capture failed to link ${target.entityType}: ${linked.error.code}`);
29
+ }
30
+ }
31
+ }
32
+ export function registerCapture(r, executors, rules, linkTargets) {
33
+ for (const rule of rules) {
34
+ r.hook({
35
+ type: "postSave",
36
+ target: { allOf: rule.entity },
37
+ handler: async (result, ctx) => {
38
+ const value = result.changes[rule.field] ?? (result.isNew ? result.data[rule.field] : undefined);
39
+ // skip: the file field was not part of this save
40
+ if (typeof value !== "string")
41
+ return;
42
+ await captureFile(executors, rule, linkTargets, { id: String(result.id), data: result.data }, value, ctx.user, ctx.db);
43
+ },
44
+ });
45
+ }
46
+ }
47
+ export function validateCaptureRules({ features }, rules, categories, linkTargets) {
48
+ for (const rule of rules) {
49
+ const label = `documents capture ${rule.entity}.${rule.field}`;
50
+ if (!categories.includes(rule.category)) {
51
+ throw new Error(`${label}: category "${rule.category}" is not in the configured categories.`);
52
+ }
53
+ const entity = features.map((f) => f.entities?.[rule.entity]).find((e) => e !== undefined);
54
+ if (entity === undefined)
55
+ throw new Error(`${label}: entity "${rule.entity}" is not registered.`);
56
+ const field = entity.fields[rule.field];
57
+ if (field?.type !== "file" && field?.type !== "image") {
58
+ throw new Error(`${label}: the field must be a single file or image field.`);
59
+ }
60
+ }
61
+ const unknownTarget = linkTargets.find((name) => !features.some((f) => f.entities?.[name] !== undefined));
62
+ if (unknownTarget !== undefined) {
63
+ throw new Error(`documents linkTargets: entity "${unknownTarget}" is not registered.`);
64
+ }
65
+ }
@@ -0,0 +1,23 @@
1
+ import type { AccessRule } from "@cosmicdrift/kumiko-framework/engine";
2
+ export declare const DOCUMENTS_FEATURE_NAME = "documents";
3
+ export declare const DOCUMENT_ENTITY = "filed-document";
4
+ export declare const DOCUMENT_LINK_ENTITY = "filed-document-link";
5
+ export declare const DEFAULT_DOCUMENT_ACCESS: AccessRule;
6
+ export declare const DEFAULT_ADMIN_ROLES: readonly string[];
7
+ export declare const DEFAULT_EXPIRING_WITHIN_DAYS = 30;
8
+ export declare const DOCUMENTS_LIST_SCREEN_ID = "list";
9
+ export declare const DocumentsHandlers: {
10
+ readonly link: "documents:write:link";
11
+ readonly unlink: "documents:write:unlink";
12
+ readonly import: "documents:write:import";
13
+ };
14
+ export declare const DocumentsQueries: {
15
+ readonly list: "documents:query:filed-document:list";
16
+ readonly detail: "documents:query:filed-document:detail";
17
+ readonly forRecord: "documents:query:for-record";
18
+ readonly expiryOverview: "documents:query:expiry-overview";
19
+ readonly overview: "documents:query:overview";
20
+ };
21
+ export declare const EXPIRY_STATES: readonly ["expired", "expiring", "valid", "none"];
22
+ export type ExpiryState = (typeof EXPIRY_STATES)[number];
23
+ export declare const EXPIRING_FACET_VALUE = "expiring";
@@ -0,0 +1,21 @@
1
+ export const DOCUMENTS_FEATURE_NAME = "documents";
2
+ export const DOCUMENT_ENTITY = "filed-document";
3
+ export const DOCUMENT_LINK_ENTITY = "filed-document-link";
4
+ export const DEFAULT_DOCUMENT_ACCESS = { roles: ["TenantAdmin", "TenantMember"] };
5
+ export const DEFAULT_ADMIN_ROLES = ["TenantAdmin", "SystemAdmin"];
6
+ export const DEFAULT_EXPIRING_WITHIN_DAYS = 30;
7
+ export const DOCUMENTS_LIST_SCREEN_ID = "list";
8
+ export const DocumentsHandlers = {
9
+ link: "documents:write:link",
10
+ unlink: "documents:write:unlink",
11
+ import: "documents:write:import",
12
+ };
13
+ export const DocumentsQueries = {
14
+ list: "documents:query:filed-document:list",
15
+ detail: "documents:query:filed-document:detail",
16
+ forRecord: "documents:query:for-record",
17
+ expiryOverview: "documents:query:expiry-overview",
18
+ overview: "documents:query:overview",
19
+ };
20
+ export const EXPIRY_STATES = ["expired", "expiring", "valid", "none"];
21
+ export const EXPIRING_FACET_VALUE = "expiring";
@@ -0,0 +1,17 @@
1
+ import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
2
+ import type { SessionUser } from "@cosmicdrift/kumiko-framework/engine";
3
+ import type { DocumentExecutors } from "./executor.ts";
4
+ export type LinkTarget = {
5
+ readonly entityType: string;
6
+ readonly entityId: string;
7
+ };
8
+ export declare function ensureDocumentLink(executors: DocumentExecutors, user: SessionUser, db: TenantDb, documentId: string, target: LinkTarget): Promise<import("@cosmicdrift/kumiko-types/write-error-info-types").WriteFailure | {
9
+ readonly isSuccess: true;
10
+ readonly data: import("@cosmicdrift/kumiko-types/hooks").SaveContext;
11
+ readonly lifecycle?: import("@cosmicdrift/kumiko-types/hooks").LifecycleResult;
12
+ } | {
13
+ isSuccess: true;
14
+ data: {
15
+ id: string;
16
+ };
17
+ }>;
@@ -0,0 +1,20 @@
1
+ import { isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
2
+ import { documentLinkAggregateId } from "./aggregate-id.js";
3
+ // The link id is deterministic, so a removed link is restored rather than recreated and a
4
+ // concurrent first create converges on the row the winner wrote.
5
+ export async function ensureDocumentLink(executors, user, db, documentId, target) {
6
+ const id = documentLinkAggregateId(user.tenantId, documentId, target.entityType, target.entityId);
7
+ const restored = await executors.link.restore({ id }, user, db);
8
+ if (restored.isSuccess)
9
+ return restored;
10
+ const alreadyLive = isPlainObject(restored.error.details) && restored.error.details["reason"] === "not_deleted";
11
+ if (alreadyLive)
12
+ return { isSuccess: true, data: { id } };
13
+ if (restored.error.code !== "not_found")
14
+ return restored;
15
+ const created = await executors.link.create({ id, documentId, entityType: target.entityType, entityId: target.entityId }, user, db);
16
+ if (created.isSuccess || created.error.code === "version_conflict") {
17
+ return { isSuccess: true, data: { id } };
18
+ }
19
+ return created;
20
+ }