Skip to content

Commit

Permalink
feat: add v3 api support to appsflyer (#3412)
Browse files Browse the repository at this point in the history
* feat: initial commit

* feat: onboarding adjust source (#3395)

* fix: onboard adjust source

* feat: onboard adjust source

* feat: small edit

* feat: small edit

* fix: fb custom audience html response (#3402)

* fix: adding test cases for old and new config

* fix: review comments addressed

---------

Co-authored-by: AASHISH MALIK <[email protected]>
  • Loading branch information
shrouti1507 and aashishmalik authored Jun 7, 2024
1 parent 0cccd58 commit e124470
Show file tree
Hide file tree
Showing 5 changed files with 2,197 additions and 237 deletions.
2 changes: 2 additions & 0 deletions src/v0/destinations/af/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const Event = {
};

const ENDPOINT = 'https://api2.appsflyer.com/inappevent/';
const ENDPOINT_V2 = 'https://api3.appsflyer.com/inappevent/';

const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

Expand All @@ -69,6 +70,7 @@ events.forEach((event) => {
module.exports = {
ConfigCategory,
ENDPOINT,
ENDPOINT_V2,
Event,
mappingConfig,
nameToEventMap,
Expand Down
44 changes: 36 additions & 8 deletions src/v0/destinations/af/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@ const {
simpleProcessRouterDest,
} = require('../../util');

const { Event, ENDPOINT, ConfigCategory, mappingConfig, nameToEventMap } = require('./config');
const {
Event,
ENDPOINT,
ENDPOINT_V2,
ConfigCategory,
mappingConfig,
nameToEventMap,
} = require('./config');
const { JSON_MIME_TYPE } = require('../../util/constant');

function responseBuilderSimple(payload, message, destination) {
const { androidAppId, appleAppId } = destination.Config;
const { androidAppId, appleAppId, sharingFilter, devKey, s2sKey, authVersion } =
destination.Config;
let endpoint;
const os = get(message, 'context.os.name');
// if ((os && os.toLowerCase() === "android") || (os && isAppleFamily(os))){
// if()
// }

const finalEndPoint =
isDefinedAndNotNull(authVersion) && authVersion === 'v2' ? ENDPOINT_V2 : ENDPOINT;

if (os && os.toLowerCase() === 'android' && androidAppId) {
endpoint = `${ENDPOINT}${androidAppId}`;
endpoint = `${finalEndPoint}${androidAppId}`;
} else if (os && isAppleFamily(os) && appleAppId) {
endpoint = `${ENDPOINT}id${appleAppId}`;
endpoint = `${finalEndPoint}id${appleAppId}`;
} else {
throw new ConfigurationError(
'os name is required along with the respective appId eg. (os->android & Android App Id is required) or (os->ios & Apple App Id is required)',
Expand Down Expand Up @@ -87,16 +99,19 @@ function responseBuilderSimple(payload, message, destination) {
updatedPayload.bundleIdentifier = bundleIdentifier;
}

const { sharingFilter, devKey } = destination.Config;
// const { sharingFilter, devKey } = destination.Config;
if (isDefinedAndNotNullAndNotEmpty(sharingFilter)) {
updatedPayload.sharing_filter = sharingFilter;
}

const finalAuthentication =
isDefinedAndNotNull(authVersion) && authVersion === 'v2' ? s2sKey : devKey;

const response = defaultRequestConfig();
response.endpoint = endpoint;
response.headers = {
'Content-Type': JSON_MIME_TYPE,
authentication: devKey,
authentication: finalAuthentication,
};
response.method = defaultPostRequestConfig.requestMethod;
response.body.JSON = removeUndefinedAndNullValues(updatedPayload);
Expand Down Expand Up @@ -203,6 +218,19 @@ function processEventTypeTrack(message, config) {
}

function processSingleMessage(message, destination) {
const { devKey, s2sKey, authVersion, useRichEventName } = destination.Config;

if (!isDefinedAndNotNull(authVersion) && !isDefinedAndNotNull(devKey)) {
throw new ConfigurationError('No authentication key is present. Aborting.');
}

if (isDefinedAndNotNull(authVersion) && authVersion === 'v2' && !isDefinedAndNotNull(s2sKey)) {
throw new ConfigurationError('s2s key is mandatory for v2 authorization. Aborting.');
}

if (isDefinedAndNotNull(authVersion) && authVersion === 'v1' && !isDefinedAndNotNull(devKey)) {
throw new ConfigurationError('dev key is mandatory for v1 authorization. Aborting.');
}
const messageType = message.type.toLowerCase();
let payload;
switch (messageType) {
Expand All @@ -212,7 +240,7 @@ function processSingleMessage(message, destination) {
}
case EventType.SCREEN: {
let eventName;
if (destination.Config.useRichEventName === true) {
if (useRichEventName === true) {
eventName = `Viewed ${
message.name || message.event || get(message, 'properties.name') || ''
} Screen`;
Expand All @@ -224,7 +252,7 @@ function processSingleMessage(message, destination) {
}
case EventType.PAGE: {
let eventName;
if (destination.Config.useRichEventName === true) {
if (useRichEventName === true) {
eventName = `Viewed ${message.name || get(message, 'properties.name') || ''} Page`;
} else {
eventName = EventType.PAGE;
Expand Down
Loading

0 comments on commit e124470

Please sign in to comment.