Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor UrlUtility to be app-specific (#846)

Leendert de Borstd7db5a4e76e0
diff --git a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
index dfc735ab2..047952135 100644
--- a/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/credentials/add-edit.tsx
@@ -20,11 +20,11 @@ import { useVaultMutate } from '@/hooks/useVaultMutate';
import { IdentityGeneratorEn, IdentityGeneratorNl, IdentityHelperUtils, BaseIdentityGenerator } from '@/utils/shared/identity-generator';
import { PasswordGenerator } from '@/utils/shared/password-generator';
import { ValidatedFormField, ValidatedFormFieldRef } from '@/components/form/ValidatedFormField';
-import { credentialSchema } from '@/utils/validationSchema';
+import { credentialSchema } from '@/utils/ValidationSchema';
import LoadingOverlay from '@/components/LoadingOverlay';
import { useAuth } from '@/context/AuthContext';
import { ThemedContainer } from '@/components/themed/ThemedContainer';
-import { extractServiceNameFromUrl } from '@/utils/shared/service-url';
+import { extractServiceNameFromUrl } from '@/utils/UrlUtility';
type CredentialMode = 'random' | 'manual';
diff --git a/apps/mobile-app/components/credentials/ServiceUrlNotice.tsx b/apps/mobile-app/components/credentials/ServiceUrlNotice.tsx
index 2a46081e6..ce87dbbee 100644
--- a/apps/mobile-app/components/credentials/ServiceUrlNotice.tsx
+++ b/apps/mobile-app/components/credentials/ServiceUrlNotice.tsx
@@ -5,7 +5,7 @@ import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import { ThemedText } from '@/components/themed/ThemedText';
import { ThemedView } from '@/components/themed/ThemedView';
import { useColors } from '@/hooks/useColorScheme';
-import { extractServiceNameFromUrl } from '@/utils/shared/service-url';
+import { extractServiceNameFromUrl } from '@/utils/UrlUtility';
interface IServiceUrlNoticeProps {
serviceUrl: string;
diff --git a/apps/mobile-app/utils/shared/service-url.ts b/apps/mobile-app/utils/UrlUtility.ts
similarity index 100%
rename from apps/mobile-app/utils/shared/service-url.ts
rename to apps/mobile-app/utils/UrlUtility.ts
diff --git a/apps/mobile-app/utils/ValidationSchema.ts b/apps/mobile-app/utils/ValidationSchema.ts
new file mode 100644
index 000000000..f7aa72bcf
--- /dev/null
+++ b/apps/mobile-app/utils/ValidationSchema.ts
@@ -0,0 +1,33 @@
+import * as Yup from 'yup';
+
+/**
+ * Credential add/edit form validation schema used by react-hook-form.
+ */
+export const credentialSchema = Yup.object().shape({
+ Id: Yup.string().optional(),
+ ServiceName: Yup.string().required('Service name is required'),
+ ServiceUrl: Yup.string().url('Invalid URL format').nullable().notRequired(),
+ Alias: Yup.object().shape({
+ FirstName: Yup.string().nullable().notRequired(),
+ LastName: Yup.string().nullable().notRequired(),
+ NickName: Yup.string().nullable().notRequired(),
+ BirthDate: Yup.string()
+ .nullable()
+ .notRequired()
+ .test(
+ 'is-valid-date-format',
+ 'Date must be in YYYY-MM-DD format',
+ value => {
+ if (!value) {
+ return true;
+ } // allow empty
+ return /^\d{4}-\d{2}-\d{2}$/.test(value);
+ },
+ ),
+ Gender: Yup.string().nullable().notRequired(),
+ Email: Yup.string().email('Invalid email format').nullable().notRequired()
+ }),
+ Username: Yup.string().nullable().notRequired(),
+ Password: Yup.string().nullable().notRequired(),
+ Notes: Yup.string().nullable().notRequired()
+});