Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[STRATCONN-3832] Validate Audience Field inputs while creating Audience" #2129

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
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
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
Loading