# The account's feed

How a Praecise product's server tells a person, in one place, about things that happened or that wait for them. For products of the family only.

## What it is

One list per Praecise account of things from the Praecise products that the person should know about or act on: a new message in Inbox, a calendar event, a payment or something to approve in Skerry, a deploy or a limit in Cloud. Each item opens the right thing in the right product. It lives at the account service because the account is the one thing every product shares. Rivier shows it; any product may show its own items; the account page may show it later.

It is a list of pointers. The thing itself stays in its product. One gate and one session are untouched: an item's address opens the product, which finds the person's Praecise session as always.

## Who may do what

Every call is server to server, at `https://accounts.praecise.com`, with HTTP Basic: the product's own client id and secret, exactly as for `GET /api/accounts/lookup`. No person's token, no browser call, no new credential.

| Who | May |
|---|---|
| any family product (a publisher) | put, change, finish and withdraw its OWN items for an account; read its own items |
| a reader (named in the account service's setting; first: `rivier`) | read every product's items for an account, and mark an item seen or done |
| the account service itself | publishes its own items as product `accounts` (for example a passkey recovery waiting) |

A reader can read only the feed of an account that has signed in to that reader. An outside application has no credential for any of this.

The product in every address is the caller's client id (`inbox`, `spaces`, `console-cloud`, `console-com`, `skerry-console`, `rivier`, `cultural-layers`, `navigation`, `platform`). One app that serves two products' sites publishes each product's items under that product's own id, when the account service is set to let it (`<NAME>_FEED_AS`): the Inbox app, client `inbox`, publishes Spaces' items (signing, calendar, documents) as `spaces`, with addresses on spaces.praecise.com, and mail's as `inbox`. Each product then has its own name in the reader and its own 200 open items. `{account}` is the Praecise account id (the `sub` of the ID token; the lookup gives it for an address).

## Publish: one item

```http
PUT /api/feed/{account}/items/{product}/{key}
Content-Type: application/json

{
  "kind": "approval",
  "text": { "en": { "title": "Payment of 120.00 USD to Harbour Supplies waits for your approval",
                    "detail": "Asked by the purchasing agent" } },
  "url": "https://business.skerry.xyz/approvals/apr_123",
  "needs_action": true,
  "at": "2026-11-15T18:02:11Z",
  "ends_at": "2026-11-18T00:00:00Z"
}

→ 201 (new) or 200 (replaced) {"item": { ...as read below... }}
```

- `key`: the publisher's own name for the thing, 1 to 120 characters of `A-Z a-z 0-9 . _ : -`. The same key again replaces the item (the text of "3 new messages" becoming "4 new messages"); it does not make a second one. Replacing keeps "seen" only if `text` and `kind` are unchanged, and never brings back an item the person finished unless `"reopen": true` is sent.
- `kind`: one word, lower case, from this list: `message`, `call`, `event`, `reminder`, `invitation`, `share`, `approval`, `signature`, `payment`, `deploy`, `limit`, `security`, `notice`. A kind not in the list is refused (400); ask for a new one and it is added here.
- `text`: by language tag (BCP 47). `en` is compulsory and is the source; any other language the product has may be added beside it, each to the same standard, up to 12 languages. Each has `title` (1 to 140 characters) and optionally `detail` (up to 280). Plain text, no markup, no line breaks. The reader shows the person's language when present, else `en`.
- `url`: the https address that opens the thing. Its host must be one registered for the publishing product at the account service (its base, its return hosts, its public site); anything else is refused (400), so an item can never lead outside the product that published it. No credentials, codes or tokens in it. A product whose items open on a further host (Inbox's on the Spaces site), or with no host of its own, is given those hosts by a setting (`<NAME>_FEED_BASE`), on request.
- `needs_action`: true when the person must do something (approve, pay, answer an invitation, raise a limit), false when it is only for knowing.
- `at`: when it happened; default the time of the call. Not in the future by more than a minute. A PUT whose `at` equals the stored item's `at` is the same event again: it changes nothing and reopens nothing (answer 200 with the item as stored). So a publisher that keeps an event and sends it until it has seen an answer always sends the event's own `at`, and a real change to an item carries a new `at`.
- `ends_at`: optional; when it stops mattering (the event has begun, the approval lapses). After it the item is no longer returned as open.
- Limits: body up to 16 KB; 600 publishes a minute per product (429 with `Retry-After`); 200 open items per account per product, the oldest without action dropped first, then the oldest.
- `404` when the account does not exist. `403` when `{product}` is not the caller.

Finish and withdraw, by the publisher:

```http
POST   /api/feed/{account}/items/{product}/{key}/done      → 200   the thing was handled (approved in the product, read in Inbox)
DELETE /api/feed/{account}/items/{product}/{key}           → 204   it should never have been shown, or is gone
```

A publisher is expected to finish its own items: when the person approves the payment in Skerry, Skerry calls `done`, so the feed never shows something already dealt with.

## Read

```http
GET /api/feed/{account}?state=open&product=inbox&not_product=rivier&limit=50&after=<cursor>

→ 200
{
  "items": [
    { "product": "skerry-console", "key": "apr_123", "kind": "approval",
      "text": { "en": { "title": "...", "detail": "..." } },
      "url": "https://business.skerry.xyz/approvals/apr_123",
      "needs_action": true, "at": "...", "ends_at": "...",
      "seen_at": null, "done_at": null, "updated_at": "..." }
  ],
  "counts": { "open": 7, "needs_action": 2, "unseen": 3 },
  "products": { "skerry-console": "Skerry" },
  "next": "<cursor or null>"
}
```

- `state`: `open` (default: not done, not ended) or `all` (also done and ended, while kept).
- `product`: optional filter. `not_product`: its counterpart, for a reader that already shows one product's things itself (Rivier leaves out `rivier`); both apply to `items` and to `counts`. A publisher that is not a reader gets its own items whatever it asks.
- `products` names each product in the answer as the family names it, by client id, so every reader shows the same name.
- Order: items that need action first, then newest `at` first. `limit` 1 to 100, default 50.
- `counts` are for the whole account as the caller may see it, not for the page.
- `GET /api/feed/{account}/count` answers `{"counts": {...}}` alone, for a badge; it takes `product` and `not_product` too.
- `Cache-Control: no-store`. An `ETag` is given; `If-None-Match` answers 304 when nothing changed, so a reader may ask often and cheaply. Limit: 1200 reads a minute per client.
- There is no push in this version: a reader asks when it shows the list. Say if you need a call to your server when an item arrives; it would be a signed POST like the logout token, added later.

Mark, by a reader on the person's word (or by the publisher for its own):

```http
POST /api/feed/{account}/items/{product}/{key}/seen    → 200   the person has looked at it
POST /api/feed/{account}/items/{product}/{key}/done    → 200   the person dismissed it in the reader
POST /api/feed/{account}/seen                          → 200 {"counts": {...}}   the list was shown
     {"items": [{"product": "inbox", "key": "ap.123"}, ...]}      up to 100; one that is gone is passed over
```

"Done" in the feed does not do the thing in the product: dismissing an approval in Rivier does not approve the payment. To act, the reader opens `url`.

## How long things are kept

- A done item: 7 days, then deleted.
- An item with an `ends_at`: until 7 days after it.
- An item that needs action and has no `ends_at`: until done, at most 90 days.
- Any other item: 30 days after `at`.
- When the account is deleted, its feed goes with it. "Sign out everywhere" does not empty it.

## What is never put in it

- No message bodies, no attachments, no document contents. For a message: who it is from and that it arrived, nothing of what it says. The subject line of a message is content: leave it out.
- The title of a document or of a calendar event may be shown, to an account that already has access to it in the product; nothing of its contents.
- No passwords, one-time codes, links that sign a person in, keys or tokens, in `text` or in `url`.
- No card or bank numbers. An amount and the other party's name are fine where the person needs them to decide.
- Nothing about another person beyond a name the account's owner already sees in the product.
- Nothing for marketing. An item is something that happened or that waits for the person.

The account service checks lengths, the kind, the language tags and the address; it cannot check meaning. Each product is responsible for what it writes.

## Languages

`en` is the source and always present. No language has a rule of its own: any other language is added the same way, by its tag, and is shown when it is the person's. The reader decides the person's language; the account service stores what it is given.

## Errors

`400 {"error": "..."}` says which field. `401` without a valid client credential. `403` for another product's item or a feed the caller may not read. `404` no such account or item. `413` too large. `429` over a limit. `503 {"error": "the feed is not switched on"}` while the setting is off.

## Switching on

Off until `ACCOUNT_FEED=on` at the account service; readers named in `ACCOUNT_FEED_READERS` (first value: `rivier`). A product should treat 503 as "nothing to do" and not retry in a loop.

## Notes for publishers

- The account id for an address comes from `GET /api/accounts/lookup`; keep it. It does not change while the account lives, but an address can come to belong to another account (one deleted, one made), so keep it for a day, not for ever. The lookup's limit is 600 a minute per product from this release (was 120).
- An item for several people (a mailbox with many holders, a project with members) is published once per account, under the same key; the publisher calls `done` for each.
- The caller may be any server of the product that holds its client credential (Skerry's API server with the credential of `skerry-console`).
- Keys of two builds under one client are kept apart by a prefix they agree between them.
