@bash-app/bash-common 30.465.0 → 30.467.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 (54) hide show
  1. package/dist/extendedSchemas.d.ts +35 -0
  2. package/dist/extendedSchemas.d.ts.map +1 -1
  3. package/dist/extendedSchemas.js +3 -0
  4. package/dist/extendedSchemas.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/membershipDefinitions.js +2 -2
  10. package/dist/membershipDefinitions.js.map +1 -1
  11. package/dist/utils/__tests__/addressUtils.test.js +3 -0
  12. package/dist/utils/__tests__/addressUtils.test.js.map +1 -1
  13. package/dist/utils/__tests__/crowdSizeValidation.test.js +1 -1
  14. package/dist/utils/__tests__/crowdSizeValidation.test.js.map +1 -1
  15. package/dist/utils/__tests__/eventTaskVolunteerRewardUtils.test.js +6 -0
  16. package/dist/utils/__tests__/eventTaskVolunteerRewardUtils.test.js.map +1 -1
  17. package/dist/utils/__tests__/guestSurface.test.js +24 -0
  18. package/dist/utils/__tests__/guestSurface.test.js.map +1 -1
  19. package/dist/utils/addressUtils.d.ts.map +1 -1
  20. package/dist/utils/addressUtils.js +28 -10
  21. package/dist/utils/addressUtils.js.map +1 -1
  22. package/dist/utils/crowdSizeValidation.d.ts.map +1 -1
  23. package/dist/utils/crowdSizeValidation.js +10 -0
  24. package/dist/utils/crowdSizeValidation.js.map +1 -1
  25. package/dist/utils/eventTimezoneIana.d.ts.map +1 -1
  26. package/dist/utils/eventTimezoneIana.js +16 -5
  27. package/dist/utils/eventTimezoneIana.js.map +1 -1
  28. package/dist/utils/guestSurface.d.ts +3 -1
  29. package/dist/utils/guestSurface.d.ts.map +1 -1
  30. package/dist/utils/guestSurface.js +26 -1
  31. package/dist/utils/guestSurface.js.map +1 -1
  32. package/dist/utils/service/__tests__/vendorPaymentWays.test.d.ts +2 -0
  33. package/dist/utils/service/__tests__/vendorPaymentWays.test.d.ts.map +1 -0
  34. package/dist/utils/service/__tests__/vendorPaymentWays.test.js +61 -0
  35. package/dist/utils/service/__tests__/vendorPaymentWays.test.js.map +1 -0
  36. package/dist/utils/service/vendorPaymentWays.d.ts +83 -0
  37. package/dist/utils/service/vendorPaymentWays.d.ts.map +1 -0
  38. package/dist/utils/service/vendorPaymentWays.js +306 -0
  39. package/dist/utils/service/vendorPaymentWays.js.map +1 -0
  40. package/package.json +1 -1
  41. package/prisma/schema.prisma +97 -1
  42. package/src/extendedSchemas.ts +3 -0
  43. package/src/index.ts +1 -0
  44. package/src/membershipDefinitions.ts +2 -2
  45. package/src/utils/__tests__/addressUtils.test.ts +6 -0
  46. package/src/utils/__tests__/crowdSizeValidation.test.ts +1 -1
  47. package/src/utils/__tests__/eventTaskVolunteerRewardUtils.test.ts +8 -0
  48. package/src/utils/__tests__/guestSurface.test.ts +29 -0
  49. package/src/utils/addressUtils.ts +26 -10
  50. package/src/utils/crowdSizeValidation.ts +14 -0
  51. package/src/utils/eventTimezoneIana.ts +22 -10
  52. package/src/utils/guestSurface.ts +33 -6
  53. package/src/utils/service/__tests__/vendorPaymentWays.test.ts +87 -0
  54. package/src/utils/service/vendorPaymentWays.ts +384 -0
@@ -39,12 +39,20 @@ describe("eventTaskVolunteerRewardUtils", () => {
39
39
  { id: "t2", neededCount: 1, bashPointsReward: 50 },
40
40
  ];
41
41
  expect(totalEventTaskBashPointsOffer({ tasks })).toBe(70);
42
+ // 2 * 10 + 1 * 80 = 100. Matching the balance is allowed; one point over is not.
42
43
  expect(
43
44
  validateHostTaskBashPointsOffer({
44
45
  hostBashPointsBalance: 100,
45
46
  tasks,
46
47
  patch: { taskId: "t2", bashPointsReward: 80 },
47
48
  }).ok
49
+ ).toBe(true);
50
+ expect(
51
+ validateHostTaskBashPointsOffer({
52
+ hostBashPointsBalance: 100,
53
+ tasks,
54
+ patch: { taskId: "t2", bashPointsReward: 81 },
55
+ }).ok
48
56
  ).toBe(false);
49
57
  expect(
50
58
  validateHostTaskBashPointsOffer({
@@ -50,6 +50,15 @@ describe("resolveEffectiveEventMode", () => {
50
50
  resolveEffectiveEventMode({ attendeeDisplayMode: "CountOnly" })
51
51
  ).toBe("CountOnly");
52
52
  });
53
+
54
+ it("honours Blurred ahead of the legacy show-attendees flag", () => {
55
+ expect(
56
+ resolveEffectiveEventMode({
57
+ attendeeDisplayMode: "Blurred",
58
+ showAttendees: true,
59
+ })
60
+ ).toBe("Blurred");
61
+ });
53
62
  });
54
63
 
55
64
  describe("resolveGuestSurfacePolicy", () => {
@@ -64,6 +73,21 @@ describe("resolveGuestSurfacePolicy", () => {
64
73
  expect(policy.showPreviewAvatars).toBe(false);
65
74
  });
66
75
 
76
+ it("Blurred shows faces without a headcount or roster for guests", () => {
77
+ const policy = resolveGuestSurfacePolicy({
78
+ eventMode: "Blurred",
79
+ isHost: false,
80
+ isAuthenticated: true,
81
+ viewerRosterDepth: "Full",
82
+ });
83
+ expect(policy.showCount).toBe(false);
84
+ expect(policy.showPreviewAvatars).toBe(true);
85
+ expect(policy.showFeatured).toBe(false);
86
+ expect(policy.showNetworkSlice).toBe(false);
87
+ expect(policy.rosterDepth).toBe("None");
88
+ expect(policy.apiPreviewLimit).toBe(5);
89
+ });
90
+
67
91
  it("CountOnly shows count but not avatars", () => {
68
92
  const policy = resolveGuestSurfacePolicy({
69
93
  eventMode: "CountOnly",
@@ -146,6 +170,11 @@ describe("capRosterDepthForEventMode", () => {
146
170
  capRosterDepthForEventMode("Full", "NetworkOnly", false)
147
171
  ).toBe("None");
148
172
  });
173
+
174
+ it("caps guests to None when faces are blurred", () => {
175
+ expect(capRosterDepthForEventMode("Full", "Blurred", false)).toBe("None");
176
+ expect(capRosterDepthForEventMode("Full", "Blurred", true)).toBe("Full");
177
+ });
149
178
  });
150
179
 
151
180
  describe("filterHiddenVisibilityUserIds", () => {
@@ -111,6 +111,24 @@ export function databaseAddressStringToAddressValues(addressString: string | und
111
111
  }
112
112
 
113
113
 
114
+ /** Drop repeated place names ("Salt Lake City, Salt Lake City, UT"). */
115
+ function uniqueAddressParts(parts: Array<string | null | undefined>): string[] {
116
+ const out: string[] = [];
117
+ const seen = new Set<string>();
118
+ for (const part of parts) {
119
+ if (!part) continue;
120
+ for (const segment of part.split(",")) {
121
+ const trimmed = segment.trim();
122
+ if (!trimmed || trimmed === "undefined") continue;
123
+ const key = trimmed.toLowerCase();
124
+ if (seen.has(key)) continue;
125
+ seen.add(key);
126
+ out.push(trimmed);
127
+ }
128
+ }
129
+ return out;
130
+ }
131
+
114
132
  /**
115
133
  * City, state/region, and country for compact card/list UIs (no street or full formatted address).
116
134
  * Detail pages should use {@link databaseAddressStringToOneLineString} or full address fields.
@@ -120,10 +138,7 @@ export function formatLocalityForCardDisplay(
120
138
  state?: string | null,
121
139
  country?: string | null
122
140
  ): string {
123
- const parts = [city?.trim(), state?.trim(), country?.trim()].filter(
124
- (p): p is string => !!p && p.length > 0
125
- );
126
- return parts.join(", ");
141
+ return uniqueAddressParts([city, state, country]).join(", ");
127
142
  }
128
143
 
129
144
  export function databaseAddressStringToOneLineString(addressString: string | undefined | null): string {
@@ -142,13 +157,14 @@ export function databaseAddressStringToOneLineString(addressString: string | und
142
157
  return address.place.trim();
143
158
  }
144
159
 
145
- let addressArr = address.place ? [address.place] : [];
146
-
147
- if (address.street && address.street !== 'undefined') addressArr.push(address.street);
148
- if (address.city && address.city !== 'undefined') addressArr.push(address.city);
149
- if (address.state && address.state !== 'undefined') addressArr.push(address.state);
160
+ const addressArr = uniqueAddressParts([
161
+ address.place,
162
+ address.street,
163
+ address.city,
164
+ address.state,
165
+ ]);
150
166
 
151
- const addressStr = addressArr.filter((str) => !!str && str !== 'undefined').join(', ');
167
+ const addressStr = addressArr.join(', ');
152
168
 
153
169
  return address.zipCode && address.zipCode !== 'undefined'
154
170
  ? `${addressStr} ${address.zipCode}`
@@ -17,5 +17,19 @@ export function validateCrowdSize(values: CrowdSizeValues): string | null {
17
17
  if (value != null && value > values.maximum) return `Maximum capacity cannot be lower than ${key} guests.`;
18
18
  }
19
19
  }
20
+ if (
21
+ values.minimum != null &&
22
+ values.expected != null &&
23
+ values.minimum > values.expected
24
+ ) {
25
+ return "Minimum guests cannot be higher than expected guests.";
26
+ }
27
+ if (
28
+ values.minimum != null &&
29
+ values.ideal != null &&
30
+ values.minimum > values.ideal
31
+ ) {
32
+ return "Minimum guests cannot be higher than ideal guests.";
33
+ }
20
34
  return null;
21
35
  }
@@ -338,6 +338,7 @@ function eventHasLocationHint(args: InferEventTimezoneArgs): boolean {
338
338
  return !!(
339
339
  args.location?.trim() ||
340
340
  args.city?.trim() ||
341
+ args.state?.trim() ||
341
342
  (args.latitude != null && args.longitude != null)
342
343
  );
343
344
  }
@@ -384,17 +385,28 @@ export function formatEventTimezoneAbbrev(
384
385
  const zoned = dt.setZone(zone);
385
386
  if (!zoned.isValid) return "";
386
387
 
387
- const short = zoned.toFormat("z");
388
- if (short && short !== "GMT" && short !== "UTC") return short;
388
+ // Luxon 3: "z" is the IANA id. "ZZZZ" is the short name (EST, MDT).
389
+ const named = zoned.toFormat("ZZZZ");
390
+ if (isShortZoneLabel(named, zone)) return named;
389
391
 
390
- return (
391
- new Intl.DateTimeFormat("en-US", {
392
- timeZone: zone,
393
- timeZoneName: "short",
394
- })
395
- .formatToParts(zoned.toJSDate())
396
- .find((part) => part.type === "timeZoneName")?.value ?? short
397
- );
392
+ const fromIntl = new Intl.DateTimeFormat("en-US", {
393
+ timeZone: zone,
394
+ timeZoneName: "short",
395
+ })
396
+ .formatToParts(zoned.toJSDate())
397
+ .find((part) => part.type === "timeZoneName")?.value;
398
+
399
+ if (isShortZoneLabel(fromIntl, zone)) return fromIntl;
400
+ return "";
401
+ }
402
+
403
+ function isShortZoneLabel(
404
+ label: string | null | undefined,
405
+ zone: string
406
+ ): label is string {
407
+ if (!label || label === "GMT" || label.includes("/")) return false;
408
+ // "z" used to return the IANA id. Keep that out of the UI, but UTC is a real label.
409
+ return label !== zone || zone === "UTC";
398
410
  }
399
411
 
400
412
  /** Curated list for the event wizard timezone picker (full IANA set is huge). */
@@ -5,11 +5,24 @@
5
5
 
6
6
  import type { PublicTeaserUser } from "../extendedSchemas.js";
7
7
 
8
- export type AttendeeDisplayMode =
9
- | "All"
10
- | "CountOnly"
11
- | "NetworkOnly"
12
- | "Hidden";
8
+ export const ATTENDEE_DISPLAY_MODES = [
9
+ "All",
10
+ "CountOnly",
11
+ "NetworkOnly",
12
+ "Blurred",
13
+ "Hidden",
14
+ ] as const;
15
+
16
+ export type AttendeeDisplayMode = (typeof ATTENDEE_DISPLAY_MODES)[number];
17
+
18
+ export function isAttendeeDisplayMode(
19
+ value: unknown
20
+ ): value is AttendeeDisplayMode {
21
+ return (
22
+ typeof value === "string" &&
23
+ (ATTENDEE_DISPLAY_MODES as readonly string[]).includes(value)
24
+ );
25
+ }
13
26
 
14
27
  /** Public competition roster on bash detail (subset of attendee modes). */
15
28
  export type ParticipantDisplayMode = "All" | "Hidden";
@@ -158,6 +171,7 @@ export function resolveEffectiveEventMode(
158
171
  const raw = event.attendeeDisplayMode;
159
172
  if (raw === "CountOnly") return "CountOnly";
160
173
  if (raw === "NetworkOnly") return "NetworkOnly";
174
+ if (raw === "Blurred") return "Blurred";
161
175
  if (raw === "Hidden") return "Hidden";
162
176
  if (event.showAttendees === false) return "Hidden";
163
177
  return "All";
@@ -186,7 +200,7 @@ export function capRosterDepthForEventMode(
186
200
  isHost: boolean
187
201
  ): GuestListDepth {
188
202
  if (isHost) return "Full";
189
- if (eventMode === "Hidden") return "None";
203
+ if (eventMode === "Hidden" || eventMode === "Blurred") return "None";
190
204
  if (eventMode === "NetworkOnly") return "None";
191
205
  return viewerDepth;
192
206
  }
@@ -211,6 +225,19 @@ export function resolveGuestSurfacePolicy(
211
225
  isHost
212
226
  );
213
227
 
228
+ if (eventMode === "Blurred" && !isHost) {
229
+ return {
230
+ showCount: false,
231
+ showPreviewAvatars: true,
232
+ showFeatured: false,
233
+ showNetworkSlice: false,
234
+ rosterDepth: "None",
235
+ previewLimit: 5,
236
+ apiPreviewLimit: 5,
237
+ effectiveMode: eventMode,
238
+ };
239
+ }
240
+
214
241
  if (eventMode === "Hidden" && !isHost) {
215
242
  return {
216
243
  showCount: false,
@@ -0,0 +1,87 @@
1
+ import { describe, expect, it } from "@jest/globals";
2
+
3
+ import {
4
+ computeSalesCut,
5
+ overlappingPaymentOptions,
6
+ snapshotFromBookingRequest,
7
+ vendorFitsHostPayment,
8
+ } from "../vendorPaymentWays.js";
9
+
10
+ const flat = { ways: ["flat"], amountCents: 20000 };
11
+ const percent = { ways: ["percentage"], percentage: 10 };
12
+ const both = { ways: ["flat", "percentage"], amountCents: 10000, percentage: 10 };
13
+
14
+ describe("vendor payment overlap", () => {
15
+ it("offers both flat and percent when the host accepts both", () => {
16
+ const overlap = overlappingPaymentOptions(
17
+ [flat, percent, both],
18
+ ["flat", "percentage"]
19
+ );
20
+ expect(overlap).toEqual([flat, percent, both]);
21
+ });
22
+
23
+ it("does not match a percent-only vendor to a flat-only bash", () => {
24
+ expect(vendorFitsHostPayment([percent], ["flat"])).toBe(false);
25
+ expect(overlappingPaymentOptions([percent], ["flat"])).toEqual([]);
26
+ });
27
+
28
+ it("keeps today's requests when the host has not listed ways", () => {
29
+ expect(overlappingPaymentOptions([percent], [])).toBeNull();
30
+ expect(vendorFitsHostPayment([percent], [])).toBe(true);
31
+ });
32
+
33
+ it("hides a booth-plus-percent option when the host only accepts a percent", () => {
34
+ expect(overlappingPaymentOptions([both, percent], ["percentage"])).toEqual([
35
+ percent,
36
+ ]);
37
+ });
38
+ });
39
+
40
+ describe("sales cut", () => {
41
+ it("takes 10 percent of $1,000", () => {
42
+ expect(
43
+ computeSalesCut({
44
+ confirmedSalesCents: 100_000,
45
+ percentage: 10,
46
+ boothFeeAlreadyPaidCents: 0,
47
+ })
48
+ ).toEqual({ owedCents: 10_000, remainingCents: 10_000 });
49
+ });
50
+
51
+ it("reduces what is still due by a booth fee already paid", () => {
52
+ expect(
53
+ computeSalesCut({
54
+ confirmedSalesCents: 100_000,
55
+ percentage: 10,
56
+ boothFeeAlreadyPaidCents: 4_000,
57
+ })
58
+ ).toEqual({ owedCents: 10_000, remainingCents: 6_000 });
59
+ });
60
+
61
+ it("owes nothing on a $0 night", () => {
62
+ expect(
63
+ computeSalesCut({
64
+ confirmedSalesCents: 0,
65
+ percentage: 10,
66
+ boothFeeAlreadyPaidCents: 0,
67
+ })
68
+ ).toEqual({ owedCents: 0, remainingCents: 0 });
69
+ });
70
+
71
+ it("does not charge before the host confirms", () => {
72
+ expect(
73
+ computeSalesCut({ confirmedSalesCents: null, percentage: 10 })
74
+ ).toBeNull();
75
+ });
76
+
77
+ it("keeps the percent from the booking after the listing changes", () => {
78
+ const booked = snapshotFromBookingRequest({
79
+ feeStructure: "percentage",
80
+ percentageRate: 10,
81
+ });
82
+ const listingPercentAfterward = 25;
83
+ expect(booked.paymentOptionPercentage).toBe(10);
84
+ expect(booked.paymentOptionBasis).toBe("ALL_SALES");
85
+ expect(booked.paymentOptionPercentage).not.toBe(listingPercentAfterward);
86
+ });
87
+ });