sgerp-frontend-lib 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/README.md +1 -1
  2. package/dist/connection-manager.d.ts +48 -0
  3. package/dist/connection-manager.d.ts.map +1 -0
  4. package/dist/connection-manager.js +156 -0
  5. package/dist/index.js +20 -2
  6. package/dist/locales/locale-server.d.ts +10 -0
  7. package/dist/locales/locale-server.d.ts.map +1 -0
  8. package/dist/locales/locale-server.js +49 -0
  9. package/dist/locales/locale.d.ts +23 -0
  10. package/dist/locales/locale.d.ts.map +1 -0
  11. package/dist/locales/locale.js +145 -0
  12. package/dist/locales/locale_en.d.ts.map +1 -1
  13. package/dist/locales/locale_en.js +84 -9
  14. package/dist/locales/locale_ja.d.ts.map +1 -1
  15. package/dist/locales/locale_ja.js +84 -9
  16. package/dist/locales/locale_ms.d.ts.map +1 -1
  17. package/dist/locales/locale_ms.js +84 -9
  18. package/dist/locales/useLocalization.d.ts +11 -0
  19. package/dist/locales/useLocalization.d.ts.map +1 -0
  20. package/dist/locales/useLocalization.js +64 -0
  21. package/dist/locales.d.ts +228 -0
  22. package/dist/locales.d.ts.map +1 -0
  23. package/dist/locales.js +229 -0
  24. package/dist/sgerp/api/client.d.ts +45 -0
  25. package/dist/sgerp/api/client.d.ts.map +1 -0
  26. package/dist/sgerp/api/client.js +141 -0
  27. package/dist/sgerp/client.js +341 -0
  28. package/dist/sgerp/collection.d.ts +391 -0
  29. package/dist/sgerp/collection.d.ts.map +1 -0
  30. package/dist/sgerp/collection.js +756 -0
  31. package/dist/sgerp/collections/account/user.d.ts +8 -0
  32. package/dist/sgerp/collections/account/user.d.ts.map +1 -0
  33. package/dist/sgerp/collections/account/user.js +10 -0
  34. package/dist/sgerp/collections/masstransit/building.d.ts +26 -0
  35. package/dist/sgerp/collections/masstransit/building.d.ts.map +1 -0
  36. package/dist/sgerp/collections/masstransit/building.js +53 -0
  37. package/dist/sgerp/collections/masstransit/transitstop.d.ts +15 -0
  38. package/dist/sgerp/collections/masstransit/transitstop.d.ts.map +1 -0
  39. package/dist/sgerp/collections/masstransit/transitstop.js +54 -0
  40. package/dist/sgerp/collections/masstransit/transitstopset.d.ts +10 -0
  41. package/dist/sgerp/collections/masstransit/transitstopset.d.ts.map +1 -0
  42. package/dist/sgerp/collections/masstransit/transitstopset.js +10 -0
  43. package/dist/sgerp/collections/sharing/organization-project.d.ts +11 -0
  44. package/dist/sgerp/collections/sharing/organization-project.d.ts.map +1 -0
  45. package/dist/sgerp/collections/sharing/organization-project.js +13 -0
  46. package/dist/sgerp/collections/sharing/organization.d.ts +11 -0
  47. package/dist/sgerp/collections/sharing/organization.d.ts.map +1 -0
  48. package/dist/sgerp/collections/sharing/organization.js +13 -0
  49. package/dist/sgerp/collections/sharing/pricing.d.ts +18 -0
  50. package/dist/sgerp/collections/sharing/pricing.d.ts.map +1 -0
  51. package/dist/sgerp/collections/sharing/pricing.js +23 -0
  52. package/dist/sgerp/collections/sharing/project-member.d.ts +8 -0
  53. package/dist/sgerp/collections/sharing/project-member.d.ts.map +1 -0
  54. package/dist/sgerp/collections/sharing/project-member.js +10 -0
  55. package/dist/sgerp/collections/sharing/project.d.ts +8 -0
  56. package/dist/sgerp/collections/sharing/project.d.ts.map +1 -0
  57. package/dist/sgerp/collections/sharing/project.js +10 -0
  58. package/dist/sgerp/collections/simulation/booking.d.ts +11 -0
  59. package/dist/sgerp/collections/simulation/booking.d.ts.map +1 -0
  60. package/dist/sgerp/collections/simulation/booking.js +13 -0
  61. package/dist/sgerp/collections/simulation/dataset.d.ts +14 -0
  62. package/dist/sgerp/collections/simulation/dataset.d.ts.map +1 -0
  63. package/dist/sgerp/collections/simulation/dataset.js +17 -0
  64. package/dist/sgerp/collections/simulation/driver.d.ts +12 -0
  65. package/dist/sgerp/collections/simulation/driver.d.ts.map +1 -0
  66. package/dist/sgerp/collections/simulation/driver.js +40 -0
  67. package/dist/sgerp/collections/simulation/geofence.d.ts +24 -0
  68. package/dist/sgerp/collections/simulation/geofence.d.ts.map +1 -0
  69. package/dist/sgerp/collections/simulation/geofence.js +66 -0
  70. package/dist/sgerp/collections/simulation/mapboxtoken.d.ts +18 -0
  71. package/dist/sgerp/collections/simulation/mapboxtoken.d.ts.map +1 -0
  72. package/dist/sgerp/collections/simulation/mapboxtoken.js +24 -0
  73. package/dist/sgerp/collections/simulation/node.js +13 -0
  74. package/dist/sgerp/collections/simulation/operationslocation.d.ts +28 -0
  75. package/dist/sgerp/collections/simulation/operationslocation.d.ts.map +1 -0
  76. package/dist/sgerp/collections/simulation/operationslocation.js +64 -0
  77. package/dist/sgerp/collections/simulation/operationslocationgroup.d.ts +12 -0
  78. package/dist/sgerp/collections/simulation/operationslocationgroup.d.ts.map +1 -0
  79. package/dist/sgerp/collections/simulation/operationslocationgroup.js +24 -0
  80. package/dist/sgerp/collections/simulation/routingprofile.d.ts +10 -0
  81. package/dist/sgerp/collections/simulation/routingprofile.d.ts.map +1 -0
  82. package/dist/sgerp/collections/simulation/routingprofile.js +10 -0
  83. package/dist/sgerp/collections/simulation/simulation.d.ts +12 -0
  84. package/dist/sgerp/collections/simulation/simulation.d.ts.map +1 -0
  85. package/dist/sgerp/collections/simulation/simulation.js +35 -0
  86. package/dist/sgerp/collections/simulation/simulationprocessor.d.ts +19 -0
  87. package/dist/sgerp/collections/simulation/simulationprocessor.d.ts.map +1 -0
  88. package/dist/sgerp/collections/simulation/simulationprocessor.js +27 -0
  89. package/dist/sgerp/collections/simulation/vehicle.js +13 -0
  90. package/dist/sgerp/collections/simulation/vehicletype.d.ts +11 -0
  91. package/dist/sgerp/collections/simulation/vehicletype.d.ts.map +1 -0
  92. package/dist/sgerp/collections/simulation/vehicletype.js +13 -0
  93. package/dist/sgerp/collections/sms_notify/smsscheduled.d.ts +11 -0
  94. package/dist/sgerp/collections/sms_notify/smsscheduled.d.ts.map +1 -0
  95. package/dist/sgerp/collections/sms_notify/smsscheduled.js +13 -0
  96. package/dist/sgerp/collections/transportation/passenger.d.ts +8 -0
  97. package/dist/sgerp/collections/transportation/passenger.d.ts.map +1 -0
  98. package/dist/sgerp/collections/transportation/passenger.js +10 -0
  99. package/dist/sgerp/collections/transportation/ticket.d.ts +11 -0
  100. package/dist/sgerp/collections/transportation/ticket.d.ts.map +1 -0
  101. package/dist/sgerp/collections/transportation/ticket.js +13 -0
  102. package/dist/sgerp/collections/transportation/transaction.d.ts +11 -0
  103. package/dist/sgerp/collections/transportation/transaction.d.ts.map +1 -0
  104. package/dist/sgerp/collections/transportation/transaction.js +13 -0
  105. package/dist/sgerp/constants/bulkoperations-enums.d.ts +71 -0
  106. package/dist/sgerp/constants/bulkoperations-enums.d.ts.map +1 -0
  107. package/dist/sgerp/constants/bulkoperations-enums.js +99 -0
  108. package/dist/sgerp/constants/messages-enums.d.ts +47 -0
  109. package/dist/sgerp/constants/messages-enums.d.ts.map +1 -0
  110. package/dist/sgerp/constants/messages-enums.js +67 -0
  111. package/dist/sgerp/constants/scheduling-enums.d.ts +42 -0
  112. package/dist/sgerp/constants/scheduling-enums.d.ts.map +1 -0
  113. package/dist/sgerp/constants/scheduling-enums.js +61 -0
  114. package/dist/sgerp/constants/simulation-enums.d.ts +93 -0
  115. package/dist/sgerp/constants/simulation-enums.d.ts.map +1 -0
  116. package/dist/sgerp/constants/simulation-enums.js +147 -0
  117. package/dist/sgerp/constants/solver-strategies.d.ts +75 -0
  118. package/dist/sgerp/constants/solver-strategies.d.ts.map +1 -0
  119. package/dist/sgerp/constants/solver-strategies.js +26 -0
  120. package/dist/sgerp/context/sgerp-context.js +134 -0
  121. package/dist/sgerp/domains.d.ts +47 -0
  122. package/dist/sgerp/domains.d.ts.map +1 -0
  123. package/dist/sgerp/domains.js +45 -0
  124. package/dist/sgerp/hooks/use-collection.js +122 -0
  125. package/dist/sgerp/hooks/use-live-updates.js +16 -13
  126. package/dist/sgerp/index.js +153 -0
  127. package/dist/sgerp/map-states/operations-location-state.d.ts +12 -0
  128. package/dist/sgerp/map-states/operations-location-state.d.ts.map +1 -0
  129. package/dist/sgerp/map-states/operations-location-state.js +86 -0
  130. package/dist/sgerp/routing/index.d.ts +51 -0
  131. package/dist/sgerp/routing/index.d.ts.map +1 -0
  132. package/dist/sgerp/routing/index.js +373 -0
  133. package/dist/sgerp/simulation-logic/fetchUtils.js +226 -0
  134. package/dist/sgerp/simulation-logic/index.js +27 -7
  135. package/dist/sgerp/simulation-logic/manualEditUtils.js +69 -0
  136. package/dist/sgerp/simulation-logic/mapUtils.js +58 -0
  137. package/dist/sgerp/simulation-logic/optimisticUpdateUtils.js +8 -5
  138. package/dist/sgerp/simulation-logic/referenceUtils.js +110 -0
  139. package/dist/sgerp/simulation-logic/routeCalculationUtils.js +43 -0
  140. package/dist/sgerp/simulation-logic/timeShiftUtils.js +63 -0
  141. package/dist/sgerp/types/account/user.d.ts +38 -0
  142. package/dist/sgerp/types/account/user.d.ts.map +1 -0
  143. package/dist/sgerp/types/account/user.js +2 -0
  144. package/dist/sgerp/types/bulkoperations/index.d.ts +37 -0
  145. package/dist/sgerp/types/bulkoperations/index.d.ts.map +1 -0
  146. package/dist/sgerp/types/bulkoperations/index.js +35 -0
  147. package/dist/sgerp/types/bulkoperations/vehicle-upload.d.ts +335 -0
  148. package/dist/sgerp/types/bulkoperations/vehicle-upload.d.ts.map +1 -0
  149. package/dist/sgerp/types/bulkoperations/vehicle-upload.js +49 -0
  150. package/dist/sgerp/types/config.d.ts +25 -0
  151. package/dist/sgerp/types/config.d.ts.map +1 -0
  152. package/dist/sgerp/types/config.js +2 -0
  153. package/dist/sgerp/types/geojson.d.ts +45 -0
  154. package/dist/sgerp/types/geojson.d.ts.map +1 -0
  155. package/dist/sgerp/types/geojson.js +6 -0
  156. package/dist/sgerp/types/map.d.ts +24 -0
  157. package/dist/sgerp/types/map.d.ts.map +1 -0
  158. package/dist/sgerp/types/map.js +2 -0
  159. package/dist/sgerp/types/masstransit/building.d.ts +24 -0
  160. package/dist/sgerp/types/masstransit/building.d.ts.map +1 -0
  161. package/dist/sgerp/types/masstransit/building.js +2 -0
  162. package/dist/sgerp/types/masstransit/transitstop.d.ts +35 -0
  163. package/dist/sgerp/types/masstransit/transitstop.d.ts.map +1 -0
  164. package/dist/sgerp/types/masstransit/transitstop.js +2 -0
  165. package/dist/sgerp/types/masstransit/transitstopset.d.ts +14 -0
  166. package/dist/sgerp/types/masstransit/transitstopset.d.ts.map +1 -0
  167. package/dist/sgerp/types/masstransit/transitstopset.js +2 -0
  168. package/dist/sgerp/types/sharing/organization-project.d.ts +14 -0
  169. package/dist/sgerp/types/sharing/organization-project.d.ts.map +1 -0
  170. package/dist/sgerp/types/sharing/organization-project.js +2 -0
  171. package/dist/sgerp/types/sharing/organization.d.ts +14 -0
  172. package/dist/sgerp/types/sharing/organization.d.ts.map +1 -0
  173. package/dist/sgerp/types/sharing/organization.js +2 -0
  174. package/dist/sgerp/types/sharing/pricing.d.ts +98 -0
  175. package/dist/sgerp/types/sharing/pricing.d.ts.map +1 -0
  176. package/dist/sgerp/types/sharing/pricing.js +2 -0
  177. package/dist/sgerp/types/sharing/project-member.d.ts +15 -0
  178. package/dist/sgerp/types/sharing/project-member.d.ts.map +1 -0
  179. package/dist/sgerp/types/sharing/project-member.js +2 -0
  180. package/dist/sgerp/types/sharing/project.d.ts +16 -0
  181. package/dist/sgerp/types/sharing/project.d.ts.map +1 -0
  182. package/dist/sgerp/types/sharing/project.js +2 -0
  183. package/dist/sgerp/types/simulation/booking.d.ts +128 -0
  184. package/dist/sgerp/types/simulation/booking.d.ts.map +1 -0
  185. package/dist/sgerp/types/simulation/booking.js +24 -0
  186. package/dist/sgerp/types/simulation/calculation-params.d.ts +20 -0
  187. package/dist/sgerp/types/simulation/calculation-params.d.ts.map +1 -0
  188. package/dist/sgerp/types/simulation/calculation-params.js +2 -0
  189. package/dist/sgerp/types/simulation/dataset.d.ts +16 -0
  190. package/dist/sgerp/types/simulation/dataset.d.ts.map +1 -0
  191. package/dist/sgerp/types/simulation/dataset.js +2 -0
  192. package/dist/sgerp/types/simulation/driver.d.ts +19 -0
  193. package/dist/sgerp/types/simulation/driver.d.ts.map +1 -0
  194. package/dist/sgerp/types/simulation/driver.js +2 -0
  195. package/dist/sgerp/types/simulation/geofence.d.ts +19 -0
  196. package/dist/sgerp/types/simulation/geofence.d.ts.map +1 -0
  197. package/dist/sgerp/types/simulation/geofence.js +2 -0
  198. package/dist/sgerp/types/simulation/logistics-api-settings.d.ts +98 -0
  199. package/dist/sgerp/types/simulation/logistics-api-settings.d.ts.map +1 -0
  200. package/dist/sgerp/types/simulation/logistics-api-settings.js +104 -0
  201. package/dist/sgerp/types/simulation/mapboxtoken.d.ts +13 -0
  202. package/dist/sgerp/types/simulation/mapboxtoken.d.ts.map +1 -0
  203. package/dist/sgerp/types/simulation/mapboxtoken.js +2 -0
  204. package/dist/sgerp/types/simulation/node.js +5 -2
  205. package/dist/sgerp/types/simulation/operationslocation.d.ts +40 -0
  206. package/dist/sgerp/types/simulation/operationslocation.d.ts.map +1 -0
  207. package/dist/sgerp/types/simulation/operationslocation.js +2 -0
  208. package/dist/sgerp/types/simulation/operationslocationgroup.d.ts +11 -0
  209. package/dist/sgerp/types/simulation/operationslocationgroup.d.ts.map +1 -0
  210. package/dist/sgerp/types/simulation/operationslocationgroup.js +2 -0
  211. package/dist/sgerp/types/simulation/pricing.d.ts +171 -0
  212. package/dist/sgerp/types/simulation/pricing.d.ts.map +1 -0
  213. package/dist/sgerp/types/simulation/pricing.js +2 -0
  214. package/dist/sgerp/types/simulation/route-cost-modification.d.ts +35 -0
  215. package/dist/sgerp/types/simulation/route-cost-modification.d.ts.map +1 -0
  216. package/dist/sgerp/types/simulation/route-cost-modification.js +5 -0
  217. package/dist/sgerp/types/simulation/routing-engine-settings.d.ts +42 -0
  218. package/dist/sgerp/types/simulation/routing-engine-settings.d.ts.map +1 -0
  219. package/dist/sgerp/types/simulation/routing-engine-settings.js +35 -0
  220. package/dist/sgerp/types/simulation/routingprofile.d.ts +32 -0
  221. package/dist/sgerp/types/simulation/routingprofile.d.ts.map +1 -0
  222. package/dist/sgerp/types/simulation/routingprofile.js +37 -0
  223. package/dist/sgerp/types/simulation/simulation.d.ts +120 -0
  224. package/dist/sgerp/types/simulation/simulation.d.ts.map +1 -0
  225. package/dist/sgerp/types/simulation/simulation.js +2 -0
  226. package/dist/sgerp/types/simulation/simulationprocessor.d.ts +31 -0
  227. package/dist/sgerp/types/simulation/simulationprocessor.d.ts.map +1 -0
  228. package/dist/sgerp/types/simulation/simulationprocessor.js +2 -0
  229. package/dist/sgerp/types/simulation/vehicle.js +2 -1
  230. package/dist/sgerp/types/simulation/vehicletype.d.ts +33 -0
  231. package/dist/sgerp/types/simulation/vehicletype.d.ts.map +1 -0
  232. package/dist/sgerp/types/simulation/vehicletype.js +2 -0
  233. package/dist/sgerp/types/sms_notify/smsscheduled.d.ts +36 -0
  234. package/dist/sgerp/types/sms_notify/smsscheduled.d.ts.map +1 -0
  235. package/dist/sgerp/types/sms_notify/smsscheduled.js +6 -0
  236. package/dist/sgerp/types/transportation/passenger.d.ts +49 -0
  237. package/dist/sgerp/types/transportation/passenger.d.ts.map +1 -0
  238. package/dist/sgerp/types/transportation/passenger.js +13 -0
  239. package/dist/sgerp/types/transportation/ticket.d.ts +31 -0
  240. package/dist/sgerp/types/transportation/ticket.d.ts.map +1 -0
  241. package/dist/sgerp/types/transportation/ticket.js +2 -0
  242. package/dist/sgerp/types/transportation/transaction.d.ts +71 -0
  243. package/dist/sgerp/types/transportation/transaction.d.ts.map +1 -0
  244. package/dist/sgerp/types/transportation/transaction.js +54 -0
  245. package/dist/sgerp/utils/bookingPayload.d.ts +80 -0
  246. package/dist/sgerp/utils/bookingPayload.d.ts.map +1 -0
  247. package/dist/sgerp/utils/bookingPayload.js +44 -0
  248. package/dist/sgerp/utils/color.d.ts +30 -0
  249. package/dist/sgerp/utils/color.d.ts.map +1 -0
  250. package/dist/sgerp/utils/color.js +117 -0
  251. package/dist/sgerp/utils/enum-helpers.d.ts +41 -0
  252. package/dist/sgerp/utils/enum-helpers.d.ts.map +1 -0
  253. package/dist/sgerp/utils/enum-helpers.js +54 -0
  254. package/dist/sgerp/utils/routeUtils.js +171 -0
  255. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Utility functions for constructing booking payloads
3
+ * Used by both single booking creation and bulk CSV import
4
+ */
5
+ export interface BookingPayloadInput {
6
+ user_id: string | number;
7
+ pickup_location_lat: number;
8
+ pickup_location_lon: number;
9
+ dropoff_location_lat: number;
10
+ dropoff_location_lon: number;
11
+ service_template_id?: number | string;
12
+ service_session_ids?: string[];
13
+ requested_departure_time?: string;
14
+ requested_destination_time?: string;
15
+ pickup_location_name?: string;
16
+ dropoff_location_name?: string;
17
+ preferred_pickup_stop_id?: number;
18
+ preferred_dropoff_stop_id?: number;
19
+ tickets?: Array<{
20
+ ticket_type: string;
21
+ demand: number;
22
+ }>;
23
+ demand?: Record<string, number>;
24
+ pickup_service_time?: number;
25
+ dropoff_service_time?: number;
26
+ data?: Record<string, unknown>;
27
+ remarks?: string;
28
+ offer_should_be_auto_accepted?: boolean;
29
+ estimate_allow_vehicle_late?: boolean;
30
+ offer_estimation_api_more_details?: boolean;
31
+ lifo_order_check?: boolean;
32
+ lifo_order_penalty?: number;
33
+ passenger_payment_method_id?: number | null;
34
+ payment_method_type?: string;
35
+ groups?: string[];
36
+ id?: string;
37
+ created_at?: string;
38
+ }
39
+ export interface BookingPayload {
40
+ id: string;
41
+ user_id: string | number;
42
+ service_template_id?: number | string;
43
+ service_session_ids: string[];
44
+ pickup_location_lat: number;
45
+ pickup_location_lon: number;
46
+ pickup_location_name?: string;
47
+ preferred_pickup_stop_id?: number;
48
+ dropoff_location_lat: number;
49
+ dropoff_location_lon: number;
50
+ dropoff_location_name?: string;
51
+ preferred_dropoff_stop_id?: number;
52
+ demand: Record<string, number>;
53
+ tickets?: Array<{
54
+ ticket_type: string;
55
+ demand: number;
56
+ }>;
57
+ data?: Record<string, unknown>;
58
+ requested_departure_time?: string;
59
+ requested_destination_time?: string;
60
+ pickup_service_time: number;
61
+ dropoff_service_time: number;
62
+ offer_should_be_auto_accepted: boolean;
63
+ passenger_payment_method_id?: number | null;
64
+ payment_method_type?: string;
65
+ created_at: string;
66
+ operator?: true;
67
+ estimate_allow_vehicle_late?: boolean;
68
+ offer_estimation_api_more_details?: boolean;
69
+ lifo_order_check?: boolean;
70
+ lifo_order_penalty?: number;
71
+ groups?: string[];
72
+ }
73
+ /**
74
+ * Build a booking payload for the /api/v2/microservices/bookings endpoint
75
+ * Handles both single booking creation and bulk import scenarios
76
+ * @param input - Booking input data
77
+ * @param includeOperatorFlag - Whether to include operator: true flag (default: true for backward compatibility)
78
+ */
79
+ export declare function buildBookingPayload(input: BookingPayloadInput, includeOperatorFlag?: boolean): BookingPayload;
80
+ //# sourceMappingURL=bookingPayload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bookingPayload.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/utils/bookingPayload.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for constructing booking payloads
4
+ * Used by both single booking creation and bulk CSV import
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.buildBookingPayload = buildBookingPayload;
8
+ /**
9
+ * Build a booking payload for the /api/v2/microservices/bookings endpoint
10
+ * Handles both single booking creation and bulk import scenarios
11
+ * @param input - Booking input data
12
+ * @param includeOperatorFlag - Whether to include operator: true flag (default: true for backward compatibility)
13
+ */
14
+ function buildBookingPayload(input, includeOperatorFlag = true) {
15
+ var _a, _b, _c;
16
+ // Generate ID if not provided
17
+ const id = input.id || crypto.randomUUID();
18
+ // Build demand object from tickets array or use provided demand
19
+ let demand = {};
20
+ let tickets;
21
+ if (input.tickets && input.tickets.length > 0) {
22
+ // If tickets are provided, use them and create empty demand
23
+ tickets = input.tickets;
24
+ demand = {};
25
+ }
26
+ else if (input.demand && Object.keys(input.demand).length > 0) {
27
+ // If demand is provided, use it (no tickets array)
28
+ demand = input.demand;
29
+ tickets = undefined;
30
+ }
31
+ else {
32
+ // Default: empty demand, no tickets
33
+ demand = {};
34
+ tickets = undefined;
35
+ }
36
+ // Build data object
37
+ const data = Object.assign({}, input.data);
38
+ if (input.remarks) {
39
+ data.remarks = input.remarks;
40
+ }
41
+ // Construct the payload
42
+ const payload = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ id, user_id: input.user_id, service_session_ids: input.service_session_ids || [], pickup_location_lat: input.pickup_location_lat, pickup_location_lon: input.pickup_location_lon, dropoff_location_lat: input.dropoff_location_lat, dropoff_location_lon: input.dropoff_location_lon, demand, pickup_service_time: (_a = input.pickup_service_time) !== null && _a !== void 0 ? _a : 0, dropoff_service_time: (_b = input.dropoff_service_time) !== null && _b !== void 0 ? _b : 0, offer_should_be_auto_accepted: (_c = input.offer_should_be_auto_accepted) !== null && _c !== void 0 ? _c : true, created_at: input.created_at || new Date().toISOString() }, (includeOperatorFlag && { operator: true })), (input.service_template_id && { service_template_id: input.service_template_id })), (input.pickup_location_name && { pickup_location_name: input.pickup_location_name })), (input.dropoff_location_name && { dropoff_location_name: input.dropoff_location_name })), (input.preferred_pickup_stop_id && { preferred_pickup_stop_id: input.preferred_pickup_stop_id })), (input.preferred_dropoff_stop_id && { preferred_dropoff_stop_id: input.preferred_dropoff_stop_id })), (tickets && tickets.length > 0 && { tickets })), (Object.keys(data).length > 0 && { data })), (input.requested_departure_time && { requested_departure_time: input.requested_departure_time })), (input.requested_destination_time && { requested_destination_time: input.requested_destination_time })), (input.passenger_payment_method_id !== undefined && { passenger_payment_method_id: input.passenger_payment_method_id })), (input.payment_method_type && { payment_method_type: input.payment_method_type })), (input.estimate_allow_vehicle_late !== undefined && { estimate_allow_vehicle_late: input.estimate_allow_vehicle_late })), (input.offer_estimation_api_more_details !== undefined && { offer_estimation_api_more_details: input.offer_estimation_api_more_details })), (input.lifo_order_check !== undefined && { lifo_order_check: input.lifo_order_check })), (input.lifo_order_penalty !== undefined && { lifo_order_penalty: input.lifo_order_penalty })), (input.groups && input.groups.length > 0 && { groups: input.groups }));
43
+ return payload;
44
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Convert HSL color values to RGB hex string
3
+ * @param h Hue (0-360)
4
+ * @param s Saturation (0-100)
5
+ * @param l Lightness (0-100)
6
+ * @returns RGB hex color string (e.g., "#ff0000")
7
+ */
8
+ export declare function getHSLToRGB(h: number, s: number, l: number): string;
9
+ /**
10
+ * Generate a color from an agent ID string
11
+ * @param agent_id Agent identifier
12
+ * @returns RGB hex color string
13
+ */
14
+ export declare function getColorFromAgentId(agent_id?: string | number | null): string;
15
+ /**
16
+ * Normalize vehicle color - returns vehicle color or generates one from agent_id if missing
17
+ * @param vehicle Vehicle object with color and agent_id properties
18
+ * @returns Normalized RGB hex color string
19
+ */
20
+ export declare function normalizeVehicleColor(vehicle: {
21
+ color?: string | null;
22
+ agent_id?: string | number | null;
23
+ }): string;
24
+ /**
25
+ * Determine if a background color is light or dark and return appropriate text color
26
+ * @param backgroundColor RGB hex color string
27
+ * @returns '#000000' for light backgrounds, '#ffffff' for dark backgrounds
28
+ */
29
+ export declare function getContrastTextColor(backgroundColor: string): string;
30
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/utils/color.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAyCnE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAe7E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,MAAM,CASnH;AAyBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAIpE"}
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHSLToRGB = getHSLToRGB;
4
+ exports.getColorFromAgentId = getColorFromAgentId;
5
+ exports.normalizeVehicleColor = normalizeVehicleColor;
6
+ exports.getContrastTextColor = getContrastTextColor;
7
+ /**
8
+ * Convert HSL color values to RGB hex string
9
+ * @param h Hue (0-360)
10
+ * @param s Saturation (0-100)
11
+ * @param l Lightness (0-100)
12
+ * @returns RGB hex color string (e.g., "#ff0000")
13
+ */
14
+ function getHSLToRGB(h, s, l) {
15
+ s /= 100;
16
+ l /= 100;
17
+ const c = (1 - Math.abs(2 * l - 1)) * s;
18
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
19
+ const m = l - c / 2;
20
+ let r = 0;
21
+ let g = 0;
22
+ let b = 0;
23
+ if (0 <= h && h < 60) {
24
+ r = c;
25
+ g = x;
26
+ b = 0;
27
+ }
28
+ else if (60 <= h && h < 120) {
29
+ r = x;
30
+ g = c;
31
+ b = 0;
32
+ }
33
+ else if (120 <= h && h < 180) {
34
+ r = 0;
35
+ g = c;
36
+ b = x;
37
+ }
38
+ else if (180 <= h && h < 240) {
39
+ r = 0;
40
+ g = x;
41
+ b = c;
42
+ }
43
+ else if (240 <= h && h < 300) {
44
+ r = x;
45
+ g = 0;
46
+ b = c;
47
+ }
48
+ else if (300 <= h && h < 360) {
49
+ r = c;
50
+ g = 0;
51
+ b = x;
52
+ }
53
+ r = Math.round((r + m) * 255);
54
+ g = Math.round((g + m) * 255);
55
+ b = Math.round((b + m) * 255);
56
+ return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
57
+ }
58
+ /**
59
+ * Generate a color from an agent ID string
60
+ * @param agent_id Agent identifier
61
+ * @returns RGB hex color string
62
+ */
63
+ function getColorFromAgentId(agent_id) {
64
+ if (!agent_id) {
65
+ agent_id = "";
66
+ }
67
+ const DIVIDER = 360;
68
+ const LIGHTNESS = 60; // Lightness in percentage
69
+ const SATURATION = 100; // Saturation in percentage
70
+ const agentIdStr = String(agent_id);
71
+ const hue = Array.from(agentIdStr).reduce((acc, char) => {
72
+ return (acc + char.charCodeAt(0)) % DIVIDER;
73
+ }, 0);
74
+ return getHSLToRGB(hue, SATURATION, LIGHTNESS);
75
+ }
76
+ /**
77
+ * Normalize vehicle color - returns vehicle color or generates one from agent_id if missing
78
+ * @param vehicle Vehicle object with color and agent_id properties
79
+ * @returns Normalized RGB hex color string
80
+ */
81
+ function normalizeVehicleColor(vehicle) {
82
+ if (vehicle.color === undefined ||
83
+ vehicle.color === null ||
84
+ vehicle.color === "#000000") {
85
+ return getColorFromAgentId(vehicle.agent_id);
86
+ }
87
+ return vehicle.color;
88
+ }
89
+ /**
90
+ * Calculate relative luminance of a color
91
+ * @param hex RGB hex color string
92
+ * @returns Luminance value between 0 and 1
93
+ */
94
+ function getRelativeLuminance(hex) {
95
+ // Remove # if present
96
+ hex = hex.replace('#', '');
97
+ // Parse RGB values
98
+ const r = parseInt(hex.substring(0, 2), 16) / 255;
99
+ const g = parseInt(hex.substring(2, 4), 16) / 255;
100
+ const b = parseInt(hex.substring(4, 6), 16) / 255;
101
+ // Apply gamma correction
102
+ const rLinear = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
103
+ const gLinear = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4);
104
+ const bLinear = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4);
105
+ // Calculate relative luminance
106
+ return 0.2126 * rLinear + 0.7152 * gLinear + 0.0722 * bLinear;
107
+ }
108
+ /**
109
+ * Determine if a background color is light or dark and return appropriate text color
110
+ * @param backgroundColor RGB hex color string
111
+ * @returns '#000000' for light backgrounds, '#ffffff' for dark backgrounds
112
+ */
113
+ function getContrastTextColor(backgroundColor) {
114
+ const luminance = getRelativeLuminance(backgroundColor);
115
+ // WCAG threshold: luminance > 0.5 is considered light
116
+ return luminance > 0.5 ? '#000000' : '#ffffff';
117
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Enum Helper Utilities
3
+ * Provides utilities for working with enums and localization
4
+ */
5
+ /**
6
+ * Gets localized options array from an enum and its labels
7
+ * Useful for populating Select/Multiselect components
8
+ *
9
+ * @example
10
+ * const options = getEnumOptions(AlgoType, AlgoTypeLabels, getText);
11
+ * // Returns: [{ value: 'static', label: 'Static' }, ...]
12
+ */
13
+ export declare function getEnumOptions<T extends string>(enumObject: Record<string, T>, labelsMap: Record<T, string>, getText: (key: string) => string): Array<{
14
+ value: T;
15
+ label: string;
16
+ }>;
17
+ /**
18
+ * Gets the localized label for a specific enum value
19
+ *
20
+ * @example
21
+ * const label = getEnumLabel(AlgoType.STATIC, AlgoTypeLabels, getText);
22
+ * // Returns: 'Static'
23
+ */
24
+ export declare function getEnumLabel<T extends string>(value: T, labelsMap: Record<T, string>, getText: (key: string) => string): string;
25
+ /**
26
+ * Gets all enum values as an array
27
+ *
28
+ * @example
29
+ * const values = getEnumValues(AlgoType);
30
+ * // Returns: ['static', 'dynamic', 'dynamic_2_stages', ...]
31
+ */
32
+ export declare function getEnumValues<T extends string>(enumObject: Record<string, T>): T[];
33
+ /**
34
+ * Checks if a value is a valid enum value
35
+ *
36
+ * @example
37
+ * const isValid = isValidEnumValue('static', AlgoType);
38
+ * // Returns: true
39
+ */
40
+ export declare function isValidEnumValue<T extends string>(value: unknown, enumObject: Record<string, T>): value is T;
41
+ //# sourceMappingURL=enum-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-helpers.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/utils/enum-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAC7C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAC7B,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAC/B,KAAK,CAAC;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAKpC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC3C,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAC/B,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAC5B,CAAC,EAAE,CAEL;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAC5B,KAAK,IAAI,CAAC,CAEZ"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * Enum Helper Utilities
4
+ * Provides utilities for working with enums and localization
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getEnumOptions = getEnumOptions;
8
+ exports.getEnumLabel = getEnumLabel;
9
+ exports.getEnumValues = getEnumValues;
10
+ exports.isValidEnumValue = isValidEnumValue;
11
+ /**
12
+ * Gets localized options array from an enum and its labels
13
+ * Useful for populating Select/Multiselect components
14
+ *
15
+ * @example
16
+ * const options = getEnumOptions(AlgoType, AlgoTypeLabels, getText);
17
+ * // Returns: [{ value: 'static', label: 'Static' }, ...]
18
+ */
19
+ function getEnumOptions(enumObject, labelsMap, getText) {
20
+ return Object.values(enumObject).map(value => ({
21
+ value,
22
+ label: getText(labelsMap[value]),
23
+ }));
24
+ }
25
+ /**
26
+ * Gets the localized label for a specific enum value
27
+ *
28
+ * @example
29
+ * const label = getEnumLabel(AlgoType.STATIC, AlgoTypeLabels, getText);
30
+ * // Returns: 'Static'
31
+ */
32
+ function getEnumLabel(value, labelsMap, getText) {
33
+ return getText(labelsMap[value]);
34
+ }
35
+ /**
36
+ * Gets all enum values as an array
37
+ *
38
+ * @example
39
+ * const values = getEnumValues(AlgoType);
40
+ * // Returns: ['static', 'dynamic', 'dynamic_2_stages', ...]
41
+ */
42
+ function getEnumValues(enumObject) {
43
+ return Object.values(enumObject);
44
+ }
45
+ /**
46
+ * Checks if a value is a valid enum value
47
+ *
48
+ * @example
49
+ * const isValid = isValidEnumValue('static', AlgoType);
50
+ * // Returns: true
51
+ */
52
+ function isValidEnumValue(value, enumObject) {
53
+ return typeof value === 'string' && Object.values(enumObject).includes(value);
54
+ }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ /**
3
+ * Route utility functions adapted from dashviewer
4
+ * Generates waypoint routes from nodes without web workers
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.generateWaypointRouteFromNodes = generateWaypointRouteFromNodes;
8
+ exports.validatePickupDropoffConstraint = validatePickupDropoffConstraint;
9
+ exports.createVehicleRoutesFromNodes = createVehicleRoutesFromNodes;
10
+ /**
11
+ * Generate waypoint route from nodes
12
+ * Groups consecutive nodes at the same location into waypoints
13
+ */
14
+ function generateWaypointRouteFromNodes(nodes) {
15
+ const route = [];
16
+ let prev_loc = null;
17
+ let waypointIdParts = [];
18
+ // Filter out transit nodes for cleaner routes
19
+ const clearedNodes = nodes.filter((node) => node.node_type !== 'transit');
20
+ // Google Maps link generation
21
+ const baseUrl = 'https://www.google.com/maps/dir/?api=1';
22
+ let origin = null;
23
+ let destination = null;
24
+ const googleWaypoints = [];
25
+ clearedNodes.forEach((node) => {
26
+ const loc = `${node.lat}-${node.lon}`;
27
+ // New location - create new waypoint
28
+ if (prev_loc !== loc) {
29
+ // Finalize previous waypoint ID
30
+ if (waypointIdParts.length > 0) {
31
+ const waypointId = waypointIdParts.join('-');
32
+ route[route.length - 1].id = waypointId;
33
+ waypointIdParts = [];
34
+ }
35
+ // Create new waypoint
36
+ const waypoint = {
37
+ id: '', // Will be set after collecting all nodes
38
+ idx: route.length + 1,
39
+ sequence: route.length + 1,
40
+ lat: node.lat,
41
+ lon: node.lon,
42
+ location_name: node.display_name || node.location_name || `Location ${route.length + 1}`,
43
+ nodes: [],
44
+ pickup_nodes: [],
45
+ dropoff_nodes: [],
46
+ point_nodes: [],
47
+ transit_nodes: [],
48
+ scheduled_ts: node.scheduled_ts,
49
+ };
50
+ route.push(waypoint);
51
+ // Google Maps link logic
52
+ const coords = `${node.lat},${node.lon}`;
53
+ if (origin === null) {
54
+ origin = coords;
55
+ }
56
+ else if (route.length > 2) {
57
+ googleWaypoints.push(coords);
58
+ }
59
+ destination = coords;
60
+ }
61
+ // Add node to current waypoint
62
+ const currentWaypoint = route[route.length - 1];
63
+ currentWaypoint.nodes.push(node);
64
+ // Group by node type
65
+ if (node.node_type === 'pickup') {
66
+ currentWaypoint.pickup_nodes.push(node);
67
+ }
68
+ else if (node.node_type === 'dropoff') {
69
+ currentWaypoint.dropoff_nodes.push(node);
70
+ }
71
+ else if (node.node_type === 'point') {
72
+ currentWaypoint.point_nodes.push(node);
73
+ }
74
+ else if (node.node_type === 'transit') {
75
+ currentWaypoint.transit_nodes.push(node);
76
+ }
77
+ waypointIdParts.push(`${node.id}`);
78
+ prev_loc = loc;
79
+ });
80
+ // Finalize last waypoint ID
81
+ if (waypointIdParts.length > 0) {
82
+ const waypointId = waypointIdParts.join('-');
83
+ route[route.length - 1].id = waypointId;
84
+ }
85
+ // Finalize Google Maps link
86
+ let googleMapsLink = baseUrl;
87
+ if (origin !== null && destination !== null) {
88
+ const params = new URLSearchParams({
89
+ origin,
90
+ destination,
91
+ travelmode: 'driving',
92
+ });
93
+ if (googleWaypoints.length > 0) {
94
+ params.append('waypoints', googleWaypoints.slice(0, -1).join('|'));
95
+ }
96
+ googleMapsLink = `${baseUrl}&${params.toString()}`;
97
+ }
98
+ return { route, googleMapsLink };
99
+ }
100
+ /**
101
+ * Validate pickup-dropoff constraint
102
+ * Returns error messages if any dropoff happens before its corresponding pickup
103
+ *
104
+ * @param waypoints - Array of waypoints with nodes
105
+ * @returns Array of error messages (empty if valid)
106
+ */
107
+ function validatePickupDropoffConstraint(waypoints) {
108
+ const errors = [];
109
+ const seen = {};
110
+ // Flatten waypoints to nodes while maintaining order
111
+ const allNodes = [];
112
+ waypoints.forEach((waypoint) => {
113
+ waypoint.nodes.forEach((node) => {
114
+ allNodes.push(node);
115
+ });
116
+ });
117
+ // PDP (Pickup-Dropoff Precedence) check
118
+ allNodes.forEach((node) => {
119
+ if (node.node_type === 'pickup') {
120
+ // Mark this booking ID as having been picked up
121
+ seen[node.booking_id] = true;
122
+ }
123
+ else if (node.node_type === 'dropoff') {
124
+ if (!(node.booking_id in seen)) {
125
+ // Error if we see a dropoff without a corresponding pickup
126
+ errors.push(`Dropoff before pickup for booking ID ${node.booking_id} at node ${node.id}`);
127
+ }
128
+ }
129
+ });
130
+ return errors;
131
+ }
132
+ /**
133
+ * Create vehicle route data from nodes
134
+ * Groups nodes by vehicle and generates waypoint routes
135
+ */
136
+ function createVehicleRoutesFromNodes(nodes, vehicleIds) {
137
+ const vehicleRoutes = new Map();
138
+ // Group nodes by vehicle
139
+ const nodesByVehicle = new Map();
140
+ nodes.forEach((node) => {
141
+ if (node.assigned_vehicle_id && node.status === 'assigned') {
142
+ if (!nodesByVehicle.has(node.assigned_vehicle_id)) {
143
+ nodesByVehicle.set(node.assigned_vehicle_id, []);
144
+ }
145
+ nodesByVehicle.get(node.assigned_vehicle_id).push(node);
146
+ }
147
+ });
148
+ // Sort nodes by scheduled time for each vehicle
149
+ nodesByVehicle.forEach((vehicleNodes) => {
150
+ vehicleNodes.sort((a, b) => {
151
+ if (!a.scheduled_ts)
152
+ return 1;
153
+ if (!b.scheduled_ts)
154
+ return -1;
155
+ return new Date(a.scheduled_ts).getTime() - new Date(b.scheduled_ts).getTime();
156
+ });
157
+ });
158
+ // Generate waypoint routes for each vehicle
159
+ vehicleIds.forEach((vehicleId) => {
160
+ const vehicleNodes = nodesByVehicle.get(vehicleId) || [];
161
+ if (vehicleNodes.length > 0) {
162
+ const { route, googleMapsLink } = generateWaypointRouteFromNodes(vehicleNodes);
163
+ vehicleRoutes.set(vehicleId, {
164
+ vehicleId,
165
+ waypoints: route,
166
+ googleMapsLink,
167
+ });
168
+ }
169
+ });
170
+ return vehicleRoutes;
171
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sgerp-frontend-lib",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "TypeScript/React library for interacting with the SGERP API, providing client SDK, Backbone.js-style Collections, and pre-built React components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",