@bid-scents/shared-sdk 1.0.3 → 1.0.4

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.
@@ -4,37 +4,31 @@ interface AuthState {
4
4
  session: any | null;
5
5
  isAuthenticated: boolean;
6
6
  isOnboarded: boolean;
7
+ loading: boolean;
8
+ error: string | null;
7
9
  setUser: (user: User | null) => void;
8
10
  setSession: (session: any | null) => void;
11
+ setLoading: (loading: boolean) => void;
12
+ setError: (error: string | null) => void;
9
13
  logout: () => void;
10
14
  }
11
15
  /**
12
16
  * Zustand store for authentication state management with Supabase.
13
17
  *
14
- * Manages user data and Supabase session which contains tokens.
18
+ * Manages user data, session state, loading states, and errors.
15
19
  * Supabase automatically handles token refresh in the background.
16
20
  *
17
- * @returns Auth store with user state, session, and actions
21
+ * @returns Auth store with user state, session, loading, and actions
18
22
  */
19
23
  export declare const useAuthStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AuthState>, "persist"> & {
20
24
  persist: {
21
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AuthState, {
22
- user: User | null;
23
- session: any;
24
- isAuthenticated: boolean;
25
- isOnboarded: boolean;
26
- }>>) => void;
25
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<AuthState, unknown>>) => void;
27
26
  clearStorage: () => void;
28
27
  rehydrate: () => Promise<void> | void;
29
28
  hasHydrated: () => boolean;
30
29
  onHydrate: (fn: (state: AuthState) => void) => () => void;
31
30
  onFinishHydration: (fn: (state: AuthState) => void) => () => void;
32
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<AuthState, {
33
- user: User | null;
34
- session: any;
35
- isAuthenticated: boolean;
36
- isOnboarded: boolean;
37
- }>>;
31
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<AuthState, unknown>>;
38
32
  };
39
33
  }>;
40
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/stores/auth.ts"],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;;;;EAiFxB,CAAA"}
@@ -1,19 +1,21 @@
1
- // Manages user authentication state with Supabase integration.
2
1
  import { create } from 'zustand';
3
- import { persist } from 'zustand/middleware';
2
+ import { persist, createJSONStorage } from 'zustand/middleware';
3
+ import AsyncStorage from '@react-native-async-storage/async-storage';
4
4
  /**
5
5
  * Zustand store for authentication state management with Supabase.
6
6
  *
7
- * Manages user data and Supabase session which contains tokens.
7
+ * Manages user data, session state, loading states, and errors.
8
8
  * Supabase automatically handles token refresh in the background.
9
9
  *
10
- * @returns Auth store with user state, session, and actions
10
+ * @returns Auth store with user state, session, loading, and actions
11
11
  */
12
12
  export const useAuthStore = create()(persist((set) => ({
13
13
  user: null,
14
14
  session: null,
15
15
  isAuthenticated: false,
16
16
  isOnboarded: false,
17
+ loading: true, // Start with loading true
18
+ error: null,
17
19
  /**
18
20
  * Updates the current user and onboarding status.
19
21
  *
@@ -22,7 +24,9 @@ export const useAuthStore = create()(persist((set) => ({
22
24
  setUser: (user) => {
23
25
  set({
24
26
  user,
25
- isOnboarded: !!user?.onboarded_at
27
+ isOnboarded: !!user?.onboarded_at,
28
+ loading: false, // Clear loading when user is set
29
+ error: null // Clear any errors
26
30
  });
27
31
  },
28
32
  /**
@@ -33,9 +37,26 @@ export const useAuthStore = create()(persist((set) => ({
33
37
  setSession: (session) => {
34
38
  set({
35
39
  session,
36
- isAuthenticated: !!session
40
+ isAuthenticated: !!session,
41
+ loading: false // Clear loading when session is determined
37
42
  });
38
43
  },
44
+ /**
45
+ * Sets the loading state.
46
+ *
47
+ * @param loading - Loading state boolean
48
+ */
49
+ setLoading: (loading) => {
50
+ set({ loading });
51
+ },
52
+ /**
53
+ * Sets the error state.
54
+ *
55
+ * @param error - Error message or null to clear
56
+ */
57
+ setError: (error) => {
58
+ set({ error, loading: false });
59
+ },
39
60
  /**
40
61
  * Clears all authentication state.
41
62
  */
@@ -44,15 +65,19 @@ export const useAuthStore = create()(persist((set) => ({
44
65
  user: null,
45
66
  session: null,
46
67
  isAuthenticated: false,
47
- isOnboarded: false
68
+ isOnboarded: false,
69
+ loading: false,
70
+ error: null
48
71
  });
49
72
  }
50
73
  }), {
51
74
  name: 'auth-storage',
75
+ storage: createJSONStorage(() => AsyncStorage),
52
76
  partialize: (state) => ({
53
77
  user: state.user,
54
78
  session: state.session,
55
79
  isAuthenticated: state.isAuthenticated,
56
80
  isOnboarded: state.isOnboarded
81
+ // Don't persist loading or error states
57
82
  })
58
83
  }));
@@ -1,4 +1,4 @@
1
1
  export { handleAuthStateChange, initializeAuth } from './auth/supabase-config';
2
- export { onboardingSchema, usernameSchema } from './validation/schemas';
3
- export type { OnboardingFormData } from './validation/schemas';
2
+ export { loginSchema, signUpSchema, onboardingSchema, usernameSchema } from './validation/schemas';
3
+ export type { OnboardingFormData, LoginFormData, SignUpFormData } from './validation/schemas';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,qBAAqB,EACrB,cAAc,EACf,MAAM,wBAAwB,CAAA;AAEjC,OAAO,EACH,gBAAgB,EAChB,cAAc,EACf,MAAM,sBAAsB,CAAA;AAE/B,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,qBAAqB,EACrB,cAAc,EACf,MAAM,wBAAwB,CAAA;AAEjC,OAAO,EACH,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACf,MAAM,sBAAsB,CAAA;AAE/B,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA"}
@@ -1,3 +1,3 @@
1
1
  // Central export for all utilities.
2
2
  export { handleAuthStateChange, initializeAuth } from './auth/supabase-config';
3
- export { onboardingSchema, usernameSchema } from './validation/schemas';
3
+ export { loginSchema, signUpSchema, onboardingSchema, usernameSchema } from './validation/schemas';
@@ -1,4 +1,47 @@
1
1
  import { z } from 'zod';
2
+ /**
3
+ * Validation schema for user login form.
4
+ *
5
+ * Enforces email format and basic password requirements.
6
+ * Used for client-side validation before authentication.
7
+ */
8
+ export declare const loginSchema: z.ZodObject<{
9
+ email: z.ZodString;
10
+ password: z.ZodString;
11
+ }, "strip", z.ZodTypeAny, {
12
+ password: string;
13
+ email: string;
14
+ }, {
15
+ password: string;
16
+ email: string;
17
+ }>;
18
+ /**
19
+ * Validation schema for user registration form.
20
+ *
21
+ * Enforces strong password requirements and password confirmation.
22
+ * Used for client-side validation before account creation.
23
+ */
24
+ export declare const signUpSchema: z.ZodEffects<z.ZodObject<{
25
+ email: z.ZodString;
26
+ password: z.ZodString;
27
+ confirmPassword: z.ZodString;
28
+ }, "strip", z.ZodTypeAny, {
29
+ password: string;
30
+ email: string;
31
+ confirmPassword: string;
32
+ }, {
33
+ password: string;
34
+ email: string;
35
+ confirmPassword: string;
36
+ }>, {
37
+ password: string;
38
+ email: string;
39
+ confirmPassword: string;
40
+ }, {
41
+ password: string;
42
+ email: string;
43
+ confirmPassword: string;
44
+ }>;
2
45
  /**
3
46
  * Validation schema for user onboarding form data.
4
47
  *
@@ -27,14 +70,24 @@ export declare const onboardingSchema: z.ZodObject<{
27
70
  cover_image_url?: string | undefined;
28
71
  bio?: string | undefined;
29
72
  }>;
30
- /**
31
- * TypeScript type inferred from the onboarding validation schema.
32
- * Use this type for form components and validation results.
33
- */
34
- export type OnboardingFormData = z.infer<typeof onboardingSchema>;
35
73
  /**
36
74
  * Validation schema for username availability checking.
37
75
  * Used for real-time username validation during form input.
38
76
  */
39
77
  export declare const usernameSchema: z.ZodString;
78
+ /**
79
+ * TypeScript type inferred from the login validation schema.
80
+ * Use this type for login form components and validation results.
81
+ */
82
+ export type LoginFormData = z.infer<typeof loginSchema>;
83
+ /**
84
+ * TypeScript type inferred from the sign up validation schema.
85
+ * Use this type for registration form components and validation results.
86
+ */
87
+ export type SignUpFormData = z.infer<typeof signUpSchema>;
88
+ /**
89
+ * TypeScript type inferred from the onboarding validation schema.
90
+ * Use this type for onboarding form components and validation results.
91
+ */
92
+ export type OnboardingFormData = z.infer<typeof onboardingSchema>;
40
93
  //# sourceMappingURL=schemas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/utils/validation/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;EAiC3B,CAAA;AAGF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAEjE;;;GAGG;AACH,eAAO,MAAM,cAAc,aAI+D,CAAA"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/utils/validation/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;;;;;EAStB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;EAkBvB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;EAiC3B,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,aAI+D,CAAA;AAE1F;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAA;AAEvD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAEzD;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA"}
@@ -1,5 +1,46 @@
1
1
  // Zod validation schemas for form inputs and data validation.
2
2
  import { z } from 'zod';
3
+ /**
4
+ * Validation schema for user login form.
5
+ *
6
+ * Enforces email format and basic password requirements.
7
+ * Used for client-side validation before authentication.
8
+ */
9
+ export const loginSchema = z.object({
10
+ email: z
11
+ .string()
12
+ .min(1, 'Email is required')
13
+ .email('Please enter a valid email address'),
14
+ password: z
15
+ .string()
16
+ .min(1, 'Password is required')
17
+ .min(6, 'Password must be at least 6 characters')
18
+ });
19
+ /**
20
+ * Validation schema for user registration form.
21
+ *
22
+ * Enforces strong password requirements and password confirmation.
23
+ * Used for client-side validation before account creation.
24
+ */
25
+ export const signUpSchema = z.object({
26
+ email: z
27
+ .string()
28
+ .min(1, 'Email is required')
29
+ .email('Please enter a valid email address'),
30
+ password: z
31
+ .string()
32
+ .min(1, 'Password is required')
33
+ .min(8, 'Password must be at least 8 characters')
34
+ .regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
35
+ .regex(/[a-z]/, 'Password must contain at least one lowercase letter')
36
+ .regex(/\d/, 'Password must contain at least one number'),
37
+ confirmPassword: z
38
+ .string()
39
+ .min(1, 'Please confirm your password')
40
+ }).refine((data) => data.password === data.confirmPassword, {
41
+ message: "Passwords don't match",
42
+ path: ['confirmPassword']
43
+ });
3
44
  /**
4
45
  * Validation schema for user onboarding form data.
5
46
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bid-scents/shared-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Shared SDK for marketplace applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -30,9 +30,10 @@
30
30
  "typescript": "^5.0.0"
31
31
  },
32
32
  "dependencies": {
33
- "zustand": "^5.0.5",
33
+ "@react-native-async-storage/async-storage": "^2.2.0",
34
+ "@tanstack/react-query": "^5.80.7",
34
35
  "zod": "^3.25.64",
35
- "@tanstack/react-query": "^5.80.7"
36
+ "zustand": "^5.0.5"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@types/bun": "latest",