@bash-app/bash-common 30.463.0 → 30.465.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 (48) hide show
  1. package/dist/__tests__/promoCodeScope.test.js +31 -1
  2. package/dist/__tests__/promoCodeScope.test.js.map +1 -1
  3. package/dist/__tests__/serviceSaveErrorMessages.test.js +4 -0
  4. package/dist/__tests__/serviceSaveErrorMessages.test.js.map +1 -1
  5. package/dist/__tests__/statusEnums.test.js +2 -0
  6. package/dist/__tests__/statusEnums.test.js.map +1 -1
  7. package/dist/definitions.d.ts +1 -1
  8. package/dist/definitions.d.ts.map +1 -1
  9. package/dist/extendedSchemas.d.ts +3 -0
  10. package/dist/extendedSchemas.d.ts.map +1 -1
  11. package/dist/extendedSchemas.js +4 -0
  12. package/dist/extendedSchemas.js.map +1 -1
  13. package/dist/feeDisplayCopy.d.ts +2 -2
  14. package/dist/feeDisplayCopy.d.ts.map +1 -1
  15. package/dist/feeDisplayCopy.js +2 -2
  16. package/dist/feeDisplayCopy.js.map +1 -1
  17. package/dist/membershipDefinitions.js +1 -1
  18. package/dist/membershipDefinitions.js.map +1 -1
  19. package/dist/mirroredPrismaEnums.d.ts +1 -0
  20. package/dist/mirroredPrismaEnums.d.ts.map +1 -1
  21. package/dist/mirroredPrismaEnums.js +1 -0
  22. package/dist/mirroredPrismaEnums.js.map +1 -1
  23. package/dist/promoCodeScope.d.ts +7 -0
  24. package/dist/promoCodeScope.d.ts.map +1 -1
  25. package/dist/promoCodeScope.js +36 -0
  26. package/dist/promoCodeScope.js.map +1 -1
  27. package/dist/serviceSaveErrorMessages.js +1 -1
  28. package/dist/serviceSaveErrorMessages.js.map +1 -1
  29. package/dist/utils/__tests__/crowdSizeValidation.test.js +2 -2
  30. package/dist/utils/__tests__/crowdSizeValidation.test.js.map +1 -1
  31. package/dist/utils/crowdSizeValidation.d.ts +2 -0
  32. package/dist/utils/crowdSizeValidation.d.ts.map +1 -1
  33. package/dist/utils/crowdSizeValidation.js +4 -2
  34. package/dist/utils/crowdSizeValidation.js.map +1 -1
  35. package/package.json +1 -1
  36. package/prisma/schema.prisma +1 -0
  37. package/src/__tests__/promoCodeScope.test.ts +36 -0
  38. package/src/__tests__/serviceSaveErrorMessages.test.ts +9 -0
  39. package/src/__tests__/statusEnums.test.ts +2 -0
  40. package/src/definitions.ts +1 -1
  41. package/src/extendedSchemas.ts +4 -0
  42. package/src/feeDisplayCopy.ts +2 -2
  43. package/src/membershipDefinitions.ts +1 -1
  44. package/src/mirroredPrismaEnums.ts +1 -0
  45. package/src/promoCodeScope.ts +55 -0
  46. package/src/serviceSaveErrorMessages.ts +1 -1
  47. package/src/utils/__tests__/crowdSizeValidation.test.ts +2 -2
  48. package/src/utils/crowdSizeValidation.ts +5 -2
@@ -1,3 +1,7 @@
1
+ import {
2
+ PROMO_CODE_REJECT_MESSAGES,
3
+ isPromoCodeRejectReason,
4
+ } from "./promoCodeRedemption.js";
1
5
  import { getPublicBashDetailPath } from "./utils/slugUtils.js";
2
6
 
3
7
  /**
@@ -86,6 +90,57 @@ export type PromoCodeStatus = {
86
90
  * id-slug path. The code is uppercased and URL-encoded. Legacy `?promocode=`
87
91
  * and `?ref=` links keep working on the bash page.
88
92
  */
93
+ /** Maps public GET promo-code-status into checkout pricing / cart engine fields. */
94
+ export function checkoutPromoFromPublicStatus(
95
+ bashEventId: string,
96
+ status: PromoCodeStatus
97
+ ): PromoScopeFields & {
98
+ code: string;
99
+ id: string;
100
+ discountAppliesToBashPoints?: boolean;
101
+ } | undefined {
102
+ if (status.status !== "valid" || !status.code.trim()) {
103
+ return undefined;
104
+ }
105
+ const discountType = status.discountType ?? "NONE";
106
+ const eligibilityMode = status.eligibilityMode ?? "ALL_TIERS";
107
+ const eligibleTierIds = status.eligibleTierIds ?? [];
108
+ return {
109
+ id: `public-status:${status.code}`,
110
+ code: status.code,
111
+ bashEventId,
112
+ discountType,
113
+ discountAmountPercentage:
114
+ discountType === "PERCENT" ? status.value : null,
115
+ discountAmountInCents:
116
+ discountType === "FIXED_CASH" ? status.value : null,
117
+ eligibilityMode,
118
+ eligibleTiers:
119
+ eligibilityMode === "SELECTED_TIERS"
120
+ ? eligibleTierIds.map((ticketTierId) => ({ ticketTierId }))
121
+ : [],
122
+ ticketTierId:
123
+ eligibilityMode === "SELECTED_TIERS" && eligibleTierIds.length === 1
124
+ ? eligibleTierIds[0]
125
+ : null,
126
+ discountAppliesToBashPoints: status.appliesToBashPoints,
127
+ };
128
+ }
129
+
130
+ export function promoRejectMessageFromPublicStatus(
131
+ status: PromoCodeStatus
132
+ ): string {
133
+ if (status.status === "valid") {
134
+ return PROMO_CODE_REJECT_MESSAGES.invalid;
135
+ }
136
+ const reason =
137
+ status.reason ??
138
+ (isPromoCodeRejectReason(status.status) ? status.status : "invalid");
139
+ return isPromoCodeRejectReason(reason)
140
+ ? PROMO_CODE_REJECT_MESSAGES[reason]
141
+ : PROMO_CODE_REJECT_MESSAGES.invalid;
142
+ }
143
+
89
144
  export function getPromoterShareUrl(args: {
90
145
  bashEventId: string;
91
146
  slug?: string | null;
@@ -47,7 +47,7 @@ export function userFacingServiceSaveError(raw: string): string {
47
47
  }
48
48
 
49
49
  if (
50
- /prisma|postgres|queryerror|database error|column .* does not exist|SQLSTATE/i.test(
50
+ /prisma|postgres|queryerror|database error|Foreign key constraint|Record to .+ does not exist|\bP20\d{2}\b|column .* does not exist|SQLSTATE/i.test(
51
51
  trimmed
52
52
  )
53
53
  ) {
@@ -1,3 +1,3 @@
1
1
  import { validateCrowdSize } from "../crowdSizeValidation";
2
- it.each([{ minimum: -5 }, { expected: 1e22 }, { ideal: 2.5 }, { minimum: 10, maximum: 5 }, { expected: 25, maximum: 10 }, { maximum: 0 }])("rejects invalid crowd sizes: %j", values => expect(validateCrowdSize(values)).not.toBeNull());
3
- it.each([{}, { minimum: null, maximum: null }, { minimum: 10, expected: 25, ideal: 35, maximum: 35 }])("accepts optional or consistent counts: %j", values => expect(validateCrowdSize(values)).toBeNull());
2
+ it.each([{ minimum: -5 }, { expected: 1e22 }, { expected: 999999999 }, { expected: 100001 }, { ideal: 2.5 }, { minimum: 10, maximum: 5 }, { expected: 25, maximum: 10 }, { maximum: 0 }])("rejects invalid crowd sizes: %j", values => expect(validateCrowdSize(values)).not.toBeNull());
3
+ it.each([{}, { minimum: null, maximum: null }, { minimum: 10, expected: 25, ideal: 35, maximum: 35 }, { expected: 100000 }])("accepts optional or consistent counts: %j", values => expect(validateCrowdSize(values)).toBeNull());
@@ -1,10 +1,13 @@
1
1
  export type CrowdSizeValues = { minimum?: number | null; ideal?: number | null; expected?: number | null; maximum?: number | null };
2
2
 
3
+ /** Matches the venue capacity ceiling the API enforces on listings. */
4
+ export const MAX_CROWD_SIZE = 100_000;
5
+
3
6
  export function validateCrowdSize(values: CrowdSizeValues): string | null {
4
7
  for (const key of ["minimum", "ideal", "expected", "maximum"] as const) {
5
8
  const value = values[key];
6
- if (value != null && (!Number.isInteger(value) || value < 0 || value > 2147483647)) {
7
- return "Guest counts must be non-negative whole numbers no larger than 2,147,483,647.";
9
+ if (value != null && (!Number.isInteger(value) || value < 0 || value > MAX_CROWD_SIZE)) {
10
+ return "Guest counts must be whole numbers from 0 to 100,000.";
8
11
  }
9
12
  if (key === "maximum" && value === 0) return "Maximum capacity must be at least 1, or leave it blank for no limit.";
10
13
  }