@opencrvs/toolkit 1.8.1-rc.facd84c → 1.8.1-rc.fbb3bff
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.
- package/dist/commons/api/router.d.ts +18 -2
- package/dist/commons/conditionals/validate.d.ts +3 -2
- package/dist/commons/events/ActionDocument.d.ts +536 -0
- package/dist/commons/events/ActionInput.d.ts +26 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +34 -34
- package/dist/commons/events/EventConfig.d.ts +22 -22
- package/dist/commons/events/EventDocument.d.ts +19 -0
- package/dist/commons/events/EventIndex.d.ts +122 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +89 -0
- package/dist/commons/events/defineConfig.d.ts +2 -2
- package/dist/commons/events/event.d.ts +63 -1
- package/dist/commons/events/field.d.ts +14 -0
- package/dist/commons/events/utils.d.ts +2 -2
- package/dist/events/index.js +147 -28
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/dist/commons/conditionals/conditionals.test.d.ts +0 -2
- package/dist/commons/conditionals/validate-address.test.d.ts +0 -2
- package/dist/commons/conditionals/validate.test.d.ts +0 -2
- package/dist/commons/events/utils.test.d.ts +0 -2
package/dist/events/index.js
CHANGED
@@ -139,6 +139,7 @@ __export(events_exports, {
|
|
139
139
|
PageConfig: () => PageConfig,
|
140
140
|
PageTypes: () => PageTypes,
|
141
141
|
PrintCertificateActionInput: () => PrintCertificateActionInput,
|
142
|
+
PrintContent: () => PrintContent,
|
142
143
|
QueryExpression: () => QueryExpression,
|
143
144
|
QueryInput: () => QueryInput,
|
144
145
|
QueryType: () => QueryType,
|
@@ -197,6 +198,7 @@ __export(events_exports, {
|
|
197
198
|
annotationActions: () => annotationActions,
|
198
199
|
applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
|
199
200
|
applyDraftsToEventIndex: () => applyDraftsToEventIndex,
|
201
|
+
areCertificateConditionsMet: () => areCertificateConditionsMet,
|
200
202
|
areConditionsMet: () => areConditionsMet,
|
201
203
|
compositeFieldTypes: () => compositeFieldTypes,
|
202
204
|
createEmptyDraft: () => createEmptyDraft,
|
@@ -1222,7 +1224,8 @@ var CertificateConfig = import_zod11.z.object({
|
|
1222
1224
|
delayed: import_zod11.z.number()
|
1223
1225
|
}),
|
1224
1226
|
svgUrl: import_zod11.z.string(),
|
1225
|
-
fonts: import_zod11.z.record(FontFamily).optional()
|
1227
|
+
fonts: import_zod11.z.record(FontFamily).optional(),
|
1228
|
+
conditionals: import_zod11.z.array(ShowConditional).optional()
|
1226
1229
|
});
|
1227
1230
|
var CertificateTemplateConfig = CertificateConfig.extend({
|
1228
1231
|
hash: import_zod11.z.string().optional(),
|
@@ -1340,7 +1343,7 @@ var SummaryConfig = import_zod14.z.object({
|
|
1340
1343
|
|
1341
1344
|
// ../commons/src/events/AdvancedSearchConfig.ts
|
1342
1345
|
var import_zod15 = require("zod");
|
1343
|
-
var MatchType = import_zod15.z.enum(["fuzzy", "exact", "range"]);
|
1346
|
+
var MatchType = import_zod15.z.enum(["fuzzy", "exact", "range", "within"]);
|
1344
1347
|
var BaseField3 = import_zod15.z.object({
|
1345
1348
|
config: import_zod15.z.object({
|
1346
1349
|
type: MatchType.describe("Determines the type of field")
|
@@ -1902,11 +1905,15 @@ var ActionBase = import_zod19.z.object({
|
|
1902
1905
|
originalActionId: UUID.optional().nullable().describe(
|
1903
1906
|
"Reference to the original action that was asynchronously rejected or accepted by 3rd party integration."
|
1904
1907
|
)
|
1908
|
+
// 'content' field reserved for additional data
|
1909
|
+
// Each action can define its own content specifc to the action
|
1910
|
+
// See PrintCertificateAction
|
1905
1911
|
});
|
1906
1912
|
var AssignedAction = ActionBase.merge(
|
1907
1913
|
import_zod19.z.object({
|
1908
1914
|
type: import_zod19.z.literal(ActionType.ASSIGN),
|
1909
1915
|
assignedTo: import_zod19.z.string()
|
1916
|
+
// TODO move into 'content' property
|
1910
1917
|
})
|
1911
1918
|
);
|
1912
1919
|
var UnassignedAction = ActionBase.merge(
|
@@ -1918,6 +1925,7 @@ var RegisterAction = ActionBase.merge(
|
|
1918
1925
|
import_zod19.z.object({
|
1919
1926
|
type: import_zod19.z.literal(ActionType.REGISTER),
|
1920
1927
|
registrationNumber: import_zod19.z.string().optional()
|
1928
|
+
// TODO move into 'content' property
|
1921
1929
|
})
|
1922
1930
|
);
|
1923
1931
|
var DeclareAction = ActionBase.merge(
|
@@ -1938,6 +1946,7 @@ var RejectAction = ActionBase.merge(
|
|
1938
1946
|
import_zod19.z.object({
|
1939
1947
|
type: import_zod19.z.literal(ActionType.REJECT),
|
1940
1948
|
reason: RejectionReason
|
1949
|
+
// TODO move into 'content' property
|
1941
1950
|
})
|
1942
1951
|
);
|
1943
1952
|
var MarkAsDuplicateAction = ActionBase.merge(
|
@@ -1949,6 +1958,7 @@ var ArchiveAction = ActionBase.merge(
|
|
1949
1958
|
import_zod19.z.object({
|
1950
1959
|
type: import_zod19.z.literal(ActionType.ARCHIVE),
|
1951
1960
|
reason: RejectionReason
|
1961
|
+
// TODO move into 'content' property
|
1952
1962
|
})
|
1953
1963
|
);
|
1954
1964
|
var CreatedAction = ActionBase.merge(
|
@@ -1961,9 +1971,13 @@ var NotifiedAction = ActionBase.merge(
|
|
1961
1971
|
type: import_zod19.z.literal(ActionType.NOTIFY)
|
1962
1972
|
})
|
1963
1973
|
);
|
1974
|
+
var PrintContent = import_zod19.z.object({
|
1975
|
+
templateId: import_zod19.z.string().optional()
|
1976
|
+
});
|
1964
1977
|
var PrintCertificateAction = ActionBase.merge(
|
1965
1978
|
import_zod19.z.object({
|
1966
|
-
type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE)
|
1979
|
+
type: import_zod19.z.literal(ActionType.PRINT_CERTIFICATE),
|
1980
|
+
content: PrintContent.optional().nullable()
|
1967
1981
|
})
|
1968
1982
|
);
|
1969
1983
|
var RequestedCorrectionAction = ActionBase.merge(
|
@@ -1975,12 +1989,14 @@ var ApprovedCorrectionAction = ActionBase.merge(
|
|
1975
1989
|
import_zod19.z.object({
|
1976
1990
|
type: import_zod19.z.literal(ActionType.APPROVE_CORRECTION),
|
1977
1991
|
requestId: import_zod19.z.string()
|
1992
|
+
// TODO move into 'content' property
|
1978
1993
|
})
|
1979
1994
|
);
|
1980
1995
|
var RejectedCorrectionAction = ActionBase.merge(
|
1981
1996
|
import_zod19.z.object({
|
1982
1997
|
type: import_zod19.z.literal(ActionType.REJECT_CORRECTION),
|
1983
1998
|
requestId: import_zod19.z.string(),
|
1999
|
+
// TODO move into 'content' property
|
1984
2000
|
reason: RejectionReason
|
1985
2001
|
})
|
1986
2002
|
);
|
@@ -2031,7 +2047,7 @@ var ResolvedUser = import_zod19.z.object({
|
|
2031
2047
|
});
|
2032
2048
|
|
2033
2049
|
// ../commons/src/conditionals/validate.ts
|
2034
|
-
var
|
2050
|
+
var import__ = __toESM(require("ajv/dist/2019"));
|
2035
2051
|
var import_ajv_formats = __toESM(require("ajv-formats"));
|
2036
2052
|
var import_date_fns = require("date-fns");
|
2037
2053
|
|
@@ -2245,9 +2261,11 @@ var isNonInteractiveFieldType = (field2) => {
|
|
2245
2261
|
};
|
2246
2262
|
|
2247
2263
|
// ../commons/src/conditionals/validate.ts
|
2248
|
-
var ajv = new
|
2264
|
+
var ajv = new import__.default({
|
2249
2265
|
$data: true,
|
2250
|
-
allowUnionTypes: true
|
2266
|
+
allowUnionTypes: true,
|
2267
|
+
strict: false
|
2268
|
+
// Allow minContains and other newer features
|
2251
2269
|
});
|
2252
2270
|
(0, import_ajv_formats.default)(ajv);
|
2253
2271
|
ajv.addKeyword({
|
@@ -2485,6 +2503,11 @@ function getValidatorsForField(fieldId, validations) {
|
|
2485
2503
|
};
|
2486
2504
|
}).filter((x) => x !== null);
|
2487
2505
|
}
|
2506
|
+
function areCertificateConditionsMet(conditions, values) {
|
2507
|
+
return conditions.every((condition) => {
|
2508
|
+
return ajv.validate(condition.conditional, values);
|
2509
|
+
});
|
2510
|
+
}
|
2488
2511
|
|
2489
2512
|
// ../commons/src/utils.ts
|
2490
2513
|
function getOrThrow(x, message) {
|
@@ -3175,6 +3198,19 @@ function createSearchConfig(baseField) {
|
|
3175
3198
|
fuzzy: () => ({
|
3176
3199
|
...baseField,
|
3177
3200
|
config: { type: "fuzzy" }
|
3201
|
+
}),
|
3202
|
+
/**
|
3203
|
+
* Creates a configuration for matching locations and the child locations
|
3204
|
+
* @returns An object containing the field ID and a configuration object with a type of 'within'.
|
3205
|
+
* @example field('createdAtLocation').within()
|
3206
|
+
* // {
|
3207
|
+
* // ...
|
3208
|
+
* // config: { type: 'within' }
|
3209
|
+
* // }
|
3210
|
+
*/
|
3211
|
+
within: () => ({
|
3212
|
+
...baseField,
|
3213
|
+
config: { type: "within" }
|
3178
3214
|
})
|
3179
3215
|
};
|
3180
3216
|
}
|
@@ -3195,32 +3231,107 @@ function eventFn(fieldId) {
|
|
3195
3231
|
var event = Object.assign(eventFn, {
|
3196
3232
|
/**
|
3197
3233
|
* Checks if the event contains a specific action type.
|
3234
|
+
* Can be used directly as a conditional or chained with additional methods.
|
3198
3235
|
* @param action - The action type to check for.
|
3199
3236
|
*/
|
3200
|
-
hasAction: (action) =>
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3237
|
+
hasAction: (action) => {
|
3238
|
+
const basicConditional = defineConditional({
|
3239
|
+
type: "object",
|
3240
|
+
properties: {
|
3241
|
+
$event: {
|
3242
|
+
type: "object",
|
3243
|
+
properties: {
|
3244
|
+
actions: {
|
3245
|
+
type: "array",
|
3246
|
+
contains: {
|
3247
|
+
type: "object",
|
3248
|
+
properties: {
|
3249
|
+
type: {
|
3250
|
+
const: action
|
3251
|
+
}
|
3252
|
+
},
|
3253
|
+
required: ["type"]
|
3254
|
+
}
|
3255
|
+
}
|
3256
|
+
},
|
3257
|
+
required: ["actions"]
|
3258
|
+
}
|
3259
|
+
},
|
3260
|
+
required: ["$event"]
|
3261
|
+
});
|
3262
|
+
const buildActionConstraints = (additionalFields) => {
|
3263
|
+
const actionProperties = {
|
3264
|
+
type: { const: action }
|
3265
|
+
};
|
3266
|
+
const requiredFields = ["type"];
|
3267
|
+
if (additionalFields) {
|
3268
|
+
Object.entries(additionalFields).forEach(([key, value]) => {
|
3269
|
+
actionProperties[key] = { const: value };
|
3270
|
+
requiredFields.push(key);
|
3271
|
+
});
|
3272
|
+
}
|
3273
|
+
return { actionProperties, requiredFields };
|
3274
|
+
};
|
3275
|
+
const createCountConditional = (countType, count, additionalFields) => {
|
3276
|
+
const { actionProperties, requiredFields } = buildActionConstraints(additionalFields);
|
3277
|
+
return defineConditional({
|
3204
3278
|
type: "object",
|
3205
3279
|
properties: {
|
3206
|
-
|
3207
|
-
type: "
|
3208
|
-
|
3209
|
-
|
3210
|
-
|
3211
|
-
|
3212
|
-
|
3213
|
-
|
3214
|
-
|
3215
|
-
|
3216
|
-
|
3280
|
+
$event: {
|
3281
|
+
type: "object",
|
3282
|
+
properties: {
|
3283
|
+
actions: {
|
3284
|
+
type: "array",
|
3285
|
+
contains: {
|
3286
|
+
type: "object",
|
3287
|
+
properties: actionProperties,
|
3288
|
+
required: requiredFields
|
3289
|
+
},
|
3290
|
+
[countType]: count
|
3291
|
+
}
|
3292
|
+
},
|
3293
|
+
required: ["actions"]
|
3217
3294
|
}
|
3218
3295
|
},
|
3219
|
-
required: ["
|
3220
|
-
}
|
3221
|
-
}
|
3222
|
-
|
3223
|
-
|
3296
|
+
required: ["$event"]
|
3297
|
+
});
|
3298
|
+
};
|
3299
|
+
const withMinMax = (additionalFields) => {
|
3300
|
+
return {
|
3301
|
+
/**
|
3302
|
+
* Creates a conditional that checks if the event contains a specific action type
|
3303
|
+
* with a minimum count of occurrences.
|
3304
|
+
*
|
3305
|
+
* @param minCount - The minimum number of actions required.
|
3306
|
+
*/
|
3307
|
+
minCount: (minCount) => createCountConditional("minContains", minCount, additionalFields),
|
3308
|
+
/**
|
3309
|
+
* Builds a conditional that sets a maximum count for the number of actions.
|
3310
|
+
* This is useful for limiting the number of actions of a specific type in a single event.
|
3311
|
+
*/
|
3312
|
+
maxCount: (maxCount) => createCountConditional("maxContains", maxCount, additionalFields)
|
3313
|
+
};
|
3314
|
+
};
|
3315
|
+
const chainableMethods = {
|
3316
|
+
/**
|
3317
|
+
* Adds additional field constraints to the action matching.
|
3318
|
+
*
|
3319
|
+
* @param fields - Object containing additional fields to match on the action.
|
3320
|
+
*/
|
3321
|
+
withFields: (fields) => withMinMax(fields),
|
3322
|
+
/**
|
3323
|
+
* Adds template ID constraint to the action matching.
|
3324
|
+
* This is a convenience method that adds content.templateId to the fields.
|
3325
|
+
*
|
3326
|
+
* @param id - The template ID to match against.
|
3327
|
+
*/
|
3328
|
+
withTemplate: (id) => withMinMax({
|
3329
|
+
content: { templateId: id }
|
3330
|
+
}),
|
3331
|
+
...withMinMax()
|
3332
|
+
};
|
3333
|
+
return { ...basicConditional, ...chainableMethods };
|
3334
|
+
},
|
3224
3335
|
field(field2) {
|
3225
3336
|
return {
|
3226
3337
|
$event: field2
|
@@ -3524,6 +3635,9 @@ var QueryExpression = import_zod25.z.object({
|
|
3524
3635
|
createdAt: import_zod25.z.optional(DateCondition),
|
3525
3636
|
updatedAt: import_zod25.z.optional(DateCondition),
|
3526
3637
|
"legalStatuses.REGISTERED.acceptedAt": import_zod25.z.optional(DateCondition),
|
3638
|
+
"legalStatuses.DECLARED.createdAtLocation": import_zod25.z.optional(
|
3639
|
+
import_zod25.z.union([Within, Exact])
|
3640
|
+
),
|
3527
3641
|
"legalStatuses.REGISTERED.createdAtLocation": import_zod25.z.optional(
|
3528
3642
|
import_zod25.z.union([Within, Exact])
|
3529
3643
|
),
|
@@ -3877,7 +3991,8 @@ var DeclareActionInput = BaseActionInput.merge(
|
|
3877
3991
|
);
|
3878
3992
|
var PrintCertificateActionInput = BaseActionInput.merge(
|
3879
3993
|
import_zod29.z.object({
|
3880
|
-
type: import_zod29.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE)
|
3994
|
+
type: import_zod29.z.literal(ActionType.PRINT_CERTIFICATE).default(ActionType.PRINT_CERTIFICATE),
|
3995
|
+
content: PrintContent.optional()
|
3881
3996
|
})
|
3882
3997
|
);
|
3883
3998
|
var RejectDeclarationActionInput = BaseActionInput.merge(
|
@@ -6819,7 +6934,11 @@ function generateActionDocument({
|
|
6819
6934
|
case ActionType.NOTIFY:
|
6820
6935
|
return { ...actionBase, type: action };
|
6821
6936
|
case ActionType.PRINT_CERTIFICATE:
|
6822
|
-
return {
|
6937
|
+
return {
|
6938
|
+
...actionBase,
|
6939
|
+
type: action,
|
6940
|
+
content: defaults.content
|
6941
|
+
};
|
6823
6942
|
case ActionType.REQUEST_CORRECTION:
|
6824
6943
|
return { ...actionBase, type: action };
|
6825
6944
|
case ActionType.APPROVE_CORRECTION:
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
"@opencrvs/commons/events": ["../commons/src/events/index.ts"]
|
20
20
|
}
|
21
21
|
},
|
22
|
-
"references": [{ "path": "../commons" }],
|
22
|
+
"references": [{ "path": "../commons/tsconfig-commonjs.json" }],
|
23
23
|
"include": ["src/**/*.ts"],
|
24
24
|
"exclude": ["**/node_modules/**", "dist"]
|
25
25
|
}
|