@better-giving/fundraiser 6.0.0 → 7.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/db.d.mts +9 -2
- package/dist/db.mjs +16 -0
- package/dist/interfaces.d.mts +10 -3
- package/package.json +1 -1
- package/src/db.mts +21 -1
- package/src/interfaces.mts +9 -3
package/dist/db.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Db, type TxType } from "@better-giving/db";
|
|
2
|
-
import type { IFund } from "./interfaces.mjs";
|
|
2
|
+
import type { IFund, IFundsPageOpts } from "./interfaces.mjs";
|
|
3
3
|
import type { IFundUpdate } from "./schema.mjs";
|
|
4
4
|
export declare class FundDb extends Db {
|
|
5
5
|
static readonly table = "funds";
|
|
@@ -8,6 +8,10 @@ export declare class FundDb extends Db {
|
|
|
8
8
|
readonly PK: `Fund#${string}`;
|
|
9
9
|
readonly SK: `Fund#${string}`;
|
|
10
10
|
};
|
|
11
|
+
gsi1_funds_key(date_created: string): {
|
|
12
|
+
readonly gsi1PK: "Funds#staging" | "Funds#production";
|
|
13
|
+
readonly gsi1SK: string;
|
|
14
|
+
};
|
|
11
15
|
fund_record(data: IFund): {
|
|
12
16
|
readonly name: string;
|
|
13
17
|
readonly description: string;
|
|
@@ -26,7 +30,7 @@ export declare class FundDb extends Db {
|
|
|
26
30
|
readonly slug?: string | undefined;
|
|
27
31
|
readonly id: string;
|
|
28
32
|
readonly spam_score?: number;
|
|
29
|
-
readonly
|
|
33
|
+
readonly created_at?: string;
|
|
30
34
|
readonly env: import("@better-giving/schemas").Environment;
|
|
31
35
|
readonly active: boolean;
|
|
32
36
|
readonly verified: boolean;
|
|
@@ -34,6 +38,8 @@ export declare class FundDb extends Db {
|
|
|
34
38
|
readonly settings: import("./interfaces.mjs").IFundSettings;
|
|
35
39
|
readonly creator_id: string;
|
|
36
40
|
readonly creator_name: string;
|
|
41
|
+
readonly gsi1PK?: "Funds#staging" | "Funds#production" | undefined;
|
|
42
|
+
readonly gsi1SK?: string | undefined;
|
|
37
43
|
readonly PK: `Fund#${string}`;
|
|
38
44
|
readonly SK: `Fund#${string}`;
|
|
39
45
|
};
|
|
@@ -41,6 +47,7 @@ export declare class FundDb extends Db {
|
|
|
41
47
|
/**@param id - slug or uuid */
|
|
42
48
|
fund(id: string): Promise<IFund | undefined>;
|
|
43
49
|
funds_get(ids: string[]): Promise<IFund[]>;
|
|
50
|
+
funds(opts: IFundsPageOpts): Promise<import("@better-giving/types/api").IPageKeyed<IFund>>;
|
|
44
51
|
fund_update(id: string, { target, slug, ...update }: IFundUpdate): Promise<Record<string, any>>;
|
|
45
52
|
fund_contrib_update_txi(id: string, amount: number): TxType["Update"];
|
|
46
53
|
fund_close(fund: string): Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
|
package/dist/db.mjs
CHANGED
|
@@ -7,9 +7,13 @@ export class FundDb extends Db {
|
|
|
7
7
|
key_fund(id) {
|
|
8
8
|
return { PK: `Fund#${id}`, SK: `Fund#${id}` };
|
|
9
9
|
}
|
|
10
|
+
gsi1_funds_key(date_created) {
|
|
11
|
+
return { gsi1PK: `Funds#${this.env}`, gsi1SK: date_created };
|
|
12
|
+
}
|
|
10
13
|
fund_record(data) {
|
|
11
14
|
return {
|
|
12
15
|
...this.key_fund(data.id),
|
|
16
|
+
...(data.created_at && this.gsi1_funds_key(data.created_at)),
|
|
13
17
|
...data,
|
|
14
18
|
};
|
|
15
19
|
}
|
|
@@ -58,6 +62,18 @@ export class FundDb extends Db {
|
|
|
58
62
|
const x = Responses?.[FundDb.table] ?? [];
|
|
59
63
|
return x.map((i) => this.sans_keys(i));
|
|
60
64
|
}
|
|
65
|
+
async funds(opts) {
|
|
66
|
+
const cmd = new QueryCommand({
|
|
67
|
+
TableName: FundDb.table,
|
|
68
|
+
Limit: opts.limit ?? 10,
|
|
69
|
+
ExclusiveStartKey: this.key_to_obj(opts.next),
|
|
70
|
+
IndexName: "gsi1",
|
|
71
|
+
KeyConditionExpression: "gsi1PK = :pk",
|
|
72
|
+
ScanIndexForward: false,
|
|
73
|
+
ExpressionAttributeValues: { ":pk": `Funds#${this.env}` },
|
|
74
|
+
});
|
|
75
|
+
return this.client.send(cmd).then((this.to_page));
|
|
76
|
+
}
|
|
61
77
|
async fund_update(id, { target, slug, ...update }) {
|
|
62
78
|
const updates = new UpdateBuilder();
|
|
63
79
|
if (slug)
|
package/dist/interfaces.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DonateMethodId, Environment } from "@better-giving/schemas";
|
|
2
|
-
import type { IPageNumbered } from "@better-giving/types/api";
|
|
2
|
+
import type { IPageKeyed, IPageNumbered } from "@better-giving/types/api";
|
|
3
3
|
import type { IFundNew } from "./schema.mjs";
|
|
4
4
|
export interface IFundSettings {
|
|
5
5
|
hide_bg_tip: boolean;
|
|
@@ -14,7 +14,7 @@ export interface IFundInternal extends IFundCreator {
|
|
|
14
14
|
/** uuid */
|
|
15
15
|
id: string;
|
|
16
16
|
spam_score?: number;
|
|
17
|
-
|
|
17
|
+
created_at?: string;
|
|
18
18
|
env: Environment;
|
|
19
19
|
/** fund can be closed before expiration */
|
|
20
20
|
active: boolean;
|
|
@@ -25,10 +25,17 @@ export interface IFundInternal extends IFundCreator {
|
|
|
25
25
|
}
|
|
26
26
|
export interface IFund extends IFundNew, IFundInternal {
|
|
27
27
|
}
|
|
28
|
+
/** typesense record */
|
|
28
29
|
export interface IFundItem extends Pick<IFundNew, "name" | "description" | "logo" | "banner" | "featured" | "members" | "target">, Pick<IFundInternal, "id" | "env" | "active" | "verified" | "donation_total_usd" | "creator_id" | "creator_name"> {
|
|
29
30
|
/** Unix timestamp @default - 253402300799 */
|
|
30
31
|
expiration: number;
|
|
31
32
|
members_csv: string;
|
|
32
33
|
}
|
|
33
|
-
export interface
|
|
34
|
+
export interface IFundItemsPage extends IPageNumbered<IFundItemsPage> {
|
|
35
|
+
}
|
|
36
|
+
export interface IFundsPageOpts {
|
|
37
|
+
limit?: number;
|
|
38
|
+
next?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface IFundsPage extends IPageKeyed<IFund> {
|
|
34
41
|
}
|
package/package.json
CHANGED
package/src/db.mts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
UpdateBuilder,
|
|
12
12
|
} from "@better-giving/db";
|
|
13
13
|
import { UUID_REGEX } from "valibot";
|
|
14
|
-
import type { IFund } from "./interfaces.mjs";
|
|
14
|
+
import type { IFund, IFundsPageOpts } from "./interfaces.mjs";
|
|
15
15
|
import type { IFundUpdate } from "./schema.mjs";
|
|
16
16
|
|
|
17
17
|
export class FundDb extends Db {
|
|
@@ -20,12 +20,19 @@ export class FundDb extends Db {
|
|
|
20
20
|
key_fund(id: string) {
|
|
21
21
|
return { PK: `Fund#${id}`, SK: `Fund#${id}` } as const;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
gsi1_funds_key(date_created: string) {
|
|
25
|
+
return { gsi1PK: `Funds#${this.env}`, gsi1SK: date_created } as const;
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
fund_record(data: IFund) {
|
|
24
29
|
return {
|
|
25
30
|
...this.key_fund(data.id),
|
|
31
|
+
...(data.created_at && this.gsi1_funds_key(data.created_at)),
|
|
26
32
|
...data,
|
|
27
33
|
} as const;
|
|
28
34
|
}
|
|
35
|
+
|
|
29
36
|
fund_put_txi(data: IFund): TxType["Put"] {
|
|
30
37
|
return {
|
|
31
38
|
TableName: FundDb.table,
|
|
@@ -71,6 +78,19 @@ export class FundDb extends Db {
|
|
|
71
78
|
return x.map((i) => this.sans_keys(i));
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
async funds(opts: IFundsPageOpts) {
|
|
82
|
+
const cmd = new QueryCommand({
|
|
83
|
+
TableName: FundDb.table,
|
|
84
|
+
Limit: opts.limit ?? 10,
|
|
85
|
+
ExclusiveStartKey: this.key_to_obj(opts.next),
|
|
86
|
+
IndexName: "gsi1",
|
|
87
|
+
KeyConditionExpression: "gsi1PK = :pk",
|
|
88
|
+
ScanIndexForward: false,
|
|
89
|
+
ExpressionAttributeValues: { ":pk": `Funds#${this.env}` },
|
|
90
|
+
});
|
|
91
|
+
return this.client.send(cmd).then(this.to_page<IFund>);
|
|
92
|
+
}
|
|
93
|
+
|
|
74
94
|
async fund_update(id: string, { target, slug, ...update }: IFundUpdate) {
|
|
75
95
|
const updates = new UpdateBuilder();
|
|
76
96
|
|
package/src/interfaces.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DonateMethodId, Environment } from "@better-giving/schemas";
|
|
2
|
-
import type { IPageNumbered } from "@better-giving/types/api";
|
|
2
|
+
import type { IPageKeyed, IPageNumbered } from "@better-giving/types/api";
|
|
3
3
|
import type { IFundNew } from "./schema.mjs";
|
|
4
4
|
|
|
5
5
|
export interface IFundSettings {
|
|
@@ -17,7 +17,7 @@ export interface IFundInternal extends IFundCreator {
|
|
|
17
17
|
/** uuid */
|
|
18
18
|
id: string;
|
|
19
19
|
spam_score?: number;
|
|
20
|
-
|
|
20
|
+
created_at?: string;
|
|
21
21
|
env: Environment;
|
|
22
22
|
/** fund can be closed before expiration */
|
|
23
23
|
active: boolean;
|
|
@@ -29,6 +29,7 @@ export interface IFundInternal extends IFundCreator {
|
|
|
29
29
|
|
|
30
30
|
export interface IFund extends IFundNew, IFundInternal {}
|
|
31
31
|
|
|
32
|
+
/** typesense record */
|
|
32
33
|
export interface IFundItem
|
|
33
34
|
extends Pick<
|
|
34
35
|
IFundNew,
|
|
@@ -55,4 +56,9 @@ export interface IFundItem
|
|
|
55
56
|
members_csv: string;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export interface
|
|
59
|
+
export interface IFundItemsPage extends IPageNumbered<IFundItemsPage> {}
|
|
60
|
+
export interface IFundsPageOpts {
|
|
61
|
+
limit?: number;
|
|
62
|
+
next?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface IFundsPage extends IPageKeyed<IFund> {}
|