@copytrade/shared-types
Version:
Shared TypeScript types for CopyTrade application
74 lines (73 loc) • 2.39 kB
JavaScript
;
/**
* Standardized API Response Types
* Shared between frontend and backend for consistent API communication
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiErrorCode = exports.AuthenticationStep = void 0;
exports.createSuccessResponse = createSuccessResponse;
exports.createErrorResponse = createErrorResponse;
exports.createActivationResponse = createActivationResponse;
// Authentication Step Constants
exports.AuthenticationStep = {
DIRECT_LOGIN: 'DIRECT_LOGIN', // Direct login (Shoonya)
OAUTH_REQUIRED: 'OAUTH_REQUIRED', // OAuth flow required (Fyers)
TOTP_REQUIRED: 'TOTP_REQUIRED', // TOTP/2FA required
CAPTCHA_REQUIRED: 'CAPTCHA_REQUIRED', // Captcha required
ALREADY_ACTIVE: 'ALREADY_ACTIVE', // Account already active
REAUTH_REQUIRED: 'REAUTH_REQUIRED' // Re-authentication required
};
// Error Code Constants
exports.ApiErrorCode = {
INVALID_CREDENTIALS: 'INVALID_CREDENTIALS',
NETWORK_ERROR: 'NETWORK_ERROR',
BROKER_ERROR: 'BROKER_ERROR',
SESSION_EXPIRED: 'SESSION_EXPIRED',
ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',
OAUTH_ERROR: 'OAUTH_ERROR',
VALIDATION_ERROR: 'VALIDATION_ERROR',
INTERNAL_ERROR: 'INTERNAL_ERROR',
RATE_LIMIT_EXCEEDED: 'RATE_LIMIT_EXCEEDED',
BROKER_MAINTENANCE: 'BROKER_MAINTENANCE'
};
// Helper function to create standardized success response
function createSuccessResponse(message, data) {
const response = {
success: true,
message,
timestamp: new Date().toISOString()
};
if (data !== undefined) {
response.data = data;
}
return response;
}
// Helper function to create standardized error response
function createErrorResponse(message, errorCode, details) {
return {
success: false,
message,
error: {
code: errorCode,
message,
details,
timestamp: new Date().toISOString()
},
timestamp: new Date().toISOString()
};
}
// Helper function to create activation response
function createActivationResponse(success, message, data, error) {
const response = {
success,
message,
timestamp: new Date().toISOString()
};
if (data !== undefined) {
response.data = data;
}
if (error !== undefined) {
response.error = error;
}
return response;
}