command_tower 0.22.0 → 0.23.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.
- checksums.yaml +4 -4
- data/app/controllers/command_tower/admin/messaging/gallery_controller.rb +35 -0
- data/app/controllers/command_tower/admin/messaging/gallery_test_sends_controller.rb +54 -0
- data/app/controllers/command_tower/me/inbox_controller.rb +19 -4
- data/app/controllers/command_tower/messaging/unsubscribe_controller.rb +43 -0
- data/app/controllers/concerns/command_tower/execution/http_boundary.rb +36 -1
- data/app/errors/command_tower/errors/messaging/announcement_type_not_supported_error.rb +23 -0
- data/app/errors/command_tower/errors/messaging/gallery_test_send_failed_error.rb +26 -0
- data/app/errors/command_tower/errors/messaging/gallery_test_send_impersonating_error.rb +23 -0
- data/app/errors/command_tower/errors/messaging/gallery_test_send_rate_limit_error.rb +25 -0
- data/app/errors/command_tower/errors/messaging/unsubscribe_rate_limit_error.rb +25 -0
- data/app/jobs/command_tower/messaging/communications/produce_recipient_job.rb +2 -2
- data/app/mailers/command_tower/messaging/channel_mailer.rb +2 -0
- data/app/models/command_tower/messaging/communication.rb +10 -0
- data/app/serializers/command_tower/serializers/admin/messaging/gallery_serializer.rb +67 -0
- data/app/services/command_tower/email_theme/resolver.rb +13 -12
- data/app/services/command_tower/messaging/accept/coordinator.rb +57 -4
- data/app/services/command_tower/messaging/accept/persister.rb +3 -0
- data/app/services/command_tower/messaging/accept/request_normalizer.rb +9 -4
- data/app/services/command_tower/messaging/accept/resolve_communication_slots.rb +114 -0
- data/app/services/command_tower/messaging/announcement_definition.rb +88 -0
- data/app/services/command_tower/messaging/contract/inbox.rb +65 -0
- data/app/services/command_tower/messaging/contract/mappers/communication_mapper.rb +9 -0
- data/app/services/command_tower/messaging/contract/requests/mark_viewed_for_communication.rb +21 -0
- data/app/services/command_tower/messaging/contract/requests/viewed_for_communication.rb +21 -0
- data/app/services/command_tower/messaging/contract/results/communication_result.rb +3 -0
- data/app/services/command_tower/messaging/contract/results/inbox_view_mark.rb +18 -0
- data/app/services/command_tower/messaging/definitions/document_builder.rb +157 -0
- data/app/services/command_tower/messaging/definitions/render_context.rb +18 -0
- data/app/services/command_tower/messaging/inbox/item_result.rb +5 -1
- data/app/services/command_tower/messaging/inbox/mutator.rb +17 -0
- data/app/services/command_tower/messaging/inbox/reader.rb +12 -0
- data/app/services/command_tower/messaging/inbox/scope.rb +8 -0
- data/app/services/command_tower/messaging/inbox.rb +8 -0
- data/app/services/command_tower/messaging/message_definition/metadata.rb +35 -0
- data/app/services/command_tower/messaging/message_definition.rb +151 -0
- data/app/services/command_tower/messaging/notification_types/declaration.rb +12 -1
- data/app/services/command_tower/messaging/notification_types/message_definition_checks.rb +143 -0
- data/app/services/command_tower/messaging/notification_types/registry.rb +2 -0
- data/app/services/command_tower/messaging/rendering/channel_renderer.rb +73 -6
- data/app/services/command_tower/messaging/rendering/compliance_footer.rb +80 -0
- data/app/services/command_tower/messaging/rendering/defined_email_renderer.rb +141 -0
- data/app/services/command_tower/messaging/rendering/inbox_document_renderer.rb +79 -4
- data/app/services/command_tower/messaging/rendering/rendered_payload.rb +13 -1
- data/app/services/command_tower/messaging/rendering/unsubscribe_headers.rb +51 -0
- data/app/services/command_tower/messaging/unsubscribe/token_verifier.rb +26 -0
- data/app/services/command_tower/services/messaging/announcements/resolve_produce_arguments.rb +74 -0
- data/app/services/command_tower/services/messaging/communications/explicit_copy_rule.rb +50 -0
- data/app/services/command_tower/services/messaging/communications/produce.rb +18 -4
- data/app/services/command_tower/services/messaging/communications/produce_many.rb +20 -2
- data/app/services/command_tower/services/messaging/gallery/channel_failed.rb +31 -0
- data/app/services/command_tower/services/messaging/gallery/check_test_send_rate_limit.rb +47 -0
- data/app/services/command_tower/services/messaging/gallery/list_gallery_types.rb +44 -0
- data/app/services/command_tower/services/messaging/gallery/preview_builder.rb +122 -0
- data/app/services/command_tower/services/messaging/gallery/preview_channels.rb +51 -0
- data/app/services/command_tower/services/messaging/gallery/preview_checks.rb +85 -0
- data/app/services/command_tower/services/messaging/gallery/preview_email.rb +56 -0
- data/app/services/command_tower/services/messaging/gallery/render_gallery_preview.rb +85 -0
- data/app/services/command_tower/services/messaging/gallery/test_send.rb +55 -0
- data/app/services/command_tower/services/messaging/inbox.rb +36 -8
- data/app/services/command_tower/services/messaging/unsubscribe/check_rate_limit.rb +57 -0
- data/app/services/command_tower/services/messaging/unsubscribe/issue_token.rb +25 -0
- data/app/services/command_tower/services/messaging/unsubscribe/opt_out_of_email.rb +65 -0
- data/app/services/command_tower/services/messaging/unsubscribe/verify_token.rb +42 -0
- data/app/services/command_tower/services/users/record_last_known_time_zone.rb +40 -0
- data/app/workflows/command_tower/workflows/admin/messaging/create_announcement_workflow.rb +16 -3
- data/app/workflows/command_tower/workflows/admin/messaging/gallery/index_workflow.rb +29 -0
- data/app/workflows/command_tower/workflows/admin/messaging/gallery/show_workflow.rb +40 -0
- data/app/workflows/command_tower/workflows/admin/messaging/gallery/test_send_workflow.rb +103 -0
- data/app/workflows/command_tower/workflows/messaging/communications/produce_recipient_workflow.rb +2 -2
- data/app/workflows/command_tower/workflows/messaging/error_mapping.rb +8 -1
- data/app/workflows/command_tower/workflows/messaging/inbox.rb +30 -5
- data/app/workflows/command_tower/workflows/messaging/unsubscribe/one_click_workflow.rb +56 -0
- data/app/workflows/command_tower/workflows/messaging/unsubscribe/preferences_redirect_workflow.rb +24 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20261124000001_add_message_definition_columns_to_messaging_communications.rb +9 -0
- data/docs/admin_workspace.md +2 -1
- data/docs/api_reference.md +78 -20
- data/docs/audit.md +9 -0
- data/docs/authentication_authorization_guide.md +1 -1
- data/docs/bootstrap/09-rbac.md +2 -0
- data/docs/bootstrap/11-auth-client-path.md +1 -1
- data/docs/cookie_authentication_guide.md +2 -0
- data/docs/extending.md +4 -0
- data/docs/messaging_integration_guide.md +40 -15
- data/docs/principal_capabilities.md +2 -0
- data/docs/ui.md +64 -2
- data/docs/upgrades/0.23.0.md +64 -0
- data/docs/upgrades/README.md +1 -0
- data/lib/command_tower/authorization/default.yml +8 -0
- data/lib/command_tower/configuration/messaging/compliance.rb +47 -0
- data/lib/command_tower/configuration/messaging/config.rb +25 -0
- data/lib/command_tower/configuration/registry/admin_workspace/config.rb +9 -0
- data/lib/command_tower/configuration/registry/admin_workspace/tool_definition.rb +10 -1
- data/lib/command_tower/configuration/registry/audit/config.rb +38 -0
- data/lib/command_tower/configuration/registry/principal_capabilities/config.rb +2 -0
- data/lib/command_tower/current.rb +1 -0
- data/lib/command_tower/email_theme/default_ui_tokens.json +18 -0
- data/lib/command_tower/email_theme/palette.rb +75 -0
- data/lib/command_tower/email_theme/token_file.rb +81 -0
- data/lib/command_tower/engine.rb +7 -0
- data/lib/command_tower/execution.rb +2 -1
- data/lib/command_tower/install/baseline.rb +1 -0
- data/lib/command_tower/rspec/message_definition.rb +125 -0
- data/lib/command_tower/ui/document.rb +18 -4
- data/lib/command_tower/ui/email/renderer/text_nodes.rb +2 -1
- data/lib/command_tower/ui/email/renderer.rb +17 -5
- data/lib/command_tower/ui/email/text_part.rb +53 -0
- data/lib/command_tower/ui/fragments/markdown.rb +121 -0
- data/lib/command_tower/ui/markdown_subset/chunker.rb +91 -0
- data/lib/command_tower/ui/markdown_subset/inline.rb +86 -0
- data/lib/command_tower/ui/markdown_subset/segment.rb +15 -0
- data/lib/command_tower/ui/markdown_subset/walker.rb +129 -0
- data/lib/command_tower/ui/nodes/instant.rb +3 -0
- data/lib/command_tower/ui/redaction.rb +44 -0
- data/lib/command_tower/ui/required_facts/matchers/text.rb +22 -0
- data/lib/command_tower/ui/required_facts/matchers/time.rb +37 -0
- data/lib/command_tower/ui/required_facts/verdict.rb +54 -0
- data/lib/command_tower/ui/text_derivation.rb +18 -17
- data/lib/command_tower/ui/time_formatter.rb +5 -3
- data/lib/command_tower/ui.rb +6 -0
- data/lib/command_tower/version.rb +1 -1
- data/lib/command_tower.rb +2 -0
- metadata +78 -2
data/docs/api_reference.md
CHANGED
|
@@ -17,14 +17,15 @@ Proof for contracts lives primarily under `spec/requests/command_tower/`.
|
|
|
17
17
|
5. [Me Inbox](#me-inbox)
|
|
18
18
|
6. [Audit events](#audit-events)
|
|
19
19
|
7. [Preferences](#preferences)
|
|
20
|
-
8. [
|
|
21
|
-
9. [
|
|
22
|
-
10. [
|
|
23
|
-
11. [
|
|
24
|
-
12. [
|
|
25
|
-
13. [
|
|
26
|
-
14. [
|
|
27
|
-
15. [
|
|
20
|
+
8. [Unsubscribe](#unsubscribe)
|
|
21
|
+
9. [Phone](#phone)
|
|
22
|
+
10. [Pushover](#pushover)
|
|
23
|
+
11. [Admin Workspace](#admin-workspace)
|
|
24
|
+
12. [Impersonation](#impersonation)
|
|
25
|
+
13. [Admin messaging](#admin-messaging)
|
|
26
|
+
14. [Non-HTTP emit APIs](#non-http-emit-apis)
|
|
27
|
+
15. [RBAC overview](#rbac-overview)
|
|
28
|
+
16. [Feature gates](#feature-gates)
|
|
28
29
|
|
|
29
30
|
---
|
|
30
31
|
|
|
@@ -189,7 +190,7 @@ Does **not** authorize `admin_impersonation` on the effective user. Shared front
|
|
|
189
190
|
| **Errors** | `401`; `403`; `412` `email_verification_required` when email verification gate applies |
|
|
190
191
|
| **Spec** | `spec/requests/command_tower/auth/principal_capabilities_spec.rb` |
|
|
191
192
|
|
|
192
|
-
Projection is effective entity grants ∩ curated `config.registry.principal_capabilities` (never role/group names). CommandTower seeds `admin_workspace`, `admin_users`, `admin_users_update`, `admin_rbac_assignments`, `admin_audit_events`, `admin_messaging_announcements`, `admin_impersonation`, `me_audit_events`. Hosts may register additive host-owned ids. Distinct from `/me` capabilities and from `GET /admin/workspace` (tool manifest). See [Principal capabilities](principal_capabilities.md).
|
|
193
|
+
Projection is effective entity grants ∩ curated `config.registry.principal_capabilities` (never role/group names). CommandTower seeds `admin_workspace`, `admin_users`, `admin_users_update`, `admin_rbac_assignments`, `admin_audit_events`, `admin_messaging_announcements`, `admin_messaging_gallery`, `admin_messaging_gallery_test_send`, `admin_impersonation`, `me_audit_events`. Hosts may register additive host-owned ids. Distinct from `/me` capabilities and from `GET /admin/workspace` (tool manifest). See [Principal capabilities](principal_capabilities.md).
|
|
193
194
|
|
|
194
195
|
### `GET /auth/email/availability`
|
|
195
196
|
|
|
@@ -337,18 +338,21 @@ Pagination for list: query `limit` (default **50**, max **100**), `offset` (defa
|
|
|
337
338
|
|
|
338
339
|
| Method | Path | Notes |
|
|
339
340
|
|--------|------|--------|
|
|
340
|
-
| `GET` | `/me/inbox` | List — `data` array of
|
|
341
|
+
| `GET` | `/me/inbox` | List — `data` array of conversation/entry rows; pagination meta; query `limit`, `offset`, `scope` only |
|
|
342
|
+
| `GET` | `/me/inbox/conversation` | One conversation's messages. Query: `key` (required), `scope` (`inbox` \| `archived`), and at most one of `around` (item id or `oldest_unread`), `before` (item id), `after` (item id); optional `limit` (only with a window mode) |
|
|
341
343
|
| `GET` | `/me/inbox/:id` | Detail (+ `body`, `metadata`, `notificationTypeKey`, `content`) |
|
|
342
|
-
| `POST` | `/me/inbox/:id/open` | Detail (+ `content`) |
|
|
344
|
+
| `POST` | `/me/inbox/:id/open` | Detail (+ `content`). Renders once; the first non-impersonated open marks the item viewed and emits one `messaging_inbox_item_viewed` audit event (see [audit.md](audit.md)). Impersonated opens return the detail without marking viewed or auditing. |
|
|
343
345
|
| `PATCH` | `/me/inbox/:id/archive` | Item |
|
|
344
346
|
| `DELETE` | `/me/inbox/:id` | `data: null` |
|
|
345
|
-
| `GET` | `/me/inbox/unread-count` | `{ count }` |
|
|
347
|
+
| `GET` | `/me/inbox/unread-count` | `{ count, badgeCount }` (`badgeCount` counts only unread items of badge-eligible notification types) |
|
|
346
348
|
| `POST` | `/me/inbox/bulk/read` | Body `ids` (1–100 ints) → `{ ids, count, changedCount }` |
|
|
347
349
|
| `POST` | `/me/inbox/bulk/unread` | same |
|
|
348
350
|
| `POST` | `/me/inbox/bulk/archive` | same |
|
|
349
351
|
| `POST` | `/me/inbox/bulk/restore` | same |
|
|
350
352
|
| `POST` | `/me/inbox/bulk/delete` | same |
|
|
351
353
|
|
|
354
|
+
For a defined notification type while impersonating (or when the type is unknown), `GET /me/inbox/:id`, `POST /me/inbox/:id/open` and `GET /me/inbox/conversation` return `metadata: null`, and `content` has its `code` nodes replaced (`UI::Redaction`).
|
|
355
|
+
|
|
352
356
|
**`content` (detail only, response-only — `inbox_document_v1`):** rendered at read from the item's `Communication`, never persisted; absent from list items. Shape: `{ schema: "inbox_document_v1", blocks: [...] }`. Allowlisted block types:
|
|
353
357
|
|
|
354
358
|
| Block | Fields | Notes |
|
|
@@ -358,13 +362,19 @@ Pagination for list: query `limit` (default **50**, max **100**), `offset` (defa
|
|
|
358
362
|
| `instant` | `at` (string) | ISO-8601 UTC. Input without an explicit offset adds no block. |
|
|
359
363
|
| `presentation` | `key` (string), `variant` (string or null) | Names a registered presentation capability; its data is composed after authoring. |
|
|
360
364
|
|
|
361
|
-
Generic (default) rendering: one `paragraph` block from `communication.body` (omitted if blank — `blocks` can legitimately be `[]`), plus one `cta` block if `metadata.
|
|
365
|
+
Generic (default) rendering: one `paragraph` block from `communication.body` (omitted if blank — `blocks` can legitimately be `[]`), plus one `cta` block if there is a safe destination: `metadata.deep_link_path` (internal, wins when present and safe) else `metadata.deep_link` (external). Label from `metadata.cta_label`, default `"Open"`.
|
|
366
|
+
|
|
367
|
+
**`X-UI-Catalog` request header:** accepted on every request (CommandTower reads it in the HTTP boundary). Missing or invalid values mean `1`; it changes only Inbox `content` for types registered with a `message:` MessageDefinition (catalog 2 or higher returns `ui_document`, catalog 1 returns `inbox_document_v1`); undefined types are identical for every catalog. Inbox read responses set `Cache-Control: no-store`. See [ui.md](ui.md#catalog-header).
|
|
368
|
+
|
|
369
|
+
**`X-Time-Zone` request header:** an optional TZInfo identifier (for example `America/New_York`, at most 64 characters). The HTTP boundary reads it into `CommandTower::Current.client_time_zone`; anything else is ignored. After a 2xx response to an authenticated, non-impersonated request, CommandTower records it as the user's `last_known_timezone` column, which `GET /me` returns (as the user's shown attribute; hosts with serializer or snapshot tests will see a real value instead of null). The write happens only when the zone changed and the previous write is more than one hour old, fails open (it never changes the response), and never logs the zone. Requests made while impersonating never write. Hosts that list CORS `headers:` explicitly must add `X-Time-Zone` ([bootstrap step 11](bootstrap/11-auth-client-path.md), [cookie guide](cookie_authentication_guide.md#cors)).
|
|
370
|
+
|
|
371
|
+
**Message definition columns:** `messaging_communications` carries three nullable columns for communications of a defined message type: `slots` (JSON, the validated slot values), `render_zone` (string, at most 64 characters: the recipient's `last_known_timezone` when valid, else the definition's default zone) and `metadata_version` (integer). A communication is definition-backed when `metadata_version` is not null; undefined types leave all three NULL. `messaging.strict_definitions` (default true outside production, false in production) decides whether a definition violation (metadata schema, explicit copy on a defined type) fails the request or is logged and degraded.
|
|
362
372
|
|
|
363
|
-
|
|
373
|
+
A notification type may override the document with a pure-Ruby composer (`declaration.inbox_document_composer`, called with `communication:`, returning an `InboxDocument`). Any failure (unregistered type, unresolvable class, a raising composer, a non-`InboxDocument` result) fails open to the generic document — the Inbox read path never 500s on a bad composer. The former `inbox_document.json.erb` host override is no longer read.
|
|
364
374
|
|
|
365
|
-
|
|
375
|
+
**List row fields (`GET /me/inbox`):** `kind`, `id`, `title`, `preview`, `activityAt`, `createdAt`, `messageCount`, `unreadCount`, `read`, `inboxItemIds`. Item payloads (archive, `bulk` targets, conversation `messages`) use `id`, `title`, `status`, `read`, `viewedAt`, `createdAt`, `updatedAt`; conversation messages also carry the detail fields.
|
|
366
376
|
|
|
367
|
-
|
|
377
|
+
Hosts never expose `inboxEnabled` as a user-facing inbox switch; it appears only in the preferences contract below.
|
|
368
378
|
|
|
369
379
|
**Errors:** `401` / `403` / `422`; show/open may return `404` `not_found`.
|
|
370
380
|
|
|
@@ -406,6 +416,21 @@ Category / notification serializers expose catalog fields (`key`, `label`, `desc
|
|
|
406
416
|
|
|
407
417
|
---
|
|
408
418
|
|
|
419
|
+
## Unsubscribe
|
|
420
|
+
|
|
421
|
+
Unauthenticated one-click unsubscribe (RFC 8058). No session, cookie or CSRF; the signed `token` query parameter is the only credential. Configuration, token and limits: [messaging_integration_guide.md](messaging_integration_guide.md#email-compliance-defined-types).
|
|
422
|
+
|
|
423
|
+
| Method | Path | Notes |
|
|
424
|
+
|--------|------|--------|
|
|
425
|
+
| `POST` | `/messaging/unsubscribe?token=` | Email off for the token's user and type. `200` `data`: `{ unsubscribed: true }` (also on a repeat). Any invalid token or ineligible type: identical `422`. Rate limited: `429` with `Retry-After` |
|
|
426
|
+
| `GET` | `/messaging/unsubscribe?token=` | Never reads the token, never mutates. `303` to `composed_url + preferences_path` (documented transport non-envelope) |
|
|
427
|
+
|
|
428
|
+
Both set `Cache-Control: no-store` and `Referrer-Policy: no-referrer`.
|
|
429
|
+
|
|
430
|
+
**Specs:** `spec/requests/command_tower/messaging/unsubscribe_spec.rb`.
|
|
431
|
+
|
|
432
|
+
---
|
|
433
|
+
|
|
409
434
|
## Phone
|
|
410
435
|
|
|
411
436
|
Routes are **always drawn**. Product SMS readiness is workflow-gated as **503** `sms_capability_unavailable`.
|
|
@@ -516,7 +541,7 @@ No query parameters. Envelope `data` (no pagination `meta`):
|
|
|
516
541
|
|
|
517
542
|
Unscoped hosts omit `scope`, `scopeOptions`, and `availability`.
|
|
518
543
|
|
|
519
|
-
Tools are filtered from the composed RBAC grant graph (`allow_everything` or an entity matching the tool's `required_entity`). `description` is additive presentation metadata (soft authoring ≤100 chars; registry hard max 160). CommandTower seeds `users`, `audit`, and `
|
|
544
|
+
Tools are filtered from the composed RBAC grant graph (`allow_everything` or an entity matching the tool's `required_entity`). `description` is additive presentation metadata (soft authoring ≤100 chars; registry hard max 160). CommandTower seeds `users`, `audit`, `messaging`, and `messaging_gallery`. Hosts add tools via `config.registry.admin_workspace.tool`. There is no generic tool execution route. `/me` does not duplicate this list. Do not use this endpoint as a UI permission probe — use [Principal capabilities](principal_capabilities.md).
|
|
520
545
|
|
|
521
546
|
Registration and boot rules: [Admin Workspace](admin_workspace.md).
|
|
522
547
|
|
|
@@ -593,11 +618,44 @@ Expired product request: overlay present + invalid row → **401** `impersonatio
|
|
|
593
618
|
|
|
594
619
|
**Body** (camel preferred; snake via underscore fallback): `title`, `body`, `campaignIdentity` (required), `audience` (`user_ids` \| `all_users`), `userIds` (required when `user_ids`), `notificationTypeKey` (default `"promotional_announcement"`), `executionMode` (`async` \| `sync`, default `async`), `metadata` (optional).
|
|
595
620
|
|
|
621
|
+
**Target type.** An undefined type (no `message:`) is produced with the given `title` and `body`, as before. A type defined by `CommandTower::Messaging::AnnouncementDefinition` (or a subclass) receives `title` and `body` as metadata (`title` up to 200 characters, `body` as markdown up to 5000; `metadata` keys are kept, and these two win) and produces no title or body of its own; a title or body outside those limits is **422** `validation_failed`. Any other defined type fails with **422** `announcement_type_not_supported`.
|
|
622
|
+
|
|
596
623
|
**Async response:** `mode`, `requested`, `campaignIdentity`, `enqueued`, `enqueueFailed`.
|
|
597
624
|
|
|
598
625
|
**Sync response:** `mode`, `requested`, `campaignIdentity`, `accepted`, `failed`, `skipped`, `failures: [{ userId, errorCode }]`.
|
|
599
626
|
|
|
600
|
-
|
|
627
|
+
### `GET /admin/messaging/gallery` and `GET /admin/messaging/gallery/:notification_type_key`
|
|
628
|
+
|
|
629
|
+
| | |
|
|
630
|
+
|--|--|
|
|
631
|
+
| **Auth** | authenticate + authorize (RBAC entity `admin_messaging_gallery`; principal capability of the same id) |
|
|
632
|
+
| **Success** | **200**, `Cache-Control: no-store` |
|
|
633
|
+
| **Errors** | `401`; `403` without the grant; `404` unknown type, type without a message definition, or unknown `fixture`; `422` invalid `zone` or a composer that fails (the failure names the channel and error class only) |
|
|
634
|
+
| **Spec** | `spec/requests/command_tower/admin/messaging/gallery_spec.rb` |
|
|
635
|
+
|
|
636
|
+
Previews every channel of each notification type that declares a `MessageDefinition`, from the definition's declared fixtures. It reads no `Communication` and no user data.
|
|
637
|
+
|
|
638
|
+
**List** returns one item per defined type: `notificationTypeKey`, `label`, `definition`, `allowedChannels`, `promotional`, `fixtures: [{ name, metadataVersion }]`.
|
|
639
|
+
|
|
640
|
+
**Show** query params (both optional): `fixture` (a declared fixture name, default the first) and `zone` (any valid TZInfo identifier, default the definition's `default_zone`). It returns `notificationTypeKey`, `fixture`, `metadataVersion`, `renderZone`, `slots`, `channels` (`push`, `sms`, `pushover`, `inbox`, `email`; a channel the type does not allow is `null`, `inbox` included), `facts` (`app`, `emailHtml`) and `checks`.
|
|
641
|
+
|
|
642
|
+
**Fixtures.** Example payloads for both endpoints, the inbox documents and the email parts are committed under `spec/fixtures/messaging/gallery/`, `spec/fixtures/ui/documents/` and `spec/fixtures/ui/email/`. Regenerate them from the dummy app with `make rake TASK=app:command_tower:messaging:fixtures`; `spec/lib/command_tower/messaging/messaging_fixtures_spec.rb` fails when a committed file differs from a fresh render. Files are sorted, pretty-printed JSON, so consumers can copy them byte for byte.
|
|
643
|
+
|
|
644
|
+
### `POST /admin/messaging/gallery/:notification_type_key/test-send`
|
|
645
|
+
|
|
646
|
+
| | |
|
|
647
|
+
|--|--|
|
|
648
|
+
| **Auth** | authenticate + authorize (RBAC entity `admin_messaging_gallery_test_send`; principal capability of the same id). Separate from `admin_messaging_gallery`: a host grants it explicitly. |
|
|
649
|
+
| **Body / params** | `fixture`, `zone` (both optional, as for the preview) |
|
|
650
|
+
| **Success** | **202** `{ notificationTypeKey, sent: true }`, `Cache-Control: no-store` |
|
|
651
|
+
| **Errors** | `401`; `403` without the grant; `403` `gallery_test_send_impersonating` while impersonating (or when the actor is not the effective user), checked before authorization and instead of the generic admin `418`; `404` unknown type, no definition or unknown `fixture`; `422` invalid `zone`, a failing composer, or a type that does not allow email; `429` `gallery_test_send_rate_limited` with `details.retry_after_seconds`; `500` when the rate-limit store (Redis) is unavailable (fails closed, nothing is sent); `502` `gallery_test_send_failed` with `details.error_code` when the email adapter refuses |
|
|
652
|
+
| **Spec** | `spec/requests/command_tower/admin/messaging/gallery_test_send_spec.rb` |
|
|
653
|
+
|
|
654
|
+
Sends the email channel of one declared fixture to the **real actor's own address** (from the user record, never from the request), through the same adapter boundary as the sender (`SelectAdapter`: the fake adapter when `config.messaging.allow_fake_adapter` is on, else the configured email adapter). Email only. It writes no `Communication`. The subject is the preview subject unchanged; a "Test message" line sits above the compliance footer; no `List-Unsubscribe*` headers are added.
|
|
655
|
+
|
|
656
|
+
Rate limit, keyed on the real actor: 5 an hour and 20 a day. A rejected call returns `429` and sends nothing. Each accepted send audits `messaging_gallery_test_sent` (retention `one_year`; metadata `actor_id`, `notification_type_key`, `fixture`; never the address). See [Audit](audit.md).
|
|
657
|
+
|
|
658
|
+
Engine admin HTTP includes workspace manifest, announcements, the message gallery (preview and test send), audit events, Users list/show, and impersonation start. Users admin also includes identity mutations (`PATCH /admin/users/:id/{name,username,email,email-validation}`) and role assignment (`PATCH /admin/users/:id/roles`); see [Admin Users](#admin-users).
|
|
601
659
|
|
|
602
660
|
---
|
|
603
661
|
|
|
@@ -607,8 +665,8 @@ Hosts call these from **product workflows** (not as HTTP on the engine):
|
|
|
607
665
|
|
|
608
666
|
| Service | Required kwargs |
|
|
609
667
|
|---------|-----------------|
|
|
610
|
-
| `CommandTower::Services::Messaging::Communications::Produce` | `user`, `notification_type_key`, `host_event_identity`, `title`, `body`, `platform_enabled_channels`; optional `metadata` |
|
|
611
|
-
| `CommandTower::Services::Messaging::Communications::ProduceMany` | `user_ids`, `notification_type_key`, `campaign_identity`, `title`, `body`, `platform_enabled_channels`; optional `metadata`, `execution_mode` (`:async` default, `:sync` capped at 25) |
|
|
668
|
+
| `CommandTower::Services::Messaging::Communications::Produce` | `user`, `notification_type_key`, `host_event_identity`, `title`, `body`, `platform_enabled_channels`; optional `metadata`, `conversation_key`, `conversation_title`. Fails validation when the registered type has `deep_link_required` and `metadata` has no non-blank `deep_link` |
|
|
669
|
+
| `CommandTower::Services::Messaging::Communications::ProduceMany` | `user_ids`, `notification_type_key`, `campaign_identity`, `title`, `body`, `platform_enabled_channels`; optional `metadata`, `conversation_key`, `conversation_title`, `execution_mode` (`:async` default, `:sync` capped at 25) |
|
|
612
670
|
|
|
613
671
|
Details: [messaging_integration_guide.md](messaging_integration_guide.md).
|
|
614
672
|
|
data/docs/audit.md
CHANGED
|
@@ -78,11 +78,20 @@ CommandTower.config.registry.audit.set_enabled!(:login_failed, true)
|
|
|
78
78
|
| `phone_cleared` | yes | no |
|
|
79
79
|
| `phone_verified` | yes | no |
|
|
80
80
|
| `announcement_produced` | yes | no |
|
|
81
|
+
| `messaging_unsubscribed` | yes | no |
|
|
82
|
+
| `messaging_gallery_test_sent` | yes | no |
|
|
81
83
|
| `impersonation_started` | yes | no |
|
|
82
84
|
| `impersonation_ended` | yes | no |
|
|
83
85
|
| `session_created` | yes | yes |
|
|
84
86
|
| `session_cleared` | no | yes |
|
|
85
87
|
| `login_failed` | no | yes |
|
|
88
|
+
| `messaging_inbox_item_viewed` | yes | yes |
|
|
89
|
+
|
|
90
|
+
`messaging_inbox_item_viewed` is emitted by `Workflows::Messaging::Inbox::OpenWorkflow` once per first view of an inbox item, for every notification type (metadata: `inbox_item_id`, `communication_id`; retention `ninety_days`, not in account history). A repeat open, bulk read/unread, `Show`, and `Contract::Inbox` emit nothing. An impersonated open returns the detail but neither marks the item viewed nor audits.
|
|
91
|
+
|
|
92
|
+
`messaging_unsubscribed` is emitted by the one-click unsubscribe workflow when a token turns email off for a type (affected user: the token's user; change key `email_enabled`; `user_history`; retention `permanent`). See [messaging_integration_guide.md](messaging_integration_guide.md#email-compliance-defined-types).
|
|
93
|
+
|
|
94
|
+
`messaging_gallery_test_sent` is emitted by `Workflows::Admin::Messaging::Gallery::TestSendWorkflow` for each accepted gallery test send (affected user: the actor; metadata: `actor_id`, `notification_type_key`, `fixture`, never the address; retention `one_year`, not in account history).
|
|
86
95
|
|
|
87
96
|
Sensitive-field / user-history / retention stay on the **registry** for emit-time policy. At INSERT the persistence subscriber copies the **smallest historical snapshot**: `user_history`, `sensitive_fields`, and `retention`. Later registry changes must not unmask historical PII. Read APIs treat a change key as sensitive if it is in the **union** of the row snapshot and the current definition (current may be more restrictive; it cannot unmask). Account-history eligibility is **only** the snapshot `user_history` column. The snapshot does not include `enabled`, `allowed_changes`, or owner. There is no `visibility` column. Retention is stored and **not enforced** as a delete/filter yet.
|
|
88
97
|
|
|
@@ -138,7 +138,7 @@ POST /admin/messaging/announcements
|
|
|
138
138
|
DELETE /auth/impersonation-session
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
Impersonation is a session overlay, not a User mutation and not an Admin Workspace tool.
|
|
141
|
+
Impersonation is a session overlay, not a User mutation and not an Admin Workspace tool. Admin user mutations (`PATCH /admin/users/:id/{name,username,email,email-validation,roles}`) are separate routes; impersonation does not perform them. See [Admin Users](api_reference.md#admin-users).
|
|
142
142
|
|
|
143
143
|
## Email verification gate
|
|
144
144
|
|
data/docs/bootstrap/09-rbac.md
CHANGED
|
@@ -74,6 +74,8 @@ The frontend workspace and user detail call these entities. Grant each one the r
|
|
|
74
74
|
- `admin_users`
|
|
75
75
|
- `admin_audit_events`
|
|
76
76
|
- `admin_messaging_announcements`
|
|
77
|
+
- `admin_messaging_gallery`
|
|
78
|
+
- `admin_messaging_gallery_test_send`
|
|
77
79
|
- `admin_impersonation`
|
|
78
80
|
|
|
79
81
|
`admin_impersonation` is what shows Impersonate. The frontend does not add a route for it.
|
|
@@ -48,7 +48,7 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
|
|
48
48
|
end
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
`headers: :any` already covers the `X-UI-Catalog` request
|
|
51
|
+
`headers: :any` already covers the `X-UI-Catalog` and `X-Time-Zone` request headers. A host that lists allowed headers explicitly must add `X-UI-Catalog` and `X-Time-Zone`.
|
|
52
52
|
|
|
53
53
|
`credentials: true` requires an **explicit origin list**, not `*`. Compose already passes `CORS_ALLOWED_ORIGINS` from step 01. The sample origins `8081`, `8082`, and `19006` belong to one web product. Add the origin this Expo web app actually uses, and keep it aligned with `config.application.url` and the API’s published port.
|
|
54
54
|
|
|
@@ -158,6 +158,8 @@ allow do
|
|
|
158
158
|
end
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
+
`headers: :any` covers the `X-Time-Zone` and `X-UI-Catalog` request headers. A host that lists allowed headers explicitly must add both.
|
|
162
|
+
|
|
161
163
|
`SameSite=None` cookies require `Secure=true` (HTTPS). Prefer same-site deployments with `SameSite=Lax` when possible.
|
|
162
164
|
|
|
163
165
|
## Production checklist
|
data/docs/extending.md
CHANGED
|
@@ -84,6 +84,8 @@ Product business events own **host** workflows that call:
|
|
|
84
84
|
- `CommandTower::Services::Messaging::Communications::Produce`
|
|
85
85
|
- `CommandTower::Services::Messaging::Communications::ProduceMany`
|
|
86
86
|
|
|
87
|
+
`CommandTower::Messaging::Contract::Inbox` mutation (`mark_viewed_for_communication`) emits no audit and is called only from a workflow that owns the audit decision.
|
|
88
|
+
|
|
87
89
|
Do not create one Messaging workflow per message type. Do not call the messaging handoff/execution pipeline directly. Summary: [messaging_integration_guide.md](messaging_integration_guide.md).
|
|
88
90
|
|
|
89
91
|
## Blank-host checklist
|
|
@@ -126,6 +128,8 @@ Nested `with_execution` shares the outer context. Do not wrap `db:migrate` or do
|
|
|
126
128
|
|
|
127
129
|
If a host **cannot** change `ApplicationController` / `ApplicationJob` superclasses, include `CommandTower::Execution::HttpBoundary` / `CommandTower::Execution::JobBoundary` as a compatibility escape hatch. Do not include those modules into every `ActionController` or `ActiveJob::Base`.
|
|
128
130
|
|
|
131
|
+
`HttpBoundary` also reads `X-Time-Zone` into `CommandTower::Current.client_time_zone` and, after a 2xx authenticated response, calls `Services::Users::RecordLastKnownTimeZone`. This is a deliberate deviation from "writes go through a workflow": it is throttled request bookkeeping on the authenticated user (like impersonation `RecordActivity`), not a business operation, and it must never change or fail the response, so it runs after the action, fails open, and skips impersonated requests. The user comes from the authentication result because `Current` carries user ids, not a user. See [api_reference.md](api_reference.md).
|
|
132
|
+
|
|
129
133
|
Automatic workflow/service lifecycle notifications are emitted by CommandTower kernels. Logging is a subscriber: emission is exhaustive; materialization is selective; log records are curated projections. The host owns format. See [Eventing](eventing.md).
|
|
130
134
|
|
|
131
135
|
## Related
|
|
@@ -10,8 +10,8 @@ Complete install and host RBAC first: [Bootstrap a new host](bootstrap/README.md
|
|
|
10
10
|
|---------|----------------|
|
|
11
11
|
| User inbox (consume) | Engine `/me/inbox*` — see [API reference](api_reference.md#me-inbox) |
|
|
12
12
|
| Preferences | Engine `/me/preferences*` — see [API reference](api_reference.md#preferences) |
|
|
13
|
+
| User inbox conversation | Engine `GET /me/inbox/conversation` — see [API reference](api_reference.md#me-inbox) |
|
|
13
14
|
| Phone / Pushover / Push endpoints | Engine `/me/phone*`, `/me/pushover*`, `/me/push*` (503 when capability unavailable) |
|
|
14
|
-
|
|
15
15
|
| Single-recipient emit | `CommandTower::Services::Messaging::Communications::Produce` |
|
|
16
16
|
| Multi-recipient emit | `CommandTower::Services::Messaging::Communications::ProduceMany` |
|
|
17
17
|
| Admin cohort announce | Engine `POST /admin/messaging/announcements` |
|
|
@@ -44,6 +44,10 @@ CommandTower::Services::Messaging::Communications::Produce.call(
|
|
|
44
44
|
| `body` | yes |
|
|
45
45
|
| `platform_enabled_channels` | yes (`Array`) |
|
|
46
46
|
| `metadata` | no (`Hash`) |
|
|
47
|
+
| `conversation_key` | no (`String`) — groups inbox items into one conversation |
|
|
48
|
+
| `conversation_title` | no (`String`) |
|
|
49
|
+
|
|
50
|
+
`Produce` fails with a validation error when the registered type declares `deep_link_required` and `metadata` has no non-blank `deep_link`.
|
|
47
51
|
|
|
48
52
|
## ProduceMany (multi recipient)
|
|
49
53
|
|
|
@@ -55,6 +59,7 @@ CommandTower::Services::Messaging::Communications::Produce.call(
|
|
|
55
59
|
| `title`, `body` | yes |
|
|
56
60
|
| `platform_enabled_channels` | yes |
|
|
57
61
|
| `metadata` | optional |
|
|
62
|
+
| `conversation_key`, `conversation_title` | optional (`String`), applied to every recipient's item |
|
|
58
63
|
| `execution_mode` | optional, default `:async`; `:sync` capped at **25** recipients |
|
|
59
64
|
|
|
60
65
|
Admin announcements HTTP is a product path over ProduceMany (async/sync, audience selection). Contract: [API reference — Admin messaging](api_reference.md#admin-messaging).
|
|
@@ -85,31 +90,51 @@ Notes:
|
|
|
85
90
|
- Generic templates receive the same four locals as before (`title`, `body`, `deep_link`, `h` — an HTML-escaping helper). Type-specific templates additionally receive `metadata` (the communication's metadata Hash) and `notification_type_key`.
|
|
86
91
|
- A missing or failing template (generic or type-specific) surfaces the same way it always has: `RenderError` with code `"render_failed"`.
|
|
87
92
|
|
|
88
|
-
### Inbox document override
|
|
89
|
-
|
|
90
|
-
The Me Inbox detail `content` field (`inbox_document_v1`, see [api_reference.md](api_reference.md#me-inbox)) is built by a separate collaborator, `InboxDocumentRenderer`, using the **same** type-directory convention and sanitized-key rule as above, resolved through `TemplateResolver.render_type_template`:
|
|
91
|
-
|
|
92
|
-
```text
|
|
93
|
-
app/views/command_tower/messaging/rendering/
|
|
94
|
-
<notification_type_key>/
|
|
95
|
-
inbox_document.json.erb # optional type-specific inbox content override
|
|
96
|
-
```
|
|
93
|
+
### Inbox document (no ERB override)
|
|
97
94
|
|
|
98
|
-
|
|
95
|
+
The Me Inbox detail `content` field (`inbox_document_v1`, see [api_reference.md](api_reference.md#me-inbox)) is built by `InboxDocumentRenderer`. An `inbox_document.json.erb` view is **not** read (the override was replaced). A notification type customizes the document through `declaration.inbox_document_composer`, a pure-Ruby class called with `communication:` that returns an `InboxDocument`. The generic document is built in Ruby from `communication.body` and `metadata`. A missing, raising, or invalid composer falls back silently to the generic document — the Inbox read path never surfaces a `RenderError` and never 500s.
|
|
99
96
|
|
|
100
97
|
## Me Inbox HTTP (summary)
|
|
101
98
|
|
|
102
99
|
| Concern | Contract |
|
|
103
100
|
|---------|----------|
|
|
104
|
-
| List | `GET /me/inbox?limit=&offset=&scope=` — meta `{ limit, offset, totalCount }` |
|
|
105
|
-
|
|
|
101
|
+
| List | `GET /me/inbox?limit=&offset=&scope=` — conversation/entry rows, meta `{ limit, offset, totalCount }` |
|
|
102
|
+
| Conversation | `GET /me/inbox/conversation?key=&scope=` (+ one of `around`/`before`/`after`, `limit`) |
|
|
103
|
+
| Detail / open / archive / delete | `/me/inbox/:id` (+ `open`, `archive`). Open marks viewed on first non-impersonated view and audits once (`messaging_inbox_item_viewed`). For defined types while impersonating (or unknown types), show, open and conversation return `metadata: null` and `content` with `code` nodes replaced (`UI::Redaction`) |
|
|
106
104
|
| Bulk | `POST /me/inbox/bulk/{read,unread,archive,restore,delete}` with body `ids` |
|
|
107
|
-
| Unread | `GET /me/inbox/unread-count` |
|
|
105
|
+
| Unread | `GET /me/inbox/unread-count` — `{ count, badgeCount }` |
|
|
108
106
|
|
|
109
|
-
Detail `content` is `inbox_document_v1` with blocks `paragraph`, `cta` (typed `destination`: internal `path` or external `href`), `instant`, and `presentation`. The `X-UI-Catalog` request header is accepted and defaults to `1`; it
|
|
107
|
+
Detail `content` is `inbox_document_v1` with blocks `paragraph`, `cta` (typed `destination`: internal `path` or external `href`), `instant`, and `presentation`. The `X-UI-Catalog` request header is accepted and defaults to `1`; it changes Inbox `content` only for types registered with a `message:` MessageDefinition (catalog 2 or higher returns `ui_document`); undefined types return `inbox_document_v1` for every catalog, and Inbox read responses set `Cache-Control: no-store` ([ui.md](ui.md#catalog-header)). Hosts never expose `inboxEnabled` as an inbox switch to users outside the preferences contract.
|
|
110
108
|
|
|
111
109
|
Pagination detail: [pagination.md](pagination.md). Full catalog: [api_reference.md](api_reference.md#me-inbox).
|
|
112
110
|
|
|
111
|
+
## Email compliance (defined types)
|
|
112
|
+
|
|
113
|
+
Emails for types registered with a `message:` MessageDefinition carry a compliance footer and, when eligible, RFC 8058 one-click unsubscribe headers. Undefined types get neither (their ERB templates are unchanged).
|
|
114
|
+
|
|
115
|
+
**Config** (`config.messaging.compliance`):
|
|
116
|
+
|
|
117
|
+
| Key | Purpose |
|
|
118
|
+
|-----|---------|
|
|
119
|
+
| `api_base_url` | Public API origin (no trailing slash, no `/api`) for the unsubscribe URL. Defaults to ENV `COMMAND_TOWER_API_BASE_URL`. Unset: headers are omitted and boot logs one warning listing the affected type keys |
|
|
120
|
+
| `preferences_path` | Appended to `config.application.composed_url` for the footer link. Unset: the link is `composed_url` |
|
|
121
|
+
| `postal_address` | Printed in the footer of promotional email. Required for any `promotional` MessageDefinition (seal check) |
|
|
122
|
+
| `unsubscribe_secret` | Optional. Overrides the key derived from `secret_key_base`. Never log it |
|
|
123
|
+
|
|
124
|
+
**Footer.** Three copies: transactional, promotional (adds `postal_address` and "Unsubscribe or manage email preferences"), and mandatory ("about your account"). The footer is the same in the composed and the fallback email, never carries a token, and does not change when headers are omitted.
|
|
125
|
+
|
|
126
|
+
**Headers.** `List-Unsubscribe: <{api_base_url}/messaging/unsubscribe?token=...>` and `List-Unsubscribe-Post: List-Unsubscribe=One-Click`. Set only for types that are not mandatory, are user configurable, allow `email`, and when `api_base_url` is set.
|
|
127
|
+
|
|
128
|
+
**Token.** A signed (not encrypted) `message_verifier("command_tower/messaging/unsubscribe")` value with purpose `unsubscribe`, payload `{u: user_id, t: notification_type_key}`, valid 90 days. It can only turn email off for that one user and type. `token` is a filtered parameter, so Rails logs hide it.
|
|
129
|
+
|
|
130
|
+
**Endpoint.** `POST /messaging/unsubscribe?token=` (mounted under `/api`) opts the user out of email for that type through the existing preferences update and audits `messaging_unsubscribed` (`user_history`, permanent) once; a repeat changes nothing and emits no second audit. Every failure (expired, tampered, wrong purpose, mandatory, unknown or ineligible type) returns the identical `422`, so the endpoint is not an oracle. `GET` never mutates: it returns `303` to `composed_url + preferences_path` with no token or user id, for people who click the link or scanners that prefetch it. Responses set `Cache-Control: no-store` and `Referrer-Policy: no-referrer`. Details: [api_reference.md](api_reference.md#unsubscribe).
|
|
131
|
+
|
|
132
|
+
**Limits.** Per token digest: 10 requests per 60 seconds (main limit). Per client IP: 120 per 60 seconds (high, because recipients share gateways). Over a limit: `429` with `Retry-After`. If Redis fails the limits fail open, so an outage never blocks an opt-out.
|
|
133
|
+
|
|
134
|
+
**Trusted proxy.** The client IP is `request.remote_ip`, which follows `X-Forwarded-For` only from the host's `trusted_proxies`. Hosts behind a load balancer must configure it, or every request shares one IP bucket.
|
|
135
|
+
|
|
136
|
+
**Accepted risk (O1, replay).** The token is a bearer value valid for 90 days and is not single use. Anyone holding the email can opt that user out of that type; the effect is limited to turning email off, which the user can undo in preferences.
|
|
137
|
+
|
|
113
138
|
## Host responsibilities
|
|
114
139
|
|
|
115
140
|
- Notification catalog content (registered into CommandTower notification types)
|
|
@@ -41,6 +41,8 @@ Lookup: `CommandTower.config.registry.principal_capabilities.fetch(:admin_worksp
|
|
|
41
41
|
| `admin_rbac_assignments` | Gate Admin Users role assignment (assignable catalog + PATCH roles) |
|
|
42
42
|
| `admin_audit_events` | Gate Audit Admin affordances and deep links outside the workspace manifest |
|
|
43
43
|
| `admin_messaging_announcements` | Gate Messaging Admin affordances outside the manifest |
|
|
44
|
+
| `admin_messaging_gallery` | Gate the Message gallery (preview every channel per message type). Only `owner` holds it by default; hosts grant it explicitly. |
|
|
45
|
+
| `admin_messaging_gallery_test_send` | Gate the gallery test send. Only `owner` holds it by default; hosts grant it explicitly. |
|
|
44
46
|
| `admin_impersonation` | Gate Impersonate affordances (5.6 composition). Possession does not start a session by itself. |
|
|
45
47
|
| `me_audit_events` | Gate Account **Activity** / self-audit Explorer presentation (4.7.1). Hosts own who receives the entity. |
|
|
46
48
|
|
data/docs/ui.md
CHANGED
|
@@ -78,6 +78,29 @@ Validation errors (`InvalidDocumentError#details`) carry node paths and codes on
|
|
|
78
78
|
| `Facts` | Base class for a host fact block. `Facts.call(builder, metadata:)` emits exactly one `facts` node; subclasses implement `compose(b, metadata:)`. |
|
|
79
79
|
| `CtaGroup` | Stacked buttons: the primary first, then up to two secondaries. |
|
|
80
80
|
| `NoticeFrame` | Tinted card with a title and body paragraphs. Informational only. |
|
|
81
|
+
| `Markdown` | One `stack` of `text` nodes from a markdown `source` (subset below). Optional `node_budget` (default 150). |
|
|
82
|
+
|
|
83
|
+
### Markdown subset
|
|
84
|
+
|
|
85
|
+
`Fragments::Markdown` parses with kramdown and walks the AST against an allowlist. Raw HTML never reaches the document.
|
|
86
|
+
|
|
87
|
+
| Author writes | Result |
|
|
88
|
+
|---|---|
|
|
89
|
+
| Paragraphs | `text` body. A soft line break is a space; a hard break is a newline. |
|
|
90
|
+
| `**bold**`, `__bold__` | strong span |
|
|
91
|
+
| `[label](https://...)`, `mailto:`, `tel:`, `[label](/internal)`, `<https://...>` | link span (`navigate`) |
|
|
92
|
+
| Links with `http:`, `javascript:`, `data:` or any other scheme | label as plain text |
|
|
93
|
+
| `#`, `##` / `###` / `####`-`######` | `text` variant `title` / `subtitle` (secondary tone) / `body` |
|
|
94
|
+
| `-`, `*`, `+` lists | one `text` per item with a "• " prefix, in a `stack` with gap `xs` |
|
|
95
|
+
| `1.` lists | "1. ", "2. " prefixes |
|
|
96
|
+
| Nested lists | flattened to one level |
|
|
97
|
+
| `*em*`, `` `code` ``, fenced code, `> quote` | plain text (code keeps line breaks) |
|
|
98
|
+
| Tables | one paragraph per row, cells joined by " · " |
|
|
99
|
+
| `---`, images, comments | dropped |
|
|
100
|
+
| Raw HTML | tags removed and text kept; `script` and `style` dropped with their content |
|
|
101
|
+
| Strikethrough, task lists | literal text |
|
|
102
|
+
|
|
103
|
+
Limits: a paragraph over 1999 characters, or over 50 spans, is split at a word boundary into several `text` nodes. Output beyond `node_budget` nodes is cut and ends with a "…" paragraph; the cut is logged with counts only. Design: `ux/states.md` section 6, G11 and G12.
|
|
81
104
|
|
|
82
105
|
## Time formatter and abbreviation rule
|
|
83
106
|
|
|
@@ -93,6 +116,27 @@ Validation errors (`InvalidDocumentError#details`) carry node paths and codes on
|
|
|
93
116
|
|
|
94
117
|
On the server the zone label is always shown for every format except `date`, unless `label: :never`. The label comes from `ZoneAbbreviation` and the `zoneAbbreviations` / `ambiguousAbbreviations` / `tzdataVersion` data in the token mapping. Regenerate it inside Docker with the engine task `app:command_tower:ui:zone_abbreviations` (`YEAR=` pins the generation year).
|
|
95
118
|
|
|
119
|
+
## User zone
|
|
120
|
+
|
|
121
|
+
A `time` node, `TimeFormatter`, `TextDerivation` and `Email::Renderer` accept `zone: :user` (wire value `"user"`). The server resolves it to the `user_zone:` keyword, which defaults to `config.ui.default_zone`; the app resolves it to the device zone. A `:time` fact node without a zone renders in the render zone.
|
|
122
|
+
|
|
123
|
+
## Message profile
|
|
124
|
+
|
|
125
|
+
`Document#validate!(profile: :message)` adds one rule to the default checks: the document has exactly one `facts` node. The default profile is unchanged.
|
|
126
|
+
|
|
127
|
+
## Redaction
|
|
128
|
+
|
|
129
|
+
`UI::Redaction.call(document, impersonating:)` returns a new document in which every `code` node becomes a `text` node reading "Open the app to check in" (variant `body`, `textTone: secondary`, label dropped), so the code value never reaches the serialised document. Only `impersonating: false` skips it; any other value redacts.
|
|
130
|
+
|
|
131
|
+
## Required facts
|
|
132
|
+
|
|
133
|
+
`UI::RequiredFacts::Verdict.call(texts:, metadata:, required_facts:, render_zone:)` is a pure check for specs and the gallery (never the send path). It returns `[{ channel:, fact_key:, passed: }]`, one row per text and required fact.
|
|
134
|
+
|
|
135
|
+
- `texts` maps channel to rendered text. Callers leave out `headline` and `pushover_title`.
|
|
136
|
+
- Each required fact is a hash: `key:`, `matcher:` (`:text`, `:time` or a host matcher), `zone:` (metadata key holding an IANA zone, or `:user`) and `optional:`. An optional fact with no metadata value yields no rows.
|
|
137
|
+
- `:text` passes when the metadata value is a substring of the text. `:time` passes when the `:time`-preset rendering (for example "6:00 AM PT") in the fact's zone is a substring; `:user` and a missing zone use `render_zone`.
|
|
138
|
+
- Host matcher protocol: any object responding to `call(text:, metadata:, t:)` and returning a Boolean. `t` is `t.call(at, zone:, format: :short, label: :auto)`, backed by `TimeFormatter` with `render_zone` as the user zone.
|
|
139
|
+
|
|
96
140
|
## Limits
|
|
97
141
|
|
|
98
142
|
`CommandTower::UI::Limits`, mirrored by `spec/fixtures/ui/wire_hardening.json` for the frontend normalizer:
|
|
@@ -118,7 +162,21 @@ Paths and links are hardened by `Hardening` (shared cases in `wire_hardening.jso
|
|
|
118
162
|
- `code` nodes raise `InvalidDocumentError` (a check-in code never reaches an email).
|
|
119
163
|
- Conversions: `component` becomes its fallback tree; internal `navigate` becomes `origin + path`; `countdown` becomes `short`; icons are dropped; a ghost button becomes an underlined link; image width and height derive from `aspect`.
|
|
120
164
|
- Text colour comes from `textTone`.
|
|
121
|
-
-
|
|
165
|
+
- The caller supplies `palette:`. Emails for MessageDefinition-backed types resolve it with `CommandTower::EmailTheme::Palette.resolve` (see "Email token file").
|
|
166
|
+
|
|
167
|
+
### Email token file
|
|
168
|
+
|
|
169
|
+
The 13-key palette comes from the first source that exists:
|
|
170
|
+
|
|
171
|
+
1. The host token file `config/ui_tokens.json` under `Rails.root`.
|
|
172
|
+
2. A customised `config.email_theme` (the 9 legacy keys map onto palette keys; `muted`, `success`, `warning` and `danger` come from the CT default).
|
|
173
|
+
3. CT's default file, `lib/command_tower/email_theme/default_ui_tokens.json`.
|
|
174
|
+
|
|
175
|
+
File format: `{ "version": 1, "palette": { "<token>": "#RRGGBB", ... } }`. `version` must be `1`. `palette` must carry every key in `UI::Email::Styles::PALETTE_KEYS` (13 keys) as `#RRGGBB`; extra tokens are ignored. The frontend export bin writes the file (`ct-export-email-tokens`).
|
|
176
|
+
|
|
177
|
+
At boot, an invalid host file raises (the message names keys, never values). A missing host file logs one warning and email falls back to sources 2 and 3. When the host file exists, `EmailTheme::Resolver` derives the 9 legacy keys from it.
|
|
178
|
+
|
|
179
|
+
Mailer previews for defined types: `/rails/mailers/message_definition/sample_email`, `sample_email_fallback` (composer failure, CT fallback document), `sample_email_user_zone`, `sample_email_promotional` (promotional footer with postal address) and `sample_email_without_api_base_url` (footer when one-click headers are omitted) (rails_app dummy app). Footer and header contract: [messaging_integration_guide.md](messaging_integration_guide.md#email-compliance-defined-types).
|
|
122
180
|
|
|
123
181
|
## Legacy mapping
|
|
124
182
|
|
|
@@ -128,7 +186,11 @@ Paths and links are hardened by `Hardening` (shared cases in `wire_hardening.jso
|
|
|
128
186
|
|
|
129
187
|
Clients send `X-UI-Catalog: <n>`. `UI::Catalog.from_header` returns `1` for a missing, blank, non-integer or non-positive value and clamps higher numbers to `UI::CATALOG` (currently `2`). `HttpBoundary` passes the result into `with_execution`, and it is available as `CommandTower::Current.ui_catalog` (default `1`; nested `with_execution` keeps the outer value).
|
|
130
188
|
|
|
131
|
-
It
|
|
189
|
+
It changes only Inbox read responses for types registered with a `message:` MessageDefinition: catalog 2 or higher returns the validated `UI::Document` (`ui_document`), catalog 1 returns `inbox_document_v1` through `UI::LegacyMapping`. Undefined types return the same `inbox_document_v1` for every catalog. The header is never read for authorization. Inbox read responses (list, show, open, conversation) set `Cache-Control: no-store`.
|
|
190
|
+
|
|
191
|
+
Push, SMS and Pushover for defined types are built from the slots stored at Accept (`headline`, `push_body`, `sms_body`, `pushover_title`, `pushover_message`), not from the catalog; undefined types keep the generic templates.
|
|
192
|
+
|
|
193
|
+
See [api_reference.md](api_reference.md#me-inbox) and the CORS note in [bootstrap/11-auth-client-path.md](bootstrap/11-auth-client-path.md).
|
|
132
194
|
|
|
133
195
|
## Producer contracts
|
|
134
196
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Upgrade: CommandTower 0.23.0
|
|
2
|
+
|
|
3
|
+
**From:** `0.22.0`
|
|
4
|
+
**To:** `0.23.0`
|
|
5
|
+
|
|
6
|
+
Minor release: hosts can register a `MessageDefinition` per notification type. A defined type declares facts, an inbox composer, an email composer and slots, and gets inbox, email, push, SMS and Pushover from one source. Email carries a compliance footer and RFC 8058 one-click unsubscribe. The admin Message gallery previews every channel and can send a test email. Authoring: [ui.md](../ui.md), [messaging_integration_guide.md](../messaging_integration_guide.md).
|
|
7
|
+
|
|
8
|
+
Undefined types keep their current behavior except for the eight approved changes below.
|
|
9
|
+
|
|
10
|
+
## Changes that also affect undefined types
|
|
11
|
+
|
|
12
|
+
| # | Change | Host impact |
|
|
13
|
+
|---|--------|-------------|
|
|
14
|
+
| 1 | Impersonated Open (`POST /me/inbox/:id/open` while impersonating) no longer marks the item viewed and does not audit. | Returns the same detail. A non-impersonated Open still marks viewed. |
|
|
15
|
+
| 2 | `messaging_inbox_item_viewed` audit event, once per first view of an inbox item, for every type. | New audit rows (retention `ninety_days`). Enablement is configurable ([audit.md](../audit.md)). |
|
|
16
|
+
| 3 | `Cache-Control: no-store` on inbox list, show, open and conversation. | Nothing in CommandTower or the shared frontend relies on ETag or conditional GET for these routes. Check any host proxy or client that does. |
|
|
17
|
+
| 4 | `GET /me` returns a real `lastKnownTimezone`. | The column is now written (see `X-Time-Zone` below). Hosts with `/me` serializer or snapshot tests see a value instead of null. |
|
|
18
|
+
| 5 | Email colours can change (ERB and auth mailers) once a host adds `config/ui_tokens.json`. | Without that file nothing changes. With it, the 9 legacy `email_theme` keys derive from the file's palette. When the palette equals the host's `email_theme`, the derived keys are identical. |
|
|
19
|
+
| 6 | Frontend `impersonating` text changes from the `••••••` mask to "Open the app to check in" (arrives with `@commandtower/frontend` 0.3.0). | Visible to operators who impersonate. |
|
|
20
|
+
| 7 | `inbox_document_composer` deprecation log line at boot, for every type still using it. | Noisy and harmless; fires for both current hosts. Migrate to `message:` when ready. |
|
|
21
|
+
| 8 | `Open` renders the document once. The communication persister writes NULL (not `{}`) for the new columns of undefined types. | Response bodies are byte-identical for undefined types (regression specs). |
|
|
22
|
+
|
|
23
|
+
## Host-visible additions
|
|
24
|
+
|
|
25
|
+
| Change | Host impact |
|
|
26
|
+
|--------|-------------|
|
|
27
|
+
| `MessageDefinition`, `AnnouncementDefinition` | Register with `message:` on a notification type. Sealed at boot; invalid definitions fail the boot check. |
|
|
28
|
+
| Migration `AddMessageDefinitionColumnsToMessagingCommunications` | Adds nullable `slots` (JSON), `render_zone` (string, 64) and `metadata_version` (integer) to `messaging_communications`. Additive and reversible; no backfill, no index. |
|
|
29
|
+
| `config.messaging.strict_definitions` | Default true in development and test, false in production. True: a definition violation fails the request. False: logged and degraded. |
|
|
30
|
+
| `config.messaging.compliance` | `api_base_url` (or ENV `COMMAND_TOWER_API_BASE_URL`), `preferences_path`, `postal_address` (required for promotional definitions), `unsubscribe_secret`. See [messaging integration guide](../messaging_integration_guide.md#email-compliance-defined-types). |
|
|
31
|
+
| One-click unsubscribe | Unauthenticated `POST` and `GET /api/messaging/unsubscribe?token=`. Defined, eligible types only. |
|
|
32
|
+
| `X-Time-Zone` request header | Read by the HTTP boundary; written to `users.last_known_timezone` after a 2xx authenticated, non-impersonated request (at most once an hour per user). |
|
|
33
|
+
| `token` filtered parameter | The engine adds `:token` to `filter_parameters`, so Rails logs hide it. |
|
|
34
|
+
| Shared email token file | Optional host `config/ui_tokens.json` (from the frontend `ct-export-email-tokens` bin). An invalid file is a boot error; a missing file logs one warning. |
|
|
35
|
+
| Message gallery | `GET /admin/messaging/gallery`, `GET /admin/messaging/gallery/:notification_type_key`, `POST .../test-send`. Admin tool `messaging_gallery`. |
|
|
36
|
+
| Audit events | `messaging_unsubscribed`, `messaging_inbox_item_viewed`, `messaging_gallery_test_sent`. |
|
|
37
|
+
| Email text part | `UI::Email::TextPart` now renders links and buttons as `label: url`. This changes the plain-text part of every UI-document email, not only defined types. |
|
|
38
|
+
| UI library | `zone: :user`, `profile: :message`, `UI::Redaction` (impersonators never receive `code.value`), `UI::RequiredFacts::Verdict`, `Fragments::Markdown` (adds the `kramdown` runtime dependency). |
|
|
39
|
+
|
|
40
|
+
## Host actions
|
|
41
|
+
|
|
42
|
+
1. Bump gem to `0.23.0` (or `>= 0.23.0`) and run `bundle install` (new dependency `kramdown`).
|
|
43
|
+
2. **Run the migration** (`db:migrate`) before the new code serves traffic. The columns are nullable and additive.
|
|
44
|
+
3. **CORS:** if the host lists CORS `headers:` explicitly, add `X-Time-Zone` (and keep `X-UI-Catalog`). `headers: :any` already covers both. Frontend 0.3.0 sends `X-Time-Zone`, so a host adopts FE 0.3.0 only after its CORS list is checked ([bootstrap step 11](../bootstrap/11-auth-client-path.md)).
|
|
45
|
+
4. **Grant the two new entities explicitly.** `admin_messaging_gallery` (preview) and `admin_messaging_gallery_test_send` (test email) are never auto-granted to an admin role. RBAC fails closed for a controller no role maps, and `owner` (`allow_everything`) adds no guards, so until a host grants **both** entities to at least one role, every caller (owner included) gets `403` on the gallery routes. Add both grants to a host role ([RBAC bootstrap](../bootstrap/09-rbac.md)); the dummy app's `messaging_gallery_operator` group in `rails_app/config/rbac_groups.yml` is an example.
|
|
46
|
+
5. **Before enabling one-click unsubscribe headers (set `api_base_url`), scrub `token=` at the edge.** The token is in the query string, so load balancer, CDN and proxy access logs and error trackers (request URLs, breadcrumbs) record it. Configure the scrub there; it is outside this repo. Rails logs already hide `token`.
|
|
47
|
+
6. If hosts sit behind a load balancer, configure `trusted_proxies` so the unsubscribe per-IP limit sees client addresses.
|
|
48
|
+
7. Optional: add `config/ui_tokens.json` (change 5 above), set `config.messaging.compliance`, and register definitions.
|
|
49
|
+
|
|
50
|
+
## Rolling deploy
|
|
51
|
+
|
|
52
|
+
Migrate first, then roll the app. Old nodes ignore the new columns and never write them. New nodes can serve inbox reads for rows written by old nodes (NULL columns mean undefined behavior). During the roll, an unsubscribe link in an email sent by a new node can reach an old node, which has no `/messaging/unsubscribe` route and answers `404`; the link works once the roll finishes. Do not set `api_base_url` until every node runs 0.23.0.
|
|
53
|
+
|
|
54
|
+
## Accepted risks and known gaps
|
|
55
|
+
|
|
56
|
+
- **Unsubscribe replay (O1, accepted).** The token is a signed bearer value valid 90 days and is not single use. A forwarded or old link can turn email off again after a user re-enabled it. The effect is limited to email off for one type, which the user can re-enable. A preference-version binding was considered and not adopted.
|
|
57
|
+
- **"Message gallery" card without a screen.** Callers holding `admin_messaging_gallery` (once a host grants it, see host action 4) see the `messaging_gallery` tool card in the Admin workspace, but the route `/admin/messaging/gallery` does nothing until a host mounts the frontend screen (a later host set). Hide it with a host-side tool override if needed.
|
|
58
|
+
- **Closeout (not in this repo):** the `X-Time-Zone` note in `workspace_pickem_v4/artifacts/COMMANDTOWER_LOCAL_JOIN.md` is added by hand at release closeout.
|
|
59
|
+
|
|
60
|
+
## Not in this release
|
|
61
|
+
|
|
62
|
+
- No change to `announcement_produced` auditing.
|
|
63
|
+
- No per-type pause, add-to-calendar, device identity, or support re-render.
|
|
64
|
+
- No change to authentication, sessions or CSRF.
|
data/docs/upgrades/README.md
CHANGED
|
@@ -4,6 +4,7 @@ Host-facing upgrade / change summaries for CommandTower releases.
|
|
|
4
4
|
|
|
5
5
|
| Version | Summary |
|
|
6
6
|
|---------|---------|
|
|
7
|
+
| [0.23.0](0.23.0.md) | Message definitions: `MessageDefinition` / `AnnouncementDefinition`, composer-built email with compliance footer and one-click unsubscribe, shared email token file, first-view inbox audit, `X-Time-Zone` writer, admin message gallery and test send; `no-store` on inbox reads; one additive migration |
|
|
7
8
|
| [0.22.0](0.22.0.md) | Server-driven UI document library (`CommandTower::UI`), legacy mapping, email renderer; `X-UI-Catalog` header read into `Current.ui_catalog` (no behavior change) |
|
|
8
9
|
| [0.21.0](0.21.0.md) | Notification preference reads: channel catalog, destinations, settings rows; PATCH merges onto stored member state |
|
|
9
10
|
| [0.20.0](0.20.0.md) | Push delivery certainty: JSON `provider_metadata` caster; duplicate-averse push recovery and Expo submission guards |
|
|
@@ -91,6 +91,14 @@ entities:
|
|
|
91
91
|
- name: admin_messaging_announcements
|
|
92
92
|
controller: CommandTower::Admin::Messaging::AnnouncementsController
|
|
93
93
|
only: create
|
|
94
|
+
- name: admin_messaging_gallery
|
|
95
|
+
controller: CommandTower::Admin::Messaging::GalleryController
|
|
96
|
+
only:
|
|
97
|
+
- index
|
|
98
|
+
- show
|
|
99
|
+
- name: admin_messaging_gallery_test_send
|
|
100
|
+
controller: CommandTower::Admin::Messaging::GalleryTestSendsController
|
|
101
|
+
only: create
|
|
94
102
|
- name: admin_audit_events
|
|
95
103
|
controller: CommandTower::Admin::Audit::EventsController
|
|
96
104
|
only:
|