@oxyhq/core 1.0.1 → 1.1.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/dist/cjs/AuthManager.js +19 -9
- package/dist/cjs/CrossDomainAuth.js +2 -2
- package/dist/cjs/HttpService.js +9 -8
- package/dist/cjs/OxyServices.base.js +16 -3
- package/dist/cjs/crypto/keyManager.js +29 -24
- package/dist/cjs/crypto/polyfill.js +6 -1
- package/dist/cjs/crypto/signatureService.js +40 -31
- package/dist/cjs/i18n/index.js +36 -45
- package/dist/cjs/i18n/locales/ar-SA.json +114 -115
- package/dist/cjs/i18n/locales/ca-ES.json +114 -115
- package/dist/cjs/i18n/locales/de-DE.json +114 -115
- package/dist/cjs/i18n/locales/en-US.json +936 -936
- package/dist/cjs/i18n/locales/es-ES.json +924 -924
- package/dist/cjs/i18n/locales/fr-FR.json +114 -115
- package/dist/cjs/i18n/locales/it-IT.json +114 -115
- package/dist/cjs/i18n/locales/ja-JP.json +2 -2
- package/dist/cjs/i18n/locales/ko-KR.json +114 -115
- package/dist/cjs/i18n/locales/pt-PT.json +114 -115
- package/dist/cjs/i18n/locales/zh-CN.json +114 -115
- package/dist/cjs/mixins/OxyServices.fedcm.js +13 -41
- package/dist/cjs/mixins/OxyServices.language.js +5 -2
- package/dist/cjs/mixins/OxyServices.privacy.js +2 -1
- package/dist/cjs/mixins/OxyServices.security.js +3 -2
- package/dist/cjs/shared/utils/debugUtils.js +8 -1
- package/dist/cjs/utils/deviceManager.js +3 -1
- package/dist/cjs/utils/platform.js +3 -2
- package/dist/esm/AuthManager.js +19 -9
- package/dist/esm/CrossDomainAuth.js +2 -2
- package/dist/esm/HttpService.js +9 -8
- package/dist/esm/OxyServices.base.js +16 -3
- package/dist/esm/crypto/keyManager.js +29 -24
- package/dist/esm/crypto/polyfill.js +6 -1
- package/dist/esm/crypto/signatureService.js +40 -31
- package/dist/esm/i18n/index.js +11 -23
- package/dist/esm/i18n/locales/ar-SA.json +114 -115
- package/dist/esm/i18n/locales/ca-ES.json +114 -115
- package/dist/esm/i18n/locales/de-DE.json +114 -115
- package/dist/esm/i18n/locales/en-US.json +936 -936
- package/dist/esm/i18n/locales/es-ES.json +924 -924
- package/dist/esm/i18n/locales/fr-FR.json +114 -115
- package/dist/esm/i18n/locales/it-IT.json +114 -115
- package/dist/esm/i18n/locales/ja-JP.json +2 -2
- package/dist/esm/i18n/locales/ko-KR.json +114 -115
- package/dist/esm/i18n/locales/pt-PT.json +114 -115
- package/dist/esm/i18n/locales/zh-CN.json +114 -115
- package/dist/esm/mixins/OxyServices.fedcm.js +13 -41
- package/dist/esm/mixins/OxyServices.language.js +5 -2
- package/dist/esm/mixins/OxyServices.privacy.js +2 -1
- package/dist/esm/mixins/OxyServices.security.js +3 -2
- package/dist/esm/shared/utils/debugUtils.js +8 -1
- package/dist/esm/utils/deviceManager.js +3 -1
- package/dist/esm/utils/platform.js +3 -2
- package/dist/types/CrossDomainAuth.d.ts +2 -2
- package/dist/types/OxyServices.base.d.ts +4 -1
- package/dist/types/OxyServices.d.ts +13 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mixins/OxyServices.analytics.d.ts +2 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +2 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +2 -0
- package/dist/types/mixins/OxyServices.developer.d.ts +2 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +2 -0
- package/dist/types/mixins/OxyServices.features.d.ts +2 -0
- package/dist/types/mixins/OxyServices.fedcm.d.ts +4 -2
- package/dist/types/mixins/OxyServices.karma.d.ts +2 -0
- package/dist/types/mixins/OxyServices.language.d.ts +2 -0
- package/dist/types/mixins/OxyServices.location.d.ts +2 -0
- package/dist/types/mixins/OxyServices.payment.d.ts +2 -0
- package/dist/types/mixins/OxyServices.popup.d.ts +2 -0
- package/dist/types/mixins/OxyServices.privacy.d.ts +2 -0
- package/dist/types/mixins/OxyServices.redirect.d.ts +2 -0
- package/dist/types/mixins/OxyServices.security.d.ts +2 -0
- package/dist/types/mixins/OxyServices.user.d.ts +2 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +2 -0
- package/package.json +2 -3
- package/src/AuthManager.ts +25 -15
- package/src/CrossDomainAuth.ts +2 -2
- package/src/HttpService.ts +9 -8
- package/src/OxyServices.base.ts +21 -4
- package/src/OxyServices.ts +23 -2
- package/src/crypto/keyManager.ts +30 -25
- package/src/crypto/polyfill.ts +6 -1
- package/src/crypto/signatureService.ts +43 -37
- package/src/i18n/index.ts +33 -45
- package/src/index.ts +3 -0
- package/src/mixins/OxyServices.fedcm.ts +14 -44
- package/src/mixins/OxyServices.language.ts +6 -3
- package/src/mixins/OxyServices.privacy.ts +2 -1
- package/src/mixins/OxyServices.security.ts +3 -2
- package/src/shared/utils/__tests__/debugUtils.test.ts +55 -0
- package/src/shared/utils/debugUtils.ts +6 -1
- package/src/utils/deviceManager.ts +4 -2
- package/src/utils/platform.ts +3 -2
|
@@ -1,120 +1,119 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"signin": {
|
|
3
|
+
"title": "登录",
|
|
4
|
+
"subtitle": "登录以继续",
|
|
5
|
+
"addAccountTitle": "添加另一个账户",
|
|
6
|
+
"addAccountSubtitle": "使用另一个账户登录",
|
|
7
|
+
"username": {
|
|
8
|
+
"label": "用户名",
|
|
9
|
+
"placeholder": "输入您的用户名",
|
|
10
|
+
"helper": "3-30个字符,仅字母和数字",
|
|
11
|
+
"required": "请输入您的用户名。",
|
|
12
|
+
"minLength": "用户名必须至少包含3个字符。"
|
|
13
|
+
},
|
|
14
|
+
"password": {
|
|
15
|
+
"label": "密码",
|
|
16
|
+
"placeholder": "输入您的密码",
|
|
17
|
+
"required": "请输入您的密码。",
|
|
18
|
+
"hint": "输入您的密码以登录"
|
|
19
|
+
},
|
|
20
|
+
"actions": {
|
|
21
|
+
"continue": "继续",
|
|
22
|
+
"back": "返回",
|
|
23
|
+
"signIn": "登录",
|
|
24
|
+
"verify": "验证",
|
|
25
|
+
"openAccountSwitcher": "切换到另一个账户",
|
|
26
|
+
"openAccountSwitcherSubtitle": "{{count}}个其他账户可用",
|
|
27
|
+
"openAccountSwitcherSubtitle_singular": "1个其他账户可用",
|
|
28
|
+
"openAccountSwitcherSubtitle_zero": "查看您保存的账户",
|
|
29
|
+
"manageAccounts": "管理保存的账户",
|
|
30
|
+
"manageAccountsSubtitle": "查看会话、删除或登出",
|
|
31
|
+
"loadingOtherAccounts": "加载其他账户中…",
|
|
32
|
+
"switchAccountFailed": "无法切换账户。请重试。"
|
|
33
|
+
},
|
|
34
|
+
"forgotPrompt": "忘记密码?",
|
|
35
|
+
"security": {
|
|
36
|
+
"dataSecure": "您的数据已加密且安全"
|
|
37
|
+
},
|
|
38
|
+
"currentlySignedInAs": "当前登录为",
|
|
39
|
+
"alreadySignedInWith": "已登录",
|
|
40
|
+
"alreadySignedIn": "已登录",
|
|
41
|
+
"alreadySignedInMessage": "此账户已登录。继续使用此账户?",
|
|
42
|
+
"continueWithAccount": "继续",
|
|
43
|
+
"currentAccount": "当前",
|
|
44
|
+
"or": "或",
|
|
45
|
+
"viewAllAccounts": "查看更多{{count}}个",
|
|
46
|
+
"status": {
|
|
47
|
+
"accountSwitched": "正在使用{{name}}"
|
|
48
|
+
}
|
|
13
49
|
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
50
|
+
"signup": {
|
|
51
|
+
"welcome": {
|
|
52
|
+
"title": "欢迎使用Oxy!",
|
|
53
|
+
"subtitle": "只需几步即可创建您的账户",
|
|
54
|
+
"haveAccount": "已有账户?",
|
|
55
|
+
"signInCta": "登录"
|
|
56
|
+
},
|
|
57
|
+
"identity": {
|
|
58
|
+
"title": "您是谁?",
|
|
59
|
+
"subtitle": "选择您的用户名并输入您的电子邮件"
|
|
60
|
+
},
|
|
61
|
+
"username": {
|
|
62
|
+
"helper": "3-30个字符,仅字母和数字",
|
|
63
|
+
"required": "请输入用户名",
|
|
64
|
+
"minLength": "用户名必须至少包含3个字符"
|
|
65
|
+
},
|
|
66
|
+
"email": {
|
|
67
|
+
"required": "请输入电子邮件地址",
|
|
68
|
+
"invalid": "请输入有效的电子邮件地址",
|
|
69
|
+
"helper": "我们绝不会分享您的电子邮件"
|
|
70
|
+
},
|
|
71
|
+
"security": {
|
|
72
|
+
"title": "保护您的账户",
|
|
73
|
+
"subtitle": "创建强密码以保护您的账户"
|
|
74
|
+
},
|
|
75
|
+
"password": {
|
|
76
|
+
"helper": "至少8个字符",
|
|
77
|
+
"required": "请输入密码",
|
|
78
|
+
"minLength": "密码必须至少包含8个字符",
|
|
79
|
+
"confirmRequired": "请确认您的密码",
|
|
80
|
+
"mismatch": "密码不匹配",
|
|
81
|
+
"confirmHint": "重新输入您的密码以确认"
|
|
82
|
+
},
|
|
83
|
+
"summary": {
|
|
84
|
+
"title": "快完成了!",
|
|
85
|
+
"subtitle": "查看您的信息并创建账户",
|
|
86
|
+
"sectionTitle": "账户信息",
|
|
87
|
+
"fields": {
|
|
88
|
+
"username": "用户名",
|
|
89
|
+
"email": "电子邮件",
|
|
90
|
+
"password": "密码"
|
|
91
|
+
},
|
|
92
|
+
"notSet": "未设置",
|
|
93
|
+
"securityTip": "为了更强的安全性,创建账户后,请在账户设置中启用生物识别身份验证。",
|
|
94
|
+
"legalReminder": "创建账户即表示您同意我们的服务条款和隐私政策。"
|
|
95
|
+
}
|
|
19
96
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"alreadySignedInMessage": "此账户已登录。继续使用此账户?",
|
|
42
|
-
"continueWithAccount": "继续",
|
|
43
|
-
"currentAccount": "当前",
|
|
44
|
-
"or": "或",
|
|
45
|
-
"viewAllAccounts": "查看更多{{count}}个",
|
|
46
|
-
"status": {
|
|
47
|
-
"accountSwitched": "正在使用{{name}}"
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
"signup": {
|
|
51
|
-
"welcome": {
|
|
52
|
-
"title": "欢迎使用Oxy!",
|
|
53
|
-
"subtitle": "只需几步即可创建您的账户",
|
|
54
|
-
"haveAccount": "已有账户?",
|
|
55
|
-
"signInCta": "登录"
|
|
56
|
-
},
|
|
57
|
-
"identity": {
|
|
58
|
-
"title": "您是谁?",
|
|
59
|
-
"subtitle": "选择您的用户名并输入您的电子邮件"
|
|
60
|
-
},
|
|
61
|
-
"username": {
|
|
62
|
-
"helper": "3-30个字符,仅字母和数字",
|
|
63
|
-
"required": "请输入用户名",
|
|
64
|
-
"minLength": "用户名必须至少包含3个字符"
|
|
65
|
-
},
|
|
66
|
-
"email": {
|
|
67
|
-
"required": "请输入电子邮件地址",
|
|
68
|
-
"invalid": "请输入有效的电子邮件地址",
|
|
69
|
-
"helper": "我们绝不会分享您的电子邮件"
|
|
70
|
-
},
|
|
71
|
-
"security": {
|
|
72
|
-
"title": "保护您的账户",
|
|
73
|
-
"subtitle": "创建强密码以保护您的账户"
|
|
74
|
-
},
|
|
75
|
-
"password": {
|
|
76
|
-
"helper": "至少8个字符",
|
|
77
|
-
"required": "请输入密码",
|
|
78
|
-
"minLength": "密码必须至少包含8个字符",
|
|
79
|
-
"confirmRequired": "请确认您的密码",
|
|
80
|
-
"mismatch": "密码不匹配",
|
|
81
|
-
"confirmHint": "重新输入您的密码以确认"
|
|
82
|
-
},
|
|
83
|
-
"summary": {
|
|
84
|
-
"title": "快完成了!",
|
|
85
|
-
"subtitle": "查看您的信息并创建账户",
|
|
86
|
-
"sectionTitle": "账户信息",
|
|
87
|
-
"fields": {
|
|
88
|
-
"username": "用户名",
|
|
89
|
-
"email": "电子邮件",
|
|
90
|
-
"password": "密码"
|
|
91
|
-
},
|
|
92
|
-
"notSet": "未设置",
|
|
93
|
-
"securityTip": "为了更强的安全性,创建账户后,请在账户设置中启用生物识别身份验证。",
|
|
94
|
-
"legalReminder": "创建账户即表示您同意我们的服务条款和隐私政策。"
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
"common": {
|
|
98
|
-
"actions": {
|
|
99
|
-
"back": "返回",
|
|
100
|
-
"continue": "继续",
|
|
101
|
-
"next": "下一步",
|
|
102
|
-
"getStarted": "开始",
|
|
103
|
-
"createAccount": "创建账户",
|
|
104
|
-
"signIn": "登录",
|
|
105
|
-
"verify": "验证",
|
|
106
|
-
"resetPassword": "重置密码"
|
|
107
|
-
},
|
|
108
|
-
"links": {
|
|
109
|
-
"recoverAccount": "恢复您的账户",
|
|
110
|
-
"signUp": "注册"
|
|
111
|
-
},
|
|
112
|
-
"labels": {
|
|
113
|
-
"username": "用户名",
|
|
114
|
-
"email": "电子邮件",
|
|
115
|
-
"password": "密码",
|
|
116
|
-
"confirmPassword": "确认密码"
|
|
97
|
+
"common": {
|
|
98
|
+
"actions": {
|
|
99
|
+
"back": "返回",
|
|
100
|
+
"continue": "继续",
|
|
101
|
+
"next": "下一步",
|
|
102
|
+
"getStarted": "开始",
|
|
103
|
+
"createAccount": "创建账户",
|
|
104
|
+
"signIn": "登录",
|
|
105
|
+
"verify": "验证",
|
|
106
|
+
"resetPassword": "重置密码"
|
|
107
|
+
},
|
|
108
|
+
"links": {
|
|
109
|
+
"recoverAccount": "恢复您的账户",
|
|
110
|
+
"signUp": "注册"
|
|
111
|
+
},
|
|
112
|
+
"labels": {
|
|
113
|
+
"username": "用户名",
|
|
114
|
+
"email": "电子邮件",
|
|
115
|
+
"password": "密码",
|
|
116
|
+
"confirmPassword": "确认密码"
|
|
117
|
+
}
|
|
117
118
|
}
|
|
118
|
-
}
|
|
119
119
|
}
|
|
120
|
-
|
|
@@ -151,7 +151,10 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
151
151
|
}
|
|
152
152
|
const clientId = this.getClientId();
|
|
153
153
|
debug.log('Silent SSO: Starting for', clientId);
|
|
154
|
-
//
|
|
154
|
+
// Only try silent mediation (no UI) - works if user previously consented.
|
|
155
|
+
// We intentionally do NOT fall back to optional mediation here because
|
|
156
|
+
// this runs on app startup — showing browser UI without user action is bad UX.
|
|
157
|
+
// Optional/interactive mediation should only happen when the user clicks "Sign In".
|
|
155
158
|
let credential = null;
|
|
156
159
|
try {
|
|
157
160
|
const nonce = this.generateNonce();
|
|
@@ -165,33 +168,13 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
165
168
|
debug.log('Silent SSO: Silent mediation result:', { hasCredential: !!credential, hasToken: !!credential?.token });
|
|
166
169
|
}
|
|
167
170
|
catch (silentError) {
|
|
168
|
-
// Silent mediation failed - this is expected if user hasn't consented before or is in quiet period
|
|
169
171
|
const errorName = silentError instanceof Error ? silentError.name : 'Unknown';
|
|
170
172
|
const errorMessage = silentError instanceof Error ? silentError.message : String(silentError);
|
|
171
|
-
debug.log('Silent SSO: Silent mediation
|
|
172
|
-
|
|
173
|
-
// If silent failed, try optional mediation which shows browser UI if needed
|
|
174
|
-
if (!credential || !credential.token) {
|
|
175
|
-
try {
|
|
176
|
-
const nonce = this.generateNonce();
|
|
177
|
-
debug.log('Silent SSO: Trying optional mediation (may show browser UI)...');
|
|
178
|
-
credential = await this.requestIdentityCredential({
|
|
179
|
-
configURL: this.constructor.DEFAULT_CONFIG_URL,
|
|
180
|
-
clientId,
|
|
181
|
-
nonce,
|
|
182
|
-
mediation: 'optional',
|
|
183
|
-
});
|
|
184
|
-
debug.log('Silent SSO: Optional mediation result:', { hasCredential: !!credential, hasToken: !!credential?.token });
|
|
185
|
-
}
|
|
186
|
-
catch (optionalError) {
|
|
187
|
-
const errorName = optionalError instanceof Error ? optionalError.name : 'Unknown';
|
|
188
|
-
const errorMessage = optionalError instanceof Error ? optionalError.message : String(optionalError);
|
|
189
|
-
debug.log('Silent SSO: Optional mediation also failed:', { name: errorName, message: errorMessage });
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
173
|
+
debug.log('Silent SSO: Silent mediation failed:', { name: errorName, message: errorMessage });
|
|
174
|
+
return null;
|
|
192
175
|
}
|
|
193
176
|
if (!credential || !credential.token) {
|
|
194
|
-
debug.log('Silent SSO: No credential returned (user
|
|
177
|
+
debug.log('Silent SSO: No credential returned (user not logged in at IdP or hasn\'t consented)');
|
|
195
178
|
return null;
|
|
196
179
|
}
|
|
197
180
|
debug.log('Silent SSO: Got credential, exchanging for session...');
|
|
@@ -341,28 +324,17 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
341
324
|
* @private
|
|
342
325
|
*/
|
|
343
326
|
async exchangeIdTokenForSession(idToken) {
|
|
344
|
-
debug.log('
|
|
345
|
-
debug.log('exchangeIdTokenForSession: Token length:', idToken?.length);
|
|
346
|
-
debug.log('exchangeIdTokenForSession: Token preview:', idToken?.substring(0, 50) + '...');
|
|
327
|
+
debug.log('Exchanging ID token for session...');
|
|
347
328
|
try {
|
|
348
329
|
const response = await this.makeRequest('POST', '/api/fedcm/exchange', { id_token: idToken }, { cache: false });
|
|
349
|
-
debug.log('
|
|
350
|
-
|
|
351
|
-
hasSessionId: !!response?.sessionId,
|
|
330
|
+
debug.log('Token exchange complete:', {
|
|
331
|
+
hasSession: !!response?.sessionId,
|
|
352
332
|
hasUser: !!response?.user,
|
|
353
|
-
hasAccessToken: !!response?.accessToken,
|
|
354
|
-
userId: response?.user?.id,
|
|
355
|
-
username: response?.user?.username,
|
|
356
|
-
responseKeys: response ? Object.keys(response) : [],
|
|
357
333
|
});
|
|
358
334
|
return response;
|
|
359
335
|
}
|
|
360
336
|
catch (error) {
|
|
361
|
-
debug.error('
|
|
362
|
-
name: error instanceof Error ? error.name : 'Unknown',
|
|
363
|
-
message: error instanceof Error ? error.message : String(error),
|
|
364
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
365
|
-
});
|
|
337
|
+
debug.error('Token exchange failed:', error instanceof Error ? error.message : String(error));
|
|
366
338
|
throw error;
|
|
367
339
|
}
|
|
368
340
|
}
|
|
@@ -427,9 +399,9 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
427
399
|
}
|
|
428
400
|
},
|
|
429
401
|
_a.DEFAULT_CONFIG_URL = 'https://auth.oxy.so/fedcm.json',
|
|
430
|
-
_a.FEDCM_TIMEOUT =
|
|
402
|
+
_a.FEDCM_TIMEOUT = 15000 // 15 seconds for interactive
|
|
431
403
|
,
|
|
432
|
-
_a.FEDCM_SILENT_TIMEOUT =
|
|
404
|
+
_a.FEDCM_SILENT_TIMEOUT = 3000 // 3 seconds for silent mediation
|
|
433
405
|
,
|
|
434
406
|
_a;
|
|
435
407
|
}
|
|
@@ -38,6 +38,7 @@ exports.OxyServicesLanguageMixin = OxyServicesLanguageMixin;
|
|
|
38
38
|
* Language Methods Mixin
|
|
39
39
|
*/
|
|
40
40
|
const languageUtils_1 = require("../utils/languageUtils");
|
|
41
|
+
const debugUtils_1 = require("../shared/utils/debugUtils");
|
|
41
42
|
function OxyServicesLanguageMixin(Base) {
|
|
42
43
|
return class extends Base {
|
|
43
44
|
constructor(...args) {
|
|
@@ -50,7 +51,9 @@ function OxyServicesLanguageMixin(Base) {
|
|
|
50
51
|
const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
51
52
|
if (isReactNative) {
|
|
52
53
|
try {
|
|
53
|
-
|
|
54
|
+
// Variable indirection prevents bundlers (Vite, webpack) from statically resolving this
|
|
55
|
+
const moduleName = '@react-native-async-storage/async-storage';
|
|
56
|
+
const asyncStorageModule = await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
54
57
|
const storage = asyncStorageModule.default;
|
|
55
58
|
return {
|
|
56
59
|
getItem: storage.getItem.bind(storage),
|
|
@@ -113,7 +116,7 @@ function OxyServicesLanguageMixin(Base) {
|
|
|
113
116
|
return null;
|
|
114
117
|
}
|
|
115
118
|
catch (error) {
|
|
116
|
-
if (
|
|
119
|
+
if ((0, debugUtils_1.isDev)()) {
|
|
117
120
|
console.warn('Failed to get current language:', error);
|
|
118
121
|
}
|
|
119
122
|
return null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OxyServicesPrivacyMixin = OxyServicesPrivacyMixin;
|
|
4
|
+
const debugUtils_1 = require("../shared/utils/debugUtils");
|
|
4
5
|
function OxyServicesPrivacyMixin(Base) {
|
|
5
6
|
return class extends Base {
|
|
6
7
|
constructor(...args) {
|
|
@@ -28,7 +29,7 @@ function OxyServicesPrivacyMixin(Base) {
|
|
|
28
29
|
}
|
|
29
30
|
catch (error) {
|
|
30
31
|
// If there's an error, assume not in list to avoid breaking functionality
|
|
31
|
-
if (
|
|
32
|
+
if ((0, debugUtils_1.isDev)()) {
|
|
32
33
|
console.warn('Error checking user list:', error);
|
|
33
34
|
}
|
|
34
35
|
return false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OxyServicesSecurityMixin = OxyServicesSecurityMixin;
|
|
4
|
+
const debugUtils_1 = require("../shared/utils/debugUtils");
|
|
4
5
|
function OxyServicesSecurityMixin(Base) {
|
|
5
6
|
return class extends Base {
|
|
6
7
|
constructor(...args) {
|
|
@@ -55,7 +56,7 @@ function OxyServicesSecurityMixin(Base) {
|
|
|
55
56
|
catch (error) {
|
|
56
57
|
// Don't throw - logging failures shouldn't break user flow
|
|
57
58
|
// But log for monitoring
|
|
58
|
-
if (
|
|
59
|
+
if ((0, debugUtils_1.isDev)()) {
|
|
59
60
|
console.warn('[OxyServices] Failed to log private key exported event:', error);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -72,7 +73,7 @@ function OxyServicesSecurityMixin(Base) {
|
|
|
72
73
|
catch (error) {
|
|
73
74
|
// Don't throw - logging failures shouldn't break user flow
|
|
74
75
|
// But log for monitoring
|
|
75
|
-
if (
|
|
76
|
+
if ((0, debugUtils_1.isDev)()) {
|
|
76
77
|
console.warn('[OxyServices] Failed to log backup created event:', error);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
@@ -13,7 +13,14 @@ exports.createDebugLogger = exports.debugError = exports.debugWarn = exports.deb
|
|
|
13
13
|
* Check if running in development mode
|
|
14
14
|
*/
|
|
15
15
|
const isDev = () => {
|
|
16
|
-
|
|
16
|
+
if (typeof __DEV__ !== 'undefined')
|
|
17
|
+
return __DEV__;
|
|
18
|
+
try {
|
|
19
|
+
return typeof process !== 'undefined' && process.env?.NODE_ENV === 'development';
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
17
24
|
};
|
|
18
25
|
exports.isDev = isDev;
|
|
19
26
|
/**
|
|
@@ -51,7 +51,9 @@ class DeviceManager {
|
|
|
51
51
|
static async getStorage() {
|
|
52
52
|
if (this.isReactNative()) {
|
|
53
53
|
try {
|
|
54
|
-
|
|
54
|
+
// Variable indirection prevents bundlers (Vite, webpack) from statically resolving this
|
|
55
|
+
const moduleName = '@react-native-async-storage/async-storage';
|
|
56
|
+
const asyncStorageModule = await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
55
57
|
const storage = asyncStorageModule.default;
|
|
56
58
|
return {
|
|
57
59
|
getItem: storage.getItem.bind(storage),
|
|
@@ -134,8 +134,9 @@ async function initPlatformFromReactNative() {
|
|
|
134
134
|
return; // Already initialized
|
|
135
135
|
}
|
|
136
136
|
try {
|
|
137
|
-
//
|
|
138
|
-
const
|
|
137
|
+
// Variable indirection prevents bundlers (Vite, webpack) from statically resolving this
|
|
138
|
+
const moduleName = 'react-native';
|
|
139
|
+
const { Platform } = await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
139
140
|
setPlatformOS(Platform.OS);
|
|
140
141
|
}
|
|
141
142
|
catch {
|
package/dist/esm/AuthManager.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module core/AuthManager
|
|
8
8
|
*/
|
|
9
|
+
import { retryAsync } from './utils/asyncUtils';
|
|
9
10
|
/**
|
|
10
11
|
* Storage keys used by AuthManager.
|
|
11
12
|
*/
|
|
@@ -206,19 +207,28 @@ export class AuthManager {
|
|
|
206
207
|
return false;
|
|
207
208
|
}
|
|
208
209
|
try {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
await retryAsync(async () => {
|
|
211
|
+
const httpService = this.oxyServices.httpService;
|
|
212
|
+
const response = await httpService.request({
|
|
213
|
+
method: 'POST',
|
|
214
|
+
url: '/api/auth/refresh',
|
|
215
|
+
data: { refreshToken },
|
|
216
|
+
cache: false,
|
|
217
|
+
});
|
|
218
|
+
await this.handleAuthSuccess(response, 'credentials');
|
|
219
|
+
}, 2, // 2 retries = 3 total attempts
|
|
220
|
+
1000, // 1s base delay with exponential backoff + jitter
|
|
221
|
+
(error) => {
|
|
222
|
+
// Don't retry on 4xx client errors (invalid/revoked token)
|
|
223
|
+
const status = error?.status ?? error?.response?.status;
|
|
224
|
+
if (status && status >= 400 && status < 500)
|
|
225
|
+
return false;
|
|
226
|
+
return true;
|
|
216
227
|
});
|
|
217
|
-
await this.handleAuthSuccess(response, 'credentials');
|
|
218
228
|
return true;
|
|
219
229
|
}
|
|
220
230
|
catch {
|
|
221
|
-
//
|
|
231
|
+
// All retry attempts exhausted, clear session
|
|
222
232
|
await this.clearSession();
|
|
223
233
|
this.currentUser = null;
|
|
224
234
|
this.notifyListeners();
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
12
|
* ```typescript
|
|
13
|
-
* import { CrossDomainAuth } from '@oxyhq/
|
|
13
|
+
* import { CrossDomainAuth } from '@oxyhq/core';
|
|
14
14
|
*
|
|
15
15
|
* const auth = new CrossDomainAuth(oxyServices);
|
|
16
16
|
*
|
|
@@ -233,7 +233,7 @@ export class CrossDomainAuth {
|
|
|
233
233
|
*
|
|
234
234
|
* @example
|
|
235
235
|
* ```typescript
|
|
236
|
-
* import { createCrossDomainAuth } from '@oxyhq/
|
|
236
|
+
* import { createCrossDomainAuth } from '@oxyhq/core';
|
|
237
237
|
*
|
|
238
238
|
* const oxyServices = new OxyServices({ baseURL: 'https://api.oxy.so' });
|
|
239
239
|
* const auth = createCrossDomainAuth(oxyServices);
|
package/dist/esm/HttpService.js
CHANGED
|
@@ -16,6 +16,7 @@ import { TTLCache, registerCacheForCleanup } from './utils/cache';
|
|
|
16
16
|
import { RequestDeduplicator, RequestQueue, SimpleLogger } from './utils/requestUtils';
|
|
17
17
|
import { retryAsync } from './utils/asyncUtils';
|
|
18
18
|
import { handleHttpError } from './utils/errorUtils';
|
|
19
|
+
import { isDev } from './shared/utils/debugUtils';
|
|
19
20
|
import { jwtDecode } from 'jwt-decode';
|
|
20
21
|
import { isNative, getPlatformOS } from './utils/platform';
|
|
21
22
|
/**
|
|
@@ -186,7 +187,7 @@ export class HttpService {
|
|
|
186
187
|
headers['X-Native-App'] = 'true';
|
|
187
188
|
}
|
|
188
189
|
// Debug logging for CSRF issues
|
|
189
|
-
if (isStateChangingMethod &&
|
|
190
|
+
if (isStateChangingMethod && isDev()) {
|
|
190
191
|
console.log('[HttpService] CSRF Debug:', {
|
|
191
192
|
url,
|
|
192
193
|
method,
|
|
@@ -370,20 +371,20 @@ export class HttpService {
|
|
|
370
371
|
// Return cached token if available
|
|
371
372
|
const cachedToken = this.tokenStore.getCsrfToken();
|
|
372
373
|
if (cachedToken) {
|
|
373
|
-
if (
|
|
374
|
+
if (isDev())
|
|
374
375
|
console.log('[HttpService] Using cached CSRF token');
|
|
375
376
|
return cachedToken;
|
|
376
377
|
}
|
|
377
378
|
// Deduplicate concurrent CSRF token fetches
|
|
378
379
|
const existingPromise = this.tokenStore.getCsrfTokenFetchPromise();
|
|
379
380
|
if (existingPromise) {
|
|
380
|
-
if (
|
|
381
|
+
if (isDev())
|
|
381
382
|
console.log('[HttpService] Waiting for existing CSRF fetch');
|
|
382
383
|
return existingPromise;
|
|
383
384
|
}
|
|
384
385
|
const fetchPromise = (async () => {
|
|
385
386
|
try {
|
|
386
|
-
if (
|
|
387
|
+
if (isDev())
|
|
387
388
|
console.log('[HttpService] Fetching CSRF token from:', `${this.baseURL}/api/csrf-token`);
|
|
388
389
|
// Use AbortController for timeout (more compatible than AbortSignal.timeout)
|
|
389
390
|
const controller = new AbortController();
|
|
@@ -395,11 +396,11 @@ export class HttpService {
|
|
|
395
396
|
signal: controller.signal,
|
|
396
397
|
});
|
|
397
398
|
clearTimeout(timeoutId);
|
|
398
|
-
if (
|
|
399
|
+
if (isDev())
|
|
399
400
|
console.log('[HttpService] CSRF fetch response:', response.status, response.ok);
|
|
400
401
|
if (response.ok) {
|
|
401
402
|
const data = await response.json();
|
|
402
|
-
if (
|
|
403
|
+
if (isDev())
|
|
403
404
|
console.log('[HttpService] CSRF response data:', data);
|
|
404
405
|
const token = data.csrfToken || null;
|
|
405
406
|
this.tokenStore.setCsrfToken(token);
|
|
@@ -413,13 +414,13 @@ export class HttpService {
|
|
|
413
414
|
this.logger.debug('CSRF token from header');
|
|
414
415
|
return headerToken;
|
|
415
416
|
}
|
|
416
|
-
if (
|
|
417
|
+
if (isDev())
|
|
417
418
|
console.log('[HttpService] CSRF fetch failed with status:', response.status);
|
|
418
419
|
this.logger.warn('Failed to fetch CSRF token:', response.status);
|
|
419
420
|
return null;
|
|
420
421
|
}
|
|
421
422
|
catch (error) {
|
|
422
|
-
if (
|
|
423
|
+
if (isDev())
|
|
423
424
|
console.log('[HttpService] CSRF fetch error:', error);
|
|
424
425
|
this.logger.warn('CSRF token fetch error:', error);
|
|
425
426
|
return null;
|
|
@@ -12,6 +12,8 @@ import { OxyAuthenticationError, OxyAuthenticationTimeoutError } from './OxyServ
|
|
|
12
12
|
*/
|
|
13
13
|
export class OxyServicesBase {
|
|
14
14
|
constructor(...args) {
|
|
15
|
+
/** @internal */ this._cachedUserId = undefined;
|
|
16
|
+
/** @internal */ this._cachedAccessToken = null;
|
|
15
17
|
const config = args[0];
|
|
16
18
|
if (!config || typeof config !== 'object') {
|
|
17
19
|
throw new Error('OxyConfig is required');
|
|
@@ -95,20 +97,31 @@ export class OxyServicesBase {
|
|
|
95
97
|
*/
|
|
96
98
|
clearTokens() {
|
|
97
99
|
this.httpService.clearTokens();
|
|
100
|
+
this._cachedUserId = undefined;
|
|
101
|
+
this._cachedAccessToken = null;
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
100
|
-
* Get the current user ID from the access token
|
|
104
|
+
* Get the current user ID from the access token.
|
|
105
|
+
* Caches the decoded value and invalidates when the token changes.
|
|
101
106
|
*/
|
|
102
107
|
getCurrentUserId() {
|
|
103
108
|
const accessToken = this.httpService.getAccessToken();
|
|
109
|
+
// Return cached value if token hasn't changed
|
|
110
|
+
if (accessToken === this._cachedAccessToken && this._cachedUserId !== undefined) {
|
|
111
|
+
return this._cachedUserId;
|
|
112
|
+
}
|
|
113
|
+
this._cachedAccessToken = accessToken;
|
|
104
114
|
if (!accessToken) {
|
|
115
|
+
this._cachedUserId = null;
|
|
105
116
|
return null;
|
|
106
117
|
}
|
|
107
118
|
try {
|
|
108
119
|
const decoded = jwtDecode(accessToken);
|
|
109
|
-
|
|
120
|
+
this._cachedUserId = decoded.userId || decoded.id || null;
|
|
121
|
+
return this._cachedUserId;
|
|
110
122
|
}
|
|
111
|
-
catch
|
|
123
|
+
catch {
|
|
124
|
+
this._cachedUserId = null;
|
|
112
125
|
return null;
|
|
113
126
|
}
|
|
114
127
|
}
|