@mccaskie-labs/workbench-fundraising 0.0.0-stage → 0.2.0
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/CHANGELOG.md +11 -0
- package/README.md +63 -2
- package/dist/cli.d.ts +12 -0
- package/dist/cli.js +161 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +137 -0
- package/dist/draw.d.ts +26 -0
- package/dist/draw.js +86 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +12 -0
- package/dist/fundraising.d.ts +238 -0
- package/dist/fundraising.js +495 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +15 -0
- package/dist/law.d.ts +81 -0
- package/dist/law.js +406 -0
- package/dist/migration.d.ts +4 -0
- package/dist/migration.js +902 -0
- package/dist/money.d.ts +4 -0
- package/dist/money.js +10 -0
- package/dist/starters.d.ts +22 -0
- package/dist/starters.js +13 -0
- package/dist/styles.d.ts +33 -0
- package/dist/styles.js +108 -0
- package/dist/types.d.ts +278 -0
- package/dist/types.js +5 -0
- package/dist/ui.d.ts +96 -0
- package/dist/ui.js +236 -0
- package/dist/words.d.ts +4 -0
- package/dist/words.js +250 -0
- package/package.json +55 -4
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import type { Campaign, CampaignStatus, CampaignTotals, DrawRecord, DrawWinner, FundraisingConfig, Gift, Pledge, Raffle, RaffleCheck, RaffleInput, RaffleResult, Ref, Refundable, Supporter, TicketLine, TicketOrder, TicketRefusal, WinnerContact } from "./types.ts";
|
|
2
|
+
type DbError = {
|
|
3
|
+
message?: string;
|
|
4
|
+
code?: string;
|
|
5
|
+
details?: string;
|
|
6
|
+
} | null;
|
|
7
|
+
/** The part of a Supabase client the package needs. Any supabase-js client fits; use the service client. */
|
|
8
|
+
export interface FundraisingClient {
|
|
9
|
+
rpc(fn: string, args: Record<string, unknown>): PromiseLike<{
|
|
10
|
+
data: unknown;
|
|
11
|
+
error: DbError;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface FundraisingOptions<C extends FundraisingConfig> {
|
|
15
|
+
db: FundraisingClient;
|
|
16
|
+
/** FUNDRAISING from src/fundraising.generated.ts (`npx workbench-fundraising generate`). */
|
|
17
|
+
config: C;
|
|
18
|
+
/** The clock, for tests. */
|
|
19
|
+
now?: () => Date;
|
|
20
|
+
}
|
|
21
|
+
export interface CampaignInput {
|
|
22
|
+
id?: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
title: string;
|
|
25
|
+
story?: string;
|
|
26
|
+
imageUrl?: string | null;
|
|
27
|
+
/** null or left out: no goal. */
|
|
28
|
+
goalCents?: number | null;
|
|
29
|
+
startsAt?: Date | string | null;
|
|
30
|
+
endsAt?: Date | string | null;
|
|
31
|
+
/** Who made or changed it: the admin's id or email. */
|
|
32
|
+
by: string;
|
|
33
|
+
}
|
|
34
|
+
export type GiftRefusal = {
|
|
35
|
+
ok: false;
|
|
36
|
+
reason: "not_live" | "too_small" | "too_big" | "no_monthly";
|
|
37
|
+
min_cents?: number;
|
|
38
|
+
max_cents?: number;
|
|
39
|
+
};
|
|
40
|
+
export interface StartedGift {
|
|
41
|
+
ok: true;
|
|
42
|
+
pledge: Pledge;
|
|
43
|
+
/** Pass to payments.payChosen({ source }) or payments.subscribe({ source, gift: true }). */
|
|
44
|
+
source: {
|
|
45
|
+
type: "gift";
|
|
46
|
+
id: string;
|
|
47
|
+
};
|
|
48
|
+
/** What the receipt's line says: "Gift to the roof appeal". */
|
|
49
|
+
label: string;
|
|
50
|
+
}
|
|
51
|
+
export interface HeldTickets {
|
|
52
|
+
ok: true;
|
|
53
|
+
order: TicketOrder;
|
|
54
|
+
/** The invoice line for payments.createInvoice(). */
|
|
55
|
+
line: TicketLine;
|
|
56
|
+
/** Pass as the invoice's source, so handlePayment() finds the order. */
|
|
57
|
+
source: {
|
|
58
|
+
type: "raffle_order";
|
|
59
|
+
id: string;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** A payments webhook outcome, as handlePayment() reads it (any workbench-payments WebhookOutcome fits). */
|
|
63
|
+
export interface PaymentOutcome {
|
|
64
|
+
kind: string;
|
|
65
|
+
invoice?: {
|
|
66
|
+
source?: {
|
|
67
|
+
type: string;
|
|
68
|
+
id: string;
|
|
69
|
+
} | null;
|
|
70
|
+
} | null;
|
|
71
|
+
payment?: {
|
|
72
|
+
id: string;
|
|
73
|
+
amount_cents: number;
|
|
74
|
+
} | null;
|
|
75
|
+
subscription?: {
|
|
76
|
+
id: string;
|
|
77
|
+
source?: Ref | null;
|
|
78
|
+
} | null;
|
|
79
|
+
}
|
|
80
|
+
/** What handlePayment() did, for the app to act on. */
|
|
81
|
+
export type Handled = {
|
|
82
|
+
kind: "gift";
|
|
83
|
+
gift: Gift;
|
|
84
|
+
first: boolean;
|
|
85
|
+
} | {
|
|
86
|
+
kind: "gift_ended";
|
|
87
|
+
pledge_id: string;
|
|
88
|
+
} | {
|
|
89
|
+
kind: "tickets";
|
|
90
|
+
order: TicketOrder;
|
|
91
|
+
}
|
|
92
|
+
/** Paid after the raffle was drawn or cancelled, or sold out: refund this payment with payments.refund(). */
|
|
93
|
+
| {
|
|
94
|
+
kind: "refund_tickets";
|
|
95
|
+
order_ref: string;
|
|
96
|
+
payment_ref: string;
|
|
97
|
+
amount_cents: number;
|
|
98
|
+
} | {
|
|
99
|
+
kind: "tickets_released";
|
|
100
|
+
order_ref: string;
|
|
101
|
+
} | {
|
|
102
|
+
kind: "ignored";
|
|
103
|
+
};
|
|
104
|
+
export interface Fundraising {
|
|
105
|
+
readonly config: FundraisingConfig;
|
|
106
|
+
saveCampaign(c: CampaignInput): Promise<Campaign>;
|
|
107
|
+
/** draft → live → closed. A closed campaign takes no new gifts. */
|
|
108
|
+
setCampaignStatus(id: string, status: CampaignStatus, by: string): Promise<Campaign>;
|
|
109
|
+
campaign(idOrSlug: string): Promise<Campaign | null>;
|
|
110
|
+
campaigns(status?: CampaignStatus): Promise<Campaign[]>;
|
|
111
|
+
/** What's been raised: confirmed gifts, cash and paid raffle tickets, less refunds. */
|
|
112
|
+
totals(campaignId: string): Promise<CampaignTotals>;
|
|
113
|
+
/** Givers who ticked the box to show their name, newest first. Never amounts. */
|
|
114
|
+
supporters(campaignId: string, limit?: number): Promise<Supporter[]>;
|
|
115
|
+
/**
|
|
116
|
+
* What a giver chose, before paying. The name shows only when showName is
|
|
117
|
+
* true (and gifts.show_names is "ask"). Answers the source and label to pay
|
|
118
|
+
* with; nothing counts until handlePayment() sees the payment.
|
|
119
|
+
*/
|
|
120
|
+
startGift(campaignId: string, o: {
|
|
121
|
+
amountCents: number;
|
|
122
|
+
monthly?: boolean;
|
|
123
|
+
showName?: boolean;
|
|
124
|
+
name?: string;
|
|
125
|
+
message?: string;
|
|
126
|
+
supporter?: Ref;
|
|
127
|
+
}): Promise<StartedGift | GiftRefusal>;
|
|
128
|
+
/** Records one confirmed payment (handlePayment does this for you). The same paymentRef again is a no-op. */
|
|
129
|
+
recordGift(o: {
|
|
130
|
+
pledgeId: string;
|
|
131
|
+
paymentRef: string;
|
|
132
|
+
amountCents: number;
|
|
133
|
+
}): Promise<Gift>;
|
|
134
|
+
/** A refunded gift stops counting. */
|
|
135
|
+
refundGift(paymentRef: string): Promise<{
|
|
136
|
+
refunded: boolean;
|
|
137
|
+
repeat: boolean;
|
|
138
|
+
}>;
|
|
139
|
+
endMonthlyGift(pledgeId: string): Promise<boolean>;
|
|
140
|
+
/** Cash or a cheque the owner counted. key makes it count once (the banking slip's number). */
|
|
141
|
+
addCash(campaignId: string, o: {
|
|
142
|
+
key: string;
|
|
143
|
+
amountCents: number;
|
|
144
|
+
note?: string;
|
|
145
|
+
by: string;
|
|
146
|
+
}): Promise<Gift>;
|
|
147
|
+
/** Checks a raffle against its place's law (docs/raffles.md). */
|
|
148
|
+
checkRaffle(r: RaffleInput): RaffleCheck;
|
|
149
|
+
/** Saves a draft raffle, whatever the check says, and answers the check for the owner's page. */
|
|
150
|
+
saveRaffle(r: RaffleInput, by: string): Promise<{
|
|
151
|
+
raffle: Raffle;
|
|
152
|
+
check: RaffleCheck;
|
|
153
|
+
}>;
|
|
154
|
+
/** Opens a draft for sale. Throws not_allowed, naming every problem, when the law check refuses it. */
|
|
155
|
+
openRaffle(id: string, by: string): Promise<{
|
|
156
|
+
raffle: Raffle;
|
|
157
|
+
check: RaffleCheck;
|
|
158
|
+
}>;
|
|
159
|
+
/** Ends sales early. tick() closes a raffle when its sales end anyway. */
|
|
160
|
+
closeSales(id: string, by: string): Promise<Raffle>;
|
|
161
|
+
/** Cancels a raffle before its draw, and answers the paid orders to refund (then call voidTickets for each). */
|
|
162
|
+
cancelRaffle(id: string, o: {
|
|
163
|
+
reason: string;
|
|
164
|
+
by: string;
|
|
165
|
+
}): Promise<{
|
|
166
|
+
raffle: Raffle;
|
|
167
|
+
refunds: Refundable[];
|
|
168
|
+
}>;
|
|
169
|
+
raffle(id: string): Promise<Raffle | null>;
|
|
170
|
+
raffles(campaignId?: string): Promise<Raffle[]>;
|
|
171
|
+
/** Holds tickets while the buyer pays. adult must be true when the raffle is adults only. */
|
|
172
|
+
holdTickets(raffleId: string, o: {
|
|
173
|
+
orderRef: string;
|
|
174
|
+
count: number;
|
|
175
|
+
buyer: {
|
|
176
|
+
name: string;
|
|
177
|
+
email: string;
|
|
178
|
+
};
|
|
179
|
+
adult: boolean;
|
|
180
|
+
customer?: Ref;
|
|
181
|
+
}): Promise<HeldTickets | TicketRefusal>;
|
|
182
|
+
/** handlePayment does this for you. */
|
|
183
|
+
confirmTickets(orderRef: string, o: {
|
|
184
|
+
paymentRef: string;
|
|
185
|
+
amountCents: number;
|
|
186
|
+
}): Promise<{
|
|
187
|
+
ok: true;
|
|
188
|
+
order: TicketOrder;
|
|
189
|
+
} | TicketRefusal>;
|
|
190
|
+
releaseTickets(orderRef: string): Promise<boolean>;
|
|
191
|
+
/** A paid order refunded before the draw leaves it. By order ref or payment ref. */
|
|
192
|
+
voidTickets(ref: string): Promise<{
|
|
193
|
+
voided: boolean;
|
|
194
|
+
repeat: boolean;
|
|
195
|
+
amount_cents: number;
|
|
196
|
+
}>;
|
|
197
|
+
order(orderRef: string): Promise<TicketOrder | null>;
|
|
198
|
+
/** The draw: only once sales have closed and no order is still being paid for. */
|
|
199
|
+
draw(raffleId: string, o: {
|
|
200
|
+
by: string;
|
|
201
|
+
witnesses?: string[];
|
|
202
|
+
}): Promise<{
|
|
203
|
+
raffle: Raffle;
|
|
204
|
+
record: DrawRecord;
|
|
205
|
+
results: RaffleResult[];
|
|
206
|
+
}>;
|
|
207
|
+
/** Redraws one unclaimed prize, after the place's holding period. */
|
|
208
|
+
redraw(raffleId: string, rank: number, o: {
|
|
209
|
+
by: string;
|
|
210
|
+
reason: string;
|
|
211
|
+
}): Promise<{
|
|
212
|
+
raffle: Raffle;
|
|
213
|
+
winner: DrawWinner;
|
|
214
|
+
}>;
|
|
215
|
+
markClaimed(raffleId: string, rank: number, by: string): Promise<Raffle>;
|
|
216
|
+
/** Each prize's winning ticket number: what the results page shows. Never names. */
|
|
217
|
+
results(raffle: Raffle): RaffleResult[];
|
|
218
|
+
/** The buyers of the winning tickets, to tell privately. */
|
|
219
|
+
winnersToTell(raffleId: string): Promise<WinnerContact[]>;
|
|
220
|
+
/** The drawn raffle's record, for verifyDraw(). */
|
|
221
|
+
drawRecord(raffle: Raffle): DrawRecord | null;
|
|
222
|
+
/** Hand it every payments webhook outcome; it records gifts and confirms or releases tickets. */
|
|
223
|
+
handlePayment(outcome: PaymentOutcome): Promise<Handled>;
|
|
224
|
+
/** From the app's cron: lapsed holds go back, raffles and campaigns past their end close. */
|
|
225
|
+
tick(): Promise<{
|
|
226
|
+
released: number;
|
|
227
|
+
closed_raffles: string[];
|
|
228
|
+
closed_campaigns: number;
|
|
229
|
+
}>;
|
|
230
|
+
/** From the app's cron: personal details cleared after their retention period. */
|
|
231
|
+
cleanup(): Promise<{
|
|
232
|
+
cleared_pledges: number;
|
|
233
|
+
cleared_orders: number;
|
|
234
|
+
deleted: number;
|
|
235
|
+
}>;
|
|
236
|
+
}
|
|
237
|
+
export declare function createFundraising<const C extends FundraisingConfig>(opts: FundraisingOptions<C>): Fundraising;
|
|
238
|
+
export {};
|