Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed May 23, 2024
1 parent 919fd3f commit 4987948
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 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.');

Check warning on line 224 in src/v0/destinations/af/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/af/transform.js#L224

Added line #L224 was not covered by tests
}

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

Check warning on line 228 in src/v0/destinations/af/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/af/transform.js#L228

Added line #L228 was not covered by tests
}

if (isDefinedAndNotNull(authVersion) && authVersion === 'v1' && !isDefinedAndNotNull(devKey)) {
throw new ConfigurationError('dev key is mandatory for v1 authorization. Aborting.');

Check warning on line 232 in src/v0/destinations/af/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/af/transform.js#L232

Added line #L232 was not covered by tests
}
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

0 comments on commit 4987948

Please sign in to comment.