@croacroa/react-native-template 1.0.0 → 2.0.1

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.
Files changed (70) hide show
  1. package/.github/workflows/ci.yml +187 -184
  2. package/.github/workflows/eas-build.yml +55 -55
  3. package/.github/workflows/eas-update.yml +50 -50
  4. package/CHANGELOG.md +106 -106
  5. package/CONTRIBUTING.md +377 -377
  6. package/README.md +399 -399
  7. package/__tests__/components/snapshots.test.tsx +131 -0
  8. package/__tests__/integration/auth-api.test.tsx +227 -0
  9. package/__tests__/performance/VirtualizedList.perf.test.tsx +362 -0
  10. package/app/(public)/onboarding.tsx +5 -5
  11. package/app.config.ts +45 -2
  12. package/assets/images/.gitkeep +7 -7
  13. package/components/onboarding/OnboardingScreen.tsx +370 -370
  14. package/components/onboarding/index.ts +2 -2
  15. package/components/providers/SuspenseBoundary.tsx +357 -0
  16. package/components/providers/index.ts +21 -0
  17. package/components/ui/Avatar.tsx +316 -316
  18. package/components/ui/Badge.tsx +416 -416
  19. package/components/ui/BottomSheet.tsx +307 -307
  20. package/components/ui/Checkbox.tsx +261 -261
  21. package/components/ui/OptimizedImage.tsx +369 -369
  22. package/components/ui/Select.tsx +240 -240
  23. package/components/ui/VirtualizedList.tsx +285 -0
  24. package/components/ui/index.ts +23 -18
  25. package/constants/config.ts +97 -54
  26. package/docs/adr/001-state-management.md +79 -79
  27. package/docs/adr/002-styling-approach.md +130 -130
  28. package/docs/adr/003-data-fetching.md +155 -155
  29. package/docs/adr/004-auth-adapter-pattern.md +144 -144
  30. package/docs/adr/README.md +78 -78
  31. package/hooks/index.ts +27 -25
  32. package/hooks/useApi.ts +102 -5
  33. package/hooks/useAuth.tsx +82 -0
  34. package/hooks/useBiometrics.ts +295 -295
  35. package/hooks/useDeepLinking.ts +256 -256
  36. package/hooks/useMFA.ts +499 -0
  37. package/hooks/useNotifications.ts +39 -0
  38. package/hooks/useOffline.ts +60 -6
  39. package/hooks/usePerformance.ts +434 -434
  40. package/hooks/useTheme.tsx +76 -0
  41. package/hooks/useUpdates.ts +358 -358
  42. package/i18n/index.ts +194 -77
  43. package/i18n/locales/ar.json +101 -0
  44. package/i18n/locales/de.json +101 -0
  45. package/i18n/locales/en.json +101 -101
  46. package/i18n/locales/es.json +101 -0
  47. package/i18n/locales/fr.json +101 -101
  48. package/jest.config.js +4 -4
  49. package/maestro/README.md +113 -113
  50. package/maestro/config.yaml +35 -35
  51. package/maestro/flows/login.yaml +62 -62
  52. package/maestro/flows/mfa-login.yaml +92 -0
  53. package/maestro/flows/mfa-setup.yaml +86 -0
  54. package/maestro/flows/navigation.yaml +68 -68
  55. package/maestro/flows/offline-conflict.yaml +101 -0
  56. package/maestro/flows/offline-sync.yaml +128 -0
  57. package/maestro/flows/offline.yaml +60 -60
  58. package/maestro/flows/register.yaml +94 -94
  59. package/package.json +175 -170
  60. package/services/analytics.ts +428 -428
  61. package/services/api.ts +340 -340
  62. package/services/authAdapter.ts +333 -333
  63. package/services/backgroundSync.ts +626 -0
  64. package/services/index.ts +54 -22
  65. package/services/security.ts +286 -0
  66. package/tailwind.config.js +47 -47
  67. package/utils/accessibility.ts +446 -446
  68. package/utils/index.ts +52 -43
  69. package/utils/validation.ts +2 -1
  70. package/utils/withAccessibility.tsx +272 -0
package/hooks/useAuth.tsx CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @fileoverview Authentication context and hooks
3
+ * Provides secure authentication with token management, auto-refresh, and persistent sessions.
4
+ * @module hooks/useAuth
5
+ */
6
+
1
7
  import {
2
8
  createContext,
3
9
  useContext,
@@ -10,6 +16,9 @@ import * as SecureStore from "expo-secure-store";
10
16
  import { router } from "expo-router";
11
17
  import { toast } from "@/utils/toast";
12
18
 
19
+ /**
20
+ * User profile information
21
+ */
13
22
  interface User {
14
23
  id: string;
15
24
  email: string;
@@ -23,14 +32,26 @@ interface AuthTokens {
23
32
  expiresAt: number;
24
33
  }
25
34
 
35
+ /**
36
+ * Authentication context type definition.
37
+ * Provides all authentication-related state and actions.
38
+ */
26
39
  interface AuthContextType {
40
+ /** Currently authenticated user, or null if not authenticated */
27
41
  user: User | null;
42
+ /** Whether the user is currently authenticated */
28
43
  isAuthenticated: boolean;
44
+ /** Whether the auth state is still loading (e.g., checking stored tokens) */
29
45
  isLoading: boolean;
46
+ /** Sign in with email and password */
30
47
  signIn: (email: string, password: string) => Promise<void>;
48
+ /** Create a new account */
31
49
  signUp: (email: string, password: string, name: string) => Promise<void>;
50
+ /** Sign out and clear all stored credentials */
32
51
  signOut: () => Promise<void>;
52
+ /** Update the current user's profile locally */
33
53
  updateUser: (user: Partial<User>) => void;
54
+ /** Manually refresh the session tokens */
34
55
  refreshSession: () => Promise<boolean>;
35
56
  }
36
57
 
@@ -40,6 +61,32 @@ const TOKEN_KEY = "auth_tokens";
40
61
  const USER_KEY = "auth_user";
41
62
  const TOKEN_REFRESH_THRESHOLD = 5 * 60 * 1000; // 5 minutes before expiry
42
63
 
64
+ /**
65
+ * Authentication Provider component.
66
+ * Wraps your app to provide authentication context to all children.
67
+ *
68
+ * Features:
69
+ * - Automatic token refresh before expiry
70
+ * - Secure token storage (iOS Keychain / Android Encrypted SharedPreferences)
71
+ * - Persistent sessions across app restarts
72
+ * - Automatic session validation on app launch
73
+ *
74
+ * @param children - Child components to wrap
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * // In your app root (_layout.tsx)
79
+ * export default function RootLayout() {
80
+ * return (
81
+ * <AuthProvider>
82
+ * <ThemeProvider>
83
+ * <App />
84
+ * </ThemeProvider>
85
+ * </AuthProvider>
86
+ * );
87
+ * }
88
+ * ```
89
+ */
43
90
  export function AuthProvider({ children }: { children: ReactNode }) {
44
91
  const [user, setUser] = useState<User | null>(null);
45
92
  const [tokens, setTokens] = useState<AuthTokens | null>(null);
@@ -256,6 +303,41 @@ export function AuthProvider({ children }: { children: ReactNode }) {
256
303
  );
257
304
  }
258
305
 
306
+ /**
307
+ * Hook to access authentication state and actions.
308
+ * Must be used within an AuthProvider.
309
+ *
310
+ * @returns Authentication context with user, state, and actions
311
+ * @throws Error if used outside of AuthProvider
312
+ *
313
+ * @example
314
+ * ```tsx
315
+ * function LoginScreen() {
316
+ * const { signIn, isLoading } = useAuth();
317
+ * const [email, setEmail] = useState('');
318
+ * const [password, setPassword] = useState('');
319
+ *
320
+ * const handleLogin = async () => {
321
+ * try {
322
+ * await signIn(email, password);
323
+ * // Navigation happens automatically via router
324
+ * } catch (error) {
325
+ * // Error toast is shown automatically
326
+ * }
327
+ * };
328
+ *
329
+ * return (
330
+ * <View>
331
+ * <Input value={email} onChangeText={setEmail} />
332
+ * <Input value={password} onChangeText={setPassword} secureTextEntry />
333
+ * <Button onPress={handleLogin} isLoading={isLoading}>
334
+ * Sign In
335
+ * </Button>
336
+ * </View>
337
+ * );
338
+ * }
339
+ * ```
340
+ */
259
341
  export function useAuth() {
260
342
  const context = useContext(AuthContext);
261
343
  if (context === undefined) {