@stevenkellner/team-conduct-api 1.0.36 → 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 +40 -43
  26. package/lib/src/functions/invitation/getInvitation.js +57 -88
  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 +81 -118
  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
@@ -2,27 +2,56 @@ import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functi
2
2
  import { MoneyAmount } from './MoneyAmount';
3
3
  import { Configuration } from './Configuration';
4
4
  import { Localization } from './Localization';
5
+ import { Locale } from './Locale';
5
6
 
7
+ /**
8
+ * Represents the amount of a fine, either as a monetary value or as items.
9
+ *
10
+ * Can be either FineAmount.Money (e.g., $10) or FineAmount.Item (e.g., 2 crates of beer).
11
+ */
6
12
  export type FineAmount =
7
13
  | FineAmount.Money
8
14
  | FineAmount.Item;
9
15
 
10
16
  export namespace FineAmount {
11
17
 
18
+ /**
19
+ * Represents a fine amount as a monetary value.
20
+ */
12
21
  export class Money implements Flattable<Money.Flatten> {
13
22
 
23
+ /**
24
+ * Creates a new Money fine amount.
25
+ *
26
+ * @param amount - The monetary amount
27
+ */
14
28
  public constructor(
15
29
  public amount: MoneyAmount
16
30
  ) {}
17
31
 
32
+ /**
33
+ * Returns a formatted string representation of the amount.
34
+ *
35
+ * @param configuration - Configuration containing currency and locale
36
+ * @returns Formatted currency string (e.g., "$10.50")
37
+ */
18
38
  public formatted(configuration: Configuration): string {
19
39
  return this.amount.formatted(configuration.currency, configuration);
20
40
  }
21
41
 
42
+ /**
43
+ * Returns a new Money instance with the amount multiplied by a factor.
44
+ *
45
+ * @param factor - The multiplication factor
46
+ * @returns New Money instance with multiplied amount
47
+ */
22
48
  public multiplied(factor: number): Money {
23
49
  return new Money(this.amount.multiplied(factor));
24
50
  }
25
51
 
52
+ /**
53
+ * Returns the flattened representation for serialization.
54
+ */
26
55
  public get flatten(): Money.Flatten {
27
56
  return {
28
57
  type: 'money',
@@ -33,40 +62,94 @@ export namespace FineAmount {
33
62
 
34
63
  export namespace Money {
35
64
 
65
+ /**
66
+ * Flattened representation of Money for serialization.
67
+ */
36
68
  export type Flatten = {
37
69
  type: 'money',
38
70
  amount: MoneyAmount.Flatten
39
71
  }
40
72
 
73
+ /**
74
+ * Type builder for Money serialization/deserialization.
75
+ */
41
76
  export class TypeBuilder implements ITypeBuilder<Flatten, Money> {
42
77
 
78
+ /**
79
+ * Builds a Money instance from flattened data.
80
+ *
81
+ * @param value - Flattened money data
82
+ * @returns Money instance
83
+ */
43
84
  public build(value: Flatten): Money {
44
85
  return new Money(MoneyAmount.builder.build(value.amount));
45
86
  }
46
87
  }
47
88
 
89
+ /**
90
+ * Singleton instance of TypeBuilder for Money.
91
+ */
48
92
  export const builder = new TypeBuilder();
49
93
  }
50
94
 
95
+ /**
96
+ * Represents a fine amount as a quantity of items.
97
+ */
51
98
  export class Item implements Flattable<Item.Flatten> {
52
99
 
100
+ /**
101
+ * Creates a new Item fine amount.
102
+ *
103
+ * @param item - The item type (e.g., 'crateOfBeer')
104
+ * @param count - The number of items
105
+ */
53
106
  public constructor(
54
107
  public item: Item.Type,
55
108
  public count: number
56
109
  ) {}
57
110
 
58
- public formatted(): string {
59
- return Localization.shared.fineAmount.item.type[this.item].withCount.value(this.count);
111
+ /**
112
+ * Returns a formatted string representation including count.
113
+ *
114
+ * @param locale - The locale for formatting
115
+ * @returns Formatted string (e.g., "2 crates of beer")
116
+ */
117
+ public formatted(locale: Locale): string;
118
+ /**
119
+ * Returns a formatted string representation including count.
120
+ *
121
+ * @param configuration - Configuration containing locale
122
+ * @returns Formatted string (e.g., "2 crates of beer")
123
+ */
124
+ public formatted(configuration: Configuration): string;
125
+ public formatted(configurationOrLocale: Configuration | Locale): string {
126
+ const locale = configurationOrLocale instanceof Configuration ? configurationOrLocale.locale : configurationOrLocale;
127
+ return Localization.shared(locale).fineAmount.item.type[this.item].withCount.value(this.count);
60
128
  }
61
129
 
62
- public formattedWithoutCount(): string {
63
- return Localization.shared.fineAmount.item.type[this.item].withoutCount.value(this.count);
130
+ /**
131
+ * Returns a formatted string representation without explicitly showing count.
132
+ *
133
+ * @param locale - The locale for formatting
134
+ * @returns Formatted string without count display
135
+ */
136
+ public formattedWithoutCount(locale: Locale): string {
137
+ return Localization.shared(locale).fineAmount.item.type[this.item].withoutCount.value(this.count);
64
138
  }
65
139
 
140
+ /**
141
+ * Returns a new Item instance with the count multiplied by a factor.
142
+ *
143
+ * @param factor - The multiplication factor
144
+ * @returns New Item instance with multiplied count
145
+ */
66
146
  public multiplied(factor: number): Item {
67
147
  return new Item(this.item, this.count * factor);
68
148
  }
69
149
 
150
+ /**
151
+ * Returns the flattened representation for serialization.
152
+ */
70
153
  public get flatten(): Item.Flatten {
71
154
  return {
72
155
  type: 'item',
@@ -78,43 +161,94 @@ export namespace FineAmount {
78
161
 
79
162
  export namespace Item {
80
163
 
81
- export type Type =
82
- | 'crateOfBeer';
164
+ const itemTypes = ['crateOfBeer'] as const;
83
165
 
84
- export namespace Type {
166
+ /**
167
+ * Item type: currently only 'crateOfBeer'.
168
+ */
169
+ export type Type = typeof itemTypes[number];
85
170
 
86
- export const all: Type[] = ['crateOfBeer'];
171
+ export namespace Type {
87
172
 
88
- export function formatted(type: Type): string {
89
- return Localization.shared.fineAmount.item.type[type].name.value();
173
+ /**
174
+ * Array containing all possible item types.
175
+ */
176
+ export const all: readonly Type[] = itemTypes;
177
+
178
+ /**
179
+ * Returns the localized name for an item type.
180
+ *
181
+ * @param type - The item type
182
+ * @param locale - The locale to use for formatting
183
+ * @returns Localized item name
184
+ */
185
+ export function formatted(type: Type, locale: Locale): string {
186
+ return Localization.shared(locale).fineAmount.item.type[type].name.value();
90
187
  }
91
188
  }
92
189
 
190
+ /**
191
+ * Flattened representation of Item for serialization.
192
+ */
93
193
  export type Flatten = {
94
194
  type: 'item',
95
195
  item: Item.Type,
96
196
  count: number
97
197
  }
98
198
 
199
+ /**
200
+ * Type builder for Item serialization/deserialization.
201
+ */
99
202
  export class TypeBuilder implements ITypeBuilder<Flatten, Item> {
100
203
 
204
+ /**
205
+ * Builds an Item instance from flattened data.
206
+ *
207
+ * @param value - Flattened item data
208
+ * @returns Item instance
209
+ */
101
210
  public build(value: Flatten): Item {
102
211
  return new Item(value.item, value.count);
103
212
  }
104
213
  }
105
214
 
215
+ /**
216
+ * Singleton instance of TypeBuilder for Item.
217
+ */
106
218
  export const builder = new TypeBuilder();
107
219
  }
108
220
 
109
-
221
+ /**
222
+ * Creates a Money fine amount.
223
+ *
224
+ * @param MoneyAmount - The monetary amount
225
+ * @returns Money instance
226
+ */
110
227
  export function money(MoneyAmount: MoneyAmount): Money {
111
228
  return new Money(MoneyAmount);
112
229
  }
113
230
 
231
+ /**
232
+ * Creates an Item fine amount.
233
+ *
234
+ * @param item - The item type
235
+ * @param count - The number of items
236
+ * @returns Item instance
237
+ */
114
238
  export function item(item: Item.Type, count: number): Item {
115
239
  return new Item(item, count);
116
240
  }
117
241
 
242
+ /**
243
+ * Compares two fine amounts and returns their relative ordering.
244
+ *
245
+ * Money amounts are considered greater than Item amounts.
246
+ * Within the same type, values are compared numerically.
247
+ *
248
+ * @param lhs - First fine amount to compare
249
+ * @param rhs - Second fine amount to compare
250
+ * @returns 'less' if lhs < rhs, 'equal' if lhs === rhs, 'greater' if lhs > rhs
251
+ */
118
252
  export function compare(lhs: FineAmount, rhs: FineAmount): 'less' | 'equal' | 'greater' {
119
253
  if (lhs instanceof Money) {
120
254
  if (!(rhs instanceof Money))
@@ -134,10 +268,24 @@ export namespace FineAmount {
134
268
  return 'equal';
135
269
  }
136
270
 
271
+ /**
272
+ * Flattened representation of FineAmount (union of Money.Flatten and Item.Flatten).
273
+ */
137
274
  export type Flatten = Money.Flatten | Item.Flatten;
138
275
 
276
+ /**
277
+ * Type builder for FineAmount serialization/deserialization.
278
+ */
139
279
  export class TypeBuilder implements ITypeBuilder<Flatten, FineAmount> {
140
280
 
281
+ /**
282
+ * Builds a FineAmount instance from flattened data.
283
+ *
284
+ * Determines the type based on the 'type' discriminator field.
285
+ *
286
+ * @param value - Flattened fine amount data
287
+ * @returns FineAmount instance (Money or Item)
288
+ */
141
289
  public build(value: Flatten): FineAmount {
142
290
  switch (value.type) {
143
291
  case 'money':
@@ -148,5 +296,8 @@ export namespace FineAmount {
148
296
  }
149
297
  }
150
298
 
299
+ /**
300
+ * Singleton instance of TypeBuilder for FineAmount.
301
+ */
151
302
  export const builder = new TypeBuilder();
152
303
  }
@@ -2,8 +2,22 @@ import { Flattable, Guid, ITypeBuilder, Tagged } from '@stevenkellner/typescript
2
2
  import { FineAmount } from './FineAmount';
3
3
  import { FineTemplateRepetition } from './FineTemplateRepetition';
4
4
 
5
+ /**
6
+ * Represents a template for creating fines with predefined reason, amount, and optional repetition rules.
7
+ *
8
+ * Fine templates allow teams to quickly create recurring or standard fines without entering
9
+ * the same information repeatedly.
10
+ */
5
11
  export class FineTemplate implements Flattable<FineTemplate.Flatten> {
6
12
 
13
+ /**
14
+ * Creates a new FineTemplate instance.
15
+ *
16
+ * @param id - Unique identifier for the fine template (GUID)
17
+ * @param reason - The reason or description for the fine
18
+ * @param amount - The monetary or item-based amount of the fine
19
+ * @param repetition - Optional repetition rules (null for non-recurring templates)
20
+ */
7
21
  public constructor(
8
22
  public id: FineTemplate.Id,
9
23
  public reason: string,
@@ -11,6 +25,9 @@ export class FineTemplate implements Flattable<FineTemplate.Flatten> {
11
25
  public repetition: FineTemplateRepetition | null
12
26
  ) {}
13
27
 
28
+ /**
29
+ * Returns the flattened representation for serialization.
30
+ */
14
31
  public get flatten(): FineTemplate.Flatten {
15
32
  return {
16
33
  id: this.id.flatten,
@@ -23,15 +40,27 @@ export class FineTemplate implements Flattable<FineTemplate.Flatten> {
23
40
 
24
41
  export namespace FineTemplate {
25
42
 
43
+ /**
44
+ * Tagged GUID type for fine template identifiers.
45
+ */
26
46
  export type Id = Tagged<Guid, 'fineTemplate'>;
27
47
 
28
48
  export namespace Id {
29
49
 
50
+ /**
51
+ * Flattened representation of a fine template ID (GUID string).
52
+ */
30
53
  export type Flatten = string;
31
54
 
55
+ /**
56
+ * Type builder for FineTemplate.Id serialization/deserialization.
57
+ */
32
58
  export const builder = Tagged.builder('fineTemplate' as const, Guid.builder);
33
59
  }
34
60
 
61
+ /**
62
+ * Flattened representation of a FineTemplate for serialization.
63
+ */
35
64
  export type Flatten = {
36
65
  id: Id.Flatten,
37
66
  reason: string,
@@ -39,8 +68,17 @@ export namespace FineTemplate {
39
68
  repetition: FineTemplateRepetition.Flatten | null
40
69
  };
41
70
 
71
+ /**
72
+ * Type builder for FineTemplate serialization/deserialization.
73
+ */
42
74
  export class TypeBuilder implements ITypeBuilder<Flatten, FineTemplate> {
43
75
 
76
+ /**
77
+ * Builds a FineTemplate instance from flattened data.
78
+ *
79
+ * @param value - Flattened fine template data
80
+ * @returns FineTemplate instance
81
+ */
44
82
  public build(value: Flatten): FineTemplate {
45
83
  return new FineTemplate(
46
84
  Id.builder.build(value.id),
@@ -51,5 +89,8 @@ export namespace FineTemplate {
51
89
  }
52
90
  }
53
91
 
92
+ /**
93
+ * Singleton instance of TypeBuilder for FineTemplate.
94
+ */
54
95
  export const builder = new TypeBuilder();
55
96
  }
@@ -1,21 +1,50 @@
1
1
  import { Flattable, ITypeBuilder, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
2
  import { Localization } from './Localization';
3
+ import { Locale } from './Locale';
3
4
 
5
+ /**
6
+ * Represents how a fine template repeats over time.
7
+ *
8
+ * Defines the repetition unit (minute, day, item, count) and optional maximum count for repetitions.
9
+ */
4
10
  export class FineTemplateRepetition implements Flattable<FineTemplateRepetition.Flatten> {
5
11
 
12
+ /**
13
+ * Creates a new FineTemplateRepetition instance.
14
+ *
15
+ * @param item - The repetition unit type (minute, day, item, count)
16
+ * @param maxCount - Optional maximum number of repetitions (null for unlimited)
17
+ */
6
18
  public constructor(
7
19
  public item: FineTemplateRepetition.Item,
8
20
  public maxCount: number | null
9
21
  ) {}
10
22
 
11
- public formatted(count: number): string {
12
- return Localization.shared.fineTemplateRepetition.item[this.item].withCount.value(count);
23
+ /**
24
+ * Returns a localized formatted string including the count value.
25
+ *
26
+ * @param count - The number of repetitions
27
+ * @param locale - The locale to use for formatting
28
+ * @returns Formatted string (e.g., "every 5 minutes")
29
+ */
30
+ public formatted(count: number, locale: Locale): string {
31
+ return Localization.shared(locale).fineTemplateRepetition.item[this.item].withCount.value(count);
13
32
  }
14
33
 
15
- public formattedWithoutCount(count: number): string {
16
- return Localization.shared.fineTemplateRepetition.item[this.item].withoutCount.value(count);
34
+ /**
35
+ * Returns a localized formatted string without explicitly showing the count.
36
+ *
37
+ * @param count - The number of repetitions
38
+ * @param locale - The locale to use for formatting
39
+ * @returns Formatted string without count display
40
+ */
41
+ public formattedWithoutCount(count: number, locale: Locale): string {
42
+ return Localization.shared(locale).fineTemplateRepetition.item[this.item].withoutCount.value(count);
17
43
  }
18
44
 
45
+ /**
46
+ * Returns the flattened representation for serialization.
47
+ */
19
48
  public get flatten(): FineTemplateRepetition.Flatten {
20
49
  return {
21
50
  item: this.item,
@@ -26,35 +55,61 @@ export class FineTemplateRepetition implements Flattable<FineTemplateRepetition.
26
55
 
27
56
  export namespace FineTemplateRepetition {
28
57
 
29
- export type Item =
30
- | 'minute'
31
- | 'day'
32
- | 'item'
33
- | 'count';
58
+ const repetitionItems = [
59
+ 'minute',
60
+ 'day',
61
+ 'item',
62
+ 'count'
63
+ ] as const;
64
+
65
+ /**
66
+ * Repetition unit type: 'minute', 'day', 'item', or 'count'.
67
+ */
68
+ export type Item = typeof repetitionItems[number];
34
69
 
35
70
  export namespace Item {
36
71
 
37
- export const all: Item[] = [
38
- 'minute',
39
- 'day',
40
- 'item',
41
- 'count'
42
- ];
72
+ /**
73
+ * Array containing all possible repetition item types.
74
+ */
75
+ export const all: readonly Item[] = repetitionItems;
43
76
 
44
- export function formatted(item: Item): string {
45
- return Localization.shared.fineTemplateRepetition.item[item].name.value();
77
+ /**
78
+ * Returns the localized name for a repetition item type.
79
+ *
80
+ * @param item - The repetition item type
81
+ * @param locale - The locale to use for formatting
82
+ * @returns Localized name string
83
+ */
84
+ export function formatted(item: Item, locale: Locale): string {
85
+ return Localization.shared(locale).fineTemplateRepetition.item[item].name.value();
46
86
  }
47
87
 
88
+ /**
89
+ * Type builder for Item serialization/deserialization.
90
+ */
48
91
  export const builder = new ValueTypeBuilder<Item>();
49
92
  }
50
93
 
94
+ /**
95
+ * Flattened representation of FineTemplateRepetition for serialization.
96
+ */
51
97
  export type Flatten = {
52
98
  item: Item,
53
99
  maxCount: number | null
54
100
  }
55
101
 
102
+ /**
103
+ * Type builder for FineTemplateRepetition serialization/deserialization.
104
+ */
56
105
  export class TypeBuilder implements ITypeBuilder<Flatten, FineTemplateRepetition> {
57
106
 
107
+ /**
108
+ * Builds a FineTemplateRepetition instance from flattened data.
109
+ *
110
+ * @param flatten - Flattened repetition data
111
+ * @returns FineTemplateRepetition instance
112
+ */
58
113
  public build(flatten: Flatten): FineTemplateRepetition {
59
114
  return new FineTemplateRepetition(
60
115
  flatten.item,
@@ -63,5 +118,8 @@ export namespace FineTemplateRepetition {
63
118
  }
64
119
  }
65
120
 
121
+ /**
122
+ * Singleton instance of TypeBuilder for FineTemplateRepetition.
123
+ */
66
124
  export const builder = new TypeBuilder();
67
125
  }
@@ -2,13 +2,34 @@ import { BytesCoder, Flattable, ITypeBuilder, OptionalTypeBuilder, Sha512, Tagge
2
2
  import { Team } from './Team';
3
3
  import { Person } from './Person';
4
4
 
5
+ /**
6
+ * Represents an invitation to join a team.
7
+ *
8
+ * An invitation can be team-wide (personId is null) or specific to a person.
9
+ * The invitation ID is generated by hashing the team ID and optional person ID.
10
+ */
5
11
  export class Invitation implements Flattable<Invitation.Flatten> {
6
12
 
13
+ /**
14
+ * Creates a new Invitation instance.
15
+ *
16
+ * @param teamId - The ID of the team for the invitation
17
+ * @param personId - Optional person ID for person-specific invitations (null for team-wide invitations)
18
+ */
7
19
  constructor(
8
20
  public teamId: Team.Id,
9
21
  public personId: Person.Id | null
10
22
  ) {}
11
23
 
24
+ /**
25
+ * Creates a unique invitation ID by hashing the team ID and optional person ID.
26
+ *
27
+ * Uses SHA-512 hashing and takes the first 12 characters of the hex representation.
28
+ * Team-wide invitations (personId null) hash only the team ID.
29
+ * Person-specific invitations hash both team ID and person ID concatenated.
30
+ *
31
+ * @returns Tagged invitation ID string (12 hex characters)
32
+ */
12
33
  public createId(): Invitation.Id {
13
34
  const hasher = new Sha512();
14
35
  const teamIdBytes = BytesCoder.fromUtf8(this.teamId.guidString);
@@ -22,6 +43,9 @@ export class Invitation implements Flattable<Invitation.Flatten> {
22
43
  return new Tagged(rawId, 'invitation');
23
44
  }
24
45
 
46
+ /**
47
+ * Returns the flattened representation for serialization.
48
+ */
25
49
  public get flatten(): Invitation.Flatten {
26
50
  return {
27
51
  teamId: this.teamId.flatten,
@@ -32,22 +56,43 @@ export class Invitation implements Flattable<Invitation.Flatten> {
32
56
 
33
57
  export namespace Invitation {
34
58
 
59
+ /**
60
+ * Tagged string type for invitation identifiers (12 hex characters).
61
+ */
35
62
  export type Id = Tagged<string, 'invitation'>;
36
63
 
37
64
  export namespace Id {
38
65
 
66
+ /**
67
+ * Flattened representation of an invitation ID (string).
68
+ */
39
69
  export type Flatten = string;
40
70
 
71
+ /**
72
+ * Type builder for Invitation.Id serialization/deserialization.
73
+ */
41
74
  export const builder = Tagged.builder('invitation' as const, new ValueTypeBuilder<string>());
42
75
  }
43
76
 
77
+ /**
78
+ * Flattened representation of an Invitation for serialization.
79
+ */
44
80
  export type Flatten = {
45
81
  teamId: Team.Id.Flatten,
46
82
  personId: Person.Id.Flatten | null
47
83
  };
48
84
 
85
+ /**
86
+ * Type builder for Invitation serialization/deserialization.
87
+ */
49
88
  export class TypeBuilder implements ITypeBuilder<Flatten, Invitation> {
50
89
 
90
+ /**
91
+ * Builds an Invitation instance from flattened data.
92
+ *
93
+ * @param value - Flattened invitation data
94
+ * @returns Invitation instance
95
+ */
51
96
  public build(value: Flatten): Invitation {
52
97
  return new Invitation(
53
98
  Team.Id.builder.build(value.teamId),
@@ -56,5 +101,8 @@ export namespace Invitation {
56
101
  }
57
102
  }
58
103
 
104
+ /**
105
+ * Singleton instance of TypeBuilder for Invitation.
106
+ */
59
107
  export const builder = new TypeBuilder();
60
108
  }
@@ -0,0 +1,20 @@
1
+ import { keys, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
+ import { localizations } from './Localization';
3
+
4
+ /**
5
+ * Supported locale types, derived from available localizations.
6
+ */
7
+ export type Locale = keyof typeof localizations;
8
+
9
+ export namespace Locale {
10
+
11
+ /**
12
+ * Array of all available locales.
13
+ */
14
+ export const all: Locale[] = keys(localizations);
15
+
16
+ /**
17
+ * Builder for constructing Locale values.
18
+ */
19
+ export const builder = new ValueTypeBuilder<Locale>();
20
+ }