UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

76 lines (75 loc) 1.96 kB
import { logger as N } from "../../shared-lib/index.js"; export default class FeatureFlag { constructor(t, e = !1, r = {}, i) { (this.id = t), (this.enabled = e), (this.properties = r), (this.trackingString = i), (this.id = t), (this.enabled = e), (this.properties = r), (this.trackingString = i); } he(t, e, r) { const i = this.properties[t]; return null == i ? (this.ye(t), null) : e(i) ? i.value : (this.Pe(r), null); } getStringProperty(t) { return this.he(t, this.Ie, "string"); } getNumberProperty(t) { return this.he(t, this.Te, "number"); } getBooleanProperty(t) { return this.he(t, this.Ne, "boolean"); } getImageProperty(t) { return this.he(t, this.Re, "image"); } getJsonProperty(t) { return this.he(t, this.Se, "jsonobject"); } getTimestampProperty(t) { return this.he(t, this.Ae, "datetime"); } bt() { const t = {}; return ( (t[FeatureFlag.hs.os] = this.id), (t[FeatureFlag.hs.Fe] = this.enabled), (t[FeatureFlag.hs.we] = this.properties), (t[FeatureFlag.hs.xe] = this.trackingString), t ); } Pe(t) { N.info(`Property is not of type ${t}.`); } ye(t) { N.info(`${t} not found in feature flag properties.`); } Ie(t) { return "string" === t.type && "string" == typeof t.value; } Te(t) { return "number" === t.type && "number" == typeof t.value; } Ne(t) { return "boolean" === t.type && "boolean" == typeof t.value; } Re(t) { return "image" === t.type && "string" == typeof t.value; } Se(t) { return ( "jsonobject" === t.type && "object" == typeof t.value && t.value.constructor == Object ); } Ae(t) { return "datetime" === t.type && "number" == typeof t.value; } } (FeatureFlag.hs = { os: "id", Fe: "e", we: "pr", xe: "fts" }), (FeatureFlag.ui = { os: "id", Fe: "enabled", we: "properties", xe: "fts" });