@oxyhq/services 5.9.2 → 5.9.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.
Files changed (202) hide show
  1. package/README.md +1 -33
  2. package/lib/commonjs/core/OxyServices.js +322 -0
  3. package/lib/commonjs/core/OxyServices.js.map +1 -0
  4. package/lib/commonjs/core/OxyServicesMain.js +51 -0
  5. package/lib/commonjs/core/OxyServicesMain.js.map +1 -0
  6. package/lib/commonjs/core/analytics/AnalyticsService.js +67 -0
  7. package/lib/commonjs/core/analytics/AnalyticsService.js.map +1 -0
  8. package/lib/commonjs/core/auth/AuthService.js +526 -0
  9. package/lib/commonjs/core/auth/AuthService.js.map +1 -0
  10. package/lib/commonjs/core/devices/DeviceService.js +61 -0
  11. package/lib/commonjs/core/devices/DeviceService.js.map +1 -0
  12. package/lib/commonjs/core/files/FileService.js +176 -0
  13. package/lib/commonjs/core/files/FileService.js.map +1 -0
  14. package/lib/commonjs/core/index.js +103 -1701
  15. package/lib/commonjs/core/index.js.map +1 -1
  16. package/lib/commonjs/core/karma/KarmaService.js +100 -0
  17. package/lib/commonjs/core/karma/KarmaService.js.map +1 -0
  18. package/lib/commonjs/core/locations/LocationService.js +131 -0
  19. package/lib/commonjs/core/locations/LocationService.js.map +1 -0
  20. package/lib/commonjs/core/payments/PaymentService.js +124 -0
  21. package/lib/commonjs/core/payments/PaymentService.js.map +1 -0
  22. package/lib/commonjs/core/users/UserService.js +234 -0
  23. package/lib/commonjs/core/users/UserService.js.map +1 -0
  24. package/lib/commonjs/index.js +164 -3
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/commonjs/models/session.js +2 -0
  27. package/lib/commonjs/{types/middleware.js.map → models/session.js.map} +1 -1
  28. package/lib/commonjs/ui/context/OxyContext.js +28 -24
  29. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  30. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +2 -2
  31. package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
  32. package/lib/commonjs/ui/screens/FileManagementScreen.js +12 -12
  33. package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
  34. package/lib/commonjs/ui/screens/ProfileScreen.js +2 -2
  35. package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
  36. package/lib/commonjs/ui/screens/SessionManagementScreen.js.map +1 -1
  37. package/lib/commonjs/ui/screens/SignInScreen.js +1 -1
  38. package/lib/commonjs/ui/screens/SignInScreen.js.map +1 -1
  39. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js +1 -1
  40. package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
  41. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
  42. package/lib/commonjs/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
  43. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js +1 -1
  44. package/lib/commonjs/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
  45. package/lib/commonjs/ui/stores/followStore.js +4 -4
  46. package/lib/commonjs/ui/stores/followStore.js.map +1 -1
  47. package/lib/commonjs/utils/apiUtils.js +93 -0
  48. package/lib/commonjs/utils/apiUtils.js.map +1 -0
  49. package/lib/commonjs/utils/asyncUtils.js +219 -0
  50. package/lib/commonjs/utils/asyncUtils.js.map +1 -0
  51. package/lib/commonjs/utils/errorUtils.js +148 -0
  52. package/lib/commonjs/utils/errorUtils.js.map +1 -0
  53. package/lib/commonjs/utils/hookUtils.js +399 -0
  54. package/lib/commonjs/utils/hookUtils.js.map +1 -0
  55. package/lib/commonjs/utils/loggerUtils.js +160 -0
  56. package/lib/commonjs/utils/loggerUtils.js.map +1 -0
  57. package/lib/commonjs/utils/validationUtils.js +174 -0
  58. package/lib/commonjs/utils/validationUtils.js.map +1 -0
  59. package/lib/module/core/OxyServices.js +316 -0
  60. package/lib/module/core/OxyServices.js.map +1 -0
  61. package/lib/module/core/OxyServicesMain.js +47 -0
  62. package/lib/module/core/OxyServicesMain.js.map +1 -0
  63. package/lib/module/core/analytics/AnalyticsService.js +62 -0
  64. package/lib/module/core/analytics/AnalyticsService.js.map +1 -0
  65. package/lib/module/core/auth/AuthService.js +521 -0
  66. package/lib/module/core/auth/AuthService.js.map +1 -0
  67. package/lib/module/core/devices/DeviceService.js +57 -0
  68. package/lib/module/core/devices/DeviceService.js.map +1 -0
  69. package/lib/module/core/files/FileService.js +171 -0
  70. package/lib/module/core/files/FileService.js.map +1 -0
  71. package/lib/module/core/index.js +25 -1690
  72. package/lib/module/core/index.js.map +1 -1
  73. package/lib/module/core/karma/KarmaService.js +95 -0
  74. package/lib/module/core/karma/KarmaService.js.map +1 -0
  75. package/lib/module/core/locations/LocationService.js +127 -0
  76. package/lib/module/core/locations/LocationService.js.map +1 -0
  77. package/lib/module/core/payments/PaymentService.js +119 -0
  78. package/lib/module/core/payments/PaymentService.js.map +1 -0
  79. package/lib/module/core/users/UserService.js +230 -0
  80. package/lib/module/core/users/UserService.js.map +1 -0
  81. package/lib/module/index.js +8 -4
  82. package/lib/module/index.js.map +1 -1
  83. package/lib/module/models/session.js +2 -0
  84. package/lib/module/{types/middleware.js.map → models/session.js.map} +1 -1
  85. package/lib/module/ui/context/OxyContext.js +28 -24
  86. package/lib/module/ui/context/OxyContext.js.map +1 -1
  87. package/lib/module/ui/screens/AccountSwitcherScreen.js +2 -2
  88. package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
  89. package/lib/module/ui/screens/FileManagementScreen.js +12 -12
  90. package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
  91. package/lib/module/ui/screens/ProfileScreen.js +2 -2
  92. package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
  93. package/lib/module/ui/screens/SessionManagementScreen.js.map +1 -1
  94. package/lib/module/ui/screens/SignInScreen.js +1 -1
  95. package/lib/module/ui/screens/SignInScreen.js.map +1 -1
  96. package/lib/module/ui/screens/karma/KarmaCenterScreen.js +1 -1
  97. package/lib/module/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
  98. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js +1 -1
  99. package/lib/module/ui/screens/karma/KarmaLeaderboardScreen.js.map +1 -1
  100. package/lib/module/ui/screens/karma/KarmaRulesScreen.js +1 -1
  101. package/lib/module/ui/screens/karma/KarmaRulesScreen.js.map +1 -1
  102. package/lib/module/ui/stores/followStore.js +4 -4
  103. package/lib/module/ui/stores/followStore.js.map +1 -1
  104. package/lib/module/utils/apiUtils.js +85 -0
  105. package/lib/module/utils/apiUtils.js.map +1 -0
  106. package/lib/module/utils/asyncUtils.js +202 -0
  107. package/lib/module/utils/asyncUtils.js.map +1 -0
  108. package/lib/module/utils/errorUtils.js +139 -0
  109. package/lib/module/utils/errorUtils.js.map +1 -0
  110. package/lib/module/utils/hookUtils.js +381 -0
  111. package/lib/module/utils/hookUtils.js.map +1 -0
  112. package/lib/module/utils/loggerUtils.js +149 -0
  113. package/lib/module/utils/loggerUtils.js.map +1 -0
  114. package/lib/module/utils/validationUtils.js +154 -0
  115. package/lib/module/utils/validationUtils.js.map +1 -0
  116. package/lib/typescript/core/OxyServices.d.ts +99 -0
  117. package/lib/typescript/core/OxyServices.d.ts.map +1 -0
  118. package/lib/typescript/core/OxyServicesMain.d.ts +33 -0
  119. package/lib/typescript/core/OxyServicesMain.d.ts.map +1 -0
  120. package/lib/typescript/core/analytics/AnalyticsService.d.ts +26 -0
  121. package/lib/typescript/core/analytics/AnalyticsService.d.ts.map +1 -0
  122. package/lib/typescript/core/auth/AuthService.d.ts +165 -0
  123. package/lib/typescript/core/auth/AuthService.d.ts.map +1 -0
  124. package/lib/typescript/core/devices/DeviceService.d.ts +20 -0
  125. package/lib/typescript/core/devices/DeviceService.d.ts.map +1 -0
  126. package/lib/typescript/core/files/FileService.d.ts +59 -0
  127. package/lib/typescript/core/files/FileService.d.ts.map +1 -0
  128. package/lib/typescript/core/index.d.ts +19 -656
  129. package/lib/typescript/core/index.d.ts.map +1 -1
  130. package/lib/typescript/core/karma/KarmaService.d.ts +50 -0
  131. package/lib/typescript/core/karma/KarmaService.d.ts.map +1 -0
  132. package/lib/typescript/core/locations/LocationService.d.ts +39 -0
  133. package/lib/typescript/core/locations/LocationService.d.ts.map +1 -0
  134. package/lib/typescript/core/payments/PaymentService.d.ts +50 -0
  135. package/lib/typescript/core/payments/PaymentService.d.ts.map +1 -0
  136. package/lib/typescript/core/users/UserService.d.ts +111 -0
  137. package/lib/typescript/core/users/UserService.d.ts.map +1 -0
  138. package/lib/typescript/index.d.ts +7 -3
  139. package/lib/typescript/index.d.ts.map +1 -1
  140. package/lib/typescript/models/{secureSession.d.ts → session.d.ts} +4 -4
  141. package/lib/typescript/models/session.d.ts.map +1 -0
  142. package/lib/typescript/ui/context/OxyContext.d.ts +2 -2
  143. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  144. package/lib/typescript/utils/apiUtils.d.ts +61 -0
  145. package/lib/typescript/utils/apiUtils.d.ts.map +1 -0
  146. package/lib/typescript/utils/asyncUtils.d.ts +64 -0
  147. package/lib/typescript/utils/asyncUtils.d.ts.map +1 -0
  148. package/lib/typescript/utils/errorUtils.d.ts +45 -0
  149. package/lib/typescript/utils/errorUtils.d.ts.map +1 -0
  150. package/lib/typescript/utils/hookUtils.d.ts +102 -0
  151. package/lib/typescript/utils/hookUtils.d.ts.map +1 -0
  152. package/lib/typescript/utils/loggerUtils.d.ts +49 -0
  153. package/lib/typescript/utils/loggerUtils.d.ts.map +1 -0
  154. package/lib/typescript/utils/validationUtils.d.ts +80 -0
  155. package/lib/typescript/utils/validationUtils.d.ts.map +1 -0
  156. package/package.json +2 -8
  157. package/src/core/OxyServices.ts +351 -0
  158. package/src/core/OxyServicesMain.ts +57 -0
  159. package/src/core/analytics/AnalyticsService.ts +64 -0
  160. package/src/core/auth/AuthService.ts +544 -0
  161. package/src/core/devices/DeviceService.ts +55 -0
  162. package/src/core/files/FileService.ts +194 -0
  163. package/src/core/index.ts +27 -1765
  164. package/src/core/karma/KarmaService.ts +104 -0
  165. package/src/core/locations/LocationService.ts +141 -0
  166. package/src/core/payments/PaymentService.ts +133 -0
  167. package/src/core/users/UserService.ts +241 -0
  168. package/src/index.ts +29 -8
  169. package/src/models/{secureSession.ts → session.ts} +5 -5
  170. package/src/ui/context/OxyContext.tsx +34 -30
  171. package/src/ui/screens/AccountSwitcherScreen.tsx +4 -4
  172. package/src/ui/screens/FileManagementScreen.tsx +12 -12
  173. package/src/ui/screens/ProfileScreen.tsx +3 -3
  174. package/src/ui/screens/SessionManagementScreen.tsx +2 -2
  175. package/src/ui/screens/SignInScreen.tsx +1 -1
  176. package/src/ui/screens/karma/KarmaCenterScreen.tsx +2 -2
  177. package/src/ui/screens/karma/KarmaLeaderboardScreen.tsx +3 -3
  178. package/src/ui/screens/karma/KarmaRulesScreen.tsx +3 -3
  179. package/src/ui/stores/followStore.ts +4 -4
  180. package/src/utils/apiUtils.ts +102 -0
  181. package/src/utils/asyncUtils.ts +265 -0
  182. package/src/utils/errorUtils.ts +172 -0
  183. package/src/utils/hookUtils.ts +397 -0
  184. package/src/utils/loggerUtils.ts +153 -0
  185. package/src/utils/validationUtils.ts +158 -0
  186. package/lib/commonjs/middleware.js +0 -17
  187. package/lib/commonjs/middleware.js.map +0 -1
  188. package/lib/commonjs/models/secureSession.js +0 -2
  189. package/lib/commonjs/models/secureSession.js.map +0 -1
  190. package/lib/commonjs/types/middleware.js +0 -6
  191. package/lib/module/middleware.js +0 -12
  192. package/lib/module/middleware.js.map +0 -1
  193. package/lib/module/models/secureSession.js +0 -2
  194. package/lib/module/models/secureSession.js.map +0 -1
  195. package/lib/module/types/middleware.js +0 -4
  196. package/lib/typescript/middleware.d.ts +0 -9
  197. package/lib/typescript/middleware.d.ts.map +0 -1
  198. package/lib/typescript/models/secureSession.d.ts.map +0 -1
  199. package/lib/typescript/types/middleware.d.ts +0 -19
  200. package/lib/typescript/types/middleware.d.ts.map +0 -1
  201. package/src/middleware.ts +0 -11
  202. 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;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,C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,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,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,aAAa;IAMrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IASlE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAOjE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAOjE,KAAK,CAAC,OAAO,EAAE,MAAM,EAA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AEzC,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,EAAE,UAAU,UAAU,EAAE,GAAG,MAAM,GAAG,EAAE,SACrC,CAAC;AAExC,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,UAAU,UAAU,EAAE,GAAG,MAAM,GAAG,EAAE,SACrC,CAAC;AAE5C,eAAO,MAAM,OAAO,GAAI,SAAS,MAAM,EAAE,UAAU,UAAU,EAAE,GAAG,MAAM,GAAG,EAAE,SACrC,CAAC;AAEzC,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,EAAE,UAAU,UAAU,EAAE,GAAG,MAAM,GAAG,EAAE,SACrC,CAAC;AAE3C,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,UAAU,UAAU,EAAE,GAAG,MAAM,GAAG,EAAE,SACrC,CAAC;AAE5C,eAAO,MAAM,QAAQ,GAAI,SAAS,MAAM,EAAE,QAAQ,GAAG,EAAE,UAAU,UAAU,EAAE,GAAG,MAAM,GAAG,EAAE,SAC3C,CAAC;AAEjD,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,EAAE,UAAU,MAAM,EAAE,UAAU,UAAU,SACtC,CAAC"}
@@ -0,0 +1,80 @@
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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
1
1
  {
2
2
  "name": "@oxyhq/services",
3
- "version": "5.9.2",
3
+ "version": "5.9.4",
4
4
  "description": "Reusable OxyHQ module 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,351 @@
1
+ import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
2
+ import { jwtDecode } from 'jwt-decode';
3
+ import { OxyConfig, ApiError, User } 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
+
169
+ /**
170
+ * Simple Express.js authentication middleware
171
+ *
172
+ * Built-in authentication middleware that validates JWT tokens and adds user data to requests.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * // Basic usage - just add it to your routes
177
+ * app.use('/api/protected', oxyServices.auth());
178
+ *
179
+ * // With debug logging
180
+ * app.use('/api/protected', oxyServices.auth({ debug: true }));
181
+ *
182
+ * // With custom error handling
183
+ * app.use('/api/protected', oxyServices.auth({
184
+ * onError: (error) => console.error('Auth failed:', error)
185
+ * }));
186
+ *
187
+ * // Load full user data
188
+ * app.use('/api/protected', oxyServices.auth({ loadUser: true }));
189
+ * ```
190
+ *
191
+ * @param options Optional configuration
192
+ * @param options.debug Enable debug logging (default: false)
193
+ * @param options.onError Custom error handler
194
+ * @param options.loadUser Load full user data (default: false for performance)
195
+ * @param options.session Use session-based validation (default: false)
196
+ * @returns Express middleware function
197
+ */
198
+ auth(options: {
199
+ debug?: boolean;
200
+ onError?: (error: ApiError) => any;
201
+ loadUser?: boolean;
202
+ session?: boolean;
203
+ } = {}) {
204
+ const { debug = false, onError, loadUser = false, session = false } = options;
205
+
206
+ return async (req: any, res: any, next: any) => {
207
+ try {
208
+ // Extract token from Authorization header
209
+ const authHeader = req.headers['authorization'];
210
+ const token = authHeader?.startsWith('Bearer ') ? authHeader.substring(7) : null;
211
+
212
+ if (debug) {
213
+ console.log(`🔐 Auth: Processing ${req.method} ${req.path}`);
214
+ console.log(`🔐 Auth: Token present: ${!!token}`);
215
+ }
216
+
217
+ if (!token) {
218
+ const error = {
219
+ message: 'Access token required',
220
+ code: 'MISSING_TOKEN',
221
+ status: 401
222
+ };
223
+
224
+ if (debug) console.log(`❌ Auth: Missing token`);
225
+
226
+ if (onError) return onError(error);
227
+ return res.status(401).json(error);
228
+ }
229
+
230
+ // Decode and validate token
231
+ let decoded: JwtPayload;
232
+ try {
233
+ decoded = jwtDecode<JwtPayload>(token);
234
+
235
+ if (debug) {
236
+ console.log(`🔐 Auth: Token decoded, User ID: ${decoded.userId || decoded.id}`);
237
+ }
238
+ } catch (decodeError) {
239
+ const error = {
240
+ message: 'Invalid token format',
241
+ code: 'INVALID_TOKEN_FORMAT',
242
+ status: 403
243
+ };
244
+
245
+ if (debug) console.log(`❌ Auth: Token decode failed`);
246
+
247
+ if (onError) return onError(error);
248
+ return res.status(403).json(error);
249
+ }
250
+
251
+ const userId = decoded.userId || decoded.id;
252
+ if (!userId) {
253
+ const error = {
254
+ message: 'Token missing user ID',
255
+ code: 'INVALID_TOKEN_PAYLOAD',
256
+ status: 403
257
+ };
258
+
259
+ if (debug) console.log(`❌ Auth: Token missing user ID`);
260
+
261
+ if (onError) return onError(error);
262
+ return res.status(403).json(error);
263
+ }
264
+
265
+ // Check token expiration
266
+ if (decoded.exp && decoded.exp < Math.floor(Date.now() / 1000)) {
267
+ const error = {
268
+ message: 'Token expired',
269
+ code: 'TOKEN_EXPIRED',
270
+ status: 403
271
+ };
272
+
273
+ if (debug) console.log(`❌ Auth: Token expired`);
274
+
275
+ if (onError) return onError(error);
276
+ return res.status(403).json(error);
277
+ }
278
+
279
+ // Session-based validation if requested
280
+ if (session && decoded.sessionId) {
281
+ try {
282
+ if (debug) console.log(`🔐 Auth: Validating session ${decoded.sessionId}`);
283
+
284
+ const sessionRes = await this.client.get(`/session/validate/${decoded.sessionId}`);
285
+ const sessionData = sessionRes.data;
286
+
287
+ if (!sessionData.valid) {
288
+ const error = {
289
+ message: 'Invalid session',
290
+ code: 'INVALID_SESSION',
291
+ status: 403
292
+ };
293
+
294
+ if (debug) console.log(`❌ Auth: Session validation failed`);
295
+
296
+ if (onError) return onError(error);
297
+ return res.status(403).json(error);
298
+ }
299
+
300
+ if (debug) console.log(`✅ Auth: Session validation successful`);
301
+ } catch (sessionError) {
302
+ const error = {
303
+ message: 'Session validation failed',
304
+ code: 'SESSION_VALIDATION_ERROR',
305
+ status: 403
306
+ };
307
+
308
+ if (debug) console.log(`❌ Auth: Session validation error`);
309
+
310
+ if (onError) return onError(error);
311
+ return res.status(403).json(error);
312
+ }
313
+ }
314
+
315
+ // Set request properties
316
+ req.userId = userId;
317
+ req.accessToken = token;
318
+
319
+ // Load user data if requested
320
+ if (loadUser) {
321
+ try {
322
+ const userRes = await this.client.get(`/users/${userId}`);
323
+ req.user = userRes.data;
324
+ } catch (userError) {
325
+ // If user loading fails, just use minimal user data
326
+ req.user = { id: userId } as User;
327
+ if (debug) console.log(`⚠️ Auth: Failed to load user data, using minimal data`);
328
+ }
329
+ } else {
330
+ // Use minimal user data for performance
331
+ req.user = { id: userId } as User;
332
+ }
333
+
334
+ if (debug) {
335
+ console.log(`✅ Auth: Authentication successful for user ${userId}`);
336
+ }
337
+
338
+ next();
339
+ } catch (error) {
340
+ const apiError = this.handleError(error);
341
+
342
+ if (debug) {
343
+ console.log(`❌ Auth: Unexpected error:`, apiError);
344
+ }
345
+
346
+ if (onError) return onError(apiError);
347
+ return res.status(apiError.status || 500).json(apiError);
348
+ }
349
+ };
350
+ }
351
+ }
@@ -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
+ }