@schibsted/niche-ads
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -0,1 +1,29 @@ | ||
## [1.2.0](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/compare/v1.1.2...v1.2.0) (2022-06-07) | ||
### Features | ||
- secure library with useEvent hook ([#52](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/52)) ([8d17f76](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/8d17f76792394ccca0a4d5f89c54bc1cbbb7ce81)) | ||
- **security:** start running CodeQL analysis ([#41](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/41)) ([ee31e13](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/ee31e13f280bc7273de3d3070c8c433599005a8a)) | ||
### Bug Fixes | ||
- **codeql:** skip when build is tag-triggered ([2004548](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/2004548257c51a44f0465777576d09c8327dfa33)) | ||
### Miscellaneous Chores | ||
- **eslint:** add curly rule ([#47](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/47)) ([437bffa](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/437bffaf82787d462ae7abb10d222001410541bd)) | ||
- update babel monorepo ([#44](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/44)) ([d087414](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/d087414362eb23b2bba1766bc78aaaa147a73c98)) | ||
- update dependency @babel/core to ^7.17.9 ([#32](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/32)) ([fb58ffd](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/fb58ffd4ebf9e4420ec03cf49d8c8f172ead0b0d)) | ||
- update dependency @commitlint/cli to ^16.3.0 ([#48](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/48)) ([6149361](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/61493616f31a3abb4460d466ec52109655f6a9fc)) | ||
- update dependency eslint to ^8.15.0 ([#46](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/46)) ([a6463fb](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/a6463fb26dd24b48a956c1476e47e939aa6a6320)) | ||
- update dependency eslint to ^8.17.0 ([#53](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/53)) ([11d73d9](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/11d73d979a4fb78c93775031fac172010b3d06c9)) | ||
- update dependency eslint-plugin-react-hooks to ^4.5.0 ([#43](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/43)) ([12b5360](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/12b5360d6152c5299d00d98a08e072a18f34a0bb)) | ||
- update dependency lint-staged to ^12.4.0 ([#39](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/39)) ([0fec683](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/0fec683d16c812c3add34d6ba5eebc79bb690223)) | ||
- update dependency lint-staged to ^12.4.2 ([#50](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/50)) ([226a6be](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/226a6be4294e230046cdfdbcd0b99748816997e9)) | ||
- update dependency lint-staged to ^12.5.0 ([#51](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/51)) ([695be85](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/695be85d3d4ae082fa48da2f0f9b66ef127d6034)) | ||
- update linters ([#29](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/29)) ([f1a7c8a](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/f1a7c8a2cdab246a026081c39bd0891afec65d6f)) | ||
- update linters ([#49](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/49)) ([64d754e](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/64d754e781a49b03b9d177e867f10bdb85504f64)) | ||
- update tool packages ([#42](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/42)) ([c10b62f](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/c10b62f529cf327114a9e526982f3ed5b9aac567)) | ||
- update tool packages ([#45](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/issues/45)) ([13e7a95](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/commit/13e7a951a9621c6c230354910c4ade9ceccea5b0)) | ||
### [1.1.2](https://github.schibsted.io/przemyslaw-babiarz/niche-ads/compare/v1.1.1...v1.1.2) (2022-04-21) | ||
@@ -2,0 +30,0 @@ |
@@ -21,2 +21,4 @@ "use strict"; | ||
var _useEvent = _interopRequireDefault(require("./useEvent")); | ||
var _jsxRuntime = require("react/jsx-runtime"); | ||
@@ -78,5 +80,5 @@ | ||
}, [placementsConfig]); | ||
const adReadyObserver = (0, _react.useCallback)(ready => { | ||
const adReadyObserver = (0, _useEvent.default)(ready => { | ||
setAdScriptsReady(ready); | ||
}, []); | ||
}); | ||
(0, _react.useEffect)(() => { | ||
@@ -91,3 +93,3 @@ scriptsLoadPromise.current = Promise.all([(0, _loadScript.default)(cdn, 'adsScript'), (0, _loadScript.default)(cogwheelCdn, 'cogwheelScript')]).then(() => { | ||
}, [cdn, cogwheelCdn, adReadyObserver]); | ||
const messageHandler = (0, _react.useCallback)(async event => { | ||
const messageHandler = (0, _useEvent.default)(async event => { | ||
if (wallpaper.enabled) { | ||
@@ -104,3 +106,3 @@ const attachWallpaperImageToPageBody = await Promise.resolve().then(() => _interopRequireWildcard(require('./appnexusMessageHandlers/wallpaper'))); | ||
(0, _collapse.default)(event); | ||
}, [wallpaper, chatbot.enabled]); | ||
}); | ||
(0, _react.useEffect)(() => { | ||
@@ -112,3 +114,3 @@ window.addEventListener('message', messageHandler); | ||
}, [messageHandler]); | ||
const loadAds = (0, _react.useCallback)(async _ref2 => { | ||
const loadAds = (0, _useEvent.default)(async _ref2 => { | ||
let { | ||
@@ -174,3 +176,3 @@ pageType, | ||
setPlacementsConfig(newPlacementConfig); | ||
}, [device, adsConfig, glimr]); | ||
}); | ||
(0, _react.useEffect)(() => { | ||
@@ -249,3 +251,3 @@ if (retryLoadAds.current) { | ||
}, [placementsConfig, adsConfig?.placements?.common]); | ||
const clearPlacements = (0, _react.useCallback)(() => { | ||
const clearPlacements = (0, _useEvent.default)(() => { | ||
placementsConfigRef.current.forEach(placementConfig => { | ||
@@ -256,3 +258,3 @@ cleanUpPlacement(placementConfig.targetId); | ||
setPlacementsConfig([]); | ||
}, []); | ||
}); | ||
const value = (0, _react.useMemo)(() => ({ | ||
@@ -259,0 +261,0 @@ loadAds, |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _useEvent = _interopRequireDefault(require("./useEvent")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -24,7 +26,7 @@ | ||
const placement = placements[targetId]; | ||
const showAd = (0, _react.useCallback)(() => { | ||
const showAd = (0, _useEvent.default)(() => { | ||
if (placement?.targetId) { | ||
(0, _appnexus.showTag)(placement.targetId); | ||
} | ||
}, [placement?.targetId]); | ||
}); | ||
return (0, _react.useMemo)(() => [placement, showAd, placementConfig], [placement, showAd, placementConfig]); | ||
@@ -31,0 +33,0 @@ }; |
{ | ||
"name": "@schibsted/niche-ads", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Package containing ads logic reappearing across our projects", | ||
@@ -15,2 +15,3 @@ "main": "dist/index.js", | ||
"lint": "eslint .", | ||
"lint-fix": "eslint . --fix", | ||
"prepare": "husky install", | ||
@@ -32,24 +33,24 @@ "release": "release-it" | ||
"devDependencies": { | ||
"@babel/cli": "^7.17.6", | ||
"@babel/core": "^7.17.7", | ||
"@babel/eslint-parser": "^7.17.0", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-react": "^7.16.7", | ||
"@commitlint/cli": "^16.2.3", | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@release-it/conventional-changelog": "^4.3.0", | ||
"eslint": "^8.10.0", | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.18.2", | ||
"@babel/eslint-parser": "^7.18.2", | ||
"@babel/preset-env": "^7.18.2", | ||
"@babel/preset-react": "^7.17.12", | ||
"@commitlint/cli": "^17.0.2", | ||
"@commitlint/config-conventional": "^17.0.2", | ||
"@release-it/conventional-changelog": "^5.0.0", | ||
"eslint": "^8.17.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-babel": "^5.3.1", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-react": "^7.29.3", | ||
"eslint-plugin-react-hooks": "^4.3.0", | ||
"husky": "^7.0.4", | ||
"lint-staged": "^12.3.8", | ||
"prettier": "^2.5.1", | ||
"eslint-plugin-react": "^7.30.0", | ||
"eslint-plugin-react-hooks": "^4.5.0", | ||
"husky": "^8.0.1", | ||
"lint-staged": "^13.0.0", | ||
"prettier": "^2.6.2", | ||
"prop-types": "^15.8.1", | ||
"release-it": "^14.14.2", | ||
"release-it": "^15.0.0", | ||
"rimraf": "^3.0.2" | ||
@@ -56,0 +57,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import { createContext, useCallback, useMemo, useState, useRef, useEffect } from 'react'; | ||
import { createContext, useMemo, useState, useRef, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -20,2 +20,3 @@ import splitEvery from './utils/splitEvery'; | ||
import collapseAd from './appnexusMessageHandlers/collapse'; | ||
import useEvent from './useEvent'; | ||
@@ -64,5 +65,5 @@ function noop() { | ||
const adReadyObserver = useCallback((ready) => { | ||
const adReadyObserver = useEvent((ready) => { | ||
setAdScriptsReady(ready); | ||
}, []); | ||
}); | ||
@@ -83,18 +84,15 @@ useEffect(() => { | ||
const messageHandler = useCallback( | ||
async (event) => { | ||
if (wallpaper.enabled) { | ||
const attachWallpaperImageToPageBody = await import('./appnexusMessageHandlers/wallpaper'); | ||
const messageHandler = useEvent(async (event) => { | ||
if (wallpaper.enabled) { | ||
const attachWallpaperImageToPageBody = await import('./appnexusMessageHandlers/wallpaper'); | ||
attachWallpaperImageToPageBody.default(event, wallpaper); | ||
} | ||
if (chatbot.enabled) { | ||
const runChatBot = await import('./appnexusMessageHandlers/chatBot'); | ||
attachWallpaperImageToPageBody.default(event, wallpaper); | ||
} | ||
if (chatbot.enabled) { | ||
const runChatBot = await import('./appnexusMessageHandlers/chatBot'); | ||
runChatBot.default(event); | ||
} | ||
collapseAd(event); | ||
}, | ||
[wallpaper, chatbot.enabled] | ||
); | ||
runChatBot.default(event); | ||
} | ||
collapseAd(event); | ||
}); | ||
@@ -109,55 +107,52 @@ useEffect(() => { | ||
const loadAds = useCallback( | ||
async ({ pageType, keywords, allowlist, blocklist }) => { | ||
await scriptsLoadPromise.current; | ||
const loadAds = useEvent(async ({ pageType, keywords, allowlist, blocklist }) => { | ||
await scriptsLoadPromise.current; | ||
if (!device || !adScriptsReadyRef.current) { | ||
retryLoadAds.current = { pageType, keywords, allowlist, blocklist }; | ||
if (!device || !adScriptsReadyRef.current) { | ||
retryLoadAds.current = { pageType, keywords, allowlist, blocklist }; | ||
return; | ||
} | ||
return; | ||
} | ||
retryLoadAds.current = false; | ||
setPlacements({}); | ||
placementsMediation.current = {}; | ||
clearRequest(); | ||
retryLoadAds.current = false; | ||
setPlacements({}); | ||
placementsMediation.current = {}; | ||
clearRequest(); | ||
const pageOptions = { | ||
...adsConfig.options, | ||
keywords: { | ||
...buildKeywords(adsConfig.keywords, device, pageType), | ||
...keywords, | ||
'aa-sch-externalid_src': Boolean(getAdId()) + Boolean(getUserId()), | ||
}, | ||
user: { | ||
externalUid: getAdId(), | ||
}, | ||
}; | ||
const pageOptions = { | ||
...adsConfig.options, | ||
keywords: { | ||
...buildKeywords(adsConfig.keywords, device, pageType), | ||
...keywords, | ||
'aa-sch-externalid_src': Boolean(getAdId()) + Boolean(getUserId()), | ||
}, | ||
user: { | ||
externalUid: getAdId(), | ||
}, | ||
}; | ||
if (glimr.enabled && (await glimr.shouldLoad())) { | ||
const { getGlimrTags } = await import('./utils/glimr'); | ||
const glimrTags = await getGlimrTags(glimr); | ||
if (glimr.enabled && (await glimr.shouldLoad())) { | ||
const { getGlimrTags } = await import('./utils/glimr'); | ||
const glimrTags = await getGlimrTags(glimr); | ||
if (glimrTags) { | ||
pageOptions.keywords['no-sno-geo'] = glimrTags; | ||
pageOptions.keywords['no-sno-weather'] = glimrTags; | ||
} | ||
if (glimrTags) { | ||
pageOptions.keywords['no-sno-geo'] = glimrTags; | ||
pageOptions.keywords['no-sno-weather'] = glimrTags; | ||
} | ||
} | ||
setPageOpts(pageOptions); | ||
setPageOpts(pageOptions); | ||
let newPlacementConfig = adsConfig.placements[device][pageType]?.filter((placement) => placement.invCode); | ||
if (!newPlacementConfig) { | ||
throw new Error(`No configuration for device: ${device} and pageType: ${pageType}`); | ||
} | ||
if (allowlist?.length > 0) { | ||
newPlacementConfig = newPlacementConfig.filter((placement) => allowlist.includes(placement.targetId)); | ||
} | ||
if (blocklist?.length > 0) { | ||
newPlacementConfig = newPlacementConfig.filter((placement) => !blocklist.includes(placement.targetId)); | ||
} | ||
setPlacementsConfig(newPlacementConfig); | ||
}, | ||
[device, adsConfig, glimr] | ||
); | ||
let newPlacementConfig = adsConfig.placements[device][pageType]?.filter((placement) => placement.invCode); | ||
if (!newPlacementConfig) { | ||
throw new Error(`No configuration for device: ${device} and pageType: ${pageType}`); | ||
} | ||
if (allowlist?.length > 0) { | ||
newPlacementConfig = newPlacementConfig.filter((placement) => allowlist.includes(placement.targetId)); | ||
} | ||
if (blocklist?.length > 0) { | ||
newPlacementConfig = newPlacementConfig.filter((placement) => !blocklist.includes(placement.targetId)); | ||
} | ||
setPlacementsConfig(newPlacementConfig); | ||
}); | ||
@@ -223,3 +218,3 @@ useEffect(() => { | ||
const clearPlacements = useCallback(() => { | ||
const clearPlacements = useEvent(() => { | ||
placementsConfigRef.current.forEach((placementConfig) => { | ||
@@ -231,3 +226,3 @@ cleanUpPlacement(placementConfig.targetId); | ||
setPlacementsConfig([]); | ||
}, []); | ||
}); | ||
@@ -234,0 +229,0 @@ const value = useMemo( |
@@ -1,4 +0,5 @@ | ||
import { useCallback, useContext, useMemo } from 'react'; | ||
import { useContext, useMemo } from 'react'; | ||
import { showTag } from './utils/appnexus'; | ||
import AdContext from './AdContext'; | ||
import useEvent from './useEvent'; | ||
@@ -10,7 +11,7 @@ const usePlacement = (targetId) => { | ||
const showAd = useCallback(() => { | ||
const showAd = useEvent(() => { | ||
if (placement?.targetId) { | ||
showTag(placement.targetId); | ||
} | ||
}, [placement?.targetId]); | ||
}); | ||
@@ -17,0 +18,0 @@ return useMemo(() => [placement, showAd, placementConfig], [placement, showAd, placementConfig]); |
Sorry, the diff of this file is not supported yet
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
86505
42
1366