@careflair/common 1.0.19 → 1.0.21

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/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { AvailabilitiesSchemaZod, AvailabilityZodInput, } from "./schemas/availa
5
5
  export { HourlyRateInputZod, HourlyRateInputZodType, } from "./schemas/hourlyRateSchemaValidation";
6
6
  export { ServicesSchema, validateServices, } from "./schemas/businessServicesValidation";
7
7
  export { VideoProvider, VideoValidationResult, detectVideoProvider, isValidCommunityVideoUrl, isValidYouTubeOrVimeoUrl, validateVideoLink, } from "./utils/videoValidation";
8
+ export { ApplicationFormValues, applicationSchema, isValidVideoUrl, } from "./schemas/applicationSchema";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateVideoLink = exports.isValidYouTubeOrVimeoUrl = exports.isValidCommunityVideoUrl = exports.detectVideoProvider = exports.validateServices = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
3
+ exports.isValidVideoUrl = exports.applicationSchema = exports.validateVideoLink = exports.isValidYouTubeOrVimeoUrl = exports.isValidCommunityVideoUrl = exports.detectVideoProvider = exports.validateServices = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
4
4
  var userValiationSchema_1 = require("./schemas/userValiationSchema");
5
5
  Object.defineProperty(exports, "UserRegistrationSchema", { enumerable: true, get: function () { return userValiationSchema_1.UserRegistrationSchema; } });
6
6
  var educationSchemas_1 = require("./schemas/educationSchemas");
@@ -19,3 +19,6 @@ Object.defineProperty(exports, "detectVideoProvider", { enumerable: true, get: f
19
19
  Object.defineProperty(exports, "isValidCommunityVideoUrl", { enumerable: true, get: function () { return videoValidation_1.isValidCommunityVideoUrl; } });
20
20
  Object.defineProperty(exports, "isValidYouTubeOrVimeoUrl", { enumerable: true, get: function () { return videoValidation_1.isValidYouTubeOrVimeoUrl; } });
21
21
  Object.defineProperty(exports, "validateVideoLink", { enumerable: true, get: function () { return videoValidation_1.validateVideoLink; } });
22
+ var applicationSchema_1 = require("./schemas/applicationSchema");
23
+ Object.defineProperty(exports, "applicationSchema", { enumerable: true, get: function () { return applicationSchema_1.applicationSchema; } });
24
+ Object.defineProperty(exports, "isValidVideoUrl", { enumerable: true, get: function () { return applicationSchema_1.isValidVideoUrl; } });
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ export declare const isValidVideoUrl: (url: string) => boolean;
3
+ export declare const applicationSchema: z.ZodObject<{
4
+ proposal: z.ZodString;
5
+ videoLink: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
6
+ amount: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ proposal: string;
9
+ videoLink?: string | undefined;
10
+ amount?: string | undefined;
11
+ }, {
12
+ proposal: string;
13
+ videoLink?: string | undefined;
14
+ amount?: string | undefined;
15
+ }>;
16
+ export type ApplicationFormValues = z.infer<typeof applicationSchema>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applicationSchema = exports.isValidVideoUrl = void 0;
4
+ const zod_1 = require("zod");
5
+ const limits_1 = require("../constants/limits");
6
+ const videoValidation_1 = require("../utils/videoValidation");
7
+ // Helper function to validate YouTube or Vimeo URLs (using unified validation)
8
+ const isValidVideoUrl = (url) => {
9
+ return (0, videoValidation_1.isValidYouTubeOrVimeoUrl)(url);
10
+ };
11
+ exports.isValidVideoUrl = isValidVideoUrl;
12
+ exports.applicationSchema = zod_1.z.object({
13
+ proposal: zod_1.z
14
+ .string()
15
+ .min(100, "Cover letter must be at least 100 characters long")
16
+ .max(5000, "Cover letter cannot exceed 5000 characters"),
17
+ videoLink: zod_1.z
18
+ .string()
19
+ .optional()
20
+ .refine((val) => !val || (0, exports.isValidVideoUrl)(val), {
21
+ message: "Please provide a valid YouTube or Vimeo URL",
22
+ }),
23
+ amount: zod_1.z
24
+ .string()
25
+ .optional()
26
+ .refine((val) => !val ||
27
+ (parseFloat(val) >= limits_1.MIN_HOURLY_RATE &&
28
+ parseFloat(val) <= limits_1.MAX_HOURLY_RATE), {
29
+ message: `Hourly rate must be between $${limits_1.MIN_HOURLY_RATE} and $${limits_1.MAX_HOURLY_RATE}`,
30
+ }),
31
+ });
@@ -1,7 +1,8 @@
1
- export { UserRegistrationInput, UserRegistrationSchema, } from "./userValiationSchema";
2
- export { EducationAndTrainingInputValidation, EducationAndTrainingSchema, } from "./educationSchemas";
3
- export { WorkHistoryInputValidation, WorkHistorySchema, } from "./workHistorySchema";
4
- export { AvailabilitiesSchemaZod, AvailabilityZodInput, } from "./availabilitySchemaValidation";
5
- export { HourlyRateInputZod, HourlyRateInputZodType, } from "./hourlyRateSchemaValidation";
6
- export { ServicesSchema, SupportWorkerServicesSchema, validateServices, validateSupportWorkerServices, } from "./businessServicesValidation";
7
- export { generalOTPSchema, pinSchema, ResetPasswordSchema } from "./otp";
1
+ export { UserRegistrationInput, UserRegistrationSchema } from "./userValiationSchema";
2
+ export { EducationAndTrainingInputValidation, EducationAndTrainingSchema } from "./educationSchemas";
3
+ export { WorkHistoryInputValidation, WorkHistorySchema } from "./workHistorySchema";
4
+ export { AvailabilitiesSchemaZod, AvailabilityZodInput } from "./availabilitySchemaValidation";
5
+ export { HourlyRateInputZod, HourlyRateInputZodType } from "./hourlyRateSchemaValidation";
6
+ export { ServicesSchema, SupportWorkerServicesSchema, validateServices, validateSupportWorkerServices } from "./businessServicesValidation";
7
+ export { ResetPasswordSchema, generalOTPSchema, pinSchema } from "./otp";
8
+ export { ApplicationFormValues, applicationSchema, isValidVideoUrl } from "./applicationSchema";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResetPasswordSchema = exports.pinSchema = exports.generalOTPSchema = exports.validateSupportWorkerServices = exports.validateServices = exports.SupportWorkerServicesSchema = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
3
+ exports.isValidVideoUrl = exports.applicationSchema = exports.pinSchema = exports.generalOTPSchema = exports.ResetPasswordSchema = exports.validateSupportWorkerServices = exports.validateServices = exports.SupportWorkerServicesSchema = exports.ServicesSchema = exports.HourlyRateInputZod = exports.AvailabilitiesSchemaZod = exports.WorkHistorySchema = exports.EducationAndTrainingSchema = exports.UserRegistrationSchema = void 0;
4
4
  var userValiationSchema_1 = require("./userValiationSchema");
5
5
  Object.defineProperty(exports, "UserRegistrationSchema", { enumerable: true, get: function () { return userValiationSchema_1.UserRegistrationSchema; } });
6
6
  var educationSchemas_1 = require("./educationSchemas");
@@ -17,6 +17,9 @@ Object.defineProperty(exports, "SupportWorkerServicesSchema", { enumerable: true
17
17
  Object.defineProperty(exports, "validateServices", { enumerable: true, get: function () { return businessServicesValidation_1.validateServices; } });
18
18
  Object.defineProperty(exports, "validateSupportWorkerServices", { enumerable: true, get: function () { return businessServicesValidation_1.validateSupportWorkerServices; } });
19
19
  var otp_1 = require("./otp");
20
+ Object.defineProperty(exports, "ResetPasswordSchema", { enumerable: true, get: function () { return otp_1.ResetPasswordSchema; } });
20
21
  Object.defineProperty(exports, "generalOTPSchema", { enumerable: true, get: function () { return otp_1.generalOTPSchema; } });
21
22
  Object.defineProperty(exports, "pinSchema", { enumerable: true, get: function () { return otp_1.pinSchema; } });
22
- Object.defineProperty(exports, "ResetPasswordSchema", { enumerable: true, get: function () { return otp_1.ResetPasswordSchema; } });
23
+ var applicationSchema_1 = require("./applicationSchema");
24
+ Object.defineProperty(exports, "applicationSchema", { enumerable: true, get: function () { return applicationSchema_1.applicationSchema; } });
25
+ Object.defineProperty(exports, "isValidVideoUrl", { enumerable: true, get: function () { return applicationSchema_1.isValidVideoUrl; } });
@@ -0,0 +1,11 @@
1
+ type SanitizeHtmlOptions = {
2
+ allowedTags?: string[];
3
+ allowedAttr?: string[];
4
+ };
5
+ /**
6
+ * Cross-platform HTML sanitizer
7
+ * On web: Uses DOMPurify if available (more robust)
8
+ * On React Native: Uses regex-based sanitizer (simpler but effective)
9
+ */
10
+ export declare const sanitizeHtml: (content: string, options?: SanitizeHtmlOptions) => string;
11
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizeHtml = void 0;
4
+ /**
5
+ * Cross-platform HTML sanitizer
6
+ * On web: Uses DOMPurify if available (more robust)
7
+ * On React Native: Uses regex-based sanitizer (simpler but effective)
8
+ */
9
+ const sanitizeHtml = (content, options = {}) => {
10
+ if (!content)
11
+ return '';
12
+ const { allowedTags = ['p', 'strong', 'em', 'ul', 'ol', 'li', 'br', 'a'], allowedAttr = ['href', 'target', 'rel', 'class'], } = options;
13
+ // Check if we're in a browser environment with DOMPurify available
14
+ if (typeof window !== 'undefined' && typeof window.DOMPurify !== 'undefined') {
15
+ const DOMPurify = window.DOMPurify;
16
+ const purifyConfig = {
17
+ ALLOWED_TAGS: allowedTags,
18
+ ALLOWED_ATTR: allowedAttr,
19
+ };
20
+ return DOMPurify.sanitize(content, purifyConfig);
21
+ }
22
+ // Fallback: Regex-based sanitizer for React Native
23
+ return sanitizeHtmlRegex(content, { allowedTags, allowedAttr });
24
+ };
25
+ exports.sanitizeHtml = sanitizeHtml;
26
+ /**
27
+ * Regex-based HTML sanitizer for React Native
28
+ * Removes dangerous tags and attributes while preserving allowed tags
29
+ */
30
+ const sanitizeHtmlRegex = (html, options) => {
31
+ let cleaned = html;
32
+ const { allowedTags = [], allowedAttr = [] } = options;
33
+ // Remove script and style tags completely
34
+ cleaned = cleaned
35
+ .replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
36
+ .replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
37
+ .replace(/<!--[\s\S]*?-->/g, '');
38
+ // Remove dangerous attributes (javascript:, onclick, etc.)
39
+ cleaned = cleaned.replace(/\s*on\w+\s*=\s*["'][^"']*["']/gi, '');
40
+ cleaned = cleaned.replace(/\s*on\w+\s*=\s*[^\s>]*/gi, '');
41
+ cleaned = cleaned.replace(/javascript:/gi, '');
42
+ // Build regex for allowed tags
43
+ const allowedTagsRegex = allowedTags.join('|');
44
+ // Remove all tags except allowed ones
45
+ if (allowedTags.length > 0) {
46
+ // First, protect allowed tags
47
+ const tagPlaceholders = {};
48
+ let placeholderIndex = 0;
49
+ // Replace allowed tags with placeholders temporarily
50
+ cleaned = cleaned.replace(new RegExp(`<(${allowedTagsRegex})([^>]*)>`, 'gi'), (match, tag, attrs) => {
51
+ // Clean attributes - only keep allowed ones
52
+ let cleanAttrs = '';
53
+ if (attrs) {
54
+ const attrRegex = new RegExp(`\\s*(${allowedAttr.join('|')})\\s*=\\s*["']([^"']*)["']`, 'gi');
55
+ const matches = attrs.match(attrRegex);
56
+ if (matches) {
57
+ cleanAttrs = ' ' + matches.join(' ');
58
+ }
59
+ }
60
+ const placeholder = `__TAG_${placeholderIndex}__`;
61
+ tagPlaceholders[placeholder] = `<${tag}${cleanAttrs}>`;
62
+ placeholderIndex++;
63
+ return placeholder;
64
+ });
65
+ // Replace closing tags
66
+ cleaned = cleaned.replace(new RegExp(`</(${allowedTagsRegex})>`, 'gi'), (match, tag) => {
67
+ const placeholder = `__TAG_${placeholderIndex}__`;
68
+ tagPlaceholders[placeholder] = `</${tag}>`;
69
+ placeholderIndex++;
70
+ return placeholder;
71
+ });
72
+ // Remove all remaining tags
73
+ cleaned = cleaned.replace(/<[^>]*>/g, '');
74
+ // Restore allowed tags
75
+ Object.keys(tagPlaceholders).forEach((placeholder) => {
76
+ cleaned = cleaned.replace(placeholder, tagPlaceholders[placeholder]);
77
+ });
78
+ }
79
+ else {
80
+ // No allowed tags, strip all HTML
81
+ cleaned = cleaned.replace(/<[^>]*>/g, '');
82
+ }
83
+ // Decode common HTML entities
84
+ cleaned = cleaned
85
+ .replace(/&nbsp;/g, ' ')
86
+ .replace(/&amp;/g, '&')
87
+ .replace(/&lt;/g, '<')
88
+ .replace(/&gt;/g, '>')
89
+ .replace(/&quot;/g, '"')
90
+ .replace(/&#39;/g, "'")
91
+ .replace(/&apos;/g, "'")
92
+ .replace(/&#x27;/g, "'")
93
+ .replace(/&#x2F;/g, '/');
94
+ // Normalize whitespace
95
+ cleaned = cleaned.replace(/\s+/g, ' ').trim();
96
+ return cleaned;
97
+ };
@@ -5,3 +5,4 @@ export * from "./debounce";
5
5
  export * from "./enum";
6
6
  export * from "./video";
7
7
  export * from "./onboarding";
8
+ export * from "./html";
@@ -28,3 +28,5 @@ __exportStar(require("./enum"), exports);
28
28
  __exportStar(require("./video"), exports);
29
29
  // Onboarding utilities
30
30
  __exportStar(require("./onboarding"), exports);
31
+ // HTML sanitization utilities
32
+ __exportStar(require("./html"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@careflair/common",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Shared assets for CareFlair",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",