Skip to content

Commit

Permalink
Merge pull request #7 from getphyllo/release_v0.1.15
Browse files Browse the repository at this point in the history
Release v0.1.15
  • Loading branch information
chiragphyllo authored Mar 16, 2022
2 parents e20fa58 + 8b16f7b commit 8c35b53
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 113 deletions.
2 changes: 1 addition & 1 deletion Issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED
<br>
<br>

3. **Specs satisfying the PhylloConnect (~> 0.1.21) dependency were found, but they required a higher minimum deployment target**
3. **Specs satisfying the PhylloConnect (~> 0.1.X) 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 you are facing this error on pod install, then run
Expand Down
73 changes: 38 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,57 @@ cd ios && pod install
import PhylloConnect from 'react-native-phyllo-connect'
```

### Subscribing to events

```sh
// Subscribe to an event by passing a callback
PhylloConnect.on('<event-type>', callbackFunction)

const callbackFunction = (body) => {
// callback body
}
```

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

- [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)

### Open Phyllo SDK flow
### Create a Phyllo Connect SDK Configuration

```sh
import { PhylloEnvironment } from 'react-native-phyllo-connect'
import PhylloConnect, { PhylloEnvironment } from "react-native-phyllo-connect";

const config = {
clientDisplayName: clientDisplayName,
clientDisplayName: clientDisplayName, // the name of your app that you want the creators to see while granting access
environment: PhylloEnvironment.sandbox, // the mode in which you want to use the SDK, `sandbox` or `production`
userId: userId, // the unique user_id parameter returned by Phyllo API when you create a user (see https://docs.getphyllo.com/docs/api-reference/reference/openapi.v1.yml/paths/~1v1~1users/post)
token: token,
userId: userId,
environment: PhylloEnvironment.<environmentType>,
workPlatformId: workPlatformId,
}
workPlatformId: workPlatformId, // (optional) the unique work_platform_id of a specific work platform, if you want the creator to skip the platform selection screen and just be able to connect just with a single work platform
};

const phylloConnect = PhylloConnect.initialize(config);
```
| Arguments | Value | Type |
| ----------------- | ---------------------- | --------------------------------------------------------- |
| clientDisplayName | Client Display Name | String |
| token | User Token | String |
| userId | User Id | String |
| environment | Environment | PhylloEnvironment.sandbox or PhylloEnvironment.production |
| workPlatformId | Platform Id (optional) | String or Null |
### Subscribing to events
const phylloConnect = PhylloConnect.initialize(config)
phylloConnect.open()
```sh
phylloConnect.on("accountConnected", (accountId, workplatformId, userId) => { // gives the successfully connected account ID and work platform ID for the given user ID
console.log(`onAccountConnected: ${accountId}, ${workplatformId}, ${userId}`);
})
phylloConnect.on("accountDisconnected", (accountId, workplatformId, userId) => { // gives the successfully disconnected account ID and work platform ID for the given user ID
console.log(`onAccountDisconnected: ${accountId}, ${workplatformId}, ${userId}`);
})
phylloConnect.on("tokenExpired", (userId) => { // gives the user ID for which the token has expired
console.log(`onTokenExpired: ${userId}`);
})
phylloConnect.on("exit", (reason, userId) => { // indicated that the user with given user ID has closed the SDK and gives an appropriate reason for it
console.log(`onExit: ${reason}, ${userId}`);
})
```
| 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 |
### Open the connection screen
```sh
phylloConnect.open();
```
### Examples
Expand Down
40 changes: 20 additions & 20 deletions android/src/main/java/com/phylloconnect/PhylloConnectModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import android.view.WindowManager
import android.view.Window
import android.view.View
import android.content.Intent
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.Arguments
import com.facebook.react.modules.core.DeviceEventManagerModule

Expand All @@ -38,11 +38,11 @@ class PhylloConnectModule(reactContext: ReactApplicationContext) : ReactContextB
environment = getPhylloEnvironment(environment),
callback = object : ConnectCallback {
override fun onAccountConnected(accountId: String?,platformId: String?, userId: String?) {
val params = Arguments.createMap();
params.putString("account_id", accountId);
params.putString("user_id", userId);
params.putString("work_platform_id", platformId);
sendEvent("onAccountConnected", params);
val values = Arguments.createArray();
values.pushString(accountId);
values.pushString(platformId);
values.pushString(userId);
sendEvent("onAccountConnected", values);
}

override fun onError(errorMsg: String?) {
Expand All @@ -54,24 +54,24 @@ class PhylloConnectModule(reactContext: ReactApplicationContext) : ReactContextB
}

override fun onAccountDisconnected(accountId: String?,platformId: String?, userId: String?) {
val params = Arguments.createMap();
params.putString("account_id", accountId);
params.putString("user_id", userId);
params.putString("work_platform_id", platformId);
sendEvent("onAccountDisconnected", params);
val values = Arguments.createArray();
values.pushString(accountId);
values.pushString(platformId);
values.pushString(userId);
sendEvent("onAccountDisconnected", values);
}

override fun onTokenExpired(userId: String?) {
val params = Arguments.createMap();
params.putString("user_id", userId);
sendEvent("onTokenExpired", params);
val values = Arguments.createArray();
values.pushString(userId);
sendEvent("onTokenExpired", values);
}

override fun onExit(reason:String?,userId: String?) {
val params = Arguments.createMap();
params.putString("user_id", userId);
params.putString("reason", reason);
sendEvent("onExit", params);
val values = Arguments.createArray();
values.pushString(reason);
values.pushString(userId);
sendEvent("onExit", values);
}
})
}
Expand Down Expand Up @@ -103,9 +103,9 @@ class PhylloConnectModule(reactContext: ReactApplicationContext) : ReactContextB

private fun sendEvent(
eventName:String,
params:WritableMap?) {
values:WritableArray?) {

reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, params)
reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(eventName, values)
}

// Required for rn built in EventEmitter Calls. Otherwise it'll show warnings
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ PODS:
- React-jsinspector (0.67.3)
- React-logger (0.67.3):
- glog
- react-native-phyllo-connect (0.0.9):
- react-native-phyllo-connect (0.1.15):
- PhylloConnect (~> 0.1.24)
- React
- react-native-simple-toast (1.1.3):
Expand Down Expand Up @@ -344,7 +344,7 @@ PODS:
- React-jsi (= 0.67.3)
- React-logger (= 0.67.3)
- React-perflogger (= 0.67.3)
- RNCAsyncStorage (1.16.1):
- RNCAsyncStorage (1.16.3):
- React-Core
- Toast (4.0.0)
- Yoga (1.14.0)
Expand Down Expand Up @@ -529,8 +529,8 @@ SPEC CHECKSUMS:
React-jsiexecutor: 15ea57ead631a11fad57634ff69f78e797113a39
React-jsinspector: 1e1e03345cf6d47779e2061d679d0a87d9ae73d8
React-logger: 1e10789cb84f99288479ba5f20822ce43ced6ffe
react-native-phyllo-connect: 5073fc56a8d5aa731fd00e844a53ee00bc331d08
react-native-simple-toast: b986e6c1befdc211af3df1bae293278a44e32990
react-native-phyllo-connect: e7fbc8fc1b54b9827603cbdd9c0f6020eb383ecc
react-native-simple-toast: bf002828cf816775a6809f7a9ec3907509bce11f
React-perflogger: 93d3f142d6d9a46e635f09ba0518027215a41098
React-RCTActionSheet: 87327c3722203cc79cf79d02fb83e7332aeedd18
React-RCTAnimation: 009c87c018d50e0b38692699405ebe631ff4872d
Expand All @@ -543,7 +543,7 @@ SPEC CHECKSUMS:
React-RCTVibration: d0361f15ea978958fab7ffb6960f475b5063d83f
React-runtimeexecutor: af1946623656f9c5fd64ca6f36f3863516193446
ReactCommon: 650e33cde4fb7d36781cd3143f5276da0abb2f96
RNCAsyncStorage: c0754b486fec6e532d358bfd7337cb45c8d2c897
RNCAsyncStorage: 13d3b40c7fae0796d10b23fbec382e7a76807a0f
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
Yoga: 90dcd029e45d8a7c1ff059e8b3c6612ff409061a
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
2 changes: 1 addition & 1 deletion example/ios/example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Sandbox - PhylloSampleApp</string>
<string>Phyllo Sample App</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react": "^17.0.2",
"react-native": "^0.67.1",
"react-native-bouncy-checkbox": "^2.1.10",
"react-native-phyllo-connect": "0.0.9",
"react-native-phyllo-connect": "^0.1.15",
"react-native-simple-toast": "^1.1.3"
},
"devDependencies": {
Expand Down
39 changes: 16 additions & 23 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ export default function ExampleApp() {
const [userToken, setUserToken] = useState('')

useEffect(() => {
// adding a event handler for onExit action
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')
const token = await AsyncStorage.getItem('user-token')
Expand All @@ -35,32 +29,25 @@ export default function ExampleApp() {
}, [])

// A callback function called upon event
const onExitCallBack = (body) => {
const { user_id, reason } = body
console.log(
`Exited from Phyllo flow, reason: ${reason}, userId: ${user_id}`
)
const onExitCallBack = (reason, userId) => {
console.log(`onExit reason: ${reason}, userId: ${userId}`)
}
const onAccountConnectedCallBack = (body) => {
const { account_id, user_id, work_platform_id } = body
const onAccountConnectedCallBack = (accountId, workplatformId, userId) => {
console.log(
`onAccountConnected => account_id:${account_id}, userId : ${user_id}, workPlatformId:${work_platform_id}`
`onAccountConnected accountId: ${accountId}, workplatformId: ${workplatformId}, userId: ${userId}`
)
}
const onAccountDisconnectedCallBack = (body) => {
const { account_id, work_platform_id, user_id } = body
const onAccountDisconnectedCallBack = (accountId, workplatformId, userId) => {
console.log(
`Account has disconnected userId: ${user_id}, workPlatformId: ${work_platform_id}, accountId: ${account_id} `
`onAccountDisconnected accountId: ${accountId}, workplatformId: ${workplatformId}, userId: ${userId}`
)
}
const onTokenExpiredCallBack = (body) => {
const { user_id } = body
console.log(`The token has expired userId: ${user_id}`)
AsyncStorage.clear()
const onTokenExpiredCallBack = (userId) => {
console.log(`onTokenExpired userId: ${userId}`)
}

const onPressButton = async (workPlatformId) => {
const clientDisplayName = 'Creator'
const clientDisplayName = 'Example'
const externalId = generateRandomString(20)
const environment = clientConfig.env

Expand Down Expand Up @@ -91,9 +78,15 @@ export default function ExampleApp() {

// opens the sdk flow
const phylloConnect = PhylloConnect.initialize(config)

phylloConnect.on('exit', onExitCallBack)
phylloConnect.on('tokenExpired', onTokenExpiredCallBack)
phylloConnect.on('accountConnected', onAccountConnectedCallBack)
phylloConnect.on('accountDisconnected', onAccountDisconnectedCallBack)

phylloConnect.open()
} catch (e) {
Alert.alert(e.message)
Alert.alert('An error occured', e.message)
console.log(e)
}
}
Expand Down
26 changes: 9 additions & 17 deletions ios/PhylloConnectModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ extension PhylloConnectModule : PhylloConnectDelegate {
public func onAccountConnected(account_id: String, work_platform_id: String, user_id: String) {
//Event Sent After Get Connect
DispatchQueue.main.async {
var dic = [String:String]()
dic["account_id"] = account_id
dic["work_platform_id"] = work_platform_id
dic["user_id"] = user_id
var values : [String] = [account_id, work_platform_id, user_id]
if self.hasObservers ?? false {
self.sendEvent(withName: "onAccountConnected", body: dic)
self.sendEvent(withName: "onAccountConnected", body: values)
}
}

Expand All @@ -94,35 +91,30 @@ extension PhylloConnectModule : PhylloConnectDelegate {
public func onAccountDisconnected(account_id: String, work_platform_id: String, user_id: String) {
//Event Sent After Get Connect
DispatchQueue.main.async {
var dic = [String:String]()
dic["account_id"] = account_id
dic["work_platform_id"] = work_platform_id
dic["user_id"] = user_id
var values : [String] = [account_id, work_platform_id, user_id]
if self.hasObservers ?? false {
self.sendEvent(withName: "onAccountDisconnected", body: dic)
self.sendEvent(withName: "onAccountDisconnected", body: values)
}
}
}

public func onTokenExpired(user_id: String) {
//Event Sent After Get Connect
DispatchQueue.main.async {
var dic = [String:String]()
dic["user_id"] = user_id
var values : [String] = [user_id]
if self.hasObservers ?? false {
self.sendEvent(withName: "onTokenExpired", body: dic)
self.sendEvent(withName: "onTokenExpired", body: values)
}
}
}


public func onExit(reason: String, user_id: String) {
//Event Sent After Get Connect
DispatchQueue.main.async {
var dic = [String:String]()
dic["user_id"] = user_id
dic["reason"] = reason
var values = [reason, user_id]
if self.hasObservers ?? false {
self.sendEvent(withName: "onExit", body: dic)
self.sendEvent(withName: "onExit", body: values)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-phyllo-connect",
"version": "0.0.9",
"version": "0.1.15",
"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",
Expand Down
Loading

0 comments on commit 8c35b53

Please sign in to comment.