@oxyhq/services 5.16.17 → 5.16.18
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/lib/commonjs/core/mixins/OxyServices.security.js +42 -0
- package/lib/commonjs/core/mixins/OxyServices.security.js.map +1 -1
- package/lib/commonjs/models/interfaces.js +2 -0
- package/lib/commonjs/models/interfaces.js.map +1 -1
- package/lib/commonjs/ui/components/FollowButton.js +19 -1
- package/lib/commonjs/ui/components/FollowButton.js.map +1 -1
- package/lib/commonjs/ui/components/GroupedItem.js +1 -27
- package/lib/commonjs/ui/components/GroupedItem.js.map +1 -1
- package/lib/commonjs/ui/components/Section.js +2 -1
- package/lib/commonjs/ui/components/Section.js.map +1 -1
- package/lib/commonjs/ui/components/SectionTitle.js +1 -2
- package/lib/commonjs/ui/components/SectionTitle.js.map +1 -1
- package/lib/commonjs/ui/components/fileManagement/FileViewer.js +3 -3
- package/lib/commonjs/ui/components/fileManagement/FileViewer.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +44 -6
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js +9 -2
- package/lib/commonjs/ui/context/hooks/useAuthOperations.js.map +1 -1
- package/lib/commonjs/ui/context/hooks/useDeviceManagement.js +1 -1
- package/lib/commonjs/ui/context/hooks/useLanguageManagement.js +1 -1
- package/lib/commonjs/ui/context/hooks/useSessionManagement.js +3 -3
- package/lib/commonjs/ui/context/hooks/useStorage.js +2 -2
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +1 -1
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useServicesQueries.js +1 -1
- package/lib/commonjs/ui/hooks/useSessionSocket.js +22 -7
- package/lib/commonjs/ui/hooks/useSessionSocket.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountCenterScreen.js +13 -13
- package/lib/commonjs/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js +17 -17
- package/lib/commonjs/ui/screens/AccountOverviewScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js +2 -2
- package/lib/commonjs/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js +10 -9
- package/lib/commonjs/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/AppInfoScreen.js +15 -15
- package/lib/commonjs/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/FeedbackScreen.js +1 -1
- package/lib/commonjs/ui/screens/FeedbackScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/FileManagementScreen.js +1 -1
- package/lib/commonjs/ui/screens/HelpSupportScreen.js +3 -3
- package/lib/commonjs/ui/screens/HelpSupportScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/HistoryViewScreen.js +2 -2
- package/lib/commonjs/ui/screens/HistoryViewScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/LanguageSelectorScreen.js +3 -1
- package/lib/commonjs/ui/screens/LanguageSelectorScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/LegalDocumentsScreen.js +4 -4
- package/lib/commonjs/ui/screens/LegalDocumentsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PaymentGatewayScreen.js +1 -1
- package/lib/commonjs/ui/screens/PaymentGatewayScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/PremiumSubscriptionScreen.js +1 -2
- package/lib/commonjs/ui/screens/PremiumSubscriptionScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/ProfileScreen.js +44 -16
- package/lib/commonjs/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/SavesCollectionsScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaAboutScreen.js +3 -1
- package/lib/commonjs/ui/screens/karma/KarmaAboutScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js +2 -2
- package/lib/commonjs/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/karma/KarmaRewardsScreen.js +8 -5
- package/lib/commonjs/ui/screens/karma/KarmaRewardsScreen.js.map +1 -1
- package/lib/commonjs/ui/utils/errorHandlers.js +49 -2
- package/lib/commonjs/ui/utils/errorHandlers.js.map +1 -1
- package/lib/commonjs/ui/utils/sessionHelpers.js +0 -2
- package/lib/commonjs/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/commonjs/utils/languageUtils.js +11 -11
- package/lib/commonjs/utils/languageUtils.js.map +1 -1
- package/lib/module/core/mixins/OxyServices.security.js +42 -0
- package/lib/module/core/mixins/OxyServices.security.js.map +1 -1
- package/lib/module/models/interfaces.js +2 -0
- package/lib/module/models/interfaces.js.map +1 -1
- package/lib/module/ui/components/FollowButton.js +19 -1
- package/lib/module/ui/components/FollowButton.js.map +1 -1
- package/lib/module/ui/components/GroupedItem.js +1 -29
- package/lib/module/ui/components/GroupedItem.js.map +1 -1
- package/lib/module/ui/components/Section.js +2 -1
- package/lib/module/ui/components/Section.js.map +1 -1
- package/lib/module/ui/components/SectionTitle.js +1 -2
- package/lib/module/ui/components/SectionTitle.js.map +1 -1
- package/lib/module/ui/components/fileManagement/FileViewer.js +3 -3
- package/lib/module/ui/components/fileManagement/FileViewer.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +45 -7
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/hooks/useAuthOperations.js +9 -2
- package/lib/module/ui/context/hooks/useAuthOperations.js.map +1 -1
- package/lib/module/ui/context/hooks/useDeviceManagement.js +1 -1
- package/lib/module/ui/context/hooks/useDeviceManagement.js.map +1 -1
- package/lib/module/ui/context/hooks/useLanguageManagement.js +1 -1
- package/lib/module/ui/context/hooks/useLanguageManagement.js.map +1 -1
- package/lib/module/ui/context/hooks/useSessionManagement.js +3 -3
- package/lib/module/ui/context/hooks/useSessionManagement.js.map +1 -1
- package/lib/module/ui/context/hooks/useStorage.js +2 -2
- package/lib/module/ui/context/hooks/useStorage.js.map +1 -1
- package/lib/module/ui/hooks/queries/useAccountQueries.js +1 -1
- package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/module/ui/hooks/queries/useServicesQueries.js +1 -1
- package/lib/module/ui/hooks/queries/useServicesQueries.js.map +1 -1
- package/lib/module/ui/hooks/useSessionSocket.js +22 -7
- package/lib/module/ui/hooks/useSessionSocket.js.map +1 -1
- package/lib/module/ui/screens/AccountCenterScreen.js +13 -13
- package/lib/module/ui/screens/AccountCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountOverviewScreen.js +17 -17
- package/lib/module/ui/screens/AccountOverviewScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSettingsScreen.js +2 -2
- package/lib/module/ui/screens/AccountSettingsScreen.js.map +1 -1
- package/lib/module/ui/screens/AccountSwitcherScreen.js +11 -10
- package/lib/module/ui/screens/AccountSwitcherScreen.js.map +1 -1
- package/lib/module/ui/screens/AppInfoScreen.js +15 -15
- package/lib/module/ui/screens/AppInfoScreen.js.map +1 -1
- package/lib/module/ui/screens/FeedbackScreen.js +1 -1
- package/lib/module/ui/screens/FeedbackScreen.js.map +1 -1
- package/lib/module/ui/screens/FileManagementScreen.js +1 -1
- package/lib/module/ui/screens/HelpSupportScreen.js +3 -3
- package/lib/module/ui/screens/HelpSupportScreen.js.map +1 -1
- package/lib/module/ui/screens/HistoryViewScreen.js +2 -2
- package/lib/module/ui/screens/HistoryViewScreen.js.map +1 -1
- package/lib/module/ui/screens/LanguageSelectorScreen.js +4 -2
- package/lib/module/ui/screens/LanguageSelectorScreen.js.map +1 -1
- package/lib/module/ui/screens/LegalDocumentsScreen.js +4 -4
- package/lib/module/ui/screens/LegalDocumentsScreen.js.map +1 -1
- package/lib/module/ui/screens/PaymentGatewayScreen.js +1 -1
- package/lib/module/ui/screens/PaymentGatewayScreen.js.map +1 -1
- package/lib/module/ui/screens/PremiumSubscriptionScreen.js +1 -2
- package/lib/module/ui/screens/PremiumSubscriptionScreen.js.map +1 -1
- package/lib/module/ui/screens/ProfileScreen.js +44 -16
- package/lib/module/ui/screens/ProfileScreen.js.map +1 -1
- package/lib/module/ui/screens/SavesCollectionsScreen.js.map +1 -1
- package/lib/module/ui/screens/karma/KarmaAboutScreen.js +3 -1
- package/lib/module/ui/screens/karma/KarmaAboutScreen.js.map +1 -1
- package/lib/module/ui/screens/karma/KarmaCenterScreen.js +3 -3
- package/lib/module/ui/screens/karma/KarmaCenterScreen.js.map +1 -1
- package/lib/module/ui/screens/karma/KarmaRewardsScreen.js +9 -6
- package/lib/module/ui/screens/karma/KarmaRewardsScreen.js.map +1 -1
- package/lib/module/ui/utils/errorHandlers.js +46 -0
- package/lib/module/ui/utils/errorHandlers.js.map +1 -1
- package/lib/module/ui/utils/sessionHelpers.js +0 -2
- package/lib/module/ui/utils/sessionHelpers.js.map +1 -1
- package/lib/module/utils/languageUtils.js +11 -11
- package/lib/module/utils/languageUtils.js.map +1 -1
- package/lib/typescript/core/mixins/OxyServices.security.d.ts +12 -0
- package/lib/typescript/core/mixins/OxyServices.security.d.ts.map +1 -1
- package/lib/typescript/core/mixins/index.d.ts +2 -0
- package/lib/typescript/core/mixins/index.d.ts.map +1 -1
- package/lib/typescript/models/interfaces.d.ts +1 -1
- package/lib/typescript/models/interfaces.d.ts.map +1 -1
- package/lib/typescript/ui/components/FollowButton.d.ts.map +1 -1
- package/lib/typescript/ui/components/GroupedItem.d.ts.map +1 -1
- package/lib/typescript/ui/components/Section.d.ts.map +1 -1
- package/lib/typescript/ui/components/SectionTitle.d.ts.map +1 -1
- package/lib/typescript/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts +1 -1
- package/lib/typescript/ui/context/hooks/useAuthOperations.d.ts.map +1 -1
- package/lib/typescript/ui/context/hooks/useLanguageManagement.d.ts +1 -1
- package/lib/typescript/ui/context/hooks/useLanguageManagement.d.ts.map +1 -1
- package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts +1 -1
- package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts.map +1 -1
- package/lib/typescript/ui/context/hooks/useStorage.d.ts +1 -1
- package/lib/typescript/ui/context/hooks/useStorage.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/useSessionSocket.d.ts.map +1 -1
- package/lib/typescript/ui/screens/LanguageSelectorScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/PremiumSubscriptionScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/ProfileScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/SavesCollectionsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/karma/KarmaAboutScreen.d.ts.map +1 -1
- package/lib/typescript/ui/screens/karma/KarmaRewardsScreen.d.ts.map +1 -1
- package/lib/typescript/ui/utils/errorHandlers.d.ts +5 -0
- package/lib/typescript/ui/utils/errorHandlers.d.ts.map +1 -1
- package/lib/typescript/ui/utils/sessionHelpers.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/mixins/OxyServices.security.ts +44 -0
- package/src/models/interfaces.ts +4 -0
- package/src/ui/components/FollowButton.tsx +19 -1
- package/src/ui/components/GroupedItem.tsx +1 -29
- package/src/ui/components/Section.tsx +1 -0
- package/src/ui/components/SectionTitle.tsx +0 -1
- package/src/ui/components/fileManagement/FileViewer.tsx +3 -3
- package/src/ui/context/OxyContext.tsx +30 -9
- package/src/ui/context/hooks/useAuthOperations.ts +16 -9
- package/src/ui/context/hooks/useDeviceManagement.ts +1 -1
- package/src/ui/context/hooks/useLanguageManagement.ts +2 -2
- package/src/ui/context/hooks/useSessionManagement.ts +3 -3
- package/src/ui/context/hooks/useStorage.ts +2 -2
- package/src/ui/hooks/queries/useAccountQueries.ts +1 -1
- package/src/ui/hooks/queries/useServicesQueries.ts +1 -1
- package/src/ui/hooks/useSessionSocket.ts +8 -7
- package/src/ui/screens/AccountCenterScreen.tsx +13 -13
- package/src/ui/screens/AccountOverviewScreen.tsx +17 -17
- package/src/ui/screens/AccountSettingsScreen.tsx +2 -2
- package/src/ui/screens/AccountSwitcherScreen.tsx +8 -8
- package/src/ui/screens/AppInfoScreen.tsx +15 -15
- package/src/ui/screens/FeedbackScreen.tsx +1 -1
- package/src/ui/screens/FileManagementScreen.tsx +1 -1
- package/src/ui/screens/HelpSupportScreen.tsx +3 -3
- package/src/ui/screens/HistoryViewScreen.tsx +2 -2
- package/src/ui/screens/LanguageSelectorScreen.tsx +4 -1
- package/src/ui/screens/LegalDocumentsScreen.tsx +4 -4
- package/src/ui/screens/PaymentGatewayScreen.tsx +1 -1
- package/src/ui/screens/PremiumSubscriptionScreen.tsx +0 -1
- package/src/ui/screens/ProfileScreen.tsx +61 -22
- package/src/ui/screens/SavesCollectionsScreen.tsx +10 -1
- package/src/ui/screens/karma/KarmaAboutScreen.tsx +8 -1
- package/src/ui/screens/karma/KarmaCenterScreen.tsx +2 -2
- package/src/ui/screens/karma/KarmaRewardsScreen.tsx +9 -6
- package/src/ui/utils/errorHandlers.ts +58 -0
- package/src/ui/utils/sessionHelpers.ts +0 -2
- package/src/utils/languageUtils.ts +11 -11
- package/lib/commonjs/ui/context/utils/errorHandlers.js +0 -100
- package/lib/commonjs/ui/context/utils/errorHandlers.js.map +0 -1
- package/lib/commonjs/ui/context/utils/sessionHelpers.js +0 -103
- package/lib/commonjs/ui/context/utils/sessionHelpers.js.map +0 -1
- package/lib/commonjs/ui/context/utils/storageHelpers.js +0 -119
- package/lib/commonjs/ui/context/utils/storageHelpers.js.map +0 -1
- package/lib/module/ui/context/utils/errorHandlers.js +0 -93
- package/lib/module/ui/context/utils/errorHandlers.js.map +0 -1
- package/lib/module/ui/context/utils/sessionHelpers.js +0 -96
- package/lib/module/ui/context/utils/sessionHelpers.js.map +0 -1
- package/lib/module/ui/context/utils/storageHelpers.js +0 -111
- package/lib/module/ui/context/utils/storageHelpers.js.map +0 -1
- package/lib/typescript/ui/context/utils/errorHandlers.d.ts +0 -30
- package/lib/typescript/ui/context/utils/errorHandlers.d.ts.map +0 -1
- package/lib/typescript/ui/context/utils/sessionHelpers.d.ts +0 -59
- package/lib/typescript/ui/context/utils/sessionHelpers.d.ts.map +0 -1
- package/lib/typescript/ui/context/utils/storageHelpers.d.ts +0 -31
- package/lib/typescript/ui/context/utils/storageHelpers.d.ts.map +0 -1
- package/src/ui/context/utils/errorHandlers.ts +0 -146
- package/src/ui/context/utils/sessionHelpers.ts +0 -146
- package/src/ui/context/utils/storageHelpers.ts +0 -134
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface StorageInterface {
|
|
2
|
-
getItem: (key: string) => Promise<string | null>;
|
|
3
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
4
|
-
removeItem: (key: string) => Promise<void>;
|
|
5
|
-
clear: () => Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
export interface SessionStorageKeys {
|
|
8
|
-
activeSessionId: string;
|
|
9
|
-
sessionIds: string;
|
|
10
|
-
language: string;
|
|
11
|
-
}
|
|
12
|
-
export interface CreateStorageOptions {
|
|
13
|
-
prefix?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Detect whether the current runtime is React Native.
|
|
17
|
-
*/
|
|
18
|
-
export declare const isReactNative: () => boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Create a platform-appropriate storage implementation.
|
|
21
|
-
* Defaults to in-memory storage when no platform storage is available.
|
|
22
|
-
*/
|
|
23
|
-
export declare const createPlatformStorage: () => Promise<StorageInterface>;
|
|
24
|
-
export declare const STORAGE_KEY_PREFIX = "oxy_session";
|
|
25
|
-
/**
|
|
26
|
-
* Produce strongly typed storage key names for the supplied prefix.
|
|
27
|
-
*
|
|
28
|
-
* @param prefix - Storage key prefix
|
|
29
|
-
*/
|
|
30
|
-
export declare const getStorageKeys: (prefix?: string) => SessionStorageKeys;
|
|
31
|
-
//# sourceMappingURL=storageHelpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storageHelpers.d.ts","sourceRoot":"","sources":["../../../../../src/ui/context/utils/storageHelpers.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACjD,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAuFD;;GAEG;AACH,eAAO,MAAM,aAAa,QAAO,OACwC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAa,OAAO,CAAC,gBAAgB,CAMtE,CAAC;AAEF,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,SAAQ,MAA2B,KAAG,kBAInE,CAAC"}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { ApiError } from '../../../models/interfaces';
|
|
2
|
-
|
|
3
|
-
type ErrorWithMessage = {
|
|
4
|
-
message?: string;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
type ErrorWithResponse = {
|
|
8
|
-
response?: {
|
|
9
|
-
status?: number;
|
|
10
|
-
data?: {
|
|
11
|
-
message?: string;
|
|
12
|
-
error?: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export interface HandleAuthErrorOptions {
|
|
18
|
-
defaultMessage: string;
|
|
19
|
-
code: string;
|
|
20
|
-
status?: number;
|
|
21
|
-
onError?: (error: ApiError) => void;
|
|
22
|
-
setAuthError?: (message: string) => void;
|
|
23
|
-
logger?: (message: string, error?: unknown) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const DEFAULT_INVALID_SESSION_MESSAGES = [
|
|
27
|
-
'Invalid or expired session',
|
|
28
|
-
'Session is invalid',
|
|
29
|
-
'Session not found',
|
|
30
|
-
'Session expired',
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
const isObject = (value: unknown): value is Record<string, unknown> =>
|
|
34
|
-
typeof value === 'object' && value !== null;
|
|
35
|
-
|
|
36
|
-
const getResponseStatus = (error: unknown): number | undefined => {
|
|
37
|
-
if (!isObject(error)) return undefined;
|
|
38
|
-
const response = (error as ErrorWithResponse).response;
|
|
39
|
-
return response?.status;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Determine whether the error represents an invalid session condition.
|
|
44
|
-
* This centralizes 401 detection across different fetch clients.
|
|
45
|
-
*/
|
|
46
|
-
export const isInvalidSessionError = (error: unknown): boolean => {
|
|
47
|
-
const status = getResponseStatus(error);
|
|
48
|
-
if (status === 401) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!isObject(error)) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Check error.status directly (HttpService sets this)
|
|
57
|
-
if ((error as any).status === 401) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const normalizedMessage = extractErrorMessage(error)?.toLowerCase();
|
|
62
|
-
if (!normalizedMessage) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Check for HTTP 401 in message (HttpService creates errors with "HTTP 401:" format)
|
|
67
|
-
if (normalizedMessage.includes('http 401') || normalizedMessage.includes('401')) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return DEFAULT_INVALID_SESSION_MESSAGES.some((msg) =>
|
|
72
|
-
normalizedMessage.includes(msg.toLowerCase()),
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Extract a consistent error message from unknown error shapes.
|
|
78
|
-
*
|
|
79
|
-
* @param error - The unknown error payload
|
|
80
|
-
* @param fallbackMessage - Message to return when no concrete message is available
|
|
81
|
-
*/
|
|
82
|
-
export const extractErrorMessage = (
|
|
83
|
-
error: unknown,
|
|
84
|
-
fallbackMessage = 'Unexpected error',
|
|
85
|
-
): string => {
|
|
86
|
-
if (typeof error === 'string' && error.trim().length > 0) {
|
|
87
|
-
return error;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!isObject(error)) {
|
|
91
|
-
return fallbackMessage;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const withMessage = error as ErrorWithMessage;
|
|
95
|
-
if (withMessage.message && withMessage.message.trim().length > 0) {
|
|
96
|
-
return withMessage.message;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const withResponse = error as ErrorWithResponse;
|
|
100
|
-
const responseMessage =
|
|
101
|
-
withResponse.response?.data?.message ?? withResponse.response?.data?.error;
|
|
102
|
-
|
|
103
|
-
if (typeof responseMessage === 'string' && responseMessage.trim().length > 0) {
|
|
104
|
-
return responseMessage;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return fallbackMessage;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Centralized error handler for auth-related operations.
|
|
112
|
-
*
|
|
113
|
-
* @param error - Unknown error object
|
|
114
|
-
* @param options - Error handling configuration
|
|
115
|
-
* @returns Resolved error message
|
|
116
|
-
*/
|
|
117
|
-
export const handleAuthError = (
|
|
118
|
-
error: unknown,
|
|
119
|
-
{
|
|
120
|
-
defaultMessage,
|
|
121
|
-
code,
|
|
122
|
-
status,
|
|
123
|
-
onError,
|
|
124
|
-
setAuthError,
|
|
125
|
-
logger,
|
|
126
|
-
}: HandleAuthErrorOptions,
|
|
127
|
-
): string => {
|
|
128
|
-
const resolvedStatus = status ?? getResponseStatus(error) ?? (isInvalidSessionError(error) ? 401 : 500);
|
|
129
|
-
const message = extractErrorMessage(error, defaultMessage);
|
|
130
|
-
|
|
131
|
-
if (logger) {
|
|
132
|
-
logger(message, error);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
setAuthError?.(message);
|
|
136
|
-
|
|
137
|
-
onError?.({
|
|
138
|
-
message,
|
|
139
|
-
code,
|
|
140
|
-
status: resolvedStatus,
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
return message;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import type { OxyServices } from '../../../core';
|
|
2
|
-
import type { ClientSession } from '../../../models/session';
|
|
3
|
-
|
|
4
|
-
interface DeviceSession {
|
|
5
|
-
sessionId: string;
|
|
6
|
-
deviceId?: string;
|
|
7
|
-
deviceName?: string;
|
|
8
|
-
expiresAt?: string;
|
|
9
|
-
lastActive?: string;
|
|
10
|
-
user?: { id?: string; _id?: { toString(): string } };
|
|
11
|
-
userId?: string;
|
|
12
|
-
isCurrent?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface FetchSessionsWithFallbackOptions {
|
|
16
|
-
fallbackDeviceId?: string;
|
|
17
|
-
fallbackUserId?: string;
|
|
18
|
-
logger?: (message: string, error?: unknown) => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ValidateSessionBatchOptions {
|
|
22
|
-
useHeaderValidation?: boolean;
|
|
23
|
-
maxConcurrency?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface SessionValidationResult {
|
|
27
|
-
sessionId: string;
|
|
28
|
-
valid: boolean;
|
|
29
|
-
user?: unknown;
|
|
30
|
-
raw?: unknown;
|
|
31
|
-
error?: unknown;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Normalize backend session payloads into `ClientSession` objects.
|
|
36
|
-
*
|
|
37
|
-
* @param sessions - Raw session array returned from the API
|
|
38
|
-
* @param fallbackDeviceId - Device identifier to use when missing from payload
|
|
39
|
-
* @param fallbackUserId - User identifier to use when missing from payload
|
|
40
|
-
*/
|
|
41
|
-
export const mapSessionsToClient = (
|
|
42
|
-
sessions: DeviceSession[],
|
|
43
|
-
fallbackDeviceId?: string,
|
|
44
|
-
fallbackUserId?: string,
|
|
45
|
-
): ClientSession[] => {
|
|
46
|
-
const now = new Date();
|
|
47
|
-
|
|
48
|
-
return sessions.map((session) => ({
|
|
49
|
-
sessionId: session.sessionId,
|
|
50
|
-
deviceId: session.deviceId || fallbackDeviceId || '',
|
|
51
|
-
expiresAt: session.expiresAt || new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000).toISOString(),
|
|
52
|
-
lastActive: session.lastActive || now.toISOString(),
|
|
53
|
-
userId:
|
|
54
|
-
session.user?.id ||
|
|
55
|
-
session.userId ||
|
|
56
|
-
(session.user?._id ? session.user._id.toString() : undefined) ||
|
|
57
|
-
fallbackUserId ||
|
|
58
|
-
'',
|
|
59
|
-
isCurrent: Boolean(session.isCurrent),
|
|
60
|
-
}));
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Fetch device sessions with fallback to the legacy session endpoint when needed.
|
|
65
|
-
*
|
|
66
|
-
* @param oxyServices - Oxy service instance
|
|
67
|
-
* @param sessionId - Session identifier to fetch
|
|
68
|
-
* @param options - Optional fallback options
|
|
69
|
-
*/
|
|
70
|
-
export const fetchSessionsWithFallback = async (
|
|
71
|
-
oxyServices: Pick<OxyServices, 'getDeviceSessions' | 'getSessionsBySessionId'>,
|
|
72
|
-
sessionId: string,
|
|
73
|
-
{
|
|
74
|
-
fallbackDeviceId,
|
|
75
|
-
fallbackUserId,
|
|
76
|
-
logger,
|
|
77
|
-
}: FetchSessionsWithFallbackOptions = {},
|
|
78
|
-
): Promise<ClientSession[]> => {
|
|
79
|
-
try {
|
|
80
|
-
const deviceSessions = await oxyServices.getDeviceSessions(sessionId);
|
|
81
|
-
return mapSessionsToClient(deviceSessions, fallbackDeviceId, fallbackUserId);
|
|
82
|
-
} catch (error) {
|
|
83
|
-
if (__DEV__ && logger) {
|
|
84
|
-
logger('Failed to get device sessions, falling back to user sessions', error);
|
|
85
|
-
} else if (__DEV__) {
|
|
86
|
-
console.warn('Failed to get device sessions, falling back to user sessions:', error);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const userSessions = await oxyServices.getSessionsBySessionId(sessionId);
|
|
90
|
-
return mapSessionsToClient(userSessions, fallbackDeviceId, fallbackUserId);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Validate multiple sessions concurrently with configurable concurrency.
|
|
96
|
-
*
|
|
97
|
-
* @param oxyServices - Oxy service instance
|
|
98
|
-
* @param sessionIds - Session identifiers to validate
|
|
99
|
-
* @param options - Validation options
|
|
100
|
-
*/
|
|
101
|
-
export const validateSessionBatch = async (
|
|
102
|
-
oxyServices: Pick<OxyServices, 'validateSession'>,
|
|
103
|
-
sessionIds: string[],
|
|
104
|
-
{ useHeaderValidation = true, maxConcurrency = 5 }: ValidateSessionBatchOptions = {},
|
|
105
|
-
): Promise<SessionValidationResult[]> => {
|
|
106
|
-
if (!sessionIds.length) {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const uniqueSessionIds = Array.from(new Set(sessionIds));
|
|
111
|
-
const safeConcurrency = Math.max(1, Math.min(maxConcurrency, uniqueSessionIds.length));
|
|
112
|
-
const results: SessionValidationResult[] = [];
|
|
113
|
-
let index = 0;
|
|
114
|
-
|
|
115
|
-
const worker = async () => {
|
|
116
|
-
while (index < uniqueSessionIds.length) {
|
|
117
|
-
const currentIndex = index;
|
|
118
|
-
index += 1;
|
|
119
|
-
const sessionId = uniqueSessionIds[currentIndex];
|
|
120
|
-
|
|
121
|
-
try {
|
|
122
|
-
const validation = await oxyServices.validateSession(sessionId, { useHeaderValidation });
|
|
123
|
-
const valid = Boolean(validation?.valid);
|
|
124
|
-
|
|
125
|
-
results.push({
|
|
126
|
-
sessionId,
|
|
127
|
-
valid,
|
|
128
|
-
user: validation?.user,
|
|
129
|
-
raw: validation,
|
|
130
|
-
});
|
|
131
|
-
} catch (error) {
|
|
132
|
-
results.push({
|
|
133
|
-
sessionId,
|
|
134
|
-
valid: false,
|
|
135
|
-
error,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
await Promise.all(Array.from({ length: safeConcurrency }, worker));
|
|
142
|
-
|
|
143
|
-
return results;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
export interface StorageInterface {
|
|
2
|
-
getItem: (key: string) => Promise<string | null>;
|
|
3
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
4
|
-
removeItem: (key: string) => Promise<void>;
|
|
5
|
-
clear: () => Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface SessionStorageKeys {
|
|
9
|
-
activeSessionId: string;
|
|
10
|
-
sessionIds: string;
|
|
11
|
-
language: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface CreateStorageOptions {
|
|
15
|
-
prefix?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create an in-memory storage implementation used as a safe fallback.
|
|
20
|
-
*/
|
|
21
|
-
const MEMORY_STORAGE = (): StorageInterface => {
|
|
22
|
-
const store = new Map<string, string>();
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
async getItem(key: string) {
|
|
26
|
-
return store.has(key) ? store.get(key)! : null;
|
|
27
|
-
},
|
|
28
|
-
async setItem(key: string, value: string) {
|
|
29
|
-
store.set(key, value);
|
|
30
|
-
},
|
|
31
|
-
async removeItem(key: string) {
|
|
32
|
-
store.delete(key);
|
|
33
|
-
},
|
|
34
|
-
async clear() {
|
|
35
|
-
store.clear();
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Create a web storage implementation backed by `localStorage`.
|
|
42
|
-
* Falls back to in-memory storage when unavailable.
|
|
43
|
-
*/
|
|
44
|
-
const createWebStorage = (): StorageInterface => {
|
|
45
|
-
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
|
|
46
|
-
return MEMORY_STORAGE();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
async getItem(key: string) {
|
|
51
|
-
try {
|
|
52
|
-
return window.localStorage.getItem(key);
|
|
53
|
-
} catch {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
async setItem(key: string, value: string) {
|
|
58
|
-
try {
|
|
59
|
-
window.localStorage.setItem(key, value);
|
|
60
|
-
} catch {
|
|
61
|
-
// Ignore quota or access issues for now.
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
async removeItem(key: string) {
|
|
65
|
-
try {
|
|
66
|
-
window.localStorage.removeItem(key);
|
|
67
|
-
} catch {
|
|
68
|
-
// Ignore failures.
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
async clear() {
|
|
72
|
-
try {
|
|
73
|
-
window.localStorage.clear();
|
|
74
|
-
} catch {
|
|
75
|
-
// Ignore failures.
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
let asyncStorageInstance: StorageInterface | null = null;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Lazily import React Native AsyncStorage implementation.
|
|
85
|
-
*/
|
|
86
|
-
const createNativeStorage = async (): Promise<StorageInterface> => {
|
|
87
|
-
if (asyncStorageInstance) {
|
|
88
|
-
return asyncStorageInstance;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
const asyncStorageModule = await import('@react-native-async-storage/async-storage');
|
|
93
|
-
asyncStorageInstance = asyncStorageModule.default as unknown as StorageInterface;
|
|
94
|
-
return asyncStorageInstance;
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (__DEV__) {
|
|
97
|
-
console.error('Failed to import AsyncStorage:', error);
|
|
98
|
-
}
|
|
99
|
-
throw new Error('AsyncStorage is required in React Native environment');
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Detect whether the current runtime is React Native.
|
|
105
|
-
*/
|
|
106
|
-
export const isReactNative = (): boolean =>
|
|
107
|
-
typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Create a platform-appropriate storage implementation.
|
|
111
|
-
* Defaults to in-memory storage when no platform storage is available.
|
|
112
|
-
*/
|
|
113
|
-
export const createPlatformStorage = async (): Promise<StorageInterface> => {
|
|
114
|
-
if (isReactNative()) {
|
|
115
|
-
return createNativeStorage();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return createWebStorage();
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
export const STORAGE_KEY_PREFIX = 'oxy_session';
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Produce strongly typed storage key names for the supplied prefix.
|
|
125
|
-
*
|
|
126
|
-
* @param prefix - Storage key prefix
|
|
127
|
-
*/
|
|
128
|
-
export const getStorageKeys = (prefix: string = STORAGE_KEY_PREFIX): SessionStorageKeys => ({
|
|
129
|
-
activeSessionId: `${prefix}_active_session_id`,
|
|
130
|
-
sessionIds: `${prefix}_session_ids`,
|
|
131
|
-
language: `${prefix}_language`,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
|