import { IntegrationAction, IntegrationDefinition, IntegrationInstance } from './../../jupiter-types/integration'; import { IntegrationInstanceConfigFieldMap } from './config'; import { IntegrationExecutionHandler } from './execution'; import IntegrationLogger from './IntegrationLogger'; import { GetIntegrationStepStartStates, IntegrationStepPhase } from './step-functions'; /** * An integration invocation event, carried throughout the activity associated * with the invocation of the integration. * * This is built when the integration is invoked with an * `IntegrationActionTriggerEvent`. The `IntegrationInvocationEvent` carries * over relevant properties and adds the `timestamp` of the invocation, and is * passed through the Step Functions state machine. * * Note that the Lambda request ID is not included, since that will be different * in each step when an integration is implemented across multiple Lambda * functions. */ export interface IntegrationInvocationEvent { /** * Identifies the tenant/account holder that activated the integration. */ readonly accountId: string; /** * The ID of the integration instance associated with the invocation. */ readonly integrationInstanceId: string; /** * The action that should be taken by the `IntegrationExecutionHandler`, * determined by whatever mechanism invokes the integration. */ readonly action: IntegrationAction; /** * The timestamp defined at integration invocation start time. This must be * used as the timestamp of operations generated throughout the execution of * an integration job. */ readonly timestamp: number; } /** * The context of an invocation, containing the `IntegrationInvocationEvent` to * provide invocation-specific tracing facilities. * * As an integration processes an invocation event, each step of the process is * provided context that includes the input delivered to the compute process, * the `event` property. In a multi-step integration, the * `IntegrationInvocationContext` may be extended to include additional, * step-specific input, and so extend the `event` as well. Search for types * which extend this one to learn more. */ export interface IntegrationInvocationContext { /** * The invocation event leading to the execution of the integration. */ readonly event: IntegrationInvocationEvent; /** * A logger configured to include information about the integration, used to * create descendant loggers as more context is acquired. */ readonly logger: IntegrationLogger; /** * A function capable of validating the integration invocation. */ readonly invocationValidator: IntegrationInvocationValidator; /** * Optional arguments provided by the execution environment to integration * invocation handling code. * * This is a weak contract in TypeScript terms; it is up to the integration to * communicate its requirements to the execution environment. */ readonly invocationArgs?: IntegrationInvocationArguments; } /** * The context necessary for validating an integration invocation instance, * provided to `IntegrationInvocationValidator` functions before execution * proceeds. */ export interface IntegrationValidationContext extends IntegrationInvocationContext { /** * The IntegrationDefinition represents information about this integration. * There is one definition no matter the number of configured instances. */ readonly definition: IntegrationDefinition; /** * The IntegrationInstance represents information about a particular * configuration of the integration, allowing the integration to operate on * behalf of the tenant/account holder represented by the * IntegrationInstance. */ readonly instance: IntegrationInstance; /** * A logger configured to include information about the current run of the * integration, allowing for tracing the run across steps in the process. */ readonly logger: IntegrationLogger; } /** * Integration-specific arguments provided to the integration by the execution * environment. * * The integration may need additional arguments that must be provided by the * execution environment. One example is provider credentials that are shared * across all integration instances, not provided by the user of the * integration. */ export interface IntegrationInvocationArguments { [argName: string]: any; } /** * Provides integration execution information to the runtime environment. * * Integrations are modules that must export from their `index` entry point an * instance of this type, which the runtime execution environment will use to * run the integration. */ export interface IntegrationInvocationConfig { invocationValidator: IntegrationInvocationValidator; executionHandler?: IntegrationExecutionHandler; integrationStepPhases?: IntegrationStepPhase[]; /** * Allows the integration to prepare state for the machine executing the steps * contained in the `integrationStepPhases`. */ getStepStartStates?: GetIntegrationStepStartStates; /** * Metadata about the properties of an integration instance configuration. */ instanceConfigFields?: IntegrationInstanceConfigFieldMap; } /** * A function that is capable of validating the integration invocation at the * start of execution, throwing an error to signal the job must be ended immediately. * * The validator function may throw an `IntegrationInstanceConfigError` with * enough information to communicate how the config may be corrected, but this * is not meant to drive a complex UI, only prevent the integration from carrying * on with an invalid config. * * The validator function may throw an `IntegrationInstanceAuthenticationError` * when the integration is unable to authenticate with the integration partner. * * This is async to allow for the possibility that validation may include some * sort of I/O, such as validating credentials. * * @param validationContext the `IntegrationValidationContext` */ export interface IntegrationInvocationValidator { (validationContext: IntegrationValidationContext): Promise; }