@opencrvs/toolkit 1.9.13-rc.56b7f8b → 1.9.13-rc.59bb028

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.
@@ -37,6 +37,7 @@ __export(conditionals_exports, {
37
37
  defineFormConditional: () => defineFormConditional,
38
38
  isEventFieldReference: () => isEventFieldReference,
39
39
  isFieldReference: () => isFieldReference,
40
+ isResolvableValueReference: () => isResolvableValueReference,
40
41
  never: () => never,
41
42
  not: () => not,
42
43
  now: () => now,
@@ -118,6 +119,1987 @@ function todayDateTimeValueSerializer() {
118
119
  return { $$now: true };
119
120
  }
120
121
 
122
+ // ../commons/src/events/FieldConfig.ts
123
+ var import_zod17 = require("zod");
124
+
125
+ // ../commons/src/events/Conditional.ts
126
+ var import_zod3 = require("zod");
127
+ var import_zod_openapi = require("zod-openapi");
128
+ (0, import_zod_openapi.extendZodWithOpenApi)(import_zod3.z);
129
+ var Conditional = import_zod3.z.custom((val) => typeof val === "object" && val !== null).openapi({
130
+ description: "JSON schema conditional configuration",
131
+ ref: "Conditional"
132
+ });
133
+ var ConditionalType = {
134
+ SHOW: "SHOW",
135
+ ENABLE: "ENABLE",
136
+ DISPLAY_ON_REVIEW: "DISPLAY_ON_REVIEW"
137
+ };
138
+ var ShowConditional = import_zod3.z.object({
139
+ type: import_zod3.z.literal(ConditionalType.SHOW),
140
+ conditional: Conditional
141
+ }).describe(
142
+ "If 'SHOW' conditional is defined, the component is shown to the user only if the condition is met"
143
+ );
144
+ var EnableConditional = import_zod3.z.object({
145
+ type: import_zod3.z.literal(ConditionalType.ENABLE),
146
+ conditional: Conditional
147
+ }).describe(
148
+ "If 'ENABLE' conditional is defined, the component is enabled only if the condition is met"
149
+ );
150
+ var ActionConditional = import_zod3.z.discriminatedUnion("type", [
151
+ // Action can be shown / hidden
152
+ ShowConditional,
153
+ // Action can be shown to the user in the list but as disabled
154
+ EnableConditional
155
+ ]);
156
+ var DisplayOnReviewConditional = import_zod3.z.object({
157
+ type: import_zod3.z.literal(ConditionalType.DISPLAY_ON_REVIEW),
158
+ conditional: Conditional
159
+ }).describe(
160
+ "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."
161
+ );
162
+ var FieldConditional = import_zod3.z.discriminatedUnion("type", [
163
+ // Field input can be shown / hidden
164
+ ShowConditional,
165
+ // Field input can be shown to the user but as disabled
166
+ EnableConditional,
167
+ // Field output can be shown / hidden on the review page
168
+ DisplayOnReviewConditional
169
+ ]).openapi({
170
+ description: "Field conditional configuration",
171
+ ref: "FieldConditional"
172
+ });
173
+
174
+ // ../commons/src/events/TranslationConfig.ts
175
+ var import_zod4 = require("zod");
176
+ var import_zod_openapi2 = require("zod-openapi");
177
+ (0, import_zod_openapi2.extendZodWithOpenApi)(import_zod4.z);
178
+ var TranslationConfig = import_zod4.z.object({
179
+ id: import_zod4.z.string().describe(
180
+ "The identifier of the translation referred in translation CSV files"
181
+ ),
182
+ defaultMessage: import_zod4.z.string().describe("Default translation message"),
183
+ description: import_zod4.z.string().describe(
184
+ "Describe the translation for a translator to be able to identify it."
185
+ )
186
+ }).openapi({
187
+ description: "Translation configuration",
188
+ ref: "TranslationConfig"
189
+ });
190
+
191
+ // ../commons/src/events/FieldType.ts
192
+ var import_zod5 = require("zod");
193
+ var FieldType = {
194
+ NAME: "NAME",
195
+ PHONE: "PHONE",
196
+ ID: "ID",
197
+ ADDRESS: "ADDRESS",
198
+ TEXT: "TEXT",
199
+ NUMBER: "NUMBER",
200
+ NUMBER_WITH_UNIT: "NUMBER_WITH_UNIT",
201
+ TEXTAREA: "TEXTAREA",
202
+ EMAIL: "EMAIL",
203
+ DATE: "DATE",
204
+ AGE: "AGE",
205
+ DATE_RANGE: "DATE_RANGE",
206
+ // // Internal use, only for search functionality
207
+ SELECT_DATE_RANGE: "SELECT_DATE_RANGE",
208
+ // Internal use, only for search functionality
209
+ TIME: "TIME",
210
+ PARAGRAPH: "PARAGRAPH",
211
+ PAGE_HEADER: "PAGE_HEADER",
212
+ RADIO_GROUP: "RADIO_GROUP",
213
+ FIELD_GROUP: "FIELD_GROUP",
214
+ FILE: "FILE",
215
+ FILE_WITH_OPTIONS: "FILE_WITH_OPTIONS",
216
+ BULLET_LIST: "BULLET_LIST",
217
+ CHECKBOX: "CHECKBOX",
218
+ SELECT: "SELECT",
219
+ COUNTRY: "COUNTRY",
220
+ LOCATION: "LOCATION",
221
+ DIVIDER: "DIVIDER",
222
+ ADMINISTRATIVE_AREA: "ADMINISTRATIVE_AREA",
223
+ FACILITY: "FACILITY",
224
+ OFFICE: "OFFICE",
225
+ SIGNATURE: "SIGNATURE",
226
+ DATA: "DATA",
227
+ BUTTON: "BUTTON",
228
+ SEARCH: "SEARCH",
229
+ ALPHA_PRINT_BUTTON: "ALPHA_PRINT_BUTTON",
230
+ HTTP: "HTTP",
231
+ LINK_BUTTON: "LINK_BUTTON",
232
+ VERIFICATION_STATUS: "VERIFICATION_STATUS",
233
+ QUERY_PARAM_READER: "QUERY_PARAM_READER",
234
+ QR_READER: "QR_READER",
235
+ ID_READER: "ID_READER",
236
+ LOADER: "LOADER"
237
+ };
238
+ var FileFieldType = import_zod5.z.enum([
239
+ FieldType.FILE,
240
+ FieldType.FILE_WITH_OPTIONS,
241
+ FieldType.SIGNATURE
242
+ ]);
243
+ var fieldTypes = Object.values(FieldType);
244
+ var compositeFieldTypes = [
245
+ FieldType.NAME,
246
+ FieldType.DATE_RANGE,
247
+ FieldType.ADDRESS,
248
+ FieldType.FILE_WITH_OPTIONS,
249
+ FieldType.FILE,
250
+ FieldType.ID_READER,
251
+ FieldType.DATA
252
+ ];
253
+ var FieldTypesToHideInReview = [
254
+ FieldType.BULLET_LIST,
255
+ FieldType.DIVIDER,
256
+ FieldType.PAGE_HEADER,
257
+ FieldType.PARAGRAPH,
258
+ FieldType.ID_READER,
259
+ FieldType.LOADER,
260
+ FieldType.HTTP,
261
+ FieldType.QUERY_PARAM_READER,
262
+ FieldType.DATA
263
+ ];
264
+
265
+ // ../commons/src/events/FieldValue.ts
266
+ var import_zod9 = require("zod");
267
+
268
+ // ../commons/src/documents.ts
269
+ var import_zod6 = require("zod");
270
+ var import_zod_openapi3 = require("zod-openapi");
271
+ (0, import_zod_openapi3.extendZodWithOpenApi)(import_zod6.z);
272
+ var FullDocumentUrl = import_zod6.z.string().brand("FullDocumentUrl").describe(
273
+ "A full url with protocol, host, bucket name, starting from the root of the S3 server, https://minio.opencrvs.com/bucket-name/document-id.jpg"
274
+ );
275
+ var FullDocumentPath = import_zod6.z.string().transform((val) => val.startsWith("/") ? val : `/${val}`).openapi({ effectType: "input", type: "string" }).describe(
276
+ "A full absolute path with bucket name, starting from the root of the S3 server, /bucket-name/document-id.jpg"
277
+ );
278
+ var DocumentPath = import_zod6.z.string().brand("DocumentPath").describe(
279
+ "A full identifier starting from the root of the S3 bucket, e.g. /document-id.jpg or /directory/document-id.jpg but never /bucket-name/document-id.jpg"
280
+ );
281
+
282
+ // ../commons/src/events/CompositeFieldValue.ts
283
+ var import_zod7 = require("zod");
284
+ var AddressType = {
285
+ DOMESTIC: "DOMESTIC",
286
+ INTERNATIONAL: "INTERNATIONAL"
287
+ };
288
+ var FileFieldValue = import_zod7.z.object({
289
+ path: FullDocumentPath,
290
+ originalFilename: import_zod7.z.string(),
291
+ type: import_zod7.z.string()
292
+ });
293
+ var NameFieldValue = import_zod7.z.object({
294
+ firstname: import_zod7.z.string(),
295
+ surname: import_zod7.z.string(),
296
+ middlename: import_zod7.z.string().optional()
297
+ });
298
+ var NameFieldUpdateValue = import_zod7.z.object({
299
+ firstname: import_zod7.z.string().nullish(),
300
+ surname: import_zod7.z.string().nullish(),
301
+ middlename: import_zod7.z.string().nullish()
302
+ }).or(import_zod7.z.null()).or(import_zod7.z.undefined());
303
+ var StreetLevelDetailsValue = import_zod7.z.record(import_zod7.z.string(), import_zod7.z.string()).optional();
304
+ var StreetLevelDetailsUpdateValue = import_zod7.z.record(import_zod7.z.string(), import_zod7.z.string().nullable()).nullish();
305
+ var BaseAddressFieldValue = import_zod7.z.object({
306
+ country: import_zod7.z.string(),
307
+ streetLevelDetails: StreetLevelDetailsValue
308
+ });
309
+ var BaseAddressFieldUpdateValue = import_zod7.z.object({
310
+ country: import_zod7.z.string().nullish(),
311
+ streetLevelDetails: StreetLevelDetailsUpdateValue
312
+ });
313
+ var DomesticAddressFieldValue = BaseAddressFieldValue.extend({
314
+ addressType: import_zod7.z.literal(AddressType.DOMESTIC),
315
+ administrativeArea: import_zod7.z.string().uuid()
316
+ });
317
+ var InternationalAddressFieldValue = BaseAddressFieldValue.extend({
318
+ addressType: import_zod7.z.literal(AddressType.INTERNATIONAL)
319
+ });
320
+ var AddressFieldValue = import_zod7.z.discriminatedUnion("addressType", [
321
+ DomesticAddressFieldValue,
322
+ InternationalAddressFieldValue
323
+ ]);
324
+ var DomesticAddressUpdateFieldValue = BaseAddressFieldUpdateValue.extend({
325
+ addressType: import_zod7.z.literal(AddressType.DOMESTIC),
326
+ administrativeArea: import_zod7.z.string().uuid().nullish()
327
+ /* Leaf level admin structure */
328
+ });
329
+ var InternationalAddressUpdateFieldValue = BaseAddressFieldUpdateValue.extend(
330
+ {
331
+ addressType: import_zod7.z.literal(AddressType.INTERNATIONAL)
332
+ }
333
+ );
334
+ var AddressFieldUpdateValue = import_zod7.z.discriminatedUnion("addressType", [
335
+ DomesticAddressUpdateFieldValue,
336
+ InternationalAddressUpdateFieldValue
337
+ ]).nullish();
338
+ var FileFieldValueWithOption = import_zod7.z.object({
339
+ path: FullDocumentPath,
340
+ originalFilename: import_zod7.z.string(),
341
+ type: import_zod7.z.string(),
342
+ option: import_zod7.z.string()
343
+ });
344
+ var FileFieldWithOptionValue = import_zod7.z.array(FileFieldValueWithOption);
345
+ var HttpFieldValue = import_zod7.z.object({
346
+ loading: import_zod7.z.boolean(),
347
+ error: import_zod7.z.object({ statusCode: import_zod7.z.number(), message: import_zod7.z.string() }).nullish(),
348
+ data: import_zod7.z.any()
349
+ });
350
+ var HttpFieldUpdateValue = import_zod7.z.object({
351
+ loading: import_zod7.z.boolean().nullish(),
352
+ error: import_zod7.z.object({ statusCode: import_zod7.z.number(), message: import_zod7.z.string() }).nullish(),
353
+ data: import_zod7.z.any().nullish()
354
+ }).or(import_zod7.z.null()).or(import_zod7.z.undefined());
355
+ var QueryParamReaderFieldValue = import_zod7.z.object({
356
+ data: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.string())
357
+ }).nullish();
358
+ var QueryParamReaderFieldUpdateValue = import_zod7.z.object({
359
+ data: import_zod7.z.record(import_zod7.z.string(), import_zod7.z.string())
360
+ });
361
+ var ReadDataValue = import_zod7.z.object({
362
+ data: import_zod7.z.any()
363
+ });
364
+ var QrReaderFieldValue = ReadDataValue;
365
+ var IdReaderFieldValue = ReadDataValue;
366
+ var NumberWithUnitFieldValue = import_zod7.z.object({
367
+ numericValue: import_zod7.z.number(),
368
+ unit: import_zod7.z.string()
369
+ });
370
+ var NumberWithUnitFieldUpdateValue = import_zod7.z.object({
371
+ numericValue: import_zod7.z.number().optional(),
372
+ unit: import_zod7.z.string().optional()
373
+ });
374
+
375
+ // ../commons/src/events/PlainDate.ts
376
+ var import_zod8 = require("zod");
377
+ var PlainDate = import_zod8.z.string().date().brand("PlainDate").describe("Date in the format YYYY-MM-DD");
378
+
379
+ // ../commons/src/events/FieldValue.ts
380
+ var TextValue = import_zod9.z.string();
381
+ var NonEmptyTextValue = TextValue.min(1);
382
+ var AgeValue = import_zod9.z.object({
383
+ age: import_zod9.z.number(),
384
+ asOfDateRef: import_zod9.z.string()
385
+ });
386
+ var AgeUpdateValue = AgeValue.optional().nullable();
387
+ var TimeValue = import_zod9.z.string().regex(/^([01][0-9]|2[0-3]):[0-5][0-9]$/);
388
+ var DatetimeValue = import_zod9.z.string().datetime();
389
+ var SelectDateRangeValue = import_zod9.z.enum([
390
+ "last7Days",
391
+ "last30Days",
392
+ "last90Days",
393
+ "last365Days"
394
+ ]);
395
+ var DateRangeFieldValue = import_zod9.z.object({
396
+ start: PlainDate,
397
+ end: PlainDate
398
+ }).or(PlainDate).describe(
399
+ "Date range with start and end dates in the format YYYY-MM-DD. Inclusive start, exclusive end."
400
+ );
401
+ var EmailValue = import_zod9.z.string().email();
402
+ var CheckboxFieldValue = import_zod9.z.boolean();
403
+ var NumberFieldValue = import_zod9.z.number();
404
+ var SignatureFieldValue = import_zod9.z.string();
405
+ var ButtonFieldValue = import_zod9.z.number();
406
+ var VerificationStatusValue = import_zod9.z.enum([
407
+ "verified",
408
+ "authenticated",
409
+ "failed",
410
+ "pending"
411
+ ]);
412
+ var LeafFieldValues = import_zod9.z.union([
413
+ AddressFieldValue,
414
+ TextValue,
415
+ PlainDate,
416
+ AgeValue,
417
+ TimeValue,
418
+ DateRangeFieldValue,
419
+ SelectDateRangeValue,
420
+ CheckboxFieldValue,
421
+ NumberFieldValue,
422
+ FileFieldValue,
423
+ FileFieldWithOptionValue,
424
+ NameFieldValue,
425
+ NameFieldUpdateValue,
426
+ ButtonFieldValue,
427
+ HttpFieldValue,
428
+ VerificationStatusValue,
429
+ QueryParamReaderFieldValue,
430
+ QrReaderFieldValue,
431
+ IdReaderFieldValue,
432
+ NumberWithUnitFieldValue,
433
+ NumberWithUnitFieldUpdateValue
434
+ ]);
435
+ var FieldGroupValue = import_zod9.z.record(import_zod9.z.string(), LeafFieldValues);
436
+ var DataFieldValue = import_zod9.z.object({
437
+ data: import_zod9.z.record(import_zod9.z.string(), LeafFieldValues)
438
+ }).nullish();
439
+ var FieldValue = import_zod9.z.union([
440
+ LeafFieldValues,
441
+ DataFieldValue,
442
+ FieldGroupValue
443
+ ]);
444
+ var PRIORITY_ORDER = [
445
+ "NameFieldUpdateValue",
446
+ "DateRangeFieldValue",
447
+ "PlainDate",
448
+ "TextValue",
449
+ "TimeValue",
450
+ "AgeUpdateValue",
451
+ "AddressFieldUpdateValue",
452
+ "SelectDateRangeValue",
453
+ "CheckboxFieldValue",
454
+ "NumberFieldValue",
455
+ "NumberWithUnitFieldUpdateValue",
456
+ "FileFieldValue",
457
+ "FileFieldWithOptionValue",
458
+ "DataFieldValue",
459
+ "GroupFieldValue"
460
+ ];
461
+ function schemaPriority(schema) {
462
+ const name = schema._def?.description;
463
+ const idx = PRIORITY_ORDER.indexOf(name);
464
+ return idx === -1 ? 9999 : idx;
465
+ }
466
+ function safeUnion(schemas) {
467
+ return import_zod9.z.custom((val) => {
468
+ const successful = schemas.filter((s) => s.safeParse(val).success);
469
+ if (successful.length === 1) {
470
+ return true;
471
+ }
472
+ if (successful.length === 0) {
473
+ return false;
474
+ }
475
+ successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
476
+ const best = successful[0];
477
+ return best.safeParse(val).success;
478
+ });
479
+ }
480
+ var FieldUpdateValue = safeUnion([
481
+ TextValue.describe("TextValue"),
482
+ PlainDate.describe("PlainDate"),
483
+ TimeValue.describe("TimeValue"),
484
+ AgeUpdateValue.describe("AgeUpdateValue"),
485
+ AddressFieldUpdateValue.describe("AddressFieldUpdateValue"),
486
+ DateRangeFieldValue.describe("DateRangeFieldValue"),
487
+ SelectDateRangeValue.describe("SelectDateRangeValue"),
488
+ CheckboxFieldValue.describe("CheckboxFieldValue"),
489
+ NumberFieldValue.describe("NumberFieldValue"),
490
+ NumberWithUnitFieldUpdateValue.describe("NumberWithUnitFieldUpdateValue"),
491
+ FileFieldValue.describe("FileFieldValue"),
492
+ FileFieldWithOptionValue.describe("FileFieldWithOptionValue"),
493
+ DataFieldValue.describe("DataFieldValue"),
494
+ FieldGroupValue.describe("GroupFieldValue"),
495
+ NameFieldUpdateValue.describe("NameFieldUpdateValue"),
496
+ HttpFieldUpdateValue.describe("HttpFieldUpdateValue"),
497
+ QueryParamReaderFieldUpdateValue.describe("QueryParamReaderFieldUpdateValue")
498
+ ]);
499
+
500
+ // ../commons/src/events/FieldConfig.ts
501
+ var import_zod_openapi6 = require("zod-openapi");
502
+
503
+ // ../commons/src/uuid.ts
504
+ var import_uuid = require("uuid");
505
+ var import_zod10 = require("zod");
506
+ var UUID = import_zod10.z.string().uuid().brand("UUID");
507
+
508
+ // ../commons/src/events/EventIndex.ts
509
+ var import_zod16 = require("zod");
510
+
511
+ // ../commons/src/events/EventMetadata.ts
512
+ var import_zod15 = require("zod");
513
+
514
+ // ../commons/src/events/ActionType.ts
515
+ var import_zod11 = require("zod");
516
+ var ActionType = {
517
+ // Pre-declaration actions
518
+ DELETE: "DELETE",
519
+ CREATE: "CREATE",
520
+ NOTIFY: "NOTIFY",
521
+ // Declaration actions
522
+ DECLARE: "DECLARE",
523
+ VALIDATE: "VALIDATE",
524
+ REGISTER: "REGISTER",
525
+ // Declaration system actions. Non-configurable.
526
+ DUPLICATE_DETECTED: "DUPLICATE_DETECTED",
527
+ REJECT: "REJECT",
528
+ // REJECT_DECLARATION
529
+ MARK_AS_DUPLICATE: "MARK_AS_DUPLICATE",
530
+ MARK_AS_NOT_DUPLICATE: "MARK_AS_NOT_DUPLICATE",
531
+ ARCHIVE: "ARCHIVE",
532
+ // Record actions
533
+ PRINT_CERTIFICATE: "PRINT_CERTIFICATE",
534
+ REQUEST_CORRECTION: "REQUEST_CORRECTION",
535
+ REJECT_CORRECTION: "REJECT_CORRECTION",
536
+ APPROVE_CORRECTION: "APPROVE_CORRECTION",
537
+ // General actions
538
+ READ: "READ",
539
+ ASSIGN: "ASSIGN",
540
+ UNASSIGN: "UNASSIGN"
541
+ };
542
+ var ConfirmableActions = [
543
+ ActionType.NOTIFY,
544
+ ActionType.DECLARE,
545
+ ActionType.VALIDATE,
546
+ ActionType.REGISTER,
547
+ ActionType.REJECT,
548
+ ActionType.ARCHIVE,
549
+ ActionType.PRINT_CERTIFICATE,
550
+ ActionType.REQUEST_CORRECTION,
551
+ ActionType.APPROVE_CORRECTION,
552
+ ActionType.REJECT_CORRECTION
553
+ ];
554
+ var ActionTypes = import_zod11.z.enum([
555
+ "DELETE",
556
+ "CREATE",
557
+ "NOTIFY",
558
+ "DECLARE",
559
+ "VALIDATE",
560
+ "REGISTER",
561
+ "DUPLICATE_DETECTED",
562
+ "REJECT",
563
+ "MARK_AS_DUPLICATE",
564
+ "MARK_AS_NOT_DUPLICATE",
565
+ "ARCHIVE",
566
+ "PRINT_CERTIFICATE",
567
+ "REQUEST_CORRECTION",
568
+ "REJECT_CORRECTION",
569
+ "APPROVE_CORRECTION",
570
+ "READ",
571
+ "ASSIGN",
572
+ "UNASSIGN"
573
+ ]);
574
+ var declarationActionValues = [
575
+ ActionTypes.enum.DECLARE,
576
+ ActionTypes.enum.VALIDATE,
577
+ ActionTypes.enum.REGISTER,
578
+ ActionTypes.enum.NOTIFY,
579
+ ActionTypes.enum.DUPLICATE_DETECTED
580
+ ];
581
+ var DeclarationActions = ActionTypes.extract(declarationActionValues);
582
+ var declarationUpdateActionValues = [
583
+ ...declarationActionValues,
584
+ ActionTypes.enum.REQUEST_CORRECTION
585
+ ];
586
+ var DeclarationUpdateActions = ActionTypes.extract(
587
+ declarationUpdateActionValues
588
+ );
589
+ var annotationActions = ActionTypes.exclude(declarationActionValues);
590
+ var writeActions = ActionTypes.exclude([
591
+ ActionType.CREATE,
592
+ ActionType.READ,
593
+ ActionType.ASSIGN,
594
+ ActionType.UNASSIGN
595
+ ]);
596
+ var workqueueActions = ActionTypes.exclude([
597
+ ActionType.CREATE,
598
+ ActionType.NOTIFY,
599
+ ActionType.DUPLICATE_DETECTED,
600
+ ActionType.REJECT,
601
+ ActionType.MARK_AS_NOT_DUPLICATE,
602
+ ActionType.REJECT_CORRECTION,
603
+ ActionType.APPROVE_CORRECTION
604
+ ]);
605
+ var META_ACTIONS = [
606
+ ActionType.ASSIGN,
607
+ ActionType.UNASSIGN,
608
+ ActionType.READ
609
+ ];
610
+
611
+ // ../commons/src/events/ActionDocument.ts
612
+ var import_zod14 = require("zod");
613
+ var import_zod_openapi4 = require("zod-openapi");
614
+
615
+ // ../commons/src/events/CreatedAtLocation.ts
616
+ var CreatedAtLocation = UUID.nullish();
617
+
618
+ // ../commons/src/authentication.ts
619
+ var import_jwt_decode = __toESM(require("jwt-decode"));
620
+ var import_zod13 = require("zod");
621
+
622
+ // ../commons/src/scopes.ts
623
+ var import_zod12 = require("zod");
624
+ var SCOPES = {
625
+ // TODO v1.8 legacy scopes
626
+ BYPASSRATELIMIT: "bypassratelimit",
627
+ REGISTER: "register",
628
+ DEMO: "demo",
629
+ CONFIG: "config",
630
+ // systems / integrations
631
+ WEBHOOK: "webhook",
632
+ NATIONALID: "nationalId",
633
+ NOTIFICATION_API: "notification-api",
634
+ RECORDSEARCH: "recordsearch",
635
+ RECORD_IMPORT: "record.import",
636
+ RECORD_EXPORT: "record.export",
637
+ RECORD_REINDEX: "record.reindex",
638
+ // declare
639
+ RECORD_DECLARE_BIRTH: "record.declare-birth",
640
+ RECORD_DECLARE_BIRTH_MY_JURISDICTION: "record.declare-birth:my-jurisdiction",
641
+ RECORD_DECLARE_DEATH: "record.declare-death",
642
+ RECORD_DECLARE_DEATH_MY_JURISDICTION: "record.declare-death:my-jurisdiction",
643
+ RECORD_DECLARE_MARRIAGE: "record.declare-marriage",
644
+ RECORD_DECLARE_MARRIAGE_MY_JURISDICTION: "record.declare-marriage:my-jurisdiction",
645
+ RECORD_SUBMIT_INCOMPLETE: "record.declaration-submit-incomplete",
646
+ // @todo: should this record be removed from events v2?
647
+ RECORD_SUBMIT_FOR_REVIEW: "record.declaration-submit-for-review",
648
+ RECORD_UNASSIGN_OTHERS: "record.unassign-others",
649
+ // validate
650
+ RECORD_SUBMIT_FOR_APPROVAL: "record.declaration-submit-for-approval",
651
+ RECORD_SUBMIT_FOR_UPDATES: "record.declaration-submit-for-updates",
652
+ RECORD_DECLARATION_EDIT: "record.declaration-edit",
653
+ RECORD_REVIEW_DUPLICATES: "record.review-duplicates",
654
+ RECORD_DECLARATION_ARCHIVE: "record.declaration-archive",
655
+ RECORD_DECLARATION_REINSTATE: "record.declaration-reinstate",
656
+ // register
657
+ RECORD_REGISTER: "record.register",
658
+ /**
659
+ * This scope is used to **print and **issue certified copies of a record
660
+ * after it has been registered. Previously Registrars had this permission.
661
+ */
662
+ RECORD_PRINT_ISSUE_CERTIFIED_COPIES: "record.registration-print&issue-certified-copies",
663
+ // correct
664
+ RECORD_REGISTRATION_REQUEST_CORRECTION: "record.registration-request-correction",
665
+ RECORD_REGISTRATION_CORRECT: "record.registration-correct",
666
+ RECORD_CONFIRM_REGISTRATION: "record.confirm-registration",
667
+ RECORD_REJECT_REGISTRATION: "record.reject-registration",
668
+ // search
669
+ SEARCH_BIRTH_MY_JURISDICTION: "search.birth:my-jurisdiction",
670
+ SEARCH_BIRTH: "search.birth",
671
+ SEARCH_DEATH_MY_JURISDICTION: "search.death:my-jurisdiction",
672
+ SEARCH_DEATH: "search.death",
673
+ SEARCH_MARRIAGE_MY_JURISDICTION: "search.marriage:my-jurisdiction",
674
+ SEARCH_MARRIAGE: "search.marriage",
675
+ // audit v1.8
676
+ RECORD_READ: "record.read",
677
+ // profile
678
+ PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
679
+ // performance
680
+ PERFORMANCE_READ: "performance.read",
681
+ PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
682
+ PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
683
+ // organisation
684
+ ORGANISATION_READ_LOCATIONS: "organisation.read-locations:all",
685
+ ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
686
+ ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
687
+ // user
688
+ USER_READ: "user.read:all",
689
+ USER_READ_MY_OFFICE: "user.read:my-office",
690
+ USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
691
+ USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
692
+ //v1.8
693
+ USER_CREATE: "user.create:all",
694
+ USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
695
+ USER_UPDATE: "user.update:all",
696
+ USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction",
697
+ // config
698
+ CONFIG_UPDATE_ALL: "config.update:all",
699
+ // data seeding
700
+ USER_DATA_SEEDING: "user.data-seeding"
701
+ };
702
+ var LegacyScopes = import_zod12.z.union([
703
+ import_zod12.z.literal(SCOPES.BYPASSRATELIMIT),
704
+ import_zod12.z.literal(SCOPES.REGISTER),
705
+ import_zod12.z.literal(SCOPES.DEMO),
706
+ import_zod12.z.literal(SCOPES.CONFIG)
707
+ ]);
708
+ var IntegrationScopes = import_zod12.z.union([
709
+ import_zod12.z.literal(SCOPES.WEBHOOK),
710
+ import_zod12.z.literal(SCOPES.NATIONALID),
711
+ import_zod12.z.literal(SCOPES.NOTIFICATION_API),
712
+ import_zod12.z.literal(SCOPES.RECORDSEARCH)
713
+ ]);
714
+ var InternalOperationsScopes = import_zod12.z.union([
715
+ import_zod12.z.literal(SCOPES.RECORD_REINDEX),
716
+ import_zod12.z.literal(SCOPES.RECORD_IMPORT)
717
+ ]);
718
+ var DeclareScopes = import_zod12.z.union([
719
+ import_zod12.z.literal(SCOPES.RECORD_DECLARE_BIRTH),
720
+ import_zod12.z.literal(SCOPES.RECORD_DECLARE_BIRTH_MY_JURISDICTION),
721
+ import_zod12.z.literal(SCOPES.RECORD_DECLARE_DEATH),
722
+ import_zod12.z.literal(SCOPES.RECORD_DECLARE_DEATH_MY_JURISDICTION),
723
+ import_zod12.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE),
724
+ import_zod12.z.literal(SCOPES.RECORD_DECLARE_MARRIAGE_MY_JURISDICTION),
725
+ import_zod12.z.literal(SCOPES.RECORD_SUBMIT_INCOMPLETE),
726
+ import_zod12.z.literal(SCOPES.RECORD_SUBMIT_FOR_REVIEW)
727
+ ]);
728
+ var UnassignScope = import_zod12.z.literal(SCOPES.RECORD_UNASSIGN_OTHERS);
729
+ var ValidateScopes = import_zod12.z.union([
730
+ import_zod12.z.literal(SCOPES.RECORD_SUBMIT_FOR_APPROVAL),
731
+ import_zod12.z.literal(SCOPES.RECORD_SUBMIT_FOR_UPDATES),
732
+ import_zod12.z.literal(SCOPES.RECORD_DECLARATION_EDIT),
733
+ import_zod12.z.literal(SCOPES.RECORD_REVIEW_DUPLICATES),
734
+ import_zod12.z.literal(SCOPES.RECORD_DECLARATION_ARCHIVE),
735
+ import_zod12.z.literal(SCOPES.RECORD_DECLARATION_REINSTATE)
736
+ ]);
737
+ var RegisterScope = import_zod12.z.literal(SCOPES.RECORD_REGISTER);
738
+ var CorrectionScopes = import_zod12.z.union([
739
+ import_zod12.z.literal(SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION),
740
+ import_zod12.z.literal(SCOPES.RECORD_REGISTRATION_CORRECT),
741
+ import_zod12.z.literal(SCOPES.RECORD_CONFIRM_REGISTRATION),
742
+ import_zod12.z.literal(SCOPES.RECORD_REJECT_REGISTRATION)
743
+ ]);
744
+ var SearchScopes = import_zod12.z.union([
745
+ import_zod12.z.literal(SCOPES.SEARCH_BIRTH_MY_JURISDICTION),
746
+ import_zod12.z.literal(SCOPES.SEARCH_BIRTH),
747
+ import_zod12.z.literal(SCOPES.SEARCH_DEATH_MY_JURISDICTION),
748
+ import_zod12.z.literal(SCOPES.SEARCH_DEATH),
749
+ import_zod12.z.literal(SCOPES.SEARCH_MARRIAGE_MY_JURISDICTION),
750
+ import_zod12.z.literal(SCOPES.SEARCH_MARRIAGE)
751
+ ]);
752
+ var AuditScopes = import_zod12.z.literal(SCOPES.RECORD_READ);
753
+ var PerformanceScopes = import_zod12.z.union([
754
+ import_zod12.z.literal(SCOPES.PERFORMANCE_READ),
755
+ import_zod12.z.literal(SCOPES.PERFORMANCE_READ_DASHBOARDS),
756
+ import_zod12.z.literal(SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS)
757
+ ]);
758
+ var OrganisationScopes = import_zod12.z.union([
759
+ import_zod12.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS),
760
+ import_zod12.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE),
761
+ import_zod12.z.literal(SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION)
762
+ ]);
763
+ var UserScopes = import_zod12.z.union([
764
+ import_zod12.z.literal(SCOPES.USER_READ),
765
+ import_zod12.z.literal(SCOPES.USER_READ_MY_OFFICE),
766
+ import_zod12.z.literal(SCOPES.USER_READ_MY_JURISDICTION),
767
+ import_zod12.z.literal(SCOPES.USER_READ_ONLY_MY_AUDIT),
768
+ import_zod12.z.literal(SCOPES.USER_CREATE),
769
+ import_zod12.z.literal(SCOPES.USER_CREATE_MY_JURISDICTION),
770
+ import_zod12.z.literal(SCOPES.USER_UPDATE),
771
+ import_zod12.z.literal(SCOPES.USER_UPDATE_MY_JURISDICTION)
772
+ ]);
773
+ var ConfigScope = import_zod12.z.literal(SCOPES.CONFIG_UPDATE_ALL);
774
+ var DataSeedingScope = import_zod12.z.literal(SCOPES.USER_DATA_SEEDING);
775
+ var LiteralScopes = import_zod12.z.union([
776
+ LegacyScopes,
777
+ IntegrationScopes,
778
+ UnassignScope,
779
+ DeclareScopes,
780
+ ValidateScopes,
781
+ RegisterScope,
782
+ import_zod12.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
783
+ CorrectionScopes,
784
+ SearchScopes,
785
+ AuditScopes,
786
+ import_zod12.z.literal(SCOPES.PROFILE_ELECTRONIC_SIGNATURE),
787
+ PerformanceScopes,
788
+ OrganisationScopes,
789
+ UserScopes,
790
+ ConfigScope,
791
+ DataSeedingScope,
792
+ InternalOperationsScopes
793
+ ]);
794
+ var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
795
+ var rawConfigurableScope = import_zod12.z.string().regex(rawConfigurableScopeRegex);
796
+ var CreateUserScope = import_zod12.z.object({
797
+ type: import_zod12.z.literal("user.create"),
798
+ options: import_zod12.z.object({
799
+ role: import_zod12.z.array(import_zod12.z.string())
800
+ })
801
+ });
802
+ var EditUserScope = import_zod12.z.object({
803
+ type: import_zod12.z.literal("user.edit"),
804
+ options: import_zod12.z.object({
805
+ role: import_zod12.z.array(import_zod12.z.string())
806
+ })
807
+ });
808
+ var WorkqueueScope = import_zod12.z.object({
809
+ type: import_zod12.z.literal("workqueue"),
810
+ options: import_zod12.z.object({
811
+ id: import_zod12.z.array(import_zod12.z.string())
812
+ })
813
+ });
814
+ var SearchScope = import_zod12.z.object({
815
+ type: import_zod12.z.literal("search"),
816
+ options: import_zod12.z.object({
817
+ event: import_zod12.z.array(import_zod12.z.string()).length(1),
818
+ access: import_zod12.z.array(import_zod12.z.enum(["my-jurisdiction", "all"])).length(1)
819
+ })
820
+ });
821
+ var PrintCertifiedCopiesScope = import_zod12.z.object({
822
+ type: import_zod12.z.literal("record.registered.print-certified-copies"),
823
+ options: import_zod12.z.object({
824
+ event: import_zod12.z.array(import_zod12.z.string()).describe("Event type, e.g. birth, death"),
825
+ templates: import_zod12.z.array(import_zod12.z.string()).optional().describe(
826
+ "Template IDs for certified copies. If not provided, all templates will be used."
827
+ )
828
+ })
829
+ });
830
+ var RecordScopeType = import_zod12.z.enum([
831
+ "record.create",
832
+ "record.read",
833
+ "record.declare",
834
+ "record.notify",
835
+ "record.declared.validate",
836
+ "record.declared.reject",
837
+ "record.declared.archive",
838
+ "record.declared.review-duplicates",
839
+ "record.register",
840
+ "record.registered.request-correction",
841
+ "record.registered.correct",
842
+ "record.unassign-others"
843
+ ]);
844
+ var RecordScope = import_zod12.z.object({
845
+ type: RecordScopeType,
846
+ options: import_zod12.z.object({
847
+ event: import_zod12.z.array(import_zod12.z.string()).describe("Event type, e.g. birth, death")
848
+ })
849
+ }).describe(
850
+ "Scopes used to check user's permission to perform actions on a record."
851
+ );
852
+ var ConfigurableRawScopes = import_zod12.z.discriminatedUnion("type", [
853
+ SearchScope,
854
+ PrintCertifiedCopiesScope,
855
+ CreateUserScope,
856
+ EditUserScope,
857
+ WorkqueueScope,
858
+ RecordScope
859
+ ]);
860
+ var scopes = Object.values(SCOPES);
861
+ var ActionScopes = import_zod12.z.union([
862
+ DeclareScopes,
863
+ ValidateScopes,
864
+ RegisterScope,
865
+ import_zod12.z.literal(SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES),
866
+ CorrectionScopes
867
+ ]);
868
+
869
+ // ../commons/src/authentication.ts
870
+ var DEFAULT_ROLES_DEFINITION = [
871
+ {
872
+ id: "FIELD_AGENT",
873
+ label: {
874
+ defaultMessage: "Field Agent",
875
+ description: "Name for user role Field Agent",
876
+ id: "userRole.fieldAgent"
877
+ },
878
+ scopes: [
879
+ `record.create[event=birth|death|tennis-club-membership]`,
880
+ "record.declare[event=birth|death|tennis-club-membership]",
881
+ SCOPES.RECORD_DECLARE_BIRTH,
882
+ SCOPES.RECORD_DECLARE_DEATH,
883
+ SCOPES.RECORD_DECLARE_MARRIAGE,
884
+ SCOPES.RECORD_SUBMIT_INCOMPLETE,
885
+ SCOPES.RECORD_SUBMIT_FOR_REVIEW,
886
+ SCOPES.SEARCH_BIRTH,
887
+ SCOPES.SEARCH_DEATH,
888
+ SCOPES.SEARCH_MARRIAGE
889
+ ]
890
+ },
891
+ {
892
+ id: "REGISTRATION_AGENT",
893
+ label: {
894
+ defaultMessage: "Registration Agent",
895
+ description: "Name for user role Registration Agent",
896
+ id: "userRole.registrationAgent"
897
+ },
898
+ scopes: [
899
+ `record.create[event=birth|death|tennis-club-membership]`,
900
+ "record.declare[event=birth|death|tennis-club-membership]",
901
+ SCOPES.RECORD_DECLARE_BIRTH,
902
+ SCOPES.RECORD_DECLARE_DEATH,
903
+ SCOPES.RECORD_DECLARE_MARRIAGE,
904
+ SCOPES.RECORD_SUBMIT_FOR_APPROVAL,
905
+ SCOPES.RECORD_SUBMIT_FOR_UPDATES,
906
+ SCOPES.RECORD_DECLARATION_ARCHIVE,
907
+ SCOPES.RECORD_DECLARATION_REINSTATE,
908
+ SCOPES.RECORD_REGISTRATION_REQUEST_CORRECTION,
909
+ SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES,
910
+ SCOPES.PERFORMANCE_READ,
911
+ SCOPES.PERFORMANCE_READ_DASHBOARDS,
912
+ SCOPES.ORGANISATION_READ_LOCATIONS,
913
+ SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE,
914
+ SCOPES.SEARCH_BIRTH,
915
+ SCOPES.SEARCH_DEATH,
916
+ SCOPES.SEARCH_MARRIAGE
917
+ ]
918
+ },
919
+ {
920
+ id: "LOCAL_REGISTRAR",
921
+ label: {
922
+ defaultMessage: "Local Registrar",
923
+ description: "Name for user role Local Registrar",
924
+ id: "userRole.localRegistrar"
925
+ },
926
+ scopes: [
927
+ `record.create[event=birth|death|tennis-club-membership]`,
928
+ "record.declare[event=birth|death|tennis-club-membership]",
929
+ SCOPES.RECORD_DECLARE_BIRTH,
930
+ SCOPES.RECORD_DECLARE_DEATH,
931
+ SCOPES.RECORD_DECLARE_MARRIAGE,
932
+ SCOPES.RECORD_SUBMIT_FOR_UPDATES,
933
+ SCOPES.RECORD_REVIEW_DUPLICATES,
934
+ "record.declared.review-duplicates[event=birth|death|tennis-club-membership]",
935
+ SCOPES.RECORD_DECLARATION_ARCHIVE,
936
+ SCOPES.RECORD_DECLARATION_REINSTATE,
937
+ SCOPES.RECORD_REGISTER,
938
+ SCOPES.RECORD_REGISTRATION_CORRECT,
939
+ SCOPES.RECORD_PRINT_ISSUE_CERTIFIED_COPIES,
940
+ SCOPES.PERFORMANCE_READ,
941
+ SCOPES.PERFORMANCE_READ_DASHBOARDS,
942
+ SCOPES.ORGANISATION_READ_LOCATIONS,
943
+ SCOPES.PROFILE_ELECTRONIC_SIGNATURE,
944
+ SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE,
945
+ SCOPES.SEARCH_BIRTH,
946
+ SCOPES.SEARCH_DEATH,
947
+ SCOPES.SEARCH_MARRIAGE
948
+ ]
949
+ },
950
+ {
951
+ id: "LOCAL_SYSTEM_ADMIN",
952
+ label: {
953
+ defaultMessage: "Local System Admin",
954
+ description: "Name for user role Local System Admin",
955
+ id: "userRole.localSystemAdmin"
956
+ },
957
+ scopes: [
958
+ SCOPES.USER_READ_MY_OFFICE,
959
+ SCOPES.USER_CREATE_MY_JURISDICTION,
960
+ SCOPES.USER_UPDATE_MY_JURISDICTION,
961
+ SCOPES.ORGANISATION_READ_LOCATIONS,
962
+ SCOPES.PERFORMANCE_READ,
963
+ SCOPES.PERFORMANCE_READ_DASHBOARDS,
964
+ SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS
965
+ // 'organisation.read-users' ?
966
+ ]
967
+ },
968
+ {
969
+ id: "NATIONAL_SYSTEM_ADMIN",
970
+ label: {
971
+ defaultMessage: "National System Admin",
972
+ description: "Name for user role National System Admin",
973
+ id: "userRole.nationalSystemAdmin"
974
+ },
975
+ scopes: [
976
+ SCOPES.USER_CREATE,
977
+ SCOPES.USER_READ,
978
+ SCOPES.USER_UPDATE,
979
+ SCOPES.ORGANISATION_READ_LOCATIONS,
980
+ SCOPES.PERFORMANCE_READ,
981
+ SCOPES.PERFORMANCE_READ_DASHBOARDS,
982
+ SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS
983
+ ]
984
+ },
985
+ {
986
+ id: "PERFORMANCE_MANAGER",
987
+ label: {
988
+ defaultMessage: "Performance Manager",
989
+ description: "Name for user role Performance Manager",
990
+ id: "userRole.performanceManager"
991
+ },
992
+ scopes: [
993
+ SCOPES.PERFORMANCE_READ,
994
+ SCOPES.PERFORMANCE_READ_DASHBOARDS,
995
+ SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS
996
+ ]
997
+ }
998
+ ];
999
+ var TokenUserType = import_zod13.z.enum(["user", "system"]);
1000
+ var TokenWithBearer = import_zod13.z.string().regex(/^Bearer\s/);
1001
+
1002
+ // ../commons/src/events/ActionDocument.ts
1003
+ (0, import_zod_openapi4.extendZodWithOpenApi)(import_zod14.z);
1004
+ var ActionUpdate = import_zod14.z.record(import_zod14.z.string(), FieldUpdateValue).describe(
1005
+ "Record of field-level changes made by an action. Supports partial updates and nullable values."
1006
+ );
1007
+ var EventState = import_zod14.z.record(import_zod14.z.string(), FieldValue).describe(
1008
+ "Aggregate representation of event data after all actions have been applied, with all updates consolidated and null values removed."
1009
+ );
1010
+ var ActionStatus = {
1011
+ Requested: "Requested",
1012
+ Accepted: "Accepted",
1013
+ Rejected: "Rejected"
1014
+ };
1015
+ var ActionBase = import_zod14.z.object({
1016
+ id: UUID.describe("Unique identifier of the action."),
1017
+ transactionId: import_zod14.z.string().describe("Unique identifier of the transaction."),
1018
+ createdByUserType: TokenUserType.describe(
1019
+ "Indicates whether the action was created by a human-user or by a system-user."
1020
+ ),
1021
+ createdAt: import_zod14.z.string().datetime().describe("Timestamp indicating when the action was created."),
1022
+ createdBy: import_zod14.z.string().describe("Identifier of the user who created the action."),
1023
+ createdByRole: import_zod14.z.string().describe("Role of the user who created the action."),
1024
+ createdBySignature: import_zod14.z.string().nullish().describe("Reference to the signature of the user who created the action."),
1025
+ createdAtLocation: CreatedAtLocation.describe(
1026
+ "Reference to the location of the user who created the action."
1027
+ ),
1028
+ declaration: ActionUpdate.describe(
1029
+ "Declaration data defined by the ActionConfig. Supports partial updates."
1030
+ ),
1031
+ annotation: ActionUpdate.optional().nullable().describe("Action-specific metadata used to annotate the event."),
1032
+ status: import_zod14.z.enum([
1033
+ ActionStatus.Requested,
1034
+ ActionStatus.Accepted,
1035
+ ActionStatus.Rejected
1036
+ ]).describe(
1037
+ "Current status of the action. Actions may be validated asynchronously by third-party integrations."
1038
+ ),
1039
+ originalActionId: UUID.optional().nullable().describe(
1040
+ "Reference to the original action asynchronously accepted or rejected by a third-party integration."
1041
+ )
1042
+ });
1043
+ var AssignedAction = ActionBase.merge(
1044
+ import_zod14.z.object({
1045
+ type: import_zod14.z.literal(ActionType.ASSIGN),
1046
+ assignedTo: import_zod14.z.string().describe("Identifier of the user to whom the action is assigned.")
1047
+ // TODO move into 'content' property
1048
+ })
1049
+ );
1050
+ var UnassignedAction = ActionBase.merge(
1051
+ import_zod14.z.object({
1052
+ type: import_zod14.z.literal(ActionType.UNASSIGN)
1053
+ })
1054
+ );
1055
+ var RegisterAction = ActionBase.merge(
1056
+ import_zod14.z.object({
1057
+ type: import_zod14.z.literal(ActionType.REGISTER),
1058
+ registrationNumber: import_zod14.z.string().optional().describe(
1059
+ "Registration number of the event. Always present for accepted registrations."
1060
+ )
1061
+ // TODO move into 'content' property
1062
+ })
1063
+ );
1064
+ var DeclareAction = ActionBase.merge(
1065
+ import_zod14.z.object({
1066
+ type: import_zod14.z.literal(ActionType.DECLARE)
1067
+ })
1068
+ );
1069
+ var ValidateAction = ActionBase.merge(
1070
+ import_zod14.z.object({
1071
+ type: import_zod14.z.literal(ActionType.VALIDATE)
1072
+ })
1073
+ );
1074
+ var ReasonContent = import_zod14.z.object({
1075
+ reason: import_zod14.z.string().min(1, { message: "Message cannot be empty" }).describe(
1076
+ "Message describing the reason for rejecting or archiving the event."
1077
+ )
1078
+ });
1079
+ var RejectAction = ActionBase.merge(
1080
+ import_zod14.z.object({
1081
+ type: import_zod14.z.literal(ActionType.REJECT),
1082
+ content: ReasonContent
1083
+ })
1084
+ );
1085
+ var PotentialDuplicate = import_zod14.z.object({
1086
+ id: UUID,
1087
+ trackingId: import_zod14.z.string()
1088
+ });
1089
+ var DuplicateDetectedAction = ActionBase.merge(
1090
+ import_zod14.z.object({
1091
+ type: import_zod14.z.literal(ActionType.DUPLICATE_DETECTED),
1092
+ content: import_zod14.z.object({
1093
+ duplicates: import_zod14.z.array(PotentialDuplicate)
1094
+ })
1095
+ })
1096
+ );
1097
+ var MarkNotDuplicateAction = ActionBase.merge(
1098
+ import_zod14.z.object({
1099
+ type: import_zod14.z.literal(ActionType.MARK_AS_NOT_DUPLICATE)
1100
+ })
1101
+ );
1102
+ var MarkAsDuplicateAction = ActionBase.merge(
1103
+ import_zod14.z.object({
1104
+ type: import_zod14.z.literal(ActionType.MARK_AS_DUPLICATE),
1105
+ content: import_zod14.z.object({
1106
+ duplicateOf: UUID
1107
+ }).optional()
1108
+ })
1109
+ );
1110
+ var ArchiveAction = ActionBase.merge(
1111
+ import_zod14.z.object({
1112
+ type: import_zod14.z.literal(ActionType.ARCHIVE),
1113
+ content: ReasonContent
1114
+ })
1115
+ );
1116
+ var CreatedAction = ActionBase.merge(
1117
+ import_zod14.z.object({
1118
+ type: import_zod14.z.literal(ActionType.CREATE)
1119
+ })
1120
+ );
1121
+ var NotifiedAction = ActionBase.merge(
1122
+ import_zod14.z.object({
1123
+ type: import_zod14.z.literal(ActionType.NOTIFY)
1124
+ })
1125
+ );
1126
+ var PrintContent = import_zod14.z.object({
1127
+ templateId: import_zod14.z.string().optional()
1128
+ });
1129
+ var PrintCertificateAction = ActionBase.merge(
1130
+ import_zod14.z.object({
1131
+ type: import_zod14.z.literal(ActionType.PRINT_CERTIFICATE),
1132
+ content: PrintContent.optional().nullable()
1133
+ })
1134
+ );
1135
+ var RequestedCorrectionAction = ActionBase.merge(
1136
+ import_zod14.z.object({
1137
+ type: import_zod14.z.literal(ActionType.REQUEST_CORRECTION)
1138
+ })
1139
+ );
1140
+ var ApprovedCorrectionAction = ActionBase.merge(
1141
+ import_zod14.z.object({
1142
+ type: import_zod14.z.literal(ActionType.APPROVE_CORRECTION),
1143
+ requestId: import_zod14.z.string()
1144
+ // TODO move into 'content' property
1145
+ })
1146
+ );
1147
+ var RejectedCorrectionAction = ActionBase.merge(
1148
+ import_zod14.z.object({
1149
+ type: import_zod14.z.literal(ActionType.REJECT_CORRECTION),
1150
+ requestId: import_zod14.z.string(),
1151
+ // TODO move into 'content' property
1152
+ content: ReasonContent
1153
+ })
1154
+ );
1155
+ var ReadAction = ActionBase.merge(
1156
+ import_zod14.z.object({
1157
+ type: import_zod14.z.literal(ActionType.READ)
1158
+ })
1159
+ );
1160
+ var ActionDocument = import_zod14.z.discriminatedUnion("type", [
1161
+ CreatedAction.openapi({ ref: "CreatedAction" }),
1162
+ ValidateAction.openapi({ ref: "ValidateAction" }),
1163
+ RejectAction.openapi({ ref: "RejectAction" }),
1164
+ DuplicateDetectedAction.openapi({ ref: "DuplicateDetectedAction" }),
1165
+ MarkNotDuplicateAction.openapi({ ref: "MarkNotDuplicateAction" }),
1166
+ MarkAsDuplicateAction.openapi({ ref: "MarkAsDuplicateAction" }),
1167
+ ArchiveAction.openapi({ ref: "ArchiveAction" }),
1168
+ NotifiedAction.openapi({ ref: "NotifiedAction" }),
1169
+ RegisterAction.openapi({ ref: "RegisterAction" }),
1170
+ DeclareAction.openapi({ ref: "DeclareAction" }),
1171
+ AssignedAction.openapi({ ref: "AssignedAction" }),
1172
+ RequestedCorrectionAction.openapi({ ref: "RequestedCorrectionAction" }),
1173
+ ApprovedCorrectionAction.openapi({ ref: "ApprovedCorrectionAction" }),
1174
+ RejectedCorrectionAction.openapi({ ref: "RejectedCorrectionAction" }),
1175
+ UnassignedAction.openapi({ ref: "UnassignedAction" }),
1176
+ PrintCertificateAction.openapi({ ref: "PrintCertificateAction" }),
1177
+ ReadAction.openapi({ ref: "ReadAction" })
1178
+ ]).openapi({
1179
+ ref: "ActionDocument"
1180
+ });
1181
+ var AsyncRejectActionDocument = ActionBase.omit({
1182
+ declaration: true,
1183
+ annotation: true
1184
+ }).merge(
1185
+ import_zod14.z.object({
1186
+ type: import_zod14.z.enum(ConfirmableActions),
1187
+ status: import_zod14.z.literal(ActionStatus.Rejected)
1188
+ })
1189
+ );
1190
+ var Action = import_zod14.z.union([ActionDocument, AsyncRejectActionDocument]);
1191
+
1192
+ // ../commons/src/events/EventMetadata.ts
1193
+ var EventStatus = import_zod15.z.enum([
1194
+ "CREATED",
1195
+ "NOTIFIED",
1196
+ "DECLARED",
1197
+ "VALIDATED",
1198
+ "REGISTERED",
1199
+ "ARCHIVED"
1200
+ ]);
1201
+ var InherentFlags = {
1202
+ PENDING_CERTIFICATION: "pending-certification",
1203
+ INCOMPLETE: "incomplete",
1204
+ REJECTED: "rejected",
1205
+ CORRECTION_REQUESTED: "correction-requested",
1206
+ POTENTIAL_DUPLICATE: "potential-duplicate"
1207
+ };
1208
+ var ActionFlag = import_zod15.z.string().regex(
1209
+ new RegExp(
1210
+ `^(${Object.values(ActionType).join("|").toLowerCase()}):(${Object.values(
1211
+ ActionStatus
1212
+ ).join("|").toLowerCase()})$`
1213
+ ),
1214
+ "Flag must be in the format ActionType:ActionStatus (lowerCase)"
1215
+ );
1216
+ var Flag = ActionFlag.or(import_zod15.z.nativeEnum(InherentFlags));
1217
+ var ZodDate = import_zod15.z.string().date();
1218
+ var ZodDateTime = import_zod15.z.string().datetime();
1219
+ var ActionCreationMetadata = import_zod15.z.object({
1220
+ createdAt: import_zod15.z.string().datetime().describe("The timestamp when the action request was created."),
1221
+ createdBy: import_zod15.z.string().describe("ID of the user who created the action request."),
1222
+ createdAtLocation: CreatedAtLocation.describe(
1223
+ "Location of the user who created the action request."
1224
+ ),
1225
+ createdByUserType: import_zod15.z.enum(["user", "system"]).nullish().describe("Whether the user is a normal user or a system."),
1226
+ acceptedAt: import_zod15.z.string().datetime().describe("Timestamp when the action request was accepted."),
1227
+ createdByRole: import_zod15.z.string().describe("Role of the user at the time of action request creation."),
1228
+ createdBySignature: import_zod15.z.string().nullish().describe("Signature of the user who created the action request.")
1229
+ });
1230
+ var RegistrationCreationMetadata = ActionCreationMetadata.extend({
1231
+ registrationNumber: import_zod15.z.string().describe(
1232
+ "Registration number of the event. Always present for accepted registrations."
1233
+ )
1234
+ });
1235
+ var LegalStatuses = import_zod15.z.object({
1236
+ [EventStatus.enum.DECLARED]: ActionCreationMetadata.nullish(),
1237
+ [EventStatus.enum.REGISTERED]: RegistrationCreationMetadata.nullish()
1238
+ });
1239
+ var EventMetadata = import_zod15.z.object({
1240
+ id: UUID,
1241
+ type: import_zod15.z.string().describe("The type of event, such as birth, death, or marriage."),
1242
+ status: EventStatus,
1243
+ legalStatuses: LegalStatuses.describe(
1244
+ "Metadata related to the legal registration of the event, such as who registered it and when."
1245
+ ),
1246
+ createdAt: import_zod15.z.string().datetime().describe("The timestamp when the event was first created and saved."),
1247
+ dateOfEvent: ZodDate.nullish(),
1248
+ createdBy: import_zod15.z.string().describe("ID of the user who created the event."),
1249
+ createdByUserType: import_zod15.z.enum(["user", "system"]).nullish().describe("Whether the user is a normal user or a system."),
1250
+ updatedByUserRole: import_zod15.z.string().describe("Role of the user who last changed the status."),
1251
+ createdAtLocation: CreatedAtLocation.describe(
1252
+ "Location of the user who created the event."
1253
+ ),
1254
+ createdBySignature: import_zod15.z.string().nullish().describe("Signature of the user who created the event."),
1255
+ updatedAtLocation: UUID.nullish().describe(
1256
+ "Location of the user who last changed the status."
1257
+ ),
1258
+ updatedAt: import_zod15.z.string().datetime().describe(
1259
+ "Timestamp of the most recent *accepted* status change. Possibly 3rd party update, if action is validation asynchronously."
1260
+ ),
1261
+ assignedTo: import_zod15.z.string().nullish().describe("ID of the user currently assigned to the event."),
1262
+ updatedBy: import_zod15.z.string().nullish().describe("ID of the user who last changed the status."),
1263
+ trackingId: import_zod15.z.string().describe(
1264
+ "System-generated tracking ID used by informants or registrars to look up the event."
1265
+ ),
1266
+ potentialDuplicates: import_zod15.z.array(PotentialDuplicate).describe(
1267
+ "List of event IDs and their tracking IDs that this event could be a duplicate of."
1268
+ ),
1269
+ flags: import_zod15.z.array(Flag)
1270
+ });
1271
+ var EventMetadataKeysArray = [
1272
+ "id",
1273
+ "type",
1274
+ "status",
1275
+ "createdAt",
1276
+ "dateOfEvent",
1277
+ "createdBy",
1278
+ "createdByUserType",
1279
+ "updatedByUserRole",
1280
+ "createdAtLocation",
1281
+ "updatedAtLocation",
1282
+ "updatedAt",
1283
+ "assignedTo",
1284
+ "updatedBy",
1285
+ "trackingId",
1286
+ "legalStatuses",
1287
+ "flags"
1288
+ ];
1289
+ var EventMetadataKeys = import_zod15.z.enum(EventMetadataKeysArray);
1290
+ var EventMetadataDateFieldIdInput = import_zod15.z.enum([
1291
+ "createdAt",
1292
+ "updatedAt",
1293
+ "legalStatuses.DECLARED.createdAt",
1294
+ "legalStatuses.DECLARED.acceptedAt",
1295
+ "legalStatuses.REGISTERED.createdAt",
1296
+ "legalStatuses.REGISTERED.acceptedAt"
1297
+ ]);
1298
+ var EventMetadataDateFieldId = import_zod15.z.enum([
1299
+ "event.createdAt",
1300
+ "event.updatedAt",
1301
+ "event.legalStatuses.DECLARED.createdAt",
1302
+ "event.legalStatuses.DECLARED.acceptedAt",
1303
+ "event.legalStatuses.REGISTERED.createdAt",
1304
+ "event.legalStatuses.REGISTERED.acceptedAt"
1305
+ ]);
1306
+
1307
+ // ../commons/src/events/EventIndex.ts
1308
+ var import_zod_openapi5 = require("zod-openapi");
1309
+
1310
+ // ../commons/src/events/Constants.ts
1311
+ var TENNIS_CLUB_MEMBERSHIP = "tennis-club-membership";
1312
+
1313
+ // ../commons/src/events/EventIndex.ts
1314
+ (0, import_zod_openapi5.extendZodWithOpenApi)(import_zod16.z);
1315
+ var EventIndex = EventMetadata.extend({
1316
+ declaration: EventState
1317
+ }).openapi({
1318
+ ref: "EventIndex"
1319
+ });
1320
+ var EventSearchIndex = import_zod16.z.record(import_zod16.z.string(), import_zod16.z.any()).and(
1321
+ import_zod16.z.object({
1322
+ type: import_zod16.z.string()
1323
+ // Ensures "type" (event-id) exists and is a string
1324
+ })
1325
+ ).openapi({
1326
+ ref: "EventSearchIndex"
1327
+ });
1328
+ var Fuzzy = import_zod16.z.object({ type: import_zod16.z.literal("fuzzy"), term: import_zod16.z.string() }).openapi({
1329
+ ref: "Fuzzy"
1330
+ });
1331
+ var Exact = import_zod16.z.object({ type: import_zod16.z.literal("exact"), term: import_zod16.z.string() }).openapi({
1332
+ ref: "Exact"
1333
+ });
1334
+ var ExactStatus = import_zod16.z.object({
1335
+ type: import_zod16.z.literal("exact"),
1336
+ term: EventStatus
1337
+ }).openapi({
1338
+ ref: "ExactStatus"
1339
+ });
1340
+ var ExactUserType = import_zod16.z.object({
1341
+ type: import_zod16.z.literal("exact"),
1342
+ term: TokenUserType
1343
+ }).openapi({
1344
+ ref: "ExactUserType"
1345
+ });
1346
+ var AnyOf = import_zod16.z.object({
1347
+ type: import_zod16.z.literal("anyOf"),
1348
+ terms: import_zod16.z.array(import_zod16.z.string())
1349
+ }).openapi({
1350
+ ref: "AnyOf"
1351
+ });
1352
+ var AnyOfStatus = import_zod16.z.object({
1353
+ type: import_zod16.z.literal("anyOf"),
1354
+ terms: import_zod16.z.array(EventStatus)
1355
+ }).openapi({
1356
+ ref: "AnyOfStatus"
1357
+ });
1358
+ var Range = import_zod16.z.object({
1359
+ type: import_zod16.z.literal("range"),
1360
+ gte: import_zod16.z.string(),
1361
+ lte: import_zod16.z.string()
1362
+ }).openapi({
1363
+ ref: "Range"
1364
+ });
1365
+ var ContainsFlags = import_zod16.z.object({
1366
+ anyOf: import_zod16.z.array(Flag).optional(),
1367
+ noneOf: import_zod16.z.array(Flag).optional()
1368
+ }).openapi({
1369
+ ref: "ContainsFlags"
1370
+ });
1371
+ var Within = import_zod16.z.object({ type: import_zod16.z.literal("within"), location: import_zod16.z.string() }).openapi({
1372
+ ref: "Within"
1373
+ });
1374
+ var RangeDate = import_zod16.z.object({
1375
+ type: import_zod16.z.literal("range"),
1376
+ gte: import_zod16.z.string().date().or(import_zod16.z.string().datetime()),
1377
+ lte: import_zod16.z.string().date().or(import_zod16.z.string().datetime())
1378
+ }).openapi({ ref: "RangeDate" });
1379
+ var ExactDate = Exact.extend({
1380
+ term: import_zod16.z.string().date().or(import_zod16.z.string().datetime())
1381
+ }).openapi({
1382
+ ref: "ExactDate"
1383
+ });
1384
+ var TimePeriod = import_zod16.z.object({
1385
+ type: import_zod16.z.literal("timePeriod"),
1386
+ term: SelectDateRangeValue
1387
+ }).openapi({
1388
+ ref: "TimePeriod"
1389
+ });
1390
+ var DateCondition = import_zod16.z.union([ExactDate, RangeDate, TimePeriod]).openapi({
1391
+ ref: "DateCondition"
1392
+ });
1393
+ var QueryInput = import_zod16.z.lazy(
1394
+ () => import_zod16.z.union([
1395
+ import_zod16.z.discriminatedUnion("type", [Fuzzy, Exact, Range, Within, AnyOf]),
1396
+ import_zod16.z.record(import_zod16.z.string(), QueryInput)
1397
+ ])
1398
+ ).openapi({
1399
+ ref: "QueryInput"
1400
+ });
1401
+ var QueryExpression = import_zod16.z.object({
1402
+ id: import_zod16.z.optional(import_zod16.z.string()),
1403
+ eventType: import_zod16.z.string(),
1404
+ status: import_zod16.z.optional(import_zod16.z.union([AnyOfStatus, ExactStatus])),
1405
+ createdAt: import_zod16.z.optional(DateCondition),
1406
+ updatedAt: import_zod16.z.optional(DateCondition),
1407
+ "legalStatuses.REGISTERED.acceptedAt": import_zod16.z.optional(DateCondition),
1408
+ "legalStatuses.DECLARED.createdAtLocation": import_zod16.z.optional(
1409
+ import_zod16.z.union([Within, Exact])
1410
+ ),
1411
+ "legalStatuses.REGISTERED.createdAtLocation": import_zod16.z.optional(
1412
+ import_zod16.z.union([Within, Exact])
1413
+ ),
1414
+ "legalStatuses.REGISTERED.registrationNumber": import_zod16.z.optional(Exact),
1415
+ createdAtLocation: import_zod16.z.optional(import_zod16.z.union([Within, Exact])),
1416
+ updatedAtLocation: import_zod16.z.optional(import_zod16.z.union([Within, Exact])),
1417
+ assignedTo: import_zod16.z.optional(Exact),
1418
+ createdByUserType: import_zod16.z.optional(ExactUserType),
1419
+ updatedByUserRole: import_zod16.z.optional(Exact),
1420
+ createdBy: import_zod16.z.optional(Exact),
1421
+ updatedBy: import_zod16.z.optional(Exact),
1422
+ trackingId: import_zod16.z.optional(Exact),
1423
+ flags: import_zod16.z.optional(ContainsFlags),
1424
+ // @todo: The type for this comes out as "any"
1425
+ data: QueryInput
1426
+ }).partial().refine((obj) => Object.values(obj).some((val) => val !== void 0), {
1427
+ message: "At least one query field must be specified."
1428
+ }).openapi({
1429
+ ref: "QueryExpression"
1430
+ });
1431
+ var QueryType = import_zod16.z.lazy(
1432
+ () => import_zod16.z.object({
1433
+ type: import_zod16.z.literal("and").or(import_zod16.z.literal("or")).openapi({ default: "and" }),
1434
+ clauses: import_zod16.z.array(import_zod16.z.union([QueryExpression, QueryType])).nonempty("At least one clause is required.").openapi({
1435
+ default: [
1436
+ {
1437
+ eventType: TENNIS_CLUB_MEMBERSHIP,
1438
+ status: {
1439
+ type: "anyOf",
1440
+ terms: EventStatus.options
1441
+ },
1442
+ updatedAt: {
1443
+ type: "range",
1444
+ gte: "2025-05-22",
1445
+ lte: "2025-05-29"
1446
+ },
1447
+ data: {}
1448
+ }
1449
+ ]
1450
+ })
1451
+ })
1452
+ ).openapi({
1453
+ ref: "QueryType"
1454
+ });
1455
+ function parseStringifiedQueryField(val) {
1456
+ if (typeof val === "string") {
1457
+ return JSON.parse(val);
1458
+ }
1459
+ return val;
1460
+ }
1461
+ var SearchQuery = import_zod16.z.object({
1462
+ query: import_zod16.z.preprocess(parseStringifiedQueryField, QueryType).openapi({
1463
+ default: {
1464
+ type: "and",
1465
+ clauses: [
1466
+ {
1467
+ eventType: TENNIS_CLUB_MEMBERSHIP,
1468
+ status: {
1469
+ type: "anyOf",
1470
+ terms: EventStatus.options
1471
+ },
1472
+ updatedAt: {
1473
+ type: "range",
1474
+ gte: "2025-05-22",
1475
+ lte: "2025-05-29"
1476
+ },
1477
+ data: {}
1478
+ }
1479
+ ]
1480
+ }
1481
+ }),
1482
+ limit: import_zod16.z.number().optional().default(100),
1483
+ offset: import_zod16.z.number().optional().default(0),
1484
+ sort: import_zod16.z.preprocess(
1485
+ parseStringifiedQueryField,
1486
+ import_zod16.z.array(
1487
+ import_zod16.z.object({
1488
+ field: import_zod16.z.string(),
1489
+ direction: import_zod16.z.enum(["asc", "desc"]).default("asc")
1490
+ })
1491
+ )
1492
+ ).optional()
1493
+ }).openapi({
1494
+ ref: "SearchQuery"
1495
+ });
1496
+
1497
+ // ../commons/src/events/FieldConfig.ts
1498
+ (0, import_zod_openapi6.extendZodWithOpenApi)(import_zod17.z);
1499
+ var FieldId = import_zod17.z.string().refine(
1500
+ /*
1501
+ * Disallow underscores '_' in field ids.
1502
+ * Why? Theres two reasons:
1503
+ * 1. We transform dots to underscores as separator in Formik field ids, so this avoids any issues with the Formik transformations.
1504
+ * 2. On Kysely-SQL queries, we use the CamelCasePlugin. This plugin transforms snake_case to camelCase also on nested (jsonb) object keys.
1505
+ * This could be disabled via 'maintainNestedObjectKeys: true', but this would also affect SQL queries which use e.g. json_agg() or to_jsonb() to aggregate results.
1506
+ */
1507
+ (val) => !val.includes("_"),
1508
+ (val) => ({
1509
+ message: `id: '${val}' must not contain underscores '_'`
1510
+ })
1511
+ ).describe("Unique identifier for the field");
1512
+ var FieldReference = import_zod17.z.object({
1513
+ $$field: FieldId,
1514
+ $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe(
1515
+ 'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1516
+ )
1517
+ }).describe("Reference to a field by its ID");
1518
+ var CodeToEvaluate = import_zod17.z.object({
1519
+ $$code: import_zod17.z.string().describe("Serialised client-side function body"),
1520
+ $$field: FieldId.describe(
1521
+ "Field whose value is passed as the first argument"
1522
+ ),
1523
+ $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe("Optional nested path within the field value")
1524
+ }).describe(
1525
+ "Serialised client-side evaluation function. Executed just-in-time on the client only."
1526
+ );
1527
+ function isCodeToEvaluate(v) {
1528
+ return !!v && typeof v === "object" && "$$code" in v;
1529
+ }
1530
+ var ValidationConfig = import_zod17.z.object({
1531
+ validator: Conditional,
1532
+ message: TranslationConfig
1533
+ });
1534
+ var requiredSchema = import_zod17.z.union([
1535
+ import_zod17.z.boolean(),
1536
+ import_zod17.z.object({
1537
+ message: TranslationConfig.describe("Custom required validation message")
1538
+ })
1539
+ ]).default(false).optional();
1540
+ var BaseField = import_zod17.z.object({
1541
+ id: FieldId.describe("Unique identifier of the field."),
1542
+ label: TranslationConfig.describe("Human-readable label of the field."),
1543
+ parent: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
1544
+ "Reference to the parent field or fields. When a parent field changes, this field is reset."
1545
+ ),
1546
+ required: requiredSchema.describe(
1547
+ "Indicates whether the field is mandatory."
1548
+ ),
1549
+ conditionals: import_zod17.z.array(FieldConditional).default([]).optional().describe(
1550
+ "Conditions determining when the field is shown or enabled. By default, the field is always shown and enabled."
1551
+ ),
1552
+ secured: import_zod17.z.boolean().default(false).optional().describe(
1553
+ "Indicates whether the field is secured. Secured fields are not indexed for search and are only visible when explicitly assigned."
1554
+ ),
1555
+ placeholder: TranslationConfig.optional(),
1556
+ validation: import_zod17.z.array(ValidationConfig).default([]).optional().describe("Additional validation rules applied to the field."),
1557
+ helperText: TranslationConfig.optional(),
1558
+ hideLabel: import_zod17.z.boolean().default(false).optional(),
1559
+ uncorrectable: import_zod17.z.boolean().default(false).optional().describe(
1560
+ "Indicates whether the field can be modified during record correction."
1561
+ ),
1562
+ value: FieldReference.or(CodeToEvaluate).or(import_zod17.z.array(FieldReference.or(CodeToEvaluate))).optional().describe(
1563
+ "Reference to the source field or fields. When a value is defined, it is copied from the parent field when changed. If multiple references are provided, the first truthy value is used. A CodeToEvaluate can be used to compute the value via a custom client-side function."
1564
+ ),
1565
+ evaluatedDefaultValue: CodeToEvaluate.optional().describe(
1566
+ "Custom client-side function used to compute the default value. Executed just-in-time on the client. Takes precedence over defaultValue when set."
1567
+ ),
1568
+ analytics: import_zod17.z.boolean().default(false).optional().describe(
1569
+ "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
1570
+ )
1571
+ }).describe("Common properties shared across all field types.");
1572
+ var Divider = BaseField.extend({
1573
+ type: import_zod17.z.literal(FieldType.DIVIDER)
1574
+ });
1575
+ var TextField = BaseField.extend({
1576
+ type: import_zod17.z.literal(FieldType.TEXT),
1577
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
1578
+ configuration: import_zod17.z.object({
1579
+ maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1580
+ type: import_zod17.z.enum(["text", "password"]).optional(),
1581
+ prefix: TranslationConfig.optional(),
1582
+ postfix: TranslationConfig.optional()
1583
+ }).default({ type: "text" }).optional()
1584
+ }).describe("Text input");
1585
+ var NumberField = BaseField.extend({
1586
+ type: import_zod17.z.literal(FieldType.NUMBER),
1587
+ defaultValue: NumberFieldValue.optional(),
1588
+ configuration: import_zod17.z.object({
1589
+ min: import_zod17.z.number().optional().describe("Minimum value"),
1590
+ max: import_zod17.z.number().optional().describe("Maximum value"),
1591
+ prefix: TranslationConfig.optional(),
1592
+ postfix: TranslationConfig.optional()
1593
+ }).optional()
1594
+ }).describe("Number input");
1595
+ var TextAreaField = BaseField.extend({
1596
+ type: import_zod17.z.literal(FieldType.TEXTAREA),
1597
+ defaultValue: NonEmptyTextValue.optional(),
1598
+ configuration: import_zod17.z.object({
1599
+ maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1600
+ rows: import_zod17.z.number().optional().describe("Number of visible text lines"),
1601
+ cols: import_zod17.z.number().optional().describe("Number of visible columns"),
1602
+ prefix: TranslationConfig.optional(),
1603
+ postfix: TranslationConfig.optional()
1604
+ }).default({ rows: 4 }).optional()
1605
+ }).describe("Multiline text input");
1606
+ var ImageMimeType = import_zod17.z.enum([
1607
+ "image/png",
1608
+ "image/jpg",
1609
+ "image/jpeg",
1610
+ "image/svg+xml"
1611
+ ]);
1612
+ var DocumentMimeType = import_zod17.z.enum([
1613
+ "application/pdf",
1614
+ "application/msword",
1615
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1616
+ "application/vnd.oasis.opendocument.text"
1617
+ ]);
1618
+ var MimeType = import_zod17.z.enum([
1619
+ ...ImageMimeType.options,
1620
+ ...DocumentMimeType.options
1621
+ ]);
1622
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
1623
+ var SignatureField = BaseField.extend({
1624
+ type: import_zod17.z.literal(FieldType.SIGNATURE),
1625
+ signaturePromptLabel: TranslationConfig.describe(
1626
+ "Title of the signature modal"
1627
+ ),
1628
+ defaultValue: SignatureFieldValue.optional(),
1629
+ configuration: import_zod17.z.object({
1630
+ maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1631
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
1632
+ }).default({
1633
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
1634
+ })
1635
+ }).describe("Signature input field");
1636
+ var EmailField = BaseField.extend({
1637
+ type: import_zod17.z.literal(FieldType.EMAIL),
1638
+ configuration: import_zod17.z.object({
1639
+ maxLength: import_zod17.z.number().optional().describe("Maximum length of the text")
1640
+ }).default({ maxLength: 10 }).optional(),
1641
+ defaultValue: NonEmptyTextValue.optional()
1642
+ });
1643
+ var DateField = BaseField.extend({
1644
+ type: import_zod17.z.literal(FieldType.DATE),
1645
+ defaultValue: SerializedNowDateTime.or(PlainDate).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
1646
+ configuration: import_zod17.z.object({
1647
+ notice: TranslationConfig.describe(
1648
+ "Text to display above the date input"
1649
+ ).optional()
1650
+ }).optional()
1651
+ }).describe("A single date input (yyyy-MM-dd)");
1652
+ var AgeField = BaseField.extend({
1653
+ type: import_zod17.z.literal(FieldType.AGE),
1654
+ defaultValue: NumberFieldValue.optional(),
1655
+ configuration: import_zod17.z.object({
1656
+ asOfDate: FieldReference,
1657
+ prefix: TranslationConfig.optional(),
1658
+ postfix: TranslationConfig.optional()
1659
+ })
1660
+ }).describe("An age input field which uses the current date as the asOfDate");
1661
+ var TimeField = BaseField.extend({
1662
+ type: import_zod17.z.literal(FieldType.TIME),
1663
+ defaultValue: SerializedNowDateTime.or(TimeValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
1664
+ configuration: import_zod17.z.object({
1665
+ use12HourFormat: import_zod17.z.boolean().optional().describe("Whether to use 12-hour format"),
1666
+ notice: TranslationConfig.describe(
1667
+ "Text to display above the time input"
1668
+ ).optional()
1669
+ }).optional()
1670
+ }).describe("A single date input (HH-mm)");
1671
+ var DateRangeField = BaseField.extend({
1672
+ type: import_zod17.z.literal(FieldType.DATE_RANGE),
1673
+ defaultValue: DateRangeFieldValue.optional(),
1674
+ configuration: import_zod17.z.object({
1675
+ notice: TranslationConfig.describe(
1676
+ "Text to display above the date input"
1677
+ ).optional()
1678
+ }).optional()
1679
+ }).describe("A date range input ({ start: yyyy-MM-dd, end: yyyy-MM-dd })");
1680
+ var HtmlFontVariant = import_zod17.z.enum([
1681
+ "reg12",
1682
+ "reg14",
1683
+ "reg16",
1684
+ "reg18",
1685
+ "h4",
1686
+ "h3",
1687
+ "h2",
1688
+ "h1"
1689
+ ]);
1690
+ var ParagraphConfiguration = import_zod17.z.object({
1691
+ styles: import_zod17.z.object({
1692
+ fontVariant: HtmlFontVariant.optional().describe(
1693
+ "Font variant to use for the paragraph text"
1694
+ ),
1695
+ hint: import_zod17.z.boolean().optional().describe("When true, paragraph is styled as a hint with grey color")
1696
+ }).optional()
1697
+ }).default({});
1698
+ var Paragraph = BaseField.extend({
1699
+ type: import_zod17.z.literal(FieldType.PARAGRAPH),
1700
+ defaultValue: NonEmptyTextValue.optional(),
1701
+ configuration: ParagraphConfiguration
1702
+ }).describe("A read-only HTML <p> paragraph");
1703
+ var PageHeader = BaseField.extend({
1704
+ type: import_zod17.z.literal(FieldType.PAGE_HEADER),
1705
+ defaultValue: NonEmptyTextValue.optional()
1706
+ }).describe("A read-only header component for form pages");
1707
+ var File = BaseField.extend({
1708
+ type: import_zod17.z.literal(FieldType.FILE),
1709
+ defaultValue: FileFieldValue.optional(),
1710
+ configuration: import_zod17.z.object({
1711
+ maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1712
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
1713
+ maxImageSize: import_zod17.z.object({
1714
+ targetSize: import_zod17.z.object({ width: import_zod17.z.number(), height: import_zod17.z.number() })
1715
+ }).optional(),
1716
+ style: import_zod17.z.object({
1717
+ width: import_zod17.z.enum(["full", "auto"]).optional().describe(
1718
+ "Whether the file upload button should take the full width of the container or not"
1719
+ )
1720
+ }).optional(),
1721
+ fileName: TranslationConfig.optional()
1722
+ }).default({
1723
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
1724
+ })
1725
+ }).describe("File upload");
1726
+ var SelectOption = import_zod17.z.object({
1727
+ value: import_zod17.z.string().describe("The value of the option"),
1728
+ label: import_zod17.z.union([import_zod17.z.string(), TranslationConfig]).describe("The label of the option"),
1729
+ conditionals: import_zod17.z.array(ActionConditional).default([]).optional()
1730
+ });
1731
+ var NumberWithUnitField = BaseField.extend({
1732
+ type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
1733
+ defaultValue: NumberWithUnitFieldValue.optional(),
1734
+ options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
1735
+ configuration: import_zod17.z.object({
1736
+ min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
1737
+ max: import_zod17.z.number().optional().describe("Maximum value of the number field"),
1738
+ numberFieldPlaceholder: TranslationConfig.optional().describe(
1739
+ "Placeholder for the number field"
1740
+ )
1741
+ }).optional()
1742
+ }).describe("Number with unit input");
1743
+ var RadioGroup = BaseField.extend({
1744
+ type: import_zod17.z.literal(FieldType.RADIO_GROUP),
1745
+ defaultValue: TextValue.optional(),
1746
+ options: import_zod17.z.array(SelectOption).describe("A list of options"),
1747
+ configuration: import_zod17.z.object({
1748
+ styles: import_zod17.z.object({
1749
+ size: import_zod17.z.enum(["NORMAL", "LARGE"]).optional()
1750
+ }).optional()
1751
+ }).optional()
1752
+ }).describe("Grouped radio options");
1753
+ var BulletList = BaseField.extend({
1754
+ type: import_zod17.z.literal(FieldType.BULLET_LIST),
1755
+ defaultValue: TextValue.optional(),
1756
+ items: import_zod17.z.array(TranslationConfig).describe("A list of items"),
1757
+ configuration: import_zod17.z.object({
1758
+ styles: import_zod17.z.object({
1759
+ fontVariant: HtmlFontVariant.optional()
1760
+ }).optional()
1761
+ }).default({})
1762
+ }).describe("A list of bullet points");
1763
+ var Select = BaseField.extend({
1764
+ type: import_zod17.z.literal(FieldType.SELECT),
1765
+ defaultValue: TextValue.optional(),
1766
+ options: import_zod17.z.array(SelectOption).describe("A list of options"),
1767
+ noOptionsMessage: TranslationConfig.optional().describe(
1768
+ `
1769
+ A translation configuration object used to display a message when no options are available.
1770
+ It must follow the shape: { id: string; defaultMessage: string; description?: string }.
1771
+ The message is rendered via intl.formatMessage(noOptionsMessage, { input }),
1772
+ where 'input' represents the text entered in the Select field.
1773
+ You can reference this variable in your message, for example:
1774
+ { ..., defaultMessage: "'{input}' is not listed among the health facilities." }
1775
+ `
1776
+ )
1777
+ }).describe("Select input");
1778
+ var SelectDateRangeOption = import_zod17.z.object({
1779
+ value: SelectDateRangeValue.describe("The value of the option"),
1780
+ label: TranslationConfig.describe("The label of the option")
1781
+ });
1782
+ var SelectDateRangeField = BaseField.extend({
1783
+ type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
1784
+ defaultValue: SelectDateRangeValue.optional(),
1785
+ options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
1786
+ }).describe("Select input with date range options");
1787
+ var NameConfig = import_zod17.z.object({
1788
+ firstname: import_zod17.z.object({ required: requiredSchema, label: TranslationConfig.optional() }).optional(),
1789
+ middlename: import_zod17.z.object({ required: requiredSchema, label: TranslationConfig.optional() }).optional(),
1790
+ surname: import_zod17.z.object({ required: requiredSchema, label: TranslationConfig.optional() }).optional()
1791
+ });
1792
+ var NameField = BaseField.extend({
1793
+ type: import_zod17.z.literal(FieldType.NAME),
1794
+ defaultValue: import_zod17.z.object({
1795
+ firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
1796
+ middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
1797
+ surname: SerializedUserField.or(NonEmptyTextValue).optional()
1798
+ }).optional(),
1799
+ configuration: import_zod17.z.object({
1800
+ name: NameConfig.default({
1801
+ firstname: { required: true },
1802
+ surname: { required: true }
1803
+ }).optional(),
1804
+ order: import_zod17.z.array(import_zod17.z.enum(["firstname", "middlename", "surname"])).optional(),
1805
+ maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1806
+ prefix: TranslationConfig.optional(),
1807
+ postfix: TranslationConfig.optional(),
1808
+ showParentFieldError: import_zod17.z.boolean().default(false).optional().describe(
1809
+ `If true, shows the parent field error and hides the subfield error`
1810
+ )
1811
+ }).default({
1812
+ name: {
1813
+ firstname: { required: true },
1814
+ surname: { required: true }
1815
+ }
1816
+ }).optional()
1817
+ }).describe("Name input field");
1818
+ var PhoneField = BaseField.extend({
1819
+ defaultValue: NonEmptyTextValue.optional(),
1820
+ type: import_zod17.z.literal(FieldType.PHONE)
1821
+ }).describe("Phone input field");
1822
+ var IdField = BaseField.extend({
1823
+ defaultValue: NonEmptyTextValue.optional(),
1824
+ type: import_zod17.z.literal(FieldType.ID)
1825
+ }).describe("ID input field");
1826
+ var Checkbox = BaseField.extend({
1827
+ type: import_zod17.z.literal(FieldType.CHECKBOX),
1828
+ defaultValue: CheckboxFieldValue.default(false)
1829
+ }).describe("Boolean checkbox field");
1830
+ var Country = BaseField.extend({
1831
+ type: import_zod17.z.literal(FieldType.COUNTRY),
1832
+ defaultValue: NonEmptyTextValue.optional(),
1833
+ optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
1834
+ "Conditionals for specific countries. Countries not listed are always shown and enabled."
1835
+ )
1836
+ }).describe("Country select field");
1837
+ var AdministrativeAreas = import_zod17.z.enum([
1838
+ "ADMIN_STRUCTURE",
1839
+ "HEALTH_FACILITY",
1840
+ "CRVS_OFFICE"
1841
+ ]);
1842
+ var AdministrativeAreaConfiguration = import_zod17.z.object({
1843
+ partOf: FieldReference.optional(),
1844
+ type: AdministrativeAreas
1845
+ }).describe("Administrative area options");
1846
+ var AdministrativeArea = BaseField.extend({
1847
+ type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
1848
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
1849
+ configuration: AdministrativeAreaConfiguration
1850
+ }).describe("Administrative area input field e.g. facility, office");
1851
+ var LocationInput = BaseField.extend({
1852
+ type: import_zod17.z.literal(FieldType.LOCATION),
1853
+ defaultValue: NonEmptyTextValue.optional(),
1854
+ configuration: import_zod17.z.object({
1855
+ searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
1856
+ })
1857
+ }).describe("Input field for a location");
1858
+ var FileUploadWithOptions = BaseField.extend({
1859
+ type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
1860
+ options: import_zod17.z.array(SelectOption).describe("A list of options"),
1861
+ defaultValue: FileFieldWithOptionValue.optional(),
1862
+ configuration: import_zod17.z.object({
1863
+ maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1864
+ maxImageSize: import_zod17.z.object({
1865
+ targetSize: import_zod17.z.object({ width: import_zod17.z.number(), height: import_zod17.z.number() })
1866
+ }).optional(),
1867
+ acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
1868
+ }).default({
1869
+ maxFileSize: DEFAULT_MAX_FILE_SIZE_BYTES
1870
+ })
1871
+ });
1872
+ var Facility = BaseField.extend({
1873
+ type: import_zod17.z.literal(FieldType.FACILITY),
1874
+ defaultValue: NonEmptyTextValue.optional()
1875
+ }).describe("Input field for a facility");
1876
+ var Office = BaseField.extend({
1877
+ type: import_zod17.z.literal(FieldType.OFFICE),
1878
+ defaultValue: NonEmptyTextValue.optional()
1879
+ }).describe("Input field for an office");
1880
+ var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
1881
+ administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
1882
+ });
1883
+ var commonDomesticFieldProps = {
1884
+ id: true,
1885
+ type: true,
1886
+ label: true,
1887
+ conditionals: true,
1888
+ required: true
1889
+ };
1890
+ var DomesticAddressField = Country.partial().pick({
1891
+ ...commonDomesticFieldProps,
1892
+ optionOverrides: true
1893
+ }).required({ id: true, type: true }).or(
1894
+ AdministrativeArea.partial().pick(commonDomesticFieldProps).required({ id: true, type: true })
1895
+ );
1896
+ var Address = BaseField.extend({
1897
+ type: import_zod17.z.literal(FieldType.ADDRESS),
1898
+ configuration: import_zod17.z.object({
1899
+ lineSeparator: import_zod17.z.string().optional(),
1900
+ fields: import_zod17.z.array(DomesticAddressField).optional(),
1901
+ streetAddressForm: import_zod17.z.array(
1902
+ import_zod17.z.object({
1903
+ id: import_zod17.z.string(),
1904
+ required: requiredSchema,
1905
+ label: TranslationConfig,
1906
+ type: import_zod17.z.literal(FieldType.TEXT),
1907
+ conditionals: import_zod17.z.array(FieldConditional).default([]).optional(),
1908
+ parent: FieldReference.optional()
1909
+ })
1910
+ ).optional()
1911
+ }).optional(),
1912
+ defaultValue: DefaultAddressFieldValue.optional()
1913
+ }).describe("Address input field \u2013 a combination of location and text fields");
1914
+ var StaticDataEntry = import_zod17.z.object({
1915
+ id: import_zod17.z.string().describe("ID for the data entry."),
1916
+ label: TranslationConfig,
1917
+ value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference).or(CodeToEvaluate)
1918
+ }).describe("Static data entry");
1919
+ var DataEntry = import_zod17.z.union([StaticDataEntry, import_zod17.z.object({ fieldId: import_zod17.z.string() })]).describe(
1920
+ "Data entry can be either a static data entry, or a reference to another field in the current form or the declaration."
1921
+ );
1922
+ var DataField = BaseField.extend({
1923
+ type: import_zod17.z.literal(FieldType.DATA),
1924
+ configuration: import_zod17.z.object({
1925
+ subtitle: TranslationConfig.optional(),
1926
+ data: import_zod17.z.array(DataEntry)
1927
+ })
1928
+ }).describe("Data field for displaying read-only data");
1929
+ var ButtonField = BaseField.extend({
1930
+ type: import_zod17.z.literal(FieldType.BUTTON),
1931
+ defaultValue: ButtonFieldValue.optional(),
1932
+ configuration: import_zod17.z.object({
1933
+ icon: import_zod17.z.string().optional().describe(
1934
+ "Icon for the button. You can find icons from OpenCRVS UI-Kit."
1935
+ ),
1936
+ loading: import_zod17.z.boolean().optional().describe("Whether the button is in a loading state and shows a spinner"),
1937
+ text: TranslationConfig.describe("Text to display on the button")
1938
+ })
1939
+ }).describe("Generic button without any built-in functionality");
1940
+ var FieldGroup = BaseField.extend({
1941
+ type: import_zod17.z.literal(FieldType.FIELD_GROUP),
1942
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1943
+ fields: import_zod17.z.lazy(() => import_zod17.z.array(FieldConfig))
1944
+ });
1945
+ var AlphaPrintButton = BaseField.extend({
1946
+ type: import_zod17.z.literal(FieldType.ALPHA_PRINT_BUTTON),
1947
+ configuration: import_zod17.z.object({
1948
+ template: import_zod17.z.string().describe("Template ID from countryconfig templates to use for printing"),
1949
+ buttonLabel: TranslationConfig.optional().describe(
1950
+ "Label for the print button"
1951
+ )
1952
+ })
1953
+ }).describe("Print button field for printing certificates");
1954
+ var HttpField = BaseField.extend({
1955
+ type: import_zod17.z.literal(FieldType.HTTP),
1956
+ defaultValue: HttpFieldValue.optional(),
1957
+ configuration: import_zod17.z.object({
1958
+ trigger: FieldReference,
1959
+ url: import_zod17.z.string().describe("URL to send the HTTP request to"),
1960
+ method: import_zod17.z.enum(["GET", "POST", "PUT", "DELETE"]),
1961
+ headers: import_zod17.z.record(import_zod17.z.string()).optional(),
1962
+ body: import_zod17.z.record(import_zod17.z.any()).optional(),
1963
+ errorValue: import_zod17.z.any().optional().describe("Value to set if the request fails"),
1964
+ params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference, CodeToEvaluate])).optional(),
1965
+ timeout: import_zod17.z.number().default(15e3).describe("Request timeout in milliseconds")
1966
+ })
1967
+ }).describe("HTTP request function triggered by a button click or other event");
1968
+ var SearchField = HttpField.extend({
1969
+ type: import_zod17.z.literal(FieldType.SEARCH),
1970
+ configuration: SearchQuery.pick({
1971
+ query: true,
1972
+ limit: true,
1973
+ offset: true
1974
+ }).extend({
1975
+ validation: ValidationConfig,
1976
+ indicators: import_zod17.z.object({
1977
+ loading: TranslationConfig.optional().describe(
1978
+ "Text to display while the search is in progress"
1979
+ ),
1980
+ offline: TranslationConfig.optional().describe(
1981
+ "Text to display when the application is offline"
1982
+ ),
1983
+ noResultsError: TranslationConfig.optional().describe(
1984
+ "Text to display when no results are found during the search"
1985
+ ),
1986
+ httpError: TranslationConfig.optional().describe(
1987
+ "Text to display when there is an HTTP error during the search"
1988
+ ),
1989
+ confirmButton: TranslationConfig.optional(),
1990
+ clearButton: TranslationConfig.optional(),
1991
+ clearModal: import_zod17.z.object({
1992
+ title: TranslationConfig.optional(),
1993
+ description: TranslationConfig.optional(),
1994
+ cancel: TranslationConfig.optional(),
1995
+ confirm: TranslationConfig.optional()
1996
+ }).optional(),
1997
+ ok: TranslationConfig.optional()
1998
+ }).optional()
1999
+ })
2000
+ });
2001
+ var LinkButtonField = BaseField.extend({
2002
+ type: import_zod17.z.literal(FieldType.LINK_BUTTON),
2003
+ configuration: import_zod17.z.object({
2004
+ url: import_zod17.z.string().describe("URL to open"),
2005
+ text: TranslationConfig.describe("Text to display on the button"),
2006
+ icon: import_zod17.z.string().optional().describe("Icon for the button. You can find icons from OpenCRVS UI-Kit.")
2007
+ })
2008
+ }).describe("Button that opens a link");
2009
+ var VerificationStatus = BaseField.extend({
2010
+ type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
2011
+ defaultValue: VerificationStatusValue.optional(),
2012
+ configuration: import_zod17.z.object({
2013
+ status: TranslationConfig.describe("Text to display on the status pill."),
2014
+ description: TranslationConfig.describe(
2015
+ "Explaining text on the banner in form."
2016
+ )
2017
+ })
2018
+ });
2019
+ var QueryParamReaderField = BaseField.extend({
2020
+ type: import_zod17.z.literal(FieldType.QUERY_PARAM_READER),
2021
+ configuration: import_zod17.z.object({
2022
+ pickParams: import_zod17.z.array(import_zod17.z.string()).describe("List of query parameters to read from the URL")
2023
+ })
2024
+ }).describe(
2025
+ "A field that maps URL query params into form values and clears them afterward"
2026
+ );
2027
+ var QrReaderField = BaseField.extend({
2028
+ type: import_zod17.z.literal(FieldType.QR_READER),
2029
+ defaultValue: QrReaderFieldValue.optional(),
2030
+ configuration: import_zod17.z.object({
2031
+ validator: import_zod17.z.custom(
2032
+ (val) => typeof val === "object" && val !== null
2033
+ )
2034
+ }).optional()
2035
+ });
2036
+ var IdReaderField = BaseField.extend({
2037
+ type: import_zod17.z.literal(FieldType.ID_READER),
2038
+ defaultValue: IdReaderFieldValue.optional(),
2039
+ methods: import_zod17.z.array(
2040
+ import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2041
+ )
2042
+ });
2043
+ var LoaderField = BaseField.extend({
2044
+ type: import_zod17.z.literal(FieldType.LOADER),
2045
+ configuration: import_zod17.z.object({
2046
+ text: TranslationConfig.describe("Display text above the loading spinner")
2047
+ })
2048
+ }).describe(
2049
+ "A non-interactive field that indicates an in progress operation in form"
2050
+ );
2051
+ var FieldConfig = import_zod17.z.discriminatedUnion("type", [
2052
+ FieldGroup,
2053
+ Address,
2054
+ TextField,
2055
+ NumberField,
2056
+ NumberWithUnitField,
2057
+ TextAreaField,
2058
+ AgeField,
2059
+ DateField,
2060
+ TimeField,
2061
+ DateRangeField,
2062
+ SelectDateRangeField,
2063
+ Paragraph,
2064
+ RadioGroup,
2065
+ BulletList,
2066
+ PageHeader,
2067
+ Select,
2068
+ NameField,
2069
+ PhoneField,
2070
+ IdField,
2071
+ Checkbox,
2072
+ File,
2073
+ Country,
2074
+ AdministrativeArea,
2075
+ Divider,
2076
+ LocationInput,
2077
+ Facility,
2078
+ Office,
2079
+ SignatureField,
2080
+ EmailField,
2081
+ FileUploadWithOptions,
2082
+ DataField,
2083
+ ButtonField,
2084
+ AlphaPrintButton,
2085
+ HttpField,
2086
+ LinkButtonField,
2087
+ VerificationStatus,
2088
+ QrReaderField,
2089
+ IdReaderField,
2090
+ QueryParamReaderField,
2091
+ LoaderField,
2092
+ SearchField
2093
+ ]).openapi({
2094
+ description: "Form field configuration",
2095
+ ref: "FieldConfig"
2096
+ });
2097
+ var AnyFileField = import_zod17.z.discriminatedUnion("type", [
2098
+ SignatureField,
2099
+ File,
2100
+ FileUploadWithOptions
2101
+ ]);
2102
+
121
2103
  // ../commons/src/conditionals/conditionals.ts
122
2104
  function defineConditional(schema) {
123
2105
  const schemaWithooutIDRef = omitKeyDeep(schema, "$id");
@@ -250,6 +2232,9 @@ function isFieldReference(value) {
250
2232
  function isEventFieldReference(value) {
251
2233
  return typeof value === "object" && value !== null && "$$event" in value;
252
2234
  }
2235
+ function isResolvableValueReference(value) {
2236
+ return isFieldReference(value) || isCodeToEvaluate(value);
2237
+ }
253
2238
  function getDateRangeToFieldReference(field, comparedField, clause) {
254
2239
  return {
255
2240
  type: "object",
@@ -684,6 +2669,48 @@ function createFieldConditionals(fieldId) {
684
2669
  }
685
2670
  },
686
2671
  required: [fieldId]
687
- })
2672
+ }),
2673
+ /**
2674
+ * Custom client-side validator. The provided function is serialised and executed
2675
+ * just-in-time on the client only. External references (e.g. lodash) are not
2676
+ * available inside the function body — all logic must be self-contained.
2677
+ *
2678
+ * @example
2679
+ * field('nid').customClientValidator((value) => {
2680
+ * // LUHN check — all logic must be inline
2681
+ * const digits = String(value).split('').map(Number)
2682
+ * // ...
2683
+ * return isValid
2684
+ * })
2685
+ */
2686
+ customClientValidator(validationFn) {
2687
+ const code = validationFn.toString();
2688
+ return defineFormConditional({
2689
+ type: "object",
2690
+ properties: wrapToPath(
2691
+ { [fieldId]: { customClientValidator: { code } } },
2692
+ this.$$subfield
2693
+ ),
2694
+ required: [fieldId]
2695
+ });
2696
+ },
2697
+ /**
2698
+ * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
2699
+ * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
2700
+ * The function is serialised and executed just-in-time on the client only.
2701
+ * External references (e.g. lodash) are not available inside the function body.
2702
+ *
2703
+ * @example
2704
+ * field('a').customClientEvaluation((aValue, ctx) =>
2705
+ * Number(aValue) + Number(ctx.$form.b)
2706
+ * )
2707
+ */
2708
+ customClientEvaluation(computationFn) {
2709
+ return {
2710
+ $$code: computationFn.toString(),
2711
+ $$field: fieldId,
2712
+ $$subfield: this.$$subfield
2713
+ };
2714
+ }
688
2715
  };
689
2716
  }