meta-cloud-api
Version:
TypeScript wrapper for Meta's Cloud API
64 lines (60 loc) • 2.52 kB
TypeScript
import { a as FlowEndpointRequest, n as FlowDataExchangeRequest, e as FlowActionEnum, o as FlowErrorNotificationRequest, p as FlowHealthCheckRequest } from './common-lV0NsO7t.js';
declare const DATA_EXCHANGE_ACTIONS: readonly [FlowActionEnum.DATA_EXCHANGE, FlowActionEnum.INIT, FlowActionEnum.BACK];
declare const ERROR_ACTIONS: readonly [FlowActionEnum.DATA_EXCHANGE, FlowActionEnum.INIT];
/**
* Type guard to check if a request is a Data Exchange request
* Validates the request structure according to the Flow API specifications
*
* @param request The Flow endpoint request to check
* @returns True if the request is a valid Data Exchange request, false otherwise
*/
declare function isFlowDataExchangeRequest(request: FlowEndpointRequest): request is FlowDataExchangeRequest & {
action: (typeof DATA_EXCHANGE_ACTIONS)[number];
screen?: string;
flow_token: string;
data?: Record<string, any>;
};
/**
* Type guard to check if a request is an Error Notification request
* Validates the request structure according to the Flow API error specifications
*
* @param request The Flow endpoint request to check
* @returns True if the request is a valid Error Notification request, false otherwise
*/
declare function isFlowErrorRequest(request: FlowEndpointRequest): request is FlowErrorNotificationRequest & {
action: (typeof ERROR_ACTIONS)[number];
screen: string;
flow_token: string;
data: {
error: string;
error_message: string;
};
};
/**
* Type guard to check if a request is a Ping (health check) request
* Simple validation for health check endpoints in the Flow API
*
* @param request The Flow endpoint request to check
* @returns True if the request is a Ping request, false otherwise
*/
declare function isFlowPingRequest(request: FlowEndpointRequest): request is FlowHealthCheckRequest;
interface MetaError extends Error {
error: {
message: string;
type: string;
code: number;
error_data?: {
messaging_product: 'whatsapp';
details: string;
};
error_subcode?: number;
fbtrace_id: string;
};
}
/**
* Determines if the error is a Meta API error response
* @param error Any error object to check
* @returns Type guard indicating if error is a Meta API error
*/
declare function isMetaError(error: any): error is MetaError;
export { type MetaError as M, isFlowErrorRequest as a, isFlowPingRequest as b, isMetaError as c, isFlowDataExchangeRequest as i };