@stevenkellner/team-conduct-api 1.0.36 → 2.0.2

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 +197 -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
@@ -1,15 +1,59 @@
1
- import { FirestoreScheme } from '../FirestoreScheme';
1
+ import { FirestoreScheme } from './FirestoreScheme';
2
2
  import { Messaging } from './Messaging';
3
+ /**
4
+ * Singleton configuration manager for Firebase services.
5
+ *
6
+ * Provides centralized access to Firestore document reference and Firebase Cloud Messaging.
7
+ * Must be configured once before accessing services.
8
+ */
3
9
  export declare class FirebaseConfiguration {
10
+ /**
11
+ * Singleton instance of FirebaseConfiguration.
12
+ */
4
13
  static readonly shared: FirebaseConfiguration;
5
14
  private configured;
6
15
  private _baseFirestoreDocument;
7
16
  private _messaging;
17
+ /**
18
+ * Private constructor to enforce singleton pattern.
19
+ */
8
20
  private constructor();
21
+ /**
22
+ * Configures the Firebase services.
23
+ *
24
+ * Must be called exactly once before accessing any Firebase services.
25
+ * Subsequent calls will throw an error.
26
+ *
27
+ * @param configuration - Configuration object containing Firestore and Messaging services
28
+ * @throws Error if already configured
29
+ */
9
30
  configure(configuration: {
10
31
  baseFirestoreDocument: FirestoreScheme;
11
32
  messaging: Messaging;
12
33
  }): void;
34
+ /**
35
+ * Reconfigures the Firebase services.
36
+ *
37
+ * Allows updating the configuration with new services.
38
+ *
39
+ * @param configuration - New configuration object containing Firestore and Messaging services
40
+ */
41
+ reconfigure(configuration: {
42
+ baseFirestoreDocument: FirestoreScheme;
43
+ messaging: Messaging;
44
+ }): void;
45
+ /**
46
+ * Gets the base Firestore document reference.
47
+ *
48
+ * @returns The configured Firestore document scheme
49
+ * @throws Error if not yet configured
50
+ */
13
51
  get baseFirestoreDocument(): FirestoreScheme;
52
+ /**
53
+ * Gets the Firebase Cloud Messaging service.
54
+ *
55
+ * @returns The configured Messaging service
56
+ * @throws Error if not yet configured
57
+ */
14
58
  get messaging(): Messaging;
15
59
  }
@@ -1,12 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FirebaseConfiguration = void 0;
4
+ /**
5
+ * Singleton configuration manager for Firebase services.
6
+ *
7
+ * Provides centralized access to Firestore document reference and Firebase Cloud Messaging.
8
+ * Must be configured once before accessing services.
9
+ */
4
10
  class FirebaseConfiguration {
11
+ /**
12
+ * Singleton instance of FirebaseConfiguration.
13
+ */
5
14
  static shared = new FirebaseConfiguration();
6
15
  configured = false;
7
16
  _baseFirestoreDocument = null;
8
17
  _messaging = null;
18
+ /**
19
+ * Private constructor to enforce singleton pattern.
20
+ */
9
21
  constructor() { }
22
+ /**
23
+ * Configures the Firebase services.
24
+ *
25
+ * Must be called exactly once before accessing any Firebase services.
26
+ * Subsequent calls will throw an error.
27
+ *
28
+ * @param configuration - Configuration object containing Firestore and Messaging services
29
+ * @throws Error if already configured
30
+ */
10
31
  configure(configuration) {
11
32
  if (this.configured)
12
33
  throw new Error('Configuration is already configured');
@@ -14,11 +35,34 @@ class FirebaseConfiguration {
14
35
  this._messaging = configuration.messaging;
15
36
  this.configured = true;
16
37
  }
38
+ /**
39
+ * Reconfigures the Firebase services.
40
+ *
41
+ * Allows updating the configuration with new services.
42
+ *
43
+ * @param configuration - New configuration object containing Firestore and Messaging services
44
+ */
45
+ reconfigure(configuration) {
46
+ this.configured = false;
47
+ this.configure(configuration);
48
+ }
49
+ /**
50
+ * Gets the base Firestore document reference.
51
+ *
52
+ * @returns The configured Firestore document scheme
53
+ * @throws Error if not yet configured
54
+ */
17
55
  get baseFirestoreDocument() {
18
56
  if (!this.configured || !this._baseFirestoreDocument)
19
57
  throw new Error('Configuration.baseFirestoreDocument is not configured');
20
58
  return this._baseFirestoreDocument;
21
59
  }
60
+ /**
61
+ * Gets the Firebase Cloud Messaging service.
62
+ *
63
+ * @returns The configured Messaging service
64
+ * @throws Error if not yet configured
65
+ */
22
66
  get messaging() {
23
67
  if (!this.configured || !this._messaging)
24
68
  throw new Error('Configuration.messaging is not configured');
@@ -0,0 +1,197 @@
1
+ import { FirestoreCollection, FirestoreDocument } from '@stevenkellner/firebase-function';
2
+ import { FirestoreScheme } from './FirestoreScheme';
3
+ import { Fine, FineTemplate, Invitation, Person, User, Team } from '../types';
4
+ /**
5
+ * Accessor class for Firestore documents and collections.
6
+ *
7
+ * Provides type-safe access to Firestore database documents and collections
8
+ * following the schema defined in {@link FirestoreScheme}.
9
+ *
10
+ * Uses a singleton pattern to ensure consistent access to the Firestore instance.
11
+ * All methods return strongly-typed Firestore references that can be used for
12
+ * database operations.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Access a team document
17
+ * const teamDoc = Firestore.shared.team(teamId);
18
+ *
19
+ * // Access a person in a team
20
+ * const personDoc = Firestore.shared.person(teamId, personId);
21
+ *
22
+ * // Access all fines in a team
23
+ * const finesCollection = Firestore.shared.fines(teamId);
24
+ * ```
25
+ *
26
+ * @remarks
27
+ * Requires {@link FirebaseConfiguration} to be configured before use.
28
+ * All document and collection references are lazy and don't perform any
29
+ * database operations until explicitly called.
30
+ */
31
+ export declare class Firestore {
32
+ /**
33
+ * Protected constructor to enforce singleton pattern.
34
+ * Use {@link Firestore.shared} to get an instance.
35
+ */
36
+ protected constructor();
37
+ /**
38
+ * The singleton instance of the Firestore accessor.
39
+ *
40
+ * @private
41
+ */
42
+ private static sharedInstance;
43
+ /**
44
+ * Gets the singleton instance of the Firestore accessor.
45
+ *
46
+ * Creates the instance on first access and returns the same instance
47
+ * on subsequent calls.
48
+ *
49
+ * @returns The singleton Firestore accessor instance
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const firestore = Firestore.shared;
54
+ * const teamDoc = firestore.team(teamId);
55
+ * ```
56
+ */
57
+ static get shared(): Firestore;
58
+ /**
59
+ * Gets the base Firestore schema from the configured Firebase instance.
60
+ *
61
+ * Accesses the global FirebaseConfiguration to retrieve the root document
62
+ * reference for all database operations.
63
+ *
64
+ * @returns The base Firestore schema with typed collections
65
+ *
66
+ * @throws {Error} If FirebaseConfiguration has not been configured
67
+ *
68
+ * @private
69
+ */
70
+ protected get base(): FirestoreScheme;
71
+ /**
72
+ * Gets a reference to a team document.
73
+ *
74
+ * @param id - The unique identifier of the team
75
+ * @returns A typed Firestore document reference for the team
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const teamDoc = Firestore.shared.team(teamId);
80
+ * const teamData = await teamDoc.get();
81
+ * ```
82
+ */
83
+ team(id: Team.Id): FirestoreDocument<Team>;
84
+ /**
85
+ * Gets a reference to a user document.
86
+ *
87
+ * @param id - The unique identifier of the user
88
+ * @returns A typed Firestore document reference for the user
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const userDoc = Firestore.shared.user(userId);
93
+ * const userData = await userDoc.get();
94
+ * ```
95
+ */
96
+ user(id: User.Id): FirestoreDocument<User>;
97
+ /**
98
+ * Gets a reference to an invitation document.
99
+ *
100
+ * @param id - The unique identifier of the invitation
101
+ * @returns A typed Firestore document reference for the invitation
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const invitationDoc = Firestore.shared.invitation(invitationId);
106
+ * const invitationData = await invitationDoc.get();
107
+ * ```
108
+ */
109
+ invitation(id: Invitation.Id): FirestoreDocument<Invitation>;
110
+ /**
111
+ * Gets a reference to the persons collection within a team.
112
+ *
113
+ * @param teamId - The unique identifier of the team
114
+ * @returns A typed Firestore collection reference for persons in the team
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const personsCollection = Firestore.shared.persons(teamId);
119
+ * const allPersons = await personsCollection.getAll();
120
+ * ```
121
+ */
122
+ persons(teamId: Team.Id): FirestoreCollection<{
123
+ [x: string]: FirestoreDocument<Person, never>;
124
+ }>;
125
+ /**
126
+ * Gets a reference to a specific person document within a team.
127
+ *
128
+ * @param teamId - The unique identifier of the team
129
+ * @param id - The unique identifier of the person
130
+ * @returns A typed Firestore document reference for the person
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const personDoc = Firestore.shared.person(teamId, personId);
135
+ * const personData = await personDoc.get();
136
+ * ```
137
+ */
138
+ person(teamId: Team.Id, id: Person.Id): FirestoreDocument<Person>;
139
+ /**
140
+ * Gets a reference to the fine templates collection within a team.
141
+ *
142
+ * @param teamId - The unique identifier of the team
143
+ * @returns A typed Firestore collection reference for fine templates in the team
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * const templatesCollection = Firestore.shared.fineTemplates(teamId);
148
+ * const allTemplates = await templatesCollection.getAll();
149
+ * ```
150
+ */
151
+ fineTemplates(teamId: Team.Id): FirestoreCollection<{
152
+ [x: string]: FirestoreDocument<FineTemplate, never>;
153
+ }>;
154
+ /**
155
+ * Gets a reference to a specific fine template document within a team.
156
+ *
157
+ * @param teamId - The unique identifier of the team
158
+ * @param id - The unique identifier of the fine template
159
+ * @returns A typed Firestore document reference for the fine template
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const templateDoc = Firestore.shared.fineTemplate(teamId, templateId);
164
+ * const templateData = await templateDoc.get();
165
+ * ```
166
+ */
167
+ fineTemplate(teamId: Team.Id, id: FineTemplate.Id): FirestoreDocument<FineTemplate>;
168
+ /**
169
+ * Gets a reference to the fines collection within a team.
170
+ *
171
+ * @param teamId - The unique identifier of the team
172
+ * @returns A typed Firestore collection reference for fines in the team
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const finesCollection = Firestore.shared.fines(teamId);
177
+ * const allFines = await finesCollection.getAll();
178
+ * ```
179
+ */
180
+ fines(teamId: Team.Id): FirestoreCollection<{
181
+ [x: string]: FirestoreDocument<Fine, never>;
182
+ }>;
183
+ /**
184
+ * Gets a reference to a specific fine document within a team.
185
+ *
186
+ * @param teamId - The unique identifier of the team
187
+ * @param id - The unique identifier of the fine
188
+ * @returns A typed Firestore document reference for the fine
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const fineDoc = Firestore.shared.fine(teamId, fineId);
193
+ * const fineData = await fineDoc.get();
194
+ * ```
195
+ */
196
+ fine(teamId: Team.Id, id: Fine.Id): FirestoreDocument<Fine>;
197
+ }
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Firestore = void 0;
4
+ const _1 = require(".");
5
+ /**
6
+ * Accessor class for Firestore documents and collections.
7
+ *
8
+ * Provides type-safe access to Firestore database documents and collections
9
+ * following the schema defined in {@link FirestoreScheme}.
10
+ *
11
+ * Uses a singleton pattern to ensure consistent access to the Firestore instance.
12
+ * All methods return strongly-typed Firestore references that can be used for
13
+ * database operations.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Access a team document
18
+ * const teamDoc = Firestore.shared.team(teamId);
19
+ *
20
+ * // Access a person in a team
21
+ * const personDoc = Firestore.shared.person(teamId, personId);
22
+ *
23
+ * // Access all fines in a team
24
+ * const finesCollection = Firestore.shared.fines(teamId);
25
+ * ```
26
+ *
27
+ * @remarks
28
+ * Requires {@link FirebaseConfiguration} to be configured before use.
29
+ * All document and collection references are lazy and don't perform any
30
+ * database operations until explicitly called.
31
+ */
32
+ class Firestore {
33
+ /**
34
+ * Protected constructor to enforce singleton pattern.
35
+ * Use {@link Firestore.shared} to get an instance.
36
+ */
37
+ constructor() { }
38
+ /**
39
+ * The singleton instance of the Firestore accessor.
40
+ *
41
+ * @private
42
+ */
43
+ static sharedInstance = null;
44
+ /**
45
+ * Gets the singleton instance of the Firestore accessor.
46
+ *
47
+ * Creates the instance on first access and returns the same instance
48
+ * on subsequent calls.
49
+ *
50
+ * @returns The singleton Firestore accessor instance
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const firestore = Firestore.shared;
55
+ * const teamDoc = firestore.team(teamId);
56
+ * ```
57
+ */
58
+ static get shared() {
59
+ if (!Firestore.sharedInstance)
60
+ Firestore.sharedInstance = new Firestore();
61
+ return Firestore.sharedInstance;
62
+ }
63
+ /**
64
+ * Gets the base Firestore schema from the configured Firebase instance.
65
+ *
66
+ * Accesses the global FirebaseConfiguration to retrieve the root document
67
+ * reference for all database operations.
68
+ *
69
+ * @returns The base Firestore schema with typed collections
70
+ *
71
+ * @throws {Error} If FirebaseConfiguration has not been configured
72
+ *
73
+ * @private
74
+ */
75
+ get base() {
76
+ return _1.FirebaseConfiguration.shared.baseFirestoreDocument;
77
+ }
78
+ /**
79
+ * Gets a reference to a team document.
80
+ *
81
+ * @param id - The unique identifier of the team
82
+ * @returns A typed Firestore document reference for the team
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const teamDoc = Firestore.shared.team(teamId);
87
+ * const teamData = await teamDoc.get();
88
+ * ```
89
+ */
90
+ team(id) {
91
+ return this.base
92
+ .collection('teams')
93
+ .document(id.guidString);
94
+ }
95
+ /**
96
+ * Gets a reference to a user document.
97
+ *
98
+ * @param id - The unique identifier of the user
99
+ * @returns A typed Firestore document reference for the user
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const userDoc = Firestore.shared.user(userId);
104
+ * const userData = await userDoc.get();
105
+ * ```
106
+ */
107
+ user(id) {
108
+ return this.base
109
+ .collection('users')
110
+ .document(id.value);
111
+ }
112
+ /**
113
+ * Gets a reference to an invitation document.
114
+ *
115
+ * @param id - The unique identifier of the invitation
116
+ * @returns A typed Firestore document reference for the invitation
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const invitationDoc = Firestore.shared.invitation(invitationId);
121
+ * const invitationData = await invitationDoc.get();
122
+ * ```
123
+ */
124
+ invitation(id) {
125
+ return this.base
126
+ .collection('invitations')
127
+ .document(id.value);
128
+ }
129
+ /**
130
+ * Gets a reference to the persons collection within a team.
131
+ *
132
+ * @param teamId - The unique identifier of the team
133
+ * @returns A typed Firestore collection reference for persons in the team
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const personsCollection = Firestore.shared.persons(teamId);
138
+ * const allPersons = await personsCollection.getAll();
139
+ * ```
140
+ */
141
+ persons(teamId) {
142
+ return this.base
143
+ .collection('teams')
144
+ .document(teamId.guidString)
145
+ .collection('persons');
146
+ }
147
+ /**
148
+ * Gets a reference to a specific person document within a team.
149
+ *
150
+ * @param teamId - The unique identifier of the team
151
+ * @param id - The unique identifier of the person
152
+ * @returns A typed Firestore document reference for the person
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const personDoc = Firestore.shared.person(teamId, personId);
157
+ * const personData = await personDoc.get();
158
+ * ```
159
+ */
160
+ person(teamId, id) {
161
+ return this.persons(teamId)
162
+ .document(id.guidString);
163
+ }
164
+ /**
165
+ * Gets a reference to the fine templates collection within a team.
166
+ *
167
+ * @param teamId - The unique identifier of the team
168
+ * @returns A typed Firestore collection reference for fine templates in the team
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * const templatesCollection = Firestore.shared.fineTemplates(teamId);
173
+ * const allTemplates = await templatesCollection.getAll();
174
+ * ```
175
+ */
176
+ fineTemplates(teamId) {
177
+ return this.base
178
+ .collection('teams')
179
+ .document(teamId.guidString)
180
+ .collection('fineTemplates');
181
+ }
182
+ /**
183
+ * Gets a reference to a specific fine template document within a team.
184
+ *
185
+ * @param teamId - The unique identifier of the team
186
+ * @param id - The unique identifier of the fine template
187
+ * @returns A typed Firestore document reference for the fine template
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const templateDoc = Firestore.shared.fineTemplate(teamId, templateId);
192
+ * const templateData = await templateDoc.get();
193
+ * ```
194
+ */
195
+ fineTemplate(teamId, id) {
196
+ return this.fineTemplates(teamId)
197
+ .document(id.guidString);
198
+ }
199
+ /**
200
+ * Gets a reference to the fines collection within a team.
201
+ *
202
+ * @param teamId - The unique identifier of the team
203
+ * @returns A typed Firestore collection reference for fines in the team
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const finesCollection = Firestore.shared.fines(teamId);
208
+ * const allFines = await finesCollection.getAll();
209
+ * ```
210
+ */
211
+ fines(teamId) {
212
+ return this.base
213
+ .collection('teams')
214
+ .document(teamId.guidString)
215
+ .collection('fines');
216
+ }
217
+ /**
218
+ * Gets a reference to a specific fine document within a team.
219
+ *
220
+ * @param teamId - The unique identifier of the team
221
+ * @param id - The unique identifier of the fine
222
+ * @returns A typed Firestore document reference for the fine
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const fineDoc = Firestore.shared.fine(teamId, fineId);
227
+ * const fineData = await fineDoc.get();
228
+ * ```
229
+ */
230
+ fine(teamId, id) {
231
+ return this.fines(teamId)
232
+ .document(id.guidString);
233
+ }
234
+ }
235
+ exports.Firestore = Firestore;
@@ -1,5 +1,19 @@
1
1
  import { FirestoreCollection, FirestoreDocument } from '@stevenkellner/firebase-function';
2
- import { Fine, FineTemplate, Invitation, Person, Team, User } from './types';
2
+ import { Fine, FineTemplate, Invitation, Person, Team, User } from '../types';
3
+ /**
4
+ * Type definition for the Firestore database schema.
5
+ *
6
+ * Defines the hierarchical structure of the Firestore database:
7
+ * - **users**: Collection of user documents indexed by User.Id
8
+ * - **invitations**: Collection of invitation documents indexed by Invitation.Id
9
+ * - **teams**: Collection of team documents indexed by Team.Id, each containing:
10
+ * - **persons**: Subcollection of person documents indexed by Person.Id
11
+ * - **fineTemplates**: Subcollection of fine template documents indexed by FineTemplate.Id
12
+ * - **fines**: Subcollection of fine documents indexed by Fine.Id
13
+ *
14
+ * This type ensures type-safe access to Firestore collections and documents
15
+ * throughout the application.
16
+ */
3
17
  export type FirestoreScheme = FirestoreDocument<never, {
4
18
  users: FirestoreCollection<{
5
19
  [UserId in string]: FirestoreDocument<User>;
@@ -1,26 +1,90 @@
1
+ /**
2
+ * Represents a notification payload for Firebase Cloud Messaging.
3
+ */
1
4
  export interface Notification {
5
+ /**
6
+ * The notification title.
7
+ */
2
8
  title?: string;
9
+ /**
10
+ * The notification body text.
11
+ */
3
12
  body?: string;
13
+ /**
14
+ * URL of an image to be displayed in the notification.
15
+ */
4
16
  imageUrl?: string;
5
17
  }
18
+ /**
19
+ * Response from sending batch messages to multiple devices.
20
+ */
6
21
  export interface BatchResponse {
22
+ /**
23
+ * Array of individual message responses.
24
+ */
7
25
  responses: {
26
+ /**
27
+ * Whether the message was sent successfully.
28
+ */
8
29
  success: boolean;
30
+ /**
31
+ * The message ID if successful.
32
+ */
9
33
  messageId?: string;
34
+ /**
35
+ * Error information if the message failed to send.
36
+ */
10
37
  error?: {
38
+ /**
39
+ * Error code identifier.
40
+ */
11
41
  code: string;
42
+ /**
43
+ * Human-readable error message.
44
+ */
12
45
  message: string;
46
+ /**
47
+ * Optional stack trace for debugging.
48
+ */
13
49
  stack?: string;
50
+ /**
51
+ * Converts the error to a JSON object.
52
+ */
14
53
  toJSON(): object;
15
54
  };
16
55
  }[];
56
+ /**
57
+ * Number of messages sent successfully.
58
+ */
17
59
  successCount: number;
60
+ /**
61
+ * Number of messages that failed to send.
62
+ */
18
63
  failureCount: number;
19
64
  }
65
+ /**
66
+ * Message to be sent to multiple device tokens.
67
+ */
20
68
  export interface MulticastMessage {
69
+ /**
70
+ * Array of device registration tokens to send the message to.
71
+ */
21
72
  tokens: string[];
73
+ /**
74
+ * Optional notification payload to include in the message.
75
+ */
22
76
  notification?: Notification;
23
77
  }
78
+ /**
79
+ * Firebase Cloud Messaging service interface.
80
+ */
24
81
  export interface Messaging {
82
+ /**
83
+ * Sends a multicast message to multiple devices.
84
+ *
85
+ * @param message - The multicast message containing tokens and notification
86
+ * @param dryRun - If true, validates the message without actually sending it
87
+ * @returns Promise resolving to batch response with success/failure details
88
+ */
25
89
  sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;
26
90
  }