@oxyhq/services 0.0.85 → 0.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/README.md +269 -79
- package/dist/components/AuthBottomSheet/types.d.ts +24 -0
- package/dist/components/AuthBottomSheet/types.js +2 -0
- package/dist/components/FileSelectorModal/types.d.ts +35 -0
- package/dist/components/FileSelectorModal/types.js +2 -0
- package/dist/components/SessionProvider.d.ts +26 -0
- package/dist/components/SessionProvider.js +367 -0
- package/dist/config.d.ts +169 -0
- package/dist/config.js +115 -0
- package/dist/constants.d.ts +54 -0
- package/dist/constants.js +61 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/index.js +23 -0
- package/dist/hooks/useAuth.d.ts +6 -0
- package/dist/hooks/useAuth.js +17 -0
- package/dist/hooks/useFiles.d.ts +10 -0
- package/dist/hooks/useFiles.js +329 -0
- package/dist/hooks/useProfile.d.ts +13 -0
- package/dist/hooks/useProfile.js +154 -0
- package/dist/hooks/useSession.d.ts +2 -0
- package/dist/hooks/useSession.js +12 -0
- package/dist/hooks/useSubscription.d.ts +15 -0
- package/dist/hooks/useSubscription.js +85 -0
- package/dist/index.d.ts +28 -7
- package/dist/index.js +82 -6
- package/dist/package.json +71 -0
- package/dist/reducers/index.d.ts +8 -0
- package/dist/reducers/index.js +29 -0
- package/dist/reducers/profileReducer.d.ts +55 -0
- package/dist/reducers/profileReducer.js +136 -0
- package/dist/services/OxyClient.d.ts +84 -0
- package/dist/services/OxyClient.js +309 -0
- package/dist/services/api.service.d.ts +61 -0
- package/dist/services/api.service.js +289 -0
- package/dist/services/auth.service.d.ts +87 -0
- package/dist/services/auth.service.js +266 -0
- package/dist/services/index.d.ts +30 -0
- package/dist/services/index.js +88 -0
- package/dist/services/payment.service.d.ts +20 -0
- package/dist/services/payment.service.js +56 -0
- package/dist/services/privacy.service.d.ts +16 -0
- package/dist/services/privacy.service.js +69 -0
- package/dist/services/profile.service.d.ts +20 -0
- package/dist/services/profile.service.js +158 -0
- package/dist/services/subscription.service.d.ts +7 -0
- package/dist/services/subscription.service.js +46 -0
- package/dist/services/user.service.d.ts +25 -0
- package/dist/services/user.service.js +109 -0
- package/dist/styles/colors.d.ts +24 -0
- package/dist/styles/colors.js +31 -0
- package/dist/styles/shared.d.ts +168 -0
- package/dist/styles/shared.js +177 -0
- package/dist/types/index.d.ts +136 -2
- package/dist/types/index.js +7 -1
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +546 -0
- package/dist/utils/authEvents.d.ts +44 -0
- package/dist/utils/authEvents.js +73 -0
- package/dist/utils/errorHandler.d.ts +68 -0
- package/dist/utils/errorHandler.js +166 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +41 -0
- package/dist/utils/logger.d.ts +100 -0
- package/dist/utils/logger.js +298 -0
- package/dist/utils/socket.d.ts +6 -0
- package/dist/utils/socket.js +179 -0
- package/dist/utils/socketConfig.d.ts +32 -0
- package/dist/utils/socketConfig.js +67 -0
- package/dist/utils/storage.d.ts +54 -0
- package/dist/utils/storage.js +253 -0
- package/package.json +71 -59
- package/dist/assets/dot-icon.d.ts +0 -3
- package/dist/assets/dot-icon.d.ts.map +0 -1
- package/dist/assets/dot-icon.js +0 -6
- package/dist/assets/verified-icon.d.ts +0 -3
- package/dist/assets/verified-icon.d.ts.map +0 -1
- package/dist/assets/verified-icon.js +0 -10
- package/dist/components/assets/oxy-logo.d.ts +0 -3
- package/dist/components/assets/oxy-logo.d.ts.map +0 -1
- package/dist/components/assets/oxy-logo.js +0 -30
- package/dist/components/auth/AccountSwitcherModal.d.ts +0 -7
- package/dist/components/auth/AccountSwitcherModal.d.ts.map +0 -1
- package/dist/components/auth/AccountSwitcherModal.js +0 -91
- package/dist/components/auth/SessionOwnerButton.d.ts +0 -3
- package/dist/components/auth/SessionOwnerButton.d.ts.map +0 -1
- package/dist/components/auth/SessionOwnerButton.js +0 -35
- package/dist/components/auth/SignInButton.d.ts +0 -8
- package/dist/components/auth/SignInButton.d.ts.map +0 -1
- package/dist/components/auth/SignInButton.js +0 -15
- package/dist/components/auth/styles/account-switcher-modal.module.css +0 -29
- package/dist/components/auth/styles/account-switcher-modal.module.css.map +0 -1
- package/dist/components/auth/styles/oavatar.module.css +0 -34
- package/dist/components/auth/styles/oavatar.module.css.map +0 -1
- package/dist/components/auth/styles/session-owner-modal.module.css +0 -35
- package/dist/components/auth/styles/session-owner-modal.module.css.map +0 -1
- package/dist/components/auth/styles/sign-in-button.module.css +0 -30
- package/dist/components/auth/styles/sign-in-button.module.css.map +0 -1
- package/dist/components/elements/button/components/button.d.ts +0 -7
- package/dist/components/elements/button/components/button.d.ts.map +0 -1
- package/dist/components/elements/button/components/button.js +0 -6
- package/dist/components/elements/button/components/styles/button.module.css +0 -25
- package/dist/components/elements/button/components/styles/button.module.css.map +0 -1
- package/dist/components/elements/button/index.d.ts +0 -2
- package/dist/components/elements/button/index.d.ts.map +0 -1
- package/dist/components/elements/button/index.js +0 -1
- package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.d.ts +0 -5
- package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.d.ts.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/components/EllipsisWrapper.js +0 -4
- package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.d.ts +0 -5
- package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.d.ts.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/components/ellipsis-wrapper.js +0 -4
- package/dist/components/elements/ellipsis-wrapper/components/styles/ellipses-wrapper.module.css +0 -11
- package/dist/components/elements/ellipsis-wrapper/components/styles/ellipses-wrapper.module.css.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/index.d.ts +0 -2
- package/dist/components/elements/ellipsis-wrapper/index.d.ts.map +0 -1
- package/dist/components/elements/ellipsis-wrapper/index.js +0 -1
- package/dist/components/elements/modal/components/confirmation-modal.d.ts +0 -12
- package/dist/components/elements/modal/components/confirmation-modal.d.ts.map +0 -1
- package/dist/components/elements/modal/components/confirmation-modal.js +0 -21
- package/dist/components/elements/modal/components/modal.d.ts +0 -13
- package/dist/components/elements/modal/components/modal.d.ts.map +0 -1
- package/dist/components/elements/modal/components/modal.js +0 -111
- package/dist/components/elements/modal/components/styles/confirmation-modal.module.css +0 -105
- package/dist/components/elements/modal/components/styles/confirmation-modal.module.css.map +0 -1
- package/dist/components/elements/modal/components/styles/modal.module.css +0 -10
- package/dist/components/elements/modal/components/styles/modal.module.css.map +0 -1
- package/dist/components/elements/modal/hooks/use-track-position.d.ts +0 -5
- package/dist/components/elements/modal/hooks/use-track-position.d.ts.map +0 -1
- package/dist/components/elements/modal/hooks/use-track-position.js +0 -35
- package/dist/components/elements/modal/index.d.ts +0 -4
- package/dist/components/elements/modal/index.d.ts.map +0 -1
- package/dist/components/elements/modal/index.js +0 -3
- package/dist/config/index.d.ts +0 -21
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -7
- package/dist/features/profile/components/avatar.d.ts +0 -10
- package/dist/features/profile/components/avatar.d.ts.map +0 -1
- package/dist/features/profile/components/avatar.js +0 -7
- package/dist/features/profile/components/styles/avatar.module.css +0 -15
- package/dist/features/profile/components/styles/avatar.module.css.map +0 -1
- package/dist/features/profile/components/styles/user-name.module.css +0 -18
- package/dist/features/profile/components/styles/user-name.module.css.map +0 -1
- package/dist/features/profile/components/styles/user-username.module.css +0 -6
- package/dist/features/profile/components/styles/user-username.module.css.map +0 -1
- package/dist/features/profile/components/user-name.d.ts +0 -7
- package/dist/features/profile/components/user-name.d.ts.map +0 -1
- package/dist/features/profile/components/user-name.js +0 -8
- package/dist/features/profile/components/user-username.d.ts +0 -5
- package/dist/features/profile/components/user-username.d.ts.map +0 -1
- package/dist/features/profile/components/user-username.js +0 -7
- package/dist/features/profile/index.d.ts +0 -4
- package/dist/features/profile/index.d.ts.map +0 -1
- package/dist/features/profile/index.js +0 -3
- package/dist/hooks/get-user.d.ts +0 -2
- package/dist/hooks/get-user.d.ts.map +0 -1
- package/dist/hooks/get-user.js +0 -31
- package/dist/hooks/getClientKey.d.ts +0 -2
- package/dist/hooks/getClientKey.d.ts.map +0 -1
- package/dist/hooks/getClientKey.js +0 -19
- package/dist/hooks/getUserById.d.ts +0 -11
- package/dist/hooks/getUserById.d.ts.map +0 -1
- package/dist/hooks/getUserById.js +0 -31
- package/dist/hooks/use-user.d.ts +0 -14
- package/dist/hooks/use-user.d.ts.map +0 -1
- package/dist/hooks/use-user.js +0 -8
- package/dist/hooks/useCrossDomainStorage.d.ts +0 -6
- package/dist/hooks/useCrossDomainStorage.d.ts.map +0 -1
- package/dist/hooks/useCrossDomainStorage.js +0 -24
- package/dist/hooks/useOxySession.d.ts +0 -30
- package/dist/hooks/useOxySession.d.ts.map +0 -1
- package/dist/hooks/useOxySession.js +0 -64
- package/dist/index.css +0 -5
- package/dist/index.css.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interfaces/index.d.ts +0 -10
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/utils/cn.d.ts +0 -3
- package/dist/utils/cn.d.ts.map +0 -1
- package/dist/utils/cn.js +0 -5
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handler Utility
|
|
3
|
+
*
|
|
4
|
+
* This utility provides centralized error handling and logging for the OxyHQ services module.
|
|
5
|
+
* It standardizes error formats, provides consistent logging, and helps with error recovery.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ErrorType {
|
|
8
|
+
NETWORK = "network",
|
|
9
|
+
AUTHENTICATION = "authentication",
|
|
10
|
+
AUTHORIZATION = "authorization",
|
|
11
|
+
VALIDATION = "validation",
|
|
12
|
+
SERVER = "server",
|
|
13
|
+
CLIENT = "client",
|
|
14
|
+
UNKNOWN = "unknown"
|
|
15
|
+
}
|
|
16
|
+
export interface StandardError {
|
|
17
|
+
message: string;
|
|
18
|
+
type: ErrorType;
|
|
19
|
+
statusCode?: number;
|
|
20
|
+
details?: Record<string, any>;
|
|
21
|
+
originalError?: any;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Normalize an error into a standard format
|
|
25
|
+
*/
|
|
26
|
+
export declare const normalizeError: (error: any, context?: string) => StandardError;
|
|
27
|
+
/**
|
|
28
|
+
* Handle an error with optional toast notification
|
|
29
|
+
*/
|
|
30
|
+
export declare const handleError: (error: any, options?: {
|
|
31
|
+
context?: string;
|
|
32
|
+
showToast?: boolean;
|
|
33
|
+
fallbackMessage?: string;
|
|
34
|
+
onAuthError?: () => void;
|
|
35
|
+
}) => StandardError;
|
|
36
|
+
/**
|
|
37
|
+
* Create a safe error handler for async functions
|
|
38
|
+
*/
|
|
39
|
+
export declare const createSafeHandler: <T>(asyncFn: (...args: any[]) => Promise<T>, options?: {
|
|
40
|
+
context?: string;
|
|
41
|
+
showToast?: boolean;
|
|
42
|
+
fallbackMessage?: string;
|
|
43
|
+
onAuthError?: () => void;
|
|
44
|
+
onError?: (error: StandardError) => void;
|
|
45
|
+
}) => (...args: any[]) => Promise<[T | null, StandardError | null]>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if an error is an authentication error
|
|
48
|
+
*/
|
|
49
|
+
export declare const isAuthError: (error: any) => boolean;
|
|
50
|
+
declare const _default: {
|
|
51
|
+
normalizeError: (error: any, context?: string) => StandardError;
|
|
52
|
+
handleError: (error: any, options?: {
|
|
53
|
+
context?: string;
|
|
54
|
+
showToast?: boolean;
|
|
55
|
+
fallbackMessage?: string;
|
|
56
|
+
onAuthError?: () => void;
|
|
57
|
+
}) => StandardError;
|
|
58
|
+
createSafeHandler: <T>(asyncFn: (...args: any[]) => Promise<T>, options?: {
|
|
59
|
+
context?: string;
|
|
60
|
+
showToast?: boolean;
|
|
61
|
+
fallbackMessage?: string;
|
|
62
|
+
onAuthError?: () => void;
|
|
63
|
+
onError?: (error: StandardError) => void;
|
|
64
|
+
}) => (...args: any[]) => Promise<[T | null, StandardError | null]>;
|
|
65
|
+
isAuthError: (error: any) => boolean;
|
|
66
|
+
ErrorType: typeof ErrorType;
|
|
67
|
+
};
|
|
68
|
+
export default _default;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error Handler Utility
|
|
4
|
+
*
|
|
5
|
+
* This utility provides centralized error handling and logging for the OxyHQ services module.
|
|
6
|
+
* It standardizes error formats, provides consistent logging, and helps with error recovery.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.isAuthError = exports.createSafeHandler = exports.handleError = exports.normalizeError = exports.ErrorType = void 0;
|
|
22
|
+
const sonner_1 = require("sonner");
|
|
23
|
+
const axios_1 = __importDefault(require("axios"));
|
|
24
|
+
// Error types
|
|
25
|
+
var ErrorType;
|
|
26
|
+
(function (ErrorType) {
|
|
27
|
+
ErrorType["NETWORK"] = "network";
|
|
28
|
+
ErrorType["AUTHENTICATION"] = "authentication";
|
|
29
|
+
ErrorType["AUTHORIZATION"] = "authorization";
|
|
30
|
+
ErrorType["VALIDATION"] = "validation";
|
|
31
|
+
ErrorType["SERVER"] = "server";
|
|
32
|
+
ErrorType["CLIENT"] = "client";
|
|
33
|
+
ErrorType["UNKNOWN"] = "unknown";
|
|
34
|
+
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
35
|
+
/**
|
|
36
|
+
* Normalize an error into a standard format
|
|
37
|
+
*/
|
|
38
|
+
const normalizeError = (error, context) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
let message = 'An unknown error occurred';
|
|
41
|
+
let type = ErrorType.UNKNOWN;
|
|
42
|
+
let statusCode = undefined;
|
|
43
|
+
let details = undefined;
|
|
44
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
45
|
+
const axiosError = error;
|
|
46
|
+
statusCode = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
47
|
+
// Extract error details from response
|
|
48
|
+
if ((_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.data) {
|
|
49
|
+
const data = axiosError.response.data;
|
|
50
|
+
message = data.message || axiosError.message || 'API request failed';
|
|
51
|
+
details = data.details || data;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
message = axiosError.message;
|
|
55
|
+
}
|
|
56
|
+
// Determine error type based on status code
|
|
57
|
+
if (!axiosError.response) {
|
|
58
|
+
type = ErrorType.NETWORK;
|
|
59
|
+
}
|
|
60
|
+
else if (statusCode === 401) {
|
|
61
|
+
type = ErrorType.AUTHENTICATION;
|
|
62
|
+
}
|
|
63
|
+
else if (statusCode === 403) {
|
|
64
|
+
type = ErrorType.AUTHORIZATION;
|
|
65
|
+
}
|
|
66
|
+
else if (statusCode === 422 || statusCode === 400) {
|
|
67
|
+
type = ErrorType.VALIDATION;
|
|
68
|
+
}
|
|
69
|
+
else if (statusCode && statusCode >= 500) {
|
|
70
|
+
type = ErrorType.SERVER;
|
|
71
|
+
}
|
|
72
|
+
else if (statusCode && statusCode >= 400) {
|
|
73
|
+
type = ErrorType.CLIENT;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (error instanceof Error) {
|
|
77
|
+
message = error.message;
|
|
78
|
+
// Try to determine error type from message
|
|
79
|
+
if (message.toLowerCase().includes('network') ||
|
|
80
|
+
message.toLowerCase().includes('connection')) {
|
|
81
|
+
type = ErrorType.NETWORK;
|
|
82
|
+
}
|
|
83
|
+
else if (message.toLowerCase().includes('authentication') ||
|
|
84
|
+
message.toLowerCase().includes('login') ||
|
|
85
|
+
message.toLowerCase().includes('token')) {
|
|
86
|
+
type = ErrorType.AUTHENTICATION;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (typeof error === 'string') {
|
|
90
|
+
message = error;
|
|
91
|
+
}
|
|
92
|
+
// Log the error with context
|
|
93
|
+
const logPrefix = context ? `[${context}]` : '';
|
|
94
|
+
console.error(`${logPrefix} Error:`, {
|
|
95
|
+
message,
|
|
96
|
+
type,
|
|
97
|
+
statusCode,
|
|
98
|
+
details,
|
|
99
|
+
originalError: error
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
message,
|
|
103
|
+
type,
|
|
104
|
+
statusCode,
|
|
105
|
+
details,
|
|
106
|
+
originalError: error
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
exports.normalizeError = normalizeError;
|
|
110
|
+
/**
|
|
111
|
+
* Handle an error with optional toast notification
|
|
112
|
+
*/
|
|
113
|
+
const handleError = (error, options = {}) => {
|
|
114
|
+
const { context, showToast = true, fallbackMessage, onAuthError } = options;
|
|
115
|
+
const standardError = (0, exports.normalizeError)(error, context);
|
|
116
|
+
// Show toast notification if requested
|
|
117
|
+
if (showToast) {
|
|
118
|
+
sonner_1.toast.error(standardError.message || fallbackMessage || 'An error occurred');
|
|
119
|
+
}
|
|
120
|
+
// Call auth error handler if it's an authentication error
|
|
121
|
+
if (standardError.type === ErrorType.AUTHENTICATION && onAuthError) {
|
|
122
|
+
onAuthError();
|
|
123
|
+
}
|
|
124
|
+
return standardError;
|
|
125
|
+
};
|
|
126
|
+
exports.handleError = handleError;
|
|
127
|
+
/**
|
|
128
|
+
* Create a safe error handler for async functions
|
|
129
|
+
*/
|
|
130
|
+
const createSafeHandler = (asyncFn, options = {}) => {
|
|
131
|
+
return (...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
try {
|
|
133
|
+
const result = yield asyncFn(...args);
|
|
134
|
+
return [result, null];
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
const standardError = (0, exports.handleError)(error, options);
|
|
138
|
+
if (options.onError) {
|
|
139
|
+
options.onError(standardError);
|
|
140
|
+
}
|
|
141
|
+
return [null, standardError];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
exports.createSafeHandler = createSafeHandler;
|
|
146
|
+
/**
|
|
147
|
+
* Check if an error is an authentication error
|
|
148
|
+
*/
|
|
149
|
+
const isAuthError = (error) => {
|
|
150
|
+
var _a;
|
|
151
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
152
|
+
return ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401;
|
|
153
|
+
}
|
|
154
|
+
if (error && typeof error === 'object' && 'type' in error) {
|
|
155
|
+
return error.type === ErrorType.AUTHENTICATION;
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
};
|
|
159
|
+
exports.isAuthError = isAuthError;
|
|
160
|
+
exports.default = {
|
|
161
|
+
normalizeError: exports.normalizeError,
|
|
162
|
+
handleError: exports.handleError,
|
|
163
|
+
createSafeHandler: exports.createSafeHandler,
|
|
164
|
+
isAuthError: exports.isAuthError,
|
|
165
|
+
ErrorType
|
|
166
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OxyHQ Services Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions and utilities for the OxyHQ services module.
|
|
5
|
+
*/
|
|
6
|
+
export * from './api';
|
|
7
|
+
export * from './storage';
|
|
8
|
+
export * from './socket';
|
|
9
|
+
export * from './socketConfig';
|
|
10
|
+
export { normalizeError, handleError, createSafeHandler, ErrorType } from './errorHandler';
|
|
11
|
+
import errorHandler from './errorHandler';
|
|
12
|
+
export { errorHandler };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OxyHQ Services Utilities
|
|
4
|
+
*
|
|
5
|
+
* Helper functions and utilities for the OxyHQ services module.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.errorHandler = exports.ErrorType = exports.createSafeHandler = exports.handleError = exports.normalizeError = void 0;
|
|
26
|
+
// Export API utilities
|
|
27
|
+
__exportStar(require("./api"), exports);
|
|
28
|
+
// Export storage utilities
|
|
29
|
+
__exportStar(require("./storage"), exports);
|
|
30
|
+
// Export socket utilities
|
|
31
|
+
__exportStar(require("./socket"), exports);
|
|
32
|
+
__exportStar(require("./socketConfig"), exports);
|
|
33
|
+
// Export error handling utilities
|
|
34
|
+
var errorHandler_1 = require("./errorHandler");
|
|
35
|
+
Object.defineProperty(exports, "normalizeError", { enumerable: true, get: function () { return errorHandler_1.normalizeError; } });
|
|
36
|
+
Object.defineProperty(exports, "handleError", { enumerable: true, get: function () { return errorHandler_1.handleError; } });
|
|
37
|
+
Object.defineProperty(exports, "createSafeHandler", { enumerable: true, get: function () { return errorHandler_1.createSafeHandler; } });
|
|
38
|
+
Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return errorHandler_1.ErrorType; } });
|
|
39
|
+
// Export default error handler
|
|
40
|
+
const errorHandler_2 = __importDefault(require("./errorHandler"));
|
|
41
|
+
exports.errorHandler = errorHandler_2.default;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Utility
|
|
3
|
+
*
|
|
4
|
+
* A centralized logging system for the OxyHQ services module.
|
|
5
|
+
* Provides consistent logging with different log levels, context, and optional remote logging.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum LogLevel {
|
|
8
|
+
DEBUG = "debug",
|
|
9
|
+
INFO = "info",
|
|
10
|
+
WARN = "warn",
|
|
11
|
+
ERROR = "error",
|
|
12
|
+
FATAL = "fatal"
|
|
13
|
+
}
|
|
14
|
+
declare class Logger {
|
|
15
|
+
private currentLogLevel;
|
|
16
|
+
private enableRemoteLogging;
|
|
17
|
+
private includeUserContext;
|
|
18
|
+
private redactSensitiveData;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Log a debug message
|
|
22
|
+
*/
|
|
23
|
+
debug(message: string, context?: string, data?: any): void;
|
|
24
|
+
/**
|
|
25
|
+
* Log an info message
|
|
26
|
+
*/
|
|
27
|
+
info(message: string, context?: string, data?: any): void;
|
|
28
|
+
/**
|
|
29
|
+
* Log a warning message
|
|
30
|
+
*/
|
|
31
|
+
warn(message: string, context?: string, data?: any): void;
|
|
32
|
+
/**
|
|
33
|
+
* Log an error message
|
|
34
|
+
*/
|
|
35
|
+
error(message: string, context?: string, data?: any): void;
|
|
36
|
+
/**
|
|
37
|
+
* Log a fatal error message
|
|
38
|
+
*/
|
|
39
|
+
fatal(message: string, context?: string, data?: any): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log a message with the specified level
|
|
42
|
+
*/
|
|
43
|
+
private log;
|
|
44
|
+
/**
|
|
45
|
+
* Check if the given log level should be processed
|
|
46
|
+
*/
|
|
47
|
+
private shouldLog;
|
|
48
|
+
/**
|
|
49
|
+
* Output log entry to console
|
|
50
|
+
*/
|
|
51
|
+
private consoleOutput;
|
|
52
|
+
/**
|
|
53
|
+
* Add user context to log entry
|
|
54
|
+
*/
|
|
55
|
+
private addUserContext;
|
|
56
|
+
/**
|
|
57
|
+
* Queue log entry for remote logging
|
|
58
|
+
*/
|
|
59
|
+
private queueForRemoteLogging;
|
|
60
|
+
/**
|
|
61
|
+
* Start processing the remote logging queue
|
|
62
|
+
*/
|
|
63
|
+
private startQueueProcessing;
|
|
64
|
+
/**
|
|
65
|
+
* Process the remote logging queue
|
|
66
|
+
*/
|
|
67
|
+
private processLogQueue;
|
|
68
|
+
/**
|
|
69
|
+
* Send logs to remote server
|
|
70
|
+
*/
|
|
71
|
+
private sendLogsToRemoteServer;
|
|
72
|
+
/**
|
|
73
|
+
* Redact sensitive fields from log data
|
|
74
|
+
*/
|
|
75
|
+
private redactSensitiveFields;
|
|
76
|
+
/**
|
|
77
|
+
* Set the current log level
|
|
78
|
+
*/
|
|
79
|
+
setLogLevel(level: LogLevel): void;
|
|
80
|
+
/**
|
|
81
|
+
* Enable or disable remote logging
|
|
82
|
+
*/
|
|
83
|
+
setRemoteLogging(enabled: boolean): void;
|
|
84
|
+
/**
|
|
85
|
+
* Log performance metrics
|
|
86
|
+
*/
|
|
87
|
+
logPerformance(operation: string, startTime: number, context?: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Create a scoped logger with a fixed context
|
|
90
|
+
*/
|
|
91
|
+
createScopedLogger(context: string): {
|
|
92
|
+
debug: (message: string, data?: any) => void;
|
|
93
|
+
info: (message: string, data?: any) => void;
|
|
94
|
+
warn: (message: string, data?: any) => void;
|
|
95
|
+
error: (message: string, data?: any) => void;
|
|
96
|
+
fatal: (message: string, data?: any) => void;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export declare const logger: Logger;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger Utility
|
|
4
|
+
*
|
|
5
|
+
* A centralized logging system for the OxyHQ services module.
|
|
6
|
+
* Provides consistent logging with different log levels, context, and optional remote logging.
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.logger = exports.LogLevel = void 0;
|
|
19
|
+
const config_1 = require("../config");
|
|
20
|
+
const storage_1 = require("./storage");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
22
|
+
// Log levels
|
|
23
|
+
var LogLevel;
|
|
24
|
+
(function (LogLevel) {
|
|
25
|
+
LogLevel["DEBUG"] = "debug";
|
|
26
|
+
LogLevel["INFO"] = "info";
|
|
27
|
+
LogLevel["WARN"] = "warn";
|
|
28
|
+
LogLevel["ERROR"] = "error";
|
|
29
|
+
LogLevel["FATAL"] = "fatal";
|
|
30
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
31
|
+
// Log level priorities (higher number = higher priority)
|
|
32
|
+
const LOG_LEVEL_PRIORITY = {
|
|
33
|
+
[LogLevel.DEBUG]: 0,
|
|
34
|
+
[LogLevel.INFO]: 1,
|
|
35
|
+
[LogLevel.WARN]: 2,
|
|
36
|
+
[LogLevel.ERROR]: 3,
|
|
37
|
+
[LogLevel.FATAL]: 4
|
|
38
|
+
};
|
|
39
|
+
// Remote logging queue
|
|
40
|
+
const logQueue = [];
|
|
41
|
+
let isProcessingQueue = false;
|
|
42
|
+
const MAX_QUEUE_SIZE = 100;
|
|
43
|
+
const QUEUE_PROCESSING_INTERVAL = 10000; // 10 seconds
|
|
44
|
+
class Logger {
|
|
45
|
+
constructor() {
|
|
46
|
+
this.currentLogLevel = config_1.OXY_LOGGING_CONFIG.LEVEL || LogLevel.ERROR;
|
|
47
|
+
this.enableRemoteLogging = config_1.OXY_LOGGING_CONFIG.ENABLE_REMOTE_LOGGING;
|
|
48
|
+
this.includeUserContext = config_1.OXY_LOGGING_CONFIG.INCLUDE_USER_CONTEXT;
|
|
49
|
+
this.redactSensitiveData = config_1.OXY_LOGGING_CONFIG.REDACT_SENSITIVE_DATA;
|
|
50
|
+
// Start queue processing if remote logging is enabled
|
|
51
|
+
if (this.enableRemoteLogging) {
|
|
52
|
+
this.startQueueProcessing();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Log a debug message
|
|
57
|
+
*/
|
|
58
|
+
debug(message, context, data) {
|
|
59
|
+
this.log(LogLevel.DEBUG, message, context, data);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Log an info message
|
|
63
|
+
*/
|
|
64
|
+
info(message, context, data) {
|
|
65
|
+
this.log(LogLevel.INFO, message, context, data);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Log a warning message
|
|
69
|
+
*/
|
|
70
|
+
warn(message, context, data) {
|
|
71
|
+
this.log(LogLevel.WARN, message, context, data);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Log an error message
|
|
75
|
+
*/
|
|
76
|
+
error(message, context, data) {
|
|
77
|
+
this.log(LogLevel.ERROR, message, context, data);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Log a fatal error message
|
|
81
|
+
*/
|
|
82
|
+
fatal(message, context, data) {
|
|
83
|
+
this.log(LogLevel.FATAL, message, context, data);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Log a message with the specified level
|
|
87
|
+
*/
|
|
88
|
+
log(level, message, context, data) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
// Check if this log level should be processed
|
|
91
|
+
if (!this.shouldLog(level)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
// Create log entry
|
|
95
|
+
const logEntry = {
|
|
96
|
+
timestamp: new Date().toISOString(),
|
|
97
|
+
level,
|
|
98
|
+
message,
|
|
99
|
+
context,
|
|
100
|
+
data: this.redactSensitiveData ? this.redactSensitiveFields(data) : data
|
|
101
|
+
};
|
|
102
|
+
// Add user context if enabled
|
|
103
|
+
if (this.includeUserContext) {
|
|
104
|
+
yield this.addUserContext(logEntry);
|
|
105
|
+
}
|
|
106
|
+
// Console output
|
|
107
|
+
this.consoleOutput(logEntry);
|
|
108
|
+
// Queue for remote logging if enabled
|
|
109
|
+
if (this.enableRemoteLogging && level !== LogLevel.DEBUG) {
|
|
110
|
+
this.queueForRemoteLogging(logEntry);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check if the given log level should be processed
|
|
116
|
+
*/
|
|
117
|
+
shouldLog(level) {
|
|
118
|
+
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.currentLogLevel];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Output log entry to console
|
|
122
|
+
*/
|
|
123
|
+
consoleOutput(entry) {
|
|
124
|
+
const { level, message, context, data } = entry;
|
|
125
|
+
const timestamp = new Date(entry.timestamp).toLocaleTimeString();
|
|
126
|
+
const contextStr = context ? `[${context}]` : '';
|
|
127
|
+
const logMessage = `${timestamp} ${level.toUpperCase()} ${contextStr} ${message}`;
|
|
128
|
+
switch (level) {
|
|
129
|
+
case LogLevel.DEBUG:
|
|
130
|
+
console.debug(logMessage, data || '');
|
|
131
|
+
break;
|
|
132
|
+
case LogLevel.INFO:
|
|
133
|
+
console.info(logMessage, data || '');
|
|
134
|
+
break;
|
|
135
|
+
case LogLevel.WARN:
|
|
136
|
+
console.warn(logMessage, data || '');
|
|
137
|
+
break;
|
|
138
|
+
case LogLevel.ERROR:
|
|
139
|
+
case LogLevel.FATAL:
|
|
140
|
+
console.error(logMessage, data || '');
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Add user context to log entry
|
|
146
|
+
*/
|
|
147
|
+
addUserContext(entry) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
try {
|
|
150
|
+
const userId = yield (0, storage_1.getData)(constants_1.STORAGE_KEYS.USER_ID);
|
|
151
|
+
if (userId) {
|
|
152
|
+
entry.userId = userId;
|
|
153
|
+
}
|
|
154
|
+
// Add session ID if available
|
|
155
|
+
const sessionId = yield (0, storage_1.getData)('sessionId');
|
|
156
|
+
if (sessionId) {
|
|
157
|
+
entry.sessionId = sessionId;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
// Silently fail if we can't get user context
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Queue log entry for remote logging
|
|
167
|
+
*/
|
|
168
|
+
queueForRemoteLogging(entry) {
|
|
169
|
+
// Add to queue, maintaining max size
|
|
170
|
+
logQueue.push(entry);
|
|
171
|
+
if (logQueue.length > MAX_QUEUE_SIZE) {
|
|
172
|
+
logQueue.shift();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Start processing the remote logging queue
|
|
177
|
+
*/
|
|
178
|
+
startQueueProcessing() {
|
|
179
|
+
setInterval(() => {
|
|
180
|
+
this.processLogQueue();
|
|
181
|
+
}, QUEUE_PROCESSING_INTERVAL);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Process the remote logging queue
|
|
185
|
+
*/
|
|
186
|
+
processLogQueue() {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
if (isProcessingQueue || logQueue.length === 0) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
isProcessingQueue = true;
|
|
192
|
+
try {
|
|
193
|
+
// Take a snapshot of the current queue
|
|
194
|
+
const logsToSend = [...logQueue];
|
|
195
|
+
logQueue.length = 0;
|
|
196
|
+
// Send logs to remote server
|
|
197
|
+
yield this.sendLogsToRemoteServer(logsToSend);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
// If sending fails, add logs back to the queue
|
|
201
|
+
console.error('Failed to send logs to remote server:', error);
|
|
202
|
+
// Only add back the most recent logs to avoid queue growing too large
|
|
203
|
+
const logsToRequeue = logQueue.length + MAX_QUEUE_SIZE > 2 * MAX_QUEUE_SIZE
|
|
204
|
+
? logQueue.slice(-MAX_QUEUE_SIZE)
|
|
205
|
+
: logQueue;
|
|
206
|
+
logQueue.push(...logsToRequeue);
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
isProcessingQueue = false;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Send logs to remote server
|
|
215
|
+
*/
|
|
216
|
+
sendLogsToRemoteServer(logs) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
// Implementation would depend on your remote logging service
|
|
219
|
+
// This is a placeholder for the actual implementation
|
|
220
|
+
if (config_1.OXY_CONFIG.ENV.IS_DEV) {
|
|
221
|
+
console.log('Would send logs to remote server:', logs);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
// In production, you would send logs to your logging service
|
|
225
|
+
// Example:
|
|
226
|
+
// await fetch('https://logging.oxy.so/api/logs', {
|
|
227
|
+
// method: 'POST',
|
|
228
|
+
// headers: { 'Content-Type': 'application/json' },
|
|
229
|
+
// body: JSON.stringify({ logs })
|
|
230
|
+
// });
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Redact sensitive fields from log data
|
|
235
|
+
*/
|
|
236
|
+
redactSensitiveFields(data) {
|
|
237
|
+
if (!data || typeof data !== 'object') {
|
|
238
|
+
return data;
|
|
239
|
+
}
|
|
240
|
+
const sensitiveFields = [
|
|
241
|
+
'password', 'token', 'accessToken', 'refreshToken', 'secret',
|
|
242
|
+
'apiKey', 'authorization', 'credential', 'pin', 'ssn', 'creditCard'
|
|
243
|
+
];
|
|
244
|
+
const redacted = Object.assign({}, data);
|
|
245
|
+
for (const key in redacted) {
|
|
246
|
+
if (Object.prototype.hasOwnProperty.call(redacted, key)) {
|
|
247
|
+
// Check if this is a sensitive field
|
|
248
|
+
if (sensitiveFields.some(field => key.toLowerCase().includes(field.toLowerCase()))) {
|
|
249
|
+
redacted[key] = '[REDACTED]';
|
|
250
|
+
}
|
|
251
|
+
else if (typeof redacted[key] === 'object' && redacted[key] !== null) {
|
|
252
|
+
// Recursively redact nested objects
|
|
253
|
+
redacted[key] = this.redactSensitiveFields(redacted[key]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return redacted;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Set the current log level
|
|
261
|
+
*/
|
|
262
|
+
setLogLevel(level) {
|
|
263
|
+
this.currentLogLevel = level;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Enable or disable remote logging
|
|
267
|
+
*/
|
|
268
|
+
setRemoteLogging(enabled) {
|
|
269
|
+
this.enableRemoteLogging = enabled;
|
|
270
|
+
if (enabled && !isProcessingQueue) {
|
|
271
|
+
this.startQueueProcessing();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Log performance metrics
|
|
276
|
+
*/
|
|
277
|
+
logPerformance(operation, startTime, context) {
|
|
278
|
+
if (!config_1.OXY_LOGGING_CONFIG.LOG_PERFORMANCE_METRICS) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const duration = Date.now() - startTime;
|
|
282
|
+
this.info(`Performance: ${operation} took ${duration}ms`, context || 'Performance', { duration });
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Create a scoped logger with a fixed context
|
|
286
|
+
*/
|
|
287
|
+
createScopedLogger(context) {
|
|
288
|
+
return {
|
|
289
|
+
debug: (message, data) => this.debug(message, context, data),
|
|
290
|
+
info: (message, data) => this.info(message, context, data),
|
|
291
|
+
warn: (message, data) => this.warn(message, context, data),
|
|
292
|
+
error: (message, data) => this.error(message, context, data),
|
|
293
|
+
fatal: (message, data) => this.fatal(message, context, data)
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// Export singleton instance
|
|
298
|
+
exports.logger = new Logger();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Socket } from 'socket.io-client';
|
|
2
|
+
export declare const getSocket: (namespace?: string) => Promise<Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null>;
|
|
3
|
+
export declare const disconnectSocket: () => void;
|
|
4
|
+
export declare const joinRoom: (socket: Socket, room: string) => boolean;
|
|
5
|
+
export declare const leaveRoom: (socket: Socket, room: string) => boolean;
|
|
6
|
+
export declare const initializeChatSocket: () => Promise<Socket<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap> | null>;
|