@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/dist/law.js ADDED
@@ -0,0 +1,406 @@
1
+ // Raffle law as data, and checkRaffle(), which refuses a raffle the place's
2
+ // law plainly doesn't allow and warns about the rest. Read from the
3
+ // regulators' own pages on 24 November 2026; docs/raffles.md has the tables,
4
+ // the sources and what was left out. Not legal advice: every answer carries a
5
+ // line telling the owner to read their regulator's page.
6
+ import { formatMoney } from "./money.js";
7
+ const NOT_ADVICE = "This is a summary of the regulator's rules, not legal advice. Read your regulator's page before you sell tickets";
8
+ const permit = (id, name) => ({ id, name });
9
+ const AUD = (dollars) => dollars * 100;
10
+ export const RAFFLE_LAWS = {
11
+ "AU-NSW": {
12
+ place: "AU-NSW",
13
+ name: "New South Wales",
14
+ law: "Community Gaming Act 2018",
15
+ regulator: "NSW Fair Trading",
16
+ url: "https://www.nsw.gov.au/money-and-taxes/community-gaming/lotteries",
17
+ checked: "2026-11-24",
18
+ measure: "prizes",
19
+ bands: [
20
+ { up_to_cents: AUD(30_000), permit: null },
21
+ { up_to_cents: null, permit: permit("authority", "Authority to conduct an art union (NSW Fair Trading)") },
22
+ ],
23
+ always: [],
24
+ cash: { kind: "allowed" },
25
+ banned: ["firearm", "tobacco", "cosmetic_surgery"],
26
+ liquor: "limits",
27
+ adults_only: false,
28
+ cause_share: "At least 40% of gross proceeds must go to the cause (30% for an art union over A$30,000).",
29
+ unclaimed_months: 3,
30
+ records_years: 7,
31
+ eligible: "Only a charity or non-profit organisation may run a raffle in New South Wales.",
32
+ notes: ["Over A$30,000 of prizes the raffle is an art union: send its rules to NSW Fair Trading at least 10 working days before it starts."],
33
+ },
34
+ "AU-VIC": {
35
+ place: "AU-VIC",
36
+ name: "Victoria",
37
+ law: "Gambling Regulation Act 2003",
38
+ regulator: "Victorian Gambling and Casino Control Commission (VGCCC)",
39
+ url: "https://www.vgccc.vic.gov.au/for-gambling-providers/community-and-charitable-gaming/raffles-permit-requirements",
40
+ checked: "2026-11-24",
41
+ measure: "prizes",
42
+ bands: [
43
+ { up_to_cents: AUD(23_060), permit: null },
44
+ { up_to_cents: null, permit: permit("permit", "Minor gaming permit (VGCCC)") },
45
+ ],
46
+ always: [],
47
+ prize_share: { min: 1 / 6, max: 1 / 2, only_without_permit: true },
48
+ max_sales_months: { months: 3, only_without_permit: true },
49
+ draw_within_days_of_close: { days: 14, only_without_permit: true },
50
+ cash: { kind: "none", travel_cash_share: 0.1 },
51
+ banned: [],
52
+ liquor: "conditions",
53
+ adults_only: false,
54
+ cause_share: "The proceeds must go to the declared organisation, through its one approved bank account.",
55
+ publish_over_cents: AUD(500),
56
+ unclaimed_months: 3,
57
+ records_years: 3,
58
+ eligible: "Only a community or charitable organisation declared by the VGCCC may run a raffle in Victoria.",
59
+ notes: ["Victoria's limit (A$23,060) is indexed each year: check it before a large raffle.", "Prizes must be handed over within 28 days of the draw."],
60
+ },
61
+ "AU-QLD": {
62
+ place: "AU-QLD",
63
+ name: "Queensland",
64
+ law: "Charitable and Non-Profit Gaming Act 1999",
65
+ regulator: "Office of Liquor and Gaming Regulation",
66
+ url: "https://www.business.qld.gov.au/industries/hospitality-tourism-sport/liquor-gaming/gaming/not-profit-charitable/competitions-raffles-bingo",
67
+ checked: "2026-11-24",
68
+ measure: "sales",
69
+ bands: [
70
+ { up_to_cents: AUD(50_000), permit: null },
71
+ { up_to_cents: null, permit: permit("licence", "Category 3 gaming licence (OLGR)") },
72
+ ],
73
+ always: [],
74
+ prize_share: { min: 0.2 },
75
+ cash: { kind: "allowed" },
76
+ banned: [],
77
+ liquor: "not_stated",
78
+ adults_only: false,
79
+ unclaimed_months: 3,
80
+ records_years: 3,
81
+ eligible: "Only an eligible non-profit association may run a raffle in Queensland without a licence.",
82
+ notes: ["Queensland's draw, results and record rules are in the Charitable and Non-Profit Gaming Rule: read the category 2 guide before selling."],
83
+ },
84
+ "AU-SA": {
85
+ place: "AU-SA",
86
+ name: "South Australia",
87
+ law: "Lotteries Act 2019",
88
+ regulator: "Consumer and Business Services",
89
+ url: "https://www.sa.gov.au/topics/family-and-community/community-organisations/fundraising-for-organisations/lotteries",
90
+ checked: "2026-11-24",
91
+ measure: "prizes",
92
+ bands: [
93
+ { up_to_cents: AUD(5_000), permit: null },
94
+ { up_to_cents: null, permit: permit("licence", "Major lottery licence (Consumer and Business Services)") },
95
+ ],
96
+ always: [],
97
+ prize_share: { min: 0.2 },
98
+ cash: { kind: "allowed" },
99
+ banned: ["firearm", "tobacco", "medical"],
100
+ liquor: "allowed",
101
+ adults_only: false,
102
+ cause_share: "At least 20% of gross proceeds must go to the cause (35% for a major lottery over A$5,000).",
103
+ publish_over_cents: AUD(250),
104
+ unclaimed_months: 1,
105
+ records_years: 1,
106
+ eligible: "Only an incorporated organisation, or an unincorporated one with at least 10 members, a committee and a constitution, may run a raffle in South Australia.",
107
+ notes: ["A major lottery with A$30,000 or more of prizes needs an independent scrutineer at the draw and an auditor.", "Cash prizes over A$1,000 are paid by bank deposit."],
108
+ },
109
+ "AU-WA": {
110
+ place: "AU-WA",
111
+ name: "Western Australia",
112
+ law: "Gaming and Wagering Commission Act 1987",
113
+ regulator: "Department of Local Government, Sport and Cultural Industries",
114
+ url: "https://www.wa.gov.au/government/publications/standard-lottery-policy",
115
+ checked: "2026-11-24",
116
+ measure: "prizes",
117
+ bands: [
118
+ { up_to_cents: AUD(200), permit: null },
119
+ { up_to_cents: null, permit: permit("permit", "Standard lottery permit (Gaming and Wagering Commission)") },
120
+ ],
121
+ always: [],
122
+ multi_day: permit("permit", "Standard lottery permit (Gaming and Wagering Commission)"),
123
+ max_sales_months: { months: 3 },
124
+ cash: { kind: "allowed" },
125
+ banned: [],
126
+ liquor: "not_stated",
127
+ adults_only: false,
128
+ unclaimed_months: 3,
129
+ records_years: 1,
130
+ eligible: "Only a club, society or body for sporting, social, charitable or similar purposes may run a raffle in Western Australia, never for private gain.",
131
+ notes: [
132
+ "Western Australia asks that a random number generator used for the draw be independently certified. Workbench's draw is random and recorded so it can be checked, but it isn't certified: ask the department whether a physical draw is needed.",
133
+ "Lodge the financial return within 14 days of the draw.",
134
+ ],
135
+ },
136
+ "AU-TAS": {
137
+ place: "AU-TAS",
138
+ name: "Tasmania",
139
+ law: "Gaming Control Act 1993",
140
+ regulator: "Liquor and Gaming Branch, Department of Treasury and Finance",
141
+ url: "https://www.treasury.tas.gov.au/liquor-and-gaming/gambling/permits/exempt-games/raffles",
142
+ checked: "2026-11-24",
143
+ measure: "prizes",
144
+ bands: [
145
+ { up_to_cents: AUD(10_000), permit: null },
146
+ { up_to_cents: null, permit: permit("permit", "Minor gaming permit (Liquor and Gaming Branch)") },
147
+ ],
148
+ always: [],
149
+ draw_within_months_of_open: 12,
150
+ cash: { kind: "max", cents: AUD(5_000) },
151
+ banned: ["firearm", "tobacco", "cosmetic_surgery"],
152
+ liquor: "minors",
153
+ adults_only: true,
154
+ cause_share: "All the proceeds after reasonable costs and the prizes must go to the cause.",
155
+ unclaimed_months: 9,
156
+ records_years: 7,
157
+ eligible: "A raffle in Tasmania must be for a not-for-profit or charitable purpose. The organisers, their families and the beneficiary's management may not buy tickets.",
158
+ notes: ["Results must be easy to find, such as on the raffle page. Winners of a permit raffle are contacted within 2 weeks of the draw."],
159
+ },
160
+ "AU-ACT": {
161
+ place: "AU-ACT",
162
+ name: "the Australian Capital Territory",
163
+ law: "Lotteries Act 1964",
164
+ regulator: "ACT Gambling and Racing Commission",
165
+ url: "https://www.gamblingandracing.act.gov.au/industry/lotteries/raffles",
166
+ checked: "2026-11-24",
167
+ measure: "prizes",
168
+ bands: [
169
+ { up_to_cents: AUD(2_500), permit: null },
170
+ { up_to_cents: null, permit: permit("permit", "Approval to conduct a lottery (ACT Gambling and Racing Commission)") },
171
+ ],
172
+ always: [],
173
+ cash: { kind: "allowed" },
174
+ banned: [],
175
+ liquor: "not_stated",
176
+ adults_only: false,
177
+ unclaimed_months: 3,
178
+ records_years: 3,
179
+ eligible: "The ACT's exempt lottery conditions say who may run a raffle without approval: read them before selling.",
180
+ notes: [],
181
+ },
182
+ "AU-NT": {
183
+ place: "AU-NT",
184
+ name: "the Northern Territory",
185
+ law: "Gaming Control Act 1993",
186
+ regulator: "Licensing NT",
187
+ url: "https://nt.gov.au/industry/gambling/lotteries-community-gambling/apply-to-run-a-minor-or-major-lottery",
188
+ checked: "2026-11-24",
189
+ measure: "sales",
190
+ bands: [
191
+ { up_to_cents: AUD(5_000), permit: null },
192
+ { up_to_cents: AUD(20_000), permit: permit("permit", "Minor lottery permit (Licensing NT)") },
193
+ { up_to_cents: null, permit: permit("permit", "Major lottery permit (Licensing NT)") },
194
+ ],
195
+ always: [],
196
+ prize_share: { min: 1 / 3 },
197
+ max_sales_months: { months: 3 },
198
+ cash: { kind: "allowed" },
199
+ banned: ["firearm", "tobacco"],
200
+ liquor: "not_first",
201
+ adults_only: false,
202
+ publish_over_cents: AUD(1_000),
203
+ unclaimed_months: 3,
204
+ records_years: 7,
205
+ eligible: "Only an approved association may run a raffle in the Northern Territory.",
206
+ notes: ["Two approved office bearers must be at the draw.", "Lodge the financial statement with Licensing NT within 2 months of the draw."],
207
+ },
208
+ PH: {
209
+ place: "PH",
210
+ name: "the Philippines",
211
+ law: "RA 1169 (PCSO), PD 1564 (solicitation permits) and PD 1602 (illegal gambling)",
212
+ regulator: "Philippine Charity Sweepstakes Office (PCSO) and DSWD",
213
+ url: "https://www.pcso.gov.ph",
214
+ checked: "2026-11-24",
215
+ measure: "prizes",
216
+ bands: [{ up_to_cents: null, permit: null }],
217
+ always: [permit("pcso", "PCSO authority for a charitable raffle"), permit("dswd", "DSWD public solicitation permit (PD 1564)")],
218
+ cash: { kind: "allowed" },
219
+ banned: ["firearm"],
220
+ liquor: "not_stated",
221
+ adults_only: true,
222
+ unclaimed_months: 3,
223
+ records_years: 5,
224
+ eligible: "No small-raffle exemption exists in the Philippines: a raffle with paid tickets is illegal gambling without PCSO's authority (PD 1602).",
225
+ notes: [
226
+ "Selling tickets online must meet PCSO's online raffle rules (servers in the Philippines, a BSP-licensed payment gateway, foreign buyers blocked, a certified draw). Check with PCSO before selling online.",
227
+ "The city or municipality where the draw is held may need a mayor's or special fundraising permit and a barangay clearance (enter it as \"local\").",
228
+ "A prize over ₱10,000 bears a 20% final tax.",
229
+ ],
230
+ },
231
+ };
232
+ export const PLACES = Object.keys(RAFFLE_LAWS);
233
+ /** The law for a place, or null where Workbench has none written down. */
234
+ export function raffleLaw(place) {
235
+ return Object.hasOwn(RAFFLE_LAWS, place) ? RAFFLE_LAWS[place] : null;
236
+ }
237
+ function addMonths(at, months) {
238
+ const d = new Date(at);
239
+ d.setUTCMonth(d.getUTCMonth() + months);
240
+ return d;
241
+ }
242
+ /** The place's own money: pesos in the Philippines, dollars in Australia. */
243
+ const money = (cents, place) => (place === "PH" ? formatMoney(cents, "PHP", "PH") : formatMoney(cents, "AUD", "AU"));
244
+ /** The prizes' cash, counting a travel prize's spending money. */
245
+ function cashOf(p) {
246
+ if (p.kind === "cash")
247
+ return p.value_cents;
248
+ return p.cash_cents ?? 0;
249
+ }
250
+ const KIND_WORDS = {
251
+ goods: "goods",
252
+ experience: "an experience",
253
+ gift_card: "a gift card",
254
+ travel: "travel",
255
+ cash: "cash",
256
+ liquor: "liquor",
257
+ firearm: "a firearm or weapon",
258
+ tobacco: "tobacco or vaping products",
259
+ cosmetic_surgery: "cosmetic surgery",
260
+ medical: "a medical treatment",
261
+ other: "other",
262
+ };
263
+ /**
264
+ * Checks a raffle against its place's law. Refusals (problems) stop it
265
+ * opening; warnings are shown beside it either way. Pure: no clock beyond
266
+ * the dates given, no database.
267
+ */
268
+ export function checkRaffle(r) {
269
+ const problems = [];
270
+ const warnings = [];
271
+ const add = (code, text) => problems.push({ code, text });
272
+ const law = raffleLaw(r.place);
273
+ const prizes = Array.isArray(r.prizes) ? r.prizes : [];
274
+ const prizesCents = prizes.reduce((s, p) => s + (Number.isSafeInteger(p.value_cents) ? p.value_cents : 0), 0);
275
+ const cashCents = prizes.reduce((s, p) => s + cashOf(p), 0);
276
+ const maxSales = Number.isSafeInteger(r.ticket_cents) && Number.isSafeInteger(r.max_tickets) ? r.ticket_cents * r.max_tickets : 0;
277
+ const share = maxSales > 0 ? prizesCents / maxSales : 0;
278
+ const figures = { prizes_cents: prizesCents, cash_cents: cashCents, max_sales_cents: maxSales, prize_share: share, left_cents: maxSales - prizesCents };
279
+ const m = (c) => money(c, r.place);
280
+ // The raffle itself.
281
+ if (prizes.length === 0)
282
+ add("prizes", "Add at least one prize.");
283
+ prizes.forEach((p, i) => {
284
+ if (p.rank !== i + 1)
285
+ add("prizes", `Prizes must be numbered 1, 2, 3 … in order (prize ${i + 1} says ${p.rank}).`);
286
+ if (typeof p.label !== "string" || !p.label.trim())
287
+ add("prizes", `Prize ${i + 1} needs a description.`);
288
+ if (!Number.isSafeInteger(p.value_cents) || p.value_cents < 1)
289
+ add("prizes", `Prize ${i + 1} needs its retail value.`);
290
+ if (p.cash_cents !== undefined && (!Number.isSafeInteger(p.cash_cents) || p.cash_cents < 0 || p.cash_cents > p.value_cents))
291
+ add("prizes", `Prize ${i + 1}'s cash part must be between 0 and its value.`);
292
+ });
293
+ if (!Number.isSafeInteger(r.ticket_cents) || r.ticket_cents < 50)
294
+ add("tickets", "A ticket must cost at least 50 cents.");
295
+ if (!Number.isSafeInteger(r.max_tickets) || r.max_tickets < 1 || r.max_tickets > 1_000_000)
296
+ add("tickets", "Set how many tickets can be sold: 1 to 1,000,000.");
297
+ else if (prizes.length > r.max_tickets)
298
+ add("tickets", "There are more prizes than tickets.");
299
+ const start = new Date(r.sales_start);
300
+ const end = new Date(r.sales_end);
301
+ const draw = new Date(r.draw_at);
302
+ const datesOk = [start, end, draw].every((d) => !Number.isNaN(d.getTime()));
303
+ if (!datesOk)
304
+ add("dates", "Set when sales open, when they close and when the draw is.");
305
+ else {
306
+ if (end <= start)
307
+ add("dates", "Sales must close after they open.");
308
+ if (draw < end)
309
+ add("draw_before_close", "The draw can't be before ticket sales close.");
310
+ }
311
+ if (typeof r.draw_place !== "string" || !r.draw_place.trim())
312
+ add("dates", "Say where and how the draw is held, as the ticket will.");
313
+ warnings.push(`${NOT_ADVICE}: ${law ? law.url : "your state or country's gaming regulator"}.`);
314
+ if (!law) {
315
+ warnings.push(`No raffle law is written down for ${r.place}: check the local rules, and whether a permit is needed, before you sell tickets.`);
316
+ return { ok: problems.length === 0, problems, warnings, permits_needed: [], figures };
317
+ }
318
+ // Permits.
319
+ const measured = law.measure === "prizes" ? prizesCents : maxSales;
320
+ const band = law.bands.find((b) => b.up_to_cents === null || measured <= b.up_to_cents) ?? law.bands[law.bands.length - 1];
321
+ const needed = [...law.always];
322
+ if (band.permit)
323
+ needed.push(band.permit);
324
+ if (law.multi_day && datesOk && end.getTime() - start.getTime() > 24 * 3600_000 && !needed.some((n) => n.id === law.multi_day.id))
325
+ needed.push(law.multi_day);
326
+ const permits = r.permits ?? {};
327
+ for (const n of needed) {
328
+ const v = permits[n.id];
329
+ if (typeof v !== "string" || !v.trim()) {
330
+ const why = law.always.includes(n)
331
+ ? `Every raffle in ${law.name} needs one.`
332
+ : law.multi_day === n && band.permit === null
333
+ ? `A raffle sold over more than one day in ${law.name} needs one.`
334
+ : `${law.measure === "prizes" ? `Prizes of ${m(prizesCents)}` : `Ticket sales of up to ${m(maxSales)}`} in ${law.name} need one.`;
335
+ add("permit_needed", `Enter the number of your ${n.name}. ${why}`);
336
+ }
337
+ }
338
+ const permitted = needed.some((n) => !law.always.includes(n));
339
+ const applies = (rule) => rule !== undefined && !(rule.only_without_permit && permitted);
340
+ if (permitted && law.place === "AU-VIC")
341
+ warnings.push("With a permit, follow the permit's own conditions on dates, ticket numbers and the draw.");
342
+ // Prizes.
343
+ for (const p of prizes) {
344
+ if (law.banned.includes(p.kind))
345
+ add("banned_prize", `${law.name} doesn't allow ${KIND_WORDS[p.kind]} as a prize ("${p.label}").`);
346
+ }
347
+ if (law.cash.kind === "none") {
348
+ for (const p of prizes) {
349
+ if (p.kind === "cash")
350
+ add("cash_prize", `Cash isn't a legal raffle prize in ${law.name} ("${p.label}").`);
351
+ else if ((p.cash_cents ?? 0) > 0 && (p.kind !== "travel" || p.cash_cents > Math.floor(p.value_cents * law.cash.travel_cash_share))) {
352
+ add("cash_prize", `In ${law.name} only a travel prize may include cash, up to ${Math.round(law.cash.travel_cash_share * 100)}% of its value ("${p.label}").`);
353
+ }
354
+ }
355
+ }
356
+ else if (law.cash.kind === "max" && cashCents > law.cash.cents) {
357
+ add("cash_prize", `Cash prizes in ${law.name} may come to at most ${m(law.cash.cents)} in total; these come to ${m(cashCents)}.`);
358
+ }
359
+ const liquor = prizes.filter((p) => p.kind === "liquor");
360
+ if (liquor.length) {
361
+ if (law.liquor === "not_first" && prizes[0]?.kind === "liquor")
362
+ add("liquor_first_prize", `Liquor can't be the main prize in ${law.name}.`);
363
+ else if (law.liquor === "minors" && r.adults_only === false)
364
+ add("under_18s", `Liquor can't be a prize in ${law.name} when under-18s can buy tickets.`);
365
+ else if (law.liquor === "limits")
366
+ warnings.push("Liquor prizes in New South Wales are limited to 20 litres up to 20% alcohol, or 5 litres above it.");
367
+ else if (law.liquor !== "allowed")
368
+ warnings.push(`Check ${law.regulator}'s rules on liquor as a prize.`);
369
+ }
370
+ if (law.adults_only && r.adults_only === false)
371
+ add("under_18s", `Ticket buyers in ${law.name} must be 18 or over.`);
372
+ // Prizes against tickets.
373
+ if (maxSales > 0 && applies(law.prize_share)) {
374
+ const ps = law.prize_share;
375
+ if (ps.min !== undefined && share + 1e-9 < ps.min) {
376
+ add("prize_share_low", `In ${law.name} the prizes must be worth at least ${Math.round(ps.min * 1000) / 10}% of the tickets (${m(Math.ceil(maxSales * ps.min))} for ${r.max_tickets} tickets at ${m(r.ticket_cents)}); they're worth ${m(prizesCents)}.`);
377
+ }
378
+ if (ps.max !== undefined && share - 1e-9 > ps.max) {
379
+ add("prize_share_high", `In ${law.name} the tickets on sale must be worth at least ${Math.round(1 / ps.max)} times the prizes: sell more tickets or a dearer ticket.`);
380
+ }
381
+ }
382
+ // Dates.
383
+ if (datesOk && end > start) {
384
+ if (applies(law.max_sales_months) && end > addMonths(start, law.max_sales_months.months)) {
385
+ add("sales_too_long", `Sales in ${law.name} may run for at most ${law.max_sales_months.months} months.`);
386
+ }
387
+ if (applies(law.draw_within_days_of_close) && draw.getTime() - end.getTime() > law.draw_within_days_of_close.days * 24 * 3600_000) {
388
+ add("draw_too_late", `The draw in ${law.name} must be within ${law.draw_within_days_of_close.days} days of the last sale.`);
389
+ }
390
+ if (law.draw_within_months_of_open !== undefined && draw > addMonths(start, law.draw_within_months_of_open)) {
391
+ add("draw_too_late", `The draw in ${law.name} must be within ${law.draw_within_months_of_open} months of sales opening.`);
392
+ }
393
+ }
394
+ // What the tool can't check.
395
+ warnings.push(law.eligible);
396
+ if (law.cause_share)
397
+ warnings.push(`${law.cause_share} If every ticket sells, ${m(figures.left_cents)} is left after prizes, before your own costs.`);
398
+ if (law.publish_over_cents !== undefined && prizes.some((p) => p.value_cents > law.publish_over_cents)) {
399
+ warnings.push(`Results must be published: the raffle page shows the winning ticket numbers, never names.`);
400
+ }
401
+ if (law.place !== "PH")
402
+ warnings.push("Tickets sold online can reach buyers in other states, whose rules may differ.");
403
+ for (const n of law.notes)
404
+ warnings.push(n);
405
+ return { ok: problems.length === 0, problems, warnings, permits_needed: needed, figures };
406
+ }
@@ -0,0 +1,4 @@
1
+ export declare const fundraisingMigration: {
2
+ up: string;
3
+ down: string;
4
+ };