@copytrade/shared-types
Version:
Shared TypeScript types for CopyTrade application
124 lines (123 loc) • 3.77 kB
TypeScript
/**
* Standardized API Response Types
* Shared between frontend and backend for consistent API communication
*/
export declare const AuthenticationStep: {
readonly DIRECT_LOGIN: "DIRECT_LOGIN";
readonly OAUTH_REQUIRED: "OAUTH_REQUIRED";
readonly TOTP_REQUIRED: "TOTP_REQUIRED";
readonly CAPTCHA_REQUIRED: "CAPTCHA_REQUIRED";
readonly ALREADY_ACTIVE: "ALREADY_ACTIVE";
readonly REAUTH_REQUIRED: "REAUTH_REQUIRED";
};
export type AuthenticationStep = typeof AuthenticationStep[keyof typeof AuthenticationStep];
export declare const ApiErrorCode: {
readonly INVALID_CREDENTIALS: "INVALID_CREDENTIALS";
readonly NETWORK_ERROR: "NETWORK_ERROR";
readonly BROKER_ERROR: "BROKER_ERROR";
readonly SESSION_EXPIRED: "SESSION_EXPIRED";
readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND";
readonly OAUTH_ERROR: "OAUTH_ERROR";
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
readonly RATE_LIMIT_EXCEEDED: "RATE_LIMIT_EXCEEDED";
readonly BROKER_MAINTENANCE: "BROKER_MAINTENANCE";
};
export type ApiErrorCode = typeof ApiErrorCode[keyof typeof ApiErrorCode];
export interface ApiError {
code: ApiErrorCode;
message: string;
details?: any;
timestamp?: string;
}
export interface BaseApiResponse {
success: boolean;
message: string;
timestamp?: string;
}
export interface ActivateAccountResponse extends BaseApiResponse {
data?: {
accountId: string;
isActive: boolean;
authStep: AuthenticationStep;
authUrl?: string;
redirectUri?: string;
additionalData?: {
brokerName?: string;
userName?: string;
exchanges?: string[];
products?: string[];
sessionValidUntil?: string;
};
};
error?: ApiError;
}
export interface DeactivateAccountResponse extends BaseApiResponse {
data?: {
accountId: string;
isActive: boolean;
};
error?: ApiError;
}
export interface ConnectedAccountsResponse extends BaseApiResponse {
accounts?: Array<{
id: string;
brokerName: string;
accountId: string;
userId: string;
userName: string;
email: string;
brokerDisplayName: string;
exchanges: string[];
products: string[];
isActive: boolean;
createdAt: string;
lastActiveAt?: string;
}>;
error?: ApiError;
}
export interface OAuthCompletionResponse extends BaseApiResponse {
data?: {
accountId: string;
isActive: boolean;
brokerName: string;
userName: string;
};
error?: ApiError;
}
export interface SuccessResponse extends BaseApiResponse {
data?: any;
error?: ApiError;
}
export interface OrderResponse extends BaseApiResponse {
data?: {
orderId: string;
status: string;
brokerOrderId?: string;
message?: string;
};
error?: ApiError;
}
export interface PortfolioResponse extends BaseApiResponse {
data?: {
summary: any;
holdings: any[];
metrics: any;
};
error?: ApiError;
}
export interface MarketDataResponse extends BaseApiResponse {
data?: {
indices?: any[];
stocks?: any[];
lastUpdated?: string;
};
error?: ApiError;
}
export declare function createSuccessResponse<T>(message: string, data?: T): BaseApiResponse & {
data?: T;
};
export declare function createErrorResponse(message: string, errorCode: ApiErrorCode, details?: any): BaseApiResponse & {
error: ApiError;
};
export declare function createActivationResponse(success: boolean, message: string, data?: ActivateAccountResponse['data'], error?: ApiError): ActivateAccountResponse;