@beabee/beabee-common 1.10.20 → 1.10.22
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/index.js +1 -0
- package/dist/cjs/utils/callouts.js +39 -1
- package/dist/cjs/utils/payments.js +31 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/callouts.js +36 -0
- package/dist/esm/utils/payments.js +27 -0
- package/dist/types/data/callouts.d.ts +2 -0
- package/dist/types/data/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/callouts.d.ts +3 -1
- package/dist/types/utils/payments.d.ts +8 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -19,4 +19,5 @@ __exportStar(require("./data"), exports);
|
|
|
19
19
|
__exportStar(require("./error"), exports);
|
|
20
20
|
__exportStar(require("./utils/callouts"), exports);
|
|
21
21
|
__exportStar(require("./utils/date"), exports);
|
|
22
|
+
__exportStar(require("./utils/payments"), exports);
|
|
22
23
|
__exportStar(require("./utils/rules"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertComponentsToFilters = exports.flattenComponents = void 0;
|
|
3
|
+
exports.convertAnswers = exports.convertAnswer = exports.convertComponentsToFilters = exports.flattenComponents = void 0;
|
|
4
4
|
function flattenComponents(components) {
|
|
5
5
|
return components.flatMap((component) => [
|
|
6
6
|
component,
|
|
@@ -45,3 +45,41 @@ function convertComponentsToFilters(components) {
|
|
|
45
45
|
return Object.fromEntries(items);
|
|
46
46
|
}
|
|
47
47
|
exports.convertComponentsToFilters = convertComponentsToFilters;
|
|
48
|
+
function getNiceAnswer(component, value) {
|
|
49
|
+
switch (component.type) {
|
|
50
|
+
case "radio":
|
|
51
|
+
case "selectboxes":
|
|
52
|
+
return component.values.find((v) => v.value === value)?.label || value;
|
|
53
|
+
case "select":
|
|
54
|
+
return (component.data.values.find((v) => v.value === value)?.label || value);
|
|
55
|
+
default:
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function convertAnswer(component, answer) {
|
|
60
|
+
if (!answer) {
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
else if (typeof answer === "object") {
|
|
64
|
+
return Object.entries(answer)
|
|
65
|
+
.filter(([, selected]) => selected)
|
|
66
|
+
.map(([value]) => getNiceAnswer(component, value))
|
|
67
|
+
.join(", ");
|
|
68
|
+
}
|
|
69
|
+
else if (typeof answer === "string") {
|
|
70
|
+
return getNiceAnswer(component, answer);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return answer.toString();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.convertAnswer = convertAnswer;
|
|
77
|
+
function convertAnswers(formSchema, answers) {
|
|
78
|
+
return Object.fromEntries(flattenComponents(formSchema.components)
|
|
79
|
+
.filter((component) => component.input)
|
|
80
|
+
.map((component) => [
|
|
81
|
+
component.label || component.key,
|
|
82
|
+
convertAnswer(component, answers[component.key]),
|
|
83
|
+
]));
|
|
84
|
+
}
|
|
85
|
+
exports.convertAnswers = convertAnswers;
|
|
@@ -0,0 +1,31 @@
|
|
|
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.014 * amount,
|
|
8
|
+
[data_1.PaymentMethod.StripeSEPA]: () => 0.3,
|
|
9
|
+
[data_1.PaymentMethod.StripeBACS]: (amount) => 0.2 * 0.01 * amount,
|
|
10
|
+
},
|
|
11
|
+
eu: {
|
|
12
|
+
[data_1.PaymentMethod.StripeCard]: (amount) => 0.25 + 0.014 * 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 / 100;
|
|
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/esm/index.js
CHANGED
|
@@ -40,3 +40,39 @@ export function convertComponentsToFilters(components) {
|
|
|
40
40
|
});
|
|
41
41
|
return Object.fromEntries(items);
|
|
42
42
|
}
|
|
43
|
+
function getNiceAnswer(component, value) {
|
|
44
|
+
switch (component.type) {
|
|
45
|
+
case "radio":
|
|
46
|
+
case "selectboxes":
|
|
47
|
+
return component.values.find((v) => v.value === value)?.label || value;
|
|
48
|
+
case "select":
|
|
49
|
+
return (component.data.values.find((v) => v.value === value)?.label || value);
|
|
50
|
+
default:
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function convertAnswer(component, answer) {
|
|
55
|
+
if (!answer) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
else if (typeof answer === "object") {
|
|
59
|
+
return Object.entries(answer)
|
|
60
|
+
.filter(([, selected]) => selected)
|
|
61
|
+
.map(([value]) => getNiceAnswer(component, value))
|
|
62
|
+
.join(", ");
|
|
63
|
+
}
|
|
64
|
+
else if (typeof answer === "string") {
|
|
65
|
+
return getNiceAnswer(component, answer);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return answer.toString();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function convertAnswers(formSchema, answers) {
|
|
72
|
+
return Object.fromEntries(flattenComponents(formSchema.components)
|
|
73
|
+
.filter((component) => component.input)
|
|
74
|
+
.map((component) => [
|
|
75
|
+
component.label || component.key,
|
|
76
|
+
convertAnswer(component, answers[component.key]),
|
|
77
|
+
]));
|
|
78
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ContributionPeriod, PaymentMethod } from "../data";
|
|
2
|
+
const stripeFees = {
|
|
3
|
+
gb: {
|
|
4
|
+
[PaymentMethod.StripeCard]: (amount) => 0.2 + 0.014 * amount,
|
|
5
|
+
[PaymentMethod.StripeSEPA]: () => 0.3,
|
|
6
|
+
[PaymentMethod.StripeBACS]: (amount) => 0.2 * 0.01 * amount,
|
|
7
|
+
},
|
|
8
|
+
eu: {
|
|
9
|
+
[PaymentMethod.StripeCard]: (amount) => 0.25 + 0.014 * 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
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const gcFee = (amount) => 0.2 + amount / 100;
|
|
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);
|
|
27
|
+
}
|
|
@@ -28,3 +28,5 @@ export type CalloutComponentSchema = SelectCalloutComponentSchema | RadioCallout
|
|
|
28
28
|
export interface CalloutFormSchema {
|
|
29
29
|
components: CalloutComponentSchema[];
|
|
30
30
|
}
|
|
31
|
+
export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean>;
|
|
32
|
+
export type CalloutResponseAnswers = Record<string, CalloutResponseAnswer>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { CalloutComponentSchema } from "../data/callouts";
|
|
1
|
+
import { CalloutComponentSchema, CalloutFormSchema, CalloutResponseAnswer, CalloutResponseAnswers } from "../data/callouts";
|
|
2
2
|
import { Filters } from "../search";
|
|
3
3
|
export declare function flattenComponents(components: CalloutComponentSchema[]): CalloutComponentSchema[];
|
|
4
4
|
export declare function convertComponentsToFilters(components: CalloutComponentSchema[]): Filters;
|
|
5
|
+
export declare function convertAnswer(component: CalloutComponentSchema, answer: CalloutResponseAnswer): string;
|
|
6
|
+
export declare function convertAnswers(formSchema: CalloutFormSchema, answers: CalloutResponseAnswers): Record<string, string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ContributionPeriod, PaymentMethod, StripeFeeCountry } from "../data";
|
|
2
|
+
interface Feeable {
|
|
3
|
+
amount: number;
|
|
4
|
+
period: ContributionPeriod;
|
|
5
|
+
paymentMethod: PaymentMethod;
|
|
6
|
+
}
|
|
7
|
+
export declare function calcPaymentFee(feeable: Feeable, country: StripeFeeCountry): number;
|
|
8
|
+
export {};
|