@opencrvs/toolkit 1.8.1-rc.25f3d5c → 1.8.1-rc.2d48701

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.
@@ -39,7 +39,6 @@ __export(events_exports, {
39
39
  ActionConfig: () => ActionConfig,
40
40
  ActionConfigBase: () => ActionConfigBase,
41
41
  ActionCreationMetadata: () => ActionCreationMetadata,
42
- ActionDetails: () => ActionDetails,
43
42
  ActionDocument: () => ActionDocument,
44
43
  ActionFormConfig: () => ActionFormConfig,
45
44
  ActionInput: () => ActionInput,
@@ -140,6 +139,7 @@ __export(events_exports, {
140
139
  PageConfig: () => PageConfig,
141
140
  PageTypes: () => PageTypes,
142
141
  PrintCertificateActionInput: () => PrintCertificateActionInput,
142
+ PrintContent: () => PrintContent,
143
143
  QueryExpression: () => QueryExpression,
144
144
  QueryInput: () => QueryInput,
145
145
  QueryType: () => QueryType,
@@ -198,6 +198,7 @@ __export(events_exports, {
198
198
  annotationActions: () => annotationActions,
199
199
  applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
200
200
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
201
+ areCertificateConditionsMet: () => areCertificateConditionsMet,
201
202
  areConditionsMet: () => areConditionsMet,
202
203
  compositeFieldTypes: () => compositeFieldTypes,
203
204
  createEmptyDraft: () => createEmptyDraft,
@@ -607,8 +608,8 @@ var UrbanAddressUpdateValue = AdminStructure.extend({
607
608
  zipCode: import_zod5.z.string().nullish()
608
609
  });
609
610
  var NameFieldValue = import_zod5.z.object({
610
- firstname: import_zod5.z.string(),
611
- surname: import_zod5.z.string(),
611
+ firstname: import_zod5.z.string().min(1),
612
+ surname: import_zod5.z.string().min(1),
612
613
  middlename: import_zod5.z.string().optional()
613
614
  });
614
615
  var NameFieldUpdateValue = import_zod5.z.object({
@@ -1223,7 +1224,8 @@ var CertificateConfig = import_zod11.z.object({
1223
1224
  delayed: import_zod11.z.number()
1224
1225
  }),
1225
1226
  svgUrl: import_zod11.z.string(),
1226
- fonts: import_zod11.z.record(FontFamily).optional()
1227
+ fonts: import_zod11.z.record(FontFamily).optional(),
1228
+ conditionals: import_zod11.z.array(ShowConditional).optional()
1227
1229
  });
1228
1230
  var CertificateTemplateConfig = CertificateConfig.extend({
1229
1231
  hash: import_zod11.z.string().optional(),
@@ -1341,7 +1343,7 @@ var SummaryConfig = import_zod14.z.object({
1341
1343
 
1342
1344
  // ../commons/src/events/AdvancedSearchConfig.ts
1343
1345
  var import_zod15 = require("zod");
1344
- var MatchType = import_zod15.z.enum(["fuzzy", "exact", "range"]);
1346
+ var MatchType = import_zod15.z.enum(["fuzzy", "exact", "range", "within"]);
1345
1347
  var BaseField3 = import_zod15.z.object({
1346
1348
  config: import_zod15.z.object({
1347
1349
  type: MatchType.describe("Determines the type of field")
@@ -1883,10 +1885,6 @@ var ActionStatus = {
1883
1885
  Accepted: "Accepted",
1884
1886
  Rejected: "Rejected"
1885
1887
  };
1886
- var ActionDetails = import_zod19.z.object({
1887
- templateId: import_zod19.z.string().optional(),
1888
- isImmediateCorrection: import_zod19.z.boolean().optional()
1889
- });
1890
1888
  var ActionBase = import_zod19.z.object({
1891
1889
  id: UUID,
1892
1890
  transactionId: import_zod19.z.string(),
@@ -1898,7 +1896,6 @@ var ActionBase = import_zod19.z.object({
1898
1896
  createdAtLocation: CreatedAtLocation,
1899
1897
  declaration: ActionUpdate,
1900
1898
  annotation: ActionUpdate.optional().nullable(),
1901
- actionDetails: ActionDetails.optional().nullable(),
1902
1899
  status: import_zod19.z.enum([
1903
1900
  ActionStatus.Requested,
1904
1901
  ActionStatus.Accepted,
@@ -1908,11 +1905,15 @@ var ActionBase = import_zod19.z.object({
1908
1905
  originalActionId: UUID.optional().nullable().describe(
1909
1906
  "Reference to the original action that was asynchronously rejected or accepted by 3rd party integration."
1910
1907
  )
1908
+ // 'content' field reserved for additional data
1909
+ // Each action can define its own content specifc to the action
1910
+ // See PrintCertificateAction
1911
1911
  });
1912
1912
  var AssignedAction = ActionBase.merge(
1913
1913
  import_zod19.z.object({
1914
1914
  type: import_zod19.z.literal(ActionType.ASSIGN),
1915
1915
  assignedTo: import_zod19.z.string()
1916
+ // TODO move into 'content' property
1916
1917
  })
1917
1918
  );
1918
1919
  var UnassignedAction = ActionBase.merge(
@@ -1924,6 +1925,7 @@ var RegisterAction = ActionBase.merge(
1924
1925
  import_zod19.z.object({
1925
1926
  type: import_zod19.z.literal(ActionType.REGISTER),
1926
1927
  registrationNumber: import_zod19.z.string().optional()
1928
+ // TODO move into 'content' property
1927
1929
  })
1928
1930
  );
1929
1931
  var DeclareAction = ActionBase.merge(
@@ -1944,6 +1946,7 @@ var RejectAction = ActionBase.merge(
1944
1946
  import_zod19.z.object({
1945
1947
  type: import_zod19.z.literal(ActionType.REJECT),
1946
1948
  reason: RejectionReason
1949
+ // TODO move into 'content' property
1947
1950
  })
1948
1951
  );
1949
1952
  var MarkAsDuplicateAction = ActionBase.merge(
@@ -1955,6 +1958,7 @@ var ArchiveAction = ActionBase.merge(
1955
1958
  import_zod19.z.object({
1956
1959
  type: import_zod19.z.literal(ActionType.ARCHIVE),
1957
1960
  reason: RejectionReason
1961
+ // TODO move into 'content' property
1958
1962
  })
1959
1963
  );
1960
1964
  var CreatedAction = ActionBase.merge(
@@ -1967,9 +1971,13 @@ var NotifiedAction = ActionBase.merge(
1967
1971
  type: import_zod19.z.literal(ActionType.NOTIFY)
1968
1972
  })
1969
1973
  );
1974
+ var PrintContent = import_zod19.z.object({
1975
+ templateId: import_zod19.z.string().optional()
1976
+ });
1970
1977
  var PrintCertificateAction = ActionBase.merge(
1971
1978
  import_zod19.z.object({
1972
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1979
+ type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE),
1980
+ content: PrintContent.optional().nullable()
1973
1981
  })
1974
1982
  );
1975
1983
  var RequestedCorrectionAction = ActionBase.merge(
@@ -1981,12 +1989,15 @@ var ApprovedCorrectionAction = ActionBase.merge(
1981
1989
  import_zod19.z.object({
1982
1990
  type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1983
1991
  requestId: import_zod19.z.string()
1992
+ // TODO move into 'content' property
1984
1993
  })
1985
1994
  );
1986
1995
  var RejectedCorrectionAction = ActionBase.merge(
1987
1996
  import_zod19.z.object({
1988
1997
  type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1989
- requestId: import_zod19.z.string()
1998
+ requestId: import_zod19.z.string(),
1999
+ // TODO move into 'content' property
2000
+ reason: RejectionReason
1990
2001
  })
1991
2002
  );
1992
2003
  var ReadAction = ActionBase.merge(
@@ -2036,7 +2047,7 @@ var ResolvedUser = import_zod19.z.object({
2036
2047
  });
2037
2048
 
2038
2049
  // ../commons/src/conditionals/validate.ts
2039
- var import_ajv = __toESM(require("ajv"));
2050
+ var import__ = __toESM(require("ajv/dist/2019"));
2040
2051
  var import_ajv_formats = __toESM(require("ajv-formats"));
2041
2052
  var import_date_fns = require("date-fns");
2042
2053
 
@@ -2250,9 +2261,11 @@ var isNonInteractiveFieldType = (field2) => {
2250
2261
  };
2251
2262
 
2252
2263
  // ../commons/src/conditionals/validate.ts
2253
- var ajv = new import_ajv.default({
2264
+ var ajv = new import__.default({
2254
2265
  $data: true,
2255
- allowUnionTypes: true
2266
+ allowUnionTypes: true,
2267
+ strict: false
2268
+ // Allow minContains and other newer features
2256
2269
  });
2257
2270
  (0, import_ajv_formats.default)(ajv);
2258
2271
  ajv.addKeyword({
@@ -2490,6 +2503,11 @@ function getValidatorsForField(fieldId, validations) {
2490
2503
  };
2491
2504
  }).filter((x) => x !== null);
2492
2505
  }
2506
+ function areCertificateConditionsMet(conditions, values) {
2507
+ return conditions.every((condition) => {
2508
+ return ajv.validate(condition.conditional, values);
2509
+ });
2510
+ }
2493
2511
 
2494
2512
  // ../commons/src/utils.ts
2495
2513
  function getOrThrow(x, message) {
@@ -3180,6 +3198,19 @@ function createSearchConfig(baseField) {
3180
3198
  fuzzy: () => ({
3181
3199
  ...baseField,
3182
3200
  config: { type: "fuzzy" }
3201
+ }),
3202
+ /**
3203
+ * Creates a configuration for matching locations and the child locations
3204
+ * @returns An object containing the field ID and a configuration object with a type of 'within'.
3205
+ * @example field('createdAtLocation').within()
3206
+ * // {
3207
+ * // ...
3208
+ * // config: { type: 'within' }
3209
+ * // }
3210
+ */
3211
+ within: () => ({
3212
+ ...baseField,
3213
+ config: { type: "within" }
3183
3214
  })
3184
3215
  };
3185
3216
  }
@@ -3200,32 +3231,107 @@ function eventFn(fieldId) {
3200
3231
  var event = Object.assign(eventFn, {
3201
3232
  /**
3202
3233
  * Checks if the event contains a specific action type.
3234
+ * Can be used directly as a conditional or chained with additional methods.
3203
3235
  * @param action - The action type to check for.
3204
3236
  */
3205
- hasAction: (action) => defineConditional({
3206
- type: "object",
3207
- properties: {
3208
- $event: {
3237
+ hasAction: (action) => {
3238
+ const basicConditional = defineConditional({
3239
+ type: "object",
3240
+ properties: {
3241
+ $event: {
3242
+ type: "object",
3243
+ properties: {
3244
+ actions: {
3245
+ type: "array",
3246
+ contains: {
3247
+ type: "object",
3248
+ properties: {
3249
+ type: {
3250
+ const: action
3251
+ }
3252
+ },
3253
+ required: ["type"]
3254
+ }
3255
+ }
3256
+ },
3257
+ required: ["actions"]
3258
+ }
3259
+ },
3260
+ required: ["$event"]
3261
+ });
3262
+ const buildActionConstraints = (additionalFields) => {
3263
+ const actionProperties = {
3264
+ type: { const: action }
3265
+ };
3266
+ const requiredFields = ["type"];
3267
+ if (additionalFields) {
3268
+ Object.entries(additionalFields).forEach(([key, value]) => {
3269
+ actionProperties[key] = { const: value };
3270
+ requiredFields.push(key);
3271
+ });
3272
+ }
3273
+ return { actionProperties, requiredFields };
3274
+ };
3275
+ const createCountConditional = (countType, count, additionalFields) => {
3276
+ const { actionProperties, requiredFields } = buildActionConstraints(additionalFields);
3277
+ return defineConditional({
3209
3278
  type: "object",
3210
3279
  properties: {
3211
- actions: {
3212
- type: "array",
3213
- contains: {
3214
- type: "object",
3215
- properties: {
3216
- type: {
3217
- const: action
3218
- }
3219
- },
3220
- required: ["type"]
3221
- }
3280
+ $event: {
3281
+ type: "object",
3282
+ properties: {
3283
+ actions: {
3284
+ type: "array",
3285
+ contains: {
3286
+ type: "object",
3287
+ properties: actionProperties,
3288
+ required: requiredFields
3289
+ },
3290
+ [countType]: count
3291
+ }
3292
+ },
3293
+ required: ["actions"]
3222
3294
  }
3223
3295
  },
3224
- required: ["actions"]
3225
- }
3226
- },
3227
- required: ["$event"]
3228
- }),
3296
+ required: ["$event"]
3297
+ });
3298
+ };
3299
+ const withMinMax = (additionalFields) => {
3300
+ return {
3301
+ /**
3302
+ * Creates a conditional that checks if the event contains a specific action type
3303
+ * with a minimum count of occurrences.
3304
+ *
3305
+ * @param minCount - The minimum number of actions required.
3306
+ */
3307
+ minCount: (minCount) => createCountConditional("minContains", minCount, additionalFields),
3308
+ /**
3309
+ * Builds a conditional that sets a maximum count for the number of actions.
3310
+ * This is useful for limiting the number of actions of a specific type in a single event.
3311
+ */
3312
+ maxCount: (maxCount) => createCountConditional("maxContains", maxCount, additionalFields)
3313
+ };
3314
+ };
3315
+ const chainableMethods = {
3316
+ /**
3317
+ * Adds additional field constraints to the action matching.
3318
+ *
3319
+ * @param fields - Object containing additional fields to match on the action.
3320
+ */
3321
+ withFields: (fields) => withMinMax(fields),
3322
+ /**
3323
+ * Adds template ID constraint to the action matching.
3324
+ * This is a convenience method that adds content.templateId to the fields.
3325
+ *
3326
+ * @param id - The template ID to match against.
3327
+ */
3328
+ withTemplate: (id) => withMinMax({
3329
+ content: { templateId: id }
3330
+ }),
3331
+ ...withMinMax()
3332
+ };
3333
+ return { ...basicConditional, ...chainableMethods };
3334
+ },
3229
3335
  field(field2) {
3230
3336
  return {
3231
3337
  $event: field2
@@ -3529,6 +3635,9 @@ var QueryExpression = import_zod25.z.object({
3529
3635
  createdAt: import_zod25.z.optional(DateCondition),
3530
3636
  updatedAt: import_zod25.z.optional(DateCondition),
3531
3637
  "legalStatuses.REGISTERED.acceptedAt": import_zod25.z.optional(DateCondition),
3638
+ "legalStatuses.DECLARED.createdAtLocation": import_zod25.z.optional(
3639
+ import_zod25.z.union([Within, Exact])
3640
+ ),
3532
3641
  "legalStatuses.REGISTERED.createdAtLocation": import_zod25.z.optional(
3533
3642
  import_zod25.z.union([Within, Exact])
3534
3643
  ),
@@ -3840,7 +3949,6 @@ var BaseActionInput = import_zod29.z.object({
3840
3949
  transactionId: import_zod29.z.string(),
3841
3950
  declaration: ActionUpdate.default({}),
3842
3951
  annotation: ActionUpdate.optional(),
3843
- actionDetails: ActionDetails.optional(),
3844
3952
  originalActionId: UUID.optional(),
3845
3953
  // should not be part of base action.
3846
3954
  keepAssignment: import_zod29.z.boolean().optional()
@@ -3883,7 +3991,8 @@ var DeclareActionInput = BaseActionInput.merge(
3883
3991
  );
3884
3992
  var PrintCertificateActionInput = BaseActionInput.merge(
3885
3993
  import_zod29.z.object({
3886
- type: import_zod29.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
3994
+ type: import_zod29.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE),
3995
+ content: PrintContent.optional()
3887
3996
  })
3888
3997
  );
3889
3998
  var RejectDeclarationActionInput = BaseActionInput.merge(
@@ -3923,7 +4032,8 @@ var RequestCorrectionActionInput = BaseActionInput.merge(
3923
4032
  var RejectCorrectionActionInput = BaseActionInput.merge(
3924
4033
  import_zod29.z.object({
3925
4034
  requestId: import_zod29.z.string(),
3926
- type: import_zod29.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
4035
+ type: import_zod29.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION),
4036
+ reason: RejectionReason
3927
4037
  })
3928
4038
  );
3929
4039
  var ApproveCorrectionActionInput = BaseActionInput.merge(
@@ -6762,7 +6872,7 @@ function eventPayloadGenerator(rng) {
6762
6872
  requestId,
6763
6873
  keepAssignment: input.keepAssignment
6764
6874
  }),
6765
- reject: (eventId, requestId, input = {}) => ({
6875
+ reject: (eventId, requestId, input) => ({
6766
6876
  type: ActionType.REJECT_CORRECTION,
6767
6877
  transactionId: input.transactionId ?? getUUID(),
6768
6878
  declaration: {},
@@ -6773,7 +6883,8 @@ function eventPayloadGenerator(rng) {
6773
6883
  ),
6774
6884
  eventId,
6775
6885
  requestId,
6776
- keepAssignment: input.keepAssignment
6886
+ keepAssignment: input.keepAssignment,
6887
+ reason: input.reason ?? { message: "" }
6777
6888
  })
6778
6889
  }
6779
6890
  }
@@ -6823,7 +6934,11 @@ function generateActionDocument({
6823
6934
  case ActionType.NOTIFY:
6824
6935
  return { ...actionBase, type: action };
6825
6936
  case ActionType.PRINT_CERTIFICATE:
6826
- return { ...actionBase, type: action };
6937
+ return {
6938
+ ...actionBase,
6939
+ type: action,
6940
+ content: defaults.content
6941
+ };
6827
6942
  case ActionType.REQUEST_CORRECTION:
6828
6943
  return { ...actionBase, type: action };
6829
6944
  case ActionType.APPROVE_CORRECTION:
@@ -6832,7 +6947,8 @@ function generateActionDocument({
6832
6947
  return {
6833
6948
  ...actionBase,
6834
6949
  requestId: getUUID(),
6835
- type: action
6950
+ type: action,
6951
+ reason: { message: "Correction rejection" }
6836
6952
  };
6837
6953
  case ActionType.REGISTER:
6838
6954
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.8.1-rc.25f3d5c",
3
+ "version": "1.8.1-rc.2d48701",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {