@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.
- package/dist/__tests__/promoCodeScope.test.js +31 -1
- package/dist/__tests__/promoCodeScope.test.js.map +1 -1
- package/dist/__tests__/serviceSaveErrorMessages.test.js +4 -0
- package/dist/__tests__/serviceSaveErrorMessages.test.js.map +1 -1
- package/dist/__tests__/statusEnums.test.js +2 -0
- package/dist/__tests__/statusEnums.test.js.map +1 -1
- package/dist/definitions.d.ts +1 -1
- package/dist/definitions.d.ts.map +1 -1
- package/dist/extendedSchemas.d.ts +3 -0
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js +4 -0
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/feeDisplayCopy.d.ts +2 -2
- package/dist/feeDisplayCopy.d.ts.map +1 -1
- package/dist/feeDisplayCopy.js +2 -2
- package/dist/feeDisplayCopy.js.map +1 -1
- package/dist/membershipDefinitions.js +1 -1
- package/dist/membershipDefinitions.js.map +1 -1
- package/dist/mirroredPrismaEnums.d.ts +1 -0
- package/dist/mirroredPrismaEnums.d.ts.map +1 -1
- package/dist/mirroredPrismaEnums.js +1 -0
- package/dist/mirroredPrismaEnums.js.map +1 -1
- package/dist/promoCodeScope.d.ts +7 -0
- package/dist/promoCodeScope.d.ts.map +1 -1
- package/dist/promoCodeScope.js +36 -0
- package/dist/promoCodeScope.js.map +1 -1
- package/dist/serviceSaveErrorMessages.js +1 -1
- package/dist/serviceSaveErrorMessages.js.map +1 -1
- package/dist/utils/__tests__/crowdSizeValidation.test.js +2 -2
- package/dist/utils/__tests__/crowdSizeValidation.test.js.map +1 -1
- package/dist/utils/crowdSizeValidation.d.ts +2 -0
- package/dist/utils/crowdSizeValidation.d.ts.map +1 -1
- package/dist/utils/crowdSizeValidation.js +4 -2
- package/dist/utils/crowdSizeValidation.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +1 -0
- package/src/__tests__/promoCodeScope.test.ts +36 -0
- package/src/__tests__/serviceSaveErrorMessages.test.ts +9 -0
- package/src/__tests__/statusEnums.test.ts +2 -0
- package/src/definitions.ts +1 -1
- package/src/extendedSchemas.ts +4 -0
- package/src/feeDisplayCopy.ts +2 -2
- package/src/membershipDefinitions.ts +1 -1
- package/src/mirroredPrismaEnums.ts +1 -0
- package/src/promoCodeScope.ts +55 -0
- package/src/serviceSaveErrorMessages.ts +1 -1
- package/src/utils/__tests__/crowdSizeValidation.test.ts +2 -2
- package/src/utils/crowdSizeValidation.ts +5 -2
package/src/promoCodeScope.ts
CHANGED
|
@@ -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 >
|
|
7
|
-
return "Guest counts must be
|
|
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
|
}
|