@braze/web-sdk 6.8.0 → 6.9.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.
- package/index.d.ts +99 -19
- package/package.json +1 -1
- package/shared-lib/event-types.js +20 -20
- package/shared-lib/indexed-db-adapter.js +64 -64
- package/shared-lib/logger.js +18 -18
- package/shared-lib/supported-options.js +8 -8
- package/src/Banner/banner-provider.js +67 -59
- package/src/Banner/banner.js +40 -19
- package/src/Banner/dismiss-banner.js +4 -0
- package/src/Banner/display/banner-to-html.js +10 -10
- package/src/Banner/display/destroy-banner-html.js +2 -2
- package/src/Banner/get-all-banners.js +6 -6
- package/src/Banner/get-banner.js +6 -6
- package/src/Banner/index.js +1 -0
- package/src/Banner/log-banner-click.js +7 -7
- package/src/Banner/log-banner-dismissal.js +7 -7
- package/src/Banner/log-banner-impressions.js +10 -10
- package/src/Banner/request-banners-refresh.js +8 -8
- package/src/Banner/subscribe-to-banners-updates.js +5 -5
- package/src/Banner/ui/insert-banner.js +8 -8
- package/src/Card/card-manager.js +31 -31
- package/src/Card/log-card-dismissal.js +2 -2
- package/src/Card/log-content-card-click.js +2 -2
- package/src/Card/log-content-card-impressions.js +4 -4
- package/src/Card/models/captioned-image.js +15 -15
- package/src/Card/models/card.js +89 -89
- package/src/Card/models/classic-card.js +16 -16
- package/src/Card/models/control-card.js +7 -7
- package/src/Card/models/image-only.js +13 -13
- package/src/Card/util/card-factory.js +32 -32
- package/src/ContentCards/content-cards-provider.js +102 -102
- package/src/ContentCards/get-cached-content-cards.js +1 -1
- package/src/ContentCards/subscribe-to-content-cards-updates.js +3 -3
- package/src/ContentCards/ui/show-content-cards.js +5 -5
- package/src/Core/add-sdk-metadata.js +2 -2
- package/src/Core/change-user.js +3 -3
- package/src/Core/destroy.js +2 -2
- package/src/Core/disable-sdk.js +4 -4
- package/src/Core/enable-sdk.js +4 -4
- package/src/Core/get-device-id.js +2 -2
- package/src/Core/handle-braze-action.js +5 -5
- package/src/Core/log-custom-event.js +5 -5
- package/src/Core/log-ecommerce-event.js +5 -5
- package/src/Core/log-purchase.js +9 -9
- package/src/Core/open-session.js +7 -7
- package/src/Core/set-logger.js +2 -2
- package/src/Core/toggle-logging.js +2 -2
- package/src/Core/wipe-data.js +6 -6
- package/src/DUST/dust-provider.js +249 -240
- package/src/DUST/dust-shared-worker-code.js +1 -1
- package/src/DUST/dust-shared-worker-impl.js +15 -14
- package/src/DUST/dust-worker-bridge.js +50 -35
- package/src/DUST/subscribe-to-dust.js +7 -7
- package/src/FeatureFlags/feature-flag-factory.js +8 -8
- package/src/FeatureFlags/feature-flag.js +3 -3
- package/src/FeatureFlags/feature-flags-provider.js +21 -21
- package/src/FeatureFlags/log-feature-flag-impression.js +5 -5
- package/src/FeatureFlags/subscribe-to-feature-flags-updates.js +1 -1
- package/src/InAppMessage/constants.js +3 -3
- package/src/InAppMessage/defer-in-app-message.js +4 -4
- package/src/InAppMessage/display/html-message-to-html.js +4 -4
- package/src/InAppMessage/display/in-app-message-to-html.js +16 -16
- package/src/InAppMessage/in-app-message-factory.js +36 -36
- package/src/InAppMessage/in-app-message-manager.js +78 -78
- package/src/InAppMessage/log-in-app-message-button-click.js +4 -4
- package/src/InAppMessage/log-in-app-message-click.js +3 -3
- package/src/InAppMessage/log-in-app-message-html-click.js +5 -5
- package/src/InAppMessage/log-in-app-message-impression.js +4 -4
- package/src/InAppMessage/models/control-message.js +4 -4
- package/src/InAppMessage/models/full-screen-message.js +4 -4
- package/src/InAppMessage/models/html-message.js +3 -3
- package/src/InAppMessage/models/in-app-message-button.js +4 -4
- package/src/InAppMessage/models/in-app-message.js +12 -12
- package/src/InAppMessage/models/modal-message.js +4 -4
- package/src/InAppMessage/models/slide-up-message.js +4 -4
- package/src/InAppMessage/models/templated-in-app-message.js +8 -8
- package/src/InAppMessage/subscribe-to-in-app-message.js +1 -1
- package/src/InAppMessage/ui/automatically-show-in-app-messages.js +3 -3
- package/src/InAppMessage/ui/show-in-app-message.js +14 -14
- package/src/Push/push-manager-factory.js +2 -2
- package/src/Push/push-manager.js +38 -38
- package/src/Push/utils/push-utils.js +6 -6
- package/src/User/user-manager.js +14 -14
- package/src/User/user.js +25 -25
- package/src/common/base-provider.js +1 -1
- package/src/common/content-cards-display.js +7 -7
- package/src/common/event-logger.js +3 -3
- package/src/common/properties-base.js +3 -3
- package/src/l10n/l10n-manager-factory.js +1 -1
- package/src/l10n/l10n-manager.js +3 -3
- package/src/managers/auth-manager.js +11 -11
- package/src/managers/braze-instance.js +56 -56
- package/src/managers/device-manager.js +10 -10
- package/src/managers/network-manager.js +102 -101
- package/src/managers/server-config-manager.js +115 -98
- package/src/managers/session-manager.js +20 -20
- package/src/managers/storage-manager-factory.js +9 -9
- package/src/managers/storage-manager.js +74 -74
- package/src/managers/subscription-manager.js +2 -2
- package/src/managers/utils.js +1 -1
- package/src/models/backend-errors.js +5 -5
- package/src/models/braze-event.js +1 -1
- package/src/models/device.js +1 -1
- package/src/models/identifier.js +2 -2
- package/src/models/push-token.js +6 -6
- package/src/models/request-result.js +1 -1
- package/src/models/server-config.js +42 -24
- package/src/request-controller.js +126 -126
- package/src/triggers/models/custom-event-data.js +4 -4
- package/src/triggers/models/custom-event-property-data.js +5 -5
- package/src/triggers/models/filter-set.js +2 -2
- package/src/triggers/models/filter.js +1 -1
- package/src/triggers/models/in-app-message-click-data.js +1 -1
- package/src/triggers/models/purchase-data.js +1 -1
- package/src/triggers/models/purchase-property-data.js +2 -2
- package/src/triggers/models/push-click-data.js +1 -1
- package/src/triggers/models/trigger-condition.js +33 -33
- package/src/triggers/models/trigger-events.js +1 -1
- package/src/triggers/models/trigger.js +33 -33
- package/src/triggers/triggers-provider-factory.js +1 -1
- package/src/triggers/triggers-provider.js +68 -68
- package/src/types.js +2 -2
- package/src/ui/js/attach-css.js +1 -1
- package/src/util/braze-actions.js +7 -7
- package/src/util/browser-detector.js +2 -2
- package/src/util/client-hints-parser.js +4 -4
- package/src/util/code-utils.js +2 -2
- package/src/util/deprecation-utils.js +2 -2
- package/src/util/dom-utils.js +7 -7
- package/src/util/ecommerce-event-validation.js +52 -35
- package/src/util/html-display-utils.js +11 -11
- package/src/util/net.js +4 -4
- package/src/util/request-header-utils.js +17 -17
- package/src/util/string-utils.js +2 -2
- package/src/util/user-agent-parser.js +2 -2
- package/src/util/validation-utils.js +12 -12
- package/src/util/window-utils.js +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const DUST_SHARED_WORKER_CODE =
|
|
2
|
-
'\n"use strict";\nconst workerSelf = self;\nlet eventSource = null;\nlet currentConfig = null;\nlet retryCount = 0;\nlet retryTimeoutId = null;\nlet connectionInProgress = false;\nconst maxRetries = 5;\nconst connectedPorts = new Map();\nlet lastSleepMs = null;\nlet currentRcs = null;\nlet ttlTimeoutId = null;\nlet leaderPortId = null;\nlet ddrTimeoutId = null;\nconst fn = {\n startConnection: null,\n handleMessage: null,\n};\nfunction broadcast(message) {\n connectedPorts.forEach((portInfo, portId) => {\n try {\n portInfo.port.postMessage(message);\n }\n catch (_a) {\n connectedPorts.delete(portId);\n }\n });\n}\nfunction randomInclusive(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nfunction electLeader() {\n if (leaderPortId && connectedPorts.has(leaderPortId)) {\n return;\n }\n const firstPortId = connectedPorts.keys().next().value;\n leaderPortId = firstPortId || null;\n if (leaderPortId) {\n console.log("[Braze Real-Time] Elected leader port:", leaderPortId);\n }\n}\nfunction promoteToLeader(portId) {\n if (connectedPorts.has(portId) && leaderPortId !== portId) {\n leaderPortId = portId;\n console.log("[Braze Real-Time] Promoted to leader (tab became active):", portId);\n }\n}\nfunction sendToLeader(message) {\n electLeader();\n if (!leaderPortId) {\n console.warn("[Braze Real-Time] No leader to send message to");\n return;\n }\n const leader = connectedPorts.get(leaderPortId);\n if (leader) {\n try {\n leader.port.postMessage(message);\n }\n catch (_a) {\n connectedPorts.delete(leaderPortId);\n leaderPortId = null;\n sendToLeader(message);\n }\n }\n}\nfunction closeConnection() {\n connectionInProgress = false;\n if (retryTimeoutId !== null) {\n clearTimeout(retryTimeoutId);\n retryTimeoutId = null;\n }\n if (ttlTimeoutId !== null) {\n clearTimeout(ttlTimeoutId);\n ttlTimeoutId = null;\n }\n if (ddrTimeoutId !== null) {\n clearTimeout(ddrTimeoutId);\n ddrTimeoutId = null;\n }\n if (eventSource) {\n eventSource.close();\n eventSource = null;\n broadcast({ type: "disconnected" });\n }\n}\nfunction retryWithBackoff() {\n if (!currentConfig) {\n return;\n }\n retryCount++;\n const { minSleepMs, maxSleepMs, scaleFactor } = currentConfig.backoff;\n let previousSleepMs = lastSleepMs;\n if (previousSleepMs == null || previousSleepMs < minSleepMs) {\n previousSleepMs = minSleepMs;\n }\n const backoffMs = Math.min(maxSleepMs, randomInclusive(minSleepMs, previousSleepMs * scaleFactor));\n lastSleepMs = backoffMs;\n console.log(`[Braze Real-Time] Retrying in ${backoffMs}ms (attempt ${retryCount}/${maxRetries})`);\n retryTimeoutId = setTimeout(function () {\n retryTimeoutId = null;\n fn.startConnection();\n }, backoffMs);\n}\nfunction startConnection(oldEventSourceToClose) {\n if (!currentConfig) {\n return;\n }\n if (eventSource && !oldEventSourceToClose) {\n console.warn("[Braze Real-Time] Connection already exists");\n return;\n }\n if (connectionInProgress && !oldEventSourceToClose) {\n console.warn("[Braze Real-Time] Connection attempt already in progress");\n return;\n }\n connectionInProgress = true;\n const { dustHost, mite, auth } = currentConfig;\n const dustHostWithScheme = /^https?:\\/\\//i.test(dustHost) ? dustHost : `https://${dustHost}`;\n let queryString = `mite=${encodeURIComponent(mite)}&attempts=${retryCount}`;\n if (auth) {\n queryString += `&auth=${encodeURIComponent(auth)}`;\n }\n if (currentRcs) {\n queryString += `&rcs=${encodeURIComponent(currentRcs)}`;\n }\n const subscribeUrl = `${dustHostWithScheme}/sse?${queryString}`;\n try {\n const newEventSource = new EventSource(subscribeUrl);\n newEventSource.onopen = function () {\n if (oldEventSourceToClose) {\n console.log("[Braze Real-Time] Gapless reconnection: new connection established, closing old connection");\n oldEventSourceToClose.close();\n }\n else {\n console.log("[Braze Real-Time] Connection established");\n }\n eventSource = newEventSource;\n connectionInProgress = false;\n retryCount = 0;\n lastSleepMs = null;\n broadcast({ type: "connected" });\n };\n newEventSource.addEventListener("msg", function (event) {\n fn.handleMessage(event.data);\n });\n newEventSource.onerror = function () {\n const readyState = newEventSource ? newEventSource.readyState : -1;\n if (readyState === 0) {\n console.log("[Braze Real-Time] Failed to connect");\n }\n else {\n console.log("[Braze Real-Time] Connection lost");\n }\n if (oldEventSourceToClose && eventSource !== newEventSource) {\n console.log("[Braze Real-Time] Gapless reconnection failed, keeping old connection");\n newEventSource.close();\n connectionInProgress = false;\n if (retryCount < maxRetries) {\n retryWithBackoff();\n }\n return;\n }\n closeConnection();\n if (retryCount < maxRetries) {\n retryWithBackoff();\n }\n else {\n console.error("[Braze Real-Time] Max retries reached");\n broadcast({ type: "error", error: "Max retry attempts reached" });\n }\n };\n }\n catch (error) {\n connectionInProgress = false;\n console.error("[Braze Real-Time] Failed to create EventSource:", error);\n broadcast({ type: "error", error: String(error) });\n }\n}\nfunction handleTtlMessage(tMs, rcs) {\n if (typeof tMs !== "number") {\n return;\n }\n if (typeof rcs === "string") {\n currentRcs = rcs;\n }\n console.log(`[Braze Real-Time] TTL set to ${tMs}ms, will perform gapless reconnection when expired`);\n if (ttlTimeoutId !== null) {\n clearTimeout(ttlTimeoutId);\n }\n ttlTimeoutId = setTimeout(function () {\n ttlTimeoutId = null;\n console.log("[Braze Real-Time] TTL expired, performing gapless reconnection");\n startConnection(eventSource || undefined);\n }, tMs);\n}\nfunction handleDdrMessage(rMs, reason) {\n if (typeof rMs !== "number") {\n return;\n }\n const backoffConfig = currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.backoff;\n const minSleepMs = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.minSleepMs) || 10000;\n const scaleFactor = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.scaleFactor) || 3;\n const maxSleepMs = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.maxSleepMs) || 300000;\n const backoffMs = Math.min(maxSleepMs, randomInclusive(minSleepMs, minSleepMs * scaleFactor));\n const waitMs = Math.round(rMs + backoffMs);\n const reasonStr = reason ? ` (${reason})` : "";\n console.log(`[Braze Real-Time] Admin requested disconnect${reasonStr}, reconnecting in ${waitMs}ms (r_ms=${rMs} + backoff=${backoffMs})`);\n if (ddrTimeoutId !== null) {\n clearTimeout(ddrTimeoutId);\n }\n closeConnection();\n ddrTimeoutId = setTimeout(function () {\n ddrTimeoutId = null;\n fn.startConnection();\n }, waitMs);\n}\nfunction handleMessage(data) {\n try {\n const message = JSON.parse(data);\n if (!message.type) {\n console.warn("[Braze Real-Time] Message without type:", message);\n return;\n }\n if (message.type === "ttl" && message.body) {\n handleTtlMessage(message.body.t_ms, message.body.rcs);\n return;\n }\n if (message.type === "ddr" && message.body) {\n handleDdrMessage(message.body.r_ms, message.body.e);\n return;\n }\n console.log(`[Braze Real-Time] Routing \'${message.type}\' message to leader`);\n sendToLeader({ type: "message", data: message });\n }\n catch (error) {\n console.warn("[Braze Real-Time] Failed to parse message:", error);\n }\n}\nfn.startConnection = startConnection;\nfn.handleMessage = handleMessage;\nfunction handlePortMessage(port, portId, message) {\n switch (message.type) {\n case "connect":\n if (currentConfig &&\n (currentConfig.mite !== message.config.mite || currentConfig.dustHost !== message.config.dustHost)) {\n console.log("[Braze Real-Time] Config changed, reconnecting");\n closeConnection();\n retryCount = 0;\n lastSleepMs = null;\n currentRcs = null;\n }\n currentConfig = message.config;\n electLeader();\n if (!eventSource && !connectionInProgress) {\n startConnection();\n }\n else if (eventSource) {\n port.postMessage({ type: "connected" });\n }\n break;\n case "disconnect":\n connectedPorts.delete(portId);\n if (portId === leaderPortId) {\n leaderPortId = null;\n electLeader();\n }\n if (connectedPorts.size === 0) {\n console.log("[Braze Real-Time] No more ports, closing connection");\n closeConnection();\n currentConfig = null;\n currentRcs = null;\n leaderPortId = null;\n }\n break;\n case "tab_active":\n promoteToLeader(portId);\n break;\n case "ping":\n port.postMessage({ type: "pong" });\n break;\n default:\n console.warn("[Braze Real-Time] Unknown message type:", message.type);\n }\n}\nworkerSelf.onconnect = function (event) {\n const port = event.ports[0];\n const portId = `port-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n connectedPorts.set(portId, { port: port });\n port.onmessage = function (messageEvent) {\n try {\n handlePortMessage(port, portId, messageEvent.data);\n }\n catch (error) {\n console.error("[Braze Real-Time] Error handling message:", error);\n }\n };\n port.onmessageerror = function () {\n console.warn("[Braze Real-Time] Message error from port:", portId);\n connectedPorts.delete(portId);\n };\n port.start();\n};\n';
|
|
2
|
+
'\n"use strict";\nconst workerSelf = self;\nlet eventSource = null;\nlet currentConfig = null;\nlet retryCount = 0;\nlet retryTimeoutId = null;\nlet connectionInProgress = false;\nconst maxRetries = 5;\nconst connectedPorts = new Map();\nlet lastSleepMs = null;\nlet currentRcs = null;\nlet ttlTimeoutId = null;\nlet leaderPortId = null;\nlet ddrTimeoutId = null;\nconst fn = {\n startConnection: null,\n handleMessage: null,\n};\nfunction broadcast(message) {\n connectedPorts.forEach((portInfo, portId) => {\n try {\n portInfo.port.postMessage(message);\n }\n catch (_a) {\n connectedPorts.delete(portId);\n }\n });\n}\nfunction randomInclusive(min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nfunction electLeader() {\n if (leaderPortId && connectedPorts.has(leaderPortId)) {\n return;\n }\n const firstPortId = connectedPorts.keys().next().value;\n leaderPortId = firstPortId || null;\n if (leaderPortId) {\n console.log("[Braze Real-Time] Elected leader port:", leaderPortId);\n }\n}\nfunction promoteToLeader(portId) {\n if (connectedPorts.has(portId) && leaderPortId !== portId) {\n leaderPortId = portId;\n console.log("[Braze Real-Time] Promoted to leader (tab became active):", portId);\n }\n}\nfunction sendToLeader(message) {\n electLeader();\n if (!leaderPortId) {\n console.warn("[Braze Real-Time] No leader to send message to");\n return;\n }\n const leader = connectedPorts.get(leaderPortId);\n if (leader) {\n try {\n leader.port.postMessage(message);\n }\n catch (_a) {\n connectedPorts.delete(leaderPortId);\n leaderPortId = null;\n sendToLeader(message);\n }\n }\n}\nfunction closeConnection() {\n connectionInProgress = false;\n if (retryTimeoutId !== null) {\n clearTimeout(retryTimeoutId);\n retryTimeoutId = null;\n }\n if (ttlTimeoutId !== null) {\n clearTimeout(ttlTimeoutId);\n ttlTimeoutId = null;\n }\n if (ddrTimeoutId !== null) {\n clearTimeout(ddrTimeoutId);\n ddrTimeoutId = null;\n }\n if (eventSource) {\n eventSource.close();\n eventSource = null;\n broadcast({ type: "disconnected" });\n }\n}\nfunction retryWithBackoff() {\n if (!currentConfig) {\n return;\n }\n retryCount++;\n const { minSleepMs, maxSleepMs, scaleFactor } = currentConfig.backoff;\n let previousSleepMs = lastSleepMs;\n if (previousSleepMs == null || previousSleepMs < minSleepMs) {\n previousSleepMs = minSleepMs;\n }\n const backoffMs = Math.min(maxSleepMs, randomInclusive(minSleepMs, previousSleepMs * scaleFactor));\n lastSleepMs = backoffMs;\n console.log(`[Braze Real-Time] Retrying in ${backoffMs}ms (attempt ${retryCount}/${maxRetries})`);\n retryTimeoutId = setTimeout(function () {\n retryTimeoutId = null;\n fn.startConnection();\n }, backoffMs);\n}\nfunction startConnection(oldEventSourceToClose) {\n if (!currentConfig) {\n return;\n }\n if (eventSource && !oldEventSourceToClose) {\n console.warn("[Braze Real-Time] Connection already exists");\n return;\n }\n if (connectionInProgress && !oldEventSourceToClose) {\n console.warn("[Braze Real-Time] Connection attempt already in progress");\n return;\n }\n connectionInProgress = true;\n const { dustHost, mite, auth } = currentConfig;\n const dustHostWithScheme = /^https?:\\/\\//i.test(dustHost) ? dustHost : `https://${dustHost}`;\n let queryString = `mite=${encodeURIComponent(mite)}&attempts=${retryCount}`;\n if (auth) {\n queryString += `&auth=${encodeURIComponent(auth)}`;\n }\n if (currentRcs) {\n queryString += `&rcs=${encodeURIComponent(currentRcs)}`;\n }\n const subscribeUrl = `${dustHostWithScheme}/sse?${queryString}`;\n try {\n const newEventSource = new EventSource(subscribeUrl);\n newEventSource.onopen = function () {\n if (oldEventSourceToClose) {\n console.log("[Braze Real-Time] Gapless reconnection: new connection established, closing old connection");\n oldEventSourceToClose.close();\n }\n else {\n console.log("[Braze Real-Time] Connection established");\n }\n eventSource = newEventSource;\n connectionInProgress = false;\n retryCount = 0;\n lastSleepMs = null;\n broadcast({ type: "connected" });\n };\n newEventSource.addEventListener("msg", function (event) {\n fn.handleMessage(event.data);\n });\n newEventSource.onerror = function () {\n const readyState = newEventSource ? newEventSource.readyState : -1;\n if (readyState === 0) {\n console.log("[Braze Real-Time] Failed to connect");\n }\n else {\n console.log("[Braze Real-Time] Connection lost");\n }\n if (oldEventSourceToClose && eventSource !== newEventSource) {\n console.log("[Braze Real-Time] Gapless reconnection failed, keeping old connection");\n newEventSource.close();\n connectionInProgress = false;\n if (retryCount < maxRetries) {\n retryWithBackoff();\n }\n return;\n }\n closeConnection();\n if (retryCount < maxRetries) {\n retryWithBackoff();\n }\n else {\n console.error("[Braze Real-Time] Max retries reached");\n broadcast({ type: "error", error: "Max retry attempts reached" });\n }\n };\n }\n catch (error) {\n connectionInProgress = false;\n console.error("[Braze Real-Time] Failed to create EventSource:", error);\n broadcast({ type: "error", error: String(error) });\n }\n}\nfunction handleTtlMessage(tMs, rcs) {\n if (typeof tMs !== "number") {\n return;\n }\n if (typeof rcs === "string") {\n currentRcs = rcs;\n }\n console.log(`[Braze Real-Time] TTL set to ${tMs}ms, will perform gapless reconnection when expired`);\n if (ttlTimeoutId !== null) {\n clearTimeout(ttlTimeoutId);\n }\n ttlTimeoutId = setTimeout(function () {\n ttlTimeoutId = null;\n console.log("[Braze Real-Time] TTL expired, performing gapless reconnection");\n startConnection(eventSource || undefined);\n }, tMs);\n}\nfunction handleDdrMessage(rMs, reason) {\n if (typeof rMs !== "number") {\n return;\n }\n const backoffConfig = currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.backoff;\n const minSleepMs = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.minSleepMs) || 10000;\n const scaleFactor = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.scaleFactor) || 3;\n const maxSleepMs = (backoffConfig === null || backoffConfig === void 0 ? void 0 : backoffConfig.maxSleepMs) || 300000;\n const backoffMs = Math.min(maxSleepMs, randomInclusive(minSleepMs, minSleepMs * scaleFactor));\n const waitMs = Math.round(rMs + backoffMs);\n const reasonStr = reason ? ` (${reason})` : "";\n console.log(`[Braze Real-Time] Admin requested disconnect${reasonStr}, reconnecting in ${waitMs}ms (r_ms=${rMs} + backoff=${backoffMs})`);\n if (ddrTimeoutId !== null) {\n clearTimeout(ddrTimeoutId);\n }\n closeConnection();\n ddrTimeoutId = setTimeout(function () {\n ddrTimeoutId = null;\n fn.startConnection();\n }, waitMs);\n}\nfunction handleMessage(data) {\n try {\n const message = JSON.parse(data);\n if (!message.type) {\n console.warn("[Braze Real-Time] Message without type:", message);\n return;\n }\n if (message.type === "ttl" && message.body) {\n handleTtlMessage(message.body.t_ms, message.body.rcs);\n return;\n }\n if (message.type === "ddr" && message.body) {\n handleDdrMessage(message.body.r_ms, message.body.e);\n return;\n }\n console.log(`[Braze Real-Time] Routing \'${message.type}\' message to leader`);\n sendToLeader({ type: "message", data: message });\n }\n catch (error) {\n console.warn("[Braze Real-Time] Failed to parse message:", error);\n }\n}\nfn.startConnection = startConnection;\nfn.handleMessage = handleMessage;\nfunction handlePortMessage(port, portId, message) {\n switch (message.type) {\n case "connect":\n if (currentConfig &&\n (currentConfig.mite !== message.config.mite || currentConfig.dustHost !== message.config.dustHost)) {\n console.log("[Braze Real-Time] Config changed, reconnecting");\n closeConnection();\n retryCount = 0;\n lastSleepMs = null;\n currentRcs = null;\n }\n currentConfig = message.config;\n if (!connectedPorts.has(portId)) {\n connectedPorts.set(portId, { port: port });\n }\n electLeader();\n if (!eventSource && !connectionInProgress) {\n startConnection();\n }\n else if (eventSource) {\n port.postMessage({ type: "connected" });\n }\n break;\n case "disconnect":\n connectedPorts.delete(portId);\n if (portId === leaderPortId) {\n leaderPortId = null;\n electLeader();\n }\n if (connectedPorts.size === 0) {\n console.log("[Braze Real-Time] No more ports, closing connection");\n closeConnection();\n currentConfig = null;\n currentRcs = null;\n leaderPortId = null;\n }\n break;\n case "tab_active":\n promoteToLeader(portId);\n break;\n case "ping":\n port.postMessage({ type: "pong" });\n break;\n default:\n console.warn("[Braze Real-Time] Unknown message type:", message.type);\n }\n}\nworkerSelf.onconnect = function (event) {\n const port = event.ports[0];\n const portId = `port-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n connectedPorts.set(portId, { port: port });\n port.onmessage = function (messageEvent) {\n try {\n handlePortMessage(port, portId, messageEvent.data);\n }\n catch (error) {\n console.error("[Braze Real-Time] Error handling message:", error);\n }\n };\n port.onmessageerror = function () {\n console.warn("[Braze Real-Time] Message error from port:", portId);\n connectedPorts.delete(portId);\n };\n port.start();\n};\n';
|
|
@@ -10,7 +10,7 @@ let ue = null,
|
|
|
10
10
|
de = null,
|
|
11
11
|
fe = null,
|
|
12
12
|
pe = null;
|
|
13
|
-
const Te = { Tn: null,
|
|
13
|
+
const Te = { Tn: null, qe: null };
|
|
14
14
|
function Re(e) {
|
|
15
15
|
se.forEach((n, o) => {
|
|
16
16
|
try {
|
|
@@ -50,7 +50,7 @@ function ze() {
|
|
|
50
50
|
function Be() {
|
|
51
51
|
if (!le) return;
|
|
52
52
|
ce++;
|
|
53
|
-
const { Rn: e,
|
|
53
|
+
const { Rn: e, zn: n, Bn: o } = le.Mn;
|
|
54
54
|
let t = ue;
|
|
55
55
|
(null == t || t < e) && (t = e);
|
|
56
56
|
const l = Math.min(n, a(e, t * o));
|
|
@@ -74,9 +74,9 @@ function ye(e) {
|
|
|
74
74
|
let c = `mite=${encodeURIComponent(o)}&attempts=${ce}`;
|
|
75
75
|
t && (c += `&auth=${encodeURIComponent(t)}`),
|
|
76
76
|
me && (c += `&rcs=${encodeURIComponent(me)}`);
|
|
77
|
-
const
|
|
77
|
+
const r = `${l}/sse?${c}`;
|
|
78
78
|
try {
|
|
79
|
-
const n = new EventSource(
|
|
79
|
+
const n = new EventSource(r);
|
|
80
80
|
(n.onopen = function () {
|
|
81
81
|
e
|
|
82
82
|
? (console.log(
|
|
@@ -91,7 +91,7 @@ function ye(e) {
|
|
|
91
91
|
Re({ type: "connected" });
|
|
92
92
|
}),
|
|
93
93
|
n.addEventListener("msg", function (e) {
|
|
94
|
-
Te.
|
|
94
|
+
Te.qe(e.data);
|
|
95
95
|
}),
|
|
96
96
|
(n.onerror = function () {
|
|
97
97
|
if (
|
|
@@ -124,13 +124,14 @@ function $e(e, n, o) {
|
|
|
124
124
|
switch (o.type) {
|
|
125
125
|
case "connect":
|
|
126
126
|
!le ||
|
|
127
|
-
(le.mite === o.
|
|
127
|
+
(le.mite === o.Cn.mite && le.Wi === o.Cn.Wi) ||
|
|
128
128
|
(console.log("[Braze Real-Time] Config changed, reconnecting"),
|
|
129
129
|
ze(),
|
|
130
130
|
(ce = 0),
|
|
131
131
|
(ue = null),
|
|
132
132
|
(me = null)),
|
|
133
|
-
(le = o.
|
|
133
|
+
(le = o.Cn),
|
|
134
|
+
se.has(n) || se.set(n, { port: e }),
|
|
134
135
|
ge(),
|
|
135
136
|
te || ie ? te && e.postMessage({ type: "connected" }) : ye();
|
|
136
137
|
break;
|
|
@@ -163,15 +164,15 @@ function $e(e, n, o) {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
(Te.Tn = ye),
|
|
166
|
-
(Te.
|
|
167
|
+
(Te.qe = function (e) {
|
|
167
168
|
try {
|
|
168
169
|
const t = JSON.parse(e);
|
|
169
170
|
if (!t.type)
|
|
170
171
|
return void console.warn("[Braze Real-Time] Message without type:", t);
|
|
171
172
|
if ("ttl" === t.type && t.body)
|
|
172
173
|
return (
|
|
173
|
-
(n = t.body.
|
|
174
|
-
(o = t.body.
|
|
174
|
+
(n = t.body.t_ms),
|
|
175
|
+
(o = t.body.rcs),
|
|
175
176
|
void (
|
|
176
177
|
"number" == typeof n &&
|
|
177
178
|
("string" == typeof o && (me = o),
|
|
@@ -191,10 +192,10 @@ function $e(e, n, o) {
|
|
|
191
192
|
if ("ddr" === t.type && t.body)
|
|
192
193
|
return void (function (e, n) {
|
|
193
194
|
if ("number" != typeof e) return;
|
|
194
|
-
const o = null == le ? void 0 : le
|
|
195
|
+
const o = null == le ? void 0 : le.Mn,
|
|
195
196
|
t = (null == o ? void 0 : o.Rn) || 1e4,
|
|
196
|
-
l = (null == o ? void 0 : o.
|
|
197
|
-
c = (null == o ? void 0 : o.
|
|
197
|
+
l = (null == o ? void 0 : o.Bn) || 3,
|
|
198
|
+
c = (null == o ? void 0 : o.zn) || 3e5,
|
|
198
199
|
r = Math.min(c, a(t, t * l)),
|
|
199
200
|
i = Math.round(e + r),
|
|
200
201
|
s = n ? ` (${n})` : "";
|
|
@@ -206,7 +207,7 @@ function $e(e, n, o) {
|
|
|
206
207
|
(pe = setTimeout(function () {
|
|
207
208
|
(pe = null), Te.Tn();
|
|
208
209
|
}, i));
|
|
209
|
-
})(t.body.
|
|
210
|
+
})(t.body.r_ms, t.body.e);
|
|
210
211
|
console.log(`[Braze Real-Time] Routing '${t.type}' message to leader`),
|
|
211
212
|
he({ type: "message", data: t });
|
|
212
213
|
} catch (e) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger as
|
|
1
|
+
import { logger as b } from "../../shared-lib/index.js";
|
|
2
2
|
import { DUST_SHARED_WORKER_CODE as ri } from "./dust-shared-worker-code.js";
|
|
3
3
|
export function isSharedWorkerSupported() {
|
|
4
4
|
return "undefined" != typeof SharedWorker;
|
|
@@ -8,17 +8,17 @@ export class DustWorkerBridge {
|
|
|
8
8
|
(this.Wr = null),
|
|
9
9
|
(this.Rr = null),
|
|
10
10
|
(this.isConnected = !1),
|
|
11
|
+
(this.Mr = null),
|
|
11
12
|
(this.Lr = null),
|
|
12
|
-
(this.
|
|
13
|
-
(this.
|
|
14
|
-
(this.
|
|
15
|
-
(this.
|
|
16
|
-
(this.Le = i.Le);
|
|
13
|
+
(this.Pe = i.Pe),
|
|
14
|
+
(this.He = i.He),
|
|
15
|
+
(this.Le = i.Le),
|
|
16
|
+
(this.Oe = i.Oe);
|
|
17
17
|
}
|
|
18
18
|
initialize() {
|
|
19
19
|
if (!isSharedWorkerSupported())
|
|
20
20
|
return (
|
|
21
|
-
|
|
21
|
+
b.info("SharedWorker not supported, will use direct connection"), !1
|
|
22
22
|
);
|
|
23
23
|
try {
|
|
24
24
|
const i = new Blob([ri], { type: "application/javascript" });
|
|
@@ -26,29 +26,29 @@ export class DustWorkerBridge {
|
|
|
26
26
|
(this.Rr = URL.createObjectURL(i)),
|
|
27
27
|
(this.Wr = new SharedWorker(this.Rr, { name: "braze-dust-worker" })),
|
|
28
28
|
(this.Wr.port.onmessage = (i) => {
|
|
29
|
-
this.
|
|
29
|
+
this.Ir(i.data);
|
|
30
30
|
}),
|
|
31
31
|
(this.Wr.port.onmessageerror = () => {
|
|
32
|
-
|
|
32
|
+
b.warn("Message error from real-time messaging worker");
|
|
33
33
|
}),
|
|
34
34
|
(this.Wr.onerror = (i) => {
|
|
35
35
|
var e;
|
|
36
|
-
|
|
36
|
+
b.error(
|
|
37
37
|
`Real-time messaging worker error: ${i.message || "unknown error"}`,
|
|
38
38
|
),
|
|
39
|
-
null === (e = this.
|
|
39
|
+
null === (e = this.Oe) ||
|
|
40
40
|
void 0 === e ||
|
|
41
41
|
e.call(this, "SharedWorker error");
|
|
42
42
|
}),
|
|
43
43
|
this.Wr.port.start(),
|
|
44
44
|
this.Ur(),
|
|
45
45
|
this.Vr(),
|
|
46
|
-
|
|
46
|
+
b.info("Real-time messaging worker initialized"),
|
|
47
47
|
!0
|
|
48
48
|
);
|
|
49
49
|
} catch (i) {
|
|
50
50
|
return (
|
|
51
|
-
|
|
51
|
+
b.error(
|
|
52
52
|
`Failed to create real-time messaging worker: ${
|
|
53
53
|
i instanceof Error ? i.message : String(i)
|
|
54
54
|
}`,
|
|
@@ -58,64 +58,79 @@ export class DustWorkerBridge {
|
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
Ir(i) {
|
|
62
62
|
var e, t, s;
|
|
63
63
|
switch (i.type) {
|
|
64
64
|
case "connected":
|
|
65
|
-
|
|
65
|
+
b.info("Real-time messaging connection established via SharedWorker"),
|
|
66
66
|
(this.isConnected = !0),
|
|
67
|
-
null === (e = this.
|
|
67
|
+
null === (e = this.He) || void 0 === e || e.call(this);
|
|
68
68
|
break;
|
|
69
69
|
case "disconnected":
|
|
70
|
-
|
|
70
|
+
b.info("Real-time messaging connection closed via SharedWorker"),
|
|
71
71
|
(this.isConnected = !1),
|
|
72
|
-
null === (t = this.
|
|
72
|
+
null === (t = this.Le) || void 0 === t || t.call(this);
|
|
73
73
|
break;
|
|
74
|
-
case "message":
|
|
75
|
-
|
|
74
|
+
case "message": {
|
|
75
|
+
const e = i.data,
|
|
76
|
+
t = { type: e.type };
|
|
77
|
+
null != e.body && (t.body = e.body), this.Pe(t);
|
|
76
78
|
break;
|
|
79
|
+
}
|
|
77
80
|
case "error":
|
|
78
|
-
|
|
79
|
-
null === (s = this.
|
|
81
|
+
b.error(`Real-time messaging error: ${i.error}`),
|
|
82
|
+
null === (s = this.Oe) || void 0 === s || s.call(this, i.error);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
Ur() {
|
|
83
|
-
this.
|
|
86
|
+
this.Mr = window.setInterval(() => {
|
|
84
87
|
this.Wr && this.Gr({ type: "ping" });
|
|
85
88
|
}, 3e4);
|
|
86
89
|
}
|
|
87
90
|
Jr() {
|
|
88
|
-
null !== this.
|
|
91
|
+
null !== this.Mr && (window.clearInterval(this.Mr), (this.Mr = null));
|
|
89
92
|
}
|
|
90
93
|
Vr() {
|
|
91
|
-
(this.
|
|
94
|
+
(this.Lr = () => {
|
|
92
95
|
"visible" === document.visibilityState &&
|
|
93
96
|
this.Wr &&
|
|
94
97
|
this.Gr({ type: "tab_active" });
|
|
95
98
|
}),
|
|
96
|
-
document.addEventListener("visibilitychange", this.
|
|
99
|
+
document.addEventListener("visibilitychange", this.Lr);
|
|
97
100
|
}
|
|
98
101
|
Kr() {
|
|
99
|
-
this.
|
|
100
|
-
(document.removeEventListener("visibilitychange", this.
|
|
101
|
-
(this.
|
|
102
|
+
this.Lr &&
|
|
103
|
+
(document.removeEventListener("visibilitychange", this.Lr),
|
|
104
|
+
(this.Lr = null));
|
|
102
105
|
}
|
|
103
106
|
Gr(i) {
|
|
104
107
|
this.Wr && this.Wr.port.postMessage(i);
|
|
105
108
|
}
|
|
106
109
|
connect(i) {
|
|
107
110
|
this.Wr
|
|
108
|
-
? (this.Gr({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
? (this.Gr({
|
|
112
|
+
type: "connect",
|
|
113
|
+
config: {
|
|
114
|
+
mite: i.mite,
|
|
115
|
+
dustHost: i.dustHost,
|
|
116
|
+
auth: i.auth,
|
|
117
|
+
backoff: {
|
|
118
|
+
minSleepMs: i.backoff.minSleepMs,
|
|
119
|
+
maxSleepMs: i.backoff.maxSleepMs,
|
|
120
|
+
scaleFactor: i.backoff.scaleFactor,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
b.info("Connecting to real-time messaging"))
|
|
125
|
+
: b.error("Cannot connect: real-time messaging worker not initialized");
|
|
111
126
|
}
|
|
112
127
|
disconnect() {
|
|
113
128
|
this.Wr &&
|
|
114
129
|
(this.Gr({ type: "disconnect" }),
|
|
115
130
|
(this.isConnected = !1),
|
|
116
|
-
|
|
131
|
+
b.info("Disconnecting from real-time messaging"));
|
|
117
132
|
}
|
|
118
|
-
|
|
133
|
+
Ke() {
|
|
119
134
|
return this.isConnected;
|
|
120
135
|
}
|
|
121
136
|
isInitialized() {
|
|
@@ -131,6 +146,6 @@ export class DustWorkerBridge {
|
|
|
131
146
|
destroy() {
|
|
132
147
|
this.disconnect(),
|
|
133
148
|
this._r(),
|
|
134
|
-
|
|
149
|
+
b.info("Real-time messaging worker destroyed");
|
|
135
150
|
}
|
|
136
151
|
}
|
|
@@ -6,19 +6,19 @@ export function subscribeToDust() {
|
|
|
6
6
|
if (!t || !n) return null;
|
|
7
7
|
const o = dr.o(),
|
|
8
8
|
s = () => {
|
|
9
|
-
if (!o.
|
|
10
|
-
o.
|
|
9
|
+
if (!o.Et()) {
|
|
10
|
+
o.cn();
|
|
11
11
|
const r = n.rn(() => {
|
|
12
|
-
t.
|
|
12
|
+
t.fn() && o.mn();
|
|
13
13
|
});
|
|
14
|
-
return r && o
|
|
14
|
+
return r && o.Lt(r), o.un() && o.an(), r;
|
|
15
15
|
}
|
|
16
|
-
return o.
|
|
16
|
+
return o.Et();
|
|
17
17
|
};
|
|
18
18
|
return (
|
|
19
19
|
t.Tr(() => {
|
|
20
|
-
r.ao() && (t.
|
|
20
|
+
r.ao() && (t.fn() ? (o.mn(), s()) : (o.hn(), o.un() && o.en()));
|
|
21
21
|
}),
|
|
22
|
-
t.
|
|
22
|
+
t.fn() ? s() : null
|
|
23
23
|
);
|
|
24
24
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { logger as
|
|
1
|
+
import { logger as b } from "../../shared-lib/index.js";
|
|
2
2
|
import FeatureFlag from "./feature-flag.js";
|
|
3
3
|
export function newFeatureFlagFromJson(e) {
|
|
4
|
-
if (e[FeatureFlag.
|
|
4
|
+
if (e[FeatureFlag.ei.qs] && "boolean" == typeof e[FeatureFlag.ei.Nr])
|
|
5
5
|
return new FeatureFlag(
|
|
6
|
-
e[FeatureFlag.
|
|
7
|
-
e[FeatureFlag.
|
|
8
|
-
e[FeatureFlag.
|
|
9
|
-
e[FeatureFlag.
|
|
6
|
+
e[FeatureFlag.ei.qs],
|
|
7
|
+
e[FeatureFlag.ei.Nr],
|
|
8
|
+
e[FeatureFlag.ei.Or],
|
|
9
|
+
e[FeatureFlag.ei.Qr],
|
|
10
10
|
);
|
|
11
|
-
|
|
11
|
+
b.info(`Unable to create feature flag from ${JSON.stringify(e, null, 2)}`);
|
|
12
12
|
}
|
|
13
13
|
export function newFeatureFlagFromSerializedValue(e) {
|
|
14
14
|
if (e[FeatureFlag.bs.qs] && "boolean" == typeof e[FeatureFlag.bs.Nr])
|
|
@@ -18,7 +18,7 @@ export function newFeatureFlagFromSerializedValue(e) {
|
|
|
18
18
|
e[FeatureFlag.bs.Or],
|
|
19
19
|
e[FeatureFlag.bs.Qr],
|
|
20
20
|
);
|
|
21
|
-
|
|
21
|
+
b.info(
|
|
22
22
|
`Unable to deserialize feature flag from ${JSON.stringify(e, null, 2)}`,
|
|
23
23
|
);
|
|
24
24
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PropertiesBase as
|
|
2
|
-
export default class FeatureFlag extends
|
|
1
|
+
import { PropertiesBase as D } from "../common/properties-base.js";
|
|
2
|
+
export default class FeatureFlag extends D {
|
|
3
3
|
constructor(s, t = !1, i = {}, e) {
|
|
4
4
|
super(i),
|
|
5
5
|
(this.id = s),
|
|
@@ -21,4 +21,4 @@ export default class FeatureFlag extends x {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
(FeatureFlag.bs = { qs: "id", Nr: "e", Or: "pr", Qr: "fts" }),
|
|
24
|
-
(FeatureFlag.
|
|
24
|
+
(FeatureFlag.ei = { qs: "id", Nr: "enabled", Or: "properties", Qr: "fts" });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger as
|
|
1
|
+
import { logger as b } from "../../shared-lib/index.js";
|
|
2
2
|
import t from "../common/base-provider.js";
|
|
3
3
|
import r from "../managers/braze-instance.js";
|
|
4
4
|
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
|
|
@@ -20,14 +20,14 @@ export default class ar extends t {
|
|
|
20
20
|
super(),
|
|
21
21
|
(this.h = t),
|
|
22
22
|
(this.B = s),
|
|
23
|
-
(this.
|
|
24
|
-
(this.
|
|
23
|
+
(this.j = i),
|
|
24
|
+
(this.C = e),
|
|
25
25
|
(this.Xr = []),
|
|
26
26
|
(this.Yr = 0),
|
|
27
27
|
(this.h = t),
|
|
28
28
|
(this.B = s),
|
|
29
|
-
(this.
|
|
30
|
-
(this.
|
|
29
|
+
(this.j = i),
|
|
30
|
+
(this.C = e),
|
|
31
31
|
(this.Zr = null),
|
|
32
32
|
(this.ho = new f()),
|
|
33
33
|
(this.D = 10),
|
|
@@ -35,7 +35,7 @@ export default class ar extends t {
|
|
|
35
35
|
(this.F = null),
|
|
36
36
|
r.S(this.ho);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
q(t) {
|
|
39
39
|
var s;
|
|
40
40
|
if (
|
|
41
41
|
(null === (s = this.h) || void 0 === s ? void 0 : s.lo()) &&
|
|
@@ -52,7 +52,7 @@ export default class ar extends t {
|
|
|
52
52
|
}
|
|
53
53
|
vo() {
|
|
54
54
|
let t = {};
|
|
55
|
-
this.
|
|
55
|
+
this.j && (t = this.j.St(s.It.Fo));
|
|
56
56
|
const i = {};
|
|
57
57
|
for (const s in t) {
|
|
58
58
|
const e = ht(t[s]);
|
|
@@ -63,14 +63,14 @@ export default class ar extends t {
|
|
|
63
63
|
po() {
|
|
64
64
|
var t;
|
|
65
65
|
return (
|
|
66
|
-
(null === (t = this.
|
|
66
|
+
(null === (t = this.j) || void 0 === t ? void 0 : t.St(s.It.jo)) || {}
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
wo(t) {
|
|
70
|
-
this.
|
|
70
|
+
this.j && this.j.Pt(s.It.jo, t);
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
return this.ho.
|
|
72
|
+
Kt(t) {
|
|
73
|
+
return this.ho.Ut(t);
|
|
74
74
|
}
|
|
75
75
|
refreshFeatureFlags(t, s, i = !1, e = !0) {
|
|
76
76
|
const r = () => {
|
|
@@ -97,7 +97,7 @@ export default class ar extends t {
|
|
|
97
97
|
const o = this.B;
|
|
98
98
|
if (!o) return void r();
|
|
99
99
|
const v = new Date().valueOf();
|
|
100
|
-
h.nt(this.
|
|
100
|
+
h.nt(this.j, h.it.Co, v),
|
|
101
101
|
-1 !== e && u.push(["X-Braze-Req-Tokens-Remaining", e.toString()]),
|
|
102
102
|
l.ot({
|
|
103
103
|
url: `${o.ht()}/feature_flags/sync`,
|
|
@@ -105,7 +105,7 @@ export default class ar extends t {
|
|
|
105
105
|
data: n,
|
|
106
106
|
lt: (s) => {
|
|
107
107
|
if (!o.ut(n, s, u)) return (f = !0), void r();
|
|
108
|
-
o.ct(), this.
|
|
108
|
+
o.ct(), this.q(s), (f = !1), "function" == typeof t && t();
|
|
109
109
|
},
|
|
110
110
|
error: (t) => {
|
|
111
111
|
o.dt(t, "retrieving feature flags"), (f = !0), r();
|
|
@@ -156,12 +156,12 @@ export default class ar extends t {
|
|
|
156
156
|
if (null == t) return !1;
|
|
157
157
|
let s = !1;
|
|
158
158
|
if (!isNaN(t)) {
|
|
159
|
-
if (-1 === t) return
|
|
159
|
+
if (-1 === t) return b.info("Feature flag refreshes not allowed"), !1;
|
|
160
160
|
s = new Date().getTime() >= (this.Yr || 0) + 1e3 * t;
|
|
161
161
|
}
|
|
162
162
|
if (!s)
|
|
163
163
|
return (
|
|
164
|
-
|
|
164
|
+
b.info(`Feature flag refreshes were rate limited to ${t} seconds`), !1
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
167
|
return this.h.lo();
|
|
@@ -169,29 +169,29 @@ export default class ar extends t {
|
|
|
169
169
|
To() {
|
|
170
170
|
var t;
|
|
171
171
|
return (
|
|
172
|
-
(null === (t = this.
|
|
172
|
+
(null === (t = this.j) || void 0 === t ? void 0 : t.St(s.It.Do)) || null
|
|
173
173
|
);
|
|
174
174
|
}
|
|
175
175
|
Io() {
|
|
176
176
|
var t, i;
|
|
177
|
-
null === (t = this.
|
|
177
|
+
null === (t = this.j) ||
|
|
178
178
|
void 0 === t ||
|
|
179
|
-
t.
|
|
179
|
+
t.Pt(s.It.Do, null === (i = this.C) || void 0 === i ? void 0 : i.$t());
|
|
180
180
|
}
|
|
181
181
|
So() {
|
|
182
182
|
var t;
|
|
183
|
-
const s = null === (t = this.
|
|
183
|
+
const s = null === (t = this.C) || void 0 === t ? void 0 : t.$t(),
|
|
184
184
|
i = this.To();
|
|
185
185
|
return null == i || s === i;
|
|
186
186
|
}
|
|
187
187
|
do() {
|
|
188
|
-
if (!this.
|
|
188
|
+
if (!this.j) return;
|
|
189
189
|
const t = {};
|
|
190
190
|
for (const s of this.Xr) {
|
|
191
191
|
const i = s.qt();
|
|
192
192
|
t[s.id] = i;
|
|
193
193
|
}
|
|
194
|
-
this.
|
|
194
|
+
this.j.Pt(s.It.Fo, t), this.j.Pt(s.It.qo, this.Yr), this.Io();
|
|
195
195
|
}
|
|
196
196
|
changeUser() {
|
|
197
197
|
this.Y();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger as
|
|
1
|
+
import { logger as b, EventTypes as p } from "../../shared-lib/index.js";
|
|
2
2
|
import v from "../common/event-logger.js";
|
|
3
3
|
import r from "../managers/braze-instance.js";
|
|
4
4
|
import lr from "./feature-flags-provider-factory.js";
|
|
@@ -8,18 +8,18 @@ export function logFeatureFlagImpression(e) {
|
|
|
8
8
|
const t =
|
|
9
9
|
"Not logging a feature flag impression. The feature flag was not part of any matching experiment.",
|
|
10
10
|
o = lr.o().vo();
|
|
11
|
-
if (!o[e]) return
|
|
11
|
+
if (!o[e]) return b.info(t), !1;
|
|
12
12
|
const n = o[e].trackingString;
|
|
13
|
-
if (!n) return
|
|
13
|
+
if (!n) return b.info(t), !1;
|
|
14
14
|
const i = lr.o().po();
|
|
15
15
|
if (i[n])
|
|
16
16
|
return (
|
|
17
|
-
|
|
17
|
+
b.info(
|
|
18
18
|
"Not logging another feature flag impression. This ID was already logged this session.",
|
|
19
19
|
),
|
|
20
20
|
!1
|
|
21
21
|
);
|
|
22
22
|
(i[n] = !0), lr.o().wo(i);
|
|
23
23
|
const s = { fid: e, fts: n };
|
|
24
|
-
return v.
|
|
24
|
+
return v.Dt(p.xo, s).lt;
|
|
25
25
|
}
|
|
@@ -51,7 +51,7 @@ export const IamSerializationKeys = {
|
|
|
51
51
|
rE: "m",
|
|
52
52
|
mE: "ma",
|
|
53
53
|
GE: "sf",
|
|
54
|
-
|
|
54
|
+
Is: "e",
|
|
55
55
|
FE: "ti",
|
|
56
56
|
HE: "ca",
|
|
57
57
|
URI: "u",
|
|
@@ -59,7 +59,7 @@ export const IamSerializationKeys = {
|
|
|
59
59
|
BE: "dt",
|
|
60
60
|
lE: "d",
|
|
61
61
|
bE: "i",
|
|
62
|
-
|
|
62
|
+
Bs: "iu",
|
|
63
63
|
gE: "is",
|
|
64
64
|
YE: "ic",
|
|
65
65
|
KE: "ibc",
|
|
@@ -81,5 +81,5 @@ export const IamSerializationKeys = {
|
|
|
81
81
|
qE: "messageFields",
|
|
82
82
|
JE: "me",
|
|
83
83
|
LANGUAGE: "l",
|
|
84
|
-
|
|
84
|
+
Ns: "ia",
|
|
85
85
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import InAppMessage from "./models/in-app-message.js";
|
|
2
2
|
import r from "../managers/braze-instance.js";
|
|
3
3
|
import ControlMessage from "./models/control-message.js";
|
|
4
|
-
import { logger as
|
|
4
|
+
import { logger as b } from "../../shared-lib/index.js";
|
|
5
5
|
import je from "./in-app-message-manager-factory.js";
|
|
6
6
|
export function deferInAppMessage(e) {
|
|
7
7
|
if (r.rr())
|
|
8
8
|
return e instanceof ControlMessage
|
|
9
|
-
? (
|
|
9
|
+
? (b.info("Not deferring since this is a ControlMessage."), !1)
|
|
10
10
|
: e instanceof InAppMessage
|
|
11
|
-
? je.ra().
|
|
12
|
-
: (
|
|
11
|
+
? je.ra().jn(e)
|
|
12
|
+
: (b.info("Not an instance of InAppMessage, ignoring."), !1);
|
|
13
13
|
}
|
|
@@ -2,15 +2,15 @@ import ro from "../../util/browser-detector.js";
|
|
|
2
2
|
import { logInAppMessageHtmlClick } from "../index.js";
|
|
3
3
|
import { OperatingSystems as so } from "../../util/device-constants.js";
|
|
4
4
|
import { buildHtmlClickHandler as ct } from "./html-message-display-utils.js";
|
|
5
|
-
import { attachHtmlToIframeWithNonce as
|
|
6
|
-
import { buildBrazeBridge as
|
|
5
|
+
import { attachHtmlToIframeWithNonce as N } from "../../util/html-display-utils.js";
|
|
6
|
+
import { buildBrazeBridge as E } from "../../util/html-display-utils.js";
|
|
7
7
|
import { IamServerTypes as dt } from "../constants.js";
|
|
8
8
|
export default function ft(t, o, s, e, n) {
|
|
9
9
|
const i = document.createElement("iframe");
|
|
10
10
|
i.setAttribute("title", "Modal Message"),
|
|
11
11
|
e && (i.style.zIndex = (e + 1).toString());
|
|
12
12
|
if (
|
|
13
|
-
(
|
|
13
|
+
(N(i, t.message, n),
|
|
14
14
|
(i.onload = () => {
|
|
15
15
|
const e = i.contentWindow;
|
|
16
16
|
e.focus();
|
|
@@ -31,7 +31,7 @@ export default function ft(t, o, s, e, n) {
|
|
|
31
31
|
const r = Object.assign(
|
|
32
32
|
Object.assign(
|
|
33
33
|
{},
|
|
34
|
-
|
|
34
|
+
E(i, (o, s) => t.tl(o, s)),
|
|
35
35
|
),
|
|
36
36
|
{
|
|
37
37
|
closeMessage: function () {
|