UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

44 lines (43 loc) 1.57 kB
import { logger as N } from "../../shared-lib/index.js"; import { BRAZE_MUST_BE_INITIALIZED_ERROR as p } from "../common/constants.js"; import r, { OPTIONS as w } from "../managers/braze-instance.js"; import { isArray as z } from "../util/code-utils.js"; import { isValidBannerPlacementId as D } from "../util/validation-utils.js"; import i from "./banner-provider-factory.js"; export function requestBannersRefresh(e, n, t) { if (!r.rr()) return void N.warn(p); const s = r.v(); if (!s) return; if (!z(e) || 0 === e.length) return void N.warn("placementIds should be a non-empty array."); if (!r.ee(w.re)) return void N.error( "Banners are disabled. Use the 'allowUserSuppliedJavascript' option for braze.initialize to enable these messages.", ); const o = i.m(); if (i.m().Rt()) return void N.warn( "Banners can be refreshed only once per session per user.", ); if (!s || !o.L()) return void s.A(() => { requestBannersRefresh(e, n, t); }); const a = s.ne(); e.length > a && (N.warn( `Number of placement IDs requested exceeds the max allowed. Trimming placementIds array from length ${e.length} to ${a} (max allowed).`, ), (e = e.slice(0, a))), 0 !== (e = e.filter( (e) => !!D(e) || (N.warn( `Placement ID should be a valid utf8 string with no whitespaces, filtering out: ${e}`, ), !1), )).length && (N.info(`Requesting banners for placement IDs: ${JSON.stringify(e)}`), i.m().$(e, n, t)); }