@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.
@@ -251,6 +251,34 @@ function getDateRangeToFieldReference(field, comparedField, clause) {
251
251
  required: [field.$$field]
252
252
  };
253
253
  }
254
+ function getDayRangeToFieldReference(field, comparedField, days, clause) {
255
+ return {
256
+ type: "object",
257
+ properties: {
258
+ [field.$$field]: wrapToPath(
259
+ {
260
+ type: "string",
261
+ format: "date",
262
+ daysFromDate: {
263
+ referenceDate: {
264
+ $data: `${field.$$subfield.length + 1}/${jsonFieldPath(
265
+ comparedField
266
+ )}`
267
+ },
268
+ clause,
269
+ days
270
+ }
271
+ },
272
+ field.$$subfield
273
+ ),
274
+ [comparedField.$$field]: wrapToPath(
275
+ { type: "string", format: "date" },
276
+ comparedField.$$subfield
277
+ )
278
+ },
279
+ required: [field.$$field]
280
+ };
281
+ }
254
282
  function defineComparison(field, value, keyword) {
255
283
  if (isFieldReference(value)) {
256
284
  const comparedField = value;
@@ -286,16 +314,17 @@ function defineComparison(field, value, keyword) {
286
314
  });
287
315
  }
288
316
  function createFieldConditionals(fieldId) {
289
- const getDayRange = (field, days, clause) => ({
317
+ const getDayRange = (field, days, clause, referenceDate) => ({
290
318
  type: "object",
291
319
  properties: {
292
320
  [field.$$field]: wrapToPath(
293
321
  {
294
322
  type: "string",
295
323
  format: "date",
296
- daysFromNow: {
324
+ daysFromDate: {
297
325
  days,
298
- clause
326
+ clause,
327
+ referenceDate
299
328
  }
300
329
  },
301
330
  field.$$subfield
@@ -348,7 +377,19 @@ function createFieldConditionals(fieldId) {
348
377
  return {
349
378
  days: (days) => ({
350
379
  inPast: () => defineFormConditional(getDayRange(this, -days, "after")),
351
- inFuture: () => defineFormConditional(getDayRange(this, days, "after"))
380
+ inFuture: () => defineFormConditional(getDayRange(this, days, "after")),
381
+ fromDate: (date) => {
382
+ if (isFieldReference(date)) {
383
+ const comparedField = date;
384
+ return defineFormConditional(
385
+ getDayRangeToFieldReference(this, comparedField, days, "after")
386
+ );
387
+ }
388
+ return defineFormConditional(getDayRange(this, days, "after", date));
389
+ },
390
+ fromNow: () => {
391
+ return defineFormConditional(getDayRange(this, days, "after"));
392
+ }
352
393
  }),
353
394
  date: (date) => {
354
395
  if (isFieldReference(date)) {
@@ -370,7 +411,26 @@ function createFieldConditionals(fieldId) {
370
411
  return {
371
412
  days: (days) => ({
372
413
  inPast: () => defineFormConditional(getDayRange(this, -days, "before")),
373
- inFuture: () => defineFormConditional(getDayRange(this, days, "before"))
414
+ inFuture: () => defineFormConditional(getDayRange(this, days, "before")),
415
+ fromDate: (date) => {
416
+ if (isFieldReference(date)) {
417
+ const comparedField = date;
418
+ return defineFormConditional(
419
+ getDayRangeToFieldReference(
420
+ this,
421
+ comparedField,
422
+ -days,
423
+ "before"
424
+ )
425
+ );
426
+ }
427
+ return defineFormConditional(
428
+ getDayRange(this, -days, "before", date)
429
+ );
430
+ },
431
+ fromNow: () => {
432
+ return defineFormConditional(getDayRange(this, -days, "before"));
433
+ }
374
434
  }),
375
435
  date: (date) => {
376
436
  if (isFieldReference(date)) {
@@ -3185,9 +3185,30 @@ var DataContext = import_zod25.z.object({
3185
3185
  $leafAdminStructureLocationIds: import_zod25.z.array(import_zod25.z.object({ id: UUID }))
3186
3186
  })
3187
3187
  });
3188
+ function resolveDataPath(rootData, dataPath, instancePath) {
3189
+ const pathParts = dataPath.split("/");
3190
+ const levels = parseInt(pathParts[0], 10);
3191
+ const referencePath = pathParts.slice(1);
3192
+ const instanceParts = instancePath.split("/").filter(Boolean);
3193
+ const traversedParts = instanceParts.slice(0, -levels);
3194
+ let current = rootData;
3195
+ for (const part of traversedParts) {
3196
+ if (current === null || current === void 0) {
3197
+ return void 0;
3198
+ }
3199
+ current = current[part];
3200
+ }
3201
+ for (const part of referencePath) {
3202
+ if (current === null || current === void 0) {
3203
+ return void 0;
3204
+ }
3205
+ current = current[part];
3206
+ }
3207
+ return current;
3208
+ }
3188
3209
  (0, import_ajv_formats.default)(ajv);
3189
3210
  ajv.addKeyword({
3190
- keyword: "daysFromNow",
3211
+ keyword: "daysFromDate",
3191
3212
  type: "string",
3192
3213
  schemaType: "object",
3193
3214
  $data: true,
@@ -3204,8 +3225,22 @@ ajv.addKeyword({
3204
3225
  if (isNaN(date.getTime())) {
3205
3226
  return false;
3206
3227
  }
3207
- const now = new Date(dataContext.rootData.$now);
3208
- const offsetDate = new Date(now.getTime() + days * 24 * 60 * 60 * 1e3);
3228
+ let referenceDate = schema.referenceDate;
3229
+ if (referenceDate && typeof referenceDate === "object" && "$data" in referenceDate) {
3230
+ referenceDate = resolveDataPath(
3231
+ dataContext.rootData,
3232
+ referenceDate.$data,
3233
+ dataContext.instancePath
3234
+ );
3235
+ }
3236
+ if (!referenceDate) {
3237
+ referenceDate = dataContext.rootData.$now;
3238
+ }
3239
+ const baseDate = new Date(referenceDate);
3240
+ if (isNaN(baseDate.getTime())) {
3241
+ return false;
3242
+ }
3243
+ const offsetDate = new Date(baseDate.getTime() + days * 24 * 60 * 60 * 1e3);
3209
3244
  return clause === "after" ? (0, import_date_fns.isAfter)(date, offsetDate) : (0, import_date_fns.isBefore)(date, offsetDate);
3210
3245
  }
3211
3246
  });
@@ -3268,7 +3303,8 @@ function isConditionMet(conditional, values, context) {
3268
3303
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3269
3304
  $online: isOnline(),
3270
3305
  $user: context.user,
3271
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? []
3306
+ $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
3307
+ $event: context.event
3272
3308
  });
3273
3309
  }
3274
3310
  function getConditionalActionsForField(field3, values) {
@@ -3294,7 +3330,8 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
3294
3330
  $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3295
3331
  $online: isOnline(),
3296
3332
  $user: context.user,
3297
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? []
3333
+ $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
3334
+ $event: context.event
3298
3335
  });
3299
3336
  return validConditionals.includes(conditionalType);
3300
3337
  }
@@ -4116,6 +4153,34 @@ function getDateRangeToFieldReference(field3, comparedField, clause) {
4116
4153
  required: [field3.$$field]
4117
4154
  };
4118
4155
  }
4156
+ function getDayRangeToFieldReference(field3, comparedField, days, clause) {
4157
+ return {
4158
+ type: "object",
4159
+ properties: {
4160
+ [field3.$$field]: wrapToPath(
4161
+ {
4162
+ type: "string",
4163
+ format: "date",
4164
+ daysFromDate: {
4165
+ referenceDate: {
4166
+ $data: `${field3.$$subfield.length + 1}/${jsonFieldPath(
4167
+ comparedField
4168
+ )}`
4169
+ },
4170
+ clause,
4171
+ days
4172
+ }
4173
+ },
4174
+ field3.$$subfield
4175
+ ),
4176
+ [comparedField.$$field]: wrapToPath(
4177
+ { type: "string", format: "date" },
4178
+ comparedField.$$subfield
4179
+ )
4180
+ },
4181
+ required: [field3.$$field]
4182
+ };
4183
+ }
4119
4184
  function defineComparison(field3, value, keyword) {
4120
4185
  if (isFieldReference(value)) {
4121
4186
  const comparedField = value;
@@ -4151,16 +4216,17 @@ function defineComparison(field3, value, keyword) {
4151
4216
  });
4152
4217
  }
4153
4218
  function createFieldConditionals(fieldId) {
4154
- const getDayRange = (field3, days, clause) => ({
4219
+ const getDayRange = (field3, days, clause, referenceDate) => ({
4155
4220
  type: "object",
4156
4221
  properties: {
4157
4222
  [field3.$$field]: wrapToPath(
4158
4223
  {
4159
4224
  type: "string",
4160
4225
  format: "date",
4161
- daysFromNow: {
4226
+ daysFromDate: {
4162
4227
  days,
4163
- clause
4228
+ clause,
4229
+ referenceDate
4164
4230
  }
4165
4231
  },
4166
4232
  field3.$$subfield
@@ -4213,7 +4279,19 @@ function createFieldConditionals(fieldId) {
4213
4279
  return {
4214
4280
  days: (days) => ({
4215
4281
  inPast: () => defineFormConditional(getDayRange(this, -days, "after")),
4216
- inFuture: () => defineFormConditional(getDayRange(this, days, "after"))
4282
+ inFuture: () => defineFormConditional(getDayRange(this, days, "after")),
4283
+ fromDate: (date) => {
4284
+ if (isFieldReference(date)) {
4285
+ const comparedField = date;
4286
+ return defineFormConditional(
4287
+ getDayRangeToFieldReference(this, comparedField, days, "after")
4288
+ );
4289
+ }
4290
+ return defineFormConditional(getDayRange(this, days, "after", date));
4291
+ },
4292
+ fromNow: () => {
4293
+ return defineFormConditional(getDayRange(this, days, "after"));
4294
+ }
4217
4295
  }),
4218
4296
  date: (date) => {
4219
4297
  if (isFieldReference(date)) {
@@ -4235,7 +4313,26 @@ function createFieldConditionals(fieldId) {
4235
4313
  return {
4236
4314
  days: (days) => ({
4237
4315
  inPast: () => defineFormConditional(getDayRange(this, -days, "before")),
4238
- inFuture: () => defineFormConditional(getDayRange(this, days, "before"))
4316
+ inFuture: () => defineFormConditional(getDayRange(this, days, "before")),
4317
+ fromDate: (date) => {
4318
+ if (isFieldReference(date)) {
4319
+ const comparedField = date;
4320
+ return defineFormConditional(
4321
+ getDayRangeToFieldReference(
4322
+ this,
4323
+ comparedField,
4324
+ -days,
4325
+ "before"
4326
+ )
4327
+ );
4328
+ }
4329
+ return defineFormConditional(
4330
+ getDayRange(this, -days, "before", date)
4331
+ );
4332
+ },
4333
+ fromNow: () => {
4334
+ return defineFormConditional(getDayRange(this, -days, "before"));
4335
+ }
4239
4336
  }),
4240
4337
  date: (date) => {
4241
4338
  if (isFieldReference(date)) {
@@ -7763,6 +7860,220 @@ var v2BirthEvent = defineConfig({
7763
7860
  advancedSearch: []
7764
7861
  });
7765
7862
 
7863
+ // ../commons/src/fixtures/digital-identity-issuance-event.ts
7864
+ var PRINT_DIGITAL_ID_CERTIFICATE_FORM = defineActionForm({
7865
+ label: {
7866
+ id: "event.digital-identity.action.certificate.form.label",
7867
+ defaultMessage: "Digital identity certificate printer",
7868
+ description: "This is what this form is referred as in the system"
7869
+ },
7870
+ pages: [
7871
+ {
7872
+ id: "collector",
7873
+ type: PageTypes.enum.FORM,
7874
+ title: {
7875
+ id: "event.tennis-club-membership.action.certificate.form.section.who.title",
7876
+ defaultMessage: "Print certified copy",
7877
+ description: "This is the title of the section"
7878
+ },
7879
+ fields: [
7880
+ {
7881
+ id: "identity.http-fetch",
7882
+ type: FieldType.HTTP,
7883
+ label: {
7884
+ defaultMessage: "Digital identity certificate",
7885
+ description: "Fetch printable digital identity certificate",
7886
+ id: "event.digital-identity.certificate.fetch.label"
7887
+ },
7888
+ configuration: {
7889
+ trigger: field("identity.http-button"),
7890
+ url: "/api/digital-identity/certificate",
7891
+ timeout: 5e3,
7892
+ method: "POST",
7893
+ headers: {
7894
+ "Content-Type": "application/json"
7895
+ },
7896
+ body: {
7897
+ subjectId: "$event.subject.id"
7898
+ }
7899
+ }
7900
+ },
7901
+ {
7902
+ id: "identity.http-button",
7903
+ type: FieldType.BUTTON,
7904
+ label: {
7905
+ defaultMessage: "Certificate",
7906
+ description: "Certificate",
7907
+ id: "event.digital-identity.certificate.button.label"
7908
+ },
7909
+ conditionals: [
7910
+ {
7911
+ type: ConditionalType.ENABLE,
7912
+ conditional: and(
7913
+ field("identity.http-fetch").isUndefined(),
7914
+ user.isOnline()
7915
+ )
7916
+ },
7917
+ {
7918
+ type: ConditionalType.SHOW,
7919
+ conditional: and(
7920
+ field("identity.http-fetch").get("loading").isFalsy(),
7921
+ field("identity.http-fetch").get("data").isFalsy()
7922
+ )
7923
+ }
7924
+ ],
7925
+ configuration: {
7926
+ icon: "IdentificationCard",
7927
+ text: {
7928
+ defaultMessage: "Fetch certificate",
7929
+ description: "Fetch certificate",
7930
+ id: "event.digital-identity.certificate.fetch.text"
7931
+ }
7932
+ }
7933
+ },
7934
+ {
7935
+ id: "identity.http-button",
7936
+ type: FieldType.BUTTON,
7937
+ label: {
7938
+ defaultMessage: "Certificate",
7939
+ description: "Certificate",
7940
+ id: "event.digital-identity.certificate.button.label"
7941
+ },
7942
+ conditionals: [
7943
+ {
7944
+ type: ConditionalType.ENABLE,
7945
+ conditional: never()
7946
+ },
7947
+ {
7948
+ type: ConditionalType.SHOW,
7949
+ conditional: field("identity.http-fetch").get("loading").isEqualTo(true)
7950
+ }
7951
+ ],
7952
+ configuration: {
7953
+ loading: true,
7954
+ text: {
7955
+ defaultMessage: "Fetching certificate\u2026",
7956
+ description: "Fetching certificate\u2026",
7957
+ id: "event.digital-identity.certificate.fetching.text"
7958
+ }
7959
+ }
7960
+ },
7961
+ {
7962
+ id: "identity.http-button",
7963
+ type: FieldType.BUTTON,
7964
+ label: {
7965
+ defaultMessage: "Certificate",
7966
+ description: "Certificate",
7967
+ id: "event.digital-identity.certificate.button.label"
7968
+ },
7969
+ conditionals: [
7970
+ {
7971
+ type: ConditionalType.ENABLE,
7972
+ conditional: never()
7973
+ },
7974
+ {
7975
+ type: ConditionalType.SHOW,
7976
+ conditional: not(field("identity.certificateId").isFalsy())
7977
+ }
7978
+ ],
7979
+ configuration: {
7980
+ icon: "Check",
7981
+ text: {
7982
+ defaultMessage: "Certificate ready",
7983
+ description: "Certificate ready",
7984
+ id: "event.digital-identity.certificate.ready.text"
7985
+ }
7986
+ }
7987
+ },
7988
+ {
7989
+ id: "identity.certificateId",
7990
+ type: FieldType.TEXT,
7991
+ parent: field("identity.http-fetch"),
7992
+ label: {
7993
+ defaultMessage: "Certificate ID",
7994
+ description: "Issued digital identity certificate identifier",
7995
+ id: "event.digital-identity.certificate.id.label"
7996
+ },
7997
+ conditionals: [
7998
+ {
7999
+ type: ConditionalType.ENABLE,
8000
+ conditional: never()
8001
+ }
8002
+ ],
8003
+ value: field("identity.http-fetch").get("data.certificateId")
8004
+ }
8005
+ ]
8006
+ }
8007
+ ]
8008
+ });
8009
+ var digitalIdentityForm = defineDeclarationForm({
8010
+ label: {
8011
+ id: "event.digital-identity.action.declare.form.label",
8012
+ defaultMessage: "Digital identity issuance",
8013
+ description: "This is what this form is referred as in the system"
8014
+ },
8015
+ pages: [
8016
+ {
8017
+ id: "subject",
8018
+ title: {
8019
+ id: "event.digital-identity.action.declare.form.section.who.title",
8020
+ defaultMessage: "Who is the digital identity issued to?",
8021
+ description: "This is the title of the section"
8022
+ },
8023
+ fields: [
8024
+ {
8025
+ id: "subject.firstname",
8026
+ type: FieldType.TEXT,
8027
+ required: true,
8028
+ conditionals: [],
8029
+ label: {
8030
+ defaultMessage: "Subject's first name",
8031
+ description: "This is the label for the field",
8032
+ id: "event.digital-identity.action.declare.form.section.who.field.firstname.label"
8033
+ }
8034
+ },
8035
+ {
8036
+ id: "subject.surname",
8037
+ type: FieldType.TEXT,
8038
+ required: true,
8039
+ conditionals: [],
8040
+ label: {
8041
+ defaultMessage: "Subject's surname",
8042
+ description: "This is the label for the field",
8043
+ id: "event.digital-identity.action.declare.form.section.who.field.surname.label"
8044
+ }
8045
+ }
8046
+ ]
8047
+ }
8048
+ ]
8049
+ });
8050
+ var digitalIdentityEvent = defineConfig({
8051
+ id: "digital-identity",
8052
+ label: {
8053
+ defaultMessage: "Digital identity issuance",
8054
+ description: "This is what this event is referred as in the system",
8055
+ id: "event.digital-identity.label"
8056
+ },
8057
+ title: {
8058
+ defaultMessage: "{subject.firstname} {subject.surname}",
8059
+ description: "This is the title of the summary",
8060
+ id: "event.digital-identity.title"
8061
+ },
8062
+ summary: { fields: [] },
8063
+ actions: [
8064
+ {
8065
+ type: ActionType.PRINT_CERTIFICATE,
8066
+ label: {
8067
+ id: "event.football-club-membership.action.collect-certificate.label",
8068
+ defaultMessage: "Print certificate",
8069
+ description: "This is shown as the action name anywhere the user can trigger the action from"
8070
+ },
8071
+ printForm: PRINT_DIGITAL_ID_CERTIFICATE_FORM
8072
+ }
8073
+ ],
8074
+ declaration: digitalIdentityForm
8075
+ });
8076
+
7766
8077
  // ../commons/src/events/test.utils.ts
7767
8078
  var import_zod35 = require("zod");
7768
8079
  var TEST_SYSTEM_IANA_TIMEZONE = "Asia/Dhaka";