@beabee/beabee-common 1.19.7 → 1.19.8
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/cjs/data/callouts.js +2 -0
- package/dist/cjs/data/index.js +67 -0
- package/dist/cjs/error/InvalidRule.js +11 -0
- package/dist/cjs/error/index.js +8 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/search/api-keys.js +11 -0
- package/dist/cjs/search/callouts.js +101 -0
- package/dist/cjs/search/contacts.js +78 -0
- package/dist/cjs/search/index.js +81 -0
- package/dist/cjs/search/notices.js +37 -0
- package/dist/cjs/search/payments.js +27 -0
- package/dist/cjs/utils/callouts.js +118 -0
- package/dist/cjs/utils/date.js +77 -0
- package/dist/cjs/utils/payments.js +31 -0
- package/dist/cjs/utils/rules.js +69 -0
- package/dist/esm/data/callouts.js +1 -0
- package/dist/esm/data/index.js +50 -57
- package/dist/esm/error/InvalidRule.js +7 -10
- package/dist/esm/error/index.js +2 -1
- package/dist/esm/index.js +7 -4
- package/dist/esm/search/api-keys.js +7 -10
- package/dist/esm/search/callouts.js +94 -100
- package/dist/esm/search/contacts.js +74 -83
- package/dist/esm/search/index.js +64 -6
- package/dist/esm/search/notices.js +33 -36
- package/dist/esm/search/payments.js +23 -26
- package/dist/esm/utils/callouts.js +93 -91
- package/dist/esm/utils/date.js +56 -56
- package/dist/esm/utils/payments.js +23 -25
- package/dist/esm/utils/rules.js +58 -75
- package/dist/types/data/callouts.d.ts +74 -0
- package/dist/types/data/index.d.ts +4 -0
- package/dist/types/error/InvalidRule.d.ts +2 -2
- package/dist/types/error/index.d.ts +2 -1
- package/dist/types/index.d.ts +7 -5
- package/dist/types/search/api-keys.d.ts +1 -0
- package/dist/types/search/callouts.d.ts +5 -1
- package/dist/types/search/contacts.d.ts +1 -2
- package/dist/types/search/index.d.ts +194 -6
- package/dist/types/search/notices.d.ts +2 -1
- package/dist/types/search/payments.d.ts +2 -1
- package/dist/types/utils/callouts.d.ts +3 -1
- package/dist/types/utils/date.d.ts +3 -3
- package/dist/types/utils/payments.d.ts +7 -1
- package/dist/types/utils/rules.d.ts +1 -1
- package/package.json +12 -31
- package/README.md +0 -41
- package/dist/cjs/data/index.cjs +0 -87
- package/dist/cjs/error/InvalidRule.cjs +0 -35
- package/dist/cjs/error/index.cjs +0 -22
- package/dist/cjs/index.cjs +0 -28
- package/dist/cjs/search/api-keys.cjs +0 -35
- package/dist/cjs/search/callouts.cjs +0 -131
- package/dist/cjs/search/contacts.cjs +0 -105
- package/dist/cjs/search/index.cjs +0 -32
- package/dist/cjs/search/notices.cjs +0 -61
- package/dist/cjs/search/operators.cjs +0 -89
- package/dist/cjs/search/payments.cjs +0 -51
- package/dist/cjs/types/api-key-filter-name.cjs +0 -16
- package/dist/cjs/types/array-filter-args.cjs +0 -16
- package/dist/cjs/types/base-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/base-filter-args.cjs +0 -16
- package/dist/cjs/types/base-validated-rule.cjs +0 -16
- package/dist/cjs/types/callout-component-schema.cjs +0 -16
- package/dist/cjs/types/callout-filter-name.cjs +0 -16
- package/dist/cjs/types/callout-form-schema.cjs +0 -16
- package/dist/cjs/types/callout-navigation-schema.cjs +0 -16
- package/dist/cjs/types/callout-response-answer-address.cjs +0 -16
- package/dist/cjs/types/callout-response-answer-file-upload.cjs +0 -16
- package/dist/cjs/types/callout-response-answer.cjs +0 -16
- package/dist/cjs/types/callout-response-answers.cjs +0 -16
- package/dist/cjs/types/callout-response-comment-filter-name.cjs +0 -16
- package/dist/cjs/types/callout-response-filter-name.cjs +0 -16
- package/dist/cjs/types/callout-slide-schema.cjs +0 -16
- package/dist/cjs/types/callout-tag-filter-name.cjs +0 -16
- package/dist/cjs/types/content-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/date-unit.cjs +0 -16
- package/dist/cjs/types/duration.cjs +0 -16
- package/dist/cjs/types/enum-filter-args.cjs +0 -16
- package/dist/cjs/types/feeable.cjs +0 -16
- package/dist/cjs/types/filter-args.cjs +0 -16
- package/dist/cjs/types/filter-type.cjs +0 -16
- package/dist/cjs/types/filters.cjs +0 -16
- package/dist/cjs/types/index.cjs +0 -120
- package/dist/cjs/types/input-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/input-file-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/nestable-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/notice-filter-name.cjs +0 -16
- package/dist/cjs/types/operators-by-type.cjs +0 -16
- package/dist/cjs/types/other-filter-args.cjs +0 -16
- package/dist/cjs/types/paginated-query.cjs +0 -16
- package/dist/cjs/types/paginated.cjs +0 -16
- package/dist/cjs/types/payment-filter-name.cjs +0 -16
- package/dist/cjs/types/radio-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/role-type.cjs +0 -16
- package/dist/cjs/types/rule-group.cjs +0 -16
- package/dist/cjs/types/rule-operator.cjs +0 -16
- package/dist/cjs/types/rule-opperator-params.cjs +0 -16
- package/dist/cjs/types/rule-value.cjs +0 -16
- package/dist/cjs/types/rule.cjs +0 -16
- package/dist/cjs/types/select-callout-component-schema.cjs +0 -16
- package/dist/cjs/types/stripe-fee-country.cjs +0 -16
- package/dist/cjs/types/unit-matches.cjs +0 -16
- package/dist/cjs/types/validated-boolean-rule.cjs +0 -16
- package/dist/cjs/types/validated-number-rule.cjs +0 -16
- package/dist/cjs/types/validated-rule-group.cjs +0 -16
- package/dist/cjs/types/validated-rule-value.cjs +0 -16
- package/dist/cjs/types/validated-rule.cjs +0 -16
- package/dist/cjs/types/validated-string-rule.cjs +0 -16
- package/dist/cjs/utils/callouts.cjs +0 -137
- package/dist/cjs/utils/date.cjs +0 -87
- package/dist/cjs/utils/index.cjs +0 -28
- package/dist/cjs/utils/payments.cjs +0 -53
- package/dist/cjs/utils/rules.cjs +0 -109
- package/dist/esm/search/operators.js +0 -62
- 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 +0 -50
- 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/index.js +0 -4
- package/dist/types/search/operators.d.ts +0 -128
- package/dist/types/types/api-key-filter-name.d.ts +0 -2
- package/dist/types/types/array-filter-args.d.ts +0 -5
- package/dist/types/types/base-callout-component-schema.d.ts +0 -9
- package/dist/types/types/base-filter-args.d.ts +0 -5
- package/dist/types/types/base-validated-rule.d.ts +0 -9
- package/dist/types/types/callout-component-schema.d.ts +0 -2
- package/dist/types/types/callout-filter-name.d.ts +0 -2
- package/dist/types/types/callout-form-schema.d.ts +0 -4
- package/dist/types/types/callout-navigation-schema.d.ts +0 -6
- package/dist/types/types/callout-response-answer-address.d.ts +0 -9
- package/dist/types/types/callout-response-answer-file-upload.d.ts +0 -3
- package/dist/types/types/callout-response-answer.d.ts +0 -2
- package/dist/types/types/callout-response-answers.d.ts +0 -5
- package/dist/types/types/callout-response-comment-filter-name.d.ts +0 -2
- package/dist/types/types/callout-response-filter-name.d.ts +0 -2
- package/dist/types/types/callout-slide-schema.d.ts +0 -7
- package/dist/types/types/callout-tag-filter-name.d.ts +0 -2
- package/dist/types/types/content-callout-component-schema.d.ts +0 -5
- package/dist/types/types/date-unit.d.ts +0 -2
- package/dist/types/types/duration.d.ts +0 -1
- package/dist/types/types/enum-filter-args.d.ts +0 -5
- package/dist/types/types/feeable.d.ts +0 -6
- package/dist/types/types/filter-args.d.ts +0 -2
- package/dist/types/types/filter-type.d.ts +0 -1
- package/dist/types/types/filters.d.ts +0 -2
- package/dist/types/types/index.d.ts +0 -50
- package/dist/types/types/input-callout-component-schema.d.ts +0 -6
- package/dist/types/types/input-file-callout-component-schema.d.ts +0 -5
- package/dist/types/types/nestable-callout-component-schema.d.ts +0 -6
- package/dist/types/types/notice-filter-name.d.ts +0 -2
- package/dist/types/types/operators-by-type.d.ts +0 -2
- package/dist/types/types/other-filter-args.d.ts +0 -4
- package/dist/types/types/paginated-query.d.ts +0 -8
- package/dist/types/types/paginated.d.ts +0 -6
- package/dist/types/types/payment-filter-name.d.ts +0 -2
- package/dist/types/types/radio-callout-component-schema.d.ts +0 -10
- package/dist/types/types/role-type.d.ts +0 -2
- package/dist/types/types/rule-group.d.ts +0 -5
- package/dist/types/types/rule-operator.d.ts +0 -2
- package/dist/types/types/rule-opperator-params.d.ts +0 -3
- package/dist/types/types/rule-value.d.ts +0 -1
- package/dist/types/types/rule.d.ts +0 -6
- package/dist/types/types/select-callout-component-schema.d.ts +0 -11
- package/dist/types/types/stripe-fee-country.d.ts +0 -1
- package/dist/types/types/unit-matches.d.ts +0 -2
- package/dist/types/types/validated-boolean-rule.d.ts +0 -2
- package/dist/types/types/validated-number-rule.d.ts +0 -2
- package/dist/types/types/validated-rule-group.d.ts +0 -5
- package/dist/types/types/validated-rule-value.d.ts +0 -2
- package/dist/types/types/validated-rule.d.ts +0 -2
- package/dist/types/types/validated-string-rule.d.ts +0 -2
- package/dist/types/utils/index.d.ts +0 -4
|
@@ -1,37 +1,34 @@
|
|
|
1
|
-
import { ItemStatus } from "../data
|
|
2
|
-
const noticeFilters = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
export {
|
|
36
|
-
noticeFilters
|
|
1
|
+
import { ItemStatus } from "../data";
|
|
2
|
+
export const noticeFilters = {
|
|
3
|
+
id: {
|
|
4
|
+
type: "text",
|
|
5
|
+
},
|
|
6
|
+
createdAt: {
|
|
7
|
+
type: "date",
|
|
8
|
+
},
|
|
9
|
+
updatedAt: {
|
|
10
|
+
type: "date",
|
|
11
|
+
},
|
|
12
|
+
name: {
|
|
13
|
+
type: "text",
|
|
14
|
+
},
|
|
15
|
+
expires: {
|
|
16
|
+
type: "date",
|
|
17
|
+
nullable: true,
|
|
18
|
+
},
|
|
19
|
+
enabled: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
},
|
|
22
|
+
text: {
|
|
23
|
+
type: "text",
|
|
24
|
+
},
|
|
25
|
+
status: {
|
|
26
|
+
type: "enum",
|
|
27
|
+
options: [
|
|
28
|
+
ItemStatus.Draft,
|
|
29
|
+
ItemStatus.Scheduled,
|
|
30
|
+
ItemStatus.Open,
|
|
31
|
+
ItemStatus.Ended,
|
|
32
|
+
],
|
|
33
|
+
},
|
|
37
34
|
};
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import { PaymentStatus } from "../data
|
|
2
|
-
const paymentFilters = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
export {
|
|
26
|
-
paymentFilters
|
|
1
|
+
import { PaymentStatus } from "../data";
|
|
2
|
+
export const paymentFilters = {
|
|
3
|
+
id: {
|
|
4
|
+
type: "text",
|
|
5
|
+
},
|
|
6
|
+
contact: {
|
|
7
|
+
type: "contact",
|
|
8
|
+
},
|
|
9
|
+
chargeDate: {
|
|
10
|
+
type: "date",
|
|
11
|
+
},
|
|
12
|
+
amount: {
|
|
13
|
+
type: "number",
|
|
14
|
+
},
|
|
15
|
+
status: {
|
|
16
|
+
type: "enum",
|
|
17
|
+
options: [
|
|
18
|
+
PaymentStatus.Successful,
|
|
19
|
+
PaymentStatus.Pending,
|
|
20
|
+
PaymentStatus.Failed,
|
|
21
|
+
PaymentStatus.Cancelled,
|
|
22
|
+
],
|
|
23
|
+
},
|
|
27
24
|
};
|
|
@@ -1,106 +1,108 @@
|
|
|
1
1
|
function isNestableComponent(component) {
|
|
2
|
-
|
|
2
|
+
// Addresses have embedded components we don't want to include
|
|
3
|
+
return "components" in component && component.type !== "address";
|
|
3
4
|
}
|
|
4
5
|
function convertValuesToOptions(values) {
|
|
5
|
-
|
|
6
|
+
return values.map(({ value, label }) => value);
|
|
6
7
|
}
|
|
7
8
|
function convertComponentToFilter(component) {
|
|
8
|
-
|
|
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
|
-
|
|
9
|
+
const baseItem = {
|
|
10
|
+
label: component.label || component.fullKey,
|
|
11
|
+
nullable: true,
|
|
12
|
+
};
|
|
13
|
+
switch (component.type) {
|
|
14
|
+
case "checkbox":
|
|
15
|
+
return { ...baseItem, type: "boolean", nullable: false };
|
|
16
|
+
case "number":
|
|
17
|
+
return { ...baseItem, type: "number" };
|
|
18
|
+
case "select":
|
|
19
|
+
return {
|
|
20
|
+
...baseItem,
|
|
21
|
+
type: "enum",
|
|
22
|
+
options: convertValuesToOptions(component.data.values),
|
|
23
|
+
};
|
|
24
|
+
case "selectboxes":
|
|
25
|
+
case "radio":
|
|
26
|
+
return {
|
|
27
|
+
...baseItem,
|
|
28
|
+
type: component.type === "radio" ? "enum" : "array",
|
|
29
|
+
options: convertValuesToOptions(component.values),
|
|
30
|
+
};
|
|
31
|
+
case "textarea":
|
|
32
|
+
return { ...baseItem, type: "blob" };
|
|
33
|
+
default:
|
|
34
|
+
return { ...baseItem, type: "text" };
|
|
35
|
+
}
|
|
35
36
|
}
|
|
36
37
|
function getNiceAnswer(component, value) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
switch (component.type) {
|
|
39
|
+
case "radio":
|
|
40
|
+
case "selectboxes":
|
|
41
|
+
return component.values.find((v) => v.value === value)?.label || value;
|
|
42
|
+
case "select":
|
|
43
|
+
return (component.data.values.find((v) => v.value === value)?.label || value);
|
|
44
|
+
default:
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
46
47
|
}
|
|
47
|
-
function flattenComponents(components) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
export function flattenComponents(components) {
|
|
49
|
+
return components.flatMap((component) => isNestableComponent(component)
|
|
50
|
+
? [component, ...flattenComponents(component.components)]
|
|
51
|
+
: [component]);
|
|
51
52
|
}
|
|
52
|
-
function filterComponents(components, filterFn) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
export function filterComponents(components, filterFn) {
|
|
54
|
+
return components.filter(filterFn).map((component) => {
|
|
55
|
+
return {
|
|
56
|
+
...component,
|
|
57
|
+
...(isNestableComponent(component) && {
|
|
58
|
+
components: filterComponents(component.components, filterFn),
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
61
62
|
}
|
|
62
|
-
function getCalloutComponents(formSchema) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}))
|
|
69
|
-
);
|
|
63
|
+
export function getCalloutComponents(formSchema) {
|
|
64
|
+
return formSchema.slides.flatMap((slide) => flattenComponents(slide.components).map((component) => ({
|
|
65
|
+
...component,
|
|
66
|
+
slideId: slide.id,
|
|
67
|
+
fullKey: `${slide.id}.${component.key}`,
|
|
68
|
+
})));
|
|
70
69
|
}
|
|
71
|
-
function getCalloutFilters(formSchema) {
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
export function getCalloutFilters(formSchema) {
|
|
71
|
+
const items = getCalloutComponents(formSchema)
|
|
72
|
+
.filter((c) => c.input)
|
|
73
|
+
.map((c) => [`answers.${c.fullKey}`, convertComponentToFilter(c)]);
|
|
74
|
+
return Object.fromEntries(items);
|
|
74
75
|
}
|
|
75
|
-
function isAddressAnswer(answer) {
|
|
76
|
-
|
|
76
|
+
export function isAddressAnswer(answer) {
|
|
77
|
+
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
77
78
|
}
|
|
78
|
-
function isFileUploadAnswer(answer) {
|
|
79
|
-
|
|
79
|
+
export function isFileUploadAnswer(answer) {
|
|
80
|
+
return !!answer && typeof answer === "object" && "url" in answer;
|
|
80
81
|
}
|
|
81
|
-
function stringifyAnswer(component, answer) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
82
|
+
export function stringifyAnswer(component, answer) {
|
|
83
|
+
if (Array.isArray(answer)) {
|
|
84
|
+
return answer.map((a) => stringifyAnswer(component, a)).join(", ");
|
|
85
|
+
}
|
|
86
|
+
else if (!answer) {
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
else if (isAddressAnswer(answer)) {
|
|
90
|
+
return answer.geometry.location.lat + ", " + answer.geometry.location.lng;
|
|
91
|
+
}
|
|
92
|
+
else if (isFileUploadAnswer(answer)) {
|
|
93
|
+
return answer.url;
|
|
94
|
+
}
|
|
95
|
+
else if (typeof answer === "object") {
|
|
96
|
+
// Checkboxes
|
|
97
|
+
return Object.entries(answer)
|
|
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
|
+
}
|
|
97
108
|
}
|
|
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
|
-
|
|
11
|
-
} from "date-fns";
|
|
1
|
+
import add from "date-fns/add";
|
|
2
|
+
import isValid from "date-fns/isValid";
|
|
3
|
+
import parseISO from "date-fns/parseISO";
|
|
4
|
+
import startOfDay from "date-fns/startOfDay";
|
|
5
|
+
import startOfHour from "date-fns/startOfHour";
|
|
6
|
+
import startOfMinute from "date-fns/startOfMinute";
|
|
7
|
+
import startOfMonth from "date-fns/startOfMonth";
|
|
8
|
+
import startOfSecond from "date-fns/startOfSecond";
|
|
9
|
+
import startOfYear from "date-fns/startOfYear";
|
|
10
|
+
// Must be ordered from highest resolution to lowest (seconds to years)
|
|
12
11
|
const dateUnits = ["s", "m", "h", "d", "M", "y"];
|
|
13
12
|
const dateUnitMap = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
y: "years",
|
|
14
|
+
M: "months",
|
|
15
|
+
d: "days",
|
|
16
|
+
h: "hours",
|
|
17
|
+
m: "minutes",
|
|
18
|
+
s: "seconds",
|
|
20
19
|
};
|
|
21
20
|
const startOf = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
y: startOfYear,
|
|
22
|
+
M: startOfMonth,
|
|
23
|
+
d: startOfDay,
|
|
24
|
+
h: startOfHour,
|
|
25
|
+
m: startOfMinute,
|
|
26
|
+
s: startOfSecond,
|
|
28
27
|
};
|
|
29
28
|
const relativeDate = /^\$now(?<units>\(((y|M|d|h|m|s):(-?\d+),?)+\))?$/;
|
|
30
29
|
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
|
|
31
33
|
const absoluteDate = /^(?<y>\d{4,})(-(?<M>\d\d)(-(?<d>\d\d)([T ](?<h>\d\d)(:(?<m>\d\d)(:(?<s>\d\d))?)?)?)?)?/;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
// Convert relative dates and returns the minimum date unit specified
|
|
35
|
+
export function parseDate(value, now) {
|
|
36
|
+
let date;
|
|
37
|
+
let units;
|
|
38
|
+
const relativeMatch = relativeDate.exec(value);
|
|
39
|
+
if (relativeMatch) {
|
|
40
|
+
date = now || new Date();
|
|
41
|
+
const unitsGroup = relativeMatch.groups?.units;
|
|
42
|
+
if (unitsGroup) {
|
|
43
|
+
const unitMatches = unitsGroup.matchAll(relativeUnit);
|
|
44
|
+
units = [];
|
|
45
|
+
for (const [_, unit, delta] of unitMatches) {
|
|
46
|
+
date = add(date, { [dateUnitMap[unit]]: Number(delta) });
|
|
47
|
+
units.push(unit);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
units = ["d"];
|
|
52
|
+
}
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
else {
|
|
55
|
+
date = parseISO(value);
|
|
56
|
+
units = Object.entries(absoluteDate.exec(value)?.groups || {})
|
|
57
|
+
.filter(([_, n]) => !!n)
|
|
58
|
+
.map(([unit]) => unit);
|
|
59
|
+
}
|
|
60
|
+
const minUnit = getMinDateUnit(units) || "s";
|
|
61
|
+
return [startOf[minUnit](date), minUnit];
|
|
55
62
|
}
|
|
56
|
-
function getMinDateUnit(units) {
|
|
57
|
-
|
|
63
|
+
export function getMinDateUnit(units) {
|
|
64
|
+
return dateUnits.find((unit) => units.includes(unit));
|
|
58
65
|
}
|
|
59
|
-
function isValidDate(s) {
|
|
60
|
-
|
|
66
|
+
export function isValidDate(s) {
|
|
67
|
+
return relativeDate.test(s) || isValid(parseISO(s));
|
|
61
68
|
}
|
|
62
|
-
export {
|
|
63
|
-
dateUnitMap,
|
|
64
|
-
dateUnits,
|
|
65
|
-
getMinDateUnit,
|
|
66
|
-
isValidDate,
|
|
67
|
-
parseDate
|
|
68
|
-
};
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { ContributionPeriod, PaymentMethod } from "../data
|
|
1
|
+
import { ContributionPeriod, PaymentMethod } from "../data";
|
|
2
2
|
const stripeFees = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
[PaymentMethod.StripeBACS]: () => 0
|
|
19
|
-
// Not available
|
|
20
|
-
}
|
|
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, // Not available
|
|
12
|
+
},
|
|
13
|
+
ca: {
|
|
14
|
+
[PaymentMethod.StripeCard]: (amount) => 0.3 + 0.029 * amount,
|
|
15
|
+
[PaymentMethod.StripeSEPA]: () => 0,
|
|
16
|
+
[PaymentMethod.StripeBACS]: () => 0, // Not available
|
|
17
|
+
},
|
|
21
18
|
};
|
|
22
19
|
const gcFee = (amount) => 0.2 + amount * 0.01;
|
|
23
|
-
function calcPaymentFee(feeable, country) {
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
export function calcPaymentFee(feeable, country) {
|
|
21
|
+
const feeFn = feeable.paymentMethod === PaymentMethod.GoCardlessDirectDebit
|
|
22
|
+
? gcFee
|
|
23
|
+
: stripeFees[country][feeable.paymentMethod];
|
|
24
|
+
return feeable.period === ContributionPeriod.Annually
|
|
25
|
+
? 0
|
|
26
|
+
: feeFn(feeable.amount);
|
|
26
27
|
}
|
|
27
|
-
export {
|
|
28
|
-
calcPaymentFee
|
|
29
|
-
};
|
package/dist/esm/utils/rules.js
CHANGED
|
@@ -1,80 +1,63 @@
|
|
|
1
|
-
import { InvalidRule } from "../error
|
|
2
|
-
import { nullableOperators, operatorsByTypeMap } from "../search
|
|
3
|
-
import { isValidDate } from "./date
|
|
4
|
-
function isRuleGroup(ruleOrGroup) {
|
|
5
|
-
|
|
1
|
+
import { InvalidRule } from "../error";
|
|
2
|
+
import { nullableOperators, operatorsByTypeMap, } from "../search";
|
|
3
|
+
import { isValidDate } from "./date";
|
|
4
|
+
export function isRuleGroup(ruleOrGroup) {
|
|
5
|
+
return "condition" in ruleOrGroup;
|
|
6
6
|
}
|
|
7
|
-
function validateRule(filters, rule) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
);
|
|
7
|
+
export function validateRule(filters, rule) {
|
|
8
|
+
const filter = filters[rule.field];
|
|
9
|
+
if (!filter) {
|
|
10
|
+
throw new InvalidRule(rule, `Invalid field: ${rule.field}`);
|
|
19
11
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
);
|
|
12
|
+
let expectedArgs = 0;
|
|
13
|
+
if (rule.operator in nullableOperators) {
|
|
14
|
+
// Field cannot be empty (except text which can always be empty)
|
|
15
|
+
if (!filter.nullable && filter.type !== "text") {
|
|
16
|
+
throw new InvalidRule(rule, `Invalid nullable operator: field is not nullable`);
|
|
17
|
+
}
|
|
27
18
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
type: filter.type,
|
|
60
|
-
nullable: !!filter.nullable,
|
|
61
|
-
operator: rule.operator,
|
|
62
|
-
value: rule.value
|
|
63
|
-
};
|
|
19
|
+
else {
|
|
20
|
+
const operator = operatorsByTypeMap[filter.type][rule.operator];
|
|
21
|
+
if (!operator) {
|
|
22
|
+
throw new InvalidRule(rule, `Invalid operator for type: ${filter.type} type doesn't define ${rule.operator}`);
|
|
23
|
+
}
|
|
24
|
+
expectedArgs = operator.args;
|
|
25
|
+
}
|
|
26
|
+
if (expectedArgs !== rule.value.length) {
|
|
27
|
+
throw new InvalidRule(rule, `Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`);
|
|
28
|
+
}
|
|
29
|
+
const expectedType = filter.type === "boolean" || filter.type === "number"
|
|
30
|
+
? filter.type
|
|
31
|
+
: "string";
|
|
32
|
+
if (rule.value.some((v) => typeof v !== expectedType)) {
|
|
33
|
+
throw new InvalidRule(rule, `Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map((v) => typeof v)} given`);
|
|
34
|
+
}
|
|
35
|
+
if (filter.type === "date" &&
|
|
36
|
+
rule.value.some((v) => !isValidDate(v))) {
|
|
37
|
+
throw new InvalidRule(rule, `Invalid operator argument: date type needs valid absolute or relative date, ${rule.value} given`);
|
|
38
|
+
}
|
|
39
|
+
if ((filter.type === "enum" || filter.type === "array") &&
|
|
40
|
+
rule.value.some((v) => filter.options?.indexOf(v) === -1)) {
|
|
41
|
+
throw new InvalidRule(rule, `Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
field: rule.field,
|
|
45
|
+
type: filter.type,
|
|
46
|
+
nullable: !!filter.nullable,
|
|
47
|
+
operator: rule.operator,
|
|
48
|
+
value: rule.value,
|
|
49
|
+
};
|
|
64
50
|
}
|
|
65
|
-
function validateRuleGroup(filters, ruleGroup) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
51
|
+
export function validateRuleGroup(filters, ruleGroup) {
|
|
52
|
+
const validatedRuleGroup = {
|
|
53
|
+
condition: ruleGroup.condition,
|
|
54
|
+
rules: [],
|
|
55
|
+
};
|
|
56
|
+
for (const rule of ruleGroup.rules) {
|
|
57
|
+
const valid = isRuleGroup(rule)
|
|
58
|
+
? validateRuleGroup(filters, rule)
|
|
59
|
+
: validateRule(filters, rule);
|
|
60
|
+
validatedRuleGroup.rules.push(valid);
|
|
61
|
+
}
|
|
62
|
+
return validatedRuleGroup;
|
|
75
63
|
}
|
|
76
|
-
export {
|
|
77
|
-
isRuleGroup,
|
|
78
|
-
validateRule,
|
|
79
|
-
validateRuleGroup
|
|
80
|
-
};
|