@denimlabs/fb-position-validation
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -11,4 +11,40 @@ "use strict"; | ||
exports.validateAllRulesByObjective = validateAllRulesByObjective; | ||
exports.ERRORS = void 0; | ||
var VALID_DEVICE_PLATFORMS = ['mobile', 'desktop']; | ||
var VALID_FACEBOOK_POSITIONS = ['feed', 'instant_article', 'instream_video', 'marketplace', 'right_hand_column', 'suggested_video', 'story']; | ||
var VALID_PUBLISHER_PLATFORMS = ['facebook', 'instagram', 'messenger', 'audience_network']; | ||
var VALID_INSTAGRAM_POSTIONS = ['story', 'stream']; | ||
var VALID_AUDIENCE_NETWORK_POSITIONS = ['classic', 'instream_video', 'reward_video']; | ||
var VALID_MESSENGER_POSITIONS = ['messenger_home', 'sponsored_messages', 'story']; | ||
var ERRORS = { | ||
UNSUPPORTED_OBJECT: Error('Unsupported Objective'), | ||
INVALID_FACEBOOK_POSITION: Error("Invalid Facebook position. Valid values are ".concat(VALID_FACEBOOK_POSITIONS)), | ||
STORY_DEVICE: Error('When using Story you can not select only desktop.'), | ||
STORY_FEED: Error('When using Story you must select Facebook Feed or Instagram Story positions.'), | ||
INSTANT_ARTICLE_FEED: Error('When using Instant Article you must also select Feed.'), | ||
INSTANT_ARTICLE_DEVICE: Error('When using Instant Article you can not select only Desktop.'), | ||
MARKETPLACE_FEED: Error('When using Marketplace you must also select Feed.'), | ||
MARKETPLACE_DEVICE: Error('When using Marketplace you can not select only Desktop.'), | ||
INVALID_INSTAGRAM_POSITION: Error("Invalid Instgram position. Valid values are ".concat(VALID_INSTAGRAM_POSTIONS)), | ||
INSTAGRAM_STORY_STREAM: Error('You can not select both Story and Stream for Instagram positions.'), | ||
INVALID_AUDIENCE_NETWORK_POSITION: Error("Invalid Audience Network position. Valid values are ".concat(VALID_AUDIENCE_NETWORK_POSITIONS)), | ||
INVALID_MESSENGER_POSITION: Error("Invalid Messenger position. Valid values are ".concat(VALID_MESSENGER_POSITIONS, ".")), | ||
MESSENGER_HOME_FACEBOOK: Error('You must select Facebook for Publisher Platform when using Messenger Home.'), | ||
MESSENGER_HOME_FEED: Error('You must select Facebook Feed when using Messenger Home.'), | ||
MESSENGER_HOME_DEVICE: Error('When using Messenger Positions you can not select only Desktop.'), | ||
MESSENGER_SPONSORED: Error('When using Messenger Positions Sponsored Messages you can not select other Messenger Positions.'), | ||
PUBLISHER_PLATFORMS_FACEBOOK: Error('When providing Publisher Platforms you must include Facebook.'), | ||
DEVICE_PLATFORMS: Error('Invalid Device Platform for this campaign goal.'), | ||
PUBLISHER_PLATFORM: Error('Invalid Publisher Platform for this campaign goal.'), | ||
FACEBOOK_POSITIONS: Error('Invalid Facebook Position for this campaign goal.'), | ||
INSTAGRAM_POSITIONS: Error('Invalid Instagram Position for this campaign goal.'), | ||
AUDIENCE_NETWORK_POSITIONS: Error('Invalid Audience Network Positions for this campaign goal.'), | ||
MESSENGER_POSITIONS: Error('Invalid Messenger Positions for this campaign goal.') | ||
}; | ||
exports.ERRORS = ERRORS; | ||
var AwarenessPublisherPlatforms = ['facebook', 'instagram', 'audience_network', 'messenger']; | ||
var AwarenessPlacments = { | ||
facebook_positions: ['feed', 'suggested_video', 'instant_article', 'instream_video', 'story'], | ||
device_platforms: VALID_DEVICE_PLATFORMS, | ||
publisher_platforms: ['facebook', 'instagram', 'audience_network', 'messenger'], | ||
facebook_positions: ['feed', 'instant_article', 'suggested_video', 'story', 'instream_video'], | ||
instagram_positions: ['stream'], | ||
@@ -18,11 +54,19 @@ audience_network_positions: ['classic', 'instream_video'], | ||
}; | ||
var EngagementPublisherPlatforms = ['facebook', 'instagram', 'messenger']; | ||
var EngagementPlacments = { | ||
facebook_positions: ['feed', 'suggested_video', 'instant_article', 'instream_video', 'story'], | ||
instagram_positions: ['stream'] | ||
device_platforms: VALID_DEVICE_PLATFORMS, | ||
publisher_platforms: ['facebook', 'instagram', 'messenger'], | ||
facebook_positions: ['feed', 'instant_article', 'suggested_video', 'marketplace', 'story', 'instream_video'], | ||
instagram_positions: ['story', 'stream'], | ||
audience_network_positions: [], | ||
messenger_positions: [] | ||
}; | ||
var ConversionPublisherPlatforms = ['facebook', 'instagram', 'audience_network', 'messenger']; | ||
var ConversionPlacments = { | ||
facebook_positions: ['feed', 'suggested_video', 'instant_article', 'instream_video', 'story', 'right_hand_column'], | ||
instagram_positions: ['stream'], | ||
audience_network_positions: ['classic', 'instream_video'], | ||
messenger_positions: ['messenger_home'] | ||
publisher_platforms: VALID_PUBLISHER_PLATFORMS, | ||
device_platforms: VALID_DEVICE_PLATFORMS, | ||
facebook_positions: VALID_FACEBOOK_POSITIONS, | ||
instagram_positions: VALID_INSTAGRAM_POSTIONS, | ||
audience_network_positions: VALID_AUDIENCE_NETWORK_POSITIONS, | ||
messenger_positions: VALID_MESSENGER_POSITIONS | ||
}; | ||
@@ -39,3 +83,3 @@ | ||
throw Error('Unsupported Objective'); | ||
throw ERRORS.UNSUPPORTED_OBJECT; | ||
} | ||
@@ -54,9 +98,5 @@ | ||
throw Error('Unsupported Objective'); | ||
throw ERRORS.UNSUPPORTED_OBJECT; | ||
} | ||
var AwarenessPublisherPlatforms = ['facebook', 'instagram', 'audience_network']; | ||
var EngagementPublisherPlatforms = ['facebook', 'instagram']; | ||
var ConversionPublisherPlatforms = ['facebook', 'instagram', 'audience_network']; | ||
function getValidPublisherPlatformsForObjective(objective) { | ||
@@ -71,12 +111,5 @@ if (objective === 'Awareness' || objective === 'BRAND_AWARENESS') { | ||
throw Error('Unsupported Objective'); | ||
throw ERRORS.UNSUPPORTED_OBJECT; | ||
} | ||
var VALID_DEVICE_PLATFORMS = ['mobile', 'desktop']; | ||
var VALID_FACEBOOK_POSITIONS = ['feed', 'right_hand_column', 'instant_article', 'suggested_video', 'marketplace', 'story', 'instream_video']; | ||
var VALID_PUBLISHER_PLATFORMS = ['facebook', 'instagram', 'messenger', 'audience_network']; | ||
var VALID_INSTAGRAM_POSTIONS = ['story', 'stream']; | ||
var VALID_AUDIENCE_NETWORK_POSITIONS = ['classic', 'instream_video', 'reward_video']; | ||
var VALID_MESSENGER_POSITIONS = ['messenger_home', 'sponsored_messages', 'story']; | ||
function validatePositioningRules(positioning) { | ||
@@ -98,3 +131,3 @@ var _positioning$device_p = positioning.device_platforms, | ||
if (!containsOnlyValid(facebook_positions, VALID_FACEBOOK_POSITIONS)) { | ||
throw Error("invalid facebook position. Valid values are ".concat(VALID_FACEBOOK_POSITIONS)); | ||
throw ERRORS.INVALID_FACEBOOK_POSITION; | ||
} | ||
@@ -107,6 +140,6 @@ | ||
} else { | ||
throw Error('when using story you can not select only desktop.'); | ||
throw ERRORS.STORY_DEVICE; | ||
} | ||
} else { | ||
throw Error('when using story you must select facebook feed or instagram story positions.'); | ||
throw ERRORS.STORY_FEED; | ||
} | ||
@@ -117,7 +150,7 @@ } | ||
if (!facebook_positions.includes('feed')) { | ||
throw Error('when using instant_article you must also select feed.'); | ||
throw ERRORS.INSTANT_ARTICLE_FEED; | ||
} | ||
if ((device_platforms || []).length > 0 && !device_platforms.includes('mobile')) { | ||
throw Error('when using instant_article you can not select only desktop.'); | ||
throw ERRORS.INSTANT_ARTICLE_DEVICE; | ||
} | ||
@@ -128,7 +161,7 @@ } | ||
if (!facebook_positions.includes('feed')) { | ||
throw Error('when using marketplace you must also select feed.'); | ||
throw ERRORS.MARKETPLACE_FEED; | ||
} | ||
if ((device_platforms || []).length > 0 && !device_platforms.includes('mobile')) { | ||
throw Error('when using marketplace you can not select only desktop.'); | ||
throw ERRORS.MARKETPLACE_DEVICE; | ||
} | ||
@@ -140,7 +173,7 @@ } | ||
if (!containsOnlyValid(instagram_positions, VALID_INSTAGRAM_POSTIONS)) { | ||
throw Error("invalid instagram position. Valid values are ".concat(VALID_INSTAGRAM_POSTIONS)); | ||
throw ERRORS.INVALID_INSTAGRAM_POSITION; | ||
} | ||
if (instagram_positions.includes('stream') && instagram_positions.includes('story')) { | ||
throw Error('can not select both story and stream for instagram positions.'); | ||
throw ERRORS.INSTAGRAM_STORY_STREAM; | ||
} | ||
@@ -151,3 +184,3 @@ } | ||
if (!containsOnlyValid(audience_network_positions, VALID_AUDIENCE_NETWORK_POSITIONS)) { | ||
throw Error("invalid audience network position. Valid values are ".concat(VALID_AUDIENCE_NETWORK_POSITIONS)); | ||
throw ERRORS.INVALID_AUDIENCE_NETWORK_POSITION; | ||
} | ||
@@ -158,3 +191,3 @@ } | ||
if (!containsOnlyValid(messenger_positions, VALID_MESSENGER_POSITIONS)) { | ||
throw Error("invalid messenger positions. Valid values are ".concat(VALID_MESSENGER_POSITIONS, ".")); | ||
throw ERRORS.INVALID_MESSENGER_POSITION; | ||
} | ||
@@ -164,7 +197,7 @@ | ||
if ((publisher_platforms || []).length > 0 && !publisher_platforms.includes('facebook')) { | ||
throw Error('You must select facebook for publisher platform when using messenger home.'); | ||
throw ERRORS.MESSENGER_HOME_FACEBOOK; | ||
} | ||
if ((facebook_positions || []).length > 0 && !facebook_positions.includes('feed')) { | ||
throw Error('You must select facebook feed when using messenger home.'); | ||
throw ERRORS.MESSENGER_HOME_FEED; | ||
} | ||
@@ -174,3 +207,3 @@ } | ||
if ((device_platforms || []).length > 0 && !device_platforms.includes('mobile')) { | ||
throw Error('when using messenger_positions you can not select only desktop.'); | ||
throw ERRORS.MESSENGER_HOME_DEVICE; | ||
} | ||
@@ -180,3 +213,3 @@ | ||
if (messenger_positions.includes('messenger_home') || messenger_positions.includes('story')) { | ||
throw Error('when using messenger_positions sponsored_messages you can not select other messenger_positions.'); | ||
throw ERRORS.MESSENGER_SPONSORED; | ||
} | ||
@@ -187,3 +220,3 @@ } | ||
if ((publisher_platforms || []).length > 0 && !publisher_platforms.includes('facebook')) { | ||
throw Error('when providing publisher_platforms you must include facebook.'); | ||
throw ERRORS.PUBLISHER_PLATFORMS_FACEBOOK; | ||
} | ||
@@ -194,7 +227,5 @@ } | ||
var validPositions = getValidPositionsForObjective(objective); | ||
var validPublisherPlatforms = getValidPublisherPlatformsForObjective(objective); | ||
var validDevicePlatforms = getValidDevicePlatformsForObjective(objective); | ||
validateDevicePlatformsAgainstValidObjectiveDevicePlatforms(validPositions.device_platforms, positioning); | ||
validatePublisherPlatformsAgainstValidObjectivePublisherPlatforms(validPositions.publisher_platforms, positioning); | ||
validatePositioningAgainstValidObjectivePositions(validPositions, positioning); | ||
validatePublisherPlatformsAgainstValidObjectivePublisherPlatforms(validPublisherPlatforms, positioning); | ||
validateDevicePlatformsAgainstValidObjectiveDevicePlatforms(validDevicePlatforms, positioning); | ||
validatePositioningRules(positioning); | ||
@@ -208,3 +239,3 @@ } | ||
if ((device_platforms || []).length > 0 && !containsOnlyValid(device_platforms, validDevicePlatforms)) { | ||
throw Error('invalid device platforms for objective'); | ||
throw ERRORS.DEVICE_PLATFORMS; | ||
} | ||
@@ -216,9 +247,5 @@ } | ||
publisher_platforms = _positioning$publishe2 === void 0 ? [] : _positioning$publishe2; | ||
console.log({ | ||
publisher_platforms: publisher_platforms, | ||
validPublisherPlatforms: validPublisherPlatforms | ||
}); | ||
if ((publisher_platforms || []).length > 0 && !containsOnlyValid(publisher_platforms, validPublisherPlatforms)) { | ||
throw Error('invalid publisher platform for objective'); | ||
throw ERRORS.PUBLISHER_PLATFORM; | ||
} | ||
@@ -243,3 +270,3 @@ } | ||
if (!containsOnlyValid(facebook_positions, validFacebookPositions)) { | ||
throw Error('Invalid facebook_positions for this objective'); | ||
throw ERRORS.FACEBOOK_POSITIONS; | ||
} | ||
@@ -250,3 +277,3 @@ } | ||
if (!containsOnlyValid(instagram_positions, validInsagramPositions)) { | ||
throw Error('Invalid instagram_positions for this objective'); | ||
throw ERRORS.INSTAGRAM_POSITIONS; | ||
} | ||
@@ -257,3 +284,3 @@ } | ||
if (!containsOnlyValid(audience_network_positions, validAudienceNetworkPositions)) { | ||
throw Error('Invalid audience_network_positions for this objective'); | ||
throw ERRORS.AUDIENCE_NETWORK_POSITIONS; | ||
} | ||
@@ -264,3 +291,3 @@ } | ||
if (!containsOnlyValid(messenger_positions, validMessengerPositions)) { | ||
throw Error('Invalid messenger_positions for this objective'); | ||
throw ERRORS.MESSENGER_POSITIONS; | ||
} | ||
@@ -267,0 +294,0 @@ } |
306
index.js
@@ -0,8 +1,125 @@ | ||
// Optional | ||
// Default All | ||
const VALID_DEVICE_PLATFORMS = ['mobile', 'desktop'] | ||
// Optional | ||
// Default All | ||
const VALID_FACEBOOK_POSITIONS = [ | ||
'feed', | ||
'instant_article', | ||
'instream_video', | ||
'marketplace', | ||
'right_hand_column', | ||
'suggested_video', | ||
'story' | ||
] | ||
// Optional | ||
// Default All | ||
const VALID_PUBLISHER_PLATFORMS = [ | ||
'facebook', | ||
'instagram', | ||
'messenger', | ||
'audience_network' | ||
] | ||
const VALID_INSTAGRAM_POSTIONS = ['story', 'stream'] | ||
const VALID_AUDIENCE_NETWORK_POSITIONS = [ | ||
'classic', | ||
'instream_video', | ||
'reward_video' | ||
] | ||
const VALID_MESSENGER_POSITIONS = [ | ||
'messenger_home', | ||
'sponsored_messages', | ||
'story' | ||
] | ||
const ERRORS = { | ||
UNSUPPORTED_OBJECT: Error('Unsupported Objective'), | ||
INVALID_FACEBOOK_POSITION: Error( | ||
`Invalid Facebook position. Valid values are ${VALID_FACEBOOK_POSITIONS}` | ||
), | ||
STORY_DEVICE: Error('When using Story you can not select only desktop.'), | ||
STORY_FEED: Error( | ||
'When using Story you must select Facebook Feed or Instagram Story positions.' | ||
), | ||
INSTANT_ARTICLE_FEED: Error( | ||
'When using Instant Article you must also select Feed.' | ||
), | ||
INSTANT_ARTICLE_DEVICE: Error( | ||
'When using Instant Article you can not select only Desktop.' | ||
), | ||
MARKETPLACE_FEED: Error('When using Marketplace you must also select Feed.'), | ||
MARKETPLACE_DEVICE: Error( | ||
'When using Marketplace you can not select only Desktop.' | ||
), | ||
INVALID_INSTAGRAM_POSITION: Error( | ||
`Invalid Instgram position. Valid values are ${VALID_INSTAGRAM_POSTIONS}` | ||
), | ||
INSTAGRAM_STORY_STREAM: Error( | ||
'You can not select both Story and Stream for Instagram positions.' | ||
), | ||
INVALID_AUDIENCE_NETWORK_POSITION: Error( | ||
`Invalid Audience Network position. Valid values are ${VALID_AUDIENCE_NETWORK_POSITIONS}` | ||
), | ||
INVALID_MESSENGER_POSITION: Error( | ||
`Invalid Messenger position. Valid values are ${VALID_MESSENGER_POSITIONS}.` | ||
), | ||
MESSENGER_HOME_FACEBOOK: Error( | ||
'You must select Facebook for Publisher Platform when using Messenger Home.' | ||
), | ||
MESSENGER_HOME_FEED: Error( | ||
'You must select Facebook Feed when using Messenger Home.' | ||
), | ||
MESSENGER_HOME_DEVICE: Error( | ||
'When using Messenger Positions you can not select only Desktop.' | ||
), | ||
MESSENGER_SPONSORED: Error( | ||
'When using Messenger Positions Sponsored Messages you can not select other Messenger Positions.' | ||
), | ||
PUBLISHER_PLATFORMS_FACEBOOK: Error( | ||
'When providing Publisher Platforms you must include Facebook.' | ||
), | ||
DEVICE_PLATFORMS: Error('Invalid Device Platform for this campaign goal.'), | ||
PUBLISHER_PLATFORM: Error( | ||
'Invalid Publisher Platform for this campaign goal.' | ||
), | ||
FACEBOOK_POSITIONS: Error( | ||
'Invalid Facebook Position for this campaign goal.' | ||
), | ||
INSTAGRAM_POSITIONS: Error( | ||
'Invalid Instagram Position for this campaign goal.' | ||
), | ||
AUDIENCE_NETWORK_POSITIONS: Error( | ||
'Invalid Audience Network Positions for this campaign goal.' | ||
), | ||
MESSENGER_POSITIONS: Error( | ||
'Invalid Messenger Positions for this campaign goal.' | ||
) | ||
} | ||
// BRAND_AWARENESS | ||
const AwarenessPublisherPlatforms = [ | ||
'facebook', | ||
'instagram', | ||
'audience_network', | ||
'messenger' | ||
] | ||
const AwarenessPlacments = { | ||
device_platforms: VALID_DEVICE_PLATFORMS, | ||
publisher_platforms: [ | ||
'facebook', | ||
'instagram', | ||
'audience_network', | ||
'messenger' | ||
], | ||
facebook_positions: [ | ||
'feed', | ||
'instant_article', | ||
'suggested_video', | ||
'instant_article', | ||
'instream_video', | ||
'story' | ||
'story', | ||
'instream_video' | ||
], | ||
@@ -14,25 +131,34 @@ instagram_positions: ['stream'], | ||
// POST_ENGAGEMENT | ||
const EngagementPublisherPlatforms = ['facebook', 'instagram', 'messenger'] | ||
const EngagementPlacments = { | ||
device_platforms: VALID_DEVICE_PLATFORMS, | ||
publisher_platforms: ['facebook', 'instagram', 'messenger'], | ||
facebook_positions: [ | ||
'feed', | ||
'instant_article', | ||
'suggested_video', | ||
'instant_article', | ||
'instream_video', | ||
'story' | ||
'marketplace', | ||
'story', | ||
'instream_video' | ||
], | ||
instagram_positions: ['stream'] | ||
instagram_positions: ['story', 'stream'], | ||
audience_network_positions: [], | ||
messenger_positions: [] | ||
} | ||
// LINK_CLICKS | ||
const ConversionPublisherPlatforms = [ | ||
'facebook', | ||
'instagram', | ||
'audience_network', | ||
'messenger' | ||
] | ||
const ConversionPlacments = { | ||
facebook_positions: [ | ||
'feed', | ||
'suggested_video', | ||
'instant_article', | ||
'instream_video', | ||
'story', | ||
'right_hand_column' | ||
], | ||
instagram_positions: ['stream'], | ||
audience_network_positions: ['classic', 'instream_video'], | ||
messenger_positions: ['messenger_home'] | ||
publisher_platforms: VALID_PUBLISHER_PLATFORMS, | ||
device_platforms: VALID_DEVICE_PLATFORMS, | ||
facebook_positions: VALID_FACEBOOK_POSITIONS, | ||
instagram_positions: VALID_INSTAGRAM_POSTIONS, | ||
audience_network_positions: VALID_AUDIENCE_NETWORK_POSITIONS, | ||
messenger_positions: VALID_MESSENGER_POSITIONS | ||
} | ||
@@ -48,3 +174,3 @@ | ||
} | ||
throw Error('Unsupported Objective') | ||
throw ERRORS.UNSUPPORTED_OBJECT | ||
} | ||
@@ -62,17 +188,5 @@ | ||
} | ||
throw Error('Unsupported Objective') | ||
throw ERRORS.UNSUPPORTED_OBJECT | ||
} | ||
const AwarenessPublisherPlatforms = [ | ||
'facebook', | ||
'instagram', | ||
'audience_network' | ||
] | ||
const EngagementPublisherPlatforms = ['facebook', 'instagram'] | ||
const ConversionPublisherPlatforms = [ | ||
'facebook', | ||
'instagram', | ||
'audience_network' | ||
] | ||
function getValidPublisherPlatformsForObjective (objective) { | ||
@@ -86,44 +200,5 @@ if (objective === 'Awareness' || objective === 'BRAND_AWARENESS') { | ||
} | ||
throw Error('Unsupported Objective') | ||
throw ERRORS.UNSUPPORTED_OBJECT | ||
} | ||
// Optional | ||
// Default All | ||
const VALID_DEVICE_PLATFORMS = ['mobile', 'desktop'] | ||
// Optional | ||
// Default All | ||
const VALID_FACEBOOK_POSITIONS = [ | ||
'feed', | ||
'right_hand_column', | ||
'instant_article', | ||
'suggested_video', | ||
'marketplace', | ||
'story', | ||
'instream_video' | ||
] | ||
// Optional | ||
// Default All | ||
const VALID_PUBLISHER_PLATFORMS = [ | ||
'facebook', | ||
'instagram', | ||
'messenger', | ||
'audience_network' | ||
] | ||
const VALID_INSTAGRAM_POSTIONS = ['story', 'stream'] | ||
const VALID_AUDIENCE_NETWORK_POSITIONS = [ | ||
'classic', | ||
'instream_video', | ||
'reward_video' | ||
] | ||
const VALID_MESSENGER_POSITIONS = [ | ||
'messenger_home', | ||
'sponsored_messages', | ||
'story' | ||
] | ||
function validatePositioningRules (positioning) { | ||
@@ -148,5 +223,3 @@ const { | ||
if (!containsOnlyValid(facebook_positions, VALID_FACEBOOK_POSITIONS)) { | ||
throw Error( | ||
`invalid facebook position. Valid values are ${VALID_FACEBOOK_POSITIONS}` | ||
) | ||
throw ERRORS.INVALID_FACEBOOK_POSITION | ||
} | ||
@@ -168,8 +241,6 @@ | ||
} else { | ||
throw Error('when using story you can not select only desktop.') | ||
throw ERRORS.STORY_DEVICE | ||
} | ||
} else { | ||
throw Error( | ||
'when using story you must select facebook feed or instagram story positions.' | ||
) | ||
throw ERRORS.STORY_FEED | ||
} | ||
@@ -182,3 +253,3 @@ } | ||
if (!facebook_positions.includes('feed')) { | ||
throw Error('when using instant_article you must also select feed.') | ||
throw ERRORS.INSTANT_ARTICLE_FEED | ||
} | ||
@@ -190,5 +261,3 @@ | ||
) { | ||
throw Error( | ||
'when using instant_article you can not select only desktop.' | ||
) | ||
throw ERRORS.INSTANT_ARTICLE_DEVICE | ||
} | ||
@@ -201,3 +270,3 @@ } | ||
if (!facebook_positions.includes('feed')) { | ||
throw Error('when using marketplace you must also select feed.') | ||
throw ERRORS.MARKETPLACE_FEED | ||
} | ||
@@ -208,3 +277,3 @@ if ( | ||
) { | ||
throw Error('when using marketplace you can not select only desktop.') | ||
throw ERRORS.MARKETPLACE_DEVICE | ||
} | ||
@@ -218,5 +287,3 @@ } | ||
if (!containsOnlyValid(instagram_positions, VALID_INSTAGRAM_POSTIONS)) { | ||
throw Error( | ||
`invalid instagram position. Valid values are ${VALID_INSTAGRAM_POSTIONS}` | ||
) | ||
throw ERRORS.INVALID_INSTAGRAM_POSITION | ||
} | ||
@@ -227,5 +294,3 @@ if ( | ||
) { | ||
throw Error( | ||
'can not select both story and stream for instagram positions.' | ||
) | ||
throw ERRORS.INSTAGRAM_STORY_STREAM | ||
} | ||
@@ -243,5 +308,3 @@ } | ||
) { | ||
throw Error( | ||
`invalid audience network position. Valid values are ${VALID_AUDIENCE_NETWORK_POSITIONS}` | ||
) | ||
throw ERRORS.INVALID_AUDIENCE_NETWORK_POSITION | ||
} | ||
@@ -253,5 +316,3 @@ } | ||
if (!containsOnlyValid(messenger_positions, VALID_MESSENGER_POSITIONS)) { | ||
throw Error( | ||
`invalid messenger positions. Valid values are ${VALID_MESSENGER_POSITIONS}.` | ||
) | ||
throw ERRORS.INVALID_MESSENGER_POSITION | ||
} | ||
@@ -265,5 +326,3 @@ | ||
) { | ||
throw Error( | ||
'You must select facebook for publisher platform when using messenger home.' | ||
) | ||
throw ERRORS.MESSENGER_HOME_FACEBOOK | ||
} | ||
@@ -274,3 +333,3 @@ if ( | ||
) { | ||
throw Error('You must select facebook feed when using messenger home.') | ||
throw ERRORS.MESSENGER_HOME_FEED | ||
} | ||
@@ -283,5 +342,3 @@ } | ||
) { | ||
throw Error( | ||
'when using messenger_positions you can not select only desktop.' | ||
) | ||
throw ERRORS.MESSENGER_HOME_DEVICE | ||
} | ||
@@ -294,5 +351,3 @@ | ||
) { | ||
throw Error( | ||
'when using messenger_positions sponsored_messages you can not select other messenger_positions.' | ||
) | ||
throw ERRORS.MESSENGER_SPONSORED | ||
} | ||
@@ -306,3 +361,3 @@ } | ||
) { | ||
throw Error('when providing publisher_platforms you must include facebook.') | ||
throw ERRORS.PUBLISHER_PLATFORMS_FACEBOOK | ||
} | ||
@@ -313,15 +368,16 @@ } | ||
const validPositions = getValidPositionsForObjective(objective) | ||
const validPublisherPlatforms = getValidPublisherPlatformsForObjective( | ||
objective | ||
// const validPublisherPlatforms = getValidPublisherPlatformsForObjective( | ||
// objective | ||
// ) | ||
// const validDevicePlatforms = getValidDevicePlatformsForObjective(objective) | ||
validateDevicePlatformsAgainstValidObjectiveDevicePlatforms( | ||
validPositions.device_platforms, | ||
positioning | ||
) | ||
const validDevicePlatforms = getValidDevicePlatformsForObjective(objective) | ||
validatePositioningAgainstValidObjectivePositions(validPositions, positioning) | ||
validatePublisherPlatformsAgainstValidObjectivePublisherPlatforms( | ||
validPublisherPlatforms, | ||
validPositions.publisher_platforms, | ||
positioning | ||
) | ||
validateDevicePlatformsAgainstValidObjectiveDevicePlatforms( | ||
validDevicePlatforms, | ||
positioning | ||
) | ||
validatePositioningAgainstValidObjectivePositions(validPositions, positioning) | ||
validatePositioningRules(positioning) | ||
@@ -339,3 +395,3 @@ } | ||
) { | ||
throw Error('invalid device platforms for objective') | ||
throw ERRORS.DEVICE_PLATFORMS | ||
} | ||
@@ -349,3 +405,2 @@ } | ||
const { publisher_platforms = [] } = positioning | ||
console.log({ publisher_platforms, validPublisherPlatforms }) | ||
if ( | ||
@@ -355,3 +410,3 @@ (publisher_platforms || []).length > 0 && | ||
) { | ||
throw Error('invalid publisher platform for objective') | ||
throw ERRORS.PUBLISHER_PLATFORM | ||
} | ||
@@ -379,3 +434,3 @@ } | ||
if (!containsOnlyValid(facebook_positions, validFacebookPositions)) { | ||
throw Error('Invalid facebook_positions for this objective') | ||
throw ERRORS.FACEBOOK_POSITIONS | ||
} | ||
@@ -386,3 +441,3 @@ } | ||
if (!containsOnlyValid(instagram_positions, validInsagramPositions)) { | ||
throw Error('Invalid instagram_positions for this objective') | ||
throw ERRORS.INSTAGRAM_POSITIONS | ||
} | ||
@@ -398,3 +453,3 @@ } | ||
) { | ||
throw Error('Invalid audience_network_positions for this objective') | ||
throw ERRORS.AUDIENCE_NETWORK_POSITIONS | ||
} | ||
@@ -405,3 +460,3 @@ } | ||
if (!containsOnlyValid(messenger_positions, validMessengerPositions)) { | ||
throw Error('Invalid messenger_positions for this objective') | ||
throw ERRORS.MESSENGER_POSITIONS | ||
} | ||
@@ -421,3 +476,4 @@ } | ||
getValidPublisherPlatformsForObjective, | ||
validateAllRulesByObjective | ||
validateAllRulesByObjective, | ||
ERRORS | ||
} |
@@ -6,3 +6,4 @@ import { | ||
getValidPublisherPlatformsForObjective, | ||
validateAllRulesByObjective | ||
validateAllRulesByObjective, | ||
ERRORS | ||
} from './index' | ||
@@ -18,8 +19,12 @@ | ||
], | ||
"device_platforms": Array [ | ||
"mobile", | ||
"desktop", | ||
], | ||
"facebook_positions": Array [ | ||
"feed", | ||
"instant_article", | ||
"suggested_video", | ||
"instant_article", | ||
"story", | ||
"instream_video", | ||
"story", | ||
], | ||
@@ -32,2 +37,8 @@ "instagram_positions": Array [ | ||
], | ||
"publisher_platforms": Array [ | ||
"facebook", | ||
"instagram", | ||
"audience_network", | ||
"messenger", | ||
], | ||
} | ||
@@ -38,12 +49,25 @@ `) | ||
Object { | ||
"audience_network_positions": Array [], | ||
"device_platforms": Array [ | ||
"mobile", | ||
"desktop", | ||
], | ||
"facebook_positions": Array [ | ||
"feed", | ||
"instant_article", | ||
"suggested_video", | ||
"instant_article", | ||
"marketplace", | ||
"story", | ||
"instream_video", | ||
"story", | ||
], | ||
"instagram_positions": Array [ | ||
"story", | ||
"stream", | ||
], | ||
"messenger_positions": Array [], | ||
"publisher_platforms": Array [ | ||
"facebook", | ||
"instagram", | ||
"messenger", | ||
], | ||
} | ||
@@ -57,12 +81,19 @@ `) | ||
"instream_video", | ||
"reward_video", | ||
], | ||
"device_platforms": Array [ | ||
"mobile", | ||
"desktop", | ||
], | ||
"facebook_positions": Array [ | ||
"feed", | ||
"suggested_video", | ||
"instant_article", | ||
"instream_video", | ||
"marketplace", | ||
"right_hand_column", | ||
"suggested_video", | ||
"story", | ||
"right_hand_column", | ||
], | ||
"instagram_positions": Array [ | ||
"story", | ||
"stream", | ||
@@ -72,3 +103,11 @@ ], | ||
"messenger_home", | ||
"sponsored_messages", | ||
"story", | ||
], | ||
"publisher_platforms": Array [ | ||
"facebook", | ||
"instagram", | ||
"messenger", | ||
"audience_network", | ||
], | ||
} | ||
@@ -80,3 +119,3 @@ `) | ||
expect(() => getValidPositionsForObjective('badPostion')).toThrowError( | ||
Error('Unsupported Objective') | ||
ERRORS.UNSUPPORTED_OBJECT | ||
) | ||
@@ -115,3 +154,3 @@ }) | ||
expect(() => getValidDevicePlatformsForObjective('invalid')).toThrowError( | ||
Error('Unsupported Objective') | ||
ERRORS.UNSUPPORTED_OBJECT | ||
) | ||
@@ -129,2 +168,3 @@ }) | ||
"audience_network", | ||
"messenger", | ||
] | ||
@@ -138,2 +178,3 @@ `) | ||
"instagram", | ||
"messenger", | ||
] | ||
@@ -148,2 +189,3 @@ `) | ||
"audience_network", | ||
"messenger", | ||
] | ||
@@ -160,5 +202,3 @@ `) | ||
expect(() => validatePositioningRules(positioning)).toThrowError( | ||
Error( | ||
`invalid facebook position. Valid values are feed,right_hand_column,instant_article,marketplace,story` | ||
) | ||
ERRORS.INVALID_FACEBOOK_POSITION | ||
) | ||
@@ -179,5 +219,3 @@ }) | ||
expect(() => validatePositioningRules(positioning)).toThrowError( | ||
Error( | ||
'when using story you must select facebook feed or instagram story positions.' | ||
) | ||
ERRORS.STORY_FEED | ||
) | ||
@@ -190,3 +228,3 @@ | ||
}) | ||
).toThrowError(Error('when using story you can not select only desktop.')) | ||
).toThrowError(ERRORS.STORY_DEVICE) | ||
@@ -198,5 +236,3 @@ expect(() => | ||
}) | ||
).not.toThrowError( | ||
Error('when using story you can not select only desktop.') | ||
) | ||
).not.toThrowError(ERRORS.STORY_DEVICE) | ||
@@ -215,5 +251,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('when providing publisher_platforms you must include facebook.') | ||
) | ||
).toThrowError(ERRORS.PUBLISHER_PLATFORMS_FACEBOOK) | ||
@@ -224,5 +258,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('when using instant_article you must also select feed.') | ||
) | ||
).toThrowError(ERRORS.INSTANT_ARTICLE_FEED) | ||
@@ -234,5 +266,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('when using instant_article you can not select only desktop.') | ||
) | ||
).toThrowError(ERRORS.INSTANT_ARTICLE_DEVICE) | ||
@@ -243,3 +273,3 @@ expect(() => | ||
}) | ||
).toThrowError(Error('when using marketplace you must also select feed.')) | ||
).toThrowError(ERRORS.MARKETPLACE_FEED) | ||
@@ -251,5 +281,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('when using marketplace you can not select only desktop.') | ||
) | ||
).toThrowError(ERRORS.MARKETPLACE_DEVICE) | ||
@@ -260,5 +288,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('can not select both story and stream for instagram positions.') | ||
) | ||
).toThrowError(ERRORS.INSTAGRAM_STORY_STREAM) | ||
@@ -269,5 +295,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('invalid instagram position. Valid values are story,stream') | ||
) | ||
).toThrowError(ERRORS.INVALID_INSTAGRAM_POSITION) | ||
@@ -278,7 +302,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error( | ||
'invalid audience network position. Valid values are classic,instream_video,reward_video' | ||
) | ||
) | ||
).toThrowError(ERRORS.INVALID_AUDIENCE_NETWORK_POSITION) | ||
@@ -289,7 +309,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error( | ||
'invalid messenger positions. Valid values are messenger_home,sponsored_messages,story.' | ||
) | ||
) | ||
).toThrowError(ERRORS.INVALID_MESSENGER_POSITION) | ||
@@ -301,7 +317,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error( | ||
'You must select facebook for publisher platform when using messenger home.' | ||
) | ||
) | ||
).toThrowError(ERRORS.MESSENGER_HOME_FACEBOOK) | ||
@@ -314,5 +326,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('You must select facebook feed when using messenger home.') | ||
) | ||
).toThrowError(ERRORS.MESSENGER_HOME_FEED) | ||
@@ -325,5 +335,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('when using messenger_positions you can not select only desktop.') | ||
) | ||
).toThrowError(ERRORS.MESSENGER_HOME_DEVICE) | ||
@@ -334,7 +342,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error( | ||
'when using messenger_positions sponsored_messages you can not select other messenger_positions.' | ||
) | ||
) | ||
).toThrowError(ERRORS.MESSENGER_SPONSORED) | ||
}) | ||
@@ -349,3 +353,3 @@ }) | ||
}) | ||
).toThrowError(Error('Invalid facebook_positions for this objective')) | ||
).toThrowError(ERRORS.FACEBOOK_POSITIONS) | ||
@@ -356,3 +360,3 @@ expect(() => | ||
}) | ||
).toThrowError(Error('Invalid instagram_positions for this objective')) | ||
).toThrowError(ERRORS.INSTAGRAM_POSITIONS) | ||
@@ -363,5 +367,3 @@ expect(() => | ||
}) | ||
).toThrowError( | ||
Error('Invalid audience_network_positions for this objective') | ||
) | ||
).toThrowError(ERRORS.AUDIENCE_NETWORK_POSITIONS) | ||
@@ -372,3 +374,3 @@ expect(() => | ||
}) | ||
).toThrowError(Error('Invalid messenger_positions for this objective')) | ||
).toThrowError(ERRORS.MESSENGER_POSITIONS) | ||
@@ -379,3 +381,3 @@ expect(() => | ||
}) | ||
).toThrowError(Error('invalid publisher platform for objective')) | ||
).toThrowError(ERRORS.PUBLISHER_PLATFORM) | ||
@@ -386,18 +388,19 @@ expect(() => | ||
}) | ||
).not.toThrowError(Error('invalid publisher platform for objective')) | ||
).not.toThrowError(ERRORS.PUBLISHER_PLATFORM) | ||
expect(() => | ||
validateAllRulesByObjective('Engagement', { | ||
validateAllRulesByObjective('Conversion', { | ||
device_platforms: [], | ||
publisher_platforms: ['facebook'], | ||
publisher_platforms: ['facebook', 'audience_network', 'messenger'], | ||
facebook_positions: [ | ||
'feed', | ||
'instant_article', | ||
'suggested_video', | ||
'instant_article', | ||
'instream_video', | ||
'right_hand_column', | ||
'story' | ||
], | ||
instagram_positions: [], | ||
audience_network_positions: [], | ||
messenger_positions: [] | ||
audience_network_positions: ['classic', 'instream_video'], | ||
messenger_positions: ['messenger_home'] | ||
}) | ||
@@ -404,0 +407,0 @@ ).not.toThrow() |
{ | ||
"name": "@denimlabs/fb-position-validation", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Validate facebook positions against denim campaign objectives.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63518
999