@saxenapackages/auth-sdk 1.0.0

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 (45) hide show
  1. package/README.md +195 -0
  2. package/dist/api/authApi.d.ts +19 -0
  3. package/dist/api/axios.d.ts +5 -0
  4. package/dist/auth-sdk.css +1 -0
  5. package/dist/components/alert/Alert.d.ts +9 -0
  6. package/dist/components/authWidget/index.d.ts +7 -0
  7. package/dist/components/forgotPassword/index.d.ts +8 -0
  8. package/dist/components/googleLogin/index.d.ts +7 -0
  9. package/dist/components/login/index.d.ts +9 -0
  10. package/dist/components/otp/index.d.ts +12 -0
  11. package/dist/components/resetPassword/index.d.ts +8 -0
  12. package/dist/components/signup/index.d.ts +8 -0
  13. package/dist/components/updateUser/index.d.ts +9 -0
  14. package/dist/hooks/useAuth.d.ts +3 -0
  15. package/dist/hooks/useLogin.d.ts +8 -0
  16. package/dist/hooks/useOtp.d.ts +9 -0
  17. package/dist/hooks/useResetPassword.d.ts +8 -0
  18. package/dist/hooks/useSignup.d.ts +8 -0
  19. package/dist/hooks/useUpdateUser.d.ts +8 -0
  20. package/dist/hooks/useVerifyIdentity.d.ts +8 -0
  21. package/dist/index.cjs +23 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +35 -0
  24. package/dist/index.js +2248 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/provider/AuthContext.d.ts +24 -0
  27. package/dist/provider/AuthProvider.d.ts +8 -0
  28. package/dist/services/event.service.d.ts +9 -0
  29. package/dist/services/storage.service.d.ts +10 -0
  30. package/dist/services/token.service.d.ts +10 -0
  31. package/dist/setupTests.d.ts +0 -0
  32. package/dist/theme/defaultTheme.d.ts +3 -0
  33. package/dist/types/api.d.ts +10 -0
  34. package/dist/types/auth.d.ts +28 -0
  35. package/dist/types/config.d.ts +139 -0
  36. package/dist/utils/errors.d.ts +7 -0
  37. package/dist/utils/helpers.d.ts +8 -0
  38. package/dist/validation/index.d.ts +6 -0
  39. package/dist/validation/login.d.ts +28 -0
  40. package/dist/validation/otp.d.ts +8 -0
  41. package/dist/validation/resetPassword.d.ts +17 -0
  42. package/dist/validation/signup.d.ts +27 -0
  43. package/dist/validation/updateUser.d.ts +38 -0
  44. package/dist/validation/verifyIdentity.d.ts +8 -0
  45. package/package.json +49 -0
@@ -0,0 +1,24 @@
1
+ import { User } from '../types/auth';
2
+ import { AuthSdkConfig } from '../types/config';
3
+ import { AuthApi } from '../api/authApi';
4
+ export interface AuthContextProps {
5
+ user: User | null;
6
+ token: string | null;
7
+ refreshToken: string | null;
8
+ isAuthenticated: boolean;
9
+ loading: boolean;
10
+ login: (payload: Record<string, any>) => Promise<any>;
11
+ logout: () => Promise<void>;
12
+ signup: (payload: Record<string, any>) => Promise<any>;
13
+ verifyOtp: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
14
+ verifyIdentity: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
15
+ resetPassword: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
16
+ refresh: () => Promise<string | null>;
17
+ getUserProfile: (site?: string, id?: string) => Promise<any>;
18
+ updateUser: (payload: Record<string, any>, site?: string, id?: string) => Promise<any>;
19
+ deleteUser: (site?: string, id?: string) => Promise<any>;
20
+ config: AuthSdkConfig;
21
+ authApi: AuthApi | null;
22
+ }
23
+ export declare const AuthContext: import('react').Context<AuthContextProps | undefined>;
24
+ export default AuthContext;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+ import { AuthSdkConfig } from '../types/config';
3
+ interface AuthProviderProps {
4
+ children: React.ReactNode;
5
+ config: AuthSdkConfig;
6
+ }
7
+ export declare const AuthProvider: React.FC<AuthProviderProps>;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ import { AuthEvent, AuthEventCallback } from '../types/auth';
2
+ declare class EventService {
3
+ private listeners;
4
+ on(event: AuthEvent, callback: AuthEventCallback): void;
5
+ off(event: AuthEvent, callback: AuthEventCallback): void;
6
+ emit(event: AuthEvent, data?: any): void;
7
+ }
8
+ export declare const eventService: EventService;
9
+ export default eventService;
@@ -0,0 +1,10 @@
1
+ import { StorageType } from '../types/config';
2
+ export declare class StorageService {
3
+ private adapter;
4
+ constructor(storageType?: StorageType);
5
+ private resolveAdapter;
6
+ getItem(key: string): Promise<string | null>;
7
+ setItem(key: string, value: string): Promise<void>;
8
+ removeItem(key: string): Promise<void>;
9
+ clear(): Promise<void>;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { StorageService } from './storage.service';
2
+ export declare class TokenService {
3
+ private storageService;
4
+ constructor(storageService: StorageService);
5
+ saveToken(key: string, token: string): Promise<void>;
6
+ getToken(key: string): Promise<string | null>;
7
+ removeToken(key: string): Promise<void>;
8
+ decodeJWT(token: string): any;
9
+ isExpired(token: string | null): boolean;
10
+ }
File without changes
@@ -0,0 +1,3 @@
1
+ import { CustomTheme } from '../types/config';
2
+ export declare const defaultLightTheme: CustomTheme;
3
+ export declare const defaultDarkTheme: CustomTheme;
@@ -0,0 +1,10 @@
1
+ export interface ApiResponse<T = any> {
2
+ data: T;
3
+ status: number;
4
+ message?: string;
5
+ }
6
+ export interface ApiRequestOptions {
7
+ headers?: Record<string, string>;
8
+ params?: Record<string, any>;
9
+ [key: string]: any;
10
+ }
@@ -0,0 +1,28 @@
1
+ import { default as React } from 'react';
2
+ export interface User {
3
+ id?: string | number;
4
+ email?: string;
5
+ name?: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface TokenSession {
9
+ token: string | null;
10
+ refreshToken: string | null;
11
+ user: User | null;
12
+ }
13
+ export type AuthEvent = 'LOGIN_SUCCESS' | 'LOGIN_FAILED' | 'LOGOUT' | 'TOKEN_EXPIRED' | 'OTP_VERIFIED' | 'PASSWORD_RESET' | 'OTP_SENT';
14
+ export type AuthEventCallback = (data?: any) => void;
15
+ export interface ComponentOverrides {
16
+ Button?: React.ComponentType<any>;
17
+ Input?: React.ComponentType<any>;
18
+ Card?: React.ComponentType<any>;
19
+ Loader?: React.ComponentType<any>;
20
+ Checkbox?: React.ComponentType<any>;
21
+ }
22
+ export interface BaseComponentProps {
23
+ components?: ComponentOverrides;
24
+ labels?: Record<string, string>;
25
+ buttonText?: string;
26
+ placeholders?: Record<string, string>;
27
+ validationSchema?: any;
28
+ }
@@ -0,0 +1,139 @@
1
+ import { z } from 'zod';
2
+ export interface StorageAdapter {
3
+ getItem(key: string): string | null | Promise<string | null>;
4
+ setItem(key: string, value: string): void | Promise<void>;
5
+ removeItem(key: string): void | Promise<void>;
6
+ clear(): void | Promise<void>;
7
+ }
8
+ export type StorageType = 'localStorage' | 'sessionStorage' | 'memory' | StorageAdapter;
9
+ export interface EndpointsConfig {
10
+ login?: string;
11
+ signup?: string;
12
+ verifyIdentity?: string;
13
+ verifyOtp?: string;
14
+ resetPassword?: string;
15
+ googleLogin?: string;
16
+ refreshToken?: string;
17
+ logout?: string;
18
+ getUser?: string;
19
+ updateUser?: string;
20
+ deleteUser?: string;
21
+ }
22
+ export interface CustomTheme {
23
+ colors?: {
24
+ primary?: string;
25
+ primaryHover?: string;
26
+ secondary?: string;
27
+ background?: string;
28
+ surface?: string;
29
+ text?: string;
30
+ textMuted?: string;
31
+ border?: string;
32
+ error?: string;
33
+ success?: string;
34
+ [key: string]: string | undefined;
35
+ };
36
+ fonts?: {
37
+ body?: string;
38
+ heading?: string;
39
+ };
40
+ borderRadius?: string;
41
+ borderRadiusCard?: string;
42
+ borderRadiusButton?: string;
43
+ borderRadiusInput?: string;
44
+ spacing?: string;
45
+ background?: string;
46
+ logo?: string;
47
+ }
48
+ export type ThemeType = 'light' | 'dark' | CustomTheme;
49
+ export interface CustomizationConfig {
50
+ labels?: Record<string, string>;
51
+ buttonText?: Record<string, string>;
52
+ placeholders?: Record<string, string>;
53
+ translations?: Record<string, Record<string, string>>;
54
+ validationSchema?: {
55
+ login?: z.ZodSchema;
56
+ signup?: z.ZodSchema;
57
+ verifyIdentity?: z.ZodSchema;
58
+ otp?: z.ZodSchema;
59
+ resetPassword?: z.ZodSchema;
60
+ updateUser?: z.ZodSchema;
61
+ };
62
+ }
63
+ export interface AuthSdkConfig {
64
+ apiBaseUrl: string;
65
+ site?: string;
66
+ endpoints?: EndpointsConfig;
67
+ storage?: StorageType;
68
+ tokenKey?: string;
69
+ refreshTokenKey?: string;
70
+ theme?: ThemeType;
71
+ headers?: Record<string, string>;
72
+ responseMapping?: {
73
+ token?: string;
74
+ refreshToken?: string;
75
+ user?: string;
76
+ [key: string]: string | undefined;
77
+ };
78
+ requestMapping?: {
79
+ login?: {
80
+ email?: string;
81
+ password?: string;
82
+ otp?: string;
83
+ [key: string]: string | undefined;
84
+ };
85
+ signup?: {
86
+ name?: string;
87
+ email?: string;
88
+ password?: string;
89
+ verifyPassword?: string;
90
+ [key: string]: string | undefined;
91
+ };
92
+ verifyIdentity?: {
93
+ email?: string;
94
+ [key: string]: string | undefined;
95
+ };
96
+ otp?: {
97
+ otp?: string;
98
+ email?: string;
99
+ token?: string;
100
+ [key: string]: string | undefined;
101
+ };
102
+ resetPassword?: {
103
+ password?: string;
104
+ verifyPassword?: string;
105
+ [key: string]: string | undefined;
106
+ };
107
+ updateUser?: {
108
+ fullName?: string;
109
+ email?: string;
110
+ username?: string;
111
+ phoneNumber?: string;
112
+ profileUrl?: string;
113
+ password?: string;
114
+ city?: string;
115
+ state?: string;
116
+ country?: string;
117
+ postalcode?: string;
118
+ [key: string]: string | undefined;
119
+ };
120
+ [key: string]: Record<string, string | undefined> | undefined;
121
+ };
122
+ enableRefreshToken?: boolean;
123
+ enableGoogleLogin?: boolean;
124
+ enableOtpLogin?: boolean;
125
+ autoLogin?: boolean;
126
+ autoRefresh?: boolean;
127
+ customization?: CustomizationConfig;
128
+ isExternalApiCall?: boolean;
129
+ onLogin?: (payload: Record<string, any>) => Promise<any>;
130
+ onSignup?: (payload: Record<string, any>) => Promise<any>;
131
+ onVerifyIdentity?: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
132
+ onVerifyOtp?: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
133
+ onResetPassword?: (payload: Record<string, any>, urlParams?: Record<string, string | number>) => Promise<any>;
134
+ onUpdateUser?: (payload: Record<string, any>, site?: string, id?: string) => Promise<any>;
135
+ onDeleteUser?: (site?: string, id?: string) => Promise<any>;
136
+ onLogout?: () => Promise<void>;
137
+ onRefresh?: (refreshToken: string) => Promise<any>;
138
+ onGetUser?: (site?: string, id?: string) => Promise<any>;
139
+ }
@@ -0,0 +1,7 @@
1
+ export type SdkErrorCode = 'INVALID_CREDENTIALS' | 'OTP_EXPIRED' | 'USER_NOT_FOUND' | 'TOKEN_EXPIRED' | 'SERVER_ERROR' | 'NETWORK_ERROR' | 'UNKNOWN_ERROR';
2
+ export declare class AuthSdkError extends Error {
3
+ code: SdkErrorCode;
4
+ originalError?: any;
5
+ constructor(message: string, code: SdkErrorCode, originalError?: any);
6
+ }
7
+ export declare function normalizeError(error: any): AuthSdkError;
@@ -0,0 +1,8 @@
1
+ export declare function decodeJWT(token: string): any;
2
+ export declare function isTokenExpired(token: string | null): boolean;
3
+ export declare function getNestedValue(obj: any, path: string): any;
4
+ export declare function setNestedValue(obj: any, path: string, value: any): any;
5
+ export declare function mapPayload(payload: Record<string, any>, mapping?: Record<string, string>): Record<string, any>;
6
+ export declare function getAccessTokenFromResponse(data: any, mappingPath?: string): string | null;
7
+ export declare function getRefreshTokenFromResponse(data: any, mappingPath?: string): string | null;
8
+ export declare function getUserFromResponse(data: any, mappingPath?: string): any;
@@ -0,0 +1,6 @@
1
+ export { loginSchema, otpEmailSchema, otpSubmitSchema } from './login';
2
+ export { signupSchema } from './signup';
3
+ export { verifyIdentitySchema } from './verifyIdentity';
4
+ export { otpSchema } from './otp';
5
+ export { resetPasswordSchema } from './resetPassword';
6
+ export { updateUserSchema } from './updateUser';
@@ -0,0 +1,28 @@
1
+ import { z } from 'zod';
2
+ export declare const loginSchema: z.ZodObject<{
3
+ email: z.ZodString;
4
+ password: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ email: string;
7
+ password: string;
8
+ }, {
9
+ email: string;
10
+ password: string;
11
+ }>;
12
+ export declare const otpEmailSchema: z.ZodObject<{
13
+ email: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ email: string;
16
+ }, {
17
+ email: string;
18
+ }>;
19
+ export declare const otpSubmitSchema: z.ZodObject<{
20
+ email: z.ZodString;
21
+ otp: z.ZodString;
22
+ }, "strip", z.ZodTypeAny, {
23
+ email: string;
24
+ otp: string;
25
+ }, {
26
+ email: string;
27
+ otp: string;
28
+ }>;
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ export declare const otpSchema: z.ZodObject<{
3
+ otp: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ otp: string;
6
+ }, {
7
+ otp: string;
8
+ }>;
@@ -0,0 +1,17 @@
1
+ import { z } from 'zod';
2
+ export declare const resetPasswordSchema: z.ZodEffects<z.ZodObject<{
3
+ password: z.ZodString;
4
+ verifyPassword: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ password: string;
7
+ verifyPassword: string;
8
+ }, {
9
+ password: string;
10
+ verifyPassword: string;
11
+ }>, {
12
+ password: string;
13
+ verifyPassword: string;
14
+ }, {
15
+ password: string;
16
+ verifyPassword: string;
17
+ }>;
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ export declare const signupSchema: z.ZodEffects<z.ZodObject<{
3
+ name: z.ZodString;
4
+ email: z.ZodString;
5
+ password: z.ZodString;
6
+ verifyPassword: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ email: string;
9
+ name: string;
10
+ password: string;
11
+ verifyPassword: string;
12
+ }, {
13
+ email: string;
14
+ name: string;
15
+ password: string;
16
+ verifyPassword: string;
17
+ }>, {
18
+ email: string;
19
+ name: string;
20
+ password: string;
21
+ verifyPassword: string;
22
+ }, {
23
+ email: string;
24
+ name: string;
25
+ password: string;
26
+ verifyPassword: string;
27
+ }>;
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+ export declare const updateUserSchema: z.ZodObject<{
3
+ fullName: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
4
+ email: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
5
+ username: z.ZodOptional<z.ZodString>;
6
+ phoneNumber: z.ZodOptional<z.ZodString>;
7
+ password: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
8
+ profileUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
9
+ city: z.ZodOptional<z.ZodString>;
10
+ state: z.ZodOptional<z.ZodString>;
11
+ country: z.ZodOptional<z.ZodString>;
12
+ postalcode: z.ZodOptional<z.ZodString>;
13
+ timezone: z.ZodOptional<z.ZodString>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ email?: string | undefined;
16
+ password?: string | undefined;
17
+ fullName?: string | undefined;
18
+ username?: string | undefined;
19
+ phoneNumber?: string | undefined;
20
+ profileUrl?: string | undefined;
21
+ city?: string | undefined;
22
+ state?: string | undefined;
23
+ country?: string | undefined;
24
+ postalcode?: string | undefined;
25
+ timezone?: string | undefined;
26
+ }, {
27
+ email?: string | undefined;
28
+ password?: string | undefined;
29
+ fullName?: string | undefined;
30
+ username?: string | undefined;
31
+ phoneNumber?: string | undefined;
32
+ profileUrl?: string | undefined;
33
+ city?: string | undefined;
34
+ state?: string | undefined;
35
+ country?: string | undefined;
36
+ postalcode?: string | undefined;
37
+ timezone?: string | undefined;
38
+ }>;
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ export declare const verifyIdentitySchema: z.ZodObject<{
3
+ email: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ email: string;
6
+ }, {
7
+ email: string;
8
+ }>;
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@saxenapackages/auth-sdk",
3
+ "version": "1.0.0",
4
+ "description": "A production-grade, highly customizable React Authentication SDK",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./dist/auth-sdk.css": "./dist/auth-sdk.css"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "vite build",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "lint": "eslint src --ext .ts,.tsx"
25
+ },
26
+ "dependencies": {
27
+ "axios": "^1.6.8",
28
+ "zod": "^3.22.4"
29
+ },
30
+ "peerDependencies": {
31
+ "react": "^18.2.0 || ^19.0.0",
32
+ "react-dom": "^18.2.0 || ^19.0.0",
33
+ "react-router-dom": "^6.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@testing-library/jest-dom": "^6.9.1",
37
+ "@types/node": "^26.1.1",
38
+ "@types/react": "^19.2.17",
39
+ "@types/react-dom": "^19.2.3",
40
+ "@typescript/typescript6": "^6.0.2",
41
+ "@vitejs/plugin-react": "^4.7.0",
42
+ "eslint": "^9.39.5",
43
+ "jsdom": "^26.1.0",
44
+ "typescript": "^7.0.2",
45
+ "vite": "^6.4.3",
46
+ "vite-plugin-dts": "^5.0.3",
47
+ "vitest": "^3.2.7"
48
+ }
49
+ }