Skip to content

Commit

Permalink
[S3] - fixing s3 destination (#2425)
Browse files Browse the repository at this point in the history
* fixing s3 destination

* fixing s3 destination

* making batch optional

* fixing bad import
  • Loading branch information
joe-ayoub-segment authored Sep 19, 2024
1 parent 508182a commit 4b75a0f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/destination-actions/src/destinations/s3/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ export const commonFields: ActionDefinition<Settings>['fields'] = {
type: 'boolean',
label: 'Enable Batching',
description: 'Enable Batching Hidden Field',
unsafe_hidden: true,
unsafe_hidden: false,
required: true,
default: true
},
batch_size: {
label: 'Batch Size',
description: 'Maximum number of events to include in each batch. Actual batch sizes may be lower.',
description:
'Maximum number of events to include in each batch. Actual batch sizes may be lower. Max batch size is 25000.',
type: 'number',
unsafe_hidden: true,
required: false,
default: 25000
},
Expand Down
8 changes: 8 additions & 0 deletions packages/destination-actions/src/destinations/s3/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import { Payload } from './syncToS3/generated-types'
import { Settings } from './generated-types'
import { Client } from './client'
import { RawMapping } from './types'
import { IntegrationError } from '@segment/actions-core'

export async function send(payloads: Payload[], settings: Settings, rawMapping: RawMapping) {

const batchSize = payloads[0] && typeof payloads[0].batch_size === 'number' ? payloads[0].batch_size : 0

if(batchSize > 25000) {
throw new IntegrationError('Batch size cannot exceed 25000', 'Invalid Payload', 400)
}

const headers = Object.keys(rawMapping.columns).map((column) => {
return snakeCase(column)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { commonFields } from '../fields'
import { send } from '../functions'
import { SingleData, BatchData, RawMapping } from '../types'
import { Data, RawMapping } from '../types'

const action: ActionDefinition<Settings, Payload> = {
title: 'Sync to S3',
Expand All @@ -12,13 +12,13 @@ const action: ActionDefinition<Settings, Payload> = {
fields: commonFields,
perform: async (_, data) => {
const { payload, settings } = data
const rawMapping: RawMapping = (data as unknown as SingleData).rawMapping
const rawMapping: RawMapping = (data as unknown as Data).rawMapping
return send([payload], settings, rawMapping)
},
performBatch: async (_, data) => {
const { payload, settings } = data
const rawMapping: RawMapping[] = (data as unknown as BatchData).rawMapping
return send(payload, settings, rawMapping[0])
const rawMapping: RawMapping = (data as unknown as Data).rawMapping
return send(payload, settings, rawMapping)
}
}

Expand Down
6 changes: 1 addition & 5 deletions packages/destination-actions/src/destinations/s3/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ export interface Credentials {
sessionToken: string
}

export interface SingleData {
export interface Data {
rawMapping: RawMapping
}

export interface BatchData {
rawMapping: RawMapping[]
}

export interface RawMapping {
columns: {
[k: string]: unknown
Expand Down

0 comments on commit 4b75a0f

Please sign in to comment.