@stevenkellner/team-conduct-api 1.0.35 → 2.0.1

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 (218) hide show
  1. package/lib/src/firebase/FirebaseConfiguration.d.ts +45 -1
  2. package/lib/src/firebase/FirebaseConfiguration.js +44 -0
  3. package/lib/src/firebase/Firestore.d.ts +196 -0
  4. package/lib/src/firebase/Firestore.js +235 -0
  5. package/lib/src/{FirestoreScheme.d.ts → firebase/FirestoreScheme.d.ts} +15 -1
  6. package/lib/src/firebase/Messaging.d.ts +64 -0
  7. package/lib/src/firebase/checkAuthentication.d.ts +37 -0
  8. package/lib/src/{checkAuthentication.js → firebase/checkAuthentication.js} +26 -1
  9. package/lib/src/firebase/index.d.ts +4 -0
  10. package/lib/src/firebase/index.js +4 -0
  11. package/lib/src/firebase/pushNotification.d.ts +39 -0
  12. package/lib/src/firebase/pushNotification.js +88 -0
  13. package/lib/src/functions/fine/add.d.ts +10 -13
  14. package/lib/src/functions/fine/add.js +3 -30
  15. package/lib/src/functions/fine/delete.d.ts +10 -13
  16. package/lib/src/functions/fine/delete.js +3 -27
  17. package/lib/src/functions/fine/update.d.ts +10 -13
  18. package/lib/src/functions/fine/update.js +3 -28
  19. package/lib/src/functions/fineTemplate/add.d.ts +6 -9
  20. package/lib/src/functions/fineTemplate/add.js +3 -12
  21. package/lib/src/functions/fineTemplate/delete.d.ts +6 -9
  22. package/lib/src/functions/fineTemplate/delete.js +3 -12
  23. package/lib/src/functions/fineTemplate/update.d.ts +6 -9
  24. package/lib/src/functions/fineTemplate/update.js +3 -12
  25. package/lib/src/functions/invitation/getInvitation.d.ts +41 -42
  26. package/lib/src/functions/invitation/getInvitation.js +58 -81
  27. package/lib/src/functions/invitation/invite.d.ts +1 -2
  28. package/lib/src/functions/invitation/invite.js +3 -18
  29. package/lib/src/functions/invitation/register.d.ts +6 -11
  30. package/lib/src/functions/invitation/register.js +3 -39
  31. package/lib/src/functions/invitation/withdraw.d.ts +1 -2
  32. package/lib/src/functions/invitation/withdraw.js +3 -13
  33. package/lib/src/functions/notification/register.d.ts +7 -10
  34. package/lib/src/functions/notification/register.js +3 -15
  35. package/lib/src/functions/notification/subscribe.d.ts +8 -11
  36. package/lib/src/functions/notification/subscribe.js +3 -14
  37. package/lib/src/functions/paypalMe/edit.d.ts +6 -9
  38. package/lib/src/functions/paypalMe/edit.js +3 -14
  39. package/lib/src/functions/person/add.d.ts +7 -10
  40. package/lib/src/functions/person/add.js +3 -12
  41. package/lib/src/functions/person/delete.d.ts +6 -9
  42. package/lib/src/functions/person/delete.js +3 -14
  43. package/lib/src/functions/person/update.d.ts +7 -10
  44. package/lib/src/functions/person/update.js +3 -13
  45. package/lib/src/functions/team/new.d.ts +9 -12
  46. package/lib/src/functions/team/new.js +3 -22
  47. package/lib/src/functions/user/kickout.d.ts +6 -9
  48. package/lib/src/functions/user/kickout.js +3 -25
  49. package/lib/src/functions/user/login.d.ts +1 -2
  50. package/lib/src/functions/user/login.js +3 -13
  51. package/lib/src/functions/user/roleEdit.d.ts +8 -11
  52. package/lib/src/functions/user/roleEdit.js +3 -18
  53. package/lib/src/index.d.ts +0 -5
  54. package/lib/src/index.js +0 -5
  55. package/lib/src/locales/de.d.ts +10 -67
  56. package/lib/src/locales/de.js +8 -0
  57. package/lib/src/locales/en.d.ts +10 -0
  58. package/lib/src/locales/en.js +19 -2
  59. package/lib/src/types/Configuration.d.ts +33 -15
  60. package/lib/src/types/Configuration.js +24 -12
  61. package/lib/src/types/Currency.d.ts +20 -0
  62. package/lib/src/types/Currency.js +19 -0
  63. package/lib/src/types/Fine.d.ts +41 -0
  64. package/lib/src/types/Fine.js +32 -0
  65. package/lib/src/types/FineAmount.d.ts +160 -9
  66. package/lib/src/types/FineAmount.js +128 -7
  67. package/lib/src/types/FineTemplate.d.ts +41 -0
  68. package/lib/src/types/FineTemplate.js +32 -0
  69. package/lib/src/types/FineTemplateRepetition.d.ts +72 -10
  70. package/lib/src/types/FineTemplateRepetition.js +66 -12
  71. package/lib/src/types/Invitation.d.ts +48 -0
  72. package/lib/src/types/Invitation.js +39 -0
  73. package/lib/src/types/Locale.d.ts +16 -0
  74. package/lib/src/types/Locale.js +16 -0
  75. package/lib/src/types/Localization.d.ts +74 -74
  76. package/lib/src/types/Localization.js +80 -41
  77. package/lib/src/types/MoneyAmount.d.ts +67 -1
  78. package/lib/src/types/MoneyAmount.js +62 -0
  79. package/lib/src/types/NotificationProperties.d.ts +70 -9
  80. package/lib/src/types/NotificationProperties.js +49 -5
  81. package/lib/src/types/PayedState.d.ts +25 -9
  82. package/lib/src/types/PayedState.js +17 -27
  83. package/lib/src/types/Person.d.ts +45 -0
  84. package/lib/src/types/Person.js +36 -0
  85. package/lib/src/types/PersonPrivateProperties.d.ts +28 -0
  86. package/lib/src/types/PersonPrivateProperties.js +25 -0
  87. package/lib/src/types/PersonSignInProperties.d.ts +30 -0
  88. package/lib/src/types/PersonSignInProperties.js +27 -0
  89. package/lib/src/types/Pluralization.d.ts +46 -0
  90. package/lib/src/types/Pluralization.js +46 -0
  91. package/lib/src/types/Team.d.ts +38 -0
  92. package/lib/src/types/Team.js +29 -0
  93. package/lib/src/types/User.d.ts +68 -3
  94. package/lib/src/types/User.js +59 -5
  95. package/lib/src/types/UserRole.d.ts +26 -4
  96. package/lib/src/types/UserRole.js +25 -9
  97. package/lib/src/types/index.d.ts +2 -0
  98. package/lib/src/types/index.js +2 -0
  99. package/lib/test/firebase/FirebaseConfiguration.test.js +155 -0
  100. package/lib/test/firebase/Firestore.test.js +46 -0
  101. package/lib/test/firebase/checkAuthentication.test.d.ts +1 -0
  102. package/lib/test/firebase/checkAuthentication.test.js +305 -0
  103. package/lib/test/firebase/firebase-utils.d.ts +32 -0
  104. package/lib/test/firebase/firebase-utils.js +131 -0
  105. package/lib/test/firebase/pushNotification.test.d.ts +1 -0
  106. package/lib/test/firebase/pushNotification.test.js +300 -0
  107. package/lib/test/locales/localization.de.test.d.ts +1 -0
  108. package/lib/test/locales/localization.de.test.js +144 -0
  109. package/lib/test/locales/localization.en.test.d.ts +1 -0
  110. package/lib/test/locales/localization.en.test.js +144 -0
  111. package/lib/test/types/Configuration.test.d.ts +1 -0
  112. package/lib/test/types/Configuration.test.js +84 -0
  113. package/lib/test/types/Currency.test.d.ts +1 -0
  114. package/lib/test/types/Currency.test.js +41 -0
  115. package/lib/test/types/Fine.test.d.ts +1 -0
  116. package/lib/test/types/Fine.test.js +265 -0
  117. package/lib/test/types/FineAmount.test.d.ts +1 -0
  118. package/lib/test/types/FineAmount.test.js +445 -0
  119. package/lib/test/types/FineTemplate.test.d.ts +1 -0
  120. package/lib/test/types/FineTemplate.test.js +271 -0
  121. package/lib/test/types/FineTemplateRepetition.test.d.ts +1 -0
  122. package/lib/test/types/FineTemplateRepetition.test.js +361 -0
  123. package/lib/test/types/Invitation.test.d.ts +1 -0
  124. package/lib/test/types/Invitation.test.js +269 -0
  125. package/lib/test/types/Locale.test.d.ts +1 -0
  126. package/lib/test/types/Locale.test.js +46 -0
  127. package/lib/test/types/Localization.test.d.ts +1 -0
  128. package/lib/test/types/Localization.test.js +241 -0
  129. package/lib/test/types/MoneyAmount.test.d.ts +1 -0
  130. package/lib/test/types/MoneyAmount.test.js +276 -0
  131. package/lib/test/types/NotificationProperties.test.d.ts +1 -0
  132. package/lib/test/types/NotificationProperties.test.js +258 -0
  133. package/lib/test/types/PayedState.test.d.ts +1 -0
  134. package/lib/test/types/PayedState.test.js +105 -0
  135. package/lib/test/types/Person.test.d.ts +1 -0
  136. package/lib/test/types/Person.test.js +266 -0
  137. package/lib/test/types/PersonPrivateProperties.test.d.ts +1 -0
  138. package/lib/test/types/PersonPrivateProperties.test.js +155 -0
  139. package/lib/test/types/PersonSignInProperties.test.d.ts +1 -0
  140. package/lib/test/types/PersonSignInProperties.test.js +208 -0
  141. package/lib/test/types/Pluralization.test.d.ts +1 -0
  142. package/lib/test/types/Pluralization.test.js +206 -0
  143. package/lib/test/types/Team.test.d.ts +1 -0
  144. package/lib/test/types/Team.test.js +145 -0
  145. package/lib/test/types/User.test.d.ts +1 -0
  146. package/lib/test/types/User.test.js +232 -0
  147. package/lib/test/types/UserRole.test.d.ts +1 -0
  148. package/lib/test/types/UserRole.test.js +140 -0
  149. package/lib/tsconfig.tsbuildinfo +1 -1
  150. package/package.json +10 -9
  151. package/src/firebase/FirebaseConfiguration.ts +49 -1
  152. package/src/firebase/Firestore.ts +248 -0
  153. package/src/{FirestoreScheme.ts → firebase/FirestoreScheme.ts} +15 -1
  154. package/src/firebase/Messaging.ts +64 -0
  155. package/src/{checkAuthentication.ts → firebase/checkAuthentication.ts} +39 -1
  156. package/src/firebase/index.ts +5 -0
  157. package/src/firebase/pushNotification.ts +90 -0
  158. package/src/functions/fine/add.ts +10 -48
  159. package/src/functions/fine/delete.ts +9 -43
  160. package/src/functions/fine/update.ts +10 -44
  161. package/src/functions/fineTemplate/add.ts +7 -23
  162. package/src/functions/fineTemplate/delete.ts +7 -23
  163. package/src/functions/fineTemplate/update.ts +7 -24
  164. package/src/functions/index.ts +0 -1
  165. package/src/functions/invitation/getInvitation.ts +83 -109
  166. package/src/functions/invitation/invite.ts +2 -25
  167. package/src/functions/invitation/register.ts +9 -60
  168. package/src/functions/invitation/withdraw.ts +2 -16
  169. package/src/functions/notification/register.ts +7 -26
  170. package/src/functions/notification/subscribe.ts +8 -26
  171. package/src/functions/paypalMe/edit.ts +7 -25
  172. package/src/functions/person/add.ts +8 -24
  173. package/src/functions/person/delete.ts +6 -25
  174. package/src/functions/person/update.ts +8 -25
  175. package/src/functions/team/new.ts +12 -42
  176. package/src/functions/user/kickout.ts +8 -41
  177. package/src/functions/user/login.ts +2 -16
  178. package/src/functions/user/roleEdit.ts +8 -32
  179. package/src/index.ts +0 -5
  180. package/src/locales/de.ts +10 -1
  181. package/src/locales/en.ts +21 -2
  182. package/src/types/Configuration.ts +33 -23
  183. package/src/types/Currency.ts +24 -0
  184. package/src/types/Fine.ts +41 -0
  185. package/src/types/FineAmount.ts +162 -11
  186. package/src/types/FineTemplate.ts +41 -0
  187. package/src/types/FineTemplateRepetition.ts +75 -17
  188. package/src/types/Invitation.ts +48 -0
  189. package/src/types/Locale.ts +20 -0
  190. package/src/types/Localization.ts +96 -41
  191. package/src/types/MoneyAmount.ts +67 -1
  192. package/src/types/NotificationProperties.ts +67 -9
  193. package/src/types/PayedState.ts +25 -30
  194. package/src/types/Person.ts +45 -0
  195. package/src/types/PersonPrivateProperties.ts +28 -1
  196. package/src/types/PersonSignInProperties.ts +30 -0
  197. package/src/types/Pluralization.ts +46 -0
  198. package/src/types/Team.ts +38 -0
  199. package/src/types/User.ts +70 -4
  200. package/src/types/UserRole.ts +32 -16
  201. package/src/types/index.ts +2 -0
  202. package/lib/src/Firestore.d.ts +0 -24
  203. package/lib/src/Firestore.js +0 -62
  204. package/lib/src/checkAuthentication.d.ts +0 -6
  205. package/lib/src/firebaseFunctionsContext.d.ts +0 -39
  206. package/lib/src/firebaseFunctionsContext.js +0 -43
  207. package/lib/src/pushNotification.d.ts +0 -3
  208. package/lib/src/pushNotification.js +0 -35
  209. package/lib/test/localization-utils.d.ts +0 -1
  210. package/lib/test/localization-utils.js +0 -24
  211. package/lib/test/localization.de.test.js +0 -151
  212. package/lib/test/localization.en.test.js +0 -145
  213. package/src/Firestore.ts +0 -75
  214. package/src/firebaseFunctionsContext.ts +0 -48
  215. package/src/pushNotification.ts +0 -37
  216. /package/lib/src/{FirestoreScheme.js → firebase/FirestoreScheme.js} +0 -0
  217. /package/lib/test/{localization.de.test.d.ts → firebase/FirebaseConfiguration.test.d.ts} +0 -0
  218. /package/lib/test/{localization.en.test.d.ts → firebase/Firestore.test.d.ts} +0 -0
@@ -3,8 +3,21 @@ import { NotificationProperties } from './NotificationProperties';
3
3
  import { User } from './User';
4
4
  import { UserRole } from './UserRole';
5
5
 
6
+ /**
7
+ * Represents the sign-in properties for a person in the system.
8
+ *
9
+ * Contains authentication-related information including user ID, sign-in timestamp,
10
+ * notification preferences, and assigned user roles for access control.
11
+ */
6
12
  export class PersonSignInProperties implements Flattable<PersonSignInProperties.Flatten> {
7
13
 
14
+ /**
15
+ * Creates new person sign-in properties.
16
+ * @param userId - The unique identifier of the user associated with this person
17
+ * @param signInDate - The timestamp when the person signed in
18
+ * @param notificationProperties - Optional notification preferences (defaults to new NotificationProperties)
19
+ * @param roles - Optional array of user roles for access control (defaults to empty array)
20
+ */
8
21
  public constructor(
9
22
  public userId: User.Id,
10
23
  public signInDate: UtcDate,
@@ -12,6 +25,9 @@ export class PersonSignInProperties implements Flattable<PersonSignInProperties.
12
25
  public roles: UserRole[] = []
13
26
  ) {}
14
27
 
28
+ /**
29
+ * Gets the flattened representation of these sign-in properties for serialization.
30
+ */
15
31
  public get flatten(): PersonSignInProperties.Flatten {
16
32
  return {
17
33
  userId: this.userId.flatten,
@@ -24,6 +40,9 @@ export class PersonSignInProperties implements Flattable<PersonSignInProperties.
24
40
 
25
41
  export namespace PersonSignInProperties {
26
42
 
43
+ /**
44
+ * Flattened representation of person sign-in properties for serialization.
45
+ */
27
46
  export type Flatten = {
28
47
  userId: User.Id.Flatten
29
48
  signInDate: UtcDate.Flatten,
@@ -31,12 +50,23 @@ export namespace PersonSignInProperties {
31
50
  roles: UserRole[]
32
51
  }
33
52
 
53
+ /**
54
+ * Builder for constructing PersonSignInProperties from flattened data.
55
+ */
34
56
  export class TypeBuilder implements ITypeBuilder<Flatten, PersonSignInProperties> {
35
57
 
58
+ /**
59
+ * Builds a PersonSignInProperties instance from flattened data.
60
+ * @param value - The flattened sign-in properties data
61
+ * @returns A new PersonSignInProperties instance
62
+ */
36
63
  public build(value: Flatten): PersonSignInProperties {
37
64
  return new PersonSignInProperties(User.Id.builder.build(value.userId), UtcDate.builder.build(value.signInDate), NotificationProperties.builder.build(value.notificationProperties), value.roles);
38
65
  }
39
66
  }
40
67
 
68
+ /**
69
+ * Singleton builder instance for PersonSignInProperties.
70
+ */
41
71
  export const builder = new TypeBuilder();
42
72
  }
@@ -1,17 +1,50 @@
1
+ /**
2
+ * Handles pluralization of strings based on count values.
3
+ * Supports different plural forms for various count categories (zero, one, two, few, many, other).
4
+ * This follows the Unicode CLDR plural rules for internationalization.
5
+ */
1
6
  export class Pluralization {
2
7
 
8
+ /**
9
+ * Plural form for count = 0 (optional).
10
+ */
3
11
  private readonly zero: string | null;
4
12
 
13
+ /**
14
+ * Plural form for count = 1 (optional).
15
+ */
5
16
  private readonly one: string | null;
6
17
 
18
+ /**
19
+ * Plural form for count = 2 (optional).
20
+ */
7
21
  private readonly two: string | null;
8
22
 
23
+ /**
24
+ * Plural form for count > 1 and < 5 (optional).
25
+ */
9
26
  private readonly few: string | null;
10
27
 
28
+ /**
29
+ * Plural form for count >= 5 and <= 20 (optional).
30
+ */
11
31
  private readonly many: string | null;
12
32
 
33
+ /**
34
+ * Default plural form used when no other category matches (required).
35
+ */
13
36
  private readonly other: string;
14
37
 
38
+ /**
39
+ * Creates a new Pluralization instance with specified plural forms.
40
+ * @param countLocals - Object containing plural forms for different count categories
41
+ * @param countLocals.zero - Optional form for zero items
42
+ * @param countLocals.one - Optional form for one item
43
+ * @param countLocals.two - Optional form for two items
44
+ * @param countLocals.few - Optional form for a few items (2-4)
45
+ * @param countLocals.many - Optional form for many items (5-20)
46
+ * @param countLocals.other - Required default form for all other counts
47
+ */
15
48
  public constructor(countLocals: {
16
49
  zero?: string,
17
50
  one?: string,
@@ -28,6 +61,19 @@ export class Pluralization {
28
61
  this.other = countLocals.other;
29
62
  }
30
63
 
64
+ /**
65
+ * Returns the appropriate plural form for the given count.
66
+ * Applies the following rules in order:
67
+ * - count = 0: returns 'zero' form if defined
68
+ * - count = 1: returns 'one' form if defined
69
+ * - count = 2: returns 'two' form if defined
70
+ * - 1 < count < 5: returns 'few' form if defined
71
+ * - 5 <= count <= 20: returns 'many' form if defined
72
+ * - Otherwise: returns 'other' form
73
+ *
74
+ * @param count - The number to determine the plural form for
75
+ * @returns The appropriate plural form string for the given count
76
+ */
31
77
  public get(count: number): string {
32
78
  if (count === 0 && this.zero)
33
79
  return this.zero;
package/src/types/Team.ts CHANGED
@@ -1,13 +1,28 @@
1
1
  import { Flattable, Guid, ITypeBuilder, Tagged } from '@stevenkellner/typescript-common-functionality';
2
2
 
3
+ /**
4
+ * Represents a team in the system with its basic information.
5
+ *
6
+ * A team is a group of people who can track fines and payments together.
7
+ * Teams can optionally have a PayPal.Me link for simplified payment collection.
8
+ */
3
9
  export class Team implements Flattable<Team.Flatten> {
4
10
 
11
+ /**
12
+ * Creates a new Team instance.
13
+ * @param id - The unique identifier for this team
14
+ * @param name - The display name of the team
15
+ * @param paypalMeLink - Optional PayPal.Me link for payment collection (null if not set)
16
+ */
5
17
  public constructor(
6
18
  public id: Team.Id,
7
19
  public name: string,
8
20
  public paypalMeLink: string | null
9
21
  ) {}
10
22
 
23
+ /**
24
+ * Gets the flattened representation of this team for serialization.
25
+ */
11
26
  public get flatten(): Team.Flatten {
12
27
  return {
13
28
  id: this.id.flatten,
@@ -19,23 +34,43 @@ export class Team implements Flattable<Team.Flatten> {
19
34
 
20
35
  export namespace Team {
21
36
 
37
+ /**
38
+ * Tagged type for team identifiers to prevent mixing with other GUID types.
39
+ */
22
40
  export type Id = Tagged<Guid, 'team'>;
23
41
 
24
42
  export namespace Id {
25
43
 
44
+ /**
45
+ * Flattened representation of a team ID (plain GUID string).
46
+ */
26
47
  export type Flatten = string;
27
48
 
49
+ /**
50
+ * Builder for constructing Team.Id instances from GUID strings.
51
+ */
28
52
  export const builder = Tagged.builder('team' as const, Guid.builder);
29
53
  }
30
54
 
55
+ /**
56
+ * Flattened representation of a Team for serialization.
57
+ */
31
58
  export type Flatten = {
32
59
  id: Id.Flatten,
33
60
  name: string,
34
61
  paypalMeLink: string | null
35
62
  }
36
63
 
64
+ /**
65
+ * Builder for constructing Team instances from flattened data.
66
+ */
37
67
  export class TypeBuilder implements ITypeBuilder<Flatten, Team> {
38
68
 
69
+ /**
70
+ * Builds a Team instance from flattened data.
71
+ * @param value - The flattened team data
72
+ * @returns A new Team instance
73
+ */
39
74
  public build(value: Flatten): Team {
40
75
  return new Team(
41
76
  Id.builder.build(value.id),
@@ -45,5 +80,8 @@ export namespace Team {
45
80
  }
46
81
  }
47
82
 
83
+ /**
84
+ * Singleton builder instance for Team.
85
+ */
48
86
  export const builder = new TypeBuilder();
49
87
  }
package/src/types/User.ts CHANGED
@@ -2,13 +2,27 @@ import { Dictionary, Flattable, ITypeBuilder, Tagged, ValueTypeBuilder } from '@
2
2
  import { Team } from './Team';
3
3
  import { Person } from './Person';
4
4
 
5
+ /**
6
+ * Represents a user in the system with associated team memberships.
7
+ *
8
+ * A user can be a member of multiple teams, and for each team, they have
9
+ * specific properties (team name and associated person ID).
10
+ */
5
11
  export class User implements Flattable<User.Flatten> {
6
12
 
13
+ /**
14
+ * Creates a new User instance.
15
+ * @param id - The unique identifier for this user
16
+ * @param teams - Dictionary mapping team IDs to team-specific user properties
17
+ */
7
18
  public constructor(
8
19
  public id: User.Id,
9
20
  public teams: Dictionary<Team.Id, User.TeamProperties> = new Dictionary(Team.Id.builder)
10
21
  ) {}
11
22
 
23
+ /**
24
+ * Gets the flattened representation of this user for serialization.
25
+ */
12
26
  public get flatten(): User.Flatten {
13
27
  return {
14
28
  id: this.id.flatten,
@@ -19,25 +33,48 @@ export class User implements Flattable<User.Flatten> {
19
33
 
20
34
  export namespace User {
21
35
 
36
+ /**
37
+ * Tagged type for user identifiers to prevent mixing with other string IDs.
38
+ */
22
39
  export type Id = Tagged<string, 'user'>;
23
40
 
24
41
  export namespace Id {
25
42
 
43
+ /**
44
+ * Flattened representation of a user ID (plain string).
45
+ */
26
46
  export type Flatten = string;
27
47
 
48
+ /**
49
+ * Builder for constructing User.Id instances from strings.
50
+ */
28
51
  export const builder = Tagged.builder('user' as const, new ValueTypeBuilder<string>());
29
52
  }
30
53
 
54
+ /**
55
+ * Properties that are specific to a user's membership in a particular team.
56
+ */
31
57
  export class TeamProperties implements Flattable<TeamProperties.Flatten> {
32
58
 
59
+ /**
60
+ * Creates new team-specific user properties.
61
+ * @param teamId - The ID of the team
62
+ * @param teamName - The display name of the team
63
+ * @param personId - The ID of the person associated with this user in this team
64
+ */
33
65
  public constructor(
34
- public name: string,
66
+ public teamId: Team.Id,
67
+ public teamName: string,
35
68
  public personId: Person.Id
36
69
  ) {}
37
70
 
71
+ /**
72
+ * Gets the flattened representation of these team properties.
73
+ */
38
74
  public get flatten(): TeamProperties.Flatten {
39
75
  return {
40
- name: this.name,
76
+ teamId: this.teamId.flatten,
77
+ teamName: this.teamName,
41
78
  personId: this.personId.flatten
42
79
  };
43
80
  }
@@ -45,32 +82,61 @@ export namespace User {
45
82
 
46
83
  export namespace TeamProperties {
47
84
 
85
+ /**
86
+ * Flattened representation of team properties for serialization.
87
+ */
48
88
  export type Flatten = {
49
- name: string,
89
+ teamId: Team.Id.Flatten,
90
+ teamName: string,
50
91
  personId: Person.Id.Flatten
51
92
  };
52
93
 
94
+ /**
95
+ * Builder for constructing TeamProperties from flattened data.
96
+ */
53
97
  export class TypeBuilder implements ITypeBuilder<Flatten, TeamProperties> {
54
98
 
99
+ /**
100
+ * Builds a TeamProperties instance from flattened data.
101
+ * @param value - The flattened team properties data
102
+ * @returns A new TeamProperties instance
103
+ */
55
104
  public build(value: Flatten): TeamProperties {
56
- return new TeamProperties(value.name, Person.Id.builder.build(value.personId));
105
+ return new TeamProperties(Team.Id.builder.build(value.teamId), value.teamName, Person.Id.builder.build(value.personId));
57
106
  }
58
107
  }
59
108
 
109
+ /**
110
+ * Singleton builder instance for TeamProperties.
111
+ */
60
112
  export const builder = new TypeBuilder();
61
113
  }
62
114
 
115
+ /**
116
+ * Flattened representation of a User for serialization.
117
+ */
63
118
  export type Flatten = {
64
119
  id: Id.Flatten,
65
120
  teams: Dictionary.Flatten<TeamProperties>
66
121
  }
67
122
 
123
+ /**
124
+ * Builder for constructing User instances from flattened data.
125
+ */
68
126
  export class TypeBuilder implements ITypeBuilder<Flatten, User> {
69
127
 
128
+ /**
129
+ * Builds a User instance from flattened data.
130
+ * @param value - The flattened user data
131
+ * @returns A new User instance with all teams reconstructed
132
+ */
70
133
  public build(value: Flatten): User {
71
134
  return new User(Id.builder.build(value.id), Dictionary.builder(Team.Id.builder, User.TeamProperties.builder).build(value.teams));
72
135
  }
73
136
  }
74
137
 
138
+ /**
139
+ * Singleton builder instance for User.
140
+ */
75
141
  export const builder = new TypeBuilder();
76
142
  }
@@ -1,24 +1,37 @@
1
1
  import { ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
2
  import { Localization, localizations } from './Localization';
3
+ import { Locale } from './Locale';
3
4
 
4
- export type UserRole =
5
- | 'person-manager'
6
- | 'fineTemplate-manager'
7
- | 'fine-manager'
8
- | 'fine-can-add'
9
- | 'team-manager';
5
+ /**
6
+ * Array of all available user roles.
7
+ */
8
+ const userRoles = [
9
+ 'person-manager', // Can manage persons, i.e. add/edit/remove persons of the team
10
+ 'fineTemplate-manager', // Can manage fine templates, i.e. add/edit/remove fine templates
11
+ 'fine-manager', // Can manage fines, i.e. add/edit/remove fines
12
+ 'fine-can-add', // Can add fines, but not edit or remove them
13
+ 'team-manager' // Can manage team settings, i.e. invite/remove team members, change team name, etc.
14
+ ] as const;
10
15
 
11
- export namespace UserRole {
16
+ /**
17
+ * Represents user roles in the application.
18
+ * Defines different levels of permissions for team members.
19
+ */
20
+ export type UserRole = typeof userRoles[number];
12
21
 
13
- export const all: UserRole[] = [
14
- 'person-manager',
15
- 'fineTemplate-manager',
16
- 'fine-manager',
17
- 'fine-can-add',
18
- 'team-manager'
19
- ];
22
+ export namespace UserRole {
23
+ /**
24
+ * Array of all available user roles.
25
+ */
26
+ export const all: readonly UserRole[] = userRoles;
20
27
 
21
- export function formatted(role: UserRole): string {
28
+ /**
29
+ * Returns the localized, human-readable name for a user role.
30
+ * @param role - The user role to format
31
+ * @param locale - The locale to use for localization
32
+ * @returns The localized role name
33
+ */
34
+ export function formatted(role: UserRole, locale: Locale): string {
22
35
  const localizationKeyMap: Record<UserRole, keyof (typeof localizations)[keyof typeof localizations]['userRole']> = {
23
36
  'person-manager': 'personManager',
24
37
  'fineTemplate-manager': 'fineTemplateManager',
@@ -26,8 +39,11 @@ export namespace UserRole {
26
39
  'fine-can-add': 'fineCanAdd',
27
40
  'team-manager': 'teamManager'
28
41
  }
29
- return Localization.shared.userRole[localizationKeyMap[role]].value();
42
+ return Localization.shared(locale).userRole[localizationKeyMap[role]].value();
30
43
  }
31
44
 
45
+ /**
46
+ * Builder for constructing UserRole values.
47
+ */
32
48
  export const builder = new ValueTypeBuilder<UserRole>();
33
49
  }
@@ -15,3 +15,5 @@ export * from './Pluralization';
15
15
  export * from './Team';
16
16
  export * from './User';
17
17
  export * from './UserRole';
18
+ export * from './Currency';
19
+ export * from './Locale';
@@ -1,24 +0,0 @@
1
- import { FirestoreCollection, FirestoreDocument } from '@stevenkellner/firebase-function';
2
- import { FirestoreScheme } from './FirestoreScheme';
3
- import { Fine, FineTemplate, Invitation, Person, User, Team } from './types';
4
- export declare class Firestore {
5
- protected base: FirestoreScheme;
6
- protected constructor();
7
- private static sharedInstance;
8
- static get shared(): Firestore;
9
- team(id: Team.Id): FirestoreDocument<Team>;
10
- user(id: User.Id): FirestoreDocument<User>;
11
- invitation(id: Invitation.Id): FirestoreDocument<Invitation>;
12
- persons(teamId: Team.Id): FirestoreCollection<{
13
- [x: string]: FirestoreDocument<Person, never>;
14
- }>;
15
- person(teamId: Team.Id, id: Person.Id): FirestoreDocument<Person>;
16
- fineTemplates(teamId: Team.Id): FirestoreCollection<{
17
- [x: string]: FirestoreDocument<FineTemplate, never>;
18
- }>;
19
- fineTemplate(teamId: Team.Id, id: FineTemplate.Id): FirestoreDocument<FineTemplate>;
20
- fines(teamId: Team.Id): FirestoreCollection<{
21
- [x: string]: FirestoreDocument<Fine, never>;
22
- }>;
23
- fine(teamId: Team.Id, id: Fine.Id): FirestoreDocument<Fine>;
24
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Firestore = void 0;
4
- const firebase_1 = require("./firebase");
5
- class Firestore {
6
- base;
7
- constructor() {
8
- this.base = firebase_1.FirebaseConfiguration.shared.baseFirestoreDocument;
9
- }
10
- static sharedInstance = null;
11
- static get shared() {
12
- if (!Firestore.sharedInstance)
13
- Firestore.sharedInstance = new Firestore();
14
- return Firestore.sharedInstance;
15
- }
16
- team(id) {
17
- return this.base
18
- .collection('teams')
19
- .document(id.guidString);
20
- }
21
- user(id) {
22
- return this.base
23
- .collection('users')
24
- .document(id.value);
25
- }
26
- invitation(id) {
27
- return this.base
28
- .collection('invitations')
29
- .document(id.value);
30
- }
31
- persons(teamId) {
32
- return this.base
33
- .collection('teams')
34
- .document(teamId.guidString)
35
- .collection('persons');
36
- }
37
- person(teamId, id) {
38
- return this.persons(teamId)
39
- .document(id.guidString);
40
- }
41
- fineTemplates(teamId) {
42
- return this.base
43
- .collection('teams')
44
- .document(teamId.guidString)
45
- .collection('fineTemplates');
46
- }
47
- fineTemplate(teamId, id) {
48
- return this.fineTemplates(teamId)
49
- .document(id.guidString);
50
- }
51
- fines(teamId) {
52
- return this.base
53
- .collection('teams')
54
- .document(teamId.guidString)
55
- .collection('fines');
56
- }
57
- fine(teamId, id) {
58
- return this.fines(teamId)
59
- .document(id.guidString);
60
- }
61
- }
62
- exports.Firestore = Firestore;
@@ -1,6 +0,0 @@
1
- import { Team, User, UserRole } from './types';
2
- type ExpectedUserRoles = UserRole | ExpectedUserRoles[] | {
3
- anyOf: ExpectedUserRoles[];
4
- };
5
- export declare function checkAuthentication(rawUserId: string | null, teamId: Team.Id, roles: ExpectedUserRoles): Promise<User.Id>;
6
- export {};
@@ -1,39 +0,0 @@
1
- import { TeamNewFunction, UserKickoutFunction, UserRoleEditFunction, PaypalMeEditFunction, NotificationRegisterFunction, NotificationSubscribeFunction, InvitationGetInvitationFunction, InvitationRegisterFunction, PersonAddFunction, PersonDeleteFunction, PersonUpdateFunction, FineTemplateAddFunction, FineTemplateDeleteFunction, FineTemplateUpdateFunction, FineAddFunction, FineDeleteFunction, FineUpdateFunction } from './functions';
2
- export declare const firebaseFunctionsContext: {
3
- team: {
4
- new: import("@stevenkellner/firebase-function").FirebaseFunctionContext<TeamNewFunction.Parameters, import("./types").User>;
5
- };
6
- user: {
7
- kickout: import("@stevenkellner/firebase-function").FirebaseFunctionContext<UserKickoutFunction.Parameters, void>;
8
- login: import("@stevenkellner/firebase-function").FirebaseFunctionContext<null, import("./types").User>;
9
- roleEdit: import("@stevenkellner/firebase-function").FirebaseFunctionContext<UserRoleEditFunction.Parameters, void>;
10
- };
11
- paypalMe: {
12
- edit: import("@stevenkellner/firebase-function").FirebaseFunctionContext<PaypalMeEditFunction.Parameters, void>;
13
- };
14
- notification: {
15
- register: import("@stevenkellner/firebase-function").FirebaseFunctionContext<NotificationRegisterFunction.Parameters, void>;
16
- subscribe: import("@stevenkellner/firebase-function").FirebaseFunctionContext<NotificationSubscribeFunction.Parameters, void>;
17
- };
18
- invitation: {
19
- invite: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").Invitation, import("./types").Invitation.Id>;
20
- withdraw: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").Invitation, void>;
21
- getInvitation: import("@stevenkellner/firebase-function").FirebaseFunctionContext<import("./types").Invitation.Id, InvitationGetInvitationFunction.ReturnType>;
22
- register: import("@stevenkellner/firebase-function").FirebaseFunctionContext<InvitationRegisterFunction.Parameters, import("./types").User>;
23
- };
24
- person: {
25
- add: import("@stevenkellner/firebase-function").FirebaseFunctionContext<PersonAddFunction.Parameters, void>;
26
- update: import("@stevenkellner/firebase-function").FirebaseFunctionContext<PersonUpdateFunction.Parameters, void>;
27
- delete: import("@stevenkellner/firebase-function").FirebaseFunctionContext<PersonDeleteFunction.Parameters, void>;
28
- };
29
- fineTemplate: {
30
- add: import("@stevenkellner/firebase-function").FirebaseFunctionContext<FineTemplateAddFunction.Parameters, void>;
31
- update: import("@stevenkellner/firebase-function").FirebaseFunctionContext<FineTemplateUpdateFunction.Parameters, void>;
32
- delete: import("@stevenkellner/firebase-function").FirebaseFunctionContext<FineTemplateDeleteFunction.Parameters, void>;
33
- };
34
- fine: {
35
- add: import("@stevenkellner/firebase-function").FirebaseFunctionContext<FineAddFunction.Parameters, void>;
36
- update: import("@stevenkellner/firebase-function").FirebaseFunctionContext<FineUpdateFunction.Parameters, void>;
37
- delete: import("@stevenkellner/firebase-function").FirebaseFunctionContext<FineDeleteFunction.Parameters, void>;
38
- };
39
- };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.firebaseFunctionsContext = void 0;
4
- const firebase_function_1 = require("@stevenkellner/firebase-function");
5
- const functions_1 = require("./functions");
6
- exports.firebaseFunctionsContext = firebase_function_1.FirebaseFunctionsContext.build(builder => ({
7
- team: {
8
- new: builder.function(functions_1.TeamNewFunction)
9
- },
10
- user: {
11
- kickout: builder.function(functions_1.UserKickoutFunction),
12
- login: builder.function(functions_1.UserLoginFunction),
13
- roleEdit: builder.function(functions_1.UserRoleEditFunction)
14
- },
15
- paypalMe: {
16
- edit: builder.function(functions_1.PaypalMeEditFunction)
17
- },
18
- notification: {
19
- register: builder.function(functions_1.NotificationRegisterFunction),
20
- subscribe: builder.function(functions_1.NotificationSubscribeFunction)
21
- },
22
- invitation: {
23
- invite: builder.function(functions_1.InvitationInviteFunction),
24
- withdraw: builder.function(functions_1.InvitationWithdrawFunction),
25
- getInvitation: builder.function(functions_1.InvitationGetInvitationFunction),
26
- register: builder.function(functions_1.InvitationRegisterFunction)
27
- },
28
- person: {
29
- add: builder.function(functions_1.PersonAddFunction),
30
- update: builder.function(functions_1.PersonUpdateFunction),
31
- delete: builder.function(functions_1.PersonDeleteFunction)
32
- },
33
- fineTemplate: {
34
- add: builder.function(functions_1.FineTemplateAddFunction),
35
- update: builder.function(functions_1.FineTemplateUpdateFunction),
36
- delete: builder.function(functions_1.FineTemplateDeleteFunction)
37
- },
38
- fine: {
39
- add: builder.function(functions_1.FineAddFunction),
40
- update: builder.function(functions_1.FineUpdateFunction),
41
- delete: builder.function(functions_1.FineDeleteFunction)
42
- }
43
- }));
@@ -1,3 +0,0 @@
1
- import { NotificationProperties, Person, Team } from './types';
2
- import { Notification } from './firebase';
3
- export declare function pushNotification(teamId: Team.Id, personId: Person.Id, topic: NotificationProperties.Subscription, notification: Notification): Promise<void>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pushNotification = pushNotification;
4
- const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
5
- const Firestore_1 = require("./Firestore");
6
- const types_1 = require("./types");
7
- const firebase_1 = require("./firebase");
8
- function successfulTokens(response, tokens) {
9
- const successfulTokens = response.responses
10
- .map((response, index) => ({
11
- failed: response.error?.code === 'messaging/invalid-registration-token' || response.error?.code === 'messaging/registration-token-not-registered',
12
- token: tokens[index]
13
- }))
14
- .filter(response => !response.failed)
15
- .map(response => response.token);
16
- const tokenDict = new typescript_common_functionality_1.Dictionary(types_1.NotificationProperties.TokenId.builder);
17
- for (const token of successfulTokens)
18
- tokenDict.set(types_1.NotificationProperties.TokenId.create(token), token);
19
- return tokenDict;
20
- }
21
- async function pushNotification(teamId, personId, topic, notification) {
22
- const personSnapshot = await Firestore_1.Firestore.shared.person(teamId, personId).snapshot();
23
- if (!personSnapshot.exists)
24
- return;
25
- const person = types_1.Person.builder.build(personSnapshot.data);
26
- if (person.signInProperties === null || !person.signInProperties.notificationProperties.subscriptions.includes(topic))
27
- return;
28
- const tokens = person.signInProperties.notificationProperties.tokens.values;
29
- const response = await firebase_1.FirebaseConfiguration.shared.messaging.sendEachForMulticast({
30
- tokens: tokens,
31
- notification: notification
32
- });
33
- person.signInProperties.notificationProperties.tokens = successfulTokens(response, tokens);
34
- await Firestore_1.Firestore.shared.person(teamId, personId).set(person);
35
- }
@@ -1 +0,0 @@
1
- export declare function hasSameKeys(record1: Record<string, unknown>, record2: Record<string, unknown>): void;