@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.
@@ -0,0 +1,4 @@
1
+ /** Cents as money: A$50.00, ₱1,500.00, US$12.00. */
2
+ export declare function formatMoney(cents: number, currency: string, country?: string): string;
3
+ /** Dollars or pesos (25.5) to cents (2550). */
4
+ export declare const toCents: (amount: number) => number;
package/dist/money.js ADDED
@@ -0,0 +1,10 @@
1
+ // Money in the house style (workbench-country's, the same as invoices,
2
+ // quotes and vouchers), always with 2 decimal places: A$50.00, ₱1,500.00.
3
+ import { audiencePack, currencySymbol, formatMoney as countryMoney } from "@mccaskie-labs/workbench-country";
4
+ /** Cents as money: A$50.00, ₱1,500.00, US$12.00. */
5
+ export function formatMoney(cents, currency, country = "AU") {
6
+ const pack = audiencePack({ country, currency: { code: currency, symbol: currencySymbol(currency) } });
7
+ return countryMoney(cents / 100, pack, { decimals: 2 });
8
+ }
9
+ /** Dollars or pesos (25.5) to cents (2550). */
10
+ export const toCents = (amount) => Math.round(amount * 100);
@@ -0,0 +1,22 @@
1
+ export declare const STARTER_FUNDRAISING: {
2
+ readonly format: 1;
3
+ readonly country: "AU";
4
+ readonly currency: "AUD";
5
+ readonly time_zone: "Australia/Sydney";
6
+ readonly organisation: {
7
+ readonly name: "Our organisation";
8
+ };
9
+ readonly gifts: {
10
+ readonly amounts: [20, 50, 100];
11
+ readonly min: 5;
12
+ readonly max: 5000;
13
+ readonly monthly: true;
14
+ readonly show_names: "ask";
15
+ };
16
+ readonly raffles: {
17
+ readonly place: "AU-NSW";
18
+ readonly adults_only: true;
19
+ readonly max_per_order: 50;
20
+ readonly hold_minutes: 30;
21
+ };
22
+ };
@@ -0,0 +1,13 @@
1
+ // What `npx workbench-fundraising init` writes: workbench/fundraising.json
2
+ // with Workbench's recommended answers for an Australian school, club or
3
+ // church, before the client's own. Gifts once or monthly, names shown only
4
+ // when the giver ticks the box, and raffles in New South Wales.
5
+ export const STARTER_FUNDRAISING = {
6
+ format: 1,
7
+ country: "AU",
8
+ currency: "AUD",
9
+ time_zone: "Australia/Sydney",
10
+ organisation: { name: "Our organisation" },
11
+ gifts: { amounts: [20, 50, 100], min: 5, max: 5000, monthly: true, show_names: "ask" },
12
+ raffles: { place: "AU-NSW", adults_only: true, max_per_order: 50, hold_minutes: 30 },
13
+ };
@@ -0,0 +1,33 @@
1
+ /** One CSS custom property the rules read, with its default. */
2
+ export interface StyleVariable {
3
+ /** `--wb-<tool>-<what>`. */
4
+ name: string;
5
+ value: string;
6
+ about: string;
7
+ }
8
+ /** A rule for a class in another state, or for an element inside it. */
9
+ export interface StyleState {
10
+ selector: string;
11
+ about: string;
12
+ css: string;
13
+ }
14
+ /** One class the tool puts on an element, with its default rule. */
15
+ export interface StyleClass {
16
+ name: string;
17
+ element: string;
18
+ about: string;
19
+ css: string;
20
+ states?: readonly StyleState[];
21
+ }
22
+ /** Every class and variable the tool draws with. */
23
+ export interface ToolStyles {
24
+ format: 1;
25
+ tool: string;
26
+ package: string;
27
+ title: string;
28
+ prefix: string;
29
+ variables: readonly StyleVariable[];
30
+ classes: readonly StyleClass[];
31
+ }
32
+ /** The style hooks of everything '@mccaskie-labs/workbench-fundraising/ui' draws. */
33
+ export declare const FUND_STYLES: ToolStyles;
package/dist/styles.js ADDED
@@ -0,0 +1,108 @@
1
+ // The look the campaign page, give form, supporters' list, thank-you,
2
+ // raffle page, tickets, results, refusals and the owner's law check start
3
+ // with (docs/capabilities-manifest.md §10). Every element the ui functions
4
+ // draw carries one of these classes, and every class has a default rule
5
+ // here, so they look finished out of the box and a project restyles them
6
+ // from its own CSS by the same names. `npx workbench-ui styles` writes these
7
+ // into the project's public/styles/workbench.css inside `@layer workbench`.
8
+ // The names are public: renaming one is a breaking change.
9
+ const v = (name) => `var(--wb-fund-${name})`;
10
+ const box = `color:${v("text")};background:${v("surface")};border:1px solid ${v("line")};border-radius:${v("radius")}`;
11
+ const muted = `color:${v("muted")}`;
12
+ /** The style hooks of everything '@mccaskie-labs/workbench-fundraising/ui' draws. */
13
+ export const FUND_STYLES = {
14
+ format: 1,
15
+ tool: "fundraising",
16
+ package: "@mccaskie-labs/workbench-fundraising",
17
+ title: "Fundraising",
18
+ prefix: "wb-fund-",
19
+ variables: [
20
+ { name: "--wb-fund-text", value: "var(--wb-text, #1f2937)", about: "Text" },
21
+ { name: "--wb-fund-muted", value: "var(--wb-muted, #5b6472)", about: "Quieter text: counts, dates, notes" },
22
+ { name: "--wb-fund-surface", value: "var(--wb-surface, #f7f8f8)", about: "Background of the cards and forms" },
23
+ { name: "--wb-fund-line", value: "var(--wb-line, #d7d8db)", about: "Borders and the progress bar's track" },
24
+ { name: "--wb-fund-accent", value: "var(--wb-accent, #2563eb)", about: "The progress bar, the chosen amount and the button" },
25
+ { name: "--wb-fund-on-accent", value: "var(--wb-on-accent, #ffffff)", about: "Text on the button" },
26
+ { name: "--wb-fund-bad", value: "var(--wb-danger, #b42318)", about: "The edge of a refusal and of the law check's problems" },
27
+ { name: "--wb-fund-radius", value: "var(--wb-radius, 8px)", about: "Corner rounding" },
28
+ ],
29
+ classes: [
30
+ { name: "wb-fund-campaign", element: "section", about: "The campaign page", css: `max-width:40rem;padding:1.25rem;${box}` },
31
+ { name: "wb-fund-image", element: "img", about: "The campaign's picture", css: `display:block;width:100%;height:auto;margin:0 0 1rem;border-radius:${v("radius")}` },
32
+ { name: "wb-fund-title", element: "h2", about: "The campaign's, raffle's or page's title", css: "margin:0 0 .75rem;font-size:1.375rem;font-weight:700" },
33
+ { name: "wb-fund-progress", element: "div", about: "The progress bar and raised line", css: "margin:0 0 1rem" },
34
+ {
35
+ name: "wb-fund-bar",
36
+ element: "progress",
37
+ about: "Raised against the goal",
38
+ css: `width:100%;height:.75rem;margin:0 0 .5rem;appearance:none;-webkit-appearance:none;border:0;border-radius:${v("radius")};background:${v("line")};overflow:hidden;accent-color:${v("accent")}`,
39
+ states: [
40
+ { selector: "::-webkit-progress-bar", about: "The track (WebKit)", css: `background:${v("line")};border-radius:${v("radius")}` },
41
+ { selector: "::-webkit-progress-value", about: "The raised part (WebKit)", css: `background:${v("accent")};border-radius:${v("radius")}` },
42
+ { selector: "::-moz-progress-bar", about: "The raised part (Firefox)", css: `background:${v("accent")};border-radius:${v("radius")}` },
43
+ ],
44
+ },
45
+ { name: "wb-fund-raised", element: "p", about: "\"A$4,250.00 raised of A$10,000.00\"", css: "margin:0;font-size:1.125rem;font-weight:600;font-variant-numeric:tabular-nums" },
46
+ { name: "wb-fund-counts", element: "p", about: "\"42 gifts · 6 giving monthly\"", css: `margin:.25rem 0 0;font-size:.9rem;${muted}` },
47
+ { name: "wb-fund-ends", element: "p", about: "\"Ends 12 Dec 2026\"", css: `margin:0 0 1rem;font-size:.9rem;${muted}` },
48
+ { name: "wb-fund-closed", element: "p", about: "The appeal has closed, or the raffle was cancelled", css: `margin:0 0 1rem;padding:.6rem .8rem;${box}` },
49
+ { name: "wb-fund-story", element: "div", about: "The campaign's story", css: "margin:0 0 1rem;line-height:1.55" },
50
+ { name: "wb-fund-para", element: "p", about: "One paragraph of the story", css: "margin:0 0 .75rem" },
51
+ { name: "wb-fund-permit", element: "p", about: "The Philippine solicitation permit line", css: `margin:0;font-size:.8rem;${muted}` },
52
+ { name: "wb-fund-give", element: "form", about: "The give form and the ticket form", css: `display:grid;gap:.75rem;max-width:40rem;margin:1rem 0;padding:1.25rem;${box}` },
53
+ { name: "wb-fund-give-title", element: "h3", about: "\"Give\", \"Buy tickets\", \"Prizes\"", css: "margin:0;font-size:1.125rem;font-weight:600" },
54
+ { name: "wb-fund-hidden", element: "input", about: "The form's hidden campaign or raffle id", css: "display:none" },
55
+ { name: "wb-fund-amounts", element: "fieldset", about: "The amounts to choose from", css: "display:flex;flex-wrap:wrap;gap:.5rem;margin:0;padding:0;border:0" },
56
+ { name: "wb-fund-often", element: "fieldset", about: "Once or every month", css: "display:flex;flex-wrap:wrap;gap:.5rem;margin:0;padding:0;border:0" },
57
+ { name: "wb-fund-legend", element: "legend", about: "A choice's heading, read by screen readers", css: "position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)" },
58
+ {
59
+ name: "wb-fund-amount",
60
+ element: "label",
61
+ about: "One amount, or once or monthly",
62
+ css: `display:inline-flex;align-items:center;gap:.4rem;padding:.5rem .9rem;border:1px solid ${v("line")};border-radius:${v("radius")};cursor:pointer;font-variant-numeric:tabular-nums`,
63
+ states: [{ selector: ":has(:checked)", about: "The chosen one", css: `border-color:${v("accent")};box-shadow:0 0 0 1px ${v("accent")}` }],
64
+ },
65
+ { name: "wb-fund-radio", element: "input", about: "The amount's radio button", css: `accent-color:${v("accent")}` },
66
+ { name: "wb-fund-other", element: "label", about: "Another amount", css: "display:flex;flex-wrap:wrap;align-items:center;gap:.5rem;width:100%" },
67
+ { name: "wb-fund-input", element: "input", about: "A text, number or email box", css: `padding:.45rem .6rem;color:${v("text")};background:transparent;border:1px solid ${v("line")};border-radius:${v("radius")};font:inherit` },
68
+ { name: "wb-fund-range", element: "span", about: "\"From A$5.00 to A$5,000.00\"", css: `font-size:.85rem;${muted}` },
69
+ { name: "wb-fund-check", element: "label", about: "A tick box with its words", css: "display:flex;align-items:center;gap:.5rem" },
70
+ { name: "wb-fund-checkbox", element: "input", about: "The tick box", css: `accent-color:${v("accent")}` },
71
+ { name: "wb-fund-field", element: "label", about: "A labelled box", css: "display:grid;gap:.25rem" },
72
+ { name: "wb-fund-textarea", element: "textarea", about: "The giver's message", css: `padding:.45rem .6rem;color:${v("text")};background:transparent;border:1px solid ${v("line")};border-radius:${v("radius")};font:inherit;resize:vertical` },
73
+ { name: "wb-fund-button", element: "button", about: "Give, Buy tickets", css: `justify-self:start;padding:.6rem 1.2rem;color:${v("on-accent")};background:${v("accent")};border:0;border-radius:${v("radius")};font:inherit;font-weight:600;cursor:pointer` },
74
+ { name: "wb-fund-supporters", element: "section", about: "The supporters' list", css: "max-width:40rem;margin:1rem 0" },
75
+ { name: "wb-fund-supporters-title", element: "h3", about: "\"Supporters\"", css: "margin:0 0 .5rem;font-size:1rem;font-weight:600" },
76
+ { name: "wb-fund-supporter-list", element: "ul", about: "The names", css: "margin:0;padding:0;list-style:none" },
77
+ { name: "wb-fund-supporter", element: "li", about: "One supporter", css: `padding:.4rem 0;border-bottom:1px solid ${v("line")}` },
78
+ { name: "wb-fund-supporter-name", element: "strong", about: "Their name", css: "font-weight:600" },
79
+ { name: "wb-fund-supporter-message", element: "span", about: "Their message", css: `${muted}` },
80
+ { name: "wb-fund-thanks", element: "section", about: "The thank-you", css: `max-width:40rem;padding:1.25rem;${box};border-top:4px solid ${v("accent")}` },
81
+ { name: "wb-fund-thanks-text", element: "p", about: "\"Thank you for your gift of …\"", css: "margin:0 0 .75rem" },
82
+ { name: "wb-fund-deductible", element: "p", about: "The tax-deductible line (deductible gift recipients only)", css: "margin:0 0 .75rem;font-weight:600" },
83
+ { name: "wb-fund-note", element: "p", about: "A quieter line", css: `margin:0 0 .5rem;font-size:.9rem;${muted}` },
84
+ { name: "wb-fund-raffle", element: "section", about: "The raffle page", css: `max-width:40rem;padding:1.25rem;${box}` },
85
+ { name: "wb-fund-prizes", element: "ol", about: "The prizes, first prize first", css: "margin:.5rem 0 1rem;padding-left:1.5rem" },
86
+ { name: "wb-fund-prize", element: "li", about: "One prize", css: "margin:0 0 .35rem" },
87
+ { name: "wb-fund-prize-label", element: "span", about: "What the prize is", css: "font-weight:500" },
88
+ { name: "wb-fund-prize-value", element: "span", about: "Its retail value", css: `${muted};font-variant-numeric:tabular-nums` },
89
+ { name: "wb-fund-facts", element: "ul", about: "Price, tickets left, dates, permits", css: "margin:0 0 1rem;padding:0;list-style:none" },
90
+ { name: "wb-fund-fact", element: "li", about: "One fact", css: `padding:.3rem 0;border-bottom:1px solid ${v("line")}` },
91
+ { name: "wb-fund-terms", element: "p", about: "The owner's own terms", css: `margin:0;font-size:.85rem;${muted};white-space:pre-line` },
92
+ { name: "wb-fund-tickets", element: "section", about: "The buyer's tickets", css: `max-width:40rem;padding:1.25rem;${box};border-top:4px solid ${v("accent")}` },
93
+ { name: "wb-fund-numbers", element: "p", about: "\"Your ticket numbers: 41–43\"", css: "margin:0 0 .75rem;font-size:1.25rem;font-weight:700;font-variant-numeric:tabular-nums" },
94
+ { name: "wb-fund-results", element: "section", about: "The results", css: `max-width:40rem;padding:1.25rem;${box}` },
95
+ { name: "wb-fund-result-list", element: "ol", about: "Each prize and its winning ticket", css: "margin:0 0 .75rem;padding-left:1.5rem" },
96
+ { name: "wb-fund-result", element: "li", about: "One prize's result", css: "margin:0 0 .4rem" },
97
+ { name: "wb-fund-result-number", element: "strong", about: "\"Ticket 117\"", css: "font-variant-numeric:tabular-nums" },
98
+ { name: "wb-fund-claimed", element: "span", about: "\"Claimed\"", css: `font-size:.85rem;${muted}` },
99
+ { name: "wb-fund-check-draw", element: "p", about: "The seed anyone can check the draw by", css: `margin:0;font-size:.8rem;${muted};word-break:break-all` },
100
+ { name: "wb-fund-refusal", element: "p", about: "Why a gift or tickets can't go ahead", css: `margin:.5rem 0;padding:.6rem .8rem;${box};border-left:4px solid ${v("bad")}` },
101
+ { name: "wb-fund-law", element: "section", about: "The owner's law check for a raffle", css: `max-width:48rem;padding:1rem;${box}` },
102
+ { name: "wb-fund-law-problems", element: "ul", about: "What stops the raffle opening", css: "margin:0 0 .75rem;padding:0;list-style:none" },
103
+ { name: "wb-fund-law-problem", element: "li", about: "One problem", css: `margin:0 0 .4rem;padding:.5rem .75rem;border-left:4px solid ${v("bad")};background:${v("surface")}` },
104
+ { name: "wb-fund-law-ok", element: "p", about: "Nothing stops it", css: `margin:0 0 .75rem;padding:.5rem .75rem;border-left:4px solid ${v("accent")}` },
105
+ { name: "wb-fund-law-warnings", element: "ul", about: "What the owner should know", css: "margin:0;padding-left:1.25rem" },
106
+ { name: "wb-fund-law-warning", element: "li", about: "One warning", css: `margin:0 0 .35rem;${muted}` },
107
+ ],
108
+ };
@@ -0,0 +1,278 @@
1
+ /** Where a raffle is run: an Australian state or territory, or the Philippines. docs/raffles.md. */
2
+ export type Place = "AU-NSW" | "AU-VIC" | "AU-QLD" | "AU-SA" | "AU-WA" | "AU-TAS" | "AU-ACT" | "AU-NT" | "PH";
3
+ export interface OrganisationConfig {
4
+ /** The name on the thank-you, the receipt line and the raffle page: "St Mary's P&F". */
5
+ name: string;
6
+ /** Australia: the ABN. Needed for the tax-deductible line. */
7
+ abn?: string;
8
+ /**
9
+ * Australia: the organisation is a deductible gift recipient (DGR) the ATO
10
+ * has endorsed. Only then does the thank-you say a gift is tax-deductible.
11
+ * Workbench can't check it: the owner says so (P9).
12
+ */
13
+ dgr?: boolean;
14
+ /** The Philippines: the DSWD public solicitation permit number, shown on campaign pages (PD 1564). */
15
+ solicitation_permit?: string;
16
+ }
17
+ export interface GiftsConfig {
18
+ /** The amounts offered as buttons, in dollars or pesos: [20, 50, 100]. 1 to 6 of them. */
19
+ amounts: number[];
20
+ /** The least and most a giver may type. Keep them inside workbench/payments.json `chosen`. */
21
+ min: number;
22
+ max: number;
23
+ /** Offer a monthly gift as well (payments' repeating payments, collect auto or invoice). */
24
+ monthly: boolean;
25
+ /** "ask": a tick box, off by default, lets a giver's name show on the page. "never": no names ever. */
26
+ show_names: "ask" | "never";
27
+ }
28
+ export interface RafflesConfig {
29
+ /** Where raffles are usually run; each raffle may say otherwise. */
30
+ place: Place;
31
+ /** Buyers confirm they are 18 or over. Always on in Tasmania and the Philippines. Default true. */
32
+ adults_only?: boolean;
33
+ /** The most tickets one order may buy. Default 50. */
34
+ max_per_order?: number;
35
+ /** How long an unpaid order holds its tickets, in minutes. Default 30. */
36
+ hold_minutes?: number;
37
+ }
38
+ export interface FundraisingConfig {
39
+ format: 1;
40
+ /** Where the organisation is, as a two-letter code: AU (the default) or PH. */
41
+ country: string;
42
+ /** ISO currency: AUD, PHP. Every campaign, gift and ticket is in this one currency. */
43
+ currency: string;
44
+ /** For dates shown to givers and buyers. From workbench/country.json. */
45
+ time_zone: string;
46
+ organisation: OrganisationConfig;
47
+ /** Left out: no online gifts (raffles only). */
48
+ gifts?: GiftsConfig;
49
+ /** Left out: no raffles. */
50
+ raffles?: RafflesConfig;
51
+ /** How long a giver's name and message, and a ticket buyer's name and email, are kept after the campaign or draw, in months. Default 24; at least the place's raffle records period. */
52
+ retention_months?: number;
53
+ }
54
+ /** A link to the app's own record, never its contents: { type: "contact", id }. */
55
+ export interface Ref {
56
+ type: string;
57
+ id: string;
58
+ }
59
+ export type CampaignStatus = "draft" | "live" | "closed";
60
+ export interface Campaign {
61
+ id: string;
62
+ /** For the page's address: roof-appeal. */
63
+ slug: string;
64
+ title: string;
65
+ /** The story, as plain text with blank lines between paragraphs. */
66
+ story: string;
67
+ image_url: string | null;
68
+ /** null: no goal shown, only what's been raised. */
69
+ goal_cents: number | null;
70
+ currency: string;
71
+ starts_at: string | null;
72
+ ends_at: string | null;
73
+ status: CampaignStatus;
74
+ created_at: string;
75
+ }
76
+ export interface CampaignTotals {
77
+ campaign_id: string;
78
+ /** Confirmed online gifts, after refunds. */
79
+ gifts_cents: number;
80
+ /** Cash and cheques the owner added. */
81
+ cash_cents: number;
82
+ /** Paid raffle tickets of raffles in this campaign, after refunds. */
83
+ raffle_cents: number;
84
+ /** All three. */
85
+ raised_cents: number;
86
+ goal_cents: number | null;
87
+ /** 0 to 100 (it can pass 100), or null with no goal. */
88
+ percent: number | null;
89
+ /** Gifts counted: online and cash. */
90
+ gifts: number;
91
+ /** Monthly givers still giving. */
92
+ monthly_givers: number;
93
+ }
94
+ /** pending: not paid yet. given: a one-off gift, paid. active: a monthly gift still giving. ended: a monthly gift that stopped. */
95
+ export type PledgeStatus = "pending" | "given" | "active" | "ended";
96
+ /** What a giver chose before paying: the amount, once or monthly, and whether their name shows. */
97
+ export interface Pledge {
98
+ id: string;
99
+ campaign_id: string;
100
+ amount_cents: number;
101
+ monthly: boolean;
102
+ show_name: boolean;
103
+ status: PledgeStatus;
104
+ created_at: string;
105
+ }
106
+ /** One gift that counts: a confirmed payment, one cycle of a monthly gift, or cash the owner added. */
107
+ export interface Gift {
108
+ id: string;
109
+ campaign_id: string;
110
+ pledge_id: string | null;
111
+ kind: "online" | "cash";
112
+ amount_cents: number;
113
+ currency: string;
114
+ /** The payment's id (online), or the owner's key (cash). */
115
+ ref: string;
116
+ monthly: boolean;
117
+ refunded: boolean;
118
+ created_at: string;
119
+ /** True when this ref was recorded before (a webhook retry). */
120
+ repeat?: boolean;
121
+ }
122
+ /** A name on the supporters' list: only givers who ticked the box. No amounts. */
123
+ export interface Supporter {
124
+ name: string;
125
+ message: string | null;
126
+ at: string;
127
+ }
128
+ /** What a prize is, so the place's rules can be checked. */
129
+ export type PrizeKind = "goods" | "experience" | "gift_card" | "travel" | "cash" | "liquor" | "firearm" | "tobacco" | "cosmetic_surgery" | "medical" | "other";
130
+ export interface Prize {
131
+ /** 1 is first prize. In order, from 1. */
132
+ rank: number;
133
+ label: string;
134
+ /** The retail value. */
135
+ value_cents: number;
136
+ kind: PrizeKind;
137
+ /** travel: the part that is cash (spending money), if any. */
138
+ cash_cents?: number;
139
+ }
140
+ export type RaffleStatus = "draft" | "selling" | "closed" | "drawn" | "cancelled";
141
+ /** What the owner enters for a raffle. */
142
+ export interface RaffleInput {
143
+ /** Leave out for a new raffle. */
144
+ id?: string;
145
+ campaign_id?: string | null;
146
+ title: string;
147
+ place: Place | string;
148
+ ticket_cents: number;
149
+ /** The most tickets that can be sold. Fixed, so the most it can take is known. */
150
+ max_tickets: number;
151
+ sales_start: string;
152
+ sales_end: string;
153
+ draw_at: string;
154
+ /** Where and how the draw is held, as the ticket says: "At the school fete, St Mary's hall, by electronic draw". */
155
+ draw_place: string;
156
+ prizes: Prize[];
157
+ /** Permit, licence or authority numbers, by the id in RAFFLE_LAWS (authority, permit, licence, pcso, dswd, local). */
158
+ permits?: Readonly<Record<string, string>>;
159
+ /** Buyers confirm they're 18 or over. Default from raffles.adults_only. */
160
+ adults_only?: boolean;
161
+ /** Extra terms the owner adds, shown on the raffle page. */
162
+ terms?: string;
163
+ }
164
+ export interface Raffle extends Required<Omit<RaffleInput, "id" | "campaign_id" | "permits" | "terms">> {
165
+ id: string;
166
+ campaign_id: string | null;
167
+ permits: Record<string, string>;
168
+ terms: string | null;
169
+ currency: string;
170
+ status: RaffleStatus;
171
+ /** Tickets paid for. */
172
+ sold: number;
173
+ /** Tickets held by orders not yet paid. */
174
+ held: number;
175
+ drawn_at: string | null;
176
+ created_at: string;
177
+ }
178
+ export interface PermitNeed {
179
+ /** The key in RaffleInput.permits. */
180
+ id: string;
181
+ /** "Minor gaming permit (VGCCC)". */
182
+ name: string;
183
+ }
184
+ export interface RaffleProblem {
185
+ code: "permit_needed" | "cash_prize" | "banned_prize" | "liquor_first_prize" | "prize_share_low" | "prize_share_high" | "sales_too_long" | "draw_too_late" | "draw_before_close" | "dates" | "prizes" | "tickets" | "under_18s";
186
+ text: string;
187
+ }
188
+ /** What checkRaffle answers. ok false: the raffle can't open. */
189
+ export interface RaffleCheck {
190
+ ok: boolean;
191
+ problems: RaffleProblem[];
192
+ /** Shown on the owner's page whether or not it's ok. Always includes the not-legal-advice line. */
193
+ warnings: string[];
194
+ permits_needed: PermitNeed[];
195
+ figures: {
196
+ prizes_cents: number;
197
+ cash_cents: number;
198
+ /** tickets × price: the most the raffle can take. */
199
+ max_sales_cents: number;
200
+ /** Prizes as a share of max sales, 0 to 1. */
201
+ prize_share: number;
202
+ /** What's left for the cause if every ticket sells, before the owner's own costs. */
203
+ left_cents: number;
204
+ };
205
+ }
206
+ /** Why tickets can't be bought. Every one has words in the UI. */
207
+ export type TicketRefusalReason = "not_selling" | "not_started" | "ended" | "sold_out" | "not_enough_left" | "too_many" | "adult_required" | "too_late";
208
+ export type TicketRefusal = {
209
+ ok: false;
210
+ reason: TicketRefusalReason;
211
+ left?: number;
212
+ max?: number;
213
+ };
214
+ export interface TicketOrder {
215
+ ref: string;
216
+ raffle_id: string;
217
+ count: number;
218
+ amount_cents: number;
219
+ currency: string;
220
+ status: "held" | "paid" | "released" | "void";
221
+ /** The ticket numbers, once paid. */
222
+ numbers: number[];
223
+ /** When an unpaid hold lapses. */
224
+ expires_at: string;
225
+ payment_ref: string | null;
226
+ repeat?: boolean;
227
+ }
228
+ /** One line for the payments tool's invoice: tickets × price. */
229
+ export interface TicketLine {
230
+ label: string;
231
+ quantity: number;
232
+ unit_cents: number;
233
+ total_cents: number;
234
+ }
235
+ export interface DrawWinner {
236
+ rank: number;
237
+ number: number;
238
+ /** 0 for the first draw; 1, 2 … for a redraw of an unclaimed prize. */
239
+ redraw: number;
240
+ at: string;
241
+ }
242
+ /** Everything needed to check a draw again with verifyDraw(). */
243
+ export interface DrawRecord {
244
+ raffle_id: string;
245
+ /** 64 hex characters, from crypto.getRandomValues at the draw. */
246
+ seed: string;
247
+ /** The highest ticket number issued: the draw is from 1 to this, less void_numbers. */
248
+ issued: number;
249
+ /** Numbers of tickets refunded before the draw, left out of it. */
250
+ void_numbers: number[];
251
+ /** SHA-256 of the ticket numbers in the draw, in order, joined by commas. */
252
+ tickets_hash: string;
253
+ winners: DrawWinner[];
254
+ by: string;
255
+ witnesses: string[];
256
+ drawn_at: string;
257
+ }
258
+ export interface RaffleResult {
259
+ rank: number;
260
+ label: string;
261
+ number: number;
262
+ claimed: boolean;
263
+ }
264
+ /** A winner to tell privately (never published). */
265
+ export interface WinnerContact {
266
+ rank: number;
267
+ label: string;
268
+ number: number;
269
+ name: string | null;
270
+ email: string | null;
271
+ order_ref: string;
272
+ }
273
+ /** Paid orders of a cancelled raffle, for the app to refund through payments. */
274
+ export interface Refundable {
275
+ order_ref: string;
276
+ payment_ref: string;
277
+ amount_cents: number;
278
+ }
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ // The shapes of workbench/fundraising.json, of a raffle, and of what the
2
+ // store answers. Money is always whole cents (integers) with the currency
3
+ // beside it; the config file writes amounts in dollars or pesos (20 or 20.50),
4
+ // which the package turns into cents once.
5
+ export {};
package/dist/ui.d.ts ADDED
@@ -0,0 +1,96 @@
1
+ import type { GiftRefusal } from "./fundraising.ts";
2
+ import type { Campaign, CampaignTotals, DrawRecord, FundraisingConfig, Gift, Raffle, RaffleCheck, RaffleResult, Supporter, TicketOrder, TicketRefusal } from "./types.ts";
3
+ export { FUND_WORDS, FUND_WORD_KEYS, type FundWordKey } from "./words.ts";
4
+ export { formatMoney } from "./money.ts";
5
+ /** The project's strings lookup: `t('ui.wbfund.raised', { raised: 'A$20.00' })`. Undefined falls back to the English. */
6
+ export type Words = (key: string, params?: Readonly<Record<string, string | number>>) => string | undefined;
7
+ export interface ViewOptions {
8
+ /** The project's strings lookup; English when left out. */
9
+ t?: Words;
10
+ /** en, tl or taglish: for dates. */
11
+ lang?: string;
12
+ }
13
+ type Cfg = Pick<FundraisingConfig, "country" | "currency" | "time_zone">;
14
+ /** "23 Nov 2026" in the project's time zone. */
15
+ export declare function formatDate(iso: string, config: Cfg, lang?: string): string;
16
+ /** "Sat 12 Dec 2026, 7:30 pm" in the project's time zone. */
17
+ export declare function formatDateTime(iso: string, config: Cfg, lang?: string): string;
18
+ /** The bar and the raised line. */
19
+ export declare function renderProgress(totals: CampaignTotals, config: Cfg, o?: ViewOptions): string;
20
+ /** The campaign's page: picture, title, progress, end date and story. Put renderGiveForm under it. */
21
+ export declare function renderCampaign(campaign: Campaign, totals: CampaignTotals, config: FundraisingConfig, o?: ViewOptions & {
22
+ now?: Date;
23
+ }): string;
24
+ export interface GiveFormOptions extends ViewOptions {
25
+ /** Where the form posts: the app's route that calls readGiveForm, startGift and payments. */
26
+ action: string;
27
+ }
28
+ /** The give form: the amounts as choices (the middle one chosen), another amount, once or monthly, and the name box. */
29
+ export declare function renderGiveForm(campaign: Campaign, config: FundraisingConfig, o: GiveFormOptions): string;
30
+ /** Cents from typed money ("25", "25.5", "1,250.00"), read from text, never through a float; null if it isn't money. */
31
+ export declare function readAmount(typed: string): number | null;
32
+ type FormLike = {
33
+ get(name: string): unknown;
34
+ };
35
+ export type GiveChoice = {
36
+ ok: true;
37
+ campaignId: string;
38
+ amountCents: number;
39
+ monthly: boolean;
40
+ showName: boolean;
41
+ name?: string;
42
+ message?: string;
43
+ } | GiftRefusal | {
44
+ ok: false;
45
+ reason: "bad_amount";
46
+ };
47
+ /** Reads the give form's post. The amount is checked against the floor and ceiling again by startGift. */
48
+ export declare function readGiveForm(form: FormLike, config: FundraisingConfig): GiveChoice;
49
+ /** The supporters' list: names of givers who ticked the box, with their message. No amounts. */
50
+ export declare function renderSupporters(list: readonly Supporter[], o?: ViewOptions): string;
51
+ /**
52
+ * The thank-you, for the page and the email beside payments' receipt. It
53
+ * says a gift is tax-deductible only when the organisation says it is a
54
+ * deductible gift recipient and gives its ABN (P9).
55
+ */
56
+ export declare function renderThanks(gift: Gift, campaign: Campaign, config: FundraisingConfig, o?: ViewOptions): string;
57
+ /** Tickets still to buy. */
58
+ export declare const ticketsLeft: (r: Raffle) => number;
59
+ /** The raffle's page: prizes, price, tickets left, dates, the draw, permit numbers and terms. Put renderTicketForm under it while it's selling. */
60
+ export declare function renderRaffle(raffle: Raffle, config: FundraisingConfig, o?: ViewOptions & {
61
+ permitNames?: Readonly<Record<string, string>>;
62
+ }): string;
63
+ /** The ticket form: how many, name, email, and the 18-or-over box when the raffle needs it. */
64
+ export declare function renderTicketForm(raffle: Raffle, config: FundraisingConfig, o: ViewOptions & {
65
+ action: string;
66
+ }): string;
67
+ export type TicketChoice = {
68
+ ok: true;
69
+ raffleId: string;
70
+ count: number;
71
+ name: string;
72
+ email: string;
73
+ adult: boolean;
74
+ } | {
75
+ ok: false;
76
+ reason: "bad_input";
77
+ };
78
+ /** Reads the ticket form's post. holdTickets checks it again. */
79
+ export declare function readTicketForm(form: FormLike): TicketChoice;
80
+ /** "1–3, 7" from [1, 2, 3, 7]. */
81
+ export declare function numberList(numbers: readonly number[]): string;
82
+ /** The buyer's tickets, for the page after paying and the email. */
83
+ export declare function renderTickets(order: TicketOrder, raffle: Raffle, config: Cfg, o?: ViewOptions): string;
84
+ /** The results: each prize and its winning ticket number, never a name; with the record, the line anyone can check the draw by. */
85
+ export declare function renderResults(raffle: Raffle, results: readonly RaffleResult[], o?: ViewOptions & {
86
+ record?: DrawRecord | null;
87
+ }): string;
88
+ /** Why a gift or tickets can't go ahead, in the buyer's words. */
89
+ export declare function renderRefusal(r: GiftRefusal | TicketRefusal | {
90
+ ok: false;
91
+ reason: "bad_amount" | "bad_input";
92
+ }, config: FundraisingConfig, o?: ViewOptions & {
93
+ startsAt?: string;
94
+ }): string;
95
+ /** The owner's law check for a raffle: what stops it opening, and what to know. English, as the regulators write. */
96
+ export declare function renderRaffleCheck(check: RaffleCheck): string;