feature: switch everything to an invite-only model

This commit is contained in:
Andy Burke 2025-10-08 17:38:23 -07:00
parent a3302d2eff
commit 49c7a135d0
10 changed files with 445 additions and 3 deletions

53
models/invites.ts Normal file
View file

@ -0,0 +1,53 @@
import { FSDB_COLLECTION } from '@andyburke/fsdb';
import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
import { by_character, by_lurid } from '@andyburke/fsdb/organizers';
export type INVITE_CODE = {
id: string;
creator_id: string;
code: string;
timestamps: {
created: string;
expires?: string;
cancelled?: string;
};
};
export const INVITE_CODES = new FSDB_COLLECTION<INVITE_CODE>({
name: 'invite_codes',
indexers: {
code: new FSDB_INDEXER_SYMLINKS<INVITE_CODE>({
name: 'code',
field: 'code',
organize: by_character
}),
creator_id: new FSDB_INDEXER_SYMLINKS<INVITE_CODE>({
name: 'creator_id',
field: 'creator_id',
to_many: true,
organize: by_lurid
})
}
});
// TODO: separate out these different validators somewhere?
export function VALIDATE_INVITE_CODE(invite_code: INVITE_CODE) {
const errors: any[] = [];
if (typeof invite_code.id !== 'string' || invite_code.id.length !== 49) {
errors.push({
cause: 'invalid_invite_code_id',
message: 'An invite code must have a lurid id, eg: able-fish-gold-wing-trip-form-seed-cost-rope-wife'
});
}
// TODO: further invite code validation
if (typeof invite_code.code !== 'string' || invite_code.id.length < 3) {
errors.push({
cause: 'invalid_invite_code_code',
message: 'An invite code must have a secret code that is at least 3 characters long.'
});
}
return errors.length ? errors : undefined;
}

36
models/signups.ts Normal file
View file

@ -0,0 +1,36 @@
import { FSDB_COLLECTION } from '@andyburke/fsdb';
import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
import { by_lurid } from '@andyburke/fsdb/organizers';
export type SIGNUP = {
id: string;
invite_code_id: string;
referring_user_id: string;
user_id: string;
timestamps: {
created: string;
};
};
export const SIGNUPS = new FSDB_COLLECTION<SIGNUP>({
name: 'signups',
indexers: {
user_id: new FSDB_INDEXER_SYMLINKS<SIGNUP>({
name: 'user_id',
field: 'user_id',
organize: by_lurid
}),
invite_code_id: new FSDB_INDEXER_SYMLINKS<SIGNUP>({
name: 'invite_code_id',
field: 'invite_code_id',
to_many: true,
organize: by_lurid
}),
referring_user_id: new FSDB_INDEXER_SYMLINKS<SIGNUP>({
name: 'referring_user_id',
field: 'referring_user_id',
to_many: true,
organize: by_lurid
})
}
});