redai-automation-web-sdk
Version:
TypeScript SDK for RedAI Automation Web API - Zalo Personal automation, messaging, advanced sticker search, and bulk operations. 100% compatible with automation-web backend. v1.8.0: Added SessionProxyService for managing proxy assignments to sessions with
501 lines • 14.5 kB
TypeScript
/**
* Error types and codes for RedAI Automation Web SDK
* Based on @warriorteam/zalo-personal SDK error handling patterns
*/
/**
* Zalo API Error Codes
* Based on @warriorteam/zalo-personal SDK and common API patterns
*/
export declare enum ZaloErrorCode {
SESSION_NOT_FOUND = 1001,
SESSION_EXPIRED = 1002,
SESSION_INACTIVE = 1003,
INVALID_CREDENTIALS = 1004,
AUTHENTICATION_FAILED = 1005,
SESSION_CREATION_FAILED = 1006,
SESSION_VALIDATION_FAILED = 1007,
USER_NOT_FOUND = 1101,
USER_ID_INVALID = 1102,
USER_PROFILE_PRIVATE = 1103,
USER_BLOCKED_YOU = 1104,
USER_DOESNT_EXIST = 1105,
USER_NOT_ACCESSIBLE = 1106,
FRIEND_REQUEST_FAILED = 1201,
FRIEND_NOT_FOUND = 1202,
ALREADY_FRIENDS = 1203,
FRIEND_REQUEST_SENT = 1204,
CANNOT_SEND_REQUEST = 1205,
FRIEND_BLOCKED = 1206,
CANNOT_UNFRIEND = 1207,
GROUP_NOT_FOUND = 1301,
GROUP_ID_INVALID = 1302,
NOT_GROUP_MEMBER = 1303,
NOT_GROUP_ADMIN = 1304,
GROUP_FULL = 1305,
CANNOT_JOIN_GROUP = 1306,
GROUP_CREATION_FAILED = 1307,
GROUP_SETTINGS_UPDATE_FAILED = 1308,
MESSAGE_NOT_FOUND = 1401,
CANNOT_SEND_MESSAGE = 1402,
MEDIA_TOO_LARGE = 1403,
UNSUPPORTED_MEDIA_TYPE = 1404,
MESSAGE_SEND_FAILED = 1405,
MESSAGE_FORWARD_FAILED = 1406,
REACTION_FAILED = 1407,
INVALID_PARAMETERS = 1501,
MISSING_REQUIRED_FIELDS = 1502,
INVALID_USER_ID_FORMAT = 1503,
INVALID_GROUP_ID_FORMAT = 1504,
INVALID_MESSAGE_FORMAT = 1505,
BATCH_SIZE_EXCEEDED = 1506,
INVALID_ATTACHMENT_FORMAT = 1507,
RATE_LIMIT_EXCEEDED = 1601,
TOO_MANY_REQUESTS = 1602,
TEMPORARY_BLOCK = 1603,
REQUEST_LIMIT_REACHED = 1604,
SPAM_DETECTED = 1605,
NETWORK_ERROR = 1701,
CONNECTION_TIMEOUT = 1702,
API_UNAVAILABLE = 1703,
SERVER_ERROR = 1704,
CONNECTION_REFUSED = 1705,
DNS_RESOLUTION_FAILED = 1706,
PROXY_CONNECTION_FAILED = 1707,
INSUFFICIENT_PERMISSIONS = 1801,
ACCESS_DENIED = 1802,
ACCOUNT_SUSPENDED = 1803,
ACCOUNT_BANNED = 1804,
DEVICE_NOT_VERIFIED = 1805,
REGION_RESTRICTED = 1806,
AGE_RESTRICTED = 1807,
OPERATION_NOT_ALLOWED = 1901,
FEATURE_NOT_AVAILABLE = 1902,
SUBSCRIPTION_REQUIRED = 1903,
QUOTA_EXCEEDED = 1904,
INVALID_OPERATION_CONTEXT = 1905,
DATA_PARSING_FAILED = 2001,
ENCRYPTION_FAILED = 2002,
DECRYPTION_FAILED = 2003,
DATA_CORRUPTION = 2004,
INVALID_JSON_FORMAT = 2005,
EXTERNAL_API_ERROR = 2101,
WEBHOOK_DELIVERY_FAILED = 2102,
CALLBACK_TIMEOUT = 2103,
THIRD_PARTY_SERVICE_ERROR = 2104,
UNKNOWN_ERROR = 9000,
INTERNAL_ERROR = 9001,
INVALID_RESPONSE = 9002,
UNEXPECTED_ERROR = 9003,
NOT_IMPLEMENTED = 9004,
MAINTENANCE_MODE = 9005
}
/**
* Zalo Error Severity Levels
*/
export declare enum ZaloErrorSeverity {
LOW = "low",
MEDIUM = "medium",
HIGH = "high",
CRITICAL = "critical"
}
/**
* Error Category Mappings
*/
export declare const ERROR_CATEGORIES: {
readonly 1001: "authentication";
readonly 1002: "authentication";
readonly 1003: "authentication";
readonly 1004: "authentication";
readonly 1005: "authentication";
readonly 1101: "user_info";
readonly 1102: "user_info";
readonly 1103: "user_info";
readonly 1104: "user_info";
readonly 1105: "user_info";
readonly 1106: "user_info";
readonly 1201: "friend_management";
readonly 1202: "friend_management";
readonly 1203: "friend_management";
readonly 1204: "friend_management";
readonly 1205: "friend_management";
readonly 1206: "friend_management";
readonly 1207: "friend_management";
readonly 1301: "group_management";
readonly 1302: "group_management";
readonly 1303: "group_management";
readonly 1304: "group_management";
readonly 1305: "group_management";
readonly 1306: "group_management";
readonly 1307: "group_management";
readonly 1308: "group_management";
readonly 1401: "messaging";
readonly 1402: "messaging";
readonly 1403: "messaging";
readonly 1404: "messaging";
readonly 1405: "messaging";
readonly 1406: "messaging";
readonly 1407: "messaging";
readonly 1501: "validation";
readonly 1502: "validation";
readonly 1503: "validation";
readonly 1504: "validation";
readonly 1505: "validation";
readonly 1506: "validation";
readonly 1507: "validation";
readonly 1601: "rate_limiting";
readonly 1602: "rate_limiting";
readonly 1603: "rate_limiting";
readonly 1604: "rate_limiting";
readonly 1605: "rate_limiting";
readonly 1701: "network";
readonly 1702: "network";
readonly 1703: "network";
readonly 1704: "network";
readonly 1705: "network";
readonly 1706: "network";
readonly 1707: "network";
readonly 1801: "permission";
readonly 1802: "permission";
readonly 1803: "permission";
readonly 1804: "permission";
readonly 1805: "permission";
readonly 1806: "permission";
readonly 1807: "permission";
readonly 1901: "business_logic";
readonly 1902: "business_logic";
readonly 1903: "business_logic";
readonly 1904: "business_logic";
readonly 1905: "business_logic";
readonly 2001: "data_processing";
readonly 2002: "data_processing";
readonly 2003: "data_processing";
readonly 2004: "data_processing";
readonly 2005: "data_processing";
readonly 2101: "external_service";
readonly 2102: "external_service";
readonly 2103: "external_service";
readonly 2104: "external_service";
readonly 9000: "generic";
readonly 9001: "generic";
readonly 9002: "generic";
readonly 9003: "generic";
readonly 9004: "generic";
readonly 9005: "generic";
};
/**
* Error Severity Mappings
*/
export declare const ERROR_SEVERITY: {
readonly 1001: ZaloErrorSeverity.HIGH;
readonly 1002: ZaloErrorSeverity.HIGH;
readonly 1003: ZaloErrorSeverity.MEDIUM;
readonly 1004: ZaloErrorSeverity.HIGH;
readonly 1005: ZaloErrorSeverity.HIGH;
readonly 1101: ZaloErrorSeverity.MEDIUM;
readonly 1102: ZaloErrorSeverity.MEDIUM;
readonly 1103: ZaloErrorSeverity.LOW;
readonly 1104: ZaloErrorSeverity.MEDIUM;
readonly 1105: ZaloErrorSeverity.MEDIUM;
readonly 1106: ZaloErrorSeverity.MEDIUM;
readonly 1201: ZaloErrorSeverity.MEDIUM;
readonly 1202: ZaloErrorSeverity.MEDIUM;
readonly 1203: ZaloErrorSeverity.LOW;
readonly 1204: ZaloErrorSeverity.LOW;
readonly 1205: ZaloErrorSeverity.MEDIUM;
readonly 1206: ZaloErrorSeverity.MEDIUM;
readonly 1207: ZaloErrorSeverity.MEDIUM;
readonly 1301: ZaloErrorSeverity.MEDIUM;
readonly 1302: ZaloErrorSeverity.MEDIUM;
readonly 1303: ZaloErrorSeverity.MEDIUM;
readonly 1304: ZaloErrorSeverity.MEDIUM;
readonly 1305: ZaloErrorSeverity.MEDIUM;
readonly 1306: ZaloErrorSeverity.MEDIUM;
readonly 1307: ZaloErrorSeverity.MEDIUM;
readonly 1308: ZaloErrorSeverity.MEDIUM;
readonly 1401: ZaloErrorSeverity.LOW;
readonly 1402: ZaloErrorSeverity.HIGH;
readonly 1403: ZaloErrorSeverity.MEDIUM;
readonly 1404: ZaloErrorSeverity.MEDIUM;
readonly 1405: ZaloErrorSeverity.HIGH;
readonly 1406: ZaloErrorSeverity.MEDIUM;
readonly 1407: ZaloErrorSeverity.LOW;
readonly 1501: ZaloErrorSeverity.MEDIUM;
readonly 1502: ZaloErrorSeverity.MEDIUM;
readonly 1503: ZaloErrorSeverity.MEDIUM;
readonly 1504: ZaloErrorSeverity.MEDIUM;
readonly 1505: ZaloErrorSeverity.MEDIUM;
readonly 1506: ZaloErrorSeverity.MEDIUM;
readonly 1507: ZaloErrorSeverity.MEDIUM;
readonly 1601: ZaloErrorSeverity.HIGH;
readonly 1602: ZaloErrorSeverity.HIGH;
readonly 1603: ZaloErrorSeverity.HIGH;
readonly 1604: ZaloErrorSeverity.HIGH;
readonly 1605: ZaloErrorSeverity.HIGH;
readonly 1701: ZaloErrorSeverity.HIGH;
readonly 1702: ZaloErrorSeverity.HIGH;
readonly 1703: ZaloErrorSeverity.HIGH;
readonly 1704: ZaloErrorSeverity.CRITICAL;
readonly 1705: ZaloErrorSeverity.HIGH;
readonly 1706: ZaloErrorSeverity.HIGH;
readonly 1707: ZaloErrorSeverity.HIGH;
readonly 1801: ZaloErrorSeverity.HIGH;
readonly 1802: ZaloErrorSeverity.HIGH;
readonly 1803: ZaloErrorSeverity.CRITICAL;
readonly 1804: ZaloErrorSeverity.CRITICAL;
readonly 1805: ZaloErrorSeverity.MEDIUM;
readonly 1806: ZaloErrorSeverity.MEDIUM;
readonly 1807: ZaloErrorSeverity.MEDIUM;
readonly 1901: ZaloErrorSeverity.MEDIUM;
readonly 1902: ZaloErrorSeverity.MEDIUM;
readonly 1903: ZaloErrorSeverity.MEDIUM;
readonly 1904: ZaloErrorSeverity.HIGH;
readonly 1905: ZaloErrorSeverity.MEDIUM;
readonly 2001: ZaloErrorSeverity.MEDIUM;
readonly 2002: ZaloErrorSeverity.HIGH;
readonly 2003: ZaloErrorSeverity.HIGH;
readonly 2004: ZaloErrorSeverity.HIGH;
readonly 2005: ZaloErrorSeverity.MEDIUM;
readonly 2101: ZaloErrorSeverity.HIGH;
readonly 2102: ZaloErrorSeverity.MEDIUM;
readonly 2103: ZaloErrorSeverity.MEDIUM;
readonly 2104: ZaloErrorSeverity.HIGH;
readonly 9000: ZaloErrorSeverity.MEDIUM;
readonly 9001: ZaloErrorSeverity.CRITICAL;
readonly 9002: ZaloErrorSeverity.MEDIUM;
readonly 9003: ZaloErrorSeverity.MEDIUM;
readonly 9004: ZaloErrorSeverity.LOW;
readonly 9005: ZaloErrorSeverity.HIGH;
};
/**
* Standardized Error Messages
*/
export declare const ERROR_MESSAGES: Record<ZaloErrorCode, string>;
/**
* Type for error details
*/
export interface ZaloErrorDetails {
/**
* Error code from ZaloErrorCode enum
*/
code: ZaloErrorCode;
/**
* Human-readable error message
*/
message: string;
/**
* Error category
*/
category: string;
/**
* Error severity level
*/
severity: ZaloErrorSeverity;
/**
* Additional context or metadata about the error
*/
context?: Record<string, any>;
/**
* Original error that caused this error (for debugging)
*/
originalError?: Error;
/**
* Timestamp when error occurred
*/
timestamp: number;
/**
* Request ID for tracking (if available)
*/
requestId?: string;
/**
* Session ID if error is session-related
*/
sessionId?: string;
/**
* User ID if error is user-related
*/
userId?: string;
/**
* Group ID if error is group-related
*/
groupId?: string;
}
/**
* Type for error response format
*/
export interface ZaloErrorResponse {
/**
* Whether the operation was successful
*/
success: false;
/**
* Error details
*/
error: ZaloErrorDetails;
/**
* Additional error context
*/
metadata?: Record<string, any>;
}
/**
* Type for successful response with error information
*/
export interface ZaloSuccessWithErrorsResponse<T> {
/**
* Overall operation success status
*/
success: true;
/**
* Result data (if any)
*/
data?: T;
/**
* Partial errors that occurred during operation
*/
errors?: ZaloErrorDetails[];
/**
* Warnings about the operation
*/
warnings?: string[];
/**
* Additional metadata
*/
metadata?: Record<string, any>;
}
/**
* Type for batch operation error
*/
export interface ZaloBatchError {
/**
* Index or identifier of the item that failed
*/
index?: string | number;
/**
* ID of the item that failed
*/
itemId?: string;
/**
* Error details for this specific item
*/
error: ZaloErrorDetails;
/**
* Original data that caused the error (sanitized)
*/
originalData?: any;
}
/**
* Type for batch operation response with mixed success/failure
*/
export interface ZaloBatchOperationResponse<T> {
/**
* Overall operation success status
*/
success: boolean;
/**
* Successfully processed items
*/
successItems?: T[];
/**
* Failed items with their errors
*/
errors?: ZaloBatchError[];
/**
* Total number of items processed
*/
totalItems: number;
/**
* Number of successful items
*/
successCount: number;
/**
* Number of failed items
*/
errorCount: number;
/**
* Success rate (0-100)
*/
successRate: number;
/**
* Additional metadata
*/
metadata?: Record<string, any>;
}
/**
* Error context builder helper
*/
export declare class ZaloErrorContext {
private details;
/**
* Set error code
*/
code(code: ZaloErrorCode): ZaloErrorContext;
/**
* Set custom message
*/
message(message: string): ZaloErrorContext;
/**
* Add context
*/
context(context: Record<string, any>): ZaloErrorContext;
/**
* Set session ID
*/
sessionId(sessionId: string): ZaloErrorContext;
/**
* Set user ID
*/
userId(userId: string): ZaloErrorContext;
/**
* Set group ID
*/
groupId(groupId: string): ZaloErrorContext;
/**
* Set request ID
*/
requestId(requestId: string): ZaloErrorContext;
/**
* Set original error
*/
originalError(error: Error): ZaloErrorContext;
/**
* Build the error details
*/
build(): ZaloErrorDetails;
}
/**
* Utility functions for error handling
*/
export declare class ZaloErrorUtils {
/**
* Create a standardized error response
*/
static createErrorResponse(code: ZaloErrorCode, customMessage?: string, context?: Record<string, any>): ZaloErrorResponse;
/**
* Check if an error is recoverable
*/
static isRecoverable(errorCode: ZaloErrorCode): boolean;
/**
* Check if an error should trigger a retry
*/
static shouldRetry(errorCode: ZaloErrorCode): boolean;
/**
* Get retry delay in milliseconds for a specific error code
*/
static getRetryDelay(errorCode: ZaloErrorCode): number;
/**
* Format error for logging
*/
static formatForLogging(error: ZaloErrorDetails): string;
/**
* Check if error is session-related
*/
static isSessionError(errorCode: ZaloErrorCode): boolean;
/**
* Check if error is user-related
*/
static isUserError(errorCode: ZaloErrorCode): boolean;
/**
* Check if error is group-related
*/
static isGroupError(errorCode: ZaloErrorCode): boolean;
}
//# sourceMappingURL=error.types.d.ts.map