@better-giving/donation 1.0.4 → 1.0.12

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.
@@ -75,6 +75,8 @@ export declare namespace Donation {
75
75
  programName?: string;
76
76
  /** honorary full name - may be empty `""` */
77
77
  inHonorOf?: string;
78
+ /** only allowed if honoree is provided */
79
+ tributeNotif?: Donation.TributeNotif;
78
80
  transactionDate: ISODate;
79
81
  /** if tipAmount is present, value includes tipAmount */
80
82
  amount: number;
@@ -399,4 +401,6 @@ export declare namespace StripeDonation {
399
401
  productId: string;
400
402
  subsQuantity: string;
401
403
  };
404
+ /** BG accepted payment methods */
405
+ type PaymentMethods = "acss_debit" | "amazon_pay" | "bancontact" | "card" | "cashapp" | "eps" | "ideal" | "link" | "p24" | "sepa_debit" | "sofort" | "us_bank_account";
402
406
  }
@@ -1,5 +1,5 @@
1
1
  import type { Donation } from "./donation.mjs";
2
- type FinalRecord = Pick<Donation.V2DBRecord, "amount" | "appUsed" | "chainName" | "charityName" | "claimed" | "denomination" | "email" | "endowmentId" | "feeAllowance" | "fiatRamp" | "fiscalSponsored" | "inHonorOf" | "isRecurring" | "network" | "nonProfitMsg" | "paymentMethod" | "programId" | "programName" | "splitLiq" | "tipAmount" | "transactionDate" | "transactionId" | "usdValue">;
2
+ type FinalRecord = Pick<Donation.V2DBRecord, "amount" | "appUsed" | "chainName" | "charityName" | "claimed" | "denomination" | "email" | "endowmentId" | "feeAllowance" | "fiatRamp" | "fiscalSponsored" | "inHonorOf" | "isRecurring" | "network" | "nonProfitMsg" | "paymentMethod" | "programId" | "programName" | "splitLiq" | "tipAmount" | "transactionDate" | "transactionId" | "tributeNotif" | "usdValue">;
3
3
  interface SettledAmounts {
4
4
  settledFee: number;
5
5
  settledNet: number;
@@ -0,0 +1,112 @@
1
+ import * as v from "valibot";
2
+ import { type Frequency } from "./intent.mjs";
3
+ export declare const oldIntent: v.SchemaWithPipe<[v.ObjectSchema<{
4
+ readonly transactionId: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
5
+ readonly type: v.OptionalSchema<v.PicklistSchema<["one-time", "subscription"], undefined>, never>;
6
+ readonly amount: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
7
+ readonly tipAmount: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
8
+ readonly feeAllowance: v.SchemaWithPipe<[v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
9
+ readonly currency: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
10
+ readonly endowmentId: v.SchemaWithPipe<[v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, v.MinValueAction<number, 1, undefined>]>;
11
+ readonly programId: v.OptionalSchema<v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.UuidAction<string, undefined>]>, never>;
12
+ readonly programName: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
13
+ readonly splitLiq: v.SchemaWithPipe<[v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 100, undefined>]>;
14
+ readonly donor: v.ObjectSchema<{
15
+ readonly title: v.PicklistSchema<readonly ["Mr", "Mrs", "Ms", "Mx", ""], undefined>;
16
+ readonly firstName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
17
+ readonly lastName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
18
+ readonly email: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.EmailAction<string, undefined>]>;
19
+ readonly address: v.OptionalSchema<v.ObjectSchema<{
20
+ readonly streetAddress: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
21
+ readonly city: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
22
+ readonly state: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>;
23
+ readonly zipCode: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
24
+ /** country name */
25
+ readonly country: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
26
+ }, undefined>, never>;
27
+ readonly ukGiftAid: v.OptionalSchema<v.BooleanSchema<undefined>, never>;
28
+ }, undefined>;
29
+ readonly inHonorOf: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
30
+ readonly tributeNotif: v.OptionalSchema<v.ObjectSchema<{
31
+ readonly toEmail: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.EmailAction<string, undefined>]>;
32
+ readonly toFullName: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.NonEmptyAction<string, undefined>]>;
33
+ readonly fromMsg: v.SchemaWithPipe<[v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, v.MaxLengthAction<string, 250, undefined>]>;
34
+ }, undefined>, never>;
35
+ readonly source: v.PicklistSchema<readonly ["bg-marketplace", "bg-widget", "tester-app"], undefined>;
36
+ readonly denomination: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
37
+ readonly chainId: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
38
+ readonly chainName: v.OptionalSchema<v.SchemaWithPipe<[v.StringSchema<undefined>, v.TrimAction]>, never>;
39
+ }, undefined>, v.TransformAction<{
40
+ amount: number;
41
+ feeAllowance: number;
42
+ tipAmount: number;
43
+ splitLiq: number;
44
+ endowmentId: number;
45
+ donor: {
46
+ email: string;
47
+ title: "" | "Mr" | "Ms" | "Mrs" | "Mx";
48
+ firstName: string;
49
+ lastName: string;
50
+ ukGiftAid?: boolean | undefined;
51
+ address?: {
52
+ streetAddress: string;
53
+ city: string;
54
+ state: string;
55
+ zipCode: string;
56
+ country: string;
57
+ } | undefined;
58
+ };
59
+ source: "bg-marketplace" | "bg-widget" | "tester-app";
60
+ chainId?: string | undefined;
61
+ programId?: string | undefined;
62
+ programName?: string | undefined;
63
+ inHonorOf?: string | undefined;
64
+ tributeNotif?: {
65
+ toEmail: string;
66
+ toFullName: string;
67
+ fromMsg: string;
68
+ } | undefined;
69
+ denomination?: string | undefined;
70
+ chainName?: string | undefined;
71
+ transactionId?: string | undefined;
72
+ type?: "one-time" | "subscription" | undefined;
73
+ currency?: string | undefined;
74
+ }, {
75
+ amount: {
76
+ amount: number;
77
+ currency: string;
78
+ tip: number;
79
+ feeAllowance: number;
80
+ };
81
+ recipient: number;
82
+ program: {
83
+ id: string;
84
+ name: string;
85
+ } | undefined;
86
+ donor: {
87
+ title: "" | "Mr" | "Ms" | "Mrs" | "Mx";
88
+ firstName: string;
89
+ lastName: string;
90
+ email: string;
91
+ address: {
92
+ street: string;
93
+ city: string;
94
+ state: string;
95
+ zipCode: string;
96
+ country: string;
97
+ ukGiftAid: boolean | undefined;
98
+ } | undefined;
99
+ };
100
+ source: "bg-marketplace" | "bg-widget" | "tester-app";
101
+ tribute: {
102
+ fullName: string;
103
+ notif: {
104
+ toEmail: string;
105
+ toFullName: string;
106
+ fromMsg: string;
107
+ } | undefined;
108
+ } | undefined;
109
+ frequency: Frequency;
110
+ viaName: string;
111
+ viaId: string;
112
+ }>]>;
@@ -0,0 +1,89 @@
1
+ import * as v from "valibot";
2
+ import { donationSource, donorTitle, tributeNotif, uuid, } from "./intent.mjs";
3
+ const str = v.pipe(v.string(), v.trim());
4
+ const requiredStr = v.pipe(str, v.nonEmpty());
5
+ const int = v.pipe(v.number(), v.integer());
6
+ const money = v.pipe(v.number(), v.minValue(0));
7
+ const donorAddress = v.object({
8
+ streetAddress: requiredStr,
9
+ city: str,
10
+ state: str,
11
+ zipCode: requiredStr,
12
+ /** country name */
13
+ country: requiredStr,
14
+ });
15
+ const donor = v.object({
16
+ title: donorTitle,
17
+ firstName: requiredStr,
18
+ lastName: requiredStr,
19
+ email: v.pipe(str, v.email()),
20
+ address: v.optional(donorAddress),
21
+ ukGiftAid: v.optional(v.boolean()),
22
+ });
23
+ export const oldIntent = v.pipe(v.object({
24
+ transactionId: v.optional(str),
25
+ type: v.optional(v.picklist(["one-time", "subscription"])),
26
+ amount: money,
27
+ tipAmount: money,
28
+ feeAllowance: money,
29
+ currency: v.optional(str),
30
+ endowmentId: v.pipe(int, v.minValue(1)),
31
+ programId: v.optional(uuid),
32
+ programName: v.optional(str),
33
+ splitLiq: v.pipe(int, v.minValue(0), v.maxValue(100)),
34
+ donor,
35
+ inHonorOf: v.optional(str),
36
+ tributeNotif: v.optional(tributeNotif),
37
+ source: donationSource,
38
+ denomination: v.optional(str),
39
+ chainId: v.optional(str),
40
+ chainName: v.optional(str),
41
+ }), v.transform((input) => ({
42
+ amount: {
43
+ amount: input.amount,
44
+ currency: input.currency ? input.currency : input.denomination ?? "",
45
+ tip: input.tipAmount,
46
+ feeAllowance: input.feeAllowance,
47
+ },
48
+ recipient: input.endowmentId,
49
+ program: input.programId && input.programName
50
+ ? {
51
+ id: input.programId,
52
+ name: input.programName,
53
+ }
54
+ : undefined,
55
+ donor: {
56
+ title: input.donor.title,
57
+ firstName: input.donor.firstName,
58
+ lastName: input.donor.lastName,
59
+ email: input.donor.email,
60
+ address: input.donor.address
61
+ ? {
62
+ street: input.donor.address.streetAddress,
63
+ city: input.donor.address.city,
64
+ state: input.donor.address.state,
65
+ zipCode: input.donor.address.zipCode,
66
+ country: input.donor.address.country,
67
+ ukGiftAid: input.donor.ukGiftAid,
68
+ }
69
+ : undefined,
70
+ },
71
+ source: input.source,
72
+ tribute: input.inHonorOf
73
+ ? {
74
+ fullName: input.inHonorOf,
75
+ notif: input.tributeNotif
76
+ ? {
77
+ toEmail: input.tributeNotif.toEmail,
78
+ toFullName: input.tributeNotif.toFullName,
79
+ fromMsg: input.tributeNotif.fromMsg,
80
+ }
81
+ : undefined,
82
+ }
83
+ : undefined,
84
+ frequency: (input.type === "subscription"
85
+ ? "recurring"
86
+ : input.type ?? "one-time"),
87
+ viaName: input.chainName ?? "fiat",
88
+ viaId: input.chainId ? input.chainId : input.transactionId ?? "fiat",
89
+ })));
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@better-giving/donation",
3
- "version": "1.0.4",
3
+ "version": "1.0.12",
4
4
  "devDependencies": {
5
5
  "@better-giving/config": "workspace:*"
6
6
  },
7
7
  "peerDependencies": {
8
- "@better-giving/types": "1.0.3",
8
+ "@better-giving/types": "1.0.5",
9
9
  "valibot": "0.42.0"
10
10
  },
11
11
  "files": [
package/src/donation.mts CHANGED
@@ -113,6 +113,8 @@ export declare namespace Donation {
113
113
  programName?: string;
114
114
  /** honorary full name - may be empty `""` */
115
115
  inHonorOf?: string;
116
+ /** only allowed if honoree is provided */
117
+ tributeNotif?: Donation.TributeNotif;
116
118
  transactionDate: ISODate;
117
119
  /** if tipAmount is present, value includes tipAmount */
118
120
  amount: number;
@@ -534,4 +536,19 @@ export declare namespace StripeDonation {
534
536
  productId: string;
535
537
  subsQuantity: string;
536
538
  };
539
+
540
+ /** BG accepted payment methods */
541
+ type PaymentMethods =
542
+ | "acss_debit"
543
+ | "amazon_pay"
544
+ | "bancontact"
545
+ | "card"
546
+ | "cashapp"
547
+ | "eps"
548
+ | "ideal"
549
+ | "link"
550
+ | "p24"
551
+ | "sepa_debit"
552
+ | "sofort"
553
+ | "us_bank_account";
537
554
  }
@@ -24,6 +24,7 @@ type FinalRecord = Pick<
24
24
  | "tipAmount"
25
25
  | "transactionDate"
26
26
  | "transactionId"
27
+ | "tributeNotif"
27
28
  | "usdValue"
28
29
  >;
29
30
 
@@ -0,0 +1,104 @@
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
+ );