@opencrvs/toolkit 1.8.0-rc.f7aaf07 → 1.8.0-rc.f7e4aad

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.
@@ -69,7 +69,7 @@ __export(events_exports, {
69
69
  Conditional: () => Conditional,
70
70
  ConditionalType: () => ConditionalType,
71
71
  ConfirmableActions: () => ConfirmableActions,
72
- CustomFlags: () => CustomFlags,
72
+ ContainsFlags: () => ContainsFlags,
73
73
  DEFAULT_DATE_OF_EVENT_PROPERTY: () => DEFAULT_DATE_OF_EVENT_PROPERTY,
74
74
  DataEntry: () => DataEntry,
75
75
  DataFieldValue: () => DataFieldValue,
@@ -124,6 +124,7 @@ __export(events_exports, {
124
124
  GenericAddressValue: () => GenericAddressValue,
125
125
  GeographicalArea: () => GeographicalArea,
126
126
  ImageMimeType: () => ImageMimeType,
127
+ InherentFlags: () => InherentFlags,
127
128
  LanguageConfig: () => LanguageConfig,
128
129
  LegalStatuses: () => LegalStatuses,
129
130
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
@@ -131,7 +132,6 @@ __export(events_exports, {
131
132
  NameFieldUpdateValue: () => NameFieldUpdateValue,
132
133
  NameFieldValue: () => NameFieldValue,
133
134
  NonEmptyTextValue: () => NonEmptyTextValue,
134
- Not: () => Not,
135
135
  NotifyActionInput: () => NotifyActionInput,
136
136
  NumberFieldValue: () => NumberFieldValue,
137
137
  PageConfig: () => PageConfig,
@@ -228,8 +228,10 @@ __export(events_exports, {
228
228
  generateEventDraftDocument: () => generateEventDraftDocument,
229
229
  generateRandomName: () => generateRandomName,
230
230
  generateRandomSignature: () => generateRandomSignature,
231
+ generateRegistrationNumber: () => generateRegistrationNumber,
231
232
  generateTransactionId: () => generateTransactionId,
232
233
  generateTranslationConfig: () => generateTranslationConfig,
234
+ generateUuid: () => generateUuid,
233
235
  generateWorkqueues: () => generateWorkqueues,
234
236
  getAcceptedActions: () => getAcceptedActions,
235
237
  getActionAnnotation: () => getActionAnnotation,
@@ -1342,9 +1344,16 @@ var import_lodash = require("lodash");
1342
1344
  var import_zod18 = require("zod");
1343
1345
  var import_zod_openapi7 = require("zod-openapi");
1344
1346
 
1345
- // ../commons/src/events/CreatedAtLocation.ts
1347
+ // ../commons/src/uuid.ts
1348
+ var import_uuid = require("uuid");
1346
1349
  var import_zod15 = require("zod");
1347
- var CreatedAtLocation = import_zod15.z.string().nullish();
1350
+ var UUID = import_zod15.z.string().uuid().brand("UUID");
1351
+ function getUUID() {
1352
+ return (0, import_uuid.v4)();
1353
+ }
1354
+
1355
+ // ../commons/src/events/CreatedAtLocation.ts
1356
+ var CreatedAtLocation = UUID.nullish();
1348
1357
 
1349
1358
  // ../commons/src/authentication.ts
1350
1359
  var import_jwt_decode = __toESM(require("jwt-decode"));
@@ -1780,7 +1789,7 @@ var ActionStatus = {
1780
1789
  Rejected: "Rejected"
1781
1790
  };
1782
1791
  var ActionBase = import_zod18.z.object({
1783
- id: import_zod18.z.string(),
1792
+ id: UUID,
1784
1793
  transactionId: import_zod18.z.string(),
1785
1794
  createdByUserType: TokenUserType,
1786
1795
  createdAt: import_zod18.z.string().datetime(),
@@ -1789,14 +1798,16 @@ var ActionBase = import_zod18.z.object({
1789
1798
  createdBySignature: import_zod18.z.string().nullish().describe("Reference to signature of the user who created the action"),
1790
1799
  createdAtLocation: CreatedAtLocation,
1791
1800
  declaration: ActionUpdate,
1792
- annotation: ActionUpdate.optional(),
1801
+ annotation: ActionUpdate.optional().nullable(),
1793
1802
  status: import_zod18.z.enum([
1794
1803
  ActionStatus.Requested,
1795
1804
  ActionStatus.Accepted,
1796
1805
  ActionStatus.Rejected
1797
1806
  ]),
1798
1807
  // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1799
- originalActionId: import_zod18.z.string().optional()
1808
+ originalActionId: UUID.optional().nullable().describe(
1809
+ "Reference to the original action that was asynchronously rejected or accepted by 3rd party integration."
1810
+ )
1800
1811
  });
1801
1812
  var AssignedAction = ActionBase.merge(
1802
1813
  import_zod18.z.object({
@@ -1806,8 +1817,7 @@ var AssignedAction = ActionBase.merge(
1806
1817
  );
1807
1818
  var UnassignedAction = ActionBase.merge(
1808
1819
  import_zod18.z.object({
1809
- type: import_zod18.z.literal(ActionType.UNASSIGN),
1810
- assignedTo: import_zod18.z.literal(null)
1820
+ type: import_zod18.z.literal(ActionType.UNASSIGN)
1811
1821
  })
1812
1822
  );
1813
1823
  var RegisterAction = ActionBase.merge(
@@ -2131,6 +2141,29 @@ var ajv = new import_ajv.default({
2131
2141
  allowUnionTypes: true
2132
2142
  });
2133
2143
  (0, import_ajv_formats.default)(ajv);
2144
+ ajv.addKeyword({
2145
+ keyword: "daysFromNow",
2146
+ type: "string",
2147
+ schemaType: "object",
2148
+ $data: true,
2149
+ errors: true,
2150
+ validate(schema, data, _, dataContext) {
2151
+ if (!(dataContext && dataContext.rootData && typeof dataContext.rootData === "object" && "$now" in dataContext.rootData && typeof dataContext.rootData.$now === "string")) {
2152
+ throw new Error("Validation context must contain $now");
2153
+ }
2154
+ const { days, clause } = schema;
2155
+ if (typeof data !== "string") {
2156
+ return false;
2157
+ }
2158
+ const date = new Date(data);
2159
+ if (isNaN(date.getTime())) {
2160
+ return false;
2161
+ }
2162
+ const now = new Date(dataContext.rootData.$now);
2163
+ const offsetDate = new Date(now.getTime() + days * 24 * 60 * 60 * 1e3);
2164
+ return clause === "after" ? (0, import_date_fns.isAfter)(date, offsetDate) : (0, import_date_fns.isBefore)(date, offsetDate);
2165
+ }
2166
+ });
2134
2167
  function validate(schema, data) {
2135
2168
  return ajv.validate(schema, data);
2136
2169
  }
@@ -2344,12 +2377,6 @@ function getValidatorsForField(fieldId, validations) {
2344
2377
  }).filter((x) => x !== null);
2345
2378
  }
2346
2379
 
2347
- // ../commons/src/uuid.ts
2348
- var import_uuid = require("uuid");
2349
- function getUUID() {
2350
- return (0, import_uuid.v4)();
2351
- }
2352
-
2353
2380
  // ../commons/src/utils.ts
2354
2381
  function getOrThrow(x, message) {
2355
2382
  if (x === void 0 || x === null) {
@@ -2357,6 +2384,9 @@ function getOrThrow(x, message) {
2357
2384
  }
2358
2385
  return x;
2359
2386
  }
2387
+ function joinValues(values, separator = " ") {
2388
+ return values.filter((value) => !!value).join(separator).trim();
2389
+ }
2360
2390
 
2361
2391
  // ../commons/src/events/utils.ts
2362
2392
  function isDeclarationActionConfig(action) {
@@ -2458,7 +2488,7 @@ function createEmptyDraft(eventId, draftId, actionType) {
2458
2488
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2459
2489
  createdByUserType: TokenUserType.Enum.user,
2460
2490
  createdBy: "@todo",
2461
- createdAtLocation: "@todo",
2491
+ createdAtLocation: "00000000-0000-0000-0000-000000000000",
2462
2492
  status: ActionStatus.Accepted,
2463
2493
  transactionId: "@todo",
2464
2494
  createdByRole: "@todo"
@@ -2751,9 +2781,6 @@ function createEventConditionals() {
2751
2781
  })
2752
2782
  };
2753
2783
  }
2754
- function getDateFromNow(days) {
2755
- return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2756
- }
2757
2784
  function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2758
2785
  return {
2759
2786
  type: "object",
@@ -2772,6 +2799,20 @@ function isFieldReference(value) {
2772
2799
  return typeof value === "object" && value !== null && "$$field" in value;
2773
2800
  }
2774
2801
  function createFieldConditionals(fieldId) {
2802
+ const getDayRange = (days, clause) => ({
2803
+ type: "object",
2804
+ properties: {
2805
+ [fieldId]: {
2806
+ type: "string",
2807
+ format: "date",
2808
+ daysFromNow: {
2809
+ days,
2810
+ clause
2811
+ }
2812
+ }
2813
+ },
2814
+ required: [fieldId]
2815
+ });
2775
2816
  const getDateRange = (date, clause) => ({
2776
2817
  type: "object",
2777
2818
  properties: {
@@ -2790,12 +2831,8 @@ function createFieldConditionals(fieldId) {
2790
2831
  $$field: fieldId,
2791
2832
  isAfter: () => ({
2792
2833
  days: (days) => ({
2793
- inPast: () => defineFormConditional(
2794
- getDateRange(getDateFromNow(days), "formatMinimum")
2795
- ),
2796
- inFuture: () => defineFormConditional(
2797
- getDateRange(getDateFromNow(-days), "formatMinimum")
2798
- )
2834
+ inPast: () => defineFormConditional(getDayRange(-days, "after")),
2835
+ inFuture: () => defineFormConditional(getDayRange(days, "after"))
2799
2836
  }),
2800
2837
  date: (date) => {
2801
2838
  if (isFieldReference(date)) {
@@ -2810,16 +2847,12 @@ function createFieldConditionals(fieldId) {
2810
2847
  }
2811
2848
  return defineFormConditional(getDateRange(date, "formatMinimum"));
2812
2849
  },
2813
- now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2850
+ now: () => defineFormConditional(getDateRange({ $data: "/$now" }, "formatMinimum"))
2814
2851
  }),
2815
2852
  isBefore: () => ({
2816
2853
  days: (days) => ({
2817
- inPast: () => defineFormConditional(
2818
- getDateRange(getDateFromNow(days), "formatMaximum")
2819
- ),
2820
- inFuture: () => defineFormConditional(
2821
- getDateRange(getDateFromNow(-days), "formatMaximum")
2822
- )
2854
+ inPast: () => defineFormConditional(getDayRange(days, "before")),
2855
+ inFuture: () => defineFormConditional(getDayRange(-days, "before"))
2823
2856
  }),
2824
2857
  date: (date) => {
2825
2858
  if (isFieldReference(date)) {
@@ -2834,7 +2867,7 @@ function createFieldConditionals(fieldId) {
2834
2867
  }
2835
2868
  return defineFormConditional(getDateRange(date, "formatMaximum"));
2836
2869
  },
2837
- now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2870
+ now: () => defineFormConditional(getDateRange({ $data: "/$now" }, "formatMaximum"))
2838
2871
  }),
2839
2872
  isEqualTo: (value) => {
2840
2873
  if (isFieldReference(value)) {
@@ -3060,8 +3093,11 @@ var EventStatus = import_zod22.z.enum([
3060
3093
  "REJECTED",
3061
3094
  "ARCHIVED"
3062
3095
  ]);
3063
- var CustomFlags = {
3064
- CERTIFICATE_PRINTED: "certificate-printed"
3096
+ var InherentFlags = {
3097
+ PRINTED: "printed",
3098
+ INCOMPLETE: "incomplete",
3099
+ REJECTED: "rejected",
3100
+ CORRECTION_REQUESTED: "correction-requested"
3065
3101
  };
3066
3102
  var Flag = import_zod22.z.string().regex(
3067
3103
  new RegExp(
@@ -3070,7 +3106,7 @@ var Flag = import_zod22.z.string().regex(
3070
3106
  ).join("|").toLowerCase()})$`
3071
3107
  ),
3072
3108
  "Flag must be in the format ActionType:ActionStatus (lowerCase)"
3073
- ).or(import_zod22.z.nativeEnum(CustomFlags));
3109
+ ).or(import_zod22.z.nativeEnum(InherentFlags));
3074
3110
  var ZodDate = import_zod22.z.string().date();
3075
3111
  var ActionCreationMetadata = import_zod22.z.object({
3076
3112
  createdAt: import_zod22.z.string().datetime().describe("The timestamp when the action request was created."),
@@ -3093,7 +3129,7 @@ var LegalStatuses = import_zod22.z.object({
3093
3129
  [EventStatus.enum.REGISTERED]: RegistrationCreationMetadata.nullish()
3094
3130
  });
3095
3131
  var EventMetadata = import_zod22.z.object({
3096
- id: import_zod22.z.string(),
3132
+ id: UUID,
3097
3133
  type: import_zod22.z.string().describe("The type of event, such as birth, death, or marriage."),
3098
3134
  status: EventStatus,
3099
3135
  legalStatuses: LegalStatuses.describe(
@@ -3108,7 +3144,9 @@ var EventMetadata = import_zod22.z.object({
3108
3144
  "Location of the user who created the event."
3109
3145
  ),
3110
3146
  createdBySignature: import_zod22.z.string().nullish().describe("Signature of the user who created the event."),
3111
- updatedAtLocation: import_zod22.z.string().nullish().describe("Location of the user who last changed the status."),
3147
+ updatedAtLocation: UUID.nullish().describe(
3148
+ "Location of the user who last changed the status."
3149
+ ),
3112
3150
  updatedAt: import_zod22.z.string().datetime().describe(
3113
3151
  "Timestamp of the most recent *accepted* status change. Possibly 3rd party update, if action is validation asynchronously."
3114
3152
  ),
@@ -3287,8 +3325,11 @@ var Range = import_zod24.z.object({
3287
3325
  }).openapi({
3288
3326
  ref: "Range"
3289
3327
  });
3290
- var Not = import_zod24.z.object({ type: import_zod24.z.literal("not"), term: import_zod24.z.string() }).openapi({
3291
- ref: "Not"
3328
+ var ContainsFlags = import_zod24.z.object({
3329
+ anyOf: import_zod24.z.array(Flag).optional(),
3330
+ noneOf: import_zod24.z.array(Flag).optional()
3331
+ }).openapi({
3332
+ ref: "ContainsFlags"
3292
3333
  });
3293
3334
  var Within = import_zod24.z.object({ type: import_zod24.z.literal("within"), location: import_zod24.z.string() }).openapi({
3294
3335
  ref: "Within"
@@ -3309,7 +3350,7 @@ var DateCondition = import_zod24.z.union([ExactDate, RangeDate]).openapi({
3309
3350
  });
3310
3351
  var QueryInput = import_zod24.z.lazy(
3311
3352
  () => import_zod24.z.union([
3312
- import_zod24.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf, Not]),
3353
+ import_zod24.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf]),
3313
3354
  import_zod24.z.record(import_zod24.z.string(), QueryInput)
3314
3355
  ])
3315
3356
  ).openapi({
@@ -3333,7 +3374,7 @@ var QueryExpression = import_zod24.z.object({
3333
3374
  createdBy: import_zod24.z.optional(Exact),
3334
3375
  updatedBy: import_zod24.z.optional(Exact),
3335
3376
  trackingId: import_zod24.z.optional(Exact),
3336
- flags: import_zod24.z.optional(import_zod24.z.array(import_zod24.z.union([AnyOf, Not]))),
3377
+ flags: import_zod24.z.optional(ContainsFlags),
3337
3378
  data: QueryInput
3338
3379
  }).partial().refine((obj) => Object.values(obj).some((val) => val !== void 0), {
3339
3380
  message: "At least one query field must be specified."
@@ -3388,6 +3429,11 @@ var SerializedQueryExpression = import_zod25.z.object({
3388
3429
  status: import_zod25.z.optional(import_zod25.z.union([AnyOfStatus, ExactStatus])),
3389
3430
  createdAt: import_zod25.z.optional(DateCondition),
3390
3431
  updatedAt: import_zod25.z.optional(DateCondition),
3432
+ "legalStatus.REGISTERED.createdAt": import_zod25.z.optional(DateCondition),
3433
+ "legalStatus.REGISTERED.createdAtLocation": import_zod25.z.optional(
3434
+ import_zod25.z.union([Within, Exact])
3435
+ ),
3436
+ "legalStatus.REGISTERED.registrationNumber": import_zod25.z.optional(Exact),
3391
3437
  createdAtLocation: import_zod25.z.optional(
3392
3438
  import_zod25.z.union([SerializableWithin, SerializableExact])
3393
3439
  ),
@@ -3399,7 +3445,7 @@ var SerializedQueryExpression = import_zod25.z.object({
3399
3445
  createdByUserType: TokenUserType,
3400
3446
  updatedBy: import_zod25.z.optional(SerializableExact),
3401
3447
  trackingId: import_zod25.z.optional(Exact),
3402
- flags: import_zod25.z.optional(import_zod25.z.array(import_zod25.z.union([AnyOf, Not]))),
3448
+ flags: import_zod25.z.optional(ContainsFlags),
3403
3449
  data: QueryInput
3404
3450
  }).partial();
3405
3451
  var Or2 = import_zod25.z.object({
@@ -3457,7 +3503,6 @@ var AvailableIcons = import_zod26.z.enum([
3457
3503
  "Copy",
3458
3504
  "Database",
3459
3505
  "DotsThreeVertical",
3460
- "DownloadSimple",
3461
3506
  "ArrowCounterClockwise",
3462
3507
  "MagnifyingGlassMinus",
3463
3508
  "MagnifyingGlassPlus",
@@ -3618,14 +3663,14 @@ var import_zod29 = require("zod");
3618
3663
  // ../commons/src/events/ActionInput.ts
3619
3664
  var import_zod28 = require("zod");
3620
3665
  var import_zod_openapi10 = require("zod-openapi");
3621
- var import_uuid3 = require("uuid");
3622
3666
  (0, import_zod_openapi10.extendZodWithOpenApi)(import_zod28.z);
3623
3667
  var BaseActionInput = import_zod28.z.object({
3624
- eventId: import_zod28.z.string(),
3668
+ eventId: UUID,
3625
3669
  transactionId: import_zod28.z.string(),
3626
3670
  declaration: ActionUpdate.default({}),
3627
3671
  annotation: ActionUpdate.optional(),
3628
- originalActionId: import_zod28.z.string().optional(),
3672
+ originalActionId: UUID.optional(),
3673
+ // should not be part of base action.
3629
3674
  keepAssignment: import_zod28.z.boolean().optional()
3630
3675
  });
3631
3676
  var CreateActionInput = BaseActionInput.merge(
@@ -3639,7 +3684,7 @@ var RegisterActionInput = BaseActionInput.merge(
3639
3684
  type: import_zod28.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
3640
3685
  registrationNumber: import_zod28.z.string().optional()
3641
3686
  })
3642
- );
3687
+ ).strict();
3643
3688
  var ValidateActionInput = BaseActionInput.merge(
3644
3689
  import_zod28.z.object({
3645
3690
  type: import_zod28.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
@@ -3653,7 +3698,7 @@ var NotifyActionInput = BaseActionInput.merge(
3653
3698
  ).openapi({
3654
3699
  default: {
3655
3700
  eventId: "<event-id-here>",
3656
- transactionId: (0, import_uuid3.v4)(),
3701
+ transactionId: getUUID(),
3657
3702
  declaration: {},
3658
3703
  annotation: {},
3659
3704
  type: ActionType.NOTIFY
@@ -3720,7 +3765,7 @@ var ReadActionInput = BaseActionInput.merge(
3720
3765
  type: import_zod28.z.literal(ActionType.READ).default(ActionType.READ)
3721
3766
  })
3722
3767
  );
3723
- var DeleteActionInput = import_zod28.z.object({ eventId: import_zod28.z.string() });
3768
+ var DeleteActionInput = import_zod28.z.object({ eventId: UUID });
3724
3769
  var ActionInput = import_zod28.z.discriminatedUnion("type", [
3725
3770
  CreateActionInput.openapi({ ref: "CreateActionInput" }),
3726
3771
  ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
@@ -3751,8 +3796,8 @@ var ActionInput = import_zod28.z.discriminatedUnion("type", [
3751
3796
 
3752
3797
  // ../commons/src/events/Draft.ts
3753
3798
  var Draft = import_zod29.z.object({
3754
- id: import_zod29.z.string(),
3755
- eventId: import_zod29.z.string(),
3799
+ id: UUID,
3800
+ eventId: UUID,
3756
3801
  transactionId: import_zod29.z.string(),
3757
3802
  createdAt: import_zod29.z.string().datetime(),
3758
3803
  action: ActionBase.extend({
@@ -3770,18 +3815,18 @@ var DraftInput = BaseActionInput.extend({
3770
3815
 
3771
3816
  // ../commons/src/events/EventInput.ts
3772
3817
  var import_zod30 = require("zod");
3773
- var import_uuid4 = require("uuid");
3818
+ var import_uuid8 = require("uuid");
3774
3819
  var EventInput = import_zod30.z.object({
3775
3820
  transactionId: import_zod30.z.string(),
3776
3821
  type: import_zod30.z.string()
3777
- }).openapi({ default: { transactionId: (0, import_uuid4.v4)(), type: "v2.birth" } });
3822
+ }).openapi({ default: { transactionId: (0, import_uuid8.v4)(), type: "v2.birth" } });
3778
3823
 
3779
3824
  // ../commons/src/events/EventDocument.ts
3780
3825
  var import_zod31 = require("zod");
3781
3826
  var import_zod_openapi11 = require("zod-openapi");
3782
3827
  (0, import_zod_openapi11.extendZodWithOpenApi)(import_zod31.z);
3783
3828
  var EventDocument = import_zod31.z.object({
3784
- id: import_zod31.z.string(),
3829
+ id: UUID,
3785
3830
  type: import_zod31.z.string(),
3786
3831
  createdAt: import_zod31.z.string().datetime(),
3787
3832
  updatedAt: import_zod31.z.string().datetime(),
@@ -3866,15 +3911,69 @@ function getLegalStatuses(actions) {
3866
3911
  };
3867
3912
  }
3868
3913
 
3869
- // ../commons/src/events/state/index.ts
3870
- function getStatusFromActions(actions) {
3871
- const hasRejectedAction = actions.some(
3872
- (a) => a.status === ActionStatus.Rejected
3914
+ // ../commons/src/events/state/flags.ts
3915
+ function isCertificatePrinted(actions) {
3916
+ return actions.reduce((prev, { type }) => {
3917
+ if (type === ActionType.PRINT_CERTIFICATE) {
3918
+ return true;
3919
+ }
3920
+ if (type === ActionType.APPROVE_CORRECTION) {
3921
+ return false;
3922
+ }
3923
+ return prev;
3924
+ }, false);
3925
+ }
3926
+ function isCorrectionRequested(actions) {
3927
+ return actions.reduce((prev, { type }) => {
3928
+ if (type === ActionType.REQUEST_CORRECTION) {
3929
+ return true;
3930
+ }
3931
+ if (type === ActionType.APPROVE_CORRECTION) {
3932
+ return false;
3933
+ }
3934
+ if (type === ActionType.REJECT_CORRECTION) {
3935
+ return false;
3936
+ }
3937
+ return prev;
3938
+ }, false);
3939
+ }
3940
+ function isDeclarationIncomplete(actions) {
3941
+ return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
3942
+ }
3943
+ function isRejected(actions) {
3944
+ return getStatusFromActions(actions) === EventStatus.enum.REJECTED;
3945
+ }
3946
+ function getFlagsFromActions(actions) {
3947
+ const sortedActions = actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
3948
+ const actionStatus = sortedActions.reduce(
3949
+ (actionStatuses, { type, status }) => ({
3950
+ ...actionStatuses,
3951
+ [type]: status
3952
+ }),
3953
+ {}
3873
3954
  );
3874
- if (hasRejectedAction) {
3875
- return EventStatus.enum.REJECTED;
3955
+ const flags = Object.entries(actionStatus).filter(([, status]) => status !== ActionStatus.Accepted).map(([type, status]) => {
3956
+ const flag = joinValues([type, status], ":").toLowerCase();
3957
+ return flag;
3958
+ });
3959
+ if (isCertificatePrinted(sortedActions)) {
3960
+ flags.push(InherentFlags.PRINTED);
3876
3961
  }
3877
- return actions.reduce((status, action) => {
3962
+ if (isCorrectionRequested(sortedActions)) {
3963
+ flags.push(InherentFlags.CORRECTION_REQUESTED);
3964
+ }
3965
+ if (isDeclarationIncomplete(sortedActions)) {
3966
+ flags.push(InherentFlags.INCOMPLETE);
3967
+ }
3968
+ if (isRejected(sortedActions)) {
3969
+ flags.push(InherentFlags.REJECTED);
3970
+ }
3971
+ return flags;
3972
+ }
3973
+
3974
+ // ../commons/src/events/state/index.ts
3975
+ function getStatusFromActions(actions) {
3976
+ return actions.filter(({ status }) => status === ActionStatus.Accepted).reduce((status, action) => {
3878
3977
  switch (action.type) {
3879
3978
  case ActionType.CREATE:
3880
3979
  return EventStatus.enum.CREATED;
@@ -3904,38 +4003,6 @@ function getStatusFromActions(actions) {
3904
4003
  }
3905
4004
  }, EventStatus.enum.CREATED);
3906
4005
  }
3907
- function getFlagsFromActions(actions) {
3908
- const sortedactions = actions.sort(
3909
- (a, b) => a.createdAt.localeCompare(b.createdAt)
3910
- );
3911
- const actionStatus = sortedactions.reduce(
3912
- (actionStatuses, { type, status }) => ({
3913
- ...actionStatuses,
3914
- [type]: status
3915
- }),
3916
- {}
3917
- );
3918
- const flags = Object.entries(actionStatus).filter(([, status]) => status !== ActionStatus.Accepted).map(([type, status]) => {
3919
- const flag = `${type.toLowerCase()}:${status.toLowerCase()}`;
3920
- return flag;
3921
- });
3922
- const isCertificatePrinted = sortedactions.reduce(
3923
- (prev, { type }) => {
3924
- if (type === ActionType.PRINT_CERTIFICATE) {
3925
- return true;
3926
- }
3927
- if (type === ActionType.APPROVE_CORRECTION) {
3928
- return false;
3929
- }
3930
- return prev;
3931
- },
3932
- false
3933
- );
3934
- if (isCertificatePrinted) {
3935
- flags.push(CustomFlags.CERTIFICATE_PRINTED);
3936
- }
3937
- return flags;
3938
- }
3939
4006
  function getAssignedUserFromActions(actions) {
3940
4007
  return actions.reduce((user2, action) => {
3941
4008
  if (action.type === ActionType.ASSIGN) {
@@ -4822,7 +4889,7 @@ var PRINT_CERTIFICATE_FORM = defineActionForm({
4822
4889
  var TENNIS_CLUB_DECLARATION_REVIEW = {
4823
4890
  title: {
4824
4891
  id: "v2.event.tennis-club-membership.action.declare.form.review.title",
4825
- defaultMessage: "{applicant.name.firstname, select, __EMPTY__ {Member declaration} other {{applicant.name.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.name.firstname} {applicant.name.surname}}}}}",
4892
+ defaultMessage: "{applicant.name.firstname, select, __EMPTY__ {Member declaration} other {{applicant.name.surname, select, __EMPTY__ {Member declaration for {applicant.name.firstname}} other {Member declaration for {applicant.name.firstname} {applicant.name.surname}}}}}",
4826
4893
  description: "Title of the review page"
4827
4894
  },
4828
4895
  fields: [
@@ -6493,17 +6560,18 @@ function generateActionDocument({
6493
6560
  configuration,
6494
6561
  action,
6495
6562
  rng = () => 0.1,
6496
- defaults = {}
6563
+ defaults = {},
6564
+ user: user2 = {}
6497
6565
  }) {
6498
6566
  const actionBase = {
6499
6567
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
6500
6568
  // @TODO: This should be fixed in the future.
6501
6569
  createdAt: new Date(Date.now() - 500).toISOString(),
6502
- createdBy: getUUID(),
6570
+ createdBy: user2.id ?? getUUID(),
6503
6571
  createdByUserType: TokenUserType.Enum.user,
6504
6572
  createdByRole: TestUserRole.Enum.FIELD_AGENT,
6505
6573
  id: getUUID(),
6506
- createdAtLocation: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
6574
+ createdAtLocation: user2.primaryOfficeId ?? "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
6507
6575
  declaration: generateActionDeclarationInput(configuration, action, rng),
6508
6576
  annotation: {},
6509
6577
  status: ActionStatus.Accepted,
@@ -6518,7 +6586,7 @@ function generateActionDocument({
6518
6586
  case ActionType.DECLARE:
6519
6587
  return { ...actionBase, type: action };
6520
6588
  case ActionType.UNASSIGN:
6521
- return { ...actionBase, type: action, assignedTo: null };
6589
+ return { ...actionBase, type: action };
6522
6590
  case ActionType.ASSIGN:
6523
6591
  return { ...actionBase, assignedTo: getUUID(), type: action };
6524
6592
  case ActionType.VALIDATE:
@@ -6557,13 +6625,14 @@ function generateActionDocument({
6557
6625
  function generateEventDocument({
6558
6626
  configuration,
6559
6627
  actions,
6560
- rng = () => 0.1
6628
+ rng = () => 0.1,
6629
+ user: user2
6561
6630
  }) {
6562
6631
  return {
6563
6632
  trackingId: getUUID(),
6564
6633
  type: configuration.id,
6565
6634
  actions: actions.map(
6566
- (action) => generateActionDocument({ configuration, action, rng })
6635
+ (action) => generateActionDocument({ configuration, action, rng, user: user2 })
6567
6636
  ),
6568
6637
  // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
6569
6638
  // @TODO: This should be fixed in the future.
@@ -6631,7 +6700,7 @@ function createPrng(seed) {
6631
6700
  return state / MODULUS;
6632
6701
  };
6633
6702
  }
6634
- function generateUuid(rng) {
6703
+ function generateUuid(rng = () => 0.1) {
6635
6704
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
6636
6705
  const r = Math.floor(rng() * 16);
6637
6706
  const v = c === "x" ? r : r & 3 | 8;
@@ -6643,6 +6712,11 @@ function generateTrackingId(rng) {
6643
6712
  const trackingId = uuid.slice(0, 6).toUpperCase();
6644
6713
  return trackingId;
6645
6714
  }
6715
+ function generateRegistrationNumber(rng) {
6716
+ const uuid = generateUuid(rng).replace(/-/g, "");
6717
+ const registrationNumber = uuid.slice(0, 12).toUpperCase();
6718
+ return registrationNumber;
6719
+ }
6646
6720
  function generateRandomSignature(rng) {
6647
6721
  return `/random-bucket/${generateUuid(rng)}.png`;
6648
6722
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.0-rc.f7aaf07",
3
+ "version": "1.8.0-rc.f7e4aad",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {
@@ -19,8 +19,8 @@
19
19
  "ajv": "^8.17.1",
20
20
  "ajv-formats": "^3.0.1",
21
21
  "superjson": "1.9.0-0",
22
- "@trpc/client": "^11.0.0-rc.648",
23
- "@trpc/server": "^11.0.0-rc.532",
22
+ "@trpc/client": "11.4.2",
23
+ "@trpc/server": "11.4.2",
24
24
  "zod-openapi": "^4.2.4"
25
25
  },
26
26
  "devDependencies": {