@stevenkellner/team-conduct-api 1.0.32 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/src/Firestore.d.ts +12 -3
  2. package/lib/src/Firestore.js +17 -8
  3. package/lib/src/FirestoreScheme.d.ts +3 -3
  4. package/lib/src/firebaseFunctionsContext.d.ts +6 -5
  5. package/lib/src/firebaseFunctionsContext.js +5 -4
  6. package/lib/src/functions/index.d.ts +4 -3
  7. package/lib/src/functions/index.js +4 -3
  8. package/lib/src/functions/invitation/getInvitation.d.ts +50 -0
  9. package/lib/src/functions/invitation/getInvitation.js +96 -0
  10. package/lib/src/functions/invitation/invite.d.ts +7 -0
  11. package/lib/src/functions/invitation/invite.js +25 -0
  12. package/lib/src/functions/invitation/register.d.ts +19 -0
  13. package/lib/src/functions/{userInvitation → invitation}/register.js +26 -19
  14. package/lib/src/functions/invitation/withdraw.d.ts +8 -0
  15. package/lib/src/functions/{userInvitation → invitation}/withdraw.js +6 -6
  16. package/lib/src/types/Invitation.d.ts +25 -0
  17. package/lib/src/types/Invitation.js +46 -0
  18. package/lib/src/types/index.d.ts +1 -1
  19. package/lib/src/types/index.js +1 -1
  20. package/lib/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +4 -4
  22. package/src/Firestore.ts +22 -10
  23. package/src/FirestoreScheme.ts +3 -3
  24. package/src/firebaseFunctionsContext.ts +6 -5
  25. package/src/functions/index.ts +4 -3
  26. package/src/functions/invitation/getInvitation.ts +140 -0
  27. package/src/functions/invitation/invite.ts +32 -0
  28. package/src/functions/invitation/register.ts +69 -0
  29. package/src/functions/{userInvitation → invitation}/withdraw.ts +6 -6
  30. package/src/types/Invitation.ts +60 -0
  31. package/src/types/index.ts +1 -1
  32. package/lib/src/functions/userInvitation/invite.d.ts +0 -7
  33. package/lib/src/functions/userInvitation/invite.js +0 -23
  34. package/lib/src/functions/userInvitation/register.d.ts +0 -7
  35. package/lib/src/functions/userInvitation/withdraw.d.ts +0 -8
  36. package/lib/src/types/UserInvitation.d.ts +0 -25
  37. package/lib/src/types/UserInvitation.js +0 -42
  38. package/src/functions/userInvitation/invite.ts +0 -28
  39. package/src/functions/userInvitation/register.ts +0 -54
  40. package/src/types/UserInvitation.ts +0 -56
@@ -1,54 +0,0 @@
1
- import { FirebaseFunction, FunctionsError } from '@stevenkellner/firebase-function';
2
- import { UserInvitation, Person, PersonSignInProperties, Team, User } from '../../types';
3
- import { Firestore } from '../../Firestore';
4
- import { UtcDate } from '@stevenkellner/typescript-common-functionality';
5
-
6
- export class UserInvitationRegisterFunction extends FirebaseFunction<UserInvitation.Id, User> {
7
-
8
- public parametersBuilder = UserInvitation.Id.builder;
9
-
10
- public returnTypeBuilder = User.builder;
11
-
12
- public async execute(invitationId: UserInvitation.Id): Promise<User> {
13
-
14
- if (this.userId === null)
15
- throw new FunctionsError('unauthenticated', 'User not authenticated');
16
- const userId = User.Id.builder.build(this.userId);
17
-
18
- const invitationSnapshot = await Firestore.shared.userInvitation(invitationId).snapshot();
19
- if (!invitationSnapshot.exists)
20
- throw new FunctionsError('not-found', 'Invitation not found');
21
- const invitation = UserInvitation.builder.build(invitationSnapshot.data);
22
-
23
- const userSnapshot = await Firestore.shared.user(userId).snapshot();
24
- let user = new User(userId);
25
- if (userSnapshot.exists)
26
- user = User.builder.build(userSnapshot.data);
27
-
28
- if (user.teams.has(invitation.teamId))
29
- throw new FunctionsError('already-exists', 'User already in team');
30
-
31
- const teamSnapshot = await Firestore.shared.team(invitation.teamId).snapshot();
32
- if (!teamSnapshot.exists)
33
- throw new FunctionsError('not-found', 'Team not found');
34
- const team = Team.builder.build(teamSnapshot.data);
35
-
36
- const personSnapshot = await Firestore.shared.person(invitation.teamId, invitation.personId).snapshot();
37
- if (!personSnapshot.exists)
38
- throw new FunctionsError('not-found', 'Person not found');
39
- const person = Person.builder.build(personSnapshot.data);
40
-
41
- if (person.signInProperties !== null)
42
- throw new FunctionsError('already-exists', 'Person already registered');
43
-
44
- await Firestore.shared.userInvitation(invitationId).remove();
45
-
46
- user.teams.set(invitation.teamId, new User.TeamProperties(team.name, invitation.personId));
47
- await Firestore.shared.user(userId).set(user);
48
-
49
- person.signInProperties = new PersonSignInProperties(userId, UtcDate.now);
50
- await Firestore.shared.person(invitation.teamId, invitation.personId).set(person);
51
-
52
- return user;
53
- }
54
- }
@@ -1,56 +0,0 @@
1
- import { BytesCoder, Flattable, ITypeBuilder, Sha512, Tagged, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
- import { Team } from './Team';
3
- import { Person } from './Person';
4
-
5
- export class UserInvitation implements Flattable<UserInvitation.Flatten> {
6
-
7
- constructor(
8
- public teamId: Team.Id,
9
- public personId: Person.Id
10
- ) {}
11
-
12
- public createId(): UserInvitation.Id {
13
- const hasher = new Sha512();
14
- const teamIdBytes = BytesCoder.fromUtf8(this.teamId.guidString);
15
- const personIdBytes = BytesCoder.fromUtf8(this.personId.guidString);
16
- const hashedInvitationBytes = hasher.hash(new Uint8Array([...teamIdBytes, ...personIdBytes]));
17
- const rawId = BytesCoder.toHex(hashedInvitationBytes).slice(0, 12);
18
- return new Tagged(rawId, 'userInvitation');
19
- }
20
-
21
- public get flatten(): UserInvitation.Flatten {
22
- return {
23
- teamId: this.teamId.flatten,
24
- personId: this.personId.flatten
25
- };
26
- }
27
- }
28
-
29
- export namespace UserInvitation {
30
-
31
- export type Id = Tagged<string, 'userInvitation'>;
32
-
33
- export namespace Id {
34
-
35
- export type Flatten = string;
36
-
37
- export const builder = Tagged.builder('userInvitation' as const, new ValueTypeBuilder<string>());
38
- }
39
-
40
- export type Flatten = {
41
- teamId: Team.Id.Flatten,
42
- personId: Person.Id.Flatten
43
- };
44
-
45
- export class TypeBuilder implements ITypeBuilder<Flatten, UserInvitation> {
46
-
47
- public build(value: Flatten): UserInvitation {
48
- return new UserInvitation(
49
- Team.Id.builder.build(value.teamId),
50
- Person.Id.builder.build(value.personId)
51
- );
52
- }
53
- }
54
-
55
- export const builder = new TypeBuilder();
56
- }