@bash-app/bash-common 30.236.0 → 30.238.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 (180) hide show
  1. package/dist/__tests__/statusEnums.test.js +88 -7
  2. package/dist/__tests__/statusEnums.test.js.map +1 -1
  3. package/dist/definitions.d.ts +39 -8
  4. package/dist/definitions.d.ts.map +1 -1
  5. package/dist/definitions.js +31 -10
  6. package/dist/definitions.js.map +1 -1
  7. package/dist/extendedSchemas.d.ts +6 -0
  8. package/dist/extendedSchemas.d.ts.map +1 -1
  9. package/dist/extendedSchemas.js.map +1 -1
  10. package/dist/index.d.ts +13 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +16 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/mirroredPrismaEnums.d.ts +145 -0
  15. package/dist/mirroredPrismaEnums.d.ts.map +1 -0
  16. package/dist/mirroredPrismaEnums.js +136 -0
  17. package/dist/mirroredPrismaEnums.js.map +1 -0
  18. package/dist/utils/__tests__/nonprofitUtils.test.d.ts +2 -0
  19. package/dist/utils/__tests__/nonprofitUtils.test.d.ts.map +1 -0
  20. package/dist/utils/__tests__/nonprofitUtils.test.js +84 -0
  21. package/dist/utils/__tests__/nonprofitUtils.test.js.map +1 -0
  22. package/dist/utils/__tests__/paymentUtils.test.js +87 -0
  23. package/dist/utils/__tests__/paymentUtils.test.js.map +1 -1
  24. package/dist/utils/nonprofitUtils.d.ts +21 -0
  25. package/dist/utils/nonprofitUtils.d.ts.map +1 -0
  26. package/dist/utils/nonprofitUtils.js +29 -0
  27. package/dist/utils/nonprofitUtils.js.map +1 -0
  28. package/dist/utils/paymentUtils.d.ts +23 -0
  29. package/dist/utils/paymentUtils.d.ts.map +1 -1
  30. package/dist/utils/paymentUtils.js +24 -7
  31. package/dist/utils/paymentUtils.js.map +1 -1
  32. package/dist/utils/service/__tests__/billingCapUtils.test.d.ts +2 -0
  33. package/dist/utils/service/__tests__/billingCapUtils.test.d.ts.map +1 -0
  34. package/dist/utils/service/__tests__/billingCapUtils.test.js +120 -0
  35. package/dist/utils/service/__tests__/billingCapUtils.test.js.map +1 -0
  36. package/dist/utils/service/__tests__/cancellationPolicyRefundResolver.test.js +1 -1
  37. package/dist/utils/service/__tests__/cancellationPolicyRefundResolver.test.js.map +1 -1
  38. package/dist/utils/service/__tests__/eventPromoterPhase3.test.d.ts +2 -0
  39. package/dist/utils/service/__tests__/eventPromoterPhase3.test.d.ts.map +1 -0
  40. package/dist/utils/service/__tests__/eventPromoterPhase3.test.js +243 -0
  41. package/dist/utils/service/__tests__/eventPromoterPhase3.test.js.map +1 -0
  42. package/dist/utils/service/__tests__/eventPromoterUtils.test.d.ts +2 -0
  43. package/dist/utils/service/__tests__/eventPromoterUtils.test.d.ts.map +1 -0
  44. package/dist/utils/service/__tests__/eventPromoterUtils.test.js +333 -0
  45. package/dist/utils/service/__tests__/eventPromoterUtils.test.js.map +1 -0
  46. package/dist/utils/service/__tests__/offerAllowListUtils.test.d.ts +2 -0
  47. package/dist/utils/service/__tests__/offerAllowListUtils.test.d.ts.map +1 -0
  48. package/dist/utils/service/__tests__/offerAllowListUtils.test.js +52 -0
  49. package/dist/utils/service/__tests__/offerAllowListUtils.test.js.map +1 -0
  50. package/dist/utils/service/__tests__/offerComparisonUtils.test.d.ts +2 -0
  51. package/dist/utils/service/__tests__/offerComparisonUtils.test.d.ts.map +1 -0
  52. package/dist/utils/service/__tests__/offerComparisonUtils.test.js +111 -0
  53. package/dist/utils/service/__tests__/offerComparisonUtils.test.js.map +1 -0
  54. package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.d.ts +2 -0
  55. package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.d.ts.map +1 -0
  56. package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.js +155 -0
  57. package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.js.map +1 -0
  58. package/dist/utils/service/__tests__/unifiedPricingResolver.test.d.ts +2 -0
  59. package/dist/utils/service/__tests__/unifiedPricingResolver.test.d.ts.map +1 -0
  60. package/dist/utils/service/__tests__/unifiedPricingResolver.test.js +77 -0
  61. package/dist/utils/service/__tests__/unifiedPricingResolver.test.js.map +1 -0
  62. package/dist/utils/service/__tests__/venueFBSettlementUtils.test.d.ts +2 -0
  63. package/dist/utils/service/__tests__/venueFBSettlementUtils.test.d.ts.map +1 -0
  64. package/dist/utils/service/__tests__/venueFBSettlementUtils.test.js +157 -0
  65. package/dist/utils/service/__tests__/venueFBSettlementUtils.test.js.map +1 -0
  66. package/dist/utils/service/__tests__/venueSettlementUtils.test.d.ts +2 -0
  67. package/dist/utils/service/__tests__/venueSettlementUtils.test.d.ts.map +1 -0
  68. package/dist/utils/service/__tests__/venueSettlementUtils.test.js +175 -0
  69. package/dist/utils/service/__tests__/venueSettlementUtils.test.js.map +1 -0
  70. package/dist/utils/service/__tests__/volunteerCompensationUtils.test.d.ts +2 -0
  71. package/dist/utils/service/__tests__/volunteerCompensationUtils.test.d.ts.map +1 -0
  72. package/dist/utils/service/__tests__/volunteerCompensationUtils.test.js +118 -0
  73. package/dist/utils/service/__tests__/volunteerCompensationUtils.test.js.map +1 -0
  74. package/dist/utils/service/apiServiceBookingApiUtils.d.ts.map +1 -1
  75. package/dist/utils/service/apiServiceBookingApiUtils.js +4 -0
  76. package/dist/utils/service/apiServiceBookingApiUtils.js.map +1 -1
  77. package/dist/utils/service/billingCapUtils.d.ts +86 -0
  78. package/dist/utils/service/billingCapUtils.d.ts.map +1 -0
  79. package/dist/utils/service/billingCapUtils.js +96 -0
  80. package/dist/utils/service/billingCapUtils.js.map +1 -0
  81. package/dist/utils/service/cancellationPolicyRefundResolver.d.ts +1 -1
  82. package/dist/utils/service/cancellationPolicyRefundResolver.d.ts.map +1 -1
  83. package/dist/utils/service/cancellationPolicyRefundResolver.js +1 -1
  84. package/dist/utils/service/cancellationPolicyRefundResolver.js.map +1 -1
  85. package/dist/utils/service/eventPromoterUtils.d.ts +319 -0
  86. package/dist/utils/service/eventPromoterUtils.d.ts.map +1 -0
  87. package/dist/utils/service/eventPromoterUtils.js +372 -0
  88. package/dist/utils/service/eventPromoterUtils.js.map +1 -0
  89. package/dist/utils/service/offerAllowListUtils.d.ts +42 -0
  90. package/dist/utils/service/offerAllowListUtils.d.ts.map +1 -0
  91. package/dist/utils/service/offerAllowListUtils.js +49 -0
  92. package/dist/utils/service/offerAllowListUtils.js.map +1 -0
  93. package/dist/utils/service/offerComparisonUtils.d.ts +69 -0
  94. package/dist/utils/service/offerComparisonUtils.d.ts.map +1 -0
  95. package/dist/utils/service/offerComparisonUtils.js +110 -0
  96. package/dist/utils/service/offerComparisonUtils.js.map +1 -0
  97. package/dist/utils/service/serviceBookingExposureUtils.d.ts +111 -0
  98. package/dist/utils/service/serviceBookingExposureUtils.d.ts.map +1 -0
  99. package/dist/utils/service/serviceBookingExposureUtils.js +133 -0
  100. package/dist/utils/service/serviceBookingExposureUtils.js.map +1 -0
  101. package/dist/utils/service/serviceBookingTypes.d.ts +1 -1
  102. package/dist/utils/service/serviceBookingTypes.d.ts.map +1 -1
  103. package/dist/utils/service/serviceUtils.d.ts +2 -1
  104. package/dist/utils/service/serviceUtils.d.ts.map +1 -1
  105. package/dist/utils/service/serviceUtils.js +17 -16
  106. package/dist/utils/service/serviceUtils.js.map +1 -1
  107. package/dist/utils/service/unifiedPricingResolver.d.ts +67 -0
  108. package/dist/utils/service/unifiedPricingResolver.d.ts.map +1 -0
  109. package/dist/utils/service/unifiedPricingResolver.js +75 -0
  110. package/dist/utils/service/unifiedPricingResolver.js.map +1 -0
  111. package/dist/utils/service/venueFBSettlementUtils.d.ts +122 -0
  112. package/dist/utils/service/venueFBSettlementUtils.d.ts.map +1 -0
  113. package/dist/utils/service/venueFBSettlementUtils.js +106 -0
  114. package/dist/utils/service/venueFBSettlementUtils.js.map +1 -0
  115. package/dist/utils/service/venueSettlementUtils.d.ts +107 -0
  116. package/dist/utils/service/venueSettlementUtils.d.ts.map +1 -0
  117. package/dist/utils/service/venueSettlementUtils.js +117 -0
  118. package/dist/utils/service/venueSettlementUtils.js.map +1 -0
  119. package/dist/utils/service/volunteerCompensationUtils.d.ts +75 -0
  120. package/dist/utils/service/volunteerCompensationUtils.d.ts.map +1 -0
  121. package/dist/utils/service/volunteerCompensationUtils.js +88 -0
  122. package/dist/utils/service/volunteerCompensationUtils.js.map +1 -0
  123. package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.d.ts +2 -0
  124. package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.d.ts.map +1 -0
  125. package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.js +67 -0
  126. package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.js.map +1 -0
  127. package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.d.ts +2 -0
  128. package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.d.ts.map +1 -0
  129. package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.js +71 -0
  130. package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.js.map +1 -0
  131. package/dist/utils/venueLoyalty/eligibilityUtils.d.ts +33 -0
  132. package/dist/utils/venueLoyalty/eligibilityUtils.d.ts.map +1 -0
  133. package/dist/utils/venueLoyalty/eligibilityUtils.js +49 -0
  134. package/dist/utils/venueLoyalty/eligibilityUtils.js.map +1 -0
  135. package/dist/utils/venueLoyalty/redemptionCodeUtils.d.ts +35 -0
  136. package/dist/utils/venueLoyalty/redemptionCodeUtils.d.ts.map +1 -0
  137. package/dist/utils/venueLoyalty/redemptionCodeUtils.js +74 -0
  138. package/dist/utils/venueLoyalty/redemptionCodeUtils.js.map +1 -0
  139. package/dist/venueLoyaltyRedemption.d.ts +146 -1
  140. package/dist/venueLoyaltyRedemption.d.ts.map +1 -1
  141. package/dist/venueLoyaltyRedemption.js +18 -2
  142. package/dist/venueLoyaltyRedemption.js.map +1 -1
  143. package/package.json +1 -1
  144. package/prisma/schema.prisma +609 -214
  145. package/src/__tests__/statusEnums.test.ts +119 -11
  146. package/src/definitions.ts +57 -14
  147. package/src/extendedSchemas.ts +6 -0
  148. package/src/index.ts +16 -6
  149. package/src/mirroredPrismaEnums.ts +181 -0
  150. package/src/utils/__tests__/nonprofitUtils.test.ts +117 -0
  151. package/src/utils/__tests__/paymentUtils.test.ts +93 -0
  152. package/src/utils/nonprofitUtils.ts +44 -0
  153. package/src/utils/paymentUtils.ts +33 -7
  154. package/src/utils/service/__tests__/billingCapUtils.test.ts +175 -0
  155. package/src/utils/service/__tests__/cancellationPolicyRefundResolver.test.ts +1 -1
  156. package/src/utils/service/__tests__/eventPromoterPhase3.test.ts +296 -0
  157. package/src/utils/service/__tests__/eventPromoterUtils.test.ts +396 -0
  158. package/src/utils/service/__tests__/offerAllowListUtils.test.ts +76 -0
  159. package/src/utils/service/__tests__/offerComparisonUtils.test.ts +124 -0
  160. package/src/utils/service/__tests__/serviceBookingExposureUtils.test.ts +171 -0
  161. package/src/utils/service/__tests__/unifiedPricingResolver.test.ts +83 -0
  162. package/src/utils/service/__tests__/venueSettlementUtils.test.ts +219 -0
  163. package/src/utils/service/__tests__/volunteerCompensationUtils.test.ts +172 -0
  164. package/src/utils/service/apiServiceBookingApiUtils.ts +4 -0
  165. package/src/utils/service/billingCapUtils.ts +145 -0
  166. package/src/utils/service/cancellationPolicyRefundResolver.ts +1 -1
  167. package/src/utils/service/eventPromoterUtils.ts +644 -0
  168. package/src/utils/service/offerAllowListUtils.ts +81 -0
  169. package/src/utils/service/offerComparisonUtils.ts +197 -0
  170. package/src/utils/service/serviceBookingExposureUtils.ts +218 -0
  171. package/src/utils/service/serviceBookingTypes.ts +4 -0
  172. package/src/utils/service/serviceUtils.ts +18 -21
  173. package/src/utils/service/unifiedPricingResolver.ts +149 -0
  174. package/src/utils/service/venueSettlementUtils.ts +198 -0
  175. package/src/utils/service/volunteerCompensationUtils.ts +145 -0
  176. package/src/utils/venueLoyalty/__tests__/eligibilityUtils.test.ts +103 -0
  177. package/src/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.ts +92 -0
  178. package/src/utils/venueLoyalty/eligibilityUtils.ts +84 -0
  179. package/src/utils/venueLoyalty/redemptionCodeUtils.ts +94 -0
  180. package/src/venueLoyaltyRedemption.ts +177 -2
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Phase 0 adoption guardrails — host-side soft cap on variable-pricing bookings.
3
+ *
4
+ * Any booking whose `pricingModel` is not flat/hourly/daily can run up the host's
5
+ * tab if turnout exceeds expectations. `maxBillableCents` lets the host put a
6
+ * dollar ceiling on each booking. The default ceiling is `1.5x` of
7
+ * `expectedAttendees * baseRateCents`, rounded up to the nearest $10 — generous
8
+ * enough that hosts almost never trip it on a good night, but tight enough to
9
+ * protect against a runaway viral bash.
10
+ *
11
+ * Snapshotted on `ServiceBooking.maxBillableCents` at booking time so settlement
12
+ * math stays stable even if platform defaults change.
13
+ *
14
+ * Kept dependency-free so the wizard, api validators, and offer-suggestion AI
15
+ * can share one source of truth.
16
+ */
17
+
18
+ /** Default ceiling multiplier on `expectedAttendees * baseRateCents`. */
19
+ export const DEFAULT_MAX_BILLABLE_MULTIPLIER = 1.5;
20
+
21
+ /** Default rounding granularity for the soft cap, in cents. ($10 = 1000 cents). */
22
+ export const DEFAULT_MAX_BILLABLE_ROUNDING_CENTS = 1000;
23
+
24
+ export interface DefaultMaxBillableCentsInput {
25
+ /**
26
+ * Expected attendees at booking time (snapshot from
27
+ * `bashEvent.expectedAttendees`). Zero / negative is treated as zero.
28
+ */
29
+ expectedAttendees: number | null | undefined;
30
+ /**
31
+ * Per-unit rate the booking is priced at (cents). For PER_ATTENDEE this is
32
+ * cents-per-attendee; for PER_PAID_ATTENDEE / PER_BASHPOINTS_ATTENDEE the
33
+ * caller passes the matching unit. Returns `null` when this is missing.
34
+ */
35
+ baseRateCents: number | null | undefined;
36
+ /**
37
+ * Optional override of the 1.5x multiplier (e.g. wizard lets host loosen the
38
+ * cap to 2x). Falls back to `DEFAULT_MAX_BILLABLE_MULTIPLIER`.
39
+ */
40
+ multiplier?: number;
41
+ /**
42
+ * Optional override of the rounding granularity in cents. Falls back to
43
+ * `DEFAULT_MAX_BILLABLE_ROUNDING_CENTS`.
44
+ */
45
+ roundingCents?: number;
46
+ }
47
+
48
+ /**
49
+ * Computes the default Phase 0 soft cap for a variable-pricing booking.
50
+ *
51
+ * Returns `null` when `baseRateCents` is unusable. Returns `0` when
52
+ * `expectedAttendees` is zero or absent — caller decides whether that means
53
+ * "skip the cap" (free / comp-only bash) or "force the host to set one explicitly".
54
+ *
55
+ * Worked example: 200 expected attendees @ $5 each → 200 * 500 * 1.5 = $1500 →
56
+ * already a multiple of $10 → cap = $1500. With 217 expected → 217 * 500 * 1.5
57
+ * = $1627.50 → round up to $1630.
58
+ */
59
+ export function defaultMaxBillableCents(
60
+ input: DefaultMaxBillableCentsInput
61
+ ): number | null {
62
+ const { baseRateCents } = input;
63
+ if (
64
+ baseRateCents == null ||
65
+ !Number.isFinite(baseRateCents) ||
66
+ baseRateCents <= 0
67
+ ) {
68
+ return null;
69
+ }
70
+ const expected = Math.max(0, Math.floor(input.expectedAttendees ?? 0));
71
+ const multiplier =
72
+ input.multiplier != null && input.multiplier > 0
73
+ ? input.multiplier
74
+ : DEFAULT_MAX_BILLABLE_MULTIPLIER;
75
+ const roundingCents =
76
+ input.roundingCents != null && input.roundingCents > 0
77
+ ? Math.floor(input.roundingCents)
78
+ : DEFAULT_MAX_BILLABLE_ROUNDING_CENTS;
79
+
80
+ const raw = expected * baseRateCents * multiplier;
81
+ if (raw <= 0) return 0;
82
+ return Math.ceil(raw / roundingCents) * roundingCents;
83
+ }
84
+
85
+ /**
86
+ * Parallel cap for `PER_BASHPOINTS_ATTENDEE` bookings — same formula, BashPoints
87
+ * units. Rounds up to the nearest 100 BashPoints by default since BashPoints
88
+ * are integer-only.
89
+ */
90
+ export function defaultMaxBillableBashPoints(input: {
91
+ expectedAttendees: number | null | undefined;
92
+ baseRateBashPoints: number | null | undefined;
93
+ multiplier?: number;
94
+ /** Defaults to 100 BashPoints. */
95
+ roundingBashPoints?: number;
96
+ }): number | null {
97
+ const { baseRateBashPoints } = input;
98
+ if (
99
+ baseRateBashPoints == null ||
100
+ !Number.isFinite(baseRateBashPoints) ||
101
+ baseRateBashPoints <= 0
102
+ ) {
103
+ return null;
104
+ }
105
+ const expected = Math.max(0, Math.floor(input.expectedAttendees ?? 0));
106
+ const multiplier =
107
+ input.multiplier != null && input.multiplier > 0
108
+ ? input.multiplier
109
+ : DEFAULT_MAX_BILLABLE_MULTIPLIER;
110
+ const rounding =
111
+ input.roundingBashPoints != null && input.roundingBashPoints > 0
112
+ ? Math.floor(input.roundingBashPoints)
113
+ : 100;
114
+ const raw = expected * baseRateBashPoints * multiplier;
115
+ if (raw <= 0) return 0;
116
+ return Math.ceil(raw / rounding) * rounding;
117
+ }
118
+
119
+ /**
120
+ * Default snippet to snapshot onto `ServiceBooking.payoutTimingNote` at booking
121
+ * time for any variable-pricing booking. Keep concise — surfaces in offer
122
+ * sheets, booking detail, and email summaries.
123
+ */
124
+ export const DEFAULT_VARIABLE_PAYOUT_TIMING_NOTE =
125
+ "Variable pricing payout: final settlement ~3 business days after the bash, after attendee numbers are locked.";
126
+
127
+ /**
128
+ * Pricing models that DO NOT need a `maxBillableCents` guardrail because the
129
+ * total is known at booking time. Used by the wizard to decide whether to
130
+ * surface the cap editor + payout-timing copy.
131
+ */
132
+ export const FLAT_PRICING_MODELS = ["FLAT_FEE", "HOURLY", "PER_DAY"] as const;
133
+
134
+ export type FlatPricingModel = (typeof FLAT_PRICING_MODELS)[number];
135
+
136
+ /**
137
+ * Returns true if the given pricing-model string is one of the FLAT models
138
+ * that don't need a variable-pricing cap or payout-timing banner.
139
+ */
140
+ export function isFlatPricingModel(
141
+ model: string | null | undefined
142
+ ): model is FlatPricingModel {
143
+ if (!model) return false;
144
+ return (FLAT_PRICING_MODELS as readonly string[]).includes(model);
145
+ }
@@ -1,4 +1,4 @@
1
- import { ServiceCancellationPolicy } from "@prisma/client";
1
+ import { ServiceCancellationPolicy } from "../../mirroredPrismaEnums.js";
2
2
  import {
3
3
  SERVICE_CANCELLATION_POLICY_DATA,
4
4
  type ServiceCancellationRefundPolicy,