@dev.smartpricing/message-composer-utils 4.5.1-next.2 → 5.0.0-automations.0
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/schemas/automation-catalog.js +47 -0
- package/dist/schemas/automation-catalog.js.map +1 -0
- package/dist/schemas/automation.js +191 -0
- package/dist/schemas/automation.js.map +1 -0
- package/dist/schemas/condition.js +17 -0
- package/dist/schemas/condition.js.map +1 -0
- package/dist/schemas/condition.test.js +73 -0
- package/dist/schemas/condition.test.js.map +1 -0
- package/dist/schemas/index.js +3 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/message-group.js +10 -8
- package/dist/schemas/message-group.js.map +1 -1
- package/dist/types/app.js +3 -0
- package/dist/types/app.js.map +1 -1
- package/dist/types/automation-catalog.js +16 -0
- package/dist/types/automation-catalog.js.map +1 -0
- package/dist/types/automation.js +9 -0
- package/dist/types/automation.js.map +1 -0
- package/dist/types/condition.js +51 -0
- package/dist/types/condition.js.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/schemas/automation-catalog.ts +62 -0
- package/src/schemas/automation.ts +230 -0
- package/src/schemas/condition.test.ts +92 -0
- package/src/schemas/condition.ts +27 -0
- package/src/schemas/index.ts +3 -0
- package/src/schemas/message-group.ts +15 -11
- package/src/types/app.ts +3 -0
- package/src/types/automation-catalog.ts +79 -0
- package/src/types/automation.ts +216 -0
- package/src/types/condition.ts +114 -0
- package/src/types/index.ts +3 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conditions in the Automation Engine's shape, and the closed vocabulary the
|
|
3
|
+
* filter components and the backend share (ADR 0018). Nothing here knows
|
|
4
|
+
* about Automations: an audience page edits Conditions too.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Every operator the Automation Engine accepts. */
|
|
8
|
+
export const CONDITION_OPERATORS = [
|
|
9
|
+
"eq",
|
|
10
|
+
"neq",
|
|
11
|
+
"gt",
|
|
12
|
+
"gte",
|
|
13
|
+
"lt",
|
|
14
|
+
"lte",
|
|
15
|
+
"in",
|
|
16
|
+
"not_in",
|
|
17
|
+
"contains",
|
|
18
|
+
"exclude",
|
|
19
|
+
"exists",
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export type ConditionOperator = (typeof CONDITION_OPERATORS)[number];
|
|
23
|
+
|
|
24
|
+
export const CONDITION_FIELD_TYPES = [
|
|
25
|
+
"select",
|
|
26
|
+
"multiselect",
|
|
27
|
+
"number",
|
|
28
|
+
"price",
|
|
29
|
+
"date",
|
|
30
|
+
"text",
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
export type ConditionFieldType = (typeof CONDITION_FIELD_TYPES)[number];
|
|
34
|
+
|
|
35
|
+
/** One test on a Trigger Event's data. `exists` takes no value. */
|
|
36
|
+
export interface Condition {
|
|
37
|
+
field: string;
|
|
38
|
+
operator: ConditionOperator;
|
|
39
|
+
value?: unknown;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The operators of the field types whose values have an order. */
|
|
43
|
+
const ORDERED_VALUE_OPERATORS = [
|
|
44
|
+
"eq",
|
|
45
|
+
"neq",
|
|
46
|
+
"gt",
|
|
47
|
+
"gte",
|
|
48
|
+
"lt",
|
|
49
|
+
"lte",
|
|
50
|
+
"exists",
|
|
51
|
+
] as const satisfies readonly ConditionOperator[];
|
|
52
|
+
|
|
53
|
+
/** The operators a Condition on a field of each type can use (ADR 0018). */
|
|
54
|
+
export const CONDITION_OPERATORS_BY_FIELD_TYPE = {
|
|
55
|
+
select: ["eq", "neq", "exists"],
|
|
56
|
+
multiselect: ["in", "not_in", "exists"],
|
|
57
|
+
number: ORDERED_VALUE_OPERATORS,
|
|
58
|
+
price: ORDERED_VALUE_OPERATORS,
|
|
59
|
+
date: ORDERED_VALUE_OPERATORS,
|
|
60
|
+
text: ["eq", "neq", "contains", "exclude", "exists"],
|
|
61
|
+
} as const satisfies Record<ConditionFieldType, readonly ConditionOperator[]>;
|
|
62
|
+
|
|
63
|
+
export function operatorFitsFieldType(
|
|
64
|
+
operator: ConditionOperator,
|
|
65
|
+
fieldType: ConditionFieldType,
|
|
66
|
+
): boolean {
|
|
67
|
+
const operators: readonly ConditionOperator[] =
|
|
68
|
+
CONDITION_OPERATORS_BY_FIELD_TYPE[fieldType];
|
|
69
|
+
return operators.includes(operator);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* What a caller passes to the layer's filter components (`FiltersEditor`,
|
|
74
|
+
* `FiltersSummary`) and what they report back (ADR 0018).
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export type FilterOptionValue = string | number;
|
|
78
|
+
|
|
79
|
+
export interface FilterOption {
|
|
80
|
+
value: FilterOptionValue;
|
|
81
|
+
label: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** One field a Condition can test, label and options already resolved. */
|
|
85
|
+
export interface FilterField {
|
|
86
|
+
/** The `field` of the Conditions on it. */
|
|
87
|
+
key: string;
|
|
88
|
+
label: string;
|
|
89
|
+
type: ConditionFieldType;
|
|
90
|
+
/** For `select` and `multiselect`. A list that is not there shows as empty. */
|
|
91
|
+
options?: FilterOption[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Why a Condition shows as an unavailable row: its field is not in `fields`,
|
|
96
|
+
* or the editor cannot edit it (an operator or a value that does not fit the
|
|
97
|
+
* field's type, one Condition too many on a field).
|
|
98
|
+
*/
|
|
99
|
+
export type FilterUnavailableReason = "unknown_field" | "not_editable";
|
|
100
|
+
|
|
101
|
+
/** What is wrong with a list of Conditions. The caller decides what blocks. */
|
|
102
|
+
export interface FiltersReport {
|
|
103
|
+
/** The fields of the Conditions that are on none of `fields`, each once. */
|
|
104
|
+
unknownFields: string[];
|
|
105
|
+
/** Every Condition shown as an unavailable row, the unknown fields included. */
|
|
106
|
+
unavailable: { condition: Condition; reason: FilterUnavailableReason }[];
|
|
107
|
+
/** Every selected option value that is not in its field's `options`. */
|
|
108
|
+
unavailableOptions: { field: string; value: FilterOptionValue }[];
|
|
109
|
+
/**
|
|
110
|
+
* Rows with a field picked and no complete value. They are not in the
|
|
111
|
+
* emitted Conditions. Always 0 from `FiltersSummary`.
|
|
112
|
+
*/
|
|
113
|
+
halfFilled: number;
|
|
114
|
+
}
|
package/src/types/index.ts
CHANGED