@opencrvs/toolkit 1.8.1-rc.5530ede → 1.8.1-rc.5c415ba

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.
@@ -117,6 +117,8 @@ export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{
117
117
  readonly REJECTED: "rejected";
118
118
  readonly CORRECTION_REQUESTED: "correction-requested";
119
119
  }>]>, "many">;
120
+ copiesPrintedForTemplate: z.ZodOptional<z.ZodNumber>;
121
+ modifiedAt: z.ZodOptional<z.ZodString>;
120
122
  }, {
121
123
  declaration: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodString, z.ZodString, z.ZodUnion<[z.ZodObject<{
122
124
  start: z.ZodString;
@@ -352,6 +354,8 @@ export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{
352
354
  dateOfEvent?: string | null | undefined;
353
355
  updatedAtLocation?: (string & z.BRAND<"UUID">) | null | undefined;
354
356
  updatedBy?: string | null | undefined;
357
+ copiesPrintedForTemplate?: number | undefined;
358
+ modifiedAt?: string | undefined;
355
359
  }, {
356
360
  type: string;
357
361
  id: string;
@@ -439,6 +443,8 @@ export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{
439
443
  dateOfEvent?: string | null | undefined;
440
444
  updatedAtLocation?: string | null | undefined;
441
445
  updatedBy?: string | null | undefined;
446
+ copiesPrintedForTemplate?: number | undefined;
447
+ modifiedAt?: string | undefined;
442
448
  }>;
443
449
  export declare const EventSearchIndex: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
444
450
  type: z.ZodString;
@@ -297,6 +297,8 @@ export declare const EventMetadata: z.ZodObject<{
297
297
  readonly REJECTED: "rejected";
298
298
  readonly CORRECTION_REQUESTED: "correction-requested";
299
299
  }>]>, "many">;
300
+ copiesPrintedForTemplate: z.ZodOptional<z.ZodNumber>;
301
+ modifiedAt: z.ZodOptional<z.ZodString>;
300
302
  }, "strip", z.ZodTypeAny, {
301
303
  type: string;
302
304
  id: string & z.BRAND<"UUID">;
@@ -335,6 +337,8 @@ export declare const EventMetadata: z.ZodObject<{
335
337
  dateOfEvent?: string | null | undefined;
336
338
  updatedAtLocation?: (string & z.BRAND<"UUID">) | null | undefined;
337
339
  updatedBy?: string | null | undefined;
340
+ copiesPrintedForTemplate?: number | undefined;
341
+ modifiedAt?: string | undefined;
338
342
  }, {
339
343
  type: string;
340
344
  id: string;
@@ -373,6 +377,8 @@ export declare const EventMetadata: z.ZodObject<{
373
377
  dateOfEvent?: string | null | undefined;
374
378
  updatedAtLocation?: string | null | undefined;
375
379
  updatedBy?: string | null | undefined;
380
+ copiesPrintedForTemplate?: number | undefined;
381
+ modifiedAt?: string | undefined;
376
382
  }>;
377
383
  export type EventMetadata = z.infer<typeof EventMetadata>;
378
384
  export declare const EventMetadataKeysArray: readonly ["id", "type", "status", "createdAt", "dateOfEvent", "createdBy", "createdByUserType", "updatedByUserRole", "createdAtLocation", "updatedAtLocation", "updatedAt", "assignedTo", "updatedBy", "trackingId", "legalStatuses", "flags"];
@@ -37,9 +37,63 @@ declare function eventFn(fieldId: EventFieldId): {
37
37
  declare const event: typeof eventFn & {
38
38
  /**
39
39
  * Checks if the event contains a specific action type.
40
+ * Can be used directly as a conditional or chained with additional methods.
40
41
  * @param action - The action type to check for.
41
42
  */
42
- hasAction: (action: ActionType) => import("../conditionals/conditionals").JSONSchema;
43
+ hasAction: (action: ActionType) => {
44
+ /**
45
+ * Creates a conditional that checks if the event contains a specific action type
46
+ * with a minimum count of occurrences.
47
+ *
48
+ * @param minCount - The minimum number of actions required.
49
+ */
50
+ minCount: (minCount: number) => import("../conditionals/conditionals").JSONSchema;
51
+ /**
52
+ * Builds a conditional that sets a maximum count for the number of actions.
53
+ * This is useful for limiting the number of actions of a specific type in a single event.
54
+ */
55
+ maxCount: (maxCount: number) => import("../conditionals/conditionals").JSONSchema;
56
+ /**
57
+ * Adds additional field constraints to the action matching.
58
+ *
59
+ * @param fields - Object containing additional fields to match on the action.
60
+ */
61
+ withFields: (fields: Record<string, unknown>) => {
62
+ /**
63
+ * Creates a conditional that checks if the event contains a specific action type
64
+ * with a minimum count of occurrences.
65
+ *
66
+ * @param minCount - The minimum number of actions required.
67
+ */
68
+ minCount: (minCount: number) => import("../conditionals/conditionals").JSONSchema;
69
+ /**
70
+ * Builds a conditional that sets a maximum count for the number of actions.
71
+ * This is useful for limiting the number of actions of a specific type in a single event.
72
+ */
73
+ maxCount: (maxCount: number) => import("../conditionals/conditionals").JSONSchema;
74
+ };
75
+ /**
76
+ * Adds template ID constraint to the action matching.
77
+ * This is a convenience method that adds actionDetails.templateId to the fields.
78
+ *
79
+ * @param id - The template ID to match against.
80
+ */
81
+ withTemplate: (id: string) => {
82
+ /**
83
+ * Creates a conditional that checks if the event contains a specific action type
84
+ * with a minimum count of occurrences.
85
+ *
86
+ * @param minCount - The minimum number of actions required.
87
+ */
88
+ minCount: (minCount: number) => import("../conditionals/conditionals").JSONSchema;
89
+ /**
90
+ * Builds a conditional that sets a maximum count for the number of actions.
91
+ * This is useful for limiting the number of actions of a specific type in a single event.
92
+ */
93
+ maxCount: (maxCount: number) => import("../conditionals/conditionals").JSONSchema;
94
+ };
95
+ __nominal__type: "JSONSchema";
96
+ };
43
97
  field(field: WorkqueueColumnKeys): WorkqueueColumnValue;
44
98
  };
45
99
  export { event };
@@ -414,7 +414,7 @@ export declare function eventPayloadGenerator(rng: () => number): {
414
414
  requestId: string;
415
415
  keepAssignment: boolean | undefined;
416
416
  };
417
- reject: (eventId: string, requestId: string, input?: Partial<Pick<RejectCorrectionActionInput, "transactionId" | "annotation" | "keepAssignment">>) => {
417
+ reject: (eventId: string, requestId: string, input: Partial<Pick<RejectCorrectionActionInput, "transactionId" | "annotation" | "keepAssignment" | "reason">>) => {
418
418
  type: "REJECT_CORRECTION";
419
419
  transactionId: string;
420
420
  declaration: {};
@@ -422,6 +422,10 @@ export declare function eventPayloadGenerator(rng: () => number): {
422
422
  eventId: string;
423
423
  requestId: string;
424
424
  keepAssignment: boolean | undefined;
425
+ reason: {
426
+ message: string;
427
+ isDuplicate?: boolean | undefined;
428
+ };
425
429
  };
426
430
  };
427
431
  };
@@ -6758,6 +6758,10 @@ export declare function findActiveDrafts(event: EventDocument, drafts: Draft[]):
6758
6758
  start: string;
6759
6759
  end: string;
6760
6760
  } | null | undefined> | null | undefined;
6761
+ actionDetails?: {
6762
+ templateId?: string | undefined;
6763
+ isImmediateCorrection?: boolean | undefined;
6764
+ } | null | undefined;
6761
6765
  originalActionId?: (string & import("zod").BRAND<"UUID">) | null | undefined;
6762
6766
  };
6763
6767
  }[];
@@ -39,6 +39,7 @@ __export(events_exports, {
39
39
  ActionConfig: () => ActionConfig,
40
40
  ActionConfigBase: () => ActionConfigBase,
41
41
  ActionCreationMetadata: () => ActionCreationMetadata,
42
+ ActionDetails: () => ActionDetails,
42
43
  ActionDocument: () => ActionDocument,
43
44
  ActionFormConfig: () => ActionFormConfig,
44
45
  ActionInput: () => ActionInput,
@@ -197,6 +198,7 @@ __export(events_exports, {
197
198
  annotationActions: () => annotationActions,
198
199
  applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
199
200
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
201
+ areCertificateConditionsMet: () => areCertificateConditionsMet,
200
202
  areConditionsMet: () => areConditionsMet,
201
203
  compositeFieldTypes: () => compositeFieldTypes,
202
204
  createEmptyDraft: () => createEmptyDraft,
@@ -606,8 +608,8 @@ var UrbanAddressUpdateValue = AdminStructure.extend({
606
608
  zipCode: import_zod5.z.string().nullish()
607
609
  });
608
610
  var NameFieldValue = import_zod5.z.object({
609
- firstname: import_zod5.z.string().min(1),
610
- surname: import_zod5.z.string().min(1),
611
+ firstname: import_zod5.z.string(),
612
+ surname: import_zod5.z.string(),
611
613
  middlename: import_zod5.z.string().optional()
612
614
  });
613
615
  var NameFieldUpdateValue = import_zod5.z.object({
@@ -1222,7 +1224,8 @@ var CertificateConfig = import_zod11.z.object({
1222
1224
  delayed: import_zod11.z.number()
1223
1225
  }),
1224
1226
  svgUrl: import_zod11.z.string(),
1225
- fonts: import_zod11.z.record(FontFamily).optional()
1227
+ fonts: import_zod11.z.record(FontFamily).optional(),
1228
+ conditionals: import_zod11.z.array(ShowConditional).optional()
1226
1229
  });
1227
1230
  var CertificateTemplateConfig = CertificateConfig.extend({
1228
1231
  hash: import_zod11.z.string().optional(),
@@ -1882,6 +1885,10 @@ var ActionStatus = {
1882
1885
  Accepted: "Accepted",
1883
1886
  Rejected: "Rejected"
1884
1887
  };
1888
+ var ActionDetails = import_zod19.z.object({
1889
+ templateId: import_zod19.z.string().optional(),
1890
+ isImmediateCorrection: import_zod19.z.boolean().optional()
1891
+ });
1885
1892
  var ActionBase = import_zod19.z.object({
1886
1893
  id: UUID,
1887
1894
  transactionId: import_zod19.z.string(),
@@ -1893,6 +1900,7 @@ var ActionBase = import_zod19.z.object({
1893
1900
  createdAtLocation: CreatedAtLocation,
1894
1901
  declaration: ActionUpdate,
1895
1902
  annotation: ActionUpdate.optional().nullable(),
1903
+ actionDetails: ActionDetails.optional().nullable(),
1896
1904
  status: import_zod19.z.enum([
1897
1905
  ActionStatus.Requested,
1898
1906
  ActionStatus.Accepted,
@@ -1980,7 +1988,8 @@ var ApprovedCorrectionAction = ActionBase.merge(
1980
1988
  var RejectedCorrectionAction = ActionBase.merge(
1981
1989
  import_zod19.z.object({
1982
1990
  type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1983
- requestId: import_zod19.z.string()
1991
+ requestId: import_zod19.z.string(),
1992
+ reason: RejectionReason
1984
1993
  })
1985
1994
  );
1986
1995
  var ReadAction = ActionBase.merge(
@@ -2030,7 +2039,7 @@ var ResolvedUser = import_zod19.z.object({
2030
2039
  });
2031
2040
 
2032
2041
  // ../commons/src/conditionals/validate.ts
2033
- var import_ajv = __toESM(require("ajv"));
2042
+ var import__ = __toESM(require("ajv/dist/2019"));
2034
2043
  var import_ajv_formats = __toESM(require("ajv-formats"));
2035
2044
  var import_date_fns = require("date-fns");
2036
2045
 
@@ -2244,9 +2253,11 @@ var isNonInteractiveFieldType = (field2) => {
2244
2253
  };
2245
2254
 
2246
2255
  // ../commons/src/conditionals/validate.ts
2247
- var ajv = new import_ajv.default({
2256
+ var ajv = new import__.default({
2248
2257
  $data: true,
2249
- allowUnionTypes: true
2258
+ allowUnionTypes: true,
2259
+ strict: false
2260
+ // Allow minContains and other newer features
2250
2261
  });
2251
2262
  (0, import_ajv_formats.default)(ajv);
2252
2263
  ajv.addKeyword({
@@ -2484,6 +2495,11 @@ function getValidatorsForField(fieldId, validations) {
2484
2495
  };
2485
2496
  }).filter((x) => x !== null);
2486
2497
  }
2498
+ function areCertificateConditionsMet(conditions, values) {
2499
+ return conditions.every((condition) => {
2500
+ return ajv.validate(condition.conditional, values);
2501
+ });
2502
+ }
2487
2503
 
2488
2504
  // ../commons/src/utils.ts
2489
2505
  function getOrThrow(x, message) {
@@ -3194,32 +3210,107 @@ function eventFn(fieldId) {
3194
3210
  var event = Object.assign(eventFn, {
3195
3211
  /**
3196
3212
  * Checks if the event contains a specific action type.
3213
+ * Can be used directly as a conditional or chained with additional methods.
3197
3214
  * @param action - The action type to check for.
3198
3215
  */
3199
- hasAction: (action) => defineConditional({
3200
- type: "object",
3201
- properties: {
3202
- $event: {
3216
+ hasAction: (action) => {
3217
+ const basicConditional = defineConditional({
3218
+ type: "object",
3219
+ properties: {
3220
+ $event: {
3221
+ type: "object",
3222
+ properties: {
3223
+ actions: {
3224
+ type: "array",
3225
+ contains: {
3226
+ type: "object",
3227
+ properties: {
3228
+ type: {
3229
+ const: action
3230
+ }
3231
+ },
3232
+ required: ["type"]
3233
+ }
3234
+ }
3235
+ },
3236
+ required: ["actions"]
3237
+ }
3238
+ },
3239
+ required: ["$event"]
3240
+ });
3241
+ const buildActionConstraints = (additionalFields) => {
3242
+ const actionProperties = {
3243
+ type: { const: action }
3244
+ };
3245
+ const requiredFields = ["type"];
3246
+ if (additionalFields) {
3247
+ Object.entries(additionalFields).forEach(([key, value]) => {
3248
+ actionProperties[key] = { const: value };
3249
+ requiredFields.push(key);
3250
+ });
3251
+ }
3252
+ return { actionProperties, requiredFields };
3253
+ };
3254
+ const createCountConditional = (countType, count, additionalFields) => {
3255
+ const { actionProperties, requiredFields } = buildActionConstraints(additionalFields);
3256
+ return defineConditional({
3203
3257
  type: "object",
3204
3258
  properties: {
3205
- actions: {
3206
- type: "array",
3207
- contains: {
3208
- type: "object",
3209
- properties: {
3210
- type: {
3211
- const: action
3212
- }
3213
- },
3214
- required: ["type"]
3215
- }
3259
+ $event: {
3260
+ type: "object",
3261
+ properties: {
3262
+ actions: {
3263
+ type: "array",
3264
+ contains: {
3265
+ type: "object",
3266
+ properties: actionProperties,
3267
+ required: requiredFields
3268
+ },
3269
+ [countType]: count
3270
+ }
3271
+ },
3272
+ required: ["actions"]
3216
3273
  }
3217
3274
  },
3218
- required: ["actions"]
3219
- }
3220
- },
3221
- required: ["$event"]
3222
- }),
3275
+ required: ["$event"]
3276
+ });
3277
+ };
3278
+ const withMinMax = (additionalFields) => {
3279
+ return {
3280
+ /**
3281
+ * Creates a conditional that checks if the event contains a specific action type
3282
+ * with a minimum count of occurrences.
3283
+ *
3284
+ * @param minCount - The minimum number of actions required.
3285
+ */
3286
+ minCount: (minCount) => createCountConditional("minContains", minCount, additionalFields),
3287
+ /**
3288
+ * Builds a conditional that sets a maximum count for the number of actions.
3289
+ * This is useful for limiting the number of actions of a specific type in a single event.
3290
+ */
3291
+ maxCount: (maxCount) => createCountConditional("maxContains", maxCount, additionalFields)
3292
+ };
3293
+ };
3294
+ const chainableMethods = {
3295
+ /**
3296
+ * Adds additional field constraints to the action matching.
3297
+ *
3298
+ * @param fields - Object containing additional fields to match on the action.
3299
+ */
3300
+ withFields: (fields) => withMinMax(fields),
3301
+ /**
3302
+ * Adds template ID constraint to the action matching.
3303
+ * This is a convenience method that adds actionDetails.templateId to the fields.
3304
+ *
3305
+ * @param id - The template ID to match against.
3306
+ */
3307
+ withTemplate: (id) => withMinMax({
3308
+ actionDetails: { templateId: id }
3309
+ }),
3310
+ ...withMinMax()
3311
+ };
3312
+ return { ...basicConditional, ...chainableMethods };
3313
+ },
3223
3314
  field(field2) {
3224
3315
  return {
3225
3316
  $event: field2
@@ -3304,7 +3395,9 @@ var EventMetadata = import_zod23.z.object({
3304
3395
  trackingId: import_zod23.z.string().describe(
3305
3396
  "System-generated tracking ID used by informants or registrars to look up the event."
3306
3397
  ),
3307
- flags: import_zod23.z.array(Flag)
3398
+ flags: import_zod23.z.array(Flag),
3399
+ copiesPrintedForTemplate: import_zod23.z.number().optional(),
3400
+ modifiedAt: import_zod23.z.string().optional()
3308
3401
  });
3309
3402
  var EventMetadataKeysArray = [
3310
3403
  "id",
@@ -3834,6 +3927,7 @@ var BaseActionInput = import_zod29.z.object({
3834
3927
  transactionId: import_zod29.z.string(),
3835
3928
  declaration: ActionUpdate.default({}),
3836
3929
  annotation: ActionUpdate.optional(),
3930
+ actionDetails: ActionDetails.optional(),
3837
3931
  originalActionId: UUID.optional(),
3838
3932
  // should not be part of base action.
3839
3933
  keepAssignment: import_zod29.z.boolean().optional()
@@ -3916,7 +4010,8 @@ var RequestCorrectionActionInput = BaseActionInput.merge(
3916
4010
  var RejectCorrectionActionInput = BaseActionInput.merge(
3917
4011
  import_zod29.z.object({
3918
4012
  requestId: import_zod29.z.string(),
3919
- type: import_zod29.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
4013
+ type: import_zod29.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION),
4014
+ reason: RejectionReason
3920
4015
  })
3921
4016
  );
3922
4017
  var ApproveCorrectionActionInput = BaseActionInput.merge(
@@ -4283,7 +4378,8 @@ function getCurrentEventState(event2, config) {
4283
4378
  trackingId: event2.trackingId,
4284
4379
  updatedByUserRole: requestActionMetadata.createdByRole,
4285
4380
  dateOfEvent: resolveDateOfEvent(event2, declaration, config),
4286
- flags: getFlagsFromActions(event2.actions)
4381
+ flags: getFlagsFromActions(event2.actions),
4382
+ copiesPrintedForTemplate: event2.copiesPrintedForTemplate ?? 0
4287
4383
  });
4288
4384
  }
4289
4385
  function getCurrentEventStateWithDrafts({
@@ -6755,7 +6851,7 @@ function eventPayloadGenerator(rng) {
6755
6851
  requestId,
6756
6852
  keepAssignment: input.keepAssignment
6757
6853
  }),
6758
- reject: (eventId, requestId, input = {}) => ({
6854
+ reject: (eventId, requestId, input) => ({
6759
6855
  type: ActionType.REJECT_CORRECTION,
6760
6856
  transactionId: input.transactionId ?? getUUID(),
6761
6857
  declaration: {},
@@ -6766,7 +6862,8 @@ function eventPayloadGenerator(rng) {
6766
6862
  ),
6767
6863
  eventId,
6768
6864
  requestId,
6769
- keepAssignment: input.keepAssignment
6865
+ keepAssignment: input.keepAssignment,
6866
+ reason: input.reason ?? { message: "" }
6770
6867
  })
6771
6868
  }
6772
6869
  }
@@ -6825,7 +6922,8 @@ function generateActionDocument({
6825
6922
  return {
6826
6923
  ...actionBase,
6827
6924
  requestId: getUUID(),
6828
- type: action
6925
+ type: action,
6926
+ reason: { message: "Correction rejection" }
6829
6927
  };
6830
6928
  case ActionType.REGISTER:
6831
6929
  return {
@@ -6960,7 +7058,8 @@ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
6960
7058
  flags: [],
6961
7059
  legalStatuses: overrides.legalStatuses ?? {},
6962
7060
  declaration: overrides.declaration ?? generateRandomApplicant(rng),
6963
- trackingId: overrides.trackingId ?? generateTrackingId(rng)
7061
+ trackingId: overrides.trackingId ?? generateTrackingId(rng),
7062
+ copiesPrintedForTemplate: overrides.copiesPrintedForTemplate ?? 0
6964
7063
  };
6965
7064
  };
6966
7065
  var generateTranslationConfig = (message) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.1-rc.5530ede",
3
+ "version": "1.8.1-rc.5c415ba",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {