@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
@@ -1,4 +1,15 @@
1
+ import { localizationEN } from '../locales/en';
1
2
  import { Pluralization } from './Pluralization';
3
+ import { Locale } from './Locale';
4
+ /**
5
+ * Type representing the structure of a localization dictionary.
6
+ * Derived from the English localization as the base template.
7
+ */
8
+ export type LocalizationDict = typeof localizationEN;
9
+ /**
10
+ * Record of all available localizations keyed by locale.
11
+ * Each localization must match the structure of LocalizationDict.
12
+ */
2
13
  export declare const localizations: {
3
14
  en: {
4
15
  notification: {
@@ -133,91 +144,80 @@ export declare const localizations: {
133
144
  };
134
145
  };
135
146
  };
147
+ /**
148
+ * Recursive type definition for localization values.
149
+ * Can be nested objects, strings with template variables, or Pluralization instances.
150
+ */
136
151
  export type SubLocalizationType = {
137
152
  [Key in string]: SubLocalizationType;
138
153
  } | string | Pluralization;
154
+ /**
155
+ * Mapped type that transforms SubLocalizationType into corresponding localization classes.
156
+ * - Objects become nested SubLocalization structures
157
+ * - Strings become ValueLocalization instances
158
+ * - Pluralization instances become PluralLocalization instances
159
+ */
139
160
  export type SubLocalization<T extends SubLocalizationType> = T extends {
140
161
  [Key in string]: SubLocalizationType;
141
162
  } ? {
142
163
  [Key in keyof T]: SubLocalization<T[Key]>;
143
164
  } : T extends string ? ValueLocalization : T extends Pluralization ? PluralLocalization : never;
165
+ /**
166
+ * Main localization class that provides access to localized strings.
167
+ * Transforms raw localization data into type-safe localization objects.
168
+ */
169
+ export declare class Localization {
170
+ /**
171
+ * Returns the localization structure for the specified locale.
172
+ * Transforms the raw localization data into ValueLocalization and PluralLocalization instances.
173
+ * @param locale - The locale to retrieve localizations for
174
+ * @returns The complete localization structure with type-safe access
175
+ */
176
+ static shared(locale: Locale): SubLocalization<LocalizationDict>;
177
+ /**
178
+ * Recursively maps raw localization data to localization class instances.
179
+ * @param localization - The raw localization value to transform
180
+ * @returns The transformed localization with proper class instances
181
+ */
182
+ private static mapSubLocalization;
183
+ }
184
+ /**
185
+ * Handles localization strings with template variable substitution.
186
+ * Supports {{variableName}} syntax for runtime value replacement.
187
+ */
144
188
  export declare class ValueLocalization {
145
- private readonly rawValues;
146
- constructor(rawValues: Record<keyof typeof localizations, string>);
189
+ private readonly rawValue;
190
+ /**
191
+ * Creates a new ValueLocalization instance.
192
+ * @param rawValue - The template string with {{variable}} placeholders
193
+ */
194
+ constructor(rawValue: string);
195
+ /**
196
+ * Returns the localized string with variables substituted.
197
+ * Template variables in the format {{key}} are replaced with provided argument values.
198
+ * @param args - Record of variable names to their replacement values
199
+ * @returns The localized string with all variables replaced
200
+ * @throws Error if a required template variable is not provided in args
201
+ */
147
202
  value(args?: Record<string, string>): string;
148
203
  }
204
+ /**
205
+ * Handles pluralized localization strings that vary based on count.
206
+ * Combines Pluralization logic with template variable substitution.
207
+ */
149
208
  export declare class PluralLocalization {
150
- private readonly pluralizations;
151
- constructor(pluralizations: Record<keyof typeof localizations, Pluralization>);
209
+ private readonly pluralization;
210
+ /**
211
+ * Creates a new PluralLocalization instance.
212
+ * @param pluralization - The Pluralization instance containing plural forms
213
+ */
214
+ constructor(pluralization: Pluralization);
215
+ /**
216
+ * Returns the appropriate pluralized string for the given count with variables substituted.
217
+ * Automatically includes 'count' in the template variables.
218
+ * @param count - The count to determine which plural form to use
219
+ * @param args - Additional template variables to substitute (count is added automatically)
220
+ * @returns The localized plural string with all variables replaced
221
+ */
152
222
  value(count: number, args?: Record<string, string>): string;
153
223
  }
154
- export declare class Localization {
155
- static locale: keyof typeof localizations;
156
- static readonly shared: {
157
- notification: {
158
- fine: {
159
- new: {
160
- title: ValueLocalization;
161
- body: ValueLocalization;
162
- };
163
- reminder: {
164
- title: ValueLocalization;
165
- body: ValueLocalization;
166
- };
167
- stateChange: {
168
- title: ValueLocalization;
169
- bodyPayed: ValueLocalization;
170
- bodyUnpayed: ValueLocalization;
171
- bodyDeleted: ValueLocalization;
172
- };
173
- };
174
- };
175
- fineAmount: {
176
- item: {
177
- type: {
178
- crateOfBeer: {
179
- name: ValueLocalization;
180
- withCount: PluralLocalization;
181
- withoutCount: PluralLocalization;
182
- };
183
- };
184
- };
185
- };
186
- fineTemplateRepetition: {
187
- item: {
188
- minute: {
189
- name: ValueLocalization;
190
- withCount: PluralLocalization;
191
- withoutCount: PluralLocalization;
192
- };
193
- day: {
194
- name: ValueLocalization;
195
- withCount: PluralLocalization;
196
- withoutCount: PluralLocalization;
197
- };
198
- item: {
199
- name: ValueLocalization;
200
- withCount: PluralLocalization;
201
- withoutCount: PluralLocalization;
202
- };
203
- count: {
204
- name: ValueLocalization;
205
- withCount: PluralLocalization;
206
- withoutCount: PluralLocalization;
207
- };
208
- };
209
- };
210
- payedState: {
211
- payed: ValueLocalization;
212
- notPayed: ValueLocalization;
213
- };
214
- userRole: {
215
- personManager: ValueLocalization;
216
- fineTemplateManager: ValueLocalization;
217
- fineManager: ValueLocalization;
218
- fineCanAdd: ValueLocalization;
219
- teamManager: ValueLocalization;
220
- };
221
- };
222
- private static getSubLocalization;
223
- }
@@ -1,21 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Localization = exports.PluralLocalization = exports.ValueLocalization = exports.localizations = void 0;
3
+ exports.PluralLocalization = exports.ValueLocalization = exports.Localization = exports.localizations = void 0;
4
4
  const typescript_common_functionality_1 = require("@stevenkellner/typescript-common-functionality");
5
5
  const en_1 = require("../locales/en");
6
6
  const de_1 = require("../locales/de");
7
7
  const Pluralization_1 = require("./Pluralization");
8
- exports.localizations = {
8
+ /**
9
+ * Helper function to ensure a record satisfies the localization structure
10
+ * while preserving its concrete type.
11
+ */
12
+ const satisfiesLocalizationRecord = (value) => value;
13
+ /**
14
+ * Record of all available localizations keyed by locale.
15
+ * Each localization must match the structure of LocalizationDict.
16
+ */
17
+ exports.localizations = satisfiesLocalizationRecord({
9
18
  en: en_1.localizationEN,
10
19
  de: de_1.localizationDE
11
- };
20
+ });
21
+ /**
22
+ * Main localization class that provides access to localized strings.
23
+ * Transforms raw localization data into type-safe localization objects.
24
+ */
25
+ class Localization {
26
+ /**
27
+ * Returns the localization structure for the specified locale.
28
+ * Transforms the raw localization data into ValueLocalization and PluralLocalization instances.
29
+ * @param locale - The locale to retrieve localizations for
30
+ * @returns The complete localization structure with type-safe access
31
+ */
32
+ static shared(locale) {
33
+ return Localization.mapSubLocalization(exports.localizations[locale]);
34
+ }
35
+ /**
36
+ * Recursively maps raw localization data to localization class instances.
37
+ * @param localization - The raw localization value to transform
38
+ * @returns The transformed localization with proper class instances
39
+ */
40
+ static mapSubLocalization(localization) {
41
+ if (typeof localization === 'object' && !(localization instanceof Pluralization_1.Pluralization))
42
+ return (0, typescript_common_functionality_1.mapRecord)(localization, subLocalization => Localization.mapSubLocalization(subLocalization));
43
+ if (typeof localization === 'string')
44
+ return new ValueLocalization(localization);
45
+ if (localization instanceof Pluralization_1.Pluralization)
46
+ return new PluralLocalization(localization);
47
+ throw new Error('Invalid localization structure');
48
+ }
49
+ }
50
+ exports.Localization = Localization;
51
+ /**
52
+ * Handles localization strings with template variable substitution.
53
+ * Supports {{variableName}} syntax for runtime value replacement.
54
+ */
12
55
  class ValueLocalization {
13
- rawValues;
14
- constructor(rawValues) {
15
- this.rawValues = rawValues;
56
+ rawValue;
57
+ /**
58
+ * Creates a new ValueLocalization instance.
59
+ * @param rawValue - The template string with {{variable}} placeholders
60
+ */
61
+ constructor(rawValue) {
62
+ this.rawValue = rawValue;
16
63
  }
64
+ /**
65
+ * Returns the localized string with variables substituted.
66
+ * Template variables in the format {{key}} are replaced with provided argument values.
67
+ * @param args - Record of variable names to their replacement values
68
+ * @returns The localized string with all variables replaced
69
+ * @throws Error if a required template variable is not provided in args
70
+ */
17
71
  value(args = {}) {
18
- let rawValue = this.rawValues[Localization.locale];
72
+ let rawValue = this.rawValue;
19
73
  const regex = /\{\{(?<key>.*?)\}\}/;
20
74
  while (true) {
21
75
  const match = regex.exec(rawValue);
@@ -30,13 +84,28 @@ class ValueLocalization {
30
84
  }
31
85
  }
32
86
  exports.ValueLocalization = ValueLocalization;
87
+ /**
88
+ * Handles pluralized localization strings that vary based on count.
89
+ * Combines Pluralization logic with template variable substitution.
90
+ */
33
91
  class PluralLocalization {
34
- pluralizations;
35
- constructor(pluralizations) {
36
- this.pluralizations = pluralizations;
92
+ pluralization;
93
+ /**
94
+ * Creates a new PluralLocalization instance.
95
+ * @param pluralization - The Pluralization instance containing plural forms
96
+ */
97
+ constructor(pluralization) {
98
+ this.pluralization = pluralization;
37
99
  }
100
+ /**
101
+ * Returns the appropriate pluralized string for the given count with variables substituted.
102
+ * Automatically includes 'count' in the template variables.
103
+ * @param count - The count to determine which plural form to use
104
+ * @param args - Additional template variables to substitute (count is added automatically)
105
+ * @returns The localized plural string with all variables replaced
106
+ */
38
107
  value(count, args = {}) {
39
- const valueLocalization = new ValueLocalization((0, typescript_common_functionality_1.mapRecord)(this.pluralizations, pluralization => pluralization.get(count)));
108
+ const valueLocalization = new ValueLocalization(this.pluralization.get(count));
40
109
  return valueLocalization.value({
41
110
  count: `${count}`,
42
111
  ...args
@@ -44,33 +113,3 @@ class PluralLocalization {
44
113
  }
45
114
  }
46
115
  exports.PluralLocalization = PluralLocalization;
47
- function swap1stAnd2ndLevel(record) {
48
- const swapped = {};
49
- for (const key1 of (0, typescript_common_functionality_1.keys)(record)) {
50
- for (const key2 of (0, typescript_common_functionality_1.keys)(record[key1])) {
51
- if (!(key2 in swapped))
52
- swapped[key2] = {};
53
- swapped[key2][key1] = record[key1][key2];
54
- }
55
- }
56
- return swapped;
57
- }
58
- class Localization {
59
- static locale = 'en';
60
- static shared = Localization.getSubLocalization(exports.localizations);
61
- static getSubLocalization(_localizations) {
62
- const _localizationValue = (0, typescript_common_functionality_1.values)(_localizations);
63
- if (_localizationValue.length === 0)
64
- return {};
65
- if (typeof _localizationValue[0] === 'object' && !(_localizationValue[0] instanceof Pluralization_1.Pluralization)) {
66
- const swapped = swap1stAnd2ndLevel(_localizations);
67
- return (0, typescript_common_functionality_1.mapRecord)(swapped, subLocalization => Localization.getSubLocalization(subLocalization));
68
- }
69
- if (typeof _localizationValue[0] === 'string')
70
- return new ValueLocalization(_localizations);
71
- if (_localizationValue[0] instanceof Pluralization_1.Pluralization)
72
- return new PluralLocalization(_localizations);
73
- throw new Error('Invalid localization structure');
74
- }
75
- }
76
- exports.Localization = Localization;
@@ -1,20 +1,86 @@
1
1
  import { Flattable, ITypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
2
  import { Configuration } from './Configuration';
3
+ import { Currency } from './Currency';
4
+ /**
5
+ * Represents a monetary amount with integer value and subunit components.
6
+ *
7
+ * Stores money as two parts: main value (e.g., dollars) and subunit value (e.g., cents).
8
+ * This prevents floating-point precision issues in financial calculations.
9
+ */
3
10
  export declare class MoneyAmount implements Flattable<MoneyAmount.Flatten> {
4
11
  value: number;
5
12
  subunitValue: number;
13
+ /**
14
+ * Creates a new MoneyAmount instance.
15
+ *
16
+ * @param value - The main value (e.g., dollars, euros)
17
+ * @param subunitValue - The subunit value (e.g., cents), should be 0-99
18
+ */
6
19
  constructor(value: number, subunitValue: number);
20
+ /**
21
+ * Returns a MoneyAmount representing zero.
22
+ */
7
23
  static get zero(): MoneyAmount;
24
+ /**
25
+ * Adds another MoneyAmount to this one and returns the result.
26
+ *
27
+ * Properly handles subunit overflow (e.g., 50 cents + 60 cents = 1 dollar 10 cents).
28
+ *
29
+ * @param amount - The MoneyAmount to add
30
+ * @returns A new MoneyAmount representing the sum
31
+ */
8
32
  added(amount: MoneyAmount): MoneyAmount;
33
+ /**
34
+ * Multiplies this MoneyAmount by a factor and returns the result.
35
+ *
36
+ * Properly handles subunit calculations and overflow.
37
+ *
38
+ * @param factor - The multiplication factor
39
+ * @returns A new MoneyAmount representing the product
40
+ */
9
41
  multiplied(factor: number): MoneyAmount;
10
- formatted(currency: Configuration.Currency, configuration: Configuration): string;
42
+ /**
43
+ * Returns a localized formatted string representation of the amount.
44
+ *
45
+ * Uses Intl.NumberFormat for proper currency formatting based on locale.
46
+ *
47
+ * @param currency - The currency code (e.g., 'USD', 'EUR')
48
+ * @param configuration - Configuration containing locale information
49
+ * @returns Formatted currency string (e.g., "$12.50", "12,50 €")
50
+ */
51
+ formatted(currency: Currency, configuration: Configuration): string;
52
+ /**
53
+ * Returns the complete monetary value as a decimal number.
54
+ *
55
+ * @returns The total value (e.g., 12.50 for 12 dollars and 50 cents)
56
+ */
11
57
  get completeValue(): number;
58
+ /**
59
+ * Returns the flattened representation as a decimal number.
60
+ */
12
61
  get flatten(): MoneyAmount.Flatten;
13
62
  }
14
63
  export declare namespace MoneyAmount {
64
+ /**
65
+ * Flattened representation of MoneyAmount as a decimal number.
66
+ */
15
67
  type Flatten = number;
68
+ /**
69
+ * Type builder for MoneyAmount serialization/deserialization.
70
+ */
16
71
  class TypeBuilder implements ITypeBuilder<Flatten, MoneyAmount> {
72
+ /**
73
+ * Builds a MoneyAmount instance from a flattened decimal value.
74
+ *
75
+ * Separates the decimal into integer and subunit parts.
76
+ *
77
+ * @param value - Decimal value (e.g., 12.50)
78
+ * @returns MoneyAmount instance
79
+ */
17
80
  build(value: Flatten): MoneyAmount;
18
81
  }
82
+ /**
83
+ * Singleton instance of TypeBuilder for MoneyAmount.
84
+ */
19
85
  const builder: TypeBuilder;
20
86
  }
@@ -1,26 +1,66 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MoneyAmount = void 0;
4
+ /**
5
+ * Represents a monetary amount with integer value and subunit components.
6
+ *
7
+ * Stores money as two parts: main value (e.g., dollars) and subunit value (e.g., cents).
8
+ * This prevents floating-point precision issues in financial calculations.
9
+ */
4
10
  class MoneyAmount {
5
11
  value;
6
12
  subunitValue;
13
+ /**
14
+ * Creates a new MoneyAmount instance.
15
+ *
16
+ * @param value - The main value (e.g., dollars, euros)
17
+ * @param subunitValue - The subunit value (e.g., cents), should be 0-99
18
+ */
7
19
  constructor(value, subunitValue) {
8
20
  this.value = value;
9
21
  this.subunitValue = subunitValue;
10
22
  }
23
+ /**
24
+ * Returns a MoneyAmount representing zero.
25
+ */
11
26
  static get zero() {
12
27
  return new MoneyAmount(0, 0);
13
28
  }
29
+ /**
30
+ * Adds another MoneyAmount to this one and returns the result.
31
+ *
32
+ * Properly handles subunit overflow (e.g., 50 cents + 60 cents = 1 dollar 10 cents).
33
+ *
34
+ * @param amount - The MoneyAmount to add
35
+ * @returns A new MoneyAmount representing the sum
36
+ */
14
37
  added(amount) {
15
38
  const subunitValue = this.subunitValue + amount.subunitValue;
16
39
  const value = this.value + amount.value + Math.floor(subunitValue / 100);
17
40
  return new MoneyAmount(value, subunitValue % 100);
18
41
  }
42
+ /**
43
+ * Multiplies this MoneyAmount by a factor and returns the result.
44
+ *
45
+ * Properly handles subunit calculations and overflow.
46
+ *
47
+ * @param factor - The multiplication factor
48
+ * @returns A new MoneyAmount representing the product
49
+ */
19
50
  multiplied(factor) {
20
51
  const subunitValue = this.subunitValue * factor;
21
52
  const value = this.value * factor + Math.floor(subunitValue / 100);
22
53
  return new MoneyAmount(value, subunitValue % 100);
23
54
  }
55
+ /**
56
+ * Returns a localized formatted string representation of the amount.
57
+ *
58
+ * Uses Intl.NumberFormat for proper currency formatting based on locale.
59
+ *
60
+ * @param currency - The currency code (e.g., 'USD', 'EUR')
61
+ * @param configuration - Configuration containing locale information
62
+ * @returns Formatted currency string (e.g., "$12.50", "12,50 €")
63
+ */
24
64
  formatted(currency, configuration) {
25
65
  const numberFormat = Intl.NumberFormat(configuration.locale, {
26
66
  style: 'currency',
@@ -28,20 +68,42 @@ class MoneyAmount {
28
68
  });
29
69
  return numberFormat.format(this.value + this.subunitValue / 100);
30
70
  }
71
+ /**
72
+ * Returns the complete monetary value as a decimal number.
73
+ *
74
+ * @returns The total value (e.g., 12.50 for 12 dollars and 50 cents)
75
+ */
31
76
  get completeValue() {
32
77
  return this.value + this.subunitValue / 100;
33
78
  }
79
+ /**
80
+ * Returns the flattened representation as a decimal number.
81
+ */
34
82
  get flatten() {
35
83
  return this.value + this.subunitValue / 100;
36
84
  }
37
85
  }
38
86
  exports.MoneyAmount = MoneyAmount;
39
87
  (function (MoneyAmount) {
88
+ /**
89
+ * Type builder for MoneyAmount serialization/deserialization.
90
+ */
40
91
  class TypeBuilder {
92
+ /**
93
+ * Builds a MoneyAmount instance from a flattened decimal value.
94
+ *
95
+ * Separates the decimal into integer and subunit parts.
96
+ *
97
+ * @param value - Decimal value (e.g., 12.50)
98
+ * @returns MoneyAmount instance
99
+ */
41
100
  build(value) {
42
101
  return new MoneyAmount(Math.floor(value), Math.round((value - Math.floor(value)) * 100));
43
102
  }
44
103
  }
45
104
  MoneyAmount.TypeBuilder = TypeBuilder;
105
+ /**
106
+ * Singleton instance of TypeBuilder for MoneyAmount.
107
+ */
46
108
  MoneyAmount.builder = new MoneyAmount.TypeBuilder();
47
109
  })(MoneyAmount || (exports.MoneyAmount = MoneyAmount = {}));
@@ -1,28 +1,89 @@
1
1
  import { Dictionary, Flattable, ITypeBuilder, Tagged, ValueTypeBuilder } from '@stevenkellner/typescript-common-functionality';
2
+ /**
3
+ * Represents notification properties for a user including device tokens and subscription preferences.
4
+ *
5
+ * Manages push notification device tokens (identified by hashed token IDs for security)
6
+ * and user preferences for which types of notifications they want to receive.
7
+ */
2
8
  export declare class NotificationProperties implements Flattable<NotificationProperties.Flatten> {
3
9
  tokens: Dictionary<NotificationProperties.TokenId, string>;
4
10
  subscriptions: NotificationProperties.Subscription[];
11
+ /**
12
+ * Creates new notification properties.
13
+ * @param tokens - Dictionary mapping token IDs to device tokens for push notifications (defaults to empty)
14
+ * @param subscriptions - Array of notification types the user is subscribed to (defaults to empty)
15
+ */
5
16
  constructor(tokens?: Dictionary<NotificationProperties.TokenId, string>, subscriptions?: NotificationProperties.Subscription[]);
17
+ /**
18
+ * Gets the flattened representation of these notification properties for serialization.
19
+ */
6
20
  get flatten(): NotificationProperties.Flatten;
7
21
  }
8
22
  export declare namespace NotificationProperties {
9
- type TokenId = Tagged<string, 'notificationToken'>;
10
- namespace TokenId {
23
+ /**
24
+ * Tagged type for notification token identifiers.
25
+ * Token IDs are derived from hashing the actual device tokens for security.
26
+ */
27
+ export type TokenId = Tagged<string, 'notificationToken'>;
28
+ export namespace TokenId {
29
+ /**
30
+ * Creates a token ID from a device token by hashing it with SHA-512.
31
+ * Only the first 16 characters of the hash are used as the identifier.
32
+ * @param token - The device push notification token
33
+ * @returns A hashed token ID for secure storage and lookup
34
+ */
11
35
  function create(token: string): TokenId;
36
+ /**
37
+ * Flattened representation of a token ID (plain string).
38
+ */
12
39
  type Flatten = string;
40
+ /**
41
+ * Builder for constructing TokenId instances from strings.
42
+ */
13
43
  const builder: Tagged.TypeBuilder<string, "notificationToken">;
14
44
  }
15
- type Subscription = 'new-fine' | 'fine-reminder' | 'fine-state-change';
16
- namespace Subscription {
17
- const all: Subscription[];
18
- const builder: ValueTypeBuilder<Subscription>;
45
+ /**
46
+ * Available notification subscription types.
47
+ */
48
+ const subscriptions: readonly ["new-fine", "fine-reminder", "fine-state-change"];
49
+ /**
50
+ * Type representing the available notification subscription options.
51
+ * - new-fine: Notifications when a new fine is created
52
+ * - fine-reminder: Reminder notifications for unpaid fines
53
+ * - fine-state-change: Notifications when a fine's status changes
54
+ */
55
+ export type Subscription = typeof subscriptions[number];
56
+ export namespace Subscription {
57
+ /**
58
+ * Readonly array of all available subscription types.
59
+ */
60
+ const all: readonly Subscription[];
61
+ /**
62
+ * Builder for constructing Subscription values from strings.
63
+ */
64
+ const builder: ValueTypeBuilder<"new-fine" | "fine-reminder" | "fine-state-change">;
19
65
  }
20
- type Flatten = {
66
+ /**
67
+ * Flattened representation of notification properties for serialization.
68
+ */
69
+ export type Flatten = {
21
70
  tokens: Dictionary.Flatten<string>;
22
71
  subscriptions: Subscription[];
23
72
  };
24
- class TypeBuilder implements ITypeBuilder<Flatten, NotificationProperties> {
73
+ /**
74
+ * Builder for constructing NotificationProperties from flattened data.
75
+ */
76
+ export class TypeBuilder implements ITypeBuilder<Flatten, NotificationProperties> {
77
+ /**
78
+ * Builds a NotificationProperties instance from flattened data.
79
+ * @param value - The flattened notification properties data
80
+ * @returns A new NotificationProperties instance
81
+ */
25
82
  build(value: Flatten): NotificationProperties;
26
83
  }
27
- const builder: TypeBuilder;
84
+ /**
85
+ * Singleton builder instance for NotificationProperties.
86
+ */
87
+ export const builder: TypeBuilder;
88
+ export {};
28
89
  }