UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

43 lines (42 loc) 1.51 kB
import { logger as E } from "../../shared-lib/index.js"; import { BANNERS_DISABLED_MESSAGE as v, BRAZE_MUST_BE_INITIALIZED_ERROR as w, } from "../common/constants.js"; import r, { OPTIONS as q } 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, t, n) { if (!r.rr()) return void E.warn(w); const o = r.l(); if (!o) return; if (!z(e) || 0 === e.length) return void E.warn("placementIds should be a non-empty array."); if (!r.ee(q.re)) return void E.error( "Banners are disabled. Use the 'allowUserSuppliedJavascript' option for braze.initialize to enable these messages.", ); const s = i.o(); if ((!1 === o.Dt() && E.error(v), !s.k())) return void o.P(() => { requestBannersRefresh(e, t, n); }); const a = o.te(); e.length > a && (E.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) || (E.warn( `Placement ID should be a valid utf8 string with no whitespaces, filtering out: ${e}`, ), !1), )).length && (E.info(`Requesting banners for placement IDs: ${JSON.stringify(e)}`), s.M(e, t, n)); }