@opencrvs/toolkit 1.8.1-rc.b849abb → 1.8.1-rc.bbbfede

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" | "reason">>) => {
417
+ reject: (eventId: string, requestId: string, input?: Partial<Pick<RejectCorrectionActionInput, "transactionId" | "annotation" | "keepAssignment">>) => {
418
418
  type: "REJECT_CORRECTION";
419
419
  transactionId: string;
420
420
  declaration: {};
@@ -422,10 +422,6 @@ 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
- };
429
425
  };
430
426
  };
431
427
  };
@@ -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,
@@ -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,8 +1988,7 @@ 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(),
1984
- reason: RejectionReason
1991
+ requestId: import_zod19.z.string()
1985
1992
  })
1986
1993
  );
1987
1994
  var ReadAction = ActionBase.merge(
@@ -2031,7 +2038,7 @@ var ResolvedUser = import_zod19.z.object({
2031
2038
  });
2032
2039
 
2033
2040
  // ../commons/src/conditionals/validate.ts
2034
- var import_ajv = __toESM(require("ajv"));
2041
+ var import__ = __toESM(require("ajv/dist/2019"));
2035
2042
  var import_ajv_formats = __toESM(require("ajv-formats"));
2036
2043
  var import_date_fns = require("date-fns");
2037
2044
 
@@ -2245,9 +2252,11 @@ var isNonInteractiveFieldType = (field2) => {
2245
2252
  };
2246
2253
 
2247
2254
  // ../commons/src/conditionals/validate.ts
2248
- var ajv = new import_ajv.default({
2255
+ var ajv = new import__.default({
2249
2256
  $data: true,
2250
- allowUnionTypes: true
2257
+ allowUnionTypes: true,
2258
+ strict: false
2259
+ // Allow minContains and other newer features
2251
2260
  });
2252
2261
  (0, import_ajv_formats.default)(ajv);
2253
2262
  ajv.addKeyword({
@@ -2485,6 +2494,11 @@ function getValidatorsForField(fieldId, validations) {
2485
2494
  };
2486
2495
  }).filter((x) => x !== null);
2487
2496
  }
2497
+ function areCertificateConditionsMet(conditions, values) {
2498
+ return conditions.every((condition) => {
2499
+ return ajv.validate(condition.conditional, values);
2500
+ });
2501
+ }
2488
2502
 
2489
2503
  // ../commons/src/utils.ts
2490
2504
  function getOrThrow(x, message) {
@@ -3195,32 +3209,107 @@ function eventFn(fieldId) {
3195
3209
  var event = Object.assign(eventFn, {
3196
3210
  /**
3197
3211
  * Checks if the event contains a specific action type.
3212
+ * Can be used directly as a conditional or chained with additional methods.
3198
3213
  * @param action - The action type to check for.
3199
3214
  */
3200
- hasAction: (action) => defineConditional({
3201
- type: "object",
3202
- properties: {
3203
- $event: {
3215
+ hasAction: (action) => {
3216
+ const basicConditional = defineConditional({
3217
+ type: "object",
3218
+ properties: {
3219
+ $event: {
3220
+ type: "object",
3221
+ properties: {
3222
+ actions: {
3223
+ type: "array",
3224
+ contains: {
3225
+ type: "object",
3226
+ properties: {
3227
+ type: {
3228
+ const: action
3229
+ }
3230
+ },
3231
+ required: ["type"]
3232
+ }
3233
+ }
3234
+ },
3235
+ required: ["actions"]
3236
+ }
3237
+ },
3238
+ required: ["$event"]
3239
+ });
3240
+ const buildActionConstraints = (additionalFields) => {
3241
+ const actionProperties = {
3242
+ type: { const: action }
3243
+ };
3244
+ const requiredFields = ["type"];
3245
+ if (additionalFields) {
3246
+ Object.entries(additionalFields).forEach(([key, value]) => {
3247
+ actionProperties[key] = { const: value };
3248
+ requiredFields.push(key);
3249
+ });
3250
+ }
3251
+ return { actionProperties, requiredFields };
3252
+ };
3253
+ const createCountConditional = (countType, count, additionalFields) => {
3254
+ const { actionProperties, requiredFields } = buildActionConstraints(additionalFields);
3255
+ return defineConditional({
3204
3256
  type: "object",
3205
3257
  properties: {
3206
- actions: {
3207
- type: "array",
3208
- contains: {
3209
- type: "object",
3210
- properties: {
3211
- type: {
3212
- const: action
3213
- }
3214
- },
3215
- required: ["type"]
3216
- }
3258
+ $event: {
3259
+ type: "object",
3260
+ properties: {
3261
+ actions: {
3262
+ type: "array",
3263
+ contains: {
3264
+ type: "object",
3265
+ properties: actionProperties,
3266
+ required: requiredFields
3267
+ },
3268
+ [countType]: count
3269
+ }
3270
+ },
3271
+ required: ["actions"]
3217
3272
  }
3218
3273
  },
3219
- required: ["actions"]
3220
- }
3221
- },
3222
- required: ["$event"]
3223
- }),
3274
+ required: ["$event"]
3275
+ });
3276
+ };
3277
+ const withMinMax = (additionalFields) => {
3278
+ return {
3279
+ /**
3280
+ * Creates a conditional that checks if the event contains a specific action type
3281
+ * with a minimum count of occurrences.
3282
+ *
3283
+ * @param minCount - The minimum number of actions required.
3284
+ */
3285
+ minCount: (minCount) => createCountConditional("minContains", minCount, additionalFields),
3286
+ /**
3287
+ * Builds a conditional that sets a maximum count for the number of actions.
3288
+ * This is useful for limiting the number of actions of a specific type in a single event.
3289
+ */
3290
+ maxCount: (maxCount) => createCountConditional("maxContains", maxCount, additionalFields)
3291
+ };
3292
+ };
3293
+ const chainableMethods = {
3294
+ /**
3295
+ * Adds additional field constraints to the action matching.
3296
+ *
3297
+ * @param fields - Object containing additional fields to match on the action.
3298
+ */
3299
+ withFields: (fields) => withMinMax(fields),
3300
+ /**
3301
+ * Adds template ID constraint to the action matching.
3302
+ * This is a convenience method that adds actionDetails.templateId to the fields.
3303
+ *
3304
+ * @param id - The template ID to match against.
3305
+ */
3306
+ withTemplate: (id) => withMinMax({
3307
+ actionDetails: { templateId: id }
3308
+ }),
3309
+ ...withMinMax()
3310
+ };
3311
+ return { ...basicConditional, ...chainableMethods };
3312
+ },
3224
3313
  field(field2) {
3225
3314
  return {
3226
3315
  $event: field2
@@ -3305,7 +3394,9 @@ var EventMetadata = import_zod23.z.object({
3305
3394
  trackingId: import_zod23.z.string().describe(
3306
3395
  "System-generated tracking ID used by informants or registrars to look up the event."
3307
3396
  ),
3308
- flags: import_zod23.z.array(Flag)
3397
+ flags: import_zod23.z.array(Flag),
3398
+ copiesPrintedForTemplate: import_zod23.z.number().optional(),
3399
+ modifiedAt: import_zod23.z.string().optional()
3309
3400
  });
3310
3401
  var EventMetadataKeysArray = [
3311
3402
  "id",
@@ -3835,6 +3926,7 @@ var BaseActionInput = import_zod29.z.object({
3835
3926
  transactionId: import_zod29.z.string(),
3836
3927
  declaration: ActionUpdate.default({}),
3837
3928
  annotation: ActionUpdate.optional(),
3929
+ actionDetails: ActionDetails.optional(),
3838
3930
  originalActionId: UUID.optional(),
3839
3931
  // should not be part of base action.
3840
3932
  keepAssignment: import_zod29.z.boolean().optional()
@@ -3917,8 +4009,7 @@ var RequestCorrectionActionInput = BaseActionInput.merge(
3917
4009
  var RejectCorrectionActionInput = BaseActionInput.merge(
3918
4010
  import_zod29.z.object({
3919
4011
  requestId: import_zod29.z.string(),
3920
- type: import_zod29.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION),
3921
- reason: RejectionReason
4012
+ type: import_zod29.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
3922
4013
  })
3923
4014
  );
3924
4015
  var ApproveCorrectionActionInput = BaseActionInput.merge(
@@ -4285,7 +4376,8 @@ function getCurrentEventState(event2, config) {
4285
4376
  trackingId: event2.trackingId,
4286
4377
  updatedByUserRole: requestActionMetadata.createdByRole,
4287
4378
  dateOfEvent: resolveDateOfEvent(event2, declaration, config),
4288
- flags: getFlagsFromActions(event2.actions)
4379
+ flags: getFlagsFromActions(event2.actions),
4380
+ copiesPrintedForTemplate: event2.copiesPrintedForTemplate ?? 0
4289
4381
  });
4290
4382
  }
4291
4383
  function getCurrentEventStateWithDrafts({
@@ -6757,7 +6849,7 @@ function eventPayloadGenerator(rng) {
6757
6849
  requestId,
6758
6850
  keepAssignment: input.keepAssignment
6759
6851
  }),
6760
- reject: (eventId, requestId, input) => ({
6852
+ reject: (eventId, requestId, input = {}) => ({
6761
6853
  type: ActionType.REJECT_CORRECTION,
6762
6854
  transactionId: input.transactionId ?? getUUID(),
6763
6855
  declaration: {},
@@ -6768,8 +6860,7 @@ function eventPayloadGenerator(rng) {
6768
6860
  ),
6769
6861
  eventId,
6770
6862
  requestId,
6771
- keepAssignment: input.keepAssignment,
6772
- reason: input.reason ?? { message: "" }
6863
+ keepAssignment: input.keepAssignment
6773
6864
  })
6774
6865
  }
6775
6866
  }
@@ -6828,8 +6919,7 @@ function generateActionDocument({
6828
6919
  return {
6829
6920
  ...actionBase,
6830
6921
  requestId: getUUID(),
6831
- type: action,
6832
- reason: { message: "Correction rejection" }
6922
+ type: action
6833
6923
  };
6834
6924
  case ActionType.REGISTER:
6835
6925
  return {
@@ -6964,7 +7054,8 @@ var eventQueryDataGenerator = (overrides = {}, seed = 1) => {
6964
7054
  flags: [],
6965
7055
  legalStatuses: overrides.legalStatuses ?? {},
6966
7056
  declaration: overrides.declaration ?? generateRandomApplicant(rng),
6967
- trackingId: overrides.trackingId ?? generateTrackingId(rng)
7057
+ trackingId: overrides.trackingId ?? generateTrackingId(rng),
7058
+ copiesPrintedForTemplate: overrides.copiesPrintedForTemplate ?? 0
6968
7059
  };
6969
7060
  };
6970
7061
  var generateTranslationConfig = (message) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.1-rc.b849abb",
3
+ "version": "1.8.1-rc.bbbfede",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {