Appearance
Styling, export and integration
Licence key validation, offline
One call, and nothing fetched
A licence key is a string. Hand it to the plot and the plot checks it where it is, in the page:
ts
export function activate(plot: Plot, key: string): LicenceStatus {
// Checked here, in the page. No request is made.
// Never throws. A key that does not hold leaves the plot drawing exactly as
// it did, with the mark on, and the plot says why in the console.
return plot.activate(key);
}The key is signed, and the check is of the signature, the dates and the host. No request is made, so it works on a network with no route out, and a page that draws PlotScope does not depend on our servers being up. A key is given to each plot when the plot is made.
Every answer, and none of them stops the plot
What comes back says where the plot stands. Press the keys above to see three of the five answers on this page: no key, a key that holds, and a key that has been altered.
ts
export function describe(licence: LicenceStatus): string {
switch (licence.status) {
case "active":
return licence.expires === 0
? `licensed to ${licence.licensee}`
: `licensed to ${licence.licensee} until ${day(licence.expires)}`;
case "free":
return "no key: the free tier, with the mark on";
case "expired":
return `expired on ${day(licence.expires)}: the mark is back on`;
case "wrongPlatform":
return `this key is for another platform, not ${licence.platform}: the mark is on`;
case "wrongHost":
return `this key is not for ${licence.host}: the mark is on`;
case "invalid":
return `not a key that holds (${licence.problem}): the mark is on`;
}
}free is a plot that was never given a key. expired and wrongHost are keys that are good, at another time or on another site. invalid is anything that is not a key we signed, and says what was wrong with it.
None of them refuses to draw. Whatever the answer, the plot goes on exactly as it was, and everything short of active puts the free tier's mark back in the corner. A dashboard that went blank over a licensing problem would be worse for everyone than a mark.
Asking again
plot.licence() gives the same answer without checking anything, for a page that wants to show its state somewhere. Every answer also carries buildDate, which is when the library the page is running was built, in seconds since 1970.