@better-giving/donation 1.1.20 → 2.0.1
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 +5 -4
- package/dist/schema.d.mts +20 -0
- package/dist/schema.mjs +17 -0
- package/package.json +2 -2
- package/src/donation.mts +5 -5
- package/src/schema.mts +34 -0
- package/src/intent.mts +0 -111
package/dist/donation.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ISODate } from "@better-giving/types/alias";
|
|
2
2
|
import type { ChainID, Environment } from "@better-giving/types/list";
|
|
3
3
|
import type { EmptyObject, OrStr } from "@better-giving/types/utils";
|
|
4
|
+
import type { Allocation, DonorTitle, Frequency } from "./schema.mjs";
|
|
4
5
|
export declare namespace Donation {
|
|
5
6
|
type Index = "AppUsed_Index" | "Checked-8283_Index" | "Email_Index" | "EndowmentId_Index" | "FundDeposits_Index" | "Tax-Receipt-Sent_Index" | "Network-FinalizedDate_Index" | "WalletAddress_Index" | "Referrer-FinalizedDate_index";
|
|
6
7
|
type App = "aging" | "angel-protocol" | "bg-marketplace" | "bg-widget" | "black-history-month" | "make-whole" | "mental-health" | "restore-earth" | "tester-app" | "ukraine-portal";
|
|
@@ -53,7 +54,6 @@ export declare namespace Donation {
|
|
|
53
54
|
type WalletAddress_Index = {
|
|
54
55
|
walletAddress?: string;
|
|
55
56
|
};
|
|
56
|
-
type DonorTitle = "Mr" | "Ms" | "Mrs" | "Mx";
|
|
57
57
|
type DonorBasicInfo = {
|
|
58
58
|
/** may be empty */
|
|
59
59
|
title?: DonorTitle;
|
|
@@ -136,6 +136,7 @@ export declare namespace Donation {
|
|
|
136
136
|
fund_name?: string;
|
|
137
137
|
fund_tx?: string;
|
|
138
138
|
company_name?: string;
|
|
139
|
+
allocation?: Allocation;
|
|
139
140
|
};
|
|
140
141
|
type NonKeyAttributes = {
|
|
141
142
|
addressComplement?: " ";
|
|
@@ -272,6 +273,7 @@ export declare namespace OnHoldDonation {
|
|
|
272
273
|
msg_to_npo?: string;
|
|
273
274
|
donor_public?: boolean;
|
|
274
275
|
company_name?: string;
|
|
276
|
+
allocation?: Allocation;
|
|
275
277
|
} & (ApesAttributes | EmptyObject) & (Donation.WithKYC | Donation.WithoutKYC);
|
|
276
278
|
type CryptoDBRecord = PrimaryKey & NonKeyAttributes & CryptoAttributes & Donation.EmailIndexKey;
|
|
277
279
|
type FiatDBRecord = PrimaryKey & Required<Donation.FiatRamp_IndexKey> & NonKeyAttributes & FiatAttributes & Required<Donation.EmailIndexKey>;
|
|
@@ -286,7 +288,6 @@ export declare namespace FiatDonations {
|
|
|
286
288
|
rate: number;
|
|
287
289
|
timestamp: string;
|
|
288
290
|
};
|
|
289
|
-
type Frequency = "one-time" | "subscription";
|
|
290
291
|
}
|
|
291
292
|
export declare namespace PayPalDonation {
|
|
292
293
|
type CreateOrder = {
|
|
@@ -356,7 +357,7 @@ export declare namespace StripeDonation {
|
|
|
356
357
|
/** DEPRECATED - can be removed eventually as existing records will eventually "expire" */
|
|
357
358
|
type LegacyMetadata = {
|
|
358
359
|
/** This attr will help in identifying PaymentIntents made for one-time donations only */
|
|
359
|
-
donation_type: Extract<
|
|
360
|
+
donation_type: Extract<Frequency, "one-time">;
|
|
360
361
|
/** This attr will link the received webhook event to a donation intent */
|
|
361
362
|
intent_tx_id: string;
|
|
362
363
|
};
|
|
@@ -367,7 +368,7 @@ export declare namespace StripeDonation {
|
|
|
367
368
|
type Metadata = {
|
|
368
369
|
[K in keyof OnHoldDonation.FiatDBRecord]: string;
|
|
369
370
|
} & {
|
|
370
|
-
title?:
|
|
371
|
+
title?: DonorTitle;
|
|
371
372
|
fullName: string;
|
|
372
373
|
ukGiftAid: string;
|
|
373
374
|
streetAddress?: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export declare const frequencies: readonly ["one-time", "recurring"];
|
|
3
|
+
export declare const frequency: v.PicklistSchema<readonly ["one-time", "recurring"], "Please select donation frequency">;
|
|
4
|
+
export type Frequency = v.InferOutput<typeof frequency>;
|
|
5
|
+
export declare const donation_sources: readonly ["bg-marketplace", "bg-widget", "tester-app"];
|
|
6
|
+
export declare const donation_source: v.PicklistSchema<readonly ["bg-marketplace", "bg-widget", "tester-app"], undefined>;
|
|
7
|
+
export type DonationSource = v.InferOutput<typeof donation_source>;
|
|
8
|
+
export declare const donor_titles: readonly ["Mr", "Mrs", "Ms", "Mx", ""];
|
|
9
|
+
export declare const donor_title: v.PicklistSchema<readonly ["Mr", "Mrs", "Ms", "Mx", ""], undefined>;
|
|
10
|
+
export type DonorTitle = v.InferOutput<typeof donor_title>;
|
|
11
|
+
export declare const allocation: v.SchemaWithPipe<[v.ObjectSchema<{
|
|
12
|
+
readonly liq: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
|
|
13
|
+
readonly lock: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
|
|
14
|
+
readonly cash: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
|
|
15
|
+
}, undefined>, v.CheckAction<{
|
|
16
|
+
liq: number;
|
|
17
|
+
lock: number;
|
|
18
|
+
cash: number;
|
|
19
|
+
}, "Allocation must sum to 100%">]>;
|
|
20
|
+
export type Allocation = v.InferOutput<typeof allocation>;
|
package/dist/schema.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export const frequencies = ["one-time", "recurring"];
|
|
3
|
+
export const frequency = v.picklist(frequencies, "Please select donation frequency");
|
|
4
|
+
export const donation_sources = [
|
|
5
|
+
"bg-marketplace",
|
|
6
|
+
"bg-widget",
|
|
7
|
+
"tester-app",
|
|
8
|
+
];
|
|
9
|
+
export const donation_source = v.picklist(donation_sources);
|
|
10
|
+
export const donor_titles = ["Mr", "Mrs", "Ms", "Mx", ""];
|
|
11
|
+
export const donor_title = v.picklist(donor_titles);
|
|
12
|
+
const pct = v.pipe(v.number(), v.minValue(0), v.maxValue(100));
|
|
13
|
+
export const allocation = v.pipe(v.object({
|
|
14
|
+
liq: pct,
|
|
15
|
+
lock: pct,
|
|
16
|
+
cash: pct,
|
|
17
|
+
}), v.check((x) => x.liq + x.lock + x.cash === 100, "Allocation must sum to 100%"));
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-giving/donation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@better-giving/config": "1.1.2"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"@better-giving/types": "1.1.7",
|
|
9
|
-
"@better-giving/schemas": "1.
|
|
9
|
+
"@better-giving/schemas": "1.2.0",
|
|
10
10
|
"valibot": "0.42.0"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
package/src/donation.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ISODate } from "@better-giving/types/alias";
|
|
2
2
|
import type { ChainID, Environment } from "@better-giving/types/list";
|
|
3
3
|
import type { EmptyObject, OrStr } from "@better-giving/types/utils";
|
|
4
|
+
import type { Allocation, DonorTitle, Frequency } from "./schema.mjs";
|
|
4
5
|
|
|
5
6
|
export declare namespace Donation {
|
|
6
7
|
type Index =
|
|
@@ -91,7 +92,6 @@ export declare namespace Donation {
|
|
|
91
92
|
walletAddress?: string; //PK
|
|
92
93
|
};
|
|
93
94
|
|
|
94
|
-
type DonorTitle = "Mr" | "Ms" | "Mrs" | "Mx";
|
|
95
95
|
type DonorBasicInfo = {
|
|
96
96
|
/** may be empty */
|
|
97
97
|
title?: DonorTitle;
|
|
@@ -186,6 +186,7 @@ export declare namespace Donation {
|
|
|
186
186
|
fund_tx?: string;
|
|
187
187
|
|
|
188
188
|
company_name?: string;
|
|
189
|
+
allocation?: Allocation;
|
|
189
190
|
};
|
|
190
191
|
|
|
191
192
|
type NonKeyAttributes = {
|
|
@@ -375,6 +376,7 @@ export declare namespace OnHoldDonation {
|
|
|
375
376
|
msg_to_npo?: string;
|
|
376
377
|
donor_public?: boolean;
|
|
377
378
|
company_name?: string;
|
|
379
|
+
allocation?: Allocation;
|
|
378
380
|
} & (ApesAttributes | EmptyObject) &
|
|
379
381
|
(Donation.WithKYC | Donation.WithoutKYC);
|
|
380
382
|
|
|
@@ -402,8 +404,6 @@ export declare namespace FiatDonations {
|
|
|
402
404
|
rate: number;
|
|
403
405
|
timestamp: string;
|
|
404
406
|
};
|
|
405
|
-
|
|
406
|
-
type Frequency = "one-time" | "subscription";
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
export declare namespace PayPalDonation {
|
|
@@ -486,7 +486,7 @@ export declare namespace StripeDonation {
|
|
|
486
486
|
/** DEPRECATED - can be removed eventually as existing records will eventually "expire" */
|
|
487
487
|
type LegacyMetadata = {
|
|
488
488
|
/** This attr will help in identifying PaymentIntents made for one-time donations only */
|
|
489
|
-
donation_type: Extract<
|
|
489
|
+
donation_type: Extract<Frequency, "one-time">;
|
|
490
490
|
/** This attr will link the received webhook event to a donation intent */
|
|
491
491
|
intent_tx_id: string;
|
|
492
492
|
};
|
|
@@ -499,7 +499,7 @@ export declare namespace StripeDonation {
|
|
|
499
499
|
[K in keyof OnHoldDonation.FiatDBRecord]: string;
|
|
500
500
|
} & {
|
|
501
501
|
// KYC fields
|
|
502
|
-
title?:
|
|
502
|
+
title?: DonorTitle;
|
|
503
503
|
fullName: string;
|
|
504
504
|
ukGiftAid: string;
|
|
505
505
|
streetAddress?: string;
|
package/src/schema.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
export const frequencies = ["one-time", "recurring"] as const;
|
|
3
|
+
export const frequency = v.picklist(
|
|
4
|
+
frequencies,
|
|
5
|
+
"Please select donation frequency"
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export type Frequency = v.InferOutput<typeof frequency>;
|
|
9
|
+
|
|
10
|
+
export const donation_sources = [
|
|
11
|
+
"bg-marketplace",
|
|
12
|
+
"bg-widget",
|
|
13
|
+
"tester-app",
|
|
14
|
+
] as const;
|
|
15
|
+
|
|
16
|
+
export const donation_source = v.picklist(donation_sources);
|
|
17
|
+
export type DonationSource = v.InferOutput<typeof donation_source>;
|
|
18
|
+
|
|
19
|
+
export const donor_titles = ["Mr", "Mrs", "Ms", "Mx", ""] as const;
|
|
20
|
+
export const donor_title = v.picklist(donor_titles);
|
|
21
|
+
|
|
22
|
+
export type DonorTitle = v.InferOutput<typeof donor_title>;
|
|
23
|
+
|
|
24
|
+
const pct = v.pipe(v.number(), v.minValue(0), v.maxValue(100));
|
|
25
|
+
export const allocation = v.pipe(
|
|
26
|
+
v.object({
|
|
27
|
+
liq: pct,
|
|
28
|
+
lock: pct,
|
|
29
|
+
cash: pct,
|
|
30
|
+
}),
|
|
31
|
+
v.check((x) => x.liq + x.lock + x.cash === 100, "Allocation must sum to 100%")
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export type Allocation = v.InferOutput<typeof allocation>;
|
package/src/intent.mts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
|
|
3
|
-
const str = v.pipe(v.string(), v.trim());
|
|
4
|
-
const required_str = v.pipe(str, v.nonEmpty());
|
|
5
|
-
|
|
6
|
-
export const frequencies = ["one-time", "recurring"] as const;
|
|
7
|
-
export const frequency = v.picklist(frequencies);
|
|
8
|
-
|
|
9
|
-
export type Frequency = v.InferOutput<typeof frequency>;
|
|
10
|
-
|
|
11
|
-
export const donation_sources = [
|
|
12
|
-
"bg-marketplace",
|
|
13
|
-
"bg-widget",
|
|
14
|
-
"tester-app",
|
|
15
|
-
] as const;
|
|
16
|
-
|
|
17
|
-
export const donation_source = v.picklist(donation_sources);
|
|
18
|
-
export type DonationSource = v.InferOutput<typeof donation_source>;
|
|
19
|
-
|
|
20
|
-
export const donor_titles = ["Mr", "Mrs", "Ms", "Mx", ""] as const;
|
|
21
|
-
export const donor_title = v.picklist(donor_titles);
|
|
22
|
-
|
|
23
|
-
export type DonorTitle = v.InferOutput<typeof donor_title>;
|
|
24
|
-
|
|
25
|
-
export const donor_address = v.object({
|
|
26
|
-
street: required_str,
|
|
27
|
-
city: required_str,
|
|
28
|
-
state: v.optional(required_str),
|
|
29
|
-
zip_code: v.optional(required_str),
|
|
30
|
-
/** country name */
|
|
31
|
-
country: required_str,
|
|
32
|
-
uk_gift_aid: v.optional(v.boolean()),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export type DonorAddress = v.InferOutput<typeof donor_address>;
|
|
36
|
-
|
|
37
|
-
export const donor = v.object({
|
|
38
|
-
title: donor_title,
|
|
39
|
-
first_name: required_str,
|
|
40
|
-
company_name: v.optional(str),
|
|
41
|
-
last_name: required_str,
|
|
42
|
-
email: v.pipe(str, v.email()),
|
|
43
|
-
address: v.optional(donor_address),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export type Donor = v.InferOutput<typeof donor>;
|
|
47
|
-
|
|
48
|
-
const money = v.pipe(v.number(), v.minValue(0));
|
|
49
|
-
|
|
50
|
-
export const amount = v.object({
|
|
51
|
-
amount: money,
|
|
52
|
-
currency: v.pipe(required_str, v.toUpperCase()),
|
|
53
|
-
tip: money,
|
|
54
|
-
fee_allowance: money,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
export type Amount = v.InferOutput<typeof amount>;
|
|
58
|
-
|
|
59
|
-
export const endow_id = v.pipe(
|
|
60
|
-
str,
|
|
61
|
-
v.transform((x) => +x),
|
|
62
|
-
v.number(),
|
|
63
|
-
v.integer(),
|
|
64
|
-
v.minValue(1)
|
|
65
|
-
);
|
|
66
|
-
export const uuid = v.pipe(str, v.uuid());
|
|
67
|
-
|
|
68
|
-
export const program = v.object({
|
|
69
|
-
id: uuid,
|
|
70
|
-
name: required_str,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
export type Program = v.InferOutput<typeof program>;
|
|
74
|
-
|
|
75
|
-
export const recipient = v.union([endow_id, uuid]);
|
|
76
|
-
|
|
77
|
-
export type Recipient = v.InferOutput<typeof recipient>;
|
|
78
|
-
|
|
79
|
-
export const tribute_notif = v.object({
|
|
80
|
-
to_email: v.pipe(str, v.email()),
|
|
81
|
-
to_fullname: v.pipe(str, v.nonEmpty()),
|
|
82
|
-
from_msg: v.pipe(str, v.maxLength(250)),
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
export type TributeNotif = v.InferOutput<typeof tribute_notif>;
|
|
86
|
-
|
|
87
|
-
export const tribute = v.object({
|
|
88
|
-
full_name: required_str,
|
|
89
|
-
notif: v.optional(tribute_notif),
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
export type Tribute = v.InferOutput<typeof tribute>;
|
|
93
|
-
|
|
94
|
-
export const intent = v.object({
|
|
95
|
-
amount,
|
|
96
|
-
recipient,
|
|
97
|
-
program: v.optional(program),
|
|
98
|
-
donor,
|
|
99
|
-
donor_message: v.optional(v.pipe(required_str, v.maxLength(500))),
|
|
100
|
-
donor_public: v.optional(v.boolean()),
|
|
101
|
-
msg_to_npo: v.optional(v.pipe(required_str, v.maxLength(500))),
|
|
102
|
-
source: donation_source,
|
|
103
|
-
tribute: v.optional(tribute),
|
|
104
|
-
frequency,
|
|
105
|
-
/** chain name, etc. */
|
|
106
|
-
via_name: str,
|
|
107
|
-
/** chain id, workflow-session-id, etc. */
|
|
108
|
-
via_id: str,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
export type DonationIntent = v.InferOutput<typeof intent>;
|