@bash-app/bash-common 30.431.0 → 30.433.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 (68) hide show
  1. package/dist/__tests__/bashSectionTitleForBashType.test.js +2 -0
  2. package/dist/__tests__/bashSectionTitleForBashType.test.js.map +1 -1
  3. package/dist/__tests__/discoveryScope.test.js +9 -1
  4. package/dist/__tests__/discoveryScope.test.js.map +1 -1
  5. package/dist/__tests__/promoCartEngine.test.d.ts +2 -0
  6. package/dist/__tests__/promoCartEngine.test.d.ts.map +1 -0
  7. package/dist/__tests__/promoCartEngine.test.js +174 -0
  8. package/dist/__tests__/promoCartEngine.test.js.map +1 -0
  9. package/dist/__tests__/promoCodeRedemption.test.d.ts +2 -0
  10. package/dist/__tests__/promoCodeRedemption.test.d.ts.map +1 -0
  11. package/dist/__tests__/promoCodeRedemption.test.js +103 -0
  12. package/dist/__tests__/promoCodeRedemption.test.js.map +1 -0
  13. package/dist/__tests__/promoCodeScope.test.d.ts +2 -0
  14. package/dist/__tests__/promoCodeScope.test.d.ts.map +1 -0
  15. package/dist/__tests__/promoCodeScope.test.js +77 -0
  16. package/dist/__tests__/promoCodeScope.test.js.map +1 -0
  17. package/dist/definitions.d.ts +3 -1
  18. package/dist/definitions.d.ts.map +1 -1
  19. package/dist/definitions.js +4 -2
  20. package/dist/definitions.js.map +1 -1
  21. package/dist/discoveryScope.d.ts +6 -6
  22. package/dist/discoveryScope.d.ts.map +1 -1
  23. package/dist/discoveryScope.js +25 -16
  24. package/dist/discoveryScope.js.map +1 -1
  25. package/dist/extendedSchemas.d.ts +1 -0
  26. package/dist/extendedSchemas.d.ts.map +1 -1
  27. package/dist/extendedSchemas.js.map +1 -1
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/promoCartEngine.d.ts +55 -0
  33. package/dist/promoCartEngine.d.ts.map +1 -0
  34. package/dist/promoCartEngine.js +135 -0
  35. package/dist/promoCartEngine.js.map +1 -0
  36. package/dist/promoCodeRedemption.d.ts +44 -0
  37. package/dist/promoCodeRedemption.d.ts.map +1 -0
  38. package/dist/promoCodeRedemption.js +81 -0
  39. package/dist/promoCodeRedemption.js.map +1 -0
  40. package/dist/promoCodeScope.d.ts +85 -0
  41. package/dist/promoCodeScope.d.ts.map +1 -0
  42. package/dist/promoCodeScope.js +93 -0
  43. package/dist/promoCodeScope.js.map +1 -0
  44. package/dist/utils/__tests__/discountEngine/discountCalculator.test.js +8 -1
  45. package/dist/utils/__tests__/discountEngine/discountCalculator.test.js.map +1 -1
  46. package/dist/utils/__tests__/paymentUtils.test.js +87 -4
  47. package/dist/utils/__tests__/paymentUtils.test.js.map +1 -1
  48. package/dist/utils/paymentUtils.d.ts +30 -5
  49. package/dist/utils/paymentUtils.d.ts.map +1 -1
  50. package/dist/utils/paymentUtils.js +43 -11
  51. package/dist/utils/paymentUtils.js.map +1 -1
  52. package/package.json +7 -3
  53. package/prisma/schema.prisma +106 -4
  54. package/src/__tests__/bashSectionTitleForBashType.test.ts +4 -0
  55. package/src/__tests__/discoveryScope.test.ts +22 -1
  56. package/src/__tests__/promoCartEngine.test.ts +201 -0
  57. package/src/__tests__/promoCodeRedemption.test.ts +134 -0
  58. package/src/__tests__/promoCodeScope.test.ts +106 -0
  59. package/src/definitions.ts +4 -2
  60. package/src/discoveryScope.ts +30 -20
  61. package/src/extendedSchemas.ts +1 -0
  62. package/src/index.ts +3 -0
  63. package/src/promoCartEngine.ts +193 -0
  64. package/src/promoCodeRedemption.ts +123 -0
  65. package/src/promoCodeScope.ts +164 -0
  66. package/src/utils/__tests__/discountEngine/discountCalculator.test.ts +8 -0
  67. package/src/utils/__tests__/paymentUtils.test.ts +100 -6
  68. package/src/utils/paymentUtils.ts +56 -13
@@ -448,12 +448,35 @@ export function lowestGuestAllInPriceCents(
448
448
  return min;
449
449
  }
450
450
 
451
- /** Max share of attributed ticket subtotal a host can assign to a performer (50%). */
452
- export const MAX_TICKET_COMMISSION_BPS = 5000;
451
+ /** A host can assign up to 100% of eligible net ticket proceeds to a promoter. */
452
+ export const MAX_TICKET_COMMISSION_BPS = 10_000;
453
453
 
454
454
  /**
455
- * Floor cents owed to a promo-code performer from the discounted ticket subtotal.
456
- * Guest price is unchanged; this amount is withheld from the host via application_fee.
455
+ * Cents left on the host transfer when withholding commission. Stripe test mode
456
+ * accepted application_fee_amount equal to the charge (check 4b, 2026-10-14),
457
+ * so a $0 host transfer is allowed and this stays 0. This is not a host share.
458
+ */
459
+ export const TEMPORARY_SETTLEMENT_SAFETY_REMAINDER_CENTS = 0;
460
+
461
+ /** Error message for an out-of-range rate, or null when 0-100% (0-10000 bps). */
462
+ export function ticketCommissionBpsError(
463
+ commissionBps: number | null | undefined
464
+ ): string | null {
465
+ if (commissionBps == null) return null;
466
+ if (!Number.isInteger(commissionBps)) {
467
+ return "Commission must be a whole number of basis points.";
468
+ }
469
+ if (commissionBps < 0 || commissionBps > MAX_TICKET_COMMISSION_BPS) {
470
+ return "Commission must be between 0% and 100% of eligible net ticket proceeds.";
471
+ }
472
+ return null;
473
+ }
474
+
475
+ /**
476
+ * Floor cents owed to a promoter: `commissionBps` of `basisCents`, where the basis
477
+ * is eligible net ticket proceeds. Guest price is unchanged; the amount is
478
+ * withheld from the host via application_fee. Rates are validated when written;
479
+ * this never pays more than 100% of the basis.
457
480
  */
458
481
  export function ticketCommissionCents(
459
482
  basisCents: number,
@@ -462,16 +485,34 @@ export function ticketCommissionCents(
462
485
  if (basisCents <= 0) return 0;
463
486
  const bps = Math.floor(Number(commissionBps) || 0);
464
487
  if (bps <= 0) return 0;
465
- const clamped = Math.min(MAX_TICKET_COMMISSION_BPS, bps);
466
- return Math.floor((basisCents * clamped) / 10_000);
488
+ return Math.floor((basisCents * Math.min(MAX_TICKET_COMMISSION_BPS, bps)) / 10_000);
467
489
  }
468
490
 
469
- export function clampTicketCommissionBps(
470
- commissionBps: number | null | undefined
471
- ): number {
472
- const bps = Math.floor(Number(commissionBps) || 0);
473
- if (bps <= 0) return 0;
474
- return Math.min(MAX_TICKET_COMMISSION_BPS, bps);
491
+ /**
492
+ * What the host would otherwise receive for the eligible ticket lines: the
493
+ * eligible discounted subtotal, less its share of the Bash platform fee and the
494
+ * Stripe processing estimate that no guest fee line pays. Tax, guest fee lines,
495
+ * coat check, and delivery are never part of it. Floored at 0.
496
+ */
497
+ export function eligibleNetTicketProceedsCents(args: {
498
+ /** Discounted subtotal of the lines the code applies to. */
499
+ eligibleSubtotalCents: number;
500
+ /** Discounted ticket subtotal of the whole cart (the fee basis). */
501
+ discountedSubtotalCents: number;
502
+ bashPlatformTotalCents: number;
503
+ guestPlatformLineCents: number;
504
+ stripeProcessingCents: number;
505
+ guestProcessingLineCents: number;
506
+ }): number {
507
+ const eligible = Math.max(0, Math.floor(args.eligibleSubtotalCents));
508
+ const cart = Math.max(0, Math.floor(args.discountedSubtotalCents));
509
+ if (eligible <= 0 || cart <= 0) return 0;
510
+ const share = Math.min(1, eligible / cart);
511
+ const hostPlatform = Math.max(0, args.bashPlatformTotalCents - args.guestPlatformLineCents);
512
+ const hostProcessing = Math.max(0, args.stripeProcessingCents - args.guestProcessingLineCents);
513
+ const net =
514
+ eligible - Math.ceil(hostPlatform * share) - Math.ceil(hostProcessing * share);
515
+ return Math.max(0, net);
475
516
  }
476
517
 
477
518
  /**
@@ -528,7 +569,9 @@ export function computeTicketApplicationFeeAmountCents(args: {
528
569
  );
529
570
  const maxWithhold = Math.max(
530
571
  0,
531
- breakdown.totalDueCents - breakdown.applicationFeeAmountCents - 1
572
+ breakdown.totalDueCents -
573
+ breakdown.applicationFeeAmountCents -
574
+ TEMPORARY_SETTLEMENT_SAFETY_REMAINDER_CENTS
532
575
  );
533
576
  const withheld = Math.min(performerCommissionCents, maxWithhold);
534
577
  return {