@opencrvs/toolkit 2.1.0-rc.9e444d5 → 2.1.0-rc.a2d8806

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.
@@ -2,7 +2,7 @@ import { ConditionalParameters, JSONSchema } from './conditionals';
2
2
  import { ActionUpdate, EventState } from '../events/ActionDocument';
3
3
  import { FieldConditional } from '../events/Conditional';
4
4
  import { FieldConfig } from '../events/FieldConfig';
5
- import { FieldUpdateValue, FieldValue } from '../events/FieldValue';
5
+ import { PlainDate, FieldUpdateValue, FieldValue } from '../events/FieldValue';
6
6
  import { TranslationConfig } from '../events/TranslationConfig';
7
7
  import { ITokenPayload } from '../authentication';
8
8
  import { UUID } from '../uuid';
@@ -14,8 +14,8 @@ import { EventDocument } from '../events/EventDocument';
14
14
  import { EventIndex } from '../events/EventIndex';
15
15
  import { Location } from '../events/locations';
16
16
  import { SystemVariables } from '../events/TemplateConfig';
17
- /** Returns today's date as an ISO date string (YYYY-MM-DD). */
18
- export declare function todayISO(): string;
17
+ /** Returns today's date as a {@link PlainDate} (YYYY-MM-DD), device-local. */
18
+ export declare function todayISO(): PlainDate;
19
19
  /**
20
20
  * Context passed to every serialised client-side function ({@link runClientFunction}).
21
21
  *
@@ -1,7 +1,7 @@
1
1
  import * as z from 'zod/v4';
2
2
  import { AddressFieldUpdateValue, AddressFieldValue, CustomFieldValue, FileFieldValue, FileFieldWithOptionValue, HttpFieldUpdateValue, IdReaderFieldValue, NameFieldUpdateValue, NameFieldValue, NumberWithUnitFieldUpdateValue, NumberWithUnitFieldValue, QrReaderFieldValue, QueryParamReaderFieldUpdateValue } from './CompositeFieldValue';
3
- import { PlainDate, plainDateToLocalDate } from './PlainDate';
4
- export { PlainDate, plainDateToLocalDate };
3
+ import { PlainDate, plainDateToLocalDate, toPlainDate } from './PlainDate';
4
+ export { PlainDate, plainDateToLocalDate, toPlainDate };
5
5
  /**
6
6
  * FieldValues defined in this file are primitive field values.
7
7
  * FieldValues defined in CompositeFieldValue.ts are composed of multiple primitive field values (Address, File etc).
@@ -9,6 +9,14 @@ import { z } from 'zod';
9
9
  */
10
10
  export declare const PlainDate: z.core.$ZodBranded<z.ZodString, "PlainDate", "out">;
11
11
  export type PlainDate = z.infer<typeof PlainDate>;
12
+ /**
13
+ * Extracts the plain calendar date from an ISO 8601 datetime (or passes an
14
+ * already-plain YYYY-MM-DD through) as a {@link PlainDate}. This is the single
15
+ * conversion from a timestamp to a location-resolution anchor — comparing
16
+ * plain dates as strings, with no timezone conversion. Assumes a valid ISO /
17
+ * YYYY-MM-DD input, as produced by the event metadata and date fields.
18
+ */
19
+ export declare function toPlainDate(dateTime: string): PlainDate;
12
20
  /**
13
21
  * Converts a {@link PlainDate} (YYYY-MM-DD) to a local `Date` at midnight.
14
22
  *
@@ -1,5 +1,6 @@
1
1
  import { UUID } from '../uuid';
2
2
  import * as z from 'zod/v4';
3
+ import { PlainDate } from './PlainDate';
3
4
  import { EventIndex } from './EventIndex';
4
5
  import { ActionCreationMetadata, RegistrationCreationMetadata } from './EventMetadata';
5
6
  import { RecordScopeV2, UserScopeV2 } from '../scopes';
@@ -75,6 +76,61 @@ export declare const Location: z.ZodObject<{
75
76
  }, z.core.$strip>>;
76
77
  }, z.core.$strip>;
77
78
  export type Location = z.infer<typeof Location>;
79
+ /**
80
+ * TEMPORARY — client-side view of {@link AdministrativeArea} with the
81
+ * server-flattened `name`, `status` and `externalId` removed, leaving exactly
82
+ * identity + versions. Every name/status read is thereby forced through the
83
+ * anchored resolution utilities ({@link resolveVersion}, {@link resolvePath})
84
+ * at compile time. Delete this type when the contract migration removes the
85
+ * flat fields from the server schema, at which point the wire type itself
86
+ * becomes identity + versions.
87
+ */
88
+ export declare const ClientAdministrativeArea: z.ZodObject<{
89
+ id: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
90
+ parentId: z.ZodNullable<z.core.$ZodBranded<z.ZodUUID, "UUID", "out">>;
91
+ versions: z.ZodArray<z.ZodObject<{
92
+ versionId: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
93
+ effectiveFrom: z.ZodISODate;
94
+ name: z.ZodString;
95
+ externalId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
96
+ status: z.ZodEnum<{
97
+ active: "active";
98
+ inactive: "inactive";
99
+ }>;
100
+ }, z.core.$strip>>;
101
+ }, z.core.$strip>;
102
+ export type ClientAdministrativeArea = z.infer<typeof ClientAdministrativeArea>;
103
+ /**
104
+ * TEMPORARY — client-side view of {@link Location} with the server-flattened
105
+ * `name`, `status` and `externalId` removed, leaving exactly identity +
106
+ * versions. See {@link ClientAdministrativeArea} for the full rationale and
107
+ * deletion condition.
108
+ */
109
+ export declare const ClientLocation: z.ZodObject<{
110
+ id: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
111
+ administrativeAreaId: z.ZodNullable<z.core.$ZodBranded<z.ZodUUID, "UUID", "out">>;
112
+ locationType: z.ZodNullable<z.ZodString>;
113
+ versions: z.ZodArray<z.ZodObject<{
114
+ versionId: z.core.$ZodBranded<z.ZodUUID, "UUID", "out">;
115
+ effectiveFrom: z.ZodISODate;
116
+ name: z.ZodString;
117
+ externalId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
118
+ status: z.ZodEnum<{
119
+ active: "active";
120
+ inactive: "inactive";
121
+ }>;
122
+ }, z.core.$strip>>;
123
+ }, z.core.$strip>;
124
+ export type ClientLocation = z.infer<typeof ClientLocation>;
125
+ /**
126
+ * Strips the server-flattened fields from a location as it enters the
127
+ * client's cached maps. The wire format keeps the flat fields for
128
+ * compatibility; the cache must not, or devices would keep rendering names
129
+ * flattened before a future-dated version takes effect.
130
+ */
131
+ export declare function toClientLocation(location: Location): ClientLocation;
132
+ /** See {@link toClientLocation}. */
133
+ export declare function toClientAdministrativeArea(area: AdministrativeArea): ClientAdministrativeArea;
78
134
  /**
79
135
  * Input payload for the locations `set` mutation. Carries only the seedable
80
136
  * identity and hierarchy fields — version history is managed by the server.
@@ -164,20 +220,10 @@ export declare function canAccessOtherUserWithScopes({ scopes, userToAccess, use
164
220
  * One of the scopes must allow access for the event to be accessible.
165
221
  */
166
222
  export declare function userCanAccessEventWithScopes(event: Partial<EventIndexWithAdministrativeHierarchy>, scopes: RecordScopeV2[], user: UserContext | SystemContext, customActionType?: string): boolean;
167
- export declare function getAdministrativeAreaHierarchy(administrativeAreaId: string | undefined | null, administrativeAreas: Map<UUID, AdministrativeArea>): {
168
- id: string & z.$brand<"UUID">;
169
- name: string;
170
- externalId?: string | null | undefined;
171
- parentId: (string & z.$brand<"UUID">) | null;
172
- status: "active" | "inactive";
173
- versions: {
174
- versionId: string & z.$brand<"UUID">;
175
- effectiveFrom: string;
176
- name: string;
177
- externalId?: string | null | undefined;
178
- status: "active" | "inactive";
179
- }[];
180
- }[];
223
+ export declare function getAdministrativeAreaHierarchy<A extends {
224
+ id: UUID;
225
+ parentId: UUID | null;
226
+ }>(administrativeAreaId: string | undefined | null, administrativeAreas: Map<UUID, A>): A[];
181
227
  /**
182
228
  * Resolves a location or administrative area UUID into a root-first hierarchy of UUIDs.
183
229
  *
@@ -189,8 +235,45 @@ export declare function getAdministrativeAreaHierarchy(administrativeAreaId: str
189
235
  * so the result is reversed to match the root-first convention used by the server.
190
236
  */
191
237
  export declare function getLocationHierarchy(selectedId: UUID, context: {
192
- administrativeAreas: Map<UUID, AdministrativeArea>;
193
- locations: Map<UUID, Location>;
238
+ administrativeAreas: Map<UUID, {
239
+ id: UUID;
240
+ parentId: UUID | null;
241
+ }>;
242
+ locations: Map<UUID, {
243
+ id: UUID;
244
+ administrativeAreaId: UUID | null;
245
+ }>;
194
246
  }): UUID[];
247
+ /**
248
+ * A node of an anchored hierarchy path: the identity id plus the name and
249
+ * status in effect at the anchor date.
250
+ */
251
+ export type ResolvedPathNode = {
252
+ id: UUID;
253
+ name: string;
254
+ status: LocationStatus;
255
+ };
256
+ /**
257
+ * Resolves a location or administrative area id into its root-first
258
+ * hierarchy path — leaf included — with every node's name and status
259
+ * resolved at the anchor date.
260
+ *
261
+ * The parent chain is identity-level and fixed for life, so the chain is
262
+ * constant and only each node's name/status varies with the anchor. Status is
263
+ * returned for callers that filter on it; an inactive node still resolves to
264
+ * its name. Returns an empty array for an unknown id.
265
+ */
266
+ export declare function resolvePath(locationId: UUID, anchor: PlainDate, context: {
267
+ administrativeAreas: Map<UUID, {
268
+ id: UUID;
269
+ parentId: UUID | null;
270
+ versions: LocationVersion[];
271
+ }>;
272
+ locations: Map<UUID, {
273
+ id: UUID;
274
+ administrativeAreaId: UUID | null;
275
+ versions: LocationVersion[];
276
+ }>;
277
+ }): ResolvedPathNode[];
195
278
  export {};
196
279
  //# sourceMappingURL=locations.d.ts.map
@@ -30,4 +30,34 @@ export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP: Map<string & impo
30
30
  status: "active" | "inactive";
31
31
  }[];
32
32
  }>;
33
+ /**
34
+ * Stripped view of {@link V2_DEFAULT_MOCK_LOCATIONS_MAP} matching what the
35
+ * client's cached location map actually holds at runtime (identity +
36
+ * versions only). Use this — not the wire-format map above — wherever a test
37
+ * stands in for `useLocations().getLocations.useSuspenseQuery()`.
38
+ */
39
+ export declare const V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP: Map<string & import("zod").$brand<"UUID">, {
40
+ id: string & import("zod").$brand<"UUID">;
41
+ administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
42
+ locationType: string | null;
43
+ versions: {
44
+ versionId: string & import("zod").$brand<"UUID">;
45
+ effectiveFrom: string;
46
+ name: string;
47
+ externalId?: string | null | undefined;
48
+ status: "active" | "inactive";
49
+ }[];
50
+ }>;
51
+ /** See {@link V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP}. */
52
+ export declare const V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP: Map<string & import("zod").$brand<"UUID">, {
53
+ id: string & import("zod").$brand<"UUID">;
54
+ parentId: (string & import("zod").$brand<"UUID">) | null;
55
+ versions: {
56
+ versionId: string & import("zod").$brand<"UUID">;
57
+ effectiveFrom: string;
58
+ name: string;
59
+ externalId?: string | null | undefined;
60
+ status: "active" | "inactive";
61
+ }[];
62
+ }>;
33
63
  //# sourceMappingURL=mocks.test.utils.d.ts.map
@@ -74,6 +74,8 @@ __export(events_exports, {
74
74
  CertificateTemplateConfig: () => CertificateTemplateConfig,
75
75
  CheckboxFieldValue: () => CheckboxFieldValue,
76
76
  Clause: () => Clause,
77
+ ClientAdministrativeArea: () => ClientAdministrativeArea,
78
+ ClientLocation: () => ClientLocation,
77
79
  ClientSpecificAction: () => ClientSpecificAction,
78
80
  ComputedDefaultValue: () => ComputedDefaultValue,
79
81
  Conditional: () => Conditional,
@@ -227,6 +229,8 @@ __export(events_exports, {
227
229
  UserAuditRecordInput: () => UserAuditRecordInput,
228
230
  V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS: () => V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS,
229
231
  V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP: () => V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP,
232
+ V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP: () => V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP,
233
+ V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP: () => V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP,
230
234
  V2_DEFAULT_MOCK_LOCATIONS: () => V2_DEFAULT_MOCK_LOCATIONS,
231
235
  V2_DEFAULT_MOCK_LOCATIONS_MAP: () => V2_DEFAULT_MOCK_LOCATIONS_MAP,
232
236
  ValidationConfig: () => ValidationConfig,
@@ -443,6 +447,7 @@ __export(events_exports, {
443
447
  precompileActionSchemas: () => precompileActionSchemas,
444
448
  resolveDateOfEvent: () => resolveDateOfEvent,
445
449
  resolveEventCustomFlags: () => resolveEventCustomFlags,
450
+ resolvePath: () => resolvePath,
446
451
  resolvePlaceOfEvent: () => resolvePlaceOfEvent,
447
452
  resolveVersion: () => resolveVersion,
448
453
  runClientFunction: () => runClientFunction,
@@ -451,6 +456,9 @@ __export(events_exports, {
451
456
  safeUnion: () => safeUnion,
452
457
  status: () => status,
453
458
  timePeriodToDateRange: () => timePeriodToDateRange,
459
+ toClientAdministrativeArea: () => toClientAdministrativeArea,
460
+ toClientLocation: () => toClientLocation,
461
+ toPlainDate: () => toPlainDate,
454
462
  todayISO: () => todayISO,
455
463
  user: () => user,
456
464
  userCanAccessEventWithScopes: () => userCanAccessEventWithScopes,
@@ -1395,6 +1403,9 @@ var CustomFieldValue = z10.unknown().brand("CustomFieldValue");
1395
1403
  // ../commons/src/events/PlainDate.ts
1396
1404
  var import_zod = require("zod");
1397
1405
  var PlainDate = import_zod.z.string().date().brand("PlainDate").describe("Date in the format YYYY-MM-DD");
1406
+ function toPlainDate(dateTime) {
1407
+ return dateTime.split("T")[0];
1408
+ }
1398
1409
  function plainDateToLocalDate(date) {
1399
1410
  const [year, month, day] = date.split("-").map(Number);
1400
1411
  return new Date(year, month - 1, day);
@@ -10529,6 +10540,31 @@ var Location = z43.object({
10529
10540
  status: LocationStatus,
10530
10541
  versions: z43.array(LocationVersion)
10531
10542
  });
10543
+ var ClientAdministrativeArea = AdministrativeArea.omit({
10544
+ name: true,
10545
+ status: true,
10546
+ externalId: true
10547
+ });
10548
+ var ClientLocation = Location.omit({
10549
+ name: true,
10550
+ status: true,
10551
+ externalId: true
10552
+ });
10553
+ function toClientLocation(location) {
10554
+ return {
10555
+ id: location.id,
10556
+ administrativeAreaId: location.administrativeAreaId,
10557
+ locationType: location.locationType,
10558
+ versions: location.versions
10559
+ };
10560
+ }
10561
+ function toClientAdministrativeArea(area) {
10562
+ return {
10563
+ id: area.id,
10564
+ parentId: area.parentId,
10565
+ versions: area.versions
10566
+ };
10567
+ }
10532
10568
  var SetLocationPayload = z43.object({
10533
10569
  id: UUID,
10534
10570
  name: z43.string(),
@@ -10733,6 +10769,16 @@ function getLocationHierarchy(selectedId, context) {
10733
10769
  );
10734
10770
  return hierarchy.reverse().map((area) => area.id);
10735
10771
  }
10772
+ function resolvePath(locationId, anchor, context) {
10773
+ return getLocationHierarchy(locationId, context).flatMap((id) => {
10774
+ const node = context.locations.get(id) ?? context.administrativeAreas.get(id);
10775
+ if (!node) {
10776
+ return [];
10777
+ }
10778
+ const { name, status: status2 } = resolveVersion(node.versions, anchor);
10779
+ return [{ id, name, status: status2 }];
10780
+ });
10781
+ }
10736
10782
 
10737
10783
  // ../commons/src/events/scopes.ts
10738
10784
  var ACTION_SCOPE_MAP = {
@@ -11368,6 +11414,15 @@ var V2_DEFAULT_MOCK_LOCATIONS_MAP = new Map(
11368
11414
  var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP = new Map(
11369
11415
  V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [a.id, a])
11370
11416
  );
11417
+ var V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP = new Map(
11418
+ V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, toClientLocation(l)])
11419
+ );
11420
+ var V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP = new Map(
11421
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [
11422
+ a.id,
11423
+ toClientAdministrativeArea(a)
11424
+ ])
11425
+ );
11371
11426
 
11372
11427
  // ../commons/src/events/locationPayloads.ts
11373
11428
  var z44 = __toESM(require("zod/v4"));
@@ -7410,6 +7410,31 @@ var Location = z43.object({
7410
7410
  status: LocationStatus,
7411
7411
  versions: z43.array(LocationVersion)
7412
7412
  });
7413
+ var ClientAdministrativeArea = AdministrativeArea.omit({
7414
+ name: true,
7415
+ status: true,
7416
+ externalId: true
7417
+ });
7418
+ var ClientLocation = Location.omit({
7419
+ name: true,
7420
+ status: true,
7421
+ externalId: true
7422
+ });
7423
+ function toClientLocation(location) {
7424
+ return {
7425
+ id: location.id,
7426
+ administrativeAreaId: location.administrativeAreaId,
7427
+ locationType: location.locationType,
7428
+ versions: location.versions
7429
+ };
7430
+ }
7431
+ function toClientAdministrativeArea(area) {
7432
+ return {
7433
+ id: area.id,
7434
+ parentId: area.parentId,
7435
+ versions: area.versions
7436
+ };
7437
+ }
7413
7438
  var SetLocationPayload = z43.object({
7414
7439
  id: UUID,
7415
7440
  name: z43.string(),
@@ -7852,6 +7877,15 @@ var V2_DEFAULT_MOCK_LOCATIONS_MAP = new Map(
7852
7877
  var V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP = new Map(
7853
7878
  V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [a.id, a])
7854
7879
  );
7880
+ var V2_DEFAULT_MOCK_CLIENT_LOCATIONS_MAP = new Map(
7881
+ V2_DEFAULT_MOCK_LOCATIONS.map((l) => [l.id, toClientLocation(l)])
7882
+ );
7883
+ var V2_DEFAULT_MOCK_CLIENT_ADMINISTRATIVE_AREAS_MAP = new Map(
7884
+ V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS.map((a) => [
7885
+ a.id,
7886
+ toClientAdministrativeArea(a)
7887
+ ])
7888
+ );
7855
7889
 
7856
7890
  // ../commons/src/events/locationPayloads.ts
7857
7891
  var z44 = __toESM(require("zod/v4"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.1.0-rc.9e444d5",
3
+ "version": "2.1.0-rc.a2d8806",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {