@better-giving/donation 1.1.14 → 1.1.16
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/donation.d.mts +1 -0
- package/dist/intent.d.mts +2 -0
- package/dist/intent.mjs +1 -0
- package/dist/old-intent.mjs +3 -3
- package/package.json +1 -1
- package/src/donation.mts +1 -0
- package/src/intent.mts +1 -0
- package/src/final-recorder.mts +0 -54
- package/src/get-min-fee-allowance.mts +0 -20
- package/src/old-intent.mts +0 -104
package/dist/donation.d.mts
CHANGED
|
@@ -196,6 +196,7 @@ export declare namespace Donation {
|
|
|
196
196
|
title?: DonorTitle;
|
|
197
197
|
firstName: string;
|
|
198
198
|
lastName: string;
|
|
199
|
+
companyName?: string;
|
|
199
200
|
email: string;
|
|
200
201
|
address?: DonorAddress;
|
|
201
202
|
/** signifies eligibility to UK Gift Aid, defaults to `false` for crypto donations */
|
package/dist/intent.d.mts
CHANGED
|
@@ -21,6 +21,7 @@ export type DonorAddress = v.InferOutput<typeof donorAddress>;
|
|
|
21
21
|
export declare const donor: v.ObjectSchema<{
|
|
22
22
|
readonly title: v.PicklistSchema<readonly ["Mr", "Mrs", "Ms", "Mx", ""], undefined>;
|
|
23
23
|
readonly firstName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
|
|
24
|
+
readonly companyName: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
|
|
24
25
|
readonly lastName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
|
|
25
26
|
readonly email: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.EmailAction<string, undefined>]>;
|
|
26
27
|
readonly address: v.OptionalSchema<v.ObjectSchema<{
|
|
@@ -80,6 +81,7 @@ export declare const intent: v.ObjectSchema<{
|
|
|
80
81
|
readonly donor: v.ObjectSchema<{
|
|
81
82
|
readonly title: v.PicklistSchema<readonly ["Mr", "Mrs", "Ms", "Mx", ""], undefined>;
|
|
82
83
|
readonly firstName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
|
|
84
|
+
readonly companyName: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
|
|
83
85
|
readonly lastName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
|
|
84
86
|
readonly email: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.EmailAction<string, undefined>]>;
|
|
85
87
|
readonly address: v.OptionalSchema<v.ObjectSchema<{
|
package/dist/intent.mjs
CHANGED
package/dist/old-intent.mjs
CHANGED
|
@@ -41,7 +41,7 @@ export const oldIntent = v.pipe(v.object({
|
|
|
41
41
|
}), v.transform((input) => ({
|
|
42
42
|
amount: {
|
|
43
43
|
amount: input.amount,
|
|
44
|
-
currency: input.currency ? input.currency : input.denomination ?? "",
|
|
44
|
+
currency: input.currency ? input.currency : (input.denomination ?? ""),
|
|
45
45
|
tip: input.tipAmount,
|
|
46
46
|
feeAllowance: input.feeAllowance,
|
|
47
47
|
},
|
|
@@ -83,7 +83,7 @@ export const oldIntent = v.pipe(v.object({
|
|
|
83
83
|
: undefined,
|
|
84
84
|
frequency: (input.type === "subscription"
|
|
85
85
|
? "recurring"
|
|
86
|
-
: input.type ?? "one-time"),
|
|
86
|
+
: (input.type ?? "one-time")),
|
|
87
87
|
viaName: input.chainName ?? "fiat",
|
|
88
|
-
viaId: input.chainId ? input.chainId : input.transactionId ?? "fiat",
|
|
88
|
+
viaId: input.chainId ? input.chainId : (input.transactionId ?? "fiat"),
|
|
89
89
|
})));
|
package/package.json
CHANGED
package/src/donation.mts
CHANGED
|
@@ -292,6 +292,7 @@ export declare namespace Donation {
|
|
|
292
292
|
title?: DonorTitle;
|
|
293
293
|
firstName: string;
|
|
294
294
|
lastName: string;
|
|
295
|
+
companyName?: string;
|
|
295
296
|
email: string;
|
|
296
297
|
address?: DonorAddress;
|
|
297
298
|
/** signifies eligibility to UK Gift Aid, defaults to `false` for crypto donations */
|
package/src/intent.mts
CHANGED
|
@@ -37,6 +37,7 @@ export type DonorAddress = v.InferOutput<typeof donorAddress>;
|
|
|
37
37
|
export const donor = v.object({
|
|
38
38
|
title: donorTitle,
|
|
39
39
|
firstName: requiredStr,
|
|
40
|
+
companyName: v.optional(str),
|
|
40
41
|
lastName: requiredStr,
|
|
41
42
|
email: v.pipe(str, v.email()),
|
|
42
43
|
address: v.optional(donorAddress),
|
package/src/final-recorder.mts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Donation } from "./donation.mjs";
|
|
2
|
-
|
|
3
|
-
type FinalRecord = Pick<
|
|
4
|
-
Donation.V2DBRecord,
|
|
5
|
-
| "amount"
|
|
6
|
-
| "appUsed"
|
|
7
|
-
| "chainName"
|
|
8
|
-
| "charityName"
|
|
9
|
-
| "claimed"
|
|
10
|
-
| "denomination"
|
|
11
|
-
| "email"
|
|
12
|
-
| "endowmentId"
|
|
13
|
-
| "feeAllowance"
|
|
14
|
-
| "fiatRamp"
|
|
15
|
-
| "fiscalSponsored"
|
|
16
|
-
| "inHonorOf"
|
|
17
|
-
| "isRecurring"
|
|
18
|
-
| "network"
|
|
19
|
-
| "nonProfitMsg"
|
|
20
|
-
| "paymentMethod"
|
|
21
|
-
| "programId"
|
|
22
|
-
| "programName"
|
|
23
|
-
| "splitLiq"
|
|
24
|
-
| "tipAmount"
|
|
25
|
-
| "transactionDate"
|
|
26
|
-
| "transactionId"
|
|
27
|
-
| "tributeNotif"
|
|
28
|
-
| "usdValue"
|
|
29
|
-
>;
|
|
30
|
-
|
|
31
|
-
interface SettledAmounts {
|
|
32
|
-
settledFee: number;
|
|
33
|
-
settledNet: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** donation is to fund */
|
|
37
|
-
interface Fund {
|
|
38
|
-
fund_id?: string;
|
|
39
|
-
fund_name?: string;
|
|
40
|
-
fund_members?: number[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type FinalRecorderPayload = {
|
|
44
|
-
/** intent to delete */
|
|
45
|
-
intentId?: string;
|
|
46
|
-
hideBgTip: boolean;
|
|
47
|
-
|
|
48
|
-
/** donation message */
|
|
49
|
-
donor_message?: string;
|
|
50
|
-
donor_public?: boolean;
|
|
51
|
-
} & FinalRecord &
|
|
52
|
-
SettledAmounts &
|
|
53
|
-
Fund &
|
|
54
|
-
(Donation.WithKYC | Donation.WithoutKYC);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param amount endow amount + tip
|
|
3
|
-
* @param rate 0-1, to be applied to amount @example `amount * rate`
|
|
4
|
-
* @param flat flat amount added to `amount * rate`. NOTE: make sure that this is in the same unit as `amount`
|
|
5
|
-
* @returns number
|
|
6
|
-
*/
|
|
7
|
-
export const getMinFeeAllowance = (
|
|
8
|
-
amount: number,
|
|
9
|
-
rate: number,
|
|
10
|
-
flat = 0
|
|
11
|
-
): number => {
|
|
12
|
-
/**
|
|
13
|
-
* fee(1) = amount * rate + flat
|
|
14
|
-
* fee(2) = (amount + fee(1)) * rate + flat
|
|
15
|
-
* fee(3) = (amount + fee(2)) * rate + flat
|
|
16
|
-
* i.e. F₍ₙ₎ = a · ∑ᵏ⁼¹ⁿ (rᵏ) + f · ∑ᵏ⁼⁰ⁿ⁻¹ (rᵏ)
|
|
17
|
-
* which converges to this formula: n approaches infinity
|
|
18
|
-
*/
|
|
19
|
-
return (amount * rate + flat) / (1 - rate);
|
|
20
|
-
};
|
package/src/old-intent.mts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
import {
|
|
3
|
-
type Frequency,
|
|
4
|
-
donationSource,
|
|
5
|
-
donorTitle,
|
|
6
|
-
tributeNotif,
|
|
7
|
-
uuid,
|
|
8
|
-
} from "./intent.mjs";
|
|
9
|
-
|
|
10
|
-
const str = v.pipe(v.string(), v.trim());
|
|
11
|
-
const requiredStr = v.pipe(str, v.nonEmpty());
|
|
12
|
-
|
|
13
|
-
const int = v.pipe(v.number(), v.integer());
|
|
14
|
-
const money = v.pipe(v.number(), v.minValue(0));
|
|
15
|
-
|
|
16
|
-
const donorAddress = v.object({
|
|
17
|
-
streetAddress: requiredStr,
|
|
18
|
-
city: str,
|
|
19
|
-
state: str,
|
|
20
|
-
zipCode: requiredStr,
|
|
21
|
-
/** country name */
|
|
22
|
-
country: requiredStr,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const donor = v.object({
|
|
26
|
-
title: donorTitle,
|
|
27
|
-
firstName: requiredStr,
|
|
28
|
-
lastName: requiredStr,
|
|
29
|
-
email: v.pipe(str, v.email()),
|
|
30
|
-
address: v.optional(donorAddress),
|
|
31
|
-
ukGiftAid: v.optional(v.boolean()),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export const oldIntent = v.pipe(
|
|
35
|
-
v.object({
|
|
36
|
-
transactionId: v.optional(str),
|
|
37
|
-
type: v.optional(v.picklist(["one-time", "subscription"])),
|
|
38
|
-
amount: money,
|
|
39
|
-
tipAmount: money,
|
|
40
|
-
feeAllowance: money,
|
|
41
|
-
currency: v.optional(str),
|
|
42
|
-
endowmentId: v.pipe(int, v.minValue(1)),
|
|
43
|
-
programId: v.optional(uuid),
|
|
44
|
-
programName: v.optional(str),
|
|
45
|
-
splitLiq: v.pipe(int, v.minValue(0), v.maxValue(100)),
|
|
46
|
-
donor,
|
|
47
|
-
inHonorOf: v.optional(str),
|
|
48
|
-
tributeNotif: v.optional(tributeNotif),
|
|
49
|
-
source: donationSource,
|
|
50
|
-
denomination: v.optional(str),
|
|
51
|
-
chainId: v.optional(str),
|
|
52
|
-
chainName: v.optional(str),
|
|
53
|
-
}),
|
|
54
|
-
v.transform((input) => ({
|
|
55
|
-
amount: {
|
|
56
|
-
amount: input.amount,
|
|
57
|
-
currency: input.currency ? input.currency : input.denomination ?? "",
|
|
58
|
-
tip: input.tipAmount,
|
|
59
|
-
feeAllowance: input.feeAllowance,
|
|
60
|
-
},
|
|
61
|
-
recipient: input.endowmentId,
|
|
62
|
-
program:
|
|
63
|
-
input.programId && input.programName
|
|
64
|
-
? {
|
|
65
|
-
id: input.programId,
|
|
66
|
-
name: input.programName,
|
|
67
|
-
}
|
|
68
|
-
: undefined,
|
|
69
|
-
donor: {
|
|
70
|
-
title: input.donor.title,
|
|
71
|
-
firstName: input.donor.firstName,
|
|
72
|
-
lastName: input.donor.lastName,
|
|
73
|
-
email: input.donor.email,
|
|
74
|
-
address: input.donor.address
|
|
75
|
-
? {
|
|
76
|
-
street: input.donor.address.streetAddress,
|
|
77
|
-
city: input.donor.address.city,
|
|
78
|
-
state: input.donor.address.state,
|
|
79
|
-
zipCode: input.donor.address.zipCode,
|
|
80
|
-
country: input.donor.address.country,
|
|
81
|
-
ukGiftAid: input.donor.ukGiftAid,
|
|
82
|
-
}
|
|
83
|
-
: undefined,
|
|
84
|
-
},
|
|
85
|
-
source: input.source,
|
|
86
|
-
tribute: input.inHonorOf
|
|
87
|
-
? {
|
|
88
|
-
fullName: input.inHonorOf,
|
|
89
|
-
notif: input.tributeNotif
|
|
90
|
-
? {
|
|
91
|
-
toEmail: input.tributeNotif.toEmail,
|
|
92
|
-
toFullName: input.tributeNotif.toFullName,
|
|
93
|
-
fromMsg: input.tributeNotif.fromMsg,
|
|
94
|
-
}
|
|
95
|
-
: undefined,
|
|
96
|
-
}
|
|
97
|
-
: undefined,
|
|
98
|
-
frequency: (input.type === "subscription"
|
|
99
|
-
? "recurring"
|
|
100
|
-
: input.type ?? "one-time") as Frequency,
|
|
101
|
-
viaName: input.chainName ?? "fiat",
|
|
102
|
-
viaId: input.chainId ? input.chainId : input.transactionId ?? "fiat",
|
|
103
|
-
}))
|
|
104
|
-
);
|