@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,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringifyAnswer = exports.isFileUploadAnswer = exports.isAddressAnswer = exports.getCalloutFilters = exports.getCalloutComponents = exports.filterComponents = exports.flattenComponents = void 0;
|
|
4
|
-
function isNestableComponent(component) {
|
|
5
|
-
// Addresses have embedded components we don't want to include
|
|
6
|
-
return "components" in component && component.type !== "address";
|
|
7
|
-
}
|
|
8
|
-
function convertValuesToOptions(values) {
|
|
9
|
-
return values.map(({ value, label }) => value);
|
|
10
|
-
}
|
|
11
|
-
function convertComponentToFilter(component) {
|
|
12
|
-
const baseItem = {
|
|
13
|
-
label: component.label || component.fullKey,
|
|
14
|
-
nullable: true,
|
|
15
|
-
};
|
|
16
|
-
switch (component.type) {
|
|
17
|
-
case "checkbox":
|
|
18
|
-
return { ...baseItem, type: "boolean", nullable: false };
|
|
19
|
-
case "number":
|
|
20
|
-
return { ...baseItem, type: "number" };
|
|
21
|
-
case "select":
|
|
22
|
-
return {
|
|
23
|
-
...baseItem,
|
|
24
|
-
type: "enum",
|
|
25
|
-
options: convertValuesToOptions(component.data.values),
|
|
26
|
-
};
|
|
27
|
-
case "selectboxes":
|
|
28
|
-
case "radio":
|
|
29
|
-
return {
|
|
30
|
-
...baseItem,
|
|
31
|
-
type: component.type === "radio" ? "enum" : "array",
|
|
32
|
-
options: convertValuesToOptions(component.values),
|
|
33
|
-
};
|
|
34
|
-
case "textarea":
|
|
35
|
-
return { ...baseItem, type: "blob" };
|
|
36
|
-
default:
|
|
37
|
-
return { ...baseItem, type: "text" };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function getNiceAnswer(component, value) {
|
|
41
|
-
switch (component.type) {
|
|
42
|
-
case "radio":
|
|
43
|
-
case "selectboxes":
|
|
44
|
-
return component.values.find((v) => v.value === value)?.label || value;
|
|
45
|
-
case "select":
|
|
46
|
-
return (component.data.values.find((v) => v.value === value)?.label || value);
|
|
47
|
-
default:
|
|
48
|
-
return value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function flattenComponents(components) {
|
|
52
|
-
return components.flatMap((component) => isNestableComponent(component)
|
|
53
|
-
? [component, ...flattenComponents(component.components)]
|
|
54
|
-
: [component]);
|
|
55
|
-
}
|
|
56
|
-
exports.flattenComponents = flattenComponents;
|
|
57
|
-
function filterComponents(components, filterFn) {
|
|
58
|
-
return components.filter(filterFn).map((component) => {
|
|
59
|
-
return {
|
|
60
|
-
...component,
|
|
61
|
-
...(isNestableComponent(component) && {
|
|
62
|
-
components: filterComponents(component.components, filterFn),
|
|
63
|
-
}),
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
exports.filterComponents = filterComponents;
|
|
68
|
-
function getCalloutComponents(formSchema) {
|
|
69
|
-
return formSchema.slides.flatMap((slide) => flattenComponents(slide.components).map((component) => ({
|
|
70
|
-
...component,
|
|
71
|
-
slideId: slide.id,
|
|
72
|
-
fullKey: `${slide.id}.${component.key}`,
|
|
73
|
-
})));
|
|
74
|
-
}
|
|
75
|
-
exports.getCalloutComponents = getCalloutComponents;
|
|
76
|
-
function getCalloutFilters(formSchema) {
|
|
77
|
-
const items = getCalloutComponents(formSchema)
|
|
78
|
-
.filter((c) => c.input)
|
|
79
|
-
.map((c) => [`answers.${c.fullKey}`, convertComponentToFilter(c)]);
|
|
80
|
-
return Object.fromEntries(items);
|
|
81
|
-
}
|
|
82
|
-
exports.getCalloutFilters = getCalloutFilters;
|
|
83
|
-
function isAddressAnswer(answer) {
|
|
84
|
-
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
85
|
-
}
|
|
86
|
-
exports.isAddressAnswer = isAddressAnswer;
|
|
87
|
-
function isFileUploadAnswer(answer) {
|
|
88
|
-
return !!answer && typeof answer === "object" && "url" in answer;
|
|
89
|
-
}
|
|
90
|
-
exports.isFileUploadAnswer = isFileUploadAnswer;
|
|
91
|
-
function stringifyAnswer(component, answer) {
|
|
92
|
-
if (Array.isArray(answer)) {
|
|
93
|
-
return answer.map((a) => stringifyAnswer(component, a)).join(", ");
|
|
94
|
-
}
|
|
95
|
-
else if (!answer) {
|
|
96
|
-
return "";
|
|
97
|
-
}
|
|
98
|
-
else if (isAddressAnswer(answer)) {
|
|
99
|
-
return answer.geometry.location.lat + ", " + answer.geometry.location.lng;
|
|
100
|
-
}
|
|
101
|
-
else if (isFileUploadAnswer(answer)) {
|
|
102
|
-
return answer.url;
|
|
103
|
-
}
|
|
104
|
-
else if (typeof answer === "object") {
|
|
105
|
-
// Checkboxes
|
|
106
|
-
return Object.entries(answer)
|
|
107
|
-
.filter(([, selected]) => selected)
|
|
108
|
-
.map(([value]) => getNiceAnswer(component, value))
|
|
109
|
-
.join(", ");
|
|
110
|
-
}
|
|
111
|
-
else if (typeof answer === "string") {
|
|
112
|
-
return getNiceAnswer(component, answer);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return answer.toString();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
exports.stringifyAnswer = stringifyAnswer;
|
package/dist/cjs/utils/date.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isValidDate = exports.getMinDateUnit = exports.parseDate = void 0;
|
|
7
|
-
const add_1 = __importDefault(require("date-fns/add"));
|
|
8
|
-
const isValid_1 = __importDefault(require("date-fns/isValid"));
|
|
9
|
-
const parseISO_1 = __importDefault(require("date-fns/parseISO"));
|
|
10
|
-
const startOfDay_1 = __importDefault(require("date-fns/startOfDay"));
|
|
11
|
-
const startOfHour_1 = __importDefault(require("date-fns/startOfHour"));
|
|
12
|
-
const startOfMinute_1 = __importDefault(require("date-fns/startOfMinute"));
|
|
13
|
-
const startOfMonth_1 = __importDefault(require("date-fns/startOfMonth"));
|
|
14
|
-
const startOfSecond_1 = __importDefault(require("date-fns/startOfSecond"));
|
|
15
|
-
const startOfYear_1 = __importDefault(require("date-fns/startOfYear"));
|
|
16
|
-
// Must be ordered from highest resolution to lowest (seconds to years)
|
|
17
|
-
const dateUnits = ["s", "m", "h", "d", "M", "y"];
|
|
18
|
-
const dateUnitMap = {
|
|
19
|
-
y: "years",
|
|
20
|
-
M: "months",
|
|
21
|
-
d: "days",
|
|
22
|
-
h: "hours",
|
|
23
|
-
m: "minutes",
|
|
24
|
-
s: "seconds",
|
|
25
|
-
};
|
|
26
|
-
const startOf = {
|
|
27
|
-
y: startOfYear_1.default,
|
|
28
|
-
M: startOfMonth_1.default,
|
|
29
|
-
d: startOfDay_1.default,
|
|
30
|
-
h: startOfHour_1.default,
|
|
31
|
-
m: startOfMinute_1.default,
|
|
32
|
-
s: startOfSecond_1.default,
|
|
33
|
-
};
|
|
34
|
-
const relativeDate = /^\$now(?<units>\(((y|M|d|h|m|s):(-?\d+),?)+\))?$/;
|
|
35
|
-
const relativeUnit = /(y|M|d|h|m|s):(-?\d+)/g;
|
|
36
|
-
// Matches the different parts of an ISO 8601 date. Note we don't validate the
|
|
37
|
-
// pattern properly as that is handled by parseISO, we just want to know which
|
|
38
|
-
// parts of the date were specified
|
|
39
|
-
const absoluteDate = /^(?<y>\d{4,})(-(?<M>\d\d)(-(?<d>\d\d)([T ](?<h>\d\d)(:(?<m>\d\d)(:(?<s>\d\d))?)?)?)?)?/;
|
|
40
|
-
// Convert relative dates and returns the minimum date unit specified
|
|
41
|
-
function parseDate(value, now) {
|
|
42
|
-
let date;
|
|
43
|
-
let units;
|
|
44
|
-
const relativeMatch = relativeDate.exec(value);
|
|
45
|
-
if (relativeMatch) {
|
|
46
|
-
date = now || new Date();
|
|
47
|
-
const unitsGroup = relativeMatch.groups?.units;
|
|
48
|
-
if (unitsGroup) {
|
|
49
|
-
const unitMatches = unitsGroup.matchAll(relativeUnit);
|
|
50
|
-
units = [];
|
|
51
|
-
for (const [_, unit, delta] of unitMatches) {
|
|
52
|
-
date = (0, add_1.default)(date, { [dateUnitMap[unit]]: Number(delta) });
|
|
53
|
-
units.push(unit);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
units = ["d"];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
date = (0, parseISO_1.default)(value);
|
|
62
|
-
units = Object.entries(absoluteDate.exec(value)?.groups || {})
|
|
63
|
-
.filter(([_, n]) => !!n)
|
|
64
|
-
.map(([unit]) => unit);
|
|
65
|
-
}
|
|
66
|
-
const minUnit = getMinDateUnit(units) || "s";
|
|
67
|
-
return [startOf[minUnit](date), minUnit];
|
|
68
|
-
}
|
|
69
|
-
exports.parseDate = parseDate;
|
|
70
|
-
function getMinDateUnit(units) {
|
|
71
|
-
return dateUnits.find((unit) => units.includes(unit));
|
|
72
|
-
}
|
|
73
|
-
exports.getMinDateUnit = getMinDateUnit;
|
|
74
|
-
function isValidDate(s) {
|
|
75
|
-
return relativeDate.test(s) || (0, isValid_1.default)((0, parseISO_1.default)(s));
|
|
76
|
-
}
|
|
77
|
-
exports.isValidDate = isValidDate;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calcPaymentFee = void 0;
|
|
4
|
-
const data_1 = require("../data");
|
|
5
|
-
const stripeFees = {
|
|
6
|
-
gb: {
|
|
7
|
-
[data_1.PaymentMethod.StripeCard]: (amount) => 0.2 + 0.015 * amount,
|
|
8
|
-
[data_1.PaymentMethod.StripeSEPA]: () => 0.3,
|
|
9
|
-
[data_1.PaymentMethod.StripeBACS]: (amount) => Math.min(2, Math.max(0.2, 0.01 * amount)),
|
|
10
|
-
},
|
|
11
|
-
eu: {
|
|
12
|
-
[data_1.PaymentMethod.StripeCard]: (amount) => 0.25 + 0.015 * amount,
|
|
13
|
-
[data_1.PaymentMethod.StripeSEPA]: () => 0.35,
|
|
14
|
-
[data_1.PaymentMethod.StripeBACS]: () => 0, // Not available
|
|
15
|
-
},
|
|
16
|
-
ca: {
|
|
17
|
-
[data_1.PaymentMethod.StripeCard]: (amount) => 0.3 + 0.029 * amount,
|
|
18
|
-
[data_1.PaymentMethod.StripeSEPA]: () => 0,
|
|
19
|
-
[data_1.PaymentMethod.StripeBACS]: () => 0, // Not available
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
const gcFee = (amount) => 0.2 + amount * 0.01;
|
|
23
|
-
function calcPaymentFee(feeable, country) {
|
|
24
|
-
const feeFn = feeable.paymentMethod === data_1.PaymentMethod.GoCardlessDirectDebit
|
|
25
|
-
? gcFee
|
|
26
|
-
: stripeFees[country][feeable.paymentMethod];
|
|
27
|
-
return feeable.period === data_1.ContributionPeriod.Annually
|
|
28
|
-
? 0
|
|
29
|
-
: feeFn(feeable.amount);
|
|
30
|
-
}
|
|
31
|
-
exports.calcPaymentFee = calcPaymentFee;
|
package/dist/cjs/utils/rules.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRuleGroup = exports.validateRule = exports.isRuleGroup = void 0;
|
|
4
|
-
const error_1 = require("../error");
|
|
5
|
-
const search_1 = require("../search");
|
|
6
|
-
const date_1 = require("./date");
|
|
7
|
-
function isRuleGroup(ruleOrGroup) {
|
|
8
|
-
return "condition" in ruleOrGroup;
|
|
9
|
-
}
|
|
10
|
-
exports.isRuleGroup = isRuleGroup;
|
|
11
|
-
function validateRule(filters, rule) {
|
|
12
|
-
const filter = filters[rule.field];
|
|
13
|
-
if (!filter) {
|
|
14
|
-
throw new error_1.InvalidRule(rule, `Invalid field: ${rule.field}`);
|
|
15
|
-
}
|
|
16
|
-
let expectedArgs = 0;
|
|
17
|
-
if (rule.operator in search_1.nullableOperators) {
|
|
18
|
-
// Field cannot be empty (except text which can always be empty)
|
|
19
|
-
if (!filter.nullable && filter.type !== "text") {
|
|
20
|
-
throw new error_1.InvalidRule(rule, `Invalid nullable operator: field is not nullable`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const operator = search_1.operatorsByTypeMap[filter.type][rule.operator];
|
|
25
|
-
if (!operator) {
|
|
26
|
-
throw new error_1.InvalidRule(rule, `Invalid operator for type: ${filter.type} type doesn't define ${rule.operator}`);
|
|
27
|
-
}
|
|
28
|
-
expectedArgs = operator.args;
|
|
29
|
-
}
|
|
30
|
-
if (expectedArgs !== rule.value.length) {
|
|
31
|
-
throw new error_1.InvalidRule(rule, `Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`);
|
|
32
|
-
}
|
|
33
|
-
const expectedType = filter.type === "boolean" || filter.type === "number"
|
|
34
|
-
? filter.type
|
|
35
|
-
: "string";
|
|
36
|
-
if (rule.value.some((v) => typeof v !== expectedType)) {
|
|
37
|
-
throw new error_1.InvalidRule(rule, `Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map((v) => typeof v)} given`);
|
|
38
|
-
}
|
|
39
|
-
if (filter.type === "date" &&
|
|
40
|
-
rule.value.some((v) => !(0, date_1.isValidDate)(v))) {
|
|
41
|
-
throw new error_1.InvalidRule(rule, `Invalid operator argument: date type needs valid absolute or relative date, ${rule.value} given`);
|
|
42
|
-
}
|
|
43
|
-
if ((filter.type === "enum" || filter.type === "array") &&
|
|
44
|
-
rule.value.some((v) => filter.options?.indexOf(v) === -1)) {
|
|
45
|
-
throw new error_1.InvalidRule(rule, `Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
field: rule.field,
|
|
49
|
-
type: filter.type,
|
|
50
|
-
nullable: !!filter.nullable,
|
|
51
|
-
operator: rule.operator,
|
|
52
|
-
value: rule.value,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
exports.validateRule = validateRule;
|
|
56
|
-
function validateRuleGroup(filters, ruleGroup) {
|
|
57
|
-
const validatedRuleGroup = {
|
|
58
|
-
condition: ruleGroup.condition,
|
|
59
|
-
rules: [],
|
|
60
|
-
};
|
|
61
|
-
for (const rule of ruleGroup.rules) {
|
|
62
|
-
const valid = isRuleGroup(rule)
|
|
63
|
-
? validateRuleGroup(filters, rule)
|
|
64
|
-
: validateRule(filters, rule);
|
|
65
|
-
validatedRuleGroup.rules.push(valid);
|
|
66
|
-
}
|
|
67
|
-
return validatedRuleGroup;
|
|
68
|
-
}
|
|
69
|
-
exports.validateRuleGroup = validateRuleGroup;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export interface BaseCalloutComponentSchema {
|
|
2
|
-
id: string;
|
|
3
|
-
type: string;
|
|
4
|
-
key: string;
|
|
5
|
-
label?: string;
|
|
6
|
-
input?: boolean;
|
|
7
|
-
adminOnly?: boolean;
|
|
8
|
-
[key: string]: unknown;
|
|
9
|
-
}
|
|
10
|
-
export interface NestableCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
11
|
-
type: "panel" | "well" | "tabs";
|
|
12
|
-
input: false;
|
|
13
|
-
components: CalloutComponentSchema[];
|
|
14
|
-
}
|
|
15
|
-
export interface InputCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
16
|
-
type: "address" | "button" | "checkbox" | "email" | "file" | "number" | "password" | "textfield" | "textarea";
|
|
17
|
-
input: true;
|
|
18
|
-
}
|
|
19
|
-
export interface SelectCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
20
|
-
type: "select";
|
|
21
|
-
input: true;
|
|
22
|
-
data: {
|
|
23
|
-
values: {
|
|
24
|
-
label: string;
|
|
25
|
-
value: string;
|
|
26
|
-
}[];
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export interface RadioCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
30
|
-
type: "radio" | "selectboxes";
|
|
31
|
-
input: true;
|
|
32
|
-
values: {
|
|
33
|
-
label: string;
|
|
34
|
-
value: string;
|
|
35
|
-
nextSlideId: string;
|
|
36
|
-
}[];
|
|
37
|
-
}
|
|
38
|
-
export type CalloutComponentSchema = SelectCalloutComponentSchema | RadioCalloutComponentSchema | InputCalloutComponentSchema | NestableCalloutComponentSchema;
|
|
39
|
-
export interface CalloutNavigationSchema {
|
|
40
|
-
prevText: string;
|
|
41
|
-
nextText: string;
|
|
42
|
-
nextSlideId: string;
|
|
43
|
-
submitText: string;
|
|
44
|
-
}
|
|
45
|
-
export interface CalloutSlideSchema {
|
|
46
|
-
id: string;
|
|
47
|
-
title: string;
|
|
48
|
-
components: CalloutComponentSchema[];
|
|
49
|
-
navigation: CalloutNavigationSchema;
|
|
50
|
-
}
|
|
51
|
-
export interface CalloutFormSchema {
|
|
52
|
-
slides: CalloutSlideSchema[];
|
|
53
|
-
}
|
|
54
|
-
export interface CalloutResponseAnswerAddress {
|
|
55
|
-
formatted_address: string;
|
|
56
|
-
geometry: {
|
|
57
|
-
location: {
|
|
58
|
-
lat: number;
|
|
59
|
-
lng: number;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export interface CalloutResponseAnswerFileUpload {
|
|
64
|
-
url: string;
|
|
65
|
-
}
|
|
66
|
-
export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean> | CalloutResponseAnswerAddress | CalloutResponseAnswerFileUpload;
|
|
67
|
-
/**
|
|
68
|
-
* Answers are grouped by slide key: {[slideId]: {[componentKey]: answer | answer[]}}
|
|
69
|
-
*/
|
|
70
|
-
export type CalloutResponseAnswers = Record<string, Record<string, CalloutResponseAnswer | CalloutResponseAnswer[]> | undefined>;
|