@beabee/beabee-common 1.19.6 → 1.19.7
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/README.md +41 -0
- package/dist/cjs/data/index.cjs +87 -0
- package/dist/cjs/error/InvalidRule.cjs +35 -0
- package/dist/cjs/error/index.cjs +22 -0
- package/dist/cjs/index.cjs +28 -0
- package/dist/cjs/search/api-keys.cjs +35 -0
- package/dist/cjs/search/callouts.cjs +131 -0
- package/dist/cjs/search/contacts.cjs +105 -0
- package/dist/cjs/search/index.cjs +32 -0
- package/dist/cjs/search/notices.cjs +61 -0
- package/dist/cjs/search/operators.cjs +89 -0
- package/dist/cjs/search/payments.cjs +51 -0
- package/dist/cjs/types/api-key-filter-name.cjs +16 -0
- package/dist/cjs/types/array-filter-args.cjs +16 -0
- package/dist/cjs/types/base-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/base-filter-args.cjs +16 -0
- package/dist/cjs/types/base-validated-rule.cjs +16 -0
- package/dist/cjs/types/callout-component-schema.cjs +16 -0
- package/dist/cjs/types/callout-filter-name.cjs +16 -0
- package/dist/cjs/types/callout-form-schema.cjs +16 -0
- package/dist/cjs/types/callout-navigation-schema.cjs +16 -0
- package/dist/cjs/types/callout-response-answer-address.cjs +16 -0
- package/dist/cjs/types/callout-response-answer-file-upload.cjs +16 -0
- package/dist/cjs/types/callout-response-answer.cjs +16 -0
- package/dist/cjs/types/callout-response-answers.cjs +16 -0
- package/dist/cjs/types/callout-response-comment-filter-name.cjs +16 -0
- package/dist/cjs/types/callout-response-filter-name.cjs +16 -0
- package/dist/cjs/types/callout-slide-schema.cjs +16 -0
- package/dist/cjs/types/callout-tag-filter-name.cjs +16 -0
- package/dist/cjs/types/content-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/date-unit.cjs +16 -0
- package/dist/cjs/types/duration.cjs +16 -0
- package/dist/cjs/types/enum-filter-args.cjs +16 -0
- package/dist/cjs/types/feeable.cjs +16 -0
- package/dist/cjs/types/filter-args.cjs +16 -0
- package/dist/cjs/types/filter-type.cjs +16 -0
- package/dist/cjs/types/filters.cjs +16 -0
- package/dist/cjs/types/index.cjs +120 -0
- package/dist/cjs/types/input-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/input-file-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/nestable-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/notice-filter-name.cjs +16 -0
- package/dist/cjs/types/operators-by-type.cjs +16 -0
- package/dist/cjs/types/other-filter-args.cjs +16 -0
- package/dist/cjs/types/paginated-query.cjs +16 -0
- package/dist/cjs/types/paginated.cjs +16 -0
- package/dist/cjs/types/payment-filter-name.cjs +16 -0
- package/dist/cjs/types/radio-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/role-type.cjs +16 -0
- package/dist/cjs/types/rule-group.cjs +16 -0
- package/dist/cjs/types/rule-operator.cjs +16 -0
- package/dist/cjs/types/rule-opperator-params.cjs +16 -0
- package/dist/cjs/types/rule-value.cjs +16 -0
- package/dist/cjs/types/rule.cjs +16 -0
- package/dist/cjs/types/select-callout-component-schema.cjs +16 -0
- package/dist/cjs/types/stripe-fee-country.cjs +16 -0
- package/dist/cjs/types/unit-matches.cjs +16 -0
- package/dist/cjs/types/validated-boolean-rule.cjs +16 -0
- package/dist/cjs/types/validated-number-rule.cjs +16 -0
- package/dist/cjs/types/validated-rule-group.cjs +16 -0
- package/dist/cjs/types/validated-rule-value.cjs +16 -0
- package/dist/cjs/types/validated-rule.cjs +16 -0
- package/dist/cjs/types/validated-string-rule.cjs +16 -0
- package/dist/cjs/utils/callouts.cjs +137 -0
- package/dist/cjs/utils/date.cjs +87 -0
- package/dist/cjs/utils/index.cjs +28 -0
- package/dist/cjs/utils/payments.cjs +53 -0
- package/dist/cjs/utils/rules.cjs +109 -0
- package/dist/esm/data/index.js +57 -50
- package/dist/esm/error/InvalidRule.js +10 -7
- package/dist/esm/error/index.js +1 -2
- package/dist/esm/index.js +4 -7
- package/dist/esm/search/api-keys.js +10 -7
- package/dist/esm/search/callouts.js +100 -94
- package/dist/esm/search/contacts.js +83 -74
- package/dist/esm/search/index.js +6 -64
- package/dist/esm/search/notices.js +36 -33
- package/dist/esm/search/operators.js +62 -0
- package/dist/esm/search/payments.js +26 -23
- package/dist/esm/types/api-key-filter-name.js +0 -0
- package/dist/esm/types/array-filter-args.js +0 -0
- package/dist/esm/types/base-callout-component-schema.js +0 -0
- package/dist/esm/types/base-filter-args.js +0 -0
- package/dist/esm/types/base-validated-rule.js +0 -0
- package/dist/esm/types/callout-component-schema.js +0 -0
- package/dist/esm/types/callout-filter-name.js +0 -0
- package/dist/esm/types/callout-form-schema.js +0 -0
- package/dist/esm/types/callout-navigation-schema.js +0 -0
- package/dist/esm/types/callout-response-answer-address.js +0 -0
- package/dist/esm/types/callout-response-answer-file-upload.js +0 -0
- package/dist/esm/types/callout-response-answer.js +0 -0
- package/dist/esm/types/callout-response-answers.js +0 -0
- package/dist/esm/types/callout-response-comment-filter-name.js +0 -0
- package/dist/esm/types/callout-response-filter-name.js +0 -0
- package/dist/esm/types/callout-slide-schema.js +0 -0
- package/dist/esm/types/callout-tag-filter-name.js +0 -0
- package/dist/esm/types/content-callout-component-schema.js +0 -0
- package/dist/esm/types/date-unit.js +0 -0
- package/dist/esm/types/duration.js +0 -0
- package/dist/esm/types/enum-filter-args.js +0 -0
- package/dist/esm/types/feeable.js +0 -0
- package/dist/esm/types/filter-args.js +0 -0
- package/dist/esm/types/filter-type.js +0 -0
- package/dist/esm/types/filters.js +0 -0
- package/dist/esm/types/index.js +50 -0
- package/dist/esm/types/input-callout-component-schema.js +0 -0
- package/dist/esm/types/input-file-callout-component-schema.js +0 -0
- package/dist/esm/types/nestable-callout-component-schema.js +0 -0
- package/dist/esm/types/notice-filter-name.js +0 -0
- package/dist/esm/types/operators-by-type.js +0 -0
- package/dist/esm/types/other-filter-args.js +0 -0
- package/dist/esm/types/paginated-query.js +0 -0
- package/dist/esm/types/paginated.js +0 -0
- package/dist/esm/types/payment-filter-name.js +0 -0
- package/dist/esm/types/radio-callout-component-schema.js +0 -0
- package/dist/esm/types/role-type.js +0 -0
- package/dist/esm/types/rule-group.js +0 -0
- package/dist/esm/types/rule-operator.js +0 -0
- package/dist/esm/types/rule-opperator-params.js +0 -0
- package/dist/esm/types/rule-value.js +0 -0
- package/dist/esm/types/rule.js +0 -0
- package/dist/esm/types/select-callout-component-schema.js +0 -0
- package/dist/esm/types/stripe-fee-country.js +0 -0
- package/dist/esm/types/unit-matches.js +0 -0
- package/dist/esm/types/validated-boolean-rule.js +0 -0
- package/dist/esm/types/validated-number-rule.js +0 -0
- package/dist/esm/types/validated-rule-group.js +0 -0
- package/dist/esm/types/validated-rule-value.js +0 -0
- package/dist/esm/types/validated-rule.js +0 -0
- package/dist/esm/types/validated-string-rule.js +0 -0
- package/dist/esm/utils/callouts.js +91 -93
- package/dist/esm/utils/date.js +56 -56
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/payments.js +25 -23
- package/dist/esm/utils/rules.js +75 -58
- package/dist/types/data/index.d.ts +0 -4
- package/dist/types/error/InvalidRule.d.ts +2 -2
- package/dist/types/error/index.d.ts +1 -2
- package/dist/types/index.d.ts +5 -7
- package/dist/types/search/api-keys.d.ts +0 -1
- package/dist/types/search/callouts.d.ts +1 -5
- package/dist/types/search/contacts.d.ts +2 -1
- package/dist/types/search/index.d.ts +6 -194
- package/dist/types/search/notices.d.ts +1 -2
- package/dist/types/search/operators.d.ts +128 -0
- package/dist/types/search/payments.d.ts +1 -2
- package/dist/types/types/api-key-filter-name.d.ts +2 -0
- package/dist/types/types/array-filter-args.d.ts +5 -0
- package/dist/types/types/base-callout-component-schema.d.ts +9 -0
- package/dist/types/types/base-filter-args.d.ts +5 -0
- package/dist/types/types/base-validated-rule.d.ts +9 -0
- package/dist/types/types/callout-component-schema.d.ts +2 -0
- package/dist/types/types/callout-filter-name.d.ts +2 -0
- package/dist/types/types/callout-form-schema.d.ts +4 -0
- package/dist/types/types/callout-navigation-schema.d.ts +6 -0
- package/dist/types/types/callout-response-answer-address.d.ts +9 -0
- package/dist/types/types/callout-response-answer-file-upload.d.ts +3 -0
- package/dist/types/types/callout-response-answer.d.ts +2 -0
- package/dist/types/types/callout-response-answers.d.ts +5 -0
- package/dist/types/types/callout-response-comment-filter-name.d.ts +2 -0
- package/dist/types/types/callout-response-filter-name.d.ts +2 -0
- package/dist/types/types/callout-slide-schema.d.ts +7 -0
- package/dist/types/types/callout-tag-filter-name.d.ts +2 -0
- package/dist/types/types/content-callout-component-schema.d.ts +5 -0
- package/dist/types/types/date-unit.d.ts +2 -0
- package/dist/types/types/duration.d.ts +1 -0
- package/dist/types/types/enum-filter-args.d.ts +5 -0
- package/dist/types/types/feeable.d.ts +6 -0
- package/dist/types/types/filter-args.d.ts +2 -0
- package/dist/types/types/filter-type.d.ts +1 -0
- package/dist/types/types/filters.d.ts +2 -0
- package/dist/types/types/index.d.ts +50 -0
- package/dist/types/types/input-callout-component-schema.d.ts +6 -0
- package/dist/types/types/input-file-callout-component-schema.d.ts +5 -0
- package/dist/types/types/nestable-callout-component-schema.d.ts +6 -0
- package/dist/types/types/notice-filter-name.d.ts +2 -0
- package/dist/types/types/operators-by-type.d.ts +2 -0
- package/dist/types/types/other-filter-args.d.ts +4 -0
- package/dist/types/types/paginated-query.d.ts +8 -0
- package/dist/types/types/paginated.d.ts +6 -0
- package/dist/types/types/payment-filter-name.d.ts +2 -0
- package/dist/types/types/radio-callout-component-schema.d.ts +10 -0
- package/dist/types/types/role-type.d.ts +2 -0
- package/dist/types/types/rule-group.d.ts +5 -0
- package/dist/types/types/rule-operator.d.ts +2 -0
- package/dist/types/types/rule-opperator-params.d.ts +3 -0
- package/dist/types/types/rule-value.d.ts +1 -0
- package/dist/types/types/rule.d.ts +6 -0
- package/dist/types/types/select-callout-component-schema.d.ts +11 -0
- package/dist/types/types/stripe-fee-country.d.ts +1 -0
- package/dist/types/types/unit-matches.d.ts +2 -0
- package/dist/types/types/validated-boolean-rule.d.ts +2 -0
- package/dist/types/types/validated-number-rule.d.ts +2 -0
- package/dist/types/types/validated-rule-group.d.ts +5 -0
- package/dist/types/types/validated-rule-value.d.ts +2 -0
- package/dist/types/types/validated-rule.d.ts +2 -0
- package/dist/types/types/validated-string-rule.d.ts +2 -0
- package/dist/types/utils/callouts.d.ts +1 -3
- package/dist/types/utils/date.d.ts +3 -3
- package/dist/types/utils/index.d.ts +4 -0
- package/dist/types/utils/payments.d.ts +1 -7
- package/dist/types/utils/rules.d.ts +1 -1
- package/package.json +31 -12
- package/dist/cjs/data/callouts.js +0 -2
- package/dist/cjs/data/index.js +0 -67
- package/dist/cjs/error/InvalidRule.js +0 -11
- package/dist/cjs/error/index.js +0 -8
- package/dist/cjs/index.js +0 -23
- package/dist/cjs/search/api-keys.js +0 -11
- package/dist/cjs/search/callouts.js +0 -101
- package/dist/cjs/search/contacts.js +0 -78
- package/dist/cjs/search/index.js +0 -81
- package/dist/cjs/search/notices.js +0 -37
- package/dist/cjs/search/payments.js +0 -27
- package/dist/cjs/utils/callouts.js +0 -118
- package/dist/cjs/utils/date.js +0 -77
- package/dist/cjs/utils/payments.js +0 -31
- package/dist/cjs/utils/rules.js +0 -69
- package/dist/esm/data/callouts.js +0 -1
- package/dist/types/data/callouts.d.ts +0 -70
|
@@ -1,108 +1,106 @@
|
|
|
1
1
|
function isNestableComponent(component) {
|
|
2
|
-
|
|
3
|
-
return "components" in component && component.type !== "address";
|
|
2
|
+
return "components" in component && component.type !== "address";
|
|
4
3
|
}
|
|
5
4
|
function convertValuesToOptions(values) {
|
|
6
|
-
|
|
5
|
+
return values.map(({ value }) => value);
|
|
7
6
|
}
|
|
8
7
|
function convertComponentToFilter(component) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
const baseItem = {
|
|
9
|
+
label: component.label || component.fullKey,
|
|
10
|
+
nullable: true
|
|
11
|
+
};
|
|
12
|
+
switch (component.type) {
|
|
13
|
+
case "checkbox":
|
|
14
|
+
return { ...baseItem, type: "boolean", nullable: false };
|
|
15
|
+
case "number":
|
|
16
|
+
return { ...baseItem, type: "number" };
|
|
17
|
+
case "select":
|
|
18
|
+
return {
|
|
19
|
+
...baseItem,
|
|
20
|
+
type: "enum",
|
|
21
|
+
options: convertValuesToOptions(component.data.values)
|
|
22
|
+
};
|
|
23
|
+
case "selectboxes":
|
|
24
|
+
case "radio":
|
|
25
|
+
return {
|
|
26
|
+
...baseItem,
|
|
27
|
+
type: component.type === "radio" ? "enum" : "array",
|
|
28
|
+
options: convertValuesToOptions(component.values)
|
|
29
|
+
};
|
|
30
|
+
case "textarea":
|
|
31
|
+
return { ...baseItem, type: "blob" };
|
|
32
|
+
default:
|
|
33
|
+
return { ...baseItem, type: "text" };
|
|
34
|
+
}
|
|
36
35
|
}
|
|
37
36
|
function getNiceAnswer(component, value) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
switch (component.type) {
|
|
38
|
+
case "radio":
|
|
39
|
+
case "selectboxes":
|
|
40
|
+
return component.values.find((v) => v.value === value)?.label || value;
|
|
41
|
+
case "select":
|
|
42
|
+
return component.data.values.find((v) => v.value === value)?.label || value;
|
|
43
|
+
default:
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
function flattenComponents(components) {
|
|
48
|
+
return components.flatMap(
|
|
49
|
+
(component) => isNestableComponent(component) ? [component, ...flattenComponents(component.components)] : [component]
|
|
50
|
+
);
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
function filterComponents(components, filterFn) {
|
|
53
|
+
return components.filter(filterFn).map((component) => {
|
|
54
|
+
return {
|
|
55
|
+
...component,
|
|
56
|
+
...isNestableComponent(component) && {
|
|
57
|
+
components: filterComponents(component.components, filterFn)
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
});
|
|
62
61
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
function getCalloutComponents(formSchema) {
|
|
63
|
+
return formSchema.slides.flatMap(
|
|
64
|
+
(slide) => flattenComponents(slide.components).map((component) => ({
|
|
65
|
+
...component,
|
|
66
|
+
slideId: slide.id,
|
|
67
|
+
fullKey: `${slide.id}.${component.key}`
|
|
68
|
+
}))
|
|
69
|
+
);
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
.map((c) => [`answers.${c.fullKey}`, convertComponentToFilter(c)]);
|
|
74
|
-
return Object.fromEntries(items);
|
|
71
|
+
function getCalloutFilters(formSchema) {
|
|
72
|
+
const items = getCalloutComponents(formSchema).filter((c) => c.input).map((c) => [`answers.${c.fullKey}`, convertComponentToFilter(c)]);
|
|
73
|
+
return Object.fromEntries(items);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
function isAddressAnswer(answer) {
|
|
76
|
+
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
function isFileUploadAnswer(answer) {
|
|
79
|
+
return !!answer && typeof answer === "object" && "url" in answer;
|
|
81
80
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
.filter(([, selected]) => selected)
|
|
99
|
-
.map(([value]) => getNiceAnswer(component, value))
|
|
100
|
-
.join(", ");
|
|
101
|
-
}
|
|
102
|
-
else if (typeof answer === "string") {
|
|
103
|
-
return getNiceAnswer(component, answer);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return answer.toString();
|
|
107
|
-
}
|
|
81
|
+
function stringifyAnswer(component, answer) {
|
|
82
|
+
if (Array.isArray(answer)) {
|
|
83
|
+
return answer.map((a) => stringifyAnswer(component, a)).join(", ");
|
|
84
|
+
} else if (!answer) {
|
|
85
|
+
return "";
|
|
86
|
+
} else if (isAddressAnswer(answer)) {
|
|
87
|
+
return answer.geometry.location.lat + ", " + answer.geometry.location.lng;
|
|
88
|
+
} else if (isFileUploadAnswer(answer)) {
|
|
89
|
+
return answer.url;
|
|
90
|
+
} else if (typeof answer === "object") {
|
|
91
|
+
return Object.entries(answer).filter(([, selected]) => selected).map(([value]) => getNiceAnswer(component, value)).join(", ");
|
|
92
|
+
} else if (typeof answer === "string") {
|
|
93
|
+
return getNiceAnswer(component, answer);
|
|
94
|
+
} else {
|
|
95
|
+
return answer.toString();
|
|
96
|
+
}
|
|
108
97
|
}
|
|
98
|
+
export {
|
|
99
|
+
filterComponents,
|
|
100
|
+
flattenComponents,
|
|
101
|
+
getCalloutComponents,
|
|
102
|
+
getCalloutFilters,
|
|
103
|
+
isAddressAnswer,
|
|
104
|
+
isFileUploadAnswer,
|
|
105
|
+
stringifyAnswer
|
|
106
|
+
};
|
package/dist/esm/utils/date.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
add,
|
|
3
|
+
isValid,
|
|
4
|
+
parseISO,
|
|
5
|
+
startOfDay,
|
|
6
|
+
startOfHour,
|
|
7
|
+
startOfMinute,
|
|
8
|
+
startOfMonth,
|
|
9
|
+
startOfSecond,
|
|
10
|
+
startOfYear
|
|
11
|
+
} from "date-fns";
|
|
11
12
|
const dateUnits = ["s", "m", "h", "d", "M", "y"];
|
|
12
13
|
const dateUnitMap = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
y: "years",
|
|
15
|
+
M: "months",
|
|
16
|
+
d: "days",
|
|
17
|
+
h: "hours",
|
|
18
|
+
m: "minutes",
|
|
19
|
+
s: "seconds"
|
|
19
20
|
};
|
|
20
21
|
const startOf = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
y: startOfYear,
|
|
23
|
+
M: startOfMonth,
|
|
24
|
+
d: startOfDay,
|
|
25
|
+
h: startOfHour,
|
|
26
|
+
m: startOfMinute,
|
|
27
|
+
s: startOfSecond
|
|
27
28
|
};
|
|
28
29
|
const relativeDate = /^\$now(?<units>\(((y|M|d|h|m|s):(-?\d+),?)+\))?$/;
|
|
29
30
|
const relativeUnit = /(y|M|d|h|m|s):(-?\d+)/g;
|
|
30
|
-
// Matches the different parts of an ISO 8601 date. Note we don't validate the
|
|
31
|
-
// pattern properly as that is handled by parseISO, we just want to know which
|
|
32
|
-
// parts of the date were specified
|
|
33
31
|
const absoluteDate = /^(?<y>\d{4,})(-(?<M>\d\d)(-(?<d>\d\d)([T ](?<h>\d\d)(:(?<m>\d\d)(:(?<s>\d\d))?)?)?)?)?/;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
else {
|
|
51
|
-
units = ["d"];
|
|
52
|
-
}
|
|
32
|
+
function parseDate(value, now) {
|
|
33
|
+
let date;
|
|
34
|
+
let units;
|
|
35
|
+
const relativeMatch = relativeDate.exec(value);
|
|
36
|
+
if (relativeMatch) {
|
|
37
|
+
date = now || /* @__PURE__ */ new Date();
|
|
38
|
+
const unitsGroup = relativeMatch.groups?.units;
|
|
39
|
+
if (unitsGroup) {
|
|
40
|
+
const unitMatches = unitsGroup.matchAll(relativeUnit);
|
|
41
|
+
units = [];
|
|
42
|
+
for (const [_, unit, delta] of unitMatches) {
|
|
43
|
+
date = add(date, { [dateUnitMap[unit]]: Number(delta) });
|
|
44
|
+
units.push(unit);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
units = ["d"];
|
|
53
48
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const minUnit = getMinDateUnit(units) || "s";
|
|
61
|
-
return [startOf[minUnit](date), minUnit];
|
|
49
|
+
} else {
|
|
50
|
+
date = parseISO(value);
|
|
51
|
+
units = Object.entries(absoluteDate.exec(value)?.groups || {}).filter(([_, n]) => !!n).map(([unit]) => unit);
|
|
52
|
+
}
|
|
53
|
+
const minUnit = getMinDateUnit(units) || "s";
|
|
54
|
+
return [startOf[minUnit](date), minUnit];
|
|
62
55
|
}
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
function getMinDateUnit(units) {
|
|
57
|
+
return dateUnits.find((unit) => units.includes(unit));
|
|
65
58
|
}
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
function isValidDate(s) {
|
|
60
|
+
return relativeDate.test(s) || isValid(parseISO(s));
|
|
68
61
|
}
|
|
62
|
+
export {
|
|
63
|
+
dateUnitMap,
|
|
64
|
+
dateUnits,
|
|
65
|
+
getMinDateUnit,
|
|
66
|
+
isValidDate,
|
|
67
|
+
parseDate
|
|
68
|
+
};
|
|
@@ -1,27 +1,29 @@
|
|
|
1
|
-
import { ContributionPeriod, PaymentMethod } from "../data";
|
|
1
|
+
import { ContributionPeriod, PaymentMethod } from "../data/index.js";
|
|
2
2
|
const stripeFees = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
gb: {
|
|
4
|
+
[PaymentMethod.StripeCard]: (amount) => 0.2 + 0.015 * amount,
|
|
5
|
+
[PaymentMethod.StripeSEPA]: () => 0.3,
|
|
6
|
+
[PaymentMethod.StripeBACS]: (amount) => Math.min(2, Math.max(0.2, 0.01 * amount))
|
|
7
|
+
},
|
|
8
|
+
eu: {
|
|
9
|
+
[PaymentMethod.StripeCard]: (amount) => 0.25 + 0.015 * amount,
|
|
10
|
+
[PaymentMethod.StripeSEPA]: () => 0.35,
|
|
11
|
+
[PaymentMethod.StripeBACS]: () => 0
|
|
12
|
+
// Not available
|
|
13
|
+
},
|
|
14
|
+
ca: {
|
|
15
|
+
[PaymentMethod.StripeCard]: (amount) => 0.3 + 0.029 * amount,
|
|
16
|
+
[PaymentMethod.StripeSEPA]: () => 0,
|
|
17
|
+
// Not available
|
|
18
|
+
[PaymentMethod.StripeBACS]: () => 0
|
|
19
|
+
// Not available
|
|
20
|
+
}
|
|
18
21
|
};
|
|
19
22
|
const gcFee = (amount) => 0.2 + amount * 0.01;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
: stripeFees[country][feeable.paymentMethod];
|
|
24
|
-
return feeable.period === ContributionPeriod.Annually
|
|
25
|
-
? 0
|
|
26
|
-
: feeFn(feeable.amount);
|
|
23
|
+
function calcPaymentFee(feeable, country) {
|
|
24
|
+
const feeFn = feeable.paymentMethod === PaymentMethod.GoCardlessDirectDebit ? gcFee : stripeFees[country][feeable.paymentMethod];
|
|
25
|
+
return feeable.period === ContributionPeriod.Annually ? 0 : feeFn(feeable.amount);
|
|
27
26
|
}
|
|
27
|
+
export {
|
|
28
|
+
calcPaymentFee
|
|
29
|
+
};
|
package/dist/esm/utils/rules.js
CHANGED
|
@@ -1,63 +1,80 @@
|
|
|
1
|
-
import { InvalidRule } from "../error";
|
|
2
|
-
import { nullableOperators, operatorsByTypeMap
|
|
3
|
-
import { isValidDate } from "./date";
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { InvalidRule } from "../error/index.js";
|
|
2
|
+
import { nullableOperators, operatorsByTypeMap } from "../search/index.js";
|
|
3
|
+
import { isValidDate } from "./date.js";
|
|
4
|
+
function isRuleGroup(ruleOrGroup) {
|
|
5
|
+
return "condition" in ruleOrGroup;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
function validateRule(filters, rule) {
|
|
8
|
+
const filter = filters[rule.field];
|
|
9
|
+
if (!filter) {
|
|
10
|
+
throw new InvalidRule(rule, `Invalid field: ${rule.field}`);
|
|
11
|
+
}
|
|
12
|
+
let expectedArgs = 0;
|
|
13
|
+
if (rule.operator in nullableOperators) {
|
|
14
|
+
if (!filter.nullable && filter.type !== "text") {
|
|
15
|
+
throw new InvalidRule(
|
|
16
|
+
rule,
|
|
17
|
+
`Invalid nullable operator: field is not nullable`
|
|
18
|
+
);
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
20
|
+
} else {
|
|
21
|
+
const operator = operatorsByTypeMap[filter.type][rule.operator];
|
|
22
|
+
if (!operator) {
|
|
23
|
+
throw new InvalidRule(
|
|
24
|
+
rule,
|
|
25
|
+
`Invalid operator for type: ${filter.type} type doesn't define ${rule.operator}`
|
|
26
|
+
);
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
expectedArgs = operator.args;
|
|
29
|
+
}
|
|
30
|
+
if (expectedArgs !== rule.value.length) {
|
|
31
|
+
throw new InvalidRule(
|
|
32
|
+
rule,
|
|
33
|
+
`Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const expectedType = filter.type === "boolean" || filter.type === "number" ? filter.type : "string";
|
|
37
|
+
if (rule.value.some((v) => typeof v !== expectedType)) {
|
|
38
|
+
throw new InvalidRule(
|
|
39
|
+
rule,
|
|
40
|
+
`Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map(
|
|
41
|
+
(v) => typeof v
|
|
42
|
+
)} given`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (filter.type === "date" && rule.value.some((v) => !isValidDate(v))) {
|
|
46
|
+
throw new InvalidRule(
|
|
47
|
+
rule,
|
|
48
|
+
`Invalid operator argument: date type needs valid absolute or relative date, ${rule.value} given`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if ((filter.type === "enum" || filter.type === "array") && rule.value.some((v) => filter.options?.indexOf(v) === -1)) {
|
|
52
|
+
throw new InvalidRule(
|
|
53
|
+
rule,
|
|
54
|
+
`Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
field: rule.field,
|
|
59
|
+
type: filter.type,
|
|
60
|
+
nullable: !!filter.nullable,
|
|
61
|
+
operator: rule.operator,
|
|
62
|
+
value: rule.value
|
|
63
|
+
};
|
|
50
64
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return validatedRuleGroup;
|
|
65
|
+
function validateRuleGroup(filters, ruleGroup) {
|
|
66
|
+
const validatedRuleGroup = {
|
|
67
|
+
condition: ruleGroup.condition,
|
|
68
|
+
rules: []
|
|
69
|
+
};
|
|
70
|
+
for (const rule of ruleGroup.rules) {
|
|
71
|
+
const valid = isRuleGroup(rule) ? validateRuleGroup(filters, rule) : validateRule(filters, rule);
|
|
72
|
+
validatedRuleGroup.rules.push(valid);
|
|
73
|
+
}
|
|
74
|
+
return validatedRuleGroup;
|
|
63
75
|
}
|
|
76
|
+
export {
|
|
77
|
+
isRuleGroup,
|
|
78
|
+
validateRule,
|
|
79
|
+
validateRuleGroup
|
|
80
|
+
};
|
|
@@ -39,7 +39,3 @@ export declare enum PaymentStatus {
|
|
|
39
39
|
Failed = "failed",
|
|
40
40
|
Cancelled = "cancelled"
|
|
41
41
|
}
|
|
42
|
-
export declare const RoleTypes: readonly ["member", "admin", "superadmin"];
|
|
43
|
-
export type RoleType = (typeof RoleTypes)[number];
|
|
44
|
-
export type StripeFeeCountry = "eu" | "gb" | "ca";
|
|
45
|
-
export * from "./callouts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Rule } from "../
|
|
2
|
-
export
|
|
1
|
+
import { Rule } from "../types/index.ts";
|
|
2
|
+
export declare class InvalidRule extends Error {
|
|
3
3
|
readonly rule: Rule;
|
|
4
4
|
readonly message: string;
|
|
5
5
|
constructor(rule: Rule, message: string);
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { InvalidRule };
|
|
1
|
+
export * from "./InvalidRule.ts";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./utils/
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./utils/payments";
|
|
7
|
-
export * from "./utils/rules";
|
|
1
|
+
export * from "./data/index.ts";
|
|
2
|
+
export * from "./error/index.ts";
|
|
3
|
+
export * from "./search/index.ts";
|
|
4
|
+
export * from "./utils/index.ts";
|
|
5
|
+
export type * from "./types/index.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ItemStatus } from "../data";
|
|
1
|
+
import { ItemStatus } from "../data/index.ts";
|
|
2
2
|
export declare const calloutFilters: {
|
|
3
3
|
readonly slug: {
|
|
4
4
|
readonly type: "text";
|
|
@@ -25,7 +25,6 @@ export declare const calloutFilters: {
|
|
|
25
25
|
readonly type: "boolean";
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
export type CalloutFilterName = keyof typeof calloutFilters;
|
|
29
28
|
export declare const calloutResponseFilters: {
|
|
30
29
|
readonly id: {
|
|
31
30
|
readonly type: "text";
|
|
@@ -58,7 +57,6 @@ export declare const calloutResponseFilters: {
|
|
|
58
57
|
readonly type: "blob";
|
|
59
58
|
};
|
|
60
59
|
};
|
|
61
|
-
export type CalloutResponseFilterName = keyof typeof calloutResponseFilters;
|
|
62
60
|
export declare const calloutResponseCommentFilters: {
|
|
63
61
|
readonly id: {
|
|
64
62
|
readonly type: "text";
|
|
@@ -79,7 +77,6 @@ export declare const calloutResponseCommentFilters: {
|
|
|
79
77
|
readonly type: "text";
|
|
80
78
|
};
|
|
81
79
|
};
|
|
82
|
-
export type CalloutResponseCommentFilterName = keyof typeof calloutResponseCommentFilters;
|
|
83
80
|
export declare const calloutTagFilters: {
|
|
84
81
|
readonly id: {
|
|
85
82
|
readonly type: "text";
|
|
@@ -94,4 +91,3 @@ export declare const calloutTagFilters: {
|
|
|
94
91
|
readonly type: "text";
|
|
95
92
|
};
|
|
96
93
|
};
|
|
97
|
-
export type CalloutTagFilterName = keyof typeof calloutTagFilters;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ContributionPeriod, ContributionType, NewsletterStatus } from "../data";
|
|
1
|
+
import { ContributionPeriod, ContributionType, NewsletterStatus } from "../data/index.ts";
|
|
2
|
+
export declare const RoleTypes: readonly ["member", "admin", "superadmin"];
|
|
2
3
|
export declare const contactFilters: {
|
|
3
4
|
readonly id: {
|
|
4
5
|
readonly type: "contact";
|