MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createInviteCode

Function createInviteCode

apps/host-selfhost/src/auth/invites.ts:85–107  ·  view source on GitHub ↗
(
  client: Client,
  input: CreateInviteCodeInput,
)

Source from the content-addressed store, hash-verified

83}
84
85export const createInviteCode = async (
86 client: Client,
87 input: CreateInviteCodeInput,
88): Promise<InviteCodeRow> => {
89 const row: InviteCodeRow = {
90 id: randomBytes(16).toString("hex"),
91 code: generateCode(),
92 role: input.role ?? "member",
93 label: input.label ?? null,
94 createdBy: input.createdBy,
95 createdAt: new Date().toISOString(),
96 expiresAt: input.expiresAt ?? null,
97 usedBy: null,
98 usedByEmail: null,
99 usedAt: null,
100 };
101 await client.execute({
102 sql: `INSERT INTO invite_code (id, code, role, label, created_by, created_at, expires_at)
103 VALUES (?, ?, ?, ?, ?, ?, ?)`,
104 args: [row.id, row.code, row.role, row.label, row.createdBy, row.createdAt, row.expiresAt],
105 });
106 return row;
107};
108
109// Newest first; the admin page renders pending + used together.
110export const listInviteCodes = async (client: Client): Promise<readonly InviteCodeRow[]> => {

Callers 1

handlers.tsFile · 0.90

Calls 3

generateCodeFunction · 0.85
toStringMethod · 0.80
executeMethod · 0.65

Tested by

no test coverage detected