Skip to content

Commit

Permalink
chore: add aliases from one signal intg object
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Jun 12, 2024
1 parent 584af32 commit 1c77b6e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/v0/destinations/one_signal/transformV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ const {
defaultPostRequestConfig,
removeUndefinedAndNullValues,
} = require('../../util');
const { populateTags, getProductPurchasesDetails, getSubscriptions } = require('./util');
const {
populateTags,
getProductPurchasesDetails,
getSubscriptions,
getOneSignalAliases,
} = require('./util');
const { JSON_MIME_TYPE } = require('../../util/constant');

const responseBuilder = (payload, Config) => {
Expand Down Expand Up @@ -46,7 +51,13 @@ const identifyResponseBuilder = (message, { Config }) => {
const tags = populateTags(message);

Check warning on line 51 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L51

Added line #L51 was not covered by tests

const payload = constructPayload(message, mappingConfig[ConfigCategory.IDENTIFY_V2.name]);

Check warning on line 53 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L53

Added line #L53 was not covered by tests

if (!payload?.identity?.external_id) {
const alias = getOneSignalAliases(message);

Check warning on line 55 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L55

Added line #L55 was not covered by tests
if (!alias.identifier) {
throw new InstrumentationError('userId or any other alias is required for identify');

Check warning on line 57 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L57

Added line #L57 was not covered by tests
}
payload.identity = alias;

Check warning on line 59 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L59

Added line #L59 was not covered by tests
}
// Following check is to intialise properties object in case we don't get properties object from construct payload
if (!payload.properties) {
payload.properties = {};

Check warning on line 63 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L63

Added line #L63 was not covered by tests
Expand Down Expand Up @@ -87,9 +98,14 @@ const trackOrGroupResponseBuilder = (message, { Config }, msgtype) => {

const externalUserId = getFieldValueFromMessage(message, 'userIdOnly');

Check warning on line 99 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L99

Added line #L99 was not covered by tests
if (!externalUserId) {
throw new InstrumentationError('userId is required for track events/updating a device');
const alias = getOneSignalAliases(message);

Check warning on line 101 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L101

Added line #L101 was not covered by tests
if (!alias.identifier) {
throw new InstrumentationError('userId or any other alias is required for track and group');

Check warning on line 103 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L103

Added line #L103 was not covered by tests
}
payload.identity = alias;
} else {
payload.identity.external_id = externalUserId;

Check warning on line 107 in src/v0/destinations/one_signal/transformV2.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/transformV2.js#L105-L107

Added lines #L105 - L107 were not covered by tests
}

/* Populating event as true in tags.
eg. tags: {
"event_name": true
Expand Down
11 changes: 10 additions & 1 deletion src/v0/destinations/one_signal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,19 @@ const getSubscriptions = (message, Config) => {
}
return subscriptions.length > 0 ? subscriptions : undefined;
};

const getOneSignalAliases = (message) => {
const integrationsObj = getIntegrationsObj(message, 'one_signal');
const alias = {};

Check warning on line 197 in src/v0/destinations/one_signal/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/util.js#L196-L197

Added lines #L196 - L197 were not covered by tests
if (integrationsObj && integrationsObj.aliasName && integrationsObj.aliasIdentifier) {
alias.type = integrationsObj.aliasName;
alias.identifier = integrationsObj.aliasIdentifier;

Check warning on line 200 in src/v0/destinations/one_signal/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/util.js#L199-L200

Added lines #L199 - L200 were not covered by tests
}
return alias;

Check warning on line 202 in src/v0/destinations/one_signal/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/one_signal/util.js#L202

Added line #L202 was not covered by tests
};
module.exports = {
populateDeviceType,
populateTags,
getProductPurchasesDetails,
getSubscriptions,
getOneSignalAliases,
};

0 comments on commit 1c77b6e

Please sign in to comment.