@bash-app/bash-common 30.476.0 → 30.480.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__/bashEventCancellationPolicy.m300.test.d.ts +2 -0
- package/dist/__tests__/bashEventCancellationPolicy.m300.test.d.ts.map +1 -0
- package/dist/__tests__/bashEventCancellationPolicy.m300.test.js +17 -0
- package/dist/__tests__/bashEventCancellationPolicy.m300.test.js.map +1 -0
- package/dist/__tests__/bashEventLocationDisplay.test.d.ts +2 -0
- package/dist/__tests__/bashEventLocationDisplay.test.d.ts.map +1 -0
- package/dist/__tests__/bashEventLocationDisplay.test.js +11 -0
- package/dist/__tests__/bashEventLocationDisplay.test.js.map +1 -0
- package/dist/__tests__/bashEventMerchCatalogValidation.m299.test.d.ts +2 -0
- package/dist/__tests__/bashEventMerchCatalogValidation.m299.test.d.ts.map +1 -0
- package/dist/__tests__/bashEventMerchCatalogValidation.m299.test.js +33 -0
- package/dist/__tests__/bashEventMerchCatalogValidation.m299.test.js.map +1 -0
- package/dist/__tests__/bashEventWriteValidation.l193.test.d.ts +2 -0
- package/dist/__tests__/bashEventWriteValidation.l193.test.d.ts.map +1 -0
- package/dist/__tests__/bashEventWriteValidation.l193.test.js +20 -0
- package/dist/__tests__/bashEventWriteValidation.l193.test.js.map +1 -0
- package/dist/__tests__/hybridSearchQuery.test.d.ts +2 -0
- package/dist/__tests__/hybridSearchQuery.test.d.ts.map +1 -0
- package/dist/__tests__/hybridSearchQuery.test.js +42 -0
- package/dist/__tests__/hybridSearchQuery.test.js.map +1 -0
- package/dist/__tests__/promoCodeScope.test.js +7 -0
- package/dist/__tests__/promoCodeScope.test.js.map +1 -1
- package/dist/__tests__/serviceListingText.l195.test.d.ts +2 -0
- package/dist/__tests__/serviceListingText.l195.test.d.ts.map +1 -0
- package/dist/__tests__/serviceListingText.l195.test.js +7 -0
- package/dist/__tests__/serviceListingText.l195.test.js.map +1 -0
- package/dist/__tests__/serviceWizardSave.pipNov14.test.d.ts +2 -0
- package/dist/__tests__/serviceWizardSave.pipNov14.test.d.ts.map +1 -0
- package/dist/__tests__/serviceWizardSave.pipNov14.test.js +42 -0
- package/dist/__tests__/serviceWizardSave.pipNov14.test.js.map +1 -0
- package/dist/bashEventCancellationPolicy.d.ts +8 -0
- package/dist/bashEventCancellationPolicy.d.ts.map +1 -1
- package/dist/bashEventCancellationPolicy.js +20 -0
- package/dist/bashEventCancellationPolicy.js.map +1 -1
- package/dist/bashEventMerchCatalogValidation.d.ts +9 -0
- package/dist/bashEventMerchCatalogValidation.d.ts.map +1 -0
- package/dist/bashEventMerchCatalogValidation.js +39 -0
- package/dist/bashEventMerchCatalogValidation.js.map +1 -0
- package/dist/bashEventWriteValidation.d.ts +13 -0
- package/dist/bashEventWriteValidation.d.ts.map +1 -0
- package/dist/bashEventWriteValidation.js +24 -0
- package/dist/bashEventWriteValidation.js.map +1 -0
- package/dist/extendedSchemas.d.ts +675 -215
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js +116 -4
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/promoCodeScope.d.ts +2 -0
- package/dist/promoCodeScope.d.ts.map +1 -1
- package/dist/promoCodeScope.js +8 -3
- package/dist/promoCodeScope.js.map +1 -1
- package/dist/serviceWizardSave.d.ts +2 -0
- package/dist/serviceWizardSave.d.ts.map +1 -1
- package/dist/serviceWizardSave.js +43 -4
- package/dist/serviceWizardSave.js.map +1 -1
- package/dist/utils/__tests__/eventTaskVolunteerRewardUtils.test.js +10 -1
- package/dist/utils/__tests__/eventTaskVolunteerRewardUtils.test.js.map +1 -1
- package/dist/utils/__tests__/webLinkValidation.test.js +11 -1
- package/dist/utils/__tests__/webLinkValidation.test.js.map +1 -1
- package/dist/utils/bashEventLocationDisplay.d.ts +3 -0
- package/dist/utils/bashEventLocationDisplay.d.ts.map +1 -0
- package/dist/utils/bashEventLocationDisplay.js +21 -0
- package/dist/utils/bashEventLocationDisplay.js.map +1 -0
- package/dist/utils/hybridSearchQuery.d.ts +29 -0
- package/dist/utils/hybridSearchQuery.d.ts.map +1 -0
- package/dist/utils/hybridSearchQuery.js +77 -0
- package/dist/utils/hybridSearchQuery.js.map +1 -0
- package/dist/utils/richTextContent.d.ts +4 -0
- package/dist/utils/richTextContent.d.ts.map +1 -1
- package/dist/utils/richTextContent.js +26 -0
- package/dist/utils/richTextContent.js.map +1 -1
- package/dist/utils/serviceListingText.d.ts +3 -0
- package/dist/utils/serviceListingText.d.ts.map +1 -0
- package/dist/utils/serviceListingText.js +6 -0
- package/dist/utils/serviceListingText.js.map +1 -0
- package/dist/utils/userUtils.d.ts +3 -0
- package/dist/utils/userUtils.d.ts.map +1 -1
- package/dist/utils/userUtils.js +10 -0
- package/dist/utils/userUtils.js.map +1 -1
- package/dist/utils/webLinkValidation.d.ts +2 -0
- package/dist/utils/webLinkValidation.d.ts.map +1 -1
- package/dist/utils/webLinkValidation.js +9 -0
- package/dist/utils/webLinkValidation.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +7 -0
- package/src/__tests__/bashEventCancellationPolicy.m300.test.ts +20 -0
- package/src/__tests__/bashEventLocationDisplay.test.ts +20 -0
- package/src/__tests__/bashEventMerchCatalogValidation.m299.test.ts +37 -0
- package/src/__tests__/bashEventWriteValidation.l193.test.ts +31 -0
- package/src/__tests__/hybridSearchQuery.test.ts +54 -0
- package/src/__tests__/promoCodeScope.test.ts +10 -0
- package/src/__tests__/serviceListingText.l195.test.ts +7 -0
- package/src/__tests__/serviceWizardSave.pipNov14.test.ts +47 -0
- package/src/bashEventCancellationPolicy.ts +23 -0
- package/src/bashEventMerchCatalogValidation.ts +45 -0
- package/src/bashEventWriteValidation.ts +31 -0
- package/src/extendedSchemas.ts +133 -6
- package/src/index.ts +5 -0
- package/src/promoCodeScope.ts +10 -3
- package/src/serviceWizardSave.ts +59 -6
- package/src/utils/__tests__/eventTaskVolunteerRewardUtils.test.ts +16 -0
- package/src/utils/__tests__/webLinkValidation.test.ts +18 -1
- package/src/utils/bashEventLocationDisplay.ts +24 -0
- package/src/utils/hybridSearchQuery.ts +93 -0
- package/src/utils/richTextContent.ts +26 -0
- package/src/utils/serviceListingText.ts +6 -0
- package/src/utils/userUtils.ts +13 -0
- package/src/utils/webLinkValidation.ts +10 -0
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
normalizeOptionalWebLinkForStorage,
|
|
3
|
+
validateOptionalWebLink,
|
|
4
|
+
} from "../webLinkValidation.js";
|
|
5
|
+
|
|
6
|
+
describe("[L194] normalizeOptionalWebLinkForStorage", () => {
|
|
7
|
+
it("clears blank and whitespace links", () => {
|
|
8
|
+
expect(normalizeOptionalWebLinkForStorage("")).toBeNull();
|
|
9
|
+
expect(normalizeOptionalWebLinkForStorage(" ")).toBeNull();
|
|
10
|
+
expect(normalizeOptionalWebLinkForStorage(null)).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("trims valid links", () => {
|
|
14
|
+
expect(normalizeOptionalWebLinkForStorage(" https://zoom.us/x ")).toBe(
|
|
15
|
+
"https://zoom.us/x"
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
2
19
|
|
|
3
20
|
it.each([undefined, null, "", "https://meet.example.com/room?key=123", "http://example.com"])("accepts an optional web link %s", value => {
|
|
4
21
|
expect(validateOptionalWebLink(value)).toBeNull();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** City/state line for cards and search. Pipe-packed place strings are not shown raw. */
|
|
2
|
+
export function formatBashCardLocation(
|
|
3
|
+
location?: string | null,
|
|
4
|
+
city?: string | null,
|
|
5
|
+
state?: string | null
|
|
6
|
+
): string | null {
|
|
7
|
+
const loc = readablePlace(location);
|
|
8
|
+
if (loc) return loc;
|
|
9
|
+
const parts = [city?.trim(), state?.trim()].filter(
|
|
10
|
+
(part): part is string => Boolean(part)
|
|
11
|
+
);
|
|
12
|
+
return parts.length ? parts.join(", ") : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function readablePlace(raw?: string | null): string | null {
|
|
16
|
+
const trimmed = raw?.trim();
|
|
17
|
+
if (!trimmed) return null;
|
|
18
|
+
if (!trimmed.includes("|")) return trimmed;
|
|
19
|
+
const parts = trimmed
|
|
20
|
+
.split("|")
|
|
21
|
+
.map((part) => part.trim())
|
|
22
|
+
.filter(Boolean);
|
|
23
|
+
return parts.length ? parts.join(", ") : null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize and escape strings for Prisma `contains` / PostgreSQL ILIKE.
|
|
3
|
+
* Unescaped `%` and `_` act as wildcards and can match every row.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Remove lone UTF-16 surrogates (e.g. from truncated percent-encoding in URLs). */
|
|
7
|
+
export function normalizeUserSearchQuery(raw: string): string {
|
|
8
|
+
if (!raw) return "";
|
|
9
|
+
const trimmed = raw.trim();
|
|
10
|
+
if (!trimmed) return "";
|
|
11
|
+
return trimmed.replace(
|
|
12
|
+
/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,
|
|
13
|
+
"\uFFFD"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Escape `\`, `%`, and `_` for Prisma `contains` on PostgreSQL. */
|
|
18
|
+
export function escapePrismaContainsPattern(term: string): string {
|
|
19
|
+
return term.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function prismaInsensitiveContains(term: string): {
|
|
23
|
+
contains: string;
|
|
24
|
+
mode: "insensitive";
|
|
25
|
+
} {
|
|
26
|
+
return {
|
|
27
|
+
contains: escapePrismaContainsPattern(term),
|
|
28
|
+
mode: "insensitive",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Letter or digit. `%` and `_` alone are not keyword queries. */
|
|
33
|
+
export function searchQueryHasKeyword(query: string): boolean {
|
|
34
|
+
return /[\p{L}\p{N}]/u.test(query);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Max rows returned from POST /api/search/hybrid (per type, before merge cap). */
|
|
38
|
+
export const HYBRID_SEARCH_MAX_RESULTS = 100;
|
|
39
|
+
|
|
40
|
+
/** Max UTF-16 code units on the raw `query` field (DoS / oversized echo). */
|
|
41
|
+
export const HYBRID_SEARCH_MAX_QUERY_LENGTH = 500;
|
|
42
|
+
|
|
43
|
+
const HYBRID_SEARCH_DEFAULT_LIMIT = 20;
|
|
44
|
+
|
|
45
|
+
export function clampHybridSearchLimit(raw: unknown): number {
|
|
46
|
+
const n =
|
|
47
|
+
typeof raw === "number"
|
|
48
|
+
? raw
|
|
49
|
+
: typeof raw === "string"
|
|
50
|
+
? Number.parseInt(raw, 10)
|
|
51
|
+
: HYBRID_SEARCH_DEFAULT_LIMIT;
|
|
52
|
+
if (!Number.isFinite(n) || n < 1) {
|
|
53
|
+
return HYBRID_SEARCH_DEFAULT_LIMIT;
|
|
54
|
+
}
|
|
55
|
+
return Math.min(Math.floor(n), HYBRID_SEARCH_MAX_RESULTS);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Express `req.query.q` may be string, string[], or absent. */
|
|
59
|
+
export function coerceSearchQueryParam(raw: unknown): string | undefined {
|
|
60
|
+
if (raw === undefined || raw === null) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(raw)) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
if (typeof raw !== "string") {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
const trimmed = raw.trim();
|
|
70
|
+
return trimmed.length > 0 ? raw : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function parseHybridSearchQueryInput(
|
|
74
|
+
raw: unknown,
|
|
75
|
+
): { ok: true; query: string } | { ok: false; error: string } {
|
|
76
|
+
if (typeof raw !== "string") {
|
|
77
|
+
return { ok: false, error: "Query parameter is required" };
|
|
78
|
+
}
|
|
79
|
+
if (raw.includes("\u0000")) {
|
|
80
|
+
return { ok: false, error: "Query cannot contain null characters" };
|
|
81
|
+
}
|
|
82
|
+
if (raw.length > HYBRID_SEARCH_MAX_QUERY_LENGTH) {
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
error: `Query must be ${HYBRID_SEARCH_MAX_QUERY_LENGTH} characters or fewer`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const query = normalizeUserSearchQuery(raw);
|
|
89
|
+
if (!query) {
|
|
90
|
+
return { ok: false, error: "Query parameter is required" };
|
|
91
|
+
}
|
|
92
|
+
return { ok: true, query };
|
|
93
|
+
}
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/** Visible character count for rich-text limits (tags stripped). */
|
|
2
|
+
export function richTextVisibleLength(html: string | null | undefined): number {
|
|
3
|
+
if (!html) return 0;
|
|
4
|
+
return html
|
|
5
|
+
.replace(/<[^>]*>/g, "")
|
|
6
|
+
.replace(/ /gi, " ")
|
|
7
|
+
.replace(/\s+/g, " ")
|
|
8
|
+
.trim().length;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Plain text from rich HTML (block tags → spaces). */
|
|
12
|
+
export function richTextToPlainText(html: string | null | undefined): string {
|
|
13
|
+
if (!html) return "";
|
|
14
|
+
return html
|
|
15
|
+
.replace(/<(br|\/p|\/h[1-6]|\/li|\/blockquote)\b[^>]*>/gi, " ")
|
|
16
|
+
.replace(/<[^>]*>/g, "")
|
|
17
|
+
.replace(/ /gi, " ")
|
|
18
|
+
.replace(/&/gi, "&")
|
|
19
|
+
.replace(/</gi, "<")
|
|
20
|
+
.replace(/>/gi, ">")
|
|
21
|
+
.replace(/"/gi, '"')
|
|
22
|
+
.replace(/'/g, "'")
|
|
23
|
+
.replace(/\s+/g, " ")
|
|
24
|
+
.trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
1
27
|
/** True when HTML/rich text has visible text or an image (not `<p></p>` alone). */
|
|
2
28
|
export function richTextHasVisibleContent(
|
|
3
29
|
html: string | null | undefined
|
package/src/utils/userUtils.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { Gender, SocialEventCadence } from "@prisma/client";
|
|
2
2
|
|
|
3
|
+
import type { PublicTeaserUser } from "../extendedSchemas.js";
|
|
4
|
+
|
|
3
5
|
export const MAX_USER_NAME_CHANGES = 3 as const;
|
|
4
6
|
|
|
7
|
+
/** Display name for blog teasers, attendee chips, and other PublicTeaserUser surfaces (no email). */
|
|
8
|
+
export function getPublicTeaserUserDisplayName(
|
|
9
|
+
author: Pick<PublicTeaserUser, "givenName" | "familyName" | "username">
|
|
10
|
+
): string {
|
|
11
|
+
const fullName = `${author.givenName ?? ""} ${author.familyName ?? ""}`.trim();
|
|
12
|
+
if (fullName) return fullName;
|
|
13
|
+
const username = author.username?.trim();
|
|
14
|
+
if (username) return username;
|
|
15
|
+
return "Bash";
|
|
16
|
+
}
|
|
17
|
+
|
|
5
18
|
/**
|
|
6
19
|
* Minimum shape needed by `getDisplayGender`. Accepts any object that has the
|
|
7
20
|
* two relevant columns (e.g. `User`, `UserExt`, `PublicUser`, or a partial
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/** Blank clears a stored link; whitespace-only is treated as unset. */
|
|
2
|
+
export function normalizeOptionalWebLinkForStorage(
|
|
3
|
+
value: unknown
|
|
4
|
+
): string | null {
|
|
5
|
+
if (value == null) return null;
|
|
6
|
+
if (typeof value !== "string") return null;
|
|
7
|
+
const trimmed = value.trim();
|
|
8
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
/** Optional user-entered web links must use HTTP(S), never executable schemes. */
|
|
2
12
|
export function validateOptionalWebLink(value: unknown): string | null {
|
|
3
13
|
if (value == null || (typeof value === "string" && !value.trim())) return null;
|