import { EventEmitter } from 'events'; import createRequestClient from '../create-request-client'; import { JSONLikeObject, JSONObject } from '../json-object'; import { InputData, Features } from '../mapping-kit'; import type { DynamicFieldResponse, InputField, RequestExtension, ExecuteInput, Result, SyncModeDefinition, DynamicFieldContext, ActionDestinationSuccessResponseType, ActionDestinationErrorResponseType, ResultMultiStatusNode, AudienceMembership } from './types'; import type { JSONSchema4 } from 'json-schema'; import { AuthTokens } from './parse-settings'; import { Logger, StatsContext, Personas, TransactionContext, StateContext, EngageDestinationCache, SubscriptionMetadata } from './index'; type MaybePromise = T | Promise; type RequestClient = ReturnType; export type RequestFn = (request: RequestClient, data: ExecuteInput) => MaybePromise; interface ReservedInputFields { batch_keys?: { label: string; description: string; type: 'string'; unsafe_hidden?: true; multiple?: true; required?: false; default?: string[]; }; } type ActionFields = Omit, keyof ReservedInputFields> & ReservedInputFields; export interface BaseActionDefinition { title: string; description: string; platform?: 'cloud' | 'web'; defaultSubscription?: string; hidden?: boolean; fields: ActionFields; } type HookValueTypes = string | boolean | number | Array; type GenericActionHookValues = Record; type IsArray = T extends (infer U)[] ? U : never; type PerformBatchResponse = MaybePromise | MaybePromise; export interface ActionDefinition extends BaseActionDefinition { dynamicFields?: { [K in keyof Payload]?: IsArray extends never ? Payload[K] extends object | undefined ? { [ObjectProperty in keyof NonNullable | '__keys__' | '__values__']?: RequestFn; } : RequestFn : IsArray extends object ? { [ObjectProperty in keyof NonNullable> | '__keys__' | '__values__']?: RequestFn; } : never; }; perform: RequestFn; performBatch?: RequestFn; hooks?: { [K in ActionHookType]?: ActionHookDefinition, NonNullable>; }; syncMode?: SyncModeDefinition; } export declare const hookTypeStrings: readonly ["onMappingSave", "retlOnMappingSave"]; export type ActionHookType = typeof hookTypeStrings[number]; export interface ActionHookResponse { successMessage?: string; savedData?: GeneratedActionHookOutputs; error?: { message: string; code: string; }; } export interface ActionHookDefinition { label: string; description: string; inputFields?: Record & { dynamic?: RequestFn; }>; outputTypes?: Record; performHook: RequestFn, AudienceSettings, GeneratedActionHookTypesInputs>; } export interface ExecuteDynamicFieldInput { settings: Settings; audienceSettings?: AudienceSettings; payload: Payload; page?: string; auth?: AuthTokens; features?: Features | undefined; statsContext?: StatsContext | undefined; hookInputs?: GenericActionHookValues; dynamicFieldContext?: DynamicFieldContext; } interface ExecuteBundle { data: Data; settings: T; audienceSettings?: AudienceSettings; mapping: JSONObject; auth: AuthTokens | undefined; hookOutputs?: Record; features?: Features | undefined; statsContext?: StatsContext | undefined; personasContext?: Personas | undefined; logger?: Logger | undefined; engageDestinationCache?: EngageDestinationCache; transactionContext?: TransactionContext; stateContext?: StateContext; subscriptionMetadata?: SubscriptionMetadata; signal?: AbortSignal; } export declare class Action extends EventEmitter { readonly definition: ActionDefinition; readonly destinationName: string; readonly schema?: JSONSchema4; readonly hookSchemas?: Record; readonly hasBatchSupport: boolean; readonly hasHookSupport: boolean; private extendRequest; constructor(destinationName: string, definition: ActionDefinition, extendRequest?: RequestExtension); execute(bundle: ExecuteBundle): Promise; executeBatch(bundle: ExecuteBundle): Promise; private extractFieldContextAndHandler; executeDynamicField(field: string, data: ExecuteDynamicFieldInput, dynamicFn?: RequestFn): Promise; executeHook(hookType: ActionHookType, data: ExecuteInput): Promise>; private performRequest; private createRequestClient; private afterResponse; private parseResponse; private fillMultiStatusResponse; } export declare class ActionDestinationSuccessResponse { private data; constructor(data: ActionDestinationSuccessResponseType); value(): ActionDestinationSuccessResponseType; } export declare class ActionDestinationErrorResponse { private data; constructor(data: ActionDestinationErrorResponseType); value(): ActionDestinationErrorResponseType; } export declare class MultiStatusResponse { private responses; length(): number; pushResponseObject(response: ActionDestinationSuccessResponse | ActionDestinationErrorResponse): void; pushSuccessResponse(response: ActionDestinationSuccessResponse | ActionDestinationSuccessResponseType): void; pushErrorResponse(response: ActionDestinationErrorResponse | ActionDestinationErrorResponseType): void; pushResponseObjectAtIndex(index: number, response: ActionDestinationSuccessResponse | ActionDestinationErrorResponse): void; setSuccessResponseAtIndex(index: number, response: ActionDestinationSuccessResponse | ActionDestinationSuccessResponseType): void; setErrorResponseAtIndex(index: number, response: ActionDestinationErrorResponse | ActionDestinationErrorResponseType): void; unsetResponseAtIndex(index: number): void; isSuccessResponseAtIndex(index: number): boolean; isErrorResponseAtIndex(index: number): boolean; getResponseAtIndex(index: number): ActionDestinationSuccessResponse | ActionDestinationErrorResponse; getAllResponses(): (ActionDestinationSuccessResponse | ActionDestinationErrorResponse)[]; } export {};