import { ActionParam } from '@memberjunction/actions-base'; import { BaseAction, OAuth2Manager } from '@memberjunction/actions'; import { UserInfo } from '@memberjunction/core'; import { MJCompanyIntegrationEntity } from '@memberjunction/core-entities'; /** * Common response structure for form submissions */ export interface FormResponse { responseId: string; formId: string; submittedAt: Date; completed: boolean; answerDetails: FormAnswer[]; answers?: Record; metadata?: { browser?: string; platform?: string; referer?: string; userAgent?: string; }; calculatedFields?: Record; hiddenFields?: Record; } /** * Structure for individual form answers */ export interface FormAnswer { fieldId: string; fieldType: string; question: string; answer: any; choices?: string[]; } /** * Statistics structure for form responses */ export interface FormStatistics { totalResponses: number; completedResponses: number; partialResponses: number; completionRate: number; averageCompletionTime?: number; responsesByDate?: Record; topAnswers?: Record> | Array<{ answer: string; count: number; }>; } /** * Base class for all form builder-related actions. * Provides common functionality and patterns for interacting with form/survey platforms. */ export declare abstract class BaseFormBuilderAction extends BaseAction { /** * The form platform this action is designed for (e.g., 'Typeform', 'Google Forms', etc.) */ protected abstract formPlatform: string; /** * The integration name to look up in the Integration entity */ protected abstract integrationName: string; /** * Cached company integration for the current execution */ private _companyIntegration; /** * Common form builder parameters that many actions will need. * CompanyID is required for secure credential lookup. * FormID is the platform-specific form identifier. */ protected getCommonFormParams(): ActionParam[]; /** * Gets the company integration record for the specified company and form platform */ protected getCompanyIntegration(companyId: string, contextUser: UserInfo): Promise; /** * Gets credentials from environment variables * Format: BIZAPPS_{PROVIDER}_{COMPANY_ID}_{CREDENTIAL_TYPE} * Example: BIZAPPS_TYPEFORM_12345_API_TOKEN * * Falls back to: BIZAPPS_{PROVIDER}_{CREDENTIAL_TYPE} if no company-specific credential found * Example fallback: BIZAPPS_TYPEFORM_API_TOKEN */ protected getCredentialFromEnv(companyId: string, credentialType: string): string | undefined; /** * Gets API credentials - first tries environment variables, then falls back to database */ protected getAPICredentials(integration: MJCompanyIntegrationEntity): Promise<{ apiToken?: string; apiKey?: string; accessToken?: string; }>; /** * Helper to securely retrieve API token for a company. * This method should be used by all form builder actions instead of accepting tokens as parameters. * * @param companyId - The MemberJunction company ID (required) * @param contextUser - The user context for database queries * @returns The API token for the specified company * @throws Error if no credentials are found or company integration is not configured */ protected getSecureAPIToken(companyId: string | null | undefined, contextUser: UserInfo): Promise; /** * Creates an OAuth2Manager instance for the specified company. * Override this method in provider-specific base classes to configure OAuth2 endpoints. * * @param companyId - The MemberJunction company ID * @param contextUser - The user context * @returns OAuth2Manager instance or null if OAuth2 is not configured */ protected createOAuth2Manager(companyId: string, contextUser: UserInfo): Promise; /** * Helper to get parameter value with type safety */ protected getParamValue(params: ActionParam[], paramName: string): any; /** * Standard date format for form platforms (ISO 8601) */ protected formatFormDate(date: Date): string; /** * Parse date from form platform format */ protected parseFormDate(dateString: string | number): Date; /** * Calculate completion rate percentage */ protected calculateCompletionRate(completed: number, total: number): number; /** * Format duration in seconds to human readable format */ protected formatDuration(seconds: number): string; /** * Helper to build consistent error messages for form operations */ protected buildFormErrorMessage(operation: string, details: string, systemError?: any): string; /** * Extract email addresses from response answers */ protected extractEmailFromResponses(responses: FormResponse[]): string[]; /** * Group responses by date */ protected groupResponsesByDate(responses: FormResponse[]): Record; /** * Calculate average completion time from responses */ protected calculateAverageCompletionTime(responses: FormResponse[]): number | undefined; /** * Find most common answers for choice fields */ protected findTopAnswers(responses: FormResponse[], fieldId: string, limit?: number): Array<{ answer: string; count: number; }>; /** * Convert responses to CSV format */ protected convertToCSV(responses: FormResponse[], includeMetadata?: boolean, delimiter?: string): { csv: string; headers: string[]; }; } //# sourceMappingURL=base-form-builder.action.d.ts.map