@schibsted/niche-advertory-adapter
Advanced tools
Comparing version 2.3.0 to 2.3.1
import type { Placement, SiteConfig } from '@sch-inventory/advertory/types/core/interface/config'; | ||
import { Device } from './types'; | ||
import type { AdsConfig, FinnBlinkConfig, GlimrConfig, LoadAdsParams, PartialAdvertoryConfig, invCodeBuilderSignature } from './types'; | ||
import type { AdsConfig, Device, FinnBlinkConfig, GlimrConfig, LoadAdsParams, PartialAdvertoryConfig, invCodeBuilderSignature } from './types'; | ||
export declare class AdvertoryAdapter { | ||
@@ -20,4 +19,3 @@ private _eventTarget; | ||
private _finnBlink; | ||
private _refreshHorseshoe; | ||
constructor({ advertoryConfig, finnBlink, glimr, initAdvertoryPackage, nicheAdsConfig, nicheInvCodeBuilder, refreshHorseshoe, updateAdvertory, }: { | ||
constructor({ advertoryConfig, finnBlink, glimr, initAdvertoryPackage, nicheAdsConfig, nicheInvCodeBuilder, updateAdvertory, }: { | ||
advertoryConfig: PartialAdvertoryConfig; | ||
@@ -31,7 +29,2 @@ finnBlink?: Pick<FinnBlinkConfig, 'channel'>; | ||
nicheInvCodeBuilder: invCodeBuilderSignature; | ||
refreshHorseshoe?: { | ||
enabled: boolean; | ||
interval: number; | ||
targetIdsToRefresh: string[]; | ||
}; | ||
updateAdvertory: (config: Partial<SiteConfig>) => Promise<Placement[]>; | ||
@@ -47,4 +40,2 @@ }); | ||
loadAds(options: LoadAdsParams): Promise<void>; | ||
private _stopHorseshoeRefresh; | ||
private _startHorseshoeRefresh; | ||
private _reLoadAds; | ||
@@ -51,0 +42,0 @@ set device(device: Device); |
@@ -11,3 +11,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { eventTarget } from '@schibsted/niche-utils'; | ||
import { Device } from './types'; | ||
const { getEventTarget } = eventTarget; | ||
@@ -21,3 +20,3 @@ export class AdvertoryAdapter { | ||
} | ||
constructor({ advertoryConfig, finnBlink, glimr, initAdvertoryPackage, nicheAdsConfig, nicheInvCodeBuilder, refreshHorseshoe, updateAdvertory, }) { | ||
constructor({ advertoryConfig, finnBlink, glimr, initAdvertoryPackage, nicheAdsConfig, nicheInvCodeBuilder, updateAdvertory, }) { | ||
this._eventTarget = getEventTarget(); | ||
@@ -36,3 +35,2 @@ this._device = null; | ||
}; | ||
this._refreshHorseshoe = null; | ||
this._advertoryConfig = advertoryConfig; | ||
@@ -47,3 +45,2 @@ this._glimr.clientId = glimr.clientId; | ||
} | ||
this._refreshHorseshoe = refreshHorseshoe || null; | ||
} | ||
@@ -61,3 +58,3 @@ initialize(initializationConfig) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f; | ||
this._lastLoadAdsParams = options; | ||
@@ -67,3 +64,2 @@ if (!this._initialized || !this._device) { | ||
} | ||
this._stopHorseshoeRefresh(); | ||
const placementsCommonConfig = this._nicheAdsConfig.placements.common; | ||
@@ -109,46 +105,4 @@ const placements = { | ||
} | ||
if ((_g = this._refreshHorseshoe) === null || _g === void 0 ? void 0 : _g.enabled) { | ||
this._startHorseshoeRefresh(); | ||
} | ||
}); | ||
} | ||
_stopHorseshoeRefresh() { | ||
var _a; | ||
if ((_a = this._refreshHorseshoe) === null || _a === void 0 ? void 0 : _a.timeoutId) { | ||
clearTimeout(this._refreshHorseshoe.timeoutId); | ||
this._refreshHorseshoe.timeoutId = undefined; | ||
} | ||
} | ||
_startHorseshoeRefresh() { | ||
var _a, _b, _c, _d; | ||
this._stopHorseshoeRefresh(); | ||
if (this._device === Device.Desktop && | ||
((_a = this._refreshHorseshoe) === null || _a === void 0 ? void 0 : _a.interval) && | ||
((_c = (_b = this._refreshHorseshoe) === null || _b === void 0 ? void 0 : _b.targetIdsToRefresh) === null || _c === void 0 ? void 0 : _c.length) > 0) { | ||
if (!((_d = this._refreshHorseshoe) === null || _d === void 0 ? void 0 : _d.visibilityListenerAttached)) { | ||
this._refreshHorseshoe.visibilityListenerAttached = true; | ||
document.addEventListener('visibilitychange', () => { | ||
if (document.visibilityState === 'visible') { | ||
this._startHorseshoeRefresh(); | ||
} | ||
else { | ||
this._stopHorseshoeRefresh(); | ||
} | ||
}); | ||
} | ||
this._refreshHorseshoe.timeoutId = setTimeout(() => { | ||
var _a; | ||
if ((_a = window.apntag) === null || _a === void 0 ? void 0 : _a.loaded) { | ||
const idsToRefresh = []; | ||
document | ||
.querySelectorAll(this._refreshHorseshoe.targetIdsToRefresh.map((id) => `[id^="${id}"]`).join(',')) | ||
.forEach((node) => { | ||
idsToRefresh.push(node.id); | ||
}); | ||
window.apntag.refresh(idsToRefresh); | ||
} | ||
this._startHorseshoeRefresh(); | ||
}, this._refreshHorseshoe.interval); | ||
} | ||
} | ||
_reLoadAds() { | ||
@@ -155,0 +109,0 @@ if (this._lastLoadAdsParams) { |
import type { AstAdType } from '@sch-inventory/advertory/types/core/interface/ast'; | ||
import type { SiteConfig } from '@sch-inventory/advertory/types/core/interface/config'; | ||
declare global { | ||
interface Window { | ||
apntag?: { | ||
loaded?: boolean; | ||
refresh: (placements: string[]) => void; | ||
}; | ||
} | ||
} | ||
export declare enum Device { | ||
@@ -12,0 +4,0 @@ Desktop = "desktop", |
{ | ||
"name": "@schibsted/niche-advertory-adapter", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"repository": { | ||
@@ -34,3 +34,3 @@ "type": "git", | ||
}, | ||
"gitHead": "2d6656dda35b67f3d84c00e64ad72d1dcb3de8f8" | ||
"gitHead": "8b11066ca08cead7ca60ecdc613e0ca27ddee6c2" | ||
} |
import type { Placement, Placements, SiteConfig } from '@sch-inventory/advertory/types/core/interface/config'; | ||
import { eventTarget } from '@schibsted/niche-utils'; | ||
import type { UpdateAdvertoryConfig } from '@sch-inventory/advertory/types/core/interface/update-advertory'; | ||
import { Device } from './types'; | ||
import type { | ||
AdsConfig, | ||
Device, | ||
FinnBlinkConfig, | ||
@@ -59,10 +59,2 @@ GlimrConfig, | ||
private _refreshHorseshoe: { | ||
enabled: boolean; | ||
interval: number; | ||
targetIdsToRefresh: string[]; | ||
timeoutId?: ReturnType<typeof setTimeout>; | ||
visibilityListenerAttached?: boolean; | ||
} | null = null; | ||
constructor({ | ||
@@ -75,3 +67,2 @@ advertoryConfig, | ||
nicheInvCodeBuilder, | ||
refreshHorseshoe, | ||
updateAdvertory, | ||
@@ -85,7 +76,2 @@ }: { | ||
nicheInvCodeBuilder: invCodeBuilderSignature; | ||
refreshHorseshoe?: { | ||
enabled: boolean; | ||
interval: number; | ||
targetIdsToRefresh: string[]; | ||
}; | ||
updateAdvertory: (config: Partial<SiteConfig>) => Promise<Placement[]>; | ||
@@ -102,3 +88,2 @@ }) { | ||
} | ||
this._refreshHorseshoe = refreshHorseshoe || null; | ||
} | ||
@@ -131,4 +116,2 @@ | ||
this._stopHorseshoeRefresh(); | ||
const placementsCommonConfig = this._nicheAdsConfig.placements.common; | ||
@@ -202,50 +185,4 @@ const placements = { | ||
} | ||
if (this._refreshHorseshoe?.enabled) { | ||
this._startHorseshoeRefresh(); | ||
} | ||
} | ||
private _stopHorseshoeRefresh() { | ||
if (this._refreshHorseshoe?.timeoutId) { | ||
clearTimeout(this._refreshHorseshoe.timeoutId); | ||
this._refreshHorseshoe.timeoutId = undefined; | ||
} | ||
} | ||
private _startHorseshoeRefresh() { | ||
this._stopHorseshoeRefresh(); | ||
if ( | ||
this._device === Device.Desktop && | ||
this._refreshHorseshoe?.interval && | ||
this._refreshHorseshoe?.targetIdsToRefresh?.length > 0 | ||
) { | ||
if (!this._refreshHorseshoe?.visibilityListenerAttached) { | ||
this._refreshHorseshoe.visibilityListenerAttached = true; | ||
document.addEventListener('visibilitychange', () => { | ||
if (document.visibilityState === 'visible') { | ||
this._startHorseshoeRefresh(); | ||
} else { | ||
this._stopHorseshoeRefresh(); | ||
} | ||
}); | ||
} | ||
this._refreshHorseshoe.timeoutId = setTimeout(() => { | ||
if (window.apntag?.loaded) { | ||
const idsToRefresh: string[] = []; | ||
document | ||
.querySelectorAll( | ||
this._refreshHorseshoe!.targetIdsToRefresh.map((id) => `[id^="${id}"]`).join(',') | ||
) | ||
.forEach((node) => { | ||
idsToRefresh.push(node.id); | ||
}); | ||
window.apntag.refresh(idsToRefresh); | ||
} | ||
this._startHorseshoeRefresh(); | ||
}, this._refreshHorseshoe.interval); | ||
} | ||
} | ||
private _reLoadAds() { | ||
@@ -252,0 +189,0 @@ if (this._lastLoadAdsParams) { |
import type { AstAdType } from '@sch-inventory/advertory/types/core/interface/ast'; | ||
import type { SiteConfig } from '@sch-inventory/advertory/types/core/interface/config'; | ||
declare global { | ||
interface Window { | ||
apntag?: { | ||
loaded?: boolean; | ||
refresh: (placements: string[]) => void; | ||
}; | ||
} | ||
} | ||
export enum Device { | ||
@@ -14,0 +5,0 @@ Desktop = 'desktop', |
29094
495