Your own page for SHADE's links
SHADE mails people links to confirm, cancel or move something: an appointment's confirm link, its cancel and reschedule links, and more as modules use them. By default such a link opens SHADE's own small page on the account API: it says what the link is for, with one button, in the site's theme when the website module is on. You can show links on a page of your own frontend instead, styled like the rest of your application.
How it works
A module says what its links show and do as data, never HTML: a title, a few paragraphs, and while the link can be used one button, after at most one choice (a new time, for example). SHADE checks the link and hands out that data. Its own page and yours render the same answer, so a module's links work on both without changes.
- In the admin, under Settings → Other frontends, give your frontend a Links page: a path such as
/links. From then on SHADE's links land on<your origin>/links?owner=…&purpose=…&token=…(the first frontend by name, when several have a links page). Links already sent keep their address. - On that page, read the link from the address, ask SHADE what it shows, and render it.
- When the person presses the button, send the link back with their choice, and render the answer.
The calls
Both are POST on the account API, with the link in a JSON body. No cookie is needed: the token is the permission.
| Call | Body | Answer |
|---|---|---|
POST /api/v1/account/links/peek | { owner, purpose, token } | What the link shows, without using it |
POST /api/v1/account/links/redeem | { owner, purpose, token, choice? } | Uses the link; what it shows then |
The answer is a LinkView:
interface LinkView {
status: 'open' | 'closed' | 'invalid' // open: it can be used; closed: done, used, cancelled or past; invalid: wrong or expired
language: string // of the words, such as 'nl' or 'en-GB'
title: string
text: string[] // paragraphs
action?: { // only while open
button: string
choose?: { legend: string, options: { value: string, label: string }[] }
}
}
A link that is wrong, expired or no longer known always answers the same invalid view, in the site's language:
nothing says why.
@shadestack/client/links has typed helpers:
import { linkFromAddress, peekLink, redeemLink } from '@shadestack/client/links'
const link = linkFromAddress(location.href)
if (link) {
const view = await peekLink(link) // on your own origin; pass { baseUrl } when the API is elsewhere
render(view)
form.addEventListener('submit', async (event) => {
event.preventDefault()
const choice = new FormData(form).get('choice')?.toString()
render(await redeemLink(link, choice))
})
}
Keep it safe
- Use only on a button. Mail scanners open links: call
peekLinkwhen the page loads andredeemLinkonly when the person presses the button. A link can be used as often as it was made for (usually once). - Keep the token out of other places. Give the page
<meta name="referrer" content="no-referrer">, so the token in its address is not sent to other sites, load no third-party scripts on it, and do not log its address. The helpers send the token in a POST body, never in an address of the API, and without cookies. - Show the words as text. Render
title,textand labels as text, never as HTML. - Calls are rate limited per IP: 30 looks and 10 uses per 10 minutes.
For module authors
A module declares its link purposes in its manifest part links and makes links with issueLink; see
Background work and services.