@opencrvs/toolkit 1.8.0-rc.f7e8fb5 → 1.8.0-rc.f82791e

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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +10779 -10294
  3. package/dist/commons/conditionals/conditionals.d.ts +31 -5
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +39 -17
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +85746 -1981
  8. package/dist/commons/events/ActionDocument.d.ts +9850 -363
  9. package/dist/commons/events/ActionInput.d.ts +5361 -496
  10. package/dist/commons/events/ActionType.d.ts +26 -11
  11. package/dist/commons/events/AdvancedSearchConfig.d.ts +371 -25
  12. package/dist/commons/events/CompositeFieldValue.d.ts +155 -2
  13. package/dist/commons/events/Conditional.d.ts +21 -5
  14. package/dist/commons/events/Draft.d.ts +374 -56
  15. package/dist/commons/events/EventConfig.d.ts +40845 -1776
  16. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  17. package/dist/commons/events/EventDocument.d.ts +3667 -499
  18. package/dist/commons/events/EventIndex.d.ts +921 -7
  19. package/dist/commons/events/EventInput.d.ts +13 -0
  20. package/dist/commons/events/EventMetadata.d.ts +16 -3
  21. package/dist/commons/events/FieldConfig.d.ts +3954 -757
  22. package/dist/commons/events/FieldType.d.ts +2 -2
  23. package/dist/commons/events/FieldTypeMapping.d.ts +154 -3
  24. package/dist/commons/events/FieldValue.d.ts +77 -3
  25. package/dist/commons/events/FormConfig.d.ts +38982 -69
  26. package/dist/commons/events/PageConfig.d.ts +9803 -0
  27. package/dist/commons/events/SummaryConfig.d.ts +81 -42
  28. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  29. package/dist/commons/events/User.d.ts +5 -0
  30. package/dist/commons/events/WorkqueueConfig.d.ts +44 -20
  31. package/dist/commons/events/defineConfig.d.ts +6749 -224
  32. package/dist/commons/events/event.d.ts +25 -0
  33. package/dist/commons/events/field.d.ts +68 -0
  34. package/dist/commons/events/index.d.ts +5 -1
  35. package/dist/commons/events/scopes.d.ts +26 -0
  36. package/dist/commons/events/test.utils.d.ts +127 -237
  37. package/dist/commons/events/utils.d.ts +3462 -109
  38. package/dist/commons/events/utils.test.d.ts +2 -0
  39. package/dist/conditionals/index.js +196 -108
  40. package/dist/events/index.js +2131 -1189
  41. package/package.json +3 -2
@@ -30,30 +30,50 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/events/index.ts
31
31
  var events_exports = {};
32
32
  __export(events_exports, {
33
+ ACTION_ALLOWED_SCOPES: () => ACTION_ALLOWED_SCOPES,
34
+ Action: () => Action,
33
35
  ActionBase: () => ActionBase,
34
36
  ActionConditional: () => ActionConditional,
35
37
  ActionConfig: () => ActionConfig,
36
38
  ActionConfigBase: () => ActionConfigBase,
37
39
  ActionDocument: () => ActionDocument,
40
+ ActionFormConfig: () => ActionFormConfig,
38
41
  ActionInput: () => ActionInput,
42
+ ActionStatus: () => ActionStatus,
39
43
  ActionType: () => ActionType,
44
+ ActionTypes: () => ActionTypes,
40
45
  ActionUpdate: () => ActionUpdate,
41
46
  AddressFieldUpdateValue: () => AddressFieldUpdateValue,
42
47
  AddressFieldValue: () => AddressFieldValue,
48
+ AddressType: () => AddressType,
43
49
  AdministrativeAreas: () => AdministrativeAreas,
44
50
  AdvancedSearchConfig: () => AdvancedSearchConfig,
45
51
  ApproveCorrectionActionInput: () => ApproveCorrectionActionInput,
46
52
  ArchiveActionInput: () => ArchiveActionInput,
53
+ AssignActionInput: () => AssignActionInput,
54
+ AsyncRejectActionDocument: () => AsyncRejectActionDocument,
47
55
  BaseActionInput: () => BaseActionInput,
56
+ CONFIG_GET_ALLOWED_SCOPES: () => CONFIG_GET_ALLOWED_SCOPES,
57
+ CONFIG_SEARCH_ALLOWED_SCOPES: () => CONFIG_SEARCH_ALLOWED_SCOPES,
48
58
  CertificateConfig: () => CertificateConfig,
49
59
  CertificateTemplateConfig: () => CertificateTemplateConfig,
50
60
  CheckboxFieldValue: () => CheckboxFieldValue,
51
61
  Clause: () => Clause,
52
62
  Conditional: () => Conditional,
53
63
  ConditionalType: () => ConditionalType,
64
+ ConfirmableActions: () => ConfirmableActions,
65
+ DataEntry: () => DataEntry,
66
+ DataFieldValue: () => DataFieldValue,
54
67
  DateValue: () => DateValue,
68
+ DeclarationActionConfig: () => DeclarationActionConfig,
69
+ DeclarationActions: () => DeclarationActions,
70
+ DeclarationFormConfig: () => DeclarationFormConfig,
71
+ DeclarationReviewConfig: () => DeclarationReviewConfig,
72
+ DeclarationUpdateActions: () => DeclarationUpdateActions,
55
73
  DeclareActionInput: () => DeclareActionInput,
56
74
  DeduplicationConfig: () => DeduplicationConfig,
75
+ DeleteActionInput: () => DeleteActionInput,
76
+ DisplayOnReviewConditional: () => DisplayOnReviewConditional,
57
77
  Draft: () => Draft,
58
78
  DraftInput: () => DraftInput,
59
79
  EmailField: () => EmailField,
@@ -61,13 +81,17 @@ __export(events_exports, {
61
81
  EnableConditional: () => EnableConditional,
62
82
  EventConfig: () => EventConfig,
63
83
  EventDocument: () => EventDocument,
84
+ EventFieldConfigSchema: () => EventFieldConfigSchema,
85
+ EventFieldId: () => EventFieldId,
64
86
  EventIndex: () => EventIndex,
65
87
  EventInput: () => EventInput,
66
88
  EventMetadata: () => EventMetadata,
67
89
  EventSearchIndex: () => EventSearchIndex,
68
90
  EventStatus: () => EventStatus,
69
91
  EventStatuses: () => EventStatuses,
92
+ FieldConditional: () => FieldConditional,
70
93
  FieldConfig: () => FieldConfig,
94
+ FieldConfigSchema: () => FieldConfigSchema,
71
95
  FieldType: () => FieldType,
72
96
  FieldUpdateValue: () => FieldUpdateValue,
73
97
  FieldValue: () => FieldValue,
@@ -75,40 +99,67 @@ __export(events_exports, {
75
99
  FileFieldValueWithOption: () => FileFieldValueWithOption,
76
100
  FileFieldWithOptionValue: () => FileFieldWithOptionValue,
77
101
  FormConfig: () => FormConfig,
78
- FormPage: () => FormPage,
102
+ FormPageConfig: () => FormPageConfig,
103
+ GenericAddressUpdateValue: () => GenericAddressUpdateValue,
104
+ GenericAddressValue: () => GenericAddressValue,
79
105
  GeographicalArea: () => GeographicalArea,
106
+ ImageMimeType: () => ImageMimeType,
80
107
  LanguageConfig: () => LanguageConfig,
81
108
  MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
109
+ MatchType: () => MatchType,
110
+ MimeType: () => MimeType,
111
+ NonEmptyTextValue: () => NonEmptyTextValue,
82
112
  NotifyActionInput: () => NotifyActionInput,
83
113
  NumberFieldValue: () => NumberFieldValue,
114
+ PageConfig: () => PageConfig,
115
+ PageTypes: () => PageTypes,
84
116
  PrintCertificateActionInput: () => PrintCertificateActionInput,
117
+ QueryInput: () => QueryInput,
118
+ QueryType: () => QueryType,
119
+ ReadActionInput: () => ReadActionInput,
120
+ RegisterAction: () => RegisterAction,
85
121
  RegisterActionInput: () => RegisterActionInput,
86
122
  RejectCorrectionActionInput: () => RejectCorrectionActionInput,
87
123
  RejectDeclarationActionInput: () => RejectDeclarationActionInput,
88
124
  RequestCorrectionActionInput: () => RequestCorrectionActionInput,
89
- RequiredTextValue: () => RequiredTextValue,
90
125
  ResolvedUser: () => ResolvedUser,
91
126
  RuralAddressUpdateValue: () => RuralAddressUpdateValue,
92
127
  RuralAddressValue: () => RuralAddressValue,
128
+ SearchField: () => SearchField,
129
+ SelectOption: () => SelectOption,
93
130
  ShowConditional: () => ShowConditional,
94
131
  SummaryConfig: () => SummaryConfig,
95
132
  TextValue: () => TextValue,
96
133
  TranslationConfig: () => TranslationConfig,
134
+ UnassignActionInput: () => UnassignActionInput,
97
135
  UrbanAddressUpdateValue: () => UrbanAddressUpdateValue,
98
136
  UrbanAddressValue: () => UrbanAddressValue,
99
137
  ValidateActionInput: () => ValidateActionInput,
138
+ VerificationActionConfig: () => VerificationActionConfig,
139
+ VerificationPageConfig: () => VerificationPageConfig,
100
140
  WorkqueueConfig: () => WorkqueueConfig,
141
+ ZodDate: () => ZodDate,
101
142
  alwaysTrue: () => alwaysTrue,
102
143
  and: () => and,
144
+ annotationActions: () => annotationActions,
103
145
  applyDraftsToEventIndex: () => applyDraftsToEventIndex,
146
+ areConditionsMet: () => areConditionsMet,
104
147
  compositeFieldTypes: () => compositeFieldTypes,
105
148
  createEmptyDraft: () => createEmptyDraft,
149
+ createEventConditionals: () => createEventConditionals,
150
+ createFieldConditionals: () => createFieldConditionals,
106
151
  createValidationSchema: () => createValidationSchema,
107
152
  deepDropNulls: () => deepDropNulls,
153
+ deepMerge: () => deepMerge,
154
+ defineActionForm: () => defineActionForm,
108
155
  defineConditional: () => defineConditional,
109
156
  defineConfig: () => defineConfig,
110
- defineForm: () => defineForm,
157
+ defineDeclarationForm: () => defineDeclarationForm,
158
+ defineFormConditional: () => defineFormConditional,
111
159
  defineFormPage: () => defineFormPage,
160
+ definePage: () => definePage,
161
+ defineWorkqueue: () => defineWorkqueue,
162
+ errorMessages: () => errorMessages,
112
163
  event: () => event,
113
164
  eventMetadataLabelMap: () => eventMetadataLabelMap,
114
165
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -116,38 +167,46 @@ __export(events_exports, {
116
167
  eventStatuses: () => eventStatuses,
117
168
  field: () => field,
118
169
  fieldTypes: () => fieldTypes,
119
- findActiveActionFields: () => findActiveActionFields,
120
- findActiveActionForm: () => findActiveActionForm,
121
- findActiveActionFormFields: () => findActiveActionFormFields,
122
- findActiveActionFormPages: () => findActiveActionFormPages,
170
+ filterUnallowedActions: () => filterUnallowedActions,
123
171
  findActiveDrafts: () => findActiveDrafts,
124
- findInputPageFields: () => findInputPageFields,
125
- findPageFields: () => findPageFields,
172
+ findAllFields: () => findAllFields,
173
+ findLastAssignmentAction: () => findLastAssignmentAction,
174
+ findRecordActionPages: () => findRecordActionPages,
175
+ generateActionAnnotationInput: () => generateActionAnnotationInput,
176
+ generateActionDeclarationInput: () => generateActionDeclarationInput,
126
177
  generateActionDocument: () => generateActionDocument,
127
- generateActionInput: () => generateActionInput,
128
178
  generateEventDocument: () => generateEventDocument,
129
179
  generateEventDraftDocument: () => generateEventDraftDocument,
130
180
  generateTransactionId: () => generateTransactionId,
131
- getActiveActionFields: () => getActiveActionFields,
132
- getActiveActionFormPages: () => getActiveActionFormPages,
133
- getAllFields: () => getAllFields,
134
- getAllPages: () => getAllPages,
181
+ generateTranslationConfig: () => generateTranslationConfig,
182
+ getAcceptedActions: () => getAcceptedActions,
183
+ getActionAnnotation: () => getActionAnnotation,
184
+ getActionAnnotationFields: () => getActionAnnotationFields,
185
+ getActionReview: () => getActionReview,
186
+ getActionReviewFields: () => getActionReviewFields,
187
+ getActionVerificationPageIds: () => getActionVerificationPageIds,
188
+ getAnnotationFromDrafts: () => getAnnotationFromDrafts,
189
+ getAssignedUserFromActions: () => getAssignedUserFromActions,
135
190
  getCurrentEventState: () => getCurrentEventState,
136
191
  getCurrentEventStateWithDrafts: () => getCurrentEventStateWithDrafts,
137
- getEventConfiguration: () => getEventConfiguration,
138
- getFieldValidationErrors: () => getFieldValidationErrors,
139
- getFormFields: () => getFormFields,
140
- getMetadataForAction: () => getMetadataForAction,
192
+ getDeclaration: () => getDeclaration,
193
+ getDeclarationFields: () => getDeclarationFields,
194
+ getDeclarationPages: () => getDeclarationPages,
195
+ getVisibleVerificationPageIds: () => getVisibleVerificationPageIds,
196
+ hasAnyOfScopes: () => hasAnyOfScopes,
141
197
  isAddressFieldType: () => isAddressFieldType,
142
198
  isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
143
199
  isBulletListFieldType: () => isBulletListFieldType,
144
200
  isCheckboxFieldType: () => isCheckboxFieldType,
201
+ isConditionMet: () => isConditionMet,
145
202
  isCountryFieldType: () => isCountryFieldType,
203
+ isDataFieldType: () => isDataFieldType,
146
204
  isDateFieldType: () => isDateFieldType,
147
205
  isDividerFieldType: () => isDividerFieldType,
148
206
  isEmailFieldType: () => isEmailFieldType,
149
207
  isFacilityFieldType: () => isFacilityFieldType,
150
208
  isFieldConfigDefaultValue: () => isFieldConfigDefaultValue,
209
+ isFieldDisplayedOnReview: () => isFieldDisplayedOnReview,
151
210
  isFieldEnabled: () => isFieldEnabled,
152
211
  isFieldValue: () => isFieldValue,
153
212
  isFieldValueWithoutTemplates: () => isFieldValueWithoutTemplates,
@@ -158,6 +217,7 @@ __export(events_exports, {
158
217
  isNumberFieldType: () => isNumberFieldType,
159
218
  isOfficeFieldType: () => isOfficeFieldType,
160
219
  isPageHeaderFieldType: () => isPageHeaderFieldType,
220
+ isPageVisible: () => isPageVisible,
161
221
  isParagraphFieldType: () => isParagraphFieldType,
162
222
  isRadioGroupFieldType: () => isRadioGroupFieldType,
163
223
  isSelectFieldType: () => isSelectFieldType,
@@ -166,49 +226,72 @@ __export(events_exports, {
166
226
  isTextAreaFieldType: () => isTextAreaFieldType,
167
227
  isTextFieldType: () => isTextFieldType,
168
228
  isUndeclaredDraft: () => isUndeclaredDraft,
229
+ isVerificationPage: () => isVerificationPage,
230
+ isWriteAction: () => isWriteAction,
231
+ mapFieldTypeToEmptyValue: () => mapFieldTypeToEmptyValue,
169
232
  mapFieldTypeToMockValue: () => mapFieldTypeToMockValue,
170
233
  mapFieldTypeToZod: () => mapFieldTypeToZod,
234
+ never: () => never,
171
235
  not: () => not,
236
+ omitHiddenAnnotationFields: () => omitHiddenAnnotationFields,
237
+ omitHiddenFields: () => omitHiddenFields,
238
+ omitHiddenPaginatedFields: () => omitHiddenPaginatedFields,
172
239
  or: () => or,
173
- resolveLabelsFromKnownFields: () => resolveLabelsFromKnownFields,
174
- stripHiddenFields: () => stripHiddenFields,
240
+ runFieldValidations: () => runFieldValidations,
175
241
  user: () => user,
176
242
  validate: () => validate,
177
243
  validateFieldInput: () => validateFieldInput,
178
- validateWorkqueueConfig: () => validateWorkqueueConfig
244
+ writeActions: () => writeActions
179
245
  });
180
246
  module.exports = __toCommonJS(events_exports);
181
247
 
182
248
  // ../commons/src/events/ActionConfig.ts
183
- var import_zod7 = require("zod");
249
+ var import_zod9 = require("zod");
184
250
 
185
251
  // ../commons/src/events/Conditional.ts
186
252
  var import_zod = require("zod");
187
- function Conditional() {
188
- return import_zod.z.custom((val) => typeof val === "object" && val !== null);
189
- }
253
+ var Conditional = import_zod.z.custom(
254
+ (val) => typeof val === "object" && val !== null
255
+ );
190
256
  var ConditionalType = {
191
- /** When 'SHOW' conditional is defined, the action is shown to the user only if the condition is met */
192
257
  SHOW: "SHOW",
193
- /** If 'ENABLE' conditional is defined, the action is enabled only if the condition is met */
194
- ENABLE: "ENABLE"
258
+ ENABLE: "ENABLE",
259
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
195
260
  };
196
261
  var ShowConditional = import_zod.z.object({
197
262
  type: import_zod.z.literal(ConditionalType.SHOW),
198
- conditional: Conditional()
199
- });
263
+ conditional: Conditional
264
+ }).describe(
265
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
266
+ );
200
267
  var EnableConditional = import_zod.z.object({
201
268
  type: import_zod.z.literal(ConditionalType.ENABLE),
202
- conditional: Conditional()
203
- });
269
+ conditional: Conditional
270
+ }).describe(
271
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
272
+ );
204
273
  var ActionConditional = import_zod.z.discriminatedUnion("type", [
205
274
  // Action can be shown / hidden
206
275
  ShowConditional,
207
276
  // Action can be shown to the user in the list but as disabled
208
277
  EnableConditional
209
278
  ]);
279
+ var DisplayOnReviewConditional = import_zod.z.object({
280
+ type: import_zod.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
281
+ conditional: Conditional
282
+ }).describe(
283
+ "If 'DISPLAY_ON_REVIEW' conditional is defined, the component is shown on the review page only if both the 'DISPLAY_ON_REVIEW' and 'SHOW' conditions are met. This should only be used for fields within declaration forms, as they are the only ones with review pages."
284
+ );
285
+ var FieldConditional = import_zod.z.discriminatedUnion("type", [
286
+ // Field input can be shown / hidden
287
+ ShowConditional,
288
+ // Field input can be shown to the user but as disabled
289
+ EnableConditional,
290
+ // Field output can be shown / hidden on the review page
291
+ DisplayOnReviewConditional
292
+ ]);
210
293
 
211
- // ../commons/src/events/FormConfig.ts
294
+ // ../commons/src/events/PageConfig.ts
212
295
  var import_zod6 = require("zod");
213
296
 
214
297
  // ../commons/src/events/FieldConfig.ts
@@ -239,7 +322,6 @@ var FieldType = {
239
322
  RADIO_GROUP: "RADIO_GROUP",
240
323
  FILE: "FILE",
241
324
  FILE_WITH_OPTIONS: "FILE_WITH_OPTIONS",
242
- HIDDEN: "HIDDEN",
243
325
  BULLET_LIST: "BULLET_LIST",
244
326
  CHECKBOX: "CHECKBOX",
245
327
  SELECT: "SELECT",
@@ -249,7 +331,8 @@ var FieldType = {
249
331
  ADMINISTRATIVE_AREA: "ADMINISTRATIVE_AREA",
250
332
  FACILITY: "FACILITY",
251
333
  OFFICE: "OFFICE",
252
- SIGNATURE: "SIGNATURE"
334
+ SIGNATURE: "SIGNATURE",
335
+ DATA: "DATA"
253
336
  };
254
337
  var fieldTypes = Object.values(FieldType);
255
338
  var compositeFieldTypes = [
@@ -267,6 +350,10 @@ var GeographicalArea = {
267
350
  URBAN: "URBAN",
268
351
  RURAL: "RURAL"
269
352
  };
353
+ var AddressType = {
354
+ DOMESTIC: "DOMESTIC",
355
+ INTERNATIONAL: "INTERNATIONAL"
356
+ };
270
357
  var FileFieldValue = import_zod3.z.object({
271
358
  filename: import_zod3.z.string(),
272
359
  originalFilename: import_zod3.z.string(),
@@ -274,6 +361,7 @@ var FileFieldValue = import_zod3.z.object({
274
361
  });
275
362
  var AdminStructure = import_zod3.z.object({
276
363
  country: import_zod3.z.string(),
364
+ addressType: import_zod3.z.literal(AddressType.DOMESTIC),
277
365
  province: import_zod3.z.string(),
278
366
  district: import_zod3.z.string()
279
367
  });
@@ -301,14 +389,33 @@ var RuralAddressUpdateValue = AdminStructure.extend({
301
389
  urbanOrRural: import_zod3.z.literal(GeographicalArea.RURAL),
302
390
  village: import_zod3.z.string().nullish()
303
391
  });
304
- var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
305
- UrbanAddressValue,
306
- RuralAddressValue
307
- ]);
392
+ var GenericAddressValue = import_zod3.z.object({
393
+ country: import_zod3.z.string(),
394
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
395
+ state: import_zod3.z.string(),
396
+ district2: import_zod3.z.string(),
397
+ cityOrTown: import_zod3.z.string().optional(),
398
+ addressLine1: import_zod3.z.string().optional(),
399
+ addressLine2: import_zod3.z.string().optional(),
400
+ addressLine3: import_zod3.z.string().optional(),
401
+ postcodeOrZip: import_zod3.z.string().optional()
402
+ });
403
+ var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [UrbanAddressValue, RuralAddressValue]).or(GenericAddressValue);
404
+ var GenericAddressUpdateValue = import_zod3.z.object({
405
+ country: import_zod3.z.string(),
406
+ addressType: import_zod3.z.literal(AddressType.INTERNATIONAL),
407
+ state: import_zod3.z.string(),
408
+ district2: import_zod3.z.string(),
409
+ cityOrTown: import_zod3.z.string().nullish(),
410
+ addressLine1: import_zod3.z.string().nullish(),
411
+ addressLine2: import_zod3.z.string().nullish(),
412
+ addressLine3: import_zod3.z.string().nullish(),
413
+ postcodeOrZip: import_zod3.z.string().nullish()
414
+ });
308
415
  var AddressFieldUpdateValue = import_zod3.z.discriminatedUnion("urbanOrRural", [
309
416
  UrbanAddressUpdateValue,
310
417
  RuralAddressUpdateValue
311
- ]);
418
+ ]).or(GenericAddressUpdateValue);
312
419
  var FileFieldValueWithOption = import_zod3.z.object({
313
420
  filename: import_zod3.z.string(),
314
421
  originalFilename: import_zod3.z.string(),
@@ -319,11 +426,12 @@ var FileFieldWithOptionValue = import_zod3.z.array(FileFieldValueWithOption);
319
426
 
320
427
  // ../commons/src/events/FieldValue.ts
321
428
  var TextValue = import_zod4.z.string();
322
- var RequiredTextValue = TextValue.min(1);
429
+ var NonEmptyTextValue = TextValue.min(1);
323
430
  var DateValue = import_zod4.z.string().date().describe("Date in the format YYYY-MM-DD");
324
431
  var EmailValue = import_zod4.z.string().email();
325
432
  var CheckboxFieldValue = import_zod4.z.boolean();
326
433
  var NumberFieldValue = import_zod4.z.number();
434
+ var DataFieldValue = import_zod4.z.undefined();
327
435
  var FieldValue = import_zod4.z.union([
328
436
  TextValue,
329
437
  DateValue,
@@ -332,7 +440,9 @@ var FieldValue = import_zod4.z.union([
332
440
  FileFieldValue,
333
441
  FileFieldWithOptionValue,
334
442
  UrbanAddressValue,
335
- RuralAddressValue
443
+ RuralAddressValue,
444
+ DataFieldValue,
445
+ GenericAddressValue
336
446
  ]);
337
447
  var FieldUpdateValue = import_zod4.z.union([
338
448
  TextValue,
@@ -342,40 +452,35 @@ var FieldUpdateValue = import_zod4.z.union([
342
452
  FileFieldValue,
343
453
  FileFieldWithOptionValue,
344
454
  UrbanAddressUpdateValue,
345
- RuralAddressUpdateValue
455
+ RuralAddressUpdateValue,
456
+ DataFieldValue,
457
+ GenericAddressUpdateValue
346
458
  ]);
347
459
 
348
460
  // ../commons/src/events/FieldConfig.ts
349
461
  var FieldId = import_zod5.z.string();
350
- var DependencyExpression = import_zod5.z.object({
351
- dependsOn: import_zod5.z.array(FieldId).default([]),
352
- expression: import_zod5.z.string()
353
- });
462
+ var ParentReference = import_zod5.z.object({
463
+ _fieldId: FieldId.optional()
464
+ }).optional();
354
465
  var BaseField = import_zod5.z.object({
355
466
  id: FieldId,
356
467
  defaultValue: import_zod5.z.union([
357
- // These are the currently supported default values types
358
- import_zod5.z.union([
359
- TextValue,
360
- RequiredTextValue,
361
- DateValue,
362
- NumberFieldValue,
363
- CheckboxFieldValue
364
- ]),
365
- DependencyExpression
468
+ TextValue,
469
+ NonEmptyTextValue,
470
+ DateValue,
471
+ NumberFieldValue,
472
+ CheckboxFieldValue
366
473
  ]).optional(),
367
- conditionals: import_zod5.z.array(ActionConditional).default([]).optional(),
474
+ parent: ParentReference,
475
+ conditionals: import_zod5.z.array(FieldConditional).default([]).optional(),
368
476
  required: import_zod5.z.boolean().default(false).optional(),
369
- disabled: import_zod5.z.boolean().default(false).optional(),
370
- hidden: import_zod5.z.boolean().default(false).optional(),
371
477
  placeholder: TranslationConfig.optional(),
372
478
  validation: import_zod5.z.array(
373
479
  import_zod5.z.object({
374
- validator: Conditional(),
480
+ validator: Conditional,
375
481
  message: TranslationConfig
376
482
  })
377
483
  ).default([]).optional(),
378
- dependsOn: import_zod5.z.array(FieldId).default([]).optional(),
379
484
  label: TranslationConfig,
380
485
  hideLabel: import_zod5.z.boolean().default(false).optional()
381
486
  });
@@ -384,7 +489,7 @@ var Divider = BaseField.extend({
384
489
  });
385
490
  var TextField = BaseField.extend({
386
491
  type: import_zod5.z.literal(FieldType.TEXT),
387
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
492
+ defaultValue: NonEmptyTextValue.optional(),
388
493
  configuration: import_zod5.z.object({
389
494
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
390
495
  type: import_zod5.z.enum(["text", "password"]).optional(),
@@ -394,7 +499,7 @@ var TextField = BaseField.extend({
394
499
  }).describe("Text input");
395
500
  var NumberField = BaseField.extend({
396
501
  type: import_zod5.z.literal(FieldType.NUMBER),
397
- defaultValue: import_zod5.z.union([NumberFieldValue, DependencyExpression]).optional(),
502
+ defaultValue: NumberFieldValue.optional(),
398
503
  configuration: import_zod5.z.object({
399
504
  min: import_zod5.z.number().optional().describe("Minimum value"),
400
505
  max: import_zod5.z.number().optional().describe("Maximum value"),
@@ -404,7 +509,7 @@ var NumberField = BaseField.extend({
404
509
  }).describe("Number input");
405
510
  var TextAreaField = BaseField.extend({
406
511
  type: import_zod5.z.literal(FieldType.TEXTAREA),
407
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
512
+ defaultValue: NonEmptyTextValue.optional(),
408
513
  configuration: import_zod5.z.object({
409
514
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text"),
410
515
  rows: import_zod5.z.number().optional().describe("Number of visible text lines"),
@@ -413,26 +518,36 @@ var TextAreaField = BaseField.extend({
413
518
  postfix: TranslationConfig.optional()
414
519
  }).default({ rows: 4 }).optional()
415
520
  }).describe("Multiline text input");
521
+ var ImageMimeType = import_zod5.z.enum([
522
+ "image/png",
523
+ "image/jpg",
524
+ "image/jpeg",
525
+ "image/svg+xml"
526
+ ]);
527
+ var MimeType = ImageMimeType;
528
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
416
529
  var SignatureField = BaseField.extend({
417
530
  type: import_zod5.z.literal(FieldType.SIGNATURE),
418
531
  signaturePromptLabel: TranslationConfig.describe(
419
532
  "Title of the signature modal"
420
533
  ),
421
534
  configuration: import_zod5.z.object({
422
- maxSizeMb: import_zod5.z.number().optional().describe("Maximum file size in MB"),
423
- allowedFileFormats: import_zod5.z.array(import_zod5.z.string()).optional().describe("List of allowed file formats for the signature")
424
- }).default({}).optional()
535
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
536
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
537
+ }).default({
538
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
539
+ })
425
540
  }).describe("Signature input field");
426
541
  var EmailField = BaseField.extend({
427
542
  type: import_zod5.z.literal(FieldType.EMAIL),
428
543
  configuration: import_zod5.z.object({
429
544
  maxLength: import_zod5.z.number().optional().describe("Maximum length of the text")
430
545
  }).default({ maxLength: 10 }).optional(),
431
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
546
+ defaultValue: NonEmptyTextValue.optional()
432
547
  });
433
548
  var DateField = BaseField.extend({
434
549
  type: import_zod5.z.literal(FieldType.DATE),
435
- defaultValue: import_zod5.z.union([DateValue, DependencyExpression]).optional(),
550
+ defaultValue: DateValue.optional(),
436
551
  configuration: import_zod5.z.object({
437
552
  notice: TranslationConfig.describe(
438
553
  "Text to display above the date input"
@@ -451,7 +566,7 @@ var HtmlFontVariant = import_zod5.z.enum([
451
566
  ]);
452
567
  var Paragraph = BaseField.extend({
453
568
  type: import_zod5.z.literal(FieldType.PARAGRAPH),
454
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
569
+ defaultValue: NonEmptyTextValue.optional(),
455
570
  configuration: import_zod5.z.object({
456
571
  styles: import_zod5.z.object({
457
572
  fontVariant: HtmlFontVariant.optional()
@@ -460,17 +575,22 @@ var Paragraph = BaseField.extend({
460
575
  }).describe("A read-only HTML <p> paragraph");
461
576
  var PageHeader = BaseField.extend({
462
577
  type: import_zod5.z.literal(FieldType.PAGE_HEADER),
463
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
578
+ defaultValue: NonEmptyTextValue.optional()
464
579
  }).describe("A read-only header component for form pages");
465
580
  var File = BaseField.extend({
466
581
  type: import_zod5.z.literal(FieldType.FILE),
467
- options: import_zod5.z.object({
582
+ configuration: import_zod5.z.object({
583
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
584
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
468
585
  style: import_zod5.z.object({
469
- fullWidth: import_zod5.z.boolean().describe(
586
+ width: import_zod5.z.enum(["full", "auto"]).optional().describe(
470
587
  "Whether the file upload button should take the full width of the container or not"
471
588
  )
472
- })
473
- }).optional()
589
+ }).optional(),
590
+ fileName: TranslationConfig.optional()
591
+ }).default({
592
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
593
+ })
474
594
  }).describe("File upload");
475
595
  var SelectOption = import_zod5.z.object({
476
596
  value: import_zod5.z.string().describe("The value of the option"),
@@ -478,7 +598,7 @@ var SelectOption = import_zod5.z.object({
478
598
  });
479
599
  var RadioGroup = BaseField.extend({
480
600
  type: import_zod5.z.literal(FieldType.RADIO_GROUP),
481
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
601
+ defaultValue: TextValue.optional(),
482
602
  options: import_zod5.z.array(SelectOption).describe("A list of options"),
483
603
  configuration: import_zod5.z.object({
484
604
  styles: import_zod5.z.object({
@@ -488,7 +608,7 @@ var RadioGroup = BaseField.extend({
488
608
  }).describe("Grouped radio options");
489
609
  var BulletList = BaseField.extend({
490
610
  type: import_zod5.z.literal(FieldType.BULLET_LIST),
491
- defaultValue: import_zod5.z.string().optional(),
611
+ defaultValue: TextValue.optional(),
492
612
  items: import_zod5.z.array(TranslationConfig).describe("A list of items"),
493
613
  configuration: import_zod5.z.object({
494
614
  styles: import_zod5.z.object({
@@ -498,16 +618,16 @@ var BulletList = BaseField.extend({
498
618
  }).describe("A list of bullet points");
499
619
  var Select = BaseField.extend({
500
620
  type: import_zod5.z.literal(FieldType.SELECT),
501
- defaultValue: import_zod5.z.union([TextValue, DependencyExpression]).optional(),
621
+ defaultValue: TextValue.optional(),
502
622
  options: import_zod5.z.array(SelectOption).describe("A list of options")
503
623
  }).describe("Select input");
504
624
  var Checkbox = BaseField.extend({
505
625
  type: import_zod5.z.literal(FieldType.CHECKBOX),
506
- defaultValue: import_zod5.z.union([CheckboxFieldValue, DependencyExpression]).optional()
626
+ defaultValue: CheckboxFieldValue.optional()
507
627
  }).describe("Boolean checkbox field");
508
628
  var Country = BaseField.extend({
509
629
  type: import_zod5.z.literal(FieldType.COUNTRY),
510
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
630
+ defaultValue: NonEmptyTextValue.optional()
511
631
  }).describe("Country select field");
512
632
  var AdministrativeAreas = import_zod5.z.enum([
513
633
  "ADMIN_STRUCTURE",
@@ -516,35 +636,57 @@ var AdministrativeAreas = import_zod5.z.enum([
516
636
  ]);
517
637
  var AdministrativeAreaConfiguration = import_zod5.z.object({
518
638
  partOf: import_zod5.z.object({
519
- $data: import_zod5.z.string()
639
+ $declaration: import_zod5.z.string()
520
640
  }).optional().describe("Parent location"),
521
641
  type: AdministrativeAreas
522
642
  }).describe("Administrative area options");
523
643
  var AdministrativeArea = BaseField.extend({
524
644
  type: import_zod5.z.literal(FieldType.ADMINISTRATIVE_AREA),
525
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional(),
645
+ defaultValue: NonEmptyTextValue.optional(),
526
646
  configuration: AdministrativeAreaConfiguration
527
647
  }).describe("Administrative area input field e.g. facility, office");
528
648
  var Location = BaseField.extend({
529
649
  type: import_zod5.z.literal(FieldType.LOCATION),
530
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
650
+ defaultValue: NonEmptyTextValue.optional()
531
651
  }).describe("Input field for a location");
532
652
  var FileUploadWithOptions = BaseField.extend({
533
653
  type: import_zod5.z.literal(FieldType.FILE_WITH_OPTIONS),
534
- options: import_zod5.z.array(SelectOption).describe("A list of options")
535
- }).describe("Select input");
654
+ options: import_zod5.z.array(SelectOption).describe("A list of options"),
655
+ configuration: import_zod5.z.object({
656
+ maxFileSize: import_zod5.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
657
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
658
+ }).default({
659
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
660
+ })
661
+ });
536
662
  var Facility = BaseField.extend({
537
663
  type: import_zod5.z.literal(FieldType.FACILITY),
538
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
664
+ defaultValue: NonEmptyTextValue.optional()
539
665
  }).describe("Input field for a facility");
540
666
  var Office = BaseField.extend({
541
667
  type: import_zod5.z.literal(FieldType.OFFICE),
542
- defaultValue: import_zod5.z.union([RequiredTextValue, DependencyExpression]).optional()
668
+ defaultValue: NonEmptyTextValue.optional()
543
669
  }).describe("Input field for an office");
544
670
  var Address = BaseField.extend({
545
671
  type: import_zod5.z.literal(FieldType.ADDRESS),
546
672
  defaultValue: AddressFieldValue.optional()
547
673
  }).describe("Address input field \u2013 a combination of location and text fields");
674
+ var DataEntry = import_zod5.z.union([
675
+ import_zod5.z.object({
676
+ label: TranslationConfig,
677
+ value: TranslationConfig.or(import_zod5.z.string())
678
+ }),
679
+ import_zod5.z.object({
680
+ fieldId: import_zod5.z.string()
681
+ })
682
+ ]);
683
+ var DataField = BaseField.extend({
684
+ type: import_zod5.z.literal(FieldType.DATA),
685
+ configuration: import_zod5.z.object({
686
+ subtitle: TranslationConfig.optional(),
687
+ data: import_zod5.z.array(DataEntry)
688
+ })
689
+ }).describe("Data field for displaying read-only data");
548
690
  var FieldConfig = import_zod5.z.discriminatedUnion("type", [
549
691
  Address,
550
692
  TextField,
@@ -566,238 +708,331 @@ var FieldConfig = import_zod5.z.discriminatedUnion("type", [
566
708
  Office,
567
709
  SignatureField,
568
710
  EmailField,
569
- FileUploadWithOptions
711
+ FileUploadWithOptions,
712
+ DataField
570
713
  ]);
571
714
 
572
- // ../commons/src/events/FormConfig.ts
573
- var FormPage = import_zod6.z.object({
715
+ // ../commons/src/events/PageConfig.ts
716
+ var PageTypes = import_zod6.z.enum(["FORM", "VERIFICATION"]);
717
+ var PageConfigBase = import_zod6.z.object({
574
718
  id: import_zod6.z.string().describe("Unique identifier for the page"),
575
719
  title: TranslationConfig.describe("Header title of the page"),
576
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page")
720
+ fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the page"),
721
+ conditional: Conditional.optional().describe(
722
+ "Page will be shown if condition is met. If conditional is not defined, the page will be always shown."
723
+ )
577
724
  });
578
- var FormConfig = import_zod6.z.object({
579
- label: TranslationConfig.describe("Human readable description of the form"),
580
- version: import_zod6.z.object({
581
- id: import_zod6.z.string().describe(
582
- "Form version. Semantic versioning recommended. Example: 0.0.1"
583
- ),
584
- label: TranslationConfig.describe(
585
- "Human readable description of the version"
586
- )
587
- }),
588
- active: import_zod6.z.boolean().default(false).describe("Whether the form is active"),
589
- pages: import_zod6.z.array(FormPage),
590
- review: import_zod6.z.object({
591
- title: TranslationConfig.describe(
592
- "Title of the form to show in review page"
593
- ),
594
- fields: import_zod6.z.array(FieldConfig).describe("Fields to be rendered on the review page for metadata")
725
+ var FormPageConfig = PageConfigBase.extend({
726
+ type: import_zod6.z.literal(PageTypes.enum.FORM).default(PageTypes.enum.FORM)
727
+ });
728
+ var VerificationActionConfig = import_zod6.z.object({
729
+ verify: import_zod6.z.object({ label: TranslationConfig }),
730
+ cancel: import_zod6.z.object({
731
+ label: TranslationConfig,
732
+ confirmation: import_zod6.z.object({
733
+ title: TranslationConfig,
734
+ body: TranslationConfig
735
+ })
595
736
  })
737
+ }).describe("Actions available on the verification page");
738
+ var VerificationPageConfig = FormPageConfig.extend({
739
+ type: import_zod6.z.literal(PageTypes.enum.VERIFICATION),
740
+ actions: VerificationActionConfig
596
741
  });
742
+ var PageConfig = import_zod6.z.discriminatedUnion("type", [
743
+ FormPageConfig,
744
+ VerificationPageConfig
745
+ ]);
597
746
 
598
747
  // ../commons/src/events/ActionType.ts
748
+ var import_zod7 = require("zod");
599
749
  var ActionType = {
750
+ // Pre-declaration actions
751
+ DELETE: "DELETE",
600
752
  CREATE: "CREATE",
601
- ASSIGN: "ASSIGN",
602
- UNASSIGN: "UNASSIGN",
603
- REGISTER: "REGISTER",
604
- VALIDATE: "VALIDATE",
605
- REQUEST_CORRECTION: "REQUEST_CORRECTION",
606
- REJECT_CORRECTION: "REJECT_CORRECTION",
607
- APPROVE_CORRECTION: "APPROVE_CORRECTION",
608
- DETECT_DUPLICATE: "DETECT_DUPLICATE",
609
753
  NOTIFY: "NOTIFY",
754
+ // Declaration actions
610
755
  DECLARE: "DECLARE",
611
- DELETE: "DELETE",
612
- PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
613
- CUSTOM: "CUSTOM",
756
+ VALIDATE: "VALIDATE",
757
+ REGISTER: "REGISTER",
758
+ // Declaration system actions. Non-configurable.
759
+ DETECT_DUPLICATE: "DETECT_DUPLICATE",
614
760
  REJECT: "REJECT",
761
+ // REJECT_DECLARATION
615
762
  MARKED_AS_DUPLICATE: "MARKED_AS_DUPLICATE",
616
- ARCHIVE: "ARCHIVE"
763
+ // MARK_AS_DUPLICATE
764
+ ARCHIVE: "ARCHIVE",
765
+ // Record actions
766
+ PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
767
+ REQUEST_CORRECTION: "REQUEST_CORRECTION",
768
+ REJECT_CORRECTION: "REJECT_CORRECTION",
769
+ APPROVE_CORRECTION: "APPROVE_CORRECTION",
770
+ // General actions
771
+ READ: "READ",
772
+ ASSIGN: "ASSIGN",
773
+ UNASSIGN: "UNASSIGN"
617
774
  };
775
+ var ConfirmableActions = [
776
+ ActionType.NOTIFY,
777
+ ActionType.DECLARE,
778
+ ActionType.VALIDATE,
779
+ ActionType.REGISTER,
780
+ ActionType.REJECT,
781
+ ActionType.ARCHIVE,
782
+ ActionType.PRINT_CERTIFICATE
783
+ ];
784
+ var ActionTypes = import_zod7.z.enum([
785
+ "DELETE",
786
+ "CREATE",
787
+ "NOTIFY",
788
+ "DECLARE",
789
+ "VALIDATE",
790
+ "REGISTER",
791
+ "DETECT_DUPLICATE",
792
+ "REJECT",
793
+ "MARKED_AS_DUPLICATE",
794
+ "ARCHIVE",
795
+ "PRINT_CERTIFICATE",
796
+ "REQUEST_CORRECTION",
797
+ "REJECT_CORRECTION",
798
+ "APPROVE_CORRECTION",
799
+ "READ",
800
+ "ASSIGN",
801
+ "UNASSIGN"
802
+ ]);
803
+ var declarationActionValues = [
804
+ ActionTypes.enum.DECLARE,
805
+ ActionTypes.enum.VALIDATE,
806
+ ActionTypes.enum.REGISTER
807
+ ];
808
+ var DeclarationActions = ActionTypes.extract(declarationActionValues);
809
+ var declarationUpdateActionValues = [
810
+ ...declarationActionValues,
811
+ ActionTypes.enum.REQUEST_CORRECTION
812
+ ];
813
+ var DeclarationUpdateActions = ActionTypes.extract(
814
+ declarationUpdateActionValues
815
+ );
816
+ var annotationActions = ActionTypes.exclude(declarationActionValues);
817
+ var writeActions = ActionTypes.exclude([
818
+ ActionType.CREATE,
819
+ ActionType.READ,
820
+ ActionType.ASSIGN,
821
+ ActionType.UNASSIGN
822
+ ]);
823
+
824
+ // ../commons/src/events/FormConfig.ts
825
+ var import_zod8 = require("zod");
826
+ var DeclarationFormConfig = import_zod8.z.object({
827
+ label: TranslationConfig.describe("Human readable description of the form"),
828
+ pages: import_zod8.z.array(FormPageConfig)
829
+ }).describe("Configuration for a declaration form");
830
+ var ActionFormConfig = import_zod8.z.object({
831
+ label: TranslationConfig.describe("Human readable description of the form"),
832
+ pages: import_zod8.z.array(PageConfig)
833
+ });
834
+ var FormConfig = import_zod8.z.union([DeclarationFormConfig, ActionFormConfig]);
618
835
 
619
836
  // ../commons/src/events/ActionConfig.ts
620
- var ActionConditional2 = import_zod7.z.discriminatedUnion("type", [
837
+ var import_zod_openapi = require("zod-openapi");
838
+ (0, import_zod_openapi.extendZodWithOpenApi)(import_zod9.z);
839
+ var ActionConditional2 = import_zod9.z.discriminatedUnion("type", [
621
840
  /** If conditional is defined, the action is shown to the user only if the condition is met */
622
841
  ShowConditional,
623
842
  /** If conditional is defined, the action is enabled only if the condition is met */
624
843
  EnableConditional
625
844
  ]);
626
- var ActionConfigBase = import_zod7.z.object({
845
+ var DeclarationReviewConfig = import_zod9.z.object({
846
+ title: TranslationConfig.describe("Title of the review page"),
847
+ fields: import_zod9.z.array(FieldConfig).describe("Fields to be rendered on the review page for annotations.")
848
+ }).describe("Configuration for **declaration** review page.");
849
+ var ActionConfigBase = import_zod9.z.object({
627
850
  label: TranslationConfig,
628
- conditionals: import_zod7.z.array(ActionConditional2).optional().default([]),
629
- draft: import_zod7.z.boolean().optional(),
630
- forms: import_zod7.z.array(FormConfig)
851
+ conditionals: import_zod9.z.array(ActionConditional2).optional().default([]),
852
+ draft: import_zod9.z.boolean().optional()
631
853
  });
632
854
  var DeclareConfig = ActionConfigBase.merge(
633
- import_zod7.z.object({
634
- type: import_zod7.z.literal(ActionType.DECLARE)
855
+ import_zod9.z.object({
856
+ type: import_zod9.z.literal(ActionType.DECLARE),
857
+ review: DeclarationReviewConfig
635
858
  })
636
859
  );
637
860
  var ValidateConfig = ActionConfigBase.merge(
638
- import_zod7.z.object({
639
- type: import_zod7.z.literal(ActionType.VALIDATE)
861
+ import_zod9.z.object({
862
+ type: import_zod9.z.literal(ActionType.VALIDATE),
863
+ review: DeclarationReviewConfig
864
+ })
865
+ );
866
+ var RegisterConfig = ActionConfigBase.merge(
867
+ import_zod9.z.object({
868
+ type: import_zod9.z.literal(ActionType.REGISTER),
869
+ review: DeclarationReviewConfig
640
870
  })
641
871
  );
642
872
  var RejectDeclarationConfig = ActionConfigBase.merge(
643
- import_zod7.z.object({
644
- type: import_zod7.z.literal(ActionType.REJECT)
873
+ import_zod9.z.object({
874
+ type: import_zod9.z.literal(ActionType.REJECT)
645
875
  })
646
876
  );
647
877
  var MarkedAsDuplicateConfig = ActionConfigBase.merge(
648
- import_zod7.z.object({
649
- type: import_zod7.z.literal(ActionType.MARKED_AS_DUPLICATE)
878
+ import_zod9.z.object({
879
+ type: import_zod9.z.literal(ActionType.MARKED_AS_DUPLICATE)
650
880
  })
651
881
  );
652
882
  var ArchiveConfig = ActionConfigBase.merge(
653
- import_zod7.z.object({
654
- type: import_zod7.z.literal(ActionType.ARCHIVE)
655
- })
656
- );
657
- var RegisterConfig = ActionConfigBase.merge(
658
- import_zod7.z.object({
659
- type: import_zod7.z.literal(ActionType.REGISTER)
883
+ import_zod9.z.object({
884
+ type: import_zod9.z.literal(ActionType.ARCHIVE)
660
885
  })
661
886
  );
662
887
  var DeleteConfig = ActionConfigBase.merge(
663
- import_zod7.z.object({
664
- type: import_zod7.z.literal(ActionType.DELETE)
888
+ import_zod9.z.object({
889
+ type: import_zod9.z.literal(ActionType.DELETE)
665
890
  })
666
891
  );
667
892
  var PrintCertificateActionConfig = ActionConfigBase.merge(
668
- import_zod7.z.object({
669
- type: import_zod7.z.literal(ActionType.PRINT_CERTIFICATE)
893
+ import_zod9.z.object({
894
+ type: import_zod9.z.literal(ActionType.PRINT_CERTIFICATE),
895
+ printForm: ActionFormConfig
670
896
  })
671
897
  );
672
898
  var RequestCorrectionConfig = ActionConfigBase.merge(
673
- import_zod7.z.object({
674
- type: import_zod7.z.literal(ActionType.REQUEST_CORRECTION),
675
- onboardingForm: import_zod7.z.array(FormPage),
676
- additionalDetailsForm: import_zod7.z.array(FormPage)
899
+ import_zod9.z.object({
900
+ type: import_zod9.z.literal(ActionType.REQUEST_CORRECTION),
901
+ onboardingForm: import_zod9.z.array(PageConfig),
902
+ additionalDetailsForm: import_zod9.z.array(PageConfig)
677
903
  })
678
904
  );
679
905
  var RejectCorrectionConfig = ActionConfigBase.merge(
680
- import_zod7.z.object({
681
- type: import_zod7.z.literal(ActionType.REJECT_CORRECTION)
906
+ import_zod9.z.object({
907
+ type: import_zod9.z.literal(ActionType.REJECT_CORRECTION)
682
908
  })
683
909
  );
684
910
  var ApproveCorrectionConfig = ActionConfigBase.merge(
685
- import_zod7.z.object({
686
- type: import_zod7.z.literal(ActionType.APPROVE_CORRECTION)
687
- })
688
- );
689
- var CustomConfig = ActionConfigBase.merge(
690
- import_zod7.z.object({
691
- type: import_zod7.z.literal(ActionType.CUSTOM)
911
+ import_zod9.z.object({
912
+ type: import_zod9.z.literal(ActionType.APPROVE_CORRECTION)
692
913
  })
693
914
  );
694
- var ActionConfig = import_zod7.z.discriminatedUnion("type", [
915
+ var ActionConfig = import_zod9.z.discriminatedUnion("type", [
916
+ /*
917
+ * OpenAPI references are defined here so our generated OpenAPI spec knows to reuse the models
918
+ * and treat them as "models" instead of duplicating the data structure in each endpoint.
919
+ */
920
+ DeclareConfig.openapi({ ref: "DeclareActionConfig" }),
921
+ ValidateConfig.openapi({ ref: "ValidateActionConfig" }),
922
+ RejectDeclarationConfig.openapi({ ref: "RejectDeclarationActionConfig" }),
923
+ MarkedAsDuplicateConfig.openapi({ ref: "MarkedAsDuplicateActionConfig" }),
924
+ ArchiveConfig.openapi({ ref: "ArchiveActionConfig" }),
925
+ RegisterConfig.openapi({ ref: "RegisterActionConfig" }),
926
+ DeleteConfig.openapi({ ref: "DeleteActionConfig" }),
927
+ PrintCertificateActionConfig.openapi({
928
+ ref: "PrintCertificateActionConfig"
929
+ }),
930
+ RequestCorrectionConfig.openapi({ ref: "RequestCorrectionActionConfig" }),
931
+ RejectCorrectionConfig.openapi({ ref: "RejectCorrectionActionConfig" }),
932
+ ApproveCorrectionConfig.openapi({ ref: "ApproveCorrectionActionConfig" })
933
+ ]).openapi({ ref: "ActionConfig" });
934
+ var DeclarationActionConfig = import_zod9.z.discriminatedUnion("type", [
695
935
  DeclareConfig,
696
936
  ValidateConfig,
697
- RejectDeclarationConfig,
698
- MarkedAsDuplicateConfig,
699
- ArchiveConfig,
700
- RegisterConfig,
701
- DeleteConfig,
702
- PrintCertificateActionConfig,
703
- RequestCorrectionConfig,
704
- RejectCorrectionConfig,
705
- ApproveCorrectionConfig,
706
- CustomConfig
937
+ RegisterConfig
707
938
  ]);
708
939
 
709
940
  // ../commons/src/events/offline/CertificateConfig.ts
710
- var import_zod8 = require("zod");
711
- var FontFamily = import_zod8.z.object({
712
- normal: import_zod8.z.string(),
713
- bold: import_zod8.z.string(),
714
- italics: import_zod8.z.string(),
715
- bolditalics: import_zod8.z.string()
941
+ var import_zod10 = require("zod");
942
+ var FontFamily = import_zod10.z.object({
943
+ normal: import_zod10.z.string(),
944
+ bold: import_zod10.z.string(),
945
+ italics: import_zod10.z.string(),
946
+ bolditalics: import_zod10.z.string()
716
947
  });
717
- var CertificateConfig = import_zod8.z.object({
718
- id: import_zod8.z.string(),
719
- event: import_zod8.z.string(),
948
+ var CertificateConfig = import_zod10.z.object({
949
+ id: import_zod10.z.string(),
950
+ event: import_zod10.z.string(),
720
951
  label: TranslationConfig,
721
- isDefault: import_zod8.z.boolean(),
722
- fee: import_zod8.z.object({
723
- onTime: import_zod8.z.number(),
724
- late: import_zod8.z.number(),
725
- delayed: import_zod8.z.number()
952
+ isDefault: import_zod10.z.boolean(),
953
+ fee: import_zod10.z.object({
954
+ onTime: import_zod10.z.number(),
955
+ late: import_zod10.z.number(),
956
+ delayed: import_zod10.z.number()
726
957
  }),
727
- svgUrl: import_zod8.z.string(),
728
- fonts: import_zod8.z.record(FontFamily).optional()
958
+ svgUrl: import_zod10.z.string(),
959
+ fonts: import_zod10.z.record(FontFamily).optional()
729
960
  });
730
961
  var CertificateTemplateConfig = CertificateConfig.extend({
731
- hash: import_zod8.z.string().optional(),
732
- svg: import_zod8.z.string()
962
+ hash: import_zod10.z.string().optional(),
963
+ svg: import_zod10.z.string()
733
964
  });
734
965
 
735
966
  // ../commons/src/events/offline/LanguageConfig.ts
736
- var import_zod9 = require("zod");
737
- var LanguageConfig = import_zod9.z.object({
738
- lang: import_zod9.z.string(),
967
+ var import_zod11 = require("zod");
968
+ var LanguageConfig = import_zod11.z.object({
969
+ lang: import_zod11.z.string(),
739
970
  /**
740
971
  * client.csv contents
741
972
  */
742
- messages: import_zod9.z.record(import_zod9.z.string())
973
+ messages: import_zod11.z.record(import_zod11.z.string())
743
974
  });
744
975
 
745
976
  // ../commons/src/events/EventConfig.ts
746
- var import_zod18 = require("zod");
977
+ var import_zod16 = require("zod");
747
978
 
748
979
  // ../commons/src/events/DeduplicationConfig.ts
749
- var import_zod10 = require("zod");
750
- var FieldReference = import_zod10.z.string();
751
- var Matcher = import_zod10.z.object({
752
- fieldId: import_zod10.z.string(),
753
- options: import_zod10.z.object({
754
- boost: import_zod10.z.number().optional()
980
+ var import_zod12 = require("zod");
981
+ var import_zod_openapi2 = require("zod-openapi");
982
+ (0, import_zod_openapi2.extendZodWithOpenApi)(import_zod12.z);
983
+ var FieldReference = import_zod12.z.string();
984
+ var Matcher = import_zod12.z.object({
985
+ fieldId: import_zod12.z.string(),
986
+ options: import_zod12.z.object({
987
+ boost: import_zod12.z.number().optional()
755
988
  }).optional().default({})
756
989
  });
757
990
  var FuzzyMatcher = Matcher.extend({
758
- type: import_zod10.z.literal("fuzzy"),
759
- options: import_zod10.z.object({
991
+ type: import_zod12.z.literal("fuzzy"),
992
+ options: import_zod12.z.object({
760
993
  /**
761
994
  * Names of length 3 or less characters = 0 edits allowed
762
995
  * Names of length 4 - 6 characters = 1 edit allowed
763
996
  * Names of length >7 characters = 2 edits allowed
764
997
  */
765
- fuzziness: import_zod10.z.union([import_zod10.z.string(), import_zod10.z.number()]).optional().default("AUTO:4,7"),
766
- boost: import_zod10.z.number().optional().default(1)
998
+ fuzziness: import_zod12.z.union([import_zod12.z.string(), import_zod12.z.number()]).optional().default("AUTO:4,7"),
999
+ boost: import_zod12.z.number().optional().default(1)
767
1000
  }).optional().default({})
768
1001
  });
769
1002
  var StrictMatcher = Matcher.extend({
770
- type: import_zod10.z.literal("strict"),
771
- options: import_zod10.z.object({
772
- boost: import_zod10.z.number().optional().default(1)
1003
+ type: import_zod12.z.literal("strict"),
1004
+ options: import_zod12.z.object({
1005
+ boost: import_zod12.z.number().optional().default(1)
773
1006
  }).optional().default({})
774
1007
  });
775
1008
  var DateRangeMatcher = Matcher.extend({
776
- type: import_zod10.z.literal("dateRange"),
777
- options: import_zod10.z.object({
778
- days: import_zod10.z.number(),
1009
+ type: import_zod12.z.literal("dateRange"),
1010
+ options: import_zod12.z.object({
1011
+ days: import_zod12.z.number(),
779
1012
  origin: FieldReference,
780
- boost: import_zod10.z.number().optional().default(1)
1013
+ boost: import_zod12.z.number().optional().default(1)
781
1014
  })
782
1015
  });
783
1016
  var DateDistanceMatcher = Matcher.extend({
784
- type: import_zod10.z.literal("dateDistance"),
785
- options: import_zod10.z.object({
786
- days: import_zod10.z.number(),
1017
+ type: import_zod12.z.literal("dateDistance"),
1018
+ options: import_zod12.z.object({
1019
+ days: import_zod12.z.number(),
787
1020
  origin: FieldReference,
788
- boost: import_zod10.z.number().optional().default(1)
1021
+ boost: import_zod12.z.number().optional().default(1)
789
1022
  })
790
1023
  });
791
- var And = import_zod10.z.object({
792
- type: import_zod10.z.literal("and"),
793
- clauses: import_zod10.z.lazy(() => Clause.array())
1024
+ var And = import_zod12.z.object({
1025
+ type: import_zod12.z.literal("and"),
1026
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1027
+ clauses: import_zod12.z.lazy(() => Clause.array())
794
1028
  });
795
- var Or = import_zod10.z.object({
796
- type: import_zod10.z.literal("or"),
797
- clauses: import_zod10.z.lazy(() => Clause.array())
1029
+ var Or = import_zod12.z.object({
1030
+ type: import_zod12.z.literal("or"),
1031
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1032
+ clauses: import_zod12.z.lazy(() => Clause.array())
798
1033
  });
799
- var Clause = import_zod10.z.lazy(
800
- () => import_zod10.z.discriminatedUnion("type", [
1034
+ var Clause = import_zod12.z.lazy(
1035
+ () => import_zod12.z.discriminatedUnion("type", [
801
1036
  And,
802
1037
  Or,
803
1038
  FuzzyMatcher,
@@ -805,275 +1040,73 @@ var Clause = import_zod10.z.lazy(
805
1040
  DateRangeMatcher,
806
1041
  DateDistanceMatcher
807
1042
  ])
808
- );
809
- var DeduplicationConfig = import_zod10.z.object({
810
- id: import_zod10.z.string(),
1043
+ ).openapi({
1044
+ ref: "Clause"
1045
+ });
1046
+ var DeduplicationConfig = import_zod12.z.object({
1047
+ id: import_zod12.z.string(),
811
1048
  label: TranslationConfig,
812
1049
  query: Clause
813
1050
  });
814
1051
 
815
1052
  // ../commons/src/events/SummaryConfig.ts
816
- var import_zod11 = require("zod");
817
- var Field = import_zod11.z.object({
818
- id: import_zod11.z.string().describe("Id of summary field"),
1053
+ var import_zod13 = require("zod");
1054
+ var BaseField2 = import_zod13.z.object({
1055
+ emptyValueMessage: TranslationConfig.optional(),
1056
+ conditionals: import_zod13.z.array(ShowConditional).default([]).optional()
1057
+ });
1058
+ var ReferenceField = BaseField2.extend({
1059
+ fieldId: import_zod13.z.string()
1060
+ }).describe("Field directly referencing event data with field id");
1061
+ var Field = BaseField2.extend({
1062
+ id: import_zod13.z.string().describe("Id of summary field"),
819
1063
  value: TranslationConfig.describe(
820
1064
  "Summary field value. Can utilise values defined in configuration and EventMetadata"
821
1065
  ),
822
1066
  label: TranslationConfig,
823
1067
  emptyValueMessage: TranslationConfig.optional()
824
- });
825
- var Title = import_zod11.z.object({
826
- id: import_zod11.z.string(),
827
- label: TranslationConfig.describe("Title content"),
828
- emptyValueMessage: TranslationConfig.optional()
829
- });
830
- var SummaryConfig = import_zod11.z.object({
831
- title: Title.describe("Title of summary view."),
832
- fields: import_zod11.z.array(Field).describe("Fields rendered in summary view.")
1068
+ }).describe("Custom configured field");
1069
+ var SummaryConfig = import_zod13.z.object({
1070
+ fields: import_zod13.z.array(import_zod13.z.union([Field, ReferenceField])).describe("Fields rendered in summary view.")
833
1071
  }).describe("Configuration for summary in event.");
834
1072
 
835
- // ../commons/src/events/WorkqueueConfig.ts
836
- var import_zod13 = require("zod");
837
-
838
- // ../commons/src/events/EventMetadata.ts
839
- var import_zod12 = require("zod");
840
- var EventStatus = {
841
- CREATED: "CREATED",
842
- NOTIFIED: "NOTIFIED",
843
- DECLARED: "DECLARED",
844
- VALIDATED: "VALIDATED",
845
- REGISTERED: "REGISTERED",
846
- CERTIFIED: "CERTIFIED",
847
- REJECTED: "REJECTED",
848
- ARCHIVED: "ARCHIVED"
849
- };
850
- var eventStatuses = Object.values(EventStatus);
851
- var EventStatuses = import_zod12.z.nativeEnum(EventStatus);
852
- var EventMetadata = import_zod12.z.object({
853
- id: import_zod12.z.string(),
854
- type: import_zod12.z.string(),
855
- status: EventStatuses,
856
- createdAt: import_zod12.z.string().datetime(),
857
- createdBy: import_zod12.z.string(),
858
- createdAtLocation: import_zod12.z.string(),
859
- modifiedAt: import_zod12.z.string().datetime(),
860
- assignedTo: import_zod12.z.string().nullish(),
861
- updatedBy: import_zod12.z.string(),
862
- trackingId: import_zod12.z.string()
863
- });
864
- var eventMetadataLabelMap = {
865
- "event.assignedTo": {
866
- id: "event.assignedTo.label",
867
- defaultMessage: "Assigned To",
868
- description: "Assigned To"
869
- },
870
- "event.createdAt": {
871
- id: "event.createdAt.label",
872
- defaultMessage: "Created",
873
- description: "Created At"
874
- },
875
- "event.createdAtLocation": {
876
- id: "event.createdAtLocation.label",
877
- defaultMessage: "Location",
878
- description: "Created At Location"
879
- },
880
- "event.createdBy": {
881
- id: "event.createdBy.label",
882
- defaultMessage: "Created By",
883
- description: "Created By"
884
- },
885
- "event.id": {
886
- id: "event.id.label",
887
- defaultMessage: "ID",
888
- description: "ID"
889
- },
890
- "event.modifiedAt": {
891
- id: "event.modifiedAt.label",
892
- defaultMessage: "Updated",
893
- description: "Modified At"
894
- },
895
- "event.status": {
896
- id: "event.status.label",
897
- defaultMessage: "Status",
898
- description: "Status"
899
- },
900
- "event.type": {
901
- id: "event.type.label",
902
- defaultMessage: "Type",
903
- description: "Type"
904
- },
905
- "event.updatedBy": {
906
- id: "event.updatedBy.label",
907
- defaultMessage: "Updated By",
908
- description: "Updated By"
909
- },
910
- "event.trackingId": {
911
- id: "event.trackingId.label",
912
- defaultMessage: "Tracking ID",
913
- description: "Tracking ID"
914
- }
915
- };
916
-
917
- // ../commons/src/events/WorkqueueConfig.ts
918
- var WorkqueueConfig = import_zod13.z.object({
919
- id: import_zod13.z.string().describe("Unique identifier for workqueue."),
920
- filters: import_zod13.z.array(
921
- import_zod13.z.object({
922
- status: import_zod13.z.array(EventStatuses).describe("Defines which statusese are included in the workqueue.")
923
- })
924
- ).describe("Filters to be applied to workqueue.")
925
- }).describe("Configuration for workqueue.");
926
-
927
1073
  // ../commons/src/events/AdvancedSearchConfig.ts
928
1074
  var import_zod14 = require("zod");
1075
+ var MatchType = import_zod14.z.enum(["FUZZY", "EXACT", "RANGE", "ANY_OF"]);
1076
+ var BaseField3 = import_zod14.z.object({
1077
+ config: import_zod14.z.object({
1078
+ type: MatchType.describe("Determines the type of field")
1079
+ }),
1080
+ options: import_zod14.z.array(SelectOption).optional()
1081
+ });
1082
+ var FieldConfigSchema = BaseField3.extend({
1083
+ fieldId: import_zod14.z.string(),
1084
+ fieldType: import_zod14.z.literal("field")
1085
+ });
1086
+ var EventFieldId = import_zod14.z.enum(["trackingId", "status"]);
1087
+ var EventFieldConfigSchema = BaseField3.extend({
1088
+ fieldId: EventFieldId,
1089
+ fieldType: import_zod14.z.literal("event")
1090
+ });
1091
+ var SearchField = import_zod14.z.discriminatedUnion("fieldType", [
1092
+ FieldConfigSchema,
1093
+ EventFieldConfigSchema
1094
+ ]);
929
1095
  var AdvancedSearchConfig = import_zod14.z.object({
930
1096
  title: TranslationConfig.describe("Advanced search tab title"),
931
- fields: import_zod14.z.array(
932
- import_zod14.z.object({
933
- fieldId: import_zod14.z.string(),
934
- config: import_zod14.z.object({
935
- type: import_zod14.z.enum(["FUZZY", "EXACT", "RANGE"]).describe("Determines the type of field")
936
- }).optional().describe("Configuration options for the field")
937
- })
938
- ).optional().default([]).describe("Advanced search fields.")
1097
+ fields: import_zod14.z.array(SearchField).describe("Advanced search fields.")
939
1098
  });
940
1099
 
941
1100
  // ../commons/src/events/utils.ts
942
1101
  var import_lodash = require("lodash");
943
1102
 
944
- // ../commons/src/workqueues/WorkqueueConfig.ts
945
- var import_zod16 = require("zod");
946
-
947
- // ../commons/src/workqueues/defaultColumns.ts
948
- var import_zod15 = require("zod");
949
- var WorkQueueColumnConfig = import_zod15.z.object({
950
- id: import_zod15.z.string(),
951
- label: TranslationConfig
952
- });
953
- var defaultColumns = {
954
- event: {
955
- id: "event",
956
- label: {
957
- defaultMessage: "Event",
958
- description: "This is the label for the workqueue column",
959
- id: "workqueue.default.column.event"
960
- }
961
- },
962
- status: {
963
- id: "status",
964
- label: {
965
- defaultMessage: "Status",
966
- description: "This is the label for the workqueue column",
967
- id: "workqueue.default.column.status"
968
- }
969
- },
970
- createdAt: {
971
- id: "createdAt",
972
- label: {
973
- defaultMessage: "Created",
974
- description: "This is the label for the workqueue column",
975
- id: "workqueue.default.column.createdAt"
976
- }
977
- },
978
- modifiedAt: {
979
- id: "modifiedAt",
980
- label: {
981
- defaultMessage: "Modified",
982
- description: "This is the label for the workqueue column",
983
- id: "workqueue.default.column.modifiedAt"
984
- }
985
- }
986
- };
987
- var DefaultColumnKeys = import_zod15.z.enum(
988
- Object.keys(defaultColumns)
989
- );
990
-
991
- // ../commons/src/workqueues/WorkqueueConfig.ts
992
- var rootWorkqueueConfig = import_zod16.z.object({
993
- id: import_zod16.z.string(),
994
- title: TranslationConfig,
995
- columns: import_zod16.z.array(WorkQueueColumnConfig),
996
- defaultColumns: import_zod16.z.array(DefaultColumnKeys)
997
- });
998
- var defineWorkqueue = (config) => rootWorkqueueConfig.parse(config);
999
-
1000
- // ../commons/src/workqueues/all.ts
1001
- var allWorkqueue = defineWorkqueue({
1002
- id: "all",
1003
- title: {
1004
- defaultMessage: "All events",
1005
- description: "This is the label for the workqueue",
1006
- id: "workqueue.all.label"
1007
- },
1008
- columns: [
1009
- {
1010
- id: "title",
1011
- label: {
1012
- defaultMessage: "Title",
1013
- description: "This is the label for the workqueue column",
1014
- id: "workqueue.all.column.title"
1015
- }
1016
- }
1017
- ],
1018
- defaultColumns: ["event", "status", "createdAt", "modifiedAt"]
1019
- });
1020
-
1021
- // ../commons/src/workqueues/readyForReview.ts
1022
- var inReviewWorkqueue = defineWorkqueue({
1023
- id: "ready-for-review",
1024
- title: {
1025
- defaultMessage: "Ready for review",
1026
- description: "Label for in review workqueue",
1027
- id: "event.workqueue.in-review.label"
1028
- },
1029
- columns: [
1030
- {
1031
- id: "title",
1032
- label: {
1033
- defaultMessage: "Title",
1034
- description: "This is the label for the workqueue column",
1035
- id: "workqueue.in-reveiw.column.title"
1036
- }
1037
- }
1038
- ],
1039
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1040
- });
1041
-
1042
- // ../commons/src/workqueues/readyToPrint.ts
1043
- var registeredWorkqueue = defineWorkqueue({
1044
- id: "registered",
1045
- title: {
1046
- defaultMessage: "Ready to print",
1047
- description: "Label for registered workqueue",
1048
- id: "event.workqueue.registered.label"
1049
- },
1050
- columns: [
1051
- {
1052
- id: "title",
1053
- label: {
1054
- defaultMessage: "Title",
1055
- description: "This is the label for the workqueue column",
1056
- id: "workqueue.registered.column.title"
1057
- }
1058
- }
1059
- ],
1060
- defaultColumns: ["event", "createdAt", "modifiedAt"]
1061
- });
1062
-
1063
- // ../commons/src/workqueues/index.ts
1064
- var workqueues = {
1065
- all: allWorkqueue,
1066
- registered: registeredWorkqueue,
1067
- inReview: inReviewWorkqueue
1068
- };
1069
-
1070
1103
  // ../commons/src/conditionals/validate.ts
1071
1104
  var import_ajv = __toESM(require("ajv"));
1072
1105
  var import_ajv_formats = __toESM(require("ajv-formats"));
1073
1106
  var import_date_fns = require("date-fns");
1074
1107
 
1075
1108
  // ../commons/src/events/FieldTypeMapping.ts
1076
- var import_zod17 = require("zod");
1109
+ var import_zod15 = require("zod");
1077
1110
  function mapFieldTypeToZod(type, required) {
1078
1111
  let schema;
1079
1112
  switch (type) {
@@ -1097,8 +1130,7 @@ function mapFieldTypeToZod(type, required) {
1097
1130
  case FieldType.FACILITY:
1098
1131
  case FieldType.OFFICE:
1099
1132
  case FieldType.SIGNATURE:
1100
- case FieldType.HIDDEN:
1101
- schema = required ? RequiredTextValue : TextValue;
1133
+ schema = required ? NonEmptyTextValue : TextValue;
1102
1134
  break;
1103
1135
  case FieldType.NUMBER:
1104
1136
  schema = NumberFieldValue;
@@ -1115,6 +1147,9 @@ function mapFieldTypeToZod(type, required) {
1115
1147
  case FieldType.ADDRESS:
1116
1148
  schema = AddressFieldUpdateValue;
1117
1149
  break;
1150
+ case FieldType.DATA:
1151
+ schema = DataFieldValue;
1152
+ break;
1118
1153
  }
1119
1154
  return required ? schema : schema.nullish();
1120
1155
  }
@@ -1123,7 +1158,7 @@ function createValidationSchema(config) {
1123
1158
  for (const field2 of config) {
1124
1159
  shape[field2.id] = mapFieldTypeToZod(field2.type, field2.required);
1125
1160
  }
1126
- return import_zod17.z.object(shape);
1161
+ return import_zod15.z.object(shape);
1127
1162
  }
1128
1163
  function mapFieldTypeToMockValue(field2, i) {
1129
1164
  switch (field2.type) {
@@ -1149,6 +1184,7 @@ function mapFieldTypeToMockValue(field2, i) {
1149
1184
  case FieldType.ADDRESS:
1150
1185
  return {
1151
1186
  country: "FAR",
1187
+ addressType: AddressType.DOMESTIC,
1152
1188
  province: "a45b982a-5c7b-4bd9-8fd8-a42d0994054c",
1153
1189
  district: "5ef450bc-712d-48ad-93f3-8da0fa453baa",
1154
1190
  urbanOrRural: "URBAN",
@@ -1170,24 +1206,72 @@ function mapFieldTypeToMockValue(field2, i) {
1170
1206
  };
1171
1207
  case FieldType.FILE_WITH_OPTIONS:
1172
1208
  return null;
1209
+ case FieldType.DATA:
1210
+ return {};
1173
1211
  }
1174
1212
  }
1175
- var isParagraphFieldType = (field2) => {
1176
- return field2.config.type === FieldType.PARAGRAPH;
1177
- };
1178
- var isDateFieldType = (field2) => {
1179
- return field2.config.type === FieldType.DATE;
1180
- };
1181
- var isPageHeaderFieldType = (field2) => {
1182
- return field2.config.type === FieldType.PAGE_HEADER;
1183
- };
1184
- var isTextFieldType = (field2) => {
1185
- return field2.config.type === FieldType.TEXT;
1186
- };
1187
- var isNumberFieldType = (field2) => {
1188
- return field2.config.type === FieldType.NUMBER;
1189
- };
1190
- var isTextAreaFieldType = (field2) => {
1213
+ function mapFieldTypeToEmptyValue(field2) {
1214
+ switch (field2.type) {
1215
+ case FieldType.DIVIDER:
1216
+ case FieldType.TEXT:
1217
+ case FieldType.TEXTAREA:
1218
+ case FieldType.BULLET_LIST:
1219
+ case FieldType.PAGE_HEADER:
1220
+ case FieldType.LOCATION:
1221
+ case FieldType.SELECT:
1222
+ case FieldType.COUNTRY:
1223
+ case FieldType.RADIO_GROUP:
1224
+ case FieldType.SIGNATURE:
1225
+ case FieldType.PARAGRAPH:
1226
+ case FieldType.ADMINISTRATIVE_AREA:
1227
+ case FieldType.FACILITY:
1228
+ case FieldType.OFFICE:
1229
+ case FieldType.NUMBER:
1230
+ case FieldType.EMAIL:
1231
+ case FieldType.DATE:
1232
+ case FieldType.CHECKBOX:
1233
+ case FieldType.DATA:
1234
+ return null;
1235
+ case FieldType.ADDRESS:
1236
+ return {
1237
+ country: null,
1238
+ addressType: AddressType.DOMESTIC,
1239
+ province: null,
1240
+ district: null,
1241
+ urbanOrRural: "URBAN",
1242
+ // Default to urban needed for validation
1243
+ town: null,
1244
+ residentialArea: null,
1245
+ street: null,
1246
+ number: null,
1247
+ zipCode: null
1248
+ };
1249
+ case FieldType.FILE:
1250
+ return {
1251
+ filename: "",
1252
+ originalFilename: "",
1253
+ type: ""
1254
+ };
1255
+ case FieldType.FILE_WITH_OPTIONS:
1256
+ return [];
1257
+ }
1258
+ }
1259
+ var isParagraphFieldType = (field2) => {
1260
+ return field2.config.type === FieldType.PARAGRAPH;
1261
+ };
1262
+ var isDateFieldType = (field2) => {
1263
+ return field2.config.type === FieldType.DATE;
1264
+ };
1265
+ var isPageHeaderFieldType = (field2) => {
1266
+ return field2.config.type === FieldType.PAGE_HEADER;
1267
+ };
1268
+ var isTextFieldType = (field2) => {
1269
+ return field2.config.type === FieldType.TEXT;
1270
+ };
1271
+ var isNumberFieldType = (field2) => {
1272
+ return field2.config.type === FieldType.NUMBER;
1273
+ };
1274
+ var isTextAreaFieldType = (field2) => {
1191
1275
  return field2.config.type === FieldType.TEXTAREA;
1192
1276
  };
1193
1277
  var isSignatureFieldType = (field2) => {
@@ -1235,21 +1319,36 @@ var isFacilityFieldType = (field2) => {
1235
1319
  var isOfficeFieldType = (field2) => {
1236
1320
  return field2.config.type === FieldType.OFFICE;
1237
1321
  };
1322
+ var isDataFieldType = (field2) => {
1323
+ return field2.config.type === FieldType.DATA;
1324
+ };
1238
1325
 
1239
1326
  // ../commons/src/conditionals/validate.ts
1240
1327
  var ajv = new import_ajv.default({
1241
- $data: true
1328
+ $data: true,
1329
+ allowUnionTypes: true
1242
1330
  });
1243
1331
  (0, import_ajv_formats.default)(ajv);
1244
1332
  function validate(schema, data) {
1245
1333
  return ajv.validate(schema, data);
1246
1334
  }
1335
+ function isConditionMet(conditional, values) {
1336
+ return validate(conditional, {
1337
+ $form: values,
1338
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1339
+ });
1340
+ }
1247
1341
  function getConditionalActionsForField(field2, values) {
1248
1342
  if (!field2.conditionals) {
1249
1343
  return [];
1250
1344
  }
1251
1345
  return field2.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
1252
1346
  }
1347
+ function areConditionsMet(conditions, values) {
1348
+ return conditions.every(
1349
+ (condition) => isConditionMet(condition.conditional, values)
1350
+ );
1351
+ }
1253
1352
  function isFieldConditionMet(field2, form, conditionalType) {
1254
1353
  const hasRule = (field2.conditionals ?? []).some(
1255
1354
  (conditional) => conditional.type === conditionalType
@@ -1268,91 +1367,88 @@ function isFieldConditionMet(field2, form, conditionalType) {
1268
1367
  function isFieldVisible(field2, form) {
1269
1368
  return isFieldConditionMet(field2, form, ConditionalType.SHOW);
1270
1369
  }
1370
+ function isFieldEmptyAndNotRequired(field2, form) {
1371
+ const fieldValue = form[field2.id];
1372
+ return !field2.required && (fieldValue === void 0 || fieldValue === "");
1373
+ }
1271
1374
  function isFieldEnabled(field2, form) {
1272
1375
  return isFieldConditionMet(field2, form, ConditionalType.ENABLE);
1273
1376
  }
1274
- var zodToIntlErrorMap = (issue, _ctx) => {
1275
- if (issue.code === "invalid_string" && issue.validation === "date") {
1276
- return {
1277
- message: {
1278
- message: {
1279
- defaultMessage: "Invalid date. Please use the format YYYY-MM-DD",
1280
- description: "This is the error message for invalid date fields",
1281
- id: "v2.error.invalidDate"
1282
- }
1283
- }
1284
- };
1285
- }
1286
- if (issue.code === "invalid_string" && issue.validation === "email") {
1287
- return {
1288
- message: {
1289
- message: {
1290
- defaultMessage: "Invalid email address",
1291
- description: "This is the error message for invalid email fields",
1292
- id: "v2.error.invalidEmail"
1293
- }
1294
- }
1295
- };
1296
- }
1297
- if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined" || issue.code === "too_small" && issue.message === void 0) {
1298
- return {
1299
- message: {
1300
- message: {
1301
- defaultMessage: "Required for registration",
1302
- description: "This is the error message for required fields",
1303
- id: "v2.error.required"
1304
- }
1305
- }
1306
- };
1377
+ function isFieldDisplayedOnReview(field2, form) {
1378
+ return isFieldVisible(field2, form) && isFieldConditionMet(field2, form, ConditionalType.DISPLAY_ON_REVIEW);
1379
+ }
1380
+ var errorMessages = {
1381
+ hiddenField: {
1382
+ id: "v2.error.hidden",
1383
+ defaultMessage: "Hidden or disabled field should not receive a value",
1384
+ description: "Error message when field is hidden or disabled, but a value was received"
1385
+ },
1386
+ invalidDate: {
1387
+ defaultMessage: "Invalid date field",
1388
+ description: "Error message when date field is invalid",
1389
+ id: "v2.error.invalidDate"
1390
+ },
1391
+ invalidEmail: {
1392
+ defaultMessage: "Invalid email address",
1393
+ description: "Error message when email address is invalid",
1394
+ id: "v2.error.invalidEmail"
1395
+ },
1396
+ requiredField: {
1397
+ defaultMessage: "Required for registration",
1398
+ description: "Error message when required field is missing",
1399
+ id: "v2.error.required"
1400
+ },
1401
+ invalidInput: {
1402
+ defaultMessage: "Invalid input",
1403
+ description: "Error message when generic field is invalid",
1404
+ id: "v2.error.invalid"
1307
1405
  }
1406
+ };
1407
+ function createIntlError(message) {
1308
1408
  return {
1309
1409
  message: {
1310
- message: {
1311
- defaultMessage: "Invalid input",
1312
- description: "This is the error message for invalid field value",
1313
- id: "v2.error.invalid"
1314
- }
1410
+ message
1315
1411
  }
1316
1412
  };
1317
- };
1318
- function getFieldValidationErrors({
1319
- field: field2,
1320
- values
1321
- }) {
1322
- const conditionalParameters = {
1323
- $form: values,
1324
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1325
- };
1326
- if (!isFieldVisible(field2, values) || !isFieldEnabled(field2, values)) {
1327
- if (values[field2.id]) {
1328
- return {
1329
- errors: [
1330
- {
1331
- message: {
1332
- id: "v2.error.hidden",
1333
- defaultMessage: "Hidden or disabled field should not receive a value",
1334
- description: "Error message when field is hidden or disabled, but a value was received"
1335
- }
1413
+ }
1414
+ function zodToIntlErrorMap(issue, _ctx) {
1415
+ switch (issue.code) {
1416
+ case "invalid_string": {
1417
+ if (_ctx.data === "") {
1418
+ return createIntlError(errorMessages.requiredField);
1419
+ }
1420
+ if (issue.validation === "date") {
1421
+ return createIntlError(errorMessages.invalidDate);
1422
+ }
1423
+ if (issue.validation === "email") {
1424
+ return createIntlError(errorMessages.invalidEmail);
1425
+ }
1426
+ break;
1427
+ }
1428
+ case "invalid_type": {
1429
+ if (issue.expected !== issue.received && issue.received === "undefined") {
1430
+ return createIntlError(errorMessages.requiredField);
1431
+ }
1432
+ break;
1433
+ }
1434
+ case "too_small": {
1435
+ if (issue.message === void 0) {
1436
+ return createIntlError(errorMessages.requiredField);
1437
+ }
1438
+ break;
1439
+ }
1440
+ case "invalid_union": {
1441
+ for (const { issues } of issue.unionErrors) {
1442
+ for (const e of issues) {
1443
+ if (zodToIntlErrorMap(e, _ctx).message.message.id !== "v2.error.required") {
1444
+ return createIntlError(errorMessages.invalidInput);
1336
1445
  }
1337
- ]
1338
- };
1446
+ }
1447
+ }
1448
+ return createIntlError(errorMessages.requiredField);
1339
1449
  }
1340
- return {
1341
- errors: []
1342
- };
1343
1450
  }
1344
- const fieldValidationResult = validateFieldInput({
1345
- field: field2,
1346
- value: values[field2.id]
1347
- });
1348
- const customValidationResults = runCustomFieldValidations({
1349
- field: field2,
1350
- conditionalParameters
1351
- });
1352
- return {
1353
- // Assumes that custom validation errors are more important than field validation errors
1354
- errors: [...customValidationResults, ...fieldValidationResult]
1355
- };
1451
+ return createIntlError(errorMessages.invalidInput);
1356
1452
  }
1357
1453
  function runCustomFieldValidations({
1358
1454
  field: field2,
@@ -1375,13 +1471,31 @@ function validateFieldInput({
1375
1471
  );
1376
1472
  return rawError.error?.issues.map((issue) => issue.message) ?? [];
1377
1473
  }
1378
-
1379
- // ../commons/src/utils.ts
1380
- function getOrThrow(x, message) {
1381
- if (x === void 0 || x === null) {
1382
- throw new Error(message);
1474
+ function runFieldValidations({
1475
+ field: field2,
1476
+ values
1477
+ }) {
1478
+ if (!isFieldVisible(field2, values) || isFieldEmptyAndNotRequired(field2, values)) {
1479
+ return {
1480
+ errors: []
1481
+ };
1383
1482
  }
1384
- return x;
1483
+ const conditionalParameters = {
1484
+ $form: values,
1485
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" })
1486
+ };
1487
+ const fieldValidationResult = validateFieldInput({
1488
+ field: field2,
1489
+ value: values[field2.id]
1490
+ });
1491
+ const customValidationResults = runCustomFieldValidations({
1492
+ field: field2,
1493
+ conditionalParameters
1494
+ });
1495
+ return {
1496
+ // Assumes that custom validation errors are based on the field type, and extend the validation.
1497
+ errors: [...fieldValidationResult, ...customValidationResults]
1498
+ };
1385
1499
  }
1386
1500
 
1387
1501
  // ../commons/src/uuid.ts
@@ -1390,142 +1504,91 @@ function getUUID() {
1390
1504
  return (0, import_uuid.v4)();
1391
1505
  }
1392
1506
 
1507
+ // ../commons/src/utils.ts
1508
+ function getOrThrow(x, message) {
1509
+ if (x === void 0 || x === null) {
1510
+ throw new Error(message);
1511
+ }
1512
+ return x;
1513
+ }
1514
+
1393
1515
  // ../commons/src/events/utils.ts
1394
- function isMetadataField(field2) {
1395
- return field2 in eventMetadataLabelMap;
1396
- }
1397
- var findInputPageFields = (config) => {
1398
- return (0, import_lodash.flattenDeep)(
1399
- config.actions.map(
1400
- ({ forms }) => forms.map(
1401
- ({ pages }) => pages.map(
1402
- ({ fields }) => fields.map(({ id, label }) => ({ id, label }))
1403
- )
1404
- )
1405
- )
1406
- );
1407
- };
1408
- var findPageFields = (config) => {
1409
- return (0, import_lodash.flattenDeep)(
1410
- config.actions.map((action) => {
1411
- if (action.type === ActionType.REQUEST_CORRECTION) {
1412
- return [
1413
- ...action.forms.map(({ pages }) => pages.map(({ fields }) => fields)),
1414
- ...action.onboardingForm.flatMap(({ fields }) => fields),
1415
- ...action.additionalDetailsForm.flatMap(({ fields }) => fields)
1416
- ];
1417
- }
1418
- return action.forms.map(({ pages }) => pages.map(({ fields }) => fields));
1419
- })
1420
- );
1421
- };
1422
- var resolveLabelsFromKnownFields = ({
1423
- pageFields,
1424
- refFields
1425
- }) => {
1426
- return refFields.map((field2) => {
1427
- if (field2.label) {
1428
- return field2;
1429
- }
1430
- if (isMetadataField(field2.id)) {
1431
- return {
1432
- ...field2,
1433
- label: eventMetadataLabelMap[field2.id]
1434
- };
1435
- }
1436
- const pageLabel = pageFields.find((pageField) => pageField.id === field2.id);
1437
- if (!pageLabel) {
1438
- throw new Error(`Referenced field ${field2.id} does not have a label`);
1439
- }
1440
- return {
1441
- ...field2,
1442
- label: pageLabel.label
1443
- };
1444
- });
1445
- };
1446
- function getAllFields(configuration) {
1447
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => [
1448
- ...form.review.fields,
1449
- ...form.pages.flatMap((page) => page.fields)
1450
- ]);
1516
+ function isDeclarationActionConfig(action) {
1517
+ return DeclarationActions.safeParse(action.type).success;
1451
1518
  }
1452
- function getAllPages(configuration) {
1453
- return configuration.actions.flatMap((action) => action.forms.filter((form) => form.active)).flatMap((form) => form.pages);
1519
+ function getDeclarationFields(configuration) {
1520
+ return configuration.declaration.pages.flatMap(({ fields }) => fields);
1454
1521
  }
1455
- function validateWorkqueueConfig(workqueueConfigs) {
1456
- workqueueConfigs.map((workqueue) => {
1457
- const rootWorkqueue = Object.values(workqueues).find(
1458
- (wq) => wq.id === workqueue.id
1459
- );
1460
- if (!rootWorkqueue) {
1461
- throw new Error(
1462
- `Invalid workqueue configuration: workqueue not found with id: ${workqueue.id}`
1463
- );
1464
- }
1465
- });
1522
+ function getDeclarationPages(configuration) {
1523
+ return configuration.declaration.pages;
1466
1524
  }
1467
- var findActiveActionForm = (configuration, action) => {
1468
- const actionConfig = configuration.actions.find((a) => a.type === action);
1469
- const form = actionConfig?.forms.find((f) => f.active);
1470
- return form;
1471
- };
1472
- var findActiveActionFormPages = (configuration, action) => {
1473
- return findActiveActionForm(configuration, action)?.pages;
1474
- };
1475
- var getFormFields = (formConfig) => {
1476
- return formConfig.pages.flatMap((p) => p.fields);
1477
- };
1478
- var findActiveActionFormFields = (configuration, action) => {
1479
- const form = findActiveActionForm(configuration, action);
1480
- return form ? getFormFields(form) : void 0;
1525
+ function getDeclaration(configuration) {
1526
+ return configuration.declaration;
1527
+ }
1528
+ var getActionAnnotationFields = (actionConfig) => {
1529
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1530
+ return [
1531
+ ...actionConfig.onboardingForm.flatMap(({ fields }) => fields),
1532
+ ...actionConfig.additionalDetailsForm.flatMap(({ fields }) => fields)
1533
+ ];
1534
+ }
1535
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1536
+ return actionConfig.printForm.pages.flatMap(({ fields }) => fields);
1537
+ }
1538
+ if (isDeclarationActionConfig(actionConfig)) {
1539
+ return actionConfig.review.fields;
1540
+ }
1541
+ return [];
1481
1542
  };
1482
- var findActiveActionFields = (configuration, action) => {
1483
- const form = findActiveActionForm(configuration, action);
1484
- const reviewFields = form?.review.fields;
1485
- const formFields = form ? getFormFields(form) : void 0;
1486
- const allFields = formFields ? formFields.concat(reviewFields ?? []) : reviewFields;
1487
- return allFields;
1543
+ function getAllAnnotationFields(config) {
1544
+ return (0, import_lodash.flattenDeep)(config.actions.map(getActionAnnotationFields));
1545
+ }
1546
+ var findRecordActionPages = (config, actionType) => {
1547
+ const action = config.actions.find((a) => a.type === actionType);
1548
+ if (action?.type === ActionType.REQUEST_CORRECTION) {
1549
+ return [...action.onboardingForm, ...action.additionalDetailsForm];
1550
+ }
1551
+ if (action?.type === ActionType.PRINT_CERTIFICATE) {
1552
+ return action.printForm.pages;
1553
+ }
1554
+ return [];
1488
1555
  };
1489
- var getActiveActionFormPages = (configuration, action) => {
1556
+ function getActionReview(configuration, actionType) {
1557
+ const [actionConfig] = configuration.actions.filter(
1558
+ (a) => a.type === actionType
1559
+ );
1490
1560
  return getOrThrow(
1491
- findActiveActionForm(configuration, action)?.pages,
1492
- "Form configuration not found for type: " + configuration.id
1561
+ actionConfig.review,
1562
+ `No review config found for ${actionType}`
1493
1563
  );
1494
- };
1495
- function getActiveActionFields(configuration, action) {
1496
- const fields = findActiveActionFields(configuration, action);
1497
- if (!fields) {
1498
- throw new Error(`No active field config found for action type ${action}`);
1499
- }
1500
- return fields;
1501
1564
  }
1502
- function getEventConfiguration(eventConfigurations, type) {
1503
- const config = eventConfigurations.find((config2) => config2.id === type);
1504
- if (!config) {
1505
- throw new Error(`Event configuration not found for type: ${type}`);
1506
- }
1507
- return config;
1565
+ function getActionReviewFields(configuration, actionType) {
1566
+ return getActionReview(configuration, actionType).fields;
1508
1567
  }
1509
- function isOptionalUncheckedCheckbox(field2, form) {
1510
- if (field2.type !== FieldType.CHECKBOX || field2.required) {
1511
- return false;
1568
+ function isPageVisible(page, formValues) {
1569
+ if (!page.conditional) {
1570
+ return true;
1512
1571
  }
1513
- return !form[field2.id];
1572
+ return isConditionMet(page.conditional, formValues);
1514
1573
  }
1515
- function stripHiddenFields(fields, data) {
1516
- return (0, import_lodash.omitBy)(data, (_2, fieldId) => {
1517
- const field2 = fields.find((f) => f.id === fieldId);
1518
- if (!field2) {
1519
- return true;
1574
+ function omitHiddenFields(fields, values, visibleVerificationPageIds = []) {
1575
+ return (0, import_lodash.omitBy)(values, (_, fieldId) => {
1576
+ if (visibleVerificationPageIds.includes(fieldId)) {
1577
+ return false;
1520
1578
  }
1521
- if (isOptionalUncheckedCheckbox(field2, data)) {
1579
+ const fieldConfigs = fields.filter((f) => f.id === fieldId);
1580
+ if (!fieldConfigs.length) {
1522
1581
  return true;
1523
1582
  }
1524
- return !isFieldVisible(field2, data);
1583
+ return fieldConfigs.every((f) => !isFieldVisible(f, values));
1525
1584
  });
1526
1585
  }
1586
+ function omitHiddenPaginatedFields(formConfig, declaration) {
1587
+ const visiblePagesFormFields = formConfig.pages.filter((p) => isPageVisible(p, declaration)).flatMap((p) => p.fields);
1588
+ return omitHiddenFields(visiblePagesFormFields, declaration);
1589
+ }
1527
1590
  function findActiveDrafts(event2, drafts) {
1528
- const actions = event2.actions.slice().sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1591
+ const actions = event2.actions.slice().filter(({ type }) => type !== ActionType.READ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1529
1592
  const lastAction = actions[actions.length - 1];
1530
1593
  return drafts.filter(({ createdAt }) => createdAt >= lastAction.createdAt).filter(({ eventId }) => eventId === event2.id);
1531
1594
  }
@@ -1537,28 +1600,103 @@ function createEmptyDraft(eventId, draftId, actionType) {
1537
1600
  transactionId: getUUID(),
1538
1601
  action: {
1539
1602
  type: actionType,
1540
- data: {},
1541
- metadata: {},
1603
+ declaration: {},
1604
+ annotation: {},
1542
1605
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1543
1606
  createdBy: "@todo",
1544
1607
  createdAtLocation: "@todo"
1545
1608
  }
1546
1609
  };
1547
1610
  }
1611
+ function isVerificationPage(page) {
1612
+ return page.type === PageTypes.enum.VERIFICATION;
1613
+ }
1614
+ function getVisibleVerificationPageIds(pages, annotation) {
1615
+ return pages.filter((page) => isVerificationPage(page)).filter((page) => isPageVisible(page, annotation)).map((page) => page.id);
1616
+ }
1617
+ function getActionVerificationPageIds(actionConfig, annotation) {
1618
+ if (actionConfig.type === ActionType.REQUEST_CORRECTION) {
1619
+ return [
1620
+ ...getVisibleVerificationPageIds(actionConfig.onboardingForm, annotation),
1621
+ ...getVisibleVerificationPageIds(
1622
+ actionConfig.additionalDetailsForm,
1623
+ annotation
1624
+ )
1625
+ ];
1626
+ }
1627
+ if (actionConfig.type === ActionType.PRINT_CERTIFICATE) {
1628
+ return getVisibleVerificationPageIds(
1629
+ actionConfig.printForm.pages,
1630
+ annotation
1631
+ );
1632
+ }
1633
+ return [];
1634
+ }
1635
+ function omitHiddenAnnotationFields(actionConfig, declaration, annotation) {
1636
+ const annotationFields = getActionAnnotationFields(actionConfig);
1637
+ const visibleVerificationPageIds = getActionVerificationPageIds(
1638
+ actionConfig,
1639
+ annotation
1640
+ );
1641
+ return omitHiddenFields(
1642
+ annotationFields,
1643
+ { ...declaration, ...annotation },
1644
+ visibleVerificationPageIds
1645
+ );
1646
+ }
1647
+ function deepMerge(currentDocument, actionDocument) {
1648
+ return (0, import_lodash.mergeWith)(
1649
+ currentDocument,
1650
+ actionDocument,
1651
+ (previousValue, incomingValue) => {
1652
+ if (incomingValue === void 0) {
1653
+ return previousValue;
1654
+ }
1655
+ if ((0, import_lodash.isArray)(incomingValue)) {
1656
+ return incomingValue;
1657
+ }
1658
+ if ((0, import_lodash.isObject)(previousValue) && (0, import_lodash.isObject)(incomingValue)) {
1659
+ return void 0;
1660
+ }
1661
+ return incomingValue;
1662
+ }
1663
+ );
1664
+ }
1665
+ function findLastAssignmentAction(actions) {
1666
+ return actions.filter(
1667
+ ({ type }) => type === ActionType.ASSIGN || type === ActionType.UNASSIGN
1668
+ ).reduce((latestAction, action) => !latestAction || action.createdAt > latestAction.createdAt ? action : latestAction, void 0);
1669
+ }
1670
+ function isWriteAction(actionType) {
1671
+ return writeActions.safeParse(actionType).success;
1672
+ }
1673
+ var findAllFields = (config) => {
1674
+ return (0, import_lodash.flattenDeep)([
1675
+ ...getDeclarationFields(config),
1676
+ ...getAllAnnotationFields(config)
1677
+ ]);
1678
+ };
1548
1679
 
1549
1680
  // ../commons/src/events/EventConfig.ts
1550
- var EventConfig = import_zod18.z.object({
1551
- id: import_zod18.z.string().describe(
1681
+ var import_zod_openapi3 = require("zod-openapi");
1682
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod16.z);
1683
+ var EventConfig = import_zod16.z.object({
1684
+ id: import_zod16.z.string().describe(
1552
1685
  'A machine-readable identifier for the event, e.g. "birth" or "death"'
1553
1686
  ),
1687
+ dateOfEvent: import_zod16.z.object({ fieldId: import_zod16.z.string() }).optional(),
1688
+ title: TranslationConfig,
1689
+ fallbackTitle: TranslationConfig.optional().describe(
1690
+ "This is a fallback title if actual title resolves to empty string"
1691
+ ),
1554
1692
  summary: SummaryConfig,
1555
1693
  label: TranslationConfig,
1556
- actions: import_zod18.z.array(ActionConfig),
1557
- workqueues: import_zod18.z.array(WorkqueueConfig),
1558
- deduplication: import_zod18.z.array(DeduplicationConfig).optional().default([]),
1559
- advancedSearch: import_zod18.z.array(AdvancedSearchConfig).optional().default([])
1694
+ actions: import_zod16.z.array(ActionConfig),
1695
+ declaration: DeclarationFormConfig,
1696
+ deduplication: import_zod16.z.array(DeduplicationConfig).optional().default([]),
1697
+ advancedSearch: import_zod16.z.array(AdvancedSearchConfig).optional().default([])
1560
1698
  }).superRefine((event2, ctx) => {
1561
- const allFields = findPageFields(event2);
1699
+ const allFields = findAllFields(event2);
1562
1700
  const fieldIds = allFields.map((field2) => field2.id);
1563
1701
  const advancedSearchFields = event2.advancedSearch.flatMap(
1564
1702
  (section) => section.fields.flatMap((field2) => field2.fieldId)
@@ -1572,287 +1710,497 @@ var EventConfig = import_zod18.z.object({
1572
1710
  });
1573
1711
  }
1574
1712
  const invalidFields = event2.advancedSearch.flatMap(
1575
- (section) => section.fields.filter((field2) => !fieldIds.includes(field2.fieldId))
1713
+ (section) => (
1714
+ // Check if the fieldId is not in the fieldIds array
1715
+ // and also not in the metadataFields array
1716
+ section.fields.filter(
1717
+ (field2) => !(fieldIds.includes(field2.fieldId) || EventFieldId.options.includes(field2.fieldId))
1718
+ )
1719
+ )
1576
1720
  );
1577
1721
  if (invalidFields.length > 0) {
1578
1722
  ctx.addIssue({
1579
1723
  code: "custom",
1580
- message: `Advanced search id must match a field id in fields array.
1724
+ message: `Advanced search id must match a field id of form fields or pre-defined metadata fields.
1581
1725
  Invalid AdvancedSearch field IDs for event ${event2.id}: ${invalidFields.map((f) => f.fieldId).join(", ")}`,
1582
1726
  path: ["advancedSearch"]
1583
1727
  });
1584
1728
  }
1729
+ if (event2.dateOfEvent) {
1730
+ const eventDateFieldId = getDeclarationFields(event2).find(
1731
+ ({ id }) => id === event2.dateOfEvent?.fieldId
1732
+ );
1733
+ if (!eventDateFieldId) {
1734
+ ctx.addIssue({
1735
+ code: "custom",
1736
+ message: `Date of event field id must match a field id in fields array.
1737
+ Invalid date of event field ID for event ${event2.id}: ${event2.dateOfEvent.fieldId}`,
1738
+ path: ["dateOfEvent"]
1739
+ });
1740
+ } else if (eventDateFieldId.type !== FieldType.DATE) {
1741
+ ctx.addIssue({
1742
+ code: "custom",
1743
+ message: `Field specified for date of event is of type: ${eventDateFieldId.type}, but it needs to be of type: ${FieldType.DATE}`,
1744
+ path: ["dateOfEvent.fieldType"]
1745
+ });
1746
+ }
1747
+ }
1748
+ }).openapi({
1749
+ ref: "EventConfig"
1585
1750
  });
1586
1751
 
1587
1752
  // ../commons/src/events/EventConfigInput.ts
1588
- var defineForm = (form) => FormConfig.parse(form);
1589
- var defineFormPage = (formPage) => FormPage.parse(formPage);
1753
+ var defineDeclarationForm = (form) => DeclarationFormConfig.parse(form);
1754
+ var defineActionForm = (actionForm) => ActionFormConfig.parse(actionForm);
1755
+ var definePage = (page) => PageConfig.parse(page);
1756
+ var defineFormPage = (formPage) => FormPageConfig.parse(formPage);
1757
+
1758
+ // ../commons/src/events/WorkqueueConfig.ts
1759
+ var import_zod17 = require("zod");
1760
+ var WorkqueueConfig = import_zod17.z.object({
1761
+ slug: import_zod17.z.string().describe("Determines the url of the workqueue."),
1762
+ name: TranslationConfig.describe(
1763
+ "Title of the workflow (both in navigation and on the page)"
1764
+ ),
1765
+ /**
1766
+ * Placeholder untill the following gets merged to develop
1767
+ * https://github.com/opencrvs/opencrvs-core/blob/5fbe9854a88504a7a13fcc856b3e82594b70c38c/packages/commons/src/events/EventIndex.ts#L92-L93
1768
+ */
1769
+ query: import_zod17.z.string(),
1770
+ actions: import_zod17.z.array(
1771
+ import_zod17.z.object({
1772
+ type: import_zod17.z.string(),
1773
+ conditionals: import_zod17.z.array(Conditional).optional()
1774
+ })
1775
+ )
1776
+ }).describe("Configuration for workqueue.");
1777
+ function defineWorkqueue(workqueues) {
1778
+ return workqueues.map((workqueue) => WorkqueueConfig.parse(workqueue));
1779
+ }
1590
1780
 
1591
1781
  // ../commons/src/events/Draft.ts
1592
- var import_zod21 = require("zod");
1782
+ var import_zod20 = require("zod");
1593
1783
 
1594
1784
  // ../commons/src/events/ActionDocument.ts
1595
- var import_zod19 = require("zod");
1596
- var ActionUpdate = import_zod19.z.record(import_zod19.z.string(), FieldUpdateValue);
1597
- var ActionBase = import_zod19.z.object({
1598
- id: import_zod19.z.string(),
1599
- createdAt: import_zod19.z.string().datetime(),
1600
- createdBy: import_zod19.z.string(),
1601
- data: ActionUpdate,
1602
- metadata: ActionUpdate.optional(),
1603
- createdAtLocation: import_zod19.z.string()
1785
+ var import_zod18 = require("zod");
1786
+ var import_zod_openapi4 = require("zod-openapi");
1787
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod18.z);
1788
+ var ActionUpdate = import_zod18.z.record(import_zod18.z.string(), FieldUpdateValue);
1789
+ var ActionStatus = {
1790
+ Requested: "Requested",
1791
+ Accepted: "Accepted",
1792
+ Rejected: "Rejected"
1793
+ };
1794
+ var ActionBase = import_zod18.z.object({
1795
+ id: import_zod18.z.string(),
1796
+ transactionId: import_zod18.z.string(),
1797
+ createdAt: import_zod18.z.string().datetime(),
1798
+ createdBy: import_zod18.z.string(),
1799
+ createdByRole: import_zod18.z.string(),
1800
+ declaration: ActionUpdate,
1801
+ annotation: ActionUpdate.optional(),
1802
+ createdAtLocation: import_zod18.z.string().optional(),
1803
+ updatedAtLocation: import_zod18.z.string().optional(),
1804
+ status: import_zod18.z.enum([
1805
+ ActionStatus.Requested,
1806
+ ActionStatus.Accepted,
1807
+ ActionStatus.Rejected
1808
+ ]),
1809
+ // If the action is an asynchronous confirmation for another action, we will save the original action id here.
1810
+ originalActionId: import_zod18.z.string().optional()
1604
1811
  });
1605
1812
  var AssignedAction = ActionBase.merge(
1606
- import_zod19.z.object({
1607
- type: import_zod19.z.literal(ActionType.ASSIGN),
1608
- assignedTo: import_zod19.z.string()
1813
+ import_zod18.z.object({
1814
+ type: import_zod18.z.literal(ActionType.ASSIGN),
1815
+ assignedTo: import_zod18.z.string()
1609
1816
  })
1610
1817
  );
1611
1818
  var UnassignedAction = ActionBase.merge(
1612
- import_zod19.z.object({
1613
- type: import_zod19.z.literal(ActionType.UNASSIGN)
1819
+ import_zod18.z.object({
1820
+ type: import_zod18.z.literal(ActionType.UNASSIGN),
1821
+ assignedTo: import_zod18.z.literal(null)
1614
1822
  })
1615
1823
  );
1616
1824
  var RegisterAction = ActionBase.merge(
1617
- import_zod19.z.object({
1618
- type: import_zod19.z.literal(ActionType.REGISTER),
1619
- identifiers: import_zod19.z.object({
1620
- trackingId: import_zod19.z.string(),
1621
- registrationNumber: import_zod19.z.string()
1622
- })
1825
+ import_zod18.z.object({
1826
+ type: import_zod18.z.literal(ActionType.REGISTER),
1827
+ registrationNumber: import_zod18.z.string().optional()
1623
1828
  })
1624
1829
  );
1625
1830
  var DeclareAction = ActionBase.merge(
1626
- import_zod19.z.object({
1627
- type: import_zod19.z.literal(ActionType.DECLARE)
1831
+ import_zod18.z.object({
1832
+ type: import_zod18.z.literal(ActionType.DECLARE)
1628
1833
  })
1629
1834
  );
1630
1835
  var ValidateAction = ActionBase.merge(
1631
- import_zod19.z.object({
1632
- type: import_zod19.z.literal(ActionType.VALIDATE)
1836
+ import_zod18.z.object({
1837
+ type: import_zod18.z.literal(ActionType.VALIDATE)
1633
1838
  })
1634
1839
  );
1635
1840
  var RejectAction = ActionBase.merge(
1636
- import_zod19.z.object({
1637
- type: import_zod19.z.literal(ActionType.REJECT)
1841
+ import_zod18.z.object({
1842
+ type: import_zod18.z.literal(ActionType.REJECT)
1638
1843
  })
1639
1844
  );
1640
1845
  var MarkAsDuplicateAction = ActionBase.merge(
1641
- import_zod19.z.object({
1642
- type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE)
1846
+ import_zod18.z.object({
1847
+ type: import_zod18.z.literal(ActionType.MARKED_AS_DUPLICATE)
1643
1848
  })
1644
1849
  );
1645
1850
  var ArchiveAction = ActionBase.merge(
1646
- import_zod19.z.object({
1647
- type: import_zod19.z.literal(ActionType.ARCHIVE)
1851
+ import_zod18.z.object({
1852
+ type: import_zod18.z.literal(ActionType.ARCHIVE)
1648
1853
  })
1649
1854
  );
1650
1855
  var CreatedAction = ActionBase.merge(
1651
- import_zod19.z.object({
1652
- type: import_zod19.z.literal(ActionType.CREATE)
1856
+ import_zod18.z.object({
1857
+ type: import_zod18.z.literal(ActionType.CREATE)
1653
1858
  })
1654
1859
  );
1655
1860
  var NotifiedAction = ActionBase.merge(
1656
- import_zod19.z.object({
1657
- type: import_zod19.z.literal(ActionType.NOTIFY)
1861
+ import_zod18.z.object({
1862
+ type: import_zod18.z.literal(ActionType.NOTIFY)
1658
1863
  })
1659
1864
  );
1660
1865
  var PrintCertificateAction = ActionBase.merge(
1661
- import_zod19.z.object({
1662
- type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
1866
+ import_zod18.z.object({
1867
+ type: import_zod18.z.literal(ActionType.PRINT_CERTIFICATE)
1663
1868
  })
1664
1869
  );
1665
1870
  var RequestedCorrectionAction = ActionBase.merge(
1666
- import_zod19.z.object({
1667
- type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION)
1871
+ import_zod18.z.object({
1872
+ type: import_zod18.z.literal(ActionType.REQUEST_CORRECTION)
1668
1873
  })
1669
1874
  );
1670
1875
  var ApprovedCorrectionAction = ActionBase.merge(
1671
- import_zod19.z.object({
1672
- type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
1673
- requestId: import_zod19.z.string()
1876
+ import_zod18.z.object({
1877
+ type: import_zod18.z.literal(ActionType.APPROVE_CORRECTION),
1878
+ requestId: import_zod18.z.string()
1674
1879
  })
1675
1880
  );
1676
1881
  var RejectedCorrectionAction = ActionBase.merge(
1677
- import_zod19.z.object({
1678
- type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
1679
- requestId: import_zod19.z.string()
1882
+ import_zod18.z.object({
1883
+ type: import_zod18.z.literal(ActionType.REJECT_CORRECTION),
1884
+ requestId: import_zod18.z.string()
1680
1885
  })
1681
1886
  );
1682
- var CustomAction = ActionBase.merge(
1683
- import_zod19.z.object({
1684
- type: import_zod19.z.literal(ActionType.CUSTOM)
1887
+ var ReadAction = ActionBase.merge(
1888
+ import_zod18.z.object({
1889
+ type: import_zod18.z.literal(ActionType.READ)
1685
1890
  })
1686
1891
  );
1687
- var ActionDocument = import_zod19.z.discriminatedUnion("type", [
1688
- CreatedAction,
1689
- ValidateAction,
1690
- RejectAction,
1691
- MarkAsDuplicateAction,
1692
- ArchiveAction,
1693
- NotifiedAction,
1694
- RegisterAction,
1695
- DeclareAction,
1696
- AssignedAction,
1697
- RequestedCorrectionAction,
1698
- ApprovedCorrectionAction,
1699
- RejectedCorrectionAction,
1700
- UnassignedAction,
1701
- PrintCertificateAction,
1702
- CustomAction
1703
- ]);
1704
- var ResolvedUser = import_zod19.z.object({
1705
- id: import_zod19.z.string(),
1706
- role: import_zod19.z.string(),
1707
- name: import_zod19.z.array(
1708
- import_zod19.z.object({
1709
- use: import_zod19.z.string(),
1710
- given: import_zod19.z.array(import_zod19.z.string()),
1711
- family: import_zod19.z.string()
1892
+ var ActionDocument = import_zod18.z.discriminatedUnion("type", [
1893
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1894
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1895
+ RejectAction.openapi({ ref: "RejectAction" }),
1896
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1897
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1898
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1899
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1900
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1901
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1902
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1903
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1904
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1905
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1906
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1907
+ ReadAction.openapi({ ref: "ReadAction" })
1908
+ ]).openapi({
1909
+ ref: "ActionDocument"
1910
+ });
1911
+ var AsyncRejectActionDocument = ActionBase.omit({
1912
+ declaration: true,
1913
+ annotation: true,
1914
+ createdBy: true,
1915
+ createdByRole: true,
1916
+ createdAtLocation: true
1917
+ }).merge(
1918
+ import_zod18.z.object({
1919
+ type: import_zod18.z.enum(ConfirmableActions),
1920
+ status: import_zod18.z.literal(ActionStatus.Rejected)
1921
+ })
1922
+ );
1923
+ var Action = import_zod18.z.union([ActionDocument, AsyncRejectActionDocument]);
1924
+ var ResolvedUser = import_zod18.z.object({
1925
+ id: import_zod18.z.string(),
1926
+ role: import_zod18.z.string(),
1927
+ name: import_zod18.z.array(
1928
+ import_zod18.z.object({
1929
+ use: import_zod18.z.string(),
1930
+ given: import_zod18.z.array(import_zod18.z.string()),
1931
+ family: import_zod18.z.string()
1712
1932
  })
1713
1933
  )
1714
1934
  });
1715
1935
 
1716
1936
  // ../commons/src/events/ActionInput.ts
1717
- var import_zod20 = require("zod");
1718
- var BaseActionInput = import_zod20.z.object({
1719
- eventId: import_zod20.z.string(),
1720
- transactionId: import_zod20.z.string(),
1721
- data: ActionUpdate,
1722
- metadata: ActionUpdate.optional()
1937
+ var import_zod19 = require("zod");
1938
+ var import_zod_openapi5 = require("zod-openapi");
1939
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod19.z);
1940
+ var BaseActionInput = import_zod19.z.object({
1941
+ eventId: import_zod19.z.string(),
1942
+ transactionId: import_zod19.z.string(),
1943
+ declaration: ActionUpdate.default({}),
1944
+ annotation: ActionUpdate.optional(),
1945
+ originalActionId: import_zod19.z.string().optional(),
1946
+ keepAssignment: import_zod19.z.boolean().optional()
1723
1947
  });
1724
1948
  var CreateActionInput = BaseActionInput.merge(
1725
- import_zod20.z.object({
1726
- type: import_zod20.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1727
- createdAtLocation: import_zod20.z.string()
1949
+ import_zod19.z.object({
1950
+ type: import_zod19.z.literal(ActionType.CREATE).default(ActionType.CREATE),
1951
+ createdAtLocation: import_zod19.z.string()
1728
1952
  })
1729
1953
  );
1730
1954
  var RegisterActionInput = BaseActionInput.merge(
1731
- import_zod20.z.object({
1732
- type: import_zod20.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1733
- identifiers: import_zod20.z.object({
1734
- trackingId: import_zod20.z.string(),
1735
- registrationNumber: import_zod20.z.string()
1736
- })
1955
+ import_zod19.z.object({
1956
+ type: import_zod19.z.literal(ActionType.REGISTER).default(ActionType.REGISTER),
1957
+ registrationNumber: import_zod19.z.string().optional()
1737
1958
  })
1738
1959
  );
1739
1960
  var ValidateActionInput = BaseActionInput.merge(
1740
- import_zod20.z.object({
1741
- type: import_zod20.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1742
- duplicates: import_zod20.z.array(import_zod20.z.string())
1961
+ import_zod19.z.object({
1962
+ type: import_zod19.z.literal(ActionType.VALIDATE).default(ActionType.VALIDATE),
1963
+ duplicates: import_zod19.z.array(import_zod19.z.string())
1743
1964
  })
1744
1965
  );
1745
1966
  var NotifyActionInput = BaseActionInput.merge(
1746
- import_zod20.z.object({
1747
- type: import_zod20.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1967
+ import_zod19.z.object({
1968
+ type: import_zod19.z.literal(ActionType.NOTIFY).default(ActionType.NOTIFY)
1748
1969
  })
1749
1970
  );
1750
1971
  var DeclareActionInput = BaseActionInput.merge(
1751
- import_zod20.z.object({
1752
- type: import_zod20.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1972
+ import_zod19.z.object({
1973
+ type: import_zod19.z.literal(ActionType.DECLARE).default(ActionType.DECLARE)
1753
1974
  })
1754
1975
  );
1755
1976
  var PrintCertificateActionInput = BaseActionInput.merge(
1756
- import_zod20.z.object({
1757
- type: import_zod20.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1977
+ import_zod19.z.object({
1978
+ type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
1758
1979
  })
1759
1980
  );
1760
1981
  var RejectDeclarationActionInput = BaseActionInput.merge(
1761
- import_zod20.z.object({
1762
- type: import_zod20.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1982
+ import_zod19.z.object({
1983
+ type: import_zod19.z.literal(ActionType.REJECT).default(ActionType.REJECT)
1763
1984
  })
1764
1985
  );
1765
1986
  var MarkedAsDuplicateActionInput = BaseActionInput.merge(
1766
- import_zod20.z.object({
1767
- type: import_zod20.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1987
+ import_zod19.z.object({
1988
+ type: import_zod19.z.literal(ActionType.MARKED_AS_DUPLICATE).default(ActionType.MARKED_AS_DUPLICATE)
1768
1989
  })
1769
1990
  );
1770
1991
  var ArchiveActionInput = BaseActionInput.merge(
1771
- import_zod20.z.object({
1772
- type: import_zod20.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1992
+ import_zod19.z.object({
1993
+ type: import_zod19.z.literal(ActionType.ARCHIVE).default(ActionType.ARCHIVE)
1773
1994
  })
1774
1995
  );
1775
1996
  var AssignActionInput = BaseActionInput.merge(
1776
- import_zod20.z.object({
1777
- type: import_zod20.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1778
- assignedTo: import_zod20.z.string()
1997
+ import_zod19.z.object({
1998
+ type: import_zod19.z.literal(ActionType.ASSIGN).default(ActionType.ASSIGN),
1999
+ assignedTo: import_zod19.z.string()
1779
2000
  })
1780
2001
  );
1781
2002
  var UnassignActionInput = BaseActionInput.merge(
1782
- import_zod20.z.object({
1783
- type: import_zod20.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN)
2003
+ import_zod19.z.object({
2004
+ type: import_zod19.z.literal(ActionType.UNASSIGN).default(ActionType.UNASSIGN),
2005
+ assignedTo: import_zod19.z.literal(null).default(null)
1784
2006
  })
1785
2007
  );
1786
2008
  var RequestCorrectionActionInput = BaseActionInput.merge(
1787
- import_zod20.z.object({
1788
- type: import_zod20.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
2009
+ import_zod19.z.object({
2010
+ type: import_zod19.z.literal(ActionType.REQUEST_CORRECTION).default(ActionType.REQUEST_CORRECTION)
1789
2011
  })
1790
2012
  );
1791
2013
  var RejectCorrectionActionInput = BaseActionInput.merge(
1792
- import_zod20.z.object({
1793
- requestId: import_zod20.z.string(),
1794
- type: import_zod20.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
2014
+ import_zod19.z.object({
2015
+ requestId: import_zod19.z.string(),
2016
+ type: import_zod19.z.literal(ActionType.REJECT_CORRECTION).default(ActionType.REJECT_CORRECTION)
1795
2017
  })
1796
2018
  );
1797
2019
  var ApproveCorrectionActionInput = BaseActionInput.merge(
1798
- import_zod20.z.object({
1799
- requestId: import_zod20.z.string(),
1800
- type: import_zod20.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
2020
+ import_zod19.z.object({
2021
+ requestId: import_zod19.z.string(),
2022
+ type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION).default(ActionType.APPROVE_CORRECTION)
1801
2023
  })
1802
2024
  );
1803
- var ActionInput = import_zod20.z.discriminatedUnion("type", [
1804
- CreateActionInput,
1805
- ValidateActionInput,
1806
- RegisterActionInput,
1807
- NotifyActionInput,
1808
- DeclareActionInput,
1809
- RejectDeclarationActionInput,
1810
- MarkedAsDuplicateActionInput,
1811
- ArchiveActionInput,
1812
- AssignActionInput,
1813
- UnassignActionInput,
1814
- PrintCertificateActionInput,
1815
- RequestCorrectionActionInput,
1816
- RejectCorrectionActionInput,
1817
- ApproveCorrectionActionInput
1818
- ]);
2025
+ var ReadActionInput = BaseActionInput.merge(
2026
+ import_zod19.z.object({
2027
+ type: import_zod19.z.literal(ActionType.READ).default(ActionType.READ)
2028
+ })
2029
+ );
2030
+ var DeleteActionInput = import_zod19.z.object({ eventId: import_zod19.z.string() });
2031
+ var ActionInput = import_zod19.z.discriminatedUnion("type", [
2032
+ CreateActionInput.openapi({ ref: "CreateActionInput" }),
2033
+ ValidateActionInput.openapi({ ref: "ValidateActionInput" }),
2034
+ RegisterActionInput.openapi({ ref: "RegisterActionInput" }),
2035
+ NotifyActionInput.openapi({ ref: "NotifyActionInput" }),
2036
+ DeclareActionInput.openapi({ ref: "DeclareActionInput" }),
2037
+ RejectDeclarationActionInput.openapi({
2038
+ ref: "RejectDeclarationActionInput"
2039
+ }),
2040
+ MarkedAsDuplicateActionInput.openapi({
2041
+ ref: "MarkedAsDuplicateActionInput"
2042
+ }),
2043
+ ArchiveActionInput.openapi({ ref: "ArchiveActionInput" }),
2044
+ AssignActionInput.openapi({ ref: "AssignActionInput" }),
2045
+ UnassignActionInput.openapi({ ref: "UnassignActionInput" }),
2046
+ PrintCertificateActionInput.openapi({ ref: "PrintCertificateActionInput" }),
2047
+ RequestCorrectionActionInput.openapi({
2048
+ ref: "RequestCorrectionActionInput"
2049
+ }),
2050
+ RejectCorrectionActionInput.openapi({ ref: "RejectCorrectionActionInput" }),
2051
+ ApproveCorrectionActionInput.openapi({
2052
+ ref: "ApproveCorrectionActionInput"
2053
+ }),
2054
+ ReadActionInput.openapi({ ref: "ReadActionInput" })
2055
+ ]).openapi({
2056
+ ref: "ActionInput"
2057
+ });
1819
2058
 
1820
2059
  // ../commons/src/events/Draft.ts
1821
- var Draft = import_zod21.z.object({
1822
- id: import_zod21.z.string(),
1823
- eventId: import_zod21.z.string(),
1824
- transactionId: import_zod21.z.string(),
1825
- createdAt: import_zod21.z.string().datetime(),
2060
+ var Draft = import_zod20.z.object({
2061
+ id: import_zod20.z.string(),
2062
+ eventId: import_zod20.z.string(),
2063
+ transactionId: import_zod20.z.string(),
2064
+ createdAt: import_zod20.z.string().datetime(),
1826
2065
  action: ActionBase.extend({
1827
- type: import_zod21.z.enum(Object.values(ActionType))
2066
+ type: ActionTypes
1828
2067
  }).omit({ id: true })
1829
2068
  });
1830
2069
  var DraftInput = BaseActionInput.extend({
1831
- type: import_zod21.z.enum(Object.values(ActionType))
2070
+ type: ActionTypes
2071
+ });
2072
+
2073
+ // ../commons/src/events/EventMetadata.ts
2074
+ var import_zod21 = require("zod");
2075
+ var EventStatus = {
2076
+ CREATED: "CREATED",
2077
+ NOTIFIED: "NOTIFIED",
2078
+ DECLARED: "DECLARED",
2079
+ VALIDATED: "VALIDATED",
2080
+ REGISTERED: "REGISTERED",
2081
+ CERTIFIED: "CERTIFIED",
2082
+ REJECTED: "REJECTED",
2083
+ ARCHIVED: "ARCHIVED"
2084
+ };
2085
+ var eventStatuses = Object.values(EventStatus);
2086
+ var EventStatuses = import_zod21.z.nativeEnum(EventStatus);
2087
+ var ZodDate = import_zod21.z.string().date();
2088
+ var EventMetadata = import_zod21.z.object({
2089
+ id: import_zod21.z.string(),
2090
+ type: import_zod21.z.string(),
2091
+ status: EventStatuses,
2092
+ createdAt: import_zod21.z.string().datetime(),
2093
+ dateOfEvent: ZodDate.nullish(),
2094
+ createdBy: import_zod21.z.string(),
2095
+ updatedByUserRole: import_zod21.z.string(),
2096
+ createdAtLocation: import_zod21.z.string(),
2097
+ updatedAtLocation: import_zod21.z.string(),
2098
+ updatedAt: import_zod21.z.string().datetime(),
2099
+ assignedTo: import_zod21.z.string().nullish(),
2100
+ updatedBy: import_zod21.z.string(),
2101
+ trackingId: import_zod21.z.string(),
2102
+ registrationNumber: import_zod21.z.string().nullish()
1832
2103
  });
2104
+ var eventMetadataLabelMap = {
2105
+ "event.assignedTo": {
2106
+ id: "event.assignedTo.label",
2107
+ defaultMessage: "Assigned To",
2108
+ description: "Assigned To"
2109
+ },
2110
+ "event.createdAt": {
2111
+ id: "event.createdAt.label",
2112
+ defaultMessage: "Created",
2113
+ description: "Created At"
2114
+ },
2115
+ "event.dateOfEvent": {
2116
+ id: "event.dateOfEvent.label",
2117
+ defaultMessage: "Date of Event",
2118
+ description: "Date of Event"
2119
+ },
2120
+ "event.createdAtLocation": {
2121
+ id: "event.createdAtLocation.label",
2122
+ defaultMessage: "Location",
2123
+ description: "Created At Location"
2124
+ },
2125
+ "event.updatedAtLocation": {
2126
+ id: "event.updatedAtLocation.label",
2127
+ defaultMessage: "Location",
2128
+ description: "Updated At Location"
2129
+ },
2130
+ "event.createdBy": {
2131
+ id: "event.createdBy.label",
2132
+ defaultMessage: "Created By",
2133
+ description: "Created By"
2134
+ },
2135
+ "event.updatedByUserRole": {
2136
+ id: "event.updatedByUserRole.label",
2137
+ defaultMessage: "Updated By Role",
2138
+ description: "Updated By Role"
2139
+ },
2140
+ "event.id": {
2141
+ id: "event.id.label",
2142
+ defaultMessage: "ID",
2143
+ description: "ID"
2144
+ },
2145
+ "event.updatedAt": {
2146
+ id: "event.modifiedAt.label",
2147
+ defaultMessage: "Updated",
2148
+ description: "Modified At"
2149
+ },
2150
+ "event.status": {
2151
+ id: "event.status.label",
2152
+ defaultMessage: "Status",
2153
+ description: "Status"
2154
+ },
2155
+ "event.type": {
2156
+ id: "event.type.label",
2157
+ defaultMessage: "Type",
2158
+ description: "Type"
2159
+ },
2160
+ "event.updatedBy": {
2161
+ id: "event.updatedBy.label",
2162
+ defaultMessage: "Updated By",
2163
+ description: "Updated By"
2164
+ },
2165
+ "event.trackingId": {
2166
+ id: "event.trackingId.label",
2167
+ defaultMessage: "Tracking ID",
2168
+ description: "Tracking ID"
2169
+ },
2170
+ "event.registrationNumber": {
2171
+ id: "event.registrationNumber.label",
2172
+ defaultMessage: "Registration Number",
2173
+ description: "Registration Number"
2174
+ }
2175
+ };
1833
2176
 
1834
2177
  // ../commons/src/events/EventInput.ts
1835
2178
  var import_zod22 = require("zod");
1836
2179
  var EventInput = import_zod22.z.object({
1837
2180
  transactionId: import_zod22.z.string(),
1838
- type: import_zod22.z.string()
2181
+ type: import_zod22.z.string(),
2182
+ dateOfEvent: import_zod22.z.object({ fieldId: import_zod22.z.string() }).optional()
1839
2183
  });
1840
2184
 
1841
2185
  // ../commons/src/events/EventDocument.ts
1842
2186
  var import_zod23 = require("zod");
2187
+ var import_zod_openapi6 = require("zod-openapi");
2188
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod23.z);
1843
2189
  var EventDocument = import_zod23.z.object({
1844
2190
  id: import_zod23.z.string(),
1845
2191
  type: import_zod23.z.string(),
2192
+ dateOfEvent: import_zod23.z.object({ fieldId: import_zod23.z.string() }).optional(),
1846
2193
  createdAt: import_zod23.z.string().datetime(),
1847
2194
  updatedAt: import_zod23.z.string().datetime(),
1848
- actions: import_zod23.z.array(ActionDocument),
2195
+ updatedAtLocation: import_zod23.z.string(),
2196
+ actions: import_zod23.z.array(Action),
1849
2197
  trackingId: import_zod23.z.string()
1850
- });
2198
+ }).openapi({ ref: "EventDocument" });
1851
2199
 
1852
2200
  // ../commons/src/events/EventIndex.ts
1853
2201
  var import_zod24 = require("zod");
1854
2202
  var EventIndex = EventMetadata.extend({
1855
- data: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
2203
+ declaration: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any())
1856
2204
  });
1857
2205
  var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.any()).and(
1858
2206
  import_zod24.z.object({
@@ -1860,35 +2208,94 @@ var EventSearchIndex = import_zod24.z.record(import_zod24.z.string(), import_zod
1860
2208
  // Ensures "type" (event-id) exists and is a string
1861
2209
  })
1862
2210
  );
2211
+ var Fuzzy = import_zod24.z.object({ type: import_zod24.z.literal("fuzzy"), term: import_zod24.z.string() });
2212
+ var Exact = import_zod24.z.object({ type: import_zod24.z.literal("exact"), term: import_zod24.z.string() });
2213
+ var AnyOf = import_zod24.z.object({
2214
+ type: import_zod24.z.literal("anyOf"),
2215
+ terms: import_zod24.z.array(import_zod24.z.string())
2216
+ });
2217
+ var Range = import_zod24.z.object({
2218
+ type: import_zod24.z.literal("range"),
2219
+ gte: import_zod24.z.string(),
2220
+ lte: import_zod24.z.string()
2221
+ });
2222
+ var Within = import_zod24.z.object({ type: import_zod24.z.literal("within"), location: import_zod24.z.string() });
2223
+ var DateCondition = import_zod24.z.union([Exact, Range]);
2224
+ var QueryInput = import_zod24.z.lazy(
2225
+ () => import_zod24.z.union([
2226
+ import_zod24.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf]),
2227
+ import_zod24.z.record(import_zod24.z.string(), QueryInput)
2228
+ ])
2229
+ );
2230
+ var QueryExpression = import_zod24.z.object({
2231
+ type: import_zod24.z.literal("and"),
2232
+ eventType: import_zod24.z.string(),
2233
+ status: import_zod24.z.optional(import_zod24.z.union([AnyOf, Exact])),
2234
+ createdAt: import_zod24.z.optional(DateCondition),
2235
+ updatedAt: import_zod24.z.optional(DateCondition),
2236
+ createAtLocation: import_zod24.z.optional(import_zod24.z.union([Within, Exact])),
2237
+ updatedAtLocation: import_zod24.z.optional(import_zod24.z.union([Within, Exact])),
2238
+ createdBy: import_zod24.z.optional(Exact),
2239
+ updatedBy: import_zod24.z.optional(Exact),
2240
+ trackingId: import_zod24.z.optional(Exact),
2241
+ data: QueryInput
2242
+ }).partial();
2243
+ var Or2 = import_zod24.z.object({
2244
+ type: import_zod24.z.literal("or"),
2245
+ clauses: import_zod24.z.array(QueryExpression)
2246
+ });
2247
+ var QueryType = import_zod24.z.discriminatedUnion("type", [QueryExpression, Or2]);
1863
2248
 
1864
2249
  // ../commons/src/events/state/index.ts
1865
- var _ = __toESM(require("lodash"));
1866
2250
  function getStatusFromActions(actions) {
2251
+ const hasRejectedAction = actions.some(
2252
+ (a) => a.status === ActionStatus.Rejected
2253
+ );
2254
+ if (hasRejectedAction) {
2255
+ return EventStatus.REJECTED;
2256
+ }
1867
2257
  return actions.reduce((status, action) => {
1868
- if (action.type === ActionType.CREATE) {
1869
- return EventStatus.CREATED;
1870
- }
1871
- if (action.type === ActionType.DECLARE) {
1872
- return EventStatus.DECLARED;
1873
- }
1874
- if (action.type === ActionType.VALIDATE) {
1875
- return EventStatus.VALIDATED;
1876
- }
1877
- if (action.type === ActionType.REGISTER) {
1878
- return EventStatus.REGISTERED;
1879
- }
1880
- if (action.type === ActionType.REJECT) {
1881
- return EventStatus.REJECTED;
1882
- }
1883
- if (action.type === ActionType.ARCHIVE) {
1884
- return EventStatus.ARCHIVED;
1885
- }
1886
- if (action.type === ActionType.NOTIFY) {
1887
- return EventStatus.NOTIFIED;
2258
+ switch (action.type) {
2259
+ case ActionType.CREATE:
2260
+ return EventStatus.CREATED;
2261
+ case ActionType.DECLARE:
2262
+ return EventStatus.DECLARED;
2263
+ case ActionType.VALIDATE:
2264
+ return EventStatus.VALIDATED;
2265
+ case ActionType.REGISTER:
2266
+ return EventStatus.REGISTERED;
2267
+ case ActionType.REJECT:
2268
+ return EventStatus.REJECTED;
2269
+ case ActionType.ARCHIVE:
2270
+ return EventStatus.ARCHIVED;
2271
+ case ActionType.NOTIFY:
2272
+ return EventStatus.NOTIFIED;
2273
+ case ActionType.PRINT_CERTIFICATE:
2274
+ return EventStatus.CERTIFIED;
2275
+ case ActionType.ASSIGN:
2276
+ case ActionType.UNASSIGN:
2277
+ case ActionType.REQUEST_CORRECTION:
2278
+ case ActionType.APPROVE_CORRECTION:
2279
+ case ActionType.MARKED_AS_DUPLICATE:
2280
+ case ActionType.REJECT_CORRECTION:
2281
+ case ActionType.READ:
2282
+ default:
2283
+ return status;
1888
2284
  }
1889
- return status;
1890
2285
  }, EventStatus.CREATED);
1891
2286
  }
2287
+ function getLastUpdatedByUserRoleFromActions(actions) {
2288
+ const actionsWithRoles = actions.filter(
2289
+ (action) => !isWriteAction(action.type) && action.status !== ActionStatus.Rejected
2290
+ ).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2291
+ const lastAction = actionsWithRoles.at(-1);
2292
+ if (!lastAction) {
2293
+ throw new Error(
2294
+ "Should never happen, at least CREATE action should be present"
2295
+ );
2296
+ }
2297
+ return ActionDocument.parse(lastAction).createdByRole;
2298
+ }
1892
2299
  function getAssignedUserFromActions(actions) {
1893
2300
  return actions.reduce((user2, action) => {
1894
2301
  if (action.type === ActionType.ASSIGN) {
@@ -1900,7 +2307,7 @@ function getAssignedUserFromActions(actions) {
1900
2307
  return user2;
1901
2308
  }, null);
1902
2309
  }
1903
- function getData(actions) {
2310
+ function aggregateActionDeclarations(actions) {
1904
2311
  const excludedActions = [
1905
2312
  ActionType.REQUEST_CORRECTION,
1906
2313
  ActionType.PRINT_CERTIFICATE
@@ -1914,47 +2321,35 @@ function getData(actions) {
1914
2321
  if (!requestAction) {
1915
2322
  return status;
1916
2323
  }
1917
- return deepMerge(status, requestAction.data);
2324
+ return deepMerge(status, requestAction.declaration);
1918
2325
  }
1919
- return deepMerge(status, action.data);
2326
+ return deepMerge(status, action.declaration);
1920
2327
  }, {});
1921
2328
  }
1922
2329
  function deepDropNulls(obj) {
1923
- if (!_.isObject(obj)) return obj;
1924
- return Object.entries(obj).reduce((acc, [key, value]) => {
1925
- if (_.isObject(value)) {
1926
- value = deepDropNulls(value);
1927
- }
1928
- if (value !== null) {
1929
- return {
1930
- ...acc,
1931
- [key]: value
1932
- };
1933
- }
1934
- return acc;
1935
- }, {});
1936
- }
1937
- function deepMerge(currentDocument, actionDocument) {
1938
- return _.mergeWith(
1939
- currentDocument,
1940
- actionDocument,
1941
- (previousValue, incomingValue) => {
1942
- if (incomingValue === void 0) {
1943
- return previousValue;
1944
- }
1945
- if (_.isArray(incomingValue)) {
1946
- return incomingValue;
1947
- }
1948
- if (_.isObject(previousValue) && _.isObject(incomingValue)) {
1949
- return void 0;
2330
+ if (Array.isArray(obj)) {
2331
+ return obj.map(deepDropNulls);
2332
+ }
2333
+ if (obj !== null && typeof obj === "object") {
2334
+ return Object.entries(obj).reduce((acc, [key, value]) => {
2335
+ const cleanedValue = deepDropNulls(value);
2336
+ if (cleanedValue !== null) {
2337
+ ;
2338
+ acc[key] = cleanedValue;
1950
2339
  }
1951
- return incomingValue;
1952
- }
1953
- );
2340
+ return acc;
2341
+ }, {});
2342
+ }
2343
+ return obj;
1954
2344
  }
1955
2345
  function isUndeclaredDraft(status) {
1956
2346
  return status === EventStatus.CREATED;
1957
2347
  }
2348
+ function getAcceptedActions(event2) {
2349
+ return event2.actions.filter(
2350
+ (a) => a.status === ActionStatus.Accepted
2351
+ );
2352
+ }
1958
2353
  function getCurrentEventState(event2) {
1959
2354
  const creationAction = event2.actions.find(
1960
2355
  (action) => action.type === ActionType.CREATE
@@ -1962,19 +2357,35 @@ function getCurrentEventState(event2) {
1962
2357
  if (!creationAction) {
1963
2358
  throw new Error(`Event ${event2.id} has no creation action`);
1964
2359
  }
1965
- const latestAction = event2.actions[event2.actions.length - 1];
2360
+ const activeActions = getAcceptedActions(event2);
2361
+ const latestAction = activeActions[activeActions.length - 1];
2362
+ const registrationAction = activeActions.find(
2363
+ (a) => a.type === ActionType.REGISTER && a.status === ActionStatus.Accepted
2364
+ );
2365
+ const registrationNumber = registrationAction?.registrationNumber ?? null;
2366
+ const declaration = aggregateActionDeclarations(activeActions);
2367
+ let dateOfEvent = event2.createdAt.split("T")[0];
2368
+ if (event2.dateOfEvent) {
2369
+ const parsedDate = ZodDate.safeParse(declaration[event2.dateOfEvent.fieldId]);
2370
+ dateOfEvent = parsedDate.success ? parsedDate.data : null;
2371
+ }
1966
2372
  return deepDropNulls({
1967
2373
  id: event2.id,
1968
2374
  type: event2.type,
1969
2375
  status: getStatusFromActions(event2.actions),
1970
2376
  createdAt: event2.createdAt,
1971
2377
  createdBy: creationAction.createdBy,
1972
- createdAtLocation: creationAction.createdAtLocation,
1973
- modifiedAt: latestAction.createdAt,
1974
- assignedTo: getAssignedUserFromActions(event2.actions),
2378
+ createdAtLocation: creationAction.createdAtLocation ?? "",
2379
+ // @todo remove using empty string
2380
+ updatedAt: latestAction.createdAt,
2381
+ assignedTo: getAssignedUserFromActions(activeActions),
1975
2382
  updatedBy: latestAction.createdBy,
1976
- data: getData(event2.actions),
1977
- trackingId: event2.trackingId
2383
+ updatedAtLocation: event2.updatedAtLocation,
2384
+ declaration,
2385
+ trackingId: event2.trackingId,
2386
+ registrationNumber,
2387
+ updatedByUserRole: getLastUpdatedByUserRoleFromActions(event2.actions),
2388
+ dateOfEvent
1978
2389
  });
1979
2390
  }
1980
2391
  function getCurrentEventStateWithDrafts(event2, drafts) {
@@ -1999,45 +2410,50 @@ function getCurrentEventStateWithDrafts(event2, drafts) {
1999
2410
  return getCurrentEventState(withDrafts);
2000
2411
  }
2001
2412
  function applyDraftsToEventIndex(eventIndex, drafts) {
2002
- const indexedAt = eventIndex.modifiedAt;
2413
+ const indexedAt = eventIndex.updatedAt;
2003
2414
  const activeDrafts = drafts.filter(({ createdAt }) => new Date(createdAt) > new Date(indexedAt)).map((draft) => draft.action).sort();
2004
2415
  if (activeDrafts.length === 0) {
2005
2416
  return eventIndex;
2006
2417
  }
2007
2418
  return {
2008
2419
  ...eventIndex,
2009
- data: {
2010
- ...eventIndex.data,
2011
- ...activeDrafts[activeDrafts.length - 1].data
2420
+ declaration: {
2421
+ ...eventIndex.declaration,
2422
+ ...activeDrafts[activeDrafts.length - 1].declaration
2012
2423
  }
2013
2424
  };
2014
2425
  }
2015
- function getMetadataForAction({
2426
+ function getAnnotationFromDrafts(drafts) {
2427
+ const actions = drafts.map((draft) => draft.action);
2428
+ const annotation = actions.reduce((ann, action) => {
2429
+ return deepMerge(ann, action.annotation ?? {});
2430
+ }, {});
2431
+ return deepDropNulls(annotation);
2432
+ }
2433
+ function getActionAnnotation({
2016
2434
  event: event2,
2017
2435
  actionType,
2018
- drafts
2436
+ drafts = []
2019
2437
  }) {
2020
- const action = event2.actions.find((action2) => actionType === action2.type);
2438
+ const activeActions = getAcceptedActions(event2);
2439
+ const action = activeActions.find(
2440
+ (activeAction) => actionType === activeAction.type
2441
+ );
2021
2442
  const eventDrafts = drafts.filter((draft) => draft.eventId === event2.id);
2022
2443
  const sorted = [
2023
2444
  ...action ? [action] : [],
2024
2445
  ...eventDrafts.map((draft) => draft.action)
2025
2446
  ].sort();
2026
- const metadata = sorted.reduce((metadata2, action2) => {
2027
- return deepMerge(metadata2, action2.metadata ?? {});
2447
+ const annotation = sorted.reduce((ann, sortedAction) => {
2448
+ return deepMerge(ann, sortedAction.annotation ?? {});
2028
2449
  }, {});
2029
- return deepDropNulls(metadata);
2450
+ return deepDropNulls(annotation);
2030
2451
  }
2031
2452
 
2032
2453
  // ../commons/src/events/defineConfig.ts
2033
2454
  var defineConfig = (config) => {
2034
- validateWorkqueueConfig(config.workqueues);
2035
2455
  const input = EventConfig.parse(config);
2036
- const pageFields = findInputPageFields(input);
2037
- return EventConfig.parse({
2038
- ...input,
2039
- pageFields
2040
- });
2456
+ return input;
2041
2457
  };
2042
2458
 
2043
2459
  // ../commons/src/events/transactions.ts
@@ -2052,6 +2468,16 @@ var import_lodash2 = require("lodash");
2052
2468
  function defineConditional(schema) {
2053
2469
  return schema;
2054
2470
  }
2471
+ function defineFormConditional(schema) {
2472
+ const schemaWithForm = {
2473
+ type: "object",
2474
+ properties: {
2475
+ $form: schema
2476
+ },
2477
+ required: ["$form"]
2478
+ };
2479
+ return defineConditional(schemaWithForm);
2480
+ }
2055
2481
  function alwaysTrue() {
2056
2482
  return {};
2057
2483
  }
@@ -2076,6 +2502,9 @@ function not(condition) {
2076
2502
  required: []
2077
2503
  });
2078
2504
  }
2505
+ function never() {
2506
+ return not(alwaysTrue());
2507
+ }
2079
2508
  var user = {
2080
2509
  hasScope: (scope) => defineConditional({
2081
2510
  type: "object",
@@ -2097,95 +2526,148 @@ var user = {
2097
2526
  required: ["$user"]
2098
2527
  })
2099
2528
  };
2100
- var event = {
2101
- hasAction: (action) => defineConditional({
2529
+ function createEventConditionals() {
2530
+ return {
2531
+ /**
2532
+ * Checks if the event contains a specific action type.
2533
+ * @param action - The action type to check for.
2534
+ */
2535
+ hasAction: (action) => defineConditional({
2536
+ type: "object",
2537
+ properties: {
2538
+ $event: {
2539
+ type: "object",
2540
+ properties: {
2541
+ actions: {
2542
+ type: "array",
2543
+ contains: {
2544
+ type: "object",
2545
+ properties: {
2546
+ type: {
2547
+ const: action
2548
+ }
2549
+ },
2550
+ required: ["type"]
2551
+ }
2552
+ }
2553
+ },
2554
+ required: ["actions"]
2555
+ }
2556
+ },
2557
+ required: ["$event"]
2558
+ })
2559
+ };
2560
+ }
2561
+ function getDateFromNow(days) {
2562
+ return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2563
+ }
2564
+ function getDateRangeToFieldReference(fieldId, comparedFieldId, clause) {
2565
+ return {
2102
2566
  type: "object",
2103
2567
  properties: {
2104
- $event: {
2105
- type: "object",
2106
- properties: {
2107
- actions: {
2108
- type: "array",
2109
- contains: {
2110
- type: "object",
2111
- properties: {
2112
- type: {
2113
- const: action
2114
- }
2115
- },
2116
- required: ["type"]
2117
- }
2118
- }
2119
- },
2120
- required: ["actions"]
2121
- }
2568
+ [fieldId]: {
2569
+ type: "string",
2570
+ format: "date",
2571
+ [clause]: { $data: `1/${comparedFieldId}` }
2572
+ },
2573
+ [comparedFieldId]: { type: "string", format: "date" }
2122
2574
  },
2123
- required: ["$event"]
2124
- })
2125
- };
2126
- function field(fieldId) {
2127
- const getDateFromNow = (days) => new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString().split("T")[0];
2575
+ required: [fieldId]
2576
+ };
2577
+ }
2578
+ function isFieldReference(value) {
2579
+ return typeof value === "object" && value !== null && "_fieldId" in value;
2580
+ }
2581
+ function createFieldConditionals(fieldId) {
2128
2582
  const getDateRange = (date, clause) => ({
2129
2583
  type: "object",
2130
2584
  properties: {
2131
- $form: {
2132
- type: "object",
2133
- properties: {
2134
- [fieldId]: {
2135
- type: "string",
2136
- format: "date",
2137
- [clause]: date
2138
- }
2139
- },
2140
- required: [fieldId]
2585
+ [fieldId]: {
2586
+ type: "string",
2587
+ format: "date",
2588
+ [clause]: date
2141
2589
  }
2142
2590
  },
2143
- required: ["$form"]
2591
+ required: [fieldId]
2144
2592
  });
2145
2593
  return {
2146
2594
  isAfter: () => ({
2147
2595
  days: (days) => ({
2148
- inPast: () => defineConditional(
2596
+ inPast: () => defineFormConditional(
2149
2597
  getDateRange(getDateFromNow(days), "formatMinimum")
2150
2598
  ),
2151
- inFuture: () => defineConditional(
2599
+ inFuture: () => defineFormConditional(
2152
2600
  getDateRange(getDateFromNow(-days), "formatMinimum")
2153
2601
  )
2154
2602
  }),
2155
- date: (date) => defineConditional(getDateRange(date, "formatMinimum")),
2156
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2603
+ date: (date) => {
2604
+ if (isFieldReference(date)) {
2605
+ const comparedFieldId = date._fieldId;
2606
+ return defineFormConditional(
2607
+ getDateRangeToFieldReference(
2608
+ fieldId,
2609
+ comparedFieldId,
2610
+ "formatMinimum"
2611
+ )
2612
+ );
2613
+ }
2614
+ return defineFormConditional(getDateRange(date, "formatMinimum"));
2615
+ },
2616
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMinimum"))
2157
2617
  }),
2158
2618
  isBefore: () => ({
2159
2619
  days: (days) => ({
2160
- inPast: () => defineConditional(
2620
+ inPast: () => defineFormConditional(
2161
2621
  getDateRange(getDateFromNow(days), "formatMaximum")
2162
2622
  ),
2163
- inFuture: () => defineConditional(
2623
+ inFuture: () => defineFormConditional(
2164
2624
  getDateRange(getDateFromNow(-days), "formatMaximum")
2165
2625
  )
2166
2626
  }),
2167
- date: (date) => defineConditional(getDateRange(date, "formatMaximum")),
2168
- now: () => defineConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2627
+ date: (date) => {
2628
+ if (isFieldReference(date)) {
2629
+ const comparedFieldId = date._fieldId;
2630
+ return defineFormConditional(
2631
+ getDateRangeToFieldReference(
2632
+ fieldId,
2633
+ comparedFieldId,
2634
+ "formatMaximum"
2635
+ )
2636
+ );
2637
+ }
2638
+ return defineFormConditional(getDateRange(date, "formatMaximum"));
2639
+ },
2640
+ now: () => defineFormConditional(getDateRange(getDateFromNow(0), "formatMaximum"))
2169
2641
  }),
2170
- isEqualTo: (value) => defineConditional({
2171
- type: "object",
2172
- properties: {
2173
- $form: {
2642
+ isEqualTo: (value) => {
2643
+ if (isFieldReference(value)) {
2644
+ const comparedFieldId = value._fieldId;
2645
+ return defineFormConditional({
2174
2646
  type: "object",
2175
2647
  properties: {
2176
2648
  [fieldId]: {
2177
- oneOf: [
2178
- { type: "string", const: value },
2179
- { type: "boolean", const: value }
2180
- ],
2181
- const: value
2182
- }
2649
+ type: ["string", "boolean"],
2650
+ const: { $data: `1/${comparedFieldId}` }
2651
+ },
2652
+ [comparedFieldId]: { type: ["string", "boolean"] }
2183
2653
  },
2184
- required: [fieldId]
2185
- }
2186
- },
2187
- required: ["$form"]
2188
- }),
2654
+ required: [fieldId, comparedFieldId]
2655
+ });
2656
+ }
2657
+ return defineFormConditional({
2658
+ type: "object",
2659
+ properties: {
2660
+ [fieldId]: {
2661
+ oneOf: [
2662
+ { type: "string", const: value },
2663
+ { type: "boolean", const: value }
2664
+ ],
2665
+ const: value
2666
+ }
2667
+ },
2668
+ required: [fieldId]
2669
+ });
2670
+ },
2189
2671
  /**
2190
2672
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
2191
2673
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -2194,91 +2676,166 @@ function field(fieldId) {
2194
2676
  * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
2195
2677
  *
2196
2678
  */
2197
- isFalsy: () => defineConditional({
2679
+ isFalsy: () => defineFormConditional({
2680
+ type: "object",
2681
+ properties: {
2682
+ [fieldId]: {
2683
+ anyOf: [
2684
+ { const: "undefined" },
2685
+ { const: false },
2686
+ { const: null },
2687
+ { const: "" }
2688
+ ]
2689
+ }
2690
+ },
2691
+ anyOf: [
2692
+ {
2693
+ required: [fieldId]
2694
+ },
2695
+ {
2696
+ not: {
2697
+ required: [fieldId]
2698
+ }
2699
+ }
2700
+ ]
2701
+ }),
2702
+ isUndefined: () => defineFormConditional({
2703
+ type: "object",
2704
+ properties: {
2705
+ [fieldId]: {
2706
+ type: "string",
2707
+ enum: ["undefined"]
2708
+ }
2709
+ },
2710
+ not: {
2711
+ required: [fieldId]
2712
+ }
2713
+ }),
2714
+ inArray: (values) => defineFormConditional({
2715
+ type: "object",
2716
+ properties: {
2717
+ [fieldId]: {
2718
+ type: "string",
2719
+ enum: values
2720
+ }
2721
+ },
2722
+ required: [fieldId]
2723
+ }),
2724
+ isValidEnglishName: () => defineFormConditional({
2198
2725
  type: "object",
2199
2726
  properties: {
2200
- $form: {
2201
- type: "object",
2202
- properties: {
2203
- [fieldId]: {
2204
- anyOf: [
2205
- { const: "undefined" },
2206
- { const: false },
2207
- { const: null },
2208
- { const: "" }
2209
- ]
2210
- }
2211
- },
2212
- anyOf: [
2213
- {
2214
- required: [fieldId]
2215
- },
2216
- {
2217
- not: {
2218
- required: [fieldId]
2219
- }
2220
- }
2221
- ]
2727
+ [fieldId]: {
2728
+ type: "string",
2729
+ pattern: "^[\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*( [\\p{Script=Latin}0-9'._-]*(\\([\\p{Script=Latin}0-9'._-]+\\))?[\\p{Script=Latin}0-9'._-]*)*$",
2730
+ description: "Name must contain only letters, numbers, and allowed special characters ('._-). No double spaces."
2222
2731
  }
2223
2732
  },
2224
- required: ["$form"]
2733
+ required: [fieldId]
2225
2734
  }),
2226
- isUndefined: () => defineConditional({
2735
+ /**
2736
+ * Checks if the field value matches a given regular expression pattern.
2737
+ * @param pattern - The regular expression pattern to match the field value against.
2738
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
2739
+ */
2740
+ matches: (pattern) => defineFormConditional({
2227
2741
  type: "object",
2228
2742
  properties: {
2229
- $form: {
2230
- type: "object",
2231
- properties: {
2232
- [fieldId]: {
2233
- type: "string",
2234
- enum: ["undefined"]
2235
- }
2236
- },
2237
- not: {
2238
- required: [fieldId]
2239
- }
2743
+ [fieldId]: {
2744
+ type: "string",
2745
+ pattern
2240
2746
  }
2241
2747
  },
2242
- required: ["$form"]
2748
+ required: [fieldId]
2243
2749
  }),
2244
- inArray: (values) => defineConditional({
2750
+ isBetween: (min, max) => defineFormConditional({
2245
2751
  type: "object",
2246
2752
  properties: {
2247
- $form: {
2248
- type: "object",
2249
- properties: {
2250
- [fieldId]: {
2251
- type: "string",
2252
- enum: values
2253
- }
2254
- },
2255
- required: [fieldId]
2753
+ [fieldId]: {
2754
+ type: "number",
2755
+ minimum: min,
2756
+ maximum: max
2256
2757
  }
2257
2758
  },
2258
- required: ["$form"]
2759
+ required: [fieldId]
2760
+ }),
2761
+ getId: () => ({ fieldId })
2762
+ };
2763
+ }
2764
+
2765
+ // ../commons/src/field-config/field-configuration.ts
2766
+ function createFieldConfigs(fieldId) {
2767
+ const baseField = {
2768
+ fieldId,
2769
+ fieldType: "field"
2770
+ };
2771
+ return {
2772
+ /**
2773
+ * Creates a range configuration for the specified field.
2774
+ *
2775
+ * @returns An object containing the field ID and a configuration object with a type of 'RANGE'.
2776
+ *
2777
+ * @example field('age').range()
2778
+ * // {
2779
+ * // fieldId: 'age',
2780
+ * // config: { type: 'RANGE' }
2781
+ * // }
2782
+ */
2783
+ range: () => ({
2784
+ ...baseField,
2785
+ config: { type: "RANGE" }
2786
+ }),
2787
+ /**
2788
+ * Creates a configuration for exact matching of the specified field.
2789
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
2790
+ * @example field('dob').exact()
2791
+ * // {
2792
+ * // fieldId: 'dob',
2793
+ * // config: { type: 'EXACT' }
2794
+ * // }
2795
+ */
2796
+ exact: () => ({
2797
+ ...baseField,
2798
+ config: { type: "EXACT" }
2799
+ }),
2800
+ /**
2801
+ * Creates a configuration for fuzzy matching of the specified field.
2802
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
2803
+ * @example field('name').fuzzy()
2804
+ * // {
2805
+ * // fieldId: 'name',
2806
+ * // config: { type: 'FUZZY' }
2807
+ * // }
2808
+ */
2809
+ fuzzy: () => ({
2810
+ ...baseField,
2811
+ config: { type: "FUZZY" }
2259
2812
  })
2260
2813
  };
2261
2814
  }
2262
2815
 
2816
+ // ../commons/src/events/field.ts
2817
+ function field(fieldId) {
2818
+ return {
2819
+ /**
2820
+ * @private Internal property used for field reference tracking.
2821
+ */
2822
+ _fieldId: fieldId,
2823
+ ...createFieldConditionals(fieldId),
2824
+ ...createFieldConfigs(fieldId)
2825
+ };
2826
+ }
2827
+
2263
2828
  // ../commons/src/fixtures/tennis-club-membership-event.ts
2264
- var PRINT_CERTIFICATE_FORM = defineForm({
2829
+ var PRINT_CERTIFICATE_FORM = defineActionForm({
2265
2830
  label: {
2266
2831
  id: "v2.event.tennis-club-membership.action.certificate.form.label",
2267
2832
  defaultMessage: "Tennis club membership certificate collector",
2268
2833
  description: "This is what this form is referred as in the system"
2269
2834
  },
2270
- version: {
2271
- id: "1.0.0",
2272
- label: {
2273
- id: "v2.event.tennis-club-membership.action.certificate.form.version.1",
2274
- defaultMessage: "Version 1",
2275
- description: "This is the first version of the form"
2276
- }
2277
- },
2278
- active: true,
2279
2835
  pages: [
2280
2836
  {
2281
2837
  id: "collector",
2838
+ type: PageTypes.enum.FORM,
2282
2839
  title: {
2283
2840
  id: "v2.event.tennis-club-membership.action.certificate.form.section.who.title",
2284
2841
  defaultMessage: "Print certified copy",
@@ -2293,7 +2850,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2293
2850
  defaultMessage: "Requester",
2294
2851
  description: "This is the label for the field"
2295
2852
  },
2296
- type: "SELECT",
2853
+ type: FieldType.SELECT,
2297
2854
  options: [
2298
2855
  {
2299
2856
  value: "INFORMANT",
@@ -2370,7 +2927,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2370
2927
  defaultMessage: "Select Type of ID",
2371
2928
  description: "This is the label for selecting the type of ID"
2372
2929
  },
2373
- type: "SELECT",
2930
+ type: FieldType.SELECT,
2374
2931
  options: [
2375
2932
  {
2376
2933
  value: "PASSPORT",
@@ -2471,7 +3028,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2471
3028
  defaultMessage: "Passport Details",
2472
3029
  description: "Field for entering Passport details"
2473
3030
  },
2474
- type: "TEXT"
3031
+ type: FieldType.TEXT
2475
3032
  },
2476
3033
  {
2477
3034
  id: "collector.DRIVING_LICENSE.details",
@@ -2522,7 +3079,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2522
3079
  defaultMessage: "Driving License Details",
2523
3080
  description: "Field for entering Driving License details"
2524
3081
  },
2525
- type: "TEXT"
3082
+ type: FieldType.TEXT
2526
3083
  },
2527
3084
  {
2528
3085
  id: "collector.REFUGEE_NUMBER.details",
@@ -2573,7 +3130,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2573
3130
  defaultMessage: "Refugee Number Details",
2574
3131
  description: "Field for entering Refugee Number details"
2575
3132
  },
2576
- type: "TEXT"
3133
+ type: FieldType.TEXT
2577
3134
  },
2578
3135
  {
2579
3136
  id: "collector.ALIEN_NUMBER.details",
@@ -2624,7 +3181,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2624
3181
  defaultMessage: "Alien Number Details",
2625
3182
  description: "Field for entering Alien Number details"
2626
3183
  },
2627
- type: "TEXT"
3184
+ type: FieldType.TEXT
2628
3185
  },
2629
3186
  {
2630
3187
  id: "collector.OTHER.idTypeOther",
@@ -2675,7 +3232,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2675
3232
  defaultMessage: "Other ID Type (if applicable)",
2676
3233
  description: 'Field for entering ID type if "Other" is selected'
2677
3234
  },
2678
- type: "TEXT"
3235
+ type: FieldType.TEXT
2679
3236
  },
2680
3237
  {
2681
3238
  id: "collector.OTHER.firstName",
@@ -2726,7 +3283,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2726
3283
  defaultMessage: "First Name",
2727
3284
  description: "This is the label for the first name field"
2728
3285
  },
2729
- type: "TEXT"
3286
+ type: FieldType.TEXT
2730
3287
  },
2731
3288
  {
2732
3289
  id: "collector.OTHER.lastName",
@@ -2777,7 +3334,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2777
3334
  defaultMessage: "Last Name",
2778
3335
  description: "This is the label for the last name field"
2779
3336
  },
2780
- type: "TEXT"
3337
+ type: FieldType.TEXT
2781
3338
  },
2782
3339
  {
2783
3340
  id: "collector.OTHER.relationshipToMember",
@@ -2828,7 +3385,7 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2828
3385
  defaultMessage: "Relationship to Member",
2829
3386
  description: "This is the label for the relationship to member field"
2830
3387
  },
2831
- type: "TEXT"
3388
+ type: FieldType.TEXT
2832
3389
  },
2833
3390
  {
2834
3391
  id: "collector.OTHER.signedAffidavit",
@@ -2879,66 +3436,88 @@ var PRINT_CERTIFICATE_FORM = defineForm({
2879
3436
  defaultMessage: "Signed Affidavit (Optional)",
2880
3437
  description: "This is the label for uploading a signed affidavit"
2881
3438
  },
2882
- type: "FILE"
3439
+ type: FieldType.FILE
2883
3440
  }
2884
3441
  ]
2885
- }
2886
- ],
2887
- review: {
2888
- title: {
2889
- id: "v2.event.tennis-club-membership.action.certificate.form.review.title",
2890
- defaultMessage: "Member certificate collector for {firstname} {surname}",
2891
- description: "Title of the form to show in review page"
2892
3442
  },
2893
- fields: []
2894
- }
2895
- });
2896
- var TENNIS_CLUB_FORM = defineForm({
2897
- label: {
2898
- id: "v2.event.tennis-club-membership.action.declare.form.label",
2899
- defaultMessage: "Tennis club membership application",
2900
- description: "This is what this form is referred as in the system"
2901
- },
2902
- active: true,
2903
- version: {
2904
- id: "1.0.0",
2905
- label: {
2906
- id: "v2.event.tennis-club-membership.action.declare.form.version.1",
2907
- defaultMessage: "Version 1",
2908
- description: "This is the first version of the form"
3443
+ {
3444
+ id: "collector.identity.verify",
3445
+ type: PageTypes.enum.VERIFICATION,
3446
+ conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
3447
+ title: {
3448
+ id: "event.tennis-club-membership.action.print.verifyIdentity",
3449
+ defaultMessage: "Verify their identity",
3450
+ description: "This is the title of the section"
3451
+ },
3452
+ fields: [],
3453
+ actions: {
3454
+ verify: {
3455
+ label: {
3456
+ defaultMessage: "Verified",
3457
+ description: "This is the label for the verification button",
3458
+ id: "v2.event.tennis-club-membership.action.certificate.form.verify"
3459
+ }
3460
+ },
3461
+ cancel: {
3462
+ label: {
3463
+ defaultMessage: "Identity does not match",
3464
+ description: "This is the label for the verification cancellation button",
3465
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel"
3466
+ },
3467
+ confirmation: {
3468
+ title: {
3469
+ defaultMessage: "Print without proof of ID?",
3470
+ description: "This is the title for the verification cancellation modal",
3471
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.title"
3472
+ },
3473
+ body: {
3474
+ defaultMessage: "Please be aware that if you proceed, you will be responsible for issuing a certificate without the necessary proof of ID from the collector",
3475
+ description: "This is the body for the verification cancellation modal",
3476
+ id: "v2.event.tennis-club-membership.action.certificate.form.cancel.confirmation.body"
3477
+ }
3478
+ }
3479
+ }
3480
+ }
2909
3481
  }
3482
+ ]
3483
+ });
3484
+ var TENNIS_CLUB_DECLARATION_REVIEW = {
3485
+ title: {
3486
+ id: "v2.event.tennis-club-membership.action.declare.form.review.title",
3487
+ defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
3488
+ description: "Title of the review page"
2910
3489
  },
2911
- review: {
2912
- title: {
2913
- id: "v2.event.tennis-club-membership.action.declare.form.review.title",
2914
- defaultMessage: "{applicant.firstname, select, __EMPTY__ {Member declaration} other {{applicant.surname, select, __EMPTY__ {Member declaration} other {Member declaration for {applicant.firstname} {applicant.surname}}}}}",
2915
- description: "Title of the form to show in review page"
3490
+ fields: [
3491
+ {
3492
+ id: "review.comment",
3493
+ type: FieldType.TEXTAREA,
3494
+ label: {
3495
+ defaultMessage: "Comment",
3496
+ id: "v2.event.birth.action.declare.form.review.comment.label",
3497
+ description: "Label for the comment field in the review section"
3498
+ }
2916
3499
  },
2917
- fields: [
2918
- {
2919
- id: "review.comment",
2920
- type: "TEXTAREA",
2921
- label: {
2922
- defaultMessage: "Comment",
2923
- id: "v2.event.birth.action.declare.form.review.comment.label",
2924
- description: "Label for the comment field in the review section"
2925
- }
3500
+ {
3501
+ type: FieldType.SIGNATURE,
3502
+ id: "review.signature",
3503
+ label: {
3504
+ defaultMessage: "Signature of informant",
3505
+ id: "v2.event.birth.action.declare.form.review.signature.label",
3506
+ description: "Label for the signature field in the review section"
2926
3507
  },
2927
- {
2928
- type: "SIGNATURE",
2929
- id: "review.signature",
2930
- label: {
2931
- defaultMessage: "Signature of informant",
2932
- id: "v2.event.birth.action.declare.form.review.signature.label",
2933
- description: "Label for the signature field in the review section"
2934
- },
2935
- signaturePromptLabel: {
2936
- id: "v2.signature.upload.modal.title",
2937
- defaultMessage: "Draw signature",
2938
- description: "Title for the modal to draw signature"
2939
- }
3508
+ signaturePromptLabel: {
3509
+ id: "v2.signature.upload.modal.title",
3510
+ defaultMessage: "Draw signature",
3511
+ description: "Title for the modal to draw signature"
2940
3512
  }
2941
- ]
3513
+ }
3514
+ ]
3515
+ };
3516
+ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
3517
+ label: {
3518
+ id: "v2.event.tennis-club-membership.action.declare.form.label",
3519
+ defaultMessage: "Tennis club membership application",
3520
+ description: "This is what this form is referred as in the system"
2942
3521
  },
2943
3522
  pages: [
2944
3523
  {
@@ -2951,7 +3530,7 @@ var TENNIS_CLUB_FORM = defineForm({
2951
3530
  fields: [
2952
3531
  {
2953
3532
  id: "applicant.firstname",
2954
- type: "TEXT",
3533
+ type: FieldType.TEXT,
2955
3534
  required: true,
2956
3535
  conditionals: [],
2957
3536
  label: {
@@ -2962,7 +3541,7 @@ var TENNIS_CLUB_FORM = defineForm({
2962
3541
  },
2963
3542
  {
2964
3543
  id: "applicant.surname",
2965
- type: "TEXT",
3544
+ type: FieldType.TEXT,
2966
3545
  required: true,
2967
3546
  conditionals: [],
2968
3547
  label: {
@@ -2984,9 +3563,8 @@ var TENNIS_CLUB_FORM = defineForm({
2984
3563
  },
2985
3564
  {
2986
3565
  id: "applicant.dob",
2987
- type: "DATE",
3566
+ type: FieldType.DATE,
2988
3567
  required: true,
2989
- conditionals: [],
2990
3568
  validation: [
2991
3569
  {
2992
3570
  message: {
@@ -2997,15 +3575,53 @@ var TENNIS_CLUB_FORM = defineForm({
2997
3575
  validator: field("applicant.dob").isBefore().now()
2998
3576
  }
2999
3577
  ],
3578
+ conditionals: [
3579
+ {
3580
+ type: ConditionalType.SHOW,
3581
+ conditional: field("applicant.dobUnknown").isFalsy()
3582
+ }
3583
+ ],
3000
3584
  label: {
3001
3585
  defaultMessage: "Applicant's date of birth",
3002
3586
  description: "This is the label for the field",
3003
3587
  id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dob.label"
3004
3588
  }
3005
3589
  },
3590
+ {
3591
+ id: "applicant.dobUnknown",
3592
+ type: FieldType.CHECKBOX,
3593
+ required: false,
3594
+ label: {
3595
+ defaultMessage: "Exact date of birth unknown",
3596
+ description: "This is the label for the field",
3597
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.dobUnknown.label"
3598
+ },
3599
+ conditionals: [
3600
+ {
3601
+ type: ConditionalType.DISPLAY_ON_REVIEW,
3602
+ conditional: never()
3603
+ }
3604
+ ]
3605
+ },
3606
+ {
3607
+ id: "applicant.age",
3608
+ type: FieldType.NUMBER,
3609
+ required: true,
3610
+ label: {
3611
+ defaultMessage: "Age of tennis-member",
3612
+ description: "This is the label for the field",
3613
+ id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.age.label"
3614
+ },
3615
+ conditionals: [
3616
+ {
3617
+ type: ConditionalType.SHOW,
3618
+ conditional: field("applicant.dobUnknown").isEqualTo(true)
3619
+ }
3620
+ ]
3621
+ },
3006
3622
  {
3007
3623
  id: "applicant.image",
3008
- type: "FILE",
3624
+ type: FieldType.FILE,
3009
3625
  required: false,
3010
3626
  label: {
3011
3627
  defaultMessage: "Applicant's profile picture",
@@ -3026,6 +3642,27 @@ var TENNIS_CLUB_FORM = defineForm({
3026
3642
  }
3027
3643
  ]
3028
3644
  },
3645
+ {
3646
+ id: "senior-pass",
3647
+ conditional: field("applicant.dob").isBefore().date("1950-01-01"),
3648
+ title: {
3649
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.title",
3650
+ defaultMessage: "Assign senior pass for applicant",
3651
+ description: "This is the title of the section"
3652
+ },
3653
+ fields: [
3654
+ {
3655
+ id: "senior-pass.id",
3656
+ type: FieldType.TEXT,
3657
+ required: true,
3658
+ label: {
3659
+ defaultMessage: "Senior pass ID",
3660
+ description: "This is the label for the field",
3661
+ id: "v2.event.tennis-club-membership.action.declare.form.section.senior-pass.field.id.label"
3662
+ }
3663
+ }
3664
+ ]
3665
+ },
3029
3666
  {
3030
3667
  id: "recommender",
3031
3668
  title: {
@@ -3047,7 +3684,7 @@ var TENNIS_CLUB_FORM = defineForm({
3047
3684
  },
3048
3685
  {
3049
3686
  id: "recommender.firstname",
3050
- type: "TEXT",
3687
+ type: FieldType.TEXT,
3051
3688
  required: true,
3052
3689
  conditionals: [
3053
3690
  {
@@ -3063,7 +3700,7 @@ var TENNIS_CLUB_FORM = defineForm({
3063
3700
  },
3064
3701
  {
3065
3702
  id: "recommender.surname",
3066
- type: "TEXT",
3703
+ type: FieldType.TEXT,
3067
3704
  required: true,
3068
3705
  conditionals: [
3069
3706
  {
@@ -3079,7 +3716,7 @@ var TENNIS_CLUB_FORM = defineForm({
3079
3716
  },
3080
3717
  {
3081
3718
  id: "recommender.id",
3082
- type: "TEXT",
3719
+ type: FieldType.TEXT,
3083
3720
  required: true,
3084
3721
  conditionals: [
3085
3722
  {
@@ -3104,20 +3741,12 @@ var tennisClubMembershipEvent = defineConfig({
3104
3741
  description: "This is what this event is referred as in the system",
3105
3742
  id: "event.tennis-club-membership.label"
3106
3743
  },
3744
+ title: {
3745
+ defaultMessage: "{applicant.firstname} {applicant.surname}",
3746
+ description: "This is the title of the summary",
3747
+ id: "v2.event.tennis-club-membership.title"
3748
+ },
3107
3749
  summary: {
3108
- title: {
3109
- id: "event.tennis-club-membership.summary.title",
3110
- label: {
3111
- defaultMessage: "{applicant.firstname} {applicant.surname}",
3112
- description: "This is the title of the summary",
3113
- id: "v2.event.tennis-club-membership.summary.title"
3114
- },
3115
- emptyValueMessage: {
3116
- defaultMessage: "Membership application",
3117
- description: "This is the message shown when the applicant name is missing",
3118
- id: "event.tennis-club-membership.summary.title.empty"
3119
- }
3120
- },
3121
3750
  fields: [
3122
3751
  {
3123
3752
  id: "applicant.firstname",
@@ -3157,28 +3786,6 @@ var tennisClubMembershipEvent = defineConfig({
3157
3786
  }
3158
3787
  ]
3159
3788
  },
3160
- workqueues: [
3161
- {
3162
- id: "all",
3163
- filters: []
3164
- },
3165
- {
3166
- id: "ready-for-review",
3167
- filters: [
3168
- {
3169
- status: ["DECLARED"]
3170
- }
3171
- ]
3172
- },
3173
- {
3174
- id: "registered",
3175
- filters: [
3176
- {
3177
- status: ["REGISTERED"]
3178
- }
3179
- ]
3180
- }
3181
- ],
3182
3789
  actions: [
3183
3790
  {
3184
3791
  type: ActionType.DECLARE,
@@ -3187,7 +3794,7 @@ var tennisClubMembershipEvent = defineConfig({
3187
3794
  description: "This is shown as the action name anywhere the user can trigger the action from",
3188
3795
  id: "event.tennis-club-membership.action.declare.label"
3189
3796
  },
3190
- forms: [TENNIS_CLUB_FORM]
3797
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3191
3798
  },
3192
3799
  {
3193
3800
  type: ActionType.VALIDATE,
@@ -3196,7 +3803,7 @@ var tennisClubMembershipEvent = defineConfig({
3196
3803
  description: "This is shown as the action name anywhere the user can trigger the action from",
3197
3804
  id: "event.tennis-club-membership.action.validate.label"
3198
3805
  },
3199
- forms: [TENNIS_CLUB_FORM]
3806
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3200
3807
  },
3201
3808
  {
3202
3809
  type: ActionType.REGISTER,
@@ -3205,7 +3812,7 @@ var tennisClubMembershipEvent = defineConfig({
3205
3812
  description: "This is shown as the action name anywhere the user can trigger the action from",
3206
3813
  id: "event.tennis-club-membership.action.register.label"
3207
3814
  },
3208
- forms: [TENNIS_CLUB_FORM]
3815
+ review: TENNIS_CLUB_DECLARATION_REVIEW
3209
3816
  },
3210
3817
  {
3211
3818
  type: ActionType.REQUEST_CORRECTION,
@@ -3214,10 +3821,10 @@ var tennisClubMembershipEvent = defineConfig({
3214
3821
  description: "This is shown as the action name anywhere the user can trigger the action from",
3215
3822
  id: "event.tennis-club-membership.action.correction.request.label"
3216
3823
  },
3217
- forms: [TENNIS_CLUB_FORM],
3218
3824
  onboardingForm: [
3219
3825
  {
3220
3826
  id: "correction-requester",
3827
+ type: PageTypes.enum.FORM,
3221
3828
  title: {
3222
3829
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3223
3830
  defaultMessage: "Correction requester",
@@ -3281,6 +3888,7 @@ var tennisClubMembershipEvent = defineConfig({
3281
3888
  },
3282
3889
  {
3283
3890
  id: "identity-check",
3891
+ type: PageTypes.enum.FORM,
3284
3892
  title: {
3285
3893
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3286
3894
  defaultMessage: "Verify their identity",
@@ -3323,6 +3931,7 @@ var tennisClubMembershipEvent = defineConfig({
3323
3931
  additionalDetailsForm: [
3324
3932
  {
3325
3933
  id: "correction-request.supporting-documents",
3934
+ type: PageTypes.enum.FORM,
3326
3935
  title: {
3327
3936
  id: "event.tennis-club-membership.action.requestCorrection.form.section.verify",
3328
3937
  defaultMessage: "Upload supporting documents",
@@ -3340,7 +3949,7 @@ var tennisClubMembershipEvent = defineConfig({
3340
3949
  },
3341
3950
  {
3342
3951
  id: "correction.supportingDocs",
3343
- type: "FILE",
3952
+ type: FieldType.FILE,
3344
3953
  label: {
3345
3954
  id: "correction.corrector.title",
3346
3955
  defaultMessage: "Upload supporting documents",
@@ -3384,6 +3993,7 @@ var tennisClubMembershipEvent = defineConfig({
3384
3993
  },
3385
3994
  {
3386
3995
  id: "correction-request.additional-details",
3996
+ type: PageTypes.enum.FORM,
3387
3997
  title: {
3388
3998
  id: "event.tennis-club-membership.action.requestCorrection.form.section.corrector",
3389
3999
  defaultMessage: "Reason for correction",
@@ -3392,7 +4002,7 @@ var tennisClubMembershipEvent = defineConfig({
3392
4002
  fields: [
3393
4003
  {
3394
4004
  id: "correction.request.reason",
3395
- type: "TEXT",
4005
+ type: FieldType.TEXT,
3396
4006
  label: {
3397
4007
  id: "correction.reason.title",
3398
4008
  defaultMessage: "Reason for correction?",
@@ -3405,7 +4015,6 @@ var tennisClubMembershipEvent = defineConfig({
3405
4015
  },
3406
4016
  {
3407
4017
  type: ActionType.APPROVE_CORRECTION,
3408
- forms: [TENNIS_CLUB_FORM],
3409
4018
  label: {
3410
4019
  defaultMessage: "Approve correction",
3411
4020
  description: "This is shown as the action name anywhere the user can trigger the action from",
@@ -3419,7 +4028,7 @@ var tennisClubMembershipEvent = defineConfig({
3419
4028
  defaultMessage: "Print certificate",
3420
4029
  description: "This is shown as the action name anywhere the user can trigger the action from"
3421
4030
  },
3422
- forms: [PRINT_CERTIFICATE_FORM],
4031
+ printForm: PRINT_CERTIFICATE_FORM,
3423
4032
  conditionals: [
3424
4033
  {
3425
4034
  type: "SHOW",
@@ -3466,8 +4075,7 @@ var tennisClubMembershipEvent = defineConfig({
3466
4075
  id: "v2.event.tennis-club-membership.action.archive.label",
3467
4076
  defaultMessage: "Archive",
3468
4077
  description: "This is shown as the action name anywhere the user can trigger the action from"
3469
- },
3470
- forms: [TENNIS_CLUB_FORM]
4078
+ }
3471
4079
  },
3472
4080
  {
3473
4081
  type: ActionType.REJECT,
@@ -3475,8 +4083,7 @@ var tennisClubMembershipEvent = defineConfig({
3475
4083
  id: "v2.event.tennis-club-membership.action.reject.label",
3476
4084
  defaultMessage: "Reject",
3477
4085
  description: "This is shown as the action name anywhere the user can trigger the action from"
3478
- },
3479
- forms: [TENNIS_CLUB_FORM]
4086
+ }
3480
4087
  }
3481
4088
  ],
3482
4089
  advancedSearch: [
@@ -3486,26 +4093,55 @@ var tennisClubMembershipEvent = defineConfig({
3486
4093
  description: "This is what this event is referred as in the system",
3487
4094
  id: "v2.event.tennis-club-membership.search"
3488
4095
  },
3489
- fields: [
3490
- {
3491
- fieldId: "applicant.dob"
3492
- }
3493
- ]
4096
+ fields: [field("applicant.dob").exact()]
3494
4097
  }
3495
- ]
4098
+ ],
4099
+ declaration: TENNIS_CLUB_DECLARATION_FORM
3496
4100
  });
3497
4101
 
3498
4102
  // ../commons/src/events/test.utils.ts
3499
- function generateActionInput(configuration, action) {
3500
- const fields = findActiveActionFormFields(configuration, action) ?? [];
3501
- const data = fields.reduce(
4103
+ function fieldConfigsToActionPayload(fields) {
4104
+ return fields.reduce(
3502
4105
  (acc, field2, i) => ({
3503
4106
  ...acc,
3504
4107
  [field2.id]: mapFieldTypeToMockValue(field2, i)
3505
4108
  }),
3506
4109
  {}
3507
4110
  );
3508
- return stripHiddenFields(fields, data);
4111
+ }
4112
+ function generateActionDeclarationInput(configuration, action) {
4113
+ const parsed = DeclarationUpdateActions.safeParse(action);
4114
+ if (parsed.success) {
4115
+ const fields = getDeclarationFields(configuration);
4116
+ const declarationConfig = getDeclaration(configuration);
4117
+ const declaration = fieldConfigsToActionPayload(fields);
4118
+ return omitHiddenPaginatedFields(declarationConfig, declaration);
4119
+ }
4120
+ console.warn(`${action} is not a declaration action. Setting data as {}.`);
4121
+ return {};
4122
+ }
4123
+ function generateActionAnnotationInput(configuration, action) {
4124
+ const actionConfig = configuration.actions.find(
4125
+ (ac) => ac.type === action
4126
+ );
4127
+ const annotationFields = actionConfig ? getActionAnnotationFields(actionConfig) : [];
4128
+ const annotation = fieldConfigsToActionPayload(annotationFields);
4129
+ const visibleVerificationPageIds = getVisibleVerificationPageIds(
4130
+ findRecordActionPages(configuration, action),
4131
+ annotation
4132
+ );
4133
+ const visiblePageVerificationMap = visibleVerificationPageIds.reduce(
4134
+ (acc, pageId) => ({
4135
+ ...acc,
4136
+ [pageId]: true
4137
+ }),
4138
+ {}
4139
+ );
4140
+ const fieldBasedPayload = omitHiddenFields(annotationFields, annotation);
4141
+ return {
4142
+ ...fieldBasedPayload,
4143
+ ...visiblePageVerificationMap
4144
+ };
3509
4145
  }
3510
4146
  var eventPayloadGenerator = {
3511
4147
  create: (input = {}) => ({
@@ -3517,27 +4153,31 @@ var eventPayloadGenerator = {
3517
4153
  type: input.type ?? "TENNIS_CLUB_MEMBERSHIP",
3518
4154
  id
3519
4155
  }),
3520
- draft: (eventId, input = {}) => (0, import_lodash2.merge)(
4156
+ draft: ({ eventId, actionType }, input = {}) => (0, import_lodash2.merge)(
3521
4157
  {
3522
4158
  id: getUUID(),
3523
4159
  eventId,
3524
4160
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3525
4161
  transactionId: getUUID(),
3526
4162
  action: {
3527
- type: ActionType.REQUEST_CORRECTION,
3528
- data: {
4163
+ transactionId: getUUID(),
4164
+ type: actionType,
4165
+ status: ActionStatus.Accepted,
4166
+ declaration: {
3529
4167
  "applicant.firstname": "Max",
3530
4168
  "applicant.surname": "McLaren",
3531
4169
  "applicant.dob": "2020-01-02",
3532
4170
  "recommender.none": true
3533
4171
  },
3534
- metadata: {
4172
+ annotation: {
3535
4173
  "correction.requester.relationship": "ANOTHER_AGENT",
3536
4174
  "correction.request.reason": "Child's name was incorrect"
3537
4175
  },
3538
4176
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3539
4177
  createdBy: "@todo",
3540
- createdAtLocation: "@todo"
4178
+ createdByRole: "@todo",
4179
+ createdAtLocation: "@todo",
4180
+ updatedAtLocation: "@todo"
3541
4181
  }
3542
4182
  },
3543
4183
  input
@@ -3546,41 +4186,104 @@ var eventPayloadGenerator = {
3546
4186
  declare: (eventId, input = {}) => ({
3547
4187
  type: ActionType.DECLARE,
3548
4188
  transactionId: input.transactionId ?? getUUID(),
3549
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.DECLARE),
4189
+ declaration: input.declaration ?? generateActionDeclarationInput(
4190
+ tennisClubMembershipEvent,
4191
+ ActionType.DECLARE
4192
+ ),
4193
+ annotation: input.annotation ?? generateActionAnnotationInput(
4194
+ tennisClubMembershipEvent,
4195
+ ActionType.DECLARE
4196
+ ),
3550
4197
  eventId
3551
4198
  }),
4199
+ /**
4200
+ * Notify allows sending incomplete data. Think it as 'partial declare' for now.
4201
+ */
4202
+ notify: (eventId, input = {}) => {
4203
+ let declaration = input.declaration;
4204
+ if (!declaration) {
4205
+ const partialDeclaration = (0, import_lodash2.omitBy)(
4206
+ generateActionDeclarationInput(
4207
+ tennisClubMembershipEvent,
4208
+ ActionType.DECLARE
4209
+ ),
4210
+ import_lodash2.isString
4211
+ );
4212
+ declaration = partialDeclaration;
4213
+ }
4214
+ return {
4215
+ type: ActionType.NOTIFY,
4216
+ transactionId: input.transactionId ?? getUUID(),
4217
+ declaration,
4218
+ eventId
4219
+ };
4220
+ },
3552
4221
  validate: (eventId, input = {}) => ({
3553
4222
  type: ActionType.VALIDATE,
3554
4223
  transactionId: input.transactionId ?? getUUID(),
3555
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.VALIDATE),
4224
+ declaration: input.declaration ?? generateActionDeclarationInput(
4225
+ tennisClubMembershipEvent,
4226
+ ActionType.VALIDATE
4227
+ ),
4228
+ annotation: input.annotation ?? generateActionAnnotationInput(
4229
+ tennisClubMembershipEvent,
4230
+ ActionType.VALIDATE
4231
+ ),
3556
4232
  duplicates: [],
3557
4233
  eventId
3558
4234
  }),
4235
+ assign: (eventId, input = {}) => ({
4236
+ type: ActionType.ASSIGN,
4237
+ transactionId: input.transactionId ?? getUUID(),
4238
+ declaration: {},
4239
+ assignedTo: input.assignedTo ?? getUUID(),
4240
+ eventId
4241
+ }),
4242
+ unassign: (eventId, input = {}) => ({
4243
+ type: ActionType.UNASSIGN,
4244
+ transactionId: input.transactionId ?? getUUID(),
4245
+ declaration: {},
4246
+ assignedTo: null,
4247
+ eventId
4248
+ }),
3559
4249
  archive: (eventId, input = {}, isDuplicate) => ({
3560
4250
  type: ActionType.ARCHIVE,
3561
4251
  transactionId: input.transactionId ?? getUUID(),
3562
- data: input.data ?? {},
3563
- metadata: { isDuplicate: isDuplicate ?? false },
4252
+ declaration: {},
4253
+ // @TODO: Check whether generator is needed?
4254
+ annotation: { isDuplicate: isDuplicate ?? false },
3564
4255
  duplicates: [],
3565
4256
  eventId
3566
4257
  }),
3567
4258
  reject: (eventId, input = {}) => ({
3568
4259
  type: ActionType.REJECT,
3569
4260
  transactionId: input.transactionId ?? getUUID(),
3570
- data: input.data ?? {},
4261
+ declaration: {},
4262
+ annotation: input.annotation ?? generateActionAnnotationInput(
4263
+ tennisClubMembershipEvent,
4264
+ ActionType.REJECT
4265
+ ),
3571
4266
  duplicates: [],
3572
4267
  eventId
3573
4268
  }),
3574
4269
  register: (eventId, input = {}) => ({
3575
4270
  type: ActionType.REGISTER,
3576
4271
  transactionId: input.transactionId ?? getUUID(),
3577
- data: input.data ?? generateActionInput(tennisClubMembershipEvent, ActionType.REGISTER),
4272
+ declaration: input.declaration ?? generateActionDeclarationInput(
4273
+ tennisClubMembershipEvent,
4274
+ ActionType.REGISTER
4275
+ ),
4276
+ annotation: input.annotation ?? generateActionAnnotationInput(
4277
+ tennisClubMembershipEvent,
4278
+ ActionType.REGISTER
4279
+ ),
3578
4280
  eventId
3579
4281
  }),
3580
4282
  printCertificate: (eventId, input = {}) => ({
3581
4283
  type: ActionType.PRINT_CERTIFICATE,
3582
4284
  transactionId: input.transactionId ?? getUUID(),
3583
- data: input.data ?? generateActionInput(
4285
+ declaration: {},
4286
+ annotation: input.annotation ?? generateActionAnnotationInput(
3584
4287
  tennisClubMembershipEvent,
3585
4288
  ActionType.PRINT_CERTIFICATE
3586
4289
  ),
@@ -3590,17 +4293,21 @@ var eventPayloadGenerator = {
3590
4293
  request: (eventId, input = {}) => ({
3591
4294
  type: ActionType.REQUEST_CORRECTION,
3592
4295
  transactionId: input.transactionId ?? getUUID(),
3593
- data: input.data ?? generateActionInput(
4296
+ declaration: input.declaration ?? generateActionDeclarationInput(
4297
+ tennisClubMembershipEvent,
4298
+ ActionType.REQUEST_CORRECTION
4299
+ ),
4300
+ annotation: input.annotation ?? generateActionAnnotationInput(
3594
4301
  tennisClubMembershipEvent,
3595
4302
  ActionType.REQUEST_CORRECTION
3596
4303
  ),
3597
- metadata: {},
3598
4304
  eventId
3599
4305
  }),
3600
4306
  approve: (eventId, requestId, input = {}) => ({
3601
4307
  type: ActionType.APPROVE_CORRECTION,
3602
4308
  transactionId: input.transactionId ?? getUUID(),
3603
- data: input.data ?? generateActionInput(
4309
+ declaration: {},
4310
+ annotation: input.annotation ?? generateActionAnnotationInput(
3604
4311
  tennisClubMembershipEvent,
3605
4312
  ActionType.APPROVE_CORRECTION
3606
4313
  ),
@@ -3610,7 +4317,8 @@ var eventPayloadGenerator = {
3610
4317
  reject: (eventId, requestId, input = {}) => ({
3611
4318
  type: ActionType.REJECT_CORRECTION,
3612
4319
  transactionId: input.transactionId ?? getUUID(),
3613
- data: input.data ?? generateActionInput(
4320
+ declaration: {},
4321
+ annotation: input.annotation ?? generateActionAnnotationInput(
3614
4322
  tennisClubMembershipEvent,
3615
4323
  ActionType.REJECT_CORRECTION
3616
4324
  ),
@@ -3626,19 +4334,29 @@ function generateActionDocument({
3626
4334
  defaults = {}
3627
4335
  }) {
3628
4336
  const actionBase = {
4337
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4338
+ // @TODO: This should be fixed in the future.
3629
4339
  createdAt: new Date(Date.now() - 500).toISOString(),
3630
4340
  createdBy: getUUID(),
4341
+ createdByRole: "FIELD_AGENT",
3631
4342
  id: getUUID(),
3632
4343
  createdAtLocation: "TODO",
3633
- data: generateActionInput(configuration, action),
3634
- metadata: {},
3635
- ...defaults
4344
+ updatedAtLocation: "TODO",
4345
+ declaration: generateActionDeclarationInput(configuration, action),
4346
+ annotation: {},
4347
+ ...defaults,
4348
+ status: ActionStatus.Accepted,
4349
+ transactionId: getUUID()
3636
4350
  };
3637
4351
  switch (action) {
4352
+ case ActionType.READ:
4353
+ return { ...actionBase, type: action };
4354
+ case ActionType.MARKED_AS_DUPLICATE:
4355
+ return { ...actionBase, type: action };
3638
4356
  case ActionType.DECLARE:
3639
4357
  return { ...actionBase, type: action };
3640
4358
  case ActionType.UNASSIGN:
3641
- return { ...actionBase, type: action };
4359
+ return { ...actionBase, type: action, assignedTo: null };
3642
4360
  case ActionType.ASSIGN:
3643
4361
  return { ...actionBase, assignedTo: getUUID(), type: action };
3644
4362
  case ActionType.VALIDATE:
@@ -3659,14 +4377,13 @@ function generateActionDocument({
3659
4377
  return { ...actionBase, requestId: getUUID(), type: action };
3660
4378
  case ActionType.REJECT_CORRECTION:
3661
4379
  return { ...actionBase, requestId: getUUID(), type: action };
3662
- case ActionType.CUSTOM:
3663
- return { ...actionBase, type: action };
3664
4380
  case ActionType.REGISTER:
3665
4381
  return {
3666
4382
  ...actionBase,
3667
- type: action,
3668
- identifiers: { trackingId: getUUID(), registrationNumber: getUUID() }
4383
+ type: action
3669
4384
  };
4385
+ case ActionType.DELETE:
4386
+ case ActionType.DETECT_DUPLICATE:
3670
4387
  default:
3671
4388
  throw new Error(`Unsupported action type: ${action}`);
3672
4389
  }
@@ -3681,12 +4398,18 @@ function generateEventDocument({
3681
4398
  actions: actions.map(
3682
4399
  (action) => generateActionDocument({ configuration, action })
3683
4400
  ),
4401
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4402
+ // @TODO: This should be fixed in the future.
3684
4403
  createdAt: new Date(Date.now() - 1e3).toISOString(),
3685
4404
  id: getUUID(),
3686
- updatedAt: new Date(Date.now() - 1e3).toISOString()
4405
+ // Offset is needed so the createdAt timestamps for events, actions and drafts make logical sense in storybook tests.
4406
+ // @TODO: This should be fixed in the future.
4407
+ updatedAt: new Date(Date.now() - 1e3).toISOString(),
4408
+ dateOfEvent: configuration.dateOfEvent,
4409
+ updatedAtLocation: getUUID()
3687
4410
  };
3688
4411
  }
3689
- function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, data = {}) {
4412
+ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, declaration = {}) {
3690
4413
  const action = generateActionDocument({
3691
4414
  configuration: tennisClubMembershipEvent,
3692
4415
  action: actionType
@@ -3696,9 +4419,9 @@ function generateEventDraftDocument(eventId, actionType = ActionType.DECLARE, da
3696
4419
  transactionId: getUUID(),
3697
4420
  action: {
3698
4421
  ...action,
3699
- data: {
3700
- ...action.data,
3701
- ...data
4422
+ declaration: {
4423
+ ...action.declaration,
4424
+ ...declaration
3702
4425
  }
3703
4426
  },
3704
4427
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3712,10 +4435,12 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3712
4435
  createdAt: overrides.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3713
4436
  createdBy: overrides.createdBy ?? getUUID(),
3714
4437
  createdAtLocation: overrides.createdAtLocation ?? getUUID(),
3715
- modifiedAt: overrides.modifiedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4438
+ updatedAtLocation: overrides.updatedAtLocation ?? getUUID(),
4439
+ updatedAt: overrides.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
3716
4440
  assignedTo: overrides.assignedTo ?? null,
3717
4441
  updatedBy: overrides.updatedBy ?? getUUID(),
3718
- data: overrides.data ?? {
4442
+ updatedByUserRole: overrides.updatedByUserRole ?? "FIELD_AGENT",
4443
+ declaration: overrides.declaration ?? {
3719
4444
  "recommender.none": true,
3720
4445
  "applicant.firstname": "Danny",
3721
4446
  "applicant.surname": "Doe",
@@ -3723,6 +4448,11 @@ var eventQueryDataGenerator = (overrides = {}) => ({
3723
4448
  },
3724
4449
  trackingId: overrides.trackingId ?? "M3F8YQ"
3725
4450
  });
4451
+ var generateTranslationConfig = (message) => ({
4452
+ defaultMessage: message,
4453
+ description: "Description for ${message}",
4454
+ id: message
4455
+ });
3726
4456
 
3727
4457
  // ../commons/src/events/TemplateConfig.ts
3728
4458
  function isTemplateVariable(value) {
@@ -3741,7 +4471,9 @@ function isFieldValueWithoutTemplates(value) {
3741
4471
  return true;
3742
4472
  }
3743
4473
  function isFieldConfigDefaultValue(value) {
3744
- if (!value) return false;
4474
+ if (!value) {
4475
+ return false;
4476
+ }
3745
4477
  if (isFieldValue(value)) {
3746
4478
  return true;
3747
4479
  }
@@ -3753,3 +4485,213 @@ function isFieldConfigDefaultValue(value) {
3753
4485
  }
3754
4486
  return false;
3755
4487
  }
4488
+
4489
+ // ../commons/src/events/scopes.ts
4490
+ var import_lodash3 = require("lodash");
4491
+
4492
+ // ../commons/src/scopes.ts
4493
+ var SCOPES = {
4494
+ // TODO v1.8 legacy scopes
4495
+ NATLSYSADMIN: "natlsysadmin",
4496
+ BYPASSRATELIMIT: "bypassratelimit",
4497
+ DECLARE: "declare",
4498
+ REGISTER: "register",
4499
+ VALIDATE: "validate",
4500
+ DEMO: "demo",
4501
+ CERTIFY: "certify",
4502
+ PERFORMANCE: "performance",
4503
+ SYSADMIN: "sysadmin",
4504
+ TEAMS: "teams",
4505
+ CONFIG: "config",
4506
+ // systems / integrations
4507
+ WEBHOOK: "webhook",
4508
+ NATIONALID: "nationalId",
4509
+ NOTIFICATION_API: "notification-api",
4510
+ RECORDSEARCH: "recordsearch",
4511
+ /**
4512
+ * @TODO This is a temporary scope to be used for V2 Events custom events declaration
4513
+ */
4514
+ RECORD_DECLARE: "record.declare-birth",
4515
+ // declare
4516
+ RECORD_DECLARE_BIRTH: "record.declare-birth",
4517
+ RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
4518
+ RECORD_DECLARE_DEATH: "record.declare-death",
4519
+ RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
4520
+ RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
4521
+ RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
4522
+ RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
4523
+ RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
4524
+ RECORD_UNASSIGN_OTHERS: "record.unassign-others",
4525
+ // validate
4526
+ RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
4527
+ RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
4528
+ RECORD_DECLARATION_EDIT: "record.declaration-edit",
4529
+ RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
4530
+ RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
4531
+ RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
4532
+ // register
4533
+ RECORD_REGISTER: "record.register",
4534
+ // certify
4535
+ RECORD_EXPORT_RECORDS: "record.export-records",
4536
+ RECORD_DECLARATION_PRINT: "record.declaration-print",
4537
+ RECORD_PRINT_RECORDS_SUPPORTING_DOCUMENTS: "record.declaration-print-supporting-documents",
4538
+ RECORD_REGISTRATION_PRINT: "record.registration-print",
4539
+ // v1.8
4540
+ /**
4541
+ * This scope is used to **print and **issue certified copies of a record
4542
+ * after it has been registered. Previously Registrars had this permission.
4543
+ */
4544
+ RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
4545
+ RECORD_PRINT_CERTIFIED_COPIES: "record.registration-print-certified-copies",
4546
+ // v1.8
4547
+ RECORD_BULK_PRINT_CERTIFIED_COPIES: "record.registration-bulk-print-certified-copies",
4548
+ // v1.8
4549
+ RECORD_REGISTRATION_VERIFY_CERTIFIED_COPIES: "record.registration-verify-certified-copies",
4550
+ // v1.8
4551
+ // correct
4552
+ RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
4553
+ RECORD_REGISTRATION_CORRECT: "record.registration-correct",
4554
+ RECORD_REGISTRATION_REQUEST_REVOCATION: "record.registration-request-revocation",
4555
+ // v1.8
4556
+ RECORD_REGISTRATION_REVOKE: "record.registration-revoke",
4557
+ // v1.8
4558
+ RECORD_REGISTRATION_REQUEST_REINSTATEMENT: "record.registration-request-reinstatement",
4559
+ // v1.8
4560
+ RECORD_REGISTRATION_REINSTATE: "record.registration-reinstate",
4561
+ // v1.8
4562
+ RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
4563
+ RECORD_REJECT_REGISTRATION: "record.reject-registration",
4564
+ // search
4565
+ SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
4566
+ SEARCH_BIRTH: "search.birth",
4567
+ SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
4568
+ SEARCH_DEATH: "search.death",
4569
+ SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
4570
+ SEARCH_MARRIAGE: "search.marriage",
4571
+ // audit v1.8
4572
+ RECORD_READ: "record.read",
4573
+ RECORD_READ_AUDIT: "record.read-audit",
4574
+ RECORD_READ_COMMENTS: "record.read-comments",
4575
+ RECORD_CREATE_COMMENTS: "record.create-comments",
4576
+ // profile
4577
+ PROFILE_UPDATE: "profile.update",
4578
+ //v1.8
4579
+ PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
4580
+ // performance
4581
+ PERFORMANCE_READ: "performance.read",
4582
+ PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
4583
+ PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
4584
+ // organisation
4585
+ ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
4586
+ ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
4587
+ ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
4588
+ // user
4589
+ USER_READ: "user.read:all",
4590
+ USER_READ_MY_OFFICE: "user.read:my-office",
4591
+ USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
4592
+ USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
4593
+ //v1.8
4594
+ USER_CREATE: "user.create:all",
4595
+ USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
4596
+ USER_UPDATE: "user.update:all",
4597
+ USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
4598
+ // config
4599
+ CONFIG_UPDATE_ALL: "config.update:all",
4600
+ // data seeding
4601
+ USER_DATA_SEEDING: "user.data-seeding"
4602
+ };
4603
+ var scopes = Object.values(SCOPES);
4604
+
4605
+ // ../commons/src/events/scopes.ts
4606
+ function hasAnyOfScopes(a, b) {
4607
+ return (0, import_lodash3.intersection)(a, b).length > 0;
4608
+ }
4609
+ var CONFIG_GET_ALLOWED_SCOPES = [
4610
+ SCOPES.RECORD_DECLARE,
4611
+ SCOPES.RECORD_READ,
4612
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4613
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4614
+ SCOPES.RECORD_REGISTER,
4615
+ SCOPES.RECORD_EXPORT_RECORDS,
4616
+ SCOPES.CONFIG,
4617
+ SCOPES.CONFIG_UPDATE_ALL
4618
+ ];
4619
+ var CONFIG_SEARCH_ALLOWED_SCOPES = [
4620
+ SCOPES.SEARCH_BIRTH,
4621
+ SCOPES.SEARCH_DEATH,
4622
+ SCOPES.SEARCH_MARRIAGE,
4623
+ SCOPES.SEARCH_BIRTH_MY_JURISDICTION,
4624
+ SCOPES.SEARCH_DEATH_MY_JURISDICTION,
4625
+ SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION
4626
+ ];
4627
+ var ACTION_ALLOWED_SCOPES = {
4628
+ [ActionType.READ]: [
4629
+ SCOPES.RECORD_DECLARE,
4630
+ SCOPES.RECORD_READ,
4631
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4632
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
4633
+ SCOPES.RECORD_REGISTER,
4634
+ SCOPES.RECORD_EXPORT_RECORDS
4635
+ ],
4636
+ [ActionType.CREATE]: [
4637
+ SCOPES.RECORD_DECLARE,
4638
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
4639
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW
4640
+ ],
4641
+ [ActionType.NOTIFY]: [SCOPES.RECORD_SUBMIT_INCOMPLETE],
4642
+ [ActionType.DECLARE]: [
4643
+ SCOPES.RECORD_DECLARE,
4644
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4645
+ SCOPES.RECORD_REGISTER
4646
+ ],
4647
+ [ActionType.DELETE]: [SCOPES.RECORD_DECLARE],
4648
+ [ActionType.VALIDATE]: [
4649
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
4650
+ SCOPES.RECORD_REGISTER
4651
+ ],
4652
+ [ActionType.REGISTER]: [SCOPES.RECORD_REGISTER],
4653
+ [ActionType.PRINT_CERTIFICATE]: [SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES],
4654
+ [ActionType.REQUEST_CORRECTION]: [
4655
+ SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION
4656
+ ],
4657
+ [ActionType.REJECT_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4658
+ [ActionType.APPROVE_CORRECTION]: [SCOPES.RECORD_REGISTRATION_CORRECT],
4659
+ [ActionType.MARKED_AS_DUPLICATE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4660
+ [ActionType.ARCHIVE]: [SCOPES.RECORD_DECLARATION_ARCHIVE],
4661
+ [ActionType.REJECT]: [SCOPES.RECORD_SUBMIT_FOR_UPDATES],
4662
+ [ActionType.ASSIGN]: null,
4663
+ [ActionType.UNASSIGN]: null,
4664
+ [ActionType.DETECT_DUPLICATE]: []
4665
+ };
4666
+ function filterUnallowedActions(actions, userScopes) {
4667
+ const allowedActions = actions.filter((action) => {
4668
+ const requiredScopes = ACTION_ALLOWED_SCOPES[action];
4669
+ if (requiredScopes === null) {
4670
+ return true;
4671
+ }
4672
+ return hasAnyOfScopes(userScopes, requiredScopes);
4673
+ });
4674
+ const hasOtherAllowedActions = allowedActions.some(
4675
+ (action) => action !== ActionType.READ && action !== ActionType.ASSIGN && action !== ActionType.UNASSIGN
4676
+ );
4677
+ if (hasOtherAllowedActions) {
4678
+ return allowedActions;
4679
+ }
4680
+ return [ActionType.READ];
4681
+ }
4682
+
4683
+ // ../commons/src/event-config/event-configuration.ts
4684
+ function createEventFieldConfig(fieldId, options) {
4685
+ return {
4686
+ fieldId,
4687
+ options,
4688
+ config: { type: "EXACT" },
4689
+ fieldType: "event"
4690
+ };
4691
+ }
4692
+
4693
+ // ../commons/src/events/event.ts
4694
+ function eventFn(fieldId, options) {
4695
+ return createEventFieldConfig(fieldId, options);
4696
+ }
4697
+ var event = Object.assign(eventFn, createEventConditionals());