40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
/**
|
|
* Types and guards the rows of `invites`, which `invite-service.ts` reads to
|
|
* check an invite before sign-up.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { SQLOutputValue } from "node:sqlite";
|
|
|
|
/**
|
|
* Stored by `createInvite`, and read back by `validateInvite` when the invite
|
|
* link is opened or used to sign up.
|
|
*/
|
|
export interface InviteRow {
|
|
/** The random token the invite link carries, which is the primary key. */
|
|
token: string;
|
|
/** Becomes the new user's `invited_by`. */
|
|
inviter_id: string;
|
|
/** Set when an account is created with the invite. */
|
|
used_at: string | null;
|
|
/** Starts the 7-day window in which the invite works. */
|
|
created_at: string;
|
|
[key: string]: SQLOutputValue;
|
|
}
|
|
|
|
/**
|
|
* Checks whether `obj`, a row `validateInvite` selected, is an
|
|
* {@link InviteRow}.
|
|
*/
|
|
export function isInviteRow(
|
|
obj: unknown,
|
|
): obj is InviteRow {
|
|
return !!obj && typeof obj === "object" &&
|
|
"token" in obj && typeof obj.token === "string" &&
|
|
"inviter_id" in obj && typeof obj.inviter_id === "string" &&
|
|
"created_at" in obj && typeof obj.created_at === "string" &&
|
|
"used_at" in obj &&
|
|
(obj.used_at === null || typeof obj.used_at === "string");
|
|
}
|