@bash-app/bash-common 30.220.0 → 30.221.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/definitions.d.ts +7 -1
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +19 -1
- package/dist/definitions.js.map +1 -1
- package/dist/extendedSchemas.d.ts +147 -0
- package/dist/extendedSchemas.d.ts.map +1 -1
- package/dist/extendedSchemas.js +20 -0
- package/dist/extendedSchemas.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/membershipDefinitions.d.ts +4 -2
- package/dist/membershipDefinitions.d.ts.map +1 -1
- package/dist/membershipDefinitions.js +9 -2
- package/dist/membershipDefinitions.js.map +1 -1
- package/dist/utils/__tests__/paymentUtils.test.js +126 -1
- package/dist/utils/__tests__/paymentUtils.test.js.map +1 -1
- package/dist/utils/__tests__/urlUtils.externalLink.test.d.ts +2 -0
- package/dist/utils/__tests__/urlUtils.externalLink.test.d.ts.map +1 -0
- package/dist/utils/__tests__/urlUtils.externalLink.test.js +29 -0
- package/dist/utils/__tests__/urlUtils.externalLink.test.js.map +1 -0
- package/dist/utils/paymentUtils.d.ts +29 -1
- package/dist/utils/paymentUtils.d.ts.map +1 -1
- package/dist/utils/paymentUtils.js +43 -3
- package/dist/utils/paymentUtils.js.map +1 -1
- package/dist/utils/urlUtils.d.ts +11 -0
- package/dist/utils/urlUtils.d.ts.map +1 -1
- package/dist/utils/urlUtils.js +40 -0
- package/dist/utils/urlUtils.js.map +1 -1
- package/package.json +1 -1
- package/prisma/schema.prisma +58 -1
- package/src/definitions.ts +22 -0
- package/src/extendedSchemas.ts +25 -0
- package/src/index.ts +1 -0
- package/src/membershipDefinitions.ts +10 -2
- package/src/utils/__tests__/paymentUtils.test.ts +174 -0
- package/src/utils/__tests__/urlUtils.externalLink.test.ts +36 -0
- package/src/utils/paymentUtils.ts +68 -1
- package/src/utils/urlUtils.ts +45 -0
package/src/utils/urlUtils.ts
CHANGED
|
@@ -206,3 +206,48 @@ export function redirectToStripeWithTimeout(
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Builds a safe absolute URL for `<a href>` from user-edited service/profile links.
|
|
212
|
+
*
|
|
213
|
+
* Browsers resolve `href="example.com"` as a **relative** URL (under the current path),
|
|
214
|
+
* not `https://example.com`, so bare domains must be prefixed with `https://`.
|
|
215
|
+
* Stores sometimes save Instagram as `@handle` instead of a full URL — those are mapped
|
|
216
|
+
* to `https://www.instagram.com/{handle}/`.
|
|
217
|
+
*
|
|
218
|
+
* @returns `"#"` when the value is empty or unsafe (`javascript:`, `data:`).
|
|
219
|
+
*/
|
|
220
|
+
export function toExternalLinkHref(raw: string | undefined | null): string {
|
|
221
|
+
if (raw == null) {
|
|
222
|
+
return "#";
|
|
223
|
+
}
|
|
224
|
+
const trimmed = raw.trim();
|
|
225
|
+
if (trimmed === "") {
|
|
226
|
+
return "#";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const lower = trimmed.toLowerCase();
|
|
230
|
+
if (lower.startsWith("javascript:") || lower.startsWith("data:")) {
|
|
231
|
+
return "#";
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (/^https?:\/\//i.test(trimmed)) {
|
|
235
|
+
return trimmed;
|
|
236
|
+
}
|
|
237
|
+
if (/^mailto:/i.test(trimmed) || /^tel:/i.test(trimmed)) {
|
|
238
|
+
return trimmed;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Instagram @handle (often stored as a handle instead of a URL)
|
|
242
|
+
if (trimmed.startsWith("@")) {
|
|
243
|
+
const handle = trimmed
|
|
244
|
+
.slice(1)
|
|
245
|
+
.trim()
|
|
246
|
+
.replace(/^@+/, "");
|
|
247
|
+
if (/^[a-zA-Z0-9._]{1,30}$/.test(handle)) {
|
|
248
|
+
return `https://www.instagram.com/${handle}/`;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return `https://${trimmed}`;
|
|
253
|
+
}
|