@opencrvs/toolkit 1.9.3-rc.b468b53 → 1.9.3-rc.b95cb0e

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.
@@ -2424,9 +2424,30 @@ var DataContext = import_zod25.z.object({
2424
2424
  $leafAdminStructureLocationIds: import_zod25.z.array(import_zod25.z.object({ id: UUID }))
2425
2425
  })
2426
2426
  });
2427
+ function resolveDataPath(rootData, dataPath, instancePath) {
2428
+ const pathParts = dataPath.split("/");
2429
+ const levels = parseInt(pathParts[0], 10);
2430
+ const referencePath = pathParts.slice(1);
2431
+ const instanceParts = instancePath.split("/").filter(Boolean);
2432
+ const traversedParts = instanceParts.slice(0, -levels);
2433
+ let current = rootData;
2434
+ for (const part of traversedParts) {
2435
+ if (current === null || current === void 0) {
2436
+ return void 0;
2437
+ }
2438
+ current = current[part];
2439
+ }
2440
+ for (const part of referencePath) {
2441
+ if (current === null || current === void 0) {
2442
+ return void 0;
2443
+ }
2444
+ current = current[part];
2445
+ }
2446
+ return current;
2447
+ }
2427
2448
  (0, import_ajv_formats.default)(ajv);
2428
2449
  ajv.addKeyword({
2429
- keyword: "daysFromNow",
2450
+ keyword: "daysFromDate",
2430
2451
  type: "string",
2431
2452
  schemaType: "object",
2432
2453
  $data: true,
@@ -2443,8 +2464,22 @@ ajv.addKeyword({
2443
2464
  if (isNaN(date.getTime())) {
2444
2465
  return false;
2445
2466
  }
2446
- const now = new Date(dataContext.rootData.$now);
2447
- const offsetDate = new Date(now.getTime() + days * 24 * 60 * 60 * 1e3);
2467
+ let referenceDate = schema.referenceDate;
2468
+ if (referenceDate && typeof referenceDate === "object" && "$data" in referenceDate) {
2469
+ referenceDate = resolveDataPath(
2470
+ dataContext.rootData,
2471
+ referenceDate.$data,
2472
+ dataContext.instancePath
2473
+ );
2474
+ }
2475
+ if (!referenceDate) {
2476
+ referenceDate = dataContext.rootData.$now;
2477
+ }
2478
+ const baseDate = new Date(referenceDate);
2479
+ if (isNaN(baseDate.getTime())) {
2480
+ return false;
2481
+ }
2482
+ const offsetDate = new Date(baseDate.getTime() + days * 24 * 60 * 60 * 1e3);
2448
2483
  return clause === "after" ? (0, import_date_fns.isAfter)(date, offsetDate) : (0, import_date_fns.isBefore)(date, offsetDate);
2449
2484
  }
2450
2485
  });
@@ -2759,6 +2794,34 @@ function getDateRangeToFieldReference(field3, comparedField, clause) {
2759
2794
  required: [field3.$$field]
2760
2795
  };
2761
2796
  }
2797
+ function getDayRangeToFieldReference(field3, comparedField, days, clause) {
2798
+ return {
2799
+ type: "object",
2800
+ properties: {
2801
+ [field3.$$field]: wrapToPath(
2802
+ {
2803
+ type: "string",
2804
+ format: "date",
2805
+ daysFromDate: {
2806
+ referenceDate: {
2807
+ $data: `${field3.$$subfield.length + 1}/${jsonFieldPath(
2808
+ comparedField
2809
+ )}`
2810
+ },
2811
+ clause,
2812
+ days
2813
+ }
2814
+ },
2815
+ field3.$$subfield
2816
+ ),
2817
+ [comparedField.$$field]: wrapToPath(
2818
+ { type: "string", format: "date" },
2819
+ comparedField.$$subfield
2820
+ )
2821
+ },
2822
+ required: [field3.$$field]
2823
+ };
2824
+ }
2762
2825
  function defineComparison(field3, value, keyword) {
2763
2826
  if (isFieldReference(value)) {
2764
2827
  const comparedField = value;
@@ -2794,16 +2857,17 @@ function defineComparison(field3, value, keyword) {
2794
2857
  });
2795
2858
  }
2796
2859
  function createFieldConditionals(fieldId) {
2797
- const getDayRange = (field3, days, clause) => ({
2860
+ const getDayRange = (field3, days, clause, referenceDate) => ({
2798
2861
  type: "object",
2799
2862
  properties: {
2800
2863
  [field3.$$field]: wrapToPath(
2801
2864
  {
2802
2865
  type: "string",
2803
2866
  format: "date",
2804
- daysFromNow: {
2867
+ daysFromDate: {
2805
2868
  days,
2806
- clause
2869
+ clause,
2870
+ referenceDate
2807
2871
  }
2808
2872
  },
2809
2873
  field3.$$subfield
@@ -2856,7 +2920,19 @@ function createFieldConditionals(fieldId) {
2856
2920
  return {
2857
2921
  days: (days) => ({
2858
2922
  inPast: () => defineFormConditional(getDayRange(this, -days, "after")),
2859
- inFuture: () => defineFormConditional(getDayRange(this, days, "after"))
2923
+ inFuture: () => defineFormConditional(getDayRange(this, days, "after")),
2924
+ fromDate: (date) => {
2925
+ if (isFieldReference(date)) {
2926
+ const comparedField = date;
2927
+ return defineFormConditional(
2928
+ getDayRangeToFieldReference(this, comparedField, days, "after")
2929
+ );
2930
+ }
2931
+ return defineFormConditional(getDayRange(this, days, "after", date));
2932
+ },
2933
+ fromNow: () => {
2934
+ return defineFormConditional(getDayRange(this, days, "after"));
2935
+ }
2860
2936
  }),
2861
2937
  date: (date) => {
2862
2938
  if (isFieldReference(date)) {
@@ -2878,7 +2954,26 @@ function createFieldConditionals(fieldId) {
2878
2954
  return {
2879
2955
  days: (days) => ({
2880
2956
  inPast: () => defineFormConditional(getDayRange(this, -days, "before")),
2881
- inFuture: () => defineFormConditional(getDayRange(this, days, "before"))
2957
+ inFuture: () => defineFormConditional(getDayRange(this, days, "before")),
2958
+ fromDate: (date) => {
2959
+ if (isFieldReference(date)) {
2960
+ const comparedField = date;
2961
+ return defineFormConditional(
2962
+ getDayRangeToFieldReference(
2963
+ this,
2964
+ comparedField,
2965
+ -days,
2966
+ "before"
2967
+ )
2968
+ );
2969
+ }
2970
+ return defineFormConditional(
2971
+ getDayRange(this, -days, "before", date)
2972
+ );
2973
+ },
2974
+ fromNow: () => {
2975
+ return defineFormConditional(getDayRange(this, -days, "before"));
2976
+ }
2882
2977
  }),
2883
2978
  date: (date) => {
2884
2979
  if (isFieldReference(date)) {
@@ -6029,6 +6124,220 @@ var v2BirthEvent = defineConfig({
6029
6124
  advancedSearch: []
6030
6125
  });
6031
6126
 
6127
+ // ../commons/src/fixtures/digital-identity-issuance-event.ts
6128
+ var PRINT_DIGITAL_ID_CERTIFICATE_FORM = defineActionForm({
6129
+ label: {
6130
+ id: "event.digital-identity.action.certificate.form.label",
6131
+ defaultMessage: "Digital identity certificate printer",
6132
+ description: "This is what this form is referred as in the system"
6133
+ },
6134
+ pages: [
6135
+ {
6136
+ id: "collector",
6137
+ type: PageTypes.enum.FORM,
6138
+ title: {
6139
+ id: "event.tennis-club-membership.action.certificate.form.section.who.title",
6140
+ defaultMessage: "Print certified copy",
6141
+ description: "This is the title of the section"
6142
+ },
6143
+ fields: [
6144
+ {
6145
+ id: "identity.http-fetch",
6146
+ type: FieldType.HTTP,
6147
+ label: {
6148
+ defaultMessage: "Digital identity certificate",
6149
+ description: "Fetch printable digital identity certificate",
6150
+ id: "event.digital-identity.certificate.fetch.label"
6151
+ },
6152
+ configuration: {
6153
+ trigger: field("identity.http-button"),
6154
+ url: "/api/digital-identity/certificate",
6155
+ timeout: 5e3,
6156
+ method: "POST",
6157
+ headers: {
6158
+ "Content-Type": "application/json"
6159
+ },
6160
+ body: {
6161
+ subjectId: "$event.subject.id"
6162
+ }
6163
+ }
6164
+ },
6165
+ {
6166
+ id: "identity.http-button",
6167
+ type: FieldType.BUTTON,
6168
+ label: {
6169
+ defaultMessage: "Certificate",
6170
+ description: "Certificate",
6171
+ id: "event.digital-identity.certificate.button.label"
6172
+ },
6173
+ conditionals: [
6174
+ {
6175
+ type: ConditionalType.ENABLE,
6176
+ conditional: and(
6177
+ field("identity.http-fetch").isUndefined(),
6178
+ user.isOnline()
6179
+ )
6180
+ },
6181
+ {
6182
+ type: ConditionalType.SHOW,
6183
+ conditional: and(
6184
+ field("identity.http-fetch").get("loading").isFalsy(),
6185
+ field("identity.http-fetch").get("data").isFalsy()
6186
+ )
6187
+ }
6188
+ ],
6189
+ configuration: {
6190
+ icon: "IdentificationCard",
6191
+ text: {
6192
+ defaultMessage: "Fetch certificate",
6193
+ description: "Fetch certificate",
6194
+ id: "event.digital-identity.certificate.fetch.text"
6195
+ }
6196
+ }
6197
+ },
6198
+ {
6199
+ id: "identity.http-button",
6200
+ type: FieldType.BUTTON,
6201
+ label: {
6202
+ defaultMessage: "Certificate",
6203
+ description: "Certificate",
6204
+ id: "event.digital-identity.certificate.button.label"
6205
+ },
6206
+ conditionals: [
6207
+ {
6208
+ type: ConditionalType.ENABLE,
6209
+ conditional: never()
6210
+ },
6211
+ {
6212
+ type: ConditionalType.SHOW,
6213
+ conditional: field("identity.http-fetch").get("loading").isEqualTo(true)
6214
+ }
6215
+ ],
6216
+ configuration: {
6217
+ loading: true,
6218
+ text: {
6219
+ defaultMessage: "Fetching certificate\u2026",
6220
+ description: "Fetching certificate\u2026",
6221
+ id: "event.digital-identity.certificate.fetching.text"
6222
+ }
6223
+ }
6224
+ },
6225
+ {
6226
+ id: "identity.http-button",
6227
+ type: FieldType.BUTTON,
6228
+ label: {
6229
+ defaultMessage: "Certificate",
6230
+ description: "Certificate",
6231
+ id: "event.digital-identity.certificate.button.label"
6232
+ },
6233
+ conditionals: [
6234
+ {
6235
+ type: ConditionalType.ENABLE,
6236
+ conditional: never()
6237
+ },
6238
+ {
6239
+ type: ConditionalType.SHOW,
6240
+ conditional: not(field("identity.certificateId").isFalsy())
6241
+ }
6242
+ ],
6243
+ configuration: {
6244
+ icon: "Check",
6245
+ text: {
6246
+ defaultMessage: "Certificate ready",
6247
+ description: "Certificate ready",
6248
+ id: "event.digital-identity.certificate.ready.text"
6249
+ }
6250
+ }
6251
+ },
6252
+ {
6253
+ id: "identity.certificateId",
6254
+ type: FieldType.TEXT,
6255
+ parent: field("identity.http-fetch"),
6256
+ label: {
6257
+ defaultMessage: "Certificate ID",
6258
+ description: "Issued digital identity certificate identifier",
6259
+ id: "event.digital-identity.certificate.id.label"
6260
+ },
6261
+ conditionals: [
6262
+ {
6263
+ type: ConditionalType.ENABLE,
6264
+ conditional: never()
6265
+ }
6266
+ ],
6267
+ value: field("identity.http-fetch").get("data.certificateId")
6268
+ }
6269
+ ]
6270
+ }
6271
+ ]
6272
+ });
6273
+ var digitalIdentityForm = defineDeclarationForm({
6274
+ label: {
6275
+ id: "event.digital-identity.action.declare.form.label",
6276
+ defaultMessage: "Digital identity issuance",
6277
+ description: "This is what this form is referred as in the system"
6278
+ },
6279
+ pages: [
6280
+ {
6281
+ id: "subject",
6282
+ title: {
6283
+ id: "event.digital-identity.action.declare.form.section.who.title",
6284
+ defaultMessage: "Who is the digital identity issued to?",
6285
+ description: "This is the title of the section"
6286
+ },
6287
+ fields: [
6288
+ {
6289
+ id: "subject.firstname",
6290
+ type: FieldType.TEXT,
6291
+ required: true,
6292
+ conditionals: [],
6293
+ label: {
6294
+ defaultMessage: "Subject's first name",
6295
+ description: "This is the label for the field",
6296
+ id: "event.digital-identity.action.declare.form.section.who.field.firstname.label"
6297
+ }
6298
+ },
6299
+ {
6300
+ id: "subject.surname",
6301
+ type: FieldType.TEXT,
6302
+ required: true,
6303
+ conditionals: [],
6304
+ label: {
6305
+ defaultMessage: "Subject's surname",
6306
+ description: "This is the label for the field",
6307
+ id: "event.digital-identity.action.declare.form.section.who.field.surname.label"
6308
+ }
6309
+ }
6310
+ ]
6311
+ }
6312
+ ]
6313
+ });
6314
+ var digitalIdentityEvent = defineConfig({
6315
+ id: "digital-identity",
6316
+ label: {
6317
+ defaultMessage: "Digital identity issuance",
6318
+ description: "This is what this event is referred as in the system",
6319
+ id: "event.digital-identity.label"
6320
+ },
6321
+ title: {
6322
+ defaultMessage: "{subject.firstname} {subject.surname}",
6323
+ description: "This is the title of the summary",
6324
+ id: "event.digital-identity.title"
6325
+ },
6326
+ summary: { fields: [] },
6327
+ actions: [
6328
+ {
6329
+ type: ActionType.PRINT_CERTIFICATE,
6330
+ label: {
6331
+ id: "event.football-club-membership.action.collect-certificate.label",
6332
+ defaultMessage: "Print certificate",
6333
+ description: "This is shown as the action name anywhere the user can trigger the action from"
6334
+ },
6335
+ printForm: PRINT_DIGITAL_ID_CERTIFICATE_FORM
6336
+ }
6337
+ ],
6338
+ declaration: digitalIdentityForm
6339
+ });
6340
+
6032
6341
  // ../commons/src/events/test.utils.ts
6033
6342
  var import_zod35 = require("zod");
6034
6343
  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.b468b53",
3
+ "version": "1.9.3-rc.b95cb0e",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {