@braze/web-sdk 4.0.3 → 4.0.6
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 +2 -4
- package/package.json +1 -1
- package/shared-lib/braze-shared-lib.js +1 -1
- package/shared-lib/encoding-utils.js +1 -1
- package/shared-lib/event-types.js +1 -1
- package/shared-lib/guid.js +1 -1
- package/shared-lib/indexed-db-adapter.js +1 -1
- package/shared-lib/logger.js +1 -1
- package/shared-lib/supported-options.js +1 -1
- package/src/ContentCards/log-content-cards-displayed.js +1 -1
- package/src/ContentCards/subscribe-to-content-cards-updates.js +1 -1
- package/src/ContentCards/ui/hide-content-cards.js +1 -1
- package/src/ContentCards/ui/show-content-cards.js +1 -1
- package/src/Core/add-sdk-metadata.js +1 -1
- package/src/Core/change-user.js +1 -1
- package/src/Core/disable-sdk.js +1 -1
- package/src/Core/enable-sdk.js +1 -1
- package/src/Core/get-user.js +1 -1
- package/src/Core/handle-braze-action.js +1 -1
- package/src/Core/is-disabled.js +1 -1
- package/src/Core/log-custom-event.js +1 -1
- package/src/Core/log-purchase.js +1 -1
- package/src/Core/open-session.js +1 -1
- package/src/Core/request-immediate-data-flush.js +1 -1
- package/src/Core/wipe-data.js +1 -1
- package/src/Feed/feed-provider-factory.js +1 -1
- package/src/Feed/feed-provider.js +1 -1
- package/src/Feed/get-cached-feed.js +1 -1
- package/src/Feed/log-feed-displayed.js +1 -1
- package/src/Feed/request-feed-refresh.js +1 -1
- package/src/Feed/subscribe-to-feed-updates.js +1 -1
- package/src/Feed/ui/hide-feed.js +1 -1
- package/src/Feed/ui/show-feed.js +1 -1
- package/src/InAppMessage/display/get-animation-effect.js +1 -1
- package/src/InAppMessage/display/html-message-to-html.js +1 -1
- package/src/InAppMessage/display/in-app-message-to-html.js +1 -1
- package/src/InAppMessage/display/modal-utils.js +1 -1
- package/src/InAppMessage/in-app-message-factory.js +1 -1
- package/src/InAppMessage/in-app-message-manager-factory.js +1 -1
- package/src/InAppMessage/in-app-message-manager.js +1 -1
- package/src/InAppMessage/log-in-app-message-button-click.js +1 -1
- package/src/InAppMessage/log-in-app-message-click.js +1 -1
- package/src/InAppMessage/log-in-app-message-html-click.js +1 -1
- package/src/InAppMessage/log-in-app-message-impression.js +1 -1
- package/src/InAppMessage/models/full-screen-message.js +1 -1
- package/src/InAppMessage/models/html-message.js +1 -1
- package/src/InAppMessage/models/in-app-message-button.js +1 -1
- package/src/InAppMessage/models/in-app-message.js +1 -1
- package/src/InAppMessage/models/modal-message.js +1 -1
- package/src/InAppMessage/models/slide-up-message.js +1 -1
- package/src/InAppMessage/models/templated-in-app-message.js +1 -1
- package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +1 -1
- package/src/InAppMessage/ui/show-in-app-message.js +1 -1
- package/src/Push/is-push-blocked.js +1 -1
- package/src/Push/is-push-permission-granted.js +1 -1
- package/src/Push/is-push-supported.js +1 -1
- package/src/Push/push-manager-factory.js +1 -1
- package/src/Push/push-manager.js +1 -1
- package/src/Push/request-push-permission.js +1 -1
- package/src/Push/unregister-push.js +1 -1
- package/src/User/user-manager.js +1 -1
- package/src/User/user.js +1 -1
- package/src/common/base-feed.js +1 -1
- package/src/common/event-logger.js +1 -1
- package/src/common/feed-display.js +1 -1
- package/src/l10n/l10n-manager-factory.js +1 -1
- package/src/l10n/l10n-manager.js +1 -1
- package/src/managers/auth-manager.js +1 -1
- package/src/managers/braze-instance.js +1 -1
- package/src/managers/device-manager.js +1 -1
- package/src/managers/network-manager.js +1 -1
- package/src/managers/server-config-manager.js +1 -1
- package/src/managers/session-manager.js +1 -1
- package/src/managers/storage-manager-factory.js +1 -1
- package/src/managers/storage-manager.js +1 -1
- package/src/managers/subscription-manager.js +1 -1
- package/src/models/backend-errors.js +1 -1
- package/src/models/braze-event.js +1 -1
- package/src/models/device.js +1 -1
- package/src/models/identifier.js +1 -1
- package/src/models/push-token.js +1 -1
- package/src/models/server-config.js +1 -1
- package/src/request-controller.js +1 -1
- package/src/triggers/models/filter-set.js +1 -1
- package/src/triggers/models/filter.js +1 -1
- package/src/triggers/models/push-click-data.js +1 -1
- package/src/triggers/models/trigger-condition.js +1 -1
- package/src/triggers/models/trigger-events.js +1 -1
- package/src/triggers/models/trigger.js +1 -1
- package/src/triggers/triggers-provider-factory.js +1 -1
- package/src/triggers/triggers-provider.js +1 -1
- package/src/ui/js/attach-css.js +1 -1
- package/src/ui/js/feed-css.js +1 -1
- package/src/ui/js/iam-css.js +1 -1
- package/src/ui/js/load-font-awesome.js +1 -1
- package/src/util/base-device-parser.js +1 -1
- package/src/util/braze-actions.js +1 -1
- package/src/util/browser-detector.js +1 -1
- package/src/util/client-hints-parser.js +1 -1
- package/src/util/component-utils.js +1 -1
- package/src/util/date-utils.js +1 -1
- package/src/util/device-constants.js +1 -1
- package/src/util/dom-utils.js +1 -1
- package/src/util/key-codes.js +1 -1
- package/src/util/net.js +1 -1
- package/src/util/user-agent-parser.js +1 -1
- package/src/util/validation-utils.js +1 -1
- package/src/util/window-utils.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import
|
|
1
|
+
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import ControlMessage from"../models/control-message.js";import HtmlMessage from"../models/html-message.js";import InAppMessage from"../models/in-app-message.js";import SlideUpMessage from"../models/slide-up-message.js";import pe from"../in-app-message-manager-factory.js";import se from"../display/get-animation-effect.js";import ce from"../display/in-app-message-to-html.js";import{logInAppMessageImpression}from"../log-in-app-message-impression.js";import{ORIENTATION as le,WindowUtils as G}from"../../util/window-utils.js";import{isURIJavascriptOrData as j}from"../../util/url-utils.js";import{KeyCodes as at}from"../../util/key-codes.js";import{setupInAppMessageUI as ss}from"../../ui/js/index.js";import r from"../../../shared-lib/braze-shared-lib.js";import{toRgba as ne}from"../../util/color-utils.js";export function showInAppMessage(t,s,o){if(!e.rr())return;if(ss(),null==t)return!1;if(t instanceof ControlMessage)return r.D.info("User received control for a multivariate test, logging to Braze servers."),logInAppMessageImpression(t),!0;if(!(t instanceof InAppMessage))return!1;const i=pe.m();t.Pi();const n=t instanceof HtmlMessage;if(n&&!t.trusted&&!e.tr())return r.D.error('HTML in-app messages are disabled. Use the "allowUserSuppliedJavascript" option for braze.initialize to enable these messages.'),i.qe(t.triggerId,InAppMessage.Oe.gi),!1;if(null==s&&(s=document.body),t.we()){if(s.querySelectorAll(".ab-modal-interactions").length>0)return r.D.info(`Cannot show in-app message ${t.message} because another message is being shown.`),i.qe(t.triggerId,InAppMessage.Oe.Hi),!1}if(G.so()){const e=G.io();if(e===le.PORTRAIT&&t.orientation===InAppMessage.Orientation.LANDSCAPE||e===le.LANDSCAPE&&t.orientation===InAppMessage.Orientation.PORTRAIT){const s=e===le.PORTRAIT?"portrait":"landscape",o=t.orientation===InAppMessage.Orientation.PORTRAIT?"portrait":"landscape";return r.D.info(`Not showing ${o} in-app message ${t.message} because the screen is currently ${s}`),i.qe(t.triggerId,InAppMessage.Oe.Fi),!1}}if(!e.tr()){let e=!1;if(t.buttons&&t.buttons.length>0){const s=t.buttons;for(let t=0;t<s.length;t++)if(s[t].clickAction===InAppMessage.ClickAction.URI){const o=s[t].uri;e=j(o)}}else t.clickAction===InAppMessage.ClickAction.URI&&(e=j(t.uri));if(e)return r.D.error('Javascript click actions are disabled. Use the "allowUserSuppliedJavascript" option for braze.initialize to enable these actions.'),i.qe(t.triggerId,InAppMessage.Oe.gi),!1}const a=document.createElement("div");if(a.className="ab-iam-root v3",a.className+=se(t),a.setAttribute("role","complementary"),t.an()&&(a.id=t.htmlId),e.nn(D.no)&&(a.style.zIndex=e.nn(D.no)+1),s.appendChild(a),t.sn()){const s=document.createElement("style");s.innerHTML=t.css,s.id=t.rn(),null!=e.nn(D.ao)&&s.setAttribute("nonce",e.nn(D.ao)),document.getElementsByTagName("head")[0].appendChild(s)}const l=t instanceof SlideUpMessage,m=ce(t,(()=>{import("../../Feed/ui/show-feed.js").then((e=>e.showFeed()))}),(s=>{if(t.we()&&t.ll()){const o=document.createElement("div");if(o.className="ab-page-blocker",t.sn()||(o.style.backgroundColor=ne(t.frameColor)),e.nn(D.no)&&(o.style.zIndex=e.nn(D.no)),a.appendChild(o),!e.nn(D.bi)){const e=(new Date).valueOf();o.onclick=o=>{(new Date).valueOf()-e>InAppMessage.ki&&(t.on(s),o.stopPropagation())}}a.appendChild(s),s.focus(),t.Di(a)}else if(l){const e=document.querySelectorAll(".ab-slideup");let o=null;for(let t=e.length-1;t>=0;t--)if(e[t]!==s){o=e[t];break}if(t.slideFrom===InAppMessage.SlideFrom.TOP){let e=0;null!=o&&(e=o.offsetTop+o.offsetHeight),s.style.top=Math.max(e,0)+"px"}else{let e=0;null!=o&&(e=(window.innerHeight||document.documentElement.clientHeight)-o.offsetTop),s.style.bottom=Math.max(e,0)+"px"}}else if(n&&!e.nn(D.bi)){const e=t;s.contentWindow.addEventListener("keydown",(function(t){t.keyCode===at.Ri&&e.closeMessage()}))}logInAppMessageImpression(t),t.dismissType===InAppMessage.DismissType.AUTO_DISMISS&&setTimeout((()=>{a.contains(s)&&t.on(s)}),t.duration),"function"==typeof o&&o()}),e.nn(D.lo),e.nn(D.no),e.nn(D.ao));return(n||l)&&(a.appendChild(m),t.Di(a)),!0}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function isPushBlocked(){if(e.rr())return or.
|
|
1
|
+
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function isPushBlocked(){if(e.rr())return or.Xe().isPushBlocked()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function isPushPermissionGranted(){if(e.rr())return or.
|
|
1
|
+
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function isPushPermissionGranted(){if(e.rr())return or.Xe().isPushPermissionGranted()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function isPushSupported(){if(e.rr())return or.
|
|
1
|
+
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function isPushSupported(){if(e.rr())return or.Xe().isPushSupported()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{OPTIONS as D}from"../managers/braze-instance.js";import aa from"./push-manager.js";const or={t:!1,pushManager:null,
|
|
1
|
+
import e,{OPTIONS as D}from"../managers/braze-instance.js";import aa from"./push-manager.js";const or={t:!1,pushManager:null,Xe:()=>(or.o(),or.pushManager||(or.pushManager=new aa(e.gr(),e.aa(),e.ce(),e.Js(),e.nn(D.ea),e.nn(D.na),e.ir(),e.nn(D.ra),e.nn(D.ta),e.l())),or.pushManager),o:()=>{or.t||(e.u(or),or.t=!0)},destroy:()=>{or.pushManager=null,or.t=!1}};export default or;
|
package/src/Push/push-manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isArray as p,isEqual as ii}from"../util/code-utils.js";import ei from"../models/push-token.js";import r from"../../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import{User}from"../User/index.js";import{WindowUtils as
|
|
1
|
+
import{isArray as p,isEqual as ii}from"../util/code-utils.js";import ei from"../models/push-token.js";import r from"../../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import{User}from"../User/index.js";import{WindowUtils as G}from"../util/window-utils.js";export default class aa{constructor(i,e,t,s,n,r,o,u,h,a){this.yi=i,this.ji=e,this.xi=t,this.zi=s+"/safari/"+e,this.Vi=n||"/service-worker.js",this.qi=r,this.wt=o,this.Yi=u||!1,this.Ji=h||!1,this.h=a,this.Ki="serviceWorker"in navigator&&"undefined"!=typeof ServiceWorkerRegistration&&"showNotification"in ServiceWorkerRegistration.prototype&&"PushManager"in window,this.Qi="safari"in window&&"pushNotification"in window.safari&&"function"==typeof window.safari.pushNotification.permission&&"function"==typeof window.safari.pushNotification.requestPermission}Xi(){return this.Ji}isPushSupported(){return this.Ki||this.Qi}isPushBlocked(){const i=this.isPushSupported()&&"Notification"in window&&null!=window.Notification&&null!=window.Notification.permission&&"denied"===window.Notification.permission,e=this.isPushSupported()&&(!("Notification"in window)||null==window.Notification);return i||e}isPushPermissionGranted(){return this.isPushSupported()&&"Notification"in window&&null!=window.Notification&&null!=window.Notification.permission&&"granted"===window.Notification.permission}Ye(){return!this.isPushBlocked()&&this.isPushSupported()&&!this.isPushPermissionGranted()}Zi(i,e,t,s,n){i.unsubscribe().then((i=>{i?this.$i(e,t,s,n):(r.D.error("Failed to unsubscribe device from push."),"function"==typeof n&&n(!1))})).catch((i=>{r.D.error("Push unsubscription error: "+i),"function"==typeof n&&n(!1)}))}hn(i,e,t){const s=(i=>{if("string"==typeof i)return i;if(0!==i.endpoint.indexOf("https://android.googleapis.com/gcm/send"))return i.endpoint;let e=i.endpoint;return i.dn&&-1===i.endpoint.indexOf(i.dn)&&(e=i.endpoint+"/"+i.dn),e})(i);let n=null,r=null;if(null!=i.getKey)try{n=btoa(String.fromCharCode.apply(null,new Uint8Array(i.getKey("p256dh")))),r=btoa(String.fromCharCode.apply(null,new Uint8Array(i.getKey("auth"))))}catch(i){if("invalid arguments"!==i.message)throw i}const o=(i=>{let e;return i.options&&(e=i.options.applicationServerKey)&&e.byteLength&&e.byteLength>0?btoa(String.fromCharCode.apply(null,new Uint8Array(e))).replace(/\+/g,"-").replace(/\//g,"_"):null})(i);this.yi.fn(s,t,n,r,o),s&&"function"==typeof e&&e(s,n,r)}pn(){this.yi.wn(!0)}bn(i,e){this.yi.wn(!1),r.D.info(i),"function"==typeof e&&e(!1)}gn(i,e,t,s){if("default"===e.permission)try{window.safari.pushNotification.requestPermission(this.zi,i,{api_key:this.ji,device_id:this.xi.te().id},(e=>{"granted"===e.permission&&this.yi.setPushNotificationSubscriptionType(User.NotificationSubscriptionTypes.OPTED_IN),this.gn(i,e,t,s)}))}catch(i){this.bn("Could not request permission for push: "+i,s)}else"denied"===e.permission?this.bn("The user has blocked notifications from this site, or Safari push is not configured in the Braze dashboard.",s):"granted"===e.permission&&(r.D.info("Device successfully subscribed to push."),this.hn(e.deviceToken,t,new Date))}yn(i,e,t){const s=s=>{switch(s){case"granted":return void("function"==typeof i&&i());case"default":return void("function"==typeof e&&e());case"denied":return void("function"==typeof t&&t());default:r.D.error("Received unexpected permission result "+s)}};let n=!1;const o=window.Notification.requestPermission((i=>{n&&s(i)}));o?o.then((i=>{s(i)})):n=!0}$i(i,e,t,s){const n={userVisibleOnly:!0};null!=e&&(n.applicationServerKey=e),i.pushManager.subscribe(n).then((i=>{r.D.info("Device successfully subscribed to push."),this.hn(i,t,new Date)})).catch((i=>{this.isPushBlocked()?(r.D.info("Permission for push notifications was denied."),"function"==typeof s&&s(!1)):r.D.error("Push subscription failed: "+i)}))}vn(){return this.Yi?navigator.serviceWorker.getRegistration():navigator.serviceWorker.register(this.Vi).then((()=>navigator.serviceWorker.ready.then((i=>(i&&"function"==typeof i.update&&i.update().catch((i=>{r.D.info("ServiceWorker update failed: "+i)})),i)))))}Pn(i){this.Yi||(i.unregister(),r.D.info("Service worker successfully unregistered."))}subscribe(i,e){if(this.isPushSupported()){if(this.Ki){if(!this.Yi&&null!=window.location){let i=this.Vi;-1===i.indexOf(window.location.host)&&(i=window.location.host+i),-1===i.indexOf(window.location.protocol)&&(i=window.location.protocol+"//"+i);const e=i.substr(0,i.lastIndexOf("/")+1);if(0!==G.kn().indexOf(e))return void r.D.error("Cannot subscribe to push from a path higher than the service worker location (tried to subscribe from "+window.location.pathname+" but service worker is at "+i+")")}if(this.isPushBlocked())return void this.bn("Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",e);if(this.wt&&!this.wt.Sn()&&0===this.wt.Gs())return r.D.info("Waiting for VAPID key from server config before subscribing to push."),void this.wt.Dn((()=>{this.subscribe(i,e)}));const t=()=>{r.D.info("Permission for push notifications was denied."),"function"==typeof e&&e(!1)},s=()=>{let i="Permission for push notifications was ignored.";this.isPushBlocked()&&(i+=" The browser has automatically blocked further permission requests for a period (probably 1 week)."),r.D.info(i),"function"==typeof e&&e(!0)},n=this.isPushPermissionGranted(),u=()=>{n||this.yi.setPushNotificationSubscriptionType(User.NotificationSubscriptionTypes.OPTED_IN),this.vn().then((t=>{if(null==t)return r.D.error("No service worker registration. Set the `manageServiceWorkerExternally` initialization option to false or ensure that your service worker is registered before calling registerPush."),void("function"==typeof e&&e());t.pushManager.getSubscription().then((s=>{let n=null;if(this.wt&&null!=this.wt.Sn()&&(n=r.Nn._n(this.wt.Sn())),s){let u=null,h=null;const a=this.h.I(o.q.Wn);if(a&&!p(a)){let i;try{i=ei.jn(a).An}catch(e){i=null}null==i||isNaN(i.getTime())||0===i.getTime()||(u=i,h=new Date(u),h.setMonth(u.getMonth()+6))}null!=n&&s.options&&s.options.applicationServerKey&&s.options.applicationServerKey.byteLength&&s.options.applicationServerKey.byteLength>0&&!ii(n,new Uint8Array(s.options.applicationServerKey))?(s.options.applicationServerKey.byteLength>12?r.D.info("Device was already subscribed to push using a different VAPID provider, creating new subscription."):r.D.info("Attempting to upgrade a gcm_sender_id-based push registration to VAPID - depending on the browser this may or may not result in the same gcm_sender_id-based subscription."),this.Zi(s,t,n,i,e)):s.expirationTime&&new Date(s.expirationTime)<=(new Date).valueOf()?(r.D.info("Push subscription is expired, creating new subscription."),this.Zi(s,t,n,i,e)):a&&p(a)?this.Zi(s,t,n,i,e):null==h?(r.D.info("No push subscription creation date found, creating new subscription."),this.Zi(s,t,n,i,e)):h<=(new Date).valueOf()?(r.D.info("Push subscription older than 6 months, creating new subscription."),this.Zi(s,t,n,i,e)):(r.D.info("Device already subscribed to push, sending existing subscription to backend."),this.hn(s,i,u))}else this.$i(t,n,i,e)})).catch((i=>{r.D.error("Error checking current push subscriptions: "+i)}))})).catch((i=>{r.D.error("ServiceWorker registration failed: "+i)}))};this.yn(u,s,t)}else if(this.Qi){if(null==this.qi||""===this.qi)return void r.D.error("You must supply the safariWebsitePushId initialization option in order to use registerPush on Safari");const t=window.safari.pushNotification.permission(this.qi);this.gn(this.qi,t,i,e)}}else r.D.info(this.Un)}unsubscribe(i,e){this.isPushSupported()?this.Ki?navigator.serviceWorker.getRegistration().then((t=>{t&&t.pushManager.getSubscription().then((s=>{s&&(this.pn(),s.unsubscribe().then((s=>{s?(r.D.info("Device successfully unsubscribed from push."),"function"==typeof i&&i()):(r.D.error("Failed to unsubscribe device from push."),"function"==typeof e&&e()),this.Pn(t)})).catch((i=>{r.D.error("Push unsubscription error: "+i),"function"==typeof e&&e()})))})).catch((i=>{r.D.error("Error unsubscribing from push: "+i),"function"==typeof e&&e()}))})):this.Qi&&(this.pn(),r.D.info("Device unsubscribed from push."),"function"==typeof i&&i()):r.D.info(this.Un)}}aa.Un="Push notifications are not supported in this browser.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function requestPushPermission(r,n){if(e.rr())return or.
|
|
1
|
+
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function requestPushPermission(r,n){if(e.rr())return or.Xe().subscribe(((n,o,t)=>{e.mr().requestImmediateDataFlush(),"function"==typeof r&&r(n,o,t)}),n)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function unregisterPush(r,n){if(e.rr())return or.
|
|
1
|
+
import e from"../managers/braze-instance.js";import or from"./push-manager-factory.js";export function unregisterPush(r,n){if(e.rr())return or.Xe().unsubscribe(r,n)}
|
package/src/User/user-manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _t from"../models/identifier.js";import{getByteLength as U}from"../util/string-utils.js";import ei from"../models/push-token.js";import r from"../../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import{User}from"../User/index.js";export default class bt{constructor(t,s){this.wt=t,this.h=s}getUserId(){const t=this.h._r(o.Cr.Ur);if(null==t)return null;let s=t.Ir,i=U(s);if(i>User.ee){for(;i>User.ee;)s=s.slice(0,s.length-1),i=U(s);t.Ir=s,this.h.Lr(o.Cr.Ur,t)}return s}Br(t){const s=null==this.getUserId();this.h.Lr(o.Cr.Ur,new _t(t)),s&&this.h.Er(t)}setCustomUserAttribute(t,s){if(this.wt.Gr(t))return r.D.info('Custom Attribute "'+t+'" is blocklisted, ignoring.'),!1;const i={};return i[t]=s,this.Hr(User.Jr,i,!0)}Hr(t,s,i,e){const u=this.h.Kr(this.getUserId(),t,s);return!e&&u&&r.D.info(`Logged${i?" custom":""} attribute ${t} with value ${s}`),u}fn(t,s,i,e,u){this.Hr("push_token",t,!1,!0),this.Hr("custom_push_public_key",i,!1,!0),this.Hr("custom_push_user_auth",e,!1,!0),this.Hr("custom_push_vapid_public_key",u,!1,!0);const h=r.Ft.xt,n=new r.qt(h,r.D),l=new ei(t,s,i,e,u);this.h.B(o.q.Wn,l.ss()),n.setItem(h.Pt.Mr,h.se,!0)}wn(t){if(this.Hr("push_token",null,!1,!0),this.Hr("custom_push_public_key",null,!1,!0),this.Hr("custom_push_user_auth",null,!1,!0),this.Hr("custom_push_vapid_public_key",null,!1,!0),t){const t=r.Ft.xt,s=new r.qt(t,r.D);this.h.B(o.q.Wn,!1),s.setItem(t.Pt.Mr,t.se,!1)}}}
|
package/src/User/user.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isArray as p,isDate as
|
|
1
|
+
import{isArray as p,isDate as yt,validateValueIsFromEnum as K}from"../util/code-utils.js";import r from"../../shared-lib/braze-shared-lib.js";import{toValidBackendTimeString as Nt}from"../util/date-utils.js";import{isValidEmail as vt,validateCustomString as X,validateStandardString as R}from"../util/validation-utils.js";export default class User{constructor(t,e){this.v=t,this.Is=e}getUserId(t){null==t&&r.D.error("getUserId must be supplied with a callback. e.g., braze.getUser().getUserId(function(userId) {console.log('the user id is ' + userId)})"),"function"==typeof t&&t(this.v.getUserId())}addAlias(t,e){return!R(t,"add alias","the alias",!1)||t.length<=0?(r.D.error("addAlias requires a non-empty alias"),!1):!R(e,"add alias","the label",!1)||e.length<=0?(r.D.error("addAlias requires a non-empty label"),!1):this.Is.Nr(t,e).S}setFirstName(t){return!!R(t,"set first name","the firstName",!0)&&this.v.Hr("first_name",t)}setLastName(t){return!!R(t,"set last name","the lastName",!0)&&this.v.Hr("last_name",t)}setEmail(t){return null===t||vt(t)?this.v.Hr("email",t):(r.D.error(`Cannot set email address - "${t}" did not pass RFC-5322 validation.`),!1)}setGender(t){return"string"==typeof t&&(t=t.toLowerCase()),!(null!==t&&!K(User.Genders,t,`Gender "${t}" is not a valid gender.`,"User.Genders"))&&this.v.Hr("gender",t)}setDateOfBirth(t,e,s){return null===t&&null===e&&null===s?this.v.Hr("dob",null):(t=parseInt(t),e=parseInt(e),s=parseInt(s),isNaN(t)||isNaN(e)||isNaN(s)||e>12||e<1||s>31||s<1?(r.D.error("Cannot set date of birth - parameters should comprise a valid date e.g. setDateOfBirth(1776, 7, 4);"),!1):this.v.Hr("dob",`${t}-${e}-${s}`))}setCountry(t){return!!R(t,"set country","the country",!0)&&this.v.Hr("country",t)}setHomeCity(t){return!!R(t,"set home city","the homeCity",!0)&&this.v.Hr("home_city",t)}setLanguage(t){return!!R(t,"set language","the language",!0)&&this.v.Hr("language",t)}setEmailNotificationSubscriptionType(t){return!!K(User.NotificationSubscriptionTypes,t,`Email notification setting "${t}" is not a valid subscription type.`,"User.NotificationSubscriptionTypes")&&this.v.Hr("email_subscribe",t)}setPushNotificationSubscriptionType(t){return!!K(User.NotificationSubscriptionTypes,t,`Push notification setting "${t}" is not a valid subscription type.`,"User.NotificationSubscriptionTypes")&&this.v.Hr("push_subscribe",t)}setPhoneNumber(t){return!!R(t,"set phone number","the phoneNumber",!0)&&(null===t||t.match(User.Sr)?this.v.Hr("phone",t):(r.D.error(`Cannot set phone number - "${t}" did not pass validation.`),!1))}setLastKnownLocation(t,e,s,i,n){return null==t||null==e?(r.D.error("Cannot set last-known location - latitude and longitude are required."),!1):(t=parseFloat(t),e=parseFloat(e),null!=s&&(s=parseFloat(s)),null!=i&&(i=parseFloat(i)),null!=n&&(n=parseFloat(n)),isNaN(t)||isNaN(e)||null!=s&&isNaN(s)||null!=i&&isNaN(i)||null!=n&&isNaN(n)?(r.D.error("Cannot set last-known location - all supplied parameters must be numeric."),!1):t>90||t<-90||e>180||e<-180?(r.D.error("Cannot set last-known location - latitude and longitude are bounded by ±90 and ±180 respectively."),!1):null!=s&&s<0||null!=n&&n<0?(r.D.error("Cannot set last-known location - accuracy and altitudeAccuracy may not be negative."),!1):this.Is.setLastKnownLocation(this.v.getUserId(),t,e,i,s,n).S)}setCustomUserAttribute(t,e){if(!X(t,"set custom user attribute","the given key"))return!1;const s=typeof e,i=yt(e),n=p(e);if("number"!==s&&"boolean"!==s&&!i&&!n&&null!==e&&!X(e,`set custom user attribute "${t}"`,"the given value"))return!1;if(i&&(e=Nt(e)),n){for(let s=0;s<e.length;s++){const r=e[s];if(!X(r,`set custom user attribute "${t}"`,"the element in the given array"))return!1}return this.Is.Or(r.A.Vr,t,e).S}return this.v.setCustomUserAttribute(t,e)}addToCustomAttributeArray(t,e){return!!X(t,"add to custom user attribute array","the given key")&&(!(null!=e&&!X(e,"add to custom user attribute array","the given value"))&&this.Is.Or(r.A.Wr,t,e).S)}removeFromCustomAttributeArray(t,e){return!!X(t,"remove from custom user attribute array","the given key")&&(!(null!=e&&!X(e,"remove from custom user attribute array","the given value"))&&this.Is.Or(r.A.Yr,t,e).S)}incrementCustomUserAttribute(t,e){if(!X(t,"increment custom user attribute","the given key"))return!1;null==e&&(e=1);const s=parseInt(e);return isNaN(s)||s!==parseFloat(e)?(r.D.error(`Cannot increment custom user attribute because the given incrementValue "${e}" is not an integer.`),!1):this.Is.Or(r.A.Qr,t,s).S}setCustomLocationAttribute(t,e,s){return!!X(t,"set custom location attribute","the given key")&&((null!==e||null!==s)&&(e=parseFloat(e),s=parseFloat(s),isNaN(e)||e>90||e<-90||isNaN(s)||s>180||s<-180)?(r.D.error("Received invalid values for latitude and/or longitude. Latitude and longitude are bounded by ±90 and ±180 respectively, or must both be null for removal."),!1):this.Is.Xr(t,e,s).S)}addToSubscriptionGroup(t){return!R(t,"add user to subscription group","subscription group ID",!1)||t.length<=0?(r.D.error("addToSubscriptionGroup requires a non-empty subscription group ID"),!1):this.Is.Zr(t,User.Cn.SUBSCRIBED).S}removeFromSubscriptionGroup(t){return!R(t,"remove user from subscription group","subscription group ID",!1)||t.length<=0?(r.D.error("removeFromSubscriptionGroup requires a non-empty subscription group ID"),!1):this.Is.Zr(t,User.Cn.UNSUBSCRIBED).S}fn(t,e,s,r,i){this.v.fn(t,e,s,r,i),this.Is.In()}wn(t){this.v.wn(t)}}User.Sr=/^[0-9 .\\(\\)\\+\\-]+$/,User.Genders={MALE:"m",FEMALE:"f",OTHER:"o",UNKNOWN:"u",NOT_APPLICABLE:"n",PREFER_NOT_TO_SAY:"p"},User.NotificationSubscriptionTypes={OPTED_IN:"opted_in",SUBSCRIBED:"subscribed",UNSUBSCRIBED:"unsubscribed"},User.Cn={SUBSCRIBED:"subscribed",UNSUBSCRIBED:"unsubscribed"},User.En="user_id",User.Jr="custom",User.ee=997;
|
package/src/common/base-feed.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlCard}from"../Card/index.js";export const FEED_ANIMATION_DURATION=500;export default class x{constructor(e,r){this.cards=e,this.lastUpdated=r}getUnreadCardCount(){let e=0;for(const r of this.cards)r.viewed||r instanceof ControlCard||e++;return e}dr(){throw new Error("Must be implemented in a subclass")}logCardImpressions(){throw new Error("Must be implemented in subclass")}logCardClick(){throw new Error("Must be implemented in subclass")}sr(){throw new Error("Must be implemented in subclass")}}x.ur=6e4,x.
|
|
1
|
+
import{ControlCard}from"../Card/index.js";export const FEED_ANIMATION_DURATION=500;export default class x{constructor(e,r){this.cards=e,this.lastUpdated=r}getUnreadCardCount(){let e=0;for(const r of this.cards)r.viewed||r instanceof ControlCard||e++;return e}dr(){throw new Error("Must be implemented in a subclass")}logCardImpressions(){throw new Error("Must be implemented in subclass")}logCardClick(){throw new Error("Must be implemented in subclass")}sr(){throw new Error("Must be implemented in subclass")}}x.ur=6e4,x.Si=500,x.uo=1e4;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";import e from"../managers/braze-instance.js";import ue from"../models/braze-event.js";import t from"../models/request-result.js";const s={G:(o,n,s)=>{const a=new t,i=e.g();if(!i)return r.D.info(`Not logging event with type "${o}" because the current session ID could not be found.`),a;const m=i.
|
|
1
|
+
import r from"../../shared-lib/braze-shared-lib.js";import e from"../managers/braze-instance.js";import ue from"../models/braze-event.js";import t from"../models/request-result.js";const s={G:(o,n,s)=>{const a=new t,i=e.g();if(!i)return r.D.info(`Not logging event with type "${o}" because the current session ID could not be found.`),a;const m=i.mo();return a.ve.push(new ue(s||e.p().getUserId(),o,(new Date).valueOf(),m,n)),a.S=e.l().bo(a.ve),a}};export default s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import x from"./base-feed.js";import{bottomHadImpression as de,getCardId as fe,impressOnBottom as
|
|
1
|
+
import x from"./base-feed.js";import{bottomHadImpression as de,getCardId as fe,impressOnBottom as be,impressOnTop as ye,markCardAsRead as Fe,topHadImpression as Te}from"../Card/display/card-display.js";import{bottomIsInView as he,topIsInView as _e}from"../util/dom-utils.js";import{Card,ControlCard}from"../Card/index.js";import{cardToHtml as xe}from"../Card/display/card-display.js";import{isArray as p}from"../util/code-utils.js";import{KeyCodes as at}from"../util/key-codes.js";import Ee from"../l10n/l10n-manager-factory.js";import{removeSubscription}from"../Core/remove-subscription.js";import r from"../../shared-lib/braze-shared-lib.js";import{BRAZE_ACTION_URI_REGEX as P}from"../util/validation-utils.js";import{INELIGIBLE_BRAZE_ACTION_URL_ERROR_TYPES as gt,ineligibleBrazeActionURLErrorMessage as ct,getDecodedBrazeAction as O,containsUnknownBrazeAction as mt}from"../util/braze-actions.js";export const LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE="data-last-requested-refresh";export const _SUBSCRIPTION_ID_DATA_ATTRIBUTE="data-update-subscription-id";export function destroyFeedHtml(e){e&&(e.className=e.className.replace("ab-show","ab-hide"),setTimeout((()=>{e&&e.parentNode&&e.parentNode.removeChild(e)}),x.Si));const t=e.getAttribute("data-update-subscription-id");null!=t&&removeSubscription(t)}export function _generateFeedBody(e,t){const o=document.createElement("div");if(o.className="ab-feed-body",o.setAttribute("aria-label","Feed"),o.setAttribute("role","feed"),null==e.lastUpdated){const e=document.createElement("div");e.className="ab-no-cards-message";const t=document.createElement("i");t.className="fa fa-spinner fa-spin fa-4x ab-initial-spinner",e.appendChild(t),o.appendChild(e)}else{let s=!1;const logCardClick=t=>{e.logCardClick(t)};for(const n of e.cards){const a=n instanceof ControlCard;!a||e.dr()?(o.appendChild(xe(n,logCardClick,t)),s=s||!a):r.D.error("Received a control card for a legacy news feed. Control cards are only supported with content cards.")}if(!s){const e=document.createElement("div");e.className="ab-no-cards-message",e.innerHTML=Ee.m().get("NO_CARDS_MESSAGE"),e.setAttribute("role","article"),o.appendChild(e)}}return o}export function detectFeedImpressions(e,t){if(null!=t){const o=[],r=t.querySelectorAll(".ab-card");e.do||(e.do={});for(let t=0;t<r.length;t++){const s=fe(r[t]);if(e.do[s])continue;let n=Te(r[t]),a=de(r[t]);const i=n,d=a,f=_e(r[t]),c=he(r[t]);if(!n&&f&&(n=!0,ye(r[t])),!a&&c&&(a=!0,be(r[t])),n&&a){if(f||c||Fe(r[t]),i&&d)continue;for(const t of e.cards)if(t.id===s){e.do[t.id]=!0,o.push(t);break}}}o.length>0&&e.logCardImpressions(o)}}export function refreshFeed(e,t){t.setAttribute("aria-busy","true");const o=t.querySelectorAll(".ab-refresh-button")[0];null!=o&&(o.className+=" fa-spin");const r=(new Date).valueOf().toString();t.setAttribute("data-last-requested-refresh",r),setTimeout((()=>{if(t.getAttribute("data-last-requested-refresh")===r){const e=t.querySelectorAll(".fa-spin");for(let t=0;t<e.length;t++)e[t].className=e[t].className.replace(/fa-spin/g,"");const o=t.querySelectorAll(".ab-initial-spinner")[0];if(null!=o){const e=document.createElement("span");e.innerHTML=Ee.m().get("FEED_TIMEOUT_MESSAGE"),o.parentNode.appendChild(e),o.parentNode.removeChild(o)}"true"===t.getAttribute("aria-busy")&&t.setAttribute("aria-busy","false")}}),x.uo),e.sr()}export function feedToHtml(e,t){const o=document.createElement("div");o.className="ab-feed ab-hide ab-effect-slide",o.setAttribute("role","dialog"),o.setAttribute("aria-label","Feed"),o.setAttribute("tabindex","-1");const r=document.createElement("div");r.className="ab-feed-buttons-wrapper",r.setAttribute("role","group"),o.appendChild(r);const s=document.createElement("i");s.className="fa fa-times ab-close-button",s.setAttribute("aria-label","Close Feed"),s.setAttribute("tabindex","0"),s.setAttribute("role","button");const n=e=>{destroyFeedHtml(o),e.stopPropagation()};s.addEventListener("keydown",(e=>{e.keyCode!==at.fo&&e.keyCode!==at.co||n(e)})),s.onclick=n;const a=document.createElement("i");a.className="fa fa-refresh ab-refresh-button",null==e.lastUpdated&&(a.className+=" fa-spin"),a.setAttribute("aria-label","Refresh Feed"),a.setAttribute("tabindex","0"),a.setAttribute("role","button");const i=t=>{refreshFeed(e,o),t.stopPropagation()};return a.addEventListener("keydown",(e=>{e.keyCode!==at.fo&&e.keyCode!==at.co||i(e)})),a.onclick=i,r.appendChild(a),r.appendChild(s),o.appendChild(_generateFeedBody(e,t)),o.onscroll=()=>{detectFeedImpressions(e,o)},o}export function updateFeedCards(e,t,o,s,n){if(!p(t))return;const a=[];for(const e of t)if(e instanceof Card){if(e.url&&P.test(e.url)){let t=O(e.url);if(mt(t)){r.D.error(ct(gt.We,"Content Card"));continue}}a.push(e)}if(e.cards=a,e.lastUpdated=o,null!=s)if(s.setAttribute("aria-busy","false"),null==e.lastUpdated)destroyFeedHtml(s);else{const t=s.querySelectorAll(".ab-feed-body")[0];if(null!=t){const o=_generateFeedBody(e,n);t.parentNode.replaceChild(o,t),detectFeedImpressions(e,o.parentNode)}}}export function registerFeedSubscriptionId(e,t){t.setAttribute("data-update-subscription-id",e)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{OPTIONS as D}from"../managers/braze-instance.js";import et from"../util/browser-detector.js";import er from"./l10n-manager.js";const
|
|
1
|
+
import e,{OPTIONS as D}from"../managers/braze-instance.js";import et from"../util/browser-detector.js";import er from"./l10n-manager.js";const Ee={t:!1,i:null,m:()=>{if(Ee.o(),!Ee.i){let r=et.language,t=!1;e.nn(D.zn)&&(r=e.nn(D.zn),t=!0),Ee.i=new er(r,t)}return Ee.i},o:()=>{Ee.t||(e.u(Ee),Ee.t=!0)},destroy:()=>{Ee.i=null,Ee.t=!1}};export default Ee;
|
package/src/l10n/l10n-manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import r from"../../shared-lib/braze-shared-lib.js";import zt from"../common/translations.js";export default class er{constructor(t,l){if(null!=t&&(t=t.toLowerCase()),null!=t&&null==zt[t]){const l=t.indexOf("-");l>0&&(t=t.substring(0,l))}if(null==zt[t]){const a="Braze does not yet have a localization for language "+t+", defaulting to English. Please contact us if you are willing and able to help us translate our SDK into this language.";l?r.D.error(a):r.D.info(a),t="en"}this.language=t}get(t){return zt[this.language][t]}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{STORAGE_KEYS as o}from"./storage-manager.js";import u from"./subscription-manager.js";import r from"../../shared-lib/braze-shared-lib.js";export default class St{constructor(t,i,s){this.h=t,this.Fn=i||!1,this.
|
|
1
|
+
import{STORAGE_KEYS as o}from"./storage-manager.js";import u from"./subscription-manager.js";import r from"../../shared-lib/braze-shared-lib.js";export default class St{constructor(t,i,s){this.h=t,this.Fn=i||!1,this.xn=s,this.Tn=new u,this.qn=0,this.Bn=1}Gn(){return this.Fn}Hn(){return this.h.I(o.q.Jn)}setSdkAuthenticationSignature(t){const i=this.Hn();this.h.B(o.q.Jn,t);const s=r.Ft.xt;new r.qt(s,r.D).setItem(s.Pt.Kn,this.Bn,t),i!==t&&this.Es()}Ln(){this.h.$s(o.q.Jn);const t=r.Ft.xt;new r.qt(t,r.D).br(t.Pt.Kn,this.Bn)}subscribeToSdkAuthenticationFailures(t){return this.xn.Et(t)}Mn(t){this.xn.Nt(t)}On(){this.Tn.removeAllSubscriptions()}Qn(){this.qn+=1}Rn(){return this.qn}Es(){this.qn=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 It from"./device-manager.js";import DeviceProperties from"../Core/device-properties.js";import{isArray as p,keys as
|
|
1
|
+
import St from"./auth-manager.js";import C from"../common/base-provider.js";import et from"../util/browser-detector.js";import It from"./device-manager.js";import DeviceProperties from"../Core/device-properties.js";import{isArray as p,keys as Y,validateValueIsFromEnum as K,values as At}from"../util/code-utils.js";import{logDeprecationWarning as y}from"../util/deprecation-utils.js";import wt from"./network-manager.js";import Tt from"../request-controller.js";import Ot from"./server-config-manager.js";import Ct from"./session-manager.js";import r from"../../shared-lib/braze-shared-lib.js";import A,{STORAGE_KEYS as o}from"./storage-manager.js";import Lt from"./storage-manager-factory.js";import u from"./subscription-manager.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";import bt from"../User/user-manager.js";import{User}from"../User/index.js";import{parseQueryStringKeyValues as st}from"../util/url-utils.js";import{WindowUtils as G}from"../util/window-utils.js";const D={Vn:"allowCrawlerActivity",$n:"baseUrl",Yn:"noCookies",Xn:"devicePropertyAllowlist",ra:"disablePushTokenMaintenance",Zn:"enableLogging",ho:"enableSdkAuthentication",ta:"manageServiceWorkerExternally",po:"minimumIntervalBetweenTriggerActionsInSeconds",Eo:"sessionTimeoutInSeconds",_o:"appVersion",ea:"serviceWorkerLocation",na:"safariWebsitePushId",zn:"localization",ao:"contentSecurityNonce",Io:"enableHtmlInAppMessages",Ao:"allowUserSuppliedJavascript",no:"inAppMessageZIndex",lo:"openInAppMessagesInNewTab",tn:"openCardsInNewTab",en:"openNewsFeedCardsInNewTab",bi:"requireExplicitInAppMessageDismissal",So:"doNotLoadFontAwesome",No:"sdkFlavor"};class Pt{constructor(){this.wo=!1,this.To=!1,this.Oo=new u,this.vo=new u,this.Co={},this.Lo=[],this.Po=[],this.De=[],this.Ro="4.0.6"}Mo(t){this.Oo.Et(t)}Ui(t){this.vo.Et(t)}initialize(t,i){if(this.yo())return r.D.info("Braze has already been initialized with an API key."),!0;this.Co=i||{};let s=this.nn(D.Zn);const e=st(G.kn());if(e&&"true"===e.brazeLogging&&(s=!0),r.D.init(s),r.D.info(`Initialization Options: ${JSON.stringify(this.Co,null,2)}`),null==t||""===t||"string"!=typeof t)return r.D.error("Braze requires a valid API key to be initialized."),!1;this.ji=t;let n=this.nn(D.$n);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.Do=n,et.jo&&!this.nn(D.Vn))return r.D.info("Ignoring activity from crawler bot "+navigator.userAgent),this.To=!0,!1;const a=this.nn(Pt.Yn)||!1;if(this.h=Lt.zo(t,a),new A.ne(null,!0).lr(o.ae))return r.D.info("Ignoring all activity due to previous opt out"),this.To=!0,!1;for(const t of Y(this.Co))-1===At(r.Uo).indexOf(t)&&r.D.warn(`Ignoring unknown initialization option '${t}'.`);const h=["mparticle","wordpress","tealium"];if(null!=this.nn(D.No)){const t=this.nn(D.No);-1!==h.indexOf(t)?this.Bo=t:r.D.error("Invalid sdk flavor passed: "+t)}let l=this.nn(r.Uo.Xn);if(null!=l)if(p(l)){const t=[];for(let i=0;i<l.length;i++)K(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 It(this.h,l),this.wt=new Ot(this.h),this.v=new bt(this.wt,this.h),this.j=new Ct(this.h,this.v,this.wt,this.nn(D.Eo));const c=new u;return this.Wo=new St(this.h,this.nn(D.ho),c),this.Ut(c),this.jt=new wt(this.xi,this.h,this.Wo,this.v,this.j,this.wt,this.ji,this.Do,this.Ro,this.Bo,this.nn(D._o)),this.Is=new Tt(this.ji,this.Do,this.j,this.xi,this.v,this.wt,this.h,(t=>{if(this.yo())for(const i of this.re())i._s(t)}),this.Wo,this.jt),this.Is.initialize(),r.D.info(`Initialized for the Braze backend at "${this.nn(D.$n)}" with API key "${this.ji}".`),null!=this.nn(D.Io)&&y("enableHtmlInAppMessages","initialization option","allowUserSuppliedJavascript"),V.init(),this.Oo.Nt(this.Co),this.wo=!0,!0}destroy(t){if(r.D.destroy(),this.yo()){this.vo.Nt(),this.vo.removeAllSubscriptions();for(const t of this.Lo)t.destroy();this.Lo=[];for(const t of this.Po)t.clearData(!1);this.Po=[],this.removeAllSubscriptions(),this.De=[],this.Is.destroy(),this.Is=null,this.Wo=null,this.xi=null,this.jt=null,this.wt=null,this.j=null,this.v=null,this.Co={},this.Bo=void 0,this.wo=!1,this.To=!1,t&&(this.h=null)}}rr(){if(this.Vo())return!1;if(!this.yo())throw new Error("Braze must be initialized before calling methods.");return!0}aa(){return this.ji}ti(){return this.Wo}Js(){return this.Do}ce(){return this.xi}nr(){return this.jt}nn(t){return this.Co[t]}re(){return this.Po}mr(){return this.Is}ir(){return this.wt}g(){return this.j}l(){return this.h}gr(){if(this.v&&this.Is)return new User(this.v,this.Is)}p(){return this.v}tr(){return!0===this.nn(D.Ao)||!0===this.nn(D.Io)}u(t){let i=!1;for(const s of this.Lo)s===t&&(i=!0);i||this.Lo.push(t)}ar(t){let i=!1;for(const s of this.Po)s.constructor===t.constructor&&(i=!0);t instanceof C&&!i&&this.Po.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.To=t}yo(){return this.wo}Vo(){return this.To}}const e=new Pt;export{e as default,Pt as BrazeSdkInstance,D as OPTIONS};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import et from"../util/browser-detector.js";import Ie from"../models/device.js";import DeviceProperties from"../Core/device-properties.js";import
|
|
1
|
+
import et from"../util/browser-detector.js";import Ie from"../models/device.js";import DeviceProperties from"../Core/device-properties.js";import _t from"../models/identifier.js";import r from"../../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import{values as At}from"../util/code-utils.js";export default class It{constructor(e,t){this.h=e,null==t&&(t=At(DeviceProperties)),this.xo=t}te(){let e=this.h._r(o.Cr.Go);null==e&&(e=new _t(r.nt.et()),this.h.Lr(o.Cr.Go,e));const t=new Ie(e.Ir);for(let e=0;e<this.xo.length;e++){const r=this.xo[e];switch(r){case DeviceProperties.BROWSER:t[r]=et.browser;break;case DeviceProperties.BROWSER_VERSION:t[r]=et.version;break;case DeviceProperties.OS:t[r]=this.Fo();break;case DeviceProperties.RESOLUTION:t[r]=screen.width+"x"+screen.height;break;case DeviceProperties.LANGUAGE:t[r]=et.language;break;case DeviceProperties.TIME_ZONE:t[r]=this.Jo(new Date);break;case DeviceProperties.USER_AGENT:t[r]=et.userAgent}}return t}Fo(){if(et.qo())return et.qo();const e=this.h.I(o.q.Ho);return e&&e.os_version?e.os_version:et.Ko()}Jo(e){if("undefined"!=typeof Intl&&"function"==typeof Intl.DateTimeFormat)try{if("function"==typeof Intl.DateTimeFormat().resolvedOptions){const e=Intl.DateTimeFormat().resolvedOptions().timeZone;if(null!=e&&""!==e)return e}}catch(e){r.D.info("Intl.DateTimeFormat threw an error, probably https://bugs.chromium.org/p/chromium/issues/detail?id=811403, falling back to GTM offset: "+e.message)}const t=e.getTimezoneOffset();return this.Qo(t)}Qo(e){const t=parseInt(e/60),r=parseInt(e%60);let s="GMT";return 0!==e&&(s+=e<0?"+":"-",s+=("00"+Math.abs(t)).slice(-2)+":"+("00"+Math.abs(r)).slice(-2)),s}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Rt from"../models/backend-errors.js";import{convertMsToSeconds as l,convertSecondsToMs as qt}from"../util/date-utils.js";import
|
|
1
|
+
import Rt from"../models/backend-errors.js";import ue from"../models/braze-event.js";import{convertMsToSeconds as l,convertSecondsToMs as qt}from"../util/date-utils.js";import s from"../common/event-logger.js";import{isArray as p,isEqual as ii}from"../util/code-utils.js";import r from"../../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"./storage-manager.js";export default class wt{constructor(t,e,s,i,r,o,n,a,h,u,c){this.xi=t,this.h=e,this.Wo=s,this.v=i,this.j=r,this.wt=o,this.ji=n,this.Do=a,this.Ro=h,this.Bo=u,this.Xo=c,this.$o=["npm"]}Ls(t,e){const s=this.xi.te(),i=s.Zs(),r=this.h.I(o.q.Ho);ii(r,i)||(t.device=i),t.api_key=this.ji,t.time=l((new Date).valueOf(),!0);const n=this.h.I(o.q.Yo)||[],a=this.h.I(o.q.Zo)||"";if(this.$o.length>0&&(!ii(n,this.$o)||a!==this.j.sa())&&(t.sdk_metadata=this.$o),t.sdk_version=this.Ro,this.Bo&&(t.sdk_flavor=this.Bo),t.app_version=this.Xo,t.device_id=s.id,e){const e=this.v.getUserId();null!=e&&(t.user_id=e)}return t}qs(t,e,i){const o=e.auth_error,n=e.error;if(!o&&!n)return!0;if(o){let e;this.Wo.Qn();const s={errorCode:o.error_code};for(const t of i)p(t)&&"X-Braze-Auth-Signature"===t[0]&&(s.signature=t[1]);t.respond_with&&t.respond_with.user_id?s.userId=t.respond_with.user_id:t.user_id&&(s.userId=t.user_id);const n=o.reason;return n?(s.reason=n,e=`due to ${n}`):e=`with error code ${o.error_code}.`,this.Wo.Gn()||(e+=' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),r.D.error(`SDK Authentication failed ${e}`),this.ia(t.events,t.attributes),this.Wo.Mn(s),!1}if(n){let i=n;switch(i){case Rt.oa:const o="Received successful response with empty body.";return s.G(r.A.ha,{e:o}),r.D.info(o),!1;case Rt.ua:const n="Received successful response with invalid JSON";return s.G(r.A.ha,{e:n+": "+e.response}),r.D.info(n),!1;case Rt.ca:i=`The API key "${t.api_key}" is invalid for the baseUrl ${this.Do}`;break;case Rt.la:i="Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";break;case Rt.fa:i="No device identifier. Please contact support@braze.com"}r.D.error("Backend error: "+i)}return!1}ma(t,e,s,i){return!!(t&&0!==t.length||e&&0!==e.length||s||i)}pa(t,e,s,i){const r=[],o=t=>t||"",n=o(this.v.getUserId());let a,h,u,c,l=this.Ys(t,e);if(s.length>0){const t=[];for(const e of s){if(a=e.Zs(),this.Wo.Gn()){if(n&&!a.user_id){c||(c={},c.events=[]),c.events.push(a);continue}if(o(a.user_id)!==n){h||(h=[]),h.push(a);continue}}t.push(a)}t.length>0&&(l.events=t)}if(i.length>0){const t=[];for(const e of i)this.Wo.Gn()&&o(e.user_id)!==n?(u||(u=[]),u.push(e)):t.push(e);t.length>0&&(l.attributes=t)}if(this.ia(h,u),l=this.Ls(l,!0),c){c=this.Ls(c,!1);const t={requestData:c,headers:this.Ns(c)};r.push(t)}if(l&&!this.ma(l.events,l.attributes,t,e))return c?r:null;const f={requestData:l,headers:this.Ns(l)};return r.push(f),r}ia(t,e){if(t){const e=[];for(const s of t){const t=ue.fromJson(s);t.time=qt(t.time),e.push(t)}this.h.bo(e)}if(e)for(const t of e)this.h.ba(t)}Ms(t,e){let s="HTTP error ";null!=t&&(s+=t+" "),s+=e,r.D.error(s)}yr(t){return s.G(r.A.Ra,{n:t})}Ys(t,e,s){const i={};t&&(i.feed=!0),e&&(i.triggers=!0);const r=null!=s?s:this.v.getUserId();return r&&(i.user_id=r),i.config={config_time:this.wt.Gs()},{respond_with:i}}Ns(t,e){const s=[["X-Braze-Api-Key",this.ji]];let i=!1;if(null!=t.respond_with&&t.respond_with.triggers&&(s.push(["X-Braze-TriggersRequest","true"]),i=!0),null!=t.respond_with&&t.respond_with.feed&&(s.push(["X-Braze-FeedRequest","true"]),i=!0),e&&(s.push(["X-Braze-ContentCardsRequest","true"]),i=!0),i&&s.push(["X-Braze-DataRequest","true"]),this.Wo.Gn()){const t=this.Wo.Hn();null!=t&&s.push(["X-Braze-Auth-Signature",t])}return s}As(t,e){const s=t.device;s&&s.os_version instanceof Promise?s.os_version.then((s=>{t.device.os_version=s,e()})):e()}Es(){this.Wo.Es()}Js(){return this.Do}addSdkMetadata(t){for(const e of t)-1===this.$o.indexOf(e)&&this.$o.push(e)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{STORAGE_KEYS as o}from"./storage-manager.js";import u from"./subscription-manager.js";import jt from"../models/server-config.js";export default class Ot{constructor(t){this.h=t,this.sh=new u,this.eh=new u,this.ih=null}rh(){if(null==this.ih){const t=this.h.I(o.q.nh);this.ih=null!=t?jt.
|
|
1
|
+
import{STORAGE_KEYS as o}from"./storage-manager.js";import u from"./subscription-manager.js";import jt from"../models/server-config.js";export default class Ot{constructor(t){this.h=t,this.sh=new u,this.eh=new u,this.ih=null}rh(){if(null==this.ih){const t=this.h.I(o.q.nh);this.ih=null!=t?jt.jn(t):new jt}return this.ih}Gs(){return this.rh().hh}lh(t){if(null!=t&&null!=t.config){const s=t.config;if(s.time>this.rh().hh){const t=new jt(s.time,s.events_blacklist,s.attributes_blacklist,s.purchases_blacklist,s.messaging_session_timeout,s.vapid_public_key,s.content_cards);let e=!1;null!=t.oh&&this.Sn()!==t.oh&&(e=!0);let i=!1;null!=t.uh.enabled&&this.Bs()!==t.uh.enabled&&(i=!0),this.ih=t,this.h.B(o.q.nh,t.ss()),e&&this.sh.Nt(),i&&this.eh.Nt()}}}Dn(t){let s=this.sh.Et(t);return this.ah&&this.sh.removeSubscription(this.ah),this.ah=s,s}Rs(t){return this.eh.Et(t)}ge(t){return-1!==this.rh().gh.indexOf(t)}Gr(t){return-1!==this.rh().mh.indexOf(t)}Dr(t){return-1!==this.rh().fh.indexOf(t)}dh(){return this.rh().ph}Sn(){return this.rh().oh}Bs(){return this.rh().uh.enabled||!1}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import ue from"../models/braze-event.js";import
|
|
1
|
+
import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import ue from"../models/braze-event.js";import _t from"../models/identifier.js";import{convertMsToSeconds as l}from"../util/date-utils.js";import r from"../../shared-lib/braze-shared-lib.js";export default class Ct{constructor(s,t,e,i){this.h=s,this.v=t,this.wt=e,this.wh=1e3,i=parseFloat(i),isNaN(i)&&(i=1800),i<this.wh/1e3&&(r.D.info("Specified session timeout of "+i+"s is too small, using the minimum session timeout of "+this.wh/1e3+"s instead."),i=this.wh/1e3),this.Sh=i}jh(s,t){return new ue(this.v.getUserId(),r.A.bh,s,t.Ir,{d:l(s-t.xh)})}sa(){const s=this.h._r(o.Cr.Dh);return null==s?null:s.Ir}Eh(){const s=(new Date).valueOf(),t=this.wt.dh(),e=this.h.I(o.q.Ch);if(null!=e&&null==t)return!1;const i=null==e||s-e>1e3*t;return i&&this.h.B(o.q.Ch,s),i}Gh(s,t){return null==t||!(s-t.xh<this.wh)&&t.Nh<s}mo(){const s=(new Date).valueOf(),t=s+1e3*this.Sh,e=this.h._r(o.Cr.Dh);if(this.Gh(s,e)){let i="Generating session start event with time "+s;if(null!=e){let s=e._h;s-e.xh<this.wh&&(s=e.xh+this.Fh),this.h.Hh(this.jh(s,e)),i+=" (old session ended "+s+")"}i+=". Will expire "+t.valueOf(),r.D.info(i);const n=new _t(r.nt.et(),t);this.h.Hh(new ue(this.v.getUserId(),r.A.Wh,s,n.Ir)),this.h.Lr(o.Cr.Dh,n);return null==this.h.I(o.q.Ch)&&this.h.B(o.q.Ch,s),n.Ir}return e._h=s,e.Nh=t,this.h.Lr(o.Cr.Dh,e),e.Ir}kh(){const s=this.h._r(o.Cr.Dh);null!=s&&(this.h.qh(o.Cr.Dh),this.h.Hh(this.jh((new Date).valueOf(),s)))}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import A,{STORAGE_KEYS as o}from"./storage-manager.js";import r from"../../shared-lib/braze-shared-lib.js";const Lt={zo:(e,t)=>{let a=!1;try{if(localStorage&&localStorage.getItem)try{localStorage.setItem(o.q.ga,!0),localStorage.getItem(o.q.ga)&&(localStorage.removeItem(o.q.ga),a=!0)}catch(e){if("QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||!(localStorage.length>0))throw e;a=!0}}catch(e){r.D.info("Local Storage not supported!")}const l=Lt.Sa(),c=new A.Ea(e,l&&!t,a);let n=null;return n=a?new A.wa(e):new A._a,new A(c,n)},Sa:()=>navigator.cookieEnabled||"cookie"in document&&(document.cookie.length>0||(document.cookie="test").indexOf.call(document.cookie,"test")>-1)};export default Lt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import et from"../util/browser-detector.js";import ue from"../models/braze-event.js";import
|
|
1
|
+
import et from"../util/browser-detector.js";import ue from"../models/braze-event.js";import _t from"../models/identifier.js";import{isArray as p,keys as Y,validateValueIsFromEnum as K,values as At}from"../util/code-utils.js";import r from"../../shared-lib/braze-shared-lib.js";import{User}from"../User/index.js";export const STORAGE_KEYS={Cr:{Ur:"ab.storage.userId",Go:"ab.storage.deviceId",Dh:"ab.storage.sessionId"},q:{ga:"ab.test",Ta:"ab.storage.events",Aa:"ab.storage.attributes",Oa:"ab.storage.attributes.anonymous_user",Ho:"ab.storage.device",Yo:"ab.storage.sdk_metadata",Zo:"ab.storage.session_id_for_cached_metadata",Wn:"ab.storage.pushToken",Ks:"ab.storage.newsFeed",Qs:"ab.storage.lastNewsFeedRefresh",P:"ab.storage.cardImpressions",nh:"ab.storage.serverConfig",Ia:"ab.storage.triggers",Ka:"ab.storage.triggers.ts",Ch:"ab.storage.messagingSessionStart",Wt:"ab.storage.cc",Cs:"ab.storage.ccLastFullSync",ws:"ab.storage.ccLastCardUpdated",$:"ab.storage.ccClicks",O:"ab.storage.ccImpressions",K:"ab.storage.ccDismissals",Ya:"ab.storage.lastDisplayedTriggerTimesById",Da:"ab.storage.lastDisplayedTriggerTime",Ga:"ab.storage.triggerFireInstancesById",Jn:"ab.storage.signature"},ae:"ab.optOut"};export default class A{constructor(t,e){this.va=t,this.Na=e}Lr(t,e){let s=e;null!=e&&e instanceof _t&&(s=e.ss()),this.va.store(t,s)}Ma(t){const e=this._r(t);null!=e&&(e._h=(new Date).valueOf(),this.Lr(t,e))}_r(t){return _t.jn(this.va.lr(t))}qh(t){this.va.remove(t)}bo(t){if(null==t||0===t.length)return!1;p(t)||(t=[t]);let e=this.Na.lr(STORAGE_KEYS.q.Ta);null!=e&&p(e)||(e=[]);for(let s=0;s<t.length;s++)e.push(t[s].ss());return this.Na.store(STORAGE_KEYS.q.Ta,e)}Hh(t){return null!=t&&this.bo([t])}Ca(){let t=this.Na.lr(STORAGE_KEYS.q.Ta);this.Na.remove(STORAGE_KEYS.q.Ta),null==t&&(t=[]);const e=[];let s=!1,o=null;if(p(t))for(let s=0;s<t.length;s++)ue.ya(t[s])?e.push(ue.jn(t[s])):o=s;else s=!0;if(s||null!=o){let n="Stored events could not be deserialized as Events";s&&(n+=", was "+Object.prototype.toString.call(t)+" not an array"),null!=o&&(n+=", value at index "+o+" does not look like an event"),n+=", serialized values were of type "+typeof t+": "+JSON.stringify(t),e.push(new ue(null,r.A.ha,(new Date).valueOf(),null,{e:n}))}return e}B(t,e){return!!K(STORAGE_KEYS.q,t,"StorageManager cannot store object.","STORAGE_KEYS.OBJECTS")&&this.Na.store(t,e)}I(t){return!!K(STORAGE_KEYS.q,t,"StorageManager cannot retrieve object.","STORAGE_KEYS.OBJECTS")&&this.Na.lr(t)}$s(t){return!!K(STORAGE_KEYS.q,t,"StorageManager cannot remove object.","STORAGE_KEYS.OBJECTS")&&(this.Na.remove(t),!0)}clearData(){const t=Y(STORAGE_KEYS.Cr),e=Y(STORAGE_KEYS.q);for(let e=0;e<t.length;e++){const s=t[e];this.va.remove(STORAGE_KEYS.Cr[s])}for(let t=0;t<e.length;t++){const s=e[t];this.Na.remove(STORAGE_KEYS.q[s])}}Ua(t){return t||STORAGE_KEYS.q.Oa}ba(t){let e=this.Na.lr(STORAGE_KEYS.q.Aa);null==e&&(e={});const s=this.Ua(t[User.En]);for(let r in t)r===User.En||null!=e[s]&&null!=e[s][r]||this.Kr(t[User.En],r,t[r])}Kr(t,e,s){let r=this.Na.lr(STORAGE_KEYS.q.Aa);null==r&&(r={});const o=this.Ua(t);let n=r[o];if(null==n&&(n={},null!=t&&(n[User.En]=t)),e===User.Jr){null==n[e]&&(n[e]={});for(let t in s)n[e][t]=s[t]}else n[e]=s;return r[o]=n,this.Na.store(STORAGE_KEYS.q.Aa,r)}Ba(){const t=this.Na.lr(STORAGE_KEYS.q.Aa);this.Na.remove(STORAGE_KEYS.q.Aa);const e=[];for(let s in t)null!=t[s]&&e.push(t[s]);return e}Er(t){const e=this.Na.lr(STORAGE_KEYS.q.Aa);if(null!=e){const s=this.Ua(null),r=e[s];null!=r&&(e[s]=void 0,this.Na.store(STORAGE_KEYS.q.Aa,e),r[User.En]=t,this.ba(r))}const s=this._r(STORAGE_KEYS.Cr.Dh);let r=null;null!=s&&(r=s.Ir);const o=this.Ca();if(null!=o)for(let e=0;e<o.length;e++){const s=o[e];null==s.userId&&s.sessionId==r&&(s.userId=t),this.Hh(s)}}Fa(){return this.Na.La}}A.wa=class{constructor(t){this.ji=t,this.La=et.Pa()?3:10}xa(t){return t+"."+this.ji}store(t,e){const s={v:e};try{return localStorage.setItem(this.xa(t),JSON.stringify(s)),!0}catch(t){return r.D.info("Storage failure: "+t.message),!1}}lr(t){try{const e=JSON.parse(localStorage.getItem(this.xa(t)));return null==e?null:e.v}catch(t){return r.D.info("Storage retrieval failure: "+t.message),null}}remove(t){try{localStorage.removeItem(this.xa(t))}catch(t){return r.D.info("Storage removal failure: "+t.message),!1}}};A.ne=class{constructor(t,e){this.ji=t,this.Ja=this.ka(),this.za=576e3,this.Qa=!!e}xa(t){return null!=this.ji?t+"."+this.ji:t}ka(){let t=0,e=document.location.hostname;const s=e.split("."),r="ab._gd";for(;t<s.length-1&&-1===document.cookie.indexOf(r+"="+r);)t++,e="."+s.slice(-1-t).join("."),document.cookie=r+"="+r+";domain="+e+";";return document.cookie=r+"=;expires="+new Date(0).toGMTString()+";domain="+e+";",e}ie(){const t=new Date;return t.setTime(t.getTime()+60*this.za*1e3),t.getFullYear()}Va(){const t=At(STORAGE_KEYS.Cr),e=document.cookie.split(";");for(let s=0;s<e.length;s++){let r=e[s];for(;" "===r.charAt(0);)r=r.substring(1);let o=!1;for(let e=0;e<t.length;e++)if(0===r.indexOf(t[e])){o=!0;break}if(o){const t=r.split("=")[0];-1===t.indexOf("."+this.ji)&&this.Ha(t)}}}store(t,e){this.Va();const s=new Date;s.setTime(s.getTime()+60*this.za*1e3);const o="expires="+s.toUTCString(),n="domain="+this.Ja;let i;i=this.Qa?e:encodeURIComponent(JSON.stringify(e));const a=this.xa(t)+"="+i+";"+o+";"+n+";path=/";return a.length>=4093?(r.D.info("Storage failure: string is "+a.length+" chars which is too large to store as a cookie."),!1):(document.cookie=a,!0)}lr(t){const e=[],s=this.xa(t)+"=",o=document.cookie.split(";");for(let n=0;n<o.length;n++){let i=o[n];for(;" "===i.charAt(0);)i=i.substring(1);if(0===i.indexOf(s))try{let t;t=this.Qa?i.substring(s.length,i.length):JSON.parse(decodeURIComponent(i.substring(s.length,i.length))),e.push(t)}catch(e){return r.D.info("Storage retrieval failure: "+e.message),this.remove(t),null}}return e.length>0?e[e.length-1]:null}remove(t){this.Ha(this.xa(t))}Ha(t){const e=t+"=;expires="+new Date(0).toGMTString();document.cookie=e,document.cookie=e+";path=/";const s=e+";domain="+this.Ja;document.cookie=s,document.cookie=s+";path=/"}};A._a=class{constructor(){this.Wa={},this.Xa=5242880,this.La=3}store(t,e){const s={value:e},o=this.qa(e);return o>this.Xa?(r.D.info("Storage failure: object is ≈"+o+" bytes which is greater than the max of "+this.Xa),!1):(this.Wa[t]=s,!0)}qa(t){const e=[],s=[t];let r=0;for(;s.length;){const t=s.pop();if("boolean"==typeof t)r+=4;else if("string"==typeof t)r+=2*t.length;else if("number"==typeof t)r+=8;else if("object"==typeof t&&-1===e.indexOf(t)){e.push(t);for(let e in t)s.push(t[e])}}return r}lr(t){const e=this.Wa[t];return null==e?null:e.value}remove(t){this.Wa[t]=null}};A.Ea=class{constructor(t,e,s){this.Za=[],e&&this.Za.push(new A.ne(t)),s&&this.Za.push(new A.wa(t)),this.Za.push(new A._a(t))}store(t,e){let s=!0;for(let r=0;r<this.Za.length;r++)s=this.Za[r].store(t,e)&&s;return s}lr(t){for(let e=0;e<this.Za.length;e++){const s=this.Za[e].lr(t);if(null!=s)return s}return null}remove(t){for(let e=0;e<this.Za.length;e++)this.Za[e].remove(t)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";export default class u{constructor(){this.
|
|
1
|
+
import r from"../../shared-lib/braze-shared-lib.js";export default class u{constructor(){this.De={}}Et(t){if("function"!=typeof t)return null;const i=r.nt.et();return this.De[i]=t,i}removeSubscription(t){delete this.De[t]}removeAllSubscriptions(){this.De={}}Nt(t){const i=[];for(let r in this.De)i.push(this.De[r](t));return i}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default{
|
|
1
|
+
export default{ca:"invalid_api_key",la:"blacklisted",fa:"no_device_identifier",ua:"invalid_json_response",oa:"empty_response",__:"sdk_auth_error"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as
|
|
1
|
+
import{isObject as Jt}from"../util/code-utils.js";import{convertMsToSeconds as l,timestampOrNow as Vt}from"../util/date-utils.js";export default class ue{constructor(t,i,s,r,e){this.userId=t,this.type=i,this.time=Vt(s),this.sessionId=r,this.data=e}Zs(){const t={name:this.type,time:l(this.time),data:this.data||{},session_id:this.sessionId};return null!=this.userId&&(t.user_id=this.userId),t}ss(){return{u:this.userId,t:this.type,ts:this.time,s:this.sessionId,d:this.data}}static fromJson(t){return new ue(t.user_id,t.name,t.time,t.session_id,t.data)}static ya(t){return null!=t&&Jt(t)&&null!=t.t&&""!==t.t}static jn(t){return new ue(t.u,t.t,t.ts,t.s,t.d)}}
|
package/src/models/device.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import DeviceProperties from"../Core/device-properties.js";export default class Ie{constructor(s){this.id=s}
|
|
1
|
+
import DeviceProperties from"../Core/device-properties.js";export default class Ie{constructor(s){this.id=s}Zs(){const s={};return null!=this[DeviceProperties.BROWSER]&&(s.browser=this[DeviceProperties.BROWSER]),null!=this[DeviceProperties.BROWSER_VERSION]&&(s.browser_version=this[DeviceProperties.BROWSER_VERSION]),null!=this[DeviceProperties.OS]&&(s.os_version=this[DeviceProperties.OS]),null!=this[DeviceProperties.RESOLUTION]&&(s.resolution=this[DeviceProperties.RESOLUTION]),null!=this[DeviceProperties.LANGUAGE]&&(s.locale=this[DeviceProperties.LANGUAGE]),null!=this[DeviceProperties.TIME_ZONE]&&(s.time_zone=this[DeviceProperties.TIME_ZONE]),null!=this[DeviceProperties.USER_AGENT]&&(s.user_agent=this[DeviceProperties.USER_AGENT]),s}}
|
package/src/models/identifier.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";export default class
|
|
1
|
+
import r from"../../shared-lib/braze-shared-lib.js";export default class _t{constructor(t,e,s){null==t&&(t=r.nt.et()),s=parseInt(s),(isNaN(s)||0===s)&&(s=(new Date).valueOf()),this.Ir=t,this.xh=s,this._h=(new Date).valueOf(),this.Nh=e}ss(){return{g:this.Ir,e:this.Nh,c:this.xh,l:this._h}}static jn(t){if(null==t||null==t.g)return null;const e=new _t(t.g,t.e,t.c);return e._h=t.l,e}}
|
package/src/models/push-token.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{rehydrateDateAfterJsonization as w}from"../util/date-utils.js";export default class ei{constructor(t,i,l,s,u){this.endpoint=t||null,this.
|
|
1
|
+
import{rehydrateDateAfterJsonization as w}from"../util/date-utils.js";export default class ei{constructor(t,i,l,s,u){this.endpoint=t||null,this.An=i||null,this.publicKey=l||null,this.tl=s||null,this.oh=u||null}ss(){return{e:this.endpoint,c:this.An,p:this.publicKey,u:this.tl,v:this.oh}}static jn(t){return new ei(t.e,w(t.c),t.p,t.u,t.v)}}
|
|
@@ -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.
|
|
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.6",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.6"!==t.s&&(s=0),new jt(s,t.e,t.a,t.p,t.m,t.v,t.c)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import b from"./util/net.js";import ue from"./models/braze-event.js";import s from"./common/event-logger.js";import{randomInclusive as lt}from"./util/math.js";import t from"./models/request-result.js";import r from"../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"./managers/storage-manager.js";import u from"./managers/subscription-manager.js";export default class Tt{constructor(t,s,i,e,n,l,h,o,r,a){this.
|
|
1
|
+
import b from"./util/net.js";import ue from"./models/braze-event.js";import s from"./common/event-logger.js";import{randomInclusive as lt}from"./util/math.js";import t from"./models/request-result.js";import r from"../shared-lib/braze-shared-lib.js";import{STORAGE_KEYS as o}from"./managers/storage-manager.js";import u from"./managers/subscription-manager.js";export default class Tt{constructor(t,s,i,e,n,l,h,o,r,a){this.ji=t,this.Do=s,this.sl=0,this.il=h.Fa(),this.hl=null,this.j=i,this.xi=e,this.v=n,this.wt=l,this.h=h,this.Wo=r,this.jt=a,this.ol=o,this.rl=new u,this.ul=50}al(t,s){return!t&&!s&&this.Wo.Rn()>=this.ul}cl(t){let s=this.j.Eh();if(t.length>0){const i=this.v.getUserId();for(const e of t){const t=!e.userId&&!i||e.userId===i;e.type===r.A.Wh&&t&&(s=!0)}}return s}dl(t,s,i,e,n,l,h){null==i&&(i=!0),i&&this.ml();const u=this.h.Ca(),a=this.h.Ba();let c=!1;const d=(t,s)=>{let h=!1;b.Fs({url:this.Do+"/data/",data:t,headers:s,S:i=>{null!=t.respond_with&&t.respond_with.triggers&&(this.sl=Math.max(this.sl-1,0)),this.jt.qs(t,i,s)?(this.Wo.Es(),this.wt.lh(i),null!=t.respond_with&&t.respond_with.user_id!=this.v.getUserId()||(null!=t.device&&this.h.B(o.q.Ho,t.device),null!=t.sdk_metadata&&(this.h.B(o.q.Yo,t.sdk_metadata),this.h.B(o.q.Zo,this.j.sa())),this.ol(i),"function"==typeof e&&e())):i.auth_error&&(h=!0)},error:()=>{null!=t.respond_with&&t.respond_with.triggers&&(this.sl=Math.max(this.sl-1,0)),this.jt.ia(t.events,t.attributes),"function"==typeof n&&n()},fl:t=>{if("function"==typeof l&&l(t),i&&!c){if(t&&!h)this.gl();else{let t=this.hl;(null==t||t<1e3*this.il)&&(t=1e3*this.il),this.gl(Math.min(3e5,lt(1e3*this.il,3*t)))}c=!0}}})},m=this.cl(u),f=s||m;if(this.al(h,m))return void r.D.info("Declining to flush data due to 50 consecutive authentication failures");if(i&&!this.jt.ma(u,a,t,f))return this.gl(),void("function"==typeof l&&l(!0));const g=this.jt.pa(t,f,u,a);f&&this.sl++;let p=!1;if(g)for(const t of g)this.jt.As(t.requestData,(()=>d(t.requestData,t.headers))),p=!0;this.Wo.Gn()&&i&&!p?this.gl():m&&(r.D.info("Invoking new session subscriptions"),this.rl.Nt())}bl(){return this.sl>0}gl(t){this.kl||(null==t&&(t=1e3*this.il),this.ml(),this.wl=setTimeout((()=>{if(document.hidden){const t="visibilitychange",s=()=>{document.hidden||(document.removeEventListener(t,s,!1),this.dl())};document.addEventListener(t,s,!1)}else this.dl()}),t),this.hl=t)}ml(){null!=this.wl&&(clearTimeout(this.wl),this.wl=null)}initialize(){this.kl=!1,this.gl()}destroy(){this.rl.removeAllSubscriptions(),this.Wo.On(),this.ml(),this.kl=!0,this.dl(null,null,!1),this.wl=null}cr(t){return this.rl.Et(t)}openSession(){const t=this.j.sa()!==this.j.mo();t&&(this.h.Ma(o.Cr.Go),this.h.Ma(o.Cr.Ur)),this.dl(null,!1,null,null,null),this.In(),t&&import("./Push/push-manager-factory.js").then((t=>{if(this.kl)return;const s=t.default.Xe();if(null!=s&&(s.isPushPermissionGranted()||s.isPushBlocked())){const t=()=>{s.Xi()?r.D.info("Push token maintenance is disabled, not refreshing token for backend."):s.subscribe()},i=(s,i)=>{i&&t()},e=()=>{const s=this.h.I(o.q.Wn);(null==s||s)&&t()},n=r.Ft.xt;new r.qt(n,r.D).hr(n.Pt.Mr,i,e)}}))}changeUser(t,s,i){const e=this.v.getUserId();if(e!==t){this.j.kh(),null!=e&&this.dl(null,!1,null,null,null),this.v.Br(t),i?this.Wo.setSdkAuthenticationSignature(i):this.Wo.Ln();for(let t=0;t<s.length;t++)s[t].changeUser(null==e);null!=e&&this.h.$s(o.q.P),this.h.$s(o.q.Ho),this.openSession(),r.D.info('Changed user to "'+t+'".')}else{let s="Doing nothing.";i&&this.Wo.Hn()!==i&&(this.Wo.setSdkAuthenticationSignature(i),s="Updated SDK authentication signature"),r.D.info(`Current user is already ${t}. ${s}`)}}requestImmediateDataFlush(t){this.ml(),this.j.mo(),this.dl(null,null,null,null,null,t,!0)}requestFeedRefresh(){this.j.mo(),this.dl(!0)}zr(t,s){this.j.mo(),r.D.info("Requesting explicit trigger refresh."),this.dl(null,!0,null,t,s)}Nr(t,i){const e=r.A.yl,n={a:t,l:i},l=s.G(e,n);return l&&r.D.info(`Logged alias ${t} with label ${i}`),l}Or(i,e,n){if(this.wt.Gr(e))return r.D.info(`Custom Attribute "${e}" is blocklisted, ignoring.`),new t;const l={key:e,value:n},h=s.G(i,l);return h&&r.D.info(`Logged custom attribute: ${e} with value: ${n}`),h}setLastKnownLocation(t,i,e,n,l,h){const o={latitude:i,longitude:e};null!=n&&(o.altitude=n),null!=l&&(o.ll_accuracy=l),null!=h&&(o.alt_accuracy=h);const u=s.G(r.A.vl,o,t);return u&&r.D.info(`Set user last known location as ${JSON.stringify(o,null,2)}`),u}kr(t,s){const i=this.j.mo();return new ue(this.v.getUserId(),r.A.Sl,t,i,{cid:s})}In(){const t=r.Ft.xt;new r.qt(t,r.D).setItem(t.Pt.jl,1,{baseUrl:this.Do,data:{api_key:this.ji,device_id:this.xi.te().id},userId:this.v.getUserId(),sdkAuthEnabled:this.Wo.Gn()})}wr(t){for(const s of t)if(s.api_key===this.ji)this.jt.ia(s.events,s.attributes);else{const t=r.Ft.xt;new r.qt(t,r.D).setItem(t.Pt.$r,r.nt.et(),s)}}Xr(i,e,n){if(this.wt.Gr(i))return r.D.info(`Custom Attribute "${i}" is blocklisted, ignoring.`),new t;let l,h;return null===e&&null===n?(l=r.A.$l,h={key:i}):(l=r.A.Al,h={key:i,latitude:e,longitude:n}),s.G(l,h)}Zr(t,i){const e={group_id:t,status:i};return s.G(r.A.Cl,e)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import kt from"./filter.js";import{isArray as p}from"../../util/code-utils.js";export default class Bt{constructor(t){this.filters=t}zl(t){let r=!0;for(let e=0;e<this.filters.length;e++){const o=this.filters[e];let s=!1;for(let r=0;r<o.length;r++)if(o[r].zl(t)){s=!0;break}if(!s){r=!1;break}}return r}static fromJson(t){if(null==t||!p(t))return null;const r=[];for(let e=0;e<t.length;e++){const o=[],s=t[e];for(let t=0;t<s.length;t++)o.push(kt.fromJson(s[t]));r.push(o)}return new Bt(r)}ss(){const t=[];for(let r=0;r<this.filters.length;r++){const e=this.filters[r],o=[];for(let t=0;t<e.length;t++)o.push(e[t].ss());t.push(o)}return t}static
|
|
1
|
+
import kt from"./filter.js";import{isArray as p}from"../../util/code-utils.js";export default class Bt{constructor(t){this.filters=t}zl(t){let r=!0;for(let e=0;e<this.filters.length;e++){const o=this.filters[e];let s=!1;for(let r=0;r<o.length;r++)if(o[r].zl(t)){s=!0;break}if(!s){r=!1;break}}return r}static fromJson(t){if(null==t||!p(t))return null;const r=[];for(let e=0;e<t.length;e++){const o=[],s=t[e];for(let t=0;t<s.length;t++)o.push(kt.fromJson(s[t]));r.push(o)}return new Bt(r)}ss(){const t=[];for(let r=0;r<this.filters.length;r++){const e=this.filters[r],o=[];for(let t=0;t<e.length;t++)o.push(e[t].ss());t.push(o)}return t}static jn(t){const r=[];for(let e=0;e<t.length;e++){const o=[],s=t[e];for(let t=0;t<s.length;t++)o.push(kt.jn(s[t]));r.push(o)}return new Bt(r)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isDate as
|
|
1
|
+
import{isDate as yt}from"../../util/code-utils.js";import{convertMsToSeconds as l,dateFromUnixTimestamp as h,secondsAgo as Ht,secondsInTheFuture as Ut}from"../../util/date-utils.js";export default class kt{constructor(t,s,e,i){this.El=t,this.Tl=s,this.comparator=e,this._l=i,this.Tl===kt.Ml.Nl&&this.comparator!==kt.Hl.Rl&&this.comparator!==kt.Hl.Ll&&this.comparator!==kt.Hl.Il&&this.comparator!==kt.Hl.Ol&&(this._l=h(this._l))}zl(t){let s=null;switch(null!=t&&(s=t[this.El]),this.comparator){case kt.Hl.Ul:return null!=s&&s.valueOf()===this._l.valueOf();case kt.Hl.Dl:return null==s||s.valueOf()!==this._l.valueOf();case kt.Hl.Ql:return typeof s==typeof this._l&&s>this._l;case kt.Hl.Rl:return this.Tl===kt.Ml.Nl?null!=s&&yt(s)&&Ht(s)<=this._l:typeof s==typeof this._l&&s>=this._l;case kt.Hl.Xl:return typeof s==typeof this._l&&s<this._l;case kt.Hl.Ll:return this.Tl===kt.Ml.Nl?null!=s&&yt(s)&&Ht(s)>=this._l:typeof s==typeof this._l&&s<=this._l;case kt.Hl.Gl:return null!=s&&"string"==typeof s&&typeof s==typeof this._l&&null!=s.match(this._l);case kt.Hl.Fl:return null!=s;case kt.Hl.Jl:return null==s;case kt.Hl.Il:return null!=s&&yt(s)&&Ut(s)<this._l;case kt.Hl.Ol:return null!=s&&yt(s)&&Ut(s)>this._l;case kt.Hl.Vl:return null==s||typeof s!=typeof this._l||"string"!=typeof s||null==s.match(this._l)}return!1}static fromJson(t){return new kt(t.property_key,t.property_type,t.comparator,t.property_value)}ss(){let t=this._l;return yt(this._l)&&(t=l(t.valueOf())),{k:this.El,t:this.Tl,c:this.comparator,v:t}}static jn(t){return new kt(t.k,t.t,t.c,t.v)}}kt.Hl={Ul:1,Dl:2,Ql:3,Rl:4,Xl:5,Ll:6,Gl:10,Fl:11,Jl:12,Il:15,Ol:16,Vl:17},kt.Ml={ql:"boolean",Kl:"number",Pl:"string",Nl:"date"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import Dt from"./trigger-condition.js";export default class
|
|
1
|
+
import Dt from"./trigger-condition.js";export default class Qt{constructor(t){this.Wl=t}zl(t){return null==this.Wl||Dt.Zl(t[0],this.Wl)}static fromJson(t){return new Qt(t?t.campaign_id:null)}ss(){return this.Wl}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import xt from"./custom-event-data.js";import Mt from"./custom-event-property-data.js";import Bt from"./filter-set.js";import Ft from"./in-app-message-click-data.js";import Gt from"./purchase-data.js";import Kt from"./purchase-property-data.js";import
|
|
1
|
+
import xt from"./custom-event-data.js";import Mt from"./custom-event-property-data.js";import Bt from"./filter-set.js";import Ft from"./in-app-message-click-data.js";import Gt from"./purchase-data.js";import Kt from"./purchase-property-data.js";import Qt from"./push-click-data.js";import Q from"./trigger-events.js";import r from"../../../shared-lib/braze-shared-lib.js";export default class Dt{constructor(e,t){this.type=e,this.data=t}$a(e,t){return Dt.ec[this.type]===e&&(null==this.data||this.data.zl(t))}static Zl(e,t){let a=null;try{a=window.atob(e)}catch(t){return r.D.info("Failed to unencode analytics id "+e+": "+t.message),!1}return t===a.split("_")[0]}static fromJson(e){const t=e.type;let r;switch(t){case Dt.tc.OPEN:r=null;break;case Dt.tc.Rr:r=Gt.fromJson(e.data);break;case Dt.tc.rc:r=Kt.fromJson(e.data);break;case Dt.tc.vr:r=Qt.fromJson(e.data);break;case Dt.tc.be:r=xt.fromJson(e.data);break;case Dt.tc.ac:r=Mt.fromJson(e.data);break;case Dt.tc.Ar:r=Ft.fromJson(e.data);break;case Dt.tc.ks:r=null}return new Dt(t,r)}ss(){return{t:this.type,d:this.data?this.data.ss():null}}static jn(e){let t,r;switch(e.t){case Dt.tc.OPEN:t=null;break;case Dt.tc.Rr:t=new Gt(e.d);break;case Dt.tc.rc:r=e.d||{},t=new Kt(r.id,Bt.jn(r.pf||[]));break;case Dt.tc.vr:t=new Qt(e.d);break;case Dt.tc.be:t=new xt(e.d);break;case Dt.tc.ac:r=e.d||{},t=new Mt(r.e,Bt.jn(r.pf||[]));break;case Dt.tc.Ar:t=new Ft(e.d);break;case Dt.tc.ks:t=null}return new Dt(e.t,t)}}Dt.tc={OPEN:"open",Rr:"purchase",rc:"purchase_property",vr:"push_click",be:"custom_event",ac:"custom_event_property",Ar:"iam_click",ks:"test"},Dt.ec={},Dt.ec[Dt.tc.OPEN]=Q.OPEN,Dt.ec[Dt.tc.Rr]=Q.Rr,Dt.ec[Dt.tc.rc]=Q.Rr,Dt.ec[Dt.tc.vr]=Q.vr,Dt.ec[Dt.tc.be]=Q.be,Dt.ec[Dt.tc.ac]=Q.be,Dt.ec[Dt.tc.Ar]=Q.Ar,Dt.ec[Dt.tc.ks]=Q.ks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default{OPEN:"open",Rr:"purchase",
|
|
1
|
+
export default{OPEN:"open",Rr:"purchase",vr:"push_click",be:"custom_event",Ar:"iam_click",ks:"test"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dateFromUnixTimestamp as h,rehydrateDateAfterJsonization as w}from"../../util/date-utils.js";import r from"../../../shared-lib/braze-shared-lib.js";import Dt from"./trigger-condition.js";import{validateValueIsFromEnum as
|
|
1
|
+
import{dateFromUnixTimestamp as h,rehydrateDateAfterJsonization as w}from"../../util/date-utils.js";import r from"../../../shared-lib/braze-shared-lib.js";import Dt from"./trigger-condition.js";import{validateValueIsFromEnum as K}from"../../util/code-utils.js";export default class ut{constructor(t,i,s,e,r,l,o,n,h,a,u,d){this.id=t,this.Th=i||[],void 0===s&&(s=null),this.startTime=s,void 0===e&&(e=null),this.endTime=e,this.priority=r||0,this.type=l,this.Ph=n||0,null==a&&(a=1e3*(this.Ph+30)),this.li=a,this.data=o,null==h&&(h=ut.yh),this.Ah=h,this.Ih=u,this.$h=d||null}Mh(t){return null==this.$h||this.Ah!==ut.yh&&t-this.$h>=1e3*this.Ah}Bh(t){this.$h=t}Jh(t){const i=t+1e3*this.Ph;return Math.max(i-(new Date).valueOf(),0)}Lh(t){const i=(new Date).valueOf()-t,s=null==t||isNaN(i)||null==this.li||i<this.li;return s||r.D.info(`Trigger action ${this.type} is no longer eligible for display - fired ${i}ms ago and has a timeout of ${this.li}ms.`),!s}static fromJson(t){const i=t.id,s=[];for(let i=0;i<t.trigger_condition.length;i++)s.push(Dt.fromJson(t.trigger_condition[i]));const e=h(t.start_time),r=h(t.end_time),l=t.priority,o=t.type,n=t.delay,a=t.re_eligibility,u=t.timeout,d=t.data,m=t.min_seconds_since_last_trigger;return K(ut.ri,o,"Could not construct Trigger from server data","Trigger.Types")?new ut(i,s,e,r,l,o,d,n,a,u,m):null}ss(){const t=[];for(let i=0;i<this.Th.length;i++)t.push(this.Th[i].ss());return{i:this.id,c:t,s:this.startTime,e:this.endTime,p:this.priority,t:this.type,da:this.data,d:this.Ph,r:this.Ah,tm:this.li,ss:this.Ih,ld:this.$h}}static jn(t){const i=[];for(let s=0;s<t.c.length;s++)i.push(Dt.jn(t.c[s]));return new ut(t.i,i,w(t.s),w(t.e),t.p,t.t,t.da,t.d,t.r,t.tm,t.ss,t.ld)}}ut.yh=-1,ut.ri={ii:"inapp",Rh:"templated_iam"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pe from"../InAppMessage/in-app-message-manager-factory.js";import e,{OPTIONS as D}from"../managers/braze-instance.js";import ir from"./triggers-provider.js";export const TriggersProviderFactory={t:!1,provider:null,er:()=>(TriggersProviderFactory.init(),TriggersProviderFactory.provider),rg:()=>{if(!TriggersProviderFactory.provider){const r=e.nn(D.po);TriggersProviderFactory.provider=new ir(null!=r?r:30,pe.m().Be(),e.l(),e.mr(),pe.m()),e.ar(TriggersProviderFactory.provider)}},init:()=>{TriggersProviderFactory.t||(TriggersProviderFactory.rg(),e.u(TriggersProviderFactory),TriggersProviderFactory.t=!0)},destroy:()=>{TriggersProviderFactory.provider=null,TriggersProviderFactory.t=!1}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import C from"../common/base-provider.js";import{newInAppMessageFromJson as it}from"../InAppMessage/in-app-message-factory.js";import ue from"../models/braze-event.js";import{InAppMessage}from"../InAppMessage/index.js";import{isArray as p,isEqual as ii,validateValueIsFromEnum as
|
|
1
|
+
import C from"../common/base-provider.js";import{newInAppMessageFromJson as it}from"../InAppMessage/in-app-message-factory.js";import ue from"../models/braze-event.js";import{InAppMessage}from"../InAppMessage/index.js";import{isArray as p,isEqual as ii,validateValueIsFromEnum as K}from"../util/code-utils.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import ft from"../InAppMessage/models/templated-in-app-message.js";import ut from"./models/trigger.js";import Q from"./models/trigger-events.js";import r from"../../shared-lib/braze-shared-lib.js";export default class ir extends C{constructor(t,i,s,e,r){super(),this.Oh=t,this.vt=i,this.h=s,this.Is=e,this.Uh=r,this.Kh=[],this.Qh=[],this.Vh=null,this.Xh={},this.Yh={},this.Zh(),this.tg()}ig(){this.Vh=this.h.I(o.q.Da)||this.Vh,this.Xh=this.h.I(o.q.Ga)||this.Xh,this.Yh=this.h.I(o.q.Ya)||this.Yh;for(let t=0;t<this.sg.length;t++){const i=this.sg[t];null!=this.Yh[i.id]&&i.Bh(this.Yh[i.id])}}Zh(){this.eg=this.h.I(o.q.Ka)||0;const t=this.h.I(o.q.Ia)||[],i=[];for(let s=0;s<t.length;s++)i.push(ut.jn(t[s]));this.sg=i,this.ig()}tg(){const t=this,i=function(i,s,e,r,h){return function(){t.hg(i,s,e,r,h)}},s={};for(let t=0;t<this.sg.length;t++)s[this.sg[t].id]=this.sg[t];let e=!1;for(let t=0;t<this.sg.length;t++){const r=this.sg[t];if(null!=this.Xh[r.id]){const t=this.Xh[r.id],h=[];for(let e=0;e<t.length;e++){const o=t[e],n=r.Jh(o.ai);if(n>0){let t,e;h.push(o),null!=o.og&&(t=o.og),null!=o.ng&&ue.ya(o.ng)&&(e=ue.jn(o.ng));const l=[];if(p(o.lg))for(let t=0;t<o.lg.length;t++){const i=s[o.lg[t]];null!=i&&l.push(i)}this.Qh.push(setTimeout(i(r,o.ai,t,e,l),n))}}this.Xh[r.id].length>h.length&&(this.Xh[r.id]=h,e=!0,0===this.Xh[r.id].length&&delete this.Xh[r.id])}}e&&this.h.B(o.q.Ga,this.Xh)}ag(){const t=[];for(let i=0;i<this.sg.length;i++)t.push(this.sg[i].ss());this.eg=(new Date).valueOf(),this.h.B(o.q.Ia,t),this.h.B(o.q.Ka,this.eg)}gg(){(this.h.I(o.q.Ka)||0)>this.eg?this.Zh():this.ig()}_s(t){let i=!1;if(null!=t&&t.triggers){this.ig();const s={},e={};this.sg=[];for(let r=0;r<t.triggers.length;r++){const h=ut.fromJson(t.triggers[r]);null!=this.Yh[h.id]&&(h.Bh(this.Yh[h.id]),s[h.id]=this.Yh[h.id]),null!=this.Xh[h.id]&&(e[h.id]=this.Xh[h.id]);for(let t=0;t<h.Th.length;t++)if(h.Th[t].$a(Q.ks,null)){i=!0;break}null!=h&&this.sg.push(h)}ii(this.Yh,s)||(this.Yh=s,this.h.B(o.q.Ya,this.Yh)),ii(this.Xh,e)||(this.Xh=e,this.h.B(o.q.Ga,this.Xh)),this.ag(),i&&(r.D.info("Trigger with test condition found, firing test."),this.je(Q.ks)),this.je(Q.OPEN);const h=this.Kh;this.Kh=[];for(let t=0;t<h.length;t++)this.je.apply(this,h[t])}}async hg(t,i,s,e,h){const o=e=>{this.ig();const h=(new Date).valueOf();if(!t.Lh(i))return!1===navigator.onLine&&t.type===ut.ri.ii&&e.imageUrl?(r.D.info(`Not showing ${t.type} trigger action ${t.id} due to offline state.`),void this.Uh.qe(t.id,InAppMessage.Oe.Bi)):void(t.Mh(h)&&this.fg(t,h,s)?(this.vt.Nt([e]),this.cg(t,h)):r.D.info(`Not displaying trigger ${t.id} because display time fell outside of the acceptable time window.`));t.type===ut.ri.Rh?this.Uh.qe(t.id,InAppMessage.Oe.ei):this.Uh.qe(t.id,InAppMessage.Oe.vi)},n=()=>{this.ig();const o=h.pop();if(null!=o)if(this.ug(o,i,s,e,h),o.Lh(i)){let t=`Server aborted in-app message display, but the timeout on fallback trigger ${o.id} has already elapsed.`;h.length>0&&(t+=" Continuing to fall back."),r.D.info(t),this.Uh.qe(o.id,InAppMessage.Oe.vi),n()}else{r.D.info(`Server aborted in-app message display. Falling back to lower priority ${o.type} trigger action ${t.id}.`);const n=1e3*o.Ph-((new Date).valueOf()-i);n>0?this.Qh.push(setTimeout((()=>{this.hg(o,i,s,e,h)}),n)):this.hg(o,i,s,e,h)}};switch(t.type){case ut.ri.ii:const h=it(t.data);if(null==h){r.D.error(`Could not parse trigger data for trigger ${t.id}, ignoring.`),this.Uh.qe(t.id,InAppMessage.Oe.ni);break}let l=await this.Uh.Ve(h);if(l){r.D.error(l),n();break}o(h);break;case ut.ri.Rh:const a=ft.fromJson(t.data,o,n,i,t.li);if(null==a){r.D.error(`Could not parse trigger data for trigger ${t.id}, ignoring.`),this.Uh.qe(t.id,InAppMessage.Oe.ni);break}this.Uh.Xs(a,s,e);break;default:r.D.error(`Trigger ${t.id} was of unexpected type ${t.type}, ignoring.`),this.Uh.qe(t.id,InAppMessage.Oe.ni)}}je(t,i,s){if(!K(Q,t,"Cannot fire trigger action.","TriggerEvents"))return;if(this.Is.bl())return r.D.info("Trigger sync is currently in progress, awaiting sync completion before firing trigger event."),void this.Kh.push(arguments);this.gg();const e=(new Date).valueOf(),h=e-this.Vh;let o=!0,n=!0;const l=[];for(let s=0;s<this.sg.length;s++){const r=this.sg[s],h=e+1e3*r.Ph;if(r.Mh(h)&&(null==r.startTime||r.startTime<=e)&&(null==r.endTime||r.endTime>=e)){let s=!1;for(let e=0;e<r.Th.length;e++)if(r.Th[e].$a(t,i)){s=!0;break}s&&(o=!1,this.fg(r,h,t)&&(n=!1,l.push(r)))}}if(o)return void r.D.info(`Trigger event ${t} did not match any trigger conditions.`);if(n)return void r.D.info(`Ignoring ${t} trigger event because a trigger was displayed ${h/1e3}s ago.`);l.sort(((t,i)=>t.priority-i.priority));const a=l.pop();null!=a&&(r.D.info(`Firing ${a.type} trigger action ${a.id} from trigger event ${t}.`),this.ug(a,e,t,s,l),0===a.Ph?this.hg(a,e,t,s,l):this.Qh.push(setTimeout((()=>{this.hg(a,e,t,s,l)}),1e3*a.Ph)))}changeUser(t){if(this.sg=[],this.h.$s(o.q.Ia),!t){this.Kh=[],this.Vh=null,this.Yh={},this.Xh={};for(let t=0;t<this.Qh.length;t++)clearTimeout(this.Qh[t]);this.Qh=[],this.h.$s(o.q.Da),this.h.$s(o.q.Ya),this.h.$s(o.q.Ga)}}clearData(){this.sg=[],this.Vh=null,this.Yh={},this.Xh={};for(let t=0;t<this.Qh.length;t++)clearTimeout(this.Qh[t]);this.Qh=[]}fg(t,i,s){if(null==this.Vh)return!0;if(s===Q.ks)return r.D.info("Ignoring minimum interval between trigger because it is a test type."),!0;let e=t.Ih;return null==e&&(e=this.Oh),i-this.Vh>=1e3*e}ug(t,i,s,e,r){this.ig(),this.Xh[t.id]=this.Xh[t.id]||[];const h={};let n;h.ai=i,h.og=s,null!=e&&(n=e.ss()),h.ng=n;const l=[];for(let t=0;t<r.length;t++)l.push(r[t].id);h.lg=l,this.Xh[t.id].push(h),this.h.B(o.q.Ga,this.Xh)}cg(t,i){this.ig(),t.Bh(i),this.Vh=i,this.h.B(o.q.Da,i),this.Yh[t.id]=i,this.h.B(o.q.Ya,this.Yh)}}
|