@opencrvs/toolkit 1.9.3-rc.866b278 → 1.9.3-rc.8e41e94

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.
@@ -230,6 +230,7 @@ var FieldType = {
230
230
  ADDRESS: "ADDRESS",
231
231
  TEXT: "TEXT",
232
232
  NUMBER: "NUMBER",
233
+ NUMBER_WITH_UNIT: "NUMBER_WITH_UNIT",
233
234
  TEXTAREA: "TEXTAREA",
234
235
  EMAIL: "EMAIL",
235
236
  DATE: "DATE",
@@ -393,6 +394,14 @@ var ReadDataValue = import_zod6.z.object({
393
394
  });
394
395
  var QrReaderFieldValue = ReadDataValue;
395
396
  var IdReaderFieldValue = ReadDataValue;
397
+ var NumberWithUnitFieldValue = import_zod6.z.object({
398
+ numericValue: import_zod6.z.number(),
399
+ unit: import_zod6.z.string()
400
+ });
401
+ var NumberWithUnitFieldUpdateValue = import_zod6.z.object({
402
+ numericValue: import_zod6.z.number().optional(),
403
+ unit: import_zod6.z.string().optional()
404
+ });
396
405
 
397
406
  // ../commons/src/events/FieldValue.ts
398
407
  var TextValue = import_zod7.z.string();
@@ -447,7 +456,9 @@ var FieldValuesWithoutDataField = import_zod7.z.union([
447
456
  VerificationStatusValue,
448
457
  QueryParamReaderFieldValue,
449
458
  QrReaderFieldValue,
450
- IdReaderFieldValue
459
+ IdReaderFieldValue,
460
+ NumberWithUnitFieldValue,
461
+ NumberWithUnitFieldUpdateValue
451
462
  ]);
452
463
  var DataFieldValue = import_zod7.z.object({
453
464
  data: import_zod7.z.record(import_zod7.z.string(), FieldValuesWithoutDataField)
@@ -467,6 +478,7 @@ var PRIORITY_ORDER = [
467
478
  "SelectDateRangeValue",
468
479
  "CheckboxFieldValue",
469
480
  "NumberFieldValue",
481
+ "NumberWithUnitFieldUpdateValue",
470
482
  "FileFieldValue",
471
483
  "FileFieldWithOptionValue",
472
484
  "DataFieldValue"
@@ -500,6 +512,7 @@ var FieldUpdateValue = safeUnion([
500
512
  SelectDateRangeValue.describe("SelectDateRangeValue"),
501
513
  CheckboxFieldValue.describe("CheckboxFieldValue"),
502
514
  NumberFieldValue.describe("NumberFieldValue"),
515
+ NumberWithUnitFieldUpdateValue.describe("NumberWithUnitFieldUpdateValue"),
503
516
  FileFieldValue.describe("FileFieldValue"),
504
517
  FileFieldWithOptionValue.describe("FileFieldWithOptionValue"),
505
518
  DataFieldValue.describe("DataFieldValue"),
@@ -1624,6 +1637,18 @@ var SelectOption = import_zod15.z.object({
1624
1637
  value: import_zod15.z.string().describe("The value of the option"),
1625
1638
  label: import_zod15.z.union([import_zod15.z.string(), TranslationConfig]).describe("The label of the option")
1626
1639
  });
1640
+ var NumberWithUnitField = BaseField.extend({
1641
+ type: import_zod15.z.literal(FieldType.NUMBER_WITH_UNIT),
1642
+ defaultValue: NumberWithUnitFieldValue.optional(),
1643
+ options: import_zod15.z.array(SelectOption).describe("A list of options for the unit select"),
1644
+ configuration: import_zod15.z.object({
1645
+ min: import_zod15.z.number().optional().describe("Minimum value of the number field"),
1646
+ max: import_zod15.z.number().optional().describe("Maximum value of the number field"),
1647
+ numberFieldPlaceholder: TranslationConfig.optional().describe(
1648
+ "Placeholder for the number field"
1649
+ )
1650
+ }).optional()
1651
+ }).describe("Number with unit input");
1627
1652
  var RadioGroup = BaseField.extend({
1628
1653
  type: import_zod15.z.literal(FieldType.RADIO_GROUP),
1629
1654
  defaultValue: TextValue.optional(),
@@ -1912,6 +1937,7 @@ var FieldConfig = import_zod15.z.discriminatedUnion("type", [
1912
1937
  Address,
1913
1938
  TextField,
1914
1939
  NumberField,
1940
+ NumberWithUnitField,
1915
1941
  TextAreaField,
1916
1942
  AgeField,
1917
1943
  DateField,
@@ -2424,9 +2450,30 @@ var DataContext = import_zod25.z.object({
2424
2450
  $leafAdminStructureLocationIds: import_zod25.z.array(import_zod25.z.object({ id: UUID }))
2425
2451
  })
2426
2452
  });
2453
+ function resolveDataPath(rootData, dataPath, instancePath) {
2454
+ const pathParts = dataPath.split("/");
2455
+ const levels = parseInt(pathParts[0], 10);
2456
+ const referencePath = pathParts.slice(1);
2457
+ const instanceParts = instancePath.split("/").filter(Boolean);
2458
+ const traversedParts = instanceParts.slice(0, -levels);
2459
+ let current = rootData;
2460
+ for (const part of traversedParts) {
2461
+ if (current === null || current === void 0) {
2462
+ return void 0;
2463
+ }
2464
+ current = current[part];
2465
+ }
2466
+ for (const part of referencePath) {
2467
+ if (current === null || current === void 0) {
2468
+ return void 0;
2469
+ }
2470
+ current = current[part];
2471
+ }
2472
+ return current;
2473
+ }
2427
2474
  (0, import_ajv_formats.default)(ajv);
2428
2475
  ajv.addKeyword({
2429
- keyword: "daysFromNow",
2476
+ keyword: "daysFromDate",
2430
2477
  type: "string",
2431
2478
  schemaType: "object",
2432
2479
  $data: true,
@@ -2443,8 +2490,22 @@ ajv.addKeyword({
2443
2490
  if (isNaN(date.getTime())) {
2444
2491
  return false;
2445
2492
  }
2446
- const now = new Date(dataContext.rootData.$now);
2447
- const offsetDate = new Date(now.getTime() + days * 24 * 60 * 60 * 1e3);
2493
+ let referenceDate = schema.referenceDate;
2494
+ if (referenceDate && typeof referenceDate === "object" && "$data" in referenceDate) {
2495
+ referenceDate = resolveDataPath(
2496
+ dataContext.rootData,
2497
+ referenceDate.$data,
2498
+ dataContext.instancePath
2499
+ );
2500
+ }
2501
+ if (!referenceDate) {
2502
+ referenceDate = dataContext.rootData.$now;
2503
+ }
2504
+ const baseDate = new Date(referenceDate);
2505
+ if (isNaN(baseDate.getTime())) {
2506
+ return false;
2507
+ }
2508
+ const offsetDate = new Date(baseDate.getTime() + days * 24 * 60 * 60 * 1e3);
2448
2509
  return clause === "after" ? (0, import_date_fns.isAfter)(date, offsetDate) : (0, import_date_fns.isBefore)(date, offsetDate);
2449
2510
  }
2450
2511
  });
@@ -2759,6 +2820,34 @@ function getDateRangeToFieldReference(field3, comparedField, clause) {
2759
2820
  required: [field3.$$field]
2760
2821
  };
2761
2822
  }
2823
+ function getDayRangeToFieldReference(field3, comparedField, days, clause) {
2824
+ return {
2825
+ type: "object",
2826
+ properties: {
2827
+ [field3.$$field]: wrapToPath(
2828
+ {
2829
+ type: "string",
2830
+ format: "date",
2831
+ daysFromDate: {
2832
+ referenceDate: {
2833
+ $data: `${field3.$$subfield.length + 1}/${jsonFieldPath(
2834
+ comparedField
2835
+ )}`
2836
+ },
2837
+ clause,
2838
+ days
2839
+ }
2840
+ },
2841
+ field3.$$subfield
2842
+ ),
2843
+ [comparedField.$$field]: wrapToPath(
2844
+ { type: "string", format: "date" },
2845
+ comparedField.$$subfield
2846
+ )
2847
+ },
2848
+ required: [field3.$$field]
2849
+ };
2850
+ }
2762
2851
  function defineComparison(field3, value, keyword) {
2763
2852
  if (isFieldReference(value)) {
2764
2853
  const comparedField = value;
@@ -2794,16 +2883,17 @@ function defineComparison(field3, value, keyword) {
2794
2883
  });
2795
2884
  }
2796
2885
  function createFieldConditionals(fieldId) {
2797
- const getDayRange = (field3, days, clause) => ({
2886
+ const getDayRange = (field3, days, clause, referenceDate) => ({
2798
2887
  type: "object",
2799
2888
  properties: {
2800
2889
  [field3.$$field]: wrapToPath(
2801
2890
  {
2802
2891
  type: "string",
2803
2892
  format: "date",
2804
- daysFromNow: {
2893
+ daysFromDate: {
2805
2894
  days,
2806
- clause
2895
+ clause,
2896
+ referenceDate
2807
2897
  }
2808
2898
  },
2809
2899
  field3.$$subfield
@@ -2856,7 +2946,19 @@ function createFieldConditionals(fieldId) {
2856
2946
  return {
2857
2947
  days: (days) => ({
2858
2948
  inPast: () => defineFormConditional(getDayRange(this, -days, "after")),
2859
- inFuture: () => defineFormConditional(getDayRange(this, days, "after"))
2949
+ inFuture: () => defineFormConditional(getDayRange(this, days, "after")),
2950
+ fromDate: (date) => {
2951
+ if (isFieldReference(date)) {
2952
+ const comparedField = date;
2953
+ return defineFormConditional(
2954
+ getDayRangeToFieldReference(this, comparedField, days, "after")
2955
+ );
2956
+ }
2957
+ return defineFormConditional(getDayRange(this, days, "after", date));
2958
+ },
2959
+ fromNow: () => {
2960
+ return defineFormConditional(getDayRange(this, days, "after"));
2961
+ }
2860
2962
  }),
2861
2963
  date: (date) => {
2862
2964
  if (isFieldReference(date)) {
@@ -2878,7 +2980,26 @@ function createFieldConditionals(fieldId) {
2878
2980
  return {
2879
2981
  days: (days) => ({
2880
2982
  inPast: () => defineFormConditional(getDayRange(this, -days, "before")),
2881
- inFuture: () => defineFormConditional(getDayRange(this, days, "before"))
2983
+ inFuture: () => defineFormConditional(getDayRange(this, days, "before")),
2984
+ fromDate: (date) => {
2985
+ if (isFieldReference(date)) {
2986
+ const comparedField = date;
2987
+ return defineFormConditional(
2988
+ getDayRangeToFieldReference(
2989
+ this,
2990
+ comparedField,
2991
+ -days,
2992
+ "before"
2993
+ )
2994
+ );
2995
+ }
2996
+ return defineFormConditional(
2997
+ getDayRange(this, -days, "before", date)
2998
+ );
2999
+ },
3000
+ fromNow: () => {
3001
+ return defineFormConditional(getDayRange(this, -days, "before"));
3002
+ }
2882
3003
  }),
2883
3004
  date: (date) => {
2884
3005
  if (isFieldReference(date)) {
@@ -3824,6 +3945,7 @@ var PRINT_CERTIFICATE_FORM = defineActionForm({
3824
3945
  {
3825
3946
  id: "collector",
3826
3947
  type: PageTypes.enum.FORM,
3948
+ requireCompletionToContinue: true,
3827
3949
  title: {
3828
3950
  id: "event.tennis-club-membership.action.certificate.form.section.who.title",
3829
3951
  defaultMessage: "Print certified copy",
@@ -4431,6 +4553,7 @@ var PRINT_CERTIFICATE_FORM = defineActionForm({
4431
4553
  {
4432
4554
  id: "collector.identity.verify",
4433
4555
  type: PageTypes.enum.VERIFICATION,
4556
+ requireCompletionToContinue: true,
4434
4557
  conditional: field("collector.requesterId").isEqualTo("INFORMANT"),
4435
4558
  title: {
4436
4559
  id: "event.tennis-club-membership.action.print.verifyIdentity",
@@ -6029,6 +6152,220 @@ var v2BirthEvent = defineConfig({
6029
6152
  advancedSearch: []
6030
6153
  });
6031
6154
 
6155
+ // ../commons/src/fixtures/digital-identity-issuance-event.ts
6156
+ var PRINT_DIGITAL_ID_CERTIFICATE_FORM = defineActionForm({
6157
+ label: {
6158
+ id: "event.digital-identity.action.certificate.form.label",
6159
+ defaultMessage: "Digital identity certificate printer",
6160
+ description: "This is what this form is referred as in the system"
6161
+ },
6162
+ pages: [
6163
+ {
6164
+ id: "collector",
6165
+ type: PageTypes.enum.FORM,
6166
+ title: {
6167
+ id: "event.tennis-club-membership.action.certificate.form.section.who.title",
6168
+ defaultMessage: "Print certified copy",
6169
+ description: "This is the title of the section"
6170
+ },
6171
+ fields: [
6172
+ {
6173
+ id: "identity.http-fetch",
6174
+ type: FieldType.HTTP,
6175
+ label: {
6176
+ defaultMessage: "Digital identity certificate",
6177
+ description: "Fetch printable digital identity certificate",
6178
+ id: "event.digital-identity.certificate.fetch.label"
6179
+ },
6180
+ configuration: {
6181
+ trigger: field("identity.http-button"),
6182
+ url: "/api/digital-identity/certificate",
6183
+ timeout: 5e3,
6184
+ method: "POST",
6185
+ headers: {
6186
+ "Content-Type": "application/json"
6187
+ },
6188
+ body: {
6189
+ subjectId: "$event.subject.id"
6190
+ }
6191
+ }
6192
+ },
6193
+ {
6194
+ id: "identity.http-button",
6195
+ type: FieldType.BUTTON,
6196
+ label: {
6197
+ defaultMessage: "Certificate",
6198
+ description: "Certificate",
6199
+ id: "event.digital-identity.certificate.button.label"
6200
+ },
6201
+ conditionals: [
6202
+ {
6203
+ type: ConditionalType.ENABLE,
6204
+ conditional: and(
6205
+ field("identity.http-fetch").isUndefined(),
6206
+ user.isOnline()
6207
+ )
6208
+ },
6209
+ {
6210
+ type: ConditionalType.SHOW,
6211
+ conditional: and(
6212
+ field("identity.http-fetch").get("loading").isFalsy(),
6213
+ field("identity.http-fetch").get("data").isFalsy()
6214
+ )
6215
+ }
6216
+ ],
6217
+ configuration: {
6218
+ icon: "IdentificationCard",
6219
+ text: {
6220
+ defaultMessage: "Fetch certificate",
6221
+ description: "Fetch certificate",
6222
+ id: "event.digital-identity.certificate.fetch.text"
6223
+ }
6224
+ }
6225
+ },
6226
+ {
6227
+ id: "identity.http-button",
6228
+ type: FieldType.BUTTON,
6229
+ label: {
6230
+ defaultMessage: "Certificate",
6231
+ description: "Certificate",
6232
+ id: "event.digital-identity.certificate.button.label"
6233
+ },
6234
+ conditionals: [
6235
+ {
6236
+ type: ConditionalType.ENABLE,
6237
+ conditional: never()
6238
+ },
6239
+ {
6240
+ type: ConditionalType.SHOW,
6241
+ conditional: field("identity.http-fetch").get("loading").isEqualTo(true)
6242
+ }
6243
+ ],
6244
+ configuration: {
6245
+ loading: true,
6246
+ text: {
6247
+ defaultMessage: "Fetching certificate\u2026",
6248
+ description: "Fetching certificate\u2026",
6249
+ id: "event.digital-identity.certificate.fetching.text"
6250
+ }
6251
+ }
6252
+ },
6253
+ {
6254
+ id: "identity.http-button",
6255
+ type: FieldType.BUTTON,
6256
+ label: {
6257
+ defaultMessage: "Certificate",
6258
+ description: "Certificate",
6259
+ id: "event.digital-identity.certificate.button.label"
6260
+ },
6261
+ conditionals: [
6262
+ {
6263
+ type: ConditionalType.ENABLE,
6264
+ conditional: never()
6265
+ },
6266
+ {
6267
+ type: ConditionalType.SHOW,
6268
+ conditional: not(field("identity.certificateId").isFalsy())
6269
+ }
6270
+ ],
6271
+ configuration: {
6272
+ icon: "Check",
6273
+ text: {
6274
+ defaultMessage: "Certificate ready",
6275
+ description: "Certificate ready",
6276
+ id: "event.digital-identity.certificate.ready.text"
6277
+ }
6278
+ }
6279
+ },
6280
+ {
6281
+ id: "identity.certificateId",
6282
+ type: FieldType.TEXT,
6283
+ parent: field("identity.http-fetch"),
6284
+ label: {
6285
+ defaultMessage: "Certificate ID",
6286
+ description: "Issued digital identity certificate identifier",
6287
+ id: "event.digital-identity.certificate.id.label"
6288
+ },
6289
+ conditionals: [
6290
+ {
6291
+ type: ConditionalType.ENABLE,
6292
+ conditional: never()
6293
+ }
6294
+ ],
6295
+ value: field("identity.http-fetch").get("data.certificateId")
6296
+ }
6297
+ ]
6298
+ }
6299
+ ]
6300
+ });
6301
+ var digitalIdentityForm = defineDeclarationForm({
6302
+ label: {
6303
+ id: "event.digital-identity.action.declare.form.label",
6304
+ defaultMessage: "Digital identity issuance",
6305
+ description: "This is what this form is referred as in the system"
6306
+ },
6307
+ pages: [
6308
+ {
6309
+ id: "subject",
6310
+ title: {
6311
+ id: "event.digital-identity.action.declare.form.section.who.title",
6312
+ defaultMessage: "Who is the digital identity issued to?",
6313
+ description: "This is the title of the section"
6314
+ },
6315
+ fields: [
6316
+ {
6317
+ id: "subject.firstname",
6318
+ type: FieldType.TEXT,
6319
+ required: true,
6320
+ conditionals: [],
6321
+ label: {
6322
+ defaultMessage: "Subject's first name",
6323
+ description: "This is the label for the field",
6324
+ id: "event.digital-identity.action.declare.form.section.who.field.firstname.label"
6325
+ }
6326
+ },
6327
+ {
6328
+ id: "subject.surname",
6329
+ type: FieldType.TEXT,
6330
+ required: true,
6331
+ conditionals: [],
6332
+ label: {
6333
+ defaultMessage: "Subject's surname",
6334
+ description: "This is the label for the field",
6335
+ id: "event.digital-identity.action.declare.form.section.who.field.surname.label"
6336
+ }
6337
+ }
6338
+ ]
6339
+ }
6340
+ ]
6341
+ });
6342
+ var digitalIdentityEvent = defineConfig({
6343
+ id: "digital-identity",
6344
+ label: {
6345
+ defaultMessage: "Digital identity issuance",
6346
+ description: "This is what this event is referred as in the system",
6347
+ id: "event.digital-identity.label"
6348
+ },
6349
+ title: {
6350
+ defaultMessage: "{subject.firstname} {subject.surname}",
6351
+ description: "This is the title of the summary",
6352
+ id: "event.digital-identity.title"
6353
+ },
6354
+ summary: { fields: [] },
6355
+ actions: [
6356
+ {
6357
+ type: ActionType.PRINT_CERTIFICATE,
6358
+ label: {
6359
+ id: "event.football-club-membership.action.collect-certificate.label",
6360
+ defaultMessage: "Print certificate",
6361
+ description: "This is shown as the action name anywhere the user can trigger the action from"
6362
+ },
6363
+ printForm: PRINT_DIGITAL_ID_CERTIFICATE_FORM
6364
+ }
6365
+ ],
6366
+ declaration: digitalIdentityForm
6367
+ });
6368
+
6032
6369
  // ../commons/src/events/test.utils.ts
6033
6370
  var import_zod35 = require("zod");
6034
6371
  var TestUserRole = import_zod35.z.enum([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.3-rc.866b278",
3
+ "version": "1.9.3-rc.8e41e94",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {