UNPKG

smartech-base-react-native

Version:
250 lines (240 loc) 9.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNative = require("react-native"); var _NativeSmartechBaseReactNative = _interopRequireDefault(require("./specs/NativeSmartechBaseReactNative")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const SmartechEventEmitter = _reactNative.Platform.select({ ios: new _reactNative.NativeEventEmitter(_NativeSmartechBaseReactNative.default), android: _reactNative.DeviceEventEmitter }); function defaultCallback(method, err, res) { if (err) { console.log('Smartech ' + method + ' default callback error', err); } else { console.log('Smartech ' + method + ' default callback result', res); } } // Used to handle callback function callWithCallback(method, args, callback) { if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') { callback = (err, res) => { defaultCallback(method, err, res); }; } if (args == null) { args = []; } args.push(callback); _NativeSmartechBaseReactNative.default[method].apply(this, args); } // Store event subscriptions for cleanup const eventMap = {}; var SmartechBaseReact = { // All the constants declared in the Smartech React Bridge. SmartechDeeplink: _NativeSmartechBaseReactNative.default.getConstants().SmartechDeeplink, SmartechWidgetDataReceived: _NativeSmartechBaseReactNative.default.getConstants().SmartechWidgetDataReceived, // This method is used to register listener. addListener: function (eventName, handler) { if (SmartechEventEmitter) { const subscription = SmartechEventEmitter.addListener(eventName, handler); if (eventName == 'SmartechDeeplink') { _NativeSmartechBaseReactNative.default.setDeeplinkInit(); } // Store in eventMap for backward compatibility eventMap[eventName] = subscription; // Return subscription so user can remove it manually return subscription; } return undefined; }, // This method is used to unregister registered listener. removeListener: function (eventName) { if (eventMap[eventName]) { eventMap[eventName].remove(); delete eventMap[eventName]; } }, /** * This method is used to track app update event. * This method should be called by the developer to track the app updates event to Smartech. */ trackAppInstall: function () { _NativeSmartechBaseReactNative.default.trackAppInstall(); }, /** * This method is used to track app update event. * This method should be called by the developer to track the app updates event to Smartech. */ trackAppUpdate: function () { _NativeSmartechBaseReactNative.default.trackAppUpdate(); }, /** * This method is used to track app install or update event by Smartech SDK itself. * This method should be called by the developer to track the app install or update event by Smartech SDK itself. * If you are calling this method then you should not call trackAppInstall or trackAppUpdate method. */ trackAppInstallUpdateBySmartech: function () { _NativeSmartechBaseReactNative.default.trackAppInstallUpdateBySmartech(); }, /** * This method is used to track custom event done by the user. * This method should be called by the developer to track any custom activites * that is performed by the user in the app to Smartech backend. */ trackEvent: function (eventName, payload) { _NativeSmartechBaseReactNative.default.trackEvent(eventName, payload); }, /** * This method is used to send login event to Smartech backend. * This method should be called only when the app gets the user's identity * or when the user does a login activity in the application. */ login: function (identity) { _NativeSmartechBaseReactNative.default.login(identity); }, /** * This method would logout the user and clear identity on Smartech backend. * This method should be called only when the user log out of the application. */ logoutAndClearUserIdentity: function (isLougoutClearIdentity) { _NativeSmartechBaseReactNative.default.logoutAndClearUserIdentity(isLougoutClearIdentity); }, /** * This method would set the user identity locally and with all subsequent events this identity will be send. * This method should be called only when the user gets the identity. */ setUserIdentity: function (identity, callback) { callWithCallback('setUserIdentity', [identity], callback); }, /** * This method would get the user identity that is stored in the SDK. * This method should be called to get the user's identity. */ getUserIdentity: function (callback) { callWithCallback('getUserIdentity', null, callback); }, /** * This method would clear the identity that is stored in the SDK. * This method will clear the user's identity by removing it from. */ clearUserIdentity: function () { _NativeSmartechBaseReactNative.default.clearUserIdentity(); }, /** * This method is used to update the user profile. * This method should be called by the developer to update all the user related attributes to Smartech. */ updateUserProfile: function (profilePayload) { _NativeSmartechBaseReactNative.default.updateUserProfile(profilePayload); }, // ----- GDPR Methods ----- /** * This method is used to opt tracking. * If you call this method then we will opt in or opt out the user of tracking. */ optTracking: function (isTrackingOpted) { _NativeSmartechBaseReactNative.default.optTracking(isTrackingOpted); }, /** * This method is used to get the current status of opt tracking. * If you call this method you will get the current status of the tracking which can be used to render the UI at app level. */ hasOptedTracking: function (callback) { callWithCallback('hasOptedTracking', null, callback); }, /** * This method is used to opt in-app messages. * If you call this method then we will opt in or opt out the user of in-app messages. */ optInAppMessage: function (isInappOpted) { _NativeSmartechBaseReactNative.default.optInAppMessage(isInappOpted); }, /** * This method is used to get the current status of opt in-app messages. * If you call this method you will get the current status of the opt in-app messages which can be used to render the UI at app level. */ hasOptedInAppMessage: function (callback) { callWithCallback('hasOptedInAppMessage', null, callback); }, // ----- Location Methods ----- /** * This method is used to set the user's location to the SDK. * You need to call this method to set location which will be passed on the Smartech SDK. */ setUserLocation: function (latitude, longitude) { _NativeSmartechBaseReactNative.default.setUserLocation(latitude, longitude); }, // ----- Helper Methods ----- /** * This method is used to get the app id used by the Smartech SDK. * If you call this method you will get the app id used by the Smartech SDK. */ getAppId: function (callback) { callWithCallback('getAppId', null, callback); }, /** * Retrieves the Unbxd identity by the Smartech SDK.. */ getNetcoreUnbxdIdentity: function (callback) { callWithCallback('getNetcoreUnbxdIdentity', null, callback); }, /** * Retrieves the Partner parameters by the Smartech SDK.. */ getPartnerParametersString: function (callback) { callWithCallback('getPartnerParametersString', null, callback); }, /** * This method is used to get the device unique id used by Smartech SDK. * If you call this method you will get the device unique id which is used to identify a device on Smartech. */ getDeviceGuid: function (callback) { callWithCallback('getDeviceGuid', null, callback); }, /** * This method is used to get the current Smartech SDK version. * If you call this method you will get the current Smartech SDK version used inside the app. */ getSDKVersion: function (callback) { callWithCallback('getSDKVersion', null, callback); }, /** * This method is used to get all widget names. * If you call this method you will get an array of all widget names. */ getAllWidgetNames: function (callback) { callWithCallback('getAllWidgetNames', null, callback); }, /** * This method is used to get widget by name. * This method should be called with a specific widget name. */ getWidgetByName: function (widgetName) { _NativeSmartechBaseReactNative.default.getWidgetByName(widgetName); }, /** * This method is used to get widgets by names. * This method should be called with an array of widget names. */ getWidgetByNames: function (widgetNames) { _NativeSmartechBaseReactNative.default.getWidgetByNames(widgetNames); }, /** * This method is used to get all widgets. * This method will fetch all available widgets. */ getAllWidgets: function () { _NativeSmartechBaseReactNative.default.getAllWidgets(); }, trackWidgetAsViewed: function (widget) { _NativeSmartechBaseReactNative.default.trackWidgetAsViewed(widget); }, trackWidgetAsClicked: function (widget) { _NativeSmartechBaseReactNative.default.trackWidgetAsClicked(widget); } }; var _default = exports.default = SmartechBaseReact; //module.exports = SmartechBaseReact; //# sourceMappingURL=index.js.map