@oxyhq/services 5.9.1 → 5.9.3
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/README.md +1 -33
- package/lib/commonjs/core/OxyServices.js +159 -0
- package/lib/commonjs/core/OxyServices.js.map +1 -0
- package/lib/commonjs/core/OxyServicesMain.js +51 -0
- package/lib/commonjs/core/OxyServicesMain.js.map +1 -0
- package/lib/commonjs/core/analytics/AnalyticsService.js +67 -0
- package/lib/commonjs/core/analytics/AnalyticsService.js.map +1 -0
- package/lib/commonjs/core/auth/AuthService.js +526 -0
- package/lib/commonjs/core/auth/AuthService.js.map +1 -0
- package/lib/commonjs/core/devices/DeviceService.js +61 -0
- package/lib/commonjs/core/devices/DeviceService.js.map +1 -0
- package/lib/commonjs/core/files/FileService.js +176 -0
- package/lib/commonjs/core/files/FileService.js.map +1 -0
- package/lib/commonjs/core/index.js +103 -1707
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/karma/KarmaService.js +100 -0
- package/lib/commonjs/core/karma/KarmaService.js.map +1 -0
- package/lib/commonjs/core/locations/LocationService.js +131 -0
- package/lib/commonjs/core/locations/LocationService.js.map +1 -0
- package/lib/commonjs/core/payments/PaymentService.js +124 -0
- package/lib/commonjs/core/payments/PaymentService.js.map +1 -0
- package/lib/commonjs/core/users/UserService.js +234 -0
- package/lib/commonjs/core/users/UserService.js.map +1 -0
- package/lib/commonjs/index.js +164 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/session.js +2 -0
- package/lib/{module/types/middleware.js.map → commonjs/models/session.js.map} +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +28 -24
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +2 -2
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/FileManagementScreen.js +12 -12
- package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ProfileScreen.js +2 -2
- package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SignInScreen.js +1 -1
- package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
- package/lib/commonjs/ui/stores/followStore.js +4 -4
- package/lib/commonjs/ui/stores/followStore.js.map +1 -1
- package/lib/commonjs/utils/apiUtils.js +93 -0
- package/lib/commonjs/utils/apiUtils.js.map +1 -0
- package/lib/commonjs/utils/asyncUtils.js +219 -0
- package/lib/commonjs/utils/asyncUtils.js.map +1 -0
- package/lib/commonjs/utils/errorUtils.js +148 -0
- package/lib/commonjs/utils/errorUtils.js.map +1 -0
- package/lib/commonjs/utils/hookUtils.js +399 -0
- package/lib/commonjs/utils/hookUtils.js.map +1 -0
- package/lib/commonjs/utils/loggerUtils.js +160 -0
- package/lib/commonjs/utils/loggerUtils.js.map +1 -0
- package/lib/commonjs/utils/validationUtils.js +174 -0
- package/lib/commonjs/utils/validationUtils.js.map +1 -0
- package/lib/module/core/OxyServices.js +153 -0
- package/lib/module/core/OxyServices.js.map +1 -0
- package/lib/module/core/OxyServicesMain.js +47 -0
- package/lib/module/core/OxyServicesMain.js.map +1 -0
- package/lib/module/core/analytics/AnalyticsService.js +62 -0
- package/lib/module/core/analytics/AnalyticsService.js.map +1 -0
- package/lib/module/core/auth/AuthService.js +521 -0
- package/lib/module/core/auth/AuthService.js.map +1 -0
- package/lib/module/core/devices/DeviceService.js +57 -0
- package/lib/module/core/devices/DeviceService.js.map +1 -0
- package/lib/module/core/files/FileService.js +171 -0
- package/lib/module/core/files/FileService.js.map +1 -0
- package/lib/module/core/index.js +25 -1694
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/karma/KarmaService.js +95 -0
- package/lib/module/core/karma/KarmaService.js.map +1 -0
- package/lib/module/core/locations/LocationService.js +127 -0
- package/lib/module/core/locations/LocationService.js.map +1 -0
- package/lib/module/core/payments/PaymentService.js +119 -0
- package/lib/module/core/payments/PaymentService.js.map +1 -0
- package/lib/module/core/users/UserService.js +230 -0
- package/lib/module/core/users/UserService.js.map +1 -0
- package/lib/module/index.js +8 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/session.js +2 -0
- package/lib/{commonjs/types/middleware.js.map → module/models/session.js.map} +1 -1
- package/lib/module/ui/context/OxyContext.js +28 -24
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +2 -2
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/FileManagementScreen.js +12 -12
- package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/module/ui/screens/ProfileScreen.js +2 -2
- package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
- package/lib/module/ui/screens/SignInScreen.js +1 -1
- package/lib/module/ui/screens/SignInScreen.js.map +1 -1
- package/lib/module/ui/screens/karma/KarmaCenterScreen.js +1 -1
- package/lib/module/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
- package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
- package/lib/module/ui/screens/karma/KarmaRulesScreen.js +1 -1
- package/lib/module/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
- package/lib/module/ui/stores/followStore.js +4 -4
- package/lib/module/ui/stores/followStore.js.map +1 -1
- package/lib/module/utils/apiUtils.js +85 -0
- package/lib/module/utils/apiUtils.js.map +1 -0
- package/lib/module/utils/asyncUtils.js +202 -0
- package/lib/module/utils/asyncUtils.js.map +1 -0
- package/lib/module/utils/errorUtils.js +139 -0
- package/lib/module/utils/errorUtils.js.map +1 -0
- package/lib/module/utils/hookUtils.js +381 -0
- package/lib/module/utils/hookUtils.js.map +1 -0
- package/lib/module/utils/loggerUtils.js +149 -0
- package/lib/module/utils/loggerUtils.js.map +1 -0
- package/lib/module/utils/validationUtils.js +154 -0
- package/lib/module/utils/validationUtils.js.map +1 -0
- package/lib/typescript/core/OxyServices.d.ts +64 -0
- package/lib/typescript/core/OxyServices.d.ts.map +1 -0
- package/lib/typescript/core/OxyServicesMain.d.ts +33 -0
- package/lib/typescript/core/OxyServicesMain.d.ts.map +1 -0
- package/lib/typescript/core/analytics/AnalyticsService.d.ts +26 -0
- package/lib/typescript/core/analytics/AnalyticsService.d.ts.map +1 -0
- package/lib/typescript/core/auth/AuthService.d.ts +165 -0
- package/lib/typescript/core/auth/AuthService.d.ts.map +1 -0
- package/lib/typescript/core/devices/DeviceService.d.ts +20 -0
- package/lib/typescript/core/devices/DeviceService.d.ts.map +1 -0
- package/lib/typescript/core/files/FileService.d.ts +59 -0
- package/lib/typescript/core/files/FileService.d.ts.map +1 -0
- package/lib/typescript/core/index.d.ts +19 -657
- package/lib/typescript/core/index.d.ts.map +1 -1
- package/lib/typescript/core/karma/KarmaService.d.ts +50 -0
- package/lib/typescript/core/karma/KarmaService.d.ts.map +1 -0
- package/lib/typescript/core/locations/LocationService.d.ts +39 -0
- package/lib/typescript/core/locations/LocationService.d.ts.map +1 -0
- package/lib/typescript/core/payments/PaymentService.d.ts +50 -0
- package/lib/typescript/core/payments/PaymentService.d.ts.map +1 -0
- package/lib/typescript/core/users/UserService.d.ts +111 -0
- package/lib/typescript/core/users/UserService.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/{secureSession.d.ts → session.d.ts} +4 -4
- package/lib/typescript/models/session.d.ts.map +1 -0
- package/lib/typescript/ui/context/OxyContext.d.ts +2 -2
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/utils/apiUtils.d.ts +61 -0
- package/lib/typescript/utils/apiUtils.d.ts.map +1 -0
- package/lib/typescript/utils/asyncUtils.d.ts +64 -0
- package/lib/typescript/utils/asyncUtils.d.ts.map +1 -0
- package/lib/typescript/utils/errorUtils.d.ts +45 -0
- package/lib/typescript/utils/errorUtils.d.ts.map +1 -0
- package/lib/typescript/utils/hookUtils.d.ts +102 -0
- package/lib/typescript/utils/hookUtils.d.ts.map +1 -0
- package/lib/typescript/utils/loggerUtils.d.ts +49 -0
- package/lib/typescript/utils/loggerUtils.d.ts.map +1 -0
- package/lib/typescript/utils/validationUtils.d.ts +80 -0
- package/lib/typescript/utils/validationUtils.d.ts.map +1 -0
- package/package.json +2 -8
- package/src/core/OxyServices.ts +168 -0
- package/src/core/OxyServicesMain.ts +57 -0
- package/src/core/analytics/AnalyticsService.ts +64 -0
- package/src/core/auth/AuthService.ts +544 -0
- package/src/core/devices/DeviceService.ts +55 -0
- package/src/core/files/FileService.ts +194 -0
- package/src/core/index.ts +26 -1769
- package/src/core/karma/KarmaService.ts +104 -0
- package/src/core/locations/LocationService.ts +141 -0
- package/src/core/payments/PaymentService.ts +133 -0
- package/src/core/users/UserService.ts +241 -0
- package/src/index.ts +29 -8
- package/src/models/{secureSession.ts → session.ts} +5 -5
- package/src/ui/context/OxyContext.tsx +34 -30
- package/src/ui/screens/AccountSwitcherScreen.tsx +4 -4
- package/src/ui/screens/FileManagementScreen.tsx +12 -12
- package/src/ui/screens/ProfileScreen.tsx +3 -3
- package/src/ui/screens/SessionManagementScreen.tsx +2 -2
- package/src/ui/screens/SignInScreen.tsx +1 -1
- package/src/ui/screens/karma/KarmaCenterScreen.tsx +2 -2
- package/src/ui/screens/karma/KarmaLeaderboardScreen.tsx +3 -3
- package/src/ui/screens/karma/KarmaRulesScreen.tsx +3 -3
- package/src/ui/stores/followStore.ts +4 -4
- package/src/utils/apiUtils.ts +102 -0
- package/src/utils/asyncUtils.ts +265 -0
- package/src/utils/errorUtils.ts +172 -0
- package/src/utils/hookUtils.ts +397 -0
- package/src/utils/loggerUtils.ts +153 -0
- package/src/utils/validationUtils.ts +158 -0
- package/lib/commonjs/models/secureSession.js +0 -2
- package/lib/commonjs/models/secureSession.js.map +0 -1
- package/lib/commonjs/types/middleware.js +0 -6
- package/lib/module/models/secureSession.js +0 -2
- package/lib/module/models/secureSession.js.map +0 -1
- package/lib/module/types/middleware.js +0 -4
- package/lib/typescript/models/secureSession.d.ts.map +0 -1
- package/lib/typescript/types/middleware.d.ts +0 -19
- package/lib/typescript/types/middleware.d.ts.map +0 -1
- package/src/types/middleware.ts +0 -20
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React hook utilities for common patterns and state management
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Hook for managing async operations with loading, error, and data states
|
|
6
|
+
*/
|
|
7
|
+
export declare function useAsync<T>(asyncFn: () => Promise<T>, deps?: any[]): {
|
|
8
|
+
data: T | null;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
execute: () => Promise<T>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Hook for managing async operations that execute on mount
|
|
15
|
+
*/
|
|
16
|
+
export declare function useAsyncEffect<T>(asyncFn: () => Promise<T>, deps?: any[]): {
|
|
17
|
+
data: T | null;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
error: Error | null;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Hook for debounced values
|
|
23
|
+
*/
|
|
24
|
+
export declare function useDebounce<T>(value: T, delay: number): T;
|
|
25
|
+
/**
|
|
26
|
+
* Hook for throttled values
|
|
27
|
+
*/
|
|
28
|
+
export declare function useThrottle<T>(value: T, delay: number): T;
|
|
29
|
+
/**
|
|
30
|
+
* Hook for previous value
|
|
31
|
+
*/
|
|
32
|
+
export declare function usePrevious<T>(value: T): T | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Hook for boolean state with toggle
|
|
35
|
+
*/
|
|
36
|
+
export declare function useToggle(initialValue?: boolean): {
|
|
37
|
+
value: boolean;
|
|
38
|
+
toggle: () => void;
|
|
39
|
+
setTrue: () => void;
|
|
40
|
+
setFalse: () => void;
|
|
41
|
+
setValue: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Hook for counter state
|
|
45
|
+
*/
|
|
46
|
+
export declare function useCounter(initialValue?: number): {
|
|
47
|
+
count: number;
|
|
48
|
+
increment: () => void;
|
|
49
|
+
decrement: () => void;
|
|
50
|
+
reset: () => void;
|
|
51
|
+
setValue: (value: number) => void;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Hook for local storage
|
|
55
|
+
*/
|
|
56
|
+
export declare function useLocalStorage<T>(key: string, initialValue: T): readonly [T, (value: T | ((val: T) => T)) => void];
|
|
57
|
+
/**
|
|
58
|
+
* Hook for session storage
|
|
59
|
+
*/
|
|
60
|
+
export declare function useSessionStorage<T>(key: string, initialValue: T): readonly [T, (value: T | ((val: T) => T)) => void];
|
|
61
|
+
/**
|
|
62
|
+
* Hook for window size
|
|
63
|
+
*/
|
|
64
|
+
export declare function useWindowSize(): {
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Hook for scroll position
|
|
70
|
+
*/
|
|
71
|
+
export declare function useScrollPosition(): number;
|
|
72
|
+
/**
|
|
73
|
+
* Hook for online/offline status
|
|
74
|
+
*/
|
|
75
|
+
export declare function useOnlineStatus(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Hook for media queries
|
|
78
|
+
*/
|
|
79
|
+
export declare function useMediaQuery(query: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Hook for keyboard events
|
|
82
|
+
*/
|
|
83
|
+
export declare function useKeyPress(targetKey: string): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Hook for click outside detection
|
|
86
|
+
*/
|
|
87
|
+
export declare function useClickOutside(ref: React.RefObject<HTMLElement>, handler: () => void): void;
|
|
88
|
+
/**
|
|
89
|
+
* Hook for form validation
|
|
90
|
+
*/
|
|
91
|
+
export declare function useFormValidation<T extends Record<string, any>>(initialValues: T, validationSchema: (values: T) => Partial<Record<keyof T, string>>): {
|
|
92
|
+
values: T;
|
|
93
|
+
errors: Partial<Record<keyof T, string>>;
|
|
94
|
+
touched: Partial<Record<keyof T, boolean>>;
|
|
95
|
+
isValid: boolean;
|
|
96
|
+
setValue: (field: keyof T, value: any) => void;
|
|
97
|
+
setTouchedField: (field: keyof T) => void;
|
|
98
|
+
setValues: import("react").Dispatch<import("react").SetStateAction<T>>;
|
|
99
|
+
setErrors: import("react").Dispatch<import("react").SetStateAction<Partial<Record<keyof T, string>>>>;
|
|
100
|
+
setTouched: import("react").Dispatch<import("react").SetStateAction<Partial<Record<keyof T, boolean>>>>;
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=hookUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hookUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/hookUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,IAAI,GAAE,GAAG,EAAO;;;;;EAwBjB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACzB,IAAI,GAAE,GAAG,EAAO;;;;EAiCjB;AAED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B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7D,aAAa,EAAE,CAAC,EAChB,gBAAgB,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;;;;;sBAU5B,MAAM,CAAC,SAAS,GAAG;6BAQZ,MAAM,CAAC;;;;EAsBpD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized logging utilities for consistent logging across the application
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
DEBUG = 0,
|
|
6
|
+
INFO = 1,
|
|
7
|
+
WARN = 2,
|
|
8
|
+
ERROR = 3,
|
|
9
|
+
NONE = 4
|
|
10
|
+
}
|
|
11
|
+
export interface LogContext {
|
|
12
|
+
component?: string;
|
|
13
|
+
method?: string;
|
|
14
|
+
userId?: string;
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
requestId?: string;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
declare class Logger {
|
|
20
|
+
private level;
|
|
21
|
+
private isDevelopment;
|
|
22
|
+
setLevel(level: LogLevel): void;
|
|
23
|
+
private shouldLog;
|
|
24
|
+
private formatMessage;
|
|
25
|
+
debug(message: string, context?: LogContext, ...args: any[]): void;
|
|
26
|
+
info(message: string, context?: LogContext, ...args: any[]): void;
|
|
27
|
+
warn(message: string, context?: LogContext, ...args: any[]): void;
|
|
28
|
+
error(message: string, error?: any, context?: LogContext, ...args: any[]): void;
|
|
29
|
+
auth(message: string, context?: LogContext, ...args: any[]): void;
|
|
30
|
+
api(message: string, context?: LogContext, ...args: any[]): void;
|
|
31
|
+
session(message: string, context?: LogContext, ...args: any[]): void;
|
|
32
|
+
user(message: string, context?: LogContext, ...args: any[]): void;
|
|
33
|
+
device(message: string, context?: LogContext, ...args: any[]): void;
|
|
34
|
+
payment(message: string, context?: LogContext, ...args: any[]): void;
|
|
35
|
+
performance(operation: string, duration: number, context?: LogContext): void;
|
|
36
|
+
errorWithStack(message: string, error: Error, context?: LogContext): void;
|
|
37
|
+
group(label: string, fn: () => void): void;
|
|
38
|
+
}
|
|
39
|
+
export declare const logger: Logger;
|
|
40
|
+
export declare const logAuth: (message: string, context?: LogContext, ...args: any[]) => void;
|
|
41
|
+
export declare const logApi: (message: string, context?: LogContext, ...args: any[]) => void;
|
|
42
|
+
export declare const logSession: (message: string, context?: LogContext, ...args: any[]) => void;
|
|
43
|
+
export declare const logUser: (message: string, context?: LogContext, ...args: any[]) => void;
|
|
44
|
+
export declare const logDevice: (message: string, context?: LogContext, ...args: any[]) => void;
|
|
45
|
+
export declare const logPayment: (message: string, context?: LogContext, ...args: any[]) => void;
|
|
46
|
+
export declare const logError: (message: string, error?: any, context?: LogContext, ...args: any[]) => void;
|
|
47
|
+
export declare const logPerformance: (operation: string, duration: number, context?: LogContext) => void;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=loggerUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loggerUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/loggerUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;CACT;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,cAAM,MAAM;IACV,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,aAAa,CAAmD;IAExE,QAA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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for common data validation patterns
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Email validation regex
|
|
6
|
+
*/
|
|
7
|
+
export declare const EMAIL_REGEX: RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* Username validation regex (alphanumeric, underscore, dash, 3-30 chars)
|
|
10
|
+
*/
|
|
11
|
+
export declare const USERNAME_REGEX: RegExp;
|
|
12
|
+
/**
|
|
13
|
+
* Password validation regex (at least 8 chars, 1 uppercase, 1 lowercase, 1 number)
|
|
14
|
+
*/
|
|
15
|
+
export declare const PASSWORD_REGEX: RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* Validate email format
|
|
18
|
+
*/
|
|
19
|
+
export declare function isValidEmail(email: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Validate username format
|
|
22
|
+
*/
|
|
23
|
+
export declare function isValidUsername(username: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Validate password strength
|
|
26
|
+
*/
|
|
27
|
+
export declare function isValidPassword(password: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Validate required string
|
|
30
|
+
*/
|
|
31
|
+
export declare function isRequiredString(value: any): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Validate required number
|
|
34
|
+
*/
|
|
35
|
+
export declare function isRequiredNumber(value: any): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Validate required boolean
|
|
38
|
+
*/
|
|
39
|
+
export declare function isRequiredBoolean(value: any): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Validate array
|
|
42
|
+
*/
|
|
43
|
+
export declare function isValidArray(value: any): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Validate object
|
|
46
|
+
*/
|
|
47
|
+
export declare function isValidObject(value: any): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Validate UUID format
|
|
50
|
+
*/
|
|
51
|
+
export declare function isValidUUID(uuid: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Validate URL format
|
|
54
|
+
*/
|
|
55
|
+
export declare function isValidURL(url: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Validate date string
|
|
58
|
+
*/
|
|
59
|
+
export declare function isValidDate(dateString: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Validate file size (in bytes)
|
|
62
|
+
*/
|
|
63
|
+
export declare function isValidFileSize(size: number, maxSize: number): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Validate file type
|
|
66
|
+
*/
|
|
67
|
+
export declare function isValidFileType(filename: string, allowedTypes: string[]): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Sanitize string input
|
|
70
|
+
*/
|
|
71
|
+
export declare function sanitizeString(input: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Sanitize HTML input
|
|
74
|
+
*/
|
|
75
|
+
export declare function sanitizeHTML(input: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Validate and sanitize user input
|
|
78
|
+
*/
|
|
79
|
+
export declare function validateAndSanitizeUserInput(input: any, type: 'string' | 'email' | 'username'): string | null;
|
|
80
|
+
//# sourceMappingURL=validationUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/validationUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,QAA+B,CAAC;AAExD;;GAEG;AACH,eAAO,MAAM,cAAc,QAA0B,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,cAAc,QAA0D,CAAC;AAEtF;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,gBA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to handle authentication, user management, karma system, device-based session management and more 🚀",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -33,10 +33,6 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"src",
|
|
35
35
|
"lib",
|
|
36
|
-
"mock.js",
|
|
37
|
-
"UI_COMPONENTS.md",
|
|
38
|
-
"CHANGELOG.md",
|
|
39
|
-
"MIGRATION_GUIDE.md",
|
|
40
36
|
"assets"
|
|
41
37
|
],
|
|
42
38
|
"keywords": [
|
|
@@ -63,9 +59,7 @@
|
|
|
63
59
|
"copy-dts": "copyfiles -u 1 \"src/**/*.d.ts\" lib/typescript",
|
|
64
60
|
"delete-debug-view": "rm -rf ./lib/commonjs/components/bottomSheetDebugView ./lib/module/components/bottomSheetDebugView ./lib/typescript/components/bottomSheetDebugView || true",
|
|
65
61
|
"delete-dts.js": "find ./lib/commonjs -name '*.d.js*' -delete && find ./lib/module -name '*.d.js*' -delete",
|
|
66
|
-
"release": "rm -rf lib && npm run build && release-it"
|
|
67
|
-
"example": "npm --cwd example",
|
|
68
|
-
"bootstrap": "npm install && npm run example"
|
|
62
|
+
"release": "rm -rf lib && npm run build && release-it"
|
|
69
63
|
},
|
|
70
64
|
"dependencies": {
|
|
71
65
|
"@react-native-async-storage/async-storage": "^2.1.2",
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { jwtDecode } from 'jwt-decode';
|
|
3
|
+
import { OxyConfig, ApiError } from '../models/interfaces';
|
|
4
|
+
import { handleHttpError } from '../utils/errorUtils';
|
|
5
|
+
|
|
6
|
+
interface JwtPayload {
|
|
7
|
+
exp: number;
|
|
8
|
+
userId: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* OxyServices - Base client library for interacting with the Oxy API
|
|
14
|
+
*
|
|
15
|
+
* This class provides the core HTTP client setup, token management, and error handling.
|
|
16
|
+
* Specific functionality is delegated to focused service modules.
|
|
17
|
+
*/
|
|
18
|
+
export class OxyServices {
|
|
19
|
+
protected client: AxiosInstance;
|
|
20
|
+
private accessToken: string | null = null;
|
|
21
|
+
private refreshToken: string | null = null;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new instance of the OxyServices client
|
|
25
|
+
* @param config - Configuration for the client
|
|
26
|
+
*/
|
|
27
|
+
constructor(config: OxyConfig) {
|
|
28
|
+
this.client = axios.create({
|
|
29
|
+
baseURL: config.baseURL,
|
|
30
|
+
timeout: 10000 // 10 second timeout
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.setupInterceptors();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Setup axios interceptors for authentication and error handling
|
|
38
|
+
*/
|
|
39
|
+
private setupInterceptors(): void {
|
|
40
|
+
// Request interceptor for adding auth header and handling token refresh
|
|
41
|
+
this.client.interceptors.request.use(async (req: InternalAxiosRequestConfig) => {
|
|
42
|
+
if (!this.accessToken) {
|
|
43
|
+
return req;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Check if token is expired and refresh if needed
|
|
47
|
+
try {
|
|
48
|
+
const decoded = jwtDecode<JwtPayload>(this.accessToken);
|
|
49
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
50
|
+
|
|
51
|
+
// If token expires in less than 60 seconds, refresh it
|
|
52
|
+
if (decoded.exp - currentTime < 60) {
|
|
53
|
+
// For session-based tokens, get a new token from the session
|
|
54
|
+
if (decoded.sessionId) {
|
|
55
|
+
try {
|
|
56
|
+
const res = await this.client.get(`/session/token/${decoded.sessionId}`);
|
|
57
|
+
this.accessToken = res.data.accessToken;
|
|
58
|
+
} catch (refreshError) {
|
|
59
|
+
// If refresh fails, clear tokens
|
|
60
|
+
this.clearTokens();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Add authorization header
|
|
66
|
+
req.headers.Authorization = `Bearer ${this.accessToken}`;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
// If token is invalid, clear it
|
|
69
|
+
this.clearTokens();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return req;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the configured base URL
|
|
78
|
+
*/
|
|
79
|
+
public getBaseURL(): string {
|
|
80
|
+
return this.client.defaults.baseURL || '';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Set authentication tokens
|
|
85
|
+
*/
|
|
86
|
+
public setTokens(accessToken: string, refreshToken: string = ''): void {
|
|
87
|
+
this.accessToken = accessToken;
|
|
88
|
+
this.refreshToken = refreshToken;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Clear stored authentication tokens
|
|
93
|
+
*/
|
|
94
|
+
public clearTokens(): void {
|
|
95
|
+
this.accessToken = null;
|
|
96
|
+
this.refreshToken = null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the current user ID from the access token
|
|
101
|
+
*/
|
|
102
|
+
public getCurrentUserId(): string | null {
|
|
103
|
+
if (!this.accessToken) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const decoded = jwtDecode<JwtPayload>(this.accessToken);
|
|
109
|
+
return decoded.userId || decoded.id || null;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Check if the client has a valid access token
|
|
117
|
+
*/
|
|
118
|
+
private hasAccessToken(): boolean {
|
|
119
|
+
return !!this.accessToken;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Validate the current access token with the server
|
|
124
|
+
*/
|
|
125
|
+
async validate(): Promise<boolean> {
|
|
126
|
+
if (!this.hasAccessToken()) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const res = await this.client.get('/auth/validate');
|
|
132
|
+
return res.data.valid === true;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get the HTTP client instance (protected for use by service modules)
|
|
140
|
+
*/
|
|
141
|
+
protected getClient(): AxiosInstance {
|
|
142
|
+
return this.client;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Centralized error handling
|
|
147
|
+
*/
|
|
148
|
+
protected handleError(error: any): ApiError {
|
|
149
|
+
return handleHttpError(error);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Health check endpoint
|
|
154
|
+
*/
|
|
155
|
+
async healthCheck(): Promise<{
|
|
156
|
+
status: string;
|
|
157
|
+
users?: number;
|
|
158
|
+
timestamp?: string;
|
|
159
|
+
[key: string]: any
|
|
160
|
+
}> {
|
|
161
|
+
try {
|
|
162
|
+
const res = await this.client.get('/health');
|
|
163
|
+
return res.data;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
throw this.handleError(error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { OxyConfig } from '../models/interfaces';
|
|
2
|
+
import { AuthService } from './auth/AuthService';
|
|
3
|
+
import { UserService } from './users/UserService';
|
|
4
|
+
import { PaymentService } from './payments/PaymentService';
|
|
5
|
+
import { KarmaService } from './karma/KarmaService';
|
|
6
|
+
import { FileService, OXY_CLOUD_URL } from './files/FileService';
|
|
7
|
+
import { LocationService } from './locations/LocationService';
|
|
8
|
+
import { AnalyticsService } from './analytics/AnalyticsService';
|
|
9
|
+
import { DeviceService } from './devices/DeviceService';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Main OxyServices class that combines all individual services
|
|
13
|
+
*
|
|
14
|
+
* This class provides a unified interface to all Oxy API services while maintaining
|
|
15
|
+
* backward compatibility with the original monolithic structure.
|
|
16
|
+
*/
|
|
17
|
+
export class OxyServicesMain extends AuthService {
|
|
18
|
+
// Service instances
|
|
19
|
+
public readonly users: UserService;
|
|
20
|
+
public readonly payments: PaymentService;
|
|
21
|
+
public readonly karma: KarmaService;
|
|
22
|
+
public readonly files: FileService;
|
|
23
|
+
public readonly locations: LocationService;
|
|
24
|
+
public readonly analytics: AnalyticsService;
|
|
25
|
+
public readonly devices: DeviceService;
|
|
26
|
+
|
|
27
|
+
constructor(config: OxyConfig) {
|
|
28
|
+
super(config);
|
|
29
|
+
|
|
30
|
+
// Initialize all service instances
|
|
31
|
+
this.users = new UserService(config);
|
|
32
|
+
this.payments = new PaymentService(config);
|
|
33
|
+
this.karma = new KarmaService(config);
|
|
34
|
+
this.files = new FileService(config);
|
|
35
|
+
this.locations = new LocationService(config);
|
|
36
|
+
this.analytics = new AnalyticsService(config);
|
|
37
|
+
this.devices = new DeviceService(config);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Re-export OXY_CLOUD_URL for convenience
|
|
41
|
+
static readonly OXY_CLOUD_URL = OXY_CLOUD_URL;
|
|
42
|
+
|
|
43
|
+
// Additional utility methods that span multiple services
|
|
44
|
+
async fetchLinkMetadata(url: string): Promise<{
|
|
45
|
+
url: string;
|
|
46
|
+
title: string;
|
|
47
|
+
description: string;
|
|
48
|
+
image?: string;
|
|
49
|
+
}> {
|
|
50
|
+
try {
|
|
51
|
+
const res = await this.getClient().get(`/link-metadata?url=${encodeURIComponent(url)}`);
|
|
52
|
+
return res.data;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw this.handleError(error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OxyServices } from '../OxyServices';
|
|
2
|
+
import { AnalyticsData, FollowerDetails, ContentViewer } from '../../models/interfaces';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Analytics service for handling analytics and content viewer operations
|
|
6
|
+
*/
|
|
7
|
+
export class AnalyticsService extends OxyServices {
|
|
8
|
+
/**
|
|
9
|
+
* Get analytics data for user
|
|
10
|
+
*/
|
|
11
|
+
async getAnalytics(userId: string, period?: string): Promise<AnalyticsData> {
|
|
12
|
+
try {
|
|
13
|
+
const params = new URLSearchParams();
|
|
14
|
+
if (period) params.append('period', period);
|
|
15
|
+
|
|
16
|
+
const res = await this.getClient().get(`/analytics/users/${userId}?${params.toString()}`);
|
|
17
|
+
return res.data;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw this.handleError(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Update analytics data
|
|
25
|
+
*/
|
|
26
|
+
async updateAnalytics(userId: string, type: string, data: Record<string, any>): Promise<{ message: string }> {
|
|
27
|
+
try {
|
|
28
|
+
const res = await this.getClient().put(`/analytics/users/${userId}/${type}`, data);
|
|
29
|
+
return res.data;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw this.handleError(error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get content viewers for user
|
|
37
|
+
*/
|
|
38
|
+
async getContentViewers(userId: string, period?: string): Promise<ContentViewer[]> {
|
|
39
|
+
try {
|
|
40
|
+
const params = new URLSearchParams();
|
|
41
|
+
if (period) params.append('period', period);
|
|
42
|
+
|
|
43
|
+
const res = await this.getClient().get(`/analytics/users/${userId}/viewers?${params.toString()}`);
|
|
44
|
+
return res.data;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw this.handleError(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get follower details for user
|
|
52
|
+
*/
|
|
53
|
+
async getFollowerDetails(userId: string, period?: string): Promise<FollowerDetails> {
|
|
54
|
+
try {
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
if (period) params.append('period', period);
|
|
57
|
+
|
|
58
|
+
const res = await this.getClient().get(`/analytics/users/${userId}/followers?${params.toString()}`);
|
|
59
|
+
return res.data;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw this.handleError(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|