@braze/web-sdk 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Type definitions for @braze/web-sdk v4.0.0
2
+ * Type definitions for @braze/web-sdk v4.0.1
3
3
  * Project: https://github.com/braze-inc/braze-web-sdk
4
4
  * (c) Braze, Inc. 2022 - http://braze.com
5
5
  * License available at https://github.com/braze-inc/braze-web-sdk/blob/master/LICENSE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@braze/web-sdk",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Braze SDK for web sites and other JS platforms.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -23,5 +23,6 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
- "sideEffects": false
26
+ "sideEffects": false,
27
+ "type": "module"
27
28
  }
@@ -1 +1 @@
1
- const Ae={init:function(n){void 0===n&&void 0!==Ae.zg||(Ae.zg=!!n),Ae.Dg||(Ae.Dg=!0)},destroy:function(){Ae.Dg=!1,Ae.zg=void 0,Ae.nd=void 0},setLogger:function(n){"function"==typeof n?(Ae.init(),Ae.nd=n):Ae.info("Ignoring setLogger call since logger is not a function")},toggleLogging:function(){Ae.init(),Ae.zg?(console.log("Disabling Braze logging"),Ae.zg=!1):(console.log("Enabled Braze logging"),Ae.zg=!0)},info:function(n){if(Ae.zg){const o="Braze: "+n;null!=Ae.nd?Ae.nd(o):console.log(o)}},warn:function(n){if(Ae.zg){const o="Braze SDK Warning: "+n+" (v4.0.0)";null!=Ae.nd?Ae.nd(o):console.warn(o)}},error:function(n){if(Ae.zg){const o="Braze SDK Error: "+n+" (v4.0.0)";null!=Ae.nd?Ae.nd(o):console.error(o)}}};export default Ae;
1
+ const Ae={init:function(n){void 0===n&&void 0!==Ae.zg||(Ae.zg=!!n),Ae.Dg||(Ae.Dg=!0)},destroy:function(){Ae.Dg=!1,Ae.zg=void 0,Ae.nd=void 0},setLogger:function(n){"function"==typeof n?(Ae.init(),Ae.nd=n):Ae.info("Ignoring setLogger call since logger is not a function")},toggleLogging:function(){Ae.init(),Ae.zg?(console.log("Disabling Braze logging"),Ae.zg=!1):(console.log("Enabled Braze logging"),Ae.zg=!0)},info:function(n){if(Ae.zg){const o="Braze: "+n;null!=Ae.nd?Ae.nd(o):console.log(o)}},warn:function(n){if(Ae.zg){const o="Braze SDK Warning: "+n+" (v4.0.1)";null!=Ae.nd?Ae.nd(o):console.warn(o)}},error:function(n){if(Ae.zg){const o="Braze SDK Error: "+n+" (v4.0.1)";null!=Ae.nd?Ae.nd(o):console.error(o)}}};export default Ae;
@@ -1 +1 @@
1
- import{Card,Banner,CaptionedImage,ClassicCard,ControlCard}from"../index.js";import{dateFromUnixTimestamp as h,rehydrateDateAfterJsonization as w}from"../../util/date-utils.js";import r from"../../../shared-lib/braze-shared-lib.js";export function newCard(e,n,t,o,i,l,u,d,a,s,w,f,m,C,p,c,x,F){let b;if(n===Card.es.Ct||n===Card.es.dt)b=new ClassicCard(e,t,o,i,l,u,d,a,s,w,f,m,C,p,c,x);else if(n===Card.es.st)b=new CaptionedImage(e,t,o,i,l,u,d,a,s,w,f,m,C,p,c,x);else if(n===Card.es.rs)b=new Banner(e,t,i,u,d,a,s,w,f,m,C,p,c,x);else{if(n!==Card.es.Rt)return r.D.error("Ignoring card with unknown type "+n),null;b=new ControlCard(e,t,d,s,C,p)}return F&&(b.test=F),b}export function newCardFromContentCardsJson(e){if(e[Card.ct.At])return null;const n=e[Card.ct.ns],r=e[Card.ct.ts],t=e[Card.ct.ls],o=e[Card.ct.it],i=e[Card.ct.os],l=e[Card.ct.ht],u=h(e[Card.ct.us]);let d;d=e[Card.ct.ps]===Card.Dt?null:h(e[Card.ct.ps]);return newCard(n,r,t,o,i,l,null,u,null,d,e[Card.ct.URL],e[Card.ct.bs],e[Card.ct.fs],e[Card.ct.xs],e[Card.ct.js],e[Card.ct.zs],e[Card.ct.gs],e[Card.ct.ks]||!1)}export function newCardFromFeedJson(e){return newCard(e.id,e.type,e.viewed,e.title,e.image,e.description,h(e.created),h(e.updated),e.categories,h(e.expires_at),e.url,e.domain,e.aspect_ratio,e.extras,!1,!1)}export function newCardFromSerializedValue(e){return newCard(e[Card.hs.ns],e[Card.hs.ts],e[Card.hs.ls],e[Card.hs.it],e[Card.hs.os],e[Card.hs.ht],w(e[Card.hs.cs]),w(e[Card.hs.us]),e[Card.hs.ds],w(e[Card.hs.ps]),e[Card.hs.URL],e[Card.hs.bs],e[Card.hs.fs],e[Card.hs.xs],e[Card.hs.js],e[Card.hs.zs],e[Card.hs.gs],e[Card.hs.ks]||!1)??void 0}
1
+ import{Card,Banner,CaptionedImage,ClassicCard,ControlCard}from"../index.js";import{dateFromUnixTimestamp as h,rehydrateDateAfterJsonization as w}from"../../util/date-utils.js";import r from"../../../shared-lib/braze-shared-lib.js";export function newCard(e,n,t,o,i,l,u,d,a,s,w,f,m,C,p,c,x,F){let b;if(n===Card.es.Ct||n===Card.es.dt)b=new ClassicCard(e,t,o,i,l,u,d,a,s,w,f,m,C,p,c,x);else if(n===Card.es.st)b=new CaptionedImage(e,t,o,i,l,u,d,a,s,w,f,m,C,p,c,x);else if(n===Card.es.rs)b=new Banner(e,t,i,u,d,a,s,w,f,m,C,p,c,x);else{if(n!==Card.es.Rt)return r.D.error("Ignoring card with unknown type "+n),null;b=new ControlCard(e,t,d,s,C,p)}return F&&(b.test=F),b}export function newCardFromContentCardsJson(e){if(e[Card.ct.At])return null;const n=e[Card.ct.ns],r=e[Card.ct.ts],t=e[Card.ct.ls],o=e[Card.ct.it],i=e[Card.ct.os],l=e[Card.ct.ht],u=h(e[Card.ct.us]),d=u;let a;a=e[Card.ct.ps]===Card.Dt?null:h(e[Card.ct.ps]);return newCard(n,r,t,o,i,l,d,u,null,a,e[Card.ct.URL],e[Card.ct.bs],e[Card.ct.fs],e[Card.ct.xs],e[Card.ct.js],e[Card.ct.zs],e[Card.ct.gs],e[Card.ct.ks]||!1)}export function newCardFromFeedJson(e){return newCard(e.id,e.type,e.viewed,e.title,e.image,e.description,h(e.created),h(e.updated),e.categories,h(e.expires_at),e.url,e.domain,e.aspect_ratio,e.extras,!1,!1)}export function newCardFromSerializedValue(e){return newCard(e[Card.hs.ns],e[Card.hs.ts],e[Card.hs.ls],e[Card.hs.it],e[Card.hs.os],e[Card.hs.ht],w(e[Card.hs.cs]),w(e[Card.hs.us]),e[Card.hs.ds],w(e[Card.hs.ps]),e[Card.hs.URL],e[Card.hs.bs],e[Card.hs.fs],e[Card.hs.xs],e[Card.hs.js],e[Card.hs.zs],e[Card.hs.gs],e[Card.hs.ks]||!1)??void 0}
@@ -1 +1 @@
1
- import St from"./auth-manager.js";import C from"../common/base-provider.js";import et from"../util/browser-detector.js";import _t from"./device-manager.js";import DeviceProperties from"../Core/device-properties.js";import{isArray as p,keys as X,validateValueIsFromEnum as B,values as It}from"../util/code-utils.js";import{logDeprecationWarning as At}from"../util/deprecation-utils.js";import Nt from"./network-manager.js";import wt from"../request-controller.js";import Tt from"./server-config-manager.js";import Ot from"./session-manager.js";import r from"../../shared-lib/braze-shared-lib.js";import K,{STORAGE_KEYS as o}from"./storage-manager.js";import vt from"./storage-manager-factory.js";import u from"./subscription-manager.js";import{TriggersProviderFactory as Q}from"../triggers/triggers-provider-factory.js";import pt from"../User/user-manager.js";import{User}from"../User/index.js";import{parseQueryStringKeyValues as st}from"../util/url-utils.js";import{WindowUtils as P}from"../util/window-utils.js";const D={$n:"allowCrawlerActivity",ea:"baseUrl",Yn:"noCookies",Xn:"devicePropertyAllowlist",ta:"disablePushTokenMaintenance",Zn:"enableLogging",ho:"enableSdkAuthentication",ia:"manageServiceWorkerExternally",lo:"minimumIntervalBetweenTriggerActionsInSeconds",uo:"sessionTimeoutInSeconds",po:"appVersion",na:"serviceWorkerLocation",ra:"safariWebsitePushId",zn:"localization",yi:"contentSecurityNonce",co:"enableHtmlInAppMessages",mo:"allowUserSuppliedJavascript",vi:"inAppMessageZIndex",zi:"openInAppMessagesInNewTab",tn:"openCardsInNewTab",en:"openNewsFeedCardsInNewTab",Oi:"requireExplicitInAppMessageDismissal",Eo:"doNotLoadFontAwesome",_o:"sdkFlavor"};class Ct{constructor(){this.fo=!1,this.Io=!1,this.Ao=new u,this.So=new u,this.No={},this.wo=[],this.To=[],this.De=[],this.Oo="4.0.0"}vo(t){this.Ao.Et(t)}Mi(t){this.So.Et(t)}initialize(t,i){if(this.bo())return r.D.info("Braze has already been initialized with an API key."),!0;this.No=i||{};let s=this.nn(D.Zn);const e=st(P.Pn());if(e&&"true"===e.brazeLogging&&(s=!0),r.D.init(s),r.D.info(`Initialization Options: ${JSON.stringify(this.No,null,2)}`),null==t||""===t||"string"!=typeof t)return r.D.error("Braze requires a valid API key to be initialized."),!1;this.Wi=t;let n=this.nn(D.ea);if(null==n||""===n||"string"!=typeof n)return r.D.error("Braze requires a valid baseUrl to be initialized."),!1;if(n=n.replace(/(\.[a-z]+)[^\.]*$/i,"$1/api/v3"),0!==n.indexOf("http")&&(n="https://"+n),this.Co=n,et.Lo&&!this.nn(D.$n))return r.D.info("Ignoring activity from crawler bot "+navigator.userAgent),this.Io=!0,!1;const a=this.nn(Ct.Yn)||!1;if(this.h=vt.Po(t,a),new K.ne(null,!0).wr(o.ae))return r.D.info("Ignoring all activity due to previous opt out"),this.Io=!0,!1;for(const t of X(this.No))-1===It(r.Ro).indexOf(t)&&r.D.warn(`Ignoring unknown initialization option '${t}'.`);const h=["mparticle","wordpress","tealium"];if(null!=this.nn(D._o)){const t=this.nn(D._o);-1!==h.indexOf(t)?this.Mo=t:r.D.error("Invalid sdk flavor passed: "+t)}let l=this.nn(r.Ro.Xn);if(null!=l)if(p(l)){const t=[];for(let i=0;i<l.length;i++)B(DeviceProperties,l[i],"devicePropertyAllowlist contained an invalid value.","DeviceProperties")&&t.push(l[i]);l=t}else r.D.error("devicePropertyAllowlist must be an array. Defaulting to all properties."),l=null;this.xi=new _t(this.h,l),this.wt=new Tt(this.h),this.v=new pt(this.wt,this.h),this.j=new Ot(this.h,this.v,this.wt,this.nn(D.uo));const c=new u;return this.yo=new St(this.h,this.nn(D.ho),c),this.Ut(c),this.jt=new Nt(this.xi,this.h,this.yo,this.v,this.j,this.wt,this.Wi,this.Co,this.Oo,this.Mo,this.nn(D.po)),this.Is=new wt(this.Wi,this.Co,this.j,this.xi,this.v,this.wt,this.h,(t=>{if(this.bo())for(const i of this.re())i._s(t)}),this.yo,this.jt),this.Is.initialize(),r.D.info(`Initialized for the Braze backend at "${this.nn(D.ea)}" with API key "${this.Wi}".`),null!=this.nn(D.co)&&At("enableHtmlInAppMessages","initialization option","allowUserSuppliedJavascript"),Q.init(),this.Ao.Nt(this.No),this.fo=!0,!0}destroy(t){if(r.D.destroy(),this.bo()){this.So.Nt(),this.So.removeAllSubscriptions();for(const t of this.wo)t.destroy();this.wo=[];for(const t of this.To)t.clearData(!1);this.To=[],this.removeAllSubscriptions(),this.De=[],this.Is.destroy(),this.Is=null,this.yo=null,this.xi=null,this.jt=null,this.wt=null,this.j=null,this.v=null,this.No={},this.Mo=void 0,this.fo=!1,this.Io=!1,t&&(this.h=null)}}rr(){if(this.Do())return!1;if(!this.bo())throw new Error("Braze must be initialized before calling methods.");return!0}aa(){return this.Wi}ti(){return this.yo}ce(){return this.xi}nr(){return this.jt}nn(t){return this.No[t]}re(){return this.To}pr(){return this.Is}ir(){return this.wt}g(){return this.j}l(){return this.h}jr(){if(this.v&&this.Is)return new User(this.v,this.Is)}p(){return this.v}tr(){return!0===this.nn(D.mo)||!0===this.nn(D.co)}u(t){let i=!1;for(const s of this.wo)s===t&&(i=!0);i||this.wo.push(t)}ar(t){let i=!1;for(const s of this.To)s.constructor===t.constructor&&(i=!0);t instanceof C&&!i&&this.To.push(t)}Ut(t){t instanceof u&&this.De.push(t)}removeAllSubscriptions(){if(this.rr())for(const t of this.De)t.removeAllSubscriptions()}removeSubscription(t){if(this.rr())for(const i of this.De)i.removeSubscription(t)}le(t){this.Io=t}bo(){return this.fo}Do(){return this.Io}}const e=new Ct;export{e as default,Ct as BrazeSdkInstance,D as OPTIONS};
1
+ import St from"./auth-manager.js";import C from"../common/base-provider.js";import et from"../util/browser-detector.js";import _t from"./device-manager.js";import DeviceProperties from"../Core/device-properties.js";import{isArray as p,keys as X,validateValueIsFromEnum as B,values as It}from"../util/code-utils.js";import{logDeprecationWarning as At}from"../util/deprecation-utils.js";import Nt from"./network-manager.js";import wt from"../request-controller.js";import Tt from"./server-config-manager.js";import Ot from"./session-manager.js";import r from"../../shared-lib/braze-shared-lib.js";import K,{STORAGE_KEYS as o}from"./storage-manager.js";import vt from"./storage-manager-factory.js";import u from"./subscription-manager.js";import{TriggersProviderFactory as Q}from"../triggers/triggers-provider-factory.js";import pt from"../User/user-manager.js";import{User}from"../User/index.js";import{parseQueryStringKeyValues as st}from"../util/url-utils.js";import{WindowUtils as P}from"../util/window-utils.js";const D={$n:"allowCrawlerActivity",ea:"baseUrl",Yn:"noCookies",Xn:"devicePropertyAllowlist",ta:"disablePushTokenMaintenance",Zn:"enableLogging",ho:"enableSdkAuthentication",ia:"manageServiceWorkerExternally",lo:"minimumIntervalBetweenTriggerActionsInSeconds",uo:"sessionTimeoutInSeconds",po:"appVersion",na:"serviceWorkerLocation",ra:"safariWebsitePushId",zn:"localization",yi:"contentSecurityNonce",co:"enableHtmlInAppMessages",mo:"allowUserSuppliedJavascript",vi:"inAppMessageZIndex",zi:"openInAppMessagesInNewTab",tn:"openCardsInNewTab",en:"openNewsFeedCardsInNewTab",Oi:"requireExplicitInAppMessageDismissal",Eo:"doNotLoadFontAwesome",_o:"sdkFlavor"};class Ct{constructor(){this.fo=!1,this.Io=!1,this.Ao=new u,this.So=new u,this.No={},this.wo=[],this.To=[],this.De=[],this.Oo="4.0.1"}vo(t){this.Ao.Et(t)}Mi(t){this.So.Et(t)}initialize(t,i){if(this.bo())return r.D.info("Braze has already been initialized with an API key."),!0;this.No=i||{};let s=this.nn(D.Zn);const e=st(P.Pn());if(e&&"true"===e.brazeLogging&&(s=!0),r.D.init(s),r.D.info(`Initialization Options: ${JSON.stringify(this.No,null,2)}`),null==t||""===t||"string"!=typeof t)return r.D.error("Braze requires a valid API key to be initialized."),!1;this.Wi=t;let n=this.nn(D.ea);if(null==n||""===n||"string"!=typeof n)return r.D.error("Braze requires a valid baseUrl to be initialized."),!1;if(n=n.replace(/(\.[a-z]+)[^\.]*$/i,"$1/api/v3"),0!==n.indexOf("http")&&(n="https://"+n),this.Co=n,et.Lo&&!this.nn(D.$n))return r.D.info("Ignoring activity from crawler bot "+navigator.userAgent),this.Io=!0,!1;const a=this.nn(Ct.Yn)||!1;if(this.h=vt.Po(t,a),new K.ne(null,!0).wr(o.ae))return r.D.info("Ignoring all activity due to previous opt out"),this.Io=!0,!1;for(const t of X(this.No))-1===It(r.Ro).indexOf(t)&&r.D.warn(`Ignoring unknown initialization option '${t}'.`);const h=["mparticle","wordpress","tealium"];if(null!=this.nn(D._o)){const t=this.nn(D._o);-1!==h.indexOf(t)?this.Mo=t:r.D.error("Invalid sdk flavor passed: "+t)}let l=this.nn(r.Ro.Xn);if(null!=l)if(p(l)){const t=[];for(let i=0;i<l.length;i++)B(DeviceProperties,l[i],"devicePropertyAllowlist contained an invalid value.","DeviceProperties")&&t.push(l[i]);l=t}else r.D.error("devicePropertyAllowlist must be an array. Defaulting to all properties."),l=null;this.xi=new _t(this.h,l),this.wt=new Tt(this.h),this.v=new pt(this.wt,this.h),this.j=new Ot(this.h,this.v,this.wt,this.nn(D.uo));const c=new u;return this.yo=new St(this.h,this.nn(D.ho),c),this.Ut(c),this.jt=new Nt(this.xi,this.h,this.yo,this.v,this.j,this.wt,this.Wi,this.Co,this.Oo,this.Mo,this.nn(D.po)),this.Is=new wt(this.Wi,this.Co,this.j,this.xi,this.v,this.wt,this.h,(t=>{if(this.bo())for(const i of this.re())i._s(t)}),this.yo,this.jt),this.Is.initialize(),r.D.info(`Initialized for the Braze backend at "${this.nn(D.ea)}" with API key "${this.Wi}".`),null!=this.nn(D.co)&&At("enableHtmlInAppMessages","initialization option","allowUserSuppliedJavascript"),Q.init(),this.Ao.Nt(this.No),this.fo=!0,!0}destroy(t){if(r.D.destroy(),this.bo()){this.So.Nt(),this.So.removeAllSubscriptions();for(const t of this.wo)t.destroy();this.wo=[];for(const t of this.To)t.clearData(!1);this.To=[],this.removeAllSubscriptions(),this.De=[],this.Is.destroy(),this.Is=null,this.yo=null,this.xi=null,this.jt=null,this.wt=null,this.j=null,this.v=null,this.No={},this.Mo=void 0,this.fo=!1,this.Io=!1,t&&(this.h=null)}}rr(){if(this.Do())return!1;if(!this.bo())throw new Error("Braze must be initialized before calling methods.");return!0}aa(){return this.Wi}ti(){return this.yo}ce(){return this.xi}nr(){return this.jt}nn(t){return this.No[t]}re(){return this.To}pr(){return this.Is}ir(){return this.wt}g(){return this.j}l(){return this.h}jr(){if(this.v&&this.Is)return new User(this.v,this.Is)}p(){return this.v}tr(){return!0===this.nn(D.mo)||!0===this.nn(D.co)}u(t){let i=!1;for(const s of this.wo)s===t&&(i=!0);i||this.wo.push(t)}ar(t){let i=!1;for(const s of this.To)s.constructor===t.constructor&&(i=!0);t instanceof C&&!i&&this.To.push(t)}Ut(t){t instanceof u&&this.De.push(t)}removeAllSubscriptions(){if(this.rr())for(const t of this.De)t.removeAllSubscriptions()}removeSubscription(t){if(this.rr())for(const i of this.De)i.removeSubscription(t)}le(t){this.Io=t}bo(){return this.fo}Do(){return this.Io}}const e=new Ct;export{e as default,Ct as BrazeSdkInstance,D as OPTIONS};
@@ -1 +1 @@
1
- export default class jt{constructor(t,s,i,h,l,e,r){this.hh=t||0,this.gh=s||[],this.mh=i||[],this.fh=h||[],this.ph=l,null!=l&&""!==l||(this.ph=null),this.oh=e||null,this.uh=r||{}}ss(){return{s:"4.0.0",l:this.hh,e:this.gh,a:this.mh,p:this.fh,m:this.ph,v:this.oh,c:this.uh}}static jn(t){let s=t.l;return"4.0.0"!==t.s&&(s=0),new jt(s,t.e,t.a,t.p,t.m,t.v,t.c)}}
1
+ export default class jt{constructor(t,s,i,h,l,e,r){this.hh=t||0,this.gh=s||[],this.mh=i||[],this.fh=h||[],this.ph=l,null!=l&&""!==l||(this.ph=null),this.oh=e||null,this.uh=r||{}}ss(){return{s:"4.0.1",l:this.hh,e:this.gh,a:this.mh,p:this.fh,m:this.ph,v:this.oh,c:this.uh}}static jn(t){let s=t.l;return"4.0.1"!==t.s&&(s=0),new jt(s,t.e,t.a,t.p,t.m,t.v,t.c)}}
@@ -1 +1 @@
1
- import e,{OPTIONS as D}from"../../managers/braze-instance.js";export function attachCSS(n,t,o){const c=n??document.querySelector("head"),s=`ab-${t}-css-definitions-${"4.0.0".replace(/\./g,"-")}`,a=c.ownerDocument??document;if(null==a.getElementById(s)){const n=a.createElement("style");n.innerHTML=o,n.id=s;const t=e.nn(D.yi);null!=t&&n.setAttribute("nonce",t),c.appendChild(n)}}
1
+ import e,{OPTIONS as D}from"../../managers/braze-instance.js";export function attachCSS(n,t,o){const c=n??document.querySelector("head"),s=`ab-${t}-css-definitions-${"4.0.1".replace(/\./g,"-")}`,a=c.ownerDocument??document;if(null==a.getElementById(s)){const n=a.createElement("style");n.innerHTML=o,n.id=s;const t=e.nn(D.yi);null!=t&&n.setAttribute("nonce",t),c.appendChild(n)}}