@oxyhq/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/dist/cjs/AuthManager.js +361 -0
- package/dist/cjs/CrossDomainAuth.js +258 -0
- package/dist/cjs/HttpService.js +618 -0
- package/dist/cjs/OxyServices.base.js +263 -0
- package/dist/cjs/OxyServices.errors.js +22 -0
- package/dist/cjs/OxyServices.js +63 -0
- package/dist/cjs/constants/version.js +16 -0
- package/dist/cjs/crypto/index.js +20 -0
- package/dist/cjs/crypto/keyManager.js +887 -0
- package/dist/cjs/crypto/polyfill.js +64 -0
- package/dist/cjs/crypto/recoveryPhrase.js +169 -0
- package/dist/cjs/crypto/signatureService.js +296 -0
- package/dist/cjs/i18n/index.js +73 -0
- package/dist/cjs/i18n/locales/ar-SA.json +120 -0
- package/dist/cjs/i18n/locales/ca-ES.json +120 -0
- package/dist/cjs/i18n/locales/de-DE.json +120 -0
- package/dist/cjs/i18n/locales/en-US.json +956 -0
- package/dist/cjs/i18n/locales/es-ES.json +944 -0
- package/dist/cjs/i18n/locales/fr-FR.json +120 -0
- package/dist/cjs/i18n/locales/it-IT.json +120 -0
- package/dist/cjs/i18n/locales/ja-JP.json +119 -0
- package/dist/cjs/i18n/locales/ko-KR.json +120 -0
- package/dist/cjs/i18n/locales/locales/ar-SA.json +120 -0
- package/dist/cjs/i18n/locales/locales/ca-ES.json +120 -0
- package/dist/cjs/i18n/locales/locales/de-DE.json +120 -0
- package/dist/cjs/i18n/locales/locales/en-US.json +956 -0
- package/dist/cjs/i18n/locales/locales/es-ES.json +944 -0
- package/dist/cjs/i18n/locales/locales/fr-FR.json +120 -0
- package/dist/cjs/i18n/locales/locales/it-IT.json +120 -0
- package/dist/cjs/i18n/locales/locales/ja-JP.json +119 -0
- package/dist/cjs/i18n/locales/locales/ko-KR.json +120 -0
- package/dist/cjs/i18n/locales/locales/pt-PT.json +120 -0
- package/dist/cjs/i18n/locales/locales/zh-CN.json +120 -0
- package/dist/cjs/i18n/locales/pt-PT.json +120 -0
- package/dist/cjs/i18n/locales/zh-CN.json +120 -0
- package/dist/cjs/index.js +153 -0
- package/dist/cjs/mixins/OxyServices.analytics.js +49 -0
- package/dist/cjs/mixins/OxyServices.assets.js +380 -0
- package/dist/cjs/mixins/OxyServices.auth.js +259 -0
- package/dist/cjs/mixins/OxyServices.developer.js +97 -0
- package/dist/cjs/mixins/OxyServices.devices.js +116 -0
- package/dist/cjs/mixins/OxyServices.features.js +309 -0
- package/dist/cjs/mixins/OxyServices.fedcm.js +435 -0
- package/dist/cjs/mixins/OxyServices.karma.js +108 -0
- package/dist/cjs/mixins/OxyServices.language.js +154 -0
- package/dist/cjs/mixins/OxyServices.location.js +43 -0
- package/dist/cjs/mixins/OxyServices.payment.js +158 -0
- package/dist/cjs/mixins/OxyServices.popup.js +371 -0
- package/dist/cjs/mixins/OxyServices.privacy.js +162 -0
- package/dist/cjs/mixins/OxyServices.redirect.js +345 -0
- package/dist/cjs/mixins/OxyServices.security.js +81 -0
- package/dist/cjs/mixins/OxyServices.user.js +355 -0
- package/dist/cjs/mixins/OxyServices.utility.js +156 -0
- package/dist/cjs/mixins/index.js +79 -0
- package/dist/cjs/mixins/mixinHelpers.js +53 -0
- package/dist/cjs/models/interfaces.js +20 -0
- package/dist/cjs/models/session.js +2 -0
- package/dist/cjs/shared/index.js +70 -0
- package/dist/cjs/shared/utils/colorUtils.js +153 -0
- package/dist/cjs/shared/utils/debugUtils.js +73 -0
- package/dist/cjs/shared/utils/errorUtils.js +183 -0
- package/dist/cjs/shared/utils/index.js +49 -0
- package/dist/cjs/shared/utils/networkUtils.js +183 -0
- package/dist/cjs/shared/utils/themeUtils.js +106 -0
- package/dist/cjs/utils/apiUtils.js +61 -0
- package/dist/cjs/utils/asyncUtils.js +194 -0
- package/dist/cjs/utils/cache.js +226 -0
- package/dist/cjs/utils/deviceManager.js +205 -0
- package/dist/cjs/utils/errorUtils.js +154 -0
- package/dist/cjs/utils/index.js +26 -0
- package/dist/cjs/utils/languageUtils.js +165 -0
- package/dist/cjs/utils/loggerUtils.js +126 -0
- package/dist/cjs/utils/platform.js +144 -0
- package/dist/cjs/utils/requestUtils.js +209 -0
- package/dist/cjs/utils/sessionUtils.js +181 -0
- package/dist/cjs/utils/validationUtils.js +173 -0
- package/dist/esm/AuthManager.js +356 -0
- package/dist/esm/CrossDomainAuth.js +253 -0
- package/dist/esm/HttpService.js +614 -0
- package/dist/esm/OxyServices.base.js +259 -0
- package/dist/esm/OxyServices.errors.js +17 -0
- package/dist/esm/OxyServices.js +59 -0
- package/dist/esm/constants/version.js +13 -0
- package/dist/esm/crypto/index.js +13 -0
- package/dist/esm/crypto/keyManager.js +850 -0
- package/dist/esm/crypto/polyfill.js +61 -0
- package/dist/esm/crypto/recoveryPhrase.js +132 -0
- package/dist/esm/crypto/signatureService.js +259 -0
- package/dist/esm/i18n/index.js +69 -0
- package/dist/esm/i18n/locales/ar-SA.json +120 -0
- package/dist/esm/i18n/locales/ca-ES.json +120 -0
- package/dist/esm/i18n/locales/de-DE.json +120 -0
- package/dist/esm/i18n/locales/en-US.json +956 -0
- package/dist/esm/i18n/locales/es-ES.json +944 -0
- package/dist/esm/i18n/locales/fr-FR.json +120 -0
- package/dist/esm/i18n/locales/it-IT.json +120 -0
- package/dist/esm/i18n/locales/ja-JP.json +119 -0
- package/dist/esm/i18n/locales/ko-KR.json +120 -0
- package/dist/esm/i18n/locales/locales/ar-SA.json +120 -0
- package/dist/esm/i18n/locales/locales/ca-ES.json +120 -0
- package/dist/esm/i18n/locales/locales/de-DE.json +120 -0
- package/dist/esm/i18n/locales/locales/en-US.json +956 -0
- package/dist/esm/i18n/locales/locales/es-ES.json +944 -0
- package/dist/esm/i18n/locales/locales/fr-FR.json +120 -0
- package/dist/esm/i18n/locales/locales/it-IT.json +120 -0
- package/dist/esm/i18n/locales/locales/ja-JP.json +119 -0
- package/dist/esm/i18n/locales/locales/ko-KR.json +120 -0
- package/dist/esm/i18n/locales/locales/pt-PT.json +120 -0
- package/dist/esm/i18n/locales/locales/zh-CN.json +120 -0
- package/dist/esm/i18n/locales/pt-PT.json +120 -0
- package/dist/esm/i18n/locales/zh-CN.json +120 -0
- package/dist/esm/index.js +55 -0
- package/dist/esm/mixins/OxyServices.analytics.js +46 -0
- package/dist/esm/mixins/OxyServices.assets.js +377 -0
- package/dist/esm/mixins/OxyServices.auth.js +256 -0
- package/dist/esm/mixins/OxyServices.developer.js +94 -0
- package/dist/esm/mixins/OxyServices.devices.js +113 -0
- package/dist/esm/mixins/OxyServices.features.js +306 -0
- package/dist/esm/mixins/OxyServices.fedcm.js +433 -0
- package/dist/esm/mixins/OxyServices.karma.js +105 -0
- package/dist/esm/mixins/OxyServices.language.js +118 -0
- package/dist/esm/mixins/OxyServices.location.js +40 -0
- package/dist/esm/mixins/OxyServices.payment.js +155 -0
- package/dist/esm/mixins/OxyServices.popup.js +369 -0
- package/dist/esm/mixins/OxyServices.privacy.js +159 -0
- package/dist/esm/mixins/OxyServices.redirect.js +343 -0
- package/dist/esm/mixins/OxyServices.security.js +78 -0
- package/dist/esm/mixins/OxyServices.user.js +352 -0
- package/dist/esm/mixins/OxyServices.utility.js +153 -0
- package/dist/esm/mixins/index.js +76 -0
- package/dist/esm/mixins/mixinHelpers.js +48 -0
- package/dist/esm/models/interfaces.js +17 -0
- package/dist/esm/models/session.js +1 -0
- package/dist/esm/shared/index.js +31 -0
- package/dist/esm/shared/utils/colorUtils.js +143 -0
- package/dist/esm/shared/utils/debugUtils.js +65 -0
- package/dist/esm/shared/utils/errorUtils.js +170 -0
- package/dist/esm/shared/utils/index.js +15 -0
- package/dist/esm/shared/utils/networkUtils.js +173 -0
- package/dist/esm/shared/utils/themeUtils.js +98 -0
- package/dist/esm/utils/apiUtils.js +55 -0
- package/dist/esm/utils/asyncUtils.js +179 -0
- package/dist/esm/utils/cache.js +218 -0
- package/dist/esm/utils/deviceManager.js +168 -0
- package/dist/esm/utils/errorUtils.js +146 -0
- package/dist/esm/utils/index.js +7 -0
- package/dist/esm/utils/languageUtils.js +158 -0
- package/dist/esm/utils/loggerUtils.js +115 -0
- package/dist/esm/utils/platform.js +102 -0
- package/dist/esm/utils/requestUtils.js +203 -0
- package/dist/esm/utils/sessionUtils.js +171 -0
- package/dist/esm/utils/validationUtils.js +153 -0
- package/dist/types/AuthManager.d.ts +143 -0
- package/dist/types/CrossDomainAuth.d.ts +160 -0
- package/dist/types/HttpService.d.ts +163 -0
- package/dist/types/OxyServices.base.d.ts +126 -0
- package/dist/types/OxyServices.d.ts +81 -0
- package/dist/types/OxyServices.errors.d.ts +11 -0
- package/dist/types/constants/version.d.ts +13 -0
- package/dist/types/crypto/index.d.ts +11 -0
- package/dist/types/crypto/keyManager.d.ts +189 -0
- package/dist/types/crypto/polyfill.d.ts +11 -0
- package/dist/types/crypto/recoveryPhrase.d.ts +58 -0
- package/dist/types/crypto/signatureService.d.ts +86 -0
- package/dist/types/i18n/index.d.ts +3 -0
- package/dist/types/index.d.ts +50 -0
- package/dist/types/mixins/OxyServices.analytics.d.ts +66 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +135 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +186 -0
- package/dist/types/mixins/OxyServices.developer.d.ts +99 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +96 -0
- package/dist/types/mixins/OxyServices.features.d.ts +228 -0
- package/dist/types/mixins/OxyServices.fedcm.d.ts +200 -0
- package/dist/types/mixins/OxyServices.karma.d.ts +85 -0
- package/dist/types/mixins/OxyServices.language.d.ts +81 -0
- package/dist/types/mixins/OxyServices.location.d.ts +64 -0
- package/dist/types/mixins/OxyServices.payment.d.ts +111 -0
- package/dist/types/mixins/OxyServices.popup.d.ts +205 -0
- package/dist/types/mixins/OxyServices.privacy.d.ts +122 -0
- package/dist/types/mixins/OxyServices.redirect.d.ts +245 -0
- package/dist/types/mixins/OxyServices.security.d.ts +78 -0
- package/dist/types/mixins/OxyServices.user.d.ts +182 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +93 -0
- package/dist/types/mixins/index.d.ts +30 -0
- package/dist/types/mixins/mixinHelpers.d.ts +31 -0
- package/dist/types/models/interfaces.d.ts +415 -0
- package/dist/types/models/session.d.ts +27 -0
- package/dist/types/shared/index.d.ts +28 -0
- package/dist/types/shared/utils/colorUtils.d.ts +104 -0
- package/dist/types/shared/utils/debugUtils.d.ts +48 -0
- package/dist/types/shared/utils/errorUtils.d.ts +97 -0
- package/dist/types/shared/utils/index.d.ts +13 -0
- package/dist/types/shared/utils/networkUtils.d.ts +139 -0
- package/dist/types/shared/utils/themeUtils.d.ts +90 -0
- package/dist/types/utils/apiUtils.d.ts +53 -0
- package/dist/types/utils/asyncUtils.d.ts +58 -0
- package/dist/types/utils/cache.d.ts +127 -0
- package/dist/types/utils/deviceManager.d.ts +65 -0
- package/dist/types/utils/errorUtils.d.ts +46 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/languageUtils.d.ts +37 -0
- package/dist/types/utils/loggerUtils.d.ts +48 -0
- package/dist/types/utils/platform.d.ts +40 -0
- package/dist/types/utils/requestUtils.d.ts +123 -0
- package/dist/types/utils/sessionUtils.d.ts +54 -0
- package/dist/types/utils/validationUtils.d.ts +85 -0
- package/package.json +84 -0
- package/src/AuthManager.ts +436 -0
- package/src/CrossDomainAuth.ts +307 -0
- package/src/HttpService.ts +752 -0
- package/src/OxyServices.base.ts +334 -0
- package/src/OxyServices.errors.ts +26 -0
- package/src/OxyServices.ts +129 -0
- package/src/constants/version.ts +15 -0
- package/src/crypto/index.ts +25 -0
- package/src/crypto/keyManager.ts +962 -0
- package/src/crypto/polyfill.ts +70 -0
- package/src/crypto/recoveryPhrase.ts +166 -0
- package/src/crypto/signatureService.ts +323 -0
- package/src/i18n/index.ts +75 -0
- package/src/i18n/locales/ar-SA.json +120 -0
- package/src/i18n/locales/ca-ES.json +120 -0
- package/src/i18n/locales/de-DE.json +120 -0
- package/src/i18n/locales/en-US.json +956 -0
- package/src/i18n/locales/es-ES.json +944 -0
- package/src/i18n/locales/fr-FR.json +120 -0
- package/src/i18n/locales/it-IT.json +120 -0
- package/src/i18n/locales/ja-JP.json +119 -0
- package/src/i18n/locales/ko-KR.json +120 -0
- package/src/i18n/locales/pt-PT.json +120 -0
- package/src/i18n/locales/zh-CN.json +120 -0
- package/src/index.ts +153 -0
- package/src/mixins/OxyServices.analytics.ts +53 -0
- package/src/mixins/OxyServices.assets.ts +412 -0
- package/src/mixins/OxyServices.auth.ts +358 -0
- package/src/mixins/OxyServices.developer.ts +114 -0
- package/src/mixins/OxyServices.devices.ts +119 -0
- package/src/mixins/OxyServices.features.ts +428 -0
- package/src/mixins/OxyServices.fedcm.ts +494 -0
- package/src/mixins/OxyServices.karma.ts +111 -0
- package/src/mixins/OxyServices.language.ts +127 -0
- package/src/mixins/OxyServices.location.ts +46 -0
- package/src/mixins/OxyServices.payment.ts +163 -0
- package/src/mixins/OxyServices.popup.ts +443 -0
- package/src/mixins/OxyServices.privacy.ts +182 -0
- package/src/mixins/OxyServices.redirect.ts +397 -0
- package/src/mixins/OxyServices.security.ts +103 -0
- package/src/mixins/OxyServices.user.ts +392 -0
- package/src/mixins/OxyServices.utility.ts +191 -0
- package/src/mixins/index.ts +91 -0
- package/src/mixins/mixinHelpers.ts +69 -0
- package/src/models/interfaces.ts +511 -0
- package/src/models/session.ts +30 -0
- package/src/shared/index.ts +82 -0
- package/src/shared/utils/colorUtils.ts +155 -0
- package/src/shared/utils/debugUtils.ts +73 -0
- package/src/shared/utils/errorUtils.ts +181 -0
- package/src/shared/utils/index.ts +59 -0
- package/src/shared/utils/networkUtils.ts +248 -0
- package/src/shared/utils/themeUtils.ts +115 -0
- package/src/types/bip39.d.ts +32 -0
- package/src/types/buffer.d.ts +97 -0
- package/src/types/color.d.ts +20 -0
- package/src/types/elliptic.d.ts +62 -0
- package/src/utils/apiUtils.ts +88 -0
- package/src/utils/asyncUtils.ts +252 -0
- package/src/utils/cache.ts +264 -0
- package/src/utils/deviceManager.ts +198 -0
- package/src/utils/errorUtils.ts +216 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/languageUtils.ts +174 -0
- package/src/utils/loggerUtils.ts +153 -0
- package/src/utils/platform.ts +117 -0
- package/src/utils/requestUtils.ts +237 -0
- package/src/utils/sessionUtils.ts +206 -0
- package/src/utils/validationUtils.ts +174 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-Domain Authentication Helper
|
|
3
|
+
*
|
|
4
|
+
* Provides a simplified API for cross-domain SSO authentication that automatically
|
|
5
|
+
* selects the best authentication method based on browser capabilities:
|
|
6
|
+
*
|
|
7
|
+
* 1. FedCM (if supported) - Modern, Google-style browser-native auth
|
|
8
|
+
* 2. Popup (fallback) - OAuth2-style popup window
|
|
9
|
+
* 3. Redirect (final fallback) - Traditional full-page redirect
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { CrossDomainAuth } from '@oxyhq/services';
|
|
14
|
+
*
|
|
15
|
+
* const auth = new CrossDomainAuth(oxyServices);
|
|
16
|
+
*
|
|
17
|
+
* // Automatic method selection
|
|
18
|
+
* const session = await auth.signIn();
|
|
19
|
+
*
|
|
20
|
+
* // Or use specific method
|
|
21
|
+
* const session = await auth.signInWithPopup();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import type { OxyServices } from './OxyServices';
|
|
25
|
+
import type { SessionLoginResponse } from './models/session';
|
|
26
|
+
export interface CrossDomainAuthOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Preferred authentication method
|
|
29
|
+
* - 'auto': Automatically select best method (default)
|
|
30
|
+
* - 'fedcm': Use FedCM (browser-native)
|
|
31
|
+
* - 'popup': Use popup window
|
|
32
|
+
* - 'redirect': Use full-page redirect
|
|
33
|
+
*/
|
|
34
|
+
method?: 'auto' | 'fedcm' | 'popup' | 'redirect';
|
|
35
|
+
/**
|
|
36
|
+
* Custom redirect URI (for redirect method)
|
|
37
|
+
*/
|
|
38
|
+
redirectUri?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to open signup page instead of login
|
|
41
|
+
*/
|
|
42
|
+
isSignup?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Popup window dimensions (for popup method)
|
|
45
|
+
*/
|
|
46
|
+
popupDimensions?: {
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Callback when auth method is selected
|
|
52
|
+
*/
|
|
53
|
+
onMethodSelected?: (method: 'fedcm' | 'popup' | 'redirect') => void;
|
|
54
|
+
}
|
|
55
|
+
export declare class CrossDomainAuth {
|
|
56
|
+
private oxyServices;
|
|
57
|
+
constructor(oxyServices: OxyServices);
|
|
58
|
+
/**
|
|
59
|
+
* Sign in with automatic method selection
|
|
60
|
+
*
|
|
61
|
+
* Tries methods in this order:
|
|
62
|
+
* 1. FedCM (if supported and not in private browsing)
|
|
63
|
+
* 2. Popup (if not blocked)
|
|
64
|
+
* 3. Redirect (always works)
|
|
65
|
+
*
|
|
66
|
+
* @param options - Authentication options
|
|
67
|
+
* @returns Session with user data and access token
|
|
68
|
+
*/
|
|
69
|
+
signIn(options?: CrossDomainAuthOptions): Promise<SessionLoginResponse | null>;
|
|
70
|
+
/**
|
|
71
|
+
* Automatic sign-in with progressive enhancement
|
|
72
|
+
*
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
private autoSignIn;
|
|
76
|
+
/**
|
|
77
|
+
* Sign in using FedCM (Federated Credential Management)
|
|
78
|
+
*
|
|
79
|
+
* Best method - browser-native, no popups, Google-like experience
|
|
80
|
+
*/
|
|
81
|
+
signInWithFedCM(options?: CrossDomainAuthOptions): Promise<SessionLoginResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Sign in using popup window
|
|
84
|
+
*
|
|
85
|
+
* Good method - preserves app state, no full page reload
|
|
86
|
+
*/
|
|
87
|
+
signInWithPopup(options?: CrossDomainAuthOptions): Promise<SessionLoginResponse>;
|
|
88
|
+
/**
|
|
89
|
+
* Sign in using full-page redirect
|
|
90
|
+
*
|
|
91
|
+
* Fallback method - works everywhere but loses app state
|
|
92
|
+
*/
|
|
93
|
+
signInWithRedirect(options?: CrossDomainAuthOptions): void;
|
|
94
|
+
/**
|
|
95
|
+
* Handle redirect callback
|
|
96
|
+
*
|
|
97
|
+
* Call this on app startup to check if we're returning from auth redirect
|
|
98
|
+
*/
|
|
99
|
+
handleRedirectCallback(): SessionLoginResponse | null;
|
|
100
|
+
/**
|
|
101
|
+
* Silent sign-in (check for existing session)
|
|
102
|
+
*
|
|
103
|
+
* Tries to automatically sign in without user interaction.
|
|
104
|
+
* Works with both FedCM and popup/iframe methods.
|
|
105
|
+
*
|
|
106
|
+
* @returns Session if user is already signed in, null otherwise
|
|
107
|
+
*/
|
|
108
|
+
silentSignIn(): Promise<SessionLoginResponse | null>;
|
|
109
|
+
/**
|
|
110
|
+
* Restore session from storage
|
|
111
|
+
*
|
|
112
|
+
* For redirect method - restores previously authenticated session from localStorage
|
|
113
|
+
*/
|
|
114
|
+
restoreSession(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Check if FedCM is supported in current browser
|
|
117
|
+
*/
|
|
118
|
+
isFedCMSupported(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Get recommended authentication method for current environment
|
|
121
|
+
*
|
|
122
|
+
* @returns Recommended method name and reason
|
|
123
|
+
*/
|
|
124
|
+
getRecommendedMethod(): {
|
|
125
|
+
method: 'fedcm' | 'popup' | 'redirect';
|
|
126
|
+
reason: string;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Initialize cross-domain auth on app startup
|
|
130
|
+
*
|
|
131
|
+
* This handles:
|
|
132
|
+
* 1. Redirect callback (if returning from auth.oxy.so)
|
|
133
|
+
* 2. Session restoration (from localStorage)
|
|
134
|
+
* 3. Silent sign-in (check for existing SSO session)
|
|
135
|
+
*
|
|
136
|
+
* @returns Session if user is authenticated, null otherwise
|
|
137
|
+
*/
|
|
138
|
+
initialize(): Promise<SessionLoginResponse | null>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Helper function to create CrossDomainAuth instance
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { createCrossDomainAuth } from '@oxyhq/services';
|
|
146
|
+
*
|
|
147
|
+
* const oxyServices = new OxyServices({ baseURL: 'https://api.oxy.so' });
|
|
148
|
+
* const auth = createCrossDomainAuth(oxyServices);
|
|
149
|
+
*
|
|
150
|
+
* // On app startup
|
|
151
|
+
* const session = await auth.initialize();
|
|
152
|
+
* if (session) {
|
|
153
|
+
* console.log('User is signed in:', session.user);
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* // Sign in button click
|
|
157
|
+
* const session = await auth.signIn();
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function createCrossDomainAuth(oxyServices: OxyServices): CrossDomainAuth;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified HTTP Service
|
|
3
|
+
*
|
|
4
|
+
* Consolidates HttpClient + RequestManager into a single efficient class.
|
|
5
|
+
* Uses native fetch instead of axios for smaller bundle size.
|
|
6
|
+
*
|
|
7
|
+
* Handles:
|
|
8
|
+
* - Authentication (token management, auto-refresh)
|
|
9
|
+
* - Caching (TTL-based)
|
|
10
|
+
* - Deduplication (concurrent requests)
|
|
11
|
+
* - Retry logic
|
|
12
|
+
* - Error handling
|
|
13
|
+
* - Request queuing
|
|
14
|
+
*/
|
|
15
|
+
import type { OxyConfig } from './models/interfaces';
|
|
16
|
+
export interface RequestOptions {
|
|
17
|
+
cache?: boolean;
|
|
18
|
+
cacheTTL?: number;
|
|
19
|
+
deduplicate?: boolean;
|
|
20
|
+
retry?: boolean;
|
|
21
|
+
maxRetries?: number;
|
|
22
|
+
timeout?: number;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
interface RequestConfig extends RequestOptions {
|
|
27
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
28
|
+
url: string;
|
|
29
|
+
data?: unknown;
|
|
30
|
+
params?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Unified HTTP Service
|
|
34
|
+
*
|
|
35
|
+
* Consolidates HttpClient + RequestManager into a single efficient class.
|
|
36
|
+
* Uses native fetch instead of axios for smaller bundle size.
|
|
37
|
+
*/
|
|
38
|
+
export declare class HttpService {
|
|
39
|
+
private baseURL;
|
|
40
|
+
private tokenStore;
|
|
41
|
+
private cache;
|
|
42
|
+
private deduplicator;
|
|
43
|
+
private requestQueue;
|
|
44
|
+
private logger;
|
|
45
|
+
private config;
|
|
46
|
+
private requestMetrics;
|
|
47
|
+
constructor(config: OxyConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Robust FormData detection that works in browser and Node.js environments
|
|
50
|
+
* Checks multiple conditions to handle different FormData implementations
|
|
51
|
+
*/
|
|
52
|
+
private isFormData;
|
|
53
|
+
/**
|
|
54
|
+
* Main request method - handles everything in one place
|
|
55
|
+
*/
|
|
56
|
+
request<T = unknown>(config: RequestConfig): Promise<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Generate cache key efficiently
|
|
59
|
+
* Uses simple hash for large objects to avoid expensive JSON.stringify
|
|
60
|
+
*/
|
|
61
|
+
private generateCacheKey;
|
|
62
|
+
/**
|
|
63
|
+
* Build full URL with query params
|
|
64
|
+
*/
|
|
65
|
+
private buildURL;
|
|
66
|
+
/**
|
|
67
|
+
* Fetch CSRF token from server (with deduplication)
|
|
68
|
+
* Required for state-changing requests (POST, PUT, PATCH, DELETE)
|
|
69
|
+
*/
|
|
70
|
+
private fetchCsrfToken;
|
|
71
|
+
/**
|
|
72
|
+
* Get auth header with automatic token refresh
|
|
73
|
+
*/
|
|
74
|
+
private getAuthHeader;
|
|
75
|
+
/**
|
|
76
|
+
* Unwrap standardized API response format
|
|
77
|
+
*/
|
|
78
|
+
private unwrapResponse;
|
|
79
|
+
/**
|
|
80
|
+
* Update request metrics
|
|
81
|
+
*/
|
|
82
|
+
private updateMetrics;
|
|
83
|
+
/**
|
|
84
|
+
* GET request convenience method
|
|
85
|
+
*/
|
|
86
|
+
get<T = unknown>(url: string, config?: Omit<RequestConfig, 'method' | 'url'>): Promise<{
|
|
87
|
+
data: T;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* POST request convenience method
|
|
91
|
+
* Supports FormData uploads - Content-Type will be set automatically for FormData
|
|
92
|
+
* @param url - Request URL
|
|
93
|
+
* @param data - Request body (can be FormData for file uploads)
|
|
94
|
+
* @param config - Request configuration including optional headers
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const formData = new FormData();
|
|
98
|
+
* formData.append('file', file);
|
|
99
|
+
* await api.post('/upload', formData, { headers: { 'X-Custom-Header': 'value' } });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
post<T = unknown>(url: string, data?: unknown, config?: Omit<RequestConfig, 'method' | 'url' | 'data'>): Promise<{
|
|
103
|
+
data: T;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* PUT request convenience method
|
|
107
|
+
* Supports FormData uploads - Content-Type will be set automatically for FormData
|
|
108
|
+
* @param url - Request URL
|
|
109
|
+
* @param data - Request body (can be FormData for file uploads)
|
|
110
|
+
* @param config - Request configuration including optional headers
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const formData = new FormData();
|
|
114
|
+
* formData.append('file', file);
|
|
115
|
+
* await api.put('/upload', formData, { headers: { 'X-Custom-Header': 'value' } });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
put<T = unknown>(url: string, data?: unknown, config?: Omit<RequestConfig, 'method' | 'url' | 'data'>): Promise<{
|
|
119
|
+
data: T;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* PATCH request convenience method
|
|
123
|
+
* Supports FormData uploads - Content-Type will be set automatically for FormData
|
|
124
|
+
* @param url - Request URL
|
|
125
|
+
* @param data - Request body (can be FormData for file uploads)
|
|
126
|
+
* @param config - Request configuration including optional headers
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const formData = new FormData();
|
|
130
|
+
* formData.append('file', file);
|
|
131
|
+
* await api.patch('/upload', formData, { headers: { 'X-Custom-Header': 'value' } });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
patch<T = unknown>(url: string, data?: unknown, config?: Omit<RequestConfig, 'method' | 'url' | 'data'>): Promise<{
|
|
135
|
+
data: T;
|
|
136
|
+
}>;
|
|
137
|
+
delete<T = unknown>(url: string, config?: Omit<RequestConfig, 'method' | 'url'>): Promise<{
|
|
138
|
+
data: T;
|
|
139
|
+
}>;
|
|
140
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
141
|
+
clearTokens(): void;
|
|
142
|
+
getAccessToken(): string | null;
|
|
143
|
+
hasAccessToken(): boolean;
|
|
144
|
+
getBaseURL(): string;
|
|
145
|
+
clearCache(): void;
|
|
146
|
+
clearCacheEntry(key: string): void;
|
|
147
|
+
getCacheStats(): {
|
|
148
|
+
size: number;
|
|
149
|
+
hits: number;
|
|
150
|
+
misses: number;
|
|
151
|
+
hitRate: number;
|
|
152
|
+
};
|
|
153
|
+
getMetrics(): {
|
|
154
|
+
totalRequests: number;
|
|
155
|
+
successfulRequests: number;
|
|
156
|
+
failedRequests: number;
|
|
157
|
+
cacheHits: number;
|
|
158
|
+
cacheMisses: number;
|
|
159
|
+
averageResponseTime: number;
|
|
160
|
+
};
|
|
161
|
+
static __resetTokensForTests(): void;
|
|
162
|
+
}
|
|
163
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { OxyConfig as OxyConfigBase } from './models/interfaces';
|
|
2
|
+
import { HttpService, type RequestOptions } from './HttpService';
|
|
3
|
+
export interface OxyConfig extends OxyConfigBase {
|
|
4
|
+
cloudURL?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Base class for OxyServices with core infrastructure
|
|
8
|
+
*/
|
|
9
|
+
export declare class OxyServicesBase {
|
|
10
|
+
httpService: HttpService;
|
|
11
|
+
cloudURL: string;
|
|
12
|
+
config: OxyConfig;
|
|
13
|
+
constructor(...args: any[]);
|
|
14
|
+
static __resetTokensForTests(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Make a request with all performance optimizations
|
|
17
|
+
* This is the main method for all API calls - ensures authentication and performance features
|
|
18
|
+
*/
|
|
19
|
+
makeRequest<T>(method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', url: string, data?: any, options?: RequestOptions): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the configured Oxy API base URL
|
|
22
|
+
*/
|
|
23
|
+
getBaseURL(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get the HTTP service instance
|
|
26
|
+
* Useful for advanced use cases where direct access to the HTTP service is needed
|
|
27
|
+
*/
|
|
28
|
+
getClient(): HttpService;
|
|
29
|
+
/**
|
|
30
|
+
* Get performance metrics
|
|
31
|
+
*/
|
|
32
|
+
getMetrics(): {
|
|
33
|
+
totalRequests: number;
|
|
34
|
+
successfulRequests: number;
|
|
35
|
+
failedRequests: number;
|
|
36
|
+
cacheHits: number;
|
|
37
|
+
cacheMisses: number;
|
|
38
|
+
averageResponseTime: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Clear request cache
|
|
42
|
+
*/
|
|
43
|
+
clearCache(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Clear specific cache entry
|
|
46
|
+
*/
|
|
47
|
+
clearCacheEntry(key: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get cache statistics
|
|
50
|
+
*/
|
|
51
|
+
getCacheStats(): {
|
|
52
|
+
size: number;
|
|
53
|
+
hits: number;
|
|
54
|
+
misses: number;
|
|
55
|
+
hitRate: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Get the configured Oxy Cloud (file storage/CDN) URL
|
|
59
|
+
*/
|
|
60
|
+
getCloudURL(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Set authentication tokens
|
|
63
|
+
*/
|
|
64
|
+
setTokens(accessToken: string, refreshToken?: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Clear stored authentication tokens
|
|
67
|
+
*/
|
|
68
|
+
clearTokens(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the current user ID from the access token
|
|
71
|
+
*/
|
|
72
|
+
getCurrentUserId(): string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Check if the client has a valid access token (public method)
|
|
75
|
+
*/
|
|
76
|
+
hasValidToken(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Get the raw access token (for constructing anchor URLs when needed)
|
|
79
|
+
*/
|
|
80
|
+
getAccessToken(): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Wait for authentication to be ready
|
|
83
|
+
*
|
|
84
|
+
* Optimized for high-scale usage with immediate synchronous check and adaptive polling.
|
|
85
|
+
* Returns immediately if token is already available (0ms delay), otherwise uses
|
|
86
|
+
* adaptive polling that starts fast (50ms) and gradually increases to reduce CPU usage.
|
|
87
|
+
*
|
|
88
|
+
* @param timeoutMs Maximum time to wait in milliseconds (default: 5000ms)
|
|
89
|
+
* @returns Promise that resolves to true if authentication is ready, false if timeout
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const isReady = await oxyServices.waitForAuth(3000);
|
|
94
|
+
* if (isReady) {
|
|
95
|
+
* // Proceed with authenticated operations
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
waitForAuth(timeoutMs?: number): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Execute a function with automatic authentication retry logic
|
|
102
|
+
* This handles the common case where API calls are made before authentication completes
|
|
103
|
+
*/
|
|
104
|
+
withAuthRetry<T>(operation: () => Promise<T>, operationName: string, options?: {
|
|
105
|
+
maxRetries?: number;
|
|
106
|
+
retryDelay?: number;
|
|
107
|
+
authTimeoutMs?: number;
|
|
108
|
+
}): Promise<T>;
|
|
109
|
+
/**
|
|
110
|
+
* Validate the current access token with the server
|
|
111
|
+
*/
|
|
112
|
+
validate(): Promise<boolean>;
|
|
113
|
+
/**
|
|
114
|
+
* Centralized error handling
|
|
115
|
+
*/
|
|
116
|
+
handleError(error: unknown): Error;
|
|
117
|
+
/**
|
|
118
|
+
* Health check endpoint
|
|
119
|
+
*/
|
|
120
|
+
healthCheck(): Promise<{
|
|
121
|
+
status: string;
|
|
122
|
+
users?: number;
|
|
123
|
+
timestamp?: string;
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
}>;
|
|
126
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OxyServices - Unified client for Oxy API and Oxy Cloud
|
|
3
|
+
*
|
|
4
|
+
* # Usage Examples
|
|
5
|
+
*
|
|
6
|
+
* ## Browser (ESM/TypeScript)
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { OxyServices } from './core/OxyServices';
|
|
10
|
+
*
|
|
11
|
+
* const oxy = new OxyServices({
|
|
12
|
+
* baseURL: 'https://api.oxy.so',
|
|
13
|
+
* cloudURL: 'https://cloud.oxy.so',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Authenticate and fetch user
|
|
17
|
+
* await oxy.setTokens('ACCESS_TOKEN');
|
|
18
|
+
* const user = await oxy.getCurrentUser();
|
|
19
|
+
*
|
|
20
|
+
* // Upload a file (browser File API)
|
|
21
|
+
* const fileInput = document.querySelector('input[type=file]');
|
|
22
|
+
* const file = fileInput.files[0];
|
|
23
|
+
* await oxy.uploadRawFile(file);
|
|
24
|
+
*
|
|
25
|
+
* // Get a file download URL for <img src>
|
|
26
|
+
* const url = oxy.getFileDownloadUrl('fileId', 'thumb');
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Node.js (CommonJS/TypeScript)
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { OxyServices } from './core/OxyServices';
|
|
33
|
+
* import fs from 'fs';
|
|
34
|
+
*
|
|
35
|
+
* const oxy = new OxyServices({
|
|
36
|
+
* baseURL: 'https://api.oxy.so',
|
|
37
|
+
* cloudURL: 'https://cloud.oxy.so',
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Authenticate and fetch user
|
|
41
|
+
* await oxy.setTokens('ACCESS_TOKEN');
|
|
42
|
+
* const user = await oxy.getCurrentUser();
|
|
43
|
+
*
|
|
44
|
+
* // Upload a file (Node.js Buffer)
|
|
45
|
+
* const buffer = fs.readFileSync('myfile.png');
|
|
46
|
+
* const blob = new Blob([buffer]);
|
|
47
|
+
* await oxy.uploadRawFile(blob, { filename: 'myfile.png' });
|
|
48
|
+
*
|
|
49
|
+
* // Get a file download URL
|
|
50
|
+
* const url = oxy.getFileDownloadUrl('fileId');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* ## Configuration
|
|
54
|
+
* - `baseURL`: Oxy API endpoint (e.g., https://api.oxy.so)
|
|
55
|
+
* - `cloudURL`: Oxy Cloud/CDN endpoint (e.g., https://cloud.oxy.so)
|
|
56
|
+
*
|
|
57
|
+
* See method JSDoc for more details and options.
|
|
58
|
+
*/
|
|
59
|
+
import { type OxyConfig } from './OxyServices.base';
|
|
60
|
+
import { OxyAuthenticationError, OxyAuthenticationTimeoutError } from './OxyServices.errors';
|
|
61
|
+
import { composeOxyServices } from './mixins';
|
|
62
|
+
declare const OxyServices_base: any;
|
|
63
|
+
export declare class OxyServices extends OxyServices_base {
|
|
64
|
+
constructor(config: OxyConfig);
|
|
65
|
+
}
|
|
66
|
+
export interface OxyServices extends InstanceType<ReturnType<typeof composeOxyServices>> {
|
|
67
|
+
}
|
|
68
|
+
export { OxyAuthenticationError, OxyAuthenticationTimeoutError };
|
|
69
|
+
/**
|
|
70
|
+
* Export the default Oxy Cloud URL (for backward compatibility)
|
|
71
|
+
*/
|
|
72
|
+
export declare const OXY_CLOUD_URL = "https://cloud.oxy.so";
|
|
73
|
+
/**
|
|
74
|
+
* Export the default Oxy API URL (for documentation)
|
|
75
|
+
*/
|
|
76
|
+
export declare const OXY_API_URL: string;
|
|
77
|
+
/**
|
|
78
|
+
* Pre-configured client instance for easy import
|
|
79
|
+
* Uses OXY_API_URL as baseURL and OXY_CLOUD_URL as cloudURL
|
|
80
|
+
*/
|
|
81
|
+
export declare const oxyClient: OxyServices;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error types for better error handling
|
|
3
|
+
*/
|
|
4
|
+
export declare class OxyAuthenticationError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly status: number;
|
|
7
|
+
constructor(message: string, code?: string, status?: number);
|
|
8
|
+
}
|
|
9
|
+
export declare class OxyAuthenticationTimeoutError extends OxyAuthenticationError {
|
|
10
|
+
constructor(operationName: string, timeoutMs: number);
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package version and metadata constants
|
|
3
|
+
* This file is auto-generated to avoid runtime dependency on package.json
|
|
4
|
+
*/
|
|
5
|
+
export declare const packageInfo: {
|
|
6
|
+
readonly name: "@oxyhq/services";
|
|
7
|
+
readonly version: "5.2.1";
|
|
8
|
+
readonly description: "Reusable OxyHQ module to handle authentication, user management, karma system and more 🚀";
|
|
9
|
+
readonly main: "lib/commonjs/node/index.js";
|
|
10
|
+
readonly module: "lib/module/node/index.js";
|
|
11
|
+
readonly types: "lib/typescript/node/index.d.ts";
|
|
12
|
+
};
|
|
13
|
+
export declare const name: "@oxyhq/services", version: "5.2.1", description: "Reusable OxyHQ module to handle authentication, user management, karma system and more 🚀";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Oxy Crypto Module
|
|
3
|
+
*
|
|
4
|
+
* Provides cryptographic identity management for the Oxy ecosystem.
|
|
5
|
+
* Handles key generation, secure storage, digital signatures, and recovery phrases.
|
|
6
|
+
*/
|
|
7
|
+
import './polyfill';
|
|
8
|
+
export { KeyManager, type KeyPair } from './keyManager';
|
|
9
|
+
export { SignatureService, type SignedMessage, type AuthChallenge } from './signatureService';
|
|
10
|
+
export { RecoveryPhraseService, type RecoveryPhraseResult } from './recoveryPhrase';
|
|
11
|
+
export { KeyManager as default } from './keyManager';
|