Skip to content

Commit

Permalink
Revert "[STRATCONN-3832] Validate Audience Field inputs while creatin…
Browse files Browse the repository at this point in the history
…g Audien…" (segmentio#2129)

This reverts commit a76c78d.
  • Loading branch information
varadarajan-tw authored Jul 2, 2024
1 parent 50108aa commit 0cc866b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 38 deletions.
9 changes: 1 addition & 8 deletions packages/core/src/destination-kit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { AuthTokens, getAuthData, getOAuth2Data, updateOAuthSettings } from './p
import { InputData, Features } from '../mapping-kit'
import { retry } from '../retry'
import { HTTPError } from '..'
import isEmpty from 'lodash/isEmpty'

export type {
BaseActionDefinition,
Expand Down Expand Up @@ -95,15 +94,12 @@ export type AudienceResult = {
}

export type AudienceMode = { type: 'realtime' } | { type: 'synced'; full_audience_sync: boolean }
export type Personas = { computation_id: 'string'; computation_key: 'string' }

export type CreateAudienceInput<Settings = unknown, AudienceSettings = unknown> = {
settings: Settings

audienceSettings?: AudienceSettings

personas?: Personas

audienceName: string

statsContext?: StatsContext
Expand Down Expand Up @@ -430,10 +426,6 @@ export class Destination<Settings = JSONObject, AudienceSettings = JSONObject> {
if (!instanceOfAudienceDestinationSettingsWithCreateGet(audienceDefinition.audienceConfig)) {
throw new Error('Unexpected call to createAudience')
}
//validate audienceField Input
if (!isEmpty(createAudienceInput.audienceSettings)) {
validateSchema(createAudienceInput.audienceSettings, fieldsToJsonSchema(audienceDefinition.audienceFields))
}
const destinationSettings = this.getDestinationSettings(createAudienceInput.settings as unknown as JSONObject)
const auth = getAuthData(createAudienceInput.settings as unknown as JSONObject)
const context: ExecuteInput<Settings, any, AudienceSettings> = {
Expand All @@ -444,6 +436,7 @@ export class Destination<Settings = JSONObject, AudienceSettings = JSONObject> {
}
const options = this.extendRequest?.(context) ?? {}
const requestClient = createRequestClient({ ...options, statsContext: context.statsContext })

return audienceDefinition.audienceConfig?.createAudience(requestClient, createAudienceInput)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,6 @@ describe('Amazon-Ads (actions)', () => {

await expect(testDestination.createAudience(createAudienceInputTemp)).rejects.toThrowError('Bad Request')
})
it('Should throw an error when invalid cpmCent is provided', async () => {
const createAudienceInput = {
settings,
audienceName: 'Test Audience',
audienceSettings: {
...audienceSettings,
ttl: '12345678',
currency: 'USD',
cpmCents: 'invalid cpm cents'
}
}

await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(
'CPM Cents must be a number but it was a string.'
)
})

it('creates an audience', async () => {
const endpoint = AUTHORIZATION_URL[`${settings.region}`]
Expand All @@ -167,9 +151,9 @@ describe('Amazon-Ads (actions)', () => {
audienceName: 'Test Audience',
audienceSettings: {
...audienceSettings,
ttl: '12345678',
ttl: 12345678,
currency: 'USD',
cpmCents: '1234'
cpmCents: 1234
}
}

Expand Down
12 changes: 10 additions & 2 deletions packages/destination-actions/src/destinations/amazon-amc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,22 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
}

if (ttl) {
payload.metadata.ttl = ttl
const timeToLive = Number(ttl)
if (!timeToLive) {
throw new IntegrationError('TTL:-String can not be converted to Number', 'INVALID_TTL_VALUE', 400)
}
payload.metadata.ttl = timeToLive
}

if (cpm_cents && currency) {
const cpmCents = Number(cpm_cents)
if (!cpmCents) {
throw new IntegrationError('CPM_CENTS:-String can not be converted to Number', 'INVALID_CPMCENTS_VALUE', 400)
}
payload.metadata.audienceFees = []
payload.metadata?.audienceFees.push({
currency,
cpmCents: cpm_cents
cpmCents: cpmCents
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import nock from 'nock'
import { createTestIntegration, IntegrationError } from '@segment/actions-core'
import Destination, { FACEBOOK_API_VERSION } from '../index'

const adAccountId = '1500000000000000'
const adAccountId = 1500000000000000
const audienceId = '1506489116128966'
const testDestination = createTestIntegration(Destination)
const getAudienceUrl = `https://graph.facebook.com/${FACEBOOK_API_VERSION}/`
Expand All @@ -29,7 +29,7 @@ describe('Facebook Custom Audiences', () => {

it('should fail if no ad account ID is set', async () => {
createAudienceInput.audienceName = 'The Void'
createAudienceInput.audienceSettings.adAccountId = ''
createAudienceInput.audienceSettings.adAccountId = 0
await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const getAudienceInput = {
audienceSettings: {}
}



describe('Taboola (actions)', () => {
describe('testAuthentication', () => {
it('should validate authentication inputs', async () => {
Expand All @@ -31,6 +33,7 @@ describe('Taboola (actions)', () => {

describe('createAudience', () => {
it('should fail if no audience name is set', async () => {

const createAudienceInput1 = {
settings: {
client_id: 'test_client_id',
Expand All @@ -40,7 +43,7 @@ describe('Taboola (actions)', () => {
audienceSettings: {
ttl_in_hours: 1024,
exclude_from_campaigns: false,
account_id: accountId
account_id:accountId
}
}

Expand All @@ -50,6 +53,7 @@ describe('Taboola (actions)', () => {
})

it('should fail if no account ID is set', async () => {

const createAudienceInput2 = {
settings: {
client_id: 'test_client_id',
Expand All @@ -59,7 +63,7 @@ describe('Taboola (actions)', () => {
audienceSettings: {
ttl_in_hours: 1024,
exclude_from_campaigns: false,
account_id: ''
account_id:''
}
}

Expand All @@ -81,7 +85,7 @@ describe('Taboola (actions)', () => {
audienceSettings: {
ttl_in_hours: 1024,
exclude_from_campaigns: false,
account_id: accountId
account_id:accountId
}
}
const r = await testDestination.createAudience(createAudienceInput3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ const createAudienceInput = {
customer_desc: CUST_DESC
},
audienceName: '',
audienceSettings: {},
personas: {
computation_key: AUDIENCE_KEY,
computation_id: AUDIENCE_ID
audienceSettings: {
personas: {
computation_key: AUDIENCE_KEY,
computation_id: AUDIENCE_ID
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
},

async createAudience(request, createAudienceInput) {
const audienceSettings = createAudienceInput.audienceSettings
// @ts-ignore type is not defined, and we will define it later
const personas = createAudienceInput.personas as PersonasSettings
const personas = audienceSettings.personas as PersonasSettings
if (!personas) {
throw new IntegrationError('Missing computation parameters: Id and Key', 'MISSING_REQUIRED_FIELD', 400)
}
Expand Down

0 comments on commit 0cc866b

Please sign in to comment.