@tmlmobilidade/interfaces 20251103.1255.55 → 20251202.1821.43

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 (153) hide show
  1. package/dist/{src → common}/enrich-user-refs.js +1 -2
  2. package/dist/common/index.d.ts +4 -0
  3. package/dist/common/index.js +4 -0
  4. package/dist/{src → common}/mongo-collection.d.ts +3 -3
  5. package/dist/{src → common}/mongo-collection.js +4 -3
  6. package/dist/{src → common}/mongo-transaction.d.ts +1 -1
  7. package/dist/index.d.ts +3 -6
  8. package/dist/index.js +3 -6
  9. package/dist/{src/interfaces → interfaces}/agencies/agencies.d.ts +3 -3
  10. package/dist/{src/interfaces → interfaces}/agencies/agencies.js +1 -1
  11. package/dist/{src/interfaces → interfaces}/alerts/alerts.d.ts +42 -4
  12. package/dist/{src/interfaces → interfaces}/alerts/alerts.js +4 -1
  13. package/dist/interfaces/alerts/index.d.ts +1 -0
  14. package/dist/interfaces/alerts/index.js +1 -0
  15. package/dist/interfaces/auth/roles.d.ts +240 -0
  16. package/dist/interfaces/auth/roles.js +69 -0
  17. package/dist/{src/interfaces → interfaces}/auth/sessions.d.ts +1 -1
  18. package/dist/{src/interfaces → interfaces}/auth/sessions.js +1 -1
  19. package/dist/interfaces/auth/users.d.ts +522 -0
  20. package/dist/interfaces/auth/users.js +118 -0
  21. package/dist/{src/interfaces → interfaces}/auth/verification-tokens.d.ts +2 -2
  22. package/dist/{src/interfaces → interfaces}/auth/verification-tokens.js +1 -1
  23. package/dist/{src/interfaces → interfaces}/file-exports/file-exports.d.ts +1 -1
  24. package/dist/{src/interfaces → interfaces}/file-exports/file-exports.js +2 -2
  25. package/dist/{src/interfaces → interfaces}/files/files.d.ts +1 -1
  26. package/dist/{src/interfaces → interfaces}/files/files.js +6 -36
  27. package/dist/{src/interfaces → interfaces}/gtfs-validations/gtfs-validations.d.ts +3 -3
  28. package/dist/{src/interfaces → interfaces}/gtfs-validations/gtfs-validations.js +1 -1
  29. package/dist/{src/interfaces → interfaces}/index.d.ts +1 -0
  30. package/dist/{src/interfaces → interfaces}/index.js +1 -0
  31. package/dist/interfaces/locations/index.d.ts +2 -0
  32. package/dist/interfaces/locations/index.js +2 -0
  33. package/dist/{src/interfaces → interfaces}/locations/locations.d.ts +17 -17
  34. package/dist/{src/interfaces → interfaces}/locations/locations.js +3 -3
  35. package/dist/interfaces/locations/municipalities.d.ts +13 -0
  36. package/dist/interfaces/locations/municipalities.js +29 -0
  37. package/dist/{src/interfaces → interfaces}/metrics/metrics.d.ts +1 -1
  38. package/dist/{src/interfaces → interfaces}/metrics/metrics.js +1 -1
  39. package/dist/{src/interfaces → interfaces}/notifications/notifications.d.ts +1 -1
  40. package/dist/{src/interfaces → interfaces}/notifications/notifications.js +5 -5
  41. package/dist/{src/interfaces → interfaces}/organizations/organizations.d.ts +1 -1
  42. package/dist/{src/interfaces → interfaces}/organizations/organizations.js +3 -3
  43. package/dist/interfaces/pcgidb/index.d.ts +3 -0
  44. package/dist/interfaces/pcgidb/index.js +3 -0
  45. package/dist/interfaces/pcgidb/pcgidb-legacy.d.ts +19 -0
  46. package/dist/interfaces/pcgidb/pcgidb-legacy.js +133 -0
  47. package/dist/interfaces/pcgidb/pcgidb-ticketing.d.ts +16 -0
  48. package/dist/interfaces/pcgidb/pcgidb-ticketing.js +127 -0
  49. package/dist/interfaces/pcgidb/pcgidb-validations.d.ts +17 -0
  50. package/dist/interfaces/pcgidb/pcgidb-validations.js +129 -0
  51. package/dist/{src/interfaces → interfaces}/plans/plans.d.ts +12 -6
  52. package/dist/{src/interfaces → interfaces}/plans/plans.js +1 -1
  53. package/dist/{src/interfaces → interfaces}/proposed-changes/proposed-changes.d.ts +1 -1
  54. package/dist/{src/interfaces → interfaces}/proposed-changes/proposed-changes.js +1 -1
  55. package/dist/{src/interfaces → interfaces}/rides/hashed-shapes.d.ts +1 -1
  56. package/dist/{src/interfaces → interfaces}/rides/hashed-shapes.js +1 -1
  57. package/dist/{src/interfaces → interfaces}/rides/hashed-trips.d.ts +1 -1
  58. package/dist/{src/interfaces → interfaces}/rides/hashed-trips.js +1 -1
  59. package/dist/{src/interfaces → interfaces}/rides/pipelines.d.ts +9 -9
  60. package/dist/{src/interfaces → interfaces}/rides/pipelines.js +20 -2
  61. package/dist/{src/interfaces → interfaces}/rides/ride-acceptances.d.ts +1 -1
  62. package/dist/{src/interfaces → interfaces}/rides/ride-acceptances.js +4 -3
  63. package/dist/{src/interfaces → interfaces}/rides/rides.d.ts +313 -313
  64. package/dist/{src/interfaces → interfaces}/rides/rides.js +1 -1
  65. package/dist/{src/interfaces → interfaces}/sams/sams.d.ts +1 -1
  66. package/dist/{src/interfaces → interfaces}/sams/sams.js +1 -1
  67. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspection-decisions.d.ts +1 -1
  68. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspection-decisions.js +1 -1
  69. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspections.d.ts +1 -1
  70. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-inspections.js +1 -1
  71. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-locations.d.ts +1 -1
  72. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-locations.js +1 -1
  73. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-refunds.d.ts +1 -1
  74. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-refunds.js +1 -1
  75. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-sales.d.ts +1 -1
  76. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-on-board-sales.js +1 -1
  77. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-validations.d.ts +1 -1
  78. package/dist/{src/interfaces → interfaces}/simplified-apex/simplified-apex-validations.js +1 -1
  79. package/dist/{src/interfaces → interfaces}/stops/stops.d.ts +7 -7
  80. package/dist/{src/interfaces → interfaces}/stops/stops.js +1 -1
  81. package/dist/interfaces/vehicle-events/index.d.ts +1 -0
  82. package/dist/interfaces/vehicle-events/index.js +1 -0
  83. package/dist/interfaces/vehicle-events/simplified-vehicle-events.d.ts +13 -0
  84. package/dist/interfaces/vehicle-events/simplified-vehicle-events.js +33 -0
  85. package/dist/{src/interfaces → interfaces}/zones/zones.d.ts +3 -3
  86. package/dist/{src/interfaces → interfaces}/zones/zones.js +1 -1
  87. package/dist/{src/providers → providers}/auth/auth.d.ts +21 -12
  88. package/dist/{src/providers → providers}/auth/auth.js +71 -60
  89. package/dist/providers/auth/index.d.ts +1 -0
  90. package/dist/providers/auth/index.js +1 -0
  91. package/dist/providers/index.d.ts +2 -0
  92. package/dist/providers/index.js +2 -0
  93. package/dist/providers/storage/index.d.ts +3 -0
  94. package/dist/providers/storage/index.js +3 -0
  95. package/dist/{src/providers → providers}/storage/oci-storage.js +2 -1
  96. package/dist/{src/providers → providers}/storage/storage.factory.d.ts +2 -11
  97. package/dist/{src/providers → providers}/storage/storage.factory.js +0 -5
  98. package/package.json +25 -26
  99. package/dist/src/interfaces/alerts/alerts-realtime.d.ts +0 -86
  100. package/dist/src/interfaces/alerts/alerts-realtime.js +0 -47
  101. package/dist/src/interfaces/alerts/index.d.ts +0 -2
  102. package/dist/src/interfaces/alerts/index.js +0 -2
  103. package/dist/src/interfaces/auth/roles.d.ts +0 -39
  104. package/dist/src/interfaces/auth/roles.js +0 -42
  105. package/dist/src/interfaces/auth/users.d.ts +0 -107
  106. package/dist/src/interfaces/auth/users.js +0 -110
  107. package/dist/src/interfaces/locations/index.d.ts +0 -1
  108. package/dist/src/interfaces/locations/index.js +0 -1
  109. package/dist/src/interfaces/vehicle-events/index.d.ts +0 -1
  110. package/dist/src/interfaces/vehicle-events/index.js +0 -1
  111. package/dist/src/interfaces/vehicle-events/vehicle-events.d.ts +0 -13
  112. package/dist/src/interfaces/vehicle-events/vehicle-events.js +0 -37
  113. package/dist/src/providers/index.d.ts +0 -5
  114. package/dist/src/providers/index.js +0 -6
  115. package/dist/src/providers/storage/s3-storage.d.ts +0 -64
  116. package/dist/src/providers/storage/s3-storage.js +0 -184
  117. /package/dist/{src → common}/aggregation-pipeline.d.ts +0 -0
  118. /package/dist/{src → common}/aggregation-pipeline.js +0 -0
  119. /package/dist/{src → common}/enrich-user-refs.d.ts +0 -0
  120. /package/dist/{src → common}/mongo-transaction.js +0 -0
  121. /package/dist/{src/interfaces → interfaces}/agencies/index.d.ts +0 -0
  122. /package/dist/{src/interfaces → interfaces}/agencies/index.js +0 -0
  123. /package/dist/{src/interfaces → interfaces}/auth/index.d.ts +0 -0
  124. /package/dist/{src/interfaces → interfaces}/auth/index.js +0 -0
  125. /package/dist/{src/interfaces → interfaces}/file-exports/index.d.ts +0 -0
  126. /package/dist/{src/interfaces → interfaces}/file-exports/index.js +0 -0
  127. /package/dist/{src/interfaces → interfaces}/files/index.d.ts +0 -0
  128. /package/dist/{src/interfaces → interfaces}/files/index.js +0 -0
  129. /package/dist/{src/interfaces → interfaces}/gtfs-validations/index.d.ts +0 -0
  130. /package/dist/{src/interfaces → interfaces}/gtfs-validations/index.js +0 -0
  131. /package/dist/{src/interfaces → interfaces}/metrics/index.d.ts +0 -0
  132. /package/dist/{src/interfaces → interfaces}/metrics/index.js +0 -0
  133. /package/dist/{src/interfaces → interfaces}/notifications/index.d.ts +0 -0
  134. /package/dist/{src/interfaces → interfaces}/notifications/index.js +0 -0
  135. /package/dist/{src/interfaces → interfaces}/organizations/index.d.ts +0 -0
  136. /package/dist/{src/interfaces → interfaces}/organizations/index.js +0 -0
  137. /package/dist/{src/interfaces → interfaces}/plans/index.d.ts +0 -0
  138. /package/dist/{src/interfaces → interfaces}/plans/index.js +0 -0
  139. /package/dist/{src/interfaces → interfaces}/proposed-changes/index.d.ts +0 -0
  140. /package/dist/{src/interfaces → interfaces}/proposed-changes/index.js +0 -0
  141. /package/dist/{src/interfaces → interfaces}/rides/index.d.ts +0 -0
  142. /package/dist/{src/interfaces → interfaces}/rides/index.js +0 -0
  143. /package/dist/{src/interfaces → interfaces}/sams/index.d.ts +0 -0
  144. /package/dist/{src/interfaces → interfaces}/sams/index.js +0 -0
  145. /package/dist/{src/interfaces → interfaces}/simplified-apex/index.d.ts +0 -0
  146. /package/dist/{src/interfaces → interfaces}/simplified-apex/index.js +0 -0
  147. /package/dist/{src/interfaces → interfaces}/stops/index.d.ts +0 -0
  148. /package/dist/{src/interfaces → interfaces}/stops/index.js +0 -0
  149. /package/dist/{src/interfaces → interfaces}/zones/index.d.ts +0 -0
  150. /package/dist/{src/interfaces → interfaces}/zones/index.js +0 -0
  151. /package/dist/{src/providers → providers}/storage/oci-storage.d.ts +0 -0
  152. /package/dist/{src/providers → providers}/storage/storage.interface.d.ts +0 -0
  153. /package/dist/{src/providers → providers}/storage/storage.interface.js +0 -0
@@ -0,0 +1,522 @@
1
+ import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
+ import { type CreateUserDto, type UpdateUserDto, type User } from '@tmlmobilidade/types';
3
+ import { type Filter, type FindOptions, type IndexDescription } from 'mongodb';
4
+ import { z } from 'zod';
5
+ declare class UsersClass extends MongoCollectionClass<User, CreateUserDto, UpdateUserDto> {
6
+ private static _instance;
7
+ protected createSchema: z.ZodSchema;
8
+ protected updateSchema: z.ZodSchema;
9
+ private constructor();
10
+ static getInstance(): Promise<UsersClass>;
11
+ /**
12
+ * Finds a user document by its email.
13
+ * @param email The email of the user to find.
14
+ * @param includePasswordHash - Whether to include the password hash in the result.
15
+ * @returns A promise that resolves to the matching user document or null if not found.
16
+ */
17
+ findByEmail(email: string, includePasswordHash?: boolean): Promise<{
18
+ password_hash: any;
19
+ permissions: ({
20
+ scope: "agencies";
21
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
22
+ } | {
23
+ scope: "alerts_scheduled";
24
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
25
+ } | {
26
+ scope: "alerts_realtime";
27
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
28
+ resources: {
29
+ agency_ids: string[];
30
+ };
31
+ } | {
32
+ scope: "rides";
33
+ action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update";
34
+ resources: {
35
+ agency_ids: string[];
36
+ };
37
+ } | {
38
+ scope: "sams";
39
+ action: "read";
40
+ } | {
41
+ scope: "gtfs_validations";
42
+ action: "create" | "read" | "request_approval";
43
+ resources: {
44
+ agency_ids: string[];
45
+ };
46
+ } | {
47
+ scope: "home";
48
+ action: "read_links" | "read_wiki";
49
+ } | {
50
+ scope: "organizations";
51
+ action: "create" | "update" | "delete" | "read";
52
+ } | {
53
+ scope: "performance";
54
+ action: "read";
55
+ } | {
56
+ scope: "plans";
57
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
58
+ resources: {
59
+ agency_ids: string[];
60
+ };
61
+ } | {
62
+ scope: "roles";
63
+ action: "create" | "update" | "delete" | "read";
64
+ } | {
65
+ scope: "stops";
66
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
67
+ resources: {
68
+ municipality_ids: string[];
69
+ agency_ids: string[];
70
+ };
71
+ } | {
72
+ scope: "users";
73
+ action: "create" | "update" | "delete" | "read";
74
+ })[];
75
+ created_at: number & {
76
+ __brand: "UnixTimestamp";
77
+ };
78
+ created_by?: string | undefined;
79
+ updated_at: number & {
80
+ __brand: "UnixTimestamp";
81
+ };
82
+ updated_by?: string | undefined;
83
+ email: string;
84
+ email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
85
+ first_name: string;
86
+ last_name: string;
87
+ organization_id: string | null;
88
+ phone: string | null;
89
+ preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
90
+ role_ids: string[];
91
+ session_ids: string[];
92
+ verification_token_ids: string[];
93
+ _id: string;
94
+ }>;
95
+ /**
96
+ * Finds a user document by its ID.
97
+ * @param id The ID of the user document to find
98
+ * @param includePasswordHash Whether to include the password hash in the result
99
+ * @returns A promise that resolves to the matching user document or null if not found
100
+ */
101
+ findById(id: string, options?: FindOptions, includePasswordHash?: boolean): Promise<{
102
+ password_hash: any;
103
+ permissions: ({
104
+ scope: "agencies";
105
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
106
+ } | {
107
+ scope: "alerts_scheduled";
108
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
109
+ } | {
110
+ scope: "alerts_realtime";
111
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
112
+ resources: {
113
+ agency_ids: string[];
114
+ };
115
+ } | {
116
+ scope: "rides";
117
+ action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update";
118
+ resources: {
119
+ agency_ids: string[];
120
+ };
121
+ } | {
122
+ scope: "sams";
123
+ action: "read";
124
+ } | {
125
+ scope: "gtfs_validations";
126
+ action: "create" | "read" | "request_approval";
127
+ resources: {
128
+ agency_ids: string[];
129
+ };
130
+ } | {
131
+ scope: "home";
132
+ action: "read_links" | "read_wiki";
133
+ } | {
134
+ scope: "organizations";
135
+ action: "create" | "update" | "delete" | "read";
136
+ } | {
137
+ scope: "performance";
138
+ action: "read";
139
+ } | {
140
+ scope: "plans";
141
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
142
+ resources: {
143
+ agency_ids: string[];
144
+ };
145
+ } | {
146
+ scope: "roles";
147
+ action: "create" | "update" | "delete" | "read";
148
+ } | {
149
+ scope: "stops";
150
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
151
+ resources: {
152
+ municipality_ids: string[];
153
+ agency_ids: string[];
154
+ };
155
+ } | {
156
+ scope: "users";
157
+ action: "create" | "update" | "delete" | "read";
158
+ })[];
159
+ created_at: number & {
160
+ __brand: "UnixTimestamp";
161
+ };
162
+ created_by?: string | undefined;
163
+ updated_at: number & {
164
+ __brand: "UnixTimestamp";
165
+ };
166
+ updated_by?: string | undefined;
167
+ email: string;
168
+ email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
169
+ first_name: string;
170
+ last_name: string;
171
+ organization_id: string | null;
172
+ phone: string | null;
173
+ preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
174
+ role_ids: string[];
175
+ session_ids: string[];
176
+ verification_token_ids: string[];
177
+ _id: string;
178
+ }>;
179
+ /**
180
+ * Finds users by their organization code.
181
+ * @param code The code of the organization to find users for.
182
+ * @param includePasswordHash Whether to include the password hash in the result.
183
+ * @returns A promise that resolves to the matching user documents or null if not found.
184
+ */
185
+ findByOrganization(id: string, includePasswordHash?: boolean): Promise<{
186
+ password_hash: any;
187
+ permissions: ({
188
+ scope: "agencies";
189
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
190
+ } | {
191
+ scope: "alerts_scheduled";
192
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
193
+ } | {
194
+ scope: "alerts_realtime";
195
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
196
+ resources: {
197
+ agency_ids: string[];
198
+ };
199
+ } | {
200
+ scope: "rides";
201
+ action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update";
202
+ resources: {
203
+ agency_ids: string[];
204
+ };
205
+ } | {
206
+ scope: "sams";
207
+ action: "read";
208
+ } | {
209
+ scope: "gtfs_validations";
210
+ action: "create" | "read" | "request_approval";
211
+ resources: {
212
+ agency_ids: string[];
213
+ };
214
+ } | {
215
+ scope: "home";
216
+ action: "read_links" | "read_wiki";
217
+ } | {
218
+ scope: "organizations";
219
+ action: "create" | "update" | "delete" | "read";
220
+ } | {
221
+ scope: "performance";
222
+ action: "read";
223
+ } | {
224
+ scope: "plans";
225
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
226
+ resources: {
227
+ agency_ids: string[];
228
+ };
229
+ } | {
230
+ scope: "roles";
231
+ action: "create" | "update" | "delete" | "read";
232
+ } | {
233
+ scope: "stops";
234
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
235
+ resources: {
236
+ municipality_ids: string[];
237
+ agency_ids: string[];
238
+ };
239
+ } | {
240
+ scope: "users";
241
+ action: "create" | "update" | "delete" | "read";
242
+ })[];
243
+ created_at: number & {
244
+ __brand: "UnixTimestamp";
245
+ };
246
+ created_by?: string | undefined;
247
+ updated_at: number & {
248
+ __brand: "UnixTimestamp";
249
+ };
250
+ updated_by?: string | undefined;
251
+ email: string;
252
+ email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
253
+ first_name: string;
254
+ last_name: string;
255
+ organization_id: string | null;
256
+ phone: string | null;
257
+ preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
258
+ role_ids: string[];
259
+ session_ids: string[];
260
+ verification_token_ids: string[];
261
+ _id: string;
262
+ }[]>;
263
+ /**
264
+ * Finds a user by their role.
265
+ * @param role The role of the user to find.
266
+ * @returns A promise that resolves to the matching user document or null if not found.
267
+ */
268
+ findByRole(role: string, includePasswordHash?: boolean): Promise<{
269
+ password_hash: any;
270
+ permissions: ({
271
+ scope: "agencies";
272
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
273
+ } | {
274
+ scope: "alerts_scheduled";
275
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
276
+ } | {
277
+ scope: "alerts_realtime";
278
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
279
+ resources: {
280
+ agency_ids: string[];
281
+ };
282
+ } | {
283
+ scope: "rides";
284
+ action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update";
285
+ resources: {
286
+ agency_ids: string[];
287
+ };
288
+ } | {
289
+ scope: "sams";
290
+ action: "read";
291
+ } | {
292
+ scope: "gtfs_validations";
293
+ action: "create" | "read" | "request_approval";
294
+ resources: {
295
+ agency_ids: string[];
296
+ };
297
+ } | {
298
+ scope: "home";
299
+ action: "read_links" | "read_wiki";
300
+ } | {
301
+ scope: "organizations";
302
+ action: "create" | "update" | "delete" | "read";
303
+ } | {
304
+ scope: "performance";
305
+ action: "read";
306
+ } | {
307
+ scope: "plans";
308
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
309
+ resources: {
310
+ agency_ids: string[];
311
+ };
312
+ } | {
313
+ scope: "roles";
314
+ action: "create" | "update" | "delete" | "read";
315
+ } | {
316
+ scope: "stops";
317
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
318
+ resources: {
319
+ municipality_ids: string[];
320
+ agency_ids: string[];
321
+ };
322
+ } | {
323
+ scope: "users";
324
+ action: "create" | "update" | "delete" | "read";
325
+ })[];
326
+ created_at: number & {
327
+ __brand: "UnixTimestamp";
328
+ };
329
+ created_by?: string | undefined;
330
+ updated_at: number & {
331
+ __brand: "UnixTimestamp";
332
+ };
333
+ updated_by?: string | undefined;
334
+ email: string;
335
+ email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
336
+ first_name: string;
337
+ last_name: string;
338
+ organization_id: string | null;
339
+ phone: string | null;
340
+ preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
341
+ role_ids: string[];
342
+ session_ids: string[];
343
+ verification_token_ids: string[];
344
+ _id: string;
345
+ }[]>;
346
+ /**
347
+ * Finds multiple documents matching the filter criteria
348
+ * with optional pagination and sorting.
349
+ * @param filter (Optional) filter criteria to match documents.
350
+ * @param perPage (Optional) number of documents per page for pagination.
351
+ * @param page (Optional) page number for pagination.
352
+ * @param sort (Optional) sort specification.
353
+ * @returns A promise that resolves to an array of matching documents.
354
+ */
355
+ findMany(filter?: Filter<User>, options?: FindOptions): Promise<{
356
+ password_hash: any;
357
+ permissions: ({
358
+ scope: "agencies";
359
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
360
+ } | {
361
+ scope: "alerts_scheduled";
362
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
363
+ } | {
364
+ scope: "alerts_realtime";
365
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
366
+ resources: {
367
+ agency_ids: string[];
368
+ };
369
+ } | {
370
+ scope: "rides";
371
+ action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update";
372
+ resources: {
373
+ agency_ids: string[];
374
+ };
375
+ } | {
376
+ scope: "sams";
377
+ action: "read";
378
+ } | {
379
+ scope: "gtfs_validations";
380
+ action: "create" | "read" | "request_approval";
381
+ resources: {
382
+ agency_ids: string[];
383
+ };
384
+ } | {
385
+ scope: "home";
386
+ action: "read_links" | "read_wiki";
387
+ } | {
388
+ scope: "organizations";
389
+ action: "create" | "update" | "delete" | "read";
390
+ } | {
391
+ scope: "performance";
392
+ action: "read";
393
+ } | {
394
+ scope: "plans";
395
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
396
+ resources: {
397
+ agency_ids: string[];
398
+ };
399
+ } | {
400
+ scope: "roles";
401
+ action: "create" | "update" | "delete" | "read";
402
+ } | {
403
+ scope: "stops";
404
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
405
+ resources: {
406
+ municipality_ids: string[];
407
+ agency_ids: string[];
408
+ };
409
+ } | {
410
+ scope: "users";
411
+ action: "create" | "update" | "delete" | "read";
412
+ })[];
413
+ created_at: number & {
414
+ __brand: "UnixTimestamp";
415
+ };
416
+ created_by?: string | undefined;
417
+ updated_at: number & {
418
+ __brand: "UnixTimestamp";
419
+ };
420
+ updated_by?: string | undefined;
421
+ email: string;
422
+ email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
423
+ first_name: string;
424
+ last_name: string;
425
+ organization_id: string | null;
426
+ phone: string | null;
427
+ preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
428
+ role_ids: string[];
429
+ session_ids: string[];
430
+ verification_token_ids: string[];
431
+ _id: string;
432
+ }[]>;
433
+ /**
434
+ * Finds a single document matching the filter criteria.
435
+ * @param filter Filter criteria to match the document.
436
+ * @returns A promise that resolves to the matching document or null if not found.
437
+ */
438
+ findOne(filter: Filter<User>): Promise<{
439
+ password_hash: any;
440
+ permissions: ({
441
+ scope: "agencies";
442
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
443
+ } | {
444
+ scope: "alerts_scheduled";
445
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
446
+ } | {
447
+ scope: "alerts_realtime";
448
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
449
+ resources: {
450
+ agency_ids: string[];
451
+ };
452
+ } | {
453
+ scope: "rides";
454
+ action: "acceptance_change_status" | "acceptance_justify" | "acceptance_lock" | "acceptance_read" | "analsys_lock" | "analysis_lock" | "analysis_read" | "analysis_reprocess" | "analysis_update" | "audit_lock" | "audit_read" | "audit_update";
455
+ resources: {
456
+ agency_ids: string[];
457
+ };
458
+ } | {
459
+ scope: "sams";
460
+ action: "read";
461
+ } | {
462
+ scope: "gtfs_validations";
463
+ action: "create" | "read" | "request_approval";
464
+ resources: {
465
+ agency_ids: string[];
466
+ };
467
+ } | {
468
+ scope: "home";
469
+ action: "read_links" | "read_wiki";
470
+ } | {
471
+ scope: "organizations";
472
+ action: "create" | "update" | "delete" | "read";
473
+ } | {
474
+ scope: "performance";
475
+ action: "read";
476
+ } | {
477
+ scope: "plans";
478
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
479
+ resources: {
480
+ agency_ids: string[];
481
+ };
482
+ } | {
483
+ scope: "roles";
484
+ action: "create" | "update" | "delete" | "read";
485
+ } | {
486
+ scope: "stops";
487
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
488
+ resources: {
489
+ municipality_ids: string[];
490
+ agency_ids: string[];
491
+ };
492
+ } | {
493
+ scope: "users";
494
+ action: "create" | "update" | "delete" | "read";
495
+ })[];
496
+ created_at: number & {
497
+ __brand: "UnixTimestamp";
498
+ };
499
+ created_by?: string | undefined;
500
+ updated_at: number & {
501
+ __brand: "UnixTimestamp";
502
+ };
503
+ updated_by?: string | undefined;
504
+ email: string;
505
+ email_verified: import("@tmlmobilidade/types").UnixTimestamp | null;
506
+ first_name: string;
507
+ last_name: string;
508
+ organization_id: string | null;
509
+ phone: string | null;
510
+ preferences: Record<string, Record<string, string | number | boolean | string[] | number[]>> | null;
511
+ role_ids: string[];
512
+ session_ids: string[];
513
+ verification_token_ids: string[];
514
+ _id: string;
515
+ }>;
516
+ protected getCollectionIndexes(): IndexDescription[];
517
+ protected getCollectionName(): string;
518
+ protected getEnvName(): string;
519
+ private sanitizeUser;
520
+ }
521
+ export declare const users: UsersClass;
522
+ export {};
@@ -0,0 +1,118 @@
1
+ /* * */
2
+ import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
+ import { PermissionCatalog, UpdateUserSchema, UserSchema } from '@tmlmobilidade/types';
4
+ import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
+ /* * */
6
+ class UsersClass extends MongoCollectionClass {
7
+ static _instance;
8
+ createSchema = UserSchema;
9
+ updateSchema = UpdateUserSchema;
10
+ constructor() {
11
+ super();
12
+ }
13
+ static async getInstance() {
14
+ if (!UsersClass._instance) {
15
+ const instance = new UsersClass();
16
+ await instance.connect();
17
+ UsersClass._instance = instance;
18
+ }
19
+ return UsersClass._instance;
20
+ }
21
+ /**
22
+ * Finds a user document by its email.
23
+ * @param email The email of the user to find.
24
+ * @param includePasswordHash - Whether to include the password hash in the result.
25
+ * @returns A promise that resolves to the matching user document or null if not found.
26
+ */
27
+ async findByEmail(email, includePasswordHash = false) {
28
+ const foundUser = await this.mongoCollection.findOne({ email: { $eq: email } });
29
+ if (!foundUser)
30
+ return null;
31
+ if (includePasswordHash)
32
+ return foundUser;
33
+ return this.sanitizeUser(foundUser);
34
+ }
35
+ /**
36
+ * Finds a user document by its ID.
37
+ * @param id The ID of the user document to find
38
+ * @param includePasswordHash Whether to include the password hash in the result
39
+ * @returns A promise that resolves to the matching user document or null if not found
40
+ */
41
+ async findById(id, options, includePasswordHash = false) {
42
+ const foundUser = await this.mongoCollection.findOne({ _id: id }, options);
43
+ if (!foundUser)
44
+ return null;
45
+ if (includePasswordHash)
46
+ return foundUser;
47
+ return this.sanitizeUser(foundUser);
48
+ }
49
+ /**
50
+ * Finds users by their organization code.
51
+ * @param code The code of the organization to find users for.
52
+ * @param includePasswordHash Whether to include the password hash in the result.
53
+ * @returns A promise that resolves to the matching user documents or null if not found.
54
+ */
55
+ async findByOrganization(id, includePasswordHash = false) {
56
+ const foundUsers = await this.mongoCollection.find({ organization_id: { $in: [id] } }).toArray();
57
+ if (includePasswordHash)
58
+ return foundUsers;
59
+ return foundUsers.map(item => this.sanitizeUser(item));
60
+ }
61
+ /**
62
+ * Finds a user by their role.
63
+ * @param role The role of the user to find.
64
+ * @returns A promise that resolves to the matching user document or null if not found.
65
+ */
66
+ async findByRole(role, includePasswordHash = false) {
67
+ const foundUsers = await this.mongoCollection.find({ role_ids: { $in: [role] } }).toArray();
68
+ if (includePasswordHash)
69
+ return foundUsers;
70
+ return foundUsers.map(item => this.sanitizeUser(item));
71
+ }
72
+ /**
73
+ * Finds multiple documents matching the filter criteria
74
+ * with optional pagination and sorting.
75
+ * @param filter (Optional) filter criteria to match documents.
76
+ * @param perPage (Optional) number of documents per page for pagination.
77
+ * @param page (Optional) page number for pagination.
78
+ * @param sort (Optional) sort specification.
79
+ * @returns A promise that resolves to an array of matching documents.
80
+ */
81
+ async findMany(filter, options) {
82
+ const foundUsers = await this.mongoCollection.find(filter ?? {}, options).toArray();
83
+ return foundUsers.map(item => this.sanitizeUser(item));
84
+ }
85
+ /**
86
+ * Finds a single document matching the filter criteria.
87
+ * @param filter Filter criteria to match the document.
88
+ * @returns A promise that resolves to the matching document or null if not found.
89
+ */
90
+ async findOne(filter) {
91
+ const foundUser = await this.mongoCollection.findOne(filter);
92
+ if (!foundUser)
93
+ return null;
94
+ return this.sanitizeUser(foundUser);
95
+ }
96
+ getCollectionIndexes() {
97
+ return [
98
+ { background: true, key: { email: 1 }, unique: true },
99
+ { background: true, key: { 'profile.first_name': 1, 'profile.last_name': 1 } },
100
+ { background: true, key: { session_ids: 1 } },
101
+ { background: true, key: { role_ids: 1 } },
102
+ ];
103
+ }
104
+ getCollectionName() {
105
+ return 'users';
106
+ }
107
+ getEnvName() {
108
+ return 'DATABASE_URI';
109
+ }
110
+ sanitizeUser(user) {
111
+ return {
112
+ ...user,
113
+ password_hash: null,
114
+ permissions: PermissionCatalog.sanitize(user.permissions),
115
+ };
116
+ }
117
+ }
118
+ export const users = AsyncSingletonProxy(UsersClass);
@@ -1,4 +1,4 @@
1
- import { MongoCollectionClass } from '../../mongo-collection.js';
1
+ import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
2
  import { CreateVerificationTokenDto, UpdateVerificationTokenDto, VerificationToken } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';
@@ -29,7 +29,7 @@ declare class VerificationTokensClass extends MongoCollectionClass<VerificationT
29
29
  user_id: string;
30
30
  created_by?: string | undefined;
31
31
  updated_by?: string | undefined;
32
- }> | null>;
32
+ }>>;
33
33
  protected getCollectionIndexes(): IndexDescription[];
34
34
  protected getCollectionName(): string;
35
35
  protected getEnvName(): string;
@@ -1,5 +1,5 @@
1
1
  /* * */
2
- import { MongoCollectionClass } from '../../mongo-collection.js';
2
+ import { MongoCollectionClass } from '../../common/mongo-collection.js';
3
3
  import { VerificationTokenSchema } from '@tmlmobilidade/types';
4
4
  import { AsyncSingletonProxy } from '@tmlmobilidade/utils';
5
5
  /* * */
@@ -1,4 +1,4 @@
1
- import { MongoCollectionClass } from '../../mongo-collection.js';
1
+ import { MongoCollectionClass } from '../../common/mongo-collection.js';
2
2
  import { CreateFileExportDto, FileExport } from '@tmlmobilidade/types';
3
3
  import { IndexDescription } from 'mongodb';
4
4
  import { z } from 'zod';