@bash-app/bash-common 30.383.0 → 30.385.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.
Files changed (91) hide show
  1. package/dist/__tests__/accessScreening.test.js +39 -1
  2. package/dist/__tests__/accessScreening.test.js.map +1 -1
  3. package/dist/__tests__/applicationFunnel.test.d.ts +2 -0
  4. package/dist/__tests__/applicationFunnel.test.d.ts.map +1 -0
  5. package/dist/__tests__/applicationFunnel.test.js +126 -0
  6. package/dist/__tests__/applicationFunnel.test.js.map +1 -0
  7. package/dist/__tests__/definitionsHelpers.test.js +20 -1
  8. package/dist/__tests__/definitionsHelpers.test.js.map +1 -1
  9. package/dist/__tests__/fundingMeter.test.d.ts +2 -0
  10. package/dist/__tests__/fundingMeter.test.d.ts.map +1 -0
  11. package/dist/__tests__/fundingMeter.test.js +129 -0
  12. package/dist/__tests__/fundingMeter.test.js.map +1 -0
  13. package/dist/__tests__/giveaway.test.d.ts +2 -0
  14. package/dist/__tests__/giveaway.test.d.ts.map +1 -0
  15. package/dist/__tests__/giveaway.test.js +65 -0
  16. package/dist/__tests__/giveaway.test.js.map +1 -0
  17. package/dist/__tests__/promoterCompetitionUtils.test.d.ts +2 -0
  18. package/dist/__tests__/promoterCompetitionUtils.test.d.ts.map +1 -0
  19. package/dist/__tests__/promoterCompetitionUtils.test.js +262 -0
  20. package/dist/__tests__/promoterCompetitionUtils.test.js.map +1 -0
  21. package/dist/accessScreening.d.ts +18 -3
  22. package/dist/accessScreening.d.ts.map +1 -1
  23. package/dist/accessScreening.js +26 -0
  24. package/dist/accessScreening.js.map +1 -1
  25. package/dist/applicationFunnel.d.ts +58 -0
  26. package/dist/applicationFunnel.d.ts.map +1 -0
  27. package/dist/applicationFunnel.js +147 -0
  28. package/dist/applicationFunnel.js.map +1 -0
  29. package/dist/definitions.d.ts +145 -5
  30. package/dist/definitions.d.ts.map +1 -1
  31. package/dist/definitions.js +137 -5
  32. package/dist/definitions.js.map +1 -1
  33. package/dist/extendedSchemas.d.ts +159 -0
  34. package/dist/extendedSchemas.d.ts.map +1 -1
  35. package/dist/extendedSchemas.js +6 -0
  36. package/dist/extendedSchemas.js.map +1 -1
  37. package/dist/fundingMeter.d.ts +66 -0
  38. package/dist/fundingMeter.d.ts.map +1 -0
  39. package/dist/fundingMeter.js +99 -0
  40. package/dist/fundingMeter.js.map +1 -0
  41. package/dist/giveaway.d.ts +71 -0
  42. package/dist/giveaway.d.ts.map +1 -0
  43. package/dist/giveaway.js +117 -0
  44. package/dist/giveaway.js.map +1 -0
  45. package/dist/index.d.ts +5 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +6 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/utils/__tests__/bashHostIdentity.test.d.ts +2 -0
  50. package/dist/utils/__tests__/bashHostIdentity.test.d.ts.map +1 -0
  51. package/dist/utils/__tests__/bashHostIdentity.test.js +39 -0
  52. package/dist/utils/__tests__/bashHostIdentity.test.js.map +1 -0
  53. package/dist/utils/__tests__/promoterCompetitionUtils.test.d.ts +2 -0
  54. package/dist/utils/__tests__/promoterCompetitionUtils.test.d.ts.map +1 -0
  55. package/dist/utils/__tests__/promoterCompetitionUtils.test.js +104 -0
  56. package/dist/utils/__tests__/promoterCompetitionUtils.test.js.map +1 -0
  57. package/dist/utils/__tests__/slugUtils.test.js +29 -2
  58. package/dist/utils/__tests__/slugUtils.test.js.map +1 -1
  59. package/dist/utils/bashHostIdentity.d.ts +18 -0
  60. package/dist/utils/bashHostIdentity.d.ts.map +1 -0
  61. package/dist/utils/bashHostIdentity.js +17 -0
  62. package/dist/utils/bashHostIdentity.js.map +1 -0
  63. package/dist/utils/promoterCompetitionUtils.d.ts +89 -0
  64. package/dist/utils/promoterCompetitionUtils.d.ts.map +1 -0
  65. package/dist/utils/promoterCompetitionUtils.js +158 -0
  66. package/dist/utils/promoterCompetitionUtils.js.map +1 -0
  67. package/dist/utils/slugUtils.d.ts +2 -0
  68. package/dist/utils/slugUtils.d.ts.map +1 -1
  69. package/dist/utils/slugUtils.js +5 -1
  70. package/dist/utils/slugUtils.js.map +1 -1
  71. package/package.json +1 -1
  72. package/prisma/schema.prisma +415 -25
  73. package/src/__tests__/accessScreening.test.ts +69 -1
  74. package/src/__tests__/applicationFunnel.test.ts +197 -0
  75. package/src/__tests__/definitionsHelpers.test.ts +24 -0
  76. package/src/__tests__/fundingMeter.test.ts +143 -0
  77. package/src/__tests__/giveaway.test.ts +111 -0
  78. package/src/__tests__/promoterCompetitionUtils.test.ts +334 -0
  79. package/src/accessScreening.ts +49 -0
  80. package/src/applicationFunnel.ts +225 -0
  81. package/src/definitions.ts +181 -5
  82. package/src/extendedSchemas.ts +116 -0
  83. package/src/fundingMeter.ts +188 -0
  84. package/src/giveaway.ts +182 -0
  85. package/src/index.ts +14 -0
  86. package/src/utils/__tests__/bashHostIdentity.test.ts +57 -0
  87. package/src/utils/__tests__/promoterCompetitionUtils.test.ts +128 -0
  88. package/src/utils/__tests__/slugUtils.test.ts +44 -0
  89. package/src/utils/bashHostIdentity.ts +30 -0
  90. package/src/utils/promoterCompetitionUtils.ts +235 -0
  91. package/src/utils/slugUtils.ts +11 -0
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Promoter Competition — pure utility functions for the Street Team / Promoter
3
+ * Competition workstream.
4
+ *
5
+ * No side effects, no DB imports — safe to import in bash-app (browser) and in api.
6
+ */
7
+ import { PromoterRewardMode, PromoterRewardType } from '../definitions.js';
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Shared input / output types
11
+ // ---------------------------------------------------------------------------
12
+
13
+ export interface PromoterMilestoneInput {
14
+ threshold?: number | null;
15
+ rank?: number | null;
16
+ rewardType: PromoterRewardType;
17
+ rewardAmountCents?: number | null;
18
+ rewardDescription?: string | null;
19
+ }
20
+
21
+ export interface PromoterCompetitionEconomics {
22
+ grossPotentialRevenueCents: number;
23
+ maxCashRewardExposureCents: number;
24
+ /** 0–100 range; maxCashReward / grossRevenue × 100, rounded to 1 decimal. */
25
+ effectiveAcquisitionCostPct: number;
26
+ /** gross − maxCashReward */
27
+ estimatedNetRevenueCents: number;
28
+ rewardBreakdown: Array<{
29
+ /** e.g. "5 sales → $15" or "Top 1 promoter → VIP access" */
30
+ label: string;
31
+ rewardAmountCents: number | null;
32
+ }>;
33
+ }
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // formatPromoterRewardLabel
37
+ // ---------------------------------------------------------------------------
38
+
39
+ /**
40
+ * Produces a single human-readable label for a promoter milestone.
41
+ *
42
+ * Examples:
43
+ * - threshold=5, CASH, rewardAmountCents=1500 → "5 sales → $15"
44
+ * - rank=1, TICKET, rewardDescription="VIP access" → "Top 1 promoter → VIP access"
45
+ * - threshold=10, TICKET, no description → "10 sales → TICKET"
46
+ */
47
+ export function formatPromoterRewardLabel(milestone: {
48
+ threshold?: number | null;
49
+ rank?: number | null;
50
+ rewardType: PromoterRewardType;
51
+ rewardAmountCents?: number | null;
52
+ rewardDescription?: string | null;
53
+ }): string {
54
+ const isCashOrCredit =
55
+ milestone.rewardType === PromoterRewardType.CASH ||
56
+ milestone.rewardType === PromoterRewardType.CREDIT;
57
+
58
+ const rewardDisplay = isCashOrCredit && milestone.rewardAmountCents != null
59
+ ? `$${(milestone.rewardAmountCents / 100).toLocaleString('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 2 })}`
60
+ : milestone.rewardDescription ?? milestone.rewardType;
61
+
62
+ if (milestone.rank != null) {
63
+ const ordinal = milestone.rank === 1 ? 'Top promoter' : `Top ${milestone.rank} promoter`;
64
+ return `${ordinal} → ${rewardDisplay}`;
65
+ }
66
+
67
+ const threshold = milestone.threshold ?? '?';
68
+ return `${threshold} sales → ${rewardDisplay}`;
69
+ }
70
+
71
+ // ---------------------------------------------------------------------------
72
+ // computePromoterCompetitionEconomics
73
+ // ---------------------------------------------------------------------------
74
+
75
+ /**
76
+ * Pure economics calculator for a PROMOTER competition.
77
+ *
78
+ * Lets hosts sanity-check their milestone structure before publishing:
79
+ * how much revenue could the event generate and what is the max cash
80
+ * payout exposure?
81
+ *
82
+ * Rank-based (rank != null) CASH/CREDIT milestones are always added to the
83
+ * max cash exposure regardless of rewardMode because they represent real
84
+ * monetary obligations (just settled at competition close, not per-sale).
85
+ */
86
+ export function computePromoterCompetitionEconomics(params: {
87
+ ticketPriceCents: number;
88
+ salesGoal: number;
89
+ milestones: PromoterMilestoneInput[];
90
+ rewardMode: PromoterRewardMode;
91
+ }): PromoterCompetitionEconomics {
92
+ const { ticketPriceCents, salesGoal, milestones, rewardMode } = params;
93
+
94
+ const grossPotentialRevenueCents = ticketPriceCents * salesGoal;
95
+
96
+ // Partition milestones into threshold-based and rank-based.
97
+ const isCash = (m: PromoterMilestoneInput): boolean =>
98
+ m.rewardType === PromoterRewardType.CASH ||
99
+ m.rewardType === PromoterRewardType.CREDIT;
100
+
101
+ const thresholdCash = milestones.filter(
102
+ (m) => m.rank == null && m.threshold != null && isCash(m) && m.rewardAmountCents != null
103
+ );
104
+ const rankCash = milestones.filter(
105
+ (m) => m.rank != null && isCash(m) && m.rewardAmountCents != null
106
+ );
107
+
108
+ let thresholdExposure = 0;
109
+ if (rewardMode === PromoterRewardMode.TOTAL_AT_MILESTONE) {
110
+ // Only the highest single threshold reward is effective at once.
111
+ thresholdExposure = Math.max(0, ...thresholdCash.map((m) => m.rewardAmountCents ?? 0));
112
+ } else {
113
+ // ADDITIVE — every threshold reward stacks.
114
+ thresholdExposure = thresholdCash.reduce(
115
+ (sum, m) => sum + (m.rewardAmountCents ?? 0),
116
+ 0
117
+ );
118
+ }
119
+
120
+ // Rank-based cash rewards always add on top (regardless of mode).
121
+ const rankExposure = rankCash.reduce(
122
+ (sum, m) => sum + (m.rewardAmountCents ?? 0),
123
+ 0
124
+ );
125
+
126
+ const maxCashRewardExposureCents = thresholdExposure + rankExposure;
127
+
128
+ const effectiveAcquisitionCostPct =
129
+ grossPotentialRevenueCents > 0
130
+ ? Math.round((maxCashRewardExposureCents / grossPotentialRevenueCents) * 1000) / 10
131
+ : 0;
132
+
133
+ const estimatedNetRevenueCents = grossPotentialRevenueCents - maxCashRewardExposureCents;
134
+
135
+ // Build rewardBreakdown — threshold milestones sorted ascending, rank milestones last.
136
+ const sortedMilestones = [...milestones].sort((a, b) => {
137
+ const aIsRank = a.rank != null;
138
+ const bIsRank = b.rank != null;
139
+ if (aIsRank && !bIsRank) return 1;
140
+ if (!aIsRank && bIsRank) return -1;
141
+ if (!aIsRank && !bIsRank) {
142
+ return (a.threshold ?? Infinity) - (b.threshold ?? Infinity);
143
+ }
144
+ // Both rank-based — sort by rank ascending.
145
+ return (a.rank ?? Infinity) - (b.rank ?? Infinity);
146
+ });
147
+
148
+ const rewardBreakdown = sortedMilestones.map((m) => ({
149
+ label: formatPromoterRewardLabel(m),
150
+ rewardAmountCents: m.rewardAmountCents ?? null,
151
+ }));
152
+
153
+ return {
154
+ grossPotentialRevenueCents,
155
+ maxCashRewardExposureCents,
156
+ effectiveAcquisitionCostPct,
157
+ estimatedNetRevenueCents,
158
+ rewardBreakdown,
159
+ };
160
+ }
161
+
162
+ // ---------------------------------------------------------------------------
163
+ // suggestPromoterSalesGoal
164
+ // ---------------------------------------------------------------------------
165
+
166
+ const SALES_GOAL_SNAP_POINTS = [25, 50, 75, 100, 150, 200] as const;
167
+
168
+ /**
169
+ * Suggests a sales goal for the promoter competition wizard.
170
+ *
171
+ * Logic: take 40–60% of remaining capacity (capacity − ticketsSold), then snap
172
+ * to the nearest common benchmark in [25, 50, 75, 100, 150, 200]. Returns null
173
+ * when data is insufficient (null inputs or capacity ≤ 0).
174
+ */
175
+ export function suggestPromoterSalesGoal(params: {
176
+ capacity: number | null;
177
+ ticketsSold: number | null;
178
+ }): number | null {
179
+ const { capacity, ticketsSold } = params;
180
+ if (capacity == null || capacity <= 0) return null;
181
+
182
+ const sold = ticketsSold ?? 0;
183
+ const remaining = Math.max(0, capacity - sold);
184
+ if (remaining === 0) return null;
185
+
186
+ // Target the midpoint of 40–60% of remaining.
187
+ const target = remaining * 0.5;
188
+
189
+ // Snap to the nearest benchmark.
190
+ let best: number = SALES_GOAL_SNAP_POINTS[0];
191
+ let bestDist = Math.abs(target - best);
192
+
193
+ for (const snap of SALES_GOAL_SNAP_POINTS) {
194
+ const dist = Math.abs(target - snap);
195
+ if (dist < bestDist) {
196
+ bestDist = dist;
197
+ best = snap;
198
+ }
199
+ }
200
+
201
+ return best;
202
+ }
203
+
204
+ // ---------------------------------------------------------------------------
205
+ // getPromoterReputationLabel
206
+ // ---------------------------------------------------------------------------
207
+
208
+ /**
209
+ * Produces a human-readable promoter reputation label based on lifetime stats.
210
+ * Returns null if the promoter has no completed events yet.
211
+ *
212
+ * Priority order (first match wins):
213
+ * 1. Competition winner (rank=1 achieved)
214
+ * 2. 100+ lifetime tickets sold
215
+ * 3. Repeat collaborator (worked with 2+ organizers more than once)
216
+ * 4. Experienced promoter (3+ events promoted)
217
+ * 5. Top seller within a competition (any milestone reached)
218
+ */
219
+ export function getPromoterReputationLabel(stats: {
220
+ lifetimeQualifiedTickets: number;
221
+ totalCompetitionsWon: number;
222
+ totalEventsPromoted: number;
223
+ repeatOrganizerCount: number;
224
+ totalMilestonesReached?: number;
225
+ }): string | null {
226
+ if (stats.totalEventsPromoted < 1) return null;
227
+
228
+ if (stats.totalCompetitionsWon >= 1) return 'Competition Winner';
229
+ if (stats.lifetimeQualifiedTickets >= 100) return '100+ Tickets Sold';
230
+ if (stats.repeatOrganizerCount >= 2) return 'Repeat Collaborator';
231
+ if (stats.totalEventsPromoted >= 3) return 'Experienced Promoter';
232
+ if ((stats.totalMilestonesReached ?? 0) >= 1) return 'Top Seller';
233
+
234
+ return null;
235
+ }
@@ -3,7 +3,9 @@ import {
3
3
  BASH_DETAIL_URL,
4
4
  BASH_EVENT_WIZARD_HOW_MAJOR_STEP,
5
5
  BASH_EVENT_WIZARD_HOW_SUBSTEP_PAYOUT,
6
+ BASH_EVENT_WIZARD_MAJOR,
6
7
  BASH_EVENT_WIZARD_PATH_PREFIX,
8
+ BASH_EVENT_WIZARD_TEMPLATES_SUBSTEP,
7
9
  } from '../definitions.js';
8
10
 
9
11
  type SlugifyOptions = {
@@ -112,6 +114,15 @@ export function getBashEventWizardPayoutStepPath(bashEventId: string): string {
112
114
  );
113
115
  }
114
116
 
117
+ /** Create / resume at Getting Started (Templates). Defaults to the `new` draft. */
118
+ export function getBashEventWizardStartPath(bashEventId = "new"): string {
119
+ return getBashEventWizardStepPath(
120
+ bashEventId,
121
+ BASH_EVENT_WIZARD_MAJOR.TEMPLATES,
122
+ BASH_EVENT_WIZARD_TEMPLATES_SUBSTEP.START
123
+ );
124
+ }
125
+
115
126
  export function parseBashUrlParams(param: string): { id: string; slug: string | null } | null {
116
127
  // Expected format: "id-slug" where id is first part before first dash
117
128
  const dashIndex = param.indexOf('-');