From 50c3bcf859d6f3355d9f871eff2f7c2acb6b3c66 Mon Sep 17 00:00:00 2001 From: Ananthu Kanive Date: Fri, 16 Jan 2026 10:59:09 +0530 Subject: [PATCH] fix: introduce sanitizeBrokerList utility and update broker list handling --- src/SmallcaseGateway.js | 21 +++++++++++++-------- src/util.js | 11 +++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/SmallcaseGateway.js b/src/SmallcaseGateway.js index 36a0aa94..0c789c9b 100644 --- a/src/SmallcaseGateway.js +++ b/src/SmallcaseGateway.js @@ -1,6 +1,10 @@ -import { NativeModules, Platform } from 'react-native'; +import { NativeModules } from 'react-native'; import { ENV } from './constants'; -import { safeObject, platformSpecificColorHex } from './util'; +import { + safeObject, + platformSpecificColorHex, + sanitizeBrokerList, +} from './util'; import { version } from '../package.json'; const { SmallcaseGateway: SmallcaseGatewayNative } = NativeModules; @@ -64,7 +68,7 @@ const setConfigEnvironment = async (envConfig) => { const safeIsLeprechaun = Boolean(isLeprechaun); const safeIsAmoEnabled = Boolean(isAmoEnabled); - const safeBrokerList = Array.isArray(brokerList) ? brokerList : []; + const safeBrokerList = sanitizeBrokerList(brokerList); const safeGatewayName = typeof gatewayName === 'string' ? gatewayName : ''; const safeEnvName = typeof environmentName === 'string' ? environmentName : ENV.PROD; @@ -91,7 +95,7 @@ const setConfigEnvironment = async (envConfig) => { const init = async (sdkToken, externalMeta) => { const safeToken = typeof sdkToken === 'string' ? sdkToken : ''; const safeExternalMeta = externalMeta && typeof externalMeta === 'object' ? externalMeta : null; - + return SmallcaseGatewayNative.init(safeToken, safeExternalMeta); }; @@ -107,10 +111,11 @@ const triggerTransaction = async (transactionId, utmParams, brokerList) => { const safeUtm = safeObject(utmParams); const safeId = typeof transactionId === 'string' ? transactionId : ''; - const safeBrokerList = - Array.isArray(brokerList) && brokerList.length - ? brokerList - : defaultBrokerList; + let safeBrokerList = sanitizeBrokerList(brokerList); + + if (safeBrokerList.length === 0) { + safeBrokerList = defaultBrokerList; + } return SmallcaseGatewayNative.triggerTransaction( safeId, diff --git a/src/util.js b/src/util.js index f1bddd5b..6874881f 100644 --- a/src/util.js +++ b/src/util.js @@ -16,3 +16,14 @@ export function platformSpecificColorHex(hex) { } return hex } + +/** sanitize the input broker array to make sure its an array and only has string values */ +export function sanitizeBrokerList(arr) { + if (!Array.isArray(arr) || arr.length === 0) { + return []; + } + + return arr.filter((val) => { + return typeof val === 'string' && val.trim() !== ''; + }); +}