@braze/web-sdk 4.0.3 → 4.0.4
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/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/html-message-to-html.js +1 -1
- package/src/InAppMessage/display/in-app-message-to-html.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/ui/show-in-app-message.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/User/user-manager.js +1 -1
- package/src/User/user.js +1 -1
- package/src/common/feed-display.js +1 -1
- package/src/l10n/l10n-manager-factory.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/models/backend-errors.js +1 -1
- package/src/models/braze-event.js +1 -1
- package/src/models/server-config.js +1 -1
- package/src/request-controller.js +1 -1
- package/src/triggers/models/filter.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/browser-detector.js +1 -1
- package/src/util/client-hints-parser.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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Type definitions for @braze/web-sdk v4.0.
|
|
2
|
+
* Type definitions for @braze/web-sdk v4.0.4
|
|
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
|
|
@@ -1769,9 +1769,7 @@
|
|
|
1769
1769
|
): boolean;
|
|
1770
1770
|
|
|
1771
1771
|
/**
|
|
1772
|
-
*
|
|
1773
|
-
* UI and should only be called if you're bypassing that and manually building
|
|
1774
|
-
* the class for displaying the cards in your own code.
|
|
1772
|
+
* @deprecated This method has been deprecated and is currently a no-op.
|
|
1775
1773
|
*/
|
|
1776
1774
|
export function logContentCardsDisplayed(): boolean;
|
|
1777
1775
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import je from"./encoding-utils.js";import{EventTypes as ve,InternalEventTypes as De}from"./event-types.js";import
|
|
1
|
+
import je from"./encoding-utils.js";import{EventTypes as ve,InternalEventTypes as De}from"./event-types.js";import Be from"./guid.js";import Ae from"./indexed-db-adapter.js";import Ge from"./logger.js";import Oe from"./supported-options.js";const r={Un:je,A:ve,qr:De,nt:Be,qt:Ae,Ft:Ae.ep,D:Ge,jo:Oe};export default r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const ve={CustomEvent:"ce",Pr:"p",Sl:"pc",nc:"ca",
|
|
1
|
+
const ve={CustomEvent:"ce",Pr:"p",Sl:"pc",nc:"ca",pa:"i",ia:"ie",T:"cci",W:"ccic",_:"ccc",L:"ccd",Wh:"ss",bh:"se",gi:"si",mi:"sc",fi:"sbc",ci:"sfe",Ir:"iec",vl:"lr",yl:"uae",U:"ci",F:"cc",Al:"lcaa",$l:"lcar",Xr:"inc",Yr:"add",Qr:"rem",Wr:"set",Cl:"sgu"},De={Fr:"feed_displayed",oc:"content_cards_displayed"};export{ve as EventTypes,De as InternalEventTypes};
|
package/shared-lib/guid.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Be={et:()=>{const t=t=>{const e=(Math.random().toString(16)+"000000000").substr(2,8);return t?"-"+e.substr(0,4)+"-"+e.substr(4,4):e};return t()+t(!0)+t(!0)+t()}};export default Be;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default class
|
|
1
|
+
export default class Ae{constructor(t,e){this.td="undefined"==typeof window?self:window,this.ed=t,this.nd=e}od(){if("indexedDB"in this.td)return this.td.indexedDB}rd(){try{if(null==this.od())return!1;if(this.od().open("Braze IndexedDB Support Test"),"undefined"!=typeof window){const t=window.chrome||window.browser||window.msBrowser;if(t&&t.runtime&&t.runtime.id)return this.nd.info("Not using IndexedDB for storage because we are running inside an extension"),!1}return!0}catch(t){return this.nd.info("Not using IndexedDB for storage due to following error: "+t),!1}}dd(t,e){const n=this.od().open(this.ed.sd,this.ed.VERSION);if(null==n)return"function"==typeof e&&e(),!1;const o=this;return n.onupgradeneeded=t=>{o.nd.info("Upgrading indexedDB "+o.ed.sd+" to v"+o.ed.VERSION+"...");const e=t.target.result;for(const t in o.ed.Pt)o.ed.Pt.hasOwnProperty(t)&&!e.objectStoreNames.contains(o.ed.Pt[t])&&e.createObjectStore(o.ed.Pt[t])},n.onsuccess=n=>{const i=n.target.result;i.onversionchange=()=>{i.close(),"function"==typeof e&&e(),o.nd.error("Needed to close the database unexpectedly because of an upgrade in another tab")},t(i)},n.onerror=t=>(o.nd.info("Could not open indexedDB "+o.ed.sd+" v"+o.ed.VERSION+": "+t.target.errorCode),"function"==typeof e&&e(),!0),!0}setItem(t,e,n,o,i){if(!this.rd())return"function"==typeof i&&i(),!1;const r=this;return this.dd((d=>{if(!d.objectStoreNames.contains(t))return r.nd.error("Could not store object "+e+" in "+t+" on indexedDB "+r.ed.sd+" - "+t+" is not a valid objectStore"),void("function"==typeof i&&i());const s=d.transaction([t],"readwrite").objectStore(t).put(n,e);s.onerror=()=>{r.nd.error("Could not store object "+e+" in "+t+" on indexedDB "+r.ed.sd),"function"==typeof i&&i()},s.onsuccess=()=>{"function"==typeof o&&o()}}),i)}getItem(t,e,n){if(!this.rd())return!1;const o=this;return this.dd((i=>{if(!i.objectStoreNames.contains(t))return void o.nd.error("Could not retrieve object "+e+" in "+t+" on indexedDB "+o.ed.sd+" - "+t+" is not a valid objectStore");const r=i.transaction([t],"readonly").objectStore(t).get(e);r.onerror=()=>{o.nd.error("Could not retrieve object "+e+" in "+t+" on indexedDB "+o.ed.sd)},r.onsuccess=t=>{const e=t.target.result;null!=e&&n(e)}}))}hr(t,e,n){if(!this.rd())return"function"==typeof n&&n(),!1;const o=this;return this.dd((i=>{if(!i.objectStoreNames.contains(t))return o.nd.error("Could not retrieve last record from "+t+" on indexedDB "+o.ed.sd+" - "+t+" is not a valid objectStore"),void("function"==typeof n&&n());const r=i.transaction([t],"readonly").objectStore(t).openCursor(null,"prev");r.onerror=()=>{o.nd.error("Could not open cursor for "+t+" on indexedDB "+o.ed.sd),"function"==typeof n&&n()},r.onsuccess=t=>{const o=t.target.result;null!=o&&null!=o.value&&null!=o.key?e(o.key,o.value):"function"==typeof n&&n()}}),n)}br(t,e){if(!this.rd())return!1;const n=this;return this.dd((o=>{if(!o.objectStoreNames.contains(t))return void n.nd.error("Could not delete record "+e+" from "+t+" on indexedDB "+n.ed.sd+" - "+t+" is not a valid objectStore");o.transaction([t],"readwrite").objectStore(t).delete(e).onerror=()=>{n.nd.error("Could not delete record "+e+" from "+t+" on indexedDB "+n.ed.sd)}}))}Jt(t,e){if(!this.rd())return!1;const n=this;return this.dd((o=>{if(!o.objectStoreNames.contains(t))return void n.nd.error("Could not retrieve objects from "+t+" on indexedDB "+n.ed.sd+" - "+t+" is not a valid objectStore");const i=o.transaction([t],"readwrite").objectStore(t),r=i.openCursor(),d=[];r.onerror=()=>{d.length>0?(n.nd.info("Cursor closed midway through for "+t+" on indexedDB "+n.ed.sd),e(d)):n.nd.error("Could not open cursor for "+t+" on indexedDB "+n.ed.sd)},r.onsuccess=t=>{const n=t.target.result;if(null!=n){if(null!=n.value&&null!=n.key){i.delete(n.key).onsuccess=()=>{d.push(n.value)}}n.continue()}else d.length>0&&e(d)}}))}clearData(){if(!this.rd())return!1;const t=[];for(const e in this.ed.Pt)this.ed.Pt.hasOwnProperty(e)&&this.ed.Pt[e]!==this.ed.Pt.oe&&t.push(this.ed.Pt[e]);const e=this;return this.dd((function(n){const o=n.transaction(t,"readwrite");for(let n=0;n<t.length;n++){const i=t[n];o.objectStore(i).clear().onerror=function(){e.nd.error("Could not clear "+this.source.name+" on indexedDB "+e.ed.sd)}}o.onerror=function(){e.nd.error("Could not clear object stores on indexedDB "+e.ed.sd)}}))}}Ae.ep={xt:{sd:"AppboyServiceWorkerAsyncStorage",VERSION:6,Pt:{jl:"data",jr:"pushClicks",Nr:"pushSubscribed",ud:"fallbackDevice",Mt:"cardUpdates",oe:"optOut",$r:"pendingData",Qn:"sdkAuthenticationSignature"},se:1}};
|
package/shared-lib/logger.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Ge={init:function(n){void 0===n&&void 0!==Ge.zg||(Ge.zg=!!n),Ge.Dg||(Ge.Dg=!0)},destroy:function(){Ge.Dg=!1,Ge.zg=void 0,Ge.nd=void 0},setLogger:function(n){"function"==typeof n?(Ge.init(),Ge.nd=n):Ge.info("Ignoring setLogger call since logger is not a function")},toggleLogging:function(){Ge.init(),Ge.zg?(console.log("Disabling Braze logging"),Ge.zg=!1):(console.log("Enabled Braze logging"),Ge.zg=!0)},info:function(n){if(Ge.zg){const o="Braze: "+n;null!=Ge.nd?Ge.nd(o):console.log(o)}},warn:function(n){if(Ge.zg){const o="Braze SDK Warning: "+n+" (v4.0.4)";null!=Ge.nd?Ge.nd(o):console.warn(o)}},error:function(n){if(Ge.zg){const o="Braze SDK Error: "+n+" (v4.0.4)";null!=Ge.nd?Ge.nd(o):console.error(o)}}};export default Ge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default{
|
|
1
|
+
export default{ho:"allowCrawlerActivity",lo:"baseUrl",uo:"noCookies",po:"devicePropertyAllowlist",ra:"disablePushTokenMaintenance",co:"enableLogging",mo:"enableSdkAuthentication",ta:"manageServiceWorkerExternally",Eo:"minimumIntervalBetweenTriggerActionsInSeconds",_o:"sessionTimeoutInSeconds",fo:"appVersion",ea:"serviceWorkerLocation",na:"safariWebsitePushId",Mn:"localization",Fe:"contentSecurityNonce",Io:"enableHtmlInAppMessages",Ao:"allowUserSuppliedJavascript",Be:"inAppMessageZIndex",Ge:"openInAppMessagesInNewTab",en:"openNewsFeedCardsInNewTab",Ki:"requireExplicitInAppMessageDismissal",So:"doNotLoadFontAwesome",do:"sdkFlavor",tn:"openCardsInNewTab"};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import{logDeprecationWarning as y}from"../util/deprecation-utils.js";export function logContentCardsDisplayed(){if(e.rr())return y("logContentCardsDisplayed","method"),!0}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import g from"./content-cards-provider-factory.js";export function subscribeToContentCardsUpdates(r){if(!e.rr())return;const t=g.er(),n=t.Ps(r);if(!t.Kt()){const r=e.
|
|
1
|
+
import e from"../managers/braze-instance.js";import g from"./content-cards-provider-factory.js";export function subscribeToContentCardsUpdates(r){if(!e.rr())return;const t=g.er(),n=t.Ps(r);if(!t.Kt()){const r=e.mr().cr((()=>{t.Ts()}));t.Vt(r)}return n}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../../managers/braze-instance.js";import{destroyFeedHtml as
|
|
1
|
+
import e from"../../managers/braze-instance.js";import{destroyFeedHtml as z}from"../../common/feed-display.js";export function hideContentCards(n){if(!e.rr())return;const o=document.querySelectorAll(".ab-feed");for(let e=0;e<o.length;e++)(null==n||null!=n&&o[e].parentNode===n)&&z(o[e])}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import{ContentCards,
|
|
1
|
+
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import{ContentCards,subscribeToContentCardsUpdates}from"../index.js";import g from"../content-cards-provider-factory.js";import{destroyFeedHtml as z,detectFeedImpressions as T,feedToHtml as N,LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE as q,refreshFeed as I,registerFeedSubscriptionId as L,updateFeedCards as M}from"../../common/feed-display.js";import{setCardHeight as $}from"../../Card/display/card-display.js";import{setupFeedUI as k}from"../../ui/js/index.js";import r from"../../../shared-lib/braze-shared-lib.js";export function showContentCards(n,t){if(!e.rr())return;k();let o=!1;null==n&&(n=document.body,o=!0);const a=e.nn(D.tn)||e.nn(D.en)||!1;let i=g.er().ys(!1);"function"==typeof t&&M(i,t(i.cards.slice()),i.lastUpdated,null,a);const s=N(i,a),f=g.er();(null==i.lastUpdated||(new Date).valueOf()-i.lastUpdated.valueOf()>ContentCards.ur)&&(null==f.Bt()||(new Date).valueOf()-f.Bt()>ContentCards.ur)&&(r.D.info(`Cached content cards were older than max TTL of ${ContentCards.ur} ms, requesting an update from the server.`),I(i,s),f.Ht((new Date).valueOf()));const l=(new Date).valueOf(),c=subscribeToContentCardsUpdates((function(n){const e=s.querySelectorAll(".ab-refresh-button")[0];if(null!=e){let n=500;const t=parseInt(s.getAttribute(q));isNaN(t)?n-=(new Date).valueOf()-l:n-=(new Date).valueOf()-t,setTimeout((function(){e.className=e.className.replace(/fa-spin/g,"")}),Math.max(n,0))}let o=n.cards;"function"==typeof t&&(o=t(o.slice())),M(i,o,n.lastUpdated,s,a)}));L(c,s);const u=function(n){const t=n.querySelectorAll(".ab-feed");let e=null;for(let o=0;o<t.length;o++)t[o].parentNode===n&&(e=t[o]);null!=e?(z(e),e.parentNode.replaceChild(s,e)):n.appendChild(s),setTimeout((function(){s.className=s.className.replace("ab-hide","ab-show")}),0),o&&s.focus(),T(i,s),$(i.cards,n)};var m;null!=n?u(n):window.onload=(m=window.onload,function(){"function"==typeof m&&m(),u(document.body)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import B from"../managers/braze-instance.js";import BrazeSdkMetadata from"./braze-sdk-metadata.js";import{isArray as p,validateValueIsFromEnum as K}from"../util/code-utils.js";import r from"../../shared-lib/braze-shared-lib.js";export function addSdkMetadata(a){if(B.rr()){if(!p(a))return r.D.error("Cannot set SDK metadata because metadata is not an array."),!1;for(const t of a)if(!K(BrazeSdkMetadata,t,"sdkMetadata contained an invalid value.","BrazeSdkMetadata"))return!1;return B.nr().addSdkMetadata(a),!0}}
|
package/src/Core/change-user.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{getByteLength as U}from"../util/string-utils.js";import r from"../../shared-lib/braze-shared-lib.js";import{User}from"../User/index.js";import{validateStandardString as R}from"../util/validation-utils.js";export function changeUser(s,i){return!!e.rr()&&(null==s||0===s.length||s!=s?(r.D.error("changeUser requires a non-empty userId."),!1):U(s)>User.ee?(r.D.error(`Rejected user id "${s}" because it is longer than ${User.ee} bytes.`),!1):!(null!=i&&!R(i,"set signature for new user","signature"))&&void e.
|
|
1
|
+
import e from"../managers/braze-instance.js";import{getByteLength as U}from"../util/string-utils.js";import r from"../../shared-lib/braze-shared-lib.js";import{User}from"../User/index.js";import{validateStandardString as R}from"../util/validation-utils.js";export function changeUser(s,i){return!!e.rr()&&(null==s||0===s.length||s!=s?(r.D.error("changeUser requires a non-empty userId."),!1):U(s)>User.ee?(r.D.error(`Rejected user id "${s}" because it is longer than ${User.ee} bytes.`),!1):!(null!=i&&!R(i,"set signature for new user","signature"))&&void e.mr().changeUser(s.toString(),e.re(),i))}
|
package/src/Core/disable-sdk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";import A,{STORAGE_KEYS as o}from"../managers/storage-manager.js";export function disableSDK(){null!=e.mr()&&e.mr().requestImmediateDataFlush();const n=new A.ne(null,!0);n.store(o.ae,"This-cookie-will-expire-in-"+n.ie());const a=r.Ft.xt;new r.qt(a,r.D).setItem(a.Pt.oe,a.se,!0),e.destroy(!1),e.le(!0)}
|
package/src/Core/enable-sdk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";import A,{STORAGE_KEYS as o}from"../managers/storage-manager.js";export function enableSDK(){new A.ne(null,!0).remove(o.ae);const a=r.Ft.xt;new r.qt(a,r.D).br(a.Pt.oe,a.se),e.destroy(!1),e.le(!1)}
|
package/src/Core/get-user.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";export function getUser(){if(e.rr())return e.
|
|
1
|
+
import e from"../managers/braze-instance.js";export function getUser(){if(e.rr())return e.gr()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"../../shared-lib/braze-shared-lib.js";import e from"../managers/braze-instance.js";import
|
|
1
|
+
import r from"../../shared-lib/braze-shared-lib.js";import e from"../managers/braze-instance.js";import F from"../util/braze-actions.js";import{decodeBrazeActions as J}from"../util/string-utils.js";import{BRAZE_ACTION_URI_REGEX as O,isValidBrazeActionJson as P}from"../util/validation-utils.js";import{WindowUtils as G}from"../util/window-utils.js";import{getUser as H}from"./get-user.js";export function _getDecodedBrazeAction(e){try{let o=e.match(O)[0].length;const t=e.substring(o);if(o>e.length-1||!t)return void r.D.error(`Did not find base64 encoded brazeAction in url to process : ${e}`);const i=J(t);return i?JSON.parse(i):void r.D.error(`Failed to decode base64 encoded brazeAction: ${t}`)}catch(o){return void r.D.error(`Failed to process brazeAction URL ${e} : ${o.message}`)}}export function _handleBrazeAction(o,t,i){if(e.rr())if(O.test(o)){const e=_getDecodedBrazeAction(o);if(!e)return;const t=async e=>{if(!P(e))return void r.D.error(`Decoded Braze Action json is invalid: ${JSON.stringify(e,null,2)}`);const o=e[F.properties.type];if(o===F.types.de)for(const o of e[F.properties.ue])t(o);else{const t=e[F.properties.fe];let i,n;switch(o){case F.types.logCustomEvent:i=await import("./log-custom-event.js"),i.logCustomEvent.apply(null,Array.prototype.slice.call(t));break;case F.types.requestPushPermission:i=await import("../Push/request-push-permission.js"),i.requestPushPermission();break;case F.types.setEmailNotificationSubscriptionType:case F.types.setPushNotificationSubscriptionType:case F.types.setCustomUserAttribute:case F.types.addToSubscriptionGroup:case F.types.removeFromSubscriptionGroup:case F.types.addToCustomAttributeArray:case F.types.removeFromCustomAttributeArray:n=H(),n[o].apply(n,Array.prototype.slice.call(t));break;case F.types.me:case F.types.pe:G.openUri.apply(null,Array.prototype.slice.call(t));break;default:r.D.info(`Ignoring unknown Braze Action: ${o}`)}}};t(e)}else G.openUri(o,i,t)}export function handleBrazeAction(e,o){_handleBrazeAction(e,o)}
|
package/src/Core/is-disabled.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import A,{STORAGE_KEYS as o}from"../managers/storage-manager.js";export function isDisabled(){return!!new A.ne(null,!0).lr(o.ae)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import s from"../common/event-logger.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import s from"../common/event-logger.js";import r from"../../shared-lib/braze-shared-lib.js";import Q from"../triggers/models/trigger-events.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";import{validateCustomProperties as W,validateCustomString as X}from"../util/validation-utils.js";export function logCustomEvent(t,o){if(!e.rr())return!1;if(null==t||t.length<=0)return r.D.error(`logCustomEvent requires a non-empty eventName, got "${t}". Ignoring event.`),!1;if(!X(t,"log custom event","the event name"))return!1;const[n,i]=W(o,"logCustomEvent","eventProperties",`log custom event "${t}"`,"event");if(!n)return!1;if(e.ir().ge(t))return r.D.info(`Custom Event "${t}" is blocklisted, ignoring.`),!1;const m=s.G(r.A.CustomEvent,{n:t,p:i});if(m.S){r.D.info(`Logged custom event "${t}".`);for(const e of m.ve)V.er().je(Q.be,[t,o],e)}return m.S}
|
package/src/Core/log-purchase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{MAX_PURCHASE_QUANTITY as Z}from"../common/constants.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import{MAX_PURCHASE_QUANTITY as Z}from"../common/constants.js";import r from"../../shared-lib/braze-shared-lib.js";import Q from"../triggers/models/trigger-events.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";import{validateCustomProperties as W,validateCustomString as X}from"../util/validation-utils.js";import s from"../common/event-logger.js";export function logPurchase(o,i,t,n,D){if(!e.rr())return!1;if(null==t&&(t="USD"),null==n&&(n=1),null==o||o.length<=0)return r.D.error(`logPurchase requires a non-empty productId, got "${o}", ignoring.`),!1;if(!X(o,"log purchase","the purchase name"))return!1;let a=parseFloat(i);if(isNaN(a))return r.D.error(`logPurchase requires a numeric price, got ${i}, ignoring.`),!1;a=a.toFixed(2);const g=parseInt(n);if(isNaN(g))return r.D.error(`logPurchase requires an integer quantity, got ${n}, ignoring.`),!1;if(g<1||g>Z)return r.D.error(`logPurchase requires a quantity >1 and <${Z}, got ${g}, ignoring.`),!1;t=t.toUpperCase();if(-1===["AED","AFN","ALL","AMD","ANG","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BIF","BMD","BND","BOB","BRL","BSD","BTC","BTN","BWP","BYR","BZD","CAD","CDF","CHF","CLF","CLP","CNY","COP","CRC","CUC","CUP","CVE","CZK","DJF","DKK","DOP","DZD","EEK","EGP","ERN","ETB","EUR","FJD","FKP","GBP","GEL","GGP","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","ILS","IMP","INR","IQD","IRR","ISK","JEP","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LTL","LVL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRO","MTL","MUR","MVR","MWK","MXN","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SLL","SOS","SRD","STD","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","UYU","UZS","VEF","VND","VUV","WST","XAF","XAG","XAU","XCD","XDR","XOF","XPD","XPF","XPT","YER","ZAR","ZMK","ZMW","ZWL"].indexOf(t))return r.D.error(`logPurchase requires a valid currencyCode, got ${t}, ignoring.`),!1;const[u,P]=W(D,"logPurchase","purchaseProperties",`log purchase "${o}"`,"purchase");if(!u)return!1;if(e.ir().Dr(o))return r.D.info(`Purchase "${o}" is blocklisted, ignoring.`),!1;const R=s.G(r.A.Pr,{pid:o,c:t,p:a,q:g,pr:P});if(R.S){r.D.info(`Logged ${g} purchase${g>1?"s":""} of "${o}" for ${t} ${a}.`);for(const r of R.ve)V.er().je(Q.Rr,[o,D],r)}return R.S}
|
package/src/Core/open-session.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";import Q from"../triggers/models/trigger-events.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";export function openSession(){if(!e.rr())return;e.mr().openSession();const i=r.Ft.xt,o=new r.qt(i,r.D);o.hr(i.Pt.jr,(function(t,n){const s=n.lastClick,c=n.trackingString;r.D.info(`Firing push click trigger from ${c} push click at ${s}`);const g=e.mr().kr(s,c),f=function(){V.er().je(Q.vr,[c],g)};e.mr().zr(f,f),o.br(i.Pt.jr,t)})),o.Jt(i.Pt.$r,(function(r){e.mr().wr(r)}))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";export function requestImmediateDataFlush(a){e.rr()&&e.
|
|
1
|
+
import e from"../managers/braze-instance.js";export function requestImmediateDataFlush(a){e.rr()&&e.mr().requestImmediateDataFlush(a)}
|
package/src/Core/wipe-data.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{keys as
|
|
1
|
+
import e from"../managers/braze-instance.js";import{keys as Y}from"../util/code-utils.js";import r from"../../shared-lib/braze-shared-lib.js";export function wipeData(){if(null==e.l())throw new Error("Braze must be initialized before calling methods.");e.l().clearData();const o=Y(r.Ft);for(let e=0;e<o.length;e++){const i=o[e],t=r.Ft[i];new r.qt(t,r.D).clearData()}if(e.rr())for(const r of e.re())r.clearData(!0)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import ee from"./feed-provider.js";const re={t:!1,provider:null,er:()=>(re.o(),re.provider||(re.provider=new ee(e.l(),e.mr()),e.ar(re.provider)),re.provider),o:()=>{re.t||(e.u(re),re.t=!0)},destroy:()=>{re.provider=null,re.t=!1}};export default re;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import C from"../common/base-provider.js";import e from"../managers/braze-instance.js";import Feed from"./feed.js";import{newCardFromFeedJson as tt,newCardFromSerializedValue as _}from"../Card/util/card-factory.js";import{rehydrateDateAfterJsonization as w}from"../util/date-utils.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import u from"../managers/subscription-manager.js";export default class
|
|
1
|
+
import C from"../common/base-provider.js";import e from"../managers/braze-instance.js";import Feed from"./feed.js";import{newCardFromFeedJson as tt,newCardFromSerializedValue as _}from"../Card/util/card-factory.js";import{rehydrateDateAfterJsonization as w}from"../util/date-utils.js";import{STORAGE_KEYS as o}from"../managers/storage-manager.js";import u from"../managers/subscription-manager.js";export default class ee extends C{constructor(t,s){super(),this.h=t,this.Is=s,this.vt=new u,e.Ut(this.vt),this.zt()}zt(){const t=this.h.I(o.q.Ks)||[],s=[];for(let i=0;i<t.length;i++){const e=_(t[i]);null!=e&&s.push(e)}this.Xt=s,this.Os=w(this.h.I(o.q.Qs))}Vs(t){const s=[];let i=null;const e=this.h.I(o.q.P)||{},r={};for(let h=0;h<t.length;h++){i=t[h];const o=tt(i);null!=o&&(e[o.id]&&(o.viewed=!0,r[o.id]=!0),s.push(o))}this.h.B(o.q.P,r),this.Xt=s,this.Ss(),this.Os=new Date,this.h.B(o.q.Qs,this.Os)}Ss(){const t=[];for(let s=0;s<this.Xt.length;s++)t.push(this.Xt[s].ss());this.h.B(o.q.Ks,t)}_s(t){null!=t&&t.feed&&(this.zt(),this.Vs(t.feed),this.vt.Nt(new Feed(this.Xt.slice(),this.Os)))}Ws(){this.zt();const t=[],s=new Date;for(let i=0;i<this.Xt.length;i++)(null==this.Xt[i].expiresAt||this.Xt[i].expiresAt>=s)&&t.push(this.Xt[i]);return new Feed(t,this.Os)}Ts(){this.Is.requestFeedRefresh()}Ps(t){return this.vt.Et(t)}clearData(t){null==t&&(t=!1),this.Xt=[],this.Os=null,t&&(this.h.$s(o.q.Ks),this.h.$s(o.q.Qs)),this.vt.Nt(new Feed(this.Xt.slice(),this.Os))}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import re from"./feed-provider-factory.js";export function getCachedFeed(){if(e.rr())return re.er().Ws()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";export function logFeedDisplayed(){if(e.rr())return e.nr().
|
|
1
|
+
import e from"../managers/braze-instance.js";import r from"../../shared-lib/braze-shared-lib.js";export function logFeedDisplayed(){if(e.rr())return e.nr().yr(r.qr.Fr).S}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import re from"./feed-provider-factory.js";export function requestFeedRefresh(){if(e.rr())return re.er().Ts()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import re from"./feed-provider-factory.js";export function subscribeToFeedUpdates(r){if(e.rr())return re.er().Ps(r)}
|
package/src/Feed/ui/hide-feed.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../../managers/braze-instance.js";import{destroyFeedHtml as
|
|
1
|
+
import e from"../../managers/braze-instance.js";import{destroyFeedHtml as z}from"../../common/feed-display.js";export function destroyFeed(){if(!e.rr())return;const o=document.querySelectorAll(".ab-feed");for(let e=0;e<o.length;e++)z(o[e])}
|
package/src/Feed/ui/show-feed.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import{destroyFeedHtml as
|
|
1
|
+
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import{destroyFeedHtml as z,detectFeedImpressions as T,feedToHtml as N,LAST_REQUESTED_REFRESH_DATA_ATTRIBUTE as q,refreshFeed as I,registerFeedSubscriptionId as L,updateFeedCards as M}from"../../common/feed-display.js";import{Feed,logFeedDisplayed,subscribeToFeedUpdates}from"../index.js";import re from"../feed-provider-factory.js";import{intersection as te}from"../../util/code-utils.js";import{setCardHeight as $}from"../../Card/display/card-display.js";import{setupFeedUI as k}from"../../ui/js/index.js";import r from"../../../shared-lib/braze-shared-lib.js";export function showFeed(t,n,o){if(!e.rr())return;k();const s=(e,t)=>{if(null==t)return e;const n=[];for(let e=0;e<t.length;e++)n.push(t[e].toLowerCase());const o=[];for(let t=0;t<e.length;t++){const r=[];for(let n=0;n<e[t].categories.length;n++)r.push(e[t].categories[n].toLowerCase());te(r,n).length>0&&o.push(e[t])}return o},i=e.nn(D.tn)||e.nn(D.en)||!1;let l=!1;null==t&&(t=document.body,l=!0);let a=!1,f=null;null==n?(f=re.er().Ws(),M(f,s(f.cards,o),f.lastUpdated,null,i),a=!0):f=new Feed(s(n,o),new Date);const u=N(f,i);if(a){(null==f.lastUpdated||(new Date).valueOf()-f.lastUpdated.valueOf()>Feed.ur)&&(r.D.info(`Cached feed was older than max TTL of ${Feed.ur} ms, requesting an update from the server.`),I(f,u));const e=(new Date).valueOf(),t=subscribeToFeedUpdates((function(t){const n=u.querySelectorAll(".ab-refresh-button")[0];if(null!=n){let t=500;const o=parseInt(u.getAttribute(q));isNaN(o)?t-=(new Date).valueOf()-e:t-=(new Date).valueOf()-o,setTimeout((function(){n.className=n.className.replace(/fa-spin/g,"")}),Math.max(t,0))}M(f,s(t.cards,o),t.lastUpdated,u,i)}));L(t,u)}const m=e=>{const t=e.querySelectorAll(".ab-feed");let n=null;for(let o=0;o<t.length;o++)t[o].parentNode===e&&(n=t[o]);null!=n?(z(n),n.parentNode.replaceChild(u,n)):e.appendChild(u),setTimeout((function(){u.className=u.className.replace("ab-hide","ab-show")}),0),l&&u.focus(),logFeedDisplayed(),T(f,u),$(f.cards,e)};var c;null!=t?m(t):window.onload=(c=window.onload,function(){"function"==typeof c&&c(),m(document.body)})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{attachInAppMessageCSS as nt}from"../../ui/js/iam-css.js";import et from"../../util/browser-detector.js";import{logInAppMessageHtmlClick}from"../index.js";import{getUser as
|
|
1
|
+
import{attachInAppMessageCSS as nt}from"../../ui/js/iam-css.js";import et from"../../util/browser-detector.js";import{logInAppMessageHtmlClick}from"../index.js";import{getUser as H}from"../../Core/get-user.js";import{InAppMessage}from"../index.js";import{keys as Y}from"../../util/code-utils.js";import{OperatingSystems as ot}from"../../util/device-constants.js";import{parseQueryStringKeyValues as st}from"../../util/url-utils.js";import{WindowUtils as G}from"../../util/window-utils.js";export default function rt(t,n,e,o,s,r){const i=document.createElement("iframe");i.setAttribute("title","Modal Message"),s&&(i.style.zIndex=s+1);const u=n=>{const e=n.getAttribute("href"),s=n.onclick;return r=>{if(null!=s&&"function"==typeof s&&!1===s())return;let u=st(e).abButtonId;if(null!=u&&""!==u||(u=n.getAttribute("id")),null!=e&&""!==e&&0!==e.indexOf("#")){const s="blank"===(n.getAttribute("target")||"").toLowerCase().replace("_",""),c=o||t.openTarget===InAppMessage.OpenTarget.BLANK||s,a=()=>{logInAppMessageHtmlClick(t,u,e),G.openUri(e,c,r)};c?a():t.on(i,a)}else logInAppMessageHtmlClick(t,u,e);return r.stopPropagation(),!1}},c=(t,n,e)=>{const o=`([\\w]+)\\s*=\\s*document.createElement\\(['"]${e}['"]\\)`,s=t.match(new RegExp(o));if(s){const e=`${s[1]}.setAttribute("nonce", "${n}")`;return`${t.slice(0,s.index+s[0].length)};${e};${t.slice(s.index+s[0].length)}`}return null};if(i.onload=()=>{let o=null;if(null!=r){o=document.createElement("html"),o.innerHTML=t.message;const n=o.getElementsByTagName("style");for(let t=0;t<n.length;t++)n[t].setAttribute("nonce",r);const e=o.getElementsByTagName("script");for(let t=0;t<e.length;t++){e[t].setAttribute("nonce",r),e[t].innerHTML=e[t].innerHTML.replace(/<style>/g,`<style nonce='${r}'>`);const n=c(e[t].innerHTML,r,"script");n&&(e[t].innerHTML=n);const o=c(e[t].innerHTML,r,"style");o&&(e[t].innerHTML=o)}}i.contentWindow.focus(),i.contentWindow.document.write(o?o.innerHTML:t.message);const s=i.contentWindow.document.getElementsByTagName("head")[0];if(null!=s){if(nt(s),t.sn()){const n=document.createElement("style");n.innerHTML=t.css,n.id=t.rn(),null!=r&&n.setAttribute("nonce",r),s.appendChild(n)}const n=i.contentWindow.document.createElement("base");n.setAttribute("target","_parent"),s.appendChild(n)}const a=i.contentWindow.document.getElementsByTagName("title");a.length>0&&i.setAttribute("title",a[0].textContent);const l={closeMessage:function(){t.on(i)},logClick:function(){const n=[t,...arguments];logInAppMessageHtmlClick.apply(t,Array.prototype.slice.call(n))},display:{},web:{}},requestPushPermission=function(){return function(){const t=arguments;import("../../Push/request-push-permission.js").then((n=>{n.requestPushPermission.apply(null,Array.prototype.slice.call(t))}))}},m={requestImmediateDataFlush:async function(){const t=arguments,n=await import("../../Core/request-immediate-data-flush.js");n.requestImmediateDataFlush.apply(null,Array.prototype.slice.call(t))},logCustomEvent:async function(){const t=arguments,n=await import("../../Core/log-custom-event.js");n.logCustomEvent.apply(null,Array.prototype.slice.call(t))},logPurchase:async function(){const t=arguments,n=await import("../../Core/log-purchase.js");n.logPurchase.apply(null,Array.prototype.slice.call(t))},unregisterPush:async function(){const t=arguments,n=await import("../../Push/unregister-push.js");n.unregisterPush.apply(null,Array.prototype.slice.call(t))},requestPushPermission:requestPushPermission()},f=function(t){return function(){m[t].apply(null,Array.prototype.slice.call(arguments))}};for(const t of Y(m))l[t]=f(t);const d=["setFirstName","setLastName","setEmail","setGender","setDateOfBirth","setCountry","setHomeCity","setEmailNotificationSubscriptionType","setLanguage","addAlias","setPushNotificationSubscriptionType","setPhoneNumber","setCustomUserAttribute","addToCustomAttributeArray","removeFromCustomAttributeArray","incrementCustomUserAttribute","setCustomLocationAttribute","addToSubscriptionGroup","removeFromSubscriptionGroup"],p=function(t){return function(){const n=H();n[t].apply(n,Array.prototype.slice.call(arguments))}},y={};for(let t=0;t<d.length;t++)y[d[t]]=p(d[t]);l.getUser=function(){return y};const b={showFeed:n},h=function(n){return function(){const e=arguments;t.on(i,(function(){b[n].apply(null,Array.prototype.slice.call(e))}))}};for(const t of Y(b))l.display[t]=h(t);const g={registerAppboyPushMessages:requestPushPermission()},A=function(t){return function(){g[t].apply(null,Array.prototype.slice.call(arguments))}};for(const t of Y(g))l.web[t]=A(t);if(i.contentWindow.appboyBridge=l,i.contentWindow.brazeBridge=l,t.un!==InAppMessage.es.cn){const t=i.contentWindow.document.getElementsByTagName("a");for(let n=0;n<t.length;n++)t[n].onclick=u(t[n]);const n=i.contentWindow.document.getElementsByTagName("button");for(let t=0;t<n.length;t++)n[t].onclick=u(n[t])}const j=i.contentWindow.document.body;if(null!=j){t.an()&&(j.id=t.htmlId);const n=document.createElement("hidden");n.onclick=l.closeMessage,n.className="ab-programmatic-close-button",j.appendChild(n)}i.contentWindow.dispatchEvent(new CustomEvent("ab.BridgeReady")),-1!==i.className.indexOf("ab-start-hidden")&&(i.className=i.className.replace("ab-start-hidden",""),e(i)),document.activeElement!==i&&i.focus()},i.className="ab-in-app-message ab-start-hidden ab-html-message ab-modal-interactions",et.OS===ot.ln){const n=document.createElement("div");return n.className="ab-ios-scroll-wrapper",n.appendChild(i),t.mn=n,n}return t.mn=i,i}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addPassiveEventListener as oe,buildSvg as ne,detectSwipe as d,DIRECTIONS as c}from"../../util/dom-utils.js";import{createCloseButton as i}from"../../util/component-utils.js";import{isTransparent as ie,toRgba as se}from"../../util/color-utils.js";import{FullScreenMessage,HtmlMessage,InAppMessage,logInAppMessageClick,ModalMessage,SlideUpMessage}from"../index.js";import{_handleBrazeAction as m}from"../../Core/handle-braze-action.js";import rt from"./html-message-to-html.js";import ce from"./modal-utils.js";import r from"../../../shared-lib/braze-shared-lib.js";export default function
|
|
1
|
+
import{addPassiveEventListener as oe,buildSvg as ne,detectSwipe as d,DIRECTIONS as c}from"../../util/dom-utils.js";import{createCloseButton as i}from"../../util/component-utils.js";import{isTransparent as ie,toRgba as se}from"../../util/color-utils.js";import{FullScreenMessage,HtmlMessage,InAppMessage,logInAppMessageClick,ModalMessage,SlideUpMessage}from"../index.js";import{_handleBrazeAction as m}from"../../Core/handle-braze-action.js";import rt from"./html-message-to-html.js";import ce from"./modal-utils.js";import r from"../../../shared-lib/braze-shared-lib.js";export default function de(e,t,o,a,n,s){if(e.he=document.activeElement,e instanceof HtmlMessage)return rt(e,t,o,a,n,s);const l=function(e,t,o,a,n){const s=document.createElement("div");s.className="ab-in-app-message ab-start-hidden ab-background",n&&(s.style.zIndex=n+1),e.we()&&(s.className+=" ab-modal-interactions",s.setAttribute("tabindex","-1")),e.sn()||(s.style.color=se(e.textColor),s.style.backgroundColor=se(e.backgroundColor),ie(e.backgroundColor)&&(s.className+=" ab-no-shadow"));const c=()=>{-1!==s.className.indexOf("ab-start-hidden")&&(s.className=s.className.replace("ab-start-hidden",""),o(s))};e.imageStyle===InAppMessage.ImageStyle.GRAPHIC&&(s.className+=" graphic"),e.orientation===InAppMessage.Orientation.LANDSCAPE&&(s.className+=" landscape"),0===e.buttons.length&&(e.clickAction!==InAppMessage.ClickAction.NONE&&(s.className+=" ab-clickable"),s.onclick=o=>(e.on(s,(()=>{logInAppMessageClick(e),e.clickAction===InAppMessage.ClickAction.URI?m(e.uri,o,a||e.openTarget===InAppMessage.OpenTarget.BLANK):e.clickAction===InAppMessage.ClickAction.NEWS_FEED&&t()})),o.stopPropagation(),!1));const d=i("Close Message",e.sn()?void 0:se(e.closeButtonColor),(()=>{e.on(s)}));s.appendChild(d),n&&(d.style.zIndex=n+2);const l=document.createElement("div");l.className="ab-message-text";const b=(e.messageAlignment||e.xe).toLowerCase();l.className+=" "+b+"-aligned";let u=!1;const f=document.createElement("div");if(f.className="ab-image-area",e.imageUrl){if(e.cropType===InAppMessage.CropType.CENTER_CROP){const t=document.createElement("span");t.className="ab-center-cropped-img",t.style.backgroundImage="url("+e.imageUrl+")",t.setAttribute("role","img"),t.setAttribute("aria-label","Modal Image"),e.ze(t),f.appendChild(t)}else{const t=document.createElement("img");t.setAttribute("src",e.imageUrl),e.ze(t),u=!0,t.onload=c,setTimeout(c,1e3),f.appendChild(t)}s.appendChild(f),l.className+=" ab-with-image"}else if(e.icon){f.className+=" ab-icon-area";const t=document.createElement("span");t.className="ab-icon",e.sn()||(t.style.backgroundColor=se(e.iconBackgroundColor),t.style.color=se(e.iconColor));const o=document.createElement("i");o.className="fa",o.appendChild(document.createTextNode(e.icon)),o.setAttribute("aria-hidden",!0),t.appendChild(o),f.appendChild(t),s.appendChild(f),l.className+=" ab-with-icon"}if(oe(l,"touchstart",(function(){})),e.header&&e.header.length>0){const t=document.createElement("h1");t.className="ab-message-header",e.Me=r.nt.et(),t.id=e.Me;const o=(e.headerAlignment||InAppMessage.TextAlignment.CENTER).toLowerCase();t.className+=" "+o+"-aligned",e.sn()||(t.style.color=se(e.headerTextColor)),t.appendChild(document.createTextNode(e.header)),l.appendChild(t)}return l.appendChild(e.ke()),s.appendChild(l),u||c(),e.mn=s,s}(e,t,o,a,n);if(e instanceof FullScreenMessage||e instanceof ModalMessage){const o=e instanceof FullScreenMessage?"ab-fullscreen":"ab-modal";l.className+=` ${o} ab-centered`,ce.Ce(e,t,l,a),ce.Le(l),ce.Ie(e.Me,l)}else if(e instanceof SlideUpMessage){l.className+=" ab-slideup";const t=l.getElementsByClassName("ab-close-button")[0];if(null!=t){const o=ne("0 0 11.38 19.44","M11.38 9.72l-9.33 9.72L0 17.3l7.27-7.58L0 2.14 2.05 0l9.33 9.72z",e.sn()?void 0:se(e.closeButtonColor));o.setAttribute("class","ab-chevron"),t.appendChild(o)}let o,a;d(l,c.ot,(e=>{l.className+=" ab-swiped-left",t.onclick(e)})),d(l,c.at,(e=>{l.className+=" ab-swiped-right",t.onclick(e)})),e.slideFrom===InAppMessage.SlideFrom.TOP?(o=c.Te,a=" ab-swiped-up"):(o=c.$e,a=" ab-swiped-down"),d(l,o,(e=>{l.className+=a,t.onclick(e)}))}return l}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import b from"../util/net.js";import e from"../managers/braze-instance.js";import{ControlMessage,HtmlMessage,InAppMessage,InAppMessageButton}from"./index.js";import s from"../common/event-logger.js";import{newInAppMessageFromJson as it}from"./in-app-message-factory.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 u from"../managers/subscription-manager.js";import ut from"../triggers/models/trigger.js";import{validateValueIsFromEnum as
|
|
1
|
+
import b from"../util/net.js";import e from"../managers/braze-instance.js";import{ControlMessage,HtmlMessage,InAppMessage,InAppMessageButton}from"./index.js";import s from"../common/event-logger.js";import{newInAppMessageFromJson as it}from"./in-app-message-factory.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 u from"../managers/subscription-manager.js";import ut from"../triggers/models/trigger.js";import{validateValueIsFromEnum as K}from"../util/code-utils.js";import{BRAZE_ACTION_URI_REGEX as O,isValidBrazeActionJson as P}from"../util/validation-utils.js";import F from"../util/braze-actions.js";import{_getDecodedBrazeAction as pt}from"../Core/handle-braze-action.js";export default class ge{constructor(t,i,s,r){this.jt=t,this.j=i,this.h=s,this.v=r,this.ii=new u,e.Ut(this.ii),this.ei=1e3,this.si=6e4}ri(){return this.ii}ni(t){return this.ii.Et(t)}oi(){return this.ai}li(t){this.ai=t}ui(i,e){if(!K(InAppMessage.pi,e,`${e} is not a valid in-app message display failure`,"InAppMessage.DisplayFailures"))return new t;const n={trigger_ids:[i],error_code:e};return s.G(r.A.ci,n)}G(i,e,n,o){const a=new t;let l;if(i instanceof ControlMessage)l={trigger_ids:[i.triggerId]};else{if(e===r.A.mi||i instanceof HtmlMessage&&e===r.A.fi){if(!i.k(o))return r.D.info("This in-app message has already received a click. Ignoring analytics event."),a}else if(e===r.A.gi){if(!i.R())return r.D.info("This in-app message has already received an impression. Ignoring analytics event."),a}l=this.hi(i)}return null==l?a:(null!=n&&(l.bid=n),s.G(e,l))}di(i,e){const n=new t;if(!i.k())return r.D.info("This in-app message button has already received a click. Ignoring analytics event."),n;const o=this.hi(e);return null==o?n:i.id===InAppMessageButton.yi?(r.D.info("This in-app message button does not have a tracking id. Not logging event to Braze servers."),n):(null!=i.id&&(o.bid=i.id),s.G(r.A.fi,o))}vi(t){const i=t=>{if(!P(t))return!1;const e=t[F.properties.type];if(e===F.types.de){let e=!1;for(const s of t[F.properties.ue])if(e=e||i(s),e)return!0;return!1}return e===F.types.requestPushPermission};if(!(t instanceof InAppMessage))return!1;const e=t.buttons;for(const t of e)if(t.clickAction===InAppMessage.ClickAction.URI&&O.test(t.uri)){const e=pt(t.uri);if(i(e))return!0}if(t.clickAction===InAppMessage.ClickAction.URI&&O.test(t.uri)){const e=pt(t.uri);return i(e)}return!1}bi(t,i,e,s){let n=this.jt.ji(!1,!1);n=this.jt.Ls(n),n.template={trigger_id:t.triggerId,trigger_event_type:i},null!=e&&(n.template.data=e.zi());const o=this.jt.Ns(n);this.jt.As(n,(()=>{b.Fs({url:`${this.jt.Js()}/template/`,data:n,headers:o,S:async i=>{if(!this.jt.qs(n,i,o))return this.ui(t.triggerId,InAppMessage.pi.Ii),void("function"==typeof t.Ai&&t.Ai());if(this.jt.Es(),null==i||null==i.templated_message)return void this.ui(t.triggerId,InAppMessage.pi.Ii);const e=i.templated_message;if(e.type!==ut.wi.Mi)return void this.ui(t.triggerId,InAppMessage.pi.Di);const s=it(e.data);if(null!=s){if(this.vi(s)){const i=(await import("../Push/push-manager-factory.js")).default.getPushManager();if(null!=i&&!i.Ti())return r.D.error("In-App Message contains a push prompt braze action, but is not eligible for a push prompt. Ignoring."),void("function"==typeof t.Ai&&t.Ai())}"function"==typeof t._i?t._i(s):this.ui(t.triggerId,InAppMessage.pi.Ii)}else this.ui(t.triggerId,InAppMessage.pi.Di)},error:r=>{let n=`getting user personalization for message ${t.triggerId}`;if((new Date).valueOf()-t.ki>t.Bi)this.ui(t.triggerId,InAppMessage.pi.Ii);else{const r=Math.min(t.Bi,this.si),o=this.ei;null==s&&(s=o);const a=Math.min(r,lt(o,3*s));n+=`. Retrying in ${a} ms`,setTimeout((()=>{this.bi(t,i,e,a)}),a)}this.jt.Ms(r,n)}})}))}hi(t){if(null==t.triggerId)return r.D.info("The in-app message has no analytics id. Not logging event to Braze servers."),null;const i={};return null!=t.triggerId&&(i.trigger_ids=[t.triggerId]),i}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{MUST_BE_IN_APP_MESSAGE_WARNING as rr}from"../common/constants.js";import{InAppMessage,InAppMessageButton}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import{MUST_BE_IN_APP_MESSAGE_WARNING as rr}from"../common/constants.js";import{InAppMessage,InAppMessageButton}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import r from"../../shared-lib/braze-shared-lib.js";import Q from"../triggers/models/trigger-events.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";export function logInAppMessageButtonClick(t,o){if(!e.rr())return!1;if(!(t instanceof InAppMessageButton))return r.D.error("button must be an InAppMessageButton object"),!1;if(!(o instanceof InAppMessage))return r.D.error(rr),!1;const s=me.m().di(t,o);if(s.S)for(let r=0;r<s.ve.length;r++)V.er().je(Q.Ar,[o.triggerId,t.id],s.ve[r]);return s.S}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{InAppMessage}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import{MUST_BE_IN_APP_MESSAGE_WARNING as rr}from"../common/constants.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import{InAppMessage}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import{MUST_BE_IN_APP_MESSAGE_WARNING as rr}from"../common/constants.js";import r from"../../shared-lib/braze-shared-lib.js";import Q from"../triggers/models/trigger-events.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";export function logInAppMessageClick(o){if(!e.rr())return!1;if(!(o instanceof InAppMessage))return r.D.error(rr),!1;const s=me.m().G(o,r.A.mi);if(s)for(let r=0;r<s.ve.length;r++)V.er().je(Q.Ar,[o.triggerId],s.ve[r]);return s.S}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{HtmlMessage}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import r from"../../shared-lib/braze-shared-lib.js";import
|
|
1
|
+
import e from"../managers/braze-instance.js";import{HtmlMessage}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import r from"../../shared-lib/braze-shared-lib.js";import Q from"../triggers/models/trigger-events.js";import{TriggersProviderFactory as V}from"../triggers/triggers-provider-factory.js";export function logInAppMessageHtmlClick(s,t,o){if(!e.rr())return!1;if(!(s instanceof HtmlMessage))return r.D.error("inAppMessage argument to logInAppMessageHtmlClick must be an HtmlMessage object."),!1;let i=r.A.mi;null!=t&&(i=r.A.fi);const n=me.m().G(s,i,t,o);if(n.S)for(let r=0;r<n.ve.length;r++)V.er().je(Q.Ar,[s.triggerId,t],n.ve[r]);return n.S}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"../managers/braze-instance.js";import{ControlMessage,InAppMessage}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import{MUST_BE_IN_APP_MESSAGE_WARNING as rr}from"../common/constants.js";import r from"../../shared-lib/braze-shared-lib.js";export function logInAppMessageImpression(n){if(!e.rr())return!1;if(!(n instanceof InAppMessage||n instanceof ControlMessage))return r.D.error(rr),!1;const s=n instanceof ControlMessage?r.A.
|
|
1
|
+
import e from"../managers/braze-instance.js";import{ControlMessage,InAppMessage}from"../InAppMessage/index.js";import me from"./in-app-message-manager-factory.js";import{MUST_BE_IN_APP_MESSAGE_WARNING as rr}from"../common/constants.js";import r from"../../shared-lib/braze-shared-lib.js";export function logInAppMessageImpression(n){if(!e.rr())return!1;if(!(n instanceof InAppMessage||n instanceof ControlMessage))return r.D.error(rr),!1;const s=n instanceof ControlMessage?r.A.Ir:r.A.gi;return me.m().G(n,s).S}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import{ControlMessage,HtmlMessage,InAppMessage,SlideUpMessage}from"../index.js";import me from"../in-app-message-manager-factory.js";import ae from"../display/get-animation-effect.js";import
|
|
1
|
+
import e,{OPTIONS as D}from"../../managers/braze-instance.js";import{ControlMessage,HtmlMessage,InAppMessage,SlideUpMessage}from"../index.js";import me from"../in-app-message-manager-factory.js";import ae from"../display/get-animation-effect.js";import de 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 nr}from"../../ui/js/index.js";import r from"../../../shared-lib/braze-shared-lib.js";import{toRgba as se}from"../../util/color-utils.js";export function showInAppMessage(t,i,o){if(!e.rr())return;if(nr(),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 s=me.m();t.Yi();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.'),s.ui(t.triggerId,InAppMessage.pi.Ji),!1;if(null==i&&(i=document.body),t.we()){if(i.querySelectorAll(".ab-modal-interactions").length>0)return r.D.info(`Cannot show in-app message ${t.message} because another message is being shown.`),s.ui(t.triggerId,InAppMessage.pi.Qi),!1}if(G.Ue()){const e=G.Je();if(e===le.PORTRAIT&&t.orientation===InAppMessage.Orientation.LANDSCAPE||e===le.LANDSCAPE&&t.orientation===InAppMessage.Orientation.PORTRAIT){const i=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 ${i}`),s.ui(t.triggerId,InAppMessage.pi.Zi),!1}}if(!e.tr()){let e=!1;if(t.buttons&&t.buttons.length>0){const i=t.buttons;for(let t=0;t<i.length;t++)if(i[t].clickAction===InAppMessage.ClickAction.URI){const o=i[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.'),s.ui(t.triggerId,InAppMessage.pi.Ji),!1}const a=document.createElement("div");if(a.className="ab-iam-root v3",a.className+=ae(t),a.setAttribute("role","complementary"),t.an()&&(a.id=t.htmlId),e.nn(D.Be)&&(a.style.zIndex=e.nn(D.Be)+1),i.appendChild(a),t.sn()){const i=document.createElement("style");i.innerHTML=t.css,i.id=t.rn(),null!=e.nn(D.Fe)&&i.setAttribute("nonce",e.nn(D.Fe)),document.getElementsByTagName("head")[0].appendChild(i)}const l=t instanceof SlideUpMessage,c=de(t,(()=>{import("../../Feed/ui/show-feed.js").then((e=>e.showFeed()))}),(i=>{if(t.we()&&t.ll()){const o=document.createElement("div");if(o.className="ab-page-blocker",t.sn()||(o.style.backgroundColor=se(t.frameColor)),e.nn(D.Be)&&(o.style.zIndex=e.nn(D.Be)),a.appendChild(o),!e.nn(D.Ki)){const e=(new Date).valueOf();o.onclick=o=>{(new Date).valueOf()-e>InAppMessage.Se&&(t.on(i),o.stopPropagation())}}a.appendChild(i),i.focus(),t.Gi(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]!==i){o=e[t];break}if(t.slideFrom===InAppMessage.SlideFrom.TOP){let e=0;null!=o&&(e=o.offsetTop+o.offsetHeight),i.style.top=Math.max(e,0)+"px"}else{let e=0;null!=o&&(e=(window.innerHeight||document.documentElement.clientHeight)-o.offsetTop),i.style.bottom=Math.max(e,0)+"px"}}else if(n&&!e.nn(D.Ki)){const e=t;i.contentWindow.addEventListener("keydown",(function(t){t.keyCode===at.xi&&e.closeMessage()}))}logInAppMessageImpression(t),t.dismissType===InAppMessage.DismissType.AUTO_DISMISS&&setTimeout((()=>{a.contains(i)&&t.on(i)}),t.duration),"function"==typeof o&&o()}),e.nn(D.Ge),e.nn(D.Be),e.nn(D.Fe));return(n||l)&&(a.appendChild(c),t.Gi(a)),!0}
|
|
@@ -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,Br:()=>(or.o(),or.pushManager||(or.pushManager=new aa(e.
|
|
1
|
+
import e,{OPTIONS as D}from"../managers/braze-instance.js";import aa from"./push-manager.js";const or={t:!1,pushManager:null,Br:()=>(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.Pe=i,this.We=e,this.Re=t,this.Ve=s+"/safari/"+e,this.Ye=n||"/service-worker.js",this.Ke=r,this.wt=o,this.Qe=u||!1,this.Xe=h||!1,this.h=a,this.Ze="serviceWorker"in navigator&&"undefined"!=typeof ServiceWorkerRegistration&&"showNotification"in ServiceWorkerRegistration.prototype&&"PushManager"in window,this.hn="safari"in window&&"pushNotification"in window.safari&&"function"==typeof window.safari.pushNotification.permission&&"function"==typeof window.safari.pushNotification.requestPermission}dn(){return this.Xe}isPushSupported(){return this.Ze||this.hn}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}Ti(){return!this.isPushBlocked()&&this.isPushSupported()&&!this.isPushPermissionGranted()}fn(i,e,t,s,n){i.unsubscribe().then((i=>{i?this.pn(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)}))}wn(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.bn&&-1===i.endpoint.indexOf(i.bn)&&(e=i.endpoint+"/"+i.bn),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.Pe.gn(s,t,n,r,o),s&&"function"==typeof e&&e(s,n,r)}yn(){this.Pe.vn(!0)}Pn(i,e){this.Pe.vn(!1),r.D.info(i),"function"==typeof e&&e(!1)}kn(i,e,t,s){if("default"===e.permission)try{window.safari.pushNotification.requestPermission(this.Ve,i,{api_key:this.We,device_id:this.Re.te().id},(e=>{"granted"===e.permission&&this.Pe.setPushNotificationSubscriptionType(User.NotificationSubscriptionTypes.OPTED_IN),this.kn(i,e,t,s)}))}catch(i){this.Pn("Could not request permission for push: "+i,s)}else"denied"===e.permission?this.Pn("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.wn(e.deviceToken,t,new Date))}Sn(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}pn(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.wn(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)}))}Dn(){return this.Qe?navigator.serviceWorker.getRegistration():navigator.serviceWorker.register(this.Ye).then((()=>navigator.serviceWorker.ready.then((i=>(i&&"function"==typeof i.update&&i.update().catch((i=>{r.D.info("ServiceWorker update failed: "+i)})),i)))))}_n(i){this.Qe||(i.unregister(),r.D.info("Service worker successfully unregistered."))}subscribe(i,e){if(this.isPushSupported()){if(this.Ze){if(!this.Qe&&null!=window.location){let i=this.Ye;-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.Nn().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.Pn("Notifications from this site are blocked. This may be a temporary embargo or a permanent denial.",e);if(this.wt&&!this.wt.Wn()&&0===this.wt.Gs())return r.D.info("Waiting for VAPID key from server config before subscribing to push."),void this.wt.An((()=>{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.Pe.setPushNotificationSubscriptionType(User.NotificationSubscriptionTypes.OPTED_IN),this.Dn().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.Wn()&&(n=r.Un.jn(this.wt.Wn())),s){let u=null,h=null;const a=this.h.I(o.q.xn);if(a&&!p(a)){let i;try{i=ei.Rn(a).Tn}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.fn(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.fn(s,t,n,i,e)):a&&p(a)?this.fn(s,t,n,i,e):null==h?(r.D.info("No push subscription creation date found, creating new subscription."),this.fn(s,t,n,i,e)):h<=(new Date).valueOf()?(r.D.info("Push subscription older than 6 months, creating new subscription."),this.fn(s,t,n,i,e)):(r.D.info("Device already subscribed to push, sending existing subscription to backend."),this.wn(s,i,u))}else this.pn(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.Sn(u,s,t)}else if(this.hn){if(null==this.Ke||""===this.Ke)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.Ke);this.kn(this.Ke,t,i,e)}}else r.D.info(this.zn)}unsubscribe(i,e){this.isPushSupported()?this.Ze?navigator.serviceWorker.getRegistration().then((t=>{t&&t.pushManager.getSubscription().then((s=>{s&&(this.yn(),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._n(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.hn&&(this.yn(),r.D.info("Device unsubscribed from push."),"function"==typeof i&&i()):r.D.info(this.zn)}}aa.zn="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.Br().subscribe(((n,o,t)=>{e.
|
|
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.Br().subscribe(((n,o,t)=>{e.mr().requestImmediateDataFlush(),"function"==typeof r&&r(n,o,t)}),n)}
|
package/src/User/user-manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import mt 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 _t{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.Tr,i=U(s);if(i>User.ee){for(;i>User.ee;)s=s.slice(0,s.length-1),i=U(s);t.Tr=s,this.h.
|
|
1
|
+
import mt 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 _t{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.Tr,i=U(s);if(i>User.ee){for(;i>User.ee;)s=s.slice(0,s.length-1),i=U(s);t.Tr=s,this.h.Lr(o.Cr.Ur,t)}return s}Er(t){const s=null==this.getUserId();this.h.Lr(o.Cr.Ur,new mt(t)),s&&this.h.Gr(t)}setCustomUserAttribute(t,s){if(this.wt.Hr(t))return r.D.info('Custom Attribute "'+t+'" is blocklisted, ignoring.'),!1;const i={};return i[t]=s,this.Jr(User.Kr,i,!0)}Jr(t,s,i,e){const u=this.h.Mr(this.getUserId(),t,s);return!e&&u&&r.D.info(`Logged${i?" custom":""} attribute ${t} with value ${s}`),u}gn(t,s,i,e,u){this.Jr("push_token",t,!1,!0),this.Jr("custom_push_public_key",i,!1,!0),this.Jr("custom_push_user_auth",e,!1,!0),this.Jr("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.xn,l.ss()),n.setItem(h.Pt.Nr,h.se,!0)}vn(t){if(this.Jr("push_token",null,!1,!0),this.Jr("custom_push_public_key",null,!1,!0),this.Jr("custom_push_user_auth",null,!1,!0),this.Jr("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.xn,!1),s.setItem(t.Pt.Nr,t.se,!1)}}}
|
package/src/User/user.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isArray as p,isDate as bt,validateValueIsFromEnum as
|
|
1
|
+
import{isArray as p,isDate as bt,validateValueIsFromEnum as K}from"../util/code-utils.js";import r from"../../shared-lib/braze-shared-lib.js";import{toValidBackendTimeString as gt}from"../util/date-utils.js";import{isValidEmail as yt,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.Sr(t,e).S}setFirstName(t){return!!R(t,"set first name","the firstName",!0)&&this.v.Jr("first_name",t)}setLastName(t){return!!R(t,"set last name","the lastName",!0)&&this.v.Jr("last_name",t)}setEmail(t){return null===t||yt(t)?this.v.Jr("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.Jr("gender",t)}setDateOfBirth(t,e,s){return null===t&&null===e&&null===s?this.v.Jr("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.Jr("dob",`${t}-${e}-${s}`))}setCountry(t){return!!R(t,"set country","the country",!0)&&this.v.Jr("country",t)}setHomeCity(t){return!!R(t,"set home city","the homeCity",!0)&&this.v.Jr("home_city",t)}setLanguage(t){return!!R(t,"set language","the language",!0)&&this.v.Jr("language",t)}setEmailNotificationSubscriptionType(t){return!!K(User.NotificationSubscriptionTypes,t,`Email notification setting "${t}" is not a valid subscription type.`,"User.NotificationSubscriptionTypes")&&this.v.Jr("email_subscribe",t)}setPushNotificationSubscriptionType(t){return!!K(User.NotificationSubscriptionTypes,t,`Push notification setting "${t}" is not a valid subscription type.`,"User.NotificationSubscriptionTypes")&&this.v.Jr("push_subscribe",t)}setPhoneNumber(t){return!!R(t,"set phone number","the phoneNumber",!0)&&(null===t||t.match(User.Or)?this.v.Jr("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=bt(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=gt(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.Vr(r.A.Wr,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.Vr(r.A.Yr,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.Vr(r.A.Qr,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.Vr(r.A.Xr,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.Zr(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.Cn(t,User.In.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.Cn(t,User.In.UNSUBSCRIBED).S}gn(t,e,s,r,i){this.v.gn(t,e,s,r,i),this.Is.En()}vn(t){this.v.vn(t)}}User.Or=/^[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.In={SUBSCRIBED:"subscribed",UNSUBSCRIBED:"unsubscribed"},User.Fn="user_id",User.Kr="custom",User.ee=997;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import x from"./base-feed.js";import{bottomHadImpression as
|
|
1
|
+
import x from"./base-feed.js";import{bottomHadImpression as fe,getCardId as pe,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";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.Fi));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.so||(e.so={});for(let t=0;t<r.length;t++){const s=pe(r[t]);if(e.so[s])continue;let n=Te(r[t]),a=fe(r[t]);const i=n,d=a,c=_e(r[t]),f=he(r[t]);if(!n&&c&&(n=!0,ye(r[t])),!a&&f&&(a=!0,be(r[t])),n&&a){if(c||f||Fe(r[t]),i&&d)continue;for(const t of e.cards)if(t.id===s){e.so[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.eo),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.ao&&e.keyCode!==at.io||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.ao&&e.keyCode!==at.io||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,r,s){if(!p(t))return;const n=[];for(let e=0;e<t.length;e++)t[e]instanceof Card&&n.push(t[e]);if(e.cards=n,e.lastUpdated=o,null!=r)if(r.setAttribute("aria-busy","false"),null==e.lastUpdated)destroyFeedHtml(r);else{const t=r.querySelectorAll(".ab-feed-body")[0];if(null!=t){const o=_generateFeedBody(e,s);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.Mn)&&(r=e.nn(D.Mn),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;
|