@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.
- package/dist/__tests__/statusEnums.test.js +88 -7
- package/dist/__tests__/statusEnums.test.js.map +1 -1
- package/dist/definitions.d.ts +39 -8
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +31 -10
- package/dist/definitions.js.map +1 -1
- package/dist/extendedSchemas.d.ts +6 -0
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/mirroredPrismaEnums.d.ts +145 -0
- package/dist/mirroredPrismaEnums.d.ts.map +1 -0
- package/dist/mirroredPrismaEnums.js +136 -0
- package/dist/mirroredPrismaEnums.js.map +1 -0
- package/dist/utils/__tests__/nonprofitUtils.test.d.ts +2 -0
- package/dist/utils/__tests__/nonprofitUtils.test.d.ts.map +1 -0
- package/dist/utils/__tests__/nonprofitUtils.test.js +84 -0
- package/dist/utils/__tests__/nonprofitUtils.test.js.map +1 -0
- package/dist/utils/__tests__/paymentUtils.test.js +87 -0
- package/dist/utils/__tests__/paymentUtils.test.js.map +1 -1
- package/dist/utils/nonprofitUtils.d.ts +21 -0
- package/dist/utils/nonprofitUtils.d.ts.map +1 -0
- package/dist/utils/nonprofitUtils.js +29 -0
- package/dist/utils/nonprofitUtils.js.map +1 -0
- package/dist/utils/paymentUtils.d.ts +23 -0
- package/dist/utils/paymentUtils.d.ts.map +1 -1
- package/dist/utils/paymentUtils.js +24 -7
- package/dist/utils/paymentUtils.js.map +1 -1
- package/dist/utils/service/__tests__/billingCapUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/billingCapUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/billingCapUtils.test.js +120 -0
- package/dist/utils/service/__tests__/billingCapUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/cancellationPolicyRefundResolver.test.js +1 -1
- package/dist/utils/service/__tests__/cancellationPolicyRefundResolver.test.js.map +1 -1
- package/dist/utils/service/__tests__/eventPromoterPhase3.test.d.ts +2 -0
- package/dist/utils/service/__tests__/eventPromoterPhase3.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/eventPromoterPhase3.test.js +243 -0
- package/dist/utils/service/__tests__/eventPromoterPhase3.test.js.map +1 -0
- package/dist/utils/service/__tests__/eventPromoterUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/eventPromoterUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/eventPromoterUtils.test.js +333 -0
- package/dist/utils/service/__tests__/eventPromoterUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/offerAllowListUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/offerAllowListUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/offerAllowListUtils.test.js +52 -0
- package/dist/utils/service/__tests__/offerAllowListUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/offerComparisonUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/offerComparisonUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/offerComparisonUtils.test.js +111 -0
- package/dist/utils/service/__tests__/offerComparisonUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.js +155 -0
- package/dist/utils/service/__tests__/serviceBookingExposureUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/unifiedPricingResolver.test.d.ts +2 -0
- package/dist/utils/service/__tests__/unifiedPricingResolver.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/unifiedPricingResolver.test.js +77 -0
- package/dist/utils/service/__tests__/unifiedPricingResolver.test.js.map +1 -0
- package/dist/utils/service/__tests__/venueFBSettlementUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/venueFBSettlementUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/venueFBSettlementUtils.test.js +157 -0
- package/dist/utils/service/__tests__/venueFBSettlementUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/venueSettlementUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/venueSettlementUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/venueSettlementUtils.test.js +175 -0
- package/dist/utils/service/__tests__/venueSettlementUtils.test.js.map +1 -0
- package/dist/utils/service/__tests__/volunteerCompensationUtils.test.d.ts +2 -0
- package/dist/utils/service/__tests__/volunteerCompensationUtils.test.d.ts.map +1 -0
- package/dist/utils/service/__tests__/volunteerCompensationUtils.test.js +118 -0
- package/dist/utils/service/__tests__/volunteerCompensationUtils.test.js.map +1 -0
- package/dist/utils/service/apiServiceBookingApiUtils.d.ts.map +1 -1
- package/dist/utils/service/apiServiceBookingApiUtils.js +4 -0
- package/dist/utils/service/apiServiceBookingApiUtils.js.map +1 -1
- package/dist/utils/service/billingCapUtils.d.ts +86 -0
- package/dist/utils/service/billingCapUtils.d.ts.map +1 -0
- package/dist/utils/service/billingCapUtils.js +96 -0
- package/dist/utils/service/billingCapUtils.js.map +1 -0
- package/dist/utils/service/cancellationPolicyRefundResolver.d.ts +1 -1
- package/dist/utils/service/cancellationPolicyRefundResolver.d.ts.map +1 -1
- package/dist/utils/service/cancellationPolicyRefundResolver.js +1 -1
- package/dist/utils/service/cancellationPolicyRefundResolver.js.map +1 -1
- package/dist/utils/service/eventPromoterUtils.d.ts +319 -0
- package/dist/utils/service/eventPromoterUtils.d.ts.map +1 -0
- package/dist/utils/service/eventPromoterUtils.js +372 -0
- package/dist/utils/service/eventPromoterUtils.js.map +1 -0
- package/dist/utils/service/offerAllowListUtils.d.ts +42 -0
- package/dist/utils/service/offerAllowListUtils.d.ts.map +1 -0
- package/dist/utils/service/offerAllowListUtils.js +49 -0
- package/dist/utils/service/offerAllowListUtils.js.map +1 -0
- package/dist/utils/service/offerComparisonUtils.d.ts +69 -0
- package/dist/utils/service/offerComparisonUtils.d.ts.map +1 -0
- package/dist/utils/service/offerComparisonUtils.js +110 -0
- package/dist/utils/service/offerComparisonUtils.js.map +1 -0
- package/dist/utils/service/serviceBookingExposureUtils.d.ts +111 -0
- package/dist/utils/service/serviceBookingExposureUtils.d.ts.map +1 -0
- package/dist/utils/service/serviceBookingExposureUtils.js +133 -0
- package/dist/utils/service/serviceBookingExposureUtils.js.map +1 -0
- package/dist/utils/service/serviceBookingTypes.d.ts +1 -1
- package/dist/utils/service/serviceBookingTypes.d.ts.map +1 -1
- package/dist/utils/service/serviceUtils.d.ts +2 -1
- package/dist/utils/service/serviceUtils.d.ts.map +1 -1
- package/dist/utils/service/serviceUtils.js +17 -16
- package/dist/utils/service/serviceUtils.js.map +1 -1
- package/dist/utils/service/unifiedPricingResolver.d.ts +67 -0
- package/dist/utils/service/unifiedPricingResolver.d.ts.map +1 -0
- package/dist/utils/service/unifiedPricingResolver.js +75 -0
- package/dist/utils/service/unifiedPricingResolver.js.map +1 -0
- package/dist/utils/service/venueFBSettlementUtils.d.ts +122 -0
- package/dist/utils/service/venueFBSettlementUtils.d.ts.map +1 -0
- package/dist/utils/service/venueFBSettlementUtils.js +106 -0
- package/dist/utils/service/venueFBSettlementUtils.js.map +1 -0
- package/dist/utils/service/venueSettlementUtils.d.ts +107 -0
- package/dist/utils/service/venueSettlementUtils.d.ts.map +1 -0
- package/dist/utils/service/venueSettlementUtils.js +117 -0
- package/dist/utils/service/venueSettlementUtils.js.map +1 -0
- package/dist/utils/service/volunteerCompensationUtils.d.ts +75 -0
- package/dist/utils/service/volunteerCompensationUtils.d.ts.map +1 -0
- package/dist/utils/service/volunteerCompensationUtils.js +88 -0
- package/dist/utils/service/volunteerCompensationUtils.js.map +1 -0
- package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.d.ts +2 -0
- package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.d.ts.map +1 -0
- package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.js +67 -0
- package/dist/utils/venueLoyalty/__tests__/eligibilityUtils.test.js.map +1 -0
- package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.d.ts +2 -0
- package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.d.ts.map +1 -0
- package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.js +71 -0
- package/dist/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.js.map +1 -0
- package/dist/utils/venueLoyalty/eligibilityUtils.d.ts +33 -0
- package/dist/utils/venueLoyalty/eligibilityUtils.d.ts.map +1 -0
- package/dist/utils/venueLoyalty/eligibilityUtils.js +49 -0
- package/dist/utils/venueLoyalty/eligibilityUtils.js.map +1 -0
- package/dist/utils/venueLoyalty/redemptionCodeUtils.d.ts +35 -0
- package/dist/utils/venueLoyalty/redemptionCodeUtils.d.ts.map +1 -0
- package/dist/utils/venueLoyalty/redemptionCodeUtils.js +74 -0
- package/dist/utils/venueLoyalty/redemptionCodeUtils.js.map +1 -0
- package/dist/venueLoyaltyRedemption.d.ts +146 -1
- package/dist/venueLoyaltyRedemption.d.ts.map +1 -1
- package/dist/venueLoyaltyRedemption.js +18 -2
- package/dist/venueLoyaltyRedemption.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +609 -214
- package/src/__tests__/statusEnums.test.ts +119 -11
- package/src/definitions.ts +57 -14
- package/src/extendedSchemas.ts +6 -0
- package/src/index.ts +16 -6
- package/src/mirroredPrismaEnums.ts +181 -0
- package/src/utils/__tests__/nonprofitUtils.test.ts +117 -0
- package/src/utils/__tests__/paymentUtils.test.ts +93 -0
- package/src/utils/nonprofitUtils.ts +44 -0
- package/src/utils/paymentUtils.ts +33 -7
- package/src/utils/service/__tests__/billingCapUtils.test.ts +175 -0
- package/src/utils/service/__tests__/cancellationPolicyRefundResolver.test.ts +1 -1
- package/src/utils/service/__tests__/eventPromoterPhase3.test.ts +296 -0
- package/src/utils/service/__tests__/eventPromoterUtils.test.ts +396 -0
- package/src/utils/service/__tests__/offerAllowListUtils.test.ts +76 -0
- package/src/utils/service/__tests__/offerComparisonUtils.test.ts +124 -0
- package/src/utils/service/__tests__/serviceBookingExposureUtils.test.ts +171 -0
- package/src/utils/service/__tests__/unifiedPricingResolver.test.ts +83 -0
- package/src/utils/service/__tests__/venueSettlementUtils.test.ts +219 -0
- package/src/utils/service/__tests__/volunteerCompensationUtils.test.ts +172 -0
- package/src/utils/service/apiServiceBookingApiUtils.ts +4 -0
- package/src/utils/service/billingCapUtils.ts +145 -0
- package/src/utils/service/cancellationPolicyRefundResolver.ts +1 -1
- package/src/utils/service/eventPromoterUtils.ts +644 -0
- package/src/utils/service/offerAllowListUtils.ts +81 -0
- package/src/utils/service/offerComparisonUtils.ts +197 -0
- package/src/utils/service/serviceBookingExposureUtils.ts +218 -0
- package/src/utils/service/serviceBookingTypes.ts +4 -0
- package/src/utils/service/serviceUtils.ts +18 -21
- package/src/utils/service/unifiedPricingResolver.ts +149 -0
- package/src/utils/service/venueSettlementUtils.ts +198 -0
- package/src/utils/service/volunteerCompensationUtils.ts +145 -0
- package/src/utils/venueLoyalty/__tests__/eligibilityUtils.test.ts +103 -0
- package/src/utils/venueLoyalty/__tests__/redemptionCodeUtils.test.ts +92 -0
- package/src/utils/venueLoyalty/eligibilityUtils.ts +84 -0
- package/src/utils/venueLoyalty/redemptionCodeUtils.ts +94 -0
- 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
|
+
}
|