Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SafeParseError } from 'zod'
import { fromZodError } from 'zod-validation-error'

import StepError from '@/errors/step'
import { TableVariableMarker } from '@/helpers/compute-parameters'
import { formatTable, TableData } from '@/helpers/format-table-variable'
import logger from '@/helpers/logger'
import Step from '@/models/step'

Expand All @@ -22,12 +24,49 @@ import { sendInvalidAttachmentsEmail } from '../../common/send-invalid-attachmen
import { throwPostmanStepError } from '../../common/throw-errors'

import getDataOutMetadata from './get-data-out-metadata'
/**
* Type guard to check if a value is a TableVariableMarker
*/
function isTableMarker(value: unknown): value is TableVariableMarker {
return (
typeof value === 'object' &&
value !== null &&
'__type' in value &&
(value as TableVariableMarker).__type === 'table'
)
}

const action: IRawAction = {
name: 'Send email',
key: 'sendTransactionalEmail',
description: 'Sends an email using Postman',
arguments: transactionalEmailFields,

preprocessVariable(key: string, value: unknown) {
// Handle table variable markers - convert to HTML table
if (isTableMarker(value)) {
// Only allow table rendering in the body field
if (key !== 'body') {
// Return placeholder for unsupported fields
return '[Table variables are only supported in the email body]'
}

const result = formatTable(value.data as TableData, {
selectedColumnIds: value.selectedColumnIds,
})

if (result.success === false) {
// Return error message as placeholder instead of failing the step
return `[Table Error: ${result.message}]`
}

return result.output
}

// Return unchanged for non-table values
return value
},

doesFileProcessing: (step: Step) => {
return (
step.parameters.attachments &&
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/apps/postman/common/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export const transactionalEmailFields: IField[] = [
type: 'rich-text' as const,
required: true,
variables: true,
variableTypes: [
'text',
'array',
'tile_row_id',
'approval',
'ai_response',
'table',
],
},
{
label: 'Recipient email(s)',
Expand Down
1 change: 1 addition & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ export type TRteMenuOption =
export interface IFieldRichText extends IBaseField {
type: 'rich-text'
value?: string
variableTypes?: TDataOutMetadatumType[]

// Specifies the order and what menu options to show in the RTE
// 'Divider' is specified manually to determine when a divider should be shown
Expand Down
Loading