@braze/web-sdk 4.2.1 → 4.4.0

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.
Files changed (178) hide show
  1. package/index.d.ts +57 -6
  2. package/package.json +1 -1
  3. package/shared-lib/braze-shared-lib.js +8 -1
  4. package/shared-lib/encoding-utils.js +12 -1
  5. package/shared-lib/event-types.js +32 -1
  6. package/shared-lib/guid.js +10 -1
  7. package/shared-lib/indexed-db-adapter.js +315 -1
  8. package/shared-lib/logger.js +38 -1
  9. package/shared-lib/supported-options.js +26 -1
  10. package/src/Card/card-manager-factory.js +14 -1
  11. package/src/Card/card-manager.js +72 -1
  12. package/src/Card/display/card-display.js +134 -1
  13. package/src/Card/index.js +5 -1
  14. package/src/Card/log-card-click.js +11 -1
  15. package/src/Card/log-card-dismissal.js +11 -1
  16. package/src/Card/log-card-impressions.js +13 -1
  17. package/src/Card/log-content-card-impressions.js +4 -1
  18. package/src/Card/models/banner.js +30 -1
  19. package/src/Card/models/captioned-image.js +32 -1
  20. package/src/Card/models/card.js +174 -1
  21. package/src/Card/models/classic-card.js +32 -1
  22. package/src/Card/models/control-card.js +38 -1
  23. package/src/Card/models/index.js +5 -1
  24. package/src/Card/util/card-factory.js +104 -1
  25. package/src/ContentCards/content-cards-provider-factory.js +20 -1
  26. package/src/ContentCards/content-cards-provider.js +283 -1
  27. package/src/ContentCards/content-cards.js +24 -1
  28. package/src/ContentCards/get-cached-content-cards.js +5 -1
  29. package/src/ContentCards/index.js +8 -1
  30. package/src/ContentCards/log-content-cards-displayed.js +5 -1
  31. package/src/ContentCards/request-content-cards-refresh.js +5 -1
  32. package/src/ContentCards/subscribe-to-content-cards-updates.js +14 -1
  33. package/src/ContentCards/ui/hide-content-cards.js +8 -1
  34. package/src/ContentCards/ui/show-content-cards.js +72 -1
  35. package/src/ContentCards/ui/toggle-content-cards.js +8 -1
  36. package/src/Core/add-sdk-metadata.js +27 -1
  37. package/src/Core/braze-sdk-metadata.js +10 -1
  38. package/src/Core/change-user.js +19 -1
  39. package/src/Core/destroy.js +5 -1
  40. package/src/Core/device-properties.js +9 -1
  41. package/src/Core/disable-sdk.js +10 -1
  42. package/src/Core/enable-sdk.js +8 -1
  43. package/src/Core/get-device-id.js +10 -1
  44. package/src/Core/get-user.js +4 -1
  45. package/src/Core/handle-braze-action.js +64 -1
  46. package/src/Core/index.js +23 -1
  47. package/src/Core/initialize.js +4 -1
  48. package/src/Core/is-disabled.js +4 -1
  49. package/src/Core/log-custom-event.js +36 -1
  50. package/src/Core/log-purchase.js +245 -1
  51. package/src/Core/open-session.js +23 -1
  52. package/src/Core/remove-all-subscriptions.js +4 -1
  53. package/src/Core/remove-subscription.js +4 -1
  54. package/src/Core/request-immediate-data-flush.js +4 -1
  55. package/src/Core/set-logger.js +4 -1
  56. package/src/Core/set-sdk-authentication-signature.js +9 -1
  57. package/src/Core/subscribe-to-sdk-authentication-failures.js +4 -1
  58. package/src/Core/toggle-logging.js +4 -1
  59. package/src/Core/wipe-data.js +15 -1
  60. package/src/FeatureFlags/feature-flag-factory.js +14 -0
  61. package/src/FeatureFlags/feature-flag.js +16 -0
  62. package/src/FeatureFlags/feature-flags-provider-factory.js +19 -0
  63. package/src/FeatureFlags/feature-flags-provider.js +94 -0
  64. package/src/FeatureFlags/get-all-feature-flags.js +12 -0
  65. package/src/FeatureFlags/get-feature-flag.js +12 -0
  66. package/src/FeatureFlags/index.js +4 -0
  67. package/src/FeatureFlags/refresh-feature-flags.js +9 -0
  68. package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +6 -0
  69. package/src/Feed/feed-provider-factory.js +18 -1
  70. package/src/Feed/feed-provider.js +79 -1
  71. package/src/Feed/feed.js +20 -1
  72. package/src/Feed/get-cached-feed.js +5 -1
  73. package/src/Feed/index.js +8 -1
  74. package/src/Feed/log-feed-displayed.js +5 -1
  75. package/src/Feed/request-feed-refresh.js +5 -1
  76. package/src/Feed/subscribe-to-feed-updates.js +5 -1
  77. package/src/Feed/ui/hide-feed.js +7 -1
  78. package/src/Feed/ui/show-feed.js +89 -1
  79. package/src/Feed/ui/toggle-feed.js +8 -1
  80. package/src/InAppMessage/display/get-animation-effect.js +19 -1
  81. package/src/InAppMessage/display/html-message-to-html.js +223 -1
  82. package/src/InAppMessage/display/in-app-message-to-html.js +152 -1
  83. package/src/InAppMessage/display/modal-utils.js +68 -1
  84. package/src/InAppMessage/in-app-message-factory.js +145 -1
  85. package/src/InAppMessage/in-app-message-manager-factory.js +16 -1
  86. package/src/InAppMessage/in-app-message-manager.js +189 -1
  87. package/src/InAppMessage/index.js +14 -1
  88. package/src/InAppMessage/log-in-app-message-button-click.js +19 -1
  89. package/src/InAppMessage/log-in-app-message-click.js +16 -1
  90. package/src/InAppMessage/log-in-app-message-html-click.js +23 -1
  91. package/src/InAppMessage/log-in-app-message-impression.js +13 -1
  92. package/src/InAppMessage/models/control-message.js +8 -1
  93. package/src/InAppMessage/models/full-screen-message.js +71 -1
  94. package/src/InAppMessage/models/html-message.js +54 -1
  95. package/src/InAppMessage/models/in-app-message-button.js +40 -1
  96. package/src/InAppMessage/models/in-app-message.js +267 -1
  97. package/src/InAppMessage/models/modal-message.js +68 -1
  98. package/src/InAppMessage/models/slide-up-message.js +58 -1
  99. package/src/InAppMessage/models/templated-in-app-message.js +14 -1
  100. package/src/InAppMessage/subscribe-to-in-app-message.js +10 -1
  101. package/src/InAppMessage/ui/automatically-show-in-app-messages.js +15 -1
  102. package/src/InAppMessage/ui/show-in-app-message.js +170 -1
  103. package/src/Push/index.js +5 -1
  104. package/src/Push/is-push-blocked.js +5 -1
  105. package/src/Push/is-push-permission-granted.js +5 -1
  106. package/src/Push/is-push-supported.js +5 -1
  107. package/src/Push/push-manager-factory.js +30 -1
  108. package/src/Push/push-manager.js +360 -1
  109. package/src/Push/request-push-permission.js +8 -1
  110. package/src/Push/unregister-push.js +5 -1
  111. package/src/Push/utils/push-utils.js +34 -1
  112. package/src/User/index.js +1 -1
  113. package/src/User/user-manager.js +70 -1
  114. package/src/User/user.js +278 -1
  115. package/src/common/base-feed.js +25 -1
  116. package/src/common/base-provider.js +6 -1
  117. package/src/common/constants.js +5 -1
  118. package/src/common/event-logger.js +24 -1
  119. package/src/common/feed-display.js +200 -1
  120. package/src/common/translations.js +148 -1
  121. package/src/index.js +9 -1
  122. package/src/l10n/l10n-manager-factory.js +22 -1
  123. package/src/l10n/l10n-manager.js +21 -1
  124. package/src/managers/auth-manager.js +48 -1
  125. package/src/managers/braze-instance.js +307 -1
  126. package/src/managers/device-manager.js +80 -1
  127. package/src/managers/network-manager.js +219 -1
  128. package/src/managers/server-config-manager.js +88 -1
  129. package/src/managers/session-manager.js +68 -1
  130. package/src/managers/storage-manager-factory.js +35 -1
  131. package/src/managers/storage-manager.js +394 -1
  132. package/src/managers/subscription-manager.js +25 -1
  133. package/src/models/backend-errors.js +8 -1
  134. package/src/models/braze-event.js +41 -1
  135. package/src/models/braze-sdk-metadata.js +10 -1
  136. package/src/models/device.js +26 -1
  137. package/src/models/identifier.js +20 -1
  138. package/src/models/push-token.js +22 -1
  139. package/src/models/request-result.js +8 -1
  140. package/src/models/server-config.js +32 -1
  141. package/src/request-controller.js +288 -1
  142. package/src/triggers/models/custom-event-data.js +14 -1
  143. package/src/triggers/models/custom-event-property-data.js +21 -1
  144. package/src/triggers/models/filter-set.js +55 -1
  145. package/src/triggers/models/filter.js +98 -1
  146. package/src/triggers/models/in-app-message-click-data.js +25 -1
  147. package/src/triggers/models/purchase-data.js +14 -1
  148. package/src/triggers/models/purchase-property-data.js +21 -1
  149. package/src/triggers/models/push-click-data.js +15 -1
  150. package/src/triggers/models/trigger-condition.js +109 -1
  151. package/src/triggers/models/trigger-events.js +8 -1
  152. package/src/triggers/models/trigger.js +110 -1
  153. package/src/triggers/triggers-provider-factory.js +30 -1
  154. package/src/triggers/triggers-provider.js +307 -1
  155. package/src/ui/js/attach-css.js +12 -1
  156. package/src/ui/js/feed-css.js +12 -1
  157. package/src/ui/js/iam-css.js +12 -1
  158. package/src/ui/js/index.js +3 -1
  159. package/src/ui/js/load-font-awesome.js +13 -1
  160. package/src/util/base-device-parser.js +14 -1
  161. package/src/util/braze-actions.js +79 -1
  162. package/src/util/browser-detector.js +85 -1
  163. package/src/util/client-hints-parser.js +60 -1
  164. package/src/util/code-utils.js +92 -1
  165. package/src/util/color-utils.js +23 -1
  166. package/src/util/component-utils.js +26 -1
  167. package/src/util/date-utils.js +27 -1
  168. package/src/util/deprecation-utils.js +5 -1
  169. package/src/util/device-constants.js +14 -1
  170. package/src/util/dom-utils.js +87 -1
  171. package/src/util/key-codes.js +1 -1
  172. package/src/util/math.js +5 -1
  173. package/src/util/net.js +75 -1
  174. package/src/util/string-utils.js +22 -1
  175. package/src/util/url-utils.js +23 -1
  176. package/src/util/user-agent-parser.js +85 -1
  177. package/src/util/validation-utils.js +136 -1
  178. package/src/util/window-utils.js +35 -1
@@ -1 +1,307 @@
1
- import St from"./auth-manager.js";import y 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 rr,validateValueIsFromEnum as F,values as At}from"../util/code-utils.js";import{logDeprecationWarning as D}from"../util/deprecation-utils.js";import wt from"./network-manager.js";import Ot from"../request-controller.js";import Ct from"./server-config-manager.js";import Lt from"./session-manager.js";import r from"../../shared-lib/braze-shared-lib.js";import G,{STORAGE_KEYS as o}from"./storage-manager.js";import Pt from"./storage-manager-factory.js";import u from"./subscription-manager.js";import{TriggersProviderFactory as W}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 H}from"../util/window-utils.js";const T={Rn:"allowCrawlerActivity",Wn:"baseUrl",Vn:"noCookies",Yn:"devicePropertyAllowlist",ta:"disablePushTokenMaintenance",Xn:"enableLogging",Zn:"enableSdkAuthentication",ia:"manageServiceWorkerExternally",ho:"minimumIntervalBetweenTriggerActionsInSeconds",po:"sessionTimeoutInSeconds",Eo:"appVersion",na:"serviceWorkerLocation",ra:"safariWebsitePushId",jn:"localization",ao:"contentSecurityNonce",_o:"enableHtmlInAppMessages",Io:"allowUserSuppliedJavascript",no:"inAppMessageZIndex",lo:"openInAppMessagesInNewTab",tn:"openCardsInNewTab",en:"openNewsFeedCardsInNewTab",Ui:"requireExplicitInAppMessageDismissal",Ao:"doNotLoadFontAwesome",So:"sdkFlavor"};class Rt{constructor(){this.No=!1,this.wo=!1,this.To=new u,this.Oo=new u,this.vo={},this.Co=[],this.Lo=[],this.De=[],this.Po="4.2.1"}Ro(t){this.To.ut(t)}Bi(t){this.Oo.ut(t)}initialize(t,i){if(this.Mo())return r.D.info("Braze has already been initialized with an API key."),!0;this.vo=i||{};let s=this.nn(T.Xn);const e=st(H.hn());if(e&&"true"===e.brazeLogging&&(s=!0),r.D.init(s),r.D.info(`Initialization Options: ${JSON.stringify(this.vo,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(T.Wn);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.yo=n,et.Do&&!this.nn(T.Rn))return r.D.info("Ignoring activity from crawler bot "+navigator.userAgent),this.wo=!0,!1;const a=this.nn(Rt.Vn)||!1;if(this.h=Pt.jo(t,a),new G.ne(null,!0).lr(o.ae))return r.D.info("Ignoring all activity due to previous opt out"),this.wo=!0,!1;for(const t of rr(this.vo))-1===At(r.zo).indexOf(t)&&r.D.warn(`Ignoring unknown initialization option '${t}'.`);const h=["mparticle","wordpress","tealium"];if(null!=this.nn(T.So)){const t=this.nn(T.So);-1!==h.indexOf(t)?this.Uo=t:r.D.error("Invalid sdk flavor passed: "+t)}let l=this.nn(r.zo.Yn);if(null!=l)if(p(l)){const t=[];for(let i=0;i<l.length;i++)F(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.Qi=new It(this.h,l),this.gt=new Ct(this.h),this.v=new bt(this.gt,this.h),this.j=new Lt(this.h,this.v,this.gt,this.nn(T.po));const c=new u;return this.Bo=new St(this.h,this.nn(T.Zn),c),this.jt(c),this.vt=new wt(this.Qi,this.h,this.Bo,this.v,this.j,this.gt,this.Ji,this.yo,this.Po,this.Uo,this.nn(T.Eo)),this.si=new Ot(this.Ji,this.yo,this.j,this.Qi,this.v,this.gt,this.h,(t=>{if(this.Mo())for(const i of this.re())i.Rs(t)}),this.Bo,this.vt),this.si.initialize(),r.D.info(`Initialized for the Braze backend at "${this.nn(T.Wn)}" with API key "${this.Ji}".`),null!=this.nn(T._o)&&D("enableHtmlInAppMessages","initialization option","allowUserSuppliedJavascript"),W.init(),this.To.St(this.vo),this.No=!0,!0}destroy(t){if(r.D.destroy(),this.Mo()){this.Oo.St(),this.Oo.removeAllSubscriptions();for(const t of this.Co)t.destroy();this.Co=[];for(const t of this.Lo)t.clearData(!1);this.Lo=[],this.removeAllSubscriptions(),this.De=[],this.si.destroy(),this.si=null,this.Bo=null,this.Qi=null,this.vt=null,this.gt=null,this.j=null,this.v=null,this.vo={},this.Uo=void 0,this.No=!1,this.wo=!1,t&&(this.h=null)}}rr(){if(this.Wo())return!1;if(!this.Mo())throw new Error("Braze must be initialized before calling methods.");return!0}ea(){return this.Ji}ii(){return this.Bo}Ks(){return this.yo}ce(){return this.Qi}nr(){return this.vt}nn(t){return this.vo[t]}re(){return this.Lo}mr(){return this.si}ir(){return this.gt}g(){return this.j}l(){return this.h}gr(){if(this.v&&this.si)return new User(this.v,this.si)}p(){return this.v}tr(){return!0===this.nn(T.Io)||!0===this.nn(T._o)}u(t){let i=!1;for(const s of this.Co)s===t&&(i=!0);i||this.Co.push(t)}ar(t){let i=!1;for(const s of this.Lo)s.constructor===t.constructor&&(i=!0);t instanceof y&&!i&&this.Lo.push(t)}jt(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.wo=t}Mo(){return this.No}Wo(){return this.wo}Ds(){return this.Po}}const e=new Rt;export{e as default,Rt as BrazeSdkInstance,T as OPTIONS};
1
+ import St from "./auth-manager.js";
2
+ import y from "../common/base-provider.js";
3
+ import ot from "../util/browser-detector.js";
4
+ import It from "./device-manager.js";
5
+ import DeviceProperties from "../Core/device-properties.js";
6
+ import {
7
+ isArray as p,
8
+ keys as rr,
9
+ validateValueIsFromEnum as F,
10
+ values as At
11
+ } from "../util/code-utils.js";
12
+ import { logDeprecationWarning as D } from "../util/deprecation-utils.js";
13
+ import Ot from "./network-manager.js";
14
+ import Lt from "../request-controller.js";
15
+ import Pt from "./server-config-manager.js";
16
+ import Rt from "./session-manager.js";
17
+ import r from "../../shared-lib/braze-shared-lib.js";
18
+ import G, { STORAGE_KEYS as o } from "./storage-manager.js";
19
+ import Mt from "./storage-manager-factory.js";
20
+ import u from "./subscription-manager.js";
21
+ import { TriggersProviderFactory as W } from "../triggers/triggers-provider-factory.js";
22
+ import bt from "../User/user-manager.js";
23
+ import { User } from "../User/index.js";
24
+ import { parseQueryStringKeyValues as it } from "../util/url-utils.js";
25
+ import { WindowUtils as H } from "../util/window-utils.js";
26
+ const T = {
27
+ Yn: "allowCrawlerActivity",
28
+ Zn: "baseUrl",
29
+ ho: "noCookies",
30
+ po: "devicePropertyAllowlist",
31
+ ta: "disablePushTokenMaintenance",
32
+ Eo: "enableLogging",
33
+ _o: "enableSdkAuthentication",
34
+ ia: "manageServiceWorkerExternally",
35
+ Io: "minimumIntervalBetweenTriggerActionsInSeconds",
36
+ Ao: "sessionTimeoutInSeconds",
37
+ So: "appVersion",
38
+ na: "serviceWorkerLocation",
39
+ ra: "safariWebsitePushId",
40
+ jn: "localization",
41
+ ao: "contentSecurityNonce",
42
+ No: "enableHtmlInAppMessages",
43
+ wo: "allowUserSuppliedJavascript",
44
+ no: "inAppMessageZIndex",
45
+ lo: "openInAppMessagesInNewTab",
46
+ tn: "openCardsInNewTab",
47
+ en: "openNewsFeedCardsInNewTab",
48
+ qi: "requireExplicitInAppMessageDismissal",
49
+ To: "doNotLoadFontAwesome",
50
+ Oo: "sdkFlavor"
51
+ };
52
+ class jt {
53
+ constructor() {
54
+ (this.vo = !1),
55
+ (this.Co = !1),
56
+ (this.Lo = new u()),
57
+ (this.Po = new u()),
58
+ (this.Ro = {}),
59
+ (this.Mo = []),
60
+ (this.jo = []),
61
+ (this.Pe = []),
62
+ (this.yo = "4.4.0");
63
+ }
64
+ Do(t) {
65
+ this.Lo.ut(t);
66
+ }
67
+ Zi(t) {
68
+ this.Po.ut(t);
69
+ }
70
+ initialize(t, i) {
71
+ if (this.Uo())
72
+ return (
73
+ r.D.info("Braze has already been initialized with an API key."), !0
74
+ );
75
+ this.Ro = i || {};
76
+ let s = this.nn(T.Eo);
77
+ const e = it(H.bn());
78
+ if (
79
+ (e && "true" === e.brazeLogging && (s = !0),
80
+ r.D.init(s),
81
+ r.D.info(`Initialization Options: ${JSON.stringify(this.Ro, null, 2)}`),
82
+ null == t || "" === t || "string" != typeof t)
83
+ )
84
+ return r.D.error("Braze requires a valid API key to be initialized."), !1;
85
+ this._r = t;
86
+ let n = this.nn(T.Zn);
87
+ if (null == n || "" === n || "string" != typeof n)
88
+ return r.D.error("Braze requires a valid baseUrl to be initialized."), !1;
89
+ !1 === /^https?:/.test(n) && (n = `https://${n}`);
90
+ let a = n;
91
+ if (
92
+ ((n = document.createElement("a")),
93
+ (n.href = a),
94
+ "/" === n.pathname && (n = `${n}api/v3`),
95
+ (this.zo = n.toString()),
96
+ ot.Bo && !this.nn(T.Yn))
97
+ )
98
+ return (
99
+ r.D.info("Ignoring activity from crawler bot " + navigator.userAgent),
100
+ (this.Co = !0),
101
+ !1
102
+ );
103
+ const h = this.nn(jt.ho) || !1;
104
+ if (((this.h = Mt.Wo(t, h)), new G.ne(null, !0).lr(o.ae)))
105
+ return (
106
+ r.D.info("Ignoring all activity due to previous opt out"),
107
+ (this.Co = !0),
108
+ !1
109
+ );
110
+ for (const t of rr(this.Ro))
111
+ -1 === At(r.Fo).indexOf(t) &&
112
+ r.D.warn(`Ignoring unknown initialization option '${t}'.`);
113
+ const l = ["mparticle", "wordpress", "tealium"];
114
+ if (null != this.nn(T.Oo)) {
115
+ const t = this.nn(T.Oo);
116
+ -1 !== l.indexOf(t)
117
+ ? (this.Vo = t)
118
+ : r.D.error("Invalid sdk flavor passed: " + t);
119
+ }
120
+ let f = this.nn(r.Fo.po);
121
+ if (null != f)
122
+ if (p(f)) {
123
+ const t = [];
124
+ for (let i = 0; i < f.length; i++)
125
+ F(
126
+ DeviceProperties,
127
+ f[i],
128
+ "devicePropertyAllowlist contained an invalid value.",
129
+ "DeviceProperties"
130
+ ) && t.push(f[i]);
131
+ f = t;
132
+ } else
133
+ r.D.error(
134
+ "devicePropertyAllowlist must be an array. Defaulting to all properties."
135
+ ),
136
+ (f = null);
137
+ (this.Ur = new It(this.h, f)),
138
+ (this.gt = new Pt(this.h)),
139
+ (this.v = new bt(this.gt, this.h)),
140
+ (this.j = new Rt(this.h, this.v, this.gt, this.nn(T.Ao)));
141
+ const m = new u();
142
+ return (
143
+ (this.Go = new St(this.h, this.nn(T._o), m)),
144
+ this.jt(m),
145
+ (this.vt = new Ot(
146
+ this.Ur,
147
+ this.h,
148
+ this.Go,
149
+ this.v,
150
+ this.j,
151
+ this.gt,
152
+ this._r,
153
+ this.zo,
154
+ this.yo,
155
+ this.Vo,
156
+ this.nn(T.So)
157
+ )),
158
+ (this.si = new Lt(
159
+ this._r,
160
+ this.zo,
161
+ this.j,
162
+ this.Ur,
163
+ this.v,
164
+ this.gt,
165
+ this.h,
166
+ t => {
167
+ if (this.Uo()) for (const i of this.re()) i.Rs(t);
168
+ },
169
+ this.Go,
170
+ this.vt
171
+ )),
172
+ this.si.initialize(),
173
+ r.D.info(
174
+ `Initialized for the Braze backend at "${this.nn(
175
+ T.Zn
176
+ )}" with API key "${this._r}".`
177
+ ),
178
+ null != this.nn(T.No) &&
179
+ D(
180
+ "enableHtmlInAppMessages",
181
+ "initialization option",
182
+ "allowUserSuppliedJavascript"
183
+ ),
184
+ W.init(),
185
+ this.gt.Te(() => {
186
+ this.gt.ye() &&
187
+ import("../FeatureFlags/refresh-feature-flags.js").then(t => {
188
+ (0, t.default)();
189
+ });
190
+ }),
191
+ this.si.cr(() => {
192
+ this.gt.ye() &&
193
+ import("../FeatureFlags/refresh-feature-flags.js").then(t => {
194
+ (0, t.default)(null, null, !0);
195
+ });
196
+ }),
197
+ this.Lo.St(this.Ro),
198
+ (this.vo = !0),
199
+ !0
200
+ );
201
+ }
202
+ destroy(t) {
203
+ if ((r.D.destroy(), this.Uo())) {
204
+ this.Po.St(), this.Po.removeAllSubscriptions();
205
+ for (const t of this.Mo) t.destroy();
206
+ this.Mo = [];
207
+ for (const t of this.jo) t.clearData(!1);
208
+ (this.jo = []),
209
+ this.removeAllSubscriptions(),
210
+ (this.Pe = []),
211
+ this.si.destroy(),
212
+ (this.si = null),
213
+ (this.Go = null),
214
+ (this.Ur = null),
215
+ (this.vt = null),
216
+ (this.gt = null),
217
+ (this.j = null),
218
+ (this.v = null),
219
+ (this.Ro = {}),
220
+ (this.Vo = void 0),
221
+ (this.vo = !1),
222
+ (this.Co = !1),
223
+ t && (this.h = null);
224
+ }
225
+ }
226
+ rr() {
227
+ if (this.Ko()) return !1;
228
+ if (!this.Uo())
229
+ throw new Error("Braze must be initialized before calling methods.");
230
+ return !0;
231
+ }
232
+ ea() {
233
+ return this._r;
234
+ }
235
+ ii() {
236
+ return this.Go;
237
+ }
238
+ Ks() {
239
+ return this.zo;
240
+ }
241
+ ce() {
242
+ return this.Ur;
243
+ }
244
+ nr() {
245
+ return this.vt;
246
+ }
247
+ nn(t) {
248
+ return this.Ro[t];
249
+ }
250
+ re() {
251
+ return this.jo;
252
+ }
253
+ mr() {
254
+ return this.si;
255
+ }
256
+ ir() {
257
+ return this.gt;
258
+ }
259
+ g() {
260
+ return this.j;
261
+ }
262
+ l() {
263
+ return this.h;
264
+ }
265
+ gr() {
266
+ if (this.v && this.si) return new User(this.v, this.si);
267
+ }
268
+ p() {
269
+ return this.v;
270
+ }
271
+ tr() {
272
+ return !0 === this.nn(T.wo) || !0 === this.nn(T.No);
273
+ }
274
+ u(t) {
275
+ let i = !1;
276
+ for (const s of this.Mo) s === t && (i = !0);
277
+ i || this.Mo.push(t);
278
+ }
279
+ ar(t) {
280
+ let i = !1;
281
+ for (const s of this.jo) s.constructor === t.constructor && (i = !0);
282
+ t instanceof y && !i && this.jo.push(t);
283
+ }
284
+ jt(t) {
285
+ t instanceof u && this.Pe.push(t);
286
+ }
287
+ removeAllSubscriptions() {
288
+ if (this.rr()) for (const t of this.Pe) t.removeAllSubscriptions();
289
+ }
290
+ removeSubscription(t) {
291
+ if (this.rr()) for (const i of this.Pe) i.removeSubscription(t);
292
+ }
293
+ le(t) {
294
+ this.Co = t;
295
+ }
296
+ Uo() {
297
+ return this.vo;
298
+ }
299
+ Ko() {
300
+ return this.Co;
301
+ }
302
+ Ds() {
303
+ return this.yo;
304
+ }
305
+ }
306
+ const e = new jt();
307
+ export { e as default, jt as BrazeSdkInstance, T as OPTIONS };
@@ -1 +1,80 @@
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.tu(o.iu.Go);null==e&&(e=new _t(r.it.nt()),this.h.ru(o.iu.Go,e));const t=new Ie(e.eu);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
+ import ot from "../util/browser-detector.js";
2
+ import Ie from "../models/device.js";
3
+ import DeviceProperties from "../Core/device-properties.js";
4
+ import _t from "../models/identifier.js";
5
+ import r from "../../shared-lib/braze-shared-lib.js";
6
+ import { STORAGE_KEYS as o } from "../managers/storage-manager.js";
7
+ import { values as At } from "../util/code-utils.js";
8
+ export default class It {
9
+ constructor(e, t) {
10
+ (this.h = e), null == t && (t = At(DeviceProperties)), (this.xo = t);
11
+ }
12
+ te() {
13
+ let e = this.h.tu(o.eu.Jo);
14
+ null == e && ((e = new _t(r.it.nt())), this.h.ru(o.eu.Jo, e));
15
+ const t = new Ie(e.iu);
16
+ for (let e = 0; e < this.xo.length; e++) {
17
+ const r = this.xo[e];
18
+ switch (r) {
19
+ case DeviceProperties.BROWSER:
20
+ t[r] = ot.browser;
21
+ break;
22
+ case DeviceProperties.BROWSER_VERSION:
23
+ t[r] = ot.version;
24
+ break;
25
+ case DeviceProperties.OS:
26
+ t[r] = this.qo();
27
+ break;
28
+ case DeviceProperties.RESOLUTION:
29
+ t[r] = screen.width + "x" + screen.height;
30
+ break;
31
+ case DeviceProperties.LANGUAGE:
32
+ t[r] = ot.language;
33
+ break;
34
+ case DeviceProperties.TIME_ZONE:
35
+ t[r] = this.Ho(new Date());
36
+ break;
37
+ case DeviceProperties.USER_AGENT:
38
+ t[r] = ot.userAgent;
39
+ }
40
+ }
41
+ return t;
42
+ }
43
+ qo() {
44
+ if (ot.Qo()) return ot.Qo();
45
+ const e = this.h.I(o.q.Xo);
46
+ return e && e.os_version ? e.os_version : ot.Yo();
47
+ }
48
+ Ho(e) {
49
+ if ("undefined" != typeof Intl && "function" == typeof Intl.DateTimeFormat)
50
+ try {
51
+ if ("function" == typeof Intl.DateTimeFormat().resolvedOptions) {
52
+ const e = Intl.DateTimeFormat().resolvedOptions().timeZone;
53
+ if (null != e && "" !== e) return e;
54
+ }
55
+ } catch (t) {
56
+ r.D.info(
57
+ "Intl.DateTimeFormat threw an error, cannot detect user's time zone:" +
58
+ t.message
59
+ ),
60
+ (e = "");
61
+ }
62
+ if (!e) return e;
63
+ const t = e.getTimezoneOffset();
64
+ return this.Zo(t);
65
+ }
66
+ Zo(e) {
67
+ const t = parseInt(e / 60),
68
+ r = parseInt(e % 60);
69
+ let s = "GMT";
70
+ return (
71
+ 0 !== e &&
72
+ ((s += e < 0 ? "+" : "-"),
73
+ (s +=
74
+ ("00" + Math.abs(t)).slice(-2) +
75
+ ":" +
76
+ ("00" + Math.abs(r)).slice(-2))),
77
+ s
78
+ );
79
+ }
80
+ }
@@ -1 +1,219 @@
1
- import qt from"../models/backend-errors.js";import ue from"../models/braze-event.js";import{convertMsToSeconds as l,convertSecondsToMs as Dt}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.Qi=t,this.h=e,this.Bo=s,this.v=i,this.j=r,this.gt=o,this.Ji=n,this.yo=a,this.Po=h,this.Uo=u,this.Xo=c,this.$o=["npm"]}Ps(t,e){const s=this.Qi.te(),i=s.li(),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.Vo())&&(t.sdk_metadata=this.$o),t.sdk_version=this.Po,this.Uo&&(t.sdk_flavor=this.Uo),t.app_version=this.Xo,t.device_id=s.id,e){const e=this.v.getUserId();null!=e&&(t.user_id=e)}return t}Os(t,e,i){const o=e.auth_error,n=e.error;if(!o&&!n)return!0;if(o){let e;this.Bo.Pn();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.Bo.Gn()||(e+=' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),r.D.error(`SDK Authentication failed ${e}`),this.sa(t.events,t.attributes),this.Bo.Mn(s),!1}if(n){let i=n;switch(i){case qt.oa:const o="Received successful response with empty body.";return s.G(r.A.qs,{e:o}),r.D.info(o),!1;case qt.ha:const n="Received successful response with invalid JSON";return s.G(r.A.qs,{e:n+": "+e.response}),r.D.info(n),!1;case qt.ua:i=`The API key "${t.api_key}" is invalid for the baseUrl ${this.yo}`;break;case qt.ca:i="Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";break;case qt.la:i="No device identifier. Please contact support@braze.com"}r.D.error("Backend error: "+i)}return!1}fa(t,e,s,i){return!!(t&&0!==t.length||e&&0!==e.length||s||i)}ma(t,e,s,i){const r=[],o=t=>t||"",n=o(this.v.getUserId());let a,h,u,c,l=this.ni(t,e);if(s.length>0){const t=[];for(const e of s){if(a=e.li(),this.Bo.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.Bo.Gn()&&o(e.user_id)!==n?(u||(u=[]),u.push(e)):t.push(e);t.length>0&&(l.attributes=t)}if(this.sa(h,u),l=this.Ps(l,!0),c){c=this.Ps(c,!1);const t={requestData:c,headers:this.Bs(c)};r.push(t)}if(l&&!this.fa(l.events,l.attributes,t,e))return c?r:null;const f={requestData:l,headers:this.Bs(l)};return r.push(f),r}sa(t,e){if(t){const e=[];for(const s of t){const t=ue.fromJson(s);t.time=Dt(t.time),e.push(t)}this.h.bo(e)}if(e)for(const t of e)this.h.pa(t)}Vs(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})}ni(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.gt.Zs()},{respond_with:i}}Bs(t,e,s){const i=[["X-Braze-Api-Key",this.Ji]];let r=!1;if(null!=t.respond_with&&t.respond_with.triggers&&(i.push(["X-Braze-TriggersRequest","true"]),r=!0),null!=t.respond_with&&t.respond_with.feed&&(i.push(["X-Braze-FeedRequest","true"]),r=!0),e){i.push(["X-Braze-ContentCardsRequest","true"]);let t=this.h.I(o.q.As);t&&s||(t=0,this.h.B(o.q.As,t)),i.push(["BRAZE-SYNC-RETRY-COUNT",t.toString()]),r=!0}if(r&&i.push(["X-Braze-DataRequest","true"]),this.Bo.Gn()){const t=this.Bo.Hn();null!=t&&i.push(["X-Braze-Auth-Signature",t])}return i}Gs(t,e){const s=t.device;s&&s.os_version instanceof Promise?s.os_version.then((s=>{t.device.os_version=s,e()})):e()}Qs(){this.Bo.Qs()}Ks(){return this.yo}addSdkMetadata(t){for(const e of t)-1===this.$o.indexOf(e)&&this.$o.push(e)}}
1
+ import qt from "../models/backend-errors.js";
2
+ import ue from "../models/braze-event.js";
3
+ import {
4
+ convertMsToSeconds as l,
5
+ convertSecondsToMs as Bt
6
+ } from "../util/date-utils.js";
7
+ import s from "../common/event-logger.js";
8
+ import { isArray as p, isEqual as ii } from "../util/code-utils.js";
9
+ import r from "../../shared-lib/braze-shared-lib.js";
10
+ import { STORAGE_KEYS as o } from "./storage-manager.js";
11
+ export default class Ot {
12
+ constructor(t, e, s, i, r, o, n, a, u, h, c) {
13
+ (this.Ur = t),
14
+ (this.h = e),
15
+ (this.Go = s),
16
+ (this.v = i),
17
+ (this.j = r),
18
+ (this.gt = o),
19
+ (this._r = n),
20
+ (this.zo = a),
21
+ (this.yo = u),
22
+ (this.Vo = h),
23
+ (this.$o = c),
24
+ (this.sa = ["npm"]);
25
+ }
26
+ Ps(t, e) {
27
+ const s = this.Ur.te(),
28
+ i = s.Mi(),
29
+ r = this.h.I(o.q.Xo);
30
+ ii(r, i) || (t.device = i),
31
+ (t.api_key = this._r),
32
+ (t.time = l(new Date().valueOf(), !0));
33
+ const n = this.h.I(o.q.oa) || [],
34
+ a = this.h.I(o.q.ua) || "";
35
+ if (
36
+ (this.sa.length > 0 &&
37
+ (!ii(n, this.sa) || a !== this.j.ha()) &&
38
+ (t.sdk_metadata = this.sa),
39
+ (t.sdk_version = this.yo),
40
+ this.Vo && (t.sdk_flavor = this.Vo),
41
+ (t.app_version = this.$o),
42
+ (t.device_id = s.id),
43
+ e)
44
+ ) {
45
+ const e = this.v.getUserId();
46
+ null != e && (t.user_id = e);
47
+ }
48
+ return t;
49
+ }
50
+ Os(t, e, i) {
51
+ const o = e.auth_error,
52
+ n = e.error;
53
+ if (!o && !n) return !0;
54
+ if (o) {
55
+ let e;
56
+ this.Go.Wn();
57
+ const s = { errorCode: o.error_code };
58
+ for (const t of i)
59
+ p(t) && "X-Braze-Auth-Signature" === t[0] && (s.signature = t[1]);
60
+ t.respond_with && t.respond_with.user_id
61
+ ? (s.userId = t.respond_with.user_id)
62
+ : t.user_id && (s.userId = t.user_id);
63
+ const n = o.reason;
64
+ return (
65
+ n
66
+ ? ((s.reason = n), (e = `due to ${n}`))
67
+ : (e = `with error code ${o.error_code}.`),
68
+ this.Go.Jn() ||
69
+ (e +=
70
+ ' Please use the "enableSdkAuthentication" initialization option to enable authentication.'),
71
+ r.D.error(`SDK Authentication failed ${e}`),
72
+ this.ca(t.events, t.attributes),
73
+ this.Go.Rn(s),
74
+ !1
75
+ );
76
+ }
77
+ if (n) {
78
+ let i = n;
79
+ switch (i) {
80
+ case qt.la:
81
+ const o = "Received successful response with empty body.";
82
+ return s.G(r.A.qs, { e: o }), r.D.info(o), !1;
83
+ case qt.fa:
84
+ const n = "Received successful response with invalid JSON";
85
+ return s.G(r.A.qs, { e: n + ": " + e.response }), r.D.info(n), !1;
86
+ case qt.ma:
87
+ i = `The API key "${t.api_key}" is invalid for the baseUrl ${this.zo}`;
88
+ break;
89
+ case qt.pa:
90
+ i =
91
+ "Sorry, we are not currently accepting your requests. If you think this is in error, please contact us.";
92
+ break;
93
+ case qt.Ra:
94
+ i = "No device identifier. Please contact support@braze.com";
95
+ }
96
+ r.D.error("Backend error: " + i);
97
+ }
98
+ return !1;
99
+ }
100
+ ba(t, e, s, i) {
101
+ return !!((t && 0 !== t.length) || (e && 0 !== e.length) || s || i);
102
+ }
103
+ ga(t, e, s, i) {
104
+ const r = [],
105
+ o = t => t || "",
106
+ n = o(this.v.getUserId());
107
+ let a,
108
+ u,
109
+ h,
110
+ c,
111
+ l = this.Ai(t, e);
112
+ if (s.length > 0) {
113
+ const t = [];
114
+ for (const e of s) {
115
+ if (((a = e.Mi()), this.Go.Jn())) {
116
+ if (n && !a.user_id) {
117
+ c || ((c = {}), (c.events = [])), c.events.push(a);
118
+ continue;
119
+ }
120
+ if (o(a.user_id) !== n) {
121
+ u || (u = []), u.push(a);
122
+ continue;
123
+ }
124
+ }
125
+ t.push(a);
126
+ }
127
+ t.length > 0 && (l.events = t);
128
+ }
129
+ if (i.length > 0) {
130
+ const t = [];
131
+ for (const e of i)
132
+ this.Go.Jn() && o(e.user_id) !== n
133
+ ? (h || (h = []), h.push(e))
134
+ : t.push(e);
135
+ t.length > 0 && (l.attributes = t);
136
+ }
137
+ if ((this.ca(u, h), (l = this.Ps(l, !0)), c)) {
138
+ c = this.Ps(c, !1);
139
+ const t = { requestData: c, headers: this.Bs(c) };
140
+ r.push(t);
141
+ }
142
+ if (l && !this.ba(l.events, l.attributes, t, e)) return c ? r : null;
143
+ const f = { requestData: l, headers: this.Bs(l) };
144
+ return r.push(f), r;
145
+ }
146
+ ca(t, e) {
147
+ if (t) {
148
+ const e = [];
149
+ for (const s of t) {
150
+ const t = ue.fromJson(s);
151
+ (t.time = Bt(t.time)), e.push(t);
152
+ }
153
+ this.h.bo(e);
154
+ }
155
+ if (e) for (const t of e) this.h.qa(t);
156
+ }
157
+ Vs(t, e) {
158
+ let s = "HTTP error ";
159
+ null != t && (s += t + " "), (s += e), r.D.error(s);
160
+ }
161
+ yr(t) {
162
+ return s.G(r.A.Aa, { n: t });
163
+ }
164
+ Ai(t, e, s) {
165
+ const i = {};
166
+ t && (i.feed = !0), e && (i.triggers = !0);
167
+ const r = null != s ? s : this.v.getUserId();
168
+ return (
169
+ r && (i.user_id = r),
170
+ (i.config = { config_time: this.gt.Zs() }),
171
+ { respond_with: i }
172
+ );
173
+ }
174
+ Bs(t, e, s, i) {
175
+ const r = [["X-Braze-Api-Key", this._r]];
176
+ let n = !1;
177
+ if (
178
+ (null != t.respond_with &&
179
+ t.respond_with.triggers &&
180
+ (r.push(["X-Braze-TriggersRequest", "true"]), (n = !0)),
181
+ null != t.respond_with &&
182
+ t.respond_with.feed &&
183
+ (r.push(["X-Braze-FeedRequest", "true"]), (n = !0)),
184
+ e)
185
+ ) {
186
+ r.push(["X-Braze-ContentCardsRequest", "true"]);
187
+ let t = this.h.I(o.q.As);
188
+ (t && i) || ((t = 0), this.h.B(o.q.As, t)),
189
+ r.push(["BRAZE-SYNC-RETRY-COUNT", t.toString()]),
190
+ (n = !0);
191
+ }
192
+ if (
193
+ (s && (r.push(["X-Braze-FeatureFlagsRequest", "true"]), (n = !0)),
194
+ n && r.push(["X-Braze-DataRequest", "true"]),
195
+ this.Go.Jn())
196
+ ) {
197
+ const t = this.Go.Kn();
198
+ null != t && r.push(["X-Braze-Auth-Signature", t]);
199
+ }
200
+ return r;
201
+ }
202
+ Gs(t, e) {
203
+ const s = t.device;
204
+ s && s.os_version instanceof Promise
205
+ ? s.os_version.then(s => {
206
+ (t.device.os_version = s), e();
207
+ })
208
+ : e();
209
+ }
210
+ Qs() {
211
+ this.Go.Qs();
212
+ }
213
+ Ks() {
214
+ return this.zo;
215
+ }
216
+ addSdkMetadata(t) {
217
+ for (const e of t) -1 === this.sa.indexOf(e) && this.sa.push(e);
218
+ }
219
+ }