grm-shared-library 1.1.205 → 1.1.206

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 (51) hide show
  1. package/dist/cjs/exceptions/filters/http-exceptions.filter.js +19 -2
  2. package/dist/cjs/exceptions/filters/http-exceptions.filter.js.map +1 -1
  3. package/dist/cjs/modules/common/decorators/calendar-date.decorator.js +59 -0
  4. package/dist/cjs/modules/common/decorators/calendar-date.decorator.js.map +1 -0
  5. package/dist/cjs/modules/common/index.js +2 -0
  6. package/dist/cjs/modules/common/index.js.map +1 -1
  7. package/dist/cjs/modules/common/utils/calendar-date.util.js +148 -0
  8. package/dist/cjs/modules/common/utils/calendar-date.util.js.map +1 -0
  9. package/dist/cjs/modules/partner/dtos/partner-member-profile.dto.js +2 -3
  10. package/dist/cjs/modules/partner/dtos/partner-member-profile.dto.js.map +1 -1
  11. package/dist/cjs/modules/partner/index.js +1 -0
  12. package/dist/cjs/modules/partner/index.js.map +1 -1
  13. package/dist/cjs/modules/partner/interfaces/partner-member-readiness.js +3 -0
  14. package/dist/cjs/modules/partner/interfaces/partner-member-readiness.js.map +1 -0
  15. package/dist/cjs/modules/partner/utils/partner-membership.util.js +23 -31
  16. package/dist/cjs/modules/partner/utils/partner-membership.util.js.map +1 -1
  17. package/dist/cjs/modules/partner/utils/partner-payload.util.js +25 -8
  18. package/dist/cjs/modules/partner/utils/partner-payload.util.js.map +1 -1
  19. package/dist/cjs/modules/user/dtos/create-user.dto.js +10 -0
  20. package/dist/cjs/modules/user/dtos/create-user.dto.js.map +1 -1
  21. package/dist/esm/exceptions/filters/http-exceptions.filter.js +19 -2
  22. package/dist/esm/exceptions/filters/http-exceptions.filter.js.map +1 -1
  23. package/dist/esm/modules/common/decorators/calendar-date.decorator.js +55 -0
  24. package/dist/esm/modules/common/decorators/calendar-date.decorator.js.map +1 -0
  25. package/dist/esm/modules/common/index.js +2 -0
  26. package/dist/esm/modules/common/index.js.map +1 -1
  27. package/dist/esm/modules/common/utils/calendar-date.util.js +140 -0
  28. package/dist/esm/modules/common/utils/calendar-date.util.js.map +1 -0
  29. package/dist/esm/modules/partner/dtos/partner-member-profile.dto.js +2 -3
  30. package/dist/esm/modules/partner/dtos/partner-member-profile.dto.js.map +1 -1
  31. package/dist/esm/modules/partner/index.js +1 -0
  32. package/dist/esm/modules/partner/index.js.map +1 -1
  33. package/dist/esm/modules/partner/interfaces/partner-member-readiness.js +2 -0
  34. package/dist/esm/modules/partner/interfaces/partner-member-readiness.js.map +1 -0
  35. package/dist/esm/modules/partner/utils/partner-membership.util.js +25 -28
  36. package/dist/esm/modules/partner/utils/partner-membership.util.js.map +1 -1
  37. package/dist/esm/modules/partner/utils/partner-payload.util.js +25 -9
  38. package/dist/esm/modules/partner/utils/partner-payload.util.js.map +1 -1
  39. package/dist/esm/modules/user/dtos/create-user.dto.js +10 -0
  40. package/dist/esm/modules/user/dtos/create-user.dto.js.map +1 -1
  41. package/dist/types/modules/common/decorators/calendar-date.decorator.d.ts +26 -0
  42. package/dist/types/modules/common/index.d.ts +2 -0
  43. package/dist/types/modules/common/utils/calendar-date.util.d.ts +80 -0
  44. package/dist/types/modules/partner/dtos/partner-member-profile.dto.d.ts +8 -1
  45. package/dist/types/modules/partner/index.d.ts +1 -0
  46. package/dist/types/modules/partner/interfaces/partner-member-readiness.d.ts +60 -0
  47. package/dist/types/modules/partner/utils/partner-membership.util.d.ts +17 -6
  48. package/dist/types/modules/partner/utils/partner-payload.util.d.ts +11 -10
  49. package/dist/types/modules/user/dtos/create-user.dto.d.ts +1 -0
  50. package/dist/types/modules/user/interfaces/user.d.ts +10 -0
  51. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The platform's one definition of a calendar date.
3
+ *
4
+ * A date of birth is a CALENDAR DATE, not an instant. It has no time, no zone
5
+ * and no offset: somebody born on 17 April 1990 was born on that day in Nairobi,
6
+ * in Kampala and in London alike. Every bug this module exists to prevent comes
7
+ * from the same mistake - treating that date as a moment, reading it back in a
8
+ * different zone, and landing a day earlier.
9
+ *
10
+ * That mistake had already been made. Before this module the platform carried
11
+ * four independent copies of the `YYYY-MM-DD` regex and a conversion that did
12
+ * `new Date(freeText)` and then `.toISOString()`. Under `TZ=Africa/Nairobi`,
13
+ * which is what the production pods run:
14
+ *
15
+ * '04/17/1990' -> '1990-04-16' (a day early)
16
+ * new Date(1990,3,17) -> '1990-04-16' (a day early - and this is exactly
17
+ * what a date picker hands you)
18
+ * '17/04/1990' -> undefined (the East African spelling, refused)
19
+ *
20
+ * A birth date that is wrong by a day is worse than one that is missing.
21
+ * Rescue.co cannot delete a member once registered, so a drifted date is
22
+ * permanent, and it is the field a paramedic uses to size a drug dose. So the
23
+ * rule here is deliberately narrow: parse what is unambiguous, refuse
24
+ * everything else, and never guess.
25
+ */
26
+ /** `YYYY-MM-DD`. The single definition - do not re-declare this anywhere. */
27
+ export declare const ISO_CALENDAR_DATE_PATTERN: RegExp;
28
+ /** Nobody lives longer than this, so anything older is a typo or a placeholder. */
29
+ export declare const MAX_HUMAN_AGE_YEARS = 120;
30
+ /**
31
+ * The age at which a person is treated as an adult, for COPY ONLY.
32
+ *
33
+ * Never a validator. Dependents on a family membership are children by design -
34
+ * that is the entire point of registering them with an emergency responder -
35
+ * so a minimum age would refuse exactly the people the feature exists for.
36
+ */
37
+ export declare const AGE_OF_MAJORITY_YEARS = 18;
38
+ /**
39
+ * A real `YYYY-MM-DD` day, not merely a string shaped like one.
40
+ *
41
+ * Rejects `2026-02-30` and `2026-13-01`: the shape is right and the day does
42
+ * not exist. Parsed at UTC midnight so the check cannot depend on where it runs.
43
+ */
44
+ export declare function isCalendarDate(value: unknown): value is string;
45
+ /**
46
+ * Reduce a stored or submitted value to a calendar date, or refuse it.
47
+ *
48
+ * Accepts exactly three things, and nothing else:
49
+ *
50
+ * 1. `YYYY-MM-DD` - the wire format every client must send
51
+ * 2. a full ISO-8601 instant in UTC - `1990-04-17T00:00:00.000Z`, which is
52
+ * what the spreadsheet importer produces
53
+ * 3. a `Date` - read in UTC, so callers must build it
54
+ * with `Date.UTC`, never `new Date(y,m,d)`
55
+ *
56
+ * Free text is REFUSED rather than guessed at. `'04/17/1990'` and `'17/04/1990'`
57
+ * are the same eight characters in different orders and the platform serves
58
+ * Kenya, Uganda and Tanzania, where the second spelling is the common one.
59
+ * There is no reading of that string that is safe to infer, so the honest
60
+ * answer is `undefined` - which surfaces as a field the operator is asked to
61
+ * collect, instead of a wrong birthday nobody ever notices.
62
+ */
63
+ export declare function toCalendarDate(value: Date | string | null | undefined): string | undefined;
64
+ /**
65
+ * A date that could belong to a living person.
66
+ *
67
+ * Deliberately NOT an age gate. There is no minimum: a dependent on a family
68
+ * membership may be a newborn. What it refuses is a date that cannot be a birth
69
+ * date at all - one in the future, or one further back than any human lifespan -
70
+ * because those are data-entry accidents (a 2026 default on a picker, a
71
+ * mis-keyed century) rather than facts about a person.
72
+ *
73
+ * `now` is injectable so the rule is deterministic under test, matching
74
+ * `isUsableMembership` and `isMembershipCoverActive`.
75
+ */
76
+ export declare function isPlausibleBirthDate(value: unknown, now?: Date): boolean;
77
+ /** Whole years, UTC throughout. Returns undefined when the date is unusable. */
78
+ export declare function calculateAge(value: unknown, now?: Date): number | undefined;
79
+ /** True when the person is below the age of majority - for COPY, never a gate. */
80
+ export declare function isMinor(value: unknown, now?: Date): boolean;
@@ -18,7 +18,14 @@ export declare class PartnerMemberProfileDto {
18
18
  */
19
19
  phoneNumber?: string;
20
20
  email?: string;
21
- /** `YYYY-MM-DD`. A calendar date, never a timestamp. */
21
+ /**
22
+ * `YYYY-MM-DD`. A calendar date, never a timestamp.
23
+ *
24
+ * `@IsBirthDate` rather than a regex: the regex this replaces accepted
25
+ * `2026-02-30` and `2999-01-01` - a day that does not exist, and one that
26
+ * has not happened yet - and Postgres rolls the first quietly forward to
27
+ * 1 March.
28
+ */
22
29
  dateOfBirth?: string;
23
30
  gender?: PartnerMemberGender;
24
31
  documentType?: PartnerMemberDocumentType;
@@ -31,6 +31,7 @@ export * from './interfaces/partner-connection-test-result';
31
31
  export * from './interfaces/partner-dispatch-events';
32
32
  export * from './interfaces/partner-member-profile';
33
33
  export * from './interfaces/partner-membership-descriptor';
34
+ export * from './interfaces/partner-member-readiness';
34
35
  export * from './interfaces/partner-membership';
35
36
  export * from './constants/partner-defaults.const';
36
37
  export * from './constants/partner-kafka.const';
@@ -0,0 +1,60 @@
1
+ import { PartnerMemberProfileFieldDescriptor } from './partner-membership-descriptor';
2
+ /**
3
+ * One thing still standing between a person and cover with a partner, described
4
+ * well enough for any client to render an input for it without knowing which
5
+ * partner asked.
6
+ *
7
+ * Carries the DESCRIPTOR and the REASON, and deliberately never the value that
8
+ * is already held. A prompt exists to collect what is missing; sending back
9
+ * what is already stored would put a date of birth into a mobile response, a
10
+ * browser cache and any log that captured it, to redisplay a fact the person
11
+ * supplied themselves.
12
+ */
13
+ export interface PartnerMemberRequirement extends PartnerMemberProfileFieldDescriptor {
14
+ /**
15
+ * MISSING needs the fact collected; MALFORMED needs it corrected. An
16
+ * operator shown "missing" for a field that is plainly filled in has
17
+ * nothing to act on.
18
+ */
19
+ reason: 'MISSING' | 'MALFORMED';
20
+ /** Why this specific value was refused, where that can be said usefully. */
21
+ detail?: string;
22
+ }
23
+ /**
24
+ * Whether the platform could register this person with the partners that cover
25
+ * them, and what it still needs if not.
26
+ *
27
+ * The contract behind every capture prompt in the product - the mobile sheet,
28
+ * the admin worklist, the beneficiary form. All of them render THIS rather than
29
+ * a hardcoded date-of-birth field, which is what keeps the feature honest as
30
+ * partners are added: a second partner wanting a national id number is a
31
+ * descriptor edit in one adapter, not an app release.
32
+ */
33
+ export interface PartnerMemberReadiness {
34
+ subjectReference: string;
35
+ /** True when nothing is outstanding - either satisfied, or nobody needs anything. */
36
+ ready: boolean;
37
+ /**
38
+ * Names of the partners that want something, for copy like "Rescue.co needs
39
+ * your date of birth". Empty when nothing is outstanding.
40
+ */
41
+ awaitingPartnerNames: string[];
42
+ /**
43
+ * Merged across every partner covering this person and de-duplicated by
44
+ * key, because two partners both wanting a date of birth is one question to
45
+ * ask, not two.
46
+ */
47
+ requirements: PartnerMemberRequirement[];
48
+ /**
49
+ * True when the person was asked and declined. Kept so "declined" can be
50
+ * told apart from "never asked" - without it a dismissed prompt is
51
+ * indistinguishable from a bug, and the only safe response to either is to
52
+ * ask again, forever.
53
+ */
54
+ declined?: boolean;
55
+ }
56
+ /** Readiness for a person and, where they have them, their dependents. */
57
+ export interface PartnerMemberReadinessResult {
58
+ subject: PartnerMemberReadiness;
59
+ dependents: PartnerMemberReadiness[];
60
+ }
@@ -1,3 +1,4 @@
1
+ import { isCalendarDate, toCalendarDate } from '../../common/utils/calendar-date.util';
1
2
  import { PartnerMemberProfileField } from '../enums/partner-member-profile-field.enum';
2
3
  import { PartnerMembershipStatus } from '../enums/partner-membership-status.enum';
3
4
  import { PartnerMembershipSubjectType } from '../enums/partner-membership-subject-type.enum';
@@ -86,16 +87,26 @@ export declare function membershipRequired(integration: {
86
87
  * retried forever against a value that will never become valid.
87
88
  */
88
89
  export declare function isMemberProfileFieldPresent(profile: PartnerMemberProfileInput, field: PartnerMemberProfileField): boolean;
89
- /** A real `YYYY-MM-DD` date, not merely one shaped like it (rejects 2026-02-30). */
90
- export declare function isCalendarDate(value: string): boolean;
90
+ /**
91
+ * Re-exported so partner code keeps one import, but there is only ONE
92
+ * implementation and it lives with the rest of the date contract.
93
+ */
94
+ export { isCalendarDate };
91
95
  /**
92
96
  * A date of birth reduced to the calendar date partners want.
93
97
  *
94
- * Accepts what the platform actually stores - a `Date`, a timestamp string, a
95
- * bare date - and returns UTC, never local. Reading a stored instant in the
96
- * server's zone is how a birthday drifts a day when a pod moves region.
98
+ * Now a thin alias over the platform contract, and NARROWER than it used to be.
99
+ * The old body did `new Date(trimmed)` on anything that was not already
100
+ * `YYYY-MM-DD` and then read the result back in UTC, which under the pods' own
101
+ * `TZ=Africa/Nairobi` turned '04/17/1990' into '1990-04-16' and refused
102
+ * '17/04/1990' - the spelling most of East Africa actually writes.
103
+ *
104
+ * Ambiguous text is now refused outright. A refused date surfaces as a field an
105
+ * operator is asked to collect; a drifted one is a permanent wrong birthday at
106
+ * a partner that cannot delete a member, on the record a paramedic uses to size
107
+ * a drug dose.
97
108
  */
98
- export declare function toPartnerCalendarDate(value: Date | string | null | undefined): string | undefined;
109
+ export declare const toPartnerCalendarDate: typeof toCalendarDate;
99
110
  /**
100
111
  * Seats to buy for a member and their dependents.
101
112
  *
@@ -49,16 +49,6 @@ export declare function sanitizePartnerPayload(value: unknown, depth?: number):
49
49
  * case-insensitively.
50
50
  */
51
51
  export declare const SECRET_KEY_FRAGMENTS: string[];
52
- /**
53
- * Key substrings that mark a value as a government identity document number.
54
- *
55
- * These are NOT credentials - they cannot be rotated, and unlike an API key,
56
- * losing one harms the PERSON rather than the platform. That asymmetry is why
57
- * they are masked rather than redacted: an operator investigating "the partner
58
- * rejected this member" still needs to tell one document from another, and
59
- * blanking the field entirely would make the audit trail useless while a full
60
- * value would put a national id in a table many people can read.
61
- */
62
52
  export declare const IDENTITY_DOCUMENT_KEY_FRAGMENTS: string[];
63
53
  /**
64
54
  * Key substrings that mark a value as a date of birth.
@@ -68,7 +58,18 @@ export declare const IDENTITY_DOCUMENT_KEY_FRAGMENTS: string[];
68
58
  * survives, because "the partner rejected a member born in 1988" is the kind of
69
59
  * thing somebody actually has to debug.
70
60
  */
61
+ /**
62
+ * Matched against a key with every separator stripped, so one fragment covers
63
+ * every spelling a producer might use.
64
+ *
65
+ * The previous list matched raw keys and therefore missed `birth_date` and
66
+ * `date-of-birth` entirely - close enough to the ones it did match that the
67
+ * gap was invisible, and wide enough that an audit payload using either
68
+ * spelling was stored with the birth date in the clear.
69
+ */
71
70
  export declare const BIRTH_DATE_KEY_FRAGMENTS: string[];
71
+ /** `1988-04-12` becomes `1988-**-**`; anything unrecognised is blanked. */
72
+ export declare function maskBirthDate(value: string): string;
72
73
  /**
73
74
  * Personal attributes that carry no diagnostic value at all in an audit record.
74
75
  *
@@ -21,4 +21,5 @@ export declare class CreateUserDto {
21
21
  verificationTokenExpiresAt?: Date;
22
22
  controlCentreId: number;
23
23
  organizationId: number;
24
+ dateOfBirth?: string;
24
25
  }
@@ -19,6 +19,16 @@ export interface User {
19
19
  password?: string;
20
20
  avatar?: string;
21
21
  designation?: string;
22
+ /**
23
+ * `YYYY-MM-DD`. A calendar date, never a timestamp.
24
+ *
25
+ * PRESENT ONLY WHERE IT WAS EXPLICITLY ASKED FOR. The column is
26
+ * `select: false` in clarion-authentication, so ordinary reads - user
27
+ * lists, guardian responses, the batch lookup other services use - do
28
+ * not load it and this property is simply absent there. Treat an absent
29
+ * value as "not loaded", never as "this person has no date of birth".
30
+ */
31
+ dateOfBirth?: string | null;
22
32
  status?: UserStatus;
23
33
  guardians?: Guardian[];
24
34
  dependentRelations?: GuardianRelation[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grm-shared-library",
3
- "version": "1.1.205",
3
+ "version": "1.1.206",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",