@insforge/react 0.4.6 → 0.4.7

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/lib.cjs CHANGED
@@ -74,10 +74,34 @@ function checkPasswordStrength(password) {
74
74
  return { score, feedback };
75
75
  }
76
76
 
77
+ // src/lib/path-utils.ts
78
+ function resolveAuthPath(targetPath) {
79
+ if (typeof window === "undefined") {
80
+ return targetPath;
81
+ }
82
+ const currentPath = window.location.pathname;
83
+ if (currentPath.startsWith("/auth/")) {
84
+ if (targetPath.startsWith("/auth/")) {
85
+ return targetPath;
86
+ }
87
+ return `/auth${targetPath}`;
88
+ }
89
+ return targetPath;
90
+ }
91
+ function resolveAuthUrl(targetPath, searchParams) {
92
+ const resolvedPath = resolveAuthPath(targetPath);
93
+ if (!searchParams || searchParams.toString() === "") {
94
+ return resolvedPath;
95
+ }
96
+ return `${resolvedPath}?${searchParams.toString()}`;
97
+ }
98
+
77
99
  exports.checkPasswordStrength = checkPasswordStrength;
78
100
  exports.createPasswordSchema = createPasswordSchema;
79
101
  exports.emailSchema = emailSchema;
80
102
  exports.passwordSchema = passwordSchema;
103
+ exports.resolveAuthPath = resolveAuthPath;
104
+ exports.resolveAuthUrl = resolveAuthUrl;
81
105
  exports.validateEmail = validateEmail;
82
106
  exports.validatePassword = validatePassword;
83
107
  //# sourceMappingURL=lib.cjs.map
package/dist/lib.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/validation.ts"],"names":["z"],"mappings":";;;;AAKO,IAAM,WAAA,GAAcA,MAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMlC;AACD,EAAA,MAAM;AAAA,IACJ,SAAA,GAAY,CAAA;AAAA,IACZ,gBAAA,GAAmB,KAAA;AAAA,IACnB,gBAAA,GAAmB,KAAA;AAAA,IACnB,aAAA,GA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AAE,OAAO,IAAA,EAAK;AAAA,EACvB;AACA,EAAA,OAAO,EAAE,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,MAAA,CAAO,MAAM,OAAA,EAAQ;AACrD;AAKO,SAAS,sBAAsB,QAAA,EAGpC;AACA,EAAA,MAAM,WAAqB,EAAC;AAC5B,EAAA,IAAI,KAAA,GAAQ,CAAA;AAEZ,EAAA,IAAI,QAAA,CAAS,UAAU,CAAA,EAAG;AACxB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,2BAA2B,CAAA;AAAA,EAC3C;AAEA,EAAA,IAAI,QAAA,CAAS,UAAU,EAAA,EAAI;AACzB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX;AAEA,EAAA,IAAI,QAAQ,IAAA,CAAK,QAAQ,KAAK,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAA,EAAG;AACpD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,0CAA0C,CAAA;AAAA,EAC1D;AAEA,EAAA,IAAI,IAAA,CAAK,IAAA,CAAK,QAAQ,CAAA,EAAG;AACvB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,6BAA6B,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,qCAAA,CAAsC,IAAA,CAAK,QAAQ,CAAA,EAAG;AACxD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,wCAAwC,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B","file":"lib.cjs","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n"]}
1
+ {"version":3,"sources":["../src/lib/validation.ts","../src/lib/path-utils.ts"],"names":["z"],"mappings":";;;;AAKO,IAAM,WAAA,GAAcA,MAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMlC;AACD,EAAA,MAAM;AAAA,IACJ,SAAA,GAAY,CAAA;AAAA,IACZ,gBAAA,GAAmB,KAAA;AAAA,IACnB,gBAAA,GAAmB,KAAA;AAAA,IACnB,aAAA,GAAgB,KAAA;AAAA,IAChB,kBAAA,GAAqB;AAAA,GACvB,GAAI,WAAW,EAAC;AAEhB,EAAA,IAAI,MAAA,GAASA,MAAE,MAAA,EAAO,CAAE,IAAI,SAAA,EAAW,CAAA,0BAAA,EAA6B,SAAS,CAAA,WAAA,CAAa,CAAA;AAE1F,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,qDAAqD,CAAA;AAAA,EACtF;AAEA,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,qDAAqD,CAAA;AAAA,EACtF;AAEA,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,IAAA,EAAM,2CAA2C,CAAA;AAAA,EACzE;AAEA,EAAA,IAAI,kBAAA,EAAoB;AACtB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA;AAAA,MACd,qCAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;AAKO,IAAM,iBAAiB,oBAAA;AAKvB,SAAS,cAAc,KAAA,EAAmD;AAC/E,EAAA,MAAM,MAAA,G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CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,6BAA6B,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,qCAAA,CAAsC,IAAA,CAAK,QAAQ,CAAA,EAAG;AACxD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,wCAAwC,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B;;;AClGO,SAAS,gBAAgB,UAAA,EAA4B;AAC1D,EAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,IAAA,OAAO,UAAA;AAAA,EACT;AAEA,EAAA,MAAM,WAAA,GAAc,OAAO,QAAA,CAAS,QAAA;AAGpC,EAAA,IAAI,WAAA,CAAY,UAAA,CAAW,QAAQ,CAAA,EAAG;AAEpC,IAAA,IAAI,UAAA,CAAW,UAAA,CAAW,QAAQ,CAAA,EAAG;AACnC,MAAA,OAAO,UAAA;AAAA,IACT;AAEA,IAAA,OAAO,QAAQ,UAAU,CAAA,CAAA;AAAA,EAC3B;AAGA,EAAA,OAAO,UAAA;AACT;AAcO,SAAS,cAAA,CAAe,YAAoB,YAAA,EAAwC;AACzF,EAAA,MAAM,YAAA,GAAe,gBAAgB,UAAU,CAAA;AAE/C,EAAA,IAAI,CAAC,YAAA,IAAgB,YAAA,CAAa,QAAA,OAAe,EAAA,EAAI;AACnD,IAAA,OAAO,YAAA;AAAA,EACT;AAEA,EAAA,OAAO,CAAA,EAAG,YAAY,CAAA,CAAA,EAAI,YAAA,CAAa,UAAU,CAAA,CAAA;AACnD","file":"lib.cjs","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n","/**\n * Path utilities for handling navigation in auth flows.\n * Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)\n */\n\n/**\n * Resolves an auth route path relative to the current location.\n * If the current path is under /auth/, it will preserve that prefix.\n * Otherwise, it returns the path as-is.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @returns The resolved path with proper base path handling\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in\n * resolveAuthPath('/sign-up') // Returns '/auth/sign-up'\n *\n * @example\n * // Current URL: http://localhost:5174/sign-in\n * resolveAuthPath('/sign-up') // Returns '/sign-up'\n */\nexport function resolveAuthPath(targetPath: string): string {\n if (typeof window === 'undefined') {\n return targetPath;\n }\n\n const currentPath = window.location.pathname;\n\n // Check if we're currently under /auth/ base path\n if (currentPath.startsWith('/auth/')) {\n // If target already has /auth/ prefix, return as-is\n if (targetPath.startsWith('/auth/')) {\n return targetPath;\n }\n // Add /auth/ prefix to the target path\n return `/auth${targetPath}`;\n }\n\n // Not under /auth/, return target path as-is\n return targetPath;\n}\n\n/**\n * Resolves an auth route URL with search params preserved.\n * Similar to resolveAuthPath but returns a full URL string with query parameters.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @param searchParams - Optional URLSearchParams to append\n * @returns The resolved URL as a string\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in?redirect=...\n * resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'\n */\nexport function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string {\n const resolvedPath = resolveAuthPath(targetPath);\n\n if (!searchParams || searchParams.toString() === '') {\n return resolvedPath;\n }\n\n return `${resolvedPath}?${searchParams.toString()}`;\n}\n"]}
package/dist/lib.d.cts CHANGED
@@ -40,4 +40,39 @@ declare function checkPasswordStrength(password: string): {
40
40
  feedback: string[];
41
41
  };
42
42
 
43
- export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, validateEmail, validatePassword };
43
+ /**
44
+ * Path utilities for handling navigation in auth flows.
45
+ * Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)
46
+ */
47
+ /**
48
+ * Resolves an auth route path relative to the current location.
49
+ * If the current path is under /auth/, it will preserve that prefix.
50
+ * Otherwise, it returns the path as-is.
51
+ *
52
+ * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
53
+ * @returns The resolved path with proper base path handling
54
+ *
55
+ * @example
56
+ * // Current URL: http://localhost:5174/auth/sign-in
57
+ * resolveAuthPath('/sign-up') // Returns '/auth/sign-up'
58
+ *
59
+ * @example
60
+ * // Current URL: http://localhost:5174/sign-in
61
+ * resolveAuthPath('/sign-up') // Returns '/sign-up'
62
+ */
63
+ declare function resolveAuthPath(targetPath: string): string;
64
+ /**
65
+ * Resolves an auth route URL with search params preserved.
66
+ * Similar to resolveAuthPath but returns a full URL string with query parameters.
67
+ *
68
+ * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
69
+ * @param searchParams - Optional URLSearchParams to append
70
+ * @returns The resolved URL as a string
71
+ *
72
+ * @example
73
+ * // Current URL: http://localhost:5174/auth/sign-in?redirect=...
74
+ * resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'
75
+ */
76
+ declare function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string;
77
+
78
+ export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword };
package/dist/lib.d.ts CHANGED
@@ -40,4 +40,39 @@ declare function checkPasswordStrength(password: string): {
40
40
  feedback: string[];
41
41
  };
42
42
 
43
- export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, validateEmail, validatePassword };
43
+ /**
44
+ * Path utilities for handling navigation in auth flows.
45
+ * Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)
46
+ */
47
+ /**
48
+ * Resolves an auth route path relative to the current location.
49
+ * If the current path is under /auth/, it will preserve that prefix.
50
+ * Otherwise, it returns the path as-is.
51
+ *
52
+ * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
53
+ * @returns The resolved path with proper base path handling
54
+ *
55
+ * @example
56
+ * // Current URL: http://localhost:5174/auth/sign-in
57
+ * resolveAuthPath('/sign-up') // Returns '/auth/sign-up'
58
+ *
59
+ * @example
60
+ * // Current URL: http://localhost:5174/sign-in
61
+ * resolveAuthPath('/sign-up') // Returns '/sign-up'
62
+ */
63
+ declare function resolveAuthPath(targetPath: string): string;
64
+ /**
65
+ * Resolves an auth route URL with search params preserved.
66
+ * Similar to resolveAuthPath but returns a full URL string with query parameters.
67
+ *
68
+ * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')
69
+ * @param searchParams - Optional URLSearchParams to append
70
+ * @returns The resolved URL as a string
71
+ *
72
+ * @example
73
+ * // Current URL: http://localhost:5174/auth/sign-in?redirect=...
74
+ * resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'
75
+ */
76
+ declare function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string;
77
+
78
+ export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword };
package/dist/lib.js CHANGED
@@ -72,6 +72,28 @@ function checkPasswordStrength(password) {
72
72
  return { score, feedback };
73
73
  }
74
74
 
75
- export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, validateEmail, validatePassword };
75
+ // src/lib/path-utils.ts
76
+ function resolveAuthPath(targetPath) {
77
+ if (typeof window === "undefined") {
78
+ return targetPath;
79
+ }
80
+ const currentPath = window.location.pathname;
81
+ if (currentPath.startsWith("/auth/")) {
82
+ if (targetPath.startsWith("/auth/")) {
83
+ return targetPath;
84
+ }
85
+ return `/auth${targetPath}`;
86
+ }
87
+ return targetPath;
88
+ }
89
+ function resolveAuthUrl(targetPath, searchParams) {
90
+ const resolvedPath = resolveAuthPath(targetPath);
91
+ if (!searchParams || searchParams.toString() === "") {
92
+ return resolvedPath;
93
+ }
94
+ return `${resolvedPath}?${searchParams.toString()}`;
95
+ }
96
+
97
+ export { checkPasswordStrength, createPasswordSchema, emailSchema, passwordSchema, resolveAuthPath, resolveAuthUrl, validateEmail, validatePassword };
76
98
  //# sourceMappingURL=lib.js.map
77
99
  //# sourceMappingURL=lib.js.map
package/dist/lib.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/validation.ts"],"names":[],"mappings":";;AAKO,IAAM,WAAA,GAAc,EAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMlC;AACD,EAAA,MAAM;AAAA,IACJ,SAAA,GAAY,CAAA;AAAA,IACZ,gBAAA,GAAmB,KAAA;AAAA,IACnB,gBAAA,GAAmB,KAAA;AAAA,IACnB,aAAA,GAAgB,KAAA;AAAA,IAChB,kBAAA,GAAqB;AAAA,GACvB,GAAI,WAAW,EAAC;AAEhB,EAAA,IAAI,MAAA,GAAS,EAAE,MAAA,EAAO,CAAE,IAAI,SAAA,EAAW,CAAA,0BAAA,EAA6B,SAAS,CAAA,WAAA,CAAa,CAAA;AAE1F,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,qDAAqD,CAAA;AAAA,EACtF;AAEA,EAAA,IAAI,gBAAA,EAAkB;AACpB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,OAAA,EAAS,qDAAqD,CAAA;AAAA,EACtF;AAEA,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA,CAAM,IAAA,EAAM,2CAA2C,CAAA;AAAA,EACzE;AAEA,EAAA,IAAI,kBAAA,EAAoB;AACtB,IAAA,MAAA,GAAS,MAAA,CAAO,KAAA;AAAA,MACd,qCAAA;AAAA,MACA;AAAA,KACF;AAAA,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AAA;AAAA,EAC1D;AAEA,EAAA,IAAI,IAAA,CAAK,IAAA,CAAK,QAAQ,CAAA,EAAG;AACvB,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,6BAA6B,CAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,qCAAA,CAAsC,IAAA,CAAK,QAAQ,CAAA,EAAG;AACxD,IAAA,KAAA,IAAS,CAAA;AAAA,EACX,CAAA,MAAO;AACL,IAAA,QAAA,CAAS,KAAK,wCAAwC,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,EAAE,OAAO,QAAA,EAAS;AAC3B","file":"lib.js","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n"]}
1
+ {"version":3,"sources":["../src/lib/validation.ts","../src/lib/path-utils.ts"],"names":[],"mappings":";;AAKO,IAAM,WAAA,GAAc,EAAE,MAAA,EAAO,CAAE,IAAI,CAAA,EAAG,mBAAmB,CAAA,CAAE,KAAA,CAAM,uBAAuB;AAKxF,SAAS,qBAAqB,OAAA,EAMlC;AACD,EAAA,MAAM;AAAA,IACJ,SAAA,GAAY,CAAA;AAAA,IACZ,gBAAA,GAAmB,KAAA;AAAA,IACnB,gBAAA,GAAmB,KAAA;AAAA,IACnB,aAAA,GAAgB,KAAA;AAAA,IAChB,kBAAA,GAAqB;AAAA,GACvB,GAAI,WAAW,EAAC;AAEhB,EAAA,IAAI,MAAA,GAAS,EAAE,MAAA,EAAO,CAAE,IAAI,SAAA,EAAW,CAAA,0BAAA,EAA6B,SAAS,CAAA,WAAA,CAAa,CAAA;AAE1F,EAAA,IAAI,gBAAA,EAAkB;AACpB,I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AGA,EAAA,OAAO,UAAA;AACT;AAcO,SAAS,cAAA,CAAe,YAAoB,YAAA,EAAwC;AACzF,EAAA,MAAM,YAAA,GAAe,gBAAgB,UAAU,CAAA;AAE/C,EAAA,IAAI,CAAC,YAAA,IAAgB,YAAA,CAAa,QAAA,OAAe,EAAA,EAAI;AACnD,IAAA,OAAO,YAAA;AAAA,EACT;AAEA,EAAA,OAAO,CAAA,EAAG,YAAY,CAAA,CAAA,EAAI,YAAA,CAAa,UAAU,CAAA,CAAA;AACnD","file":"lib.js","sourcesContent":["import { z } from 'zod';\n\n/**\n * Email validation schema\n */\nexport const emailSchema = z.string().min(1, 'Email is required').email('Invalid email address');\n\n/**\n * Password validation schema with configurable requirements\n */\nexport function createPasswordSchema(options?: {\n minLength?: number;\n requireUppercase?: boolean;\n requireLowercase?: boolean;\n requireNumber?: boolean;\n requireSpecialChar?: boolean;\n}) {\n const {\n minLength = 6,\n requireUppercase = false,\n requireLowercase = false,\n requireNumber = false,\n requireSpecialChar = false,\n } = options || {};\n\n let schema = z.string().min(minLength, `Password must be at least ${minLength} characters`);\n\n if (requireUppercase) {\n schema = schema.regex(/[A-Z]/, 'Password must contain at least one uppercase letter');\n }\n\n if (requireLowercase) {\n schema = schema.regex(/[a-z]/, 'Password must contain at least one lowercase letter');\n }\n\n if (requireNumber) {\n schema = schema.regex(/\\d/, 'Password must contain at least one number');\n }\n\n if (requireSpecialChar) {\n schema = schema.regex(\n /[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/,\n 'Password must contain at least one special character'\n );\n }\n\n return schema;\n}\n\n/**\n * Default password schema (minimum 6 characters)\n */\nexport const passwordSchema = createPasswordSchema();\n\n/**\n * Validate email format\n */\nexport function validateEmail(email: string): { valid: boolean; error?: string } {\n const result = emailSchema.safeParse(email);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password format\n */\nexport function validatePassword(\n password: string,\n options?: Parameters<typeof createPasswordSchema>[0]\n): { valid: boolean; error?: string } {\n const schema = createPasswordSchema(options);\n const result = schema.safeParse(password);\n if (result.success) {\n return { valid: true };\n }\n return { valid: false, error: result.error.message };\n}\n\n/**\n * Validate password strength based on multiple criteria\n */\nexport function checkPasswordStrength(password: string): {\n score: number;\n feedback: string[];\n} {\n const feedback: string[] = [];\n let score = 0;\n\n if (password.length >= 8) {\n score += 1;\n } else {\n feedback.push('Use at least 8 characters');\n }\n\n if (password.length >= 12) {\n score += 1;\n }\n\n if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Use both uppercase and lowercase letters');\n }\n\n if (/\\d/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one number');\n }\n\n if (/[!@#$%^&*()_+\\-=[\\]{};':\"\\\\|,.<>/?]/.test(password)) {\n score += 1;\n } else {\n feedback.push('Include at least one special character');\n }\n\n return { score, feedback };\n}\n","/**\n * Path utilities for handling navigation in auth flows.\n * Ensures proper path resolution when auth pages are served under a base path (e.g., /auth/)\n */\n\n/**\n * Resolves an auth route path relative to the current location.\n * If the current path is under /auth/, it will preserve that prefix.\n * Otherwise, it returns the path as-is.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @returns The resolved path with proper base path handling\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in\n * resolveAuthPath('/sign-up') // Returns '/auth/sign-up'\n *\n * @example\n * // Current URL: http://localhost:5174/sign-in\n * resolveAuthPath('/sign-up') // Returns '/sign-up'\n */\nexport function resolveAuthPath(targetPath: string): string {\n if (typeof window === 'undefined') {\n return targetPath;\n }\n\n const currentPath = window.location.pathname;\n\n // Check if we're currently under /auth/ base path\n if (currentPath.startsWith('/auth/')) {\n // If target already has /auth/ prefix, return as-is\n if (targetPath.startsWith('/auth/')) {\n return targetPath;\n }\n // Add /auth/ prefix to the target path\n return `/auth${targetPath}`;\n }\n\n // Not under /auth/, return target path as-is\n return targetPath;\n}\n\n/**\n * Resolves an auth route URL with search params preserved.\n * Similar to resolveAuthPath but returns a full URL string with query parameters.\n *\n * @param targetPath - The target auth path (e.g., '/sign-in', '/sign-up')\n * @param searchParams - Optional URLSearchParams to append\n * @returns The resolved URL as a string\n *\n * @example\n * // Current URL: http://localhost:5174/auth/sign-in?redirect=...\n * resolveAuthUrl('/sign-up', searchParams) // Returns '/auth/sign-up?redirect=...'\n */\nexport function resolveAuthUrl(targetPath: string, searchParams?: URLSearchParams): string {\n const resolvedPath = resolveAuthPath(targetPath);\n\n if (!searchParams || searchParams.toString() === '') {\n return resolvedPath;\n }\n\n return `${resolvedPath}?${searchParams.toString()}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insforge/react",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "description": "Framework-agnostic React authentication UI components for Insforge - reusable across all frameworks",
6
6
  "main": "./dist/index.cjs",