@opencrvs/toolkit 1.8.1-rc.98d21b5 → 1.8.1-rc.b6b235d
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 +4 -0
- package/dist/commons/conditionals/validate.d.ts +3 -2
- package/dist/commons/events/EventIndex.d.ts +3 -0
- package/dist/commons/events/EventMetadata.d.ts +3 -0
- package/dist/commons/events/event.d.ts +55 -1
- package/dist/events/index.js +110 -25
- package/package.json +1 -1
@@ -7493,6 +7493,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
7493
7493
|
dateOfEvent?: string | null | undefined;
|
7494
7494
|
updatedAtLocation?: (string & import("zod").BRAND<"UUID">) | null | undefined;
|
7495
7495
|
updatedBy?: string | null | undefined;
|
7496
|
+
modifiedAt?: string | undefined;
|
7496
7497
|
}[];
|
7497
7498
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
7498
7499
|
}>;
|
@@ -7588,6 +7589,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
7588
7589
|
dateOfEvent?: string | null | undefined;
|
7589
7590
|
updatedAtLocation?: (string & import("zod").BRAND<"UUID">) | null | undefined;
|
7590
7591
|
updatedBy?: string | null | undefined;
|
7592
|
+
modifiedAt?: string | undefined;
|
7591
7593
|
}[];
|
7592
7594
|
meta: import("trpc-to-openapi").OpenApiMeta;
|
7593
7595
|
}>;
|
@@ -10805,6 +10807,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
10805
10807
|
set: import("@trpc/server").TRPCMutationProcedure<{
|
10806
10808
|
input: {
|
10807
10809
|
id: string;
|
10810
|
+
externalId: string | null;
|
10808
10811
|
name: string;
|
10809
10812
|
partOf: string | null;
|
10810
10813
|
}[];
|
@@ -10815,6 +10818,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
10815
10818
|
input: void;
|
10816
10819
|
output: {
|
10817
10820
|
id: string & import("zod").BRAND<"UUID">;
|
10821
|
+
externalId: string | null;
|
10818
10822
|
name: string;
|
10819
10823
|
partOf: (string & import("zod").BRAND<"UUID">) | null;
|
10820
10824
|
}[];
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { ConditionalParameters, JSONSchema } from './conditionals';
|
2
|
-
import {
|
2
|
+
import { ActionUpdate, EventState } from '../events/ActionDocument';
|
3
|
+
import { FieldConditional } from '../events/Conditional';
|
3
4
|
import { FieldConfig } from '../events/FieldConfig';
|
4
5
|
import { FieldUpdateValue } from '../events/FieldValue';
|
5
6
|
import { TranslationConfig } from '../events/TranslationConfig';
|
6
|
-
import { FieldConditional } from '../events/Conditional';
|
7
7
|
export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
|
8
8
|
export declare function isConditionMet(conditional: JSONSchema, values: Record<string, unknown>): boolean;
|
9
9
|
export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
|
@@ -77,4 +77,5 @@ export declare function runFieldValidations({ field, values }: {
|
|
77
77
|
}[];
|
78
78
|
};
|
79
79
|
export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
|
80
|
+
export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
|
80
81
|
//# sourceMappingURL=validate.d.ts.map
|
@@ -117,6 +117,7 @@ export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{
|
|
117
117
|
readonly REJECTED: "rejected";
|
118
118
|
readonly CORRECTION_REQUESTED: "correction-requested";
|
119
119
|
}>]>, "many">;
|
120
|
+
modifiedAt: z.ZodOptional<z.ZodString>;
|
120
121
|
}, {
|
121
122
|
declaration: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodString, z.ZodString, z.ZodUnion<[z.ZodObject<{
|
122
123
|
start: z.ZodString;
|
@@ -352,6 +353,7 @@ export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{
|
|
352
353
|
dateOfEvent?: string | null | undefined;
|
353
354
|
updatedAtLocation?: (string & z.BRAND<"UUID">) | null | undefined;
|
354
355
|
updatedBy?: string | null | undefined;
|
356
|
+
modifiedAt?: string | undefined;
|
355
357
|
}, {
|
356
358
|
type: string;
|
357
359
|
id: string;
|
@@ -439,6 +441,7 @@ export declare const EventIndex: z.ZodObject<z.objectUtil.extendShape<{
|
|
439
441
|
dateOfEvent?: string | null | undefined;
|
440
442
|
updatedAtLocation?: string | null | undefined;
|
441
443
|
updatedBy?: string | null | undefined;
|
444
|
+
modifiedAt?: string | undefined;
|
442
445
|
}>;
|
443
446
|
export declare const EventSearchIndex: z.ZodIntersection<z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodObject<{
|
444
447
|
type: z.ZodString;
|
@@ -297,6 +297,7 @@ export declare const EventMetadata: z.ZodObject<{
|
|
297
297
|
readonly REJECTED: "rejected";
|
298
298
|
readonly CORRECTION_REQUESTED: "correction-requested";
|
299
299
|
}>]>, "many">;
|
300
|
+
modifiedAt: z.ZodOptional<z.ZodString>;
|
300
301
|
}, "strip", z.ZodTypeAny, {
|
301
302
|
type: string;
|
302
303
|
id: string & z.BRAND<"UUID">;
|
@@ -335,6 +336,7 @@ export declare const EventMetadata: z.ZodObject<{
|
|
335
336
|
dateOfEvent?: string | null | undefined;
|
336
337
|
updatedAtLocation?: (string & z.BRAND<"UUID">) | null | undefined;
|
337
338
|
updatedBy?: string | null | undefined;
|
339
|
+
modifiedAt?: string | undefined;
|
338
340
|
}, {
|
339
341
|
type: string;
|
340
342
|
id: string;
|
@@ -373,6 +375,7 @@ export declare const EventMetadata: z.ZodObject<{
|
|
373
375
|
dateOfEvent?: string | null | undefined;
|
374
376
|
updatedAtLocation?: string | null | undefined;
|
375
377
|
updatedBy?: string | null | undefined;
|
378
|
+
modifiedAt?: string | undefined;
|
376
379
|
}>;
|
377
380
|
export type EventMetadata = z.infer<typeof EventMetadata>;
|
378
381
|
export declare const EventMetadataKeysArray: readonly ["id", "type", "status", "createdAt", "dateOfEvent", "createdBy", "createdByUserType", "updatedByUserRole", "createdAtLocation", "updatedAtLocation", "updatedAt", "assignedTo", "updatedBy", "trackingId", "legalStatuses", "flags"];
|
@@ -45,9 +45,63 @@ declare function eventFn(fieldId: EventFieldId): {
|
|
45
45
|
declare const event: typeof eventFn & {
|
46
46
|
/**
|
47
47
|
* Checks if the event contains a specific action type.
|
48
|
+
* Can be used directly as a conditional or chained with additional methods.
|
48
49
|
* @param action - The action type to check for.
|
49
50
|
*/
|
50
|
-
hasAction: (action: ActionType) =>
|
51
|
+
hasAction: (action: ActionType) => {
|
52
|
+
/**
|
53
|
+
* Creates a conditional that checks if the event contains a specific action type
|
54
|
+
* with a minimum count of occurrences.
|
55
|
+
*
|
56
|
+
* @param minCount - The minimum number of actions required.
|
57
|
+
*/
|
58
|
+
minCount: (minCount: number) => import("../conditionals/conditionals").JSONSchema;
|
59
|
+
/**
|
60
|
+
* Builds a conditional that sets a maximum count for the number of actions.
|
61
|
+
* This is useful for limiting the number of actions of a specific type in a single event.
|
62
|
+
*/
|
63
|
+
maxCount: (maxCount: number) => import("../conditionals/conditionals").JSONSchema;
|
64
|
+
/**
|
65
|
+
* Adds additional field constraints to the action matching.
|
66
|
+
*
|
67
|
+
* @param fields - Object containing additional fields to match on the action.
|
68
|
+
*/
|
69
|
+
withFields: (fields: Record<string, unknown>) => {
|
70
|
+
/**
|
71
|
+
* Creates a conditional that checks if the event contains a specific action type
|
72
|
+
* with a minimum count of occurrences.
|
73
|
+
*
|
74
|
+
* @param minCount - The minimum number of actions required.
|
75
|
+
*/
|
76
|
+
minCount: (minCount: number) => import("../conditionals/conditionals").JSONSchema;
|
77
|
+
/**
|
78
|
+
* Builds a conditional that sets a maximum count for the number of actions.
|
79
|
+
* This is useful for limiting the number of actions of a specific type in a single event.
|
80
|
+
*/
|
81
|
+
maxCount: (maxCount: number) => import("../conditionals/conditionals").JSONSchema;
|
82
|
+
};
|
83
|
+
/**
|
84
|
+
* Adds template ID constraint to the action matching.
|
85
|
+
* This is a convenience method that adds content.templateId to the fields.
|
86
|
+
*
|
87
|
+
* @param id - The template ID to match against.
|
88
|
+
*/
|
89
|
+
withTemplate: (id: string) => {
|
90
|
+
/**
|
91
|
+
* Creates a conditional that checks if the event contains a specific action type
|
92
|
+
* with a minimum count of occurrences.
|
93
|
+
*
|
94
|
+
* @param minCount - The minimum number of actions required.
|
95
|
+
*/
|
96
|
+
minCount: (minCount: number) => import("../conditionals/conditionals").JSONSchema;
|
97
|
+
/**
|
98
|
+
* Builds a conditional that sets a maximum count for the number of actions.
|
99
|
+
* This is useful for limiting the number of actions of a specific type in a single event.
|
100
|
+
*/
|
101
|
+
maxCount: (maxCount: number) => import("../conditionals/conditionals").JSONSchema;
|
102
|
+
};
|
103
|
+
__nominal__type: "JSONSchema";
|
104
|
+
};
|
51
105
|
field(field: WorkqueueColumnKeys): WorkqueueColumnValue;
|
52
106
|
};
|
53
107
|
export { event };
|
package/dist/events/index.js
CHANGED
@@ -198,6 +198,7 @@ __export(events_exports, {
|
|
198
198
|
annotationActions: () => annotationActions,
|
199
199
|
applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
|
200
200
|
applyDraftsToEventIndex: () => applyDraftsToEventIndex,
|
201
|
+
areCertificateConditionsMet: () => areCertificateConditionsMet,
|
201
202
|
areConditionsMet: () => areConditionsMet,
|
202
203
|
compositeFieldTypes: () => compositeFieldTypes,
|
203
204
|
createEmptyDraft: () => createEmptyDraft,
|
@@ -1223,7 +1224,8 @@ var CertificateConfig = import_zod11.z.object({
|
|
1223
1224
|
delayed: import_zod11.z.number()
|
1224
1225
|
}),
|
1225
1226
|
svgUrl: import_zod11.z.string(),
|
1226
|
-
fonts: import_zod11.z.record(FontFamily).optional()
|
1227
|
+
fonts: import_zod11.z.record(FontFamily).optional(),
|
1228
|
+
conditionals: import_zod11.z.array(ShowConditional).optional()
|
1227
1229
|
});
|
1228
1230
|
var CertificateTemplateConfig = CertificateConfig.extend({
|
1229
1231
|
hash: import_zod11.z.string().optional(),
|
@@ -2045,7 +2047,7 @@ var ResolvedUser = import_zod19.z.object({
|
|
2045
2047
|
});
|
2046
2048
|
|
2047
2049
|
// ../commons/src/conditionals/validate.ts
|
2048
|
-
var
|
2050
|
+
var import__ = __toESM(require("ajv/dist/2019"));
|
2049
2051
|
var import_ajv_formats = __toESM(require("ajv-formats"));
|
2050
2052
|
var import_date_fns = require("date-fns");
|
2051
2053
|
|
@@ -2259,9 +2261,11 @@ var isNonInteractiveFieldType = (field2) => {
|
|
2259
2261
|
};
|
2260
2262
|
|
2261
2263
|
// ../commons/src/conditionals/validate.ts
|
2262
|
-
var ajv = new
|
2264
|
+
var ajv = new import__.default({
|
2263
2265
|
$data: true,
|
2264
|
-
allowUnionTypes: true
|
2266
|
+
allowUnionTypes: true,
|
2267
|
+
strict: false
|
2268
|
+
// Allow minContains and other newer features
|
2265
2269
|
});
|
2266
2270
|
(0, import_ajv_formats.default)(ajv);
|
2267
2271
|
ajv.addKeyword({
|
@@ -2499,6 +2503,11 @@ function getValidatorsForField(fieldId, validations) {
|
|
2499
2503
|
};
|
2500
2504
|
}).filter((x) => x !== null);
|
2501
2505
|
}
|
2506
|
+
function areCertificateConditionsMet(conditions, values) {
|
2507
|
+
return conditions.every((condition) => {
|
2508
|
+
return ajv.validate(condition.conditional, values);
|
2509
|
+
});
|
2510
|
+
}
|
2502
2511
|
|
2503
2512
|
// ../commons/src/utils.ts
|
2504
2513
|
function getOrThrow(x, message) {
|
@@ -3222,32 +3231,107 @@ function eventFn(fieldId) {
|
|
3222
3231
|
var event = Object.assign(eventFn, {
|
3223
3232
|
/**
|
3224
3233
|
* Checks if the event contains a specific action type.
|
3234
|
+
* Can be used directly as a conditional or chained with additional methods.
|
3225
3235
|
* @param action - The action type to check for.
|
3226
3236
|
*/
|
3227
|
-
hasAction: (action) =>
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
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({
|
3231
3278
|
type: "object",
|
3232
3279
|
properties: {
|
3233
|
-
|
3234
|
-
type: "
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
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"]
|
3244
3294
|
}
|
3245
3295
|
},
|
3246
|
-
required: ["
|
3247
|
-
}
|
3248
|
-
}
|
3249
|
-
|
3250
|
-
|
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
|
+
},
|
3251
3335
|
field(field2) {
|
3252
3336
|
return {
|
3253
3337
|
$event: field2
|
@@ -3332,7 +3416,8 @@ var EventMetadata = import_zod23.z.object({
|
|
3332
3416
|
trackingId: import_zod23.z.string().describe(
|
3333
3417
|
"System-generated tracking ID used by informants or registrars to look up the event."
|
3334
3418
|
),
|
3335
|
-
flags: import_zod23.z.array(Flag)
|
3419
|
+
flags: import_zod23.z.array(Flag),
|
3420
|
+
modifiedAt: import_zod23.z.string().optional()
|
3336
3421
|
});
|
3337
3422
|
var EventMetadataKeysArray = [
|
3338
3423
|
"id",
|