diff --git a/.gitignore b/.gitignore index e6ffda7c8..9e847acd6 100755 --- a/.gitignore +++ b/.gitignore @@ -67,9 +67,9 @@ lib/ # examples examples/ios/* -react-native-connect-0.0.1.tgz -react-native-phyllo-connect-0.0.1.tgz +*.tgz .env .vscode package-lock.json -example/package-lock.json \ No newline at end of file +example/package-lock.json +example/config.js \ No newline at end of file diff --git a/Issues.md b/Issues.md new file mode 100644 index 000000000..9ce8d2bdd --- /dev/null +++ b/Issues.md @@ -0,0 +1,32 @@ +# Facing any issues? + +1. **Execution failed for task ':app:processDebugMainManifest'.**\ + +> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @66b22ec6 + +If you are facing this error on Android run, modify android/app/src/main/AndroidManifest.xml set `allowBackup` to `True` + +```sh + +``` + +
+
+ +2. **Execution failed for task ':app:processDebugMainManifest'.** + +> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @66b22ec6 + +If you are facing this error on Android, modify android/gradle.properties and add the following line at the end + +```sh +org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED +``` + +3. **Specs satisfying the PhylloConnect (~> 0.1.21) dependency were found, but they required a higher minimum deployment target** + > [!] CocoaPods could not find compatible versions for pod "PhylloConnect":react-native-phyllo-connect (from ../node_modules/react-native-phyllo-connect) was resolved to X.Y.Z, which depends on PhylloConnect (~> X.Y.Z) + +If your issue not listed here, raise an issue in the [issues section](https://github.com/getphyllo/phyllo-connect-reactnative/issues) or report your issue on [#bug-reports](https://discord.com/channels/897097781355888640/949535402845405184) channel of our [Discord server](https://discord.com/channels/897097781355888640/). diff --git a/README.md b/README.md index df8f1282e..0b7f778ec 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ ## Configuring the SDK -In your react-native project directory: +In your React Native project directory: ```sh npm install react-native-phyllo-connect @@ -25,31 +25,34 @@ Then install iOS dependencies using cocoapods:\ cd ios && pod install ``` -## React native implementation +## React Native implementation -### Import and create an instace +### Importing from react-native-phyllo-connect ```sh -// import the PhylloConnect to your application import PhylloConnect from 'react-native-phyllo-connect' - -// create an instance of PhylloConnect -const phylloConnect = new PhylloConnect() ``` ### Subscribing to events ```sh // Subscribe to an event by passing a callback -const eventWatcher = phylloConnect.addAnEventListener('', callbackFunction) +PhylloConnect.on('', callbackFunction) -// Unsubscribe with remove -eventWatcher.remove() +const callbackFunction = (body) => { + // callback body +} ``` -here event type can be `onExit`, `onAccountConnected`, `onAccountDisconnected`, `onTokenExpired`. +Event types can be `exit`, `accountConnected`, `accountDisconnected`, or `tokenExpired`. +| Event type | Description | Callback body| +| -----------| ------------| --------- | +| exit | Called when a user exits from phyllo flow| user_id, reason | +| accountConnected | Called when a user connects a platform| user_id, account_id, work_platform_id | +| accountDisconnected | Called when a user disconnects a platform| user_id, account_id, work_platform_id | +| tokenExpired | Called when a user token expires| user_id | -Creating a user and token for a user +### Creating a user and token - [Check this document on creating a user](https://docs.getphyllo.com/docs/api-reference/b3A6MTQwNjEzNzY-create-a-user) - [Check this document on creating a user token](https://docs.getphyllo.com/docs/api-reference/b3A6MTQwNjEzNzc-create-an-sdk-token) @@ -57,23 +60,34 @@ Creating a user and token for a user ### Open Phyllo SDK flow ```sh -phylloConnect.initialize({ clientDisplayName, userId, token, platformId, env}); +import { PhylloEnvironment } from 'react-native-phyllo-connect' + +const config = { + clientDisplayName: clientDisplayName, + token: token, + userId: userId, + environment: PhylloEnvironment., + workPlatformId: workPlatformId, +} + +const phylloConnect = PhylloConnect.initialize(config) +phylloConnect.open() ``` -| Arguments | Value | Type | -| ----------------- | ----------------------- | ------------------------------------------ | -| clientDisplayName | Application Name | String | -| userId | User Id | String | -| token | User Token | String | -| platformId | Platform Id | String or Undefined | -| env | Development Environment | "development" or "production" or "sandbox" | +| Arguments | Value | Type | +| ----------------- | ---------------------- | ------------------------------------------------------------------------------------------ | +| clientDisplayName | Client Display Name | String | +| token | User Token | String | +| userId | User Id | String | +| environment | Environment | PhylloEnvironment.sandbox or PhylloEnvironment.development or PhylloEnvironment.production | +| workPlatformId | Platform Id (optional) | String or Null | ### Examples -Try our [sample app](https://github.com/getphyllo/phyllo-connect-reactnative/tree/release-v0.0.1/example) +Try our [sample app](https://github.com/getphyllo/phyllo-connect-reactnative/tree/main/example) -Facing any issue? Feel free to raise an issue in the [issues section](<(https://github.com/getphyllo/phyllo-connect-reactnative/issues)>) +Facing any issue? We have listed solutions for some comman issues [here](https://github.com/getphyllo/phyllo-connect-reactnative/blob/develop/Issues.md), If it doesn't help you, feel free to raise an issue in the [issues section](https://github.com/getphyllo/phyllo-connect-reactnative/issues) or report your issue on [#bug-reports](https://discord.com/channels/897097781355888640/949535402845405184) channel of our [Discord server](https://discord.com/channels/897097781355888640/). ## Author diff --git a/android/app b/android/app deleted file mode 100644 index 59027cfe1..000000000 Binary files a/android/app and /dev/null differ diff --git a/android/build.gradle b/android/build.gradle index 1ab1ca09b..f813c41a2 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -40,7 +40,7 @@ repositories { dependencies { //noinspection GradleDynamicVersion implementation 'com.facebook.react:react-native:+' - implementation "com.getphyllo:phyllo-connect:0.1.13" + implementation "com.getphyllo:phyllo-connect:0.1.14" implementation "com.squareup.okhttp3:okhttp-urlconnection:4.9.0" implementation "com.squareup.okhttp3:logging-interceptor:4.9.0" diff --git a/example/.env b/example/.env deleted file mode 100644 index 6b5503c1d..000000000 --- a/example/.env +++ /dev/null @@ -1,3 +0,0 @@ -CLIENT_ID="" -CLIENT_SECRET="" -ENVIRONMENT="development" \ No newline at end of file diff --git a/example/README.md b/example/README.md index 342ea94ba..53af7457d 100644 --- a/example/README.md +++ b/example/README.md @@ -29,11 +29,11 @@ npm install cd ios && pod install ``` -### 🔑 Add your client ID and secrets to `example/config.js` file +### 🔑 Add your credentials in `example/src/config.js` file > Assuming you have a client ID and secret, if not reach out at contact@getphyllo.com -``` +```sh clientId = 'YOUR-CLIENT-ID' clientSecret = 'YOUR-SECRET-KEY' env = 'APPLICATION-ENVIRONMENT' diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 2a28c72a7..43ee36eed 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -74,9 +74,6 @@ PODS: - glog (0.3.5) - libevent (2.1.12) - OpenSSL-Universal (1.1.180) - - phyllo-connect-react-native (0.0.1): - - PhylloConnect (~> 0.1.20) - - React - PhylloConnect (0.1.21) - RCT-Folly (2021.06.28.00-v2): - boost @@ -276,6 +273,12 @@ PODS: - React-jsinspector (0.67.3) - React-logger (0.67.3): - glog + - react-native-phyllo-connect (0.0.8): + - PhylloConnect (~> 0.1.21) + - React + - react-native-simple-toast (1.1.3): + - React-Core + - Toast (~> 4.0.0) - React-perflogger (0.67.3) - React-RCTActionSheet (0.67.3): - React-Core/RCTActionSheetHeaders (= 0.67.3) @@ -343,6 +346,7 @@ PODS: - React-perflogger (= 0.67.3) - RNCAsyncStorage (1.16.1): - React-Core + - Toast (4.0.0) - Yoga (1.14.0) - YogaKit (1.18.1): - Yoga (~> 1.14) @@ -375,7 +379,6 @@ DEPENDENCIES: - FlipperKit/SKIOSNetworkPlugin (= 0.99.0) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - OpenSSL-Universal (= 1.1.180) - - phyllo-connect-react-native (from `../node_modules/phyllo-connect-react-native`) - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) @@ -390,6 +393,8 @@ DEPENDENCIES: - React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`) - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) + - react-native-phyllo-connect (from `../node_modules/react-native-phyllo-connect`) + - react-native-simple-toast (from `../node_modules/react-native-simple-toast`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) - React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`) @@ -421,6 +426,7 @@ SPEC REPOS: - libevent - OpenSSL-Universal - PhylloConnect + - Toast - YogaKit EXTERNAL SOURCES: @@ -434,8 +440,6 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/React/FBReactNativeSpec" glog: :podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec" - phyllo-connect-react-native: - :path: "../node_modules/phyllo-connect-react-native" RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTRequired: @@ -460,6 +464,10 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/jsinspector" React-logger: :path: "../node_modules/react-native/ReactCommon/logger" + react-native-phyllo-connect: + :path: "../node_modules/react-native-phyllo-connect" + react-native-simple-toast: + :path: "../node_modules/react-native-simple-toast" React-perflogger: :path: "../node_modules/react-native/ReactCommon/reactperflogger" React-RCTActionSheet: @@ -508,7 +516,6 @@ SPEC CHECKSUMS: glog: 85ecdd10ee8d8ec362ef519a6a45ff9aa27b2e85 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b - phyllo-connect-react-native: 0d2366c5a2d3b92ff38c179ec1ed489ce80af7d4 PhylloConnect: 77394c7b6ba60c18dafdf056327120776f77c212 RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685 RCTRequired: 3c77b683474faf23920fbefc71c4e13af21470c0 @@ -522,6 +529,8 @@ SPEC CHECKSUMS: React-jsiexecutor: 15ea57ead631a11fad57634ff69f78e797113a39 React-jsinspector: 1e1e03345cf6d47779e2061d679d0a87d9ae73d8 React-logger: 1e10789cb84f99288479ba5f20822ce43ced6ffe + react-native-phyllo-connect: 415946bb24b7a0249aa9ab4b19540d216891d03e + react-native-simple-toast: b986e6c1befdc211af3df1bae293278a44e32990 React-perflogger: 93d3f142d6d9a46e635f09ba0518027215a41098 React-RCTActionSheet: 87327c3722203cc79cf79d02fb83e7332aeedd18 React-RCTAnimation: 009c87c018d50e0b38692699405ebe631ff4872d @@ -535,6 +544,7 @@ SPEC CHECKSUMS: React-runtimeexecutor: af1946623656f9c5fd64ca6f36f3863516193446 ReactCommon: 650e33cde4fb7d36781cd3143f5276da0abb2f96 RNCAsyncStorage: c0754b486fec6e532d358bfd7337cb45c8d2c897 + Toast: 91b396c56ee72a5790816f40d3a94dd357abc196 Yoga: 90dcd029e45d8a7c1ff059e8b3c6612ff409061a YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/example/ios/example.xcodeproj/project.pbxproj b/example/ios/example.xcodeproj/project.pbxproj index 2f58d5198..599a67c9b 100644 --- a/example/ios/example.xcodeproj/project.pbxproj +++ b/example/ios/example.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ 0264ED890D079BB9A99DCA28 /* libPods-example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AFBF5BFF5F2120C4BEF2749 /* libPods-example.a */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; - F69336A727D0BA5000EAC317 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = F69336A627D0BA5000EAC317 /* main.jsbundle */; }; FAA6DE282607FC1C0044CA6D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA6DE272607FC1C0044CA6D /* AppDelegate.swift */; }; /* End PBXBuildFile section */ @@ -22,7 +21,6 @@ 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = example/LaunchScreen.storyboard; sourceTree = ""; }; 97D2F575C9E1CCB8487D7A83 /* Pods-example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.debug.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.debug.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; - F69336A627D0BA5000EAC317 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = ""; }; F9197C6B9DA65F8C6AC6D250 /* Pods-example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example.release.xcconfig"; path = "Target Support Files/Pods-example/Pods-example.release.xcconfig"; sourceTree = ""; }; FAA6DE272607FC1C0044CA6D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = example/AppDelegate.swift; sourceTree = ""; }; FAA6DE2A2607FC480044CA6D /* example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "example-Bridging-Header.h"; path = "example/example-Bridging-Header.h"; sourceTree = ""; }; @@ -46,7 +44,6 @@ FAA6DE272607FC1C0044CA6D /* AppDelegate.swift */, 13B07FB51A68108700A75B9A /* Images.xcassets */, 13B07FB61A68108700A75B9A /* Info.plist */, - F69336A627D0BA5000EAC317 /* main.jsbundle */, 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, FAA6DE2A2607FC480044CA6D /* example-Bridging-Header.h */, ); @@ -161,7 +158,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - F69336A727D0BA5000EAC317 /* main.jsbundle in Resources */, 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, ); diff --git a/example/metro.config.js b/example/metro.config.js index 6a38538dd..c81b3ca13 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -5,23 +5,7 @@ * @format */ -const path = require('path') -const exclusionList = require('metro-config/src/defaults/exclusionList') - -const moduleRoot = path.resolve(__dirname, '..') - module.exports = { - watchFolders: [moduleRoot], - resolver: { - extraNodeModules: { - react: path.resolve(__dirname, 'node_modules/react'), - 'react-native': path.resolve(__dirname, 'node_modules/react-native'), - }, - blockList: exclusionList([ - new RegExp(`${moduleRoot}/node_modules/react/.*`), - new RegExp(`${moduleRoot}/node_modules/react-native/.*`), - ]), - }, transformer: { getTransformOptions: async () => ({ transform: { diff --git a/example/package.json b/example/package.json index 2cae1b53f..8ddb22cb4 100644 --- a/example/package.json +++ b/example/package.json @@ -15,10 +15,11 @@ "axios": "^0.26.0", "babel-runtime": "^6.26.0", "base-64": "^1.0.0", - "phyllo-connect-react-native": "0.0.1", "react": "^17.0.2", "react-native": "^0.67.1", - "react-native-bouncy-checkbox": "^2.1.10" + "react-native-bouncy-checkbox": "^2.1.10", + "react-native-phyllo-connect": "0.0.8", + "react-native-simple-toast": "^1.1.3" }, "devDependencies": { "@babel/core": "^7.16.12", diff --git a/example/src/App.js b/example/src/App.js index cdf490976..3d369b2b0 100644 --- a/example/src/App.js +++ b/example/src/App.js @@ -6,10 +6,7 @@ import BouncyCheckbox from 'react-native-bouncy-checkbox' import { createUser, createUserToken } from './APIHandler' import { generateRandomString } from './randomGenerator' -import config from './config' - -// create a new instance for PhylloConnect -const phylloConnect = new PhylloConnect() +import clientConfig from './config' export default function ExampleApp() { const [existingUser, setExistingUser] = useState(false) @@ -18,19 +15,10 @@ export default function ExampleApp() { useEffect(() => { // adding a event handler for onExit action - const onExit = phylloConnect.addAnEventListener('onExit', onExitCallBack) - const onAccountConnected = phylloConnect.addAnEventListener( - 'onAccountConnected', - onAccountConnectedCallBack - ) - const onAccountDisconnected = phylloConnect.addAnEventListener( - 'onAccountDisconnected', - onAccountDisconnectedCallBack - ) - const onTokenExpired = phylloConnect.addAnEventListener( - 'onTokenExpired', - onTokenExpiredCallBack - ) + PhylloConnect.on('exit', onExitCallBack) + PhylloConnect.on('accountConnected', onAccountConnectedCallBack) + PhylloConnect.on('accountDisconnected', onAccountDisconnectedCallBack) + PhylloConnect.on('tokenExpired', onTokenExpiredCallBack) // check if user exist or not const getUserFromStorage = async () => { const userId = await AsyncStorage.getItem('user-id') @@ -44,34 +32,37 @@ export default function ExampleApp() { } getUserFromStorage() - - // remove the event watcher - return () => { - onExit.remove() - onAccountConnected.remove() - onAccountDisconnected.remove() - onTokenExpired.remove() - } }, []) // A callback function called upon event const onExitCallBack = (body) => { - console.log('Exited from Phyllo flow') + const { user_id, reason } = body + console.log( + `Exited from Phyllo flow, reason: ${reason}, userId: ${user_id}` + ) } const onAccountConnectedCallBack = (body) => { - console.log('Account has connected') + const { account_id, user_id, work_platform_id } = body + console.log( + `onAccountConnected => account_id:${account_id}, userId : ${user_id}, workPlatformId:${work_platform_id}` + ) } const onAccountDisconnectedCallBack = (body) => { - console.log('Account has disconnected') + const { account_id, work_platform_id, user_id } = body + console.log( + `Account has disconnected userId: ${user_id}, workPlatformId: ${work_platform_id}, accountId: ${account_id} ` + ) } const onTokenExpiredCallBack = (body) => { - console.log('The token has expired') + const { user_id } = body + console.log(`The token has expired userId: ${user_id}`) AsyncStorage.clear() } - const onPressButton = async (platformId) => { + const onPressButton = async (workPlatformId) => { const clientDisplayName = 'Creator' const externalId = generateRandomString(20) + const environment = clientConfig.env let id, token try { @@ -89,14 +80,17 @@ export default function ExampleApp() { setUserToken(token) } - // opens the sdk flow - phylloConnect.initialize({ + // set config + const config = { clientDisplayName, token, userId: id, - platformId, - env: config.env, - }) + workPlatformId, + environment, + } + + // opens the sdk flow + const phylloConnect = PhylloConnect.initialize(config) phylloConnect.open() } catch (e) { Alert.alert(e.message) diff --git a/example/src/config.js b/example/src/config.js index a8d121f52..3b53608ac 100644 --- a/example/src/config.js +++ b/example/src/config.js @@ -1,6 +1,6 @@ -const clientId = '' -const clientSecret = '' -const env = 'development' +const clientId = '' // add your Id here +const clientSecret = '' // add your client Secret +const env = '' // add your environment type, development, sandbox, production are the valid values export default { clientId, diff --git a/ios/PhylloConnectModule.swift b/ios/PhylloConnectModule.swift index 19b45a7ba..9a2de94ed 100644 --- a/ios/PhylloConnectModule.swift +++ b/ios/PhylloConnectModule.swift @@ -8,7 +8,7 @@ import Foundation import PhylloConnect -import React + @objc(PhylloConnectModule) public class PhylloConnectModule: RCTEventEmitter { diff --git a/package.json b/package.json index 833df7fa1..41415f944 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "react-native-phyllo-connect", - "version": "0.0.5", + "version": "0.0.8", "description": "Phyllo Connect is a quick and secure way to connect work platforms via Phyllo in your app. Supports: iOS, Android.", "homepage": "https://github.com/getphyllo/phyllo-connect-reactnative/", "types": "lib/index.d.ts", "author": "Phyllo ", "license": "MIT", - "main": "./lib/index.d.ts", + "main": "./lib/index.js", "bugs": { "url": "https://github.com/getphyllo/phyllo-connect-reactnative/issues" }, @@ -64,5 +64,12 @@ "json", "node" ] - } + }, + "keywords": [ + "phyllo-connect", + "getphyllo", + "phyllo", + "react-native-phyllo-connect", + "phyllo-connect-react-native" + ] } diff --git a/src/PhylloConnect.ts b/src/PhylloConnect.ts index 4ce3dd99b..846270d95 100644 --- a/src/PhylloConnect.ts +++ b/src/PhylloConnect.ts @@ -6,45 +6,67 @@ interface IPhylloInitialize { clientDisplayName: string token: string userId: string - env: PhylloEnvironment - platformId?: string | undefined + environment: PhylloEnvironment + workPlatformId?: string } type TEventType = - | 'onAccountConnected' - | 'onAccountDisconnected' - | 'onExit' - | 'onTokenExpired' + | 'accountConnected' + | 'accountDisconnected' + | 'exit' + | 'tokenExpired' const phyllo = NativeModules.PhylloConnectModule +const eventEmitter = new NativeEventEmitter(phyllo) -class PhylloConnectSDK { - // eventListeners: Set - eventEmitter: NativeEventEmitter - constructor() { - // this.eventListeners = new Set() - this.eventEmitter = new NativeEventEmitter(phyllo) +const validateConfig = (params: IPhylloInitialize) => { + if (!params.environment || !(params.environment in PhylloEnvironment)) { + throw new Error('Please provide a valid environment') } - addAnEventListener = (event: TEventType, callback: (body?: any) => {}) => { - // return the event, let the user handle it - return this.eventEmitter.addListener(event, callback) + if (!params.userId) { + throw new Error('Please provide a User Id') } - - open = () => { - phyllo.open() + if (!params.clientDisplayName) { + throw new Error('Please Provide Client Display Name') + } + if (!params.token) { + throw new Error('Please provide a Token') } +} - initialize = ({ +const PhylloConnectSDK = { + on: (event: TEventType, callback: (body?: any) => {}) => { + // we are adding 'on' at the beginning, capitalize the next work, ex: exit -> onExit + const eventName = 'on' + event[0].toUpperCase() + event.slice(1) + return eventEmitter.addListener(eventName, callback) + }, + initialize: ({ clientDisplayName, token, userId, - env, - platformId = undefined, + environment, + workPlatformId = '', }: IPhylloInitialize) => { - phyllo.initialize(clientDisplayName, token, userId, env, platformId) - } + validateConfig({ + clientDisplayName, + token, + userId, + environment, + }) + + // maintain the same order + phyllo.initialize( + clientDisplayName, + token, + userId, + environment, + workPlatformId + ) + + // this is to solely match web sdk signature + return { open: () => phyllo.open() } + }, } -// const PhylloConnect = new PhylloConnectSDK() -// create a new object and export +// export the object export default PhylloConnectSDK diff --git a/src/PhylloEnvironment.ts b/src/PhylloEnvironment.ts index 5a33fe3be..5183e12fe 100644 --- a/src/PhylloEnvironment.ts +++ b/src/PhylloEnvironment.ts @@ -1,7 +1,7 @@ enum PhylloEnvironment { - Development = 'development', - Production = 'production', - Sandbox = 'sandbox', + development = 'development', + production = 'production', + sandbox = 'sandbox', } export { PhylloEnvironment }