Activity: notify client and signed requests
activity/client.ts: discovering the notify service, choosing its endpoint path, and sending the signed notification request.

src/activity/client.ts is the only code that talks to the notify service. It has four exported functions and one constant, and it holds no state.

Exports

Export

Behaviour

HOSTED_NOTIFY

https://hyper.media/hm/api/notify. The default deployment, "also used for sites without explicit notify configuration".

normalizeNotifyUrl(input)

Trims, strips trailing slashes, adds https:// when there is no scheme. Empty input gives null. Only https: and http: are allowed (Invalid notification server address.). Migrates retired hosts: notify.seed.hyper.media to HOSTED_NOTIFY, notify-dev.seed.hyper.media to https://dev.hyper.media/hm/api/notify.

notifyEndpoint(base)

"Hosted notify and standalone notify have different endpoint paths." A base whose path ends with /hm/api/notify posts to {base}/notifications; any other base posts to {origin}/hm/api/notifications.

resolveNotifyUrl(server)

GET {server}/hm/api/config, then normalizeNotifyUrl(notifyServiceUrl or notifyServiceHost), else HOSTED_NOTIFY. A failed config fetch throws: discovery does not silently fall back.

notificationRequest(base, signer, now, actions?)

One signed read or write. Returns a validated Snapshot.

The signed request

notificationRequest builds one of two payloads, both with limit: 400:

    read: {action: "get-notification-state", limit: 400}

    write: {action: "apply-notification-actions", actions: [...], limit: 400}

It then calls createNotifyEnvelope(payload, signer, now) from Crypto: signed envelopes. The signer is adapted from the Identity Signer: principal is principalFromEd25519(publicKey) (34 bytes) and sign wraps the key's synchronous sign. The envelope adds signer and time (from now), signs the strict DAG-CBOR encoding of the map without sig, and returns the bytes of the same map with sig added.

The request:

POST {notifyEndpoint(base)} Content-Type: application/cbor redirect: error body: envelope bytes

redirect: "error" carries the comment "Never forward signed identity requests to a redirect's destination." A Bun test starts a redirecting server and asserts that the destination receives nothing.

now is not read here. It is the root contract's time.epochAtZero + performanceNow() stamp, passed through the source. The service rejects times more than 20 seconds from its own clock, which is why the root contract uses a deliberate ask stamp.

Response checks

    The private jsonFetch applies exactTimeout: 15000.

    parseSnapshot validates the whole body.

    accountId, config.accountId and readState.accountId must all equal the signer's account id.

Error messages

Message

Cause

Notification server not responding ({host}).

fetch threw: offline, timeout, or a redirect

The notification server sent an unreadable response.

body is not JSON

the body's error string, else Request failed ({status}).

non-2xx status

The notification server sent an invalid inbox.

parseSnapshot failed

The notification server returned another identity’s inbox.

account id mismatch

Invalid notification server address.

configured URL has another scheme

For a load, these reach the screen through Contract's failure(activityData); for a write, through the reply's error.

Grants

Requests need the net.fetch https: grant, and the local fixture needs net.fetch http://127.0.0.1:4790, both listed in app.ts. See Grants and capabilities.

Tests

In activity.test.ts, the group "notify protocol and identity adapter" has 9 tests: discovery keeps the hosted fallback; signed requests refuse redirects; a missing local identity returns the empty state without fetching; another identity's response is refused; hosted, legacy, standalone and path-mounted services resolve; the signer uses principal bytes and signs the map without sig; the mock rejects stale, tampered and zero-sig bytes; malformed snapshots are failures; service errors keep their message.

Known limits

    limit is fixed at 400 and there is no paging: beforeMs and siteUid, which the envelope type allows, are never sent.

    resolveNotifyUrl does not trim a trailing slash from server and runs on every load and every write (no cache).

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Attributes
name
Activity: notify client and signed requests
summary
activity/client.ts: discovering the notify service, choosing its endpoint path, and sending the signed notification request.