@tmlmobilidade/types 20251031.1051.3 → 20251202.1817.5

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 (235) hide show
  1. package/dist/{src/_common → _common}/index.d.ts +4 -2
  2. package/dist/{src/_common → _common}/index.js +4 -2
  3. package/dist/_common/mongo.d.ts +3 -0
  4. package/dist/_common/status.d.ts +13 -0
  5. package/dist/_common/status.js +20 -0
  6. package/dist/_common/utility.js +1 -0
  7. package/dist/{src/agency.d.ts → agency.d.ts} +4 -15
  8. package/dist/{src/agency.js → agency.js} +1 -6
  9. package/dist/{src/alert.d.ts → alert.d.ts} +20 -21
  10. package/dist/{src/alert.js → alert.js} +8 -14
  11. package/dist/{src/simplified-apex → apex}/simplified-apex-validation.d.ts +20 -20
  12. package/dist/{src/auth → auth}/index.d.ts +1 -1
  13. package/dist/{src/auth → auth}/index.js +1 -1
  14. package/dist/{src/auth → auth}/password-requirements.js +2 -1
  15. package/dist/auth/role.d.ts +958 -0
  16. package/dist/{src/auth → auth}/role.js +2 -2
  17. package/dist/{src/auth → auth}/session.d.ts +13 -9
  18. package/dist/{src/auth → auth}/session.js +1 -1
  19. package/dist/auth/user.d.ts +1281 -0
  20. package/dist/{src/auth → auth}/user.js +11 -14
  21. package/dist/{src/file-exports → file-exports}/common.d.ts +9 -8
  22. package/dist/{src/file-exports → file-exports}/common.js +1 -1
  23. package/dist/file-exports/index.d.ts +121 -0
  24. package/dist/file-exports/ride-export.d.ts +410 -0
  25. package/dist/file-exports/ride-export.js +131 -0
  26. package/dist/{src/file.d.ts → file.d.ts} +18 -18
  27. package/dist/gtfs/agency.d.ts +30 -0
  28. package/dist/gtfs/agency.js +13 -0
  29. package/dist/gtfs/feed-info.d.ts +33 -0
  30. package/dist/{src/gtfs.js → gtfs/feed-info.js} +1 -11
  31. package/dist/{src/gtfs → gtfs}/index.d.ts +3 -0
  32. package/dist/{src/gtfs → gtfs}/index.js +3 -0
  33. package/dist/gtfs/service-alert.d.ts +26 -0
  34. package/dist/index.d.ts +22 -22
  35. package/dist/index.js +22 -22
  36. package/dist/locations/census.d.ts +211 -0
  37. package/dist/locations/census.js +2 -0
  38. package/dist/locations/district.d.ts +24 -0
  39. package/dist/locations/district.js +2 -0
  40. package/dist/locations/index.d.ts +6 -0
  41. package/dist/locations/index.js +6 -0
  42. package/dist/locations/locality.d.ts +27 -0
  43. package/dist/locations/locality.js +2 -0
  44. package/dist/locations/municipality.d.ts +25 -0
  45. package/dist/locations/municipality.js +2 -0
  46. package/dist/locations/parish.d.ts +26 -0
  47. package/dist/locations/parish.js +2 -0
  48. package/dist/locations/queries.d.ts +117 -0
  49. package/dist/{src/locations.js → locations/queries.js} +5 -16
  50. package/dist/metrics/demand/demand_by_agency.d.ts +210 -0
  51. package/dist/metrics/demand/demand_by_agency.js +39 -0
  52. package/dist/metrics/demand/demand_by_category.d.ts +475 -0
  53. package/dist/metrics/demand/demand_by_category.js +114 -0
  54. package/dist/metrics/demand/demand_by_line.d.ts +246 -0
  55. package/dist/metrics/demand/demand_by_line.js +56 -0
  56. package/dist/metrics/demand/demand_by_pattern.d.ts +332 -0
  57. package/dist/metrics/demand/demand_by_pattern.js +56 -0
  58. package/dist/metrics/demand/demand_by_product.d.ts +475 -0
  59. package/dist/metrics/demand/demand_by_product.js +114 -0
  60. package/dist/metrics/demand/index.d.ts +6 -0
  61. package/dist/metrics/demand/index.js +8 -0
  62. package/dist/metrics/demand/records.d.ts +320 -0
  63. package/dist/metrics/demand/records.js +53 -0
  64. package/dist/metrics/index.d.ts +2647 -0
  65. package/dist/metrics/index.js +48 -0
  66. package/dist/metrics/realtime.d.ts +667 -0
  67. package/dist/metrics/realtime.js +41 -0
  68. package/dist/{src/notification.d.ts → notification.d.ts} +4 -4
  69. package/dist/{src/organization.d.ts → organization.d.ts} +32 -32
  70. package/dist/{src/organization.js → organization.js} +7 -7
  71. package/dist/permissions/agencies.d.ts +12 -0
  72. package/dist/permissions/agencies.js +13 -0
  73. package/dist/permissions/alerts.d.ts +36 -0
  74. package/dist/permissions/alerts.js +25 -0
  75. package/dist/permissions/controller.d.ts +36 -0
  76. package/dist/permissions/controller.js +30 -0
  77. package/dist/permissions/gtfs-validations.d.ts +25 -0
  78. package/dist/permissions/gtfs-validations.js +14 -0
  79. package/dist/permissions/home.d.ts +12 -0
  80. package/dist/permissions/home.js +10 -0
  81. package/dist/permissions/index.d.ts +268 -0
  82. package/dist/permissions/index.js +149 -0
  83. package/dist/permissions/organizations.d.ts +12 -0
  84. package/dist/permissions/organizations.js +12 -0
  85. package/dist/permissions/performance.d.ts +12 -0
  86. package/dist/permissions/performance.js +9 -0
  87. package/dist/permissions/plans.d.ts +25 -0
  88. package/dist/permissions/plans.js +22 -0
  89. package/dist/permissions/roles.d.ts +12 -0
  90. package/dist/permissions/roles.js +12 -0
  91. package/dist/permissions/stops.d.ts +30 -0
  92. package/dist/permissions/stops.js +17 -0
  93. package/dist/permissions/users.d.ts +12 -0
  94. package/dist/permissions/users.js +12 -0
  95. package/dist/{src/plans → plans}/gtfs-validation.d.ts +55 -63
  96. package/dist/{src/plans → plans}/gtfs-validation.js +3 -6
  97. package/dist/plans/plan-app-status.d.ts +15 -0
  98. package/dist/plans/plan-app-status.js +10 -0
  99. package/dist/{src/plans → plans}/plan.d.ts +240 -104
  100. package/dist/{src/plans → plans}/plan.js +8 -10
  101. package/dist/{src/_common/proposed-change.d.ts → proposed-change.d.ts} +21 -22
  102. package/dist/{src/_common/proposed-change.js → proposed-change.js} +5 -7
  103. package/dist/{src/rides → rides}/index.d.ts +1 -0
  104. package/dist/{src/rides → rides}/index.js +1 -0
  105. package/dist/{src/rides → rides}/ride-acceptance.d.ts +65 -65
  106. package/dist/{src/rides → rides}/ride-analysis.d.ts +34 -34
  107. package/dist/{src/rides → rides}/ride-audit.d.ts +10 -10
  108. package/dist/rides/ride-normalized.d.ts +29 -0
  109. package/dist/rides/ride-normalized.js +2 -0
  110. package/dist/{src/rides → rides}/ride.d.ts +523 -567
  111. package/dist/{src/rides → rides}/ride.js +2 -16
  112. package/dist/{src/sams → sams}/sam-analysis.d.ts +11 -11
  113. package/dist/{src/sams → sams}/sam-analysis.js +4 -4
  114. package/dist/{src/sams → sams}/sam.d.ts +76 -76
  115. package/dist/{src/sams → sams}/sam.js +1 -1
  116. package/dist/{src/stop.d.ts → stop.d.ts} +32 -43
  117. package/dist/{src/stop.js → stop.js} +3 -8
  118. package/dist/vehicle-events/gtfs-rt-vehicle-event-extended.d.ts +77 -0
  119. package/dist/vehicle-events/gtfs-rt-vehicle-event-extended.js +21 -0
  120. package/dist/vehicle-events/index.d.ts +2 -0
  121. package/dist/vehicle-events/index.js +2 -0
  122. package/dist/{src/vehicle-event.d.ts → vehicle-events/simplified-vehicle-event.d.ts} +9 -9
  123. package/dist/{src/vehicle-event.js → vehicle-events/simplified-vehicle-event.js} +3 -3
  124. package/dist/wiki.js +2 -0
  125. package/dist/{src/zone.d.ts → zone.d.ts} +2 -16
  126. package/dist/{src/zone.js → zone.js} +0 -6
  127. package/package.json +18 -21
  128. package/README.md +0 -13
  129. package/dist/src/_common/email.d.ts +0 -4
  130. package/dist/src/_common/email.js +0 -7
  131. package/dist/src/auth/permission.d.ts +0 -19
  132. package/dist/src/auth/permission.js +0 -8
  133. package/dist/src/auth/role.d.ts +0 -127
  134. package/dist/src/auth/user.d.ts +0 -311
  135. package/dist/src/file-exports/index.d.ts +0 -121
  136. package/dist/src/file-exports/ride-export.d.ts +0 -470
  137. package/dist/src/file-exports/ride-export.js +0 -128
  138. package/dist/src/gtfs.d.ts +0 -88
  139. package/dist/src/locations.d.ts +0 -319
  140. package/dist/src/metrics/demand.d.ts +0 -803
  141. package/dist/src/metrics/demand.js +0 -153
  142. package/dist/src/metrics/index.d.ts +0 -806
  143. package/dist/src/metrics/index.js +0 -19
  144. package/dist/src/plans/plan-controller.d.ts +0 -15
  145. package/dist/src/plans/plan-controller.js +0 -10
  146. package/dist/src/system/index.d.ts +0 -2
  147. package/dist/src/system/index.js +0 -2
  148. package/dist/src/system/processing-status.d.ts +0 -9
  149. package/dist/src/system/processing-status.js +0 -5
  150. package/dist/{src/_common → _common}/comment.d.ts +8 -8
  151. package/dist/{src/_common → _common}/comment.js +0 -0
  152. package/dist/{src/_common → _common}/document.d.ts +0 -0
  153. package/dist/{src/_common → _common}/document.js +0 -0
  154. package/dist/{src/system → _common}/environment.d.ts +0 -0
  155. package/dist/{src/system → _common}/environment.js +0 -0
  156. package/dist/{src/_common → _common}/fastify.d.ts +0 -0
  157. package/dist/{src/_common → _common}/fastify.js +0 -0
  158. package/dist/{src/_common/utility.js → _common/mongo.js} +0 -0
  159. package/dist/{src/_common → _common}/operational-date.d.ts +0 -0
  160. package/dist/{src/_common → _common}/operational-date.js +0 -0
  161. package/dist/{src/_common → _common}/unix-timestamp.d.ts +0 -0
  162. package/dist/{src/_common → _common}/unix-timestamp.js +0 -0
  163. package/dist/{src/_common → _common}/utility.d.ts +0 -0
  164. package/dist/{src/simplified-apex → apex}/index.d.ts +0 -0
  165. package/dist/{src/simplified-apex → apex}/index.js +0 -0
  166. package/dist/{src/simplified-apex → apex}/simplified-apex-inspection-decision.d.ts +0 -0
  167. package/dist/{src/simplified-apex → apex}/simplified-apex-inspection-decision.js +0 -0
  168. package/dist/{src/simplified-apex → apex}/simplified-apex-inspection.d.ts +0 -0
  169. package/dist/{src/simplified-apex → apex}/simplified-apex-inspection.js +0 -0
  170. package/dist/{src/simplified-apex → apex}/simplified-apex-location.d.ts +16 -16
  171. package/dist/{src/simplified-apex → apex}/simplified-apex-location.js +0 -0
  172. package/dist/{src/simplified-apex → apex}/simplified-apex-on-board-refund.d.ts +20 -20
  173. package/dist/{src/simplified-apex → apex}/simplified-apex-on-board-refund.js +0 -0
  174. package/dist/{src/simplified-apex → apex}/simplified-apex-on-board-sale.d.ts +25 -25
  175. package/dist/{src/simplified-apex → apex}/simplified-apex-on-board-sale.js +0 -0
  176. package/dist/{src/simplified-apex → apex}/simplified-apex-type.d.ts +0 -0
  177. package/dist/{src/simplified-apex → apex}/simplified-apex-type.js +0 -0
  178. package/dist/{src/simplified-apex → apex}/simplified-apex-validation.js +0 -0
  179. package/dist/{src/auth → auth}/login.d.ts +0 -0
  180. package/dist/{src/auth → auth}/login.js +0 -0
  181. package/dist/{src/auth → auth}/password-requirements.d.ts +0 -0
  182. package/dist/{src/auth → auth}/verification-token.d.ts +0 -0
  183. package/dist/{src/auth → auth}/verification-token.js +0 -0
  184. package/dist/{src/file-exports → file-exports}/index.js +0 -0
  185. package/dist/{src/file.js → file.js} +0 -0
  186. package/dist/{src/gtfs → gtfs}/calendar-dates.d.ts +0 -0
  187. package/dist/{src/gtfs → gtfs}/calendar-dates.js +0 -0
  188. package/dist/{src/gtfs → gtfs}/calendar.d.ts +0 -0
  189. package/dist/{src/gtfs → gtfs}/calendar.js +0 -0
  190. package/dist/{src/gtfs → gtfs}/cause-effetcs.d.ts +0 -0
  191. package/dist/{src/gtfs → gtfs}/cause-effetcs.js +0 -0
  192. package/dist/{src/gtfs → gtfs}/common.d.ts +0 -0
  193. package/dist/{src/gtfs → gtfs}/common.js +0 -0
  194. package/dist/{src/gtfs → gtfs}/routes.d.ts +0 -0
  195. package/dist/{src/gtfs → gtfs}/routes.js +0 -0
  196. package/dist/{src/pcgi/pcgi-apex-location.js → gtfs/service-alert.js} +0 -0
  197. package/dist/{src/gtfs → gtfs}/shapes.d.ts +0 -0
  198. package/dist/{src/gtfs → gtfs}/shapes.js +0 -0
  199. package/dist/{src/gtfs → gtfs}/stop-times.d.ts +0 -0
  200. package/dist/{src/gtfs → gtfs}/stop-times.js +0 -0
  201. package/dist/{src/gtfs → gtfs}/stops.d.ts +0 -0
  202. package/dist/{src/gtfs → gtfs}/stops.js +0 -0
  203. package/dist/{src/gtfs → gtfs}/trips.d.ts +0 -0
  204. package/dist/{src/gtfs → gtfs}/trips.js +0 -0
  205. package/dist/{src/metrics → metrics}/common.d.ts +0 -0
  206. package/dist/{src/metrics → metrics}/common.js +0 -0
  207. package/dist/{src/notification.js → notification.js} +0 -0
  208. package/dist/{src/pcgi → pcgi}/index.d.ts +0 -0
  209. package/dist/{src/pcgi → pcgi}/index.js +0 -0
  210. package/dist/{src/pcgi → pcgi}/pcgi-apex-location.d.ts +0 -0
  211. package/dist/{src/pcgi/pcgi-apex-refund.js → pcgi/pcgi-apex-location.js} +0 -0
  212. package/dist/{src/pcgi → pcgi}/pcgi-apex-refund.d.ts +0 -0
  213. package/dist/{src/pcgi/pcgi-apex-sale.js → pcgi/pcgi-apex-refund.js} +0 -0
  214. package/dist/{src/pcgi → pcgi}/pcgi-apex-sale.d.ts +0 -0
  215. package/dist/{src/pcgi/pcgi-apex-validation.js → pcgi/pcgi-apex-sale.js} +0 -0
  216. package/dist/{src/pcgi → pcgi}/pcgi-apex-validation.d.ts +0 -0
  217. package/dist/{src/pcgi/pcgi-transaction-entity.js → pcgi/pcgi-apex-validation.js} +0 -0
  218. package/dist/{src/pcgi → pcgi}/pcgi-transaction-entity.d.ts +0 -0
  219. package/dist/{src/rides/hashed-shape.js → pcgi/pcgi-transaction-entity.js} +0 -0
  220. package/dist/{src/plans → plans}/index.d.ts +0 -0
  221. package/dist/{src/plans → plans}/index.js +0 -0
  222. package/dist/{src/plans → plans}/plan-pcgi-legacy.d.ts +0 -0
  223. package/dist/{src/plans → plans}/plan-pcgi-legacy.js +0 -0
  224. package/dist/{src/rides → rides}/hashed-shape.d.ts +0 -0
  225. package/dist/{src/rides/hashed-trip.js → rides/hashed-shape.js} +0 -0
  226. package/dist/{src/rides → rides}/hashed-trip.d.ts +0 -0
  227. package/dist/{src/wiki.js → rides/hashed-trip.js} +0 -0
  228. package/dist/{src/rides → rides}/ride-acceptance.js +1 -1
  229. /package/dist/{src/rides → rides}/ride-analysis.js +0 -0
  230. /package/dist/{src/rides → rides}/ride-audit.js +0 -0
  231. /package/dist/{src/rides → rides}/ride-overrides.d.ts +0 -0
  232. /package/dist/{src/rides → rides}/ride-overrides.js +0 -0
  233. /package/dist/{src/sams → sams}/index.d.ts +0 -0
  234. /package/dist/{src/sams → sams}/index.js +0 -0
  235. /package/dist/{src/wiki.d.ts → wiki.d.ts} +0 -0
@@ -0,0 +1,268 @@
1
+ import { z } from 'zod';
2
+ export declare const PermissionSchema: z.ZodDiscriminatedUnion<"scope", [z.ZodObject<{
3
+ action: z.ZodEnum<["create", "delete", "read", "toggle_lock", "update"]>;
4
+ scope: z.ZodLiteral<"agencies">;
5
+ }, "strip", z.ZodTypeAny, {
6
+ scope: "agencies";
7
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
8
+ }, {
9
+ scope: "agencies";
10
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
11
+ }>, z.ZodObject<{
12
+ action: z.ZodEnum<["create", "delete", "read", "toggle_lock", "update"]>;
13
+ scope: z.ZodLiteral<"alerts_scheduled">;
14
+ }, "strip", z.ZodTypeAny, {
15
+ scope: "alerts_scheduled";
16
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
17
+ }, {
18
+ scope: "alerts_scheduled";
19
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
20
+ }>, z.ZodObject<{
21
+ action: z.ZodEnum<["create", "delete", "read", "toggle_lock", "update"]>;
22
+ resources: z.ZodDefault<z.ZodObject<{
23
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ agency_ids: string[];
26
+ }, {
27
+ agency_ids?: string[] | undefined;
28
+ }>>;
29
+ scope: z.ZodLiteral<"alerts_realtime">;
30
+ }, "strip", z.ZodTypeAny, {
31
+ scope: "alerts_realtime";
32
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
33
+ resources: {
34
+ agency_ids: string[];
35
+ };
36
+ }, {
37
+ scope: "alerts_realtime";
38
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
39
+ resources?: {
40
+ agency_ids?: string[] | undefined;
41
+ } | undefined;
42
+ }>, z.ZodObject<{
43
+ action: z.ZodEnum<["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"]>;
44
+ resources: z.ZodDefault<z.ZodObject<{
45
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
46
+ }, "strip", z.ZodTypeAny, {
47
+ agency_ids: string[];
48
+ }, {
49
+ agency_ids?: string[] | undefined;
50
+ }>>;
51
+ scope: z.ZodLiteral<"rides">;
52
+ }, "strip", z.ZodTypeAny, {
53
+ scope: "rides";
54
+ 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";
55
+ resources: {
56
+ agency_ids: string[];
57
+ };
58
+ }, {
59
+ scope: "rides";
60
+ 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";
61
+ resources?: {
62
+ agency_ids?: string[] | undefined;
63
+ } | undefined;
64
+ }>, z.ZodObject<{
65
+ action: z.ZodEnum<["read"]>;
66
+ scope: z.ZodLiteral<"sams">;
67
+ }, "strip", z.ZodTypeAny, {
68
+ scope: "sams";
69
+ action: "read";
70
+ }, {
71
+ scope: "sams";
72
+ action: "read";
73
+ }>, z.ZodObject<{
74
+ action: z.ZodEnum<["create", "read", "request_approval"]>;
75
+ resources: z.ZodDefault<z.ZodObject<{
76
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ agency_ids: string[];
79
+ }, {
80
+ agency_ids?: string[] | undefined;
81
+ }>>;
82
+ scope: z.ZodLiteral<"gtfs_validations">;
83
+ }, "strip", z.ZodTypeAny, {
84
+ scope: "gtfs_validations";
85
+ action: "create" | "read" | "request_approval";
86
+ resources: {
87
+ agency_ids: string[];
88
+ };
89
+ }, {
90
+ scope: "gtfs_validations";
91
+ action: "create" | "read" | "request_approval";
92
+ resources?: {
93
+ agency_ids?: string[] | undefined;
94
+ } | undefined;
95
+ }>, z.ZodObject<{
96
+ action: z.ZodEnum<["read_links", "read_wiki"]>;
97
+ scope: z.ZodLiteral<"home">;
98
+ }, "strip", z.ZodTypeAny, {
99
+ scope: "home";
100
+ action: "read_links" | "read_wiki";
101
+ }, {
102
+ scope: "home";
103
+ action: "read_links" | "read_wiki";
104
+ }>, z.ZodObject<{
105
+ action: z.ZodEnum<["create", "delete", "read", "update"]>;
106
+ scope: z.ZodLiteral<"organizations">;
107
+ }, "strip", z.ZodTypeAny, {
108
+ scope: "organizations";
109
+ action: "create" | "update" | "delete" | "read";
110
+ }, {
111
+ scope: "organizations";
112
+ action: "create" | "update" | "delete" | "read";
113
+ }>, z.ZodObject<{
114
+ action: z.ZodEnum<["read"]>;
115
+ scope: z.ZodLiteral<"performance">;
116
+ }, "strip", z.ZodTypeAny, {
117
+ scope: "performance";
118
+ action: "read";
119
+ }, {
120
+ scope: "performance";
121
+ action: "read";
122
+ }>, z.ZodObject<{
123
+ action: z.ZodEnum<["create", "delete", "read", "read_controller", "read_pcgi_legacy", "toggle_lock", "update", "update_controller", "update_feed_info_dates", "update_gtfs_plan", "update_pcgi_legacy"]>;
124
+ resources: z.ZodDefault<z.ZodObject<{
125
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
126
+ }, "strip", z.ZodTypeAny, {
127
+ agency_ids: string[];
128
+ }, {
129
+ agency_ids?: string[] | undefined;
130
+ }>>;
131
+ scope: z.ZodLiteral<"plans">;
132
+ }, "strip", z.ZodTypeAny, {
133
+ scope: "plans";
134
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
135
+ resources: {
136
+ agency_ids: string[];
137
+ };
138
+ }, {
139
+ scope: "plans";
140
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
141
+ resources?: {
142
+ agency_ids?: string[] | undefined;
143
+ } | undefined;
144
+ }>, z.ZodObject<{
145
+ action: z.ZodEnum<["create", "delete", "read", "update"]>;
146
+ scope: z.ZodLiteral<"roles">;
147
+ }, "strip", z.ZodTypeAny, {
148
+ scope: "roles";
149
+ action: "create" | "update" | "delete" | "read";
150
+ }, {
151
+ scope: "roles";
152
+ action: "create" | "update" | "delete" | "read";
153
+ }>, z.ZodObject<{
154
+ action: z.ZodEnum<["create", "delete", "read", "toggle_lock", "update"]>;
155
+ resources: z.ZodDefault<z.ZodObject<{
156
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
157
+ municipality_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
158
+ }, "strip", z.ZodTypeAny, {
159
+ municipality_ids: string[];
160
+ agency_ids: string[];
161
+ }, {
162
+ municipality_ids?: string[] | undefined;
163
+ agency_ids?: string[] | undefined;
164
+ }>>;
165
+ scope: z.ZodLiteral<"stops">;
166
+ }, "strip", z.ZodTypeAny, {
167
+ scope: "stops";
168
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
169
+ resources: {
170
+ municipality_ids: string[];
171
+ agency_ids: string[];
172
+ };
173
+ }, {
174
+ scope: "stops";
175
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
176
+ resources?: {
177
+ municipality_ids?: string[] | undefined;
178
+ agency_ids?: string[] | undefined;
179
+ } | undefined;
180
+ }>, z.ZodObject<{
181
+ action: z.ZodEnum<["create", "delete", "read", "update"]>;
182
+ scope: z.ZodLiteral<"users">;
183
+ }, "strip", z.ZodTypeAny, {
184
+ scope: "users";
185
+ action: "create" | "update" | "delete" | "read";
186
+ }, {
187
+ scope: "users";
188
+ action: "create" | "update" | "delete" | "read";
189
+ }>]>;
190
+ export type Permission = z.infer<typeof PermissionSchema>;
191
+ export type ActionsOf<S extends Permission['scope']> = Extract<Permission, {
192
+ scope: S;
193
+ }>['action'];
194
+ export type PermissionCatalogType = {
195
+ [S in Permission['scope']]: {
196
+ actions: {
197
+ [A in ActionsOf<S>]: A;
198
+ };
199
+ scope: S;
200
+ };
201
+ };
202
+ /**
203
+ * Arguments for hasPermissionResource function.
204
+ * @param T The type of the resource.
205
+ */
206
+ export interface HasPermissionResourceArgs {
207
+ action: string;
208
+ permissions: Permission[];
209
+ resource_key: string;
210
+ scope: string;
211
+ value: unknown;
212
+ }
213
+ /**
214
+ * PermissionCatalog provides a structured catalog of all available permissions
215
+ * in the system, categorized by scope and their respective actions.
216
+ * Use it to reference required permissions in components and services.
217
+ */
218
+ export declare class PermissionCatalog {
219
+ static readonly ALLOW_ALL_FLAG = "allow_all";
220
+ /**
221
+ * Generates the complete permission catalog by extracting
222
+ * scopes and actions from the defined PermissionSchema.
223
+ * @return A catalog object mapping scopes to their actions.
224
+ */
225
+ static get all(): PermissionCatalogType;
226
+ /**
227
+ * Get a specific permission from a full list by scope and action.
228
+ * @param permissionEntries The full list of permissions of the user.
229
+ * @param scope The resource scope of the permission to filter by.
230
+ * @param action The action of the permission to filter by.
231
+ * @returns The filtered Permission object or undefined if not found.
232
+ */
233
+ static get<S extends Permission['scope']>(permissionEntries: Permission[], scope: S, action: ActionsOf<S>): Extract<Permission, {
234
+ action: ActionsOf<S>;
235
+ scope: S;
236
+ }> | undefined;
237
+ /**
238
+ * Check if a list of permission entries has the requested scope/action pair.
239
+ * @param permissionEntries The list of permission entries to check against.
240
+ * @param scope The required scope to check.
241
+ * @param action The required action to check.
242
+ * @returns The permission object or undefined if not found.
243
+ */
244
+ static hasPermission<S extends Permission['scope']>(permissionEntries: Permission[], scope: S, action: ActionsOf<S>): boolean;
245
+ /**
246
+ * Check if a permission exists in a list of permissions, with additional check for a given resource value.
247
+ * If a `value` exists in a `resource` of a User `permissions` object that
248
+ * matches the given `action` and `scope`. For example, if you want to check if
249
+ * a user has access to a specific `agency_id`, you set `value=43` and `resource_key='agency_ids'`.
250
+ * If the provided `permissions` object contains the value `43` inside the `scope='plans'`,
251
+ * `action='create'` and `resource_key='agency_ids'` the function will return true.
252
+ * @param permissions The list of permissions (from a user or request).
253
+ * @param value The permission value to check against.
254
+ * @param resource_key The key of the resource.
255
+ * @param scope The scope of the permission.
256
+ * @param action The action of the permission.
257
+ * @returns The permission.
258
+ */
259
+ static hasPermissionResource({ action, permissions, resource_key, scope, value }: HasPermissionResourceArgs): boolean;
260
+ /**
261
+ * Sanitizes a list of permissions by removing any entries
262
+ * that do not correspond to valid scopes and actions
263
+ * defined in the PermissionCatalog.
264
+ * @param existingEntries Array of Permission objects to sanitize.
265
+ * @return A cleaned array containing only valid permissions.
266
+ */
267
+ static sanitize(existingEntries: Permission[]): Permission[];
268
+ }
@@ -0,0 +1,149 @@
1
+ /* eslint-disable @typescript-eslint/no-extraneous-class */
2
+ /* * */
3
+ import { AgenciesPermissionSchema } from './agencies.js';
4
+ import { AlertsRealtimePermissionSchema, AlertsScheduledPermissionSchema } from './alerts.js';
5
+ import { RidesPermissionSchema, SamsPermissionSchema } from './controller.js';
6
+ import { GtfsValidationsPermissionSchema } from './gtfs-validations.js';
7
+ import { HomePermissionSchema } from './home.js';
8
+ import { OrganizationsPermissionSchema } from './organizations.js';
9
+ import { PerformancePermissionSchema } from './performance.js';
10
+ import { PlansPermissionSchema } from './plans.js';
11
+ import { RolesPermissionSchema } from './roles.js';
12
+ import { StopsPermissionSchema } from './stops.js';
13
+ import { UsersPermissionSchema } from './users.js';
14
+ import { z } from 'zod';
15
+ /* * */
16
+ export const PermissionSchema = z.discriminatedUnion('scope', [
17
+ AgenciesPermissionSchema,
18
+ AlertsScheduledPermissionSchema,
19
+ AlertsRealtimePermissionSchema,
20
+ RidesPermissionSchema,
21
+ SamsPermissionSchema,
22
+ GtfsValidationsPermissionSchema,
23
+ HomePermissionSchema,
24
+ OrganizationsPermissionSchema,
25
+ PerformancePermissionSchema,
26
+ PlansPermissionSchema,
27
+ RolesPermissionSchema,
28
+ StopsPermissionSchema,
29
+ UsersPermissionSchema,
30
+ ]);
31
+ /**
32
+ * PermissionCatalog provides a structured catalog of all available permissions
33
+ * in the system, categorized by scope and their respective actions.
34
+ * Use it to reference required permissions in components and services.
35
+ */
36
+ export class PermissionCatalog {
37
+ //
38
+ static ALLOW_ALL_FLAG = 'allow_all';
39
+ /**
40
+ * Generates the complete permission catalog by extracting
41
+ * scopes and actions from the defined PermissionSchema.
42
+ * @return A catalog object mapping scopes to their actions.
43
+ */
44
+ static get all() {
45
+ // Initialize catalog object
46
+ const catalog = {};
47
+ // Iterate over each schema option
48
+ for (const schemaOption of PermissionSchema.options) {
49
+ // Extract scope name and actions
50
+ const scopeName = schemaOption.shape.scope.value;
51
+ const actions = schemaOption.shape.action.options;
52
+ // Build catalog entry
53
+ catalog[scopeName] = {
54
+ actions: Object.fromEntries(actions.map((a) => [a, a])),
55
+ scope: scopeName,
56
+ };
57
+ }
58
+ // Return the completed catalog
59
+ return catalog;
60
+ }
61
+ /**
62
+ * Get a specific permission from a full list by scope and action.
63
+ * @param permissionEntries The full list of permissions of the user.
64
+ * @param scope The resource scope of the permission to filter by.
65
+ * @param action The action of the permission to filter by.
66
+ * @returns The filtered Permission object or undefined if not found.
67
+ */
68
+ static get(permissionEntries, scope, action) {
69
+ return permissionEntries.find((p) => p.scope === scope && p.action === action);
70
+ }
71
+ /**
72
+ * Check if a list of permission entries has the requested scope/action pair.
73
+ * @param permissionEntries The list of permission entries to check against.
74
+ * @param scope The required scope to check.
75
+ * @param action The required action to check.
76
+ * @returns The permission object or undefined if not found.
77
+ */
78
+ static hasPermission(permissionEntries, scope, action) {
79
+ return permissionEntries.find(p => p.scope === scope && p.action === action) !== undefined;
80
+ }
81
+ /**
82
+ * Check if a permission exists in a list of permissions, with additional check for a given resource value.
83
+ * If a `value` exists in a `resource` of a User `permissions` object that
84
+ * matches the given `action` and `scope`. For example, if you want to check if
85
+ * a user has access to a specific `agency_id`, you set `value=43` and `resource_key='agency_ids'`.
86
+ * If the provided `permissions` object contains the value `43` inside the `scope='plans'`,
87
+ * `action='create'` and `resource_key='agency_ids'` the function will return true.
88
+ * @param permissions The list of permissions (from a user or request).
89
+ * @param value The permission value to check against.
90
+ * @param resource_key The key of the resource.
91
+ * @param scope The scope of the permission.
92
+ * @param action The action of the permission.
93
+ * @returns The permission.
94
+ */
95
+ static hasPermissionResource({ action, permissions, resource_key, scope, value }) {
96
+ //
97
+ //
98
+ // Return false if no permissions
99
+ if (!permissions)
100
+ return false;
101
+ //
102
+ // Find the permission with the given action and scope
103
+ const foundPermission = permissions.find(p => p.action === action && p.scope === scope);
104
+ if (!foundPermission)
105
+ return false;
106
+ //
107
+ // Check if value exists in the permission.resources[resource_key]
108
+ const resourceValues = foundPermission['resources']?.[resource_key];
109
+ if (!resourceValues)
110
+ return false;
111
+ //
112
+ // If resourceValues is an Array, check if value is in the array
113
+ // or if it contains the ALLOW_ALL_FLAG.
114
+ if (Array.isArray(resourceValues) && resourceValues.includes(this.ALLOW_ALL_FLAG))
115
+ return true;
116
+ if (Array.isArray(resourceValues) && resourceValues.includes(value))
117
+ return true;
118
+ //
119
+ // If resourceValues is not an Array, check if it is equal to the requested value
120
+ if (resourceValues === value)
121
+ return true;
122
+ //
123
+ // Otherwise, return false
124
+ return false;
125
+ //
126
+ }
127
+ /**
128
+ * Sanitizes a list of permissions by removing any entries
129
+ * that do not correspond to valid scopes and actions
130
+ * defined in the PermissionCatalog.
131
+ * @param existingEntries Array of Permission objects to sanitize.
132
+ * @return A cleaned array containing only valid permissions.
133
+ */
134
+ static sanitize(existingEntries) {
135
+ // Create a new array to hold valid permissions
136
+ const cleanedPermissions = {};
137
+ // Iterate through each permission entry of the user
138
+ for (const permissionEntry of existingEntries) {
139
+ // Validate the permission entry
140
+ const validationResult = PermissionSchema.safeParse(permissionEntry);
141
+ if (!validationResult.success)
142
+ continue;
143
+ // Permission is valid; keep it
144
+ cleanedPermissions[`${permissionEntry.scope}:${permissionEntry.action}`] = permissionEntry;
145
+ }
146
+ // Return the cleaned permissions array
147
+ return Object.values(cleanedPermissions);
148
+ }
149
+ }
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const OrganizationsPermissionSchema: z.ZodObject<{
3
+ action: z.ZodEnum<["create", "delete", "read", "update"]>;
4
+ scope: z.ZodLiteral<"organizations">;
5
+ }, "strip", z.ZodTypeAny, {
6
+ scope: "organizations";
7
+ action: "create" | "update" | "delete" | "read";
8
+ }, {
9
+ scope: "organizations";
10
+ action: "create" | "update" | "delete" | "read";
11
+ }>;
12
+ export type OrganizationsPermission = z.infer<typeof OrganizationsPermissionSchema>;
@@ -0,0 +1,12 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const OrganizationsPermissionSchema = z.object({
5
+ action: z.enum([
6
+ 'create',
7
+ 'delete',
8
+ 'read',
9
+ 'update',
10
+ ]),
11
+ scope: z.literal('organizations'),
12
+ });
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const PerformancePermissionSchema: z.ZodObject<{
3
+ action: z.ZodEnum<["read"]>;
4
+ scope: z.ZodLiteral<"performance">;
5
+ }, "strip", z.ZodTypeAny, {
6
+ scope: "performance";
7
+ action: "read";
8
+ }, {
9
+ scope: "performance";
10
+ action: "read";
11
+ }>;
12
+ export type PerformancePermission = z.infer<typeof PerformancePermissionSchema>;
@@ -0,0 +1,9 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const PerformancePermissionSchema = z.object({
5
+ action: z.enum([
6
+ 'read',
7
+ ]),
8
+ scope: z.literal('performance'),
9
+ });
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+ export declare const PlansPermissionSchema: z.ZodObject<{
3
+ action: z.ZodEnum<["create", "delete", "read", "read_controller", "read_pcgi_legacy", "toggle_lock", "update", "update_controller", "update_feed_info_dates", "update_gtfs_plan", "update_pcgi_legacy"]>;
4
+ resources: z.ZodDefault<z.ZodObject<{
5
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ agency_ids: string[];
8
+ }, {
9
+ agency_ids?: string[] | undefined;
10
+ }>>;
11
+ scope: z.ZodLiteral<"plans">;
12
+ }, "strip", z.ZodTypeAny, {
13
+ scope: "plans";
14
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
15
+ resources: {
16
+ agency_ids: string[];
17
+ };
18
+ }, {
19
+ scope: "plans";
20
+ action: "create" | "update" | "delete" | "read" | "toggle_lock" | "read_controller" | "read_pcgi_legacy" | "update_controller" | "update_feed_info_dates" | "update_gtfs_plan" | "update_pcgi_legacy";
21
+ resources?: {
22
+ agency_ids?: string[] | undefined;
23
+ } | undefined;
24
+ }>;
25
+ export type PlansPermission = z.infer<typeof PlansPermissionSchema>;
@@ -0,0 +1,22 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const PlansPermissionSchema = z.object({
5
+ action: z.enum([
6
+ 'create',
7
+ 'delete',
8
+ 'read',
9
+ 'read_controller',
10
+ 'read_pcgi_legacy',
11
+ 'toggle_lock',
12
+ 'update',
13
+ 'update_controller',
14
+ 'update_feed_info_dates',
15
+ 'update_gtfs_plan',
16
+ 'update_pcgi_legacy',
17
+ ]),
18
+ resources: z.object({
19
+ agency_ids: z.array(z.string()).default([]),
20
+ }).default({}),
21
+ scope: z.literal('plans'),
22
+ });
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const RolesPermissionSchema: z.ZodObject<{
3
+ action: z.ZodEnum<["create", "delete", "read", "update"]>;
4
+ scope: z.ZodLiteral<"roles">;
5
+ }, "strip", z.ZodTypeAny, {
6
+ scope: "roles";
7
+ action: "create" | "update" | "delete" | "read";
8
+ }, {
9
+ scope: "roles";
10
+ action: "create" | "update" | "delete" | "read";
11
+ }>;
12
+ export type RolesPermission = z.infer<typeof RolesPermissionSchema>;
@@ -0,0 +1,12 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const RolesPermissionSchema = z.object({
5
+ action: z.enum([
6
+ 'create',
7
+ 'delete',
8
+ 'read',
9
+ 'update',
10
+ ]),
11
+ scope: z.literal('roles'),
12
+ });
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ export declare const StopsPermissionSchema: z.ZodObject<{
3
+ action: z.ZodEnum<["create", "delete", "read", "toggle_lock", "update"]>;
4
+ resources: z.ZodDefault<z.ZodObject<{
5
+ agency_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
6
+ municipality_ids: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ municipality_ids: string[];
9
+ agency_ids: string[];
10
+ }, {
11
+ municipality_ids?: string[] | undefined;
12
+ agency_ids?: string[] | undefined;
13
+ }>>;
14
+ scope: z.ZodLiteral<"stops">;
15
+ }, "strip", z.ZodTypeAny, {
16
+ scope: "stops";
17
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
18
+ resources: {
19
+ municipality_ids: string[];
20
+ agency_ids: string[];
21
+ };
22
+ }, {
23
+ scope: "stops";
24
+ action: "create" | "update" | "delete" | "read" | "toggle_lock";
25
+ resources?: {
26
+ municipality_ids?: string[] | undefined;
27
+ agency_ids?: string[] | undefined;
28
+ } | undefined;
29
+ }>;
30
+ export type StopsPermission = z.infer<typeof StopsPermissionSchema>;
@@ -0,0 +1,17 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const StopsPermissionSchema = z.object({
5
+ action: z.enum([
6
+ 'create',
7
+ 'delete',
8
+ 'read',
9
+ 'toggle_lock',
10
+ 'update',
11
+ ]),
12
+ resources: z.object({
13
+ agency_ids: z.array(z.string()).default([]),
14
+ municipality_ids: z.array(z.string()).default([]),
15
+ }).default({}),
16
+ scope: z.literal('stops'),
17
+ });
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare const UsersPermissionSchema: z.ZodObject<{
3
+ action: z.ZodEnum<["create", "delete", "read", "update"]>;
4
+ scope: z.ZodLiteral<"users">;
5
+ }, "strip", z.ZodTypeAny, {
6
+ scope: "users";
7
+ action: "create" | "update" | "delete" | "read";
8
+ }, {
9
+ scope: "users";
10
+ action: "create" | "update" | "delete" | "read";
11
+ }>;
12
+ export type UsersPermission = z.infer<typeof UsersPermissionSchema>;
@@ -0,0 +1,12 @@
1
+ /* * */
2
+ import { z } from 'zod';
3
+ /* * */
4
+ export const UsersPermissionSchema = z.object({
5
+ action: z.enum([
6
+ 'create',
7
+ 'delete',
8
+ 'read',
9
+ 'update',
10
+ ]),
11
+ scope: z.literal('users'),
12
+ });