@opencrvs/toolkit 1.9.13-rc.bb847c0 → 1.9.13-rc.c1f317c

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.
@@ -69,7 +69,6 @@ __export(events_exports, {
69
69
  CheckboxFieldValue: () => CheckboxFieldValue,
70
70
  Clause: () => Clause,
71
71
  ClientSpecificAction: () => ClientSpecificAction,
72
- CodeToEvaluate: () => CodeToEvaluate,
73
72
  Conditional: () => Conditional,
74
73
  ConditionalType: () => ConditionalType,
75
74
  ConfirmableActions: () => ConfirmableActions,
@@ -230,7 +229,6 @@ __export(events_exports, {
230
229
  areConditionsMet: () => areConditionsMet,
231
230
  buildFormState: () => buildFormState,
232
231
  canUserReadEvent: () => canUserReadEvent,
233
- compileClientFunction: () => compileClientFunction,
234
232
  compositeFieldTypes: () => compositeFieldTypes,
235
233
  configurableEventScopeAllowed: () => configurableEventScopeAllowed,
236
234
  createEmptyDraft: () => createEmptyDraft,
@@ -315,7 +313,6 @@ __export(events_exports, {
315
313
  isBulletListFieldType: () => isBulletListFieldType,
316
314
  isButtonFieldType: () => isButtonFieldType,
317
315
  isCheckboxFieldType: () => isCheckboxFieldType,
318
- isCodeToEvaluate: () => isCodeToEvaluate,
319
316
  isConditionMet: () => isConditionMet,
320
317
  isCountryFieldType: () => isCountryFieldType,
321
318
  isDataFieldType: () => isDataFieldType,
@@ -356,7 +353,6 @@ __export(events_exports, {
356
353
  isQrReaderFieldType: () => isQrReaderFieldType,
357
354
  isQueryParamReaderFieldType: () => isQueryParamReaderFieldType,
358
355
  isRadioGroupFieldType: () => isRadioGroupFieldType,
359
- isResolvableValueReference: () => isResolvableValueReference,
360
356
  isSearchFieldType: () => isSearchFieldType,
361
357
  isSelectDateRangeFieldType: () => isSelectDateRangeFieldType,
362
358
  isSelectFieldType: () => isSelectFieldType,
@@ -387,7 +383,6 @@ __export(events_exports, {
387
383
  runStructuralValidations: () => runStructuralValidations,
388
384
  safeUnion: () => safeUnion,
389
385
  timePeriodToDateRange: () => timePeriodToDateRange,
390
- todayISO: () => todayISO,
391
386
  user: () => user,
392
387
  validate: () => validate,
393
388
  validateFieldInput: () => validateFieldInput,
@@ -1992,18 +1987,6 @@ var FieldReference = import_zod17.z.object({
1992
1987
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1993
1988
  )
1994
1989
  }).describe("Reference to a field by its ID");
1995
- var CodeToEvaluate = import_zod17.z.object({
1996
- $$code: import_zod17.z.string().describe("Serialised client-side function body"),
1997
- $$field: FieldId.describe(
1998
- "Field whose value is passed as the first argument"
1999
- ),
2000
- $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe("Optional nested path within the field value")
2001
- }).describe(
2002
- "Serialised client-side evaluation function. Executed just-in-time on the client only."
2003
- );
2004
- function isCodeToEvaluate(v) {
2005
- return !!v && typeof v === "object" && "$$code" in v;
2006
- }
2007
1990
  var ValidationConfig = import_zod17.z.object({
2008
1991
  validator: Conditional,
2009
1992
  message: TranslationConfig
@@ -2036,11 +2019,8 @@ var BaseField = import_zod17.z.object({
2036
2019
  uncorrectable: import_zod17.z.boolean().default(false).optional().describe(
2037
2020
  "Indicates whether the field can be modified during record correction."
2038
2021
  ),
2039
- value: FieldReference.or(CodeToEvaluate).or(import_zod17.z.array(FieldReference.or(CodeToEvaluate))).optional().describe(
2040
- "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."
2041
- ),
2042
- evaluatedDefaultValue: CodeToEvaluate.optional().describe(
2043
- "Custom client-side function used to compute the default value. Executed just-in-time on the client. Takes precedence over defaultValue when set."
2022
+ value: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
2023
+ "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."
2044
2024
  ),
2045
2025
  analytics: import_zod17.z.boolean().default(false).optional().describe(
2046
2026
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -2388,7 +2368,7 @@ var Address = BaseField.extend({
2388
2368
  var StaticDataEntry = import_zod17.z.object({
2389
2369
  id: import_zod17.z.string().describe("ID for the data entry."),
2390
2370
  label: TranslationConfig,
2391
- value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference).or(CodeToEvaluate)
2371
+ value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference)
2392
2372
  }).describe("Static data entry");
2393
2373
  var DataEntry = import_zod17.z.union([StaticDataEntry, import_zod17.z.object({ fieldId: import_zod17.z.string() })]).describe(
2394
2374
  "Data entry can be either a static data entry, or a reference to another field in the current form or the declaration."
@@ -2435,7 +2415,7 @@ var HttpField = BaseField.extend({
2435
2415
  headers: import_zod17.z.record(import_zod17.z.string()).optional(),
2436
2416
  body: import_zod17.z.record(import_zod17.z.any()).optional(),
2437
2417
  errorValue: import_zod17.z.any().optional().describe("Value to set if the request fails"),
2438
- params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference, CodeToEvaluate])).optional(),
2418
+ params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference])).optional(),
2439
2419
  timeout: import_zod17.z.number().default(15e3).describe("Request timeout in milliseconds")
2440
2420
  })
2441
2421
  }).describe("HTTP request function triggered by a button click or other event");
@@ -3385,18 +3365,6 @@ function resolveDataPath(rootData, dataPath, instancePath) {
3385
3365
  }
3386
3366
  return current;
3387
3367
  }
3388
- function todayISO() {
3389
- return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
3390
- }
3391
- var compiledFunctionCache = /* @__PURE__ */ new Map();
3392
- function compileClientFunction(code) {
3393
- let fn = compiledFunctionCache.get(code);
3394
- if (!fn) {
3395
- fn = new Function(`return (${code})`)();
3396
- compiledFunctionCache.set(code, fn);
3397
- }
3398
- return fn;
3399
- }
3400
3368
  (0, import_ajv_formats.default)(ajv);
3401
3369
  ajv.addKeyword({
3402
3370
  keyword: "daysFromDate",
@@ -3442,21 +3410,12 @@ ajv.addKeyword({
3442
3410
  $data: true,
3443
3411
  errors: true,
3444
3412
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
3445
- validate(_schema, data, _2, dataContext) {
3413
+ validate(schema, data, _2, dataContext) {
3446
3414
  const locationIdInput = data;
3447
3415
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
3448
3416
  return locations.some((location) => location.id === locationIdInput);
3449
3417
  }
3450
3418
  });
3451
- ajv.addKeyword({
3452
- keyword: "customClientValidator",
3453
- schemaType: "object",
3454
- errors: true,
3455
- // @ts-ignore -- DataContext is not typed in AJV's public API
3456
- validate(schema, data, _2, dataContext) {
3457
- return compileClientFunction(schema.code)(data, dataContext?.rootData);
3458
- }
3459
- });
3460
3419
  function mergeWithBaseFormState(values, context) {
3461
3420
  return { ...context.baseFormState, ...values };
3462
3421
  }
@@ -4332,9 +4291,6 @@ function isFieldReference(value) {
4332
4291
  function isEventFieldReference(value) {
4333
4292
  return typeof value === "object" && value !== null && "$$event" in value;
4334
4293
  }
4335
- function isResolvableValueReference(value) {
4336
- return isFieldReference(value) || isCodeToEvaluate(value);
4337
- }
4338
4294
  function getDateRangeToFieldReference(field3, comparedField, clause) {
4339
4295
  return {
4340
4296
  type: "object",
@@ -4769,49 +4725,7 @@ function createFieldConditionals(fieldId) {
4769
4725
  }
4770
4726
  },
4771
4727
  required: [fieldId]
4772
- }),
4773
- /**
4774
- * Custom client-side validator. The provided function is serialised and executed
4775
- * just-in-time on the client only. External references (e.g. lodash) are not
4776
- * available inside the function body — all logic must be self-contained.
4777
- *
4778
- * @example
4779
- * field('nid').customClientValidator((value) => {
4780
- * // LUHN check — all logic must be inline
4781
- * const digits = String(value).split('').map(Number)
4782
- * // ...
4783
- * return isValid
4784
- * })
4785
- */
4786
- customClientValidator(validationFn) {
4787
- const code = validationFn.toString();
4788
- return defineFormConditional({
4789
- type: "object",
4790
- properties: wrapToPath(
4791
- { [fieldId]: { customClientValidator: { code } } },
4792
- this.$$subfield
4793
- ),
4794
- required: [fieldId]
4795
- });
4796
- },
4797
- /**
4798
- * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
4799
- * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
4800
- * The function is serialised and executed just-in-time on the client only.
4801
- * External references (e.g. lodash) are not available inside the function body.
4802
- *
4803
- * @example
4804
- * field('a').customClientEvaluation((aValue, ctx) =>
4805
- * Number(aValue) + Number(ctx.$form.b)
4806
- * )
4807
- */
4808
- customClientEvaluation(computationFn) {
4809
- return {
4810
- $$code: computationFn.toString(),
4811
- $$field: fieldId,
4812
- $$subfield: this.$$subfield
4813
- };
4814
- }
4728
+ })
4815
4729
  };
4816
4730
  }
4817
4731
 
@@ -5392,6 +5306,8 @@ var BaseActionInput = import_zod34.z.object({
5392
5306
  originalActionId: UUID.optional(),
5393
5307
  // should not be part of base action.
5394
5308
  keepAssignment: import_zod34.z.boolean().optional(),
5309
+ keepAssignmentIfAccepted: import_zod34.z.boolean().optional(),
5310
+ keepAssignmentIfRejected: import_zod34.z.boolean().optional(),
5395
5311
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5396
5312
  createdAtLocation: CreatedAtLocation.describe(
5397
5313
  "A valid office location ID. This is required for system users performing actions. The provided location must be a leaf-location, i.e. it must not have any children locations."
@@ -1493,15 +1493,6 @@ var FieldReference = import_zod17.z.object({
1493
1493
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1494
1494
  )
1495
1495
  }).describe("Reference to a field by its ID");
1496
- var CodeToEvaluate = import_zod17.z.object({
1497
- $$code: import_zod17.z.string().describe("Serialised client-side function body"),
1498
- $$field: FieldId.describe(
1499
- "Field whose value is passed as the first argument"
1500
- ),
1501
- $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe("Optional nested path within the field value")
1502
- }).describe(
1503
- "Serialised client-side evaluation function. Executed just-in-time on the client only."
1504
- );
1505
1496
  var ValidationConfig = import_zod17.z.object({
1506
1497
  validator: Conditional,
1507
1498
  message: TranslationConfig
@@ -1534,11 +1525,8 @@ var BaseField = import_zod17.z.object({
1534
1525
  uncorrectable: import_zod17.z.boolean().default(false).optional().describe(
1535
1526
  "Indicates whether the field can be modified during record correction."
1536
1527
  ),
1537
- value: FieldReference.or(CodeToEvaluate).or(import_zod17.z.array(FieldReference.or(CodeToEvaluate))).optional().describe(
1538
- "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."
1539
- ),
1540
- evaluatedDefaultValue: CodeToEvaluate.optional().describe(
1541
- "Custom client-side function used to compute the default value. Executed just-in-time on the client. Takes precedence over defaultValue when set."
1528
+ value: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
1529
+ "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."
1542
1530
  ),
1543
1531
  analytics: import_zod17.z.boolean().default(false).optional().describe(
1544
1532
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -1886,7 +1874,7 @@ var Address = BaseField.extend({
1886
1874
  var StaticDataEntry = import_zod17.z.object({
1887
1875
  id: import_zod17.z.string().describe("ID for the data entry."),
1888
1876
  label: TranslationConfig,
1889
- value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference).or(CodeToEvaluate)
1877
+ value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference)
1890
1878
  }).describe("Static data entry");
1891
1879
  var DataEntry = import_zod17.z.union([StaticDataEntry, import_zod17.z.object({ fieldId: import_zod17.z.string() })]).describe(
1892
1880
  "Data entry can be either a static data entry, or a reference to another field in the current form or the declaration."
@@ -1933,7 +1921,7 @@ var HttpField = BaseField.extend({
1933
1921
  headers: import_zod17.z.record(import_zod17.z.string()).optional(),
1934
1922
  body: import_zod17.z.record(import_zod17.z.any()).optional(),
1935
1923
  errorValue: import_zod17.z.any().optional().describe("Value to set if the request fails"),
1936
- params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference, CodeToEvaluate])).optional(),
1924
+ params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference])).optional(),
1937
1925
  timeout: import_zod17.z.number().default(15e3).describe("Request timeout in milliseconds")
1938
1926
  })
1939
1927
  }).describe("HTTP request function triggered by a button click or other event");
@@ -2568,15 +2556,6 @@ function resolveDataPath(rootData, dataPath, instancePath) {
2568
2556
  }
2569
2557
  return current;
2570
2558
  }
2571
- var compiledFunctionCache = /* @__PURE__ */ new Map();
2572
- function compileClientFunction(code) {
2573
- let fn = compiledFunctionCache.get(code);
2574
- if (!fn) {
2575
- fn = new Function(`return (${code})`)();
2576
- compiledFunctionCache.set(code, fn);
2577
- }
2578
- return fn;
2579
- }
2580
2559
  (0, import_ajv_formats.default)(ajv);
2581
2560
  ajv.addKeyword({
2582
2561
  keyword: "daysFromDate",
@@ -2622,21 +2601,12 @@ ajv.addKeyword({
2622
2601
  $data: true,
2623
2602
  errors: true,
2624
2603
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
2625
- validate(_schema, data, _2, dataContext) {
2604
+ validate(schema, data, _2, dataContext) {
2626
2605
  const locationIdInput = data;
2627
2606
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
2628
2607
  return locations.some((location) => location.id === locationIdInput);
2629
2608
  }
2630
2609
  });
2631
- ajv.addKeyword({
2632
- keyword: "customClientValidator",
2633
- schemaType: "object",
2634
- errors: true,
2635
- // @ts-ignore -- DataContext is not typed in AJV's public API
2636
- validate(schema, data, _2, dataContext) {
2637
- return compileClientFunction(schema.code)(data, dataContext?.rootData);
2638
- }
2639
- });
2640
2610
 
2641
2611
  // ../commons/src/utils.ts
2642
2612
  var z29 = __toESM(require("zod"));
@@ -3259,49 +3229,7 @@ function createFieldConditionals(fieldId) {
3259
3229
  }
3260
3230
  },
3261
3231
  required: [fieldId]
3262
- }),
3263
- /**
3264
- * Custom client-side validator. The provided function is serialised and executed
3265
- * just-in-time on the client only. External references (e.g. lodash) are not
3266
- * available inside the function body — all logic must be self-contained.
3267
- *
3268
- * @example
3269
- * field('nid').customClientValidator((value) => {
3270
- * // LUHN check — all logic must be inline
3271
- * const digits = String(value).split('').map(Number)
3272
- * // ...
3273
- * return isValid
3274
- * })
3275
- */
3276
- customClientValidator(validationFn) {
3277
- const code = validationFn.toString();
3278
- return defineFormConditional({
3279
- type: "object",
3280
- properties: wrapToPath(
3281
- { [fieldId]: { customClientValidator: { code } } },
3282
- this.$$subfield
3283
- ),
3284
- required: [fieldId]
3285
- });
3286
- },
3287
- /**
3288
- * Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
3289
- * that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
3290
- * The function is serialised and executed just-in-time on the client only.
3291
- * External references (e.g. lodash) are not available inside the function body.
3292
- *
3293
- * @example
3294
- * field('a').customClientEvaluation((aValue, ctx) =>
3295
- * Number(aValue) + Number(ctx.$form.b)
3296
- * )
3297
- */
3298
- customClientEvaluation(computationFn) {
3299
- return {
3300
- $$code: computationFn.toString(),
3301
- $$field: fieldId,
3302
- $$subfield: this.$$subfield
3303
- };
3304
- }
3232
+ })
3305
3233
  };
3306
3234
  }
3307
3235
 
@@ -3873,6 +3801,8 @@ var BaseActionInput = import_zod34.z.object({
3873
3801
  originalActionId: UUID.optional(),
3874
3802
  // should not be part of base action.
3875
3803
  keepAssignment: import_zod34.z.boolean().optional(),
3804
+ keepAssignmentIfAccepted: import_zod34.z.boolean().optional(),
3805
+ keepAssignmentIfRejected: import_zod34.z.boolean().optional(),
3876
3806
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
3877
3807
  createdAtLocation: CreatedAtLocation.describe(
3878
3808
  "A valid office location ID. This is required for system users performing actions. The provided location must be a leaf-location, i.e. it must not have any children locations."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.13-rc.bb847c0",
3
+ "version": "1.9.13-rc.c1f317c",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {
@@ -17,21 +17,21 @@
17
17
  "build:all": "lerna run build --include-dependencies --scope @opencrvs/toolkit && ./build.sh"
18
18
  },
19
19
  "dependencies": {
20
- "uuid": "^9.0.0",
20
+ "@trpc/client": "11.4.3",
21
+ "@trpc/server": "11.4.3",
21
22
  "ajv": "^8.17.1",
22
23
  "ajv-formats": "^3.0.1",
23
24
  "object-hash": "^3.0.0",
24
25
  "superjson": "1.9.0-0",
25
- "@trpc/client": "11.4.3",
26
- "@trpc/server": "11.4.3",
26
+ "uuid": "^9.0.0",
27
27
  "zod-openapi": "^4.2.4"
28
28
  },
29
29
  "devDependencies": {
30
+ "@opencrvs/events": "^1.9.0",
31
+ "@types/object-hash": "^3.0.6",
30
32
  "@types/uuid": "^9.0.3",
31
33
  "esbuild": "^0.24.0",
32
- "typescript": "^5.6.3",
33
- "@opencrvs/events": "^1.9.0",
34
- "@types/object-hash": "^3.0.6"
34
+ "typescript": "^5.6.3"
35
35
  },
36
36
  "moduleNameMapper": {
37
37
  "@opencrvs/commons/events": "@opencrvs/commons/build/dist/common/events/index.js",