@bash-app/bash-common 30.333.0 → 30.334.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__/causeTags.test.d.ts +2 -0
- package/dist/__tests__/causeTags.test.d.ts.map +1 -0
- package/dist/__tests__/causeTags.test.js +94 -0
- package/dist/__tests__/causeTags.test.js.map +1 -0
- package/dist/__tests__/hostCrmGrowthPack.test.js +12 -2
- package/dist/__tests__/hostCrmGrowthPack.test.js.map +1 -1
- package/dist/causeTags.d.ts +42 -0
- package/dist/causeTags.d.ts.map +1 -0
- package/dist/causeTags.js +173 -0
- package/dist/causeTags.js.map +1 -0
- package/dist/definitions.d.ts +23 -0
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +28 -0
- package/dist/definitions.js.map +1 -1
- package/dist/hostCrmAutomation.d.ts +12 -2
- package/dist/hostCrmAutomation.d.ts.map +1 -1
- package/dist/hostCrmAutomation.js +16 -2
- package/dist/hostCrmAutomation.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/sms/smsTemplates.d.ts +6 -1
- package/dist/sms/smsTemplates.d.ts.map +1 -1
- package/dist/sms/smsTemplates.js +1 -0
- package/dist/sms/smsTemplates.js.map +1 -1
- package/dist/utils/__tests__/coatCheckUtils.test.d.ts +2 -0
- package/dist/utils/__tests__/coatCheckUtils.test.d.ts.map +1 -0
- package/dist/utils/__tests__/coatCheckUtils.test.js +76 -0
- package/dist/utils/__tests__/coatCheckUtils.test.js.map +1 -0
- package/dist/utils/coatCheckUtils.d.ts +30 -0
- package/dist/utils/coatCheckUtils.d.ts.map +1 -0
- package/dist/utils/coatCheckUtils.js +85 -0
- package/dist/utils/coatCheckUtils.js.map +1 -0
- package/dist/utils/slugUtils.d.ts +3 -4
- package/dist/utils/slugUtils.d.ts.map +1 -1
- package/dist/utils/slugUtils.js +3 -4
- package/dist/utils/slugUtils.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +429 -3
- package/src/__tests__/causeTags.test.ts +143 -0
- package/src/__tests__/hostCrmGrowthPack.test.ts +14 -1
- package/src/causeTags.ts +243 -0
- package/src/definitions.ts +46 -0
- package/src/hostCrmAutomation.ts +25 -2
- package/src/index.ts +2 -0
- package/src/sms/smsTemplates.ts +6 -0
- package/src/utils/__tests__/coatCheckUtils.test.ts +110 -0
- package/src/utils/coatCheckUtils.ts +134 -0
- package/src/utils/slugUtils.ts +3 -4
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COAT_CHECK_ENTITLEMENT_STATUSES,
|
|
3
|
+
COAT_CHECK_QR_TYPE,
|
|
4
|
+
COAT_CHECK_SCAN_OUTCOMES,
|
|
5
|
+
COAT_CHECK_SLOT_OCCUPYING_STATUSES,
|
|
6
|
+
type CoatCheckEntitlementStatusName,
|
|
7
|
+
type CoatCheckScanOutcome,
|
|
8
|
+
} from "../definitions.js";
|
|
9
|
+
|
|
10
|
+
export type CoatCheckQrPayload = {
|
|
11
|
+
type: typeof COAT_CHECK_QR_TYPE;
|
|
12
|
+
eventId: string;
|
|
13
|
+
entitlementId: string;
|
|
14
|
+
qrToken: string;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function encodeCoatCheckQrPayload(args: {
|
|
19
|
+
eventId: string;
|
|
20
|
+
entitlementId: string;
|
|
21
|
+
qrToken: string;
|
|
22
|
+
}): string {
|
|
23
|
+
const payload: CoatCheckQrPayload = {
|
|
24
|
+
type: COAT_CHECK_QR_TYPE,
|
|
25
|
+
eventId: args.eventId,
|
|
26
|
+
entitlementId: args.entitlementId,
|
|
27
|
+
qrToken: args.qrToken,
|
|
28
|
+
timestamp: Date.now(),
|
|
29
|
+
};
|
|
30
|
+
return JSON.stringify(payload);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function parseCoatCheckQrPayload(
|
|
34
|
+
raw: string
|
|
35
|
+
): CoatCheckQrPayload | null {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(raw) as Partial<CoatCheckQrPayload>;
|
|
38
|
+
if (
|
|
39
|
+
parsed?.type !== COAT_CHECK_QR_TYPE ||
|
|
40
|
+
typeof parsed.eventId !== "string" ||
|
|
41
|
+
typeof parsed.entitlementId !== "string" ||
|
|
42
|
+
typeof parsed.qrToken !== "string"
|
|
43
|
+
) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
type: COAT_CHECK_QR_TYPE,
|
|
48
|
+
eventId: parsed.eventId,
|
|
49
|
+
entitlementId: parsed.entitlementId,
|
|
50
|
+
qrToken: parsed.qrToken,
|
|
51
|
+
timestamp:
|
|
52
|
+
typeof parsed.timestamp === "number" ? parsed.timestamp : Date.now(),
|
|
53
|
+
};
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function coatCheckScanOutcomeForStatus(
|
|
60
|
+
status: CoatCheckEntitlementStatusName
|
|
61
|
+
): CoatCheckScanOutcome {
|
|
62
|
+
switch (status) {
|
|
63
|
+
case "Paid":
|
|
64
|
+
return "ready_for_dropoff";
|
|
65
|
+
case "CheckedIn":
|
|
66
|
+
return "ready_for_claim";
|
|
67
|
+
case "Claimed":
|
|
68
|
+
return "already_claimed";
|
|
69
|
+
case "Refunded":
|
|
70
|
+
case "Cancelled":
|
|
71
|
+
return "cancelled_or_refunded";
|
|
72
|
+
default:
|
|
73
|
+
return "invalid_or_expired";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function canTransitionCoatCheckStatus(
|
|
78
|
+
from: CoatCheckEntitlementStatusName,
|
|
79
|
+
to: CoatCheckEntitlementStatusName
|
|
80
|
+
): boolean {
|
|
81
|
+
if (from === to) return false;
|
|
82
|
+
if (from === "Paid" && to === "CheckedIn") return true;
|
|
83
|
+
if (from === "CheckedIn" && to === "Claimed") return true;
|
|
84
|
+
if (
|
|
85
|
+
(from === "Paid" || from === "CheckedIn") &&
|
|
86
|
+
(to === "Refunded" || to === "Cancelled")
|
|
87
|
+
) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function isCoatCheckSlotOccupyingStatus(
|
|
94
|
+
status: string
|
|
95
|
+
): status is CoatCheckEntitlementStatusName {
|
|
96
|
+
return (COAT_CHECK_SLOT_OCCUPYING_STATUSES as readonly string[]).includes(
|
|
97
|
+
status
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function isCoatCheckEntitlementStatus(
|
|
102
|
+
status: string
|
|
103
|
+
): status is CoatCheckEntitlementStatusName {
|
|
104
|
+
return (COAT_CHECK_ENTITLEMENT_STATUSES as readonly string[]).includes(status);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function assertCoatCheckScanOutcome(
|
|
108
|
+
outcome: string
|
|
109
|
+
): outcome is CoatCheckScanOutcome {
|
|
110
|
+
return (COAT_CHECK_SCAN_OUTCOMES as readonly string[]).includes(outcome);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Remaining slots; null capacity = unlimited (Infinity for math). */
|
|
114
|
+
export function remainingCoatCheckSlots(args: {
|
|
115
|
+
capacity: number | null | undefined;
|
|
116
|
+
occupiedCount: number;
|
|
117
|
+
}): number | null {
|
|
118
|
+
if (args.capacity == null) return null;
|
|
119
|
+
return Math.max(0, args.capacity - args.occupiedCount);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function clampCoatCheckPurchaseQty(args: {
|
|
123
|
+
requested: number;
|
|
124
|
+
maxPerPurchase: number;
|
|
125
|
+
remainingSlots: number | null;
|
|
126
|
+
}): number {
|
|
127
|
+
const maxPer = Math.max(1, args.maxPerPurchase || 1);
|
|
128
|
+
let qty = Math.max(0, Math.floor(args.requested));
|
|
129
|
+
qty = Math.min(qty, maxPer);
|
|
130
|
+
if (args.remainingSlots != null) {
|
|
131
|
+
qty = Math.min(qty, args.remainingSlots);
|
|
132
|
+
}
|
|
133
|
+
return qty;
|
|
134
|
+
}
|
package/src/utils/slugUtils.ts
CHANGED
|
@@ -53,10 +53,9 @@ export function getPublicBashDetailPath(
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* link works for people who aren't signed in yet.
|
|
56
|
+
* Path to Your Memories (private vault) for a bash — nested under bash detail
|
|
57
|
+
* (`/bash/{id}-{slug}/memories`). Requires sign-in + eligibility; not a public
|
|
58
|
+
* unauthenticated recap page.
|
|
60
59
|
*/
|
|
61
60
|
export function getPublicBashMemoriesPath(
|
|
62
61
|
bashEventId: string,
|