@stevenkellner/team-conduct-api 2.0.18 → 2.0.20

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 (231) hide show
  1. package/lib/src/functions/fine/add.d.ts +3 -8
  2. package/lib/src/functions/fine/add.js +1 -2
  3. package/lib/src/functions/fine/delete.d.ts +1 -6
  4. package/lib/src/functions/fine/delete.js +2 -3
  5. package/lib/src/functions/fine/update.d.ts +2 -8
  6. package/lib/src/functions/fine/update.js +1 -3
  7. package/lib/src/functions/fineTemplate/add.d.ts +3 -3
  8. package/lib/src/functions/fineTemplate/update.d.ts +3 -3
  9. package/lib/src/functions/firebaseFunctionsContext.d.ts +34 -1
  10. package/lib/src/functions/firebaseFunctionsContext.js +33 -33
  11. package/lib/src/functions/index.d.ts +10 -8
  12. package/lib/src/functions/index.js +11 -8
  13. package/lib/src/functions/notification/markNotificationAsRead.d.ts +14 -0
  14. package/lib/src/functions/notification/{subscribe.js → markNotificationAsRead.js} +5 -7
  15. package/lib/src/functions/person/kickout.d.ts +6 -6
  16. package/lib/src/functions/person/kickout.js +4 -4
  17. package/lib/src/functions/person/roleEdit.d.ts +5 -5
  18. package/lib/src/functions/person/roleEdit.js +3 -3
  19. package/lib/src/functions/{paypalMe/edit.d.ts → team/delete.d.ts} +5 -7
  20. package/lib/src/functions/{paypalMe/edit.js → team/delete.js} +4 -5
  21. package/lib/src/functions/team/new.d.ts +18 -18
  22. package/lib/src/functions/team/new.js +8 -4
  23. package/lib/src/functions/team/update.d.ts +34 -0
  24. package/lib/src/functions/team/update.js +23 -0
  25. package/lib/src/functions/user/register.d.ts +4 -0
  26. package/lib/src/functions/user/register.js +3 -1
  27. package/lib/src/functions/user/update.d.ts +26 -0
  28. package/lib/src/functions/user/update.js +15 -0
  29. package/lib/src/index.d.ts +1 -1
  30. package/lib/src/index.js +1 -1
  31. package/lib/src/locales/de.d.ts +1 -1
  32. package/lib/src/locales/de.js +6 -2
  33. package/lib/src/locales/en.d.ts +6 -2
  34. package/lib/src/locales/en.js +6 -2
  35. package/lib/src/types/{MoneyAmount.d.ts → Money.d.ts} +23 -23
  36. package/lib/src/types/{MoneyAmount.js → Money.js} +25 -25
  37. package/lib/src/types/fine/Fine.d.ts +275 -0
  38. package/lib/src/types/fine/Fine.js +318 -0
  39. package/lib/src/types/fine/FineTemplate.d.ts +154 -0
  40. package/lib/src/types/fine/FineTemplate.js +170 -0
  41. package/lib/src/types/{PayedState.d.ts → fine/PayedState.d.ts} +1 -1
  42. package/lib/src/types/{PayedState.js → fine/PayedState.js} +1 -1
  43. package/lib/src/types/fine/index.d.ts +3 -0
  44. package/lib/src/{firebase → types/fine}/index.js +3 -6
  45. package/lib/src/types/index.d.ts +7 -18
  46. package/lib/src/types/index.js +7 -18
  47. package/lib/src/types/{Localization.d.ts → localization/Localization.d.ts} +15 -43
  48. package/lib/src/types/localization/Localization.js +54 -0
  49. package/lib/src/types/localization/PluralLocalization.d.ts +23 -0
  50. package/lib/src/types/localization/PluralLocalization.js +35 -0
  51. package/lib/src/types/{Pluralization.d.ts → localization/Pluralization.d.ts} +1 -0
  52. package/lib/src/types/{Pluralization.js → localization/Pluralization.js} +1 -0
  53. package/lib/src/types/localization/ValueLocalization.d.ts +22 -0
  54. package/lib/src/types/localization/ValueLocalization.js +41 -0
  55. package/lib/src/types/localization/index.d.ts +5 -0
  56. package/lib/src/types/localization/index.js +21 -0
  57. package/lib/src/types/notification/InAppNotification.d.ts +152 -0
  58. package/lib/src/types/notification/InAppNotification.js +136 -0
  59. package/lib/src/types/notification/index.d.ts +1 -0
  60. package/lib/src/types/notification/index.js +17 -0
  61. package/lib/src/types/{Person.d.ts → person/Person.d.ts} +3 -3
  62. package/lib/src/types/{Person.js → person/Person.js} +3 -3
  63. package/lib/src/types/{PersonProperties.d.ts → person/PersonProperties.d.ts} +8 -7
  64. package/lib/src/types/{PersonProperties.js → person/PersonProperties.js} +7 -6
  65. package/lib/src/types/{PersonSignInProperties.d.ts → person/PersonSignInProperties.d.ts} +9 -11
  66. package/lib/src/types/{PersonSignInProperties.js → person/PersonSignInProperties.js} +7 -10
  67. package/lib/src/types/person/index.d.ts +3 -0
  68. package/lib/src/types/person/index.js +19 -0
  69. package/lib/src/types/{Invitation.d.ts → team/Invitation.d.ts} +1 -1
  70. package/lib/src/types/{Invitation.js → team/Invitation.js} +1 -1
  71. package/lib/src/types/team/Team.d.ts +144 -0
  72. package/lib/src/types/team/Team.js +141 -0
  73. package/lib/src/types/team/TeamRole.d.ts +30 -0
  74. package/lib/src/types/{UserRole.js → team/TeamRole.js} +16 -15
  75. package/lib/src/types/team/index.d.ts +3 -0
  76. package/lib/src/types/team/index.js +19 -0
  77. package/lib/src/types/{NotificationProperties.d.ts → user/NotificationProperties.d.ts} +8 -3
  78. package/lib/src/types/{NotificationProperties.js → user/NotificationProperties.js} +4 -0
  79. package/lib/src/types/user/User.d.ts +328 -0
  80. package/lib/src/types/user/User.js +355 -0
  81. package/lib/src/types/user/index.d.ts +2 -0
  82. package/lib/src/types/user/index.js +18 -0
  83. package/lib/src/utils/StaticUnionTypeBuilder.d.ts +9 -0
  84. package/lib/src/utils/StaticUnionTypeBuilder.js +23 -0
  85. package/lib/src/utils/index.d.ts +1 -0
  86. package/lib/src/utils/index.js +17 -0
  87. package/lib/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +4 -3
  89. package/src/functions/fine/add.ts +3 -5
  90. package/src/functions/fine/delete.ts +3 -5
  91. package/src/functions/fine/update.ts +2 -5
  92. package/src/functions/firebaseFunctionsContext.ts +40 -40
  93. package/src/functions/index.ts +11 -9
  94. package/src/functions/notification/markNotificationAsRead.ts +19 -0
  95. package/src/functions/person/add.ts +1 -1
  96. package/src/functions/person/kickout.ts +6 -6
  97. package/src/functions/person/roleEdit.ts +5 -5
  98. package/src/functions/{paypalMe/edit.ts → team/delete.ts} +5 -7
  99. package/src/functions/team/new.ts +19 -11
  100. package/src/functions/team/update.ts +40 -0
  101. package/src/functions/user/register.ts +7 -3
  102. package/src/functions/user/update.ts +29 -0
  103. package/src/index.ts +1 -1
  104. package/src/locales/de.ts +7 -3
  105. package/src/locales/en.ts +7 -3
  106. package/src/types/{MoneyAmount.ts → Money.ts} +29 -29
  107. package/src/types/fine/Fine.ts +399 -0
  108. package/src/types/fine/FineTemplate.ts +219 -0
  109. package/src/types/{PayedState.ts → fine/PayedState.ts} +2 -2
  110. package/src/types/fine/index.ts +3 -0
  111. package/src/types/index.ts +7 -18
  112. package/src/types/{Localization.ts → localization/Localization.ts} +7 -64
  113. package/src/types/localization/PluralLocalization.ts +32 -0
  114. package/src/types/{Pluralization.ts → localization/Pluralization.ts} +1 -0
  115. package/src/types/localization/ValueLocalization.ts +36 -0
  116. package/src/types/localization/index.ts +5 -0
  117. package/src/types/notification/InAppNotification.ts +184 -0
  118. package/src/types/notification/index.ts +1 -0
  119. package/src/types/{Person.ts → person/Person.ts} +3 -3
  120. package/src/types/{PersonProperties.ts → person/PersonProperties.ts} +8 -7
  121. package/src/types/{PersonSignInProperties.ts → person/PersonSignInProperties.ts} +13 -12
  122. package/src/types/person/index.ts +3 -0
  123. package/src/types/{Invitation.ts → team/Invitation.ts} +1 -1
  124. package/src/types/team/Team.ts +204 -0
  125. package/src/types/{UserRole.ts → team/TeamRole.ts} +19 -17
  126. package/src/types/team/index.ts +3 -0
  127. package/src/types/{NotificationProperties.ts → user/NotificationProperties.ts} +12 -3
  128. package/src/types/user/User.ts +451 -0
  129. package/src/types/user/index.ts +2 -0
  130. package/src/utils/StaticUnionTypeBuilder.ts +23 -0
  131. package/src/utils/index.ts +1 -0
  132. package/lib/src/firebase/FirebaseConfiguration.d.ts +0 -64
  133. package/lib/src/firebase/FirebaseConfiguration.js +0 -79
  134. package/lib/src/firebase/Firestore.d.ts +0 -201
  135. package/lib/src/firebase/Firestore.js +0 -244
  136. package/lib/src/firebase/FirestoreScheme.d.ts +0 -42
  137. package/lib/src/firebase/FirestoreScheme.js +0 -2
  138. package/lib/src/firebase/Messaging.d.ts +0 -90
  139. package/lib/src/firebase/Messaging.js +0 -2
  140. package/lib/src/firebase/checkAuthentication.d.ts +0 -38
  141. package/lib/src/firebase/checkAuthentication.js +0 -64
  142. package/lib/src/firebase/index.d.ts +0 -6
  143. package/lib/src/firebase/pushNotification.d.ts +0 -39
  144. package/lib/src/firebase/pushNotification.js +0 -88
  145. package/lib/src/functions/notification/subscribe.d.ts +0 -18
  146. package/lib/src/types/Configuration.d.ts +0 -46
  147. package/lib/src/types/Configuration.js +0 -51
  148. package/lib/src/types/Fine.d.ts +0 -71
  149. package/lib/src/types/Fine.js +0 -74
  150. package/lib/src/types/FineAmount.d.ts +0 -207
  151. package/lib/src/types/FineAmount.js +0 -238
  152. package/lib/src/types/FineTemplate.d.ts +0 -69
  153. package/lib/src/types/FineTemplate.js +0 -72
  154. package/lib/src/types/FineTemplateRepetition.d.ts +0 -87
  155. package/lib/src/types/FineTemplateRepetition.js +0 -103
  156. package/lib/src/types/Localization.js +0 -115
  157. package/lib/src/types/Team.d.ts +0 -62
  158. package/lib/src/types/Team.js +0 -64
  159. package/lib/src/types/User.d.ts +0 -221
  160. package/lib/src/types/User.js +0 -235
  161. package/lib/src/types/UserRole.d.ts +0 -29
  162. package/lib/test/firebase/FirebaseConfiguration.test.d.ts +0 -1
  163. package/lib/test/firebase/FirebaseConfiguration.test.js +0 -158
  164. package/lib/test/firebase/Firestore.test.d.ts +0 -1
  165. package/lib/test/firebase/Firestore.test.js +0 -46
  166. package/lib/test/firebase/checkAuthentication.test.d.ts +0 -1
  167. package/lib/test/firebase/checkAuthentication.test.js +0 -356
  168. package/lib/test/firebase/firebase-utils.d.ts +0 -32
  169. package/lib/test/firebase/firebase-utils.js +0 -134
  170. package/lib/test/firebase/pushNotification.test.d.ts +0 -1
  171. package/lib/test/firebase/pushNotification.test.js +0 -300
  172. package/lib/test/locales/localization.de.test.d.ts +0 -1
  173. package/lib/test/locales/localization.de.test.js +0 -144
  174. package/lib/test/locales/localization.en.test.d.ts +0 -1
  175. package/lib/test/locales/localization.en.test.js +0 -144
  176. package/lib/test/types/Configuration.test.d.ts +0 -1
  177. package/lib/test/types/Configuration.test.js +0 -84
  178. package/lib/test/types/Currency.test.d.ts +0 -1
  179. package/lib/test/types/Currency.test.js +0 -41
  180. package/lib/test/types/Fine.test.d.ts +0 -1
  181. package/lib/test/types/Fine.test.js +0 -265
  182. package/lib/test/types/FineAmount.test.d.ts +0 -1
  183. package/lib/test/types/FineAmount.test.js +0 -445
  184. package/lib/test/types/FineTemplate.test.d.ts +0 -1
  185. package/lib/test/types/FineTemplate.test.js +0 -271
  186. package/lib/test/types/FineTemplateRepetition.test.d.ts +0 -1
  187. package/lib/test/types/FineTemplateRepetition.test.js +0 -361
  188. package/lib/test/types/Invitation.test.d.ts +0 -1
  189. package/lib/test/types/Invitation.test.js +0 -269
  190. package/lib/test/types/Locale.test.d.ts +0 -1
  191. package/lib/test/types/Locale.test.js +0 -46
  192. package/lib/test/types/Localization.test.d.ts +0 -1
  193. package/lib/test/types/Localization.test.js +0 -241
  194. package/lib/test/types/MoneyAmount.test.d.ts +0 -1
  195. package/lib/test/types/MoneyAmount.test.js +0 -276
  196. package/lib/test/types/NotificationProperties.test.d.ts +0 -1
  197. package/lib/test/types/NotificationProperties.test.js +0 -258
  198. package/lib/test/types/PayedState.test.d.ts +0 -1
  199. package/lib/test/types/PayedState.test.js +0 -136
  200. package/lib/test/types/Person.test.d.ts +0 -1
  201. package/lib/test/types/Person.test.js +0 -266
  202. package/lib/test/types/PersonProperties.test.d.ts +0 -1
  203. package/lib/test/types/PersonProperties.test.js +0 -155
  204. package/lib/test/types/PersonSignInProperties.test.d.ts +0 -1
  205. package/lib/test/types/PersonSignInProperties.test.js +0 -208
  206. package/lib/test/types/Pluralization.test.d.ts +0 -1
  207. package/lib/test/types/Pluralization.test.js +0 -206
  208. package/lib/test/types/Team.test.d.ts +0 -1
  209. package/lib/test/types/Team.test.js +0 -145
  210. package/lib/test/types/User.test.d.ts +0 -1
  211. package/lib/test/types/User.test.js +0 -450
  212. package/lib/test/types/UserRole.test.d.ts +0 -1
  213. package/lib/test/types/UserRole.test.js +0 -140
  214. package/src/firebase/FirebaseConfiguration.ts +0 -99
  215. package/src/firebase/Firestore.ts +0 -258
  216. package/src/firebase/FirestoreScheme.ts +0 -41
  217. package/src/firebase/Messaging.ts +0 -93
  218. package/src/firebase/checkAuthentication.ts +0 -91
  219. package/src/firebase/index.ts +0 -7
  220. package/src/firebase/pushNotification.ts +0 -90
  221. package/src/functions/notification/subscribe.ts +0 -23
  222. package/src/types/Configuration.ts +0 -65
  223. package/src/types/Fine.ts +0 -100
  224. package/src/types/FineAmount.ts +0 -303
  225. package/src/types/FineTemplate.ts +0 -96
  226. package/src/types/FineTemplateRepetition.ts +0 -125
  227. package/src/types/Team.ts +0 -87
  228. package/src/types/User.ts +0 -302
  229. /package/lib/src/types/{Locale.d.ts → localization/Locale.d.ts} +0 -0
  230. /package/lib/src/types/{Locale.js → localization/Locale.js} +0 -0
  231. /package/src/types/{Locale.ts → localization/Locale.ts} +0 -0
@@ -1,201 +0,0 @@
1
- import { FirestoreBatch, FirestoreCollection, FirestoreDocument, UserAuthId } 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
- batch(): FirestoreBatch;
72
- /**
73
- * Gets a reference to a team document.
74
- *
75
- * @param id - The unique identifier of the team
76
- * @returns A typed Firestore document reference for the team
77
- *
78
- * @example
79
- * ```typescript
80
- * const teamDoc = Firestore.shared.team(teamId);
81
- * const teamData = await teamDoc.get();
82
- * ```
83
- */
84
- team(id: Team.Id): FirestoreDocument<Team>;
85
- userAuth(userAuthId: UserAuthId): FirestoreDocument<{
86
- userId: User.Id;
87
- }>;
88
- /**
89
- * Gets a reference to a user document.
90
- *
91
- * @param id - The unique identifier of the user
92
- * @returns A typed Firestore document reference for the user
93
- *
94
- * @example
95
- * ```typescript
96
- * const userDoc = Firestore.shared.user(userId);
97
- * const userData = await userDoc.get();
98
- * ```
99
- */
100
- user(id: User.Id): FirestoreDocument<User>;
101
- /**
102
- * Gets a reference to an invitation document.
103
- *
104
- * @param id - The unique identifier of the invitation
105
- * @returns A typed Firestore document reference for the invitation
106
- *
107
- * @example
108
- * ```typescript
109
- * const invitationDoc = Firestore.shared.invitation(invitationId);
110
- * const invitationData = await invitationDoc.get();
111
- * ```
112
- */
113
- invitation(id: Invitation.Id): FirestoreDocument<Invitation>;
114
- /**
115
- * Gets a reference to the persons collection within a team.
116
- *
117
- * @param teamId - The unique identifier of the team
118
- * @returns A typed Firestore collection reference for persons in the team
119
- *
120
- * @example
121
- * ```typescript
122
- * const personsCollection = Firestore.shared.persons(teamId);
123
- * const allPersons = await personsCollection.getAll();
124
- * ```
125
- */
126
- persons(teamId: Team.Id): FirestoreCollection<{
127
- [x: string]: FirestoreDocument<Person, never>;
128
- }>;
129
- /**
130
- * Gets a reference to a specific person document within a team.
131
- *
132
- * @param teamId - The unique identifier of the team
133
- * @param id - The unique identifier of the person
134
- * @returns A typed Firestore document reference for the person
135
- *
136
- * @example
137
- * ```typescript
138
- * const personDoc = Firestore.shared.person(teamId, personId);
139
- * const personData = await personDoc.get();
140
- * ```
141
- */
142
- person(teamId: Team.Id, id: Person.Id): FirestoreDocument<Person>;
143
- /**
144
- * Gets a reference to the fine templates collection within a team.
145
- *
146
- * @param teamId - The unique identifier of the team
147
- * @returns A typed Firestore collection reference for fine templates in the team
148
- *
149
- * @example
150
- * ```typescript
151
- * const templatesCollection = Firestore.shared.fineTemplates(teamId);
152
- * const allTemplates = await templatesCollection.getAll();
153
- * ```
154
- */
155
- fineTemplates(teamId: Team.Id): FirestoreCollection<{
156
- [x: string]: FirestoreDocument<FineTemplate, never>;
157
- }>;
158
- /**
159
- * Gets a reference to a specific fine template document within a team.
160
- *
161
- * @param teamId - The unique identifier of the team
162
- * @param id - The unique identifier of the fine template
163
- * @returns A typed Firestore document reference for the fine template
164
- *
165
- * @example
166
- * ```typescript
167
- * const templateDoc = Firestore.shared.fineTemplate(teamId, templateId);
168
- * const templateData = await templateDoc.get();
169
- * ```
170
- */
171
- fineTemplate(teamId: Team.Id, id: FineTemplate.Id): FirestoreDocument<FineTemplate>;
172
- /**
173
- * Gets a reference to the fines collection within a team.
174
- *
175
- * @param teamId - The unique identifier of the team
176
- * @returns A typed Firestore collection reference for fines in the team
177
- *
178
- * @example
179
- * ```typescript
180
- * const finesCollection = Firestore.shared.fines(teamId);
181
- * const allFines = await finesCollection.getAll();
182
- * ```
183
- */
184
- fines(teamId: Team.Id): FirestoreCollection<{
185
- [x: string]: FirestoreDocument<Fine, never>;
186
- }>;
187
- /**
188
- * Gets a reference to a specific fine document within a team.
189
- *
190
- * @param teamId - The unique identifier of the team
191
- * @param id - The unique identifier of the fine
192
- * @returns A typed Firestore document reference for the fine
193
- *
194
- * @example
195
- * ```typescript
196
- * const fineDoc = Firestore.shared.fine(teamId, fineId);
197
- * const fineData = await fineDoc.get();
198
- * ```
199
- */
200
- fine(teamId: Team.Id, id: Fine.Id): FirestoreDocument<Fine>;
201
- }
@@ -1,244 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Firestore = void 0;
4
- const firebase_function_1 = require("@stevenkellner/firebase-function");
5
- const _1 = require(".");
6
- /**
7
- * Accessor class for Firestore documents and collections.
8
- *
9
- * Provides type-safe access to Firestore database documents and collections
10
- * following the schema defined in {@link FirestoreScheme}.
11
- *
12
- * Uses a singleton pattern to ensure consistent access to the Firestore instance.
13
- * All methods return strongly-typed Firestore references that can be used for
14
- * database operations.
15
- *
16
- * @example
17
- * ```typescript
18
- * // Access a team document
19
- * const teamDoc = Firestore.shared.team(teamId);
20
- *
21
- * // Access a person in a team
22
- * const personDoc = Firestore.shared.person(teamId, personId);
23
- *
24
- * // Access all fines in a team
25
- * const finesCollection = Firestore.shared.fines(teamId);
26
- * ```
27
- *
28
- * @remarks
29
- * Requires {@link FirebaseConfiguration} to be configured before use.
30
- * All document and collection references are lazy and don't perform any
31
- * database operations until explicitly called.
32
- */
33
- class Firestore {
34
- /**
35
- * Protected constructor to enforce singleton pattern.
36
- * Use {@link Firestore.shared} to get an instance.
37
- */
38
- constructor() { }
39
- /**
40
- * The singleton instance of the Firestore accessor.
41
- *
42
- * @private
43
- */
44
- static sharedInstance = null;
45
- /**
46
- * Gets the singleton instance of the Firestore accessor.
47
- *
48
- * Creates the instance on first access and returns the same instance
49
- * on subsequent calls.
50
- *
51
- * @returns The singleton Firestore accessor instance
52
- *
53
- * @example
54
- * ```typescript
55
- * const firestore = Firestore.shared;
56
- * const teamDoc = firestore.team(teamId);
57
- * ```
58
- */
59
- static get shared() {
60
- if (!Firestore.sharedInstance)
61
- Firestore.sharedInstance = new Firestore();
62
- return Firestore.sharedInstance;
63
- }
64
- /**
65
- * Gets the base Firestore schema from the configured Firebase instance.
66
- *
67
- * Accesses the global FirebaseConfiguration to retrieve the root document
68
- * reference for all database operations.
69
- *
70
- * @returns The base Firestore schema with typed collections
71
- *
72
- * @throws {Error} If FirebaseConfiguration has not been configured
73
- *
74
- * @private
75
- */
76
- get base() {
77
- return _1.FirebaseConfiguration.shared.baseFirestoreDocument;
78
- }
79
- batch() {
80
- return new firebase_function_1.FirestoreBatch(_1.FirebaseConfiguration.shared.firebaseFirestore);
81
- }
82
- /**
83
- * Gets a reference to a team document.
84
- *
85
- * @param id - The unique identifier of the team
86
- * @returns A typed Firestore document reference for the team
87
- *
88
- * @example
89
- * ```typescript
90
- * const teamDoc = Firestore.shared.team(teamId);
91
- * const teamData = await teamDoc.get();
92
- * ```
93
- */
94
- team(id) {
95
- return this.base
96
- .collection('teams')
97
- .document(id.guidString);
98
- }
99
- userAuth(userAuthId) {
100
- return this.base
101
- .collection('userAuthIdDict')
102
- .document(userAuthId.value);
103
- }
104
- /**
105
- * Gets a reference to a user document.
106
- *
107
- * @param id - The unique identifier of the user
108
- * @returns A typed Firestore document reference for the user
109
- *
110
- * @example
111
- * ```typescript
112
- * const userDoc = Firestore.shared.user(userId);
113
- * const userData = await userDoc.get();
114
- * ```
115
- */
116
- user(id) {
117
- return this.base
118
- .collection('users')
119
- .document(id.value);
120
- }
121
- /**
122
- * Gets a reference to an invitation document.
123
- *
124
- * @param id - The unique identifier of the invitation
125
- * @returns A typed Firestore document reference for the invitation
126
- *
127
- * @example
128
- * ```typescript
129
- * const invitationDoc = Firestore.shared.invitation(invitationId);
130
- * const invitationData = await invitationDoc.get();
131
- * ```
132
- */
133
- invitation(id) {
134
- return this.base
135
- .collection('invitations')
136
- .document(id.value);
137
- }
138
- /**
139
- * Gets a reference to the persons collection within a team.
140
- *
141
- * @param teamId - The unique identifier of the team
142
- * @returns A typed Firestore collection reference for persons in the team
143
- *
144
- * @example
145
- * ```typescript
146
- * const personsCollection = Firestore.shared.persons(teamId);
147
- * const allPersons = await personsCollection.getAll();
148
- * ```
149
- */
150
- persons(teamId) {
151
- return this.base
152
- .collection('teams')
153
- .document(teamId.guidString)
154
- .collection('persons');
155
- }
156
- /**
157
- * Gets a reference to a specific person document within a team.
158
- *
159
- * @param teamId - The unique identifier of the team
160
- * @param id - The unique identifier of the person
161
- * @returns A typed Firestore document reference for the person
162
- *
163
- * @example
164
- * ```typescript
165
- * const personDoc = Firestore.shared.person(teamId, personId);
166
- * const personData = await personDoc.get();
167
- * ```
168
- */
169
- person(teamId, id) {
170
- return this.persons(teamId)
171
- .document(id.guidString);
172
- }
173
- /**
174
- * Gets a reference to the fine templates collection within a team.
175
- *
176
- * @param teamId - The unique identifier of the team
177
- * @returns A typed Firestore collection reference for fine templates in the team
178
- *
179
- * @example
180
- * ```typescript
181
- * const templatesCollection = Firestore.shared.fineTemplates(teamId);
182
- * const allTemplates = await templatesCollection.getAll();
183
- * ```
184
- */
185
- fineTemplates(teamId) {
186
- return this.base
187
- .collection('teams')
188
- .document(teamId.guidString)
189
- .collection('fineTemplates');
190
- }
191
- /**
192
- * Gets a reference to a specific fine template document within a team.
193
- *
194
- * @param teamId - The unique identifier of the team
195
- * @param id - The unique identifier of the fine template
196
- * @returns A typed Firestore document reference for the fine template
197
- *
198
- * @example
199
- * ```typescript
200
- * const templateDoc = Firestore.shared.fineTemplate(teamId, templateId);
201
- * const templateData = await templateDoc.get();
202
- * ```
203
- */
204
- fineTemplate(teamId, id) {
205
- return this.fineTemplates(teamId)
206
- .document(id.guidString);
207
- }
208
- /**
209
- * Gets a reference to the fines collection within a team.
210
- *
211
- * @param teamId - The unique identifier of the team
212
- * @returns A typed Firestore collection reference for fines in the team
213
- *
214
- * @example
215
- * ```typescript
216
- * const finesCollection = Firestore.shared.fines(teamId);
217
- * const allFines = await finesCollection.getAll();
218
- * ```
219
- */
220
- fines(teamId) {
221
- return this.base
222
- .collection('teams')
223
- .document(teamId.guidString)
224
- .collection('fines');
225
- }
226
- /**
227
- * Gets a reference to a specific fine document within a team.
228
- *
229
- * @param teamId - The unique identifier of the team
230
- * @param id - The unique identifier of the fine
231
- * @returns A typed Firestore document reference for the fine
232
- *
233
- * @example
234
- * ```typescript
235
- * const fineDoc = Firestore.shared.fine(teamId, fineId);
236
- * const fineData = await fineDoc.get();
237
- * ```
238
- */
239
- fine(teamId, id) {
240
- return this.fines(teamId)
241
- .document(id.guidString);
242
- }
243
- }
244
- exports.Firestore = Firestore;
@@ -1,42 +0,0 @@
1
- import { FirestoreCollection, FirestoreDocument } from '@stevenkellner/firebase-function';
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
- */
17
- export type FirestoreScheme = FirestoreDocument<never, {
18
- userAuthIdDict: FirestoreCollection<{
19
- [UserAuthId in string]: FirestoreDocument<{
20
- userId: User.Id;
21
- }>;
22
- }>;
23
- users: FirestoreCollection<{
24
- [UserId in string]: FirestoreDocument<User>;
25
- }>;
26
- invitations: FirestoreCollection<{
27
- [InvitationId in string]: FirestoreDocument<Invitation>;
28
- }>;
29
- teams: FirestoreCollection<{
30
- [TeamId in string]: FirestoreDocument<Team, {
31
- persons: FirestoreCollection<{
32
- [PersonId in string]: FirestoreDocument<Person>;
33
- }>;
34
- fineTemplates: FirestoreCollection<{
35
- [PersonId in string]: FirestoreDocument<FineTemplate>;
36
- }>;
37
- fines: FirestoreCollection<{
38
- [PersonId in string]: FirestoreDocument<Fine>;
39
- }>;
40
- }>;
41
- }>;
42
- }>;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,90 +0,0 @@
1
- /**
2
- * Represents a notification payload for Firebase Cloud Messaging.
3
- */
4
- export interface Notification {
5
- /**
6
- * The notification title.
7
- */
8
- title?: string;
9
- /**
10
- * The notification body text.
11
- */
12
- body?: string;
13
- /**
14
- * URL of an image to be displayed in the notification.
15
- */
16
- imageUrl?: string;
17
- }
18
- /**
19
- * Response from sending batch messages to multiple devices.
20
- */
21
- export interface BatchResponse {
22
- /**
23
- * Array of individual message responses.
24
- */
25
- responses: {
26
- /**
27
- * Whether the message was sent successfully.
28
- */
29
- success: boolean;
30
- /**
31
- * The message ID if successful.
32
- */
33
- messageId?: string;
34
- /**
35
- * Error information if the message failed to send.
36
- */
37
- error?: {
38
- /**
39
- * Error code identifier.
40
- */
41
- code: string;
42
- /**
43
- * Human-readable error message.
44
- */
45
- message: string;
46
- /**
47
- * Optional stack trace for debugging.
48
- */
49
- stack?: string;
50
- /**
51
- * Converts the error to a JSON object.
52
- */
53
- toJSON(): object;
54
- };
55
- }[];
56
- /**
57
- * Number of messages sent successfully.
58
- */
59
- successCount: number;
60
- /**
61
- * Number of messages that failed to send.
62
- */
63
- failureCount: number;
64
- }
65
- /**
66
- * Message to be sent to multiple device tokens.
67
- */
68
- export interface MulticastMessage {
69
- /**
70
- * Array of device registration tokens to send the message to.
71
- */
72
- tokens: string[];
73
- /**
74
- * Optional notification payload to include in the message.
75
- */
76
- notification?: Notification;
77
- }
78
- /**
79
- * Firebase Cloud Messaging service interface.
80
- */
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
- */
89
- sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;
90
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,38 +0,0 @@
1
- import { UserAuthId } from '@stevenkellner/firebase-function';
2
- import { Team, User, UserRole } from '../types';
3
- /**
4
- * Type representing expected user role requirements.
5
- *
6
- * Can be:
7
- * - A single `UserRole` (user must have this role)
8
- * - An array of `ExpectedUserRoles` (user must satisfy ALL requirements - logical AND)
9
- * - An object with `anyOf` property (user must satisfy AT LEAST ONE requirement - logical OR)
10
- *
11
- * Examples:
12
- * - `'admin'` - User must be admin
13
- * - `['member', 'treasurer']` - User must be both member AND treasurer
14
- * - `{ anyOf: ['admin', 'treasurer'] }` - User must be admin OR treasurer
15
- */
16
- type ExpectedUserRoles = UserRole | ExpectedUserRoles[] | {
17
- anyOf: ExpectedUserRoles[];
18
- };
19
- /**
20
- * Validates that a user is authenticated and has the required roles for a specific team.
21
- *
22
- * Performs comprehensive authentication checks:
23
- * 1. Verifies the user is authenticated (rawUserId is not null)
24
- * 2. Checks that the user exists in the database
25
- * 3. Confirms the user is a member of the specified team
26
- * 4. Validates that the person associated with the user exists
27
- * 5. Ensures the person is signed in (has signInProperties)
28
- * 6. Verifies the person has the required roles
29
- *
30
- * @param userAuthId - The raw user authentication ID string from authentication context (null if not authenticated)
31
- * @param teamId - The ID of the team to check membership and roles for
32
- * @param roles - The expected role requirements (supports AND/OR logic via ExpectedUserRoles)
33
- * @returns The validated User.Id if all checks pass
34
- * @throws {FunctionsError} 'unauthenticated' - If rawUserId is null
35
- * @throws {FunctionsError} 'permission-denied' - If any validation check fails
36
- */
37
- export declare function checkAuthentication(userAuthId: UserAuthId | null, teamId: Team.Id, roles: ExpectedUserRoles): Promise<User.Id>;
38
- export {};
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkAuthentication = checkAuthentication;
4
- const firebase_function_1 = require("@stevenkellner/firebase-function");
5
- const types_1 = require("../types");
6
- const Firestore_1 = require("./Firestore");
7
- /**
8
- * Checks if the user has the required roles according to the expected role requirements.
9
- *
10
- * @param userRoles - Array of roles the user currently has
11
- * @param expectedRoles - The role requirements to check against (supports AND/OR logic)
12
- * @returns `true` if the user satisfies the role requirements, `false` otherwise
13
- */
14
- function hasUserRoles(userRoles, expectedRoles) {
15
- if (Array.isArray(expectedRoles))
16
- return expectedRoles.every(expectedRole => hasUserRoles(userRoles, expectedRole));
17
- else if (typeof expectedRoles === 'object' && 'anyOf' in expectedRoles)
18
- return expectedRoles.anyOf.some(role => hasUserRoles(userRoles, role));
19
- else
20
- return userRoles.includes(expectedRoles);
21
- }
22
- /**
23
- * Validates that a user is authenticated and has the required roles for a specific team.
24
- *
25
- * Performs comprehensive authentication checks:
26
- * 1. Verifies the user is authenticated (rawUserId is not null)
27
- * 2. Checks that the user exists in the database
28
- * 3. Confirms the user is a member of the specified team
29
- * 4. Validates that the person associated with the user exists
30
- * 5. Ensures the person is signed in (has signInProperties)
31
- * 6. Verifies the person has the required roles
32
- *
33
- * @param userAuthId - The raw user authentication ID string from authentication context (null if not authenticated)
34
- * @param teamId - The ID of the team to check membership and roles for
35
- * @param roles - The expected role requirements (supports AND/OR logic via ExpectedUserRoles)
36
- * @returns The validated User.Id if all checks pass
37
- * @throws {FunctionsError} 'unauthenticated' - If rawUserId is null
38
- * @throws {FunctionsError} 'permission-denied' - If any validation check fails
39
- */
40
- async function checkAuthentication(userAuthId, teamId, roles) {
41
- if (userAuthId === null)
42
- throw new firebase_function_1.FunctionsError('unauthenticated', 'User is not authenticated');
43
- const userAuthSnapshot = await Firestore_1.Firestore.shared.userAuth(userAuthId).snapshot();
44
- if (!userAuthSnapshot.exists)
45
- throw new firebase_function_1.FunctionsError('permission-denied', 'User authentication does not exist');
46
- const userId = types_1.User.Id.builder.build(userAuthSnapshot.data.userId);
47
- const userSnapshot = await Firestore_1.Firestore.shared.user(userId).snapshot();
48
- if (!userSnapshot.exists)
49
- throw new firebase_function_1.FunctionsError('permission-denied', 'User does not exist');
50
- const user = types_1.User.builder.build(userSnapshot.data);
51
- if (!user.teams.has(teamId))
52
- throw new firebase_function_1.FunctionsError('permission-denied', 'User is not a member of the team');
53
- const team = user.teams.get(teamId);
54
- const personSnapshot = await Firestore_1.Firestore.shared.person(teamId, team.personId).snapshot();
55
- if (!personSnapshot.exists)
56
- throw new firebase_function_1.FunctionsError('permission-denied', 'Person does not exist');
57
- const person = types_1.Person.builder.build(personSnapshot.data);
58
- if (person.signInProperties === null)
59
- throw new firebase_function_1.FunctionsError('permission-denied', 'Person is not signed in');
60
- const userHasRoles = hasUserRoles(person.signInProperties.roles, roles);
61
- if (!userHasRoles)
62
- throw new firebase_function_1.FunctionsError('permission-denied', 'User does not have the required roles');
63
- return userId;
64
- }
@@ -1,6 +0,0 @@
1
- export * from './FirebaseConfiguration';
2
- export * from './Messaging';
3
- export * from './checkAuthentication';
4
- export * from './Firestore';
5
- export * from './FirestoreScheme';
6
- export * from './pushNotification';