@oxyhq/services 5.13.12 → 5.13.16

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 (209) hide show
  1. package/README.md +10 -0
  2. package/lib/commonjs/core/OxyServices.base.js +271 -0
  3. package/lib/commonjs/core/OxyServices.base.js.map +1 -0
  4. package/lib/commonjs/core/OxyServices.errors.js +26 -0
  5. package/lib/commonjs/core/OxyServices.errors.js.map +1 -0
  6. package/lib/commonjs/core/OxyServices.js +58 -2009
  7. package/lib/commonjs/core/OxyServices.js.map +1 -1
  8. package/lib/commonjs/core/mixins/OxyServices.analytics.js +60 -0
  9. package/lib/commonjs/core/mixins/OxyServices.analytics.js.map +1 -0
  10. package/lib/commonjs/core/mixins/OxyServices.assets.js +406 -0
  11. package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -0
  12. package/lib/commonjs/core/mixins/OxyServices.auth.js +303 -0
  13. package/lib/commonjs/core/mixins/OxyServices.auth.js.map +1 -0
  14. package/lib/commonjs/core/mixins/OxyServices.developer.js +115 -0
  15. package/lib/commonjs/core/mixins/OxyServices.developer.js.map +1 -0
  16. package/lib/commonjs/core/mixins/OxyServices.devices.js +119 -0
  17. package/lib/commonjs/core/mixins/OxyServices.devices.js.map +1 -0
  18. package/lib/commonjs/core/mixins/OxyServices.karma.js +117 -0
  19. package/lib/commonjs/core/mixins/OxyServices.karma.js.map +1 -0
  20. package/lib/commonjs/core/mixins/OxyServices.language.js +124 -0
  21. package/lib/commonjs/core/mixins/OxyServices.language.js.map +1 -0
  22. package/lib/commonjs/core/mixins/OxyServices.location.js +55 -0
  23. package/lib/commonjs/core/mixins/OxyServices.location.js.map +1 -0
  24. package/lib/commonjs/core/mixins/OxyServices.payment.js +66 -0
  25. package/lib/commonjs/core/mixins/OxyServices.payment.js.map +1 -0
  26. package/lib/commonjs/core/mixins/OxyServices.privacy.js +174 -0
  27. package/lib/commonjs/core/mixins/OxyServices.privacy.js.map +1 -0
  28. package/lib/commonjs/core/mixins/OxyServices.totp.js +53 -0
  29. package/lib/commonjs/core/mixins/OxyServices.totp.js.map +1 -0
  30. package/lib/commonjs/core/mixins/OxyServices.user.js +389 -0
  31. package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -0
  32. package/lib/commonjs/core/mixins/OxyServices.utility.js +161 -0
  33. package/lib/commonjs/core/mixins/OxyServices.utility.js.map +1 -0
  34. package/lib/commonjs/core/mixins/index.js +39 -0
  35. package/lib/commonjs/core/mixins/index.js.map +1 -0
  36. package/lib/commonjs/core/mixins/mixinHelpers.js +62 -0
  37. package/lib/commonjs/core/mixins/mixinHelpers.js.map +1 -0
  38. package/lib/commonjs/index.js.map +1 -1
  39. package/lib/commonjs/ui/context/OxyContext.js +26 -47
  40. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  41. package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +239 -1
  42. package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
  43. package/lib/commonjs/utils/apiUtils.js +0 -14
  44. package/lib/commonjs/utils/apiUtils.js.map +1 -1
  45. package/lib/commonjs/utils/asyncUtils.js +0 -20
  46. package/lib/commonjs/utils/asyncUtils.js.map +1 -1
  47. package/lib/module/core/OxyServices.base.js +265 -0
  48. package/lib/module/core/OxyServices.base.js.map +1 -0
  49. package/lib/module/core/OxyServices.errors.js +20 -0
  50. package/lib/module/core/OxyServices.errors.js.map +1 -0
  51. package/lib/module/core/OxyServices.js +43 -2005
  52. package/lib/module/core/OxyServices.js.map +1 -1
  53. package/lib/module/core/mixins/OxyServices.analytics.js +56 -0
  54. package/lib/module/core/mixins/OxyServices.analytics.js.map +1 -0
  55. package/lib/module/core/mixins/OxyServices.assets.js +402 -0
  56. package/lib/module/core/mixins/OxyServices.assets.js.map +1 -0
  57. package/lib/module/core/mixins/OxyServices.auth.js +299 -0
  58. package/lib/module/core/mixins/OxyServices.auth.js.map +1 -0
  59. package/lib/module/core/mixins/OxyServices.developer.js +111 -0
  60. package/lib/module/core/mixins/OxyServices.developer.js.map +1 -0
  61. package/lib/module/core/mixins/OxyServices.devices.js +115 -0
  62. package/lib/module/core/mixins/OxyServices.devices.js.map +1 -0
  63. package/lib/module/core/mixins/OxyServices.karma.js +113 -0
  64. package/lib/module/core/mixins/OxyServices.karma.js.map +1 -0
  65. package/lib/module/core/mixins/OxyServices.language.js +120 -0
  66. package/lib/module/core/mixins/OxyServices.language.js.map +1 -0
  67. package/lib/module/core/mixins/OxyServices.location.js +51 -0
  68. package/lib/module/core/mixins/OxyServices.location.js.map +1 -0
  69. package/lib/module/core/mixins/OxyServices.payment.js +62 -0
  70. package/lib/module/core/mixins/OxyServices.payment.js.map +1 -0
  71. package/lib/module/core/mixins/OxyServices.privacy.js +170 -0
  72. package/lib/module/core/mixins/OxyServices.privacy.js.map +1 -0
  73. package/lib/module/core/mixins/OxyServices.totp.js +49 -0
  74. package/lib/module/core/mixins/OxyServices.totp.js.map +1 -0
  75. package/lib/module/core/mixins/OxyServices.user.js +385 -0
  76. package/lib/module/core/mixins/OxyServices.user.js.map +1 -0
  77. package/lib/module/core/mixins/OxyServices.utility.js +156 -0
  78. package/lib/module/core/mixins/OxyServices.utility.js.map +1 -0
  79. package/lib/module/core/mixins/index.js +36 -0
  80. package/lib/module/core/mixins/index.js.map +1 -0
  81. package/lib/module/core/mixins/mixinHelpers.js +56 -0
  82. package/lib/module/core/mixins/mixinHelpers.js.map +1 -0
  83. package/lib/module/index.js.map +1 -1
  84. package/lib/module/ui/context/OxyContext.js +26 -47
  85. package/lib/module/ui/context/OxyContext.js.map +1 -1
  86. package/lib/module/ui/navigation/types.js.map +1 -1
  87. package/lib/module/ui/screens/PrivacySettingsScreen.js +241 -3
  88. package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
  89. package/lib/module/utils/apiUtils.js +0 -13
  90. package/lib/module/utils/apiUtils.js.map +1 -1
  91. package/lib/module/utils/asyncUtils.js +0 -20
  92. package/lib/module/utils/asyncUtils.js.map +1 -1
  93. package/lib/typescript/core/OxyServices.base.d.ts +123 -0
  94. package/lib/typescript/core/OxyServices.base.d.ts.map +1 -0
  95. package/lib/typescript/core/OxyServices.d.ts +969 -682
  96. package/lib/typescript/core/OxyServices.d.ts.map +1 -1
  97. package/lib/typescript/core/OxyServices.errors.d.ts +12 -0
  98. package/lib/typescript/core/OxyServices.errors.d.ts.map +1 -0
  99. package/lib/typescript/core/mixins/OxyServices.analytics.d.ts +70 -0
  100. package/lib/typescript/core/mixins/OxyServices.analytics.d.ts.map +1 -0
  101. package/lib/typescript/core/mixins/OxyServices.assets.d.ts +159 -0
  102. package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -0
  103. package/lib/typescript/core/mixins/OxyServices.auth.d.ts +168 -0
  104. package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -0
  105. package/lib/typescript/core/mixins/OxyServices.developer.d.ts +103 -0
  106. package/lib/typescript/core/mixins/OxyServices.developer.d.ts.map +1 -0
  107. package/lib/typescript/core/mixins/OxyServices.devices.d.ts +93 -0
  108. package/lib/typescript/core/mixins/OxyServices.devices.d.ts.map +1 -0
  109. package/lib/typescript/core/mixins/OxyServices.karma.d.ts +89 -0
  110. package/lib/typescript/core/mixins/OxyServices.karma.d.ts.map +1 -0
  111. package/lib/typescript/core/mixins/OxyServices.language.d.ts +85 -0
  112. package/lib/typescript/core/mixins/OxyServices.language.d.ts.map +1 -0
  113. package/lib/typescript/core/mixins/OxyServices.location.d.ts +68 -0
  114. package/lib/typescript/core/mixins/OxyServices.location.d.ts.map +1 -0
  115. package/lib/typescript/core/mixins/OxyServices.payment.d.ts +74 -0
  116. package/lib/typescript/core/mixins/OxyServices.payment.d.ts.map +1 -0
  117. package/lib/typescript/core/mixins/OxyServices.privacy.d.ts +126 -0
  118. package/lib/typescript/core/mixins/OxyServices.privacy.d.ts.map +1 -0
  119. package/lib/typescript/core/mixins/OxyServices.totp.d.ts +69 -0
  120. package/lib/typescript/core/mixins/OxyServices.totp.d.ts.map +1 -0
  121. package/lib/typescript/core/mixins/OxyServices.user.d.ts +189 -0
  122. package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -0
  123. package/lib/typescript/core/mixins/OxyServices.utility.d.ts +97 -0
  124. package/lib/typescript/core/mixins/OxyServices.utility.d.ts.map +1 -0
  125. package/lib/typescript/core/mixins/index.d.ts +898 -0
  126. package/lib/typescript/core/mixins/index.d.ts.map +1 -0
  127. package/lib/typescript/core/mixins/mixinHelpers.d.ts +32 -0
  128. package/lib/typescript/core/mixins/mixinHelpers.d.ts.map +1 -0
  129. package/lib/typescript/index.d.ts +1 -1
  130. package/lib/typescript/index.d.ts.map +1 -1
  131. package/lib/typescript/models/interfaces.d.ts +36 -0
  132. package/lib/typescript/models/interfaces.d.ts.map +1 -1
  133. package/lib/typescript/ui/context/OxyContext.d.ts +2 -6
  134. package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
  135. package/lib/typescript/ui/navigation/types.d.ts +0 -1
  136. package/lib/typescript/ui/navigation/types.d.ts.map +1 -1
  137. package/lib/typescript/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
  138. package/lib/typescript/utils/apiUtils.d.ts +0 -7
  139. package/lib/typescript/utils/apiUtils.d.ts.map +1 -1
  140. package/lib/typescript/utils/asyncUtils.d.ts +0 -11
  141. package/lib/typescript/utils/asyncUtils.d.ts.map +1 -1
  142. package/package.json +1 -1
  143. package/src/core/OxyServices.base.ts +311 -0
  144. package/src/core/OxyServices.errors.ts +26 -0
  145. package/src/core/OxyServices.ts +43 -2026
  146. package/src/core/mixins/OxyServices.analytics.ts +53 -0
  147. package/src/core/mixins/OxyServices.assets.ts +390 -0
  148. package/src/core/mixins/OxyServices.auth.ts +275 -0
  149. package/src/core/mixins/OxyServices.developer.ts +114 -0
  150. package/src/core/mixins/OxyServices.devices.ts +103 -0
  151. package/src/core/mixins/OxyServices.karma.ts +111 -0
  152. package/src/core/mixins/OxyServices.language.ts +127 -0
  153. package/src/core/mixins/OxyServices.location.ts +46 -0
  154. package/src/core/mixins/OxyServices.payment.ts +59 -0
  155. package/src/core/mixins/OxyServices.privacy.ts +182 -0
  156. package/src/core/mixins/OxyServices.totp.ts +36 -0
  157. package/src/core/mixins/OxyServices.user.ts +380 -0
  158. package/src/core/mixins/OxyServices.utility.ts +187 -0
  159. package/src/core/mixins/index.ts +58 -0
  160. package/src/core/mixins/mixinHelpers.ts +69 -0
  161. package/src/index.ts +4 -0
  162. package/src/models/interfaces.ts +40 -0
  163. package/src/ui/context/OxyContext.tsx +35 -53
  164. package/src/ui/navigation/types.ts +0 -1
  165. package/src/ui/screens/PrivacySettingsScreen.tsx +240 -2
  166. package/src/utils/apiUtils.ts +0 -14
  167. package/src/utils/asyncUtils.ts +0 -20
  168. package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js +0 -192
  169. package/lib/commonjs/ui/screens/internal/SignInPasswordStep.js.map +0 -1
  170. package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js +0 -142
  171. package/lib/commonjs/ui/screens/internal/SignInUsernameStep.js.map +0 -1
  172. package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js +0 -113
  173. package/lib/commonjs/ui/screens/internal/SignUpIdentityStep.js.map +0 -1
  174. package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js +0 -132
  175. package/lib/commonjs/ui/screens/internal/SignUpSecurityStep.js.map +0 -1
  176. package/lib/commonjs/ui/screens/internal/SignUpSummaryStep.js +0 -83
  177. package/lib/commonjs/ui/screens/internal/SignUpSummaryStep.js.map +0 -1
  178. package/lib/commonjs/ui/screens/internal/SignUpWelcomeStep.js +0 -58
  179. package/lib/commonjs/ui/screens/internal/SignUpWelcomeStep.js.map +0 -1
  180. package/lib/module/ui/screens/internal/SignInPasswordStep.js +0 -186
  181. package/lib/module/ui/screens/internal/SignInPasswordStep.js.map +0 -1
  182. package/lib/module/ui/screens/internal/SignInUsernameStep.js +0 -136
  183. package/lib/module/ui/screens/internal/SignInUsernameStep.js.map +0 -1
  184. package/lib/module/ui/screens/internal/SignUpIdentityStep.js +0 -108
  185. package/lib/module/ui/screens/internal/SignUpIdentityStep.js.map +0 -1
  186. package/lib/module/ui/screens/internal/SignUpSecurityStep.js +0 -127
  187. package/lib/module/ui/screens/internal/SignUpSecurityStep.js.map +0 -1
  188. package/lib/module/ui/screens/internal/SignUpSummaryStep.js +0 -78
  189. package/lib/module/ui/screens/internal/SignUpSummaryStep.js.map +0 -1
  190. package/lib/module/ui/screens/internal/SignUpWelcomeStep.js +0 -53
  191. package/lib/module/ui/screens/internal/SignUpWelcomeStep.js.map +0 -1
  192. package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts +0 -28
  193. package/lib/typescript/ui/screens/internal/SignInPasswordStep.d.ts.map +0 -1
  194. package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts +0 -25
  195. package/lib/typescript/ui/screens/internal/SignInUsernameStep.d.ts.map +0 -1
  196. package/lib/typescript/ui/screens/internal/SignUpIdentityStep.d.ts +0 -20
  197. package/lib/typescript/ui/screens/internal/SignUpIdentityStep.d.ts.map +0 -1
  198. package/lib/typescript/ui/screens/internal/SignUpSecurityStep.d.ts +0 -24
  199. package/lib/typescript/ui/screens/internal/SignUpSecurityStep.d.ts.map +0 -1
  200. package/lib/typescript/ui/screens/internal/SignUpSummaryStep.d.ts +0 -15
  201. package/lib/typescript/ui/screens/internal/SignUpSummaryStep.d.ts.map +0 -1
  202. package/lib/typescript/ui/screens/internal/SignUpWelcomeStep.d.ts +0 -13
  203. package/lib/typescript/ui/screens/internal/SignUpWelcomeStep.d.ts.map +0 -1
  204. package/src/ui/screens/internal/SignInPasswordStep.tsx +0 -184
  205. package/src/ui/screens/internal/SignInUsernameStep.tsx +0 -145
  206. package/src/ui/screens/internal/SignUpIdentityStep.tsx +0 -112
  207. package/src/ui/screens/internal/SignUpSecurityStep.tsx +0 -132
  208. package/src/ui/screens/internal/SignUpSummaryStep.tsx +0 -66
  209. package/src/ui/screens/internal/SignUpWelcomeStep.tsx +0 -52
package/README.md CHANGED
@@ -719,6 +719,16 @@ npm install axios jwt-decode invariant
719
719
 
720
720
  **Note**: `react-native-url-polyfill` is already included as a dependency in this package.
721
721
 
722
+ ## 📚 Documentation
723
+
724
+ Comprehensive documentation is available in the `/docs` directory:
725
+
726
+ - **[Getting Started](./docs/GETTING_STARTED.md)** - Quick start guide for new developers
727
+ - **[API Reference](./docs/API_REFERENCE.md)** - Complete API method documentation
728
+ - **[Integration Guide](./docs/INTEGRATION_GUIDE.md)** - Platform-specific integration guides
729
+ - **[Examples](./docs/EXAMPLES.md)** - Complete working code examples
730
+ - **[Best Practices](./docs/BEST_PRACTICES.md)** - Production-ready patterns and tips
731
+
722
732
  ## 📚 Examples
723
733
 
724
734
  ### Complete React Native App
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OxyServicesBase = void 0;
7
+ var _jwtDecode = require("jwt-decode");
8
+ var _errorUtils = require("../utils/errorUtils");
9
+ var _HttpClient = require("./HttpClient");
10
+ var _RequestManager = require("./RequestManager");
11
+ var _OxyServices = require("./OxyServices.errors");
12
+ /**
13
+ * OxyServices Base Class
14
+ *
15
+ * Contains core infrastructure, HTTP client, request management, and error handling
16
+ */
17
+
18
+ /**
19
+ * Base class for OxyServices with core infrastructure
20
+ */
21
+ class OxyServicesBase {
22
+ constructor(...args) {
23
+ const config = args[0];
24
+ if (!config || typeof config !== 'object') {
25
+ throw new Error('OxyConfig is required');
26
+ }
27
+ this.config = config;
28
+ this.cloudURL = config.cloudURL || 'https://cloud.oxy.so';
29
+
30
+ // Initialize HTTP client (handles authentication and interceptors)
31
+ this.httpClient = new _HttpClient.HttpClient(config);
32
+
33
+ // Initialize request manager (handles caching, deduplication, queuing, retry)
34
+ this.requestManager = new _RequestManager.RequestManager(this.httpClient, config);
35
+ }
36
+
37
+ // Test-only utility to reset global tokens between jest tests
38
+ static __resetTokensForTests() {
39
+ _HttpClient.HttpClient.__resetTokensForTests();
40
+ }
41
+
42
+ /**
43
+ * Make a request with all performance optimizations
44
+ * This is the main method for all API calls - ensures authentication and performance features
45
+ */
46
+ async makeRequest(method, url, data, options = {}) {
47
+ return this.requestManager.request(method, url, data, options);
48
+ }
49
+
50
+ // ============================================================================
51
+ // CORE METHODS (HTTP Client, Token Management, Error Handling)
52
+ // ============================================================================
53
+
54
+ /**
55
+ * Get the configured Oxy API base URL
56
+ */
57
+ getBaseURL() {
58
+ return this.httpClient.getBaseURL();
59
+ }
60
+
61
+ /**
62
+ * Get the HTTP client instance
63
+ * Useful for advanced use cases where direct access to the HTTP client is needed
64
+ */
65
+ getClient() {
66
+ return this.httpClient;
67
+ }
68
+
69
+ /**
70
+ * Get performance metrics
71
+ */
72
+ getMetrics() {
73
+ return this.requestManager.getMetrics();
74
+ }
75
+
76
+ /**
77
+ * Clear request cache
78
+ */
79
+ clearCache() {
80
+ this.requestManager.clearCache();
81
+ }
82
+
83
+ /**
84
+ * Clear specific cache entry
85
+ */
86
+ clearCacheEntry(key) {
87
+ this.requestManager.clearCacheEntry(key);
88
+ }
89
+
90
+ /**
91
+ * Get cache statistics
92
+ */
93
+ getCacheStats() {
94
+ return this.requestManager.getCacheStats();
95
+ }
96
+
97
+ /**
98
+ * Get the configured Oxy Cloud (file storage/CDN) URL
99
+ */
100
+ getCloudURL() {
101
+ return this.cloudURL;
102
+ }
103
+
104
+ /**
105
+ * Set authentication tokens
106
+ */
107
+ setTokens(accessToken, refreshToken = '') {
108
+ this.httpClient.setTokens(accessToken, refreshToken);
109
+ }
110
+
111
+ /**
112
+ * Clear stored authentication tokens
113
+ */
114
+ clearTokens() {
115
+ this.httpClient.clearTokens();
116
+ }
117
+
118
+ /**
119
+ * Get the current user ID from the access token
120
+ */
121
+ getCurrentUserId() {
122
+ const accessToken = this.httpClient.getAccessToken();
123
+ if (!accessToken) {
124
+ return null;
125
+ }
126
+ try {
127
+ const decoded = (0, _jwtDecode.jwtDecode)(accessToken);
128
+ return decoded.userId || decoded.id || null;
129
+ } catch (error) {
130
+ return null;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Check if the client has a valid access token (public method)
136
+ */
137
+ hasValidToken() {
138
+ return this.httpClient.hasAccessToken();
139
+ }
140
+
141
+ /**
142
+ * Get the raw access token (for constructing anchor URLs when needed)
143
+ */
144
+ getAccessToken() {
145
+ return this.httpClient.getAccessToken();
146
+ }
147
+
148
+ /**
149
+ * Wait for authentication to be ready (public method)
150
+ * Useful for apps that want to ensure authentication is complete before proceeding
151
+ */
152
+ async waitForAuth(timeoutMs = 5000) {
153
+ return this.waitForAuthentication(timeoutMs);
154
+ }
155
+
156
+ /**
157
+ * Wait for authentication to be ready with timeout
158
+ */
159
+ async waitForAuthentication(timeoutMs = 5000) {
160
+ const startTime = Date.now();
161
+ const checkInterval = 100; // Check every 100ms
162
+
163
+ while (Date.now() - startTime < timeoutMs) {
164
+ if (this.httpClient.hasAccessToken()) {
165
+ return true;
166
+ }
167
+ await new Promise(resolve => setTimeout(resolve, checkInterval));
168
+ }
169
+ return false;
170
+ }
171
+
172
+ /**
173
+ * Check if the client has a valid access token
174
+ */
175
+ hasAccessToken() {
176
+ return this.httpClient.hasAccessToken();
177
+ }
178
+
179
+ /**
180
+ * Execute a function with automatic authentication retry logic
181
+ * This handles the common case where API calls are made before authentication completes
182
+ */
183
+ async withAuthRetry(operation, operationName, options = {}) {
184
+ const {
185
+ maxRetries = 2,
186
+ retryDelay = 1000,
187
+ authTimeoutMs = 5000
188
+ } = options;
189
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
190
+ try {
191
+ // First attempt: check if we have a token
192
+ if (!this.httpClient.hasAccessToken()) {
193
+ if (attempt === 0) {
194
+ // On first attempt, wait briefly for authentication to complete
195
+ const authReady = await this.waitForAuthentication(authTimeoutMs);
196
+ if (!authReady) {
197
+ throw new _OxyServices.OxyAuthenticationTimeoutError(operationName, authTimeoutMs);
198
+ }
199
+ } else {
200
+ // On retry attempts, fail immediately if no token
201
+ throw new _OxyServices.OxyAuthenticationError(`Authentication required: ${operationName} requires a valid access token.`, 'AUTH_REQUIRED');
202
+ }
203
+ }
204
+
205
+ // Execute the operation
206
+ return await operation();
207
+ } catch (error) {
208
+ const isLastAttempt = attempt === maxRetries;
209
+ const isAuthError = error?.response?.status === 401 || error?.code === 'MISSING_TOKEN' || error?.message?.includes('Authentication') || error instanceof _OxyServices.OxyAuthenticationError;
210
+ if (isAuthError && !isLastAttempt && !(error instanceof _OxyServices.OxyAuthenticationTimeoutError)) {
211
+ await new Promise(resolve => setTimeout(resolve, retryDelay));
212
+ continue;
213
+ }
214
+
215
+ // If it's not an auth error, or it's the last attempt, throw the error
216
+ if (error instanceof _OxyServices.OxyAuthenticationError) {
217
+ throw error;
218
+ }
219
+ throw this.handleError(error);
220
+ }
221
+ }
222
+
223
+ // This should never be reached, but TypeScript requires it
224
+ throw new _OxyServices.OxyAuthenticationError(`${operationName} failed after ${maxRetries + 1} attempts`);
225
+ }
226
+
227
+ /**
228
+ * Validate the current access token with the server
229
+ */
230
+ async validate() {
231
+ if (!this.hasAccessToken()) {
232
+ return false;
233
+ }
234
+ try {
235
+ const res = await this.makeRequest('GET', '/api/auth/validate', undefined, {
236
+ cache: false,
237
+ retry: false
238
+ });
239
+ return res.valid === true;
240
+ } catch (error) {
241
+ return false;
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Centralized error handling
247
+ */
248
+ handleError(error) {
249
+ const api = (0, _errorUtils.handleHttpError)(error);
250
+ const err = new Error(api.message);
251
+ err.code = api.code;
252
+ err.status = api.status;
253
+ err.details = api.details;
254
+ return err;
255
+ }
256
+
257
+ /**
258
+ * Health check endpoint
259
+ */
260
+ async healthCheck() {
261
+ try {
262
+ return await this.makeRequest('GET', '/health', undefined, {
263
+ cache: false
264
+ });
265
+ } catch (error) {
266
+ throw this.handleError(error);
267
+ }
268
+ }
269
+ }
270
+ exports.OxyServicesBase = OxyServicesBase;
271
+ //# sourceMappingURL=OxyServices.base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_jwtDecode","require","_errorUtils","_HttpClient","_RequestManager","_OxyServices","OxyServicesBase","constructor","args","config","Error","cloudURL","httpClient","HttpClient","requestManager","RequestManager","__resetTokensForTests","makeRequest","method","url","data","options","request","getBaseURL","getClient","getMetrics","clearCache","clearCacheEntry","key","getCacheStats","getCloudURL","setTokens","accessToken","refreshToken","clearTokens","getCurrentUserId","getAccessToken","decoded","jwtDecode","userId","id","error","hasValidToken","hasAccessToken","waitForAuth","timeoutMs","waitForAuthentication","startTime","Date","now","checkInterval","Promise","resolve","setTimeout","withAuthRetry","operation","operationName","maxRetries","retryDelay","authTimeoutMs","attempt","authReady","OxyAuthenticationTimeoutError","OxyAuthenticationError","isLastAttempt","isAuthError","response","status","code","message","includes","handleError","validate","res","undefined","cache","retry","valid","api","handleHttpError","err","details","healthCheck","exports"],"sourceRoot":"../../../src","sources":["core/OxyServices.base.ts"],"mappings":";;;;;;AAKA,IAAAA,UAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAVA;AACA;AACA;AACA;AACA;;AAoBA;AACA;AACA;AACO,MAAMK,eAAe,CAAC;EAM3BC,WAAWA,CAAC,GAAGC,IAAW,EAAE;IAC1B,MAAMC,MAAM,GAAGD,IAAI,CAAC,CAAC,CAAc;IACnC,IAAI,CAACC,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;MACzC,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;IAC1C;IACA,IAAI,CAACD,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACE,QAAQ,GAAGF,MAAM,CAACE,QAAQ,IAAI,sBAAsB;;IAEzD;IACA,IAAI,CAACC,UAAU,GAAG,IAAIC,sBAAU,CAACJ,MAAM,CAAC;;IAExC;IACA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EAKd;IACD,IAAI;MACF,OAAO,MAAM,IAAI,CAACjE,WAAW,CAAC,KAAK,EAAE,SAAS,EAAEyD,SAAS,EAAE;QAAEC,KAAK,EAAE;MAAM,CAAC,CAAC;IAC9E,CAAC,CAAC,OAAOlC,KAAK,EAAE;MACd,MAAM,IAAI,CAAC8B,WAAW,CAAC9B,KAAK,CAAC;IAC/B;EACF;AACF;AAAC0C,OAAA,CAAA7E,eAAA,GAAAA,eAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OxyAuthenticationTimeoutError = exports.OxyAuthenticationError = void 0;
7
+ /**
8
+ * Custom error types for better error handling
9
+ */
10
+ class OxyAuthenticationError extends Error {
11
+ constructor(message, code = 'AUTH_ERROR', status = 401) {
12
+ super(message);
13
+ this.name = 'OxyAuthenticationError';
14
+ this.code = code;
15
+ this.status = status;
16
+ }
17
+ }
18
+ exports.OxyAuthenticationError = OxyAuthenticationError;
19
+ class OxyAuthenticationTimeoutError extends OxyAuthenticationError {
20
+ constructor(operationName, timeoutMs) {
21
+ super(`Authentication timeout (${timeoutMs}ms): ${operationName} requires user authentication. Please ensure the user is logged in before calling this method.`, 'AUTH_TIMEOUT', 408);
22
+ this.name = 'OxyAuthenticationTimeoutError';
23
+ }
24
+ }
25
+ exports.OxyAuthenticationTimeoutError = OxyAuthenticationTimeoutError;
26
+ //# sourceMappingURL=OxyServices.errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OxyAuthenticationError","Error","constructor","message","code","status","name","exports","OxyAuthenticationTimeoutError","operationName","timeoutMs"],"sourceRoot":"../../../src","sources":["core/OxyServices.errors.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACO,MAAMA,sBAAsB,SAASC,KAAK,CAAC;EAIhDC,WAAWA,CAACC,OAAe,EAAEC,IAAI,GAAG,YAAY,EAAEC,MAAM,GAAG,GAAG,EAAE;IAC9D,KAAK,CAACF,OAAO,CAAC;IACd,IAAI,CAACG,IAAI,GAAG,wBAAwB;IACpC,IAAI,CAACF,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,MAAM,GAAGA,MAAM;EACtB;AACF;AAACE,OAAA,CAAAP,sBAAA,GAAAA,sBAAA;AAEM,MAAMQ,6BAA6B,SAASR,sBAAsB,CAAC;EACxEE,WAAWA,CAACO,aAAqB,EAAEC,SAAiB,EAAE;IACpD,KAAK,CACH,2BAA2BA,SAAS,QAAQD,aAAa,gGAAgG,EACzJ,cAAc,EACd,GACF,CAAC;IACD,IAAI,CAACH,IAAI,GAAG,+BAA+B;EAC7C;AACF;AAACC,OAAA,CAAAC,6BAAA,GAAAA,6BAAA","ignoreList":[]}