@proveanything/smartlinks-auth-ui 0.5.15 → 0.5.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/dist/components/SmartlinksAuthUI.d.ts.map +1 -1
- package/dist/index.esm.js +54 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +54 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAcpE,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAcpE,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AA2V7I,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CAqBjD,CAAC;AAqDF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAI/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA4rE5D,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -13088,8 +13088,48 @@ const useAuth = () => {
|
|
|
13088
13088
|
};
|
|
13089
13089
|
|
|
13090
13090
|
// VERSION: Update this when making changes to help identify which version is running
|
|
13091
|
-
const AUTH_UI_VERSION = '
|
|
13091
|
+
const AUTH_UI_VERSION = '47';
|
|
13092
13092
|
const LOG_PREFIX = `[SmartlinksAuthUI:v${AUTH_UI_VERSION}]`;
|
|
13093
|
+
const PERMANENT_WHATSAPP_EXCHANGE_ERROR_CODES = new Set([
|
|
13094
|
+
'TOKEN_ALREADY_USED',
|
|
13095
|
+
'SESSION_ALREADY_USED',
|
|
13096
|
+
'WHATSAPP_SESSION_ALREADY_USED',
|
|
13097
|
+
'INVALID_TOKEN',
|
|
13098
|
+
'TOKEN_EXPIRED',
|
|
13099
|
+
'INVALID_SESSION',
|
|
13100
|
+
'SESSION_EXPIRED',
|
|
13101
|
+
'SESSION_NOT_FOUND',
|
|
13102
|
+
]);
|
|
13103
|
+
const getExchangeErrorCode = (error) => {
|
|
13104
|
+
if (!error || typeof error !== 'object')
|
|
13105
|
+
return undefined;
|
|
13106
|
+
const err = error;
|
|
13107
|
+
return err.errorCode || err.details?.errorCode || err.details?.error || err.response?.data?.errorCode || err.response?.data?.error;
|
|
13108
|
+
};
|
|
13109
|
+
const getExchangeErrorStatus = (error) => {
|
|
13110
|
+
if (!error || typeof error !== 'object')
|
|
13111
|
+
return undefined;
|
|
13112
|
+
const err = error;
|
|
13113
|
+
return err.statusCode || err.status || err.response?.status;
|
|
13114
|
+
};
|
|
13115
|
+
const getExchangeErrorMessage = (error) => {
|
|
13116
|
+
if (error instanceof Error)
|
|
13117
|
+
return error.message || '';
|
|
13118
|
+
if (!error || typeof error !== 'object')
|
|
13119
|
+
return '';
|
|
13120
|
+
const err = error;
|
|
13121
|
+
return err.message || err.details?.message || err.response?.data?.message || '';
|
|
13122
|
+
};
|
|
13123
|
+
const isPermanentWhatsAppExchangeError = (error) => {
|
|
13124
|
+
const errorCode = getExchangeErrorCode(error)?.toUpperCase();
|
|
13125
|
+
if (errorCode && PERMANENT_WHATSAPP_EXCHANGE_ERROR_CODES.has(errorCode)) {
|
|
13126
|
+
return true;
|
|
13127
|
+
}
|
|
13128
|
+
const status = getExchangeErrorStatus(error);
|
|
13129
|
+
const message = getExchangeErrorMessage(error).toLowerCase();
|
|
13130
|
+
const looksPermanentMessage = /(already used|already been used|session.*used|expired|invalid|not found|consumed)/i.test(message);
|
|
13131
|
+
return looksPermanentMessage && [400, 401, 404, 409, 410].includes(status ?? -1);
|
|
13132
|
+
};
|
|
13093
13133
|
// Normalize malformed query strings where a second '?' is used instead of '&'.
|
|
13094
13134
|
// Some host platforms append "?mode=...&token=..." to a URL that already has a "?pageId=...",
|
|
13095
13135
|
// resulting in "?pageId=xxx?mode=resetPassword&token=yyy". Convert any extra '?' to '&'
|
|
@@ -14791,6 +14831,10 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14791
14831
|
try {
|
|
14792
14832
|
await updatePendingWhatsAppSession({ exchangeStartedAt: Date.now() });
|
|
14793
14833
|
const session = await api.exchangeWhatsAppSession(send.token, send.sessionKey);
|
|
14834
|
+
const resultErrorMessage = getActionResultErrorMessage(session);
|
|
14835
|
+
if (resultErrorMessage) {
|
|
14836
|
+
throw Object.assign(new Error(resultErrorMessage), session);
|
|
14837
|
+
}
|
|
14794
14838
|
if (session?.token && session.user) {
|
|
14795
14839
|
await auth.login(session.token, session.user, session.accountData, true, getExpirationFromResponse(session));
|
|
14796
14840
|
if (!proxyMode) {
|
|
@@ -14803,6 +14847,15 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14803
14847
|
}
|
|
14804
14848
|
}
|
|
14805
14849
|
catch (err) {
|
|
14850
|
+
if (isPermanentWhatsAppExchangeError(err)) {
|
|
14851
|
+
log.warn('WhatsApp session exchange failed permanently; clearing stale pending session:', err);
|
|
14852
|
+
setAuthSuccess(false);
|
|
14853
|
+
setSuccessMessage(undefined);
|
|
14854
|
+
setError('This WhatsApp sign-in session has already been used or expired. Please start again.');
|
|
14855
|
+
setRestoredWhatsAppSend(null);
|
|
14856
|
+
await clearPendingWhatsAppSession();
|
|
14857
|
+
return true;
|
|
14858
|
+
}
|
|
14806
14859
|
const latestPending = await loadPendingWhatsAppSession();
|
|
14807
14860
|
if (!latestPending) {
|
|
14808
14861
|
return true;
|