@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
47 lines (46 loc) • 1.63 kB
JavaScript
import { logger as N } 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 z } from "../managers/braze-instance.js";
import { isArray as D } from "../util/code-utils.js";
import { isValidBannerPlacementId as R } 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(w);
const s = r.v();
if (!s) return;
if (!D(e) || 0 === e.length)
return void N.warn("placementIds should be a non-empty array.");
if (!r.ee(z.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 ((!1 === s.zt() && N.error(v), !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) =>
!!R(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));
}