grm-shared-library 1.1.221 → 1.1.222

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 (192) hide show
  1. package/dist/cjs/index.js +1 -0
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/kafka/topics.js +10 -1
  4. package/dist/cjs/kafka/topics.js.map +1 -1
  5. package/dist/cjs/modules/alert-dispatch/dtos/guardian-audience.dto.js +41 -0
  6. package/dist/cjs/modules/alert-dispatch/dtos/guardian-audience.dto.js.map +1 -0
  7. package/dist/cjs/modules/alert-dispatch/index.js +4 -0
  8. package/dist/cjs/modules/alert-dispatch/index.js.map +1 -1
  9. package/dist/cjs/modules/alert-dispatch/interfaces/guardian-audience.js +3 -0
  10. package/dist/cjs/modules/alert-dispatch/interfaces/guardian-audience.js.map +1 -0
  11. package/dist/cjs/modules/alert-dispatch/utils/guardian-audience.util.js +63 -0
  12. package/dist/cjs/modules/alert-dispatch/utils/guardian-audience.util.js.map +1 -0
  13. package/dist/cjs/modules/common/constants/service.const.js +1 -0
  14. package/dist/cjs/modules/common/constants/service.const.js.map +1 -1
  15. package/dist/cjs/modules/gis/dtos/private-trip.dto.js +180 -0
  16. package/dist/cjs/modules/gis/dtos/private-trip.dto.js.map +1 -0
  17. package/dist/cjs/modules/gis/enums/trip-privacy.enum.js +28 -0
  18. package/dist/cjs/modules/gis/enums/trip-privacy.enum.js.map +1 -0
  19. package/dist/cjs/modules/gis/index.js +3 -0
  20. package/dist/cjs/modules/gis/index.js.map +1 -1
  21. package/dist/cjs/modules/gis/interfaces/trip-summary.js +3 -0
  22. package/dist/cjs/modules/gis/interfaces/trip-summary.js.map +1 -0
  23. package/dist/cjs/modules/incident/dtos/incident/incident.dto.js +22 -0
  24. package/dist/cjs/modules/incident/dtos/incident/incident.dto.js.map +1 -1
  25. package/dist/cjs/modules/incident/enums/incident-origin-type.enum.js +17 -0
  26. package/dist/cjs/modules/incident/enums/incident-origin-type.enum.js.map +1 -0
  27. package/dist/cjs/modules/incident/index.js +1 -0
  28. package/dist/cjs/modules/incident/index.js.map +1 -1
  29. package/dist/cjs/modules/organization/index.js +1 -0
  30. package/dist/cjs/modules/organization/index.js.map +1 -1
  31. package/dist/cjs/modules/organization/interfaces/organization-created-event.js +3 -0
  32. package/dist/cjs/modules/organization/interfaces/organization-created-event.js.map +1 -0
  33. package/dist/cjs/modules/permission/data/permissions.data.js +8 -0
  34. package/dist/cjs/modules/permission/data/permissions.data.js.map +1 -1
  35. package/dist/cjs/modules/permission/enums/permission-actions.enum.js +12 -0
  36. package/dist/cjs/modules/permission/enums/permission-actions.enum.js.map +1 -1
  37. package/dist/cjs/modules/permission/enums/permissions-module.enum.js +1 -0
  38. package/dist/cjs/modules/permission/enums/permissions-module.enum.js.map +1 -1
  39. package/dist/cjs/modules/role/constants/safety-roles.js +25 -0
  40. package/dist/cjs/modules/role/constants/safety-roles.js.map +1 -0
  41. package/dist/cjs/modules/role/data/roles.data.js +38 -6
  42. package/dist/cjs/modules/role/data/roles.data.js.map +1 -1
  43. package/dist/cjs/modules/role/index.js +1 -0
  44. package/dist/cjs/modules/role/index.js.map +1 -1
  45. package/dist/cjs/modules/safety/constants/safety-check-limits.const.js +51 -0
  46. package/dist/cjs/modules/safety/constants/safety-check-limits.const.js.map +1 -0
  47. package/dist/cjs/modules/safety/constants/safety-integration.const.js +71 -0
  48. package/dist/cjs/modules/safety/constants/safety-integration.const.js.map +1 -0
  49. package/dist/cjs/modules/safety/constants/safety-taxonomy.const.js +50 -0
  50. package/dist/cjs/modules/safety/constants/safety-taxonomy.const.js.map +1 -0
  51. package/dist/cjs/modules/safety/dtos/safety-admin.dto.js +232 -0
  52. package/dist/cjs/modules/safety/dtos/safety-admin.dto.js.map +1 -0
  53. package/dist/cjs/modules/safety/dtos/safety-check.dto.js +170 -0
  54. package/dist/cjs/modules/safety/dtos/safety-check.dto.js.map +1 -0
  55. package/dist/cjs/modules/safety/dtos/safety-internal.dto.js +162 -0
  56. package/dist/cjs/modules/safety/dtos/safety-internal.dto.js.map +1 -0
  57. package/dist/cjs/modules/safety/enums/safety-check-status.enum.js +45 -0
  58. package/dist/cjs/modules/safety/enums/safety-check-status.enum.js.map +1 -0
  59. package/dist/cjs/modules/safety/enums/safety-enums.js +93 -0
  60. package/dist/cjs/modules/safety/enums/safety-enums.js.map +1 -0
  61. package/dist/cjs/modules/safety/enums/safety-error-code.enum.js +27 -0
  62. package/dist/cjs/modules/safety/enums/safety-error-code.enum.js.map +1 -0
  63. package/dist/cjs/modules/safety/index.js +35 -0
  64. package/dist/cjs/modules/safety/index.js.map +1 -0
  65. package/dist/cjs/modules/safety/interfaces/safety-check-event.js +3 -0
  66. package/dist/cjs/modules/safety/interfaces/safety-check-event.js.map +1 -0
  67. package/dist/cjs/modules/safety/interfaces/safety-check.js +3 -0
  68. package/dist/cjs/modules/safety/interfaces/safety-check.js.map +1 -0
  69. package/dist/cjs/modules/safety/utils/safety-check-state-machine.js +75 -0
  70. package/dist/cjs/modules/safety/utils/safety-check-state-machine.js.map +1 -0
  71. package/dist/cjs/modules/safety/utils/safety-check-timing.util.js +68 -0
  72. package/dist/cjs/modules/safety/utils/safety-check-timing.util.js.map +1 -0
  73. package/dist/cjs/modules/sms/constants/sms-templates.config.js +12 -0
  74. package/dist/cjs/modules/sms/constants/sms-templates.config.js.map +1 -1
  75. package/dist/cjs/modules/sms/enums/sms-template.enum.js +2 -0
  76. package/dist/cjs/modules/sms/enums/sms-template.enum.js.map +1 -1
  77. package/dist/esm/index.js +1 -0
  78. package/dist/esm/index.js.map +1 -1
  79. package/dist/esm/kafka/topics.js +10 -1
  80. package/dist/esm/kafka/topics.js.map +1 -1
  81. package/dist/esm/modules/alert-dispatch/dtos/guardian-audience.dto.js +37 -0
  82. package/dist/esm/modules/alert-dispatch/dtos/guardian-audience.dto.js.map +1 -0
  83. package/dist/esm/modules/alert-dispatch/index.js +4 -0
  84. package/dist/esm/modules/alert-dispatch/index.js.map +1 -1
  85. package/dist/esm/modules/alert-dispatch/interfaces/guardian-audience.js +2 -0
  86. package/dist/esm/modules/alert-dispatch/interfaces/guardian-audience.js.map +1 -0
  87. package/dist/esm/modules/alert-dispatch/utils/guardian-audience.util.js +56 -0
  88. package/dist/esm/modules/alert-dispatch/utils/guardian-audience.util.js.map +1 -0
  89. package/dist/esm/modules/common/constants/service.const.js +1 -0
  90. package/dist/esm/modules/common/constants/service.const.js.map +1 -1
  91. package/dist/esm/modules/gis/dtos/private-trip.dto.js +171 -0
  92. package/dist/esm/modules/gis/dtos/private-trip.dto.js.map +1 -0
  93. package/dist/esm/modules/gis/enums/trip-privacy.enum.js +25 -0
  94. package/dist/esm/modules/gis/enums/trip-privacy.enum.js.map +1 -0
  95. package/dist/esm/modules/gis/index.js +3 -0
  96. package/dist/esm/modules/gis/index.js.map +1 -1
  97. package/dist/esm/modules/gis/interfaces/trip-summary.js +2 -0
  98. package/dist/esm/modules/gis/interfaces/trip-summary.js.map +1 -0
  99. package/dist/esm/modules/incident/dtos/incident/incident.dto.js +23 -1
  100. package/dist/esm/modules/incident/dtos/incident/incident.dto.js.map +1 -1
  101. package/dist/esm/modules/incident/enums/incident-origin-type.enum.js +14 -0
  102. package/dist/esm/modules/incident/enums/incident-origin-type.enum.js.map +1 -0
  103. package/dist/esm/modules/incident/index.js +1 -0
  104. package/dist/esm/modules/incident/index.js.map +1 -1
  105. package/dist/esm/modules/organization/index.js +1 -0
  106. package/dist/esm/modules/organization/index.js.map +1 -1
  107. package/dist/esm/modules/organization/interfaces/organization-created-event.js +2 -0
  108. package/dist/esm/modules/organization/interfaces/organization-created-event.js.map +1 -0
  109. package/dist/esm/modules/permission/data/permissions.data.js +8 -0
  110. package/dist/esm/modules/permission/data/permissions.data.js.map +1 -1
  111. package/dist/esm/modules/permission/enums/permission-actions.enum.js +12 -0
  112. package/dist/esm/modules/permission/enums/permission-actions.enum.js.map +1 -1
  113. package/dist/esm/modules/permission/enums/permissions-module.enum.js +1 -0
  114. package/dist/esm/modules/permission/enums/permissions-module.enum.js.map +1 -1
  115. package/dist/esm/modules/role/constants/safety-roles.js +22 -0
  116. package/dist/esm/modules/role/constants/safety-roles.js.map +1 -0
  117. package/dist/esm/modules/role/data/roles.data.js +38 -6
  118. package/dist/esm/modules/role/data/roles.data.js.map +1 -1
  119. package/dist/esm/modules/role/index.js +1 -0
  120. package/dist/esm/modules/role/index.js.map +1 -1
  121. package/dist/esm/modules/safety/constants/safety-check-limits.const.js +48 -0
  122. package/dist/esm/modules/safety/constants/safety-check-limits.const.js.map +1 -0
  123. package/dist/esm/modules/safety/constants/safety-integration.const.js +67 -0
  124. package/dist/esm/modules/safety/constants/safety-integration.const.js.map +1 -0
  125. package/dist/esm/modules/safety/constants/safety-taxonomy.const.js +45 -0
  126. package/dist/esm/modules/safety/constants/safety-taxonomy.const.js.map +1 -0
  127. package/dist/esm/modules/safety/dtos/safety-admin.dto.js +225 -0
  128. package/dist/esm/modules/safety/dtos/safety-admin.dto.js.map +1 -0
  129. package/dist/esm/modules/safety/dtos/safety-check.dto.js +161 -0
  130. package/dist/esm/modules/safety/dtos/safety-check.dto.js.map +1 -0
  131. package/dist/esm/modules/safety/dtos/safety-internal.dto.js +155 -0
  132. package/dist/esm/modules/safety/dtos/safety-internal.dto.js.map +1 -0
  133. package/dist/esm/modules/safety/enums/safety-check-status.enum.js +42 -0
  134. package/dist/esm/modules/safety/enums/safety-check-status.enum.js.map +1 -0
  135. package/dist/esm/modules/safety/enums/safety-enums.js +90 -0
  136. package/dist/esm/modules/safety/enums/safety-enums.js.map +1 -0
  137. package/dist/esm/modules/safety/enums/safety-error-code.enum.js +24 -0
  138. package/dist/esm/modules/safety/enums/safety-error-code.enum.js.map +1 -0
  139. package/dist/esm/modules/safety/index.js +19 -0
  140. package/dist/esm/modules/safety/index.js.map +1 -0
  141. package/dist/esm/modules/safety/interfaces/safety-check-event.js +2 -0
  142. package/dist/esm/modules/safety/interfaces/safety-check-event.js.map +1 -0
  143. package/dist/esm/modules/safety/interfaces/safety-check.js +2 -0
  144. package/dist/esm/modules/safety/interfaces/safety-check.js.map +1 -0
  145. package/dist/esm/modules/safety/utils/safety-check-state-machine.js +67 -0
  146. package/dist/esm/modules/safety/utils/safety-check-state-machine.js.map +1 -0
  147. package/dist/esm/modules/safety/utils/safety-check-timing.util.js +59 -0
  148. package/dist/esm/modules/safety/utils/safety-check-timing.util.js.map +1 -0
  149. package/dist/esm/modules/sms/constants/sms-templates.config.js +12 -0
  150. package/dist/esm/modules/sms/constants/sms-templates.config.js.map +1 -1
  151. package/dist/esm/modules/sms/enums/sms-template.enum.js +2 -0
  152. package/dist/esm/modules/sms/enums/sms-template.enum.js.map +1 -1
  153. package/dist/types/index.d.ts +1 -0
  154. package/dist/types/kafka/topics.d.ts +4 -0
  155. package/dist/types/modules/alert-dispatch/dtos/guardian-audience.dto.d.ts +6 -0
  156. package/dist/types/modules/alert-dispatch/index.d.ts +3 -0
  157. package/dist/types/modules/alert-dispatch/interfaces/guardian-audience.d.ts +23 -0
  158. package/dist/types/modules/alert-dispatch/utils/guardian-audience.util.d.ts +18 -0
  159. package/dist/types/modules/common/constants/service.const.d.ts +4 -0
  160. package/dist/types/modules/gis/dtos/private-trip.dto.d.ts +42 -0
  161. package/dist/types/modules/gis/enums/trip-privacy.enum.d.ts +22 -0
  162. package/dist/types/modules/gis/index.d.ts +3 -0
  163. package/dist/types/modules/gis/interfaces/client-safe-trip.d.ts +8 -0
  164. package/dist/types/modules/gis/interfaces/trip-summary.d.ts +26 -0
  165. package/dist/types/modules/incident/dtos/incident/incident.dto.d.ts +14 -0
  166. package/dist/types/modules/incident/enums/incident-origin-type.enum.d.ts +12 -0
  167. package/dist/types/modules/incident/index.d.ts +1 -0
  168. package/dist/types/modules/incident/intefaces/incident-category.d.ts +10 -0
  169. package/dist/types/modules/incident/intefaces/incident-type.d.ts +10 -0
  170. package/dist/types/modules/incident/intefaces/incident.d.ts +14 -0
  171. package/dist/types/modules/organization/index.d.ts +1 -0
  172. package/dist/types/modules/organization/interfaces/organization-created-event.d.ts +18 -0
  173. package/dist/types/modules/permission/enums/permission-actions.enum.d.ts +3 -0
  174. package/dist/types/modules/permission/enums/permissions-module.enum.d.ts +2 -1
  175. package/dist/types/modules/role/constants/safety-roles.d.ts +14 -0
  176. package/dist/types/modules/role/index.d.ts +1 -0
  177. package/dist/types/modules/safety/constants/safety-check-limits.const.d.ts +47 -0
  178. package/dist/types/modules/safety/constants/safety-integration.const.d.ts +64 -0
  179. package/dist/types/modules/safety/constants/safety-taxonomy.const.d.ts +31 -0
  180. package/dist/types/modules/safety/dtos/safety-admin.dto.d.ts +39 -0
  181. package/dist/types/modules/safety/dtos/safety-check.dto.d.ts +38 -0
  182. package/dist/types/modules/safety/dtos/safety-internal.dto.d.ts +51 -0
  183. package/dist/types/modules/safety/enums/safety-check-status.enum.d.ts +40 -0
  184. package/dist/types/modules/safety/enums/safety-enums.d.ts +81 -0
  185. package/dist/types/modules/safety/enums/safety-error-code.enum.d.ts +22 -0
  186. package/dist/types/modules/safety/index.d.ts +13 -0
  187. package/dist/types/modules/safety/interfaces/safety-check-event.d.ts +36 -0
  188. package/dist/types/modules/safety/interfaces/safety-check.d.ts +180 -0
  189. package/dist/types/modules/safety/utils/safety-check-state-machine.d.ts +30 -0
  190. package/dist/types/modules/safety/utils/safety-check-timing.util.d.ts +37 -0
  191. package/dist/types/modules/sms/enums/sms-template.enum.d.ts +2 -0
  192. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import { SafetyFeature, SafetyIncidentCategoryCode, SafetyIncidentTypeCode } from '../enums/safety-enums';
2
+ export interface SafetyIncidentTypeDefinition {
3
+ code: SafetyIncidentTypeCode;
4
+ name: string;
5
+ description: string;
6
+ feature: SafetyFeature;
7
+ }
8
+ export interface SafetyIncidentCategoryDefinition {
9
+ code: SafetyIncidentCategoryCode;
10
+ name: string;
11
+ description: string;
12
+ types: readonly SafetyIncidentTypeDefinition[];
13
+ }
14
+ /**
15
+ * The incident category and types EVERY organization receives - existing ones by
16
+ * migration and reconciliation, new ones on `org.created`. There is no
17
+ * per-organization exception (NAVCDP included).
18
+ *
19
+ * They are SYSTEM rows in clarion-incident (`isSystem = true`, matched by
20
+ * `code`, never by name): hidden from the SOS bottom sheet and from package
21
+ * configuration, immutable through the admin API, and raised only by the
22
+ * safety features themselves.
23
+ *
24
+ * Names are stored once at provisioning; renaming here does not rename existing
25
+ * rows.
26
+ */
27
+ export declare const SAFETY_ALERTS_TAXONOMY: SafetyIncidentCategoryDefinition;
28
+ /** The incident type a safety feature raises its SOS as. */
29
+ export declare function safetyIncidentTypeCodeFor(feature: SafetyFeature): SafetyIncidentTypeCode;
30
+ /** True for a code clarion-incident treats as a platform-managed safety type. */
31
+ export declare function isSafetyIncidentTypeCode(code: string | null | undefined): code is SafetyIncidentTypeCode;
@@ -0,0 +1,39 @@
1
+ import { SafetyCheckStatus } from '../enums/safety-check-status.enum';
2
+ /**
3
+ * Filters for the admin Safety Check list. Every field NARROWS what the caller
4
+ * may already see: `organizationId` is honoured only for a super-admin; anybody
5
+ * else is scoped from their trusted context regardless of what arrives here.
6
+ */
7
+ export declare class SafetyCheckAdminQueryDto {
8
+ page?: number;
9
+ limit?: number;
10
+ status?: SafetyCheckStatus;
11
+ organizationId?: number;
12
+ userId?: number;
13
+ sosOnly?: boolean;
14
+ from?: string;
15
+ to?: string;
16
+ id?: string;
17
+ }
18
+ export declare class CreateSafetyCheckReasonDto {
19
+ code: string;
20
+ label: string;
21
+ description?: string;
22
+ organizationId?: number;
23
+ countryCode?: string;
24
+ isCustom?: boolean;
25
+ active?: boolean;
26
+ displayOrder?: number;
27
+ }
28
+ /** Code, organization and custom-ness are fixed once created; everything shown to users can change. */
29
+ export declare class UpdateSafetyCheckReasonDto {
30
+ label?: string;
31
+ description?: string | null;
32
+ countryCode?: string | null;
33
+ active?: boolean;
34
+ displayOrder?: number;
35
+ }
36
+ export declare class SafetyCheckReasonAdminQueryDto {
37
+ organizationId?: number;
38
+ includeInactive?: boolean;
39
+ }
@@ -0,0 +1,38 @@
1
+ import { GuardianAudienceDto } from '../../alert-dispatch/dtos/guardian-audience.dto';
2
+ /** A device-reported position. Never logged by any Safety service. */
3
+ export declare class SafetyCheckLocationDto {
4
+ lat: number;
5
+ lng: number;
6
+ accuracy?: number;
7
+ }
8
+ /**
9
+ * Starting a Safety Check.
10
+ *
11
+ * Nothing here is trusted beyond its shape: clarion-safety re-checks the reason
12
+ * against the database, every guardian against clarion-authentication, and the
13
+ * provider option against clarion-billing. The duration is bounded here AND in
14
+ * the domain.
15
+ */
16
+ export declare class StartSafetyCheckDto {
17
+ reasonId: string;
18
+ customReason?: string;
19
+ durationMinutes: number;
20
+ promptCountdownSeconds?: number;
21
+ guardians: GuardianAudienceDto;
22
+ notifyServiceProvider: boolean;
23
+ notifyGuardiansOnStartEnd: boolean;
24
+ startLocation?: SafetyCheckLocationDto;
25
+ }
26
+ export declare class ExtendSafetyCheckDto {
27
+ additionalMinutes: number;
28
+ }
29
+ /** Body of check-in, stop and manual SOS. The location is optional context. */
30
+ export declare class SafetyCheckActionDto {
31
+ location?: SafetyCheckLocationDto;
32
+ }
33
+ export declare class SafetyCheckTrackPointDto extends SafetyCheckLocationDto {
34
+ timestamp: string;
35
+ }
36
+ export declare class SafetyCheckTrackPointsDto {
37
+ points: SafetyCheckTrackPointDto[];
38
+ }
@@ -0,0 +1,51 @@
1
+ import { GuardianAudienceDto } from '../../alert-dispatch/dtos/guardian-audience.dto';
2
+ import { SafetyCheckSosTrigger, SafetyFeature } from '../enums/safety-enums';
3
+ import { SafetyCheckLocationDto } from './safety-check.dto';
4
+ /**
5
+ * clarion-safety -> clarion-incident: raise the SOS for a safety feature.
6
+ *
7
+ * Internal only (never proxied by the gateway) and token-protected. Idempotent on
8
+ * (feature, originReferenceId): a retry - from a workflow, the sweeper, or a user
9
+ * pressing twice - returns the incident the first call created.
10
+ *
11
+ * clarion-incident builds the incident itself: the reporter from the user's
12
+ * account, the Safety Alerts category and type from the organization's system
13
+ * rows, and entitlement/dispatch through the same pipeline as every SOS. The
14
+ * caller cannot choose a type, a class or an entitlement tier.
15
+ */
16
+ export declare class CreateSafetyAlertIncidentDto {
17
+ feature: SafetyFeature;
18
+ originReferenceId: string;
19
+ trigger: SafetyCheckSosTrigger;
20
+ organizationId: number;
21
+ userId: number;
22
+ appId: string;
23
+ controlCentreId?: number;
24
+ location?: SafetyCheckLocationDto;
25
+ notifyServiceProvider: boolean;
26
+ guardianAudience: GuardianAudienceDto;
27
+ tripId?: string;
28
+ description?: string;
29
+ }
30
+ /** clarion-safety -> clarion-workflow-manager: start the durable timer. Idempotent per check. */
31
+ export declare class StartSafetyCheckWorkflowDto {
32
+ safetyCheckId: string;
33
+ firstWakeAt: string;
34
+ }
35
+ /**
36
+ * clarion-safety -> clarion-workflow-manager: something changed. Purely an
37
+ * optimisation - a lost signal only means the workflow wakes at its previous
38
+ * time and asks clarion-safety, which answers with the truth.
39
+ */
40
+ export declare class SignalSafetyCheckWorkflowDto {
41
+ done?: boolean;
42
+ nextWakeAt?: string;
43
+ }
44
+ /**
45
+ * clarion-billing -> clarion-incident: which of these incident type ids are
46
+ * platform-managed system types (the Safety SOS types). Billing refuses to put
47
+ * those in a package, whatever the admin UI shows.
48
+ */
49
+ export declare class ClassifyIncidentTypesDto {
50
+ ids: number[];
51
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Lifecycle of one Safety Check. clarion-safety is the only writer; every
3
+ * transition is validated against SAFETY_CHECK_TRANSITIONS
4
+ * (utils/safety-check-state-machine.ts) and applied as a conditional update, so
5
+ * two racing writers can never both win.
6
+ *
7
+ * CREATED accepted and persisted; tracking and the durable timer are
8
+ * still being set up. The user already counts as being in a
9
+ * check (the clock started when it was accepted).
10
+ * ACTIVE running; the user is expected to check in at
11
+ * scheduledCheckInAt.
12
+ * PROMPTING the check-in time has passed and the user is being asked to
13
+ * confirm they are safe. SOS is raised at promptDeadlineAt.
14
+ * CHECKED_IN the user confirmed they are safe. Terminal, successful.
15
+ * SOS_TRIGGERED an SOS was raised - the user missed the check-in or asked for
16
+ * one. Terminal for the check; the incident lives on in
17
+ * clarion-incident. `incidentId` is null until the incident
18
+ * has been created (clarion-safety keeps retrying).
19
+ * STOPPED the user ended the check before it completed. Terminal.
20
+ * EXPIRED the check-in window closed so long ago (a platform outage
21
+ * longer than SAFETY_CHECK_LIMITS.staleSosWindowMinutes) that
22
+ * raising an SOS now would be noise rather than help. Terminal;
23
+ * always an operational alarm.
24
+ * CANCELLED ended by the platform rather than the user (e.g. the account
25
+ * was signed out and the user chose to end it). Terminal.
26
+ * FAILED the SOS could not be raised because clarion-incident refused
27
+ * it outright (a non-retryable error). Terminal; the user is
28
+ * told to call for help and operators are alerted.
29
+ */
30
+ export declare enum SafetyCheckStatus {
31
+ CREATED = "CREATED",
32
+ ACTIVE = "ACTIVE",
33
+ PROMPTING = "PROMPTING",
34
+ CHECKED_IN = "CHECKED_IN",
35
+ SOS_TRIGGERED = "SOS_TRIGGERED",
36
+ STOPPED = "STOPPED",
37
+ EXPIRED = "EXPIRED",
38
+ CANCELLED = "CANCELLED",
39
+ FAILED = "FAILED"
40
+ }
@@ -0,0 +1,81 @@
1
+ /** Why a Safety Check raised an SOS. */
2
+ export declare enum SafetyCheckSosTrigger {
3
+ /** The prompt countdown ran out without the user confirming they were safe. */
4
+ MISSED_CHECK_IN = "MISSED_CHECK_IN",
5
+ /** The user pressed SOS from the Safety Check screen. */
6
+ USER_REQUESTED = "USER_REQUESTED"
7
+ }
8
+ /** Who caused a Safety Check transition - recorded on every audit entry. */
9
+ export declare enum SafetyCheckActorType {
10
+ USER = "USER",
11
+ /** The durable timer in clarion-workflow-manager. */
12
+ WORKFLOW = "WORKFLOW",
13
+ /** clarion-safety's backstop sweeper, acting on an overdue check. */
14
+ RECONCILER = "RECONCILER",
15
+ SYSTEM = "SYSTEM"
16
+ }
17
+ /** Audit trail entries (safety_check_events.eventType). Never carries a location. */
18
+ export declare enum SafetyCheckAuditEventType {
19
+ CREATED = "CREATED",
20
+ ACTIVATED = "ACTIVATED",
21
+ TRACKING_STARTED = "TRACKING_STARTED",
22
+ TRACKING_UNAVAILABLE = "TRACKING_UNAVAILABLE",
23
+ WORKFLOW_STARTED = "WORKFLOW_STARTED",
24
+ WORKFLOW_START_FAILED = "WORKFLOW_START_FAILED",
25
+ EXTENDED = "EXTENDED",
26
+ PROMPT_STARTED = "PROMPT_STARTED",
27
+ CHECKED_IN = "CHECKED_IN",
28
+ STOPPED = "STOPPED",
29
+ CANCELLED = "CANCELLED",
30
+ SOS_TRIGGERED = "SOS_TRIGGERED",
31
+ SOS_INCIDENT_CREATED = "SOS_INCIDENT_CREATED",
32
+ SOS_INCIDENT_RETRY = "SOS_INCIDENT_RETRY",
33
+ SOS_FAILED = "SOS_FAILED",
34
+ EXPIRED = "EXPIRED"
35
+ }
36
+ /**
37
+ * The safety features that can raise an incident. Phase 1 raises only
38
+ * SAFETY_CHECK; FOLLOW_ME exists because its incident type is provisioned for
39
+ * every organization from day one.
40
+ */
41
+ export declare enum SafetyFeature {
42
+ SAFETY_CHECK = "SAFETY_CHECK",
43
+ FOLLOW_ME = "FOLLOW_ME"
44
+ }
45
+ /** Stable code of the incident category every organization receives. */
46
+ export declare enum SafetyIncidentCategoryCode {
47
+ SAFETY_ALERTS = "SAFETY_ALERTS"
48
+ }
49
+ /** Stable codes of the incident types inside the Safety Alerts category. */
50
+ export declare enum SafetyIncidentTypeCode {
51
+ SAFETY_CHECK_SOS = "SAFETY_CHECK_SOS",
52
+ FOLLOW_ME_SOS = "FOLLOW_ME_SOS"
53
+ }
54
+ /**
55
+ * Kafka event types published by clarion-safety (the `eventType` field of
56
+ * SafetyCheckEvent). One topic per type, see KAFKA_TOPICS.SAFETY_CHECK_*.
57
+ */
58
+ export declare enum SafetyCheckEventType {
59
+ STARTED = "SAFETY_CHECK_STARTED",
60
+ PROMPTING = "SAFETY_CHECK_PROMPTING",
61
+ ENDED = "SAFETY_CHECK_ENDED",
62
+ SOS_TRIGGERED = "SAFETY_CHECK_SOS_TRIGGERED"
63
+ }
64
+ /**
65
+ * Push `data.action` / `data.type` values the mobile app routes on. Sent by
66
+ * clarion-notification; the app allow-lists them in
67
+ * notification_deep_link_coordinator.dart. Changing a value is a breaking
68
+ * change to installed apps.
69
+ */
70
+ export declare enum SafetyPushAction {
71
+ /** To the user: it is time to confirm you are safe. */
72
+ SAFETY_CHECK_PROMPT = "SAFETY_CHECK_PROMPT",
73
+ /** To the user: an SOS was raised for your Safety Check. */
74
+ SAFETY_CHECK_SOS_TRIGGERED = "SAFETY_CHECK_SOS_TRIGGERED",
75
+ /** To the user: the Safety Check ended without them (FAILED/EXPIRED/CANCELLED). */
76
+ SAFETY_CHECK_ENDED = "SAFETY_CHECK_ENDED",
77
+ /** To a guardian: somebody who chose you started a Safety Check. */
78
+ SAFETY_CHECK_GUARDIAN_STARTED = "SAFETY_CHECK_GUARDIAN_STARTED",
79
+ /** To a guardian: that Safety Check ended safely. */
80
+ SAFETY_CHECK_GUARDIAN_ENDED = "SAFETY_CHECK_GUARDIAN_ENDED"
81
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Machine-readable `code` on every error clarion-safety returns, so the app can
3
+ * react (e.g. adopt the check a duplicate start collided with) without parsing
4
+ * the human message.
5
+ */
6
+ export declare enum SafetyCheckErrorCode {
7
+ NOT_FOUND = "SAFETY_CHECK_NOT_FOUND",
8
+ ALREADY_ACTIVE = "SAFETY_CHECK_ALREADY_ACTIVE",
9
+ ALREADY_ENDED = "SAFETY_CHECK_ENDED",
10
+ SOS_ALREADY_TRIGGERED = "SAFETY_CHECK_SOS_ALREADY_TRIGGERED",
11
+ INVALID_TRANSITION = "SAFETY_CHECK_INVALID_TRANSITION",
12
+ INVALID_DURATION = "SAFETY_CHECK_INVALID_DURATION",
13
+ MAX_DURATION_EXCEEDED = "SAFETY_CHECK_MAX_DURATION_EXCEEDED",
14
+ INVALID_REASON = "SAFETY_CHECK_INVALID_REASON",
15
+ CUSTOM_REASON_REQUIRED = "SAFETY_CHECK_CUSTOM_REASON_REQUIRED",
16
+ GUARDIAN_NOT_FOUND = "SAFETY_CHECK_GUARDIAN_NOT_FOUND",
17
+ GUARDIANS_UNAVAILABLE = "SAFETY_CHECK_GUARDIANS_UNAVAILABLE",
18
+ NO_SOS_RECIPIENTS = "SAFETY_CHECK_NO_SOS_RECIPIENTS",
19
+ SERVICE_PROVIDER_NOT_ENTITLED = "SAFETY_CHECK_SERVICE_PROVIDER_NOT_ENTITLED",
20
+ TRACKING_CLOSED = "SAFETY_CHECK_TRACKING_CLOSED",
21
+ RATE_LIMITED = "SAFETY_CHECK_RATE_LIMITED"
22
+ }
@@ -0,0 +1,13 @@
1
+ export * from './enums/safety-check-status.enum';
2
+ export * from './enums/safety-enums';
3
+ export * from './enums/safety-error-code.enum';
4
+ export * from './constants/safety-check-limits.const';
5
+ export * from './constants/safety-taxonomy.const';
6
+ export * from './constants/safety-integration.const';
7
+ export * from './interfaces/safety-check';
8
+ export * from './interfaces/safety-check-event';
9
+ export * from './dtos/safety-check.dto';
10
+ export * from './dtos/safety-admin.dto';
11
+ export * from './dtos/safety-internal.dto';
12
+ export * from './utils/safety-check-state-machine';
13
+ export * from './utils/safety-check-timing.util';
@@ -0,0 +1,36 @@
1
+ import { GuardianAudience } from '../../alert-dispatch/interfaces/guardian-audience';
2
+ import { SafetyCheckStatus } from '../enums/safety-check-status.enum';
3
+ import { SafetyCheckEventType, SafetyCheckSosTrigger } from '../enums/safety-enums';
4
+ /**
5
+ * The Kafka payload for every KAFKA_TOPICS.SAFETY_CHECK_* topic. Published by
6
+ * clarion-safety through its transactional outbox (at-least-once, keyed by the
7
+ * check id so one check's events stay in order); consumers dedupe on `eventId`.
8
+ *
9
+ * Carries NO location. `guardianAudience` holds guardian identifiers because
10
+ * clarion-notification needs them to reach exactly the chosen guardians.
11
+ */
12
+ export interface SafetyCheckEvent {
13
+ eventId: string;
14
+ eventType: SafetyCheckEventType;
15
+ version: 1;
16
+ occurredAt: string;
17
+ correlationId: string | null;
18
+ safetyCheckId: string;
19
+ userId: number;
20
+ organizationId: number;
21
+ controlCentreId: number | null;
22
+ appId: string | null;
23
+ countryCode: string | null;
24
+ status: SafetyCheckStatus;
25
+ reasonLabel: string;
26
+ durationMinutes: number;
27
+ startedAt: string;
28
+ scheduledCheckInAt: string;
29
+ promptStartedAt: string | null;
30
+ promptDeadlineAt: string | null;
31
+ endedAt: string | null;
32
+ notifyGuardiansOnStartEnd: boolean;
33
+ guardianAudience: GuardianAudience;
34
+ sosTrigger: SafetyCheckSosTrigger | null;
35
+ incidentId: number | null;
36
+ }
@@ -0,0 +1,180 @@
1
+ import { GuardianAudience } from '../../alert-dispatch/interfaces/guardian-audience';
2
+ import { SafetyCheckStatus } from '../enums/safety-check-status.enum';
3
+ import { SafetyCheckActorType, SafetyCheckAuditEventType, SafetyCheckSosTrigger } from '../enums/safety-enums';
4
+ /** A reason as the app's dropdown shows it. */
5
+ export interface SafetyCheckReasonView {
6
+ id: string;
7
+ code: string;
8
+ label: string;
9
+ description: string | null;
10
+ /** The "Write my own" entry: the user types the reason. */
11
+ isCustom: boolean;
12
+ displayOrder: number;
13
+ }
14
+ /** A reason as the admin manages it. */
15
+ export interface SafetyCheckReasonAdminView extends SafetyCheckReasonView {
16
+ /** Null for a platform-wide reason. */
17
+ organizationId: number | null;
18
+ /** Null for every country. */
19
+ countryCode: string | null;
20
+ active: boolean;
21
+ createdAt: string;
22
+ updatedAt: string;
23
+ }
24
+ /**
25
+ * One Safety Check as its owner sees it.
26
+ *
27
+ * Timestamps are ISO 8601 from the SERVER clock. `serverTime` lets the app work
28
+ * out its own clock skew: remaining = scheduledCheckInAt - serverTime, counted
29
+ * down from when the response arrived.
30
+ */
31
+ export interface SafetyCheckView {
32
+ id: string;
33
+ status: SafetyCheckStatus;
34
+ reasonId: string | null;
35
+ reasonCode: string | null;
36
+ /** What to show: the typed reason for "Write my own", else the reason's label at start. */
37
+ reasonLabel: string;
38
+ customReason: string | null;
39
+ /** Total minutes from start to the (possibly extended) check-in time. */
40
+ durationMinutes: number;
41
+ extensionCount: number;
42
+ startedAt: string;
43
+ scheduledCheckInAt: string;
44
+ promptCountdownSeconds: number;
45
+ promptStartedAt: string | null;
46
+ /** When the visible countdown ends. */
47
+ promptDeadlineAt: string | null;
48
+ checkedInAt: string | null;
49
+ endedAt: string | null;
50
+ guardians: GuardianAudience;
51
+ notifyGuardiansOnStartEnd: boolean;
52
+ /** What the user asked for. */
53
+ notifyServiceProviderRequested: boolean;
54
+ /** Whether the provider option was available to them at start (billing). */
55
+ notifyServiceProviderAllowed: boolean;
56
+ sosTrigger: SafetyCheckSosTrigger | null;
57
+ sosTriggeredAt: string | null;
58
+ /** Null until clarion-incident has created the SOS. */
59
+ incidentId: number | null;
60
+ tripId: string | null;
61
+ serverTime: string;
62
+ }
63
+ export interface SafetyCheckCurrentResponse {
64
+ /** The user's open check, or the one that most recently raised an SOS still awaiting its incident. */
65
+ check: SafetyCheckView | null;
66
+ serverTime: string;
67
+ }
68
+ /** What the setup screens need from the server, so client and server agree. */
69
+ export interface SafetyCheckStartOptions {
70
+ limits: {
71
+ minDurationMinutes: number;
72
+ maxDurationMinutes: number;
73
+ presetDurationsMinutes: number[];
74
+ minPromptCountdownSeconds: number;
75
+ maxPromptCountdownSeconds: number;
76
+ customReasonMaxLength: number;
77
+ };
78
+ defaults: {
79
+ durationMinutes: number;
80
+ promptCountdownSeconds: number;
81
+ notifyServiceProvider: boolean;
82
+ notifyGuardiansOnStartEnd: boolean;
83
+ };
84
+ serviceProvider: {
85
+ /** Offer the "notify the service provider" option at all. */
86
+ available: boolean;
87
+ /** Billing tier (PREMIUM/TRIAL/FREE), null when billing could not be asked. */
88
+ tier: string | null;
89
+ /** Billing could not be asked; the option is offered and the SOS decides. */
90
+ degraded: boolean;
91
+ };
92
+ serverTime: string;
93
+ }
94
+ /** The recorded trip, WITHOUT coordinates - location is never shown before an SOS. */
95
+ export interface SafetyCheckTripSummary {
96
+ id: string;
97
+ status: string;
98
+ visibility: string;
99
+ purpose: string;
100
+ incidentId: number | null;
101
+ startedAt: string;
102
+ endedAt: string | null;
103
+ sharedAt: string | null;
104
+ distanceMeters: number | null;
105
+ trackPointCount: number;
106
+ }
107
+ export interface SafetyCheckAuditEntry {
108
+ id: string;
109
+ eventType: SafetyCheckAuditEventType;
110
+ fromStatus: SafetyCheckStatus | null;
111
+ toStatus: SafetyCheckStatus | null;
112
+ actorType: SafetyCheckActorType;
113
+ actorUserId: number | null;
114
+ /** Identifiers and timings only - never a location or a message body. */
115
+ metadata: Record<string, unknown> | null;
116
+ createdAt: string;
117
+ }
118
+ /** A row of the admin list. */
119
+ export interface SafetyCheckAdminListItem {
120
+ id: string;
121
+ status: SafetyCheckStatus;
122
+ userId: number;
123
+ userName: string | null;
124
+ organizationId: number;
125
+ controlCentreId: number | null;
126
+ reasonLabel: string;
127
+ durationMinutes: number;
128
+ startedAt: string;
129
+ scheduledCheckInAt: string;
130
+ checkedInAt: string | null;
131
+ endedAt: string | null;
132
+ sosTrigger: SafetyCheckSosTrigger | null;
133
+ incidentId: number | null;
134
+ createdAt: string;
135
+ }
136
+ /** The admin detail view. */
137
+ export interface SafetyCheckAdminDetail {
138
+ check: SafetyCheckView & {
139
+ userId: number;
140
+ userName: string | null;
141
+ userPhoneNumber: string | null;
142
+ organizationId: number;
143
+ controlCentreId: number | null;
144
+ appId: string | null;
145
+ countryCode: string | null;
146
+ entitlementTierAtStart: string | null;
147
+ workflowId: string | null;
148
+ workflowStartedAt: string | null;
149
+ trackPointCount: number;
150
+ lastLocationAt: string | null;
151
+ sosAttempts: number;
152
+ sosFailureReason: string | null;
153
+ createdAt: string;
154
+ updatedAt: string;
155
+ };
156
+ events: SafetyCheckAuditEntry[];
157
+ trip: SafetyCheckTripSummary | null;
158
+ }
159
+ /** What the durable timer gets back from every advance. */
160
+ export interface SafetyCheckAdvanceResult {
161
+ status: SafetyCheckStatus;
162
+ /** Nothing more for the timer to do. */
163
+ done: boolean;
164
+ /** When to call advance again (server clock). Null when done. */
165
+ nextWakeAt: string | null;
166
+ }
167
+ /** clarion-incident's answer to CreateSafetyAlertIncidentDto. */
168
+ export interface SafetyAlertIncidentResult {
169
+ incidentId: number;
170
+ /** False when an earlier call already created it (idempotent replay). */
171
+ created: boolean;
172
+ conversationId: string | null;
173
+ notifyServiceProvider: boolean;
174
+ notifyGuardians: boolean;
175
+ entitlementTier: string | null;
176
+ }
177
+ /** clarion-incident's answer to "which of these type ids are system types". */
178
+ export interface IncidentTypeClassification {
179
+ systemTypeIds: number[];
180
+ }
@@ -0,0 +1,30 @@
1
+ import { SafetyCheckStatus } from '../enums/safety-check-status.enum';
2
+ /**
3
+ * Every legal Safety Check transition. clarion-safety refuses anything else, and
4
+ * applies each allowed one as `UPDATE ... WHERE status IN (<allowed sources>)`, so
5
+ * the database - not the caller - decides a race.
6
+ *
7
+ * Re-applying a transition to a check already in the target state is NOT listed
8
+ * here: it is an idempotent no-op, answered with the current check
9
+ * (see isIdempotentRepeat).
10
+ */
11
+ export declare const SAFETY_CHECK_TRANSITIONS: Readonly<Record<SafetyCheckStatus, readonly SafetyCheckStatus[]>>;
12
+ /** States in which the user is "in a Safety Check": at most one per user. */
13
+ export declare const OPEN_SAFETY_CHECK_STATUSES: readonly SafetyCheckStatus[];
14
+ /** States from which the check will never move again. */
15
+ export declare const TERMINAL_SAFETY_CHECK_STATUSES: readonly SafetyCheckStatus[];
16
+ /**
17
+ * States in which location is still being recorded for the check. SOS_TRIGGERED
18
+ * is included: the recorded trip becomes the incident's trip and keeps growing.
19
+ */
20
+ export declare const TRACKING_SAFETY_CHECK_STATUSES: readonly SafetyCheckStatus[];
21
+ export declare function isOpenSafetyCheckStatus(status: SafetyCheckStatus | string | null | undefined): boolean;
22
+ export declare function isTerminalSafetyCheckStatus(status: SafetyCheckStatus | string | null | undefined): boolean;
23
+ export declare function canTransitionSafetyCheck(from: SafetyCheckStatus, to: SafetyCheckStatus): boolean;
24
+ /** The states a check may be in for a transition to `to` to be applied. */
25
+ export declare function allowedSourcesFor(to: SafetyCheckStatus): SafetyCheckStatus[];
26
+ /**
27
+ * A repeated request for the state the check is already in - a retried "I'm OK",
28
+ * a second stop. Answered with the current check, never an error.
29
+ */
30
+ export declare function isIdempotentRepeat(current: SafetyCheckStatus, requested: SafetyCheckStatus): boolean;
@@ -0,0 +1,37 @@
1
+ export interface SafetyCheckDurationValidation {
2
+ valid: boolean;
3
+ reason?: 'NOT_AN_INTEGER' | 'TOO_SHORT' | 'TOO_LONG';
4
+ }
5
+ /** Validates a requested duration against the platform limits. */
6
+ export declare function validateSafetyCheckDuration(minutes: unknown): SafetyCheckDurationValidation;
7
+ /** Whether a prompt countdown (seconds) is within the configurable range. */
8
+ export declare function isValidPromptCountdownSeconds(seconds: unknown): boolean;
9
+ /** The latest moment a check started at `startedAt` may be scheduled to check in. */
10
+ export declare function latestAllowedCheckInAt(startedAt: Date): Date;
11
+ export interface SafetyCheckExtensionPlan {
12
+ allowed: boolean;
13
+ /** New check-in time when allowed. */
14
+ scheduledCheckInAt?: Date;
15
+ /** Total minutes from start to the new check-in time. */
16
+ totalDurationMinutes?: number;
17
+ /** Most minutes that could still be added right now (0 when at the cap). */
18
+ maxAdditionalMinutes: number;
19
+ }
20
+ /**
21
+ * Plans an extension. While the check-in time is still ahead the extension is
22
+ * added to it; once it has passed (the user is being prompted) it counts from
23
+ * now. Either way the result may not end more than maxDurationMinutes after the
24
+ * check started - an extension never lets a check outlive the 24 hour cap.
25
+ */
26
+ export declare function planSafetyCheckExtension(input: {
27
+ startedAt: Date;
28
+ scheduledCheckInAt: Date;
29
+ now: Date;
30
+ additionalMinutes: number;
31
+ }): SafetyCheckExtensionPlan;
32
+ /** When the prompt shown at `promptStartedAt` runs out (what the user sees). */
33
+ export declare function promptDeadlineFrom(promptStartedAt: Date, promptCountdownSeconds: number): Date;
34
+ /** When the server actually raises the SOS: the visible deadline plus the grace. */
35
+ export declare function sosDueAt(promptDeadlineAt: Date): Date;
36
+ /** Whether an SOS that fell due at `dueAt` is too stale to raise at `now`. */
37
+ export declare function isSosTooStale(dueAt: Date, now: Date): boolean;
@@ -6,6 +6,8 @@ export declare enum SmsTemplateType {
6
6
  SECURITY_ALERT = "security_alert",
7
7
  INCIDENT_NOTIFICATION = "incident_notification",
8
8
  INCIDENT_GUARDIAN_NOTIFICATION = "incident_guardian_notification",
9
+ SAFETY_CHECK_GUARDIAN_STARTED = "safety_check_guardian_started",
10
+ SAFETY_CHECK_GUARDIAN_ENDED = "safety_check_guardian_ended",
9
11
  APPOINTMENT_REMINDER = "appointment_reminder",
10
12
  GENERAL_NOTIFICATION = "general_notification"
11
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grm-shared-library",
3
- "version": "1.1.221",
3
+ "version": "1.1.222",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",