Skip to content

Commit df05351

Browse files
abhandageCopilot
andauthored
tier-1/batch-2: refactor API versioning to use versioning-info module (#3471)
* tier 1 batch 2 * tier 1 batch 2 * Update packages/destination-actions/src/destinations/reddit-conversions-api/index.ts Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent b276479 commit df05351

File tree

19 files changed

+127
-77
lines changed

19 files changed

+127
-77
lines changed

packages/destination-actions/src/destinations/adobe-target/adobeTarget_operations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RequestClient, IntegrationError, APIError } from '@segment/actions-core'
22
import { StatsContext } from '@segment/actions-core/destination-kit'
3+
import { ADOBE_TARGET_API_VERSION } from './versioning-info'
34

45
function getNestedObjects(obj: { [x: string]: any }, objectPath = '', attributes: { [x: string]: string } = {}) {
56
// Do not run on null or undefined
@@ -60,7 +61,7 @@ export default class AdobeTarget {
6061
): Promise<IntegrationError | undefined> => {
6162
try {
6263
await this.request(
63-
`https://${clientCode}.tt.omtrdc.net/rest/v1/profiles/thirdPartyId/${userId}?client=${clientCode}`,
64+
`https://${clientCode}.tt.omtrdc.net/rest/${ADOBE_TARGET_API_VERSION}/profiles/thirdPartyId/${userId}?client=${clientCode}`,
6465
{ method: 'get', skipResponseCloning: true }
6566
)
6667
} catch (error) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** ADOBE_TARGET_API_VERSION
2+
* Endpoint segment uses: /rest/v1/profiles/thirdPartyId/{userId}
3+
* API reference: https://experienceleague.adobe.com/en/docs/target-dev/developer/api/profile-apis/profiles-api
4+
*/
5+
export const ADOBE_TARGET_API_VERSION = 'v1'

packages/destination-actions/src/destinations/pinterest-conversions/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const API_VERSION = 'v5'
1+
import { PINTEREST_CONVERSIONS_API_VERSION } from './versioning-info'
2+
3+
export const API_VERSION = PINTEREST_CONVERSIONS_API_VERSION
24
export const EVENT_NAME = {
35
ADD_TO_CART: 'add_to_cart',
46
CHECKOUT: 'checkout',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** PINTEREST_CONVERSIONS_API_VERSION
2+
* Pinterest conversions API version.
3+
* API reference: https://developers.pinterest.com/docs/api/v5/introduction
4+
*/
5+
export const PINTEREST_CONVERSIONS_API_VERSION = 'v5'

packages/destination-actions/src/destinations/reddit-conversions-api/index.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Settings } from './generated-types'
33
import type { RedditConversionsTestAuthenticationError } from './types'
44
import standardEvent from './standardEvent'
55
import customEvent from './customEvent'
6+
import { REDDIT_CONVERSIONS_API_VERSION } from './versioning-info'
67

78
const destination: DestinationDefinition<Settings> = {
89
name: 'Reddit Conversions API',
@@ -35,33 +36,36 @@ const destination: DestinationDefinition<Settings> = {
3536
},
3637
testAuthentication: async (request, { settings }) => {
3738
try {
38-
return await request(`https://ads-api.reddit.com/api/v2.0/conversions/events/${settings.ad_account_id}`, {
39-
method: 'POST',
40-
headers: {
41-
Authorization: `Bearer ${settings.conversion_token}`
42-
},
43-
json: {
44-
test_mode: true,
45-
events: [
46-
{
47-
event_at: new Date().toISOString(),
48-
user: {
49-
50-
external_id: 'identity-test',
51-
ip_address: '127.0.0.1',
52-
user_agent: 'Mozilla/5.0'
53-
},
54-
event_type: {
55-
tracking_type: 'PageVisit'
56-
},
57-
event_metadata: {
58-
currency: 'USD',
59-
value_decimal: 1
39+
return await request(
40+
`https://ads-api.reddit.com/api/${REDDIT_CONVERSIONS_API_VERSION}/conversions/events/${settings.ad_account_id}`,
41+
{
42+
method: 'POST',
43+
headers: {
44+
Authorization: `Bearer ${settings.conversion_token}`
45+
},
46+
json: {
47+
test_mode: true,
48+
events: [
49+
{
50+
event_at: new Date().toISOString(),
51+
user: {
52+
53+
external_id: 'identity-test',
54+
ip_address: '127.0.0.1',
55+
user_agent: 'Mozilla/5.0'
56+
},
57+
event_type: {
58+
tracking_type: 'PageVisit'
59+
},
60+
event_metadata: {
61+
currency: 'USD',
62+
value_decimal: 1
63+
}
6064
}
61-
}
62-
]
65+
]
66+
}
6367
}
64-
})
68+
)
6569
} catch (err) {
6670
const error = err as RedditConversionsTestAuthenticationError
6771
if (error.response && error.response.status === 401) {

packages/destination-actions/src/destinations/reddit-conversions-api/utils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
DatapProcessingOptions
1212
} from './types'
1313
import { processHashing } from '../../lib/hashing-utils'
14+
import { REDDIT_CONVERSIONS_API_VERSION } from './versioning-info'
1415

1516
type EventMetadataType = StandardEvent['event_metadata'] | CustomEvent['event_metadata']
1617
type ProductsType = StandardEvent['products'] | CustomEvent['products']
@@ -21,11 +22,14 @@ type ScreenDimensionsType = StandardEvent['screen_dimensions'] | CustomEvent['sc
2122

2223
export async function send(request: RequestClient, settings: Settings, payload: StandardEvent[] | CustomEvent[]) {
2324
const data = createRedditPayload(payload, settings)
24-
return request(`https://ads-api.reddit.com/api/v2.0/conversions/events/${settings.ad_account_id}`, {
25-
method: 'POST',
26-
headers: { Authorization: `Bearer ${settings.conversion_token}` },
27-
json: JSON.parse(JSON.stringify(data))
28-
})
25+
return request(
26+
`https://ads-api.reddit.com/api/${REDDIT_CONVERSIONS_API_VERSION}/conversions/events/${settings.ad_account_id}`,
27+
{
28+
method: 'POST',
29+
headers: { Authorization: `Bearer ${settings.conversion_token}` },
30+
json: JSON.parse(JSON.stringify(data))
31+
}
32+
)
2933
}
3034

3135
function createRedditPayload(payloads: StandardEvent[] | CustomEvent[], settings: Settings): StandardEventPayload {
@@ -170,7 +174,7 @@ const smartHash = (value: string | undefined, cleaningFunction?: (value: string)
170174
}
171175

172176
function cleanPhoneNumber(phoneNumber: string): string {
173-
if (!phoneNumber) return ""
177+
if (!phoneNumber) return ''
174178
phoneNumber = phoneNumber.trim()
175179
const prefix = '+'
176180
if (phoneNumber.startsWith('+')) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** REDDIT_CONVERSIONS_API_VERSION
2+
* Reddit conversions API version.
3+
* API reference: https://ads-api.reddit.com/docs/v2/changelog
4+
*/
5+
export const REDDIT_CONVERSIONS_API_VERSION = 'v2.0'

packages/destination-actions/src/destinations/snap-conversions-api/reportConversionEvent/snap-capi-v3.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
smartHash
1515
} from './utils'
1616
import { processHashing } from '../../../lib/hashing-utils'
17+
import { SNAP_CONVERSIONS_API_VERSION } from '../versioning-info'
1718

1819
const CURRENCY_ISO_4217_CODES = new Set([
1920
'USD',
@@ -687,7 +688,7 @@ const buildRequestURL = (settings: Settings, action_source: string | undefined,
687688
})()
688689
)
689690

690-
return `https://tr.snapchat.com/v3/${appOrPixelID}/events?access_token=${authToken}`
691+
return `https://tr.snapchat.com/${SNAP_CONVERSIONS_API_VERSION}/${appOrPixelID}/events?access_token=${authToken}`
691692
}
692693

693694
const validatePayload = (payload: ReturnType<typeof buildPayloadData>) => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** SNAP_CONVERSIONS_API_VERSION
2+
* Snapchat Conversions API version.
3+
* API reference: https://developers.snap.com/api/marketing-api/Conversions-API/UsingTheAPI
4+
*/
5+
export const SNAP_CONVERSIONS_API_VERSION = 'v3'

packages/destination-actions/src/destinations/tiktok-audiences/__tests__/index.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import nock from 'nock'
22
import { createTestIntegration, IntegrationError } from '@segment/actions-core'
3-
import { BASE_URL, GET_AUDIENCE_URL, TIKTOK_API_VERSION } from '../constants'
3+
import { BASE_URL, GET_AUDIENCE_URL } from '../constants'
44
import Destination from '../index'
5+
import { TIKTOK_AUDIENCES_API_VERSION } from '../versioning-info'
56

67
const testDestination = createTestIntegration(Destination)
78

@@ -94,7 +95,7 @@ describe('TikTok Audiences', () => {
9495

9596
it('should create a new TikTok Audience', async () => {
9697
nock(BASE_URL)
97-
.post(`/${TIKTOK_API_VERSION}/segment/audience/`, {
98+
.post(`/${TIKTOK_AUDIENCES_API_VERSION}/segment/audience/`, {
9899
custom_audience_name: 'The Super Mario Brothers Fans',
99100
advertiser_id: '42884288',
100101
action: 'create'

0 commit comments

Comments
 (0)