@oxyhq/services 5.13.15 → 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.
- package/README.md +10 -0
- package/lib/commonjs/core/OxyServices.base.js +271 -0
- package/lib/commonjs/core/OxyServices.base.js.map +1 -0
- package/lib/commonjs/core/OxyServices.errors.js +26 -0
- package/lib/commonjs/core/OxyServices.errors.js.map +1 -0
- package/lib/commonjs/core/OxyServices.js +58 -2168
- package/lib/commonjs/core/OxyServices.js.map +1 -1
- package/lib/commonjs/core/mixins/OxyServices.analytics.js +60 -0
- package/lib/commonjs/core/mixins/OxyServices.analytics.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.assets.js +406 -0
- package/lib/commonjs/core/mixins/OxyServices.assets.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.auth.js +303 -0
- package/lib/commonjs/core/mixins/OxyServices.auth.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.developer.js +115 -0
- package/lib/commonjs/core/mixins/OxyServices.developer.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.devices.js +119 -0
- package/lib/commonjs/core/mixins/OxyServices.devices.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.karma.js +117 -0
- package/lib/commonjs/core/mixins/OxyServices.karma.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.language.js +124 -0
- package/lib/commonjs/core/mixins/OxyServices.language.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.location.js +55 -0
- package/lib/commonjs/core/mixins/OxyServices.location.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.payment.js +66 -0
- package/lib/commonjs/core/mixins/OxyServices.payment.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.privacy.js +174 -0
- package/lib/commonjs/core/mixins/OxyServices.privacy.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.totp.js +53 -0
- package/lib/commonjs/core/mixins/OxyServices.totp.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.user.js +389 -0
- package/lib/commonjs/core/mixins/OxyServices.user.js.map +1 -0
- package/lib/commonjs/core/mixins/OxyServices.utility.js +161 -0
- package/lib/commonjs/core/mixins/OxyServices.utility.js.map +1 -0
- package/lib/commonjs/core/mixins/index.js +39 -0
- package/lib/commonjs/core/mixins/index.js.map +1 -0
- package/lib/commonjs/core/mixins/mixinHelpers.js +62 -0
- package/lib/commonjs/core/mixins/mixinHelpers.js.map +1 -0
- package/lib/commonjs/ui/context/OxyContext.js +27 -2
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/module/core/OxyServices.base.js +265 -0
- package/lib/module/core/OxyServices.base.js.map +1 -0
- package/lib/module/core/OxyServices.errors.js +20 -0
- package/lib/module/core/OxyServices.errors.js.map +1 -0
- package/lib/module/core/OxyServices.js +43 -2164
- package/lib/module/core/OxyServices.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.analytics.js +56 -0
- package/lib/module/core/mixins/OxyServices.analytics.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.assets.js +402 -0
- package/lib/module/core/mixins/OxyServices.assets.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.auth.js +299 -0
- package/lib/module/core/mixins/OxyServices.auth.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.developer.js +111 -0
- package/lib/module/core/mixins/OxyServices.developer.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.devices.js +115 -0
- package/lib/module/core/mixins/OxyServices.devices.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.karma.js +113 -0
- package/lib/module/core/mixins/OxyServices.karma.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.language.js +120 -0
- package/lib/module/core/mixins/OxyServices.language.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.location.js +51 -0
- package/lib/module/core/mixins/OxyServices.location.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.payment.js +62 -0
- package/lib/module/core/mixins/OxyServices.payment.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.privacy.js +170 -0
- package/lib/module/core/mixins/OxyServices.privacy.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.totp.js +49 -0
- package/lib/module/core/mixins/OxyServices.totp.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.user.js +385 -0
- package/lib/module/core/mixins/OxyServices.user.js.map +1 -0
- package/lib/module/core/mixins/OxyServices.utility.js +156 -0
- package/lib/module/core/mixins/OxyServices.utility.js.map +1 -0
- package/lib/module/core/mixins/index.js +36 -0
- package/lib/module/core/mixins/index.js.map +1 -0
- package/lib/module/core/mixins/mixinHelpers.js +56 -0
- package/lib/module/core/mixins/mixinHelpers.js.map +1 -0
- package/lib/module/ui/context/OxyContext.js +27 -2
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/typescript/core/OxyServices.base.d.ts +123 -0
- package/lib/typescript/core/OxyServices.base.d.ts.map +1 -0
- package/lib/typescript/core/OxyServices.d.ts +969 -746
- package/lib/typescript/core/OxyServices.d.ts.map +1 -1
- package/lib/typescript/core/OxyServices.errors.d.ts +12 -0
- package/lib/typescript/core/OxyServices.errors.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.analytics.d.ts +70 -0
- package/lib/typescript/core/mixins/OxyServices.analytics.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.assets.d.ts +159 -0
- package/lib/typescript/core/mixins/OxyServices.assets.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts +168 -0
- package/lib/typescript/core/mixins/OxyServices.auth.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.developer.d.ts +103 -0
- package/lib/typescript/core/mixins/OxyServices.developer.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.devices.d.ts +93 -0
- package/lib/typescript/core/mixins/OxyServices.devices.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.karma.d.ts +89 -0
- package/lib/typescript/core/mixins/OxyServices.karma.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.language.d.ts +85 -0
- package/lib/typescript/core/mixins/OxyServices.language.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.location.d.ts +68 -0
- package/lib/typescript/core/mixins/OxyServices.location.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.payment.d.ts +74 -0
- package/lib/typescript/core/mixins/OxyServices.payment.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.privacy.d.ts +126 -0
- package/lib/typescript/core/mixins/OxyServices.privacy.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.totp.d.ts +69 -0
- package/lib/typescript/core/mixins/OxyServices.totp.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.user.d.ts +189 -0
- package/lib/typescript/core/mixins/OxyServices.user.d.ts.map +1 -0
- package/lib/typescript/core/mixins/OxyServices.utility.d.ts +97 -0
- package/lib/typescript/core/mixins/OxyServices.utility.d.ts.map +1 -0
- package/lib/typescript/core/mixins/index.d.ts +898 -0
- package/lib/typescript/core/mixins/index.d.ts.map +1 -0
- package/lib/typescript/core/mixins/mixinHelpers.d.ts +32 -0
- package/lib/typescript/core/mixins/mixinHelpers.d.ts.map +1 -0
- package/lib/typescript/models/interfaces.d.ts +10 -0
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts +2 -0
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/OxyServices.base.ts +311 -0
- package/src/core/OxyServices.errors.ts +26 -0
- package/src/core/OxyServices.ts +43 -2199
- package/src/core/mixins/OxyServices.analytics.ts +53 -0
- package/src/core/mixins/OxyServices.assets.ts +390 -0
- package/src/core/mixins/OxyServices.auth.ts +275 -0
- package/src/core/mixins/OxyServices.developer.ts +114 -0
- package/src/core/mixins/OxyServices.devices.ts +103 -0
- package/src/core/mixins/OxyServices.karma.ts +111 -0
- package/src/core/mixins/OxyServices.language.ts +127 -0
- package/src/core/mixins/OxyServices.location.ts +46 -0
- package/src/core/mixins/OxyServices.payment.ts +59 -0
- package/src/core/mixins/OxyServices.privacy.ts +182 -0
- package/src/core/mixins/OxyServices.totp.ts +36 -0
- package/src/core/mixins/OxyServices.user.ts +380 -0
- package/src/core/mixins/OxyServices.utility.ts +187 -0
- package/src/core/mixins/index.ts +58 -0
- package/src/core/mixins/mixinHelpers.ts +69 -0
- package/src/models/interfaces.ts +12 -0
- package/src/ui/context/OxyContext.tsx +36 -0
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,IAAI,CAACK,cAAc,GAAG,IAAIC,8BAAc,CAAC,IAAI,CAAC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AC,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":[]}
|