Skip to content

Commit

Permalink
Merge pull request #104 from colorfy-software/master
Browse files Browse the repository at this point in the history
Add TypeScript support
  • Loading branch information
biancalui-emarsys authored May 7, 2024
2 parents f2951de + 59b50c8 commit 518f83a
Show file tree
Hide file tree
Showing 9 changed files with 724 additions and 591 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ DerivedData

*.xcuserstate


*.hprof

# Android/IntelliJ
Expand All @@ -44,7 +43,6 @@ local.properties
npm-debug.log
yarn-error.log


# BUCK
buck-out/
\.buckd/
Expand All @@ -66,3 +64,4 @@ buck-out/
*.bundle
sample/ios/Podfile.lock
sample/android/app/google-services.json
typescript/*
267 changes: 139 additions & 128 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,137 +1,148 @@
import { NativeModules, NativeEventEmitter } from 'react-native';
import { NativeModules, NativeEventEmitter } from "react-native";

const { RNEmarsysWrapper } = NativeModules;

import Push from './src/push';
import InApp, { InlineInAppView } from './src/inapp';
import Inbox from './src/inbox';
import Predict from './src/predict';
import Geofence from './src/geofence';
import Push from "./src/push";
import Inbox from "./src/inbox";
import Predict from "./src/predict";
import Geofence from "./src/geofence";
import InApp, { InlineInAppView } from "./src/inapp";

const Emarsys = {

/* Init ***************************************************************************************************************************************/

/**
* @desc After application setup is finished, you can use setContact method to identify the user with a contactFieldValue.
* Without setContact all events will be tracked as anonymous usage.
* @param required string contactFieldValue - user identification
* @param required integer contactFieldId - field used for identification
* @return bool - success or failure
*/
setContact(contactFieldId, contactFieldValue) {
return RNEmarsysWrapper.setContact(contactFieldId, contactFieldValue)
},

/**
* @desc When the user signs out, we should use the clearContact method.
* The method is going to automatically log in an anonymous user instead of the one leaving.
* @return bool - success or failure
*/
clearContact() {
return RNEmarsysWrapper.clearContact()
},

/**
* @desc If you want to track custom events, the trackCustomEvent method should be used.
* @param required string eventName - Name of tracked custom event.
* @param object eventAttributes - Attributes of tracked custom event.
* @return bool - success or failure
*/
trackCustomEvent(eventName, eventAttributes) {
return RNEmarsysWrapper.trackCustomEvent(eventName, eventAttributes ? eventAttributes : null)
},

/**
* @desc Register an event handler to react to events triggered by Emarsys.
* @param function (eventName, payload) callback function receiving events
* @return bool - success or failure
*/
setEventHandler(callback) {
const eventEmitter = new NativeEventEmitter(RNEmarsysWrapper);
eventEmitter.addListener('handleEvent', function (result) {
callback(result.eventName, result.payload);
});
RNEmarsysWrapper.setEventHandler();
},

/* DeepLink ***********************************************************************************************************************************/

/**
* @desc The Emarsys SDK automatically tracks email link clicks that open the application directly in most use cases, with only one exception: manual tracking is needed.
* @param string url - Track URL
* @return bool - success or failure
*/
trackDeepLink(url) {
return RNEmarsysWrapper.trackDeepLink(url)
},

/* Config ***********************************************************************************************************************************/

/**
* @desc Emarsys SDK provides a solution for applicationCode change in a convenient way without restarting the SDK.
* @param string applicationCode - applicationCode for change
* @return bool - success or failure
*/
changeApplicationCode(applicationCode) {
return RNEmarsysWrapper.changeApplicationCode(applicationCode)
},

/**
* @desc Emarsys SDK provides a solution for merchantId change in a convenient way without restarting the SDK.
* @param string merchantId - merchantId for change
* @return bool - success or failure
*/
changeMerchantId(merchantId) {
return RNEmarsysWrapper.changeMerchantId(merchantId)
},

/**
* @desc Provides what is the actual applicationCode set in the SDK.
* @return string - applicationCode
*/
getApplicationCode() {
return RNEmarsysWrapper.getApplicationCode()
},

/**
* @desc Provides what is the actual merchantId set in the SDK.
* @return string - merchantId
*/
getMerchantId() {
return RNEmarsysWrapper.getMerchantId()
},

/**
* @desc Provides what is the actual contactFieldId set in the SDK.
* @return integer - contactFieldId
*/
getContactFieldId() {
return RNEmarsysWrapper.getContactFieldId()
},

getHardwareId() {
return RNEmarsysWrapper.getHardwareId()
},

getLanguageCode() {
return RNEmarsysWrapper.getLanguageCode()
},

getSdkVersion() {
return RNEmarsysWrapper.getSdkVersion()
},

push: Push,
inApp: InApp,
InlineInAppView,
inbox: Inbox,
predict: Predict,
geofence: Geofence,

/* Init ***************************************************************************************************************************************/

/**
* After application setup is finished, you can use `setContact()` method to identify the user with a `contactFieldValue`.
* Without `setContact()` all events will be tracked as anonymous usage.
* @param {number} contactFieldId - Field used for identification.
* @param {string} contactFieldValue - User identification.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
setContact(contactFieldId, contactFieldValue) {
return RNEmarsysWrapper.setContact(contactFieldId, contactFieldValue);
},

/**
* When the user signs out, we should use the `clearContact()` method.
* The method is going to automatically log in an anonymous user instead of the one leaving.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
clearContact() {
return RNEmarsysWrapper.clearContact();
},

/**
* If you want to track custom events, the `trackCustomEvent()` method should be used.
* @param {string} eventName - Name of the tracked custom event.
* @param {Record<string, unknown> | undefined} eventAttributes - Object containing the attributes of the tracked custom event.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
trackCustomEvent(eventName, eventAttributes = null) {
return RNEmarsysWrapper.trackCustomEvent(eventName, eventAttributes);
},

/**
* Register an event handler to react to events triggered by Emarsys.
* @param {(eventName: string, payload: unknown) => void} callback - Function receiving `eventName` & `payload` for
* each event.
* @returns {void}
*/
setEventHandler(callback) {
const eventEmitter = new NativeEventEmitter(RNEmarsysWrapper);
eventEmitter.addListener("handleEvent", function (result) {
callback(result.eventName, result.payload);
});
RNEmarsysWrapper.setEventHandler();
},

/* DeepLink ***********************************************************************************************************************************/

/**
* The Emarsys SDK automatically tracks email link clicks that open the application directly in most use cases, with only one exception: manual tracking is needed.
* @param {string} url - URL to track.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
trackDeepLink(url) {
return RNEmarsysWrapper.trackDeepLink(url);
},

/* Config ***********************************************************************************************************************************/

/**
* Emarsys SDK provides a solution for `applicationCode` change in a convenient way without restarting the SDK.
* @param {string} applicationCode - New `applicationCode` string to change for.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
changeApplicationCode(applicationCode) {
return RNEmarsysWrapper.changeApplicationCode(applicationCode);
},

/**
* Emarsys SDK provides a solution for `merchantId` change in a convenient way without restarting the SDK.
* @param {string} merchantId - New `merchantId` string to change for.
* @returns {Promise<boolean>} Promise with success or failure boolean.
*/
changeMerchantId(merchantId) {
return RNEmarsysWrapper.changeMerchantId(merchantId);
},

/**
* Provides what is the actual applicationCode set in the SDK.
* @returns {Promise<string>} Currently set `applicationCode` string.
*/
getApplicationCode() {
return RNEmarsysWrapper.getApplicationCode();
},

/**
* Provides what is the actual merchantId set in the SDK.
* @returns {Promise<string>} Currently set `merchantId` string.
*/
getMerchantId() {
return RNEmarsysWrapper.getMerchantId();
},

/**
* Provides what is the actual contactFieldId set in the SDK.
* @returns {Promise<number>} Currently set `contactFieldId` number.
*/
getContactFieldId() {
return RNEmarsysWrapper.getContactFieldId();
},

/**
* Provides what is the actual `hardwareId` set in the SDK.
* @returns {Promise<string>} Current `hardwareId` string.
*/
getHardwareId() {
return RNEmarsysWrapper.getHardwareId();
},

/**
* Provides what is the actual `languageCode` set in the SDK.
* @returns {Promise<string>} Current `languageCode` string.
*/
getLanguageCode() {
return RNEmarsysWrapper.getLanguageCode();
},

/**
* Provides what is the actual `sdkVersion` in the SDK.
* @returns {Promise<string>} String of the current Emarsys SDK version.
*/
getSdkVersion() {
return RNEmarsysWrapper.getSdkVersion();
},

push: Push,
inApp: InApp,
inbox: Inbox,
InlineInAppView,
predict: Predict,
geofence: Geofence,
};

export default Emarsys;

import { version } from './package.json';
RNEmarsysWrapper.trackCustomEvent('wrapper:init', { type: 'react-native', version })
import { version } from "./package.json";
RNEmarsysWrapper.trackCustomEvent("wrapper:init", { type: "react-native", version });
45 changes: 27 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
{
"name": "react-native-emarsys-wrapper",
"version": "1.17.0",
"description": "React Native wrapper for Emarsys SDK",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"react-native",
"Emarsys"
],
"author": "emarsys",
"license": "MIT",
"peerDependencies": {
"react": ">=17.0.2",
"react-native": ">=0.67.3"
}
"name": "react-native-emarsys-wrapper",
"version": "1.17.0",
"description": "React Native wrapper for Emarsys SDK",
"main": "index.js",
"types": "typescript/index.d.ts",
"type": "module",
"scripts": {
"prepare": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"react-native",
"Emarsys"
],
"author": "emarsys",
"license": "MIT",
"devDependencies": {
"typescript": ">=3.7.2"
},
"peerDependencies": {
"@types/jest": "*",
"@types/react": "*",
"@tsconfig/react-native": "*",
"@types/react-test-renderer": "*",
"react": ">=17.0.2",
"react-native": ">=0.67.3"
}
}
Loading

0 comments on commit 518f83a

Please sign in to comment.