@cosmicdrift/kumiko-samples 0.422.0 → 0.424.1

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 (82) hide show
  1. package/package.json +1 -1
  2. package/packages/bundled-features/package.json +11 -1
  3. package/packages/bundled-features/src/auth-email-password/handlers/login.write.ts +52 -0
  4. package/packages/bundled-features/src/auth-email-password/index.ts +4 -0
  5. package/packages/bundled-features/src/channel-push/changes.json +8 -1
  6. package/packages/bundled-features/src/channel-push/push-channel.ts +2 -3
  7. package/packages/bundled-features/src/document-draft/README.md +84 -0
  8. package/packages/bundled-features/src/document-draft/changes.json +8 -0
  9. package/packages/bundled-features/src/document-draft/entity.ts +125 -0
  10. package/packages/bundled-features/src/document-draft/feature.ts +56 -0
  11. package/packages/bundled-features/src/document-draft/handlers/blocks.query.ts +63 -0
  12. package/packages/bundled-features/src/document-draft/handlers/by-subject.query.ts +50 -0
  13. package/packages/bundled-features/src/document-draft/handlers/create.write.ts +110 -0
  14. package/packages/bundled-features/src/document-draft/handlers/discard.write.ts +32 -0
  15. package/packages/bundled-features/src/document-draft/handlers/finalize.write.ts +103 -0
  16. package/packages/bundled-features/src/document-draft/handlers/patch.write.ts +86 -0
  17. package/packages/bundled-features/src/document-draft/handlers/revise.write.ts +46 -0
  18. package/packages/bundled-features/src/document-draft/handlers/save.write.ts +53 -0
  19. package/packages/bundled-features/src/document-draft/i18n.ts +22 -0
  20. package/packages/bundled-features/src/document-draft/index.ts +21 -0
  21. package/packages/bundled-features/src/document-draft/lib.ts +77 -0
  22. package/packages/bundled-features/src/document-draft/options.ts +51 -0
  23. package/packages/bundled-features/src/document-draft/payloads.ts +45 -0
  24. package/packages/bundled-features/src/document-draft/screens/editor-screen.ts +17 -0
  25. package/packages/bundled-features/src/document-draft/user-data.ts +63 -0
  26. package/packages/bundled-features/src/document-draft/web/client-plugin.tsx +20 -0
  27. package/packages/bundled-features/src/document-draft/web/constants.ts +56 -0
  28. package/packages/bundled-features/src/document-draft/web/editor-screen.tsx +418 -0
  29. package/packages/bundled-features/src/document-draft/web/i18n.ts +54 -0
  30. package/packages/bundled-features/src/document-draft/web/index.ts +14 -0
  31. package/packages/bundled-features/src/helpdesk/changes.json +6 -0
  32. package/packages/bundled-features/src/shared/index.ts +6 -0
  33. package/packages/bundled-features/src/{signature → shared}/subject-scope.ts +17 -6
  34. package/packages/bundled-features/src/signature/changes.json +6 -0
  35. package/packages/bundled-features/src/signature/feature.ts +1 -1
  36. package/packages/bundled-features/src/signature/handlers/cancel.write.ts +1 -1
  37. package/packages/bundled-features/src/signature/handlers/issue-link.write.ts +1 -1
  38. package/packages/bundled-features/src/signature/handlers/request.write.ts +1 -1
  39. package/packages/bundled-features/src/signature/handlers/revoke-link.write.ts +1 -1
  40. package/packages/bundled-features/src/signature/handlers/sign-in-person.write.ts +1 -1
  41. package/packages/bundled-features/src/signature/options.ts +2 -1
  42. package/packages/bundled-features/src/signature/subject-queries.ts +1 -1
  43. package/packages/bundled-features/src/template-resolver/api.ts +3 -1
  44. package/packages/bundled-features/src/template-resolver/boot-rules.ts +5 -0
  45. package/packages/bundled-features/src/template-resolver/changes.json +30 -0
  46. package/packages/bundled-features/src/template-resolver/feature.ts +15 -1
  47. package/packages/bundled-features/src/template-resolver/handlers/create-variant.write.ts +134 -0
  48. package/packages/bundled-features/src/template-resolver/handlers/document-base.ts +3 -0
  49. package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +44 -1
  50. package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +12 -1
  51. package/packages/bundled-features/src/template-resolver/handlers/template-write.ts +111 -11
  52. package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +29 -4
  53. package/packages/bundled-features/src/template-resolver/handlers/upsert-tenant.write.ts +1 -0
  54. package/packages/bundled-features/src/template-resolver/handlers/variants.query.ts +89 -0
  55. package/packages/bundled-features/src/template-resolver/i18n.ts +1 -0
  56. package/packages/bundled-features/src/template-resolver/index.ts +22 -0
  57. package/packages/bundled-features/src/template-resolver/seeding.ts +16 -1
  58. package/packages/bundled-features/src/template-resolver/template-delivery-policy.ts +56 -6
  59. package/packages/bundled-features/src/template-resolver/template-edit-policy.ts +5 -5
  60. package/packages/bundled-features/src/template-resolver/template-meta.ts +1 -0
  61. package/packages/bundled-features/src/template-resolver/template-variants.ts +50 -0
  62. package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +10 -1
  63. package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +10 -4
  64. package/packages/bundled-features/src/template-resolver/web/i18n.ts +26 -0
  65. package/packages/bundled-features/src/template-resolver/web/index.ts +5 -0
  66. package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +5 -0
  67. package/packages/bundled-features/src/template-resolver/web/system-placeholders.ts +17 -0
  68. package/packages/bundled-features/src/tenant/changes.json +7 -0
  69. package/packages/bundled-features/src/tenant/handlers/update-member-roles.write.ts +1 -1
  70. package/packages/bundled-features/src/tenant/i18n.ts +0 -1
  71. package/packages/bundled-features/src/tenant-inactivity/changes.json +7 -0
  72. package/packages/bundled-features/src/tenant-inactivity/constants.ts +1 -1
  73. package/packages/bundled-features/src/tenant-lifecycle/changes.json +7 -0
  74. package/packages/bundled-features/src/tenant-lifecycle/constants.ts +1 -1
  75. package/samples/apps/ui-walkthrough/src/run-config.ts +1 -0
  76. package/samples/apps/use-all-bundled/feature-manifest.json +37 -1
  77. package/samples/apps/use-all-bundled/kumiko/migrations/0069_document-draft.rebuild.json +4 -0
  78. package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
  79. package/samples/apps/use-all-bundled/src/run-config.ts +8 -0
  80. package/samples/recipes/session-exchange/README.md +34 -0
  81. package/samples/recipes/session-exchange/package.json +12 -0
  82. package/samples/recipes/session-exchange/src/feature.ts +54 -0
@@ -0,0 +1,50 @@
1
+ import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
2
+ import * as z from "zod";
3
+
4
+ export const VARIANT_SEPARATOR = ":";
5
+ export const VARIANT_KIND = "document-pdf" as const;
6
+ export const VARIANT_NAME_MAX_LENGTH = 40;
7
+ export const VARIANT_UNKNOWN_REASON = "template_variant_unknown";
8
+
9
+ // One kebab segment: the variant slug is `<base>:<name>` and a second ":" would read as another base.
10
+ export const variantNameSchema = z
11
+ .string()
12
+ .min(1)
13
+ .max(VARIANT_NAME_MAX_LENGTH)
14
+ .regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, "name must be kebab-case (lowercase, digits, dashes)");
15
+
16
+ export function variantSlug(baseSlug: string, name: string): string {
17
+ return `${baseSlug}${VARIANT_SEPARATOR}${name}`;
18
+ }
19
+
20
+ export function isVariantSlugOf(slug: string, baseSlug: string): boolean {
21
+ const prefix = `${baseSlug}${VARIANT_SEPARATOR}`;
22
+ return slug.startsWith(prefix) && variantNameSchema.safeParse(slug.slice(prefix.length)).success;
23
+ }
24
+
25
+ // Stored meta is untrusted JSON; only a string counts as a base slug.
26
+ export function readVariantOf(meta: unknown): string | null {
27
+ const variantOf = propertyOf(meta, "variantOf");
28
+ return typeof variantOf === "string" ? variantOf : null;
29
+ }
30
+
31
+ export function variantOfMatchesSlug(slug: string, meta: unknown): boolean {
32
+ const variantOf = readVariantOf(meta);
33
+ return variantOf === null || isVariantSlugOf(slug, variantOf);
34
+ }
35
+
36
+ // German special letters are transliterated and the rest kebab-cased, so any title yields a valid name.
37
+ export function variantNameFromTitle(title: string): string {
38
+ return title
39
+ .toLowerCase()
40
+ .replace(/ä/g, "ae")
41
+ .replace(/ö/g, "oe")
42
+ .replace(/ü/g, "ue")
43
+ .replace(/ß/g, "ss")
44
+ .normalize("NFD")
45
+ .replace(/[̀-ͯ]/g, "")
46
+ .replace(/[^a-z0-9]+/g, "-")
47
+ .replace(/^-+|-+$/g, "")
48
+ .slice(0, VARIANT_NAME_MAX_LENGTH)
49
+ .replace(/-+$/g, "");
50
+ }
@@ -29,9 +29,17 @@ function tableClasses(canvas: boolean, page: boolean): string {
29
29
  : "[&_table]:mb-2 [&_table]:mt-6 [&_.ProseMirror>:first-child_table]:mt-0 [&_.ProseMirror>table:first-child]:mt-0",
30
30
  "[&_td:last-child>p[data-size=small][data-align=right]]:whitespace-nowrap",
31
31
  )
32
- : "[&_table]:my-2";
32
+ : cn(
33
+ "[&_table]:my-2",
34
+ // The repeat strip is absolutely placed above its table and needs a line of room inside the wrapper.
35
+ "[&_.tableWrapper:has([data-testid=document-repeat-strip])_table]:mt-[var(--doc-line,1.25rem)]!",
36
+ );
33
37
  }
34
38
 
39
+ // A wide table scrolls inside its wrapper instead of pushing past the editor frame. Not on the
40
+ // paper canvas, where tables are bounded by the page.
41
+ const TABLE_SCROLL_CLASS = "[&_.tableWrapper]:max-w-full [&_.tableWrapper]:overflow-x-auto";
42
+
35
43
  // The PDF prints cells top-aligned, header like body text and no rules unless the layout sets a
36
44
  // table style; the dashed outline only marks the cells while editing, like the frame outline.
37
45
  function cellClasses(canvas: boolean, print: DocumentPrintMode): string {
@@ -82,6 +90,7 @@ export function renderEditorContent(
82
90
  "[&_a]:underline [&_a]:text-primary",
83
91
  "[&_strong]:font-bold [&_em]:italic [&_u]:underline",
84
92
  tableClasses(canvas, page),
93
+ !page && TABLE_SCROLL_CLASS,
85
94
  // A layout region has no content below its table; margins there only inflate the region box.
86
95
  hosted && "[&_td>div]:my-0 [&_.ProseMirror>.tableWrapper:last-child_table]:mb-0",
87
96
  "[&_table]:w-full [&_table]:border-collapse",
@@ -186,6 +186,12 @@ function renderPrintBlockMenu(c: TiptapContext): ReactNode {
186
186
  );
187
187
  }
188
188
 
189
+ // The form-field toolbar wraps on desktop; under md every row is one line that swipes sideways.
190
+ // `relative` makes the row the containing block of absolutely placed children (hidden inputs, popover
191
+ // anchors); without it they escape the scroll clip and widen the page.
192
+ const NARROW_SCROLL_ROW =
193
+ "relative gap-1 p-1 max-md:flex-nowrap max-md:overflow-x-auto md:flex-wrap [&>*]:shrink-0";
194
+
189
195
  function renderPrintStyleRow(c: TiptapContext): ReactNode {
190
196
  const { canvas } = c;
191
197
  return (
@@ -193,8 +199,8 @@ function renderPrintStyleRow(c: TiptapContext): ReactNode {
193
199
  className={cn(
194
200
  "flex items-center border-b border-input",
195
201
  canvas
196
- ? "min-h-9 flex-wrap gap-1.5 bg-background px-1.5 py-1 [&>*]:shrink-0"
197
- : "flex-wrap gap-1 p-1",
202
+ ? "relative min-h-9 gap-1.5 bg-background px-1.5 py-1 max-md:flex-nowrap max-md:overflow-x-auto md:flex-wrap [&>*]:shrink-0"
203
+ : NARROW_SCROLL_ROW,
198
204
  )}
199
205
  >
200
206
  {renderPrintTextStyleGroup(c)}
@@ -245,8 +251,8 @@ function renderMainToolbarRow(c: TiptapContext): ReactNode {
245
251
  className={cn(
246
252
  "flex items-center border-b border-input",
247
253
  canvas
248
- ? "min-h-9 flex-nowrap gap-0 overflow-hidden bg-background px-1.5 [&>*]:shrink-0 [&_button]:h-7 [&_button]:gap-1 [&_button]:px-1 [&_button]:text-xs"
249
- : "flex-wrap gap-1 p-1",
254
+ ? "relative min-h-9 flex-nowrap gap-0 overflow-x-auto bg-background md:overflow-hidden px-1.5 [&>*]:shrink-0 [&_button]:h-7 [&_button]:gap-1 [&_button]:px-1 [&_button]:text-xs"
255
+ : NARROW_SCROLL_ROW,
250
256
  )}
251
257
  >
252
258
  {renderParagraphStyleSelect(c)}
@@ -8,6 +8,22 @@ import type { TranslationsByLocale } from "@cosmicdrift/kumiko-renderer";
8
8
 
9
9
  export const defaultTranslations: TranslationsByLocale = {
10
10
  en: {
11
+ "template-resolver.systemPlaceholder.tenantName": "Company name",
12
+ "template-resolver.systemPlaceholder.signature": "Signature",
13
+ "template-resolver.systemPlaceholder.imprint": "Imprint",
14
+ "template-resolver.systemPlaceholder.unsubscribeUrl": "Unsubscribe link",
15
+ "template-resolver.systemPlaceholder.page": "Page number",
16
+ "template-resolver.systemPlaceholder.pages": "Page count",
17
+ "template-resolver.systemPlaceholder.companyAddress": "Address",
18
+ "template-resolver.systemPlaceholder.companyPhone": "Phone",
19
+ "template-resolver.systemPlaceholder.companyEmail": "Email",
20
+ "template-resolver.systemPlaceholder.companyWebsite": "Website",
21
+ "template-resolver.systemPlaceholder.companyRegister": "Commercial register",
22
+ "template-resolver.systemPlaceholder.companyVatId": "VAT ID",
23
+ "template-resolver.systemPlaceholder.companyManagement": "Management",
24
+ "template-resolver.systemPlaceholder.companyBank": "Bank",
25
+ "template-resolver.systemPlaceholder.companyIban": "IBAN",
26
+ "template-resolver.systemPlaceholder.companyBic": "BIC",
11
27
  "template-resolver.documentEditor.button": "Button",
12
28
  "template-resolver.documentEditor.buttonDefaultText": "Confirm",
13
29
  "template-resolver.documentEditor.buttonTarget": "Button target",
@@ -112,6 +128,16 @@ export const defaultTranslations: TranslationsByLocale = {
112
128
  "templateResolver.errors.patch.regionNotAllowed":
113
129
  "A region only applies to PDF layouts, not to {kind}.",
114
130
  "templateResolver.errors.patch.layoutExists": "A layout with the slug {slug} already exists.",
131
+ "templateResolver.errors.patch.variantsNotEnabled":
132
+ "Variants are not enabled for the template {slug}.",
133
+ "templateResolver.errors.patch.variantExists": "A variant with the slug {slug} already exists.",
134
+ "templateResolver.errors.patch.variantNameInvalid":
135
+ "The short name must be lowercase letters, digits and dashes; give one or change the title.",
136
+ "templateResolver.errors.patch.variablesInheritedFromBase":
137
+ "A variant uses the variables of its base template {slug}; change them there.",
138
+ "templateResolver.errors.patch.invalidVariantOf":
139
+ "The variant must belong to the base template in its slug.",
140
+ "templateResolver.errors.variantUnknown": "The variant {variant} does not exist.",
115
141
  "templateResolver.errors.template.reservedLayoutSlug":
116
142
  "The prefix {prefix} is reserved for tenant layouts.",
117
143
  "templateResolver.errors.patch.emptyFormat": "Give at least one of align, style or textStyle.",
@@ -79,4 +79,9 @@ export {
79
79
  TemplateResolverHandlers,
80
80
  TemplateResolverQueries,
81
81
  } from "./qualified-names.ts";
82
+ export {
83
+ SYSTEM_PLACEHOLDER_TYPE,
84
+ systemPlaceholderLabel,
85
+ translatedOr,
86
+ } from "./system-placeholders.ts";
82
87
  export { WebPreviewRenderer } from "./web-preview-renderer.tsx";
@@ -23,6 +23,7 @@ export const TemplateResolverHandlers = {
23
23
  applyLayout: "template-resolver:write:apply-layout",
24
24
  createLayout: "template-resolver:write:create-layout",
25
25
  publishTemplates: "template-resolver:write:publish-templates",
26
+ createVariant: "template-resolver:write:create-variant",
26
27
  } as const;
27
28
 
28
29
  // The config feature's write handler, which applyLayout dispatches to for the tenant default layout.
@@ -43,6 +44,7 @@ export const TemplateResolverQueries = {
43
44
  documentBlocks: "template-resolver:query:document-blocks",
44
45
  exportBundle: "template-resolver:query:export-bundle",
45
46
  sendTestStatus: "template-resolver:query:send-test-status",
47
+ variants: "template-resolver:query:variants",
46
48
  // Public pair — anonymous-reachable, kind pinned to text-block.
47
49
  bySlug: "template-resolver:query:by-slug",
48
50
  byTenant: "template-resolver:query:by-tenant",
@@ -85,4 +87,7 @@ export const TemplateResolverErrors = {
85
87
  testMailNoChannel: "template_test_mail_no_channel",
86
88
  testMailNoAddress: "template_test_mail_no_address",
87
89
  testMailFailed: "template_test_mail_failed",
90
+ variantsNotEnabled: "variants_not_enabled",
91
+ variantExists: "variant_exists",
92
+ variantNameInvalid: "variant_name_invalid",
88
93
  } as const;
@@ -0,0 +1,17 @@
1
+ import type { Translate } from "@cosmicdrift/kumiko-renderer/headless";
2
+
3
+ // Placeholders the renderer fills in; only the ones that are not plain text are listed.
4
+ export const SYSTEM_PLACEHOLDER_TYPE: Readonly<Partial<Record<string, "link">>> = {
5
+ imprint: "link",
6
+ unsubscribeUrl: "link",
7
+ };
8
+
9
+ // t() returns the key itself without a translation.
10
+ export function translatedOr(t: Translate, key: string, fallback: string): string {
11
+ const translated = t(key);
12
+ return translated === key ? fallback : translated;
13
+ }
14
+
15
+ export function systemPlaceholderLabel(t: Translate, name: string): string {
16
+ return translatedOr(t, `template-resolver.systemPlaceholder.${name}`, name);
17
+ }
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "version": "0.423.0",
4
+ "type": "breaking",
5
+ "title": "The TenantOwner role option is removed from the member roles form",
6
+ "detail": "The role option label `tenant:entity:__action-form__:field:roles:option:TenantOwner` is gone together with the role.",
7
+ "migration": "Remove any app translation or screen reference to the `TenantOwner` role option."
8
+ },
2
9
  {
3
10
  "version": "0.414.0",
4
11
  "type": "fix",
@@ -74,7 +74,7 @@ export const updateMemberRolesWrite = defineWriteHandler({
74
74
  // are session-scoped (event.user.tenantId).
75
75
  access: { roles: ["system", ...access.admin] },
76
76
  description:
77
- "Sets the roles a user holds in a tenant, rejecting reserved role names and any grant that would raise the target above the caller; roles the caller could not grant (platform roles such as DataProtectionOfficer or TenantOwner, undeclared or higher-tier app roles) are kept, only the system user replaces the full list; admins act on their own tenant, SystemAdmins on any.",
77
+ "Sets the roles a user holds in a tenant, rejecting reserved role names and any grant that would raise the target above the caller; roles the caller could not grant (platform roles such as DataProtectionOfficer, undeclared or higher-tier app roles) are kept, only the system user replaces the full list; admins act on their own tenant, SystemAdmins on any.",
78
78
  agent: { risk: "high" },
79
79
  handler: async (event, ctx) => {
80
80
  if (!ctx.systemDb) {
@@ -50,7 +50,6 @@ export const TENANT_I18N: Readonly<Record<string, LocalizedString>> = {
50
50
  "tenant:entity:__action-form__:field:roles:option:Member": { en: "Member" },
51
51
  "tenant:entity:__action-form__:field:roles:option:Admin": { en: "Admin" },
52
52
  "tenant:entity:__action-form__:field:roles:option:TenantAdmin": { en: "Tenant Admin" },
53
- "tenant:entity:__action-form__:field:roles:option:TenantOwner": { en: "Tenant Owner" },
54
53
  "tenant:entity:__action-form__:field:roles:option:DataProtectionOfficer": {
55
54
  en: "Data Protection Officer",
56
55
  },
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "version": "0.423.0",
4
+ "type": "breaking",
5
+ "title": "TenantOwner is no longer a keep-account role",
6
+ "detail": "`TENANT_KEEP_ACCOUNT_ROLES` is now `[\"TenantAdmin\", \"Admin\"]`; the inactivity warning mail and the keep-account handlers address these roles only.",
7
+ "migration": "Grant `Admin` or `TenantAdmin` instead of `TenantOwner`."
8
+ },
2
9
  {
3
10
  "version": "0.415.0",
4
11
  "type": "fix",
@@ -2,7 +2,7 @@ export const TENANT_INACTIVITY_FEATURE = "tenant-inactivity";
2
2
  export const TENANT_INACTIVITY_STATE_ENTITY = "tenant-inactivity-state";
3
3
 
4
4
  // Stays import-free for the client-safe subpath; a test ties it to TENANT_ACCOUNT_CLOSE_ROLES.
5
- export const TENANT_KEEP_ACCOUNT_ROLES = ["TenantOwner", "TenantAdmin", "Admin"] as const;
5
+ export const TENANT_KEEP_ACCOUNT_ROLES = ["TenantAdmin", "Admin"] as const;
6
6
 
7
7
  export const TenantInactivityJobs = {
8
8
  check: `${TENANT_INACTIVITY_FEATURE}:job:check-inactive-tenants`,
@@ -1,4 +1,11 @@
1
1
  [
2
+ {
3
+ "version": "0.423.0",
4
+ "type": "breaking",
5
+ "title": "TenantOwner no longer closes the account",
6
+ "detail": "`TENANT_ACCOUNT_CLOSE_ROLES` is now `[\"Admin\"]`. `TenantAdmin` is not added, so the set of roles that may request or cancel tenant destruction only loses the removed role.",
7
+ "migration": "Grant `Admin` instead of `TenantOwner` to members who close the account."
8
+ },
2
9
  {
3
10
  "version": "0.418.0",
4
11
  "type": "fix",
@@ -1,6 +1,6 @@
1
1
  export const TENANT_LIFECYCLE_FEATURE = "tenant-lifecycle" as const;
2
2
 
3
- export const TENANT_ACCOUNT_CLOSE_ROLES = ["TenantOwner", "Admin"] as const;
3
+ export const TENANT_ACCOUNT_CLOSE_ROLES = ["Admin"] as const;
4
4
 
5
5
  export const TENANT_AGGREGATE_TYPE = "tenant" as const;
6
6
 
@@ -48,6 +48,7 @@ const TENANT_EDITABLE_TEMPLATES: readonly TenantEditableTemplate[] = [
48
48
  kind: "document-pdf" as const,
49
49
  slug,
50
50
  access: { roles: ["TenantAdmin"] },
51
+ ...(slug === "billing:invoice" && { variants: true as const }),
51
52
  })),
52
53
  ...(["mail-layout", "pdf-layout"] as const).map((kind) => ({
53
54
  kind,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "source": "samples/apps/use-all-bundled APP_FEATURES (composeFeatures includeBundled + signup)",
3
- "featureCount": 96,
3
+ "featureCount": 97,
4
4
  "features": [
5
5
  {
6
6
  "name": "account-security",
@@ -881,6 +881,41 @@
881
881
  "recommended": false
882
882
  }
883
883
  },
884
+ {
885
+ "name": "document-draft",
886
+ "description": "Document drafts: one editable copy of a PDF document template per object (for example a lease contract). A draft is created from a template or one of its variants with the values for its placeholders, changed with the structured operations of template patch-draft or the editor, and finalized to a stored PDF through the injected print function; the template stays unchanged. Revise reopens a finalized draft. Body, variables and the last change are personal data of the draft, which is its own crypto-shredding subject.",
887
+ "toggleableDefault": null,
888
+ "requires": [
889
+ "files",
890
+ "template-resolver",
891
+ "user-data-rights"
892
+ ],
893
+ "optionalRequires": [],
894
+ "configReads": [],
895
+ "exposesApis": [],
896
+ "usesApis": [],
897
+ "extensionsUsed": [
898
+ {
899
+ "extensionName": "userData",
900
+ "entityName": "documentDraft"
901
+ }
902
+ ],
903
+ "configKeys": [],
904
+ "secrets": [],
905
+ "writeHandlers": [
906
+ "document-draft:write:create",
907
+ "document-draft:write:discard",
908
+ "document-draft:write:finalize",
909
+ "document-draft:write:patch",
910
+ "document-draft:write:revise",
911
+ "document-draft:write:save"
912
+ ],
913
+ "uiHints": {
914
+ "displayLabel": "Document drafts",
915
+ "category": "data",
916
+ "recommended": false
917
+ }
918
+ },
884
919
  {
885
920
  "name": "document-ingest-foundation",
886
921
  "description": "Shared PDF/Scan/Image → normalized-text ingest primitive. Owns the `documentExtract` entity (fileRefId, storageKey, per-page text + metadata) as an implicit entity-projection, the per-tenant `ocrLanguage`/`maxPagesPerFile` config keys, the `documentIngestProvider` extension-point providers register accepted mimeTypes/size caps under, and a fileRef.created/fileRef.restored trigger that resolves the provider for a file's mimeType and requests ingest via `documentIngest.requested` tagged with the winning provider — a delete→restore round-trip re-requests ingest the same way a fresh upload does. An orphan-extract guard forgets any `documentExtract` whose fileRef is no longer live at processing time, regardless of how a provider's own write races the fileRef's delete/forget — providers should write through `writeDocumentExtractForLiveFileRef`.",
@@ -3099,6 +3134,7 @@
3099
3134
  "template-resolver:write:archive-system",
3100
3135
  "template-resolver:write:copy-locale",
3101
3136
  "template-resolver:write:create-layout",
3137
+ "template-resolver:write:create-variant",
3102
3138
  "template-resolver:write:discard-draft",
3103
3139
  "template-resolver:write:discard-draft-system",
3104
3140
  "template-resolver:write:import-bundle",
@@ -0,0 +1,4 @@
1
+ {
2
+ "version": 1,
3
+ "tables": ["read_document_drafts"]
4
+ }
@@ -24,6 +24,7 @@ import { complianceProfilesClient } from "@cosmicdrift/kumiko-bundled-features/c
24
24
  import { configClient } from "@cosmicdrift/kumiko-bundled-features/config/web";
25
25
  import { customFieldsClient } from "@cosmicdrift/kumiko-bundled-features/custom-fields/web";
26
26
  import { deliveryClient } from "@cosmicdrift/kumiko-bundled-features/delivery/web";
27
+ import { documentDraftClient } from "@cosmicdrift/kumiko-bundled-features/document-draft/web";
27
28
  import { featureTogglesClient } from "@cosmicdrift/kumiko-bundled-features/feature-toggles/web";
28
29
  import { foldersClient } from "@cosmicdrift/kumiko-bundled-features/folders/web";
29
30
  import { inboundMailFoundationClient } from "@cosmicdrift/kumiko-bundled-features/inbound-mail-foundation/web";
@@ -137,6 +138,8 @@ createKumikoApp({
137
138
  // PDF template editor with live PDF preview, mounted as the custom screen
138
139
  // app-screens declares (no nav entry; opened by URL).
139
140
  documentDesignerClient(),
141
+ // Editor screen of per-object document drafts, opened by URL with the draft id.
142
+ documentDraftClient(),
140
143
  appScreens,
141
144
  ],
142
145
  });
@@ -43,6 +43,7 @@ import { createCustomFieldsFeature } from "@cosmicdrift/kumiko-bundled-features/
43
43
  import { createDataRetentionFeature } from "@cosmicdrift/kumiko-bundled-features/data-retention";
44
44
  import { createDeliveryFeature } from "@cosmicdrift/kumiko-bundled-features/delivery";
45
45
  import { createDerivativesSharpFeature } from "@cosmicdrift/kumiko-bundled-features/derivatives-sharp";
46
+ import { createDocumentDraftFeature } from "@cosmicdrift/kumiko-bundled-features/document-draft";
46
47
  import { createDocumentIngestFoundationFeature } from "@cosmicdrift/kumiko-bundled-features/document-ingest-foundation";
47
48
  import { createDocumentsFeature } from "@cosmicdrift/kumiko-bundled-features/documents";
48
49
  import {
@@ -111,6 +112,8 @@ import { localeDe } from "@cosmicdrift/kumiko-locale-de";
111
112
  import {
112
113
  createRendererPuppeteerClientFeature,
113
114
  renderHtmlToPdf,
115
+ renderPdfBeforeTransaction,
116
+ storeRenderedPdf,
114
117
  } from "@cosmicdrift/kumiko-renderer-puppeteer-client";
115
118
  import { ADMIN_NAV_QN, ADMIN_NAV_WORKSPACES, adminNavFeature } from "./app/admin-nav-feature";
116
119
  import { DEV_TENANT_ID } from "./app/auth-constants";
@@ -390,6 +393,11 @@ export const APP_FEATURES = [
390
393
  /* smoke-only */
391
394
  },
392
395
  }),
396
+ // document-draft: the app hands over the client's print and store functions as they are.
397
+ createDocumentDraftFeature({
398
+ subjectTypes: ["lease"],
399
+ pdf: { render: renderPdfBeforeTransaction, store: storeRenderedPdf },
400
+ }),
393
401
  createHandbookKnowledgeFeature({
394
402
  pages: {
395
403
  defaultLocale: "en",
@@ -0,0 +1,34 @@
1
+ # Sample: Session Exchange
2
+
3
+ **I want my own login method (Apple/Google ID token, email link) without rebuilding cookies, JWTs and rate limits.**
4
+
5
+ ## What this sample shows
6
+
7
+ An anonymous write handler verifies an identity and returns `{ kind: "auth-session", session }`. The app lists it under `auth.sessionExchangeHandlers`; `POST /api/auth/session-exchange` runs it and mints the session like `/auth/login` (token, cookies). The rate limit counts per IP and method and is not reset on success, because the route cannot tell whose code was right. By default it reuses the login limiter; set `auth.sessionExchangeRateLimit` to a larger limiter, or `null` to turn it off (for example when the methods carry signed tokens).
8
+
9
+ ## What to copy into your app
10
+
11
+ ```ts illustration
12
+ auth: {
13
+ membershipQuery: "tenant:query:memberships",
14
+ loginHandler: "auth-email-password:write:login",
15
+ sessionExchangeHandlers: { code: "demo-exchange:write:code" },
16
+ },
17
+ ```
18
+
19
+ The client calls `POST /api/auth/session-exchange` with `{ method: "code", payload: { ... } }`.
20
+
21
+ ## Design rules
22
+
23
+ 1. **Only listed handlers can issue a session.** The route resolves `method` against the map (own keys only); the handler QN never comes from the client.
24
+ 2. **The handler owns verification.** The demo compares a fixed code; a real handler verifies the ID token signature and audience first, then calls `sessionForVerifiedUser(ctx, { email })` (or `{ userId }`) for the login gates: account status, membership choice, claims. A lookup by email only issues a session for a verified address (otherwise a pre-registered attacker account would be taken over by the victim), a lookup by `userId` trusts your own identity link. There is no password or lockout gate, so accept only credentials that cannot be guessed: a signed ID token or a long random one-time token. A short code (six digits by mail) needs its own attempt counter per identity in the handler; the route only knows the IP, and a per-IP bucket does not stop a distributed guess. There is no MFA gate: boot aborts when `auth-mfa` is mounted together with `sessionExchangeHandlers`.
25
+ 3. **Anything but `auth-session` is rejected.** An MFA challenge or foreign result yields 500 and no cookie.
26
+ 4. **Errors map like login.** `details.reason` goes through `loginErrorStatusMap`.
27
+ 5. **Grant SYSTEM to the one handler, hide it from agents.** `escapeHatch: { grants: ["systemIdentity"] }` on the exchange handler, not `r.systemScope()` on the feature, and `agent: { expose: false }` because the payload is a credential.
28
+
29
+ ## Tests
30
+
31
+ - **End-to-end over HTTP:** exchange returns a token that authenticates a query
32
+ - **Wrong code:** 401 via `invalid_credentials`
33
+ - **Restricted user:** no session
34
+ - **Unknown method:** 400
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@cosmicdrift/kumiko-sample-session-exchange",
3
+ "description": "auth.sessionExchangeHandlers — app-defined login methods (ID token, email code) that the framework mints into a session.",
4
+ "private": true,
5
+ "dependencies": {
6
+ "@cosmicdrift/kumiko-bundled-features": "workspace:*",
7
+ "@cosmicdrift/kumiko-framework": "workspace:*"
8
+ },
9
+ "devDependencies": {
10
+ "@cosmicdrift/kumiko-testing": "workspace:*"
11
+ }
12
+ }
@@ -0,0 +1,54 @@
1
+ // Session Exchange Sample
2
+ //
3
+ // An app-defined login method: an anonymous write handler verifies an identity
4
+ // and returns { kind: "auth-session", session }; the framework route mints the
5
+ // session (token, cookies, rate limit) exactly like /auth/login.
6
+ //
7
+ // What to copy into your own app:
8
+ //
9
+ // auth: {
10
+ // membershipQuery: "tenant:query:memberships",
11
+ // sessionExchangeHandlers: { code: "demo-exchange:write:code" },
12
+ // },
13
+ //
14
+ // Only handlers listed in sessionExchangeHandlers can cause a session to be
15
+ // issued, so a handler that merely returns a session-shaped object elsewhere
16
+ // stays harmless. The demo code check stands in for verifying an ID token;
17
+ // sessionForVerifiedUser then runs the login gates after the identity proof
18
+ // (account status, membership choice, claims).
19
+
20
+ import { sessionForVerifiedUser } from "@cosmicdrift/kumiko-bundled-features/auth-email-password";
21
+ import { defineFeature } from "@cosmicdrift/kumiko-framework/engine";
22
+ import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
23
+ import { z } from "zod";
24
+
25
+ export const DEMO_EXCHANGE_CODE = "246810";
26
+ export const DEMO_EXCHANGE_QN = "demo-exchange:write:code";
27
+ export const INVALID_CREDENTIALS_REASON = "invalid_credentials";
28
+
29
+ export const demoExchangeFeature = defineFeature("demo-exchange", (r) => {
30
+ r.requires({ features: ["user", "tenant"] });
31
+
32
+ r.writeHandler({
33
+ name: "code",
34
+ schema: z.object({ email: z.email(), code: z.string().min(1) }),
35
+ access: { roles: ["anonymous"] },
36
+ escapeHatch: {
37
+ grants: ["systemIdentity"],
38
+ reason:
39
+ "Unauthenticated exchange has no caller identity yet — sessionForVerifiedUser looks up the user and resolves the membership as SYSTEM before a session exists.",
40
+ },
41
+ // The payload carries a credential (code or ID token) that must never enter an LLM transcript.
42
+ agent: { expose: false },
43
+ handler: async (event, ctx) => {
44
+ if (event.payload.code !== DEMO_EXCHANGE_CODE) {
45
+ return writeFailure(
46
+ new UnprocessableError(INVALID_CREDENTIALS_REASON, {
47
+ i18nKey: "demo-exchange.errors.invalidCredentials",
48
+ }),
49
+ );
50
+ }
51
+ return sessionForVerifiedUser(ctx, { email: event.payload.email });
52
+ },
53
+ });
54
+ });