diff --git a/packages/destination-actions/src/destinations/snap-audiences/__tests__/index.test.ts b/packages/destination-actions/src/destinations/snap-audiences/__tests__/index.test.ts index 03132acec8..5a60fbe98b 100644 --- a/packages/destination-actions/src/destinations/snap-audiences/__tests__/index.test.ts +++ b/packages/destination-actions/src/destinations/snap-audiences/__tests__/index.test.ts @@ -20,15 +20,6 @@ const createAudienceInput = { describe('Snap Audiences', () => { describe('createAudience', () => { - beforeEach(() => { - // Catch all Segment API requests and return 200 - nock('https://api.segment.io').persist().post('/v1/track').reply(200) - }) - - afterEach(() => { - nock.cleanAll() - }) - it('should fail if Segment audience name is available', async () => { createAudienceInput.audienceName = '' await expect(testDestination.createAudience(createAudienceInput)).rejects.toThrowError(IntegrationError) diff --git a/packages/destination-actions/src/destinations/snap-audiences/index.ts b/packages/destination-actions/src/destinations/snap-audiences/index.ts index 3ac9cd7c81..ce2a58b7a5 100644 --- a/packages/destination-actions/src/destinations/snap-audiences/index.ts +++ b/packages/destination-actions/src/destinations/snap-audiences/index.ts @@ -1,4 +1,4 @@ -import { AudienceDestinationDefinition, defaultValues, IntegrationError, RequestClient } from '@segment/actions-core' +import { AudienceDestinationDefinition, defaultValues, IntegrationError } from '@segment/actions-core' import type { Settings, AudienceSettings } from './generated-types' import syncAudience from './syncAudience' const ACCESS_TOKEN_URL = 'https://accounts.snapchat.com/login/oauth2/access_token' @@ -116,101 +116,29 @@ const destination: AudienceDestinationDefinition = { const ad_account_id = createAudienceInput.settings.ad_account_id const { customAudienceName, description, retention_in_days } = createAudienceInput.audienceSettings || {} - // Track input values - await sendToSegment( - 'jsYMXBFcHxTHnNfZfwQo5FsL8jVRrjAu', - 'Create Audience Input', - ad_account_id, - { - rawInput: createAudienceInput, - extractedValues: { - audienceName, - ad_account_id, - customAudienceName, - description, - retention_in_days - } - }, - request - ) - if (!audienceName) { throw new IntegrationError('Missing audience name value', 'MISSING_REQUIRED_FIELD', 400) } - const requestBody = { - segments: [ - { - name: customAudienceName !== '' ? customAudienceName : audienceName, - source_type: 'FIRST_PARTY', - ad_account_id, - description, - retention_in_days - } - ] - } - - // Track request details - await sendToSegment( - 'jsYMXBFcHxTHnNfZfwQo5FsL8jVRrjAu', - 'Create Audience Request Details', - ad_account_id, - { - url: `https://adsapi.snapchat.com/v1/adaccounts/${ad_account_id}/segments`, - headers: { - Authorization: 'Bearer [TOKEN HIDDEN]', - 'Content-Type': 'application/json' - }, - requestBody - }, - request - ) - - try { - const response = await request(`https://adsapi.snapchat.com/v1/adaccounts/${ad_account_id}/segments`, { - method: 'POST', - json: { - segments: [ - { - name: customAudienceName !== '' ? customAudienceName : audienceName, - source_type: 'FIRST_PARTY', - ad_account_id, - description, - retention_in_days - } - ] - } as CreateAudienceReq - }) - const data: SnapAudienceResponse = await response.json() - const snapAudienceId = data.segments[0].segment.id + const response = await request(`https://adsapi.snapchat.com/v1/adaccounts/${ad_account_id}/segments`, { + method: 'POST', + json: { + segments: [ + { + name: customAudienceName !== '' ? customAudienceName : audienceName, + source_type: 'FIRST_PARTY', + ad_account_id, + description, + retention_in_days + } + ] + } as CreateAudienceReq + }) - // Track response - await sendToSegment( - 'jsYMXBFcHxTHnNfZfwQo5FsL8jVRrjAu', - 'Create Audience Response', - ad_account_id, - { - status: response.status, - responseData: data, - extractedAudienceId: snapAudienceId - }, - request - ) + const data: SnapAudienceResponse = await response.json() + const snapAudienceId = data.segments[0].segment.id - return { externalId: snapAudienceId } - } catch (error) { - // Error response - await sendToSegment( - 'jsYMXBFcHxTHnNfZfwQo5FsL8jVRrjAu', - 'Create Audience Error', - ad_account_id, - { - error: error.response.data - }, - request - ) - } - return { externalId: '1234' } + return { externalId: snapAudienceId } }, getAudience: async (request, { externalId }) => { @@ -229,24 +157,4 @@ const destination: AudienceDestinationDefinition = { } } -async function sendToSegment(writeKey: any, event: string, userId: string, properties: any, request: RequestClient) { - const response = await request('https://api.segment.io/v1/track', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Basic ${Buffer.from(writeKey).toString('base64')}` - }, - json: { - event, - userId, - properties - } - }) - - if (!response.ok) { - throw new Error(`Failed to send event to Segment: ${response.statusText}`) - } - - return response -} export default destination